@opencode/ai 2.1.4 → 2.2.0
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 +283 -114
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -1
- package/dist/cache-policy.d.ts +4 -0
- package/dist/cache-policy.js +20 -6
- package/dist/decision-client.d.ts +21 -0
- package/dist/decision-client.js +55 -0
- package/dist/decision.d.ts +472 -0
- package/dist/decision.js +158 -0
- package/dist/effect.d.ts +38 -0
- package/dist/effect.js +27 -0
- package/dist/effort-updates.d.ts +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
- package/dist/experimental/cloudflare-run-extraction.js +83 -0
- package/dist/experimental/extraction.d.ts +183 -0
- package/dist/experimental/extraction.js +102 -0
- package/dist/experimental/realtime.d.ts +7 -2
- package/dist/experimental/realtime.js +5 -5
- package/dist/experimental.d.ts +2 -3
- package/dist/experimental.js +1 -2
- package/dist/image-client.d.ts +5 -14
- package/dist/image-client.js +0 -1
- package/dist/image.d.ts +6 -176
- package/dist/image.js +4 -11
- package/dist/index.d.ts +1426 -34
- package/dist/index.js +127 -24
- package/dist/llm.d.ts +16 -1
- package/dist/llm.js +34 -0
- package/dist/media-client.d.ts +2 -1
- package/dist/media-model.d.ts +3 -0
- package/dist/media-model.js +4 -1
- package/dist/media.d.ts +0 -7
- package/dist/media.js +0 -6
- package/dist/protocols/alibaba-chat.d.ts +20 -0
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +52 -17
- package/dist/protocols/alibaba-responses.d.ts +6 -3
- package/dist/protocols/anthropic-messages.d.ts +160 -54
- package/dist/protocols/anthropic-messages.js +44 -13
- package/dist/protocols/bedrock-converse.d.ts +110 -15
- package/dist/protocols/bedrock-converse.js +112 -15
- package/dist/protocols/bedrock-event-stream.js +1 -0
- package/dist/protocols/bfl-images.d.ts +9 -0
- package/dist/protocols/bfl-images.js +17 -15
- package/dist/protocols/cartesia-speech.d.ts +0 -18
- package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
- package/dist/protocols/cloudflare-run-decisions.js +36 -0
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
- package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
- package/dist/protocols/deepgram-speech.d.ts +0 -18
- package/dist/protocols/elevenlabs-speech.d.ts +0 -18
- package/dist/protocols/fal-images.d.ts +10 -1
- package/dist/protocols/fal-images.js +16 -25
- package/dist/protocols/fal-video.js +1 -1
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +11 -6
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-images.js +8 -37
- package/dist/protocols/google-interactions.d.ts +4 -0
- package/dist/protocols/google-interactions.js +12 -5
- package/dist/protocols/google-speech.d.ts +0 -18
- package/dist/protocols/google-speech.js +0 -1
- package/dist/protocols/google-transcription.d.ts +0 -18
- package/dist/protocols/google-transcription.js +0 -1
- package/dist/protocols/google-video.d.ts +1 -1
- package/dist/protocols/google-video.js +2 -7
- package/dist/protocols/index.d.ts +3 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/meta-images.d.ts +7 -1
- package/dist/protocols/meta-images.js +10 -8
- package/dist/protocols/meta-messages.d.ts +52 -17
- package/dist/protocols/meta-messages.js +14 -1
- package/dist/protocols/meta-responses.d.ts +6 -0
- package/dist/protocols/meta-responses.js +29 -1
- package/dist/protocols/open-responses.d.ts +30 -0
- package/dist/protocols/open-responses.js +8 -18
- package/dist/protocols/openai-chat.d.ts +713 -1
- package/dist/protocols/openai-chat.js +35 -22
- package/dist/protocols/openai-compatible-chat.d.ts +22 -1
- package/dist/protocols/openai-compatible-responses.d.ts +8 -5
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +128 -0
- package/dist/protocols/openai-images.d.ts +21 -24
- package/dist/protocols/openai-images.js +100 -34
- package/dist/protocols/openai-responses.d.ts +82 -24
- package/dist/protocols/openai-responses.js +32 -2
- package/dist/protocols/openai-speech.d.ts +0 -18
- package/dist/protocols/openai-speech.js +15 -5
- package/dist/protocols/openai-transcription.d.ts +0 -18
- package/dist/protocols/openai-transcription.js +3 -4
- package/dist/protocols/replicate-images.js +1 -1
- package/dist/protocols/runway-video.d.ts +1 -1
- package/dist/protocols/runway-video.js +1 -1
- package/dist/protocols/shared.d.ts +9 -1
- package/dist/protocols/shared.js +13 -2
- package/dist/protocols/stability-images.d.ts +5 -0
- package/dist/protocols/stability-images.js +4 -9
- package/dist/protocols/system-one.d.ts +101 -0
- package/dist/protocols/system-one.js +230 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
- package/dist/protocols/utils/bedrock-cache.js +7 -6
- package/dist/protocols/utils/cache.d.ts +14 -3
- package/dist/protocols/utils/cache.js +11 -4
- package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
- package/dist/protocols/utils/gemini-generate-content.js +10 -16
- package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
- package/dist/protocols/utils/gemini-json-schema.js +3 -3
- package/dist/protocols/utils/image-sizing.d.ts +31 -0
- package/dist/protocols/utils/image-sizing.js +73 -0
- package/dist/protocols/utils/media-input.d.ts +4 -5
- package/dist/protocols/utils/media-input.js +8 -5
- package/dist/protocols/utils/speech-stream.d.ts +0 -1
- package/dist/protocols/utils/speech-stream.js +0 -1
- package/dist/protocols/utils/tool-schema.js +15 -5
- package/dist/protocols/utils/tool-stream.d.ts +9 -0
- package/dist/protocols/venice-chat.d.ts +19 -0
- package/dist/protocols/venice-chat.js +1 -1
- package/dist/protocols/xai-images.d.ts +1 -2
- package/dist/protocols/xai-images.js +9 -2
- package/dist/protocols/xai-responses.d.ts +10 -0
- package/dist/protocols/xai-responses.js +28 -2
- package/dist/protocols/xai-video.d.ts +1 -1
- package/dist/protocols/xai-video.js +11 -8
- package/dist/protocols/zai-chat.d.ts +21 -0
- package/dist/protocols/zai-images.d.ts +3 -1
- package/dist/protocols/zai-images.js +12 -11
- package/dist/protocols/zai-messages.d.ts +52 -17
- package/dist/provider-error.js +19 -4
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +79 -18
- package/dist/providers/alibaba.js +16 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +197 -138
- package/dist/providers/amazon-bedrock.d.ts +34 -14
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +52 -17
- package/dist/providers/anthropic.d.ts +52 -17
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +50 -9
- package/dist/providers/azure.js +19 -1
- package/dist/providers/baseten/decisions.d.ts +2 -0
- package/dist/providers/baseten/decisions.js +1 -0
- package/dist/providers/baseten.d.ts +51 -1
- package/dist/providers/baseten.js +41 -8
- package/dist/providers/cerebras.d.ts +42 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +177 -43
- package/dist/providers/cloudflare-ai-gateway.js +32 -4
- package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
- package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
- package/dist/providers/cloudflare-workers-ai/images.js +1 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +55 -1
- package/dist/providers/cloudflare-workers-ai.js +45 -9
- package/dist/providers/cohere.d.ts +42 -0
- package/dist/providers/deepinfra.d.ts +42 -0
- package/dist/providers/deepseek.d.ts +42 -0
- package/dist/providers/digitalocean/decisions.d.ts +2 -0
- package/dist/providers/digitalocean/decisions.js +1 -0
- package/dist/providers/digitalocean/images.d.ts +2 -0
- package/dist/providers/digitalocean/images.js +1 -0
- package/dist/providers/digitalocean.d.ts +72 -1
- package/dist/providers/digitalocean.js +39 -8
- package/dist/providers/fireworks.d.ts +42 -0
- package/dist/providers/google/images.d.ts +2 -0
- package/dist/providers/google/images.js +1 -0
- package/dist/providers/google-vertex/images.d.ts +2 -0
- package/dist/providers/google-vertex/images.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +21 -0
- package/dist/providers/google-vertex-messages.d.ts +52 -17
- package/dist/providers/google-vertex-responses.d.ts +3 -0
- package/dist/providers/google-vertex.d.ts +3 -1
- package/dist/providers/google-vertex.js +30 -13
- package/dist/providers/google.d.ts +5 -4
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +42 -4
- package/dist/providers/groq.js +0 -6
- package/dist/providers/meta.d.ts +197 -138
- package/dist/providers/minimax.d.ts +76 -17
- package/dist/providers/moonshot.d.ts +76 -17
- package/dist/providers/openai/images.d.ts +2 -0
- package/dist/providers/openai/images.js +1 -0
- package/dist/providers/openai-compatible/images.d.ts +2 -0
- package/dist/providers/openai-compatible/images.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +3 -0
- package/dist/providers/openai-compatible.d.ts +24 -1
- package/dist/providers/openai-compatible.js +21 -9
- package/dist/providers/openai-options.d.ts +3 -1
- package/dist/providers/openai.d.ts +46 -9
- package/dist/providers/openai.js +20 -4
- package/dist/providers/opencode/decisions.d.ts +2 -0
- package/dist/providers/opencode/decisions.js +1 -0
- package/dist/providers/opencode.d.ts +9 -10
- package/dist/providers/opencode.js +10 -8
- package/dist/providers/openrouter/decisions.d.ts +2 -0
- package/dist/providers/openrouter/decisions.js +1 -0
- package/dist/providers/openrouter/images.d.ts +2 -0
- package/dist/providers/openrouter/images.js +1 -0
- package/dist/providers/openrouter.d.ts +92 -11
- package/dist/providers/openrouter.js +38 -16
- package/dist/providers/togetherai.d.ts +42 -0
- package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
- package/dist/providers/typesafe-ai/decisions.js +1 -0
- package/dist/providers/typesafe-ai.d.ts +9 -10
- package/dist/providers/typesafe-ai.js +10 -8
- package/dist/providers/venice.d.ts +19 -0
- package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
- package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
- package/dist/providers/vercel-ai-gateway/images.js +1 -0
- package/dist/providers/vercel-ai-gateway.d.ts +10 -16
- package/dist/providers/vercel-ai-gateway.js +31 -85
- package/dist/providers/xai/images.d.ts +2 -0
- package/dist/providers/xai/images.js +1 -0
- package/dist/providers/xai.d.ts +28 -5
- package/dist/providers/xai.js +15 -8
- package/dist/providers/zai/images.d.ts +2 -0
- package/dist/providers/zai/images.js +1 -0
- package/dist/providers/zai-coding-plan.d.ts +76 -17
- package/dist/providers/zai.d.ts +26 -4
- package/dist/providers/zai.js +15 -8
- package/dist/route/client.d.ts +2 -2
- package/dist/route/client.js +26 -4
- package/dist/route/decision.d.ts +58 -0
- package/dist/route/decision.js +75 -0
- package/dist/route/executor.d.ts +1 -1
- package/dist/route/framing.d.ts +2 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.js +3 -0
- package/dist/route/media-protocol.d.ts +1 -0
- package/dist/route/media-protocol.js +12 -8
- package/dist/route/media.d.ts +5 -1
- package/dist/route/media.js +6 -2
- package/dist/route/transport/http.js +1 -0
- package/dist/route/transport/index.d.ts +1 -0
- package/dist/schema/events.d.ts +148 -6
- package/dist/schema/events.js +20 -0
- package/dist/schema/messages.d.ts +6 -2
- package/dist/schema/messages.js +3 -0
- package/dist/schema/options.d.ts +5 -3
- package/dist/schema/options.js +8 -3
- package/dist/speech-client.d.ts +5 -14
- package/dist/speech-client.js +0 -1
- package/dist/speech.d.ts +0 -135
- package/dist/speech.js +2 -4
- package/dist/testing.d.ts +25 -24
- package/dist/testing.js +3 -21
- package/dist/transcription-client.d.ts +5 -14
- package/dist/transcription.d.ts +0 -135
- package/dist/transcription.js +1 -1
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +5 -14
- package/dist/video-client.js +0 -1
- package/dist/video.d.ts +1 -136
- package/dist/video.js +3 -5
- package/package.json +513 -11
- package/dist/experimental/evaluation-client.d.ts +0 -21
- package/dist/experimental/evaluation-client.js +0 -64
- package/dist/experimental/evaluation.d.ts +0 -242
- package/dist/experimental/evaluation.js +0 -108
- package/dist/experimental/system-one.d.ts +0 -16
- package/dist/experimental/system-one.js +0 -135
- package/dist/promise.d.ts +0 -1021
- package/dist/promise.js +0 -101
- package/dist/provider.d.ts +0 -23
- package/dist/provider.js +0 -2
|
@@ -72,6 +72,9 @@ export declare const routes: (Route<{
|
|
|
72
72
|
readonly content: readonly ({
|
|
73
73
|
readonly type: "input_text";
|
|
74
74
|
readonly text: string;
|
|
75
|
+
} | {
|
|
76
|
+
readonly type: "input_video";
|
|
77
|
+
readonly video_url: string;
|
|
75
78
|
} | {
|
|
76
79
|
readonly type: "input_image";
|
|
77
80
|
readonly image_url: string;
|
|
@@ -205,6 +208,11 @@ export declare const routes: (Route<{
|
|
|
205
208
|
readonly image_url: {
|
|
206
209
|
readonly url: string;
|
|
207
210
|
};
|
|
211
|
+
} | {
|
|
212
|
+
readonly type: "video_url";
|
|
213
|
+
readonly video_url: {
|
|
214
|
+
readonly url: string;
|
|
215
|
+
};
|
|
208
216
|
} | {
|
|
209
217
|
readonly type: "file";
|
|
210
218
|
readonly file: {
|
|
@@ -226,6 +234,11 @@ export declare const routes: (Route<{
|
|
|
226
234
|
readonly image_url: {
|
|
227
235
|
readonly url: string;
|
|
228
236
|
};
|
|
237
|
+
} | {
|
|
238
|
+
readonly type: "video_url";
|
|
239
|
+
readonly video_url: {
|
|
240
|
+
readonly url: string;
|
|
241
|
+
};
|
|
229
242
|
} | {
|
|
230
243
|
readonly type: "file";
|
|
231
244
|
readonly file: {
|
|
@@ -307,7 +320,18 @@ export declare const routes: (Route<{
|
|
|
307
320
|
} | undefined;
|
|
308
321
|
readonly store?: boolean | undefined;
|
|
309
322
|
readonly prompt_cache_key?: string | undefined;
|
|
323
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
324
|
+
readonly prompt_cache_options?: {
|
|
325
|
+
readonly ttl?: string | undefined;
|
|
326
|
+
} | undefined;
|
|
310
327
|
readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
328
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
329
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
330
|
+
readonly parallel_tool_calls?: boolean | undefined;
|
|
331
|
+
readonly metadata?: {
|
|
332
|
+
readonly [x: string]: string;
|
|
333
|
+
} | undefined;
|
|
334
|
+
readonly safety_identifier?: string | undefined;
|
|
311
335
|
readonly tool_stream?: boolean | undefined;
|
|
312
336
|
readonly max_completion_tokens?: number | undefined;
|
|
313
337
|
readonly max_tokens?: number | undefined;
|
|
@@ -345,7 +369,7 @@ export declare const routes: (Route<{
|
|
|
345
369
|
readonly text: string;
|
|
346
370
|
readonly cache_control?: {
|
|
347
371
|
readonly type: "ephemeral";
|
|
348
|
-
readonly ttl?:
|
|
372
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
349
373
|
} | undefined;
|
|
350
374
|
}[] | undefined;
|
|
351
375
|
readonly messages: readonly ({
|
|
@@ -355,7 +379,7 @@ export declare const routes: (Route<{
|
|
|
355
379
|
readonly text: string;
|
|
356
380
|
readonly cache_control?: {
|
|
357
381
|
readonly type: "ephemeral";
|
|
358
|
-
readonly ttl?:
|
|
382
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
359
383
|
} | undefined;
|
|
360
384
|
} | {
|
|
361
385
|
readonly type: "image";
|
|
@@ -372,11 +396,28 @@ export declare const routes: (Route<{
|
|
|
372
396
|
};
|
|
373
397
|
readonly cache_control?: {
|
|
374
398
|
readonly type: "ephemeral";
|
|
375
|
-
readonly ttl?:
|
|
399
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
376
400
|
} | undefined;
|
|
377
401
|
readonly transformations?: {
|
|
378
402
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
379
403
|
} | undefined;
|
|
404
|
+
} | {
|
|
405
|
+
readonly type: "video";
|
|
406
|
+
readonly source: {
|
|
407
|
+
readonly type: "base64";
|
|
408
|
+
readonly media_type: string;
|
|
409
|
+
readonly data: string;
|
|
410
|
+
} | {
|
|
411
|
+
readonly type: "url";
|
|
412
|
+
readonly url: string;
|
|
413
|
+
} | {
|
|
414
|
+
readonly type: "file";
|
|
415
|
+
readonly file_id: string;
|
|
416
|
+
};
|
|
417
|
+
readonly cache_control?: {
|
|
418
|
+
readonly type: "ephemeral";
|
|
419
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
420
|
+
} | undefined;
|
|
380
421
|
} | {
|
|
381
422
|
readonly type: "document";
|
|
382
423
|
readonly source: {
|
|
@@ -396,7 +437,7 @@ export declare const routes: (Route<{
|
|
|
396
437
|
};
|
|
397
438
|
readonly cache_control?: {
|
|
398
439
|
readonly type: "ephemeral";
|
|
399
|
-
readonly ttl?:
|
|
440
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
400
441
|
} | undefined;
|
|
401
442
|
readonly title?: string | undefined;
|
|
402
443
|
readonly context?: string | undefined;
|
|
@@ -411,7 +452,7 @@ export declare const routes: (Route<{
|
|
|
411
452
|
readonly text: string;
|
|
412
453
|
readonly cache_control?: {
|
|
413
454
|
readonly type: "ephemeral";
|
|
414
|
-
readonly ttl?:
|
|
455
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
415
456
|
} | undefined;
|
|
416
457
|
} | {
|
|
417
458
|
readonly type: "image";
|
|
@@ -428,11 +469,28 @@ export declare const routes: (Route<{
|
|
|
428
469
|
};
|
|
429
470
|
readonly cache_control?: {
|
|
430
471
|
readonly type: "ephemeral";
|
|
431
|
-
readonly ttl?:
|
|
472
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
432
473
|
} | undefined;
|
|
433
474
|
readonly transformations?: {
|
|
434
475
|
readonly oversized_image?: "downsize" | "error" | undefined;
|
|
435
476
|
} | undefined;
|
|
477
|
+
} | {
|
|
478
|
+
readonly type: "video";
|
|
479
|
+
readonly source: {
|
|
480
|
+
readonly type: "base64";
|
|
481
|
+
readonly media_type: string;
|
|
482
|
+
readonly data: string;
|
|
483
|
+
} | {
|
|
484
|
+
readonly type: "url";
|
|
485
|
+
readonly url: string;
|
|
486
|
+
} | {
|
|
487
|
+
readonly type: "file";
|
|
488
|
+
readonly file_id: string;
|
|
489
|
+
};
|
|
490
|
+
readonly cache_control?: {
|
|
491
|
+
readonly type: "ephemeral";
|
|
492
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
493
|
+
} | undefined;
|
|
436
494
|
} | {
|
|
437
495
|
readonly type: "document";
|
|
438
496
|
readonly source: {
|
|
@@ -452,7 +510,7 @@ export declare const routes: (Route<{
|
|
|
452
510
|
};
|
|
453
511
|
readonly cache_control?: {
|
|
454
512
|
readonly type: "ephemeral";
|
|
455
|
-
readonly ttl?:
|
|
513
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
456
514
|
} | undefined;
|
|
457
515
|
readonly title?: string | undefined;
|
|
458
516
|
readonly context?: string | undefined;
|
|
@@ -463,7 +521,7 @@ export declare const routes: (Route<{
|
|
|
463
521
|
readonly is_error?: boolean | undefined;
|
|
464
522
|
readonly cache_control?: {
|
|
465
523
|
readonly type: "ephemeral";
|
|
466
|
-
readonly ttl?:
|
|
524
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
467
525
|
} | undefined;
|
|
468
526
|
})[];
|
|
469
527
|
} | {
|
|
@@ -476,7 +534,7 @@ export declare const routes: (Route<{
|
|
|
476
534
|
readonly text: string;
|
|
477
535
|
readonly cache_control?: {
|
|
478
536
|
readonly type: "ephemeral";
|
|
479
|
-
readonly ttl?:
|
|
537
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
480
538
|
} | undefined;
|
|
481
539
|
} | {
|
|
482
540
|
readonly type: "thinking";
|
|
@@ -484,14 +542,14 @@ export declare const routes: (Route<{
|
|
|
484
542
|
readonly signature: string;
|
|
485
543
|
readonly cache_control?: {
|
|
486
544
|
readonly type: "ephemeral";
|
|
487
|
-
readonly ttl?:
|
|
545
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
488
546
|
} | undefined;
|
|
489
547
|
} | {
|
|
490
548
|
readonly type: "redacted_thinking";
|
|
491
549
|
readonly data: string;
|
|
492
550
|
readonly cache_control?: {
|
|
493
551
|
readonly type: "ephemeral";
|
|
494
|
-
readonly ttl?:
|
|
552
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
495
553
|
} | undefined;
|
|
496
554
|
} | {
|
|
497
555
|
readonly type: "tool_use";
|
|
@@ -500,7 +558,7 @@ export declare const routes: (Route<{
|
|
|
500
558
|
readonly input: unknown;
|
|
501
559
|
readonly cache_control?: {
|
|
502
560
|
readonly type: "ephemeral";
|
|
503
|
-
readonly ttl?:
|
|
561
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
504
562
|
} | undefined;
|
|
505
563
|
} | {
|
|
506
564
|
readonly type: "server_tool_use";
|
|
@@ -509,7 +567,7 @@ export declare const routes: (Route<{
|
|
|
509
567
|
readonly input: unknown;
|
|
510
568
|
readonly cache_control?: {
|
|
511
569
|
readonly type: "ephemeral";
|
|
512
|
-
readonly ttl?:
|
|
570
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
513
571
|
} | undefined;
|
|
514
572
|
} | {
|
|
515
573
|
readonly type: "code_execution_tool_result" | "web_fetch_tool_result" | "web_search_tool_result";
|
|
@@ -517,7 +575,7 @@ export declare const routes: (Route<{
|
|
|
517
575
|
readonly content: unknown;
|
|
518
576
|
readonly cache_control?: {
|
|
519
577
|
readonly type: "ephemeral";
|
|
520
|
-
readonly ttl?:
|
|
578
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
521
579
|
} | undefined;
|
|
522
580
|
})[];
|
|
523
581
|
} | {
|
|
@@ -527,7 +585,7 @@ export declare const routes: (Route<{
|
|
|
527
585
|
readonly text: string;
|
|
528
586
|
readonly cache_control?: {
|
|
529
587
|
readonly type: "ephemeral";
|
|
530
|
-
readonly ttl?:
|
|
588
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
531
589
|
} | undefined;
|
|
532
590
|
}[];
|
|
533
591
|
readonly output_config?: {
|
|
@@ -542,7 +600,7 @@ export declare const routes: (Route<{
|
|
|
542
600
|
};
|
|
543
601
|
readonly cache_control?: {
|
|
544
602
|
readonly type: "ephemeral";
|
|
545
|
-
readonly ttl?:
|
|
603
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
546
604
|
} | undefined;
|
|
547
605
|
}[] | undefined;
|
|
548
606
|
readonly tool_choice?: {
|
|
@@ -570,7 +628,7 @@ export declare const routes: (Route<{
|
|
|
570
628
|
} | undefined;
|
|
571
629
|
readonly cache_control?: {
|
|
572
630
|
readonly type: "ephemeral";
|
|
573
|
-
readonly ttl?:
|
|
631
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
574
632
|
} | undefined;
|
|
575
633
|
readonly container?: string | {
|
|
576
634
|
readonly id?: string | null | undefined;
|
|
@@ -583,6 +641,7 @@ export declare const routes: (Route<{
|
|
|
583
641
|
readonly user_id?: string | null | undefined;
|
|
584
642
|
} | undefined;
|
|
585
643
|
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "standard_only"> | undefined;
|
|
644
|
+
readonly speed?: import("../schema/options.js").OpenString<"fast" | "standard"> | undefined;
|
|
586
645
|
readonly thinking?: {
|
|
587
646
|
readonly type: import("../schema/options.js").OpenString<"adaptive" | "disabled" | "enabled">;
|
|
588
647
|
} | undefined;
|
package/dist/providers/zai.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ProviderPackage } from "../provider-package.js";
|
|
|
2
2
|
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
3
3
|
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
4
4
|
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
5
|
-
import { type ModelID } from "../schema/index.js";
|
|
5
|
+
import { type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
6
6
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
7
|
export type ChatOptionsInput = ZAIChat.OptionsInput;
|
|
8
8
|
export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
@@ -23,6 +23,11 @@ export declare const routes: Route<{
|
|
|
23
23
|
readonly image_url: {
|
|
24
24
|
readonly url: string;
|
|
25
25
|
};
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "video_url";
|
|
28
|
+
readonly video_url: {
|
|
29
|
+
readonly url: string;
|
|
30
|
+
};
|
|
26
31
|
} | {
|
|
27
32
|
readonly type: "file";
|
|
28
33
|
readonly file: {
|
|
@@ -44,6 +49,11 @@ export declare const routes: Route<{
|
|
|
44
49
|
readonly image_url: {
|
|
45
50
|
readonly url: string;
|
|
46
51
|
};
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "video_url";
|
|
54
|
+
readonly video_url: {
|
|
55
|
+
readonly url: string;
|
|
56
|
+
};
|
|
47
57
|
} | {
|
|
48
58
|
readonly type: "file";
|
|
49
59
|
readonly file: {
|
|
@@ -125,7 +135,18 @@ export declare const routes: Route<{
|
|
|
125
135
|
} | undefined;
|
|
126
136
|
readonly store?: boolean | undefined;
|
|
127
137
|
readonly prompt_cache_key?: string | undefined;
|
|
138
|
+
readonly prompt_cache_retention?: string | undefined;
|
|
139
|
+
readonly prompt_cache_options?: {
|
|
140
|
+
readonly ttl?: string | undefined;
|
|
141
|
+
} | undefined;
|
|
128
142
|
readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
143
|
+
readonly verbosity?: import("../schema/options.js").OpenString<"high" | "low" | "medium"> | undefined;
|
|
144
|
+
readonly service_tier?: import("../schema/options.js").OpenString<"auto" | "default" | "flex" | "priority"> | undefined;
|
|
145
|
+
readonly parallel_tool_calls?: boolean | undefined;
|
|
146
|
+
readonly metadata?: {
|
|
147
|
+
readonly [x: string]: string;
|
|
148
|
+
} | undefined;
|
|
149
|
+
readonly safety_identifier?: string | undefined;
|
|
129
150
|
readonly tool_stream?: boolean | undefined;
|
|
130
151
|
readonly max_completion_tokens?: number | undefined;
|
|
131
152
|
readonly max_tokens?: number | undefined;
|
|
@@ -176,7 +197,7 @@ export declare const configure: (input?: Config) => {
|
|
|
176
197
|
readonly requestID?: string | undefined;
|
|
177
198
|
readonly userID?: string | undefined;
|
|
178
199
|
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
179
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
200
|
+
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
180
201
|
configure: typeof configure;
|
|
181
202
|
};
|
|
182
203
|
export declare const provider: {
|
|
@@ -209,10 +230,10 @@ export declare const provider: {
|
|
|
209
230
|
readonly requestID?: string | undefined;
|
|
210
231
|
readonly userID?: string | undefined;
|
|
211
232
|
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
212
|
-
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
233
|
+
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
213
234
|
configure: typeof configure;
|
|
214
235
|
};
|
|
215
|
-
export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
236
|
+
export declare const image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
216
237
|
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
217
238
|
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
218
239
|
readonly thinking?: {
|
|
@@ -228,4 +249,5 @@ export declare const chat: (modelID: string | ModelID) => import("../schema/opti
|
|
|
228
249
|
readonly userID?: string | undefined;
|
|
229
250
|
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
230
251
|
export declare const model: ProviderPackage.Definition<Settings, ChatOptionsInput>["model"];
|
|
252
|
+
export declare const imageModel: (modelID: string, settings: Settings) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
231
253
|
export * as ZAI from "./zai.js";
|
package/dist/providers/zai.js
CHANGED
|
@@ -27,7 +27,7 @@ export const configure = (input = {}) => {
|
|
|
27
27
|
})
|
|
28
28
|
.model({ id: modelID, compatibility: ZAIChat.compatibility });
|
|
29
29
|
const media = MediaRoute.deployment(input, auth(input));
|
|
30
|
-
const image = (modelID) => ZAIImages.model({ ...media, id: modelID });
|
|
30
|
+
const image = (modelID, providerOptions) => ZAIImages.model({ ...media, id: modelID, providerOptions });
|
|
31
31
|
return {
|
|
32
32
|
id,
|
|
33
33
|
model: chat,
|
|
@@ -39,11 +39,18 @@ export const configure = (input = {}) => {
|
|
|
39
39
|
export const provider = configure();
|
|
40
40
|
export const image = provider.image;
|
|
41
41
|
export const chat = provider.chat;
|
|
42
|
-
export const model = (modelID,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
export const model = (modelID, settings) => configure(config(settings)).model(modelID);
|
|
43
|
+
export const imageModel = (modelID, settings) => {
|
|
44
|
+
const input = config(settings);
|
|
45
|
+
return configure(input).image(modelID, input.providerOptions);
|
|
46
|
+
};
|
|
47
|
+
function config({ apiKey, baseURL, body, headers, ...providerOptions }) {
|
|
48
|
+
return {
|
|
49
|
+
apiKey,
|
|
50
|
+
baseURL,
|
|
51
|
+
headers,
|
|
52
|
+
http: body === undefined ? undefined : { body },
|
|
53
|
+
providerOptions,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
49
56
|
export * as ZAI from "./zai.js";
|
package/dist/route/client.d.ts
CHANGED
|
@@ -193,7 +193,7 @@ export declare function make<Body, Prepared, Frame, Event, State>(input: MakeTra
|
|
|
193
193
|
* the public surface preemptively.
|
|
194
194
|
*/
|
|
195
195
|
export declare function make<Body, Frame, Event, State>(input: MakeInput<Body, Frame, Event, State>): Route<Body, HttpTransport.HttpPrepared<Frame>>;
|
|
196
|
-
/**
|
|
196
|
+
/** Test-only projection of the execution compiler; exported from `@opencode/ai/testing`. */
|
|
197
197
|
export declare const compileRequest: (request: LLMRequest<LanguageModel<{
|
|
198
198
|
readonly [x: string]: unknown;
|
|
199
199
|
}, CompactionOperations | undefined>>) => Effect.Effect<{
|
|
@@ -220,7 +220,7 @@ export declare const LLMClient: {
|
|
|
220
220
|
readonly canCompact: typeof canCompact;
|
|
221
221
|
readonly compact: typeof compact;
|
|
222
222
|
readonly Service: typeof LLMClientService;
|
|
223
|
-
readonly layer: Layer.Layer<LLMClientService, never,
|
|
223
|
+
readonly layer: Layer.Layer<LLMClientService, never, RequestExecutor.RequestExecutorService>;
|
|
224
224
|
readonly stream: typeof stream;
|
|
225
225
|
readonly generate: typeof generate;
|
|
226
226
|
};
|
package/dist/route/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cause, Context, Effect, Layer, Schema, Stream } from "effect";
|
|
1
|
+
import { Cause, Context, Effect, Layer, Option, Schema, Stream } from "effect";
|
|
2
2
|
import { Auth } from "./auth.js";
|
|
3
3
|
import { Endpoint } from "./endpoint.js";
|
|
4
4
|
import { RequestExecutor } from "./executor.js";
|
|
@@ -91,13 +91,22 @@ const incompleteStreamError = (route) => new AIError({
|
|
|
91
91
|
const requireTerminalEvent = (route) => (events) => Stream.suspend(() => {
|
|
92
92
|
let terminal = false;
|
|
93
93
|
return events.pipe(Stream.mapEffect((event) => {
|
|
94
|
-
|
|
94
|
+
// Raw events carry provider frames that may trail the terminal event.
|
|
95
|
+
if (terminal && !LLMEvent.is.raw(event))
|
|
95
96
|
return Effect.fail(ProviderShared.eventError(route, `Provider emitted ${event.type} after the terminal event`));
|
|
96
97
|
if (LLMEvent.is.finish(event) || LLMEvent.is.providerError(event))
|
|
97
98
|
terminal = true;
|
|
98
99
|
return Effect.succeed(event);
|
|
99
100
|
}), Stream.onEnd(Effect.suspend(() => (terminal ? Effect.void : Effect.fail(incompleteStreamError(route))))));
|
|
100
101
|
});
|
|
102
|
+
const decodeJsonOption = Schema.decodeUnknownOption(ProviderShared.Json);
|
|
103
|
+
// JSON text frames are parsed; non-JSON sentinels such as `[DONE]` stay strings.
|
|
104
|
+
const rawFrame = (frame) => typeof frame === "string" ? Option.getOrElse(decodeJsonOption(frame), () => frame) : frame;
|
|
105
|
+
// Transports may interleave their own marker objects with provider frames, e.g. Gemini's continuation boundary.
|
|
106
|
+
const isProviderFrame = (frame) => typeof frame !== "object" ||
|
|
107
|
+
frame === null ||
|
|
108
|
+
Array.isArray(frame) ||
|
|
109
|
+
Object.getPrototypeOf(frame) === Object.prototype;
|
|
101
110
|
function makeFromTransport(input) {
|
|
102
111
|
const protocol = input.protocol;
|
|
103
112
|
const decodeEventEffect = Schema.decodeUnknownEffect(protocol.stream.event);
|
|
@@ -165,7 +174,9 @@ function makeFromTransport(input) {
|
|
|
165
174
|
let state = protocol.stream.initial(request);
|
|
166
175
|
const parsed = events.pipe(Stream.mapEffect(({ event, frame }) => protocol.stream.step(state, event).pipe(Effect.catchCause((cause) => Effect.fail(streamError(route, `Failed to parse ${route} event`, cause))), Effect.map(([next, output]) => {
|
|
167
176
|
state = next;
|
|
168
|
-
return
|
|
177
|
+
return request.includeRaw && isProviderFrame(frame)
|
|
178
|
+
? [LLMEvent.raw({ data: execution.raw?.(frame) ?? rawFrame(frame) }), ...output]
|
|
179
|
+
: output;
|
|
169
180
|
}), Effect.mapError(frameError(frame, event)))), Stream.flatMap(Stream.fromIterable));
|
|
170
181
|
const onHalt = protocol.stream.onHalt;
|
|
171
182
|
return onHalt
|
|
@@ -216,6 +227,17 @@ const prepareRequest = (request) => {
|
|
|
216
227
|
: LLMRequest.update(resolved, { http: mergeHttpOptions(new HttpOptions({ headers }), resolved.http) });
|
|
217
228
|
};
|
|
218
229
|
const compile = Effect.fn("LLM.compile")(function* (request, options) {
|
|
230
|
+
const references = request.messages.flatMap((message) => message.content.flatMap((part) => {
|
|
231
|
+
if (part.type === "media") {
|
|
232
|
+
const source = part.media.source;
|
|
233
|
+
return source.type === "url" ? [source.url] : source.type === "ref" ? [source.id] : [];
|
|
234
|
+
}
|
|
235
|
+
if (part.type !== "tool-result" || part.result.type !== "content")
|
|
236
|
+
return [];
|
|
237
|
+
return part.result.value.flatMap((item) => (item.type === "file" ? [item.uri] : []));
|
|
238
|
+
}));
|
|
239
|
+
if (references.some((reference) => /^\s*file:/i.test(reference)))
|
|
240
|
+
return yield* ProviderShared.invalidRequest("Local file references must be read with Media.file(path) before sending");
|
|
219
241
|
const resolved = prepareRequest(request);
|
|
220
242
|
const route = resolved.model.route;
|
|
221
243
|
const body = yield* route.body.from(resolved);
|
|
@@ -227,7 +249,7 @@ const compile = Effect.fn("LLM.compile")(function* (request, options) {
|
|
|
227
249
|
prepared,
|
|
228
250
|
};
|
|
229
251
|
});
|
|
230
|
-
/**
|
|
252
|
+
/** Test-only projection of the execution compiler; exported from `@opencode/ai/testing`. */
|
|
231
253
|
export const compileRequest = Effect.fn("LLM.compileRequest")(function* (request) {
|
|
232
254
|
const compiled = yield* compile(request);
|
|
233
255
|
return {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { HttpClientResponse } from "effect/http";
|
|
3
|
+
import { DecisionModel, DecisionModelCompatibility, type DecisionOptions, type DecisionRequestFor, type DecisionResponse } from "../decision.js";
|
|
4
|
+
import { HttpOptions, ProviderID, type AIError, type ProviderOptions } from "../schema/index.js";
|
|
5
|
+
import { Auth } from "./auth.js";
|
|
6
|
+
import { Endpoint } from "./endpoint.js";
|
|
7
|
+
import { MediaProtocol } from "./media-protocol.js";
|
|
8
|
+
/** One decision API: how a request becomes its JSON body and how its response becomes a `DecisionResponse`. */
|
|
9
|
+
export interface Protocol {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/** The host only takes inline data, so URL media is downloaded before `body.from`. */
|
|
13
|
+
readonly inlineMedia?: boolean;
|
|
14
|
+
readonly body: {
|
|
15
|
+
readonly from: (request: DecisionRequestFor) => Effect.Effect<Record<string, unknown>, AIError>;
|
|
16
|
+
};
|
|
17
|
+
readonly response: {
|
|
18
|
+
readonly decode: (response: HttpClientResponse.HttpClientResponse, context: {
|
|
19
|
+
readonly request: DecisionRequestFor;
|
|
20
|
+
readonly providerMetadataKey: string;
|
|
21
|
+
}) => Effect.Effect<DecisionResponse, AIError>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare const protocol: (input: Protocol) => Protocol;
|
|
25
|
+
export interface Patch {
|
|
26
|
+
readonly id?: string;
|
|
27
|
+
readonly provider?: string | ProviderID;
|
|
28
|
+
/** ProviderMetadata namespace for responses; defaults to the provider. */
|
|
29
|
+
readonly providerMetadataKey?: string;
|
|
30
|
+
readonly endpoint?: Endpoint.EndpointPatch<MediaProtocol.Body, DecisionRequestFor>;
|
|
31
|
+
readonly auth?: Auth.Definition;
|
|
32
|
+
readonly headers?: Record<string, string>;
|
|
33
|
+
readonly http?: HttpOptions.Input;
|
|
34
|
+
}
|
|
35
|
+
export interface Route {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly provider: ProviderID;
|
|
38
|
+
readonly providerMetadataKey: string;
|
|
39
|
+
readonly protocol: Protocol;
|
|
40
|
+
readonly endpoint: Endpoint.Definition<MediaProtocol.Body, DecisionRequestFor>;
|
|
41
|
+
readonly auth: Auth.Definition;
|
|
42
|
+
readonly headers?: Record<string, string>;
|
|
43
|
+
readonly http?: HttpOptions;
|
|
44
|
+
readonly with: (patch: Patch) => Route;
|
|
45
|
+
readonly model: <Options extends DecisionOptions = DecisionOptions>(input: {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly compatibility?: DecisionModelCompatibility.Input;
|
|
48
|
+
readonly providerOptions?: ProviderOptions;
|
|
49
|
+
}) => DecisionModel<Options>;
|
|
50
|
+
}
|
|
51
|
+
export interface MakeInput extends Omit<Patch, "endpoint"> {
|
|
52
|
+
readonly id: string;
|
|
53
|
+
readonly provider: string | ProviderID;
|
|
54
|
+
readonly protocol: Protocol;
|
|
55
|
+
readonly endpoint: Endpoint.Definition<MediaProtocol.Body, DecisionRequestFor>;
|
|
56
|
+
}
|
|
57
|
+
export declare const make: (input: MakeInput) => Route;
|
|
58
|
+
export * as DecisionRoute from "./decision.js";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { DecisionModel, DecisionModelCompatibility, } from "../decision.js";
|
|
3
|
+
import { HttpOptions, ProviderID } from "../schema/index.js";
|
|
4
|
+
import { Auth } from "./auth.js";
|
|
5
|
+
import { Endpoint } from "./endpoint.js";
|
|
6
|
+
import { RequestExecutorService } from "./executor-service.js";
|
|
7
|
+
import { MediaProtocol } from "./media-protocol.js";
|
|
8
|
+
import { MediaRoute } from "./media.js";
|
|
9
|
+
export const protocol = (input) => input;
|
|
10
|
+
export const make = (input) => {
|
|
11
|
+
const provider = ProviderID.make(input.provider);
|
|
12
|
+
const route = {
|
|
13
|
+
id: input.id,
|
|
14
|
+
provider,
|
|
15
|
+
providerMetadataKey: input.providerMetadataKey ?? provider,
|
|
16
|
+
protocol: input.protocol,
|
|
17
|
+
endpoint: input.endpoint,
|
|
18
|
+
auth: input.auth ?? Auth.none,
|
|
19
|
+
headers: input.headers,
|
|
20
|
+
http: HttpOptions.make(input.http),
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
...route,
|
|
24
|
+
with: (patch) => make({
|
|
25
|
+
...route,
|
|
26
|
+
...patch,
|
|
27
|
+
// A new provider gets its own metadata key unless the patch names one.
|
|
28
|
+
providerMetadataKey: patch.providerMetadataKey ?? (patch.provider === undefined ? route.providerMetadataKey : undefined),
|
|
29
|
+
endpoint: patch.endpoint === undefined ? route.endpoint : Endpoint.merge(route.endpoint, patch.endpoint),
|
|
30
|
+
headers: patch.headers === undefined ? route.headers : { ...route.headers, ...patch.headers },
|
|
31
|
+
http: patch.http === undefined ? route.http : HttpOptions.make(patch.http),
|
|
32
|
+
}),
|
|
33
|
+
model: (model) => {
|
|
34
|
+
const send = transport(route);
|
|
35
|
+
return DecisionModel.make({
|
|
36
|
+
id: model.id,
|
|
37
|
+
provider,
|
|
38
|
+
http: route.http,
|
|
39
|
+
providerOptions: model.providerOptions,
|
|
40
|
+
compatibility: model.compatibility === undefined ? undefined : DecisionModelCompatibility.make(model.compatibility),
|
|
41
|
+
route: { id: route.id, generate: send },
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
// The HTTP plumbing (URL, query, auth, headers, `http` overlays, surrogate sanitizing) is the one media routes use.
|
|
47
|
+
const transport = (route) => {
|
|
48
|
+
const identity = MediaProtocol.identity({ id: route.id, name: route.protocol.name, provider: route.provider });
|
|
49
|
+
const composed = MediaRoute.inline({
|
|
50
|
+
protocol: MediaProtocol.inline(identity, {
|
|
51
|
+
body: {
|
|
52
|
+
from: (request) => route.protocol.body.from(request).pipe(Effect.map((body) => MediaProtocol.json(body))),
|
|
53
|
+
},
|
|
54
|
+
response: {
|
|
55
|
+
decode: (response, context) => route.protocol.response.decode(response, {
|
|
56
|
+
request: context.request,
|
|
57
|
+
providerMetadataKey: route.providerMetadataKey,
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
endpoint: route.endpoint,
|
|
62
|
+
auth: route.auth,
|
|
63
|
+
headers: route.headers,
|
|
64
|
+
});
|
|
65
|
+
return Effect.fnUntraced(function* (request, execute) {
|
|
66
|
+
if (!route.protocol.inlineMedia)
|
|
67
|
+
return yield* composed.generate(request, execute);
|
|
68
|
+
const input = yield* Effect.forEach(request.input, (part) => materialize(part, execute));
|
|
69
|
+
return yield* composed.generate({ ...request, input }, execute);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const materialize = (part, execute) => part.type === "media" && part.media.source.type === "url"
|
|
73
|
+
? part.media.materialize().pipe(Effect.provideService(RequestExecutorService, { execute }), Effect.map((media) => ({ ...part, media })))
|
|
74
|
+
: Effect.succeed(part);
|
|
75
|
+
export * as DecisionRoute from "./decision.js";
|
package/dist/route/executor.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
|
|
|
3
3
|
import { AIError } from "../schema/index.js";
|
|
4
4
|
import { Service, type HttpMiddleware, type Interface } from "./executor-service.js";
|
|
5
5
|
export { responseHttp, Service } from "./executor-service.js";
|
|
6
|
-
export type { HttpHandler, HttpMiddleware, Interface } from "./executor-service.js";
|
|
6
|
+
export type { HttpHandler, HttpMiddleware, Interface, RequestExecutorService } from "./executor-service.js";
|
|
7
7
|
/** Preserve HTTP diagnostics for executor and externally captured failures alike. */
|
|
8
8
|
export declare const httpFailure: (input: {
|
|
9
9
|
readonly message: string;
|
package/dist/route/framing.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface Definition<Frame> {
|
|
|
21
21
|
readonly frame: (bytes: Stream.Stream<Uint8Array, AIError>) => Stream.Stream<Frame, AIError>;
|
|
22
22
|
/** Original wire representation when framing transforms the provider payload. */
|
|
23
23
|
readonly body?: (frame: Frame) => string | undefined;
|
|
24
|
+
/** Provider value exposed as a `raw` event when framing adds fields of its own. Defaults to the frame. */
|
|
25
|
+
readonly raw?: (frame: Frame) => unknown;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* `framing` step for Server-Sent Events. Decodes UTF-8, runs the SSE channel
|
package/dist/route/index.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export { Framing } from "./framing.js";
|
|
|
10
10
|
export { Protocol } from "./protocol.js";
|
|
11
11
|
export { HttpTransport, WebSocketTransport } from "./transport/index.js";
|
|
12
12
|
export * as Transport from "./transport/index.js";
|
|
13
|
+
export { ProviderShared } from "../protocols/shared.js";
|
|
14
|
+
export { classifyProviderFailure } from "../provider-error.js";
|
|
15
|
+
export { mergeHttpOptions } from "../schema/index.js";
|
|
13
16
|
export type { Definition as AuthShape, AuthInput, Credential, CredentialError } from "./auth.js";
|
|
14
17
|
export type { ApiKeyMode, AuthOverride, ProviderAuthOption } from "./auth-options.js";
|
|
15
18
|
export type { Definition as EndpointFn, EndpointInput } from "./endpoint.js";
|
package/dist/route/index.js
CHANGED
|
@@ -9,3 +9,6 @@ export { Framing } from "./framing.js";
|
|
|
9
9
|
export { Protocol } from "./protocol.js";
|
|
10
10
|
export { HttpTransport, WebSocketTransport } from "./transport/index.js";
|
|
11
11
|
export * as Transport from "./transport/index.js";
|
|
12
|
+
export { ProviderShared } from "../protocols/shared.js";
|
|
13
|
+
export { classifyProviderFailure } from "../provider-error.js";
|
|
14
|
+
export { mergeHttpOptions } from "../schema/index.js";
|
|
@@ -153,6 +153,7 @@ export declare const identity: (input: {
|
|
|
153
153
|
pending: (id: string) => AIError;
|
|
154
154
|
contentPolicy: (message: string) => AIError;
|
|
155
155
|
}, AIError, never>;
|
|
156
|
+
bytes: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<Uint8Array<ArrayBuffer>, AIError, never>;
|
|
156
157
|
decodeJson: <A>(schema: Schema.Codec<A, unknown>) => (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<{
|
|
157
158
|
body: string;
|
|
158
159
|
http: HttpContext;
|