@ai-sdk/gateway 4.0.147 → 4.0.149
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 +13 -0
- package/dist/index.d.ts +17 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +223 -35
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +29 -0
- package/package.json +1 -1
- package/src/gateway-decision-model-settings.ts +4 -0
- package/src/gateway-decision-model.ts +7 -52
- package/src/gateway-extraction-model-settings.ts +1 -0
- package/src/gateway-extraction-model.ts +287 -0
- package/src/gateway-language-model-settings.ts +5 -0
- package/src/gateway-model-entry.ts +1 -0
- package/src/gateway-provider.ts +26 -0
- package/src/gateway-video-model-settings.ts +1 -0
- package/src/gateway-warning-schema.ts +24 -0
- package/src/index.ts +1 -0
- package/src/to-gateway-state-parts.ts +34 -0
package/docs/00-ai-gateway.mdx
CHANGED
|
@@ -503,6 +503,35 @@ console.log(ranking);
|
|
|
503
503
|
|
|
504
504
|
Reranking models are useful for improving search results in retrieval-augmented generation (RAG) pipelines by re-scoring candidate documents after an initial retrieval step.
|
|
505
505
|
|
|
506
|
+
## Extraction Models
|
|
507
|
+
|
|
508
|
+
<Note type="warning">
|
|
509
|
+
Extraction is experimental and the API may change in patch releases.
|
|
510
|
+
</Note>
|
|
511
|
+
|
|
512
|
+
You can create extraction models using the `extractionModel` method on the provider instance and use them with [`experimental_extract`](/docs/ai-sdk-core/extractions):
|
|
513
|
+
|
|
514
|
+
```ts
|
|
515
|
+
import { gateway } from '@ai-sdk/gateway';
|
|
516
|
+
import { experimental_extract } from 'ai';
|
|
517
|
+
|
|
518
|
+
const { answers } = await experimental_extract({
|
|
519
|
+
model: gateway.extractionModel('scaledown/extract-1'),
|
|
520
|
+
state: 'Invoice INV-2041 from Acme Corp. Contacts: Ana, Bo.',
|
|
521
|
+
fields: {
|
|
522
|
+
invoiceNumber: { type: 'text', instructions: 'The invoice number' },
|
|
523
|
+
contacts: { type: 'list', items: 'text', instructions: 'Contact names' },
|
|
524
|
+
},
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
console.log(answers.invoiceNumber.value); // 'INV-2041'
|
|
528
|
+
console.log(answers.contacts.value); // ['Ana', 'Bo']
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
- **Field types:** which field types are supported depends on the model. A field the model cannot extract throws `Experimental_ExtractionUnsupportedFieldTypeError` with the `fieldId` and `fieldType`, after the request reaches the gateway.
|
|
532
|
+
- **Files:** send file state inline, as bytes or base64. Files given as a URL are downloaded by `experimental_extract` when you pass `experimental_download`. File references are sent to the gateway unchanged, which rejects them for now, so they fail after the request is sent.
|
|
533
|
+
- **Provider options:** [gateway provider options](#gateway-provider-options) such as `user` and `tags` go under `providerOptions.gateway`.
|
|
534
|
+
|
|
506
535
|
## Streaming Speech Models
|
|
507
536
|
|
|
508
537
|
<Note type="warning">
|
package/package.json
CHANGED
|
@@ -4,8 +4,12 @@ export type GatewayDecisionModelId =
|
|
|
4
4
|
| 'baseten/mammoth-1'
|
|
5
5
|
| 'convaiinnovations/laya'
|
|
6
6
|
| 'google/gemini-decision-1'
|
|
7
|
+
| 'heygen/heygen-decision-1'
|
|
8
|
+
| 'heygen/heygen-decision-1-turbo'
|
|
7
9
|
| 'liquid/d1'
|
|
8
10
|
| 'liquid/d1-ultra'
|
|
11
|
+
| 'liquid/d1.2'
|
|
12
|
+
| 'liquid/d1.2-ultra'
|
|
9
13
|
| 'microsoft/microsoft-decision-1'
|
|
10
14
|
| 'nace-ai/drex-max-finance'
|
|
11
15
|
| 'nace-ai/drex-max-v1.1'
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type Experimental_DecisionModelV4State as DecisionModelV4State,
|
|
5
|
-
type SharedV4ProviderMetadata,
|
|
1
|
+
import type {
|
|
2
|
+
Experimental_DecisionModelV4 as DecisionModelV4,
|
|
3
|
+
SharedV4ProviderMetadata,
|
|
6
4
|
} from '@ai-sdk/provider';
|
|
7
5
|
import {
|
|
8
6
|
combineHeaders,
|
|
9
|
-
convertUint8ArrayToBase64,
|
|
10
7
|
createJsonErrorResponseHandler,
|
|
11
8
|
createJsonResponseHandler,
|
|
12
9
|
getErrorMessage,
|
|
@@ -22,6 +19,8 @@ import { asGatewayError } from './errors';
|
|
|
22
19
|
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
23
20
|
import type { GatewayConfig } from './gateway-config';
|
|
24
21
|
import { gatewayDecisionProviderOptionsSchema } from './gateway-provider-options';
|
|
22
|
+
import { gatewayWarningSchema } from './gateway-warning-schema';
|
|
23
|
+
import { toGatewayStateParts } from './to-gateway-state-parts';
|
|
25
24
|
|
|
26
25
|
export class GatewayDecisionModel implements DecisionModelV4 {
|
|
27
26
|
readonly specificationVersion = 'v4';
|
|
@@ -56,7 +55,7 @@ export class GatewayDecisionModel implements DecisionModelV4 {
|
|
|
56
55
|
}: Parameters<DecisionModelV4['doDecide']>[0]): Promise<
|
|
57
56
|
Awaited<ReturnType<DecisionModelV4['doDecide']>>
|
|
58
57
|
> {
|
|
59
|
-
const stateParts =
|
|
58
|
+
const stateParts = toGatewayStateParts({ state, modelType: 'decision' });
|
|
60
59
|
const gatewayOptions = await parseProviderOptions({
|
|
61
60
|
provider: 'gateway',
|
|
62
61
|
providerOptions,
|
|
@@ -156,29 +155,6 @@ const gatewayDecisionAnswerSchema = () =>
|
|
|
156
155
|
}),
|
|
157
156
|
]);
|
|
158
157
|
|
|
159
|
-
const gatewayDecisionWarningSchema = () =>
|
|
160
|
-
z.discriminatedUnion('type', [
|
|
161
|
-
z.object({
|
|
162
|
-
type: z.literal('unsupported'),
|
|
163
|
-
feature: z.string(),
|
|
164
|
-
details: z.optional(z.string()),
|
|
165
|
-
}),
|
|
166
|
-
z.object({
|
|
167
|
-
type: z.literal('compatibility'),
|
|
168
|
-
feature: z.string(),
|
|
169
|
-
details: z.optional(z.string()),
|
|
170
|
-
}),
|
|
171
|
-
z.object({
|
|
172
|
-
type: z.literal('deprecated'),
|
|
173
|
-
setting: z.string(),
|
|
174
|
-
message: z.string(),
|
|
175
|
-
}),
|
|
176
|
-
z.object({
|
|
177
|
-
type: z.literal('other'),
|
|
178
|
-
message: z.string(),
|
|
179
|
-
}),
|
|
180
|
-
]);
|
|
181
|
-
|
|
182
158
|
const gatewayDecisionResponseSchema = lazySchema(() =>
|
|
183
159
|
zodSchema(
|
|
184
160
|
z.object({
|
|
@@ -196,31 +172,10 @@ const gatewayDecisionResponseSchema = lazySchema(() =>
|
|
|
196
172
|
outputTokens: z.optional(z.number()),
|
|
197
173
|
}),
|
|
198
174
|
),
|
|
199
|
-
warnings: z.optional(z.array(
|
|
175
|
+
warnings: z.optional(z.array(gatewayWarningSchema())),
|
|
200
176
|
providerMetadata: z.optional(
|
|
201
177
|
z.record(z.string(), z.record(z.string(), z.unknown())),
|
|
202
178
|
),
|
|
203
179
|
}),
|
|
204
180
|
),
|
|
205
181
|
);
|
|
206
|
-
|
|
207
|
-
function toGatewayDecisionState(
|
|
208
|
-
state: DecisionModelV4State,
|
|
209
|
-
): DecisionModelV4State {
|
|
210
|
-
return state.map(part => {
|
|
211
|
-
if (part.type !== 'file') return part;
|
|
212
|
-
if (part.data.type !== 'data') {
|
|
213
|
-
throw new UnsupportedFunctionalityError({
|
|
214
|
-
functionality: `Gateway decision file input: ${part.data.type} data`,
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
const { data } = part.data;
|
|
218
|
-
return {
|
|
219
|
-
...part,
|
|
220
|
-
data: {
|
|
221
|
-
type: 'data',
|
|
222
|
-
data: typeof data === 'string' ? data : convertUint8ArrayToBase64(data),
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
});
|
|
226
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type GatewayExtractionModelId = string & {};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
APICallError,
|
|
3
|
+
Experimental_ExtractionUnsupportedFieldTypeError as ExtractionUnsupportedFieldTypeError,
|
|
4
|
+
type Experimental_ExtractionModelV4 as ExtractionModelV4,
|
|
5
|
+
type Experimental_ExtractionModelV4Result as ExtractionModelV4Result,
|
|
6
|
+
type SharedV4ProviderMetadata,
|
|
7
|
+
} from '@ai-sdk/provider';
|
|
8
|
+
import {
|
|
9
|
+
combineHeaders,
|
|
10
|
+
createJsonErrorResponseHandler,
|
|
11
|
+
createJsonResponseHandler,
|
|
12
|
+
getErrorMessage,
|
|
13
|
+
lazySchema,
|
|
14
|
+
postJsonToApi,
|
|
15
|
+
resolve,
|
|
16
|
+
safeValidateTypes,
|
|
17
|
+
zodSchema,
|
|
18
|
+
type Resolvable,
|
|
19
|
+
} from '@ai-sdk/provider-utils';
|
|
20
|
+
import { z } from './zod';
|
|
21
|
+
import { asGatewayError } from './errors';
|
|
22
|
+
import { extractApiCallResponse } from './errors/extract-api-call-response';
|
|
23
|
+
import { parseAuthMethod } from './errors/parse-auth-method';
|
|
24
|
+
import type { GatewayConfig } from './gateway-config';
|
|
25
|
+
import { gatewayWarningSchema } from './gateway-warning-schema';
|
|
26
|
+
import { toGatewayStateParts } from './to-gateway-state-parts';
|
|
27
|
+
|
|
28
|
+
export class GatewayExtractionModel implements ExtractionModelV4 {
|
|
29
|
+
readonly specificationVersion = 'v4';
|
|
30
|
+
|
|
31
|
+
// Support varies by model, so the gateway rejects unsupported fields.
|
|
32
|
+
readonly supportedFieldTypes = [
|
|
33
|
+
'text',
|
|
34
|
+
'number',
|
|
35
|
+
'date',
|
|
36
|
+
'time',
|
|
37
|
+
'datetime',
|
|
38
|
+
'duration',
|
|
39
|
+
'list',
|
|
40
|
+
] as const;
|
|
41
|
+
|
|
42
|
+
constructor(
|
|
43
|
+
readonly modelId: string,
|
|
44
|
+
private readonly config: GatewayConfig & {
|
|
45
|
+
provider: string;
|
|
46
|
+
o11yHeaders: Resolvable<Record<string, string>>;
|
|
47
|
+
},
|
|
48
|
+
) {}
|
|
49
|
+
|
|
50
|
+
get provider(): string {
|
|
51
|
+
return this.config.provider;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async doExtract({
|
|
55
|
+
state,
|
|
56
|
+
fields,
|
|
57
|
+
referenceDate,
|
|
58
|
+
maxOutputTokens,
|
|
59
|
+
reasoning,
|
|
60
|
+
headers,
|
|
61
|
+
abortSignal,
|
|
62
|
+
providerOptions,
|
|
63
|
+
}: Parameters<ExtractionModelV4['doExtract']>[0]): Promise<
|
|
64
|
+
Awaited<ReturnType<ExtractionModelV4['doExtract']>>
|
|
65
|
+
> {
|
|
66
|
+
const stateParts = toGatewayStateParts({
|
|
67
|
+
state,
|
|
68
|
+
modelType: 'extraction',
|
|
69
|
+
allowReferences: true,
|
|
70
|
+
});
|
|
71
|
+
const resolvedHeaders = this.config.headers
|
|
72
|
+
? await resolve(this.config.headers)
|
|
73
|
+
: undefined;
|
|
74
|
+
try {
|
|
75
|
+
const {
|
|
76
|
+
responseHeaders,
|
|
77
|
+
value: responseBody,
|
|
78
|
+
rawValue,
|
|
79
|
+
} = await postJsonToApi({
|
|
80
|
+
url: this.getUrl(),
|
|
81
|
+
headers: combineHeaders(
|
|
82
|
+
resolvedHeaders,
|
|
83
|
+
headers ?? {},
|
|
84
|
+
this.getModelConfigHeaders(),
|
|
85
|
+
await resolve(this.config.o11yHeaders),
|
|
86
|
+
),
|
|
87
|
+
body: {
|
|
88
|
+
stateParts,
|
|
89
|
+
fields,
|
|
90
|
+
referenceDate,
|
|
91
|
+
maxOutputTokens,
|
|
92
|
+
reasoning,
|
|
93
|
+
...(providerOptions ? { providerOptions } : {}),
|
|
94
|
+
},
|
|
95
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
96
|
+
gatewayExtractionResponseSchema,
|
|
97
|
+
),
|
|
98
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
99
|
+
errorSchema: z.any(),
|
|
100
|
+
errorToMessage: data => getErrorMessage(data) ?? 'unknown error',
|
|
101
|
+
}),
|
|
102
|
+
...(abortSignal && { abortSignal }),
|
|
103
|
+
fetch: this.config.fetch,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
answers: omitNulls(
|
|
108
|
+
responseBody.answers,
|
|
109
|
+
) as ExtractionModelV4Result['answers'],
|
|
110
|
+
...(responseBody.usage
|
|
111
|
+
? {
|
|
112
|
+
usage: {
|
|
113
|
+
inputTokens: responseBody.usage.inputTokens ?? undefined,
|
|
114
|
+
outputTokens: responseBody.usage.outputTokens ?? undefined,
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
: {}),
|
|
118
|
+
warnings: responseBody.warnings ?? [],
|
|
119
|
+
providerMetadata: (responseBody.providerMetadata ??
|
|
120
|
+
undefined) as unknown as SharedV4ProviderMetadata,
|
|
121
|
+
response: {
|
|
122
|
+
modelId: responseBody.model ?? this.modelId,
|
|
123
|
+
headers: responseHeaders,
|
|
124
|
+
body: rawValue,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
const unsupportedField = await getUnsupportedField(error);
|
|
129
|
+
if (unsupportedField != null) {
|
|
130
|
+
throw new ExtractionUnsupportedFieldTypeError({
|
|
131
|
+
...unsupportedField,
|
|
132
|
+
provider: this.provider,
|
|
133
|
+
modelId: this.modelId,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
throw await asGatewayError(
|
|
137
|
+
error,
|
|
138
|
+
await parseAuthMethod(resolvedHeaders ?? {}),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private getUrl() {
|
|
144
|
+
return `${this.config.baseURL}/extraction-model`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private getModelConfigHeaders() {
|
|
148
|
+
return {
|
|
149
|
+
'ai-extraction-model-specification-version': '4',
|
|
150
|
+
'ai-model-id': this.modelId,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const gatewayExtractionSourceSchema = () =>
|
|
156
|
+
z.discriminatedUnion('type', [
|
|
157
|
+
z.object({
|
|
158
|
+
type: z.literal('text'),
|
|
159
|
+
part: z.number(),
|
|
160
|
+
start: z.number(),
|
|
161
|
+
end: z.number(),
|
|
162
|
+
}),
|
|
163
|
+
z.object({
|
|
164
|
+
type: z.literal('file'),
|
|
165
|
+
part: z.number(),
|
|
166
|
+
}),
|
|
167
|
+
]);
|
|
168
|
+
|
|
169
|
+
const stringAnswerSchema = <TYPE extends string>(type: TYPE) =>
|
|
170
|
+
z.object({
|
|
171
|
+
type: z.literal(type),
|
|
172
|
+
value: z.nullable(z.string()),
|
|
173
|
+
guess: z.nullish(z.string()),
|
|
174
|
+
pNull: z.nullish(z.number()),
|
|
175
|
+
confidence: z.nullish(z.number()),
|
|
176
|
+
source: z.nullish(gatewayExtractionSourceSchema()),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const numberAnswerSchema = <TYPE extends string>(type: TYPE) =>
|
|
180
|
+
z.object({
|
|
181
|
+
type: z.literal(type),
|
|
182
|
+
value: z.nullable(z.number()),
|
|
183
|
+
guess: z.nullish(z.number()),
|
|
184
|
+
pNull: z.nullish(z.number()),
|
|
185
|
+
confidence: z.nullish(z.number()),
|
|
186
|
+
source: z.nullish(gatewayExtractionSourceSchema()),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const gatewayExtractionAnswerSchema = () =>
|
|
190
|
+
z.discriminatedUnion('type', [
|
|
191
|
+
stringAnswerSchema('text'),
|
|
192
|
+
numberAnswerSchema('number'),
|
|
193
|
+
stringAnswerSchema('date'),
|
|
194
|
+
stringAnswerSchema('time'),
|
|
195
|
+
stringAnswerSchema('datetime'),
|
|
196
|
+
numberAnswerSchema('duration'),
|
|
197
|
+
z.object({
|
|
198
|
+
type: z.literal('list'),
|
|
199
|
+
value: z.nullable(z.union([z.array(z.string()), z.array(z.number())])),
|
|
200
|
+
pNull: z.nullish(z.number()),
|
|
201
|
+
confidence: z.nullish(z.number()),
|
|
202
|
+
items: z.nullish(
|
|
203
|
+
z.array(
|
|
204
|
+
z.object({
|
|
205
|
+
confidence: z.nullish(z.number()),
|
|
206
|
+
source: z.nullish(gatewayExtractionSourceSchema()),
|
|
207
|
+
}),
|
|
208
|
+
),
|
|
209
|
+
),
|
|
210
|
+
}),
|
|
211
|
+
z.object({
|
|
212
|
+
type: z.literal('refusal'),
|
|
213
|
+
}),
|
|
214
|
+
]);
|
|
215
|
+
|
|
216
|
+
// Warnings are advisory: one this client does not know is kept as `other`
|
|
217
|
+
// instead of failing a successful response.
|
|
218
|
+
const gatewayExtractionWarningSchema = () =>
|
|
219
|
+
z.union([
|
|
220
|
+
gatewayWarningSchema(),
|
|
221
|
+
z.pipe(
|
|
222
|
+
z.unknown(),
|
|
223
|
+
z.transform(warning => ({
|
|
224
|
+
type: 'other' as const,
|
|
225
|
+
message: `Unknown warning: ${JSON.stringify(warning)}`,
|
|
226
|
+
})),
|
|
227
|
+
),
|
|
228
|
+
]);
|
|
229
|
+
|
|
230
|
+
const gatewayExtractionResponseSchema = lazySchema(() =>
|
|
231
|
+
zodSchema(
|
|
232
|
+
z.object({
|
|
233
|
+
answers: z.record(z.string(), gatewayExtractionAnswerSchema()),
|
|
234
|
+
model: z.nullish(z.string()),
|
|
235
|
+
usage: z.nullish(
|
|
236
|
+
z.object({
|
|
237
|
+
inputTokens: z.nullish(z.number()),
|
|
238
|
+
outputTokens: z.nullish(z.number()),
|
|
239
|
+
}),
|
|
240
|
+
),
|
|
241
|
+
warnings: z.nullish(z.array(gatewayExtractionWarningSchema())),
|
|
242
|
+
providerMetadata: z.nullish(
|
|
243
|
+
z.record(z.string(), z.record(z.string(), z.unknown())),
|
|
244
|
+
),
|
|
245
|
+
}),
|
|
246
|
+
),
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const gatewayUnsupportedFieldErrorSchema = lazySchema(() =>
|
|
250
|
+
zodSchema(
|
|
251
|
+
z.object({
|
|
252
|
+
error: z.object({
|
|
253
|
+
type: z.literal('invalid_request_error'),
|
|
254
|
+
param: z.object({
|
|
255
|
+
name: z.literal('AI_ExtractionUnsupportedFieldTypeError'),
|
|
256
|
+
fieldId: z.string(),
|
|
257
|
+
fieldType: z.string(),
|
|
258
|
+
}),
|
|
259
|
+
}),
|
|
260
|
+
}),
|
|
261
|
+
),
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
/** Reads the field from the gateway's unsupported field type response. */
|
|
265
|
+
async function getUnsupportedField(
|
|
266
|
+
error: unknown,
|
|
267
|
+
): Promise<{ fieldId: string; fieldType: string } | undefined> {
|
|
268
|
+
if (!APICallError.isInstance(error)) return undefined;
|
|
269
|
+
const result = await safeValidateTypes({
|
|
270
|
+
value: extractApiCallResponse(error),
|
|
271
|
+
schema: gatewayUnsupportedFieldErrorSchema,
|
|
272
|
+
});
|
|
273
|
+
if (!result.success) return undefined;
|
|
274
|
+
const { fieldId, fieldType } = result.value.error.param;
|
|
275
|
+
return { fieldId, fieldType };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Drops `null` optional fields, which the specification leaves out. */
|
|
279
|
+
function omitNulls(value: unknown): unknown {
|
|
280
|
+
if (Array.isArray(value)) return value.map(omitNulls);
|
|
281
|
+
if (value == null || typeof value !== 'object') return value;
|
|
282
|
+
return Object.fromEntries(
|
|
283
|
+
Object.entries(value)
|
|
284
|
+
.filter(([key, entry]) => entry !== null || key === 'value')
|
|
285
|
+
.map(([key, entry]) => [key, omitNulls(entry)]),
|
|
286
|
+
);
|
|
287
|
+
}
|
|
@@ -251,6 +251,10 @@ export type GatewayModelId =
|
|
|
251
251
|
| 'openai/gpt-6.1-sol-fast'
|
|
252
252
|
| 'openai/gpt-6.1-terra'
|
|
253
253
|
| 'openai/gpt-6.1-terra-fast'
|
|
254
|
+
| 'openai/gpt-6.2-astra'
|
|
255
|
+
| 'openai/gpt-6.2-astra-fast'
|
|
256
|
+
| 'openai/gpt-6.2-sol'
|
|
257
|
+
| 'openai/gpt-6.2-sol-fast'
|
|
254
258
|
| 'openai/gpt-oss-120b'
|
|
255
259
|
| 'openai/gpt-oss-20b'
|
|
256
260
|
| 'openai/gpt-oss-safeguard-120b'
|
|
@@ -266,6 +270,7 @@ export type GatewayModelId =
|
|
|
266
270
|
| 'perplexity/sonar'
|
|
267
271
|
| 'quiverai/arrow-2'
|
|
268
272
|
| 'quiverai/arrow-2-telos'
|
|
273
|
+
| 'recursive/flint-v1.0'
|
|
269
274
|
| 'reflection/beam'
|
|
270
275
|
| 'reflection/beam-free'
|
|
271
276
|
| 'sakana/fugu-max'
|
package/src/gateway-provider.ts
CHANGED
|
@@ -41,6 +41,7 @@ import { GatewayEmbeddingModel } from './gateway-embedding-model';
|
|
|
41
41
|
import { GatewayImageModel } from './gateway-image-model';
|
|
42
42
|
import { GatewayVideoModel } from './gateway-video-model';
|
|
43
43
|
import { GatewayDecisionModel } from './gateway-decision-model';
|
|
44
|
+
import { GatewayExtractionModel } from './gateway-extraction-model';
|
|
44
45
|
import { GatewayRerankingModel } from './gateway-reranking-model';
|
|
45
46
|
import { GatewaySpeechModel, toGatewaySpeechUrl } from './gateway-speech-model';
|
|
46
47
|
import {
|
|
@@ -50,6 +51,7 @@ import {
|
|
|
50
51
|
import { GatewayRealtimeModel } from './gateway-realtime-model';
|
|
51
52
|
import type { GatewayEmbeddingModelId } from './gateway-embedding-model-settings';
|
|
52
53
|
import type { GatewayDecisionModelId } from './gateway-decision-model-settings';
|
|
54
|
+
import type { GatewayExtractionModelId } from './gateway-extraction-model-settings';
|
|
53
55
|
import type { GatewayImageModelId } from './gateway-image-model-settings';
|
|
54
56
|
import type { GatewayRerankingModelId } from './gateway-reranking-model-settings';
|
|
55
57
|
import type { GatewaySpeechModelId } from './gateway-speech-model-settings';
|
|
@@ -69,6 +71,7 @@ import {
|
|
|
69
71
|
type TranscriptionModelV4,
|
|
70
72
|
type Experimental_VideoModelV4,
|
|
71
73
|
type Experimental_DecisionModelV4,
|
|
74
|
+
type Experimental_ExtractionModelV4,
|
|
72
75
|
type Experimental_StreamingSpeechModelV4,
|
|
73
76
|
type Experimental_RealtimeFactoryV4 as RealtimeFactoryV4,
|
|
74
77
|
type Experimental_RealtimeFactoryV4GetTokenOptions as RealtimeFactoryV4GetTokenOptions,
|
|
@@ -184,6 +187,18 @@ export interface GatewayProvider extends ProviderV4 {
|
|
|
184
187
|
modelId: GatewayDecisionModelId,
|
|
185
188
|
): ReturnType<GatewayProvider['evaluationModel']>;
|
|
186
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Creates a model for extracting typed field values from shared state.
|
|
192
|
+
*/
|
|
193
|
+
extraction(modelId: GatewayExtractionModelId): Experimental_ExtractionModelV4;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Creates a model for extracting typed field values from shared state.
|
|
197
|
+
*/
|
|
198
|
+
extractionModel(
|
|
199
|
+
modelId: GatewayExtractionModelId,
|
|
200
|
+
): Experimental_ExtractionModelV4;
|
|
201
|
+
|
|
187
202
|
/**
|
|
188
203
|
* Creates a model for text-to-speech generation.
|
|
189
204
|
*/
|
|
@@ -688,6 +703,17 @@ export function createGateway(
|
|
|
688
703
|
provider.decision = createDecisionModel;
|
|
689
704
|
provider.evaluationModel = createDecisionModel;
|
|
690
705
|
provider.evaluation = createDecisionModel;
|
|
706
|
+
const createExtractionModel = (modelId: GatewayExtractionModelId) => {
|
|
707
|
+
return new GatewayExtractionModel(modelId, {
|
|
708
|
+
provider: 'gateway',
|
|
709
|
+
baseURL,
|
|
710
|
+
headers: getHeaders,
|
|
711
|
+
fetch: options.fetch,
|
|
712
|
+
o11yHeaders: createO11yHeaders(),
|
|
713
|
+
});
|
|
714
|
+
};
|
|
715
|
+
provider.extractionModel = createExtractionModel;
|
|
716
|
+
provider.extraction = createExtractionModel;
|
|
691
717
|
const createSpeechModel = (modelId: GatewaySpeechModelId) => {
|
|
692
718
|
return new GatewaySpeechModel(modelId, {
|
|
693
719
|
provider: 'gateway',
|
|
@@ -14,6 +14,7 @@ export type GatewayVideoModelId =
|
|
|
14
14
|
| 'bytedance/seedance-2.0-fast'
|
|
15
15
|
| 'bytedance/seedance-2.0-mini'
|
|
16
16
|
| 'bytedance/seedance-2.5'
|
|
17
|
+
| 'bytedance/seedance-2.5-flash'
|
|
17
18
|
| 'bytedance/seedance-v1.0-pro'
|
|
18
19
|
| 'bytedance/seedance-v1.0-pro-fast'
|
|
19
20
|
| 'google/veo-3.1-fast-generate-001'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from './zod';
|
|
2
|
+
|
|
3
|
+
export const gatewayWarningSchema = () =>
|
|
4
|
+
z.discriminatedUnion('type', [
|
|
5
|
+
z.object({
|
|
6
|
+
type: z.literal('unsupported'),
|
|
7
|
+
feature: z.string(),
|
|
8
|
+
details: z.optional(z.string()),
|
|
9
|
+
}),
|
|
10
|
+
z.object({
|
|
11
|
+
type: z.literal('compatibility'),
|
|
12
|
+
feature: z.string(),
|
|
13
|
+
details: z.optional(z.string()),
|
|
14
|
+
}),
|
|
15
|
+
z.object({
|
|
16
|
+
type: z.literal('deprecated'),
|
|
17
|
+
setting: z.string(),
|
|
18
|
+
message: z.string(),
|
|
19
|
+
}),
|
|
20
|
+
z.object({
|
|
21
|
+
type: z.literal('other'),
|
|
22
|
+
message: z.string(),
|
|
23
|
+
}),
|
|
24
|
+
]);
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { DecisionFallbackCondition } from './gateway-provider-options';
|
|
|
3
3
|
|
|
4
4
|
export type { GatewayEmbeddingModelId } from './gateway-embedding-model-settings';
|
|
5
5
|
export type { GatewayDecisionModelId } from './gateway-decision-model-settings';
|
|
6
|
+
export type { GatewayExtractionModelId } from './gateway-extraction-model-settings';
|
|
6
7
|
export type { GatewayImageModelId } from './gateway-image-model-settings';
|
|
7
8
|
export type { GatewayModelId } from './gateway-language-model-settings';
|
|
8
9
|
export {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UnsupportedFunctionalityError,
|
|
3
|
+
type Experimental_DecisionModelV4State as DecisionModelV4State,
|
|
4
|
+
} from '@ai-sdk/provider';
|
|
5
|
+
import { convertUint8ArrayToBase64 } from '@ai-sdk/provider-utils';
|
|
6
|
+
|
|
7
|
+
/** Converts inline file bytes to base64 and rejects file data that cannot be sent. */
|
|
8
|
+
export function toGatewayStateParts({
|
|
9
|
+
state,
|
|
10
|
+
modelType,
|
|
11
|
+
allowReferences = false,
|
|
12
|
+
}: {
|
|
13
|
+
state: DecisionModelV4State;
|
|
14
|
+
modelType: 'decision' | 'extraction';
|
|
15
|
+
allowReferences?: boolean;
|
|
16
|
+
}): DecisionModelV4State {
|
|
17
|
+
return state.map(part => {
|
|
18
|
+
if (part.type !== 'file') return part;
|
|
19
|
+
if (allowReferences && part.data.type === 'reference') return part;
|
|
20
|
+
if (part.data.type !== 'data') {
|
|
21
|
+
throw new UnsupportedFunctionalityError({
|
|
22
|
+
functionality: `Gateway ${modelType} file input: ${part.data.type} data`,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const { data } = part.data;
|
|
26
|
+
return {
|
|
27
|
+
...part,
|
|
28
|
+
data: {
|
|
29
|
+
type: 'data',
|
|
30
|
+
data: typeof data === 'string' ? data : convertUint8ArrayToBase64(data),
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|