@ai-sdk/open-responses 2.0.0-beta.9 → 2.0.0-canary.34
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 +221 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +166 -107
- package/dist/index.js.map +1 -1
- package/package.json +11 -9
- package/src/index.ts +9 -0
- package/src/open-responses-provider.ts +4 -4
- package/src/responses/convert-to-open-responses-input.ts +67 -39
- 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 +45 -12
- package/dist/index.d.mts +0 -34
- package/dist/index.mjs +0 -628
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
export const openResponsesLanguageModelOptions = lazySchema(() =>
|
|
9
|
+
zodSchema(
|
|
10
|
+
z.object({
|
|
11
|
+
/**
|
|
12
|
+
* Controls reasoning summary output from the model.
|
|
13
|
+
* Valid values: 'concise', 'detailed', 'auto'.
|
|
14
|
+
*/
|
|
15
|
+
reasoningSummary: z.enum(['concise', 'detailed', 'auto']).nullish(),
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export type OpenResponsesLanguageModelOptions = InferSchema<
|
|
21
|
+
typeof openResponsesLanguageModelOptions
|
|
22
|
+
>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
LanguageModelV4,
|
|
3
3
|
LanguageModelV4CallOptions,
|
|
4
4
|
LanguageModelV4Content,
|
|
@@ -17,21 +17,26 @@ import {
|
|
|
17
17
|
isCustomReasoning,
|
|
18
18
|
jsonSchema,
|
|
19
19
|
mapReasoningToProviderEffort,
|
|
20
|
-
|
|
20
|
+
parseProviderOptions,
|
|
21
21
|
postJsonToApi,
|
|
22
|
+
serializeModelOptions,
|
|
23
|
+
WORKFLOW_SERIALIZE,
|
|
24
|
+
WORKFLOW_DESERIALIZE,
|
|
25
|
+
type ParseResult,
|
|
22
26
|
} from '@ai-sdk/provider-utils';
|
|
23
27
|
import { z } from 'zod/v4';
|
|
24
28
|
import { convertToOpenResponsesInput } from './convert-to-open-responses-input';
|
|
25
29
|
import {
|
|
26
|
-
FunctionToolParam,
|
|
27
|
-
OpenResponsesRequestBody,
|
|
28
|
-
OpenResponsesResponseBody,
|
|
29
|
-
OpenResponsesChunk,
|
|
30
30
|
openResponsesErrorSchema,
|
|
31
|
-
|
|
31
|
+
type FunctionToolParam,
|
|
32
|
+
type OpenResponsesRequestBody,
|
|
33
|
+
type OpenResponsesResponseBody,
|
|
34
|
+
type OpenResponsesChunk,
|
|
35
|
+
type ToolChoiceParam,
|
|
32
36
|
} from './open-responses-api';
|
|
33
37
|
import { mapOpenResponsesFinishReason } from './map-open-responses-finish-reason';
|
|
34
|
-
import { OpenResponsesConfig } from './open-responses-config';
|
|
38
|
+
import type { OpenResponsesConfig } from './open-responses-config';
|
|
39
|
+
import { openResponsesLanguageModelOptions } from './open-responses-language-model-options';
|
|
35
40
|
|
|
36
41
|
export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
37
42
|
readonly specificationVersion = 'v4';
|
|
@@ -40,6 +45,20 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
40
45
|
|
|
41
46
|
private readonly config: OpenResponsesConfig;
|
|
42
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
|
+
|
|
43
62
|
constructor(modelId: string, config: OpenResponsesConfig) {
|
|
44
63
|
this.modelId = modelId;
|
|
45
64
|
this.config = config;
|
|
@@ -130,6 +149,12 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
130
149
|
}
|
|
131
150
|
: undefined;
|
|
132
151
|
|
|
152
|
+
const openResponsesOptions = await parseProviderOptions({
|
|
153
|
+
provider: this.config.providerOptionsName,
|
|
154
|
+
providerOptions,
|
|
155
|
+
schema: openResponsesLanguageModelOptions,
|
|
156
|
+
});
|
|
157
|
+
|
|
133
158
|
const resolvedReasoningEffort = isCustomReasoning(reasoning)
|
|
134
159
|
? reasoning === 'none'
|
|
135
160
|
? 'none'
|
|
@@ -157,8 +182,16 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
157
182
|
presence_penalty: presencePenalty,
|
|
158
183
|
frequency_penalty: frequencyPenalty,
|
|
159
184
|
reasoning:
|
|
160
|
-
resolvedReasoningEffort != null
|
|
161
|
-
|
|
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
|
+
}
|
|
162
195
|
: undefined,
|
|
163
196
|
tools: functionTools?.length ? functionTools : undefined,
|
|
164
197
|
tool_choice: convertedToolChoice,
|
|
@@ -179,7 +212,7 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
179
212
|
rawValue: rawResponse,
|
|
180
213
|
} = await postJsonToApi({
|
|
181
214
|
url: this.config.url,
|
|
182
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
215
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
183
216
|
body,
|
|
184
217
|
failedResponseHandler: createJsonErrorResponseHandler({
|
|
185
218
|
errorSchema: openResponsesErrorSchema,
|
|
@@ -284,7 +317,7 @@ export class OpenResponsesLanguageModel implements LanguageModelV4 {
|
|
|
284
317
|
|
|
285
318
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
286
319
|
url: this.config.url,
|
|
287
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
320
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
288
321
|
body: {
|
|
289
322
|
...body,
|
|
290
323
|
stream: true,
|
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 };
|