@ai-sdk/openai 2.0.0-canary.0 → 2.0.0-canary.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +120 -0
- package/dist/index.d.mts +35 -102
- package/dist/index.d.ts +35 -102
- package/dist/index.js +987 -889
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1007 -899
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +390 -0
- package/dist/internal/index.d.ts +390 -0
- package/{internal/dist → dist/internal}/index.js +967 -877
- package/dist/internal/index.js.map +1 -0
- package/{internal/dist → dist/internal}/index.mjs +980 -884
- package/dist/internal/index.mjs.map +1 -0
- package/package.json +15 -15
- package/internal/dist/index.d.mts +0 -290
- package/internal/dist/index.d.ts +0 -290
- package/internal/dist/index.js.map +0 -1
- package/internal/dist/index.mjs.map +0 -1
|
@@ -25,21 +25,24 @@ __export(internal_exports, {
|
|
|
25
25
|
OpenAIEmbeddingModel: () => OpenAIEmbeddingModel,
|
|
26
26
|
OpenAIImageModel: () => OpenAIImageModel,
|
|
27
27
|
OpenAIResponsesLanguageModel: () => OpenAIResponsesLanguageModel,
|
|
28
|
-
|
|
28
|
+
OpenAISpeechModel: () => OpenAISpeechModel,
|
|
29
|
+
OpenAITranscriptionModel: () => OpenAITranscriptionModel,
|
|
30
|
+
modelMaxImagesPerCall: () => modelMaxImagesPerCall,
|
|
31
|
+
openaiEmbeddingProviderOptions: () => openaiEmbeddingProviderOptions,
|
|
32
|
+
openaiProviderOptions: () => openaiProviderOptions
|
|
29
33
|
});
|
|
30
34
|
module.exports = __toCommonJS(internal_exports);
|
|
31
35
|
|
|
32
36
|
// src/openai-chat-language-model.ts
|
|
33
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
34
38
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
35
|
-
var
|
|
39
|
+
var import_zod3 = require("zod");
|
|
36
40
|
|
|
37
41
|
// src/convert-to-openai-chat-messages.ts
|
|
38
42
|
var import_provider = require("@ai-sdk/provider");
|
|
39
43
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
40
44
|
function convertToOpenAIChatMessages({
|
|
41
45
|
prompt,
|
|
42
|
-
useLegacyFunctionCalling = false,
|
|
43
46
|
systemMessageMode = "system"
|
|
44
47
|
}) {
|
|
45
48
|
const messages = [];
|
|
@@ -80,55 +83,71 @@ function convertToOpenAIChatMessages({
|
|
|
80
83
|
messages.push({
|
|
81
84
|
role: "user",
|
|
82
85
|
content: content.map((part, index) => {
|
|
83
|
-
var _a, _b, _c
|
|
86
|
+
var _a, _b, _c;
|
|
84
87
|
switch (part.type) {
|
|
85
88
|
case "text": {
|
|
86
89
|
return { type: "text", text: part.text };
|
|
87
90
|
}
|
|
88
|
-
case "image": {
|
|
89
|
-
return {
|
|
90
|
-
type: "image_url",
|
|
91
|
-
image_url: {
|
|
92
|
-
url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils.convertUint8ArrayToBase64)(part.image)}`,
|
|
93
|
-
// OpenAI specific extension: image detail
|
|
94
|
-
detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
91
|
case "file": {
|
|
99
|
-
if (part.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
type: "input_audio",
|
|
115
|
-
input_audio: { data: part.data, format: "mp3" }
|
|
116
|
-
};
|
|
92
|
+
if (part.mediaType.startsWith("image/")) {
|
|
93
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
94
|
+
return {
|
|
95
|
+
type: "image_url",
|
|
96
|
+
image_url: {
|
|
97
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`,
|
|
98
|
+
// OpenAI specific extension: image detail
|
|
99
|
+
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
} else if (part.mediaType.startsWith("audio/")) {
|
|
103
|
+
if (part.data instanceof URL) {
|
|
104
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
105
|
+
functionality: "audio file parts with URLs"
|
|
106
|
+
});
|
|
117
107
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
108
|
+
switch (part.mediaType) {
|
|
109
|
+
case "audio/wav": {
|
|
110
|
+
return {
|
|
111
|
+
type: "input_audio",
|
|
112
|
+
input_audio: {
|
|
113
|
+
data: (0, import_provider_utils.convertToBase64)(part.data),
|
|
114
|
+
format: "wav"
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
case "audio/mp3":
|
|
119
|
+
case "audio/mpeg": {
|
|
120
|
+
return {
|
|
121
|
+
type: "input_audio",
|
|
122
|
+
input_audio: {
|
|
123
|
+
data: (0, import_provider_utils.convertToBase64)(part.data),
|
|
124
|
+
format: "mp3"
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
default: {
|
|
129
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
130
|
+
functionality: `audio content parts with media type ${part.mediaType}`
|
|
131
|
+
});
|
|
132
|
+
}
|
|
126
133
|
}
|
|
127
|
-
|
|
134
|
+
} else if (part.mediaType === "application/pdf") {
|
|
135
|
+
if (part.data instanceof URL) {
|
|
128
136
|
throw new import_provider.UnsupportedFunctionalityError({
|
|
129
|
-
functionality:
|
|
137
|
+
functionality: "PDF file parts with URLs"
|
|
130
138
|
});
|
|
131
139
|
}
|
|
140
|
+
return {
|
|
141
|
+
type: "file",
|
|
142
|
+
file: {
|
|
143
|
+
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
144
|
+
file_data: `data:application/pdf;base64,${part.data}`
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
} else {
|
|
148
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
149
|
+
functionality: `file part media type ${part.mediaType}`
|
|
150
|
+
});
|
|
132
151
|
}
|
|
133
152
|
}
|
|
134
153
|
}
|
|
@@ -158,41 +177,20 @@ function convertToOpenAIChatMessages({
|
|
|
158
177
|
}
|
|
159
178
|
}
|
|
160
179
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
messages.push({
|
|
168
|
-
role: "assistant",
|
|
169
|
-
content: text,
|
|
170
|
-
function_call: toolCalls.length > 0 ? toolCalls[0].function : void 0
|
|
171
|
-
});
|
|
172
|
-
} else {
|
|
173
|
-
messages.push({
|
|
174
|
-
role: "assistant",
|
|
175
|
-
content: text,
|
|
176
|
-
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
177
|
-
});
|
|
178
|
-
}
|
|
180
|
+
messages.push({
|
|
181
|
+
role: "assistant",
|
|
182
|
+
content: text,
|
|
183
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
184
|
+
});
|
|
179
185
|
break;
|
|
180
186
|
}
|
|
181
187
|
case "tool": {
|
|
182
188
|
for (const toolResponse of content) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
});
|
|
189
|
-
} else {
|
|
190
|
-
messages.push({
|
|
191
|
-
role: "tool",
|
|
192
|
-
tool_call_id: toolResponse.toolCallId,
|
|
193
|
-
content: JSON.stringify(toolResponse.result)
|
|
194
|
-
});
|
|
195
|
-
}
|
|
189
|
+
messages.push({
|
|
190
|
+
role: "tool",
|
|
191
|
+
tool_call_id: toolResponse.toolCallId,
|
|
192
|
+
content: JSON.stringify(toolResponse.result)
|
|
193
|
+
});
|
|
196
194
|
}
|
|
197
195
|
break;
|
|
198
196
|
}
|
|
@@ -205,6 +203,19 @@ function convertToOpenAIChatMessages({
|
|
|
205
203
|
return { messages, warnings };
|
|
206
204
|
}
|
|
207
205
|
|
|
206
|
+
// src/get-response-metadata.ts
|
|
207
|
+
function getResponseMetadata({
|
|
208
|
+
id,
|
|
209
|
+
model,
|
|
210
|
+
created
|
|
211
|
+
}) {
|
|
212
|
+
return {
|
|
213
|
+
id: id != null ? id : void 0,
|
|
214
|
+
modelId: model != null ? model : void 0,
|
|
215
|
+
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
208
219
|
// src/map-openai-chat-logprobs.ts
|
|
209
220
|
function mapOpenAIChatLogProbsOutput(logprobs) {
|
|
210
221
|
var _a, _b;
|
|
@@ -235,18 +246,69 @@ function mapOpenAIFinishReason(finishReason) {
|
|
|
235
246
|
}
|
|
236
247
|
}
|
|
237
248
|
|
|
238
|
-
// src/openai-
|
|
249
|
+
// src/openai-chat-options.ts
|
|
239
250
|
var import_zod = require("zod");
|
|
251
|
+
var openaiProviderOptions = import_zod.z.object({
|
|
252
|
+
/**
|
|
253
|
+
* Modify the likelihood of specified tokens appearing in the completion.
|
|
254
|
+
*
|
|
255
|
+
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
256
|
+
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
257
|
+
*/
|
|
258
|
+
logitBias: import_zod.z.record(import_zod.z.coerce.number(), import_zod.z.number()).optional(),
|
|
259
|
+
/**
|
|
260
|
+
* Return the log probabilities of the tokens.
|
|
261
|
+
*
|
|
262
|
+
* Setting to true will return the log probabilities of the tokens that
|
|
263
|
+
* were generated.
|
|
264
|
+
*
|
|
265
|
+
* Setting to a number will return the log probabilities of the top n
|
|
266
|
+
* tokens that were generated.
|
|
267
|
+
*/
|
|
268
|
+
logprobs: import_zod.z.union([import_zod.z.boolean(), import_zod.z.number()]).optional(),
|
|
269
|
+
/**
|
|
270
|
+
* Whether to enable parallel function calling during tool use. Default to true.
|
|
271
|
+
*/
|
|
272
|
+
parallelToolCalls: import_zod.z.boolean().optional(),
|
|
273
|
+
/**
|
|
274
|
+
* A unique identifier representing your end-user, which can help OpenAI to
|
|
275
|
+
* monitor and detect abuse.
|
|
276
|
+
*/
|
|
277
|
+
user: import_zod.z.string().optional(),
|
|
278
|
+
/**
|
|
279
|
+
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
280
|
+
*/
|
|
281
|
+
reasoningEffort: import_zod.z.enum(["low", "medium", "high"]).optional(),
|
|
282
|
+
/**
|
|
283
|
+
* Maximum number of completion tokens to generate. Useful for reasoning models.
|
|
284
|
+
*/
|
|
285
|
+
maxCompletionTokens: import_zod.z.number().optional(),
|
|
286
|
+
/**
|
|
287
|
+
* Whether to enable persistence in responses API.
|
|
288
|
+
*/
|
|
289
|
+
store: import_zod.z.boolean().optional(),
|
|
290
|
+
/**
|
|
291
|
+
* Metadata to associate with the request.
|
|
292
|
+
*/
|
|
293
|
+
metadata: import_zod.z.record(import_zod.z.string()).optional(),
|
|
294
|
+
/**
|
|
295
|
+
* Parameters for prediction mode.
|
|
296
|
+
*/
|
|
297
|
+
prediction: import_zod.z.record(import_zod.z.any()).optional()
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// src/openai-error.ts
|
|
301
|
+
var import_zod2 = require("zod");
|
|
240
302
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
241
|
-
var openaiErrorDataSchema =
|
|
242
|
-
error:
|
|
243
|
-
message:
|
|
303
|
+
var openaiErrorDataSchema = import_zod2.z.object({
|
|
304
|
+
error: import_zod2.z.object({
|
|
305
|
+
message: import_zod2.z.string(),
|
|
244
306
|
// The additional information below is handled loosely to support
|
|
245
307
|
// OpenAI-compatible providers that have slightly different error
|
|
246
308
|
// responses:
|
|
247
|
-
type:
|
|
248
|
-
param:
|
|
249
|
-
code:
|
|
309
|
+
type: import_zod2.z.string().nullish(),
|
|
310
|
+
param: import_zod2.z.any().nullish(),
|
|
311
|
+
code: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number()]).nullish()
|
|
250
312
|
})
|
|
251
313
|
});
|
|
252
314
|
var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
|
|
@@ -254,74 +316,17 @@ var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
|
|
|
254
316
|
errorToMessage: (data) => data.error.message
|
|
255
317
|
});
|
|
256
318
|
|
|
257
|
-
// src/get-response-metadata.ts
|
|
258
|
-
function getResponseMetadata({
|
|
259
|
-
id,
|
|
260
|
-
model,
|
|
261
|
-
created
|
|
262
|
-
}) {
|
|
263
|
-
return {
|
|
264
|
-
id: id != null ? id : void 0,
|
|
265
|
-
modelId: model != null ? model : void 0,
|
|
266
|
-
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
319
|
// src/openai-prepare-tools.ts
|
|
271
320
|
var import_provider2 = require("@ai-sdk/provider");
|
|
272
321
|
function prepareTools({
|
|
273
|
-
|
|
274
|
-
|
|
322
|
+
tools,
|
|
323
|
+
toolChoice,
|
|
275
324
|
structuredOutputs
|
|
276
325
|
}) {
|
|
277
|
-
|
|
278
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
326
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
279
327
|
const toolWarnings = [];
|
|
280
328
|
if (tools == null) {
|
|
281
|
-
return { tools: void 0,
|
|
282
|
-
}
|
|
283
|
-
const toolChoice = mode.toolChoice;
|
|
284
|
-
if (useLegacyFunctionCalling) {
|
|
285
|
-
const openaiFunctions = [];
|
|
286
|
-
for (const tool of tools) {
|
|
287
|
-
if (tool.type === "provider-defined") {
|
|
288
|
-
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
289
|
-
} else {
|
|
290
|
-
openaiFunctions.push({
|
|
291
|
-
name: tool.name,
|
|
292
|
-
description: tool.description,
|
|
293
|
-
parameters: tool.parameters
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (toolChoice == null) {
|
|
298
|
-
return {
|
|
299
|
-
functions: openaiFunctions,
|
|
300
|
-
function_call: void 0,
|
|
301
|
-
toolWarnings
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
const type2 = toolChoice.type;
|
|
305
|
-
switch (type2) {
|
|
306
|
-
case "auto":
|
|
307
|
-
case "none":
|
|
308
|
-
case void 0:
|
|
309
|
-
return {
|
|
310
|
-
functions: openaiFunctions,
|
|
311
|
-
function_call: void 0,
|
|
312
|
-
toolWarnings
|
|
313
|
-
};
|
|
314
|
-
case "required":
|
|
315
|
-
throw new import_provider2.UnsupportedFunctionalityError({
|
|
316
|
-
functionality: "useLegacyFunctionCalling and toolChoice: required"
|
|
317
|
-
});
|
|
318
|
-
default:
|
|
319
|
-
return {
|
|
320
|
-
functions: openaiFunctions,
|
|
321
|
-
function_call: { name: toolChoice.toolName },
|
|
322
|
-
toolWarnings
|
|
323
|
-
};
|
|
324
|
-
}
|
|
329
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
325
330
|
}
|
|
326
331
|
const openaiTools = [];
|
|
327
332
|
for (const tool of tools) {
|
|
@@ -340,18 +345,18 @@ function prepareTools({
|
|
|
340
345
|
}
|
|
341
346
|
}
|
|
342
347
|
if (toolChoice == null) {
|
|
343
|
-
return { tools: openaiTools,
|
|
348
|
+
return { tools: openaiTools, toolChoice: void 0, toolWarnings };
|
|
344
349
|
}
|
|
345
350
|
const type = toolChoice.type;
|
|
346
351
|
switch (type) {
|
|
347
352
|
case "auto":
|
|
348
353
|
case "none":
|
|
349
354
|
case "required":
|
|
350
|
-
return { tools: openaiTools,
|
|
355
|
+
return { tools: openaiTools, toolChoice: type, toolWarnings };
|
|
351
356
|
case "tool":
|
|
352
357
|
return {
|
|
353
358
|
tools: openaiTools,
|
|
354
|
-
|
|
359
|
+
toolChoice: {
|
|
355
360
|
type: "function",
|
|
356
361
|
function: {
|
|
357
362
|
name: toolChoice.toolName
|
|
@@ -362,7 +367,7 @@ function prepareTools({
|
|
|
362
367
|
default: {
|
|
363
368
|
const _exhaustiveCheck = type;
|
|
364
369
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
365
|
-
functionality: `
|
|
370
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
366
371
|
});
|
|
367
372
|
}
|
|
368
373
|
}
|
|
@@ -371,31 +376,22 @@ function prepareTools({
|
|
|
371
376
|
// src/openai-chat-language-model.ts
|
|
372
377
|
var OpenAIChatLanguageModel = class {
|
|
373
378
|
constructor(modelId, settings, config) {
|
|
374
|
-
this.specificationVersion = "
|
|
379
|
+
this.specificationVersion = "v2";
|
|
375
380
|
this.modelId = modelId;
|
|
376
381
|
this.settings = settings;
|
|
377
382
|
this.config = config;
|
|
378
383
|
}
|
|
379
|
-
get supportsStructuredOutputs() {
|
|
380
|
-
var _a;
|
|
381
|
-
return (_a = this.settings.structuredOutputs) != null ? _a : isReasoningModel(this.modelId);
|
|
382
|
-
}
|
|
383
|
-
get defaultObjectGenerationMode() {
|
|
384
|
-
if (isAudioModel(this.modelId)) {
|
|
385
|
-
return "tool";
|
|
386
|
-
}
|
|
387
|
-
return this.supportsStructuredOutputs ? "json" : "tool";
|
|
388
|
-
}
|
|
389
384
|
get provider() {
|
|
390
385
|
return this.config.provider;
|
|
391
386
|
}
|
|
392
|
-
|
|
393
|
-
return
|
|
387
|
+
async getSupportedUrls() {
|
|
388
|
+
return {
|
|
389
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
390
|
+
};
|
|
394
391
|
}
|
|
395
392
|
getArgs({
|
|
396
|
-
mode,
|
|
397
393
|
prompt,
|
|
398
|
-
|
|
394
|
+
maxOutputTokens,
|
|
399
395
|
temperature,
|
|
400
396
|
topP,
|
|
401
397
|
topK,
|
|
@@ -404,39 +400,33 @@ var OpenAIChatLanguageModel = class {
|
|
|
404
400
|
stopSequences,
|
|
405
401
|
responseFormat,
|
|
406
402
|
seed,
|
|
407
|
-
|
|
403
|
+
tools,
|
|
404
|
+
toolChoice,
|
|
405
|
+
providerOptions
|
|
408
406
|
}) {
|
|
409
|
-
var _a, _b, _c
|
|
410
|
-
const type = mode.type;
|
|
407
|
+
var _a, _b, _c;
|
|
411
408
|
const warnings = [];
|
|
409
|
+
const openaiOptions = (_a = (0, import_provider_utils3.parseProviderOptions)({
|
|
410
|
+
provider: "openai",
|
|
411
|
+
providerOptions,
|
|
412
|
+
schema: openaiProviderOptions
|
|
413
|
+
})) != null ? _a : {};
|
|
412
414
|
if (topK != null) {
|
|
413
415
|
warnings.push({
|
|
414
416
|
type: "unsupported-setting",
|
|
415
417
|
setting: "topK"
|
|
416
418
|
});
|
|
417
419
|
}
|
|
418
|
-
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.
|
|
420
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.settings.structuredOutputs) {
|
|
419
421
|
warnings.push({
|
|
420
422
|
type: "unsupported-setting",
|
|
421
423
|
setting: "responseFormat",
|
|
422
424
|
details: "JSON response format schema is only supported with structuredOutputs"
|
|
423
425
|
});
|
|
424
426
|
}
|
|
425
|
-
const useLegacyFunctionCalling = this.settings.useLegacyFunctionCalling;
|
|
426
|
-
if (useLegacyFunctionCalling && this.settings.parallelToolCalls === true) {
|
|
427
|
-
throw new import_provider3.UnsupportedFunctionalityError({
|
|
428
|
-
functionality: "useLegacyFunctionCalling with parallelToolCalls"
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
if (useLegacyFunctionCalling && this.supportsStructuredOutputs) {
|
|
432
|
-
throw new import_provider3.UnsupportedFunctionalityError({
|
|
433
|
-
functionality: "structuredOutputs with useLegacyFunctionCalling"
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
427
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
|
|
437
428
|
{
|
|
438
429
|
prompt,
|
|
439
|
-
useLegacyFunctionCalling,
|
|
440
430
|
systemMessageMode: getSystemMessageMode(this.modelId)
|
|
441
431
|
}
|
|
442
432
|
);
|
|
@@ -445,35 +435,38 @@ var OpenAIChatLanguageModel = class {
|
|
|
445
435
|
// model id:
|
|
446
436
|
model: this.modelId,
|
|
447
437
|
// model specific settings:
|
|
448
|
-
logit_bias:
|
|
449
|
-
logprobs:
|
|
450
|
-
top_logprobs: typeof
|
|
451
|
-
user:
|
|
452
|
-
parallel_tool_calls:
|
|
438
|
+
logit_bias: openaiOptions.logitBias,
|
|
439
|
+
logprobs: openaiOptions.logprobs === true || typeof openaiOptions.logprobs === "number" ? true : void 0,
|
|
440
|
+
top_logprobs: typeof openaiOptions.logprobs === "number" ? openaiOptions.logprobs : typeof openaiOptions.logprobs === "boolean" ? openaiOptions.logprobs ? 0 : void 0 : void 0,
|
|
441
|
+
user: openaiOptions.user,
|
|
442
|
+
parallel_tool_calls: openaiOptions.parallelToolCalls,
|
|
453
443
|
// standardized settings:
|
|
454
|
-
max_tokens:
|
|
444
|
+
max_tokens: maxOutputTokens,
|
|
455
445
|
temperature,
|
|
456
446
|
top_p: topP,
|
|
457
447
|
frequency_penalty: frequencyPenalty,
|
|
458
448
|
presence_penalty: presencePenalty,
|
|
459
|
-
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ?
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
449
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? (
|
|
450
|
+
// TODO convert into provider option
|
|
451
|
+
this.settings.structuredOutputs && responseFormat.schema != null ? {
|
|
452
|
+
type: "json_schema",
|
|
453
|
+
json_schema: {
|
|
454
|
+
schema: responseFormat.schema,
|
|
455
|
+
strict: true,
|
|
456
|
+
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
457
|
+
description: responseFormat.description
|
|
458
|
+
}
|
|
459
|
+
} : { type: "json_object" }
|
|
460
|
+
) : void 0,
|
|
468
461
|
stop: stopSequences,
|
|
469
462
|
seed,
|
|
470
463
|
// openai specific settings:
|
|
471
|
-
// TODO remove in next major version; we auto-map
|
|
472
|
-
max_completion_tokens:
|
|
473
|
-
store:
|
|
474
|
-
metadata:
|
|
475
|
-
prediction:
|
|
476
|
-
reasoning_effort:
|
|
464
|
+
// TODO remove in next major version; we auto-map maxOutputTokens now
|
|
465
|
+
max_completion_tokens: openaiOptions.maxCompletionTokens,
|
|
466
|
+
store: openaiOptions.store,
|
|
467
|
+
metadata: openaiOptions.metadata,
|
|
468
|
+
prediction: openaiOptions.prediction,
|
|
469
|
+
reasoning_effort: openaiOptions.reasoningEffort,
|
|
477
470
|
// messages:
|
|
478
471
|
messages
|
|
479
472
|
};
|
|
@@ -537,82 +530,33 @@ var OpenAIChatLanguageModel = class {
|
|
|
537
530
|
}
|
|
538
531
|
baseArgs.max_tokens = void 0;
|
|
539
532
|
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
533
|
+
} else if (this.modelId.startsWith("gpt-4o-search-preview") || this.modelId.startsWith("gpt-4o-mini-search-preview")) {
|
|
534
|
+
if (baseArgs.temperature != null) {
|
|
535
|
+
baseArgs.temperature = void 0;
|
|
536
|
+
warnings.push({
|
|
537
|
+
type: "unsupported-setting",
|
|
538
|
+
setting: "temperature",
|
|
539
|
+
details: "temperature is not supported for the search preview models and has been removed."
|
|
547
540
|
});
|
|
548
|
-
return {
|
|
549
|
-
args: {
|
|
550
|
-
...baseArgs,
|
|
551
|
-
tools,
|
|
552
|
-
tool_choice,
|
|
553
|
-
functions,
|
|
554
|
-
function_call
|
|
555
|
-
},
|
|
556
|
-
warnings: [...warnings, ...toolWarnings]
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
case "object-json": {
|
|
560
|
-
return {
|
|
561
|
-
args: {
|
|
562
|
-
...baseArgs,
|
|
563
|
-
response_format: this.supportsStructuredOutputs && mode.schema != null ? {
|
|
564
|
-
type: "json_schema",
|
|
565
|
-
json_schema: {
|
|
566
|
-
schema: mode.schema,
|
|
567
|
-
strict: true,
|
|
568
|
-
name: (_h = mode.name) != null ? _h : "response",
|
|
569
|
-
description: mode.description
|
|
570
|
-
}
|
|
571
|
-
} : { type: "json_object" }
|
|
572
|
-
},
|
|
573
|
-
warnings
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
case "object-tool": {
|
|
577
|
-
return {
|
|
578
|
-
args: useLegacyFunctionCalling ? {
|
|
579
|
-
...baseArgs,
|
|
580
|
-
function_call: {
|
|
581
|
-
name: mode.tool.name
|
|
582
|
-
},
|
|
583
|
-
functions: [
|
|
584
|
-
{
|
|
585
|
-
name: mode.tool.name,
|
|
586
|
-
description: mode.tool.description,
|
|
587
|
-
parameters: mode.tool.parameters
|
|
588
|
-
}
|
|
589
|
-
]
|
|
590
|
-
} : {
|
|
591
|
-
...baseArgs,
|
|
592
|
-
tool_choice: {
|
|
593
|
-
type: "function",
|
|
594
|
-
function: { name: mode.tool.name }
|
|
595
|
-
},
|
|
596
|
-
tools: [
|
|
597
|
-
{
|
|
598
|
-
type: "function",
|
|
599
|
-
function: {
|
|
600
|
-
name: mode.tool.name,
|
|
601
|
-
description: mode.tool.description,
|
|
602
|
-
parameters: mode.tool.parameters,
|
|
603
|
-
strict: this.supportsStructuredOutputs ? true : void 0
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
]
|
|
607
|
-
},
|
|
608
|
-
warnings
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
default: {
|
|
612
|
-
const _exhaustiveCheck = type;
|
|
613
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
614
541
|
}
|
|
615
542
|
}
|
|
543
|
+
const {
|
|
544
|
+
tools: openaiTools,
|
|
545
|
+
toolChoice: openaiToolChoice,
|
|
546
|
+
toolWarnings
|
|
547
|
+
} = prepareTools({
|
|
548
|
+
tools,
|
|
549
|
+
toolChoice,
|
|
550
|
+
structuredOutputs: (_c = this.settings.structuredOutputs) != null ? _c : false
|
|
551
|
+
});
|
|
552
|
+
return {
|
|
553
|
+
args: {
|
|
554
|
+
...baseArgs,
|
|
555
|
+
tools: openaiTools,
|
|
556
|
+
tool_choice: openaiToolChoice
|
|
557
|
+
},
|
|
558
|
+
warnings: [...warnings, ...toolWarnings]
|
|
559
|
+
};
|
|
616
560
|
}
|
|
617
561
|
async doGenerate(options) {
|
|
618
562
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -635,10 +579,23 @@ var OpenAIChatLanguageModel = class {
|
|
|
635
579
|
abortSignal: options.abortSignal,
|
|
636
580
|
fetch: this.config.fetch
|
|
637
581
|
});
|
|
638
|
-
const { messages: rawPrompt, ...rawSettings } = body;
|
|
639
582
|
const choice = response.choices[0];
|
|
640
|
-
const
|
|
641
|
-
const
|
|
583
|
+
const content = [];
|
|
584
|
+
const text = choice.message.content;
|
|
585
|
+
if (text != null && text.length > 0) {
|
|
586
|
+
content.push({ type: "text", text });
|
|
587
|
+
}
|
|
588
|
+
for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
|
|
589
|
+
content.push({
|
|
590
|
+
type: "tool-call",
|
|
591
|
+
toolCallType: "function",
|
|
592
|
+
toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils3.generateId)(),
|
|
593
|
+
toolName: toolCall.function.name,
|
|
594
|
+
args: toolCall.function.arguments
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
const completionTokenDetails = (_c = response.usage) == null ? void 0 : _c.completion_tokens_details;
|
|
598
|
+
const promptTokenDetails = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details;
|
|
642
599
|
const providerMetadata = { openai: {} };
|
|
643
600
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null) {
|
|
644
601
|
providerMetadata.openai.reasoningTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens;
|
|
@@ -653,81 +610,24 @@ var OpenAIChatLanguageModel = class {
|
|
|
653
610
|
providerMetadata.openai.cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
|
|
654
611
|
}
|
|
655
612
|
return {
|
|
656
|
-
|
|
657
|
-
toolCalls: this.settings.useLegacyFunctionCalling && choice.message.function_call ? [
|
|
658
|
-
{
|
|
659
|
-
toolCallType: "function",
|
|
660
|
-
toolCallId: (0, import_provider_utils3.generateId)(),
|
|
661
|
-
toolName: choice.message.function_call.name,
|
|
662
|
-
args: choice.message.function_call.arguments
|
|
663
|
-
}
|
|
664
|
-
] : (_d = choice.message.tool_calls) == null ? void 0 : _d.map((toolCall) => {
|
|
665
|
-
var _a2;
|
|
666
|
-
return {
|
|
667
|
-
toolCallType: "function",
|
|
668
|
-
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils3.generateId)(),
|
|
669
|
-
toolName: toolCall.function.name,
|
|
670
|
-
args: toolCall.function.arguments
|
|
671
|
-
};
|
|
672
|
-
}),
|
|
613
|
+
content,
|
|
673
614
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
674
615
|
usage: {
|
|
675
|
-
|
|
676
|
-
|
|
616
|
+
inputTokens: (_f = (_e = response.usage) == null ? void 0 : _e.prompt_tokens) != null ? _f : void 0,
|
|
617
|
+
outputTokens: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0
|
|
618
|
+
},
|
|
619
|
+
request: { body },
|
|
620
|
+
response: {
|
|
621
|
+
...getResponseMetadata(response),
|
|
622
|
+
headers: responseHeaders,
|
|
623
|
+
body: rawResponse
|
|
677
624
|
},
|
|
678
|
-
rawCall: { rawPrompt, rawSettings },
|
|
679
|
-
rawResponse: { headers: responseHeaders, body: rawResponse },
|
|
680
|
-
request: { body: JSON.stringify(body) },
|
|
681
|
-
response: getResponseMetadata(response),
|
|
682
625
|
warnings,
|
|
683
626
|
logprobs: mapOpenAIChatLogProbsOutput(choice.logprobs),
|
|
684
627
|
providerMetadata
|
|
685
628
|
};
|
|
686
629
|
}
|
|
687
630
|
async doStream(options) {
|
|
688
|
-
if (this.settings.simulateStreaming) {
|
|
689
|
-
const result = await this.doGenerate(options);
|
|
690
|
-
const simulatedStream = new ReadableStream({
|
|
691
|
-
start(controller) {
|
|
692
|
-
controller.enqueue({ type: "response-metadata", ...result.response });
|
|
693
|
-
if (result.text) {
|
|
694
|
-
controller.enqueue({
|
|
695
|
-
type: "text-delta",
|
|
696
|
-
textDelta: result.text
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
if (result.toolCalls) {
|
|
700
|
-
for (const toolCall of result.toolCalls) {
|
|
701
|
-
controller.enqueue({
|
|
702
|
-
type: "tool-call-delta",
|
|
703
|
-
toolCallType: "function",
|
|
704
|
-
toolCallId: toolCall.toolCallId,
|
|
705
|
-
toolName: toolCall.toolName,
|
|
706
|
-
argsTextDelta: toolCall.args
|
|
707
|
-
});
|
|
708
|
-
controller.enqueue({
|
|
709
|
-
type: "tool-call",
|
|
710
|
-
...toolCall
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
controller.enqueue({
|
|
715
|
-
type: "finish",
|
|
716
|
-
finishReason: result.finishReason,
|
|
717
|
-
usage: result.usage,
|
|
718
|
-
logprobs: result.logprobs,
|
|
719
|
-
providerMetadata: result.providerMetadata
|
|
720
|
-
});
|
|
721
|
-
controller.close();
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
return {
|
|
725
|
-
stream: simulatedStream,
|
|
726
|
-
rawCall: result.rawCall,
|
|
727
|
-
rawResponse: result.rawResponse,
|
|
728
|
-
warnings: result.warnings
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
631
|
const { args, warnings } = this.getArgs(options);
|
|
732
632
|
const body = {
|
|
733
633
|
...args,
|
|
@@ -752,17 +652,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
752
652
|
const { messages: rawPrompt, ...rawSettings } = args;
|
|
753
653
|
const toolCalls = [];
|
|
754
654
|
let finishReason = "unknown";
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
655
|
+
const usage = {
|
|
656
|
+
inputTokens: void 0,
|
|
657
|
+
outputTokens: void 0
|
|
758
658
|
};
|
|
759
659
|
let logprobs;
|
|
760
660
|
let isFirstChunk = true;
|
|
761
|
-
const { useLegacyFunctionCalling } = this.settings;
|
|
762
661
|
const providerMetadata = { openai: {} };
|
|
763
662
|
return {
|
|
764
663
|
stream: response.pipeThrough(
|
|
765
664
|
new TransformStream({
|
|
665
|
+
start(controller) {
|
|
666
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
667
|
+
},
|
|
766
668
|
transform(chunk, controller) {
|
|
767
669
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
768
670
|
if (!chunk.success) {
|
|
@@ -790,10 +692,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
790
692
|
prompt_tokens_details,
|
|
791
693
|
completion_tokens_details
|
|
792
694
|
} = value.usage;
|
|
793
|
-
usage =
|
|
794
|
-
|
|
795
|
-
completionTokens: completion_tokens != null ? completion_tokens : void 0
|
|
796
|
-
};
|
|
695
|
+
usage.inputTokens = prompt_tokens != null ? prompt_tokens : void 0;
|
|
696
|
+
usage.outputTokens = completion_tokens != null ? completion_tokens : void 0;
|
|
797
697
|
if ((completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens) != null) {
|
|
798
698
|
providerMetadata.openai.reasoningTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens;
|
|
799
699
|
}
|
|
@@ -817,8 +717,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
817
717
|
const delta = choice.delta;
|
|
818
718
|
if (delta.content != null) {
|
|
819
719
|
controller.enqueue({
|
|
820
|
-
type: "text
|
|
821
|
-
|
|
720
|
+
type: "text",
|
|
721
|
+
text: delta.content
|
|
822
722
|
});
|
|
823
723
|
}
|
|
824
724
|
const mappedLogprobs = mapOpenAIChatLogProbsOutput(
|
|
@@ -828,16 +728,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
828
728
|
if (logprobs === void 0) logprobs = [];
|
|
829
729
|
logprobs.push(...mappedLogprobs);
|
|
830
730
|
}
|
|
831
|
-
|
|
832
|
-
{
|
|
833
|
-
type: "function",
|
|
834
|
-
id: (0, import_provider_utils3.generateId)(),
|
|
835
|
-
function: delta.function_call,
|
|
836
|
-
index: 0
|
|
837
|
-
}
|
|
838
|
-
] : delta.tool_calls;
|
|
839
|
-
if (mappedToolCalls != null) {
|
|
840
|
-
for (const toolCallDelta of mappedToolCalls) {
|
|
731
|
+
if (delta.tool_calls != null) {
|
|
732
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
841
733
|
const index = toolCallDelta.index;
|
|
842
734
|
if (toolCalls[index] == null) {
|
|
843
735
|
if (toolCallDelta.type !== "function") {
|
|
@@ -919,125 +811,111 @@ var OpenAIChatLanguageModel = class {
|
|
|
919
811
|
}
|
|
920
812
|
},
|
|
921
813
|
flush(controller) {
|
|
922
|
-
var _a, _b;
|
|
923
814
|
controller.enqueue({
|
|
924
815
|
type: "finish",
|
|
925
816
|
finishReason,
|
|
926
817
|
logprobs,
|
|
927
|
-
usage
|
|
928
|
-
promptTokens: (_a = usage.promptTokens) != null ? _a : NaN,
|
|
929
|
-
completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
|
|
930
|
-
},
|
|
818
|
+
usage,
|
|
931
819
|
...providerMetadata != null ? { providerMetadata } : {}
|
|
932
820
|
});
|
|
933
821
|
}
|
|
934
822
|
})
|
|
935
823
|
),
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
request: { body: JSON.stringify(body) },
|
|
939
|
-
warnings
|
|
824
|
+
request: { body },
|
|
825
|
+
response: { headers: responseHeaders }
|
|
940
826
|
};
|
|
941
827
|
}
|
|
942
828
|
};
|
|
943
|
-
var openaiTokenUsageSchema =
|
|
944
|
-
prompt_tokens:
|
|
945
|
-
completion_tokens:
|
|
946
|
-
prompt_tokens_details:
|
|
947
|
-
cached_tokens:
|
|
829
|
+
var openaiTokenUsageSchema = import_zod3.z.object({
|
|
830
|
+
prompt_tokens: import_zod3.z.number().nullish(),
|
|
831
|
+
completion_tokens: import_zod3.z.number().nullish(),
|
|
832
|
+
prompt_tokens_details: import_zod3.z.object({
|
|
833
|
+
cached_tokens: import_zod3.z.number().nullish()
|
|
948
834
|
}).nullish(),
|
|
949
|
-
completion_tokens_details:
|
|
950
|
-
reasoning_tokens:
|
|
951
|
-
accepted_prediction_tokens:
|
|
952
|
-
rejected_prediction_tokens:
|
|
835
|
+
completion_tokens_details: import_zod3.z.object({
|
|
836
|
+
reasoning_tokens: import_zod3.z.number().nullish(),
|
|
837
|
+
accepted_prediction_tokens: import_zod3.z.number().nullish(),
|
|
838
|
+
rejected_prediction_tokens: import_zod3.z.number().nullish()
|
|
953
839
|
}).nullish()
|
|
954
840
|
}).nullish();
|
|
955
|
-
var openaiChatResponseSchema =
|
|
956
|
-
id:
|
|
957
|
-
created:
|
|
958
|
-
model:
|
|
959
|
-
choices:
|
|
960
|
-
|
|
961
|
-
message:
|
|
962
|
-
role:
|
|
963
|
-
content:
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
type: import_zod2.z.literal("function"),
|
|
972
|
-
function: import_zod2.z.object({
|
|
973
|
-
name: import_zod2.z.string(),
|
|
974
|
-
arguments: import_zod2.z.string()
|
|
841
|
+
var openaiChatResponseSchema = import_zod3.z.object({
|
|
842
|
+
id: import_zod3.z.string().nullish(),
|
|
843
|
+
created: import_zod3.z.number().nullish(),
|
|
844
|
+
model: import_zod3.z.string().nullish(),
|
|
845
|
+
choices: import_zod3.z.array(
|
|
846
|
+
import_zod3.z.object({
|
|
847
|
+
message: import_zod3.z.object({
|
|
848
|
+
role: import_zod3.z.literal("assistant").nullish(),
|
|
849
|
+
content: import_zod3.z.string().nullish(),
|
|
850
|
+
tool_calls: import_zod3.z.array(
|
|
851
|
+
import_zod3.z.object({
|
|
852
|
+
id: import_zod3.z.string().nullish(),
|
|
853
|
+
type: import_zod3.z.literal("function"),
|
|
854
|
+
function: import_zod3.z.object({
|
|
855
|
+
name: import_zod3.z.string(),
|
|
856
|
+
arguments: import_zod3.z.string()
|
|
975
857
|
})
|
|
976
858
|
})
|
|
977
859
|
).nullish()
|
|
978
860
|
}),
|
|
979
|
-
index:
|
|
980
|
-
logprobs:
|
|
981
|
-
content:
|
|
982
|
-
|
|
983
|
-
token:
|
|
984
|
-
logprob:
|
|
985
|
-
top_logprobs:
|
|
986
|
-
|
|
987
|
-
token:
|
|
988
|
-
logprob:
|
|
861
|
+
index: import_zod3.z.number(),
|
|
862
|
+
logprobs: import_zod3.z.object({
|
|
863
|
+
content: import_zod3.z.array(
|
|
864
|
+
import_zod3.z.object({
|
|
865
|
+
token: import_zod3.z.string(),
|
|
866
|
+
logprob: import_zod3.z.number(),
|
|
867
|
+
top_logprobs: import_zod3.z.array(
|
|
868
|
+
import_zod3.z.object({
|
|
869
|
+
token: import_zod3.z.string(),
|
|
870
|
+
logprob: import_zod3.z.number()
|
|
989
871
|
})
|
|
990
872
|
)
|
|
991
873
|
})
|
|
992
874
|
).nullable()
|
|
993
875
|
}).nullish(),
|
|
994
|
-
finish_reason:
|
|
876
|
+
finish_reason: import_zod3.z.string().nullish()
|
|
995
877
|
})
|
|
996
878
|
),
|
|
997
879
|
usage: openaiTokenUsageSchema
|
|
998
880
|
});
|
|
999
|
-
var openaiChatChunkSchema =
|
|
1000
|
-
|
|
1001
|
-
id:
|
|
1002
|
-
created:
|
|
1003
|
-
model:
|
|
1004
|
-
choices:
|
|
1005
|
-
|
|
1006
|
-
delta:
|
|
1007
|
-
role:
|
|
1008
|
-
content:
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
type: import_zod2.z.literal("function").optional(),
|
|
1018
|
-
function: import_zod2.z.object({
|
|
1019
|
-
name: import_zod2.z.string().nullish(),
|
|
1020
|
-
arguments: import_zod2.z.string().nullish()
|
|
881
|
+
var openaiChatChunkSchema = import_zod3.z.union([
|
|
882
|
+
import_zod3.z.object({
|
|
883
|
+
id: import_zod3.z.string().nullish(),
|
|
884
|
+
created: import_zod3.z.number().nullish(),
|
|
885
|
+
model: import_zod3.z.string().nullish(),
|
|
886
|
+
choices: import_zod3.z.array(
|
|
887
|
+
import_zod3.z.object({
|
|
888
|
+
delta: import_zod3.z.object({
|
|
889
|
+
role: import_zod3.z.enum(["assistant"]).nullish(),
|
|
890
|
+
content: import_zod3.z.string().nullish(),
|
|
891
|
+
tool_calls: import_zod3.z.array(
|
|
892
|
+
import_zod3.z.object({
|
|
893
|
+
index: import_zod3.z.number(),
|
|
894
|
+
id: import_zod3.z.string().nullish(),
|
|
895
|
+
type: import_zod3.z.literal("function").optional(),
|
|
896
|
+
function: import_zod3.z.object({
|
|
897
|
+
name: import_zod3.z.string().nullish(),
|
|
898
|
+
arguments: import_zod3.z.string().nullish()
|
|
1021
899
|
})
|
|
1022
900
|
})
|
|
1023
901
|
).nullish()
|
|
1024
902
|
}).nullish(),
|
|
1025
|
-
logprobs:
|
|
1026
|
-
content:
|
|
1027
|
-
|
|
1028
|
-
token:
|
|
1029
|
-
logprob:
|
|
1030
|
-
top_logprobs:
|
|
1031
|
-
|
|
1032
|
-
token:
|
|
1033
|
-
logprob:
|
|
903
|
+
logprobs: import_zod3.z.object({
|
|
904
|
+
content: import_zod3.z.array(
|
|
905
|
+
import_zod3.z.object({
|
|
906
|
+
token: import_zod3.z.string(),
|
|
907
|
+
logprob: import_zod3.z.number(),
|
|
908
|
+
top_logprobs: import_zod3.z.array(
|
|
909
|
+
import_zod3.z.object({
|
|
910
|
+
token: import_zod3.z.string(),
|
|
911
|
+
logprob: import_zod3.z.number()
|
|
1034
912
|
})
|
|
1035
913
|
)
|
|
1036
914
|
})
|
|
1037
915
|
).nullable()
|
|
1038
916
|
}).nullish(),
|
|
1039
|
-
finish_reason:
|
|
1040
|
-
index:
|
|
917
|
+
finish_reason: import_zod3.z.string().nullable().optional(),
|
|
918
|
+
index: import_zod3.z.number()
|
|
1041
919
|
})
|
|
1042
920
|
),
|
|
1043
921
|
usage: openaiTokenUsageSchema
|
|
@@ -1045,10 +923,7 @@ var openaiChatChunkSchema = import_zod2.z.union([
|
|
|
1045
923
|
openaiErrorDataSchema
|
|
1046
924
|
]);
|
|
1047
925
|
function isReasoningModel(modelId) {
|
|
1048
|
-
return modelId
|
|
1049
|
-
}
|
|
1050
|
-
function isAudioModel(modelId) {
|
|
1051
|
-
return modelId.startsWith("gpt-4o-audio-preview");
|
|
926
|
+
return modelId.startsWith("o");
|
|
1052
927
|
}
|
|
1053
928
|
function getSystemMessageMode(modelId) {
|
|
1054
929
|
var _a, _b;
|
|
@@ -1079,9 +954,8 @@ var reasoningModels = {
|
|
|
1079
954
|
};
|
|
1080
955
|
|
|
1081
956
|
// src/openai-completion-language-model.ts
|
|
1082
|
-
var import_provider5 = require("@ai-sdk/provider");
|
|
1083
957
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1084
|
-
var
|
|
958
|
+
var import_zod4 = require("zod");
|
|
1085
959
|
|
|
1086
960
|
// src/convert-to-openai-completion-prompt.ts
|
|
1087
961
|
var import_provider4 = require("@ai-sdk/provider");
|
|
@@ -1115,13 +989,8 @@ function convertToOpenAICompletionPrompt({
|
|
|
1115
989
|
case "text": {
|
|
1116
990
|
return part.text;
|
|
1117
991
|
}
|
|
1118
|
-
case "image": {
|
|
1119
|
-
throw new import_provider4.UnsupportedFunctionalityError({
|
|
1120
|
-
functionality: "images"
|
|
1121
|
-
});
|
|
1122
|
-
}
|
|
1123
992
|
}
|
|
1124
|
-
}).join("");
|
|
993
|
+
}).filter(Boolean).join("");
|
|
1125
994
|
text += `${user}:
|
|
1126
995
|
${userMessage}
|
|
1127
996
|
|
|
@@ -1184,8 +1053,7 @@ function mapOpenAICompletionLogProbs(logprobs) {
|
|
|
1184
1053
|
// src/openai-completion-language-model.ts
|
|
1185
1054
|
var OpenAICompletionLanguageModel = class {
|
|
1186
1055
|
constructor(modelId, settings, config) {
|
|
1187
|
-
this.specificationVersion = "
|
|
1188
|
-
this.defaultObjectGenerationMode = void 0;
|
|
1056
|
+
this.specificationVersion = "v2";
|
|
1189
1057
|
this.modelId = modelId;
|
|
1190
1058
|
this.settings = settings;
|
|
1191
1059
|
this.config = config;
|
|
@@ -1193,11 +1061,15 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1193
1061
|
get provider() {
|
|
1194
1062
|
return this.config.provider;
|
|
1195
1063
|
}
|
|
1064
|
+
async getSupportedUrls() {
|
|
1065
|
+
return {
|
|
1066
|
+
// no supported urls for completion models
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1196
1069
|
getArgs({
|
|
1197
|
-
mode,
|
|
1198
1070
|
inputFormat,
|
|
1199
1071
|
prompt,
|
|
1200
|
-
|
|
1072
|
+
maxOutputTokens,
|
|
1201
1073
|
temperature,
|
|
1202
1074
|
topP,
|
|
1203
1075
|
topK,
|
|
@@ -1205,16 +1077,19 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1205
1077
|
presencePenalty,
|
|
1206
1078
|
stopSequences: userStopSequences,
|
|
1207
1079
|
responseFormat,
|
|
1080
|
+
tools,
|
|
1081
|
+
toolChoice,
|
|
1208
1082
|
seed
|
|
1209
1083
|
}) {
|
|
1210
|
-
var _a;
|
|
1211
|
-
const type = mode.type;
|
|
1212
1084
|
const warnings = [];
|
|
1213
1085
|
if (topK != null) {
|
|
1214
|
-
warnings.push({
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
});
|
|
1086
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1087
|
+
}
|
|
1088
|
+
if (tools == null ? void 0 : tools.length) {
|
|
1089
|
+
warnings.push({ type: "unsupported-setting", setting: "tools" });
|
|
1090
|
+
}
|
|
1091
|
+
if (toolChoice != null) {
|
|
1092
|
+
warnings.push({ type: "unsupported-setting", setting: "toolChoice" });
|
|
1218
1093
|
}
|
|
1219
1094
|
if (responseFormat != null && responseFormat.type !== "text") {
|
|
1220
1095
|
warnings.push({
|
|
@@ -1225,56 +1100,30 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1225
1100
|
}
|
|
1226
1101
|
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
|
|
1227
1102
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1103
|
+
return {
|
|
1104
|
+
args: {
|
|
1105
|
+
// model id:
|
|
1106
|
+
model: this.modelId,
|
|
1107
|
+
// model specific settings:
|
|
1108
|
+
echo: this.settings.echo,
|
|
1109
|
+
logit_bias: this.settings.logitBias,
|
|
1110
|
+
logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
|
|
1111
|
+
suffix: this.settings.suffix,
|
|
1112
|
+
user: this.settings.user,
|
|
1113
|
+
// standardized settings:
|
|
1114
|
+
max_tokens: maxOutputTokens,
|
|
1115
|
+
temperature,
|
|
1116
|
+
top_p: topP,
|
|
1117
|
+
frequency_penalty: frequencyPenalty,
|
|
1118
|
+
presence_penalty: presencePenalty,
|
|
1119
|
+
seed,
|
|
1120
|
+
// prompt:
|
|
1121
|
+
prompt: completionPrompt,
|
|
1122
|
+
// stop sequences:
|
|
1123
|
+
stop: stop.length > 0 ? stop : void 0
|
|
1124
|
+
},
|
|
1125
|
+
warnings
|
|
1248
1126
|
};
|
|
1249
|
-
switch (type) {
|
|
1250
|
-
case "regular": {
|
|
1251
|
-
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
|
1252
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1253
|
-
functionality: "tools"
|
|
1254
|
-
});
|
|
1255
|
-
}
|
|
1256
|
-
if (mode.toolChoice) {
|
|
1257
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1258
|
-
functionality: "toolChoice"
|
|
1259
|
-
});
|
|
1260
|
-
}
|
|
1261
|
-
return { args: baseArgs, warnings };
|
|
1262
|
-
}
|
|
1263
|
-
case "object-json": {
|
|
1264
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1265
|
-
functionality: "object-json mode"
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
case "object-tool": {
|
|
1269
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1270
|
-
functionality: "object-tool mode"
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
default: {
|
|
1274
|
-
const _exhaustiveCheck = type;
|
|
1275
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
1127
|
}
|
|
1279
1128
|
async doGenerate(options) {
|
|
1280
1129
|
const { args, warnings } = this.getArgs(options);
|
|
@@ -1296,21 +1145,22 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1296
1145
|
abortSignal: options.abortSignal,
|
|
1297
1146
|
fetch: this.config.fetch
|
|
1298
1147
|
});
|
|
1299
|
-
const { prompt: rawPrompt, ...rawSettings } = args;
|
|
1300
1148
|
const choice = response.choices[0];
|
|
1301
1149
|
return {
|
|
1302
|
-
text: choice.text,
|
|
1150
|
+
content: [{ type: "text", text: choice.text }],
|
|
1303
1151
|
usage: {
|
|
1304
|
-
|
|
1305
|
-
|
|
1152
|
+
inputTokens: response.usage.prompt_tokens,
|
|
1153
|
+
outputTokens: response.usage.completion_tokens
|
|
1306
1154
|
},
|
|
1307
1155
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
1308
1156
|
logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1157
|
+
request: { body: args },
|
|
1158
|
+
response: {
|
|
1159
|
+
...getResponseMetadata(response),
|
|
1160
|
+
headers: responseHeaders,
|
|
1161
|
+
body: rawResponse
|
|
1162
|
+
},
|
|
1163
|
+
warnings
|
|
1314
1164
|
};
|
|
1315
1165
|
}
|
|
1316
1166
|
async doStream(options) {
|
|
@@ -1335,17 +1185,19 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1335
1185
|
abortSignal: options.abortSignal,
|
|
1336
1186
|
fetch: this.config.fetch
|
|
1337
1187
|
});
|
|
1338
|
-
const { prompt: rawPrompt, ...rawSettings } = args;
|
|
1339
1188
|
let finishReason = "unknown";
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1189
|
+
const usage = {
|
|
1190
|
+
inputTokens: void 0,
|
|
1191
|
+
outputTokens: void 0
|
|
1343
1192
|
};
|
|
1344
1193
|
let logprobs;
|
|
1345
1194
|
let isFirstChunk = true;
|
|
1346
1195
|
return {
|
|
1347
1196
|
stream: response.pipeThrough(
|
|
1348
1197
|
new TransformStream({
|
|
1198
|
+
start(controller) {
|
|
1199
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
1200
|
+
},
|
|
1349
1201
|
transform(chunk, controller) {
|
|
1350
1202
|
if (!chunk.success) {
|
|
1351
1203
|
finishReason = "error";
|
|
@@ -1366,10 +1218,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1366
1218
|
});
|
|
1367
1219
|
}
|
|
1368
1220
|
if (value.usage != null) {
|
|
1369
|
-
usage =
|
|
1370
|
-
|
|
1371
|
-
completionTokens: value.usage.completion_tokens
|
|
1372
|
-
};
|
|
1221
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
1222
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
1373
1223
|
}
|
|
1374
1224
|
const choice = value.choices[0];
|
|
1375
1225
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
@@ -1377,8 +1227,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1377
1227
|
}
|
|
1378
1228
|
if ((choice == null ? void 0 : choice.text) != null) {
|
|
1379
1229
|
controller.enqueue({
|
|
1380
|
-
type: "text
|
|
1381
|
-
|
|
1230
|
+
type: "text",
|
|
1231
|
+
text: choice.text
|
|
1382
1232
|
});
|
|
1383
1233
|
}
|
|
1384
1234
|
const mappedLogprobs = mapOpenAICompletionLogProbs(
|
|
@@ -1399,65 +1249,80 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1399
1249
|
}
|
|
1400
1250
|
})
|
|
1401
1251
|
),
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
warnings,
|
|
1405
|
-
request: { body: JSON.stringify(body) }
|
|
1252
|
+
request: { body },
|
|
1253
|
+
response: { headers: responseHeaders }
|
|
1406
1254
|
};
|
|
1407
1255
|
}
|
|
1408
1256
|
};
|
|
1409
|
-
var openaiCompletionResponseSchema =
|
|
1410
|
-
id:
|
|
1411
|
-
created:
|
|
1412
|
-
model:
|
|
1413
|
-
choices:
|
|
1414
|
-
|
|
1415
|
-
text:
|
|
1416
|
-
finish_reason:
|
|
1417
|
-
logprobs:
|
|
1418
|
-
tokens:
|
|
1419
|
-
token_logprobs:
|
|
1420
|
-
top_logprobs:
|
|
1257
|
+
var openaiCompletionResponseSchema = import_zod4.z.object({
|
|
1258
|
+
id: import_zod4.z.string().nullish(),
|
|
1259
|
+
created: import_zod4.z.number().nullish(),
|
|
1260
|
+
model: import_zod4.z.string().nullish(),
|
|
1261
|
+
choices: import_zod4.z.array(
|
|
1262
|
+
import_zod4.z.object({
|
|
1263
|
+
text: import_zod4.z.string(),
|
|
1264
|
+
finish_reason: import_zod4.z.string(),
|
|
1265
|
+
logprobs: import_zod4.z.object({
|
|
1266
|
+
tokens: import_zod4.z.array(import_zod4.z.string()),
|
|
1267
|
+
token_logprobs: import_zod4.z.array(import_zod4.z.number()),
|
|
1268
|
+
top_logprobs: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number())).nullable()
|
|
1421
1269
|
}).nullish()
|
|
1422
1270
|
})
|
|
1423
1271
|
),
|
|
1424
|
-
usage:
|
|
1425
|
-
prompt_tokens:
|
|
1426
|
-
completion_tokens:
|
|
1272
|
+
usage: import_zod4.z.object({
|
|
1273
|
+
prompt_tokens: import_zod4.z.number(),
|
|
1274
|
+
completion_tokens: import_zod4.z.number()
|
|
1427
1275
|
})
|
|
1428
1276
|
});
|
|
1429
|
-
var openaiCompletionChunkSchema =
|
|
1430
|
-
|
|
1431
|
-
id:
|
|
1432
|
-
created:
|
|
1433
|
-
model:
|
|
1434
|
-
choices:
|
|
1435
|
-
|
|
1436
|
-
text:
|
|
1437
|
-
finish_reason:
|
|
1438
|
-
index:
|
|
1439
|
-
logprobs:
|
|
1440
|
-
tokens:
|
|
1441
|
-
token_logprobs:
|
|
1442
|
-
top_logprobs:
|
|
1277
|
+
var openaiCompletionChunkSchema = import_zod4.z.union([
|
|
1278
|
+
import_zod4.z.object({
|
|
1279
|
+
id: import_zod4.z.string().nullish(),
|
|
1280
|
+
created: import_zod4.z.number().nullish(),
|
|
1281
|
+
model: import_zod4.z.string().nullish(),
|
|
1282
|
+
choices: import_zod4.z.array(
|
|
1283
|
+
import_zod4.z.object({
|
|
1284
|
+
text: import_zod4.z.string(),
|
|
1285
|
+
finish_reason: import_zod4.z.string().nullish(),
|
|
1286
|
+
index: import_zod4.z.number(),
|
|
1287
|
+
logprobs: import_zod4.z.object({
|
|
1288
|
+
tokens: import_zod4.z.array(import_zod4.z.string()),
|
|
1289
|
+
token_logprobs: import_zod4.z.array(import_zod4.z.number()),
|
|
1290
|
+
top_logprobs: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number())).nullable()
|
|
1443
1291
|
}).nullish()
|
|
1444
1292
|
})
|
|
1445
1293
|
),
|
|
1446
|
-
usage:
|
|
1447
|
-
prompt_tokens:
|
|
1448
|
-
completion_tokens:
|
|
1294
|
+
usage: import_zod4.z.object({
|
|
1295
|
+
prompt_tokens: import_zod4.z.number(),
|
|
1296
|
+
completion_tokens: import_zod4.z.number()
|
|
1449
1297
|
}).nullish()
|
|
1450
1298
|
}),
|
|
1451
1299
|
openaiErrorDataSchema
|
|
1452
1300
|
]);
|
|
1453
1301
|
|
|
1454
1302
|
// src/openai-embedding-model.ts
|
|
1455
|
-
var
|
|
1303
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
1456
1304
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
1457
|
-
var
|
|
1305
|
+
var import_zod6 = require("zod");
|
|
1306
|
+
|
|
1307
|
+
// src/openai-embedding-options.ts
|
|
1308
|
+
var import_zod5 = require("zod");
|
|
1309
|
+
var openaiEmbeddingProviderOptions = import_zod5.z.object({
|
|
1310
|
+
/**
|
|
1311
|
+
The number of dimensions the resulting output embeddings should have.
|
|
1312
|
+
Only supported in text-embedding-3 and later models.
|
|
1313
|
+
*/
|
|
1314
|
+
dimensions: import_zod5.z.number().optional(),
|
|
1315
|
+
/**
|
|
1316
|
+
A unique identifier representing your end-user, which can help OpenAI to
|
|
1317
|
+
monitor and detect abuse. Learn more.
|
|
1318
|
+
*/
|
|
1319
|
+
user: import_zod5.z.string().optional()
|
|
1320
|
+
});
|
|
1321
|
+
|
|
1322
|
+
// src/openai-embedding-model.ts
|
|
1458
1323
|
var OpenAIEmbeddingModel = class {
|
|
1459
1324
|
constructor(modelId, settings, config) {
|
|
1460
|
-
this.specificationVersion = "
|
|
1325
|
+
this.specificationVersion = "v2";
|
|
1461
1326
|
this.modelId = modelId;
|
|
1462
1327
|
this.settings = settings;
|
|
1463
1328
|
this.config = config;
|
|
@@ -1476,17 +1341,28 @@ var OpenAIEmbeddingModel = class {
|
|
|
1476
1341
|
async doEmbed({
|
|
1477
1342
|
values,
|
|
1478
1343
|
headers,
|
|
1479
|
-
abortSignal
|
|
1344
|
+
abortSignal,
|
|
1345
|
+
providerOptions
|
|
1480
1346
|
}) {
|
|
1347
|
+
var _a;
|
|
1481
1348
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1482
|
-
throw new
|
|
1349
|
+
throw new import_provider5.TooManyEmbeddingValuesForCallError({
|
|
1483
1350
|
provider: this.provider,
|
|
1484
1351
|
modelId: this.modelId,
|
|
1485
1352
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
1486
1353
|
values
|
|
1487
1354
|
});
|
|
1488
1355
|
}
|
|
1489
|
-
const
|
|
1356
|
+
const openaiOptions = (_a = (0, import_provider_utils5.parseProviderOptions)({
|
|
1357
|
+
provider: "openai",
|
|
1358
|
+
providerOptions,
|
|
1359
|
+
schema: openaiEmbeddingProviderOptions
|
|
1360
|
+
})) != null ? _a : {};
|
|
1361
|
+
const {
|
|
1362
|
+
responseHeaders,
|
|
1363
|
+
value: response,
|
|
1364
|
+
rawValue
|
|
1365
|
+
} = await (0, import_provider_utils5.postJsonToApi)({
|
|
1490
1366
|
url: this.config.url({
|
|
1491
1367
|
path: "/embeddings",
|
|
1492
1368
|
modelId: this.modelId
|
|
@@ -1496,8 +1372,8 @@ var OpenAIEmbeddingModel = class {
|
|
|
1496
1372
|
model: this.modelId,
|
|
1497
1373
|
input: values,
|
|
1498
1374
|
encoding_format: "float",
|
|
1499
|
-
dimensions:
|
|
1500
|
-
user:
|
|
1375
|
+
dimensions: openaiOptions.dimensions,
|
|
1376
|
+
user: openaiOptions.user
|
|
1501
1377
|
},
|
|
1502
1378
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1503
1379
|
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
@@ -1509,18 +1385,18 @@ var OpenAIEmbeddingModel = class {
|
|
|
1509
1385
|
return {
|
|
1510
1386
|
embeddings: response.data.map((item) => item.embedding),
|
|
1511
1387
|
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
|
1512
|
-
|
|
1388
|
+
response: { headers: responseHeaders, body: rawValue }
|
|
1513
1389
|
};
|
|
1514
1390
|
}
|
|
1515
1391
|
};
|
|
1516
|
-
var openaiTextEmbeddingResponseSchema =
|
|
1517
|
-
data:
|
|
1518
|
-
usage:
|
|
1392
|
+
var openaiTextEmbeddingResponseSchema = import_zod6.z.object({
|
|
1393
|
+
data: import_zod6.z.array(import_zod6.z.object({ embedding: import_zod6.z.array(import_zod6.z.number()) })),
|
|
1394
|
+
usage: import_zod6.z.object({ prompt_tokens: import_zod6.z.number() }).nullish()
|
|
1519
1395
|
});
|
|
1520
1396
|
|
|
1521
1397
|
// src/openai-image-model.ts
|
|
1522
1398
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1523
|
-
var
|
|
1399
|
+
var import_zod7 = require("zod");
|
|
1524
1400
|
|
|
1525
1401
|
// src/openai-image-settings.ts
|
|
1526
1402
|
var modelMaxImagesPerCall = {
|
|
@@ -1598,17 +1474,284 @@ var OpenAIImageModel = class {
|
|
|
1598
1474
|
};
|
|
1599
1475
|
}
|
|
1600
1476
|
};
|
|
1601
|
-
var openaiImageResponseSchema =
|
|
1602
|
-
data:
|
|
1477
|
+
var openaiImageResponseSchema = import_zod7.z.object({
|
|
1478
|
+
data: import_zod7.z.array(import_zod7.z.object({ b64_json: import_zod7.z.string() }))
|
|
1603
1479
|
});
|
|
1604
1480
|
|
|
1605
|
-
// src/
|
|
1481
|
+
// src/openai-transcription-model.ts
|
|
1482
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1483
|
+
var import_zod8 = require("zod");
|
|
1484
|
+
var openAIProviderOptionsSchema = import_zod8.z.object({
|
|
1485
|
+
include: import_zod8.z.array(import_zod8.z.string()).nullish(),
|
|
1486
|
+
language: import_zod8.z.string().nullish(),
|
|
1487
|
+
prompt: import_zod8.z.string().nullish(),
|
|
1488
|
+
temperature: import_zod8.z.number().min(0).max(1).nullish().default(0),
|
|
1489
|
+
timestampGranularities: import_zod8.z.array(import_zod8.z.enum(["word", "segment"])).nullish().default(["segment"])
|
|
1490
|
+
});
|
|
1491
|
+
var languageMap = {
|
|
1492
|
+
afrikaans: "af",
|
|
1493
|
+
arabic: "ar",
|
|
1494
|
+
armenian: "hy",
|
|
1495
|
+
azerbaijani: "az",
|
|
1496
|
+
belarusian: "be",
|
|
1497
|
+
bosnian: "bs",
|
|
1498
|
+
bulgarian: "bg",
|
|
1499
|
+
catalan: "ca",
|
|
1500
|
+
chinese: "zh",
|
|
1501
|
+
croatian: "hr",
|
|
1502
|
+
czech: "cs",
|
|
1503
|
+
danish: "da",
|
|
1504
|
+
dutch: "nl",
|
|
1505
|
+
english: "en",
|
|
1506
|
+
estonian: "et",
|
|
1507
|
+
finnish: "fi",
|
|
1508
|
+
french: "fr",
|
|
1509
|
+
galician: "gl",
|
|
1510
|
+
german: "de",
|
|
1511
|
+
greek: "el",
|
|
1512
|
+
hebrew: "he",
|
|
1513
|
+
hindi: "hi",
|
|
1514
|
+
hungarian: "hu",
|
|
1515
|
+
icelandic: "is",
|
|
1516
|
+
indonesian: "id",
|
|
1517
|
+
italian: "it",
|
|
1518
|
+
japanese: "ja",
|
|
1519
|
+
kannada: "kn",
|
|
1520
|
+
kazakh: "kk",
|
|
1521
|
+
korean: "ko",
|
|
1522
|
+
latvian: "lv",
|
|
1523
|
+
lithuanian: "lt",
|
|
1524
|
+
macedonian: "mk",
|
|
1525
|
+
malay: "ms",
|
|
1526
|
+
marathi: "mr",
|
|
1527
|
+
maori: "mi",
|
|
1528
|
+
nepali: "ne",
|
|
1529
|
+
norwegian: "no",
|
|
1530
|
+
persian: "fa",
|
|
1531
|
+
polish: "pl",
|
|
1532
|
+
portuguese: "pt",
|
|
1533
|
+
romanian: "ro",
|
|
1534
|
+
russian: "ru",
|
|
1535
|
+
serbian: "sr",
|
|
1536
|
+
slovak: "sk",
|
|
1537
|
+
slovenian: "sl",
|
|
1538
|
+
spanish: "es",
|
|
1539
|
+
swahili: "sw",
|
|
1540
|
+
swedish: "sv",
|
|
1541
|
+
tagalog: "tl",
|
|
1542
|
+
tamil: "ta",
|
|
1543
|
+
thai: "th",
|
|
1544
|
+
turkish: "tr",
|
|
1545
|
+
ukrainian: "uk",
|
|
1546
|
+
urdu: "ur",
|
|
1547
|
+
vietnamese: "vi",
|
|
1548
|
+
welsh: "cy"
|
|
1549
|
+
};
|
|
1550
|
+
var OpenAITranscriptionModel = class {
|
|
1551
|
+
constructor(modelId, config) {
|
|
1552
|
+
this.modelId = modelId;
|
|
1553
|
+
this.config = config;
|
|
1554
|
+
this.specificationVersion = "v1";
|
|
1555
|
+
}
|
|
1556
|
+
get provider() {
|
|
1557
|
+
return this.config.provider;
|
|
1558
|
+
}
|
|
1559
|
+
getArgs({
|
|
1560
|
+
audio,
|
|
1561
|
+
mediaType,
|
|
1562
|
+
providerOptions
|
|
1563
|
+
}) {
|
|
1564
|
+
var _a, _b, _c, _d, _e;
|
|
1565
|
+
const warnings = [];
|
|
1566
|
+
const openAIOptions = (0, import_provider_utils7.parseProviderOptions)({
|
|
1567
|
+
provider: "openai",
|
|
1568
|
+
providerOptions,
|
|
1569
|
+
schema: openAIProviderOptionsSchema
|
|
1570
|
+
});
|
|
1571
|
+
const formData = new FormData();
|
|
1572
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
|
|
1573
|
+
formData.append("model", this.modelId);
|
|
1574
|
+
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1575
|
+
if (openAIOptions) {
|
|
1576
|
+
const transcriptionModelOptions = {
|
|
1577
|
+
include: (_a = openAIOptions.include) != null ? _a : void 0,
|
|
1578
|
+
language: (_b = openAIOptions.language) != null ? _b : void 0,
|
|
1579
|
+
prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
|
|
1580
|
+
temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
|
|
1581
|
+
timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
|
|
1582
|
+
};
|
|
1583
|
+
for (const key in transcriptionModelOptions) {
|
|
1584
|
+
const value = transcriptionModelOptions[key];
|
|
1585
|
+
if (value !== void 0) {
|
|
1586
|
+
formData.append(key, String(value));
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
return {
|
|
1591
|
+
formData,
|
|
1592
|
+
warnings
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
async doGenerate(options) {
|
|
1596
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1597
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1598
|
+
const { formData, warnings } = this.getArgs(options);
|
|
1599
|
+
const {
|
|
1600
|
+
value: response,
|
|
1601
|
+
responseHeaders,
|
|
1602
|
+
rawValue: rawResponse
|
|
1603
|
+
} = await (0, import_provider_utils7.postFormDataToApi)({
|
|
1604
|
+
url: this.config.url({
|
|
1605
|
+
path: "/audio/transcriptions",
|
|
1606
|
+
modelId: this.modelId
|
|
1607
|
+
}),
|
|
1608
|
+
headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
|
|
1609
|
+
formData,
|
|
1610
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1611
|
+
successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
|
|
1612
|
+
openaiTranscriptionResponseSchema
|
|
1613
|
+
),
|
|
1614
|
+
abortSignal: options.abortSignal,
|
|
1615
|
+
fetch: this.config.fetch
|
|
1616
|
+
});
|
|
1617
|
+
const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
|
|
1618
|
+
return {
|
|
1619
|
+
text: response.text,
|
|
1620
|
+
segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
|
|
1621
|
+
text: word.word,
|
|
1622
|
+
startSecond: word.start,
|
|
1623
|
+
endSecond: word.end
|
|
1624
|
+
}))) != null ? _e : [],
|
|
1625
|
+
language,
|
|
1626
|
+
durationInSeconds: (_f = response.duration) != null ? _f : void 0,
|
|
1627
|
+
warnings,
|
|
1628
|
+
response: {
|
|
1629
|
+
timestamp: currentDate,
|
|
1630
|
+
modelId: this.modelId,
|
|
1631
|
+
headers: responseHeaders,
|
|
1632
|
+
body: rawResponse
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
var openaiTranscriptionResponseSchema = import_zod8.z.object({
|
|
1638
|
+
text: import_zod8.z.string(),
|
|
1639
|
+
language: import_zod8.z.string().nullish(),
|
|
1640
|
+
duration: import_zod8.z.number().nullish(),
|
|
1641
|
+
words: import_zod8.z.array(
|
|
1642
|
+
import_zod8.z.object({
|
|
1643
|
+
word: import_zod8.z.string(),
|
|
1644
|
+
start: import_zod8.z.number(),
|
|
1645
|
+
end: import_zod8.z.number()
|
|
1646
|
+
})
|
|
1647
|
+
).nullish()
|
|
1648
|
+
});
|
|
1649
|
+
|
|
1650
|
+
// src/openai-speech-model.ts
|
|
1606
1651
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1607
|
-
var
|
|
1652
|
+
var import_zod9 = require("zod");
|
|
1653
|
+
var OpenAIProviderOptionsSchema = import_zod9.z.object({
|
|
1654
|
+
instructions: import_zod9.z.string().nullish(),
|
|
1655
|
+
speed: import_zod9.z.number().min(0.25).max(4).default(1).nullish()
|
|
1656
|
+
});
|
|
1657
|
+
var OpenAISpeechModel = class {
|
|
1658
|
+
constructor(modelId, config) {
|
|
1659
|
+
this.modelId = modelId;
|
|
1660
|
+
this.config = config;
|
|
1661
|
+
this.specificationVersion = "v1";
|
|
1662
|
+
}
|
|
1663
|
+
get provider() {
|
|
1664
|
+
return this.config.provider;
|
|
1665
|
+
}
|
|
1666
|
+
getArgs({
|
|
1667
|
+
text,
|
|
1668
|
+
voice = "alloy",
|
|
1669
|
+
outputFormat = "mp3",
|
|
1670
|
+
speed,
|
|
1671
|
+
instructions,
|
|
1672
|
+
providerOptions
|
|
1673
|
+
}) {
|
|
1674
|
+
const warnings = [];
|
|
1675
|
+
const openAIOptions = (0, import_provider_utils8.parseProviderOptions)({
|
|
1676
|
+
provider: "openai",
|
|
1677
|
+
providerOptions,
|
|
1678
|
+
schema: OpenAIProviderOptionsSchema
|
|
1679
|
+
});
|
|
1680
|
+
const requestBody = {
|
|
1681
|
+
model: this.modelId,
|
|
1682
|
+
input: text,
|
|
1683
|
+
voice,
|
|
1684
|
+
response_format: "mp3",
|
|
1685
|
+
speed,
|
|
1686
|
+
instructions
|
|
1687
|
+
};
|
|
1688
|
+
if (outputFormat) {
|
|
1689
|
+
if (["mp3", "opus", "aac", "flac", "wav", "pcm"].includes(outputFormat)) {
|
|
1690
|
+
requestBody.response_format = outputFormat;
|
|
1691
|
+
} else {
|
|
1692
|
+
warnings.push({
|
|
1693
|
+
type: "unsupported-setting",
|
|
1694
|
+
setting: "outputFormat",
|
|
1695
|
+
details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
if (openAIOptions) {
|
|
1700
|
+
const speechModelOptions = {};
|
|
1701
|
+
for (const key in speechModelOptions) {
|
|
1702
|
+
const value = speechModelOptions[key];
|
|
1703
|
+
if (value !== void 0) {
|
|
1704
|
+
requestBody[key] = value;
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
return {
|
|
1709
|
+
requestBody,
|
|
1710
|
+
warnings
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
async doGenerate(options) {
|
|
1714
|
+
var _a, _b, _c;
|
|
1715
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1716
|
+
const { requestBody, warnings } = this.getArgs(options);
|
|
1717
|
+
const {
|
|
1718
|
+
value: audio,
|
|
1719
|
+
responseHeaders,
|
|
1720
|
+
rawValue: rawResponse
|
|
1721
|
+
} = await (0, import_provider_utils8.postJsonToApi)({
|
|
1722
|
+
url: this.config.url({
|
|
1723
|
+
path: "/audio/speech",
|
|
1724
|
+
modelId: this.modelId
|
|
1725
|
+
}),
|
|
1726
|
+
headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
|
|
1727
|
+
body: requestBody,
|
|
1728
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1729
|
+
successfulResponseHandler: (0, import_provider_utils8.createBinaryResponseHandler)(),
|
|
1730
|
+
abortSignal: options.abortSignal,
|
|
1731
|
+
fetch: this.config.fetch
|
|
1732
|
+
});
|
|
1733
|
+
return {
|
|
1734
|
+
audio,
|
|
1735
|
+
warnings,
|
|
1736
|
+
request: {
|
|
1737
|
+
body: JSON.stringify(requestBody)
|
|
1738
|
+
},
|
|
1739
|
+
response: {
|
|
1740
|
+
timestamp: currentDate,
|
|
1741
|
+
modelId: this.modelId,
|
|
1742
|
+
headers: responseHeaders,
|
|
1743
|
+
body: rawResponse
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
|
|
1749
|
+
// src/responses/openai-responses-language-model.ts
|
|
1750
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1751
|
+
var import_zod10 = require("zod");
|
|
1608
1752
|
|
|
1609
1753
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1610
|
-
var
|
|
1611
|
-
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1754
|
+
var import_provider6 = require("@ai-sdk/provider");
|
|
1612
1755
|
function convertToOpenAIResponsesMessages({
|
|
1613
1756
|
prompt,
|
|
1614
1757
|
systemMessageMode
|
|
@@ -1647,38 +1790,35 @@ function convertToOpenAIResponsesMessages({
|
|
|
1647
1790
|
messages.push({
|
|
1648
1791
|
role: "user",
|
|
1649
1792
|
content: content.map((part, index) => {
|
|
1650
|
-
var _a, _b, _c
|
|
1793
|
+
var _a, _b, _c;
|
|
1651
1794
|
switch (part.type) {
|
|
1652
1795
|
case "text": {
|
|
1653
1796
|
return { type: "input_text", text: part.text };
|
|
1654
1797
|
}
|
|
1655
|
-
case "image": {
|
|
1656
|
-
return {
|
|
1657
|
-
type: "input_image",
|
|
1658
|
-
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils7.convertUint8ArrayToBase64)(part.image)}`,
|
|
1659
|
-
// OpenAI specific extension: image detail
|
|
1660
|
-
detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
1661
|
-
};
|
|
1662
|
-
}
|
|
1663
1798
|
case "file": {
|
|
1664
|
-
if (part.
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
}
|
|
1677
|
-
default: {
|
|
1678
|
-
throw new import_provider7.UnsupportedFunctionalityError({
|
|
1679
|
-
functionality: "Only PDF files are supported in user messages"
|
|
1799
|
+
if (part.mediaType.startsWith("image/")) {
|
|
1800
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
1801
|
+
return {
|
|
1802
|
+
type: "input_image",
|
|
1803
|
+
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
1804
|
+
// OpenAI specific extension: image detail
|
|
1805
|
+
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
1806
|
+
};
|
|
1807
|
+
} else if (part.mediaType === "application/pdf") {
|
|
1808
|
+
if (part.data instanceof URL) {
|
|
1809
|
+
throw new import_provider6.UnsupportedFunctionalityError({
|
|
1810
|
+
functionality: "PDF file parts with URLs"
|
|
1680
1811
|
});
|
|
1681
1812
|
}
|
|
1813
|
+
return {
|
|
1814
|
+
type: "input_file",
|
|
1815
|
+
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
1816
|
+
file_data: `data:application/pdf;base64,${part.data}`
|
|
1817
|
+
};
|
|
1818
|
+
} else {
|
|
1819
|
+
throw new import_provider6.UnsupportedFunctionalityError({
|
|
1820
|
+
functionality: `file part media type ${part.mediaType}`
|
|
1821
|
+
});
|
|
1682
1822
|
}
|
|
1683
1823
|
}
|
|
1684
1824
|
}
|
|
@@ -1747,18 +1887,17 @@ function mapOpenAIResponseFinishReason({
|
|
|
1747
1887
|
}
|
|
1748
1888
|
|
|
1749
1889
|
// src/responses/openai-responses-prepare-tools.ts
|
|
1750
|
-
var
|
|
1890
|
+
var import_provider7 = require("@ai-sdk/provider");
|
|
1751
1891
|
function prepareResponsesTools({
|
|
1752
|
-
|
|
1892
|
+
tools,
|
|
1893
|
+
toolChoice,
|
|
1753
1894
|
strict
|
|
1754
1895
|
}) {
|
|
1755
|
-
|
|
1756
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
1896
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1757
1897
|
const toolWarnings = [];
|
|
1758
1898
|
if (tools == null) {
|
|
1759
|
-
return { tools: void 0,
|
|
1899
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
1760
1900
|
}
|
|
1761
|
-
const toolChoice = mode.toolChoice;
|
|
1762
1901
|
const openaiTools = [];
|
|
1763
1902
|
for (const tool of tools) {
|
|
1764
1903
|
switch (tool.type) {
|
|
@@ -1791,37 +1930,24 @@ function prepareResponsesTools({
|
|
|
1791
1930
|
}
|
|
1792
1931
|
}
|
|
1793
1932
|
if (toolChoice == null) {
|
|
1794
|
-
return { tools: openaiTools,
|
|
1933
|
+
return { tools: openaiTools, toolChoice: void 0, toolWarnings };
|
|
1795
1934
|
}
|
|
1796
1935
|
const type = toolChoice.type;
|
|
1797
1936
|
switch (type) {
|
|
1798
1937
|
case "auto":
|
|
1799
1938
|
case "none":
|
|
1800
1939
|
case "required":
|
|
1801
|
-
return { tools: openaiTools,
|
|
1802
|
-
case "tool":
|
|
1803
|
-
if (toolChoice.toolName === "web_search_preview") {
|
|
1804
|
-
return {
|
|
1805
|
-
tools: openaiTools,
|
|
1806
|
-
tool_choice: {
|
|
1807
|
-
type: "web_search_preview"
|
|
1808
|
-
},
|
|
1809
|
-
toolWarnings
|
|
1810
|
-
};
|
|
1811
|
-
}
|
|
1940
|
+
return { tools: openaiTools, toolChoice: type, toolWarnings };
|
|
1941
|
+
case "tool":
|
|
1812
1942
|
return {
|
|
1813
1943
|
tools: openaiTools,
|
|
1814
|
-
|
|
1815
|
-
type: "function",
|
|
1816
|
-
name: toolChoice.toolName
|
|
1817
|
-
},
|
|
1944
|
+
toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
1818
1945
|
toolWarnings
|
|
1819
1946
|
};
|
|
1820
|
-
}
|
|
1821
1947
|
default: {
|
|
1822
1948
|
const _exhaustiveCheck = type;
|
|
1823
|
-
throw new
|
|
1824
|
-
functionality: `
|
|
1949
|
+
throw new import_provider7.UnsupportedFunctionalityError({
|
|
1950
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1825
1951
|
});
|
|
1826
1952
|
}
|
|
1827
1953
|
}
|
|
@@ -1830,17 +1956,20 @@ function prepareResponsesTools({
|
|
|
1830
1956
|
// src/responses/openai-responses-language-model.ts
|
|
1831
1957
|
var OpenAIResponsesLanguageModel = class {
|
|
1832
1958
|
constructor(modelId, config) {
|
|
1833
|
-
this.specificationVersion = "
|
|
1834
|
-
this.defaultObjectGenerationMode = "json";
|
|
1959
|
+
this.specificationVersion = "v2";
|
|
1835
1960
|
this.modelId = modelId;
|
|
1836
1961
|
this.config = config;
|
|
1837
1962
|
}
|
|
1963
|
+
async getSupportedUrls() {
|
|
1964
|
+
return {
|
|
1965
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1838
1968
|
get provider() {
|
|
1839
1969
|
return this.config.provider;
|
|
1840
1970
|
}
|
|
1841
1971
|
getArgs({
|
|
1842
|
-
|
|
1843
|
-
maxTokens,
|
|
1972
|
+
maxOutputTokens,
|
|
1844
1973
|
temperature,
|
|
1845
1974
|
stopSequences,
|
|
1846
1975
|
topP,
|
|
@@ -1849,24 +1978,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1849
1978
|
frequencyPenalty,
|
|
1850
1979
|
seed,
|
|
1851
1980
|
prompt,
|
|
1852
|
-
|
|
1981
|
+
providerOptions,
|
|
1982
|
+
tools,
|
|
1983
|
+
toolChoice,
|
|
1853
1984
|
responseFormat
|
|
1854
1985
|
}) {
|
|
1855
|
-
var _a, _b
|
|
1986
|
+
var _a, _b;
|
|
1856
1987
|
const warnings = [];
|
|
1857
1988
|
const modelConfig = getResponsesModelConfig(this.modelId);
|
|
1858
|
-
const type = mode.type;
|
|
1859
1989
|
if (topK != null) {
|
|
1860
|
-
warnings.push({
|
|
1861
|
-
type: "unsupported-setting",
|
|
1862
|
-
setting: "topK"
|
|
1863
|
-
});
|
|
1990
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1864
1991
|
}
|
|
1865
1992
|
if (seed != null) {
|
|
1866
|
-
warnings.push({
|
|
1867
|
-
type: "unsupported-setting",
|
|
1868
|
-
setting: "seed"
|
|
1869
|
-
});
|
|
1993
|
+
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1870
1994
|
}
|
|
1871
1995
|
if (presencePenalty != null) {
|
|
1872
1996
|
warnings.push({
|
|
@@ -1881,19 +2005,16 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1881
2005
|
});
|
|
1882
2006
|
}
|
|
1883
2007
|
if (stopSequences != null) {
|
|
1884
|
-
warnings.push({
|
|
1885
|
-
type: "unsupported-setting",
|
|
1886
|
-
setting: "stopSequences"
|
|
1887
|
-
});
|
|
2008
|
+
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
1888
2009
|
}
|
|
1889
2010
|
const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
|
|
1890
2011
|
prompt,
|
|
1891
2012
|
systemMessageMode: modelConfig.systemMessageMode
|
|
1892
2013
|
});
|
|
1893
2014
|
warnings.push(...messageWarnings);
|
|
1894
|
-
const openaiOptions = (0,
|
|
2015
|
+
const openaiOptions = (0, import_provider_utils9.parseProviderOptions)({
|
|
1895
2016
|
provider: "openai",
|
|
1896
|
-
providerOptions
|
|
2017
|
+
providerOptions,
|
|
1897
2018
|
schema: openaiResponsesProviderOptionsSchema
|
|
1898
2019
|
});
|
|
1899
2020
|
const isStrict = (_a = openaiOptions == null ? void 0 : openaiOptions.strictSchemas) != null ? _a : true;
|
|
@@ -1902,7 +2023,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1902
2023
|
input: messages,
|
|
1903
2024
|
temperature,
|
|
1904
2025
|
top_p: topP,
|
|
1905
|
-
max_output_tokens:
|
|
2026
|
+
max_output_tokens: maxOutputTokens,
|
|
1906
2027
|
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
|
|
1907
2028
|
text: {
|
|
1908
2029
|
format: responseFormat.schema != null ? {
|
|
@@ -1947,178 +2068,145 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1947
2068
|
});
|
|
1948
2069
|
}
|
|
1949
2070
|
}
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
return {
|
|
1968
|
-
args: {
|
|
1969
|
-
...baseArgs,
|
|
1970
|
-
text: {
|
|
1971
|
-
format: mode.schema != null ? {
|
|
1972
|
-
type: "json_schema",
|
|
1973
|
-
strict: isStrict,
|
|
1974
|
-
name: (_c = mode.name) != null ? _c : "response",
|
|
1975
|
-
description: mode.description,
|
|
1976
|
-
schema: mode.schema
|
|
1977
|
-
} : { type: "json_object" }
|
|
1978
|
-
}
|
|
1979
|
-
},
|
|
1980
|
-
warnings
|
|
1981
|
-
};
|
|
1982
|
-
}
|
|
1983
|
-
case "object-tool": {
|
|
1984
|
-
return {
|
|
1985
|
-
args: {
|
|
1986
|
-
...baseArgs,
|
|
1987
|
-
tool_choice: { type: "function", name: mode.tool.name },
|
|
1988
|
-
tools: [
|
|
1989
|
-
{
|
|
1990
|
-
type: "function",
|
|
1991
|
-
name: mode.tool.name,
|
|
1992
|
-
description: mode.tool.description,
|
|
1993
|
-
parameters: mode.tool.parameters,
|
|
1994
|
-
strict: isStrict
|
|
1995
|
-
}
|
|
1996
|
-
]
|
|
1997
|
-
},
|
|
1998
|
-
warnings
|
|
1999
|
-
};
|
|
2000
|
-
}
|
|
2001
|
-
default: {
|
|
2002
|
-
const _exhaustiveCheck = type;
|
|
2003
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2071
|
+
const {
|
|
2072
|
+
tools: openaiTools,
|
|
2073
|
+
toolChoice: openaiToolChoice,
|
|
2074
|
+
toolWarnings
|
|
2075
|
+
} = prepareResponsesTools({
|
|
2076
|
+
tools,
|
|
2077
|
+
toolChoice,
|
|
2078
|
+
strict: isStrict
|
|
2079
|
+
});
|
|
2080
|
+
return {
|
|
2081
|
+
args: {
|
|
2082
|
+
...baseArgs,
|
|
2083
|
+
tools: openaiTools,
|
|
2084
|
+
tool_choice: openaiToolChoice
|
|
2085
|
+
},
|
|
2086
|
+
warnings: [...warnings, ...toolWarnings]
|
|
2087
|
+
};
|
|
2006
2088
|
}
|
|
2007
2089
|
async doGenerate(options) {
|
|
2008
|
-
var _a, _b, _c, _d, _e;
|
|
2090
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2009
2091
|
const { args: body, warnings } = this.getArgs(options);
|
|
2010
2092
|
const {
|
|
2011
2093
|
responseHeaders,
|
|
2012
2094
|
value: response,
|
|
2013
2095
|
rawValue: rawResponse
|
|
2014
|
-
} = await (0,
|
|
2096
|
+
} = await (0, import_provider_utils9.postJsonToApi)({
|
|
2015
2097
|
url: this.config.url({
|
|
2016
2098
|
path: "/responses",
|
|
2017
2099
|
modelId: this.modelId
|
|
2018
2100
|
}),
|
|
2019
|
-
headers: (0,
|
|
2101
|
+
headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
|
|
2020
2102
|
body,
|
|
2021
2103
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2022
|
-
successfulResponseHandler: (0,
|
|
2023
|
-
|
|
2024
|
-
id:
|
|
2025
|
-
created_at:
|
|
2026
|
-
model:
|
|
2027
|
-
output:
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
type:
|
|
2031
|
-
role:
|
|
2032
|
-
content:
|
|
2033
|
-
|
|
2034
|
-
type:
|
|
2035
|
-
text:
|
|
2036
|
-
annotations:
|
|
2037
|
-
|
|
2038
|
-
type:
|
|
2039
|
-
start_index:
|
|
2040
|
-
end_index:
|
|
2041
|
-
url:
|
|
2042
|
-
title:
|
|
2104
|
+
successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
|
|
2105
|
+
import_zod10.z.object({
|
|
2106
|
+
id: import_zod10.z.string(),
|
|
2107
|
+
created_at: import_zod10.z.number(),
|
|
2108
|
+
model: import_zod10.z.string(),
|
|
2109
|
+
output: import_zod10.z.array(
|
|
2110
|
+
import_zod10.z.discriminatedUnion("type", [
|
|
2111
|
+
import_zod10.z.object({
|
|
2112
|
+
type: import_zod10.z.literal("message"),
|
|
2113
|
+
role: import_zod10.z.literal("assistant"),
|
|
2114
|
+
content: import_zod10.z.array(
|
|
2115
|
+
import_zod10.z.object({
|
|
2116
|
+
type: import_zod10.z.literal("output_text"),
|
|
2117
|
+
text: import_zod10.z.string(),
|
|
2118
|
+
annotations: import_zod10.z.array(
|
|
2119
|
+
import_zod10.z.object({
|
|
2120
|
+
type: import_zod10.z.literal("url_citation"),
|
|
2121
|
+
start_index: import_zod10.z.number(),
|
|
2122
|
+
end_index: import_zod10.z.number(),
|
|
2123
|
+
url: import_zod10.z.string(),
|
|
2124
|
+
title: import_zod10.z.string()
|
|
2043
2125
|
})
|
|
2044
2126
|
)
|
|
2045
2127
|
})
|
|
2046
2128
|
)
|
|
2047
2129
|
}),
|
|
2048
|
-
|
|
2049
|
-
type:
|
|
2050
|
-
call_id:
|
|
2051
|
-
name:
|
|
2052
|
-
arguments:
|
|
2130
|
+
import_zod10.z.object({
|
|
2131
|
+
type: import_zod10.z.literal("function_call"),
|
|
2132
|
+
call_id: import_zod10.z.string(),
|
|
2133
|
+
name: import_zod10.z.string(),
|
|
2134
|
+
arguments: import_zod10.z.string()
|
|
2053
2135
|
}),
|
|
2054
|
-
|
|
2055
|
-
type:
|
|
2136
|
+
import_zod10.z.object({
|
|
2137
|
+
type: import_zod10.z.literal("web_search_call")
|
|
2056
2138
|
}),
|
|
2057
|
-
|
|
2058
|
-
type:
|
|
2139
|
+
import_zod10.z.object({
|
|
2140
|
+
type: import_zod10.z.literal("computer_call")
|
|
2059
2141
|
}),
|
|
2060
|
-
|
|
2061
|
-
type:
|
|
2142
|
+
import_zod10.z.object({
|
|
2143
|
+
type: import_zod10.z.literal("reasoning")
|
|
2062
2144
|
})
|
|
2063
2145
|
])
|
|
2064
2146
|
),
|
|
2065
|
-
incomplete_details:
|
|
2147
|
+
incomplete_details: import_zod10.z.object({ reason: import_zod10.z.string() }).nullable(),
|
|
2066
2148
|
usage: usageSchema
|
|
2067
2149
|
})
|
|
2068
2150
|
),
|
|
2069
2151
|
abortSignal: options.abortSignal,
|
|
2070
2152
|
fetch: this.config.fetch
|
|
2071
2153
|
});
|
|
2072
|
-
const
|
|
2073
|
-
const
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2154
|
+
const content = [];
|
|
2155
|
+
for (const part of response.output) {
|
|
2156
|
+
switch (part.type) {
|
|
2157
|
+
case "message": {
|
|
2158
|
+
for (const contentPart of part.content) {
|
|
2159
|
+
content.push({
|
|
2160
|
+
type: "text",
|
|
2161
|
+
text: contentPart.text
|
|
2162
|
+
});
|
|
2163
|
+
for (const annotation of contentPart.annotations) {
|
|
2164
|
+
content.push({
|
|
2165
|
+
type: "source",
|
|
2166
|
+
sourceType: "url",
|
|
2167
|
+
id: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c : (0, import_provider_utils9.generateId)(),
|
|
2168
|
+
url: annotation.url,
|
|
2169
|
+
title: annotation.title
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
break;
|
|
2174
|
+
}
|
|
2175
|
+
case "function_call": {
|
|
2176
|
+
content.push({
|
|
2177
|
+
type: "tool-call",
|
|
2178
|
+
toolCallType: "function",
|
|
2179
|
+
toolCallId: part.call_id,
|
|
2180
|
+
toolName: part.name,
|
|
2181
|
+
args: part.arguments
|
|
2182
|
+
});
|
|
2183
|
+
break;
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2079
2187
|
return {
|
|
2080
|
-
|
|
2081
|
-
sources: outputTextElements.flatMap(
|
|
2082
|
-
(content) => content.annotations.map((annotation) => {
|
|
2083
|
-
var _a2, _b2, _c2;
|
|
2084
|
-
return {
|
|
2085
|
-
sourceType: "url",
|
|
2086
|
-
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0, import_provider_utils8.generateId)(),
|
|
2087
|
-
url: annotation.url,
|
|
2088
|
-
title: annotation.title
|
|
2089
|
-
};
|
|
2090
|
-
})
|
|
2091
|
-
),
|
|
2188
|
+
content,
|
|
2092
2189
|
finishReason: mapOpenAIResponseFinishReason({
|
|
2093
|
-
finishReason: (
|
|
2094
|
-
hasToolCalls:
|
|
2190
|
+
finishReason: (_d = response.incomplete_details) == null ? void 0 : _d.reason,
|
|
2191
|
+
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
2095
2192
|
}),
|
|
2096
|
-
toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
2097
2193
|
usage: {
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
},
|
|
2101
|
-
rawCall: {
|
|
2102
|
-
rawPrompt: void 0,
|
|
2103
|
-
rawSettings: {}
|
|
2104
|
-
},
|
|
2105
|
-
rawResponse: {
|
|
2106
|
-
headers: responseHeaders,
|
|
2107
|
-
body: rawResponse
|
|
2108
|
-
},
|
|
2109
|
-
request: {
|
|
2110
|
-
body: JSON.stringify(body)
|
|
2194
|
+
inputTokens: response.usage.input_tokens,
|
|
2195
|
+
outputTokens: response.usage.output_tokens
|
|
2111
2196
|
},
|
|
2197
|
+
request: { body },
|
|
2112
2198
|
response: {
|
|
2113
2199
|
id: response.id,
|
|
2114
2200
|
timestamp: new Date(response.created_at * 1e3),
|
|
2115
|
-
modelId: response.model
|
|
2201
|
+
modelId: response.model,
|
|
2202
|
+
headers: responseHeaders,
|
|
2203
|
+
body: rawResponse
|
|
2116
2204
|
},
|
|
2117
2205
|
providerMetadata: {
|
|
2118
2206
|
openai: {
|
|
2119
2207
|
responseId: response.id,
|
|
2120
|
-
cachedPromptTokens: (
|
|
2121
|
-
reasoningTokens: (
|
|
2208
|
+
cachedPromptTokens: (_f = (_e = response.usage.input_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : null,
|
|
2209
|
+
reasoningTokens: (_h = (_g = response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : null
|
|
2122
2210
|
}
|
|
2123
2211
|
},
|
|
2124
2212
|
warnings
|
|
@@ -2126,18 +2214,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2126
2214
|
}
|
|
2127
2215
|
async doStream(options) {
|
|
2128
2216
|
const { args: body, warnings } = this.getArgs(options);
|
|
2129
|
-
const { responseHeaders, value: response } = await (0,
|
|
2217
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils9.postJsonToApi)({
|
|
2130
2218
|
url: this.config.url({
|
|
2131
2219
|
path: "/responses",
|
|
2132
2220
|
modelId: this.modelId
|
|
2133
2221
|
}),
|
|
2134
|
-
headers: (0,
|
|
2222
|
+
headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
|
|
2135
2223
|
body: {
|
|
2136
2224
|
...body,
|
|
2137
2225
|
stream: true
|
|
2138
2226
|
},
|
|
2139
2227
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2140
|
-
successfulResponseHandler: (0,
|
|
2228
|
+
successfulResponseHandler: (0, import_provider_utils9.createEventSourceResponseHandler)(
|
|
2141
2229
|
openaiResponsesChunkSchema
|
|
2142
2230
|
),
|
|
2143
2231
|
abortSignal: options.abortSignal,
|
|
@@ -2145,8 +2233,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2145
2233
|
});
|
|
2146
2234
|
const self = this;
|
|
2147
2235
|
let finishReason = "unknown";
|
|
2148
|
-
|
|
2149
|
-
|
|
2236
|
+
const usage = {
|
|
2237
|
+
inputTokens: void 0,
|
|
2238
|
+
outputTokens: void 0
|
|
2239
|
+
};
|
|
2150
2240
|
let cachedPromptTokens = null;
|
|
2151
2241
|
let reasoningTokens = null;
|
|
2152
2242
|
let responseId = null;
|
|
@@ -2155,6 +2245,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2155
2245
|
return {
|
|
2156
2246
|
stream: response.pipeThrough(
|
|
2157
2247
|
new TransformStream({
|
|
2248
|
+
start(controller) {
|
|
2249
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
2250
|
+
},
|
|
2158
2251
|
transform(chunk, controller) {
|
|
2159
2252
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2160
2253
|
if (!chunk.success) {
|
|
@@ -2198,8 +2291,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2198
2291
|
});
|
|
2199
2292
|
} else if (isTextDeltaChunk(value)) {
|
|
2200
2293
|
controller.enqueue({
|
|
2201
|
-
type: "text
|
|
2202
|
-
|
|
2294
|
+
type: "text",
|
|
2295
|
+
text: value.delta
|
|
2203
2296
|
});
|
|
2204
2297
|
} else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
|
|
2205
2298
|
ongoingToolCalls[value.output_index] = void 0;
|
|
@@ -2216,19 +2309,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2216
2309
|
finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
|
|
2217
2310
|
hasToolCalls
|
|
2218
2311
|
});
|
|
2219
|
-
|
|
2220
|
-
|
|
2312
|
+
usage.inputTokens = value.response.usage.input_tokens;
|
|
2313
|
+
usage.outputTokens = value.response.usage.output_tokens;
|
|
2221
2314
|
cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
|
|
2222
2315
|
reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
|
|
2223
2316
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2224
2317
|
controller.enqueue({
|
|
2225
2318
|
type: "source",
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
title: value.annotation.title
|
|
2231
|
-
}
|
|
2319
|
+
sourceType: "url",
|
|
2320
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils9.generateId)(),
|
|
2321
|
+
url: value.annotation.url,
|
|
2322
|
+
title: value.annotation.title
|
|
2232
2323
|
});
|
|
2233
2324
|
}
|
|
2234
2325
|
},
|
|
@@ -2236,7 +2327,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2236
2327
|
controller.enqueue({
|
|
2237
2328
|
type: "finish",
|
|
2238
2329
|
finishReason,
|
|
2239
|
-
usage
|
|
2330
|
+
usage,
|
|
2240
2331
|
...(cachedPromptTokens != null || reasoningTokens != null) && {
|
|
2241
2332
|
providerMetadata: {
|
|
2242
2333
|
openai: {
|
|
@@ -2250,89 +2341,84 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2250
2341
|
}
|
|
2251
2342
|
})
|
|
2252
2343
|
),
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
rawSettings: {}
|
|
2256
|
-
},
|
|
2257
|
-
rawResponse: { headers: responseHeaders },
|
|
2258
|
-
request: { body: JSON.stringify(body) },
|
|
2259
|
-
warnings
|
|
2344
|
+
request: { body },
|
|
2345
|
+
response: { headers: responseHeaders }
|
|
2260
2346
|
};
|
|
2261
2347
|
}
|
|
2262
2348
|
};
|
|
2263
|
-
var usageSchema =
|
|
2264
|
-
input_tokens:
|
|
2265
|
-
input_tokens_details:
|
|
2266
|
-
output_tokens:
|
|
2267
|
-
output_tokens_details:
|
|
2349
|
+
var usageSchema = import_zod10.z.object({
|
|
2350
|
+
input_tokens: import_zod10.z.number(),
|
|
2351
|
+
input_tokens_details: import_zod10.z.object({ cached_tokens: import_zod10.z.number().nullish() }).nullish(),
|
|
2352
|
+
output_tokens: import_zod10.z.number(),
|
|
2353
|
+
output_tokens_details: import_zod10.z.object({ reasoning_tokens: import_zod10.z.number().nullish() }).nullish()
|
|
2268
2354
|
});
|
|
2269
|
-
var textDeltaChunkSchema =
|
|
2270
|
-
type:
|
|
2271
|
-
delta:
|
|
2355
|
+
var textDeltaChunkSchema = import_zod10.z.object({
|
|
2356
|
+
type: import_zod10.z.literal("response.output_text.delta"),
|
|
2357
|
+
delta: import_zod10.z.string()
|
|
2272
2358
|
});
|
|
2273
|
-
var responseFinishedChunkSchema =
|
|
2274
|
-
type:
|
|
2275
|
-
response:
|
|
2276
|
-
incomplete_details:
|
|
2359
|
+
var responseFinishedChunkSchema = import_zod10.z.object({
|
|
2360
|
+
type: import_zod10.z.enum(["response.completed", "response.incomplete"]),
|
|
2361
|
+
response: import_zod10.z.object({
|
|
2362
|
+
incomplete_details: import_zod10.z.object({ reason: import_zod10.z.string() }).nullish(),
|
|
2277
2363
|
usage: usageSchema
|
|
2278
2364
|
})
|
|
2279
2365
|
});
|
|
2280
|
-
var responseCreatedChunkSchema =
|
|
2281
|
-
type:
|
|
2282
|
-
response:
|
|
2283
|
-
id:
|
|
2284
|
-
created_at:
|
|
2285
|
-
model:
|
|
2366
|
+
var responseCreatedChunkSchema = import_zod10.z.object({
|
|
2367
|
+
type: import_zod10.z.literal("response.created"),
|
|
2368
|
+
response: import_zod10.z.object({
|
|
2369
|
+
id: import_zod10.z.string(),
|
|
2370
|
+
created_at: import_zod10.z.number(),
|
|
2371
|
+
model: import_zod10.z.string()
|
|
2286
2372
|
})
|
|
2287
2373
|
});
|
|
2288
|
-
var responseOutputItemDoneSchema =
|
|
2289
|
-
type:
|
|
2290
|
-
output_index:
|
|
2291
|
-
item:
|
|
2292
|
-
|
|
2293
|
-
type:
|
|
2374
|
+
var responseOutputItemDoneSchema = import_zod10.z.object({
|
|
2375
|
+
type: import_zod10.z.literal("response.output_item.done"),
|
|
2376
|
+
output_index: import_zod10.z.number(),
|
|
2377
|
+
item: import_zod10.z.discriminatedUnion("type", [
|
|
2378
|
+
import_zod10.z.object({
|
|
2379
|
+
type: import_zod10.z.literal("message")
|
|
2294
2380
|
}),
|
|
2295
|
-
|
|
2296
|
-
type:
|
|
2297
|
-
id:
|
|
2298
|
-
call_id:
|
|
2299
|
-
name:
|
|
2300
|
-
arguments:
|
|
2301
|
-
status:
|
|
2381
|
+
import_zod10.z.object({
|
|
2382
|
+
type: import_zod10.z.literal("function_call"),
|
|
2383
|
+
id: import_zod10.z.string(),
|
|
2384
|
+
call_id: import_zod10.z.string(),
|
|
2385
|
+
name: import_zod10.z.string(),
|
|
2386
|
+
arguments: import_zod10.z.string(),
|
|
2387
|
+
status: import_zod10.z.literal("completed")
|
|
2302
2388
|
})
|
|
2303
2389
|
])
|
|
2304
2390
|
});
|
|
2305
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2306
|
-
type:
|
|
2307
|
-
item_id:
|
|
2308
|
-
output_index:
|
|
2309
|
-
delta:
|
|
2391
|
+
var responseFunctionCallArgumentsDeltaSchema = import_zod10.z.object({
|
|
2392
|
+
type: import_zod10.z.literal("response.function_call_arguments.delta"),
|
|
2393
|
+
item_id: import_zod10.z.string(),
|
|
2394
|
+
output_index: import_zod10.z.number(),
|
|
2395
|
+
delta: import_zod10.z.string()
|
|
2310
2396
|
});
|
|
2311
|
-
var responseOutputItemAddedSchema =
|
|
2312
|
-
type:
|
|
2313
|
-
output_index:
|
|
2314
|
-
item:
|
|
2315
|
-
|
|
2316
|
-
type:
|
|
2397
|
+
var responseOutputItemAddedSchema = import_zod10.z.object({
|
|
2398
|
+
type: import_zod10.z.literal("response.output_item.added"),
|
|
2399
|
+
output_index: import_zod10.z.number(),
|
|
2400
|
+
item: import_zod10.z.discriminatedUnion("type", [
|
|
2401
|
+
import_zod10.z.object({
|
|
2402
|
+
type: import_zod10.z.literal("message")
|
|
2317
2403
|
}),
|
|
2318
|
-
|
|
2319
|
-
type:
|
|
2320
|
-
id:
|
|
2321
|
-
call_id:
|
|
2322
|
-
name:
|
|
2323
|
-
arguments:
|
|
2404
|
+
import_zod10.z.object({
|
|
2405
|
+
type: import_zod10.z.literal("function_call"),
|
|
2406
|
+
id: import_zod10.z.string(),
|
|
2407
|
+
call_id: import_zod10.z.string(),
|
|
2408
|
+
name: import_zod10.z.string(),
|
|
2409
|
+
arguments: import_zod10.z.string()
|
|
2324
2410
|
})
|
|
2325
2411
|
])
|
|
2326
2412
|
});
|
|
2327
|
-
var responseAnnotationAddedSchema =
|
|
2328
|
-
type:
|
|
2329
|
-
annotation:
|
|
2330
|
-
type:
|
|
2331
|
-
url:
|
|
2332
|
-
title:
|
|
2413
|
+
var responseAnnotationAddedSchema = import_zod10.z.object({
|
|
2414
|
+
type: import_zod10.z.literal("response.output_text.annotation.added"),
|
|
2415
|
+
annotation: import_zod10.z.object({
|
|
2416
|
+
type: import_zod10.z.literal("url_citation"),
|
|
2417
|
+
url: import_zod10.z.string(),
|
|
2418
|
+
title: import_zod10.z.string()
|
|
2333
2419
|
})
|
|
2334
2420
|
});
|
|
2335
|
-
var openaiResponsesChunkSchema =
|
|
2421
|
+
var openaiResponsesChunkSchema = import_zod10.z.union([
|
|
2336
2422
|
textDeltaChunkSchema,
|
|
2337
2423
|
responseFinishedChunkSchema,
|
|
2338
2424
|
responseCreatedChunkSchema,
|
|
@@ -2340,7 +2426,7 @@ var openaiResponsesChunkSchema = import_zod6.z.union([
|
|
|
2340
2426
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2341
2427
|
responseOutputItemAddedSchema,
|
|
2342
2428
|
responseAnnotationAddedSchema,
|
|
2343
|
-
|
|
2429
|
+
import_zod10.z.object({ type: import_zod10.z.string() }).passthrough()
|
|
2344
2430
|
// fallback for unknown chunks
|
|
2345
2431
|
]);
|
|
2346
2432
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2385,15 +2471,15 @@ function getResponsesModelConfig(modelId) {
|
|
|
2385
2471
|
requiredAutoTruncation: false
|
|
2386
2472
|
};
|
|
2387
2473
|
}
|
|
2388
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2389
|
-
metadata:
|
|
2390
|
-
parallelToolCalls:
|
|
2391
|
-
previousResponseId:
|
|
2392
|
-
store:
|
|
2393
|
-
user:
|
|
2394
|
-
reasoningEffort:
|
|
2395
|
-
strictSchemas:
|
|
2396
|
-
instructions:
|
|
2474
|
+
var openaiResponsesProviderOptionsSchema = import_zod10.z.object({
|
|
2475
|
+
metadata: import_zod10.z.any().nullish(),
|
|
2476
|
+
parallelToolCalls: import_zod10.z.boolean().nullish(),
|
|
2477
|
+
previousResponseId: import_zod10.z.string().nullish(),
|
|
2478
|
+
store: import_zod10.z.boolean().nullish(),
|
|
2479
|
+
user: import_zod10.z.string().nullish(),
|
|
2480
|
+
reasoningEffort: import_zod10.z.string().nullish(),
|
|
2481
|
+
strictSchemas: import_zod10.z.boolean().nullish(),
|
|
2482
|
+
instructions: import_zod10.z.string().nullish()
|
|
2397
2483
|
});
|
|
2398
2484
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2399
2485
|
0 && (module.exports = {
|
|
@@ -2402,6 +2488,10 @@ var openaiResponsesProviderOptionsSchema = import_zod6.z.object({
|
|
|
2402
2488
|
OpenAIEmbeddingModel,
|
|
2403
2489
|
OpenAIImageModel,
|
|
2404
2490
|
OpenAIResponsesLanguageModel,
|
|
2405
|
-
|
|
2491
|
+
OpenAISpeechModel,
|
|
2492
|
+
OpenAITranscriptionModel,
|
|
2493
|
+
modelMaxImagesPerCall,
|
|
2494
|
+
openaiEmbeddingProviderOptions,
|
|
2495
|
+
openaiProviderOptions
|
|
2406
2496
|
});
|
|
2407
2497
|
//# sourceMappingURL=index.js.map
|