@opencode/ai 2.1.3 → 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 +13 -22
- package/dist/image-client.js +0 -1
- package/dist/image.d.ts +154 -324
- 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 +32 -12
- package/dist/protocols/alibaba-images.d.ts +22 -0
- package/dist/protocols/alibaba-images.js +77 -0
- package/dist/protocols/alibaba-messages.d.ts +62 -27
- package/dist/protocols/alibaba-responses.d.ts +41 -38
- package/dist/protocols/anthropic-messages.d.ts +196 -94
- package/dist/protocols/anthropic-messages.js +47 -16
- package/dist/protocols/bedrock-converse.d.ts +140 -47
- package/dist/protocols/bedrock-converse.js +114 -18
- 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 +32 -50
- 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/cohere-chat.d.ts +7 -8
- package/dist/protocols/deepgram-speech.d.ts +32 -50
- package/dist/protocols/elevenlabs-speech.d.ts +32 -50
- 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 +37 -34
- package/dist/protocols/gemini.js +13 -8
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-images.js +8 -37
- package/dist/protocols/google-interactions.d.ts +18 -14
- package/dist/protocols/google-interactions.js +14 -7
- package/dist/protocols/google-speech.d.ts +32 -50
- package/dist/protocols/google-speech.js +0 -1
- package/dist/protocols/google-transcription.d.ts +32 -50
- 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 +73 -38
- package/dist/protocols/meta-messages.js +14 -1
- package/dist/protocols/meta-responses.d.ts +84 -78
- package/dist/protocols/meta-responses.js +29 -1
- package/dist/protocols/mistral-chat.d.ts +81 -78
- package/dist/protocols/mistral-chat.js +2 -1
- package/dist/protocols/open-responses-channel.js +47 -46
- package/dist/protocols/open-responses-continuation.d.ts +8 -2
- package/dist/protocols/open-responses-continuation.js +3 -1
- package/dist/protocols/open-responses.d.ts +426 -396
- package/dist/protocols/open-responses.js +16 -25
- package/dist/protocols/openai-chat.d.ts +764 -52
- package/dist/protocols/openai-chat.js +38 -25
- package/dist/protocols/openai-compatible-chat.d.ts +35 -15
- package/dist/protocols/openai-compatible-responses.d.ts +44 -42
- package/dist/protocols/openai-decisions.d.ts +22 -0
- package/dist/protocols/openai-decisions.js +128 -0
- package/dist/protocols/openai-images.d.ts +53 -56
- package/dist/protocols/openai-images.js +100 -34
- package/dist/protocols/openai-responses.d.ts +322 -264
- package/dist/protocols/openai-responses.js +33 -3
- package/dist/protocols/openai-speech.d.ts +32 -50
- package/dist/protocols/openai-speech.js +15 -5
- package/dist/protocols/openai-transcription.d.ts +32 -50
- package/dist/protocols/openai-transcription.js +15 -11
- 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/partial-json-options.d.ts +0 -1
- package/dist/protocols/utils/partial-json-options.js +0 -1
- 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 +10 -1
- package/dist/protocols/venice-chat.d.ts +71 -53
- package/dist/protocols/venice-chat.js +7 -6
- package/dist/protocols/xai-images.d.ts +1 -2
- package/dist/protocols/xai-images.js +9 -2
- package/dist/protocols/xai-responses.d.ts +88 -78
- 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 +54 -30
- package/dist/protocols/zai-chat.js +8 -3
- package/dist/protocols/zai-images.d.ts +3 -1
- package/dist/protocols/zai-images.js +12 -11
- package/dist/protocols/zai-messages.d.ts +72 -35
- package/dist/protocols/zai-messages.js +3 -2
- package/dist/provider-error.js +24 -7
- package/dist/providers/alibaba/images.d.ts +2 -0
- package/dist/providers/alibaba/images.js +1 -0
- package/dist/providers/alibaba.d.ts +146 -85
- package/dist/providers/alibaba.js +16 -8
- package/dist/providers/amazon-bedrock-mantle.d.ts +277 -218
- package/dist/providers/amazon-bedrock.d.ts +48 -28
- package/dist/providers/amazon-bedrock.js +11 -11
- package/dist/providers/anthropic-compatible.d.ts +64 -29
- package/dist/providers/anthropic.d.ts +64 -29
- package/dist/providers/azure/images.d.ts +2 -0
- package/dist/providers/azure/images.js +1 -0
- package/dist/providers/azure.d.ts +156 -115
- 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 +75 -25
- package/dist/providers/baseten.js +41 -8
- package/dist/providers/cerebras.d.ts +66 -24
- 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 +409 -272
- package/dist/providers/cloudflare-ai-gateway.js +33 -6
- 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 +79 -25
- package/dist/providers/cloudflare-workers-ai.js +45 -9
- package/dist/providers/cohere.d.ts +117 -75
- package/dist/providers/deepinfra.d.ts +66 -24
- package/dist/providers/deepseek.d.ts +66 -24
- 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 +108 -37
- package/dist/providers/digitalocean.js +39 -8
- package/dist/providers/fireworks.d.ts +66 -24
- 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 +33 -12
- package/dist/providers/google-vertex-messages.d.ts +64 -29
- package/dist/providers/google-vertex-mistral.d.ts +17 -17
- package/dist/providers/google-vertex-responses.d.ts +38 -35
- package/dist/providers/google-vertex.d.ts +20 -18
- package/dist/providers/google-vertex.js +32 -15
- package/dist/providers/google.d.ts +22 -21
- package/dist/providers/google.js +15 -8
- package/dist/providers/groq.d.ts +66 -28
- package/dist/providers/groq.js +0 -6
- package/dist/providers/meta.d.ts +144 -85
- package/dist/providers/minimax.d.ts +145 -86
- package/dist/providers/mistral.d.ts +28 -28
- package/dist/providers/moonshot.d.ts +277 -218
- package/dist/providers/open-responses-options.d.ts +0 -1
- package/dist/providers/open-responses-options.js +1 -1
- 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 +38 -35
- package/dist/providers/openai-compatible.d.ts +36 -13
- package/dist/providers/openai-compatible.js +22 -10
- package/dist/providers/openai-options.d.ts +3 -2
- package/dist/providers/openai-options.js +0 -1
- package/dist/providers/openai.d.ts +146 -109
- 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 +128 -47
- package/dist/providers/openrouter.js +38 -16
- package/dist/providers/togetherai.d.ts +66 -24
- 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 +214 -20
- 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 +40 -17
- 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 +224 -85
- package/dist/providers/zai.d.ts +110 -23
- package/dist/providers/zai.js +15 -8
- package/dist/route/auth-options.d.ts +0 -3
- package/dist/route/auth.d.ts +0 -2
- package/dist/route/auth.js +0 -2
- package/dist/route/client.d.ts +2 -4
- package/dist/route/client.js +29 -8
- package/dist/route/decision.d.ts +58 -0
- package/dist/route/decision.js +75 -0
- package/dist/route/executor-service.js +1 -1
- 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 +13 -22
- package/dist/speech-client.js +0 -1
- package/dist/speech.d.ts +148 -283
- 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 +13 -22
- package/dist/transcription.d.ts +148 -283
- package/dist/transcription.js +1 -1
- package/dist/utils/media-type.js +22 -1
- package/dist/video-client.d.ts +13 -22
- package/dist/video-client.js +0 -1
- package/dist/video.d.ts +115 -250
- package/dist/video.js +3 -5
- package/package.json +516 -13
- 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 -115
- 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
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"> & {
|
|
@@ -19,44 +19,54 @@ export declare const routes: Route<{
|
|
|
19
19
|
readonly messages: readonly ({
|
|
20
20
|
readonly role: "system";
|
|
21
21
|
readonly content: string | readonly ({
|
|
22
|
-
readonly type: "text";
|
|
23
|
-
readonly text: string;
|
|
24
|
-
readonly cache_control?: {
|
|
25
|
-
readonly type: "ephemeral";
|
|
26
|
-
readonly ttl?: string | undefined;
|
|
27
|
-
} | undefined;
|
|
28
|
-
} | {
|
|
29
22
|
readonly type: "image_url";
|
|
30
23
|
readonly image_url: {
|
|
31
24
|
readonly url: string;
|
|
32
25
|
};
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "video_url";
|
|
28
|
+
readonly video_url: {
|
|
29
|
+
readonly url: string;
|
|
30
|
+
};
|
|
33
31
|
} | {
|
|
34
32
|
readonly type: "file";
|
|
35
33
|
readonly file: {
|
|
36
34
|
readonly filename: string;
|
|
37
35
|
readonly file_data: string;
|
|
38
36
|
};
|
|
39
|
-
}
|
|
40
|
-
} | {
|
|
41
|
-
readonly role: "user";
|
|
42
|
-
readonly content: string | readonly ({
|
|
37
|
+
} | {
|
|
43
38
|
readonly type: "text";
|
|
44
39
|
readonly text: string;
|
|
45
40
|
readonly cache_control?: {
|
|
46
41
|
readonly type: "ephemeral";
|
|
47
42
|
readonly ttl?: string | undefined;
|
|
48
43
|
} | undefined;
|
|
49
|
-
}
|
|
44
|
+
})[];
|
|
45
|
+
} | {
|
|
46
|
+
readonly role: "user";
|
|
47
|
+
readonly content: string | readonly ({
|
|
50
48
|
readonly type: "image_url";
|
|
51
49
|
readonly image_url: {
|
|
52
50
|
readonly url: string;
|
|
53
51
|
};
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "video_url";
|
|
54
|
+
readonly video_url: {
|
|
55
|
+
readonly url: string;
|
|
56
|
+
};
|
|
54
57
|
} | {
|
|
55
58
|
readonly type: "file";
|
|
56
59
|
readonly file: {
|
|
57
60
|
readonly filename: string;
|
|
58
61
|
readonly file_data: string;
|
|
59
62
|
};
|
|
63
|
+
} | {
|
|
64
|
+
readonly type: "text";
|
|
65
|
+
readonly text: string;
|
|
66
|
+
readonly cache_control?: {
|
|
67
|
+
readonly type: "ephemeral";
|
|
68
|
+
readonly ttl?: string | undefined;
|
|
69
|
+
} | undefined;
|
|
60
70
|
})[];
|
|
61
71
|
} | {
|
|
62
72
|
readonly role: "tool";
|
|
@@ -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;
|
|
@@ -136,31 +157,97 @@ export declare const routes: Route<{
|
|
|
136
157
|
readonly seed?: number | undefined;
|
|
137
158
|
readonly stop?: readonly string[] | undefined;
|
|
138
159
|
readonly thinking?: {
|
|
139
|
-
readonly type?:
|
|
160
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
140
161
|
readonly clear_thinking?: boolean | undefined;
|
|
141
162
|
} | undefined;
|
|
142
163
|
readonly do_sample?: boolean | undefined;
|
|
143
164
|
readonly response_format?: {
|
|
144
|
-
readonly type:
|
|
165
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
145
166
|
} | undefined;
|
|
146
167
|
readonly request_id?: string | undefined;
|
|
147
168
|
readonly user_id?: string | undefined;
|
|
148
169
|
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
|
|
149
170
|
export declare const configure: (input?: Config) => {
|
|
150
171
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
151
|
-
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<
|
|
152
|
-
|
|
153
|
-
|
|
172
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
173
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
174
|
+
readonly thinking?: {
|
|
175
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
176
|
+
readonly clear_thinking?: boolean | undefined;
|
|
177
|
+
} | undefined;
|
|
178
|
+
readonly toolStream?: boolean | undefined;
|
|
179
|
+
readonly doSample?: boolean | undefined;
|
|
180
|
+
readonly responseFormat?: {
|
|
181
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
182
|
+
} | undefined;
|
|
183
|
+
readonly requestID?: string | undefined;
|
|
184
|
+
readonly userID?: string | undefined;
|
|
185
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
186
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
187
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
188
|
+
readonly thinking?: {
|
|
189
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
190
|
+
readonly clear_thinking?: boolean | undefined;
|
|
191
|
+
} | undefined;
|
|
192
|
+
readonly toolStream?: boolean | undefined;
|
|
193
|
+
readonly doSample?: boolean | undefined;
|
|
194
|
+
readonly responseFormat?: {
|
|
195
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
196
|
+
} | undefined;
|
|
197
|
+
readonly requestID?: string | undefined;
|
|
198
|
+
readonly userID?: string | undefined;
|
|
199
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
200
|
+
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
154
201
|
configure: typeof configure;
|
|
155
202
|
};
|
|
156
203
|
export declare const provider: {
|
|
157
204
|
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
158
|
-
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<
|
|
159
|
-
|
|
160
|
-
|
|
205
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
206
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
207
|
+
readonly thinking?: {
|
|
208
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
209
|
+
readonly clear_thinking?: boolean | undefined;
|
|
210
|
+
} | undefined;
|
|
211
|
+
readonly toolStream?: boolean | undefined;
|
|
212
|
+
readonly doSample?: boolean | undefined;
|
|
213
|
+
readonly responseFormat?: {
|
|
214
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
215
|
+
} | undefined;
|
|
216
|
+
readonly requestID?: string | undefined;
|
|
217
|
+
readonly userID?: string | undefined;
|
|
218
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
219
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
220
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
221
|
+
readonly thinking?: {
|
|
222
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
223
|
+
readonly clear_thinking?: boolean | undefined;
|
|
224
|
+
} | undefined;
|
|
225
|
+
readonly toolStream?: boolean | undefined;
|
|
226
|
+
readonly doSample?: boolean | undefined;
|
|
227
|
+
readonly responseFormat?: {
|
|
228
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
229
|
+
} | undefined;
|
|
230
|
+
readonly requestID?: string | undefined;
|
|
231
|
+
readonly userID?: string | undefined;
|
|
232
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
233
|
+
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
161
234
|
configure: typeof configure;
|
|
162
235
|
};
|
|
163
|
-
export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
164
|
-
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<
|
|
236
|
+
export declare const image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
237
|
+
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
238
|
+
readonly reasoningEffort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
239
|
+
readonly thinking?: {
|
|
240
|
+
readonly type?: import("../schema/options.js").OpenString<"disabled" | "enabled"> | undefined;
|
|
241
|
+
readonly clear_thinking?: boolean | undefined;
|
|
242
|
+
} | undefined;
|
|
243
|
+
readonly toolStream?: boolean | undefined;
|
|
244
|
+
readonly doSample?: boolean | undefined;
|
|
245
|
+
readonly responseFormat?: {
|
|
246
|
+
readonly type: import("../schema/options.js").OpenString<"json_object" | "text">;
|
|
247
|
+
} | undefined;
|
|
248
|
+
readonly requestID?: string | undefined;
|
|
249
|
+
readonly userID?: string | undefined;
|
|
250
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
165
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>;
|
|
166
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";
|
|
@@ -14,9 +14,6 @@ export type RequiredApiKeyAuth = {
|
|
|
14
14
|
readonly auth?: never;
|
|
15
15
|
};
|
|
16
16
|
export type ProviderAuthOption<Mode extends ApiKeyMode> = AuthOverride | (Mode extends "optional" ? OptionalApiKeyAuth : RequiredApiKeyAuth);
|
|
17
|
-
export type LanguageModelOptions<Base, Mode extends ApiKeyMode> = Omit<Base, "apiKey" | "auth"> & ProviderAuthOption<Mode>;
|
|
18
|
-
export type LanguageModelArgs<Base, Mode extends ApiKeyMode> = Mode extends "optional" ? readonly [options?: LanguageModelOptions<Base, Mode>] : readonly [options: LanguageModelOptions<Base, Mode>];
|
|
19
|
-
export type LanguageModelFactory<Base, Mode extends ApiKeyMode, LanguageModel> = (id: string, ...args: LanguageModelArgs<Base, Mode>) => LanguageModel;
|
|
20
17
|
/**
|
|
21
18
|
* Require at least one of the keys in `T`. Use for option shapes where any
|
|
22
19
|
* subset of fields is acceptable but at least one must be present (e.g. Azure
|
package/dist/route/auth.d.ts
CHANGED
|
@@ -31,7 +31,6 @@ export interface Definition {
|
|
|
31
31
|
readonly orElse: (that: Definition) => Definition;
|
|
32
32
|
readonly pipe: <A>(f: (self: Definition) => A) => A;
|
|
33
33
|
}
|
|
34
|
-
export declare const isAuth: (input: unknown) => input is Definition;
|
|
35
34
|
export declare const value: (secret: string, source?: string) => Credential;
|
|
36
35
|
export declare const optional: (secret: Secret | undefined, source?: string) => Credential;
|
|
37
36
|
export declare const config: (name: string) => Credential;
|
|
@@ -42,7 +41,6 @@ export declare const remove: (name: string) => Definition;
|
|
|
42
41
|
export declare const custom: (apply: (input: AuthInput) => Effect.Effect<Headers.Headers, AIError>) => Definition;
|
|
43
42
|
export declare const passthrough: Definition;
|
|
44
43
|
export declare function bearer(source: Secret | Credential): Definition;
|
|
45
|
-
export declare const apiKey: typeof bearer;
|
|
46
44
|
export declare function header(name: string): (source: Secret | Credential) => Definition;
|
|
47
45
|
export declare function header(name: string, source: Secret | Credential): Definition;
|
|
48
46
|
export declare function bearerHeader(name: string): (source: Secret | Credential) => Definition;
|
package/dist/route/auth.js
CHANGED
|
@@ -9,7 +9,6 @@ export class MissingCredentialError extends Error {
|
|
|
9
9
|
this.source = source;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
export const isAuth = (input) => typeof input === "object" && input !== null && "apply" in input && typeof input.apply === "function";
|
|
13
12
|
const credential = (load) => {
|
|
14
13
|
const self = {
|
|
15
14
|
load,
|
|
@@ -65,7 +64,6 @@ const credentialInput = (source) => typeof source === "string" || Redacted.isRed
|
|
|
65
64
|
export function bearer(source) {
|
|
66
65
|
return credentialInput(source).bearer();
|
|
67
66
|
}
|
|
68
|
-
export const apiKey = bearer;
|
|
69
67
|
export function header(name, source) {
|
|
70
68
|
if (source === undefined) {
|
|
71
69
|
return (next) => credentialInput(next).header(name);
|
package/dist/route/client.d.ts
CHANGED
|
@@ -46,7 +46,6 @@ export interface Route<Body, Prepared = unknown, Compact extends CompactionOpera
|
|
|
46
46
|
readonly streamPrepared: (prepared: Prepared, request: LLMRequest, runtime: TransportRuntime, options?: StreamOptions) => Stream.Stream<LLMEvent, AIError>;
|
|
47
47
|
}
|
|
48
48
|
export type AnyRoute<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Route<any, any, Compact>;
|
|
49
|
-
export type HttpOptionsInput = HttpOptions.Input;
|
|
50
49
|
export type RouteLanguageModelInput = Omit<LanguageModel.Input, "provider" | "route">;
|
|
51
50
|
export type RouteRoutedLanguageModelInput = Omit<LanguageModel.Input, "route">;
|
|
52
51
|
export interface RouteDefaults {
|
|
@@ -71,7 +70,6 @@ export interface RoutePatch<Body, Prepared> extends RouteDefaultsInput {
|
|
|
71
70
|
readonly endpoint?: EndpointPatch<Body>;
|
|
72
71
|
}
|
|
73
72
|
type RouteMappedLanguageModelInput = RouteLanguageModelInput | RouteRoutedLanguageModelInput;
|
|
74
|
-
export declare const generationOptions: (input: GenerationOptions.Input | undefined) => GenerationOptions | undefined;
|
|
75
73
|
export interface Interface {
|
|
76
74
|
readonly compact: CompactMethod;
|
|
77
75
|
readonly stream: StreamMethod;
|
|
@@ -195,7 +193,7 @@ export declare function make<Body, Prepared, Frame, Event, State>(input: MakeTra
|
|
|
195
193
|
* the public surface preemptively.
|
|
196
194
|
*/
|
|
197
195
|
export declare function make<Body, Frame, Event, State>(input: MakeInput<Body, Frame, Event, State>): Route<Body, HttpTransport.HttpPrepared<Frame>>;
|
|
198
|
-
/**
|
|
196
|
+
/** Test-only projection of the execution compiler; exported from `@opencode/ai/testing`. */
|
|
199
197
|
export declare const compileRequest: (request: LLMRequest<LanguageModel<{
|
|
200
198
|
readonly [x: string]: unknown;
|
|
201
199
|
}, CompactionOperations | undefined>>) => Effect.Effect<{
|
|
@@ -222,7 +220,7 @@ export declare const LLMClient: {
|
|
|
222
220
|
readonly canCompact: typeof canCompact;
|
|
223
221
|
readonly compact: typeof compact;
|
|
224
222
|
readonly Service: typeof LLMClientService;
|
|
225
|
-
readonly layer: Layer.Layer<LLMClientService, never,
|
|
223
|
+
readonly layer: Layer.Layer<LLMClientService, never, RequestExecutor.RequestExecutorService>;
|
|
226
224
|
readonly stream: typeof stream;
|
|
227
225
|
readonly generate: typeof generate;
|
|
228
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";
|
|
@@ -32,7 +32,7 @@ const mergeRouteDefaults = (base, patch) => {
|
|
|
32
32
|
...base,
|
|
33
33
|
...patch,
|
|
34
34
|
headers,
|
|
35
|
-
generation: mergeGenerationOptions(
|
|
35
|
+
generation: mergeGenerationOptions(base?.generation, patch.generation),
|
|
36
36
|
providerOptions: mergeProviderOptions(base?.providerOptions, patch.providerOptions),
|
|
37
37
|
http: mergeHttpOptions(base?.http, HttpOptions.make(patch.http), headers === undefined ? undefined : new HttpOptions({ headers })),
|
|
38
38
|
};
|
|
@@ -43,7 +43,6 @@ const mergeHeaders = (...items) => {
|
|
|
43
43
|
return undefined;
|
|
44
44
|
return Object.fromEntries(entries);
|
|
45
45
|
};
|
|
46
|
-
export const generationOptions = (input) => input === undefined ? undefined : GenerationOptions.make(input);
|
|
47
46
|
export function canCompact(request, options) {
|
|
48
47
|
if (options?.mechanism === "trigger")
|
|
49
48
|
return request.model.route.compact?.trigger !== undefined;
|
|
@@ -92,13 +91,22 @@ const incompleteStreamError = (route) => new AIError({
|
|
|
92
91
|
const requireTerminalEvent = (route) => (events) => Stream.suspend(() => {
|
|
93
92
|
let terminal = false;
|
|
94
93
|
return events.pipe(Stream.mapEffect((event) => {
|
|
95
|
-
|
|
94
|
+
// Raw events carry provider frames that may trail the terminal event.
|
|
95
|
+
if (terminal && !LLMEvent.is.raw(event))
|
|
96
96
|
return Effect.fail(ProviderShared.eventError(route, `Provider emitted ${event.type} after the terminal event`));
|
|
97
97
|
if (LLMEvent.is.finish(event) || LLMEvent.is.providerError(event))
|
|
98
98
|
terminal = true;
|
|
99
99
|
return Effect.succeed(event);
|
|
100
100
|
}), Stream.onEnd(Effect.suspend(() => (terminal ? Effect.void : Effect.fail(incompleteStreamError(route))))));
|
|
101
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;
|
|
102
110
|
function makeFromTransport(input) {
|
|
103
111
|
const protocol = input.protocol;
|
|
104
112
|
const decodeEventEffect = Schema.decodeUnknownEffect(protocol.stream.event);
|
|
@@ -126,8 +134,8 @@ function makeFromTransport(input) {
|
|
|
126
134
|
id: id ?? routeInput.id,
|
|
127
135
|
provider: provider ?? routeInput.provider,
|
|
128
136
|
providerMetadataKey: providerMetadataKey ??
|
|
129
|
-
(provider !== undefined &&
|
|
130
|
-
?
|
|
137
|
+
(provider !== undefined && provider !== routeInput.provider
|
|
138
|
+
? provider
|
|
131
139
|
: routeInput.providerMetadataKey),
|
|
132
140
|
auth: auth ?? routeInput.auth,
|
|
133
141
|
endpoint: endpoint ? Endpoint.merge(routeInput.endpoint, endpoint) : routeInput.endpoint,
|
|
@@ -166,7 +174,9 @@ function makeFromTransport(input) {
|
|
|
166
174
|
let state = protocol.stream.initial(request);
|
|
167
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]) => {
|
|
168
176
|
state = next;
|
|
169
|
-
return
|
|
177
|
+
return request.includeRaw && isProviderFrame(frame)
|
|
178
|
+
? [LLMEvent.raw({ data: execution.raw?.(frame) ?? rawFrame(frame) }), ...output]
|
|
179
|
+
: output;
|
|
170
180
|
}), Effect.mapError(frameError(frame, event)))), Stream.flatMap(Stream.fromIterable));
|
|
171
181
|
const onHalt = protocol.stream.onHalt;
|
|
172
182
|
return onHalt
|
|
@@ -217,6 +227,17 @@ const prepareRequest = (request) => {
|
|
|
217
227
|
: LLMRequest.update(resolved, { http: mergeHttpOptions(new HttpOptions({ headers }), resolved.http) });
|
|
218
228
|
};
|
|
219
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");
|
|
220
241
|
const resolved = prepareRequest(request);
|
|
221
242
|
const route = resolved.model.route;
|
|
222
243
|
const body = yield* route.body.from(resolved);
|
|
@@ -228,7 +249,7 @@ const compile = Effect.fn("LLM.compile")(function* (request, options) {
|
|
|
228
249
|
prepared,
|
|
229
250
|
};
|
|
230
251
|
});
|
|
231
|
-
/**
|
|
252
|
+
/** Test-only projection of the execution compiler; exported from `@opencode/ai/testing`. */
|
|
232
253
|
export const compileRequest = Effect.fn("LLM.compileRequest")(function* (request) {
|
|
233
254
|
const compiled = yield* compile(request);
|
|
234
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";
|
|
@@ -3,7 +3,7 @@ import { HttpContext } from "../schema/errors.js";
|
|
|
3
3
|
export class RequestExecutorService extends Context.Service()("@opencode/AI/RequestExecutor") {
|
|
4
4
|
}
|
|
5
5
|
export const Service = RequestExecutorService;
|
|
6
|
-
export const headerDetails = (headers) => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name,
|
|
6
|
+
export const headerDetails = (headers) => Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, value]));
|
|
7
7
|
export const responseHttp = (response) => new HttpContext({
|
|
8
8
|
url: response.request.url,
|
|
9
9
|
status: response.status,
|
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;
|