@ai-sdk/openai 2.0.26 → 2.0.28
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 +57 -8
- package/dist/index.d.ts +57 -8
- package/dist/index.js +78 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -25
- 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 +32 -24
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +32 -24
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -359,23 +359,11 @@ var compoundFilterSchema = z3.object({
|
|
|
359
359
|
});
|
|
360
360
|
var filtersSchema = z3.union([comparisonFilterSchema, compoundFilterSchema]);
|
|
361
361
|
var fileSearchArgsSchema = z3.object({
|
|
362
|
-
/**
|
|
363
|
-
* List of vector store IDs to search through. If not provided, searches all available vector stores.
|
|
364
|
-
*/
|
|
365
362
|
vectorStoreIds: z3.array(z3.string()).optional(),
|
|
366
|
-
/**
|
|
367
|
-
* Maximum number of search results to return. Defaults to 10.
|
|
368
|
-
*/
|
|
369
363
|
maxNumResults: z3.number().optional(),
|
|
370
|
-
/**
|
|
371
|
-
* Ranking options for the search.
|
|
372
|
-
*/
|
|
373
364
|
ranking: z3.object({
|
|
374
365
|
ranker: z3.enum(["auto", "default-2024-08-21"]).optional()
|
|
375
366
|
}).optional(),
|
|
376
|
-
/**
|
|
377
|
-
* A filter to apply based on file attributes.
|
|
378
|
-
*/
|
|
379
367
|
filters: filtersSchema.optional()
|
|
380
368
|
});
|
|
381
369
|
var fileSearch = createProviderDefinedToolFactory({
|
|
@@ -1829,11 +1817,14 @@ var codeInterpreterArgsSchema = z11.object({
|
|
|
1829
1817
|
})
|
|
1830
1818
|
]).optional()
|
|
1831
1819
|
});
|
|
1832
|
-
var
|
|
1820
|
+
var codeInterpreterToolFactory = createProviderDefinedToolFactory3({
|
|
1833
1821
|
id: "openai.code_interpreter",
|
|
1834
1822
|
name: "code_interpreter",
|
|
1835
1823
|
inputSchema: z11.object({})
|
|
1836
1824
|
});
|
|
1825
|
+
var codeInterpreter = (args = {}) => {
|
|
1826
|
+
return codeInterpreterToolFactory(args);
|
|
1827
|
+
};
|
|
1837
1828
|
|
|
1838
1829
|
// src/tool/web-search.ts
|
|
1839
1830
|
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory4 } from "@ai-sdk/provider-utils";
|
|
@@ -1851,7 +1842,7 @@ var webSearchArgsSchema = z12.object({
|
|
|
1851
1842
|
timezone: z12.string().optional()
|
|
1852
1843
|
}).optional()
|
|
1853
1844
|
});
|
|
1854
|
-
var
|
|
1845
|
+
var webSearchToolFactory = createProviderDefinedToolFactory4({
|
|
1855
1846
|
id: "openai.web_search",
|
|
1856
1847
|
name: "web_search",
|
|
1857
1848
|
inputSchema: z12.object({
|
|
@@ -1873,14 +1864,56 @@ var factory = createProviderDefinedToolFactory4({
|
|
|
1873
1864
|
})
|
|
1874
1865
|
});
|
|
1875
1866
|
var webSearch = (args = {}) => {
|
|
1876
|
-
return
|
|
1867
|
+
return webSearchToolFactory(args);
|
|
1877
1868
|
};
|
|
1878
1869
|
|
|
1879
1870
|
// src/openai-tools.ts
|
|
1880
1871
|
var openaiTools = {
|
|
1872
|
+
/**
|
|
1873
|
+
* The Code Interpreter tool allows models to write and run Python code in a
|
|
1874
|
+
* sandboxed environment to solve complex problems in domains like data analysis,
|
|
1875
|
+
* coding, and math.
|
|
1876
|
+
*
|
|
1877
|
+
* @param container - The container to use for the code interpreter.
|
|
1878
|
+
*
|
|
1879
|
+
* Must have name `code_interpreter`.
|
|
1880
|
+
*/
|
|
1881
1881
|
codeInterpreter,
|
|
1882
|
+
/**
|
|
1883
|
+
* File search is a tool available in the Responses API. It enables models to
|
|
1884
|
+
* retrieve information in a knowledge base of previously uploaded files through
|
|
1885
|
+
* semantic and keyword search.
|
|
1886
|
+
*
|
|
1887
|
+
* Must have name `file_search`.
|
|
1888
|
+
*
|
|
1889
|
+
* @param vectorStoreIds - The vector store IDs to use for the file search.
|
|
1890
|
+
* @param maxNumResults - The maximum number of results to return.
|
|
1891
|
+
* @param ranking - The ranking options to use for the file search.
|
|
1892
|
+
* @param filters - The filters to use for the file search.
|
|
1893
|
+
*/
|
|
1882
1894
|
fileSearch,
|
|
1895
|
+
/**
|
|
1896
|
+
* Web search allows models to access up-to-date information from the internet
|
|
1897
|
+
* and provide answers with sourced citations.
|
|
1898
|
+
*
|
|
1899
|
+
* Must have name `web_search_preview`.
|
|
1900
|
+
*
|
|
1901
|
+
* @param searchContextSize - The search context size to use for the web search.
|
|
1902
|
+
* @param userLocation - The user location to use for the web search.
|
|
1903
|
+
*
|
|
1904
|
+
* @deprecated Use `webSearch` instead.
|
|
1905
|
+
*/
|
|
1883
1906
|
webSearchPreview,
|
|
1907
|
+
/**
|
|
1908
|
+
* Web search allows models to access up-to-date information from the internet
|
|
1909
|
+
* and provide answers with sourced citations.
|
|
1910
|
+
*
|
|
1911
|
+
* Must have name `web_search`.
|
|
1912
|
+
*
|
|
1913
|
+
* @param filters - The filters to use for the web search.
|
|
1914
|
+
* @param searchContextSize - The search context size to use for the web search.
|
|
1915
|
+
* @param userLocation - The user location to use for the web search.
|
|
1916
|
+
*/
|
|
1884
1917
|
webSearch
|
|
1885
1918
|
};
|
|
1886
1919
|
|
|
@@ -2280,7 +2313,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2280
2313
|
toolChoice,
|
|
2281
2314
|
responseFormat
|
|
2282
2315
|
}) {
|
|
2283
|
-
var _a, _b;
|
|
2316
|
+
var _a, _b, _c;
|
|
2284
2317
|
const warnings = [];
|
|
2285
2318
|
const modelConfig = getResponsesModelConfig(this.modelId);
|
|
2286
2319
|
if (topK != null) {
|
|
@@ -2316,8 +2349,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2316
2349
|
schema: openaiResponsesProviderOptionsSchema
|
|
2317
2350
|
});
|
|
2318
2351
|
const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
|
|
2352
|
+
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
2319
2353
|
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;
|
|
2320
|
-
|
|
2354
|
+
include = topLogprobs ? Array.isArray(include) ? [...include, "message.output_text.logprobs"] : ["message.output_text.logprobs"] : include;
|
|
2355
|
+
const webSearchToolName = (_b = tools == null ? void 0 : tools.find(
|
|
2356
|
+
(tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
2357
|
+
)) == null ? void 0 : _b.name;
|
|
2358
|
+
include = webSearchToolName ? Array.isArray(include) ? [...include, "web_search_call.action.sources"] : ["web_search_call.action.sources"] : include;
|
|
2321
2359
|
const baseArgs = {
|
|
2322
2360
|
model: this.modelId,
|
|
2323
2361
|
input: messages,
|
|
@@ -2330,7 +2368,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2330
2368
|
format: responseFormat.schema != null ? {
|
|
2331
2369
|
type: "json_schema",
|
|
2332
2370
|
strict: strictJsonSchema,
|
|
2333
|
-
name: (
|
|
2371
|
+
name: (_c = responseFormat.name) != null ? _c : "response",
|
|
2334
2372
|
description: responseFormat.description,
|
|
2335
2373
|
schema: responseFormat.schema
|
|
2336
2374
|
} : { type: "json_object" }
|
|
@@ -2348,7 +2386,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2348
2386
|
user: openaiOptions == null ? void 0 : openaiOptions.user,
|
|
2349
2387
|
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
2350
2388
|
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
2351
|
-
include
|
|
2389
|
+
include,
|
|
2352
2390
|
prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
|
|
2353
2391
|
safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
|
|
2354
2392
|
top_logprobs: topLogprobs,
|
|
@@ -2426,6 +2464,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2426
2464
|
strictJsonSchema
|
|
2427
2465
|
});
|
|
2428
2466
|
return {
|
|
2467
|
+
webSearchToolName,
|
|
2429
2468
|
args: {
|
|
2430
2469
|
...baseArgs,
|
|
2431
2470
|
tools: openaiTools2,
|
|
@@ -2436,7 +2475,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2436
2475
|
}
|
|
2437
2476
|
async doGenerate(options) {
|
|
2438
2477
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2439
|
-
const {
|
|
2478
|
+
const {
|
|
2479
|
+
args: body,
|
|
2480
|
+
warnings,
|
|
2481
|
+
webSearchToolName
|
|
2482
|
+
} = await this.getArgs(options);
|
|
2440
2483
|
const url = this.config.url({
|
|
2441
2484
|
path: "/responses",
|
|
2442
2485
|
modelId: this.modelId
|
|
@@ -2487,12 +2530,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2487
2530
|
start_index: z14.number().nullish(),
|
|
2488
2531
|
end_index: z14.number().nullish(),
|
|
2489
2532
|
quote: z14.string().nullish()
|
|
2533
|
+
}),
|
|
2534
|
+
z14.object({
|
|
2535
|
+
type: z14.literal("container_file_citation")
|
|
2490
2536
|
})
|
|
2491
2537
|
])
|
|
2492
2538
|
)
|
|
2493
2539
|
})
|
|
2494
2540
|
)
|
|
2495
2541
|
}),
|
|
2542
|
+
z14.object({
|
|
2543
|
+
type: z14.literal("code_interpreter_call")
|
|
2544
|
+
}),
|
|
2496
2545
|
z14.object({
|
|
2497
2546
|
type: z14.literal("function_call"),
|
|
2498
2547
|
call_id: z14.string(),
|
|
@@ -2633,14 +2682,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2633
2682
|
content.push({
|
|
2634
2683
|
type: "tool-call",
|
|
2635
2684
|
toolCallId: part.id,
|
|
2636
|
-
toolName: "
|
|
2685
|
+
toolName: webSearchToolName != null ? webSearchToolName : "web_search",
|
|
2637
2686
|
input: JSON.stringify({ action: part.action }),
|
|
2638
2687
|
providerExecuted: true
|
|
2639
2688
|
});
|
|
2640
2689
|
content.push({
|
|
2641
2690
|
type: "tool-result",
|
|
2642
2691
|
toolCallId: part.id,
|
|
2643
|
-
toolName: "
|
|
2692
|
+
toolName: webSearchToolName != null ? webSearchToolName : "web_search",
|
|
2644
2693
|
result: { status: part.status },
|
|
2645
2694
|
providerExecuted: true
|
|
2646
2695
|
});
|
|
@@ -2725,7 +2774,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2725
2774
|
};
|
|
2726
2775
|
}
|
|
2727
2776
|
async doStream(options) {
|
|
2728
|
-
const {
|
|
2777
|
+
const {
|
|
2778
|
+
args: body,
|
|
2779
|
+
warnings,
|
|
2780
|
+
webSearchToolName
|
|
2781
|
+
} = await this.getArgs(options);
|
|
2729
2782
|
const { responseHeaders, value: response } = await postJsonToApi5({
|
|
2730
2783
|
url: this.config.url({
|
|
2731
2784
|
path: "/responses",
|
|
@@ -2786,13 +2839,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2786
2839
|
});
|
|
2787
2840
|
} else if (value.item.type === "web_search_call") {
|
|
2788
2841
|
ongoingToolCalls[value.output_index] = {
|
|
2789
|
-
toolName: "
|
|
2842
|
+
toolName: webSearchToolName != null ? webSearchToolName : "web_search",
|
|
2790
2843
|
toolCallId: value.item.id
|
|
2791
2844
|
};
|
|
2792
2845
|
controller.enqueue({
|
|
2793
2846
|
type: "tool-input-start",
|
|
2794
2847
|
id: value.item.id,
|
|
2795
|
-
toolName: "
|
|
2848
|
+
toolName: webSearchToolName != null ? webSearchToolName : "web_search"
|
|
2796
2849
|
});
|
|
2797
2850
|
} else if (value.item.type === "computer_call") {
|
|
2798
2851
|
ongoingToolCalls[value.output_index] = {
|