@opencode/ai 0.0.0-reserved → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/README.md +879 -2
  2. package/dist/cache-policy.d.ts +2 -0
  3. package/dist/cache-policy.js +129 -0
  4. package/dist/image-client.d.ts +19 -0
  5. package/dist/image-client.js +28 -0
  6. package/dist/image.d.ts +110 -0
  7. package/dist/image.js +103 -0
  8. package/dist/index.d.ts +18 -0
  9. package/dist/index.js +12 -0
  10. package/dist/llm.d.ts +252 -0
  11. package/dist/llm.js +74 -0
  12. package/dist/protocols/alibaba-chat.d.ts +225 -0
  13. package/dist/protocols/alibaba-chat.js +75 -0
  14. package/dist/protocols/alibaba-messages.d.ts +350 -0
  15. package/dist/protocols/alibaba-messages.js +40 -0
  16. package/dist/protocols/alibaba-responses.d.ts +255 -0
  17. package/dist/protocols/alibaba-responses.js +80 -0
  18. package/dist/protocols/anthropic-messages.d.ts +980 -0
  19. package/dist/protocols/anthropic-messages.js +1460 -0
  20. package/dist/protocols/bedrock-converse.d.ts +499 -0
  21. package/dist/protocols/bedrock-converse.js +643 -0
  22. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  23. package/dist/protocols/bedrock-event-stream.js +97 -0
  24. package/dist/protocols/gemini.d.ts +285 -0
  25. package/dist/protocols/gemini.js +671 -0
  26. package/dist/protocols/google-images.d.ts +30 -0
  27. package/dist/protocols/google-images.js +181 -0
  28. package/dist/protocols/index.d.ts +12 -0
  29. package/dist/protocols/index.js +12 -0
  30. package/dist/protocols/meta-images.d.ts +26 -0
  31. package/dist/protocols/meta-images.js +89 -0
  32. package/dist/protocols/meta-messages.d.ts +356 -0
  33. package/dist/protocols/meta-messages.js +41 -0
  34. package/dist/protocols/meta-responses.d.ts +473 -0
  35. package/dist/protocols/meta-responses.js +173 -0
  36. package/dist/protocols/mistral-chat.d.ts +540 -0
  37. package/dist/protocols/mistral-chat.js +624 -0
  38. package/dist/protocols/open-responses-channel.d.ts +25 -0
  39. package/dist/protocols/open-responses-channel.js +141 -0
  40. package/dist/protocols/open-responses-continuation.d.ts +16 -0
  41. package/dist/protocols/open-responses-continuation.js +170 -0
  42. package/dist/protocols/open-responses.d.ts +1715 -0
  43. package/dist/protocols/open-responses.js +1228 -0
  44. package/dist/protocols/openai-chat.d.ts +860 -0
  45. package/dist/protocols/openai-chat.js +966 -0
  46. package/dist/protocols/openai-compatible-chat.d.ts +109 -0
  47. package/dist/protocols/openai-compatible-chat.js +19 -0
  48. package/dist/protocols/openai-compatible-responses.d.ts +172 -0
  49. package/dist/protocols/openai-compatible-responses.js +18 -0
  50. package/dist/protocols/openai-images.d.ts +32 -0
  51. package/dist/protocols/openai-images.js +183 -0
  52. package/dist/protocols/openai-responses.d.ts +1389 -0
  53. package/dist/protocols/openai-responses.js +260 -0
  54. package/dist/protocols/shared.d.ts +193 -0
  55. package/dist/protocols/shared.js +290 -0
  56. package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
  57. package/dist/protocols/utils/bedrock-auth.js +85 -0
  58. package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
  59. package/dist/protocols/utils/bedrock-cache.js +49 -0
  60. package/dist/protocols/utils/bedrock-media.d.ts +55 -0
  61. package/dist/protocols/utils/bedrock-media.js +73 -0
  62. package/dist/protocols/utils/cache.d.ts +6 -0
  63. package/dist/protocols/utils/cache.js +5 -0
  64. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  65. package/dist/protocols/utils/gemini-tool-schema.js +103 -0
  66. package/dist/protocols/utils/image-input.d.ts +21 -0
  67. package/dist/protocols/utils/image-input.js +20 -0
  68. package/dist/protocols/utils/lifecycle.d.ts +24 -0
  69. package/dist/protocols/utils/lifecycle.js +72 -0
  70. package/dist/protocols/utils/meta-image.d.ts +2 -0
  71. package/dist/protocols/utils/meta-image.js +13 -0
  72. package/dist/protocols/utils/open-responses-options.d.ts +56 -0
  73. package/dist/protocols/utils/open-responses-options.js +61 -0
  74. package/dist/protocols/utils/openai-image.d.ts +5 -0
  75. package/dist/protocols/utils/openai-image.js +18 -0
  76. package/dist/protocols/utils/openai-options.d.ts +16 -0
  77. package/dist/protocols/utils/openai-options.js +14 -0
  78. package/dist/protocols/utils/partial-json-options.d.ts +62 -0
  79. package/dist/protocols/utils/partial-json-options.js +52 -0
  80. package/dist/protocols/utils/partial-json.d.ts +8 -0
  81. package/dist/protocols/utils/partial-json.js +279 -0
  82. package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
  83. package/dist/protocols/utils/responses-checkpoint.js +107 -0
  84. package/dist/protocols/utils/responses-compaction.d.ts +4 -0
  85. package/dist/protocols/utils/responses-compaction.js +129 -0
  86. package/dist/protocols/utils/responses-hosted-tools.d.ts +26 -0
  87. package/dist/protocols/utils/responses-hosted-tools.js +32 -0
  88. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  89. package/dist/protocols/utils/tool-schema.js +54 -0
  90. package/dist/protocols/utils/tool-stream.d.ts +710 -0
  91. package/dist/protocols/utils/tool-stream.js +155 -0
  92. package/dist/protocols/xai-images.d.ts +26 -0
  93. package/dist/protocols/xai-images.js +106 -0
  94. package/dist/protocols/xai-responses.d.ts +250 -0
  95. package/dist/protocols/xai-responses.js +81 -0
  96. package/dist/protocols/zai-chat.d.ts +202 -0
  97. package/dist/protocols/zai-chat.js +49 -0
  98. package/dist/protocols/zai-images.d.ts +22 -0
  99. package/dist/protocols/zai-images.js +79 -0
  100. package/dist/protocols/zai-messages.d.ts +344 -0
  101. package/dist/protocols/zai-messages.js +27 -0
  102. package/dist/protocols.d.ts +1 -0
  103. package/dist/protocols.js +1 -0
  104. package/dist/provider-error.d.ts +15 -0
  105. package/dist/provider-error.js +125 -0
  106. package/dist/provider-package.d.ts +15 -0
  107. package/dist/provider-package.js +1 -0
  108. package/dist/provider.d.ts +23 -0
  109. package/dist/provider.js +2 -0
  110. package/dist/providers/alibaba/chat.d.ts +1 -0
  111. package/dist/providers/alibaba/chat.js +1 -0
  112. package/dist/providers/alibaba/messages.d.ts +3 -0
  113. package/dist/providers/alibaba/messages.js +1 -0
  114. package/dist/providers/alibaba/responses.d.ts +3 -0
  115. package/dist/providers/alibaba/responses.js +1 -0
  116. package/dist/providers/alibaba.d.ts +711 -0
  117. package/dist/providers/alibaba.js +94 -0
  118. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  119. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  120. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  121. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  122. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  123. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  124. package/dist/providers/amazon-bedrock-mantle.d.ts +313 -0
  125. package/dist/providers/amazon-bedrock-mantle.js +79 -0
  126. package/dist/providers/amazon-bedrock.d.ts +173 -0
  127. package/dist/providers/amazon-bedrock.js +41 -0
  128. package/dist/providers/anthropic-compatible.d.ts +309 -0
  129. package/dist/providers/anthropic-compatible.js +50 -0
  130. package/dist/providers/anthropic.d.ts +307 -0
  131. package/dist/providers/anthropic.js +42 -0
  132. package/dist/providers/azure/chat.d.ts +2 -0
  133. package/dist/providers/azure/chat.js +1 -0
  134. package/dist/providers/azure/responses.d.ts +2 -0
  135. package/dist/providers/azure/responses.js +1 -0
  136. package/dist/providers/azure.d.ts +598 -0
  137. package/dist/providers/azure.js +115 -0
  138. package/dist/providers/baseten.d.ts +228 -0
  139. package/dist/providers/baseten.js +38 -0
  140. package/dist/providers/cerebras.d.ts +227 -0
  141. package/dist/providers/cerebras.js +40 -0
  142. package/dist/providers/cloudflare-ai-gateway.d.ts +237 -0
  143. package/dist/providers/cloudflare-ai-gateway.js +65 -0
  144. package/dist/providers/cloudflare-workers-ai.d.ts +231 -0
  145. package/dist/providers/cloudflare-workers-ai.js +51 -0
  146. package/dist/providers/deepinfra.d.ts +227 -0
  147. package/dist/providers/deepinfra.js +43 -0
  148. package/dist/providers/deepseek.d.ts +228 -0
  149. package/dist/providers/deepseek.js +41 -0
  150. package/dist/providers/fireworks.d.ts +228 -0
  151. package/dist/providers/fireworks.js +38 -0
  152. package/dist/providers/google-vertex/chat.d.ts +2 -0
  153. package/dist/providers/google-vertex/chat.js +1 -0
  154. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  155. package/dist/providers/google-vertex/gemini.js +1 -0
  156. package/dist/providers/google-vertex/messages.d.ts +2 -0
  157. package/dist/providers/google-vertex/messages.js +1 -0
  158. package/dist/providers/google-vertex/responses.d.ts +2 -0
  159. package/dist/providers/google-vertex/responses.js +1 -0
  160. package/dist/providers/google-vertex-chat.d.ts +132 -0
  161. package/dist/providers/google-vertex-chat.js +55 -0
  162. package/dist/providers/google-vertex-messages.d.ts +306 -0
  163. package/dist/providers/google-vertex-messages.js +75 -0
  164. package/dist/providers/google-vertex-responses.d.ts +197 -0
  165. package/dist/providers/google-vertex-responses.js +56 -0
  166. package/dist/providers/google-vertex-shared.d.ts +22 -0
  167. package/dist/providers/google-vertex-shared.js +72 -0
  168. package/dist/providers/google-vertex.d.ts +119 -0
  169. package/dist/providers/google-vertex.js +98 -0
  170. package/dist/providers/google.d.ts +114 -0
  171. package/dist/providers/google.js +42 -0
  172. package/dist/providers/groq.d.ts +314 -0
  173. package/dist/providers/groq.js +81 -0
  174. package/dist/providers/index.d.ts +31 -0
  175. package/dist/providers/index.js +31 -0
  176. package/dist/providers/meta/chat.d.ts +2 -0
  177. package/dist/providers/meta/chat.js +1 -0
  178. package/dist/providers/meta/messages.d.ts +2 -0
  179. package/dist/providers/meta/messages.js +1 -0
  180. package/dist/providers/meta/responses.d.ts +2 -0
  181. package/dist/providers/meta/responses.js +1 -0
  182. package/dist/providers/meta.d.ts +636 -0
  183. package/dist/providers/meta.js +113 -0
  184. package/dist/providers/minimax/chat.d.ts +4 -0
  185. package/dist/providers/minimax/chat.js +8 -0
  186. package/dist/providers/minimax/messages.d.ts +1 -0
  187. package/dist/providers/minimax/messages.js +1 -0
  188. package/dist/providers/minimax/responses.d.ts +4 -0
  189. package/dist/providers/minimax/responses.js +8 -0
  190. package/dist/providers/minimax.d.ts +598 -0
  191. package/dist/providers/minimax.js +89 -0
  192. package/dist/providers/mistral.d.ts +207 -0
  193. package/dist/providers/mistral.js +28 -0
  194. package/dist/providers/moonshot/chat.d.ts +1 -0
  195. package/dist/providers/moonshot/chat.js +1 -0
  196. package/dist/providers/moonshot/messages.d.ts +4 -0
  197. package/dist/providers/moonshot/messages.js +8 -0
  198. package/dist/providers/moonshot/responses.d.ts +4 -0
  199. package/dist/providers/moonshot/responses.js +8 -0
  200. package/dist/providers/moonshot.d.ts +596 -0
  201. package/dist/providers/moonshot.js +90 -0
  202. package/dist/providers/open-responses-options.d.ts +6 -0
  203. package/dist/providers/open-responses-options.js +1 -0
  204. package/dist/providers/openai/chat.d.ts +2 -0
  205. package/dist/providers/openai/chat.js +1 -0
  206. package/dist/providers/openai/responses.d.ts +2 -0
  207. package/dist/providers/openai/responses.js +1 -0
  208. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  209. package/dist/providers/openai-compatible/responses.js +1 -0
  210. package/dist/providers/openai-compatible-responses.d.ts +195 -0
  211. package/dist/providers/openai-compatible-responses.js +32 -0
  212. package/dist/providers/openai-compatible.d.ts +130 -0
  213. package/dist/providers/openai-compatible.js +33 -0
  214. package/dist/providers/openai-options.d.ts +26 -0
  215. package/dist/providers/openai-options.js +41 -0
  216. package/dist/providers/openai.d.ts +404 -0
  217. package/dist/providers/openai.js +82 -0
  218. package/dist/providers/openrouter.d.ts +563 -0
  219. package/dist/providers/openrouter.js +114 -0
  220. package/dist/providers/togetherai.d.ts +227 -0
  221. package/dist/providers/togetherai.js +40 -0
  222. package/dist/providers/xai.d.ts +163 -0
  223. package/dist/providers/xai.js +88 -0
  224. package/dist/providers/zai/chat.d.ts +1 -0
  225. package/dist/providers/zai/chat.js +1 -0
  226. package/dist/providers/zai-coding-plan/chat.d.ts +1 -0
  227. package/dist/providers/zai-coding-plan/chat.js +1 -0
  228. package/dist/providers/zai-coding-plan/messages.d.ts +4 -0
  229. package/dist/providers/zai-coding-plan/messages.js +8 -0
  230. package/dist/providers/zai-coding-plan/responses.d.ts +4 -0
  231. package/dist/providers/zai-coding-plan/responses.js +8 -0
  232. package/dist/providers/zai-coding-plan.d.ts +577 -0
  233. package/dist/providers/zai-coding-plan.js +63 -0
  234. package/dist/providers/zai.d.ts +149 -0
  235. package/dist/providers/zai.js +53 -0
  236. package/dist/providers.d.ts +1 -0
  237. package/dist/providers.js +1 -0
  238. package/dist/route/auth-options.d.ts +34 -0
  239. package/dist/route/auth-options.js +14 -0
  240. package/dist/route/auth.d.ts +51 -0
  241. package/dist/route/auth.js +87 -0
  242. package/dist/route/client.d.ts +430 -0
  243. package/dist/route/client.js +307 -0
  244. package/dist/route/endpoint.d.ts +28 -0
  245. package/dist/route/endpoint.js +21 -0
  246. package/dist/route/executor.d.ts +27 -0
  247. package/dist/route/executor.js +183 -0
  248. package/dist/route/framing.d.ts +29 -0
  249. package/dist/route/framing.js +14 -0
  250. package/dist/route/index.d.ts +16 -0
  251. package/dist/route/index.js +9 -0
  252. package/dist/route/protocol.d.ts +76 -0
  253. package/dist/route/protocol.js +16 -0
  254. package/dist/route/transport/http.d.ts +34 -0
  255. package/dist/route/transport/http.js +68 -0
  256. package/dist/route/transport/index.d.ts +41 -0
  257. package/dist/route/transport/index.js +4 -0
  258. package/dist/route/transport/websocket-channel.d.ts +57 -0
  259. package/dist/route/transport/websocket-channel.js +1 -0
  260. package/dist/route/transport/websocket.d.ts +56 -0
  261. package/dist/route/transport/websocket.js +370 -0
  262. package/dist/route.d.ts +1 -0
  263. package/dist/route.js +1 -0
  264. package/dist/schema/errors.d.ts +170 -0
  265. package/dist/schema/errors.js +131 -0
  266. package/dist/schema/events.d.ts +8123 -0
  267. package/dist/schema/events.js +550 -0
  268. package/dist/schema/ids.d.ts +17 -0
  269. package/dist/schema/ids.js +10 -0
  270. package/dist/schema/index.d.ts +5 -0
  271. package/dist/schema/index.js +5 -0
  272. package/dist/schema/messages.d.ts +646 -0
  273. package/dist/schema/messages.js +301 -0
  274. package/dist/schema/options.d.ts +159 -0
  275. package/dist/schema/options.js +189 -0
  276. package/dist/testing.d.ts +1693 -0
  277. package/dist/testing.js +129 -0
  278. package/dist/tool-history.d.ts +2 -0
  279. package/dist/tool-history.js +84 -0
  280. package/dist/tool-runtime.d.ts +15 -0
  281. package/dist/tool-runtime.js +62 -0
  282. package/dist/tool.d.ts +136 -0
  283. package/dist/tool.js +66 -0
  284. package/dist/utils/record.d.ts +2 -0
  285. package/dist/utils/record.js +2 -0
  286. package/dist/utils/sanitize.d.ts +1 -0
  287. package/dist/utils/sanitize.js +12 -0
  288. package/package.json +43 -10
@@ -0,0 +1,710 @@
1
+ import { Effect } from "effect";
2
+ import { AIError, LLMEvent, type ProviderMetadata } from "../../schema/index.js";
3
+ import { type ToolAccumulator } from "../shared.js";
4
+ type StreamKey = string | number;
5
+ /**
6
+ * One pending streamed tool call. Providers emit the tool identity and JSON
7
+ * argument text across separate chunks; `input` is the raw JSON string collected
8
+ * so far, not the parsed object.
9
+ */
10
+ export interface PendingTool extends ToolAccumulator {
11
+ readonly providerExecuted?: boolean;
12
+ readonly providerMetadata?: ProviderMetadata;
13
+ }
14
+ /**
15
+ * Sparse parser state keyed by the provider's stream-local tool identifier.
16
+ *
17
+ * This key is not the final tool-call id (`call_...`). It is the id/index the
18
+ * provider uses while streaming a partial call: OpenAI Chat / Anthropic /
19
+ * Bedrock use numeric content indexes, while OpenAI Responses uses string
20
+ * `item_id`s. The generic keeps each protocol internally consistent.
21
+ */
22
+ export type State<K extends StreamKey> = Partial<Record<K, PendingTool>>;
23
+ /**
24
+ * Result of adding argument text to one pending tool call. It returns both the
25
+ * next `tools` state and the updated `tool` because parsers often need the
26
+ * current id/name immediately. `events` contains lifecycle and delta events
27
+ * produced by the append; metadata-only deltas update identity without output.
28
+ */
29
+ export interface AppendOutcome<K extends StreamKey> {
30
+ readonly tools: State<K>;
31
+ readonly tool: PendingTool;
32
+ readonly events: ReadonlyArray<LLMEvent>;
33
+ }
34
+ /** Create empty accumulator state for one provider stream. */
35
+ export declare const empty: <K extends StreamKey>() => State<K>;
36
+ export declare const isError: <K extends StreamKey>(result: AppendOutcome<K> | AIError) => result is AIError;
37
+ /**
38
+ * Register a tool call whose start event arrived before any argument deltas.
39
+ * Used by Anthropic `content_block_start`, Bedrock `contentBlockStart`, and
40
+ * OpenAI Responses `response.output_item.added`.
41
+ */
42
+ export declare const start: <K extends StreamKey>(tools: State<K>, key: K, tool: Omit<PendingTool, "input"> & {
43
+ readonly input?: string;
44
+ }) => Partial<Record<K, PendingTool>>;
45
+ /**
46
+ * Append a streamed argument delta, starting the tool if this provider encodes
47
+ * identity on the first delta instead of a separate start event. OpenAI Chat has
48
+ * this shape: `tool_calls[].index` is the stream key, and `id` / `name` may only
49
+ * appear on the first delta for that index.
50
+ */
51
+ export declare const appendOrStart: <K extends StreamKey>(route: string, tools: State<K>, key: K, delta: {
52
+ readonly id?: string;
53
+ readonly name?: string;
54
+ readonly text: string;
55
+ }, missingToolMessage: string) => AppendOutcome<K> | AIError;
56
+ /**
57
+ * Append argument text to a started tool. Returns `undefined` when no tool is
58
+ * open under `key`, for protocols that ignore deltas without a matching block.
59
+ */
60
+ export declare const append: <K extends StreamKey>(tools: State<K>, key: K, text: string) => AppendOutcome<K> | undefined;
61
+ /**
62
+ * Append argument text to a tool that must already have been started. This keeps
63
+ * protocols honest when their stream grammar promises a start event before any
64
+ * argument delta.
65
+ */
66
+ export declare const appendExisting: <K extends StreamKey>(route: string, tools: State<K>, key: K, text: string, missingToolMessage: string) => AppendOutcome<K> | AIError;
67
+ /**
68
+ * Finalize one pending tool call: parse the accumulated raw JSON, remove it
69
+ * from state, and recover incomplete local arguments when needed.
70
+ * Missing keys are a no-op because some providers emit stop events for
71
+ * non-tool content blocks.
72
+ */
73
+ export declare const finish: <K extends StreamKey>(route: string, tools: State<K>, key: K) => Effect.Effect<{
74
+ tools: Partial<Record<K, PendingTool>>;
75
+ events?: undefined;
76
+ } | {
77
+ tools: Partial<Record<K, PendingTool>>;
78
+ events: readonly (({
79
+ readonly type: "compaction";
80
+ readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
81
+ readonly id?: string | undefined;
82
+ readonly text?: string | null | undefined;
83
+ readonly encrypted?: string | undefined;
84
+ } & ({
85
+ readonly encrypted: string;
86
+ readonly text?: never;
87
+ } | {
88
+ readonly text: string | null;
89
+ readonly encrypted?: never;
90
+ })) | {
91
+ readonly type: "step-start";
92
+ readonly index: number;
93
+ } | {
94
+ readonly id: string;
95
+ readonly type: "text-start";
96
+ readonly providerMetadata?: {
97
+ readonly [x: string]: {
98
+ readonly [x: string]: unknown;
99
+ };
100
+ } | undefined;
101
+ } | {
102
+ readonly id: string;
103
+ readonly type: "text-delta";
104
+ readonly text: string;
105
+ readonly providerMetadata?: {
106
+ readonly [x: string]: {
107
+ readonly [x: string]: unknown;
108
+ };
109
+ } | undefined;
110
+ } | {
111
+ readonly id: string;
112
+ readonly type: "text-end";
113
+ readonly text?: string | undefined;
114
+ readonly providerMetadata?: {
115
+ readonly [x: string]: {
116
+ readonly [x: string]: unknown;
117
+ };
118
+ } | undefined;
119
+ } | {
120
+ readonly id: string;
121
+ readonly type: "reasoning-start";
122
+ readonly providerMetadata?: {
123
+ readonly [x: string]: {
124
+ readonly [x: string]: unknown;
125
+ };
126
+ } | undefined;
127
+ } | {
128
+ readonly id: string;
129
+ readonly type: "reasoning-delta";
130
+ readonly text: string;
131
+ readonly providerMetadata?: {
132
+ readonly [x: string]: {
133
+ readonly [x: string]: unknown;
134
+ };
135
+ } | undefined;
136
+ } | {
137
+ readonly id: string;
138
+ readonly type: "reasoning-end";
139
+ readonly text?: string | undefined;
140
+ readonly providerMetadata?: {
141
+ readonly [x: string]: {
142
+ readonly [x: string]: unknown;
143
+ };
144
+ } | undefined;
145
+ } | {
146
+ readonly id: string;
147
+ readonly type: "tool-input-start";
148
+ readonly name: string;
149
+ readonly providerMetadata?: {
150
+ readonly [x: string]: {
151
+ readonly [x: string]: unknown;
152
+ };
153
+ } | undefined;
154
+ readonly namespace?: string | undefined;
155
+ readonly providerExecuted?: boolean | undefined;
156
+ } | {
157
+ readonly id: string;
158
+ readonly type: "tool-input-delta";
159
+ readonly name: string;
160
+ readonly text: string;
161
+ readonly input?: unknown;
162
+ readonly namespace?: string | undefined;
163
+ } | {
164
+ readonly id: string;
165
+ readonly type: "tool-input-end";
166
+ readonly name: string;
167
+ readonly providerMetadata?: {
168
+ readonly [x: string]: {
169
+ readonly [x: string]: unknown;
170
+ };
171
+ } | undefined;
172
+ readonly namespace?: string | undefined;
173
+ } | {
174
+ readonly id: string;
175
+ readonly type: "tool-input-error";
176
+ readonly name: string;
177
+ readonly raw: string;
178
+ readonly namespace?: string | undefined;
179
+ } | {
180
+ readonly id: string;
181
+ readonly type: "tool-call";
182
+ readonly name: string;
183
+ readonly input: unknown;
184
+ readonly providerMetadata?: {
185
+ readonly [x: string]: {
186
+ readonly [x: string]: unknown;
187
+ };
188
+ } | undefined;
189
+ readonly namespace?: string | undefined;
190
+ readonly providerExecuted?: boolean | undefined;
191
+ } | {
192
+ readonly id: string;
193
+ readonly type: "tool-result";
194
+ readonly name: string;
195
+ readonly result: {
196
+ readonly type: "json";
197
+ readonly value: unknown;
198
+ } | {
199
+ readonly type: "text";
200
+ readonly value: unknown;
201
+ } | {
202
+ readonly type: "error";
203
+ readonly value: unknown;
204
+ } | {
205
+ readonly type: "content";
206
+ readonly value: readonly ({
207
+ readonly type: "text";
208
+ readonly text: string;
209
+ } | {
210
+ readonly type: "file";
211
+ readonly uri: string;
212
+ readonly mime: string;
213
+ readonly name?: string | undefined;
214
+ })[];
215
+ };
216
+ readonly output?: {
217
+ readonly structured: unknown;
218
+ readonly content: readonly ({
219
+ readonly type: "text";
220
+ readonly text: string;
221
+ } | {
222
+ readonly type: "file";
223
+ readonly uri: string;
224
+ readonly mime: string;
225
+ readonly name?: string | undefined;
226
+ })[];
227
+ } | undefined;
228
+ readonly providerMetadata?: {
229
+ readonly [x: string]: {
230
+ readonly [x: string]: unknown;
231
+ };
232
+ } | undefined;
233
+ readonly namespace?: string | undefined;
234
+ readonly providerExecuted?: boolean | undefined;
235
+ } | {
236
+ readonly id: string;
237
+ readonly type: "tool-error";
238
+ readonly name: string;
239
+ readonly message: string;
240
+ readonly error?: unknown;
241
+ readonly providerMetadata?: {
242
+ readonly [x: string]: {
243
+ readonly [x: string]: unknown;
244
+ };
245
+ } | undefined;
246
+ readonly namespace?: string | undefined;
247
+ } | {
248
+ readonly type: "step-finish";
249
+ readonly reason: {
250
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
251
+ readonly raw?: string | undefined;
252
+ };
253
+ readonly index: number;
254
+ readonly providerMetadata?: {
255
+ readonly [x: string]: {
256
+ readonly [x: string]: unknown;
257
+ };
258
+ } | undefined;
259
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
260
+ } | {
261
+ readonly type: "finish";
262
+ readonly reason: {
263
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
264
+ readonly raw?: string | undefined;
265
+ };
266
+ readonly providerMetadata?: {
267
+ readonly [x: string]: {
268
+ readonly [x: string]: unknown;
269
+ };
270
+ } | undefined;
271
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
272
+ } | {
273
+ readonly type: "provider-error";
274
+ readonly message: string;
275
+ readonly providerMetadata?: {
276
+ readonly [x: string]: {
277
+ readonly [x: string]: unknown;
278
+ };
279
+ } | undefined;
280
+ readonly classification?: "context-overflow" | "payload-too-large" | undefined;
281
+ })[];
282
+ }, AIError, never>;
283
+ /**
284
+ * Finalize one pending tool call with an authoritative final input string.
285
+ * OpenAI Responses can send accumulated deltas and then repeat the completed
286
+ * arguments on `response.output_item.done`; the final value wins.
287
+ */
288
+ export declare const finishWithInput: <K extends StreamKey>(route: string, tools: State<K>, key: K, input: string) => Effect.Effect<{
289
+ tools: Partial<Record<K, PendingTool>>;
290
+ events?: undefined;
291
+ } | {
292
+ tools: Partial<Record<K, PendingTool>>;
293
+ events: readonly (({
294
+ readonly type: "compaction";
295
+ readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
296
+ readonly id?: string | undefined;
297
+ readonly text?: string | null | undefined;
298
+ readonly encrypted?: string | undefined;
299
+ } & ({
300
+ readonly encrypted: string;
301
+ readonly text?: never;
302
+ } | {
303
+ readonly text: string | null;
304
+ readonly encrypted?: never;
305
+ })) | {
306
+ readonly type: "step-start";
307
+ readonly index: number;
308
+ } | {
309
+ readonly id: string;
310
+ readonly type: "text-start";
311
+ readonly providerMetadata?: {
312
+ readonly [x: string]: {
313
+ readonly [x: string]: unknown;
314
+ };
315
+ } | undefined;
316
+ } | {
317
+ readonly id: string;
318
+ readonly type: "text-delta";
319
+ readonly text: string;
320
+ readonly providerMetadata?: {
321
+ readonly [x: string]: {
322
+ readonly [x: string]: unknown;
323
+ };
324
+ } | undefined;
325
+ } | {
326
+ readonly id: string;
327
+ readonly type: "text-end";
328
+ readonly text?: string | undefined;
329
+ readonly providerMetadata?: {
330
+ readonly [x: string]: {
331
+ readonly [x: string]: unknown;
332
+ };
333
+ } | undefined;
334
+ } | {
335
+ readonly id: string;
336
+ readonly type: "reasoning-start";
337
+ readonly providerMetadata?: {
338
+ readonly [x: string]: {
339
+ readonly [x: string]: unknown;
340
+ };
341
+ } | undefined;
342
+ } | {
343
+ readonly id: string;
344
+ readonly type: "reasoning-delta";
345
+ readonly text: string;
346
+ readonly providerMetadata?: {
347
+ readonly [x: string]: {
348
+ readonly [x: string]: unknown;
349
+ };
350
+ } | undefined;
351
+ } | {
352
+ readonly id: string;
353
+ readonly type: "reasoning-end";
354
+ readonly text?: string | undefined;
355
+ readonly providerMetadata?: {
356
+ readonly [x: string]: {
357
+ readonly [x: string]: unknown;
358
+ };
359
+ } | undefined;
360
+ } | {
361
+ readonly id: string;
362
+ readonly type: "tool-input-start";
363
+ readonly name: string;
364
+ readonly providerMetadata?: {
365
+ readonly [x: string]: {
366
+ readonly [x: string]: unknown;
367
+ };
368
+ } | undefined;
369
+ readonly namespace?: string | undefined;
370
+ readonly providerExecuted?: boolean | undefined;
371
+ } | {
372
+ readonly id: string;
373
+ readonly type: "tool-input-delta";
374
+ readonly name: string;
375
+ readonly text: string;
376
+ readonly input?: unknown;
377
+ readonly namespace?: string | undefined;
378
+ } | {
379
+ readonly id: string;
380
+ readonly type: "tool-input-end";
381
+ readonly name: string;
382
+ readonly providerMetadata?: {
383
+ readonly [x: string]: {
384
+ readonly [x: string]: unknown;
385
+ };
386
+ } | undefined;
387
+ readonly namespace?: string | undefined;
388
+ } | {
389
+ readonly id: string;
390
+ readonly type: "tool-input-error";
391
+ readonly name: string;
392
+ readonly raw: string;
393
+ readonly namespace?: string | undefined;
394
+ } | {
395
+ readonly id: string;
396
+ readonly type: "tool-call";
397
+ readonly name: string;
398
+ readonly input: unknown;
399
+ readonly providerMetadata?: {
400
+ readonly [x: string]: {
401
+ readonly [x: string]: unknown;
402
+ };
403
+ } | undefined;
404
+ readonly namespace?: string | undefined;
405
+ readonly providerExecuted?: boolean | undefined;
406
+ } | {
407
+ readonly id: string;
408
+ readonly type: "tool-result";
409
+ readonly name: string;
410
+ readonly result: {
411
+ readonly type: "json";
412
+ readonly value: unknown;
413
+ } | {
414
+ readonly type: "text";
415
+ readonly value: unknown;
416
+ } | {
417
+ readonly type: "error";
418
+ readonly value: unknown;
419
+ } | {
420
+ readonly type: "content";
421
+ readonly value: readonly ({
422
+ readonly type: "text";
423
+ readonly text: string;
424
+ } | {
425
+ readonly type: "file";
426
+ readonly uri: string;
427
+ readonly mime: string;
428
+ readonly name?: string | undefined;
429
+ })[];
430
+ };
431
+ readonly output?: {
432
+ readonly structured: unknown;
433
+ readonly content: readonly ({
434
+ readonly type: "text";
435
+ readonly text: string;
436
+ } | {
437
+ readonly type: "file";
438
+ readonly uri: string;
439
+ readonly mime: string;
440
+ readonly name?: string | undefined;
441
+ })[];
442
+ } | undefined;
443
+ readonly providerMetadata?: {
444
+ readonly [x: string]: {
445
+ readonly [x: string]: unknown;
446
+ };
447
+ } | undefined;
448
+ readonly namespace?: string | undefined;
449
+ readonly providerExecuted?: boolean | undefined;
450
+ } | {
451
+ readonly id: string;
452
+ readonly type: "tool-error";
453
+ readonly name: string;
454
+ readonly message: string;
455
+ readonly error?: unknown;
456
+ readonly providerMetadata?: {
457
+ readonly [x: string]: {
458
+ readonly [x: string]: unknown;
459
+ };
460
+ } | undefined;
461
+ readonly namespace?: string | undefined;
462
+ } | {
463
+ readonly type: "step-finish";
464
+ readonly reason: {
465
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
466
+ readonly raw?: string | undefined;
467
+ };
468
+ readonly index: number;
469
+ readonly providerMetadata?: {
470
+ readonly [x: string]: {
471
+ readonly [x: string]: unknown;
472
+ };
473
+ } | undefined;
474
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
475
+ } | {
476
+ readonly type: "finish";
477
+ readonly reason: {
478
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
479
+ readonly raw?: string | undefined;
480
+ };
481
+ readonly providerMetadata?: {
482
+ readonly [x: string]: {
483
+ readonly [x: string]: unknown;
484
+ };
485
+ } | undefined;
486
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
487
+ } | {
488
+ readonly type: "provider-error";
489
+ readonly message: string;
490
+ readonly providerMetadata?: {
491
+ readonly [x: string]: {
492
+ readonly [x: string]: unknown;
493
+ };
494
+ } | undefined;
495
+ readonly classification?: "context-overflow" | "payload-too-large" | undefined;
496
+ })[];
497
+ }, AIError, never>;
498
+ /**
499
+ * Finalize every pending tool call at once. OpenAI Chat has this shape: it does
500
+ * not emit per-tool stop events, so all accumulated calls finish independently
501
+ * when the choice receives a terminal `finish_reason`.
502
+ */
503
+ export declare const finishAll: <K extends StreamKey>(route: string, tools: State<K>) => Effect.Effect<{
504
+ tools: Partial<Record<K, PendingTool>>;
505
+ events: (({
506
+ readonly type: "compaction";
507
+ readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
508
+ readonly id?: string | undefined;
509
+ readonly text?: string | null | undefined;
510
+ readonly encrypted?: string | undefined;
511
+ } & ({
512
+ readonly encrypted: string;
513
+ readonly text?: never;
514
+ } | {
515
+ readonly text: string | null;
516
+ readonly encrypted?: never;
517
+ })) | {
518
+ readonly type: "step-start";
519
+ readonly index: number;
520
+ } | {
521
+ readonly id: string;
522
+ readonly type: "text-start";
523
+ readonly providerMetadata?: {
524
+ readonly [x: string]: {
525
+ readonly [x: string]: unknown;
526
+ };
527
+ } | undefined;
528
+ } | {
529
+ readonly id: string;
530
+ readonly type: "text-delta";
531
+ readonly text: string;
532
+ readonly providerMetadata?: {
533
+ readonly [x: string]: {
534
+ readonly [x: string]: unknown;
535
+ };
536
+ } | undefined;
537
+ } | {
538
+ readonly id: string;
539
+ readonly type: "text-end";
540
+ readonly text?: string | undefined;
541
+ readonly providerMetadata?: {
542
+ readonly [x: string]: {
543
+ readonly [x: string]: unknown;
544
+ };
545
+ } | undefined;
546
+ } | {
547
+ readonly id: string;
548
+ readonly type: "reasoning-start";
549
+ readonly providerMetadata?: {
550
+ readonly [x: string]: {
551
+ readonly [x: string]: unknown;
552
+ };
553
+ } | undefined;
554
+ } | {
555
+ readonly id: string;
556
+ readonly type: "reasoning-delta";
557
+ readonly text: string;
558
+ readonly providerMetadata?: {
559
+ readonly [x: string]: {
560
+ readonly [x: string]: unknown;
561
+ };
562
+ } | undefined;
563
+ } | {
564
+ readonly id: string;
565
+ readonly type: "reasoning-end";
566
+ readonly text?: string | undefined;
567
+ readonly providerMetadata?: {
568
+ readonly [x: string]: {
569
+ readonly [x: string]: unknown;
570
+ };
571
+ } | undefined;
572
+ } | {
573
+ readonly id: string;
574
+ readonly type: "tool-input-start";
575
+ readonly name: string;
576
+ readonly providerMetadata?: {
577
+ readonly [x: string]: {
578
+ readonly [x: string]: unknown;
579
+ };
580
+ } | undefined;
581
+ readonly namespace?: string | undefined;
582
+ readonly providerExecuted?: boolean | undefined;
583
+ } | {
584
+ readonly id: string;
585
+ readonly type: "tool-input-delta";
586
+ readonly name: string;
587
+ readonly text: string;
588
+ readonly input?: unknown;
589
+ readonly namespace?: string | undefined;
590
+ } | {
591
+ readonly id: string;
592
+ readonly type: "tool-input-end";
593
+ readonly name: string;
594
+ readonly providerMetadata?: {
595
+ readonly [x: string]: {
596
+ readonly [x: string]: unknown;
597
+ };
598
+ } | undefined;
599
+ readonly namespace?: string | undefined;
600
+ } | {
601
+ readonly id: string;
602
+ readonly type: "tool-input-error";
603
+ readonly name: string;
604
+ readonly raw: string;
605
+ readonly namespace?: string | undefined;
606
+ } | {
607
+ readonly id: string;
608
+ readonly type: "tool-call";
609
+ readonly name: string;
610
+ readonly input: unknown;
611
+ readonly providerMetadata?: {
612
+ readonly [x: string]: {
613
+ readonly [x: string]: unknown;
614
+ };
615
+ } | undefined;
616
+ readonly namespace?: string | undefined;
617
+ readonly providerExecuted?: boolean | undefined;
618
+ } | {
619
+ readonly id: string;
620
+ readonly type: "tool-result";
621
+ readonly name: string;
622
+ readonly result: {
623
+ readonly type: "json";
624
+ readonly value: unknown;
625
+ } | {
626
+ readonly type: "text";
627
+ readonly value: unknown;
628
+ } | {
629
+ readonly type: "error";
630
+ readonly value: unknown;
631
+ } | {
632
+ readonly type: "content";
633
+ readonly value: readonly ({
634
+ readonly type: "text";
635
+ readonly text: string;
636
+ } | {
637
+ readonly type: "file";
638
+ readonly uri: string;
639
+ readonly mime: string;
640
+ readonly name?: string | undefined;
641
+ })[];
642
+ };
643
+ readonly output?: {
644
+ readonly structured: unknown;
645
+ readonly content: readonly ({
646
+ readonly type: "text";
647
+ readonly text: string;
648
+ } | {
649
+ readonly type: "file";
650
+ readonly uri: string;
651
+ readonly mime: string;
652
+ readonly name?: string | undefined;
653
+ })[];
654
+ } | undefined;
655
+ readonly providerMetadata?: {
656
+ readonly [x: string]: {
657
+ readonly [x: string]: unknown;
658
+ };
659
+ } | undefined;
660
+ readonly namespace?: string | undefined;
661
+ readonly providerExecuted?: boolean | undefined;
662
+ } | {
663
+ readonly id: string;
664
+ readonly type: "tool-error";
665
+ readonly name: string;
666
+ readonly message: string;
667
+ readonly error?: unknown;
668
+ readonly providerMetadata?: {
669
+ readonly [x: string]: {
670
+ readonly [x: string]: unknown;
671
+ };
672
+ } | undefined;
673
+ readonly namespace?: string | undefined;
674
+ } | {
675
+ readonly type: "step-finish";
676
+ readonly reason: {
677
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
678
+ readonly raw?: string | undefined;
679
+ };
680
+ readonly index: number;
681
+ readonly providerMetadata?: {
682
+ readonly [x: string]: {
683
+ readonly [x: string]: unknown;
684
+ };
685
+ } | undefined;
686
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
687
+ } | {
688
+ readonly type: "finish";
689
+ readonly reason: {
690
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
691
+ readonly raw?: string | undefined;
692
+ };
693
+ readonly providerMetadata?: {
694
+ readonly [x: string]: {
695
+ readonly [x: string]: unknown;
696
+ };
697
+ } | undefined;
698
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
699
+ } | {
700
+ readonly type: "provider-error";
701
+ readonly message: string;
702
+ readonly providerMetadata?: {
703
+ readonly [x: string]: {
704
+ readonly [x: string]: unknown;
705
+ };
706
+ } | undefined;
707
+ readonly classification?: "context-overflow" | "payload-too-large" | undefined;
708
+ })[];
709
+ }, AIError, never>;
710
+ export * as ToolStream from "./tool-stream.js";