@ai-sdk/openai 2.0.27 → 2.0.29
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.mts +16 -29
- package/dist/index.d.ts +16 -29
- package/dist/index.js +107 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +103 -13
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +105 -15
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1807,8 +1807,20 @@ var openaiImageResponseSchema = z10.object({
|
|
|
1807
1807
|
});
|
|
1808
1808
|
|
|
1809
1809
|
// src/tool/code-interpreter.ts
|
|
1810
|
-
import {
|
|
1810
|
+
import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
|
|
1811
1811
|
import { z as z11 } from "zod/v4";
|
|
1812
|
+
var codeInterpreterInputSchema = z11.object({
|
|
1813
|
+
code: z11.string().nullish(),
|
|
1814
|
+
containerId: z11.string()
|
|
1815
|
+
});
|
|
1816
|
+
var codeInterpreterOutputSchema = z11.object({
|
|
1817
|
+
outputs: z11.array(
|
|
1818
|
+
z11.discriminatedUnion("type", [
|
|
1819
|
+
z11.object({ type: z11.literal("logs"), logs: z11.string() }),
|
|
1820
|
+
z11.object({ type: z11.literal("image"), url: z11.string() })
|
|
1821
|
+
])
|
|
1822
|
+
).nullish()
|
|
1823
|
+
});
|
|
1812
1824
|
var codeInterpreterArgsSchema = z11.object({
|
|
1813
1825
|
container: z11.union([
|
|
1814
1826
|
z11.string(),
|
|
@@ -1817,14 +1829,18 @@ var codeInterpreterArgsSchema = z11.object({
|
|
|
1817
1829
|
})
|
|
1818
1830
|
]).optional()
|
|
1819
1831
|
});
|
|
1820
|
-
var
|
|
1832
|
+
var codeInterpreterToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
|
|
1821
1833
|
id: "openai.code_interpreter",
|
|
1822
1834
|
name: "code_interpreter",
|
|
1823
|
-
inputSchema:
|
|
1835
|
+
inputSchema: codeInterpreterInputSchema,
|
|
1836
|
+
outputSchema: codeInterpreterOutputSchema
|
|
1824
1837
|
});
|
|
1838
|
+
var codeInterpreter = (args = {}) => {
|
|
1839
|
+
return codeInterpreterToolFactory(args);
|
|
1840
|
+
};
|
|
1825
1841
|
|
|
1826
1842
|
// src/tool/web-search.ts
|
|
1827
|
-
import { createProviderDefinedToolFactory as
|
|
1843
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory3 } from "@ai-sdk/provider-utils";
|
|
1828
1844
|
import { z as z12 } from "zod/v4";
|
|
1829
1845
|
var webSearchArgsSchema = z12.object({
|
|
1830
1846
|
filters: z12.object({
|
|
@@ -1839,7 +1855,7 @@ var webSearchArgsSchema = z12.object({
|
|
|
1839
1855
|
timezone: z12.string().optional()
|
|
1840
1856
|
}).optional()
|
|
1841
1857
|
});
|
|
1842
|
-
var
|
|
1858
|
+
var webSearchToolFactory = createProviderDefinedToolFactory3({
|
|
1843
1859
|
id: "openai.web_search",
|
|
1844
1860
|
name: "web_search",
|
|
1845
1861
|
inputSchema: z12.object({
|
|
@@ -1861,7 +1877,7 @@ var factory = createProviderDefinedToolFactory4({
|
|
|
1861
1877
|
})
|
|
1862
1878
|
});
|
|
1863
1879
|
var webSearch = (args = {}) => {
|
|
1864
|
-
return
|
|
1880
|
+
return webSearchToolFactory(args);
|
|
1865
1881
|
};
|
|
1866
1882
|
|
|
1867
1883
|
// src/openai-tools.ts
|
|
@@ -2269,6 +2285,18 @@ var webSearchCallItem = z14.object({
|
|
|
2269
2285
|
})
|
|
2270
2286
|
]).nullish()
|
|
2271
2287
|
});
|
|
2288
|
+
var codeInterpreterCallItem = z14.object({
|
|
2289
|
+
type: z14.literal("code_interpreter_call"),
|
|
2290
|
+
id: z14.string(),
|
|
2291
|
+
code: z14.string().nullable(),
|
|
2292
|
+
container_id: z14.string(),
|
|
2293
|
+
outputs: z14.array(
|
|
2294
|
+
z14.discriminatedUnion("type", [
|
|
2295
|
+
z14.object({ type: z14.literal("logs"), logs: z14.string() }),
|
|
2296
|
+
z14.object({ type: z14.literal("image"), url: z14.string() })
|
|
2297
|
+
])
|
|
2298
|
+
).nullable()
|
|
2299
|
+
});
|
|
2272
2300
|
var TOP_LOGPROBS_MAX = 20;
|
|
2273
2301
|
var LOGPROBS_SCHEMA = z14.array(
|
|
2274
2302
|
z14.object({
|
|
@@ -2310,7 +2338,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2310
2338
|
toolChoice,
|
|
2311
2339
|
responseFormat
|
|
2312
2340
|
}) {
|
|
2313
|
-
var _a, _b;
|
|
2341
|
+
var _a, _b, _c, _d;
|
|
2314
2342
|
const warnings = [];
|
|
2315
2343
|
const modelConfig = getResponsesModelConfig(this.modelId);
|
|
2316
2344
|
if (topK != null) {
|
|
@@ -2346,8 +2374,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2346
2374
|
schema: openaiResponsesProviderOptionsSchema
|
|
2347
2375
|
});
|
|
2348
2376
|
const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
|
|
2377
|
+
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
2349
2378
|
const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
|
|
2350
|
-
|
|
2379
|
+
include = topLogprobs ? Array.isArray(include) ? [...include, "message.output_text.logprobs"] : ["message.output_text.logprobs"] : include;
|
|
2380
|
+
const webSearchToolName = (_b = tools == null ? void 0 : tools.find(
|
|
2381
|
+
(tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
2382
|
+
)) == null ? void 0 : _b.name;
|
|
2383
|
+
include = webSearchToolName ? Array.isArray(include) ? [...include, "web_search_call.action.sources"] : ["web_search_call.action.sources"] : include;
|
|
2384
|
+
const codeInterpreterToolName = (_c = tools == null ? void 0 : tools.find(
|
|
2385
|
+
(tool) => tool.type === "provider-defined" && tool.id === "openai.code_interpreter"
|
|
2386
|
+
)) == null ? void 0 : _c.name;
|
|
2387
|
+
include = codeInterpreterToolName ? Array.isArray(include) ? [...include, "code_interpreter_call.outputs"] : ["code_interpreter_call.outputs"] : include;
|
|
2351
2388
|
const baseArgs = {
|
|
2352
2389
|
model: this.modelId,
|
|
2353
2390
|
input: messages,
|
|
@@ -2360,7 +2397,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2360
2397
|
format: responseFormat.schema != null ? {
|
|
2361
2398
|
type: "json_schema",
|
|
2362
2399
|
strict: strictJsonSchema,
|
|
2363
|
-
name: (
|
|
2400
|
+
name: (_d = responseFormat.name) != null ? _d : "response",
|
|
2364
2401
|
description: responseFormat.description,
|
|
2365
2402
|
schema: responseFormat.schema
|
|
2366
2403
|
} : { type: "json_object" }
|
|
@@ -2378,7 +2415,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2378
2415
|
user: openaiOptions == null ? void 0 : openaiOptions.user,
|
|
2379
2416
|
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
2380
2417
|
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
2381
|
-
include
|
|
2418
|
+
include,
|
|
2382
2419
|
prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
|
|
2383
2420
|
safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
|
|
2384
2421
|
top_logprobs: topLogprobs,
|
|
@@ -2456,6 +2493,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2456
2493
|
strictJsonSchema
|
|
2457
2494
|
});
|
|
2458
2495
|
return {
|
|
2496
|
+
webSearchToolName,
|
|
2459
2497
|
args: {
|
|
2460
2498
|
...baseArgs,
|
|
2461
2499
|
tools: openaiTools2,
|
|
@@ -2466,7 +2504,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2466
2504
|
}
|
|
2467
2505
|
async doGenerate(options) {
|
|
2468
2506
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2469
|
-
const {
|
|
2507
|
+
const {
|
|
2508
|
+
args: body,
|
|
2509
|
+
warnings,
|
|
2510
|
+
webSearchToolName
|
|
2511
|
+
} = await this.getArgs(options);
|
|
2470
2512
|
const url = this.config.url({
|
|
2471
2513
|
path: "/responses",
|
|
2472
2514
|
modelId: this.modelId
|
|
@@ -2517,12 +2559,16 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2517
2559
|
start_index: z14.number().nullish(),
|
|
2518
2560
|
end_index: z14.number().nullish(),
|
|
2519
2561
|
quote: z14.string().nullish()
|
|
2562
|
+
}),
|
|
2563
|
+
z14.object({
|
|
2564
|
+
type: z14.literal("container_file_citation")
|
|
2520
2565
|
})
|
|
2521
2566
|
])
|
|
2522
2567
|
)
|
|
2523
2568
|
})
|
|
2524
2569
|
)
|
|
2525
2570
|
}),
|
|
2571
|
+
codeInterpreterCallItem,
|
|
2526
2572
|
z14.object({
|
|
2527
2573
|
type: z14.literal("function_call"),
|
|
2528
2574
|
call_id: z14.string(),
|
|
@@ -2663,14 +2709,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2663
2709
|
content.push({
|
|
2664
2710
|
type: "tool-call",
|
|
2665
2711
|
toolCallId: part.id,
|
|
2666
|
-
toolName: "
|
|
2712
|
+
toolName: webSearchToolName != null ? webSearchToolName : "web_search",
|
|
2667
2713
|
input: JSON.stringify({ action: part.action }),
|
|
2668
2714
|
providerExecuted: true
|
|
2669
2715
|
});
|
|
2670
2716
|
content.push({
|
|
2671
2717
|
type: "tool-result",
|
|
2672
2718
|
toolCallId: part.id,
|
|
2673
|
-
toolName: "
|
|
2719
|
+
toolName: webSearchToolName != null ? webSearchToolName : "web_search",
|
|
2674
2720
|
result: { status: part.status },
|
|
2675
2721
|
providerExecuted: true
|
|
2676
2722
|
});
|
|
@@ -2718,6 +2764,28 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2718
2764
|
});
|
|
2719
2765
|
break;
|
|
2720
2766
|
}
|
|
2767
|
+
case "code_interpreter_call": {
|
|
2768
|
+
content.push({
|
|
2769
|
+
type: "tool-call",
|
|
2770
|
+
toolCallId: part.id,
|
|
2771
|
+
toolName: "code_interpreter",
|
|
2772
|
+
input: JSON.stringify({
|
|
2773
|
+
code: part.code,
|
|
2774
|
+
containerId: part.container_id
|
|
2775
|
+
}),
|
|
2776
|
+
providerExecuted: true
|
|
2777
|
+
});
|
|
2778
|
+
content.push({
|
|
2779
|
+
type: "tool-result",
|
|
2780
|
+
toolCallId: part.id,
|
|
2781
|
+
toolName: "code_interpreter",
|
|
2782
|
+
result: {
|
|
2783
|
+
outputs: part.outputs
|
|
2784
|
+
},
|
|
2785
|
+
providerExecuted: true
|
|
2786
|
+
});
|
|
2787
|
+
break;
|
|
2788
|
+
}
|
|
2721
2789
|
}
|
|
2722
2790
|
}
|
|
2723
2791
|
const providerMetadata = {
|
|
@@ -2755,7 +2823,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2755
2823
|
};
|
|
2756
2824
|
}
|
|
2757
2825
|
async doStream(options) {
|
|
2758
|
-
const {
|
|
2826
|
+
const {
|
|
2827
|
+
args: body,
|
|
2828
|
+
warnings,
|
|
2829
|
+
webSearchToolName
|
|
2830
|
+
} = await this.getArgs(options);
|
|
2759
2831
|
const { responseHeaders, value: response } = await postJsonToApi5({
|
|
2760
2832
|
url: this.config.url({
|
|
2761
2833
|
path: "/responses",
|
|
@@ -2816,13 +2888,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2816
2888
|
});
|
|
2817
2889
|
} else if (value.item.type === "web_search_call") {
|
|
2818
2890
|
ongoingToolCalls[value.output_index] = {
|
|
2819
|
-
toolName: "
|
|
2891
|
+
toolName: webSearchToolName != null ? webSearchToolName : "web_search",
|
|
2820
2892
|
toolCallId: value.item.id
|
|
2821
2893
|
};
|
|
2822
2894
|
controller.enqueue({
|
|
2823
2895
|
type: "tool-input-start",
|
|
2824
2896
|
id: value.item.id,
|
|
2825
|
-
toolName: "
|
|
2897
|
+
toolName: webSearchToolName != null ? webSearchToolName : "web_search"
|
|
2826
2898
|
});
|
|
2827
2899
|
} else if (value.item.type === "computer_call") {
|
|
2828
2900
|
ongoingToolCalls[value.output_index] = {
|
|
@@ -2957,6 +3029,26 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2957
3029
|
},
|
|
2958
3030
|
providerExecuted: true
|
|
2959
3031
|
});
|
|
3032
|
+
} else if (value.item.type === "code_interpreter_call") {
|
|
3033
|
+
controller.enqueue({
|
|
3034
|
+
type: "tool-call",
|
|
3035
|
+
toolCallId: value.item.id,
|
|
3036
|
+
toolName: "code_interpreter",
|
|
3037
|
+
input: JSON.stringify({
|
|
3038
|
+
code: value.item.code,
|
|
3039
|
+
containerId: value.item.container_id
|
|
3040
|
+
}),
|
|
3041
|
+
providerExecuted: true
|
|
3042
|
+
});
|
|
3043
|
+
controller.enqueue({
|
|
3044
|
+
type: "tool-result",
|
|
3045
|
+
toolCallId: value.item.id,
|
|
3046
|
+
toolName: "code_interpreter",
|
|
3047
|
+
result: {
|
|
3048
|
+
outputs: value.item.outputs
|
|
3049
|
+
},
|
|
3050
|
+
providerExecuted: true
|
|
3051
|
+
});
|
|
2960
3052
|
} else if (value.item.type === "message") {
|
|
2961
3053
|
controller.enqueue({
|
|
2962
3054
|
type: "text-end",
|
|
@@ -3202,6 +3294,7 @@ var responseOutputItemDoneSchema = z14.object({
|
|
|
3202
3294
|
arguments: z14.string(),
|
|
3203
3295
|
status: z14.literal("completed")
|
|
3204
3296
|
}),
|
|
3297
|
+
codeInterpreterCallItem,
|
|
3205
3298
|
webSearchCallItem,
|
|
3206
3299
|
z14.object({
|
|
3207
3300
|
type: z14.literal("computer_call"),
|