@dirgha/code 1.2.0
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/LICENSE +101 -0
- package/README.md +674 -0
- package/dist/dirgha.mjs +2185 -0
- package/dist_v2/acp/index.d.ts +1 -0
- package/dist_v2/acp/index.js +2 -0
- package/dist_v2/acp/server.d.ts +31 -0
- package/dist_v2/acp/server.js +137 -0
- package/dist_v2/cli/auth-cmd.d.ts +10 -0
- package/dist_v2/cli/auth-cmd.js +69 -0
- package/dist_v2/cli/config.d.ts +46 -0
- package/dist_v2/cli/config.js +70 -0
- package/dist_v2/cli/flags.d.ts +10 -0
- package/dist_v2/cli/flags.js +49 -0
- package/dist_v2/cli/flows/full-cycle.d.ts +30 -0
- package/dist_v2/cli/flows/full-cycle.js +39 -0
- package/dist_v2/cli/flows/index.d.ts +2 -0
- package/dist_v2/cli/flows/index.js +3 -0
- package/dist_v2/cli/flows/tarball.d.ts +10 -0
- package/dist_v2/cli/flows/tarball.js +47 -0
- package/dist_v2/cli/index.d.ts +4 -0
- package/dist_v2/cli/index.js +5 -0
- package/dist_v2/cli/interactive.d.ts +21 -0
- package/dist_v2/cli/interactive.js +207 -0
- package/dist_v2/cli/main.d.ts +10 -0
- package/dist_v2/cli/main.js +173 -0
- package/dist_v2/cli/models-cmd.d.ts +6 -0
- package/dist_v2/cli/models-cmd.js +50 -0
- package/dist_v2/cli/setup.d.ts +13 -0
- package/dist_v2/cli/setup.js +128 -0
- package/dist_v2/cli/slash/account.d.ts +10 -0
- package/dist_v2/cli/slash/account.js +59 -0
- package/dist_v2/cli/slash/clear.d.ts +8 -0
- package/dist_v2/cli/slash/clear.js +15 -0
- package/dist_v2/cli/slash/compact.d.ts +7 -0
- package/dist_v2/cli/slash/compact.js +13 -0
- package/dist_v2/cli/slash/config.d.ts +8 -0
- package/dist_v2/cli/slash/config.js +49 -0
- package/dist_v2/cli/slash/exit.d.ts +7 -0
- package/dist_v2/cli/slash/exit.js +16 -0
- package/dist_v2/cli/slash/fleet.d.ts +7 -0
- package/dist_v2/cli/slash/fleet.js +22 -0
- package/dist_v2/cli/slash/help.d.ts +9 -0
- package/dist_v2/cli/slash/help.js +31 -0
- package/dist_v2/cli/slash/history.d.ts +7 -0
- package/dist_v2/cli/slash/history.js +42 -0
- package/dist_v2/cli/slash/index.d.ts +30 -0
- package/dist_v2/cli/slash/index.js +52 -0
- package/dist_v2/cli/slash/init.d.ts +8 -0
- package/dist_v2/cli/slash/init.js +57 -0
- package/dist_v2/cli/slash/keys.d.ts +8 -0
- package/dist_v2/cli/slash/keys.js +101 -0
- package/dist_v2/cli/slash/login.d.ts +10 -0
- package/dist_v2/cli/slash/login.js +47 -0
- package/dist_v2/cli/slash/memory.d.ts +8 -0
- package/dist_v2/cli/slash/memory.js +101 -0
- package/dist_v2/cli/slash/mode.d.ts +8 -0
- package/dist_v2/cli/slash/mode.js +30 -0
- package/dist_v2/cli/slash/models.d.ts +8 -0
- package/dist_v2/cli/slash/models.js +73 -0
- package/dist_v2/cli/slash/resume.d.ts +8 -0
- package/dist_v2/cli/slash/resume.js +24 -0
- package/dist_v2/cli/slash/session.d.ts +8 -0
- package/dist_v2/cli/slash/session.js +74 -0
- package/dist_v2/cli/slash/setup.d.ts +8 -0
- package/dist_v2/cli/slash/setup.js +50 -0
- package/dist_v2/cli/slash/status.d.ts +7 -0
- package/dist_v2/cli/slash/status.js +37 -0
- package/dist_v2/cli/slash/theme.d.ts +9 -0
- package/dist_v2/cli/slash/theme.js +53 -0
- package/dist_v2/cli/slash/types.d.ts +14 -0
- package/dist_v2/cli/slash/types.js +9 -0
- package/dist_v2/cli/slash/upgrade.d.ts +9 -0
- package/dist_v2/cli/slash/upgrade.js +66 -0
- package/dist_v2/cli/slash.d.ts +72 -0
- package/dist_v2/cli/slash.js +77 -0
- package/dist_v2/cli/subcommands/ask.d.ts +17 -0
- package/dist_v2/cli/subcommands/ask.js +76 -0
- package/dist_v2/cli/subcommands/audit.d.ts +15 -0
- package/dist_v2/cli/subcommands/audit.js +128 -0
- package/dist_v2/cli/subcommands/chat.d.ts +13 -0
- package/dist_v2/cli/subcommands/chat.js +72 -0
- package/dist_v2/cli/subcommands/compact.d.ts +14 -0
- package/dist_v2/cli/subcommands/compact.js +114 -0
- package/dist_v2/cli/subcommands/doctor.d.ts +11 -0
- package/dist_v2/cli/subcommands/doctor.js +103 -0
- package/dist_v2/cli/subcommands/export-session.d.ts +10 -0
- package/dist_v2/cli/subcommands/export-session.js +60 -0
- package/dist_v2/cli/subcommands/import-session.d.ts +11 -0
- package/dist_v2/cli/subcommands/import-session.js +77 -0
- package/dist_v2/cli/subcommands/index.d.ts +40 -0
- package/dist_v2/cli/subcommands/index.js +38 -0
- package/dist_v2/cli/subcommands/init.d.ts +10 -0
- package/dist_v2/cli/subcommands/init.js +74 -0
- package/dist_v2/cli/subcommands/keys.d.ts +12 -0
- package/dist_v2/cli/subcommands/keys.js +136 -0
- package/dist_v2/cli/subcommands/login.d.ts +10 -0
- package/dist_v2/cli/subcommands/login.js +60 -0
- package/dist_v2/cli/subcommands/logout.d.ts +10 -0
- package/dist_v2/cli/subcommands/logout.js +21 -0
- package/dist_v2/cli/subcommands/models.d.ts +14 -0
- package/dist_v2/cli/subcommands/models.js +144 -0
- package/dist_v2/cli/subcommands/setup.d.ts +11 -0
- package/dist_v2/cli/subcommands/setup.js +107 -0
- package/dist_v2/cli/subcommands/stats.d.ts +13 -0
- package/dist_v2/cli/subcommands/stats.js +148 -0
- package/dist_v2/cli/subcommands/status.d.ts +14 -0
- package/dist_v2/cli/subcommands/status.js +91 -0
- package/dist_v2/cli/submit-paper.d.ts +15 -0
- package/dist_v2/cli/submit-paper.js +68 -0
- package/dist_v2/context/_fts.d.ts +62 -0
- package/dist_v2/context/_fts.js +195 -0
- package/dist_v2/context/branch.d.ts +18 -0
- package/dist_v2/context/branch.js +66 -0
- package/dist_v2/context/compaction.d.ts +26 -0
- package/dist_v2/context/compaction.js +120 -0
- package/dist_v2/context/index.d.ts +5 -0
- package/dist_v2/context/index.js +6 -0
- package/dist_v2/context/knowledge.d.ts +38 -0
- package/dist_v2/context/knowledge.js +146 -0
- package/dist_v2/context/memory.d.ts +80 -0
- package/dist_v2/context/memory.js +276 -0
- package/dist_v2/context/mode.d.ts +25 -0
- package/dist_v2/context/mode.js +81 -0
- package/dist_v2/context/session.d.ts +56 -0
- package/dist_v2/context/session.js +108 -0
- package/dist_v2/daemon/index.d.ts +2 -0
- package/dist_v2/daemon/index.js +3 -0
- package/dist_v2/daemon/protocol.d.ts +73 -0
- package/dist_v2/daemon/protocol.js +6 -0
- package/dist_v2/daemon/server.d.ts +35 -0
- package/dist_v2/daemon/server.js +191 -0
- package/dist_v2/eval/index.d.ts +5 -0
- package/dist_v2/eval/index.js +6 -0
- package/dist_v2/eval/regression.d.ts +14 -0
- package/dist_v2/eval/regression.js +106 -0
- package/dist_v2/eval/reporter.d.ts +7 -0
- package/dist_v2/eval/reporter.js +34 -0
- package/dist_v2/eval/swe-bench.d.ts +18 -0
- package/dist_v2/eval/swe-bench.js +23 -0
- package/dist_v2/eval/terminal-bench.d.ts +13 -0
- package/dist_v2/eval/terminal-bench.js +19 -0
- package/dist_v2/eval/types.d.ts +36 -0
- package/dist_v2/eval/types.js +5 -0
- package/dist_v2/fleet/apply-back.d.ts +27 -0
- package/dist_v2/fleet/apply-back.js +191 -0
- package/dist_v2/fleet/cli-command.d.ts +61 -0
- package/dist_v2/fleet/cli-command.js +329 -0
- package/dist_v2/fleet/index.d.ts +21 -0
- package/dist_v2/fleet/index.js +21 -0
- package/dist_v2/fleet/runner.d.ts +28 -0
- package/dist_v2/fleet/runner.js +347 -0
- package/dist_v2/fleet/tripleshot.d.ts +21 -0
- package/dist_v2/fleet/tripleshot.js +222 -0
- package/dist_v2/fleet/types.d.ts +193 -0
- package/dist_v2/fleet/types.js +24 -0
- package/dist_v2/fleet/worktree.d.ts +51 -0
- package/dist_v2/fleet/worktree.js +176 -0
- package/dist_v2/hooks/index.d.ts +1 -0
- package/dist_v2/hooks/index.js +2 -0
- package/dist_v2/hooks/registry.d.ts +21 -0
- package/dist_v2/hooks/registry.js +40 -0
- package/dist_v2/index.d.ts +12 -0
- package/dist_v2/index.js +11 -0
- package/dist_v2/integrations/arniko-client.d.ts +42 -0
- package/dist_v2/integrations/arniko-client.js +86 -0
- package/dist_v2/integrations/auth.d.ts +45 -0
- package/dist_v2/integrations/auth.js +54 -0
- package/dist_v2/integrations/billing.d.ts +71 -0
- package/dist_v2/integrations/billing.js +107 -0
- package/dist_v2/integrations/bucky-client.d.ts +105 -0
- package/dist_v2/integrations/bucky-client.js +76 -0
- package/dist_v2/integrations/deploy-client.d.ts +60 -0
- package/dist_v2/integrations/deploy-client.js +87 -0
- package/dist_v2/integrations/device-auth.d.ts +48 -0
- package/dist_v2/integrations/device-auth.js +192 -0
- package/dist_v2/integrations/entitlements.d.ts +34 -0
- package/dist_v2/integrations/entitlements.js +43 -0
- package/dist_v2/integrations/http.d.ts +22 -0
- package/dist_v2/integrations/http.js +114 -0
- package/dist_v2/integrations/index.d.ts +8 -0
- package/dist_v2/integrations/index.js +15 -0
- package/dist_v2/intelligence/cost.d.ts +28 -0
- package/dist_v2/intelligence/cost.js +58 -0
- package/dist_v2/intelligence/error-classifier.d.ts +8 -0
- package/dist_v2/intelligence/error-classifier.js +71 -0
- package/dist_v2/intelligence/index.d.ts +5 -0
- package/dist_v2/intelligence/index.js +6 -0
- package/dist_v2/intelligence/prices.d.ts +13 -0
- package/dist_v2/intelligence/prices.js +26 -0
- package/dist_v2/intelligence/smart-router.d.ts +21 -0
- package/dist_v2/intelligence/smart-router.js +59 -0
- package/dist_v2/intelligence/telemetry.d.ts +22 -0
- package/dist_v2/intelligence/telemetry.js +31 -0
- package/dist_v2/kernel/agent-loop.d.ts +32 -0
- package/dist_v2/kernel/agent-loop.js +151 -0
- package/dist_v2/kernel/event-stream.d.ts +18 -0
- package/dist_v2/kernel/event-stream.js +102 -0
- package/dist_v2/kernel/index.d.ts +4 -0
- package/dist_v2/kernel/index.js +5 -0
- package/dist_v2/kernel/message.d.ts +29 -0
- package/dist_v2/kernel/message.js +118 -0
- package/dist_v2/kernel/types.d.ts +206 -0
- package/dist_v2/kernel/types.js +9 -0
- package/dist_v2/mcp/client.d.ts +44 -0
- package/dist_v2/mcp/client.js +63 -0
- package/dist_v2/mcp/index.d.ts +3 -0
- package/dist_v2/mcp/index.js +4 -0
- package/dist_v2/mcp/tool-bridge.d.ts +11 -0
- package/dist_v2/mcp/tool-bridge.js +33 -0
- package/dist_v2/mcp/transport.d.ts +29 -0
- package/dist_v2/mcp/transport.js +73 -0
- package/dist_v2/parity/index.d.ts +3 -0
- package/dist_v2/parity/index.js +4 -0
- package/dist_v2/parity/mock-openai-compat.d.ts +15 -0
- package/dist_v2/parity/mock-openai-compat.js +35 -0
- package/dist_v2/parity/runner.d.ts +21 -0
- package/dist_v2/parity/runner.js +76 -0
- package/dist_v2/parity/scenarios.d.ts +20 -0
- package/dist_v2/parity/scenarios.js +70 -0
- package/dist_v2/providers/anthropic.d.ts +21 -0
- package/dist_v2/providers/anthropic.js +191 -0
- package/dist_v2/providers/dispatch.d.ts +11 -0
- package/dist_v2/providers/dispatch.js +45 -0
- package/dist_v2/providers/fireworks.d.ts +18 -0
- package/dist_v2/providers/fireworks.js +44 -0
- package/dist_v2/providers/gemini.d.ts +19 -0
- package/dist_v2/providers/gemini.js +188 -0
- package/dist_v2/providers/http.d.ts +41 -0
- package/dist_v2/providers/http.js +188 -0
- package/dist_v2/providers/iface.d.ts +18 -0
- package/dist_v2/providers/iface.js +18 -0
- package/dist_v2/providers/index.d.ts +39 -0
- package/dist_v2/providers/index.js +51 -0
- package/dist_v2/providers/nvidia.d.ts +27 -0
- package/dist_v2/providers/nvidia.js +142 -0
- package/dist_v2/providers/ollama.d.ts +15 -0
- package/dist_v2/providers/ollama.js +37 -0
- package/dist_v2/providers/openai-compat.d.ts +29 -0
- package/dist_v2/providers/openai-compat.js +239 -0
- package/dist_v2/providers/openai.d.ts +20 -0
- package/dist_v2/providers/openai.js +107 -0
- package/dist_v2/providers/openrouter.d.ts +24 -0
- package/dist_v2/providers/openrouter.js +69 -0
- package/dist_v2/safety/approval-bus.d.ts +26 -0
- package/dist_v2/safety/approval-bus.js +48 -0
- package/dist_v2/safety/audit-log.d.ts +27 -0
- package/dist_v2/safety/audit-log.js +71 -0
- package/dist_v2/safety/index.d.ts +4 -0
- package/dist_v2/safety/index.js +5 -0
- package/dist_v2/safety/policy.d.ts +32 -0
- package/dist_v2/safety/policy.js +131 -0
- package/dist_v2/safety/sandbox/bwrap.d.ts +11 -0
- package/dist_v2/safety/sandbox/bwrap.js +52 -0
- package/dist_v2/safety/sandbox/iface.d.ts +29 -0
- package/dist_v2/safety/sandbox/iface.js +8 -0
- package/dist_v2/safety/sandbox/index.d.ts +7 -0
- package/dist_v2/safety/sandbox/index.js +8 -0
- package/dist_v2/safety/sandbox/landlock.d.ts +17 -0
- package/dist_v2/safety/sandbox/landlock.js +26 -0
- package/dist_v2/safety/sandbox/noop.d.ts +12 -0
- package/dist_v2/safety/sandbox/noop.js +52 -0
- package/dist_v2/safety/sandbox/seatbelt.d.ts +11 -0
- package/dist_v2/safety/sandbox/seatbelt.js +49 -0
- package/dist_v2/safety/sandbox/select.d.ts +6 -0
- package/dist_v2/safety/sandbox/select.js +42 -0
- package/dist_v2/safety/sandbox/windows.d.ts +13 -0
- package/dist_v2/safety/sandbox/windows.js +22 -0
- package/dist_v2/skills/index.d.ts +3 -0
- package/dist_v2/skills/index.js +4 -0
- package/dist_v2/skills/loader.d.ts +38 -0
- package/dist_v2/skills/loader.js +102 -0
- package/dist_v2/skills/matcher.d.ts +14 -0
- package/dist_v2/skills/matcher.js +72 -0
- package/dist_v2/skills/runtime.d.ts +13 -0
- package/dist_v2/skills/runtime.js +40 -0
- package/dist_v2/subagents/delegator.d.ts +36 -0
- package/dist_v2/subagents/delegator.js +82 -0
- package/dist_v2/subagents/index.d.ts +2 -0
- package/dist_v2/subagents/index.js +3 -0
- package/dist_v2/subagents/pool.d.ts +18 -0
- package/dist_v2/subagents/pool.js +31 -0
- package/dist_v2/tools/browser.d.ts +27 -0
- package/dist_v2/tools/browser.js +179 -0
- package/dist_v2/tools/checkpoint.d.ts +25 -0
- package/dist_v2/tools/checkpoint.js +222 -0
- package/dist_v2/tools/cron.d.ts +32 -0
- package/dist_v2/tools/cron.js +160 -0
- package/dist_v2/tools/diff.d.ts +18 -0
- package/dist_v2/tools/diff.js +117 -0
- package/dist_v2/tools/exec.d.ts +19 -0
- package/dist_v2/tools/exec.js +49 -0
- package/dist_v2/tools/fs-edit.d.ts +11 -0
- package/dist_v2/tools/fs-edit.js +81 -0
- package/dist_v2/tools/fs-ls.d.ts +7 -0
- package/dist_v2/tools/fs-ls.js +57 -0
- package/dist_v2/tools/fs-read.d.ts +7 -0
- package/dist_v2/tools/fs-read.js +60 -0
- package/dist_v2/tools/fs-write.d.ts +8 -0
- package/dist_v2/tools/fs-write.js +46 -0
- package/dist_v2/tools/git.d.ts +8 -0
- package/dist_v2/tools/git.js +57 -0
- package/dist_v2/tools/index.d.ts +25 -0
- package/dist_v2/tools/index.js +39 -0
- package/dist_v2/tools/multimodal.d.ts +41 -0
- package/dist_v2/tools/multimodal.js +381 -0
- package/dist_v2/tools/permission.d.ts +27 -0
- package/dist_v2/tools/permission.js +43 -0
- package/dist_v2/tools/registry.d.ts +44 -0
- package/dist_v2/tools/registry.js +62 -0
- package/dist_v2/tools/search-glob.d.ts +7 -0
- package/dist_v2/tools/search-glob.js +98 -0
- package/dist_v2/tools/search-grep.d.ts +7 -0
- package/dist_v2/tools/search-grep.js +109 -0
- package/dist_v2/tools/shell.d.ts +10 -0
- package/dist_v2/tools/shell.js +76 -0
- package/dist_v2/tools/task.d.ts +8 -0
- package/dist_v2/tools/task.js +37 -0
- package/dist_v2/tui/approval.d.ts +7 -0
- package/dist_v2/tui/approval.js +55 -0
- package/dist_v2/tui/index.d.ts +4 -0
- package/dist_v2/tui/index.js +5 -0
- package/dist_v2/tui/ink/App.d.ts +39 -0
- package/dist_v2/tui/ink/App.js +206 -0
- package/dist_v2/tui/ink/components/AtFileComplete.d.ts +25 -0
- package/dist_v2/tui/ink/components/AtFileComplete.js +158 -0
- package/dist_v2/tui/ink/components/HelpOverlay.d.ts +24 -0
- package/dist_v2/tui/ink/components/HelpOverlay.js +130 -0
- package/dist_v2/tui/ink/components/InputBox.d.ts +35 -0
- package/dist_v2/tui/ink/components/InputBox.js +153 -0
- package/dist_v2/tui/ink/components/Logo.d.ts +12 -0
- package/dist_v2/tui/ink/components/Logo.js +27 -0
- package/dist_v2/tui/ink/components/ModelPicker.d.ts +26 -0
- package/dist_v2/tui/ink/components/ModelPicker.js +80 -0
- package/dist_v2/tui/ink/components/PasteCollapse.d.ts +36 -0
- package/dist_v2/tui/ink/components/PasteCollapse.js +59 -0
- package/dist_v2/tui/ink/components/StatusBar.d.ts +18 -0
- package/dist_v2/tui/ink/components/StatusBar.js +41 -0
- package/dist_v2/tui/ink/components/StreamingText.d.ts +14 -0
- package/dist_v2/tui/ink/components/StreamingText.js +11 -0
- package/dist_v2/tui/ink/components/ThinkingBlock.d.ts +13 -0
- package/dist_v2/tui/ink/components/ThinkingBlock.js +13 -0
- package/dist_v2/tui/ink/components/ToolBox.d.ts +20 -0
- package/dist_v2/tui/ink/components/ToolBox.js +63 -0
- package/dist_v2/tui/ink/components/vim-bindings.d.ts +43 -0
- package/dist_v2/tui/ink/components/vim-bindings.js +135 -0
- package/dist_v2/tui/ink/index.d.ts +39 -0
- package/dist_v2/tui/ink/index.js +47 -0
- package/dist_v2/tui/ink/use-event-projection.d.ts +51 -0
- package/dist_v2/tui/ink/use-event-projection.js +126 -0
- package/dist_v2/tui/ink/use-overlays.d.ts +24 -0
- package/dist_v2/tui/ink/use-overlays.js +50 -0
- package/dist_v2/tui/renderer.d.ts +19 -0
- package/dist_v2/tui/renderer.js +64 -0
- package/dist_v2/tui/status-bar.d.ts +12 -0
- package/dist_v2/tui/status-bar.js +16 -0
- package/dist_v2/tui/theme.d.ts +27 -0
- package/dist_v2/tui/theme.js +56 -0
- package/dist_v2/utils/json-repair.d.ts +7 -0
- package/dist_v2/utils/json-repair.js +45 -0
- package/package.json +113 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Compatibility shim. Use `./device-auth.js` directly.
|
|
3
|
+
*
|
|
4
|
+
* Earlier revisions of the CLI shipped two parallel auth modules: this
|
|
5
|
+
* file (storing `~/.dirgha/auth.json` behind `/api/auth/cli/*`) and
|
|
6
|
+
* `device-auth.ts` (storing `~/.dirgha/credentials.json` behind
|
|
7
|
+
* `/api/auth/device/*`). The device-code flow is the spec-aligned one
|
|
8
|
+
* and is now the canonical implementation. This shim preserves the
|
|
9
|
+
* historical `AuthClient` surface so a small number of in-tree callers
|
|
10
|
+
* (`cli/auth-cmd.ts`, `cli/flows/full-cycle.ts`) keep compiling while
|
|
11
|
+
* they migrate.
|
|
12
|
+
*
|
|
13
|
+
* On first use we silently migrate any pre-existing `auth.json` payload
|
|
14
|
+
* into `credentials.json` (see `device-auth.migrateLegacyAuth`).
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `Token` from `./device-auth.js`. Retained for back-compat.
|
|
18
|
+
*/
|
|
19
|
+
export interface AuthToken {
|
|
20
|
+
jwt: string;
|
|
21
|
+
scope: string[];
|
|
22
|
+
expiresAt: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
}
|
|
25
|
+
/** @deprecated Use the functional API in `./device-auth.js`. */
|
|
26
|
+
export interface AuthClient {
|
|
27
|
+
currentToken(): Promise<AuthToken | undefined>;
|
|
28
|
+
login(): Promise<AuthToken>;
|
|
29
|
+
logout(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** @deprecated Use `startDeviceAuth` / `pollDeviceAuth` arguments instead. */
|
|
32
|
+
export interface AuthClientOptions {
|
|
33
|
+
gatewayUrl?: string;
|
|
34
|
+
tokenPath?: string;
|
|
35
|
+
pollIntervalMs?: number;
|
|
36
|
+
pollTimeoutMs?: number;
|
|
37
|
+
openBrowser?: (url: string) => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Prefer the functional API in `./device-auth.js`
|
|
41
|
+
* (`startDeviceAuth`, `pollDeviceAuth`, `saveToken`,
|
|
42
|
+
* `loadToken`, `clearToken`). This helper exists only so
|
|
43
|
+
* legacy callers keep compiling.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createAuthClient(opts?: AuthClientOptions): AuthClient;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Compatibility shim. Use `./device-auth.js` directly.
|
|
3
|
+
*
|
|
4
|
+
* Earlier revisions of the CLI shipped two parallel auth modules: this
|
|
5
|
+
* file (storing `~/.dirgha/auth.json` behind `/api/auth/cli/*`) and
|
|
6
|
+
* `device-auth.ts` (storing `~/.dirgha/credentials.json` behind
|
|
7
|
+
* `/api/auth/device/*`). The device-code flow is the spec-aligned one
|
|
8
|
+
* and is now the canonical implementation. This shim preserves the
|
|
9
|
+
* historical `AuthClient` surface so a small number of in-tree callers
|
|
10
|
+
* (`cli/auth-cmd.ts`, `cli/flows/full-cycle.ts`) keep compiling while
|
|
11
|
+
* they migrate.
|
|
12
|
+
*
|
|
13
|
+
* On first use we silently migrate any pre-existing `auth.json` payload
|
|
14
|
+
* into `credentials.json` (see `device-auth.migrateLegacyAuth`).
|
|
15
|
+
*/
|
|
16
|
+
import { clearToken, loadToken, migrateLegacyAuth, pollDeviceAuth, saveToken, startDeviceAuth, } from './device-auth.js';
|
|
17
|
+
function toAuthToken(tok) {
|
|
18
|
+
return { jwt: tok.token, scope: [], expiresAt: tok.expiresAt, userId: tok.userId };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Prefer the functional API in `./device-auth.js`
|
|
22
|
+
* (`startDeviceAuth`, `pollDeviceAuth`, `saveToken`,
|
|
23
|
+
* `loadToken`, `clearToken`). This helper exists only so
|
|
24
|
+
* legacy callers keep compiling.
|
|
25
|
+
*/
|
|
26
|
+
export function createAuthClient(opts = {}) {
|
|
27
|
+
const openBrowser = opts.openBrowser ?? ((url) => { process.stdout.write(`Open in a browser to continue:\n${url}\n`); });
|
|
28
|
+
const apiBase = opts.gatewayUrl;
|
|
29
|
+
return {
|
|
30
|
+
async currentToken() {
|
|
31
|
+
await migrateLegacyAuth().catch(() => undefined);
|
|
32
|
+
const tok = await loadToken();
|
|
33
|
+
return tok ? toAuthToken(tok) : undefined;
|
|
34
|
+
},
|
|
35
|
+
async login() {
|
|
36
|
+
await migrateLegacyAuth().catch(() => undefined);
|
|
37
|
+
const start = await startDeviceAuth(apiBase);
|
|
38
|
+
openBrowser(start.verifyUri);
|
|
39
|
+
const result = await pollDeviceAuth(start.deviceCode, apiBase, {
|
|
40
|
+
intervalMs: opts.pollIntervalMs ?? start.interval,
|
|
41
|
+
timeoutMs: opts.pollTimeoutMs,
|
|
42
|
+
});
|
|
43
|
+
await saveToken(result.token, result.userId, result.email);
|
|
44
|
+
const stored = await loadToken();
|
|
45
|
+
if (!stored)
|
|
46
|
+
throw new Error('login succeeded but token failed to persist');
|
|
47
|
+
return toAuthToken(stored);
|
|
48
|
+
},
|
|
49
|
+
async logout() {
|
|
50
|
+
await clearToken();
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Billing client — quota preflight, usage recording, and per-session budget
|
|
3
|
+
* enforcement for the agent loop.
|
|
4
|
+
*
|
|
5
|
+
* Three remote endpoints:
|
|
6
|
+
* POST /api/billing/preflight — quota check before an LLM call
|
|
7
|
+
* POST /api/billing/record — post-request usage recording
|
|
8
|
+
* GET /api/billing/account — tier + balance + limits snapshot
|
|
9
|
+
*
|
|
10
|
+
* The local `BillingContext` accumulates per-session totals so the loop can
|
|
11
|
+
* enforce an optional per-session budget without a round trip on every turn.
|
|
12
|
+
*/
|
|
13
|
+
export interface QuotaCheck {
|
|
14
|
+
allowed: boolean;
|
|
15
|
+
reason?: string;
|
|
16
|
+
remaining: number;
|
|
17
|
+
resetAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface UsageRecord {
|
|
20
|
+
costUsd: number;
|
|
21
|
+
newBalance: number;
|
|
22
|
+
}
|
|
23
|
+
export interface AccountStatus {
|
|
24
|
+
userId: string;
|
|
25
|
+
email: string;
|
|
26
|
+
tier: 'free' | 'pro' | 'team' | 'enterprise';
|
|
27
|
+
balanceUsd: number;
|
|
28
|
+
limits: {
|
|
29
|
+
dailyTokens: number;
|
|
30
|
+
monthlyTokens: number;
|
|
31
|
+
dailyTokensUsed: number;
|
|
32
|
+
monthlyTokensUsed: number;
|
|
33
|
+
};
|
|
34
|
+
resetAt: string;
|
|
35
|
+
}
|
|
36
|
+
export interface BillingContext {
|
|
37
|
+
sessionId: string;
|
|
38
|
+
tokensUsed: number;
|
|
39
|
+
costUsdTotal: number;
|
|
40
|
+
budgetCapUsd?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface PreflightResult {
|
|
43
|
+
allowed: boolean;
|
|
44
|
+
reason?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check remote quota before dispatching an LLM call. Returns allowed=false
|
|
48
|
+
* plus a human-readable reason when the user is out of quota. Throws on
|
|
49
|
+
* network / 5xx errors (the caller decides whether to fail open).
|
|
50
|
+
*/
|
|
51
|
+
export declare function checkQuota(token: string, estimatedTokens: number, apiBase?: string): Promise<QuotaCheck>;
|
|
52
|
+
/**
|
|
53
|
+
* Record post-request usage. The gateway is the source of truth for cost —
|
|
54
|
+
* we trust its math rather than recomputing locally.
|
|
55
|
+
*/
|
|
56
|
+
export declare function recordUsage(token: string, modelId: string, inputTokens: number, outputTokens: number, apiBase?: string): Promise<UsageRecord>;
|
|
57
|
+
/** Fetch tier + balance + limits. */
|
|
58
|
+
export declare function getAccountStatus(token: string, apiBase?: string): Promise<AccountStatus>;
|
|
59
|
+
export declare function createBillingContext(sessionId: string, budgetCapUsd?: number): BillingContext;
|
|
60
|
+
/**
|
|
61
|
+
* Pre-request quota + budget gate. Local budget is checked first (no I/O);
|
|
62
|
+
* remote preflight is optional and fails open when a token is absent or
|
|
63
|
+
* the gateway is unreachable.
|
|
64
|
+
*/
|
|
65
|
+
export declare function preRequestCheck(ctx: BillingContext, estTokens: number, opts?: {
|
|
66
|
+
token?: string;
|
|
67
|
+
apiBase?: string;
|
|
68
|
+
remote?: boolean;
|
|
69
|
+
}): Promise<PreflightResult>;
|
|
70
|
+
/** Folds a recorded usage sample into a session context. */
|
|
71
|
+
export declare function applyUsage(ctx: BillingContext, inputTokens: number, outputTokens: number, costUsd: number): BillingContext;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Billing client — quota preflight, usage recording, and per-session budget
|
|
3
|
+
* enforcement for the agent loop.
|
|
4
|
+
*
|
|
5
|
+
* Three remote endpoints:
|
|
6
|
+
* POST /api/billing/preflight — quota check before an LLM call
|
|
7
|
+
* POST /api/billing/record — post-request usage recording
|
|
8
|
+
* GET /api/billing/account — tier + balance + limits snapshot
|
|
9
|
+
*
|
|
10
|
+
* The local `BillingContext` accumulates per-session totals so the loop can
|
|
11
|
+
* enforce an optional per-session budget without a round trip on every turn.
|
|
12
|
+
*/
|
|
13
|
+
import { IntegrationError, jsonRequest } from './http.js';
|
|
14
|
+
const DEFAULT_API_BASE = 'https://api.dirgha.ai';
|
|
15
|
+
function resolveApiBase(apiBase) {
|
|
16
|
+
const raw = apiBase ?? process.env.DIRGHA_API_BASE ?? DEFAULT_API_BASE;
|
|
17
|
+
return raw.replace(/\/+$/, '');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check remote quota before dispatching an LLM call. Returns allowed=false
|
|
21
|
+
* plus a human-readable reason when the user is out of quota. Throws on
|
|
22
|
+
* network / 5xx errors (the caller decides whether to fail open).
|
|
23
|
+
*/
|
|
24
|
+
export async function checkQuota(token, estimatedTokens, apiBase) {
|
|
25
|
+
const response = await jsonRequest({
|
|
26
|
+
baseUrl: resolveApiBase(apiBase),
|
|
27
|
+
path: '/api/billing/preflight',
|
|
28
|
+
method: 'POST',
|
|
29
|
+
token,
|
|
30
|
+
body: { estimated_tokens: estimatedTokens },
|
|
31
|
+
timeoutMs: 5_000,
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
allowed: response.allowed !== false,
|
|
35
|
+
reason: response.reason,
|
|
36
|
+
remaining: typeof response.remaining === 'number' ? response.remaining : 0,
|
|
37
|
+
resetAt: response.resetAt ?? response.reset_at ?? '',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Record post-request usage. The gateway is the source of truth for cost —
|
|
42
|
+
* we trust its math rather than recomputing locally.
|
|
43
|
+
*/
|
|
44
|
+
export async function recordUsage(token, modelId, inputTokens, outputTokens, apiBase) {
|
|
45
|
+
const response = await jsonRequest({
|
|
46
|
+
baseUrl: resolveApiBase(apiBase),
|
|
47
|
+
path: '/api/billing/record',
|
|
48
|
+
method: 'POST',
|
|
49
|
+
token,
|
|
50
|
+
body: { model_id: modelId, input_tokens: inputTokens, output_tokens: outputTokens },
|
|
51
|
+
timeoutMs: 5_000,
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
costUsd: response.costUsd ?? response.cost_usd ?? 0,
|
|
55
|
+
newBalance: response.newBalance ?? response.new_balance ?? 0,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Fetch tier + balance + limits. */
|
|
59
|
+
export async function getAccountStatus(token, apiBase) {
|
|
60
|
+
return jsonRequest({
|
|
61
|
+
baseUrl: resolveApiBase(apiBase),
|
|
62
|
+
path: '/api/billing/account',
|
|
63
|
+
method: 'GET',
|
|
64
|
+
token,
|
|
65
|
+
timeoutMs: 5_000,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export function createBillingContext(sessionId, budgetCapUsd) {
|
|
69
|
+
return { sessionId, tokensUsed: 0, costUsdTotal: 0, budgetCapUsd };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Pre-request quota + budget gate. Local budget is checked first (no I/O);
|
|
73
|
+
* remote preflight is optional and fails open when a token is absent or
|
|
74
|
+
* the gateway is unreachable.
|
|
75
|
+
*/
|
|
76
|
+
export async function preRequestCheck(ctx, estTokens, opts = {}) {
|
|
77
|
+
if (ctx.budgetCapUsd !== undefined && ctx.costUsdTotal >= ctx.budgetCapUsd) {
|
|
78
|
+
return {
|
|
79
|
+
allowed: false,
|
|
80
|
+
reason: `Session budget cap reached: $${ctx.costUsdTotal.toFixed(4)} / $${ctx.budgetCapUsd.toFixed(4)}`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (opts.remote !== false && opts.token) {
|
|
84
|
+
try {
|
|
85
|
+
const quota = await checkQuota(opts.token, estTokens, opts.apiBase);
|
|
86
|
+
if (!quota.allowed) {
|
|
87
|
+
return { allowed: false, reason: quota.reason ?? 'Quota exceeded' };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
// Offline-first: swallow network + auth errors, let the LLM call
|
|
92
|
+
// surface the real failure if the gateway is truly down.
|
|
93
|
+
if (err instanceof IntegrationError && err.status === 401) {
|
|
94
|
+
return { allowed: false, reason: 'Auth expired — run `dirgha login`' };
|
|
95
|
+
}
|
|
96
|
+
// fall through — offline-first
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return { allowed: true };
|
|
100
|
+
}
|
|
101
|
+
/** Folds a recorded usage sample into a session context. */
|
|
102
|
+
export function applyUsage(ctx, inputTokens, outputTokens, costUsd) {
|
|
103
|
+
ctx.tokensUsed += inputTokens + outputTokens;
|
|
104
|
+
ctx.costUsdTotal += costUsd;
|
|
105
|
+
return ctx;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bucky client. Thin wrapper over the Hono.js service (default port
|
|
3
|
+
* 3002). All methods take an explicit bearer token argument so callers
|
|
4
|
+
* can control scope (gateway passthrough vs anonymous for public
|
|
5
|
+
* endpoints).
|
|
6
|
+
*/
|
|
7
|
+
export interface BuckyTask {
|
|
8
|
+
id: string;
|
|
9
|
+
status: string;
|
|
10
|
+
title: string;
|
|
11
|
+
payload?: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface Team {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
members?: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface MeshStatus {
|
|
19
|
+
peerCount: number;
|
|
20
|
+
peers: Array<{
|
|
21
|
+
id: string;
|
|
22
|
+
addr?: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export interface CodeBlock {
|
|
26
|
+
id: string;
|
|
27
|
+
code: string;
|
|
28
|
+
language: string;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
}
|
|
31
|
+
export interface Proposal {
|
|
32
|
+
id: string;
|
|
33
|
+
title: string;
|
|
34
|
+
description: string;
|
|
35
|
+
status: string;
|
|
36
|
+
}
|
|
37
|
+
export interface VmHandle {
|
|
38
|
+
vmId: string;
|
|
39
|
+
endpoint?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface BuckyClientOptions {
|
|
42
|
+
baseUrl?: string;
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
}
|
|
45
|
+
export declare function createBuckyClient(opts?: BuckyClientOptions): {
|
|
46
|
+
tasks: {
|
|
47
|
+
list(token?: string): Promise<{
|
|
48
|
+
tasks: BuckyTask[];
|
|
49
|
+
}>;
|
|
50
|
+
submit(payload: unknown, token?: string): Promise<BuckyTask>;
|
|
51
|
+
};
|
|
52
|
+
dao: {
|
|
53
|
+
listTeams(token?: string): Promise<{
|
|
54
|
+
teams: Team[];
|
|
55
|
+
}>;
|
|
56
|
+
getTeam(id: string, token?: string): Promise<Team>;
|
|
57
|
+
};
|
|
58
|
+
mesh: {
|
|
59
|
+
status(token?: string): Promise<MeshStatus>;
|
|
60
|
+
};
|
|
61
|
+
lightning: {
|
|
62
|
+
balance(token?: string): Promise<{
|
|
63
|
+
sats: number;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
reputation: {
|
|
67
|
+
get(userId: string, token?: string): Promise<{
|
|
68
|
+
userId: string;
|
|
69
|
+
score: number;
|
|
70
|
+
}>;
|
|
71
|
+
};
|
|
72
|
+
code: {
|
|
73
|
+
register(code: string, language: string, token?: string): Promise<{
|
|
74
|
+
id: string;
|
|
75
|
+
}>;
|
|
76
|
+
get(id: string, token?: string): Promise<CodeBlock>;
|
|
77
|
+
list(token?: string): Promise<{
|
|
78
|
+
blocks: CodeBlock[];
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
governance: {
|
|
82
|
+
propose(proposal: Partial<Proposal> & {
|
|
83
|
+
proposer: string;
|
|
84
|
+
title: string;
|
|
85
|
+
}, token?: string): Promise<Proposal>;
|
|
86
|
+
vote(vote: {
|
|
87
|
+
proposalId: string;
|
|
88
|
+
voterId: string;
|
|
89
|
+
balance: number;
|
|
90
|
+
direction: "yes" | "no";
|
|
91
|
+
}, token?: string): Promise<{
|
|
92
|
+
ok: boolean;
|
|
93
|
+
}>;
|
|
94
|
+
list(token?: string): Promise<{
|
|
95
|
+
proposals: Proposal[];
|
|
96
|
+
}>;
|
|
97
|
+
};
|
|
98
|
+
vm: {
|
|
99
|
+
create(cpuCount: number, memoryMB: number, token?: string): Promise<VmHandle>;
|
|
100
|
+
destroy(vmId: string, token?: string): Promise<{
|
|
101
|
+
ok: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
export type BuckyClient = ReturnType<typeof createBuckyClient>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bucky client. Thin wrapper over the Hono.js service (default port
|
|
3
|
+
* 3002). All methods take an explicit bearer token argument so callers
|
|
4
|
+
* can control scope (gateway passthrough vs anonymous for public
|
|
5
|
+
* endpoints).
|
|
6
|
+
*/
|
|
7
|
+
import { jsonRequest } from './http.js';
|
|
8
|
+
export function createBuckyClient(opts = {}) {
|
|
9
|
+
const baseUrl = opts.baseUrl ?? process.env.DIRGHA_BUCKY_URL ?? 'http://localhost:3002';
|
|
10
|
+
const timeoutMs = opts.timeoutMs ?? 20_000;
|
|
11
|
+
const req = (options) => jsonRequest({ baseUrl, timeoutMs, ...options });
|
|
12
|
+
return {
|
|
13
|
+
tasks: {
|
|
14
|
+
list(token) {
|
|
15
|
+
return req({ method: 'GET', path: '/api/tasks', token });
|
|
16
|
+
},
|
|
17
|
+
submit(payload, token) {
|
|
18
|
+
return req({ method: 'POST', path: '/api/tasks', body: payload, token });
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
dao: {
|
|
22
|
+
listTeams(token) {
|
|
23
|
+
return req({ method: 'GET', path: '/api/dao/teams', token });
|
|
24
|
+
},
|
|
25
|
+
getTeam(id, token) {
|
|
26
|
+
return req({ method: 'GET', path: `/api/dao/teams/${encodeURIComponent(id)}`, token });
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
mesh: {
|
|
30
|
+
status(token) {
|
|
31
|
+
return req({ method: 'GET', path: '/api/mesh/status', token });
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
lightning: {
|
|
35
|
+
balance(token) {
|
|
36
|
+
return req({ method: 'GET', path: '/api/lightning/balance', token });
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
reputation: {
|
|
40
|
+
get(userId, token) {
|
|
41
|
+
return req({ method: 'GET', path: `/api/reputation/${encodeURIComponent(userId)}`, token });
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
code: {
|
|
45
|
+
register(code, language, token) {
|
|
46
|
+
return req({ method: 'POST', path: '/code/register', body: { code, language }, token });
|
|
47
|
+
},
|
|
48
|
+
get(id, token) {
|
|
49
|
+
return req({ method: 'GET', path: `/code/${encodeURIComponent(id)}`, token });
|
|
50
|
+
},
|
|
51
|
+
list(token) {
|
|
52
|
+
return req({ method: 'GET', path: '/code', token });
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
governance: {
|
|
56
|
+
propose(proposal, token) {
|
|
57
|
+
return req({ method: 'POST', path: '/governance/propose', body: proposal, token });
|
|
58
|
+
},
|
|
59
|
+
vote(vote, token) {
|
|
60
|
+
return req({ method: 'POST', path: '/governance/vote', body: vote, token });
|
|
61
|
+
},
|
|
62
|
+
list(token) {
|
|
63
|
+
return req({ method: 'GET', path: '/governance/proposals', token });
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
vm: {
|
|
67
|
+
create(cpuCount, memoryMB, token) {
|
|
68
|
+
return req({ method: 'POST', path: '/vm/create', body: { cpuCount, memoryMB }, token });
|
|
69
|
+
},
|
|
70
|
+
destroy(vmId, token) {
|
|
71
|
+
return req({ method: 'DELETE', path: `/vm/${encodeURIComponent(vmId)}`, token });
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=bucky-client.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dirgha Deploy client. Talks to the gateway deploy routes (port 3001
|
|
3
|
+
* in development, api.dirgha.ai in production). Supports project CRUD,
|
|
4
|
+
* deployment trigger + rollback, a CLI tarball upload endpoint, and a
|
|
5
|
+
* Server-Sent-Events log stream.
|
|
6
|
+
*/
|
|
7
|
+
export interface Project {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
provider: string;
|
|
11
|
+
region: string;
|
|
12
|
+
domains: string[];
|
|
13
|
+
createdAt: string;
|
|
14
|
+
}
|
|
15
|
+
export interface Deployment {
|
|
16
|
+
id: string;
|
|
17
|
+
projectId: string;
|
|
18
|
+
status: 'queued' | 'building' | 'ready' | 'failed' | 'rolled_back';
|
|
19
|
+
url?: string;
|
|
20
|
+
commitSha?: string;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
}
|
|
23
|
+
export interface DeployClientOptions {
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function createDeployClient(opts?: DeployClientOptions): {
|
|
28
|
+
projects: {
|
|
29
|
+
list(token: string): Promise<{
|
|
30
|
+
projects: Project[];
|
|
31
|
+
}>;
|
|
32
|
+
create(project: Partial<Project> & {
|
|
33
|
+
name: string;
|
|
34
|
+
}, token: string): Promise<Project>;
|
|
35
|
+
get(id: string, token: string): Promise<Project>;
|
|
36
|
+
update(id: string, patch: Partial<Project>, token: string): Promise<Project>;
|
|
37
|
+
remove(id: string, token: string): Promise<{
|
|
38
|
+
ok: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
};
|
|
41
|
+
deployments: {
|
|
42
|
+
list(projectId: string, token: string): Promise<{
|
|
43
|
+
deployments: Deployment[];
|
|
44
|
+
}>;
|
|
45
|
+
trigger(projectId: string, input: {
|
|
46
|
+
commitSha: string;
|
|
47
|
+
commitMessage: string;
|
|
48
|
+
}, token: string): Promise<Deployment>;
|
|
49
|
+
rollback(projectId: string, deploymentId: string, token: string): Promise<Deployment>;
|
|
50
|
+
logs(deploymentId: string, token: string): AsyncIterable<{
|
|
51
|
+
ts: string;
|
|
52
|
+
stream: "stdout" | "stderr" | "system";
|
|
53
|
+
line: string;
|
|
54
|
+
}>;
|
|
55
|
+
};
|
|
56
|
+
cli: {
|
|
57
|
+
upload(projectId: string, tarballPath: string, token: string): Promise<Deployment>;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export type DeployClient = ReturnType<typeof createDeployClient>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dirgha Deploy client. Talks to the gateway deploy routes (port 3001
|
|
3
|
+
* in development, api.dirgha.ai in production). Supports project CRUD,
|
|
4
|
+
* deployment trigger + rollback, a CLI tarball upload endpoint, and a
|
|
5
|
+
* Server-Sent-Events log stream.
|
|
6
|
+
*/
|
|
7
|
+
import { createReadStream } from 'node:fs';
|
|
8
|
+
import { stat } from 'node:fs/promises';
|
|
9
|
+
import { basename } from 'node:path';
|
|
10
|
+
import { jsonRequest, sseRequest, IntegrationError } from './http.js';
|
|
11
|
+
export function createDeployClient(opts = {}) {
|
|
12
|
+
const baseUrl = opts.baseUrl ?? process.env.DIRGHA_GATEWAY_URL ?? 'https://api.dirgha.ai';
|
|
13
|
+
const timeoutMs = opts.timeoutMs ?? 30_000;
|
|
14
|
+
const req = (options) => jsonRequest({ baseUrl, timeoutMs, ...options });
|
|
15
|
+
return {
|
|
16
|
+
projects: {
|
|
17
|
+
list(token) {
|
|
18
|
+
return req({ method: 'GET', path: '/api/deploy/projects', token });
|
|
19
|
+
},
|
|
20
|
+
create(project, token) {
|
|
21
|
+
return req({ method: 'POST', path: '/api/deploy/projects', body: project, token });
|
|
22
|
+
},
|
|
23
|
+
get(id, token) {
|
|
24
|
+
return req({ method: 'GET', path: `/api/deploy/projects/${encodeURIComponent(id)}`, token });
|
|
25
|
+
},
|
|
26
|
+
update(id, patch, token) {
|
|
27
|
+
return req({ method: 'PATCH', path: `/api/deploy/projects/${encodeURIComponent(id)}`, body: patch, token });
|
|
28
|
+
},
|
|
29
|
+
remove(id, token) {
|
|
30
|
+
return req({ method: 'DELETE', path: `/api/deploy/projects/${encodeURIComponent(id)}`, token });
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
deployments: {
|
|
34
|
+
list(projectId, token) {
|
|
35
|
+
return req({ method: 'GET', path: `/api/deploy/projects/${encodeURIComponent(projectId)}/deployments`, token });
|
|
36
|
+
},
|
|
37
|
+
trigger(projectId, input, token) {
|
|
38
|
+
return req({ method: 'POST', path: `/api/deploy/projects/${encodeURIComponent(projectId)}/deploy`, body: input, token });
|
|
39
|
+
},
|
|
40
|
+
rollback(projectId, deploymentId, token) {
|
|
41
|
+
return req({ method: 'POST', path: `/api/deploy/projects/${encodeURIComponent(projectId)}/rollback`, body: { deploymentId }, token });
|
|
42
|
+
},
|
|
43
|
+
async *logs(deploymentId, token) {
|
|
44
|
+
const stream = await sseRequest({
|
|
45
|
+
baseUrl,
|
|
46
|
+
path: `/api/deployments/${encodeURIComponent(deploymentId)}/logs`,
|
|
47
|
+
token,
|
|
48
|
+
});
|
|
49
|
+
for await (const payload of stream) {
|
|
50
|
+
try {
|
|
51
|
+
yield JSON.parse(payload);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
yield { ts: new Date().toISOString(), stream: 'system', line: payload };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
cli: {
|
|
60
|
+
async upload(projectId, tarballPath, token) {
|
|
61
|
+
const info = await stat(tarballPath).catch(() => undefined);
|
|
62
|
+
if (!info)
|
|
63
|
+
throw new IntegrationError(`Tarball not found: ${tarballPath}`);
|
|
64
|
+
const url = new URL(`${baseUrl.replace(/\/+$/, '')}/api/deploy/cli`);
|
|
65
|
+
url.searchParams.set('projectId', projectId);
|
|
66
|
+
const file = createReadStream(tarballPath);
|
|
67
|
+
const response = await fetch(url.toString(), {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
Authorization: `Bearer ${token}`,
|
|
71
|
+
'Content-Type': 'application/gzip',
|
|
72
|
+
'Content-Length': String(info.size),
|
|
73
|
+
'X-Tarball-Name': basename(tarballPath),
|
|
74
|
+
},
|
|
75
|
+
body: file,
|
|
76
|
+
duplex: 'half',
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
const body = await response.text().catch(() => '');
|
|
80
|
+
throw new IntegrationError(`Upload failed: HTTP ${response.status} ${body}`, response.status);
|
|
81
|
+
}
|
|
82
|
+
return await response.json();
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=deploy-client.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device-code OAuth flow for the Dirgha gateway.
|
|
3
|
+
*
|
|
4
|
+
* Canonical auth module. Stores tokens at `~/.dirgha/credentials.json`
|
|
5
|
+
* (0600) and drives the `/api/auth/device/*` endpoints. The older
|
|
6
|
+
* `integrations/auth.ts` is now a compatibility shim that delegates
|
|
7
|
+
* here so the billing + entitlements stack has exactly one source of
|
|
8
|
+
* truth for the active token.
|
|
9
|
+
*
|
|
10
|
+
* Callers:
|
|
11
|
+
* - Slash commands (`/login`, `/account`, `/upgrade`) via `loadToken()`.
|
|
12
|
+
* - CLI subcommands (`dirgha login`, `dirgha logout`).
|
|
13
|
+
* - Billing preflight (`preRequestCheck` reads the bearer).
|
|
14
|
+
*/
|
|
15
|
+
export interface DeviceAuthStart {
|
|
16
|
+
userCode: string;
|
|
17
|
+
verifyUri: string;
|
|
18
|
+
deviceCode: string;
|
|
19
|
+
interval: number;
|
|
20
|
+
expiresIn: number;
|
|
21
|
+
}
|
|
22
|
+
export interface DeviceAuthResult {
|
|
23
|
+
token: string;
|
|
24
|
+
userId: string;
|
|
25
|
+
email: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Token {
|
|
28
|
+
token: string;
|
|
29
|
+
userId: string;
|
|
30
|
+
email: string;
|
|
31
|
+
expiresAt: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function startDeviceAuth(apiBase?: string): Promise<DeviceAuthStart>;
|
|
34
|
+
export declare function pollDeviceAuth(deviceCode: string, apiBase?: string, opts?: {
|
|
35
|
+
intervalMs?: number;
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
}): Promise<DeviceAuthResult>;
|
|
38
|
+
export declare function saveToken(token: string, userId: string, email: string): Promise<void>;
|
|
39
|
+
export declare function loadToken(): Promise<Token | null>;
|
|
40
|
+
export declare function clearToken(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* One-shot migration from the legacy `~/.dirgha/auth.json` format
|
|
43
|
+
* (`integrations/auth.ts`) to the canonical `credentials.json`. Safe to
|
|
44
|
+
* call on every CLI start — returns `false` fast when nothing to do.
|
|
45
|
+
*
|
|
46
|
+
* Logs a single line to stderr on a successful move. Silent on no-op.
|
|
47
|
+
*/
|
|
48
|
+
export declare function migrateLegacyAuth(): Promise<boolean>;
|