@opencode/ai 0.0.0-reserved → 2.0.1

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