@opencode/ai 2.0.22 → 2.0.24
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 +61 -1
- package/dist/cache-policy.js +13 -9
- package/dist/protocols/alibaba-chat.d.ts +3 -3
- package/dist/protocols/alibaba-messages.d.ts +3 -0
- package/dist/protocols/alibaba-responses.d.ts +19 -12
- package/dist/protocols/alibaba-responses.js +3 -5
- package/dist/protocols/anthropic-messages.d.ts +3 -0
- package/dist/protocols/anthropic-messages.js +53 -48
- package/dist/protocols/bedrock-converse.js +3 -3
- package/dist/protocols/cartesia-speech.js +3 -3
- package/dist/protocols/cohere-chat.d.ts +178 -0
- package/dist/protocols/cohere-chat.js +299 -0
- package/dist/protocols/elevenlabs-speech.js +3 -3
- package/dist/protocols/gemini.d.ts +2 -2
- package/dist/protocols/gemini.js +3 -3
- package/dist/protocols/google-interactions.d.ts +236 -0
- package/dist/protocols/google-interactions.js +478 -0
- package/dist/protocols/google-speech.js +1 -1
- package/dist/protocols/google-transcription.js +1 -1
- package/dist/protocols/index.d.ts +2 -0
- package/dist/protocols/index.js +2 -0
- package/dist/protocols/meta-messages.d.ts +3 -0
- package/dist/protocols/meta-responses.d.ts +34 -58
- package/dist/protocols/meta-responses.js +8 -27
- package/dist/protocols/mistral-chat.d.ts +24 -9
- package/dist/protocols/mistral-chat.js +22 -10
- package/dist/protocols/open-responses.d.ts +424 -103
- package/dist/protocols/open-responses.js +30 -20
- package/dist/protocols/openai-chat.d.ts +401 -5
- package/dist/protocols/openai-chat.js +18 -21
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +16 -4
- package/dist/protocols/openai-images.js +2 -2
- package/dist/protocols/openai-responses.d.ts +90 -223
- package/dist/protocols/openai-responses.js +6 -13
- package/dist/protocols/openai-speech.js +1 -1
- package/dist/protocols/openai-transcription.js +1 -1
- package/dist/protocols/shared.js +2 -2
- package/dist/protocols/stability-images.js +1 -1
- package/dist/protocols/utils/bedrock-media.js +2 -2
- package/dist/protocols/utils/gateway-protocol.d.ts +17 -0
- package/dist/protocols/utils/gateway-protocol.js +57 -0
- package/dist/protocols/utils/responses-checkpoint.js +2 -2
- package/dist/protocols/utils/responses-hosted-tools.js +1 -1
- package/dist/protocols/utils/tool-stream.js +15 -7
- package/dist/protocols/venice-chat.d.ts +280 -0
- package/dist/protocols/venice-chat.js +283 -0
- package/dist/protocols/xai-responses.d.ts +21 -21
- package/dist/protocols/xai-responses.js +2 -8
- package/dist/protocols/zai-chat.d.ts +3 -3
- package/dist/protocols/zai-messages.d.ts +3 -0
- package/dist/provider-error.js +7 -1
- package/dist/providers/alibaba.d.ts +17 -13
- package/dist/providers/amazon-bedrock/mantle/messages.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/messages.js +1 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +301 -9
- package/dist/providers/amazon-bedrock-mantle.js +28 -3
- package/dist/providers/azure.d.ts +13 -61
- package/dist/providers/baseten.d.ts +2 -2
- package/dist/providers/cerebras.d.ts +2 -2
- package/dist/providers/cloudflare-ai-gateway.d.ts +14 -62
- package/dist/providers/cloudflare-workers-ai.d.ts +2 -2
- package/dist/providers/cohere/chat.d.ts +4 -0
- package/dist/providers/cohere/chat.js +8 -0
- package/dist/providers/cohere.d.ts +395 -0
- package/dist/providers/cohere.js +48 -0
- package/dist/providers/deepinfra.d.ts +2 -2
- package/dist/providers/deepseek.d.ts +2 -2
- package/dist/providers/digitalocean.d.ts +5 -5
- package/dist/providers/fireworks.d.ts +2 -2
- package/dist/providers/google/interactions.d.ts +7 -0
- package/dist/providers/google/interactions.js +8 -0
- package/dist/providers/google-vertex-chat.d.ts +1 -1
- package/dist/providers/google-vertex-messages.js +1 -0
- package/dist/providers/google-vertex-responses.d.ts +16 -4
- package/dist/providers/google-vertex.d.ts +1 -1
- package/dist/providers/google.d.ts +95 -4
- package/dist/providers/google.js +8 -1
- package/dist/providers/groq.d.ts +4 -4
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.js +2 -0
- package/dist/providers/meta.d.ts +15 -28
- package/dist/providers/minimax.d.ts +17 -5
- package/dist/providers/mistral.d.ts +10 -4
- package/dist/providers/moonshot.d.ts +17 -5
- package/dist/providers/openai-compatible-responses.d.ts +16 -4
- package/dist/providers/openai-compatible.d.ts +1 -1
- package/dist/providers/openai-options.d.ts +1 -1
- package/dist/providers/openai.d.ts +7 -31
- package/dist/providers/openrouter.d.ts +5 -5
- package/dist/providers/togetherai.d.ts +2 -2
- package/dist/providers/venice.d.ts +183 -0
- package/dist/providers/venice.js +38 -0
- package/dist/providers/vercel-ai-gateway/chat.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/chat.js +1 -0
- package/dist/providers/vercel-ai-gateway/messages.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/messages.js +1 -0
- package/dist/providers/vercel-ai-gateway/responses.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/responses.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +91 -9
- package/dist/providers/vercel-ai-gateway.js +161 -21
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/zai-coding-plan.d.ts +17 -5
- package/dist/providers/zai.d.ts +1 -1
- package/dist/route/client.js +2 -5
- package/dist/route/framing.js +23 -23
- package/package.json +3 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Protocol } from "../route/protocol.js";
|
|
3
|
-
import { HttpTransport } from "../route/transport/index.js";
|
|
4
3
|
import { OpenResponses } from "./open-responses.js";
|
|
5
4
|
export declare const WebSearch: Schema.Struct<{
|
|
6
5
|
readonly type: Schema.Literal<"web_search">;
|
|
@@ -63,6 +62,15 @@ export declare const protocol: Protocol<{
|
|
|
63
62
|
readonly error?: unknown;
|
|
64
63
|
readonly arguments?: string | undefined;
|
|
65
64
|
readonly server_label?: string | undefined;
|
|
65
|
+
} | {
|
|
66
|
+
readonly type: "configuration_update";
|
|
67
|
+
readonly reasoning: {
|
|
68
|
+
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
69
|
+
};
|
|
70
|
+
} | {
|
|
71
|
+
readonly [x: string]: unknown;
|
|
72
|
+
readonly type: string;
|
|
73
|
+
readonly id: string;
|
|
66
74
|
} | {
|
|
67
75
|
readonly type: "reasoning";
|
|
68
76
|
readonly summary: readonly {
|
|
@@ -139,13 +147,6 @@ export declare const protocol: Protocol<{
|
|
|
139
147
|
readonly type: "input_video";
|
|
140
148
|
readonly video_url: string;
|
|
141
149
|
})[];
|
|
142
|
-
} | {
|
|
143
|
-
readonly id: string;
|
|
144
|
-
readonly type: "image_generation_call";
|
|
145
|
-
readonly status?: string | undefined;
|
|
146
|
-
readonly error?: unknown;
|
|
147
|
-
readonly result?: string | null | undefined;
|
|
148
|
-
readonly output_format?: string | undefined;
|
|
149
150
|
})[];
|
|
150
151
|
readonly model: string;
|
|
151
152
|
readonly stream: true;
|
|
@@ -158,6 +159,9 @@ export declare const protocol: Protocol<{
|
|
|
158
159
|
readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
159
160
|
} | undefined;
|
|
160
161
|
readonly tools?: readonly ({
|
|
162
|
+
readonly [x: string]: unknown;
|
|
163
|
+
readonly type: string;
|
|
164
|
+
} | {
|
|
161
165
|
readonly type: "function";
|
|
162
166
|
readonly description: string;
|
|
163
167
|
readonly name: string;
|
|
@@ -165,24 +169,6 @@ export declare const protocol: Protocol<{
|
|
|
165
169
|
readonly [x: string]: unknown;
|
|
166
170
|
};
|
|
167
171
|
readonly strict?: boolean | undefined;
|
|
168
|
-
} | {
|
|
169
|
-
readonly type: "web_search";
|
|
170
|
-
readonly search_context_size?: string | undefined;
|
|
171
|
-
readonly user_location?: {
|
|
172
|
-
readonly type: "approximate";
|
|
173
|
-
readonly region?: string | undefined;
|
|
174
|
-
readonly city?: string | undefined;
|
|
175
|
-
readonly country?: string | undefined;
|
|
176
|
-
readonly timezone?: string | undefined;
|
|
177
|
-
} | undefined;
|
|
178
|
-
} | {
|
|
179
|
-
readonly type: "image_generation";
|
|
180
|
-
readonly size?: string | undefined;
|
|
181
|
-
readonly output_format?: string | undefined;
|
|
182
|
-
readonly reasoning_strength?: string | undefined;
|
|
183
|
-
readonly enable_image_search?: boolean | undefined;
|
|
184
|
-
readonly enable_web_search?: boolean | undefined;
|
|
185
|
-
readonly enable_shell?: boolean | undefined;
|
|
186
172
|
})[] | undefined;
|
|
187
173
|
readonly text?: {
|
|
188
174
|
readonly verbosity?: import("./utils/open-responses-options.js").TextVerbosity | undefined;
|
|
@@ -203,9 +189,10 @@ export declare const protocol: Protocol<{
|
|
|
203
189
|
readonly top_p?: number | undefined;
|
|
204
190
|
readonly frequency_penalty?: number | undefined;
|
|
205
191
|
readonly presence_penalty?: number | undefined;
|
|
192
|
+
readonly store?: boolean | undefined;
|
|
193
|
+
readonly max_output_tokens?: number | undefined;
|
|
206
194
|
readonly prompt_cache_key?: string | undefined;
|
|
207
195
|
readonly parallel_tool_calls?: boolean | undefined;
|
|
208
|
-
readonly store?: boolean | undefined;
|
|
209
196
|
readonly include?: readonly import("./utils/open-responses-options.js").ResponseIncludable[] | undefined;
|
|
210
197
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
211
198
|
readonly stream_options?: {
|
|
@@ -213,7 +200,6 @@ export declare const protocol: Protocol<{
|
|
|
213
200
|
} | undefined;
|
|
214
201
|
readonly safety_identifier?: string | undefined;
|
|
215
202
|
readonly top_logprobs?: number | undefined;
|
|
216
|
-
readonly max_output_tokens?: number | undefined;
|
|
217
203
|
readonly max_tool_calls?: number | undefined;
|
|
218
204
|
}, string, {
|
|
219
205
|
readonly [x: string]: unknown;
|
|
@@ -233,18 +219,21 @@ export declare const protocol: Protocol<{
|
|
|
233
219
|
readonly name?: string | undefined;
|
|
234
220
|
readonly namespace?: string | undefined;
|
|
235
221
|
readonly arguments?: string | undefined;
|
|
236
|
-
readonly encrypted_content?: string | null | undefined;
|
|
237
222
|
readonly call_id?: string | undefined;
|
|
223
|
+
readonly encrypted_content?: string | null | undefined;
|
|
238
224
|
}[] | undefined;
|
|
239
225
|
readonly error?: unknown;
|
|
240
226
|
readonly usage?: {
|
|
227
|
+
readonly [x: string]: unknown;
|
|
241
228
|
readonly input_tokens?: number | undefined;
|
|
242
229
|
readonly output_tokens?: number | undefined;
|
|
243
230
|
readonly output_tokens_details?: {
|
|
231
|
+
readonly [x: string]: unknown;
|
|
244
232
|
readonly reasoning_tokens?: number | undefined;
|
|
245
233
|
} | null | undefined;
|
|
246
234
|
readonly total_tokens?: number | undefined;
|
|
247
235
|
readonly input_tokens_details?: {
|
|
236
|
+
readonly [x: string]: unknown;
|
|
248
237
|
readonly cached_tokens?: number | undefined;
|
|
249
238
|
readonly cache_write_tokens?: number | undefined;
|
|
250
239
|
} | null | undefined;
|
|
@@ -261,8 +250,8 @@ export declare const protocol: Protocol<{
|
|
|
261
250
|
readonly name?: string | undefined;
|
|
262
251
|
readonly namespace?: string | undefined;
|
|
263
252
|
readonly arguments?: string | undefined;
|
|
264
|
-
readonly encrypted_content?: string | null | undefined;
|
|
265
253
|
readonly call_id?: string | undefined;
|
|
254
|
+
readonly encrypted_content?: string | null | undefined;
|
|
266
255
|
} | null | undefined;
|
|
267
256
|
readonly delta?: string | undefined;
|
|
268
257
|
readonly arguments?: string | undefined;
|
|
@@ -271,7 +260,7 @@ export declare const protocol: Protocol<{
|
|
|
271
260
|
readonly summary_index?: number | undefined;
|
|
272
261
|
readonly status_code?: unknown;
|
|
273
262
|
}, ParserState>;
|
|
274
|
-
export declare const httpTransport:
|
|
263
|
+
export declare const httpTransport: import("../route/transport/http.js").HttpJsonTransport<{
|
|
275
264
|
readonly input: readonly ({
|
|
276
265
|
readonly [x: string]: unknown;
|
|
277
266
|
readonly id: string;
|
|
@@ -309,6 +298,15 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
309
298
|
readonly error?: unknown;
|
|
310
299
|
readonly arguments?: string | undefined;
|
|
311
300
|
readonly server_label?: string | undefined;
|
|
301
|
+
} | {
|
|
302
|
+
readonly type: "configuration_update";
|
|
303
|
+
readonly reasoning: {
|
|
304
|
+
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
305
|
+
};
|
|
306
|
+
} | {
|
|
307
|
+
readonly [x: string]: unknown;
|
|
308
|
+
readonly type: string;
|
|
309
|
+
readonly id: string;
|
|
312
310
|
} | {
|
|
313
311
|
readonly type: "reasoning";
|
|
314
312
|
readonly summary: readonly {
|
|
@@ -385,13 +383,6 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
385
383
|
readonly type: "input_video";
|
|
386
384
|
readonly video_url: string;
|
|
387
385
|
})[];
|
|
388
|
-
} | {
|
|
389
|
-
readonly id: string;
|
|
390
|
-
readonly type: "image_generation_call";
|
|
391
|
-
readonly status?: string | undefined;
|
|
392
|
-
readonly error?: unknown;
|
|
393
|
-
readonly result?: string | null | undefined;
|
|
394
|
-
readonly output_format?: string | undefined;
|
|
395
386
|
})[];
|
|
396
387
|
readonly model: string;
|
|
397
388
|
readonly stream: true;
|
|
@@ -404,6 +395,9 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
404
395
|
readonly effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
405
396
|
} | undefined;
|
|
406
397
|
readonly tools?: readonly ({
|
|
398
|
+
readonly [x: string]: unknown;
|
|
399
|
+
readonly type: string;
|
|
400
|
+
} | {
|
|
407
401
|
readonly type: "function";
|
|
408
402
|
readonly description: string;
|
|
409
403
|
readonly name: string;
|
|
@@ -411,24 +405,6 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
411
405
|
readonly [x: string]: unknown;
|
|
412
406
|
};
|
|
413
407
|
readonly strict?: boolean | undefined;
|
|
414
|
-
} | {
|
|
415
|
-
readonly type: "web_search";
|
|
416
|
-
readonly search_context_size?: string | undefined;
|
|
417
|
-
readonly user_location?: {
|
|
418
|
-
readonly type: "approximate";
|
|
419
|
-
readonly region?: string | undefined;
|
|
420
|
-
readonly city?: string | undefined;
|
|
421
|
-
readonly country?: string | undefined;
|
|
422
|
-
readonly timezone?: string | undefined;
|
|
423
|
-
} | undefined;
|
|
424
|
-
} | {
|
|
425
|
-
readonly type: "image_generation";
|
|
426
|
-
readonly size?: string | undefined;
|
|
427
|
-
readonly output_format?: string | undefined;
|
|
428
|
-
readonly reasoning_strength?: string | undefined;
|
|
429
|
-
readonly enable_image_search?: boolean | undefined;
|
|
430
|
-
readonly enable_web_search?: boolean | undefined;
|
|
431
|
-
readonly enable_shell?: boolean | undefined;
|
|
432
408
|
})[] | undefined;
|
|
433
409
|
readonly text?: {
|
|
434
410
|
readonly verbosity?: import("./utils/open-responses-options.js").TextVerbosity | undefined;
|
|
@@ -449,9 +425,10 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
449
425
|
readonly top_p?: number | undefined;
|
|
450
426
|
readonly frequency_penalty?: number | undefined;
|
|
451
427
|
readonly presence_penalty?: number | undefined;
|
|
428
|
+
readonly store?: boolean | undefined;
|
|
429
|
+
readonly max_output_tokens?: number | undefined;
|
|
452
430
|
readonly prompt_cache_key?: string | undefined;
|
|
453
431
|
readonly parallel_tool_calls?: boolean | undefined;
|
|
454
|
-
readonly store?: boolean | undefined;
|
|
455
432
|
readonly include?: readonly import("./utils/open-responses-options.js").ResponseIncludable[] | undefined;
|
|
456
433
|
readonly truncation?: "auto" | "disabled" | undefined;
|
|
457
434
|
readonly stream_options?: {
|
|
@@ -459,7 +436,6 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
459
436
|
} | undefined;
|
|
460
437
|
readonly safety_identifier?: string | undefined;
|
|
461
438
|
readonly top_logprobs?: number | undefined;
|
|
462
|
-
readonly max_output_tokens?: number | undefined;
|
|
463
439
|
readonly max_tool_calls?: number | undefined;
|
|
464
440
|
}, string>;
|
|
465
441
|
export * as MetaResponses from "./meta-responses.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Effect, Encoding, Schema } from "effect";
|
|
2
2
|
import { Protocol } from "../route/protocol.js";
|
|
3
|
-
import { HttpTransport } from "../route/transport/index.js";
|
|
4
3
|
import { LLMEvent, LLMRequest, Message, ToolResultPart } from "../schema/index.js";
|
|
5
4
|
import { OpenResponses } from "./open-responses.js";
|
|
6
5
|
import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
|
|
@@ -37,23 +36,18 @@ const ImageItem = Schema.Struct({
|
|
|
37
36
|
output_format: Schema.optional(Schema.String),
|
|
38
37
|
error: Schema.optional(Schema.Unknown),
|
|
39
38
|
});
|
|
40
|
-
const Body = Schema.Struct({
|
|
41
|
-
...OpenResponses.coreFields,
|
|
42
|
-
input: Schema.Array(Schema.Union([OpenResponses.InputItem, ImageItem])),
|
|
43
|
-
tools: optionalArray(Schema.Union([OpenResponses.Tool, NativeTool])),
|
|
44
|
-
stream: Schema.Literal(true),
|
|
45
|
-
});
|
|
46
39
|
const MessageAnnotations = Schema.Struct({
|
|
47
40
|
content: Schema.Array(Schema.Struct({ annotations: optionalArray(JsonObject) })),
|
|
48
41
|
});
|
|
49
42
|
const adapter = {
|
|
50
43
|
id: ADAPTER,
|
|
51
44
|
name: NAME,
|
|
45
|
+
nativeTool: (native) => ProviderShared.validateWith(Schema.decodeUnknownEffect(NativeTool))(native.meta),
|
|
52
46
|
restoreHostedToolItem: (item) => (Schema.is(ImageItem)(item) ? item : undefined),
|
|
53
47
|
};
|
|
54
48
|
const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
55
49
|
const key = request.model.route.providerMetadataKey ?? String(request.model.provider);
|
|
56
|
-
|
|
50
|
+
return yield* OpenResponses.fromRequestWithAdapter(LLMRequest.update(request, {
|
|
57
51
|
messages: request.messages.map((message) => Message.make({
|
|
58
52
|
...message,
|
|
59
53
|
content: message.content.map((part) => {
|
|
@@ -73,27 +67,14 @@ const fromRequest = Effect.fn("MetaResponses.fromRequest")(function* (request) {
|
|
|
73
67
|
});
|
|
74
68
|
}),
|
|
75
69
|
})),
|
|
76
|
-
}));
|
|
77
|
-
return yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))({
|
|
78
|
-
...(yield* OpenResponses.lowerConversation(projected.request, adapter)),
|
|
79
|
-
...OpenResponses.lowerGeneration(request),
|
|
80
|
-
tools: projected.tools.length === 0
|
|
81
|
-
? undefined
|
|
82
|
-
: yield* Effect.forEach(projected.tools, (tool) => Effect.gen(function* () {
|
|
83
|
-
if (tool.native === undefined)
|
|
84
|
-
return yield* OpenResponses.lowerTool(NAME, tool);
|
|
85
|
-
return yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(NativeTool))(tool.native.meta);
|
|
86
|
-
})),
|
|
87
|
-
tool_choice: OpenResponses.allowedToolChoice(request) ??
|
|
88
|
-
(request.toolChoice ? yield* OpenResponses.lowerToolChoice(NAME, request.toolChoice) : undefined),
|
|
89
|
-
});
|
|
70
|
+
}), adapter);
|
|
90
71
|
});
|
|
91
72
|
const HOSTED_TOOLS = {
|
|
92
73
|
web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
|
|
93
74
|
image_generation_call: {
|
|
94
75
|
name: "image_generation",
|
|
95
76
|
input: () => ({}),
|
|
96
|
-
result: Effect.
|
|
77
|
+
result: Effect.fnUntraced(function* (raw) {
|
|
97
78
|
const item = yield* Schema.decodeUnknownEffect(ImageItem)(raw).pipe(Effect.mapError((cause) => ProviderShared.eventError(ADAPTER, "Meta returned an invalid image item", ProviderShared.encodeJson(raw), cause)));
|
|
98
79
|
if (item.error !== undefined && item.error !== null)
|
|
99
80
|
return { type: "error", value: item.error };
|
|
@@ -111,7 +92,7 @@ const HOSTED_TOOLS = {
|
|
|
111
92
|
}),
|
|
112
93
|
},
|
|
113
94
|
};
|
|
114
|
-
const onEvent = Effect.
|
|
95
|
+
const onEvent = Effect.fnUntraced(function* (state, input) {
|
|
115
96
|
const event = OpenResponses.normalize(state, input);
|
|
116
97
|
if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS))
|
|
117
98
|
return yield* ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS);
|
|
@@ -135,7 +116,7 @@ const onEvent = Effect.fn("MetaResponses.onEvent")(function* (state, input) {
|
|
|
135
116
|
: item),
|
|
136
117
|
];
|
|
137
118
|
});
|
|
138
|
-
const step = Effect.
|
|
119
|
+
const step = Effect.fnUntraced(function* (state, input) {
|
|
139
120
|
const completedItems = new Set(state.completedItems);
|
|
140
121
|
const event = OpenResponses.normalize(state, input);
|
|
141
122
|
if (event.type === "response.output_item.done" && event.item && completedItems.has(event.item.id))
|
|
@@ -163,7 +144,7 @@ const step = Effect.fn("MetaResponses.step")(function* (state, input) {
|
|
|
163
144
|
});
|
|
164
145
|
export const protocol = Protocol.make({
|
|
165
146
|
id: ADAPTER,
|
|
166
|
-
body: { schema:
|
|
147
|
+
body: { schema: OpenResponses.OpenResponsesBody, from: fromRequest },
|
|
167
148
|
stream: {
|
|
168
149
|
event: OpenResponses.protocol.stream.event,
|
|
169
150
|
initial: (request) => ({ ...OpenResponses.initial(request, adapter), completedItems: new Set() }),
|
|
@@ -171,5 +152,5 @@ export const protocol = Protocol.make({
|
|
|
171
152
|
terminal: OpenResponses.terminal,
|
|
172
153
|
},
|
|
173
154
|
});
|
|
174
|
-
export const httpTransport =
|
|
155
|
+
export const httpTransport = OpenResponses.httpTransport;
|
|
175
156
|
export * as MetaResponses from "./meta-responses.js";
|
|
@@ -36,7 +36,10 @@ declare const MistralBody: Schema.Struct<{
|
|
|
36
36
|
readonly model: Schema.String;
|
|
37
37
|
readonly messages: Schema.$Array<Schema.toTaggedUnion<"role", readonly [Schema.Struct<{
|
|
38
38
|
readonly role: Schema.Literal<"system">;
|
|
39
|
-
readonly content: Schema.String
|
|
39
|
+
readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Struct<{
|
|
40
|
+
readonly type: Schema.Literal<"text">;
|
|
41
|
+
readonly text: Schema.String;
|
|
42
|
+
}>>]>;
|
|
40
43
|
}>, Schema.Struct<{
|
|
41
44
|
readonly role: Schema.Literal<"user">;
|
|
42
45
|
readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
@@ -123,7 +126,10 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
|
|
|
123
126
|
model: string & import("effect/Brand").Brand<"AI.ModelID">;
|
|
124
127
|
messages: ({
|
|
125
128
|
readonly role: "system";
|
|
126
|
-
readonly content: string
|
|
129
|
+
readonly content: string | readonly {
|
|
130
|
+
readonly type: "text";
|
|
131
|
+
readonly text: string;
|
|
132
|
+
}[];
|
|
127
133
|
} | {
|
|
128
134
|
readonly role: "user";
|
|
129
135
|
readonly content: string | readonly ({
|
|
@@ -237,7 +243,10 @@ export declare const protocol: Protocol<{
|
|
|
237
243
|
readonly model: string;
|
|
238
244
|
readonly messages: readonly ({
|
|
239
245
|
readonly role: "system";
|
|
240
|
-
readonly content: string
|
|
246
|
+
readonly content: string | readonly {
|
|
247
|
+
readonly type: "text";
|
|
248
|
+
readonly text: string;
|
|
249
|
+
}[];
|
|
241
250
|
} | {
|
|
242
251
|
readonly role: "user";
|
|
243
252
|
readonly content: string | readonly ({
|
|
@@ -310,9 +319,9 @@ export declare const protocol: Protocol<{
|
|
|
310
319
|
};
|
|
311
320
|
} | undefined;
|
|
312
321
|
readonly top_p?: number | undefined;
|
|
313
|
-
readonly random_seed?: number | undefined;
|
|
314
322
|
readonly frequency_penalty?: number | undefined;
|
|
315
323
|
readonly presence_penalty?: number | undefined;
|
|
324
|
+
readonly random_seed?: number | undefined;
|
|
316
325
|
readonly prompt_cache_key?: string | undefined;
|
|
317
326
|
readonly safe_prompt?: boolean | undefined;
|
|
318
327
|
readonly document_image_limit?: number | undefined;
|
|
@@ -329,9 +338,9 @@ export declare const protocol: Protocol<{
|
|
|
329
338
|
} | null | undefined;
|
|
330
339
|
readonly usage?: {
|
|
331
340
|
readonly [x: string]: unknown;
|
|
341
|
+
readonly total_tokens?: number | null | undefined;
|
|
332
342
|
readonly prompt_tokens?: number | null | undefined;
|
|
333
343
|
readonly completion_tokens?: number | null | undefined;
|
|
334
|
-
readonly total_tokens?: number | null | undefined;
|
|
335
344
|
readonly num_cached_tokens?: number | null | undefined;
|
|
336
345
|
readonly prompt_token_details?: {
|
|
337
346
|
readonly [x: string]: unknown;
|
|
@@ -371,7 +380,10 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
371
380
|
readonly model: string;
|
|
372
381
|
readonly messages: readonly ({
|
|
373
382
|
readonly role: "system";
|
|
374
|
-
readonly content: string
|
|
383
|
+
readonly content: string | readonly {
|
|
384
|
+
readonly type: "text";
|
|
385
|
+
readonly text: string;
|
|
386
|
+
}[];
|
|
375
387
|
} | {
|
|
376
388
|
readonly role: "user";
|
|
377
389
|
readonly content: string | readonly ({
|
|
@@ -444,9 +456,9 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
444
456
|
};
|
|
445
457
|
} | undefined;
|
|
446
458
|
readonly top_p?: number | undefined;
|
|
447
|
-
readonly random_seed?: number | undefined;
|
|
448
459
|
readonly frequency_penalty?: number | undefined;
|
|
449
460
|
readonly presence_penalty?: number | undefined;
|
|
461
|
+
readonly random_seed?: number | undefined;
|
|
450
462
|
readonly prompt_cache_key?: string | undefined;
|
|
451
463
|
readonly safe_prompt?: boolean | undefined;
|
|
452
464
|
readonly document_image_limit?: number | undefined;
|
|
@@ -459,7 +471,10 @@ export declare const route: Route<{
|
|
|
459
471
|
readonly model: string;
|
|
460
472
|
readonly messages: readonly ({
|
|
461
473
|
readonly role: "system";
|
|
462
|
-
readonly content: string
|
|
474
|
+
readonly content: string | readonly {
|
|
475
|
+
readonly type: "text";
|
|
476
|
+
readonly text: string;
|
|
477
|
+
}[];
|
|
463
478
|
} | {
|
|
464
479
|
readonly role: "user";
|
|
465
480
|
readonly content: string | readonly ({
|
|
@@ -532,9 +547,9 @@ export declare const route: Route<{
|
|
|
532
547
|
};
|
|
533
548
|
} | undefined;
|
|
534
549
|
readonly top_p?: number | undefined;
|
|
535
|
-
readonly random_seed?: number | undefined;
|
|
536
550
|
readonly frequency_penalty?: number | undefined;
|
|
537
551
|
readonly presence_penalty?: number | undefined;
|
|
552
|
+
readonly random_seed?: number | undefined;
|
|
538
553
|
readonly prompt_cache_key?: string | undefined;
|
|
539
554
|
readonly safe_prompt?: boolean | undefined;
|
|
540
555
|
readonly document_image_limit?: number | undefined;
|
|
@@ -39,7 +39,10 @@ const MistralAssistantToolCall = Schema.Struct({
|
|
|
39
39
|
function: Schema.Struct({ name: Schema.String, arguments: Schema.String }),
|
|
40
40
|
});
|
|
41
41
|
const MistralMessage = Schema.Union([
|
|
42
|
-
Schema.Struct({
|
|
42
|
+
Schema.Struct({
|
|
43
|
+
role: Schema.Literal("system"),
|
|
44
|
+
content: Schema.Union([Schema.String, Schema.Array(MistralTextContent)]),
|
|
45
|
+
}),
|
|
43
46
|
Schema.Struct({
|
|
44
47
|
role: Schema.Literal("user"),
|
|
45
48
|
content: Schema.Union([Schema.String, Schema.Array(MistralUserContent)]),
|
|
@@ -140,7 +143,7 @@ const MistralEvent = Schema.StructWithRest(Schema.Struct({
|
|
|
140
143
|
error: optionalNull(MistralError),
|
|
141
144
|
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
142
145
|
const MistralStreamEvent = Schema.Union([Schema.Literal(DONE), Protocol.jsonEvent(MistralEvent)]);
|
|
143
|
-
const lowerMedia = Effect.
|
|
146
|
+
const lowerMedia = Effect.fnUntraced(function* (part) {
|
|
144
147
|
const mime = part.media.mediaType.toLowerCase();
|
|
145
148
|
const url = ProviderShared.mediaUrl(part.media) ??
|
|
146
149
|
(yield* ProviderShared.requireInlineMedia("Mistral Chat", part.media)).dataUrl;
|
|
@@ -150,7 +153,7 @@ const lowerMedia = Effect.fn("MistralChat.lowerMedia")(function* (part) {
|
|
|
150
153
|
return { type: "document_url", document_url: url };
|
|
151
154
|
return yield* ProviderShared.invalidRequest(`Mistral Chat does not support media type ${part.media.mediaType}`);
|
|
152
155
|
});
|
|
153
|
-
const lowerUser = Effect.
|
|
156
|
+
const lowerUser = Effect.fnUntraced(function* (message) {
|
|
154
157
|
const content = [];
|
|
155
158
|
for (const part of message.content) {
|
|
156
159
|
if (part.type === "text") {
|
|
@@ -172,7 +175,7 @@ const lowerToolCall = (part, normalizeID) => ({
|
|
|
172
175
|
type: "function",
|
|
173
176
|
function: { name: part.name, arguments: ProviderShared.encodeJson(part.input) },
|
|
174
177
|
});
|
|
175
|
-
const lowerAssistant = Effect.
|
|
178
|
+
const lowerAssistant = Effect.fnUntraced(function* (message, normalizeID, prefix) {
|
|
176
179
|
const structured = message.content.some((part) => part.type === "reasoning" && isMistralThinkingContent(part.providerMetadata?.mistral?.thinking));
|
|
177
180
|
const content = [];
|
|
178
181
|
const text = [];
|
|
@@ -208,7 +211,7 @@ const lowerAssistant = Effect.fn("MistralChat.lowerAssistant")(function* (messag
|
|
|
208
211
|
...(prefix ? { prefix: true } : {}),
|
|
209
212
|
};
|
|
210
213
|
});
|
|
211
|
-
const lowerToolResults = Effect.
|
|
214
|
+
const lowerToolResults = Effect.fnUntraced(function* (message, normalizeID) {
|
|
212
215
|
const output = [];
|
|
213
216
|
for (const part of message.content) {
|
|
214
217
|
if (part.type !== "tool-result")
|
|
@@ -241,9 +244,18 @@ const lowerToolResults = Effect.fn("MistralChat.lowerToolResults")(function* (me
|
|
|
241
244
|
}
|
|
242
245
|
return output;
|
|
243
246
|
});
|
|
244
|
-
const lowerMessages = Effect.
|
|
247
|
+
const lowerMessages = Effect.fnUntraced(function* (request) {
|
|
245
248
|
const normalizeID = MistralToolID.normalizer(request);
|
|
246
|
-
const messages = request.system.length === 0
|
|
249
|
+
const messages = request.system.length === 0
|
|
250
|
+
? []
|
|
251
|
+
: [
|
|
252
|
+
{
|
|
253
|
+
role: "system",
|
|
254
|
+
content: request.system.length === 1
|
|
255
|
+
? request.system[0].text
|
|
256
|
+
: request.system.map((part) => ({ type: "text", text: part.text })),
|
|
257
|
+
},
|
|
258
|
+
];
|
|
247
259
|
for (const message of request.messages) {
|
|
248
260
|
if (message.role === "system") {
|
|
249
261
|
const update = yield* ProviderShared.wrappedSystemUpdate("Mistral Chat", message);
|
|
@@ -439,7 +451,7 @@ const toolText = (tool) => {
|
|
|
439
451
|
return value;
|
|
440
452
|
return value === null || value === undefined ? "" : ProviderShared.encodeJson(value);
|
|
441
453
|
};
|
|
442
|
-
const appendTools = Effect.
|
|
454
|
+
const appendTools = Effect.fnUntraced(function* (initial, events, deltas) {
|
|
443
455
|
if (deltas.length === 0)
|
|
444
456
|
return initial;
|
|
445
457
|
let state = closeActive(initial, events);
|
|
@@ -494,7 +506,7 @@ const hasLateContent = (event) => {
|
|
|
494
506
|
return true;
|
|
495
507
|
return (delta?.tool_calls ?? []).some((tool) => Boolean(tool.id) || Boolean(tool.function?.name) || tool.function?.arguments !== undefined);
|
|
496
508
|
};
|
|
497
|
-
const step = Effect.
|
|
509
|
+
const step = Effect.fnUntraced(function* (state, event) {
|
|
498
510
|
if (event.error) {
|
|
499
511
|
const body = ProviderShared.encodeJson(event);
|
|
500
512
|
return yield* new AIError({
|
|
@@ -547,7 +559,7 @@ const step = Effect.fn("MistralChat.step")(function* (state, event) {
|
|
|
547
559
|
events,
|
|
548
560
|
];
|
|
549
561
|
});
|
|
550
|
-
const finishEvents = Effect.
|
|
562
|
+
const finishEvents = Effect.fnUntraced(function* (state) {
|
|
551
563
|
if (!state.finishReason)
|
|
552
564
|
return yield* new AIError({
|
|
553
565
|
reason: new InvalidProviderOutputError({
|