@zenning/openai 1.4.2 → 1.4.4
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/dist/index.d.mts +134 -122
- package/dist/index.d.ts +134 -122
- package/dist/index.js +575 -269
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +575 -269
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.js +500 -181
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +500 -181
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/internal/dist/index.js
CHANGED
|
@@ -1898,7 +1898,7 @@ var OpenAISpeechModel = class {
|
|
|
1898
1898
|
|
|
1899
1899
|
// src/responses/openai-responses-language-model.ts
|
|
1900
1900
|
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
1901
|
-
var
|
|
1901
|
+
var import_zod12 = require("zod");
|
|
1902
1902
|
|
|
1903
1903
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1904
1904
|
var import_provider7 = require("@ai-sdk/provider");
|
|
@@ -2042,6 +2042,71 @@ function mapOpenAIResponseFinishReason({
|
|
|
2042
2042
|
|
|
2043
2043
|
// src/responses/openai-responses-prepare-tools.ts
|
|
2044
2044
|
var import_provider8 = require("@ai-sdk/provider");
|
|
2045
|
+
|
|
2046
|
+
// src/tool/code-interpreter.ts
|
|
2047
|
+
var import_zod8 = require("zod");
|
|
2048
|
+
var codeInterpreterArgsSchema = import_zod8.z.object({
|
|
2049
|
+
container: import_zod8.z.union([
|
|
2050
|
+
import_zod8.z.string(),
|
|
2051
|
+
import_zod8.z.object({
|
|
2052
|
+
fileIds: import_zod8.z.array(import_zod8.z.string()).optional()
|
|
2053
|
+
})
|
|
2054
|
+
]).optional()
|
|
2055
|
+
});
|
|
2056
|
+
|
|
2057
|
+
// src/tool/file-search.ts
|
|
2058
|
+
var import_zod9 = require("zod");
|
|
2059
|
+
var comparisonFilterSchema = import_zod9.z.object({
|
|
2060
|
+
key: import_zod9.z.string(),
|
|
2061
|
+
type: import_zod9.z.enum(["eq", "ne", "gt", "gte", "lt", "lte"]),
|
|
2062
|
+
value: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.number(), import_zod9.z.boolean()])
|
|
2063
|
+
});
|
|
2064
|
+
var compoundFilterSchema = import_zod9.z.object({
|
|
2065
|
+
type: import_zod9.z.enum(["and", "or"]),
|
|
2066
|
+
filters: import_zod9.z.array(
|
|
2067
|
+
import_zod9.z.union([comparisonFilterSchema, import_zod9.z.lazy(() => compoundFilterSchema)])
|
|
2068
|
+
)
|
|
2069
|
+
});
|
|
2070
|
+
var filtersSchema = import_zod9.z.union([comparisonFilterSchema, compoundFilterSchema]);
|
|
2071
|
+
var fileSearchArgsSchema = import_zod9.z.object({
|
|
2072
|
+
vectorStoreIds: import_zod9.z.array(import_zod9.z.string()).optional(),
|
|
2073
|
+
maxNumResults: import_zod9.z.number().optional(),
|
|
2074
|
+
ranking: import_zod9.z.object({
|
|
2075
|
+
ranker: import_zod9.z.enum(["auto", "default-2024-08-21"]).optional()
|
|
2076
|
+
}).optional(),
|
|
2077
|
+
filters: filtersSchema.optional()
|
|
2078
|
+
});
|
|
2079
|
+
|
|
2080
|
+
// src/tool/web-search.ts
|
|
2081
|
+
var import_zod10 = require("zod");
|
|
2082
|
+
var webSearchArgsSchema = import_zod10.z.object({
|
|
2083
|
+
filters: import_zod10.z.object({
|
|
2084
|
+
allowedDomains: import_zod10.z.array(import_zod10.z.string()).optional()
|
|
2085
|
+
}).optional(),
|
|
2086
|
+
searchContextSize: import_zod10.z.enum(["low", "medium", "high"]).optional(),
|
|
2087
|
+
userLocation: import_zod10.z.object({
|
|
2088
|
+
type: import_zod10.z.literal("approximate"),
|
|
2089
|
+
country: import_zod10.z.string().optional(),
|
|
2090
|
+
city: import_zod10.z.string().optional(),
|
|
2091
|
+
region: import_zod10.z.string().optional(),
|
|
2092
|
+
timezone: import_zod10.z.string().optional()
|
|
2093
|
+
}).optional()
|
|
2094
|
+
});
|
|
2095
|
+
|
|
2096
|
+
// src/tool/web-search-preview.ts
|
|
2097
|
+
var import_zod11 = require("zod");
|
|
2098
|
+
var webSearchPreviewArgsSchema = import_zod11.z.object({
|
|
2099
|
+
searchContextSize: import_zod11.z.enum(["low", "medium", "high"]).optional(),
|
|
2100
|
+
userLocation: import_zod11.z.object({
|
|
2101
|
+
type: import_zod11.z.literal("approximate"),
|
|
2102
|
+
country: import_zod11.z.string().optional(),
|
|
2103
|
+
city: import_zod11.z.string().optional(),
|
|
2104
|
+
region: import_zod11.z.string().optional(),
|
|
2105
|
+
timezone: import_zod11.z.string().optional()
|
|
2106
|
+
}).optional()
|
|
2107
|
+
});
|
|
2108
|
+
|
|
2109
|
+
// src/responses/openai-responses-prepare-tools.ts
|
|
2045
2110
|
function prepareResponsesTools({
|
|
2046
2111
|
mode,
|
|
2047
2112
|
strict
|
|
@@ -2067,31 +2132,48 @@ function prepareResponsesTools({
|
|
|
2067
2132
|
break;
|
|
2068
2133
|
case "provider-defined":
|
|
2069
2134
|
switch (tool.id) {
|
|
2070
|
-
case "openai.file_search":
|
|
2135
|
+
case "openai.file_search": {
|
|
2136
|
+
const args = fileSearchArgsSchema.parse(tool.args);
|
|
2071
2137
|
openaiTools.push({
|
|
2072
2138
|
type: "file_search",
|
|
2073
|
-
vector_store_ids:
|
|
2074
|
-
max_num_results:
|
|
2075
|
-
ranking:
|
|
2076
|
-
filters:
|
|
2139
|
+
vector_store_ids: args.vectorStoreIds,
|
|
2140
|
+
max_num_results: args.maxNumResults,
|
|
2141
|
+
ranking_options: args.ranking ? { ranker: args.ranking.ranker } : void 0,
|
|
2142
|
+
filters: args.filters
|
|
2077
2143
|
});
|
|
2078
2144
|
break;
|
|
2079
|
-
|
|
2145
|
+
}
|
|
2146
|
+
case "openai.web_search_preview": {
|
|
2147
|
+
const args = webSearchPreviewArgsSchema.parse(tool.args);
|
|
2080
2148
|
openaiTools.push({
|
|
2081
2149
|
type: "web_search_preview",
|
|
2082
|
-
search_context_size:
|
|
2083
|
-
user_location:
|
|
2150
|
+
search_context_size: args.searchContextSize,
|
|
2151
|
+
user_location: args.userLocation
|
|
2152
|
+
});
|
|
2153
|
+
break;
|
|
2154
|
+
}
|
|
2155
|
+
case "openai.web_search": {
|
|
2156
|
+
const args = webSearchArgsSchema.parse(tool.args);
|
|
2157
|
+
openaiTools.push({
|
|
2158
|
+
type: "web_search",
|
|
2159
|
+
filters: args.filters != null ? { allowed_domains: args.filters.allowedDomains } : void 0,
|
|
2160
|
+
search_context_size: args.searchContextSize,
|
|
2161
|
+
user_location: args.userLocation
|
|
2084
2162
|
});
|
|
2085
2163
|
break;
|
|
2086
|
-
|
|
2164
|
+
}
|
|
2165
|
+
case "openai.code_interpreter": {
|
|
2166
|
+
const args = codeInterpreterArgsSchema.parse(tool.args);
|
|
2087
2167
|
openaiTools.push({
|
|
2088
2168
|
type: "code_interpreter",
|
|
2089
|
-
container:
|
|
2169
|
+
container: args.container == null ? { type: "auto", file_ids: void 0 } : typeof args.container === "string" ? args.container : { type: "auto", file_ids: args.container.fileIds }
|
|
2090
2170
|
});
|
|
2091
2171
|
break;
|
|
2092
|
-
|
|
2172
|
+
}
|
|
2173
|
+
default: {
|
|
2093
2174
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
2094
2175
|
break;
|
|
2176
|
+
}
|
|
2095
2177
|
}
|
|
2096
2178
|
break;
|
|
2097
2179
|
default:
|
|
@@ -2108,34 +2190,12 @@ function prepareResponsesTools({
|
|
|
2108
2190
|
case "none":
|
|
2109
2191
|
case "required":
|
|
2110
2192
|
return { tools: openaiTools, tool_choice: type, toolWarnings };
|
|
2111
|
-
case "tool":
|
|
2112
|
-
if (toolChoice.toolName === "web_search_preview") {
|
|
2113
|
-
return {
|
|
2114
|
-
tools: openaiTools,
|
|
2115
|
-
tool_choice: {
|
|
2116
|
-
type: "web_search_preview"
|
|
2117
|
-
},
|
|
2118
|
-
toolWarnings
|
|
2119
|
-
};
|
|
2120
|
-
}
|
|
2121
|
-
if (toolChoice.toolName === "code_interpreter") {
|
|
2122
|
-
return {
|
|
2123
|
-
tools: openaiTools,
|
|
2124
|
-
tool_choice: {
|
|
2125
|
-
type: "code_interpreter"
|
|
2126
|
-
},
|
|
2127
|
-
toolWarnings
|
|
2128
|
-
};
|
|
2129
|
-
}
|
|
2193
|
+
case "tool":
|
|
2130
2194
|
return {
|
|
2131
2195
|
tools: openaiTools,
|
|
2132
|
-
tool_choice: {
|
|
2133
|
-
type: "function",
|
|
2134
|
-
name: toolChoice.toolName
|
|
2135
|
-
},
|
|
2196
|
+
tool_choice: toolChoice.toolName === "code_interpreter" || toolChoice.toolName === "file_search" || toolChoice.toolName === "web_search_preview" || toolChoice.toolName === "web_search" ? { type: toolChoice.toolName } : { type: "function", name: toolChoice.toolName },
|
|
2136
2197
|
toolWarnings
|
|
2137
2198
|
};
|
|
2138
|
-
}
|
|
2139
2199
|
default: {
|
|
2140
2200
|
const _exhaustiveCheck = type;
|
|
2141
2201
|
throw new import_provider8.UnsupportedFunctionalityError({
|
|
@@ -2349,55 +2409,107 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2349
2409
|
body,
|
|
2350
2410
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2351
2411
|
successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
|
|
2352
|
-
|
|
2353
|
-
id:
|
|
2354
|
-
created_at:
|
|
2355
|
-
model:
|
|
2356
|
-
output:
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
type:
|
|
2360
|
-
role:
|
|
2361
|
-
content:
|
|
2362
|
-
|
|
2363
|
-
type:
|
|
2364
|
-
text:
|
|
2365
|
-
annotations:
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2412
|
+
import_zod12.z.object({
|
|
2413
|
+
id: import_zod12.z.string(),
|
|
2414
|
+
created_at: import_zod12.z.number(),
|
|
2415
|
+
model: import_zod12.z.string(),
|
|
2416
|
+
output: import_zod12.z.array(
|
|
2417
|
+
import_zod12.z.discriminatedUnion("type", [
|
|
2418
|
+
import_zod12.z.object({
|
|
2419
|
+
type: import_zod12.z.literal("message"),
|
|
2420
|
+
role: import_zod12.z.literal("assistant"),
|
|
2421
|
+
content: import_zod12.z.array(
|
|
2422
|
+
import_zod12.z.object({
|
|
2423
|
+
type: import_zod12.z.literal("output_text"),
|
|
2424
|
+
text: import_zod12.z.string(),
|
|
2425
|
+
annotations: import_zod12.z.array(
|
|
2426
|
+
import_zod12.z.discriminatedUnion("type", [
|
|
2427
|
+
import_zod12.z.object({
|
|
2428
|
+
type: import_zod12.z.literal("url_citation"),
|
|
2429
|
+
start_index: import_zod12.z.number(),
|
|
2430
|
+
end_index: import_zod12.z.number(),
|
|
2431
|
+
url: import_zod12.z.string(),
|
|
2432
|
+
title: import_zod12.z.string()
|
|
2433
|
+
}),
|
|
2434
|
+
import_zod12.z.object({
|
|
2435
|
+
type: import_zod12.z.literal("file_citation"),
|
|
2436
|
+
file_id: import_zod12.z.string(),
|
|
2437
|
+
filename: import_zod12.z.string().nullish(),
|
|
2438
|
+
index: import_zod12.z.number().nullish(),
|
|
2439
|
+
start_index: import_zod12.z.number().nullish(),
|
|
2440
|
+
end_index: import_zod12.z.number().nullish(),
|
|
2441
|
+
quote: import_zod12.z.string().nullish()
|
|
2442
|
+
}),
|
|
2443
|
+
import_zod12.z.object({
|
|
2444
|
+
type: import_zod12.z.literal("container_file_citation")
|
|
2445
|
+
})
|
|
2446
|
+
])
|
|
2373
2447
|
)
|
|
2374
2448
|
})
|
|
2375
2449
|
)
|
|
2376
2450
|
}),
|
|
2377
|
-
|
|
2378
|
-
type:
|
|
2379
|
-
call_id: import_zod8.z.string(),
|
|
2380
|
-
name: import_zod8.z.string(),
|
|
2381
|
-
arguments: import_zod8.z.string()
|
|
2451
|
+
import_zod12.z.object({
|
|
2452
|
+
type: import_zod12.z.literal("code_interpreter_call")
|
|
2382
2453
|
}),
|
|
2383
|
-
|
|
2384
|
-
type:
|
|
2454
|
+
import_zod12.z.object({
|
|
2455
|
+
type: import_zod12.z.literal("function_call"),
|
|
2456
|
+
call_id: import_zod12.z.string(),
|
|
2457
|
+
name: import_zod12.z.string(),
|
|
2458
|
+
arguments: import_zod12.z.string()
|
|
2385
2459
|
}),
|
|
2386
|
-
|
|
2387
|
-
type:
|
|
2460
|
+
import_zod12.z.object({
|
|
2461
|
+
type: import_zod12.z.literal("web_search_call"),
|
|
2462
|
+
id: import_zod12.z.string(),
|
|
2463
|
+
status: import_zod12.z.string().optional(),
|
|
2464
|
+
action: import_zod12.z.discriminatedUnion("type", [
|
|
2465
|
+
import_zod12.z.object({
|
|
2466
|
+
type: import_zod12.z.literal("search"),
|
|
2467
|
+
query: import_zod12.z.string().nullish()
|
|
2468
|
+
}),
|
|
2469
|
+
import_zod12.z.object({
|
|
2470
|
+
type: import_zod12.z.literal("open_page"),
|
|
2471
|
+
url: import_zod12.z.string()
|
|
2472
|
+
}),
|
|
2473
|
+
import_zod12.z.object({
|
|
2474
|
+
type: import_zod12.z.literal("find"),
|
|
2475
|
+
url: import_zod12.z.string(),
|
|
2476
|
+
pattern: import_zod12.z.string()
|
|
2477
|
+
})
|
|
2478
|
+
]).nullish()
|
|
2479
|
+
}),
|
|
2480
|
+
import_zod12.z.object({
|
|
2481
|
+
type: import_zod12.z.literal("computer_call"),
|
|
2482
|
+
id: import_zod12.z.string(),
|
|
2483
|
+
status: import_zod12.z.string().optional()
|
|
2484
|
+
}),
|
|
2485
|
+
import_zod12.z.object({
|
|
2486
|
+
type: import_zod12.z.literal("file_search_call"),
|
|
2487
|
+
id: import_zod12.z.string(),
|
|
2488
|
+
status: import_zod12.z.string().optional(),
|
|
2489
|
+
queries: import_zod12.z.array(import_zod12.z.string()).nullish(),
|
|
2490
|
+
results: import_zod12.z.array(
|
|
2491
|
+
import_zod12.z.object({
|
|
2492
|
+
attributes: import_zod12.z.object({
|
|
2493
|
+
file_id: import_zod12.z.string(),
|
|
2494
|
+
filename: import_zod12.z.string(),
|
|
2495
|
+
score: import_zod12.z.number(),
|
|
2496
|
+
text: import_zod12.z.string()
|
|
2497
|
+
})
|
|
2498
|
+
})
|
|
2499
|
+
).nullish()
|
|
2388
2500
|
}),
|
|
2389
|
-
|
|
2390
|
-
type:
|
|
2391
|
-
summary:
|
|
2392
|
-
|
|
2393
|
-
type:
|
|
2394
|
-
text:
|
|
2501
|
+
import_zod12.z.object({
|
|
2502
|
+
type: import_zod12.z.literal("reasoning"),
|
|
2503
|
+
summary: import_zod12.z.array(
|
|
2504
|
+
import_zod12.z.object({
|
|
2505
|
+
type: import_zod12.z.literal("summary_text"),
|
|
2506
|
+
text: import_zod12.z.string()
|
|
2395
2507
|
})
|
|
2396
2508
|
)
|
|
2397
2509
|
})
|
|
2398
2510
|
])
|
|
2399
2511
|
),
|
|
2400
|
-
incomplete_details:
|
|
2512
|
+
incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullable(),
|
|
2401
2513
|
usage: usageSchema
|
|
2402
2514
|
})
|
|
2403
2515
|
),
|
|
@@ -2405,12 +2517,38 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2405
2517
|
fetch: this.config.fetch
|
|
2406
2518
|
});
|
|
2407
2519
|
const outputTextElements = response.output.filter((output) => output.type === "message").flatMap((output) => output.content).filter((content) => content.type === "output_text");
|
|
2408
|
-
const toolCalls =
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2520
|
+
const toolCalls = [];
|
|
2521
|
+
for (const output of response.output) {
|
|
2522
|
+
if (output.type === "function_call") {
|
|
2523
|
+
toolCalls.push({
|
|
2524
|
+
toolCallType: "function",
|
|
2525
|
+
toolCallId: output.call_id,
|
|
2526
|
+
toolName: output.name,
|
|
2527
|
+
args: output.arguments
|
|
2528
|
+
});
|
|
2529
|
+
} else if (output.type === "web_search_call") {
|
|
2530
|
+
toolCalls.push({
|
|
2531
|
+
toolCallType: "function",
|
|
2532
|
+
toolCallId: output.id,
|
|
2533
|
+
toolName: "web_search_preview",
|
|
2534
|
+
args: JSON.stringify({ action: output.action })
|
|
2535
|
+
});
|
|
2536
|
+
} else if (output.type === "computer_call") {
|
|
2537
|
+
toolCalls.push({
|
|
2538
|
+
toolCallType: "function",
|
|
2539
|
+
toolCallId: output.id,
|
|
2540
|
+
toolName: "computer_use",
|
|
2541
|
+
args: ""
|
|
2542
|
+
});
|
|
2543
|
+
} else if (output.type === "file_search_call") {
|
|
2544
|
+
toolCalls.push({
|
|
2545
|
+
toolCallType: "function",
|
|
2546
|
+
toolCallId: output.id,
|
|
2547
|
+
toolName: "file_search",
|
|
2548
|
+
args: ""
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2414
2552
|
const reasoningSummary = (_b = (_a = response.output.find((item) => item.type === "reasoning")) == null ? void 0 : _a.summary) != null ? _b : null;
|
|
2415
2553
|
console.log(JSON.stringify({
|
|
2416
2554
|
msg: "ai-sdk: content annotations",
|
|
@@ -2420,13 +2558,29 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2420
2558
|
text: outputTextElements.map((content) => content.text).join("\n"),
|
|
2421
2559
|
sources: outputTextElements.flatMap(
|
|
2422
2560
|
(content) => content.annotations.map((annotation) => {
|
|
2423
|
-
var _a2, _b2, _c2;
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2561
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h, _i, _j, _k;
|
|
2562
|
+
if (annotation.type === "url_citation") {
|
|
2563
|
+
return {
|
|
2564
|
+
sourceType: "url",
|
|
2565
|
+
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0, import_provider_utils10.generateId)(),
|
|
2566
|
+
url: annotation.url,
|
|
2567
|
+
title: annotation.title
|
|
2568
|
+
};
|
|
2569
|
+
} else if (annotation.type === "file_citation") {
|
|
2570
|
+
return {
|
|
2571
|
+
sourceType: "url",
|
|
2572
|
+
id: (_f2 = (_e2 = (_d2 = this.config).generateId) == null ? void 0 : _e2.call(_d2)) != null ? _f2 : (0, import_provider_utils10.generateId)(),
|
|
2573
|
+
url: `file://${annotation.file_id}`,
|
|
2574
|
+
title: (_h = (_g2 = annotation.quote) != null ? _g2 : annotation.filename) != null ? _h : "Document"
|
|
2575
|
+
};
|
|
2576
|
+
} else {
|
|
2577
|
+
return {
|
|
2578
|
+
sourceType: "url",
|
|
2579
|
+
id: (_k = (_j = (_i = this.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils10.generateId)(),
|
|
2580
|
+
url: "",
|
|
2581
|
+
title: "Unknown Source"
|
|
2582
|
+
};
|
|
2583
|
+
}
|
|
2430
2584
|
})
|
|
2431
2585
|
),
|
|
2432
2586
|
finishReason: mapOpenAIResponseFinishReason({
|
|
@@ -2500,7 +2654,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2500
2654
|
stream: response.pipeThrough(
|
|
2501
2655
|
new TransformStream({
|
|
2502
2656
|
transform(chunk, controller) {
|
|
2503
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2657
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2504
2658
|
if (!chunk.success) {
|
|
2505
2659
|
finishReason = "error";
|
|
2506
2660
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2520,6 +2674,42 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2520
2674
|
toolName: value.item.name,
|
|
2521
2675
|
argsTextDelta: value.item.arguments
|
|
2522
2676
|
});
|
|
2677
|
+
} else if (value.item.type === "web_search_call") {
|
|
2678
|
+
ongoingToolCalls[value.output_index] = {
|
|
2679
|
+
toolName: "web_search_preview",
|
|
2680
|
+
toolCallId: value.item.id
|
|
2681
|
+
};
|
|
2682
|
+
controller.enqueue({
|
|
2683
|
+
type: "tool-call-delta",
|
|
2684
|
+
toolCallType: "function",
|
|
2685
|
+
toolCallId: value.item.id,
|
|
2686
|
+
toolName: "web_search_preview",
|
|
2687
|
+
argsTextDelta: JSON.stringify({ action: value.item.action })
|
|
2688
|
+
});
|
|
2689
|
+
} else if (value.item.type === "computer_call") {
|
|
2690
|
+
ongoingToolCalls[value.output_index] = {
|
|
2691
|
+
toolName: "computer_use",
|
|
2692
|
+
toolCallId: value.item.id
|
|
2693
|
+
};
|
|
2694
|
+
controller.enqueue({
|
|
2695
|
+
type: "tool-call-delta",
|
|
2696
|
+
toolCallType: "function",
|
|
2697
|
+
toolCallId: value.item.id,
|
|
2698
|
+
toolName: "computer_use",
|
|
2699
|
+
argsTextDelta: ""
|
|
2700
|
+
});
|
|
2701
|
+
} else if (value.item.type === "file_search_call") {
|
|
2702
|
+
ongoingToolCalls[value.output_index] = {
|
|
2703
|
+
toolName: "file_search",
|
|
2704
|
+
toolCallId: value.item.id
|
|
2705
|
+
};
|
|
2706
|
+
controller.enqueue({
|
|
2707
|
+
type: "tool-call-delta",
|
|
2708
|
+
toolCallType: "function",
|
|
2709
|
+
toolCallId: value.item.id,
|
|
2710
|
+
toolName: "file_search",
|
|
2711
|
+
argsTextDelta: ""
|
|
2712
|
+
});
|
|
2523
2713
|
}
|
|
2524
2714
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2525
2715
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -2550,16 +2740,51 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2550
2740
|
type: "reasoning",
|
|
2551
2741
|
textDelta: value.delta
|
|
2552
2742
|
});
|
|
2553
|
-
} else if (isResponseOutputItemDoneChunk(value)
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2743
|
+
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
2744
|
+
if (value.item.type === "function_call") {
|
|
2745
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2746
|
+
hasToolCalls = true;
|
|
2747
|
+
controller.enqueue({
|
|
2748
|
+
type: "tool-call",
|
|
2749
|
+
toolCallType: "function",
|
|
2750
|
+
toolCallId: value.item.call_id,
|
|
2751
|
+
toolName: value.item.name,
|
|
2752
|
+
args: value.item.arguments
|
|
2753
|
+
});
|
|
2754
|
+
} else if (value.item.type === "web_search_call") {
|
|
2755
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2756
|
+
hasToolCalls = true;
|
|
2757
|
+
controller.enqueue({
|
|
2758
|
+
type: "tool-call",
|
|
2759
|
+
toolCallType: "function",
|
|
2760
|
+
toolCallId: value.item.id,
|
|
2761
|
+
toolName: "web_search_preview",
|
|
2762
|
+
args: JSON.stringify({ action: value.item.action })
|
|
2763
|
+
});
|
|
2764
|
+
} else if (value.item.type === "computer_call") {
|
|
2765
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2766
|
+
hasToolCalls = true;
|
|
2767
|
+
controller.enqueue({
|
|
2768
|
+
type: "tool-call",
|
|
2769
|
+
toolCallType: "function",
|
|
2770
|
+
toolCallId: value.item.id,
|
|
2771
|
+
toolName: "computer_use",
|
|
2772
|
+
args: ""
|
|
2773
|
+
});
|
|
2774
|
+
} else if (value.item.type === "file_search_call") {
|
|
2775
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2776
|
+
hasToolCalls = true;
|
|
2777
|
+
controller.enqueue({
|
|
2778
|
+
type: "tool-call",
|
|
2779
|
+
toolCallType: "function",
|
|
2780
|
+
toolCallId: value.item.id,
|
|
2781
|
+
toolName: "file_search",
|
|
2782
|
+
args: JSON.stringify({
|
|
2783
|
+
queries: value.item.queries,
|
|
2784
|
+
results: value.item.results
|
|
2785
|
+
})
|
|
2786
|
+
});
|
|
2787
|
+
}
|
|
2563
2788
|
} else if (isResponseFinishedChunk(value)) {
|
|
2564
2789
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2565
2790
|
finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
|
|
@@ -2574,15 +2799,27 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2574
2799
|
msg: "ai-sdk: source (stream)",
|
|
2575
2800
|
source: value.annotation
|
|
2576
2801
|
}));
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2802
|
+
if (value.annotation.type === "url_citation") {
|
|
2803
|
+
controller.enqueue({
|
|
2804
|
+
type: "source",
|
|
2805
|
+
source: {
|
|
2806
|
+
sourceType: "url",
|
|
2807
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils10.generateId)(),
|
|
2808
|
+
url: value.annotation.url,
|
|
2809
|
+
title: value.annotation.title
|
|
2810
|
+
}
|
|
2811
|
+
});
|
|
2812
|
+
} else if (value.annotation.type === "file_citation") {
|
|
2813
|
+
controller.enqueue({
|
|
2814
|
+
type: "source",
|
|
2815
|
+
source: {
|
|
2816
|
+
sourceType: "url",
|
|
2817
|
+
id: (_k = (_j = (_i = self.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils10.generateId)(),
|
|
2818
|
+
url: `file://${value.annotation.file_id}`,
|
|
2819
|
+
title: (_m = (_l = value.annotation.quote) != null ? _l : value.annotation.filename) != null ? _m : "Document"
|
|
2820
|
+
}
|
|
2821
|
+
});
|
|
2822
|
+
}
|
|
2586
2823
|
}
|
|
2587
2824
|
},
|
|
2588
2825
|
flush(controller) {
|
|
@@ -2613,86 +2850,168 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2613
2850
|
};
|
|
2614
2851
|
}
|
|
2615
2852
|
};
|
|
2616
|
-
var usageSchema =
|
|
2617
|
-
input_tokens:
|
|
2618
|
-
input_tokens_details:
|
|
2619
|
-
output_tokens:
|
|
2620
|
-
output_tokens_details:
|
|
2853
|
+
var usageSchema = import_zod12.z.object({
|
|
2854
|
+
input_tokens: import_zod12.z.number(),
|
|
2855
|
+
input_tokens_details: import_zod12.z.object({ cached_tokens: import_zod12.z.number().nullish() }).nullish(),
|
|
2856
|
+
output_tokens: import_zod12.z.number(),
|
|
2857
|
+
output_tokens_details: import_zod12.z.object({ reasoning_tokens: import_zod12.z.number().nullish() }).nullish()
|
|
2621
2858
|
});
|
|
2622
|
-
var textDeltaChunkSchema =
|
|
2623
|
-
type:
|
|
2624
|
-
delta:
|
|
2859
|
+
var textDeltaChunkSchema = import_zod12.z.object({
|
|
2860
|
+
type: import_zod12.z.literal("response.output_text.delta"),
|
|
2861
|
+
delta: import_zod12.z.string()
|
|
2625
2862
|
});
|
|
2626
|
-
var responseFinishedChunkSchema =
|
|
2627
|
-
type:
|
|
2628
|
-
response:
|
|
2629
|
-
incomplete_details:
|
|
2863
|
+
var responseFinishedChunkSchema = import_zod12.z.object({
|
|
2864
|
+
type: import_zod12.z.enum(["response.completed", "response.incomplete"]),
|
|
2865
|
+
response: import_zod12.z.object({
|
|
2866
|
+
incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullish(),
|
|
2630
2867
|
usage: usageSchema
|
|
2631
2868
|
})
|
|
2632
2869
|
});
|
|
2633
|
-
var responseCreatedChunkSchema =
|
|
2634
|
-
type:
|
|
2635
|
-
response:
|
|
2636
|
-
id:
|
|
2637
|
-
created_at:
|
|
2638
|
-
model:
|
|
2870
|
+
var responseCreatedChunkSchema = import_zod12.z.object({
|
|
2871
|
+
type: import_zod12.z.literal("response.created"),
|
|
2872
|
+
response: import_zod12.z.object({
|
|
2873
|
+
id: import_zod12.z.string(),
|
|
2874
|
+
created_at: import_zod12.z.number(),
|
|
2875
|
+
model: import_zod12.z.string()
|
|
2639
2876
|
})
|
|
2640
2877
|
});
|
|
2641
|
-
var responseOutputItemDoneSchema =
|
|
2642
|
-
type:
|
|
2643
|
-
output_index:
|
|
2644
|
-
item:
|
|
2645
|
-
|
|
2646
|
-
type:
|
|
2878
|
+
var responseOutputItemDoneSchema = import_zod12.z.object({
|
|
2879
|
+
type: import_zod12.z.literal("response.output_item.done"),
|
|
2880
|
+
output_index: import_zod12.z.number(),
|
|
2881
|
+
item: import_zod12.z.discriminatedUnion("type", [
|
|
2882
|
+
import_zod12.z.object({
|
|
2883
|
+
type: import_zod12.z.literal("message")
|
|
2647
2884
|
}),
|
|
2648
|
-
|
|
2649
|
-
type:
|
|
2650
|
-
id:
|
|
2651
|
-
call_id:
|
|
2652
|
-
name:
|
|
2653
|
-
arguments:
|
|
2654
|
-
status:
|
|
2885
|
+
import_zod12.z.object({
|
|
2886
|
+
type: import_zod12.z.literal("function_call"),
|
|
2887
|
+
id: import_zod12.z.string(),
|
|
2888
|
+
call_id: import_zod12.z.string(),
|
|
2889
|
+
name: import_zod12.z.string(),
|
|
2890
|
+
arguments: import_zod12.z.string(),
|
|
2891
|
+
status: import_zod12.z.literal("completed")
|
|
2892
|
+
}),
|
|
2893
|
+
import_zod12.z.object({
|
|
2894
|
+
type: import_zod12.z.literal("web_search_call"),
|
|
2895
|
+
id: import_zod12.z.string(),
|
|
2896
|
+
status: import_zod12.z.string(),
|
|
2897
|
+
action: import_zod12.z.discriminatedUnion("type", [
|
|
2898
|
+
import_zod12.z.object({
|
|
2899
|
+
type: import_zod12.z.literal("search"),
|
|
2900
|
+
query: import_zod12.z.string().nullish()
|
|
2901
|
+
}),
|
|
2902
|
+
import_zod12.z.object({
|
|
2903
|
+
type: import_zod12.z.literal("open_page"),
|
|
2904
|
+
url: import_zod12.z.string()
|
|
2905
|
+
}),
|
|
2906
|
+
import_zod12.z.object({
|
|
2907
|
+
type: import_zod12.z.literal("find"),
|
|
2908
|
+
url: import_zod12.z.string(),
|
|
2909
|
+
pattern: import_zod12.z.string()
|
|
2910
|
+
})
|
|
2911
|
+
]).nullish()
|
|
2912
|
+
}),
|
|
2913
|
+
import_zod12.z.object({
|
|
2914
|
+
type: import_zod12.z.literal("computer_call"),
|
|
2915
|
+
id: import_zod12.z.string(),
|
|
2916
|
+
status: import_zod12.z.literal("completed")
|
|
2917
|
+
}),
|
|
2918
|
+
import_zod12.z.object({
|
|
2919
|
+
type: import_zod12.z.literal("file_search_call"),
|
|
2920
|
+
id: import_zod12.z.string(),
|
|
2921
|
+
status: import_zod12.z.literal("completed"),
|
|
2922
|
+
queries: import_zod12.z.array(import_zod12.z.string()).nullish(),
|
|
2923
|
+
results: import_zod12.z.array(
|
|
2924
|
+
import_zod12.z.object({
|
|
2925
|
+
attributes: import_zod12.z.object({
|
|
2926
|
+
file_id: import_zod12.z.string(),
|
|
2927
|
+
filename: import_zod12.z.string(),
|
|
2928
|
+
score: import_zod12.z.number(),
|
|
2929
|
+
text: import_zod12.z.string()
|
|
2930
|
+
})
|
|
2931
|
+
})
|
|
2932
|
+
).nullish()
|
|
2655
2933
|
})
|
|
2656
2934
|
])
|
|
2657
2935
|
});
|
|
2658
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2659
|
-
type:
|
|
2660
|
-
item_id:
|
|
2661
|
-
output_index:
|
|
2662
|
-
delta:
|
|
2936
|
+
var responseFunctionCallArgumentsDeltaSchema = import_zod12.z.object({
|
|
2937
|
+
type: import_zod12.z.literal("response.function_call_arguments.delta"),
|
|
2938
|
+
item_id: import_zod12.z.string(),
|
|
2939
|
+
output_index: import_zod12.z.number(),
|
|
2940
|
+
delta: import_zod12.z.string()
|
|
2663
2941
|
});
|
|
2664
|
-
var responseOutputItemAddedSchema =
|
|
2665
|
-
type:
|
|
2666
|
-
output_index:
|
|
2667
|
-
item:
|
|
2668
|
-
|
|
2669
|
-
type:
|
|
2942
|
+
var responseOutputItemAddedSchema = import_zod12.z.object({
|
|
2943
|
+
type: import_zod12.z.literal("response.output_item.added"),
|
|
2944
|
+
output_index: import_zod12.z.number(),
|
|
2945
|
+
item: import_zod12.z.discriminatedUnion("type", [
|
|
2946
|
+
import_zod12.z.object({
|
|
2947
|
+
type: import_zod12.z.literal("message")
|
|
2670
2948
|
}),
|
|
2671
|
-
|
|
2672
|
-
type:
|
|
2673
|
-
id:
|
|
2674
|
-
call_id:
|
|
2675
|
-
name:
|
|
2676
|
-
arguments:
|
|
2949
|
+
import_zod12.z.object({
|
|
2950
|
+
type: import_zod12.z.literal("function_call"),
|
|
2951
|
+
id: import_zod12.z.string(),
|
|
2952
|
+
call_id: import_zod12.z.string(),
|
|
2953
|
+
name: import_zod12.z.string(),
|
|
2954
|
+
arguments: import_zod12.z.string()
|
|
2955
|
+
}),
|
|
2956
|
+
import_zod12.z.object({
|
|
2957
|
+
type: import_zod12.z.literal("web_search_call"),
|
|
2958
|
+
id: import_zod12.z.string(),
|
|
2959
|
+
status: import_zod12.z.string(),
|
|
2960
|
+
action: import_zod12.z.object({
|
|
2961
|
+
type: import_zod12.z.literal("search"),
|
|
2962
|
+
query: import_zod12.z.string().optional()
|
|
2963
|
+
}).nullish()
|
|
2964
|
+
}),
|
|
2965
|
+
import_zod12.z.object({
|
|
2966
|
+
type: import_zod12.z.literal("computer_call"),
|
|
2967
|
+
id: import_zod12.z.string(),
|
|
2968
|
+
status: import_zod12.z.string()
|
|
2969
|
+
}),
|
|
2970
|
+
import_zod12.z.object({
|
|
2971
|
+
type: import_zod12.z.literal("file_search_call"),
|
|
2972
|
+
id: import_zod12.z.string(),
|
|
2973
|
+
status: import_zod12.z.string(),
|
|
2974
|
+
queries: import_zod12.z.array(import_zod12.z.string()).nullish(),
|
|
2975
|
+
results: import_zod12.z.array(
|
|
2976
|
+
import_zod12.z.object({
|
|
2977
|
+
attributes: import_zod12.z.object({
|
|
2978
|
+
file_id: import_zod12.z.string(),
|
|
2979
|
+
filename: import_zod12.z.string(),
|
|
2980
|
+
score: import_zod12.z.number(),
|
|
2981
|
+
text: import_zod12.z.string()
|
|
2982
|
+
})
|
|
2983
|
+
})
|
|
2984
|
+
).optional()
|
|
2677
2985
|
})
|
|
2678
2986
|
])
|
|
2679
2987
|
});
|
|
2680
|
-
var responseAnnotationAddedSchema =
|
|
2681
|
-
type:
|
|
2682
|
-
annotation:
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2988
|
+
var responseAnnotationAddedSchema = import_zod12.z.object({
|
|
2989
|
+
type: import_zod12.z.literal("response.output_text.annotation.added"),
|
|
2990
|
+
annotation: import_zod12.z.discriminatedUnion("type", [
|
|
2991
|
+
import_zod12.z.object({
|
|
2992
|
+
type: import_zod12.z.literal("url_citation"),
|
|
2993
|
+
url: import_zod12.z.string(),
|
|
2994
|
+
title: import_zod12.z.string()
|
|
2995
|
+
}),
|
|
2996
|
+
import_zod12.z.object({
|
|
2997
|
+
type: import_zod12.z.literal("file_citation"),
|
|
2998
|
+
file_id: import_zod12.z.string(),
|
|
2999
|
+
filename: import_zod12.z.string().nullish(),
|
|
3000
|
+
index: import_zod12.z.number().nullish(),
|
|
3001
|
+
start_index: import_zod12.z.number().nullish(),
|
|
3002
|
+
end_index: import_zod12.z.number().nullish(),
|
|
3003
|
+
quote: import_zod12.z.string().nullish()
|
|
3004
|
+
})
|
|
3005
|
+
])
|
|
2687
3006
|
});
|
|
2688
|
-
var responseReasoningSummaryTextDeltaSchema =
|
|
2689
|
-
type:
|
|
2690
|
-
item_id:
|
|
2691
|
-
output_index:
|
|
2692
|
-
summary_index:
|
|
2693
|
-
delta:
|
|
3007
|
+
var responseReasoningSummaryTextDeltaSchema = import_zod12.z.object({
|
|
3008
|
+
type: import_zod12.z.literal("response.reasoning_summary_text.delta"),
|
|
3009
|
+
item_id: import_zod12.z.string(),
|
|
3010
|
+
output_index: import_zod12.z.number(),
|
|
3011
|
+
summary_index: import_zod12.z.number(),
|
|
3012
|
+
delta: import_zod12.z.string()
|
|
2694
3013
|
});
|
|
2695
|
-
var openaiResponsesChunkSchema =
|
|
3014
|
+
var openaiResponsesChunkSchema = import_zod12.z.union([
|
|
2696
3015
|
textDeltaChunkSchema,
|
|
2697
3016
|
responseFinishedChunkSchema,
|
|
2698
3017
|
responseCreatedChunkSchema,
|
|
@@ -2701,7 +3020,7 @@ var openaiResponsesChunkSchema = import_zod8.z.union([
|
|
|
2701
3020
|
responseOutputItemAddedSchema,
|
|
2702
3021
|
responseAnnotationAddedSchema,
|
|
2703
3022
|
responseReasoningSummaryTextDeltaSchema,
|
|
2704
|
-
|
|
3023
|
+
import_zod12.z.object({ type: import_zod12.z.string() }).passthrough()
|
|
2705
3024
|
// fallback for unknown chunks
|
|
2706
3025
|
]);
|
|
2707
3026
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2749,18 +3068,18 @@ function getResponsesModelConfig(modelId) {
|
|
|
2749
3068
|
requiredAutoTruncation: false
|
|
2750
3069
|
};
|
|
2751
3070
|
}
|
|
2752
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2753
|
-
metadata:
|
|
2754
|
-
parallelToolCalls:
|
|
2755
|
-
include:
|
|
2756
|
-
previousResponseId:
|
|
2757
|
-
forceNoTemperature:
|
|
2758
|
-
store:
|
|
2759
|
-
user:
|
|
2760
|
-
reasoningEffort:
|
|
2761
|
-
strictSchemas:
|
|
2762
|
-
instructions:
|
|
2763
|
-
reasoningSummary:
|
|
3071
|
+
var openaiResponsesProviderOptionsSchema = import_zod12.z.object({
|
|
3072
|
+
metadata: import_zod12.z.any().nullish(),
|
|
3073
|
+
parallelToolCalls: import_zod12.z.boolean().nullish(),
|
|
3074
|
+
include: import_zod12.z.array(import_zod12.z.string()).nullish(),
|
|
3075
|
+
previousResponseId: import_zod12.z.string().nullish(),
|
|
3076
|
+
forceNoTemperature: import_zod12.z.boolean().nullish(),
|
|
3077
|
+
store: import_zod12.z.boolean().nullish(),
|
|
3078
|
+
user: import_zod12.z.string().nullish(),
|
|
3079
|
+
reasoningEffort: import_zod12.z.string().nullish(),
|
|
3080
|
+
strictSchemas: import_zod12.z.boolean().nullish(),
|
|
3081
|
+
instructions: import_zod12.z.string().nullish(),
|
|
3082
|
+
reasoningSummary: import_zod12.z.string().nullish()
|
|
2764
3083
|
});
|
|
2765
3084
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2766
3085
|
0 && (module.exports = {
|