@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
package/docs/sdk/storage.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
sidebarTitle: "
|
|
2
|
+
title: "Configure session storage"
|
|
3
|
+
sidebarTitle: "Configure storage"
|
|
4
4
|
description: "Configure local SQLite, JSONL, in-memory, and PostgreSQL storage for createAgentSession(), createAgentSessionRuntime(), and SessionManager."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
By default, Atomic persists sessions in local SQLite at `~/.atomic/workflows/journal.sqlite` (`session_` table prefix). In SDK applications, you can
|
|
7
|
+
By default, Atomic persists sessions in local SQLite at `~/.atomic/workflows/journal.sqlite` (`session_` table prefix). In SDK applications, you can choose any of the four supported backends per session, share one database connection across multiple sessions, or manage lifecycle explicitly through `createAgentSessionRuntime()` and `SessionManager`.
|
|
8
8
|
|
|
9
9
|
For CLI setup, database role administration, migrations, and custom drivers, see [Storage](/storage).
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Choose a backend
|
|
12
12
|
|
|
13
13
|
| Backend | Package | How to pass it | Best for |
|
|
14
14
|
| --- | --- | --- | --- |
|
|
@@ -127,7 +127,7 @@ import { createAgentSession, JsonlSessionStore } from "@bastani/atomic";
|
|
|
127
127
|
|
|
128
128
|
Atomic offers three in-memory configurations with different release and rehydrate behavior:
|
|
129
129
|
|
|
130
|
-
1. **`SessionManager.inMemory()`:** Ephemeral private session with no external store handle. Cannot be released and rehydrated (`not-reopenable`)
|
|
130
|
+
1. **`SessionManager.inMemory()`:** Ephemeral private session with no external store handle. Cannot be released and rehydrated (`not-reopenable`); combining it with `releaseWhenIdle` rejects immediately in `createAgentSession()`.
|
|
131
131
|
2. **Caller-owned `new MemorySessionStore()`:** Keeps session history in process RAM across `session.release()` and `runtime.rehydrate()` without writing anything to disk. You own the store and close it with `await store.close()`.
|
|
132
132
|
3. **Disk-spilling memory store via `resolveSessionStore(cwd, { agentDir, sessionStore: { kind: "memory" } })`:** Writes released session history to private owner-only files (`0700`/`0600`) under `<agentDir>/released-history/` to free RAM while idle, cleaning up files on close and process exit (throws `SessionSpillError` if a spill file is missing or corrupt).
|
|
133
133
|
|
|
@@ -292,14 +292,20 @@ try {
|
|
|
292
292
|
}
|
|
293
293
|
```
|
|
294
294
|
|
|
295
|
-
>
|
|
295
|
+
<Warning>
|
|
296
|
+
**`{ kind: "adapter" }` does not search your application's local `node_modules`.** Atomic resolves adapter package names from user-scope packages installed with `atomic install` (`~/.atomic/agent/npm`), directories passed in `DefaultResourceLoader({ additionalExtensionPaths: [packageRoot] })`, or paths relative to `agentDir`. If your app installed `@bastani/atomic-storage-postgres` only with `npm install`, use **Option A** (`openPostgresDatabase()`), install it in user scope (`atomic install npm:@bastani/atomic-storage-postgres`), pass its directory via `additionalExtensionPaths`, or pass a resolved file path (`fileURLToPath(import.meta.resolve(POSTGRES_ADAPTER_PACKAGE))`).
|
|
297
|
+
</Warning>
|
|
296
298
|
|
|
297
|
-
>
|
|
299
|
+
<Note>
|
|
300
|
+
Atomic 0.10.11 removed libSQL and Turso support, including `@bastani/atomic-storage-libsql`, `teamProfileSelection()`, and `LIBSQL_ADAPTER_PACKAGE`. To move sessions off libSQL, see [Moving off libSQL](/storage#moving-off-libsql).
|
|
301
|
+
</Note>
|
|
298
302
|
|
|
299
303
|
## `createAgentSessionRuntime()` and `SessionManager` with explicit stores
|
|
300
304
|
|
|
301
305
|
Neither `createAgentSessionRuntime()` nor `createAgentSessionFromServices()` takes `sessionStore` or `storage` directly. Both take a pre-opened `sessionManager: SessionManager`, and every later `newSession()`, `switchSession()`, `fork()`, and `rehydrate()` call inherits the store from `sessionManager.getSessionStore()`.
|
|
302
306
|
|
|
307
|
+
Pass `interactive: true` to `createAgentSessionRuntime()` only when attaching an interactive UI; when omitted (`false`), resuming a worktree snapshot starts the first turn while the blueprint build runs in the background unless `resume.waitForBlueprint` is set. Call `runtime.takeResumeNotices()` after `switchSession()` or `rehydrate()` to retrieve resume warnings once.
|
|
308
|
+
|
|
303
309
|
Use these explicit-store `SessionManager` methods to open, resume, and inspect sessions against any `SessionStore` (`SqlSessionStore`, `JsonlSessionStore`, `MemorySessionStore`, or a store from `resolveSessionStore()`):
|
|
304
310
|
|
|
305
311
|
```typescript
|
|
@@ -519,12 +525,46 @@ async function runWithStorageHandling(fn: () => Promise<void>): Promise<void> {
|
|
|
519
525
|
}
|
|
520
526
|
```
|
|
521
527
|
|
|
522
|
-
For the full list of storage error classes
|
|
528
|
+
For the full list of storage error classes and cross-process `serializeStorageError()` / `rehydrateStorageError()`, see [Storage errors](/storage#storage-errors) and [Session and storage errors](/sdk/reference#session-and-storage-errors).
|
|
529
|
+
|
|
530
|
+
## Testing custom storage adapters
|
|
531
|
+
|
|
532
|
+
If you implement a custom `SqliteDatabase` driver or storage adapter, import `registerSqliteDatabaseConformance()` from `@bastani/atomic/storage/testing` to run Atomic's conformance test suite (parameter binding, binary blobs, transactions, rollbacks, reopening, and typed error contracts) inside your own test runner:
|
|
533
|
+
|
|
534
|
+
```typescript
|
|
535
|
+
import { describe, it } from "vitest";
|
|
536
|
+
import { registerSqliteDatabaseConformance } from "@bastani/atomic/storage/testing";
|
|
537
|
+
|
|
538
|
+
registerSqliteDatabaseConformance({ describe, it }, "MyDatabaseAdapter", async (body) => {
|
|
539
|
+
const database = await openMyAdapter();
|
|
540
|
+
try {
|
|
541
|
+
await body({
|
|
542
|
+
database,
|
|
543
|
+
reopen: () => openMyAdapter(),
|
|
544
|
+
withRollbackFailure: async (cause, fn) => {
|
|
545
|
+
// Inject a rollback failure using `cause` while running `fn`
|
|
546
|
+
await fn();
|
|
547
|
+
},
|
|
548
|
+
});
|
|
549
|
+
} finally {
|
|
550
|
+
await database.close();
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
```
|
|
523
554
|
|
|
524
555
|
## Related docs
|
|
525
556
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
557
|
+
<Columns cols={2}>
|
|
558
|
+
<Card title="Operator storage setup" href="/storage">
|
|
559
|
+
PostgreSQL roles, TLS, proxies, poolers, migrations, `atomic storage` commands, and custom drivers.
|
|
560
|
+
</Card>
|
|
561
|
+
<Card title="@bastani/atomic-storage-postgres" href="/libraries/storage-postgres">
|
|
562
|
+
PostgreSQL adapter options, PgBouncer auto-detection, cloud IAM, and SQL helpers.
|
|
563
|
+
</Card>
|
|
564
|
+
<Card title="Use the TypeScript SDK" href="/sdk">
|
|
565
|
+
`createAgentSession()`, workspaces, Intercom policies, and lifecycle hooks.
|
|
566
|
+
</Card>
|
|
567
|
+
<Card title="SessionManager API" href="/session-format#sessionmanager-api">
|
|
568
|
+
Entry types, tree navigation, and session append methods, plus [SDK API reference](/sdk/reference).
|
|
569
|
+
</Card>
|
|
570
|
+
</Columns>
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
sidebarTitle: "
|
|
4
|
-
description: "Make typed, schema-validated classifier or chat model decisions with decide()
|
|
2
|
+
title: "Make structured decisions"
|
|
3
|
+
sidebarTitle: "Make decisions"
|
|
4
|
+
description: "Make typed, schema-validated classifier or chat model decisions with decide(), generateStructuredOutput(), and structured_output without starting an agent session."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Atomic provides one decision
|
|
7
|
+
Atomic provides one decision engine across three entry points:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
| Entry point | Use when | Error contract |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| [`decide()`](#decide) | You want typed `choice`, `bool`, or `score` answers (with classifier probabilities) and built-in secret screening | Always throws `DecisionError` subclasses (or `signal.reason` on caller abort) |
|
|
12
|
+
| [`generateStructuredOutput()`](#select-the-inference-model) | You need arbitrary JSON Schema output from explicit model candidates or `settings` | Wraps into `DecisionError` only when `settings` is passed and `model` is omitted (timeouts always throw `DecisionTimeoutError`) |
|
|
13
|
+
| `structured_output` tool | An agent session should infer and return a final schema-validated answer | Same as `generateStructuredOutput()` using session `decisionModel` unless the model passes an explicit `model` |
|
|
12
14
|
|
|
13
15
|
None of these APIs starts a child agent, invokes other tools, authorizes an action, or changes the selected chat model.
|
|
14
16
|
|
|
@@ -16,11 +18,11 @@ None of these APIs starts a child agent, invokes other tools, authorizes an acti
|
|
|
16
18
|
|
|
17
19
|
`decide({ state, questions, settings, modelRegistry, currentModel, ... })` evaluates one or more independent named questions against one `state` object in a single request:
|
|
18
20
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
21
|
+
- **`choice`:** pick one option. `criteria` maps each option name to its meaning.
|
|
22
|
+
- **`bool`:** a yes/no question. `criteria` defines what `true` and `false` mean.
|
|
23
|
+
- **`score`:** grade on ordered levels. `criteria` lists at least two level descriptions, lowest first.
|
|
22
24
|
|
|
23
|
-
`decide()` resolves `decisionModel` once. When a classifier answers, `source` is `"classifier"` and answers include probabilities and confidence scores. If the classifier fails, the current chat model answers without probabilities, sets `source: "chat"`, and populates `result.fallback`. An empty or `"auto"` `decisionModel` uses `currentModel` directly. Pass `requireProbabilities: true` to restrict answers to classifiers so chat models or classifier failures reject instead of falling back.
|
|
25
|
+
`decide()` resolves [`decisionModel`](/settings#decisionmodel) once. When a classifier answers, `source` is `"classifier"` and answers include probabilities and confidence scores. If the classifier fails, the current chat model answers without probabilities, sets `source: "chat"`, and populates `result.fallback`. An empty or `"auto"` `decisionModel` uses `currentModel` directly. Pass `requireProbabilities: true` to restrict answers to classifiers so chat models or classifier failures reject instead of falling back.
|
|
24
26
|
|
|
25
27
|
Standalone SDK usage with `ModelRuntime`, `ModelRegistry`, and `SettingsManager`:
|
|
26
28
|
|
|
@@ -66,16 +68,14 @@ Inside an extension handler, pass `settings: { getDecisionModel: () => ctx.getDe
|
|
|
66
68
|
- `state`: non-empty plain JSON object containing the facts to evaluate.
|
|
67
69
|
- `questions`: non-empty record mapping caller-chosen IDs to `choice`, `bool`, or `score` question definitions.
|
|
68
70
|
- `instructions`: optional top-level context shared across all questions. Defaults to ``"Answer each question about `state`."`` and must be non-blank if supplied.
|
|
69
|
-
- `deadline`: optional positive integer wall-clock limit in milliseconds covering credential screening, requests, retries, repairs, and fallbacks. Defaults to [`httpIdleTimeoutMs`](/settings#http).
|
|
70
|
-
- `retry`: optional `RetryPolicy`
|
|
71
|
-
- `signal`: optional `AbortSignal`; cancellation rejects immediately with
|
|
72
|
-
- `model`: optional exact `provider/model` ID to use instead of `decisionModel
|
|
71
|
+
- `deadline`: optional positive safe integer wall-clock limit in milliseconds covering credential screening, requests, retries, repairs, and fallbacks. Defaults to `settings.getHttpIdleTimeoutMs?.()` (from [`httpIdleTimeoutMs`](/settings#http)), or 10 minutes if unset.
|
|
72
|
+
- `retry`: optional `RetryPolicy` for transient chat transport errors. Precedence is `request.retry` → `settings.getRetrySettings?.()` → `{ enabled: true, maxRetries: 3, baseDelayMs: 2000 }`.
|
|
73
|
+
- `signal`: optional `AbortSignal`; cancellation rejects immediately with `signal.reason`.
|
|
74
|
+
- `model`: optional exact `provider/model` ID to use instead of `decisionModel` (cannot be `"auto"` or have surrounding whitespace).
|
|
73
75
|
- `requireProbabilities`: when `true`, only a classifier may answer.
|
|
74
76
|
|
|
75
77
|
### Return value (`DecisionResult`)
|
|
76
78
|
|
|
77
|
-
`decide()` resolves with:
|
|
78
|
-
|
|
79
79
|
```typescript
|
|
80
80
|
interface DecisionResult<Q> {
|
|
81
81
|
answers: Record<keyof Q, DecisionAnswer>;
|
|
@@ -95,32 +95,39 @@ Each entry in `result.answers.<id>` matches its question type:
|
|
|
95
95
|
|
|
96
96
|
Keep action logic in application code. Compare probabilities against per-action thresholds, require stricter thresholds for irreversible actions, and pair `choice` questions with a `bool` applicability check (because `choice` always picks one option). `decide()` never caches results; cache them yourself if needed.
|
|
97
97
|
|
|
98
|
-
###
|
|
98
|
+
### Input validation and credential screening
|
|
99
99
|
|
|
100
|
-
`decide()`
|
|
100
|
+
`decide()` validates and snapshots the request before calling any model so later caller mutations cannot alter an in-flight call. It rejects immediately with `DecisionRequestError` (`code: "invalid-request"`) if:
|
|
101
101
|
|
|
102
|
-
-
|
|
103
|
-
- `
|
|
104
|
-
- a
|
|
102
|
+
- `state` is empty, an array, cyclic, contains `NaN`/`Infinity`, or contains non-plain objects (such as `Date`, `Map`, or class instances);
|
|
103
|
+
- `questions` is empty, has blank/whitespace question IDs or option keys, blank instructions/criteria descriptions, or a `score` question with fewer than 2 levels;
|
|
104
|
+
- `instructions` is blank when supplied, `deadline` is not a positive safe integer, or `model` is `"auto"`, empty, or has leading/trailing whitespace; or
|
|
105
|
+
- `state` contains a credential (`reason: "credential-in-state"`): any known environment credential, `Bearer` tokens, PEM private keys, `sk-`/`ghp_`/`github_pat_` key patterns, or a credential configured in `modelRegistry`.
|
|
105
106
|
|
|
106
|
-
`
|
|
107
|
+
If `modelRegistry.containsConfiguredCredential()` throws during screening, `decide()` rejects with `DecisionProviderError` (`detail: "configured-credential screening failed before any model was asked"`).
|
|
107
108
|
|
|
108
|
-
|
|
109
|
+
<Warning>
|
|
110
|
+
`generateStructuredOutput()` does **not** run automatic credential screening. Always strip secrets from `state` and `instructions` yourself before calling `generateStructuredOutput()`.
|
|
111
|
+
</Warning>
|
|
109
112
|
|
|
110
|
-
|
|
113
|
+
### Errors {#errors}
|
|
111
114
|
|
|
112
|
-
|
|
115
|
+
Every failure from `decide()` rejects with a `DecisionError` (except caller cancellation, which rejects with `signal.reason`). Branch on the error class, type guard, or `code` — never on message text.
|
|
113
116
|
|
|
114
|
-
|
|
117
|
+
Every `DecisionError` exposes `code`, `hint`, `retryable`, `cause`, and `fields()` (returning the JSON-safe structured fields for that subclass). Use `isDecisionError(error)` and the per-class guards across process boundaries, `findDecisionError(error)` or `isRetryableDecisionError(error)` to walk a `cause` chain, and `serializeDecisionError()` / `parseSerializedDecisionError()` / `rehydrateDecisionError()` to transport errors across processes (`parseSerializedDecisionError()` returns `undefined` for malformed payloads).
|
|
115
118
|
|
|
116
|
-
| Class | `code` | When | Fields | What to do |
|
|
119
|
+
| Class | `code` | When | Fields (`error.fields()`) | What to do |
|
|
117
120
|
| --- | --- | --- | --- | --- |
|
|
118
|
-
| `DecisionConfigError` | `invalid-setting`
|
|
119
|
-
| `DecisionRequestError` | `invalid-request` |
|
|
121
|
+
| `DecisionConfigError` | `invalid-setting` | `decisionModel` is not a string or has surrounding whitespace | `source`, `field`, optional `scope` (`"global" \| "project"`) | Set an exact `provider/model`, `"auto"`, or `""`. |
|
|
122
|
+
| `DecisionRequestError` | `invalid-request` | Invalid `state`, credential in `state`, malformed `questions`, blank `instructions`, invalid `deadline`, or invalid `model` | `field`, `reason` | Fix the request; nothing was sent. |
|
|
120
123
|
| `DecisionModelUnavailableError` | `model-unavailable` | `decisionModel` is not a registered chat or classifier model (`not-in-catalog`), no chat model is selected (`no-chat-model`), probabilities are required from a chat model (`no-probabilities`), or the host provides no decision model or registry (`host-unsupported`) | `reason`, `model` | Choose another decision model or select a chat model. |
|
|
121
|
-
| `DecisionTimeoutError` | `timeout` | The wall-clock deadline expired | `timeoutMs`, `elapsedMs`, `phase`, `attempts` | Retry, or raise `deadline` / `timeoutMs`.
|
|
124
|
+
| `DecisionTimeoutError` | `timeout` | The wall-clock deadline expired | `timeoutMs`, `elapsedMs`, `phase`, `attempts` | Retry, or raise `deadline` / `timeoutMs`. `retryable` is `true`. |
|
|
122
125
|
| `DecisionOutputError` | `invalid-output` | The model responded, but output failed schema validation after repairs | `model`, `detail` | Clarify questions or pick another model. |
|
|
123
|
-
| `DecisionProviderError` | `provider-failure` | The provider request failed | `model`, `providerStatus`, `providerCode`, `retryAfterMs`, `detail` |
|
|
126
|
+
| `DecisionProviderError` | `provider-failure` | The provider request failed (or credential screening threw) | `model`, `providerStatus`, `providerCode`, `retryAfterMs`, `detail` | `retryable` is `true` **only** when `providerCode` is `"rate_limit_exceeded"` or `"insufficient_quota"`; otherwise check provider status and auth. |
|
|
127
|
+
|
|
128
|
+
<Note>
|
|
129
|
+
Legacy `routerModel` entries in `settings.json` migrate to `decisionModel` automatically (an existing `decisionModel` wins, and invalid legacy values are ignored with a one-time warning). `DecisionConfigError` still recognizes the legacy decode-only code `"renamed-setting"` when rehydrating serialized errors from older processes. See [decisionModel](/settings#decisionmodel).
|
|
130
|
+
</Note>
|
|
124
131
|
|
|
125
132
|
```typescript
|
|
126
133
|
import { decide, isDecisionError, isDecisionProviderError, isDecisionTimeoutError } from "@bastani/atomic";
|
|
@@ -152,7 +159,8 @@ try {
|
|
|
152
159
|
break;
|
|
153
160
|
case "provider-failure":
|
|
154
161
|
if (isDecisionProviderError(error) && error.retryable) {
|
|
155
|
-
|
|
162
|
+
// retryable is true only when providerCode is "rate_limit_exceeded" or "insufficient_quota".
|
|
163
|
+
console.error(`Retryable provider error (${error.providerCode}); wait ${error.retryAfterMs ?? 0}ms.`);
|
|
156
164
|
} else {
|
|
157
165
|
console.error(error.hint);
|
|
158
166
|
}
|
|
@@ -161,17 +169,26 @@ try {
|
|
|
161
169
|
case "invalid-setting":
|
|
162
170
|
case "invalid-request":
|
|
163
171
|
case "invalid-output":
|
|
164
|
-
case "renamed-setting":
|
|
165
172
|
console.error(`${error.code}: ${error.hint}`);
|
|
166
173
|
break;
|
|
167
174
|
}
|
|
168
175
|
}
|
|
169
176
|
```
|
|
170
177
|
|
|
171
|
-
## How `decisionModel`
|
|
178
|
+
## How `decisionModel` and `DecisionError` wrapping apply
|
|
172
179
|
|
|
173
|
-
|
|
174
|
-
|
|
180
|
+
`DecisionError` wrapping differs between `decide()`, `generateStructuredOutput()`, and `structured_output`:
|
|
181
|
+
|
|
182
|
+
<Warning>
|
|
183
|
+
In `generateStructuredOutput()` (and the `structured_output` tool), passing an explicit `model` causes Atomic to **ignore `settings`** (`decisionModel` is not consulted), so inference, output, and provider errors throw plain `Error` instances rather than `DecisionError` subclasses. Input validation errors (invalid `maxTokens`, invalid `state`, blank `instructions`, invalid `currentModel`, invalid `timeoutMs`, or missing `model`/`currentModel`) also throw plain `Error` even when `settings` is passed.
|
|
184
|
+
</Warning>
|
|
185
|
+
|
|
186
|
+
- **`decide()`:** Always resolves `decisionModel` (or validates explicit `model`) and wraps every failure into a `DecisionError` subclass (except caller aborts, which reject with `signal.reason`).
|
|
187
|
+
- **`generateStructuredOutput()`:**
|
|
188
|
+
- **With `settings` and `model` omitted:** resolves `decisionModel` (throwing `DecisionConfigError` or `DecisionModelUnavailableError` immediately if invalid) and wraps inference/output/provider failures into `DecisionError` subclasses (`DecisionOutputError`, `DecisionProviderError`). Input validation errors still throw plain `Error`.
|
|
189
|
+
- **Without `settings`, OR with an explicit `model`:** ignores `settings` and throws plain `Error` instances on resolution, inference, output, and provider failures.
|
|
190
|
+
- **Timeouts:** Always reject with `DecisionTimeoutError` regardless of whether `settings` or `model` was passed.
|
|
191
|
+
- **`structured_output` tool:** Delegates to `generateStructuredOutput()` with session `settings` and `timeoutMs` resolved from the session's `httpIdleTimeoutMs`. When the calling model omits `model`, it starts on `decisionModel` and wraps inference failures into `DecisionError`; when the calling model passes an explicit `model`, `settings` is ignored and non-timeout failures throw plain `Error`.
|
|
175
192
|
|
|
176
193
|
### Switch `decisionModel` on a live session
|
|
177
194
|
|
|
@@ -192,14 +209,14 @@ session.setDecisionModel("auto", "project", { persist: false });
|
|
|
192
209
|
|
|
193
210
|
## Select the inference model
|
|
194
211
|
|
|
195
|
-
|
|
212
|
+
In `generateStructuredOutput()`, pass an optional exact `provider/model` string (not a `Model` object and not `"auto"`):
|
|
196
213
|
|
|
197
214
|
- `model`: primary candidate (chat model or registered classifier such as `typesafe/jev-latest`).
|
|
198
215
|
- `fallbackModels`: ordered list of exact `provider/model` IDs.
|
|
199
216
|
- Omit `model` to start on `decisionModel` when `settings` is passed, or on `currentModel` otherwise.
|
|
200
217
|
- After `model` and `fallbackModels`, Atomic tries `currentModel` if it has not already been tried.
|
|
201
218
|
|
|
202
|
-
Image-generation models, wildcard patterns, reasoning suffixes, surrounding whitespace, and unregistered IDs are invalid. Atomic skips invalid `model`/`fallbackModels` entries, records each error in `modelAttempts`, and advances to the remaining candidates including `currentModel` (failing with the first error only when no candidate resolves). When `model` is omitted and `settings` is provided, an invalid or unregistered `decisionModel` fails immediately with a [`DecisionError`](#errors) instead of skipping.
|
|
219
|
+
Image-generation models, wildcard patterns, reasoning suffixes, surrounding whitespace, and unregistered IDs are invalid. When `model` is explicitly passed (or `settings` is omitted), Atomic skips invalid `model`/`fallbackModels` entries, records each error in `modelAttempts`, and advances to the remaining candidates including `currentModel` (failing with the first error only when no candidate resolves). When `model` is omitted and `settings` is provided, an invalid or unregistered `decisionModel` fails immediately with a [`DecisionError`](#errors) instead of skipping.
|
|
203
220
|
|
|
204
221
|
### Choice-compatible schemas
|
|
205
222
|
|
|
@@ -232,11 +249,9 @@ const result = await generateStructuredOutput({
|
|
|
232
249
|
console.log(result.value.category, result.model);
|
|
233
250
|
```
|
|
234
251
|
|
|
235
|
-
`result.value` holds the schema-validated result, `result.model` identifies the candidate that answered, and `result.modelAttempts` records skipped and failed candidates when a fallback chain ran.
|
|
236
|
-
|
|
237
|
-
`result.usage` reports chat token usage when a chat candidate produced the result (classifier billing is reported separately by the classifier operation). A schema-valid result does not guarantee policy compliance, so check the result against your own rules before acting.
|
|
252
|
+
`result.value` holds the schema-validated result, `result.model` identifies the candidate that answered, and `result.modelAttempts` records skipped and failed candidates when a fallback chain ran. `result.usage` reports chat token usage when a chat candidate produced the result (classifier billing is reported separately by the classifier operation). A schema-valid result does not guarantee policy compliance, so check the result against your own rules before acting.
|
|
238
253
|
|
|
239
|
-
The `structured_output` tool accepts required `instructions`, non-empty named `state`, and optional `model` and `fallbackModels` from the calling model. `createStructuredOutputTool({ schema })` fixes the output schema
|
|
254
|
+
The `structured_output` tool accepts required `instructions`, non-empty named `state`, and optional `model` and `fallbackModels` from the calling model. `createStructuredOutputTool({ schema })` fixes the output schema; the calling model cannot override the deadline (set it with `timeoutMs`). See [Structured output final results](/sdk/reference#structured-output-final-results).
|
|
240
255
|
|
|
241
256
|
## Prepare a decision
|
|
242
257
|
|
|
@@ -244,28 +259,39 @@ Put the task criteria in `instructions` and all relevant facts, constraints, and
|
|
|
244
259
|
|
|
245
260
|
For `generateStructuredOutput()`, supply `instructions`, `state`, and `schema` (prefer `{ additionalProperties: false }` on object schemas). Keep numeric thresholds in application code, and add an explicit abstention option when no choice may fit.
|
|
246
261
|
|
|
247
|
-
## Provider behavior and limits
|
|
262
|
+
## Provider behavior and limits {#provider-behavior-and-limits}
|
|
248
263
|
|
|
249
|
-
|
|
264
|
+
| Behavior | Chat models | Classifiers (for example [TypeSafe Jev](/providers#typesafe-jev)) |
|
|
265
|
+
| --- | --- | --- |
|
|
266
|
+
| **Schema support** | Any valid JSON Schema | Finite Choice schemas only (skipped otherwise) |
|
|
267
|
+
| **Execution mechanism** | One internal result tool matching `schema`, strict sampling where supported, validated without coercion or key stripping | One `classify` call with `state` and derived choice questions (no trimming of `state`) |
|
|
268
|
+
| **Repair loop** | Up to 3 repair attempts (1 initial + 3 repairs) for prose-only replies, extra tool calls, truncated output, or invalid payloads | No repair loop; invalid or rejected requests advance directly to the next fallback candidate |
|
|
269
|
+
| **Transport and retries** | HTTP/SSE only (no WebSocket fallback; Anthropic server-side fallbacks disabled); transient transport errors follow `retry` (default `{ enabled: true, maxRetries: 3, baseDelayMs: 2000 }`) | Provider `classify` implementation owns transport retries within the shared abort signal and retry limit |
|
|
270
|
+
| **Probabilities & confidence** | Not returned | Returned on `decide()` answers; advisory and never reject an otherwise valid option |
|
|
250
271
|
|
|
251
|
-
|
|
272
|
+
### Optional fields and `null` placeholders
|
|
252
273
|
|
|
253
|
-
|
|
274
|
+
Use `Type.Optional(...)` for fields that may be omitted. When a strict chat provider encodes an omitted optional field as `null`, Atomic strips that `null` placeholder if the property schema rejects `null` (including inside nested objects and array items). Allow `null` explicitly in the schema if `null` is a valid answer. Always set `additionalProperties: false` on closed objects.
|
|
254
275
|
|
|
255
|
-
|
|
276
|
+
## Cancellation and failures {#cancellation-and-failures}
|
|
256
277
|
|
|
257
|
-
|
|
278
|
+
### Deadlines and timeouts
|
|
258
279
|
|
|
259
|
-
|
|
280
|
+
One wall-clock deadline covers the entire call: credential screening, every repair attempt, transport retry, and fallback candidate combined. Configure it with `deadline` (in `decide()`) or `timeoutMs` (in `generateStructuredOutput()` and `createStructuredOutputTool()`) as a positive safe integer in milliseconds. Atomic checks the deadline before every retry so overdue backoffs never start another request.
|
|
260
281
|
|
|
261
|
-
|
|
282
|
+
- **Default deadline:**
|
|
283
|
+
- `decide()` and `structured_output`: read `httpIdleTimeoutMs` from settings/session first, then fall back to 10 minutes (`600_000` ms).
|
|
284
|
+
- Standalone `generateStructuredOutput()`: defaults directly to 10 minutes (`600_000` ms) and does **not** read `settings.getHttpIdleTimeoutMs()`. Pass `timeoutMs` explicitly to override it.
|
|
285
|
+
- Setting `httpIdleTimeoutMs` to `0` (`"disabled"`) uses JavaScript's maximum timer delay (`2,147,483,647` ms, ~24.8 days).
|
|
286
|
+
- **On expiration:** Atomic aborts the in-flight request (even if the provider ignores abort signals) and rejects with `DecisionTimeoutError`, including `timeoutMs`, `elapsedMs`, `phase`, `hint`, and per-attempt timings (for example, `Attempts: 1) stopReason=stop 25m02s; 2) still generating 4m58s.`). Timeouts are final and never trigger further repairs or fallbacks.
|
|
262
287
|
|
|
263
|
-
|
|
288
|
+
### Caller cancellation (`AbortSignal`)
|
|
264
289
|
|
|
265
|
-
|
|
290
|
+
Pass an `AbortSignal` (such as `AbortSignal.timeout(ms)`) to cancel sooner; cancellation stops the in-flight request immediately and halts the fallback chain:
|
|
266
291
|
|
|
267
|
-
|
|
292
|
+
- **`decide()`** rejects with `signal.reason`.
|
|
293
|
+
- **`generateStructuredOutput()`** replaces non-timeout caller aborts with a plain `Error("Structured output cancelled; no decision was accepted.")` (discarding custom `signal.reason`).
|
|
268
294
|
|
|
269
|
-
|
|
295
|
+
### Output token cap and error hygiene
|
|
270
296
|
|
|
271
|
-
Provider errors report static reasons without raw response bodies or credentials. Classifier failures and chat provider errors advance to the next fallback candidate; ordinary chat text without a valid tool call gets up to 3 repair attempts before advancing.
|
|
297
|
+
`generateStructuredOutput()` sets no default output token cap; pass optional `maxTokens` as a positive safe integer up to `2,147,483,647` to cap output below the model's limit. Provider errors report static reasons without raw response bodies or credentials. Classifier failures and chat provider errors advance to the next fallback candidate; ordinary chat text without a valid tool call gets up to 3 repair attempts before advancing.
|
package/docs/sdk/web-server.md
CHANGED
|
@@ -1,47 +1,49 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
sidebarTitle: "
|
|
2
|
+
title: "Stream from a web server"
|
|
3
|
+
sidebarTitle: "Stream over HTTP"
|
|
4
4
|
description: "Run Atomic sessions behind a Next.js App Router endpoint and stream newline-delimited JSON output to a browser."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
This guide puts an Atomic agent behind an HTTP endpoint using Next.js App Router. The same pattern works in any long-running Node.js server: keep one session per conversation, start
|
|
7
|
+
This guide puts an Atomic agent behind an HTTP endpoint using Next.js App Router. The same pattern works in any long-running Node.js server: keep one session per conversation, start one prompt per request, and stream session events back as newline-delimited JSON (NDJSON).
|
|
8
8
|
|
|
9
|
-
Read [TypeScript SDK](/sdk) first for `createAgentSession()`, `AgentSession`, `AgentSessionRuntime`, and session events. For servers that release idle sessions and rehydrate them on later requests, wrap sessions with `createAgentSessionRuntime()` instead (see [Releasing idle sessions](/sdk#releasing-idle-sessions)).
|
|
9
|
+
Read [Use the TypeScript SDK](/sdk) first for `createAgentSession()`, `AgentSession`, `AgentSessionRuntime`, and session events. For servers that release idle sessions and rehydrate them on later requests, wrap sessions with `createAgentSessionRuntime()` instead (see [Releasing idle sessions](/sdk#releasing-idle-sessions)).
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Prerequisites and setup
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Atomic requires Node.js 24.20 or newer. Dependency install scripts are not required; if your package manager blocks install scripts, leave them disabled.
|
|
18
|
-
|
|
19
|
-
## Keep Atomic out of the server bundle
|
|
13
|
+
<Steps>
|
|
14
|
+
<Step title="Install @bastani/atomic">
|
|
15
|
+
Atomic requires Node.js 24.20 or newer. Dependency install scripts are not required; if your package manager blocks install scripts, leave them disabled.
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npm install @bastani/atomic
|
|
19
|
+
```
|
|
20
|
+
</Step>
|
|
21
|
+
<Step title="Keep Atomic external to the server bundle">
|
|
22
|
+
Atomic resolves its bundled resources and native modules relative to `node_modules`, so list it in `serverExternalPackages` (Next.js 15 and later):
|
|
22
23
|
|
|
23
|
-
```typescript
|
|
24
|
-
// next.config.ts
|
|
25
|
-
import type { NextConfig } from "next";
|
|
24
|
+
```typescript
|
|
25
|
+
// next.config.ts
|
|
26
|
+
import type { NextConfig } from "next";
|
|
26
27
|
|
|
27
|
-
const nextConfig: NextConfig = {
|
|
28
|
-
|
|
29
|
-
};
|
|
28
|
+
const nextConfig: NextConfig = {
|
|
29
|
+
serverExternalPackages: ["@bastani/atomic", "@bastani/atomic-natives", "@bastani/atomic-ai"],
|
|
30
|
+
};
|
|
30
31
|
|
|
31
|
-
export default nextConfig;
|
|
32
|
-
```
|
|
32
|
+
export default nextConfig;
|
|
33
|
+
```
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
List any other Atomic packages your server imports directly, including [`@bastani/atomic-storage-postgres`](/libraries/storage-postgres) when storing sessions in PostgreSQL (see [Configure session storage](/sdk/storage)).
|
|
36
|
+
</Step>
|
|
37
|
+
<Step title="Use the Node.js runtime and Atomic's TypeBox subpath">
|
|
38
|
+
Every route handler that imports Atomic must run on the Node.js runtime, not Edge:
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
```typescript
|
|
41
|
+
export const runtime = "nodejs";
|
|
42
|
+
```
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export const runtime = "nodejs";
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Import Atomic only from server code. Client components may use `import type` from `@bastani/atomic`, which adds zero bytes to the browser bundle.
|
|
44
|
+
Import Atomic only from server code (client components may use `import type` from `@bastani/atomic`, which adds zero bytes to the browser bundle). When defining custom tool schemas, import TypeBox from `@bastani/atomic/typebox` (and its subpaths such as `/value`, `/compile`, and `/format`) so custom formats share Atomic's validation registry.
|
|
45
|
+
</Step>
|
|
46
|
+
</Steps>
|
|
45
47
|
|
|
46
48
|
## Keep one session per conversation
|
|
47
49
|
|
|
@@ -126,9 +128,11 @@ if (!state.shutdownRegistered) {
|
|
|
126
128
|
}
|
|
127
129
|
```
|
|
128
130
|
|
|
129
|
-
|
|
131
|
+
<Warning>
|
|
132
|
+
Sessions stored on `globalThis` live in one Node.js server process. Run this pattern on a long-lived server with sticky routing per conversation if you scale to multiple instances; short-lived serverless functions discard process memory between requests.
|
|
133
|
+
</Warning>
|
|
130
134
|
|
|
131
|
-
|
|
135
|
+
`SessionManager.inMemory()` keeps history only in RAM. To persist conversations across restarts or share them across servers, pass a SQLite, JSONL, or PostgreSQL `SessionManager` or `sessionStore` (see [Configure session storage](/sdk/storage)). Call `closeConversation()` when a conversation finishes or goes idle, and run `closeAllConversations()` on `SIGTERM`/`SIGINT` so session stores and child processes close cleanly.
|
|
132
136
|
|
|
133
137
|
## Stream a prompt
|
|
134
138
|
|
|
@@ -219,9 +223,8 @@ Key behaviors:
|
|
|
219
223
|
- **One prompt at a time:** `session.prompt()` rejects while streaming, so the route returns `409` and flips `busy` synchronously to prevent races. To queue prompts instead of rejecting, call `session.prompt(message, { streamingBehavior: "followUp" })`.
|
|
220
224
|
- **Stop on disconnect:** When the browser disconnects or aborts `fetch`, `request.signal` and `cancel()` call `session.abort()`, stopping the current turn and tools while keeping the session reusable.
|
|
221
225
|
- **Payload throttling:** Each line emits the complete transcript so far. For long responses, throttle updates on a short timer or send incremental diffs.
|
|
222
|
-
- **
|
|
223
|
-
|
|
224
|
-
`createTranscript()` returns a tool result's text by default. To send structured `details` for specific tools instead, pass `createTranscript({ toolResult: (toolName) => (toolName === "todo" ? "details" : "content") })`.
|
|
226
|
+
- **Structured tool details:** `createTranscript()` returns a tool result's text by default. Pass `createTranscript({ toolResult: (toolName) => (toolName === "todo" ? "details" : "content") })` to emit structured `details` for specific tools.
|
|
227
|
+
- **Error sanitization:** Log raw errors server-side and return generic user-safe messages to the browser.
|
|
225
228
|
|
|
226
229
|
## Read the stream in the browser
|
|
227
230
|
|
|
@@ -266,19 +269,30 @@ Render each part by `type`: `text` and `thinking` hold strings, and a `toolCall`
|
|
|
266
269
|
|
|
267
270
|
## Secure the endpoint
|
|
268
271
|
|
|
269
|
-
|
|
272
|
+
<Warning>
|
|
273
|
+
Atomic has [no built-in sandbox](/security#no-built-in-sandbox). Any HTTP route driving an agent session lets callers execute enabled tools with the server process's OS permissions, and `cwd` does not jail file tools to that directory.
|
|
274
|
+
</Warning>
|
|
270
275
|
|
|
271
276
|
- **Require authentication** on every route that creates sessions or sends prompts, and scope conversation IDs to the authenticated user.
|
|
272
|
-
- **Allow only needed tools.** `tools` is an allowlist; the example enables only read-only `read`, `find`, and `search`. Omit `bash`, `edit`, and `write` unless the agent must mutate files or run commands. `excludedTools`
|
|
277
|
+
- **Allow only needed tools.** `tools` is an allowlist; the example enables only read-only `read`, `find`, and `search`. Omit `bash`, `edit`, and `write` unless the agent must mutate files or run commands. Use `excludedTools` to strip specific tools or `noTools: "all"` to expose none, and omit `ask_user_question` in headless servers. See [Tools](/sdk/reference#tools).
|
|
273
278
|
- **Disable unused builtins.** Turn off `subagents`, `mcp`, `web-access`, and `intercom` via `builtins` when not required.
|
|
274
|
-
- **Choose `cwd` deliberately.** `cwd` sets the starting directory for relative
|
|
279
|
+
- **Choose `cwd` deliberately.** `cwd` sets the starting directory for relative paths and project discovery, but tools can still access absolute paths outside `cwd`. Point `cwd` at a controlled directory, never user input.
|
|
275
280
|
- **Isolate the process** in a container, VM, or restricted OS account whenever callers must not reach other server files or when write/shell tools are enabled. See [Containerization](/containerization).
|
|
276
281
|
- **Keep credentials server-side.** Provider keys live in the server's `ModelRuntime`. Never forward them to browsers or accept raw keys from untrusted clients.
|
|
277
282
|
|
|
278
283
|
## Next steps
|
|
279
284
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
+
<Columns cols={2}>
|
|
286
|
+
<Card title="Use the TypeScript SDK" href="/sdk">
|
|
287
|
+
Sessions, prompting, workspaces, Intercom policies, and lifecycle hooks.
|
|
288
|
+
</Card>
|
|
289
|
+
<Card title="Configure session storage" href="/sdk/storage">
|
|
290
|
+
Persist server sessions in SQLite, JSONL, or PostgreSQL and wire `createAgentSessionRuntime()`.
|
|
291
|
+
</Card>
|
|
292
|
+
<Card title="SDK API reference" href="/sdk/reference">
|
|
293
|
+
Every `createAgentSession()` option, runtime method, error class, and export.
|
|
294
|
+
</Card>
|
|
295
|
+
<Card title="Orchestration" href="/orchestration">
|
|
296
|
+
Multi-step workflows with codemode and subagents, plus [migrating older workflows](/orchestration/migrating-workflows).
|
|
297
|
+
</Card>
|
|
298
|
+
</Columns>
|