Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b60d2e2

Browse files
fix(openai): allow open_page action type url to be nullish (#10646)
## Background OAI sometimes doesn't render the `url` param for the `open_page` action type, leading to validation errors. ## Summary Set the parameter to `.nullish()` ## Manual Verification - First, just run the repro code example to observe the error. - Then apply the fix and run the same example again ## Checklist - [ ] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [ ] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [ ] I have reviewed this pull request (self-review) ## Related Issues Fixes #9308 and #10669
1 parent 4b636cd commit b60d2e2

File tree

6 files changed

+75
-62
lines changed

6 files changed

+75
-62
lines changed

.changeset/shiny-llamas-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ai-sdk/openai': patch
3+
---
4+
5+
fix(openai): allow open_page action type url to be nullish

examples/next-openai/components/tool/azure-web-search-preview-view.tsx

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@ export default function AzureWebSearchPreviewView({
4949
</span>
5050
Opened a page
5151
</div>
52-
<div className="pl-5 text-sm text-green-900 break-all">
53-
<span className="font-semibold">URL:</span>{' '}
54-
<a
55-
href={output.action.url}
56-
target="_blank"
57-
rel="noopener noreferrer"
58-
className="underline hover:text-green-700"
59-
>
60-
{output.action.url}
61-
</a>
62-
</div>
52+
{output.action.url && (
53+
<div className="pl-5 text-sm text-green-900 break-all">
54+
<span className="font-semibold">URL:</span>{' '}
55+
<a
56+
href={output.action.url}
57+
target="_blank"
58+
rel="noopener noreferrer"
59+
className="underline hover:text-green-700"
60+
>
61+
{output.action.url}
62+
</a>
63+
</div>
64+
)}
6365
</div>
6466
);
6567
case 'find':
@@ -71,23 +73,25 @@ export default function AzureWebSearchPreviewView({
7173
</span>
7274
Searched for pattern in page
7375
</div>
76+
{output.action.url && (
77+
<div className="pl-5 text-sm text-yellow-900 break-all">
78+
<span className="font-semibold">URL:</span>{' '}
79+
<a
80+
href={output.action.url}
81+
target="_blank"
82+
rel="noopener noreferrer"
83+
className="underline hover:text-yellow-700"
84+
>
85+
{output.action.url}
86+
</a>
87+
</div>
88+
)}
7489
<div className="pl-5 text-sm text-yellow-900">
7590
<span className="font-semibold">Pattern:</span>{' '}
7691
<span className="inline-block bg-white border border-yellow-100 rounded px-2 py-0.5 font-mono">
7792
{output.action.pattern}
7893
</span>
7994
</div>
80-
<div className="pl-5 text-sm text-yellow-900 break-all">
81-
<span className="font-semibold">In URL:</span>{' '}
82-
<a
83-
href={output.action.url}
84-
target="_blank"
85-
rel="noopener noreferrer"
86-
className="underline hover:text-yellow-700"
87-
>
88-
{output.action.url}
89-
</a>
90-
</div>
9195
</div>
9296
);
9397
}

examples/next-openai/components/tool/openai-web-search-view.tsx

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,19 @@ export default function OpenAIWebSearchView({
7474
</span>
7575
Opened a page
7676
</div>
77-
<div className="pl-5 text-sm text-green-900 break-all">
78-
<span className="font-semibold">URL:</span>{' '}
79-
<a
80-
href={output.action.url}
81-
target="_blank"
82-
rel="noopener noreferrer"
83-
className="underline hover:text-green-700"
84-
>
85-
{output.action.url}
86-
</a>
87-
</div>
77+
{output.action.url && (
78+
<div className="pl-5 text-sm text-green-900 break-all">
79+
<span className="font-semibold">URL:</span>{' '}
80+
<a
81+
href={output.action.url}
82+
target="_blank"
83+
rel="noopener noreferrer"
84+
className="underline hover:text-green-700"
85+
>
86+
{output.action.url}
87+
</a>
88+
</div>
89+
)}
8890
</div>
8991
);
9092
case 'find':
@@ -96,23 +98,25 @@ export default function OpenAIWebSearchView({
9698
</span>
9799
Searched for pattern in page
98100
</div>
101+
{output.action.url && (
102+
<div className="pl-5 text-sm text-yellow-900 break-all">
103+
<span className="font-semibold">URL:</span>{' '}
104+
<a
105+
href={output.action.url}
106+
target="_blank"
107+
rel="noopener noreferrer"
108+
className="underline hover:text-yellow-700"
109+
>
110+
{output.action.url}
111+
</a>
112+
</div>
113+
)}
99114
<div className="pl-5 text-sm text-yellow-900">
100115
<span className="font-semibold">Pattern:</span>{' '}
101116
<span className="inline-block bg-white border border-yellow-100 rounded px-2 py-0.5 font-mono">
102117
{output.action.pattern}
103118
</span>
104119
</div>
105-
<div className="pl-5 text-sm text-yellow-900 break-all">
106-
<span className="font-semibold">In URL:</span>{' '}
107-
<a
108-
href={output.action.url}
109-
target="_blank"
110-
rel="noopener noreferrer"
111-
className="underline hover:text-yellow-700"
112-
>
113-
{output.action.url}
114-
</a>
115-
</div>
116120
</div>
117121
);
118122
}

packages/openai/src/responses/openai-responses-api.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,12 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
485485
}),
486486
z.object({
487487
type: z.literal('open_page'),
488-
url: z.string(),
488+
url: z.string().nullish(),
489489
}),
490490
z.object({
491491
type: z.literal('find'),
492-
url: z.string(),
493-
pattern: z.string(),
492+
url: z.string().nullish(),
493+
pattern: z.string().nullish(),
494494
}),
495495
]),
496496
}),
@@ -818,12 +818,12 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
818818
}),
819819
z.object({
820820
type: z.literal('open_page'),
821-
url: z.string(),
821+
url: z.string().nullish(),
822822
}),
823823
z.object({
824824
type: z.literal('find'),
825-
url: z.string(),
826-
pattern: z.string(),
825+
url: z.string().nullish(),
826+
pattern: z.string().nullish(),
827827
}),
828828
]),
829829
}),

packages/openai/src/tool/web-search-preview.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ const webSearchPreviewOutputSchema = lazySchema(() =>
3636
}),
3737
z.object({
3838
type: z.literal('openPage'),
39-
url: z.string(),
39+
url: z.string().nullish(),
4040
}),
4141
z.object({
4242
type: z.literal('find'),
43-
url: z.string(),
44-
pattern: z.string(),
43+
url: z.string().nullish(),
44+
pattern: z.string().nullish(),
4545
}),
4646
]),
4747
}),
@@ -78,7 +78,7 @@ export const webSearchPreview = createProviderToolFactoryWithOutputSchema<
7878
/**
7979
* The URL opened by the model.
8080
*/
81-
url: string;
81+
url?: string | null;
8282
}
8383
| {
8484
/**
@@ -89,12 +89,12 @@ export const webSearchPreview = createProviderToolFactoryWithOutputSchema<
8989
/**
9090
* The URL of the page searched for the pattern.
9191
*/
92-
url: string;
92+
url?: string | null;
9393

9494
/**
9595
* The pattern or text to search for within the page.
9696
*/
97-
pattern: string;
97+
pattern?: string | null;
9898
};
9999
},
100100
{

packages/openai/src/tool/web-search.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ export const webSearchOutputSchema = lazySchema(() =>
3838
}),
3939
z.object({
4040
type: z.literal('openPage'),
41-
url: z.string(),
41+
url: z.string().nullish(),
4242
}),
4343
z.object({
4444
type: z.literal('find'),
45-
url: z.string(),
46-
pattern: z.string(),
45+
url: z.string().nullish(),
46+
pattern: z.string().nullish(),
4747
}),
4848
]),
4949
sources: z
@@ -88,7 +88,7 @@ export const webSearchToolFactory = createProviderToolFactoryWithOutputSchema<
8888
/**
8989
* The URL opened by the model.
9090
*/
91-
url: string;
91+
url?: string | null;
9292
}
9393
| {
9494
/**
@@ -99,12 +99,12 @@ export const webSearchToolFactory = createProviderToolFactoryWithOutputSchema<
9999
/**
100100
* The URL of the page searched for the pattern.
101101
*/
102-
url: string;
102+
url?: string | null;
103103

104104
/**
105105
* The pattern or text to search for within the page.
106106
*/
107-
pattern: string;
107+
pattern?: string | null;
108108
};
109109

110110
/**

0 commit comments

Comments
 (0)