@bastani/atomic 0.9.19-alpha.5 → 0.9.19-alpha.7

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 (209) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +2 -2
  3. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  4. package/dist/builtin/intercom/broker/client.ts +19 -1
  5. package/dist/builtin/intercom/index.bundle.mjs +8 -1
  6. package/dist/builtin/intercom/package.json +1 -1
  7. package/dist/builtin/mcp/package.json +1 -1
  8. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  9. package/dist/builtin/subagents/README.md +3 -1
  10. package/dist/builtin/subagents/agents/codebase-online-researcher.md +7 -7
  11. package/dist/builtin/subagents/package.json +1 -1
  12. package/dist/builtin/subagents/skills/subagent/SKILL.md +3 -1
  13. package/dist/builtin/subagents/src/extension/index.bundle.mjs +2 -1
  14. package/dist/builtin/web-access/CHANGELOG.md +13 -0
  15. package/dist/builtin/web-access/README.md +31 -24
  16. package/dist/builtin/web-access/index.bundle.mjs +16121 -80
  17. package/dist/builtin/web-access/package.json +2 -1
  18. package/dist/builtin/workflows/CHANGELOG.md +15 -0
  19. package/dist/builtin/workflows/README.md +1 -1
  20. package/dist/builtin/workflows/builtin/adversarial-verification.js +2 -2
  21. package/dist/builtin/workflows/builtin/{chunk-vhmnzdj9.js → chunk-1jth021m.js} +1 -1
  22. package/dist/builtin/workflows/builtin/{chunk-p8jjwfg6.js → chunk-2377r57g.js} +4 -2
  23. package/dist/builtin/workflows/builtin/{chunk-hbnwv56f.js → chunk-31j2gs7h.js} +2 -2
  24. package/dist/builtin/workflows/builtin/{chunk-n8zysf1t.js → chunk-ngkqkzej.js} +1 -1
  25. package/dist/builtin/workflows/builtin/{chunk-1nbq96fh.js → chunk-nkrafh9s.js} +1 -1
  26. package/dist/builtin/workflows/builtin/{chunk-1kx4aggw.js → chunk-wf741bv3.js} +2 -2
  27. package/dist/builtin/workflows/builtin/{chunk-t6x2d78s.js → chunk-z29qbehr.js} +1 -1
  28. package/dist/builtin/workflows/builtin/generate-and-filter.js +2 -2
  29. package/dist/builtin/workflows/builtin/goal.js +3 -3
  30. package/dist/builtin/workflows/builtin/index.js +7 -7
  31. package/dist/builtin/workflows/builtin/ralph.js +3 -3
  32. package/dist/builtin/workflows/builtin/tournament.js +2 -2
  33. package/dist/builtin/workflows/package.json +1 -1
  34. package/dist/builtin/workflows/src/extension/index.bundle.mjs +339 -31
  35. package/dist/builtin/workflows/src/index.js +67 -19
  36. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +2 -0
  37. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  38. package/dist/core/agent-session-tool-registry.js +10 -0
  39. package/dist/core/agent-session-tool-registry.js.map +1 -1
  40. package/dist/core/bash-executor.js.map +1 -1
  41. package/dist/core/tools/bash.d.ts +1 -1
  42. package/dist/core/tools/bash.d.ts.map +1 -1
  43. package/dist/core/tools/bash.js +3 -2
  44. package/dist/core/tools/bash.js.map +1 -1
  45. package/dist/core/tools/edit.d.ts +3 -0
  46. package/dist/core/tools/edit.d.ts.map +1 -1
  47. package/dist/core/tools/edit.js +91 -12
  48. package/dist/core/tools/edit.js.map +1 -1
  49. package/dist/core/tools/file-mutation-coordinator.d.ts +255 -0
  50. package/dist/core/tools/file-mutation-coordinator.d.ts.map +1 -0
  51. package/dist/core/tools/file-mutation-coordinator.js +300 -0
  52. package/dist/core/tools/file-mutation-coordinator.js.map +1 -0
  53. package/dist/core/tools/file-mutation-queue.d.ts +14 -1
  54. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  55. package/dist/core/tools/file-mutation-queue.js +15 -3
  56. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  57. package/dist/core/tools/hashline.d.ts +9 -0
  58. package/dist/core/tools/hashline.d.ts.map +1 -1
  59. package/dist/core/tools/hashline.js +12 -1
  60. package/dist/core/tools/hashline.js.map +1 -1
  61. package/dist/core/tools/index.d.ts +9 -1
  62. package/dist/core/tools/index.d.ts.map +1 -1
  63. package/dist/core/tools/index.js +67 -12
  64. package/dist/core/tools/index.js.map +1 -1
  65. package/dist/core/tools/non-minting-snapshot-store.d.ts +49 -0
  66. package/dist/core/tools/non-minting-snapshot-store.d.ts.map +1 -0
  67. package/dist/core/tools/non-minting-snapshot-store.js +64 -0
  68. package/dist/core/tools/non-minting-snapshot-store.js.map +1 -0
  69. package/dist/core/tools/powershell.d.ts +2 -2
  70. package/dist/core/tools/powershell.d.ts.map +1 -1
  71. package/dist/core/tools/powershell.js +2 -5
  72. package/dist/core/tools/powershell.js.map +1 -1
  73. package/dist/core/tools/read-document-extract.js.map +1 -1
  74. package/dist/core/tools/render-utils.js.map +1 -1
  75. package/dist/core/tools/write.d.ts +30 -1
  76. package/dist/core/tools/write.d.ts.map +1 -1
  77. package/dist/core/tools/write.js +97 -8
  78. package/dist/core/tools/write.js.map +1 -1
  79. package/dist/index.d.ts +1 -1
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  83. package/dist/modes/interactive/components/task-live-transcript.d.ts +1 -1
  84. package/dist/modes/interactive/components/task-live-transcript.d.ts.map +1 -1
  85. package/dist/modes/interactive/components/task-live-transcript.js +19 -11
  86. package/dist/modes/interactive/components/task-live-transcript.js.map +1 -1
  87. package/dist/modes/interactive/interactive-mode-base.d.ts +1 -0
  88. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  89. package/dist/modes/interactive/interactive-mode-base.js +3 -1
  90. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  91. package/dist/modes/interactive/interactive-mode-surface.d.ts +1 -1
  92. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  93. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  94. package/dist/modes/interactive/interactive-render-chat.js +28 -4
  95. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  96. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  97. package/dist/modes/interactive/interactive-startup.js +3 -0
  98. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  99. package/dist/modes/interactive-engine/activity-watchdog.d.ts +2 -2
  100. package/dist/modes/interactive-engine/activity-watchdog.d.ts.map +1 -1
  101. package/dist/modes/interactive-engine/activity-watchdog.js.map +1 -1
  102. package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts +3 -1
  103. package/dist/modes/interactive-engine/engine-diagnostic-view.d.ts.map +1 -1
  104. package/dist/modes/interactive-engine/engine-diagnostic-view.js +11 -0
  105. package/dist/modes/interactive-engine/engine-diagnostic-view.js.map +1 -1
  106. package/dist/modes/interactive-engine/isolated-runtime.js +2 -1
  107. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  108. package/dist/modes/rpc/rpc-client-process.d.ts +2 -0
  109. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  110. package/dist/modes/rpc/rpc-client-process.js +23 -1
  111. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  112. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  113. package/dist/modes/rpc/rpc-client.js +20 -3
  114. package/dist/modes/rpc/rpc-client.js.map +1 -1
  115. package/dist/utils/markit.d.ts +2 -0
  116. package/dist/utils/markit.d.ts.map +1 -1
  117. package/dist/utils/markit.js +65 -5
  118. package/dist/utils/markit.js.map +1 -1
  119. package/docs/background-tasks.md +15 -11
  120. package/docs/build.md +51 -0
  121. package/docs/changelog.mdx +8 -8
  122. package/docs/compaction/reference.md +267 -0
  123. package/docs/compaction.md +36 -219
  124. package/docs/computer-use.md +35 -0
  125. package/docs/containerization.md +9 -5
  126. package/docs/custom-provider/api-reference.md +145 -0
  127. package/docs/custom-provider/oauth.md +131 -0
  128. package/docs/custom-provider/override.md +34 -0
  129. package/docs/custom-provider/registration.md +163 -0
  130. package/docs/custom-provider/streaming.md +214 -0
  131. package/docs/custom-provider.md +43 -607
  132. package/docs/development.md +87 -0
  133. package/docs/docs.json +199 -76
  134. package/docs/environment-variables.md +1 -1
  135. package/docs/extensions/api-reference.md +1001 -0
  136. package/docs/extensions/authoring.md +676 -0
  137. package/docs/extensions/events.md +793 -0
  138. package/docs/extensions/examples.md +94 -0
  139. package/docs/extensions/ui.md +470 -0
  140. package/docs/extensions.md +270 -2768
  141. package/docs/getting-started/authentication.md +55 -0
  142. package/docs/getting-started/first-session.md +172 -0
  143. package/docs/getting-started/installation.md +154 -0
  144. package/docs/getting-started/project-instructions.md +43 -0
  145. package/docs/guides/configuration.md +65 -0
  146. package/docs/guides/intercom.md +24 -0
  147. package/docs/guides/non-interactive.md +33 -0
  148. package/docs/guides/subagents.md +24 -0
  149. package/docs/guides/workflows.md +27 -0
  150. package/docs/guides.md +41 -0
  151. package/docs/index.md +13 -45
  152. package/docs/intercom/operations.md +178 -0
  153. package/docs/intercom/reference.md +146 -0
  154. package/docs/intercom.md +54 -259
  155. package/docs/json.md +17 -0
  156. package/docs/llama-cpp.md +5 -0
  157. package/docs/models/artificial-analysis-index.md +89 -0
  158. package/docs/models/evals.md +2 -2
  159. package/docs/models/model-selection.md +3 -3
  160. package/docs/models/pareto-efficiency.md +2 -2
  161. package/docs/models/reference.md +601 -0
  162. package/docs/models.md +45 -550
  163. package/docs/packages/authoring.md +88 -0
  164. package/docs/packages/reference.md +43 -0
  165. package/docs/packages.md +28 -107
  166. package/docs/programmatic.md +29 -0
  167. package/docs/prompt-templates.md +11 -0
  168. package/docs/providers/reference.md +23 -0
  169. package/docs/providers.md +10 -15
  170. package/docs/quickstart.md +44 -238
  171. package/docs/reference/cli.md +252 -0
  172. package/docs/reference.md +52 -0
  173. package/docs/rpc/examples.md +64 -0
  174. package/docs/rpc/extension-ui.md +198 -0
  175. package/docs/rpc/protocol.md +1341 -0
  176. package/docs/rpc.md +109 -1346
  177. package/docs/sdk/reference.md +1090 -0
  178. package/docs/sdk.md +56 -1002
  179. package/docs/session-format.md +2 -0
  180. package/docs/sessions.md +6 -10
  181. package/docs/settings.md +6 -45
  182. package/docs/skills/authoring.md +95 -0
  183. package/docs/skills/reference.md +60 -0
  184. package/docs/skills.md +20 -122
  185. package/docs/subagents/authoring.md +37 -0
  186. package/docs/subagents/reference.md +60 -0
  187. package/docs/subagents.md +42 -96
  188. package/docs/terminal-setup.md +1 -1
  189. package/docs/themes/reference.md +176 -0
  190. package/docs/themes.md +21 -135
  191. package/docs/tmux.md +5 -0
  192. package/docs/tools/edit.md +5 -0
  193. package/docs/tools.md +31 -0
  194. package/docs/tui/reference.md +343 -0
  195. package/docs/tui.md +23 -286
  196. package/docs/usage.md +26 -209
  197. package/docs/web-access.md +40 -0
  198. package/docs/windows.md +2 -1
  199. package/docs/workflows/api-reference.md +11 -4
  200. package/docs/workflows/authoring.md +4 -2
  201. package/docs/workflows/builtins.md +2 -2
  202. package/docs/workflows/operations.md +11 -7
  203. package/docs/workflows/reliable-design.md +21 -3
  204. package/docs/workflows/verification.md +8 -0
  205. package/examples/extensions/gondolin/index.ts +116 -148
  206. package/examples/extensions/gondolin/package.json +1 -1
  207. package/examples/extensions/ssh.ts +56 -34
  208. package/npm-shrinkwrap.json +33 -33
  209. package/package.json +4 -4
@@ -0,0 +1,214 @@
1
+ ---
2
+ title: Provider streaming API
3
+ description: "Implement a custom streaming API: events, content blocks, tool calls, stop reasons, and usage."
4
+ ---
5
+
6
+ # Provider streaming API
7
+
8
+ ## Custom Streaming API
9
+
10
+ For providers with non-standard APIs, implement `streamSimple`. Study the existing API implementations before writing your own:
11
+
12
+ **Reference implementations:**
13
+
14
+ Atomic uses provider implementations from its installed `@bastani/pi-ai` dependency. The streaming implementations behind the `api` field live under `node_modules/@bastani/pi-ai/dist/api/`, including:
15
+ - `anthropic-messages.d.ts` / `anthropic-messages.js` - Anthropic Messages API
16
+ - `mistral-conversations.d.ts` / `mistral-conversations.js` - Mistral Conversations/Chat streaming
17
+ - `openai-completions.d.ts` / `openai-completions.js` - OpenAI Chat Completions
18
+ - `openai-responses.d.ts` / `openai-responses.js` - OpenAI Responses API
19
+ - `google-generative-ai.d.ts` / `google-generative-ai.js` - Google Generative AI
20
+ - `bedrock-converse-stream.d.ts` / `bedrock-converse-stream.js` - Amazon Bedrock Converse API
21
+ Per-vendor provider configurations (base URLs, auth, model catalogs) live under `dist/providers/`, for example `anthropic.d.ts` / `anthropic.js` and `mistral.d.ts` / `mistral.js`.
22
+
23
+ ### Stream Pattern
24
+
25
+ All providers follow the same pattern:
26
+
27
+ ```typescript
28
+ import {
29
+ type AssistantMessage,
30
+ type AssistantMessageEventStream,
31
+ type Context,
32
+ type Model,
33
+ type SimpleStreamOptions,
34
+ calculateCost,
35
+ createAssistantMessageEventStream,
36
+ } from "@bastani/pi-ai";
37
+
38
+ function streamMyProvider(
39
+ model: Model<any>,
40
+ context: Context,
41
+ options?: SimpleStreamOptions
42
+ ): AssistantMessageEventStream {
43
+ const stream = createAssistantMessageEventStream();
44
+
45
+ (async () => {
46
+ // Initialize output message
47
+ const output: AssistantMessage = {
48
+ role: "assistant",
49
+ content: [],
50
+ api: model.api,
51
+ provider: model.provider,
52
+ model: model.id,
53
+ usage: {
54
+ input: 0,
55
+ output: 0,
56
+ cacheRead: 0,
57
+ cacheWrite: 0,
58
+ totalTokens: 0,
59
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
60
+ },
61
+ stopReason: "pending",
62
+ timestamp: Date.now(),
63
+ };
64
+
65
+ try {
66
+ // Push start event
67
+ stream.push({ type: "start", partial: output });
68
+
69
+ // Make API request and process response...
70
+ // Push content events as they arrive, and set output.stopReason from the
71
+ // terminal event. A reason your provider sends that you do not map must
72
+ // become an error, not a silent "stop".
73
+ if (output.stopReason === "pending") {
74
+ throw new Error("Provider stream ended without a stop reason");
75
+ }
76
+ if (output.stopReason === "error" || output.stopReason === "aborted") {
77
+ throw new Error(output.errorMessage || "An unknown error occurred");
78
+ }
79
+
80
+ // Push done event
81
+ stream.push({
82
+ type: "done",
83
+ reason: output.stopReason,
84
+ message: output
85
+ });
86
+ stream.end();
87
+ } catch (error) {
88
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
89
+ output.errorMessage = error instanceof Error ? error.message : String(error);
90
+ stream.push({ type: "error", reason: output.stopReason, error: output });
91
+ stream.end();
92
+ }
93
+ })();
94
+
95
+ return stream;
96
+ }
97
+ ```
98
+
99
+ ### Event Types
100
+
101
+ Push events via `stream.push()` in this order:
102
+
103
+ 1. `{ type: "start", partial: output }` - Stream started
104
+
105
+ 2. Content events (repeatable, track `contentIndex` for each block):
106
+ - `{ type: "text_start", contentIndex, partial }` - Text block started
107
+ - `{ type: "text_delta", contentIndex, delta, partial }` - Text chunk
108
+ - `{ type: "text_end", contentIndex, content, partial }` - Text block ended
109
+ - `{ type: "thinking_start", contentIndex, partial }` - Thinking started
110
+ - `{ type: "thinking_delta", contentIndex, delta, partial }` - Thinking chunk
111
+ - `{ type: "thinking_end", contentIndex, content, partial }` - Thinking ended
112
+ - `{ type: "toolcall_start", contentIndex, partial }` - Tool call started
113
+ - `{ type: "toolcall_delta", contentIndex, delta, partial }` - Tool call JSON chunk
114
+ - `{ type: "toolcall_end", contentIndex, toolCall, partial }` - Tool call ended
115
+
116
+ 3. `{ type: "done", reason, message }` or `{ type: "error", reason, error }` - Stream ended
117
+
118
+ The `partial` field in each event contains the current `AssistantMessage` state. Update `output.content` as you receive data, then include `output` as the `partial`.
119
+
120
+ ### Stop Reasons
121
+
122
+ `StopReason` is `"pending" | "stop" | "length" | "toolUse" | "error" | "aborted"`.
123
+
124
+ Start the partial message at `"pending"`. It is the reason every in-flight message carries, and it says the terminal event has not arrived yet — it is not a default standing in for `"stop"`. Set the real reason when the provider says the turn ended, then push `done` with it.
125
+
126
+ Two checks belong immediately before `done`:
127
+
128
+ - a stream that reached the end while still `"pending"` never received a terminal event, so raise rather than report a stop that did not happen;
129
+ - `"error"` and `"aborted"` are failures, so raise them with `output.errorMessage` and let the `catch` push an `error` event.
130
+
131
+ `done` accepts only `"stop"`, `"length"`, and `"toolUse"`, which is exactly what those two checks leave, so the `as "stop" | "length" | "toolUse"` cast older implementations used is no longer needed.
132
+
133
+ Map each raw reason your provider can send onto one of the five terminal values, and **raise on one you do not recognise** rather than falling back to `"stop"`. This is what the built-in providers do: an unmapped reason becomes a provider error naming the raw value, so a new truncation or safety signal is visible instead of arriving as a turn that looks like it finished normally. The optional `rawStopReason` field on `AssistantMessage` is where the provider's own string belongs when you want to keep it.
134
+
135
+ ### Content Blocks
136
+
137
+ Add content blocks to `output.content` as they arrive:
138
+
139
+ ```typescript
140
+ // Text block
141
+ output.content.push({ type: "text", text: "" });
142
+ stream.push({ type: "text_start", contentIndex: output.content.length - 1, partial: output });
143
+
144
+ // As text arrives
145
+ const block = output.content[contentIndex];
146
+ if (block.type === "text") {
147
+ block.text += delta;
148
+ stream.push({ type: "text_delta", contentIndex, delta, partial: output });
149
+ }
150
+
151
+ // When block completes
152
+ stream.push({ type: "text_end", contentIndex, content: block.text, partial: output });
153
+ ```
154
+
155
+ ### Tool Calls
156
+
157
+ Tool calls require accumulating JSON and parsing:
158
+
159
+ ```typescript
160
+ // Start tool call
161
+ output.content.push({
162
+ type: "toolCall",
163
+ id: toolCallId,
164
+ name: toolName,
165
+ arguments: {}
166
+ });
167
+ stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
168
+
169
+ // Accumulate JSON
170
+ let partialJson = "";
171
+ partialJson += jsonDelta;
172
+ try {
173
+ block.arguments = JSON.parse(partialJson);
174
+ } catch {}
175
+ stream.push({ type: "toolcall_delta", contentIndex, delta: jsonDelta, partial: output });
176
+
177
+ // Complete
178
+ stream.push({
179
+ type: "toolcall_end",
180
+ contentIndex,
181
+ toolCall: { type: "toolCall", id, name, arguments: block.arguments },
182
+ partial: output
183
+ });
184
+ ```
185
+
186
+ ### Usage and Cost
187
+
188
+ Update usage from API response and calculate cost:
189
+
190
+ ```typescript
191
+ output.usage.input = response.usage.input_tokens;
192
+ output.usage.output = response.usage.output_tokens;
193
+ output.usage.cacheRead = response.usage.cache_read_tokens ?? 0;
194
+ output.usage.cacheWrite = response.usage.cache_write_tokens ?? 0;
195
+ output.usage.totalTokens = output.usage.input + output.usage.output +
196
+ output.usage.cacheRead + output.usage.cacheWrite;
197
+ calculateCost(model, output.usage);
198
+ ```
199
+
200
+ `calculateCost()` selects one rate set for the whole request. Aggregate input is `usage.input + usage.cacheRead + usage.cacheWrite`; a tier applies only when that sum is strictly greater than `inputTokensAbove`, and the matching tier with the highest threshold wins. Every tier must provide complete `input`, `output`, `cacheRead`, and `cacheWrite` rates. Extension-registered models preserve these tiers, and matching `models.json` `modelOverrides` use the same replacement rules described in [Custom Models](/models/reference#request-wide-cost-tiers).
201
+
202
+ ### Registration
203
+
204
+ Register your stream function:
205
+
206
+ ```typescript
207
+ pi.registerProvider("my-provider", {
208
+ baseUrl: "https://api.example.com",
209
+ apiKey: "$MY_API_KEY",
210
+ api: "my-custom-api",
211
+ models: [...],
212
+ streamSimple: streamMyProvider
213
+ });
214
+ ```