@opencode/ai 2.2.4 → 2.2.6
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/README.md +133 -69
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +20 -125
- package/dist/decision.js +25 -15
- package/dist/effect.d.ts +4 -15
- package/dist/effect.js +2 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -464
- package/dist/image.js +17 -15
- package/dist/index.d.ts +28 -465
- package/dist/index.js +18 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +5 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +57 -185
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +11 -22
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +56 -89
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +54 -32
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +14 -20
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/open-responses.js +10 -15
- package/dist/protocols/openai-chat.d.ts +3 -23
- package/dist/protocols/openai-chat.js +26 -47
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +1 -4
- package/dist/protocols/shared.js +13 -11
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +3 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +5 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +9 -80
- package/dist/providers/alibaba.d.ts +67 -4
- package/dist/providers/alibaba.js +6 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +322 -7
- package/dist/providers/azure.js +25 -9
- package/dist/providers/baseten.d.ts +5 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +5 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere.d.ts +6 -5
- package/dist/providers/cohere.js +7 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra.d.ts +5 -5
- package/dist/providers/deepinfra.js +5 -13
- package/dist/providers/deepseek.d.ts +5 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean.d.ts +8 -5
- package/dist/providers/digitalocean.js +13 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks.d.ts +5 -5
- package/dist/providers/fireworks.js +4 -15
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex-chat.d.ts +3 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +3 -3
- package/dist/providers/google.d.ts +15 -13
- package/dist/providers/google.js +9 -19
- package/dist/providers/groq.d.ts +5 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +5 -5
- package/dist/providers/meta.js +10 -24
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +5 -5
- package/dist/providers/minimax.js +11 -23
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +5 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +6 -7
- package/dist/providers/openai-compatible.js +4 -10
- package/dist/providers/openai.d.ts +4 -4
- package/dist/providers/openai.js +3 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter.d.ts +8 -5
- package/dist/providers/openrouter.js +16 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +5 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +4 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway.d.ts +5 -5
- package/dist/providers/vercel-ai-gateway.js +15 -28
- package/dist/providers/xai.d.ts +4 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +5 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +5 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +12 -0
- package/dist/public.js +5 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +9 -9
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
|
@@ -70,238 +70,12 @@ export declare const appendExisting: <K extends StreamKey>(route: string, tools:
|
|
|
70
70
|
* from state, and reject malformed local arguments without repairing them.
|
|
71
71
|
* Missing keys are a no-op because some providers emit stop events for
|
|
72
72
|
* non-tool content blocks.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
tools: Partial<Record<K, PendingTool>>;
|
|
76
|
-
events?: undefined;
|
|
77
|
-
} | {
|
|
78
|
-
tools: Partial<Record<K, PendingTool>>;
|
|
79
|
-
events: readonly ({
|
|
80
|
-
readonly type: "step-start";
|
|
81
|
-
readonly index: number;
|
|
82
|
-
} | {
|
|
83
|
-
readonly type: "raw";
|
|
84
|
-
readonly data: unknown;
|
|
85
|
-
} | {
|
|
86
|
-
readonly type: "text-start";
|
|
87
|
-
readonly id: string;
|
|
88
|
-
readonly providerMetadata?: {
|
|
89
|
-
readonly [x: string]: {
|
|
90
|
-
readonly [x: string]: unknown;
|
|
91
|
-
};
|
|
92
|
-
} | undefined;
|
|
93
|
-
} | {
|
|
94
|
-
readonly type: "text-delta";
|
|
95
|
-
readonly id: string;
|
|
96
|
-
readonly text: string;
|
|
97
|
-
readonly providerMetadata?: {
|
|
98
|
-
readonly [x: string]: {
|
|
99
|
-
readonly [x: string]: unknown;
|
|
100
|
-
};
|
|
101
|
-
} | undefined;
|
|
102
|
-
} | {
|
|
103
|
-
readonly type: "text-end";
|
|
104
|
-
readonly id: string;
|
|
105
|
-
readonly text?: string | undefined;
|
|
106
|
-
readonly providerMetadata?: {
|
|
107
|
-
readonly [x: string]: {
|
|
108
|
-
readonly [x: string]: unknown;
|
|
109
|
-
};
|
|
110
|
-
} | undefined;
|
|
111
|
-
} | {
|
|
112
|
-
readonly type: "reasoning-start";
|
|
113
|
-
readonly id: string;
|
|
114
|
-
readonly providerMetadata?: {
|
|
115
|
-
readonly [x: string]: {
|
|
116
|
-
readonly [x: string]: unknown;
|
|
117
|
-
};
|
|
118
|
-
} | undefined;
|
|
119
|
-
} | {
|
|
120
|
-
readonly type: "reasoning-delta";
|
|
121
|
-
readonly id: string;
|
|
122
|
-
readonly text: string;
|
|
123
|
-
readonly providerMetadata?: {
|
|
124
|
-
readonly [x: string]: {
|
|
125
|
-
readonly [x: string]: unknown;
|
|
126
|
-
};
|
|
127
|
-
} | undefined;
|
|
128
|
-
} | {
|
|
129
|
-
readonly type: "reasoning-end";
|
|
130
|
-
readonly id: string;
|
|
131
|
-
readonly text?: string | undefined;
|
|
132
|
-
readonly providerMetadata?: {
|
|
133
|
-
readonly [x: string]: {
|
|
134
|
-
readonly [x: string]: unknown;
|
|
135
|
-
};
|
|
136
|
-
} | undefined;
|
|
137
|
-
} | {
|
|
138
|
-
readonly type: "tool-input-start";
|
|
139
|
-
readonly id: string;
|
|
140
|
-
readonly name: string;
|
|
141
|
-
readonly namespace?: string | undefined;
|
|
142
|
-
readonly providerExecuted?: boolean | undefined;
|
|
143
|
-
readonly providerMetadata?: {
|
|
144
|
-
readonly [x: string]: {
|
|
145
|
-
readonly [x: string]: unknown;
|
|
146
|
-
};
|
|
147
|
-
} | undefined;
|
|
148
|
-
} | {
|
|
149
|
-
readonly type: "tool-input-delta";
|
|
150
|
-
readonly id: string;
|
|
151
|
-
readonly name: string;
|
|
152
|
-
readonly namespace?: string | undefined;
|
|
153
|
-
readonly text: string;
|
|
154
|
-
readonly input?: unknown;
|
|
155
|
-
} | {
|
|
156
|
-
readonly type: "tool-input-end";
|
|
157
|
-
readonly id: string;
|
|
158
|
-
readonly name: string;
|
|
159
|
-
readonly namespace?: string | undefined;
|
|
160
|
-
readonly providerMetadata?: {
|
|
161
|
-
readonly [x: string]: {
|
|
162
|
-
readonly [x: string]: unknown;
|
|
163
|
-
};
|
|
164
|
-
} | undefined;
|
|
165
|
-
} | {
|
|
166
|
-
readonly type: "tool-input-error";
|
|
167
|
-
readonly id: string;
|
|
168
|
-
readonly name: string;
|
|
169
|
-
readonly namespace?: string | undefined;
|
|
170
|
-
readonly raw: string;
|
|
171
|
-
} | {
|
|
172
|
-
readonly type: "tool-call";
|
|
173
|
-
readonly id: string;
|
|
174
|
-
readonly name: string;
|
|
175
|
-
readonly namespace?: string | undefined;
|
|
176
|
-
readonly input: unknown;
|
|
177
|
-
readonly providerExecuted?: boolean | undefined;
|
|
178
|
-
readonly providerMetadata?: {
|
|
179
|
-
readonly [x: string]: {
|
|
180
|
-
readonly [x: string]: unknown;
|
|
181
|
-
};
|
|
182
|
-
} | undefined;
|
|
183
|
-
} | {
|
|
184
|
-
readonly type: "tool-result";
|
|
185
|
-
readonly id: string;
|
|
186
|
-
readonly name: string;
|
|
187
|
-
readonly namespace?: string | undefined;
|
|
188
|
-
readonly result: {
|
|
189
|
-
readonly type: "json";
|
|
190
|
-
readonly value: unknown;
|
|
191
|
-
} | {
|
|
192
|
-
readonly type: "text";
|
|
193
|
-
readonly value: unknown;
|
|
194
|
-
} | {
|
|
195
|
-
readonly type: "error";
|
|
196
|
-
readonly value: unknown;
|
|
197
|
-
} | {
|
|
198
|
-
readonly type: "content";
|
|
199
|
-
readonly value: readonly ({
|
|
200
|
-
readonly type: "text";
|
|
201
|
-
readonly text: string;
|
|
202
|
-
} | {
|
|
203
|
-
readonly type: "file";
|
|
204
|
-
readonly uri: string;
|
|
205
|
-
readonly mime: string;
|
|
206
|
-
readonly name?: string | undefined;
|
|
207
|
-
})[];
|
|
208
|
-
};
|
|
209
|
-
readonly output?: {
|
|
210
|
-
readonly structured: unknown;
|
|
211
|
-
readonly content: readonly ({
|
|
212
|
-
readonly type: "text";
|
|
213
|
-
readonly text: string;
|
|
214
|
-
} | {
|
|
215
|
-
readonly type: "file";
|
|
216
|
-
readonly uri: string;
|
|
217
|
-
readonly mime: string;
|
|
218
|
-
readonly name?: string | undefined;
|
|
219
|
-
})[];
|
|
220
|
-
} | undefined;
|
|
221
|
-
readonly providerExecuted?: boolean | undefined;
|
|
222
|
-
readonly providerMetadata?: {
|
|
223
|
-
readonly [x: string]: {
|
|
224
|
-
readonly [x: string]: unknown;
|
|
225
|
-
};
|
|
226
|
-
} | undefined;
|
|
227
|
-
} | {
|
|
228
|
-
readonly type: "tool-error";
|
|
229
|
-
readonly id: string;
|
|
230
|
-
readonly name: string;
|
|
231
|
-
readonly namespace?: string | undefined;
|
|
232
|
-
readonly message: string;
|
|
233
|
-
readonly error?: unknown;
|
|
234
|
-
readonly providerMetadata?: {
|
|
235
|
-
readonly [x: string]: {
|
|
236
|
-
readonly [x: string]: unknown;
|
|
237
|
-
};
|
|
238
|
-
} | undefined;
|
|
239
|
-
} | {
|
|
240
|
-
readonly type: "step-finish";
|
|
241
|
-
readonly index: number;
|
|
242
|
-
readonly reason: {
|
|
243
|
-
readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
|
|
244
|
-
readonly raw?: string | undefined;
|
|
245
|
-
readonly category?: string | undefined;
|
|
246
|
-
readonly explanation?: string | undefined;
|
|
247
|
-
};
|
|
248
|
-
readonly usage?: import("../../schema/events.js").Usage | undefined;
|
|
249
|
-
readonly providerMetadata?: {
|
|
250
|
-
readonly [x: string]: {
|
|
251
|
-
readonly [x: string]: unknown;
|
|
252
|
-
};
|
|
253
|
-
} | undefined;
|
|
254
|
-
} | {
|
|
255
|
-
readonly type: "finish";
|
|
256
|
-
readonly reason: {
|
|
257
|
-
readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
|
|
258
|
-
readonly raw?: string | undefined;
|
|
259
|
-
readonly category?: string | undefined;
|
|
260
|
-
readonly explanation?: string | undefined;
|
|
261
|
-
};
|
|
262
|
-
readonly usage?: import("../../schema/events.js").Usage | undefined;
|
|
263
|
-
readonly providerMetadata?: {
|
|
264
|
-
readonly [x: string]: {
|
|
265
|
-
readonly [x: string]: unknown;
|
|
266
|
-
};
|
|
267
|
-
} | undefined;
|
|
268
|
-
} | {
|
|
269
|
-
readonly type: "media";
|
|
270
|
-
readonly media: import("../../media.js").Asset;
|
|
271
|
-
readonly providerMetadata?: {
|
|
272
|
-
readonly [x: string]: {
|
|
273
|
-
readonly [x: string]: unknown;
|
|
274
|
-
};
|
|
275
|
-
} | undefined;
|
|
276
|
-
} | {
|
|
277
|
-
readonly type: "provider-error";
|
|
278
|
-
readonly message: string;
|
|
279
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
280
|
-
readonly providerMetadata?: {
|
|
281
|
-
readonly [x: string]: {
|
|
282
|
-
readonly [x: string]: unknown;
|
|
283
|
-
};
|
|
284
|
-
} | undefined;
|
|
285
|
-
} | ({
|
|
286
|
-
readonly type: "compaction";
|
|
287
|
-
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
288
|
-
readonly id?: string | undefined;
|
|
289
|
-
readonly encrypted?: string | undefined;
|
|
290
|
-
readonly text?: string | null | undefined;
|
|
291
|
-
} & ({
|
|
292
|
-
readonly encrypted: string;
|
|
293
|
-
readonly text?: never;
|
|
294
|
-
} | {
|
|
295
|
-
readonly text: string | null;
|
|
296
|
-
readonly encrypted?: never;
|
|
297
|
-
})))[];
|
|
298
|
-
}, AIError, never>;
|
|
299
|
-
/**
|
|
300
|
-
* Finalize one pending tool call with an authoritative final input string.
|
|
73
|
+
*
|
|
74
|
+
* Pass `input` when the provider sends an authoritative final input string.
|
|
301
75
|
* OpenAI Responses can send accumulated deltas and then repeat the completed
|
|
302
76
|
* arguments on `response.output_item.done`; the final value wins.
|
|
303
77
|
*/
|
|
304
|
-
export declare const
|
|
78
|
+
export declare const finish: <K extends StreamKey>(route: string, tools: State<K>, key: K, input?: string) => Effect.Effect<{
|
|
305
79
|
tools: Partial<Record<K, PendingTool>>;
|
|
306
80
|
events?: undefined;
|
|
307
81
|
} | {
|
|
@@ -454,18 +228,6 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
|
|
|
454
228
|
readonly [x: string]: unknown;
|
|
455
229
|
};
|
|
456
230
|
} | undefined;
|
|
457
|
-
} | {
|
|
458
|
-
readonly type: "tool-error";
|
|
459
|
-
readonly id: string;
|
|
460
|
-
readonly name: string;
|
|
461
|
-
readonly namespace?: string | undefined;
|
|
462
|
-
readonly message: string;
|
|
463
|
-
readonly error?: unknown;
|
|
464
|
-
readonly providerMetadata?: {
|
|
465
|
-
readonly [x: string]: {
|
|
466
|
-
readonly [x: string]: unknown;
|
|
467
|
-
};
|
|
468
|
-
} | undefined;
|
|
469
231
|
} | {
|
|
470
232
|
readonly type: "step-finish";
|
|
471
233
|
readonly index: number;
|
|
@@ -490,6 +252,7 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
|
|
|
490
252
|
readonly explanation?: string | undefined;
|
|
491
253
|
};
|
|
492
254
|
readonly usage?: import("../../schema/events.js").Usage | undefined;
|
|
255
|
+
readonly message?: import("../../schema/messages.js").AssistantMessage | undefined;
|
|
493
256
|
readonly providerMetadata?: {
|
|
494
257
|
readonly [x: string]: {
|
|
495
258
|
readonly [x: string]: unknown;
|
|
@@ -503,15 +266,6 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
|
|
|
503
266
|
readonly [x: string]: unknown;
|
|
504
267
|
};
|
|
505
268
|
} | undefined;
|
|
506
|
-
} | {
|
|
507
|
-
readonly type: "provider-error";
|
|
508
|
-
readonly message: string;
|
|
509
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
510
|
-
readonly providerMetadata?: {
|
|
511
|
-
readonly [x: string]: {
|
|
512
|
-
readonly [x: string]: unknown;
|
|
513
|
-
};
|
|
514
|
-
} | undefined;
|
|
515
269
|
} | ({
|
|
516
270
|
readonly type: "compaction";
|
|
517
271
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -681,18 +435,6 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
|
|
|
681
435
|
readonly [x: string]: unknown;
|
|
682
436
|
};
|
|
683
437
|
} | undefined;
|
|
684
|
-
} | {
|
|
685
|
-
readonly type: "tool-error";
|
|
686
|
-
readonly id: string;
|
|
687
|
-
readonly name: string;
|
|
688
|
-
readonly namespace?: string | undefined;
|
|
689
|
-
readonly message: string;
|
|
690
|
-
readonly error?: unknown;
|
|
691
|
-
readonly providerMetadata?: {
|
|
692
|
-
readonly [x: string]: {
|
|
693
|
-
readonly [x: string]: unknown;
|
|
694
|
-
};
|
|
695
|
-
} | undefined;
|
|
696
438
|
} | {
|
|
697
439
|
readonly type: "step-finish";
|
|
698
440
|
readonly index: number;
|
|
@@ -717,6 +459,7 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
|
|
|
717
459
|
readonly explanation?: string | undefined;
|
|
718
460
|
};
|
|
719
461
|
readonly usage?: import("../../schema/events.js").Usage | undefined;
|
|
462
|
+
readonly message?: import("../../schema/messages.js").AssistantMessage | undefined;
|
|
720
463
|
readonly providerMetadata?: {
|
|
721
464
|
readonly [x: string]: {
|
|
722
465
|
readonly [x: string]: unknown;
|
|
@@ -730,15 +473,6 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
|
|
|
730
473
|
readonly [x: string]: unknown;
|
|
731
474
|
};
|
|
732
475
|
} | undefined;
|
|
733
|
-
} | {
|
|
734
|
-
readonly type: "provider-error";
|
|
735
|
-
readonly message: string;
|
|
736
|
-
readonly classification?: "context-overflow" | "payload-too-large" | undefined;
|
|
737
|
-
readonly providerMetadata?: {
|
|
738
|
-
readonly [x: string]: {
|
|
739
|
-
readonly [x: string]: unknown;
|
|
740
|
-
};
|
|
741
|
-
} | undefined;
|
|
742
476
|
} | ({
|
|
743
477
|
readonly type: "compaction";
|
|
744
478
|
readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
@@ -124,22 +124,12 @@ export const appendExisting = (route, tools, key, text, missingToolMessage) => a
|
|
|
124
124
|
* from state, and reject malformed local arguments without repairing them.
|
|
125
125
|
* Missing keys are a no-op because some providers emit stop events for
|
|
126
126
|
* non-tool content blocks.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const tool = tools[key];
|
|
130
|
-
if (!tool)
|
|
131
|
-
return { tools };
|
|
132
|
-
return {
|
|
133
|
-
tools: withoutTool(tools, key),
|
|
134
|
-
events: finishEvents(tool, yield* toolCall(route, tool)),
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
/**
|
|
138
|
-
* Finalize one pending tool call with an authoritative final input string.
|
|
127
|
+
*
|
|
128
|
+
* Pass `input` when the provider sends an authoritative final input string.
|
|
139
129
|
* OpenAI Responses can send accumulated deltas and then repeat the completed
|
|
140
130
|
* arguments on `response.output_item.done`; the final value wins.
|
|
141
131
|
*/
|
|
142
|
-
export const
|
|
132
|
+
export const finish = (route, tools, key, input) => Effect.gen(function* () {
|
|
143
133
|
const tool = tools[key];
|
|
144
134
|
if (!tool)
|
|
145
135
|
return { tools };
|
|
@@ -48,7 +48,9 @@ interface State {
|
|
|
48
48
|
}
|
|
49
49
|
export declare const compatibility: {
|
|
50
50
|
maxTokensField: "max_completion_tokens";
|
|
51
|
-
|
|
51
|
+
};
|
|
52
|
+
export declare const capabilities: {
|
|
53
|
+
promptCacheKey: true;
|
|
52
54
|
};
|
|
53
55
|
export declare const protocol: Protocol<{
|
|
54
56
|
readonly model: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { Protocol } from "../route/protocol.js";
|
|
3
|
-
import { AIError, LLMEvent } from "../schema/index.js";
|
|
3
|
+
import { AIError, LLMEvent, } from "../schema/index.js";
|
|
4
4
|
import { classifyProviderFailure } from "../provider-error.js";
|
|
5
5
|
import { OpenAIChat } from "./openai-chat.js";
|
|
6
6
|
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
@@ -138,7 +138,7 @@ const fromRequest = Effect.fn("VeniceChat.fromRequest")(function* (request) {
|
|
|
138
138
|
});
|
|
139
139
|
return {
|
|
140
140
|
...body,
|
|
141
|
-
max_completion_tokens: options.maxCompletionTokens ?? options.maxTokens ?? request.
|
|
141
|
+
max_completion_tokens: options.maxCompletionTokens ?? options.maxTokens ?? request.maxTokens,
|
|
142
142
|
reasoning_effort: undefined,
|
|
143
143
|
reasoning: options.reasoningEffort === undefined
|
|
144
144
|
? options.reasoning
|
|
@@ -153,7 +153,7 @@ const fromRequest = Effect.fn("VeniceChat.fromRequest")(function* (request) {
|
|
|
153
153
|
prompt_cache_retention: options.promptCacheRetention ?? body.prompt_cache_retention,
|
|
154
154
|
parallel_tool_calls: options.parallelToolCalls,
|
|
155
155
|
min_p: options.minP,
|
|
156
|
-
top_k: request.
|
|
156
|
+
top_k: request.topK,
|
|
157
157
|
repetition_penalty: options.repetitionPenalty,
|
|
158
158
|
stop_token_ids: options.stopTokenIds,
|
|
159
159
|
logprobs: options.logprobs,
|
|
@@ -261,8 +261,8 @@ const onHalt = Effect.fn("VeniceChat.onHalt")(function* (state) {
|
|
|
261
261
|
});
|
|
262
262
|
export const compatibility = {
|
|
263
263
|
maxTokensField: "max_completion_tokens",
|
|
264
|
-
supportsPromptCacheKey: true,
|
|
265
264
|
};
|
|
265
|
+
export const capabilities = { promptCacheKey: true };
|
|
266
266
|
export const protocol = Protocol.make({
|
|
267
267
|
id: "venice-chat",
|
|
268
268
|
body: { schema: Body, from: fromRequest },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
@@ -11,7 +11,7 @@ export type XAIImageOptions = {
|
|
|
11
11
|
readonly responseFormat?: OpenString<"url" | "b64_json">;
|
|
12
12
|
readonly response_format?: OpenString<"url" | "b64_json">;
|
|
13
13
|
} & Record<string, unknown>;
|
|
14
|
-
export type Request =
|
|
14
|
+
export type Request = ImageRequest<ImageModel<XAIImageOptions>>;
|
|
15
15
|
/** xAI renders `1k` or `2k`; other tiers use the nearest one. */
|
|
16
16
|
export declare const resolution: (request: {
|
|
17
17
|
readonly resolution?: string;
|
|
@@ -59,31 +59,16 @@ const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request) {
|
|
|
59
59
|
...body,
|
|
60
60
|
presence_penalty: undefined,
|
|
61
61
|
frequency_penalty: undefined,
|
|
62
|
-
top_k: request.
|
|
62
|
+
top_k: request.topK,
|
|
63
63
|
min_p: options.minP,
|
|
64
64
|
};
|
|
65
65
|
});
|
|
66
|
+
// Grok speaks the standard Responses reasoning dialect (`reasoning_summary_text.*`,
|
|
67
|
+
// handled by the baseline); only its hosted tool vocabulary differs.
|
|
66
68
|
const HOSTED_TOOLS = {
|
|
67
|
-
|
|
69
|
+
...ResponsesHostedTools.common,
|
|
68
70
|
x_search_call: { name: "x_search", input: (item) => item.action ?? {} },
|
|
69
|
-
file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
|
|
70
|
-
code_interpreter_call: {
|
|
71
|
-
name: "code_interpreter",
|
|
72
|
-
input: (item) => ({ code: item.code, container_id: item.container_id }),
|
|
73
|
-
},
|
|
74
71
|
image_generation_call: { name: "image_generation", input: () => ({}) },
|
|
75
|
-
mcp_call: {
|
|
76
|
-
name: "mcp",
|
|
77
|
-
input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
// Grok speaks the standard Responses reasoning dialect (`reasoning_summary_text.*`,
|
|
81
|
-
// handled by the baseline); only its hosted tool vocabulary differs.
|
|
82
|
-
const step = (state, input) => {
|
|
83
|
-
const event = OpenResponses.normalize(state, input);
|
|
84
|
-
if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS))
|
|
85
|
-
return ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS);
|
|
86
|
-
return OpenResponses.step(state, event);
|
|
87
72
|
};
|
|
88
73
|
export const protocol = Protocol.make({
|
|
89
74
|
id: ADAPTER,
|
|
@@ -91,12 +76,7 @@ export const protocol = Protocol.make({
|
|
|
91
76
|
schema: Body,
|
|
92
77
|
from: fromRequest,
|
|
93
78
|
},
|
|
94
|
-
stream:
|
|
95
|
-
event: OpenResponses.protocol.stream.event,
|
|
96
|
-
initial: (request) => OpenResponses.initial(request, adapter),
|
|
97
|
-
step,
|
|
98
|
-
terminal: OpenResponses.terminal,
|
|
99
|
-
},
|
|
79
|
+
stream: ResponsesHostedTools.stream(adapter, HOSTED_TOOLS),
|
|
100
80
|
});
|
|
101
81
|
export const compact = ResponsesCompaction.make(adapter, (request) => OpenResponses.lowerTools(ProviderShared.flattenTools(request.tools), adapter, OpenAIFreeform.tools(request)));
|
|
102
82
|
export * as XAIResponses from "./xai-responses.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
|
-
import { VideoModel, VideoResponse, type
|
|
4
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
5
5
|
export declare const DEFAULT_BASE_URL = "https://api.x.ai/v1";
|
|
6
6
|
export declare const PATH = "/videos/generations";
|
|
7
7
|
export declare const EDIT_PATH = "/videos/edits";
|
|
@@ -17,7 +17,7 @@ export type XAIVideoOptions = {
|
|
|
17
17
|
readonly voice_id: string;
|
|
18
18
|
}>;
|
|
19
19
|
} & Record<string, unknown>;
|
|
20
|
-
export type Request =
|
|
20
|
+
export type Request = VideoRequest<VideoModel<XAIVideoOptions>>;
|
|
21
21
|
export declare const Token: Schema.Struct<{
|
|
22
22
|
readonly requestID: Schema.String;
|
|
23
23
|
}>;
|
|
@@ -21,10 +21,14 @@ declare const Options: Schema.Struct<{
|
|
|
21
21
|
export type OptionsInput = typeof Options.Type;
|
|
22
22
|
export declare const compatibility: {
|
|
23
23
|
maxTokensField: "max_tokens";
|
|
24
|
-
supportsStrictMode: false;
|
|
25
24
|
reasoningField: string;
|
|
26
25
|
zaiToolStream: false;
|
|
27
26
|
};
|
|
27
|
+
export declare const capabilities: {
|
|
28
|
+
tools: {
|
|
29
|
+
strict: false;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
28
32
|
export declare const protocol: Protocol<{
|
|
29
33
|
readonly model: string;
|
|
30
34
|
readonly messages: readonly ({
|
|
@@ -44,10 +44,10 @@ const fromRequest = Effect.fn("ZAIChat.fromRequest")(function* (request) {
|
|
|
44
44
|
});
|
|
45
45
|
export const compatibility = {
|
|
46
46
|
maxTokensField: "max_tokens",
|
|
47
|
-
supportsStrictMode: false,
|
|
48
47
|
reasoningField: "reasoning_content",
|
|
49
48
|
zaiToolStream: false,
|
|
50
49
|
};
|
|
50
|
+
export const capabilities = { tools: { strict: false } };
|
|
51
51
|
export const protocol = Protocol.make({
|
|
52
52
|
id: "zai-chat",
|
|
53
53
|
body: { schema: Body, from: fromRequest },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImageModel, ImageResponse, type
|
|
1
|
+
import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
import { type OpenString } from "../schema/index.js";
|
|
@@ -11,7 +11,7 @@ export type ZAIImageOptions = {
|
|
|
11
11
|
readonly quality?: OpenString<"hd" | "standard">;
|
|
12
12
|
readonly userID?: string;
|
|
13
13
|
} & Record<string, unknown>;
|
|
14
|
-
export type Request =
|
|
14
|
+
export type Request = ImageRequest<ImageModel<ZAIImageOptions>>;
|
|
15
15
|
export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
|
|
16
16
|
export declare const model: (input: MediaRoute.ModelInput) => ImageModel<ZAIImageOptions>;
|
|
17
17
|
export declare const ZAIImages: {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { Protocol } from "../route/protocol.js";
|
|
3
|
-
import { LLMRequest } from "../schema/index.js";
|
|
4
3
|
import { AnthropicMessages } from "./anthropic-messages.js";
|
|
5
4
|
import { ProviderShared } from "./shared.js";
|
|
6
5
|
import { OpenResponsesOptions } from "./utils/open-responses-options.js";
|
|
@@ -15,9 +14,10 @@ const Body = Schema.Struct({
|
|
|
15
14
|
const fromRequest = Effect.fn("ZAIMessages.fromRequest")(function* (request) {
|
|
16
15
|
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
|
|
17
16
|
// Z.AI accepts enabled thinking without Anthropic's mandatory token budget.
|
|
18
|
-
const body = yield* AnthropicMessages.protocol.body.from(
|
|
17
|
+
const body = yield* AnthropicMessages.protocol.body.from({
|
|
18
|
+
...request,
|
|
19
19
|
providerOptions: { ...request.providerOptions, thinking: undefined },
|
|
20
|
-
})
|
|
20
|
+
});
|
|
21
21
|
return { ...body, thinking: options.thinking };
|
|
22
22
|
});
|
|
23
23
|
export const protocol = Protocol.make({
|
package/dist/provider-error.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AIError, type HttpContext, type HttpRateLimitDetails } from "./schema/index.js";
|
|
2
2
|
export declare const isContextOverflow: (message: string) => boolean;
|
|
3
|
-
export declare const isPayloadTooLarge: (message: string) => boolean;
|
|
4
3
|
export declare const isContextOverflowFailure: (failure: unknown) => boolean;
|
|
5
4
|
/**
|
|
6
5
|
* Whether a failed call may succeed when sent again: rate limits, provider-side failures, transport failures that did
|
package/dist/provider-error.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Option, Schema, SchemaGetter } from "effect";
|
|
2
|
-
import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError,
|
|
3
|
-
import {
|
|
4
|
-
import { isRecord } from "./utils/record.js";
|
|
2
|
+
import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError, ProviderInternalError, QuotaExceededError, RateLimitError, UnknownProviderError, } from "./schema/index.js";
|
|
3
|
+
import { awsErrorType, providerCodes } from "./utils/provider-codes.js";
|
|
5
4
|
const patterns = [
|
|
6
5
|
/prompt is too long/i,
|
|
7
6
|
/input is too long for (?:the )?(?:requested|selected) model/i,
|
|
@@ -29,6 +28,8 @@ const patterns = [
|
|
|
29
28
|
// Hugging Face Text Generation Inference, e.g. Together
|
|
30
29
|
/`inputs` tokens \+ `max_new_tokens` must be <= \d+/i,
|
|
31
30
|
/context window exceeds limit/i,
|
|
31
|
+
// LiteLLM's ContextWindowExceededError
|
|
32
|
+
/context window exceeded/i,
|
|
32
33
|
/exceeded model token limit/i,
|
|
33
34
|
/context[_ ]length[_ ]exceeded/i,
|
|
34
35
|
/context length is only \d+ tokens/i,
|
|
@@ -55,51 +56,15 @@ const exclusions = [
|
|
|
55
56
|
];
|
|
56
57
|
export const isContextOverflow = (message) => !exclusions.some((pattern) => pattern.test(message)) &&
|
|
57
58
|
(patterns.some((pattern) => pattern.test(message)) || /^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(message));
|
|
58
|
-
|
|
59
|
-
export const isContextOverflowFailure = (failure) => failure instanceof AIError
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const isPayloadTooLarge = (message) => payloadPatterns.some((pattern) => pattern.test(message));
|
|
60
|
+
export const isContextOverflowFailure = (failure) => failure instanceof AIError &&
|
|
61
|
+
failure.reason._tag === "InvalidRequest" &&
|
|
62
|
+
failure.reason.classification === "context-overflow";
|
|
62
63
|
/**
|
|
63
64
|
* Whether a failed call may succeed when sent again: rate limits, provider-side failures, transport failures that did
|
|
64
65
|
* not deliver an accepted write, and unrecognized failures. Callers decide which calls are safe to repeat.
|
|
65
66
|
*/
|
|
66
|
-
export const isRetryable = (error) =>
|
|
67
|
-
const override = error.reason.http?.headers["x-should-retry"];
|
|
68
|
-
if (override === "true")
|
|
69
|
-
return true;
|
|
70
|
-
if (override === "false")
|
|
71
|
-
return false;
|
|
72
|
-
switch (error.reason._tag) {
|
|
73
|
-
case "RateLimit":
|
|
74
|
-
case "ProviderInternal":
|
|
75
|
-
return true;
|
|
76
|
-
// A WebSocket acknowledgment marks delivery accepted before model output may exist.
|
|
77
|
-
// Read failures can still recover; the caller chooses retry versus continuation from durable output.
|
|
78
|
-
case "Transport":
|
|
79
|
-
return (error.reason.delivery !== "rejected" &&
|
|
80
|
-
(error.reason.delivery !== "accepted" || error.reason.operation === "read"));
|
|
81
|
-
case "InvalidProviderOutput":
|
|
82
|
-
return error.reason.classification === "incomplete-stream";
|
|
83
|
-
// Unrecognized failures retry: classification records affirmative
|
|
84
|
-
// deterministic evidence, and transient failures are exactly the ones
|
|
85
|
-
// that arrive in shapes no classifier anticipates.
|
|
86
|
-
case "UnknownProvider":
|
|
87
|
-
return true;
|
|
88
|
-
case "Authentication":
|
|
89
|
-
case "QuotaExceeded":
|
|
90
|
-
case "ContentPolicy":
|
|
91
|
-
case "InvalidRequest":
|
|
92
|
-
case "UnsupportedOperation":
|
|
93
|
-
case "NoRoute":
|
|
94
|
-
case "Timeout":
|
|
95
|
-
return false;
|
|
96
|
-
default: {
|
|
97
|
-
const exhaustive = error.reason;
|
|
98
|
-
return exhaustive;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
const decodeJson = Schema.decodeUnknownOption(Json);
|
|
67
|
+
export const isRetryable = (error) => error.isRetryable;
|
|
103
68
|
// OpenCode Zen reports account caps as typed 429/402 errors that are not throttles.
|
|
104
69
|
const QUOTA_CODES = new Set([
|
|
105
70
|
"insufficient_quota",
|
|
@@ -249,39 +214,3 @@ export function classifyProviderFailure(input) {
|
|
|
249
214
|
return new InvalidRequestError(details);
|
|
250
215
|
return new UnknownProviderError(details);
|
|
251
216
|
}
|
|
252
|
-
function providerCodes(value) {
|
|
253
|
-
const decoded = typeof value === "string" ? Option.getOrUndefined(decodeJson(value)) : value;
|
|
254
|
-
if (!isRecord(decoded))
|
|
255
|
-
return [];
|
|
256
|
-
const error = isRecord(decoded.error) ? decoded.error : undefined;
|
|
257
|
-
const inner = error && isRecord(error.innererror) ? error.innererror : undefined;
|
|
258
|
-
const metadata = error && isRecord(error.metadata) ? error.metadata : undefined;
|
|
259
|
-
const response = isRecord(decoded.response) ? decoded.response : undefined;
|
|
260
|
-
const responseError = response && isRecord(response.error) ? response.error : undefined;
|
|
261
|
-
const exception = isRecord(decoded.exception) ? decoded.exception : undefined;
|
|
262
|
-
return [
|
|
263
|
-
decoded.code,
|
|
264
|
-
...awsErrorType(decoded.__type),
|
|
265
|
-
...awsErrorType(decoded.code),
|
|
266
|
-
decoded.error_type,
|
|
267
|
-
error?.code,
|
|
268
|
-
error?.type,
|
|
269
|
-
error?.status,
|
|
270
|
-
error?.error_type,
|
|
271
|
-
// Google `google.rpc.ErrorInfo` details carry the specific reason.
|
|
272
|
-
...(Array.isArray(error?.details)
|
|
273
|
-
? error.details.map((detail) => (isRecord(detail) ? detail.reason : undefined))
|
|
274
|
-
: []),
|
|
275
|
-
inner?.code,
|
|
276
|
-
metadata?.error_type,
|
|
277
|
-
responseError?.code,
|
|
278
|
-
response?.error_type,
|
|
279
|
-
exception?.type,
|
|
280
|
-
].filter((value) => typeof value === "string");
|
|
281
|
-
}
|
|
282
|
-
// AWS restJson1 reports the modeled error in `X-Amzn-Errortype`, `__type` or `code`, possibly
|
|
283
|
-
// namespaced (`ns#Name`) or suffixed (`Name:uri`). Keep the shape name only.
|
|
284
|
-
// https://smithy.io/2.0/aws/protocols/aws-restjson1-protocol.html#operation-error-serialization
|
|
285
|
-
function awsErrorType(value) {
|
|
286
|
-
return typeof value === "string" ? [value.replace(/:.*/s, "").replace(/^[^#]*#/, "")] : [];
|
|
287
|
-
}
|