@ai-sdk/open-responses 2.0.0-beta.3 → 2.0.0-beta.31
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 +232 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +149 -93
- package/dist/index.js.map +1 -1
- package/package.json +11 -12
- package/src/index.ts +1 -0
- package/src/open-responses-provider.ts +1 -1
- package/src/responses/convert-to-open-responses-input.ts +38 -21
- package/src/responses/open-responses-config.ts +2 -1
- package/src/responses/open-responses-language-model.ts +58 -2
- package/src/responses/open-responses-options.ts +18 -0
- package/dist/index.d.mts +0 -34
- package/dist/index.mjs +0 -613
- package/dist/index.mjs.map +0 -1
|
@@ -14,9 +14,15 @@ import {
|
|
|
14
14
|
createEventSourceResponseHandler,
|
|
15
15
|
createJsonErrorResponseHandler,
|
|
16
16
|
createJsonResponseHandler,
|
|
17
|
+
isCustomReasoning,
|
|
17
18
|
jsonSchema,
|
|
19
|
+
mapReasoningToProviderEffort,
|
|
20
|
+
parseProviderOptions,
|
|
18
21
|
ParseResult,
|
|
19
22
|
postJsonToApi,
|
|
23
|
+
serializeModelOptions,
|
|
24
|
+
WORKFLOW_SERIALIZE,
|
|
25
|
+
WORKFLOW_DESERIALIZE,
|
|
20
26
|
} from '@ai-sdk/provider-utils';
|
|
21
27
|
import { z } from 'zod/v4';
|
|
22
28
|
import { convertToOpenResponsesInput } from './convert-to-open-responses-input';
|
|
@@ -30,6 +36,7 @@ import {
|
|
|
30
36
|
} from './open-responses-api';
|
|
31
37
|
import { mapOpenResponsesFinishReason } from './map-open-responses-finish-reason';
|
|
32
38
|
import { OpenResponsesConfig } from './open-responses-config';
|
|
39
|
+
import { openResponsesOptionsSchema } from './open-responses-options';
|
|
33
40
|
|
|
34
41
|
export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
35
42
|
readonly specificationVersion = 'v4';
|
|
@@ -38,6 +45,20 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
38
45
|
|
|
39
46
|
private readonly config: OpenResponsesConfig;
|
|
40
47
|
|
|
48
|
+
static [WORKFLOW_SERIALIZE](model: OpenResponsesLanguageModel) {
|
|
49
|
+
return serializeModelOptions({
|
|
50
|
+
modelId: model.modelId,
|
|
51
|
+
config: model.config,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
56
|
+
modelId: string;
|
|
57
|
+
config: OpenResponsesConfig;
|
|
58
|
+
}) {
|
|
59
|
+
return new OpenResponsesLanguageModel(options.modelId, options.config);
|
|
60
|
+
}
|
|
61
|
+
|
|
41
62
|
constructor(modelId: string, config: OpenResponsesConfig) {
|
|
42
63
|
this.modelId = modelId;
|
|
43
64
|
this.config = config;
|
|
@@ -60,6 +81,7 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
60
81
|
presencePenalty,
|
|
61
82
|
frequencyPenalty,
|
|
62
83
|
seed,
|
|
84
|
+
reasoning,
|
|
63
85
|
prompt,
|
|
64
86
|
providerOptions,
|
|
65
87
|
tools,
|
|
@@ -127,6 +149,28 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
127
149
|
}
|
|
128
150
|
: undefined;
|
|
129
151
|
|
|
152
|
+
const openResponsesOptions = await parseProviderOptions({
|
|
153
|
+
provider: this.config.providerOptionsName,
|
|
154
|
+
providerOptions,
|
|
155
|
+
schema: openResponsesOptionsSchema,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const resolvedReasoningEffort = isCustomReasoning(reasoning)
|
|
159
|
+
? reasoning === 'none'
|
|
160
|
+
? 'none'
|
|
161
|
+
: mapReasoningToProviderEffort({
|
|
162
|
+
reasoning,
|
|
163
|
+
effortMap: {
|
|
164
|
+
minimal: 'low',
|
|
165
|
+
low: 'low',
|
|
166
|
+
medium: 'medium',
|
|
167
|
+
high: 'high',
|
|
168
|
+
xhigh: 'xhigh',
|
|
169
|
+
},
|
|
170
|
+
warnings,
|
|
171
|
+
})
|
|
172
|
+
: undefined;
|
|
173
|
+
|
|
130
174
|
return {
|
|
131
175
|
body: {
|
|
132
176
|
model: this.modelId,
|
|
@@ -137,6 +181,18 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
137
181
|
top_p: topP,
|
|
138
182
|
presence_penalty: presencePenalty,
|
|
139
183
|
frequency_penalty: frequencyPenalty,
|
|
184
|
+
reasoning:
|
|
185
|
+
resolvedReasoningEffort != null ||
|
|
186
|
+
openResponsesOptions?.reasoningSummary != null
|
|
187
|
+
? {
|
|
188
|
+
...(resolvedReasoningEffort != null && {
|
|
189
|
+
effort: resolvedReasoningEffort,
|
|
190
|
+
}),
|
|
191
|
+
...(openResponsesOptions?.reasoningSummary != null && {
|
|
192
|
+
summary: openResponsesOptions.reasoningSummary,
|
|
193
|
+
}),
|
|
194
|
+
}
|
|
195
|
+
: undefined,
|
|
140
196
|
tools: functionTools?.length ? functionTools : undefined,
|
|
141
197
|
tool_choice: convertedToolChoice,
|
|
142
198
|
...(textFormat != null && { text: { format: textFormat } }),
|
|
@@ -156,7 +212,7 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
156
212
|
rawValue: rawResponse,
|
|
157
213
|
} = await postJsonToApi({
|
|
158
214
|
url: this.config.url,
|
|
159
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
215
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
160
216
|
body,
|
|
161
217
|
failedResponseHandler: createJsonErrorResponseHandler({
|
|
162
218
|
errorSchema: openResponsesErrorSchema,
|
|
@@ -261,7 +317,7 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
261
317
|
|
|
262
318
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
263
319
|
url: this.config.url,
|
|
264
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
320
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
265
321
|
body: {
|
|
266
322
|
...body,
|
|
267
323
|
stream: true,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InferSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
export const openResponsesOptionsSchema = lazySchema(() =>
|
|
5
|
+
zodSchema(
|
|
6
|
+
z.object({
|
|
7
|
+
/**
|
|
8
|
+
* Controls reasoning summary output from the model.
|
|
9
|
+
* Valid values: 'concise', 'detailed', 'auto'.
|
|
10
|
+
*/
|
|
11
|
+
reasoningSummary: z.enum(['concise', 'detailed', 'auto']).nullish(),
|
|
12
|
+
}),
|
|
13
|
+
),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export type OpenResponsesOptions = InferSchema<
|
|
17
|
+
typeof openResponsesOptionsSchema
|
|
18
|
+
>;
|
package/dist/index.d.mts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
|
|
4
|
-
declare const VERSION: string;
|
|
5
|
-
|
|
6
|
-
interface OpenResponsesProvider extends ProviderV4 {
|
|
7
|
-
(modelId: string): LanguageModelV4;
|
|
8
|
-
}
|
|
9
|
-
interface OpenResponsesProviderSettings {
|
|
10
|
-
/**
|
|
11
|
-
* URL for the Open Responses API POST endpoint.
|
|
12
|
-
*/
|
|
13
|
-
url: string;
|
|
14
|
-
/**
|
|
15
|
-
* Provider name. Used as key for provider options and metadata.
|
|
16
|
-
*/
|
|
17
|
-
name: string;
|
|
18
|
-
/**
|
|
19
|
-
* API key for authenticating requests.
|
|
20
|
-
*/
|
|
21
|
-
apiKey?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Custom headers to include in the requests.
|
|
24
|
-
*/
|
|
25
|
-
headers?: Record<string, string>;
|
|
26
|
-
/**
|
|
27
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
28
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
29
|
-
*/
|
|
30
|
-
fetch?: FetchFunction;
|
|
31
|
-
}
|
|
32
|
-
declare function createOpenResponses(options: OpenResponsesProviderSettings): OpenResponsesProvider;
|
|
33
|
-
|
|
34
|
-
export { VERSION, createOpenResponses };
|