@bastani/atomic 0.10.10-alpha.1 → 0.10.10-alpha.2
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 +26 -0
- package/README.md +22 -15
- 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 +2 -2
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +2 -2
- package/dist/_shared/mode-shared-2QJSCUM6.js +2 -2
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/sdk-RRLVN7ER.js +2 -2
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/startup-0-0-4VG2G44V.js +2 -2
- package/dist/_shared/startup-0-1-XTIL65D4.js +2 -2
- package/dist/_shared/startup-0-2-27OWFHV6.js +7 -6
- package/dist/_shared/startup-0-2-27OWFHV6.js.map +1 -1
- package/dist/_shared/startup-0-3-T4DVFYWX.js +2 -2
- package/dist/_shared/startup-0-4-ZMJV547D.js +2 -2
- package/dist/_shared/startup-0-5-FD2P735I.js +2 -2
- package/dist/_shared/startup-10-0-TDQNBDDL.js +2 -2
- package/dist/_shared/startup-15-1-4S7FLMNG.js +2 -2
- package/dist/_shared/startup-8-0-34CBHPZH.js +2 -2
- package/dist/_shared/startup-8-1-4KANEHRA.js +2 -2
- package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/README.md +4 -4
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/README.md +28 -4
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/README.md +3 -3
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/README.md +2 -2
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +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 +2 -2
- 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.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- 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.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- 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/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.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.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +2 -2
- 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.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.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.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.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.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.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.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- 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/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/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.md +8 -5
- package/docs/build.md +11 -6
- package/docs/changelog.mdx +1 -1
- package/docs/codemode.md +10 -2
- package/docs/compaction/reference.md +6 -4
- package/docs/compaction.md +3 -3
- package/docs/containerization.md +13 -5
- package/docs/custom-provider/api-reference.md +8 -6
- package/docs/custom-provider/oauth.md +4 -4
- package/docs/custom-provider/registration.md +3 -3
- package/docs/custom-provider.md +8 -8
- package/docs/development.md +40 -5
- package/docs/docs.json +21 -5
- package/docs/environment-variables.md +20 -18
- package/docs/extensions/api-reference.md +8 -6
- package/docs/extensions/authoring.md +4 -4
- package/docs/extensions.md +43 -6
- package/docs/guides/configuration.md +21 -1
- package/docs/guides/intercom.md +4 -0
- package/docs/guides/non-interactive.md +4 -2
- package/docs/guides/orchestration.md +4 -2
- package/docs/guides/resume-on-any-machine.md +12 -6
- package/docs/guides/subagents.md +4 -0
- package/docs/guides/team-setup.md +13 -2
- package/docs/guides.md +10 -4
- package/docs/herdr.md +4 -4
- package/docs/index.md +12 -4
- package/docs/intercom/operations.md +26 -4
- package/docs/intercom/reference.md +25 -3
- package/docs/intercom.md +13 -5
- package/docs/json.md +2 -0
- package/docs/keybindings.md +17 -4
- package/docs/libraries/agent-core.md +4 -2
- package/docs/libraries/ai.md +71 -53
- package/docs/libraries/codemode.md +3 -2
- package/docs/libraries/schema.md +5 -2
- package/docs/libraries/storage-libsql.md +92 -0
- package/docs/libraries/storage-postgres.md +119 -0
- package/docs/libraries/telemetry.md +35 -2
- package/docs/libraries.md +23 -6
- package/docs/llama-cpp.md +2 -2
- package/docs/mcp-servers.md +50 -4
- package/docs/models/reference.md +13 -9
- package/docs/models-configuration.md +7 -7
- package/docs/models.md +18 -8
- package/docs/orchestration/migrating-workflows.md +2 -2
- package/docs/orchestration/patterns.md +8 -8
- package/docs/orchestration.md +5 -3
- package/docs/packages/authoring.md +3 -1
- package/docs/packages/reference.md +3 -1
- package/docs/packages.md +5 -3
- package/docs/programmatic.md +14 -8
- package/docs/prompt-templates.md +5 -3
- package/docs/providers/reference.md +7 -7
- package/docs/providers.md +22 -10
- package/docs/quickstart.md +13 -11
- package/docs/reference/cli.md +10 -5
- package/docs/reference.md +8 -4
- package/docs/rpc/examples.md +47 -0
- package/docs/rpc/extension-ui.md +7 -1
- package/docs/rpc/protocol.md +3 -2
- package/docs/rpc.md +3 -1
- package/docs/sdk/reference.md +144 -38
- package/docs/sdk/storage.md +614 -0
- package/docs/sdk/structured-decisions.md +77 -4
- package/docs/sdk/web-server.md +3 -2
- package/docs/sdk.md +26 -115
- package/docs/security.md +17 -7
- package/docs/session-format.md +38 -24
- package/docs/sessions.md +21 -15
- package/docs/settings.md +17 -14
- package/docs/skills.md +47 -3
- package/docs/storage.md +38 -24
- package/docs/subagents/authoring.md +3 -1
- package/docs/subagents/reference.md +8 -2
- package/docs/subagents.md +35 -6
- package/docs/terminal-setup.md +1 -1
- package/docs/themes.md +5 -3
- package/docs/tmux.md +4 -4
- package/docs/tools.md +11 -0
- package/docs/usage.md +25 -15
- package/docs/web-access.md +35 -0
- package/docs/windows.md +9 -6
- package/docs/worktree-snapshots.md +22 -11
- package/examples/sdk/11-sessions.ts +4 -4
- package/package.json +8 -8
- package/schemas/models.schema.json +7 -7
package/docs/libraries/ai.md
CHANGED
|
@@ -4,11 +4,7 @@ sidebarTitle: "@bastani/atomic-ai"
|
|
|
4
4
|
description: "Unified LLM API for providers, models, auth, streaming, tool calling, images, classification, and thinking."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
`@bastani/atomic-ai` is the LLM library Atomic runs on (requires Node.js 22.19+). It ships in every Atomic release at Atomic's version, and you can install it independently
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @bastani/atomic-ai
|
|
11
|
-
```
|
|
7
|
+
`@bastani/atomic-ai` is the LLM library Atomic runs on (requires Node.js 22.19+). It ships in every Atomic release at Atomic's version, and you can install it independently (see [Installation](#installation)).
|
|
12
8
|
|
|
13
9
|
Inside an Atomic extension, import it without installing it because the host provides it. See [Standalone libraries](/libraries) for how the packages fit together and for legacy package names that still resolve inside Atomic.
|
|
14
10
|
|
|
@@ -65,83 +61,88 @@ Requires Node.js 22.19 or newer.
|
|
|
65
61
|
Key root and subpath exports:
|
|
66
62
|
|
|
67
63
|
- Root `@bastani/atomic-ai`: `createModels`, `createProvider`, `Type`/`Static`/`TSchema` (re-exported from TypeBox), thinking helpers (`DEFAULT_THINKING_BUDGETS`, `fittedThinkingBudget`, `thinkingBudgetForLevel`, `getSupportedThinkingLevels`, `clampThinkingLevel`), `OAuthRefreshRejectedError`, `GitHubCopilot*Error`, `cleanupSessionResources`, and `PI_AI_VERSION`.
|
|
68
|
-
- Subpaths: `@bastani/atomic-ai/providers/<provider>`, `@bastani/atomic-ai/providers/all`, `@bastani/atomic-ai/api/<api-id>`, `@bastani/atomic-ai/session-resources`, `@bastani/atomic-ai/bun-oauth`, `@bastani/atomic-ai/oauth`, and `@bastani/atomic-ai/compat`.
|
|
64
|
+
- Subpaths: `@bastani/atomic-ai/models`, `@bastani/atomic-ai/providers/<provider>`, `@bastani/atomic-ai/providers/all`, `@bastani/atomic-ai/api/<api-id>`, `@bastani/atomic-ai/utils/*`, `@bastani/atomic-ai/session-resources`, `@bastani/atomic-ai/bedrock-provider`, `@bastani/atomic-ai/lazy-bedrock-provider`, `@bastani/atomic-ai/oauth`, `@bastani/atomic-ai/bun-oauth`, `@bastani/atomic-ai/lazy-oauth`, and `@bastani/atomic-ai/compat`.
|
|
69
65
|
|
|
70
66
|
## Quick start
|
|
71
67
|
|
|
72
|
-
Build a `Models` collection of providers and stream through it. The fastest start registers every built-in provider; apps optimizing bundle size register individual providers instead (see [Provider factories](#provider-factories) and [Bundling and tree shaking](#bundling-and-tree-shaking)).
|
|
68
|
+
Build a `Models` collection of providers and stream through it. Export `OPENAI_API_KEY` before running these examples. The fastest start registers every built-in provider; apps optimizing bundle size register individual providers instead (see [Provider factories](#provider-factories) and [Bundling and tree shaking](#bundling-and-tree-shaking)).
|
|
69
|
+
|
|
70
|
+
### Streaming with tool calls
|
|
73
71
|
|
|
74
72
|
```typescript
|
|
75
|
-
import { Type, type Context, type Tool } from
|
|
76
|
-
import { builtinModels } from
|
|
73
|
+
import { Type, type Context, type Tool } from "@bastani/atomic-ai";
|
|
74
|
+
import { builtinModels } from "@bastani/atomic-ai/providers/all";
|
|
77
75
|
|
|
78
76
|
// A Models collection with every built-in provider registered
|
|
79
77
|
const models = builtinModels();
|
|
80
78
|
|
|
81
79
|
// Sync lookup against the collection
|
|
82
|
-
const model = models.getModel(
|
|
80
|
+
const model = models.getModel("openai", "gpt-4o-mini");
|
|
81
|
+
if (!model) throw new Error("Model not found");
|
|
83
82
|
|
|
84
83
|
// Define tools with TypeBox schemas for type safety and validation
|
|
85
|
-
const tools: Tool[] = [
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
84
|
+
const tools: Tool[] = [
|
|
85
|
+
{
|
|
86
|
+
name: "get_time",
|
|
87
|
+
description: "Get the current time",
|
|
88
|
+
parameters: Type.Object({
|
|
89
|
+
timezone: Type.Optional(Type.String({ description: "Optional timezone (e.g., America/New_York)" })),
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
];
|
|
92
93
|
|
|
93
94
|
// Build a conversation context (easily serializable and transferable between models)
|
|
94
95
|
const context: Context = {
|
|
95
|
-
systemPrompt:
|
|
96
|
-
messages: [{ role:
|
|
97
|
-
tools
|
|
96
|
+
systemPrompt: "You are a helpful assistant.",
|
|
97
|
+
messages: [{ role: "user", content: "What time is it?", timestamp: Date.now() }],
|
|
98
|
+
tools,
|
|
98
99
|
};
|
|
99
100
|
|
|
100
|
-
// Option 1: Streaming with all event types.
|
|
101
101
|
// Auth resolves through the provider (OPENAI_API_KEY from the environment here).
|
|
102
102
|
const s = models.stream(model, context);
|
|
103
103
|
|
|
104
104
|
for await (const event of s) {
|
|
105
105
|
switch (event.type) {
|
|
106
|
-
case
|
|
106
|
+
case "start":
|
|
107
107
|
console.log(`Starting with ${event.partial.model}`);
|
|
108
108
|
break;
|
|
109
|
-
case
|
|
110
|
-
console.log(
|
|
109
|
+
case "text_start":
|
|
110
|
+
console.log("\n[Text started]");
|
|
111
111
|
break;
|
|
112
|
-
case
|
|
112
|
+
case "text_delta":
|
|
113
113
|
process.stdout.write(event.delta);
|
|
114
114
|
break;
|
|
115
|
-
case
|
|
116
|
-
console.log(
|
|
115
|
+
case "text_end":
|
|
116
|
+
console.log("\n[Text ended]");
|
|
117
117
|
break;
|
|
118
|
-
case
|
|
119
|
-
console.log(
|
|
118
|
+
case "thinking_start":
|
|
119
|
+
console.log("[Model is thinking...]");
|
|
120
120
|
break;
|
|
121
|
-
case
|
|
121
|
+
case "thinking_delta":
|
|
122
122
|
process.stdout.write(event.delta);
|
|
123
123
|
break;
|
|
124
|
-
case
|
|
125
|
-
console.log(
|
|
124
|
+
case "thinking_end":
|
|
125
|
+
console.log("[Thinking complete]");
|
|
126
126
|
break;
|
|
127
|
-
case
|
|
127
|
+
case "toolcall_start":
|
|
128
128
|
console.log(`\n[Tool call started: index ${event.contentIndex}]`);
|
|
129
129
|
break;
|
|
130
|
-
case
|
|
130
|
+
case "toolcall_delta": {
|
|
131
131
|
// Partial tool arguments are being streamed
|
|
132
132
|
const partialCall = event.partial.content[event.contentIndex];
|
|
133
|
-
if (partialCall
|
|
133
|
+
if (partialCall?.type === "toolCall") {
|
|
134
134
|
console.log(`[Streaming args for ${partialCall.name}]`);
|
|
135
135
|
}
|
|
136
136
|
break;
|
|
137
|
-
|
|
137
|
+
}
|
|
138
|
+
case "toolcall_end":
|
|
138
139
|
console.log(`\nTool called: ${event.toolCall.name}`);
|
|
139
140
|
console.log(`Arguments: ${JSON.stringify(event.toolCall.arguments)}`);
|
|
140
141
|
break;
|
|
141
|
-
case
|
|
142
|
+
case "done":
|
|
142
143
|
console.log(`\nFinished: ${event.reason}`);
|
|
143
144
|
break;
|
|
144
|
-
case
|
|
145
|
+
case "error":
|
|
145
146
|
console.error(`Error: ${event.error.errorMessage}`);
|
|
146
147
|
break;
|
|
147
148
|
}
|
|
@@ -152,24 +153,26 @@ const finalMessage = await s.result();
|
|
|
152
153
|
context.messages.push(finalMessage);
|
|
153
154
|
|
|
154
155
|
// Handle tool calls if any
|
|
155
|
-
const toolCalls = finalMessage.content.filter(
|
|
156
|
+
const toolCalls = finalMessage.content.filter((block) => block.type === "toolCall");
|
|
156
157
|
for (const call of toolCalls) {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
const timeZone = typeof call.arguments.timezone === "string" ? call.arguments.timezone : "UTC";
|
|
159
|
+
const result =
|
|
160
|
+
call.name === "get_time"
|
|
161
|
+
? new Date().toLocaleString("en-US", {
|
|
162
|
+
timeZone,
|
|
163
|
+
dateStyle: "full",
|
|
164
|
+
timeStyle: "long",
|
|
165
|
+
})
|
|
166
|
+
: "Unknown tool";
|
|
164
167
|
|
|
165
168
|
// Add tool result to context (supports text and images)
|
|
166
169
|
context.messages.push({
|
|
167
|
-
role:
|
|
170
|
+
role: "toolResult",
|
|
168
171
|
toolCallId: call.id,
|
|
169
172
|
toolName: call.name,
|
|
170
|
-
content: [{ type:
|
|
173
|
+
content: [{ type: "text", text: result }],
|
|
171
174
|
isError: false,
|
|
172
|
-
timestamp: Date.now()
|
|
175
|
+
timestamp: Date.now(),
|
|
173
176
|
});
|
|
174
177
|
}
|
|
175
178
|
|
|
@@ -177,19 +180,34 @@ for (const call of toolCalls) {
|
|
|
177
180
|
if (toolCalls.length > 0) {
|
|
178
181
|
const continuation = await models.complete(model, context);
|
|
179
182
|
context.messages.push(continuation);
|
|
180
|
-
console.log(
|
|
183
|
+
console.log("After tool execution:", continuation.content);
|
|
181
184
|
}
|
|
182
185
|
|
|
183
186
|
console.log(`Total tokens: ${finalMessage.usage.input} in, ${finalMessage.usage.output} out`);
|
|
184
187
|
console.log(`Cost: $${finalMessage.usage.cost.total.toFixed(4)}`);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Non-streaming completion
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import { type Context } from "@bastani/atomic-ai";
|
|
194
|
+
import { builtinModels } from "@bastani/atomic-ai/providers/all";
|
|
195
|
+
|
|
196
|
+
const models = builtinModels();
|
|
197
|
+
const model = models.getModel("openai", "gpt-4o-mini");
|
|
198
|
+
if (!model) throw new Error("Model not found");
|
|
199
|
+
|
|
200
|
+
const context: Context = {
|
|
201
|
+
systemPrompt: "You are a concise assistant.",
|
|
202
|
+
messages: [{ role: "user", content: "Summarize HTTP 429 in one sentence.", timestamp: Date.now() }],
|
|
203
|
+
};
|
|
185
204
|
|
|
186
|
-
// Option 2: Get complete response without streaming
|
|
187
205
|
const response = await models.complete(model, context);
|
|
188
206
|
|
|
189
207
|
for (const block of response.content) {
|
|
190
|
-
if (block.type ===
|
|
208
|
+
if (block.type === "text") {
|
|
191
209
|
console.log(block.text);
|
|
192
|
-
} else if (block.type ===
|
|
210
|
+
} else if (block.type === "toolCall") {
|
|
193
211
|
console.log(`Tool: ${block.name}(${JSON.stringify(block.arguments)})`);
|
|
194
212
|
}
|
|
195
213
|
}
|
|
@@ -4,7 +4,7 @@ sidebarTitle: "@bastani/atomic-codemode"
|
|
|
4
4
|
description: "Run model-written JavaScript in a QuickJS WebAssembly sandbox whose only capability is calling injected tools."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Runs model-written JavaScript in a QuickJS VM (compiled to WebAssembly) where the only capability is calling injected tools. Nested tool calls never enter the LLM context; only the script's output and return value do.
|
|
7
|
+
Runs model-written JavaScript in a QuickJS VM (compiled to WebAssembly) where the only capability is calling injected tools. Nested tool calls never enter the LLM context; only the script's output and return value do. See [Standalone libraries](/libraries) for all standalone packages.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -36,6 +36,7 @@ See [Usage on Node and Bun](#usage-on-node-and-bun) and [Usage on Cloudflare Wor
|
|
|
36
36
|
## Usage on Node and Bun
|
|
37
37
|
|
|
38
38
|
```ts
|
|
39
|
+
import { readFile } from "node:fs/promises";
|
|
39
40
|
import { CodemodeSandbox } from "@bastani/atomic-codemode";
|
|
40
41
|
|
|
41
42
|
const sandbox = new CodemodeSandbox({
|
|
@@ -45,7 +46,7 @@ const sandbox = new CodemodeSandbox({
|
|
|
45
46
|
name: "read",
|
|
46
47
|
execute: async (args, { signal }) => {
|
|
47
48
|
const { path } = args as { path: string };
|
|
48
|
-
return await readFile(path, "utf8");
|
|
49
|
+
return await readFile(path, { encoding: "utf8", signal });
|
|
49
50
|
},
|
|
50
51
|
},
|
|
51
52
|
],
|
package/docs/libraries/schema.md
CHANGED
|
@@ -12,7 +12,7 @@ JSON Schema builders and validation without `eval`. Each schema compiles once in
|
|
|
12
12
|
- Schemas are never mutated, so frozen schemas work.
|
|
13
13
|
- Format checks live in an optional subpath import.
|
|
14
14
|
|
|
15
|
-
Atomic validates tool arguments with `@bastani/atomic-schema`. See [Tool parameter schemas](/extensions#tool-parameter-schemas). Extensions can import `@bastani/atomic-schema` from the host without installing it.
|
|
15
|
+
Atomic validates tool arguments with `@bastani/atomic-schema`. See [Tool parameter schemas](/extensions#tool-parameter-schemas) and [Standalone libraries](/libraries). Extensions can import `@bastani/atomic-schema` from the host without installing it.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
@@ -33,7 +33,10 @@ const Read = obj({
|
|
|
33
33
|
type Read = Static<typeof Read>; // { path: string; mode: "text" | "binary"; offset?: number }
|
|
34
34
|
|
|
35
35
|
const read = compile(Read);
|
|
36
|
-
|
|
36
|
+
const value: unknown = { path: "README.md", mode: "text" };
|
|
37
|
+
if (read.check(value)) {
|
|
38
|
+
console.log(value.path); // value is narrowed to Read
|
|
39
|
+
}
|
|
37
40
|
|
|
38
41
|
read.errors({ offset: 0, extra: true });
|
|
39
42
|
// [
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "@bastani/atomic-storage-libsql"
|
|
3
|
+
sidebarTitle: "@bastani/atomic-storage-libsql"
|
|
4
|
+
description: "libSQL and Turso storage adapter for Atomic sessions and Intercom multi-node routing, usable from the CLI or TypeScript SDK."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`@bastani/atomic-storage-libsql` is Atomic's standalone libSQL and [Turso](https://turso.tech) storage adapter. It stores sessions and Intercom multi-node routing in a shared Turso database, self-hosted `sqld` server, or local libSQL file with one URL and one auth token. Unlike the six core libraries in [Standalone libraries](/libraries), this package is not bundled inside `@bastani/atomic`; install it only when you use libSQL or Turso.
|
|
8
|
+
|
|
9
|
+
- **Plain ESM with types:** Ships plain JavaScript ESM and TypeScript declarations (`libsql.d.ts`), requiring Node.js 22.19+ with no TypeScript loader.
|
|
10
|
+
- **Batched writes:** Sends statement batches to remote libSQL servers in a single request and redacts auth tokens and custom headers from error diagnostics.
|
|
11
|
+
|
|
12
|
+
For operator setup, see [Turso and libSQL](/storage#turso-and-libsql). For sharing Intercom across a team while keeping personal sessions local, see [Team and CI setup](/guides/team-setup). For all five SDK storage backends and `createAgentSessionRuntime()`, see [SDK storage backends](/sdk/storage).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Install according to how you use Atomic:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# CLI (install in user scope without -l; Atomic searches user-scope packages for adapters)
|
|
20
|
+
atomic install npm:@bastani/atomic-storage-libsql
|
|
21
|
+
|
|
22
|
+
# TypeScript SDK application
|
|
23
|
+
npm install @bastani/atomic-storage-libsql @bastani/atomic
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## SDK quick start
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { createAgentSession } from "@bastani/atomic";
|
|
30
|
+
import { openLibsqlDatabase } from "@bastani/atomic-storage-libsql";
|
|
31
|
+
|
|
32
|
+
const database = await openLibsqlDatabase({
|
|
33
|
+
url: "libsql://<db>.turso.io",
|
|
34
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const { session } = await createAgentSession({
|
|
39
|
+
sessionStore: { kind: "database", database, prefix: "app_" },
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
await session.prompt("Summarize the failing tests in this repository");
|
|
43
|
+
} finally {
|
|
44
|
+
await session.dispose();
|
|
45
|
+
}
|
|
46
|
+
} finally {
|
|
47
|
+
await database.close();
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Pass the returned `SqliteDatabase` to `createAgentSession({ sessionStore: { kind: "database", database, prefix? } })` or `SqlSessionStore.open(database, { prefix? })`. Atomic leaves caller-owned database handles open on `session.dispose()`, so always close `database` in your outer `finally`.
|
|
52
|
+
|
|
53
|
+
## `LibsqlDatabaseOptions`
|
|
54
|
+
|
|
55
|
+
| Option | Type | Required | Description |
|
|
56
|
+
| --- | --- | --- | --- |
|
|
57
|
+
| `url` | `string` | Yes | A `libsql://`, `https://`, `http://`, `wss://`, `ws://`, or `file:` URL. (`atomic storage join` and `atomic team join` accept `libsql://`, `https://`, `http://`, `wss://`, `ws://`, or an absolute `file:` URL without embedded credentials.) |
|
|
58
|
+
| `authToken` | `string` | For remote databases | Database auth token. In CLI settings, pass through `secrets` (`{ "file": ... }` or `{ "env": ... }`) so it never lands in `settings.json`. |
|
|
59
|
+
| `namespace` | `string` | No | Self-hosted `sqld` namespace (`sqld --enable-namespaces`), sent as the `x-namespace` header. Requires a `libsql:`, `https:`, or `http:` URL. |
|
|
60
|
+
| `headers` | `Readonly<Record<string, string>>` | No | Extra request headers sent on every HTTP/libSQL request and redacted from diagnostics. Requires a `libsql:`, `https:`, or `http:` URL. |
|
|
61
|
+
|
|
62
|
+
## Exported API
|
|
63
|
+
|
|
64
|
+
- `openLibsqlDatabase(options: LibsqlDatabaseOptions): Promise<SqliteDatabase>` — opens a libSQL/Turso-backed `SqliteDatabase`.
|
|
65
|
+
- Type: `LibsqlDatabaseOptions`.
|
|
66
|
+
- Default export: `StorageAdapterModule` (`{ atomicStorageAdapter: 1, openDatabase }`) used by `atomic` CLI settings, `{ kind: "adapter" }` selections, and `teamProfileSelection()`.
|
|
67
|
+
|
|
68
|
+
## Concurrency, WAL, and `sqld` retries
|
|
69
|
+
|
|
70
|
+
- **Local `file:` databases:** On first open, the adapter enables write-ahead logging (WAL, creating `-wal` and `-shm` sidecar files) with a 5-second busy timeout matching Atomic's built-in SQLite stores. Single statements, single-statement `exec`, batches, and transaction starts retry when another connection commits while waiting; multi-statement `exec` calls are not retried. Open a local file through only one SQLite library at a time so concurrent readers do not see stale WAL state.
|
|
71
|
+
- **Remote `sqld` servers:** When `sqld` hits a WAL checkpoint, it returns `SQLITE_BUSY` immediately without running the write. The adapter retries single statements, single-statement `exec`, batches, and transaction starts with jittered exponential backoff for up to 5 seconds within a 10-second wall-clock ceiling (one 5-second lock timeout plus one 5-second checkpoint window). For self-hosted `sqld`, start with `--checkpoint-interval-s 60` (or `SQLD_CHECKPOINT_INTERVAL_S=60`).
|
|
72
|
+
|
|
73
|
+
## CLI configuration
|
|
74
|
+
|
|
75
|
+
Join a shared database for both sessions and Intercom:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
turso db tokens create <db> > ~/turso-token
|
|
79
|
+
chmod 600 ~/turso-token
|
|
80
|
+
atomic storage join libsql://<db>.turso.io --token-file ~/turso-token
|
|
81
|
+
atomic intercom restart
|
|
82
|
+
atomic storage status
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
To share Intercom across machines while keeping personal sessions in local SQLite, run `atomic team join <url> --token-file ~/turso-token` instead (see [Team and CI setup](/guides/team-setup)). Run `atomic storage migrate` when upgrading schemas on a shared database.
|
|
86
|
+
|
|
87
|
+
## Related docs
|
|
88
|
+
|
|
89
|
+
- [Turso and libSQL operator guide](/storage#turso-and-libsql): CLI setup, manual `settings.json`, size limits, and storage errors.
|
|
90
|
+
- [Team and CI setup](/guides/team-setup): shared team Intercom, CI runner profiles, and `teamProfileSelection()`.
|
|
91
|
+
- [SDK storage backends](/sdk/storage): complete `createAgentSession()`, `createAgentSessionRuntime()`, and error-handling recipes.
|
|
92
|
+
- [Standalone libraries](/libraries): all published `@bastani/atomic-*` packages.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "@bastani/atomic-storage-postgres"
|
|
3
|
+
sidebarTitle: "@bastani/atomic-storage-postgres"
|
|
4
|
+
description: "PostgreSQL storage adapter for Atomic sessions and Intercom multi-node routing, usable from the CLI or TypeScript SDK."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`@bastani/atomic-storage-postgres` is Atomic's standalone [PostgreSQL](https://www.postgresql.org) storage adapter. It stores sessions and Intercom multi-node routing in one shared PostgreSQL database so multiple machines or SDK hosts can share state. Unlike the six core libraries in [Standalone libraries](/libraries), this package is not bundled inside `@bastani/atomic`; install it only when you use PostgreSQL.
|
|
8
|
+
|
|
9
|
+
- **PostgreSQL version requirement:** Atomic sessions require **PostgreSQL 16 or later** (for session JSON query functions). The adapter accepts **PostgreSQL 14 or later** on connect for non-session tables and rejects servers older than PostgreSQL 14.
|
|
10
|
+
- **Plain ESM with types:** Ships plain JavaScript ESM and TypeScript declarations (`postgres.d.ts`), requiring Node.js 22.19+ with no TypeScript loader.
|
|
11
|
+
|
|
12
|
+
For operator setup, role creation SQL, migrations, and troubleshooting, see [PostgreSQL setup](/storage#postgresql). For all five SDK storage backends and `createAgentSessionRuntime()`, see [SDK storage backends](/sdk/storage).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Install according to how you use Atomic:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# CLI (install in user scope without -l; Atomic searches user-scope packages for adapters)
|
|
20
|
+
atomic install npm:@bastani/atomic-storage-postgres
|
|
21
|
+
|
|
22
|
+
# TypeScript SDK application
|
|
23
|
+
npm install @bastani/atomic-storage-postgres @bastani/atomic
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If you use [cloud IAM authentication](#cloud-iam-authentication), also install the matching optional peer dependency for your cloud provider (`@azure/identity`, `@aws-sdk/rds-signer`, or `google-auth-library`).
|
|
27
|
+
|
|
28
|
+
## SDK quick start
|
|
29
|
+
|
|
30
|
+
Create your database roles and run `atomic storage migrate` as the owner role first (see [Set up the database](/storage#set-up-the-database)), then connect from your Node.js application with `openPostgresDatabase()`:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { readFile } from "node:fs/promises";
|
|
34
|
+
import { createAgentSession } from "@bastani/atomic";
|
|
35
|
+
import { openPostgresDatabase } from "@bastani/atomic-storage-postgres";
|
|
36
|
+
|
|
37
|
+
const database = await openPostgresDatabase({
|
|
38
|
+
url: "postgresql://atomic_runtime@db.example.com:5432/atomic",
|
|
39
|
+
// Accepts a string or an async callback invoked for every new connection (supports rotation).
|
|
40
|
+
password: async () => (await readFile("/run/secrets/postgres-password", "utf8")).trim(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const { session } = await createAgentSession({
|
|
45
|
+
// PostgreSQL prefixes must be lowercase and at most 24 characters.
|
|
46
|
+
sessionStore: { kind: "database", database, prefix: "app_" },
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
await session.prompt("Summarize the open tasks in this repository");
|
|
50
|
+
} finally {
|
|
51
|
+
await session.dispose();
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
await database.close();
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Pass the returned `SqliteDatabase` to `createAgentSession({ sessionStore: { kind: "database", database, prefix? } })` or `SqlSessionStore.open(database, { prefix? })`. Atomic leaves caller-owned database handles open on `session.dispose()`, so always close `database` in your outer `finally`.
|
|
59
|
+
|
|
60
|
+
## `PostgresDatabaseOptions`
|
|
61
|
+
|
|
62
|
+
| Option | Type | Default | Description |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `url` | `string` *(required)* | — | A `postgres://` or `postgresql://` URL with a username and no embedded password. Any password in the URL or a `password=` query parameter is rejected with `credential-in-url`. |
|
|
65
|
+
| `password` | `string \| (() => Promise<string>)` | — | Password string or async callback invoked for each new connection. Omit when using cloud `auth`; combining cloud `auth` with `password` throws `conflicting-token`. |
|
|
66
|
+
| `auth` | `"password" \| "azure-entra" \| "aws-iam" \| "gcp-iam"` | `"password"` | Credential strategy. Cloud modes request short-lived tokens per new connection via the provider's SDK. |
|
|
67
|
+
| `maxConnections` | `number` | `8` (`DEFAULT_MAX_CONNECTIONS`) | Maximum pooled connections kept open per process. |
|
|
68
|
+
| `statementTimeoutMs` | `number` | `30000` (`DEFAULT_STATEMENT_TIMEOUT_MS`) | Server-side per-statement timeout in milliseconds before cancellation. |
|
|
69
|
+
| `listenUrl` | `string` | `url` | Direct session-mode endpoint for `LISTEN`/`NOTIFY` wake-ups when `url` goes through a transaction pooler. |
|
|
70
|
+
| `schema` | `string` | `"atomic"` (`DEFAULT_SCHEMA`) | Lowercase schema holding Atomic's tables. Existing databases with tables in `public` and no `atomic` schema keep using `public` until `atomic storage migrate` moves them. Every transaction sets `SET LOCAL search_path`. |
|
|
71
|
+
| `sdkSearchPaths` | `readonly string[]` | — | Extra npm prefix directories to search when loading a cloud IAM SDK not found beside the adapter. CLI adapter loading passes `<agentDir>/npm`. |
|
|
72
|
+
| `proxy` | `string` | Environment proxy | An `http://` or `https://` proxy URL for `CONNECT` tunneling (credentials sent in `Proxy-Authorization` and redacted), or `"none"` to connect directly. Overrides environment proxy variables for TCP hosts. |
|
|
73
|
+
| `socket` | `PostgresSocketFactory` | — | Custom transport callback `(target: ProxyTarget) => Duplex \| Promise<Duplex>` carrying the PostgreSQL protocol (`target` has `{ host, port }` from `url` or `PGHOST`/`PGPORT`). Atomic negotiates TLS over it as over a normal socket. Cannot be combined with `proxy` (`conflicting-transport`). Socket directories always connect directly. |
|
|
74
|
+
|
|
75
|
+
## Exported API
|
|
76
|
+
|
|
77
|
+
- `openPostgresDatabase(options: PostgresDatabaseOptions): Promise<SqliteDatabase>` — opens a pooled PostgreSQL-backed `SqliteDatabase`.
|
|
78
|
+
- `DEFAULT_MAX_CONNECTIONS` (`8`), `DEFAULT_STATEMENT_TIMEOUT_MS` (`30000`), `DEFAULT_SCHEMA` (`"atomic"`).
|
|
79
|
+
- `numberPlaceholders(sql: string): string` — rewrites positional `?` parameters outside string literals, quoted identifiers, and comments to `$1`, `$2`, ....
|
|
80
|
+
- `physicalIdentifiers(sql: string): string` — replaces unquoted identifiers longer than 63 bytes with their deterministic PostgreSQL physical identifier.
|
|
81
|
+
- Types: `PostgresDatabaseOptions`, `PostgresSocketFactory`, `ProxyTarget`.
|
|
82
|
+
- Default export: `StorageAdapterModule` (`{ atomicStorageAdapter: 1, liveSecrets, openDatabase }`) used by `atomic` CLI settings and `{ kind: "adapter" }` selections.
|
|
83
|
+
|
|
84
|
+
## Cloud IAM authentication
|
|
85
|
+
|
|
86
|
+
On Azure, AWS, and Google Cloud, set `auth` and omit `password` / `secrets.password`. Only the selected provider's SDK is loaded on first connection. Tokens stay in memory, never appear in settings or errors, time out after 8 seconds, and clear and retry once on rejection (`28P01`, or Azure `28000`). Missing SDKs or token failures throw `StorageConfigError` (`reason: "auth-unavailable"`). Cloud tokens require TLS (`sslmode=verify-full` or `require`).
|
|
87
|
+
|
|
88
|
+
| `auth` | Optional peer SDK | CLI user-scope install | Credential source |
|
|
89
|
+
| --- | --- | --- | --- |
|
|
90
|
+
| `azure-entra` | `@azure/identity` | `atomic install npm:@azure/identity@4.14.1` | `DefaultAzureCredential` for `https://ossrdbms-aad.database.windows.net/.default` (reused until 5 minutes before expiry) |
|
|
91
|
+
| `aws-iam` | `@aws-sdk/rds-signer` | `atomic install npm:@aws-sdk/rds-signer@3.1169.0` | RDS `Signer` using the AWS default credential chain (`AWS_*`, profiles, IRSA, instance profile) |
|
|
92
|
+
| `gcp-iam` | `google-auth-library` | `atomic install npm:google-auth-library@11.3.4` | `GoogleAuth` for `https://www.googleapis.com/auth/sqlservice.login` (ADC, GKE/GCE/Cloud Run metadata) |
|
|
93
|
+
|
|
94
|
+
For Azure Database for PostgreSQL Flexible Server (PostgreSQL 16+), Azure HorizonDB (PostgreSQL 17, read/write endpoint), Amazon RDS/Aurora, and Google Cloud SQL role-grant SQL, see [PostgreSQL setup](/storage#azure) and [Cloud identities](/storage#cloud-identities).
|
|
95
|
+
|
|
96
|
+
## TLS, HTTP proxies, and connection poolers
|
|
97
|
+
|
|
98
|
+
- **TLS defaults:** When `url` omits `sslmode`, Atomic applies `sslmode=verify-full` for remote hosts (checking `PGHOST` if omitted from the URL). Add `sslrootcert=/path/to/ca.pem` for private CAs. Without `sslrootcert`, `require` verifies both certificate and hostname like `verify-full` (stricter than libpq). TLS parameter names are case-sensitive; unknown `sslmode` values are rejected.
|
|
99
|
+
- **HTTP `CONNECT` proxies:** Without `options.proxy`, remote TCP hosts check `HTTPS_PROXY` (`https_proxy`), then `ALL_PROXY` (when HTTP/HTTPS), then `HTTP_PROXY`, respecting `NO_PROXY`. Loopback hosts and Unix socket directories connect directly. Keep `sslmode=verify-full` (or `verify-ca` with a private CA) so TLS runs end to end through the tunnel.
|
|
100
|
+
- **Connection poolers and wake-ups:** Works with transaction-mode poolers (PgBouncer, Azure port `6432`, Supabase Supavisor, Neon `-pooler`) with no session-level state or named prepared statements. Each process opens one extra `LISTEN` connection outside the pool for instant Intercom wake-ups; when `url` uses a transaction pooler, set `listenUrl` to a direct endpoint or Atomic falls back to polling automatically.
|
|
101
|
+
- **Retries and errors:** Connection drops, lock conflicts (`40001`, `40P01`, `55P03`), and canceled statements (`57014`) throw `StorageTransientError` (read-only and unwritten calls retry automatically). Invalid credentials (`28P01`), missing databases (`3D000`), and certificate errors fail immediately. Missing privileges (`42501`) fail immediately with `StorageConfigError` (`reason: "missing-privilege"`) naming the exact `GRANT` or migration command.
|
|
102
|
+
|
|
103
|
+
## CLI configuration
|
|
104
|
+
|
|
105
|
+
Join a machine with the CLI after installing in user scope and running `atomic storage migrate`:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
printf '%s' "$PASSWORD" > ~/atomic-db-password
|
|
109
|
+
chmod 600 ~/atomic-db-password
|
|
110
|
+
atomic storage join 'postgresql://atomic_runtime@db.example.com:5432/atomic' --password-file ~/atomic-db-password
|
|
111
|
+
atomic intercom restart
|
|
112
|
+
atomic storage status
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Related docs
|
|
116
|
+
|
|
117
|
+
- [PostgreSQL operator guide](/storage#postgresql): role creation SQL, migrations, Azure/RDS/Cloud SQL setup, and troubleshooting.
|
|
118
|
+
- [SDK storage backends](/sdk/storage): complete `createAgentSession()`, `createAgentSessionRuntime()`, and error-handling recipes.
|
|
119
|
+
- [Standalone libraries](/libraries): all published `@bastani/atomic-*` packages.
|
|
@@ -4,7 +4,7 @@ sidebarTitle: "@bastani/atomic-telemetry"
|
|
|
4
4
|
description: "Vendor-neutral telemetry contracts, no-op and in-memory contexts, metrics, trace rendering, and typed telemetry schemas."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Vendor-neutral telemetry contracts and typed schema utilities for Atomic's libraries. This package contains no exporter and sends nothing on its own; you supply the adapter.
|
|
7
|
+
Vendor-neutral telemetry contracts and typed schema utilities for Atomic's libraries. This package contains no exporter and sends nothing on its own; you supply the adapter. See [Standalone libraries](/libraries) for all standalone packages.
|
|
8
8
|
|
|
9
9
|
This package provides:
|
|
10
10
|
|
|
@@ -24,6 +24,39 @@ Applications can use the in-memory reference or supply an adapter for OpenTeleme
|
|
|
24
24
|
npm install @bastani/atomic-telemetry
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import {
|
|
31
|
+
InMemoryTelemetryContext,
|
|
32
|
+
NOOP_TELEMETRY_CONTEXT,
|
|
33
|
+
type TelemetryContext,
|
|
34
|
+
} from "@bastani/atomic-telemetry";
|
|
35
|
+
import { renderTrace } from "@bastani/atomic-telemetry/render";
|
|
36
|
+
|
|
37
|
+
const accounts = new Map<string, { id: string; plan: string }>([["acct-1", { id: "acct-1", plan: "pro" }]]);
|
|
38
|
+
|
|
39
|
+
async function loadAccount(accountId: string, telemetry: TelemetryContext = NOOP_TELEMETRY_CONTEXT) {
|
|
40
|
+
return telemetry.startSpan(
|
|
41
|
+
{
|
|
42
|
+
name: "example.account.load",
|
|
43
|
+
attributes: { "example.account.id": accountId },
|
|
44
|
+
},
|
|
45
|
+
async (span) => {
|
|
46
|
+
const account = accounts.get(accountId);
|
|
47
|
+
span.setAttributes({ "example.account.found": account !== undefined });
|
|
48
|
+
return account;
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const recorder = new InMemoryTelemetryContext();
|
|
54
|
+
await loadAccount("acct-1", recorder);
|
|
55
|
+
|
|
56
|
+
const { traces } = await recorder.findTraces();
|
|
57
|
+
if (traces[0]) console.log(renderTrace(traces[0].spans));
|
|
58
|
+
```
|
|
59
|
+
|
|
27
60
|
## Telemetry concepts
|
|
28
61
|
|
|
29
62
|
Telemetry describes what a program did while running using spans, attributes, events, statuses, and explicit context:
|
|
@@ -481,7 +514,7 @@ Adapters do not need to understand schema objects. Instrumentation helpers and t
|
|
|
481
514
|
|
|
482
515
|
## Using with `@bastani/atomic-ai`
|
|
483
516
|
|
|
484
|
-
Pass a parent `TelemetryContext` to `@bastani/atomic-ai` through `telemetryContext` in request options:
|
|
517
|
+
Pass a parent `TelemetryContext` to [`@bastani/atomic-ai`](/libraries/ai) through `telemetryContext` in request options:
|
|
485
518
|
|
|
486
519
|
```typescript
|
|
487
520
|
import { InMemoryTelemetryContext } from '@bastani/atomic-telemetry';
|
package/docs/libraries.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Standalone libraries"
|
|
3
|
-
sidebarTitle: "
|
|
4
|
-
description: "Explore
|
|
3
|
+
sidebarTitle: "All libraries"
|
|
4
|
+
description: "Explore Atomic's six core @bastani/atomic-* TypeScript libraries and two optional storage adapter packages for extensions, SDK apps, and standalone Node.js 22.19+ projects."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Atomic
|
|
7
|
+
Atomic publishes six core TypeScript libraries and two optional storage adapter packages (all requiring Node.js 22.19 or newer). Each package publishes on npm at Atomic's version with every release and works independently outside Atomic.
|
|
8
|
+
|
|
9
|
+
## Core libraries
|
|
10
|
+
|
|
11
|
+
The six core libraries are bundled inside `@bastani/atomic` and provided to extensions automatically:
|
|
8
12
|
|
|
9
13
|
| Package | What it does |
|
|
10
14
|
| --- | --- |
|
|
@@ -15,17 +19,30 @@ Atomic is built on six TypeScript libraries (requiring Node.js 22.19 or newer).
|
|
|
15
19
|
| [`@bastani/atomic-schema`](/libraries/schema) | JSON Schema builders and validation without `eval` |
|
|
16
20
|
| [`@bastani/atomic-telemetry`](/libraries/telemetry) | Vendor-neutral telemetry contracts and reference contexts that send nothing on their own |
|
|
17
21
|
|
|
22
|
+
## Storage adapter packages
|
|
23
|
+
|
|
24
|
+
Remote SQL storage adapters are **not** bundled into `@bastani/atomic` and must be installed separately when you use PostgreSQL or libSQL/Turso:
|
|
25
|
+
|
|
26
|
+
| Package | What it does |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| [`@bastani/atomic-storage-postgres`](/libraries/storage-postgres) | PostgreSQL 16+ storage adapter (`openPostgresDatabase()`, cloud IAM, proxies, poolers) for shared sessions and Intercom |
|
|
29
|
+
| [`@bastani/atomic-storage-libsql`](/libraries/storage-libsql) | libSQL and Turso storage adapter (`openLibsqlDatabase()`, namespaces, WAL/sqld retries) for shared sessions and Intercom |
|
|
30
|
+
|
|
31
|
+
For CLI usage, install storage adapters in user scope with `atomic install npm:@bastani/atomic-storage-postgres` or `atomic install npm:@bastani/atomic-storage-libsql`. For TypeScript SDK applications, install them with `npm install` alongside `@bastani/atomic` (see [SDK storage backends](/sdk/storage)).
|
|
32
|
+
|
|
33
|
+
> **Native bindings:** `@bastani/atomic-natives` is an internal N-API native module installed automatically as a runtime dependency of `@bastani/atomic` (with per-platform binary packages in its `optionalDependencies`) and is not intended as a standalone user library.
|
|
34
|
+
|
|
18
35
|
## Install
|
|
19
36
|
|
|
20
|
-
Install a library on its own with npm:
|
|
37
|
+
Install a core library on its own with npm:
|
|
21
38
|
|
|
22
39
|
```bash
|
|
23
40
|
npm install @bastani/atomic-ai
|
|
24
41
|
```
|
|
25
42
|
|
|
26
|
-
Inside an Atomic [extension](/extensions), import the libraries without installing them. The running Atomic process provides them, so your extension shares its instances. If you publish an [Atomic package](/packages/authoring) that imports them, list them in `peerDependencies` with a `"*"` range.
|
|
43
|
+
Inside an Atomic [extension](/extensions), import the six core libraries without installing them. The running Atomic process provides them, so your extension shares its instances. If you publish an [Atomic package](/packages/authoring) that imports them, list them in `peerDependencies` with a `"*"` range.
|
|
27
44
|
|
|
28
|
-
To build on Atomic's sessions, tools, and extensions rather than the bare libraries, use the [SDK](/sdk)
|
|
45
|
+
To build on Atomic's sessions, tools, and extensions rather than the bare libraries, use the [SDK](/sdk) and [SDK storage backends](/sdk/storage). For custom extension UI, start with [TUI components](/tui).
|
|
29
46
|
|
|
30
47
|
## Older package names
|
|
31
48
|
|
package/docs/llama-cpp.md
CHANGED
|
@@ -45,7 +45,7 @@ For settings tuned to a specific NVIDIA GPU and model, see [NVIDIA RTX recipes](
|
|
|
45
45
|
|
|
46
46
|
## Configure Atomic
|
|
47
47
|
|
|
48
|
-
Run `/login llama.cpp` and enter the router URL and optional API key. The default URL is `http://127.0.0.1:9931` (trailing slashes and `/v1` are normalized automatically). When the router runs with `--no-models-autoload`, login saves only the connection; load a model with `/llama`, then select it with `/model`.
|
|
48
|
+
Run `/login llama.cpp` inside an interactive session and enter the router URL and optional API key. The default URL is `http://127.0.0.1:9931` (trailing slashes and `/v1` are normalized automatically). Shell `atomic auth login` does not load extension providers, so use `/login llama.cpp` or environment variables below instead (see [CLI reference](/reference/cli#credential-commands) and [Model providers](/providers)). When the router runs with `--no-models-autoload`, login saves only the connection; load a model with `/llama`, then select it with `/model`.
|
|
49
49
|
|
|
50
50
|
You can configure the same values with environment variables instead of `/login`:
|
|
51
51
|
|
|
@@ -82,7 +82,7 @@ Each llama.cpp model sets both `contextWindow` and `maxTokens` from the router-r
|
|
|
82
82
|
|
|
83
83
|
## Classification
|
|
84
84
|
|
|
85
|
-
Classifier models answer typed `choice`, `bool`, and `score` questions about JSON state, letting a local model serve `decide()` and `structured_output` decisions as your [`decisionModel`](/settings#decisionmodel). Extensions can call `ctx.modelRegistry.classify()` and codemode scripts can call `models.classify()`; see [Classifier models](/models#use-classifier-models).
|
|
85
|
+
Classifier models answer typed `choice`, `bool`, and `score` questions about JSON state, letting a local model serve `decide()` and `structured_output` decisions as your [`decisionModel`](/settings#decisionmodel) (see [Structured decisions](/sdk/structured-decisions)). Extensions can call `ctx.modelRegistry.classify()` and codemode scripts can call `models.classify()`; see [Classifier models](/models#use-classifier-models).
|
|
86
86
|
|
|
87
87
|
Atomic exposes llama.cpp models as classifiers in two ways:
|
|
88
88
|
|