@bastani/atomic 0.10.14-alpha.1 → 0.10.15-alpha.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.
- package/CHANGELOG.md +29 -0
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +3 -3
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +3 -3
- package/dist/_shared/mode-shared-2QJSCUM6.js +3 -3
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/runtime-O4KCSG4C.js +2 -2
- package/dist/_shared/{sdk-B5LEWGGI.js → sdk-OHKMDJ74.js} +27 -5
- package/dist/_shared/{sdk-B5LEWGGI.js.map → sdk-OHKMDJ74.js.map} +1 -1
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/startup-0-0-Q3MWKUK4.js +2 -2
- package/dist/_shared/startup-0-1-M6OWAYHH.js +2 -2
- package/dist/_shared/{startup-0-2-5QHPCEON.js → startup-0-2-2HUMCPKX.js} +14 -16
- package/dist/_shared/startup-0-2-2HUMCPKX.js.map +1 -0
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +3 -3
- package/dist/_shared/startup-0-4-ZMJV547D.js +3 -3
- package/dist/_shared/startup-0-5-YDW47QX6.js +3 -3
- package/dist/_shared/startup-10-0-TDQNBDDL.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +6 -30
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +3 -3
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +3 -3
- package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
- package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/auth-cli.code.js +1 -1
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +1 -1
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/compaction/compactor.d.ts +0 -8
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +2 -2
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/sdk.code.js +1 -1
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +3 -3
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/node-sqlite-thread.js +2 -2
- package/dist/core/storage/node-sqlite.js +2 -2
- package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
- package/dist/core/storage/offline-snapshot-file.js +3 -3
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +2 -2
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +2 -2
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +1 -1
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-window.code.js +2 -2
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +2 -2
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +1 -1
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +2 -2
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.code.js +1 -1
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +2 -2
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +2 -2
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.js +2 -2
- package/dist/core/worktree-snapshot/errors.code.js +1 -1
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +1 -1
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.d.ts +21 -1
- package/dist/index.js +2 -2
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +2 -2
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/6.js +1 -1
- package/dist/utils/startup-database-spare.code.js +1 -1
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/background-tasks/reference.md +182 -0
- package/docs/background-tasks.md +98 -405
- package/docs/build.md +67 -27
- package/docs/changelog.mdx +9 -0
- package/docs/codemode.md +108 -39
- package/docs/compaction/branch-summaries.md +54 -0
- package/docs/compaction/custom-compactors.md +161 -0
- package/docs/compaction/memory-compaction.md +77 -0
- package/docs/compaction/reference.md +86 -38
- package/docs/compaction.md +51 -252
- package/docs/computer-use.md +169 -321
- package/docs/containerization.md +71 -57
- package/docs/custom-provider/api-reference.md +119 -25
- package/docs/custom-provider/oauth.md +114 -132
- package/docs/custom-provider/override.md +37 -27
- package/docs/custom-provider/registration.md +107 -83
- package/docs/custom-provider/streaming.md +85 -71
- package/docs/custom-provider.md +85 -52
- package/docs/development.md +39 -29
- package/docs/docs.json +76 -63
- package/docs/environment-variables.md +94 -44
- package/docs/extensions/api-reference.md +86 -43
- package/docs/extensions/authoring.md +162 -154
- package/docs/extensions/events.md +80 -25
- package/docs/extensions/examples.md +90 -85
- package/docs/extensions/ui.md +206 -82
- package/docs/extensions.md +79 -108
- package/docs/getting-started/authentication.md +67 -36
- package/docs/getting-started/first-session.md +53 -43
- package/docs/getting-started/installation.md +116 -89
- package/docs/getting-started/project-instructions.md +48 -34
- package/docs/guides/configuration.md +82 -20
- package/docs/guides/non-interactive.md +66 -24
- package/docs/guides/resume-on-any-machine.md +135 -82
- package/docs/guides/team-setup.md +114 -105
- package/docs/guides.md +76 -32
- package/docs/herdr.md +15 -16
- package/docs/how-atomic-works.md +140 -0
- package/docs/index.md +58 -44
- package/docs/intercom/operations.md +141 -151
- package/docs/intercom/reference.md +85 -108
- package/docs/intercom.md +84 -145
- package/docs/json.md +120 -67
- package/docs/keybindings.md +85 -49
- package/docs/libraries/agent-core.md +137 -275
- package/docs/libraries/ai.md +100 -84
- package/docs/libraries/codemode.md +210 -300
- package/docs/libraries/schema.md +59 -53
- package/docs/libraries/storage-postgres.md +49 -35
- package/docs/libraries/telemetry.md +153 -354
- package/docs/libraries/tui.md +265 -393
- package/docs/libraries.md +42 -26
- package/docs/llama-cpp.md +171 -161
- package/docs/mcp-servers.md +90 -51
- package/docs/models/choose-a-model.md +188 -0
- package/docs/models/reference.md +74 -30
- package/docs/models.md +153 -88
- package/docs/orchestration/migrating-workflows.md +23 -16
- package/docs/orchestration/patterns.md +39 -44
- package/docs/orchestration.md +65 -26
- package/docs/packages/authoring.md +51 -29
- package/docs/packages/reference.md +42 -21
- package/docs/packages.md +69 -58
- package/docs/programmatic.md +118 -24
- package/docs/prompt-templates.md +84 -83
- package/docs/providers/reference.md +43 -48
- package/docs/providers.md +219 -451
- package/docs/quickstart.md +140 -120
- package/docs/reference/cli.md +135 -97
- package/docs/reference.md +20 -18
- package/docs/rpc/examples.md +76 -20
- package/docs/rpc/extension-ui.md +64 -38
- package/docs/rpc/protocol.md +361 -110
- package/docs/rpc.md +57 -17
- package/docs/sdk/reference.md +409 -534
- package/docs/sdk/storage.md +53 -13
- package/docs/sdk/structured-decisions.md +82 -56
- package/docs/sdk/web-server.md +57 -43
- package/docs/sdk.md +106 -84
- package/docs/security.md +42 -64
- package/docs/session-format.md +62 -38
- package/docs/sessions.md +99 -214
- package/docs/settings.md +165 -195
- package/docs/shell-aliases.md +9 -6
- package/docs/skills/authoring.md +69 -48
- package/docs/skills/reference.md +51 -20
- package/docs/skills.md +99 -148
- package/docs/slash-commands.md +129 -0
- package/docs/storage/custom-adapters.md +160 -85
- package/docs/storage/jsonl.md +81 -66
- package/docs/storage/postgres/pgbouncer.md +120 -126
- package/docs/storage/postgres/tuning.md +120 -143
- package/docs/storage/postgres.md +314 -330
- package/docs/storage/sqlite.md +71 -42
- package/docs/storage.md +298 -302
- package/docs/subagents/authoring.md +55 -38
- package/docs/subagents/reference.md +73 -33
- package/docs/subagents.md +119 -187
- package/docs/terminal-setup.md +50 -38
- package/docs/termux.md +67 -41
- package/docs/themes/reference.md +23 -19
- package/docs/themes.md +142 -127
- package/docs/tmux.md +47 -55
- package/docs/tools.md +147 -109
- package/docs/tui/reference.md +166 -214
- package/docs/tui.md +196 -341
- package/docs/usage.md +118 -138
- package/docs/verification.md +79 -51
- package/docs/web-access.md +121 -101
- package/docs/windows.md +26 -27
- package/docs/worktree-snapshots/reference.md +245 -0
- package/docs/worktree-snapshots.md +71 -259
- package/package.json +8 -8
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +0 -1
- package/docs/guides/intercom.md +0 -32
- package/docs/guides/orchestration.md +0 -28
- package/docs/guides/subagents.md +0 -37
|
@@ -1,12 +1,45 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Register a custom provider"
|
|
3
|
-
sidebarTitle: "Register
|
|
4
|
-
description: "
|
|
3
|
+
sidebarTitle: "Register a Provider"
|
|
4
|
+
description: "Register custom providers with static or discovered models, pick a streaming API, create multi-account aliases, and unregister providers."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Register a custom provider when you want to add models dynamically at startup, attach custom handlers or authentication, or expose multiple accounts for the same provider. All registrations should be awaited inside your `async` extension factory so Atomic discovers them before the session starts.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Static and dynamic model registration {#register-new-provider}
|
|
10
|
+
|
|
11
|
+
Start with a static model definition alongside `baseUrl`, `apiKey`, and `api`:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import type { ExtensionAPI } from "@bastani/atomic";
|
|
15
|
+
|
|
16
|
+
export default async function (atomic: ExtensionAPI) {
|
|
17
|
+
await atomic.registerProvider("my-llm", {
|
|
18
|
+
name: "My LLM",
|
|
19
|
+
baseUrl: "https://api.my-llm.com/v1",
|
|
20
|
+
apiKey: "$MY_LLM_API_KEY", // supports $ENV_VAR, ${ENV_VAR}, !command, or literal values
|
|
21
|
+
api: "openai-completions", // built-in streaming API implementation
|
|
22
|
+
models: [
|
|
23
|
+
{
|
|
24
|
+
id: "my-llm-large",
|
|
25
|
+
name: "My LLM Large",
|
|
26
|
+
reasoning: true,
|
|
27
|
+
input: ["text", "image"],
|
|
28
|
+
cost: {
|
|
29
|
+
input: 3.0, // USD per million tokens
|
|
30
|
+
output: 15.0,
|
|
31
|
+
cacheRead: 0.3,
|
|
32
|
+
cacheWrite: 3.75,
|
|
33
|
+
},
|
|
34
|
+
contextWindow: 200000,
|
|
35
|
+
maxTokens: 16384,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For servers whose available models change at runtime, fetch the list inside the `async` extension factory so startup waits before building the model picker:
|
|
10
43
|
|
|
11
44
|
```typescript
|
|
12
45
|
import type { ExtensionAPI } from "@bastani/atomic";
|
|
@@ -39,102 +72,88 @@ export default async function (atomic: ExtensionAPI) {
|
|
|
39
72
|
}
|
|
40
73
|
```
|
|
41
74
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
await atomic.registerProvider("my-llm", {
|
|
46
|
-
baseUrl: "https://api.my-llm.com/v1",
|
|
47
|
-
apiKey: "$MY_LLM_API_KEY", // supports $ENV_VAR, ${ENV_VAR}, !command, or literal values
|
|
48
|
-
api: "openai-completions", // streaming API implementation
|
|
49
|
-
models: [
|
|
50
|
-
{
|
|
51
|
-
id: "my-llm-large",
|
|
52
|
-
name: "My LLM Large",
|
|
53
|
-
reasoning: true,
|
|
54
|
-
input: ["text", "image"],
|
|
55
|
-
cost: {
|
|
56
|
-
input: 3.0, // USD per million tokens
|
|
57
|
-
output: 15.0,
|
|
58
|
-
cacheRead: 0.3,
|
|
59
|
-
cacheWrite: 3.75
|
|
60
|
-
},
|
|
61
|
-
contextWindow: 200000,
|
|
62
|
-
maxTokens: 16384
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
});
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Providing `models` replaces all existing chat, image, classifier, and compactor models for that provider. Omitting `type` registers a chat model; image and classifier models require `type: "image"` or `type: "classifier"` plus handlers in `images` or `classifiers`; compactor models use `type: "compactor"` (`ProviderCompactorModelConfig`, see [Compactor request contract](/compaction/reference#compactor-request-contract)). See the [mixed-operation provider example](/custom-provider#mixed-operation-providers).
|
|
75
|
+
Providing `models` replaces all existing chat, image, classifier, and compactor models for that provider. Omitting `type` registers a chat model; image and classifier models require `type: "image"` or `type: "classifier"` plus matching handlers in `images` or `classifiers`; compactor models use `type: "compactor"` (`ProviderCompactorModelConfig`, see [Compactor request contract](/compaction/reference#compactor-request-contract)). See the [mixed-operation provider example](/custom-provider#mixed-operation-providers).
|
|
69
76
|
|
|
70
|
-
Registered providers appear in `/login`
|
|
77
|
+
Registered providers appear in `/login` alongside built-in providers: `/login my-llm` prompts for an API key, saves it in `auth.json`, and displays configured status (such as `✓ env: MY_LLM_API_KEY`). Once credentials are configured, `/model` lists the provider's models; selecting a model without credentials reports `No API key found for my-llm` with a `/login` hint. See [Credential resolution order](/providers/reference#resolution-order).
|
|
71
78
|
|
|
72
79
|
### API types
|
|
73
80
|
|
|
74
|
-
The `api` field selects
|
|
81
|
+
The `api` field selects one of Atomic's built-in chat streaming protocols:
|
|
75
82
|
|
|
76
83
|
| API | Use for |
|
|
77
84
|
| --- | --- |
|
|
78
|
-
| `
|
|
79
|
-
| `openai-completions` | OpenAI Chat Completions API and compatibles |
|
|
85
|
+
| `openai-completions` | OpenAI Chat Completions API and most OpenAI-compatible servers |
|
|
80
86
|
| `openai-responses` | OpenAI Responses API |
|
|
81
87
|
| `azure-openai-responses` | Azure OpenAI Responses API |
|
|
82
88
|
| `openai-codex-responses` | OpenAI Codex Responses API |
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
89
|
+
| `anthropic-messages` | Anthropic Claude Messages API and compatibles |
|
|
90
|
+
| `mistral-conversations` | Native Mistral Conversations and Chat streaming |
|
|
91
|
+
| `google-generative-ai` | Google Generative AI (Gemini API) |
|
|
85
92
|
| `google-vertex` | Google Vertex AI API |
|
|
86
93
|
| `bedrock-converse-stream` | Amazon Bedrock Converse API |
|
|
87
|
-
| `pi-messages` | Custom gateways speaking
|
|
94
|
+
| `pi-messages` | Custom gateways speaking Atomic's native `pi-messages` protocol |
|
|
88
95
|
|
|
89
|
-
Image (`images`) and classifier (`classifiers`) handlers use their own operation-specific `api` keys independent of this
|
|
96
|
+
Image (`images`) and classifier (`classifiers`) handlers use their own operation-specific `api` keys independent of this table. Compactor models (`type: "compactor"`) declare a compactor `api` string at model or provider level and follow the [Compactor request contract](/compaction/reference#compactor-request-contract).
|
|
90
97
|
|
|
91
|
-
Most OpenAI-compatible servers use `openai-completions`. Configure model-specific thinking controls with `thinkingLevelMap` and
|
|
98
|
+
Most OpenAI-compatible servers use `openai-completions`. Configure model-specific thinking controls with `thinkingLevelMap` and server quirks with `compat`:
|
|
92
99
|
|
|
93
100
|
```typescript
|
|
94
|
-
models: [
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
models: [
|
|
102
|
+
{
|
|
103
|
+
id: "custom-model",
|
|
104
|
+
name: "Custom Model",
|
|
105
|
+
reasoning: true,
|
|
106
|
+
input: ["text"],
|
|
107
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
108
|
+
contextWindow: 128000,
|
|
109
|
+
maxTokens: 16384,
|
|
110
|
+
thinkingLevelMap: { // Map Atomic thinking levels; null hides unsupported levels
|
|
111
|
+
minimal: null,
|
|
112
|
+
low: null,
|
|
113
|
+
medium: null,
|
|
114
|
+
high: "default",
|
|
115
|
+
xhigh: null,
|
|
116
|
+
max: "max",
|
|
117
|
+
},
|
|
118
|
+
compat: {
|
|
119
|
+
supportsDeveloperRole: false,
|
|
120
|
+
supportsReasoningEffort: true,
|
|
121
|
+
maxTokensField: "max_tokens",
|
|
122
|
+
requiresToolResultName: true,
|
|
123
|
+
thinkingFormat: "qwen",
|
|
124
|
+
cacheControlFormat: "anthropic",
|
|
125
|
+
},
|
|
109
126
|
},
|
|
110
|
-
|
|
111
|
-
supportsDeveloperRole: false,
|
|
112
|
-
supportsReasoningEffort: true,
|
|
113
|
-
maxTokensField: "max_tokens",
|
|
114
|
-
requiresToolResultName: true,
|
|
115
|
-
thinkingFormat: "qwen",
|
|
116
|
-
cacheControlFormat: "anthropic"
|
|
117
|
-
}
|
|
118
|
-
}]
|
|
127
|
+
]
|
|
119
128
|
```
|
|
120
129
|
|
|
121
130
|
See [Compatibility fields](/models-configuration#compatibility) for every `compat` option (`thinkingFormat`, `cacheControlFormat`, session affinity, and tool flags). Use `mistral-conversations` for native Mistral endpoints; if routing a Mistral-compatible endpoint through `openai-completions`, configure `compat` flags explicitly.
|
|
122
131
|
|
|
123
132
|
### Auth header
|
|
124
133
|
|
|
125
|
-
Set `authHeader: true` when an endpoint expects `Authorization: Bearer <key>`
|
|
134
|
+
Set `authHeader: true` when an endpoint expects `Authorization: Bearer <key>` derived from the resolved `apiKey`:
|
|
126
135
|
|
|
127
136
|
```typescript
|
|
128
137
|
await atomic.registerProvider("custom-api", {
|
|
129
|
-
baseUrl: "https://api.example.com",
|
|
138
|
+
baseUrl: "https://api.example.com/v1",
|
|
130
139
|
apiKey: "$MY_API_KEY",
|
|
131
140
|
authHeader: true,
|
|
132
141
|
api: "openai-completions",
|
|
133
|
-
models: [
|
|
142
|
+
models: [
|
|
143
|
+
{
|
|
144
|
+
id: "custom-chat",
|
|
145
|
+
name: "Custom Chat",
|
|
146
|
+
reasoning: false,
|
|
147
|
+
input: ["text"],
|
|
148
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
149
|
+
contextWindow: 128000,
|
|
150
|
+
maxTokens: 4096,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
134
153
|
});
|
|
135
154
|
```
|
|
136
155
|
|
|
137
|
-
If `authHeader: true` is set and
|
|
156
|
+
If `authHeader: true` is set and no API key resolves (for example, `$MY_API_KEY` is unset and no key is saved in `auth.json`), requests fail with a missing API key error.
|
|
138
157
|
|
|
139
158
|
## Multiple accounts for one provider
|
|
140
159
|
|
|
@@ -144,7 +163,7 @@ Use `atomic.registerProviderAlias()` to reuse an existing provider's models, OAu
|
|
|
144
163
|
import type { ExtensionAPI } from "@bastani/atomic";
|
|
145
164
|
|
|
146
165
|
export default async function (atomic: ExtensionAPI) {
|
|
147
|
-
for (let account = 1; account <=
|
|
166
|
+
for (let account = 1; account <= 3; account++) {
|
|
148
167
|
await atomic.registerProviderAlias({
|
|
149
168
|
id: `openai-${account}`,
|
|
150
169
|
name: `OpenAI account ${account}`,
|
|
@@ -154,25 +173,30 @@ export default async function (atomic: ExtensionAPI) {
|
|
|
154
173
|
}
|
|
155
174
|
```
|
|
156
175
|
|
|
157
|
-
Run `/login openai-1`, choose **
|
|
176
|
+
Run `/login openai-1`, choose **Use a subscription** (for ChatGPT sign-in on OpenAI's Responses API) or **Use an API key**, and select an `openai-1` model in `/model`. Repeat for each alias.
|
|
158
177
|
|
|
159
|
-
|
|
178
|
+
<Note>
|
|
179
|
+
Confirm the intended account in your browser during login. An alias only isolates stored credentials in `auth.json` — it does not select an account automatically or increase provider quota.
|
|
180
|
+
</Note>
|
|
160
181
|
|
|
161
|
-
|
|
182
|
+
How aliases behave:
|
|
162
183
|
|
|
163
|
-
|
|
184
|
+
- **Isolated credentials.** Each alias stores and refreshes its own credentials without borrowing the source's stored login or ambient environment keys. Keeping the same alias ID preserves saved credentials.
|
|
185
|
+
- **Supported auth types.** Aliases work with OAuth logins and non-empty stored API keys. For ambient-only authentication (such as an AWS profile or environment-based service account), use the original provider or register a full custom provider instead.
|
|
186
|
+
- **Inherited configuration.** Aliases inherit the source's endpoint, shared headers, models, derived Fast variants, OAuth callbacks, and request handling. Do not hard-code account secrets in source headers; supply per-account credentials through `/login`. Saved messages and callbacks keep the alias ID.
|
|
187
|
+
- **Catalog updates.** Source catalog updates are shared across aliases while availability filters run per alias credential. Aliases do not run separate catalog discovery, except `github-copilot` aliases, which refresh their own account's model list independently.
|
|
164
188
|
|
|
165
189
|
Validation rules for `registerProviderAlias()`:
|
|
166
190
|
|
|
167
191
|
- `id` and `provider` must be distinct, non-empty strings.
|
|
168
|
-
- `id` cannot match any built-in provider, `models.json` provider, or existing non-alias extension provider
|
|
169
|
-
- `provider` must already be registered and
|
|
170
|
-
- `registerProviderAlias({ id, name, provider })` is shorthand for `registerProvider(id, { aliasOf: provider, name })`.
|
|
171
|
-
-
|
|
192
|
+
- `id` cannot match any built-in provider, `models.json` provider, or existing non-alias extension provider.
|
|
193
|
+
- `provider` must already be registered and must point directly to a source provider, never to another alias.
|
|
194
|
+
- `registerProviderAlias({ id, name, provider })` is shorthand for `registerProvider(id, { aliasOf: provider, name })`. Only `aliasOf` and optional `name` are allowed on an alias; configure endpoints, headers, and `models.json` overrides on the source provider instead.
|
|
195
|
+
- Calling `await atomic.unregisterProvider("openai-1")` removes the alias without deleting its saved credentials in `auth.json`.
|
|
172
196
|
|
|
173
197
|
## Unregister a provider {#unregister-provider}
|
|
174
198
|
|
|
175
|
-
Call `atomic.unregisterProvider(name)` to remove a provider registered with `
|
|
199
|
+
Call `await atomic.unregisterProvider(name)` to remove a provider registered with `registerProvider()` or `registerProviderAlias()`:
|
|
176
200
|
|
|
177
201
|
```typescript
|
|
178
202
|
await atomic.registerProvider("my-llm", {
|
|
@@ -187,13 +211,13 @@ await atomic.registerProvider("my-llm", {
|
|
|
187
211
|
input: ["text", "image"],
|
|
188
212
|
cost: { input: 3.0, output: 15.0, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
189
213
|
contextWindow: 200000,
|
|
190
|
-
maxTokens: 16384
|
|
191
|
-
}
|
|
192
|
-
]
|
|
214
|
+
maxTokens: 16384,
|
|
215
|
+
},
|
|
216
|
+
],
|
|
193
217
|
});
|
|
194
218
|
|
|
195
|
-
// Remove later without
|
|
219
|
+
// Remove later without running /reload
|
|
196
220
|
await atomic.unregisterProvider("my-llm");
|
|
197
221
|
```
|
|
198
222
|
|
|
199
|
-
Unregistering removes the provider's dynamic models, API key fallback, OAuth registration, and custom stream handlers, restoring any
|
|
223
|
+
Unregistering removes the provider's dynamic models, API key fallback, OAuth registration, and custom stream handlers, restoring any built-in provider it overrode. Calls made after startup take effect immediately without `/reload`, and if the active session is using a model from the removed provider, Atomic refreshes the active model immediately. Calling `unregisterProvider()` for an unknown provider is a safe no-op.
|
|
@@ -1,47 +1,56 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Implement provider streaming"
|
|
3
|
-
sidebarTitle: "Streaming
|
|
3
|
+
sidebarTitle: "Implement Streaming"
|
|
4
4
|
description: "Build a custom streamSimple handler with stream events, content blocks, tool calls, stop reasons, and cost calculation."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
When a provider uses a protocol that none of Atomic's built-in APIs speak, supply a `streamSimple` handler in `atomic.registerProvider()`. Your handler converts upstream chunks into normalized Atomic stream events so the UI, retries, compaction, and tool execution work identically to built-in providers.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<Steps>
|
|
10
|
+
<Step title="Create the event stream and output message">
|
|
11
|
+
Construct an `AssistantMessageEventStream` via `createAssistantMessageEventStream()` and initialize an `AssistantMessage` with `stopReason: "pending"`, `timestamp: Date.now()`, and zeroed `usage`.
|
|
12
|
+
</Step>
|
|
13
|
+
<Step title="Emit start and send the request">
|
|
14
|
+
Push `{ type: "start", partial: output }`, read the system prompt and tools from `context.messages`, and open the upstream request while forwarding `options?.signal`.
|
|
15
|
+
</Step>
|
|
16
|
+
<Step title="Stream content blocks">
|
|
17
|
+
Append text, thinking, and tool-call blocks to `output.content` and push matching `*_start`, `*_delta`, and `*_end` events as chunks arrive.
|
|
18
|
+
</Step>
|
|
19
|
+
<Step title="Compute usage and map the stop reason">
|
|
20
|
+
Populate `output.usage`, call `calculateCost(model, output.usage)`, and map the provider's terminal finish reason onto Atomic's `StopReason` union (throwing on unrecognized values).
|
|
21
|
+
</Step>
|
|
22
|
+
<Step title="Emit done or error and end the stream">
|
|
23
|
+
Push `{ type: "done", reason, message: output }` on success — or `{ type: "error", reason, error: output }` in `catch` — then call `stream.end()`.
|
|
24
|
+
</Step>
|
|
25
|
+
</Steps>
|
|
10
26
|
|
|
11
|
-
|
|
12
|
-
- `mistral-conversations.ts`: Mistral Conversations and Chat streaming
|
|
13
|
-
- `openai-completions.ts`: OpenAI Chat Completions
|
|
14
|
-
- `openai-responses.ts`: OpenAI Responses API
|
|
15
|
-
- `google-generative-ai.ts`: Google Generative AI
|
|
16
|
-
- `bedrock-converse-stream.ts`: Amazon Bedrock Converse API
|
|
27
|
+
## Stream pattern
|
|
17
28
|
|
|
18
|
-
|
|
29
|
+
Return a stream created by `createAssistantMessageEventStream()` (or `new AssistantMessageEventStream()`). A plain `EventStream` subclass does not satisfy Atomic's response stream contract.
|
|
19
30
|
|
|
20
|
-
|
|
31
|
+
`AssistantMessageEventStream` automatically fills `output.durationMs` using a monotonic clock when you push `done` or `error`. Set `timestamp: Date.now()` when the request starts; existing durations are preserved, and messages whose timestamps predate the stream (such as fetched deferred results) remain untimed.
|
|
21
32
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Note on context types: `@bastani/atomic-ai` types the `context` argument as `TranscriptContext`, while `ProviderConfig.streamSimple` uses the compatible `Context` alias; both pass the normalized message transcript where `getCurrentSystemPrompt(context.messages)` and `getCurrentTools(context.messages)` read the active system prompt and tools.
|
|
33
|
+
<Note>
|
|
34
|
+
`ProviderConfig.streamSimple` types `context` as `Context`, and Atomic passes a normalized transcript where `getCurrentSystemPrompt(context.messages)` and `getCurrentTools(context.messages)` resolve the active system prompt and tool definitions.
|
|
35
|
+
</Note>
|
|
27
36
|
|
|
28
37
|
```typescript
|
|
29
38
|
import {
|
|
39
|
+
type Api,
|
|
30
40
|
type AssistantMessage,
|
|
31
41
|
type AssistantMessageEventStream,
|
|
42
|
+
type Context,
|
|
32
43
|
type Model,
|
|
33
44
|
type SimpleStreamOptions,
|
|
34
|
-
type TranscriptContext,
|
|
35
45
|
calculateCost,
|
|
36
46
|
createAssistantMessageEventStream,
|
|
37
47
|
getCurrentSystemPrompt,
|
|
38
48
|
getCurrentTools,
|
|
39
|
-
ToolCallArgumentsStream,
|
|
40
49
|
} from "@bastani/atomic-ai";
|
|
41
50
|
|
|
42
51
|
function streamMyProvider(
|
|
43
|
-
model: Model<
|
|
44
|
-
context:
|
|
52
|
+
model: Model<Api>,
|
|
53
|
+
context: Context,
|
|
45
54
|
options?: SimpleStreamOptions
|
|
46
55
|
): AssistantMessageEventStream {
|
|
47
56
|
const stream = createAssistantMessageEventStream();
|
|
@@ -49,7 +58,7 @@ function streamMyProvider(
|
|
|
49
58
|
(async () => {
|
|
50
59
|
const systemPrompt = getCurrentSystemPrompt(context.messages);
|
|
51
60
|
const tools = getCurrentTools(context.messages);
|
|
52
|
-
|
|
61
|
+
|
|
53
62
|
const output: AssistantMessage = {
|
|
54
63
|
role: "assistant",
|
|
55
64
|
content: [],
|
|
@@ -69,12 +78,13 @@ function streamMyProvider(
|
|
|
69
78
|
};
|
|
70
79
|
|
|
71
80
|
try {
|
|
72
|
-
// Push start event
|
|
73
81
|
stream.push({ type: "start", partial: output });
|
|
74
82
|
|
|
75
|
-
// Send
|
|
76
|
-
//
|
|
77
|
-
//
|
|
83
|
+
// Send your upstream request using systemPrompt, tools, context.messages, and options.
|
|
84
|
+
// Push content block events as chunks arrive, populate output.usage, call
|
|
85
|
+
// calculateCost(model, output.usage), and set output.stopReason from the terminal event.
|
|
86
|
+
// Throw on any unrecognized provider stop reason instead of defaulting to "stop".
|
|
87
|
+
|
|
78
88
|
if (output.stopReason === "pending") {
|
|
79
89
|
throw new Error("Provider stream ended without a stop reason");
|
|
80
90
|
}
|
|
@@ -82,11 +92,10 @@ function streamMyProvider(
|
|
|
82
92
|
throw new Error(output.errorMessage || "An unknown error occurred");
|
|
83
93
|
}
|
|
84
94
|
|
|
85
|
-
// Push done event
|
|
86
95
|
stream.push({
|
|
87
96
|
type: "done",
|
|
88
97
|
reason: output.stopReason,
|
|
89
|
-
message: output
|
|
98
|
+
message: output,
|
|
90
99
|
});
|
|
91
100
|
stream.end();
|
|
92
101
|
} catch (error) {
|
|
@@ -101,7 +110,7 @@ function streamMyProvider(
|
|
|
101
110
|
}
|
|
102
111
|
```
|
|
103
112
|
|
|
104
|
-
Common
|
|
113
|
+
### Common `SimpleStreamOptions` fields
|
|
105
114
|
|
|
106
115
|
| Option | Purpose |
|
|
107
116
|
| --- | --- |
|
|
@@ -113,50 +122,43 @@ Common fields on `options` (`SimpleStreamOptions`):
|
|
|
113
122
|
| `temperature`, `maxTokens`, `samplingParams` | Generation parameters and custom request-body sampling overrides |
|
|
114
123
|
| `sessionId`, `cacheRetention`, `transport` | Session affinity ID, prompt-cache retention tier, and transport preference |
|
|
115
124
|
| `timeoutMs`, `websocketConnectTimeoutMs`, `streamDeadlineMs`, `retryDeadline` | Request, handshake, idle-stream, and retry timeout bounds |
|
|
116
|
-
| `onPayload`, `onResponse`, `onProviderStreamEvent` | Lifecycle hooks to inspect
|
|
117
|
-
|
|
118
|
-
### Event types
|
|
125
|
+
| `onPayload`, `onResponse`, `onProviderStreamEvent` | Lifecycle hooks to inspect or modify payloads, inspect HTTP responses, and observe parsed raw stream chunks before normalization |
|
|
119
126
|
|
|
120
|
-
|
|
127
|
+
## Event types
|
|
121
128
|
|
|
122
|
-
|
|
123
|
-
2. Content events (repeatable; track `contentIndex` for each block):
|
|
124
|
-
- `{ type: "text_start", contentIndex, partial }`: text block started.
|
|
125
|
-
- `{ type: "text_delta", contentIndex, delta, partial }`: text chunk.
|
|
126
|
-
- `{ type: "text_end", contentIndex, content, partial }`: text block ended.
|
|
127
|
-
- `{ type: "thinking_start", contentIndex, partial }`: thinking block started.
|
|
128
|
-
- `{ type: "thinking_delta", contentIndex, delta, partial }`: thinking chunk.
|
|
129
|
-
- `{ type: "thinking_end", contentIndex, content, partial }`: thinking block ended.
|
|
130
|
-
- `{ type: "toolcall_start", contentIndex, partial }`: tool call started.
|
|
131
|
-
- `{ type: "toolcall_delta", contentIndex, delta, partial }`: tool call JSON chunk.
|
|
132
|
-
- `{ type: "toolcall_end", contentIndex, toolCall, partial }`: tool call ended.
|
|
133
|
-
3. `{ type: "done", reason, message }` or `{ type: "error", reason, error }`: stream ended.
|
|
129
|
+
Push events through `stream.push()` in this order:
|
|
134
130
|
|
|
135
|
-
|
|
131
|
+
1. `{ type: "start", partial: output }` — stream started.
|
|
132
|
+
2. Content block events (repeatable; `contentIndex` is the block's index in `output.content`):
|
|
133
|
+
- Text: `text_start`, `text_delta` (`delta`), `text_end` (`content`)
|
|
134
|
+
- Thinking: `thinking_start`, `thinking_delta` (`delta`), `thinking_end` (`content`)
|
|
135
|
+
- Tool calls: `toolcall_start`, `toolcall_delta` (`delta`), `toolcall_end` (`toolCall`)
|
|
136
|
+
3. Terminal event: `{ type: "done", reason, message }` or `{ type: "error", reason, error }`, followed by `stream.end()`.
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
`partial` always carries the current `AssistantMessage` state. Mutate `output.content` before pushing each event, then pass `output` as `partial`.
|
|
138
139
|
|
|
139
|
-
|
|
140
|
+
## Stop reasons
|
|
140
141
|
|
|
141
|
-
|
|
142
|
+
`StopReason` is `"pending" | "stop" | "length" | "toolUse" | "error" | "aborted" | "deferred"` (`"deferred"` is for asynchronous batch APIs).
|
|
142
143
|
|
|
143
|
-
|
|
144
|
+
Initialize every in-flight message to `"pending"`. Assign the mapped reason when the provider emits its terminal event, and run two checks before pushing `done`:
|
|
144
145
|
|
|
145
|
-
- If `output.stopReason` is still `"pending"`, throw an error so a stream
|
|
146
|
+
- If `output.stopReason` is still `"pending"`, throw an error so a stream that drops before its terminal event does not appear complete.
|
|
146
147
|
- If `output.stopReason` is `"error"` or `"aborted"`, throw `output.errorMessage` so the `catch` block emits an `error` event.
|
|
147
148
|
|
|
148
|
-
|
|
149
|
+
After those two checks, the remaining terminal reasons (`"stop"`, `"length"`, `"toolUse"`, and `"deferred"`) are all valid for `done`.
|
|
149
150
|
|
|
150
|
-
Map every
|
|
151
|
+
Map every upstream finish reason explicitly and **throw on any unrecognized value** instead of falling back to `"stop"`. Store the provider's original string in `output.rawStopReason` when helpful for diagnostics.
|
|
151
152
|
|
|
152
|
-
|
|
153
|
+
## Content blocks
|
|
153
154
|
|
|
154
|
-
Append
|
|
155
|
+
Append each new block to `output.content`, update it as deltas arrive, and emit its closing event:
|
|
155
156
|
|
|
156
157
|
```typescript
|
|
157
158
|
// Start text block
|
|
158
159
|
output.content.push({ type: "text", text: "" });
|
|
159
|
-
|
|
160
|
+
const contentIndex = output.content.length - 1;
|
|
161
|
+
stream.push({ type: "text_start", contentIndex, partial: output });
|
|
160
162
|
|
|
161
163
|
// Append text delta
|
|
162
164
|
const block = output.content[contentIndex];
|
|
@@ -166,22 +168,30 @@ if (block.type === "text") {
|
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
// Complete text block
|
|
169
|
-
|
|
171
|
+
if (block.type === "text") {
|
|
172
|
+
stream.push({ type: "text_end", contentIndex, content: block.text, partial: output });
|
|
173
|
+
}
|
|
170
174
|
```
|
|
171
175
|
|
|
172
|
-
|
|
176
|
+
Thinking blocks follow the same lifecycle with `{ type: "thinking", thinking: "" }` and `thinking_start` / `thinking_delta` / `thinking_end`.
|
|
177
|
+
|
|
178
|
+
## Tool calls
|
|
173
179
|
|
|
174
|
-
Tool call arguments stream as JSON
|
|
180
|
+
Tool call arguments stream as JSON fragments. Use `ToolCallArgumentsStream` from `@bastani/atomic-ai` to parse deltas incrementally rather than re-parsing the entire buffer on every chunk:
|
|
175
181
|
|
|
176
182
|
```typescript
|
|
183
|
+
import { ToolCallArgumentsStream } from "@bastani/atomic-ai";
|
|
184
|
+
|
|
177
185
|
// Start tool call
|
|
178
|
-
|
|
179
|
-
type: "toolCall",
|
|
186
|
+
const block = {
|
|
187
|
+
type: "toolCall" as const,
|
|
180
188
|
id: toolCallId,
|
|
181
189
|
name: toolName,
|
|
182
|
-
arguments: {}
|
|
183
|
-
}
|
|
184
|
-
|
|
190
|
+
arguments: {},
|
|
191
|
+
};
|
|
192
|
+
output.content.push(block);
|
|
193
|
+
const contentIndex = output.content.length - 1;
|
|
194
|
+
stream.push({ type: "toolcall_start", contentIndex, partial: output });
|
|
185
195
|
|
|
186
196
|
const args = new ToolCallArgumentsStream();
|
|
187
197
|
|
|
@@ -189,12 +199,12 @@ const args = new ToolCallArgumentsStream();
|
|
|
189
199
|
block.arguments = args.append(jsonDelta);
|
|
190
200
|
stream.push({ type: "toolcall_delta", contentIndex, delta: jsonDelta, partial: output });
|
|
191
201
|
|
|
192
|
-
// Finalize: full parse; malformed
|
|
202
|
+
// Finalize: full parse; malformed JSON records `argumentsError` on `block`
|
|
193
203
|
Object.assign(block, args.finish());
|
|
194
204
|
stream.push({ type: "toolcall_end", contentIndex, toolCall: block, partial: output });
|
|
195
205
|
```
|
|
196
206
|
|
|
197
|
-
|
|
207
|
+
## Usage and cost
|
|
198
208
|
|
|
199
209
|
Populate `output.usage` from the provider response and call `calculateCost()`:
|
|
200
210
|
|
|
@@ -211,11 +221,11 @@ output.usage.totalTokens =
|
|
|
211
221
|
calculateCost(model, output.usage);
|
|
212
222
|
```
|
|
213
223
|
|
|
214
|
-
`calculateCost(model, output.usage)` mutates `output.usage.cost` in place and returns it
|
|
224
|
+
`calculateCost(model, output.usage)` mutates `output.usage.cost` in place and returns it, applying any long-context `cost.tiers` configured on the model. See [Request-wide cost tiers](/models/reference#request-wide-cost-tiers) for threshold matching and `modelOverrides` rules.
|
|
215
225
|
|
|
216
|
-
|
|
226
|
+
## Registration
|
|
217
227
|
|
|
218
|
-
|
|
228
|
+
Pass `streamSimple` alongside a provider-level `api` string in `atomic.registerProvider()`. Supplying `streamSimple` requires `api` at the provider level and suppresses derived `-fast` variants for that `api`:
|
|
219
229
|
|
|
220
230
|
```typescript
|
|
221
231
|
await atomic.registerProvider("my-provider", {
|
|
@@ -230,9 +240,13 @@ await atomic.registerProvider("my-provider", {
|
|
|
230
240
|
input: ["text"],
|
|
231
241
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
232
242
|
contextWindow: 128000,
|
|
233
|
-
maxTokens: 8192
|
|
234
|
-
}
|
|
243
|
+
maxTokens: 8192,
|
|
244
|
+
},
|
|
235
245
|
],
|
|
236
|
-
streamSimple: streamMyProvider
|
|
246
|
+
streamSimple: streamMyProvider,
|
|
237
247
|
});
|
|
238
248
|
```
|
|
249
|
+
|
|
250
|
+
<Tip>
|
|
251
|
+
For general streaming utilities, transcript helpers, and standalone `@bastani/atomic-ai` usage outside extensions, see the [AI library reference](/libraries/ai).
|
|
252
|
+
</Tip>
|