@ai-sdk/open-responses 2.0.0-beta.21 → 2.0.0-beta.23
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 +30 -0
- package/dist/index.js +112 -103
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/responses/convert-to-open-responses-input.ts +25 -18
- package/src/responses/open-responses-config.ts +1 -1
- package/src/responses/open-responses-language-model.ts +19 -2
- package/dist/index.d.mts +0 -40
- package/dist/index.mjs +0 -665
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @ai-sdk/open-responses
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b3976a2: Add workflow serialization support to all provider models.
|
|
8
|
+
|
|
9
|
+
**`@ai-sdk/provider-utils`:** New `serializeModel()` helper that extracts only serializable properties from a model instance, filtering out functions and objects containing functions. Third-party provider authors can use this to add workflow support to their own models.
|
|
10
|
+
|
|
11
|
+
**All providers:** `headers` is now optional in provider config types. This is non-breaking — existing code that passes `headers` continues to work. Custom provider implementations that construct model configs manually can now omit `headers`, which is useful when models are deserialized from a workflow step boundary where auth is provided separately.
|
|
12
|
+
|
|
13
|
+
All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
|
|
14
|
+
|
|
15
|
+
- ff5eba1: feat: roll `image-*` tool output types into their equivalent `file-*` types
|
|
16
|
+
- Updated dependencies [b3976a2]
|
|
17
|
+
- Updated dependencies [ff5eba1]
|
|
18
|
+
- @ai-sdk/provider-utils@5.0.0-beta.20
|
|
19
|
+
- @ai-sdk/provider@4.0.0-beta.12
|
|
20
|
+
|
|
21
|
+
## 2.0.0-beta.22
|
|
22
|
+
|
|
23
|
+
### Major Changes
|
|
24
|
+
|
|
25
|
+
- ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [ef992f8]
|
|
30
|
+
- @ai-sdk/provider@4.0.0-beta.11
|
|
31
|
+
- @ai-sdk/provider-utils@5.0.0-beta.19
|
|
32
|
+
|
|
3
33
|
## 2.0.0-beta.21
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,44 +1,37 @@
|
|
|
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.23" : "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
|
-
|
|
41
|
-
|
|
31
|
+
import {
|
|
32
|
+
UnsupportedFunctionalityError
|
|
33
|
+
} from "@ai-sdk/provider";
|
|
34
|
+
import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
|
|
42
35
|
async function convertToOpenResponsesInput({
|
|
43
36
|
prompt
|
|
44
37
|
}) {
|
|
@@ -61,8 +54,8 @@ async function convertToOpenResponsesInput({
|
|
|
61
54
|
break;
|
|
62
55
|
}
|
|
63
56
|
case "file": {
|
|
64
|
-
if (
|
|
65
|
-
throw new
|
|
57
|
+
if (isProviderReference(part.data)) {
|
|
58
|
+
throw new UnsupportedFunctionalityError({
|
|
66
59
|
functionality: "file parts with provider references"
|
|
67
60
|
});
|
|
68
61
|
}
|
|
@@ -77,7 +70,7 @@ async function convertToOpenResponsesInput({
|
|
|
77
70
|
userContent.push({
|
|
78
71
|
type: "input_image",
|
|
79
72
|
...part.data instanceof URL ? { image_url: part.data.toString() } : {
|
|
80
|
-
image_url: `data:${mediaType};base64,${
|
|
73
|
+
image_url: `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
81
74
|
}
|
|
82
75
|
});
|
|
83
76
|
break;
|
|
@@ -148,26 +141,33 @@ async function convertToOpenResponsesInput({
|
|
|
148
141
|
});
|
|
149
142
|
break;
|
|
150
143
|
}
|
|
151
|
-
case "
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
144
|
+
case "file-data": {
|
|
145
|
+
if (item.mediaType.startsWith("image/")) {
|
|
146
|
+
contentParts.push({
|
|
147
|
+
type: "input_image",
|
|
148
|
+
image_url: `data:${item.mediaType};base64,${item.data}`
|
|
149
|
+
});
|
|
150
|
+
} else {
|
|
151
|
+
contentParts.push({
|
|
152
|
+
type: "input_file",
|
|
153
|
+
filename: (_b = item.filename) != null ? _b : "data",
|
|
154
|
+
file_data: `data:${item.mediaType};base64,${item.data}`
|
|
155
|
+
});
|
|
156
|
+
}
|
|
163
157
|
break;
|
|
164
158
|
}
|
|
165
|
-
case "file-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
case "file-url": {
|
|
160
|
+
if (item.mediaType.startsWith("image/")) {
|
|
161
|
+
contentParts.push({
|
|
162
|
+
type: "input_image",
|
|
163
|
+
image_url: item.url
|
|
164
|
+
});
|
|
165
|
+
} else {
|
|
166
|
+
contentParts.push({
|
|
167
|
+
type: "input_file",
|
|
168
|
+
file_url: item.url
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
171
|
break;
|
|
172
172
|
}
|
|
173
173
|
default: {
|
|
@@ -202,17 +202,17 @@ async function convertToOpenResponsesInput({
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
// src/responses/open-responses-api.ts
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
var openResponsesErrorSchema =
|
|
209
|
-
() =>
|
|
210
|
-
|
|
211
|
-
error:
|
|
212
|
-
message:
|
|
213
|
-
type:
|
|
214
|
-
param:
|
|
215
|
-
code:
|
|
205
|
+
import { lazySchema } from "@ai-sdk/provider-utils";
|
|
206
|
+
import { z } from "zod/v4";
|
|
207
|
+
import { zodSchema } from "@ai-sdk/provider-utils";
|
|
208
|
+
var openResponsesErrorSchema = lazySchema(
|
|
209
|
+
() => zodSchema(
|
|
210
|
+
z.object({
|
|
211
|
+
error: z.object({
|
|
212
|
+
message: z.string(),
|
|
213
|
+
type: z.string(),
|
|
214
|
+
param: z.string(),
|
|
215
|
+
code: z.string()
|
|
216
216
|
})
|
|
217
217
|
})
|
|
218
218
|
)
|
|
@@ -237,22 +237,22 @@ function mapOpenResponsesFinishReason({
|
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
// src/responses/open-responses-options.ts
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
var openResponsesOptionsSchema = (
|
|
243
|
-
() => (
|
|
244
|
-
|
|
240
|
+
import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
|
|
241
|
+
import { z as z2 } from "zod/v4";
|
|
242
|
+
var openResponsesOptionsSchema = lazySchema2(
|
|
243
|
+
() => zodSchema2(
|
|
244
|
+
z2.object({
|
|
245
245
|
/**
|
|
246
246
|
* Controls reasoning summary output from the model.
|
|
247
247
|
* Valid values: 'concise', 'detailed', 'auto'.
|
|
248
248
|
*/
|
|
249
|
-
reasoningSummary:
|
|
249
|
+
reasoningSummary: z2.enum(["concise", "detailed", "auto"]).nullish()
|
|
250
250
|
})
|
|
251
251
|
)
|
|
252
252
|
);
|
|
253
253
|
|
|
254
254
|
// src/responses/open-responses-language-model.ts
|
|
255
|
-
var OpenResponsesLanguageModel = class {
|
|
255
|
+
var OpenResponsesLanguageModel = class _OpenResponsesLanguageModel {
|
|
256
256
|
constructor(modelId, config) {
|
|
257
257
|
this.specificationVersion = "v4";
|
|
258
258
|
this.supportedUrls = {
|
|
@@ -261,6 +261,15 @@ var OpenResponsesLanguageModel = class {
|
|
|
261
261
|
this.modelId = modelId;
|
|
262
262
|
this.config = config;
|
|
263
263
|
}
|
|
264
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
265
|
+
return serializeModelOptions({
|
|
266
|
+
modelId: model.modelId,
|
|
267
|
+
config: model.config
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
271
|
+
return new _OpenResponsesLanguageModel(options.modelId, options.config);
|
|
272
|
+
}
|
|
264
273
|
get provider() {
|
|
265
274
|
return this.config.provider;
|
|
266
275
|
}
|
|
@@ -316,12 +325,12 @@ var OpenResponsesLanguageModel = class {
|
|
|
316
325
|
strict: true
|
|
317
326
|
} : {}
|
|
318
327
|
} : void 0;
|
|
319
|
-
const openResponsesOptions = await
|
|
328
|
+
const openResponsesOptions = await parseProviderOptions({
|
|
320
329
|
provider: this.config.providerOptionsName,
|
|
321
330
|
providerOptions,
|
|
322
331
|
schema: openResponsesOptionsSchema
|
|
323
332
|
});
|
|
324
|
-
const resolvedReasoningEffort =
|
|
333
|
+
const resolvedReasoningEffort = isCustomReasoning(reasoning) ? reasoning === "none" ? "none" : mapReasoningToProviderEffort({
|
|
325
334
|
reasoning,
|
|
326
335
|
effortMap: {
|
|
327
336
|
minimal: "low",
|
|
@@ -358,23 +367,23 @@ var OpenResponsesLanguageModel = class {
|
|
|
358
367
|
};
|
|
359
368
|
}
|
|
360
369
|
async doGenerate(options) {
|
|
361
|
-
var _a, _b, _c, _d, _e, _f;
|
|
370
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
362
371
|
const { body, warnings } = await this.getArgs(options);
|
|
363
372
|
const {
|
|
364
373
|
responseHeaders,
|
|
365
374
|
value: response,
|
|
366
375
|
rawValue: rawResponse
|
|
367
|
-
} = await
|
|
376
|
+
} = await postJsonToApi({
|
|
368
377
|
url: this.config.url,
|
|
369
|
-
headers: (
|
|
378
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
370
379
|
body,
|
|
371
|
-
failedResponseHandler:
|
|
380
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
372
381
|
errorSchema: openResponsesErrorSchema,
|
|
373
382
|
errorToMessage: (error) => error.error.message
|
|
374
383
|
}),
|
|
375
|
-
successfulResponseHandler:
|
|
384
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
376
385
|
// do not validate the response body, only apply types to the response body
|
|
377
|
-
|
|
386
|
+
jsonSchema(() => {
|
|
378
387
|
throw new Error("json schema not implemented");
|
|
379
388
|
})
|
|
380
389
|
),
|
|
@@ -387,7 +396,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
387
396
|
switch (part.type) {
|
|
388
397
|
// TODO AI SDK 7 adjust reasoning in the specification to better support the reasoning structure from open responses.
|
|
389
398
|
case "reasoning": {
|
|
390
|
-
for (const contentPart of (
|
|
399
|
+
for (const contentPart of (_c = part.content) != null ? _c : []) {
|
|
391
400
|
content.push({
|
|
392
401
|
type: "reasoning",
|
|
393
402
|
text: contentPart.text
|
|
@@ -418,17 +427,17 @@ var OpenResponsesLanguageModel = class {
|
|
|
418
427
|
}
|
|
419
428
|
const usage = response.usage;
|
|
420
429
|
const inputTokens = usage == null ? void 0 : usage.input_tokens;
|
|
421
|
-
const cachedInputTokens = (
|
|
430
|
+
const cachedInputTokens = (_d = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _d.cached_tokens;
|
|
422
431
|
const outputTokens = usage == null ? void 0 : usage.output_tokens;
|
|
423
|
-
const reasoningTokens = (
|
|
432
|
+
const reasoningTokens = (_e = usage == null ? void 0 : usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens;
|
|
424
433
|
return {
|
|
425
434
|
content,
|
|
426
435
|
finishReason: {
|
|
427
436
|
unified: mapOpenResponsesFinishReason({
|
|
428
|
-
finishReason: (
|
|
437
|
+
finishReason: (_f = response.incomplete_details) == null ? void 0 : _f.reason,
|
|
429
438
|
hasToolCalls
|
|
430
439
|
}),
|
|
431
|
-
raw: (
|
|
440
|
+
raw: (_h = (_g = response.incomplete_details) == null ? void 0 : _g.reason) != null ? _h : void 0
|
|
432
441
|
},
|
|
433
442
|
usage: {
|
|
434
443
|
inputTokens: {
|
|
@@ -457,20 +466,21 @@ var OpenResponsesLanguageModel = class {
|
|
|
457
466
|
};
|
|
458
467
|
}
|
|
459
468
|
async doStream(options) {
|
|
469
|
+
var _a, _b;
|
|
460
470
|
const { body, warnings } = await this.getArgs(options);
|
|
461
|
-
const { responseHeaders, value: response } = await
|
|
471
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
462
472
|
url: this.config.url,
|
|
463
|
-
headers: (
|
|
473
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
464
474
|
body: {
|
|
465
475
|
...body,
|
|
466
476
|
stream: true
|
|
467
477
|
},
|
|
468
|
-
failedResponseHandler:
|
|
478
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
469
479
|
errorSchema: openResponsesErrorSchema,
|
|
470
480
|
errorToMessage: (error) => error.error.message
|
|
471
481
|
}),
|
|
472
482
|
// TODO consider validation
|
|
473
|
-
successfulResponseHandler:
|
|
483
|
+
successfulResponseHandler: createEventSourceResponseHandler(z3.any()),
|
|
474
484
|
abortSignal: options.abortSignal,
|
|
475
485
|
fetch: this.config.fetch
|
|
476
486
|
});
|
|
@@ -488,14 +498,14 @@ var OpenResponsesLanguageModel = class {
|
|
|
488
498
|
}
|
|
489
499
|
};
|
|
490
500
|
const updateUsage = (responseUsage) => {
|
|
491
|
-
var
|
|
501
|
+
var _a2, _b2;
|
|
492
502
|
if (!responseUsage) {
|
|
493
503
|
return;
|
|
494
504
|
}
|
|
495
505
|
const inputTokens = responseUsage.input_tokens;
|
|
496
|
-
const cachedInputTokens = (
|
|
506
|
+
const cachedInputTokens = (_a2 = responseUsage.input_tokens_details) == null ? void 0 : _a2.cached_tokens;
|
|
497
507
|
const outputTokens = responseUsage.output_tokens;
|
|
498
|
-
const reasoningTokens = (
|
|
508
|
+
const reasoningTokens = (_b2 = responseUsage.output_tokens_details) == null ? void 0 : _b2.reasoning_tokens;
|
|
499
509
|
usage.inputTokens = {
|
|
500
510
|
total: inputTokens,
|
|
501
511
|
noCache: (inputTokens != null ? inputTokens : 0) - (cachedInputTokens != null ? cachedInputTokens : 0),
|
|
@@ -523,7 +533,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
523
533
|
controller.enqueue({ type: "stream-start", warnings });
|
|
524
534
|
},
|
|
525
535
|
transform(parseResult, controller) {
|
|
526
|
-
var
|
|
536
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
527
537
|
if (options.includeRawChunks) {
|
|
528
538
|
controller.enqueue({
|
|
529
539
|
type: "raw",
|
|
@@ -543,8 +553,8 @@ var OpenResponsesLanguageModel = class {
|
|
|
543
553
|
};
|
|
544
554
|
} else if (chunk.type === "response.function_call_arguments.delta") {
|
|
545
555
|
const functionCallChunk = chunk;
|
|
546
|
-
const toolCall = (
|
|
547
|
-
toolCall.arguments = ((
|
|
556
|
+
const toolCall = (_a2 = toolCallsByItemId[functionCallChunk.item_id]) != null ? _a2 : toolCallsByItemId[functionCallChunk.item_id] = {};
|
|
557
|
+
toolCall.arguments = ((_b2 = toolCall.arguments) != null ? _b2 : "") + functionCallChunk.delta;
|
|
548
558
|
} else if (chunk.type === "response.function_call_arguments.done") {
|
|
549
559
|
const functionCallChunk = chunk;
|
|
550
560
|
const toolCall = (_c = toolCallsByItemId[functionCallChunk.item_id]) != null ? _c : toolCallsByItemId[functionCallChunk.item_id] = {};
|
|
@@ -628,7 +638,7 @@ var OpenResponsesLanguageModel = class {
|
|
|
628
638
|
// src/open-responses-provider.ts
|
|
629
639
|
function createOpenResponses(options) {
|
|
630
640
|
const providerName = options.name;
|
|
631
|
-
const getHeaders = () =>
|
|
641
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
632
642
|
{
|
|
633
643
|
...options.apiKey ? {
|
|
634
644
|
Authorization: `Bearer ${options.apiKey}`
|
|
@@ -644,7 +654,7 @@ function createOpenResponses(options) {
|
|
|
644
654
|
headers: getHeaders,
|
|
645
655
|
url: options.url,
|
|
646
656
|
fetch: options.fetch,
|
|
647
|
-
generateId: () =>
|
|
657
|
+
generateId: () => generateId()
|
|
648
658
|
});
|
|
649
659
|
};
|
|
650
660
|
const createLanguageModel = (modelId) => {
|
|
@@ -661,16 +671,15 @@ function createOpenResponses(options) {
|
|
|
661
671
|
provider.specificationVersion = "v4";
|
|
662
672
|
provider.languageModel = createLanguageModel;
|
|
663
673
|
provider.embeddingModel = (modelId) => {
|
|
664
|
-
throw new
|
|
674
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
665
675
|
};
|
|
666
676
|
provider.imageModel = (modelId) => {
|
|
667
|
-
throw new
|
|
677
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
668
678
|
};
|
|
669
679
|
return provider;
|
|
670
680
|
}
|
|
671
|
-
|
|
672
|
-
0 && (module.exports = {
|
|
681
|
+
export {
|
|
673
682
|
VERSION,
|
|
674
683
|
createOpenResponses
|
|
675
|
-
}
|
|
684
|
+
};
|
|
676
685
|
//# sourceMappingURL=index.js.map
|