@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/internal/index.js
CHANGED
|
@@ -444,7 +444,23 @@ var webSearchPreviewArgsSchema = import_v44.z.object({
|
|
|
444
444
|
var webSearchPreview = (0, import_provider_utils4.createProviderDefinedToolFactory)({
|
|
445
445
|
id: "openai.web_search_preview",
|
|
446
446
|
name: "web_search_preview",
|
|
447
|
-
inputSchema: import_v44.z.object({
|
|
447
|
+
inputSchema: import_v44.z.object({
|
|
448
|
+
action: import_v44.z.discriminatedUnion("type", [
|
|
449
|
+
import_v44.z.object({
|
|
450
|
+
type: import_v44.z.literal("search"),
|
|
451
|
+
query: import_v44.z.string()
|
|
452
|
+
}),
|
|
453
|
+
import_v44.z.object({
|
|
454
|
+
type: import_v44.z.literal("open_page"),
|
|
455
|
+
url: import_v44.z.string()
|
|
456
|
+
}),
|
|
457
|
+
import_v44.z.object({
|
|
458
|
+
type: import_v44.z.literal("find"),
|
|
459
|
+
url: import_v44.z.string(),
|
|
460
|
+
pattern: import_v44.z.string()
|
|
461
|
+
})
|
|
462
|
+
]).nullish()
|
|
463
|
+
})
|
|
448
464
|
});
|
|
449
465
|
|
|
450
466
|
// src/chat/openai-chat-prepare-tools.ts
|
|
@@ -2187,9 +2203,10 @@ async function convertToOpenAIResponsesMessages({
|
|
|
2187
2203
|
};
|
|
2188
2204
|
} else if (part.mediaType === "application/pdf") {
|
|
2189
2205
|
if (part.data instanceof URL) {
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2206
|
+
return {
|
|
2207
|
+
type: "input_file",
|
|
2208
|
+
file_url: part.data.toString()
|
|
2209
|
+
};
|
|
2193
2210
|
}
|
|
2194
2211
|
return {
|
|
2195
2212
|
type: "input_file",
|
|
@@ -2446,6 +2463,26 @@ function prepareResponsesTools({
|
|
|
2446
2463
|
}
|
|
2447
2464
|
|
|
2448
2465
|
// src/responses/openai-responses-language-model.ts
|
|
2466
|
+
var webSearchCallItem = import_v416.z.object({
|
|
2467
|
+
type: import_v416.z.literal("web_search_call"),
|
|
2468
|
+
id: import_v416.z.string(),
|
|
2469
|
+
status: import_v416.z.string(),
|
|
2470
|
+
action: import_v416.z.discriminatedUnion("type", [
|
|
2471
|
+
import_v416.z.object({
|
|
2472
|
+
type: import_v416.z.literal("search"),
|
|
2473
|
+
query: import_v416.z.string()
|
|
2474
|
+
}),
|
|
2475
|
+
import_v416.z.object({
|
|
2476
|
+
type: import_v416.z.literal("open_page"),
|
|
2477
|
+
url: import_v416.z.string()
|
|
2478
|
+
}),
|
|
2479
|
+
import_v416.z.object({
|
|
2480
|
+
type: import_v416.z.literal("find"),
|
|
2481
|
+
url: import_v416.z.string(),
|
|
2482
|
+
pattern: import_v416.z.string()
|
|
2483
|
+
})
|
|
2484
|
+
]).nullish()
|
|
2485
|
+
});
|
|
2449
2486
|
var TOP_LOGPROBS_MAX = 20;
|
|
2450
2487
|
var LOGPROBS_SCHEMA = import_v416.z.array(
|
|
2451
2488
|
import_v416.z.object({
|
|
@@ -2463,7 +2500,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2463
2500
|
constructor(modelId, config) {
|
|
2464
2501
|
this.specificationVersion = "v2";
|
|
2465
2502
|
this.supportedUrls = {
|
|
2466
|
-
"image/*": [/^https?:\/\/.*$/]
|
|
2503
|
+
"image/*": [/^https?:\/\/.*$/],
|
|
2504
|
+
"application/pdf": [/^https?:\/\/.*$/]
|
|
2467
2505
|
};
|
|
2468
2506
|
this.modelId = modelId;
|
|
2469
2507
|
this.config = config;
|
|
@@ -2641,7 +2679,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2641
2679
|
};
|
|
2642
2680
|
}
|
|
2643
2681
|
async doGenerate(options) {
|
|
2644
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n
|
|
2682
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2645
2683
|
const { args: body, warnings } = await this.getArgs(options);
|
|
2646
2684
|
const url = this.config.url({
|
|
2647
2685
|
path: "/responses",
|
|
@@ -2704,15 +2742,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2704
2742
|
arguments: import_v416.z.string(),
|
|
2705
2743
|
id: import_v416.z.string()
|
|
2706
2744
|
}),
|
|
2707
|
-
|
|
2708
|
-
type: import_v416.z.literal("web_search_call"),
|
|
2709
|
-
id: import_v416.z.string(),
|
|
2710
|
-
status: import_v416.z.string().optional(),
|
|
2711
|
-
action: import_v416.z.object({
|
|
2712
|
-
type: import_v416.z.literal("search"),
|
|
2713
|
-
query: import_v416.z.string().optional()
|
|
2714
|
-
}).nullish()
|
|
2715
|
-
}),
|
|
2745
|
+
webSearchCallItem,
|
|
2716
2746
|
import_v416.z.object({
|
|
2717
2747
|
type: import_v416.z.literal("computer_call"),
|
|
2718
2748
|
id: import_v416.z.string(),
|
|
@@ -2843,17 +2873,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2843
2873
|
type: "tool-call",
|
|
2844
2874
|
toolCallId: part.id,
|
|
2845
2875
|
toolName: "web_search_preview",
|
|
2846
|
-
input: (
|
|
2876
|
+
input: JSON.stringify({ action: part.action }),
|
|
2847
2877
|
providerExecuted: true
|
|
2848
2878
|
});
|
|
2849
2879
|
content.push({
|
|
2850
2880
|
type: "tool-result",
|
|
2851
2881
|
toolCallId: part.id,
|
|
2852
2882
|
toolName: "web_search_preview",
|
|
2853
|
-
result: {
|
|
2854
|
-
status: part.status || "completed",
|
|
2855
|
-
...((_l = part.action) == null ? void 0 : _l.query) && { query: part.action.query }
|
|
2856
|
-
},
|
|
2883
|
+
result: { status: part.status },
|
|
2857
2884
|
providerExecuted: true
|
|
2858
2885
|
});
|
|
2859
2886
|
break;
|
|
@@ -2911,15 +2938,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2911
2938
|
return {
|
|
2912
2939
|
content,
|
|
2913
2940
|
finishReason: mapOpenAIResponseFinishReason({
|
|
2914
|
-
finishReason: (
|
|
2941
|
+
finishReason: (_j = response.incomplete_details) == null ? void 0 : _j.reason,
|
|
2915
2942
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
2916
2943
|
}),
|
|
2917
2944
|
usage: {
|
|
2918
2945
|
inputTokens: response.usage.input_tokens,
|
|
2919
2946
|
outputTokens: response.usage.output_tokens,
|
|
2920
2947
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
2921
|
-
reasoningTokens: (
|
|
2922
|
-
cachedInputTokens: (
|
|
2948
|
+
reasoningTokens: (_l = (_k = response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0,
|
|
2949
|
+
cachedInputTokens: (_n = (_m = response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0
|
|
2923
2950
|
},
|
|
2924
2951
|
request: { body },
|
|
2925
2952
|
response: {
|
|
@@ -2971,7 +2998,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2971
2998
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2972
2999
|
},
|
|
2973
3000
|
transform(chunk, controller) {
|
|
2974
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p
|
|
3001
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2975
3002
|
if (options.includeRawChunks) {
|
|
2976
3003
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2977
3004
|
}
|
|
@@ -3078,20 +3105,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3078
3105
|
type: "tool-call",
|
|
3079
3106
|
toolCallId: value.item.id,
|
|
3080
3107
|
toolName: "web_search_preview",
|
|
3081
|
-
input: (
|
|
3108
|
+
input: JSON.stringify({ action: value.item.action }),
|
|
3082
3109
|
providerExecuted: true
|
|
3083
3110
|
});
|
|
3084
3111
|
controller.enqueue({
|
|
3085
3112
|
type: "tool-result",
|
|
3086
3113
|
toolCallId: value.item.id,
|
|
3087
3114
|
toolName: "web_search_preview",
|
|
3088
|
-
result: {
|
|
3089
|
-
type: "web_search_tool_result",
|
|
3090
|
-
status: value.item.status || "completed",
|
|
3091
|
-
...((_d = value.item.action) == null ? void 0 : _d.query) && {
|
|
3092
|
-
query: value.item.action.query
|
|
3093
|
-
}
|
|
3094
|
-
},
|
|
3115
|
+
result: { status: value.item.status },
|
|
3095
3116
|
providerExecuted: true
|
|
3096
3117
|
});
|
|
3097
3118
|
} else if (value.item.type === "computer_call") {
|
|
@@ -3158,7 +3179,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3158
3179
|
providerMetadata: {
|
|
3159
3180
|
openai: {
|
|
3160
3181
|
itemId: value.item.id,
|
|
3161
|
-
reasoningEncryptedContent: (
|
|
3182
|
+
reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
3162
3183
|
}
|
|
3163
3184
|
}
|
|
3164
3185
|
});
|
|
@@ -3193,7 +3214,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3193
3214
|
}
|
|
3194
3215
|
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
3195
3216
|
if (value.summary_index > 0) {
|
|
3196
|
-
(
|
|
3217
|
+
(_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
|
|
3197
3218
|
value.summary_index
|
|
3198
3219
|
);
|
|
3199
3220
|
controller.enqueue({
|
|
@@ -3202,7 +3223,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3202
3223
|
providerMetadata: {
|
|
3203
3224
|
openai: {
|
|
3204
3225
|
itemId: value.item_id,
|
|
3205
|
-
reasoningEncryptedContent: (
|
|
3226
|
+
reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
|
|
3206
3227
|
}
|
|
3207
3228
|
}
|
|
3208
3229
|
});
|
|
@@ -3220,20 +3241,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3220
3241
|
});
|
|
3221
3242
|
} else if (isResponseFinishedChunk(value)) {
|
|
3222
3243
|
finishReason = mapOpenAIResponseFinishReason({
|
|
3223
|
-
finishReason: (
|
|
3244
|
+
finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
|
|
3224
3245
|
hasToolCalls
|
|
3225
3246
|
});
|
|
3226
3247
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
3227
3248
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
3228
3249
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
3229
|
-
usage.reasoningTokens = (
|
|
3230
|
-
usage.cachedInputTokens = (
|
|
3250
|
+
usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
|
|
3251
|
+
usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
|
|
3231
3252
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
3232
3253
|
if (value.annotation.type === "url_citation") {
|
|
3233
3254
|
controller.enqueue({
|
|
3234
3255
|
type: "source",
|
|
3235
3256
|
sourceType: "url",
|
|
3236
|
-
id: (
|
|
3257
|
+
id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : (0, import_provider_utils14.generateId)(),
|
|
3237
3258
|
url: value.annotation.url,
|
|
3238
3259
|
title: value.annotation.title
|
|
3239
3260
|
});
|
|
@@ -3241,7 +3262,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3241
3262
|
controller.enqueue({
|
|
3242
3263
|
type: "source",
|
|
3243
3264
|
sourceType: "document",
|
|
3244
|
-
id: (
|
|
3265
|
+
id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : (0, import_provider_utils14.generateId)(),
|
|
3245
3266
|
mediaType: "text/plain",
|
|
3246
3267
|
title: value.annotation.quote,
|
|
3247
3268
|
filename: value.annotation.file_id
|
|
@@ -3381,15 +3402,7 @@ var responseOutputItemDoneSchema = import_v416.z.object({
|
|
|
3381
3402
|
arguments: import_v416.z.string(),
|
|
3382
3403
|
status: import_v416.z.literal("completed")
|
|
3383
3404
|
}),
|
|
3384
|
-
|
|
3385
|
-
type: import_v416.z.literal("web_search_call"),
|
|
3386
|
-
id: import_v416.z.string(),
|
|
3387
|
-
status: import_v416.z.literal("completed"),
|
|
3388
|
-
action: import_v416.z.object({
|
|
3389
|
-
type: import_v416.z.literal("search"),
|
|
3390
|
-
query: import_v416.z.string().optional()
|
|
3391
|
-
}).nullish()
|
|
3392
|
-
}),
|
|
3405
|
+
webSearchCallItem,
|
|
3393
3406
|
import_v416.z.object({
|
|
3394
3407
|
type: import_v416.z.literal("computer_call"),
|
|
3395
3408
|
id: import_v416.z.string(),
|