@ai-sdk/gateway 4.0.109 → 4.0.111

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ai-sdk/gateway",
3
3
  "private": false,
4
- "version": "4.0.109",
4
+ "version": "4.0.111",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "sideEffects": false,
@@ -30,8 +30,8 @@
30
30
  }
31
31
  },
32
32
  "dependencies": {
33
- "@ai-sdk/provider": "4.0.26",
34
- "@ai-sdk/provider-utils": "5.0.58",
33
+ "@ai-sdk/provider": "4.0.27",
34
+ "@ai-sdk/provider-utils": "5.0.59",
35
35
  "@vercel/oidc": "3.2.0"
36
36
  },
37
37
  "devDependencies": {
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  UnsupportedFunctionalityError,
3
3
  type Experimental_DecisionModelV4 as DecisionModelV4,
4
+ type Experimental_DecisionModelV4State as DecisionModelV4State,
4
5
  type SharedV4ProviderMetadata,
5
6
  } from '@ai-sdk/provider';
6
7
  import {
7
8
  combineHeaders,
9
+ convertUint8ArrayToBase64,
8
10
  createJsonErrorResponseHandler,
9
11
  createJsonResponseHandler,
10
12
  getErrorMessage,
@@ -52,21 +54,7 @@ export class GatewayDecisionModel implements DecisionModelV4 {
52
54
  }: Parameters<DecisionModelV4['doDecide']>[0]): Promise<
53
55
  Awaited<ReturnType<DecisionModelV4['doDecide']>>
54
56
  > {
55
- const values = state.map(part => {
56
- if (part.type === 'file') {
57
- throw new UnsupportedFunctionalityError({
58
- functionality: 'Gateway decision file input',
59
- });
60
- }
61
- return part.type === 'text' ? part.text : part.value;
62
- });
63
- // Keep the legacy Gateway state format: string, JSON object, or JSON array.
64
- const requestState =
65
- values.length === 1 &&
66
- (typeof values[0] === 'string' ||
67
- (typeof values[0] === 'object' && values[0] !== null))
68
- ? values[0]
69
- : values;
57
+ const stateParts = toGatewayDecisionState(state);
70
58
  const gatewayOptions = await parseProviderOptions({
71
59
  provider: 'gateway',
72
60
  providerOptions,
@@ -93,7 +81,7 @@ export class GatewayDecisionModel implements DecisionModelV4 {
93
81
  await resolve(this.config.o11yHeaders),
94
82
  ),
95
83
  body: {
96
- state: requestState,
84
+ stateParts,
97
85
  questions,
98
86
  ...(validatedProviderOptions
99
87
  ? { providerOptions: validatedProviderOptions }
@@ -209,3 +197,24 @@ const gatewayDecisionResponseSchema = lazySchema(() =>
209
197
  }),
210
198
  ),
211
199
  );
200
+
201
+ function toGatewayDecisionState(
202
+ state: DecisionModelV4State,
203
+ ): DecisionModelV4State {
204
+ return state.map(part => {
205
+ if (part.type !== 'file') return part;
206
+ if (part.data.type !== 'data') {
207
+ throw new UnsupportedFunctionalityError({
208
+ functionality: `Gateway decision file input: ${part.data.type} data`,
209
+ });
210
+ }
211
+ const { data } = part.data;
212
+ return {
213
+ ...part,
214
+ data: {
215
+ type: 'data',
216
+ data: typeof data === 'string' ? data : convertUint8ArrayToBase64(data),
217
+ },
218
+ };
219
+ });
220
+ }