@zenning/openai 1.4.3 → 1.4.5
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 +807 -358
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +797 -366
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.js +730 -268
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +720 -276
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/internal/dist/index.js
CHANGED
|
@@ -4,8 +4,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __export = (target, all) => {
|
|
7
|
-
for (var
|
|
8
|
-
__defProp(target,
|
|
7
|
+
for (var name14 in all)
|
|
8
|
+
__defProp(target, name14, { get: all[name14], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -32,13 +32,171 @@ __export(internal_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(internal_exports);
|
|
34
34
|
|
|
35
|
+
// ../provider/dist/index.mjs
|
|
36
|
+
var marker = "vercel.ai.error";
|
|
37
|
+
var symbol = Symbol.for(marker);
|
|
38
|
+
var _a;
|
|
39
|
+
var _AISDKError = class _AISDKError2 extends Error {
|
|
40
|
+
/**
|
|
41
|
+
* Creates an AI SDK Error.
|
|
42
|
+
*
|
|
43
|
+
* @param {Object} params - The parameters for creating the error.
|
|
44
|
+
* @param {string} params.name - The name of the error.
|
|
45
|
+
* @param {string} params.message - The error message.
|
|
46
|
+
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
47
|
+
*/
|
|
48
|
+
constructor({
|
|
49
|
+
name: name14,
|
|
50
|
+
message,
|
|
51
|
+
cause
|
|
52
|
+
}) {
|
|
53
|
+
super(message);
|
|
54
|
+
this[_a] = true;
|
|
55
|
+
this.name = name14;
|
|
56
|
+
this.cause = cause;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks if the given error is an AI SDK Error.
|
|
60
|
+
* @param {unknown} error - The error to check.
|
|
61
|
+
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
62
|
+
*/
|
|
63
|
+
static isInstance(error) {
|
|
64
|
+
return _AISDKError2.hasMarker(error, marker);
|
|
65
|
+
}
|
|
66
|
+
static hasMarker(error, marker15) {
|
|
67
|
+
const markerSymbol = Symbol.for(marker15);
|
|
68
|
+
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
_a = symbol;
|
|
72
|
+
var AISDKError = _AISDKError;
|
|
73
|
+
var name = "AI_APICallError";
|
|
74
|
+
var marker2 = `vercel.ai.error.${name}`;
|
|
75
|
+
var symbol2 = Symbol.for(marker2);
|
|
76
|
+
var _a2;
|
|
77
|
+
_a2 = symbol2;
|
|
78
|
+
var name2 = "AI_EmptyResponseBodyError";
|
|
79
|
+
var marker3 = `vercel.ai.error.${name2}`;
|
|
80
|
+
var symbol3 = Symbol.for(marker3);
|
|
81
|
+
var _a3;
|
|
82
|
+
_a3 = symbol3;
|
|
83
|
+
var name3 = "AI_InvalidArgumentError";
|
|
84
|
+
var marker4 = `vercel.ai.error.${name3}`;
|
|
85
|
+
var symbol4 = Symbol.for(marker4);
|
|
86
|
+
var _a4;
|
|
87
|
+
_a4 = symbol4;
|
|
88
|
+
var name4 = "AI_InvalidPromptError";
|
|
89
|
+
var marker5 = `vercel.ai.error.${name4}`;
|
|
90
|
+
var symbol5 = Symbol.for(marker5);
|
|
91
|
+
var _a5;
|
|
92
|
+
var InvalidPromptError = class extends AISDKError {
|
|
93
|
+
constructor({
|
|
94
|
+
prompt,
|
|
95
|
+
message,
|
|
96
|
+
cause
|
|
97
|
+
}) {
|
|
98
|
+
super({ name: name4, message: `Invalid prompt: ${message}`, cause });
|
|
99
|
+
this[_a5] = true;
|
|
100
|
+
this.prompt = prompt;
|
|
101
|
+
}
|
|
102
|
+
static isInstance(error) {
|
|
103
|
+
return AISDKError.hasMarker(error, marker5);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
_a5 = symbol5;
|
|
107
|
+
var name5 = "AI_InvalidResponseDataError";
|
|
108
|
+
var marker6 = `vercel.ai.error.${name5}`;
|
|
109
|
+
var symbol6 = Symbol.for(marker6);
|
|
110
|
+
var _a6;
|
|
111
|
+
var InvalidResponseDataError = class extends AISDKError {
|
|
112
|
+
constructor({
|
|
113
|
+
data,
|
|
114
|
+
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
115
|
+
}) {
|
|
116
|
+
super({ name: name5, message });
|
|
117
|
+
this[_a6] = true;
|
|
118
|
+
this.data = data;
|
|
119
|
+
}
|
|
120
|
+
static isInstance(error) {
|
|
121
|
+
return AISDKError.hasMarker(error, marker6);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
_a6 = symbol6;
|
|
125
|
+
var name6 = "AI_JSONParseError";
|
|
126
|
+
var marker7 = `vercel.ai.error.${name6}`;
|
|
127
|
+
var symbol7 = Symbol.for(marker7);
|
|
128
|
+
var _a7;
|
|
129
|
+
_a7 = symbol7;
|
|
130
|
+
var name7 = "AI_LoadAPIKeyError";
|
|
131
|
+
var marker8 = `vercel.ai.error.${name7}`;
|
|
132
|
+
var symbol8 = Symbol.for(marker8);
|
|
133
|
+
var _a8;
|
|
134
|
+
_a8 = symbol8;
|
|
135
|
+
var name8 = "AI_LoadSettingError";
|
|
136
|
+
var marker9 = `vercel.ai.error.${name8}`;
|
|
137
|
+
var symbol9 = Symbol.for(marker9);
|
|
138
|
+
var _a9;
|
|
139
|
+
_a9 = symbol9;
|
|
140
|
+
var name9 = "AI_NoContentGeneratedError";
|
|
141
|
+
var marker10 = `vercel.ai.error.${name9}`;
|
|
142
|
+
var symbol10 = Symbol.for(marker10);
|
|
143
|
+
var _a10;
|
|
144
|
+
_a10 = symbol10;
|
|
145
|
+
var name10 = "AI_NoSuchModelError";
|
|
146
|
+
var marker11 = `vercel.ai.error.${name10}`;
|
|
147
|
+
var symbol11 = Symbol.for(marker11);
|
|
148
|
+
var _a11;
|
|
149
|
+
_a11 = symbol11;
|
|
150
|
+
var name11 = "AI_TooManyEmbeddingValuesForCallError";
|
|
151
|
+
var marker12 = `vercel.ai.error.${name11}`;
|
|
152
|
+
var symbol12 = Symbol.for(marker12);
|
|
153
|
+
var _a12;
|
|
154
|
+
var TooManyEmbeddingValuesForCallError = class extends AISDKError {
|
|
155
|
+
constructor(options) {
|
|
156
|
+
super({
|
|
157
|
+
name: name11,
|
|
158
|
+
message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
|
|
159
|
+
});
|
|
160
|
+
this[_a12] = true;
|
|
161
|
+
this.provider = options.provider;
|
|
162
|
+
this.modelId = options.modelId;
|
|
163
|
+
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
164
|
+
this.values = options.values;
|
|
165
|
+
}
|
|
166
|
+
static isInstance(error) {
|
|
167
|
+
return AISDKError.hasMarker(error, marker12);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
_a12 = symbol12;
|
|
171
|
+
var name12 = "AI_TypeValidationError";
|
|
172
|
+
var marker13 = `vercel.ai.error.${name12}`;
|
|
173
|
+
var symbol13 = Symbol.for(marker13);
|
|
174
|
+
var _a13;
|
|
175
|
+
_a13 = symbol13;
|
|
176
|
+
var name13 = "AI_UnsupportedFunctionalityError";
|
|
177
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
178
|
+
var symbol14 = Symbol.for(marker14);
|
|
179
|
+
var _a14;
|
|
180
|
+
var UnsupportedFunctionalityError = class extends AISDKError {
|
|
181
|
+
constructor({
|
|
182
|
+
functionality,
|
|
183
|
+
message = `'${functionality}' functionality not supported.`
|
|
184
|
+
}) {
|
|
185
|
+
super({ name: name13, message });
|
|
186
|
+
this[_a14] = true;
|
|
187
|
+
this.functionality = functionality;
|
|
188
|
+
}
|
|
189
|
+
static isInstance(error) {
|
|
190
|
+
return AISDKError.hasMarker(error, marker14);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
_a14 = symbol14;
|
|
194
|
+
|
|
35
195
|
// src/openai-chat-language-model.ts
|
|
36
|
-
var import_provider3 = require("@ai-sdk/provider");
|
|
37
196
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
38
197
|
var import_zod2 = require("zod");
|
|
39
198
|
|
|
40
199
|
// src/convert-to-openai-chat-messages.ts
|
|
41
|
-
var import_provider = require("@ai-sdk/provider");
|
|
42
200
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
43
201
|
function convertToOpenAIChatMessages({
|
|
44
202
|
prompt,
|
|
@@ -83,7 +241,7 @@ function convertToOpenAIChatMessages({
|
|
|
83
241
|
messages.push({
|
|
84
242
|
role: "user",
|
|
85
243
|
content: content.map((part, index) => {
|
|
86
|
-
var
|
|
244
|
+
var _a15, _b, _c, _d;
|
|
87
245
|
switch (part.type) {
|
|
88
246
|
case "text": {
|
|
89
247
|
return { type: "text", text: part.text };
|
|
@@ -92,7 +250,7 @@ function convertToOpenAIChatMessages({
|
|
|
92
250
|
return {
|
|
93
251
|
type: "image_url",
|
|
94
252
|
image_url: {
|
|
95
|
-
url: part.image instanceof URL ? part.image.toString() : `data:${(
|
|
253
|
+
url: part.image instanceof URL ? part.image.toString() : `data:${(_a15 = part.mimeType) != null ? _a15 : "image/jpeg"};base64,${(0, import_provider_utils.convertUint8ArrayToBase64)(part.image)}`,
|
|
96
254
|
// OpenAI specific extension: image detail
|
|
97
255
|
detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
98
256
|
}
|
|
@@ -100,7 +258,7 @@ function convertToOpenAIChatMessages({
|
|
|
100
258
|
}
|
|
101
259
|
case "file": {
|
|
102
260
|
if (part.data instanceof URL) {
|
|
103
|
-
throw new
|
|
261
|
+
throw new UnsupportedFunctionalityError({
|
|
104
262
|
functionality: "'File content parts with URL data' functionality not supported."
|
|
105
263
|
});
|
|
106
264
|
}
|
|
@@ -128,7 +286,7 @@ function convertToOpenAIChatMessages({
|
|
|
128
286
|
};
|
|
129
287
|
}
|
|
130
288
|
default: {
|
|
131
|
-
throw new
|
|
289
|
+
throw new UnsupportedFunctionalityError({
|
|
132
290
|
functionality: `File content part type ${part.mimeType} in user messages`
|
|
133
291
|
});
|
|
134
292
|
}
|
|
@@ -163,7 +321,7 @@ function convertToOpenAIChatMessages({
|
|
|
163
321
|
}
|
|
164
322
|
if (useLegacyFunctionCalling) {
|
|
165
323
|
if (toolCalls.length > 1) {
|
|
166
|
-
throw new
|
|
324
|
+
throw new UnsupportedFunctionalityError({
|
|
167
325
|
functionality: "useLegacyFunctionCalling with multiple tool calls in one message"
|
|
168
326
|
});
|
|
169
327
|
}
|
|
@@ -210,8 +368,8 @@ function convertToOpenAIChatMessages({
|
|
|
210
368
|
|
|
211
369
|
// src/map-openai-chat-logprobs.ts
|
|
212
370
|
function mapOpenAIChatLogProbsOutput(logprobs) {
|
|
213
|
-
var
|
|
214
|
-
return (_b = (
|
|
371
|
+
var _a15, _b;
|
|
372
|
+
return (_b = (_a15 = logprobs == null ? void 0 : logprobs.content) == null ? void 0 : _a15.map(({ token, logprob, top_logprobs }) => ({
|
|
215
373
|
token,
|
|
216
374
|
logprob,
|
|
217
375
|
topLogprobs: top_logprobs ? top_logprobs.map(({ token: token2, logprob: logprob2 }) => ({
|
|
@@ -271,14 +429,13 @@ function getResponseMetadata({
|
|
|
271
429
|
}
|
|
272
430
|
|
|
273
431
|
// src/openai-prepare-tools.ts
|
|
274
|
-
var import_provider2 = require("@ai-sdk/provider");
|
|
275
432
|
function prepareTools({
|
|
276
433
|
mode,
|
|
277
434
|
useLegacyFunctionCalling = false,
|
|
278
435
|
structuredOutputs
|
|
279
436
|
}) {
|
|
280
|
-
var
|
|
281
|
-
const tools = ((
|
|
437
|
+
var _a15;
|
|
438
|
+
const tools = ((_a15 = mode.tools) == null ? void 0 : _a15.length) ? mode.tools : void 0;
|
|
282
439
|
const toolWarnings = [];
|
|
283
440
|
if (tools == null) {
|
|
284
441
|
return { tools: void 0, tool_choice: void 0, toolWarnings };
|
|
@@ -315,7 +472,7 @@ function prepareTools({
|
|
|
315
472
|
toolWarnings
|
|
316
473
|
};
|
|
317
474
|
case "required":
|
|
318
|
-
throw new
|
|
475
|
+
throw new UnsupportedFunctionalityError({
|
|
319
476
|
functionality: "useLegacyFunctionCalling and toolChoice: required"
|
|
320
477
|
});
|
|
321
478
|
default:
|
|
@@ -364,7 +521,7 @@ function prepareTools({
|
|
|
364
521
|
};
|
|
365
522
|
default: {
|
|
366
523
|
const _exhaustiveCheck = type;
|
|
367
|
-
throw new
|
|
524
|
+
throw new UnsupportedFunctionalityError({
|
|
368
525
|
functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
|
|
369
526
|
});
|
|
370
527
|
}
|
|
@@ -380,8 +537,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
380
537
|
this.config = config;
|
|
381
538
|
}
|
|
382
539
|
get supportsStructuredOutputs() {
|
|
383
|
-
var
|
|
384
|
-
return (
|
|
540
|
+
var _a15;
|
|
541
|
+
return (_a15 = this.settings.structuredOutputs) != null ? _a15 : isReasoningModel(this.modelId);
|
|
385
542
|
}
|
|
386
543
|
get defaultObjectGenerationMode() {
|
|
387
544
|
if (isAudioModel(this.modelId)) {
|
|
@@ -409,7 +566,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
409
566
|
seed,
|
|
410
567
|
providerMetadata
|
|
411
568
|
}) {
|
|
412
|
-
var
|
|
569
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h;
|
|
413
570
|
const type = mode.type;
|
|
414
571
|
const warnings = [];
|
|
415
572
|
if (topK != null) {
|
|
@@ -427,12 +584,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
427
584
|
}
|
|
428
585
|
const useLegacyFunctionCalling = this.settings.useLegacyFunctionCalling;
|
|
429
586
|
if (useLegacyFunctionCalling && this.settings.parallelToolCalls === true) {
|
|
430
|
-
throw new
|
|
587
|
+
throw new UnsupportedFunctionalityError({
|
|
431
588
|
functionality: "useLegacyFunctionCalling with parallelToolCalls"
|
|
432
589
|
});
|
|
433
590
|
}
|
|
434
591
|
if (useLegacyFunctionCalling && this.supportsStructuredOutputs) {
|
|
435
|
-
throw new
|
|
592
|
+
throw new UnsupportedFunctionalityError({
|
|
436
593
|
functionality: "structuredOutputs with useLegacyFunctionCalling"
|
|
437
594
|
});
|
|
438
595
|
}
|
|
@@ -464,7 +621,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
464
621
|
json_schema: {
|
|
465
622
|
schema: responseFormat.schema,
|
|
466
623
|
strict: true,
|
|
467
|
-
name: (
|
|
624
|
+
name: (_a15 = responseFormat.name) != null ? _a15 : "response",
|
|
468
625
|
description: responseFormat.description
|
|
469
626
|
}
|
|
470
627
|
} : { type: "json_object" } : void 0,
|
|
@@ -627,7 +784,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
627
784
|
}
|
|
628
785
|
}
|
|
629
786
|
async doGenerate(options) {
|
|
630
|
-
var
|
|
787
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h;
|
|
631
788
|
const { args: body, warnings } = this.getArgs(options);
|
|
632
789
|
const {
|
|
633
790
|
responseHeaders,
|
|
@@ -649,7 +806,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
649
806
|
});
|
|
650
807
|
const { messages: rawPrompt, ...rawSettings } = body;
|
|
651
808
|
const choice = response.choices[0];
|
|
652
|
-
const completionTokenDetails = (
|
|
809
|
+
const completionTokenDetails = (_a15 = response.usage) == null ? void 0 : _a15.completion_tokens_details;
|
|
653
810
|
const promptTokenDetails = (_b = response.usage) == null ? void 0 : _b.prompt_tokens_details;
|
|
654
811
|
const providerMetadata = { openai: {} };
|
|
655
812
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null) {
|
|
@@ -674,10 +831,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
674
831
|
args: choice.message.function_call.arguments
|
|
675
832
|
}
|
|
676
833
|
] : (_d = choice.message.tool_calls) == null ? void 0 : _d.map((toolCall) => {
|
|
677
|
-
var
|
|
834
|
+
var _a16;
|
|
678
835
|
return {
|
|
679
836
|
toolCallType: "function",
|
|
680
|
-
toolCallId: (
|
|
837
|
+
toolCallId: (_a16 = toolCall.id) != null ? _a16 : (0, import_provider_utils3.generateId)(),
|
|
681
838
|
toolName: toolCall.function.name,
|
|
682
839
|
args: toolCall.function.arguments
|
|
683
840
|
};
|
|
@@ -776,7 +933,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
776
933
|
stream: response.pipeThrough(
|
|
777
934
|
new TransformStream({
|
|
778
935
|
transform(chunk, controller) {
|
|
779
|
-
var
|
|
936
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
780
937
|
if (!chunk.success) {
|
|
781
938
|
finishReason = "error";
|
|
782
939
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -853,19 +1010,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
853
1010
|
const index = toolCallDelta.index;
|
|
854
1011
|
if (toolCalls[index] == null) {
|
|
855
1012
|
if (toolCallDelta.type !== "function") {
|
|
856
|
-
throw new
|
|
1013
|
+
throw new InvalidResponseDataError({
|
|
857
1014
|
data: toolCallDelta,
|
|
858
1015
|
message: `Expected 'function' type.`
|
|
859
1016
|
});
|
|
860
1017
|
}
|
|
861
1018
|
if (toolCallDelta.id == null) {
|
|
862
|
-
throw new
|
|
1019
|
+
throw new InvalidResponseDataError({
|
|
863
1020
|
data: toolCallDelta,
|
|
864
1021
|
message: `Expected 'id' to be a string.`
|
|
865
1022
|
});
|
|
866
1023
|
}
|
|
867
|
-
if (((
|
|
868
|
-
throw new
|
|
1024
|
+
if (((_a15 = toolCallDelta.function) == null ? void 0 : _a15.name) == null) {
|
|
1025
|
+
throw new InvalidResponseDataError({
|
|
869
1026
|
data: toolCallDelta,
|
|
870
1027
|
message: `Expected 'function.name' to be a string.`
|
|
871
1028
|
});
|
|
@@ -931,13 +1088,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
931
1088
|
}
|
|
932
1089
|
},
|
|
933
1090
|
flush(controller) {
|
|
934
|
-
var
|
|
1091
|
+
var _a15, _b;
|
|
935
1092
|
controller.enqueue({
|
|
936
1093
|
type: "finish",
|
|
937
1094
|
finishReason,
|
|
938
1095
|
logprobs,
|
|
939
1096
|
usage: {
|
|
940
|
-
promptTokens: (
|
|
1097
|
+
promptTokens: (_a15 = usage.promptTokens) != null ? _a15 : NaN,
|
|
941
1098
|
completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
|
|
942
1099
|
},
|
|
943
1100
|
...providerMetadata != null ? { providerMetadata } : {}
|
|
@@ -1063,11 +1220,11 @@ function isAudioModel(modelId) {
|
|
|
1063
1220
|
return modelId.startsWith("gpt-4o-audio-preview");
|
|
1064
1221
|
}
|
|
1065
1222
|
function getSystemMessageMode(modelId) {
|
|
1066
|
-
var
|
|
1223
|
+
var _a15, _b;
|
|
1067
1224
|
if (!isReasoningModel(modelId)) {
|
|
1068
1225
|
return "system";
|
|
1069
1226
|
}
|
|
1070
|
-
return (_b = (
|
|
1227
|
+
return (_b = (_a15 = reasoningModels[modelId]) == null ? void 0 : _a15.systemMessageMode) != null ? _b : "developer";
|
|
1071
1228
|
}
|
|
1072
1229
|
var reasoningModels = {
|
|
1073
1230
|
"o1-mini": {
|
|
@@ -1103,12 +1260,10 @@ var reasoningModels = {
|
|
|
1103
1260
|
};
|
|
1104
1261
|
|
|
1105
1262
|
// src/openai-completion-language-model.ts
|
|
1106
|
-
var import_provider5 = require("@ai-sdk/provider");
|
|
1107
1263
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1108
1264
|
var import_zod3 = require("zod");
|
|
1109
1265
|
|
|
1110
1266
|
// src/convert-to-openai-completion-prompt.ts
|
|
1111
|
-
var import_provider4 = require("@ai-sdk/provider");
|
|
1112
1267
|
function convertToOpenAICompletionPrompt({
|
|
1113
1268
|
prompt,
|
|
1114
1269
|
inputFormat,
|
|
@@ -1128,7 +1283,7 @@ function convertToOpenAICompletionPrompt({
|
|
|
1128
1283
|
for (const { role, content } of prompt) {
|
|
1129
1284
|
switch (role) {
|
|
1130
1285
|
case "system": {
|
|
1131
|
-
throw new
|
|
1286
|
+
throw new InvalidPromptError({
|
|
1132
1287
|
message: "Unexpected system message in prompt: ${content}",
|
|
1133
1288
|
prompt
|
|
1134
1289
|
});
|
|
@@ -1140,7 +1295,7 @@ function convertToOpenAICompletionPrompt({
|
|
|
1140
1295
|
return part.text;
|
|
1141
1296
|
}
|
|
1142
1297
|
case "image": {
|
|
1143
|
-
throw new
|
|
1298
|
+
throw new UnsupportedFunctionalityError({
|
|
1144
1299
|
functionality: "images"
|
|
1145
1300
|
});
|
|
1146
1301
|
}
|
|
@@ -1159,7 +1314,7 @@ ${userMessage}
|
|
|
1159
1314
|
return part.text;
|
|
1160
1315
|
}
|
|
1161
1316
|
case "tool-call": {
|
|
1162
|
-
throw new
|
|
1317
|
+
throw new UnsupportedFunctionalityError({
|
|
1163
1318
|
functionality: "tool-call messages"
|
|
1164
1319
|
});
|
|
1165
1320
|
}
|
|
@@ -1172,7 +1327,7 @@ ${assistantMessage}
|
|
|
1172
1327
|
break;
|
|
1173
1328
|
}
|
|
1174
1329
|
case "tool": {
|
|
1175
|
-
throw new
|
|
1330
|
+
throw new UnsupportedFunctionalityError({
|
|
1176
1331
|
functionality: "tool messages"
|
|
1177
1332
|
});
|
|
1178
1333
|
}
|
|
@@ -1231,7 +1386,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1231
1386
|
responseFormat,
|
|
1232
1387
|
seed
|
|
1233
1388
|
}) {
|
|
1234
|
-
var
|
|
1389
|
+
var _a15;
|
|
1235
1390
|
const type = mode.type;
|
|
1236
1391
|
const warnings = [];
|
|
1237
1392
|
if (topK != null) {
|
|
@@ -1272,25 +1427,25 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1272
1427
|
};
|
|
1273
1428
|
switch (type) {
|
|
1274
1429
|
case "regular": {
|
|
1275
|
-
if ((
|
|
1276
|
-
throw new
|
|
1430
|
+
if ((_a15 = mode.tools) == null ? void 0 : _a15.length) {
|
|
1431
|
+
throw new UnsupportedFunctionalityError({
|
|
1277
1432
|
functionality: "tools"
|
|
1278
1433
|
});
|
|
1279
1434
|
}
|
|
1280
1435
|
if (mode.toolChoice) {
|
|
1281
|
-
throw new
|
|
1436
|
+
throw new UnsupportedFunctionalityError({
|
|
1282
1437
|
functionality: "toolChoice"
|
|
1283
1438
|
});
|
|
1284
1439
|
}
|
|
1285
1440
|
return { args: baseArgs, warnings };
|
|
1286
1441
|
}
|
|
1287
1442
|
case "object-json": {
|
|
1288
|
-
throw new
|
|
1443
|
+
throw new UnsupportedFunctionalityError({
|
|
1289
1444
|
functionality: "object-json mode"
|
|
1290
1445
|
});
|
|
1291
1446
|
}
|
|
1292
1447
|
case "object-tool": {
|
|
1293
|
-
throw new
|
|
1448
|
+
throw new UnsupportedFunctionalityError({
|
|
1294
1449
|
functionality: "object-tool mode"
|
|
1295
1450
|
});
|
|
1296
1451
|
}
|
|
@@ -1476,7 +1631,6 @@ var openaiCompletionChunkSchema = import_zod3.z.union([
|
|
|
1476
1631
|
]);
|
|
1477
1632
|
|
|
1478
1633
|
// src/openai-embedding-model.ts
|
|
1479
|
-
var import_provider6 = require("@ai-sdk/provider");
|
|
1480
1634
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
1481
1635
|
var import_zod4 = require("zod");
|
|
1482
1636
|
var OpenAIEmbeddingModel = class {
|
|
@@ -1490,12 +1644,12 @@ var OpenAIEmbeddingModel = class {
|
|
|
1490
1644
|
return this.config.provider;
|
|
1491
1645
|
}
|
|
1492
1646
|
get maxEmbeddingsPerCall() {
|
|
1493
|
-
var
|
|
1494
|
-
return (
|
|
1647
|
+
var _a15;
|
|
1648
|
+
return (_a15 = this.settings.maxEmbeddingsPerCall) != null ? _a15 : 2048;
|
|
1495
1649
|
}
|
|
1496
1650
|
get supportsParallelCalls() {
|
|
1497
|
-
var
|
|
1498
|
-
return (
|
|
1651
|
+
var _a15;
|
|
1652
|
+
return (_a15 = this.settings.supportsParallelCalls) != null ? _a15 : true;
|
|
1499
1653
|
}
|
|
1500
1654
|
async doEmbed({
|
|
1501
1655
|
values,
|
|
@@ -1503,7 +1657,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1503
1657
|
abortSignal
|
|
1504
1658
|
}) {
|
|
1505
1659
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1506
|
-
throw new
|
|
1660
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
1507
1661
|
provider: this.provider,
|
|
1508
1662
|
modelId: this.modelId,
|
|
1509
1663
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -1563,8 +1717,8 @@ var OpenAIImageModel = class {
|
|
|
1563
1717
|
this.specificationVersion = "v1";
|
|
1564
1718
|
}
|
|
1565
1719
|
get maxImagesPerCall() {
|
|
1566
|
-
var
|
|
1567
|
-
return (_b = (
|
|
1720
|
+
var _a15, _b;
|
|
1721
|
+
return (_b = (_a15 = this.settings.maxImagesPerCall) != null ? _a15 : modelMaxImagesPerCall[this.modelId]) != null ? _b : 1;
|
|
1568
1722
|
}
|
|
1569
1723
|
get provider() {
|
|
1570
1724
|
return this.config.provider;
|
|
@@ -1579,7 +1733,7 @@ var OpenAIImageModel = class {
|
|
|
1579
1733
|
headers,
|
|
1580
1734
|
abortSignal
|
|
1581
1735
|
}) {
|
|
1582
|
-
var
|
|
1736
|
+
var _a15, _b, _c, _d;
|
|
1583
1737
|
const warnings = [];
|
|
1584
1738
|
if (aspectRatio != null) {
|
|
1585
1739
|
warnings.push({
|
|
@@ -1591,7 +1745,7 @@ var OpenAIImageModel = class {
|
|
|
1591
1745
|
if (seed != null) {
|
|
1592
1746
|
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1593
1747
|
}
|
|
1594
|
-
const currentDate = (_c = (_b = (
|
|
1748
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1595
1749
|
const { value: response, responseHeaders } = await (0, import_provider_utils6.postJsonToApi)({
|
|
1596
1750
|
url: this.config.url({
|
|
1597
1751
|
path: "/images/generations",
|
|
@@ -1711,7 +1865,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1711
1865
|
mediaType,
|
|
1712
1866
|
providerOptions
|
|
1713
1867
|
}) {
|
|
1714
|
-
var
|
|
1868
|
+
var _a15, _b, _c, _d, _e;
|
|
1715
1869
|
const warnings = [];
|
|
1716
1870
|
const openAIOptions = (0, import_provider_utils7.parseProviderOptions)({
|
|
1717
1871
|
provider: "openai",
|
|
@@ -1724,7 +1878,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1724
1878
|
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1725
1879
|
if (openAIOptions) {
|
|
1726
1880
|
const transcriptionModelOptions = {
|
|
1727
|
-
include: (
|
|
1881
|
+
include: (_a15 = openAIOptions.include) != null ? _a15 : void 0,
|
|
1728
1882
|
language: (_b = openAIOptions.language) != null ? _b : void 0,
|
|
1729
1883
|
prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
|
|
1730
1884
|
temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
|
|
@@ -1743,8 +1897,8 @@ var OpenAITranscriptionModel = class {
|
|
|
1743
1897
|
};
|
|
1744
1898
|
}
|
|
1745
1899
|
async doGenerate(options) {
|
|
1746
|
-
var
|
|
1747
|
-
const currentDate = (_c = (_b = (
|
|
1900
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
1901
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1748
1902
|
const { formData, warnings } = this.getArgs(options);
|
|
1749
1903
|
const {
|
|
1750
1904
|
value: response,
|
|
@@ -1861,8 +2015,8 @@ var OpenAISpeechModel = class {
|
|
|
1861
2015
|
};
|
|
1862
2016
|
}
|
|
1863
2017
|
async doGenerate(options) {
|
|
1864
|
-
var
|
|
1865
|
-
const currentDate = (_c = (_b = (
|
|
2018
|
+
var _a15, _b, _c;
|
|
2019
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1866
2020
|
const { requestBody, warnings } = this.getArgs(options);
|
|
1867
2021
|
const {
|
|
1868
2022
|
value: audio,
|
|
@@ -1898,10 +2052,9 @@ var OpenAISpeechModel = class {
|
|
|
1898
2052
|
|
|
1899
2053
|
// src/responses/openai-responses-language-model.ts
|
|
1900
2054
|
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
1901
|
-
var
|
|
2055
|
+
var import_zod12 = require("zod");
|
|
1902
2056
|
|
|
1903
2057
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1904
|
-
var import_provider7 = require("@ai-sdk/provider");
|
|
1905
2058
|
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1906
2059
|
function convertToOpenAIResponsesMessages({
|
|
1907
2060
|
prompt,
|
|
@@ -1941,7 +2094,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1941
2094
|
messages.push({
|
|
1942
2095
|
role: "user",
|
|
1943
2096
|
content: content.map((part, index) => {
|
|
1944
|
-
var
|
|
2097
|
+
var _a15, _b, _c, _d;
|
|
1945
2098
|
switch (part.type) {
|
|
1946
2099
|
case "text": {
|
|
1947
2100
|
return { type: "input_text", text: part.text };
|
|
@@ -1949,14 +2102,14 @@ function convertToOpenAIResponsesMessages({
|
|
|
1949
2102
|
case "image": {
|
|
1950
2103
|
return {
|
|
1951
2104
|
type: "input_image",
|
|
1952
|
-
image_url: part.image instanceof URL ? part.image.toString() : `data:${(
|
|
2105
|
+
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a15 = part.mimeType) != null ? _a15 : "image/jpeg"};base64,${(0, import_provider_utils9.convertUint8ArrayToBase64)(part.image)}`,
|
|
1953
2106
|
// OpenAI specific extension: image detail
|
|
1954
2107
|
detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
1955
2108
|
};
|
|
1956
2109
|
}
|
|
1957
2110
|
case "file": {
|
|
1958
2111
|
if (part.data instanceof URL) {
|
|
1959
|
-
throw new
|
|
2112
|
+
throw new UnsupportedFunctionalityError({
|
|
1960
2113
|
functionality: "File URLs in user messages"
|
|
1961
2114
|
});
|
|
1962
2115
|
}
|
|
@@ -1969,7 +2122,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1969
2122
|
};
|
|
1970
2123
|
}
|
|
1971
2124
|
default: {
|
|
1972
|
-
throw new
|
|
2125
|
+
throw new UnsupportedFunctionalityError({
|
|
1973
2126
|
functionality: "Only PDF files are supported in user messages"
|
|
1974
2127
|
});
|
|
1975
2128
|
}
|
|
@@ -2040,14 +2193,76 @@ function mapOpenAIResponseFinishReason({
|
|
|
2040
2193
|
}
|
|
2041
2194
|
}
|
|
2042
2195
|
|
|
2196
|
+
// src/tool/code-interpreter.ts
|
|
2197
|
+
var import_zod8 = require("zod");
|
|
2198
|
+
var codeInterpreterArgsSchema = import_zod8.z.object({
|
|
2199
|
+
container: import_zod8.z.union([
|
|
2200
|
+
import_zod8.z.string(),
|
|
2201
|
+
import_zod8.z.object({
|
|
2202
|
+
fileIds: import_zod8.z.array(import_zod8.z.string()).optional()
|
|
2203
|
+
})
|
|
2204
|
+
]).optional()
|
|
2205
|
+
});
|
|
2206
|
+
|
|
2207
|
+
// src/tool/file-search.ts
|
|
2208
|
+
var import_zod9 = require("zod");
|
|
2209
|
+
var comparisonFilterSchema = import_zod9.z.object({
|
|
2210
|
+
key: import_zod9.z.string(),
|
|
2211
|
+
type: import_zod9.z.enum(["eq", "ne", "gt", "gte", "lt", "lte"]),
|
|
2212
|
+
value: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.number(), import_zod9.z.boolean()])
|
|
2213
|
+
});
|
|
2214
|
+
var compoundFilterSchema = import_zod9.z.object({
|
|
2215
|
+
type: import_zod9.z.enum(["and", "or"]),
|
|
2216
|
+
filters: import_zod9.z.array(
|
|
2217
|
+
import_zod9.z.union([comparisonFilterSchema, import_zod9.z.lazy(() => compoundFilterSchema)])
|
|
2218
|
+
)
|
|
2219
|
+
});
|
|
2220
|
+
var filtersSchema = import_zod9.z.union([comparisonFilterSchema, compoundFilterSchema]);
|
|
2221
|
+
var fileSearchArgsSchema = import_zod9.z.object({
|
|
2222
|
+
vectorStoreIds: import_zod9.z.array(import_zod9.z.string()).optional(),
|
|
2223
|
+
maxNumResults: import_zod9.z.number().optional(),
|
|
2224
|
+
ranking: import_zod9.z.object({
|
|
2225
|
+
ranker: import_zod9.z.enum(["auto", "default-2024-08-21"]).optional()
|
|
2226
|
+
}).optional(),
|
|
2227
|
+
filters: filtersSchema.optional()
|
|
2228
|
+
});
|
|
2229
|
+
|
|
2230
|
+
// src/tool/web-search.ts
|
|
2231
|
+
var import_zod10 = require("zod");
|
|
2232
|
+
var webSearchArgsSchema = import_zod10.z.object({
|
|
2233
|
+
filters: import_zod10.z.object({
|
|
2234
|
+
allowedDomains: import_zod10.z.array(import_zod10.z.string()).optional()
|
|
2235
|
+
}).optional(),
|
|
2236
|
+
searchContextSize: import_zod10.z.enum(["low", "medium", "high"]).optional(),
|
|
2237
|
+
userLocation: import_zod10.z.object({
|
|
2238
|
+
type: import_zod10.z.literal("approximate"),
|
|
2239
|
+
country: import_zod10.z.string().optional(),
|
|
2240
|
+
city: import_zod10.z.string().optional(),
|
|
2241
|
+
region: import_zod10.z.string().optional(),
|
|
2242
|
+
timezone: import_zod10.z.string().optional()
|
|
2243
|
+
}).optional()
|
|
2244
|
+
});
|
|
2245
|
+
|
|
2246
|
+
// src/tool/web-search-preview.ts
|
|
2247
|
+
var import_zod11 = require("zod");
|
|
2248
|
+
var webSearchPreviewArgsSchema = import_zod11.z.object({
|
|
2249
|
+
searchContextSize: import_zod11.z.enum(["low", "medium", "high"]).optional(),
|
|
2250
|
+
userLocation: import_zod11.z.object({
|
|
2251
|
+
type: import_zod11.z.literal("approximate"),
|
|
2252
|
+
country: import_zod11.z.string().optional(),
|
|
2253
|
+
city: import_zod11.z.string().optional(),
|
|
2254
|
+
region: import_zod11.z.string().optional(),
|
|
2255
|
+
timezone: import_zod11.z.string().optional()
|
|
2256
|
+
}).optional()
|
|
2257
|
+
});
|
|
2258
|
+
|
|
2043
2259
|
// src/responses/openai-responses-prepare-tools.ts
|
|
2044
|
-
var import_provider8 = require("@ai-sdk/provider");
|
|
2045
2260
|
function prepareResponsesTools({
|
|
2046
2261
|
mode,
|
|
2047
2262
|
strict
|
|
2048
2263
|
}) {
|
|
2049
|
-
var
|
|
2050
|
-
const tools = ((
|
|
2264
|
+
var _a15;
|
|
2265
|
+
const tools = ((_a15 = mode.tools) == null ? void 0 : _a15.length) ? mode.tools : void 0;
|
|
2051
2266
|
const toolWarnings = [];
|
|
2052
2267
|
if (tools == null) {
|
|
2053
2268
|
return { tools: void 0, tool_choice: void 0, toolWarnings };
|
|
@@ -2067,31 +2282,48 @@ function prepareResponsesTools({
|
|
|
2067
2282
|
break;
|
|
2068
2283
|
case "provider-defined":
|
|
2069
2284
|
switch (tool.id) {
|
|
2070
|
-
case "openai.file_search":
|
|
2285
|
+
case "openai.file_search": {
|
|
2286
|
+
const args = fileSearchArgsSchema.parse(tool.args);
|
|
2071
2287
|
openaiTools.push({
|
|
2072
2288
|
type: "file_search",
|
|
2073
|
-
vector_store_ids:
|
|
2074
|
-
max_num_results:
|
|
2075
|
-
ranking:
|
|
2076
|
-
filters:
|
|
2289
|
+
vector_store_ids: args.vectorStoreIds,
|
|
2290
|
+
max_num_results: args.maxNumResults,
|
|
2291
|
+
ranking_options: args.ranking ? { ranker: args.ranking.ranker } : void 0,
|
|
2292
|
+
filters: args.filters
|
|
2077
2293
|
});
|
|
2078
2294
|
break;
|
|
2079
|
-
|
|
2295
|
+
}
|
|
2296
|
+
case "openai.web_search_preview": {
|
|
2297
|
+
const args = webSearchPreviewArgsSchema.parse(tool.args);
|
|
2080
2298
|
openaiTools.push({
|
|
2081
2299
|
type: "web_search_preview",
|
|
2082
|
-
search_context_size:
|
|
2083
|
-
user_location:
|
|
2300
|
+
search_context_size: args.searchContextSize,
|
|
2301
|
+
user_location: args.userLocation
|
|
2302
|
+
});
|
|
2303
|
+
break;
|
|
2304
|
+
}
|
|
2305
|
+
case "openai.web_search": {
|
|
2306
|
+
const args = webSearchArgsSchema.parse(tool.args);
|
|
2307
|
+
openaiTools.push({
|
|
2308
|
+
type: "web_search",
|
|
2309
|
+
filters: args.filters != null ? { allowed_domains: args.filters.allowedDomains } : void 0,
|
|
2310
|
+
search_context_size: args.searchContextSize,
|
|
2311
|
+
user_location: args.userLocation
|
|
2084
2312
|
});
|
|
2085
2313
|
break;
|
|
2086
|
-
|
|
2314
|
+
}
|
|
2315
|
+
case "openai.code_interpreter": {
|
|
2316
|
+
const args = codeInterpreterArgsSchema.parse(tool.args);
|
|
2087
2317
|
openaiTools.push({
|
|
2088
2318
|
type: "code_interpreter",
|
|
2089
|
-
container:
|
|
2319
|
+
container: args.container == null ? { type: "auto", file_ids: void 0 } : typeof args.container === "string" ? args.container : { type: "auto", file_ids: args.container.fileIds }
|
|
2090
2320
|
});
|
|
2091
2321
|
break;
|
|
2092
|
-
|
|
2322
|
+
}
|
|
2323
|
+
default: {
|
|
2093
2324
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
2094
2325
|
break;
|
|
2326
|
+
}
|
|
2095
2327
|
}
|
|
2096
2328
|
break;
|
|
2097
2329
|
default:
|
|
@@ -2108,37 +2340,15 @@ function prepareResponsesTools({
|
|
|
2108
2340
|
case "none":
|
|
2109
2341
|
case "required":
|
|
2110
2342
|
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
|
-
}
|
|
2343
|
+
case "tool":
|
|
2130
2344
|
return {
|
|
2131
2345
|
tools: openaiTools,
|
|
2132
|
-
tool_choice: {
|
|
2133
|
-
type: "function",
|
|
2134
|
-
name: toolChoice.toolName
|
|
2135
|
-
},
|
|
2346
|
+
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
2347
|
toolWarnings
|
|
2137
2348
|
};
|
|
2138
|
-
}
|
|
2139
2349
|
default: {
|
|
2140
2350
|
const _exhaustiveCheck = type;
|
|
2141
|
-
throw new
|
|
2351
|
+
throw new UnsupportedFunctionalityError({
|
|
2142
2352
|
functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
|
|
2143
2353
|
});
|
|
2144
2354
|
}
|
|
@@ -2171,7 +2381,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2171
2381
|
providerMetadata,
|
|
2172
2382
|
responseFormat
|
|
2173
2383
|
}) {
|
|
2174
|
-
var
|
|
2384
|
+
var _a15, _b, _c;
|
|
2175
2385
|
const warnings = [];
|
|
2176
2386
|
const modelConfig = getResponsesModelConfig(this.modelId);
|
|
2177
2387
|
const type = mode.type;
|
|
@@ -2216,7 +2426,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2216
2426
|
providerOptions: providerMetadata,
|
|
2217
2427
|
schema: openaiResponsesProviderOptionsSchema
|
|
2218
2428
|
});
|
|
2219
|
-
const isStrict = (
|
|
2429
|
+
const isStrict = (_a15 = openaiOptions == null ? void 0 : openaiOptions.strictSchemas) != null ? _a15 : true;
|
|
2220
2430
|
console.log("openaiOptions", JSON.stringify(openaiOptions));
|
|
2221
2431
|
const baseArgs = {
|
|
2222
2432
|
model: this.modelId,
|
|
@@ -2334,7 +2544,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2334
2544
|
}
|
|
2335
2545
|
}
|
|
2336
2546
|
async doGenerate(options) {
|
|
2337
|
-
var
|
|
2547
|
+
var _a15, _b, _c, _d, _e, _f, _g;
|
|
2338
2548
|
const { args: body, warnings } = this.getArgs(options);
|
|
2339
2549
|
const {
|
|
2340
2550
|
responseHeaders,
|
|
@@ -2349,55 +2559,107 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2349
2559
|
body,
|
|
2350
2560
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2351
2561
|
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
|
-
|
|
2562
|
+
import_zod12.z.object({
|
|
2563
|
+
id: import_zod12.z.string(),
|
|
2564
|
+
created_at: import_zod12.z.number(),
|
|
2565
|
+
model: import_zod12.z.string(),
|
|
2566
|
+
output: import_zod12.z.array(
|
|
2567
|
+
import_zod12.z.discriminatedUnion("type", [
|
|
2568
|
+
import_zod12.z.object({
|
|
2569
|
+
type: import_zod12.z.literal("message"),
|
|
2570
|
+
role: import_zod12.z.literal("assistant"),
|
|
2571
|
+
content: import_zod12.z.array(
|
|
2572
|
+
import_zod12.z.object({
|
|
2573
|
+
type: import_zod12.z.literal("output_text"),
|
|
2574
|
+
text: import_zod12.z.string(),
|
|
2575
|
+
annotations: import_zod12.z.array(
|
|
2576
|
+
import_zod12.z.discriminatedUnion("type", [
|
|
2577
|
+
import_zod12.z.object({
|
|
2578
|
+
type: import_zod12.z.literal("url_citation"),
|
|
2579
|
+
start_index: import_zod12.z.number(),
|
|
2580
|
+
end_index: import_zod12.z.number(),
|
|
2581
|
+
url: import_zod12.z.string(),
|
|
2582
|
+
title: import_zod12.z.string()
|
|
2583
|
+
}),
|
|
2584
|
+
import_zod12.z.object({
|
|
2585
|
+
type: import_zod12.z.literal("file_citation"),
|
|
2586
|
+
file_id: import_zod12.z.string(),
|
|
2587
|
+
filename: import_zod12.z.string().nullish(),
|
|
2588
|
+
index: import_zod12.z.number().nullish(),
|
|
2589
|
+
start_index: import_zod12.z.number().nullish(),
|
|
2590
|
+
end_index: import_zod12.z.number().nullish(),
|
|
2591
|
+
quote: import_zod12.z.string().nullish()
|
|
2592
|
+
}),
|
|
2593
|
+
import_zod12.z.object({
|
|
2594
|
+
type: import_zod12.z.literal("container_file_citation")
|
|
2595
|
+
})
|
|
2596
|
+
])
|
|
2373
2597
|
)
|
|
2374
2598
|
})
|
|
2375
2599
|
)
|
|
2376
2600
|
}),
|
|
2377
|
-
|
|
2378
|
-
type:
|
|
2379
|
-
call_id: import_zod8.z.string(),
|
|
2380
|
-
name: import_zod8.z.string(),
|
|
2381
|
-
arguments: import_zod8.z.string()
|
|
2601
|
+
import_zod12.z.object({
|
|
2602
|
+
type: import_zod12.z.literal("code_interpreter_call")
|
|
2382
2603
|
}),
|
|
2383
|
-
|
|
2384
|
-
type:
|
|
2604
|
+
import_zod12.z.object({
|
|
2605
|
+
type: import_zod12.z.literal("function_call"),
|
|
2606
|
+
call_id: import_zod12.z.string(),
|
|
2607
|
+
name: import_zod12.z.string(),
|
|
2608
|
+
arguments: import_zod12.z.string()
|
|
2385
2609
|
}),
|
|
2386
|
-
|
|
2387
|
-
type:
|
|
2610
|
+
import_zod12.z.object({
|
|
2611
|
+
type: import_zod12.z.literal("web_search_call"),
|
|
2612
|
+
id: import_zod12.z.string(),
|
|
2613
|
+
status: import_zod12.z.string().optional(),
|
|
2614
|
+
action: import_zod12.z.discriminatedUnion("type", [
|
|
2615
|
+
import_zod12.z.object({
|
|
2616
|
+
type: import_zod12.z.literal("search"),
|
|
2617
|
+
query: import_zod12.z.string().nullish()
|
|
2618
|
+
}),
|
|
2619
|
+
import_zod12.z.object({
|
|
2620
|
+
type: import_zod12.z.literal("open_page"),
|
|
2621
|
+
url: import_zod12.z.string()
|
|
2622
|
+
}),
|
|
2623
|
+
import_zod12.z.object({
|
|
2624
|
+
type: import_zod12.z.literal("find"),
|
|
2625
|
+
url: import_zod12.z.string(),
|
|
2626
|
+
pattern: import_zod12.z.string()
|
|
2627
|
+
})
|
|
2628
|
+
]).nullish()
|
|
2629
|
+
}),
|
|
2630
|
+
import_zod12.z.object({
|
|
2631
|
+
type: import_zod12.z.literal("computer_call"),
|
|
2632
|
+
id: import_zod12.z.string(),
|
|
2633
|
+
status: import_zod12.z.string().optional()
|
|
2634
|
+
}),
|
|
2635
|
+
import_zod12.z.object({
|
|
2636
|
+
type: import_zod12.z.literal("file_search_call"),
|
|
2637
|
+
id: import_zod12.z.string(),
|
|
2638
|
+
status: import_zod12.z.string().optional(),
|
|
2639
|
+
queries: import_zod12.z.array(import_zod12.z.string()).nullish(),
|
|
2640
|
+
results: import_zod12.z.array(
|
|
2641
|
+
import_zod12.z.object({
|
|
2642
|
+
attributes: import_zod12.z.object({
|
|
2643
|
+
file_id: import_zod12.z.string(),
|
|
2644
|
+
filename: import_zod12.z.string(),
|
|
2645
|
+
score: import_zod12.z.number(),
|
|
2646
|
+
text: import_zod12.z.string()
|
|
2647
|
+
})
|
|
2648
|
+
})
|
|
2649
|
+
).nullish()
|
|
2388
2650
|
}),
|
|
2389
|
-
|
|
2390
|
-
type:
|
|
2391
|
-
summary:
|
|
2392
|
-
|
|
2393
|
-
type:
|
|
2394
|
-
text:
|
|
2651
|
+
import_zod12.z.object({
|
|
2652
|
+
type: import_zod12.z.literal("reasoning"),
|
|
2653
|
+
summary: import_zod12.z.array(
|
|
2654
|
+
import_zod12.z.object({
|
|
2655
|
+
type: import_zod12.z.literal("summary_text"),
|
|
2656
|
+
text: import_zod12.z.string()
|
|
2395
2657
|
})
|
|
2396
2658
|
)
|
|
2397
2659
|
})
|
|
2398
2660
|
])
|
|
2399
2661
|
),
|
|
2400
|
-
incomplete_details:
|
|
2662
|
+
incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullable(),
|
|
2401
2663
|
usage: usageSchema
|
|
2402
2664
|
})
|
|
2403
2665
|
),
|
|
@@ -2405,13 +2667,39 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2405
2667
|
fetch: this.config.fetch
|
|
2406
2668
|
});
|
|
2407
2669
|
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
|
-
|
|
2414
|
-
|
|
2670
|
+
const toolCalls = [];
|
|
2671
|
+
for (const output of response.output) {
|
|
2672
|
+
if (output.type === "function_call") {
|
|
2673
|
+
toolCalls.push({
|
|
2674
|
+
toolCallType: "function",
|
|
2675
|
+
toolCallId: output.call_id,
|
|
2676
|
+
toolName: output.name,
|
|
2677
|
+
args: output.arguments
|
|
2678
|
+
});
|
|
2679
|
+
} else if (output.type === "web_search_call") {
|
|
2680
|
+
toolCalls.push({
|
|
2681
|
+
toolCallType: "function",
|
|
2682
|
+
toolCallId: output.id,
|
|
2683
|
+
toolName: "web_search_preview",
|
|
2684
|
+
args: JSON.stringify({ action: output.action })
|
|
2685
|
+
});
|
|
2686
|
+
} else if (output.type === "computer_call") {
|
|
2687
|
+
toolCalls.push({
|
|
2688
|
+
toolCallType: "function",
|
|
2689
|
+
toolCallId: output.id,
|
|
2690
|
+
toolName: "computer_use",
|
|
2691
|
+
args: ""
|
|
2692
|
+
});
|
|
2693
|
+
} else if (output.type === "file_search_call") {
|
|
2694
|
+
toolCalls.push({
|
|
2695
|
+
toolCallType: "function",
|
|
2696
|
+
toolCallId: output.id,
|
|
2697
|
+
toolName: "file_search",
|
|
2698
|
+
args: ""
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
const reasoningSummary = (_b = (_a15 = response.output.find((item) => item.type === "reasoning")) == null ? void 0 : _a15.summary) != null ? _b : null;
|
|
2415
2703
|
console.log(JSON.stringify({
|
|
2416
2704
|
msg: "ai-sdk: content annotations",
|
|
2417
2705
|
annotations: outputTextElements.flatMap((content) => content.annotations)
|
|
@@ -2420,13 +2708,31 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2420
2708
|
text: outputTextElements.map((content) => content.text).join("\n"),
|
|
2421
2709
|
sources: outputTextElements.flatMap(
|
|
2422
2710
|
(content) => content.annotations.map((annotation) => {
|
|
2423
|
-
var
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2711
|
+
var _a16, _b2, _c2, _d2, _e2, _f2, _g2, _h, _i;
|
|
2712
|
+
if (annotation.type === "url_citation") {
|
|
2713
|
+
return {
|
|
2714
|
+
sourceType: "url",
|
|
2715
|
+
id: (_c2 = (_b2 = (_a16 = this.config).generateId) == null ? void 0 : _b2.call(_a16)) != null ? _c2 : (0, import_provider_utils10.generateId)(),
|
|
2716
|
+
url: annotation.url,
|
|
2717
|
+
title: annotation.title
|
|
2718
|
+
};
|
|
2719
|
+
} else if (annotation.type === "file_citation") {
|
|
2720
|
+
return {
|
|
2721
|
+
sourceType: "document",
|
|
2722
|
+
id: (_f2 = (_e2 = (_d2 = this.config).generateId) == null ? void 0 : _e2.call(_d2)) != null ? _f2 : (0, import_provider_utils10.generateId)(),
|
|
2723
|
+
mediaType: "text/plain",
|
|
2724
|
+
title: annotation.quote || annotation.filename || "Document",
|
|
2725
|
+
filename: annotation.filename,
|
|
2726
|
+
quote: annotation.quote
|
|
2727
|
+
};
|
|
2728
|
+
} else {
|
|
2729
|
+
return {
|
|
2730
|
+
sourceType: "url",
|
|
2731
|
+
id: (_i = (_h = (_g2 = this.config).generateId) == null ? void 0 : _h.call(_g2)) != null ? _i : (0, import_provider_utils10.generateId)(),
|
|
2732
|
+
url: "",
|
|
2733
|
+
title: "Unknown Source"
|
|
2734
|
+
};
|
|
2735
|
+
}
|
|
2430
2736
|
})
|
|
2431
2737
|
),
|
|
2432
2738
|
finishReason: mapOpenAIResponseFinishReason({
|
|
@@ -2500,7 +2806,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2500
2806
|
stream: response.pipeThrough(
|
|
2501
2807
|
new TransformStream({
|
|
2502
2808
|
transform(chunk, controller) {
|
|
2503
|
-
var
|
|
2809
|
+
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2504
2810
|
if (!chunk.success) {
|
|
2505
2811
|
finishReason = "error";
|
|
2506
2812
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2520,6 +2826,42 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2520
2826
|
toolName: value.item.name,
|
|
2521
2827
|
argsTextDelta: value.item.arguments
|
|
2522
2828
|
});
|
|
2829
|
+
} else if (value.item.type === "web_search_call") {
|
|
2830
|
+
ongoingToolCalls[value.output_index] = {
|
|
2831
|
+
toolName: "web_search_preview",
|
|
2832
|
+
toolCallId: value.item.id
|
|
2833
|
+
};
|
|
2834
|
+
controller.enqueue({
|
|
2835
|
+
type: "tool-call-delta",
|
|
2836
|
+
toolCallType: "function",
|
|
2837
|
+
toolCallId: value.item.id,
|
|
2838
|
+
toolName: "web_search_preview",
|
|
2839
|
+
argsTextDelta: JSON.stringify({ action: value.item.action })
|
|
2840
|
+
});
|
|
2841
|
+
} else if (value.item.type === "computer_call") {
|
|
2842
|
+
ongoingToolCalls[value.output_index] = {
|
|
2843
|
+
toolName: "computer_use",
|
|
2844
|
+
toolCallId: value.item.id
|
|
2845
|
+
};
|
|
2846
|
+
controller.enqueue({
|
|
2847
|
+
type: "tool-call-delta",
|
|
2848
|
+
toolCallType: "function",
|
|
2849
|
+
toolCallId: value.item.id,
|
|
2850
|
+
toolName: "computer_use",
|
|
2851
|
+
argsTextDelta: ""
|
|
2852
|
+
});
|
|
2853
|
+
} else if (value.item.type === "file_search_call") {
|
|
2854
|
+
ongoingToolCalls[value.output_index] = {
|
|
2855
|
+
toolName: "file_search",
|
|
2856
|
+
toolCallId: value.item.id
|
|
2857
|
+
};
|
|
2858
|
+
controller.enqueue({
|
|
2859
|
+
type: "tool-call-delta",
|
|
2860
|
+
toolCallType: "function",
|
|
2861
|
+
toolCallId: value.item.id,
|
|
2862
|
+
toolName: "file_search",
|
|
2863
|
+
argsTextDelta: ""
|
|
2864
|
+
});
|
|
2523
2865
|
}
|
|
2524
2866
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2525
2867
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -2550,19 +2892,54 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2550
2892
|
type: "reasoning",
|
|
2551
2893
|
textDelta: value.delta
|
|
2552
2894
|
});
|
|
2553
|
-
} else if (isResponseOutputItemDoneChunk(value)
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2895
|
+
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
2896
|
+
if (value.item.type === "function_call") {
|
|
2897
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2898
|
+
hasToolCalls = true;
|
|
2899
|
+
controller.enqueue({
|
|
2900
|
+
type: "tool-call",
|
|
2901
|
+
toolCallType: "function",
|
|
2902
|
+
toolCallId: value.item.call_id,
|
|
2903
|
+
toolName: value.item.name,
|
|
2904
|
+
args: value.item.arguments
|
|
2905
|
+
});
|
|
2906
|
+
} else if (value.item.type === "web_search_call") {
|
|
2907
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2908
|
+
hasToolCalls = true;
|
|
2909
|
+
controller.enqueue({
|
|
2910
|
+
type: "tool-call",
|
|
2911
|
+
toolCallType: "function",
|
|
2912
|
+
toolCallId: value.item.id,
|
|
2913
|
+
toolName: "web_search_preview",
|
|
2914
|
+
args: JSON.stringify({ action: value.item.action })
|
|
2915
|
+
});
|
|
2916
|
+
} else if (value.item.type === "computer_call") {
|
|
2917
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2918
|
+
hasToolCalls = true;
|
|
2919
|
+
controller.enqueue({
|
|
2920
|
+
type: "tool-call",
|
|
2921
|
+
toolCallType: "function",
|
|
2922
|
+
toolCallId: value.item.id,
|
|
2923
|
+
toolName: "computer_use",
|
|
2924
|
+
args: ""
|
|
2925
|
+
});
|
|
2926
|
+
} else if (value.item.type === "file_search_call") {
|
|
2927
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2928
|
+
hasToolCalls = true;
|
|
2929
|
+
controller.enqueue({
|
|
2930
|
+
type: "tool-call",
|
|
2931
|
+
toolCallType: "function",
|
|
2932
|
+
toolCallId: value.item.id,
|
|
2933
|
+
toolName: "file_search",
|
|
2934
|
+
args: JSON.stringify({
|
|
2935
|
+
queries: value.item.queries,
|
|
2936
|
+
results: value.item.results
|
|
2937
|
+
})
|
|
2938
|
+
});
|
|
2939
|
+
}
|
|
2563
2940
|
} else if (isResponseFinishedChunk(value)) {
|
|
2564
2941
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2565
|
-
finishReason: (
|
|
2942
|
+
finishReason: (_a15 = value.response.incomplete_details) == null ? void 0 : _a15.reason,
|
|
2566
2943
|
hasToolCalls
|
|
2567
2944
|
});
|
|
2568
2945
|
promptTokens = value.response.usage.input_tokens;
|
|
@@ -2574,21 +2951,29 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2574
2951
|
msg: "ai-sdk: source (stream)",
|
|
2575
2952
|
source: value.annotation
|
|
2576
2953
|
}));
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2954
|
+
if (value.annotation.type === "url_citation") {
|
|
2955
|
+
controller.enqueue({
|
|
2956
|
+
type: "source",
|
|
2957
|
+
source: {
|
|
2958
|
+
sourceType: "url",
|
|
2959
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils10.generateId)(),
|
|
2960
|
+
url: value.annotation.url,
|
|
2961
|
+
title: value.annotation.title
|
|
2962
|
+
}
|
|
2963
|
+
});
|
|
2964
|
+
} else if (value.annotation.type === "file_citation") {
|
|
2965
|
+
controller.enqueue({
|
|
2966
|
+
type: "source",
|
|
2967
|
+
source: {
|
|
2968
|
+
sourceType: "document",
|
|
2969
|
+
id: (_k = (_j = (_i = self.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils10.generateId)(),
|
|
2970
|
+
mediaType: "text/plain",
|
|
2971
|
+
title: value.annotation.quote || value.annotation.filename || "Document",
|
|
2585
2972
|
filename: value.annotation.filename,
|
|
2586
|
-
|
|
2587
|
-
}
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
}
|
|
2591
|
-
});
|
|
2973
|
+
quote: value.annotation.quote
|
|
2974
|
+
}
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2592
2977
|
}
|
|
2593
2978
|
},
|
|
2594
2979
|
flush(controller) {
|
|
@@ -2619,91 +3004,168 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2619
3004
|
};
|
|
2620
3005
|
}
|
|
2621
3006
|
};
|
|
2622
|
-
var usageSchema =
|
|
2623
|
-
input_tokens:
|
|
2624
|
-
input_tokens_details:
|
|
2625
|
-
output_tokens:
|
|
2626
|
-
output_tokens_details:
|
|
3007
|
+
var usageSchema = import_zod12.z.object({
|
|
3008
|
+
input_tokens: import_zod12.z.number(),
|
|
3009
|
+
input_tokens_details: import_zod12.z.object({ cached_tokens: import_zod12.z.number().nullish() }).nullish(),
|
|
3010
|
+
output_tokens: import_zod12.z.number(),
|
|
3011
|
+
output_tokens_details: import_zod12.z.object({ reasoning_tokens: import_zod12.z.number().nullish() }).nullish()
|
|
2627
3012
|
});
|
|
2628
|
-
var textDeltaChunkSchema =
|
|
2629
|
-
type:
|
|
2630
|
-
delta:
|
|
3013
|
+
var textDeltaChunkSchema = import_zod12.z.object({
|
|
3014
|
+
type: import_zod12.z.literal("response.output_text.delta"),
|
|
3015
|
+
delta: import_zod12.z.string()
|
|
2631
3016
|
});
|
|
2632
|
-
var responseFinishedChunkSchema =
|
|
2633
|
-
type:
|
|
2634
|
-
response:
|
|
2635
|
-
incomplete_details:
|
|
3017
|
+
var responseFinishedChunkSchema = import_zod12.z.object({
|
|
3018
|
+
type: import_zod12.z.enum(["response.completed", "response.incomplete"]),
|
|
3019
|
+
response: import_zod12.z.object({
|
|
3020
|
+
incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullish(),
|
|
2636
3021
|
usage: usageSchema
|
|
2637
3022
|
})
|
|
2638
3023
|
});
|
|
2639
|
-
var responseCreatedChunkSchema =
|
|
2640
|
-
type:
|
|
2641
|
-
response:
|
|
2642
|
-
id:
|
|
2643
|
-
created_at:
|
|
2644
|
-
model:
|
|
3024
|
+
var responseCreatedChunkSchema = import_zod12.z.object({
|
|
3025
|
+
type: import_zod12.z.literal("response.created"),
|
|
3026
|
+
response: import_zod12.z.object({
|
|
3027
|
+
id: import_zod12.z.string(),
|
|
3028
|
+
created_at: import_zod12.z.number(),
|
|
3029
|
+
model: import_zod12.z.string()
|
|
2645
3030
|
})
|
|
2646
3031
|
});
|
|
2647
|
-
var responseOutputItemDoneSchema =
|
|
2648
|
-
type:
|
|
2649
|
-
output_index:
|
|
2650
|
-
item:
|
|
2651
|
-
|
|
2652
|
-
type:
|
|
3032
|
+
var responseOutputItemDoneSchema = import_zod12.z.object({
|
|
3033
|
+
type: import_zod12.z.literal("response.output_item.done"),
|
|
3034
|
+
output_index: import_zod12.z.number(),
|
|
3035
|
+
item: import_zod12.z.discriminatedUnion("type", [
|
|
3036
|
+
import_zod12.z.object({
|
|
3037
|
+
type: import_zod12.z.literal("message")
|
|
2653
3038
|
}),
|
|
2654
|
-
|
|
2655
|
-
type:
|
|
2656
|
-
id:
|
|
2657
|
-
call_id:
|
|
2658
|
-
name:
|
|
2659
|
-
arguments:
|
|
2660
|
-
status:
|
|
3039
|
+
import_zod12.z.object({
|
|
3040
|
+
type: import_zod12.z.literal("function_call"),
|
|
3041
|
+
id: import_zod12.z.string(),
|
|
3042
|
+
call_id: import_zod12.z.string(),
|
|
3043
|
+
name: import_zod12.z.string(),
|
|
3044
|
+
arguments: import_zod12.z.string(),
|
|
3045
|
+
status: import_zod12.z.literal("completed")
|
|
3046
|
+
}),
|
|
3047
|
+
import_zod12.z.object({
|
|
3048
|
+
type: import_zod12.z.literal("web_search_call"),
|
|
3049
|
+
id: import_zod12.z.string(),
|
|
3050
|
+
status: import_zod12.z.string(),
|
|
3051
|
+
action: import_zod12.z.discriminatedUnion("type", [
|
|
3052
|
+
import_zod12.z.object({
|
|
3053
|
+
type: import_zod12.z.literal("search"),
|
|
3054
|
+
query: import_zod12.z.string().nullish()
|
|
3055
|
+
}),
|
|
3056
|
+
import_zod12.z.object({
|
|
3057
|
+
type: import_zod12.z.literal("open_page"),
|
|
3058
|
+
url: import_zod12.z.string()
|
|
3059
|
+
}),
|
|
3060
|
+
import_zod12.z.object({
|
|
3061
|
+
type: import_zod12.z.literal("find"),
|
|
3062
|
+
url: import_zod12.z.string(),
|
|
3063
|
+
pattern: import_zod12.z.string()
|
|
3064
|
+
})
|
|
3065
|
+
]).nullish()
|
|
3066
|
+
}),
|
|
3067
|
+
import_zod12.z.object({
|
|
3068
|
+
type: import_zod12.z.literal("computer_call"),
|
|
3069
|
+
id: import_zod12.z.string(),
|
|
3070
|
+
status: import_zod12.z.literal("completed")
|
|
3071
|
+
}),
|
|
3072
|
+
import_zod12.z.object({
|
|
3073
|
+
type: import_zod12.z.literal("file_search_call"),
|
|
3074
|
+
id: import_zod12.z.string(),
|
|
3075
|
+
status: import_zod12.z.literal("completed"),
|
|
3076
|
+
queries: import_zod12.z.array(import_zod12.z.string()).nullish(),
|
|
3077
|
+
results: import_zod12.z.array(
|
|
3078
|
+
import_zod12.z.object({
|
|
3079
|
+
attributes: import_zod12.z.object({
|
|
3080
|
+
file_id: import_zod12.z.string(),
|
|
3081
|
+
filename: import_zod12.z.string(),
|
|
3082
|
+
score: import_zod12.z.number(),
|
|
3083
|
+
text: import_zod12.z.string()
|
|
3084
|
+
})
|
|
3085
|
+
})
|
|
3086
|
+
).nullish()
|
|
2661
3087
|
})
|
|
2662
3088
|
])
|
|
2663
3089
|
});
|
|
2664
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2665
|
-
type:
|
|
2666
|
-
item_id:
|
|
2667
|
-
output_index:
|
|
2668
|
-
delta:
|
|
3090
|
+
var responseFunctionCallArgumentsDeltaSchema = import_zod12.z.object({
|
|
3091
|
+
type: import_zod12.z.literal("response.function_call_arguments.delta"),
|
|
3092
|
+
item_id: import_zod12.z.string(),
|
|
3093
|
+
output_index: import_zod12.z.number(),
|
|
3094
|
+
delta: import_zod12.z.string()
|
|
2669
3095
|
});
|
|
2670
|
-
var responseOutputItemAddedSchema =
|
|
2671
|
-
type:
|
|
2672
|
-
output_index:
|
|
2673
|
-
item:
|
|
2674
|
-
|
|
2675
|
-
type:
|
|
3096
|
+
var responseOutputItemAddedSchema = import_zod12.z.object({
|
|
3097
|
+
type: import_zod12.z.literal("response.output_item.added"),
|
|
3098
|
+
output_index: import_zod12.z.number(),
|
|
3099
|
+
item: import_zod12.z.discriminatedUnion("type", [
|
|
3100
|
+
import_zod12.z.object({
|
|
3101
|
+
type: import_zod12.z.literal("message")
|
|
2676
3102
|
}),
|
|
2677
|
-
|
|
2678
|
-
type:
|
|
2679
|
-
id:
|
|
2680
|
-
call_id:
|
|
2681
|
-
name:
|
|
2682
|
-
arguments:
|
|
3103
|
+
import_zod12.z.object({
|
|
3104
|
+
type: import_zod12.z.literal("function_call"),
|
|
3105
|
+
id: import_zod12.z.string(),
|
|
3106
|
+
call_id: import_zod12.z.string(),
|
|
3107
|
+
name: import_zod12.z.string(),
|
|
3108
|
+
arguments: import_zod12.z.string()
|
|
3109
|
+
}),
|
|
3110
|
+
import_zod12.z.object({
|
|
3111
|
+
type: import_zod12.z.literal("web_search_call"),
|
|
3112
|
+
id: import_zod12.z.string(),
|
|
3113
|
+
status: import_zod12.z.string(),
|
|
3114
|
+
action: import_zod12.z.object({
|
|
3115
|
+
type: import_zod12.z.literal("search"),
|
|
3116
|
+
query: import_zod12.z.string().optional()
|
|
3117
|
+
}).nullish()
|
|
3118
|
+
}),
|
|
3119
|
+
import_zod12.z.object({
|
|
3120
|
+
type: import_zod12.z.literal("computer_call"),
|
|
3121
|
+
id: import_zod12.z.string(),
|
|
3122
|
+
status: import_zod12.z.string()
|
|
3123
|
+
}),
|
|
3124
|
+
import_zod12.z.object({
|
|
3125
|
+
type: import_zod12.z.literal("file_search_call"),
|
|
3126
|
+
id: import_zod12.z.string(),
|
|
3127
|
+
status: import_zod12.z.string(),
|
|
3128
|
+
queries: import_zod12.z.array(import_zod12.z.string()).nullish(),
|
|
3129
|
+
results: import_zod12.z.array(
|
|
3130
|
+
import_zod12.z.object({
|
|
3131
|
+
attributes: import_zod12.z.object({
|
|
3132
|
+
file_id: import_zod12.z.string(),
|
|
3133
|
+
filename: import_zod12.z.string(),
|
|
3134
|
+
score: import_zod12.z.number(),
|
|
3135
|
+
text: import_zod12.z.string()
|
|
3136
|
+
})
|
|
3137
|
+
})
|
|
3138
|
+
).optional()
|
|
2683
3139
|
})
|
|
2684
3140
|
])
|
|
2685
3141
|
});
|
|
2686
|
-
var responseAnnotationAddedSchema =
|
|
2687
|
-
type:
|
|
2688
|
-
annotation:
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
3142
|
+
var responseAnnotationAddedSchema = import_zod12.z.object({
|
|
3143
|
+
type: import_zod12.z.literal("response.output_text.annotation.added"),
|
|
3144
|
+
annotation: import_zod12.z.discriminatedUnion("type", [
|
|
3145
|
+
import_zod12.z.object({
|
|
3146
|
+
type: import_zod12.z.literal("url_citation"),
|
|
3147
|
+
url: import_zod12.z.string(),
|
|
3148
|
+
title: import_zod12.z.string()
|
|
3149
|
+
}),
|
|
3150
|
+
import_zod12.z.object({
|
|
3151
|
+
type: import_zod12.z.literal("file_citation"),
|
|
3152
|
+
file_id: import_zod12.z.string(),
|
|
3153
|
+
filename: import_zod12.z.string().nullish(),
|
|
3154
|
+
index: import_zod12.z.number().nullish(),
|
|
3155
|
+
start_index: import_zod12.z.number().nullish(),
|
|
3156
|
+
end_index: import_zod12.z.number().nullish(),
|
|
3157
|
+
quote: import_zod12.z.string().nullish()
|
|
3158
|
+
})
|
|
3159
|
+
])
|
|
2698
3160
|
});
|
|
2699
|
-
var responseReasoningSummaryTextDeltaSchema =
|
|
2700
|
-
type:
|
|
2701
|
-
item_id:
|
|
2702
|
-
output_index:
|
|
2703
|
-
summary_index:
|
|
2704
|
-
delta:
|
|
3161
|
+
var responseReasoningSummaryTextDeltaSchema = import_zod12.z.object({
|
|
3162
|
+
type: import_zod12.z.literal("response.reasoning_summary_text.delta"),
|
|
3163
|
+
item_id: import_zod12.z.string(),
|
|
3164
|
+
output_index: import_zod12.z.number(),
|
|
3165
|
+
summary_index: import_zod12.z.number(),
|
|
3166
|
+
delta: import_zod12.z.string()
|
|
2705
3167
|
});
|
|
2706
|
-
var openaiResponsesChunkSchema =
|
|
3168
|
+
var openaiResponsesChunkSchema = import_zod12.z.union([
|
|
2707
3169
|
textDeltaChunkSchema,
|
|
2708
3170
|
responseFinishedChunkSchema,
|
|
2709
3171
|
responseCreatedChunkSchema,
|
|
@@ -2712,7 +3174,7 @@ var openaiResponsesChunkSchema = import_zod8.z.union([
|
|
|
2712
3174
|
responseOutputItemAddedSchema,
|
|
2713
3175
|
responseAnnotationAddedSchema,
|
|
2714
3176
|
responseReasoningSummaryTextDeltaSchema,
|
|
2715
|
-
|
|
3177
|
+
import_zod12.z.object({ type: import_zod12.z.string() }).passthrough()
|
|
2716
3178
|
// fallback for unknown chunks
|
|
2717
3179
|
]);
|
|
2718
3180
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2760,18 +3222,18 @@ function getResponsesModelConfig(modelId) {
|
|
|
2760
3222
|
requiredAutoTruncation: false
|
|
2761
3223
|
};
|
|
2762
3224
|
}
|
|
2763
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2764
|
-
metadata:
|
|
2765
|
-
parallelToolCalls:
|
|
2766
|
-
include:
|
|
2767
|
-
previousResponseId:
|
|
2768
|
-
forceNoTemperature:
|
|
2769
|
-
store:
|
|
2770
|
-
user:
|
|
2771
|
-
reasoningEffort:
|
|
2772
|
-
strictSchemas:
|
|
2773
|
-
instructions:
|
|
2774
|
-
reasoningSummary:
|
|
3225
|
+
var openaiResponsesProviderOptionsSchema = import_zod12.z.object({
|
|
3226
|
+
metadata: import_zod12.z.any().nullish(),
|
|
3227
|
+
parallelToolCalls: import_zod12.z.boolean().nullish(),
|
|
3228
|
+
include: import_zod12.z.array(import_zod12.z.string()).nullish(),
|
|
3229
|
+
previousResponseId: import_zod12.z.string().nullish(),
|
|
3230
|
+
forceNoTemperature: import_zod12.z.boolean().nullish(),
|
|
3231
|
+
store: import_zod12.z.boolean().nullish(),
|
|
3232
|
+
user: import_zod12.z.string().nullish(),
|
|
3233
|
+
reasoningEffort: import_zod12.z.string().nullish(),
|
|
3234
|
+
strictSchemas: import_zod12.z.boolean().nullish(),
|
|
3235
|
+
instructions: import_zod12.z.string().nullish(),
|
|
3236
|
+
reasoningSummary: import_zod12.z.string().nullish()
|
|
2775
3237
|
});
|
|
2776
3238
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2777
3239
|
0 && (module.exports = {
|