@north-light/cli 0.3.530 → 0.3.531
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/dist/clients/attach/session/connection.js +1 -1
- package/dist/clients/attach/session/reconnect.js +1 -1
- package/dist/clients/attach/viewer.js +3 -3
- package/dist/core/async-array.d.ts +7 -0
- package/dist/core/async-array.js +1 -0
- package/dist/core/audit.d.ts +1 -1
- package/dist/core/audit.js +2 -2
- package/dist/core/canvas/attention.d.ts +4 -4
- package/dist/core/canvas/attention.js +1 -1
- package/dist/core/canvas/boot.d.ts +4 -4
- package/dist/core/canvas/boot.js +1 -1
- package/dist/core/canvas/canvas.d.ts +59 -59
- package/dist/core/canvas/canvas.js +19 -19
- package/dist/core/canvas/context-strip.js +2 -2
- package/dist/core/canvas/crons.d.ts +27 -27
- package/dist/core/canvas/crons.js +11 -11
- package/dist/core/canvas/daemon-actions.d.ts +10 -10
- package/dist/core/canvas/daemon-actions.js +8 -8
- package/dist/core/canvas/daemon-owner.d.ts +3 -3
- package/dist/core/canvas/daemon-owner.js +2 -2
- package/dist/core/canvas/db.d.ts +19 -30
- package/dist/core/canvas/db.js +3 -2
- package/dist/core/canvas/deliveries.d.ts +16 -16
- package/dist/core/canvas/deliveries.js +24 -24
- package/dist/core/canvas/executions.d.ts +8 -8
- package/dist/core/canvas/executions.js +1 -1
- package/dist/core/canvas/focuses.d.ts +8 -8
- package/dist/core/canvas/focuses.js +1 -1
- package/dist/core/canvas/history.d.ts +3 -3
- package/dist/core/canvas/history.js +9 -9
- package/dist/core/canvas/install-id.d.ts +1 -1
- package/dist/core/canvas/install-id.js +1 -1
- package/dist/core/canvas/managed-worktree-sweep-candidates.d.ts +1 -1
- package/dist/core/canvas/managed-worktree-sweep-candidates.js +2 -2
- package/dist/core/canvas/memory-reads.d.ts +6 -6
- package/dist/core/canvas/memory-reads.js +1 -1
- package/dist/core/canvas/nav-model.d.ts +13 -13
- package/dist/core/canvas/nav-model.js +1 -1
- package/dist/core/canvas/node-agent-paths.d.ts +6 -6
- package/dist/core/canvas/node-agent-paths.js +1 -1
- package/dist/core/canvas/node-tokens.d.ts +7 -7
- package/dist/core/canvas/node-tokens.js +3 -3
- package/dist/core/canvas/outcome-actions.d.ts +5 -5
- package/dist/core/canvas/outcome-actions.js +3 -3
- package/dist/core/canvas/recovery.d.ts +26 -26
- package/dist/core/canvas/recovery.js +2 -2
- package/dist/core/canvas/render-source.d.ts +1 -1
- package/dist/core/canvas/render-source.js +1 -1
- package/dist/core/canvas/sessions.d.ts +10 -10
- package/dist/core/canvas/sessions.js +4 -4
- package/dist/core/canvas/source.js +1 -1
- package/dist/core/canvas/structured-requests.d.ts +15 -15
- package/dist/core/canvas/structured-requests.js +5 -5
- package/dist/core/canvas/tree.d.ts +9 -9
- package/dist/core/canvas/tree.js +5 -5
- package/dist/core/canvas/waits.d.ts +13 -13
- package/dist/core/canvas/waits.js +6 -6
- package/dist/core/canvas/worktrees.d.ts +15 -15
- package/dist/core/canvas/worktrees.js +1 -1
- package/dist/core/command-hooks/transport/exec-lifecycle.js +1 -1
- package/dist/core/conversation-store/file-store.d.ts +7 -7
- package/dist/core/conversation-store/file-store.js +9 -9
- package/dist/core/conversation-store/index.d.ts +16 -14
- package/dist/core/conversation-store/index.js +1 -1
- package/dist/core/conversation-store/listener.js +5 -5
- package/dist/core/conversation-store/patch.d.ts +3 -1
- package/dist/core/conversation-store/patch.js +1 -1
- package/dist/core/feed/feed.js +3 -3
- package/dist/core/feed/inbox.d.ts +2 -2
- package/dist/core/feed/inbox.js +1 -1
- package/dist/core/feed/messages.d.ts +11 -12
- package/dist/core/feed/messages.js +5 -5
- package/dist/core/feed/reports.d.ts +4 -4
- package/dist/core/feed/reports.js +2 -2
- package/dist/core/grants/cover.d.ts +1 -1
- package/dist/core/grants/cover.js +1 -1
- package/dist/core/grants/local.d.ts +1 -1
- package/dist/core/grants/local.js +1 -1
- package/dist/core/grants/mirror.d.ts +19 -19
- package/dist/core/grants/mirror.js +2 -2
- package/dist/core/grants/on-sync.d.ts +1 -1
- package/dist/core/grants/on-sync.js +1 -1
- package/dist/core/grants/remove.js +1 -1
- package/dist/core/grants/sync.js +1 -1
- package/dist/core/graph/access.d.ts +17 -17
- package/dist/core/graph/access.js +3 -3
- package/dist/core/graph/custom.d.ts +16 -16
- package/dist/core/graph/custom.js +9 -9
- package/dist/core/graph/deletion.d.ts +3 -7
- package/dist/core/graph/deletion.js +4 -4
- package/dist/core/graph/documents.d.ts +24 -27
- package/dist/core/graph/documents.js +7 -7
- package/dist/core/graph/edges.d.ts +13 -13
- package/dist/core/graph/edges.js +1 -1
- package/dist/core/graph/events.d.ts +7 -9
- package/dist/core/graph/events.js +8 -8
- package/dist/core/graph/exposures.d.ts +6 -6
- package/dist/core/graph/exposures.js +4 -4
- package/dist/core/graph/jobs.d.ts +6 -8
- package/dist/core/graph/jobs.js +2 -2
- package/dist/core/graph/kinds/action.js +1 -1
- package/dist/core/graph/kinds/custom.js +2 -2
- package/dist/core/graph/kinds/document.d.ts +1 -0
- package/dist/core/graph/kinds/document.js +4 -4
- package/dist/core/graph/kinds/dto.d.ts +2 -2
- package/dist/core/graph/kinds/dto.js +1 -1
- package/dist/core/graph/kinds/job.js +2 -2
- package/dist/core/graph/kinds/kind.d.ts +6 -8
- package/dist/core/graph/kinds/kind.js +1 -1
- package/dist/core/graph/kinds/node.js +5 -5
- package/dist/core/graph/kinds/owner.js +2 -2
- package/dist/core/graph/kinds/registry.d.ts +6 -9
- package/dist/core/graph/kinds/registry.js +1 -1
- package/dist/core/graph/names.d.ts +6 -6
- package/dist/core/graph/names.js +3 -3
- package/dist/core/graph/object-waits.d.ts +4 -7
- package/dist/core/graph/object-waits.js +1 -1
- package/dist/core/graph/objects.d.ts +14 -14
- package/dist/core/graph/objects.js +9 -9
- package/dist/core/graph/package-docs.d.ts +2 -7
- package/dist/core/graph/package-docs.js +5 -5
- package/dist/core/graph/package-kinds.d.ts +2 -5
- package/dist/core/graph/package-kinds.js +1 -1
- package/dist/core/graph/package-reconcile.d.ts +2 -5
- package/dist/core/graph/package-reconcile.js +1 -1
- package/dist/core/graph/reader.d.ts +18 -18
- package/dist/core/graph/reader.js +3 -3
- package/dist/core/graph/receivers.d.ts +4 -4
- package/dist/core/graph/receivers.js +5 -5
- package/dist/core/graph/repo-sync/exchange.d.ts +3 -7
- package/dist/core/graph/repo-sync/exchange.js +2 -2
- package/dist/core/graph/repo-sync/repos.d.ts +7 -5
- package/dist/core/graph/repo-sync/repos.js +3 -3
- package/dist/core/graph/repo-sync/sync.d.ts +3 -6
- package/dist/core/graph/repo-sync/sync.js +2 -2
- package/dist/core/graph/rules.d.ts +5 -5
- package/dist/core/graph/rules.js +3 -3
- package/dist/core/graph/spaces/app.js +1 -1
- package/dist/core/graph/spaces/index.d.ts +4 -5
- package/dist/core/graph/spaces/index.js +1 -1
- package/dist/core/graph/spaces/own-memory.d.ts +4 -4
- package/dist/core/graph/spaces/own-memory.js +1 -1
- package/dist/core/graph/spaces/person.js +3 -3
- package/dist/core/graph/spaces/repo.d.ts +1 -1
- package/dist/core/graph/spaces/repo.js +1 -1
- package/dist/core/graph/watches.d.ts +15 -15
- package/dist/core/graph/watches.js +10 -10
- package/dist/core/human/feedback-companion.d.ts +2 -2
- package/dist/core/human/feedback-companion.js +1 -1
- package/dist/core/human/feedback.d.ts +3 -3
- package/dist/core/human/feedback.js +1 -1
- package/dist/core/human/requests.d.ts +34 -33
- package/dist/core/human/requests.js +20 -20
- package/dist/core/human/scan.d.ts +2 -2
- package/dist/core/human/scan.js +1 -1
- package/dist/core/human/tickets.d.ts +9 -9
- package/dist/core/human/tickets.js +1 -1
- package/dist/core/llm/app-rungs.d.ts +1 -1
- package/dist/core/llm/app-rungs.js +1 -1
- package/dist/core/llm/run.js +1 -1
- package/dist/core/peer/directory.d.ts +1 -1
- package/dist/core/peer/directory.js +1 -1
- package/dist/core/peer/envelope.d.ts +3 -3
- package/dist/core/peer/envelope.js +1 -1
- package/dist/core/peer/home.d.ts +7 -7
- package/dist/core/peer/home.js +2 -2
- package/dist/core/peer/ingest.d.ts +6 -6
- package/dist/core/peer/ingest.js +1 -1
- package/dist/core/peer/outbox-store.d.ts +14 -14
- package/dist/core/peer/outbox-store.js +5 -5
- package/dist/core/peer/receiver.d.ts +2 -2
- package/dist/core/peer/receiver.js +1 -1
- package/dist/core/peer/stubs.d.ts +10 -10
- package/dist/core/peer/stubs.js +1 -1
- package/dist/core/providers/approval.d.ts +2 -2
- package/dist/core/providers/approval.js +2 -2
- package/dist/core/providers/audit.d.ts +3 -3
- package/dist/core/providers/audit.js +2 -2
- package/dist/core/providers/bundles.js +2 -2
- package/dist/core/providers/call.d.ts +2 -2
- package/dist/core/providers/call.js +1 -1
- package/dist/core/providers/files.d.ts +1 -1
- package/dist/core/providers/files.js +1 -1
- package/dist/core/providers/mint.js +1 -1
- package/dist/core/providers/receipts.d.ts +1 -1
- package/dist/core/providers/receipts.js +2 -2
- package/dist/core/review/birth.js +1 -1
- package/dist/core/review/comments.d.ts +19 -19
- package/dist/core/review/comments.js +5 -5
- package/dist/core/review/companion.d.ts +1 -1
- package/dist/core/review/companion.js +1 -1
- package/dist/core/review/document.d.ts +3 -3
- package/dist/core/review/document.js +2 -2
- package/dist/core/review/fork.js +2 -2
- package/dist/core/review/realize.js +1 -1
- package/dist/core/review/remap.d.ts +2 -2
- package/dist/core/review/remap.js +4 -4
- package/dist/core/review/stage.d.ts +1 -1
- package/dist/core/review/stage.js +1 -1
- package/dist/core/review/store.d.ts +21 -21
- package/dist/core/review/store.js +1 -1
- package/dist/core/runs/activity.d.ts +1 -1
- package/dist/core/runs/activity.js +5 -5
- package/dist/core/runs/confinement.d.ts +7 -7
- package/dist/core/runs/confinement.js +2 -2
- package/dist/core/runs/events.d.ts +12 -12
- package/dist/core/runs/events.js +4 -4
- package/dist/core/runs/operations.d.ts +11 -11
- package/dist/core/runs/operations.js +5 -5
- package/dist/core/runs/questions.d.ts +10 -10
- package/dist/core/runs/questions.js +3 -3
- package/dist/core/runtime/auth-reload.js +1 -1
- package/dist/core/runtime/bearings.d.ts +5 -5
- package/dist/core/runtime/bearings.js +6 -6
- package/dist/core/runtime/broker-inventory.js +1 -1
- package/dist/core/runtime/broker-request.js +1 -1
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/close.d.ts +3 -3
- package/dist/core/runtime/close.js +1 -1
- package/dist/core/runtime/deliver-live.js +1 -1
- package/dist/core/runtime/fleet.d.ts +2 -2
- package/dist/core/runtime/host.d.ts +3 -3
- package/dist/core/runtime/host.js +3 -3
- package/dist/core/runtime/kickoff.d.ts +12 -12
- package/dist/core/runtime/kickoff.js +17 -17
- package/dist/core/runtime/launch-target.d.ts +1 -1
- package/dist/core/runtime/launch-target.js +1 -1
- package/dist/core/runtime/ledger.d.ts +3 -3
- package/dist/core/runtime/ledger.js +3 -3
- package/dist/core/runtime/lifecycle.d.ts +1 -1
- package/dist/core/runtime/lifecycle.js +2 -2
- package/dist/core/runtime/memory-admission.js +1 -1
- package/dist/core/runtime/model-swap.d.ts +2 -2
- package/dist/core/runtime/model-swap.js +1 -1
- package/dist/core/runtime/node-read.d.ts +1 -1
- package/dist/core/runtime/node-read.js +2 -2
- package/dist/core/runtime/nodes.d.ts +6 -6
- package/dist/core/runtime/nodes.js +1 -1
- package/dist/core/runtime/outcome-document.d.ts +1 -1
- package/dist/core/runtime/outcome-document.js +1 -1
- package/dist/core/runtime/persona.d.ts +3 -3
- package/dist/core/runtime/persona.js +2 -2
- package/dist/core/runtime/placement.d.ts +11 -11
- package/dist/core/runtime/placement.js +1 -1
- package/dist/core/runtime/promote.d.ts +3 -3
- package/dist/core/runtime/promote.js +1 -1
- package/dist/core/runtime/recycle.js +1 -1
- package/dist/core/runtime/reopen.d.ts +5 -5
- package/dist/core/runtime/reopen.js +1 -1
- package/dist/core/runtime/reset.d.ts +4 -4
- package/dist/core/runtime/reset.js +1 -1
- package/dist/core/runtime/revive-all.d.ts +2 -2
- package/dist/core/runtime/revive-all.js +1 -1
- package/dist/core/runtime/revive.d.ts +4 -4
- package/dist/core/runtime/revive.js +2 -2
- package/dist/core/runtime/roadmap.d.ts +6 -6
- package/dist/core/runtime/roadmap.js +5 -5
- package/dist/core/runtime/session-branch.d.ts +1 -1
- package/dist/core/runtime/session-branch.js +1 -1
- package/dist/core/runtime/session-list-cache.js +1 -1
- package/dist/core/runtime/situational-live.js +1 -1
- package/dist/core/runtime/spawn.d.ts +2 -2
- package/dist/core/runtime/spawn.js +2 -2
- package/dist/core/runtime/stop-guard.d.ts +2 -2
- package/dist/core/runtime/stop-guard.js +3 -3
- package/dist/core/runtime/warm-pool.d.ts +2 -2
- package/dist/core/runtime/warm-pool.js +1 -1
- package/dist/core/spaces/mounts.d.ts +2 -2
- package/dist/core/spaces/mounts.js +1 -1
- package/dist/core/spaces/permissions.d.ts +1 -1
- package/dist/core/spaces/permissions.js +1 -1
- package/dist/core/spaces/process.d.ts +1 -1
- package/dist/core/spaces/process.js +1 -1
- package/dist/core/spaces/space.js +1 -1
- package/dist/core/spaces/stop.d.ts +3 -3
- package/dist/core/spaces/stop.js +2 -2
- package/dist/core/spaces/users.d.ts +6 -6
- package/dist/core/spaces/users.js +1 -1
- package/dist/core/storage/attachments.d.ts +2 -2
- package/dist/core/storage/attachments.js +1 -1
- package/dist/core/storage/shares.d.ts +2 -2
- package/dist/core/storage/shares.js +1 -1
- package/dist/core/storage/tables.d.ts +21 -21
- package/dist/core/storage/tables.js +3 -3
- package/dist/core/substrate/delivery/corpus.d.ts +5 -8
- package/dist/core/substrate/delivery/corpus.js +3 -3
- package/dist/core/substrate/delivery/deliver.d.ts +10 -15
- package/dist/core/substrate/delivery/deliver.js +3 -3
- package/dist/core/substrate/delivery/plan.d.ts +2 -12
- package/dist/core/substrate/delivery/plan.js +3 -3
- package/dist/core/substrate/delivery/render-boot.d.ts +4 -4
- package/dist/core/substrate/delivery/render-boot.js +18 -18
- package/dist/core/substrate/delivery/render-event.d.ts +7 -14
- package/dist/core/substrate/delivery/render-event.js +4 -4
- package/dist/core/substrate/subject.d.ts +2 -2
- package/dist/core/substrate/subject.js +1 -1
- package/dist/core/usage/ledger.d.ts +6 -6
- package/dist/core/usage/ledger.js +4 -4
- package/dist/core/worktree-close.js +4 -4
- package/dist/core/worktree-mutation-async.js +7 -7
- package/dist/core/worktree-quarantine.js +1 -1
- package/dist/core/worktree-sweep.d.ts +1 -1
- package/dist/core/worktree-sweep.js +6 -6
- package/dist/core/worktree.d.ts +5 -5
- package/dist/core/worktree.js +13 -13
- package/dist/daemon/analytics/compute.d.ts +2 -2
- package/dist/daemon/analytics/compute.js +1 -1
- package/dist/daemon/api/app-listener.d.ts +4 -4
- package/dist/daemon/api/app-listener.js +13 -13
- package/dist/daemon/api/bridge.js +5 -5
- package/dist/daemon/api/document-listener.js +6 -6
- package/dist/daemon/api/handlers/analytics.js +1 -1
- package/dist/daemon/api/handlers/attach.js +1 -1
- package/dist/daemon/api/handlers/bash-jobs.js +1 -1
- package/dist/daemon/api/handlers/bash.js +1 -1
- package/dist/daemon/api/handlers/broker-ops.d.ts +1 -1
- package/dist/daemon/api/handlers/broker-ops.js +1 -1
- package/dist/daemon/api/handlers/broker-recovery.d.ts +1 -1
- package/dist/daemon/api/handlers/broker-recovery.js +1 -1
- package/dist/daemon/api/handlers/broker-signals.d.ts +2 -2
- package/dist/daemon/api/handlers/broker-signals.js +2 -2
- package/dist/daemon/api/handlers/canvas.d.ts +1 -1
- package/dist/daemon/api/handlers/canvas.js +4 -4
- package/dist/daemon/api/handlers/chat-inventory.js +1 -1
- package/dist/daemon/api/handlers/crons.js +1 -1
- package/dist/daemon/api/handlers/custom-objects.d.ts +4 -4
- package/dist/daemon/api/handlers/custom-objects.js +3 -3
- package/dist/daemon/api/handlers/delivery-retry.js +1 -1
- package/dist/daemon/api/handlers/delivery.js +1 -1
- package/dist/daemon/api/handlers/docs.d.ts +4 -4
- package/dist/daemon/api/handlers/docs.js +1 -1
- package/dist/daemon/api/handlers/feedback-comments.js +3 -3
- package/dist/daemon/api/handlers/files.js +1 -1
- package/dist/daemon/api/handlers/focus.js +1 -1
- package/dist/daemon/api/handlers/health.js +3 -3
- package/dist/daemon/api/handlers/hook-exec.js +1 -1
- package/dist/daemon/api/handlers/human-requests.js +1 -1
- package/dist/daemon/api/handlers/inbox-page.d.ts +1 -1
- package/dist/daemon/api/handlers/inbox-page.js +1 -1
- package/dist/daemon/api/handlers/inbox.d.ts +1 -1
- package/dist/daemon/api/handlers/inbox.js +1 -1
- package/dist/daemon/api/handlers/llm.d.ts +1 -1
- package/dist/daemon/api/handlers/llm.js +3 -3
- package/dist/daemon/api/handlers/memory-reads.js +1 -1
- package/dist/daemon/api/handlers/memory.d.ts +5 -5
- package/dist/daemon/api/handlers/memory.js +5 -5
- package/dist/daemon/api/handlers/messages.js +2 -2
- package/dist/daemon/api/handlers/node-events.d.ts +2 -2
- package/dist/daemon/api/handlers/node-events.js +3 -3
- package/dist/daemon/api/handlers/node-outcomes.js +1 -1
- package/dist/daemon/api/handlers/node-records.js +2 -2
- package/dist/daemon/api/handlers/nodes.d.ts +1 -1
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/handlers/objects.js +3 -3
- package/dist/daemon/api/handlers/package-docs.js +1 -1
- package/dist/daemon/api/handlers/plugin-app-token.d.ts +1 -1
- package/dist/daemon/api/handlers/plugin-app-token.js +1 -1
- package/dist/daemon/api/handlers/profiles.d.ts +3 -3
- package/dist/daemon/api/handlers/profiles.js +1 -1
- package/dist/daemon/api/handlers/providers.d.ts +1 -1
- package/dist/daemon/api/handlers/providers.js +1 -1
- package/dist/daemon/api/handlers/questions.js +1 -1
- package/dist/daemon/api/handlers/reports.d.ts +1 -1
- package/dist/daemon/api/handlers/reports.js +5 -5
- package/dist/daemon/api/handlers/review-comments.js +1 -1
- package/dist/daemon/api/handlers/reviews.js +1 -1
- package/dist/daemon/api/handlers/runs.js +1 -1
- package/dist/daemon/api/handlers/structured-requests.js +1 -1
- package/dist/daemon/api/handlers/subscriptions.js +1 -1
- package/dist/daemon/api/handlers/transfer.js +1 -1
- package/dist/daemon/api/map.d.ts +3 -3
- package/dist/daemon/api/map.js +1 -1
- package/dist/daemon/api/principal.d.ts +1 -1
- package/dist/daemon/api/principal.js +1 -1
- package/dist/daemon/api/reader.d.ts +5 -5
- package/dist/daemon/api/reader.js +1 -1
- package/dist/daemon/api/router.d.ts +5 -5
- package/dist/daemon/api/router.js +1 -1
- package/dist/daemon/api/server.js +1 -1
- package/dist/daemon/broker-signals/bus.d.ts +1 -1
- package/dist/daemon/broker-signals/bus.js +1 -1
- package/dist/daemon/companion-retire.js +1 -1
- package/dist/daemon/cron/armed-context.d.ts +2 -2
- package/dist/daemon/cron/armed-context.js +1 -1
- package/dist/daemon/cron/authority.d.ts +2 -2
- package/dist/daemon/cron/authority.js +1 -1
- package/dist/daemon/cron/disposition.js +1 -1
- package/dist/daemon/cron/ended.d.ts +1 -1
- package/dist/daemon/cron/ended.js +2 -2
- package/dist/daemon/cron/escalation.js +3 -3
- package/dist/daemon/cron/folders.d.ts +1 -1
- package/dist/daemon/cron/folders.js +1 -1
- package/dist/daemon/cron/held.d.ts +1 -1
- package/dist/daemon/cron/held.js +1 -1
- package/dist/daemon/cron/lease-recovery.d.ts +1 -1
- package/dist/daemon/cron/lease-recovery.js +1 -1
- package/dist/daemon/cron/passes.d.ts +2 -2
- package/dist/daemon/cron/passes.js +1 -1
- package/dist/daemon/cron/run-socket.d.ts +1 -1
- package/dist/daemon/cron/run-socket.js +1 -1
- package/dist/daemon/cron/settle.js +1 -1
- package/dist/daemon/cron/sinks.d.ts +1 -1
- package/dist/daemon/cron/sinks.js +2 -2
- package/dist/daemon/cron-run.d.ts +12 -3
- package/dist/daemon/cron-run.js +2 -2
- package/dist/daemon/crtrd.js +6 -6
- package/dist/daemon/delivery/run-delivery.js +1 -1
- package/dist/daemon/due-sources.d.ts +3 -3
- package/dist/daemon/due-sources.js +1 -1
- package/dist/daemon/due.d.ts +3 -3
- package/dist/daemon/due.js +7 -7
- package/dist/daemon/fleet.d.ts +2 -2
- package/dist/daemon/fleet.js +11 -11
- package/dist/daemon/human/finish.js +3 -3
- package/dist/daemon/human/settle.d.ts +1 -1
- package/dist/daemon/human/settle.js +1 -1
- package/dist/daemon/human/sweep.js +1 -1
- package/dist/daemon/joined-owner.d.ts +2 -2
- package/dist/daemon/joined-owner.js +1 -1
- package/dist/daemon/messaging/node-message.js +1 -1
- package/dist/daemon/park-activity.d.ts +2 -2
- package/dist/daemon/park-activity.js +1 -1
- package/dist/daemon/peer/authority.js +1 -1
- package/dist/daemon/peer/forward.d.ts +6 -6
- package/dist/daemon/peer/forward.js +1 -1
- package/dist/daemon/peer/handlers.js +1 -1
- package/dist/daemon/peer/ingress.d.ts +4 -4
- package/dist/daemon/peer/ingress.js +1 -1
- package/dist/daemon/peer/outbox.d.ts +2 -2
- package/dist/daemon/peer/outbox.js +1 -1
- package/dist/daemon/peer/relay-service.js +1 -1
- package/dist/daemon/plugin-objects/read-leaf.d.ts +2 -2
- package/dist/daemon/plugin-objects/read-leaf.js +2 -2
- package/dist/daemon/profile-delete.js +1 -1
- package/dist/daemon/readiness.d.ts +2 -2
- package/dist/daemon/readiness.js +1 -1
- package/dist/daemon/reconcilers/action-lane.d.ts +1 -1
- package/dist/daemon/reconcilers/action-lane.js +1 -1
- package/dist/daemon/reconcilers/bash-deadline.js +2 -2
- package/dist/daemon/reconcilers/broker-supervision.d.ts +1 -1
- package/dist/daemon/reconcilers/broker-supervision.js +4 -4
- package/dist/daemon/reconcilers/controller-death.d.ts +1 -1
- package/dist/daemon/reconcilers/controller-death.js +1 -1
- package/dist/daemon/reconcilers/cron-lane.d.ts +1 -1
- package/dist/daemon/reconcilers/cron-lane.js +1 -1
- package/dist/daemon/reconcilers/delivery-lane.d.ts +1 -1
- package/dist/daemon/reconcilers/delivery-lane.js +2 -2
- package/dist/daemon/reconcilers/fault-retry-backstop.d.ts +3 -3
- package/dist/daemon/reconcilers/fault-retry-backstop.js +1 -1
- package/dist/daemon/reconcilers/grove-instance-sweep.d.ts +2 -2
- package/dist/daemon/reconcilers/grove-instance-sweep.js +1 -1
- package/dist/daemon/reconcilers/live-obligation.d.ts +6 -6
- package/dist/daemon/reconcilers/live-obligation.js +1 -1
- package/dist/daemon/reconcilers/managed-worktree-sweep.js +1 -1
- package/dist/daemon/reconcilers/node-deadline.d.ts +1 -1
- package/dist/daemon/reconcilers/node-deadline.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/respawn-policy.d.ts +3 -3
- package/dist/daemon/reconcilers/node-lifecycle/respawn-policy.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/terminating.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/tick.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/wants-execution.d.ts +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/wants-execution.js +1 -1
- package/dist/daemon/reconcilers/pending-review-submit.d.ts +1 -1
- package/dist/daemon/reconcilers/pending-review-submit.js +1 -1
- package/dist/daemon/reconcilers/storage-due-work.js +1 -1
- package/dist/daemon/reconcilers/storage-maintenance.d.ts +1 -1
- package/dist/daemon/reconcilers/storage-maintenance.js +2 -2
- package/dist/daemon/reconcilers/structured-request-lane.d.ts +1 -1
- package/dist/daemon/reconcilers/structured-request-lane.js +1 -1
- package/dist/daemon/review/comment-notify.js +2 -2
- package/dist/daemon/review/companion.d.ts +3 -3
- package/dist/daemon/review/companion.js +1 -1
- package/dist/daemon/review/finish.js +1 -1
- package/dist/daemon/review/sweep.js +1 -1
- package/dist/daemon/run-notices.d.ts +4 -4
- package/dist/daemon/run-notices.js +1 -1
- package/dist/daemon/runs/append-section.d.ts +2 -2
- package/dist/daemon/runs/append-section.js +2 -2
- package/dist/daemon/runs/observer.d.ts +2 -2
- package/dist/daemon/runs/observer.js +2 -2
- package/dist/daemon/structured-requests/boot.d.ts +1 -1
- package/dist/daemon/structured-requests/boot.js +1 -1
- package/dist/daemon/structured-requests/effects.js +1 -1
- package/dist/daemon/structured-requests/sidecar.d.ts +1 -1
- package/dist/daemon/structured-requests/sidecar.js +1 -1
- package/dist/migrations/004-canvas-documents/apply.d.ts +3 -3
- package/dist/migrations/004-canvas-documents/apply.js +1 -1
- package/dist/migrations/004-canvas-documents/index.d.ts +2 -2
- package/dist/migrations/004-canvas-documents/index.js +2 -2
- package/dist/migrations/activation.js +2 -2
- package/docs/public-api.md +11 -0
- package/package.json +3 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=Object.defineProperty;var p=(o,t)=>c(o,"name",{value:t,configurable:!0});import{statSync as u}from"node:fs";import{isAbsolute as f}from"node:path";import{ApiError as d}from"../../../api/index.js";import{buildOperationalEnvBase as l}from"../../../core/runtime/spawn-env.js";import{runAppCommand as w}from"../../../core/runtime/run-command.js";import{getNode as _}from"../../../core/canvas/canvas.js";import{readProfileEnvVars as b}from"../../../core/profiles/env-store.js";import{readAppEnvVars as y}from"../../../core/profiles/app-env-store.js";import{usage as i}from"../../../core/errors.js";import{appOf as h}from"../router.js";const T=60,m=600,E=256*1024;function A(o){if(typeof o!="object"||o===null||Array.isArray(o))throw i("bash requires an object body");const t=o;if(typeof t.command!="string"||t.command==="")throw i("bash requires a non-empty `command`");if(typeof t.cwd!="string"||!f(t.cwd))throw new d(404,"cwd_not_found","cwd must name an absolute directory");try{if(!u(t.cwd).isDirectory())throw new Error("not a directory")}catch{throw new d(404,"cwd_not_found",`cwd not found: ${t.cwd}`)}const r=t.timeout_s??T;if(typeof r!="number"||!Number.isFinite(r)||r<=0||r>m)throw new d(422,"invalid_timeout",`timeout_s must be greater than 0 and at most ${m}`);if(t.profile!==void 0&&typeof t.profile!="string")throw i("profile must be a string");let n;if(t.env!==void 0){if(typeof t.env!="object"||t.env===null||Array.isArray(t.env))throw i("env must be an object of string values");n={};for(const[s
|
|
1
|
+
var c=Object.defineProperty;var p=(o,t)=>c(o,"name",{value:t,configurable:!0});import{statSync as u}from"node:fs";import{isAbsolute as f}from"node:path";import{ApiError as d}from"../../../api/index.js";import{buildOperationalEnvBase as l}from"../../../core/runtime/spawn-env.js";import{runAppCommand as w}from"../../../core/runtime/run-command.js";import{getNode as _}from"../../../core/canvas/canvas.js";import{readProfileEnvVars as b}from"../../../core/profiles/env-store.js";import{readAppEnvVars as y}from"../../../core/profiles/app-env-store.js";import{usage as i}from"../../../core/errors.js";import{appOf as h}from"../router.js";const T=60,m=600,E=256*1024;function A(o){if(typeof o!="object"||o===null||Array.isArray(o))throw i("bash requires an object body");const t=o;if(typeof t.command!="string"||t.command==="")throw i("bash requires a non-empty `command`");if(typeof t.cwd!="string"||!f(t.cwd))throw new d(404,"cwd_not_found","cwd must name an absolute directory");try{if(!u(t.cwd).isDirectory())throw new Error("not a directory")}catch{throw new d(404,"cwd_not_found",`cwd not found: ${t.cwd}`)}const r=t.timeout_s??T;if(typeof r!="number"||!Number.isFinite(r)||r<=0||r>m)throw new d(422,"invalid_timeout",`timeout_s must be greater than 0 and at most ${m}`);if(t.profile!==void 0&&typeof t.profile!="string")throw i("profile must be a string");let n;if(t.env!==void 0){if(typeof t.env!="object"||t.env===null||Array.isArray(t.env))throw i("env must be an object of string values");n={};for(const[a,s]of Object.entries(t.env)){if(typeof s!="string")throw i("env must be an object of string values");n[a]=s}}return{command:t.command,cwd:t.cwd,timeout_s:r,env:n,profile:t.profile}}p(A,"parseRequest");async function g(o){const t=A(o.body),r=h(o.principal)??"app:terminal";if(r!=="app:terminal"&&t.profile!==void 0)throw new d(403,"permission_error","app bash cannot select an owner profile");const n=r==="app:terminal"?t.profile??null:null,a=l({targetCwd:t.cwd,targetProfileId:n,skipSpawnAllow:r!=="app:terminal"}),s={...a,...y(r),...r==="app:terminal"?b(n):{},...t.env,...n===null?{}:{CRTR_PROFILE_ID:n},CRTR_ADMITTED_HOST_PATH:a.CRTR_ADMITTED_HOST_PATH},e=await(await w({app:r,...o.principal.class==="broker"?{nodeId:o.principal.node,isolated:(await _(o.principal.node))?.isolated===!0}:{},command:t.command,cwd:t.cwd,env:s,timeoutMs:t.timeout_s*1e3,headBytes:E})).completion;if(e.processError!==null)throw e.processError;return{status:200,body:{exit_code:e.timedOut?null:e.exitCode,signal:e.signal,stdout:e.stdout,stdout_truncated:e.stdoutTruncated,stderr:e.stderr,stderr_truncated:e.stderrTruncated,timed_out:e.timedOut,duration_ms:e.durationMs}}}p(g,"handleBash");const q=[{method:"POST",pattern:"/v1/bash",scope:"crtr:act",handler:g}];export{q as bashRoutes};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BrokerExtensionNodeDTO } from '../../../api/dto/broker-ops.js';
|
|
2
2
|
import { getNode } from '../../../core/canvas/canvas.js';
|
|
3
3
|
import { type RouteTable } from '../router.js';
|
|
4
|
-
export declare function extensionNode(node: NonNullable<ReturnType<typeof getNode
|
|
4
|
+
export declare function extensionNode(node: NonNullable<Awaited<ReturnType<typeof getNode>>>): Promise<BrokerExtensionNodeDTO>;
|
|
5
5
|
export declare const brokerOperationRoutes: RouteTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var A=Object.defineProperty;var i=(e,t)=>A(e,"name",{value:t,configurable:!0});import{canonicalSessionFile as F,findNodeBySessionFile as O,getNode as y,isWarmSpare as R,listNodeIdentities as T,recordRespawnAttempt as I,recordSettledTurn as $,setPresence as b,subscriptionsOf as j,updateNode as g,updateNodeTelemetry as C}from"../../../core/canvas/canvas.js";import{recordExecutionPid as q}from"../../../core/canvas/executions.js";import{bindSession as E,readLiveSession as M,transferSession as L}from"../../../core/canvas/sessions.js";import{isSafeNodeId as D}from"../../../core/canvas/paths.js";import{appForNode as G}from"../../../core/canvas/node-agent-paths.js";import{isPidAlive as J}from"../../../core/canvas/pid.js";import{editorLabel as P}from"../../../core/canvas/labels.js";import{assembleNodeSubject as W}from"../../../core/substrate/subject.js";import{withCanvasWrite as l}from"../../../core/canvas/db.js";import{notFound as v,usage as a}from"../../../core/errors.js";import{hasUnseenWakeMail as N}from"../../../core/canvas/deliveries.js";import{clearYieldMessage as U}from"../../../core/runtime/kickoff.js";import{readRoadmap as V}from"../../../core/runtime/roadmap.js";import{forkSourceNode as Y}from"../../../core/runtime/nodes.js";import{transition as _}from"../../../core/runtime/lifecycle.js";import{focusOf as k,tearDownNode as x}from"../../../core/runtime/placement.js";import{hasAttachedBrokerViewers as z}from"../viewer-presence.js";import{evaluateStop as H}from"../../../core/runtime/stop-guard.js";import{clearFault as h,recordFault as K}from"../../../core/canvas/recovery.js";import{updateModelRecipe as Q}from"../../../core/runtime/model-swap.js";import{completeCompanionRequestedSubmit as X}from"../../review/finish.js";import{emitEvent as Z}from"../../../core/events/emit.js";import{consumePendingPark as ee,recordPendingParkActivity as te}from"../../park-pending.js";import{shouldParkAfterSummary as ne}from"../../park-activity.js";import{ownerOnly as oe}from"../router.js";import{requireCurrentExecution as m}from"./broker-recovery.js";import{ensureRunObserver as re}from"../../runs/observer.js";import{parseNodeTelemetryRecord as ie,writeNodeTelemetryRecord as se}from"./telemetry-record.js";function p(e,t){if(typeof e!="object"||e===null||Array.isArray(e))throw a(`${t} requires a JSON body`);return e}i(p,"objectBody");function ae(e){const t=p(e,"broker session-bound");if(typeof t.executionId!="string"||t.executionId==="")throw a("executionId must be a non-empty string");if(typeof t.piSessionId!="string"||t.piSessionId==="")throw a("piSessionId must be a non-empty string");if(t.sessionFile!==null&&typeof t.sessionFile!="string")throw a("sessionFile must be a string or null");if(!Number.isSafeInteger(t.pid)||t.pid<=0)throw a("pid must be a positive safe integer");if(t.reason!==null&&typeof t.reason!="string")throw a("reason must be a string or null");if(!Array.isArray(t.reviewBoundaryIds)||!t.reviewBoundaryIds.every(n=>typeof n=="string"))throw a("reviewBoundaryIds must be an array of strings");return t}i(ae,"parseSessionBoundBody");function de(e){const t=p(e,"broker settle");if(typeof t.stopReason!="string")throw a("stopReason must be a string");for(const n of["backgroundJobsRunning","pushedFinal"])if(typeof t[n]!="boolean")throw a(`${n} must be a boolean`);return t}i(de,"parseSettleBody");function ue(e){const t=p(e,"broker park-complete");if(t.outcome!=="completed"&&t.outcome!=="failed")throw a("outcome must be completed or failed");return t}i(ue,"parseParkCompleteBody");function ce(e){const t=p(e,"broker telemetry");if(typeof t.expected_execution_id!="string"||t.expected_execution_id==="")throw a("expected_execution_id must be a non-empty string");const n=ie(t);return{...n,expected_execution_id:t.expected_execution_id,updated_at:new Date(n.updated_at).toISOString()}}i(ce,"parseTelemetryBody");function le(e){const t=p(e,"broker model");if(typeof t.spec!="string"||t.spec.trim()==="")throw a("spec must be a non-empty string");const n=t.intent;if(n!==void 0){const r=n!==null&&typeof n=="object"?n:void 0;if(r===void 0||typeof r.family!="string"||r.family===""||!["ultra","strong","medium","light"].includes(r.strength))throw a("intent must be { family, strength } with strength ultra|strong|medium|light when present")}if(typeof t.userSelected!="boolean")throw a("userSelected must be a boolean");return t}i(le,"parseModelCommitBody");function f(e){const t=y(e);if(t===null)throw v(`unknown node: ${e}`,{received:e});return t}i(f,"requireNode");function w(e){return{node_id:e.node_id,grantee:G(e.node_id),name:e.name,...e.description===void 0?{}:{description:e.description},...e.title===void 0?{}:{title:e.title},...e.icon===void 0?{}:{icon:e.icon},kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,status:e.status,cwd:e.cwd,parent:e.parent??null,fork_from:e.fork_from??null,profile_id:e.profile_id??null,...e.managed_worktree===void 0?{}:{managed_worktree:e.managed_worktree===null?null:{state:e.managed_worktree.state,...e.managed_worktree.cleanup===void 0?{}:{cleanup:e.managed_worktree.cleanup},path:e.managed_worktree.path,branch:e.managed_worktree.branch,base_ref:e.managed_worktree.base_ref,base_sha:e.managed_worktree.base_sha}},...e.review_binding===void 0?{}:{review_binding:e.review_binding??null},intent:e.intent??null,...e.persona_ack===void 0?{}:{persona_ack:e.persona_ack},created:e.created}}i(w,"extensionNode");function pe(e){const t=f(e),n=[],r=new Set([e]);let o=t.parent??null;for(;o!==null&&o!==""&&!r.has(o);){r.add(o);const c=y(o);if(c===null)break;n.unshift(w(c)),o=c.parent??null}const s=j(e).map(c=>y(c.node_id)).filter(c=>c!==null&&c.kind!=="human").sort((c,S)=>c.status===S.status?0:c.status==="active"?-1:S.status==="active"?1:0).map(w),u=typeof t.fork_source_file=="string"?Y(t.fork_source_file):null,d=W(e);if(d===null)throw v(`unknown node: ${e}`,{received:e});return{node:w(t),warm_spare:R(e),ancestors:n,children:s,fork_source:u===null?null:w(u),subject:d,report_nodes:T(),roadmap:V(e)}}i(pe,"extensionState");function B(e,t){return e?.kind===t.kind&&e?.mode===t.mode&&e?.lifecycle===t.lifecycle}i(B,"samePersona");function me(e){const t=p(e,"broker generated-name");if(t.kind!=="initial"&&t.kind!=="recap")throw a("kind must be initial or recap");if(typeof t.description!="string"||typeof t.title!="string"||typeof t.icon!="string")throw a("description, title, and icon must be strings");if(t.kind==="initial")return t;const n=t.expected;if(typeof n!="object"||n===null||Array.isArray(n)||["name","description","title","icon","kind"].some(r=>typeof n[r]!="string"))throw a("recap expected must contain name, description, title, icon, and kind strings");return t}i(me,"parseGeneratedNameBody");function fe(e){const t=p(e,"broker persona-ack"),n=i(r=>{const o=t[r];if(typeof o!="object"||o===null||Array.isArray(o)||typeof o.kind!="string"||o.mode!=="base"&&o.mode!=="orchestrator"||o.lifecycle!=="terminal"&&o.lifecycle!=="resident")throw a(`${r} must be a persona state`);return o},"parse");return{expected_execution_id:t.expected_execution_id,from:n("from"),to:n("to")}}i(fe,"parsePersonaAckBody");function he(e){const t=e.params.id,n=ae(e.body),r=n.sessionFile===null?null:F(n.sessionFile);return{status:200,body:l(()=>{const s=f(t);if(q(n.executionId,t,n.pid)==="shutdown")return{action:"shutdown"};const u=s.review_binding?.review_id;if(u!==void 0&&!n.reviewBoundaryIds.includes(u))return{action:"shutdown"};if(n.reason==="new"&&s.parent==null)return{action:"relaunch_root"};if(n.reason!=="new"&&s.fork_from!=null&&s.pi_session_id==null&&r===null)return{action:"shutdown"};const d=r===null?null:O(r);if(d!==null&&d.node_id!==t){if(J(d.pi_pid))return K(t,{link:"daemon\u2192node",op:"session-file-ownership",kind:"protocol",retry:{disposition:"fatal"},message:`refusing to bind ${r}: it is owned by live node ${d.node_id}`}),{action:"shutdown"};const c=M(d.node_id);if(c===null||L({fromNodeId:d.node_id,fromBindingId:c.bindingId,toNodeId:t,executionId:n.executionId,sessionId:n.piSessionId,transcriptPath:r})!=="transferred")return{action:"shutdown"}}else if(E(t,{executionId:n.executionId,sessionId:n.piSessionId,transcriptPath:r})==="shutdown")return{action:"shutdown"};return n.reason!=="new"&&(U(t),s.intent==="refresh"&&_(t,"revive")),{action:"none"}})}}i(he,"handleSessionBound");function ye(e,t){const n=y(e);if(n===null){if(t.pushedFinal)return{action:"shutdown"};throw v(`unknown node: ${e}`,{received:e})}if($(e,new Date().toISOString()),(t.stopReason==="stop"||t.stopReason==="length")&&I(e,{failures:0,notBefore:null}),t.stopReason==="quit")return(n.status==="active"||n.status==="idle")&&n.intent===null&&(_(e,"finish"),h(e),k(e)!==null&&x(e),b(e,{pane:null,tmux_session:null,window:null})),{action:"shutdown"};if(t.stopReason!=="stop"&&t.stopReason!=="length")return h(e,{link:"daemon\u2192node"}),n.intent==="refresh"?{action:"shutdown"}:{action:"stay_dormant"};const r={pushedFinal:t.pushedFinal};if(r.pushedFinal||n.status==="done")return h(e),k(e)!==null&&x(e),b(e,{pane:null,tmux_session:null,window:null}),{action:"shutdown"};if(n.intent==="refresh")return h(e),{action:"shutdown"};const o=H(e,r,t.backgroundJobsRunning);return h(e),o.action==="reprompt"?{action:"reprompt",prompt:o.message}:o.reason==="finished"?N(e)?{action:"stay_dormant"}:{action:"shutdown"}:o.reason!=="awaiting"&&o.reason!=="scheduled"?{action:"stay_dormant"}:k(e)!==null||z(e)||N(e)?{action:"stay_dormant"}:(_(e,"release"),{action:"shutdown"})}i(ye,"settleBroker");function _e(e){const t=e.params.id,n=de(e.body);m(t,n.expected_execution_id);const r=l(()=>ye(t,n));return r.action!=="reprompt"&&X(t),{status:200,body:r}}i(_e,"handleSettle");function ke(e){const t=e.params.id,n=ue(e.body);return m(t,n.expected_execution_id),{status:200,body:l(()=>{const o=ee(t);if(o===void 0)return{action:"stay_dormant"};const s=f(t);return ne(t,s,o)?(h(t),_(t,"park"),k(t)!==null&&x(t),b(t,{pane:null,tmux_session:null,window:null}),Z({level:n.outcome==="completed"?"info":"warn",event:"broker.park.complete",...D(t)?{node_id:t}:{},outcome:n.outcome==="completed"?"succeeded":"failed"}),{action:"shutdown"}):{action:"stay_dormant"}})}}i(ke,"handleParkComplete");function we(e){const t=e.params.id;return m(t,p(e.body,"broker park-activity").expected_execution_id),{status:200,body:l(()=>({activity:te(t)?"recorded":"none"}))}}i(we,"handleParkActivity");function be(e){const t=e.params.id,n=ce(e.body);return m(t,n.expected_execution_id),l(()=>{C(t,{tokensIn:n.tokens_in,contextTokens:n.context_tokens,lastActivity:n.last_activity,updatedAt:n.updated_at}),se(t,n)}),{status:204}}i(be,"handleTelemetry");function ge(e){const t=e.params.id,n=le(e.body);return m(t,n.expected_execution_id),{status:200,body:{modelOverride:l(()=>Q(f(t),n.spec,n.intent,n.userSelected)).model_override}}}i(ge,"handleModelCommit");function ve(e){const t=e.params.id,n=f(t);return n.run_id&&re(t,n.run_id),{status:200,body:pe(t)}}i(ve,"handleExtensionState");function xe(e){const t=e.params.id,n=me(e.body);return m(t,n.expected_execution_id),{status:200,body:l(()=>{const o=f(t);if(n.kind==="initial"){if((o.description??"").trim()!=="")return{applied:!1};const d=g(t,{description:n.description,...n.title.trim()===""?{}:{title:n.title},...n.icon.trim()===""?{}:{icon:n.icon}});return{applied:!0,editorLabel:P(d),description:d.description??"",title:d.title??"",icon:d.icon??""}}const s=n.expected;if(o.name!==s.name||(o.description??"")!==s.description||(o.title??"")!==s.title||(o.icon??"")!==s.icon||o.kind!==s.kind)return{applied:!1};const u=g(t,{description:n.description,title:n.title.trim()===""?void 0:n.title,icon:n.icon.trim()===""?void 0:n.icon});return{applied:!0,editorLabel:P(u),description:u.description??"",title:u.title??"",icon:u.icon??""}})}}i(xe,"handleGeneratedName");function Se(e){const t=e.params.id,n=fe(e.body);return m(t,n.expected_execution_id),{status:200,body:l(()=>{const o=f(t),s={kind:o.kind,mode:o.mode,lifecycle:o.lifecycle},u=o.persona_ack,d=u===void 0?s:{kind:u.kind??o.kind,mode:u.mode,lifecycle:u.lifecycle};return!B(s,n.to)||!B(d,n.from)?{applied:!1}:(g(t,{persona_ack:n.to}),{applied:!0})})}}i(Se,"handlePersonaAck");const et=oe([{method:"POST",pattern:"/v1/nodes/:id/broker/session-bound",handler:he},{method:"POST",pattern:"/v1/nodes/:id/broker/settle",handler:_e},{method:"POST",pattern:"/v1/nodes/:id/broker/park-complete",handler:ke},{method:"POST",pattern:"/v1/nodes/:id/broker/park-activity",handler:we},{method:"POST",pattern:"/v1/nodes/:id/broker/telemetry",handler:be},{method:"POST",pattern:"/v1/nodes/:id/broker/model",handler:ge},{method:"GET",pattern:"/v1/nodes/:id/broker/extension-state",handler:ve},{method:"POST",pattern:"/v1/nodes/:id/broker/generated-name",handler:xe},{method:"POST",pattern:"/v1/nodes/:id/broker/persona-ack",handler:Se}]);export{et as brokerOperationRoutes,w as extensionNode};
|
|
1
|
+
var F=Object.defineProperty;var r=(e,t)=>F(e,"name",{value:t,configurable:!0});import{canonicalSessionFile as O,findNodeBySessionFile as R,getNode as y,isWarmSpare as T,listNodeIdentities as I,recordRespawnAttempt as $,recordSettledTurn as j,setPresence as b,subscriptionsOf as C,updateNode as g,updateNodeTelemetry as q}from"../../../core/canvas/canvas.js";import{recordExecutionPid as E}from"../../../core/canvas/executions.js";import{bindSession as M,readLiveSession as L,transferSession as D}from"../../../core/canvas/sessions.js";import{isSafeNodeId as G}from"../../../core/canvas/paths.js";import{appForNode as J}from"../../../core/canvas/node-agent-paths.js";import{isPidAlive as W}from"../../../core/canvas/pid.js";import{editorLabel as P}from"../../../core/canvas/labels.js";import{assembleNodeSubject as U}from"../../../core/substrate/subject.js";import{withCanvasWrite as l}from"../../../core/canvas/db.js";import{notFound as v,usage as s}from"../../../core/errors.js";import{hasUnseenWakeMail as N}from"../../../core/canvas/deliveries.js";import{clearYieldMessage as V}from"../../../core/runtime/kickoff.js";import{readRoadmap as Y}from"../../../core/runtime/roadmap.js";import{forkSourceNode as z}from"../../../core/runtime/nodes.js";import{transition as h}from"../../../core/runtime/lifecycle.js";import{focusOf as _,tearDownNode as x}from"../../../core/runtime/placement.js";import{hasAttachedBrokerViewers as H}from"../viewer-presence.js";import{evaluateStop as K}from"../../../core/runtime/stop-guard.js";import{clearFault as w,recordFault as Q}from"../../../core/canvas/recovery.js";import{updateModelRecipe as X}from"../../../core/runtime/model-swap.js";import{completeCompanionRequestedSubmit as Z}from"../../review/finish.js";import{emitEvent as ee}from"../../../core/events/emit.js";import{consumePendingPark as te,recordPendingParkActivity as ne}from"../../park-pending.js";import{shouldParkAfterSummary as ie}from"../../park-activity.js";import{ownerOnly as oe}from"../router.js";import{requireCurrentExecution as m}from"./broker-recovery.js";import{ensureRunObserver as re}from"../../runs/observer.js";import{parseNodeTelemetryRecord as ae,writeNodeTelemetryRecord as se}from"./telemetry-record.js";import{mapAsync as A}from"../../../core/async-array.js";function p(e,t){if(typeof e!="object"||e===null||Array.isArray(e))throw s(`${t} requires a JSON body`);return e}r(p,"objectBody");function de(e){const t=p(e,"broker session-bound");if(typeof t.executionId!="string"||t.executionId==="")throw s("executionId must be a non-empty string");if(typeof t.piSessionId!="string"||t.piSessionId==="")throw s("piSessionId must be a non-empty string");if(t.sessionFile!==null&&typeof t.sessionFile!="string")throw s("sessionFile must be a string or null");if(!Number.isSafeInteger(t.pid)||t.pid<=0)throw s("pid must be a positive safe integer");if(t.reason!==null&&typeof t.reason!="string")throw s("reason must be a string or null");if(!Array.isArray(t.reviewBoundaryIds)||!t.reviewBoundaryIds.every(n=>typeof n=="string"))throw s("reviewBoundaryIds must be an array of strings");return t}r(de,"parseSessionBoundBody");function ce(e){const t=p(e,"broker settle");if(typeof t.stopReason!="string")throw s("stopReason must be a string");for(const n of["backgroundJobsRunning","pushedFinal"])if(typeof t[n]!="boolean")throw s(`${n} must be a boolean`);return t}r(ce,"parseSettleBody");function ue(e){const t=p(e,"broker park-complete");if(t.outcome!=="completed"&&t.outcome!=="failed")throw s("outcome must be completed or failed");return t}r(ue,"parseParkCompleteBody");function le(e){const t=p(e,"broker telemetry");if(typeof t.expected_execution_id!="string"||t.expected_execution_id==="")throw s("expected_execution_id must be a non-empty string");const n=ae(t);return{...n,expected_execution_id:t.expected_execution_id,updated_at:new Date(n.updated_at).toISOString()}}r(le,"parseTelemetryBody");function pe(e){const t=p(e,"broker model");if(typeof t.spec!="string"||t.spec.trim()==="")throw s("spec must be a non-empty string");const n=t.intent;if(n!==void 0){const o=n!==null&&typeof n=="object"?n:void 0;if(o===void 0||typeof o.family!="string"||o.family===""||!["ultra","strong","medium","light"].includes(o.strength))throw s("intent must be { family, strength } with strength ultra|strong|medium|light when present")}if(typeof t.userSelected!="boolean")throw s("userSelected must be a boolean");return t}r(pe,"parseModelCommitBody");async function f(e){const t=await y(e);if(t===null)throw v(`unknown node: ${e}`,{received:e});return t}r(f,"requireNode");async function k(e){return{node_id:e.node_id,grantee:await J(e.node_id),name:e.name,...e.description===void 0?{}:{description:e.description},...e.title===void 0?{}:{title:e.title},...e.icon===void 0?{}:{icon:e.icon},kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,status:e.status,cwd:e.cwd,parent:e.parent??null,fork_from:e.fork_from??null,profile_id:e.profile_id??null,...e.managed_worktree===void 0?{}:{managed_worktree:e.managed_worktree===null?null:{state:e.managed_worktree.state,...e.managed_worktree.cleanup===void 0?{}:{cleanup:e.managed_worktree.cleanup},path:e.managed_worktree.path,branch:e.managed_worktree.branch,base_ref:e.managed_worktree.base_ref,base_sha:e.managed_worktree.base_sha}},...e.review_binding===void 0?{}:{review_binding:e.review_binding??null},intent:e.intent??null,...e.persona_ack===void 0?{}:{persona_ack:e.persona_ack},created:e.created}}r(k,"extensionNode");async function me(e){const t=await f(e),n=[],o=new Set([e]);let i=t.parent??null;for(;i!==null&&i!==""&&!o.has(i);){o.add(i);const u=await y(i);if(u===null)break;n.unshift(await k(u)),i=u.parent??null}const a=await A((await A(await C(e),async u=>await y(u.node_id))).filter(u=>u!==null&&u.kind!=="human").sort((u,S)=>u.status===S.status?0:u.status==="active"?-1:S.status==="active"?1:0),k),c=typeof t.fork_source_file=="string"?await z(t.fork_source_file):null,d=await U(e);if(d===null)throw v(`unknown node: ${e}`,{received:e});return{node:await k(t),warm_spare:await T(e),ancestors:n,children:a,fork_source:c===null?null:await k(c),subject:d,report_nodes:await I(),roadmap:await Y(e)}}r(me,"extensionState");function B(e,t){return e?.kind===t.kind&&e?.mode===t.mode&&e?.lifecycle===t.lifecycle}r(B,"samePersona");function fe(e){const t=p(e,"broker generated-name");if(t.kind!=="initial"&&t.kind!=="recap")throw s("kind must be initial or recap");if(typeof t.description!="string"||typeof t.title!="string"||typeof t.icon!="string")throw s("description, title, and icon must be strings");if(t.kind==="initial")return t;const n=t.expected;if(typeof n!="object"||n===null||Array.isArray(n)||["name","description","title","icon","kind"].some(o=>typeof n[o]!="string"))throw s("recap expected must contain name, description, title, icon, and kind strings");return t}r(fe,"parseGeneratedNameBody");function we(e){const t=p(e,"broker persona-ack"),n=r(o=>{const i=t[o];if(typeof i!="object"||i===null||Array.isArray(i)||typeof i.kind!="string"||i.mode!=="base"&&i.mode!=="orchestrator"||i.lifecycle!=="terminal"&&i.lifecycle!=="resident")throw s(`${o} must be a persona state`);return i},"parse");return{expected_execution_id:t.expected_execution_id,from:n("from"),to:n("to")}}r(we,"parsePersonaAckBody");async function ye(e){const t=e.params.id,n=de(e.body),o=n.sessionFile===null?null:O(n.sessionFile);return{status:200,body:await l(async()=>{const a=await f(t);if(await E(n.executionId,t,n.pid)==="shutdown")return{action:"shutdown"};const c=a.review_binding?.review_id;if(c!==void 0&&!n.reviewBoundaryIds.includes(c))return{action:"shutdown"};if(n.reason==="new"&&a.parent==null)return{action:"relaunch_root"};if(n.reason!=="new"&&a.fork_from!=null&&a.pi_session_id==null&&o===null)return{action:"shutdown"};const d=o===null?null:await R(o);if(d!==null&&d.node_id!==t){if(W(d.pi_pid))return await Q(t,{link:"daemon\u2192node",op:"session-file-ownership",kind:"protocol",retry:{disposition:"fatal"},message:`refusing to bind ${o}: it is owned by live node ${d.node_id}`}),{action:"shutdown"};const u=await L(d.node_id);if(u===null||await D({fromNodeId:d.node_id,fromBindingId:u.bindingId,toNodeId:t,executionId:n.executionId,sessionId:n.piSessionId,transcriptPath:o})!=="transferred")return{action:"shutdown"}}else if(await M(t,{executionId:n.executionId,sessionId:n.piSessionId,transcriptPath:o})==="shutdown")return{action:"shutdown"};return n.reason!=="new"&&(await V(t),a.intent==="refresh"&&await h(t,"revive")),{action:"none"}})}}r(ye,"handleSessionBound");async function he(e,t){const n=await y(e);if(n===null){if(t.pushedFinal)return{action:"shutdown"};throw v(`unknown node: ${e}`,{received:e})}if(await j(e,new Date().toISOString()),(t.stopReason==="stop"||t.stopReason==="length")&&await $(e,{failures:0,notBefore:null}),t.stopReason==="quit")return(n.status==="active"||n.status==="idle")&&n.intent===null&&(await h(e,"finish"),await w(e),await _(e)!==null&&await x(e),await b(e,{pane:null,tmux_session:null,window:null})),{action:"shutdown"};if(t.stopReason!=="stop"&&t.stopReason!=="length")return await w(e,{link:"daemon\u2192node"}),n.intent==="refresh"?{action:"shutdown"}:{action:"stay_dormant"};const o={pushedFinal:t.pushedFinal};if(o.pushedFinal||n.status==="done")return await w(e),await _(e)!==null&&await x(e),await b(e,{pane:null,tmux_session:null,window:null}),{action:"shutdown"};if(n.intent==="refresh")return await w(e),{action:"shutdown"};const i=await K(e,o,t.backgroundJobsRunning);return await w(e),i.action==="reprompt"?{action:"reprompt",prompt:i.message}:i.reason==="finished"?await N(e)?{action:"stay_dormant"}:{action:"shutdown"}:i.reason!=="awaiting"&&i.reason!=="scheduled"?{action:"stay_dormant"}:await _(e)!==null||H(e)||await N(e)?{action:"stay_dormant"}:(await h(e,"release"),{action:"shutdown"})}r(he,"settleBroker");async function _e(e){const t=e.params.id,n=ce(e.body);await m(t,n.expected_execution_id);const o=await l(async()=>await he(t,n));return o.action!=="reprompt"&&Z(t),{status:200,body:o}}r(_e,"handleSettle");async function ke(e){const t=e.params.id,n=ue(e.body);return await m(t,n.expected_execution_id),{status:200,body:await l(async()=>{const i=te(t);if(i===void 0)return{action:"stay_dormant"};const a=await f(t);return await ie(t,a,i)?(await w(t),await h(t,"park"),await _(t)!==null&&await x(t),await b(t,{pane:null,tmux_session:null,window:null}),ee({level:n.outcome==="completed"?"info":"warn",event:"broker.park.complete",...G(t)?{node_id:t}:{},outcome:n.outcome==="completed"?"succeeded":"failed"}),{action:"shutdown"}):{action:"stay_dormant"}})}}r(ke,"handleParkComplete");async function be(e){const t=e.params.id;return await m(t,p(e.body,"broker park-activity").expected_execution_id),{status:200,body:await l(async()=>({activity:ne(t)?"recorded":"none"}))}}r(be,"handleParkActivity");async function ge(e){const t=e.params.id,n=le(e.body);return await m(t,n.expected_execution_id),await l(async()=>{await q(t,{tokensIn:n.tokens_in,contextTokens:n.context_tokens,lastActivity:n.last_activity,updatedAt:n.updated_at}),se(t,n)}),{status:204}}r(ge,"handleTelemetry");async function ve(e){const t=e.params.id,n=pe(e.body);return await m(t,n.expected_execution_id),{status:200,body:{modelOverride:(await l(async()=>await X(await f(t),n.spec,n.intent,n.userSelected))).model_override}}}r(ve,"handleModelCommit");async function xe(e){const t=e.params.id,n=await f(t);return n.run_id&&await re(t,n.run_id),{status:200,body:await me(t)}}r(xe,"handleExtensionState");async function Se(e){const t=e.params.id,n=fe(e.body);return await m(t,n.expected_execution_id),{status:200,body:await l(async()=>{const i=await f(t);if(n.kind==="initial"){if((i.description??"").trim()!=="")return{applied:!1};const d=await g(t,{description:n.description,...n.title.trim()===""?{}:{title:n.title},...n.icon.trim()===""?{}:{icon:n.icon}});return{applied:!0,editorLabel:P(d),description:d.description??"",title:d.title??"",icon:d.icon??""}}const a=n.expected;if(i.name!==a.name||(i.description??"")!==a.description||(i.title??"")!==a.title||(i.icon??"")!==a.icon||i.kind!==a.kind)return{applied:!1};const c=await g(t,{description:n.description,title:n.title.trim()===""?void 0:n.title,icon:n.icon.trim()===""?void 0:n.icon});return{applied:!0,editorLabel:P(c),description:c.description??"",title:c.title??"",icon:c.icon??""}})}}r(Se,"handleGeneratedName");async function Pe(e){const t=e.params.id,n=we(e.body);return await m(t,n.expected_execution_id),{status:200,body:await l(async()=>{const i=await f(t),a={kind:i.kind,mode:i.mode,lifecycle:i.lifecycle},c=i.persona_ack,d=c===void 0?a:{kind:c.kind??i.kind,mode:c.mode,lifecycle:c.lifecycle};return!B(a,n.to)||!B(d,n.from)?{applied:!1}:(await g(t,{persona_ack:n.to}),{applied:!0})})}}r(Pe,"handlePersonaAck");const nt=oe([{method:"POST",pattern:"/v1/nodes/:id/broker/session-bound",handler:ye},{method:"POST",pattern:"/v1/nodes/:id/broker/settle",handler:_e},{method:"POST",pattern:"/v1/nodes/:id/broker/park-complete",handler:ke},{method:"POST",pattern:"/v1/nodes/:id/broker/park-activity",handler:be},{method:"POST",pattern:"/v1/nodes/:id/broker/telemetry",handler:ge},{method:"POST",pattern:"/v1/nodes/:id/broker/model",handler:ve},{method:"GET",pattern:"/v1/nodes/:id/broker/extension-state",handler:xe},{method:"POST",pattern:"/v1/nodes/:id/broker/generated-name",handler:Se},{method:"POST",pattern:"/v1/nodes/:id/broker/persona-ack",handler:Pe}]);export{nt as brokerOperationRoutes,k as extensionNode};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type RouteTable } from '../router.js';
|
|
2
|
-
export declare function requireCurrentExecution(nodeId: string, expectedExecutionId: unknown): void
|
|
2
|
+
export declare function requireCurrentExecution(nodeId: string, expectedExecutionId: unknown): Promise<void>;
|
|
3
3
|
export declare const brokerRecoveryRoutes: RouteTable;
|
|
4
4
|
export declare const nodeFaultRoutes: RouteTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var k=Object.defineProperty;var o=(r,e)=>k(r,"name",{value:e,configurable:!0});import{ApiError as E}from"../../../api/errors.js";import{getNode as I}from"../../../core/canvas/canvas.js";import{liveExecutionForNode as S}from"../../../core/canvas/executions.js";import{admitEpisode as T,clearEpisode as q,clearFault as m,closeTurn as P,invalidateEpisode as R,openTurn as h,parseProviderError as F,readEpisode as A,readFault as l,recordFault as v,recordPendingEpisode as N,recordTransportPoisonVerdict as O,recordTurnProgress as j,reopenEpisode as L}from"../../../core/canvas/recovery.js";import{notFound as D,usage as n}from"../../../core/errors.js";import{hasPresentedViewer as B}from"../viewer-presence.js";import{ownerOnly as b}from"../router.js";const f=new Set(["pi\u2192provider","viewer\u2194broker","relay\u2194broker","viewer\u2194crtrd","daemon\u2192node","crtr\u2192pi"]),$=new Set(["rate-limit","overloaded","connection","auth","protocol","context-overflow","other","wedged","model-not-found"]),C=new Set(["auto","manual","fatal"]),K=new Set(["sdk","daemon","client"]);function d(r,e){if(typeof r!="object"||r===null||Array.isArray(r))throw n(`${e} requires a JSON object`);return r}o(d,"objectBody");async function a(r){if(await I(r)===null)throw D(`unknown node: ${r}`,{received:r})}o(a,"requireNode");async function c(r,e){if(typeof e!="string"||e==="")throw n("expected_execution_id must be a non-empty string");const t=await S(r);if(t===null||t.executionId!==e)throw new E(409,"stale_execution","broker execution is no longer current")}o(c,"requireCurrentExecution");function g(r){if(typeof r!="object"||r===null||Array.isArray(r))throw n("retry must be an object");const e=r;if(!C.has(e.disposition))throw n("retry.disposition must be auto, manual, or fatal");if(e.by!==void 0&&!K.has(e.by))throw n("retry.by must be sdk, daemon, or client");for(const t of["attempt","max"])if(e[t]!==void 0&&(!Number.isSafeInteger(e[t])||e[t]<0))throw n(`retry.${t} must be a non-negative safe integer`);if(e.nextAt!==void 0&&typeof e.nextAt!="string")throw n("retry.nextAt must be a string");return e}o(g,"parseRetry");function _(r){const e=d(r,"fault input");if(!f.has(e.link))throw n("fault link is invalid");if(typeof e.op!="string"||e.op==="")throw n("fault op must be a non-empty string");if(!$.has(e.kind))throw n("fault kind is invalid");if(typeof e.message!="string")throw n("fault message must be a string");if(e.operation_id!==void 0&&(typeof e.operation_id!="string"||e.operation_id===""))throw n("operation_id must be a non-empty string");if(e.since!==void 0&&typeof e.since!="string")throw n("since must be a string");if(e.anchor_entry_id!==void 0&&(typeof e.anchor_entry_id!="string"||e.anchor_entry_id===""))throw n("anchor_entry_id must be a non-empty string");const t=e.provider_error===void 0?void 0:F(e.provider_error);if(e.provider_error!==void 0&&t===void 0)throw n("provider_error is invalid");return{...e,...t===void 0?{}:{provider_error:t},retry:g(e.retry)}}o(_,"parseFaultInput");function y(r){return{link:r.link,op:r.op,kind:r.kind,retry:r.retry,message:r.message,...r.operation_id===void 0?{}:{operation_id:r.operation_id},...r.since===void 0?{}:{since:r.since},...r.anchor_entry_id===void 0?{}:{anchorEntryId:r.anchor_entry_id},...r.provider_error===void 0?{}:{providerError:r.provider_error}}}o(y,"faultInput");function u(r){return{fault_id:r.faultId,link:r.link,op:r.op,kind:r.kind,retry:r.retry,message:r.message,since:r.since,operation_id:r.operation_id,...r.anchorEntryId===void 0?{}:{anchor_entry_id:r.anchorEntryId},...r.providerError===void 0?{}:{provider_error:r.providerError}}}o(u,"faultDto");async function x(r){const e=await l(r),t=await A(r);return{fault:e===null?null:u(e),episode:t===null?null:{state:t.state,session_id:t.sessionId,fault:u(t.fault)}}}o(x,"recoveryState");function U(r){const e=d(r,"broker turn"),t=e.event;if(t!=="started"&&t!=="progress"&&t!=="closed"&&t!=="interrupted"&&t!=="exit-diagnostic")throw n("event is invalid");if(typeof e.expected_execution_id!="string"||e.expected_execution_id==="")throw n("expected_execution_id must be a non-empty string");if(t==="closed"){if(e.end_reason!=="settled"&&e.end_reason!=="teardown-aborted")throw n("closed turn requires end_reason settled or teardown-aborted")}else if(e.end_reason!==void 0)throw n("end_reason is valid only for closed turns");if(t==="exit-diagnostic"){const i=d(e.exit_diagnostic,"exit_diagnostic"),s=d(i.transport_poison,"exit_diagnostic.transport_poison");if(i.schema!=="crtr.execution-exit-diagnostic/v1"||!Number.isSafeInteger(s.consecutive_passes)||s.consecutive_passes<1||!Array.isArray(s.routes)||s.routes.length===0||!s.routes.every(p=>typeof p=="string"&&p!==""))throw n("exit_diagnostic is invalid")}else if(e.exit_diagnostic!==void 0)throw n("exit_diagnostic is valid only for exit-diagnostic turns");return e}o(U,"parseTurn");async function V(r){const e=r.params.id;await a(e);const t=U(r.body);await c(e,t.expected_execution_id);let i;switch(t.event){case"started":i=await h(t.expected_execution_id,{reason:"agent-start"});break;case"interrupted":i=await h(t.expected_execution_id,{reason:"prompt-unsettled"});break;case"progress":i=await j(t.expected_execution_id);break;case"closed":i=await P(t.expected_execution_id,{endReason:t.end_reason,viewerPresent:B(e)});break;case"exit-diagnostic":{const w=t.exit_diagnostic.transport_poison;i=await O(t.expected_execution_id,{consecutivePasses:w.consecutive_passes,routes:w.routes});break}}const s=(await l(e))?.link;return{status:200,body:{applied:i,fault_link:s==="daemon\u2192node"||s==="pi\u2192provider"?s:null}}}o(V,"handleTurn");function Y(r){const e=d(r,"provider retry");if(typeof e.expected_execution_id!="string"||e.expected_execution_id==="")throw n("expected_execution_id must be a non-empty string");if(!["record-pending","admit","reopen","invalidate","clear"].includes(e.op))throw n("provider retry op is invalid");if(typeof e.session_id!="string"||e.session_id==="")throw n("session_id must be a non-empty string");if(e.op==="record-pending"&&(e.input=_(e.input)),e.op==="admit"){if(typeof e.fault_id!="string"||e.fault_id==="")throw n("admit requires fault_id");e.retry=g(e.retry)}return e}o(Y,"parseProviderRetry");async function G(r){const e=r.params.id;await a(e);const t=Y(r.body);await c(e,t.expected_execution_id);let i;switch(t.op){case"record-pending":i=await N(e,{sessionId:t.session_id,input:y(t.input)})!==null;break;case"admit":i=await T(e,{sessionId:t.session_id,faultId:t.fault_id,retry:t.retry});break;case"reopen":i=await L(e,{sessionId:t.session_id});break;case"invalidate":i=await R(e,{sessionId:t.session_id});break;case"clear":i=await q(e,{sessionId:t.session_id});break}return{status:200,body:{applied:i,episode:(await x(e)).episode}}}o(G,"handleProviderRetry");function J(r){const e=d(r,"broker fault");if(typeof e.expected_execution_id!="string"||e.expected_execution_id==="")throw n("expected_execution_id must be a non-empty string");if(e.op!=="record"&&e.op!=="clear")throw n("fault op must be record or clear");if(e.op==="record"&&(e.input=_(e.input)),e.op==="clear"&&e.link!==void 0&&!f.has(e.link))throw n("fault link is invalid");if(e.preserve_episode!==void 0&&typeof e.preserve_episode!="boolean")throw n("preserve_episode must be boolean");return e}o(J,"parseBrokerFault");async function W(r){const e=r.params.id;await a(e);const t=J(r.body);await c(e,t.expected_execution_id);const i=t.op==="record"?await v(e,y(t.input)):(await m(e,{...t.link===void 0?{}:{link:t.link},...t.preserve_episode===void 0?{}:{preserveEpisode:t.preserve_episode}}),await l(e));return{status:200,body:{fault:i===null?null:u(i)}}}o(W,"handleBrokerFault");async function z(r){const e=r.params.id;return await a(e),await c(e,r.query.get("expected_execution_id")),{status:200,body:await x(e)}}o(z,"handleRecovery");async function H(r){const e=r.params.id;await a(e);const t=await v(e,y(_(r.body)));return{status:200,body:{fault:t===null?null:u(t)}}}o(H,"handleNodeFaultRecord");async function M(r){const e=r.params.id;await a(e);const t=r.query.get("link");if(t!==null&&!f.has(t))throw n("fault link is invalid");const i=r.query.get("preserve_episode");if(i!==null&&i!=="true"&&i!=="false")throw n("preserve_episode must be true or false");return{status:200,body:{cleared:await m(e,{...t===null?{}:{link:t},...i===null?{}:{preserveEpisode:i==="true"}})}}}o(M,"handleNodeFaultClear");const oe=b([{method:"POST",pattern:"/v1/broker/:id/turn",handler:V},{method:"POST",pattern:"/v1/broker/:id/provider-retry",handler:G},{method:"POST",pattern:"/v1/broker/:id/fault",handler:W},{method:"GET",pattern:"/v1/broker/:id/recovery",handler:z}]),se=b([{method:"POST",pattern:"/v1/nodes/:id/fault",handler:H},{method:"DELETE",pattern:"/v1/nodes/:id/fault",handler:M}]);export{oe as brokerRecoveryRoutes,se as nodeFaultRoutes,c as requireCurrentExecution};
|
|
@@ -9,10 +9,10 @@ export declare class BrokerSignalStreams {
|
|
|
9
9
|
pingMs: number;
|
|
10
10
|
blockedMs: number;
|
|
11
11
|
});
|
|
12
|
-
open(nodeId: string, res: ServerResponse, hello: BrokerSignalLineDTO, req: RequestContext['req']): void
|
|
12
|
+
open(nodeId: string, res: ServerResponse, hello: BrokerSignalLineDTO, req: RequestContext['req']): Promise<void>;
|
|
13
13
|
/** Hint the node's broker to re-run its retry scheduling. False when no
|
|
14
14
|
* broker stream is open (it resyncs on reconnect instead). */
|
|
15
|
-
nudgeFaultRetry(nodeId: string): boolean
|
|
15
|
+
nudgeFaultRetry(nodeId: string): Promise<boolean>;
|
|
16
16
|
close(): void;
|
|
17
17
|
}
|
|
18
18
|
export declare const brokerSignalStreams: BrokerSignalStreams;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var D=Object.defineProperty;var r=(
|
|
2
|
-
`)||(
|
|
1
|
+
var D=Object.defineProperty;var r=(c,e)=>D(c,"name",{value:e,configurable:!0});import{ApiError as M}from"../../../api/errors.js";import{getNode as y}from"../../../core/canvas/canvas.js";import{brokerSignalBus as E}from"../../broker-signals/bus.js";import{boundDaemonControl as T}from"../../control.js";import{requireCurrentExecution as v}from"./broker-recovery.js";import{extensionNode as _}from"./broker-ops.js";const R=15e3,C=3e4;class N{static{r(this,"BrokerSignalStreams")}timing;streams=new Map;constructor(e={pingMs:R,blockedMs:C}){this.timing=e}async open(e,t,u,d){this.streams.get(e)?.close();let n=!1,i=!1,h=!1,w=!1,g=!1,s,m,b;const a=r((o=!1)=>{n||(n=!0,m!==void 0&&clearInterval(m),s!==void 0&&clearTimeout(s),t.off("drain",k),t.off("close",l),t.off("error",l),d.off("aborted",l),b?.(),this.streams.get(e)===S&&this.streams.delete(e),o?t.destroy():t.writableEnded||t.end())},"close"),f=r(o=>{n||i||t.write(`${JSON.stringify(o)}
|
|
2
|
+
`)||(i=!0,s=setTimeout(()=>a(!0),this.timing.blockedMs),s.unref())},"send"),p=r(async()=>{if(!(n||i)&&(h&&(h=!1,f({type:"mail",channel:"wake",at:Date.now()})),g&&!i&&(g=!1,f({type:"fault-retry",at:Date.now()})),w&&!i)){w=!1;const o=await y(e);o!==null&&f({type:"node",node:await _(o),at:Date.now()})}},"flush"),k=r(()=>{i=!1,s!==void 0&&clearTimeout(s),s=void 0,p().catch(()=>a())},"drain"),l=r(()=>a(),"onClosed"),S={close:a,nudgeFaultRetry:r(async()=>{if(!n){g=!0;try{await p()}catch{a()}}},"nudgeFaultRetry")};this.streams.set(e,S),t.on("drain",k),t.once("close",l),t.once("error",l),b=await E.subscribe((o,x)=>{o!==e||n||(x==="mail"?h=!0:w=!0,p().catch(()=>a()))}),m=setInterval(()=>{if(!(i||n))try{f({type:"ping",at:Date.now()})}catch{a()}},this.timing.pingMs),m.unref(),d.once("aborted",l);try{f(u),await p()}catch{a()}}async nudgeFaultRetry(e){const t=this.streams.get(e);return t===void 0?!1:(await t.nudgeFaultRetry(),!0)}close(){for(const e of[...this.streams.values()])e.close()}}const B=new N;async function F(c){const e=c.params.id??"",t=await y(e);if(t===null)throw new M(404,"node_not_found",`no node ${e}`);const u=c.query.get("execution_id");await v(e,u);const{req:d,res:n}=c;n.writeHead(200,{"content-type":"application/x-ndjson; charset=utf-8","cache-control":"no-cache",connection:"keep-alive"});try{await B.open(e,n,{type:"hello",epoch:T()?.epoch??"",execution_id:u,node:await _(await y(e)??t),at:Date.now()},d)}catch{n.writableEnded||n.end()}return{status:200}}r(F,"handleSignals");const J=[{method:"GET",pattern:"/v1/nodes/:id/broker/signals",handler:F}];export{N as BrokerSignalStreams,J as brokerSignalRoutes,B as brokerSignalStreams};
|
|
@@ -3,5 +3,5 @@ import { type HandlerResult, type RequestContext, type RouteTable } from '../rou
|
|
|
3
3
|
* application/gzip, not HTTP content-encoding: the local socket fetch returns a
|
|
4
4
|
* byte stream without automatic decompression. Build from selected columns so
|
|
5
5
|
* the daemon does not materialize or serialize outcome/activity/placement. */
|
|
6
|
-
export declare function handleBrowse(ctx: RequestContext): HandlerResult
|
|
6
|
+
export declare function handleBrowse(ctx: RequestContext): Promise<HandlerResult>;
|
|
7
7
|
export declare const canvasRoutes: RouteTable;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
`);if(e.length>0){const c=
|
|
3
|
-
`).forEach((u,g)=>{
|
|
1
|
+
var X=Object.defineProperty;var l=(t,e)=>X(t,"name",{value:e,configurable:!0});import{gzipSync as Z}from"node:zlib";import{browseNodes as F,graphNodes as ee,listNodes as G,pruneNodes as te,pruneToLimit as ne,rosterEdges as S,rosterNodes as se}from"../../../core/canvas/canvas.js";import{liveObjectWaitsNamed as oe,readControllerWait as re}from"../../../core/canvas/waits.js";import{activeBackgroundBashJobs as ae}from"../../../core/bash-jobs.js";import{contextDir as ie}from"../../../core/canvas/node-agent-paths.js";import{nowIso as I}from"../../../core/fs-utils.js";import{isPidPresent as de}from"../../../core/canvas/pid.js";import{dashboardRowsAllFromSource as le,enrichRowsFromSource as ce}from"../../../core/canvas/render-source.js";import{localCanvasSource as D}from"../../../core/canvas/source.js";import{ticketCountsForNodes as q,ticketsAcrossCanvas as ue}from"../../../core/canvas/attention.js";import{buildCorpus as fe,groupCorpus as pe,resolveRef as me}from"../../../core/canvas/history.js";import{listFocuses as H,reapEmptyNodes as _e}from"../../../core/runtime/placement.js";import{boundFleet as ye}from"../../../core/runtime/fleet.js";import{retentionHold as he}from"../../reconcilers/live-obligation.js";import{notFound as be,usage as _}from"../../../core/errors.js";import{openDb as ge}from"../../../core/canvas/db.js";import{view as ve}from"../../../core/canvas/tree.js";import{isLiveStatus as we}from"../../../core/canvas/node-order.js";import{readNodeRecap as ke}from"../../../core/canvas/node-recap.js";import{readGoal as Se}from"../../../core/runtime/kickoff.js";import{faultSummary as Ne}from"../../../core/canvas/status-glyph.js";import{listPendingAsks as Re}from"../../../core/human/requests.js";import{toGraphNodeDTO as Ce}from"../map.js";import{actsAsPerson as je,canReadNode as A,canReadRun as Ie}from"../router.js";import{ApiError as T}from"../../../api/errors.js";import{filterAsync as $,mapAsync as x}from"../../../core/async-array.js";async function N(t){return t.principal.class==="person"?null:new Set((await $(await G(),async e=>await A(t.principal,e.grantee??"app:terminal",e.node_id))).map(e=>e.node_id))}l(N,"visibleNodes");async function z(t){return t.principal.class==="person"?null:new Set((await $(await G(),async e=>e.run_id?await Ie(t.principal,e.grantee??"app:terminal",e.node_id):await A(t.principal,e.grantee??"app:terminal",e.node_id))).map(e=>e.node_id))}l(z,"visibleHistoryNodes");async function Me(t){const e=await N(t);return{status:200,body:{items:(await ue()).filter(n=>e===null||e.has(n.node_id)).map(n=>({node_id:n.node_id,name:n.name,cwd:n.cwd,count:n.count,subjects:n.subjects}))}}}l(Me,"handleAttention");async function Le(t){const e=t.body;if(e===null||typeof e!="object"||!Array.isArray(e.node_ids))throw _("attention count request requires node_ids: string[]");const r=e.node_ids;if(!r.every(o=>typeof o=="string"))throw _("attention count request node_ids must contain only strings");const n=await N(t);return{status:200,body:{counts:await q(r.filter(o=>n===null||n.has(o)))}}}l(Le,"handleAttentionCounts");function J(t){return Buffer.from(String(t),"utf8").toString("base64")}l(J,"encodeCursor");function K(t){const e=Number(Buffer.from(t,"base64").toString("utf8"));if(!Number.isInteger(e)||e<0)throw _(`invalid cursor: ${t}`);return e}l(K,"decodeCursor");function Oe(t,e,r){const i=t.loadBody().split(`
|
|
2
|
+
`);if(e.length>0){const c=i.findIndex(p=>{const f=p.toLowerCase();return e.some(y=>f.includes(y))});if(c!==-1)return i.slice(c,c+r).map(p=>p.trim()).filter(p=>p!=="").join(" \u23CE ")}const o=i.map(c=>c.trim()).filter(c=>c!=="").slice(0,r).join(" \u23CE ");return o!==""?o:t.title}l(Oe,"snippet");function Ee(t,e,r){const n=[...t];return e==="relevance"&&r!==void 0?n.sort((i,o)=>(r.get(o.ref)??0)-(r.get(i.ref)??0)||o.tsMs-i.tsMs||i.ref.localeCompare(o.ref)):e==="oldest"?n.sort((i,o)=>i.tsMs-o.tsMs||i.ref.localeCompare(o.ref)):n.sort((i,o)=>o.tsMs-i.tsMs||i.ref.localeCompare(o.ref)),n}l(Ee,"sortArtifacts");function Ae(t){if(t==null)return{};if(typeof t!="object")throw _("history search body must be a JSON object");return t}l(Ae,"parseSearchBody");function Te(t){if(t===null||typeof t!="object")throw _("history grep body must be a JSON object");const e=t;if(typeof e.pattern!="string"||e.pattern==="")throw _("history grep body requires a non-empty pattern");return e}l(Te,"parseGrepBody");async function B(t,e){const r={cwd:t.cwd,allCwds:t.all_cwds===!0,under:t.under,nodes:t.nodes},n={types:t.types,kinds:t.kinds,statuses:t.statuses,sinceMs:t.since_ms,untilMs:t.until_ms,origins:t.origins,roles:t.roles,from:t.from},i=await z(e);return(await fe(r,n)).filter(o=>i===null||i.has(o.nodeId))}l(B,"buildCorpusFromQuery");function $e(t){if(t==null)return{};if(typeof t!="object")throw _("history stats body must be a JSON object");return t}l($e,"parseStatsBody");const W=["origin","node","kind","day","type","role"];async function Be(t){const e=$e(t.body),r=e.group_by??"type";if(!W.includes(r))throw _(`--group-by must be one of: ${W.join(", ")}; received: ${String(e.group_by)}`);const n=await B(e,t),i=pe(n,r);return{status:200,body:{group_by:r,groups:i,total:i.reduce((c,p)=>c+p.count,0),scanned:n.length}}}l(Be,"handleHistoryStats");async function Pe(t){const e=Te(t.body),r=Math.min(100,Math.max(1,e.limit??20)),n=await B(e,t),i=e.cursor!==void 0?K(e.cursor):0;let o;try{o=new RegExp(e.pattern,"i")}catch{throw _(`invalid regex pattern: ${e.pattern}`)}const c=[];for(const a of n)a.loadBody().split(`
|
|
3
|
+
`).forEach((u,g)=>{o.test(u)&&c.push({ref:a.ref,node:`${a.nodeName} (${a.nodeId})`,ts:a.ts,line:g+1,text:u.trim()})});c.sort((a,s)=>a.ref.localeCompare(s.ref)||a.line-s.line);const p=c.slice(i,i+r),f=i+r<c.length?J(i+r):null;return{status:200,body:{hits:p,next_cursor:f,total:c.length}}}l(Pe,"handleHistoryGrep");async function Fe(t){const e=Ae(t.body),r=(e.query??"").trim(),n=e.weigh_body===!0,i=e.full===!0,o=Math.max(1,e.snippet_lines??1),c=Math.min(100,Math.max(1,e.limit??20)),p=e.per_node===!0;if(p&&(e.nodes===void 0||e.nodes.length===0))throw new T(400,"invalid_request","`per_node` requires a non-empty `nodes` list",{param:"nodes"});const f=await B(e,t),y=e.cursor!==void 0?K(e.cursor):0,a=r.toLowerCase().split(/\s+/).filter(d=>d.length>0);let s=f,u;const g=e.sort??(a.length>0?"relevance":"recency");if(a.length>0&&g==="relevance"){u=new Map;const d=[];for(const m of f){const E=m.title.toLowerCase(),Y=m.nodeName.toLowerCase(),V=m.nodeDesc.toLowerCase(),P=n?m.loadBody().toLowerCase():null;let k=0;for(const j of a)E.includes(j)&&(k+=10),Y.includes(j)&&(k+=5),V.includes(j)&&(k+=3),P!==null&&P.includes(j)&&(k+=1);k>0&&(u.set(m.ref,k),d.push(m))}s=d}else a.length>0&&(s=f.filter(d=>{const m=`${d.title}
|
|
4
4
|
${d.nodeName}
|
|
5
5
|
${d.nodeDesc}${n?`
|
|
6
|
-
`+d.loadBody():""}`.toLowerCase();return
|
|
6
|
+
`+d.loadBody():""}`.toLowerCase();return a.some(E=>m.includes(E))}));let b=Ee(s,g,u);if(p){const d=new Set;b=b.filter(m=>!d.has(m.nodeId)&&d.add(m.nodeId))}const v=p?b:b.slice(y,y+c),h=!p&&y+c<b.length?J(y+c):null;return{status:200,body:{hits:v.map(d=>{const m={ref:d.ref,node:`${d.nodeName} (${d.nodeId})`,kind:d.nodeKind,source:d.source,ts:d.ts,...p?{node_id:d.nodeId}:{}};return g==="relevance"&&u!==void 0&&(m.score=u.get(d.ref)??0),i?m.body=d.loadBody():m.snippet=Oe(d,a,o),m}),next_cursor:h,total:b.length}}}l(Fe,"handleHistorySearch");async function Ge(t){const e=(t.query.get("ref")??"").trim();if(!e.includes(":"))throw _(`ref must be <node-id>:inbox/<n>, <node-id>:session, or <node-id>:session/<n>; received: ${e}`,{received:e,next:"Get a valid ref from `crtr canvas history search`. Reports and documents are `crtr canvas read <name>`."});const r=await me(e);if(r===null)throw be(`no inbox entry or message for ref: ${e}`,{ref:e,next:"Re-run `crtr canvas history search` for a current ref. Reports and documents are `crtr canvas read <name>`."});if((await z(t))?.has(r.nodeId)===!1)throw new T(404,"not_found","artifact not found");const n=r.source,o=t.query.get("format")==="raw"&&r.raw!==null?r.raw:r.body;return{status:200,body:{ref:e,node:`${r.nodeName} (${r.nodeId})`,source:n,ts:r.ts,content:o}}}l(Ge,"handleHistoryRead");function De(t){for(const[n]of t.query)if(n!=="live")throw _(`unknown snapshot query parameter: ${n}`);const e=t.query.getAll("live");if(e.length>1)throw _("live must appear at most once");const r=e[0];if(r===void 0||r==="false"||r==="0")return!1;if(r==="true"||r==="1")return!0;throw _("live must be true or false")}l(De,"snapshotLiveOnly");async function qe(t){const e=new Set((await H()).map(a=>a.node_id)),r=await N(t),n=(await le(D,e,De(t))).filter(a=>r===null||r.has(a.node_id)),i=await q(n.map(a=>a.node_id));await ce(D,n,i);const o=await x(n,async a=>{const s=a.srcRow,u=s?.host_kind??"tmux";return{node_id:a.node_id,name:a.name,title:a.handle??a.name,description:a.description??null,kind:a.kind,mode:a.mode,lifecycle:a.lifecycle??s?.lifecycle,status:a.status,cwd:a.cwd,profile_id:a.profile_id??null,parent:s?.parent??null,created:a.created,host_kind:u,enterable:u==="broker",attention_count:a.asks,...s?.cycles!=null?{cycles:s.cycles}:{},...a.mtimeMs!==void 0?{last_activity:new Date(a.mtimeMs).toISOString()}:{},ctx_tokens:a.ctx_tokens,streaming:a.streaming??!1,jobs_active:s!==void 0&&de(s.pi_pid)?ae(await ie(a.node_id)).length:0,waiting_for:(await re(a.node_id))?.controllerId??null,hanging:a.hanging??null,viewed:a.viewed??!1,final_report:s?.final_report??null,finalized_at:s?.finalized_at??null}}),c=new Map;for(const a of await S()){const s=c.get(a.from_id);s===void 0?c.set(a.from_id,[a.to_id]):s.push(a.to_id)}const p=new Set(n.map(a=>a.node_id)),f=Object.fromEntries(n.map(a=>[a.node_id,(c.get(a.node_id)??[]).filter(s=>p.has(s))]));return{status:200,body:{generated_at:I(),nodes:o,subscriptions:f}}}l(qe,"handleSnapshot");async function U(){const t=(await se()).map(n=>{const i=n.host_kind??"tmux";return{node_id:n.node_id,name:n.name,kind:n.kind,mode:n.mode,lifecycle:n.lifecycle,status:n.status,cwd:n.cwd,host_kind:i,enterable:i==="broker",parent:n.parent,created:n.created}}),e=(await S()).map(n=>({from_id:n.from_id,to_id:n.to_id,active:n.active,created:n.created})),r=(await oe()).map(n=>({node_id:n.nodeId,object_id:n.objectId,object_type:n.objectType,object_name:n.objectName,created:new Date(n.createdAt).toISOString()}));return{generated_at:I(),nodes:t,edges:e,object_waits:r}}l(U,"buildRoster");let R=null,M=null;function He(){return R===null?(R=Promise.resolve().then(async()=>await U()).finally(()=>{R=null}),R):(M===null&&(M=R.then(async()=>await U()).finally(()=>{M=null})),M)}l(He,"rosterCoalesced");async function xe(t){const e=await He(),r=await N(t);return r===null?{status:200,body:e}:{status:200,body:{...e,nodes:e.nodes.filter(n=>r.has(n.node_id)),edges:e.edges.filter(n=>r.has(n.from_id)&&r.has(n.to_id)),object_waits:(e.object_waits??[]).filter(n=>r.has(n.node_id))}}}l(xe,"handleRoster");function Q(t){if(t.name!==""&&t.name!==t.kind)return t.name;const e=(t.description??"").trim();return e!==""?e:t.name}l(Q,"liveRootName");const ze=1440*6e4;async function Je(){const t=await F(),e=new Map(t.map(s=>[s.node_id,s])),r=new Map((await(await ge()).prepare("SELECT node_id, reply_at, read_at, intent FROM nodes WHERE parent IS NULL").all()).map(s=>[s.node_id,s])),n=await Re(),i=new Map;for(const s of n)i.set(s.requester_node_id,(i.get(s.requester_node_id)??0)+1);const o=new Date(Date.now()-ze).toISOString(),c=l(s=>{const u=r.get(s.node_id);return u?.reply_at!=null&&(u.read_at==null||u.reply_at>u.read_at)||(i.get(s.node_id)??0)>0?!0:s.status!=="done"||u?.intent!=="parked"?!1:[s.created,s.telemetry_updated_at,u.reply_at].reduce((v,h)=>h!=null&&h>v?h:v,"")>=o},"keepFinished"),p=t.filter(s=>s.parent===null&&s.kind!=="human"&&(we(s.status)||c(s))),f=new Map;for(const s of await S())f.set(s.from_id,[...f.get(s.from_id)??[],s.to_id]);const y=l(s=>{const u=e.get(s)?.fault;return u&&u.link!=="broker\u2194crtrd"?Ne(u):null},"faultOf"),a=await x(p,async s=>{const u=[s.node_id,...await ve(s.node_id)].filter(d=>e.get(d)?.kind!=="human"&&e.has(d)),g=new Set(u),b=n.filter(d=>g.has(d.requester_node_id)),v=r.get(s.node_id),h=v?.reply_at??null,O=v?.read_at??null;let w=s.created;for(const d of u){const m=e.get(d).telemetry_updated_at;m!=null&&m>w&&(w=m)}return h!==null&&h>w&&(w=h),{node_id:s.node_id,name:Q(s),cwd:s.cwd,profile_id:s.profile_id,status:s.status,state_line:(()=>{const d=ke(s.node_id)?.state.trim();return d||null})(),goal:(await Se(s.node_id))?.trim()||null,asks:b.length,first_ask_ticket_id:b[0]?.inbox_ticket_id??null,fault:u.map(y).find(d=>d!==null)??null,running_count:u.filter(d=>e.get(d).streaming===!0).length,unread:h!==null&&(O===null||h>O),last_activity:w,children:(f.get(s.node_id)??[]).filter(d=>e.has(d)&&e.get(d).kind!=="human").map(d=>{const m=e.get(d);return{node_id:d,name:Q(m),status:m.status,streaming:m.streaming===!0,asks:i.get(d)??0,fault:y(d)}})}});return{generated_at:I(),rows:a}}l(Je,"buildLiveRoots");let C=null,L=null;function Ke(){const t=l(()=>Promise.resolve().then(Je),"run");return C===null?(C=t().finally(()=>{C=null}),C):(L===null&&(L=C.then(t).finally(()=>{L=null})),L)}l(Ke,"liveRootsCoalesced");async function We(t){if(!je(t.principal))throw new T(403,"permission_error","only the person reads the dashboard");const e=await Ke(),r=t.query.get("profile");return{status:200,body:r===null?e:{...e,rows:e.rows.filter(n=>n.profile_id===r)}}}l(We,"handleLiveRoots");async function Ue(t){const e=(await $(await F(),async o=>t.principal.class==="person"||await A(t.principal,o.grantee??"app:terminal",o.node_id))).map(o=>({node_id:o.node_id,name:o.name,description:o.description,kind:o.kind,mode:o.mode,lifecycle:o.lifecycle,status:o.status,cwd:o.cwd,profile_id:o.profile_id,grantee:o.grantee??"app:terminal",parent:o.parent,created:o.created,frozen_at:o.frozen_at??null,terminal_reason:o.terminal_reason??null,final_report:o.final_report??null,telemetry_tokens_in:o.telemetry_tokens_in??null,telemetry_updated_at:o.telemetry_updated_at??null,fault:o.fault&&o.fault.link!=="broker\u2194crtrd"?{...o.fault,link:o.fault.link}:null,streaming:o.streaming??!1})),r=new Set(e.map(o=>o.node_id)),n=(await S()).filter(o=>r.has(o.from_id)&&r.has(o.to_id));return{status:200,rawBody:Z(JSON.stringify({nodes:e,edges:n}),{level:1}),headers:{"content-type":"application/gzip"}}}l(Ue,"handleBrowse");async function Qe(t){const e=await N(t);return{status:200,body:{generated_at:I(),nodes:(await ee()).filter(n=>e===null||e.has(n.node_id)).map(Ce),edges:(await S()).filter(n=>e===null||e.has(n.from_id)&&e.has(n.to_id)).map(n=>({from_id:n.from_id,to_id:n.to_id,active:n.active,created:n.created})),focused_node_ids:(await H()).map(n=>n.node_id).filter(n=>e===null||e.has(n))}}}l(Qe,"handleGraph");function Ye(t){if(t==null)return{};if(typeof t!="object")throw _("prune body must be a JSON object");const e=t,r=l(a=>{const s=e[a];if(s!==void 0){if(typeof s!="number"||!Number.isFinite(s))throw _(`${a} must be a number`);return s}},"num"),n=l(a=>{const s=e[a];if(s!==void 0){if(typeof s!="boolean")throw _(`${a} must be a boolean`);return s}},"bool"),i={},o=r("limit");o!==void 0&&(i.limit=o);const c=r("ttl_days");c!==void 0&&(i.ttl_days=c);const p=n("include_stale");p!==void 0&&(i.include_stale=p);const f=n("empty");f!==void 0&&(i.empty=f);const y=n("dry_run");return y!==void 0&&(i.dry_run=y),i}l(Ye,"parsePruneBody");async function Ve(t){const e=Ye(t.body),r=e.ttl_days??14,n=e.dry_run??!1,i=await he(ye());let o;return e.limit!==void 0?o=(await ne({maxNodes:e.limit,held:i,dryRun:n})).pruned.map(f=>({node_id:f.node_id,status:f.status,created:f.created})):e.empty===!0?o=(await _e({dryRun:n})).map(f=>({node_id:f,status:"empty",created:""})):o=(await te({ttlDays:r,held:i,dryRun:n,includeStale:e.include_stale??!1})).pruned.map(f=>({node_id:f.node_id,status:f.status,created:f.created})),{status:200,body:{pruned:o,dry_run:n,ttl_days:r}}}l(Ve,"handlePrune");const Rt=[{method:"GET",pattern:"/v1/canvas/attention",handler:Me},{method:"POST",pattern:"/v1/canvas/attention/counts",handler:Le},{method:"POST",pattern:"/v1/canvas/history/search",handler:Fe},{method:"POST",pattern:"/v1/canvas/history/grep",handler:Pe},{method:"GET",pattern:"/v1/canvas/history/read",handler:Ge},{method:"POST",pattern:"/v1/canvas/history/stats",handler:Be},{method:"GET",pattern:"/v1/canvas/snapshot",handler:qe},{method:"GET",pattern:"/v1/canvas/roster",handler:xe},{method:"GET",pattern:"/v1/canvas/live-roots",handler:We},{method:"GET",pattern:"/v1/canvas/browse",handler:Ue},{method:"GET",pattern:"/v1/canvas/graph",handler:Qe},{method:"POST",pattern:"/v1/canvas/prune",ownerOnly:!0,handler:Ve}];export{Rt as canvasRoutes,Ue as handleBrowse};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var n=Object.defineProperty;var e=(t,o)=>n(t,"name",{value:o,configurable:!0});import{getNode as r}from"../../../core/canvas/canvas.js";import{isSafeNodeId as d}from"../../../core/canvas/paths.js";import{notFound as i,usage as a}from"../../../core/errors.js";import{readChatInventory as m}from"../../../core/runtime/broker-inventory.js";async function s(t){const o=t.params.id;if(!d(o))throw a(`invalid node id: ${o}`,{received:o});if(r(o)===null)throw i(`unknown node: ${o}`,{received:o});return{status:200,body:await m(o)}}e(s,"handleGet");const v=[{method:"GET",pattern:"/v1/nodes/:id/chat-inventory",handler:s}];export{v as chatInventoryRoutes};
|
|
1
|
+
var n=Object.defineProperty;var e=(t,o)=>n(t,"name",{value:o,configurable:!0});import{getNode as r}from"../../../core/canvas/canvas.js";import{isSafeNodeId as d}from"../../../core/canvas/paths.js";import{notFound as i,usage as a}from"../../../core/errors.js";import{readChatInventory as m}from"../../../core/runtime/broker-inventory.js";async function s(t){const o=t.params.id;if(!d(o))throw a(`invalid node id: ${o}`,{received:o});if(await r(o)===null)throw i(`unknown node: ${o}`,{received:o});return{status:200,body:await m(o)}}e(s,"handleGet");const v=[{method:"GET",pattern:"/v1/nodes/:id/chat-inventory",handler:s}];export{v as chatInventoryRoutes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var X=Object.defineProperty;var t=(e,n)=>X(e,"name",{value:n,configurable:!0});import{randomUUID as nn}from"node:crypto";import{relative as en,resolve as B,sep as G}from"node:path";import{ApiError as c}from"../../../api/errors.js";import{armCron as rn,parseCronSink as on,getCron as y,listCrons as T,listCronRuns as F,pokeHeldCrons as tn,setCronState as L}from"../../../core/canvas/crons.js";import{getNode as h}from"../../../core/canvas/canvas.js";import{appSpace as sn,cronFolder as an}from"../../../core/layout.js";import{appProcessesSandboxed as cn,cwdIsMounted as ln}from"../../../core/spaces/process.js";import{activeGrant as dn,activeGrantForApp as un,grantFor as pn,terminalGrant as fn}from"../../../core/grants/mirror.js";import{readConfig as _n}from"../../../core/config.js";import{assertScope as Z}from"../../../core/scopes.js";import{InputError as i}from"../../../core/io.js";import{nextSlotAfter as hn}from"../../../core/wake.js";import{executeCron as mn,markSelfCanceledCronRun as gn}from"../../cron-run.js";import{toCronDTO as k,toCronRunDTO as H}from"../map.js";import{appOf as A,assertCeiling as wn,canReadNode as bn}from"../router.js";import{checkCronBirth as vn,checkCronFire as yn}from"../../cron/authority.js";import{endCron as kn}from"../../cron/ended.js";import{requireUsableProfile as Sn}from"./profiles.js";function E(e,n){const r=e[n];if(typeof r!="string"||r.trim()==="")throw new i({error:"missing_field",message:`cron arm request requires a non-empty "${n}"`,field:n,next:`Send a non-empty string "${n}".`});return r}t(E,"requireString");function C(e,n,r,o){if(e==null)return o;if(typeof e=="string"&&r.includes(e))return e;throw new i({error:`bad_${n}`,message:`"${String(e)}" is not a valid ${n}`,field:n,next:`Use one of: ${r.join(", ")}.`})}t(C,"requireEnum");function $n(e){if(e==="human")return JSON.stringify({human:!0});if(e.startsWith("node:")){const n=e.slice(5).trim();if(n==="")throw new i({error:"bad_sink",message:"node sink requires a node id",field:"sink",next:'Use sink "node:<node-id>".'});if(h(n)===null)throw new i({error:"sink_node_not_found",message:`sink node ${n} does not exist on the canvas`,field:"sink",next:"Name a live node id, or use spawn:<kind> for a delivery that outlives any one node."});return JSON.stringify({node:n})}if(e.startsWith("spawn:")){const n=e.slice(6).trim();if(n==="")throw new i({error:"bad_sink",message:"spawn sink requires a node kind",field:"sink",next:'Use sink "spawn:<kind>" (e.g. spawn:general).'});return JSON.stringify({spawn:n})}throw new i({error:"bad_sink",message:`"${e}" is not a valid sink`,field:"sink",next:"Use node:<node-id>, spawn:<kind>, or human."})}t($n,"parseSinkSpec");const Cn=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;function M(e,n){if(!Cn.test(e)||Number.isNaN(Date.parse(e)))throw new i({error:`bad_${n}`,message:`"${e}" is not a UTC ISO instant`,field:n,next:'Send a resolved UTC instant like "2026-06-07T09:00:00.000Z" (the client resolves the time grammar).'});return e}t(M,"requireUtcIso");function On(e){try{hn(e,new Date)}catch(n){throw new i({error:"bad_recur",message:`recur is not advanceable: ${n instanceof Error?n.message:String(n)}`,field:"recur",next:'Send recur JSON the daemon can advance: {"every":"6h"} or {"cron":"0 9 * * *","tz":"America/New_York"}.'})}return e}t(On,"requireRecur");function In(e){let n;try{n=JSON.parse(e)}catch{throw new i({error:"bad_env_json",message:"env_json is not valid JSON",field:"env_json",next:'Send a JSON object of string values, e.g. {"API_BASE":"https://x"}.'})}if(typeof n!="object"||n===null||Array.isArray(n))throw new i({error:"bad_env_json",message:"env_json must be a JSON object",field:"env_json",next:'Send a JSON object of string values, e.g. {"API_BASE":"https://x"}.'});for(const[r,o]of Object.entries(n))if(typeof o!="string")throw new i({error:"bad_env_json",message:`env_json value for "${r}" is not a string`,field:"env_json",next:"Every env value must be a string."});return e}t(In,"requireEnvJson");function U(e){const n=e.query.get("profile");return n!==null&&n.trim()!==""?n.trim():null}t(U,"callerProfile");function Y(e,n){return n===null||e.scope==="global"||e.profile===n}t(Y,"inScope");function K(e){return e.principal.class==="person"?null:A(e.principal)}t(K,"callerApp");function J(e,n){return bn(e.principal,n.grantee,n.created_by??void 0)}t(J,"visibleTo");function Nn(e){return typeof e.anchor_node=="string"&&e.anchor_node!==""?e.anchor_node:null}t(Nn,"anchorNodeOf");function qn(e,n,r,o,a,u){const l=typeof e.cwd=="string"&&e.cwd.trim()!==""?B(e.cwd):null;if(!cn()){if(l===null)throw new i({error:"missing_field",message:'cron arm request requires a non-empty "cwd"',field:"cwd",next:'Send a non-empty string "cwd".'});return l}const p=o!==null&&h(o)!==null?o:void 0,d=t(N=>ln(n,N,p,a,void 0,u),"reaches");if(l!==null&&d(l))return l;const s=sn(n).files;if(l!==null&&e.cwd_is_default!==!0)throw new c(400,"invalid_request",`cwd ${l} is not inside a directory this app's cron runs can see, so every run would fail to start; use a directory under ${s}`,{cwd:l,default:s},void 0,{param:"cwd"});const m=r===null?null:h(r)?.cwd??null;return m!==null&&d(m)?m:s}t(qn,"resolveArmedCwd");function jn(e,n,r){const o=e.principal;if(o.class==="person"){const s=fn();return{sub:s?.sub??"user:local",grant_id:s?.id??null,scopes:null,origin_run_id:null}}if(o.class==="app"){const s=un(n);if(s===null)throw new c(401,"grant_revoked",`no active grant for ${n}`);const m=e.ceiling??o.scopes;return{sub:s.sub,grant_id:s.id,scopes:[...m??s.resolved],origin_run_id:null}}if(o.class==="cron"){const s=yn({grantee:o.app,sub:o.sub,grant_id:o.grant,scopes:o.scopes});if(!s.allowed)throw new c(s.reason==="scope_missing"?403:401,s.reason==="scope_missing"?"scope_missing":"grant_revoked",s.message);return{sub:o.sub,grant_id:o.grant,scopes:o.scopes===null?[...s.effectiveScopes]:[...o.scopes],origin_run_id:o.origin_run}}if(o.class!=="broker")throw new c(401,"unauthorized","this caller cannot arm a cron");const a=r??h(o.node),u=a?.grant_id??o.grant,l=a?.sub??o.sub,p=u!=null?dn(u):pn(n,l);if(p===null){if(n==="app:terminal"&&!_n("user").runtime?.issuer)return{sub:l,grant_id:u??null,scopes:a?.scopes??o.scopes,origin_run_id:a?.run_id??o.run};throw new c(401,"grant_revoked","the node grant is not active")}const d=a?.scopes??o.scopes;return{sub:p.sub,grant_id:p.id,scopes:d===null?[...p.resolved]:[...d],origin_run_id:a?.run_id??o.run}}t(jn,"armPrincipal");function Pn(e){const n=e.body??{},r=E(n,"name"),o=E(n,"command"),a=M(E(n,"fire_at"),"fire_at"),u=typeof n.recur=="string"&&n.recur!==""?On(n.recur):null,l=typeof n.expires_at=="string"&&n.expires_at!==""?M(n.expires_at,"expires_at"):null,p=typeof n.env_json=="string"&&n.env_json!==""?In(n.env_json):null,d=typeof n.sink=="string"&&n.sink.trim()!==""?n.sink.trim():null,s=C(n.on_output,"on_output",["silent","on-failure","always","on-change"],d?.startsWith("node:")?"on-change":"on-failure"),m=C(n.overlap,"overlap",["skip","queue","replace"],"skip"),N=C(n.tier,"tier",["normal","urgent","critical"],"normal"),D=s==="always"||s==="on-change";if(D&&d===null)throw new i({error:"sink_required",message:`on_output "${s}" delivers stdout every qualifying run \u2014 it needs a sink`,field:"sink",next:"Pass sink node:<node-id> (a living node's inbox), spawn:<kind> (birth a fresh node per delivery), or human (the humanloop inbox)."});if(!D&&d!==null)throw new i({error:"sink_unused",message:`on_output "${s}" never delivers stdout \u2014 a sink would be dead config`,field:"sink",next:'Drop the sink, or use on_output "always"/"on-change" if delivery is the point.'});const Q=d!==null?$n(d):"{}";if(d?.startsWith("spawn:")&&(wn(e.ceiling,"crtr:act"),e.principal.class==="cron")){const _=vn({grantee:e.principal.app,sub:e.principal.sub,grant_id:e.principal.grant,scopes:e.principal.scopes});if(!_.allowed)throw new c(_.reason==="scope_missing"?403:401,_.reason==="scope_missing"?"scope_missing":"grant_revoked",_.message)}const b=A(e.principal)??"app:terminal",v=e.principal.class==="broker"?e.principal.node:e.principal.class==="cron"?null:typeof n.created_by=="string"&&n.created_by!==""?n.created_by:null;if(e.principal.class==="broker"&&n.created_by!=null&&n.created_by!==v)throw new c(403,"permission_error","a broker may only arm a cron as its own node");const g=v===null?null:h(v);if(g!==null){if(g.grantee!==b)throw new i({error:"creator_app_mismatch",message:"creator node belongs to another app",field:"created_by",next:"Use a node of the calling app."});Z(g,"crtr:schedule"),d?.startsWith("spawn:")&&Z(g,"crtr:act")}if(n.isolated!==void 0&&typeof n.isolated!="boolean")throw new c(400,"invalid_request","isolated must be a boolean");if(g?.isolated&&n.isolated===!1)throw new c(403,"isolated_run","a cron created by an isolated node cannot escape isolation");const W=g?.isolated===!0||e.principal.class==="cron"&&e.principal.isolated;if(W&&n.isolated===!1)throw new c(403,"isolated_run","a cron created by an isolated caller cannot escape isolation");const q=W||n.isolated===!0,w=jn(e,b,g),j=nn(),S=q?an(b,j):null;if(S!==null&&n.cwd_is_default!==!0){const _=en(S,typeof n.cwd=="string"&&n.cwd.trim()!==""?B(n.cwd):S);if(_===".."||_.startsWith(`..${G}`)||_.startsWith(G))throw new c(400,"invalid_request","an isolated cron must run in its own cron folder",{param:"cwd"})}const V=S??qn(n,b,v,Nn(n),q,{sub:w.sub,grantId:w.grant_id,scopes:w.scopes}),f=typeof n.anchor_node=="string"&&n.anchor_node!==""?n.anchor_node:null;if(f!==null&&h(f)!==null&&h(f).grantee!==b)throw new i({error:"anchor_app_mismatch",message:"anchor node belongs to another app",field:"anchor_node",next:"Use an anchor of the calling app."});if(f!==null&&h(f)===null)throw new i({error:"anchor_not_found",message:`anchor node ${f} does not exist on the canvas`,field:"anchor_node",next:"Name a live node id, or drop the anchor \u2014 an unanchored cron outlives every node."});const x=n.cancel_on_wake===!0;if(x&&f===null)throw new i({error:"cancel_on_wake_needs_anchor",message:"cancel_on_wake couples the cron to a node's dormancy \u2014 it requires an anchor node",field:"anchor_node",next:"Pass anchor_node with the node whose wake should cancel this cron."});const $=n.run_timeout_s??300;if(typeof $!="number"||!Number.isInteger($)||$<=0)throw new i({error:"bad_run_timeout",message:`run_timeout_s must be a positive integer (got ${String(n.run_timeout_s)})`,field:"run_timeout_s",next:"Send the timeout in whole seconds, e.g. 300."});const P=typeof n.profile=="string"&&n.profile!==""?Sn(e,n.profile).profileId:null,z=C(n.scope,"scope",["profile","global"],P!==null?"profile":"global");if(z==="profile"&&P===null)throw new i({error:"scope_needs_profile",message:'scope "profile" names the profile the cron lists and cancels within \u2014 it requires a profile',field:"profile",next:'Send a profile, or use scope "global" for a canvas-home-wide cron.'});return rn({cron_id:j,name:r,created_by:v,grantee:b,sub:w.sub,grant_id:w.grant_id,scopes:w.scopes,origin_run_id:w.origin_run_id,isolated:q,command:o,fire_at:a,recur:u,tz:typeof n.tz=="string"?n.tz:null,expires_at:l,anchor_node:f,cancel_on_wake:x,cwd:V,env_json:p,profile:P,scope:z,run_timeout_s:$,overlap:m,on_output:s,sink:Q,tier:N}),{status:201,body:k(y(j),null)}}t(Pn,"handleArm");function Tn(e){const n=U(e);return{status:200,body:(n===null?T({all:!0}):[...T({profile:n}),...T({global:!0})].sort((o,a)=>o.fire_at<a.fire_at?-1:o.fire_at>a.fire_at?1:0)).filter(o=>J(e,o)).map(o=>k(o,R(o)))}}t(Tn,"handleList");function R(e){return F(e.cron_id)[0]??null}t(R,"lastRunOf");function O(e){const n=e.params.cronId,r=y(n);if(r===null||!J(e,r))throw new c(404,"cron_not_found",`no cron ${n}`);if(!Y(r,U(e)))throw new c(404,"cron_not_found",`no cron ${n} in this profile \u2014 it is scoped to another profile`);return r}t(O,"requireCron");function I(e,n){const r=K(e);if(r!==null&&n.grantee!==r)throw new c(403,"other_app_run",`cron ${n.cron_id} belongs to another app`);return n}t(I,"requireOwnCron");function An(e){const n=O(e),r=F(n.cron_id);return{status:200,body:{cron:k(n,r[0]??null),runs:r.map(H)}}}t(An,"handleShow");function En(e){const n=I(e,O(e));L(n.cron_id,"paused");const r=y(n.cron_id);return{status:200,body:k(r,R(r))}}t(En,"handlePause");function Un(e){const n=I(e,O(e));L(n.cron_id,"active");const r=y(n.cron_id);return{status:200,body:k(r,R(r))}}t(Un,"handleResume");async function Jn(e){const n=I(e,O(e));if(n.run_state==="running")throw new c(409,"cron_running",`cron ${n.cron_id} has a run in flight \u2014 wait for it to settle`);const r=await mn(n,{outOfBand:!0});if(r===null)throw new c(409,"cron_running",`cron ${n.cron_id} was claimed by a concurrent run \u2014 check \`cron show\` for its result`);return{status:200,body:H(r)}}t(Jn,"handleRun");function Rn(e){const n=new Date().toISOString();return{status:200,body:{unparked:tn(n,K(e)),at:n}}}t(Rn,"handlePoke");function Dn(e,n){const r=e.principal;if(r.class==="cron")return r.cron===n.cron_id?null:{kind:"canceled",by:`cron ${r.cron}`};if(r.class==="broker"){const a=on(n.sink);return a?.kind==="node"&&a.node===r.node?null:{kind:"canceled",by:`node ${r.node}`}}const o=A(r);return{kind:"canceled",by:o===null||o==="app:terminal"?"the person":o}}t(Dn,"cancelNotice");function Wn(e){const n=e.params.cronId,r=y(n);if(r!==null&&!J(e,r))throw new c(404,"cron_not_found",`no cron ${n}`);if(r!==null&&!Y(r,U(e)))throw new c(404,"cron_not_found",`no cron ${n} in this profile \u2014 it is scoped to another profile`);r!==null&&I(e,r);const o=e.query.get("run_id"),a=e.principal.class==="cron"?o===e.principal.execution&&n===e.principal.cron:!0,u=o!==null&&a&&gn(n,o);return r!==null&&kn(r,u?null:Dn(e,r),{preserveRunningProcess:u}),{status:204}}t(Wn,"handleCancel");const se=[{method:"POST",pattern:"/v1/crons",scope:"crtr:schedule",handler:Pn},{method:"GET",pattern:"/v1/crons",handler:Tn},{method:"GET",pattern:"/v1/crons/:cronId",handler:An},{method:"POST",pattern:"/v1/crons/:cronId/pause",scope:"crtr:schedule",handler:En},{method:"POST",pattern:"/v1/crons/:cronId/resume",scope:"crtr:schedule",handler:Un},{method:"POST",pattern:"/v1/crons/poke",scope:"crtr:schedule",handler:Rn},{method:"POST",pattern:"/v1/crons/:cronId/run",scope:"crtr:schedule",handler:Jn},{method:"DELETE",pattern:"/v1/crons/:cronId",scope:"crtr:schedule",handler:Wn}];export{se as cronRoutes};
|
|
1
|
+
var X=Object.defineProperty;var t=(e,n)=>X(e,"name",{value:n,configurable:!0});import{randomUUID as nn}from"node:crypto";import{relative as en,resolve as B,sep as G}from"node:path";import{ApiError as c}from"../../../api/errors.js";import{armCron as rn,parseCronSink as on,getCron as v,listCrons as P,listCronRuns as F,pokeHeldCrons as tn,setCronState as L}from"../../../core/canvas/crons.js";import{getNode as _}from"../../../core/canvas/canvas.js";import{appSpace as sn,cronFolder as an}from"../../../core/layout.js";import{appProcessesSandboxed as cn,cwdIsMounted as ln}from"../../../core/spaces/process.js";import{activeGrant as dn,activeGrantForApp as un,grantFor as pn,terminalGrant as fn}from"../../../core/grants/mirror.js";import{readConfig as wn}from"../../../core/config.js";import{assertScope as Z}from"../../../core/scopes.js";import{InputError as s}from"../../../core/io.js";import{nextSlotAfter as _n}from"../../../core/wake.js";import{executeCron as hn,markSelfCanceledCronRun as mn}from"../../cron-run.js";import{toCronDTO as k,toCronRunDTO as H}from"../map.js";import{appOf as T,assertCeiling as gn,canReadNode as yn}from"../router.js";import{checkCronBirth as bn,checkCronFire as vn}from"../../cron/authority.js";import{endCron as kn}from"../../cron/ended.js";import{requireUsableProfile as Sn}from"./profiles.js";import{filterAsync as $n,mapAsync as Cn}from"../../../core/async-array.js";function E(e,n){const r=e[n];if(typeof r!="string"||r.trim()==="")throw new s({error:"missing_field",message:`cron arm request requires a non-empty "${n}"`,field:n,next:`Send a non-empty string "${n}".`});return r}t(E,"requireString");function C(e,n,r,o){if(e==null)return o;if(typeof e=="string"&&r.includes(e))return e;throw new s({error:`bad_${n}`,message:`"${String(e)}" is not a valid ${n}`,field:n,next:`Use one of: ${r.join(", ")}.`})}t(C,"requireEnum");async function On(e){if(e==="human")return JSON.stringify({human:!0});if(e.startsWith("node:")){const n=e.slice(5).trim();if(n==="")throw new s({error:"bad_sink",message:"node sink requires a node id",field:"sink",next:'Use sink "node:<node-id>".'});if(await _(n)===null)throw new s({error:"sink_node_not_found",message:`sink node ${n} does not exist on the canvas`,field:"sink",next:"Name a live node id, or use spawn:<kind> for a delivery that outlives any one node."});return JSON.stringify({node:n})}if(e.startsWith("spawn:")){const n=e.slice(6).trim();if(n==="")throw new s({error:"bad_sink",message:"spawn sink requires a node kind",field:"sink",next:'Use sink "spawn:<kind>" (e.g. spawn:general).'});return JSON.stringify({spawn:n})}throw new s({error:"bad_sink",message:`"${e}" is not a valid sink`,field:"sink",next:"Use node:<node-id>, spawn:<kind>, or human."})}t(On,"parseSinkSpec");const In=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;function M(e,n){if(!In.test(e)||Number.isNaN(Date.parse(e)))throw new s({error:`bad_${n}`,message:`"${e}" is not a UTC ISO instant`,field:n,next:'Send a resolved UTC instant like "2026-06-07T09:00:00.000Z" (the client resolves the time grammar).'});return e}t(M,"requireUtcIso");function Nn(e){try{_n(e,new Date)}catch(n){throw new s({error:"bad_recur",message:`recur is not advanceable: ${n instanceof Error?n.message:String(n)}`,field:"recur",next:'Send recur JSON the daemon can advance: {"every":"6h"} or {"cron":"0 9 * * *","tz":"America/New_York"}.'})}return e}t(Nn,"requireRecur");function qn(e){let n;try{n=JSON.parse(e)}catch{throw new s({error:"bad_env_json",message:"env_json is not valid JSON",field:"env_json",next:'Send a JSON object of string values, e.g. {"API_BASE":"https://x"}.'})}if(typeof n!="object"||n===null||Array.isArray(n))throw new s({error:"bad_env_json",message:"env_json must be a JSON object",field:"env_json",next:'Send a JSON object of string values, e.g. {"API_BASE":"https://x"}.'});for(const[r,o]of Object.entries(n))if(typeof o!="string")throw new s({error:"bad_env_json",message:`env_json value for "${r}" is not a string`,field:"env_json",next:"Every env value must be a string."});return e}t(qn,"requireEnvJson");function U(e){const n=e.query.get("profile");return n!==null&&n.trim()!==""?n.trim():null}t(U,"callerProfile");function Y(e,n){return n===null||e.scope==="global"||e.profile===n}t(Y,"inScope");function K(e){return e.principal.class==="person"?null:T(e.principal)}t(K,"callerApp");async function J(e,n){return await yn(e.principal,n.grantee,n.created_by??void 0)}t(J,"visibleTo");function jn(e){return typeof e.anchor_node=="string"&&e.anchor_node!==""?e.anchor_node:null}t(jn,"anchorNodeOf");async function An(e,n,r,o,a,u){const l=typeof e.cwd=="string"&&e.cwd.trim()!==""?B(e.cwd):null;if(!cn()){if(l===null)throw new s({error:"missing_field",message:'cron arm request requires a non-empty "cwd"',field:"cwd",next:'Send a non-empty string "cwd".'});return l}const p=o!==null&&await _(o)!==null?o:void 0,d=t(async N=>await ln(n,N,p,a,void 0,u),"reaches");if(l!==null&&await d(l))return l;const i=sn(n).files;if(l!==null&&e.cwd_is_default!==!0)throw new c(400,"invalid_request",`cwd ${l} is not inside a directory this app's cron runs can see, so every run would fail to start; use a directory under ${i}`,{cwd:l,default:i},void 0,{param:"cwd"});const h=r===null?null:(await _(r))?.cwd??null;return h!==null&&await d(h)?h:i}t(An,"resolveArmedCwd");async function Pn(e,n,r){const o=e.principal;if(o.class==="person"){const i=await fn();return{sub:i?.sub??"user:local",grant_id:i?.id??null,scopes:null,origin_run_id:null}}if(o.class==="app"){const i=await un(n);if(i===null)throw new c(401,"grant_revoked",`no active grant for ${n}`);const h=e.ceiling??o.scopes;return{sub:i.sub,grant_id:i.id,scopes:[...h??i.resolved],origin_run_id:null}}if(o.class==="cron"){const i=await vn({grantee:o.app,sub:o.sub,grant_id:o.grant,scopes:o.scopes});if(!i.allowed)throw new c(i.reason==="scope_missing"?403:401,i.reason==="scope_missing"?"scope_missing":"grant_revoked",i.message);return{sub:o.sub,grant_id:o.grant,scopes:o.scopes===null?[...i.effectiveScopes]:[...o.scopes],origin_run_id:o.origin_run}}if(o.class!=="broker")throw new c(401,"unauthorized","this caller cannot arm a cron");const a=r??await _(o.node),u=a?.grant_id??o.grant,l=a?.sub??o.sub,p=u!=null?await dn(u):await pn(n,l);if(p===null){if(n==="app:terminal"&&!wn("user").runtime?.issuer)return{sub:l,grant_id:u??null,scopes:a?.scopes??o.scopes,origin_run_id:a?.run_id??o.run};throw new c(401,"grant_revoked","the node grant is not active")}const d=a?.scopes??o.scopes;return{sub:p.sub,grant_id:p.id,scopes:d===null?[...p.resolved]:[...d],origin_run_id:a?.run_id??o.run}}t(Pn,"armPrincipal");async function Tn(e){const n=e.body??{},r=E(n,"name"),o=E(n,"command"),a=M(E(n,"fire_at"),"fire_at"),u=typeof n.recur=="string"&&n.recur!==""?Nn(n.recur):null,l=typeof n.expires_at=="string"&&n.expires_at!==""?M(n.expires_at,"expires_at"):null,p=typeof n.env_json=="string"&&n.env_json!==""?qn(n.env_json):null,d=typeof n.sink=="string"&&n.sink.trim()!==""?n.sink.trim():null,i=C(n.on_output,"on_output",["silent","on-failure","always","on-change"],d?.startsWith("node:")?"on-change":"on-failure"),h=C(n.overlap,"overlap",["skip","queue","replace"],"skip"),N=C(n.tier,"tier",["normal","urgent","critical"],"normal"),D=i==="always"||i==="on-change";if(D&&d===null)throw new s({error:"sink_required",message:`on_output "${i}" delivers stdout every qualifying run \u2014 it needs a sink`,field:"sink",next:"Pass sink node:<node-id> (a living node's inbox), spawn:<kind> (birth a fresh node per delivery), or human (the humanloop inbox)."});if(!D&&d!==null)throw new s({error:"sink_unused",message:`on_output "${i}" never delivers stdout \u2014 a sink would be dead config`,field:"sink",next:'Drop the sink, or use on_output "always"/"on-change" if delivery is the point.'});const Q=d!==null?await On(d):"{}";if(d?.startsWith("spawn:")&&(gn(e.ceiling,"crtr:act"),e.principal.class==="cron")){const w=await bn({grantee:e.principal.app,sub:e.principal.sub,grant_id:e.principal.grant,scopes:e.principal.scopes});if(!w.allowed)throw new c(w.reason==="scope_missing"?403:401,w.reason==="scope_missing"?"scope_missing":"grant_revoked",w.message)}const y=T(e.principal)??"app:terminal",b=e.principal.class==="broker"?e.principal.node:e.principal.class==="cron"?null:typeof n.created_by=="string"&&n.created_by!==""?n.created_by:null;if(e.principal.class==="broker"&&n.created_by!=null&&n.created_by!==b)throw new c(403,"permission_error","a broker may only arm a cron as its own node");const m=b===null?null:await _(b);if(m!==null){if(m.grantee!==y)throw new s({error:"creator_app_mismatch",message:"creator node belongs to another app",field:"created_by",next:"Use a node of the calling app."});Z(m,"crtr:schedule"),d?.startsWith("spawn:")&&Z(m,"crtr:act")}if(n.isolated!==void 0&&typeof n.isolated!="boolean")throw new c(400,"invalid_request","isolated must be a boolean");if(m?.isolated&&n.isolated===!1)throw new c(403,"isolated_run","a cron created by an isolated node cannot escape isolation");const W=m?.isolated===!0||e.principal.class==="cron"&&e.principal.isolated;if(W&&n.isolated===!1)throw new c(403,"isolated_run","a cron created by an isolated caller cannot escape isolation");const q=W||n.isolated===!0,g=await Pn(e,y,m),j=nn(),S=q?an(y,j):null;if(S!==null&&n.cwd_is_default!==!0){const w=en(S,typeof n.cwd=="string"&&n.cwd.trim()!==""?B(n.cwd):S);if(w===".."||w.startsWith(`..${G}`)||w.startsWith(G))throw new c(400,"invalid_request","an isolated cron must run in its own cron folder",{param:"cwd"})}const V=S??await An(n,y,b,jn(n),q,{sub:g.sub,grantId:g.grant_id,scopes:g.scopes}),f=typeof n.anchor_node=="string"&&n.anchor_node!==""?n.anchor_node:null;if(f!==null&&await _(f)!==null&&(await _(f)).grantee!==y)throw new s({error:"anchor_app_mismatch",message:"anchor node belongs to another app",field:"anchor_node",next:"Use an anchor of the calling app."});if(f!==null&&await _(f)===null)throw new s({error:"anchor_not_found",message:`anchor node ${f} does not exist on the canvas`,field:"anchor_node",next:"Name a live node id, or drop the anchor \u2014 an unanchored cron outlives every node."});const x=n.cancel_on_wake===!0;if(x&&f===null)throw new s({error:"cancel_on_wake_needs_anchor",message:"cancel_on_wake couples the cron to a node's dormancy \u2014 it requires an anchor node",field:"anchor_node",next:"Pass anchor_node with the node whose wake should cancel this cron."});const $=n.run_timeout_s??300;if(typeof $!="number"||!Number.isInteger($)||$<=0)throw new s({error:"bad_run_timeout",message:`run_timeout_s must be a positive integer (got ${String(n.run_timeout_s)})`,field:"run_timeout_s",next:"Send the timeout in whole seconds, e.g. 300."});const A=typeof n.profile=="string"&&n.profile!==""?(await Sn(e,n.profile)).profileId:null,z=C(n.scope,"scope",["profile","global"],A!==null?"profile":"global");if(z==="profile"&&A===null)throw new s({error:"scope_needs_profile",message:'scope "profile" names the profile the cron lists and cancels within \u2014 it requires a profile',field:"profile",next:'Send a profile, or use scope "global" for a canvas-home-wide cron.'});return await rn({cron_id:j,name:r,created_by:b,grantee:y,sub:g.sub,grant_id:g.grant_id,scopes:g.scopes,origin_run_id:g.origin_run_id,isolated:q,command:o,fire_at:a,recur:u,tz:typeof n.tz=="string"?n.tz:null,expires_at:l,anchor_node:f,cancel_on_wake:x,cwd:V,env_json:p,profile:A,scope:z,run_timeout_s:$,overlap:h,on_output:i,sink:Q,tier:N}),{status:201,body:k(await v(j),null)}}t(Tn,"handleArm");async function En(e){const n=U(e),r=await $n(n===null?await P({all:!0}):[...await P({profile:n}),...await P({global:!0})].sort((o,a)=>o.fire_at<a.fire_at?-1:o.fire_at>a.fire_at?1:0),async o=>await J(e,o));return{status:200,body:await Cn(r,async o=>k(o,await R(o)))}}t(En,"handleList");async function R(e){return(await F(e.cron_id))[0]??null}t(R,"lastRunOf");async function O(e){const n=e.params.cronId,r=await v(n);if(r===null||!await J(e,r))throw new c(404,"cron_not_found",`no cron ${n}`);if(!Y(r,U(e)))throw new c(404,"cron_not_found",`no cron ${n} in this profile \u2014 it is scoped to another profile`);return r}t(O,"requireCron");function I(e,n){const r=K(e);if(r!==null&&n.grantee!==r)throw new c(403,"other_app_run",`cron ${n.cron_id} belongs to another app`);return n}t(I,"requireOwnCron");async function Un(e){const n=await O(e),r=await F(n.cron_id);return{status:200,body:{cron:k(n,r[0]??null),runs:r.map(H)}}}t(Un,"handleShow");async function Jn(e){const n=I(e,await O(e));await L(n.cron_id,"paused");const r=await v(n.cron_id);return{status:200,body:k(r,await R(r))}}t(Jn,"handlePause");async function Rn(e){const n=I(e,await O(e));await L(n.cron_id,"active");const r=await v(n.cron_id);return{status:200,body:k(r,await R(r))}}t(Rn,"handleResume");async function Dn(e){const n=I(e,await O(e));if(n.run_state==="running")throw new c(409,"cron_running",`cron ${n.cron_id} has a run in flight \u2014 wait for it to settle`);const r=await hn(n,{outOfBand:!0});if(r===null)throw new c(409,"cron_running",`cron ${n.cron_id} was claimed by a concurrent run \u2014 check \`cron show\` for its result`);return{status:200,body:H(r)}}t(Dn,"handleRun");async function Wn(e){const n=new Date().toISOString();return{status:200,body:{unparked:await tn(n,K(e)),at:n}}}t(Wn,"handlePoke");function xn(e,n){const r=e.principal;if(r.class==="cron")return r.cron===n.cron_id?null:{kind:"canceled",by:`cron ${r.cron}`};if(r.class==="broker"){const a=on(n.sink);return a?.kind==="node"&&a.node===r.node?null:{kind:"canceled",by:`node ${r.node}`}}const o=T(r);return{kind:"canceled",by:o===null||o==="app:terminal"?"the person":o}}t(xn,"cancelNotice");async function zn(e){const n=e.params.cronId,r=await v(n);if(r!==null&&!await J(e,r))throw new c(404,"cron_not_found",`no cron ${n}`);if(r!==null&&!Y(r,U(e)))throw new c(404,"cron_not_found",`no cron ${n} in this profile \u2014 it is scoped to another profile`);r!==null&&I(e,r);const o=e.query.get("run_id"),a=e.principal.class==="cron"?o===e.principal.execution&&n===e.principal.cron:!0,u=o!==null&&a&&mn(n,o);return r!==null&&await kn(r,u?null:xn(e,r),{preserveRunningProcess:u}),{status:204}}t(zn,"handleCancel");const ce=[{method:"POST",pattern:"/v1/crons",scope:"crtr:schedule",handler:Tn},{method:"GET",pattern:"/v1/crons",handler:En},{method:"GET",pattern:"/v1/crons/:cronId",handler:Un},{method:"POST",pattern:"/v1/crons/:cronId/pause",scope:"crtr:schedule",handler:Jn},{method:"POST",pattern:"/v1/crons/:cronId/resume",scope:"crtr:schedule",handler:Rn},{method:"POST",pattern:"/v1/crons/poke",scope:"crtr:schedule",handler:Wn},{method:"POST",pattern:"/v1/crons/:cronId/run",scope:"crtr:schedule",handler:Dn},{method:"DELETE",pattern:"/v1/crons/:cronId",scope:"crtr:schedule",handler:zn}];export{ce as cronRoutes};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CanvasDb } from '../../../core/canvas/db.js';
|
|
2
2
|
import type { ObjectRow } from '../../../core/graph/types.js';
|
|
3
3
|
import type { RequestContext, RouteTable } from '../router.js';
|
|
4
4
|
/** A token cannot read the graph. Resolve only identity here; authorization follows before any response. */
|
|
5
|
-
export declare function customObjectRef(db:
|
|
5
|
+
export declare function customObjectRef(db: CanvasDb, raw: string): Promise<ObjectRow>;
|
|
6
6
|
/** An argv object runs host commands: only a person or node principal may change it or what it watches — never an app or publish token. */
|
|
7
|
-
export declare function fenceArgv(db:
|
|
7
|
+
export declare function fenceArgv(db: CanvasDb, ctx: RequestContext, object: ObjectRow): Promise<void>;
|
|
8
8
|
/** A valid object bearer grants only this object; an ordinary principal must act as its owner. */
|
|
9
|
-
export declare function authorizeCustom(db:
|
|
9
|
+
export declare function authorizeCustom(db: CanvasDb, ctx: RequestContext, object: ObjectRow, concealed?: boolean): Promise<ObjectRow | null>;
|
|
10
10
|
export declare const customObjectRoutes: RouteTable;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var A=Object.defineProperty;var
|
|
2
|
-
`),s
|
|
3
|
-
`)},15e3),C=
|
|
1
|
+
var A=Object.defineProperty;var a=(r,e)=>A(r,"name",{value:e,configurable:!0});import{ApiError as c}from"../../../api/errors.js";import{emitEvent as F}from"../../../core/events/emit.js";import{withCanvasWrite as f,openDb as $}from"../../../core/canvas/db.js";import{registerCustomObject as L,publishCustom as P,unregisterCustomObject as H,pendingFor as I,acknowledge as W,verifyPublishToken as j,mayActAs as h,onQueueSignal as M,customReachable as k}from"../../../core/graph/custom.js";import{getById as E,getByRowid as b}from"../../../core/graph/objects.js";import{readerFor as N}from"../../../core/graph/reader.js";import{resolveName as D}from"../../../core/graph/names.js";import{stubOf as z}from"../../../core/peer/stubs.js";import{PRIVACY_LEVELS_DTO as B}from"../../../api/dto/objects.js";import{receiverForObject as Q}from"../../../core/graph/receivers.js";import{readerFor as w,resolveRef as V}from"../reader.js";import{isRecord as d}from"./validate.js";import{receiverEndpoint as G,resolveReceiverAddress as J}from"../../../core/graph/receiver-url.js";const l=a(r=>{throw new c(400,"invalid_request",`invalid ${r}`)},"bad"),p=a(()=>{throw new c(404,"not_found","custom object not found")},"missing");async function m(r,e){const n=await E(r,e)??await(async()=>{const i=await N(r,{class:"person"},async()=>[]),o=await D(r,i,e);return"object"in o?o.object:null})();return!n||!n.type.includes(".")||n.deleted_at!==null?p():n}a(m,"customObjectRef");async function U(r,e,t){if(await Q(r,t)==="argv"&&(e.publishToken||e.principal.class!=="person"&&e.principal.class!=="broker"))throw new c(403,"argv_forbidden","argv object requires a person or node principal")}a(U,"fenceArgv");async function y(r,e,t,n=!1){if(e.publishToken){if(await j(r,t,e.publishToken))return t;if(n)return p();throw new c(401,"invalid_publish_token","invalid publish token")}if(e.principal.class==="anonymous")return p();const i=await w(r,e),o=t.owner===null?null:await b(r,t.owner);return!o||!await h(r,i,o)||!await k(r,i,t)?p():i.class==="person"?i.person:i.class==="app"?i.app:i.class==="node"?i.node:i.object}a(y,"authorizeCustom");async function Y(r){const e=r.body;if((!d(e)||typeof e.kind!="string"||typeof e.name!="string"||typeof e.description!="string"||e.events!==void 0&&!d(e.events)||e.owner!==void 0&&typeof e.owner!="string"||e.rotate_token!==void 0&&typeof e.rotate_token!="boolean"||e.privacy!==void 0&&!B.includes(e.privacy))&&l("register request"),d(e.receiver)&&"url"in e.receiver&&typeof e.receiver.url=="string")try{await J(G(e.receiver.url))}catch(t){throw new c(400,"invalid_receiver",`invalid receiver URL: ${String(t)}`)}return await f(async t=>{const n=await w(t,r),i=e.owner===void 0?n.class==="person"?n.person:n.app:await(async()=>{const u=await V(t,n,e.owner);return"deleted"in u||"remote"in u?p():u})();["person","app","repo","profile"].includes(i.type)||l("owner");const o=await L(t,n,{kind:e.kind,name:e.name,owner:i,description:e.description,...e.events===void 0?{}:{events:e.events},...e.receiver===void 0?{}:{receiver:e.receiver},rotateToken:e.rotate_token,...e.privacy===void 0?{}:{privacy:e.privacy}});return{id:o.object.id,name:o.object.name,...o.token?{token:o.token}:{}}})}a(Y,"register");async function K(r,e,t){const n=await r.prepare("SELECT owner, source, declared FROM object_kinds WHERE name = ?").get(t.type);if(!n||n.source==="register")return;if(n.source==="manifest"&&n.declared===0)throw new c(409,"kind_inert",`${t.type} is no longer declared by an installed plugin`);if(e.publishToken)return;const i=await b(r,n.owner);if(!i||!await h(r,await w(r,e),i))throw new c(403,"forbidden",`only ${i?.name??"the kind owner"} may publish ${t.type}`)}a(K,"requirePublisher");async function X(r){const e=r.body;return(!d(e)||typeof e.event!="string"||typeof e.summary!="string"||e.cause!==void 0&&typeof e.cause!="string")&&l("publish request"),await f(async t=>{const n=await m(t,r.params.ref),i=await z(t,n);if(i!==null)throw new c(404,"not_here",`${n.id} is not homed on this machine (it is a stub of ${i.home_machine})`,{id:n.id,home_machine:i.home_machine});const o=await y(t,r,n);return await K(t,r,n),await P(t,n,o,e)})}a(X,"publish");async function Z(r){await f(async e=>{const t=await m(e,r.params.ref),n=await y(e,r,t);await U(e,r,t),await H(e,t,n)})}a(Z,"unregister");async function x(r){const e=r.body;return(!d(e)||!Array.isArray(e.delivery_ids)||e.delivery_ids.some(t=>typeof t!="string"))&&l("delivery_ids"),await f(async t=>{const n=await m(t,r.params.ref);return await y(t,r,n,!0),await R(t,n),await W(t,n,e.delivery_ids)})}a(x,"ack");async function R(r,e){if((await r.prepare("SELECT receiver_json FROM custom_objects WHERE object = ?").get(e.rowid))?.receiver_json!=='"queue"')throw new c(409,"not_a_queue","object does not have a queue receiver")}a(R,"requireQueue");async function ee(r){const e=r.query.get("after");e!==null&&(!/^\d+$/.test(e)||!Number.isSafeInteger(Number(e)))&&l("after");const t=await $(),n=await m(t,r.params.ref);await y(t,r,n,!0),await R(t,n);const i=r.res;i.writeHead(200,{"content-type":"application/x-ndjson; charset=utf-8","cache-control":"no-cache","x-accel-buffering":"no"});let o=-1;const u=a(async()=>{const s=await E(t,n.id);if(!s||s.deleted_at!==null)return!1;if(r.publishToken)return await j(t,s,r.publishToken)&&(await t.prepare("SELECT receiver_json FROM custom_objects WHERE object = ?").get(s.rowid))?.receiver_json==='"queue"';if(r.principal.class==="anonymous")return!1;const _=s.owner===null?null:await b(t,s.owner),g=await w(t,r);return _!==null&&await h(t,g,_)&&await k(t,g,s)&&(await t.prepare("SELECT receiver_json FROM custom_objects WHERE object = ?").get(s.rowid))?.receiver_json==='"queue"'},"authorized"),v=a(async()=>{if(!(i.destroyed||i.writableEnded)){if(!await u()){i.end();return}for(const s of await I(t,n,o))i.write(`${JSON.stringify(s)}
|
|
2
|
+
`),o=s.seq}},"flush"),O=await M(n.id,v),q=a(async()=>{await v(),!i.destroyed&&!i.writableEnded&&i.write(`
|
|
3
|
+
`)},"beat"),S=setInterval(()=>{q().catch(s=>F({level:"error",event:"api.custom_objects.heartbeat_failed",node_id:n.id,error:s}))},15e3),C=a(()=>{clearInterval(S),O()},"close");return i.once("close",C),await v(),{status:200}}a(ee,"stream");const T=a(r=>async e=>({status:200,body:await r(e)}),"ok"),me=[{method:"POST",pattern:"/v1/custom-objects",handler:a(async r=>({status:200,body:await Y(r)}),"handler")},{method:"POST",pattern:"/v1/custom-objects/:ref/events",handler:T(X)},{method:"DELETE",pattern:"/v1/custom-objects/:ref",handler:a(async r=>(await Z(r),{status:204}),"handler")},{method:"GET",pattern:"/v1/custom-objects/:ref/deliveries",handler:ee},{method:"POST",pattern:"/v1/custom-objects/:ref/deliveries/ack",handler:T(x)}];export{y as authorizeCustom,m as customObjectRef,me as customObjectRoutes,U as fenceArgv};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var d=Object.defineProperty;var t=(r,e)=>d(r,"name",{value:e,configurable:!0});import{ApiError as i}from"../../../api/errors.js";import{retryFailedDaemonAction as o}from"../../../core/canvas/daemon-actions.js";import{retryFailedDelivery as
|
|
1
|
+
var d=Object.defineProperty;var t=(r,e)=>d(r,"name",{value:e,configurable:!0});import{ApiError as i}from"../../../api/errors.js";import{retryFailedDaemonAction as o}from"../../../core/canvas/daemon-actions.js";import{retryFailedDelivery as a}from"../../../core/canvas/deliveries.js";const n=/^[0-9a-f]{32}$/;async function l(r){const e=r.params.delivery_id??"";if(!n.test(e))throw new i(400,"invalid_request","delivery_id must be the 32-character id of a delivery");if(!await a(e)&&!await o(e))throw new i(404,"delivery_not_failed",`no failed delivery ${e} to retry (it does not exist, is not permanently failed, or was canceled)`);return{status:200,body:{delivery_id:e,state:"pending"}}}t(l,"handleRetry");const m=[{method:"POST",pattern:"/v1/deliveries/:delivery_id/retry",handler:l}];export{m as deliveryRetryRoutes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _=Object.defineProperty;var c=(e,n)=>_(e,"name",{value:n,configurable:!0});import{ApiError as r}from"../../../api/errors.js";import{withCanvasWrite as f}from"../../../core/canvas/db.js";import{readerForNode as l}from"../../../core/graph/reader.js";import{noteNodeBooting as j}from"../../../core/graph/repo-sync/index.js";import{checkoutsForCwd as h,warmCheckoutIdentities as k}from"../../../core/graph/repo-sync/repos.js";import{getNode as N}from"../../../core/canvas/canvas.js";import{DRY_RUN_ONLY as q,deliver as A,hypotheticalFrom as C,hypotheticalReader as I,inspect as p}from"../../../core/substrate/delivery/deliver.js";import{requireCurrentExecution as w}from"./broker-recovery.js";const O=["boot","system-prompt","compact","persona","file-read","command","pre-command","slash-command","names",...q];function m(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new r(400,"usage","delivery requires a JSON body");const n=e;if(!O.includes(n.activity))throw new r(400,"usage",`invalid delivery activity: ${String(n.activity)}`);if(n.subject!==void 0&&typeof n.subject!="string")throw new r(400,"usage","delivery subject must be a string");return n}c(m,"parse");function b(e){if(e.principal.class!=="person"&&e.principal.class!=="broker")throw new r(403,"permission_error","a delivery dry run is available to a person or a node only")}c(b,"requirePerson");function R(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new r(400,"usage","hypothetical must be an object");const n=c((o,s)=>{if(o!==void 0){if(typeof o!="string"||o==="")throw new r(400,"usage",`hypothetical.${s} must be a non-empty string`);return o}},"str"),t=n(e.cwd,"cwd");if(t!==void 0&&!t.startsWith("/"))throw new r(400,"usage","hypothetical.cwd must be an absolute path");if(e.mode!==void 0&&e.mode!=="base"&&e.mode!=="orchestrator")throw new r(400,"usage","hypothetical.mode must be base or orchestrator");if(e.lifecycle!==void 0&&e.lifecycle!=="terminal"&&e.lifecycle!=="resident")throw new r(400,"usage","hypothetical.lifecycle must be terminal or resident");if(e.has_manager!==void 0&&typeof e.has_manager!="boolean")throw new r(400,"usage","hypothetical.has_manager must be a boolean");if(e.depth!==void 0&&(!Number.isInteger(e.depth)||e.depth<0))throw new r(400,"usage","hypothetical.depth must be a non-negative integer");const i={};t!==void 0&&(i.cwd=t),e.profile!==void 0&&(i.profile=e.profile===null?null:n(e.profile,"profile"));const d=n(e.grantee,"grantee");d!==void 0&&(i.grantee=d);const a=n(e.kind,"kind");return a!==void 0&&(i.kind=a),e.mode!==void 0&&(i.mode=e.mode),e.lifecycle!==void 0&&(i.lifecycle=e.lifecycle),e.has_manager!==void 0&&(i.hasManager=e.has_manager),e.depth!==void 0&&(i.depth=e.depth),i}c(R,"hypotheticalOf");async function y(e,n){const t=e===void 0?void 0:await N(e);for(const i of[t?.cwd,n])i&&k(i)}c(y,"warmDeliveryCwds");async function S(e){b(e);const n=m(e.body);if(n.node!==void 0&&typeof n.node!="string")throw new r(400,"usage","node must be a node id");const t={activity:n.activity,...n.subject!==void 0?{subject:n.subject}:{}};await y(n.node,n.hypothetical?.cwd);const{result:i,plan:d}=await f(async a=>{if(n.hypothetical===void 0){if(n.node===void 0)throw new r(400,"usage","a delivery dry run names a node, a hypothetical node, or both");return await p(a,await l(a,n.node,async v=>await h(a,v)),t,n.subject_override)}const o=R(n.hypothetical),s=n.node!==void 0?await C(n.node,o):{...o,cwd:o.cwd??""};if(s.cwd==="")throw new r(400,"usage","a hypothetical node needs a cwd");const{reader:u,subject:g}=await I(a,s);return await p(a,u,t,n.subject_override,g)},{rollback:!0});return{status:200,body:{...i,plan:d}}}c(S,"handleDryRun");async function D(e){const n=e.params.id,t=m(e.body),i={activity:t.activity,...t.subject!==void 0?{subject:t.subject}:{},...t.inherited===!0?{inherited:!0}:{}};if(t.dry_run===!0){b(e),await y(n);const{result:a,plan:o}=await f(async s=>await p(s,await l(s,n,async u=>await h(s,u)),i,t.subject_override),{rollback:!0});return{status:200,body:{...a,plan:o}}}if(e.principal.class==="broker"&&e.principal.node!==n)throw new r(403,"permission_error","delivery is performed by the node's own broker");return await w(n,t.expected_execution_id),t.activity==="boot"&&(await j(n),await w(n,t.expected_execution_id)),await y(n),{status:200,body:await f(async a=>await A(a,await l(a,n,async o=>await h(a,o)),i))}}c(D,"handleDelivery");const L=[{method:"POST",pattern:"/v1/nodes/:id/delivery",handler:D},{method:"POST",pattern:"/v1/delivery/dry-run",handler:S}];export{L as deliveryRoutes};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CanvasDb } from '../../../core/canvas/db.js';
|
|
2
2
|
import type { ObjectRow, Reader } from '../../../core/graph/types.js';
|
|
3
3
|
import type { RouteTable } from '../router.js';
|
|
4
|
-
export declare function canonicalName(db:
|
|
4
|
+
export declare function canonicalName(db: CanvasDb, o: ObjectRow): Promise<string>;
|
|
5
5
|
/** A committed change to a repo-owned document starts that repo's sync. */
|
|
6
6
|
export interface RepoChange {
|
|
7
7
|
repos: ObjectRow[];
|
|
@@ -10,7 +10,7 @@ export interface RepoChange {
|
|
|
10
10
|
/** The repos among `owners` and the directories that may hold a checkout of them (the caller's cwd,
|
|
11
11
|
* a node's own else the request's, and the checkouts its view reaches), captured inside the write
|
|
12
12
|
* transaction and acted on after it commits. */
|
|
13
|
-
export declare function repoChange(db:
|
|
13
|
+
export declare function repoChange(db: CanvasDb, reader: Reader, owners: ObjectRow[], requestCwd?: string): Promise<RepoChange>;
|
|
14
14
|
/** The change is committed; a sync that cannot start is reported as an event, never as a failed write. */
|
|
15
|
-
export declare function syncChanged(change: RepoChange): void
|
|
15
|
+
export declare function syncChanged(change: RepoChange): Promise<void>;
|
|
16
16
|
export declare const docRoutes: RouteTable;
|