@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,537 @@
1
+ import { Schema } from "effect";
2
+ import { Route, type RouteDefaultsInput } from "../route/client.js";
3
+ import { Protocol } from "../route/protocol.js";
4
+ import { type ProviderAuthOption } from "../route/auth-options.js";
5
+ import { type ModelID, type ProviderOptions } from "../schema/index.js";
6
+ import type { ProviderPackage } from "../provider-package.js";
7
+ import * as OpenAIChat from "../protocols/openai-chat.js";
8
+ export declare const profile: {
9
+ readonly provider: "openrouter";
10
+ readonly baseURL: "https://openrouter.ai/api/v1";
11
+ };
12
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
13
+ type OpenRouterString<Known extends string> = Known | (string & {});
14
+ export interface OpenRouterProviderRouting {
15
+ readonly [key: string]: unknown;
16
+ readonly order?: ReadonlyArray<string>;
17
+ readonly allow_fallbacks?: boolean;
18
+ readonly require_parameters?: boolean;
19
+ readonly data_collection?: OpenRouterString<"allow" | "deny">;
20
+ readonly only?: ReadonlyArray<string>;
21
+ readonly ignore?: ReadonlyArray<string>;
22
+ readonly quantizations?: ReadonlyArray<string>;
23
+ readonly sort?: OpenRouterString<"price" | "throughput" | "latency">;
24
+ readonly max_price?: Readonly<{
25
+ prompt?: number | string;
26
+ completion?: number | string;
27
+ image?: number | string;
28
+ audio?: number | string;
29
+ request?: number | string;
30
+ }>;
31
+ readonly zdr?: boolean;
32
+ }
33
+ export type OpenRouterPlugin = Readonly<{
34
+ id: "web";
35
+ max_results?: number;
36
+ search_prompt?: string;
37
+ engine?: OpenRouterString<"native" | "exa">;
38
+ }> | Readonly<{
39
+ id: "file-parser";
40
+ max_files?: number;
41
+ pdf?: {
42
+ engine?: string;
43
+ };
44
+ }> | Readonly<{
45
+ id: "moderation";
46
+ }> | Readonly<{
47
+ id: "response-healing";
48
+ }> | Readonly<{
49
+ id: "auto-router";
50
+ allowed_models?: ReadonlyArray<string>;
51
+ }> | Readonly<{
52
+ id: string & {};
53
+ [key: string]: unknown;
54
+ }>;
55
+ export interface OpenRouterOptions {
56
+ readonly [key: string]: unknown;
57
+ readonly debug?: Readonly<{
58
+ echo_upstream_body?: boolean;
59
+ }>;
60
+ readonly models?: ReadonlyArray<string>;
61
+ readonly plugins?: ReadonlyArray<OpenRouterPlugin>;
62
+ readonly provider?: OpenRouterProviderRouting;
63
+ readonly reasoning?: Readonly<{
64
+ enabled?: boolean;
65
+ exclude?: boolean;
66
+ effort?: OpenRouterString<"none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">;
67
+ max_tokens?: number;
68
+ }>;
69
+ readonly usage?: boolean | Readonly<{
70
+ include: boolean;
71
+ }>;
72
+ readonly user?: string;
73
+ readonly web_search_options?: Readonly<{
74
+ max_results?: number;
75
+ search_prompt?: string;
76
+ engine?: OpenRouterString<"native" | "exa">;
77
+ }>;
78
+ }
79
+ export type OpenRouterProviderOptionsInput = ProviderOptions & {
80
+ readonly openrouter?: OpenRouterOptions;
81
+ };
82
+ export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
83
+ readonly baseURL?: string;
84
+ readonly providerOptions?: OpenRouterProviderOptionsInput;
85
+ };
86
+ export interface Settings extends ProviderPackage.Settings {
87
+ readonly apiKey?: string;
88
+ readonly baseURL?: string;
89
+ readonly providerOptions?: OpenRouterProviderOptionsInput;
90
+ }
91
+ declare const OpenRouterBody: Schema.StructWithRest<Schema.Struct<{
92
+ model: Schema.String;
93
+ messages: Schema.$Array<Schema.toTaggedUnion<"role", readonly [Schema.Struct<{
94
+ readonly role: Schema.Literal<"system">;
95
+ readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
96
+ readonly type: Schema.Literal<"text">;
97
+ readonly text: Schema.String;
98
+ readonly cache_control: Schema.optional<Schema.Struct<{
99
+ readonly type: Schema.Literal<"ephemeral">;
100
+ readonly ttl: Schema.optional<Schema.String>;
101
+ }>>;
102
+ }>, Schema.Struct<{
103
+ readonly type: Schema.Literal<"image_url">;
104
+ readonly image_url: Schema.Struct<{
105
+ readonly url: Schema.String;
106
+ }>;
107
+ }>]>>]>;
108
+ }>, Schema.Struct<{
109
+ readonly role: Schema.Literal<"user">;
110
+ readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
111
+ readonly type: Schema.Literal<"text">;
112
+ readonly text: Schema.String;
113
+ readonly cache_control: Schema.optional<Schema.Struct<{
114
+ readonly type: Schema.Literal<"ephemeral">;
115
+ readonly ttl: Schema.optional<Schema.String>;
116
+ }>>;
117
+ }>, Schema.Struct<{
118
+ readonly type: Schema.Literal<"image_url">;
119
+ readonly image_url: Schema.Struct<{
120
+ readonly url: Schema.String;
121
+ }>;
122
+ }>]>>]>;
123
+ }>, Schema.StructWithRest<Schema.Struct<{
124
+ readonly role: Schema.Literal<"assistant">;
125
+ readonly content: Schema.NullOr<Schema.String>;
126
+ readonly tool_calls: Schema.optional<Schema.$Array<Schema.Struct<{
127
+ readonly id: Schema.String;
128
+ readonly type: Schema.tag<"function">;
129
+ readonly function: Schema.Struct<{
130
+ readonly name: Schema.String;
131
+ readonly arguments: Schema.String;
132
+ }>;
133
+ }>>>;
134
+ readonly reasoning_content: Schema.optional<Schema.String>;
135
+ readonly reasoning: Schema.optional<Schema.String>;
136
+ readonly reasoning_text: Schema.optional<Schema.String>;
137
+ readonly reasoning_details: Schema.optional<Schema.Unknown>;
138
+ readonly cache_control: Schema.optional<Schema.Struct<{
139
+ readonly type: Schema.Literal<"ephemeral">;
140
+ readonly ttl: Schema.optional<Schema.String>;
141
+ }>>;
142
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
143
+ readonly role: Schema.Literal<"tool">;
144
+ readonly tool_call_id: Schema.String;
145
+ readonly content: Schema.String;
146
+ readonly cache_control: Schema.optional<Schema.Struct<{
147
+ readonly type: Schema.Literal<"ephemeral">;
148
+ readonly ttl: Schema.optional<Schema.String>;
149
+ }>>;
150
+ }>]>>;
151
+ tools: Schema.optional<Schema.$Array<Schema.Struct<{
152
+ readonly type: Schema.tag<"function">;
153
+ readonly function: Schema.Struct<{
154
+ readonly name: Schema.String;
155
+ readonly description: Schema.String;
156
+ readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
157
+ }>;
158
+ readonly cache_control: Schema.optional<Schema.Struct<{
159
+ readonly type: Schema.Literal<"ephemeral">;
160
+ readonly ttl: Schema.optional<Schema.String>;
161
+ }>>;
162
+ }>>>;
163
+ tool_choice: Schema.optional<Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
164
+ readonly type: Schema.tag<"function">;
165
+ readonly function: Schema.Struct<{
166
+ readonly name: Schema.String;
167
+ }>;
168
+ }>]>>;
169
+ stream: Schema.Literal<true>;
170
+ stream_options: Schema.optional<Schema.Struct<{
171
+ readonly include_usage: Schema.Boolean;
172
+ }>>;
173
+ store: Schema.optional<Schema.Boolean>;
174
+ prompt_cache_key: Schema.optional<Schema.String>;
175
+ reasoning_effort: Schema.optional<Schema.String>;
176
+ max_completion_tokens: Schema.optional<Schema.Number>;
177
+ max_tokens: Schema.optional<Schema.Number>;
178
+ temperature: Schema.optional<Schema.Number>;
179
+ top_p: Schema.optional<Schema.Number>;
180
+ frequency_penalty: Schema.optional<Schema.Number>;
181
+ presence_penalty: Schema.optional<Schema.Number>;
182
+ seed: Schema.optional<Schema.Number>;
183
+ stop: Schema.optional<Schema.$Array<Schema.String>>;
184
+ }>, readonly [Schema.$Record<Schema.String, Schema.Any>]>;
185
+ export type OpenRouterBody = Schema.Schema.Type<typeof OpenRouterBody>;
186
+ export declare const protocol: Protocol<{
187
+ readonly [x: string]: any;
188
+ readonly model: string;
189
+ readonly messages: readonly ({
190
+ readonly role: "system";
191
+ readonly content: string | readonly ({
192
+ readonly type: "text";
193
+ readonly text: string;
194
+ readonly cache_control?: {
195
+ readonly type: "ephemeral";
196
+ readonly ttl?: string | undefined;
197
+ } | undefined;
198
+ } | {
199
+ readonly type: "image_url";
200
+ readonly image_url: {
201
+ readonly url: string;
202
+ };
203
+ })[];
204
+ } | {
205
+ readonly role: "user";
206
+ readonly content: string | readonly ({
207
+ readonly type: "text";
208
+ readonly text: string;
209
+ readonly cache_control?: {
210
+ readonly type: "ephemeral";
211
+ readonly ttl?: string | undefined;
212
+ } | undefined;
213
+ } | {
214
+ readonly type: "image_url";
215
+ readonly image_url: {
216
+ readonly url: string;
217
+ };
218
+ })[];
219
+ } | {
220
+ readonly [x: string]: unknown;
221
+ readonly content: string | null;
222
+ readonly role: "assistant";
223
+ readonly reasoning?: string | undefined;
224
+ readonly reasoning_content?: string | undefined;
225
+ readonly reasoning_text?: string | undefined;
226
+ readonly cache_control?: {
227
+ readonly type: "ephemeral";
228
+ readonly ttl?: string | undefined;
229
+ } | undefined;
230
+ readonly tool_calls?: readonly {
231
+ readonly id: string;
232
+ readonly type: "function";
233
+ readonly function: {
234
+ readonly name: string;
235
+ readonly arguments: string;
236
+ };
237
+ }[] | undefined;
238
+ readonly reasoning_details?: unknown;
239
+ } | {
240
+ readonly content: string;
241
+ readonly role: "tool";
242
+ readonly tool_call_id: string;
243
+ readonly cache_control?: {
244
+ readonly type: "ephemeral";
245
+ readonly ttl?: string | undefined;
246
+ } | undefined;
247
+ })[];
248
+ readonly stream: true;
249
+ readonly stop?: readonly string[] | undefined;
250
+ readonly max_completion_tokens?: number | undefined;
251
+ readonly max_tokens?: number | undefined;
252
+ readonly tools?: readonly {
253
+ readonly function: {
254
+ readonly name: string;
255
+ readonly description: string;
256
+ readonly parameters: {
257
+ readonly [x: string]: unknown;
258
+ };
259
+ };
260
+ readonly type: "function";
261
+ readonly cache_control?: {
262
+ readonly type: "ephemeral";
263
+ readonly ttl?: string | undefined;
264
+ } | undefined;
265
+ }[] | undefined;
266
+ readonly temperature?: number | undefined;
267
+ readonly seed?: number | undefined;
268
+ readonly tool_choice?: "required" | "none" | "auto" | {
269
+ readonly type: "function";
270
+ readonly function: {
271
+ readonly name: string;
272
+ };
273
+ } | undefined;
274
+ readonly top_p?: number | undefined;
275
+ readonly store?: boolean | undefined;
276
+ readonly stream_options?: {
277
+ readonly include_usage: boolean;
278
+ } | undefined;
279
+ readonly prompt_cache_key?: string | undefined;
280
+ readonly reasoning_effort?: string | undefined;
281
+ readonly frequency_penalty?: number | undefined;
282
+ readonly presence_penalty?: number | undefined;
283
+ }, string, {
284
+ readonly error?: {
285
+ readonly message: string;
286
+ readonly code?: string | number | null | undefined;
287
+ } | null | undefined;
288
+ readonly usage?: {
289
+ readonly [x: string]: unknown;
290
+ readonly prompt_tokens?: number | null | undefined;
291
+ readonly completion_tokens?: number | null | undefined;
292
+ readonly total_tokens?: number | null | undefined;
293
+ readonly prompt_tokens_details?: {
294
+ readonly [x: string]: unknown;
295
+ readonly cached_tokens?: number | null | undefined;
296
+ readonly cache_write_tokens?: number | null | undefined;
297
+ } | null | undefined;
298
+ readonly completion_tokens_details?: {
299
+ readonly [x: string]: unknown;
300
+ readonly reasoning_tokens?: number | null | undefined;
301
+ readonly accepted_prediction_tokens?: number | null | undefined;
302
+ readonly rejected_prediction_tokens?: number | null | undefined;
303
+ } | null | undefined;
304
+ } | null | undefined;
305
+ readonly choices?: readonly {
306
+ readonly delta?: {
307
+ readonly [x: string]: unknown;
308
+ readonly reasoning?: string | null | undefined;
309
+ readonly reasoning_content?: string | null | undefined;
310
+ readonly reasoning_text?: string | null | undefined;
311
+ readonly content?: string | null | undefined;
312
+ readonly tool_calls?: readonly {
313
+ readonly function?: {
314
+ readonly name?: string | null | undefined;
315
+ readonly arguments?: string | null | undefined;
316
+ } | null | undefined;
317
+ readonly id?: string | null | undefined;
318
+ readonly index?: number | null | undefined;
319
+ }[] | null | undefined;
320
+ readonly reasoning_details?: unknown;
321
+ } | null | undefined;
322
+ readonly finish_reason?: string | null | undefined;
323
+ readonly native_finish_reason?: string | null | undefined;
324
+ }[] | null | undefined;
325
+ }, OpenAIChat.ParserState>;
326
+ export declare const route: Route<{
327
+ readonly [x: string]: any;
328
+ readonly model: string;
329
+ readonly messages: readonly ({
330
+ readonly role: "system";
331
+ readonly content: string | readonly ({
332
+ readonly type: "text";
333
+ readonly text: string;
334
+ readonly cache_control?: {
335
+ readonly type: "ephemeral";
336
+ readonly ttl?: string | undefined;
337
+ } | undefined;
338
+ } | {
339
+ readonly type: "image_url";
340
+ readonly image_url: {
341
+ readonly url: string;
342
+ };
343
+ })[];
344
+ } | {
345
+ readonly role: "user";
346
+ readonly content: string | readonly ({
347
+ readonly type: "text";
348
+ readonly text: string;
349
+ readonly cache_control?: {
350
+ readonly type: "ephemeral";
351
+ readonly ttl?: string | undefined;
352
+ } | undefined;
353
+ } | {
354
+ readonly type: "image_url";
355
+ readonly image_url: {
356
+ readonly url: string;
357
+ };
358
+ })[];
359
+ } | {
360
+ readonly [x: string]: unknown;
361
+ readonly content: string | null;
362
+ readonly role: "assistant";
363
+ readonly reasoning?: string | undefined;
364
+ readonly reasoning_content?: string | undefined;
365
+ readonly reasoning_text?: string | undefined;
366
+ readonly cache_control?: {
367
+ readonly type: "ephemeral";
368
+ readonly ttl?: string | undefined;
369
+ } | undefined;
370
+ readonly tool_calls?: readonly {
371
+ readonly id: string;
372
+ readonly type: "function";
373
+ readonly function: {
374
+ readonly name: string;
375
+ readonly arguments: string;
376
+ };
377
+ }[] | undefined;
378
+ readonly reasoning_details?: unknown;
379
+ } | {
380
+ readonly content: string;
381
+ readonly role: "tool";
382
+ readonly tool_call_id: string;
383
+ readonly cache_control?: {
384
+ readonly type: "ephemeral";
385
+ readonly ttl?: string | undefined;
386
+ } | undefined;
387
+ })[];
388
+ readonly stream: true;
389
+ readonly stop?: readonly string[] | undefined;
390
+ readonly max_completion_tokens?: number | undefined;
391
+ readonly max_tokens?: number | undefined;
392
+ readonly tools?: readonly {
393
+ readonly function: {
394
+ readonly name: string;
395
+ readonly description: string;
396
+ readonly parameters: {
397
+ readonly [x: string]: unknown;
398
+ };
399
+ };
400
+ readonly type: "function";
401
+ readonly cache_control?: {
402
+ readonly type: "ephemeral";
403
+ readonly ttl?: string | undefined;
404
+ } | undefined;
405
+ }[] | undefined;
406
+ readonly temperature?: number | undefined;
407
+ readonly seed?: number | undefined;
408
+ readonly tool_choice?: "required" | "none" | "auto" | {
409
+ readonly type: "function";
410
+ readonly function: {
411
+ readonly name: string;
412
+ };
413
+ } | undefined;
414
+ readonly top_p?: number | undefined;
415
+ readonly store?: boolean | undefined;
416
+ readonly stream_options?: {
417
+ readonly include_usage: boolean;
418
+ } | undefined;
419
+ readonly prompt_cache_key?: string | undefined;
420
+ readonly reasoning_effort?: string | undefined;
421
+ readonly frequency_penalty?: number | undefined;
422
+ readonly presence_penalty?: number | undefined;
423
+ }, import("../route/transport/http.js").HttpPrepared<string>>;
424
+ export declare const routes: Route<{
425
+ readonly [x: string]: any;
426
+ readonly model: string;
427
+ readonly messages: readonly ({
428
+ readonly role: "system";
429
+ readonly content: string | readonly ({
430
+ readonly type: "text";
431
+ readonly text: string;
432
+ readonly cache_control?: {
433
+ readonly type: "ephemeral";
434
+ readonly ttl?: string | undefined;
435
+ } | undefined;
436
+ } | {
437
+ readonly type: "image_url";
438
+ readonly image_url: {
439
+ readonly url: string;
440
+ };
441
+ })[];
442
+ } | {
443
+ readonly role: "user";
444
+ readonly content: string | readonly ({
445
+ readonly type: "text";
446
+ readonly text: string;
447
+ readonly cache_control?: {
448
+ readonly type: "ephemeral";
449
+ readonly ttl?: string | undefined;
450
+ } | undefined;
451
+ } | {
452
+ readonly type: "image_url";
453
+ readonly image_url: {
454
+ readonly url: string;
455
+ };
456
+ })[];
457
+ } | {
458
+ readonly [x: string]: unknown;
459
+ readonly content: string | null;
460
+ readonly role: "assistant";
461
+ readonly reasoning?: string | undefined;
462
+ readonly reasoning_content?: string | undefined;
463
+ readonly reasoning_text?: string | undefined;
464
+ readonly cache_control?: {
465
+ readonly type: "ephemeral";
466
+ readonly ttl?: string | undefined;
467
+ } | undefined;
468
+ readonly tool_calls?: readonly {
469
+ readonly id: string;
470
+ readonly type: "function";
471
+ readonly function: {
472
+ readonly name: string;
473
+ readonly arguments: string;
474
+ };
475
+ }[] | undefined;
476
+ readonly reasoning_details?: unknown;
477
+ } | {
478
+ readonly content: string;
479
+ readonly role: "tool";
480
+ readonly tool_call_id: string;
481
+ readonly cache_control?: {
482
+ readonly type: "ephemeral";
483
+ readonly ttl?: string | undefined;
484
+ } | undefined;
485
+ })[];
486
+ readonly stream: true;
487
+ readonly stop?: readonly string[] | undefined;
488
+ readonly max_completion_tokens?: number | undefined;
489
+ readonly max_tokens?: number | undefined;
490
+ readonly tools?: readonly {
491
+ readonly function: {
492
+ readonly name: string;
493
+ readonly description: string;
494
+ readonly parameters: {
495
+ readonly [x: string]: unknown;
496
+ };
497
+ };
498
+ readonly type: "function";
499
+ readonly cache_control?: {
500
+ readonly type: "ephemeral";
501
+ readonly ttl?: string | undefined;
502
+ } | undefined;
503
+ }[] | undefined;
504
+ readonly temperature?: number | undefined;
505
+ readonly seed?: number | undefined;
506
+ readonly tool_choice?: "required" | "none" | "auto" | {
507
+ readonly type: "function";
508
+ readonly function: {
509
+ readonly name: string;
510
+ };
511
+ } | undefined;
512
+ readonly top_p?: number | undefined;
513
+ readonly store?: boolean | undefined;
514
+ readonly stream_options?: {
515
+ readonly include_usage: boolean;
516
+ } | undefined;
517
+ readonly prompt_cache_key?: string | undefined;
518
+ readonly reasoning_effort?: string | undefined;
519
+ readonly frequency_penalty?: number | undefined;
520
+ readonly presence_penalty?: number | undefined;
521
+ }, import("../route/transport/http.js").HttpPrepared<string>>[];
522
+ export declare const configure: (input?: LanguageModelOptions) => {
523
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
524
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterProviderOptionsInput>;
525
+ configure: (input?: LanguageModelOptions) => /*elided*/ any;
526
+ };
527
+ export declare const provider: {
528
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
529
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterProviderOptionsInput>;
530
+ configure: (input?: LanguageModelOptions) => {
531
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
532
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterProviderOptionsInput>;
533
+ configure: /*elided*/ any;
534
+ };
535
+ };
536
+ export declare const model: ProviderPackage.Definition<Settings, OpenRouterProviderOptionsInput>["model"];
537
+ export {};
@@ -0,0 +1,117 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Route } from "../route/client.js";
3
+ import { Endpoint } from "../route/endpoint.js";
4
+ import { Framing } from "../route/framing.js";
5
+ import { Protocol } from "../route/protocol.js";
6
+ import { AuthOptions } from "../route/auth-options.js";
7
+ import { ProviderID } from "../schema/index.js";
8
+ import * as OpenAICompatibleProfiles from "./openai-compatible-profile.js";
9
+ import * as OpenAIChat from "../protocols/openai-chat.js";
10
+ import { newBreakpoints, ttlBucket } from "../protocols/utils/cache.js";
11
+ import { isRecord } from "../protocols/shared.js";
12
+ export const profile = OpenAICompatibleProfiles.profiles.openrouter;
13
+ export const id = ProviderID.make(profile.provider);
14
+ const ADAPTER = "openrouter";
15
+ const OpenRouterBody = Schema.StructWithRest(Schema.Struct(OpenAIChat.bodyFields), [
16
+ Schema.Record(Schema.String, Schema.Any),
17
+ ]);
18
+ export const protocol = Protocol.make({
19
+ id: "openrouter-chat",
20
+ body: {
21
+ schema: OpenRouterBody,
22
+ from: (request) => OpenAIChat.fromRequest(request, { cacheControl: cacheControl() }).pipe(Effect.map((body) => {
23
+ const sourceAssistants = request.messages.filter((message) => message.role === "assistant");
24
+ let assistantIndex = 0;
25
+ const messages = body.messages.map((message) => {
26
+ if (message.role !== "assistant")
27
+ return message;
28
+ const source = sourceAssistants[assistantIndex++];
29
+ const reasoning = source?.content
30
+ .filter((part) => part.type === "reasoning")
31
+ .map((part) => part.text)
32
+ .join("");
33
+ const reasoningDetails = Array.isArray(message.reasoning_details) ? message.reasoning_details : undefined;
34
+ return {
35
+ ...message,
36
+ reasoning_content: undefined,
37
+ reasoning_text: undefined,
38
+ reasoning: reasoning && reasoningDetails && reasoningDetails.length > 0 ? reasoning : undefined,
39
+ reasoning_details: reasoningDetails,
40
+ };
41
+ });
42
+ return {
43
+ ...body,
44
+ messages,
45
+ ...bodyOptions(request.providerOptions?.openrouter),
46
+ ...(request.promptCacheKey ? { prompt_cache_key: request.promptCacheKey } : {}),
47
+ };
48
+ })),
49
+ },
50
+ stream: OpenAIChat.protocol.stream,
51
+ });
52
+ const cacheControl = () => {
53
+ const breakpoints = newBreakpoints(4);
54
+ return (cache) => {
55
+ if (cache === undefined || breakpoints.remaining === 0)
56
+ return undefined;
57
+ breakpoints.remaining -= 1;
58
+ return {
59
+ type: "ephemeral",
60
+ ...(ttlBucket(cache.ttlSeconds) === "1h" ? { ttl: "1h" } : {}),
61
+ };
62
+ };
63
+ };
64
+ const bodyOptions = (input) => {
65
+ const openrouter = isRecord(input) ? input : {};
66
+ const { usage, models, provider, plugins, web_search_options, debug, user, reasoning, promptCacheKey, ...options } = openrouter;
67
+ return {
68
+ ...options,
69
+ ...(usage === undefined || usage === true
70
+ ? { usage: { include: true } }
71
+ : usage === false
72
+ ? { usage: { include: false } }
73
+ : isRecord(usage)
74
+ ? { usage }
75
+ : {}),
76
+ ...(Array.isArray(models) ? { models } : {}),
77
+ ...(isRecord(provider) ? { provider } : {}),
78
+ ...(Array.isArray(plugins) ? { plugins } : {}),
79
+ ...(isRecord(web_search_options) ? { web_search_options } : {}),
80
+ ...(isRecord(debug) ? { debug } : {}),
81
+ ...(typeof user === "string" ? { user } : {}),
82
+ ...(isRecord(reasoning) ? { reasoning } : {}),
83
+ };
84
+ };
85
+ export const route = Route.make({
86
+ id: ADAPTER,
87
+ provider: profile.provider,
88
+ protocol,
89
+ endpoint: Endpoint.path("/chat/completions", { baseURL: profile.baseURL }),
90
+ framing: Framing.sse,
91
+ });
92
+ export const routes = [route];
93
+ const configuredRoute = (input) => {
94
+ const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
95
+ return route.with({
96
+ ...rest,
97
+ endpoint: { baseURL: baseURL ?? profile.baseURL },
98
+ auth: AuthOptions.bearer(input, "OPENROUTER_API_KEY"),
99
+ });
100
+ };
101
+ export const configure = (input = {}) => {
102
+ const route = configuredRoute(input);
103
+ return {
104
+ id,
105
+ model: (modelID) => route.model({ id: modelID }),
106
+ configure,
107
+ };
108
+ };
109
+ export const provider = configure();
110
+ export const model = (modelID, settings) => configure({
111
+ apiKey: settings.apiKey,
112
+ baseURL: settings.baseURL,
113
+ headers: settings.headers,
114
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
115
+ limits: settings.limits,
116
+ providerOptions: settings.providerOptions,
117
+ }).model(modelID);