@opencode-ai/ai 0.0.0-beta-17492

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.
Files changed (194) hide show
  1. package/README.md +392 -0
  2. package/dist/cache-policy.d.ts +2 -0
  3. package/dist/cache-policy.js +121 -0
  4. package/dist/image-client.d.ts +19 -0
  5. package/dist/image-client.js +19 -0
  6. package/dist/image.d.ts +110 -0
  7. package/dist/image.js +102 -0
  8. package/dist/index.d.ts +18 -0
  9. package/dist/index.js +12 -0
  10. package/dist/llm.d.ts +230 -0
  11. package/dist/llm.js +77 -0
  12. package/dist/protocols/anthropic-messages.d.ts +633 -0
  13. package/dist/protocols/anthropic-messages.js +860 -0
  14. package/dist/protocols/bedrock-converse.d.ts +533 -0
  15. package/dist/protocols/bedrock-converse.js +584 -0
  16. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  17. package/dist/protocols/bedrock-event-stream.js +73 -0
  18. package/dist/protocols/gemini.d.ts +300 -0
  19. package/dist/protocols/gemini.js +512 -0
  20. package/dist/protocols/google-images.d.ts +30 -0
  21. package/dist/protocols/google-images.js +191 -0
  22. package/dist/protocols/index.d.ts +10 -0
  23. package/dist/protocols/index.js +10 -0
  24. package/dist/protocols/open-responses-channel.d.ts +26 -0
  25. package/dist/protocols/open-responses-channel.js +120 -0
  26. package/dist/protocols/open-responses.d.ts +951 -0
  27. package/dist/protocols/open-responses.js +873 -0
  28. package/dist/protocols/openai-chat.d.ts +795 -0
  29. package/dist/protocols/openai-chat.js +718 -0
  30. package/dist/protocols/openai-compatible-chat.d.ts +107 -0
  31. package/dist/protocols/openai-compatible-chat.js +20 -0
  32. package/dist/protocols/openai-compatible-responses.d.ts +96 -0
  33. package/dist/protocols/openai-compatible-responses.js +17 -0
  34. package/dist/protocols/openai-images.d.ts +32 -0
  35. package/dist/protocols/openai-images.js +188 -0
  36. package/dist/protocols/openai-responses-channel.d.ts +12 -0
  37. package/dist/protocols/openai-responses-channel.js +142 -0
  38. package/dist/protocols/openai-responses.d.ts +596 -0
  39. package/dist/protocols/openai-responses.js +208 -0
  40. package/dist/protocols/shared.d.ts +194 -0
  41. package/dist/protocols/shared.js +238 -0
  42. package/dist/protocols/utils/bedrock-auth.d.ts +21 -0
  43. package/dist/protocols/utils/bedrock-auth.js +43 -0
  44. package/dist/protocols/utils/bedrock-cache.d.ts +15 -0
  45. package/dist/protocols/utils/bedrock-cache.js +29 -0
  46. package/dist/protocols/utils/bedrock-media.d.ts +49 -0
  47. package/dist/protocols/utils/bedrock-media.js +70 -0
  48. package/dist/protocols/utils/cache.d.ts +6 -0
  49. package/dist/protocols/utils/cache.js +8 -0
  50. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  51. package/dist/protocols/utils/gemini-tool-schema.js +103 -0
  52. package/dist/protocols/utils/image-input.d.ts +21 -0
  53. package/dist/protocols/utils/image-input.js +22 -0
  54. package/dist/protocols/utils/lifecycle.d.ts +20 -0
  55. package/dist/protocols/utils/lifecycle.js +68 -0
  56. package/dist/protocols/utils/open-responses-options.d.ts +21 -0
  57. package/dist/protocols/utils/open-responses-options.js +41 -0
  58. package/dist/protocols/utils/openai-image.d.ts +5 -0
  59. package/dist/protocols/utils/openai-image.js +18 -0
  60. package/dist/protocols/utils/openai-options.d.ts +14 -0
  61. package/dist/protocols/utils/openai-options.js +14 -0
  62. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  63. package/dist/protocols/utils/tool-schema.js +81 -0
  64. package/dist/protocols/utils/tool-stream.d.ts +639 -0
  65. package/dist/protocols/utils/tool-stream.js +141 -0
  66. package/dist/protocols/xai-images.d.ts +26 -0
  67. package/dist/protocols/xai-images.js +111 -0
  68. package/dist/protocols/zai-images.d.ts +22 -0
  69. package/dist/protocols/zai-images.js +84 -0
  70. package/dist/protocols.d.ts +1 -0
  71. package/dist/protocols.js +1 -0
  72. package/dist/provider-error.d.ts +14 -0
  73. package/dist/provider-error.js +130 -0
  74. package/dist/provider-package.d.ts +15 -0
  75. package/dist/provider-package.js +1 -0
  76. package/dist/provider.d.ts +23 -0
  77. package/dist/provider.js +2 -0
  78. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  79. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  80. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  81. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  82. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  83. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  84. package/dist/providers/amazon-bedrock-mantle.d.ts +247 -0
  85. package/dist/providers/amazon-bedrock-mantle.js +68 -0
  86. package/dist/providers/amazon-bedrock.d.ts +172 -0
  87. package/dist/providers/amazon-bedrock.js +41 -0
  88. package/dist/providers/anthropic-compatible.d.ts +218 -0
  89. package/dist/providers/anthropic-compatible.js +45 -0
  90. package/dist/providers/anthropic.d.ts +216 -0
  91. package/dist/providers/anthropic.js +40 -0
  92. package/dist/providers/azure/chat.d.ts +2 -0
  93. package/dist/providers/azure/chat.js +1 -0
  94. package/dist/providers/azure/responses.d.ts +2 -0
  95. package/dist/providers/azure/responses.js +1 -0
  96. package/dist/providers/azure.d.ts +248 -0
  97. package/dist/providers/azure.js +90 -0
  98. package/dist/providers/cloudflare.d.ts +338 -0
  99. package/dist/providers/cloudflare.js +87 -0
  100. package/dist/providers/google-vertex/chat.d.ts +2 -0
  101. package/dist/providers/google-vertex/chat.js +1 -0
  102. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  103. package/dist/providers/google-vertex/gemini.js +1 -0
  104. package/dist/providers/google-vertex/messages.d.ts +2 -0
  105. package/dist/providers/google-vertex/messages.js +1 -0
  106. package/dist/providers/google-vertex/responses.d.ts +2 -0
  107. package/dist/providers/google-vertex/responses.js +1 -0
  108. package/dist/providers/google-vertex-chat.d.ts +131 -0
  109. package/dist/providers/google-vertex-chat.js +50 -0
  110. package/dist/providers/google-vertex-messages.d.ts +215 -0
  111. package/dist/providers/google-vertex-messages.js +75 -0
  112. package/dist/providers/google-vertex-responses.d.ts +122 -0
  113. package/dist/providers/google-vertex-responses.js +51 -0
  114. package/dist/providers/google-vertex-shared.d.ts +22 -0
  115. package/dist/providers/google-vertex-shared.js +61 -0
  116. package/dist/providers/google-vertex.d.ts +115 -0
  117. package/dist/providers/google-vertex.js +64 -0
  118. package/dist/providers/google.d.ts +112 -0
  119. package/dist/providers/google.js +43 -0
  120. package/dist/providers/index.d.ts +18 -0
  121. package/dist/providers/index.js +18 -0
  122. package/dist/providers/open-responses-options.d.ts +16 -0
  123. package/dist/providers/open-responses-options.js +1 -0
  124. package/dist/providers/openai/chat.d.ts +2 -0
  125. package/dist/providers/openai/chat.js +1 -0
  126. package/dist/providers/openai/responses.d.ts +2 -0
  127. package/dist/providers/openai/responses.js +1 -0
  128. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  129. package/dist/providers/openai-compatible/responses.js +1 -0
  130. package/dist/providers/openai-compatible-profile.d.ts +43 -0
  131. package/dist/providers/openai-compatible-profile.js +12 -0
  132. package/dist/providers/openai-compatible-responses.d.ts +120 -0
  133. package/dist/providers/openai-compatible-responses.js +33 -0
  134. package/dist/providers/openai-compatible.d.ts +167 -0
  135. package/dist/providers/openai-compatible.js +55 -0
  136. package/dist/providers/openai-options.d.ts +21 -0
  137. package/dist/providers/openai-options.js +41 -0
  138. package/dist/providers/openai.d.ts +264 -0
  139. package/dist/providers/openai.js +83 -0
  140. package/dist/providers/openrouter.d.ts +537 -0
  141. package/dist/providers/openrouter.js +117 -0
  142. package/dist/providers/xai.d.ts +249 -0
  143. package/dist/providers/xai.js +79 -0
  144. package/dist/providers/zai.d.ts +24 -0
  145. package/dist/providers/zai.js +21 -0
  146. package/dist/providers.d.ts +1 -0
  147. package/dist/providers.js +1 -0
  148. package/dist/route/auth-options.d.ts +34 -0
  149. package/dist/route/auth-options.js +14 -0
  150. package/dist/route/auth.d.ts +51 -0
  151. package/dist/route/auth.js +89 -0
  152. package/dist/route/client.d.ts +348 -0
  153. package/dist/route/client.js +214 -0
  154. package/dist/route/endpoint.d.ts +28 -0
  155. package/dist/route/endpoint.js +21 -0
  156. package/dist/route/executor.d.ts +23 -0
  157. package/dist/route/executor.js +227 -0
  158. package/dist/route/framing.d.ts +23 -0
  159. package/dist/route/framing.js +4 -0
  160. package/dist/route/index.d.ts +16 -0
  161. package/dist/route/index.js +9 -0
  162. package/dist/route/protocol.d.ts +77 -0
  163. package/dist/route/protocol.js +17 -0
  164. package/dist/route/transport/http.d.ts +34 -0
  165. package/dist/route/transport/http.js +63 -0
  166. package/dist/route/transport/index.d.ts +39 -0
  167. package/dist/route/transport/index.js +4 -0
  168. package/dist/route/transport/websocket-channel.d.ts +56 -0
  169. package/dist/route/transport/websocket-channel.js +1 -0
  170. package/dist/route/transport/websocket.d.ts +55 -0
  171. package/dist/route/transport/websocket.js +326 -0
  172. package/dist/route.d.ts +1 -0
  173. package/dist/route.js +1 -0
  174. package/dist/schema/errors.d.ts +159 -0
  175. package/dist/schema/errors.js +155 -0
  176. package/dist/schema/events.d.ts +4587 -0
  177. package/dist/schema/events.js +492 -0
  178. package/dist/schema/ids.d.ts +30 -0
  179. package/dist/schema/ids.js +19 -0
  180. package/dist/schema/index.d.ts +5 -0
  181. package/dist/schema/index.js +5 -0
  182. package/dist/schema/messages.d.ts +402 -0
  183. package/dist/schema/messages.js +244 -0
  184. package/dist/schema/options.d.ts +159 -0
  185. package/dist/schema/options.js +202 -0
  186. package/dist/testing.d.ts +1493 -0
  187. package/dist/testing.js +88 -0
  188. package/dist/tool-runtime.d.ts +15 -0
  189. package/dist/tool-runtime.js +54 -0
  190. package/dist/tool.d.ts +135 -0
  191. package/dist/tool.js +66 -0
  192. package/dist/utils/record.d.ts +2 -0
  193. package/dist/utils/record.js +2 -0
  194. package/package.json +47 -0
@@ -0,0 +1,248 @@
1
+ import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js";
2
+ import type { Route as RouteDef, RouteDefaultsInput } from "../route/client.js";
3
+ import type { ProviderPackage } from "../provider-package.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
+ type AzureURL = AtLeastOne<{
8
+ readonly resourceName: string;
9
+ readonly baseURL: string;
10
+ }>;
11
+ export type LanguageModelOptions = AzureURL & RouteDefaultsInput & ProviderAuthOption<"optional"> & {
12
+ readonly apiVersion?: string;
13
+ readonly queryParams?: Record<string, string>;
14
+ readonly useDeploymentBasedUrls?: boolean;
15
+ readonly providerOptions?: OpenAIProviderOptionsInput;
16
+ };
17
+ export type Config = LanguageModelOptions;
18
+ export type Settings = ProviderPackage.Settings & AzureURL & {
19
+ readonly apiKey?: string;
20
+ readonly apiVersion?: string;
21
+ readonly queryParams?: Readonly<Record<string, string>>;
22
+ readonly useDeploymentBasedUrls?: boolean;
23
+ readonly providerOptions?: OpenAIProviderOptionsInput;
24
+ };
25
+ export declare const routes: (RouteDef<{
26
+ readonly model: string;
27
+ readonly messages: readonly ({
28
+ readonly role: "system";
29
+ readonly content: string | readonly ({
30
+ readonly type: "text";
31
+ readonly text: string;
32
+ readonly cache_control?: {
33
+ readonly type: "ephemeral";
34
+ readonly ttl?: string | undefined;
35
+ } | undefined;
36
+ } | {
37
+ readonly type: "image_url";
38
+ readonly image_url: {
39
+ readonly url: string;
40
+ };
41
+ })[];
42
+ } | {
43
+ readonly role: "user";
44
+ readonly content: string | readonly ({
45
+ readonly type: "text";
46
+ readonly text: string;
47
+ readonly cache_control?: {
48
+ readonly type: "ephemeral";
49
+ readonly ttl?: string | undefined;
50
+ } | undefined;
51
+ } | {
52
+ readonly type: "image_url";
53
+ readonly image_url: {
54
+ readonly url: string;
55
+ };
56
+ })[];
57
+ } | {
58
+ readonly [x: string]: unknown;
59
+ readonly content: string | null;
60
+ readonly role: "assistant";
61
+ readonly reasoning?: string | undefined;
62
+ readonly reasoning_content?: string | undefined;
63
+ readonly reasoning_text?: string | undefined;
64
+ readonly cache_control?: {
65
+ readonly type: "ephemeral";
66
+ readonly ttl?: string | undefined;
67
+ } | undefined;
68
+ readonly tool_calls?: readonly {
69
+ readonly id: string;
70
+ readonly type: "function";
71
+ readonly function: {
72
+ readonly name: string;
73
+ readonly arguments: string;
74
+ };
75
+ }[] | undefined;
76
+ readonly reasoning_details?: unknown;
77
+ } | {
78
+ readonly content: string;
79
+ readonly role: "tool";
80
+ readonly tool_call_id: string;
81
+ readonly cache_control?: {
82
+ readonly type: "ephemeral";
83
+ readonly ttl?: string | undefined;
84
+ } | undefined;
85
+ })[];
86
+ readonly stream: true;
87
+ readonly stop?: readonly string[] | undefined;
88
+ readonly max_completion_tokens?: number | undefined;
89
+ readonly max_tokens?: number | undefined;
90
+ readonly tools?: readonly {
91
+ readonly function: {
92
+ readonly name: string;
93
+ readonly description: string;
94
+ readonly parameters: {
95
+ readonly [x: string]: unknown;
96
+ };
97
+ };
98
+ readonly type: "function";
99
+ readonly cache_control?: {
100
+ readonly type: "ephemeral";
101
+ readonly ttl?: string | undefined;
102
+ } | undefined;
103
+ }[] | undefined;
104
+ readonly temperature?: number | undefined;
105
+ readonly seed?: number | undefined;
106
+ readonly tool_choice?: "required" | "none" | "auto" | {
107
+ readonly type: "function";
108
+ readonly function: {
109
+ readonly name: string;
110
+ };
111
+ } | undefined;
112
+ readonly top_p?: number | undefined;
113
+ readonly store?: boolean | undefined;
114
+ readonly stream_options?: {
115
+ readonly include_usage: boolean;
116
+ } | undefined;
117
+ readonly prompt_cache_key?: string | undefined;
118
+ readonly reasoning_effort?: string | undefined;
119
+ readonly frequency_penalty?: number | undefined;
120
+ readonly presence_penalty?: number | undefined;
121
+ }, import("../route/transport/http.js").HttpPrepared<string>> | RouteDef<{
122
+ readonly input: readonly ({
123
+ readonly type: "reasoning";
124
+ readonly summary: readonly {
125
+ readonly type: "summary_text";
126
+ readonly text: string;
127
+ }[];
128
+ readonly id?: string | undefined;
129
+ readonly encrypted_content?: string | null | undefined;
130
+ } | {
131
+ readonly type: "item_reference";
132
+ readonly id: string;
133
+ } | {
134
+ readonly role: "system";
135
+ readonly content: string;
136
+ } | {
137
+ readonly role: "user";
138
+ readonly content: readonly ({
139
+ readonly type: "input_image";
140
+ readonly image_url: string;
141
+ } | {
142
+ readonly type: "input_file";
143
+ readonly filename: string;
144
+ readonly file_data: string;
145
+ readonly mime_type?: string | undefined;
146
+ } | {
147
+ readonly type: "input_text";
148
+ readonly text: string;
149
+ })[];
150
+ } | {
151
+ readonly content: readonly {
152
+ readonly type: "output_text";
153
+ readonly text: string;
154
+ }[];
155
+ readonly role: "assistant";
156
+ readonly phase?: "commentary" | "final_answer" | undefined;
157
+ } | {
158
+ readonly type: "function_call";
159
+ readonly call_id: string;
160
+ readonly name: string;
161
+ readonly arguments: string;
162
+ } | {
163
+ readonly type: "function_call_output";
164
+ readonly call_id: string;
165
+ readonly output: string | readonly ({
166
+ readonly type: "input_image";
167
+ readonly image_url: string;
168
+ } | {
169
+ readonly type: "input_file";
170
+ readonly filename: string;
171
+ readonly file_data: string;
172
+ readonly mime_type?: string | undefined;
173
+ } | {
174
+ readonly type: "input_text";
175
+ readonly text: string;
176
+ })[];
177
+ } | {
178
+ readonly content: readonly {
179
+ readonly type: "output_text";
180
+ readonly text: string;
181
+ }[];
182
+ readonly role: "assistant";
183
+ readonly phase?: "commentary" | "final_answer" | null | undefined;
184
+ })[];
185
+ readonly model: string;
186
+ readonly stream: true;
187
+ readonly instructions?: string | undefined;
188
+ readonly reasoning?: {
189
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
190
+ readonly effort?: string | undefined;
191
+ } | undefined;
192
+ readonly tools?: readonly ({
193
+ readonly type: "function";
194
+ readonly description: string;
195
+ readonly name: string;
196
+ readonly parameters: {
197
+ readonly [x: string]: unknown;
198
+ };
199
+ readonly strict?: boolean | undefined;
200
+ } | {
201
+ readonly type: "image_generation";
202
+ readonly size?: string | undefined;
203
+ readonly action?: "generate" | "auto" | "edit" | undefined;
204
+ readonly output_format?: "png" | "jpeg" | "webp" | undefined;
205
+ readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
206
+ readonly background?: "auto" | "opaque" | "transparent" | undefined;
207
+ readonly output_compression?: number | undefined;
208
+ readonly input_fidelity?: "low" | "high" | undefined;
209
+ readonly partial_images?: number | undefined;
210
+ })[] | undefined;
211
+ readonly text?: {
212
+ readonly verbosity?: "low" | "medium" | "high" | undefined;
213
+ } | undefined;
214
+ readonly temperature?: number | undefined;
215
+ readonly tool_choice?: "required" | "none" | "auto" | {
216
+ readonly type: "function";
217
+ readonly name: string;
218
+ } | {
219
+ readonly type: "image_generation";
220
+ } | undefined;
221
+ readonly top_p?: number | undefined;
222
+ readonly include?: readonly ("file_search_call.results" | "web_search_call.results" | "web_search_call.action.sources" | "message.input_image.image_url" | "computer_call_output.output.image_url" | "code_interpreter_call.outputs" | "reasoning.encrypted_content" | "message.output_text.logprobs")[] | undefined;
223
+ readonly store?: boolean | undefined;
224
+ readonly prompt_cache_key?: string | undefined;
225
+ readonly service_tier?: "default" | "auto" | "flex" | "priority" | undefined;
226
+ readonly max_output_tokens?: number | undefined;
227
+ }, import("../protocols/open-responses-channel.js").Prepared>)[];
228
+ export declare const configure: (input: Config) => {
229
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
230
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
231
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
232
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
233
+ configure: (input: Config) => /*elided*/ any;
234
+ };
235
+ export declare const provider: {
236
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
237
+ configure: (input: Config) => {
238
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
239
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
240
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
241
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
242
+ configure: /*elided*/ any;
243
+ };
244
+ };
245
+ export declare const responsesModel: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
246
+ export declare const chatModel: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
247
+ export declare const model: (modelID: string, settings: Settings) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
248
+ export {};
@@ -0,0 +1,90 @@
1
+ import { Auth } from "../route/auth.js";
2
+ import {} from "../route/auth-options.js";
3
+ import { ProviderID } from "../schema/index.js";
4
+ import * as OpenAIChat from "../protocols/openai-chat.js";
5
+ import * as OpenAIResponses from "../protocols/openai-responses.js";
6
+ import { ProviderShared } from "../protocols/shared.js";
7
+ import { withOpenAIOptions } from "./openai-options.js";
8
+ export const id = ProviderID.make("azure");
9
+ const routeAuth = Auth.remove("authorization");
10
+ const resourceBaseURL = (resourceName) => `https://${resourceName.trim()}.openai.azure.com/openai`;
11
+ const responsesRoute = OpenAIResponses.route.with({
12
+ id: "azure-openai-responses",
13
+ provider: id,
14
+ auth: routeAuth,
15
+ });
16
+ const chatRoute = OpenAIChat.route.with({
17
+ id: "azure-openai-chat",
18
+ provider: id,
19
+ auth: routeAuth,
20
+ });
21
+ export const routes = [responsesRoute, chatRoute];
22
+ const defaults = (input) => {
23
+ const { apiKey: _, apiVersion: _apiVersion, resourceName: _resourceName, useDeploymentBasedUrls: _useDeploymentBasedUrls, baseURL: _baseURL, queryParams: _queryParams, ...rest } = input;
24
+ if ("auth" in rest) {
25
+ const { auth: _, ...withoutAuth } = rest;
26
+ return withoutAuth;
27
+ }
28
+ return rest;
29
+ };
30
+ const auth = (input) => {
31
+ if ("auth" in input && input.auth)
32
+ return input.auth;
33
+ return Auth.remove("authorization").andThen(Auth.optional("apiKey" in input ? input.apiKey : undefined, "apiKey")
34
+ .orElse(Auth.config("AZURE_OPENAI_API_KEY"))
35
+ .pipe(Auth.header("api-key")));
36
+ };
37
+ const configuredRoute = (route, input, modelID) => route.with({
38
+ auth: auth(input),
39
+ endpoint: endpoint(input, modelID),
40
+ });
41
+ function endpoint(input, modelID) {
42
+ const baseURL = ProviderShared.trimBaseUrl(input.baseURL ?? resourceBaseURL(input.resourceName));
43
+ const query = { "api-version": input.apiVersion ?? "v1", ...input.queryParams };
44
+ if (input.useDeploymentBasedUrls)
45
+ return { baseURL: `${baseURL}/deployments/${modelID}`, query };
46
+ if (input.baseURL !== undefined && !new URL(input.baseURL).hostname.endsWith(".openai.azure.com")) {
47
+ return { baseURL, query: input.queryParams };
48
+ }
49
+ return { baseURL: `${baseURL}/v1`, query };
50
+ }
51
+ export const configure = (input) => {
52
+ const modelDefaults = defaults(input);
53
+ const responses = (modelID) => configuredRoute(responsesRoute, input, modelID)
54
+ .with(withOpenAIOptions(modelID, modelDefaults))
55
+ .model({ id: modelID });
56
+ const chat = (modelID) => configuredRoute(chatRoute, input, modelID)
57
+ .with(withOpenAIOptions(modelID, modelDefaults))
58
+ .model({ id: modelID });
59
+ return {
60
+ id,
61
+ model: responses,
62
+ responses,
63
+ chat,
64
+ configure,
65
+ };
66
+ };
67
+ export const provider = {
68
+ id,
69
+ configure,
70
+ };
71
+ const config = (settings) => {
72
+ const common = {
73
+ apiKey: settings.apiKey,
74
+ apiVersion: settings.apiVersion,
75
+ headers: settings.headers === undefined ? undefined : { ...settings.headers },
76
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
77
+ limits: settings.limits,
78
+ providerOptions: settings.providerOptions,
79
+ queryParams: settings.queryParams === undefined ? undefined : { ...settings.queryParams },
80
+ useDeploymentBasedUrls: settings.useDeploymentBasedUrls,
81
+ };
82
+ if (settings.baseURL !== undefined)
83
+ return { ...common, baseURL: settings.baseURL };
84
+ if (settings.resourceName !== undefined)
85
+ return { ...common, resourceName: settings.resourceName };
86
+ throw new Error("Azure requires resourceName or baseURL");
87
+ };
88
+ export const responsesModel = (modelID, settings) => configure(config(settings)).responses(modelID);
89
+ export const chatModel = (modelID, settings) => configure(config(settings)).chat(modelID);
90
+ export const model = responsesModel;
@@ -0,0 +1,338 @@
1
+ import type { Config, Redacted } from "effect";
2
+ import { type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js";
3
+ import 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 aiGatewayID: string & import("effect/Brand").Brand<"AI.ProviderID">;
7
+ export declare const workersAIID: string & import("effect/Brand").Brand<"AI.ProviderID">;
8
+ export declare const aiGatewayAuthEnvVars: readonly ["CLOUDFLARE_API_TOKEN", "CF_AIG_TOKEN"];
9
+ export declare const workersAIAuthEnvVars: readonly ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN"];
10
+ type CloudflareSecret = string | Redacted.Redacted | Config.Config<string | Redacted.Redacted>;
11
+ type GatewayURL = AtLeastOne<{
12
+ readonly accountId: string;
13
+ readonly baseURL: string;
14
+ }> & {
15
+ readonly gatewayId?: string;
16
+ };
17
+ export type AIGatewayOptions = GatewayURL & Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
18
+ /** Cloudflare AI Gateway authentication token. Sent as `cf-aig-authorization`. */
19
+ readonly gatewayApiKey?: CloudflareSecret;
20
+ readonly providerOptions?: OpenAIProviderOptionsInput;
21
+ };
22
+ type WorkersAIURL = AtLeastOne<{
23
+ readonly accountId: string;
24
+ readonly baseURL: string;
25
+ }>;
26
+ export type WorkersAIOptions = WorkersAIURL & Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
27
+ readonly providerOptions?: OpenAIProviderOptionsInput;
28
+ };
29
+ export declare const aiGatewayBaseURL: (input: GatewayURL) => string;
30
+ export declare const workersAIBaseURL: (input: WorkersAIURL) => string;
31
+ export declare const aiGatewayRoute: import("../route/client.js").Route<{
32
+ readonly model: string;
33
+ readonly messages: readonly ({
34
+ readonly role: "system";
35
+ readonly content: string | readonly ({
36
+ readonly type: "text";
37
+ readonly text: string;
38
+ readonly cache_control?: {
39
+ readonly type: "ephemeral";
40
+ readonly ttl?: string | undefined;
41
+ } | undefined;
42
+ } | {
43
+ readonly type: "image_url";
44
+ readonly image_url: {
45
+ readonly url: string;
46
+ };
47
+ })[];
48
+ } | {
49
+ readonly role: "user";
50
+ readonly content: string | readonly ({
51
+ readonly type: "text";
52
+ readonly text: string;
53
+ readonly cache_control?: {
54
+ readonly type: "ephemeral";
55
+ readonly ttl?: string | undefined;
56
+ } | undefined;
57
+ } | {
58
+ readonly type: "image_url";
59
+ readonly image_url: {
60
+ readonly url: string;
61
+ };
62
+ })[];
63
+ } | {
64
+ readonly [x: string]: unknown;
65
+ readonly content: string | null;
66
+ readonly role: "assistant";
67
+ readonly reasoning?: string | undefined;
68
+ readonly reasoning_content?: string | undefined;
69
+ readonly reasoning_text?: string | undefined;
70
+ readonly cache_control?: {
71
+ readonly type: "ephemeral";
72
+ readonly ttl?: string | undefined;
73
+ } | undefined;
74
+ readonly tool_calls?: readonly {
75
+ readonly id: string;
76
+ readonly type: "function";
77
+ readonly function: {
78
+ readonly name: string;
79
+ readonly arguments: string;
80
+ };
81
+ }[] | undefined;
82
+ readonly reasoning_details?: unknown;
83
+ } | {
84
+ readonly content: string;
85
+ readonly role: "tool";
86
+ readonly tool_call_id: string;
87
+ readonly cache_control?: {
88
+ readonly type: "ephemeral";
89
+ readonly ttl?: string | undefined;
90
+ } | undefined;
91
+ })[];
92
+ readonly stream: true;
93
+ readonly stop?: readonly string[] | undefined;
94
+ readonly max_completion_tokens?: number | undefined;
95
+ readonly max_tokens?: number | undefined;
96
+ readonly tools?: readonly {
97
+ readonly function: {
98
+ readonly name: string;
99
+ readonly description: string;
100
+ readonly parameters: {
101
+ readonly [x: string]: unknown;
102
+ };
103
+ };
104
+ readonly type: "function";
105
+ readonly cache_control?: {
106
+ readonly type: "ephemeral";
107
+ readonly ttl?: string | undefined;
108
+ } | undefined;
109
+ }[] | undefined;
110
+ readonly temperature?: number | undefined;
111
+ readonly seed?: number | undefined;
112
+ readonly tool_choice?: "required" | "none" | "auto" | {
113
+ readonly type: "function";
114
+ readonly function: {
115
+ readonly name: string;
116
+ };
117
+ } | undefined;
118
+ readonly top_p?: number | undefined;
119
+ readonly store?: boolean | undefined;
120
+ readonly stream_options?: {
121
+ readonly include_usage: boolean;
122
+ } | undefined;
123
+ readonly prompt_cache_key?: string | undefined;
124
+ readonly reasoning_effort?: string | undefined;
125
+ readonly frequency_penalty?: number | undefined;
126
+ readonly presence_penalty?: number | undefined;
127
+ }, import("../route/transport/http.js").HttpPrepared<string>>;
128
+ export declare const workersAIRoute: import("../route/client.js").Route<{
129
+ readonly model: string;
130
+ readonly messages: readonly ({
131
+ readonly role: "system";
132
+ readonly content: string | readonly ({
133
+ readonly type: "text";
134
+ readonly text: string;
135
+ readonly cache_control?: {
136
+ readonly type: "ephemeral";
137
+ readonly ttl?: string | undefined;
138
+ } | undefined;
139
+ } | {
140
+ readonly type: "image_url";
141
+ readonly image_url: {
142
+ readonly url: string;
143
+ };
144
+ })[];
145
+ } | {
146
+ readonly role: "user";
147
+ readonly content: string | readonly ({
148
+ readonly type: "text";
149
+ readonly text: string;
150
+ readonly cache_control?: {
151
+ readonly type: "ephemeral";
152
+ readonly ttl?: string | undefined;
153
+ } | undefined;
154
+ } | {
155
+ readonly type: "image_url";
156
+ readonly image_url: {
157
+ readonly url: string;
158
+ };
159
+ })[];
160
+ } | {
161
+ readonly [x: string]: unknown;
162
+ readonly content: string | null;
163
+ readonly role: "assistant";
164
+ readonly reasoning?: string | undefined;
165
+ readonly reasoning_content?: string | undefined;
166
+ readonly reasoning_text?: string | undefined;
167
+ readonly cache_control?: {
168
+ readonly type: "ephemeral";
169
+ readonly ttl?: string | undefined;
170
+ } | undefined;
171
+ readonly tool_calls?: readonly {
172
+ readonly id: string;
173
+ readonly type: "function";
174
+ readonly function: {
175
+ readonly name: string;
176
+ readonly arguments: string;
177
+ };
178
+ }[] | undefined;
179
+ readonly reasoning_details?: unknown;
180
+ } | {
181
+ readonly content: string;
182
+ readonly role: "tool";
183
+ readonly tool_call_id: string;
184
+ readonly cache_control?: {
185
+ readonly type: "ephemeral";
186
+ readonly ttl?: string | undefined;
187
+ } | undefined;
188
+ })[];
189
+ readonly stream: true;
190
+ readonly stop?: readonly string[] | undefined;
191
+ readonly max_completion_tokens?: number | undefined;
192
+ readonly max_tokens?: number | undefined;
193
+ readonly tools?: readonly {
194
+ readonly function: {
195
+ readonly name: string;
196
+ readonly description: string;
197
+ readonly parameters: {
198
+ readonly [x: string]: unknown;
199
+ };
200
+ };
201
+ readonly type: "function";
202
+ readonly cache_control?: {
203
+ readonly type: "ephemeral";
204
+ readonly ttl?: string | undefined;
205
+ } | undefined;
206
+ }[] | undefined;
207
+ readonly temperature?: number | undefined;
208
+ readonly seed?: number | undefined;
209
+ readonly tool_choice?: "required" | "none" | "auto" | {
210
+ readonly type: "function";
211
+ readonly function: {
212
+ readonly name: string;
213
+ };
214
+ } | undefined;
215
+ readonly top_p?: number | undefined;
216
+ readonly store?: boolean | undefined;
217
+ readonly stream_options?: {
218
+ readonly include_usage: boolean;
219
+ } | undefined;
220
+ readonly prompt_cache_key?: string | undefined;
221
+ readonly reasoning_effort?: string | undefined;
222
+ readonly frequency_penalty?: number | undefined;
223
+ readonly presence_penalty?: number | undefined;
224
+ }, import("../route/transport/http.js").HttpPrepared<string>>;
225
+ export declare const routes: import("../route/client.js").Route<{
226
+ readonly model: string;
227
+ readonly messages: readonly ({
228
+ readonly role: "system";
229
+ readonly content: string | readonly ({
230
+ readonly type: "text";
231
+ readonly text: string;
232
+ readonly cache_control?: {
233
+ readonly type: "ephemeral";
234
+ readonly ttl?: string | undefined;
235
+ } | undefined;
236
+ } | {
237
+ readonly type: "image_url";
238
+ readonly image_url: {
239
+ readonly url: string;
240
+ };
241
+ })[];
242
+ } | {
243
+ readonly role: "user";
244
+ readonly content: string | readonly ({
245
+ readonly type: "text";
246
+ readonly text: string;
247
+ readonly cache_control?: {
248
+ readonly type: "ephemeral";
249
+ readonly ttl?: string | undefined;
250
+ } | undefined;
251
+ } | {
252
+ readonly type: "image_url";
253
+ readonly image_url: {
254
+ readonly url: string;
255
+ };
256
+ })[];
257
+ } | {
258
+ readonly [x: string]: unknown;
259
+ readonly content: string | null;
260
+ readonly role: "assistant";
261
+ readonly reasoning?: string | undefined;
262
+ readonly reasoning_content?: string | undefined;
263
+ readonly reasoning_text?: string | undefined;
264
+ readonly cache_control?: {
265
+ readonly type: "ephemeral";
266
+ readonly ttl?: string | undefined;
267
+ } | undefined;
268
+ readonly tool_calls?: readonly {
269
+ readonly id: string;
270
+ readonly type: "function";
271
+ readonly function: {
272
+ readonly name: string;
273
+ readonly arguments: string;
274
+ };
275
+ }[] | undefined;
276
+ readonly reasoning_details?: unknown;
277
+ } | {
278
+ readonly content: string;
279
+ readonly role: "tool";
280
+ readonly tool_call_id: string;
281
+ readonly cache_control?: {
282
+ readonly type: "ephemeral";
283
+ readonly ttl?: string | undefined;
284
+ } | undefined;
285
+ })[];
286
+ readonly stream: true;
287
+ readonly stop?: readonly string[] | undefined;
288
+ readonly max_completion_tokens?: number | undefined;
289
+ readonly max_tokens?: number | undefined;
290
+ readonly tools?: readonly {
291
+ readonly function: {
292
+ readonly name: string;
293
+ readonly description: string;
294
+ readonly parameters: {
295
+ readonly [x: string]: unknown;
296
+ };
297
+ };
298
+ readonly type: "function";
299
+ readonly cache_control?: {
300
+ readonly type: "ephemeral";
301
+ readonly ttl?: string | undefined;
302
+ } | undefined;
303
+ }[] | undefined;
304
+ readonly temperature?: number | undefined;
305
+ readonly seed?: number | undefined;
306
+ readonly tool_choice?: "required" | "none" | "auto" | {
307
+ readonly type: "function";
308
+ readonly function: {
309
+ readonly name: string;
310
+ };
311
+ } | undefined;
312
+ readonly top_p?: number | undefined;
313
+ readonly store?: boolean | undefined;
314
+ readonly stream_options?: {
315
+ readonly include_usage: boolean;
316
+ } | undefined;
317
+ readonly prompt_cache_key?: string | undefined;
318
+ readonly reasoning_effort?: string | undefined;
319
+ readonly frequency_penalty?: number | undefined;
320
+ readonly presence_penalty?: number | undefined;
321
+ }, import("../route/transport/http.js").HttpPrepared<string>>[];
322
+ export declare const CloudflareAIGateway: {
323
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
324
+ configure: (options: AIGatewayOptions) => {
325
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
326
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
327
+ configure: /*elided*/ any;
328
+ };
329
+ };
330
+ export declare const CloudflareWorkersAI: {
331
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
332
+ configure: (options: WorkersAIOptions) => {
333
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
334
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
335
+ configure: /*elided*/ any;
336
+ };
337
+ };
338
+ export {};