my-durable 0.0.0-stage → 0.0.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/.env.example +7 -0
- package/LICENSE +21 -0
- package/README.md +328 -2
- package/ai_docs/durable_pi/announcement.md +860 -0
- package/ai_docs/durable_pi/changelog.md +51 -0
- package/ai_docs/durable_pi/chord-delta-findings.md +362 -0
- package/ai_docs/durable_pi/coding-agent-integration.md +70 -0
- package/ai_docs/durable_pi/pico-v5-chord-usage.md +391 -0
- package/ai_docs/durable_pi/pico-v5-handoff.md +921 -0
- package/ai_docs/durable_pi/readme.md +617 -0
- package/ai_docs/durable_pi/sources.md +22 -0
- package/ai_docs/durable_pi/spec.md +4696 -0
- package/ai_docs/durable_pi/vacation-planner.md +57 -0
- package/ai_docs/pi/chord.md +268 -0
- package/ai_docs/pi/cli-integration.md +110 -0
- package/ai_docs/pi/cli.md +325 -0
- package/ai_docs/pi/codemode.md +211 -0
- package/ai_docs/pi/compaction.md +467 -0
- package/ai_docs/pi/configuration.md +51 -0
- package/ai_docs/pi/containerization.md +187 -0
- package/ai_docs/pi/custom-provider.md +177 -0
- package/ai_docs/pi/environment-variables.md +102 -0
- package/ai_docs/pi/extensions.md +278 -0
- package/ai_docs/pi/how-pi-works.md +53 -0
- package/ai_docs/pi/index.md +43 -0
- package/ai_docs/pi/json.md +230 -0
- package/ai_docs/pi/keybindings.md +198 -0
- package/ai_docs/pi/llama-cpp.md +118 -0
- package/ai_docs/pi/mcp.md +274 -0
- package/ai_docs/pi/message-types.md +265 -0
- package/ai_docs/pi/models.md +209 -0
- package/ai_docs/pi/overview.md +166 -0
- package/ai_docs/pi/packages.md +133 -0
- package/ai_docs/pi/pi-agent-core.md +568 -0
- package/ai_docs/pi/pi-ai.md +1942 -0
- package/ai_docs/pi/prompt-templates.md +63 -0
- package/ai_docs/pi/providers.md +204 -0
- package/ai_docs/pi/quickstart.md +140 -0
- package/ai_docs/pi/readme.md +99 -0
- package/ai_docs/pi/rpc-commands.md +864 -0
- package/ai_docs/pi/rpc-extension-ui.md +204 -0
- package/ai_docs/pi/rpc.md +197 -0
- package/ai_docs/pi/sdk.md +151 -0
- package/ai_docs/pi/security.md +103 -0
- package/ai_docs/pi/session-format.md +297 -0
- package/ai_docs/pi/sessions.md +70 -0
- package/ai_docs/pi/settings.md +173 -0
- package/ai_docs/pi/shell-aliases.md +97 -0
- package/ai_docs/pi/skills.md +97 -0
- package/ai_docs/pi/slash-commands.md +64 -0
- package/ai_docs/pi/sources.md +57 -0
- package/ai_docs/pi/terminal-setup.md +223 -0
- package/ai_docs/pi/termux.md +121 -0
- package/ai_docs/pi/themes.md +140 -0
- package/ai_docs/pi/tmux.md +59 -0
- package/ai_docs/pi/toolkit.md +168 -0
- package/ai_docs/pi/tui.md +129 -0
- package/ai_docs/pi/usage.md +98 -0
- package/ai_docs/pi/virtual-models.md +118 -0
- package/ai_docs/pi/windows.md +71 -0
- package/apps/dpi-backend/.nvmrc +1 -0
- package/apps/dpi-backend/API.md +99 -0
- package/apps/dpi-backend/README.md +119 -0
- package/apps/dpi-backend/deploy/backend.env.example +9 -0
- package/apps/dpi-backend/deploy/dpi-backend.plist +26 -0
- package/apps/dpi-backend/deploy/dpi-backend.service +22 -0
- package/apps/dpi-backend/package.json +33 -0
- package/apps/dpi-backend/prompts/one_sentence.md +3 -0
- package/apps/dpi-backend/prompts/smart_ass_opus_fix.md +169 -0
- package/apps/dpi-backend/scripts/check-contract.mjs +151 -0
- package/apps/dpi-backend/scripts/migrate-playground.ts +66 -0
- package/apps/dpi-backend/scripts/record-nested-fixture.mts +154 -0
- package/apps/dpi-backend/scripts/token.ts +57 -0
- package/apps/dpi-backend/src/addons.ts +139 -0
- package/apps/dpi-backend/src/auth.ts +20 -0
- package/apps/dpi-backend/src/config.ts +54 -0
- package/apps/dpi-backend/src/contract-check.ts +118 -0
- package/apps/dpi-backend/src/errors.ts +50 -0
- package/apps/dpi-backend/src/extensions.ts +510 -0
- package/apps/dpi-backend/src/faux.ts +80 -0
- package/apps/dpi-backend/src/history.ts +165 -0
- package/apps/dpi-backend/src/idempotency.ts +20 -0
- package/apps/dpi-backend/src/jev.ts +43 -0
- package/apps/dpi-backend/src/jobs.ts +790 -0
- package/apps/dpi-backend/src/main.ts +76 -0
- package/apps/dpi-backend/src/model-catalog.ts +180 -0
- package/apps/dpi-backend/src/pairing-files.ts +142 -0
- package/apps/dpi-backend/src/pairing.ts +459 -0
- package/apps/dpi-backend/src/routes.ts +217 -0
- package/apps/dpi-backend/src/shared-state.ts +85 -0
- package/apps/dpi-backend/src/store.ts +1240 -0
- package/apps/dpi-backend/src/streams.ts +256 -0
- package/apps/dpi-backend/src/tunnel.ts +955 -0
- package/apps/dpi-backend/tsconfig.json +13 -0
- package/apps/dpi-playground/README.md +83 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-CFGc7lHT.js +77 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DFdKpwm_.css +1 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/anthropic.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/deepseek.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/durable-pi.svg +14 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/gemini.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/grok.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/kimi.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/lab.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/meta.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/minimax.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/openai.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/qwen.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/xiaomi.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/icons/zai.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +16 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/index.html +15 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/package.json +5 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/anthropic.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/deepseek.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/durable-pi.svg +14 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/gemini.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/grok.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/kimi.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/lab.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/meta.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/minimax.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/openai.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/qwen.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/xiaomi.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/public/icons/zai.png +0 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/App.vue +180 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/commands.ts +119 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/composables.ts +129 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/hub.ts +40 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/icon-path.ts +7 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/ids.ts +2 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/jobs.ts +80 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/link-policy.ts +16 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/markdown-policy.ts +115 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/markdown.ts +60 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/pair-close.ts +23 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/pair-handoff.ts +56 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/pair.ts +166 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/qrcode.ts +323 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/signature.ts +146 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +373 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/stream.ts +183 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/AgentView.vue +342 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Composer.vue +198 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ContextBar.vue +254 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/DeviceCredentialsDialog.vue +40 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/DeviceIcon.vue +56 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/DirBrowser.vue +95 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ExtensionsPanel.vue +96 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/HelpDialog.vue +69 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +425 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/JobCard.vue +221 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/MobileNav.vue +39 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ModelPicker.vue +71 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NetworkSidebar.vue +236 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NewSessionDialog.vue +114 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/OfflinePanel.vue +128 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/PairDeviceWizard.vue +433 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/PromptDialog.vue +89 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/StateEditor.vue +179 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TasksPanel.vue +280 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Toast.vue +11 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TokenManager.vue +175 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TopBar.vue +114 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TranscriptItem.vue +152 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TreeRow.vue +195 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TunnelStatusBar.vue +107 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/extensions.css +105 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/jobs.css +655 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/main.ts +22 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/network.css +675 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/style.css +3203 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/tsconfig.json +16 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/vite.config.ts +14 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/package.json +5 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/audit.ts +406 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/client-ip.ts +72 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/credentials.ts +265 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/guard.ts +43 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/http-errors.ts +156 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/identity.ts +60 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/limiter.ts +165 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +460 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/monitor.ts +320 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/mux.ts +277 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/pairing.ts +816 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/proxy.ts +128 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/rotation.ts +583 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/seed.ts +11 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/transport.ts +108 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/tunnel-token.ts +11 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/tunnel-transport.ts +560 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/tunnel.ts +873 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/tsconfig.json +13 -0
- package/apps/dpi-playground/package.json +37 -0
- package/apps/dpi-sdk/README.md +74 -0
- package/apps/dpi-sdk/package.json +20 -0
- package/apps/dpi-sdk/scripts/net.ts +73 -0
- package/apps/dpi-sdk/src/api.ts +631 -0
- package/apps/dpi-sdk/src/app-state.ts +111 -0
- package/apps/dpi-sdk/src/client.ts +330 -0
- package/apps/dpi-sdk/src/errors.ts +16 -0
- package/apps/dpi-sdk/src/jobs.ts +99 -0
- package/apps/dpi-sdk/src/models.ts +472 -0
- package/apps/dpi-sdk/src/node/chunk.ts +488 -0
- package/apps/dpi-sdk/src/node/config.ts +175 -0
- package/apps/dpi-sdk/src/node/drivers.ts +402 -0
- package/apps/dpi-sdk/src/node/ops.ts +114 -0
- package/apps/dpi-sdk/src/node/private-dir.ts +48 -0
- package/apps/dpi-sdk/src/node/registry-migration.ts +549 -0
- package/apps/dpi-sdk/src/node/registry.ts +390 -0
- package/apps/dpi-sdk/src/node/sse-writer.ts +151 -0
- package/apps/dpi-sdk/src/protocol/backoff.ts +31 -0
- package/apps/dpi-sdk/src/protocol/limits.ts +199 -0
- package/apps/dpi-sdk/src/protocol/pairing.ts +311 -0
- package/apps/dpi-sdk/src/protocol/rest-routes.ts +105 -0
- package/apps/dpi-sdk/src/protocol/tunnel.ts +331 -0
- package/apps/dpi-sdk/src/sse.ts +117 -0
- package/apps/dpi-sdk/src/transcript.ts +291 -0
- package/apps/dpi-sdk/tsconfig.json +13 -0
- package/apps/dpi-sdk/w +20 -0
- package/apps/dpi-tui/README.md +54 -0
- package/apps/dpi-tui/bin/dpi-tui.mjs +5 -0
- package/apps/dpi-tui/package.json +20 -0
- package/apps/dpi-tui/src/app.ts +433 -0
- package/apps/dpi-tui/src/commands.ts +151 -0
- package/apps/dpi-tui/src/main.ts +122 -0
- package/apps/dpi-tui/src/pairing.ts +287 -0
- package/apps/dpi-tui/src/pickers.ts +238 -0
- package/apps/dpi-tui/src/render.ts +164 -0
- package/apps/dpi-tui/src/theme.ts +57 -0
- package/apps/dpi-tui/tsconfig.json +14 -0
- package/bin/device.mjs +5 -0
- package/bin/hub.mjs +5 -0
- package/bin/tui.mjs +5 -0
- package/deploy/Caddyfile +120 -0
- package/docs/verification.md +102 -0
- package/dpi-network.example.yaml +62 -0
- package/images/01_durable_agent_network.svg +185 -0
- package/images/02_pi_made_durable.svg +204 -0
- package/images/03_restart_mid_tool.svg +168 -0
- package/images/07_one_api_every_client.svg +123 -0
- package/images/08_device_session_agent.svg +123 -0
- package/images/09_compact_keep_history.svg +143 -0
- package/images/10_shared_app_state.svg +177 -0
- package/images/11_durable_jobs_wait.svg +141 -0
- package/images/12_tools_change_mid_run.svg +231 -0
- package/images/13_hook_blocks_tool.svg +122 -0
- package/images/14_fork_at_any_entry.svg +119 -0
- package/images/15_web_client.png +0 -0
- package/images/16_terminal_client.svg +43 -0
- package/images/17_devices_are_data.svg +182 -0
- package/images/18_should_every_agent_be_durable.svg +118 -0
- package/images/19_sqlite_on_every_device.svg +155 -0
- package/images/20_admission_and_effects.svg +134 -0
- package/justfile +33 -0
- package/package.json +41 -4
- package/scripts/verify.mjs +210 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"types": ["node"],
|
|
10
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"]
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*.ts"]
|
|
13
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dpi-playground",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"workspaces": [
|
|
6
|
+
"apps/*"
|
|
7
|
+
],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "tsx apps/dpi-playground-hub/src/main.ts --dev",
|
|
10
|
+
"start": "tsx apps/dpi-playground-hub/src/main.ts",
|
|
11
|
+
"build": "vue-tsc --noEmit -p apps/dpi-playground-fe/tsconfig.json && tsc --noEmit -p apps/dpi-playground-hub/tsconfig.json && vite build --config apps/dpi-playground-fe/vite.config.ts",
|
|
12
|
+
"lint": "oxlint apps tests",
|
|
13
|
+
"fmt": "oxfmt apps tests",
|
|
14
|
+
"test": "tsx --test tests/*.test.ts"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"dompurify": "^3.2.0",
|
|
18
|
+
"express": "^5.1.0",
|
|
19
|
+
"lucide-vue-next": "^0.468.0",
|
|
20
|
+
"marked": "^17.0.0",
|
|
21
|
+
"vue": "3.5.43",
|
|
22
|
+
"ws": "8.22.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@playwright/test": "latest",
|
|
26
|
+
"@types/express": "^5.0.0",
|
|
27
|
+
"@types/node": "^24.0.0",
|
|
28
|
+
"@types/ws": "8.18.2",
|
|
29
|
+
"@vitejs/plugin-vue": "latest",
|
|
30
|
+
"oxfmt": "0.72.0",
|
|
31
|
+
"oxlint": "1.87.0",
|
|
32
|
+
"tsx": "latest",
|
|
33
|
+
"typescript": "5.9.3",
|
|
34
|
+
"vite": "8.3.2",
|
|
35
|
+
"vue-tsc": "latest"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# dpi-sdk
|
|
2
|
+
|
|
3
|
+
The shared contract of the Durable Agent Network. Every client in this repo (the hub, the web client, `dpi-tui`, the test suites and `just net`) builds on it, and so can yours. It has no runtime dependencies in `src/`, and everything outside `src/node/` also runs in browsers. `src/node/` uses `yaml`, `node:sqlite` and child processes, so it needs Node 22.19 or newer (the repo pins 24).
|
|
4
|
+
|
|
5
|
+
The apps import it by relative path (`../../dpi-sdk/src/client.ts`, or `@sdk/*` in the Vite client). It is not published to npm.
|
|
6
|
+
|
|
7
|
+
## Layout
|
|
8
|
+
|
|
9
|
+
| File | Exports |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `src/api.ts` | The v1 wire contract: `DeviceInfo`, `DeviceTree`, `SessionSummary`, `AgentSummary`, `AgentDetail`, `SendResult`, `TaskNode`, `WireEntry`, the stream `Frame` and the hub's `MuxFrame`, `API_VERSION`, `THINKING_LEVELS` and the compaction defaults and helpers |
|
|
12
|
+
| `src/client.ts` | `DpiClient` (device, tree, dirs, sessions, createSession, device docs and events, plus raw `request` and `stream`), `SessionHandle` (get, rename, archive, agents, createAgent, tasks, abortTask, inspect, compaction, setCompaction, submission, events), `AgentHandle` (get, rename, `send` with a `whenBusy` of follow-up, steer or reject, withdraw, abort, fork, config, configure, compact, reset, entries, transcript, doc, extensions, setExtension, demo for App State edits and job runs, events) and `follow()`, which keeps a stream open with backoff |
|
|
13
|
+
| `src/sse.ts` | `readSse()`, a fetch-based SSE reader that works in browsers and Node |
|
|
14
|
+
| `src/models.ts` | Reducers that turn frames into view state: `AgentModel` (transcript items, live tools, inbox, usage), `SessionModel` (agents, tasks, lineage) and `NetworkModel` with `networkTree()` |
|
|
15
|
+
| `src/transcript.ts` | `toTranscript()` (the items both clients render), `toMarkdown()`, `sumUsage()` and message text helpers |
|
|
16
|
+
| `src/app-state.ts` | App State paths and changes: `readState()`, `changeState()`, `replaceState()` |
|
|
17
|
+
| `src/jobs.ts` | Durable job definitions and run records (`JobDef`, `JobRun`, the `demo.job-runs` document) |
|
|
18
|
+
| `src/errors.ts` | `DpiError` with the API error code, and `isDpiError()` |
|
|
19
|
+
| `src/node/registry.ts` | `NetworkRegistry`: the client-side device registry in `~/.dpi/network.sqlite` (URLs, tokens, live status, UI state), and `toPublic()`, the token-free view the hub serves |
|
|
20
|
+
| `src/node/config.ts` | Parses `dpi-network.yaml` (found by walking up from the working directory, or `DPI_NETWORK_FILE`) and syncs it into the registry |
|
|
21
|
+
| `src/node/drivers.ts`, `ops.ts` | One driver per device kind (`local`, `ssh`, `exe-dev`, `url`) with the steps behind `just net` |
|
|
22
|
+
| `scripts/net.ts` | The ops CLI behind every `just net` recipe. From this folder: `npx tsx scripts/net.ts <verb> [device]` or `npm run net -- <verb> [device]`. `help` lists the verbs |
|
|
23
|
+
|
|
24
|
+
## The registry file
|
|
25
|
+
|
|
26
|
+
`~/.dpi/network.sqlite` is schema **v1**. A v0 file is migrated automatically on first open, and the migration is deliberately strict:
|
|
27
|
+
|
|
28
|
+
- **Stop every writer first** (hub, TUI, `just net`): a v0 file is migrated only while the process holds the file's exclusive lock, which exists only when no other connection has it open. Otherwise the open aborts — it never migrates a live file.
|
|
29
|
+
- Before touching anything it writes a verified backup to `network.sqlite.pre-v1.bak` (0600, `VACUUM INTO` + fsync, re-opened and row-checked). Keep that file until you have verified the v1 registry.
|
|
30
|
+
- The rebuild runs in one transaction and `user_version=1` is set inside it; any failure rolls back to an intact v0 file. Re-running on a valid v1 is a no-op; an unknown or partial schema aborts instead of guessing.
|
|
31
|
+
- The v0 preflight is fail-closed the same way: a v0 file that already carries stray v1-only objects, or unknown extra columns in its tables (`devices`, `ui_state`), is refused before the backup is written, with the offending object / table and column named in the error.
|
|
32
|
+
|
|
33
|
+
`~/.dpi` itself is enforced 0700 on every start (created that way, or tightened; a directory owned by another account is refused), and the database file is kept 0600.
|
|
34
|
+
|
|
35
|
+
## Use it
|
|
36
|
+
|
|
37
|
+
Send work and wait for the answer in one request:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { DpiClient } from "./src/client.ts";
|
|
41
|
+
|
|
42
|
+
const client = new DpiClient("http://127.0.0.1:4780", process.env.DPI_TOKEN);
|
|
43
|
+
const agent = client.agent("my-session", "main");
|
|
44
|
+
const result = await agent.send("Summarize the failing tests", "followUp", "ci-4812", 120_000);
|
|
45
|
+
if (result.status === "done") console.log(result.answer.text);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The `requestId` (`ci-4812`) makes the send idempotent: retry with the same id and the device admits it once.
|
|
49
|
+
|
|
50
|
+
Render a live transcript. The stream sends `hello`, a snapshot, then deltas, and a reconnect starts from a fresh snapshot:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { follow } from "./src/client.ts";
|
|
54
|
+
import { AgentModel } from "./src/models.ts";
|
|
55
|
+
|
|
56
|
+
const model = new AgentModel();
|
|
57
|
+
model.subscribe(() => render(model.state.items));
|
|
58
|
+
const stop = new AbortController();
|
|
59
|
+
const following = follow(
|
|
60
|
+
(signal) => agent.events(signal),
|
|
61
|
+
(frame) => model.apply(frame),
|
|
62
|
+
(state) => console.log("stream", state), // connecting | live | offline | unauthorized | gone
|
|
63
|
+
stop.signal,
|
|
64
|
+
);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`follow()` reconnects with backoff, and each reconnect starts from a fresh snapshot. Its promise resolves only after `stop.abort()`, or when the device answers `unauthorized` or `not_found`, so don't await it on your main path. Closing the stream never stops the agent.
|
|
68
|
+
|
|
69
|
+
## Test
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm run check # strict types
|
|
73
|
+
npm test # SSE parsing, reducers against a recorded stream, compaction, App State, YAML config, registry
|
|
74
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dpi-sdk",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Durable Agent Network contract, client, models and device registry. Browser-safe core; src/node needs yaml; src/protocol needs @sinclair/typebox (browser-safe, no Node builtins).",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"check": "tsc --noEmit -p .",
|
|
8
|
+
"test": "tsx --test tests/*.test.ts",
|
|
9
|
+
"net": "tsx scripts/net.ts"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@sinclair/typebox": "0.34.52",
|
|
13
|
+
"yaml": "^2.8.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^24.0.0",
|
|
17
|
+
"tsx": "^4.20.0",
|
|
18
|
+
"typescript": "5.9.3"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Network ops CLI behind every `just` recipe. Reads dpi-network.yaml, dispatches to the driver
|
|
2
|
+
// for the device's kind. Usage: net <verb> [device] [args...]
|
|
3
|
+
import { DpiClient } from "../src/client.js";
|
|
4
|
+
import { DpiError } from "../src/errors.js";
|
|
5
|
+
import { loadNetworkConfig, syncConfigToRegistry, type NetDevice } from "../src/node/config.js";
|
|
6
|
+
import { drivers, type DriverContext, type Verb } from "../src/node/drivers.js";
|
|
7
|
+
import { NetworkRegistry } from "../src/node/registry.js";
|
|
8
|
+
|
|
9
|
+
const [verb = "help", id, ...args] = process.argv.slice(2);
|
|
10
|
+
const log = (line: string) => console.log(line);
|
|
11
|
+
const fail = (message: string): never => {
|
|
12
|
+
console.error(`net: ${message}`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const HELP = `net <verb> [device] [args]
|
|
17
|
+
ls | status [device] devices from dpi-network.yaml (+ dpi-tui --save), probed live
|
|
18
|
+
ids device ids from dpi-network.yaml, one per line
|
|
19
|
+
up <device> every step the device's kind supports (idempotent)
|
|
20
|
+
create | provision | deploy | env | service | expose | register <device>
|
|
21
|
+
restart | down | logs <device> [lines]
|
|
22
|
+
rotate <device> new token on the device, restart, re-register
|
|
23
|
+
destroy <device> [--yes] exe-dev only; only VMs named in dpi-network.yaml
|
|
24
|
+
probe-unauth <device> /healthz must be 200 and /v1/device without a token 401`;
|
|
25
|
+
|
|
26
|
+
async function probe(url: string, token: string | null) {
|
|
27
|
+
if (!token) return { status: "unauthorized", detail: "no token (just net register <id>)" };
|
|
28
|
+
try {
|
|
29
|
+
const info = await new DpiClient(url, token).device({ timeoutMs: 5000 });
|
|
30
|
+
const tree = await new DpiClient(url, token).tree();
|
|
31
|
+
return { status: "online", detail: `${info.name} uid ${info.uid.slice(0, 8)} api v${info.apiVersion} ${tree.sessions.length} sessions` };
|
|
32
|
+
} catch (e) {
|
|
33
|
+
const err = e as DpiError;
|
|
34
|
+
return { status: err.code === "unauthorized" ? "unauthorized" : "offline", detail: err.message };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function main() {
|
|
39
|
+
if (verb === "help" || verb === "--help") return console.log(HELP);
|
|
40
|
+
const config = loadNetworkConfig();
|
|
41
|
+
if (verb === "ids") return console.log(Object.keys(config.devices).join("\n"));
|
|
42
|
+
const registry = new NetworkRegistry();
|
|
43
|
+
syncConfigToRegistry(config, registry);
|
|
44
|
+
if (verb === "ls" || verb === "status") {
|
|
45
|
+
const rows = registry.list().filter((d) => !id || d.id === id);
|
|
46
|
+
const lanRows = rows.filter((d) => d.transport === "lan" && d.url);
|
|
47
|
+
const results = await Promise.all(lanRows.map((d) => probe(d.url!, d.token)));
|
|
48
|
+
const width = Math.max(4, ...rows.map((d) => d.id.length));
|
|
49
|
+
for (const [i, d] of lanRows.entries()) {
|
|
50
|
+
const r = results[i];
|
|
51
|
+
registry.recordStatus(d.id, { status: r.status as "online", error: r.status === "online" ? null : r.detail, ...(r.status === "online" ? { seenAt: Date.now() } : {}) });
|
|
52
|
+
console.log(`${d.id.padEnd(width)} ${d.kind.padEnd(7)} ${r.status.padEnd(12)} ${d.url} ${r.detail}`);
|
|
53
|
+
}
|
|
54
|
+
if (results.some((r) => r.status !== "online")) process.exitCode = 2;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (!id) fail(`${verb} needs a device id. Devices: ${Object.keys(config.devices).join(", ")}`);
|
|
58
|
+
const device: NetDevice = config.devices[id] ?? fail(`No device "${id}" in ${config.file}. Devices: ${Object.keys(config.devices).join(", ")}`);
|
|
59
|
+
if (verb === "probe-unauth") {
|
|
60
|
+
const health = await fetch(`${device.url}/healthz`).then((r) => r.status).catch(() => 0);
|
|
61
|
+
const anon = await fetch(`${device.url}/v1/device`).then((r) => r.status).catch(() => 0);
|
|
62
|
+
console.log(`${id}: /healthz ${health}, /v1/device without token ${anon}`);
|
|
63
|
+
if (health !== 200 || anon !== 401) process.exitCode = 1;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const driver = drivers[device.kind];
|
|
67
|
+
const step = driver[verb as Verb];
|
|
68
|
+
if (!step) fail(`"${verb}" is not supported for kind ${device.kind}. Supported: ${Object.keys(driver).join(", ")}`);
|
|
69
|
+
const ctx: DriverContext = { config, registry, args, log };
|
|
70
|
+
await step!(device, ctx);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main().catch((e) => fail(e instanceof Error ? e.message : String(e)));
|