@opencode/ai 0.0.0-beta-19275
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 +682 -0
- 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/anthropic-messages.d.ts +957 -0
- package/dist/protocols/anthropic-messages.js +1414 -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 +350 -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 +23 -0
- package/dist/protocols/open-responses-channel.js +141 -0
- package/dist/protocols/open-responses-continuation.d.ts +12 -0
- package/dist/protocols/open-responses-continuation.js +161 -0
- package/dist/protocols/open-responses.d.ts +1583 -0
- package/dist/protocols/open-responses.js +1206 -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-images.d.ts +22 -0
- package/dist/protocols/zai-images.js +79 -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 +11 -0
- package/dist/provider-package.js +1 -0
- package/dist/provider.d.ts +23 -0
- package/dist/provider.js +2 -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 +371 -0
- package/dist/providers/amazon-bedrock-mantle.js +76 -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 +304 -0
- package/dist/providers/anthropic-compatible.js +44 -0
- package/dist/providers/anthropic.d.ts +302 -0
- package/dist/providers/anthropic.js +39 -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 +599 -0
- package/dist/providers/azure.js +115 -0
- package/dist/providers/baseten.d.ts +229 -0
- package/dist/providers/baseten.js +38 -0
- package/dist/providers/cerebras.d.ts +228 -0
- package/dist/providers/cerebras.js +40 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +238 -0
- package/dist/providers/cloudflare-ai-gateway.js +59 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +232 -0
- package/dist/providers/cloudflare-workers-ai.js +45 -0
- package/dist/providers/deepinfra.d.ts +228 -0
- package/dist/providers/deepinfra.js +43 -0
- package/dist/providers/deepseek.d.ts +229 -0
- package/dist/providers/deepseek.js +41 -0
- package/dist/providers/fireworks.d.ts +229 -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 +133 -0
- package/dist/providers/google-vertex-chat.js +55 -0
- package/dist/providers/google-vertex-messages.d.ts +301 -0
- package/dist/providers/google-vertex-messages.js +75 -0
- package/dist/providers/google-vertex-responses.d.ts +198 -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 +61 -0
- package/dist/providers/google-vertex.d.ts +120 -0
- package/dist/providers/google-vertex.js +92 -0
- package/dist/providers/google.d.ts +115 -0
- package/dist/providers/google.js +42 -0
- package/dist/providers/groq.d.ts +315 -0
- package/dist/providers/groq.js +81 -0
- package/dist/providers/index.d.ts +28 -0
- package/dist/providers/index.js +28 -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 +631 -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 +593 -0
- package/dist/providers/minimax.js +89 -0
- package/dist/providers/mistral.d.ts +208 -0
- package/dist/providers/mistral.js +28 -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 +196 -0
- package/dist/providers/openai-compatible-responses.js +32 -0
- package/dist/providers/openai-compatible.d.ts +131 -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 +405 -0
- package/dist/providers/openai.js +82 -0
- package/dist/providers/openrouter.d.ts +564 -0
- package/dist/providers/openrouter.js +114 -0
- package/dist/providers/togetherai.d.ts +228 -0
- package/dist/providers/togetherai.js +40 -0
- package/dist/providers/xai.d.ts +164 -0
- package/dist/providers/xai.js +84 -0
- package/dist/providers/zai.d.ts +24 -0
- package/dist/providers/zai.js +21 -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 +304 -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 +366 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +158 -0
- package/dist/schema/errors.js +120 -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 +157 -0
- package/dist/schema/options.js +187 -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 +48 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import type { Config, Redacted } from "effect";
|
|
2
|
+
import type { ProviderPackage } from "../provider-package.js";
|
|
3
|
+
import type { AtLeastOne, ProviderAuthOption } from "../route/auth-options.js";
|
|
4
|
+
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
5
|
+
import { type ModelID } from "../schema/index.js";
|
|
6
|
+
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
7
|
+
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
8
|
+
export declare const authEnvVars: readonly ["CLOUDFLARE_API_TOKEN", "CF_AIG_TOKEN"];
|
|
9
|
+
type GatewayURL = AtLeastOne<{
|
|
10
|
+
readonly accountId: string;
|
|
11
|
+
readonly baseURL: string;
|
|
12
|
+
}> & {
|
|
13
|
+
readonly gatewayId?: string;
|
|
14
|
+
};
|
|
15
|
+
export type LanguageModelOptions = GatewayURL & Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
16
|
+
/** Cloudflare AI Gateway authentication token. Sent as `cf-aig-authorization`. */
|
|
17
|
+
readonly gatewayApiKey?: string | Redacted.Redacted | Config.Config<string | Redacted.Redacted>;
|
|
18
|
+
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
19
|
+
};
|
|
20
|
+
export type Settings = ProviderPackage.Settings & GatewayURL & {
|
|
21
|
+
readonly apiKey?: string;
|
|
22
|
+
readonly gatewayApiKey?: string;
|
|
23
|
+
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
24
|
+
};
|
|
25
|
+
export declare const baseURL: (input: GatewayURL) => string;
|
|
26
|
+
export declare const route: Route<{
|
|
27
|
+
readonly model: string;
|
|
28
|
+
readonly messages: readonly ({
|
|
29
|
+
readonly role: "system";
|
|
30
|
+
readonly content: string | readonly ({
|
|
31
|
+
readonly type: "text";
|
|
32
|
+
readonly text: string;
|
|
33
|
+
readonly cache_control?: {
|
|
34
|
+
readonly type: "ephemeral";
|
|
35
|
+
readonly ttl?: string | undefined;
|
|
36
|
+
} | undefined;
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "image_url";
|
|
39
|
+
readonly image_url: {
|
|
40
|
+
readonly url: string;
|
|
41
|
+
};
|
|
42
|
+
})[];
|
|
43
|
+
} | {
|
|
44
|
+
readonly role: "user";
|
|
45
|
+
readonly content: string | readonly ({
|
|
46
|
+
readonly type: "text";
|
|
47
|
+
readonly text: string;
|
|
48
|
+
readonly cache_control?: {
|
|
49
|
+
readonly type: "ephemeral";
|
|
50
|
+
readonly ttl?: string | undefined;
|
|
51
|
+
} | undefined;
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "image_url";
|
|
54
|
+
readonly image_url: {
|
|
55
|
+
readonly url: string;
|
|
56
|
+
};
|
|
57
|
+
})[];
|
|
58
|
+
} | {
|
|
59
|
+
readonly [x: string]: unknown;
|
|
60
|
+
readonly content: string | null;
|
|
61
|
+
readonly role: "assistant";
|
|
62
|
+
readonly reasoning?: string | undefined;
|
|
63
|
+
readonly reasoning_content?: string | undefined;
|
|
64
|
+
readonly reasoning_text?: string | undefined;
|
|
65
|
+
readonly cache_control?: {
|
|
66
|
+
readonly type: "ephemeral";
|
|
67
|
+
readonly ttl?: string | undefined;
|
|
68
|
+
} | undefined;
|
|
69
|
+
readonly tool_calls?: readonly {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly type: "function";
|
|
72
|
+
readonly function: {
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly arguments: string;
|
|
75
|
+
};
|
|
76
|
+
}[] | undefined;
|
|
77
|
+
readonly reasoning_details?: unknown;
|
|
78
|
+
} | {
|
|
79
|
+
readonly content: string;
|
|
80
|
+
readonly role: "tool";
|
|
81
|
+
readonly tool_call_id: string;
|
|
82
|
+
readonly cache_control?: {
|
|
83
|
+
readonly type: "ephemeral";
|
|
84
|
+
readonly ttl?: string | undefined;
|
|
85
|
+
} | undefined;
|
|
86
|
+
})[];
|
|
87
|
+
readonly stream: true;
|
|
88
|
+
readonly max_completion_tokens?: number | undefined;
|
|
89
|
+
readonly max_tokens?: number | undefined;
|
|
90
|
+
readonly tools?: readonly {
|
|
91
|
+
readonly function: {
|
|
92
|
+
readonly description: string;
|
|
93
|
+
readonly name: string;
|
|
94
|
+
readonly parameters: {
|
|
95
|
+
readonly [x: string]: unknown;
|
|
96
|
+
};
|
|
97
|
+
readonly strict?: boolean | undefined;
|
|
98
|
+
};
|
|
99
|
+
readonly type: "function";
|
|
100
|
+
readonly cache_control?: {
|
|
101
|
+
readonly type: "ephemeral";
|
|
102
|
+
readonly ttl?: string | undefined;
|
|
103
|
+
} | undefined;
|
|
104
|
+
}[] | undefined;
|
|
105
|
+
readonly stop?: readonly string[] | undefined;
|
|
106
|
+
readonly temperature?: number | undefined;
|
|
107
|
+
readonly seed?: number | undefined;
|
|
108
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
109
|
+
readonly type: "function";
|
|
110
|
+
readonly function: {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
};
|
|
113
|
+
} | undefined;
|
|
114
|
+
readonly top_p?: number | undefined;
|
|
115
|
+
readonly frequency_penalty?: number | undefined;
|
|
116
|
+
readonly presence_penalty?: number | undefined;
|
|
117
|
+
readonly prompt_cache_key?: string | undefined;
|
|
118
|
+
readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
|
|
119
|
+
readonly store?: boolean | undefined;
|
|
120
|
+
readonly stream_options?: {
|
|
121
|
+
readonly include_usage: boolean;
|
|
122
|
+
} | undefined;
|
|
123
|
+
readonly tool_stream?: boolean | undefined;
|
|
124
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
|
|
125
|
+
export declare const routes: Route<{
|
|
126
|
+
readonly model: string;
|
|
127
|
+
readonly messages: readonly ({
|
|
128
|
+
readonly role: "system";
|
|
129
|
+
readonly content: string | readonly ({
|
|
130
|
+
readonly type: "text";
|
|
131
|
+
readonly text: string;
|
|
132
|
+
readonly cache_control?: {
|
|
133
|
+
readonly type: "ephemeral";
|
|
134
|
+
readonly ttl?: string | undefined;
|
|
135
|
+
} | undefined;
|
|
136
|
+
} | {
|
|
137
|
+
readonly type: "image_url";
|
|
138
|
+
readonly image_url: {
|
|
139
|
+
readonly url: string;
|
|
140
|
+
};
|
|
141
|
+
})[];
|
|
142
|
+
} | {
|
|
143
|
+
readonly role: "user";
|
|
144
|
+
readonly content: string | readonly ({
|
|
145
|
+
readonly type: "text";
|
|
146
|
+
readonly text: string;
|
|
147
|
+
readonly cache_control?: {
|
|
148
|
+
readonly type: "ephemeral";
|
|
149
|
+
readonly ttl?: string | undefined;
|
|
150
|
+
} | undefined;
|
|
151
|
+
} | {
|
|
152
|
+
readonly type: "image_url";
|
|
153
|
+
readonly image_url: {
|
|
154
|
+
readonly url: string;
|
|
155
|
+
};
|
|
156
|
+
})[];
|
|
157
|
+
} | {
|
|
158
|
+
readonly [x: string]: unknown;
|
|
159
|
+
readonly content: string | null;
|
|
160
|
+
readonly role: "assistant";
|
|
161
|
+
readonly reasoning?: string | undefined;
|
|
162
|
+
readonly reasoning_content?: string | undefined;
|
|
163
|
+
readonly reasoning_text?: string | undefined;
|
|
164
|
+
readonly cache_control?: {
|
|
165
|
+
readonly type: "ephemeral";
|
|
166
|
+
readonly ttl?: string | undefined;
|
|
167
|
+
} | undefined;
|
|
168
|
+
readonly tool_calls?: readonly {
|
|
169
|
+
readonly id: string;
|
|
170
|
+
readonly type: "function";
|
|
171
|
+
readonly function: {
|
|
172
|
+
readonly name: string;
|
|
173
|
+
readonly arguments: string;
|
|
174
|
+
};
|
|
175
|
+
}[] | undefined;
|
|
176
|
+
readonly reasoning_details?: unknown;
|
|
177
|
+
} | {
|
|
178
|
+
readonly content: string;
|
|
179
|
+
readonly role: "tool";
|
|
180
|
+
readonly tool_call_id: string;
|
|
181
|
+
readonly cache_control?: {
|
|
182
|
+
readonly type: "ephemeral";
|
|
183
|
+
readonly ttl?: string | undefined;
|
|
184
|
+
} | undefined;
|
|
185
|
+
})[];
|
|
186
|
+
readonly stream: true;
|
|
187
|
+
readonly max_completion_tokens?: number | undefined;
|
|
188
|
+
readonly max_tokens?: number | undefined;
|
|
189
|
+
readonly tools?: readonly {
|
|
190
|
+
readonly function: {
|
|
191
|
+
readonly description: string;
|
|
192
|
+
readonly name: string;
|
|
193
|
+
readonly parameters: {
|
|
194
|
+
readonly [x: string]: unknown;
|
|
195
|
+
};
|
|
196
|
+
readonly strict?: boolean | undefined;
|
|
197
|
+
};
|
|
198
|
+
readonly type: "function";
|
|
199
|
+
readonly cache_control?: {
|
|
200
|
+
readonly type: "ephemeral";
|
|
201
|
+
readonly ttl?: string | undefined;
|
|
202
|
+
} | undefined;
|
|
203
|
+
}[] | undefined;
|
|
204
|
+
readonly stop?: readonly string[] | undefined;
|
|
205
|
+
readonly temperature?: number | undefined;
|
|
206
|
+
readonly seed?: number | undefined;
|
|
207
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
208
|
+
readonly type: "function";
|
|
209
|
+
readonly function: {
|
|
210
|
+
readonly name: string;
|
|
211
|
+
};
|
|
212
|
+
} | undefined;
|
|
213
|
+
readonly top_p?: number | undefined;
|
|
214
|
+
readonly frequency_penalty?: number | undefined;
|
|
215
|
+
readonly presence_penalty?: number | undefined;
|
|
216
|
+
readonly prompt_cache_key?: string | undefined;
|
|
217
|
+
readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
|
|
218
|
+
readonly store?: boolean | undefined;
|
|
219
|
+
readonly stream_options?: {
|
|
220
|
+
readonly include_usage: boolean;
|
|
221
|
+
} | undefined;
|
|
222
|
+
readonly tool_stream?: boolean | undefined;
|
|
223
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
|
|
224
|
+
export declare const configure: (input: LanguageModelOptions) => {
|
|
225
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
226
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
227
|
+
configure: (input: LanguageModelOptions) => /*elided*/ any;
|
|
228
|
+
};
|
|
229
|
+
export declare const provider: {
|
|
230
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
231
|
+
configure: (input: LanguageModelOptions) => {
|
|
232
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
233
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
234
|
+
configure: /*elided*/ any;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
export declare const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
|
|
238
|
+
export * as CloudflareAIGateway from "./cloudflare-ai-gateway.js";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
2
|
+
import { Auth } from "../route/auth.js";
|
|
3
|
+
import { Route } from "../route/client.js";
|
|
4
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
+
import { ProviderID } from "../schema/index.js";
|
|
6
|
+
export const id = ProviderID.make("cloudflare-ai-gateway");
|
|
7
|
+
export const authEnvVars = ["CLOUDFLARE_API_TOKEN", "CF_AIG_TOKEN"];
|
|
8
|
+
export const baseURL = (input) => {
|
|
9
|
+
if (input.baseURL)
|
|
10
|
+
return input.baseURL;
|
|
11
|
+
if (!input.accountId)
|
|
12
|
+
throw new Error("CloudflareAIGateway.configure requires accountId unless baseURL is supplied");
|
|
13
|
+
return `https://gateway.ai.cloudflare.com/v1/${encodeURIComponent(input.accountId)}/${encodeURIComponent(input.gatewayId?.trim() || "default")}/compat`;
|
|
14
|
+
};
|
|
15
|
+
const auth = (input) => {
|
|
16
|
+
if ("auth" in input && input.auth)
|
|
17
|
+
return input.auth;
|
|
18
|
+
const gateway = Auth.optional(input.gatewayApiKey, "gatewayApiKey")
|
|
19
|
+
.orElse(Auth.config(authEnvVars[0]))
|
|
20
|
+
.orElse(Auth.config(authEnvVars[1]))
|
|
21
|
+
.pipe(Auth.bearerHeader("cf-aig-authorization"));
|
|
22
|
+
if (!("apiKey" in input) || input.apiKey === undefined)
|
|
23
|
+
return gateway;
|
|
24
|
+
if (input.gatewayApiKey === undefined)
|
|
25
|
+
return Auth.bearer(input.apiKey);
|
|
26
|
+
return Auth.bearerHeader("cf-aig-authorization", input.gatewayApiKey).andThen(Auth.bearer(input.apiKey));
|
|
27
|
+
};
|
|
28
|
+
export const route = Route.make({
|
|
29
|
+
id: "cloudflare-ai-gateway",
|
|
30
|
+
provider: id,
|
|
31
|
+
providerMetadataKey: "cloudflare-ai-gateway",
|
|
32
|
+
protocol: OpenAIChat.protocol,
|
|
33
|
+
endpoint: Endpoint.path("/chat/completions"),
|
|
34
|
+
framing: OpenAIChat.framing,
|
|
35
|
+
});
|
|
36
|
+
export const routes = [route];
|
|
37
|
+
export const configure = (input) => {
|
|
38
|
+
const { accountId: _accountId, gatewayId: _gatewayId, apiKey: _apiKey, gatewayApiKey: _gatewayApiKey, baseURL: _baseURL, auth: _auth, ...defaults } = input;
|
|
39
|
+
const configured = route.with({
|
|
40
|
+
...defaults,
|
|
41
|
+
endpoint: { baseURL: baseURL(input) },
|
|
42
|
+
auth: auth(input),
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
id,
|
|
46
|
+
model: (modelID) => configured.model({ id: modelID }),
|
|
47
|
+
configure,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export const provider = { id, configure };
|
|
51
|
+
export const model = (modelID, settings) => configure({
|
|
52
|
+
apiKey: settings.apiKey,
|
|
53
|
+
gatewayApiKey: settings.gatewayApiKey,
|
|
54
|
+
baseURL: baseURL(settings),
|
|
55
|
+
headers: settings.headers === undefined ? undefined : { ...settings.headers },
|
|
56
|
+
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
|
|
57
|
+
providerOptions: settings.providerOptions,
|
|
58
|
+
}).model(modelID);
|
|
59
|
+
export * as CloudflareAIGateway from "./cloudflare-ai-gateway.js";
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
+
import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js";
|
|
3
|
+
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
4
|
+
import { type ModelID } from "../schema/index.js";
|
|
5
|
+
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
|
|
6
|
+
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
|
+
export declare const authEnvVars: readonly ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN"];
|
|
8
|
+
type WorkersAIURL = AtLeastOne<{
|
|
9
|
+
readonly accountId: string;
|
|
10
|
+
readonly baseURL: string;
|
|
11
|
+
}>;
|
|
12
|
+
export type LanguageModelOptions = WorkersAIURL & Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
13
|
+
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
14
|
+
};
|
|
15
|
+
export type Settings = ProviderPackage.Settings & WorkersAIURL & {
|
|
16
|
+
readonly apiKey?: string;
|
|
17
|
+
readonly providerOptions?: OpenAIProviderOptionsInput;
|
|
18
|
+
};
|
|
19
|
+
export declare const baseURL: (input: WorkersAIURL) => string;
|
|
20
|
+
export declare const route: Route<{
|
|
21
|
+
readonly model: string;
|
|
22
|
+
readonly messages: readonly ({
|
|
23
|
+
readonly role: "system";
|
|
24
|
+
readonly content: string | readonly ({
|
|
25
|
+
readonly type: "text";
|
|
26
|
+
readonly text: string;
|
|
27
|
+
readonly cache_control?: {
|
|
28
|
+
readonly type: "ephemeral";
|
|
29
|
+
readonly ttl?: string | undefined;
|
|
30
|
+
} | undefined;
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "image_url";
|
|
33
|
+
readonly image_url: {
|
|
34
|
+
readonly url: string;
|
|
35
|
+
};
|
|
36
|
+
})[];
|
|
37
|
+
} | {
|
|
38
|
+
readonly role: "user";
|
|
39
|
+
readonly content: string | readonly ({
|
|
40
|
+
readonly type: "text";
|
|
41
|
+
readonly text: string;
|
|
42
|
+
readonly cache_control?: {
|
|
43
|
+
readonly type: "ephemeral";
|
|
44
|
+
readonly ttl?: string | undefined;
|
|
45
|
+
} | undefined;
|
|
46
|
+
} | {
|
|
47
|
+
readonly type: "image_url";
|
|
48
|
+
readonly image_url: {
|
|
49
|
+
readonly url: string;
|
|
50
|
+
};
|
|
51
|
+
})[];
|
|
52
|
+
} | {
|
|
53
|
+
readonly [x: string]: unknown;
|
|
54
|
+
readonly content: string | null;
|
|
55
|
+
readonly role: "assistant";
|
|
56
|
+
readonly reasoning?: string | undefined;
|
|
57
|
+
readonly reasoning_content?: string | undefined;
|
|
58
|
+
readonly reasoning_text?: string | undefined;
|
|
59
|
+
readonly cache_control?: {
|
|
60
|
+
readonly type: "ephemeral";
|
|
61
|
+
readonly ttl?: string | undefined;
|
|
62
|
+
} | undefined;
|
|
63
|
+
readonly tool_calls?: readonly {
|
|
64
|
+
readonly id: string;
|
|
65
|
+
readonly type: "function";
|
|
66
|
+
readonly function: {
|
|
67
|
+
readonly name: string;
|
|
68
|
+
readonly arguments: string;
|
|
69
|
+
};
|
|
70
|
+
}[] | undefined;
|
|
71
|
+
readonly reasoning_details?: unknown;
|
|
72
|
+
} | {
|
|
73
|
+
readonly content: string;
|
|
74
|
+
readonly role: "tool";
|
|
75
|
+
readonly tool_call_id: string;
|
|
76
|
+
readonly cache_control?: {
|
|
77
|
+
readonly type: "ephemeral";
|
|
78
|
+
readonly ttl?: string | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
})[];
|
|
81
|
+
readonly stream: true;
|
|
82
|
+
readonly max_completion_tokens?: number | undefined;
|
|
83
|
+
readonly max_tokens?: number | undefined;
|
|
84
|
+
readonly tools?: readonly {
|
|
85
|
+
readonly function: {
|
|
86
|
+
readonly description: string;
|
|
87
|
+
readonly name: string;
|
|
88
|
+
readonly parameters: {
|
|
89
|
+
readonly [x: string]: unknown;
|
|
90
|
+
};
|
|
91
|
+
readonly strict?: boolean | undefined;
|
|
92
|
+
};
|
|
93
|
+
readonly type: "function";
|
|
94
|
+
readonly cache_control?: {
|
|
95
|
+
readonly type: "ephemeral";
|
|
96
|
+
readonly ttl?: string | undefined;
|
|
97
|
+
} | undefined;
|
|
98
|
+
}[] | undefined;
|
|
99
|
+
readonly stop?: readonly string[] | undefined;
|
|
100
|
+
readonly temperature?: number | undefined;
|
|
101
|
+
readonly seed?: number | undefined;
|
|
102
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
103
|
+
readonly type: "function";
|
|
104
|
+
readonly function: {
|
|
105
|
+
readonly name: string;
|
|
106
|
+
};
|
|
107
|
+
} | undefined;
|
|
108
|
+
readonly top_p?: number | undefined;
|
|
109
|
+
readonly frequency_penalty?: number | undefined;
|
|
110
|
+
readonly presence_penalty?: number | undefined;
|
|
111
|
+
readonly prompt_cache_key?: string | undefined;
|
|
112
|
+
readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
|
|
113
|
+
readonly store?: boolean | undefined;
|
|
114
|
+
readonly stream_options?: {
|
|
115
|
+
readonly include_usage: boolean;
|
|
116
|
+
} | undefined;
|
|
117
|
+
readonly tool_stream?: boolean | undefined;
|
|
118
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
|
|
119
|
+
export declare const routes: Route<{
|
|
120
|
+
readonly model: string;
|
|
121
|
+
readonly messages: readonly ({
|
|
122
|
+
readonly role: "system";
|
|
123
|
+
readonly content: string | readonly ({
|
|
124
|
+
readonly type: "text";
|
|
125
|
+
readonly text: string;
|
|
126
|
+
readonly cache_control?: {
|
|
127
|
+
readonly type: "ephemeral";
|
|
128
|
+
readonly ttl?: string | undefined;
|
|
129
|
+
} | undefined;
|
|
130
|
+
} | {
|
|
131
|
+
readonly type: "image_url";
|
|
132
|
+
readonly image_url: {
|
|
133
|
+
readonly url: string;
|
|
134
|
+
};
|
|
135
|
+
})[];
|
|
136
|
+
} | {
|
|
137
|
+
readonly role: "user";
|
|
138
|
+
readonly content: string | readonly ({
|
|
139
|
+
readonly type: "text";
|
|
140
|
+
readonly text: string;
|
|
141
|
+
readonly cache_control?: {
|
|
142
|
+
readonly type: "ephemeral";
|
|
143
|
+
readonly ttl?: string | undefined;
|
|
144
|
+
} | undefined;
|
|
145
|
+
} | {
|
|
146
|
+
readonly type: "image_url";
|
|
147
|
+
readonly image_url: {
|
|
148
|
+
readonly url: string;
|
|
149
|
+
};
|
|
150
|
+
})[];
|
|
151
|
+
} | {
|
|
152
|
+
readonly [x: string]: unknown;
|
|
153
|
+
readonly content: string | null;
|
|
154
|
+
readonly role: "assistant";
|
|
155
|
+
readonly reasoning?: string | undefined;
|
|
156
|
+
readonly reasoning_content?: string | undefined;
|
|
157
|
+
readonly reasoning_text?: string | undefined;
|
|
158
|
+
readonly cache_control?: {
|
|
159
|
+
readonly type: "ephemeral";
|
|
160
|
+
readonly ttl?: string | undefined;
|
|
161
|
+
} | undefined;
|
|
162
|
+
readonly tool_calls?: readonly {
|
|
163
|
+
readonly id: string;
|
|
164
|
+
readonly type: "function";
|
|
165
|
+
readonly function: {
|
|
166
|
+
readonly name: string;
|
|
167
|
+
readonly arguments: string;
|
|
168
|
+
};
|
|
169
|
+
}[] | undefined;
|
|
170
|
+
readonly reasoning_details?: unknown;
|
|
171
|
+
} | {
|
|
172
|
+
readonly content: string;
|
|
173
|
+
readonly role: "tool";
|
|
174
|
+
readonly tool_call_id: string;
|
|
175
|
+
readonly cache_control?: {
|
|
176
|
+
readonly type: "ephemeral";
|
|
177
|
+
readonly ttl?: string | undefined;
|
|
178
|
+
} | undefined;
|
|
179
|
+
})[];
|
|
180
|
+
readonly stream: true;
|
|
181
|
+
readonly max_completion_tokens?: number | undefined;
|
|
182
|
+
readonly max_tokens?: number | undefined;
|
|
183
|
+
readonly tools?: readonly {
|
|
184
|
+
readonly function: {
|
|
185
|
+
readonly description: string;
|
|
186
|
+
readonly name: string;
|
|
187
|
+
readonly parameters: {
|
|
188
|
+
readonly [x: string]: unknown;
|
|
189
|
+
};
|
|
190
|
+
readonly strict?: boolean | undefined;
|
|
191
|
+
};
|
|
192
|
+
readonly type: "function";
|
|
193
|
+
readonly cache_control?: {
|
|
194
|
+
readonly type: "ephemeral";
|
|
195
|
+
readonly ttl?: string | undefined;
|
|
196
|
+
} | undefined;
|
|
197
|
+
}[] | undefined;
|
|
198
|
+
readonly stop?: readonly string[] | undefined;
|
|
199
|
+
readonly temperature?: number | undefined;
|
|
200
|
+
readonly seed?: number | undefined;
|
|
201
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
202
|
+
readonly type: "function";
|
|
203
|
+
readonly function: {
|
|
204
|
+
readonly name: string;
|
|
205
|
+
};
|
|
206
|
+
} | undefined;
|
|
207
|
+
readonly top_p?: number | undefined;
|
|
208
|
+
readonly frequency_penalty?: number | undefined;
|
|
209
|
+
readonly presence_penalty?: number | undefined;
|
|
210
|
+
readonly prompt_cache_key?: string | undefined;
|
|
211
|
+
readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
|
|
212
|
+
readonly store?: boolean | undefined;
|
|
213
|
+
readonly stream_options?: {
|
|
214
|
+
readonly include_usage: boolean;
|
|
215
|
+
} | undefined;
|
|
216
|
+
readonly tool_stream?: boolean | undefined;
|
|
217
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
|
|
218
|
+
export declare const configure: (input: LanguageModelOptions) => {
|
|
219
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
220
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
221
|
+
configure: (input: LanguageModelOptions) => /*elided*/ any;
|
|
222
|
+
};
|
|
223
|
+
export declare const provider: {
|
|
224
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
225
|
+
configure: (input: LanguageModelOptions) => {
|
|
226
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
227
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
228
|
+
configure: /*elided*/ any;
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
export declare const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
|
|
232
|
+
export * as CloudflareWorkersAI from "./cloudflare-workers-ai.js";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
2
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
3
|
+
import { Route } from "../route/client.js";
|
|
4
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
+
import { ProviderID } from "../schema/index.js";
|
|
6
|
+
export const id = ProviderID.make("cloudflare-workers-ai");
|
|
7
|
+
export const authEnvVars = ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN"];
|
|
8
|
+
export const baseURL = (input) => {
|
|
9
|
+
if (input.baseURL)
|
|
10
|
+
return input.baseURL;
|
|
11
|
+
if (!input.accountId)
|
|
12
|
+
throw new Error("CloudflareWorkersAI.configure requires accountId unless baseURL is supplied");
|
|
13
|
+
return `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(input.accountId)}/ai/v1`;
|
|
14
|
+
};
|
|
15
|
+
export const route = Route.make({
|
|
16
|
+
id: "cloudflare-workers-ai",
|
|
17
|
+
provider: id,
|
|
18
|
+
providerMetadataKey: "cloudflare-workers-ai",
|
|
19
|
+
protocol: OpenAIChat.protocol,
|
|
20
|
+
endpoint: Endpoint.path("/chat/completions"),
|
|
21
|
+
framing: OpenAIChat.framing,
|
|
22
|
+
});
|
|
23
|
+
export const routes = [route];
|
|
24
|
+
export const configure = (input) => {
|
|
25
|
+
const { accountId: _accountId, apiKey: _apiKey, auth: _auth, baseURL: _baseURL, ...defaults } = input;
|
|
26
|
+
const configured = route.with({
|
|
27
|
+
...defaults,
|
|
28
|
+
endpoint: { baseURL: baseURL(input) },
|
|
29
|
+
auth: AuthOptions.bearer(input, authEnvVars),
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
id,
|
|
33
|
+
model: (modelID) => configured.model({ id: modelID }),
|
|
34
|
+
configure,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export const provider = { id, configure };
|
|
38
|
+
export const model = (modelID, settings) => configure({
|
|
39
|
+
apiKey: settings.apiKey,
|
|
40
|
+
baseURL: baseURL(settings),
|
|
41
|
+
headers: settings.headers === undefined ? undefined : { ...settings.headers },
|
|
42
|
+
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
|
|
43
|
+
providerOptions: settings.providerOptions,
|
|
44
|
+
}).model(modelID);
|
|
45
|
+
export * as CloudflareWorkersAI from "./cloudflare-workers-ai.js";
|