@ai-sdk/openai 4.0.91 → 4.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +178 -96
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +10 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +231 -149
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +19 -0
- package/package.json +3 -3
- package/src/responses/convert-to-openai-responses-input.ts +89 -0
- package/src/responses/map-openai-responses-annotation.ts +75 -0
- package/src/responses/openai-responses-api.ts +8 -0
- package/src/responses/openai-responses-language-model.ts +167 -134
- package/src/responses/openai-responses-provider-metadata.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 4.0.92
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6aedb07: fix(openai): replay web search results when response storage is disabled
|
|
8
|
+
- e57803c: Expose complete retrieved web-search URLs and file-search documents as sources, and normalize inline references separately as citations on text parts and text-end events. Preserve citation-derived sources when retrieval data is unavailable, including web-search-preview and Azure responses. Keep raw annotations, citation titles, and text locations available. Deduplicate file-search passages by file ID.
|
|
9
|
+
- 1f7e5ad: fix(openai): JSON-encode custom tool input deltas for progressive UI updates
|
|
10
|
+
- Updated dependencies [9667bf2]
|
|
11
|
+
- Updated dependencies [e57803c]
|
|
12
|
+
- Updated dependencies [81663cc]
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.59
|
|
14
|
+
- @ai-sdk/provider@4.0.27
|
|
15
|
+
|
|
3
16
|
## 4.0.91
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1925,6 +1925,9 @@ type OpenaiResponsesTextProviderMetadata = {
|
|
|
1925
1925
|
openai: ResponsesTextProviderMetadata;
|
|
1926
1926
|
};
|
|
1927
1927
|
type ResponsesSourceDocumentProviderMetadata = {
|
|
1928
|
+
type: 'file_search';
|
|
1929
|
+
fileId: string;
|
|
1930
|
+
} | {
|
|
1928
1931
|
type: 'file_citation';
|
|
1929
1932
|
fileId: string;
|
|
1930
1933
|
index: number;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["_$__tool_apply_patch0.ApplyPatchOperation","_$__tool_custom0.customToolFactory","_$_0.OpenAIComputerAction","_$_0.OpenAIComputerSafetyCheck","_$__responses_openai_responses_api0.OpenAIResponsesFileSearchToolComparisonFilter","_$__responses_openai_responses_api0.OpenAIResponsesFileSearchToolCompoundFilter","_$__tool_web_search0.webSearchToolFactory","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4SessionConfig","RealtimeModelV4","RealtimeModelV4SessionConfig","RealtimeModelV4ClientEvent","RealtimeModelV4","RealtimeModelV4","RealtimeFactoryV4","DecisionModelV4","SpeechTranslationModelV4","BatchV4","SpeechTranslationModelV4StreamOptions","SpeechTranslationModelV4"],"sources":["../src/openai-config.ts","../src/openai-decision-model.ts","../src/chat/openai-chat-language-model-options.ts","../src/completion/openai-completion-language-model-options.ts","../src/embedding/openai-embedding-model-options.ts","../src/image/openai-image-model-options.ts","../src/tool/apply-patch.ts","../src/tool/custom.ts","../src/responses/openai-responses-api.ts","../src/tool/web-search.ts","../src/openai-tools.ts","../src/live/openai-realtime-model-live-options.ts","../src/realtime/openai-realtime-model.ts","../src/live/openai-realtime-model-live.ts","../src/realtime/openai-realtime-factory.ts","../src/responses/openai-responses-language-model-options.ts","../src/speech/openai-speech-model-options.ts","../src/transcription/openai-transcription-model-options.ts","../src/speech-translation/openai-speech-translation-model-options.ts","../src/openai-provider.ts","../src/responses/openai-responses-prepare-tools.ts","../src/speech-translation/openai-speech-translation-model.ts","../src/files/openai-files-options.ts","../src/tool/computer.ts","../src/responses/openai-responses-provider-metadata.ts","../src/version.ts","../src/openai-decision-model-options.ts"],"mappings":";;;;KAKK,gBAAgB;KAMT;EACV;EACA;EACA,MAAM;IAAW;IAAiB;;EAClC,gBAAgB;EAChB,QAAQ;EACR,YAAY;EACZ;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;;EASA;;;;KCdU;;;KCnBA;cAsEC,iEAA8B;;;;;;;;;;;;;;;;;;;;;;;KAwJ/B,iCAAiC,mBACpC;;;KC/NG;cAKC,uEAAoC;;cAApC;;;;;KAiDD,uCAAuC,mBAC1C;;;KCxDG;cAMC,8DAA2B;;;;KAkB5B,8BAA8B,mBACjC;;;KCzBG;cAiFC,0DAAuB;;;;;;;KAIxB,0BAA0B,mBAC7B;cAGI,oEAAiC;;;;;;;;;KAmBlC,oCAAoC,mBACvC;cAGI,8DAA2B;;;;;;;;KAW5B,8BAA8B,mBACjC;;;;;;KCzEG;EAEN;;;;EAIA;;;;EAIA;;EAGA;;;;EAIA;;EAGA;;;;EAIA;;;;EAIA;;;;cCxDO,oDAAiB;;;;EAMZ;;;;;EAMN;;;;;EAOJ;IACE;IACA;IACA;;IAGA;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$__tool_apply_patch0.ApplyPatchOperation","_$__tool_custom0.customToolFactory","_$_0.OpenAIComputerAction","_$_0.OpenAIComputerSafetyCheck","_$__responses_openai_responses_api0.OpenAIResponsesFileSearchToolComparisonFilter","_$__responses_openai_responses_api0.OpenAIResponsesFileSearchToolCompoundFilter","_$__tool_web_search0.webSearchToolFactory","RealtimeModelV4ClientSecretOptions","RealtimeModelV4ClientSecretResult","RealtimeModelV4ServerEvent","RealtimeModelV4ClientEvent","RealtimeModelV4SessionConfig","RealtimeModelV4","RealtimeModelV4SessionConfig","RealtimeModelV4ClientEvent","RealtimeModelV4","RealtimeModelV4","RealtimeFactoryV4","DecisionModelV4","SpeechTranslationModelV4","BatchV4","SpeechTranslationModelV4StreamOptions","SpeechTranslationModelV4"],"sources":["../src/openai-config.ts","../src/openai-decision-model.ts","../src/chat/openai-chat-language-model-options.ts","../src/completion/openai-completion-language-model-options.ts","../src/embedding/openai-embedding-model-options.ts","../src/image/openai-image-model-options.ts","../src/tool/apply-patch.ts","../src/tool/custom.ts","../src/responses/openai-responses-api.ts","../src/tool/web-search.ts","../src/openai-tools.ts","../src/live/openai-realtime-model-live-options.ts","../src/realtime/openai-realtime-model.ts","../src/live/openai-realtime-model-live.ts","../src/realtime/openai-realtime-factory.ts","../src/responses/openai-responses-language-model-options.ts","../src/speech/openai-speech-model-options.ts","../src/transcription/openai-transcription-model-options.ts","../src/speech-translation/openai-speech-translation-model-options.ts","../src/openai-provider.ts","../src/responses/openai-responses-prepare-tools.ts","../src/speech-translation/openai-speech-translation-model.ts","../src/files/openai-files-options.ts","../src/tool/computer.ts","../src/responses/openai-responses-provider-metadata.ts","../src/version.ts","../src/openai-decision-model-options.ts"],"mappings":";;;;KAKK,gBAAgB;KAMT;EACV;EACA;EACA,MAAM;IAAW;IAAiB;;EAClC,gBAAgB;EAChB,QAAQ;EACR,YAAY;EACZ;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;;EASA;;;;KCdU;;;KCnBA;cAsEC,iEAA8B;;;;;;;;;;;;;;;;;;;;;;;KAwJ/B,iCAAiC,mBACpC;;;KC/NG;cAKC,uEAAoC;;cAApC;;;;;KAiDD,uCAAuC,mBAC1C;;;KCxDG;cAMC,8DAA2B;;;;KAkB5B,8BAA8B,mBACjC;;;KCzBG;cAiFC,0DAAuB;;;;;;;KAIxB,0BAA0B,mBAC7B;cAGI,oEAAiC;;;;;;;;;KAmBlC,oCAAoC,mBACvC;cAGI,8DAA2B;;;;;;;;KAW5B,8BAA8B,mBACjC;;;;;;KCzEG;EAEN;;;;EAIA;;;;EAIA;;EAGA;;;;EAIA;;EAGA;;;;E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A;IACM;;IAEA;IACA;;;KAII;EACV,QAAQ;;KAGE;EACV;EACA;EACA;;KAGU;EACV,QAAQ;;KAGE;EACV;EACA;EACA,cAAc,MAAM;;KAGV;EACV,QAAQ;;KAGE;EAEN;EACA;;EAGA;EACA;EACA;;EAGA;EACA;EACA;;EAGA;EACA;EACA;;KAGM;EACV,QAAQ;;;;qBCzFG;;;cCKA,6DAA0B;EAAA;;KAS3B,6BAA6B,mBAChC"}
|
package/dist/index.js
CHANGED
|
@@ -4580,6 +4580,47 @@ function mapToolCaller(caller) {
|
|
|
4580
4580
|
caller_id: caller.callerId
|
|
4581
4581
|
} : caller;
|
|
4582
4582
|
}
|
|
4583
|
+
async function convertWebSearchToolResultOutput({ output, id }) {
|
|
4584
|
+
if (output.type !== "json") return;
|
|
4585
|
+
const validation = await safeValidateTypes({
|
|
4586
|
+
value: output.value,
|
|
4587
|
+
schema: webSearchOutputSchema
|
|
4588
|
+
});
|
|
4589
|
+
if (!validation.success || validation.value.action == null) return;
|
|
4590
|
+
const { action, sources } = validation.value;
|
|
4591
|
+
switch (action.type) {
|
|
4592
|
+
case "search": return {
|
|
4593
|
+
type: "web_search_call",
|
|
4594
|
+
id,
|
|
4595
|
+
status: "completed",
|
|
4596
|
+
action: {
|
|
4597
|
+
type: "search",
|
|
4598
|
+
...action.query != null && { query: action.query },
|
|
4599
|
+
...action.queries != null && { queries: action.queries },
|
|
4600
|
+
...sources != null && { sources }
|
|
4601
|
+
}
|
|
4602
|
+
};
|
|
4603
|
+
case "openPage": return {
|
|
4604
|
+
type: "web_search_call",
|
|
4605
|
+
id,
|
|
4606
|
+
status: "completed",
|
|
4607
|
+
action: {
|
|
4608
|
+
type: "open_page",
|
|
4609
|
+
url: action.url
|
|
4610
|
+
}
|
|
4611
|
+
};
|
|
4612
|
+
case "findInPage": return {
|
|
4613
|
+
type: "web_search_call",
|
|
4614
|
+
id,
|
|
4615
|
+
status: "completed",
|
|
4616
|
+
action: {
|
|
4617
|
+
type: "find_in_page",
|
|
4618
|
+
url: action.url,
|
|
4619
|
+
pattern: action.pattern
|
|
4620
|
+
}
|
|
4621
|
+
};
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4583
4624
|
async function convertFunctionToolResultOutput({ output, toolName, outputSchemaToolNames, promptCacheBreakpoint, providerOptionsName, warnings }) {
|
|
4584
4625
|
const hasOutputSchema = outputSchemaToolNames?.has(toolName);
|
|
4585
4626
|
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [{
|
|
@@ -5097,6 +5138,24 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
|
|
|
5097
5138
|
if (part.output.type === "execution-denied" || part.output.type === "json" && typeof part.output.value === "object" && part.output.value != null && "type" in part.output.value && part.output.value.type === "execution-denied") break;
|
|
5098
5139
|
if (hasConversation) break;
|
|
5099
5140
|
const resolvedResultToolName = toolNameMapping.toProviderToolName(part.toolName);
|
|
5141
|
+
if (resolvedResultToolName === "web_search" || resolvedResultToolName === "web_search_preview") {
|
|
5142
|
+
const itemId = (part.providerOptions?.[providerOptionsName])?.itemId ?? part.toolCallId;
|
|
5143
|
+
if (store) {
|
|
5144
|
+
input.push({
|
|
5145
|
+
type: "item_reference",
|
|
5146
|
+
id: itemId
|
|
5147
|
+
});
|
|
5148
|
+
break;
|
|
5149
|
+
}
|
|
5150
|
+
const webSearchCall = await convertWebSearchToolResultOutput({
|
|
5151
|
+
output: part.output,
|
|
5152
|
+
id: itemId
|
|
5153
|
+
});
|
|
5154
|
+
if (webSearchCall != null) {
|
|
5155
|
+
input.push(webSearchCall);
|
|
5156
|
+
break;
|
|
5157
|
+
}
|
|
5158
|
+
}
|
|
5100
5159
|
if (part.toolName === toolSearchToolName) {
|
|
5101
5160
|
const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId ?? part.toolCallId;
|
|
5102
5161
|
if (store) input.push({
|
|
@@ -5532,6 +5591,40 @@ const openaiResponsesReasoningProviderOptionsSchema = z.object({
|
|
|
5532
5591
|
reasoningEncryptedContent: z.string().nullish()
|
|
5533
5592
|
});
|
|
5534
5593
|
//#endregion
|
|
5594
|
+
//#region src/responses/map-openai-responses-annotation.ts
|
|
5595
|
+
function mapOpenAIResponsesAnnotationSource(annotation, providerOptionsName, id) {
|
|
5596
|
+
if (annotation.type === "url_citation") return {
|
|
5597
|
+
type: "source",
|
|
5598
|
+
sourceType: "url",
|
|
5599
|
+
id,
|
|
5600
|
+
url: annotation.url,
|
|
5601
|
+
title: annotation.title
|
|
5602
|
+
};
|
|
5603
|
+
const filename = annotation.type === "file_path" ? annotation.file_id : annotation.filename;
|
|
5604
|
+
return {
|
|
5605
|
+
type: "source",
|
|
5606
|
+
sourceType: "document",
|
|
5607
|
+
id,
|
|
5608
|
+
mediaType: annotation.type === "file_path" ? "application/octet-stream" : "text/plain",
|
|
5609
|
+
title: filename,
|
|
5610
|
+
filename,
|
|
5611
|
+
providerMetadata: { [providerOptionsName]: {
|
|
5612
|
+
type: annotation.type,
|
|
5613
|
+
fileId: annotation.file_id,
|
|
5614
|
+
...annotation.type === "container_file_citation" ? { containerId: annotation.container_id } : { index: annotation.index }
|
|
5615
|
+
} }
|
|
5616
|
+
};
|
|
5617
|
+
}
|
|
5618
|
+
function mapOpenAIResponsesCitations(annotations, providerOptionsName) {
|
|
5619
|
+
return annotations.flatMap((annotation) => annotation.type === "file_path" ? [] : [{
|
|
5620
|
+
source: mapOpenAIResponsesAnnotationSource(annotation, providerOptionsName, annotation.type === "url_citation" ? annotation.url : annotation.file_id),
|
|
5621
|
+
..."start_index" in annotation ? {
|
|
5622
|
+
startIndex: annotation.start_index,
|
|
5623
|
+
endIndex: annotation.end_index
|
|
5624
|
+
} : {}
|
|
5625
|
+
}]);
|
|
5626
|
+
}
|
|
5627
|
+
//#endregion
|
|
5535
5628
|
//#region src/responses/openai-responses-prepare-tools.ts
|
|
5536
5629
|
async function prepareResponsesTools({ tools, toolChoice, allowedTools, toolNameMapping, customProviderToolNames, outputSchemaToolNames, supportsAsyncToolCalling = true }) {
|
|
5537
5630
|
tools = tools?.length ? tools : void 0;
|
|
@@ -6418,6 +6511,9 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6418
6511
|
const content = [];
|
|
6419
6512
|
const logprobs = [];
|
|
6420
6513
|
const functionTools = options.tools?.filter((tool) => tool.type === "function") ?? [];
|
|
6514
|
+
const hasWebSearchActionSources = response.output.some((part) => part.type === "web_search_call" && part.action?.type === "search" && part.action.sources?.some((source) => source.type === "url"));
|
|
6515
|
+
const hasFileSearchResults = response.output.some((part) => part.type === "file_search_call" && (part.results?.length ?? 0) > 0);
|
|
6516
|
+
const retrievedFileIds = /* @__PURE__ */ new Set();
|
|
6421
6517
|
let hasFunctionCall = false;
|
|
6422
6518
|
const hostedToolSearchCallIds = [];
|
|
6423
6519
|
for (const part of response.output) switch (part.type) {
|
|
@@ -6523,54 +6619,13 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6523
6619
|
content.push({
|
|
6524
6620
|
type: "text",
|
|
6525
6621
|
text: contentPart.text,
|
|
6622
|
+
...contentPart.annotations.some((annotation) => annotation.type !== "file_path") && { citations: mapOpenAIResponsesCitations(contentPart.annotations, providerOptionsName) },
|
|
6526
6623
|
providerMetadata: { [providerOptionsName]: providerMetadata }
|
|
6527
6624
|
});
|
|
6528
|
-
for (const annotation of contentPart.annotations)
|
|
6529
|
-
type
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
url: annotation.url,
|
|
6533
|
-
title: annotation.title
|
|
6534
|
-
});
|
|
6535
|
-
else if (annotation.type === "file_citation") content.push({
|
|
6536
|
-
type: "source",
|
|
6537
|
-
sourceType: "document",
|
|
6538
|
-
id: this.config.generateId?.() ?? generateId(),
|
|
6539
|
-
mediaType: "text/plain",
|
|
6540
|
-
title: annotation.filename,
|
|
6541
|
-
filename: annotation.filename,
|
|
6542
|
-
providerMetadata: { [providerOptionsName]: {
|
|
6543
|
-
type: annotation.type,
|
|
6544
|
-
fileId: annotation.file_id,
|
|
6545
|
-
index: annotation.index
|
|
6546
|
-
} }
|
|
6547
|
-
});
|
|
6548
|
-
else if (annotation.type === "container_file_citation") content.push({
|
|
6549
|
-
type: "source",
|
|
6550
|
-
sourceType: "document",
|
|
6551
|
-
id: this.config.generateId?.() ?? generateId(),
|
|
6552
|
-
mediaType: "text/plain",
|
|
6553
|
-
title: annotation.filename,
|
|
6554
|
-
filename: annotation.filename,
|
|
6555
|
-
providerMetadata: { [providerOptionsName]: {
|
|
6556
|
-
type: annotation.type,
|
|
6557
|
-
fileId: annotation.file_id,
|
|
6558
|
-
containerId: annotation.container_id
|
|
6559
|
-
} }
|
|
6560
|
-
});
|
|
6561
|
-
else if (annotation.type === "file_path") content.push({
|
|
6562
|
-
type: "source",
|
|
6563
|
-
sourceType: "document",
|
|
6564
|
-
id: this.config.generateId?.() ?? generateId(),
|
|
6565
|
-
mediaType: "application/octet-stream",
|
|
6566
|
-
title: annotation.file_id,
|
|
6567
|
-
filename: annotation.file_id,
|
|
6568
|
-
providerMetadata: { [providerOptionsName]: {
|
|
6569
|
-
type: annotation.type,
|
|
6570
|
-
fileId: annotation.file_id,
|
|
6571
|
-
index: annotation.index
|
|
6572
|
-
} }
|
|
6573
|
-
});
|
|
6625
|
+
for (const annotation of contentPart.annotations) {
|
|
6626
|
+
if (annotation.type === "url_citation" && hasWebSearchActionSources || annotation.type === "file_citation" && hasFileSearchResults) continue;
|
|
6627
|
+
content.push(mapOpenAIResponsesAnnotationSource(annotation, providerOptionsName, this.config.generateId?.() ?? generateId()));
|
|
6628
|
+
}
|
|
6574
6629
|
}
|
|
6575
6630
|
break;
|
|
6576
6631
|
case "function_call": {
|
|
@@ -6663,6 +6718,14 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6663
6718
|
result: { status: part.status }
|
|
6664
6719
|
} : { result: mapWebSearchOutput(part.action) }
|
|
6665
6720
|
});
|
|
6721
|
+
if (part.action?.type === "search") {
|
|
6722
|
+
for (const source of part.action.sources ?? []) if (source.type === "url") content.push({
|
|
6723
|
+
type: "source",
|
|
6724
|
+
sourceType: "url",
|
|
6725
|
+
id: this.config.generateId?.() ?? generateId(),
|
|
6726
|
+
url: source.url
|
|
6727
|
+
});
|
|
6728
|
+
}
|
|
6666
6729
|
break;
|
|
6667
6730
|
case "mcp_call": {
|
|
6668
6731
|
const toolCallId = part.approval_request_id != null ? approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id] ?? part.id : part.id;
|
|
@@ -6765,6 +6828,22 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6765
6828
|
})) ?? null
|
|
6766
6829
|
}
|
|
6767
6830
|
});
|
|
6831
|
+
for (const result of part.results ?? []) {
|
|
6832
|
+
if (retrievedFileIds.has(result.file_id)) continue;
|
|
6833
|
+
retrievedFileIds.add(result.file_id);
|
|
6834
|
+
content.push({
|
|
6835
|
+
type: "source",
|
|
6836
|
+
sourceType: "document",
|
|
6837
|
+
id: this.config.generateId?.() ?? generateId(),
|
|
6838
|
+
mediaType: "text/plain",
|
|
6839
|
+
title: result.filename,
|
|
6840
|
+
filename: result.filename,
|
|
6841
|
+
providerMetadata: { [providerOptionsName]: {
|
|
6842
|
+
type: "file_search",
|
|
6843
|
+
fileId: result.file_id
|
|
6844
|
+
} }
|
|
6845
|
+
});
|
|
6846
|
+
}
|
|
6768
6847
|
break;
|
|
6769
6848
|
case "code_interpreter_call":
|
|
6770
6849
|
content.push({
|
|
@@ -6875,7 +6954,11 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6875
6954
|
const logprobs = [];
|
|
6876
6955
|
let responseId = null;
|
|
6877
6956
|
const ongoingToolCalls = {};
|
|
6878
|
-
|
|
6957
|
+
let ongoingAnnotations = [];
|
|
6958
|
+
let hasWebSearchActionSources = false;
|
|
6959
|
+
let hasFileSearchResults = false;
|
|
6960
|
+
const retrievedFileIds = /* @__PURE__ */ new Set();
|
|
6961
|
+
const fallbackAnnotations = [];
|
|
6879
6962
|
let activeMessagePhase;
|
|
6880
6963
|
let hasFunctionCall = false;
|
|
6881
6964
|
const activeReasoning = {};
|
|
@@ -6948,6 +7031,11 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6948
7031
|
id: value.item.call_id,
|
|
6949
7032
|
toolName
|
|
6950
7033
|
});
|
|
7034
|
+
controller.enqueue({
|
|
7035
|
+
type: "tool-input-delta",
|
|
7036
|
+
id: value.item.call_id,
|
|
7037
|
+
delta: "\""
|
|
7038
|
+
});
|
|
6951
7039
|
} else if (value.item.type === "web_search_call") {
|
|
6952
7040
|
ongoingToolCalls[value.output_index] = {
|
|
6953
7041
|
toolName: toolNameMapping.toCustomToolName(webSearchToolName ?? "web_search"),
|
|
@@ -7067,7 +7155,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7067
7155
|
};
|
|
7068
7156
|
else if (value.item.type === "shell_call_output") {} else if (value.item.type === "message") {
|
|
7069
7157
|
activeOutputItemIds[value.output_index] = value.item.id;
|
|
7070
|
-
ongoingAnnotations
|
|
7158
|
+
ongoingAnnotations = [];
|
|
7071
7159
|
activeMessagePhase = value.item.phase ?? void 0;
|
|
7072
7160
|
controller.enqueue({
|
|
7073
7161
|
type: "text-start",
|
|
@@ -7103,6 +7191,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7103
7191
|
controller.enqueue({
|
|
7104
7192
|
type: "text-end",
|
|
7105
7193
|
id: itemId,
|
|
7194
|
+
...ongoingAnnotations.some((annotation) => annotation.type !== "file_path") && { citations: mapOpenAIResponsesCitations(ongoingAnnotations, providerOptionsName) },
|
|
7106
7195
|
providerMetadata: { [providerOptionsName]: {
|
|
7107
7196
|
itemId,
|
|
7108
7197
|
...phase != null && { phase },
|
|
@@ -7221,6 +7310,11 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7221
7310
|
ongoingToolCalls[value.output_index] = void 0;
|
|
7222
7311
|
hasFunctionCall = true;
|
|
7223
7312
|
const toolName = toolNameMapping.toCustomToolName(value.item.name);
|
|
7313
|
+
controller.enqueue({
|
|
7314
|
+
type: "tool-input-delta",
|
|
7315
|
+
id: value.item.call_id,
|
|
7316
|
+
delta: "\""
|
|
7317
|
+
});
|
|
7224
7318
|
controller.enqueue({
|
|
7225
7319
|
type: "tool-input-end",
|
|
7226
7320
|
id: value.item.call_id
|
|
@@ -7246,6 +7340,17 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7246
7340
|
result: { status: value.item.status }
|
|
7247
7341
|
} : { result: mapWebSearchOutput(value.item.action) }
|
|
7248
7342
|
});
|
|
7343
|
+
if (value.item.action?.type === "search") {
|
|
7344
|
+
for (const source of value.item.action.sources ?? []) if (source.type === "url") {
|
|
7345
|
+
hasWebSearchActionSources = true;
|
|
7346
|
+
controller.enqueue({
|
|
7347
|
+
type: "source",
|
|
7348
|
+
sourceType: "url",
|
|
7349
|
+
id: self.config.generateId?.() ?? generateId(),
|
|
7350
|
+
url: source.url
|
|
7351
|
+
});
|
|
7352
|
+
}
|
|
7353
|
+
}
|
|
7249
7354
|
} else if (value.item.type === "computer_call") {
|
|
7250
7355
|
ongoingToolCalls[value.output_index] = void 0;
|
|
7251
7356
|
if (value.item.call_id == null) {
|
|
@@ -7307,6 +7412,23 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7307
7412
|
})) ?? null
|
|
7308
7413
|
}
|
|
7309
7414
|
});
|
|
7415
|
+
for (const result of value.item.results ?? []) {
|
|
7416
|
+
hasFileSearchResults = true;
|
|
7417
|
+
if (retrievedFileIds.has(result.file_id)) continue;
|
|
7418
|
+
retrievedFileIds.add(result.file_id);
|
|
7419
|
+
controller.enqueue({
|
|
7420
|
+
type: "source",
|
|
7421
|
+
sourceType: "document",
|
|
7422
|
+
id: self.config.generateId?.() ?? generateId(),
|
|
7423
|
+
mediaType: "text/plain",
|
|
7424
|
+
title: result.filename,
|
|
7425
|
+
filename: result.filename,
|
|
7426
|
+
providerMetadata: { [providerOptionsName]: {
|
|
7427
|
+
type: "file_search",
|
|
7428
|
+
fileId: result.file_id
|
|
7429
|
+
} }
|
|
7430
|
+
});
|
|
7431
|
+
}
|
|
7310
7432
|
} else if (value.item.type === "code_interpreter_call") {
|
|
7311
7433
|
ongoingToolCalls[value.output_index] = void 0;
|
|
7312
7434
|
controller.enqueue({
|
|
@@ -7520,7 +7642,7 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7520
7642
|
if (toolCall != null) controller.enqueue({
|
|
7521
7643
|
type: "tool-input-delta",
|
|
7522
7644
|
id: toolCall.toolCallId,
|
|
7523
|
-
delta: value.delta
|
|
7645
|
+
delta: escapeJSONDelta(value.delta)
|
|
7524
7646
|
});
|
|
7525
7647
|
} else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
|
|
7526
7648
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -7704,52 +7826,8 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7704
7826
|
}
|
|
7705
7827
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
7706
7828
|
ongoingAnnotations.push(value.annotation);
|
|
7707
|
-
if (value.annotation.type === "url_citation")
|
|
7708
|
-
|
|
7709
|
-
sourceType: "url",
|
|
7710
|
-
id: self.config.generateId?.() ?? generateId(),
|
|
7711
|
-
url: value.annotation.url,
|
|
7712
|
-
title: value.annotation.title
|
|
7713
|
-
});
|
|
7714
|
-
else if (value.annotation.type === "file_citation") controller.enqueue({
|
|
7715
|
-
type: "source",
|
|
7716
|
-
sourceType: "document",
|
|
7717
|
-
id: self.config.generateId?.() ?? generateId(),
|
|
7718
|
-
mediaType: "text/plain",
|
|
7719
|
-
title: value.annotation.filename,
|
|
7720
|
-
filename: value.annotation.filename,
|
|
7721
|
-
providerMetadata: { [providerOptionsName]: {
|
|
7722
|
-
type: value.annotation.type,
|
|
7723
|
-
fileId: value.annotation.file_id,
|
|
7724
|
-
index: value.annotation.index
|
|
7725
|
-
} }
|
|
7726
|
-
});
|
|
7727
|
-
else if (value.annotation.type === "container_file_citation") controller.enqueue({
|
|
7728
|
-
type: "source",
|
|
7729
|
-
sourceType: "document",
|
|
7730
|
-
id: self.config.generateId?.() ?? generateId(),
|
|
7731
|
-
mediaType: "text/plain",
|
|
7732
|
-
title: value.annotation.filename,
|
|
7733
|
-
filename: value.annotation.filename,
|
|
7734
|
-
providerMetadata: { [providerOptionsName]: {
|
|
7735
|
-
type: value.annotation.type,
|
|
7736
|
-
fileId: value.annotation.file_id,
|
|
7737
|
-
containerId: value.annotation.container_id
|
|
7738
|
-
} }
|
|
7739
|
-
});
|
|
7740
|
-
else if (value.annotation.type === "file_path") controller.enqueue({
|
|
7741
|
-
type: "source",
|
|
7742
|
-
sourceType: "document",
|
|
7743
|
-
id: self.config.generateId?.() ?? generateId(),
|
|
7744
|
-
mediaType: "application/octet-stream",
|
|
7745
|
-
title: value.annotation.file_id,
|
|
7746
|
-
filename: value.annotation.file_id,
|
|
7747
|
-
providerMetadata: { [providerOptionsName]: {
|
|
7748
|
-
type: value.annotation.type,
|
|
7749
|
-
fileId: value.annotation.file_id,
|
|
7750
|
-
index: value.annotation.index
|
|
7751
|
-
} }
|
|
7752
|
-
});
|
|
7829
|
+
if (value.annotation.type === "url_citation" || value.annotation.type === "file_citation") fallbackAnnotations.push(value.annotation);
|
|
7830
|
+
else controller.enqueue(mapOpenAIResponsesAnnotationSource(value.annotation, providerOptionsName, self.config.generateId?.() ?? generateId()));
|
|
7753
7831
|
} else if (isErrorChunk(value)) {
|
|
7754
7832
|
encounteredStreamError = true;
|
|
7755
7833
|
finishReason = {
|
|
@@ -7763,6 +7841,10 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7763
7841
|
}
|
|
7764
7842
|
},
|
|
7765
7843
|
flush(controller) {
|
|
7844
|
+
for (const annotation of fallbackAnnotations) {
|
|
7845
|
+
if (annotation.type === "url_citation" && hasWebSearchActionSources || annotation.type === "file_citation" && hasFileSearchResults) continue;
|
|
7846
|
+
controller.enqueue(mapOpenAIResponsesAnnotationSource(annotation, providerOptionsName, self.config.generateId?.() ?? generateId()));
|
|
7847
|
+
}
|
|
7766
7848
|
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
7767
7849
|
if (!toolCall?.suppressInputStreaming) continue;
|
|
7768
7850
|
controller.enqueue({
|
|
@@ -10086,7 +10168,7 @@ var OpenAISkills = class {
|
|
|
10086
10168
|
};
|
|
10087
10169
|
//#endregion
|
|
10088
10170
|
//#region src/version.ts
|
|
10089
|
-
const VERSION = "4.0.
|
|
10171
|
+
const VERSION = "4.0.92";
|
|
10090
10172
|
//#endregion
|
|
10091
10173
|
//#region src/openai-provider.ts
|
|
10092
10174
|
/**
|