@opencode/ai 0.0.0-beta-19275

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/README.md +682 -0
  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/anthropic-messages.d.ts +957 -0
  13. package/dist/protocols/anthropic-messages.js +1414 -0
  14. package/dist/protocols/bedrock-converse.d.ts +499 -0
  15. package/dist/protocols/bedrock-converse.js +643 -0
  16. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  17. package/dist/protocols/bedrock-event-stream.js +97 -0
  18. package/dist/protocols/gemini.d.ts +285 -0
  19. package/dist/protocols/gemini.js +671 -0
  20. package/dist/protocols/google-images.d.ts +30 -0
  21. package/dist/protocols/google-images.js +181 -0
  22. package/dist/protocols/index.d.ts +12 -0
  23. package/dist/protocols/index.js +12 -0
  24. package/dist/protocols/meta-images.d.ts +26 -0
  25. package/dist/protocols/meta-images.js +89 -0
  26. package/dist/protocols/meta-messages.d.ts +350 -0
  27. package/dist/protocols/meta-messages.js +41 -0
  28. package/dist/protocols/meta-responses.d.ts +473 -0
  29. package/dist/protocols/meta-responses.js +173 -0
  30. package/dist/protocols/mistral-chat.d.ts +540 -0
  31. package/dist/protocols/mistral-chat.js +624 -0
  32. package/dist/protocols/open-responses-channel.d.ts +23 -0
  33. package/dist/protocols/open-responses-channel.js +141 -0
  34. package/dist/protocols/open-responses-continuation.d.ts +12 -0
  35. package/dist/protocols/open-responses-continuation.js +161 -0
  36. package/dist/protocols/open-responses.d.ts +1583 -0
  37. package/dist/protocols/open-responses.js +1206 -0
  38. package/dist/protocols/openai-chat.d.ts +860 -0
  39. package/dist/protocols/openai-chat.js +966 -0
  40. package/dist/protocols/openai-compatible-chat.d.ts +109 -0
  41. package/dist/protocols/openai-compatible-chat.js +19 -0
  42. package/dist/protocols/openai-compatible-responses.d.ts +172 -0
  43. package/dist/protocols/openai-compatible-responses.js +18 -0
  44. package/dist/protocols/openai-images.d.ts +32 -0
  45. package/dist/protocols/openai-images.js +183 -0
  46. package/dist/protocols/openai-responses.d.ts +1389 -0
  47. package/dist/protocols/openai-responses.js +260 -0
  48. package/dist/protocols/shared.d.ts +193 -0
  49. package/dist/protocols/shared.js +290 -0
  50. package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
  51. package/dist/protocols/utils/bedrock-auth.js +85 -0
  52. package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
  53. package/dist/protocols/utils/bedrock-cache.js +49 -0
  54. package/dist/protocols/utils/bedrock-media.d.ts +55 -0
  55. package/dist/protocols/utils/bedrock-media.js +73 -0
  56. package/dist/protocols/utils/cache.d.ts +6 -0
  57. package/dist/protocols/utils/cache.js +5 -0
  58. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  59. package/dist/protocols/utils/gemini-tool-schema.js +103 -0
  60. package/dist/protocols/utils/image-input.d.ts +21 -0
  61. package/dist/protocols/utils/image-input.js +20 -0
  62. package/dist/protocols/utils/lifecycle.d.ts +24 -0
  63. package/dist/protocols/utils/lifecycle.js +72 -0
  64. package/dist/protocols/utils/meta-image.d.ts +2 -0
  65. package/dist/protocols/utils/meta-image.js +13 -0
  66. package/dist/protocols/utils/open-responses-options.d.ts +56 -0
  67. package/dist/protocols/utils/open-responses-options.js +61 -0
  68. package/dist/protocols/utils/openai-image.d.ts +5 -0
  69. package/dist/protocols/utils/openai-image.js +18 -0
  70. package/dist/protocols/utils/openai-options.d.ts +16 -0
  71. package/dist/protocols/utils/openai-options.js +14 -0
  72. package/dist/protocols/utils/partial-json-options.d.ts +62 -0
  73. package/dist/protocols/utils/partial-json-options.js +52 -0
  74. package/dist/protocols/utils/partial-json.d.ts +8 -0
  75. package/dist/protocols/utils/partial-json.js +279 -0
  76. package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
  77. package/dist/protocols/utils/responses-checkpoint.js +107 -0
  78. package/dist/protocols/utils/responses-compaction.d.ts +4 -0
  79. package/dist/protocols/utils/responses-compaction.js +129 -0
  80. package/dist/protocols/utils/responses-hosted-tools.d.ts +26 -0
  81. package/dist/protocols/utils/responses-hosted-tools.js +32 -0
  82. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  83. package/dist/protocols/utils/tool-schema.js +54 -0
  84. package/dist/protocols/utils/tool-stream.d.ts +710 -0
  85. package/dist/protocols/utils/tool-stream.js +155 -0
  86. package/dist/protocols/xai-images.d.ts +26 -0
  87. package/dist/protocols/xai-images.js +106 -0
  88. package/dist/protocols/xai-responses.d.ts +250 -0
  89. package/dist/protocols/xai-responses.js +81 -0
  90. package/dist/protocols/zai-images.d.ts +22 -0
  91. package/dist/protocols/zai-images.js +79 -0
  92. package/dist/protocols.d.ts +1 -0
  93. package/dist/protocols.js +1 -0
  94. package/dist/provider-error.d.ts +15 -0
  95. package/dist/provider-error.js +125 -0
  96. package/dist/provider-package.d.ts +11 -0
  97. package/dist/provider-package.js +1 -0
  98. package/dist/provider.d.ts +23 -0
  99. package/dist/provider.js +2 -0
  100. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  101. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  102. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  103. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  104. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  105. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  106. package/dist/providers/amazon-bedrock-mantle.d.ts +371 -0
  107. package/dist/providers/amazon-bedrock-mantle.js +76 -0
  108. package/dist/providers/amazon-bedrock.d.ts +173 -0
  109. package/dist/providers/amazon-bedrock.js +41 -0
  110. package/dist/providers/anthropic-compatible.d.ts +304 -0
  111. package/dist/providers/anthropic-compatible.js +44 -0
  112. package/dist/providers/anthropic.d.ts +302 -0
  113. package/dist/providers/anthropic.js +39 -0
  114. package/dist/providers/azure/chat.d.ts +2 -0
  115. package/dist/providers/azure/chat.js +1 -0
  116. package/dist/providers/azure/responses.d.ts +2 -0
  117. package/dist/providers/azure/responses.js +1 -0
  118. package/dist/providers/azure.d.ts +599 -0
  119. package/dist/providers/azure.js +115 -0
  120. package/dist/providers/baseten.d.ts +229 -0
  121. package/dist/providers/baseten.js +38 -0
  122. package/dist/providers/cerebras.d.ts +228 -0
  123. package/dist/providers/cerebras.js +40 -0
  124. package/dist/providers/cloudflare-ai-gateway.d.ts +238 -0
  125. package/dist/providers/cloudflare-ai-gateway.js +59 -0
  126. package/dist/providers/cloudflare-workers-ai.d.ts +232 -0
  127. package/dist/providers/cloudflare-workers-ai.js +45 -0
  128. package/dist/providers/deepinfra.d.ts +228 -0
  129. package/dist/providers/deepinfra.js +43 -0
  130. package/dist/providers/deepseek.d.ts +229 -0
  131. package/dist/providers/deepseek.js +41 -0
  132. package/dist/providers/fireworks.d.ts +229 -0
  133. package/dist/providers/fireworks.js +38 -0
  134. package/dist/providers/google-vertex/chat.d.ts +2 -0
  135. package/dist/providers/google-vertex/chat.js +1 -0
  136. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  137. package/dist/providers/google-vertex/gemini.js +1 -0
  138. package/dist/providers/google-vertex/messages.d.ts +2 -0
  139. package/dist/providers/google-vertex/messages.js +1 -0
  140. package/dist/providers/google-vertex/responses.d.ts +2 -0
  141. package/dist/providers/google-vertex/responses.js +1 -0
  142. package/dist/providers/google-vertex-chat.d.ts +133 -0
  143. package/dist/providers/google-vertex-chat.js +55 -0
  144. package/dist/providers/google-vertex-messages.d.ts +301 -0
  145. package/dist/providers/google-vertex-messages.js +75 -0
  146. package/dist/providers/google-vertex-responses.d.ts +198 -0
  147. package/dist/providers/google-vertex-responses.js +56 -0
  148. package/dist/providers/google-vertex-shared.d.ts +22 -0
  149. package/dist/providers/google-vertex-shared.js +61 -0
  150. package/dist/providers/google-vertex.d.ts +120 -0
  151. package/dist/providers/google-vertex.js +92 -0
  152. package/dist/providers/google.d.ts +115 -0
  153. package/dist/providers/google.js +42 -0
  154. package/dist/providers/groq.d.ts +315 -0
  155. package/dist/providers/groq.js +81 -0
  156. package/dist/providers/index.d.ts +28 -0
  157. package/dist/providers/index.js +28 -0
  158. package/dist/providers/meta/chat.d.ts +2 -0
  159. package/dist/providers/meta/chat.js +1 -0
  160. package/dist/providers/meta/messages.d.ts +2 -0
  161. package/dist/providers/meta/messages.js +1 -0
  162. package/dist/providers/meta/responses.d.ts +2 -0
  163. package/dist/providers/meta/responses.js +1 -0
  164. package/dist/providers/meta.d.ts +631 -0
  165. package/dist/providers/meta.js +113 -0
  166. package/dist/providers/minimax/chat.d.ts +4 -0
  167. package/dist/providers/minimax/chat.js +8 -0
  168. package/dist/providers/minimax/messages.d.ts +1 -0
  169. package/dist/providers/minimax/messages.js +1 -0
  170. package/dist/providers/minimax/responses.d.ts +4 -0
  171. package/dist/providers/minimax/responses.js +8 -0
  172. package/dist/providers/minimax.d.ts +593 -0
  173. package/dist/providers/minimax.js +89 -0
  174. package/dist/providers/mistral.d.ts +208 -0
  175. package/dist/providers/mistral.js +28 -0
  176. package/dist/providers/open-responses-options.d.ts +6 -0
  177. package/dist/providers/open-responses-options.js +1 -0
  178. package/dist/providers/openai/chat.d.ts +2 -0
  179. package/dist/providers/openai/chat.js +1 -0
  180. package/dist/providers/openai/responses.d.ts +2 -0
  181. package/dist/providers/openai/responses.js +1 -0
  182. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  183. package/dist/providers/openai-compatible/responses.js +1 -0
  184. package/dist/providers/openai-compatible-responses.d.ts +196 -0
  185. package/dist/providers/openai-compatible-responses.js +32 -0
  186. package/dist/providers/openai-compatible.d.ts +131 -0
  187. package/dist/providers/openai-compatible.js +33 -0
  188. package/dist/providers/openai-options.d.ts +26 -0
  189. package/dist/providers/openai-options.js +41 -0
  190. package/dist/providers/openai.d.ts +405 -0
  191. package/dist/providers/openai.js +82 -0
  192. package/dist/providers/openrouter.d.ts +564 -0
  193. package/dist/providers/openrouter.js +114 -0
  194. package/dist/providers/togetherai.d.ts +228 -0
  195. package/dist/providers/togetherai.js +40 -0
  196. package/dist/providers/xai.d.ts +164 -0
  197. package/dist/providers/xai.js +84 -0
  198. package/dist/providers/zai.d.ts +24 -0
  199. package/dist/providers/zai.js +21 -0
  200. package/dist/providers.d.ts +1 -0
  201. package/dist/providers.js +1 -0
  202. package/dist/route/auth-options.d.ts +34 -0
  203. package/dist/route/auth-options.js +14 -0
  204. package/dist/route/auth.d.ts +51 -0
  205. package/dist/route/auth.js +87 -0
  206. package/dist/route/client.d.ts +430 -0
  207. package/dist/route/client.js +304 -0
  208. package/dist/route/endpoint.d.ts +28 -0
  209. package/dist/route/endpoint.js +21 -0
  210. package/dist/route/executor.d.ts +27 -0
  211. package/dist/route/executor.js +183 -0
  212. package/dist/route/framing.d.ts +29 -0
  213. package/dist/route/framing.js +14 -0
  214. package/dist/route/index.d.ts +16 -0
  215. package/dist/route/index.js +9 -0
  216. package/dist/route/protocol.d.ts +76 -0
  217. package/dist/route/protocol.js +16 -0
  218. package/dist/route/transport/http.d.ts +34 -0
  219. package/dist/route/transport/http.js +68 -0
  220. package/dist/route/transport/index.d.ts +41 -0
  221. package/dist/route/transport/index.js +4 -0
  222. package/dist/route/transport/websocket-channel.d.ts +57 -0
  223. package/dist/route/transport/websocket-channel.js +1 -0
  224. package/dist/route/transport/websocket.d.ts +56 -0
  225. package/dist/route/transport/websocket.js +366 -0
  226. package/dist/route.d.ts +1 -0
  227. package/dist/route.js +1 -0
  228. package/dist/schema/errors.d.ts +158 -0
  229. package/dist/schema/errors.js +120 -0
  230. package/dist/schema/events.d.ts +8123 -0
  231. package/dist/schema/events.js +550 -0
  232. package/dist/schema/ids.d.ts +17 -0
  233. package/dist/schema/ids.js +10 -0
  234. package/dist/schema/index.d.ts +5 -0
  235. package/dist/schema/index.js +5 -0
  236. package/dist/schema/messages.d.ts +646 -0
  237. package/dist/schema/messages.js +301 -0
  238. package/dist/schema/options.d.ts +157 -0
  239. package/dist/schema/options.js +187 -0
  240. package/dist/testing.d.ts +1693 -0
  241. package/dist/testing.js +129 -0
  242. package/dist/tool-history.d.ts +2 -0
  243. package/dist/tool-history.js +84 -0
  244. package/dist/tool-runtime.d.ts +15 -0
  245. package/dist/tool-runtime.js +62 -0
  246. package/dist/tool.d.ts +136 -0
  247. package/dist/tool.js +66 -0
  248. package/dist/utils/record.d.ts +2 -0
  249. package/dist/utils/record.js +2 -0
  250. package/dist/utils/sanitize.d.ts +1 -0
  251. package/dist/utils/sanitize.js +12 -0
  252. package/package.json +48 -0
@@ -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,87 @@
1
+ import { Config, Effect, Redacted } from "effect";
2
+ import { Headers } from "effect/unstable/http";
3
+ import { AuthenticationError, InvalidRequestError, 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
+ reason: error instanceof MissingCredentialError
80
+ ? new AuthenticationError({ message: error.message, cause: error })
81
+ : new InvalidRequestError({ message: `Failed to resolve auth config: ${error.message}`, cause: error }),
82
+ });
83
+ }
84
+ return error;
85
+ };
86
+ export const toEffect = (input) => (authInput) => input.apply(authInput).pipe(Effect.mapError(toAIError));
87
+ export * as Auth from "./auth.js";
@@ -0,0 +1,430 @@
1
+ import { Context, Effect, Layer, Schema, Stream } from "effect";
2
+ import { Auth } from "./auth.js";
3
+ import { Endpoint, type EndpointPatch } from "./endpoint.js";
4
+ import { RequestExecutor } from "./executor.js";
5
+ import { Framing } from "./framing.js";
6
+ import { HttpTransport } from "./transport/index.js";
7
+ import type { HttpMiddleware, Transport, TransportRuntime, WebSocketChannelExecutor } from "./transport/index.js";
8
+ import type { Protocol } from "./protocol.js";
9
+ import type { ProtocolID, ProviderOptions } from "../schema/index.js";
10
+ import { AIError, CompactionResponse, CompactionCheckpointResponse, GenerationOptions, HttpOptions, LLMRequest, LLMResponse, LanguageModel, LLMEvent, ProviderID } from "../schema/index.js";
11
+ export interface RouteBody<Body> {
12
+ /** Schema for the validated provider-native body sent as the JSON request. */
13
+ readonly schema: Schema.Codec<Body, unknown>;
14
+ /** Build the provider-native body from a common `LLMRequest`. */
15
+ readonly from: (request: LLMRequest) => Effect.Effect<Body, AIError>;
16
+ }
17
+ export interface Route<Body, Prepared = unknown, Compact extends CompactionOperations | undefined = CompactionOperations | undefined> {
18
+ readonly compact: Compact;
19
+ readonly id: string;
20
+ readonly provider?: ProviderID;
21
+ /** ProviderMetadata namespace emitted and consumed by this route. */
22
+ readonly providerMetadataKey?: string;
23
+ readonly protocol: ProtocolID;
24
+ readonly endpoint: Endpoint.Definition<Body>;
25
+ readonly auth: Auth.Definition;
26
+ /** Deployment headers resolved once for every operation, before transport authentication. */
27
+ readonly headers?: (input: {
28
+ readonly request: LLMRequest;
29
+ }) => Record<string, string>;
30
+ readonly transport: Transport<Body, Prepared, unknown>;
31
+ readonly defaults: RouteDefaults;
32
+ readonly body: RouteBody<Body>;
33
+ readonly with: {
34
+ <Next extends CompactionOperations | undefined>(patch: RoutePatch<Body, Prepared> & {
35
+ readonly compact: Next;
36
+ }): Route<Body, Prepared, Next>;
37
+ (patch: Omit<RoutePatch<Body, Prepared>, "compact"> & {
38
+ readonly compact?: undefined;
39
+ }): Route<Body, Prepared, Compact>;
40
+ (patch: RoutePatch<Body, Prepared>): Route<Body, Prepared>;
41
+ };
42
+ readonly model: <Options extends ProviderOptions = ProviderOptions>(input: RouteMappedLanguageModelInput) => LanguageModel<Options, Compact>;
43
+ readonly prepareTransport: (body: Body, request: LLMRequest, options?: StreamOptions) => Effect.Effect<Prepared, AIError>;
44
+ readonly streamPrepared: (prepared: Prepared, request: LLMRequest, runtime: TransportRuntime, options?: StreamOptions) => Stream.Stream<LLMEvent, AIError>;
45
+ }
46
+ export type AnyRoute<Compact extends CompactionOperations | undefined = CompactionOperations | undefined> = Route<any, any, Compact>;
47
+ export type HttpOptionsInput = HttpOptions.Input;
48
+ export type RouteLanguageModelInput = Omit<LanguageModel.Input, "provider" | "route">;
49
+ export type RouteRoutedLanguageModelInput = Omit<LanguageModel.Input, "route">;
50
+ export interface RouteDefaults {
51
+ readonly headers?: Record<string, string>;
52
+ readonly generation?: GenerationOptions;
53
+ readonly providerOptions?: ProviderOptions;
54
+ readonly http?: HttpOptions;
55
+ }
56
+ export interface RouteDefaultsInput {
57
+ readonly headers?: Record<string, string>;
58
+ readonly generation?: GenerationOptions.Input;
59
+ readonly providerOptions?: ProviderOptions;
60
+ readonly http?: HttpOptions.Input;
61
+ }
62
+ export interface RoutePatch<Body, Prepared> extends RouteDefaultsInput {
63
+ readonly compact?: CompactionOperations;
64
+ readonly id?: string;
65
+ readonly provider?: string | ProviderID;
66
+ readonly providerMetadataKey?: string;
67
+ readonly auth?: Auth.Definition;
68
+ readonly transport?: Transport<Body, Prepared, unknown>;
69
+ readonly endpoint?: EndpointPatch<Body>;
70
+ }
71
+ type RouteMappedLanguageModelInput = RouteLanguageModelInput | RouteRoutedLanguageModelInput;
72
+ export declare const generationOptions: (input: GenerationOptions.Input | undefined) => GenerationOptions | undefined;
73
+ export declare const httpOptions: (input: HttpOptionsInput | undefined) => HttpOptions | undefined;
74
+ export interface Interface {
75
+ readonly compact: CompactMethod;
76
+ readonly stream: StreamMethod;
77
+ readonly generate: GenerateMethod;
78
+ }
79
+ export interface StreamOptions {
80
+ readonly http?: HttpMiddleware;
81
+ readonly webSocket?: WebSocketChannelExecutor;
82
+ }
83
+ export interface StreamMethod {
84
+ (request: LLMRequest, options?: StreamOptions): Stream.Stream<LLMEvent, AIError>;
85
+ }
86
+ export interface GenerateMethod {
87
+ (request: LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError>;
88
+ }
89
+ export type CompactOperation = (request: LLMRequest, executor: RequestExecutor.Interface, options?: Pick<StreamOptions, "http">) => Effect.Effect<CompactionResponse, AIError>;
90
+ export type TriggerCompactOperation = (request: LLMRequest, executor: RequestExecutor.Interface, options: TriggerCompactOptions) => Effect.Effect<CompactionCheckpointResponse, AIError>;
91
+ /** Protocol capabilities, not deployment/model eligibility. */
92
+ export interface CompactionOperations {
93
+ readonly endpoint?: CompactOperation;
94
+ readonly trigger?: TriggerCompactOperation;
95
+ }
96
+ export interface EndpointCompactOptions extends Pick<StreamOptions, "http"> {
97
+ readonly mechanism?: "endpoint";
98
+ readonly webSocket?: never;
99
+ }
100
+ export interface TriggerCompactOptions extends StreamOptions {
101
+ readonly mechanism: "trigger";
102
+ }
103
+ export type CompactionRequest = LLMRequest & {
104
+ readonly model: LanguageModel<ProviderOptions, {
105
+ readonly endpoint: CompactOperation;
106
+ }>;
107
+ };
108
+ export type CheckpointRequest = LLMRequest & {
109
+ readonly model: LanguageModel<ProviderOptions, {
110
+ readonly trigger: TriggerCompactOperation;
111
+ }>;
112
+ };
113
+ export interface CompactMethod<R = never> {
114
+ (request: CheckpointRequest, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, R>;
115
+ (request: CompactionRequest, options?: EndpointCompactOptions): Effect.Effect<CompactionResponse, AIError, R>;
116
+ }
117
+ export declare function canCompact(request: LLMRequest, options?: {
118
+ readonly mechanism?: "endpoint";
119
+ }): request is CompactionRequest;
120
+ export declare function canCompact(request: LLMRequest, options: {
121
+ readonly mechanism: "trigger";
122
+ }): request is CheckpointRequest;
123
+ declare const Service_base: Context.ServiceClass<Service, "@opencode/LLMClient", Interface>;
124
+ export declare class Service extends Service_base {
125
+ }
126
+ export interface MakeInput<Body, Frame, Event, State> {
127
+ readonly compact?: CompactionOperations;
128
+ /** Route id used in diagnostics and prepared request metadata. */
129
+ readonly id: string;
130
+ /** Provider identity for route-owned model construction. */
131
+ readonly provider?: string | ProviderID;
132
+ /** ProviderMetadata namespace emitted and consumed by this route. */
133
+ readonly providerMetadataKey?: string;
134
+ /** Semantic API contract — owns body construction, body schema, and parsing. */
135
+ readonly protocol: Protocol<Body, Frame, Event, State>;
136
+ /** Where the request is sent. */
137
+ readonly endpoint: Endpoint.Definition<Body>;
138
+ /** Per-request transport auth. Provider facades override this via `route.with(...)`. */
139
+ readonly auth?: Auth.Definition;
140
+ /** Stream framing — bytes -> frames before `protocol.stream.event` decoding. */
141
+ readonly framing: Framing.Definition<Frame>;
142
+ /** Static / per-request headers added before `auth` runs. */
143
+ readonly headers?: (input: {
144
+ readonly request: LLMRequest;
145
+ }) => Record<string, string>;
146
+ /** Route/request defaults used when compiling requests for this route. */
147
+ readonly defaults?: RouteDefaultsInput;
148
+ }
149
+ export interface MakeTransportInput<Body, Prepared, Frame, Event, State> {
150
+ readonly compact?: CompactionOperations;
151
+ /** Route id used in diagnostics and prepared request metadata. */
152
+ readonly id: string;
153
+ /** Provider identity for route-owned model construction. */
154
+ readonly provider?: string | ProviderID;
155
+ /** ProviderMetadata namespace emitted and consumed by this route. */
156
+ readonly providerMetadataKey?: string;
157
+ /** Semantic API contract — owns body construction, body schema, and parsing. */
158
+ readonly protocol: Protocol<Body, Frame, Event, State>;
159
+ /** Where the request is sent. */
160
+ readonly endpoint: Endpoint.Definition<Body>;
161
+ /** Per-request transport auth. Provider facades override this via `route.with(...)`. */
162
+ readonly auth?: Auth.Definition;
163
+ /** Static / per-request headers added before `auth` runs. */
164
+ readonly headers?: (input: {
165
+ readonly request: LLMRequest;
166
+ }) => Record<string, string>;
167
+ /** Runnable transport route. */
168
+ readonly transport: Transport<Body, Prepared, Frame>;
169
+ /** Route/request defaults used when compiling requests for this route. */
170
+ readonly defaults?: RouteDefaultsInput;
171
+ }
172
+ export declare function make<Body, Prepared, Frame, Event, State, Compact extends CompactionOperations>(input: MakeTransportInput<Body, Prepared, Frame, Event, State> & {
173
+ readonly compact: Compact;
174
+ }): Route<Body, Prepared, Compact>;
175
+ export declare function make<Body, Frame, Event, State, Compact extends CompactionOperations>(input: MakeInput<Body, Frame, Event, State> & {
176
+ readonly compact: Compact;
177
+ }): Route<Body, HttpTransport.HttpPrepared<Frame>, Compact>;
178
+ export declare function make<Body, Prepared, Frame, Event, State>(input: MakeTransportInput<Body, Prepared, Frame, Event, State>): Route<Body, Prepared>;
179
+ /**
180
+ * Build a `Route` by composing the four orthogonal pieces of a deployment:
181
+ *
182
+ * - `Protocol` — what is the API I'm speaking?
183
+ * - `Endpoint` — where do I send the request?
184
+ * - `Auth` — how do I authenticate it?
185
+ * - `Framing` — how do I cut the response stream into protocol frames?
186
+ *
187
+ * Plus optional `headers` for cross-cutting deployment concerns (provider
188
+ * version pins, per-deployment quirks).
189
+ *
190
+ * This is the canonical route constructor. If a new route does not fit
191
+ * this four-axis model, add a purpose-built constructor rather than widening
192
+ * the public surface preemptively.
193
+ */
194
+ export declare function make<Body, Frame, Event, State>(input: MakeInput<Body, Frame, Event, State>): Route<Body, HttpTransport.HttpPrepared<Frame>>;
195
+ /** @internal Test-only projection of the execution compiler; not exported from package barrels. */
196
+ export declare const compileRequest: (request: LLMRequest<LanguageModel<{
197
+ readonly [x: string]: unknown;
198
+ }, CompactionOperations | undefined>>) => Effect.Effect<{
199
+ id: string;
200
+ route: string;
201
+ protocol: string;
202
+ model: LanguageModel<{
203
+ readonly [x: string]: unknown;
204
+ }, CompactionOperations | undefined>;
205
+ body: any;
206
+ metadata: {
207
+ transport: string;
208
+ };
209
+ }, AIError, never>;
210
+ export declare function stream(request: LLMRequest, options?: StreamOptions): Stream.Stream<LLMEvent, AIError, Service>;
211
+ export declare function generate(request: LLMRequest, options?: StreamOptions): Effect.Effect<LLMResponse, AIError, Service>;
212
+ export declare function compact(request: CheckpointRequest, options: TriggerCompactOptions): Effect.Effect<CompactionCheckpointResponse, AIError, Service>;
213
+ export declare function compact(request: CompactionRequest, options?: EndpointCompactOptions): Effect.Effect<CompactionResponse, AIError, Service>;
214
+ export declare const streamRequest: (request: LLMRequest, options?: StreamOptions) => Stream.Stream<({
215
+ readonly type: "compaction";
216
+ readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
217
+ readonly id?: string | undefined;
218
+ readonly text?: string | null | undefined;
219
+ readonly encrypted?: string | undefined;
220
+ } & ({
221
+ readonly encrypted: string;
222
+ readonly text?: never;
223
+ } | {
224
+ readonly text: string | null;
225
+ readonly encrypted?: never;
226
+ })) | {
227
+ readonly type: "step-start";
228
+ readonly index: number;
229
+ } | {
230
+ readonly id: string;
231
+ readonly type: "text-start";
232
+ readonly providerMetadata?: {
233
+ readonly [x: string]: {
234
+ readonly [x: string]: unknown;
235
+ };
236
+ } | undefined;
237
+ } | {
238
+ readonly id: string;
239
+ readonly type: "text-delta";
240
+ readonly text: string;
241
+ readonly providerMetadata?: {
242
+ readonly [x: string]: {
243
+ readonly [x: string]: unknown;
244
+ };
245
+ } | undefined;
246
+ } | {
247
+ readonly id: string;
248
+ readonly type: "text-end";
249
+ readonly text?: string | undefined;
250
+ readonly providerMetadata?: {
251
+ readonly [x: string]: {
252
+ readonly [x: string]: unknown;
253
+ };
254
+ } | undefined;
255
+ } | {
256
+ readonly id: string;
257
+ readonly type: "reasoning-start";
258
+ readonly providerMetadata?: {
259
+ readonly [x: string]: {
260
+ readonly [x: string]: unknown;
261
+ };
262
+ } | undefined;
263
+ } | {
264
+ readonly id: string;
265
+ readonly type: "reasoning-delta";
266
+ readonly text: string;
267
+ readonly providerMetadata?: {
268
+ readonly [x: string]: {
269
+ readonly [x: string]: unknown;
270
+ };
271
+ } | undefined;
272
+ } | {
273
+ readonly id: string;
274
+ readonly type: "reasoning-end";
275
+ readonly text?: string | undefined;
276
+ readonly providerMetadata?: {
277
+ readonly [x: string]: {
278
+ readonly [x: string]: unknown;
279
+ };
280
+ } | undefined;
281
+ } | {
282
+ readonly id: string;
283
+ readonly type: "tool-input-start";
284
+ readonly name: string;
285
+ readonly providerMetadata?: {
286
+ readonly [x: string]: {
287
+ readonly [x: string]: unknown;
288
+ };
289
+ } | undefined;
290
+ readonly namespace?: string | undefined;
291
+ readonly providerExecuted?: boolean | undefined;
292
+ } | {
293
+ readonly id: string;
294
+ readonly type: "tool-input-delta";
295
+ readonly name: string;
296
+ readonly text: string;
297
+ readonly input?: unknown;
298
+ readonly namespace?: string | undefined;
299
+ } | {
300
+ readonly id: string;
301
+ readonly type: "tool-input-end";
302
+ readonly name: string;
303
+ readonly providerMetadata?: {
304
+ readonly [x: string]: {
305
+ readonly [x: string]: unknown;
306
+ };
307
+ } | undefined;
308
+ readonly namespace?: string | undefined;
309
+ } | {
310
+ readonly id: string;
311
+ readonly type: "tool-input-error";
312
+ readonly name: string;
313
+ readonly raw: string;
314
+ readonly namespace?: string | undefined;
315
+ } | {
316
+ readonly id: string;
317
+ readonly type: "tool-call";
318
+ readonly name: string;
319
+ readonly input: unknown;
320
+ readonly providerMetadata?: {
321
+ readonly [x: string]: {
322
+ readonly [x: string]: unknown;
323
+ };
324
+ } | undefined;
325
+ readonly namespace?: string | undefined;
326
+ readonly providerExecuted?: boolean | undefined;
327
+ } | {
328
+ readonly id: string;
329
+ readonly type: "tool-result";
330
+ readonly name: string;
331
+ readonly result: {
332
+ readonly type: "json";
333
+ readonly value: unknown;
334
+ } | {
335
+ readonly type: "text";
336
+ readonly value: unknown;
337
+ } | {
338
+ readonly type: "error";
339
+ readonly value: unknown;
340
+ } | {
341
+ readonly type: "content";
342
+ readonly value: readonly ({
343
+ readonly type: "text";
344
+ readonly text: string;
345
+ } | {
346
+ readonly type: "file";
347
+ readonly uri: string;
348
+ readonly mime: string;
349
+ readonly name?: string | undefined;
350
+ })[];
351
+ };
352
+ readonly output?: {
353
+ readonly structured: unknown;
354
+ readonly content: readonly ({
355
+ readonly type: "text";
356
+ readonly text: string;
357
+ } | {
358
+ readonly type: "file";
359
+ readonly uri: string;
360
+ readonly mime: string;
361
+ readonly name?: string | undefined;
362
+ })[];
363
+ } | undefined;
364
+ readonly providerMetadata?: {
365
+ readonly [x: string]: {
366
+ readonly [x: string]: unknown;
367
+ };
368
+ } | undefined;
369
+ readonly namespace?: string | undefined;
370
+ readonly providerExecuted?: boolean | undefined;
371
+ } | {
372
+ readonly id: string;
373
+ readonly type: "tool-error";
374
+ readonly name: string;
375
+ readonly message: string;
376
+ readonly error?: unknown;
377
+ readonly providerMetadata?: {
378
+ readonly [x: string]: {
379
+ readonly [x: string]: unknown;
380
+ };
381
+ } | undefined;
382
+ readonly namespace?: string | undefined;
383
+ } | {
384
+ readonly type: "step-finish";
385
+ readonly reason: {
386
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
387
+ readonly raw?: string | undefined;
388
+ };
389
+ readonly index: number;
390
+ readonly providerMetadata?: {
391
+ readonly [x: string]: {
392
+ readonly [x: string]: unknown;
393
+ };
394
+ } | undefined;
395
+ readonly usage?: import("../schema/events.js").Usage | undefined;
396
+ } | {
397
+ readonly type: "finish";
398
+ readonly reason: {
399
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
400
+ readonly raw?: string | undefined;
401
+ };
402
+ readonly providerMetadata?: {
403
+ readonly [x: string]: {
404
+ readonly [x: string]: unknown;
405
+ };
406
+ } | undefined;
407
+ readonly usage?: import("../schema/events.js").Usage | undefined;
408
+ } | {
409
+ readonly type: "provider-error";
410
+ readonly message: string;
411
+ readonly providerMetadata?: {
412
+ readonly [x: string]: {
413
+ readonly [x: string]: unknown;
414
+ };
415
+ } | undefined;
416
+ readonly classification?: "context-overflow" | "payload-too-large" | undefined;
417
+ }, AIError, Service>;
418
+ export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
419
+ export declare const Route: {
420
+ readonly make: typeof make;
421
+ };
422
+ export declare const LLMClient: {
423
+ readonly canCompact: typeof canCompact;
424
+ readonly compact: typeof compact;
425
+ readonly Service: typeof Service;
426
+ readonly layer: Layer.Layer<Service, never, RequestExecutor.Service>;
427
+ readonly stream: typeof stream;
428
+ readonly generate: typeof generate;
429
+ };
430
+ export {};