@bastani/atomic 0.10.9-alpha.1 → 0.10.10-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 +69 -0
- package/README.md +211 -155
- 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 +27 -12
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +47 -7
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
- package/dist/_shared/mode-shared-2QJSCUM6.js +48 -19
- package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
- package/dist/_shared/{p1a-prewarm-UQY3X2UK.js → p1a-prewarm-XIU57JHF.js} +5 -5
- package/dist/_shared/{p1a-prewarm-UQY3X2UK.js.map → p1a-prewarm-XIU57JHF.js.map} +1 -1
- package/dist/_shared/p2-shell-main-B2WIALFD.js +30 -25
- package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +5 -5
- package/dist/_shared/{sdk-OSBEPR3Q.js → sdk-RRLVN7ER.js} +15 -9
- package/dist/_shared/sdk-RRLVN7ER.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/settings-startup-8-DNZ2RIHM.js +4 -1
- package/dist/_shared/settings-startup-8-DNZ2RIHM.js.map +1 -1
- package/dist/_shared/{startup-0-0-TYUFUOJZ.js → startup-0-0-4VG2G44V.js} +427 -33
- package/dist/_shared/startup-0-0-4VG2G44V.js.map +1 -0
- package/dist/_shared/{startup-0-1-W2G2UY7R.js → startup-0-1-XTIL65D4.js} +18 -11
- package/dist/_shared/startup-0-1-XTIL65D4.js.map +1 -0
- package/dist/_shared/{startup-0-2-UXBUEOXW.js → startup-0-2-27OWFHV6.js} +145 -58
- package/dist/_shared/startup-0-2-27OWFHV6.js.map +1 -0
- package/dist/_shared/startup-0-3-T4DVFYWX.js +15 -25
- package/dist/_shared/startup-0-3-T4DVFYWX.js.map +1 -1
- package/dist/_shared/{startup-0-4-HN5EB4K7.js → startup-0-4-ZMJV547D.js} +81 -12
- package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -0
- package/dist/_shared/startup-0-5-FD2P735I.js +90 -50
- package/dist/_shared/startup-0-5-FD2P735I.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +5 -5
- package/dist/_shared/startup-12-0-55AAXBJZ.js +13 -7
- package/dist/_shared/startup-12-0-55AAXBJZ.js.map +1 -1
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
- package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
- package/dist/_shared/startup-15-1-4S7FLMNG.js +88 -28
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +5 -5
- package/dist/_shared/startup-8-1-4KANEHRA.js +61 -17
- package/dist/_shared/startup-8-1-4KANEHRA.js.map +1 -1
- package/dist/_shared/storage-command-7MGXLJGZ.js +4 -4
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/README.md +85 -114
- package/dist/builtin/intercom/broker/broker.bundle.mjs +3 -3
- package/dist/builtin/intercom/broker/presence-handler.ts +1 -1
- package/dist/builtin/intercom/group.ts +7 -3
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/README.md +37 -27
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +8 -0
- package/dist/builtin/subagents/README.md +71 -138
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +213 -74
- package/dist/builtin/web-access/CHANGELOG.md +9 -0
- package/dist/builtin/web-access/README.md +60 -87
- package/dist/builtin/web-access/index.bundle.mjs +387 -351
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +4 -4
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +2 -2
- 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.code.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 +2 -2
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +2 -2
- 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 +2 -2
- 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 +2 -2
- 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/agent-session-methods.d.ts +4 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/compaction/compactor.d.ts +20 -14
- package/dist/core/compaction/errors.d.ts +120 -0
- package/dist/core/compaction/index.d.ts +1 -0
- package/dist/core/compaction/model-resolver.d.ts +2 -2
- 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.code.js +1 -1
- 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/api-types.d.ts +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- 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.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +1 -1
- package/dist/core/extensions/provider-types.d.ts +18 -6
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/extensions/runner-context.js +1 -1
- 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 +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/model-config.d.ts +40 -0
- package/dist/core/model-registry.js +1 -1
- package/dist/core/model-resolver-scope.d.ts +4 -4
- package/dist/core/model-runtime.d.ts +1 -1
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/provider-composer-internal.d.ts +11 -2
- package/dist/core/sdk.code.js +3 -3
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +5 -5
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.code.js +1 -1
- 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/settings-manager-basic-accessors.d.ts +6 -2
- 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 +3 -3
- 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 +2 -2
- 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 +3 -3
- 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 +3 -3
- 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 +3 -3
- 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 +3 -3
- 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 +3 -3
- 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 +4 -4
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.code.js +1 -1
- 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.code.js +2 -2
- 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 +3 -3
- 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.code.js +1 -1
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.code.js +2 -2
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +2 -2
- 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-extensions.d.ts +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +7 -7
- package/dist/main-first-time-setup.code.js +2 -2
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/settings-selector-types.d.ts +1 -0
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
- 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/interactive/theme/color-utils.d.ts +5 -5
- package/dist/modes/interactive/theme/theme-loading.d.ts +1 -0
- package/dist/modes/interactive-engine/engine-prewarm.js +1 -1
- package/dist/modes/interactive-engine/remote-model-catalog.d.ts +1 -0
- package/dist/modes/print-mode.js +1 -1
- package/dist/modes/rpc/rpc-client-api.d.ts +6 -0
- package/dist/modes/rpc/rpc-types.d.ts +29 -2
- package/dist/package-manager-cli.code.js +5 -5
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/rpc-entry.js +1 -1
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/7.js +1 -1
- package/dist/startup-stages/8.js +1 -2
- package/dist/startup-stages/9.js +2 -1
- package/dist/utils/native-module.d.ts +44 -0
- package/dist/utils/startup-database-spare.code.js +3 -3
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/background-tasks.md +235 -243
- package/docs/build.md +12 -11
- package/docs/codemode.md +60 -51
- package/docs/compaction/reference.md +61 -24
- package/docs/compaction.md +117 -65
- package/docs/computer-use.md +179 -146
- package/docs/containerization.md +79 -33
- package/docs/custom-provider/api-reference.md +148 -11
- package/docs/custom-provider/oauth.md +44 -27
- package/docs/custom-provider/override.md +14 -7
- package/docs/custom-provider/registration.md +75 -65
- package/docs/custom-provider/streaming.md +42 -19
- package/docs/custom-provider.md +25 -61
- package/docs/development.md +47 -43
- package/docs/docs.json +33 -33
- package/docs/environment-variables.md +83 -57
- package/docs/extensions/api-reference.md +323 -734
- package/docs/extensions/authoring.md +186 -269
- package/docs/extensions/events.md +308 -375
- package/docs/extensions/examples.md +122 -74
- package/docs/extensions/ui.md +217 -197
- package/docs/extensions.md +152 -259
- package/docs/getting-started/authentication.md +27 -14
- package/docs/getting-started/first-session.md +25 -26
- package/docs/getting-started/installation.md +62 -84
- package/docs/getting-started/project-instructions.md +39 -14
- package/docs/guides/configuration.md +42 -20
- package/docs/guides/intercom.md +17 -13
- package/docs/guides/non-interactive.md +29 -16
- package/docs/guides/orchestration.md +16 -10
- package/docs/guides/resume-on-any-machine.md +54 -49
- package/docs/guides/subagents.md +22 -14
- package/docs/guides/team-setup.md +37 -26
- package/docs/guides.md +22 -21
- package/docs/herdr.md +21 -16
- package/docs/index.md +16 -17
- package/docs/intercom/operations.md +68 -66
- package/docs/intercom/reference.md +196 -191
- package/docs/intercom.md +103 -92
- package/docs/json.md +71 -71
- package/docs/keybindings.md +63 -50
- package/docs/libraries/agent-core.md +49 -8
- package/docs/libraries/ai.md +21 -12
- package/docs/libraries/codemode.md +28 -6
- package/docs/libraries/schema.md +7 -7
- package/docs/libraries/telemetry.md +7 -7
- package/docs/libraries/tui.md +74 -94
- package/docs/libraries.md +5 -5
- package/docs/llama-cpp.md +38 -33
- package/docs/mcp-servers.md +96 -90
- package/docs/models/reference.md +46 -33
- package/docs/models-configuration.md +12 -6
- package/docs/models.md +93 -88
- package/docs/orchestration/migrating-workflows.md +21 -19
- package/docs/orchestration/patterns.md +35 -20
- package/docs/orchestration.md +22 -21
- package/docs/packages/authoring.md +28 -19
- package/docs/packages/reference.md +75 -16
- package/docs/packages.md +31 -33
- package/docs/programmatic.md +22 -21
- package/docs/prompt-templates.md +63 -41
- package/docs/providers/reference.md +35 -19
- package/docs/providers.md +61 -71
- package/docs/quickstart.md +32 -46
- package/docs/reference/cli.md +249 -252
- package/docs/reference.md +23 -20
- package/docs/rpc/examples.md +74 -17
- package/docs/rpc/extension-ui.md +79 -62
- package/docs/rpc/protocol.md +816 -358
- package/docs/rpc.md +75 -151
- package/docs/sdk/reference.md +175 -45
- package/docs/sdk/structured-decisions.md +92 -62
- package/docs/sdk/web-server.md +79 -46
- package/docs/sdk.md +237 -195
- package/docs/security.md +106 -43
- package/docs/session-format.md +96 -59
- package/docs/sessions.md +149 -113
- package/docs/settings.md +289 -204
- package/docs/shell-aliases.md +15 -6
- package/docs/skills/authoring.md +17 -9
- package/docs/skills/reference.md +23 -21
- package/docs/skills.md +104 -97
- package/docs/storage.md +140 -242
- package/docs/subagents/authoring.md +147 -16
- package/docs/subagents/reference.md +100 -30
- package/docs/subagents.md +220 -252
- package/docs/terminal-setup.md +97 -69
- package/docs/termux.md +51 -85
- package/docs/themes/reference.md +51 -37
- package/docs/themes.md +49 -54
- package/docs/tmux.md +38 -21
- package/docs/tools.md +198 -147
- package/docs/tui/reference.md +64 -32
- package/docs/tui.md +38 -66
- package/docs/usage.md +76 -78
- package/docs/verification.md +25 -25
- package/docs/web-access.md +72 -55
- package/docs/windows.md +53 -58
- package/docs/worktree-snapshots.md +62 -65
- package/package.json +8 -8
- package/schemas/models.schema.json +51 -0
- package/dist/_shared/sdk-OSBEPR3Q.js.map +0 -1
- package/dist/_shared/startup-0-0-TYUFUOJZ.js.map +0 -1
- package/dist/_shared/startup-0-1-W2G2UY7R.js.map +0 -1
- package/dist/_shared/startup-0-2-UXBUEOXW.js.map +0 -1
- package/dist/_shared/startup-0-4-HN5EB4K7.js.map +0 -1
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Structured decisions
|
|
3
|
-
|
|
2
|
+
title: "Structured decisions API"
|
|
3
|
+
sidebarTitle: "Structured decisions"
|
|
4
|
+
description: "Make typed, schema-validated classifier or chat model decisions with decide() and generateStructuredOutput() without starting an agent session."
|
|
4
5
|
---
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
Atomic provides one decision service across three entry points:
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
- [`decide()`](#decide) asks the configured [`decisionModel`](/settings#decisionmodel) typed `choice`, `bool`, and `score` questions and returns typed answers with optional probabilities.
|
|
10
|
+
- The `structured_output` tool uses the same decision model and raises `DecisionError` subclasses on failure.
|
|
11
|
+
- `generateStructuredOutput()` from `@bastani/atomic` makes one schema-validated decision on the models you pass through the same runtime.
|
|
9
12
|
|
|
10
|
-
None of these APIs starts a child agent,
|
|
13
|
+
None of these APIs starts a child agent, invokes other tools, authorizes an action, or changes the selected chat model.
|
|
11
14
|
|
|
12
|
-
## decide
|
|
15
|
+
## Make typed decisions with `decide()` {#decide}
|
|
13
16
|
|
|
14
|
-
`decide({ state, questions,
|
|
17
|
+
`decide({ state, questions, settings, modelRegistry, currentModel, ... })` evaluates one or more independent named questions against one `state` object in a single request:
|
|
15
18
|
|
|
16
|
-
- `choice`: pick one option. `criteria` maps each option to its meaning.
|
|
17
|
-
- `bool`: a yes/no question
|
|
18
|
-
- `score`: grade on ordered levels. `criteria` lists at least two
|
|
19
|
+
- `choice`: pick one option. `criteria` maps each option name to its meaning.
|
|
20
|
+
- `bool`: a yes/no question. `criteria` defines what `true` and `false` mean.
|
|
21
|
+
- `score`: grade on ordered levels. `criteria` lists at least two level descriptions, lowest first.
|
|
19
22
|
|
|
20
|
-
`decide()` resolves `decisionModel` once. When a classifier answers,
|
|
21
|
-
|
|
22
|
-
If the classifier fails, the current chat model answers without probabilities, sets `source: "chat"`, and includes a `fallback` object. An empty or `"auto"` `decisionModel` uses the current chat model directly. Pass `requireProbabilities: true` when your code requires probabilities: only a classifier may answer, and a chat decision model or classifier failure rejects instead of falling back.
|
|
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.
|
|
23
24
|
|
|
24
25
|
```typescript
|
|
25
26
|
import { decide, isDecisionError } from "@bastani/atomic";
|
|
@@ -46,61 +47,92 @@ const result = await decide({
|
|
|
46
47
|
});
|
|
47
48
|
const approve = result.answers.intent.probabilities?.approve ?? 0;
|
|
48
49
|
if (approve >= 0.9 && (result.answers.complete.probability ?? 0) >= 0.8) {
|
|
49
|
-
//
|
|
50
|
+
// Application code decides what to do at each threshold.
|
|
50
51
|
}
|
|
51
52
|
```
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
### Request options
|
|
54
55
|
|
|
55
|
-
`
|
|
56
|
+
- `state`: non-empty plain JSON object containing the facts to evaluate.
|
|
57
|
+
- `questions`: non-empty record mapping caller-chosen IDs to `choice`, `bool`, or `score` question definitions.
|
|
58
|
+
- `instructions`: optional top-level context shared across all questions. Defaults to ``"Answer each question about `state`."`` and must be non-blank if supplied.
|
|
59
|
+
- `deadline`: optional positive integer wall-clock limit in milliseconds covering credential screening, requests, retries, repairs, and fallbacks. Defaults to [`httpIdleTimeoutMs`](/settings#http).
|
|
60
|
+
- `retry`: optional `RetryPolicy` overriding default chat retries (`{ enabled: true, maxRetries: 3, baseDelayMs: 2000 }`).
|
|
61
|
+
- `signal`: optional `AbortSignal`; cancellation rejects immediately with the signal's reason.
|
|
62
|
+
- `model`: optional exact `provider/model` ID to use instead of `decisionModel`.
|
|
63
|
+
- `requireProbabilities`: when `true`, only a classifier may answer.
|
|
56
64
|
|
|
57
|
-
|
|
58
|
-
- `signal`: cancels the decision and rejects with the signal's reason.
|
|
59
|
-
- `model`: names an exact `provider/model` ID to use instead of `decisionModel`.
|
|
60
|
-
- Credential screening: Atomic refuses `state` containing an environment credential, key-shaped text, or a saved credential known to `modelRegistry` before sending any model request. Atomic copies `state` before asynchronous screening, so mutating the caller's object later does not alter an in-flight decision.
|
|
65
|
+
### Return value (`DecisionResult`)
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
`decide()` resolves with:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
interface DecisionResult<Q> {
|
|
71
|
+
answers: Record<keyof Q, DecisionAnswer>;
|
|
72
|
+
source: "classifier" | "chat";
|
|
73
|
+
model: string;
|
|
74
|
+
responseModel: string;
|
|
75
|
+
usage: { inputTokens: number; outputTokens: number };
|
|
76
|
+
fallback?: { from: string; to: string; reason: string };
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Each entry in `result.answers.<id>` matches its question type:
|
|
81
|
+
|
|
82
|
+
- **`choice`:** `{ type: "choice", choice: string, probabilities?: Record<string, number>, confidence?: number }`.
|
|
83
|
+
- **`bool`:** `{ type: "bool", value: boolean, probability?: number }`. When a classifier answers, `value` is `probability >= 0.5`.
|
|
84
|
+
- **`score`:** `{ type: "score", score: number, confidence?: number }`. Levels are 0-indexed from `0` to `criteria.length - 1`: chat models return an integer index, while classifiers return a numeric score (rounded during validation).
|
|
63
85
|
|
|
64
|
-
|
|
86
|
+
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.
|
|
65
87
|
|
|
66
|
-
|
|
88
|
+
### Credential screening boundary
|
|
67
89
|
|
|
68
|
-
|
|
90
|
+
`decide()` actively screens `state` before sending any request. It snapshots `state` (so later caller mutations cannot alter an in-flight call) and rejects with `DecisionRequestError` (`reason: "credential-in-state"`) if `state` contains:
|
|
69
91
|
|
|
70
|
-
|
|
92
|
+
- any known environment credential,
|
|
93
|
+
- `Bearer` tokens, PEM private keys, or `sk-`, `ghp_`, or `github_pat_` key patterns, or
|
|
94
|
+
- a credential configured in `modelRegistry`.
|
|
71
95
|
|
|
72
|
-
|
|
96
|
+
`generateStructuredOutput()` does **not** run automatic credential screening. Always strip secrets from `state` and `instructions` yourself before calling `generateStructuredOutput()`.
|
|
97
|
+
|
|
98
|
+
### Errors
|
|
99
|
+
|
|
100
|
+
Every failure from `decide()` rejects with a `DecisionError`. Branch on the error class or `code`, never on message text.
|
|
101
|
+
|
|
102
|
+
Each error includes `hint`, `retryable`, and `cause`. `isDecisionError(error)` and the per-class guards recognize errors across process boundaries. Use `serializeDecisionError()` and `rehydrateDecisionError()` to transport errors between processes, and `findDecisionError(error)` or `isRetryableDecisionError(error)` to walk a `cause` chain. Validate untrusted serialized payloads with `parseSerializedDecisionError()` before calling `rehydrateDecisionError()` (returns `undefined` when malformed).
|
|
103
|
+
|
|
104
|
+
Legacy `routerModel` settings migrate to `decisionModel` automatically. An existing `decisionModel` takes precedence, and invalid legacy values are ignored with a one-time warning. See [decisionModel](/settings#decisionmodel).
|
|
105
|
+
|
|
106
|
+
| Class | `code` | When | Fields | What to do |
|
|
73
107
|
| --- | --- | --- | --- | --- |
|
|
74
|
-
| `DecisionConfigError` | `invalid-setting` | `decisionModel` is not a string or has surrounding whitespace | `source`, `field` | Set an exact `provider/model`, `auto
|
|
75
|
-
| `DecisionRequestError` | `invalid-request` | Empty or non-JSON `state`, credential in `state`, no questions,
|
|
76
|
-
| `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
|
|
77
|
-
| `DecisionTimeoutError` | `timeout` | The deadline
|
|
78
|
-
| `DecisionOutputError` | `invalid-output` | The model
|
|
79
|
-
| `DecisionProviderError` | `provider-failure` | The
|
|
108
|
+
| `DecisionConfigError` | `invalid-setting` (or legacy decode-only `renamed-setting`) | `decisionModel` is not a string or has surrounding whitespace | `source`, `field`, optional `scope` (`"global" \| "project"`) | Set an exact `provider/model`, `"auto"`, or `""`. |
|
|
109
|
+
| `DecisionRequestError` | `invalid-request` | Empty or non-JSON `state`, credential in `state`, no questions, malformed question, blank `instructions`, invalid `deadline`, or invalid `model` | `field`, `reason` | Fix the request; nothing was sent. |
|
|
110
|
+
| `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. |
|
|
111
|
+
| `DecisionTimeoutError` | `timeout` | The wall-clock deadline expired | `timeoutMs`, `elapsedMs`, `phase`, `attempts` | Retry, or raise `deadline` / `timeoutMs`. Retryable. |
|
|
112
|
+
| `DecisionOutputError` | `invalid-output` | The model responded, but output failed schema validation after repairs | `model`, `detail` | Clarify questions or pick another model. |
|
|
113
|
+
| `DecisionProviderError` | `provider-failure` | The provider request failed | `model`, `providerStatus`, `providerCode`, `retryAfterMs`, `detail` | Retryable on rate limits or quota exhaustion (`providerCode`); otherwise check provider status and auth. |
|
|
80
114
|
|
|
81
|
-
##
|
|
115
|
+
## How `decisionModel` applies across APIs
|
|
82
116
|
|
|
83
|
-
- **The `structured_output` tool** (when called without its own `model`) starts on `decisionModel
|
|
84
|
-
- **`generateStructuredOutput()`** uses only the models you pass
|
|
117
|
+
- **The `structured_output` tool** (when called without its own `model`) starts on `decisionModel`. A classifier answers when the schema is a finite Choice; otherwise Atomic tries `fallbackModels` and then `currentModel`. Failures always reject with a `DecisionError`.
|
|
118
|
+
- **`generateStructuredOutput()`** uses only the models you pass (`model`, `fallbackModels`, `currentModel`) unless you pass `settings`, in which case omitting `model` starts on `decisionModel` like the tool. Note: calling `generateStructuredOutput()` **without `settings`** throws plain `Error` instances rather than `DecisionError` subclasses; `DecisionError` wrapping applies whenever `settings` is passed or when calling `decide()` or `structured_output`.
|
|
85
119
|
|
|
86
120
|
## Select the inference model
|
|
87
121
|
|
|
88
|
-
Pass an optional exact `provider/model` string
|
|
122
|
+
Pass an optional exact `provider/model` string (not a `Model` object and not `"auto"`):
|
|
89
123
|
|
|
90
|
-
- `model
|
|
91
|
-
- `fallbackModels
|
|
92
|
-
- Omit `model` to start on `decisionModel` when `settings` is passed
|
|
124
|
+
- `model`: primary candidate (chat model or registered classifier such as `typesafe/jev-latest`).
|
|
125
|
+
- `fallbackModels`: ordered list of exact `provider/model` IDs.
|
|
126
|
+
- Omit `model` to start on `decisionModel` when `settings` is passed, or on `currentModel` otherwise.
|
|
93
127
|
- After `model` and `fallbackModels`, Atomic tries `currentModel` if it has not already been tried.
|
|
94
128
|
|
|
95
|
-
Image-generation models,
|
|
96
|
-
|
|
97
|
-
A catalog entry does not guarantee that the provider can classify, that credentials work, or that quota remains. When `model` is omitted and `settings` is passed, `decisionModel` is never skipped: an unregistered or invalid `decisionModel` fails immediately with a [`DecisionError`](#errors).
|
|
129
|
+
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.
|
|
98
130
|
|
|
99
131
|
### Choice-compatible schemas
|
|
100
132
|
|
|
101
|
-
|
|
133
|
+
Classifiers answer finite Choice schemas: literal unions, enums, booleans, and flat closed objects (`additionalProperties: false`) whose required fields all use those types. Free-form text, unconstrained numbers, arrays, optional fields, and nested objects are incompatible; Atomic skips classifier candidates for those schemas, records each skip in `modelAttempts`, and advances to chat fallbacks.
|
|
102
134
|
|
|
103
|
-
Pass the session `modelRegistry
|
|
135
|
+
Pass the session `modelRegistry` so classifier credentials resolve from its login store (such as `/login typesafe` or `TYPESAFE_API_KEY`). Never copy API keys into `state`.
|
|
104
136
|
|
|
105
137
|
```typescript
|
|
106
138
|
import { Type } from "@bastani/atomic/typebox";
|
|
@@ -127,42 +159,40 @@ const result = await generateStructuredOutput({
|
|
|
127
159
|
console.log(result.value.category, result.model);
|
|
128
160
|
```
|
|
129
161
|
|
|
130
|
-
`result.value` holds the schema-validated
|
|
162
|
+
`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.
|
|
131
163
|
|
|
132
|
-
|
|
164
|
+
`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 validate invariants before acting.
|
|
133
165
|
|
|
134
|
-
The `structured_output` tool accepts required `instructions`,
|
|
166
|
+
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).
|
|
135
167
|
|
|
136
168
|
## Prepare a decision
|
|
137
169
|
|
|
138
|
-
|
|
170
|
+
Put the task criteria in `instructions` and all relevant facts, constraints, and text snippets in named `state` fields. File paths and URLs identify sources, but do not substitute for their contents. Exclude secrets from both `state` and `instructions`.
|
|
139
171
|
|
|
140
|
-
For `generateStructuredOutput()`, supply `instructions`, `state`, and `schema
|
|
172
|
+
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.
|
|
141
173
|
|
|
142
174
|
## Provider behavior and limits
|
|
143
175
|
|
|
144
|
-
Chat candidates receive one internal result tool
|
|
145
|
-
|
|
146
|
-
The public `structured_output` tool is separate: its parameters are `instructions`, `state`, and optional model selectors, and its result is the inferred value.
|
|
176
|
+
Chat candidates receive one internal result tool matching `schema`. Atomic serializes schemas per provider, enables strict sampling where supported, and validates returned arguments without type coercion or stripping extra keys. Always set `additionalProperties: false` on closed objects. Prose-only replies, extra tool calls, truncated output, or invalid payloads trigger up to 3 repair attempts (1 initial attempt plus 3 repairs) before advancing to the next fallback candidate.
|
|
147
177
|
|
|
148
|
-
Use `Type.Optional(...)` for fields that may be omitted. When a strict provider encodes an omitted optional
|
|
178
|
+
Use `Type.Optional(...)` for fields that may be omitted. When a strict 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.
|
|
149
179
|
|
|
150
|
-
Chat decisions use HTTP/SSE
|
|
180
|
+
Chat decisions use HTTP/SSE transport (not WebSocket fallback) and disable configured Anthropic server-side fallbacks. Transient chat transport errors follow `retry` (default `{ enabled: true, maxRetries: 3, baseDelayMs: 2000 }`). Classifier calls invoke the provider's `classify` method with the retry limit and abort signal; provider implementations own transport retries.
|
|
151
181
|
|
|
152
|
-
|
|
182
|
+
Registered classifiers (such as [TypeSafe Jev](/providers#typesafe-jev)) receive `state` and derived choice questions in one `classify` call without trimming `state`. If a classifier rejects the size or context, or cannot represent the schema, Atomic skips or advances to the next candidate without retrying the rejected request.
|
|
153
183
|
|
|
154
|
-
Atomic
|
|
184
|
+
Atomic verifies that every classifier answer chooses a valid option. Reported model names, probabilities, and confidence values are advisory and never reject an otherwise valid answer.
|
|
155
185
|
|
|
156
186
|
## Cancellation and failures
|
|
157
187
|
|
|
158
|
-
One wall-clock deadline covers the entire call: every repair attempt, transport retry, and fallback candidate
|
|
188
|
+
One wall-clock deadline covers the entire call: every repair attempt, transport retry, and fallback candidate combined. Configure it with `timeoutMs` (or `deadline` in `decide()`) as a positive safe integer in milliseconds. Atomic checks the deadline before every retry so overdue backoffs never start another request.
|
|
159
189
|
|
|
160
|
-
When
|
|
190
|
+
When omitted, `structured_output` uses the session's [`httpIdleTimeoutMs`](/settings#http) setting and standalone calls default to 10 minutes. Disabling the idle timeout (`0` or `"disabled"`) leaves only the JavaScript timer limit (~24.8 days). Increase the deadline for slow reasoning models or large `state` payloads.
|
|
161
191
|
|
|
162
|
-
When the deadline expires, Atomic
|
|
192
|
+
When the deadline expires, Atomic aborts the in-flight request (even if the provider ignores abort signals) and rejects with `DecisionTimeoutError`, including the deadline, phase, hint, and per-attempt timings (for example, `Attempts: 1) stopReason=stop 25m02s; 2) still generating 4m58s.`). Timeouts are final and do not trigger further repairs or fallbacks.
|
|
163
193
|
|
|
164
|
-
Pass an `AbortSignal` (such as `AbortSignal.timeout(
|
|
194
|
+
Pass an `AbortSignal` (such as `AbortSignal.timeout(ms)`) to cancel sooner; cancellation rejects immediately and halts the fallback chain.
|
|
165
195
|
|
|
166
|
-
|
|
196
|
+
`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.
|
|
167
197
|
|
|
168
|
-
Provider errors report static reasons without raw response bodies or credentials. Classifier failures
|
|
198
|
+
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,16 +1,12 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
sidebarTitle: "Web server"
|
|
4
|
-
description: "Run Atomic sessions behind a Next.js App Router
|
|
2
|
+
title: "Embed Atomic in a web server"
|
|
3
|
+
sidebarTitle: "Web server guide"
|
|
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
|
-
|
|
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 a prompt per request, and stream session events back as newline-delimited JSON (NDJSON).
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Read the [SDK](/sdk) page first for `createAgentSession()`, `AgentSession`, `AgentSessionRuntime`, and session events.
|
|
12
|
-
|
|
13
|
-
The examples below use `createAgentSession()`, `ModelRuntime`, `SessionManager`, and `createTranscript()` from `@bastani/atomic`. 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 [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)).
|
|
14
10
|
|
|
15
11
|
## Install
|
|
16
12
|
|
|
@@ -18,13 +14,15 @@ The examples below use `createAgentSession()`, `ModelRuntime`, `SessionManager`,
|
|
|
18
14
|
npm install @bastani/atomic
|
|
19
15
|
```
|
|
20
16
|
|
|
21
|
-
Atomic requires Node.js 22.19 or newer. Dependency install scripts are not required; if your package manager
|
|
17
|
+
Atomic requires Node.js 22.19 or newer. Dependency install scripts are not required; if your package manager blocks install scripts, leave them disabled.
|
|
18
|
+
|
|
19
|
+
On Node 22, pass `--experimental-async-context-frame` on the server's `node` command line (not in `NODE_OPTIONS`) to avoid `AsyncLocalStorage` promise-hook overhead across concurrent HTTP requests; see [Node 22 hosts](/sdk#node-22-hosts).
|
|
22
20
|
|
|
23
21
|
## Keep Atomic out of the server bundle
|
|
24
22
|
|
|
25
|
-
Atomic
|
|
23
|
+
Atomic resolves its bundled resources and native modules relative to `node_modules`, so keep it outside Next.js's server bundle using `serverExternalPackages` (Next.js 15 and later):
|
|
26
24
|
|
|
27
|
-
```
|
|
25
|
+
```typescript
|
|
28
26
|
// next.config.ts
|
|
29
27
|
import type { NextConfig } from "next";
|
|
30
28
|
|
|
@@ -35,23 +33,23 @@ const nextConfig: NextConfig = {
|
|
|
35
33
|
export default nextConfig;
|
|
36
34
|
```
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
Once `@bastani/atomic` is external, its dependencies load from `node_modules`. List any other Atomic packages your application imports directly.
|
|
39
37
|
|
|
40
|
-
Import TypeBox for tool schemas from `@bastani/atomic/typebox` (and
|
|
38
|
+
Import TypeBox for custom tool schemas from `@bastani/atomic/typebox` (and its subpaths such as `/value`, `/compile`, and `/format`) rather than `typebox` directly so custom formats and settings share Atomic's TypeBox registry.
|
|
41
39
|
|
|
42
|
-
Every route that imports Atomic must
|
|
40
|
+
Every route that imports Atomic must run on the Node.js runtime:
|
|
43
41
|
|
|
44
|
-
```
|
|
42
|
+
```typescript
|
|
45
43
|
export const runtime = "nodejs";
|
|
46
44
|
```
|
|
47
45
|
|
|
48
|
-
Import Atomic only from server code. Client components may use `import type` from `@bastani/atomic`, which adds
|
|
46
|
+
Import Atomic only from server code. Client components may use `import type` from `@bastani/atomic`, which adds zero bytes to the browser bundle.
|
|
49
47
|
|
|
50
48
|
## Keep one session per conversation
|
|
51
49
|
|
|
52
|
-
An `AgentSession`
|
|
50
|
+
An `AgentSession` owns the conversation history, so create one per conversation and reuse it across requests. Store shared state on `globalThis` so `next dev` hot reloads preserve active sessions without leaking them. Restart the dev server after changing session options because existing sessions keep their creation options.
|
|
53
51
|
|
|
54
|
-
```
|
|
52
|
+
```typescript
|
|
55
53
|
// lib/atomic.ts
|
|
56
54
|
import "server-only";
|
|
57
55
|
import { type AgentSession, createAgentSession, ModelRuntime, SessionManager } from "@bastani/atomic";
|
|
@@ -64,20 +62,31 @@ export interface Conversation {
|
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
interface AtomicState {
|
|
67
|
-
modelRuntime
|
|
65
|
+
modelRuntime?: Promise<ModelRuntime>;
|
|
68
66
|
conversations: Map<string, Promise<Conversation>>;
|
|
67
|
+
shutdownRegistered?: boolean;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
const shared = globalThis as typeof globalThis & { atomicState?: AtomicState };
|
|
72
71
|
const state = (shared.atomicState ??= {
|
|
73
|
-
modelRuntime: ModelRuntime.create(),
|
|
74
72
|
conversations: new Map(),
|
|
75
73
|
});
|
|
76
74
|
|
|
75
|
+
function getModelRuntime(): Promise<ModelRuntime> {
|
|
76
|
+
if (!state.modelRuntime) {
|
|
77
|
+
// Clear cached promise on startup failure so a later request can retry.
|
|
78
|
+
state.modelRuntime = ModelRuntime.create().catch((error) => {
|
|
79
|
+
state.modelRuntime = undefined;
|
|
80
|
+
throw error;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return state.modelRuntime;
|
|
84
|
+
}
|
|
85
|
+
|
|
77
86
|
export function getConversation(id: string): Promise<Conversation> {
|
|
78
87
|
let conversation = state.conversations.get(id);
|
|
79
88
|
if (!conversation) {
|
|
80
|
-
conversation =
|
|
89
|
+
conversation = getModelRuntime().then(async (modelRuntime) => {
|
|
81
90
|
const { session } = await createAgentSession({
|
|
82
91
|
cwd: WORKSPACE,
|
|
83
92
|
sessionManager: SessionManager.inMemory(WORKSPACE),
|
|
@@ -94,21 +103,40 @@ export function getConversation(id: string): Promise<Conversation> {
|
|
|
94
103
|
}
|
|
95
104
|
|
|
96
105
|
export async function closeConversation(id: string): Promise<void> {
|
|
97
|
-
const
|
|
106
|
+
const pending = state.conversations.get(id);
|
|
98
107
|
state.conversations.delete(id);
|
|
99
|
-
if (
|
|
108
|
+
if (!pending) return;
|
|
109
|
+
const conversation = await pending.catch(() => undefined);
|
|
110
|
+
if (!conversation) return;
|
|
111
|
+
// Abort active work with pauseQueuedMessages so dispose() does not wait for a running turn.
|
|
112
|
+
await conversation.session.abort({ pauseQueuedMessages: true });
|
|
113
|
+
await conversation.session.dispose();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function closeAllConversations(): Promise<void> {
|
|
117
|
+
const ids = [...state.conversations.keys()];
|
|
118
|
+
await Promise.allSettled(ids.map((id) => closeConversation(id)));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!state.shutdownRegistered) {
|
|
122
|
+
state.shutdownRegistered = true;
|
|
123
|
+
for (const signal of ["SIGTERM", "SIGINT"] as const) {
|
|
124
|
+
process.once(signal, () => {
|
|
125
|
+
void closeAllConversations().finally(() => process.exit(0));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
100
128
|
}
|
|
101
129
|
```
|
|
102
130
|
|
|
103
|
-
`SessionManager.inMemory()` keeps history in process memory. To
|
|
131
|
+
`SessionManager.inMemory()` keeps history in process memory. To persist conversations across restarts, pass a SQLite, JSONL, or database-backed `SessionManager` or `sessionStore` (see [Sessions](/sessions)). Call `closeConversation()` when a conversation finishes or goes idle, and run `closeAllConversations()` on `SIGTERM`/`SIGINT` so session stores and child processes close cleanly.
|
|
104
132
|
|
|
105
|
-
Sessions on `globalThis` live in one server process. Run this on a long-lived Node.js server
|
|
133
|
+
Sessions on `globalThis` live in one server process. Run this on a long-lived Node.js server with sticky routing per conversation if you scale to multiple instances; short-lived serverless functions discard process memory between requests.
|
|
106
134
|
|
|
107
135
|
## Stream a prompt
|
|
108
136
|
|
|
109
|
-
|
|
137
|
+
This route starts one prompt and streams the assistant's output as NDJSON. `createTranscript()` converts session events into ordered JSON-serializable parts (`text`, `thinking`, and `toolCall` paired with its `result`). Tool calls appear in `message_end` before execution begins and gain their `result` as `tool_execution_update` and `tool_execution_end` arrive, so each line carries the full output so far and the browser replaces its rendered list.
|
|
110
138
|
|
|
111
|
-
```
|
|
139
|
+
```typescript
|
|
112
140
|
// app/api/chat/route.ts
|
|
113
141
|
import { createTranscript, type TranscriptPart } from "@bastani/atomic";
|
|
114
142
|
import { getConversation } from "@/lib/atomic";
|
|
@@ -161,7 +189,11 @@ export async function POST(request: Request): Promise<Response> {
|
|
|
161
189
|
session
|
|
162
190
|
.prompt(message)
|
|
163
191
|
.then(() => send({ type: "done" }))
|
|
164
|
-
.catch((error:
|
|
192
|
+
.catch((error: unknown) => {
|
|
193
|
+
console.error("Prompt failed:", error);
|
|
194
|
+
// Sanitize errors in production instead of exposing internal paths or stack details.
|
|
195
|
+
send({ type: "error", message: "The request could not be completed." });
|
|
196
|
+
})
|
|
165
197
|
.finally(() => {
|
|
166
198
|
unsubscribe();
|
|
167
199
|
request.signal.removeEventListener("abort", stop);
|
|
@@ -184,13 +216,14 @@ export async function POST(request: Request): Promise<Response> {
|
|
|
184
216
|
}
|
|
185
217
|
```
|
|
186
218
|
|
|
187
|
-
|
|
219
|
+
Key behaviors:
|
|
188
220
|
|
|
189
|
-
- **One prompt at a time
|
|
190
|
-
- **Stop on disconnect
|
|
191
|
-
- **Payload
|
|
221
|
+
- **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" })`.
|
|
222
|
+
- **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.
|
|
223
|
+
- **Payload throttling:** Each line emits the complete transcript so far. For long responses, throttle updates on a short timer or send incremental diffs.
|
|
224
|
+
- **Error sanitization:** Log raw errors server-side and send sanitized user-safe error messages to the browser.
|
|
192
225
|
|
|
193
|
-
`createTranscript()`
|
|
226
|
+
`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") })`.
|
|
194
227
|
|
|
195
228
|
## Read the stream in the browser
|
|
196
229
|
|
|
@@ -231,22 +264,22 @@ export async function sendMessage(
|
|
|
231
264
|
}
|
|
232
265
|
```
|
|
233
266
|
|
|
234
|
-
Render each part by `type`: `text` and `thinking`
|
|
267
|
+
Render each part by `type`: `text` and `thinking` hold strings, and a `toolCall` part has `name`, `arguments`, and (once progress or completion arrives) `result` (`content`, `isError`, `isPartial`). Pass an `AbortController` signal to cancel from the UI.
|
|
235
268
|
|
|
236
269
|
## Secure the endpoint
|
|
237
270
|
|
|
238
|
-
|
|
271
|
+
Any route driving an agent session lets callers run tools with the server process's OS permissions. Atomic has [no built-in sandbox](/security#no-built-in-sandbox).
|
|
239
272
|
|
|
240
|
-
- **Require authentication** on every route that creates sessions or sends prompts, and scope conversation
|
|
241
|
-
- **Allow only
|
|
242
|
-
- **Disable builtins
|
|
243
|
-
- **Choose
|
|
244
|
-
- **Isolate the process** in a container, VM, or restricted OS account
|
|
245
|
-
- **Keep credentials
|
|
273
|
+
- **Require authentication** on every route that creates sessions or sends prompts, and scope conversation IDs to the authenticated user.
|
|
274
|
+
- **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` removes tools, and `noTools: "all"` exposes none. Omit `ask_user_question` in headless sessions. See [Tools](/sdk/reference#tools).
|
|
275
|
+
- **Disable unused builtins.** Turn off `subagents`, `mcp`, `web-access`, and `intercom` via `builtins` when not required.
|
|
276
|
+
- **Choose `cwd` deliberately.** `cwd` sets the starting directory for relative tool paths and project discovery, but does not jail file access (tools can read absolute paths outside `cwd`). Point `cwd` at a controlled directory, never user input.
|
|
277
|
+
- **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).
|
|
278
|
+
- **Keep credentials server-side.** Provider keys live in the server's `ModelRuntime`. Never forward them to browsers or accept raw keys from untrusted clients.
|
|
246
279
|
|
|
247
280
|
## Next steps
|
|
248
281
|
|
|
249
|
-
- [SDK](/sdk)
|
|
250
|
-
- [SDK API reference](/sdk/reference)
|
|
251
|
-
- [Orchestration](/orchestration)
|
|
252
|
-
- [Migrating workflows](/orchestration/migrating-workflows)
|
|
282
|
+
- [TypeScript SDK](/sdk): sessions, prompting, storage, and events.
|
|
283
|
+
- [SDK API reference](/sdk/reference): every `createAgentSession()` option and export.
|
|
284
|
+
- [Orchestration](/orchestration): multi-step workflows with codemode and subagents.
|
|
285
|
+
- [Migrating workflows](/orchestration/migrating-workflows): replacing older workflow definitions.
|