@opencode/ai 2.1.4 → 2.2.0

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 (269) hide show
  1. package/README.md +283 -114
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/cache-policy.d.ts +4 -0
  5. package/dist/cache-policy.js +20 -6
  6. package/dist/decision-client.d.ts +21 -0
  7. package/dist/decision-client.js +55 -0
  8. package/dist/decision.d.ts +472 -0
  9. package/dist/decision.js +158 -0
  10. package/dist/effect.d.ts +38 -0
  11. package/dist/effect.js +27 -0
  12. package/dist/effort-updates.d.ts +2 -2
  13. package/dist/experimental/cloudflare-run-extraction.d.ts +13 -0
  14. package/dist/experimental/cloudflare-run-extraction.js +83 -0
  15. package/dist/experimental/extraction.d.ts +183 -0
  16. package/dist/experimental/extraction.js +102 -0
  17. package/dist/experimental/realtime.d.ts +7 -2
  18. package/dist/experimental/realtime.js +5 -5
  19. package/dist/experimental.d.ts +2 -3
  20. package/dist/experimental.js +1 -2
  21. package/dist/image-client.d.ts +5 -14
  22. package/dist/image-client.js +0 -1
  23. package/dist/image.d.ts +6 -176
  24. package/dist/image.js +4 -11
  25. package/dist/index.d.ts +1426 -34
  26. package/dist/index.js +127 -24
  27. package/dist/llm.d.ts +16 -1
  28. package/dist/llm.js +34 -0
  29. package/dist/media-client.d.ts +2 -1
  30. package/dist/media-model.d.ts +3 -0
  31. package/dist/media-model.js +4 -1
  32. package/dist/media.d.ts +0 -7
  33. package/dist/media.js +0 -6
  34. package/dist/protocols/alibaba-chat.d.ts +20 -0
  35. package/dist/protocols/alibaba-images.d.ts +22 -0
  36. package/dist/protocols/alibaba-images.js +77 -0
  37. package/dist/protocols/alibaba-messages.d.ts +52 -17
  38. package/dist/protocols/alibaba-responses.d.ts +6 -3
  39. package/dist/protocols/anthropic-messages.d.ts +160 -54
  40. package/dist/protocols/anthropic-messages.js +44 -13
  41. package/dist/protocols/bedrock-converse.d.ts +110 -15
  42. package/dist/protocols/bedrock-converse.js +112 -15
  43. package/dist/protocols/bedrock-event-stream.js +1 -0
  44. package/dist/protocols/bfl-images.d.ts +9 -0
  45. package/dist/protocols/bfl-images.js +17 -15
  46. package/dist/protocols/cartesia-speech.d.ts +0 -18
  47. package/dist/protocols/cloudflare-run-decisions.d.ts +9 -0
  48. package/dist/protocols/cloudflare-run-decisions.js +36 -0
  49. package/dist/protocols/cloudflare-workers-ai-images.d.ts +23 -0
  50. package/dist/protocols/cloudflare-workers-ai-images.js +80 -0
  51. package/dist/protocols/deepgram-speech.d.ts +0 -18
  52. package/dist/protocols/elevenlabs-speech.d.ts +0 -18
  53. package/dist/protocols/fal-images.d.ts +10 -1
  54. package/dist/protocols/fal-images.js +16 -25
  55. package/dist/protocols/fal-video.js +1 -1
  56. package/dist/protocols/gemini.d.ts +3 -0
  57. package/dist/protocols/gemini.js +11 -6
  58. package/dist/protocols/google-images.d.ts +2 -2
  59. package/dist/protocols/google-images.js +8 -37
  60. package/dist/protocols/google-interactions.d.ts +4 -0
  61. package/dist/protocols/google-interactions.js +12 -5
  62. package/dist/protocols/google-speech.d.ts +0 -18
  63. package/dist/protocols/google-speech.js +0 -1
  64. package/dist/protocols/google-transcription.d.ts +0 -18
  65. package/dist/protocols/google-transcription.js +0 -1
  66. package/dist/protocols/google-video.d.ts +1 -1
  67. package/dist/protocols/google-video.js +2 -7
  68. package/dist/protocols/index.d.ts +3 -0
  69. package/dist/protocols/index.js +3 -0
  70. package/dist/protocols/meta-images.d.ts +7 -1
  71. package/dist/protocols/meta-images.js +10 -8
  72. package/dist/protocols/meta-messages.d.ts +52 -17
  73. package/dist/protocols/meta-messages.js +14 -1
  74. package/dist/protocols/meta-responses.d.ts +6 -0
  75. package/dist/protocols/meta-responses.js +29 -1
  76. package/dist/protocols/open-responses.d.ts +30 -0
  77. package/dist/protocols/open-responses.js +8 -18
  78. package/dist/protocols/openai-chat.d.ts +713 -1
  79. package/dist/protocols/openai-chat.js +35 -22
  80. package/dist/protocols/openai-compatible-chat.d.ts +22 -1
  81. package/dist/protocols/openai-compatible-responses.d.ts +8 -5
  82. package/dist/protocols/openai-decisions.d.ts +22 -0
  83. package/dist/protocols/openai-decisions.js +128 -0
  84. package/dist/protocols/openai-images.d.ts +21 -24
  85. package/dist/protocols/openai-images.js +100 -34
  86. package/dist/protocols/openai-responses.d.ts +82 -24
  87. package/dist/protocols/openai-responses.js +32 -2
  88. package/dist/protocols/openai-speech.d.ts +0 -18
  89. package/dist/protocols/openai-speech.js +15 -5
  90. package/dist/protocols/openai-transcription.d.ts +0 -18
  91. package/dist/protocols/openai-transcription.js +3 -4
  92. package/dist/protocols/replicate-images.js +1 -1
  93. package/dist/protocols/runway-video.d.ts +1 -1
  94. package/dist/protocols/runway-video.js +1 -1
  95. package/dist/protocols/shared.d.ts +9 -1
  96. package/dist/protocols/shared.js +13 -2
  97. package/dist/protocols/stability-images.d.ts +5 -0
  98. package/dist/protocols/stability-images.js +4 -9
  99. package/dist/protocols/system-one.d.ts +101 -0
  100. package/dist/protocols/system-one.js +230 -0
  101. package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
  102. package/dist/protocols/utils/bedrock-cache.js +7 -6
  103. package/dist/protocols/utils/cache.d.ts +14 -3
  104. package/dist/protocols/utils/cache.js +11 -4
  105. package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
  106. package/dist/protocols/utils/gemini-generate-content.js +10 -16
  107. package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
  108. package/dist/protocols/utils/gemini-json-schema.js +3 -3
  109. package/dist/protocols/utils/image-sizing.d.ts +31 -0
  110. package/dist/protocols/utils/image-sizing.js +73 -0
  111. package/dist/protocols/utils/media-input.d.ts +4 -5
  112. package/dist/protocols/utils/media-input.js +8 -5
  113. package/dist/protocols/utils/speech-stream.d.ts +0 -1
  114. package/dist/protocols/utils/speech-stream.js +0 -1
  115. package/dist/protocols/utils/tool-schema.js +15 -5
  116. package/dist/protocols/utils/tool-stream.d.ts +9 -0
  117. package/dist/protocols/venice-chat.d.ts +19 -0
  118. package/dist/protocols/venice-chat.js +1 -1
  119. package/dist/protocols/xai-images.d.ts +1 -2
  120. package/dist/protocols/xai-images.js +9 -2
  121. package/dist/protocols/xai-responses.d.ts +10 -0
  122. package/dist/protocols/xai-responses.js +28 -2
  123. package/dist/protocols/xai-video.d.ts +1 -1
  124. package/dist/protocols/xai-video.js +11 -8
  125. package/dist/protocols/zai-chat.d.ts +21 -0
  126. package/dist/protocols/zai-images.d.ts +3 -1
  127. package/dist/protocols/zai-images.js +12 -11
  128. package/dist/protocols/zai-messages.d.ts +52 -17
  129. package/dist/provider-error.js +19 -4
  130. package/dist/providers/alibaba/images.d.ts +2 -0
  131. package/dist/providers/alibaba/images.js +1 -0
  132. package/dist/providers/alibaba.d.ts +79 -18
  133. package/dist/providers/alibaba.js +16 -8
  134. package/dist/providers/amazon-bedrock-mantle.d.ts +197 -138
  135. package/dist/providers/amazon-bedrock.d.ts +34 -14
  136. package/dist/providers/amazon-bedrock.js +11 -11
  137. package/dist/providers/anthropic-compatible.d.ts +52 -17
  138. package/dist/providers/anthropic.d.ts +52 -17
  139. package/dist/providers/azure/images.d.ts +2 -0
  140. package/dist/providers/azure/images.js +1 -0
  141. package/dist/providers/azure.d.ts +50 -9
  142. package/dist/providers/azure.js +19 -1
  143. package/dist/providers/baseten/decisions.d.ts +2 -0
  144. package/dist/providers/baseten/decisions.js +1 -0
  145. package/dist/providers/baseten.d.ts +51 -1
  146. package/dist/providers/baseten.js +41 -8
  147. package/dist/providers/cerebras.d.ts +42 -0
  148. package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
  149. package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
  150. package/dist/providers/cloudflare-ai-gateway.d.ts +177 -43
  151. package/dist/providers/cloudflare-ai-gateway.js +32 -4
  152. package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
  153. package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
  154. package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
  155. package/dist/providers/cloudflare-workers-ai/images.js +1 -0
  156. package/dist/providers/cloudflare-workers-ai.d.ts +55 -1
  157. package/dist/providers/cloudflare-workers-ai.js +45 -9
  158. package/dist/providers/cohere.d.ts +42 -0
  159. package/dist/providers/deepinfra.d.ts +42 -0
  160. package/dist/providers/deepseek.d.ts +42 -0
  161. package/dist/providers/digitalocean/decisions.d.ts +2 -0
  162. package/dist/providers/digitalocean/decisions.js +1 -0
  163. package/dist/providers/digitalocean/images.d.ts +2 -0
  164. package/dist/providers/digitalocean/images.js +1 -0
  165. package/dist/providers/digitalocean.d.ts +72 -1
  166. package/dist/providers/digitalocean.js +39 -8
  167. package/dist/providers/fireworks.d.ts +42 -0
  168. package/dist/providers/google/images.d.ts +2 -0
  169. package/dist/providers/google/images.js +1 -0
  170. package/dist/providers/google-vertex/images.d.ts +2 -0
  171. package/dist/providers/google-vertex/images.js +1 -0
  172. package/dist/providers/google-vertex-chat.d.ts +21 -0
  173. package/dist/providers/google-vertex-messages.d.ts +52 -17
  174. package/dist/providers/google-vertex-responses.d.ts +3 -0
  175. package/dist/providers/google-vertex.d.ts +3 -1
  176. package/dist/providers/google-vertex.js +30 -13
  177. package/dist/providers/google.d.ts +5 -4
  178. package/dist/providers/google.js +15 -8
  179. package/dist/providers/groq.d.ts +42 -4
  180. package/dist/providers/groq.js +0 -6
  181. package/dist/providers/meta.d.ts +197 -138
  182. package/dist/providers/minimax.d.ts +76 -17
  183. package/dist/providers/moonshot.d.ts +76 -17
  184. package/dist/providers/openai/images.d.ts +2 -0
  185. package/dist/providers/openai/images.js +1 -0
  186. package/dist/providers/openai-compatible/images.d.ts +2 -0
  187. package/dist/providers/openai-compatible/images.js +1 -0
  188. package/dist/providers/openai-compatible-responses.d.ts +3 -0
  189. package/dist/providers/openai-compatible.d.ts +24 -1
  190. package/dist/providers/openai-compatible.js +21 -9
  191. package/dist/providers/openai-options.d.ts +3 -1
  192. package/dist/providers/openai.d.ts +46 -9
  193. package/dist/providers/openai.js +20 -4
  194. package/dist/providers/opencode/decisions.d.ts +2 -0
  195. package/dist/providers/opencode/decisions.js +1 -0
  196. package/dist/providers/opencode.d.ts +9 -10
  197. package/dist/providers/opencode.js +10 -8
  198. package/dist/providers/openrouter/decisions.d.ts +2 -0
  199. package/dist/providers/openrouter/decisions.js +1 -0
  200. package/dist/providers/openrouter/images.d.ts +2 -0
  201. package/dist/providers/openrouter/images.js +1 -0
  202. package/dist/providers/openrouter.d.ts +92 -11
  203. package/dist/providers/openrouter.js +38 -16
  204. package/dist/providers/togetherai.d.ts +42 -0
  205. package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
  206. package/dist/providers/typesafe-ai/decisions.js +1 -0
  207. package/dist/providers/typesafe-ai.d.ts +9 -10
  208. package/dist/providers/typesafe-ai.js +10 -8
  209. package/dist/providers/venice.d.ts +19 -0
  210. package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
  211. package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
  212. package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
  213. package/dist/providers/vercel-ai-gateway/images.js +1 -0
  214. package/dist/providers/vercel-ai-gateway.d.ts +10 -16
  215. package/dist/providers/vercel-ai-gateway.js +31 -85
  216. package/dist/providers/xai/images.d.ts +2 -0
  217. package/dist/providers/xai/images.js +1 -0
  218. package/dist/providers/xai.d.ts +28 -5
  219. package/dist/providers/xai.js +15 -8
  220. package/dist/providers/zai/images.d.ts +2 -0
  221. package/dist/providers/zai/images.js +1 -0
  222. package/dist/providers/zai-coding-plan.d.ts +76 -17
  223. package/dist/providers/zai.d.ts +26 -4
  224. package/dist/providers/zai.js +15 -8
  225. package/dist/route/client.d.ts +2 -2
  226. package/dist/route/client.js +26 -4
  227. package/dist/route/decision.d.ts +58 -0
  228. package/dist/route/decision.js +75 -0
  229. package/dist/route/executor.d.ts +1 -1
  230. package/dist/route/framing.d.ts +2 -0
  231. package/dist/route/index.d.ts +3 -0
  232. package/dist/route/index.js +3 -0
  233. package/dist/route/media-protocol.d.ts +1 -0
  234. package/dist/route/media-protocol.js +12 -8
  235. package/dist/route/media.d.ts +5 -1
  236. package/dist/route/media.js +6 -2
  237. package/dist/route/transport/http.js +1 -0
  238. package/dist/route/transport/index.d.ts +1 -0
  239. package/dist/schema/events.d.ts +148 -6
  240. package/dist/schema/events.js +20 -0
  241. package/dist/schema/messages.d.ts +6 -2
  242. package/dist/schema/messages.js +3 -0
  243. package/dist/schema/options.d.ts +5 -3
  244. package/dist/schema/options.js +8 -3
  245. package/dist/speech-client.d.ts +5 -14
  246. package/dist/speech-client.js +0 -1
  247. package/dist/speech.d.ts +0 -135
  248. package/dist/speech.js +2 -4
  249. package/dist/testing.d.ts +25 -24
  250. package/dist/testing.js +3 -21
  251. package/dist/transcription-client.d.ts +5 -14
  252. package/dist/transcription.d.ts +0 -135
  253. package/dist/transcription.js +1 -1
  254. package/dist/utils/media-type.js +22 -1
  255. package/dist/video-client.d.ts +5 -14
  256. package/dist/video-client.js +0 -1
  257. package/dist/video.d.ts +1 -136
  258. package/dist/video.js +3 -5
  259. package/package.json +513 -11
  260. package/dist/experimental/evaluation-client.d.ts +0 -21
  261. package/dist/experimental/evaluation-client.js +0 -64
  262. package/dist/experimental/evaluation.d.ts +0 -242
  263. package/dist/experimental/evaluation.js +0 -108
  264. package/dist/experimental/system-one.d.ts +0 -16
  265. package/dist/experimental/system-one.js +0 -135
  266. package/dist/promise.d.ts +0 -1021
  267. package/dist/promise.js +0 -101
  268. package/dist/provider.d.ts +0 -23
  269. package/dist/provider.js +0 -2
@@ -32,6 +32,14 @@ const FAILURES = {
32
32
  export const identity = (input) => {
33
33
  const provider = ProviderID.make(input.provider);
34
34
  const frameError = (message, body, cause) => new AIError({ reason: new InvalidProviderOutputError({ route: input.id, message, body, cause }) });
35
+ const readError = (http) => (cause) => new AIError({
36
+ reason: new InvalidProviderOutputError({
37
+ route: input.id,
38
+ message: `Failed to read the ${input.name} response`,
39
+ http,
40
+ cause,
41
+ }),
42
+ });
35
43
  /**
36
44
  * Read a text body while retaining the original payload and HTTP context on every downstream error. `invalid` is a
37
45
  * malformed provider document; `ended` is a generation that reached a terminal status without output (`failed`
@@ -41,14 +49,7 @@ export const identity = (input) => {
41
49
  */
42
50
  const text = Effect.fn("MediaProtocol.text")(function* (response) {
43
51
  const http = RequestExecutor.responseHttp(response);
44
- const body = yield* response.text.pipe(Effect.mapError((cause) => new AIError({
45
- reason: new InvalidProviderOutputError({
46
- route: input.id,
47
- message: `Failed to read the ${input.name} response`,
48
- http,
49
- cause,
50
- }),
51
- })));
52
+ const body = yield* response.text.pipe(Effect.mapError(readError(http)));
52
53
  return {
53
54
  body,
54
55
  http,
@@ -77,11 +78,14 @@ export const identity = (input) => {
77
78
  return { ...output, value };
78
79
  });
79
80
  };
81
+ /** Read a raw binary body, for providers that answer with the media bytes themselves. */
82
+ const bytes = (response) => response.arrayBuffer.pipe(Effect.map((buffer) => new Uint8Array(buffer)), Effect.mapError(readError(RequestExecutor.responseHttp(response))));
80
83
  return {
81
84
  id: input.id,
82
85
  name: input.name,
83
86
  provider,
84
87
  text,
88
+ bytes,
85
89
  decodeJson,
86
90
  /** Decode a submission response into the token and first snapshot. */
87
91
  decodeStarted: (schema, started) => {
@@ -4,7 +4,7 @@ import { Endpoint } from "./endpoint.js";
4
4
  import { type Interface } from "./executor-service.js";
5
5
  import { MediaProtocol } from "./media-protocol.js";
6
6
  import { Generation } from "../generation.js";
7
- import { AIError, HttpOptions, ProviderID } from "../schema/index.js";
7
+ import { AIError, HttpOptions, ProviderID, type ProviderOptions } from "../schema/index.js";
8
8
  export type Execute = Interface["execute"];
9
9
  /** The minimum a media request must carry for the route to build a transport request. */
10
10
  export interface MediaRequest {
@@ -12,7 +12,9 @@ export interface MediaRequest {
12
12
  readonly id: string;
13
13
  readonly provider: ProviderID;
14
14
  readonly http?: HttpOptions;
15
+ readonly providerOptions?: ProviderOptions;
15
16
  };
17
+ readonly providerOptions?: ProviderOptions;
16
18
  readonly http?: HttpOptions;
17
19
  }
18
20
  /** Deployment inputs every media model factory accepts; provider facades fill these from `configure(...)`. */
@@ -22,6 +24,8 @@ export interface ModelInput {
22
24
  readonly baseURL?: string;
23
25
  readonly headers?: Record<string, string>;
24
26
  readonly http?: HttpOptions;
27
+ /** Defaults under each request's `providerOptions`. */
28
+ readonly providerOptions?: ProviderOptions;
25
29
  }
26
30
  /** A provider facade's `configure(...)` input as the `ModelInput` every media selector shares, minus the model id. */
27
31
  export declare const deployment: (input: {
@@ -7,7 +7,7 @@ import { RequestExecutor } from "./executor.js";
7
7
  import { MediaProtocol } from "./media-protocol.js";
8
8
  import { Generation, isTerminal } from "../generation.js";
9
9
  import { isRetryable } from "../provider-error.js";
10
- import { AIError, AIErrorReason, HttpOptions, InvalidRequestError, ProviderID, UnsupportedOperationError, mergeHttpOptions, } from "../schema/index.js";
10
+ import { AIError, AIErrorReason, HttpOptions, InvalidRequestError, ProviderID, UnsupportedOperationError, mergeHttpOptions, mergeProviderOptions, } from "../schema/index.js";
11
11
  import { encodeJson } from "../utils/json.js";
12
12
  import { sanitizeSurrogates } from "../utils/sanitize.js";
13
13
  /** A provider facade's `configure(...)` input as the `ModelInput` every media selector shares, minus the model id. */
@@ -161,12 +161,16 @@ const makeTransport = (input) => {
161
161
  submit: Effect.fn("MediaRoute.submit")(function* (request, protocol, execute) {
162
162
  yield* rejectUnsupported(input.protocol.id, input.protocol.provider, request, protocol.unsupported);
163
163
  const http = mergeHttpOptions(routeHttp, request.model.http, request.http);
164
+ const providerOptions = mergeProviderOptions(request.model.providerOptions, request.providerOptions);
164
165
  const headers = Headers.fromInput(http?.headers);
165
166
  const prepared = protocol.prepare === undefined
166
167
  ? request
167
168
  : yield* protocol.prepare(request, (path, body) => send({ method: "POST", url: baseURL(path), headers, request, body }, execute).pipe(Effect.map((sent) => sent.response)));
168
169
  // Sanitize after merging so model-level overlays are covered; the model value is restored, not sanitized.
169
- const resolved = { ...sanitizeSurrogates({ ...prepared, http }), model: request.model };
170
+ const resolved = {
171
+ ...sanitizeSurrogates({ ...prepared, http, providerOptions }),
172
+ model: request.model,
173
+ };
170
174
  const body = yield* protocol.from(resolved);
171
175
  const url = withQuery(withQuery(Endpoint.render(input.endpoint, { request: resolved, body }), body.type === "multipart" ? undefined : body.query), http?.query);
172
176
  const sent = yield* send({ method: "POST", url, headers, request: resolved, body }, execute);
@@ -78,6 +78,7 @@ export const httpJson = (input) => ({
78
78
  }), Stream.interruptWhen(Effect.sleep(remaining).pipe(Effect.andThen(Effect.fail(timeout("read", "Timed out waiting for the response to complete", http))))))),
79
79
  http,
80
80
  body: prepared.framing.body,
81
+ raw: prepared.framing.raw,
81
82
  };
82
83
  }),
83
84
  });
@@ -11,6 +11,7 @@ export interface TransportExecution<Frame> {
11
11
  readonly frames: Stream.Stream<Frame, AIError>;
12
12
  readonly http?: HttpContext;
13
13
  body?(frame: Frame): string | undefined;
14
+ raw?(frame: Frame): unknown;
14
15
  /** Optional successful-consumption acknowledgement. HTTP leaves this absent. */
15
16
  readonly complete?: Effect.Effect<void>;
16
17
  }
@@ -15,6 +15,12 @@ declare const Usage_base: Schema.Class<Usage, Schema.Struct<{
15
15
  readonly cacheWriteInputTokens: Schema.optional<Schema.Number>;
16
16
  readonly reasoningTokens: Schema.optional<Schema.Number>;
17
17
  readonly totalTokens: Schema.optional<Schema.Number>;
18
+ /**
19
+ * USD the endpoint says it charged for this request, as OpenRouter, LiteLLM and OpenCode Zen report it in
20
+ * `usage.cost`. `0` is authoritative: the request was free or a subscription covered it. Absent, callers price the
21
+ * tokens themselves.
22
+ */
23
+ readonly cost: Schema.optional<Schema.Number>;
18
24
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
19
25
  }>, {}>;
20
26
  /**
@@ -97,6 +103,13 @@ export declare const MediaUsage: Schema.Union<readonly [Schema.Struct<{
97
103
  readonly seconds: Schema.Number;
98
104
  }>]>;
99
105
  export type MediaUsage = Schema.Schema.Type<typeof MediaUsage>;
106
+ /** Token usage from a provider's counts. A usage object without any count is no usage, so it returns undefined. */
107
+ export declare const tokenUsage: (counts: {
108
+ readonly input?: number;
109
+ readonly output?: number;
110
+ readonly total?: number;
111
+ readonly details?: Record<string, unknown>;
112
+ }) => MediaUsage | undefined;
100
113
  declare const CompactionResponse_base: Schema.Class<CompactionResponse, Schema.Struct<{
101
114
  readonly replacement: Schema.$Array<typeof Message>;
102
115
  readonly usage: Schema.optional<typeof Usage>;
@@ -404,6 +417,12 @@ export declare const ProviderErrorEvent: Schema.Struct<{
404
417
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
405
418
  }>;
406
419
  export type ProviderErrorEvent = Schema.Schema.Type<typeof ProviderErrorEvent>;
420
+ /** One provider frame as received, emitted before the events parsed from it when the request sets `includeRaw`. */
421
+ export declare const RawEvent: Schema.Struct<{
422
+ readonly type: Schema.tag<"raw">;
423
+ readonly data: Schema.Unknown;
424
+ }>;
425
+ export type RawEvent = Schema.Schema.Type<typeof RawEvent>;
407
426
  declare const llmEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.refine<{
408
427
  readonly type: "compaction";
409
428
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -637,6 +656,9 @@ declare const llmEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.refi
637
656
  readonly message: Schema.String;
638
657
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
639
658
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
659
+ }>, Schema.Struct<{
660
+ readonly type: Schema.tag<"raw">;
661
+ readonly data: Schema.Unknown;
640
662
  }>]>;
641
663
  type WithID<Event extends {
642
664
  readonly id: unknown;
@@ -886,8 +908,11 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
886
908
  readonly message: Schema.String;
887
909
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
888
910
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
911
+ }>, Schema.Struct<{
912
+ readonly type: Schema.tag<"raw">;
913
+ readonly data: Schema.Unknown;
889
914
  }>]> & {
890
- readonly discriminants: readonly ["compaction", "step-start", "text-start", "text-delta", "text-end", "reasoning-start", "reasoning-delta", "reasoning-end", "tool-input-start", "tool-input-delta", "tool-input-end", "tool-input-error", "tool-call", "tool-result", "tool-error", "media", "step-finish", "finish", "provider-error"];
915
+ readonly discriminants: readonly ["compaction", "step-start", "text-start", "text-delta", "text-end", "reasoning-start", "reasoning-delta", "reasoning-end", "tool-input-start", "tool-input-delta", "tool-input-end", "tool-input-error", "tool-call", "tool-result", "tool-error", "media", "step-finish", "finish", "provider-error", "raw"];
891
916
  readonly cases: {
892
917
  compaction: Schema.refine<{
893
918
  readonly type: "compaction";
@@ -970,6 +995,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
970
995
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
971
996
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
972
997
  }>;
998
+ raw: Schema.Struct<{
999
+ readonly type: Schema.tag<"raw">;
1000
+ readonly data: Schema.Unknown;
1001
+ }>;
973
1002
  "reasoning-delta": Schema.Struct<{
974
1003
  readonly type: Schema.tag<"reasoning-delta">;
975
1004
  readonly id: Schema.String;
@@ -1145,6 +1174,9 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
1145
1174
  readonly isAnyOf: <const Keys>(keys: readonly Keys[]) => (value: {
1146
1175
  readonly type: "step-start";
1147
1176
  readonly index: number;
1177
+ } | {
1178
+ readonly type: "raw";
1179
+ readonly data: unknown;
1148
1180
  } | {
1149
1181
  readonly type: "text-start";
1150
1182
  readonly id: string;
@@ -1362,6 +1394,11 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
1362
1394
  readonly index: number;
1363
1395
  }, {
1364
1396
  readonly type: Keys;
1397
+ }> | Extract<{
1398
+ readonly type: "raw";
1399
+ readonly data: unknown;
1400
+ }, {
1401
+ readonly type: Keys;
1365
1402
  }> | Extract<{
1366
1403
  readonly type: "text-start";
1367
1404
  readonly id: string;
@@ -1667,6 +1704,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
1667
1704
  };
1668
1705
  } | undefined;
1669
1706
  };
1707
+ raw: (u: unknown) => u is {
1708
+ readonly type: "raw";
1709
+ readonly data: unknown;
1710
+ };
1670
1711
  "reasoning-delta": (u: unknown) => u is {
1671
1712
  readonly type: "reasoning-delta";
1672
1713
  readonly id: string;
@@ -2063,6 +2104,9 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2063
2104
  readonly message: Schema.String;
2064
2105
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
2065
2106
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
2107
+ }> | Schema.Struct<{
2108
+ readonly type: Schema.tag<"raw">;
2109
+ readonly data: Schema.Unknown;
2066
2110
  }> | (Schema.refine<{
2067
2111
  readonly type: "compaction";
2068
2112
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -2092,6 +2136,9 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2092
2136
  }) as M["Type"]["type"]]: (value: M["Type"]) => any; }>(value: {
2093
2137
  readonly type: "step-start";
2094
2138
  readonly index: number;
2139
+ } | {
2140
+ readonly type: "raw";
2141
+ readonly data: unknown;
2095
2142
  } | {
2096
2143
  readonly type: "text-start";
2097
2144
  readonly id: string;
@@ -2512,6 +2559,9 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2512
2559
  readonly message: Schema.String;
2513
2560
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
2514
2561
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
2562
+ }> | Schema.Struct<{
2563
+ readonly type: Schema.tag<"raw">;
2564
+ readonly data: Schema.Unknown;
2515
2565
  }> | (Schema.refine<{
2516
2566
  readonly type: "compaction";
2517
2567
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -2541,6 +2591,9 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2541
2591
  }) as M["Type"]["type"]]: (value: M["Type"]) => any; }>(cases: Cases): (value: {
2542
2592
  readonly type: "step-start";
2543
2593
  readonly index: number;
2594
+ } | {
2595
+ readonly type: "raw";
2596
+ readonly data: unknown;
2544
2597
  } | {
2545
2598
  readonly type: "text-start";
2546
2599
  readonly id: string;
@@ -2963,6 +3016,9 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2963
3016
  readonly message: Schema.String;
2964
3017
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
2965
3018
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
3019
+ }> | Schema.Struct<{
3020
+ readonly type: Schema.tag<"raw">;
3021
+ readonly data: Schema.Unknown;
2966
3022
  }> | (Schema.refine<{
2967
3023
  readonly type: "compaction";
2968
3024
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -2989,9 +3045,12 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
2989
3045
  readonly text: string | null;
2990
3046
  readonly encrypted?: never;
2991
3047
  })) => CompactionPart;
2992
- }) as M["Type"]["type"]]+?: (value: M["Type"]) => any; } & { [K in Exclude<keyof Cases, "compaction" | "finish" | "media" | "provider-error" | "reasoning-delta" | "reasoning-end" | "reasoning-start" | "step-finish" | "step-start" | "text-delta" | "text-end" | "text-start" | "tool-call" | "tool-error" | "tool-input-delta" | "tool-input-end" | "tool-input-error" | "tool-input-start" | "tool-result">]: never; }, OrElse extends (value: Exclude<{
3048
+ }) as M["Type"]["type"]]+?: (value: M["Type"]) => any; } & { [K in Exclude<keyof Cases, "compaction" | "finish" | "media" | "provider-error" | "raw" | "reasoning-delta" | "reasoning-end" | "reasoning-start" | "step-finish" | "step-start" | "text-delta" | "text-end" | "text-start" | "tool-call" | "tool-error" | "tool-input-delta" | "tool-input-end" | "tool-input-error" | "tool-input-start" | "tool-result">]: never; }, OrElse extends (value: Exclude<{
2993
3049
  readonly type: "step-start";
2994
3050
  readonly index: number;
3051
+ } | {
3052
+ readonly type: "raw";
3053
+ readonly data: unknown;
2995
3054
  } | {
2996
3055
  readonly type: "text-start";
2997
3056
  readonly id: string;
@@ -3207,6 +3266,9 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
3207
3266
  })), { readonly [K in "type"]: keyof Cases; }>) => any>(value: {
3208
3267
  readonly type: "step-start";
3209
3268
  readonly index: number;
3269
+ } | {
3270
+ readonly type: "raw";
3271
+ readonly data: unknown;
3210
3272
  } | {
3211
3273
  readonly type: "text-start";
3212
3274
  readonly id: string;
@@ -3627,6 +3689,9 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
3627
3689
  readonly message: Schema.String;
3628
3690
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
3629
3691
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
3692
+ }> | Schema.Struct<{
3693
+ readonly type: Schema.tag<"raw">;
3694
+ readonly data: Schema.Unknown;
3630
3695
  }> | (Schema.refine<{
3631
3696
  readonly type: "compaction";
3632
3697
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -3653,9 +3718,12 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
3653
3718
  readonly text: string | null;
3654
3719
  readonly encrypted?: never;
3655
3720
  })) => CompactionPart;
3656
- }) as M["Type"]["type"]]+?: (value: M["Type"]) => any; } & { [K in Exclude<keyof Cases, "compaction" | "finish" | "media" | "provider-error" | "reasoning-delta" | "reasoning-end" | "reasoning-start" | "step-finish" | "step-start" | "text-delta" | "text-end" | "text-start" | "tool-call" | "tool-error" | "tool-input-delta" | "tool-input-end" | "tool-input-error" | "tool-input-start" | "tool-result">]: never; }, OrElse extends (value: Exclude<{
3721
+ }) as M["Type"]["type"]]+?: (value: M["Type"]) => any; } & { [K in Exclude<keyof Cases, "compaction" | "finish" | "media" | "provider-error" | "raw" | "reasoning-delta" | "reasoning-end" | "reasoning-start" | "step-finish" | "step-start" | "text-delta" | "text-end" | "text-start" | "tool-call" | "tool-error" | "tool-input-delta" | "tool-input-end" | "tool-input-error" | "tool-input-start" | "tool-result">]: never; }, OrElse extends (value: Exclude<{
3657
3722
  readonly type: "step-start";
3658
3723
  readonly index: number;
3724
+ } | {
3725
+ readonly type: "raw";
3726
+ readonly data: unknown;
3659
3727
  } | {
3660
3728
  readonly type: "text-start";
3661
3729
  readonly id: string;
@@ -3871,6 +3939,9 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
3871
3939
  })), { readonly [K in "type"]: keyof Cases; }>) => any>(cases: Cases, orElse: OrElse): (value: {
3872
3940
  readonly type: "step-start";
3873
3941
  readonly index: number;
3942
+ } | {
3943
+ readonly type: "raw";
3944
+ readonly data: unknown;
3874
3945
  } | {
3875
3946
  readonly type: "text-start";
3876
3947
  readonly id: string;
@@ -4352,6 +4423,13 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
4352
4423
  };
4353
4424
  } | undefined;
4354
4425
  };
4426
+ raw: (input: {
4427
+ readonly type?: "raw" | undefined;
4428
+ readonly data: unknown;
4429
+ }, options?: Schema.MakeOptions) => {
4430
+ readonly type: "raw";
4431
+ readonly data: unknown;
4432
+ };
4355
4433
  is: {
4356
4434
  compaction: (u: unknown) => u is {
4357
4435
  readonly type: "compaction";
@@ -4587,6 +4665,10 @@ export declare const LLMEvent: Schema.Union<readonly [Schema.refine<{
4587
4665
  };
4588
4666
  } | undefined;
4589
4667
  };
4668
+ raw: (u: unknown) => u is {
4669
+ readonly type: "raw";
4670
+ readonly data: unknown;
4671
+ };
4590
4672
  };
4591
4673
  };
4592
4674
  export type LLMEvent = Schema.Schema.Type<typeof llmEventTagged>;
@@ -4847,8 +4929,11 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
4847
4929
  readonly message: Schema.String;
4848
4930
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
4849
4931
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
4932
+ }>, Schema.Struct<{
4933
+ readonly type: Schema.tag<"raw">;
4934
+ readonly data: Schema.Unknown;
4850
4935
  }>]> & {
4851
- readonly discriminants: readonly ["compaction", "step-start", "text-start", "text-delta", "text-end", "reasoning-start", "reasoning-delta", "reasoning-end", "tool-input-start", "tool-input-delta", "tool-input-end", "tool-input-error", "tool-call", "tool-result", "tool-error", "media", "step-finish", "finish", "provider-error"];
4936
+ readonly discriminants: readonly ["compaction", "step-start", "text-start", "text-delta", "text-end", "reasoning-start", "reasoning-delta", "reasoning-end", "tool-input-start", "tool-input-delta", "tool-input-end", "tool-input-error", "tool-call", "tool-result", "tool-error", "media", "step-finish", "finish", "provider-error", "raw"];
4852
4937
  readonly cases: {
4853
4938
  compaction: Schema.refine<{
4854
4939
  readonly type: "compaction";
@@ -4931,6 +5016,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
4931
5016
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
4932
5017
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
4933
5018
  }>;
5019
+ raw: Schema.Struct<{
5020
+ readonly type: Schema.tag<"raw">;
5021
+ readonly data: Schema.Unknown;
5022
+ }>;
4934
5023
  "reasoning-delta": Schema.Struct<{
4935
5024
  readonly type: Schema.tag<"reasoning-delta">;
4936
5025
  readonly id: Schema.String;
@@ -5106,6 +5195,9 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
5106
5195
  readonly isAnyOf: <const Keys>(keys: readonly Keys[]) => (value: {
5107
5196
  readonly type: "step-start";
5108
5197
  readonly index: number;
5198
+ } | {
5199
+ readonly type: "raw";
5200
+ readonly data: unknown;
5109
5201
  } | {
5110
5202
  readonly type: "text-start";
5111
5203
  readonly id: string;
@@ -5323,6 +5415,11 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
5323
5415
  readonly index: number;
5324
5416
  }, {
5325
5417
  readonly type: Keys;
5418
+ }> | Extract<{
5419
+ readonly type: "raw";
5420
+ readonly data: unknown;
5421
+ }, {
5422
+ readonly type: Keys;
5326
5423
  }> | Extract<{
5327
5424
  readonly type: "text-start";
5328
5425
  readonly id: string;
@@ -5628,6 +5725,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
5628
5725
  };
5629
5726
  } | undefined;
5630
5727
  };
5728
+ raw: (u: unknown) => u is {
5729
+ readonly type: "raw";
5730
+ readonly data: unknown;
5731
+ };
5631
5732
  "reasoning-delta": (u: unknown) => u is {
5632
5733
  readonly type: "reasoning-delta";
5633
5734
  readonly id: string;
@@ -6024,6 +6125,9 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6024
6125
  readonly message: Schema.String;
6025
6126
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
6026
6127
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
6128
+ }> | Schema.Struct<{
6129
+ readonly type: Schema.tag<"raw">;
6130
+ readonly data: Schema.Unknown;
6027
6131
  }> | (Schema.refine<{
6028
6132
  readonly type: "compaction";
6029
6133
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -6053,6 +6157,9 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6053
6157
  }) as M["Type"]["type"]]: (value: M["Type"]) => any; }>(value: {
6054
6158
  readonly type: "step-start";
6055
6159
  readonly index: number;
6160
+ } | {
6161
+ readonly type: "raw";
6162
+ readonly data: unknown;
6056
6163
  } | {
6057
6164
  readonly type: "text-start";
6058
6165
  readonly id: string;
@@ -6473,6 +6580,9 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6473
6580
  readonly message: Schema.String;
6474
6581
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
6475
6582
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
6583
+ }> | Schema.Struct<{
6584
+ readonly type: Schema.tag<"raw">;
6585
+ readonly data: Schema.Unknown;
6476
6586
  }> | (Schema.refine<{
6477
6587
  readonly type: "compaction";
6478
6588
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -6502,6 +6612,9 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6502
6612
  }) as M["Type"]["type"]]: (value: M["Type"]) => any; }>(cases: Cases): (value: {
6503
6613
  readonly type: "step-start";
6504
6614
  readonly index: number;
6615
+ } | {
6616
+ readonly type: "raw";
6617
+ readonly data: unknown;
6505
6618
  } | {
6506
6619
  readonly type: "text-start";
6507
6620
  readonly id: string;
@@ -6924,6 +7037,9 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6924
7037
  readonly message: Schema.String;
6925
7038
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
6926
7039
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
7040
+ }> | Schema.Struct<{
7041
+ readonly type: Schema.tag<"raw">;
7042
+ readonly data: Schema.Unknown;
6927
7043
  }> | (Schema.refine<{
6928
7044
  readonly type: "compaction";
6929
7045
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -6950,9 +7066,12 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
6950
7066
  readonly text: string | null;
6951
7067
  readonly encrypted?: never;
6952
7068
  })) => CompactionPart;
6953
- }) as M["Type"]["type"]]+?: (value: M["Type"]) => any; } & { [K in Exclude<keyof Cases, "compaction" | "finish" | "media" | "provider-error" | "reasoning-delta" | "reasoning-end" | "reasoning-start" | "step-finish" | "step-start" | "text-delta" | "text-end" | "text-start" | "tool-call" | "tool-error" | "tool-input-delta" | "tool-input-end" | "tool-input-error" | "tool-input-start" | "tool-result">]: never; }, OrElse extends (value: Exclude<{
7069
+ }) as M["Type"]["type"]]+?: (value: M["Type"]) => any; } & { [K in Exclude<keyof Cases, "compaction" | "finish" | "media" | "provider-error" | "raw" | "reasoning-delta" | "reasoning-end" | "reasoning-start" | "step-finish" | "step-start" | "text-delta" | "text-end" | "text-start" | "tool-call" | "tool-error" | "tool-input-delta" | "tool-input-end" | "tool-input-error" | "tool-input-start" | "tool-result">]: never; }, OrElse extends (value: Exclude<{
6954
7070
  readonly type: "step-start";
6955
7071
  readonly index: number;
7072
+ } | {
7073
+ readonly type: "raw";
7074
+ readonly data: unknown;
6956
7075
  } | {
6957
7076
  readonly type: "text-start";
6958
7077
  readonly id: string;
@@ -7168,6 +7287,9 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
7168
7287
  })), { readonly [K in "type"]: keyof Cases; }>) => any>(value: {
7169
7288
  readonly type: "step-start";
7170
7289
  readonly index: number;
7290
+ } | {
7291
+ readonly type: "raw";
7292
+ readonly data: unknown;
7171
7293
  } | {
7172
7294
  readonly type: "text-start";
7173
7295
  readonly id: string;
@@ -7588,6 +7710,9 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
7588
7710
  readonly message: Schema.String;
7589
7711
  readonly classification: Schema.optional<Schema.Literals<readonly ["context-overflow", "payload-too-large"]>>;
7590
7712
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
7713
+ }> | Schema.Struct<{
7714
+ readonly type: Schema.tag<"raw">;
7715
+ readonly data: Schema.Unknown;
7591
7716
  }> | (Schema.refine<{
7592
7717
  readonly type: "compaction";
7593
7718
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -7614,9 +7739,12 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
7614
7739
  readonly text: string | null;
7615
7740
  readonly encrypted?: never;
7616
7741
  })) => CompactionPart;
7617
- }) as M["Type"]["type"]]+?: (value: M["Type"]) => any; } & { [K in Exclude<keyof Cases, "compaction" | "finish" | "media" | "provider-error" | "reasoning-delta" | "reasoning-end" | "reasoning-start" | "step-finish" | "step-start" | "text-delta" | "text-end" | "text-start" | "tool-call" | "tool-error" | "tool-input-delta" | "tool-input-end" | "tool-input-error" | "tool-input-start" | "tool-result">]: never; }, OrElse extends (value: Exclude<{
7742
+ }) as M["Type"]["type"]]+?: (value: M["Type"]) => any; } & { [K in Exclude<keyof Cases, "compaction" | "finish" | "media" | "provider-error" | "raw" | "reasoning-delta" | "reasoning-end" | "reasoning-start" | "step-finish" | "step-start" | "text-delta" | "text-end" | "text-start" | "tool-call" | "tool-error" | "tool-input-delta" | "tool-input-end" | "tool-input-error" | "tool-input-start" | "tool-result">]: never; }, OrElse extends (value: Exclude<{
7618
7743
  readonly type: "step-start";
7619
7744
  readonly index: number;
7745
+ } | {
7746
+ readonly type: "raw";
7747
+ readonly data: unknown;
7620
7748
  } | {
7621
7749
  readonly type: "text-start";
7622
7750
  readonly id: string;
@@ -7832,6 +7960,9 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
7832
7960
  })), { readonly [K in "type"]: keyof Cases; }>) => any>(cases: Cases, orElse: OrElse): (value: {
7833
7961
  readonly type: "step-start";
7834
7962
  readonly index: number;
7963
+ } | {
7964
+ readonly type: "raw";
7965
+ readonly data: unknown;
7835
7966
  } | {
7836
7967
  readonly type: "text-start";
7837
7968
  readonly id: string;
@@ -8313,6 +8444,13 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
8313
8444
  };
8314
8445
  } | undefined;
8315
8446
  };
8447
+ raw: (input: {
8448
+ readonly type?: "raw" | undefined;
8449
+ readonly data: unknown;
8450
+ }, options?: Schema.MakeOptions) => {
8451
+ readonly type: "raw";
8452
+ readonly data: unknown;
8453
+ };
8316
8454
  is: {
8317
8455
  compaction: (u: unknown) => u is {
8318
8456
  readonly type: "compaction";
@@ -8548,6 +8686,10 @@ declare const LLMResponse_base: Schema.Class<LLMResponse, Schema.Struct<{
8548
8686
  };
8549
8687
  } | undefined;
8550
8688
  };
8689
+ raw: (u: unknown) => u is {
8690
+ readonly type: "raw";
8691
+ readonly data: unknown;
8692
+ };
8551
8693
  };
8552
8694
  }>;
8553
8695
  readonly usage: Schema.optional<typeof Usage>;
@@ -61,6 +61,12 @@ export class Usage extends Schema.Class("AI.Usage")({
61
61
  cacheWriteInputTokens: Schema.optional(Schema.Number),
62
62
  reasoningTokens: Schema.optional(Schema.Number),
63
63
  totalTokens: Schema.optional(Schema.Number),
64
+ /**
65
+ * USD the endpoint says it charged for this request, as OpenRouter, LiteLLM and OpenCode Zen report it in
66
+ * `usage.cost`. `0` is authoritative: the request was free or a subscription covered it. Absent, callers price the
67
+ * tokens themselves.
68
+ */
69
+ cost: Schema.optional(Schema.Number),
64
70
  providerMetadata: Schema.optional(ProviderMetadata),
65
71
  }) {
66
72
  /**
@@ -95,6 +101,10 @@ export const MediaUsage = Schema.Union([
95
101
  ])
96
102
  .pipe(Schema.toTaggedUnion("type"))
97
103
  .annotate({ identifier: "AI.MediaUsage" });
104
+ /** Token usage from a provider's counts. A usage object without any count is no usage, so it returns undefined. */
105
+ export const tokenUsage = (counts) => counts.input === undefined && counts.output === undefined && counts.total === undefined
106
+ ? undefined
107
+ : { type: "tokens", ...counts };
98
108
  /** A replacement context window, not an assistant message to append to prior history. */
99
109
  export class CompactionResponse extends Schema.Class("LLM.CompactionResponse")({
100
110
  replacement: Schema.Array(Message),
@@ -241,6 +251,11 @@ export const ProviderErrorEvent = Schema.Struct({
241
251
  classification: Schema.optional(ProviderFailureClassification),
242
252
  providerMetadata: Schema.optional(ProviderMetadata),
243
253
  }).annotate({ identifier: "LLM.Event.ProviderError" });
254
+ /** One provider frame as received, emitted before the events parsed from it when the request sets `includeRaw`. */
255
+ export const RawEvent = Schema.Struct({
256
+ type: Schema.tag("raw"),
257
+ data: Schema.Unknown,
258
+ }).annotate({ identifier: "LLM.Event.Raw" });
244
259
  const llmEventTagged = Schema.Union([
245
260
  CompactionPart,
246
261
  StepStart,
@@ -261,6 +276,7 @@ const llmEventTagged = Schema.Union([
261
276
  StepFinish,
262
277
  Finish,
263
278
  ProviderErrorEvent,
279
+ RawEvent,
264
280
  ]).pipe(Schema.toTaggedUnion("type"));
265
281
  const contentBlockID = (value) => ContentBlockID.make(value);
266
282
  const toolCallID = (value) => ToolCallID.make(value);
@@ -299,6 +315,7 @@ export const LLMEvent = Object.assign(llmEventTagged, {
299
315
  usage: input.usage === undefined ? undefined : Usage.from(input.usage),
300
316
  }),
301
317
  providerError: ProviderErrorEvent.make,
318
+ raw: RawEvent.make,
302
319
  is: {
303
320
  compaction: llmEventTagged.guards.compaction,
304
321
  stepStart: llmEventTagged.guards["step-start"],
@@ -319,6 +336,7 @@ export const LLMEvent = Object.assign(llmEventTagged, {
319
336
  stepFinish: llmEventTagged.guards["step-finish"],
320
337
  finish: llmEventTagged.guards.finish,
321
338
  providerError: llmEventTagged.guards["provider-error"],
339
+ raw: llmEventTagged.guards.raw,
322
340
  },
323
341
  });
324
342
  /** Joins deltas per fragment, letting an authoritative end value replace that fragment's accumulated deltas. */
@@ -503,6 +521,8 @@ const reduceToolCall = (state, event) => {
503
521
  return { ...appendContent(state, toolCallContent(event)), toolInputs };
504
522
  };
505
523
  const reduceResponseState = (state, event) => {
524
+ if (event.type === "raw")
525
+ return state;
506
526
  const next = appendEvent(state, event);
507
527
  switch (event.type) {
508
528
  case "compaction":
@@ -691,10 +691,12 @@ declare const requestSchema: Schema.Struct<{
691
691
  readonly messages: Schema.optional<Schema.Union<readonly [Schema.Literal<"latest-user-message">, Schema.Literal<"latest-assistant">, Schema.Struct<{
692
692
  readonly tail: Schema.Natural;
693
693
  }>]>>;
694
- readonly ttlSeconds: Schema.optional<Schema.Number>;
694
+ readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
695
695
  }>]>>;
696
696
  readonly promptCacheKey: Schema.optional<Schema.String>;
697
697
  readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
698
+ /** Emit a `raw` event with each provider frame before the events parsed from it. */
699
+ readonly includeRaw: Schema.optional<Schema.Boolean>;
698
700
  }>;
699
701
  declare const LLMRequest_base: Schema.Class<LLMRequest<LanguageModel<{
700
702
  readonly [x: string]: unknown;
@@ -728,10 +730,12 @@ declare const LLMRequest_base: Schema.Class<LLMRequest<LanguageModel<{
728
730
  readonly messages: Schema.optional<Schema.Union<readonly [Schema.Literal<"latest-user-message">, Schema.Literal<"latest-assistant">, Schema.Struct<{
729
731
  readonly tail: Schema.Natural;
730
732
  }>]>>;
731
- readonly ttlSeconds: Schema.optional<Schema.Number>;
733
+ readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
732
734
  }>]>>;
733
735
  readonly promptCacheKey: Schema.optional<Schema.String>;
734
736
  readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
737
+ /** Emit a `raw` event with each provider frame before the events parsed from it. */
738
+ readonly includeRaw: Schema.optional<Schema.Boolean>;
735
739
  }>, {}>;
736
740
  export declare class LLMRequest<Model extends LanguageModel = LanguageModel> extends LLMRequest_base {
737
741
  readonly model: Model;