@north-light/cli 0.3.529 → 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/api/dto/lifecycle.d.ts +3 -1
- package/dist/api/dto/messages.d.ts +5 -3
- package/dist/builtin-memory/crouter-plugin/bundles-and-memory.md +1 -1
- package/dist/builtin-memory/crouter-plugin/commands.md +1 -1
- package/dist/clients/attach/session/connection.js +1 -1
- package/dist/clients/attach/session/reconnect.js +1 -1
- package/dist/clients/attach/viewer.js +508 -508
- package/dist/commands/node/message.js +1 -1
- package/dist/commands/sys/join.js +1 -1
- 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/lifecycle-catalog.d.ts +4 -4
- package/dist/core/command-hooks/lifecycle-catalog.js +1 -1
- package/dist/core/command-hooks/transport/exec-lifecycle.js +1 -1
- package/dist/core/command-plugins/bundle.d.ts +1 -1
- package/dist/core/command-plugins/bundle.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/directory/join.d.ts +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 +21 -10
- 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 +3 -3
- 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/launcher/run.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/plugin/bundles-and-memory.md +1 -1
- package/docs/plugin/commands.md +1 -1
- package/docs/public-api.md +11 -0
- package/package.json +4 -3
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
var x=Object.defineProperty;var
|
|
1
|
+
var x=Object.defineProperty;var c=(o,n)=>x(o,"name",{value:n,configurable:!0});import{realpathSync as E}from"node:fs";import{isAbsolute as y,relative as _,sep as h}from"node:path";import{ApiError as r}from"../../../api/index.js";import{coreHookCatalog as T}from"../../../build-root.js";import{getNode as O}from"../../../core/canvas/canvas.js";import{isSafeNodeId as P,nodeAgentDir as A}from"../../../core/canvas/paths.js";import{discoverHookRegistry as I}from"../../../core/command-hooks/discovery.js";import{EXEC_HOOK_TIMEOUT_MS as S}from"../../../core/command-hooks/transport/exec-invoke.js";import{buildAppProcessEnv as H}from"../../../core/runtime/spawn-env.js";import{compileLaunch as N}from"../../../core/spaces/mounts.js";import{appProcessSandboxed as M,launchAppProcess as R}from"../../../core/spaces/process.js";import{requireCurrentExecution as B}from"./broker-recovery.js";async function k(o,n,t){const i=o.params.id;if(i===void 0?o.principal.class!=="person":!P(i)||o.principal.class!=="broker"||o.principal.node!==i)throw new r(403,"permission_error","hook execution requires its current node, or the person for the global route");const e=i===void 0?null:await O(i);if(i!==void 0&&!e)throw new r(404,"not_found","node not found");if(i!==void 0&&await B(i,n),typeof t!="string"||!y(t))throw new r(400,"invalid_request","hook cwd must be absolute");if(!M())throw new r(400,"invalid_request","hook routes require the root launcher");let d;try{d=E(t)}catch(u){throw u.code==="ENOENT"?new r(400,"invalid_request","hook cwd does not exist"):u}if(e){if(e.isolated===!0){const a=A(i,e.grantee??"app:terminal"),s=_(a,d);if(s===".."||s.startsWith(`..${h}`)||s.startsWith(h))throw new r(403,"permission_error","hook cwd is outside the isolated node folder")}const u=await N({nodeId:i,app:o.principal.class==="broker"?o.principal.app:"app:terminal",sub:e.sub??"user:local",grantId:e.grant_id??null,scopes:e.scopes??null,isolated:e.isolated===!0,command:[],env:{},auditMissing:c(()=>{},"auditMissing")}),f=c(a=>{const s=_(a,d);return s===""||s!==".."&&!s.startsWith(`..${h}`)&&!y(s)},"within");if(!u.mounts.some(a=>f(a.source)))throw new r(403,"permission_error","hook cwd is outside the node mounts")}return{id:i,node:e,cwd:d,app:e&&o.principal.class==="broker"?o.principal.app:"app:terminal"}}c(k,"checkedContext");async function b(o,n){const t=I(await T(),o,n);if(!t.valid)throw new r(422,"hook_registry_invalid","the effective hook registry is invalid");return t}c(b,"currentRegistry");async function C(o){const{node:n,cwd:t}=await k(o,o.query.get("expected_execution_id"),o.query.get("cwd"));return{status:200,body:{hooks:(await b(t,n.profile_id??null)).hooks.filter(e=>e.plugin.scope==="user").map(e=>({id:e.id,plugin:e.plugin.name,target:e.target,phase:e.phase,op:e.op,description:e.description,effects:e.effects,declarationIndex:e.declarationIndex}))}}}c(C,"handleHookPlan");async function v(o){const n=o.body;if(!n||typeof n!="object"||Array.isArray(n))throw new r(400,"invalid_request","hook execution requires a JSON body");const t=n,{id:i,node:e,cwd:d,app:u}=await k(o,t.expected_execution_id,t.cwd);if(typeof t.hook_id!="string"||typeof t.request!="string")throw new r(400,"invalid_request","hook execution requires hook_id and request");const a=(await b(d,e?.profile_id??null)).hooks.find(p=>p.id===t.hook_id);if(!a)throw new r(404,"hook_not_registered","hook id is not registered for this cwd");const s=H(d,e?.profile_id??null,u),m=await R({...i===void 0?{}:{nodeId:i},app:u,command:[a.executable,"--crtr-hook-protocol","1"],cwd:d,pluginRoot:a.plugin.root,env:s,stdin:t.request,stdoutBytes:10*1024*1024,stderrBytes:64*1024});let l,w=!1;try{const p=await Promise.race([m.completion,new Promise((W,g)=>{l=setTimeout(()=>{w=!0,m.stop().then(()=>g(new r(504,"hook_timeout","hook executable timed out")),q=>g(q))},S)})]);if(w)throw new r(504,"hook_timeout","hook executable timed out");if(p.stdoutTruncated)throw new r(502,"hook_output_limit","hook stdout exceeded the 10 MiB cap");return{status:200,body:{stdout:p.stdout,status:p.exitCode,signal:p.signal}}}finally{l&&clearTimeout(l)}}c(v,"handleHookExec");const Y=[{method:"GET",pattern:"/v1/nodes/:id/hooks/plan",handler:C},{method:"POST",pattern:"/v1/nodes/:id/hooks/exec",handler:v},{method:"POST",pattern:"/v1/hooks/exec",handler:v}];export{Y as hookExecRoutes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=Object.defineProperty;var o=(e,t)=>P(e,"name",{value:t,configurable:!0});import{statSync as N}from"node:fs";import{isAbsolute as T}from"node:path";import{ApiError as s}from"../../../api/index.js";import{readDaemonActionById as C}from"../../../core/canvas/daemon-actions.js";import{isSafeNodeId as I}from"../../../core/canvas/paths.js";import{getNode as b}from"../../../core/canvas/canvas.js";import{assertScope as $}from"../../../core/scopes.js";import{resolvePageComponents as g}from"../../../core/config.js";import{resolveHumanAction as D}from"../../../core/human-actions.js";import{HUMAN_ACTION_NAME_PATTERN as x}from"../../../core/human/action-binding.js";import{createPageRequest as J,getRequest as F}from"../../../core/human/requests.js";import{preparePageSource as M}from"../../../core/human/page-authoring.js";import{PageCompilerError as B}from"../../../core/human/page-errors.js";import{publishPage as G,validatePageTicketResponses as H}from"../../../core/human/tickets.js";import{cancelHumanTicket as L,resolvePageTicket as U}from"../../human/finish.js";import{inboxPageProjection as K}from"./inbox-page.js";import{appOf as X}from"../router.js";const z=1e3,q=200,m={placement:"inline",inbox:!0,reply:!1},v=["sessionName","askedBy","emittedAt","profileName","nodeId"];function c(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}o(c,"isPlainObject");function l(e,t,n){for(const r of Object.keys(e))if(!t.includes(r))throw new s(400,"invalid_request",`unexpected field in ${n}: ${r}`)}o(l,"requireNoExtraKeys");function i(e){return new s(400,"invalid_request",e)}o(i,"invalid");function w(e){if(!c(e))throw i("`page` must be an object");if(l(e,["dialect","source"],"`page`"),e.dialect!=="jsx"&&e.dialect!=="html")throw i('`page.dialect` must be "jsx" or "html"');if(typeof e.source!="string"||e.source.trim()==="")throw i("`page.source` must be the authored page text");return{dialect:e.dialect,source:e.source}}o(w,"validatePage");function S(e,t){const n=e??t;if(n!=="inline"&&n!=="panel")throw i('`delivery.placement` must be "inline" or "panel"');return n}o(S,"validatePlacement");function V(e,t){if(e===void 0)return m;if(!c(e))throw i("`delivery` must be an object");l(e,["placement","inbox","reply"],"`delivery`");const n=e.inbox??m.inbox,r=e.reply??m.reply;if(typeof n!="boolean")throw i("`delivery.inbox` must be boolean");if(typeof r!="boolean")throw i("`delivery.reply` must be boolean");if(r&&t===null)throw i("`delivery.reply` requires `requester_node_id`");return{placement:S(e.placement,m.placement),inbox:n,reply:r}}o(V,"validateCreateDelivery");function Y(e,t){if(e===void 0)return t;if(!c(e))throw i("`delivery` must be an object");return l(e,["placement"],"`delivery`"),{...t,placement:S(e.placement,t.placement)}}o(Y,"validateReplaceDelivery");function Q(e){if(e===void 0)return;if(!c(e))throw i("`source` must be an object");l(e,v,"`source`");const t={};for(const n of v){const r=e[n];if(r!==void 0){if(typeof r!="string"||r==="")throw i(`\`source.${n}\` must be a nonempty string`);t[n]=r}}return t}o(Q,"validateSource");function W(e){if(typeof e!="string"||e==="")throw i("`creator_cwd` is required");if(!T(e))throw i("`creator_cwd` must be an absolute path");try{if(!N(e).isDirectory())throw i(`\`creator_cwd\` is not a directory: ${e}`)}catch(t){throw t instanceof s?t:i(`\`creator_cwd\` does not exist: ${e}`)}return e}o(W,"validateCreatorCwd");function Z(e){if(e!==void 0){if(!c(e))throw i("`action` must be an object");if(l(e,["name","payload"],"`action`"),typeof e.name!="string"||!x.test(e.name))throw i("`action.name` must be a declared action name");return{name:e.name,payload:e.payload??null}}}o(Z,"validateActionSelection");function ee(e){if(e==null)return null;if(typeof e!="string"||!I(e))throw i("`requester_node_id` must be a safe node id or null");return e}o(ee,"validateRequesterNodeId");function te(e){if(!c(e))throw i("request body is required");l(e,["page","delivery","source","requester_node_id","creator_cwd","action"],"the request body");const t=Q(e.source),n=ee(e.requester_node_id),r=Z(e.action);return{page:w(e.page),delivery:V(e.delivery,n),...t===void 0?{}:{source:t},requesterNodeId:n,creatorCwd:W(e.creator_cwd),...r===void 0?{}:{action:r}}}o(te,"validateCreateRequest");function ne(e,t){if(!c(e))throw i("request body is required");return l(e,["page","delivery"],"the request body"),{page:w(e.page),delivery:Y(e.delivery,t)}}o(ne,"validateReplaceRequest");function _(e,t,n){if(e!==void 0){if(typeof e!="string"||e.trim()===""||e.length>n)throw i(`\`${t}\` must be nonempty after trim and at most ${n} characters`);return e}}o(_,"optionalBoundedString");function re(e){if(!c(e))throw i("request body is required");if(l(e,["responses","actor"],"the request body"),!c(e.responses))throw i("`responses` must be an object");const t=_(e.actor,"actor",q);return{responses:e.responses,...t===void 0?{}:{actor:t}}}o(re,"validateRespondRequest");function oe(e){if(e===void 0)return{};if(!c(e))throw i("request body must be an object");l(e,["reason","actor"],"the request body");const t=_(e.reason,"reason",z),n=_(e.actor,"actor",q);return{...t===void 0?{}:{reason:t},...n===void 0?{}:{actor:n}}}o(oe,"validateSettleRequest");function h(e){const t=e.params.request_id;if(typeof t!="string"||t==="")throw i("request id is required");return t}o(h,"requestId");function f(e){const t=F(e);if(t===null||t.kind!=="page")throw new s(404,"not_found","no request with that id");return t}o(f,"requirePageRequest");function A(e){try{const t=JSON.parse(e.specification_json);if(!c(t))throw new Error("not an object");return t}catch{throw new s(500,"internal","the request specification could not be read")}}o(A,"manifest");function ie(e){if(e.result_json===null)return null;try{return JSON.parse(e.result_json)}catch{throw new s(500,"internal","the request result could not be read")}}o(ie,"terminalResult");function ae(e){if(e.action_json===null)return null;try{const t=JSON.parse(e.action_json);if(t.schema!=="crtr.human-action-binding/v1"||typeof t.name!="string")throw new Error("invalid action");return t}catch{throw new s(500,"internal","the request action could not be read")}}o(ae,"frozenAction");function se(e){return e.state!=="settled"?"pending":e.outcome==="answered"?"answered":e.outcome==="dismissed"?"dismissed":"canceled"}o(se,"requestState");function de(e){if(e.action_delivery_id===null)return{state:"none",attempt:0};const t=C(e.action_delivery_id);if(t===null)return{state:"none",attempt:0};const n=t.state==="acknowledged"?"accepted":t.state==="permanent_failed"?"permanent_failed":t.state==="handed_off"?"running":"pending",r={state:n,attempt:t.attempts};return n==="pending"&&t.nextAttemptAt!==null&&(r.next_attempt_at=new Date(t.nextAttemptAt).toISOString()),t.acknowledgedAt!==null&&(r.accepted_at=new Date(t.acknowledgedAt).toISOString()),t.failedAt!==null&&(r.permanent_failed_at=new Date(t.failedAt).toISOString()),t.lastFailure!==null&&(r.last_failure=t.lastFailure),r}o(de,"deliveryDetail");function y(e){const t=A(e),n=ie(e),r=se(e),a={request_id:e.request_id,inbox_ticket_id:e.inbox_ticket_id,request_dir:e.request_dir,kind:e.kind,state:r,title:e.title,source:t.source??{},emitted_at:t.source?.emittedAt??e.created_at};e.subtitle!==null&&(a.subtitle=e.subtitle),e.kind==="page"&&(a.page=K(e)),n!==null&&(a.settled_at=e.settled_at??e.updated_at,n.kind==="page"&&r==="answered"&&(a.responses=n.responses),n.kind==="canceled"&&n.reason!==void 0&&(a.reason=n.reason),n.kind==="page"&&n.actor!==void 0&&(a.actor=n.actor),n.kind==="canceled"&&n.actor!==void 0&&(a.actor=n.actor));const u=ae(e);return u!==null&&(a.action={name:u.name,payload:u.payload},a.delivery=de(e)),a}o(y,"requestToDTO");function k(e,t,n,r){try{return M({dialect:e,document:t,source:n,delivery:r,productKinds:g()})}catch(a){throw a instanceof B?a:i(a instanceof Error?a.message:"the page could not be prepared")}}o(k,"prepareOrReject");function ce(e){const t=te(e.body),n=t.requesterNodeId??t.source?.nodeId;if(n!=null){const d=b(n);d!==null&&$(d,"crtr:act")}let r;if(t.action!==void 0){const d=D(t.action.name,t.creatorCwd);if("kind"in d){const E=d.kind==="unknown_action"?`no action named ${d.name} is declared from ${t.creatorCwd}`:`${d.name} is declared in ${d.configOrigin} but unusable: ${d.reason}`;throw new s(400,d.kind,E)}const p=n==null?null:b(n);if(n&&!p)throw new s(404,"not_found","action requester node not found");if(p&&e.principal.class!=="person"&&p.grantee!==X(e.principal))throw new s(403,"permission_error","action requester belongs to another app");r=JSON.stringify({schema:"crtr.human-action-binding/v1",name:t.action.name,payload:t.action.payload,creatorCwd:t.creatorCwd,configOrigin:d.configOrigin,argv:d.argv,cwd:d.cwd,app:p?.grantee??(e.principal.class==="broker"?e.principal.app:"app:terminal")})}const a=k(t.page.dialect,t.page.source,t.source,t.delivery),u=J({prepared:a,requester_node_id:t.requesterNodeId,...r===void 0?{}:{action_json:r}});return{status:201,body:{request_id:u.request_id,request_dir:u.request_dir,state:"pending",...t.action===void 0?{}:{action:{name:t.action.name}},delivery_state:"none"}}}o(ce,"handleCreate");function ue(e){return{status:200,body:y(f(h(e)))}}o(ue,"handleGet");function le(e){const t=f(h(e));if(t.state==="settled")throw new s(409,"already_settled","the request already has a terminal result");const n=A(t),r=ne(e.body,n.delivery),a=k(r.page.dialect,r.page.source,n.source,r.delivery);try{G(t.request_dir,a)}catch(u){throw u instanceof Error&&u.message===`page request is not open: ${t.request_id}`?new s(409,"already_settled","the request already has a terminal result"):u}return{status:200,body:y(f(t.request_id))}}o(le,"handleReplace");function O(e){return e instanceof s?e:e instanceof Error&&e.message.includes("unknown page request")?new s(404,"not_found","no request with that id"):e instanceof Error&&e.message==="page_has_no_response_lifecycle"?new s(409,"not_settleable","this request carries no response lifecycle"):new s(500,"internal","the request could not be settled")}o(O,"settlementError");function R(e){if(e.state==="settled")throw new s(409,"already_settled","the request already has a terminal result");if(!e.settleable)throw new s(409,"not_settleable","this request carries no response lifecycle")}o(R,"requireSettleable");async function fe(e){const t=f(h(e)),n=re(e.body);R(t);try{H(t.request_dir,n.responses)}catch(r){throw i(r instanceof Error?r.message:"the response map is invalid")}try{await U(t.request_id,n.responses,n.actor===void 0?{}:{actor:n.actor})}catch(r){throw O(r)}return{status:200,body:y(f(t.request_id))}}o(fe,"handleRespond");async function j(e,t){const n=f(h(e)),r=oe(e.body);R(n);try{await L(n.request_id,{...r,disposition:t})}catch(a){throw O(a)}return{status:200,body:y(f(n.request_id))}}o(j,"settle");function pe(){return{status:200,body:{components:[...g()]}}}o(pe,"handleComponents");const Te=[{method:"GET",pattern:"/v1/human/components",handler:o(()=>pe(),"handler")},{method:"POST",pattern:"/v1/human/requests",scope:"crtr:act",handler:ce},{method:"GET",pattern:"/v1/human/requests/:request_id",handler:ue},{method:"POST",pattern:"/v1/human/requests/:request_id/replace",handler:le},{method:"POST",pattern:"/v1/human/requests/:request_id/respond",handler:fe},{method:"POST",pattern:"/v1/human/requests/:request_id/dismiss",handler:o(e=>j(e,"dismissed"),"handler")},{method:"POST",pattern:"/v1/human/requests/:request_id/cancel",handler:o(e=>j(e,"canceled"),"handler")}];export{Te as humanRequestRoutes};
|
|
1
|
+
var P=Object.defineProperty;var o=(e,t)=>P(e,"name",{value:t,configurable:!0});import{statSync as N}from"node:fs";import{isAbsolute as T}from"node:path";import{ApiError as s}from"../../../api/index.js";import{readDaemonActionById as C}from"../../../core/canvas/daemon-actions.js";import{isSafeNodeId as I}from"../../../core/canvas/paths.js";import{getNode as b}from"../../../core/canvas/canvas.js";import{assertScope as $}from"../../../core/scopes.js";import{resolvePageComponents as g}from"../../../core/config.js";import{resolveHumanAction as D}from"../../../core/human-actions.js";import{HUMAN_ACTION_NAME_PATTERN as x}from"../../../core/human/action-binding.js";import{createPageRequest as J,getRequest as F}from"../../../core/human/requests.js";import{preparePageSource as M}from"../../../core/human/page-authoring.js";import{PageCompilerError as B}from"../../../core/human/page-errors.js";import{publishPage as G,validatePageTicketResponses as H}from"../../../core/human/tickets.js";import{cancelHumanTicket as L,resolvePageTicket as U}from"../../human/finish.js";import{inboxPageProjection as K}from"./inbox-page.js";import{appOf as X}from"../router.js";const z=1e3,q=200,m={placement:"inline",inbox:!0,reply:!1},v=["sessionName","askedBy","emittedAt","profileName","nodeId"];function c(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}o(c,"isPlainObject");function l(e,t,n){for(const r of Object.keys(e))if(!t.includes(r))throw new s(400,"invalid_request",`unexpected field in ${n}: ${r}`)}o(l,"requireNoExtraKeys");function i(e){return new s(400,"invalid_request",e)}o(i,"invalid");function w(e){if(!c(e))throw i("`page` must be an object");if(l(e,["dialect","source"],"`page`"),e.dialect!=="jsx"&&e.dialect!=="html")throw i('`page.dialect` must be "jsx" or "html"');if(typeof e.source!="string"||e.source.trim()==="")throw i("`page.source` must be the authored page text");return{dialect:e.dialect,source:e.source}}o(w,"validatePage");function S(e,t){const n=e??t;if(n!=="inline"&&n!=="panel")throw i('`delivery.placement` must be "inline" or "panel"');return n}o(S,"validatePlacement");function V(e,t){if(e===void 0)return m;if(!c(e))throw i("`delivery` must be an object");l(e,["placement","inbox","reply"],"`delivery`");const n=e.inbox??m.inbox,r=e.reply??m.reply;if(typeof n!="boolean")throw i("`delivery.inbox` must be boolean");if(typeof r!="boolean")throw i("`delivery.reply` must be boolean");if(r&&t===null)throw i("`delivery.reply` requires `requester_node_id`");return{placement:S(e.placement,m.placement),inbox:n,reply:r}}o(V,"validateCreateDelivery");function Y(e,t){if(e===void 0)return t;if(!c(e))throw i("`delivery` must be an object");return l(e,["placement"],"`delivery`"),{...t,placement:S(e.placement,t.placement)}}o(Y,"validateReplaceDelivery");function Q(e){if(e===void 0)return;if(!c(e))throw i("`source` must be an object");l(e,v,"`source`");const t={};for(const n of v){const r=e[n];if(r!==void 0){if(typeof r!="string"||r==="")throw i(`\`source.${n}\` must be a nonempty string`);t[n]=r}}return t}o(Q,"validateSource");function W(e){if(typeof e!="string"||e==="")throw i("`creator_cwd` is required");if(!T(e))throw i("`creator_cwd` must be an absolute path");try{if(!N(e).isDirectory())throw i(`\`creator_cwd\` is not a directory: ${e}`)}catch(t){throw t instanceof s?t:i(`\`creator_cwd\` does not exist: ${e}`)}return e}o(W,"validateCreatorCwd");function Z(e){if(e!==void 0){if(!c(e))throw i("`action` must be an object");if(l(e,["name","payload"],"`action`"),typeof e.name!="string"||!x.test(e.name))throw i("`action.name` must be a declared action name");return{name:e.name,payload:e.payload??null}}}o(Z,"validateActionSelection");function ee(e){if(e==null)return null;if(typeof e!="string"||!I(e))throw i("`requester_node_id` must be a safe node id or null");return e}o(ee,"validateRequesterNodeId");function te(e){if(!c(e))throw i("request body is required");l(e,["page","delivery","source","requester_node_id","creator_cwd","action"],"the request body");const t=Q(e.source),n=ee(e.requester_node_id),r=Z(e.action);return{page:w(e.page),delivery:V(e.delivery,n),...t===void 0?{}:{source:t},requesterNodeId:n,creatorCwd:W(e.creator_cwd),...r===void 0?{}:{action:r}}}o(te,"validateCreateRequest");function ne(e,t){if(!c(e))throw i("request body is required");return l(e,["page","delivery"],"the request body"),{page:w(e.page),delivery:Y(e.delivery,t)}}o(ne,"validateReplaceRequest");function _(e,t,n){if(e!==void 0){if(typeof e!="string"||e.trim()===""||e.length>n)throw i(`\`${t}\` must be nonempty after trim and at most ${n} characters`);return e}}o(_,"optionalBoundedString");function re(e){if(!c(e))throw i("request body is required");if(l(e,["responses","actor"],"the request body"),!c(e.responses))throw i("`responses` must be an object");const t=_(e.actor,"actor",q);return{responses:e.responses,...t===void 0?{}:{actor:t}}}o(re,"validateRespondRequest");function oe(e){if(e===void 0)return{};if(!c(e))throw i("request body must be an object");l(e,["reason","actor"],"the request body");const t=_(e.reason,"reason",z),n=_(e.actor,"actor",q);return{...t===void 0?{}:{reason:t},...n===void 0?{}:{actor:n}}}o(oe,"validateSettleRequest");function h(e){const t=e.params.request_id;if(typeof t!="string"||t==="")throw i("request id is required");return t}o(h,"requestId");async function f(e){const t=await F(e);if(t===null||t.kind!=="page")throw new s(404,"not_found","no request with that id");return t}o(f,"requirePageRequest");function A(e){try{const t=JSON.parse(e.specification_json);if(!c(t))throw new Error("not an object");return t}catch{throw new s(500,"internal","the request specification could not be read")}}o(A,"manifest");function ie(e){if(e.result_json===null)return null;try{return JSON.parse(e.result_json)}catch{throw new s(500,"internal","the request result could not be read")}}o(ie,"terminalResult");function ae(e){if(e.action_json===null)return null;try{const t=JSON.parse(e.action_json);if(t.schema!=="crtr.human-action-binding/v1"||typeof t.name!="string")throw new Error("invalid action");return t}catch{throw new s(500,"internal","the request action could not be read")}}o(ae,"frozenAction");function se(e){return e.state!=="settled"?"pending":e.outcome==="answered"?"answered":e.outcome==="dismissed"?"dismissed":"canceled"}o(se,"requestState");async function de(e){if(e.action_delivery_id===null)return{state:"none",attempt:0};const t=await C(e.action_delivery_id);if(t===null)return{state:"none",attempt:0};const n=t.state==="acknowledged"?"accepted":t.state==="permanent_failed"?"permanent_failed":t.state==="handed_off"?"running":"pending",r={state:n,attempt:t.attempts};return n==="pending"&&t.nextAttemptAt!==null&&(r.next_attempt_at=new Date(t.nextAttemptAt).toISOString()),t.acknowledgedAt!==null&&(r.accepted_at=new Date(t.acknowledgedAt).toISOString()),t.failedAt!==null&&(r.permanent_failed_at=new Date(t.failedAt).toISOString()),t.lastFailure!==null&&(r.last_failure=t.lastFailure),r}o(de,"deliveryDetail");async function y(e){const t=A(e),n=ie(e),r=se(e),a={request_id:e.request_id,inbox_ticket_id:e.inbox_ticket_id,request_dir:e.request_dir,kind:e.kind,state:r,title:e.title,source:t.source??{},emitted_at:t.source?.emittedAt??e.created_at};e.subtitle!==null&&(a.subtitle=e.subtitle),e.kind==="page"&&(a.page=await K(e)),n!==null&&(a.settled_at=e.settled_at??e.updated_at,n.kind==="page"&&r==="answered"&&(a.responses=n.responses),n.kind==="canceled"&&n.reason!==void 0&&(a.reason=n.reason),n.kind==="page"&&n.actor!==void 0&&(a.actor=n.actor),n.kind==="canceled"&&n.actor!==void 0&&(a.actor=n.actor));const u=ae(e);return u!==null&&(a.action={name:u.name,payload:u.payload},a.delivery=await de(e)),a}o(y,"requestToDTO");function k(e,t,n,r){try{return M({dialect:e,document:t,source:n,delivery:r,productKinds:g()})}catch(a){throw a instanceof B?a:i(a instanceof Error?a.message:"the page could not be prepared")}}o(k,"prepareOrReject");async function ce(e){const t=te(e.body),n=t.requesterNodeId??t.source?.nodeId;if(n!=null){const d=await b(n);d!==null&&$(d,"crtr:act")}let r;if(t.action!==void 0){const d=D(t.action.name,t.creatorCwd);if("kind"in d){const E=d.kind==="unknown_action"?`no action named ${d.name} is declared from ${t.creatorCwd}`:`${d.name} is declared in ${d.configOrigin} but unusable: ${d.reason}`;throw new s(400,d.kind,E)}const p=n==null?null:await b(n);if(n&&!p)throw new s(404,"not_found","action requester node not found");if(p&&e.principal.class!=="person"&&p.grantee!==X(e.principal))throw new s(403,"permission_error","action requester belongs to another app");r=JSON.stringify({schema:"crtr.human-action-binding/v1",name:t.action.name,payload:t.action.payload,creatorCwd:t.creatorCwd,configOrigin:d.configOrigin,argv:d.argv,cwd:d.cwd,app:p?.grantee??(e.principal.class==="broker"?e.principal.app:"app:terminal")})}const a=k(t.page.dialect,t.page.source,t.source,t.delivery),u=await J({prepared:a,requester_node_id:t.requesterNodeId,...r===void 0?{}:{action_json:r}});return{status:201,body:{request_id:u.request_id,request_dir:u.request_dir,state:"pending",...t.action===void 0?{}:{action:{name:t.action.name}},delivery_state:"none"}}}o(ce,"handleCreate");async function ue(e){return{status:200,body:await y(await f(h(e)))}}o(ue,"handleGet");async function le(e){const t=await f(h(e));if(t.state==="settled")throw new s(409,"already_settled","the request already has a terminal result");const n=A(t),r=ne(e.body,n.delivery),a=k(r.page.dialect,r.page.source,n.source,r.delivery);try{await G(t.request_dir,a)}catch(u){throw u instanceof Error&&u.message===`page request is not open: ${t.request_id}`?new s(409,"already_settled","the request already has a terminal result"):u}return{status:200,body:await y(await f(t.request_id))}}o(le,"handleReplace");function O(e){return e instanceof s?e:e instanceof Error&&e.message.includes("unknown page request")?new s(404,"not_found","no request with that id"):e instanceof Error&&e.message==="page_has_no_response_lifecycle"?new s(409,"not_settleable","this request carries no response lifecycle"):new s(500,"internal","the request could not be settled")}o(O,"settlementError");function R(e){if(e.state==="settled")throw new s(409,"already_settled","the request already has a terminal result");if(!e.settleable)throw new s(409,"not_settleable","this request carries no response lifecycle")}o(R,"requireSettleable");async function fe(e){const t=await f(h(e)),n=re(e.body);R(t);try{await H(t.request_dir,n.responses)}catch(r){throw i(r instanceof Error?r.message:"the response map is invalid")}try{await U(t.request_id,n.responses,n.actor===void 0?{}:{actor:n.actor})}catch(r){throw O(r)}return{status:200,body:await y(await f(t.request_id))}}o(fe,"handleRespond");async function j(e,t){const n=await f(h(e)),r=oe(e.body);R(n);try{await L(n.request_id,{...r,disposition:t})}catch(a){throw O(a)}return{status:200,body:await y(await f(n.request_id))}}o(j,"settle");function pe(){return{status:200,body:{components:[...g()]}}}o(pe,"handleComponents");const Te=[{method:"GET",pattern:"/v1/human/components",handler:o(()=>pe(),"handler")},{method:"POST",pattern:"/v1/human/requests",scope:"crtr:act",handler:ce},{method:"GET",pattern:"/v1/human/requests/:request_id",handler:ue},{method:"POST",pattern:"/v1/human/requests/:request_id/replace",handler:le},{method:"POST",pattern:"/v1/human/requests/:request_id/respond",handler:fe},{method:"POST",pattern:"/v1/human/requests/:request_id/dismiss",handler:o(e=>j(e,"dismissed"),"handler")},{method:"POST",pattern:"/v1/human/requests/:request_id/cancel",handler:o(e=>j(e,"canceled"),"handler")}];export{Te as humanRequestRoutes};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { InboxPageDTO } from '../../../api/index.js';
|
|
2
2
|
import { type HumanRequestRecord } from '../../../core/human/requests.js';
|
|
3
3
|
/** Project the one SQL-selected page revision for every page reader. */
|
|
4
|
-
export declare function inboxPageProjection(request: HumanRequestRecord): InboxPageDTO
|
|
4
|
+
export declare function inboxPageProjection(request: HumanRequestRecord): Promise<InboxPageDTO>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s=Object.defineProperty;var r=(e,t)=>s(e,"name",{value:t,configurable:!0});import{readFileSync as n}from"node:fs";import{readPageFeedback as u}from"../../../core/human/feedback.js";import{pageModulePath as a,pagePath as l}from"../../../core/human/convention.js";import{parsePage as p}from"../../../core/human/page.js";import{presentationDir as f}from"../../../core/human/requests.js";import{readPageProgress as g,readTicketResult as m}from"../../../core/human/tickets.js";import{toPageFeedbackDTO as k}from"../map.js";function y(e){const t={kind:e.kind,step:e.step,config:e.config};return e.id!==void 0&&(t.id=e.id),e.unvalidated===!0&&(t.unvalidated=!0),e.display===!0&&(t.display=!0),t}r(y,"pageSlotToDTO");function b(e){const t={schema:"crtr.page/v2",dialect:e.dialect,title:e.title,delivery:e.delivery,document:e.document,steps:e.steps,slots:e.slots.map(y)};if(e.subtitle!==void 0&&(t.subtitle=e.subtitle),e.source!==void 0){const i={};e.source.sessionName!==void 0&&(i.sessionName=e.source.sessionName),e.source.askedBy!==void 0&&(i.askedBy=e.source.askedBy),e.source.emittedAt!==void 0&&(i.emittedAt=e.source.emittedAt),e.source.profileName!==void 0&&(i.profileName=e.source.profileName),e.source.nodeId!==void 0&&(i.nodeId=e.source.nodeId),Object.keys(i).length>0&&(t.source=i)}return t}r(b,"pageManifestToDTO");function _(e){return e.settleable?e.state!=="settled"?"pending":e.outcome==="canceled"||e.outcome==="dismissed"?"canceled":"resolved":"passive"}r(_,"state");async function v(e){const t=await m(e.request_dir);if(t===null)return null;if(t.kind==="page"||t.kind==="canceled")return t;throw new Error(`page request has an invalid terminal result: ${e.request_id}`)}r(v,"result");async function O(e){if(e.kind!=="page")throw new Error(`request is not a page: ${e.request_id}`);const t=f(e),i=p(t),o=n(l(t,i.dialect),"utf8"),c=i.dialect==="jsx"?n(a(t),"utf8"):o,d=e.settleable?await g(e.request_dir):null;return{ticket_id:e.inbox_ticket_id,kind:"page",state:_(e),revision:t,page:b(i),document:c,source_document:o,document_media_type:i.dialect==="jsx"?"text/jsx":"text/html",progress:d===null?null:{responses:d},result:await v(e),feedback:k(await u(e.request_dir))}}r(O,"inboxPageProjection");export{O as inboxPageProjection};
|
|
@@ -7,6 +7,6 @@ export interface ResolvedTicket {
|
|
|
7
7
|
}
|
|
8
8
|
/** Resolve one opaque inbox ticket id to its canonical directory. Shared with
|
|
9
9
|
* the feedback-comment routes, which address tickets by the same ids. */
|
|
10
|
-
export declare function resolveTicket(ticketId: InboxTicketIdDTO): ResolvedTicket | null
|
|
10
|
+
export declare function resolveTicket(ticketId: InboxTicketIdDTO): Promise<ResolvedTicket | null>;
|
|
11
11
|
export declare function requireTicketId(params: Record<string, string>): InboxTicketIdDTO;
|
|
12
12
|
export declare const inboxRoutes: RouteTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var g=Object.defineProperty;var
|
|
1
|
+
var g=Object.defineProperty;var a=(e,n)=>g(e,"name",{value:n,configurable:!0});import{ApiError as t}from"../../../api/index.js";import{inboxPageProjection as v}from"./inbox-page.js";import{getRequestByInboxTicket as p}from"../../../core/human/requests.js";import{getNode as _}from"../../../core/canvas/canvas.js";import{canReadNode as m}from"../router.js";import{parsePage as q}from"../../../core/human/page.js";import{scanInbox as T,scanPageHistory as I}from"../../../core/human/scan.js";import{readPageTicket as w,readTicketResult as h,selectedPageDir as A,validatePageTicketResponses as P,writePageProgress as x}from"../../../core/human/tickets.js";import{describePageAnswer as E}from"../../../core/human/answer.js";import{cancelHumanTicket as R,resolvePageTicket as O}from"../../human/finish.js";import{filterAsync as b}from"../../../core/async-array.js";const N="Canceled from the inbox.",S=1e3,C=/^[a-f0-9]{64}$/;async function c(e){const n=await p(e);return n===null?null:{ticketId:n.request_id,dir:n.request_dir,kind:n.kind}}a(c,"resolveTicket");function l(e){const n=e.ticket_id;if(n===void 0||!C.test(n))throw new t(400,"invalid_request","invalid ticket id");return n}a(l,"requireTicketId");function u(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}a(u,"isPlainObject");function k(e,n){for(const i of Object.keys(e))if(!n.includes(i))throw new t(400,"invalid_request",`unexpected field: ${i}`)}a(k,"requireNoExtraKeys");function D(e){if(!u(e))throw new t(400,"invalid_request","respond body is required");if(k(e,["responses"]),!u(e.responses))throw new t(400,"invalid_request","`responses` must be an object");return{responses:e.responses}}a(D,"validateRespondRequest");function j(e){if(!u(e))throw new t(400,"invalid_request","progress body is required");if(k(e,["responses"]),!u(e.responses))throw new t(400,"invalid_request","`responses` must be an object");return{responses:e.responses}}a(j,"validateProgressRequest");function G(e){if(e===void 0)return{};if(!u(e))throw new t(400,"invalid_request","cancel body must be an object");if(k(e,["reason"]),e.reason===void 0)return{};const n=e.reason;if(typeof n!="string")throw new t(400,"invalid_request","`reason` must be a string");if(n.trim()===""||n.length>S)throw new t(400,"invalid_request","`reason` must be nonempty after trim and at most 1000 characters");return{reason:n}}a(G,"validateCancelRequest");const L=[/^slot ".*?" /,/^response names unknown or non-response-bearing slot id/,/^final page response is missing response-bearing slot id/];function f(e){return e instanceof Error&&L.some(n=>n.test(e.message))}a(f,"isSlotValidationError");function y(e){const n={request_id:e.id,request_dir:e.dir,ticket_id:e.inboxTicketId,kind:"page",title:e.title,placement:e.placement,dialect:e.dialect,steps:e.steps,emitted_at:e.emittedAt,source:e.source,slot_kinds:e.slotKinds,inbox:e.inbox,awaits_response:e.awaitsResponse,state:e.state};return e.subtitle!==""&&(n.subtitle=e.subtitle),e.answerDigest!==void 0&&(n.answer_digest=e.answerDigest),e.recommendedOptions.length>0&&(n.recommended_options=e.recommendedOptions.map(i=>({slot_id:i.slotId,option_id:i.optionId,label:i.label}))),e.fastAction!==void 0&&(n.fast_action={kind:e.fastAction.kind,responses:e.fastAction.responses}),n}a(y,"pageSummaryToDTO");async function H(e){return{status:200,body:{tickets:(await b(await T(),async i=>{if(e.principal.class==="person")return!0;const s=await p(i.inboxTicketId),r=s?.requester_node_id?await _(s.requester_node_id):null;return r!==null&&await m(e.principal,r.grantee??"app:terminal",r.node_id)})).map(i=>{if(i.kind==="page")return y(i);if(i.kind==="review")return{request_id:i.id,request_dir:i.dir,ticket_id:i.inboxTicketId,kind:"review",title:i.title,subtitle:i.subtitle,blocked_since:i.blockedSince,source:i.source};throw new Error(`unknown ticket kind: ${i.kind}`)}).sort((i,s)=>{const r=a(d=>d.kind==="page"?d.emitted_at:d.blocked_since,"pageTime"),o=Date.parse(r(s))-Date.parse(r(i));return o!==0?o:i.ticket_id.localeCompare(s.ticket_id)})}}}a(H,"handleList");async function K(e){const n=e.query.get("node_id");if(n==="")throw new t(400,"invalid_request","node_id must be nonempty when present");return{status:200,body:{tickets:(await b(await I(n??void 0),async r=>{if(e.principal.class==="person")return!0;const o=await p(r.inboxTicketId),d=o?.requester_node_id?await _(o.requester_node_id):null;return d!==null&&await m(e.principal,d.grantee??"app:terminal",d.node_id)})).map(y)}}}a(K,"handleHistory");async function $(e){const n=l(e.params),i=await c(n);if(i===null)throw new t(404,"ticket_not_found","no matching ticket");if(i.kind==="review")throw new t(409,"ticket_kind_unsupported","review tickets have no page read operation");const s=await p(n);if(s===null||s.kind!=="page")throw new t(404,"ticket_not_found","no matching ticket");try{return{status:200,body:await v(s)}}catch{throw new t(500,"internal","the ticket could not be read")}}a($,"handleGetPage");async function V(e){const n=l(e.params),i=D(e.body),s=await c(n);if(s===null)throw new t(404,"ticket_not_found","no matching ticket");if(s.kind==="review")throw new t(409,"ticket_kind_unsupported","review tickets submit through their own path");if((await w(s.dir)).state==="passive")throw new t(409,"page_has_no_response_lifecycle","this page has no response lifecycle");const r=await h(s.dir);if(r!==null&&r.kind!=="canceled")throw new t(409,"ticket_already_resolved","ticket was already resolved");if(r?.kind==="canceled")throw new t(409,"ticket_canceled","canceled tickets cannot be answered");try{await P(s.dir,i.responses)}catch(o){throw f(o)?new t(400,"invalid_ticket_response",o.message):new t(500,"internal","validation failed")}try{const o=await O(s.ticketId,i.responses);if(o.kind!=="page")throw new t(409,"ticket_kind_mismatch","unexpected result kind");return{status:200,body:o}}catch(o){throw o instanceof t?o:f(o)?new t(400,"invalid_ticket_response",o.message):new t(500,"internal","the ticket could not be finalized")}}a(V,"handleRespond");async function z(e){const n=l(e.params),i=j(e.body),s=await c(n);if(s===null)throw new t(404,"ticket_not_found","no matching ticket");if(s.kind==="review")throw new t(409,"ticket_kind_unsupported","review tickets do not support progress autosave");if((await w(s.dir)).state==="passive")throw new t(409,"page_has_no_response_lifecycle","this page has no response lifecycle");const r=await h(s.dir);if(r!==null&&r.kind!=="canceled")throw new t(409,"ticket_already_resolved","ticket was already resolved");try{return await x(s.dir,i.responses),{status:200,body:{}}}catch(o){throw f(o)?new t(400,"invalid_ticket_response",o.message):new t(500,"internal","progress could not be saved")}}a(z,"handleProgress");async function B(e){const n=l(e.params),i=G(e.body),s=await c(n);if(s===null)throw new t(404,"ticket_not_found","no matching ticket");if(s.kind==="review")throw new t(409,"ticket_kind_unsupported","review tickets have their own cancel path");if((await w(s.dir)).state==="passive")throw new t(409,"page_has_no_response_lifecycle","this page has no response lifecycle");try{const r=await R(s.ticketId,{reason:i.reason??N,actor:"human",disposition:"dismissed"});if(r.outcome==="already_settled"||r.result.kind!=="canceled")throw new t(409,"ticket_already_resolved","ticket was already resolved");return{status:200,body:r.result}}catch(r){throw r instanceof t?r:new t(500,"internal","the ticket could not be canceled")}}a(B,"handleCancel");async function F(e){const n=l(e.params),i=await c(n);if(i===null)throw new t(404,"ticket_not_found","no matching ticket");if(i.kind==="review")throw new t(409,"ticket_kind_unsupported","review tickets fetch responses through their own path");const s=await h(i.dir);if(s===null)throw new t(404,"ticket_pending","ticket has no response yet");if(s.kind==="canceled")throw new t(404,"ticket_canceled","canceled tickets have no response");if(s.kind!=="page")throw new t(409,"ticket_kind_mismatch","unexpected result kind");try{const r=q(await A(i.dir));return{status:200,body:{...s,answer:E(r,s.responses,{completedAt:s.completedAt})}}}catch{throw new t(500,"internal","the ticket answer could not be read")}}a(F,"handleGetResponse");const se=[{method:"GET",pattern:"/v1/human/inbox",handler:H},{method:"GET",pattern:"/v1/human/inbox/history",handler:K},{method:"GET",pattern:"/v1/human/inbox/:ticket_id",handler:$},{method:"GET",pattern:"/v1/human/inbox/:ticket_id/response",handler:F},{method:"POST",pattern:"/v1/human/inbox/:ticket_id/respond",handler:V},{method:"POST",pattern:"/v1/human/inbox/:ticket_id/progress",handler:z},{method:"POST",pattern:"/v1/human/inbox/:ticket_id/cancel",handler:B}];export{se as inboxRoutes,l as requireTicketId,c as resolveTicket};
|
|
@@ -4,7 +4,7 @@ import { type SocketPrincipal } from '../server.js';
|
|
|
4
4
|
import { type SpendTarget } from '../../../core/usage/ledger.js';
|
|
5
5
|
/** Who a socket caller's model call bills: a broker's node bills its grant's app under
|
|
6
6
|
* that grant's cap; the person (and a local scoped token) bills the person's own agent, uncapped. */
|
|
7
|
-
export declare function spendTarget(principal: SocketPrincipal | undefined): SpendTarget
|
|
7
|
+
export declare function spendTarget(principal: SocketPrincipal | undefined): Promise<SpendTarget>;
|
|
8
8
|
/** `cap_exhausted` names when the count starts over and what the person can do (contract 2 error table). */
|
|
9
9
|
export declare function capFields(error: RunError): Record<string, unknown>;
|
|
10
10
|
export declare const llmRoutes: RouteTable;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var O=Object.defineProperty;var s=(e,t)=>O(e,"name",{value:t,configurable:!0});import{randomUUID as _}from"node:crypto";import{MODEL_CONTEXT_BODY_MAX_BYTES as S}from"../../../core/llm/body-limits.js";import{llmCallerOf as g,parseLlmRequest as E,runLlm as R}from"../../../core/llm/run.js";import{RunError as d}from"../../../core/runs/operations.js";import{errorCodes as T}from"../../../api/error-codes.js";import{getNode as q}from"../../../core/canvas/canvas.js";import{socketPrincipal as
|
|
2
|
-
`)}:void 0,u?{cwd:u.cwd,profileId:u.profile_id??null}:void 0,c,P(n));return r.stream?(t.headersSent||t.writeHead(200,{"content-type":"application/x-ndjson; charset=utf-8","cache-control":"no-cache"}),t.end(),{status:200}):{status:200,body:x.completion}}catch(r){if(t.headersSent){const n=r instanceof d?r:new d(503,"upstream_model_unavailable","model stream failed"),u=n.details&&typeof n.details=="object"&&!Array.isArray(n.details)?n.details:{},c=v(
|
|
3
|
-
`),{status:200}}if(r instanceof d){const n=v(r.details,
|
|
1
|
+
var O=Object.defineProperty;var s=(e,t)=>O(e,"name",{value:t,configurable:!0});import{randomUUID as _}from"node:crypto";import{MODEL_CONTEXT_BODY_MAX_BYTES as S}from"../../../core/llm/body-limits.js";import{llmCallerOf as g,parseLlmRequest as E,runLlm as R}from"../../../core/llm/run.js";import{RunError as d}from"../../../core/runs/operations.js";import{errorCodes as T}from"../../../api/error-codes.js";import{getNode as q}from"../../../core/canvas/canvas.js";import{socketPrincipal as i}from"../server.js";import{activeGrant as y,activeGrantForApp as w,grantFor as h,grantsSource as b,payerOfGrant as I}from"../../../core/grants/mirror.js";import{parseUsageMonth as N,UNCAPPED_GRANTEE as D,usageFor as G}from"../../../core/usage/ledger.js";function v(e,t){if(t==="broker"||t==="person"||t===void 0||!e||typeof e!="object"||Array.isArray(e)||!("rate_limit"in e))return e;const{rate_limit:o,...a}=e;return a}s(v,"operatorDetails");async function A(e){if(e?.class==="broker"){const t=e.grant?await y(e.grant):await h(e.app,e.sub);return{grantee:e.app,spend_cap:t&&t.grantee===e.app?t.spend_cap:null}}if(e?.class==="app"){const t=await b();if(t===null||t==="local")return{grantee:e.app,spend_cap:null};let o;try{o=await w(e.app)}catch{throw new d(401,"grant_revoked",`${e.app} has several active grants; a local token cannot name which user's cap applies`)}if(!o)throw new d(401,"grant_revoked",`${e.app} has no active grant`);return{grantee:e.app,spend_cap:o.spend_cap}}return{grantee:D,spend_cap:null}}s(A,"spendTarget");async function P(e){if(e?.class==="broker"){if(e.app==="app:terminal")return;const t=e.grant?await y(e.grant):await h(e.app,e.sub);if(!t&&await I(e.grant)==="app")throw new d(401,"grant_revoked",`${e.app}'s app-paid grant is no longer active`);return g(t&&t.grantee===e.app?t:null)}if(e?.class==="app"){const t=await b();return t===null||t==="local"?void 0:g(await w(e.app))}}s(P,"llmCaller");function k(e){const t=T[e.code];return t?t.type:e.status===429?"rate_limit_error":e.status<500?"invalid_request_error":"server_error"}s(k,"errorType");function U(e){if(e.code!=="cap_exhausted")return{};const t=e.details?.reset_at;return{...typeof t=="string"?{reset_at:t}:{},user_action:"raise_cap"}}s(U,"capFields");const Y=[{method:"POST",pattern:"/v1/llm",scope:"crtr:llm",maxBodyBytes:S,handler:s(async({body:e,res:t,req:o})=>{const a=_();t.setHeader("Request-Id",a);const m=new AbortController,p=s(()=>m.abort(),"abort");t.on("close",p);let l;try{const r=E(e),n=i(o),u=n?.class==="broker"?await q(n.node):null;if(n?.class==="broker"&&!u)throw new d(401,"unauthorized","node not found");const c=await A(n),x=await R(r,m.signal,r.stream?f=>{typeof f.served_model=="string"&&(l=f.served_model),t.headersSent||t.writeHead(200,{"content-type":"application/x-ndjson; charset=utf-8","cache-control":"no-cache"}),t.write(`${JSON.stringify(f)}
|
|
2
|
+
`)}:void 0,u?{cwd:u.cwd,profileId:u.profile_id??null}:void 0,c,await P(n));return r.stream?(t.headersSent||t.writeHead(200,{"content-type":"application/x-ndjson; charset=utf-8","cache-control":"no-cache"}),t.end(),{status:200}):{status:200,body:x.completion}}catch(r){if(t.headersSent){const n=r instanceof d?r:new d(503,"upstream_model_unavailable","model stream failed"),u=n.details&&typeof n.details=="object"&&!Array.isArray(n.details)?n.details:{},c=v(l!==void 0&&typeof u.served_model!="string"?{...u,served_model:l}:n.details,i(o)?.class);return t.end(`${JSON.stringify({error:{code:n.code,message:n.message,...c===void 0?{}:{details:c},type:"server_error",origin:"runtime",retryable:n.retryable,request_id:a}})}
|
|
3
|
+
`),{status:200}}if(r instanceof d){const n=v(r.details,i(o)?.class);return r.code==="all_routes_exhausted"&&t.setHeader("Retry-After",String(r.details.retry_after_s)),{status:r.status,body:{error:{code:r.code,message:r.message,...n===void 0?{}:{details:n},type:k(r),...r.param?{param:r.param}:{},origin:"runtime",retryable:r.retryable,request_id:a,...r.code==="all_routes_exhausted"?{retry_after_s:r.details.retry_after_s}:{},...U(r)}}}}throw r}finally{t.off("close",p)}},"handler")},{method:"GET",pattern:"/v1/usage",handler:s(async({req:e})=>{const t=_(),o={"Request-Id":t};try{const a=await A(i(e));return{status:200,headers:o,body:await G(a.grantee,a.spend_cap,N(new URL(e.url??"/","http://runtime.local").searchParams.get("month")))}}catch(a){if(!(a instanceof d))throw a;return{status:a.status,headers:o,body:{error:{code:a.code,message:a.message,type:k(a),...a.param?{param:a.param}:{},origin:"runtime",retryable:!1,request_id:t}}}}},"handler")}];export{U as capFields,Y as llmRoutes,A as spendTarget};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var l=Object.defineProperty;var i=(e
|
|
1
|
+
var l=Object.defineProperty;var i=(t,e)=>l(t,"name",{value:e,configurable:!0});import{ApiError as f}from"../../../api/index.js";import{getNode as w}from"../../../core/canvas/canvas.js";import{insertMemoryReads as b}from"../../../core/canvas/memory-reads.js";const p=500,u=512,v=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/;function r(t){return new f(400,"invalid_request",t)}i(r,"invalid");function y(t,e,o){if(typeof t!="string"||t.length===0||t.length>u)throw r(`events[${o}].${e} must be a non-empty string of at most ${u} characters`);return t}i(y,"text");function g(t){if(typeof t!="object"||t===null||Array.isArray(t))throw r("body must be an object");const e=Object.keys(t).filter(n=>n!=="events");if(e.length>0)throw r(`unknown body field: ${e.join(", ")}`);const o=t.events;if(!Array.isArray(o)||o.length<1||o.length>p)throw r(`events must be an array of 1\u2013${p} events`);return o.map((n,a)=>{if(typeof n!="object"||n===null||Array.isArray(n))throw r(`events[${a}] must be an object`);const s=n,m=Object.keys(s).filter(h=>!["name","scope","at","type"].includes(h));if(m.length>0)throw r(`events[${a}] has unknown field: ${m.join(", ")}`);if(s.type!=="read"&&s.type!=="loaded")throw r(`events[${a}].type must be "read" or "loaded"`);const d=s.at,c=typeof d=="string"&&v.test(d)?Date.parse(d):Number.NaN;if(!Number.isFinite(c))throw r(`events[${a}].at must be an ISO UTC timestamp`);return{name:y(s.name,"name",a),scope:y(s.scope,"scope",a),at:new Date(c).toISOString(),type:s.type}})}i(g,"parseEvents");async function A(t){const e=t.params.id??"",o=g(t.body),n=await w(e);if(!n||n.kind==="human")throw new f(404,"not_found","node not found");return await b(e,o),{status:204}}i(A,"handleMemoryReads");const M=[{method:"POST",pattern:"/v1/nodes/:id/memory-reads",handler:A}];export{p as MAX_MEMORY_READ_EVENTS,u as MAX_MEMORY_READ_TEXT,M as memoryReadsRoutes};
|
|
@@ -24,15 +24,15 @@ export interface MemoryDocument extends MemoryListItem {
|
|
|
24
24
|
}
|
|
25
25
|
/** The longest prefix of at most `max` bytes that ends on a whole UTF-8 character. */
|
|
26
26
|
export declare function utf8Prefix(buffer: Buffer, max: number): Buffer;
|
|
27
|
-
export declare function memoryList(principal: RequestPrincipal, query: URLSearchParams): {
|
|
27
|
+
export declare function memoryList(principal: RequestPrincipal, query: URLSearchParams): Promise<{
|
|
28
28
|
items: MemoryListItem[];
|
|
29
29
|
next_cursor: string | null;
|
|
30
|
-
}
|
|
31
|
-
export declare function memoryGet(principal: RequestPrincipal, query: URLSearchParams): MemoryDocument
|
|
32
|
-
export declare function handleMemoryOperation(name: string, principal: RequestPrincipal, query: URLSearchParams): {
|
|
30
|
+
}>;
|
|
31
|
+
export declare function memoryGet(principal: RequestPrincipal, query: URLSearchParams): Promise<MemoryDocument>;
|
|
32
|
+
export declare function handleMemoryOperation(name: string, principal: RequestPrincipal, query: URLSearchParams): Promise<{
|
|
33
33
|
status: number;
|
|
34
34
|
body: unknown;
|
|
35
|
-
}
|
|
35
|
+
}>;
|
|
36
36
|
/** Unix socket and v0 loopback: person, broker, and a scoped app token. */
|
|
37
37
|
export declare const memoryRoutes: RouteTable;
|
|
38
38
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
AND NOT EXISTS (SELECT 1 FROM revision_parents p WHERE p.parent = r.rowid) ORDER BY r.number DESC, r.rev_id LIMIT 1`).get(e.rowid),o=
|
|
1
|
+
var M=Object.defineProperty;var n=(t,e)=>M(t,"name",{value:e,configurable:!0});import{createHash as x}from"node:crypto";import{withCanvasWrite as N}from"../../../core/canvas/db.js";import{canRead as O}from"../../../core/graph/access.js";import{bodyOf as C}from"../../../core/graph/bodies.js";import{ensureOwner as H}from"../../../core/graph/objects.js";import{readerFor as j}from"../../../core/graph/reader.js";import{checkoutsForCwd as B}from"../../../core/graph/repo-sync/repos.js";import{RunError as g}from"../../../core/runs/operations.js";import{mapAsync as F}from"../../../core/async-array.js";const ie=new Set(["memory.list","memory.get"]),W=1024*1024,E=/^[A-Za-z0-9_-]+(\/[A-Za-z0-9_-]+)*$/,_=["knowledge","preference"],s=n((t,e)=>new g(400,"invalid_request",t,e),"invalid"),R=n(()=>new g(404,"not_found","no memory document by that name"),"notFound");function S(t){const e=t.get("store");if(e===null)throw s("store is required","store");if(e!=="user")throw s('store must be "user"',"store")}n(S,"store");function Y(t){const e=t.get("kind");if(e===null)return null;if(!_.includes(e))throw s("kind must be knowledge or preference","kind");return e}n(Y,"kindOf");function J(t){const e=t.get("limit");if(e===null)return 50;if(!/^(0|[1-9]\d*)$/.test(e)||Number(e)<1||Number(e)>100)throw s("limit must be an integer from 1 to 100","limit");return Number(e)}n(J,"limitOf");function z(t,e){return x("sha256").update(JSON.stringify(["user",t,e])).digest("base64url").slice(0,16)}n(z,"filterHash");function U(t,e){return Buffer.from(JSON.stringify({n:t,f:e}),"utf8").toString("base64url")}n(U,"encodeCursor");function $(t,e){if(t===null)return null;try{if(!/^[A-Za-z0-9_-]+$/.test(t))throw new Error("not base64url");const r=JSON.parse(Buffer.from(t,"base64url").toString("utf8"));if(typeof r.n=="string"&&E.test(r.n)&&r.f===e)return r.n}catch{}throw s("cursor is not the next_cursor of a previous page with the same store, path and kind","cursor")}n($,"decodeCursor");async function v(t){return await H(t,"person","local-user","user:local","user")}n(v,"personObject");async function b(t,e){return await j(t,e,async r=>await B(t,r))}n(b,"graphReader");async function A(t,e){const r=await t.prepare(`SELECT r.body_hash, r.created_at FROM revisions r WHERE r.document = ?
|
|
2
|
+
AND NOT EXISTS (SELECT 1 FROM revision_parents p WHERE p.parent = r.rowid) ORDER BY r.number DESC, r.rev_id LIMIT 1`).get(e.rowid),o=await t.prepare("SELECT created_at, author FROM revisions WHERE document = ? ORDER BY number, created_at LIMIT 1").get(e.rowid);if(!r||!o)throw R();return{head:r,first:o}}n(A,"revisions");async function I(t,e){const{head:r,first:o}=await A(t,e),a=e.name.lastIndexOf("/");return{name:e.name,folder:a<0?"":e.name.slice(0,a),kind:e.kind,preview:e.preview,summary:e.summary,privacy:e.privacy,revision:e.revision,created_at:o.created_at,updated_at:r.created_at}}n(I,"item");async function G(t,e){return e===null?null:(await t.prepare(`SELECT i.external_id FROM objects a
|
|
3
3
|
JOIN identities i ON i.object = CASE WHEN a.type = 'node' THEN a.owner ELSE a.rowid END AND i.scheme = 'app'
|
|
4
|
-
WHERE a.rowid = ?`).get(e)?.external_id??null}n(G,"granteeOf");function Z(t,e){if(t.length<=e)return t;let r=e;for(;r>0&&(t[r]&192)===128;)r--;return t.subarray(0,r)}n(Z,"utf8Prefix");const
|
|
4
|
+
WHERE a.rowid = ?`).get(e))?.external_id??null}n(G,"granteeOf");function Z(t,e){if(t.length<=e)return t;let r=e;for(;r>0&&(t[r]&192)===128;)r--;return t.subarray(0,r)}n(Z,"utf8Prefix");const L=200;async function P(t,e){S(e);const r=e.get("path");if(r!==null&&!E.test(r))throw s("path must be name segments of letters, digits, `_` or `-` joined by `/`","path");const o=Y(e),a=J(e),d=z(r,o);let i=$(e.get("cursor"),d);return await N(async u=>{const p=await b(u,t),m=await v(u),c=r===null?null:`${r}/`,w=o===null?_:[o],k=u.prepare(`SELECT o.*, d.summary, d.revision, d.source_path FROM objects o JOIN documents d ON d.object = o.rowid
|
|
5
5
|
WHERE o.owner = ? AND o.type = 'document' AND o.deleted_at IS NULL AND d.unlisted = 0
|
|
6
6
|
AND o.kind IN (?, ?) AND (? IS NULL OR substr(o.name, 1, length(?)) = ?) AND (? IS NULL OR o.name > ?)
|
|
7
|
-
ORDER BY o.name LIMIT ?`),
|
|
8
|
-
WHERE o.owner = ? AND o.type = 'document' AND o.name = ? AND o.deleted_at IS NULL AND o.kind IN ('knowledge', 'preference')`).get(
|
|
7
|
+
ORDER BY o.name LIMIT ?`),l=[];for(;;){const f=await k.all(m.rowid,w[0],w[w.length-1],c,c,c,i,i,L);for(const y of f)if(i=y.name,await O(u,p,y)&&l.push(y),l.length>a)break;if(l.length>a||f.length<L)break}const h=l.slice(0,a),T=l.length>a;return{items:await F(h,async f=>await I(u,f)),next_cursor:T?U(h[h.length-1].name,d):null}})}n(P,"memoryList");async function X(t,e){S(e);const r=e.get("name");if(r===null)throw s("name is required","name");if(!E.test(r))throw s("name must be segments of letters, digits, `_` or `-` joined by `/`","name");return await N(async o=>{const a=await b(o,t),d=await v(o),i=await o.prepare(`SELECT o.*, d.summary, d.revision, d.source_path FROM objects o JOIN documents d ON d.object = o.rowid
|
|
8
|
+
WHERE o.owner = ? AND o.type = 'document' AND o.name = ? AND o.deleted_at IS NULL AND o.kind IN ('knowledge', 'preference')`).get(d.rowid,r);if(!i||!await O(o,a,i))throw R();const{head:u,first:p}=await A(o,i),m=Buffer.from(C(u.body_hash,i.source_path),"utf8"),c=Z(m,W);return{...await I(o,i),body:c.toString("utf8"),size:m.length,truncated:c.length<m.length,grantee:await G(o,p.author)}})}n(X,"memoryGet");async function D(t,e,r){if(t==="memory.list")return{status:200,body:await P(e,r)};if(t==="memory.get")return{status:200,body:await X(e,r)};throw new g(404,"not_found","unknown operation")}n(D,"handleMemoryOperation");const se=[{method:"GET",pattern:"/v1/memory",handler:n(async t=>await D("memory.list",t.principal,t.query),"handler")},{method:"GET",pattern:"/v1/memory/document",handler:n(async t=>await D("memory.get",t.principal,t.query),"handler")}];export{W as MEMORY_BODY_MAX_BYTES,ie as MEMORY_OPERATIONS,D as handleMemoryOperation,X as memoryGet,P as memoryList,se as memoryRoutes,Z as utf8Prefix};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`)[0].slice(0,120)}u(
|
|
1
|
+
var ce=Object.defineProperty;var u=(t,e)=>ce(t,"name",{value:e,configurable:!0});import{randomBytes as ue}from"node:crypto";import{claimNodeMail as le,acknowledgeNodeMail as fe}from"../../../core/canvas/deliveries.js";import{nodeMailEntry as me}from"../../../core/feed/inbox.js";import{enqueueNodeMail as L,cancelPendingNodeMail as pe}from"../../../core/feed/messages.js";import{reviveNode as U}from"../../../core/runtime/revive.js";import{BrokerUnreachableError as D}from"../../../core/runtime/broker-request.js";import{isBrokerLive as R}from"../../../core/runtime/model-swap.js";import{deliverLive as ye,interruptLive as he}from"../../../core/runtime/interactive-deliver.js";import{isProfilePaused as we}from"../../../core/profiles/manifest.js";import{getNode as O,withFreshTerminalGuard as be}from"../../../core/canvas/canvas.js";import{getById as G,nodeObject as F,ownerForGrantee as ge}from"../../../core/graph/objects.js";import{recordActedOn as ve}from"../../../core/graph/edges.js";import{recordWatch as H}from"../../../core/graph/watches.js";import{publish as V}from"../../../core/graph/events.js";import{readerFor as K}from"../reader.js";import{canRead as _e}from"../../../core/graph/access.js";import{withCanvasWrite as k}from"../../../core/canvas/db.js";import{getPendingStructuredRequestForNode as Q}from"../../../core/canvas/structured-requests.js";import{cancelCronsOnWake as X}from"../../../core/canvas/crons.js";import{assertNotFinalized as M,assertFinalizedForReopen as ke,commitReopenResident as P}from"../../../core/runtime/reopen.js";import{admitLegacyStructuredOutput as Se}from"../../structured-requests/sidecar.js";import{assertOutputSchemaAccepted as $e}from"../../../core/runtime/structured-output.js";import{appendSituationalContext as E,formatSituationalProse as Ne}from"../../../core/runtime/situational-context.js";import{formatDataCard as Y}from"../../../shared/generated-context.js";import{hasNoNaturalCycle as je}from"../../../core/runtime/revive-all.js";import{recordPendingParkActivity as Ae}from"../../park-pending.js";import{wantsExecution as qe}from"../../reconcilers/node-lifecycle/wants-execution.js";import{hasFreshGroundState as Oe}from"../../../core/runtime/revive.js";import{CrtrError as Ce,notFound as C,usage as c}from"../../../core/errors.js";import{emitEvent as xe}from"../../../core/events/emit.js";import{assertScope as Re}from"../../../core/scopes.js";import{InputError as I}from"../../../core/io.js";import{ApiError as Fe}from"../../../api/index.js";import{describeObject as Me,stubOf as Pe}from"../../../core/peer/stubs.js";import{machineNameOf as Z}from"../../../core/peer/names.js";import{callerNode as Ee,callerStub as Ie,forwardVerb as ee,relayError as te,remoteStub as Te,unknownError as re,withMachine as ne}from"../../peer/forward.js";import{ownerOnly as Be}from"../router.js";const ze=["critical","urgent","normal","deferred"];function oe(t,e){if(typeof t!="object"||t===null||Array.isArray(t))throw c(`${e} must be an object { kind, facts?, body? }`);const a=t,n=a.kind;if(typeof n!="string"||n.trim()==="")throw c(`${e}.kind is required`);if(!n.includes(":"))throw c(`${e}.kind must be namespaced (contain ':'): ${n}`);const r={kind:n},o=a.facts;if(o!==void 0){if(typeof o!="object"||o===null||Array.isArray(o))throw c(`${e}.facts must be an object of string or number values`);const d={};for(const[l,m]of Object.entries(o)){if(typeof m!="string"&&typeof m!="number")throw c(`${e}.facts.${l} must be a string or number`);d[l]=m}r.facts=d}const s=a.body;if(s!==void 0){if(typeof s!="string")throw c(`${e}.body must be a string`);r.body=s}return r}u(oe,"parseCardRequest");function ae(t,e){try{return Y(t.kind,t.facts??{},t.body??"")}catch(a){throw c(`${e}: ${a instanceof Error?a.message:String(a)}`)}}u(ae,"renderCard");function We(t){if(typeof t!="object"||t===null)throw c("a message requires a JSON body { body, tier?, fresh? }");const e=t,a=e.body,n=e.fresh===!0,r=e.tier,o=e.situational_context,s=e.output_schema,d=typeof a=="string"&&a.trim()!=="",l=typeof o=="string"&&o.trim()!=="",m=typeof s=="string"&&s.trim()!=="",v=e.situational_card,S=e.context_cards,b=v===void 0?void 0:oe(v,"situational_card");if(S!==void 0&&!Array.isArray(S))throw c("context_cards must be an array of { kind, facts?, body? }");const p=S?.map((N,$)=>oe(N,`context_cards[${$}]`));if(b!==void 0&&typeof o=="string"&&o!=="")throw c("situational_card and situational_context are mutually exclusive");const w=b!==void 0||p!==void 0&&p.length>0;if(!n&&!d&&!l&&!m&&!w)throw c("a message requires a non-empty body (or fresh: true, situational_context, a runtime card, or output_schema)");if(n&&p!==void 0&&p.length>0)throw c("context_cards cannot ride a fresh revive (no inbox entry carries them)");if(r!==void 0&&!ze.includes(r))throw c(`invalid tier: ${String(r)} (expected critical|urgent|normal|deferred)`);const f={body:typeof a=="string"?a:""};r!==void 0&&(f.tier=r),n&&(f.fresh=!0),e.reopen===!0&&(f.reopen=!0),typeof o=="string"&&(f.situational_context=o),b!==void 0&&(f.situational_card=b),p!==void 0&&(f.context_cards=p),typeof s=="string"&&(f.output_schema=s),typeof e.from=="string"&&(f.from=e.from);const y=e.delivery;if(y!==void 0&&y!=="interactive")throw c(`invalid delivery: ${String(y)} (expected interactive)`);if(y==="interactive"){if(n||f.situational_context!==void 0||f.output_schema!==void 0)throw c("interactive delivery supports a body, runtime cards, and reopen only (no fresh, situational_context, or output_schema)");if(!d)throw c("interactive delivery requires a non-empty body");if(f.tier==="deferred")throw c("interactive delivery cannot be deferred");f.delivery="interactive"}return f}u(We,"parseSendBody");function Je(t){let e;try{e=JSON.parse(t)}catch{throw c("output_schema must be a JSON schema string")}if(typeof e!="object"||e===null||Array.isArray(e))throw c("output_schema must be a JSON schema object");return e}u(Je,"parseSchema");function Le(t){return t.split(`
|
|
2
|
+
`)[0].slice(0,120)}u(Le,"label");function ie(t,e){return e===null?"":Y("reopen-final-report",{report:`${t}/${e}`},"This node previously completed work. Read this final report before acting on the new instruction.")}u(ie,"previousFinalReportCard");async function Ue(t,e,a){if(a!==null&&a!=="human"&&(await G(t,a))?.type==="node"){const o=await F(t,a);return{actor:o,senderNode:o}}if(a==="human")return{actor:await ge(t,"user:local"),senderNode:null};const n=await K(t,e);return{actor:n.class==="person"?n.person:n.class==="app"?n.app:n.node,senderNode:n.class==="node"?n.node:null}}u(Ue,"messageActor");async function se(t,e,a,n,r,o){const s=await F(t,a),{actor:d,senderNode:l}=await Ue(t,e,n),m=r===null?{}:{pointer:r};await ve(t,d,s),l!==null&&l.rowid!==s.rowid&&await H(t,l,s,"message",{endsOn:o&&r!==null?`result:${r}`:"final"}),await V(t,{event:"messaged",object:s,actor:d,attrs:{},...m}),l!==null&&await V(t,{event:"sent",object:l,actor:l,attrs:{to:s.id},...m})}u(se,"recordMessage");function De(t,e){return new I({error:"deferred_no_natural_cycle",message:`${t} is ${e} with no natural next cycle ahead of it \u2014 a deferred message would never be delivered.`,next:"Use --tier normal, urgent, or critical to wake it now, or --reopen (with a body or --fresh) to re-task it first."})}u(De,"deferredNoNaturalCycle");async function Ge(t){if(!await Oe(t))throw new Fe(422,"unprocessable",`node ${t} has no goal/roadmap on disk \u2014 a fresh revive would resume amnesiac.`)}u(Ge,"assertRecoverableForFresh");function He(t,e){return t instanceof I?{error:t.payload.error,message:t.payload.message,next:t.payload.next,message_id:e}:t instanceof Ce?{error:t.code,message:t.message,message_id:e}:{error:"wake_failed",message:"the target could not be woken; see the daemon log",message_id:e}}u(He,"wakeFailure");async function Ve(t,e){const a=typeof t.body=="object"&&t.body!==null&&!Array.isArray(t.body)?{...t.body}:t.body;typeof a=="object"&&a!==null&&delete a.from;const n=await ee(t,e,{method:"POST",path:`/v1/nodes/${encodeURIComponent(e)}/messages`,body:a});if(n.kind==="local")return null;if(n.kind==="unknown")throw re(e,n.unreachable);if(n.status>=400)throw te(n.status,n.body);return await k(async r=>{const o=await Ee(r,t);if(o===null)return;const s=n.body?.object,d=await Te(r,e,"node",n.machine.id,s);await H(r,o,d,"message",{endsOn:"final"})}),{status:n.status,body:ne(n.body,n.machine)}}u(Ve,"forwardMessage");async function Ke(t){const e=await Qe(t);if(t.principal.class!=="forwarded"||typeof e.body!="object"||e.body===null)return e;const a=await k(async n=>{const r=await F(n,t.params.id);return await _e(n,await K(n,t),r)?await Me(n,r):{id:r.id,type:r.type,kind:null,name:r.id,owner:null}});return{...e,body:{...e.body,object:a}}}u(Ke,"handleMessage");async function Qe(t){const e=t.params.id,a=await Ve(t,e);if(a!==null)return a;const n=await O(e);if(n===null)throw C(`unknown node: ${e}`,{received:e});const r=We(t.body),o=r.tier??"normal",s=we(n.profile_id),d=t.principal.class==="forwarded"?await k(async i=>(await Ie(i,t))?.id??null):r.from??null;if(d!==null){const i=await O(d);i!==null&&Re(i,"crtr:act")}const l=d===null?null:await k(async i=>{const h=await G(i,d);return h===null?null:(await Pe(i,h))?.home_machine??null}),m=l===null?void 0:`${d} on ${Z(l)}`,v=t.principal.class==="broker"?t.principal.node:null,S=l===null?{}:{from_machine:Z(l)},b=r.body.trim()!=="",p=r.situational_card!==void 0?ae(r.situational_card,"situational_card"):r.situational_context!==void 0?Ne(r.situational_context.trim()):"",w=p!=="",f=(r.context_cards??[]).map((i,h)=>ae(i,`context_cards[${h}]`)),y=r.output_schema!==void 0&&r.output_schema.trim()!==""?Je(r.output_schema):null;y!==null&&await $e(y);let N=!1;const $=u(async i=>{if(!(y===null||N)){if(await Q(e)!==null)throw new I({error:"structured_request_conflict",message:`node ${e} already has a pending structured request`,next:"Wait for the current request to settle before requesting another structured result."});await Se(e,"oneoff",y,i),N=!0}},"ensureSchema");if(r.fresh){const i=r.reopen?await ke(e):null;r.reopen||await M(e),await Ge(e),await $(),w&&E(e,p),r.reopen&&await P(e,i,v);const h=await U(e,{resume:!1,capacity:"refuse"});return{status:201,body:{node_id:e,delivered:!1,revived:h.launch!==void 0}}}r.delivery==="interactive"&&!r.reopen&&await M(e);let T=!1,_="";if(r.delivery==="interactive"&&r.reopen&&(_=ie(e,await P(e,void 0,v)),T=!0),r.delivery==="interactive"&&await $(),r.delivery==="interactive"&&!s&&!n.run_id&&R(n))try{return w&&E(e,p),await ye(e,r.body,{cards:[..._===""?[]:[_],...w?[p]:[],...f],origin:d==="human"?{type:"human"}:{type:"runtime",kind:"inbox",entries:[{...d===null?{}:{from:d},...m===void 0?{}:{fromName:m},kind:"message",tier:o}]}}),await k(async h=>await se(h,t,e,d,null,!1)),await X(e),{status:201,body:{node_id:e,delivered:!0,revived:!1,delivered_via:"engine"}}}catch(i){if(!(i instanceof D))throw i}const B=u(async()=>{r.reopen||await M(e);const i=ue(16).toString("hex"),h=u(async q=>await se(q,t,e,d,i,y!==null),"withinEnqueue");await $(i),w&&E(e,p),r.reopen&&!T&&(_=ie(e,await P(e,void 0,v)));const x=[..._===""?[]:[_],...f],J=x.length>0?{cards:x}:{};if(b||y!==null){const q=b?r.body:`A one-off structured-output request has been granted. Submit a result matching the requested schema with the \`submit_result\` tool (\`request_id: "${(await Q(e))?.request_id??"<request-id>"}"\`) before you stop; after it is accepted, continue normally.`;return await L(e,{senderNodeId:d,...m===void 0?{}:{senderName:m},urgency:o,wake:1,kind:"message",messageId:i,withinEnqueue:h,label:Le(q),bodyJson:{body:q,...S,...w?{situational:!0}:{},...J}})}return await L(e,{senderNodeId:d,...m===void 0?{}:{senderName:m},urgency:o,wake:1,kind:"message",messageId:i,withinEnqueue:h,label:w?"(ambient context updated)":"(context delivered)",bodyJson:{...w?{situational:!0}:{},situationalOnly:!0,...J}})},"deliverImmediate"),g=await u(async()=>{if(o==="deferred"){const i=await be(e,je,B);if(i.kind==="missing")throw C(`unknown node: ${e}`,{received:e});if(i.kind==="terminal")throw De(e,i.status);return i.result}return await B()},"deliver")();g.urgency!=="deferred"&&await k(async()=>Ae(e));const j=await O(e);if(j===null)throw C(`unknown node: ${e}`,{received:e});n.frozen_at!==null&&await X(e);let z=!1,W=!1,A;if((r.reopen||j.lifecycle==="terminal"||!await qe(j))&&g.urgency!=="deferred"&&!s&&!R(j))try{const i=await U(e,{resume:!0,capacity:"freeze"});z=i.launch!==void 0,W=i.outcome==="frozen"}catch(i){A=He(i,g.messageId),xe({level:"error",event:"message.wake_failed",node_id:e,error:i,fields:{message_id:g.messageId,error_code:A.error}})}return{status:201,body:{node_id:e,delivered:!0,revived:z,...W?{not_revived_reason:"capacity_frozen"}:{},...A===void 0?{}:{wake_failed:A},delivered_at:g.createdAt,...g.urgency===o?{}:{delivered_tier:g.urgency},...r.delivery==="interactive"?{delivered_via:"inbox"}:{}}}}u(Qe,"handleMessageHere");async function Xe(t){const e=t.params.id,a=await ee(t,e,{method:"POST",path:`/v1/nodes/${encodeURIComponent(e)}/interrupt`,body:t.body});if(a.kind==="unknown")throw re(e,a.unreachable);if(a.kind==="remote"){if(a.status>=400)throw te(a.status,a.body);return{status:a.status,body:ne(a.body,a.machine)}}const n=await O(e);if(n===null)throw C(`unknown node: ${e}`,{received:e});const r=await pe(e,{senderNodeId:"human",kind:"message"});let o=!1;if(R(n))try{o=await he(e)!=="idle"}catch(d){if(!(d instanceof D))throw d}return{status:200,body:{node_id:e,outcome:o?"aborted_turn":r.length>0?"canceled_pending":"idle",aborted_turn:o,canceled_pending:r.length}}}u(Xe,"handleInterrupt");function de(t){if(typeof t.body!="object"||t.body===null||Array.isArray(t.body))throw c("mail requires an object body");const e=t.body;if(typeof e.execution_id!="string"||e.execution_id.trim()==="")throw c("execution_id is required");return e}u(de,"mailBody");async function Ye(t){const e=de(t),a=e.channel;if(a!=="wake"&&a!=="passive"&&a!=="deferred_run")throw c("channel must be wake, passive, or deferred_run");const n=await le(t.params.id,e.execution_id,a);return{status:200,body:{action:n.action,deliveries:n.deliveries.map(o=>({delivery_id:o.deliveryId,attempts:o.attempts,handoff:o.handoff,entry:{...me(o),seq:o.message.seq}}))}}}u(Ye,"handleMailClaim");async function Ze(t){const e=de(t);if(!Array.isArray(e.deliveries))throw c("deliveries must be an array");const a=e.deliveries.map(o=>{if(typeof o!="object"||o===null||Array.isArray(o))throw c("each delivery must be an object");const s=o;if(typeof s.delivery_id!="string"||s.delivery_id==="")throw c("delivery_id is required");if(!Number.isSafeInteger(s.attempts)||s.attempts<1)throw c("attempts must be a positive integer");if(s.disposition!=="acknowledged"&&s.disposition!=="released")throw c("disposition must be acknowledged or released");return{delivery_id:s.delivery_id,attempts:s.attempts,disposition:s.disposition}}),n=await fe(t.params.id,e.execution_id,a.map(o=>({deliveryId:o.delivery_id,attempts:o.attempts,disposition:o.disposition})));return{status:200,body:{action:n.action,results:n.results.map(o=>({delivery_id:o.deliveryId,outcome:o.outcome}))}}}u(Ze,"handleMailAcknowledge");const Wt=Be([{method:"POST",pattern:"/v1/nodes/:id/mail/claim",handler:Ye},{method:"POST",pattern:"/v1/nodes/:id/mail/acknowledge",handler:Ze}]),Jt=[{method:"POST",pattern:"/v1/nodes/:id/messages",scope:"crtr:act",handler:Ke},{method:"POST",pattern:"/v1/nodes/:id/interrupt",scope:"crtr:act",handler:Xe}];export{Wt as brokerMailRoutes,Ke as handleMessage,Jt as messageRoutes};
|
|
@@ -33,10 +33,10 @@ export declare class NodeEventTranslationState {
|
|
|
33
33
|
export declare function translateBrokerFrame(nodeId: string, frame: BrokerToClient, state?: NodeEventTranslationState): StreamEventPayload[];
|
|
34
34
|
declare class NodeEventStreams {
|
|
35
35
|
private readonly hubs;
|
|
36
|
-
subscribe(nodeId: string, after: number | undefined, subscriber: Subscriber): {
|
|
36
|
+
subscribe(nodeId: string, after: number | undefined, subscriber: Subscriber): Promise<{
|
|
37
37
|
unsubscribe: () => void;
|
|
38
38
|
terminal: boolean;
|
|
39
|
-
}
|
|
39
|
+
}>;
|
|
40
40
|
report(nodeId: string, report: ReportDTO): void;
|
|
41
41
|
}
|
|
42
42
|
export declare const nodeEventStreams: NodeEventStreams;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var O=Object.defineProperty;var o=(n,e)=>O(n,"name",{value:e,configurable:!0});import{randomUUID as q}from"node:crypto";import{ApiError as E}from"../../../api/errors.js";import{BrokerClient as C}from"../../../core/broker-client/client.js";import{getNode as
|
|
1
|
+
var O=Object.defineProperty;var o=(n,e)=>O(n,"name",{value:e,configurable:!0});import{randomUUID as q}from"node:crypto";import{ApiError as E}from"../../../api/errors.js";import{BrokerClient as C}from"../../../core/broker-client/client.js";import{getNode as m}from"../../../core/canvas/canvas.js";import{emitEvent as k}from"../../../core/events/emit.js";import{isPidAlive as B}from"../../../core/canvas/pid.js";import{BROKER_VIEW_SOCKET_WAIT_MS as M}from"../../../core/runtime/view-socket.js";import{toNodeOutcomeDTO as D}from"../map.js";import{reportsForNode as L}from"./reports.js";const $=15e3,P=6e4,I=250,j=512,x=256*1024,G=1e3,V=32*1024*1024;class H{static{o(this,"NodeEventRing")}events=[];bytes=0;nextSequence=1;earliestAvailable=1;append(e){const t={...e,sequence_number:this.nextSequence++},s=Buffer.byteLength(JSON.stringify(t),"utf8");if(s>x)return this.events=[],this.bytes=0,this.earliestAvailable=this.nextSequence,t;for(this.events.push(t),this.bytes+=s;this.events.length>j||this.bytes>x;){const r=this.events.shift();if(r===void 0)break;this.bytes-=Buffer.byteLength(JSON.stringify(r),"utf8"),this.earliestAvailable=r.sequence_number+1}return t}replay(e){if(e===void 0)return{gap:null,events:this.events};const t=e<this.earliestAvailable-1||e>=this.nextSequence?T(this.earliestAvailable):null;return{gap:t,events:t===null?this.events.filter(s=>s.sequence_number>e):this.events}}get empty(){return this.events.length===0}}function T(n){return{type:"error",error:{code:"stream_gap",message:"the requested event cursor is older than this daemon can resume",details:{earliest_sequence:n}}}}o(T,"streamGap");function z(n){return n===null?"arguments: null":Array.isArray(n)?`arguments: array (${n.length} items)`:typeof n=="object"?`arguments: object (${Object.keys(n).length} fields)`:`arguments: ${typeof n}`}o(z,"toolSummary");function b(n){if(typeof n!="object"||n===null)return"";const e=n.content;return typeof e=="string"?e:Array.isArray(e)?e.filter(t=>typeof t=="object"&&t!==null).filter(t=>t.type==="text"&&typeof t.text=="string").map(t=>t.text).join(""):""}o(b,"assistantText");class A{static{o(this,"NodeEventTranslationState")}toolSummaries=new Map;emittedAssistantText="";resetAssistantText(){this.emittedAssistantText=""}emitAssistantTextDelta(e){const t=b(e),s=t.startsWith(this.emittedAssistantText)?t.slice(this.emittedAssistantText.length):t;return this.emittedAssistantText=t,s}seedAssistantText(e){const t=b(e);return this.emittedAssistantText=t,t}}function J(n,e,t=new A){switch(e.type){case"message_start":return e.message.role==="assistant"&&t.resetAssistantText(),[];case"message_update":{if(e.message.role!=="assistant")return[];const s=t.emitAssistantTextDelta(e.message);return s===""?[]:[{type:"node.output_text.delta",node_id:n,delta:s}]}case"message_end":{if(e.message.role!=="assistant")return[];const s=b(e.message);return t.resetAssistantText(),[{type:"node.output_text.done",node_id:n,text:s}]}case"tool_execution_start":{const s=z(e.args);return t.toolSummaries.set(e.toolCallId,s),[{type:"node.tool_call.started",node_id:n,tool_call_id:e.toolCallId,tool:e.toolName,summary:s}]}case"tool_execution_end":{const s=t.toolSummaries.get(e.toolCallId)??"[arguments unavailable]";return t.toolSummaries.delete(e.toolCallId),[{type:"node.tool_call.completed",node_id:n,tool_call_id:e.toolCallId,tool:e.toolName,status:e.isError?"error":"ok",summary:s}]}case"turn_start":return[{type:"node.turn.started",node_id:n}];case"turn_end":return[{type:"node.turn.completed",node_id:n}];default:return[]}}o(J,"translateBrokerFrame");class W{static{o(this,"NodeEventHub")}nodeId;remove;ring=new H;subscribers=new Set;observer;observerErrorAt;poll;reconnect;idleClose;status;settledRevision;settledOutcome;settledSequence;snapshotSeeded=!1;reportsSeeded=!1;translationState=new A;fresh=!0;constructor(e,t){this.nodeId=e,this.remove=t}async subscribe(e,t){const s=this.fresh&&e!==void 0;this.fresh=!1,await this.start();const r=this.settledOutcome!==void 0,a=s?{gap:T(1),events:this.ring.replay(void 0).events}:this.ring.replay(e);r||(this.subscribers.add(t),this.status!=="dormant"&&await this.openObserver());let c=!1;return queueMicrotask(()=>{if(!c){a.gap!==null&&t(a.gap);for(const u of a.events)t(u)}}),r&&this.scheduleIdleClose(),{unsubscribe:o(()=>{c=!0,r||this.unsubscribe(t)},"unsubscribe"),terminal:r}}report(e){this.settledRevision===void 0&&this.publish({type:"node.report.pushed",node_id:this.nodeId,report:e})}async start(){this.idleClose!==void 0&&(clearTimeout(this.idleClose),this.idleClose=void 0),this.poll===void 0&&(await this.check(),this.settledRevision===void 0&&(await this.seedReports(),this.poll=setInterval(()=>this.checkDetached(),I)))}async seedReports(){if(!this.reportsSeeded){this.reportsSeeded=!0;for(const e of(await L(this.nodeId)).reverse())this.report(e)}}async check(){const e=await m(this.nodeId);if(e===null){this.fail("stream_error",`node ${this.nodeId} no longer exists`);return}const t=D(e);if(t!==null){this.settledRevision!==t.revision&&(this.settledRevision=t.revision,this.settledOutcome=t,this.settledSequence=this.publish({type:"node.settled",node_id:this.nodeId,outcome:t}).sequence_number,this.stopObserver(),this.stopPoll());return}const s=e.pi_pid===null?"dormant":e.status;if(s==="dormant"){this.observerErrorAt=void 0,this.status!=="dormant"&&(this.status=s,this.publish({type:"node.status.changed",node_id:this.nodeId,status:s}));return}this.status===void 0?this.status=s:this.status!=="dormant"&&this.status!==s&&(this.status=s,this.publish({type:"node.status.changed",node_id:this.nodeId,status:s})),await this.openObserver()}async openObserver(){if(this.observer!==void 0||this.subscribers.size===0)return;const e=new C(this.nodeId);this.observer=e,e.on("connect",()=>{(async()=>{this.observerErrorAt=void 0;const t=await m(this.nodeId);this.status==="dormant"&&t!==null&&t.pi_pid!==null&&(this.status=t.status,this.publish({type:"node.status.changed",node_id:this.nodeId,status:t.status})),e.send({type:"hello",role:"observer",client_id:q(),attends:!1})})().catch(t=>this.fail("stream_error",t instanceof Error?t.message:String(t)))}),e.on("frame",t=>{try{t.type==="welcome"&&this.seedSnapshot(t.snapshot);for(const s of J(this.nodeId,t,this.translationState))this.publish(s)}catch(s){this.fail("stream_error",s instanceof Error?s.message:String(s))}}),e.on("error",()=>{(async()=>{const t=await m(this.nodeId),s=Date.now();if(t!==null&&t.pi_pid!==null&&B(t.pi_pid)){if(this.observerErrorAt??=s,s-this.observerErrorAt<M)return;this.fail("stream_error","observer connection failed");return}this.observerErrorAt=void 0})().catch(t=>this.fail("stream_error",t instanceof Error?t.message:String(t)))}),e.on("close",()=>{this.observer===e&&(this.observer=void 0,!(this.subscribers.size===0||this.settledRevision!==void 0)&&(this.status!=="dormant"&&(this.publish({type:"node.status.changed",node_id:this.nodeId,status:"dormant"}),this.status="dormant"),this.scheduleReconnect()))}),e.connect()}seedSnapshot(e){if(this.snapshotSeeded)return;this.snapshotSeeded=!0;const t=e.messages.filter(r=>r.role==="assistant"),s=e.state.isStreaming?t.pop():void 0;for(const r of t)this.publish({type:"node.output_text.done",node_id:this.nodeId,text:b(r)});s!==void 0&&this.publish({type:"node.output_text.delta",node_id:this.nodeId,delta:this.translationState.seedAssistantText(s)})}scheduleReconnect(){this.reconnect===void 0&&(this.reconnect=setTimeout(()=>{this.reconnect=void 0,this.checkDetached()},I))}checkDetached(){this.check().catch(e=>k({level:"error",event:"api.node_events.check_failed",node_id:this.nodeId,error:e}))}publish(e){const t=this.ring.append(e);for(const s of[...this.subscribers])s(t);return t}fail(e,t){const s={type:"error",error:{code:e,message:t}};for(const r of[...this.subscribers])r(s);this.stopObserver(),this.stopPoll()}unsubscribe(e){this.subscribers.delete(e),this.subscribers.size===0&&this.scheduleIdleClose()}scheduleIdleClose(){this.idleClose===void 0&&(this.idleClose=setTimeout(()=>{this.stopObserver(),this.stopPoll(),this.remove()},P))}stopObserver(){this.reconnect!==void 0&&(clearTimeout(this.reconnect),this.reconnect=void 0);const e=this.observer;this.observer=void 0,e?.close()}stopPoll(){this.poll!==void 0&&(clearInterval(this.poll),this.poll=void 0)}}class F{static{o(this,"NodeEventStreams")}hubs=new Map;async subscribe(e,t,s){let r=this.hubs.get(e);return r===void 0&&(r=new W(e,()=>this.hubs.delete(e)),this.hubs.set(e,r)),await r.subscribe(t,s)}report(e,t){this.hubs.get(e)?.report(t)}}const K=new F;function U(n){const e=n.get("after");if(e===null||e==="")return{};if(!/^(?:0|[1-9]\d*)$/.test(e))throw new E(400,"invalid_request","`after` must be a non-negative integer");const t=Number(e);if(!Number.isSafeInteger(t))throw new E(400,"invalid_request","`after` must be a safe integer");return{after:t}}o(U,"parseQuery");function w(n){const{type:e,...t}=n;return`event: ${e}
|
|
2
2
|
data: ${JSON.stringify(t)}
|
|
3
3
|
|
|
4
|
-
`}o(
|
|
4
|
+
`}o(w,"sseRecord");async function Y(n){const e=n.params.id??"";if(await m(e)===null)throw new E(404,"node_not_found",`no node ${e}`);const{after:t}=U(n.query),{req:s,res:r}=n;r.writeHead(200,{"content-type":"text/event-stream; charset=utf-8","cache-control":"no-cache",connection:"keep-alive"});let a=!1,c=!1,u=!1,h=0;const d=[];let v,f;const _=o(()=>{r.writableEnded||r.end()},"finish"),p=o(()=>{if(!a){if(a=!0,f!==void 0&&clearInterval(f),v?.(),r.destroyed){d.length=0,h=0,_();return}if(u||d.length>0){c=!0;return}_()}},"close"),y=o(()=>{for(u=!1;d.length>0;){const i=d.shift();if(h-=Buffer.byteLength(i,"utf8"),!r.write(i)){u=!0,r.once("drain",y);return}}c&&_()},"flush"),N=o(()=>{if(a)return;d.length=0,h=0;const i=w({type:"error",error:{code:"stream_dropped",message:"stream reader is too slow"}});d.push(i),h=Buffer.byteLength(i,"utf8"),a=!0,c=!0,f!==void 0&&clearInterval(f),v?.(),u||y()},"dropSlowReader"),g=o(i=>{if(a)return!1;if(u||d.length>0){const l=Buffer.byteLength(i,"utf8");return d.length>=G||h+l>V?(N(),!1):(d.push(i),h+=l,!0)}return r.write(i)||(u=!0,r.once("drain",y)),!0},"write"),S=o((i,l)=>{a||g(w({type:"error",error:{code:i,message:l}})),p()},"fail"),R=o(i=>{try{if(!g(w(i)))return;(i.type==="node.settled"||i.type==="error"&&i.error.code!=="stream_gap")&&p()}catch(l){S("stream_error",l instanceof Error?l.message:String(l))}},"onEvent");f=setInterval(()=>{try{a||g(`: keepalive
|
|
5
5
|
|
|
6
|
-
`)}catch(i){S("stream_error",i instanceof Error?i.message:String(i))}}
|
|
6
|
+
`)}catch(i){S("stream_error",i instanceof Error?i.message:String(i))}},$),s.once("close",p);try{const i=await K.subscribe(e,t,R);v=i.unsubscribe,i.terminal&&queueMicrotask(p)}catch(i){S("stream_error",i instanceof Error?i.message:String(i))}return{status:200}}o(Y,"handleEvents");const ae=[{method:"GET",pattern:"/v1/nodes/:id/events",handler:Y}];export{H as NodeEventRing,A as NodeEventTranslationState,ae as nodeEventRoutes,K as nodeEventStreams,J as translateBrokerFrame};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _=Object.defineProperty;var a=(t,e)=>_(t,"name",{value:e,configurable:!0});import{setTimeout as h}from"node:timers/promises";import{ApiError as r}from"../../../api/errors.js";import{getNode as v}from"../../../core/canvas/canvas.js";import{withCanvasWrite as m,openDb as A}from"../../../core/canvas/db.js";import{enqueueLateOutcomeAction as O,readOutcomeAction as l,registerOutcomeAction as g,unregisterOutcomeAction as D}from"../../../core/canvas/outcome-actions.js";import{OUTCOME_PAYLOAD_MAX_BYTES as f}from"../../../core/canvas/types.js";import{composeNodeOutcomeDocument as N}from"../../../core/runtime/outcome-document.js";import{HUMAN_ACTION_NAME_PATTERN as k}from"../../../core/human/action-binding.js";import{resolveHumanAction as b}from"../../../core/human-actions.js";import{toNodeOutcomeDTO as p,toOutcomeDeliveryDTO as E}from"../map.js";import{waitSeconds as T}from"../long-poll-wait.js";const q=250;async function s(t){const e=await v(t);if(e===null)throw new r(404,"node_not_found",`no node ${t}`);return e}a(s,"requireNode");async function $(t){const e=p(t);return{node_id:t.node_id,state:e===null?"pending":"settled",outcome:e,node_status:t.status,deadline_at:t.deadline_at??null}}a($,"responseFor");async function L(t){const e=t.params.id??"",o=Date.now()+T("node-outcomes.get.119",t.query)*1e3;let n=await s(e);for(;p(n)===null&&Date.now()<o;)await h(Math.min(q,o-Date.now())),n=await s(e);return{status:200,body:await $(n)}}a(L,"handleGetOutcome");function j(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}a(j,"isPlainObject");function M(t){let e;try{e=JSON.stringify(t)}catch{throw new r(400,"invalid_request","`payload` must be JSON-serializable")}if(e===void 0)throw new r(400,"invalid_request","`payload` must be JSON-serializable");return Buffer.byteLength(e,"utf8")}a(M,"payloadBytes");function P(t){if(!j(t))throw new r(400,"invalid_request","request body must be an object");for(const o of Object.keys(t))if(o!=="action"&&o!=="payload")throw new r(400,"invalid_request",`unexpected field in request body: ${o}`);const e=t.action;if(typeof e!="string"||!k.test(e))throw new r(400,"invalid_request","`action` must be a declared action name");if(t.payload!==void 0&&M(t.payload)>f)throw new r(413,"payload_too_large",`serialized payload exceeds ${f} bytes`);return t.payload===void 0?{action:e}:{action:e,payload:t.payload}}a(P,"parseRegistration");function w(t,e){const o=e.delivery,n=Date.parse(e.object.created_at);return E({nodeId:t,actionName:e.actionName,state:o===null?"armed":o.state==="handed_off"?"running":o.state==="acknowledged"?"accepted":o.state,attempt:o?.attempts??0,nextAttemptAt:o?.nextAttemptAt??0,acceptedAt:o?.acknowledgedAt??null,permanentFailedAt:o?.failedAt??null,lastFailure:o?.lastFailure??null,createdAt:n,updatedAt:o?.updatedAt??e.updatedAt})}a(w,"outcomeView");function S(t){const e=t.outcome_reason;let o,n;return t.outcome_kind==="result"||e==="finished"||e==="declined"?(o="done",n="done"):e==="parked"?(o="done",n="parked"):e==="closed"||e==="retired"||e==="stranded"||e==="deadline_exceeded"?(o="canceled",n=null):(o="dead",n=null),{...t,status:o,intent:n,terminal_reason:e}}a(S,"nodeAtOutcome");function R(t,e){const o=b(t,e);if(!("kind"in o))return o;throw o.kind==="unknown_action"?new r(422,"unknown_action",`no action named ${t} is declared from ${e}`):new r(422,"invalid_action",`${t} is declared in ${o.configOrigin} but unusable: ${o.reason}`,{reason:o.reason,configOrigin:o.configOrigin})}a(R,"resolveAction");async function x(t){const e=t.params.id??"",o=await s(e),n=P(t.body),y=R(n.action,o.cwd);return await m(async d=>{const u=await l(d,e);if(u&&u.delivery!==null)throw new r(409,"outcome_delivery_settled","outcome delivery has already started or settled");const i=await s(e);if(await g(d,e,{actionName:n.action,...y,payload:n.payload}),i.outcome_at!==null){if(i.outcome_kind==null||i.outcome_reason==null||i.outcome_revision==null||i.outcome_at==null)throw new Error(`outcome latch is incomplete for node ${e}`);await O(d,e,await N({node:S(i),outcome:{kind:i.outcome_kind,reason:i.outcome_reason,at:i.outcome_at,revision:i.outcome_revision,detailJson:i.outcome_detail_json??null},finalReport:i.final_report}))}const c=await l(d,e);if(c===null)throw new Error(`outcome action was not registered for ${e}`);return{status:200,body:w(e,c)}})}a(x,"handlePutDelivery");async function z(t){const e=t.params.id??"",o=await l(await A(),e);if(o===null)throw new r(404,"outcome_delivery_not_found",`no outcome delivery for node ${e}`);return{status:200,body:w(e,o)}}a(z,"handleGetDelivery");async function F(t){const e=t.params.id??"";return await m(async o=>{if(!await D(o,e))throw new r(409,"outcome_delivery_settled","outcome delivery has already started or settled");return{status:204}})}a(F,"handleDeleteDelivery");const Q=[{method:"GET",pattern:"/v1/nodes/:id/outcome",handler:L},{method:"PUT",pattern:"/v1/nodes/:id/outcome-delivery",handler:x},{method:"GET",pattern:"/v1/nodes/:id/outcome-delivery",handler:z},{method:"DELETE",pattern:"/v1/nodes/:id/outcome-delivery",handler:F}];export{Q as nodeOutcomeRoutes};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var p=Object.defineProperty;var o=(e,r)=>p(e,"name",{value:r,configurable:!0});import{
|
|
1
|
+
var p=Object.defineProperty;var o=(e,r)=>p(e,"name",{value:r,configurable:!0});import{dirname as c,isAbsolute as l,join as f,resolve as h}from"node:path";import{appendRotatingRecord as y}from"../../../core/log.js";import{jobDir as b,messagesDir as g}from"../../../core/canvas/paths.js";import{parseNodeTelemetryRecord as w,writeNodeTelemetryRecord as _}from"./telemetry-record.js";import{openDb as v}from"../../../core/canvas/db.js";import{reportDocumentBody as N}from"../../../core/feed/inbox.js";import{reportRefNodeId as S}from"../../../shared/inbox-entry-body.js";import{writeNodeRecap as R}from"../../../core/canvas/node-recap.js";import{markStopSignal as T,consumeStopSignals as E,clearStopSignals as j}from"../../../core/runtime/stop-signals.js";import{notFound as s,usage as n}from"../../../core/errors.js";import{isBeneathRefusal as D,readFileBeneath as A}from"../../../core/spaces/open-beneath.js";import{requireCurrentExecution as u}from"./broker-recovery.js";async function i(e){if(e.body===null||typeof e.body!="object"||Array.isArray(e.body))throw n("node record requires a JSON object");const r=e.body;return await u(e.params.id,r.expected_execution_id),r}o(i,"body");function a(e,r){if(typeof e!="string")throw n(`${r} must be a string`);return e}o(a,"text");const M=[{method:"POST",pattern:"/v1/nodes/:id/records/log",handler:o(async e=>{const r=a((await i(e)).record,"record");return{status:200,body:{appended:y(f(b(e.params.id),"log.jsonl"),r)}}},"handler")},{method:"PUT",pattern:"/v1/nodes/:id/records/telemetry",handler:o(async e=>(_(e.params.id,w(await i(e))),{status:204}),"handler")},{method:"PUT",pattern:"/v1/nodes/:id/records/recap",handler:o(async e=>(R(e.params.id,a((await i(e)).briefing,"briefing")),{status:204}),"handler")},{method:"GET",pattern:"/v1/nodes/:id/records/inbox",handler:o(async e=>{const r=e.params.id,d=e.query.get("ref");if(await u(r,e.query.get("execution_id")),d===null||S(d)===void 0)throw n("ref must be a report handle");const t=await(await v()).prepare(`SELECT m.object_id FROM deliveries d JOIN messages m ON m.message_id = d.message_id
|
|
2
2
|
WHERE d.destination_id = ? AND d.state = 'handed_off'
|
|
3
|
-
AND d.claim_owner = ? AND d.canceled_at IS NULL AND m.body_ref = ? LIMIT 1`).get(r,e.query.get("execution_id"),d);if(t===void 0)throw
|
|
3
|
+
AND d.claim_owner = ? AND d.canceled_at IS NULL AND m.body_ref = ? LIMIT 1`).get(r,e.query.get("execution_id"),d);if(t===void 0)throw s("report was not delivered to this node");const m=t.object_id===null?null:await N(t.object_id);if(m===null)throw s("report not found");return{status:200,body:{content:m}}},"handler")},{method:"GET",pattern:"/v1/nodes/:id/records/passive",handler:o(e=>{const r=e.query.get("ref"),d=g(e.params.id);if(r===null||!l(r)||c(h(r))!==d||!r.endsWith(".md"))throw n("ref must be a direct-message spill path for this node");try{return{status:200,body:{content:A(d,r).toString("utf8")}}}catch(t){throw t.code==="ENOENT"?s("passive message not found"):D(t)?n("ref meets a symlink or is not a regular file; only the node's own message files are served"):t}},"handler")},{method:"POST",pattern:"/v1/nodes/:id/records/pushed-final",handler:o(async e=>{const r=await i(e);if(r.action==="mark")T(e.params.id,"pushedFinal",a(r.expected_execution_id,"expected_execution_id"));else if(r.action==="clear")j(e.params.id);else{if(r.action==="consume")return{status:200,body:E(e.params.id,a(r.expected_execution_id,"expected_execution_id"))};throw n("action must be mark, clear or consume")}return{status:200,body:{pushedFinal:!1}}},"handler")}];export{M as nodeRecordRoutes};
|