@opencode/ai 2.1.3 → 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 (288) 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 +13 -22
  22. package/dist/image-client.js +0 -1
  23. package/dist/image.d.ts +154 -324
  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 +32 -12
  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 +62 -27
  38. package/dist/protocols/alibaba-responses.d.ts +41 -38
  39. package/dist/protocols/anthropic-messages.d.ts +196 -94
  40. package/dist/protocols/anthropic-messages.js +47 -16
  41. package/dist/protocols/bedrock-converse.d.ts +140 -47
  42. package/dist/protocols/bedrock-converse.js +114 -18
  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 +32 -50
  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/cohere-chat.d.ts +7 -8
  52. package/dist/protocols/deepgram-speech.d.ts +32 -50
  53. package/dist/protocols/elevenlabs-speech.d.ts +32 -50
  54. package/dist/protocols/fal-images.d.ts +10 -1
  55. package/dist/protocols/fal-images.js +16 -25
  56. package/dist/protocols/fal-video.js +1 -1
  57. package/dist/protocols/gemini.d.ts +37 -34
  58. package/dist/protocols/gemini.js +13 -8
  59. package/dist/protocols/google-images.d.ts +2 -2
  60. package/dist/protocols/google-images.js +8 -37
  61. package/dist/protocols/google-interactions.d.ts +18 -14
  62. package/dist/protocols/google-interactions.js +14 -7
  63. package/dist/protocols/google-speech.d.ts +32 -50
  64. package/dist/protocols/google-speech.js +0 -1
  65. package/dist/protocols/google-transcription.d.ts +32 -50
  66. package/dist/protocols/google-transcription.js +0 -1
  67. package/dist/protocols/google-video.d.ts +1 -1
  68. package/dist/protocols/google-video.js +2 -7
  69. package/dist/protocols/index.d.ts +3 -0
  70. package/dist/protocols/index.js +3 -0
  71. package/dist/protocols/meta-images.d.ts +7 -1
  72. package/dist/protocols/meta-images.js +10 -8
  73. package/dist/protocols/meta-messages.d.ts +73 -38
  74. package/dist/protocols/meta-messages.js +14 -1
  75. package/dist/protocols/meta-responses.d.ts +84 -78
  76. package/dist/protocols/meta-responses.js +29 -1
  77. package/dist/protocols/mistral-chat.d.ts +81 -78
  78. package/dist/protocols/mistral-chat.js +2 -1
  79. package/dist/protocols/open-responses-channel.js +47 -46
  80. package/dist/protocols/open-responses-continuation.d.ts +8 -2
  81. package/dist/protocols/open-responses-continuation.js +3 -1
  82. package/dist/protocols/open-responses.d.ts +426 -396
  83. package/dist/protocols/open-responses.js +16 -25
  84. package/dist/protocols/openai-chat.d.ts +764 -52
  85. package/dist/protocols/openai-chat.js +38 -25
  86. package/dist/protocols/openai-compatible-chat.d.ts +35 -15
  87. package/dist/protocols/openai-compatible-responses.d.ts +44 -42
  88. package/dist/protocols/openai-decisions.d.ts +22 -0
  89. package/dist/protocols/openai-decisions.js +128 -0
  90. package/dist/protocols/openai-images.d.ts +53 -56
  91. package/dist/protocols/openai-images.js +100 -34
  92. package/dist/protocols/openai-responses.d.ts +322 -264
  93. package/dist/protocols/openai-responses.js +33 -3
  94. package/dist/protocols/openai-speech.d.ts +32 -50
  95. package/dist/protocols/openai-speech.js +15 -5
  96. package/dist/protocols/openai-transcription.d.ts +32 -50
  97. package/dist/protocols/openai-transcription.js +15 -11
  98. package/dist/protocols/replicate-images.js +1 -1
  99. package/dist/protocols/runway-video.d.ts +1 -1
  100. package/dist/protocols/runway-video.js +1 -1
  101. package/dist/protocols/shared.d.ts +9 -1
  102. package/dist/protocols/shared.js +13 -2
  103. package/dist/protocols/stability-images.d.ts +5 -0
  104. package/dist/protocols/stability-images.js +4 -9
  105. package/dist/protocols/system-one.d.ts +101 -0
  106. package/dist/protocols/system-one.js +230 -0
  107. package/dist/protocols/utils/bedrock-cache.d.ts +2 -2
  108. package/dist/protocols/utils/bedrock-cache.js +7 -6
  109. package/dist/protocols/utils/cache.d.ts +14 -3
  110. package/dist/protocols/utils/cache.js +11 -4
  111. package/dist/protocols/utils/gemini-generate-content.d.ts +3 -3
  112. package/dist/protocols/utils/gemini-generate-content.js +10 -16
  113. package/dist/protocols/utils/gemini-json-schema.d.ts +5 -0
  114. package/dist/protocols/utils/gemini-json-schema.js +3 -3
  115. package/dist/protocols/utils/image-sizing.d.ts +31 -0
  116. package/dist/protocols/utils/image-sizing.js +73 -0
  117. package/dist/protocols/utils/media-input.d.ts +4 -5
  118. package/dist/protocols/utils/media-input.js +8 -5
  119. package/dist/protocols/utils/partial-json-options.d.ts +0 -1
  120. package/dist/protocols/utils/partial-json-options.js +0 -1
  121. package/dist/protocols/utils/speech-stream.d.ts +0 -1
  122. package/dist/protocols/utils/speech-stream.js +0 -1
  123. package/dist/protocols/utils/tool-schema.js +15 -5
  124. package/dist/protocols/utils/tool-stream.d.ts +10 -1
  125. package/dist/protocols/venice-chat.d.ts +71 -53
  126. package/dist/protocols/venice-chat.js +7 -6
  127. package/dist/protocols/xai-images.d.ts +1 -2
  128. package/dist/protocols/xai-images.js +9 -2
  129. package/dist/protocols/xai-responses.d.ts +88 -78
  130. package/dist/protocols/xai-responses.js +28 -2
  131. package/dist/protocols/xai-video.d.ts +1 -1
  132. package/dist/protocols/xai-video.js +11 -8
  133. package/dist/protocols/zai-chat.d.ts +54 -30
  134. package/dist/protocols/zai-chat.js +8 -3
  135. package/dist/protocols/zai-images.d.ts +3 -1
  136. package/dist/protocols/zai-images.js +12 -11
  137. package/dist/protocols/zai-messages.d.ts +72 -35
  138. package/dist/protocols/zai-messages.js +3 -2
  139. package/dist/provider-error.js +24 -7
  140. package/dist/providers/alibaba/images.d.ts +2 -0
  141. package/dist/providers/alibaba/images.js +1 -0
  142. package/dist/providers/alibaba.d.ts +146 -85
  143. package/dist/providers/alibaba.js +16 -8
  144. package/dist/providers/amazon-bedrock-mantle.d.ts +277 -218
  145. package/dist/providers/amazon-bedrock.d.ts +48 -28
  146. package/dist/providers/amazon-bedrock.js +11 -11
  147. package/dist/providers/anthropic-compatible.d.ts +64 -29
  148. package/dist/providers/anthropic.d.ts +64 -29
  149. package/dist/providers/azure/images.d.ts +2 -0
  150. package/dist/providers/azure/images.js +1 -0
  151. package/dist/providers/azure.d.ts +156 -115
  152. package/dist/providers/azure.js +19 -1
  153. package/dist/providers/baseten/decisions.d.ts +2 -0
  154. package/dist/providers/baseten/decisions.js +1 -0
  155. package/dist/providers/baseten.d.ts +75 -25
  156. package/dist/providers/baseten.js +41 -8
  157. package/dist/providers/cerebras.d.ts +66 -24
  158. package/dist/providers/cloudflare-ai-gateway/decisions.d.ts +2 -0
  159. package/dist/providers/cloudflare-ai-gateway/decisions.js +1 -0
  160. package/dist/providers/cloudflare-ai-gateway.d.ts +409 -272
  161. package/dist/providers/cloudflare-ai-gateway.js +33 -6
  162. package/dist/providers/cloudflare-workers-ai/decisions.d.ts +2 -0
  163. package/dist/providers/cloudflare-workers-ai/decisions.js +1 -0
  164. package/dist/providers/cloudflare-workers-ai/images.d.ts +2 -0
  165. package/dist/providers/cloudflare-workers-ai/images.js +1 -0
  166. package/dist/providers/cloudflare-workers-ai.d.ts +79 -25
  167. package/dist/providers/cloudflare-workers-ai.js +45 -9
  168. package/dist/providers/cohere.d.ts +117 -75
  169. package/dist/providers/deepinfra.d.ts +66 -24
  170. package/dist/providers/deepseek.d.ts +66 -24
  171. package/dist/providers/digitalocean/decisions.d.ts +2 -0
  172. package/dist/providers/digitalocean/decisions.js +1 -0
  173. package/dist/providers/digitalocean/images.d.ts +2 -0
  174. package/dist/providers/digitalocean/images.js +1 -0
  175. package/dist/providers/digitalocean.d.ts +108 -37
  176. package/dist/providers/digitalocean.js +39 -8
  177. package/dist/providers/fireworks.d.ts +66 -24
  178. package/dist/providers/google/images.d.ts +2 -0
  179. package/dist/providers/google/images.js +1 -0
  180. package/dist/providers/google-vertex/images.d.ts +2 -0
  181. package/dist/providers/google-vertex/images.js +1 -0
  182. package/dist/providers/google-vertex-chat.d.ts +33 -12
  183. package/dist/providers/google-vertex-messages.d.ts +64 -29
  184. package/dist/providers/google-vertex-mistral.d.ts +17 -17
  185. package/dist/providers/google-vertex-responses.d.ts +38 -35
  186. package/dist/providers/google-vertex.d.ts +20 -18
  187. package/dist/providers/google-vertex.js +32 -15
  188. package/dist/providers/google.d.ts +22 -21
  189. package/dist/providers/google.js +15 -8
  190. package/dist/providers/groq.d.ts +66 -28
  191. package/dist/providers/groq.js +0 -6
  192. package/dist/providers/meta.d.ts +144 -85
  193. package/dist/providers/minimax.d.ts +145 -86
  194. package/dist/providers/mistral.d.ts +28 -28
  195. package/dist/providers/moonshot.d.ts +277 -218
  196. package/dist/providers/open-responses-options.d.ts +0 -1
  197. package/dist/providers/open-responses-options.js +1 -1
  198. package/dist/providers/openai/images.d.ts +2 -0
  199. package/dist/providers/openai/images.js +1 -0
  200. package/dist/providers/openai-compatible/images.d.ts +2 -0
  201. package/dist/providers/openai-compatible/images.js +1 -0
  202. package/dist/providers/openai-compatible-responses.d.ts +38 -35
  203. package/dist/providers/openai-compatible.d.ts +36 -13
  204. package/dist/providers/openai-compatible.js +22 -10
  205. package/dist/providers/openai-options.d.ts +3 -2
  206. package/dist/providers/openai-options.js +0 -1
  207. package/dist/providers/openai.d.ts +146 -109
  208. package/dist/providers/openai.js +20 -4
  209. package/dist/providers/opencode/decisions.d.ts +2 -0
  210. package/dist/providers/opencode/decisions.js +1 -0
  211. package/dist/providers/opencode.d.ts +9 -10
  212. package/dist/providers/opencode.js +10 -8
  213. package/dist/providers/openrouter/decisions.d.ts +2 -0
  214. package/dist/providers/openrouter/decisions.js +1 -0
  215. package/dist/providers/openrouter/images.d.ts +2 -0
  216. package/dist/providers/openrouter/images.js +1 -0
  217. package/dist/providers/openrouter.d.ts +128 -47
  218. package/dist/providers/openrouter.js +38 -16
  219. package/dist/providers/togetherai.d.ts +66 -24
  220. package/dist/providers/typesafe-ai/decisions.d.ts +2 -0
  221. package/dist/providers/typesafe-ai/decisions.js +1 -0
  222. package/dist/providers/typesafe-ai.d.ts +9 -10
  223. package/dist/providers/typesafe-ai.js +10 -8
  224. package/dist/providers/venice.d.ts +214 -20
  225. package/dist/providers/vercel-ai-gateway/decisions.d.ts +2 -0
  226. package/dist/providers/vercel-ai-gateway/decisions.js +1 -0
  227. package/dist/providers/vercel-ai-gateway/images.d.ts +2 -0
  228. package/dist/providers/vercel-ai-gateway/images.js +1 -0
  229. package/dist/providers/vercel-ai-gateway.d.ts +10 -16
  230. package/dist/providers/vercel-ai-gateway.js +31 -85
  231. package/dist/providers/xai/images.d.ts +2 -0
  232. package/dist/providers/xai/images.js +1 -0
  233. package/dist/providers/xai.d.ts +40 -17
  234. package/dist/providers/xai.js +15 -8
  235. package/dist/providers/zai/images.d.ts +2 -0
  236. package/dist/providers/zai/images.js +1 -0
  237. package/dist/providers/zai-coding-plan.d.ts +224 -85
  238. package/dist/providers/zai.d.ts +110 -23
  239. package/dist/providers/zai.js +15 -8
  240. package/dist/route/auth-options.d.ts +0 -3
  241. package/dist/route/auth.d.ts +0 -2
  242. package/dist/route/auth.js +0 -2
  243. package/dist/route/client.d.ts +2 -4
  244. package/dist/route/client.js +29 -8
  245. package/dist/route/decision.d.ts +58 -0
  246. package/dist/route/decision.js +75 -0
  247. package/dist/route/executor-service.js +1 -1
  248. package/dist/route/executor.d.ts +1 -1
  249. package/dist/route/framing.d.ts +2 -0
  250. package/dist/route/index.d.ts +3 -0
  251. package/dist/route/index.js +3 -0
  252. package/dist/route/media-protocol.d.ts +1 -0
  253. package/dist/route/media-protocol.js +12 -8
  254. package/dist/route/media.d.ts +5 -1
  255. package/dist/route/media.js +6 -2
  256. package/dist/route/transport/http.js +1 -0
  257. package/dist/route/transport/index.d.ts +1 -0
  258. package/dist/schema/events.d.ts +148 -6
  259. package/dist/schema/events.js +20 -0
  260. package/dist/schema/messages.d.ts +6 -2
  261. package/dist/schema/messages.js +3 -0
  262. package/dist/schema/options.d.ts +5 -3
  263. package/dist/schema/options.js +8 -3
  264. package/dist/speech-client.d.ts +13 -22
  265. package/dist/speech-client.js +0 -1
  266. package/dist/speech.d.ts +148 -283
  267. package/dist/speech.js +2 -4
  268. package/dist/testing.d.ts +25 -24
  269. package/dist/testing.js +3 -21
  270. package/dist/transcription-client.d.ts +13 -22
  271. package/dist/transcription.d.ts +148 -283
  272. package/dist/transcription.js +1 -1
  273. package/dist/utils/media-type.js +22 -1
  274. package/dist/video-client.d.ts +13 -22
  275. package/dist/video-client.js +0 -1
  276. package/dist/video.d.ts +115 -250
  277. package/dist/video.js +3 -5
  278. package/package.json +516 -13
  279. package/dist/experimental/evaluation-client.d.ts +0 -21
  280. package/dist/experimental/evaluation-client.js +0 -64
  281. package/dist/experimental/evaluation.d.ts +0 -242
  282. package/dist/experimental/evaluation.js +0 -115
  283. package/dist/experimental/system-one.d.ts +0 -16
  284. package/dist/experimental/system-one.js +0 -135
  285. package/dist/promise.d.ts +0 -1021
  286. package/dist/promise.js +0 -101
  287. package/dist/provider.d.ts +0 -23
  288. package/dist/provider.js +0 -2
@@ -1,8 +1,8 @@
1
1
  import { Layer } from "effect";
2
2
  import { RequestExecutor } from "./route/executor.js";
3
3
  /** Every modality client over `executor`, which stays in the output so `asset.bytes()` and `Media.write` resolve. */
4
- export declare const layerWith: <E, R>(executor: Layer.Layer<RequestExecutor.Service, E, R>) => Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | import("./route/executor-service.js").RequestExecutorService | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, E, R>;
4
+ export declare const layerWith: <E, R>(executor: Layer.Layer<RequestExecutor.Service, E, R>) => Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | RequestExecutor.RequestExecutorService | import("./decision-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, E, R>;
5
5
  /** Every modality client plus the executor over `RequestExecutor.fetchLayer`: the one layer most programs need. */
6
- export declare const layer: Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | import("./route/executor-service.js").RequestExecutorService | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, never, never>;
6
+ export declare const layer: Layer.Layer<import("./image-client.js").ImageClientService | import("./route/client.js").LLMClientService | RequestExecutor.RequestExecutorService | import("./decision-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService, never, never>;
7
7
  export type Services = Layer.Success<typeof layer>;
8
8
  export * as AIClient from "./ai-client.js";
package/dist/ai-client.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Layer } from "effect";
2
+ import { DecisionClient } from "./decision-client.js";
2
3
  import { ImageClient } from "./image-client.js";
3
4
  import { LLMClient } from "./route/client.js";
4
5
  import { RequestExecutor } from "./route/executor.js";
@@ -6,7 +7,7 @@ import { SpeechClient } from "./speech-client.js";
6
7
  import { TranscriptionClient } from "./transcription-client.js";
7
8
  import { VideoClient } from "./video-client.js";
8
9
  /** Every modality client over `executor`, which stays in the output so `asset.bytes()` and `Media.write` resolve. */
9
- export const layerWith = (executor) => Layer.mergeAll(LLMClient.layer, ImageClient.layer, VideoClient.layer, SpeechClient.layer, TranscriptionClient.layer).pipe(Layer.provideMerge(executor));
10
+ export const layerWith = (executor) => Layer.mergeAll(LLMClient.layer, ImageClient.layer, VideoClient.layer, SpeechClient.layer, TranscriptionClient.layer, DecisionClient.layer).pipe(Layer.provideMerge(executor));
10
11
  /** Every modality client plus the executor over `RequestExecutor.fetchLayer`: the one layer most programs need. */
11
12
  export const layer = layerWith(RequestExecutor.fetchLayer);
12
13
  export * as AIClient from "./ai-client.js";
@@ -1,2 +1,6 @@
1
1
  import { LLMRequest } from "./schema/messages.js";
2
+ /** The requested cache lifetime, for routes that send it as a request-level option instead of on markers. */
3
+ export declare const requestTTL: (request: LLMRequest) => `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
2
4
  export declare const applyCachePolicy: (request: LLMRequest) => LLMRequest;
5
+ /** Whether the cache policy places inline markers, which then carry the requested lifetime. */
6
+ export declare const placesMarkers: (request: LLMRequest) => boolean;
@@ -24,14 +24,23 @@ const BREAKPOINT_CAP = 4;
24
24
  // - undefined → "auto" — caching is on by default.
25
25
  // - "auto" → tools + first/last system + final message boundary.
26
26
  // - "none" → no auto placement; manual `CacheHint`s still flow.
27
+ // - `{ ttl }` → "auto" with that lifetime.
27
28
  // - object form → exactly what the caller asked for.
28
29
  const resolve = (policy) => {
29
- if (policy === undefined || policy === "auto")
30
- return AUTO;
31
30
  if (policy === "none")
32
31
  return NONE;
33
- return policy;
32
+ if (typeof policy === "object" && !isAuto(policy))
33
+ return policy;
34
+ return AUTO;
34
35
  };
36
+ const isAuto = (policy) => policy === undefined ||
37
+ policy === "auto" ||
38
+ (typeof policy === "object" &&
39
+ policy.tools === undefined &&
40
+ policy.system === undefined &&
41
+ policy.messages === undefined);
42
+ /** The requested cache lifetime, for routes that send it as a request-level option instead of on markers. */
43
+ export const requestTTL = (request) => (typeof request.cache === "object" ? request.cache.ttl : undefined);
35
44
  // Protocols whose wire format ignores inline cache markers (OpenAI's implicit
36
45
  // prefix caching, Gemini's implicit + out-of-band CachedContent). Skip the
37
46
  // whole policy pass for these — emitting hints would be harmless but pointless.
@@ -65,7 +74,7 @@ const gatewayPolicy = (modelID) => {
65
74
  return QWEN;
66
75
  return NONE;
67
76
  };
68
- const makeHint = (ttlSeconds) => ttlSeconds !== undefined ? new CacheHint({ type: "ephemeral", ttlSeconds }) : new CacheHint({ type: "ephemeral" });
77
+ const makeHint = (ttl) => ttl !== undefined ? new CacheHint({ type: "ephemeral", ttl }) : new CacheHint({ type: "ephemeral" });
69
78
  const markLastTool = (tools, hint, budget) => {
70
79
  const target = tools.at(-1);
71
80
  if (target === undefined)
@@ -147,7 +156,7 @@ export const applyCachePolicy = (request) => {
147
156
  const policy = selectPolicy(request);
148
157
  if (!policy.tools && !policy.system && !policy.messages)
149
158
  return request;
150
- const hint = makeHint(policy.ttlSeconds);
159
+ const hint = makeHint(requestTTL(request));
151
160
  const budget = { remaining: Math.max(0, BREAKPOINT_CAP - countHints(request)) };
152
161
  const tools = policy.tools ? markLastTool(request.tools, hint, budget) : request.tools;
153
162
  const system = policy.system ? markSystemBoundaries(request.system, hint, budget) : request.system;
@@ -156,11 +165,16 @@ export const applyCachePolicy = (request) => {
156
165
  return request;
157
166
  return LLMRequest.update(request, { tools, system, messages });
158
167
  };
168
+ /** Whether the cache policy places inline markers, which then carry the requested lifetime. */
169
+ export const placesMarkers = (request) => {
170
+ const policy = selectPolicy(request);
171
+ return Boolean(policy.tools || policy.system || policy.messages);
172
+ };
159
173
  // A declared cache format overrides the route allowlist and its model-ID heuristics.
160
174
  const selectPolicy = (request) => {
161
175
  const format = request.model.compatibility?.cacheFormat;
162
176
  const route = request.model.route.id;
163
- const auto = request.cache === undefined || request.cache === "auto";
177
+ const auto = isAuto(request.cache);
164
178
  if (format === "alibaba")
165
179
  return auto ? QWEN : { ...resolve(request.cache), tools: false };
166
180
  if (format === "anthropic")
@@ -0,0 +1,21 @@
1
+ import { Context, Effect, Layer } from "effect";
2
+ import type { DecisionOptions, DecisionQuestions, DecisionRequestFor, DecisionResponseFor } from "./decision.js";
3
+ import { RequestExecutor } from "./route/executor.js";
4
+ import { AIError } from "./schema/index.js";
5
+ export type Execute = RequestExecutor.Interface["execute"];
6
+ export interface Interface {
7
+ readonly generate: <Options extends DecisionOptions, const Questions extends DecisionQuestions>(request: DecisionRequestFor<Options, Questions>) => Effect.Effect<DecisionResponseFor<Questions>, AIError>;
8
+ }
9
+ declare const Service_base: Context.ServiceClass<Service, "@opencode/AI/DecisionClient", Interface>;
10
+ export declare class Service extends Service_base {
11
+ }
12
+ export declare const generate: <Options extends DecisionOptions, const Questions extends DecisionQuestions>(request: DecisionRequestFor<Options, Questions>) => Effect.Effect<DecisionResponseFor<Questions>, AIError, Service>;
13
+ export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
14
+ export declare const fetchLayer: Layer.Layer<RequestExecutor.RequestExecutorService | Service, never, never>;
15
+ export declare const DecisionClient: {
16
+ readonly Service: typeof Service;
17
+ readonly layer: Layer.Layer<Service, never, RequestExecutor.RequestExecutorService>;
18
+ readonly fetchLayer: Layer.Layer<RequestExecutor.RequestExecutorService | Service, never, never>;
19
+ readonly generate: typeof generate;
20
+ };
21
+ export {};
@@ -0,0 +1,55 @@
1
+ import { Context, Effect, Layer } from "effect";
2
+ import { RequestExecutor } from "./route/executor.js";
3
+ import { AIError, InvalidProviderOutputError } from "./schema/index.js";
4
+ export class Service extends Context.Service()("@opencode/AI/DecisionClient") {
5
+ }
6
+ export const generate = (request) => Effect.flatMap(Service, (client) => client.generate(request));
7
+ export const layer = Layer.effect(Service, Effect.gen(function* () {
8
+ const executor = yield* RequestExecutor.Service;
9
+ return Service.of({
10
+ generate: Effect.fnUntraced(function* (request) {
11
+ const route = request.model.route;
12
+ const response = yield* route.generate(request, executor.execute);
13
+ if (answersMatch(request.questions, response.answers))
14
+ return response;
15
+ return yield* new AIError({
16
+ reason: new InvalidProviderOutputError({
17
+ route: route.id,
18
+ message: "Decision answers do not match the requested questions",
19
+ cause: response.answers,
20
+ }),
21
+ });
22
+ }),
23
+ });
24
+ }));
25
+ export const fetchLayer = layer.pipe(Layer.provideMerge(RequestExecutor.fetchLayer));
26
+ /** Host bugs (a missing or extra answer, an option that wasn't offered, a score off the scale) fail the whole call. */
27
+ const answersMatch = (questions, answers) => questions.length === answers.length &&
28
+ questions.every((question, index) => {
29
+ const answer = answers[index];
30
+ if (answer.name !== question.name)
31
+ return false;
32
+ if (answer.type === "error")
33
+ return true;
34
+ if (question.type === "predicate")
35
+ return answer.type === "predicate";
36
+ if (question.type === "choice") {
37
+ if (answer.type !== "choice")
38
+ return false;
39
+ const values = question.choices.map((choice) => choice.value);
40
+ return (values.includes(answer.choice) &&
41
+ sameMembers(values, answer.probabilities.map((item) => item.value)));
42
+ }
43
+ if (answer.type !== "score" || answer.score < 0 || answer.score > question.levels.length - 1)
44
+ return false;
45
+ return sameMembers(question.levels.map((_, level) => level), answer.probabilities.map((item) => item.value));
46
+ });
47
+ const sameMembers = (expected, received) => expected.length === received.length &&
48
+ new Set(received).size === received.length &&
49
+ received.every((item) => expected.includes(item));
50
+ export const DecisionClient = {
51
+ Service,
52
+ layer,
53
+ fetchLayer,
54
+ generate,
55
+ };
@@ -0,0 +1,472 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Service, type Execute } from "./decision-client.js";
3
+ import { Media } from "./media.js";
4
+ import { AIError, HttpOptions, ModelID, ProviderID, ProviderOptions, type OpenString } from "./schema/index.js";
5
+ export declare const DecisionTextPart: Schema.Struct<{
6
+ readonly type: Schema.Literal<"text">;
7
+ readonly text: Schema.String;
8
+ }>;
9
+ export declare const DecisionJsonPart: Schema.Struct<{
10
+ readonly type: Schema.Literal<"json">;
11
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
12
+ }>;
13
+ export declare const DecisionMediaPart: Schema.Struct<{
14
+ readonly type: Schema.Literal<"media">;
15
+ readonly media: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
16
+ readonly source: Schema.Union<readonly [Schema.Struct<{
17
+ readonly type: Schema.Literal<"bytes">;
18
+ readonly data: Schema.Uint8Array;
19
+ readonly mediaType: Schema.String;
20
+ }>, Schema.Struct<{
21
+ readonly type: Schema.Literal<"base64">;
22
+ readonly data: Schema.String;
23
+ readonly mediaType: Schema.String;
24
+ }>, Schema.Struct<{
25
+ readonly type: Schema.Literal<"url">;
26
+ readonly url: Schema.String;
27
+ readonly mediaType: Schema.optional<Schema.String>;
28
+ readonly expiresAt: Schema.optional<Schema.Number>;
29
+ }>, Schema.Struct<{
30
+ readonly type: Schema.Literal<"ref">;
31
+ readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
32
+ readonly id: Schema.String;
33
+ readonly mediaType: Schema.optional<Schema.String>;
34
+ }>]>;
35
+ readonly info: Schema.optional<Schema.Struct<{
36
+ readonly width: Schema.optional<Schema.Number>;
37
+ readonly height: Schema.optional<Schema.Number>;
38
+ readonly durationSeconds: Schema.optional<Schema.Number>;
39
+ readonly sampleRate: Schema.optional<Schema.Number>;
40
+ readonly channels: Schema.optional<Schema.Number>;
41
+ readonly encoding: Schema.optional<Schema.String>;
42
+ readonly format: Schema.optional<Schema.String>;
43
+ }>>;
44
+ readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
45
+ }>, never, never>;
46
+ readonly filename: Schema.optional<Schema.String>;
47
+ }>;
48
+ export declare const DecisionPart: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
49
+ readonly type: Schema.Literal<"text">;
50
+ readonly text: Schema.String;
51
+ }>, Schema.Struct<{
52
+ readonly type: Schema.Literal<"json">;
53
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
54
+ }>, Schema.Struct<{
55
+ readonly type: Schema.Literal<"media">;
56
+ readonly media: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
57
+ readonly source: Schema.Union<readonly [Schema.Struct<{
58
+ readonly type: Schema.Literal<"bytes">;
59
+ readonly data: Schema.Uint8Array;
60
+ readonly mediaType: Schema.String;
61
+ }>, Schema.Struct<{
62
+ readonly type: Schema.Literal<"base64">;
63
+ readonly data: Schema.String;
64
+ readonly mediaType: Schema.String;
65
+ }>, Schema.Struct<{
66
+ readonly type: Schema.Literal<"url">;
67
+ readonly url: Schema.String;
68
+ readonly mediaType: Schema.optional<Schema.String>;
69
+ readonly expiresAt: Schema.optional<Schema.Number>;
70
+ }>, Schema.Struct<{
71
+ readonly type: Schema.Literal<"ref">;
72
+ readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
73
+ readonly id: Schema.String;
74
+ readonly mediaType: Schema.optional<Schema.String>;
75
+ }>]>;
76
+ readonly info: Schema.optional<Schema.Struct<{
77
+ readonly width: Schema.optional<Schema.Number>;
78
+ readonly height: Schema.optional<Schema.Number>;
79
+ readonly durationSeconds: Schema.optional<Schema.Number>;
80
+ readonly sampleRate: Schema.optional<Schema.Number>;
81
+ readonly channels: Schema.optional<Schema.Number>;
82
+ readonly encoding: Schema.optional<Schema.String>;
83
+ readonly format: Schema.optional<Schema.String>;
84
+ }>>;
85
+ readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
86
+ }>, never, never>;
87
+ readonly filename: Schema.optional<Schema.String>;
88
+ }>]>;
89
+ export type DecisionPart = Schema.Schema.Type<typeof DecisionPart>;
90
+ /** A plain object is one `json` part. */
91
+ export type DecisionInput = typeof Schema.JsonObject.Type | ReadonlyArray<DecisionPart>;
92
+ /** Choice values are typed: `true` and `"true"` are different values. */
93
+ export declare const ChoiceValue: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
94
+ export type ChoiceValue = Schema.Schema.Type<typeof ChoiceValue>;
95
+ export declare const PredicateQuestion: Schema.Struct<{
96
+ readonly name: Schema.String;
97
+ readonly type: Schema.Literal<"predicate">;
98
+ readonly instructions: Schema.String;
99
+ }>;
100
+ export type PredicateQuestion = Schema.Schema.Type<typeof PredicateQuestion>;
101
+ export declare const ChoiceQuestion: Schema.Struct<{
102
+ readonly name: Schema.String;
103
+ readonly type: Schema.Literal<"choice">;
104
+ readonly instructions: Schema.String;
105
+ readonly choices: Schema.$Array<Schema.Struct<{
106
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
107
+ readonly description: Schema.optional<Schema.String>;
108
+ }>>;
109
+ }>;
110
+ export type ChoiceQuestion = Schema.Schema.Type<typeof ChoiceQuestion>;
111
+ export declare const ScoreQuestion: Schema.Struct<{
112
+ readonly name: Schema.String;
113
+ readonly type: Schema.Literal<"score">;
114
+ readonly instructions: Schema.String;
115
+ readonly levels: Schema.$Array<Schema.Struct<{
116
+ readonly label: Schema.String;
117
+ readonly description: Schema.optional<Schema.String>;
118
+ }>>;
119
+ }>;
120
+ export type ScoreQuestion = Schema.Schema.Type<typeof ScoreQuestion>;
121
+ export declare const DecisionQuestion: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
122
+ readonly name: Schema.String;
123
+ readonly type: Schema.Literal<"predicate">;
124
+ readonly instructions: Schema.String;
125
+ }>, Schema.Struct<{
126
+ readonly name: Schema.String;
127
+ readonly type: Schema.Literal<"choice">;
128
+ readonly instructions: Schema.String;
129
+ readonly choices: Schema.$Array<Schema.Struct<{
130
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
131
+ readonly description: Schema.optional<Schema.String>;
132
+ }>>;
133
+ }>, Schema.Struct<{
134
+ readonly name: Schema.String;
135
+ readonly type: Schema.Literal<"score">;
136
+ readonly instructions: Schema.String;
137
+ readonly levels: Schema.$Array<Schema.Struct<{
138
+ readonly label: Schema.String;
139
+ readonly description: Schema.optional<Schema.String>;
140
+ }>>;
141
+ }>]>;
142
+ export type DecisionQuestion = Schema.Schema.Type<typeof DecisionQuestion>;
143
+ export type DecisionQuestions = ReadonlyArray<DecisionQuestion>;
144
+ export declare const PredicateAnswer: Schema.Struct<{
145
+ readonly name: Schema.String;
146
+ readonly type: Schema.Literal<"predicate">;
147
+ readonly probability: Schema.Number;
148
+ }>;
149
+ export type PredicateAnswer = Schema.Schema.Type<typeof PredicateAnswer>;
150
+ export declare const ChoiceAnswer: Schema.Struct<{
151
+ readonly name: Schema.String;
152
+ readonly type: Schema.Literal<"choice">;
153
+ readonly choice: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
154
+ readonly probabilities: Schema.$Array<Schema.Struct<{
155
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
156
+ readonly probability: Schema.Number;
157
+ }>>;
158
+ readonly confidence: Schema.Number;
159
+ }>;
160
+ export type ChoiceAnswer = Schema.Schema.Type<typeof ChoiceAnswer>;
161
+ /** `score` is the probability-weighted level index; `probabilities` has one entry per level. */
162
+ export declare const ScoreAnswer: Schema.Struct<{
163
+ readonly name: Schema.String;
164
+ readonly type: Schema.Literal<"score">;
165
+ readonly score: Schema.Number;
166
+ readonly probabilities: Schema.$Array<Schema.Struct<{
167
+ readonly value: Schema.Int;
168
+ readonly label: Schema.String;
169
+ readonly probability: Schema.Number;
170
+ }>>;
171
+ readonly confidence: Schema.Number;
172
+ }>;
173
+ export type ScoreAnswer = Schema.Schema.Type<typeof ScoreAnswer>;
174
+ /** Why a question has no answer; hosts may report reasons beyond these. */
175
+ export type ErrorReason = OpenString<"refusal">;
176
+ export declare const ErrorReason: Schema.Codec<ErrorReason>;
177
+ /** This one question has no answer; the other answers still came back. */
178
+ export declare const ErrorAnswer: Schema.Struct<{
179
+ readonly name: Schema.String;
180
+ readonly type: Schema.Literal<"error">;
181
+ readonly reason: Schema.Codec<ErrorReason, ErrorReason, never, never>;
182
+ readonly message: Schema.optional<Schema.String>;
183
+ }>;
184
+ export type ErrorAnswer = Schema.Schema.Type<typeof ErrorAnswer>;
185
+ export declare const DecisionAnswer: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
186
+ readonly name: Schema.String;
187
+ readonly type: Schema.Literal<"predicate">;
188
+ readonly probability: Schema.Number;
189
+ }>, Schema.Struct<{
190
+ readonly name: Schema.String;
191
+ readonly type: Schema.Literal<"choice">;
192
+ readonly choice: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
193
+ readonly probabilities: Schema.$Array<Schema.Struct<{
194
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
195
+ readonly probability: Schema.Number;
196
+ }>>;
197
+ readonly confidence: Schema.Number;
198
+ }>, Schema.Struct<{
199
+ readonly name: Schema.String;
200
+ readonly type: Schema.Literal<"score">;
201
+ readonly score: Schema.Number;
202
+ readonly probabilities: Schema.$Array<Schema.Struct<{
203
+ readonly value: Schema.Int;
204
+ readonly label: Schema.String;
205
+ readonly probability: Schema.Number;
206
+ }>>;
207
+ readonly confidence: Schema.Number;
208
+ }>, Schema.Struct<{
209
+ readonly name: Schema.String;
210
+ readonly type: Schema.Literal<"error">;
211
+ readonly reason: Schema.Codec<ErrorReason, ErrorReason, never, never>;
212
+ readonly message: Schema.optional<Schema.String>;
213
+ }>]>;
214
+ export type DecisionAnswer = Schema.Schema.Type<typeof DecisionAnswer>;
215
+ type ChoiceValueOf<Question> = Question extends {
216
+ readonly choices: ReadonlyArray<{
217
+ readonly value: infer Value;
218
+ }>;
219
+ } ? Value : never;
220
+ export type AnswerFor<Question extends DecisionQuestion> = (Question extends {
221
+ readonly type: "predicate";
222
+ } ? PredicateAnswer & {
223
+ readonly name: Question["name"];
224
+ } : Question extends {
225
+ readonly type: "choice";
226
+ } ? {
227
+ readonly name: Question["name"];
228
+ readonly type: "choice";
229
+ readonly choice: ChoiceValueOf<Question>;
230
+ readonly probabilities: ReadonlyArray<{
231
+ readonly value: ChoiceValueOf<Question>;
232
+ readonly probability: number;
233
+ }>;
234
+ readonly confidence: number;
235
+ } : ScoreAnswer & {
236
+ readonly name: Question["name"];
237
+ }) | (ErrorAnswer & {
238
+ readonly name: Question["name"];
239
+ });
240
+ /** One answer per question, in question order. */
241
+ export type AnswersFor<Questions extends DecisionQuestions> = {
242
+ readonly [Index in keyof Questions]: AnswerFor<Questions[Index]>;
243
+ };
244
+ export type DecisionOptions = Record<string, unknown>;
245
+ /** What a decision model's route does; `DecisionRoute.make(...).model(...)` builds one from a protocol. */
246
+ export interface DecisionModelRoute<Options extends DecisionOptions = DecisionOptions> {
247
+ readonly id: string;
248
+ generate(request: DecisionRequestFor<Options>, execute: Execute): Effect.Effect<DecisionResponse, AIError>;
249
+ }
250
+ declare const DecisionModelCompatibility_base: Schema.Class<DecisionModelCompatibility, Schema.Struct<{
251
+ /**
252
+ * Where a System One host reads media, from models.dev `[api.systemone] compatibility.media_input`, named after
253
+ * where the media goes in the body: `assets` (TypeSafe's assets map, referenced from the state), `state` (items
254
+ * inside a state list) or `root` (one top-level list per kind: `images`, `audio`, `videos`).
255
+ */
256
+ readonly mediaInput: Schema.optional<Schema.Literals<readonly ["assets", "state", "root"]>>;
257
+ }>, {}>;
258
+ /** Host quirks a protocol adapts to, like `LanguageModelCompatibility` for language models. */
259
+ export declare class DecisionModelCompatibility extends DecisionModelCompatibility_base {
260
+ }
261
+ export declare namespace DecisionModelCompatibility {
262
+ type Input = DecisionModelCompatibility | ConstructorParameters<typeof DecisionModelCompatibility>[0];
263
+ const make: (input: Input) => DecisionModelCompatibility;
264
+ }
265
+ export declare class DecisionModel<Options extends DecisionOptions = DecisionOptions> {
266
+ protected readonly _Options: Options;
267
+ readonly id: ModelID;
268
+ readonly provider: ProviderID;
269
+ readonly route: DecisionModelRoute<Options>;
270
+ readonly http?: HttpOptions;
271
+ readonly compatibility?: DecisionModelCompatibility;
272
+ /** Defaults under each request's `providerOptions`, such as options a provider package reads from its settings. */
273
+ readonly providerOptions?: ProviderOptions;
274
+ constructor(input: DecisionModel.Input<Options>);
275
+ static make<Options extends DecisionOptions = DecisionOptions>(input: DecisionModel.MakeInput<Options>): DecisionModel<Options>;
276
+ }
277
+ export declare namespace DecisionModel {
278
+ interface Input<Options extends DecisionOptions = DecisionOptions> {
279
+ readonly id: ModelID;
280
+ readonly provider: ProviderID;
281
+ readonly route: DecisionModelRoute<Options>;
282
+ readonly http?: HttpOptions;
283
+ readonly compatibility?: DecisionModelCompatibility;
284
+ readonly providerOptions?: ProviderOptions;
285
+ }
286
+ interface MakeInput<Options extends DecisionOptions = DecisionOptions> extends Omit<Input<Options>, "id" | "provider"> {
287
+ readonly id: string | ModelID;
288
+ readonly provider: string | ProviderID;
289
+ }
290
+ }
291
+ export declare const DecisionModelSchema: Schema.declare<DecisionModel<DecisionOptions>, DecisionModel<DecisionOptions>>;
292
+ export type DecisionModelOptions<Model> = Model extends DecisionModel<infer Options> ? Options : never;
293
+ declare const DecisionRequest_base: Schema.Class<DecisionRequest, Schema.Struct<{
294
+ readonly model: Schema.declare<DecisionModel<DecisionOptions>, DecisionModel<DecisionOptions>>;
295
+ readonly input: Schema.$Array<Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
296
+ readonly type: Schema.Literal<"text">;
297
+ readonly text: Schema.String;
298
+ }>, Schema.Struct<{
299
+ readonly type: Schema.Literal<"json">;
300
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
301
+ }>, Schema.Struct<{
302
+ readonly type: Schema.Literal<"media">;
303
+ readonly media: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
304
+ readonly source: Schema.Union<readonly [Schema.Struct<{
305
+ readonly type: Schema.Literal<"bytes">;
306
+ readonly data: Schema.Uint8Array;
307
+ readonly mediaType: Schema.String;
308
+ }>, Schema.Struct<{
309
+ readonly type: Schema.Literal<"base64">;
310
+ readonly data: Schema.String;
311
+ readonly mediaType: Schema.String;
312
+ }>, Schema.Struct<{
313
+ readonly type: Schema.Literal<"url">;
314
+ readonly url: Schema.String;
315
+ readonly mediaType: Schema.optional<Schema.String>;
316
+ readonly expiresAt: Schema.optional<Schema.Number>;
317
+ }>, Schema.Struct<{
318
+ readonly type: Schema.Literal<"ref">;
319
+ readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
320
+ readonly id: Schema.String;
321
+ readonly mediaType: Schema.optional<Schema.String>;
322
+ }>]>;
323
+ readonly info: Schema.optional<Schema.Struct<{
324
+ readonly width: Schema.optional<Schema.Number>;
325
+ readonly height: Schema.optional<Schema.Number>;
326
+ readonly durationSeconds: Schema.optional<Schema.Number>;
327
+ readonly sampleRate: Schema.optional<Schema.Number>;
328
+ readonly channels: Schema.optional<Schema.Number>;
329
+ readonly encoding: Schema.optional<Schema.String>;
330
+ readonly format: Schema.optional<Schema.String>;
331
+ }>>;
332
+ readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
333
+ }>, never, never>;
334
+ readonly filename: Schema.optional<Schema.String>;
335
+ }>]>>;
336
+ readonly questions: Schema.refine<readonly ({
337
+ readonly name: string;
338
+ readonly type: "predicate";
339
+ readonly instructions: string;
340
+ } | {
341
+ readonly name: string;
342
+ readonly type: "choice";
343
+ readonly instructions: string;
344
+ readonly choices: readonly {
345
+ readonly value: string | boolean;
346
+ readonly description?: string | undefined;
347
+ }[];
348
+ } | {
349
+ readonly name: string;
350
+ readonly type: "score";
351
+ readonly instructions: string;
352
+ readonly levels: readonly {
353
+ readonly label: string;
354
+ readonly description?: string | undefined;
355
+ }[];
356
+ })[], Schema.refine<readonly ({
357
+ readonly name: string;
358
+ readonly type: "predicate";
359
+ readonly instructions: string;
360
+ } | {
361
+ readonly name: string;
362
+ readonly type: "choice";
363
+ readonly instructions: string;
364
+ readonly choices: readonly {
365
+ readonly value: string | boolean;
366
+ readonly description?: string | undefined;
367
+ }[];
368
+ } | {
369
+ readonly name: string;
370
+ readonly type: "score";
371
+ readonly instructions: string;
372
+ readonly levels: readonly {
373
+ readonly label: string;
374
+ readonly description?: string | undefined;
375
+ }[];
376
+ })[], Schema.$Array<Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
377
+ readonly name: Schema.String;
378
+ readonly type: Schema.Literal<"predicate">;
379
+ readonly instructions: Schema.String;
380
+ }>, Schema.Struct<{
381
+ readonly name: Schema.String;
382
+ readonly type: Schema.Literal<"choice">;
383
+ readonly instructions: Schema.String;
384
+ readonly choices: Schema.$Array<Schema.Struct<{
385
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
386
+ readonly description: Schema.optional<Schema.String>;
387
+ }>>;
388
+ }>, Schema.Struct<{
389
+ readonly name: Schema.String;
390
+ readonly type: Schema.Literal<"score">;
391
+ readonly instructions: Schema.String;
392
+ readonly levels: Schema.$Array<Schema.Struct<{
393
+ readonly label: Schema.String;
394
+ readonly description: Schema.optional<Schema.String>;
395
+ }>>;
396
+ }>]>>>>;
397
+ readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
398
+ readonly http: Schema.optional<typeof HttpOptions>;
399
+ }>, {}>;
400
+ export declare class DecisionRequest extends DecisionRequest_base {
401
+ protected readonly _DecisionRequest: void;
402
+ }
403
+ export type DecisionRequestFor<Options extends DecisionOptions = DecisionOptions, Questions extends DecisionQuestions = DecisionQuestions> = Omit<DecisionRequest, "model" | "questions" | "providerOptions"> & {
404
+ readonly model: DecisionModel<Options>;
405
+ readonly questions: Questions;
406
+ readonly providerOptions?: Options;
407
+ };
408
+ export type DecisionRequestInput<Model extends DecisionModel = DecisionModel, Questions extends DecisionQuestions = DecisionQuestions> = {
409
+ readonly model: Model;
410
+ readonly input: DecisionInput;
411
+ readonly questions: Questions;
412
+ readonly providerOptions?: NoInfer<DecisionModelOptions<Model>>;
413
+ readonly http?: HttpOptions.Input;
414
+ };
415
+ declare const DecisionUsage_base: Schema.Class<DecisionUsage, Schema.Struct<{
416
+ readonly inputTokens: Schema.optional<Schema.Number>;
417
+ readonly outputTokens: Schema.optional<Schema.Number>;
418
+ readonly totalTokens: Schema.optional<Schema.Number>;
419
+ /** USD the host says it charged for this request. */
420
+ readonly cost: Schema.optional<Schema.Number>;
421
+ }>, {}>;
422
+ /** What decision hosts report; their raw usage stays in the response's `providerMetadata`. */
423
+ export declare class DecisionUsage extends DecisionUsage_base {
424
+ }
425
+ declare const DecisionResponse_base: Schema.Class<DecisionResponse, Schema.Struct<{
426
+ readonly answers: Schema.$Array<Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
427
+ readonly name: Schema.String;
428
+ readonly type: Schema.Literal<"predicate">;
429
+ readonly probability: Schema.Number;
430
+ }>, Schema.Struct<{
431
+ readonly name: Schema.String;
432
+ readonly type: Schema.Literal<"choice">;
433
+ readonly choice: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
434
+ readonly probabilities: Schema.$Array<Schema.Struct<{
435
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
436
+ readonly probability: Schema.Number;
437
+ }>>;
438
+ readonly confidence: Schema.Number;
439
+ }>, Schema.Struct<{
440
+ readonly name: Schema.String;
441
+ readonly type: Schema.Literal<"score">;
442
+ readonly score: Schema.Number;
443
+ readonly probabilities: Schema.$Array<Schema.Struct<{
444
+ readonly value: Schema.Int;
445
+ readonly label: Schema.String;
446
+ readonly probability: Schema.Number;
447
+ }>>;
448
+ readonly confidence: Schema.Number;
449
+ }>, Schema.Struct<{
450
+ readonly name: Schema.String;
451
+ readonly type: Schema.Literal<"error">;
452
+ readonly reason: Schema.Codec<ErrorReason, ErrorReason, never, never>;
453
+ readonly message: Schema.optional<Schema.String>;
454
+ }>]>>;
455
+ readonly usage: Schema.optional<typeof DecisionUsage>;
456
+ readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
457
+ }>, {}>;
458
+ export declare class DecisionResponse extends DecisionResponse_base {
459
+ }
460
+ export type DecisionResponseFor<Questions extends DecisionQuestions> = Omit<DecisionResponse, "answers"> & {
461
+ readonly answers: AnswersFor<Questions>;
462
+ };
463
+ export declare function request<const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>): DecisionRequestFor<DecisionModelOptions<Model>, Questions>;
464
+ export declare function request(input: DecisionRequest): DecisionRequest;
465
+ export declare function request(input: DecisionRequest | DecisionRequestInput): DecisionRequest;
466
+ export declare function generate<const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>): Effect.Effect<DecisionResponseFor<Questions>, AIError, Service>;
467
+ export declare function generate(input: DecisionRequest): Effect.Effect<DecisionResponse, AIError, Service>;
468
+ export declare const Decision: {
469
+ readonly request: typeof request;
470
+ readonly generate: typeof generate;
471
+ };
472
+ export {};