@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,249 @@
1
+ import { type ProviderAuthOption } from "../route/auth-options.js";
2
+ import { Route, type RouteDefaultsInput } from "../route/client.js";
3
+ import { type ModelID, type ProviderOptions } from "../schema/index.js";
4
+ import type { OpenAIOptionsInput } from "./openai-options.js";
5
+ import type { ProviderPackage } from "../provider-package.js";
6
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
7
+ export type XAIProviderOptionsInput = ProviderOptions & {
8
+ readonly xai?: OpenAIOptionsInput;
9
+ };
10
+ export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
11
+ readonly baseURL?: string;
12
+ readonly providerOptions?: XAIProviderOptionsInput;
13
+ };
14
+ export interface Settings extends ProviderPackage.Settings {
15
+ readonly apiKey?: string;
16
+ readonly baseURL?: string;
17
+ readonly providerOptions?: XAIProviderOptionsInput;
18
+ }
19
+ export type { XAIImageOptions } from "../protocols/xai-images.js";
20
+ export declare const routes: (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 stop?: readonly string[] | undefined;
83
+ readonly max_completion_tokens?: number | undefined;
84
+ readonly max_tokens?: number | undefined;
85
+ readonly tools?: readonly {
86
+ readonly function: {
87
+ readonly name: string;
88
+ readonly description: string;
89
+ readonly parameters: {
90
+ readonly [x: string]: unknown;
91
+ };
92
+ };
93
+ readonly type: "function";
94
+ readonly cache_control?: {
95
+ readonly type: "ephemeral";
96
+ readonly ttl?: string | undefined;
97
+ } | undefined;
98
+ }[] | undefined;
99
+ readonly temperature?: number | undefined;
100
+ readonly seed?: number | undefined;
101
+ readonly tool_choice?: "required" | "none" | "auto" | {
102
+ readonly type: "function";
103
+ readonly function: {
104
+ readonly name: string;
105
+ };
106
+ } | undefined;
107
+ readonly top_p?: number | undefined;
108
+ readonly store?: boolean | undefined;
109
+ readonly stream_options?: {
110
+ readonly include_usage: boolean;
111
+ } | undefined;
112
+ readonly prompt_cache_key?: string | undefined;
113
+ readonly reasoning_effort?: string | undefined;
114
+ readonly frequency_penalty?: number | undefined;
115
+ readonly presence_penalty?: number | undefined;
116
+ }, import("../route/transport/http.js").HttpPrepared<string>> | Route<{
117
+ readonly input: readonly ({
118
+ readonly type: "reasoning";
119
+ readonly summary: readonly {
120
+ readonly type: "summary_text";
121
+ readonly text: string;
122
+ }[];
123
+ readonly id?: string | undefined;
124
+ readonly encrypted_content?: string | null | undefined;
125
+ } | {
126
+ readonly type: "item_reference";
127
+ readonly id: string;
128
+ } | {
129
+ readonly role: "system";
130
+ readonly content: string;
131
+ } | {
132
+ readonly role: "user";
133
+ readonly content: readonly ({
134
+ readonly type: "input_image";
135
+ readonly image_url: string;
136
+ } | {
137
+ readonly type: "input_file";
138
+ readonly filename: string;
139
+ readonly file_data: string;
140
+ readonly mime_type?: string | undefined;
141
+ } | {
142
+ readonly type: "input_text";
143
+ readonly text: string;
144
+ })[];
145
+ } | {
146
+ readonly content: readonly {
147
+ readonly type: "output_text";
148
+ readonly text: string;
149
+ }[];
150
+ readonly role: "assistant";
151
+ readonly phase?: "commentary" | "final_answer" | undefined;
152
+ } | {
153
+ readonly type: "function_call";
154
+ readonly call_id: string;
155
+ readonly name: string;
156
+ readonly arguments: string;
157
+ } | {
158
+ readonly type: "function_call_output";
159
+ readonly call_id: string;
160
+ readonly output: string | readonly ({
161
+ readonly type: "input_image";
162
+ readonly image_url: string;
163
+ } | {
164
+ readonly type: "input_file";
165
+ readonly filename: string;
166
+ readonly file_data: string;
167
+ readonly mime_type?: string | undefined;
168
+ } | {
169
+ readonly type: "input_text";
170
+ readonly text: string;
171
+ })[];
172
+ } | {
173
+ readonly content: readonly {
174
+ readonly type: "output_text";
175
+ readonly text: string;
176
+ }[];
177
+ readonly role: "assistant";
178
+ readonly phase?: "commentary" | "final_answer" | null | undefined;
179
+ })[];
180
+ readonly model: string;
181
+ readonly stream: true;
182
+ readonly instructions?: string | undefined;
183
+ readonly reasoning?: {
184
+ readonly summary?: "auto" | "concise" | "detailed" | undefined;
185
+ readonly effort?: string | undefined;
186
+ } | undefined;
187
+ readonly tools?: readonly ({
188
+ readonly type: "function";
189
+ readonly description: string;
190
+ readonly name: string;
191
+ readonly parameters: {
192
+ readonly [x: string]: unknown;
193
+ };
194
+ readonly strict?: boolean | undefined;
195
+ } | {
196
+ readonly type: "image_generation";
197
+ readonly size?: string | undefined;
198
+ readonly action?: "generate" | "auto" | "edit" | undefined;
199
+ readonly output_format?: "png" | "jpeg" | "webp" | undefined;
200
+ readonly quality?: "low" | "medium" | "high" | "auto" | undefined;
201
+ readonly background?: "auto" | "opaque" | "transparent" | undefined;
202
+ readonly output_compression?: number | undefined;
203
+ readonly input_fidelity?: "low" | "high" | undefined;
204
+ readonly partial_images?: number | undefined;
205
+ })[] | undefined;
206
+ readonly text?: {
207
+ readonly verbosity?: "low" | "medium" | "high" | undefined;
208
+ } | undefined;
209
+ readonly temperature?: number | undefined;
210
+ readonly tool_choice?: "required" | "none" | "auto" | {
211
+ readonly type: "function";
212
+ readonly name: string;
213
+ } | {
214
+ readonly type: "image_generation";
215
+ } | undefined;
216
+ readonly top_p?: number | undefined;
217
+ 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;
218
+ readonly store?: boolean | undefined;
219
+ readonly prompt_cache_key?: string | undefined;
220
+ readonly service_tier?: "default" | "auto" | "flex" | "priority" | undefined;
221
+ readonly max_output_tokens?: number | undefined;
222
+ }, import("../route/transport/http.js").HttpPrepared<string>>)[];
223
+ export declare const configure: (input?: LanguageModelOptions) => {
224
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
225
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
226
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
227
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
228
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
229
+ configure: (input?: LanguageModelOptions) => /*elided*/ any;
230
+ };
231
+ export declare const provider: {
232
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
233
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
234
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
235
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
236
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
237
+ configure: (input?: LanguageModelOptions) => {
238
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
239
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
240
+ responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
241
+ chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
242
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
243
+ configure: /*elided*/ any;
244
+ };
245
+ };
246
+ export declare const model: ProviderPackage.Definition<Settings, XAIProviderOptionsInput>["model"];
247
+ export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
248
+ export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<XAIProviderOptionsInput>;
249
+ export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/xai-images.js").XAIImageOptions>;
@@ -0,0 +1,79 @@
1
+ import { AuthOptions } from "../route/auth-options.js";
2
+ import { Route } from "../route/client.js";
3
+ import { Endpoint } from "../route/endpoint.js";
4
+ import { HttpOptions, ProviderID } from "../schema/index.js";
5
+ import * as OpenAICompatibleProfiles from "./openai-compatible-profile.js";
6
+ import * as OpenAICompatibleChat from "../protocols/openai-compatible-chat.js";
7
+ import * as OpenAIChat from "../protocols/openai-chat.js";
8
+ import * as OpenAIResponses from "../protocols/openai-responses.js";
9
+ import { XAIImages } from "../protocols/xai-images.js";
10
+ export const id = ProviderID.make("xai");
11
+ const responsesRoute = Route.make({
12
+ id: "openai-responses",
13
+ provider: id,
14
+ providerMetadataKey: "xai",
15
+ protocol: OpenAIResponses.protocol,
16
+ endpoint: Endpoint.path("/responses", { baseURL: OpenAICompatibleProfiles.profiles.xai.baseURL }),
17
+ transport: OpenAIResponses.httpTransport,
18
+ defaults: { providerOptions: { xai: { store: false } } },
19
+ });
20
+ const chatRoute = Route.make({
21
+ id: "openai-compatible-chat",
22
+ provider: id,
23
+ providerMetadataKey: "xai",
24
+ protocol: OpenAIChat.protocol,
25
+ endpoint: Endpoint.path("/chat/completions", { baseURL: OpenAICompatibleProfiles.profiles.xai.baseURL }),
26
+ transport: OpenAICompatibleChat.route.transport,
27
+ headers: ({ request }) => request.promptCacheKey ? { "x-grok-conv-id": request.promptCacheKey } : {},
28
+ });
29
+ export const routes = [responsesRoute, chatRoute];
30
+ const auth = (options) => AuthOptions.bearer(options, "XAI_API_KEY");
31
+ const configuredResponsesRoute = (input) => {
32
+ const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
33
+ return responsesRoute.with({
34
+ ...rest,
35
+ endpoint: { baseURL: baseURL ?? OpenAICompatibleProfiles.profiles.xai.baseURL },
36
+ auth: auth(input),
37
+ });
38
+ };
39
+ const configuredChatRoute = (input) => {
40
+ const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
41
+ return chatRoute.with({
42
+ ...rest,
43
+ endpoint: { baseURL: baseURL ?? OpenAICompatibleProfiles.profiles.xai.baseURL },
44
+ auth: auth(input),
45
+ });
46
+ };
47
+ export const configure = (input = {}) => {
48
+ const responsesRoute = configuredResponsesRoute(input);
49
+ const chatRoute = configuredChatRoute(input);
50
+ const responses = (modelID) => responsesRoute.model({ id: modelID });
51
+ const chat = (modelID) => chatRoute.model({ id: modelID });
52
+ const image = (modelID) => XAIImages.model({
53
+ id: modelID,
54
+ auth: auth(input),
55
+ baseURL: input.baseURL ?? OpenAICompatibleProfiles.profiles.xai.baseURL,
56
+ headers: input.headers,
57
+ http: input.http === undefined ? undefined : HttpOptions.make(input.http),
58
+ });
59
+ return {
60
+ id,
61
+ model: responses,
62
+ responses,
63
+ chat,
64
+ image,
65
+ configure,
66
+ };
67
+ };
68
+ export const provider = configure();
69
+ export const model = (modelID, settings) => configure({
70
+ apiKey: settings.apiKey,
71
+ baseURL: settings.baseURL,
72
+ headers: settings.headers,
73
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
74
+ limits: settings.limits,
75
+ providerOptions: settings.providerOptions,
76
+ }).model(modelID);
77
+ export const responses = provider.responses;
78
+ export const chat = provider.chat;
79
+ export const image = provider.image;
@@ -0,0 +1,24 @@
1
+ import { type ProviderAuthOption } from "../route/auth-options.js";
2
+ import { HttpOptions, type ModelID } from "../schema/index.js";
3
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
4
+ export type Config = ProviderAuthOption<"optional"> & {
5
+ readonly baseURL?: string;
6
+ readonly headers?: Record<string, string>;
7
+ readonly http?: HttpOptions.Input;
8
+ };
9
+ export type { ZAIImageOptions } from "../protocols/zai-images.js";
10
+ export declare const configure: (input?: Config) => {
11
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
12
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/zai-images.js").ZAIImageOptions>;
13
+ configure: (input?: Config) => /*elided*/ any;
14
+ };
15
+ export declare const provider: {
16
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
17
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/zai-images.js").ZAIImageOptions>;
18
+ configure: (input?: Config) => {
19
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
20
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/zai-images.js").ZAIImageOptions>;
21
+ configure: /*elided*/ any;
22
+ };
23
+ };
24
+ export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/zai-images.js").ZAIImageOptions>;
@@ -0,0 +1,21 @@
1
+ import { ZAIImages } from "../protocols/zai-images.js";
2
+ import { AuthOptions } from "../route/auth-options.js";
3
+ import { HttpOptions, ProviderID } from "../schema/index.js";
4
+ export const id = ProviderID.make("zai");
5
+ const auth = (options) => AuthOptions.bearer(options, "ZAI_API_KEY");
6
+ export const configure = (input = {}) => {
7
+ const image = (modelID) => ZAIImages.model({
8
+ id: modelID,
9
+ auth: auth(input),
10
+ baseURL: input.baseURL,
11
+ headers: input.headers,
12
+ http: input.http === undefined ? undefined : HttpOptions.make(input.http),
13
+ });
14
+ return {
15
+ id,
16
+ image,
17
+ configure,
18
+ };
19
+ };
20
+ export const provider = configure();
21
+ export const image = provider.image;
@@ -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,89 @@
1
+ import { Config, Effect, Redacted } from "effect";
2
+ import { Headers } from "effect/unstable/http";
3
+ import { AuthenticationReason, InvalidRequestReason, 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
+ module: "Auth",
80
+ method: "apply",
81
+ reason: error instanceof MissingCredentialError
82
+ ? new AuthenticationReason({ message: error.message, kind: "missing" })
83
+ : new InvalidRequestReason({ message: `Failed to resolve auth config: ${error.message}` }),
84
+ });
85
+ }
86
+ return error;
87
+ };
88
+ export const toEffect = (input) => (authInput) => input.apply(authInput).pipe(Effect.mapError(toAIError));
89
+ export * as Auth from "./auth.js";