@bastani/atomic 0.10.14 → 0.10.15-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +3 -3
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +3 -3
- package/dist/_shared/mode-shared-2QJSCUM6.js +3 -3
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/runtime-O4KCSG4C.js +2 -2
- package/dist/_shared/{sdk-B5LEWGGI.js → sdk-OHKMDJ74.js} +27 -5
- package/dist/_shared/{sdk-B5LEWGGI.js.map → sdk-OHKMDJ74.js.map} +1 -1
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/startup-0-0-Q3MWKUK4.js +2 -2
- package/dist/_shared/startup-0-1-M6OWAYHH.js +2 -2
- package/dist/_shared/{startup-0-2-5QHPCEON.js → startup-0-2-2HUMCPKX.js} +14 -16
- package/dist/_shared/startup-0-2-2HUMCPKX.js.map +1 -0
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +3 -3
- package/dist/_shared/startup-0-4-ZMJV547D.js +3 -3
- package/dist/_shared/startup-0-5-YDW47QX6.js +3 -3
- package/dist/_shared/startup-10-0-TDQNBDDL.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +6 -30
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +3 -3
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +3 -3
- package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
- package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/auth-cli.code.js +1 -1
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +1 -1
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/compaction/compactor.d.ts +0 -8
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +2 -2
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/sdk.code.js +1 -1
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +3 -3
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/node-sqlite-thread.js +2 -2
- package/dist/core/storage/node-sqlite.js +2 -2
- package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
- package/dist/core/storage/offline-snapshot-file.js +3 -3
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +2 -2
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +2 -2
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +1 -1
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-window.code.js +2 -2
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +2 -2
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +1 -1
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +2 -2
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.code.js +1 -1
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +2 -2
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +2 -2
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.js +2 -2
- package/dist/core/worktree-snapshot/errors.code.js +1 -1
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +1 -1
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.d.ts +21 -1
- package/dist/index.js +2 -2
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +2 -2
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/6.js +1 -1
- package/dist/utils/startup-database-spare.code.js +1 -1
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/background-tasks/reference.md +182 -0
- package/docs/background-tasks.md +98 -405
- package/docs/build.md +67 -27
- package/docs/changelog.mdx +1 -1
- package/docs/codemode.md +108 -39
- package/docs/compaction/branch-summaries.md +54 -0
- package/docs/compaction/custom-compactors.md +161 -0
- package/docs/compaction/memory-compaction.md +77 -0
- package/docs/compaction/reference.md +86 -38
- package/docs/compaction.md +51 -252
- package/docs/computer-use.md +169 -321
- package/docs/containerization.md +71 -57
- package/docs/custom-provider/api-reference.md +119 -25
- package/docs/custom-provider/oauth.md +114 -132
- package/docs/custom-provider/override.md +37 -27
- package/docs/custom-provider/registration.md +107 -83
- package/docs/custom-provider/streaming.md +85 -71
- package/docs/custom-provider.md +85 -52
- package/docs/development.md +39 -29
- package/docs/docs.json +76 -63
- package/docs/environment-variables.md +94 -44
- package/docs/extensions/api-reference.md +86 -43
- package/docs/extensions/authoring.md +162 -154
- package/docs/extensions/events.md +80 -25
- package/docs/extensions/examples.md +90 -85
- package/docs/extensions/ui.md +206 -82
- package/docs/extensions.md +79 -108
- package/docs/getting-started/authentication.md +67 -36
- package/docs/getting-started/first-session.md +53 -43
- package/docs/getting-started/installation.md +116 -89
- package/docs/getting-started/project-instructions.md +48 -34
- package/docs/guides/configuration.md +82 -20
- package/docs/guides/non-interactive.md +66 -24
- package/docs/guides/resume-on-any-machine.md +135 -82
- package/docs/guides/team-setup.md +114 -105
- package/docs/guides.md +76 -32
- package/docs/herdr.md +15 -16
- package/docs/how-atomic-works.md +140 -0
- package/docs/index.md +58 -44
- package/docs/intercom/operations.md +141 -151
- package/docs/intercom/reference.md +85 -108
- package/docs/intercom.md +84 -145
- package/docs/json.md +120 -67
- package/docs/keybindings.md +85 -49
- package/docs/libraries/agent-core.md +137 -275
- package/docs/libraries/ai.md +100 -84
- package/docs/libraries/codemode.md +210 -300
- package/docs/libraries/schema.md +59 -53
- package/docs/libraries/storage-postgres.md +49 -35
- package/docs/libraries/telemetry.md +153 -354
- package/docs/libraries/tui.md +265 -393
- package/docs/libraries.md +42 -26
- package/docs/llama-cpp.md +171 -161
- package/docs/mcp-servers.md +90 -51
- package/docs/models/choose-a-model.md +188 -0
- package/docs/models/reference.md +74 -30
- package/docs/models.md +153 -88
- package/docs/orchestration/migrating-workflows.md +23 -16
- package/docs/orchestration/patterns.md +39 -44
- package/docs/orchestration.md +65 -26
- package/docs/packages/authoring.md +51 -29
- package/docs/packages/reference.md +42 -21
- package/docs/packages.md +69 -58
- package/docs/programmatic.md +118 -24
- package/docs/prompt-templates.md +84 -83
- package/docs/providers/reference.md +43 -48
- package/docs/providers.md +219 -451
- package/docs/quickstart.md +140 -120
- package/docs/reference/cli.md +135 -97
- package/docs/reference.md +20 -18
- package/docs/rpc/examples.md +76 -20
- package/docs/rpc/extension-ui.md +64 -38
- package/docs/rpc/protocol.md +361 -110
- package/docs/rpc.md +57 -17
- package/docs/sdk/reference.md +409 -534
- package/docs/sdk/storage.md +53 -13
- package/docs/sdk/structured-decisions.md +82 -56
- package/docs/sdk/web-server.md +57 -43
- package/docs/sdk.md +106 -84
- package/docs/security.md +42 -64
- package/docs/session-format.md +62 -38
- package/docs/sessions.md +99 -214
- package/docs/settings.md +165 -195
- package/docs/shell-aliases.md +9 -6
- package/docs/skills/authoring.md +69 -48
- package/docs/skills/reference.md +51 -20
- package/docs/skills.md +99 -148
- package/docs/slash-commands.md +129 -0
- package/docs/storage/custom-adapters.md +160 -85
- package/docs/storage/jsonl.md +81 -66
- package/docs/storage/postgres/pgbouncer.md +120 -126
- package/docs/storage/postgres/tuning.md +120 -143
- package/docs/storage/postgres.md +314 -330
- package/docs/storage/sqlite.md +71 -42
- package/docs/storage.md +298 -302
- package/docs/subagents/authoring.md +55 -38
- package/docs/subagents/reference.md +73 -33
- package/docs/subagents.md +119 -187
- package/docs/terminal-setup.md +50 -38
- package/docs/termux.md +67 -41
- package/docs/themes/reference.md +23 -19
- package/docs/themes.md +142 -127
- package/docs/tmux.md +47 -55
- package/docs/tools.md +147 -109
- package/docs/tui/reference.md +166 -214
- package/docs/tui.md +196 -341
- package/docs/usage.md +118 -138
- package/docs/verification.md +79 -51
- package/docs/web-access.md +121 -101
- package/docs/windows.md +26 -27
- package/docs/worktree-snapshots/reference.md +245 -0
- package/docs/worktree-snapshots.md +71 -259
- package/package.json +8 -8
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +0 -1
- package/docs/guides/intercom.md +0 -32
- package/docs/guides/orchestration.md +0 -28
- package/docs/guides/subagents.md +0 -37
|
@@ -1,87 +1,124 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Add OAuth login to a provider"
|
|
3
|
-
sidebarTitle: "OAuth
|
|
3
|
+
sidebarTitle: "Add OAuth Login"
|
|
4
4
|
description: "Implement OAuth login callbacks, token refresh, rejected-login errors, and dynamic model catalog refresh."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Add an `oauth` configuration to `atomic.registerProvider()` to integrate browser sign-in, device-code flows, or manual token entry directly with `/login`. Atomic handles credential storage in `auth.json`, cross-session refresh locking, and automatic retries after token refresh.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Implement OAuth login
|
|
10
|
+
|
|
11
|
+
Supply `name`, `login`, `refreshToken`, and `getApiKey` on `oauth`, alongside the provider's models:
|
|
10
12
|
|
|
11
13
|
```typescript
|
|
14
|
+
import type { ExtensionAPI } from "@bastani/atomic";
|
|
12
15
|
import type { OAuthCredentials, OAuthLoginCallbacks } from "@bastani/atomic-ai";
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
17
|
+
export default async function (atomic: ExtensionAPI) {
|
|
18
|
+
await atomic.registerProvider("corporate-ai", {
|
|
19
|
+
baseUrl: "https://ai.corp.com/v1",
|
|
20
|
+
api: "openai-responses",
|
|
21
|
+
models: [
|
|
22
|
+
{
|
|
23
|
+
id: "corp-chat-1",
|
|
24
|
+
name: "Corporate Chat 1",
|
|
25
|
+
reasoning: true,
|
|
26
|
+
input: ["text", "image"],
|
|
27
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
28
|
+
contextWindow: 200000,
|
|
29
|
+
maxTokens: 16384,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
oauth: {
|
|
33
|
+
name: "Corporate AI (SSO)",
|
|
34
|
+
|
|
35
|
+
async login(callbacks: OAuthLoginCallbacks, signal: AbortSignal): Promise<OAuthCredentials> {
|
|
36
|
+
// Choose the interaction matching your identity provider:
|
|
37
|
+
// 1. Browser-based OAuth redirect
|
|
38
|
+
callbacks.onAuth({ url: "https://sso.corp.com/authorize?..." });
|
|
39
|
+
|
|
40
|
+
// 2. Or device authorization code flow:
|
|
41
|
+
// callbacks.onDeviceCode({
|
|
42
|
+
// userCode: "ABCD-1234",
|
|
43
|
+
// verificationUri: "https://sso.corp.com/device",
|
|
44
|
+
// });
|
|
45
|
+
|
|
46
|
+
// 3. Prompt for manual authorization code or token
|
|
47
|
+
const code = await callbacks.onPrompt({ message: "Enter SSO code:" });
|
|
48
|
+
|
|
49
|
+
// Forward `signal` so cancelling /login aborts the network request
|
|
50
|
+
const tokens = await exchangeCodeForTokens(code, { signal });
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
refresh: tokens.refreshToken,
|
|
54
|
+
access: tokens.accessToken,
|
|
55
|
+
expires: Date.now() + tokens.expiresIn * 1000,
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
async refreshToken(
|
|
60
|
+
credentials: OAuthCredentials,
|
|
61
|
+
signal: AbortSignal
|
|
62
|
+
): Promise<OAuthCredentials> {
|
|
63
|
+
const tokens = await refreshAccessToken(credentials.refresh, { signal });
|
|
64
|
+
return {
|
|
65
|
+
refresh: tokens.refreshToken ?? credentials.refresh,
|
|
66
|
+
access: tokens.accessToken,
|
|
67
|
+
expires: Date.now() + tokens.expiresIn * 1000,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
getApiKey(credentials: OAuthCredentials): string {
|
|
72
|
+
return credentials.access;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
// Optional: adjust chat models from the token (image, classifier, and compactor models pass through unchanged)
|
|
76
|
+
modifyModels(models, credentials) {
|
|
77
|
+
const region = decodeRegionFromToken(credentials.access);
|
|
78
|
+
return models.map((model) => ({
|
|
79
|
+
...model,
|
|
80
|
+
baseUrl: `https://${region}.ai.corp.com/v1`,
|
|
81
|
+
}));
|
|
82
|
+
},
|
|
42
83
|
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
```
|
|
43
87
|
|
|
44
|
-
|
|
45
|
-
credentials: OAuthCredentials,
|
|
46
|
-
signal: AbortSignal
|
|
47
|
-
): Promise<OAuthCredentials> {
|
|
48
|
-
const tokens = await refreshAccessToken(credentials.refresh, { signal });
|
|
49
|
-
return {
|
|
50
|
-
refresh: tokens.refreshToken ?? credentials.refresh,
|
|
51
|
-
access: tokens.accessToken,
|
|
52
|
-
expires: Date.now() + tokens.expiresIn * 1000
|
|
53
|
-
};
|
|
54
|
-
},
|
|
88
|
+
Users sign in with `/login corporate-ai`. See [`OAuthLoginCallbacks`](/custom-provider/api-reference#oauthlogincallbacks) and [`OAuthCredentials`](/custom-provider/api-reference#oauthcredentials) for the full callback and credential interfaces.
|
|
55
89
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
90
|
+
<Note>
|
|
91
|
+
Shell [`atomic auth login`](/reference/cli#credential-commands) does not load extensions. Users must sign in to extension-registered providers through interactive `/login <provider>`.
|
|
92
|
+
</Note>
|
|
59
93
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
94
|
+
## Refresh timing, callbacks, and lifecycle
|
|
95
|
+
|
|
96
|
+
For how extension OAuth interacts with `auth.json` and other credential sources, see [Token refresh](/providers#token-refresh) and [Credential resolution order](/providers/reference#resolution-order).
|
|
97
|
+
|
|
98
|
+
### Token refresh timing and locking
|
|
99
|
+
|
|
100
|
+
- **5-minute refresh window.** Atomic refreshes stored OAuth tokens whenever fewer than 5 minutes of validity remain.
|
|
101
|
+
- **Cross-session lock.** Concurrent sessions serialize refreshes under a credential lock held for up to 2 minutes.
|
|
102
|
+
- **Caller wait budgets.** Chat requests wait up to 15 seconds for pre-request auth preparation; catalog refreshes wait up to 60 seconds.
|
|
103
|
+
|
|
104
|
+
<Warning>
|
|
105
|
+
Pass `signal` to your network call in `refreshToken()`, and do **not** add a shorter abort timeout of your own. Atomic never aborts `signal` on a caller wait timeout because the upstream server may have already rotated the refresh token; a late response still persists, and normal exit waits up to 3 seconds for it to finish.
|
|
106
|
+
</Warning>
|
|
71
107
|
|
|
72
|
-
|
|
108
|
+
### Callbacks, dialogs, and cancellation
|
|
73
109
|
|
|
74
|
-
|
|
110
|
+
- **Use callbacks, never stdin/stdout.** Always prompt and notify users through `callbacks`, because login flows may run in an isolated background process.
|
|
111
|
+
- **Dialog customization.** Set `loginLabel` to customize the login dialog title. Set `usesCallbackServer: true` when your login flow listens on a local callback server and also accepts a pasted redirect URL as fallback.
|
|
112
|
+
- **Device-code confirmation.** In `/login`, pressing **Enter** on a device-code prompt opens the verification URL and copies the user code by default. Pass `openBrowserOnConfirm: false` or `copyCodeOnConfirm: false` in `onDeviceCode()` to disable either behavior.
|
|
113
|
+
- **Save and cancellation semantics.** Successful login persists credentials before refreshing the model catalog; catalog-refresh errors appear in `/model` without rolling back the saved login. `/logout` deletes stored credentials without calling `refreshModels()`. Pressing `Escape` or `Ctrl+C` cancels cleanly (`AbortError` or an aborted `signal` stays quiet) and leaves prior credentials untouched, while provider denials, timeouts, network failures, malformed responses, and storage errors are shown to the user. Later registrations override earlier ones with the same provider ID.
|
|
75
114
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- **Two registration forms.** Config-object registration (`atomic.registerProvider(id, config)`) reads `config.oauth.usesCallbackServer`. Native `Provider` registration (`atomic.registerProvider(provider)`) reads `provider.auth.oauth.usesCallbackServer` when racing a local callback server against `interaction.prompt({ type: "manual_code", message: "Paste redirect URL:" })`. The built-in Anthropic, OpenAI, OpenAI Codex, and OpenRouter OAuth objects already set this flag; keep it when wrapping them, or set `false` for a replacement flow without a callback server. See [Native `Provider` registration](/custom-provider/api-reference#native-provider-registration).
|
|
80
|
-
- **Lifecycle and cancellation.** Successful login saves credentials before refreshing the model catalog. Logout removes stored credentials without calling `refreshModels`. Pressing Escape or Ctrl+C cancels login cleanly and keeps prior credentials and models unchanged. Later registrations override earlier ones by provider ID. Intentional cancellation (native `AbortError`, an aborted `signal`, nested abort causes, or the legacy exact `Login cancelled` error) stays quiet, whereas provider denials, timeouts, network errors, malformed responses, token exchange failures, and storage errors remain visible. Catalog-refresh errors appear in `/model` while keeping cached models usable and never roll back a saved login.
|
|
115
|
+
<Note>
|
|
116
|
+
**Native `Provider` registrations:** When using `atomic.registerProvider(provider)` instead of a config object, Atomic reads `provider.auth.oauth.usesCallbackServer` to decide whether to show the manual redirect-URL fallback alongside a local callback server. Built-in Anthropic, OpenAI, OpenAI Codex, and OpenRouter OAuth implementations already set this flag — preserve it when wrapping them, or set `false` for a replacement flow without a callback server. See [Native `Provider` registration](/custom-provider/api-reference#native-provider-registration).
|
|
117
|
+
</Note>
|
|
81
118
|
|
|
82
119
|
## Rejected logins
|
|
83
120
|
|
|
84
|
-
When
|
|
121
|
+
When your identity provider permanently rejects a stored refresh token (revoked access or expired login), throw `OAuthRefreshRejectedError` from `refreshToken()`:
|
|
85
122
|
|
|
86
123
|
```typescript
|
|
87
124
|
import { OAuthRefreshRejectedError } from "@bastani/atomic";
|
|
@@ -92,6 +129,7 @@ async refreshToken(credentials, signal) {
|
|
|
92
129
|
body: refreshBody(credentials),
|
|
93
130
|
signal,
|
|
94
131
|
});
|
|
132
|
+
|
|
95
133
|
if (!response.ok) {
|
|
96
134
|
const body = await response.json().catch(() => ({}));
|
|
97
135
|
if (response.status === 401 || body.error === "invalid_grant") {
|
|
@@ -103,30 +141,31 @@ async refreshToken(credentials, signal) {
|
|
|
103
141
|
}
|
|
104
142
|
throw new Error(`Token refresh failed (${response.status})`);
|
|
105
143
|
}
|
|
144
|
+
|
|
106
145
|
// Return refreshed credentials
|
|
107
146
|
}
|
|
108
147
|
```
|
|
109
148
|
|
|
110
|
-
Atomic checks whether another session saved a newer login
|
|
149
|
+
Atomic first checks whether another session already saved a newer login. If not, the request fails with a clear re-login prompt:
|
|
111
150
|
|
|
112
151
|
```text
|
|
113
152
|
OAuth refresh failed for corporate-ai: invalid_grant (Refresh token expired). The provider rejected the stored login; run /login corporate-ai to sign in again.
|
|
114
153
|
```
|
|
115
154
|
|
|
116
|
-
The message
|
|
155
|
+
The message includes only the provider ID, error code (or `HTTP <status>`), and safe description. Pass stored secrets as the third argument so Atomic strips any description that echoes a token, contains a URL, or exceeds length limits.
|
|
117
156
|
|
|
118
|
-
Atomic also recognizes rejected logins thrown as
|
|
157
|
+
Atomic also recognizes rejected logins thrown as ordinary errors (or wrapped in `cause`) when they carry HTTP `401` or any of the standard rejection codes (`invalid_grant`, `refresh_token_expired`, `refresh_token_reused`, `refresh_token_invalidated`):
|
|
119
158
|
|
|
120
|
-
- Errors with `error` or `code` set to a rejected-login code (`error_description`
|
|
159
|
+
- Errors with `error` or `code` set to a rejected-login code (`error_description` provides the description).
|
|
121
160
|
- Errors whose `body`, `data`, `response.data`, or `response.body` carries a rejected-login code in `error`, `error.code`, or `code` (object or JSON string).
|
|
122
161
|
- Errors with `status`, `statusCode`, `response.status`, or `response.statusCode` equal to `401`.
|
|
123
|
-
- Error messages containing
|
|
162
|
+
- Error messages containing one of the rejected-login codes.
|
|
124
163
|
|
|
125
|
-
Other failures (HTTP 5xx, network
|
|
164
|
+
Other failures (HTTP 5xx, network errors, or OAuth errors like `invalid_client`, `invalid_request`, or `server_error`) report `OAuth refresh failed for <provider>: <message>` without asking the user to log in again.
|
|
126
165
|
|
|
127
166
|
## Dynamic model catalog refresh
|
|
128
167
|
|
|
129
|
-
|
|
168
|
+
If a provider's available models change over time or depend on the signed-in account, implement `refreshModels(context)`. Atomic calls it during bounded asynchronous refreshes independently of login completion:
|
|
130
169
|
|
|
131
170
|
```typescript
|
|
132
171
|
await atomic.registerProvider("corporate-ai", {
|
|
@@ -137,68 +176,11 @@ await atomic.registerProvider("corporate-ai", {
|
|
|
137
176
|
async refreshModels({ allowNetwork, signal, force, credential }) {
|
|
138
177
|
if (!allowNetwork) return cachedModels;
|
|
139
178
|
return await fetchCorporateModels({ signal, force, credential });
|
|
140
|
-
}
|
|
179
|
+
},
|
|
141
180
|
});
|
|
142
181
|
```
|
|
143
182
|
|
|
144
|
-
- **Config-object registration (`registerProvider(id, config)`):**
|
|
145
|
-
- **Native `Provider` registration (`registerProvider(provider)`):**
|
|
146
|
-
|
|
147
|
-
The existing catalog stays usable while a refresh runs. Each provider's refresh settles independently; if one fails, times out, or sees an aborted `signal`, it keeps its previous list. For all `RefreshModelsContext` fields (`credential`, `stored`, `publish`, `allowNetwork`, `force`, `signal`, `baseUrl`, and `updateCredential`), see [`RefreshModelsContext`](/custom-provider/api-reference#refreshmodelscontext).
|
|
148
|
-
|
|
149
|
-
## OAuthLoginCallbacks
|
|
150
|
-
|
|
151
|
-
`callbacks` exposes the full user-interaction surface for `config.oauth.login()`:
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
interface OAuthLoginCallbacks {
|
|
155
|
-
/** Open a URL in the browser (for OAuth redirects). */
|
|
156
|
-
onAuth(info: { url: string; instructions?: string }): void;
|
|
157
|
-
|
|
158
|
-
/** Show a device code (for device authorization flows). */
|
|
159
|
-
onDeviceCode(info: {
|
|
160
|
-
userCode: string;
|
|
161
|
-
verificationUri: string;
|
|
162
|
-
openBrowserOnConfirm?: boolean; // default true
|
|
163
|
-
copyCodeOnConfirm?: boolean; // default true
|
|
164
|
-
intervalSeconds?: number;
|
|
165
|
-
expiresInSeconds?: number;
|
|
166
|
-
}): void;
|
|
167
|
-
|
|
168
|
-
/** Prompt the user for input (for manual code or token entry). */
|
|
169
|
-
onPrompt(prompt: {
|
|
170
|
-
message: string;
|
|
171
|
-
placeholder?: string;
|
|
172
|
-
allowEmpty?: boolean;
|
|
173
|
-
}): Promise<string>;
|
|
174
|
-
|
|
175
|
-
/** Report non-blocking status updates during login. */
|
|
176
|
-
onProgress?(message: string): void;
|
|
177
|
-
|
|
178
|
-
/** Read a manually pasted redirect URL or authorization code. */
|
|
179
|
-
onManualCodeInput?(): Promise<string>;
|
|
180
|
-
|
|
181
|
-
/** Let the user pick from a list of options (for example tenant or workspace). */
|
|
182
|
-
onSelect(prompt: {
|
|
183
|
-
message: string;
|
|
184
|
-
options: Array<{ id: string; label: string }>;
|
|
185
|
-
}): Promise<string | undefined>;
|
|
186
|
-
|
|
187
|
-
/** Cancellation signal for the active login attempt. */
|
|
188
|
-
signal?: AbortSignal;
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
In `/login`, pressing Enter (`tui.select.confirm`) opens the device verification URL and copies the code by default. Disable either action with `openBrowserOnConfirm: false` or `copyCodeOnConfirm: false` in `onDeviceCode` or native `AuthEvent` notifications.
|
|
193
|
-
|
|
194
|
-
## OAuthCredentials
|
|
183
|
+
- **Config-object registration (`registerProvider(id, config)`):** Return `ProviderModelConfig[]` (chat, image, classifier, or compactor) to replace the registration's live models. When `allowNetwork` is `false` (offline or cache-only startup restore), return cached models without making network requests.
|
|
184
|
+
- **Native `Provider` registration (`registerProvider(provider)`):** Call `await context.publish({ persist, update })` to update `models-store.json` and provider-owned state, then expose the refreshed models from `getModels()` (or `getAllModels()` for mixed-operation providers).
|
|
195
185
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
interface OAuthCredentials {
|
|
200
|
-
refresh: string; // Refresh token passed to refreshToken()
|
|
201
|
-
access: string; // Access token returned by getApiKey()
|
|
202
|
-
expires: number; // Expiration timestamp in milliseconds
|
|
203
|
-
}
|
|
204
|
-
```
|
|
186
|
+
The existing catalog remains selectable while a refresh runs. Each provider settles independently; if a refresh fails, times out, or sees an aborted `signal`, Atomic keeps the previous list. See [`RefreshModelsContext`](/custom-provider/api-reference#refreshmodelscontext) for every field on `context`.
|
|
@@ -1,41 +1,51 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Override a built-in provider"
|
|
3
|
-
sidebarTitle: "Override
|
|
4
|
-
description: "
|
|
3
|
+
sidebarTitle: "Override a Provider"
|
|
4
|
+
description: "Route a built-in provider through a proxy or attach custom request headers from an extension while keeping its models."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Use an extension override when you want to route a built-in provider through a corporate proxy, compute endpoints dynamically, or attach custom headers without redefining its model catalog. For static overrides with no code, configure [`~/.atomic/agent/models.json`](/models) instead.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Proxy or attach headers {#override-existing-provider}
|
|
10
|
+
|
|
11
|
+
Call `atomic.registerProvider()` with the built-in provider's ID and only the fields you want to override (`baseUrl` and/or `headers`):
|
|
10
12
|
|
|
11
13
|
```typescript
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
headers
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
14
|
+
import type { ExtensionAPI } from "@bastani/atomic";
|
|
15
|
+
|
|
16
|
+
export default async function (atomic: ExtensionAPI) {
|
|
17
|
+
// Route all Anthropic requests through a proxy
|
|
18
|
+
await atomic.registerProvider("anthropic", {
|
|
19
|
+
baseUrl: "https://proxy.example.com",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Add custom headers to OpenAI requests
|
|
23
|
+
await atomic.registerProvider("openai", {
|
|
24
|
+
headers: {
|
|
25
|
+
"X-Custom-Header": "value",
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Override both baseUrl and headers on Google
|
|
30
|
+
await atomic.registerProvider("google", {
|
|
31
|
+
baseUrl: "https://ai-gateway.corp.com/google",
|
|
32
|
+
headers: {
|
|
33
|
+
// Supports $ENV_VAR, ${ENV_VAR}, !command, or literal values ($$ for $, $! for leading !)
|
|
34
|
+
"X-Corp-Auth": "$CORP_AUTH_TOKEN",
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
32
38
|
```
|
|
33
39
|
|
|
34
|
-
When you
|
|
40
|
+
When you omit `models`, Atomic keeps every built-in model and existing authentication flow for that provider.
|
|
41
|
+
|
|
42
|
+
<Note>
|
|
43
|
+
Supplying a `models` array switches from an override to a full replacement across chat, image, classifier, and compactor models for that provider. To register new models or a brand-new provider, see [Register a custom provider](/custom-provider/registration).
|
|
44
|
+
</Note>
|
|
35
45
|
|
|
36
46
|
## How overrides merge and revert
|
|
37
47
|
|
|
38
|
-
- **Header merging.** Extension `headers` merge over `models.json` `headers` and over provider authentication headers
|
|
48
|
+
- **Header merging.** Extension `headers` merge over `models.json` `headers` and over provider authentication headers, with extension values winning on key collision. Header values support `$ENV_VAR`, `${ENV_VAR}`, `!command`, `$$`, and `$!` ([Value resolution](/models/reference#value-resolution)).
|
|
39
49
|
- **Incremental re-registration.** Calling `registerProvider("anthropic", { headers })` after `registerProvider("anthropic", { baseUrl })` keeps `baseUrl`, because defined fields merge over the previous registration.
|
|
40
|
-
- **Derived fast variants.** Overriding `baseUrl` on `anthropic`, `openai`, or `xai` preserves derived `-fast` variants as long as you do not
|
|
50
|
+
- **Derived fast variants.** Overriding `baseUrl` or `headers` on built-in `anthropic`, `anthropic-api`, `openai`, `openai-api`, `openai-codex`, or `xai` preserves derived `-fast` (and eligible `-ultrafast`) variants as long as you do not replace `models` or supply a custom `streamSimple` handler for that API.
|
|
41
51
|
- **Reverting an override.** Call `await atomic.unregisterProvider("anthropic")` to remove the extension override and restore the built-in provider (along with any `models.json` configuration) immediately without running `/reload`.
|