@ai-sdk/open-responses 2.0.56 → 2.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,1787 +1,1371 @@
1
- // src/version.ts
2
- var VERSION = true ? "2.0.56" : "0.0.0-test";
3
-
4
- // src/open-responses-provider.ts
5
- import {
6
- NoSuchModelError
7
- } from "@ai-sdk/provider";
8
- import {
9
- generateId,
10
- withUserAgentSuffix
11
- } from "@ai-sdk/provider-utils";
12
-
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"
1
+ import { APICallError, NoSuchModelError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
2
+ import { SerializationError, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderStreamError, generateId, getTopLevelMediaType, isCustomReasoning, jsonSchema, lazySchema, mapReasoningToProviderEffort, parseProviderOptions, postJsonToApi, resolveFullMediaType, serializeModelOptions, withUserAgentSuffix, zodSchema } from "@ai-sdk/provider-utils";
3
+ import { z } from "zod/v4";
4
+ //#region src/version.ts
5
+ const VERSION = "2.0.57";
6
+ //#endregion
7
+ //#region src/open-responses-extension.ts
8
+ const coreToolTypes = /* @__PURE__ */ new Set(["allowed_tools", "function"]);
9
+ const coreItemTypes = /* @__PURE__ */ new Set([
10
+ "function_call",
11
+ "function_call_output",
12
+ "item_reference",
13
+ "message",
14
+ "reasoning"
21
15
  ]);
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"
16
+ const coreEventTypes = /* @__PURE__ */ new Set([
17
+ "error",
18
+ "response.completed",
19
+ "response.content_part.added",
20
+ "response.content_part.done",
21
+ "response.created",
22
+ "response.failed",
23
+ "response.function_call_arguments.delta",
24
+ "response.function_call_arguments.done",
25
+ "response.in_progress",
26
+ "response.incomplete",
27
+ "response.output_item.added",
28
+ "response.output_item.done",
29
+ "response.output_text.delta",
30
+ "response.output_text.done",
31
+ "response.reasoning_summary_part.added",
32
+ "response.reasoning_summary_part.done",
33
+ "response.reasoning_summary_text.delta",
34
+ "response.reasoning_summary_text.done",
35
+ "response.reasoning_text.delta",
36
+ "response.refusal.delta",
37
+ "response.refusal.done"
44
38
  ]);
45
39
  function createOpenResponsesExtensionRegistry(extensions) {
46
- const registry = {
47
- byEventType: /* @__PURE__ */ new Map(),
48
- byExtensionId: /* @__PURE__ */ new Map(),
49
- byItemType: /* @__PURE__ */ new Map(),
50
- byProviderToolId: /* @__PURE__ */ new Map(),
51
- byToolType: /* @__PURE__ */ new Map()
52
- };
53
- for (const extension of extensions ?? []) {
54
- const namespaceSeparatorIndex = extension.id.indexOf(".");
55
- if (namespaceSeparatorIndex <= 0) {
56
- throw new Error(
57
- `Open Responses extension ID ${extension.id} must use <implementor>.<extension> format.`
58
- );
59
- }
60
- const namespace = extension.id.slice(0, namespaceSeparatorIndex);
61
- registerUnique({
62
- map: registry.byExtensionId,
63
- key: extension.id,
64
- extension,
65
- field: "id"
66
- });
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;
80
- const hasToolEncoder = extension.encodeTool != null;
81
- if (hasToolType !== hasToolEncoder) {
82
- const typeField = extension.bareToolType != null ? "bareToolType" : "toolType";
83
- throw new Error(
84
- `Open Responses extension ${extension.id} must provide ${typeField} and encodeTool together.`
85
- );
86
- }
87
- if (extension.encodeToolChoice != null && !hasToolEncoder) {
88
- throw new Error(
89
- `Open Responses extension ${extension.id} cannot provide encodeToolChoice without a tool type and encodeTool.`
90
- );
91
- }
92
- if (hasToolType && hasToolEncoder) {
93
- const toolExtension = extension;
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
- }
109
- registerUnique({
110
- map: registry.byProviderToolId,
111
- key: extension.id,
112
- extension: toolExtension,
113
- field: "provider-tool id"
114
- });
115
- registerUnique({
116
- map: registry.byToolType,
117
- key: toolType,
118
- extension: toolExtension,
119
- field: "tool type"
120
- });
121
- }
122
- const itemTypes = [
123
- ...extension.itemTypes ?? [],
124
- ...extension.bareItemTypes ?? []
125
- ];
126
- const hasItemTypes = extension.itemTypes != null || extension.bareItemTypes != null;
127
- const hasItemDecoder = extension.decodeItem != null;
128
- if (hasItemTypes !== hasItemDecoder) {
129
- throw new Error(
130
- `Open Responses extension ${extension.id} must provide itemTypes or bareItemTypes together with decodeItem.`
131
- );
132
- }
133
- if (extension.encodeInputItem != null && !hasItemDecoder) {
134
- throw new Error(
135
- `Open Responses extension ${extension.id} cannot provide encodeInputItem without itemTypes or bareItemTypes and decodeItem.`
136
- );
137
- }
138
- if (hasItemTypes && hasItemDecoder) {
139
- const itemExtension = extension;
140
- if (itemTypes.length === 0) {
141
- throw new Error(
142
- `Open Responses extension ${extension.id} must register at least one item type.`
143
- );
144
- }
145
- for (const itemType of extension.itemTypes ?? []) {
146
- assertNamespacedType({
147
- extensionId: extension.id,
148
- namespace,
149
- type: itemType,
150
- field: "itemTypes"
151
- });
152
- registerUnique({
153
- map: registry.byItemType,
154
- key: itemType,
155
- extension: itemExtension,
156
- field: "item type"
157
- });
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
- }
173
- }
174
- const eventTypes = [
175
- ...extension.eventTypes ?? [],
176
- ...extension.bareEventTypes ?? []
177
- ];
178
- const hasEventTypes = extension.eventTypes != null || extension.bareEventTypes != null;
179
- const hasEventDecoder = extension.decodeEvent != null;
180
- if (hasEventTypes !== hasEventDecoder) {
181
- throw new Error(
182
- `Open Responses extension ${extension.id} must provide eventTypes or bareEventTypes together with decodeEvent.`
183
- );
184
- }
185
- if (hasEventTypes && hasEventDecoder) {
186
- const eventExtension = extension;
187
- if (eventTypes.length === 0) {
188
- throw new Error(
189
- `Open Responses extension ${extension.id} must register at least one event type.`
190
- );
191
- }
192
- for (const eventType of extension.eventTypes ?? []) {
193
- assertNamespacedType({
194
- extensionId: extension.id,
195
- namespace,
196
- type: eventType,
197
- field: "eventTypes"
198
- });
199
- registerUnique({
200
- map: registry.byEventType,
201
- key: eventType,
202
- extension: eventExtension,
203
- field: "event type"
204
- });
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
- }
220
- }
221
- if (!hasToolEncoder && !hasItemDecoder && !hasEventDecoder) {
222
- throw new Error(
223
- `Open Responses extension ${extension.id} must register a tool, item, or event capability.`
224
- );
225
- }
226
- }
227
- return registry;
40
+ const registry = {
41
+ byEventType: /* @__PURE__ */ new Map(),
42
+ byExtensionId: /* @__PURE__ */ new Map(),
43
+ byItemType: /* @__PURE__ */ new Map(),
44
+ byProviderToolId: /* @__PURE__ */ new Map(),
45
+ byToolType: /* @__PURE__ */ new Map()
46
+ };
47
+ for (const extension of extensions ?? []) {
48
+ const namespaceSeparatorIndex = extension.id.indexOf(".");
49
+ if (namespaceSeparatorIndex <= 0) throw new Error(`Open Responses extension ID ${extension.id} must use <implementor>.<extension> format.`);
50
+ const namespace = extension.id.slice(0, namespaceSeparatorIndex);
51
+ registerUnique({
52
+ map: registry.byExtensionId,
53
+ key: extension.id,
54
+ extension,
55
+ field: "id"
56
+ });
57
+ if ((extension.bareToolType != null || extension.bareItemTypes != null || extension.bareEventTypes != null) !== (extension.allowBareTypes === true)) throw new Error(`Open Responses extension ${extension.id} must set allowBareTypes to true exactly when registering bare types.`);
58
+ if (extension.toolType != null && extension.bareToolType != null) throw new Error(`Open Responses extension ${extension.id} cannot provide toolType and bareToolType together.`);
59
+ const toolType = extension.toolType ?? extension.bareToolType;
60
+ const hasToolType = toolType != null;
61
+ const hasToolEncoder = extension.encodeTool != null;
62
+ if (hasToolType !== hasToolEncoder) {
63
+ const typeField = extension.bareToolType != null ? "bareToolType" : "toolType";
64
+ throw new Error(`Open Responses extension ${extension.id} must provide ${typeField} and encodeTool together.`);
65
+ }
66
+ if (extension.encodeToolChoice != null && !hasToolEncoder) throw new Error(`Open Responses extension ${extension.id} cannot provide encodeToolChoice without a tool type and encodeTool.`);
67
+ if (hasToolType && hasToolEncoder) {
68
+ const toolExtension = extension;
69
+ if (extension.toolType != null) assertNamespacedType({
70
+ extensionId: extension.id,
71
+ namespace,
72
+ type: extension.toolType,
73
+ field: "toolType"
74
+ });
75
+ else assertBareType({
76
+ coreTypes: coreToolTypes,
77
+ extensionId: extension.id,
78
+ type: extension.bareToolType,
79
+ field: "bareToolType"
80
+ });
81
+ registerUnique({
82
+ map: registry.byProviderToolId,
83
+ key: extension.id,
84
+ extension: toolExtension,
85
+ field: "provider-tool id"
86
+ });
87
+ registerUnique({
88
+ map: registry.byToolType,
89
+ key: toolType,
90
+ extension: toolExtension,
91
+ field: "tool type"
92
+ });
93
+ }
94
+ const itemTypes = [...extension.itemTypes ?? [], ...extension.bareItemTypes ?? []];
95
+ const hasItemTypes = extension.itemTypes != null || extension.bareItemTypes != null;
96
+ const hasItemDecoder = extension.decodeItem != null;
97
+ if (hasItemTypes !== hasItemDecoder) throw new Error(`Open Responses extension ${extension.id} must provide itemTypes or bareItemTypes together with decodeItem.`);
98
+ if (extension.encodeInputItem != null && !hasItemDecoder) throw new Error(`Open Responses extension ${extension.id} cannot provide encodeInputItem without itemTypes or bareItemTypes and decodeItem.`);
99
+ if (hasItemTypes && hasItemDecoder) {
100
+ const itemExtension = extension;
101
+ if (itemTypes.length === 0) throw new Error(`Open Responses extension ${extension.id} must register at least one item type.`);
102
+ for (const itemType of extension.itemTypes ?? []) {
103
+ assertNamespacedType({
104
+ extensionId: extension.id,
105
+ namespace,
106
+ type: itemType,
107
+ field: "itemTypes"
108
+ });
109
+ registerUnique({
110
+ map: registry.byItemType,
111
+ key: itemType,
112
+ extension: itemExtension,
113
+ field: "item type"
114
+ });
115
+ }
116
+ for (const itemType of extension.bareItemTypes ?? []) {
117
+ assertBareType({
118
+ coreTypes: coreItemTypes,
119
+ extensionId: extension.id,
120
+ type: itemType,
121
+ field: "bareItemTypes"
122
+ });
123
+ registerUnique({
124
+ map: registry.byItemType,
125
+ key: itemType,
126
+ extension: itemExtension,
127
+ field: "item type"
128
+ });
129
+ }
130
+ }
131
+ const eventTypes = [...extension.eventTypes ?? [], ...extension.bareEventTypes ?? []];
132
+ const hasEventTypes = extension.eventTypes != null || extension.bareEventTypes != null;
133
+ const hasEventDecoder = extension.decodeEvent != null;
134
+ if (hasEventTypes !== hasEventDecoder) throw new Error(`Open Responses extension ${extension.id} must provide eventTypes or bareEventTypes together with decodeEvent.`);
135
+ if (hasEventTypes && hasEventDecoder) {
136
+ const eventExtension = extension;
137
+ if (eventTypes.length === 0) throw new Error(`Open Responses extension ${extension.id} must register at least one event type.`);
138
+ for (const eventType of extension.eventTypes ?? []) {
139
+ assertNamespacedType({
140
+ extensionId: extension.id,
141
+ namespace,
142
+ type: eventType,
143
+ field: "eventTypes"
144
+ });
145
+ registerUnique({
146
+ map: registry.byEventType,
147
+ key: eventType,
148
+ extension: eventExtension,
149
+ field: "event type"
150
+ });
151
+ }
152
+ for (const eventType of extension.bareEventTypes ?? []) {
153
+ assertBareType({
154
+ coreTypes: coreEventTypes,
155
+ extensionId: extension.id,
156
+ type: eventType,
157
+ field: "bareEventTypes"
158
+ });
159
+ registerUnique({
160
+ map: registry.byEventType,
161
+ key: eventType,
162
+ extension: eventExtension,
163
+ field: "event type"
164
+ });
165
+ }
166
+ }
167
+ if (!hasToolEncoder && !hasItemDecoder && !hasEventDecoder) throw new Error(`Open Responses extension ${extension.id} must register a tool, item, or event capability.`);
168
+ }
169
+ return registry;
228
170
  }
229
- function assertNamespacedType({
230
- extensionId,
231
- namespace,
232
- type,
233
- field
234
- }) {
235
- const separatorIndex = type.indexOf(":");
236
- if (separatorIndex <= 0 || type.slice(0, separatorIndex) !== namespace) {
237
- throw new Error(
238
- `Open Responses extension ${extensionId} has invalid ${field} value ${type}. Extension wire types must use the ${namespace}: namespace.`
239
- );
240
- }
171
+ function assertNamespacedType({ extensionId, namespace, type, field }) {
172
+ const separatorIndex = type.indexOf(":");
173
+ if (separatorIndex <= 0 || type.slice(0, separatorIndex) !== namespace) throw new Error(`Open Responses extension ${extensionId} has invalid ${field} value ${type}. Extension wire types must use the ${namespace}: namespace.`);
241
174
  }
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
- }
175
+ function assertBareType({ coreTypes, extensionId, type, field }) {
176
+ if (type.length === 0 || type.includes(":")) throw new Error(`Open Responses extension ${extensionId} has invalid ${field} value ${type}. Bare extension wire types must be non-empty and must not contain a colon.`);
177
+ if (coreTypes.has(type)) throw new Error(`Open Responses extension ${extensionId} cannot register core ${field} value ${type}.`);
258
178
  }
259
179
  function getOpenResponsesExtensionItemTypes(extension) {
260
- return [...extension.itemTypes ?? [], ...extension.bareItemTypes ?? []];
180
+ return [...extension.itemTypes ?? [], ...extension.bareItemTypes ?? []];
261
181
  }
262
182
  function getOpenResponsesExtensionToolType(extension) {
263
- return extension.toolType ?? extension.bareToolType;
183
+ return extension.toolType ?? extension.bareToolType;
264
184
  }
185
+ /**
186
+ * Keeps the internal API unions narrow enough to discriminate core wire types.
187
+ * Bare records only reach this boundary after registry validation.
188
+ */
265
189
  function asOpenResponsesExtensionRecord(value) {
266
- return value;
190
+ return value;
267
191
  }
268
- function registerUnique({
269
- map,
270
- key,
271
- extension,
272
- field
273
- }) {
274
- const existing = map.get(key);
275
- if (existing != null) {
276
- throw new Error(
277
- `Open Responses extension ${extension.id} cannot register ${field} ${String(key)} because it is already registered by ${existing.id}.`
278
- );
279
- }
280
- map.set(key, extension);
192
+ function registerUnique({ map, key, extension, field }) {
193
+ const existing = map.get(key);
194
+ if (existing != null) throw new Error(`Open Responses extension ${extension.id} cannot register ${field} ${String(key)} because it is already registered by ${existing.id}.`);
195
+ map.set(key, extension);
281
196
  }
282
197
  function isOpenResponsesExtensionRecord(value) {
283
- return isOpenResponsesJSONObject(value) && typeof value.type === "string";
198
+ return isOpenResponsesJSONObject(value) && typeof value.type === "string";
284
199
  }
285
200
  function isOpenResponsesJSONObject(value) {
286
- return value != null && typeof value === "object" && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype && Object.values(value).every(isOpenResponsesJSONValue);
201
+ return value != null && typeof value === "object" && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype && Object.values(value).every(isOpenResponsesJSONValue);
287
202
  }
288
203
  function isOpenResponsesExtensionItem(value) {
289
- return isOpenResponsesExtensionRecord(value) && typeof value.id === "string" && typeof value.status === "string";
204
+ return isOpenResponsesExtensionRecord(value) && typeof value.id === "string" && typeof value.status === "string";
290
205
  }
291
206
  function isOpenResponsesExtensionEvent(value) {
292
- return isOpenResponsesExtensionRecord(value) && typeof value.sequence_number === "number";
207
+ return isOpenResponsesExtensionRecord(value) && typeof value.sequence_number === "number";
293
208
  }
294
209
  function isOpenResponsesJSONValue(value) {
295
- if (value == null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
296
- return true;
297
- }
298
- if (Array.isArray(value)) {
299
- return value.every(isOpenResponsesJSONValue);
300
- }
301
- return isOpenResponsesJSONObject(value);
210
+ if (value == null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return true;
211
+ if (Array.isArray(value)) return value.every(isOpenResponsesJSONValue);
212
+ return isOpenResponsesJSONObject(value);
302
213
  }
303
-
304
- // src/open-responses-tools.ts
305
- import {
306
- createProviderDefinedToolFactory,
307
- lazySchema,
308
- zodSchema
309
- } from "@ai-sdk/provider-utils";
310
- import { z } from "zod/v4";
311
- var customInputSchema = lazySchema(() => zodSchema(z.string()));
312
- function createOpenResponsesTools({
313
- customToolId
314
- }) {
315
- const customToolFactory = createProviderDefinedToolFactory({
316
- id: customToolId,
317
- inputSchema: customInputSchema
318
- });
319
- return {
320
- /**
321
- * Creates a caller-executed OpenAI-compatible custom tool. Custom tools accept
322
- * a raw string, optionally constrained by a grammar. Requires endpoint support.
323
- */
324
- customTool: (options) => customToolFactory(options)
325
- };
214
+ //#endregion
215
+ //#region src/open-responses-tools.ts
216
+ const customInputSchema = lazySchema(() => zodSchema(z.string()));
217
+ function createOpenResponsesTools({ customToolId }) {
218
+ const customToolFactory = createProviderDefinedToolFactory({
219
+ id: customToolId,
220
+ inputSchema: customInputSchema
221
+ });
222
+ return {
223
+ /**
224
+ * Creates a caller-executed OpenAI-compatible custom tool. Custom tools accept
225
+ * a raw string, optionally constrained by a grammar. Requires endpoint support.
226
+ */
227
+ customTool: (options) => customToolFactory(options) };
326
228
  }
327
-
328
- // src/responses/open-responses-language-model.ts
329
- import {
330
- APICallError
331
- } from "@ai-sdk/provider";
332
- import {
333
- combineHeaders,
334
- createEventSourceResponseHandler,
335
- createJsonErrorResponseHandler,
336
- createJsonResponseHandler,
337
- createProviderStreamError,
338
- isCustomReasoning,
339
- jsonSchema,
340
- mapReasoningToProviderEffort,
341
- parseProviderOptions,
342
- postJsonToApi,
343
- SerializationError,
344
- serializeModelOptions,
345
- WORKFLOW_SERIALIZE,
346
- WORKFLOW_DESERIALIZE
347
- } from "@ai-sdk/provider-utils";
348
- import { z as z4 } from "zod/v4";
349
-
350
- // src/responses/convert-to-open-responses-input.ts
351
- import {
352
- UnsupportedFunctionalityError
353
- } from "@ai-sdk/provider";
354
- import {
355
- convertToBase64,
356
- getTopLevelMediaType,
357
- resolveFullMediaType
358
- } from "@ai-sdk/provider-utils";
359
- async function convertToOpenResponsesInput({
360
- prompt,
361
- providerOptionsName = "open-responses",
362
- extensionRegistry,
363
- providerToolsByName = /* @__PURE__ */ new Map(),
364
- strictResponseInput = false,
365
- customToolId
366
- }) {
367
- const input = [];
368
- const warnings = [];
369
- const systemMessages = [];
370
- const replayedExtensionItems = /* @__PURE__ */ new Set();
371
- for (const { role, content } of prompt) {
372
- switch (role) {
373
- case "system": {
374
- systemMessages.push(content);
375
- break;
376
- }
377
- case "user": {
378
- const userContent = [];
379
- for (const part of content) {
380
- switch (part.type) {
381
- case "text": {
382
- userContent.push({ type: "input_text", text: part.text });
383
- break;
384
- }
385
- case "file": {
386
- switch (part.data.type) {
387
- case "reference": {
388
- throw new UnsupportedFunctionalityError({
389
- functionality: "file parts with provider references"
390
- });
391
- }
392
- case "text": {
393
- throw new UnsupportedFunctionalityError({
394
- functionality: "text file parts"
395
- });
396
- }
397
- case "url":
398
- case "data": {
399
- const topLevel = getTopLevelMediaType(part.mediaType);
400
- if (topLevel === "image") {
401
- userContent.push({
402
- type: "input_image",
403
- ...part.data.type === "url" ? { image_url: part.data.url.toString() } : {
404
- image_url: `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`
405
- },
406
- detail: getImageDetail(part, providerOptionsName)
407
- });
408
- } else if (part.data.type === "url") {
409
- userContent.push({
410
- type: "input_file",
411
- file_url: part.data.url.toString()
412
- });
413
- } else {
414
- const fullMediaType = resolveFullMediaType({ part });
415
- userContent.push({
416
- type: "input_file",
417
- filename: part.filename ?? "data",
418
- file_data: `data:${fullMediaType};base64,${convertToBase64(part.data.data)}`
419
- });
420
- }
421
- break;
422
- }
423
- }
424
- break;
425
- }
426
- }
427
- }
428
- input.push({ type: "message", role: "user", content: userContent });
429
- break;
430
- }
431
- case "assistant": {
432
- let assistantContent = [];
433
- let assistantMessageId;
434
- const flushAssistantContent = () => {
435
- if (assistantContent.length === 0) {
436
- return;
437
- }
438
- if (strictResponseInput && assistantMessageId == null) {
439
- input.push({
440
- type: "message",
441
- role: "assistant",
442
- content: assistantContent.map(
443
- (part) => part.type === "output_text" ? part.text : part.refusal
444
- ).join("")
445
- });
446
- } else if (strictResponseInput) {
447
- input.push({
448
- id: assistantMessageId,
449
- type: "message",
450
- status: "completed",
451
- role: "assistant",
452
- content: assistantContent.map(
453
- (part) => part.type === "output_text" ? {
454
- ...part,
455
- annotations: part.annotations ?? [],
456
- logprobs: part.logprobs ?? []
457
- } : part
458
- )
459
- });
460
- } else {
461
- input.push({
462
- type: "message",
463
- role: "assistant",
464
- content: assistantContent,
465
- ...assistantMessageId != null && { id: assistantMessageId }
466
- });
467
- }
468
- assistantContent = [];
469
- assistantMessageId = void 0;
470
- };
471
- for (const part of content) {
472
- const extensionReplay = getExtensionReplay({
473
- part,
474
- providerOptionsName,
475
- extensionRegistry
476
- });
477
- if (extensionReplay != null) {
478
- flushAssistantContent();
479
- const replayItem = extensionReplay.item;
480
- if (replayItem != null) {
481
- const replayKey = `${replayItem.type}:${replayItem.id}`;
482
- if (!replayedExtensionItems.has(replayKey)) {
483
- input.push(asOpenResponsesExtensionRecord(replayItem));
484
- replayedExtensionItems.add(replayKey);
485
- }
486
- }
487
- continue;
488
- }
489
- if (part.type === "tool-call" || part.type === "tool-result") {
490
- const providerTool = providerToolsByName.get(part.toolName);
491
- const extension = providerTool == null ? void 0 : extensionRegistry?.byProviderToolId.get(providerTool.id);
492
- if (providerTool != null && extension != null) {
493
- flushAssistantContent();
494
- const encoded = await encodeExtensionInputPart({
495
- extensionRegistry,
496
- part,
497
- providerTool
498
- });
499
- if (encoded == null) {
500
- warnings.push({
501
- type: "unsupported",
502
- feature: `provider-defined tool ${providerTool.id} ${part.type} history`
503
- });
504
- } else {
505
- input.push(...encoded.map(asOpenResponsesExtensionRecord));
506
- }
507
- continue;
508
- }
509
- }
510
- switch (part.type) {
511
- case "reasoning": {
512
- flushAssistantContent();
513
- const providerData = getProviderData(part, providerOptionsName);
514
- const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
515
- const summary = parseReasoningSummary(
516
- providerData?.reasoningSummary
517
- );
518
- const reasoningContent = parseReasoningContent(
519
- providerData?.reasoningContent
520
- );
521
- const hasReasoningContent = providerData != null && "reasoningContent" in providerData;
522
- const encryptedContent = typeof providerData?.reasoningEncryptedContent === "string" ? providerData.reasoningEncryptedContent : void 0;
523
- const reasoningItem = {
524
- type: "reasoning",
525
- summary: summary ?? [],
526
- ...itemId != null && { id: itemId },
527
- ...reasoningContent != null ? { content: reasoningContent } : !hasReasoningContent && part.text.length > 0 ? {
528
- content: [
529
- {
530
- type: "reasoning_text",
531
- text: part.text
532
- }
533
- ]
534
- } : {},
535
- ...encryptedContent != null && {
536
- encrypted_content: encryptedContent
537
- }
538
- };
539
- const previousItem = input[input.length - 1];
540
- if (reasoningItem.id != null && previousItem?.type === "reasoning" && previousItem.id === reasoningItem.id) {
541
- if (reasoningItem.content != null) {
542
- previousItem.content = [
543
- ...previousItem.content ?? [],
544
- ...reasoningItem.content
545
- ];
546
- }
547
- } else {
548
- input.push(reasoningItem);
549
- }
550
- break;
551
- }
552
- case "text": {
553
- const providerData = getProviderData(part, providerOptionsName);
554
- const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
555
- const annotations = parseOutputTextAnnotations(
556
- providerData?.annotations
557
- );
558
- if (assistantContent.length > 0 && assistantMessageId !== itemId) {
559
- flushAssistantContent();
560
- }
561
- assistantMessageId = itemId;
562
- assistantContent.push({
563
- type: "output_text",
564
- text: part.text,
565
- ...annotations != null && { annotations }
566
- });
567
- break;
568
- }
569
- case "tool-call": {
570
- flushAssistantContent();
571
- const argumentsValue = typeof part.input === "string" ? part.input : JSON.stringify(part.input);
572
- const providerData = getProviderData(part, providerOptionsName);
573
- const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
574
- const providerTool = providerToolsByName.get(part.toolName);
575
- if (customToolId != null && providerTool?.id === customToolId) {
576
- input.push({
577
- type: "custom_tool_call",
578
- ...itemId != null && { id: itemId },
579
- call_id: part.toolCallId,
580
- name: part.toolName,
581
- input: argumentsValue
582
- });
583
- } else {
584
- input.push({
585
- type: "function_call",
586
- ...itemId != null && { id: itemId },
587
- call_id: part.toolCallId,
588
- name: part.toolName,
589
- arguments: argumentsValue
590
- });
591
- }
592
- break;
593
- }
594
- }
595
- }
596
- flushAssistantContent();
597
- break;
598
- }
599
- case "tool": {
600
- for (const part of content) {
601
- if (part.type === "tool-result") {
602
- const extensionReplay = getExtensionReplay({
603
- part,
604
- providerOptionsName,
605
- extensionRegistry
606
- });
607
- if (extensionReplay != null) {
608
- const replayItem = extensionReplay.item;
609
- if (replayItem != null) {
610
- const replayKey = `${replayItem.type}:${replayItem.id}`;
611
- if (!replayedExtensionItems.has(replayKey)) {
612
- input.push(asOpenResponsesExtensionRecord(replayItem));
613
- replayedExtensionItems.add(replayKey);
614
- }
615
- }
616
- continue;
617
- }
618
- const providerTool = providerToolsByName.get(part.toolName);
619
- const extension = providerTool == null ? void 0 : extensionRegistry?.byProviderToolId.get(providerTool.id);
620
- if (providerTool != null && extension != null) {
621
- const encoded = await encodeExtensionInputPart({
622
- extensionRegistry,
623
- part,
624
- providerTool
625
- });
626
- if (encoded == null) {
627
- warnings.push({
628
- type: "unsupported",
629
- feature: `provider-defined tool ${providerTool.id} tool-result history`
630
- });
631
- } else {
632
- input.push(...encoded.map(asOpenResponsesExtensionRecord));
633
- }
634
- continue;
635
- }
636
- const output = part.output;
637
- let contentValue;
638
- switch (output.type) {
639
- case "text":
640
- case "error-text":
641
- contentValue = output.value;
642
- break;
643
- case "execution-denied":
644
- contentValue = output.reason ?? "Tool call execution denied.";
645
- break;
646
- case "json":
647
- case "error-json":
648
- contentValue = JSON.stringify(output.value);
649
- break;
650
- case "content": {
651
- const contentParts = [];
652
- for (const item of output.value) {
653
- switch (item.type) {
654
- case "text": {
655
- contentParts.push({
656
- type: "input_text",
657
- text: item.text
658
- });
659
- break;
660
- }
661
- case "file": {
662
- const topLevel = getTopLevelMediaType(item.mediaType);
663
- if (item.data.type === "data") {
664
- const fullMediaType = resolveFullMediaType({
665
- part: item
666
- });
667
- if (topLevel === "image") {
668
- contentParts.push({
669
- type: "input_image",
670
- image_url: `data:${fullMediaType};base64,${convertToBase64(item.data.data)}`,
671
- detail: getImageDetail(item, providerOptionsName)
672
- });
673
- } else {
674
- contentParts.push({
675
- type: "input_file",
676
- filename: item.filename ?? "data",
677
- file_data: `data:${fullMediaType};base64,${convertToBase64(item.data.data)}`
678
- });
679
- }
680
- } else if (item.data.type === "url") {
681
- if (topLevel === "image") {
682
- contentParts.push({
683
- type: "input_image",
684
- image_url: item.data.url.toString(),
685
- detail: getImageDetail(item, providerOptionsName)
686
- });
687
- } else {
688
- contentParts.push({
689
- type: "input_file",
690
- file_url: item.data.url.toString()
691
- });
692
- }
693
- } else {
694
- warnings.push({
695
- type: "other",
696
- message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
697
- });
698
- }
699
- break;
700
- }
701
- default: {
702
- warnings.push({
703
- type: "other",
704
- message: `unsupported tool content part type: ${item.type}`
705
- });
706
- break;
707
- }
708
- }
709
- }
710
- contentValue = contentParts;
711
- break;
712
- }
713
- }
714
- input.push({
715
- type: customToolId != null && providerTool?.id === customToolId ? "custom_tool_call_output" : "function_call_output",
716
- call_id: part.toolCallId,
717
- output: contentValue
718
- });
719
- }
720
- }
721
- break;
722
- }
723
- }
724
- }
725
- return {
726
- input,
727
- instructions: systemMessages.length > 0 ? systemMessages.join("\n") : void 0,
728
- warnings
729
- };
229
+ //#endregion
230
+ //#region src/responses/convert-to-open-responses-input.ts
231
+ async function convertToOpenResponsesInput({ prompt, providerOptionsName = "open-responses", extensionRegistry, providerToolsByName = /* @__PURE__ */ new Map(), strictResponseInput = false, customToolId }) {
232
+ const input = [];
233
+ const warnings = [];
234
+ const systemMessages = [];
235
+ const replayedExtensionItems = /* @__PURE__ */ new Set();
236
+ for (const { role, content } of prompt) switch (role) {
237
+ case "system":
238
+ systemMessages.push(content);
239
+ break;
240
+ case "user": {
241
+ const userContent = [];
242
+ for (const part of content) switch (part.type) {
243
+ case "text":
244
+ userContent.push({
245
+ type: "input_text",
246
+ text: part.text
247
+ });
248
+ break;
249
+ case "file": switch (part.data.type) {
250
+ case "reference": throw new UnsupportedFunctionalityError({ functionality: "file parts with provider references" });
251
+ case "text": throw new UnsupportedFunctionalityError({ functionality: "text file parts" });
252
+ case "url":
253
+ case "data": if (getTopLevelMediaType(part.mediaType) === "image") userContent.push({
254
+ type: "input_image",
255
+ ...part.data.type === "url" ? { image_url: part.data.url.toString() } : { image_url: `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}` },
256
+ detail: getImageDetail(part, providerOptionsName)
257
+ });
258
+ else if (part.data.type === "url") userContent.push({
259
+ type: "input_file",
260
+ file_url: part.data.url.toString()
261
+ });
262
+ else {
263
+ const fullMediaType = resolveFullMediaType({ part });
264
+ userContent.push({
265
+ type: "input_file",
266
+ filename: part.filename ?? "data",
267
+ file_data: `data:${fullMediaType};base64,${convertToBase64(part.data.data)}`
268
+ });
269
+ }
270
+ }
271
+ }
272
+ input.push({
273
+ type: "message",
274
+ role: "user",
275
+ content: userContent
276
+ });
277
+ break;
278
+ }
279
+ case "assistant": {
280
+ let assistantContent = [];
281
+ let assistantMessageId;
282
+ const flushAssistantContent = () => {
283
+ if (assistantContent.length === 0) return;
284
+ if (strictResponseInput && assistantMessageId == null) input.push({
285
+ type: "message",
286
+ role: "assistant",
287
+ content: assistantContent.map((part) => part.type === "output_text" ? part.text : part.refusal).join("")
288
+ });
289
+ else if (strictResponseInput) input.push({
290
+ id: assistantMessageId,
291
+ type: "message",
292
+ status: "completed",
293
+ role: "assistant",
294
+ content: assistantContent.map((part) => part.type === "output_text" ? {
295
+ ...part,
296
+ annotations: part.annotations ?? [],
297
+ logprobs: part.logprobs ?? []
298
+ } : part)
299
+ });
300
+ else input.push({
301
+ type: "message",
302
+ role: "assistant",
303
+ content: assistantContent,
304
+ ...assistantMessageId != null && { id: assistantMessageId }
305
+ });
306
+ assistantContent = [];
307
+ assistantMessageId = void 0;
308
+ };
309
+ for (const part of content) {
310
+ const extensionReplay = getExtensionReplay({
311
+ part,
312
+ providerOptionsName,
313
+ extensionRegistry
314
+ });
315
+ if (extensionReplay != null) {
316
+ flushAssistantContent();
317
+ const replayItem = extensionReplay.item;
318
+ if (replayItem != null) {
319
+ const replayKey = `${replayItem.type}:${replayItem.id}`;
320
+ if (!replayedExtensionItems.has(replayKey)) {
321
+ input.push(asOpenResponsesExtensionRecord(replayItem));
322
+ replayedExtensionItems.add(replayKey);
323
+ }
324
+ }
325
+ continue;
326
+ }
327
+ if (part.type === "tool-call" || part.type === "tool-result") {
328
+ const providerTool = providerToolsByName.get(part.toolName);
329
+ const extension = providerTool == null ? void 0 : extensionRegistry?.byProviderToolId.get(providerTool.id);
330
+ if (providerTool != null && extension != null) {
331
+ flushAssistantContent();
332
+ const encoded = await encodeExtensionInputPart({
333
+ extensionRegistry,
334
+ part,
335
+ providerTool
336
+ });
337
+ if (encoded == null) warnings.push({
338
+ type: "unsupported",
339
+ feature: `provider-defined tool ${providerTool.id} ${part.type} history`
340
+ });
341
+ else input.push(...encoded.map(asOpenResponsesExtensionRecord));
342
+ continue;
343
+ }
344
+ }
345
+ switch (part.type) {
346
+ case "reasoning": {
347
+ flushAssistantContent();
348
+ const providerData = getProviderData(part, providerOptionsName);
349
+ const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
350
+ const summary = parseReasoningSummary(providerData?.reasoningSummary);
351
+ const reasoningContent = parseReasoningContent(providerData?.reasoningContent);
352
+ const hasReasoningContent = providerData != null && "reasoningContent" in providerData;
353
+ const encryptedContent = typeof providerData?.reasoningEncryptedContent === "string" ? providerData.reasoningEncryptedContent : void 0;
354
+ const reasoningItem = {
355
+ type: "reasoning",
356
+ summary: summary ?? [],
357
+ ...itemId != null && { id: itemId },
358
+ ...reasoningContent != null ? { content: reasoningContent } : !hasReasoningContent && part.text.length > 0 ? { content: [{
359
+ type: "reasoning_text",
360
+ text: part.text
361
+ }] } : {},
362
+ ...encryptedContent != null && { encrypted_content: encryptedContent }
363
+ };
364
+ const previousItem = input[input.length - 1];
365
+ if (reasoningItem.id != null && previousItem?.type === "reasoning" && previousItem.id === reasoningItem.id) {
366
+ if (reasoningItem.content != null) previousItem.content = [...previousItem.content ?? [], ...reasoningItem.content];
367
+ } else input.push(reasoningItem);
368
+ break;
369
+ }
370
+ case "text": {
371
+ const providerData = getProviderData(part, providerOptionsName);
372
+ const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
373
+ const annotations = parseOutputTextAnnotations(providerData?.annotations);
374
+ if (assistantContent.length > 0 && assistantMessageId !== itemId) flushAssistantContent();
375
+ assistantMessageId = itemId;
376
+ assistantContent.push({
377
+ type: "output_text",
378
+ text: part.text,
379
+ ...annotations != null && { annotations }
380
+ });
381
+ break;
382
+ }
383
+ case "tool-call": {
384
+ flushAssistantContent();
385
+ const argumentsValue = typeof part.input === "string" ? part.input : JSON.stringify(part.input);
386
+ const providerData = getProviderData(part, providerOptionsName);
387
+ const itemId = typeof providerData?.itemId === "string" ? providerData.itemId : void 0;
388
+ const providerTool = providerToolsByName.get(part.toolName);
389
+ if (customToolId != null && providerTool?.id === customToolId) input.push({
390
+ type: "custom_tool_call",
391
+ ...itemId != null && { id: itemId },
392
+ call_id: part.toolCallId,
393
+ name: part.toolName,
394
+ input: argumentsValue
395
+ });
396
+ else input.push({
397
+ type: "function_call",
398
+ ...itemId != null && { id: itemId },
399
+ call_id: part.toolCallId,
400
+ name: part.toolName,
401
+ arguments: argumentsValue
402
+ });
403
+ break;
404
+ }
405
+ }
406
+ }
407
+ flushAssistantContent();
408
+ break;
409
+ }
410
+ case "tool": for (const part of content) if (part.type === "tool-result") {
411
+ const extensionReplay = getExtensionReplay({
412
+ part,
413
+ providerOptionsName,
414
+ extensionRegistry
415
+ });
416
+ if (extensionReplay != null) {
417
+ const replayItem = extensionReplay.item;
418
+ if (replayItem != null) {
419
+ const replayKey = `${replayItem.type}:${replayItem.id}`;
420
+ if (!replayedExtensionItems.has(replayKey)) {
421
+ input.push(asOpenResponsesExtensionRecord(replayItem));
422
+ replayedExtensionItems.add(replayKey);
423
+ }
424
+ }
425
+ continue;
426
+ }
427
+ const providerTool = providerToolsByName.get(part.toolName);
428
+ const extension = providerTool == null ? void 0 : extensionRegistry?.byProviderToolId.get(providerTool.id);
429
+ if (providerTool != null && extension != null) {
430
+ const encoded = await encodeExtensionInputPart({
431
+ extensionRegistry,
432
+ part,
433
+ providerTool
434
+ });
435
+ if (encoded == null) warnings.push({
436
+ type: "unsupported",
437
+ feature: `provider-defined tool ${providerTool.id} tool-result history`
438
+ });
439
+ else input.push(...encoded.map(asOpenResponsesExtensionRecord));
440
+ continue;
441
+ }
442
+ const output = part.output;
443
+ let contentValue;
444
+ switch (output.type) {
445
+ case "text":
446
+ case "error-text":
447
+ contentValue = output.value;
448
+ break;
449
+ case "execution-denied":
450
+ contentValue = output.reason ?? "Tool call execution denied.";
451
+ break;
452
+ case "json":
453
+ case "error-json":
454
+ contentValue = JSON.stringify(output.value);
455
+ break;
456
+ case "content": {
457
+ const contentParts = [];
458
+ for (const item of output.value) switch (item.type) {
459
+ case "text":
460
+ contentParts.push({
461
+ type: "input_text",
462
+ text: item.text
463
+ });
464
+ break;
465
+ case "file": {
466
+ const topLevel = getTopLevelMediaType(item.mediaType);
467
+ if (item.data.type === "data") {
468
+ const fullMediaType = resolveFullMediaType({ part: item });
469
+ if (topLevel === "image") contentParts.push({
470
+ type: "input_image",
471
+ image_url: `data:${fullMediaType};base64,${convertToBase64(item.data.data)}`,
472
+ detail: getImageDetail(item, providerOptionsName)
473
+ });
474
+ else contentParts.push({
475
+ type: "input_file",
476
+ filename: item.filename ?? "data",
477
+ file_data: `data:${fullMediaType};base64,${convertToBase64(item.data.data)}`
478
+ });
479
+ } else if (item.data.type === "url") {
480
+ if (topLevel === "image") contentParts.push({
481
+ type: "input_image",
482
+ image_url: item.data.url.toString(),
483
+ detail: getImageDetail(item, providerOptionsName)
484
+ });
485
+ else contentParts.push({
486
+ type: "input_file",
487
+ file_url: item.data.url.toString()
488
+ });
489
+ } else warnings.push({
490
+ type: "other",
491
+ message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
492
+ });
493
+ break;
494
+ }
495
+ default: warnings.push({
496
+ type: "other",
497
+ message: `unsupported tool content part type: ${item.type}`
498
+ });
499
+ }
500
+ contentValue = contentParts;
501
+ break;
502
+ }
503
+ }
504
+ input.push({
505
+ type: customToolId != null && providerTool?.id === customToolId ? "custom_tool_call_output" : "function_call_output",
506
+ call_id: part.toolCallId,
507
+ output: contentValue
508
+ });
509
+ }
510
+ }
511
+ return {
512
+ input,
513
+ instructions: systemMessages.length > 0 ? systemMessages.join("\n") : void 0,
514
+ warnings
515
+ };
730
516
  }
731
- async function encodeExtensionInputPart({
732
- extensionRegistry,
733
- part,
734
- providerTool
735
- }) {
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) {
740
- return void 0;
741
- }
742
- try {
743
- const value = await encodeInputItem({
744
- part,
745
- tool: providerTool
746
- });
747
- const items = value == null ? void 0 : Array.isArray(value) ? value : [value];
748
- if (items == null || items.length === 0 || !items.every(
749
- (item) => isOpenResponsesExtensionItem(item) && itemTypes.includes(item.type)
750
- )) {
751
- return void 0;
752
- }
753
- return items;
754
- } catch {
755
- return void 0;
756
- }
517
+ async function encodeExtensionInputPart({ extensionRegistry, part, providerTool }) {
518
+ const extension = extensionRegistry?.byProviderToolId.get(providerTool.id);
519
+ const encodeInputItem = extension?.encodeInputItem;
520
+ const itemTypes = extension == null ? [] : getOpenResponsesExtensionItemTypes(extension);
521
+ if (encodeInputItem == null || itemTypes.length === 0) return;
522
+ try {
523
+ const value = await encodeInputItem({
524
+ part,
525
+ tool: providerTool
526
+ });
527
+ const items = value == null ? void 0 : Array.isArray(value) ? value : [value];
528
+ if (items == null || items.length === 0 || !items.every((item) => isOpenResponsesExtensionItem(item) && itemTypes.includes(item.type))) return;
529
+ return items;
530
+ } catch {
531
+ return;
532
+ }
757
533
  }
758
- function getExtensionReplay({
759
- part,
760
- providerOptionsName,
761
- extensionRegistry
762
- }) {
763
- const extensionData = getProviderData(
764
- part,
765
- providerOptionsName
766
- )?.openResponsesExtension;
767
- if (extensionData == null || typeof extensionData !== "object" || Array.isArray(extensionData)) {
768
- return void 0;
769
- }
770
- const { id, item, itemId } = extensionData;
771
- if (typeof id !== "string") {
772
- return void 0;
773
- }
774
- const extension = extensionRegistry?.byExtensionId.get(
775
- id
776
- );
777
- if (extension == null) {
778
- return void 0;
779
- }
780
- if (isOpenResponsesExtensionItem(item) && getOpenResponsesExtensionItemTypes(extension).includes(item.type)) {
781
- return { item };
782
- }
783
- return typeof itemId === "string" ? {} : void 0;
534
+ function getExtensionReplay({ part, providerOptionsName, extensionRegistry }) {
535
+ const extensionData = getProviderData(part, providerOptionsName)?.openResponsesExtension;
536
+ if (extensionData == null || typeof extensionData !== "object" || Array.isArray(extensionData)) return;
537
+ const { id, item, itemId } = extensionData;
538
+ if (typeof id !== "string") return;
539
+ const extension = extensionRegistry?.byExtensionId.get(id);
540
+ if (extension == null) return;
541
+ if (isOpenResponsesExtensionItem(item) && getOpenResponsesExtensionItemTypes(extension).includes(item.type)) return { item };
542
+ return typeof itemId === "string" ? {} : void 0;
784
543
  }
785
544
  function getProviderData(part, providerOptionsName) {
786
- const providerData = part.providerOptions?.[providerOptionsName] ?? part.providerMetadata?.[providerOptionsName];
787
- return providerData != null && typeof providerData === "object" && !Array.isArray(providerData) ? providerData : void 0;
545
+ const providerData = part.providerOptions?.[providerOptionsName] ?? part.providerMetadata?.[providerOptionsName];
546
+ return providerData != null && typeof providerData === "object" && !Array.isArray(providerData) ? providerData : void 0;
788
547
  }
789
548
  function getImageDetail(part, providerOptionsName) {
790
- const imageDetail = getProviderData(part, providerOptionsName)?.imageDetail;
791
- return imageDetail === "low" || imageDetail === "high" || imageDetail === "auto" ? imageDetail : "auto";
549
+ const imageDetail = getProviderData(part, providerOptionsName)?.imageDetail;
550
+ return imageDetail === "low" || imageDetail === "high" || imageDetail === "auto" ? imageDetail : "auto";
792
551
  }
793
552
  function parseReasoningSummary(value) {
794
- if (!Array.isArray(value) || !value.every(
795
- (part) => part != null && typeof part === "object" && part.type === "summary_text" && typeof part.text === "string"
796
- )) {
797
- return void 0;
798
- }
799
- return value.map((part) => ({
800
- type: "summary_text",
801
- text: part.text
802
- }));
553
+ if (!Array.isArray(value) || !value.every((part) => part != null && typeof part === "object" && part.type === "summary_text" && typeof part.text === "string")) return;
554
+ return value.map((part) => ({
555
+ type: "summary_text",
556
+ text: part.text
557
+ }));
803
558
  }
804
559
  function parseReasoningContent(value) {
805
- if (!Array.isArray(value) || !value.every(
806
- (part) => part != null && typeof part === "object" && part.type === "reasoning_text" && typeof part.text === "string"
807
- )) {
808
- return void 0;
809
- }
810
- return value.map((part) => ({
811
- type: "reasoning_text",
812
- text: part.text
813
- }));
560
+ if (!Array.isArray(value) || !value.every((part) => part != null && typeof part === "object" && part.type === "reasoning_text" && typeof part.text === "string")) return;
561
+ return value.map((part) => ({
562
+ type: "reasoning_text",
563
+ text: part.text
564
+ }));
814
565
  }
815
566
  function parseOutputTextAnnotations(value) {
816
- if (!Array.isArray(value) || !value.every(
817
- (annotation) => annotation != null && typeof annotation === "object" && annotation.type === "url_citation" && typeof annotation.start_index === "number" && typeof annotation.end_index === "number" && typeof annotation.url === "string" && typeof annotation.title === "string"
818
- )) {
819
- return void 0;
820
- }
821
- return value.map((annotation) => ({
822
- type: "url_citation",
823
- start_index: annotation.start_index,
824
- end_index: annotation.end_index,
825
- url: annotation.url,
826
- title: annotation.title
827
- }));
567
+ if (!Array.isArray(value) || !value.every((annotation) => annotation != null && typeof annotation === "object" && annotation.type === "url_citation" && typeof annotation.start_index === "number" && typeof annotation.end_index === "number" && typeof annotation.url === "string" && typeof annotation.title === "string")) return;
568
+ return value.map((annotation) => ({
569
+ type: "url_citation",
570
+ start_index: annotation.start_index,
571
+ end_index: annotation.end_index,
572
+ url: annotation.url,
573
+ title: annotation.title
574
+ }));
828
575
  }
829
-
830
- // src/responses/open-responses-api.ts
831
- import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
832
- import { z as z2 } from "zod/v4";
833
- var openResponsesErrorSchema = lazySchema2(
834
- () => zodSchema2(
835
- z2.object({
836
- error: z2.object({
837
- message: z2.string(),
838
- type: z2.string().nullish(),
839
- param: z2.string().nullish(),
840
- code: z2.string().nullish()
841
- })
842
- })
843
- )
844
- );
845
-
846
- // src/responses/map-open-responses-finish-reason.ts
847
- function mapOpenResponsesFinishReason({
848
- finishReason,
849
- hasToolCalls
850
- }) {
851
- switch (finishReason) {
852
- case void 0:
853
- case null:
854
- return hasToolCalls ? "tool-calls" : "stop";
855
- case "max_output_tokens":
856
- return "length";
857
- case "content_filter":
858
- return "content-filter";
859
- default:
860
- return hasToolCalls ? "tool-calls" : "other";
861
- }
576
+ //#endregion
577
+ //#region src/responses/open-responses-api.ts
578
+ const openResponsesErrorSchema = lazySchema(() => zodSchema(z.object({ error: z.object({
579
+ message: z.string(),
580
+ type: z.string().nullish(),
581
+ param: z.string().nullish(),
582
+ code: z.string().nullish()
583
+ }) })));
584
+ //#endregion
585
+ //#region src/responses/map-open-responses-finish-reason.ts
586
+ function mapOpenResponsesFinishReason({ finishReason, hasToolCalls }) {
587
+ switch (finishReason) {
588
+ case void 0:
589
+ case null: return hasToolCalls ? "tool-calls" : "stop";
590
+ case "max_output_tokens": return "length";
591
+ case "content_filter": return "content-filter";
592
+ default: return hasToolCalls ? "tool-calls" : "other";
593
+ }
862
594
  }
863
-
864
- // src/responses/open-responses-language-model-options.ts
865
- import {
866
- lazySchema as lazySchema3,
867
- zodSchema as zodSchema3
868
- } from "@ai-sdk/provider-utils";
869
- import { z as z3 } from "zod/v4";
870
- var openResponsesLanguageModelOptions = lazySchema3(
871
- () => zodSchema3(
872
- z3.object({
873
- /**
874
- * Provider-native reasoning effort. The value is passed through to the
875
- * endpoint and takes precedence over the top-level `reasoning` setting.
876
- */
877
- reasoningEffort: z3.string().nullish(),
878
- /**
879
- * Controls reasoning summary output from the model.
880
- * Valid values: 'concise', 'detailed', 'auto'.
881
- */
882
- reasoningSummary: z3.enum(["concise", "detailed", "auto"]).nullish()
883
- })
884
- )
885
- );
886
-
887
- // src/responses/open-responses-language-model.ts
888
- var defaultFailedResponseHandler = createJsonErrorResponseHandler({
889
- errorSchema: openResponsesErrorSchema,
890
- errorToMessage: (error) => error.error.message
595
+ //#endregion
596
+ //#region src/responses/open-responses-language-model-options.ts
597
+ const openResponsesLanguageModelOptions = lazySchema(() => zodSchema(z.object({
598
+ /**
599
+ * Provider-native reasoning effort. The value is passed through to the
600
+ * endpoint and takes precedence over the top-level `reasoning` setting.
601
+ */
602
+ reasoningEffort: z.string().nullish(),
603
+ /**
604
+ * Controls reasoning summary output from the model.
605
+ * Valid values: 'concise', 'detailed', 'auto'.
606
+ */
607
+ reasoningSummary: z.enum([
608
+ "concise",
609
+ "detailed",
610
+ "auto"
611
+ ]).nullish()
612
+ })));
613
+ //#endregion
614
+ //#region src/responses/open-responses-language-model.ts
615
+ const defaultFailedResponseHandler = createJsonErrorResponseHandler({
616
+ errorSchema: openResponsesErrorSchema,
617
+ errorToMessage: (error) => error.error.message
891
618
  });
892
- var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
893
- constructor(modelId, config) {
894
- this.specificationVersion = "v4";
895
- this.supportedUrls = {
896
- "image/*": [/^https?:\/\/.*$/]
897
- };
898
- this.modelId = modelId;
899
- this.config = config;
900
- this.extensionRegistry = config.extensionRegistry ?? createOpenResponsesExtensionRegistry();
901
- }
902
- static [WORKFLOW_SERIALIZE](model) {
903
- if (model.extensionRegistry.byExtensionId.size > 0) {
904
- throw new SerializationError({
905
- message: "Open Responses models with registered extensions cannot be serialized across workflow boundaries. Recreate the provider with its extension codecs inside the workflow step."
906
- });
907
- }
908
- return serializeModelOptions({
909
- modelId: model.modelId,
910
- config: model.config
911
- });
912
- }
913
- static [WORKFLOW_DESERIALIZE](options) {
914
- return new _OpenResponsesLanguageModel(options.modelId, options.config);
915
- }
916
- get provider() {
917
- return this.config.provider;
918
- }
919
- async getArgs({
920
- maxOutputTokens,
921
- temperature,
922
- stopSequences,
923
- topP,
924
- topK,
925
- presencePenalty,
926
- frequencyPenalty,
927
- seed,
928
- reasoning,
929
- prompt,
930
- providerOptions,
931
- tools,
932
- toolChoice,
933
- responseFormat
934
- }) {
935
- const warnings = [];
936
- if (stopSequences != null) {
937
- warnings.push({ type: "unsupported", feature: "stopSequences" });
938
- }
939
- if (topK != null) {
940
- warnings.push({ type: "unsupported", feature: "topK" });
941
- }
942
- if (seed != null) {
943
- warnings.push({ type: "unsupported", feature: "seed" });
944
- }
945
- const providerToolsByName = new Map(
946
- (tools ?? []).filter((tool) => tool.type === "provider").map((tool) => [tool.name, tool])
947
- );
948
- const {
949
- input,
950
- instructions,
951
- warnings: inputWarnings
952
- } = await convertToOpenResponsesInput({
953
- prompt,
954
- providerOptionsName: this.config.providerOptionsName,
955
- extensionRegistry: this.extensionRegistry,
956
- providerToolsByName,
957
- strictResponseInput: this.config.strictResponseInput,
958
- customToolId: this.config.customToolId
959
- });
960
- warnings.push(...inputWarnings);
961
- const convertedTools = [];
962
- const encodedProviderToolsByName = /* @__PURE__ */ new Map();
963
- for (const tool of tools ?? []) {
964
- if (tool.type === "provider") {
965
- if (this.config.customToolId != null && tool.id === this.config.customToolId) {
966
- const format = tool.args.format != null && typeof tool.args.format === "object" && !Array.isArray(tool.args.format) ? tool.args.format : void 0;
967
- convertedTools.push({
968
- type: "custom",
969
- name: tool.name,
970
- description: typeof tool.args.description === "string" ? tool.args.description : void 0,
971
- format: format != null && "type" in format && format.type === "grammar" && "syntax" in format && (format.syntax === "regex" || format.syntax === "lark") && "definition" in format && typeof format.definition === "string" ? {
972
- type: "grammar",
973
- syntax: format.syntax,
974
- definition: format.definition
975
- } : format != null && "type" in format && format.type === "text" ? { type: "text" } : void 0
976
- });
977
- continue;
978
- }
979
- const extension = this.extensionRegistry.byProviderToolId.get(tool.id);
980
- let encoded;
981
- if (extension != null) {
982
- const toolType = getOpenResponsesExtensionToolType(extension);
983
- try {
984
- const fields = await extension.encodeTool({
985
- name: tool.name,
986
- args: tool.args
987
- });
988
- if (isOpenResponsesJSONObject(fields)) {
989
- encoded = {
990
- ...fields,
991
- type: toolType
992
- };
993
- }
994
- } catch {
995
- }
996
- }
997
- if (encoded == null) {
998
- warnings.push({
999
- type: "unsupported",
1000
- feature: `provider-defined tool ${tool.id}`
1001
- });
1002
- } else if (extension != null) {
1003
- convertedTools.push(asOpenResponsesExtensionRecord(encoded));
1004
- encodedProviderToolsByName.set(tool.name, {
1005
- toolType: getOpenResponsesExtensionToolType(extension),
1006
- encodeToolChoice: extension.encodeToolChoice,
1007
- tool
1008
- });
1009
- }
1010
- } else {
1011
- convertedTools.push({
1012
- type: "function",
1013
- name: tool.name,
1014
- description: tool.description,
1015
- parameters: tool.inputSchema,
1016
- ...tool.strict != null ? { strict: tool.strict } : {}
1017
- });
1018
- }
1019
- }
1020
- let convertedToolChoice;
1021
- if (toolChoice?.type === "tool") {
1022
- const registeredTool = encodedProviderToolsByName.get(
1023
- toolChoice.toolName
1024
- );
1025
- if (registeredTool == null) {
1026
- if (this.config.customToolId != null && providerToolsByName.get(toolChoice.toolName)?.id === this.config.customToolId) {
1027
- convertedToolChoice = {
1028
- type: "custom",
1029
- name: toolChoice.toolName
1030
- };
1031
- } else if (!providerToolsByName.has(toolChoice.toolName)) {
1032
- convertedToolChoice = {
1033
- type: "function",
1034
- name: toolChoice.toolName
1035
- };
1036
- }
1037
- } else {
1038
- const { encodeToolChoice, tool, toolType } = registeredTool;
1039
- let fields = {};
1040
- try {
1041
- fields = await encodeToolChoice?.({
1042
- name: tool.name,
1043
- args: tool.args
1044
- });
1045
- } catch {
1046
- fields = void 0;
1047
- }
1048
- if (encodeToolChoice != null && !isOpenResponsesJSONObject(fields)) {
1049
- warnings.push({
1050
- type: "unsupported",
1051
- feature: `tool choice for provider-defined tool ${tool.id}`
1052
- });
1053
- } else {
1054
- convertedToolChoice = asOpenResponsesExtensionRecord({
1055
- ...isOpenResponsesJSONObject(fields) ? fields : {},
1056
- type: toolType
1057
- });
1058
- }
1059
- }
1060
- } else {
1061
- convertedToolChoice = toolChoice?.type;
1062
- }
1063
- const textFormat = responseFormat?.type === "json" && this.config.structuredOutputs !== false ? responseFormat.schema != null ? {
1064
- type: "json_schema",
1065
- name: responseFormat.name ?? "response",
1066
- description: responseFormat.description,
1067
- schema: responseFormat.schema,
1068
- strict: true
1069
- } : { type: "json_object" } : void 0;
1070
- if (responseFormat?.type === "json" && this.config.structuredOutputs === false) {
1071
- warnings.push({ type: "unsupported", feature: "responseFormat" });
1072
- }
1073
- const openResponsesOptions = await parseProviderOptions({
1074
- provider: this.config.providerOptionsName,
1075
- providerOptions,
1076
- schema: openResponsesLanguageModelOptions
1077
- });
1078
- const resolvedReasoningEffort = openResponsesOptions?.reasoningEffort ?? (isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
1079
- reasoning,
1080
- effortMap: {
1081
- minimal: "low",
1082
- low: "low",
1083
- medium: "medium",
1084
- high: "high",
1085
- xhigh: "xhigh"
1086
- },
1087
- warnings
1088
- }) : void 0);
1089
- return {
1090
- body: {
1091
- model: this.modelId,
1092
- input,
1093
- instructions,
1094
- max_output_tokens: maxOutputTokens,
1095
- temperature,
1096
- top_p: topP,
1097
- presence_penalty: presencePenalty,
1098
- frequency_penalty: frequencyPenalty,
1099
- reasoning: resolvedReasoningEffort != null || openResponsesOptions?.reasoningSummary != null ? {
1100
- ...resolvedReasoningEffort != null && {
1101
- effort: resolvedReasoningEffort
1102
- },
1103
- ...openResponsesOptions?.reasoningSummary != null && {
1104
- summary: openResponsesOptions.reasoningSummary
1105
- }
1106
- } : void 0,
1107
- tools: convertedTools.length ? convertedTools : void 0,
1108
- tool_choice: convertedToolChoice,
1109
- ...textFormat != null && { text: { format: textFormat } }
1110
- },
1111
- warnings
1112
- };
1113
- }
1114
- async doGenerate(options) {
1115
- const { body, warnings } = await this.getArgs(options);
1116
- const {
1117
- responseHeaders,
1118
- value: response,
1119
- rawValue: rawResponse
1120
- } = await postJsonToApi({
1121
- url: this.config.url,
1122
- headers: combineHeaders(this.config.headers?.(), options.headers),
1123
- body,
1124
- failedResponseHandler: this.config.failedResponseHandler ?? defaultFailedResponseHandler,
1125
- successfulResponseHandler: createJsonResponseHandler(
1126
- // do not validate the response body, only apply types to the response body
1127
- jsonSchema(() => {
1128
- throw new Error("json schema not implemented");
1129
- })
1130
- ),
1131
- abortSignal: options.abortSignal,
1132
- fetch: this.config.fetch
1133
- });
1134
- if (response.error) {
1135
- const errorMetadata = this.config.getResponseErrorMetadata?.(
1136
- response.error
1137
- );
1138
- throw new APICallError({
1139
- message: response.error.message,
1140
- url: this.config.url,
1141
- requestBodyValues: body,
1142
- statusCode: errorMetadata?.statusCode ?? 400,
1143
- isRetryable: errorMetadata?.isRetryable,
1144
- responseHeaders,
1145
- responseBody: rawResponse,
1146
- data: response.error
1147
- });
1148
- }
1149
- if (response.output == null) {
1150
- const detail = response.incomplete_details?.reason ?? response.status;
1151
- throw new APICallError({
1152
- message: detail ? `Responses API returned no output (${detail})` : "Responses API returned no output",
1153
- url: this.config.url,
1154
- requestBodyValues: body,
1155
- statusCode: 500,
1156
- responseHeaders,
1157
- responseBody: rawResponse,
1158
- isRetryable: false
1159
- });
1160
- }
1161
- const content = [];
1162
- let hasToolCalls = false;
1163
- for (const part of response.output) {
1164
- switch (part.type) {
1165
- // TODO AI SDK 7 adjust reasoning in the specification to better support the reasoning structure from open responses.
1166
- case "reasoning": {
1167
- if ((part.content?.length ?? 0) > 0) {
1168
- for (const contentPart of part.content) {
1169
- content.push({
1170
- type: "reasoning",
1171
- text: contentPart.text,
1172
- providerMetadata: createReasoningProviderMetadata({
1173
- part,
1174
- providerOptionsName: this.config.providerOptionsName,
1175
- reasoningContent: [contentPart]
1176
- })
1177
- });
1178
- }
1179
- } else {
1180
- content.push({
1181
- type: "reasoning",
1182
- text: part.summary.map((summaryPart) => summaryPart.text).join(""),
1183
- providerMetadata: createReasoningProviderMetadata({
1184
- part,
1185
- providerOptionsName: this.config.providerOptionsName
1186
- })
1187
- });
1188
- }
1189
- break;
1190
- }
1191
- case "message": {
1192
- for (const contentPart of part.content) {
1193
- const annotations = getOutputTextAnnotations(contentPart);
1194
- content.push({
1195
- type: "text",
1196
- text: contentPart.text,
1197
- providerMetadata: {
1198
- [this.config.providerOptionsName]: {
1199
- itemId: part.id,
1200
- ...annotations.length > 0 && { annotations }
1201
- }
1202
- }
1203
- });
1204
- }
1205
- break;
1206
- }
1207
- case "function_call": {
1208
- hasToolCalls = true;
1209
- content.push({
1210
- type: "tool-call",
1211
- toolCallId: part.call_id,
1212
- toolName: part.name,
1213
- input: part.arguments,
1214
- providerMetadata: {
1215
- [this.config.providerOptionsName]: { itemId: part.id }
1216
- }
1217
- });
1218
- break;
1219
- }
1220
- case "custom_tool_call": {
1221
- hasToolCalls = true;
1222
- content.push({
1223
- type: "tool-call",
1224
- toolCallId: part.call_id,
1225
- toolName: part.name,
1226
- input: JSON.stringify(part.input),
1227
- providerMetadata: {
1228
- [this.config.providerOptionsName]: { itemId: part.id }
1229
- }
1230
- });
1231
- break;
1232
- }
1233
- default: {
1234
- if (!isOpenResponsesExtensionItem(part)) {
1235
- break;
1236
- }
1237
- const decoded = await decodeExtensionItem({
1238
- extensionRegistry: this.extensionRegistry,
1239
- item: part,
1240
- mode: "generate",
1241
- providerOptionsName: this.config.providerOptionsName
1242
- });
1243
- if (decoded != null) {
1244
- content.push(...decoded);
1245
- hasToolCalls ||= decoded.some((part2) => part2.type === "tool-call");
1246
- }
1247
- break;
1248
- }
1249
- }
1250
- }
1251
- const usage = response.usage;
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;
1257
- return {
1258
- content,
1259
- finishReason: {
1260
- unified: mapOpenResponsesFinishReason({
1261
- finishReason: response.incomplete_details?.reason,
1262
- hasToolCalls
1263
- }),
1264
- raw: response.incomplete_details?.reason ?? void 0
1265
- },
1266
- usage: {
1267
- inputTokens: {
1268
- total: inputTokens,
1269
- noCache: (inputTokens ?? 0) - (cachedInputTokens ?? 0) - (cacheWriteTokens ?? 0),
1270
- cacheRead: cachedInputTokens,
1271
- cacheWrite: cacheWriteTokens
1272
- },
1273
- outputTokens: {
1274
- total: outputTokens,
1275
- text: (outputTokens ?? 0) - (reasoningTokens ?? 0),
1276
- reasoning: reasoningTokens
1277
- },
1278
- raw: response.usage
1279
- },
1280
- request: { body },
1281
- response: {
1282
- id: response.id,
1283
- timestamp: new Date(response.created_at * 1e3),
1284
- modelId: response.model,
1285
- headers: responseHeaders,
1286
- body: rawResponse
1287
- },
1288
- providerMetadata: void 0,
1289
- warnings
1290
- };
1291
- }
1292
- async doStream(options) {
1293
- const { body, warnings } = await this.getArgs(options);
1294
- const { responseHeaders, value: response } = await postJsonToApi({
1295
- url: this.config.url,
1296
- headers: combineHeaders(this.config.headers?.(), options.headers),
1297
- body: {
1298
- ...body,
1299
- stream: true
1300
- },
1301
- failedResponseHandler: this.config.failedResponseHandler ?? defaultFailedResponseHandler,
1302
- successfulResponseHandler: createEventSourceResponseHandler(z4.any()),
1303
- abortSignal: options.abortSignal,
1304
- fetch: this.config.fetch
1305
- });
1306
- const usage = {
1307
- inputTokens: {
1308
- total: void 0,
1309
- noCache: void 0,
1310
- cacheRead: void 0,
1311
- cacheWrite: void 0
1312
- },
1313
- outputTokens: {
1314
- total: void 0,
1315
- text: void 0,
1316
- reasoning: void 0
1317
- }
1318
- };
1319
- const updateUsage = (responseUsage) => {
1320
- if (!responseUsage) {
1321
- return;
1322
- }
1323
- const inputTokens = responseUsage.input_tokens;
1324
- const cachedInputTokens = responseUsage.input_tokens_details?.cached_tokens;
1325
- const cacheWriteTokens = responseUsage.input_tokens_details?.cache_write_tokens;
1326
- const outputTokens = responseUsage.output_tokens;
1327
- const reasoningTokens = responseUsage.output_tokens_details?.reasoning_tokens;
1328
- usage.inputTokens = {
1329
- total: inputTokens,
1330
- noCache: (inputTokens ?? 0) - (cachedInputTokens ?? 0) - (cacheWriteTokens ?? 0),
1331
- cacheRead: cachedInputTokens,
1332
- cacheWrite: cacheWriteTokens
1333
- };
1334
- usage.outputTokens = {
1335
- total: outputTokens,
1336
- text: (outputTokens ?? 0) - (reasoningTokens ?? 0),
1337
- reasoning: reasoningTokens
1338
- };
1339
- usage.raw = responseUsage;
1340
- };
1341
- let activeReasoningId;
1342
- let hasToolCalls = false;
1343
- let finishReason = {
1344
- unified: "other",
1345
- raw: void 0
1346
- };
1347
- const toolCallsByItemId = /* @__PURE__ */ new Map();
1348
- const customToolCallsByItemId = /* @__PURE__ */ new Map();
1349
- const providerOptionsName = this.config.providerOptionsName;
1350
- const extensionRegistry = this.extensionRegistry;
1351
- const extensionStreamState = /* @__PURE__ */ new Map();
1352
- const getResponseErrorMetadata = this.config.getResponseErrorMetadata;
1353
- return {
1354
- stream: response.pipeThrough(
1355
- new TransformStream({
1356
- start(controller) {
1357
- controller.enqueue({ type: "stream-start", warnings });
1358
- },
1359
- async transform(parseResult, controller) {
1360
- if (options.includeRawChunks) {
1361
- controller.enqueue({
1362
- type: "raw",
1363
- rawValue: parseResult.rawValue
1364
- });
1365
- }
1366
- if (!parseResult.success) {
1367
- controller.enqueue({ type: "error", error: parseResult.error });
1368
- return;
1369
- }
1370
- const chunk = parseResult.value;
1371
- if (isOpenResponsesExtensionEvent(chunk)) {
1372
- const extension = extensionRegistry.byEventType.get(chunk.type);
1373
- if (extension?.decodeEvent != null) {
1374
- try {
1375
- const decoded = await extension.decodeEvent({
1376
- event: chunk,
1377
- state: extensionStreamState
1378
- });
1379
- for (const part of decoded ?? []) {
1380
- controller.enqueue(part);
1381
- hasToolCalls ||= part.type === "tool-call" || part.type === "tool-input-start";
1382
- }
1383
- } catch (error) {
1384
- controller.enqueue({ type: "error", error });
1385
- }
1386
- return;
1387
- }
1388
- }
1389
- if (chunk.type === "response.output_item.added" && chunk.item.type === "function_call") {
1390
- toolCallsByItemId.set(chunk.item.id, {
1391
- toolName: chunk.item.name,
1392
- toolCallId: chunk.item.call_id,
1393
- arguments: chunk.item.arguments
1394
- });
1395
- } else if (chunk.type === "response.function_call_arguments.delta") {
1396
- const functionCallChunk = chunk;
1397
- const toolCall = toolCallsByItemId.get(functionCallChunk.item_id);
1398
- if (toolCall == null) {
1399
- toolCallsByItemId.set(functionCallChunk.item_id, {
1400
- arguments: functionCallChunk.delta
1401
- });
1402
- return;
1403
- }
1404
- toolCall.arguments = (toolCall.arguments ?? "") + functionCallChunk.delta;
1405
- } else if (chunk.type === "response.function_call_arguments.done") {
1406
- const functionCallChunk = chunk;
1407
- const toolCall = toolCallsByItemId.get(functionCallChunk.item_id);
1408
- if (toolCall == null) {
1409
- toolCallsByItemId.set(functionCallChunk.item_id, {
1410
- arguments: functionCallChunk.arguments
1411
- });
1412
- return;
1413
- }
1414
- toolCall.arguments = functionCallChunk.arguments;
1415
- } else if (chunk.type === "response.output_item.done" && chunk.item.type === "function_call") {
1416
- const toolCall = toolCallsByItemId.get(chunk.item.id);
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 ?? "";
1420
- controller.enqueue({
1421
- type: "tool-call",
1422
- toolCallId,
1423
- toolName,
1424
- input,
1425
- providerMetadata: {
1426
- [providerOptionsName]: {
1427
- itemId: chunk.item.id
1428
- }
1429
- }
1430
- });
1431
- hasToolCalls = true;
1432
- toolCallsByItemId.delete(chunk.item.id);
1433
- } else if (chunk.type === "response.output_item.added" && chunk.item.type === "custom_tool_call") {
1434
- customToolCallsByItemId.set(chunk.item.id, {
1435
- toolName: chunk.item.name,
1436
- toolCallId: chunk.item.call_id,
1437
- input: chunk.item.input
1438
- });
1439
- controller.enqueue({
1440
- type: "tool-input-start",
1441
- id: chunk.item.call_id,
1442
- toolName: chunk.item.name
1443
- });
1444
- } else if (chunk.type === "response.custom_tool_call_input.delta") {
1445
- const toolCall = customToolCallsByItemId.get(chunk.item_id);
1446
- if (toolCall == null) {
1447
- customToolCallsByItemId.set(chunk.item_id, {
1448
- input: chunk.delta
1449
- });
1450
- } else {
1451
- toolCall.input = (toolCall.input ?? "") + chunk.delta;
1452
- }
1453
- controller.enqueue({
1454
- type: "tool-input-delta",
1455
- id: customToolCallsByItemId.get(chunk.item_id)?.toolCallId ?? chunk.item_id,
1456
- delta: chunk.delta
1457
- });
1458
- } else if (chunk.type === "response.custom_tool_call_input.done") {
1459
- const toolCall = customToolCallsByItemId.get(chunk.item_id);
1460
- if (toolCall == null) {
1461
- customToolCallsByItemId.set(chunk.item_id, {
1462
- input: chunk.input
1463
- });
1464
- } else {
1465
- toolCall.input = chunk.input;
1466
- }
1467
- } else if (chunk.type === "response.output_item.done" && chunk.item.type === "custom_tool_call") {
1468
- const toolCall = customToolCallsByItemId.get(chunk.item.id);
1469
- const toolCallId = toolCall?.toolCallId ?? chunk.item.call_id;
1470
- const input = chunk.item.input !== "" ? chunk.item.input : toolCall?.input ?? "";
1471
- controller.enqueue({ type: "tool-input-end", id: toolCallId });
1472
- controller.enqueue({
1473
- type: "tool-call",
1474
- toolCallId,
1475
- toolName: toolCall?.toolName ?? chunk.item.name,
1476
- input: JSON.stringify(input),
1477
- providerMetadata: {
1478
- [providerOptionsName]: { itemId: chunk.item.id }
1479
- }
1480
- });
1481
- hasToolCalls = true;
1482
- customToolCallsByItemId.delete(chunk.item.id);
1483
- } else if (chunk.type === "response.output_item.done" && isOpenResponsesExtensionItem(chunk.item) && extensionRegistry.byItemType.has(chunk.item.type)) {
1484
- try {
1485
- const decoded = await decodeExtensionItem({
1486
- extensionRegistry,
1487
- item: chunk.item,
1488
- mode: "stream",
1489
- providerOptionsName
1490
- });
1491
- for (const part of decoded ?? []) {
1492
- controller.enqueue(part);
1493
- hasToolCalls ||= part.type === "tool-call";
1494
- }
1495
- } catch (error) {
1496
- controller.enqueue({ type: "error", error });
1497
- }
1498
- } else if (chunk.type === "response.output_item.added" && chunk.item.type === "reasoning") {
1499
- controller.enqueue({
1500
- type: "reasoning-start",
1501
- id: chunk.item.id
1502
- });
1503
- activeReasoningId = chunk.item.id;
1504
- } else if (chunk.type === "response.reasoning_summary_text.delta" || chunk.type === "response.reasoning_text.delta") {
1505
- const reasoningChunk = chunk;
1506
- controller.enqueue({
1507
- type: "reasoning-delta",
1508
- id: reasoningChunk.item_id,
1509
- delta: reasoningChunk.delta
1510
- });
1511
- } else if (chunk.type === "response.output_item.done" && chunk.item.type === "reasoning") {
1512
- controller.enqueue({
1513
- type: "reasoning-end",
1514
- id: chunk.item.id,
1515
- providerMetadata: createReasoningProviderMetadata({
1516
- part: chunk.item,
1517
- providerOptionsName
1518
- })
1519
- });
1520
- if (activeReasoningId === chunk.item.id) {
1521
- activeReasoningId = void 0;
1522
- }
1523
- } else if (chunk.type === "response.output_item.added" && chunk.item.type === "message") {
1524
- controller.enqueue({ type: "text-start", id: chunk.item.id });
1525
- } else if (chunk.type === "response.output_text.delta") {
1526
- controller.enqueue({
1527
- type: "text-delta",
1528
- id: chunk.item_id,
1529
- delta: chunk.delta
1530
- });
1531
- } else if (chunk.type === "response.output_item.done" && chunk.item.type === "message") {
1532
- const annotations = chunk.item.content.flatMap(
1533
- getOutputTextAnnotations
1534
- );
1535
- controller.enqueue({
1536
- type: "text-end",
1537
- id: chunk.item.id,
1538
- providerMetadata: {
1539
- [providerOptionsName]: {
1540
- itemId: chunk.item.id,
1541
- ...annotations.length > 0 && { annotations }
1542
- }
1543
- }
1544
- });
1545
- } else if (chunk.type === "response.completed" || chunk.type === "response.incomplete") {
1546
- const reason = chunk.response.incomplete_details?.reason;
1547
- finishReason = {
1548
- unified: mapOpenResponsesFinishReason({
1549
- finishReason: reason,
1550
- hasToolCalls
1551
- }),
1552
- raw: reason ?? void 0
1553
- };
1554
- updateUsage(chunk.response.usage);
1555
- } else if (chunk.type === "response.failed") {
1556
- finishReason = {
1557
- unified: "error",
1558
- raw: chunk.response.error?.code ?? chunk.response.status
1559
- };
1560
- updateUsage(chunk.response.usage);
1561
- if (chunk.response.error != null) {
1562
- controller.enqueue({
1563
- type: "error",
1564
- error: createOpenResponsesStreamError({
1565
- type: chunk.type,
1566
- error: chunk.response.error,
1567
- data: chunk,
1568
- getResponseErrorMetadata
1569
- })
1570
- });
1571
- }
1572
- } else if (chunk.type === "error") {
1573
- finishReason = {
1574
- unified: "error",
1575
- raw: chunk.error.code
1576
- };
1577
- controller.enqueue({
1578
- type: "error",
1579
- error: createOpenResponsesStreamError({
1580
- type: chunk.type,
1581
- error: chunk.error,
1582
- data: chunk,
1583
- getResponseErrorMetadata
1584
- })
1585
- });
1586
- }
1587
- },
1588
- flush(controller) {
1589
- if (activeReasoningId != null) {
1590
- controller.enqueue({
1591
- type: "reasoning-end",
1592
- id: activeReasoningId
1593
- });
1594
- }
1595
- controller.enqueue({
1596
- type: "finish",
1597
- finishReason,
1598
- usage,
1599
- providerMetadata: void 0
1600
- });
1601
- }
1602
- })
1603
- ),
1604
- request: { body },
1605
- response: { headers: responseHeaders }
1606
- };
1607
- }
619
+ var OpenResponsesLanguageModel = class OpenResponsesLanguageModel {
620
+ static [WORKFLOW_SERIALIZE](model) {
621
+ if (model.extensionRegistry.byExtensionId.size > 0) throw new SerializationError({ message: "Open Responses models with registered extensions cannot be serialized across workflow boundaries. Recreate the provider with its extension codecs inside the workflow step." });
622
+ return serializeModelOptions({
623
+ modelId: model.modelId,
624
+ config: model.config
625
+ });
626
+ }
627
+ static [WORKFLOW_DESERIALIZE](options) {
628
+ return new OpenResponsesLanguageModel(options.modelId, options.config);
629
+ }
630
+ constructor(modelId, config) {
631
+ this.specificationVersion = "v4";
632
+ this.supportedUrls = { "image/*": [/^https?:\/\/.*$/] };
633
+ this.modelId = modelId;
634
+ this.config = config;
635
+ this.extensionRegistry = config.extensionRegistry ?? createOpenResponsesExtensionRegistry();
636
+ }
637
+ get provider() {
638
+ return this.config.provider;
639
+ }
640
+ async getArgs({ maxOutputTokens, temperature, stopSequences, topP, topK, presencePenalty, frequencyPenalty, seed, reasoning, prompt, providerOptions, tools, toolChoice, responseFormat }) {
641
+ const warnings = [];
642
+ if (stopSequences != null) warnings.push({
643
+ type: "unsupported",
644
+ feature: "stopSequences"
645
+ });
646
+ if (topK != null) warnings.push({
647
+ type: "unsupported",
648
+ feature: "topK"
649
+ });
650
+ if (seed != null) warnings.push({
651
+ type: "unsupported",
652
+ feature: "seed"
653
+ });
654
+ const providerToolsByName = new Map((tools ?? []).filter((tool) => tool.type === "provider").map((tool) => [tool.name, tool]));
655
+ const { input, instructions, warnings: inputWarnings } = await convertToOpenResponsesInput({
656
+ prompt,
657
+ providerOptionsName: this.config.providerOptionsName,
658
+ extensionRegistry: this.extensionRegistry,
659
+ providerToolsByName,
660
+ strictResponseInput: this.config.strictResponseInput,
661
+ customToolId: this.config.customToolId
662
+ });
663
+ warnings.push(...inputWarnings);
664
+ const convertedTools = [];
665
+ const encodedProviderToolsByName = /* @__PURE__ */ new Map();
666
+ for (const tool of tools ?? []) if (tool.type === "provider") {
667
+ if (this.config.customToolId != null && tool.id === this.config.customToolId) {
668
+ const format = tool.args.format != null && typeof tool.args.format === "object" && !Array.isArray(tool.args.format) ? tool.args.format : void 0;
669
+ convertedTools.push({
670
+ type: "custom",
671
+ name: tool.name,
672
+ description: typeof tool.args.description === "string" ? tool.args.description : void 0,
673
+ format: format != null && "type" in format && format.type === "grammar" && "syntax" in format && (format.syntax === "regex" || format.syntax === "lark") && "definition" in format && typeof format.definition === "string" ? {
674
+ type: "grammar",
675
+ syntax: format.syntax,
676
+ definition: format.definition
677
+ } : format != null && "type" in format && format.type === "text" ? { type: "text" } : void 0
678
+ });
679
+ continue;
680
+ }
681
+ const extension = this.extensionRegistry.byProviderToolId.get(tool.id);
682
+ let encoded;
683
+ if (extension != null) {
684
+ const toolType = getOpenResponsesExtensionToolType(extension);
685
+ try {
686
+ const fields = await extension.encodeTool({
687
+ name: tool.name,
688
+ args: tool.args
689
+ });
690
+ if (isOpenResponsesJSONObject(fields)) encoded = {
691
+ ...fields,
692
+ type: toolType
693
+ };
694
+ } catch {}
695
+ }
696
+ if (encoded == null) warnings.push({
697
+ type: "unsupported",
698
+ feature: `provider-defined tool ${tool.id}`
699
+ });
700
+ else if (extension != null) {
701
+ convertedTools.push(asOpenResponsesExtensionRecord(encoded));
702
+ encodedProviderToolsByName.set(tool.name, {
703
+ toolType: getOpenResponsesExtensionToolType(extension),
704
+ encodeToolChoice: extension.encodeToolChoice,
705
+ tool
706
+ });
707
+ }
708
+ } else convertedTools.push({
709
+ type: "function",
710
+ name: tool.name,
711
+ description: tool.description,
712
+ parameters: tool.inputSchema,
713
+ ...tool.strict != null ? { strict: tool.strict } : {}
714
+ });
715
+ let convertedToolChoice;
716
+ if (toolChoice?.type === "tool") {
717
+ const registeredTool = encodedProviderToolsByName.get(toolChoice.toolName);
718
+ if (registeredTool == null) {
719
+ if (this.config.customToolId != null && providerToolsByName.get(toolChoice.toolName)?.id === this.config.customToolId) convertedToolChoice = {
720
+ type: "custom",
721
+ name: toolChoice.toolName
722
+ };
723
+ else if (!providerToolsByName.has(toolChoice.toolName)) convertedToolChoice = {
724
+ type: "function",
725
+ name: toolChoice.toolName
726
+ };
727
+ } else {
728
+ const { encodeToolChoice, tool, toolType } = registeredTool;
729
+ let fields = {};
730
+ try {
731
+ fields = await encodeToolChoice?.({
732
+ name: tool.name,
733
+ args: tool.args
734
+ });
735
+ } catch {
736
+ fields = void 0;
737
+ }
738
+ if (encodeToolChoice != null && !isOpenResponsesJSONObject(fields)) warnings.push({
739
+ type: "unsupported",
740
+ feature: `tool choice for provider-defined tool ${tool.id}`
741
+ });
742
+ else convertedToolChoice = asOpenResponsesExtensionRecord({
743
+ ...isOpenResponsesJSONObject(fields) ? fields : {},
744
+ type: toolType
745
+ });
746
+ }
747
+ } else convertedToolChoice = toolChoice?.type;
748
+ const textFormat = responseFormat?.type === "json" && this.config.structuredOutputs !== false ? responseFormat.schema != null ? {
749
+ type: "json_schema",
750
+ name: responseFormat.name ?? "response",
751
+ description: responseFormat.description,
752
+ schema: responseFormat.schema,
753
+ strict: true
754
+ } : { type: "json_object" } : void 0;
755
+ if (responseFormat?.type === "json" && this.config.structuredOutputs === false) warnings.push({
756
+ type: "unsupported",
757
+ feature: "responseFormat"
758
+ });
759
+ const openResponsesOptions = await parseProviderOptions({
760
+ provider: this.config.providerOptionsName,
761
+ providerOptions,
762
+ schema: openResponsesLanguageModelOptions
763
+ });
764
+ const resolvedReasoningEffort = openResponsesOptions?.reasoningEffort ?? (isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
765
+ reasoning,
766
+ effortMap: {
767
+ minimal: "low",
768
+ low: "low",
769
+ medium: "medium",
770
+ high: "high",
771
+ xhigh: "xhigh"
772
+ },
773
+ warnings
774
+ }) : void 0);
775
+ return {
776
+ body: {
777
+ model: this.modelId,
778
+ input,
779
+ instructions,
780
+ max_output_tokens: maxOutputTokens,
781
+ temperature,
782
+ top_p: topP,
783
+ presence_penalty: presencePenalty,
784
+ frequency_penalty: frequencyPenalty,
785
+ reasoning: resolvedReasoningEffort != null || openResponsesOptions?.reasoningSummary != null ? {
786
+ ...resolvedReasoningEffort != null && { effort: resolvedReasoningEffort },
787
+ ...openResponsesOptions?.reasoningSummary != null && { summary: openResponsesOptions.reasoningSummary }
788
+ } : void 0,
789
+ tools: convertedTools.length ? convertedTools : void 0,
790
+ tool_choice: convertedToolChoice,
791
+ ...textFormat != null && { text: { format: textFormat } }
792
+ },
793
+ warnings
794
+ };
795
+ }
796
+ async doGenerate(options) {
797
+ const { body, warnings } = await this.getArgs(options);
798
+ const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
799
+ url: this.config.url,
800
+ headers: combineHeaders(this.config.headers?.(), options.headers),
801
+ body,
802
+ failedResponseHandler: this.config.failedResponseHandler ?? defaultFailedResponseHandler,
803
+ successfulResponseHandler: createJsonResponseHandler(jsonSchema(() => {
804
+ throw new Error("json schema not implemented");
805
+ })),
806
+ abortSignal: options.abortSignal,
807
+ fetch: this.config.fetch
808
+ });
809
+ if (response.error) {
810
+ const errorMetadata = this.config.getResponseErrorMetadata?.(response.error);
811
+ throw new APICallError({
812
+ message: response.error.message,
813
+ url: this.config.url,
814
+ requestBodyValues: body,
815
+ statusCode: errorMetadata?.statusCode ?? 400,
816
+ isRetryable: errorMetadata?.isRetryable,
817
+ responseHeaders,
818
+ responseBody: rawResponse,
819
+ data: response.error
820
+ });
821
+ }
822
+ if (response.output == null) {
823
+ const detail = response.incomplete_details?.reason ?? response.status;
824
+ throw new APICallError({
825
+ message: detail ? `Responses API returned no output (${detail})` : "Responses API returned no output",
826
+ url: this.config.url,
827
+ requestBodyValues: body,
828
+ statusCode: 500,
829
+ responseHeaders,
830
+ responseBody: rawResponse,
831
+ isRetryable: false
832
+ });
833
+ }
834
+ const content = [];
835
+ let hasToolCalls = false;
836
+ for (const part of response.output) switch (part.type) {
837
+ case "reasoning":
838
+ if ((part.content?.length ?? 0) > 0) for (const contentPart of part.content) content.push({
839
+ type: "reasoning",
840
+ text: contentPart.text,
841
+ providerMetadata: createReasoningProviderMetadata({
842
+ part,
843
+ providerOptionsName: this.config.providerOptionsName,
844
+ reasoningContent: [contentPart]
845
+ })
846
+ });
847
+ else content.push({
848
+ type: "reasoning",
849
+ text: part.summary.map((summaryPart) => summaryPart.text).join(""),
850
+ providerMetadata: createReasoningProviderMetadata({
851
+ part,
852
+ providerOptionsName: this.config.providerOptionsName
853
+ })
854
+ });
855
+ break;
856
+ case "message":
857
+ for (const contentPart of part.content) {
858
+ const annotations = getOutputTextAnnotations(contentPart);
859
+ content.push({
860
+ type: "text",
861
+ text: contentPart.text,
862
+ providerMetadata: { [this.config.providerOptionsName]: {
863
+ itemId: part.id,
864
+ ...annotations.length > 0 && { annotations }
865
+ } }
866
+ });
867
+ }
868
+ break;
869
+ case "function_call":
870
+ hasToolCalls = true;
871
+ content.push({
872
+ type: "tool-call",
873
+ toolCallId: part.call_id,
874
+ toolName: part.name,
875
+ input: part.arguments,
876
+ providerMetadata: { [this.config.providerOptionsName]: { itemId: part.id } }
877
+ });
878
+ break;
879
+ case "custom_tool_call":
880
+ hasToolCalls = true;
881
+ content.push({
882
+ type: "tool-call",
883
+ toolCallId: part.call_id,
884
+ toolName: part.name,
885
+ input: JSON.stringify(part.input),
886
+ providerMetadata: { [this.config.providerOptionsName]: { itemId: part.id } }
887
+ });
888
+ break;
889
+ default: {
890
+ if (!isOpenResponsesExtensionItem(part)) break;
891
+ const decoded = await decodeExtensionItem({
892
+ extensionRegistry: this.extensionRegistry,
893
+ item: part,
894
+ mode: "generate",
895
+ providerOptionsName: this.config.providerOptionsName
896
+ });
897
+ if (decoded != null) {
898
+ content.push(...decoded);
899
+ hasToolCalls ||= decoded.some((part) => part.type === "tool-call");
900
+ }
901
+ break;
902
+ }
903
+ }
904
+ const usage = response.usage;
905
+ const inputTokens = usage?.input_tokens;
906
+ const cachedInputTokens = usage?.input_tokens_details?.cached_tokens;
907
+ const cacheWriteTokens = usage?.input_tokens_details?.cache_write_tokens;
908
+ const outputTokens = usage?.output_tokens;
909
+ const reasoningTokens = usage?.output_tokens_details?.reasoning_tokens;
910
+ return {
911
+ content,
912
+ finishReason: {
913
+ unified: mapOpenResponsesFinishReason({
914
+ finishReason: response.incomplete_details?.reason,
915
+ hasToolCalls
916
+ }),
917
+ raw: response.incomplete_details?.reason ?? void 0
918
+ },
919
+ usage: {
920
+ inputTokens: {
921
+ total: inputTokens,
922
+ noCache: (inputTokens ?? 0) - (cachedInputTokens ?? 0) - (cacheWriteTokens ?? 0),
923
+ cacheRead: cachedInputTokens,
924
+ cacheWrite: cacheWriteTokens
925
+ },
926
+ outputTokens: {
927
+ total: outputTokens,
928
+ text: (outputTokens ?? 0) - (reasoningTokens ?? 0),
929
+ reasoning: reasoningTokens
930
+ },
931
+ raw: response.usage
932
+ },
933
+ request: { body },
934
+ response: {
935
+ id: response.id,
936
+ timestamp: /* @__PURE__ */ new Date(response.created_at * 1e3),
937
+ modelId: response.model,
938
+ headers: responseHeaders,
939
+ body: rawResponse
940
+ },
941
+ providerMetadata: void 0,
942
+ warnings
943
+ };
944
+ }
945
+ async doStream(options) {
946
+ const { body, warnings } = await this.getArgs(options);
947
+ const { responseHeaders, value: response } = await postJsonToApi({
948
+ url: this.config.url,
949
+ headers: combineHeaders(this.config.headers?.(), options.headers),
950
+ body: {
951
+ ...body,
952
+ stream: true
953
+ },
954
+ failedResponseHandler: this.config.failedResponseHandler ?? defaultFailedResponseHandler,
955
+ successfulResponseHandler: createEventSourceResponseHandler(z.any()),
956
+ abortSignal: options.abortSignal,
957
+ fetch: this.config.fetch
958
+ });
959
+ const usage = {
960
+ inputTokens: {
961
+ total: void 0,
962
+ noCache: void 0,
963
+ cacheRead: void 0,
964
+ cacheWrite: void 0
965
+ },
966
+ outputTokens: {
967
+ total: void 0,
968
+ text: void 0,
969
+ reasoning: void 0
970
+ }
971
+ };
972
+ const updateUsage = (responseUsage) => {
973
+ if (!responseUsage) return;
974
+ const inputTokens = responseUsage.input_tokens;
975
+ const cachedInputTokens = responseUsage.input_tokens_details?.cached_tokens;
976
+ const cacheWriteTokens = responseUsage.input_tokens_details?.cache_write_tokens;
977
+ const outputTokens = responseUsage.output_tokens;
978
+ const reasoningTokens = responseUsage.output_tokens_details?.reasoning_tokens;
979
+ usage.inputTokens = {
980
+ total: inputTokens,
981
+ noCache: (inputTokens ?? 0) - (cachedInputTokens ?? 0) - (cacheWriteTokens ?? 0),
982
+ cacheRead: cachedInputTokens,
983
+ cacheWrite: cacheWriteTokens
984
+ };
985
+ usage.outputTokens = {
986
+ total: outputTokens,
987
+ text: (outputTokens ?? 0) - (reasoningTokens ?? 0),
988
+ reasoning: reasoningTokens
989
+ };
990
+ usage.raw = responseUsage;
991
+ };
992
+ let activeReasoningId;
993
+ let hasToolCalls = false;
994
+ let finishReason = {
995
+ unified: "other",
996
+ raw: void 0
997
+ };
998
+ const toolCallsByItemId = /* @__PURE__ */ new Map();
999
+ const customToolCallsByItemId = /* @__PURE__ */ new Map();
1000
+ const providerOptionsName = this.config.providerOptionsName;
1001
+ const extensionRegistry = this.extensionRegistry;
1002
+ const extensionStreamState = /* @__PURE__ */ new Map();
1003
+ const getResponseErrorMetadata = this.config.getResponseErrorMetadata;
1004
+ return {
1005
+ stream: response.pipeThrough(new TransformStream({
1006
+ start(controller) {
1007
+ controller.enqueue({
1008
+ type: "stream-start",
1009
+ warnings
1010
+ });
1011
+ },
1012
+ async transform(parseResult, controller) {
1013
+ if (options.includeRawChunks) controller.enqueue({
1014
+ type: "raw",
1015
+ rawValue: parseResult.rawValue
1016
+ });
1017
+ if (!parseResult.success) {
1018
+ controller.enqueue({
1019
+ type: "error",
1020
+ error: parseResult.error
1021
+ });
1022
+ return;
1023
+ }
1024
+ const chunk = parseResult.value;
1025
+ if (isOpenResponsesExtensionEvent(chunk)) {
1026
+ const extension = extensionRegistry.byEventType.get(chunk.type);
1027
+ if (extension?.decodeEvent != null) {
1028
+ try {
1029
+ const decoded = await extension.decodeEvent({
1030
+ event: chunk,
1031
+ state: extensionStreamState
1032
+ });
1033
+ for (const part of decoded ?? []) {
1034
+ controller.enqueue(part);
1035
+ hasToolCalls ||= part.type === "tool-call" || part.type === "tool-input-start";
1036
+ }
1037
+ } catch (error) {
1038
+ controller.enqueue({
1039
+ type: "error",
1040
+ error
1041
+ });
1042
+ }
1043
+ return;
1044
+ }
1045
+ }
1046
+ if (chunk.type === "response.output_item.added" && chunk.item.type === "function_call") toolCallsByItemId.set(chunk.item.id, {
1047
+ toolName: chunk.item.name,
1048
+ toolCallId: chunk.item.call_id,
1049
+ arguments: chunk.item.arguments
1050
+ });
1051
+ else if (chunk.type === "response.function_call_arguments.delta") {
1052
+ const functionCallChunk = chunk;
1053
+ const toolCall = toolCallsByItemId.get(functionCallChunk.item_id);
1054
+ if (toolCall == null) {
1055
+ toolCallsByItemId.set(functionCallChunk.item_id, { arguments: functionCallChunk.delta });
1056
+ return;
1057
+ }
1058
+ toolCall.arguments = (toolCall.arguments ?? "") + functionCallChunk.delta;
1059
+ } else if (chunk.type === "response.function_call_arguments.done") {
1060
+ const functionCallChunk = chunk;
1061
+ const toolCall = toolCallsByItemId.get(functionCallChunk.item_id);
1062
+ if (toolCall == null) {
1063
+ toolCallsByItemId.set(functionCallChunk.item_id, { arguments: functionCallChunk.arguments });
1064
+ return;
1065
+ }
1066
+ toolCall.arguments = functionCallChunk.arguments;
1067
+ } else if (chunk.type === "response.output_item.done" && chunk.item.type === "function_call") {
1068
+ const toolCall = toolCallsByItemId.get(chunk.item.id);
1069
+ const toolName = toolCall?.toolName ?? chunk.item.name;
1070
+ const toolCallId = toolCall?.toolCallId ?? chunk.item.call_id;
1071
+ const input = chunk.item.arguments !== "" ? chunk.item.arguments : toolCall?.arguments ?? "";
1072
+ controller.enqueue({
1073
+ type: "tool-call",
1074
+ toolCallId,
1075
+ toolName,
1076
+ input,
1077
+ providerMetadata: { [providerOptionsName]: { itemId: chunk.item.id } }
1078
+ });
1079
+ hasToolCalls = true;
1080
+ toolCallsByItemId.delete(chunk.item.id);
1081
+ } else if (chunk.type === "response.output_item.added" && chunk.item.type === "custom_tool_call") {
1082
+ customToolCallsByItemId.set(chunk.item.id, {
1083
+ toolName: chunk.item.name,
1084
+ toolCallId: chunk.item.call_id,
1085
+ input: chunk.item.input
1086
+ });
1087
+ controller.enqueue({
1088
+ type: "tool-input-start",
1089
+ id: chunk.item.call_id,
1090
+ toolName: chunk.item.name
1091
+ });
1092
+ } else if (chunk.type === "response.custom_tool_call_input.delta") {
1093
+ const toolCall = customToolCallsByItemId.get(chunk.item_id);
1094
+ if (toolCall == null) customToolCallsByItemId.set(chunk.item_id, { input: chunk.delta });
1095
+ else toolCall.input = (toolCall.input ?? "") + chunk.delta;
1096
+ controller.enqueue({
1097
+ type: "tool-input-delta",
1098
+ id: customToolCallsByItemId.get(chunk.item_id)?.toolCallId ?? chunk.item_id,
1099
+ delta: chunk.delta
1100
+ });
1101
+ } else if (chunk.type === "response.custom_tool_call_input.done") {
1102
+ const toolCall = customToolCallsByItemId.get(chunk.item_id);
1103
+ if (toolCall == null) customToolCallsByItemId.set(chunk.item_id, { input: chunk.input });
1104
+ else toolCall.input = chunk.input;
1105
+ } else if (chunk.type === "response.output_item.done" && chunk.item.type === "custom_tool_call") {
1106
+ const toolCall = customToolCallsByItemId.get(chunk.item.id);
1107
+ const toolCallId = toolCall?.toolCallId ?? chunk.item.call_id;
1108
+ const input = chunk.item.input !== "" ? chunk.item.input : toolCall?.input ?? "";
1109
+ controller.enqueue({
1110
+ type: "tool-input-end",
1111
+ id: toolCallId
1112
+ });
1113
+ controller.enqueue({
1114
+ type: "tool-call",
1115
+ toolCallId,
1116
+ toolName: toolCall?.toolName ?? chunk.item.name,
1117
+ input: JSON.stringify(input),
1118
+ providerMetadata: { [providerOptionsName]: { itemId: chunk.item.id } }
1119
+ });
1120
+ hasToolCalls = true;
1121
+ customToolCallsByItemId.delete(chunk.item.id);
1122
+ } else if (chunk.type === "response.output_item.done" && isOpenResponsesExtensionItem(chunk.item) && extensionRegistry.byItemType.has(chunk.item.type)) try {
1123
+ const decoded = await decodeExtensionItem({
1124
+ extensionRegistry,
1125
+ item: chunk.item,
1126
+ mode: "stream",
1127
+ providerOptionsName
1128
+ });
1129
+ for (const part of decoded ?? []) {
1130
+ controller.enqueue(part);
1131
+ hasToolCalls ||= part.type === "tool-call";
1132
+ }
1133
+ } catch (error) {
1134
+ controller.enqueue({
1135
+ type: "error",
1136
+ error
1137
+ });
1138
+ }
1139
+ else if (chunk.type === "response.output_item.added" && chunk.item.type === "reasoning") {
1140
+ controller.enqueue({
1141
+ type: "reasoning-start",
1142
+ id: chunk.item.id
1143
+ });
1144
+ activeReasoningId = chunk.item.id;
1145
+ } else if (chunk.type === "response.reasoning_summary_text.delta" || chunk.type === "response.reasoning_text.delta") {
1146
+ const reasoningChunk = chunk;
1147
+ controller.enqueue({
1148
+ type: "reasoning-delta",
1149
+ id: reasoningChunk.item_id,
1150
+ delta: reasoningChunk.delta
1151
+ });
1152
+ } else if (chunk.type === "response.output_item.done" && chunk.item.type === "reasoning") {
1153
+ controller.enqueue({
1154
+ type: "reasoning-end",
1155
+ id: chunk.item.id,
1156
+ providerMetadata: createReasoningProviderMetadata({
1157
+ part: chunk.item,
1158
+ providerOptionsName
1159
+ })
1160
+ });
1161
+ if (activeReasoningId === chunk.item.id) activeReasoningId = void 0;
1162
+ } else if (chunk.type === "response.output_item.added" && chunk.item.type === "message") controller.enqueue({
1163
+ type: "text-start",
1164
+ id: chunk.item.id
1165
+ });
1166
+ else if (chunk.type === "response.output_text.delta") controller.enqueue({
1167
+ type: "text-delta",
1168
+ id: chunk.item_id,
1169
+ delta: chunk.delta
1170
+ });
1171
+ else if (chunk.type === "response.output_item.done" && chunk.item.type === "message") {
1172
+ const annotations = chunk.item.content.flatMap(getOutputTextAnnotations);
1173
+ controller.enqueue({
1174
+ type: "text-end",
1175
+ id: chunk.item.id,
1176
+ providerMetadata: { [providerOptionsName]: {
1177
+ itemId: chunk.item.id,
1178
+ ...annotations.length > 0 && { annotations }
1179
+ } }
1180
+ });
1181
+ } else if (chunk.type === "response.completed" || chunk.type === "response.incomplete") {
1182
+ const reason = chunk.response.incomplete_details?.reason;
1183
+ finishReason = {
1184
+ unified: mapOpenResponsesFinishReason({
1185
+ finishReason: reason,
1186
+ hasToolCalls
1187
+ }),
1188
+ raw: reason ?? void 0
1189
+ };
1190
+ updateUsage(chunk.response.usage);
1191
+ } else if (chunk.type === "response.failed") {
1192
+ finishReason = {
1193
+ unified: "error",
1194
+ raw: chunk.response.error?.code ?? chunk.response.status
1195
+ };
1196
+ updateUsage(chunk.response.usage);
1197
+ if (chunk.response.error != null) controller.enqueue({
1198
+ type: "error",
1199
+ error: createOpenResponsesStreamError({
1200
+ type: chunk.type,
1201
+ error: chunk.response.error,
1202
+ data: chunk,
1203
+ getResponseErrorMetadata
1204
+ })
1205
+ });
1206
+ } else if (chunk.type === "error") {
1207
+ finishReason = {
1208
+ unified: "error",
1209
+ raw: chunk.error.code
1210
+ };
1211
+ controller.enqueue({
1212
+ type: "error",
1213
+ error: createOpenResponsesStreamError({
1214
+ type: chunk.type,
1215
+ error: chunk.error,
1216
+ data: chunk,
1217
+ getResponseErrorMetadata
1218
+ })
1219
+ });
1220
+ }
1221
+ },
1222
+ flush(controller) {
1223
+ if (activeReasoningId != null) controller.enqueue({
1224
+ type: "reasoning-end",
1225
+ id: activeReasoningId
1226
+ });
1227
+ controller.enqueue({
1228
+ type: "finish",
1229
+ finishReason,
1230
+ usage,
1231
+ providerMetadata: void 0
1232
+ });
1233
+ }
1234
+ })),
1235
+ request: { body },
1236
+ response: { headers: responseHeaders }
1237
+ };
1238
+ }
1608
1239
  };
1609
- function createOpenResponsesStreamError({
1610
- type,
1611
- error,
1612
- data,
1613
- getResponseErrorMetadata
1614
- }) {
1615
- return createProviderStreamError({
1616
- message: error.message,
1617
- type,
1618
- code: error.code,
1619
- ...getResponseErrorMetadata?.(error),
1620
- data
1621
- });
1240
+ function createOpenResponsesStreamError({ type, error, data, getResponseErrorMetadata }) {
1241
+ return createProviderStreamError({
1242
+ message: error.message,
1243
+ type,
1244
+ code: error.code,
1245
+ ...getResponseErrorMetadata?.(error),
1246
+ data
1247
+ });
1622
1248
  }
1623
- function createReasoningProviderMetadata({
1624
- part,
1625
- providerOptionsName,
1626
- reasoningContent = part.content
1627
- }) {
1628
- return {
1629
- [providerOptionsName]: {
1630
- itemId: part.id,
1631
- reasoningSummary: part.summary.map((summaryPart) => ({
1632
- type: "summary_text",
1633
- text: summaryPart.text
1634
- })),
1635
- reasoningContent: reasoningContent == null ? null : reasoningContent.map((contentPart) => ({
1636
- type: "reasoning_text",
1637
- text: contentPart.text
1638
- })),
1639
- ...part.encrypted_content != null && {
1640
- reasoningEncryptedContent: part.encrypted_content
1641
- }
1642
- }
1643
- };
1249
+ function createReasoningProviderMetadata({ part, providerOptionsName, reasoningContent = part.content }) {
1250
+ return { [providerOptionsName]: {
1251
+ itemId: part.id,
1252
+ reasoningSummary: part.summary.map((summaryPart) => ({
1253
+ type: "summary_text",
1254
+ text: summaryPart.text
1255
+ })),
1256
+ reasoningContent: reasoningContent == null ? null : reasoningContent.map((contentPart) => ({
1257
+ type: "reasoning_text",
1258
+ text: contentPart.text
1259
+ })),
1260
+ ...part.encrypted_content != null && { reasoningEncryptedContent: part.encrypted_content }
1261
+ } };
1644
1262
  }
1645
- async function decodeExtensionItem({
1646
- extensionRegistry,
1647
- item,
1648
- mode,
1649
- providerOptionsName
1650
- }) {
1651
- const extension = extensionRegistry.byItemType.get(item.type);
1652
- if (extension == null) {
1653
- return void 0;
1654
- }
1655
- const decoded = await extension.decodeItem({ item, mode });
1656
- if (decoded == null) {
1657
- return void 0;
1658
- }
1659
- return [
1660
- createExtensionReplayCarrier({
1661
- extension,
1662
- item,
1663
- providerOptionsName
1664
- }),
1665
- ...decoded.map(
1666
- (part) => addExtensionItemReferenceMetadata({
1667
- extension,
1668
- item,
1669
- part,
1670
- providerOptionsName
1671
- })
1672
- )
1673
- ];
1263
+ async function decodeExtensionItem({ extensionRegistry, item, mode, providerOptionsName }) {
1264
+ const extension = extensionRegistry.byItemType.get(item.type);
1265
+ if (extension == null) return;
1266
+ const decoded = await extension.decodeItem({
1267
+ item,
1268
+ mode
1269
+ });
1270
+ if (decoded == null) return;
1271
+ return [createExtensionReplayCarrier({
1272
+ extension,
1273
+ item,
1274
+ providerOptionsName
1275
+ }), ...decoded.map((part) => addExtensionItemReferenceMetadata({
1276
+ extension,
1277
+ item,
1278
+ part,
1279
+ providerOptionsName
1280
+ }))];
1674
1281
  }
1675
- function createExtensionReplayCarrier({
1676
- extension,
1677
- item,
1678
- providerOptionsName
1679
- }) {
1680
- return {
1681
- type: "custom",
1682
- kind: "open-responses.extension-replay",
1683
- providerMetadata: {
1684
- [providerOptionsName]: {
1685
- openResponsesExtension: {
1686
- id: extension.id,
1687
- item
1688
- }
1689
- }
1690
- }
1691
- };
1282
+ function createExtensionReplayCarrier({ extension, item, providerOptionsName }) {
1283
+ return {
1284
+ type: "custom",
1285
+ kind: "open-responses.extension-replay",
1286
+ providerMetadata: { [providerOptionsName]: { openResponsesExtension: {
1287
+ id: extension.id,
1288
+ item
1289
+ } } }
1290
+ };
1692
1291
  }
1693
- function addExtensionItemReferenceMetadata({
1694
- extension,
1695
- item,
1696
- part,
1697
- providerOptionsName
1698
- }) {
1699
- const providerMetadata = part.providerMetadata ?? {};
1700
- return {
1701
- ...part,
1702
- providerMetadata: {
1703
- ...providerMetadata,
1704
- [providerOptionsName]: {
1705
- ...providerMetadata[providerOptionsName],
1706
- openResponsesExtension: {
1707
- id: extension.id,
1708
- itemId: item.id
1709
- }
1710
- }
1711
- }
1712
- };
1292
+ function addExtensionItemReferenceMetadata({ extension, item, part, providerOptionsName }) {
1293
+ const providerMetadata = part.providerMetadata ?? {};
1294
+ return {
1295
+ ...part,
1296
+ providerMetadata: {
1297
+ ...providerMetadata,
1298
+ [providerOptionsName]: {
1299
+ ...providerMetadata[providerOptionsName],
1300
+ openResponsesExtension: {
1301
+ id: extension.id,
1302
+ itemId: item.id
1303
+ }
1304
+ }
1305
+ }
1306
+ };
1713
1307
  }
1714
1308
  function getOutputTextAnnotations(value) {
1715
- if (value == null || typeof value !== "object" || !("annotations" in value) || !Array.isArray(value.annotations) || !value.annotations.every(
1716
- (annotation) => annotation != null && typeof annotation === "object" && annotation.type === "url_citation" && typeof annotation.start_index === "number" && typeof annotation.end_index === "number" && typeof annotation.url === "string" && typeof annotation.title === "string"
1717
- )) {
1718
- return [];
1719
- }
1720
- return value.annotations.map((annotation) => ({
1721
- type: "url_citation",
1722
- start_index: annotation.start_index,
1723
- end_index: annotation.end_index,
1724
- url: annotation.url,
1725
- title: annotation.title
1726
- }));
1309
+ if (value == null || typeof value !== "object" || !("annotations" in value) || !Array.isArray(value.annotations) || !value.annotations.every((annotation) => annotation != null && typeof annotation === "object" && annotation.type === "url_citation" && typeof annotation.start_index === "number" && typeof annotation.end_index === "number" && typeof annotation.url === "string" && typeof annotation.title === "string")) return [];
1310
+ return value.annotations.map((annotation) => ({
1311
+ type: "url_citation",
1312
+ start_index: annotation.start_index,
1313
+ end_index: annotation.end_index,
1314
+ url: annotation.url,
1315
+ title: annotation.title
1316
+ }));
1727
1317
  }
1728
-
1729
- // src/open-responses-provider.ts
1318
+ //#endregion
1319
+ //#region src/open-responses-provider.ts
1730
1320
  function createOpenResponses(options) {
1731
- const providerName = options.name;
1732
- const customToolId = options.customToolId ?? "open-responses.custom";
1733
- const extensionRegistry = createOpenResponsesExtensionRegistry(
1734
- options.experimental_extensions
1735
- );
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
- );
1745
- const createResponsesModel = (modelId) => {
1746
- return new OpenResponsesLanguageModel(modelId, {
1747
- provider: `${providerName}.responses`,
1748
- providerOptionsName: providerName,
1749
- headers: getHeaders,
1750
- url: options.url,
1751
- fetch: options.fetch,
1752
- failedResponseHandler: options.failedResponseHandler,
1753
- getResponseErrorMetadata: options.getResponseErrorMetadata,
1754
- generateId: () => generateId(),
1755
- extensionRegistry,
1756
- strictResponseInput: options.strictResponseInput,
1757
- customToolId,
1758
- structuredOutputs: options.structuredOutputs
1759
- });
1760
- };
1761
- const createLanguageModel = (modelId) => {
1762
- if (new.target) {
1763
- throw new Error(
1764
- "The OpenAI model function cannot be called with the new keyword."
1765
- );
1766
- }
1767
- return createResponsesModel(modelId);
1768
- };
1769
- const provider = function(modelId) {
1770
- return createLanguageModel(modelId);
1771
- };
1772
- provider.specificationVersion = "v4";
1773
- provider.languageModel = createLanguageModel;
1774
- provider.tools = createOpenResponsesTools({ customToolId });
1775
- provider.embeddingModel = (modelId) => {
1776
- throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
1777
- };
1778
- provider.imageModel = (modelId) => {
1779
- throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1780
- };
1781
- return provider;
1321
+ const providerName = options.name;
1322
+ const customToolId = options.customToolId ?? "open-responses.custom";
1323
+ const extensionRegistry = createOpenResponsesExtensionRegistry(options.experimental_extensions);
1324
+ const getHeaders = () => withUserAgentSuffix({
1325
+ ...options.apiKey ? { Authorization: `Bearer ${options.apiKey}` } : {},
1326
+ ...typeof options.headers === "function" ? options.headers() : options.headers
1327
+ }, options.userAgentSuffix ?? `ai-sdk-open-responses/2.0.57`);
1328
+ const createResponsesModel = (modelId) => {
1329
+ return new OpenResponsesLanguageModel(modelId, {
1330
+ provider: `${providerName}.responses`,
1331
+ providerOptionsName: providerName,
1332
+ headers: getHeaders,
1333
+ url: options.url,
1334
+ fetch: options.fetch,
1335
+ failedResponseHandler: options.failedResponseHandler,
1336
+ getResponseErrorMetadata: options.getResponseErrorMetadata,
1337
+ generateId: () => generateId(),
1338
+ extensionRegistry,
1339
+ strictResponseInput: options.strictResponseInput,
1340
+ customToolId,
1341
+ structuredOutputs: options.structuredOutputs
1342
+ });
1343
+ };
1344
+ const createLanguageModel = (modelId) => {
1345
+ if (new.target) throw new Error("The OpenAI model function cannot be called with the new keyword.");
1346
+ return createResponsesModel(modelId);
1347
+ };
1348
+ const provider = function(modelId) {
1349
+ return createLanguageModel(modelId);
1350
+ };
1351
+ provider.specificationVersion = "v4";
1352
+ provider.languageModel = createLanguageModel;
1353
+ provider.tools = createOpenResponsesTools({ customToolId });
1354
+ provider.embeddingModel = (modelId) => {
1355
+ throw new NoSuchModelError({
1356
+ modelId,
1357
+ modelType: "embeddingModel"
1358
+ });
1359
+ };
1360
+ provider.imageModel = (modelId) => {
1361
+ throw new NoSuchModelError({
1362
+ modelId,
1363
+ modelType: "imageModel"
1364
+ });
1365
+ };
1366
+ return provider;
1782
1367
  }
1783
- export {
1784
- VERSION,
1785
- createOpenResponses
1786
- };
1368
+ //#endregion
1369
+ export { VERSION, createOpenResponses };
1370
+
1787
1371
  //# sourceMappingURL=index.js.map