@ai-sdk/openai 2.0.16 → 2.0.18
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 +18 -0
- package/dist/index.js +62 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -49
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +62 -49
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +62 -49
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -426,7 +426,23 @@ var webSearchPreviewArgsSchema = z4.object({
|
|
|
426
426
|
var webSearchPreview = createProviderDefinedToolFactory2({
|
|
427
427
|
id: "openai.web_search_preview",
|
|
428
428
|
name: "web_search_preview",
|
|
429
|
-
inputSchema: z4.object({
|
|
429
|
+
inputSchema: z4.object({
|
|
430
|
+
action: z4.discriminatedUnion("type", [
|
|
431
|
+
z4.object({
|
|
432
|
+
type: z4.literal("search"),
|
|
433
|
+
query: z4.string()
|
|
434
|
+
}),
|
|
435
|
+
z4.object({
|
|
436
|
+
type: z4.literal("open_page"),
|
|
437
|
+
url: z4.string()
|
|
438
|
+
}),
|
|
439
|
+
z4.object({
|
|
440
|
+
type: z4.literal("find"),
|
|
441
|
+
url: z4.string(),
|
|
442
|
+
pattern: z4.string()
|
|
443
|
+
})
|
|
444
|
+
]).nullish()
|
|
445
|
+
})
|
|
430
446
|
});
|
|
431
447
|
|
|
432
448
|
// src/chat/openai-chat-prepare-tools.ts
|
|
@@ -1908,9 +1924,10 @@ async function convertToOpenAIResponsesMessages({
|
|
|
1908
1924
|
};
|
|
1909
1925
|
} else if (part.mediaType === "application/pdf") {
|
|
1910
1926
|
if (part.data instanceof URL) {
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1927
|
+
return {
|
|
1928
|
+
type: "input_file",
|
|
1929
|
+
file_url: part.data.toString()
|
|
1930
|
+
};
|
|
1914
1931
|
}
|
|
1915
1932
|
return {
|
|
1916
1933
|
type: "input_file",
|
|
@@ -2150,6 +2167,26 @@ function prepareResponsesTools({
|
|
|
2150
2167
|
}
|
|
2151
2168
|
|
|
2152
2169
|
// src/responses/openai-responses-language-model.ts
|
|
2170
|
+
var webSearchCallItem = z13.object({
|
|
2171
|
+
type: z13.literal("web_search_call"),
|
|
2172
|
+
id: z13.string(),
|
|
2173
|
+
status: z13.string(),
|
|
2174
|
+
action: z13.discriminatedUnion("type", [
|
|
2175
|
+
z13.object({
|
|
2176
|
+
type: z13.literal("search"),
|
|
2177
|
+
query: z13.string()
|
|
2178
|
+
}),
|
|
2179
|
+
z13.object({
|
|
2180
|
+
type: z13.literal("open_page"),
|
|
2181
|
+
url: z13.string()
|
|
2182
|
+
}),
|
|
2183
|
+
z13.object({
|
|
2184
|
+
type: z13.literal("find"),
|
|
2185
|
+
url: z13.string(),
|
|
2186
|
+
pattern: z13.string()
|
|
2187
|
+
})
|
|
2188
|
+
]).nullish()
|
|
2189
|
+
});
|
|
2153
2190
|
var TOP_LOGPROBS_MAX = 20;
|
|
2154
2191
|
var LOGPROBS_SCHEMA = z13.array(
|
|
2155
2192
|
z13.object({
|
|
@@ -2167,7 +2204,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2167
2204
|
constructor(modelId, config) {
|
|
2168
2205
|
this.specificationVersion = "v2";
|
|
2169
2206
|
this.supportedUrls = {
|
|
2170
|
-
"image/*": [/^https?:\/\/.*$/]
|
|
2207
|
+
"image/*": [/^https?:\/\/.*$/],
|
|
2208
|
+
"application/pdf": [/^https?:\/\/.*$/]
|
|
2171
2209
|
};
|
|
2172
2210
|
this.modelId = modelId;
|
|
2173
2211
|
this.config = config;
|
|
@@ -2345,7 +2383,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2345
2383
|
};
|
|
2346
2384
|
}
|
|
2347
2385
|
async doGenerate(options) {
|
|
2348
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n
|
|
2386
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2349
2387
|
const { args: body, warnings } = await this.getArgs(options);
|
|
2350
2388
|
const url = this.config.url({
|
|
2351
2389
|
path: "/responses",
|
|
@@ -2408,15 +2446,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2408
2446
|
arguments: z13.string(),
|
|
2409
2447
|
id: z13.string()
|
|
2410
2448
|
}),
|
|
2411
|
-
|
|
2412
|
-
type: z13.literal("web_search_call"),
|
|
2413
|
-
id: z13.string(),
|
|
2414
|
-
status: z13.string().optional(),
|
|
2415
|
-
action: z13.object({
|
|
2416
|
-
type: z13.literal("search"),
|
|
2417
|
-
query: z13.string().optional()
|
|
2418
|
-
}).nullish()
|
|
2419
|
-
}),
|
|
2449
|
+
webSearchCallItem,
|
|
2420
2450
|
z13.object({
|
|
2421
2451
|
type: z13.literal("computer_call"),
|
|
2422
2452
|
id: z13.string(),
|
|
@@ -2547,17 +2577,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2547
2577
|
type: "tool-call",
|
|
2548
2578
|
toolCallId: part.id,
|
|
2549
2579
|
toolName: "web_search_preview",
|
|
2550
|
-
input: (
|
|
2580
|
+
input: JSON.stringify({ action: part.action }),
|
|
2551
2581
|
providerExecuted: true
|
|
2552
2582
|
});
|
|
2553
2583
|
content.push({
|
|
2554
2584
|
type: "tool-result",
|
|
2555
2585
|
toolCallId: part.id,
|
|
2556
2586
|
toolName: "web_search_preview",
|
|
2557
|
-
result: {
|
|
2558
|
-
status: part.status || "completed",
|
|
2559
|
-
...((_l = part.action) == null ? void 0 : _l.query) && { query: part.action.query }
|
|
2560
|
-
},
|
|
2587
|
+
result: { status: part.status },
|
|
2561
2588
|
providerExecuted: true
|
|
2562
2589
|
});
|
|
2563
2590
|
break;
|
|
@@ -2615,15 +2642,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2615
2642
|
return {
|
|
2616
2643
|
content,
|
|
2617
2644
|
finishReason: mapOpenAIResponseFinishReason({
|
|
2618
|
-
finishReason: (
|
|
2645
|
+
finishReason: (_j = response.incomplete_details) == null ? void 0 : _j.reason,
|
|
2619
2646
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
2620
2647
|
}),
|
|
2621
2648
|
usage: {
|
|
2622
2649
|
inputTokens: response.usage.input_tokens,
|
|
2623
2650
|
outputTokens: response.usage.output_tokens,
|
|
2624
2651
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
2625
|
-
reasoningTokens: (
|
|
2626
|
-
cachedInputTokens: (
|
|
2652
|
+
reasoningTokens: (_l = (_k = response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0,
|
|
2653
|
+
cachedInputTokens: (_n = (_m = response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0
|
|
2627
2654
|
},
|
|
2628
2655
|
request: { body },
|
|
2629
2656
|
response: {
|
|
@@ -2675,7 +2702,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2675
2702
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2676
2703
|
},
|
|
2677
2704
|
transform(chunk, controller) {
|
|
2678
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p
|
|
2705
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2679
2706
|
if (options.includeRawChunks) {
|
|
2680
2707
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2681
2708
|
}
|
|
@@ -2782,20 +2809,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2782
2809
|
type: "tool-call",
|
|
2783
2810
|
toolCallId: value.item.id,
|
|
2784
2811
|
toolName: "web_search_preview",
|
|
2785
|
-
input: (
|
|
2812
|
+
input: JSON.stringify({ action: value.item.action }),
|
|
2786
2813
|
providerExecuted: true
|
|
2787
2814
|
});
|
|
2788
2815
|
controller.enqueue({
|
|
2789
2816
|
type: "tool-result",
|
|
2790
2817
|
toolCallId: value.item.id,
|
|
2791
2818
|
toolName: "web_search_preview",
|
|
2792
|
-
result: {
|
|
2793
|
-
type: "web_search_tool_result",
|
|
2794
|
-
status: value.item.status || "completed",
|
|
2795
|
-
...((_d = value.item.action) == null ? void 0 : _d.query) && {
|
|
2796
|
-
query: value.item.action.query
|
|
2797
|
-
}
|
|
2798
|
-
},
|
|
2819
|
+
result: { status: value.item.status },
|
|
2799
2820
|
providerExecuted: true
|
|
2800
2821
|
});
|
|
2801
2822
|
} else if (value.item.type === "computer_call") {
|
|
@@ -2862,7 +2883,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2862
2883
|
providerMetadata: {
|
|
2863
2884
|
openai: {
|
|
2864
2885
|
itemId: value.item.id,
|
|
2865
|
-
reasoningEncryptedContent: (
|
|
2886
|
+
reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
2866
2887
|
}
|
|
2867
2888
|
}
|
|
2868
2889
|
});
|
|
@@ -2897,7 +2918,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2897
2918
|
}
|
|
2898
2919
|
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
2899
2920
|
if (value.summary_index > 0) {
|
|
2900
|
-
(
|
|
2921
|
+
(_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
|
|
2901
2922
|
value.summary_index
|
|
2902
2923
|
);
|
|
2903
2924
|
controller.enqueue({
|
|
@@ -2906,7 +2927,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2906
2927
|
providerMetadata: {
|
|
2907
2928
|
openai: {
|
|
2908
2929
|
itemId: value.item_id,
|
|
2909
|
-
reasoningEncryptedContent: (
|
|
2930
|
+
reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
|
|
2910
2931
|
}
|
|
2911
2932
|
}
|
|
2912
2933
|
});
|
|
@@ -2924,20 +2945,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2924
2945
|
});
|
|
2925
2946
|
} else if (isResponseFinishedChunk(value)) {
|
|
2926
2947
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2927
|
-
finishReason: (
|
|
2948
|
+
finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
|
|
2928
2949
|
hasToolCalls
|
|
2929
2950
|
});
|
|
2930
2951
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2931
2952
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2932
2953
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2933
|
-
usage.reasoningTokens = (
|
|
2934
|
-
usage.cachedInputTokens = (
|
|
2954
|
+
usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
|
|
2955
|
+
usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
|
|
2935
2956
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2936
2957
|
if (value.annotation.type === "url_citation") {
|
|
2937
2958
|
controller.enqueue({
|
|
2938
2959
|
type: "source",
|
|
2939
2960
|
sourceType: "url",
|
|
2940
|
-
id: (
|
|
2961
|
+
id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
|
|
2941
2962
|
url: value.annotation.url,
|
|
2942
2963
|
title: value.annotation.title
|
|
2943
2964
|
});
|
|
@@ -2945,7 +2966,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2945
2966
|
controller.enqueue({
|
|
2946
2967
|
type: "source",
|
|
2947
2968
|
sourceType: "document",
|
|
2948
|
-
id: (
|
|
2969
|
+
id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2(),
|
|
2949
2970
|
mediaType: "text/plain",
|
|
2950
2971
|
title: value.annotation.quote,
|
|
2951
2972
|
filename: value.annotation.file_id
|
|
@@ -3085,15 +3106,7 @@ var responseOutputItemDoneSchema = z13.object({
|
|
|
3085
3106
|
arguments: z13.string(),
|
|
3086
3107
|
status: z13.literal("completed")
|
|
3087
3108
|
}),
|
|
3088
|
-
|
|
3089
|
-
type: z13.literal("web_search_call"),
|
|
3090
|
-
id: z13.string(),
|
|
3091
|
-
status: z13.literal("completed"),
|
|
3092
|
-
action: z13.object({
|
|
3093
|
-
type: z13.literal("search"),
|
|
3094
|
-
query: z13.string().optional()
|
|
3095
|
-
}).nullish()
|
|
3096
|
-
}),
|
|
3109
|
+
webSearchCallItem,
|
|
3097
3110
|
z13.object({
|
|
3098
3111
|
type: z13.literal("computer_call"),
|
|
3099
3112
|
id: z13.string(),
|