@ai-sdk/open-responses 2.0.52 → 2.0.55
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 +25 -0
- package/dist/index.d.ts +97 -40
- package/dist/index.js +255 -160
- package/dist/index.js.map +1 -1
- package/docs/06-open-responses.mdx +55 -4
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/open-responses-extension.ts +299 -67
- package/src/open-responses-provider.ts +2 -2
- package/src/responses/convert-to-open-responses-input.ts +12 -9
- package/src/responses/open-responses-language-model.ts +20 -16
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var VERSION = true ? "2.0.
|
|
2
|
+
var VERSION = true ? "2.0.55" : "0.0.0-test";
|
|
3
3
|
|
|
4
4
|
// src/open-responses-provider.ts
|
|
5
5
|
import {
|
|
@@ -11,6 +11,37 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/open-responses-extension.ts
|
|
14
|
+
var coreToolTypes = /* @__PURE__ */ new Set(["allowed_tools", "function"]);
|
|
15
|
+
var coreItemTypes = /* @__PURE__ */ new Set([
|
|
16
|
+
"function_call",
|
|
17
|
+
"function_call_output",
|
|
18
|
+
"item_reference",
|
|
19
|
+
"message",
|
|
20
|
+
"reasoning"
|
|
21
|
+
]);
|
|
22
|
+
var coreEventTypes = /* @__PURE__ */ new Set([
|
|
23
|
+
"error",
|
|
24
|
+
"response.completed",
|
|
25
|
+
"response.content_part.added",
|
|
26
|
+
"response.content_part.done",
|
|
27
|
+
"response.created",
|
|
28
|
+
"response.failed",
|
|
29
|
+
"response.function_call_arguments.delta",
|
|
30
|
+
"response.function_call_arguments.done",
|
|
31
|
+
"response.in_progress",
|
|
32
|
+
"response.incomplete",
|
|
33
|
+
"response.output_item.added",
|
|
34
|
+
"response.output_item.done",
|
|
35
|
+
"response.output_text.delta",
|
|
36
|
+
"response.output_text.done",
|
|
37
|
+
"response.reasoning_summary_part.added",
|
|
38
|
+
"response.reasoning_summary_part.done",
|
|
39
|
+
"response.reasoning_summary_text.delta",
|
|
40
|
+
"response.reasoning_summary_text.done",
|
|
41
|
+
"response.reasoning_text.delta",
|
|
42
|
+
"response.refusal.delta",
|
|
43
|
+
"response.refusal.done"
|
|
44
|
+
]);
|
|
14
45
|
function createOpenResponsesExtensionRegistry(extensions) {
|
|
15
46
|
const registry = {
|
|
16
47
|
byEventType: /* @__PURE__ */ new Map(),
|
|
@@ -19,7 +50,7 @@ function createOpenResponsesExtensionRegistry(extensions) {
|
|
|
19
50
|
byProviderToolId: /* @__PURE__ */ new Map(),
|
|
20
51
|
byToolType: /* @__PURE__ */ new Map()
|
|
21
52
|
};
|
|
22
|
-
for (const extension of extensions
|
|
53
|
+
for (const extension of extensions ?? []) {
|
|
23
54
|
const namespaceSeparatorIndex = extension.id.indexOf(".");
|
|
24
55
|
if (namespaceSeparatorIndex <= 0) {
|
|
25
56
|
throw new Error(
|
|
@@ -33,26 +64,48 @@ function createOpenResponsesExtensionRegistry(extensions) {
|
|
|
33
64
|
extension,
|
|
34
65
|
field: "id"
|
|
35
66
|
});
|
|
36
|
-
const
|
|
67
|
+
const hasBareTypes = extension.bareToolType != null || extension.bareItemTypes != null || extension.bareEventTypes != null;
|
|
68
|
+
if (hasBareTypes !== (extension.allowBareTypes === true)) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Open Responses extension ${extension.id} must set allowBareTypes to true exactly when registering bare types.`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (extension.toolType != null && extension.bareToolType != null) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Open Responses extension ${extension.id} cannot provide toolType and bareToolType together.`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const toolType = extension.toolType ?? extension.bareToolType;
|
|
79
|
+
const hasToolType = toolType != null;
|
|
37
80
|
const hasToolEncoder = extension.encodeTool != null;
|
|
38
81
|
if (hasToolType !== hasToolEncoder) {
|
|
82
|
+
const typeField = extension.bareToolType != null ? "bareToolType" : "toolType";
|
|
39
83
|
throw new Error(
|
|
40
|
-
`Open Responses extension ${extension.id} must provide
|
|
84
|
+
`Open Responses extension ${extension.id} must provide ${typeField} and encodeTool together.`
|
|
41
85
|
);
|
|
42
86
|
}
|
|
43
87
|
if (extension.encodeToolChoice != null && !hasToolEncoder) {
|
|
44
88
|
throw new Error(
|
|
45
|
-
`Open Responses extension ${extension.id} cannot provide encodeToolChoice without
|
|
89
|
+
`Open Responses extension ${extension.id} cannot provide encodeToolChoice without a tool type and encodeTool.`
|
|
46
90
|
);
|
|
47
91
|
}
|
|
48
92
|
if (hasToolType && hasToolEncoder) {
|
|
49
93
|
const toolExtension = extension;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
94
|
+
if (extension.toolType != null) {
|
|
95
|
+
assertNamespacedType({
|
|
96
|
+
extensionId: extension.id,
|
|
97
|
+
namespace,
|
|
98
|
+
type: extension.toolType,
|
|
99
|
+
field: "toolType"
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
assertBareType({
|
|
103
|
+
coreTypes: coreToolTypes,
|
|
104
|
+
extensionId: extension.id,
|
|
105
|
+
type: extension.bareToolType,
|
|
106
|
+
field: "bareToolType"
|
|
107
|
+
});
|
|
108
|
+
}
|
|
56
109
|
registerUnique({
|
|
57
110
|
map: registry.byProviderToolId,
|
|
58
111
|
key: extension.id,
|
|
@@ -61,31 +114,35 @@ function createOpenResponsesExtensionRegistry(extensions) {
|
|
|
61
114
|
});
|
|
62
115
|
registerUnique({
|
|
63
116
|
map: registry.byToolType,
|
|
64
|
-
key:
|
|
117
|
+
key: toolType,
|
|
65
118
|
extension: toolExtension,
|
|
66
|
-
field: "
|
|
119
|
+
field: "tool type"
|
|
67
120
|
});
|
|
68
121
|
}
|
|
69
|
-
const
|
|
122
|
+
const itemTypes = [
|
|
123
|
+
...extension.itemTypes ?? [],
|
|
124
|
+
...extension.bareItemTypes ?? []
|
|
125
|
+
];
|
|
126
|
+
const hasItemTypes = extension.itemTypes != null || extension.bareItemTypes != null;
|
|
70
127
|
const hasItemDecoder = extension.decodeItem != null;
|
|
71
128
|
if (hasItemTypes !== hasItemDecoder) {
|
|
72
129
|
throw new Error(
|
|
73
|
-
`Open Responses extension ${extension.id} must provide itemTypes
|
|
130
|
+
`Open Responses extension ${extension.id} must provide itemTypes or bareItemTypes together with decodeItem.`
|
|
74
131
|
);
|
|
75
132
|
}
|
|
76
133
|
if (extension.encodeInputItem != null && !hasItemDecoder) {
|
|
77
134
|
throw new Error(
|
|
78
|
-
`Open Responses extension ${extension.id} cannot provide encodeInputItem without itemTypes and decodeItem.`
|
|
135
|
+
`Open Responses extension ${extension.id} cannot provide encodeInputItem without itemTypes or bareItemTypes and decodeItem.`
|
|
79
136
|
);
|
|
80
137
|
}
|
|
81
138
|
if (hasItemTypes && hasItemDecoder) {
|
|
82
139
|
const itemExtension = extension;
|
|
83
|
-
if (
|
|
140
|
+
if (itemTypes.length === 0) {
|
|
84
141
|
throw new Error(
|
|
85
142
|
`Open Responses extension ${extension.id} must register at least one item type.`
|
|
86
143
|
);
|
|
87
144
|
}
|
|
88
|
-
for (const itemType of
|
|
145
|
+
for (const itemType of extension.itemTypes ?? []) {
|
|
89
146
|
assertNamespacedType({
|
|
90
147
|
extensionId: extension.id,
|
|
91
148
|
namespace,
|
|
@@ -99,22 +156,40 @@ function createOpenResponsesExtensionRegistry(extensions) {
|
|
|
99
156
|
field: "item type"
|
|
100
157
|
});
|
|
101
158
|
}
|
|
159
|
+
for (const itemType of extension.bareItemTypes ?? []) {
|
|
160
|
+
assertBareType({
|
|
161
|
+
coreTypes: coreItemTypes,
|
|
162
|
+
extensionId: extension.id,
|
|
163
|
+
type: itemType,
|
|
164
|
+
field: "bareItemTypes"
|
|
165
|
+
});
|
|
166
|
+
registerUnique({
|
|
167
|
+
map: registry.byItemType,
|
|
168
|
+
key: itemType,
|
|
169
|
+
extension: itemExtension,
|
|
170
|
+
field: "item type"
|
|
171
|
+
});
|
|
172
|
+
}
|
|
102
173
|
}
|
|
103
|
-
const
|
|
174
|
+
const eventTypes = [
|
|
175
|
+
...extension.eventTypes ?? [],
|
|
176
|
+
...extension.bareEventTypes ?? []
|
|
177
|
+
];
|
|
178
|
+
const hasEventTypes = extension.eventTypes != null || extension.bareEventTypes != null;
|
|
104
179
|
const hasEventDecoder = extension.decodeEvent != null;
|
|
105
180
|
if (hasEventTypes !== hasEventDecoder) {
|
|
106
181
|
throw new Error(
|
|
107
|
-
`Open Responses extension ${extension.id} must provide eventTypes
|
|
182
|
+
`Open Responses extension ${extension.id} must provide eventTypes or bareEventTypes together with decodeEvent.`
|
|
108
183
|
);
|
|
109
184
|
}
|
|
110
185
|
if (hasEventTypes && hasEventDecoder) {
|
|
111
186
|
const eventExtension = extension;
|
|
112
|
-
if (
|
|
187
|
+
if (eventTypes.length === 0) {
|
|
113
188
|
throw new Error(
|
|
114
189
|
`Open Responses extension ${extension.id} must register at least one event type.`
|
|
115
190
|
);
|
|
116
191
|
}
|
|
117
|
-
for (const eventType of
|
|
192
|
+
for (const eventType of extension.eventTypes ?? []) {
|
|
118
193
|
assertNamespacedType({
|
|
119
194
|
extensionId: extension.id,
|
|
120
195
|
namespace,
|
|
@@ -128,6 +203,20 @@ function createOpenResponsesExtensionRegistry(extensions) {
|
|
|
128
203
|
field: "event type"
|
|
129
204
|
});
|
|
130
205
|
}
|
|
206
|
+
for (const eventType of extension.bareEventTypes ?? []) {
|
|
207
|
+
assertBareType({
|
|
208
|
+
coreTypes: coreEventTypes,
|
|
209
|
+
extensionId: extension.id,
|
|
210
|
+
type: eventType,
|
|
211
|
+
field: "bareEventTypes"
|
|
212
|
+
});
|
|
213
|
+
registerUnique({
|
|
214
|
+
map: registry.byEventType,
|
|
215
|
+
key: eventType,
|
|
216
|
+
extension: eventExtension,
|
|
217
|
+
field: "event type"
|
|
218
|
+
});
|
|
219
|
+
}
|
|
131
220
|
}
|
|
132
221
|
if (!hasToolEncoder && !hasItemDecoder && !hasEventDecoder) {
|
|
133
222
|
throw new Error(
|
|
@@ -143,12 +232,39 @@ function assertNamespacedType({
|
|
|
143
232
|
type,
|
|
144
233
|
field
|
|
145
234
|
}) {
|
|
146
|
-
|
|
235
|
+
const separatorIndex = type.indexOf(":");
|
|
236
|
+
if (separatorIndex <= 0 || type.slice(0, separatorIndex) !== namespace) {
|
|
147
237
|
throw new Error(
|
|
148
238
|
`Open Responses extension ${extensionId} has invalid ${field} value ${type}. Extension wire types must use the ${namespace}: namespace.`
|
|
149
239
|
);
|
|
150
240
|
}
|
|
151
241
|
}
|
|
242
|
+
function assertBareType({
|
|
243
|
+
coreTypes,
|
|
244
|
+
extensionId,
|
|
245
|
+
type,
|
|
246
|
+
field
|
|
247
|
+
}) {
|
|
248
|
+
if (type.length === 0 || type.includes(":")) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
`Open Responses extension ${extensionId} has invalid ${field} value ${type}. Bare extension wire types must be non-empty and must not contain a colon.`
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
if (coreTypes.has(type)) {
|
|
254
|
+
throw new Error(
|
|
255
|
+
`Open Responses extension ${extensionId} cannot register core ${field} value ${type}.`
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function getOpenResponsesExtensionItemTypes(extension) {
|
|
260
|
+
return [...extension.itemTypes ?? [], ...extension.bareItemTypes ?? []];
|
|
261
|
+
}
|
|
262
|
+
function getOpenResponsesExtensionToolType(extension) {
|
|
263
|
+
return extension.toolType ?? extension.bareToolType;
|
|
264
|
+
}
|
|
265
|
+
function asOpenResponsesExtensionRecord(value) {
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
152
268
|
function registerUnique({
|
|
153
269
|
map,
|
|
154
270
|
key,
|
|
@@ -163,11 +279,8 @@ function registerUnique({
|
|
|
163
279
|
}
|
|
164
280
|
map.set(key, extension);
|
|
165
281
|
}
|
|
166
|
-
function isOpenResponsesNamespacedType(value) {
|
|
167
|
-
return typeof value === "string" && value.includes(":");
|
|
168
|
-
}
|
|
169
282
|
function isOpenResponsesExtensionRecord(value) {
|
|
170
|
-
return isOpenResponsesJSONObject(value) &&
|
|
283
|
+
return isOpenResponsesJSONObject(value) && typeof value.type === "string";
|
|
171
284
|
}
|
|
172
285
|
function isOpenResponsesJSONObject(value) {
|
|
173
286
|
return value != null && typeof value === "object" && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype && Object.values(value).every(isOpenResponsesJSONValue);
|
|
@@ -251,7 +364,6 @@ async function convertToOpenResponsesInput({
|
|
|
251
364
|
strictResponseInput = false,
|
|
252
365
|
customToolId
|
|
253
366
|
}) {
|
|
254
|
-
var _a, _b, _c, _d;
|
|
255
367
|
const input = [];
|
|
256
368
|
const warnings = [];
|
|
257
369
|
const systemMessages = [];
|
|
@@ -302,7 +414,7 @@ async function convertToOpenResponsesInput({
|
|
|
302
414
|
const fullMediaType = resolveFullMediaType({ part });
|
|
303
415
|
userContent.push({
|
|
304
416
|
type: "input_file",
|
|
305
|
-
filename:
|
|
417
|
+
filename: part.filename ?? "data",
|
|
306
418
|
file_data: `data:${fullMediaType};base64,${convertToBase64(part.data.data)}`
|
|
307
419
|
});
|
|
308
420
|
}
|
|
@@ -338,14 +450,11 @@ async function convertToOpenResponsesInput({
|
|
|
338
450
|
status: "completed",
|
|
339
451
|
role: "assistant",
|
|
340
452
|
content: assistantContent.map(
|
|
341
|
-
(part) => {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
logprobs: (_b2 = part.logprobs) != null ? _b2 : []
|
|
347
|
-
} : part;
|
|
348
|
-
}
|
|
453
|
+
(part) => part.type === "output_text" ? {
|
|
454
|
+
...part,
|
|
455
|
+
annotations: part.annotations ?? [],
|
|
456
|
+
logprobs: part.logprobs ?? []
|
|
457
|
+
} : part
|
|
349
458
|
)
|
|
350
459
|
});
|
|
351
460
|
} else {
|
|
@@ -371,7 +480,7 @@ async function convertToOpenResponsesInput({
|
|
|
371
480
|
if (replayItem != null) {
|
|
372
481
|
const replayKey = `${replayItem.type}:${replayItem.id}`;
|
|
373
482
|
if (!replayedExtensionItems.has(replayKey)) {
|
|
374
|
-
input.push(replayItem);
|
|
483
|
+
input.push(asOpenResponsesExtensionRecord(replayItem));
|
|
375
484
|
replayedExtensionItems.add(replayKey);
|
|
376
485
|
}
|
|
377
486
|
}
|
|
@@ -379,7 +488,7 @@ async function convertToOpenResponsesInput({
|
|
|
379
488
|
}
|
|
380
489
|
if (part.type === "tool-call" || part.type === "tool-result") {
|
|
381
490
|
const providerTool = providerToolsByName.get(part.toolName);
|
|
382
|
-
const extension = providerTool == null ? void 0 : extensionRegistry
|
|
491
|
+
const extension = providerTool == null ? void 0 : extensionRegistry?.byProviderToolId.get(providerTool.id);
|
|
383
492
|
if (providerTool != null && extension != null) {
|
|
384
493
|
flushAssistantContent();
|
|
385
494
|
const encoded = await encodeExtensionInputPart({
|
|
@@ -393,7 +502,7 @@ async function convertToOpenResponsesInput({
|
|
|
393
502
|
feature: `provider-defined tool ${providerTool.id} ${part.type} history`
|
|
394
503
|
});
|
|
395
504
|
} else {
|
|
396
|
-
input.push(...encoded);
|
|
505
|
+
input.push(...encoded.map(asOpenResponsesExtensionRecord));
|
|
397
506
|
}
|
|
398
507
|
continue;
|
|
399
508
|
}
|
|
@@ -402,18 +511,18 @@ async function convertToOpenResponsesInput({
|
|
|
402
511
|
case "reasoning": {
|
|
403
512
|
flushAssistantContent();
|
|
404
513
|
const providerData = getProviderData(part, providerOptionsName);
|
|
405
|
-
const itemId = typeof
|
|
514
|
+
const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
|
|
406
515
|
const summary = parseReasoningSummary(
|
|
407
|
-
providerData
|
|
516
|
+
providerData?.reasoningSummary
|
|
408
517
|
);
|
|
409
518
|
const reasoningContent = parseReasoningContent(
|
|
410
|
-
providerData
|
|
519
|
+
providerData?.reasoningContent
|
|
411
520
|
);
|
|
412
521
|
const hasReasoningContent = providerData != null && "reasoningContent" in providerData;
|
|
413
|
-
const encryptedContent = typeof
|
|
522
|
+
const encryptedContent = typeof providerData?.reasoningEncryptedContent === "string" ? providerData.reasoningEncryptedContent : void 0;
|
|
414
523
|
const reasoningItem = {
|
|
415
524
|
type: "reasoning",
|
|
416
|
-
summary: summary
|
|
525
|
+
summary: summary ?? [],
|
|
417
526
|
...itemId != null && { id: itemId },
|
|
418
527
|
...reasoningContent != null ? { content: reasoningContent } : !hasReasoningContent && part.text.length > 0 ? {
|
|
419
528
|
content: [
|
|
@@ -428,10 +537,10 @@ async function convertToOpenResponsesInput({
|
|
|
428
537
|
}
|
|
429
538
|
};
|
|
430
539
|
const previousItem = input[input.length - 1];
|
|
431
|
-
if (reasoningItem.id != null &&
|
|
540
|
+
if (reasoningItem.id != null && previousItem?.type === "reasoning" && previousItem.id === reasoningItem.id) {
|
|
432
541
|
if (reasoningItem.content != null) {
|
|
433
542
|
previousItem.content = [
|
|
434
|
-
...
|
|
543
|
+
...previousItem.content ?? [],
|
|
435
544
|
...reasoningItem.content
|
|
436
545
|
];
|
|
437
546
|
}
|
|
@@ -442,9 +551,9 @@ async function convertToOpenResponsesInput({
|
|
|
442
551
|
}
|
|
443
552
|
case "text": {
|
|
444
553
|
const providerData = getProviderData(part, providerOptionsName);
|
|
445
|
-
const itemId = typeof
|
|
554
|
+
const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
|
|
446
555
|
const annotations = parseOutputTextAnnotations(
|
|
447
|
-
providerData
|
|
556
|
+
providerData?.annotations
|
|
448
557
|
);
|
|
449
558
|
if (assistantContent.length > 0 && assistantMessageId !== itemId) {
|
|
450
559
|
flushAssistantContent();
|
|
@@ -461,9 +570,9 @@ async function convertToOpenResponsesInput({
|
|
|
461
570
|
flushAssistantContent();
|
|
462
571
|
const argumentsValue = typeof part.input === "string" ? part.input : JSON.stringify(part.input);
|
|
463
572
|
const providerData = getProviderData(part, providerOptionsName);
|
|
464
|
-
const itemId = typeof
|
|
573
|
+
const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
|
|
465
574
|
const providerTool = providerToolsByName.get(part.toolName);
|
|
466
|
-
if (customToolId != null &&
|
|
575
|
+
if (customToolId != null && providerTool?.id === customToolId) {
|
|
467
576
|
input.push({
|
|
468
577
|
type: "custom_tool_call",
|
|
469
578
|
...itemId != null && { id: itemId },
|
|
@@ -500,14 +609,14 @@ async function convertToOpenResponsesInput({
|
|
|
500
609
|
if (replayItem != null) {
|
|
501
610
|
const replayKey = `${replayItem.type}:${replayItem.id}`;
|
|
502
611
|
if (!replayedExtensionItems.has(replayKey)) {
|
|
503
|
-
input.push(replayItem);
|
|
612
|
+
input.push(asOpenResponsesExtensionRecord(replayItem));
|
|
504
613
|
replayedExtensionItems.add(replayKey);
|
|
505
614
|
}
|
|
506
615
|
}
|
|
507
616
|
continue;
|
|
508
617
|
}
|
|
509
618
|
const providerTool = providerToolsByName.get(part.toolName);
|
|
510
|
-
const extension = providerTool == null ? void 0 : extensionRegistry
|
|
619
|
+
const extension = providerTool == null ? void 0 : extensionRegistry?.byProviderToolId.get(providerTool.id);
|
|
511
620
|
if (providerTool != null && extension != null) {
|
|
512
621
|
const encoded = await encodeExtensionInputPart({
|
|
513
622
|
extensionRegistry,
|
|
@@ -520,7 +629,7 @@ async function convertToOpenResponsesInput({
|
|
|
520
629
|
feature: `provider-defined tool ${providerTool.id} tool-result history`
|
|
521
630
|
});
|
|
522
631
|
} else {
|
|
523
|
-
input.push(...encoded);
|
|
632
|
+
input.push(...encoded.map(asOpenResponsesExtensionRecord));
|
|
524
633
|
}
|
|
525
634
|
continue;
|
|
526
635
|
}
|
|
@@ -532,7 +641,7 @@ async function convertToOpenResponsesInput({
|
|
|
532
641
|
contentValue = output.value;
|
|
533
642
|
break;
|
|
534
643
|
case "execution-denied":
|
|
535
|
-
contentValue =
|
|
644
|
+
contentValue = output.reason ?? "Tool call execution denied.";
|
|
536
645
|
break;
|
|
537
646
|
case "json":
|
|
538
647
|
case "error-json":
|
|
@@ -564,7 +673,7 @@ async function convertToOpenResponsesInput({
|
|
|
564
673
|
} else {
|
|
565
674
|
contentParts.push({
|
|
566
675
|
type: "input_file",
|
|
567
|
-
filename:
|
|
676
|
+
filename: item.filename ?? "data",
|
|
568
677
|
file_data: `data:${fullMediaType};base64,${convertToBase64(item.data.data)}`
|
|
569
678
|
});
|
|
570
679
|
}
|
|
@@ -603,7 +712,7 @@ async function convertToOpenResponsesInput({
|
|
|
603
712
|
}
|
|
604
713
|
}
|
|
605
714
|
input.push({
|
|
606
|
-
type: customToolId != null &&
|
|
715
|
+
type: customToolId != null && providerTool?.id === customToolId ? "custom_tool_call_output" : "function_call_output",
|
|
607
716
|
call_id: part.toolCallId,
|
|
608
717
|
output: contentValue
|
|
609
718
|
});
|
|
@@ -624,10 +733,10 @@ async function encodeExtensionInputPart({
|
|
|
624
733
|
part,
|
|
625
734
|
providerTool
|
|
626
735
|
}) {
|
|
627
|
-
const extension = extensionRegistry
|
|
628
|
-
const encodeInputItem = extension
|
|
629
|
-
const itemTypes = extension == null ?
|
|
630
|
-
if (encodeInputItem == null || itemTypes
|
|
736
|
+
const extension = extensionRegistry?.byProviderToolId.get(providerTool.id);
|
|
737
|
+
const encodeInputItem = extension?.encodeInputItem;
|
|
738
|
+
const itemTypes = extension == null ? [] : getOpenResponsesExtensionItemTypes(extension);
|
|
739
|
+
if (encodeInputItem == null || itemTypes.length === 0) {
|
|
631
740
|
return void 0;
|
|
632
741
|
}
|
|
633
742
|
try {
|
|
@@ -642,7 +751,7 @@ async function encodeExtensionInputPart({
|
|
|
642
751
|
return void 0;
|
|
643
752
|
}
|
|
644
753
|
return items;
|
|
645
|
-
} catch
|
|
754
|
+
} catch {
|
|
646
755
|
return void 0;
|
|
647
756
|
}
|
|
648
757
|
}
|
|
@@ -651,11 +760,10 @@ function getExtensionReplay({
|
|
|
651
760
|
providerOptionsName,
|
|
652
761
|
extensionRegistry
|
|
653
762
|
}) {
|
|
654
|
-
|
|
655
|
-
const extensionData = (_a = getProviderData(
|
|
763
|
+
const extensionData = getProviderData(
|
|
656
764
|
part,
|
|
657
765
|
providerOptionsName
|
|
658
|
-
)
|
|
766
|
+
)?.openResponsesExtension;
|
|
659
767
|
if (extensionData == null || typeof extensionData !== "object" || Array.isArray(extensionData)) {
|
|
660
768
|
return void 0;
|
|
661
769
|
}
|
|
@@ -663,25 +771,23 @@ function getExtensionReplay({
|
|
|
663
771
|
if (typeof id !== "string") {
|
|
664
772
|
return void 0;
|
|
665
773
|
}
|
|
666
|
-
const extension = extensionRegistry
|
|
774
|
+
const extension = extensionRegistry?.byExtensionId.get(
|
|
667
775
|
id
|
|
668
776
|
);
|
|
669
777
|
if (extension == null) {
|
|
670
778
|
return void 0;
|
|
671
779
|
}
|
|
672
|
-
if (isOpenResponsesExtensionItem(item) && (
|
|
780
|
+
if (isOpenResponsesExtensionItem(item) && getOpenResponsesExtensionItemTypes(extension).includes(item.type)) {
|
|
673
781
|
return { item };
|
|
674
782
|
}
|
|
675
783
|
return typeof itemId === "string" ? {} : void 0;
|
|
676
784
|
}
|
|
677
785
|
function getProviderData(part, providerOptionsName) {
|
|
678
|
-
|
|
679
|
-
const providerData = (_c = (_a = part.providerOptions) == null ? void 0 : _a[providerOptionsName]) != null ? _c : (_b = part.providerMetadata) == null ? void 0 : _b[providerOptionsName];
|
|
786
|
+
const providerData = part.providerOptions?.[providerOptionsName] ?? part.providerMetadata?.[providerOptionsName];
|
|
680
787
|
return providerData != null && typeof providerData === "object" && !Array.isArray(providerData) ? providerData : void 0;
|
|
681
788
|
}
|
|
682
789
|
function getImageDetail(part, providerOptionsName) {
|
|
683
|
-
|
|
684
|
-
const imageDetail = (_a = getProviderData(part, providerOptionsName)) == null ? void 0 : _a.imageDetail;
|
|
790
|
+
const imageDetail = getProviderData(part, providerOptionsName)?.imageDetail;
|
|
685
791
|
return imageDetail === "low" || imageDetail === "high" || imageDetail === "auto" ? imageDetail : "auto";
|
|
686
792
|
}
|
|
687
793
|
function parseReasoningSummary(value) {
|
|
@@ -789,10 +895,9 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
789
895
|
this.supportedUrls = {
|
|
790
896
|
"image/*": [/^https?:\/\/.*$/]
|
|
791
897
|
};
|
|
792
|
-
var _a;
|
|
793
898
|
this.modelId = modelId;
|
|
794
899
|
this.config = config;
|
|
795
|
-
this.extensionRegistry =
|
|
900
|
+
this.extensionRegistry = config.extensionRegistry ?? createOpenResponsesExtensionRegistry();
|
|
796
901
|
}
|
|
797
902
|
static [WORKFLOW_SERIALIZE](model) {
|
|
798
903
|
if (model.extensionRegistry.byExtensionId.size > 0) {
|
|
@@ -827,7 +932,6 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
827
932
|
toolChoice,
|
|
828
933
|
responseFormat
|
|
829
934
|
}) {
|
|
830
|
-
var _a, _b, _c;
|
|
831
935
|
const warnings = [];
|
|
832
936
|
if (stopSequences != null) {
|
|
833
937
|
warnings.push({ type: "unsupported", feature: "stopSequences" });
|
|
@@ -839,7 +943,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
839
943
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
840
944
|
}
|
|
841
945
|
const providerToolsByName = new Map(
|
|
842
|
-
(tools
|
|
946
|
+
(tools ?? []).filter((tool) => tool.type === "provider").map((tool) => [tool.name, tool])
|
|
843
947
|
);
|
|
844
948
|
const {
|
|
845
949
|
input,
|
|
@@ -856,7 +960,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
856
960
|
warnings.push(...inputWarnings);
|
|
857
961
|
const convertedTools = [];
|
|
858
962
|
const encodedProviderToolsByName = /* @__PURE__ */ new Map();
|
|
859
|
-
for (const tool of tools
|
|
963
|
+
for (const tool of tools ?? []) {
|
|
860
964
|
if (tool.type === "provider") {
|
|
861
965
|
if (this.config.customToolId != null && tool.id === this.config.customToolId) {
|
|
862
966
|
const format = tool.args.format != null && typeof tool.args.format === "object" && !Array.isArray(tool.args.format) ? tool.args.format : void 0;
|
|
@@ -875,6 +979,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
875
979
|
const extension = this.extensionRegistry.byProviderToolId.get(tool.id);
|
|
876
980
|
let encoded;
|
|
877
981
|
if (extension != null) {
|
|
982
|
+
const toolType = getOpenResponsesExtensionToolType(extension);
|
|
878
983
|
try {
|
|
879
984
|
const fields = await extension.encodeTool({
|
|
880
985
|
name: tool.name,
|
|
@@ -883,10 +988,10 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
883
988
|
if (isOpenResponsesJSONObject(fields)) {
|
|
884
989
|
encoded = {
|
|
885
990
|
...fields,
|
|
886
|
-
type:
|
|
991
|
+
type: toolType
|
|
887
992
|
};
|
|
888
993
|
}
|
|
889
|
-
} catch
|
|
994
|
+
} catch {
|
|
890
995
|
}
|
|
891
996
|
}
|
|
892
997
|
if (encoded == null) {
|
|
@@ -895,9 +1000,9 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
895
1000
|
feature: `provider-defined tool ${tool.id}`
|
|
896
1001
|
});
|
|
897
1002
|
} else if (extension != null) {
|
|
898
|
-
convertedTools.push(encoded);
|
|
1003
|
+
convertedTools.push(asOpenResponsesExtensionRecord(encoded));
|
|
899
1004
|
encodedProviderToolsByName.set(tool.name, {
|
|
900
|
-
toolType: extension
|
|
1005
|
+
toolType: getOpenResponsesExtensionToolType(extension),
|
|
901
1006
|
encodeToolChoice: extension.encodeToolChoice,
|
|
902
1007
|
tool
|
|
903
1008
|
});
|
|
@@ -913,12 +1018,12 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
913
1018
|
}
|
|
914
1019
|
}
|
|
915
1020
|
let convertedToolChoice;
|
|
916
|
-
if (
|
|
1021
|
+
if (toolChoice?.type === "tool") {
|
|
917
1022
|
const registeredTool = encodedProviderToolsByName.get(
|
|
918
1023
|
toolChoice.toolName
|
|
919
1024
|
);
|
|
920
1025
|
if (registeredTool == null) {
|
|
921
|
-
if (this.config.customToolId != null &&
|
|
1026
|
+
if (this.config.customToolId != null && providerToolsByName.get(toolChoice.toolName)?.id === this.config.customToolId) {
|
|
922
1027
|
convertedToolChoice = {
|
|
923
1028
|
type: "custom",
|
|
924
1029
|
name: toolChoice.toolName
|
|
@@ -933,11 +1038,11 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
933
1038
|
const { encodeToolChoice, tool, toolType } = registeredTool;
|
|
934
1039
|
let fields = {};
|
|
935
1040
|
try {
|
|
936
|
-
fields = await
|
|
1041
|
+
fields = await encodeToolChoice?.({
|
|
937
1042
|
name: tool.name,
|
|
938
1043
|
args: tool.args
|
|
939
|
-
})
|
|
940
|
-
} catch
|
|
1044
|
+
});
|
|
1045
|
+
} catch {
|
|
941
1046
|
fields = void 0;
|
|
942
1047
|
}
|
|
943
1048
|
if (encodeToolChoice != null && !isOpenResponsesJSONObject(fields)) {
|
|
@@ -946,23 +1051,23 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
946
1051
|
feature: `tool choice for provider-defined tool ${tool.id}`
|
|
947
1052
|
});
|
|
948
1053
|
} else {
|
|
949
|
-
convertedToolChoice = {
|
|
1054
|
+
convertedToolChoice = asOpenResponsesExtensionRecord({
|
|
950
1055
|
...isOpenResponsesJSONObject(fields) ? fields : {},
|
|
951
1056
|
type: toolType
|
|
952
|
-
};
|
|
1057
|
+
});
|
|
953
1058
|
}
|
|
954
1059
|
}
|
|
955
1060
|
} else {
|
|
956
|
-
convertedToolChoice = toolChoice
|
|
1061
|
+
convertedToolChoice = toolChoice?.type;
|
|
957
1062
|
}
|
|
958
|
-
const textFormat =
|
|
1063
|
+
const textFormat = responseFormat?.type === "json" && this.config.structuredOutputs !== false ? responseFormat.schema != null ? {
|
|
959
1064
|
type: "json_schema",
|
|
960
|
-
name:
|
|
1065
|
+
name: responseFormat.name ?? "response",
|
|
961
1066
|
description: responseFormat.description,
|
|
962
1067
|
schema: responseFormat.schema,
|
|
963
1068
|
strict: true
|
|
964
1069
|
} : { type: "json_object" } : void 0;
|
|
965
|
-
if (
|
|
1070
|
+
if (responseFormat?.type === "json" && this.config.structuredOutputs === false) {
|
|
966
1071
|
warnings.push({ type: "unsupported", feature: "responseFormat" });
|
|
967
1072
|
}
|
|
968
1073
|
const openResponsesOptions = await parseProviderOptions({
|
|
@@ -970,7 +1075,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
970
1075
|
providerOptions,
|
|
971
1076
|
schema: openResponsesLanguageModelOptions
|
|
972
1077
|
});
|
|
973
|
-
const resolvedReasoningEffort =
|
|
1078
|
+
const resolvedReasoningEffort = openResponsesOptions?.reasoningEffort ?? (isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
|
|
974
1079
|
reasoning,
|
|
975
1080
|
effortMap: {
|
|
976
1081
|
minimal: "low",
|
|
@@ -980,7 +1085,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
980
1085
|
xhigh: "xhigh"
|
|
981
1086
|
},
|
|
982
1087
|
warnings
|
|
983
|
-
}) : void 0;
|
|
1088
|
+
}) : void 0);
|
|
984
1089
|
return {
|
|
985
1090
|
body: {
|
|
986
1091
|
model: this.modelId,
|
|
@@ -991,11 +1096,11 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
991
1096
|
top_p: topP,
|
|
992
1097
|
presence_penalty: presencePenalty,
|
|
993
1098
|
frequency_penalty: frequencyPenalty,
|
|
994
|
-
reasoning: resolvedReasoningEffort != null ||
|
|
1099
|
+
reasoning: resolvedReasoningEffort != null || openResponsesOptions?.reasoningSummary != null ? {
|
|
995
1100
|
...resolvedReasoningEffort != null && {
|
|
996
1101
|
effort: resolvedReasoningEffort
|
|
997
1102
|
},
|
|
998
|
-
...
|
|
1103
|
+
...openResponsesOptions?.reasoningSummary != null && {
|
|
999
1104
|
summary: openResponsesOptions.reasoningSummary
|
|
1000
1105
|
}
|
|
1001
1106
|
} : void 0,
|
|
@@ -1007,7 +1112,6 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1007
1112
|
};
|
|
1008
1113
|
}
|
|
1009
1114
|
async doGenerate(options) {
|
|
1010
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1011
1115
|
const { body, warnings } = await this.getArgs(options);
|
|
1012
1116
|
const {
|
|
1013
1117
|
responseHeaders,
|
|
@@ -1015,9 +1119,9 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1015
1119
|
rawValue: rawResponse
|
|
1016
1120
|
} = await postJsonToApi({
|
|
1017
1121
|
url: this.config.url,
|
|
1018
|
-
headers: combineHeaders(
|
|
1122
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
1019
1123
|
body,
|
|
1020
|
-
failedResponseHandler:
|
|
1124
|
+
failedResponseHandler: this.config.failedResponseHandler ?? defaultFailedResponseHandler,
|
|
1021
1125
|
successfulResponseHandler: createJsonResponseHandler(
|
|
1022
1126
|
// do not validate the response body, only apply types to the response body
|
|
1023
1127
|
jsonSchema(() => {
|
|
@@ -1028,23 +1132,22 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1028
1132
|
fetch: this.config.fetch
|
|
1029
1133
|
});
|
|
1030
1134
|
if (response.error) {
|
|
1031
|
-
const errorMetadata =
|
|
1032
|
-
_d,
|
|
1135
|
+
const errorMetadata = this.config.getResponseErrorMetadata?.(
|
|
1033
1136
|
response.error
|
|
1034
1137
|
);
|
|
1035
1138
|
throw new APICallError({
|
|
1036
1139
|
message: response.error.message,
|
|
1037
1140
|
url: this.config.url,
|
|
1038
1141
|
requestBodyValues: body,
|
|
1039
|
-
statusCode:
|
|
1040
|
-
isRetryable: errorMetadata
|
|
1142
|
+
statusCode: errorMetadata?.statusCode ?? 400,
|
|
1143
|
+
isRetryable: errorMetadata?.isRetryable,
|
|
1041
1144
|
responseHeaders,
|
|
1042
1145
|
responseBody: rawResponse,
|
|
1043
1146
|
data: response.error
|
|
1044
1147
|
});
|
|
1045
1148
|
}
|
|
1046
1149
|
if (response.output == null) {
|
|
1047
|
-
const detail =
|
|
1150
|
+
const detail = response.incomplete_details?.reason ?? response.status;
|
|
1048
1151
|
throw new APICallError({
|
|
1049
1152
|
message: detail ? `Responses API returned no output (${detail})` : "Responses API returned no output",
|
|
1050
1153
|
url: this.config.url,
|
|
@@ -1061,7 +1164,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1061
1164
|
switch (part.type) {
|
|
1062
1165
|
// TODO AI SDK 7 adjust reasoning in the specification to better support the reasoning structure from open responses.
|
|
1063
1166
|
case "reasoning": {
|
|
1064
|
-
if ((
|
|
1167
|
+
if ((part.content?.length ?? 0) > 0) {
|
|
1065
1168
|
for (const contentPart of part.content) {
|
|
1066
1169
|
content.push({
|
|
1067
1170
|
type: "reasoning",
|
|
@@ -1139,37 +1242,37 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1139
1242
|
});
|
|
1140
1243
|
if (decoded != null) {
|
|
1141
1244
|
content.push(...decoded);
|
|
1142
|
-
hasToolCalls
|
|
1245
|
+
hasToolCalls ||= decoded.some((part2) => part2.type === "tool-call");
|
|
1143
1246
|
}
|
|
1144
1247
|
break;
|
|
1145
1248
|
}
|
|
1146
1249
|
}
|
|
1147
1250
|
}
|
|
1148
1251
|
const usage = response.usage;
|
|
1149
|
-
const inputTokens = usage
|
|
1150
|
-
const cachedInputTokens =
|
|
1151
|
-
const cacheWriteTokens =
|
|
1152
|
-
const outputTokens = usage
|
|
1153
|
-
const reasoningTokens =
|
|
1252
|
+
const inputTokens = usage?.input_tokens;
|
|
1253
|
+
const cachedInputTokens = usage?.input_tokens_details?.cached_tokens;
|
|
1254
|
+
const cacheWriteTokens = usage?.input_tokens_details?.cache_write_tokens;
|
|
1255
|
+
const outputTokens = usage?.output_tokens;
|
|
1256
|
+
const reasoningTokens = usage?.output_tokens_details?.reasoning_tokens;
|
|
1154
1257
|
return {
|
|
1155
1258
|
content,
|
|
1156
1259
|
finishReason: {
|
|
1157
1260
|
unified: mapOpenResponsesFinishReason({
|
|
1158
|
-
finishReason:
|
|
1261
|
+
finishReason: response.incomplete_details?.reason,
|
|
1159
1262
|
hasToolCalls
|
|
1160
1263
|
}),
|
|
1161
|
-
raw:
|
|
1264
|
+
raw: response.incomplete_details?.reason ?? void 0
|
|
1162
1265
|
},
|
|
1163
1266
|
usage: {
|
|
1164
1267
|
inputTokens: {
|
|
1165
1268
|
total: inputTokens,
|
|
1166
|
-
noCache: (inputTokens
|
|
1269
|
+
noCache: (inputTokens ?? 0) - (cachedInputTokens ?? 0) - (cacheWriteTokens ?? 0),
|
|
1167
1270
|
cacheRead: cachedInputTokens,
|
|
1168
1271
|
cacheWrite: cacheWriteTokens
|
|
1169
1272
|
},
|
|
1170
1273
|
outputTokens: {
|
|
1171
1274
|
total: outputTokens,
|
|
1172
|
-
text: (outputTokens
|
|
1275
|
+
text: (outputTokens ?? 0) - (reasoningTokens ?? 0),
|
|
1173
1276
|
reasoning: reasoningTokens
|
|
1174
1277
|
},
|
|
1175
1278
|
raw: response.usage
|
|
@@ -1187,16 +1290,15 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1187
1290
|
};
|
|
1188
1291
|
}
|
|
1189
1292
|
async doStream(options) {
|
|
1190
|
-
var _a, _b, _c;
|
|
1191
1293
|
const { body, warnings } = await this.getArgs(options);
|
|
1192
1294
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1193
1295
|
url: this.config.url,
|
|
1194
|
-
headers: combineHeaders(
|
|
1296
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
1195
1297
|
body: {
|
|
1196
1298
|
...body,
|
|
1197
1299
|
stream: true
|
|
1198
1300
|
},
|
|
1199
|
-
failedResponseHandler:
|
|
1301
|
+
failedResponseHandler: this.config.failedResponseHandler ?? defaultFailedResponseHandler,
|
|
1200
1302
|
successfulResponseHandler: createEventSourceResponseHandler(z4.any()),
|
|
1201
1303
|
abortSignal: options.abortSignal,
|
|
1202
1304
|
fetch: this.config.fetch
|
|
@@ -1215,24 +1317,23 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1215
1317
|
}
|
|
1216
1318
|
};
|
|
1217
1319
|
const updateUsage = (responseUsage) => {
|
|
1218
|
-
var _a2, _b2, _c2;
|
|
1219
1320
|
if (!responseUsage) {
|
|
1220
1321
|
return;
|
|
1221
1322
|
}
|
|
1222
1323
|
const inputTokens = responseUsage.input_tokens;
|
|
1223
|
-
const cachedInputTokens =
|
|
1224
|
-
const cacheWriteTokens =
|
|
1324
|
+
const cachedInputTokens = responseUsage.input_tokens_details?.cached_tokens;
|
|
1325
|
+
const cacheWriteTokens = responseUsage.input_tokens_details?.cache_write_tokens;
|
|
1225
1326
|
const outputTokens = responseUsage.output_tokens;
|
|
1226
|
-
const reasoningTokens =
|
|
1327
|
+
const reasoningTokens = responseUsage.output_tokens_details?.reasoning_tokens;
|
|
1227
1328
|
usage.inputTokens = {
|
|
1228
1329
|
total: inputTokens,
|
|
1229
|
-
noCache: (inputTokens
|
|
1330
|
+
noCache: (inputTokens ?? 0) - (cachedInputTokens ?? 0) - (cacheWriteTokens ?? 0),
|
|
1230
1331
|
cacheRead: cachedInputTokens,
|
|
1231
1332
|
cacheWrite: cacheWriteTokens
|
|
1232
1333
|
};
|
|
1233
1334
|
usage.outputTokens = {
|
|
1234
1335
|
total: outputTokens,
|
|
1235
|
-
text: (outputTokens
|
|
1336
|
+
text: (outputTokens ?? 0) - (reasoningTokens ?? 0),
|
|
1236
1337
|
reasoning: reasoningTokens
|
|
1237
1338
|
};
|
|
1238
1339
|
usage.raw = responseUsage;
|
|
@@ -1256,7 +1357,6 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1256
1357
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1257
1358
|
},
|
|
1258
1359
|
async transform(parseResult, controller) {
|
|
1259
|
-
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1260
1360
|
if (options.includeRawChunks) {
|
|
1261
1361
|
controller.enqueue({
|
|
1262
1362
|
type: "raw",
|
|
@@ -1270,21 +1370,21 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1270
1370
|
const chunk = parseResult.value;
|
|
1271
1371
|
if (isOpenResponsesExtensionEvent(chunk)) {
|
|
1272
1372
|
const extension = extensionRegistry.byEventType.get(chunk.type);
|
|
1273
|
-
if (
|
|
1373
|
+
if (extension?.decodeEvent != null) {
|
|
1274
1374
|
try {
|
|
1275
1375
|
const decoded = await extension.decodeEvent({
|
|
1276
1376
|
event: chunk,
|
|
1277
1377
|
state: extensionStreamState
|
|
1278
1378
|
});
|
|
1279
|
-
for (const part of decoded
|
|
1379
|
+
for (const part of decoded ?? []) {
|
|
1280
1380
|
controller.enqueue(part);
|
|
1281
|
-
hasToolCalls
|
|
1381
|
+
hasToolCalls ||= part.type === "tool-call" || part.type === "tool-input-start";
|
|
1282
1382
|
}
|
|
1283
1383
|
} catch (error) {
|
|
1284
1384
|
controller.enqueue({ type: "error", error });
|
|
1285
1385
|
}
|
|
1386
|
+
return;
|
|
1286
1387
|
}
|
|
1287
|
-
return;
|
|
1288
1388
|
}
|
|
1289
1389
|
if (chunk.type === "response.output_item.added" && chunk.item.type === "function_call") {
|
|
1290
1390
|
toolCallsByItemId.set(chunk.item.id, {
|
|
@@ -1301,7 +1401,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1301
1401
|
});
|
|
1302
1402
|
return;
|
|
1303
1403
|
}
|
|
1304
|
-
toolCall.arguments = (
|
|
1404
|
+
toolCall.arguments = (toolCall.arguments ?? "") + functionCallChunk.delta;
|
|
1305
1405
|
} else if (chunk.type === "response.function_call_arguments.done") {
|
|
1306
1406
|
const functionCallChunk = chunk;
|
|
1307
1407
|
const toolCall = toolCallsByItemId.get(functionCallChunk.item_id);
|
|
@@ -1314,9 +1414,9 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1314
1414
|
toolCall.arguments = functionCallChunk.arguments;
|
|
1315
1415
|
} else if (chunk.type === "response.output_item.done" && chunk.item.type === "function_call") {
|
|
1316
1416
|
const toolCall = toolCallsByItemId.get(chunk.item.id);
|
|
1317
|
-
const toolName =
|
|
1318
|
-
const toolCallId =
|
|
1319
|
-
const input = chunk.item.arguments !== "" ? chunk.item.arguments :
|
|
1417
|
+
const toolName = toolCall?.toolName ?? chunk.item.name;
|
|
1418
|
+
const toolCallId = toolCall?.toolCallId ?? chunk.item.call_id;
|
|
1419
|
+
const input = chunk.item.arguments !== "" ? chunk.item.arguments : toolCall?.arguments ?? "";
|
|
1320
1420
|
controller.enqueue({
|
|
1321
1421
|
type: "tool-call",
|
|
1322
1422
|
toolCallId,
|
|
@@ -1348,11 +1448,11 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1348
1448
|
input: chunk.delta
|
|
1349
1449
|
});
|
|
1350
1450
|
} else {
|
|
1351
|
-
toolCall.input = (
|
|
1451
|
+
toolCall.input = (toolCall.input ?? "") + chunk.delta;
|
|
1352
1452
|
}
|
|
1353
1453
|
controller.enqueue({
|
|
1354
1454
|
type: "tool-input-delta",
|
|
1355
|
-
id:
|
|
1455
|
+
id: customToolCallsByItemId.get(chunk.item_id)?.toolCallId ?? chunk.item_id,
|
|
1356
1456
|
delta: chunk.delta
|
|
1357
1457
|
});
|
|
1358
1458
|
} else if (chunk.type === "response.custom_tool_call_input.done") {
|
|
@@ -1366,13 +1466,13 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1366
1466
|
}
|
|
1367
1467
|
} else if (chunk.type === "response.output_item.done" && chunk.item.type === "custom_tool_call") {
|
|
1368
1468
|
const toolCall = customToolCallsByItemId.get(chunk.item.id);
|
|
1369
|
-
const toolCallId =
|
|
1370
|
-
const input = chunk.item.input !== "" ? chunk.item.input :
|
|
1469
|
+
const toolCallId = toolCall?.toolCallId ?? chunk.item.call_id;
|
|
1470
|
+
const input = chunk.item.input !== "" ? chunk.item.input : toolCall?.input ?? "";
|
|
1371
1471
|
controller.enqueue({ type: "tool-input-end", id: toolCallId });
|
|
1372
1472
|
controller.enqueue({
|
|
1373
1473
|
type: "tool-call",
|
|
1374
1474
|
toolCallId,
|
|
1375
|
-
toolName:
|
|
1475
|
+
toolName: toolCall?.toolName ?? chunk.item.name,
|
|
1376
1476
|
input: JSON.stringify(input),
|
|
1377
1477
|
providerMetadata: {
|
|
1378
1478
|
[providerOptionsName]: { itemId: chunk.item.id }
|
|
@@ -1380,7 +1480,7 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1380
1480
|
});
|
|
1381
1481
|
hasToolCalls = true;
|
|
1382
1482
|
customToolCallsByItemId.delete(chunk.item.id);
|
|
1383
|
-
} else if (chunk.type === "response.output_item.done" && isOpenResponsesExtensionItem(chunk.item)) {
|
|
1483
|
+
} else if (chunk.type === "response.output_item.done" && isOpenResponsesExtensionItem(chunk.item) && extensionRegistry.byItemType.has(chunk.item.type)) {
|
|
1384
1484
|
try {
|
|
1385
1485
|
const decoded = await decodeExtensionItem({
|
|
1386
1486
|
extensionRegistry,
|
|
@@ -1388,9 +1488,9 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1388
1488
|
mode: "stream",
|
|
1389
1489
|
providerOptionsName
|
|
1390
1490
|
});
|
|
1391
|
-
for (const part of decoded
|
|
1491
|
+
for (const part of decoded ?? []) {
|
|
1392
1492
|
controller.enqueue(part);
|
|
1393
|
-
hasToolCalls
|
|
1493
|
+
hasToolCalls ||= part.type === "tool-call";
|
|
1394
1494
|
}
|
|
1395
1495
|
} catch (error) {
|
|
1396
1496
|
controller.enqueue({ type: "error", error });
|
|
@@ -1443,19 +1543,19 @@ var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
|
1443
1543
|
}
|
|
1444
1544
|
});
|
|
1445
1545
|
} else if (chunk.type === "response.completed" || chunk.type === "response.incomplete") {
|
|
1446
|
-
const reason =
|
|
1546
|
+
const reason = chunk.response.incomplete_details?.reason;
|
|
1447
1547
|
finishReason = {
|
|
1448
1548
|
unified: mapOpenResponsesFinishReason({
|
|
1449
1549
|
finishReason: reason,
|
|
1450
1550
|
hasToolCalls
|
|
1451
1551
|
}),
|
|
1452
|
-
raw: reason
|
|
1552
|
+
raw: reason ?? void 0
|
|
1453
1553
|
};
|
|
1454
1554
|
updateUsage(chunk.response.usage);
|
|
1455
1555
|
} else if (chunk.type === "response.failed") {
|
|
1456
1556
|
finishReason = {
|
|
1457
1557
|
unified: "error",
|
|
1458
|
-
raw:
|
|
1558
|
+
raw: chunk.response.error?.code ?? chunk.response.status
|
|
1459
1559
|
};
|
|
1460
1560
|
updateUsage(chunk.response.usage);
|
|
1461
1561
|
if (chunk.response.error != null) {
|
|
@@ -1516,7 +1616,7 @@ function createOpenResponsesStreamError({
|
|
|
1516
1616
|
message: error.message,
|
|
1517
1617
|
type,
|
|
1518
1618
|
code: error.code,
|
|
1519
|
-
...getResponseErrorMetadata
|
|
1619
|
+
...getResponseErrorMetadata?.(error),
|
|
1520
1620
|
data
|
|
1521
1621
|
});
|
|
1522
1622
|
}
|
|
@@ -1596,8 +1696,7 @@ function addExtensionItemReferenceMetadata({
|
|
|
1596
1696
|
part,
|
|
1597
1697
|
providerOptionsName
|
|
1598
1698
|
}) {
|
|
1599
|
-
|
|
1600
|
-
const providerMetadata = (_a = part.providerMetadata) != null ? _a : {};
|
|
1699
|
+
const providerMetadata = part.providerMetadata ?? {};
|
|
1601
1700
|
return {
|
|
1602
1701
|
...part,
|
|
1603
1702
|
providerMetadata: {
|
|
@@ -1629,24 +1728,20 @@ function getOutputTextAnnotations(value) {
|
|
|
1629
1728
|
|
|
1630
1729
|
// src/open-responses-provider.ts
|
|
1631
1730
|
function createOpenResponses(options) {
|
|
1632
|
-
var _a;
|
|
1633
1731
|
const providerName = options.name;
|
|
1634
|
-
const customToolId =
|
|
1732
|
+
const customToolId = options.customToolId ?? "open-responses.custom";
|
|
1635
1733
|
const extensionRegistry = createOpenResponsesExtensionRegistry(
|
|
1636
1734
|
options.experimental_extensions
|
|
1637
1735
|
);
|
|
1638
|
-
const getHeaders = () =>
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
(_a2 = options.userAgentSuffix) != null ? _a2 : `ai-sdk/open-responses/${VERSION}`
|
|
1648
|
-
);
|
|
1649
|
-
};
|
|
1736
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
1737
|
+
{
|
|
1738
|
+
...options.apiKey ? {
|
|
1739
|
+
Authorization: `Bearer ${options.apiKey}`
|
|
1740
|
+
} : {},
|
|
1741
|
+
...typeof options.headers === "function" ? options.headers() : options.headers
|
|
1742
|
+
},
|
|
1743
|
+
options.userAgentSuffix ?? `ai-sdk/open-responses/${VERSION}`
|
|
1744
|
+
);
|
|
1650
1745
|
const createResponsesModel = (modelId) => {
|
|
1651
1746
|
return new OpenResponsesLanguageModel(modelId, {
|
|
1652
1747
|
provider: `${providerName}.responses`,
|