@ai-sdk/open-responses 2.0.0-beta.5 → 2.0.0-beta.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +402 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +220 -120
- package/dist/index.js.map +1 -1
- package/package.json +14 -15
- package/src/index.ts +9 -0
- package/src/open-responses-provider.ts +4 -4
- package/src/responses/convert-to-open-responses-input.ts +88 -41
- package/src/responses/map-open-responses-finish-reason.ts +1 -1
- package/src/responses/open-responses-api.ts +2 -3
- package/src/responses/open-responses-config.ts +3 -2
- package/src/responses/open-responses-language-model-options.ts +22 -0
- package/src/responses/open-responses-language-model.ts +94 -37
- package/dist/index.d.mts +0 -34
- package/dist/index.mjs +0 -613
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,47 +1,45 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createOpenResponses: () => createOpenResponses
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
1
|
// src/version.ts
|
|
29
|
-
var VERSION = true ? "2.0.0-beta.
|
|
2
|
+
var VERSION = true ? "2.0.0-beta.54" : "0.0.0-test";
|
|
30
3
|
|
|
31
4
|
// src/open-responses-provider.ts
|
|
32
|
-
|
|
33
|
-
|
|
5
|
+
import {
|
|
6
|
+
NoSuchModelError
|
|
7
|
+
} from "@ai-sdk/provider";
|
|
8
|
+
import {
|
|
9
|
+
generateId,
|
|
10
|
+
withUserAgentSuffix
|
|
11
|
+
} from "@ai-sdk/provider-utils";
|
|
34
12
|
|
|
35
13
|
// src/responses/open-responses-language-model.ts
|
|
36
|
-
|
|
37
|
-
|
|
14
|
+
import {
|
|
15
|
+
combineHeaders,
|
|
16
|
+
createEventSourceResponseHandler,
|
|
17
|
+
createJsonErrorResponseHandler,
|
|
18
|
+
createJsonResponseHandler,
|
|
19
|
+
isCustomReasoning,
|
|
20
|
+
jsonSchema,
|
|
21
|
+
mapReasoningToProviderEffort,
|
|
22
|
+
parseProviderOptions,
|
|
23
|
+
postJsonToApi,
|
|
24
|
+
serializeModelOptions,
|
|
25
|
+
WORKFLOW_SERIALIZE,
|
|
26
|
+
WORKFLOW_DESERIALIZE
|
|
27
|
+
} from "@ai-sdk/provider-utils";
|
|
28
|
+
import { z as z3 } from "zod/v4";
|
|
38
29
|
|
|
39
30
|
// src/responses/convert-to-open-responses-input.ts
|
|
40
|
-
|
|
31
|
+
import {
|
|
32
|
+
UnsupportedFunctionalityError
|
|
33
|
+
} from "@ai-sdk/provider";
|
|
34
|
+
import {
|
|
35
|
+
convertToBase64,
|
|
36
|
+
getTopLevelMediaType,
|
|
37
|
+
resolveFullMediaType
|
|
38
|
+
} from "@ai-sdk/provider-utils";
|
|
41
39
|
async function convertToOpenResponsesInput({
|
|
42
40
|
prompt
|
|
43
41
|
}) {
|
|
44
|
-
var _a, _b;
|
|
42
|
+
var _a, _b, _c;
|
|
45
43
|
const input = [];
|
|
46
44
|
const warnings = [];
|
|
47
45
|
const systemMessages = [];
|
|
@@ -60,20 +58,43 @@ async function convertToOpenResponsesInput({
|
|
|
60
58
|
break;
|
|
61
59
|
}
|
|
62
60
|
case "file": {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
71
|
-
userContent.push({
|
|
72
|
-
type: "input_image",
|
|
73
|
-
...part.data instanceof URL ? { image_url: part.data.toString() } : {
|
|
74
|
-
image_url: `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
|
|
61
|
+
switch (part.data.type) {
|
|
62
|
+
case "reference": {
|
|
63
|
+
throw new UnsupportedFunctionalityError({
|
|
64
|
+
functionality: "file parts with provider references"
|
|
65
|
+
});
|
|
75
66
|
}
|
|
76
|
-
|
|
67
|
+
case "text": {
|
|
68
|
+
throw new UnsupportedFunctionalityError({
|
|
69
|
+
functionality: "text file parts"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
case "url":
|
|
73
|
+
case "data": {
|
|
74
|
+
const topLevel = getTopLevelMediaType(part.mediaType);
|
|
75
|
+
if (topLevel === "image") {
|
|
76
|
+
userContent.push({
|
|
77
|
+
type: "input_image",
|
|
78
|
+
...part.data.type === "url" ? { image_url: part.data.url.toString() } : {
|
|
79
|
+
image_url: `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
} else if (part.data.type === "url") {
|
|
83
|
+
userContent.push({
|
|
84
|
+
type: "input_file",
|
|
85
|
+
file_url: part.data.url.toString()
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
89
|
+
userContent.push({
|
|
90
|
+
type: "input_file",
|
|
91
|
+
filename: (_a = part.filename) != null ? _a : "data",
|
|
92
|
+
file_data: `data:${fullMediaType};base64,${convertToBase64(part.data.data)}`
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
77
98
|
break;
|
|
78
99
|
}
|
|
79
100
|
}
|
|
@@ -125,7 +146,7 @@ async function convertToOpenResponsesInput({
|
|
|
125
146
|
contentValue = output.value;
|
|
126
147
|
break;
|
|
127
148
|
case "execution-denied":
|
|
128
|
-
contentValue = (
|
|
149
|
+
contentValue = (_b = output.reason) != null ? _b : "Tool call execution denied.";
|
|
129
150
|
break;
|
|
130
151
|
case "json":
|
|
131
152
|
case "error-json":
|
|
@@ -142,26 +163,42 @@ async function convertToOpenResponsesInput({
|
|
|
142
163
|
});
|
|
143
164
|
break;
|
|
144
165
|
}
|
|
145
|
-
case "
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
case "file": {
|
|
167
|
+
const topLevel = getTopLevelMediaType(item.mediaType);
|
|
168
|
+
if (item.data.type === "data") {
|
|
169
|
+
const fullMediaType = resolveFullMediaType({
|
|
170
|
+
part: item
|
|
171
|
+
});
|
|
172
|
+
if (topLevel === "image") {
|
|
173
|
+
contentParts.push({
|
|
174
|
+
type: "input_image",
|
|
175
|
+
image_url: `data:${fullMediaType};base64,${convertToBase64(item.data.data)}`
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
contentParts.push({
|
|
179
|
+
type: "input_file",
|
|
180
|
+
filename: (_c = item.filename) != null ? _c : "data",
|
|
181
|
+
file_data: `data:${fullMediaType};base64,${convertToBase64(item.data.data)}`
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
} else if (item.data.type === "url") {
|
|
185
|
+
if (topLevel === "image") {
|
|
186
|
+
contentParts.push({
|
|
187
|
+
type: "input_image",
|
|
188
|
+
image_url: item.data.url.toString()
|
|
189
|
+
});
|
|
190
|
+
} else {
|
|
191
|
+
contentParts.push({
|
|
192
|
+
type: "input_file",
|
|
193
|
+
file_url: item.data.url.toString()
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
warnings.push({
|
|
198
|
+
type: "other",
|
|
199
|
+
message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
|
|
200
|
+
});
|
|
201
|
+
}
|
|
165
202
|
break;
|
|
166
203
|
}
|
|
167
204
|
default: {
|
|
@@ -196,17 +233,16 @@ async function convertToOpenResponsesInput({
|
|
|
196
233
|
}
|
|
197
234
|
|
|
198
235
|
// src/responses/open-responses-api.ts
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
var
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
code: import_v4.z.string()
|
|
236
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
237
|
+
import { z } from "zod/v4";
|
|
238
|
+
var openResponsesErrorSchema = lazySchema(
|
|
239
|
+
() => zodSchema(
|
|
240
|
+
z.object({
|
|
241
|
+
error: z.object({
|
|
242
|
+
message: z.string(),
|
|
243
|
+
type: z.string(),
|
|
244
|
+
param: z.string(),
|
|
245
|
+
code: z.string()
|
|
210
246
|
})
|
|
211
247
|
})
|
|
212
248
|
)
|
|
@@ -230,8 +266,26 @@ function mapOpenResponsesFinishReason({
|
|
|
230
266
|
}
|
|
231
267
|
}
|
|
232
268
|
|
|
269
|
+
// src/responses/open-responses-language-model-options.ts
|
|
270
|
+
import {
|
|
271
|
+
lazySchema as lazySchema2,
|
|
272
|
+
zodSchema as zodSchema2
|
|
273
|
+
} from "@ai-sdk/provider-utils";
|
|
274
|
+
import { z as z2 } from "zod/v4";
|
|
275
|
+
var openResponsesLanguageModelOptions = lazySchema2(
|
|
276
|
+
() => zodSchema2(
|
|
277
|
+
z2.object({
|
|
278
|
+
/**
|
|
279
|
+
* Controls reasoning summary output from the model.
|
|
280
|
+
* Valid values: 'concise', 'detailed', 'auto'.
|
|
281
|
+
*/
|
|
282
|
+
reasoningSummary: z2.enum(["concise", "detailed", "auto"]).nullish()
|
|
283
|
+
})
|
|
284
|
+
)
|
|
285
|
+
);
|
|
286
|
+
|
|
233
287
|
// src/responses/open-responses-language-model.ts
|
|
234
|
-
var OpenResponsesLanguageModel = class {
|
|
288
|
+
var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
235
289
|
constructor(modelId, config) {
|
|
236
290
|
this.specificationVersion = "v4";
|
|
237
291
|
this.supportedUrls = {
|
|
@@ -240,6 +294,15 @@ var OpenResponsesLanguageModel = class {
|
|
|
240
294
|
this.modelId = modelId;
|
|
241
295
|
this.config = config;
|
|
242
296
|
}
|
|
297
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
298
|
+
return serializeModelOptions({
|
|
299
|
+
modelId: model.modelId,
|
|
300
|
+
config: model.config
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
304
|
+
return new _OpenResponsesLanguageModel(options.modelId, options.config);
|
|
305
|
+
}
|
|
243
306
|
get provider() {
|
|
244
307
|
return this.config.provider;
|
|
245
308
|
}
|
|
@@ -252,6 +315,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
252
315
|
presencePenalty,
|
|
253
316
|
frequencyPenalty,
|
|
254
317
|
seed,
|
|
318
|
+
reasoning,
|
|
255
319
|
prompt,
|
|
256
320
|
providerOptions,
|
|
257
321
|
tools,
|
|
@@ -294,6 +358,22 @@ var OpenResponsesLanguageModel = class {
|
|
|
294
358
|
strict: true
|
|
295
359
|
} : {}
|
|
296
360
|
} : void 0;
|
|
361
|
+
const openResponsesOptions = await parseProviderOptions({
|
|
362
|
+
provider: this.config.providerOptionsName,
|
|
363
|
+
providerOptions,
|
|
364
|
+
schema: openResponsesLanguageModelOptions
|
|
365
|
+
});
|
|
366
|
+
const resolvedReasoningEffort = isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
|
|
367
|
+
reasoning,
|
|
368
|
+
effortMap: {
|
|
369
|
+
minimal: "low",
|
|
370
|
+
low: "low",
|
|
371
|
+
medium: "medium",
|
|
372
|
+
high: "high",
|
|
373
|
+
xhigh: "xhigh"
|
|
374
|
+
},
|
|
375
|
+
warnings
|
|
376
|
+
}) : void 0;
|
|
297
377
|
return {
|
|
298
378
|
body: {
|
|
299
379
|
model: this.modelId,
|
|
@@ -304,6 +384,14 @@ var OpenResponsesLanguageModel = class {
|
|
|
304
384
|
top_p: topP,
|
|
305
385
|
presence_penalty: presencePenalty,
|
|
306
386
|
frequency_penalty: frequencyPenalty,
|
|
387
|
+
reasoning: resolvedReasoningEffort != null || (openResponsesOptions == null ? void 0 : openResponsesOptions.reasoningSummary) != null ? {
|
|
388
|
+
...resolvedReasoningEffort != null && {
|
|
389
|
+
effort: resolvedReasoningEffort
|
|
390
|
+
},
|
|
391
|
+
...(openResponsesOptions == null ? void 0 : openResponsesOptions.reasoningSummary) != null && {
|
|
392
|
+
summary: openResponsesOptions.reasoningSummary
|
|
393
|
+
}
|
|
394
|
+
} : void 0,
|
|
307
395
|
tools: (functionTools == null ? void 0 : functionTools.length) ? functionTools : void 0,
|
|
308
396
|
tool_choice: convertedToolChoice,
|
|
309
397
|
...textFormat != null && { text: { format: textFormat } }
|
|
@@ -312,23 +400,23 @@ var OpenResponsesLanguageModel = class {
|
|
|
312
400
|
};
|
|
313
401
|
}
|
|
314
402
|
async doGenerate(options) {
|
|
315
|
-
var _a, _b, _c, _d, _e, _f;
|
|
403
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
316
404
|
const { body, warnings } = await this.getArgs(options);
|
|
317
405
|
const {
|
|
318
406
|
responseHeaders,
|
|
319
407
|
value: response,
|
|
320
408
|
rawValue: rawResponse
|
|
321
|
-
} = await
|
|
409
|
+
} = await postJsonToApi({
|
|
322
410
|
url: this.config.url,
|
|
323
|
-
headers: (
|
|
411
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
324
412
|
body,
|
|
325
|
-
failedResponseHandler:
|
|
413
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
326
414
|
errorSchema: openResponsesErrorSchema,
|
|
327
415
|
errorToMessage: (error) => error.error.message
|
|
328
416
|
}),
|
|
329
|
-
successfulResponseHandler:
|
|
417
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
330
418
|
// do not validate the response body, only apply types to the response body
|
|
331
|
-
|
|
419
|
+
jsonSchema(() => {
|
|
332
420
|
throw new Error("json schema not implemented");
|
|
333
421
|
})
|
|
334
422
|
),
|
|
@@ -341,7 +429,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
341
429
|
switch (part.type) {
|
|
342
430
|
// TODO AI SDK 7 adjust reasoning in the specification to better support the reasoning structure from open responses.
|
|
343
431
|
case "reasoning": {
|
|
344
|
-
for (const contentPart of (
|
|
432
|
+
for (const contentPart of (_c = part.content) != null ? _c : []) {
|
|
345
433
|
content.push({
|
|
346
434
|
type: "reasoning",
|
|
347
435
|
text: contentPart.text
|
|
@@ -372,17 +460,17 @@ var OpenResponsesLanguageModel = class {
|
|
|
372
460
|
}
|
|
373
461
|
const usage = response.usage;
|
|
374
462
|
const inputTokens = usage == null ? void 0 : usage.input_tokens;
|
|
375
|
-
const cachedInputTokens = (
|
|
463
|
+
const cachedInputTokens = (_d = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _d.cached_tokens;
|
|
376
464
|
const outputTokens = usage == null ? void 0 : usage.output_tokens;
|
|
377
|
-
const reasoningTokens = (
|
|
465
|
+
const reasoningTokens = (_e = usage == null ? void 0 : usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens;
|
|
378
466
|
return {
|
|
379
467
|
content,
|
|
380
468
|
finishReason: {
|
|
381
469
|
unified: mapOpenResponsesFinishReason({
|
|
382
|
-
finishReason: (
|
|
470
|
+
finishReason: (_f = response.incomplete_details) == null ? void 0 : _f.reason,
|
|
383
471
|
hasToolCalls
|
|
384
472
|
}),
|
|
385
|
-
raw: (
|
|
473
|
+
raw: (_h = (_g = response.incomplete_details) == null ? void 0 : _g.reason) != null ? _h : void 0
|
|
386
474
|
},
|
|
387
475
|
usage: {
|
|
388
476
|
inputTokens: {
|
|
@@ -411,20 +499,20 @@ var OpenResponsesLanguageModel = class {
|
|
|
411
499
|
};
|
|
412
500
|
}
|
|
413
501
|
async doStream(options) {
|
|
502
|
+
var _a, _b;
|
|
414
503
|
const { body, warnings } = await this.getArgs(options);
|
|
415
|
-
const { responseHeaders, value: response } = await
|
|
504
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
416
505
|
url: this.config.url,
|
|
417
|
-
headers: (
|
|
506
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
418
507
|
body: {
|
|
419
508
|
...body,
|
|
420
509
|
stream: true
|
|
421
510
|
},
|
|
422
|
-
failedResponseHandler:
|
|
511
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
423
512
|
errorSchema: openResponsesErrorSchema,
|
|
424
513
|
errorToMessage: (error) => error.error.message
|
|
425
514
|
}),
|
|
426
|
-
|
|
427
|
-
successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(import_v42.z.any()),
|
|
515
|
+
successfulResponseHandler: createEventSourceResponseHandler(z3.any()),
|
|
428
516
|
abortSignal: options.abortSignal,
|
|
429
517
|
fetch: this.config.fetch
|
|
430
518
|
});
|
|
@@ -442,14 +530,14 @@ var OpenResponsesLanguageModel = class {
|
|
|
442
530
|
}
|
|
443
531
|
};
|
|
444
532
|
const updateUsage = (responseUsage) => {
|
|
445
|
-
var
|
|
533
|
+
var _a2, _b2;
|
|
446
534
|
if (!responseUsage) {
|
|
447
535
|
return;
|
|
448
536
|
}
|
|
449
537
|
const inputTokens = responseUsage.input_tokens;
|
|
450
|
-
const cachedInputTokens = (
|
|
538
|
+
const cachedInputTokens = (_a2 = responseUsage.input_tokens_details) == null ? void 0 : _a2.cached_tokens;
|
|
451
539
|
const outputTokens = responseUsage.output_tokens;
|
|
452
|
-
const reasoningTokens = (
|
|
540
|
+
const reasoningTokens = (_b2 = responseUsage.output_tokens_details) == null ? void 0 : _b2.reasoning_tokens;
|
|
453
541
|
usage.inputTokens = {
|
|
454
542
|
total: inputTokens,
|
|
455
543
|
noCache: (inputTokens != null ? inputTokens : 0) - (cachedInputTokens != null ? cachedInputTokens : 0),
|
|
@@ -469,7 +557,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
469
557
|
unified: "other",
|
|
470
558
|
raw: void 0
|
|
471
559
|
};
|
|
472
|
-
const toolCallsByItemId =
|
|
560
|
+
const toolCallsByItemId = /* @__PURE__ */ new Map();
|
|
473
561
|
return {
|
|
474
562
|
stream: response.pipeThrough(
|
|
475
563
|
new TransformStream({
|
|
@@ -477,7 +565,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
477
565
|
controller.enqueue({ type: "stream-start", warnings });
|
|
478
566
|
},
|
|
479
567
|
transform(parseResult, controller) {
|
|
480
|
-
var
|
|
568
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h;
|
|
481
569
|
if (options.includeRawChunks) {
|
|
482
570
|
controller.enqueue({
|
|
483
571
|
type: "raw",
|
|
@@ -490,24 +578,36 @@ var OpenResponsesLanguageModel = class {
|
|
|
490
578
|
}
|
|
491
579
|
const chunk = parseResult.value;
|
|
492
580
|
if (chunk.type === "response.output_item.added" && chunk.item.type === "function_call") {
|
|
493
|
-
toolCallsByItemId
|
|
581
|
+
toolCallsByItemId.set(chunk.item.id, {
|
|
494
582
|
toolName: chunk.item.name,
|
|
495
583
|
toolCallId: chunk.item.call_id,
|
|
496
584
|
arguments: chunk.item.arguments
|
|
497
|
-
};
|
|
585
|
+
});
|
|
498
586
|
} else if (chunk.type === "response.function_call_arguments.delta") {
|
|
499
587
|
const functionCallChunk = chunk;
|
|
500
|
-
const toolCall = (
|
|
501
|
-
|
|
588
|
+
const toolCall = toolCallsByItemId.get(functionCallChunk.item_id);
|
|
589
|
+
if (toolCall == null) {
|
|
590
|
+
toolCallsByItemId.set(functionCallChunk.item_id, {
|
|
591
|
+
arguments: functionCallChunk.delta
|
|
592
|
+
});
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
toolCall.arguments = ((_a2 = toolCall.arguments) != null ? _a2 : "") + functionCallChunk.delta;
|
|
502
596
|
} else if (chunk.type === "response.function_call_arguments.done") {
|
|
503
597
|
const functionCallChunk = chunk;
|
|
504
|
-
const toolCall = (
|
|
598
|
+
const toolCall = toolCallsByItemId.get(functionCallChunk.item_id);
|
|
599
|
+
if (toolCall == null) {
|
|
600
|
+
toolCallsByItemId.set(functionCallChunk.item_id, {
|
|
601
|
+
arguments: functionCallChunk.arguments
|
|
602
|
+
});
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
505
605
|
toolCall.arguments = functionCallChunk.arguments;
|
|
506
606
|
} else if (chunk.type === "response.output_item.done" && chunk.item.type === "function_call") {
|
|
507
|
-
const toolCall = toolCallsByItemId
|
|
508
|
-
const toolName = (
|
|
509
|
-
const toolCallId = (
|
|
510
|
-
const input = (
|
|
607
|
+
const toolCall = toolCallsByItemId.get(chunk.item.id);
|
|
608
|
+
const toolName = (_b2 = toolCall == null ? void 0 : toolCall.toolName) != null ? _b2 : chunk.item.name;
|
|
609
|
+
const toolCallId = (_c = toolCall == null ? void 0 : toolCall.toolCallId) != null ? _c : chunk.item.call_id;
|
|
610
|
+
const input = (_e = (_d = toolCall == null ? void 0 : toolCall.arguments) != null ? _d : chunk.item.arguments) != null ? _e : "";
|
|
511
611
|
controller.enqueue({
|
|
512
612
|
type: "tool-call",
|
|
513
613
|
toolCallId,
|
|
@@ -515,7 +615,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
515
615
|
input
|
|
516
616
|
});
|
|
517
617
|
hasToolCalls = true;
|
|
518
|
-
delete
|
|
618
|
+
toolCallsByItemId.delete(chunk.item.id);
|
|
519
619
|
} else if (chunk.type === "response.output_item.added" && chunk.item.type === "reasoning") {
|
|
520
620
|
controller.enqueue({
|
|
521
621
|
type: "reasoning-start",
|
|
@@ -543,7 +643,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
543
643
|
} else if (chunk.type === "response.output_item.done" && chunk.item.type === "message") {
|
|
544
644
|
controller.enqueue({ type: "text-end", id: chunk.item.id });
|
|
545
645
|
} else if (chunk.type === "response.completed" || chunk.type === "response.incomplete") {
|
|
546
|
-
const reason = (
|
|
646
|
+
const reason = (_f = chunk.response.incomplete_details) == null ? void 0 : _f.reason;
|
|
547
647
|
finishReason = {
|
|
548
648
|
unified: mapOpenResponsesFinishReason({
|
|
549
649
|
finishReason: reason,
|
|
@@ -555,7 +655,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
555
655
|
} else if (chunk.type === "response.failed") {
|
|
556
656
|
finishReason = {
|
|
557
657
|
unified: "error",
|
|
558
|
-
raw: (
|
|
658
|
+
raw: (_h = (_g = chunk.response.error) == null ? void 0 : _g.code) != null ? _h : chunk.response.status
|
|
559
659
|
};
|
|
560
660
|
updateUsage(chunk.response.usage);
|
|
561
661
|
}
|
|
@@ -582,7 +682,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
582
682
|
// src/open-responses-provider.ts
|
|
583
683
|
function createOpenResponses(options) {
|
|
584
684
|
const providerName = options.name;
|
|
585
|
-
const getHeaders = () =>
|
|
685
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
586
686
|
{
|
|
587
687
|
...options.apiKey ? {
|
|
588
688
|
Authorization: `Bearer ${options.apiKey}`
|
|
@@ -594,10 +694,11 @@ function createOpenResponses(options) {
|
|
|
594
694
|
const createResponsesModel = (modelId) => {
|
|
595
695
|
return new OpenResponsesLanguageModel(modelId, {
|
|
596
696
|
provider: `${providerName}.responses`,
|
|
697
|
+
providerOptionsName: providerName,
|
|
597
698
|
headers: getHeaders,
|
|
598
699
|
url: options.url,
|
|
599
700
|
fetch: options.fetch,
|
|
600
|
-
generateId: () =>
|
|
701
|
+
generateId: () => generateId()
|
|
601
702
|
});
|
|
602
703
|
};
|
|
603
704
|
const createLanguageModel = (modelId) => {
|
|
@@ -614,16 +715,15 @@ function createOpenResponses(options) {
|
|
|
614
715
|
provider.specificationVersion = "v4";
|
|
615
716
|
provider.languageModel = createLanguageModel;
|
|
616
717
|
provider.embeddingModel = (modelId) => {
|
|
617
|
-
throw new
|
|
718
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
618
719
|
};
|
|
619
720
|
provider.imageModel = (modelId) => {
|
|
620
|
-
throw new
|
|
721
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
621
722
|
};
|
|
622
723
|
return provider;
|
|
623
724
|
}
|
|
624
|
-
|
|
625
|
-
0 && (module.exports = {
|
|
725
|
+
export {
|
|
626
726
|
VERSION,
|
|
627
727
|
createOpenResponses
|
|
628
|
-
}
|
|
728
|
+
};
|
|
629
729
|
//# sourceMappingURL=index.js.map
|