@opencode/ai 0.0.0-reserved → 2.0.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 +879 -2
- package/dist/cache-policy.d.ts +2 -0
- package/dist/cache-policy.js +129 -0
- package/dist/image-client.d.ts +19 -0
- package/dist/image-client.js +28 -0
- package/dist/image.d.ts +110 -0
- package/dist/image.js +103 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/dist/llm.d.ts +252 -0
- package/dist/llm.js +74 -0
- package/dist/protocols/alibaba-chat.d.ts +225 -0
- package/dist/protocols/alibaba-chat.js +75 -0
- package/dist/protocols/alibaba-messages.d.ts +350 -0
- package/dist/protocols/alibaba-messages.js +40 -0
- package/dist/protocols/alibaba-responses.d.ts +255 -0
- package/dist/protocols/alibaba-responses.js +80 -0
- package/dist/protocols/anthropic-messages.d.ts +980 -0
- package/dist/protocols/anthropic-messages.js +1460 -0
- package/dist/protocols/bedrock-converse.d.ts +499 -0
- package/dist/protocols/bedrock-converse.js +643 -0
- package/dist/protocols/bedrock-event-stream.d.ts +9 -0
- package/dist/protocols/bedrock-event-stream.js +97 -0
- package/dist/protocols/gemini.d.ts +285 -0
- package/dist/protocols/gemini.js +671 -0
- package/dist/protocols/google-images.d.ts +30 -0
- package/dist/protocols/google-images.js +181 -0
- package/dist/protocols/index.d.ts +12 -0
- package/dist/protocols/index.js +12 -0
- package/dist/protocols/meta-images.d.ts +26 -0
- package/dist/protocols/meta-images.js +89 -0
- package/dist/protocols/meta-messages.d.ts +356 -0
- package/dist/protocols/meta-messages.js +41 -0
- package/dist/protocols/meta-responses.d.ts +473 -0
- package/dist/protocols/meta-responses.js +173 -0
- package/dist/protocols/mistral-chat.d.ts +540 -0
- package/dist/protocols/mistral-chat.js +624 -0
- package/dist/protocols/open-responses-channel.d.ts +25 -0
- package/dist/protocols/open-responses-channel.js +141 -0
- package/dist/protocols/open-responses-continuation.d.ts +16 -0
- package/dist/protocols/open-responses-continuation.js +170 -0
- package/dist/protocols/open-responses.d.ts +1715 -0
- package/dist/protocols/open-responses.js +1228 -0
- package/dist/protocols/openai-chat.d.ts +860 -0
- package/dist/protocols/openai-chat.js +966 -0
- package/dist/protocols/openai-compatible-chat.d.ts +109 -0
- package/dist/protocols/openai-compatible-chat.js +19 -0
- package/dist/protocols/openai-compatible-responses.d.ts +172 -0
- package/dist/protocols/openai-compatible-responses.js +18 -0
- package/dist/protocols/openai-images.d.ts +32 -0
- package/dist/protocols/openai-images.js +183 -0
- package/dist/protocols/openai-responses.d.ts +1389 -0
- package/dist/protocols/openai-responses.js +260 -0
- package/dist/protocols/shared.d.ts +193 -0
- package/dist/protocols/shared.js +290 -0
- package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
- package/dist/protocols/utils/bedrock-auth.js +85 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
- package/dist/protocols/utils/bedrock-cache.js +49 -0
- package/dist/protocols/utils/bedrock-media.d.ts +55 -0
- package/dist/protocols/utils/bedrock-media.js +73 -0
- package/dist/protocols/utils/cache.d.ts +6 -0
- package/dist/protocols/utils/cache.js +5 -0
- package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
- package/dist/protocols/utils/gemini-tool-schema.js +103 -0
- package/dist/protocols/utils/image-input.d.ts +21 -0
- package/dist/protocols/utils/image-input.js +20 -0
- package/dist/protocols/utils/lifecycle.d.ts +24 -0
- package/dist/protocols/utils/lifecycle.js +72 -0
- package/dist/protocols/utils/meta-image.d.ts +2 -0
- package/dist/protocols/utils/meta-image.js +13 -0
- package/dist/protocols/utils/open-responses-options.d.ts +56 -0
- package/dist/protocols/utils/open-responses-options.js +61 -0
- package/dist/protocols/utils/openai-image.d.ts +5 -0
- package/dist/protocols/utils/openai-image.js +18 -0
- package/dist/protocols/utils/openai-options.d.ts +16 -0
- package/dist/protocols/utils/openai-options.js +14 -0
- package/dist/protocols/utils/partial-json-options.d.ts +62 -0
- package/dist/protocols/utils/partial-json-options.js +52 -0
- package/dist/protocols/utils/partial-json.d.ts +8 -0
- package/dist/protocols/utils/partial-json.js +279 -0
- package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
- package/dist/protocols/utils/responses-checkpoint.js +107 -0
- package/dist/protocols/utils/responses-compaction.d.ts +4 -0
- package/dist/protocols/utils/responses-compaction.js +129 -0
- package/dist/protocols/utils/responses-hosted-tools.d.ts +26 -0
- package/dist/protocols/utils/responses-hosted-tools.js +32 -0
- package/dist/protocols/utils/tool-schema.d.ts +8 -0
- package/dist/protocols/utils/tool-schema.js +54 -0
- package/dist/protocols/utils/tool-stream.d.ts +710 -0
- package/dist/protocols/utils/tool-stream.js +155 -0
- package/dist/protocols/xai-images.d.ts +26 -0
- package/dist/protocols/xai-images.js +106 -0
- package/dist/protocols/xai-responses.d.ts +250 -0
- package/dist/protocols/xai-responses.js +81 -0
- package/dist/protocols/zai-chat.d.ts +202 -0
- package/dist/protocols/zai-chat.js +49 -0
- package/dist/protocols/zai-images.d.ts +22 -0
- package/dist/protocols/zai-images.js +79 -0
- package/dist/protocols/zai-messages.d.ts +344 -0
- package/dist/protocols/zai-messages.js +27 -0
- package/dist/protocols.d.ts +1 -0
- package/dist/protocols.js +1 -0
- package/dist/provider-error.d.ts +15 -0
- package/dist/provider-error.js +125 -0
- package/dist/provider-package.d.ts +15 -0
- package/dist/provider-package.js +1 -0
- package/dist/provider.d.ts +23 -0
- package/dist/provider.js +2 -0
- package/dist/providers/alibaba/chat.d.ts +1 -0
- package/dist/providers/alibaba/chat.js +1 -0
- package/dist/providers/alibaba/messages.d.ts +3 -0
- package/dist/providers/alibaba/messages.js +1 -0
- package/dist/providers/alibaba/responses.d.ts +3 -0
- package/dist/providers/alibaba/responses.js +1 -0
- package/dist/providers/alibaba.d.ts +711 -0
- package/dist/providers/alibaba.js +94 -0
- package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
- package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
- package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle.js +1 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +313 -0
- package/dist/providers/amazon-bedrock-mantle.js +79 -0
- package/dist/providers/amazon-bedrock.d.ts +173 -0
- package/dist/providers/amazon-bedrock.js +41 -0
- package/dist/providers/anthropic-compatible.d.ts +309 -0
- package/dist/providers/anthropic-compatible.js +50 -0
- package/dist/providers/anthropic.d.ts +307 -0
- package/dist/providers/anthropic.js +42 -0
- package/dist/providers/azure/chat.d.ts +2 -0
- package/dist/providers/azure/chat.js +1 -0
- package/dist/providers/azure/responses.d.ts +2 -0
- package/dist/providers/azure/responses.js +1 -0
- package/dist/providers/azure.d.ts +598 -0
- package/dist/providers/azure.js +115 -0
- package/dist/providers/baseten.d.ts +228 -0
- package/dist/providers/baseten.js +38 -0
- package/dist/providers/cerebras.d.ts +227 -0
- package/dist/providers/cerebras.js +40 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +237 -0
- package/dist/providers/cloudflare-ai-gateway.js +65 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +231 -0
- package/dist/providers/cloudflare-workers-ai.js +51 -0
- package/dist/providers/deepinfra.d.ts +227 -0
- package/dist/providers/deepinfra.js +43 -0
- package/dist/providers/deepseek.d.ts +228 -0
- package/dist/providers/deepseek.js +41 -0
- package/dist/providers/fireworks.d.ts +228 -0
- package/dist/providers/fireworks.js +38 -0
- package/dist/providers/google-vertex/chat.d.ts +2 -0
- package/dist/providers/google-vertex/chat.js +1 -0
- package/dist/providers/google-vertex/gemini.d.ts +2 -0
- package/dist/providers/google-vertex/gemini.js +1 -0
- package/dist/providers/google-vertex/messages.d.ts +2 -0
- package/dist/providers/google-vertex/messages.js +1 -0
- package/dist/providers/google-vertex/responses.d.ts +2 -0
- package/dist/providers/google-vertex/responses.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +132 -0
- package/dist/providers/google-vertex-chat.js +55 -0
- package/dist/providers/google-vertex-messages.d.ts +306 -0
- package/dist/providers/google-vertex-messages.js +75 -0
- package/dist/providers/google-vertex-responses.d.ts +197 -0
- package/dist/providers/google-vertex-responses.js +56 -0
- package/dist/providers/google-vertex-shared.d.ts +22 -0
- package/dist/providers/google-vertex-shared.js +72 -0
- package/dist/providers/google-vertex.d.ts +119 -0
- package/dist/providers/google-vertex.js +98 -0
- package/dist/providers/google.d.ts +114 -0
- package/dist/providers/google.js +42 -0
- package/dist/providers/groq.d.ts +314 -0
- package/dist/providers/groq.js +81 -0
- package/dist/providers/index.d.ts +31 -0
- package/dist/providers/index.js +31 -0
- package/dist/providers/meta/chat.d.ts +2 -0
- package/dist/providers/meta/chat.js +1 -0
- package/dist/providers/meta/messages.d.ts +2 -0
- package/dist/providers/meta/messages.js +1 -0
- package/dist/providers/meta/responses.d.ts +2 -0
- package/dist/providers/meta/responses.js +1 -0
- package/dist/providers/meta.d.ts +636 -0
- package/dist/providers/meta.js +113 -0
- package/dist/providers/minimax/chat.d.ts +4 -0
- package/dist/providers/minimax/chat.js +8 -0
- package/dist/providers/minimax/messages.d.ts +1 -0
- package/dist/providers/minimax/messages.js +1 -0
- package/dist/providers/minimax/responses.d.ts +4 -0
- package/dist/providers/minimax/responses.js +8 -0
- package/dist/providers/minimax.d.ts +598 -0
- package/dist/providers/minimax.js +89 -0
- package/dist/providers/mistral.d.ts +207 -0
- package/dist/providers/mistral.js +28 -0
- package/dist/providers/moonshot/chat.d.ts +1 -0
- package/dist/providers/moonshot/chat.js +1 -0
- package/dist/providers/moonshot/messages.d.ts +4 -0
- package/dist/providers/moonshot/messages.js +8 -0
- package/dist/providers/moonshot/responses.d.ts +4 -0
- package/dist/providers/moonshot/responses.js +8 -0
- package/dist/providers/moonshot.d.ts +596 -0
- package/dist/providers/moonshot.js +90 -0
- package/dist/providers/open-responses-options.d.ts +6 -0
- package/dist/providers/open-responses-options.js +1 -0
- package/dist/providers/openai/chat.d.ts +2 -0
- package/dist/providers/openai/chat.js +1 -0
- package/dist/providers/openai/responses.d.ts +2 -0
- package/dist/providers/openai/responses.js +1 -0
- package/dist/providers/openai-compatible/responses.d.ts +1 -0
- package/dist/providers/openai-compatible/responses.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +195 -0
- package/dist/providers/openai-compatible-responses.js +32 -0
- package/dist/providers/openai-compatible.d.ts +130 -0
- package/dist/providers/openai-compatible.js +33 -0
- package/dist/providers/openai-options.d.ts +26 -0
- package/dist/providers/openai-options.js +41 -0
- package/dist/providers/openai.d.ts +404 -0
- package/dist/providers/openai.js +82 -0
- package/dist/providers/openrouter.d.ts +563 -0
- package/dist/providers/openrouter.js +114 -0
- package/dist/providers/togetherai.d.ts +227 -0
- package/dist/providers/togetherai.js +40 -0
- package/dist/providers/xai.d.ts +163 -0
- package/dist/providers/xai.js +88 -0
- package/dist/providers/zai/chat.d.ts +1 -0
- package/dist/providers/zai/chat.js +1 -0
- package/dist/providers/zai-coding-plan/chat.d.ts +1 -0
- package/dist/providers/zai-coding-plan/chat.js +1 -0
- package/dist/providers/zai-coding-plan/messages.d.ts +4 -0
- package/dist/providers/zai-coding-plan/messages.js +8 -0
- package/dist/providers/zai-coding-plan/responses.d.ts +4 -0
- package/dist/providers/zai-coding-plan/responses.js +8 -0
- package/dist/providers/zai-coding-plan.d.ts +577 -0
- package/dist/providers/zai-coding-plan.js +63 -0
- package/dist/providers/zai.d.ts +149 -0
- package/dist/providers/zai.js +53 -0
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +1 -0
- package/dist/route/auth-options.d.ts +34 -0
- package/dist/route/auth-options.js +14 -0
- package/dist/route/auth.d.ts +51 -0
- package/dist/route/auth.js +87 -0
- package/dist/route/client.d.ts +430 -0
- package/dist/route/client.js +307 -0
- package/dist/route/endpoint.d.ts +28 -0
- package/dist/route/endpoint.js +21 -0
- package/dist/route/executor.d.ts +27 -0
- package/dist/route/executor.js +183 -0
- package/dist/route/framing.d.ts +29 -0
- package/dist/route/framing.js +14 -0
- package/dist/route/index.d.ts +16 -0
- package/dist/route/index.js +9 -0
- package/dist/route/protocol.d.ts +76 -0
- package/dist/route/protocol.js +16 -0
- package/dist/route/transport/http.d.ts +34 -0
- package/dist/route/transport/http.js +68 -0
- package/dist/route/transport/index.d.ts +41 -0
- package/dist/route/transport/index.js +4 -0
- package/dist/route/transport/websocket-channel.d.ts +57 -0
- package/dist/route/transport/websocket-channel.js +1 -0
- package/dist/route/transport/websocket.d.ts +56 -0
- package/dist/route/transport/websocket.js +370 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +170 -0
- package/dist/schema/errors.js +131 -0
- package/dist/schema/events.d.ts +8123 -0
- package/dist/schema/events.js +550 -0
- package/dist/schema/ids.d.ts +17 -0
- package/dist/schema/ids.js +10 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/messages.d.ts +646 -0
- package/dist/schema/messages.js +301 -0
- package/dist/schema/options.d.ts +159 -0
- package/dist/schema/options.js +189 -0
- package/dist/testing.d.ts +1693 -0
- package/dist/testing.js +129 -0
- package/dist/tool-history.d.ts +2 -0
- package/dist/tool-history.js +84 -0
- package/dist/tool-runtime.d.ts +15 -0
- package/dist/tool-runtime.js +62 -0
- package/dist/tool.d.ts +136 -0
- package/dist/tool.js +66 -0
- package/dist/utils/record.d.ts +2 -0
- package/dist/utils/record.js +2 -0
- package/dist/utils/sanitize.d.ts +1 -0
- package/dist/utils/sanitize.js +12 -0
- package/package.json +43 -10
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
+
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
3
|
+
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
4
|
+
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
5
|
+
import { type ModelID } from "../schema/index.js";
|
|
6
|
+
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
|
+
export type ChatOptionsInput = ZAIChat.OptionsInput;
|
|
8
|
+
export type Config = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
9
|
+
readonly baseURL?: string;
|
|
10
|
+
readonly providerOptions?: ChatOptionsInput;
|
|
11
|
+
};
|
|
12
|
+
export type Settings = ProviderPackage.Settings & ChatOptionsInput & {
|
|
13
|
+
readonly apiKey?: string;
|
|
14
|
+
readonly baseURL?: string;
|
|
15
|
+
};
|
|
16
|
+
export type { ZAIImageOptions } from "../protocols/zai-images.js";
|
|
17
|
+
export declare const routes: Route<{
|
|
18
|
+
readonly model: string;
|
|
19
|
+
readonly messages: readonly ({
|
|
20
|
+
readonly role: "system";
|
|
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
|
+
readonly type: "image_url";
|
|
30
|
+
readonly image_url: {
|
|
31
|
+
readonly url: string;
|
|
32
|
+
};
|
|
33
|
+
})[];
|
|
34
|
+
} | {
|
|
35
|
+
readonly role: "user";
|
|
36
|
+
readonly content: string | readonly ({
|
|
37
|
+
readonly type: "text";
|
|
38
|
+
readonly text: string;
|
|
39
|
+
readonly cache_control?: {
|
|
40
|
+
readonly type: "ephemeral";
|
|
41
|
+
readonly ttl?: string | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
} | {
|
|
44
|
+
readonly type: "image_url";
|
|
45
|
+
readonly image_url: {
|
|
46
|
+
readonly url: string;
|
|
47
|
+
};
|
|
48
|
+
})[];
|
|
49
|
+
} | {
|
|
50
|
+
readonly [x: string]: unknown;
|
|
51
|
+
readonly content: string | null;
|
|
52
|
+
readonly role: "assistant";
|
|
53
|
+
readonly reasoning?: string | undefined;
|
|
54
|
+
readonly reasoning_content?: string | undefined;
|
|
55
|
+
readonly reasoning_text?: string | undefined;
|
|
56
|
+
readonly cache_control?: {
|
|
57
|
+
readonly type: "ephemeral";
|
|
58
|
+
readonly ttl?: string | undefined;
|
|
59
|
+
} | undefined;
|
|
60
|
+
readonly tool_calls?: readonly {
|
|
61
|
+
readonly id: string;
|
|
62
|
+
readonly type: "function";
|
|
63
|
+
readonly function: {
|
|
64
|
+
readonly name: string;
|
|
65
|
+
readonly arguments: string;
|
|
66
|
+
};
|
|
67
|
+
}[] | undefined;
|
|
68
|
+
readonly reasoning_details?: unknown;
|
|
69
|
+
} | {
|
|
70
|
+
readonly content: string;
|
|
71
|
+
readonly role: "tool";
|
|
72
|
+
readonly tool_call_id: string;
|
|
73
|
+
readonly cache_control?: {
|
|
74
|
+
readonly type: "ephemeral";
|
|
75
|
+
readonly ttl?: string | undefined;
|
|
76
|
+
} | undefined;
|
|
77
|
+
})[];
|
|
78
|
+
readonly stream: true;
|
|
79
|
+
readonly max_completion_tokens?: number | undefined;
|
|
80
|
+
readonly max_tokens?: number | undefined;
|
|
81
|
+
readonly tools?: readonly {
|
|
82
|
+
readonly function: {
|
|
83
|
+
readonly description: string;
|
|
84
|
+
readonly name: string;
|
|
85
|
+
readonly parameters: {
|
|
86
|
+
readonly [x: string]: unknown;
|
|
87
|
+
};
|
|
88
|
+
readonly strict?: boolean | undefined;
|
|
89
|
+
};
|
|
90
|
+
readonly type: "function";
|
|
91
|
+
readonly cache_control?: {
|
|
92
|
+
readonly type: "ephemeral";
|
|
93
|
+
readonly ttl?: string | undefined;
|
|
94
|
+
} | undefined;
|
|
95
|
+
}[] | undefined;
|
|
96
|
+
readonly stop?: readonly string[] | undefined;
|
|
97
|
+
readonly temperature?: number | undefined;
|
|
98
|
+
readonly seed?: number | undefined;
|
|
99
|
+
readonly thinking?: {
|
|
100
|
+
readonly type?: string | undefined;
|
|
101
|
+
readonly clear_thinking?: boolean | undefined;
|
|
102
|
+
} | undefined;
|
|
103
|
+
readonly user_id?: string | undefined;
|
|
104
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
105
|
+
readonly type: "function";
|
|
106
|
+
readonly function: {
|
|
107
|
+
readonly name: string;
|
|
108
|
+
};
|
|
109
|
+
} | undefined;
|
|
110
|
+
readonly top_p?: number | undefined;
|
|
111
|
+
readonly frequency_penalty?: number | undefined;
|
|
112
|
+
readonly presence_penalty?: number | undefined;
|
|
113
|
+
readonly prompt_cache_key?: string | undefined;
|
|
114
|
+
readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
|
|
115
|
+
readonly store?: boolean | undefined;
|
|
116
|
+
readonly stream_options?: {
|
|
117
|
+
readonly include_usage: boolean;
|
|
118
|
+
} | undefined;
|
|
119
|
+
readonly tool_stream?: boolean | undefined;
|
|
120
|
+
readonly response_format?: {
|
|
121
|
+
readonly type: string;
|
|
122
|
+
} | undefined;
|
|
123
|
+
readonly do_sample?: boolean | undefined;
|
|
124
|
+
readonly request_id?: string | undefined;
|
|
125
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
|
|
126
|
+
export declare const configure: (input?: Config) => {
|
|
127
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
128
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
129
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
130
|
+
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
131
|
+
configure: (input?: Config) => /*elided*/ any;
|
|
132
|
+
};
|
|
133
|
+
export declare const provider: {
|
|
134
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
135
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
136
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
137
|
+
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
138
|
+
configure: (input?: Config) => {
|
|
139
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
140
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
141
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
142
|
+
image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
143
|
+
configure: /*elided*/ any;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("./zai.js").ZAIImageOptions>;
|
|
147
|
+
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ZAIChat.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
148
|
+
export declare const model: ProviderPackage.Definition<Settings, ChatOptionsInput>["model"];
|
|
149
|
+
export * as ZAI from "./zai.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ZAIChat } from "../protocols/zai-chat.js";
|
|
2
|
+
import { ZAIImages } from "../protocols/zai-images.js";
|
|
3
|
+
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
4
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
5
|
+
import { Route } from "../route/client.js";
|
|
6
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
7
|
+
import { HttpOptions, ProviderID } from "../schema/index.js";
|
|
8
|
+
export const id = ProviderID.make("zai");
|
|
9
|
+
const auth = (options) => AuthOptions.bearer(options, "ZAI_API_KEY");
|
|
10
|
+
const chatRoute = Route.make({
|
|
11
|
+
id: "zai-chat",
|
|
12
|
+
provider: id,
|
|
13
|
+
providerMetadataKey: "zai",
|
|
14
|
+
protocol: ZAIChat.protocol,
|
|
15
|
+
endpoint: Endpoint.path("/chat/completions", { baseURL: "https://api.z.ai/api/paas/v4" }),
|
|
16
|
+
framing: OpenAIChat.framing,
|
|
17
|
+
});
|
|
18
|
+
export const routes = [chatRoute];
|
|
19
|
+
export const configure = (input = {}) => {
|
|
20
|
+
const { apiKey: _apiKey, auth: _auth, baseURL, ...rest } = input;
|
|
21
|
+
const chat = (modelID) => chatRoute
|
|
22
|
+
.with({
|
|
23
|
+
...rest,
|
|
24
|
+
endpoint: baseURL === undefined ? undefined : { baseURL },
|
|
25
|
+
auth: auth(input),
|
|
26
|
+
})
|
|
27
|
+
.model({ id: modelID, compatibility: ZAIChat.compatibility });
|
|
28
|
+
const image = (modelID) => ZAIImages.model({
|
|
29
|
+
id: modelID,
|
|
30
|
+
auth: auth(input),
|
|
31
|
+
baseURL: input.baseURL,
|
|
32
|
+
headers: input.headers,
|
|
33
|
+
http: input.http === undefined ? undefined : HttpOptions.make(input.http),
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
model: chat,
|
|
38
|
+
chat,
|
|
39
|
+
image,
|
|
40
|
+
configure,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export const provider = configure();
|
|
44
|
+
export const image = provider.image;
|
|
45
|
+
export const chat = provider.chat;
|
|
46
|
+
export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => configure({
|
|
47
|
+
apiKey,
|
|
48
|
+
baseURL,
|
|
49
|
+
headers,
|
|
50
|
+
http: body === undefined ? undefined : { body: { ...body } },
|
|
51
|
+
providerOptions,
|
|
52
|
+
}).model(modelID);
|
|
53
|
+
export * as ZAI from "./zai.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./providers/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./providers/index.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Config, Redacted } from "effect";
|
|
2
|
+
import { Auth } from "./auth.js";
|
|
3
|
+
export type ApiKeyMode = "optional" | "required";
|
|
4
|
+
export type AuthOverride = {
|
|
5
|
+
readonly auth: Auth.Definition;
|
|
6
|
+
readonly apiKey?: never;
|
|
7
|
+
};
|
|
8
|
+
export type OptionalApiKeyAuth = {
|
|
9
|
+
readonly apiKey?: string | Redacted.Redacted<string> | Config.Config<string | Redacted.Redacted<string>>;
|
|
10
|
+
readonly auth?: never;
|
|
11
|
+
};
|
|
12
|
+
export type RequiredApiKeyAuth = {
|
|
13
|
+
readonly apiKey: string | Redacted.Redacted<string> | Config.Config<string | Redacted.Redacted<string>>;
|
|
14
|
+
readonly auth?: never;
|
|
15
|
+
};
|
|
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
|
+
/**
|
|
21
|
+
* Require at least one of the keys in `T`. Use for option shapes where any
|
|
22
|
+
* subset of fields is acceptable but at least one must be present (e.g. Azure
|
|
23
|
+
* accepts `resourceName` or `baseURL`).
|
|
24
|
+
*/
|
|
25
|
+
export type AtLeastOne<T> = {
|
|
26
|
+
[K in keyof T]: Required<Pick<T, K>> & Partial<Omit<T, K>>;
|
|
27
|
+
}[keyof T];
|
|
28
|
+
/**
|
|
29
|
+
* Standard bearer-auth resolution for providers: honor an explicit `auth`
|
|
30
|
+
* override, otherwise resolve `apiKey` (option > config var) and apply it as
|
|
31
|
+
* a bearer token.
|
|
32
|
+
*/
|
|
33
|
+
export declare const bearer: (options: ProviderAuthOption<"optional">, envVar: string | ReadonlyArray<string>) => Auth.Definition;
|
|
34
|
+
export * as AuthOptions from "./auth-options.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Auth } from "./auth.js";
|
|
2
|
+
/**
|
|
3
|
+
* Standard bearer-auth resolution for providers: honor an explicit `auth`
|
|
4
|
+
* override, otherwise resolve `apiKey` (option > config var) and apply it as
|
|
5
|
+
* a bearer token.
|
|
6
|
+
*/
|
|
7
|
+
export const bearer = (options, envVar) => {
|
|
8
|
+
if ("auth" in options && options.auth)
|
|
9
|
+
return options.auth;
|
|
10
|
+
return (Array.isArray(envVar) ? envVar : [envVar])
|
|
11
|
+
.reduce((auth, name) => auth.orElse(Auth.config(name)), Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey"))
|
|
12
|
+
.bearer();
|
|
13
|
+
};
|
|
14
|
+
export * as AuthOptions from "./auth-options.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Config, Effect, Redacted } from "effect";
|
|
2
|
+
import { Headers } from "effect/unstable/http";
|
|
3
|
+
import { AIError, type HttpOptions } from "../schema/index.js";
|
|
4
|
+
export declare class MissingCredentialError extends Error {
|
|
5
|
+
readonly source: string;
|
|
6
|
+
readonly _tag = "MissingCredentialError";
|
|
7
|
+
constructor(source: string);
|
|
8
|
+
}
|
|
9
|
+
export type CredentialError = MissingCredentialError | Config.ConfigError;
|
|
10
|
+
export type AuthError = CredentialError | AIError;
|
|
11
|
+
type Secret = string | Redacted.Redacted | Config.Config<string | Redacted.Redacted>;
|
|
12
|
+
export interface AuthInput {
|
|
13
|
+
readonly request: {
|
|
14
|
+
readonly http?: HttpOptions;
|
|
15
|
+
};
|
|
16
|
+
readonly method: "POST" | "GET";
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly body: string;
|
|
19
|
+
readonly headers: Headers.Headers;
|
|
20
|
+
}
|
|
21
|
+
export interface Credential {
|
|
22
|
+
readonly load: Effect.Effect<Redacted.Redacted, CredentialError>;
|
|
23
|
+
readonly orElse: (that: Credential) => Credential;
|
|
24
|
+
readonly bearer: () => Definition;
|
|
25
|
+
readonly header: (name: string) => Definition;
|
|
26
|
+
readonly pipe: <A>(f: (self: Credential) => A) => A;
|
|
27
|
+
}
|
|
28
|
+
export interface Definition {
|
|
29
|
+
readonly apply: (input: AuthInput) => Effect.Effect<Headers.Headers, AuthError>;
|
|
30
|
+
readonly andThen: (that: Definition) => Definition;
|
|
31
|
+
readonly orElse: (that: Definition) => Definition;
|
|
32
|
+
readonly pipe: <A>(f: (self: Definition) => A) => A;
|
|
33
|
+
}
|
|
34
|
+
export declare const isAuth: (input: unknown) => input is Definition;
|
|
35
|
+
export declare const value: (secret: string, source?: string) => Credential;
|
|
36
|
+
export declare const optional: (secret: Secret | undefined, source?: string) => Credential;
|
|
37
|
+
export declare const config: (name: string) => Credential;
|
|
38
|
+
export declare const effect: (load: Effect.Effect<Redacted.Redacted, CredentialError>) => Credential;
|
|
39
|
+
export declare const none: Definition;
|
|
40
|
+
export declare const headers: (input: Headers.Input) => Definition;
|
|
41
|
+
export declare const remove: (name: string) => Definition;
|
|
42
|
+
export declare const custom: (apply: (input: AuthInput) => Effect.Effect<Headers.Headers, AIError>) => Definition;
|
|
43
|
+
export declare const passthrough: Definition;
|
|
44
|
+
export declare function bearer(source: Secret | Credential): Definition;
|
|
45
|
+
export declare const apiKey: typeof bearer;
|
|
46
|
+
export declare function header(name: string): (source: Secret | Credential) => Definition;
|
|
47
|
+
export declare function header(name: string, source: Secret | Credential): Definition;
|
|
48
|
+
export declare function bearerHeader(name: string): (source: Secret | Credential) => Definition;
|
|
49
|
+
export declare function bearerHeader(name: string, source: Secret | Credential): Definition;
|
|
50
|
+
export declare const toEffect: (input: Definition) => (authInput: AuthInput) => Effect.Effect<Headers.Headers, AIError>;
|
|
51
|
+
export * as Auth from "./auth.js";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Config, Effect, Redacted } from "effect";
|
|
2
|
+
import { Headers } from "effect/unstable/http";
|
|
3
|
+
import { AuthenticationError, InvalidRequestError, AIError } from "../schema/index.js";
|
|
4
|
+
export class MissingCredentialError extends Error {
|
|
5
|
+
source;
|
|
6
|
+
_tag = "MissingCredentialError";
|
|
7
|
+
constructor(source) {
|
|
8
|
+
super(`Missing auth credential: ${source}`);
|
|
9
|
+
this.source = source;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const isAuth = (input) => typeof input === "object" && input !== null && "apply" in input && typeof input.apply === "function";
|
|
13
|
+
const credential = (load) => {
|
|
14
|
+
const self = {
|
|
15
|
+
load,
|
|
16
|
+
orElse: (that) => credential(load.pipe(Effect.catch(() => that.load))),
|
|
17
|
+
bearer: () => fromCredential(self, (secret) => ({ authorization: `Bearer ${secret}` })),
|
|
18
|
+
header: (name) => fromCredential(self, (secret) => ({ [name]: secret })),
|
|
19
|
+
pipe: (f) => f(self),
|
|
20
|
+
};
|
|
21
|
+
return self;
|
|
22
|
+
};
|
|
23
|
+
const auth = (apply) => {
|
|
24
|
+
const self = {
|
|
25
|
+
apply,
|
|
26
|
+
andThen: (that) => auth((input) => apply(input).pipe(Effect.flatMap((headers) => that.apply({ ...input, headers })))),
|
|
27
|
+
orElse: (that) => auth((input) => apply(input).pipe(Effect.catch(() => that.apply(input)))),
|
|
28
|
+
pipe: (f) => f(self),
|
|
29
|
+
};
|
|
30
|
+
return self;
|
|
31
|
+
};
|
|
32
|
+
const fromCredential = (source, render) => auth((input) => source.load.pipe(Effect.map((secret) => Headers.setAll(input.headers, render(Redacted.value(secret))))));
|
|
33
|
+
const secretEffect = (secret, source) => {
|
|
34
|
+
const redacted = typeof secret === "string" ? Redacted.make(secret) : secret;
|
|
35
|
+
if (Redacted.value(redacted) === "")
|
|
36
|
+
return Effect.fail(new MissingCredentialError(source));
|
|
37
|
+
return Effect.succeed(redacted);
|
|
38
|
+
};
|
|
39
|
+
const credentialFromSecret = (secret, source) => {
|
|
40
|
+
if (typeof secret === "string" || Redacted.isRedacted(secret))
|
|
41
|
+
return credential(secretEffect(secret, source));
|
|
42
|
+
return credential(Effect.gen(function* () {
|
|
43
|
+
return yield* secretEffect(yield* secret, source);
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
export const value = (secret, source = "value") => credentialFromSecret(secret, source);
|
|
47
|
+
export const optional = (secret, source = "optional value") => secret === undefined
|
|
48
|
+
? credential(Effect.fail(new MissingCredentialError(source)))
|
|
49
|
+
: credentialFromSecret(secret, source);
|
|
50
|
+
export const config = (name) => credentialFromSecret(Config.redacted(name), name);
|
|
51
|
+
export const effect = (load) => credential(load);
|
|
52
|
+
export const none = auth((input) => Effect.succeed(input.headers));
|
|
53
|
+
export const headers = (input) => auth((inputAuth) => Effect.succeed(Headers.setAll(inputAuth.headers, input)));
|
|
54
|
+
export const remove = (name) => auth((input) => Effect.succeed(Headers.remove(input.headers, name)));
|
|
55
|
+
export const custom = (apply) => auth(apply);
|
|
56
|
+
export const passthrough = none;
|
|
57
|
+
const credentialInput = (source) => typeof source === "string" || Redacted.isRedacted(source) || Config.isConfig(source)
|
|
58
|
+
? credentialFromSecret(source, "value")
|
|
59
|
+
: source;
|
|
60
|
+
export function bearer(source) {
|
|
61
|
+
return credentialInput(source).bearer();
|
|
62
|
+
}
|
|
63
|
+
export const apiKey = bearer;
|
|
64
|
+
export function header(name, source) {
|
|
65
|
+
if (source === undefined) {
|
|
66
|
+
return (next) => credentialInput(next).header(name);
|
|
67
|
+
}
|
|
68
|
+
return credentialInput(source).header(name);
|
|
69
|
+
}
|
|
70
|
+
export function bearerHeader(name, source) {
|
|
71
|
+
const render = (input) => fromCredential(credentialInput(input), (secret) => ({ [name]: `Bearer ${secret}` }));
|
|
72
|
+
if (source === undefined)
|
|
73
|
+
return render;
|
|
74
|
+
return render(source);
|
|
75
|
+
}
|
|
76
|
+
const toAIError = (error) => {
|
|
77
|
+
if (error instanceof MissingCredentialError || error instanceof Config.ConfigError) {
|
|
78
|
+
return new AIError({
|
|
79
|
+
reason: error instanceof MissingCredentialError
|
|
80
|
+
? new AuthenticationError({ message: error.message, cause: error })
|
|
81
|
+
: new InvalidRequestError({ message: `Failed to resolve auth config: ${error.message}`, cause: error }),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return error;
|
|
85
|
+
};
|
|
86
|
+
export const toEffect = (input) => (authInput) => input.apply(authInput).pipe(Effect.mapError(toAIError));
|
|
87
|
+
export * as Auth from "./auth.js";
|