@opencode/ai 2.0.20 → 2.0.21
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/dist/cache-policy.js +15 -3
- package/dist/protocols/alibaba-chat.d.ts +16 -10
- package/dist/protocols/openai-chat.d.ts +114 -71
- package/dist/protocols/openai-chat.js +31 -32
- package/dist/protocols/openai-compatible-chat.d.ts +16 -10
- package/dist/protocols/zai-chat.d.ts +16 -10
- package/dist/provider-error.js +4 -0
- package/dist/providers/alibaba.d.ts +16 -10
- package/dist/providers/amazon-bedrock-mantle.d.ts +16 -10
- package/dist/providers/azure.d.ts +16 -10
- package/dist/providers/baseten.d.ts +32 -20
- package/dist/providers/cerebras.d.ts +32 -20
- package/dist/providers/cloudflare-ai-gateway.d.ts +32 -20
- package/dist/providers/cloudflare-ai-gateway.js +43 -35
- package/dist/providers/cloudflare-workers-ai.d.ts +32 -20
- package/dist/providers/deepinfra.d.ts +32 -20
- package/dist/providers/deepseek.d.ts +32 -20
- package/dist/providers/fireworks.d.ts +32 -20
- package/dist/providers/google-vertex-chat.d.ts +16 -10
- package/dist/providers/groq.d.ts +32 -20
- package/dist/providers/meta.d.ts +16 -10
- package/dist/providers/minimax.d.ts +16 -10
- package/dist/providers/moonshot.d.ts +16 -10
- package/dist/providers/openai-compatible.d.ts +16 -10
- package/dist/providers/openai.d.ts +16 -10
- package/dist/providers/openrouter.d.ts +64 -40
- package/dist/providers/togetherai.d.ts +32 -20
- package/dist/providers/xai.d.ts +16 -10
- package/dist/providers/zai-coding-plan.d.ts +16 -10
- package/dist/providers/zai.d.ts +16 -10
- package/package.json +3 -3
|
@@ -69,15 +69,18 @@ export declare const routes: (Route<{
|
|
|
69
69
|
})[];
|
|
70
70
|
} | {
|
|
71
71
|
readonly [x: string]: unknown;
|
|
72
|
-
readonly content: string |
|
|
72
|
+
readonly content: string | readonly {
|
|
73
|
+
readonly type: "text";
|
|
74
|
+
readonly text: string;
|
|
75
|
+
readonly cache_control?: {
|
|
76
|
+
readonly type: "ephemeral";
|
|
77
|
+
readonly ttl?: string | undefined;
|
|
78
|
+
} | undefined;
|
|
79
|
+
}[] | null;
|
|
73
80
|
readonly role: "assistant";
|
|
74
81
|
readonly reasoning?: string | undefined;
|
|
75
82
|
readonly reasoning_content?: string | undefined;
|
|
76
83
|
readonly reasoning_text?: string | undefined;
|
|
77
|
-
readonly cache_control?: {
|
|
78
|
-
readonly type: "ephemeral";
|
|
79
|
-
readonly ttl?: string | undefined;
|
|
80
|
-
} | undefined;
|
|
81
84
|
readonly tool_calls?: readonly {
|
|
82
85
|
readonly function: {
|
|
83
86
|
readonly name: string;
|
|
@@ -93,13 +96,16 @@ export declare const routes: (Route<{
|
|
|
93
96
|
}[] | undefined;
|
|
94
97
|
readonly reasoning_details?: unknown;
|
|
95
98
|
} | {
|
|
96
|
-
readonly content: string;
|
|
97
99
|
readonly role: "tool";
|
|
98
100
|
readonly tool_call_id: string;
|
|
99
|
-
readonly
|
|
100
|
-
readonly type: "
|
|
101
|
-
readonly
|
|
102
|
-
|
|
101
|
+
readonly content: string | readonly {
|
|
102
|
+
readonly type: "text";
|
|
103
|
+
readonly text: string;
|
|
104
|
+
readonly cache_control?: {
|
|
105
|
+
readonly type: "ephemeral";
|
|
106
|
+
readonly ttl?: string | undefined;
|
|
107
|
+
} | undefined;
|
|
108
|
+
}[];
|
|
103
109
|
})[];
|
|
104
110
|
readonly stream: true;
|
|
105
111
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -72,15 +72,18 @@ export declare const routes: (Route<{
|
|
|
72
72
|
})[];
|
|
73
73
|
} | {
|
|
74
74
|
readonly [x: string]: unknown;
|
|
75
|
-
readonly content: string |
|
|
75
|
+
readonly content: string | readonly {
|
|
76
|
+
readonly type: "text";
|
|
77
|
+
readonly text: string;
|
|
78
|
+
readonly cache_control?: {
|
|
79
|
+
readonly type: "ephemeral";
|
|
80
|
+
readonly ttl?: string | undefined;
|
|
81
|
+
} | undefined;
|
|
82
|
+
}[] | null;
|
|
76
83
|
readonly role: "assistant";
|
|
77
84
|
readonly reasoning?: string | undefined;
|
|
78
85
|
readonly reasoning_content?: string | undefined;
|
|
79
86
|
readonly reasoning_text?: string | undefined;
|
|
80
|
-
readonly cache_control?: {
|
|
81
|
-
readonly type: "ephemeral";
|
|
82
|
-
readonly ttl?: string | undefined;
|
|
83
|
-
} | undefined;
|
|
84
87
|
readonly tool_calls?: readonly {
|
|
85
88
|
readonly function: {
|
|
86
89
|
readonly name: string;
|
|
@@ -96,13 +99,16 @@ export declare const routes: (Route<{
|
|
|
96
99
|
}[] | undefined;
|
|
97
100
|
readonly reasoning_details?: unknown;
|
|
98
101
|
} | {
|
|
99
|
-
readonly content: string;
|
|
100
102
|
readonly role: "tool";
|
|
101
103
|
readonly tool_call_id: string;
|
|
102
|
-
readonly
|
|
103
|
-
readonly type: "
|
|
104
|
-
readonly
|
|
105
|
-
|
|
104
|
+
readonly content: string | readonly {
|
|
105
|
+
readonly type: "text";
|
|
106
|
+
readonly text: string;
|
|
107
|
+
readonly cache_control?: {
|
|
108
|
+
readonly type: "ephemeral";
|
|
109
|
+
readonly ttl?: string | undefined;
|
|
110
|
+
} | undefined;
|
|
111
|
+
}[];
|
|
106
112
|
})[];
|
|
107
113
|
readonly stream: true;
|
|
108
114
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -297,15 +297,18 @@ export declare const routes: (Route<{
|
|
|
297
297
|
})[];
|
|
298
298
|
} | {
|
|
299
299
|
readonly [x: string]: unknown;
|
|
300
|
-
readonly content: string |
|
|
300
|
+
readonly content: string | readonly {
|
|
301
|
+
readonly type: "text";
|
|
302
|
+
readonly text: string;
|
|
303
|
+
readonly cache_control?: {
|
|
304
|
+
readonly type: "ephemeral";
|
|
305
|
+
readonly ttl?: string | undefined;
|
|
306
|
+
} | undefined;
|
|
307
|
+
}[] | null;
|
|
301
308
|
readonly role: "assistant";
|
|
302
309
|
readonly reasoning?: string | undefined;
|
|
303
310
|
readonly reasoning_content?: string | undefined;
|
|
304
311
|
readonly reasoning_text?: string | undefined;
|
|
305
|
-
readonly cache_control?: {
|
|
306
|
-
readonly type: "ephemeral";
|
|
307
|
-
readonly ttl?: string | undefined;
|
|
308
|
-
} | undefined;
|
|
309
312
|
readonly tool_calls?: readonly {
|
|
310
313
|
readonly function: {
|
|
311
314
|
readonly name: string;
|
|
@@ -321,13 +324,16 @@ export declare const routes: (Route<{
|
|
|
321
324
|
}[] | undefined;
|
|
322
325
|
readonly reasoning_details?: unknown;
|
|
323
326
|
} | {
|
|
324
|
-
readonly content: string;
|
|
325
327
|
readonly role: "tool";
|
|
326
328
|
readonly tool_call_id: string;
|
|
327
|
-
readonly
|
|
328
|
-
readonly type: "
|
|
329
|
-
readonly
|
|
330
|
-
|
|
329
|
+
readonly content: string | readonly {
|
|
330
|
+
readonly type: "text";
|
|
331
|
+
readonly text: string;
|
|
332
|
+
readonly cache_control?: {
|
|
333
|
+
readonly type: "ephemeral";
|
|
334
|
+
readonly ttl?: string | undefined;
|
|
335
|
+
} | undefined;
|
|
336
|
+
}[];
|
|
331
337
|
})[];
|
|
332
338
|
readonly stream: true;
|
|
333
339
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -58,15 +58,18 @@ export declare const route: Route<{
|
|
|
58
58
|
})[];
|
|
59
59
|
} | {
|
|
60
60
|
readonly [x: string]: unknown;
|
|
61
|
-
readonly content: string |
|
|
61
|
+
readonly content: string | readonly {
|
|
62
|
+
readonly type: "text";
|
|
63
|
+
readonly text: string;
|
|
64
|
+
readonly cache_control?: {
|
|
65
|
+
readonly type: "ephemeral";
|
|
66
|
+
readonly ttl?: string | undefined;
|
|
67
|
+
} | undefined;
|
|
68
|
+
}[] | null;
|
|
62
69
|
readonly role: "assistant";
|
|
63
70
|
readonly reasoning?: string | undefined;
|
|
64
71
|
readonly reasoning_content?: string | undefined;
|
|
65
72
|
readonly reasoning_text?: string | undefined;
|
|
66
|
-
readonly cache_control?: {
|
|
67
|
-
readonly type: "ephemeral";
|
|
68
|
-
readonly ttl?: string | undefined;
|
|
69
|
-
} | undefined;
|
|
70
73
|
readonly tool_calls?: readonly {
|
|
71
74
|
readonly function: {
|
|
72
75
|
readonly name: string;
|
|
@@ -82,13 +85,16 @@ export declare const route: Route<{
|
|
|
82
85
|
}[] | undefined;
|
|
83
86
|
readonly reasoning_details?: unknown;
|
|
84
87
|
} | {
|
|
85
|
-
readonly content: string;
|
|
86
88
|
readonly role: "tool";
|
|
87
89
|
readonly tool_call_id: string;
|
|
88
|
-
readonly
|
|
89
|
-
readonly type: "
|
|
90
|
-
readonly
|
|
91
|
-
|
|
90
|
+
readonly content: string | readonly {
|
|
91
|
+
readonly type: "text";
|
|
92
|
+
readonly text: string;
|
|
93
|
+
readonly cache_control?: {
|
|
94
|
+
readonly type: "ephemeral";
|
|
95
|
+
readonly ttl?: string | undefined;
|
|
96
|
+
} | undefined;
|
|
97
|
+
}[];
|
|
92
98
|
})[];
|
|
93
99
|
readonly stream: true;
|
|
94
100
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -174,15 +180,18 @@ export declare const routes: Route<{
|
|
|
174
180
|
})[];
|
|
175
181
|
} | {
|
|
176
182
|
readonly [x: string]: unknown;
|
|
177
|
-
readonly content: string |
|
|
183
|
+
readonly content: string | readonly {
|
|
184
|
+
readonly type: "text";
|
|
185
|
+
readonly text: string;
|
|
186
|
+
readonly cache_control?: {
|
|
187
|
+
readonly type: "ephemeral";
|
|
188
|
+
readonly ttl?: string | undefined;
|
|
189
|
+
} | undefined;
|
|
190
|
+
}[] | null;
|
|
178
191
|
readonly role: "assistant";
|
|
179
192
|
readonly reasoning?: string | undefined;
|
|
180
193
|
readonly reasoning_content?: string | undefined;
|
|
181
194
|
readonly reasoning_text?: string | undefined;
|
|
182
|
-
readonly cache_control?: {
|
|
183
|
-
readonly type: "ephemeral";
|
|
184
|
-
readonly ttl?: string | undefined;
|
|
185
|
-
} | undefined;
|
|
186
195
|
readonly tool_calls?: readonly {
|
|
187
196
|
readonly function: {
|
|
188
197
|
readonly name: string;
|
|
@@ -198,13 +207,16 @@ export declare const routes: Route<{
|
|
|
198
207
|
}[] | undefined;
|
|
199
208
|
readonly reasoning_details?: unknown;
|
|
200
209
|
} | {
|
|
201
|
-
readonly content: string;
|
|
202
210
|
readonly role: "tool";
|
|
203
211
|
readonly tool_call_id: string;
|
|
204
|
-
readonly
|
|
205
|
-
readonly type: "
|
|
206
|
-
readonly
|
|
207
|
-
|
|
212
|
+
readonly content: string | readonly {
|
|
213
|
+
readonly type: "text";
|
|
214
|
+
readonly text: string;
|
|
215
|
+
readonly cache_control?: {
|
|
216
|
+
readonly type: "ephemeral";
|
|
217
|
+
readonly ttl?: string | undefined;
|
|
218
|
+
} | undefined;
|
|
219
|
+
}[];
|
|
208
220
|
})[];
|
|
209
221
|
readonly stream: true;
|
|
210
222
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -58,15 +58,18 @@ export declare const route: Route<{
|
|
|
58
58
|
})[];
|
|
59
59
|
} | {
|
|
60
60
|
readonly [x: string]: unknown;
|
|
61
|
-
readonly content: string |
|
|
61
|
+
readonly content: string | readonly {
|
|
62
|
+
readonly type: "text";
|
|
63
|
+
readonly text: string;
|
|
64
|
+
readonly cache_control?: {
|
|
65
|
+
readonly type: "ephemeral";
|
|
66
|
+
readonly ttl?: string | undefined;
|
|
67
|
+
} | undefined;
|
|
68
|
+
}[] | null;
|
|
62
69
|
readonly role: "assistant";
|
|
63
70
|
readonly reasoning?: string | undefined;
|
|
64
71
|
readonly reasoning_content?: string | undefined;
|
|
65
72
|
readonly reasoning_text?: string | undefined;
|
|
66
|
-
readonly cache_control?: {
|
|
67
|
-
readonly type: "ephemeral";
|
|
68
|
-
readonly ttl?: string | undefined;
|
|
69
|
-
} | undefined;
|
|
70
73
|
readonly tool_calls?: readonly {
|
|
71
74
|
readonly function: {
|
|
72
75
|
readonly name: string;
|
|
@@ -82,13 +85,16 @@ export declare const route: Route<{
|
|
|
82
85
|
}[] | undefined;
|
|
83
86
|
readonly reasoning_details?: unknown;
|
|
84
87
|
} | {
|
|
85
|
-
readonly content: string;
|
|
86
88
|
readonly role: "tool";
|
|
87
89
|
readonly tool_call_id: string;
|
|
88
|
-
readonly
|
|
89
|
-
readonly type: "
|
|
90
|
-
readonly
|
|
91
|
-
|
|
90
|
+
readonly content: string | readonly {
|
|
91
|
+
readonly type: "text";
|
|
92
|
+
readonly text: string;
|
|
93
|
+
readonly cache_control?: {
|
|
94
|
+
readonly type: "ephemeral";
|
|
95
|
+
readonly ttl?: string | undefined;
|
|
96
|
+
} | undefined;
|
|
97
|
+
}[];
|
|
92
98
|
})[];
|
|
93
99
|
readonly stream: true;
|
|
94
100
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -174,15 +180,18 @@ export declare const routes: Route<{
|
|
|
174
180
|
})[];
|
|
175
181
|
} | {
|
|
176
182
|
readonly [x: string]: unknown;
|
|
177
|
-
readonly content: string |
|
|
183
|
+
readonly content: string | readonly {
|
|
184
|
+
readonly type: "text";
|
|
185
|
+
readonly text: string;
|
|
186
|
+
readonly cache_control?: {
|
|
187
|
+
readonly type: "ephemeral";
|
|
188
|
+
readonly ttl?: string | undefined;
|
|
189
|
+
} | undefined;
|
|
190
|
+
}[] | null;
|
|
178
191
|
readonly role: "assistant";
|
|
179
192
|
readonly reasoning?: string | undefined;
|
|
180
193
|
readonly reasoning_content?: string | undefined;
|
|
181
194
|
readonly reasoning_text?: string | undefined;
|
|
182
|
-
readonly cache_control?: {
|
|
183
|
-
readonly type: "ephemeral";
|
|
184
|
-
readonly ttl?: string | undefined;
|
|
185
|
-
} | undefined;
|
|
186
195
|
readonly tool_calls?: readonly {
|
|
187
196
|
readonly function: {
|
|
188
197
|
readonly name: string;
|
|
@@ -198,13 +207,16 @@ export declare const routes: Route<{
|
|
|
198
207
|
}[] | undefined;
|
|
199
208
|
readonly reasoning_details?: unknown;
|
|
200
209
|
} | {
|
|
201
|
-
readonly content: string;
|
|
202
210
|
readonly role: "tool";
|
|
203
211
|
readonly tool_call_id: string;
|
|
204
|
-
readonly
|
|
205
|
-
readonly type: "
|
|
206
|
-
readonly
|
|
207
|
-
|
|
212
|
+
readonly content: string | readonly {
|
|
213
|
+
readonly type: "text";
|
|
214
|
+
readonly text: string;
|
|
215
|
+
readonly cache_control?: {
|
|
216
|
+
readonly type: "ephemeral";
|
|
217
|
+
readonly ttl?: string | undefined;
|
|
218
|
+
} | undefined;
|
|
219
|
+
}[];
|
|
208
220
|
})[];
|
|
209
221
|
readonly stream: true;
|
|
210
222
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -577,15 +577,18 @@ export declare const route: import("../route/client.js").Route<{
|
|
|
577
577
|
})[];
|
|
578
578
|
} | {
|
|
579
579
|
readonly [x: string]: unknown;
|
|
580
|
-
readonly content: string |
|
|
580
|
+
readonly content: string | readonly {
|
|
581
|
+
readonly type: "text";
|
|
582
|
+
readonly text: string;
|
|
583
|
+
readonly cache_control?: {
|
|
584
|
+
readonly type: "ephemeral";
|
|
585
|
+
readonly ttl?: string | undefined;
|
|
586
|
+
} | undefined;
|
|
587
|
+
}[] | null;
|
|
581
588
|
readonly role: "assistant";
|
|
582
589
|
readonly reasoning?: string | undefined;
|
|
583
590
|
readonly reasoning_content?: string | undefined;
|
|
584
591
|
readonly reasoning_text?: string | undefined;
|
|
585
|
-
readonly cache_control?: {
|
|
586
|
-
readonly type: "ephemeral";
|
|
587
|
-
readonly ttl?: string | undefined;
|
|
588
|
-
} | undefined;
|
|
589
592
|
readonly tool_calls?: readonly {
|
|
590
593
|
readonly function: {
|
|
591
594
|
readonly name: string;
|
|
@@ -601,13 +604,16 @@ export declare const route: import("../route/client.js").Route<{
|
|
|
601
604
|
}[] | undefined;
|
|
602
605
|
readonly reasoning_details?: unknown;
|
|
603
606
|
} | {
|
|
604
|
-
readonly content: string;
|
|
605
607
|
readonly role: "tool";
|
|
606
608
|
readonly tool_call_id: string;
|
|
607
|
-
readonly
|
|
608
|
-
readonly type: "
|
|
609
|
-
readonly
|
|
610
|
-
|
|
609
|
+
readonly content: string | readonly {
|
|
610
|
+
readonly type: "text";
|
|
611
|
+
readonly text: string;
|
|
612
|
+
readonly cache_control?: {
|
|
613
|
+
readonly type: "ephemeral";
|
|
614
|
+
readonly ttl?: string | undefined;
|
|
615
|
+
} | undefined;
|
|
616
|
+
}[];
|
|
611
617
|
})[];
|
|
612
618
|
readonly stream: true;
|
|
613
619
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -965,15 +971,18 @@ export declare const routes: (import("../route/client.js").Route<{
|
|
|
965
971
|
})[];
|
|
966
972
|
} | {
|
|
967
973
|
readonly [x: string]: unknown;
|
|
968
|
-
readonly content: string |
|
|
974
|
+
readonly content: string | readonly {
|
|
975
|
+
readonly type: "text";
|
|
976
|
+
readonly text: string;
|
|
977
|
+
readonly cache_control?: {
|
|
978
|
+
readonly type: "ephemeral";
|
|
979
|
+
readonly ttl?: string | undefined;
|
|
980
|
+
} | undefined;
|
|
981
|
+
}[] | null;
|
|
969
982
|
readonly role: "assistant";
|
|
970
983
|
readonly reasoning?: string | undefined;
|
|
971
984
|
readonly reasoning_content?: string | undefined;
|
|
972
985
|
readonly reasoning_text?: string | undefined;
|
|
973
|
-
readonly cache_control?: {
|
|
974
|
-
readonly type: "ephemeral";
|
|
975
|
-
readonly ttl?: string | undefined;
|
|
976
|
-
} | undefined;
|
|
977
986
|
readonly tool_calls?: readonly {
|
|
978
987
|
readonly function: {
|
|
979
988
|
readonly name: string;
|
|
@@ -989,13 +998,16 @@ export declare const routes: (import("../route/client.js").Route<{
|
|
|
989
998
|
}[] | undefined;
|
|
990
999
|
readonly reasoning_details?: unknown;
|
|
991
1000
|
} | {
|
|
992
|
-
readonly content: string;
|
|
993
1001
|
readonly role: "tool";
|
|
994
1002
|
readonly tool_call_id: string;
|
|
995
|
-
readonly
|
|
996
|
-
readonly type: "
|
|
997
|
-
readonly
|
|
998
|
-
|
|
1003
|
+
readonly content: string | readonly {
|
|
1004
|
+
readonly type: "text";
|
|
1005
|
+
readonly text: string;
|
|
1006
|
+
readonly cache_control?: {
|
|
1007
|
+
readonly type: "ephemeral";
|
|
1008
|
+
readonly ttl?: string | undefined;
|
|
1009
|
+
} | undefined;
|
|
1010
|
+
}[];
|
|
999
1011
|
})[];
|
|
1000
1012
|
readonly stream: true;
|
|
1001
1013
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -7,13 +7,20 @@ export const authEnvVars = ["CLOUDFLARE_API_TOKEN", "CF_AIG_TOKEN"];
|
|
|
7
7
|
export const baseURL = (input) => {
|
|
8
8
|
if (input.baseURL)
|
|
9
9
|
return input.baseURL;
|
|
10
|
-
|
|
11
|
-
throw new ProviderConfigurationError({
|
|
12
|
-
provider: id,
|
|
13
|
-
message: "CloudflareAIGateway.configure requires accountId unless baseURL is supplied",
|
|
14
|
-
});
|
|
15
|
-
return `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(input.accountId)}/ai/v1`;
|
|
10
|
+
return `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(requireAccountId(input))}/ai/v1`;
|
|
16
11
|
};
|
|
12
|
+
// Cloudflare's REST API rejects parts of the Anthropic Messages and OpenAI Responses request shapes, such as
|
|
13
|
+
// system prompt blocks and `minimal` reasoning effort, so these models use the provider-native gateway endpoints.
|
|
14
|
+
const passthroughURL = (input, provider) => `https://gateway.ai.cloudflare.com/v1/${encodeURIComponent(requireAccountId(input))}/${encodeURIComponent(gatewayId(input))}/${provider}`;
|
|
15
|
+
const requireAccountId = (input) => {
|
|
16
|
+
if (input.accountId)
|
|
17
|
+
return input.accountId;
|
|
18
|
+
throw new ProviderConfigurationError({
|
|
19
|
+
provider: id,
|
|
20
|
+
message: "CloudflareAIGateway.configure requires accountId unless baseURL is supplied",
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const gatewayId = (input) => input.gatewayId?.trim() || "default";
|
|
17
24
|
export const responsesRoute = OpenAIResponses.route.with({
|
|
18
25
|
id: "cloudflare-ai-gateway-responses",
|
|
19
26
|
provider: id,
|
|
@@ -30,16 +37,10 @@ export const route = OpenAIChat.route.with({
|
|
|
30
37
|
endpoint: { baseURL: undefined },
|
|
31
38
|
});
|
|
32
39
|
export const routes = [responsesRoute, messagesRoute, route];
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return Auth.optional(input.gatewayApiKey ?? ("apiKey" in input ? input.apiKey : undefined), "apiKey")
|
|
37
|
-
.orElse(Auth.config(authEnvVars[0]))
|
|
38
|
-
.orElse(Auth.config(authEnvVars[1]))
|
|
39
|
-
.bearer();
|
|
40
|
-
};
|
|
40
|
+
const credential = (input) => Auth.optional(input.gatewayApiKey ?? ("apiKey" in input ? input.apiKey : undefined), "apiKey")
|
|
41
|
+
.orElse(Auth.config(authEnvVars[0]))
|
|
42
|
+
.orElse(Auth.config(authEnvVars[1]));
|
|
41
43
|
const headers = (input) => ({
|
|
42
|
-
...(input.gatewayId === undefined ? {} : { "cf-aig-gateway-id": input.gatewayId.trim() || "default" }),
|
|
43
44
|
...(input.metadata === undefined
|
|
44
45
|
? {}
|
|
45
46
|
: { "cf-aig-metadata": Schema.encodeSync(Schema.fromJsonString(Schema.Unknown))(input.metadata) }),
|
|
@@ -49,34 +50,41 @@ const headers = (input) => ({
|
|
|
49
50
|
...(input.collectLog === undefined ? {} : { "cf-aig-collect-log": String(input.collectLog) }),
|
|
50
51
|
...input.headers,
|
|
51
52
|
});
|
|
52
|
-
const modelID = (input) => {
|
|
53
|
-
const value = String(input);
|
|
54
|
-
if (value.startsWith("workers-ai/"))
|
|
55
|
-
return value.slice("workers-ai/".length);
|
|
56
|
-
if (value.startsWith("anthropic/"))
|
|
57
|
-
return `anthropic/${value.slice("anthropic/".length).replaceAll(".", "-")}`;
|
|
58
|
-
return value;
|
|
59
|
-
};
|
|
60
53
|
export const configure = (input) => {
|
|
61
|
-
const
|
|
54
|
+
const custom = "auth" in input && input.auth ? input.auth : undefined;
|
|
55
|
+
const rest = {
|
|
62
56
|
endpoint: { baseURL: baseURL(input) },
|
|
63
|
-
auth:
|
|
64
|
-
headers: headers(input),
|
|
57
|
+
auth: custom ?? credential(input).bearer(),
|
|
58
|
+
headers: { "cf-aig-gateway-id": gatewayId(input), ...headers(input) },
|
|
65
59
|
http: input.http,
|
|
66
60
|
providerOptions: input.providerOptions,
|
|
67
61
|
};
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const
|
|
62
|
+
// A custom baseURL stands in for the REST API, so every model keeps using it with gateway model IDs.
|
|
63
|
+
const native = input.baseURL === undefined;
|
|
64
|
+
const passthrough = (provider) => native
|
|
65
|
+
? {
|
|
66
|
+
...rest,
|
|
67
|
+
endpoint: { baseURL: passthroughURL(input, provider) },
|
|
68
|
+
auth: custom ?? Auth.bearerHeader("cf-aig-authorization", credential(input)),
|
|
69
|
+
headers: headers(input),
|
|
70
|
+
}
|
|
71
|
+
: rest;
|
|
72
|
+
const responses = responsesRoute.with(passthrough("openai"));
|
|
73
|
+
const messages = messagesRoute.with(passthrough("anthropic/v1"));
|
|
74
|
+
const chat = route.with(rest);
|
|
71
75
|
return {
|
|
72
76
|
id,
|
|
73
77
|
model: (input) => {
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
return responses.model({ id:
|
|
77
|
-
if (
|
|
78
|
-
return messages.model({
|
|
79
|
-
|
|
78
|
+
const value = String(input);
|
|
79
|
+
if (value.startsWith("openai/"))
|
|
80
|
+
return responses.model({ id: native ? value.slice("openai/".length) : value });
|
|
81
|
+
if (value.startsWith("anthropic/"))
|
|
82
|
+
return messages.model({
|
|
83
|
+
id: native ? value.slice("anthropic/".length).replaceAll(".", "-") : value,
|
|
84
|
+
});
|
|
85
|
+
if (value.startsWith("workers-ai/"))
|
|
86
|
+
return chat.model({ id: value.slice("workers-ai/".length) });
|
|
87
|
+
return chat.model({ id: value });
|
|
80
88
|
},
|
|
81
89
|
configure,
|
|
82
90
|
};
|
|
@@ -62,15 +62,18 @@ export declare const route: Route<{
|
|
|
62
62
|
})[];
|
|
63
63
|
} | {
|
|
64
64
|
readonly [x: string]: unknown;
|
|
65
|
-
readonly content: string |
|
|
65
|
+
readonly content: string | readonly {
|
|
66
|
+
readonly type: "text";
|
|
67
|
+
readonly text: string;
|
|
68
|
+
readonly cache_control?: {
|
|
69
|
+
readonly type: "ephemeral";
|
|
70
|
+
readonly ttl?: string | undefined;
|
|
71
|
+
} | undefined;
|
|
72
|
+
}[] | null;
|
|
66
73
|
readonly role: "assistant";
|
|
67
74
|
readonly reasoning?: string | undefined;
|
|
68
75
|
readonly reasoning_content?: string | undefined;
|
|
69
76
|
readonly reasoning_text?: string | undefined;
|
|
70
|
-
readonly cache_control?: {
|
|
71
|
-
readonly type: "ephemeral";
|
|
72
|
-
readonly ttl?: string | undefined;
|
|
73
|
-
} | undefined;
|
|
74
77
|
readonly tool_calls?: readonly {
|
|
75
78
|
readonly function: {
|
|
76
79
|
readonly name: string;
|
|
@@ -86,13 +89,16 @@ export declare const route: Route<{
|
|
|
86
89
|
}[] | undefined;
|
|
87
90
|
readonly reasoning_details?: unknown;
|
|
88
91
|
} | {
|
|
89
|
-
readonly content: string;
|
|
90
92
|
readonly role: "tool";
|
|
91
93
|
readonly tool_call_id: string;
|
|
92
|
-
readonly
|
|
93
|
-
readonly type: "
|
|
94
|
-
readonly
|
|
95
|
-
|
|
94
|
+
readonly content: string | readonly {
|
|
95
|
+
readonly type: "text";
|
|
96
|
+
readonly text: string;
|
|
97
|
+
readonly cache_control?: {
|
|
98
|
+
readonly type: "ephemeral";
|
|
99
|
+
readonly ttl?: string | undefined;
|
|
100
|
+
} | undefined;
|
|
101
|
+
}[];
|
|
96
102
|
})[];
|
|
97
103
|
readonly stream: true;
|
|
98
104
|
readonly max_completion_tokens?: number | undefined;
|
|
@@ -178,15 +184,18 @@ export declare const routes: Route<{
|
|
|
178
184
|
})[];
|
|
179
185
|
} | {
|
|
180
186
|
readonly [x: string]: unknown;
|
|
181
|
-
readonly content: string |
|
|
187
|
+
readonly content: string | readonly {
|
|
188
|
+
readonly type: "text";
|
|
189
|
+
readonly text: string;
|
|
190
|
+
readonly cache_control?: {
|
|
191
|
+
readonly type: "ephemeral";
|
|
192
|
+
readonly ttl?: string | undefined;
|
|
193
|
+
} | undefined;
|
|
194
|
+
}[] | null;
|
|
182
195
|
readonly role: "assistant";
|
|
183
196
|
readonly reasoning?: string | undefined;
|
|
184
197
|
readonly reasoning_content?: string | undefined;
|
|
185
198
|
readonly reasoning_text?: string | undefined;
|
|
186
|
-
readonly cache_control?: {
|
|
187
|
-
readonly type: "ephemeral";
|
|
188
|
-
readonly ttl?: string | undefined;
|
|
189
|
-
} | undefined;
|
|
190
199
|
readonly tool_calls?: readonly {
|
|
191
200
|
readonly function: {
|
|
192
201
|
readonly name: string;
|
|
@@ -202,13 +211,16 @@ export declare const routes: Route<{
|
|
|
202
211
|
}[] | undefined;
|
|
203
212
|
readonly reasoning_details?: unknown;
|
|
204
213
|
} | {
|
|
205
|
-
readonly content: string;
|
|
206
214
|
readonly role: "tool";
|
|
207
215
|
readonly tool_call_id: string;
|
|
208
|
-
readonly
|
|
209
|
-
readonly type: "
|
|
210
|
-
readonly
|
|
211
|
-
|
|
216
|
+
readonly content: string | readonly {
|
|
217
|
+
readonly type: "text";
|
|
218
|
+
readonly text: string;
|
|
219
|
+
readonly cache_control?: {
|
|
220
|
+
readonly type: "ephemeral";
|
|
221
|
+
readonly ttl?: string | undefined;
|
|
222
|
+
} | undefined;
|
|
223
|
+
}[];
|
|
212
224
|
})[];
|
|
213
225
|
readonly stream: true;
|
|
214
226
|
readonly max_completion_tokens?: number | undefined;
|