@north-light/cli 0.3.750 → 0.3.752

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.
Files changed (70) hide show
  1. package/dist/api/contract.d.ts +1 -1
  2. package/dist/api/contract.js +1 -1
  3. package/dist/api/dto/environments.d.ts +37 -0
  4. package/dist/api/routes.d.ts +2 -0
  5. package/dist/api/routes.js +1 -1
  6. package/dist/builtin-memory/crouter-sdk/release-notes.md +10 -0
  7. package/dist/clients/attach/viewer.js +1 -1
  8. package/dist/core/canvas/schema-pg/037-grant-principals.sql +50 -0
  9. package/dist/core/canvas/schema-version.d.ts +1 -1
  10. package/dist/core/canvas/schema-version.js +1 -1
  11. package/dist/core/environments.js +1 -1
  12. package/dist/core/grants/local.js +1 -1
  13. package/dist/core/grants/mirror.d.ts +11 -3
  14. package/dist/core/grants/mirror.js +12 -12
  15. package/dist/core/grants/shadow.js +1 -1
  16. package/dist/core/grants/sync.js +1 -1
  17. package/dist/core/graph/objects.d.ts +3 -1
  18. package/dist/core/graph/objects.js +10 -10
  19. package/dist/core/ledger/payer.d.ts +4 -4
  20. package/dist/core/ledger/payer.js +1 -1
  21. package/dist/core/llm/app-rungs.js +1 -1
  22. package/dist/core/llm/run.d.ts +2 -2
  23. package/dist/core/llm/run.js +2 -2
  24. package/dist/core/profiles/manifest.d.ts +5 -0
  25. package/dist/core/profiles/manifest.js +1 -1
  26. package/dist/core/runtime/runner/blaxel/image-build.d.ts +10 -11
  27. package/dist/core/runtime/runner/blaxel/image-build.js +7 -6
  28. package/dist/core/runtime/start-check.js +1 -1
  29. package/dist/daemon/api/app-listener.js +12 -12
  30. package/dist/daemon/api/handlers/app-environments.d.ts +2 -0
  31. package/dist/daemon/api/handlers/app-environments.js +1 -0
  32. package/dist/daemon/api/handlers/git-credential.js +1 -1
  33. package/dist/daemon/api/handlers/runs.js +1 -1
  34. package/dist/daemon/api/operations.js +1 -1
  35. package/dist/daemon/api/principal.d.ts +11 -5
  36. package/dist/daemon/api/principal.js +1 -1
  37. package/dist/daemon/api/server.js +1 -1
  38. package/dist/daemon/crtrd.js +12 -12
  39. package/dist/daemon/reconcilers/recipe-image.d.ts +2 -0
  40. package/dist/daemon/reconcilers/recipe-image.js +5 -5
  41. package/docs/ci-runner.md +1 -1
  42. package/docs/sdk/release-notes.md +10 -0
  43. package/package.json +3 -3
  44. package/packages/crouter-api/dist/api/contract.js +1 -1
  45. package/packages/crouter-api/dist/api/routes.js +2 -0
  46. package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
  47. package/packages/crouter-api/dist/core/environments.js +3 -2
  48. package/packages/crouter-api/dist/core/grants/local.js +1 -1
  49. package/packages/crouter-api/dist/core/grants/mirror.js +35 -11
  50. package/packages/crouter-api/dist/core/grants/shadow.js +4 -2
  51. package/packages/crouter-api/dist/core/grants/sync.js +5 -4
  52. package/packages/crouter-api/dist/core/graph/objects.js +2 -2
  53. package/packages/crouter-api/dist/core/ledger/payer.js +8 -3
  54. package/packages/crouter-api/dist/core/llm/app-rungs.js +2 -2
  55. package/packages/crouter-api/dist/core/llm/run.js +3 -2
  56. package/packages/crouter-api/dist/core/profiles/manifest.js +1 -1
  57. package/packages/crouter-api/dist/core/runtime/runner/blaxel/image-build.js +42 -44
  58. package/packages/crouter-api/dist/core/runtime/start-check.js +2 -2
  59. package/packages/crouter-api/dist/daemon/api/handlers/git-credential.js +12 -2
  60. package/packages/crouter-api/dist/daemon/api/operations.js +4 -0
  61. package/packages/crouter-api/dist/daemon/api/principal.js +26 -7
  62. package/packages/crouter-api/dist/daemon/reconcilers/recipe-image.js +9 -1
  63. package/packages/crouter-api/package.json +1 -1
  64. package/packages/crouter-identity/dist/index.d.ts +4 -2
  65. package/packages/crouter-identity/dist/index.js +31 -12
  66. package/packages/crouter-identity/package.json +1 -1
  67. package/packages/crouter-plugin/dist/serve.js +4 -1
  68. package/packages/crouter-plugin/dist/verify.js +36 -8
  69. package/packages/crouter-plugin/package.json +3 -3
  70. package/runtime.lock.json +14 -14
@@ -1 +1 @@
1
- var a=Object.defineProperty;var r=(e,s)=>a(e,"name",{value:s,configurable:!0});const n=[{name:"conversation.create",method:"POST",path:"/v1/conversations",classes:["broker"],resource:"none"},{name:"conversation.list",method:"GET",path:"/v1/conversations",classes:["broker","person"],resource:"none"},{name:"conversation.append",method:"POST",path:"/v1/conversations/:id/entries",classes:["broker"],resource:"none"},{name:"conversation.commit",method:"POST",path:"/v1/conversations/:id/commit",classes:["broker"],resource:"none"},{name:"conversation.read",method:"GET",path:"/v1/conversations/:id",classes:["broker","person"],resource:"none"},{name:"conversation.header",method:"GET",path:"/v1/conversations/:id/header",classes:["broker","person"],resource:"none"},{name:"conversation.replace",method:"PUT",path:"/v1/conversations/:id",classes:["broker"],resource:"none"},{name:"conversation.fork",method:"POST",path:"/v1/conversations/:id/fork",classes:["broker"],resource:"none"},{name:"conversation.delete",method:"DELETE",path:"/v1/conversations/:id",classes:["broker"],resource:"none"},{name:"health",method:"GET",path:"/v1/health",classes:["anonymous"],resource:"none",stage:"v0.5"},{name:"ready",method:"GET",path:"/v1/ready",classes:["anonymous"],resource:"none",stage:"v0.5"},{name:"chat-inventory.get.1",method:"GET",path:"/v1/nodes/:id/chat-inventory",classes:["person","broker","cron"],resource:"node-read"},{name:"settings.get",method:"GET",path:"/v1/settings",classes:["person","broker"],resource:"none"},{name:"settings.put",method:"PUT",path:"/v1/settings",classes:["person","broker"],resource:"none"},{name:"model-config.put.2",method:"PUT",path:"/v1/model-config",classes:["person","broker"],resource:"none"},{name:"files.get.3",method:"GET",path:"/v1/files/peek",classes:["person","broker"],resource:"none"},{name:"files.post.4",method:"POST",path:"/v1/files/write",classes:["person","broker"],resource:"none"},{name:"files.get.5",method:"GET",path:"/v1/files/list",classes:["person","broker"],resource:"none"},{name:"reviews.post.6",method:"POST",path:"/v1/human/reviews",classes:["person","broker"],resource:"human",scope:"crtr:act"},{name:"reviews.get.7",method:"GET",path:"/v1/human/reviews",classes:["person","broker"],resource:"human"},{name:"reviews.get.8",method:"GET",path:"/v1/human/reviews/:review_id",classes:["person","broker"],resource:"human"},{name:"reviews.post.9",method:"POST",path:"/v1/human/reviews/:review_id/submit",classes:["person","broker"],resource:"human"},{name:"reviews.post.10",method:"POST",path:"/v1/human/reviews/:review_id/cancel",classes:["person","broker"],resource:"human"},{name:"reviews.get.11",method:"GET",path:"/v1/human/reviews/:review_id/document",classes:["person","broker"],resource:"human"},{name:"feedback-comments.post.12",method:"POST",path:"/v1/human/inbox/:ticket_id/feedback-comments",classes:["person","broker"],resource:"human"},{name:"feedback-comments.post.13",method:"POST",path:"/v1/human/inbox/:ticket_id/feedback-comments/:comment_id/resolve",classes:["person","broker"],resource:"human"},{name:"node.log.append",method:"POST",path:"/v1/nodes/:id/records/log",classes:["person","broker"],resource:"node-own"},{name:"node.summaries.put",method:"PUT",path:"/v1/nodes/:id/records/summaries",classes:["person","broker"],resource:"node-own"},{name:"node.attachments.list",method:"GET",path:"/v1/nodes/:id/attachments",classes:["person","broker"],resource:"node-own"},{name:"node.attachments.read",method:"GET",path:"/v1/nodes/:id/attachments/:sha256",classes:["person","broker"],resource:"node-own"},{name:"node.telemetry.put",method:"PUT",path:"/v1/nodes/:id/records/telemetry",classes:["person","broker"],resource:"node-own"},{name:"node.recap.put",method:"PUT",path:"/v1/nodes/:id/records/recap",classes:["person","broker"],resource:"node-own"},{name:"node.inbox.read",method:"GET",path:"/v1/nodes/:id/records/inbox",classes:["person","broker"],resource:"node-own"},{name:"node.passive.read",method:"GET",path:"/v1/nodes/:id/records/passive",classes:["person","broker"],resource:"node-own"},{name:"node.pushed-final",method:"POST",path:"/v1/nodes/:id/records/pushed-final",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.14",method:"POST",path:"/v1/nodes/:id/broker/session-bound",classes:["person","broker"],resource:"node-own"},{name:"broker.cycle-start",method:"POST",path:"/v1/nodes/:id/broker/cycle-start",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.15",method:"POST",path:"/v1/nodes/:id/broker/settle",classes:["person","broker"],resource:"node-own"},{name:"broker.cycle",method:"POST",path:"/v1/nodes/:id/broker/cycle",classes:["broker"],resource:"node-own"},{name:"broker.idle",method:"POST",path:"/v1/nodes/:id/broker/idle",classes:["broker"],resource:"node-own"},{name:"broker-ops.post.16",method:"POST",path:"/v1/nodes/:id/broker/park-complete",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.17",method:"POST",path:"/v1/nodes/:id/broker/park-activity",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.18",method:"POST",path:"/v1/nodes/:id/broker/telemetry",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.19",method:"POST",path:"/v1/nodes/:id/broker/model",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.get.20",method:"GET",path:"/v1/nodes/:id/broker/extension-state",classes:["person","broker"],resource:"node-own"},{name:"broker.signals",method:"GET",path:"/v1/nodes/:id/broker/signals",classes:["broker"],resource:"node-own",stream:!0},{name:"nodes.broker-structured-request",method:"GET",path:"/v1/nodes/:id/broker/structured-request",classes:["person","broker"],resource:"node-own"},{name:"nodes.broker-goal",method:"POST",path:"/v1/nodes/:id/broker/goal",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.21",method:"POST",path:"/v1/nodes/:id/broker/generated-name",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.22",method:"POST",path:"/v1/nodes/:id/broker/persona-ack",classes:["person","broker"],resource:"node-own"},{name:"objects.read",method:"GET",path:"/v1/objects/:ref",classes:["person","app","broker","cron","forwarded"],resource:"objects",stage:"objects"},{name:"objects.list",method:"GET",path:"/v1/objects",classes:["person","app","broker","cron","forwarded"],resource:"objects",stage:"objects"},{name:"objects.search",method:"POST",path:"/v1/objects/search",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"objects.watch",method:"POST",path:"/v1/objects/:ref/watch",classes:["anonymous","person","app","broker","cron","forwarded"],resource:"objects",stage:"objects"},{name:"objects.unwatch",method:"DELETE",path:"/v1/objects/:ref/watch",classes:["anonymous","person","app","broker","cron","forwarded"],resource:"objects",stage:"objects"},{name:"objects.shares",method:"GET",path:"/v1/objects/:ref/shares",classes:["person","broker"],resource:"objects",stage:"objects"},{name:"objects.share",method:"POST",path:"/v1/objects/:ref/shares",classes:["person","broker"],resource:"objects",stage:"objects"},{name:"objects.unshare",method:"DELETE",path:"/v1/objects/:ref/shares",classes:["person","broker"],resource:"objects",stage:"objects"},{name:"custom-objects.register",method:"POST",path:"/v1/custom-objects",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"custom-objects.publish",method:"POST",path:"/v1/custom-objects/:ref/events",classes:["anonymous","person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"custom-objects.unregister",method:"DELETE",path:"/v1/custom-objects/:ref",classes:["anonymous","person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"custom-objects.receive",method:"GET",path:"/v1/custom-objects/:ref/deliveries",classes:["anonymous","person","app","broker","cron"],resource:"objects",stream:!0,stage:"objects"},{name:"custom-objects.ack",method:"POST",path:"/v1/custom-objects/:ref/deliveries/ack",classes:["anonymous","person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"objects.edges",method:"GET",path:"/v1/objects/:ref/edges",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.write",method:"POST",path:"/v1/docs",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.edit",method:"PATCH",path:"/v1/docs/:ref",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.move",method:"POST",path:"/v1/docs/:ref/move",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.delete",method:"DELETE",path:"/v1/docs/:ref",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.history",method:"GET",path:"/v1/docs/:ref/history",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"schemas.register",method:"POST",path:"/v1/schemas",classes:["app"],resource:"objects",stage:"objects"},{name:"relations.write",method:"POST",path:"/v1/relations",classes:["app"],resource:"objects",stage:"objects"},{name:"relations.replace",method:"PUT",path:"/v1/relations",classes:["app"],resource:"objects",stage:"objects"},{name:"relations.list",method:"GET",path:"/v1/relations",classes:["app"],resource:"objects",stage:"objects"},{name:"check",method:"POST",path:"/v1/check",classes:["app"],resource:"objects",stage:"objects"},{name:"docs.lint",method:"POST",path:"/v1/docs/lint",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"plugins.app-token",method:"GET",path:"/v1/plugins/:name/app-token",classes:["person","broker"],resource:"none"},{name:"plugins.call-headers",method:"POST",path:"/v1/plugins/:name/call-headers",classes:["person","broker"],resource:"none"},{name:"documents.browser-access",method:"GET",path:"/v1/documents/browser-access",classes:["person"],resource:"none"},{name:"documents.reconcile-packages",method:"POST",path:"/v1/documents/reconcile-packages",classes:["person","broker"],resource:"none"},{name:"nodes.delivery",method:"POST",path:"/v1/nodes/:id/delivery",classes:["person","broker"],resource:"node-own"},{name:"delivery.dry-run",method:"POST",path:"/v1/delivery/dry-run",classes:["person","broker"],resource:"none"},{name:"bash-jobs.background",method:"POST",path:"/v1/nodes/:id/jobs/:jobId/background",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"health.get.33",method:"GET",path:"/healthz",classes:["anonymous"],resource:"none"},{name:"health.get.34",method:"GET",path:"/v1/status",classes:["person","broker"],resource:"none"},{name:"daemon.due",method:"GET",path:"/v1/due",classes:["person","broker"],resource:"none"},{name:"bash-jobs.report",method:"POST",path:"/v1/nodes/:id/jobs/:jobId/report",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"bash-jobs.patch",method:"PATCH",path:"/v1/nodes/:id/jobs/:jobId",classes:["person","broker"],resource:"node-write"},{name:"files.create",method:"POST",path:"/v1/nodes/:id/files",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"files.complete",method:"POST",path:"/v1/nodes/:id/files/:fileId/complete",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"node-uploads.create",method:"POST",path:"/v1/nodes/:id/uploads",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"node-uploads.link",method:"POST",path:"/v1/nodes/:id/uploads/:uploadId/link",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"bash-jobs.start",method:"POST",path:"/v1/nodes/:id/jobs/start",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"hooks.plan",method:"GET",path:"/v1/nodes/:id/hooks/plan",classes:["broker"],resource:"node-own"},{name:"hooks.exec",method:"POST",path:"/v1/nodes/:id/hooks/exec",classes:["broker"],resource:"node-own"},{name:"hooks.exec.person",method:"POST",path:"/v1/hooks/exec",classes:["person","broker"],resource:"none"},{name:"bash-jobs.get.35",method:"GET",path:"/v1/nodes/:id/jobs",classes:["person","broker","cron"],resource:"node-read"},{name:"bash-jobs.output",method:"GET",path:"/v1/nodes/:id/jobs/:jobId/output",classes:["person","broker","cron"],resource:"node-read"},{name:"bash-jobs.delete.36",method:"DELETE",path:"/v1/nodes/:id/jobs/:jobId",classes:["person","broker"],resource:"node-write"},{name:"prospective-chat-inventory.get.37",method:"GET",path:"/v1/prospective-chat-inventory",classes:["person","broker"],resource:"none"},{name:"node-events.get.38",method:"GET",path:"/v1/nodes/:id/events",classes:["person","broker","cron"],resource:"node-read"},{name:"bash.post.39",method:"POST",path:"/v1/bash",classes:["person","broker"],resource:"daemon-bash",scope:"crtr:act"},{name:"subscriptions.post.40",method:"POST",path:"/v1/nodes/:id/subscriptions",classes:["person","broker"],resource:"node-write"},{name:"subscriptions.delete.41",method:"DELETE",path:"/v1/nodes/:id/subscriptions/:target",classes:["person","broker"],resource:"node-write"},{name:"attach.post.42",method:"POST",path:"/v1/nodes/:id/attach",classes:["person","broker"],resource:"node-write"},{name:"review-comments.post.44",method:"POST",path:"/v1/human/reviews/self/comments",classes:["person","broker"],resource:"human"},{name:"review-comments.get.45",method:"GET",path:"/v1/human/reviews/self/comments",classes:["person","broker"],resource:"human"},{name:"review-comments.post.46",method:"POST",path:"/v1/human/reviews/:review_id/comments",classes:["person","broker"],resource:"human"},{name:"review-comments.get.47",method:"GET",path:"/v1/human/reviews/:review_id/comments",classes:["person","broker"],resource:"human"},{name:"review-comments.get.48",method:"GET",path:"/v1/human/reviews/:review_id/comment-events",classes:["person","broker"],resource:"human"},{name:"review-comments.post.49",method:"POST",path:"/v1/human/reviews/:review_id/comment-ranges",classes:["person","broker"],resource:"human"},{name:"review-comments.get.50",method:"GET",path:"/v1/human/comments/:comment_id",classes:["person","broker"],resource:"human"},{name:"review-comments.post.51",method:"POST",path:"/v1/human/comments/:comment_id/edit",classes:["person","broker"],resource:"human"},{name:"review-comments.post.52",method:"POST",path:"/v1/human/comments/:comment_id/resolve",classes:["person","broker"],resource:"human"},{name:"review-comments.post.53",method:"POST",path:"/v1/human/comments/:comment_id/reopen",classes:["person","broker"],resource:"human"},{name:"review-comments.post.54",method:"POST",path:"/v1/human/comments/:comment_id/delete",classes:["person","broker"],resource:"human"},{name:"review-comments.post.55",method:"POST",path:"/v1/human/comments/:comment_id/fork",classes:["person","broker"],resource:"human"},{name:"messages.post.56",method:"POST",path:"/v1/nodes/:id/mail/claim",classes:["person","broker"],resource:"node-own"},{name:"messages.post.57",method:"POST",path:"/v1/nodes/:id/mail/acknowledge",classes:["person","broker"],resource:"node-own"},{name:"messages.post.58",method:"POST",path:"/v1/nodes/:id/messages",classes:["person","broker","cron","forwarded"],resource:"node-write"},{name:"messages.post.59",method:"POST",path:"/v1/nodes/:id/interrupt",classes:["person","broker","cron","forwarded"],resource:"node-write"},{name:"reports.post.60",method:"POST",path:"/v1/nodes/:id/reports",classes:["person","broker"],resource:"node-own"},{name:"reports.get.61",method:"GET",path:"/v1/nodes/:id/reports",classes:["person","broker","cron"],resource:"node-read"},{name:"reports.post.62",method:"POST",path:"/v1/nodes/:id/result",classes:["person","broker"],resource:"node-own"},{name:"inbox.get.63",method:"GET",path:"/v1/human/inbox",classes:["person","broker"],resource:"human"},{name:"inbox.get.64",method:"GET",path:"/v1/human/inbox/history",classes:["person","broker"],resource:"human"},{name:"inbox.get.65",method:"GET",path:"/v1/human/inbox/:ticket_id",classes:["person","broker"],resource:"human"},{name:"inbox.get.66",method:"GET",path:"/v1/human/inbox/:ticket_id/response",classes:["person","broker"],resource:"human"},{name:"inbox.post.67",method:"POST",path:"/v1/human/inbox/:ticket_id/respond",classes:["person","broker"],resource:"human"},{name:"inbox.post.68",method:"POST",path:"/v1/human/inbox/:ticket_id/progress",classes:["person","broker"],resource:"human"},{name:"inbox.post.69",method:"POST",path:"/v1/human/inbox/:ticket_id/cancel",classes:["person","broker"],resource:"human"},{name:"worktree.post.70",method:"POST",path:"/v1/nodes/:id/worktree/close",classes:["person","broker"],resource:"node-write"},{name:"worktree.post.71",method:"POST",path:"/v1/nodes/:id/worktree/abandon",classes:["person","broker"],resource:"node-write"},{name:"worktree.get.72",method:"GET",path:"/v1/worktrees/quarantined",classes:["person","broker"],resource:"none"},{name:"crons.post.73",method:"POST",path:"/v1/crons",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.get.74",method:"GET",path:"/v1/crons",classes:["person","app","broker","cron"],resource:"cron"},{name:"crons.get.75",method:"GET",path:"/v1/crons/:cronId",classes:["person","app","broker","cron"],resource:"cron"},{name:"crons.post.76",method:"POST",path:"/v1/crons/:cronId/pause",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.post.77",method:"POST",path:"/v1/crons/:cronId/resume",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.post.78",method:"POST",path:"/v1/crons/poke",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.post.79",method:"POST",path:"/v1/crons/:cronId/run",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.delete.80",method:"DELETE",path:"/v1/crons/:cronId",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"modelauth.get.81",method:"GET",path:"/v1/model-auth",classes:["person","broker"],resource:"none"},{name:"modelauth.get.82",method:"GET",path:"/v1/model-auth/readiness",classes:["person","broker"],resource:"none"},{name:"modelauth.put.83",method:"PUT",path:"/v1/model-auth/:provider",classes:["person","broker"],resource:"none"},{name:"modelauth.delete.84",method:"DELETE",path:"/v1/model-auth/:provider",classes:["person","broker"],resource:"none"},{name:"modelauth.delete.account",method:"DELETE",path:"/v1/model-auth/:provider/accounts/:label",classes:["person","broker"],resource:"none"},{name:"modelauth.patch.account",method:"PATCH",path:"/v1/model-auth/:provider/accounts/:label",classes:["person","broker"],resource:"none"},{name:"model_auth.start",method:"POST",path:"/v1/model-auth/flows",classes:["person","broker"],resource:"none"},{name:"model_auth.complete",method:"POST",path:"/v1/model-auth/flows/:flow_id/complete",classes:["person","broker"],resource:"none"},{name:"model_auth.cancel",method:"POST",path:"/v1/model-auth/flows/:flow_id/cancel",classes:["person","broker"],resource:"none"},{name:"model_auth.get",method:"GET",path:"/v1/model-auth/flows/:flow_id",classes:["person","broker"],resource:"none"},{name:"nodes.post.85",method:"POST",path:"/v1/nodes",classes:["person","broker","cron"],resource:"node-own",scope:"crtr:act"},{name:"nodes.get.86",method:"GET",path:"/v1/nodes",classes:["person","broker","cron"],resource:"nodes-list"},{name:"nodes.post.87",method:"POST",path:"/v1/nodes/revive-all",classes:["person","broker"],resource:"none"},{name:"nodes.get.88",method:"GET",path:"/v1/nodes/:id",classes:["person","broker","cron","forwarded"],resource:"node-read"},{name:"nodes.get.89",method:"GET",path:"/v1/nodes/:id/snapshot",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.90",method:"GET",path:"/v1/nodes/:id/subject",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.91",method:"GET",path:"/v1/nodes/:id/messages",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.92",method:"GET",path:"/v1/nodes/:id/session",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.93",method:"GET",path:"/v1/nodes/:id/transcript",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.94",method:"GET",path:"/v1/nodes/:id/context",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.post.96",method:"POST",path:"/v1/nodes/:id/fork",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.97",method:"POST",path:"/v1/nodes/:id/revive",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.kick",method:"POST",path:"/v1/nodes/:id/kick",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.98",method:"POST",path:"/v1/nodes/:id/relaunch-root",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.99",method:"POST",path:"/v1/nodes/:id/close",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.read",method:"POST",path:"/v1/nodes/:id/read",classes:["person"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.100",method:"POST",path:"/v1/nodes/:id/recycle",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.101",method:"POST",path:"/v1/nodes/:id/demote",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.102",method:"POST",path:"/v1/nodes/:id/promote",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.103",method:"POST",path:"/v1/nodes/:id/yield",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.104",method:"POST",path:"/v1/nodes/:id/wait",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.patch.105",method:"PATCH",path:"/v1/nodes/:id/config",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"broker-recovery.post.106",method:"POST",path:"/v1/broker/:id/turn",classes:["person","broker"],resource:"node-own"},{name:"broker-recovery.post.107",method:"POST",path:"/v1/broker/:id/provider-retry",classes:["person","broker"],resource:"node-own"},{name:"broker-recovery.post.108",method:"POST",path:"/v1/broker/:id/fault",classes:["person","broker"],resource:"node-own"},{name:"broker-recovery.get.109",method:"GET",path:"/v1/broker/:id/recovery",classes:["person","broker"],resource:"node-own"},{name:"broker-recovery.post.110",method:"POST",path:"/v1/nodes/:id/fault",classes:["person","broker"],resource:"node-write"},{name:"broker-recovery.delete.111",method:"DELETE",path:"/v1/nodes/:id/fault",classes:["person","broker"],resource:"node-write"},{name:"profiles.put.112",method:"PUT",path:"/v1/profiles/:name",classes:["person","app","broker"],resource:"profile"},{name:"profiles.post.113",method:"POST",path:"/v1/profiles/:name/pause",classes:["person","broker"],resource:"profile"},{name:"profiles.post.114",method:"POST",path:"/v1/profiles/:name/resume",classes:["person","broker"],resource:"profile"},{name:"profiles.patch.115",method:"PATCH",path:"/v1/profiles/:name/metadata",classes:["person","app","broker"],resource:"profile"},{name:"profile.create",method:"POST",path:"/v1/profiles",classes:["person","app","broker"],resource:"profile"},{name:"profile.update",method:"PATCH",path:"/v1/profiles/:name",classes:["person","app","broker"],resource:"profile"},{name:"app.env.list",method:"GET",path:"/v1/apps/self/env",classes:["person","app","broker"],resource:"profile"},{name:"app.env.set",method:"PUT",path:"/v1/apps/self/env/:var",classes:["person","app","broker"],resource:"profile"},{name:"app.env.remove",method:"DELETE",path:"/v1/apps/self/env/:var",classes:["person","app","broker"],resource:"profile"},{name:"profile.env.list",method:"GET",path:"/v1/profiles/:name/env",classes:["person","app","broker"],resource:"profile"},{name:"profile.env.set",method:"PUT",path:"/v1/profiles/:name/env/:var",classes:["person","app","broker"],resource:"profile"},{name:"profile.env.remove",method:"DELETE",path:"/v1/profiles/:name/env/:var",classes:["person","app","broker"],resource:"profile"},{name:"profile.environment.get",method:"GET",path:"/v1/profiles/:name/environment",classes:["person","broker","cron"],resource:"profile"},{name:"profile.environment.set",method:"PUT",path:"/v1/profiles/:name/environment",classes:["person","broker"],resource:"profile"},{name:"profiles.delete.116",method:"DELETE",path:"/v1/profiles/:name",classes:["person","app","broker"],resource:"profile"},{name:"profile.list",method:"GET",path:"/v1/profiles",classes:["person","app","broker","cron"],resource:"profile",stage:"chat"},{name:"profiles.get.118",method:"GET",path:"/v1/profiles/:name",classes:["person","app","broker"],resource:"profile"},{name:"import.start",method:"POST",path:"/v1/imports",classes:["person","import"],resource:"none"},{name:"import.upload-urls",method:"POST",path:"/v1/imports/:run_id/upload-urls",classes:["person","import"],resource:"none"},{name:"import.store",method:"PUT",path:"/v1/imports/:run_id/stores/:name",classes:["person","import"],resource:"none"},{name:"import.load",method:"POST",path:"/v1/imports/:run_id/load",classes:["person","import"],resource:"none"},{name:"import.get",method:"GET",path:"/v1/imports/:run_id",classes:["person","import"],resource:"none"},{name:"import.rollback",method:"POST",path:"/v1/imports/:run_id/rollback",classes:["person"],resource:"none"},{name:"machine.register",method:"POST",path:"/v1/machines",classes:["person"],resource:"none"},{name:"machine.revoke",method:"DELETE",path:"/v1/machines/:environment_id",classes:["person"],resource:"none"},{name:"import.machine-credential",method:"POST",path:"/v1/imports/:run_id/machine-credential",classes:["person"],resource:"none"},{name:"execution.import-unpacked",method:"POST",path:"/v1/executions/:execution_id/import-unpacked",classes:["broker"],resource:"none"},{name:"execution.start",method:"GET",path:"/v1/executions/:execution_id/start",classes:["broker"],resource:"none"},{name:"environment.git-credential",method:"POST",path:"/v1/environments/:environment_id/git-credential",classes:["broker"],resource:"none"},{name:"feedback.file",method:"POST",path:"/v1/feedback",classes:["broker"],resource:"none"},{name:"node-outcomes.get.119",method:"GET",path:"/v1/nodes/:id/outcome",classes:["person","broker","cron"],resource:"node-read"},{name:"node-outcomes.put.120",method:"PUT",path:"/v1/nodes/:id/outcome-delivery",classes:["person","broker"],resource:"node-write"},{name:"node-outcomes.get.121",method:"GET",path:"/v1/nodes/:id/outcome-delivery",classes:["person","broker","cron"],resource:"node-read"},{name:"node-outcomes.delete.122",method:"DELETE",path:"/v1/nodes/:id/outcome-delivery",classes:["person","broker"],resource:"node-write"},{name:"canvas.get.123",method:"GET",path:"/v1/canvas/attention",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.post.124",method:"POST",path:"/v1/canvas/attention/counts",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.post.125",method:"POST",path:"/v1/canvas/history/search",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.post.126",method:"POST",path:"/v1/canvas/history/grep",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.get.127",method:"GET",path:"/v1/canvas/history/read",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.post.128",method:"POST",path:"/v1/canvas/history/stats",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.get.129",method:"GET",path:"/v1/canvas/snapshot",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.get.130",method:"GET",path:"/v1/canvas/roster",classes:["person","broker","cron"],resource:"canvas-read"},{name:"canvas.get.view",method:"GET",path:"/v1/canvas/view/:id",classes:["person","broker"],resource:"canvas-read"},{name:"canvas.get.live-roots",method:"GET",path:"/v1/canvas/live-roots",classes:["person"],resource:"canvas-read"},{name:"canvas.get.browse",method:"GET",path:"/v1/canvas/browse",classes:["person","broker"],resource:"canvas-read"},{name:"canvas.get.analytics",method:"GET",path:"/v1/canvas/analytics",classes:["person","broker"],resource:"canvas-read"},{name:"memory-reads.post",method:"POST",path:"/v1/nodes/:id/memory-reads",classes:["person","broker"],resource:"node-own"},{name:"canvas.get.131",method:"GET",path:"/v1/canvas/graph",classes:["person","broker"],resource:"canvas-read"},{name:"canvas.post.132",method:"POST",path:"/v1/canvas/prune",classes:["person","broker"],resource:"none"},{name:"daemon.post.133",method:"POST",path:"/v1/daemon/restart",classes:["person","broker"],resource:"daemon-control"},{name:"daemon.post.134",method:"POST",path:"/v1/daemon/migrate",classes:["person","broker"],resource:"daemon-control"},{name:"daemon.drain.start",method:"POST",path:"/v1/daemon/drain",classes:["person"],resource:"daemon-control"},{name:"daemon.drain.end",method:"DELETE",path:"/v1/daemon/drain",classes:["person"],resource:"daemon-control"},{name:"daemon.post.135",method:"POST",path:"/v1/daemon/admit",classes:["person","broker"],resource:"daemon-control"},{name:"human.components.list",method:"GET",path:"/v1/human/components",classes:["person","broker"],resource:"none"},{name:"human-requests.post.136",method:"POST",path:"/v1/human/requests",classes:["person","broker"],resource:"human",scope:"crtr:act"},{name:"human-requests.get.137",method:"GET",path:"/v1/human/requests/:request_id",classes:["person","broker"],resource:"human"},{name:"human-requests.post.138",method:"POST",path:"/v1/human/requests/:request_id/replace",classes:["person","broker"],resource:"human"},{name:"human-requests.post.139",method:"POST",path:"/v1/human/requests/:request_id/respond",classes:["person","broker"],resource:"human"},{name:"human-requests.post.140",method:"POST",path:"/v1/human/requests/:request_id/dismiss",classes:["person","broker"],resource:"human"},{name:"human-requests.post.141",method:"POST",path:"/v1/human/requests/:request_id/cancel",classes:["person","broker"],resource:"human"},{name:"focus.get.142",method:"GET",path:"/v1/focuses",classes:["person","broker"],resource:"none"},{name:"focus.post.143",method:"POST",path:"/v1/focuses",classes:["person","broker"],resource:"none"},{name:"focus.get.144",method:"GET",path:"/v1/focuses/by-node",classes:["person","broker"],resource:"none"},{name:"focus.get.145",method:"GET",path:"/v1/focuses/by-pane",classes:["person","broker"],resource:"none"},{name:"focus.patch.146",method:"PATCH",path:"/v1/focuses/:focus_id",classes:["person","broker"],resource:"none"},{name:"focus.delete.147",method:"DELETE",path:"/v1/focuses/:focus_id",classes:["person","broker"],resource:"none"},{name:"delivery.retry",method:"POST",path:"/v1/deliveries/:delivery_id/retry",classes:["person","broker"],resource:"none"},{name:"limits.show",method:"GET",path:"/v1/limits",classes:["person","broker"],resource:"none"},{name:"limits.set",method:"PUT",path:"/v1/limits/apps/:app",classes:["person"],resource:"none"},{name:"limits.remove",method:"DELETE",path:"/v1/limits/apps/:app",classes:["person"],resource:"none"},{name:"charges.list",method:"GET",path:"/v1/charges",classes:["person","app","broker"],resource:"none",stage:"objects"},{name:"spend_limits.list",method:"GET",path:"/v1/spend-limits",classes:["person","broker"],resource:"none"},{name:"spend_limits.set",method:"PUT",path:"/v1/spend-limits/:id",classes:["person"],resource:"none"},{name:"spend_limits.remove",method:"DELETE",path:"/v1/spend-limits/:id",classes:["person"],resource:"none"},{name:"space.list",method:"GET",path:"/v1/spaces",classes:["person","broker"],resource:"none"},{name:"kinds.list",method:"GET",path:"/v1/kinds",classes:["person","app","broker"],resource:"none"},{name:"grant.get",method:"GET",path:"/v1/grant",classes:["app"],resource:"none",stage:"v0.5"},{name:"exec",method:"POST",path:"/v1/exec",classes:["app"],scope:"crtr:act",resource:"none",stage:"v0.5"},{name:"usage.get",method:"GET",path:"/v1/usage",classes:["person","app","broker"],resource:"none",stage:"v1"},{name:"llm",method:"POST",path:"/v1/llm",classes:["app","person","broker"],scope:"crtr:llm",resource:"none",stage:"v1"},{name:"llm.anthropic_messages",method:"POST",path:"/v1/llm/anthropic/messages",classes:["app"],scope:"crtr:llm",resource:"none",stage:"v1"},{name:"structured-request.create",method:"POST",path:"/v1/structured-requests",classes:["person","app","broker"],scope:"crtr:act",resource:"none"},{name:"structured-request.get",method:"GET",path:"/v1/structured-requests/:request_id",classes:["person","app","broker"],resource:"none"},{name:"structured-request.cancel",method:"POST",path:"/v1/structured-requests/:request_id/cancel",classes:["person","app","broker"],scope:"crtr:act",resource:"none"},{name:"run.start",method:"POST",path:"/v1/runs",classes:["app"],scope:"crtr:act",resource:"none",stage:"v0.5",idempotency:"24h"},{name:"run.list",method:"GET",path:"/v1/runs",classes:["app","person","broker","cron"],resource:"run",stage:"v0.5"},{name:"run.get",method:"GET",path:"/v1/runs/:run_id",classes:["app","person","broker","cron"],resource:"run",stage:"v0.5"},{name:"run.message",method:"POST",path:"/v1/runs/:run_id/messages",classes:["app","person","broker","cron"],scope:"crtr:act",resource:"run",stage:"v0.5",idempotency:"24h"},{name:"run.events",method:"GET",path:"/v1/runs/:run_id/events",classes:["app","person","broker","cron"],resource:"run",stage:"v0.5",stream:!0},{name:"run.interrupt",method:"POST",path:"/v1/runs/:run_id/interrupt",classes:["app","person","broker"],resource:"run",stage:"v0.5"},{name:"run.cancel",method:"POST",path:"/v1/runs/:run_id/cancel",classes:["app","person","broker"],resource:"run",stage:"v0.5"},{name:"run.delete",method:"DELETE",path:"/v1/runs/:run_id",classes:["app","person","broker"],resource:"run",stage:"v0.5"},{name:"run.rename",method:"POST",path:"/v1/runs/:run_id/rename",classes:["app"],resource:"run",stage:"chat"},{name:"question.get",method:"GET",path:"/v1/questions/:question_id",classes:["app"],resource:"none",stage:"chat"},{name:"question.answer",method:"POST",path:"/v1/questions/:question_id/answer",classes:["app"],resource:"none",stage:"chat"},{name:"question.cancel",method:"POST",path:"/v1/questions/:question_id/cancel",classes:["app"],resource:"none",stage:"chat"},{name:"trace.get",method:"GET",path:"/v1/runs/:run_id/trace",classes:["app","person","broker"],resource:"run",stage:"v0.5"},{name:"upload.create",method:"POST",path:"/v1/uploads",classes:["app"],scope:"crtr:act",resource:"none",stage:"file-transfer"},{name:"attachment.link",method:"GET",path:"/v1/attachments/link",classes:["app"],resource:"none",stage:"file-transfer"},{name:"file.link",method:"GET",path:"/v1/files/:file_id/link",classes:["app"],resource:"none",stage:"file-transfer"},{name:"share.create",method:"POST",path:"/v1/shares",classes:["app"],resource:"none",stage:"file-transfer"},{name:"share.list",method:"GET",path:"/v1/shares",classes:["app"],resource:"none",stage:"file-transfer"},{name:"share.delete",method:"DELETE",path:"/v1/shares/:share_id",classes:["app"],resource:"none",stage:"file-transfer"},{name:"memory.list",method:"GET",path:"/v1/memory",classes:["person","app","broker"],resource:"none",stage:"m13"},{name:"memory.get",method:"GET",path:"/v1/memory/document",classes:["person","app","broker"],resource:"none",stage:"m13"},{name:"audit.list",method:"GET",path:"/v1/audit",classes:["person","app"],resource:"none",stage:"v1"},{name:"provider.tools",method:"GET",path:"/v1/providers/tools",classes:["person","app","broker","cron"],resource:"none",stage:"v1"},{name:"provider.tools",method:"GET",path:"/v1/providers/:provider/tools",classes:["person","app","broker","cron"],resource:"none",stage:"v1"},{name:"provider.call",method:"POST",path:"/v1/provider/call",classes:["person","app","broker","cron"],resource:"none",stage:"v1"},{name:"peer.events",method:"POST",path:"/v1/peer/events",classes:["machine"],resource:"none"},{name:"peer.outbox.claim",method:"POST",path:"/v1/peer/outbox/claim",classes:["machine"],resource:"none"},{name:"peer.outbox.ack",method:"POST",path:"/v1/peer/outbox/ack",classes:["machine"],resource:"none"},{name:"peer.locate",method:"POST",path:"/v1/peer/locate",classes:["machine"],resource:"none"},{name:"runtime.sync-notice",method:"POST",path:"/v1/runtime/sync-notice",classes:["directory"],resource:"none",stage:"v1"},{name:"runtime.vendor-status",method:"GET",path:"/v1/runtime/vendor-status",classes:["directory"],resource:"none",stage:"v1"},{name:"runtime.vendor-account-remove",method:"POST",path:"/v1/runtime/vendor-account-remove",classes:["directory"],resource:"none",stage:"v1"}];function c(e,s){return n.find(o=>o.method===e.toUpperCase()&&o.path===s)}r(c,"operationFor");export{n as OPERATIONS,c as operationFor};
1
+ var n=Object.defineProperty;var r=(e,s)=>n(e,"name",{value:s,configurable:!0});const a=[{name:"conversation.create",method:"POST",path:"/v1/conversations",classes:["broker"],resource:"none"},{name:"conversation.list",method:"GET",path:"/v1/conversations",classes:["broker","person"],resource:"none"},{name:"conversation.append",method:"POST",path:"/v1/conversations/:id/entries",classes:["broker"],resource:"none"},{name:"conversation.commit",method:"POST",path:"/v1/conversations/:id/commit",classes:["broker"],resource:"none"},{name:"conversation.read",method:"GET",path:"/v1/conversations/:id",classes:["broker","person"],resource:"none"},{name:"conversation.header",method:"GET",path:"/v1/conversations/:id/header",classes:["broker","person"],resource:"none"},{name:"conversation.replace",method:"PUT",path:"/v1/conversations/:id",classes:["broker"],resource:"none"},{name:"conversation.fork",method:"POST",path:"/v1/conversations/:id/fork",classes:["broker"],resource:"none"},{name:"conversation.delete",method:"DELETE",path:"/v1/conversations/:id",classes:["broker"],resource:"none"},{name:"health",method:"GET",path:"/v1/health",classes:["anonymous"],resource:"none",stage:"v0.5"},{name:"ready",method:"GET",path:"/v1/ready",classes:["anonymous"],resource:"none",stage:"v0.5"},{name:"chat-inventory.get.1",method:"GET",path:"/v1/nodes/:id/chat-inventory",classes:["person","broker","cron"],resource:"node-read"},{name:"settings.get",method:"GET",path:"/v1/settings",classes:["person","broker"],resource:"none"},{name:"settings.put",method:"PUT",path:"/v1/settings",classes:["person","broker"],resource:"none"},{name:"model-config.put.2",method:"PUT",path:"/v1/model-config",classes:["person","broker"],resource:"none"},{name:"files.get.3",method:"GET",path:"/v1/files/peek",classes:["person","broker"],resource:"none"},{name:"files.post.4",method:"POST",path:"/v1/files/write",classes:["person","broker"],resource:"none"},{name:"files.get.5",method:"GET",path:"/v1/files/list",classes:["person","broker"],resource:"none"},{name:"reviews.post.6",method:"POST",path:"/v1/human/reviews",classes:["person","broker"],resource:"human",scope:"crtr:act"},{name:"reviews.get.7",method:"GET",path:"/v1/human/reviews",classes:["person","broker"],resource:"human"},{name:"reviews.get.8",method:"GET",path:"/v1/human/reviews/:review_id",classes:["person","broker"],resource:"human"},{name:"reviews.post.9",method:"POST",path:"/v1/human/reviews/:review_id/submit",classes:["person","broker"],resource:"human"},{name:"reviews.post.10",method:"POST",path:"/v1/human/reviews/:review_id/cancel",classes:["person","broker"],resource:"human"},{name:"reviews.get.11",method:"GET",path:"/v1/human/reviews/:review_id/document",classes:["person","broker"],resource:"human"},{name:"feedback-comments.post.12",method:"POST",path:"/v1/human/inbox/:ticket_id/feedback-comments",classes:["person","broker"],resource:"human"},{name:"feedback-comments.post.13",method:"POST",path:"/v1/human/inbox/:ticket_id/feedback-comments/:comment_id/resolve",classes:["person","broker"],resource:"human"},{name:"node.log.append",method:"POST",path:"/v1/nodes/:id/records/log",classes:["person","broker"],resource:"node-own"},{name:"node.summaries.put",method:"PUT",path:"/v1/nodes/:id/records/summaries",classes:["person","broker"],resource:"node-own"},{name:"node.attachments.list",method:"GET",path:"/v1/nodes/:id/attachments",classes:["person","broker"],resource:"node-own"},{name:"node.attachments.read",method:"GET",path:"/v1/nodes/:id/attachments/:sha256",classes:["person","broker"],resource:"node-own"},{name:"node.telemetry.put",method:"PUT",path:"/v1/nodes/:id/records/telemetry",classes:["person","broker"],resource:"node-own"},{name:"node.recap.put",method:"PUT",path:"/v1/nodes/:id/records/recap",classes:["person","broker"],resource:"node-own"},{name:"node.inbox.read",method:"GET",path:"/v1/nodes/:id/records/inbox",classes:["person","broker"],resource:"node-own"},{name:"node.passive.read",method:"GET",path:"/v1/nodes/:id/records/passive",classes:["person","broker"],resource:"node-own"},{name:"node.pushed-final",method:"POST",path:"/v1/nodes/:id/records/pushed-final",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.14",method:"POST",path:"/v1/nodes/:id/broker/session-bound",classes:["person","broker"],resource:"node-own"},{name:"broker.cycle-start",method:"POST",path:"/v1/nodes/:id/broker/cycle-start",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.15",method:"POST",path:"/v1/nodes/:id/broker/settle",classes:["person","broker"],resource:"node-own"},{name:"broker.cycle",method:"POST",path:"/v1/nodes/:id/broker/cycle",classes:["broker"],resource:"node-own"},{name:"broker.idle",method:"POST",path:"/v1/nodes/:id/broker/idle",classes:["broker"],resource:"node-own"},{name:"broker-ops.post.16",method:"POST",path:"/v1/nodes/:id/broker/park-complete",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.17",method:"POST",path:"/v1/nodes/:id/broker/park-activity",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.18",method:"POST",path:"/v1/nodes/:id/broker/telemetry",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.19",method:"POST",path:"/v1/nodes/:id/broker/model",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.get.20",method:"GET",path:"/v1/nodes/:id/broker/extension-state",classes:["person","broker"],resource:"node-own"},{name:"broker.signals",method:"GET",path:"/v1/nodes/:id/broker/signals",classes:["broker"],resource:"node-own",stream:!0},{name:"nodes.broker-structured-request",method:"GET",path:"/v1/nodes/:id/broker/structured-request",classes:["person","broker"],resource:"node-own"},{name:"nodes.broker-goal",method:"POST",path:"/v1/nodes/:id/broker/goal",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.21",method:"POST",path:"/v1/nodes/:id/broker/generated-name",classes:["person","broker"],resource:"node-own"},{name:"broker-ops.post.22",method:"POST",path:"/v1/nodes/:id/broker/persona-ack",classes:["person","broker"],resource:"node-own"},{name:"objects.read",method:"GET",path:"/v1/objects/:ref",classes:["person","app","broker","cron","forwarded"],resource:"objects",stage:"objects"},{name:"objects.list",method:"GET",path:"/v1/objects",classes:["person","app","broker","cron","forwarded"],resource:"objects",stage:"objects"},{name:"objects.search",method:"POST",path:"/v1/objects/search",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"objects.watch",method:"POST",path:"/v1/objects/:ref/watch",classes:["anonymous","person","app","broker","cron","forwarded"],resource:"objects",stage:"objects"},{name:"objects.unwatch",method:"DELETE",path:"/v1/objects/:ref/watch",classes:["anonymous","person","app","broker","cron","forwarded"],resource:"objects",stage:"objects"},{name:"objects.shares",method:"GET",path:"/v1/objects/:ref/shares",classes:["person","broker"],resource:"objects",stage:"objects"},{name:"objects.share",method:"POST",path:"/v1/objects/:ref/shares",classes:["person","broker"],resource:"objects",stage:"objects"},{name:"objects.unshare",method:"DELETE",path:"/v1/objects/:ref/shares",classes:["person","broker"],resource:"objects",stage:"objects"},{name:"custom-objects.register",method:"POST",path:"/v1/custom-objects",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"custom-objects.publish",method:"POST",path:"/v1/custom-objects/:ref/events",classes:["anonymous","person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"custom-objects.unregister",method:"DELETE",path:"/v1/custom-objects/:ref",classes:["anonymous","person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"custom-objects.receive",method:"GET",path:"/v1/custom-objects/:ref/deliveries",classes:["anonymous","person","app","broker","cron"],resource:"objects",stream:!0,stage:"objects"},{name:"custom-objects.ack",method:"POST",path:"/v1/custom-objects/:ref/deliveries/ack",classes:["anonymous","person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"objects.edges",method:"GET",path:"/v1/objects/:ref/edges",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.write",method:"POST",path:"/v1/docs",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.edit",method:"PATCH",path:"/v1/docs/:ref",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.move",method:"POST",path:"/v1/docs/:ref/move",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.delete",method:"DELETE",path:"/v1/docs/:ref",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"docs.history",method:"GET",path:"/v1/docs/:ref/history",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"schemas.register",method:"POST",path:"/v1/schemas",classes:["app"],resource:"objects",stage:"objects"},{name:"relations.write",method:"POST",path:"/v1/relations",classes:["app"],resource:"objects",stage:"objects"},{name:"relations.replace",method:"PUT",path:"/v1/relations",classes:["app"],resource:"objects",stage:"objects"},{name:"relations.list",method:"GET",path:"/v1/relations",classes:["app"],resource:"objects",stage:"objects"},{name:"check",method:"POST",path:"/v1/check",classes:["app"],resource:"objects",stage:"objects"},{name:"docs.lint",method:"POST",path:"/v1/docs/lint",classes:["person","app","broker","cron"],resource:"objects",stage:"objects"},{name:"plugins.app-token",method:"GET",path:"/v1/plugins/:name/app-token",classes:["person","broker"],resource:"none"},{name:"plugins.call-headers",method:"POST",path:"/v1/plugins/:name/call-headers",classes:["person","broker"],resource:"none"},{name:"documents.browser-access",method:"GET",path:"/v1/documents/browser-access",classes:["person"],resource:"none"},{name:"documents.reconcile-packages",method:"POST",path:"/v1/documents/reconcile-packages",classes:["person","broker"],resource:"none"},{name:"nodes.delivery",method:"POST",path:"/v1/nodes/:id/delivery",classes:["person","broker"],resource:"node-own"},{name:"delivery.dry-run",method:"POST",path:"/v1/delivery/dry-run",classes:["person","broker"],resource:"none"},{name:"bash-jobs.background",method:"POST",path:"/v1/nodes/:id/jobs/:jobId/background",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"health.get.33",method:"GET",path:"/healthz",classes:["anonymous"],resource:"none"},{name:"health.get.34",method:"GET",path:"/v1/status",classes:["person","broker"],resource:"none"},{name:"daemon.due",method:"GET",path:"/v1/due",classes:["person","broker"],resource:"none"},{name:"bash-jobs.report",method:"POST",path:"/v1/nodes/:id/jobs/:jobId/report",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"bash-jobs.patch",method:"PATCH",path:"/v1/nodes/:id/jobs/:jobId",classes:["person","broker"],resource:"node-write"},{name:"files.create",method:"POST",path:"/v1/nodes/:id/files",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"files.complete",method:"POST",path:"/v1/nodes/:id/files/:fileId/complete",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"node-uploads.create",method:"POST",path:"/v1/nodes/:id/uploads",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"node-uploads.link",method:"POST",path:"/v1/nodes/:id/uploads/:uploadId/link",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"bash-jobs.start",method:"POST",path:"/v1/nodes/:id/jobs/start",classes:["broker"],resource:"node-own",scope:"crtr:act"},{name:"hooks.plan",method:"GET",path:"/v1/nodes/:id/hooks/plan",classes:["broker"],resource:"node-own"},{name:"hooks.exec",method:"POST",path:"/v1/nodes/:id/hooks/exec",classes:["broker"],resource:"node-own"},{name:"hooks.exec.person",method:"POST",path:"/v1/hooks/exec",classes:["person","broker"],resource:"none"},{name:"bash-jobs.get.35",method:"GET",path:"/v1/nodes/:id/jobs",classes:["person","broker","cron"],resource:"node-read"},{name:"bash-jobs.output",method:"GET",path:"/v1/nodes/:id/jobs/:jobId/output",classes:["person","broker","cron"],resource:"node-read"},{name:"bash-jobs.delete.36",method:"DELETE",path:"/v1/nodes/:id/jobs/:jobId",classes:["person","broker"],resource:"node-write"},{name:"prospective-chat-inventory.get.37",method:"GET",path:"/v1/prospective-chat-inventory",classes:["person","broker"],resource:"none"},{name:"node-events.get.38",method:"GET",path:"/v1/nodes/:id/events",classes:["person","broker","cron"],resource:"node-read"},{name:"bash.post.39",method:"POST",path:"/v1/bash",classes:["person","broker"],resource:"daemon-bash",scope:"crtr:act"},{name:"subscriptions.post.40",method:"POST",path:"/v1/nodes/:id/subscriptions",classes:["person","broker"],resource:"node-write"},{name:"subscriptions.delete.41",method:"DELETE",path:"/v1/nodes/:id/subscriptions/:target",classes:["person","broker"],resource:"node-write"},{name:"attach.post.42",method:"POST",path:"/v1/nodes/:id/attach",classes:["person","broker"],resource:"node-write"},{name:"review-comments.post.44",method:"POST",path:"/v1/human/reviews/self/comments",classes:["person","broker"],resource:"human"},{name:"review-comments.get.45",method:"GET",path:"/v1/human/reviews/self/comments",classes:["person","broker"],resource:"human"},{name:"review-comments.post.46",method:"POST",path:"/v1/human/reviews/:review_id/comments",classes:["person","broker"],resource:"human"},{name:"review-comments.get.47",method:"GET",path:"/v1/human/reviews/:review_id/comments",classes:["person","broker"],resource:"human"},{name:"review-comments.get.48",method:"GET",path:"/v1/human/reviews/:review_id/comment-events",classes:["person","broker"],resource:"human"},{name:"review-comments.post.49",method:"POST",path:"/v1/human/reviews/:review_id/comment-ranges",classes:["person","broker"],resource:"human"},{name:"review-comments.get.50",method:"GET",path:"/v1/human/comments/:comment_id",classes:["person","broker"],resource:"human"},{name:"review-comments.post.51",method:"POST",path:"/v1/human/comments/:comment_id/edit",classes:["person","broker"],resource:"human"},{name:"review-comments.post.52",method:"POST",path:"/v1/human/comments/:comment_id/resolve",classes:["person","broker"],resource:"human"},{name:"review-comments.post.53",method:"POST",path:"/v1/human/comments/:comment_id/reopen",classes:["person","broker"],resource:"human"},{name:"review-comments.post.54",method:"POST",path:"/v1/human/comments/:comment_id/delete",classes:["person","broker"],resource:"human"},{name:"review-comments.post.55",method:"POST",path:"/v1/human/comments/:comment_id/fork",classes:["person","broker"],resource:"human"},{name:"messages.post.56",method:"POST",path:"/v1/nodes/:id/mail/claim",classes:["person","broker"],resource:"node-own"},{name:"messages.post.57",method:"POST",path:"/v1/nodes/:id/mail/acknowledge",classes:["person","broker"],resource:"node-own"},{name:"messages.post.58",method:"POST",path:"/v1/nodes/:id/messages",classes:["person","broker","cron","forwarded"],resource:"node-write"},{name:"messages.post.59",method:"POST",path:"/v1/nodes/:id/interrupt",classes:["person","broker","cron","forwarded"],resource:"node-write"},{name:"reports.post.60",method:"POST",path:"/v1/nodes/:id/reports",classes:["person","broker"],resource:"node-own"},{name:"reports.get.61",method:"GET",path:"/v1/nodes/:id/reports",classes:["person","broker","cron"],resource:"node-read"},{name:"reports.post.62",method:"POST",path:"/v1/nodes/:id/result",classes:["person","broker"],resource:"node-own"},{name:"inbox.get.63",method:"GET",path:"/v1/human/inbox",classes:["person","broker"],resource:"human"},{name:"inbox.get.64",method:"GET",path:"/v1/human/inbox/history",classes:["person","broker"],resource:"human"},{name:"inbox.get.65",method:"GET",path:"/v1/human/inbox/:ticket_id",classes:["person","broker"],resource:"human"},{name:"inbox.get.66",method:"GET",path:"/v1/human/inbox/:ticket_id/response",classes:["person","broker"],resource:"human"},{name:"inbox.post.67",method:"POST",path:"/v1/human/inbox/:ticket_id/respond",classes:["person","broker"],resource:"human"},{name:"inbox.post.68",method:"POST",path:"/v1/human/inbox/:ticket_id/progress",classes:["person","broker"],resource:"human"},{name:"inbox.post.69",method:"POST",path:"/v1/human/inbox/:ticket_id/cancel",classes:["person","broker"],resource:"human"},{name:"worktree.post.70",method:"POST",path:"/v1/nodes/:id/worktree/close",classes:["person","broker"],resource:"node-write"},{name:"worktree.post.71",method:"POST",path:"/v1/nodes/:id/worktree/abandon",classes:["person","broker"],resource:"node-write"},{name:"worktree.get.72",method:"GET",path:"/v1/worktrees/quarantined",classes:["person","broker"],resource:"none"},{name:"crons.post.73",method:"POST",path:"/v1/crons",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.get.74",method:"GET",path:"/v1/crons",classes:["person","app","broker","cron"],resource:"cron"},{name:"crons.get.75",method:"GET",path:"/v1/crons/:cronId",classes:["person","app","broker","cron"],resource:"cron"},{name:"crons.post.76",method:"POST",path:"/v1/crons/:cronId/pause",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.post.77",method:"POST",path:"/v1/crons/:cronId/resume",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.post.78",method:"POST",path:"/v1/crons/poke",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.post.79",method:"POST",path:"/v1/crons/:cronId/run",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"crons.delete.80",method:"DELETE",path:"/v1/crons/:cronId",classes:["person","app","broker","cron"],resource:"cron",scope:"crtr:schedule"},{name:"modelauth.get.81",method:"GET",path:"/v1/model-auth",classes:["person","broker"],resource:"none"},{name:"modelauth.get.82",method:"GET",path:"/v1/model-auth/readiness",classes:["person","broker"],resource:"none"},{name:"modelauth.put.83",method:"PUT",path:"/v1/model-auth/:provider",classes:["person","broker"],resource:"none"},{name:"modelauth.delete.84",method:"DELETE",path:"/v1/model-auth/:provider",classes:["person","broker"],resource:"none"},{name:"modelauth.delete.account",method:"DELETE",path:"/v1/model-auth/:provider/accounts/:label",classes:["person","broker"],resource:"none"},{name:"modelauth.patch.account",method:"PATCH",path:"/v1/model-auth/:provider/accounts/:label",classes:["person","broker"],resource:"none"},{name:"model_auth.start",method:"POST",path:"/v1/model-auth/flows",classes:["person","broker"],resource:"none"},{name:"model_auth.complete",method:"POST",path:"/v1/model-auth/flows/:flow_id/complete",classes:["person","broker"],resource:"none"},{name:"model_auth.cancel",method:"POST",path:"/v1/model-auth/flows/:flow_id/cancel",classes:["person","broker"],resource:"none"},{name:"model_auth.get",method:"GET",path:"/v1/model-auth/flows/:flow_id",classes:["person","broker"],resource:"none"},{name:"nodes.post.85",method:"POST",path:"/v1/nodes",classes:["person","broker","cron"],resource:"node-own",scope:"crtr:act"},{name:"nodes.get.86",method:"GET",path:"/v1/nodes",classes:["person","broker","cron"],resource:"nodes-list"},{name:"nodes.post.87",method:"POST",path:"/v1/nodes/revive-all",classes:["person","broker"],resource:"none"},{name:"nodes.get.88",method:"GET",path:"/v1/nodes/:id",classes:["person","broker","cron","forwarded"],resource:"node-read"},{name:"nodes.get.89",method:"GET",path:"/v1/nodes/:id/snapshot",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.90",method:"GET",path:"/v1/nodes/:id/subject",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.91",method:"GET",path:"/v1/nodes/:id/messages",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.92",method:"GET",path:"/v1/nodes/:id/session",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.93",method:"GET",path:"/v1/nodes/:id/transcript",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.get.94",method:"GET",path:"/v1/nodes/:id/context",classes:["person","broker","cron"],resource:"node-read"},{name:"nodes.post.96",method:"POST",path:"/v1/nodes/:id/fork",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.97",method:"POST",path:"/v1/nodes/:id/revive",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.kick",method:"POST",path:"/v1/nodes/:id/kick",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.98",method:"POST",path:"/v1/nodes/:id/relaunch-root",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.99",method:"POST",path:"/v1/nodes/:id/close",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.read",method:"POST",path:"/v1/nodes/:id/read",classes:["person"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.100",method:"POST",path:"/v1/nodes/:id/recycle",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.101",method:"POST",path:"/v1/nodes/:id/demote",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.102",method:"POST",path:"/v1/nodes/:id/promote",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.103",method:"POST",path:"/v1/nodes/:id/yield",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.post.104",method:"POST",path:"/v1/nodes/:id/wait",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"nodes.patch.105",method:"PATCH",path:"/v1/nodes/:id/config",classes:["person","broker"],resource:"node-write",scope:"crtr:act"},{name:"broker-recovery.post.106",method:"POST",path:"/v1/broker/:id/turn",classes:["person","broker"],resource:"node-own"},{name:"broker-recovery.post.107",method:"POST",path:"/v1/broker/:id/provider-retry",classes:["person","broker"],resource:"node-own"},{name:"broker-recovery.post.108",method:"POST",path:"/v1/broker/:id/fault",classes:["person","broker"],resource:"node-own"},{name:"broker-recovery.get.109",method:"GET",path:"/v1/broker/:id/recovery",classes:["person","broker"],resource:"node-own"},{name:"broker-recovery.post.110",method:"POST",path:"/v1/nodes/:id/fault",classes:["person","broker"],resource:"node-write"},{name:"broker-recovery.delete.111",method:"DELETE",path:"/v1/nodes/:id/fault",classes:["person","broker"],resource:"node-write"},{name:"profiles.put.112",method:"PUT",path:"/v1/profiles/:name",classes:["person","app","broker"],resource:"profile"},{name:"profiles.post.113",method:"POST",path:"/v1/profiles/:name/pause",classes:["person","broker"],resource:"profile"},{name:"profiles.post.114",method:"POST",path:"/v1/profiles/:name/resume",classes:["person","broker"],resource:"profile"},{name:"profiles.patch.115",method:"PATCH",path:"/v1/profiles/:name/metadata",classes:["person","app","broker"],resource:"profile"},{name:"profile.create",method:"POST",path:"/v1/profiles",classes:["person","app","broker"],resource:"profile"},{name:"profile.update",method:"PATCH",path:"/v1/profiles/:name",classes:["person","app","broker"],resource:"profile"},{name:"app.env.list",method:"GET",path:"/v1/apps/self/env",classes:["person","app","broker"],resource:"profile"},{name:"app.env.set",method:"PUT",path:"/v1/apps/self/env/:var",classes:["person","app","broker"],resource:"profile"},{name:"app.env.remove",method:"DELETE",path:"/v1/apps/self/env/:var",classes:["person","app","broker"],resource:"profile"},{name:"profile.env.list",method:"GET",path:"/v1/profiles/:name/env",classes:["person","app","broker"],resource:"profile"},{name:"profile.env.set",method:"PUT",path:"/v1/profiles/:name/env/:var",classes:["person","app","broker"],resource:"profile"},{name:"profile.env.remove",method:"DELETE",path:"/v1/profiles/:name/env/:var",classes:["person","app","broker"],resource:"profile"},{name:"profile.environment.get",method:"GET",path:"/v1/profiles/:name/environment",classes:["person","broker","cron"],resource:"profile"},{name:"profile.environment.set",method:"PUT",path:"/v1/profiles/:name/environment",classes:["person","broker"],resource:"profile"},{name:"environment.create",method:"POST",path:"/v1/environments",classes:["app"],resource:"profile"},{name:"environment.list",method:"GET",path:"/v1/environments",classes:["app","person"],resource:"profile"},{name:"environment.patch",method:"PATCH",path:"/v1/environments/:name",classes:["app","person"],resource:"profile"},{name:"environment.delete",method:"DELETE",path:"/v1/environments/:name",classes:["app","person"],resource:"profile"},{name:"profiles.delete.116",method:"DELETE",path:"/v1/profiles/:name",classes:["person","app","broker"],resource:"profile"},{name:"profile.list",method:"GET",path:"/v1/profiles",classes:["person","app","broker","cron"],resource:"profile",stage:"chat"},{name:"profiles.get.118",method:"GET",path:"/v1/profiles/:name",classes:["person","app","broker"],resource:"profile"},{name:"import.start",method:"POST",path:"/v1/imports",classes:["person","import"],resource:"none"},{name:"import.upload-urls",method:"POST",path:"/v1/imports/:run_id/upload-urls",classes:["person","import"],resource:"none"},{name:"import.store",method:"PUT",path:"/v1/imports/:run_id/stores/:name",classes:["person","import"],resource:"none"},{name:"import.load",method:"POST",path:"/v1/imports/:run_id/load",classes:["person","import"],resource:"none"},{name:"import.get",method:"GET",path:"/v1/imports/:run_id",classes:["person","import"],resource:"none"},{name:"import.rollback",method:"POST",path:"/v1/imports/:run_id/rollback",classes:["person"],resource:"none"},{name:"machine.register",method:"POST",path:"/v1/machines",classes:["person"],resource:"none"},{name:"machine.revoke",method:"DELETE",path:"/v1/machines/:environment_id",classes:["person"],resource:"none"},{name:"import.machine-credential",method:"POST",path:"/v1/imports/:run_id/machine-credential",classes:["person"],resource:"none"},{name:"execution.import-unpacked",method:"POST",path:"/v1/executions/:execution_id/import-unpacked",classes:["broker"],resource:"none"},{name:"execution.start",method:"GET",path:"/v1/executions/:execution_id/start",classes:["broker"],resource:"none"},{name:"environment.git-credential",method:"POST",path:"/v1/environments/:environment_id/git-credential",classes:["broker"],resource:"none"},{name:"feedback.file",method:"POST",path:"/v1/feedback",classes:["broker"],resource:"none"},{name:"node-outcomes.get.119",method:"GET",path:"/v1/nodes/:id/outcome",classes:["person","broker","cron"],resource:"node-read"},{name:"node-outcomes.put.120",method:"PUT",path:"/v1/nodes/:id/outcome-delivery",classes:["person","broker"],resource:"node-write"},{name:"node-outcomes.get.121",method:"GET",path:"/v1/nodes/:id/outcome-delivery",classes:["person","broker","cron"],resource:"node-read"},{name:"node-outcomes.delete.122",method:"DELETE",path:"/v1/nodes/:id/outcome-delivery",classes:["person","broker"],resource:"node-write"},{name:"canvas.get.123",method:"GET",path:"/v1/canvas/attention",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.post.124",method:"POST",path:"/v1/canvas/attention/counts",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.post.125",method:"POST",path:"/v1/canvas/history/search",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.post.126",method:"POST",path:"/v1/canvas/history/grep",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.get.127",method:"GET",path:"/v1/canvas/history/read",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.post.128",method:"POST",path:"/v1/canvas/history/stats",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.get.129",method:"GET",path:"/v1/canvas/snapshot",classes:["person","broker","forwarded"],resource:"canvas-read"},{name:"canvas.get.130",method:"GET",path:"/v1/canvas/roster",classes:["person","broker","cron"],resource:"canvas-read"},{name:"canvas.get.view",method:"GET",path:"/v1/canvas/view/:id",classes:["person","broker"],resource:"canvas-read"},{name:"canvas.get.live-roots",method:"GET",path:"/v1/canvas/live-roots",classes:["person"],resource:"canvas-read"},{name:"canvas.get.browse",method:"GET",path:"/v1/canvas/browse",classes:["person","broker"],resource:"canvas-read"},{name:"canvas.get.analytics",method:"GET",path:"/v1/canvas/analytics",classes:["person","broker"],resource:"canvas-read"},{name:"memory-reads.post",method:"POST",path:"/v1/nodes/:id/memory-reads",classes:["person","broker"],resource:"node-own"},{name:"canvas.get.131",method:"GET",path:"/v1/canvas/graph",classes:["person","broker"],resource:"canvas-read"},{name:"canvas.post.132",method:"POST",path:"/v1/canvas/prune",classes:["person","broker"],resource:"none"},{name:"daemon.post.133",method:"POST",path:"/v1/daemon/restart",classes:["person","broker"],resource:"daemon-control"},{name:"daemon.post.134",method:"POST",path:"/v1/daemon/migrate",classes:["person","broker"],resource:"daemon-control"},{name:"daemon.drain.start",method:"POST",path:"/v1/daemon/drain",classes:["person"],resource:"daemon-control"},{name:"daemon.drain.end",method:"DELETE",path:"/v1/daemon/drain",classes:["person"],resource:"daemon-control"},{name:"daemon.post.135",method:"POST",path:"/v1/daemon/admit",classes:["person","broker"],resource:"daemon-control"},{name:"human.components.list",method:"GET",path:"/v1/human/components",classes:["person","broker"],resource:"none"},{name:"human-requests.post.136",method:"POST",path:"/v1/human/requests",classes:["person","broker"],resource:"human",scope:"crtr:act"},{name:"human-requests.get.137",method:"GET",path:"/v1/human/requests/:request_id",classes:["person","broker"],resource:"human"},{name:"human-requests.post.138",method:"POST",path:"/v1/human/requests/:request_id/replace",classes:["person","broker"],resource:"human"},{name:"human-requests.post.139",method:"POST",path:"/v1/human/requests/:request_id/respond",classes:["person","broker"],resource:"human"},{name:"human-requests.post.140",method:"POST",path:"/v1/human/requests/:request_id/dismiss",classes:["person","broker"],resource:"human"},{name:"human-requests.post.141",method:"POST",path:"/v1/human/requests/:request_id/cancel",classes:["person","broker"],resource:"human"},{name:"focus.get.142",method:"GET",path:"/v1/focuses",classes:["person","broker"],resource:"none"},{name:"focus.post.143",method:"POST",path:"/v1/focuses",classes:["person","broker"],resource:"none"},{name:"focus.get.144",method:"GET",path:"/v1/focuses/by-node",classes:["person","broker"],resource:"none"},{name:"focus.get.145",method:"GET",path:"/v1/focuses/by-pane",classes:["person","broker"],resource:"none"},{name:"focus.patch.146",method:"PATCH",path:"/v1/focuses/:focus_id",classes:["person","broker"],resource:"none"},{name:"focus.delete.147",method:"DELETE",path:"/v1/focuses/:focus_id",classes:["person","broker"],resource:"none"},{name:"delivery.retry",method:"POST",path:"/v1/deliveries/:delivery_id/retry",classes:["person","broker"],resource:"none"},{name:"limits.show",method:"GET",path:"/v1/limits",classes:["person","broker"],resource:"none"},{name:"limits.set",method:"PUT",path:"/v1/limits/apps/:app",classes:["person"],resource:"none"},{name:"limits.remove",method:"DELETE",path:"/v1/limits/apps/:app",classes:["person"],resource:"none"},{name:"charges.list",method:"GET",path:"/v1/charges",classes:["person","app","broker"],resource:"none",stage:"objects"},{name:"spend_limits.list",method:"GET",path:"/v1/spend-limits",classes:["person","broker"],resource:"none"},{name:"spend_limits.set",method:"PUT",path:"/v1/spend-limits/:id",classes:["person"],resource:"none"},{name:"spend_limits.remove",method:"DELETE",path:"/v1/spend-limits/:id",classes:["person"],resource:"none"},{name:"space.list",method:"GET",path:"/v1/spaces",classes:["person","broker"],resource:"none"},{name:"kinds.list",method:"GET",path:"/v1/kinds",classes:["person","app","broker"],resource:"none"},{name:"grant.get",method:"GET",path:"/v1/grant",classes:["app"],resource:"none",stage:"v0.5"},{name:"exec",method:"POST",path:"/v1/exec",classes:["app"],scope:"crtr:act",resource:"none",stage:"v0.5"},{name:"usage.get",method:"GET",path:"/v1/usage",classes:["person","app","broker"],resource:"none",stage:"v1"},{name:"llm",method:"POST",path:"/v1/llm",classes:["app","person","broker"],scope:"crtr:llm",resource:"none",stage:"v1"},{name:"llm.anthropic_messages",method:"POST",path:"/v1/llm/anthropic/messages",classes:["app"],scope:"crtr:llm",resource:"none",stage:"v1"},{name:"structured-request.create",method:"POST",path:"/v1/structured-requests",classes:["person","app","broker"],scope:"crtr:act",resource:"none"},{name:"structured-request.get",method:"GET",path:"/v1/structured-requests/:request_id",classes:["person","app","broker"],resource:"none"},{name:"structured-request.cancel",method:"POST",path:"/v1/structured-requests/:request_id/cancel",classes:["person","app","broker"],scope:"crtr:act",resource:"none"},{name:"run.start",method:"POST",path:"/v1/runs",classes:["app"],scope:"crtr:act",resource:"none",stage:"v0.5",idempotency:"24h"},{name:"run.list",method:"GET",path:"/v1/runs",classes:["app","person","broker","cron"],resource:"run",stage:"v0.5"},{name:"run.get",method:"GET",path:"/v1/runs/:run_id",classes:["app","person","broker","cron"],resource:"run",stage:"v0.5"},{name:"run.message",method:"POST",path:"/v1/runs/:run_id/messages",classes:["app","person","broker","cron"],scope:"crtr:act",resource:"run",stage:"v0.5",idempotency:"24h"},{name:"run.events",method:"GET",path:"/v1/runs/:run_id/events",classes:["app","person","broker","cron"],resource:"run",stage:"v0.5",stream:!0},{name:"run.interrupt",method:"POST",path:"/v1/runs/:run_id/interrupt",classes:["app","person","broker"],resource:"run",stage:"v0.5"},{name:"run.cancel",method:"POST",path:"/v1/runs/:run_id/cancel",classes:["app","person","broker"],resource:"run",stage:"v0.5"},{name:"run.delete",method:"DELETE",path:"/v1/runs/:run_id",classes:["app","person","broker"],resource:"run",stage:"v0.5"},{name:"run.rename",method:"POST",path:"/v1/runs/:run_id/rename",classes:["app"],resource:"run",stage:"chat"},{name:"question.get",method:"GET",path:"/v1/questions/:question_id",classes:["app"],resource:"none",stage:"chat"},{name:"question.answer",method:"POST",path:"/v1/questions/:question_id/answer",classes:["app"],resource:"none",stage:"chat"},{name:"question.cancel",method:"POST",path:"/v1/questions/:question_id/cancel",classes:["app"],resource:"none",stage:"chat"},{name:"trace.get",method:"GET",path:"/v1/runs/:run_id/trace",classes:["app","person","broker"],resource:"run",stage:"v0.5"},{name:"upload.create",method:"POST",path:"/v1/uploads",classes:["app"],scope:"crtr:act",resource:"none",stage:"file-transfer"},{name:"attachment.link",method:"GET",path:"/v1/attachments/link",classes:["app"],resource:"none",stage:"file-transfer"},{name:"file.link",method:"GET",path:"/v1/files/:file_id/link",classes:["app"],resource:"none",stage:"file-transfer"},{name:"share.create",method:"POST",path:"/v1/shares",classes:["app"],resource:"none",stage:"file-transfer"},{name:"share.list",method:"GET",path:"/v1/shares",classes:["app"],resource:"none",stage:"file-transfer"},{name:"share.delete",method:"DELETE",path:"/v1/shares/:share_id",classes:["app"],resource:"none",stage:"file-transfer"},{name:"memory.list",method:"GET",path:"/v1/memory",classes:["person","app","broker"],resource:"none",stage:"m13"},{name:"memory.get",method:"GET",path:"/v1/memory/document",classes:["person","app","broker"],resource:"none",stage:"m13"},{name:"audit.list",method:"GET",path:"/v1/audit",classes:["person","app"],resource:"none",stage:"v1"},{name:"provider.tools",method:"GET",path:"/v1/providers/tools",classes:["person","app","broker","cron"],resource:"none",stage:"v1"},{name:"provider.tools",method:"GET",path:"/v1/providers/:provider/tools",classes:["person","app","broker","cron"],resource:"none",stage:"v1"},{name:"provider.call",method:"POST",path:"/v1/provider/call",classes:["person","app","broker","cron"],resource:"none",stage:"v1"},{name:"peer.events",method:"POST",path:"/v1/peer/events",classes:["machine"],resource:"none"},{name:"peer.outbox.claim",method:"POST",path:"/v1/peer/outbox/claim",classes:["machine"],resource:"none"},{name:"peer.outbox.ack",method:"POST",path:"/v1/peer/outbox/ack",classes:["machine"],resource:"none"},{name:"peer.locate",method:"POST",path:"/v1/peer/locate",classes:["machine"],resource:"none"},{name:"runtime.sync-notice",method:"POST",path:"/v1/runtime/sync-notice",classes:["directory"],resource:"none",stage:"v1"},{name:"runtime.vendor-status",method:"GET",path:"/v1/runtime/vendor-status",classes:["directory"],resource:"none",stage:"v1"},{name:"runtime.vendor-account-remove",method:"POST",path:"/v1/runtime/vendor-account-remove",classes:["directory"],resource:"none",stage:"v1"}];function c(e,s){return a.find(o=>o.method===e.toUpperCase()&&o.path===s)}r(c,"operationFor");export{a as OPERATIONS,c as operationFor};
@@ -5,9 +5,12 @@ import { type NoticeTicket } from './sync-notice.js';
5
5
  export interface AppPrincipal {
6
6
  sub: string;
7
7
  grantee: string;
8
+ /** The caller: the token's presenting link (an app, an app owning `sub`'s namespace, or a person acting through an exchanged token). */
9
+ actor: string;
8
10
  client_id: string;
9
- grant: string;
10
- rev: number;
11
+ /** Null for an owner principal, which holds its namespace without a grant row. */
12
+ grant: string | null;
13
+ rev: number | null;
11
14
  resolved: Scope[];
12
15
  resolved_scopes: GrantScope[];
13
16
  spend_cap: number | null;
@@ -58,9 +61,10 @@ export declare class AppPrincipalResolver {
58
61
  * 503 before the mirror loads; every other failure is 401. */
59
62
  verifyCall(authorization: string | undefined): Promise<CallToken>;
60
63
  resolve(authorization: string | undefined, scope?: string): Promise<AppPrincipal>;
61
- /** The caller an already-verified app token names. Grantee, grant and rev come from the token's app link
62
- * (`chain[0]`, which must be the whole chain); the mirror is made to cover the link's `rev` and the grant
63
- * is read now (`coverGrant`). A token whose presenter is not an app link holding a grant is refused 401. */
64
+ /** The caller an already-verified token names, from `chain[0]` (which must be the whole chain): (a) an app link holding a
65
+ * grant, (b) an owner link (a grantless app link whose app owns `sub`'s namespace: no grant row, the app's declared
66
+ * scopes), or (c) a person's grant-bearing link on an exchanged token. A grant is covered by the mirror and read now
67
+ * (`coverGrant`). Any other presenter is refused 401. */
64
68
  resolveVerified(token: CallToken, scope?: string): Promise<AppPrincipal>;
65
69
  }
66
70
  /** The mirrored grant a caller's token names, read now, when it is still the
@@ -68,3 +72,5 @@ export declare class AppPrincipalResolver {
68
72
  * Otherwise 401 `grant_revoked`. `resolve()` and every later re-read during a
69
73
  * request (a `grant.get` long-poll waking) apply this one check. */
70
74
  export declare function callerGrant(caller: Pick<AppPrincipal, 'grant' | 'sub' | 'grantee'>): Promise<ActiveGrant>;
75
+ /** The grant id of a caller that must hold a grant row; an owner principal (CR-9 (b)) holds none, so the operation is 403. */
76
+ export declare function grantIdOf(caller: Pick<AppPrincipal, 'grant'>): string;
@@ -1 +1 @@
1
- var v=Object.defineProperty;var o=(a,e)=>v(a,"name",{value:e,configurable:!0});import{covers as m,JwksCache as p,MissingRevClaimError as _,verifyCallToken as b}from"@north-light/identity";import{createLocalJWKSet as l,decodeProtectedHeader as h,jwtVerify as f}from"jose";import{callerGrantOf as k,coverGrant as x}from"../../core/grants/cover.js";import{RunError as n}from"../../core/runs/operations.js";import{NoticeLedger as E}from"./sync-notice.js";function C(a){return new n(401,"unauthorized",a==="vendor_sign_in"?"invalid vendor sign-in handoff":"invalid key handoff")}o(C,"unauthorizedHandoff");class q{static{o(this,"AppPrincipalResolver")}issuer;audience;syncGrants;cache;ready=!1;timer;constructor(e,t,r,i){this.issuer=e,this.audience=t,this.syncGrants=r,this.cache=new p(e,fetch,i),this.load(),this.timer=setInterval(()=>{this.ready||this.load()},5e3),this.timer.unref()}async load(){try{await this.cache.load(),this.ready=!0}catch{}}isReady(){return this.ready}get jwks(){return this.cache}close(){this.timer&&clearInterval(this.timer)}ledger=new E;async verifySyncNotice(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");return this.ledger.accept(e,this.cache,this.issuer,this.audience)}async verifyHandoff(e,t){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const r=o(()=>C(t),"refuse");if(!e)throw r();let i;try{const u=h(e);if(u.alg!=="ES256")throw r();const g=await this.cache.forKid(u.kid);({payload:i}=await f(e,l(g),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp","jti","sub"]}))}catch{throw r()}const{sub:s,jti:c,exp:d,purpose:w,aud:y}=i;if(w!==t||y!==this.audience||typeof s!="string"||typeof c!="string"||c===""||typeof d!="number")throw r();return{sub:s,jti:c,exp:d}}async verifyDirectoryRead(e,t){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const r=o(()=>new n(401,"unauthorized","invalid directory token"),"refuse");if(!e?.startsWith("Bearer ")||e.length<=7)throw r();const i=e.slice(7);let s;try{const c=h(i);if(c.alg!=="ES256")throw r();const d=await this.cache.forKid(c.kid);({payload:s}=await f(i,l(d),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp"]}))}catch{throw r()}if(s.purpose!==t||s.aud!==this.audience)throw r()}async verifyCall(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");if(!e?.startsWith("Bearer ")||e.length<=7)throw new n(401,"unauthorized","a directory access token is required");const t=e.slice(7);try{if(h(t).alg!=="ES256")throw new Error("Invalid call token header");return await b({token:t,jwks:this.cache,issuer:this.issuer,audience:this.audience})}catch(r){throw r instanceof _?new n(401,"unauthorized",r.message):new n(401,"unauthorized","invalid directory access token")}}async resolve(e,t){return this.resolveVerified(await this.verifyCall(e),t)}async resolveVerified(e,t){const r=e.chain[0],i=e.claims;if(e.chain.length!==1||!r||!r.sub.startsWith("app:")||r.grant===void 0||r.rev===void 0||!/^[A-Za-z0-9_-]{1,64}$/.test(i.client_id)||i.grantee!==void 0&&i.grantee!==r.sub||i.rev!==void 0&&i.rev!==r.rev)throw new n(401,"unauthorized","invalid directory access token");const s=await x(r.grant,r.rev,e.sub,r.sub,this.syncGrants);if(t&&!s.resolved.some(c=>m(c,t)))throw new n(403,"scope_missing",`missing scope ${t}`,void 0,void 0,t);return{sub:e.sub,grantee:r.sub,client_id:i.client_id,grant:r.grant,rev:s.rev,resolved:s.resolved,resolved_scopes:s.resolved_scopes,spend_cap:s.spend_cap,dependencies:s.dependencies??{},exp:i.exp}}}async function H(a){return await k(a.grant,a.sub,a.grantee)}o(H,"callerGrant");export{q as AppPrincipalResolver,H as callerGrant,C as unauthorizedHandoff};
1
+ var m=Object.defineProperty;var u=(s,r)=>m(s,"name",{value:r,configurable:!0});import{covers as w,JwksCache as v,parsePrincipal as _,MissingRevClaimError as b,verifyCallToken as k}from"@north-light/identity";import{createLocalJWKSet as p,decodeProtectedHeader as l,jwtVerify as g}from"jose";import{callerGrantOf as x,coverGrant as E}from"../../core/grants/cover.js";import{ownerScopes as S}from"../../core/grants/owner.js";import{RunError as n}from"../../core/runs/operations.js";import{NoticeLedger as C}from"./sync-notice.js";function G(s){return new n(401,"unauthorized",s==="vendor_sign_in"?"invalid vendor sign-in handoff":"invalid key handoff")}u(G,"unauthorizedHandoff");class L{static{u(this,"AppPrincipalResolver")}issuer;audience;syncGrants;cache;ready=!1;timer;constructor(r,i,e,t){this.issuer=r,this.audience=i,this.syncGrants=e,this.cache=new v(r,fetch,t),this.load(),this.timer=setInterval(()=>{this.ready||this.load()},5e3),this.timer.unref()}async load(){try{await this.cache.load(),this.ready=!0}catch{}}isReady(){return this.ready}get jwks(){return this.cache}close(){this.timer&&clearInterval(this.timer)}ledger=new C;async verifySyncNotice(r){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");return this.ledger.accept(r,this.cache,this.issuer,this.audience)}async verifyHandoff(r,i){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const e=u(()=>G(i),"refuse");if(!r)throw e();let t;try{const f=l(r);if(f.alg!=="ES256")throw e();const y=await this.cache.forKid(f.kid);({payload:t}=await g(r,p(y),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp","jti","sub"]}))}catch{throw e()}const{sub:o,jti:d,exp:a,purpose:c,aud:h}=t;if(c!==i||h!==this.audience||typeof o!="string"||typeof d!="string"||d===""||typeof a!="number")throw e();return{sub:o,jti:d,exp:a}}async verifyDirectoryRead(r,i){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const e=u(()=>new n(401,"unauthorized","invalid directory token"),"refuse");if(!r?.startsWith("Bearer ")||r.length<=7)throw e();const t=r.slice(7);let o;try{const d=l(t);if(d.alg!=="ES256")throw e();const a=await this.cache.forKid(d.kid);({payload:o}=await g(t,p(a),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp"]}))}catch{throw e()}if(o.purpose!==i||o.aud!==this.audience)throw e()}async verifyCall(r){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");if(!r?.startsWith("Bearer ")||r.length<=7)throw new n(401,"unauthorized","a directory access token is required");const i=r.slice(7);try{if(l(i).alg!=="ES256")throw new Error("Invalid call token header");return await k({token:i,jwks:this.cache,issuer:this.issuer,audience:this.audience})}catch(e){throw e instanceof b?new n(401,"unauthorized",e.message):new n(401,"unauthorized","invalid directory access token")}}async resolve(r,i){return this.resolveVerified(await this.verifyCall(r),i)}async resolveVerified(r,i){const e=r.chain[0],t=r.claims,o=e!==void 0&&e.grant!==void 0&&e.rev!==void 0,d=e!==void 0&&_(e.sub)?.kind==="user";if(r.chain.length!==1||!e||!/^[A-Za-z0-9_-]{1,64}$/.test(t.client_id)||!(e.owner===!0||o&&(e.sub.startsWith("app:")||d))||t.grantee!==void 0&&t.grantee!==e.sub||t.rev!==void 0&&t.rev!==e.rev)throw new n(401,"unauthorized","invalid directory access token");if(e.owner===!0){const c=S(e.sub);if(i&&!c.some(h=>w(h,i)))throw new n(403,"scope_missing",`missing scope ${i}`,void 0,void 0,i);return{sub:r.sub,grantee:e.sub,actor:e.sub,client_id:t.client_id,grant:null,rev:null,resolved:c,resolved_scopes:c.map(h=>({scope:h,mode:"always"})),spend_cap:null,dependencies:{},exp:t.exp}}const a=await E(e.grant,e.rev,r.sub,e.sub,this.syncGrants);if(i&&!a.resolved.some(c=>w(c,i)))throw new n(403,"scope_missing",`missing scope ${i}`,void 0,void 0,i);return{sub:r.sub,grantee:e.sub,actor:e.sub,client_id:t.client_id,grant:e.grant,rev:a.rev,resolved:a.resolved,resolved_scopes:a.resolved_scopes,spend_cap:a.spend_cap,dependencies:a.dependencies??{},exp:t.exp}}}async function P(s){return await x(j(s),s.sub,s.grantee)}u(P,"callerGrant");function j(s){if(s.grant===null)throw new n(403,"permission_error","this operation needs a grant; an owner token holds none");return s.grant}u(j,"grantIdOf");export{L as AppPrincipalResolver,P as callerGrant,j as grantIdOf,G as unauthorizedHandoff};
@@ -1 +1 @@
1
- var Fe=Object.defineProperty;var i=(e,r)=>Fe(e,"name",{value:r,configurable:!0});import{markAuthenticated as j,markReceived as V}from"../../core/step-timings.js";import{IMPORT_TOKEN_PREFIX as Me,importPrincipalFor as $e}from"./import-auth.js";import{createServer as pe}from"node:http";import{createServer as Je}from"node:https";import{chmodSync as We,existsSync as X,readFileSync as de,unlinkSync as me}from"node:fs";import{MINIMUM_RUNTIME_VERSION_HEADER as fe,RUNTIME_VERSION_HEADER as Z,minimumRuntimeRefusal as je}from"../../api/runtime-version.js";import{CONTRACT_HEADER as Q,CONTRACT_LEVEL as ge,REQUIRED_CONTRACT_HEADER as he,contractRefusal as Ve}from"../../api/contract.js";import{crtrVersion as q}from"../../shared/crtr-version.js";import{apiSocketPath as Ge}from"../../core/canvas/paths.js";import{resolveNodeToken as Ye}from"../../core/canvas/node-tokens.js";import{isCloudRole as I,runAsPerson as G}from"../../core/canvas/person.js";import{isCanvasRequest as Ke,serveCanvas as Xe}from"./canvas-host.js";import{personBearerVerifier as Re}from"./auth/person-bearer.js";import{personHasSnapshot as ee}from"../../core/scoped-state/person-store.js";import{loadPersonSettings as re}from"../../core/scoped-state/person-rows.js";import{AppPrincipalResolver as Ze}from"./principal.js";import{createAppRequestHandler as Qe}from"./app-listener.js";import{decodeJwt as qe}from"jose";import{handleRuntimeSignIn as er,isRuntimeSignInPath as rr}from"./key-signin.js";import{RunError as C}from"../../core/runs/operations.js";import{createRepoPluginHandler as tr,isRepoPluginPath as nr}from"./repo-plugin.js";import{removeVendorAccount as or,vendorStatus as ir}from"./handlers/vendor-status.js";import{toErrorBody as sr}from"./map.js";import{CONTROL_BODY_MAX_BYTES as ar}from"../../core/llm/body-limits.js";import{grantFor as lr,hasSyncedGrants as cr}from"../../core/grants/mirror.js";import{readConfig as Ae}from"../../core/config.js";import{directoryIssuer as ur}from"../../core/directory/issuer.js";import{peerUid as pr}from"../../native/linux.js";import{findScopedApiToken as dr,getApiToken as mr,listScopedApiTokens as fr}from"../../core/secrets.js";import{emitEvent as A}from"../../core/events/emit.js";import{envCrtrdTcp as gr,envCrtrdToken as hr}from"../../shared/env.js";import{Router as ve,actsAsPerson as ye}from"./router.js";import{handleAttachUpgrade as Rr,refuseUpgrade as y}from"./bridge.js";import{handleMachineLinkUpgrade as Ar,machineLinkEnvironment as vr,setApiAddress as yr}from"../machine-link/holder.js";import{handleMachineViewUpgrade as _r,machineViewEnvironment as wr}from"../machine-link/forward.js";import{boundDaemonControl as Er}from"../control.js";import{attachRoutes as Sr,mayAttachNode as _e}from"./handlers/attach.js";import{peerRoutes as br}from"../peer/handlers.js";import{bashJobRoutes as Tr}from"./handlers/bash-jobs.js";import{nodeFileRoutes as Cr}from"./handlers/node-files.js";import{bashRoutes as kr}from"./handlers/bash.js";import{hookExecRoutes as Pr}from"./handlers/hook-exec.js";import{brokerOperationRoutes as we}from"./handlers/broker-ops.js";import{brokerSignalRoutes as Ur,brokerSignalStreams as Or}from"./handlers/broker-signals.js";import{brokerRecoveryRoutes as Ee,nodeFaultRoutes as Nr}from"./handlers/broker-recovery.js";import{canvasRoutes as Ir}from"./handlers/canvas.js";import{conversationRoutes as Hr}from"./handlers/conversations.js";import{chatInventoryRoutes as zr}from"./handlers/chat-inventory.js";import{daemonRoutes as Lr}from"./handlers/daemon.js";import{fileRoutes as Br}from"./handlers/files.js";import{focusRoutes as xr}from"./handlers/focus.js";import{analyticsRoutes as Dr}from"./handlers/analytics.js";import{memoryReadsRoutes as Fr}from"./handlers/memory-reads.js";import{memoryRoutes as Mr}from"./handlers/memory.js";import{healthRoutes as $r}from"./handlers/health.js";import{humanRequestRoutes as Jr}from"./handlers/human-requests.js";import{inboxRoutes as Wr}from"./handlers/inbox.js";import{feedbackCommentRoutes as jr}from"./handlers/feedback-comments.js";import{objectRoutes as Vr}from"./handlers/objects.js";import{shareRoutes as Gr}from"./handlers/shares.js";import{customObjectRoutes as Yr}from"./handlers/custom-objects.js";import{docRoutes as Kr}from"./handlers/docs.js";import{deliveryRoutes as Se}from"./handlers/delivery.js";import{deliveryRetryRoutes as Xr}from"./handlers/delivery-retry.js";import{packageDocRoutes as Zr}from"./handlers/package-docs.js";import{documentAccessRoutes as Qr}from"./handlers/document-access.js";import{pluginAppRoutes as qr}from"./handlers/plugin-app-token.js";import{brokerMailRoutes as be,messageRoutes as et}from"./handlers/messages.js";import{modelAuthRoutes as rt}from"./handlers/modelauth.js";import{llmRoutes as tt}from"./handlers/llm.js";import{providerRoutes as nt}from"./handlers/providers.js";import{modelConfigRoutes as ot}from"./handlers/model-config.js";import{settingsRoutes as it}from"./handlers/settings.js";import{nodeRoutes as st}from"./handlers/nodes.js";import{nodeRecordRoutes as at}from"./handlers/node-records.js";import{nodeOutcomeRoutes as lt}from"./handlers/node-outcomes.js";import{nodeEventRoutes as ct}from"./handlers/node-events.js";import{profileRoutes as ut}from"./handlers/profiles.js";import{environmentRoutes as pt}from"./handlers/environments.js";import{prospectiveChatInventoryRoutes as dt}from"./handlers/prospective-chat-inventory.js";import{reportRoutes as mt}from"./handlers/reports.js";import{runRoutes as ft}from"./handlers/run-routes.js";import{reviewCommentRoutes as gt}from"./handlers/review-comments.js";import{reviewRoutes as ht}from"./handlers/reviews.js";import{subscriptionRoutes as Rt}from"./handlers/subscriptions.js";import{structuredRequestRoutes as At}from"./handlers/structured-requests.js";import{cronRoutes as vt}from"./handlers/crons.js";import{setCronRequestHandler as Te}from"../cron/run-socket.js";import{RUN_TOKEN_PREFIX as yt,cronPrincipalForRunToken as _t}from"../cron/run-token.js";import{worktreeRoutes as wt}from"./handlers/worktree.js";import{limitsRoutes as Et}from"./handlers/limits.js";import{chargeRoutes as St,spendLimitRoutes as bt}from"./handlers/charges.js";import{executionStartRoutes as Tt}from"./handlers/execution-start.js";import{machineCredentialRoutes as Ct}from"./handlers/machine-credential.js";import{machineRoutes as kt}from"./handlers/machines.js";import{importRoutes as Pt}from"./handlers/imports.js";import{gitCredentialRoutes as Ut}from"./handlers/git-credential.js";import{feedbackRoutes as Ot}from"./handlers/feedback.js";function Nt(e){return new ve().registerAll($r(e)).registerAll(Lr).registerAll(Gr).registerAll(st).registerAll(at).registerAll(lt).registerAll(Xr).registerAll(ct).registerAll(Tr).registerAll(Cr).registerAll(kr).registerAll(Pr).registerAll(we).registerAll(Ur).registerAll(Se).registerAll(Ee).registerAll(Nr).registerAll(wt).registerAll(Et).registerAll(St).registerAll(Tt).registerAll(Ct).registerAll(kt).registerAll(Pt).registerAll(Ut).registerAll(Ot).registerAll(bt).registerAll(be).registerAll(et).registerAll(mt).registerAll(ft).registerAll(At).registerAll(Sr).registerAll(Ir).registerAll(Hr).registerAll(Dr).registerAll(Fr).registerAll(Mr).registerAll(Br).registerAll(Vr).registerAll(Yr).registerAll(Kr).registerAll(Zr).registerAll(Qr).registerAll(qr).registerAll(xr).registerAll(Rt).registerAll(vt).registerAll(ut).registerAll(pt).registerAll(rt).registerAll(tt).registerAll(nt).registerAll(ot).registerAll(it).registerAll(ht).registerAll(gt).registerAll(Wr).registerAll(Jr).registerAll(zr).registerAll(dt).registerAll(jr).registerAll(br)}i(Nt,"buildRouter");function It(e,r){if(e.toUpperCase()!=="GET")return null;const s=r.split("/").filter(u=>u.length>0);if(s.length!==4||s[0]!=="v1"||s[1]!=="nodes"||s[3]!=="attach")return null;const a=s[2];return a===void 0||a===""?null:decodeURIComponent(a)}i(It,"attachNodeId");function Ht(e){const r=e.trim();if(r==="")return null;const s=r.lastIndexOf(":");if(s<0)return null;const a=r.slice(0,s),u=r.slice(s+1),d=Number(u);return!Number.isInteger(d)||d<0||d>65535?null:{host:a===""?"0.0.0.0":a,port:d}}i(Ht,"parseTcp");function zt(e,r){return`${e.includes(":")?`[${e}]`:e}:${r}`}i(zt,"formatTcpAddress");const M={code:"unauthorized",message:"missing or invalid bearer token"},L={code:"owner_only",message:"attach is owner-only; a scoped token does not reach it"},$={code:"person_bearer_not_supported",message:"this listener accepts a person bearer only on a cloud role with CRTR_DIRECTORY_URL and CRTR_PUBLIC_API_URL set; call with a node, app or public token"},te={class:"anonymous",app:"",node:"",run:null,uid:-1,sub:"",grant:null,client_id:null,scopes:[]},B=new WeakMap;function J(e){return B.get(e)}i(J,"socketPrincipal");async function Ce(e,r){const s=process.platform==="linux"?pr(e.socket):null,a=e.headers.authorization;if(a===void 0)return s===null||r.has(s)?{class:"person"}:"unauthorized";if(typeof a!="string"||!a.startsWith("Bearer "))return"unauthorized";if(a.slice(7).startsWith("crtr_pub_"))return te;if(a.slice(7).startsWith(ne)){const u=Oe(a.slice(7));return u!==void 0&&(s===null||r.has(s))?u.principal:"unauthorized"}return ke(a.slice(7),s)}i(Ce,"resolveSocketPrincipal");async function ke(e,r){const s=await Ye(e);if(!s||r!==null&&r!==s.uid)return"unauthorized";const a=ur();if(a&&!I()&&!await cr(a))return"runtime_starting";const u=s.grant??(await lr("app:terminal",s.sub))?.id??null;return{class:"broker",...s,grant:u}}i(ke,"brokerPrincipal");function Pe(e){if(!(e.class==="anonymous"||e.class==="import"))return e.sub!==void 0&&e.sub!==""?e.sub:void 0}i(Pe,"requestPerson");function Ue(e,r){r.class==="broker"&&A({event:"api.request.principal",level:r.app==="app:terminal"?"debug":"info",node_id:r.node,fields:{principal:`${r.app} node:${r.node}`,method:e.method,path:e.url}})}i(Ue,"noteBrokerRequest");const ne="crtr_app_";function Oe(e){const r=e.startsWith(ne)?dr(e):void 0;return r===void 0?void 0:{principal:{class:"app",app:r.grantee,scopes:r.scopes},ceiling:r.scopes}}i(Oe,"appBearer");function Lt(e){const r=new Map;for(const s of fr("user"))r.set(s.token,{principal:{class:"app",app:s.grantee,scopes:s.scopes},ceiling:s.scopes});return e!==void 0&&r.set(e,{principal:{class:"person"},ceiling:null}),r}i(Lt,"resolveBearers");function Bt(e){try{return qe(e).act!==void 0}catch{return!1}}i(Bt,"carriesAct");const xt=/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/;function U(e,r){return e!==void 0&&(e.reason=r),"unauthorized"}i(U,"deny");async function Ne(e,r,s){const a=e.headers.authorization;if(a===void 0&&(e.method??"GET").toUpperCase()==="GET"&&(e.url??"").split("?")[0]==="/healthz")return{principal:te,ceiling:null};if(typeof a!="string"||!a.startsWith("Bearer "))return U(s,a===void 0?"no_authorization_header":"not_a_bearer");const u=a.slice(7);if(u.startsWith("crtr_pub_"))return{principal:te,ceiling:null};if(u.startsWith(ne))return Oe(u)??U(s,"app_token_unknown");if(u.startsWith(yt)){const S=await _t(u);return S===null?U(s,"run_token_invalid_or_settled"):{principal:S,ceiling:null}}const d=r.get(u);if(d!==void 0)return d;const g=$e(u);if(g!==null)return{principal:g,ceiling:null};if(u.startsWith(Me))return U(s,"import_token_invalid");if(xt.test(u)){if(I()&&Bt(u)){const x=K();if(x===null)return"person_bearer";try{const w=await x.verifyCall(a);return w.chain[0]?.sub.startsWith("app:")?{call:w}:U(s,"call_token_presenter_not_an_app")}catch(w){return w instanceof C&&w.status===503?"runtime_starting":U(s,`call_token_${w instanceof C?w.code:"invalid"}`)}}const S=I()?Re():null;if(S===null)return"person_bearer";const O=await S.verify(u);return O===null?U(s,"person_bearer_not_verified"):{principal:{class:"person",sub:O},ceiling:null}}const f=await ke(u,null);return f==="unauthorized"?U(s,"node_token_unknown"):typeof f=="string"?f:{principal:f,ceiling:null}}i(Ne,"authorizeTcp");let Y;function K(){if(Y!==void 0)return Y;const e=process.env.CRTR_DIRECTORY_URL||void 0,r=process.env.CRTR_PUBLIC_API_URL||void 0;return Y=e===void 0||r===void 0?null:new Ze(e,r,async()=>{}),Y}i(K,"cloudCallResolver");let Ie;function Dt(){const e=K();if(e===null)throw new C(503,"runtime_starting","app calls are not configured on this listener");return Ie??=Qe(e,async()=>!0,async()=>{}),Ie}i(Dt,"cloudAppCalls");async function Ft(e,r){H(r),z(r);const s=K();try{if(s===null)throw new C(503,"runtime_starting","sign-in is not configured on this listener");await er(e,r,new URL(e.url??"/","http://runtime.local"),s)}catch(a){if(!(a instanceof C))throw a;if(r.headersSent){r.destroy();return}r.writeHead(a.status,{"content-type":"application/json; charset=utf-8","cache-control":"no-store"}),r.end(JSON.stringify({error:{code:a.code,message:a.message,...a.param?{param:a.param}:{},origin:"runtime"}}))}}i(Ft,"serveRuntimeSignIn");function Mt(){const e=process.env.CRTRD_TLS_CERT||void 0,r=process.env.CRTRD_TLS_KEY||void 0;if(e===void 0&&r===void 0)return null;if(e===void 0||r===void 0)throw new Error("CRTRD_TLS_CERT and CRTRD_TLS_KEY must be set together");return{cert:de(e),key:de(r)}}i(Mt,"tcpTls");function H(e){e.setHeader(Z,q()),e.setHeader(Q,ge)}i(H,"advertiseRuntime");function z(e){e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Expose-Headers",`${Z}, ${Q}`)}i(z,"exposeRuntimeHeaders");function $t(e,r){return(e.method??"GET").toUpperCase()!=="OPTIONS"?!1:(H(r),r.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Expose-Headers":`${Z}, ${Q}`,"Access-Control-Allow-Headers":`authorization, content-type, ${fe.toLowerCase()}, ${he.toLowerCase()}`,"Access-Control-Allow-Methods":"GET, POST, PATCH, PUT, DELETE, OPTIONS","Access-Control-Max-Age":"600"}),r.end(),!0)}i($t,"answerPreflight");function oe(e,r=!1){H(e),r&&z(e),e.writeHead(401,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{...M,origin:"runtime"}}))}i(oe,"writeUnauthorized");function Jt(e){H(e),z(e),e.writeHead(401,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{...$,origin:"runtime"}}))}i(Jt,"writePersonBearerRefused");const Wt={"/v1/runtime/vendor-status":{method:"GET",purpose:"vendor_status"},"/v1/runtime/vendor-account-remove":{method:"POST",purpose:"vendor_account_remove"}};async function jt(e,r){if(!I())return!1;const s=new URL(e.url??"/","http://runtime.local").pathname,a=Wt[s];if(a===void 0||e.method!==a.method)return!1;const u=i((d,g)=>{H(r),z(r),r.writeHead(d,{"content-type":"application/json; charset=utf-8"}),r.end(JSON.stringify(g))},"answer");try{const d=Re();if(d===null)throw new C(401,$.code,$.message);const g=e.headers.authorization,f=g?.startsWith("Bearer ")?await d.verifyPurpose(g.slice(7),a.purpose):null;if(f===null)throw new C(401,"unauthorized","invalid directory token");const S=a.purpose==="vendor_status"?void 0:await Vt(e);u(200,await G(f,async()=>a.purpose==="vendor_status"?ir():await or(S)))}catch(d){const{status:g,body:f}=sr(d);u(g,f)}return!0}i(jt,"serveCloudVendorRoute");async function Vt(e){const r=[];let s=0;for await(const a of e){if(s+=a.length,s>ar)throw new C(400,"invalid_request","request body too large");r.push(a)}if(s!==0)try{return JSON.parse(Buffer.concat(r).toString("utf8"))}catch{throw new C(400,"invalid_request","invalid JSON body")}}i(Vt,"readVendorBody");function ie(e){H(e),e.writeHead(503,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{code:"runtime_starting",message:"runtime is not ready",type:"server_error",origin:"runtime",retryable:!0}}))}i(ie,"writeRuntimeStarting");function Gt(e,r){e.writeHead(503,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{code:"startup_blocked",message:r,origin:"runtime"}}))}i(Gt,"writeStartupBlocked");function He(e,r,s){return new Promise(a=>{for(const f of r)f.destroy();if(s===void 0){try{e.closeAllConnections()}catch{}e.close(()=>a());return}const u=[];e.close(()=>{for(const f of u)clearTimeout(f);a()});const d=setInterval(()=>e.closeIdleConnections(),250),g=setTimeout(()=>e.closeAllConnections(),s);u.push(d,g),e.closeIdleConnections()})}i(He,"closeServer");function Mo(e={}){let r=null;const s=Nt(()=>r),a=new ve().registerAll(we).registerAll(Se).registerAll(Ee).registerAll(be),u=i((t,n)=>{const c=Er()?.startupBlock()??null;return c===null||t==="GET"&&(n==="/healthz"||n==="/v1/status"||n==="/v1/ready")||t==="POST"&&(n==="/v1/daemon/migrate"||n==="/v1/daemon/admit")||c.phase==="recovering"&&a.match(t,n)!==null?null:c},"startupBlockFor"),d=e.socketPath??Ge(),g=new Set([process.getuid?.()??0,...Ae("user").runtime?.person_uids??[]]),f=i((t,n,c)=>{H(n);const p=i(m=>Array.isArray(m)?m[0]:m,"first"),N=p(t.headers[fe.toLowerCase()]),h=je(N,q())??Ve(p(t.headers[he.toLowerCase()]),ge,{legacyMinimum:N,runtimeVersion:q()});if(h!==null){n.writeHead(h.status,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:h.code,message:h.message,type:"invalid_request_error",origin:"runtime",retryable:!1,..."param"in h?{param:h.param}:{details:h.details}}}));return}const T=i(m=>{const E=J(t);A({event:"api.request.failed",level:"error",...E?.class==="broker"?{node_id:E.node}:{},error:m instanceof Error?m:new Error(String(m))});try{n.headersSent||n.writeHead(500,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:"internal",message:"internal error",origin:"runtime"}}))}catch{}},"internalFailure");let k;try{k=new URL(t.url??"/","http://127.0.0.1")}catch{try{n.writeHead(400,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:"invalid_request",message:"request URL is invalid",origin:"runtime"}}))}catch{}return}try{const m=u((t.method??"GET").toUpperCase(),k.pathname);if(m!==null){Gt(n,m.message);return}const E=J(t)??{class:"person"},o=Pe(E),l=i(()=>s.handle(t,n,c,E),"handled");(o===void 0?l():G(o,i(async()=>{ee()||await re(o),await l()},"handledAsPerson"))).catch(T)}catch(m){T(m)}},"onRequest"),S=i(async(t,n,c)=>{const p=J(t);return p===void 0||ye(p)||await _e(p,"either",c)?!0:(y(n,404,"Not Found","node_not_found",`no node ${c}`),!1)},"authorizeAttachUpgrade"),O=new Set,x=i(t=>{O.add(t),t.once("close",()=>O.delete(t)),t.on("error",()=>{})},"trackUpgrade"),w=i((t,n,c)=>{try{const p=new URL(t.url??"/","http://127.0.0.1"),N=u((t.method??"GET").toUpperCase(),p.pathname);if(N!==null){y(n,503,"Service Unavailable","startup_blocked",N.message);return}const h=It(t.method??"GET",p.pathname);if(h===null){n.destroy();return}const T=(()=>{const m=J(t);return m===void 0?void 0:Pe(m)})(),k=i(()=>S(t,n,h).then(m=>m?Rr(t,n,c,h,async E=>{const o=J(t);return o===void 0||ye(o)||await _e(o,E,h)}):void 0),"attach");(T===void 0?k():G(T,async()=>{ee()||await re(T),await k()})).catch(()=>{try{n.destroy()}catch{}})}catch{try{n.destroy()}catch{}}},"onUpgrade"),ze=i(t=>{t.on("error",n=>{A({event:"api.server.failed",level:"error",error:n})})},"bindErrorHandler"),Le=i(async(t,n)=>{V(t);try{const c=await Ce(t,g);if(j(t),c==="unauthorized"){A({event:"api.principal.denied",level:"warn",fields:{method:t.method}}),oe(n);return}if(c==="runtime_starting"){ie(n);return}B.set(t,c),Ue(t,c),f(t,n,c.class==="app"?c.scopes:null)}catch(c){A({event:"api.principal.failed",level:"error",error:c instanceof Error?c:new Error(String(c))}),ie(n)}},"onSocketRequest"),D=pe((t,n)=>{Le(t,n).catch(c=>A({event:"api.principal.failed",level:"error",error:c instanceof Error?c:new Error(String(c))}))}),Be=i(async(t,n,c)=>{V(t);try{const p=await Ce(t,g);if(j(t),p==="unauthorized"||p==="runtime_starting"){p==="unauthorized"&&A({event:"api.principal.denied",level:"warn",fields:{method:t.method}}),y(n,p==="unauthorized"?401:503,"Unauthorized",p,"socket principal unavailable");return}if(p.class!=="person"&&p.class!=="broker"){y(n,403,"Forbidden",L.code,L.message);return}B.set(t,p),w(t,n,c)}catch(p){A({event:"api.principal.failed",level:"error",error:p instanceof Error?p:new Error(String(p))}),y(n,503,"Service Unavailable","runtime_starting","socket principal unavailable")}},"onSocketUpgrade");D.on("upgrade",(t,n,c)=>{x(n),Be(t,n,c).catch(p=>A({event:"api.principal.failed",level:"error",error:p instanceof Error?p:new Error(String(p))}))}),Te((t,n,c)=>{B.set(t,c),f(t,n,null)});let se=!1,ae,le;const xe=new Promise((t,n)=>{ae=t,le=n});D.once("listening",()=>{se=!0,ae()}),D.on("error",t=>{A({event:"api.server.failed",level:"error",error:t}),se||le(t)});try{X(d)&&me(d)}catch{}D.listen(d,()=>{try{We(d,process.platform==="linux"&&X("/run/crtr/launcher.sock")?438:384)}catch(t){A({event:"api.socket.chmod_failed",level:"error",error:t instanceof Error?t:new Error(String(t))})}});let b,ce=Promise.resolve();const W=e.tcp??gr()??Ae("user").api.tcp;if(W!==void 0&&W!==""){const t=Ht(W);if(t===null)A({event:"api.tcp.invalid",level:"error",error:new Error(`invalid CRTRD_TCP/--tcp spec: ${W}`)});else{I()&&K();const n=I()?tr():null,c=e.token??hr()??mr("user"),p=Lt(c),N=i(async(o,l)=>{if(V(o),Ke(o)){await Xe(o,l);return}if($t(o,l))return;if(I()&&rr(new URL(o.url??"/","http://runtime.local").pathname)){await Ft(o,l);return}if(await jt(o,l))return;if(n!==null&&nr(new URL(o.url??"/","http://runtime.local").pathname)){await n(o,l);return}const v={},R=await Ne(o,p,v);if(j(o),R==="runtime_starting"){z(l),ie(l);return}if(R==="person_bearer"){Jt(l);return}if(R==="unauthorized"){A({event:"api.principal.denied",level:"warn",fields:{method:o.method,listener:"tcp",path:new URL(o.url??"/","http://runtime.local").pathname,reason:v.reason??"unknown"}}),oe(l,!0);return}if("call"in R){z(l);const F=R.call.sub;await G(F,async()=>{ee()||await re(F),await Dt()(o,l,R.call)});return}B.set(o,R.principal),Ue(o,R.principal),z(l),f(o,l,R.ceiling)},"tcpOnRequest"),h=i(async(o,l,v)=>{V(o);const R=vr(o);if(R!==null){const _=await Ar(o,l,v,R);_!==null&&y(l,_.status,_.text,_.code,_.message);return}const F=wr(o);if(F!==null){const _=_r(o,l,v,F);_!==null&&y(l,_.status,_.text,_.code,_.message);return}const P=await Ne(o,p);if(j(o),P==="runtime_starting"){y(l,503,"Service Unavailable","runtime_starting","grant sync is not ready");return}if(P==="person_bearer"){y(l,401,"Unauthorized",$.code,$.message);return}if(P==="unauthorized"){y(l,401,"Unauthorized",M.code,M.message);return}if("call"in P){y(l,403,"Forbidden",L.code,L.message);return}if(P.ceiling!==null||P.principal.class==="anonymous"||P.principal.class==="import"){y(l,403,"Forbidden",L.code,L.message);return}B.set(o,P.principal),w(o,l,v)},"tcpOnUpgrade"),T=i(o=>{A({event:"api.principal.failed",level:"error",error:o instanceof Error?o:new Error(String(o))})},"failed"),k=i((o,l)=>{N(o,l).catch(v=>{T(v),l.headersSent?l.destroy():oe(l,!0)})},"listener"),m=Mt();b=m===null?pe(k):Je(m,k),b.on("upgrade",(o,l,v)=>{x(l),h(o,l,v).catch(R=>{T(R),y(l,401,"Unauthorized",M.code,M.message)})}),ze(b),b.once("listening",()=>{const o=b?.address();if(o!==null&&typeof o=="object"){const{address:l,port:v}=o;r=zt(l,v),l!=="0.0.0.0"&&l!=="::"&&yr(r)}});const E=b;ce=new Promise(o=>{E.once("listening",o),E.once("error",()=>o())}),b.listen(t.port,t.host)}}let ue=!1;const De=i(async(t={})=>{if(!ue){ue=!0,Te(null),Or.close(),await Promise.all([He(D,O,t.graceMs),b!==void 0?He(b,O,t.graceMs):Promise.resolve()]);try{X(d)&&me(d)}catch{}}},"close");return{ready:xe.then(()=>ce),tcpAddress:i(()=>r,"tcpAddress"),close:De}}i(Mo,"createApiServer");export{Nt as buildRouter,He as closeServer,Mo as createApiServer,J as socketPrincipal};
1
+ var Fe=Object.defineProperty;var i=(e,r)=>Fe(e,"name",{value:r,configurable:!0});import{markAuthenticated as j,markReceived as V}from"../../core/step-timings.js";import{IMPORT_TOKEN_PREFIX as Me,importPrincipalFor as $e}from"./import-auth.js";import{createServer as pe}from"node:http";import{createServer as Je}from"node:https";import{chmodSync as We,existsSync as X,readFileSync as de,unlinkSync as me}from"node:fs";import{MINIMUM_RUNTIME_VERSION_HEADER as fe,RUNTIME_VERSION_HEADER as Z,minimumRuntimeRefusal as je}from"../../api/runtime-version.js";import{CONTRACT_HEADER as Q,CONTRACT_LEVEL as ge,REQUIRED_CONTRACT_HEADER as he,contractRefusal as Ve}from"../../api/contract.js";import{crtrVersion as q}from"../../shared/crtr-version.js";import{apiSocketPath as Ge}from"../../core/canvas/paths.js";import{resolveNodeToken as Ye}from"../../core/canvas/node-tokens.js";import{isCloudRole as I,runAsPerson as G}from"../../core/canvas/person.js";import{isCanvasRequest as Ke,serveCanvas as Xe}from"./canvas-host.js";import{personBearerVerifier as Re}from"./auth/person-bearer.js";import{personHasSnapshot as ee}from"../../core/scoped-state/person-store.js";import{loadPersonSettings as re}from"../../core/scoped-state/person-rows.js";import{AppPrincipalResolver as Ze}from"./principal.js";import{createAppRequestHandler as Qe}from"./app-listener.js";import{decodeJwt as qe}from"jose";import{handleRuntimeSignIn as er,isRuntimeSignInPath as rr}from"./key-signin.js";import{RunError as C}from"../../core/runs/operations.js";import{createRepoPluginHandler as tr,isRepoPluginPath as nr}from"./repo-plugin.js";import{removeVendorAccount as or,vendorStatus as ir}from"./handlers/vendor-status.js";import{toErrorBody as sr}from"./map.js";import{CONTROL_BODY_MAX_BYTES as ar}from"../../core/llm/body-limits.js";import{grantFor as lr,hasSyncedGrants as cr}from"../../core/grants/mirror.js";import{readConfig as Ae}from"../../core/config.js";import{directoryIssuer as ur}from"../../core/directory/issuer.js";import{peerUid as pr}from"../../native/linux.js";import{findScopedApiToken as dr,getApiToken as mr,listScopedApiTokens as fr}from"../../core/secrets.js";import{emitEvent as A}from"../../core/events/emit.js";import{envCrtrdTcp as gr,envCrtrdToken as hr}from"../../shared/env.js";import{Router as ve,actsAsPerson as ye}from"./router.js";import{handleAttachUpgrade as Rr,refuseUpgrade as y}from"./bridge.js";import{handleMachineLinkUpgrade as Ar,machineLinkEnvironment as vr,setApiAddress as yr}from"../machine-link/holder.js";import{handleMachineViewUpgrade as _r,machineViewEnvironment as wr}from"../machine-link/forward.js";import{boundDaemonControl as Er}from"../control.js";import{attachRoutes as Sr,mayAttachNode as _e}from"./handlers/attach.js";import{peerRoutes as br}from"../peer/handlers.js";import{bashJobRoutes as Tr}from"./handlers/bash-jobs.js";import{nodeFileRoutes as Cr}from"./handlers/node-files.js";import{bashRoutes as kr}from"./handlers/bash.js";import{hookExecRoutes as Pr}from"./handlers/hook-exec.js";import{brokerOperationRoutes as we}from"./handlers/broker-ops.js";import{brokerSignalRoutes as Ur,brokerSignalStreams as Or}from"./handlers/broker-signals.js";import{brokerRecoveryRoutes as Ee,nodeFaultRoutes as Nr}from"./handlers/broker-recovery.js";import{canvasRoutes as Ir}from"./handlers/canvas.js";import{conversationRoutes as Hr}from"./handlers/conversations.js";import{chatInventoryRoutes as zr}from"./handlers/chat-inventory.js";import{daemonRoutes as Lr}from"./handlers/daemon.js";import{fileRoutes as Br}from"./handlers/files.js";import{focusRoutes as xr}from"./handlers/focus.js";import{analyticsRoutes as Dr}from"./handlers/analytics.js";import{memoryReadsRoutes as Fr}from"./handlers/memory-reads.js";import{memoryRoutes as Mr}from"./handlers/memory.js";import{healthRoutes as $r}from"./handlers/health.js";import{humanRequestRoutes as Jr}from"./handlers/human-requests.js";import{inboxRoutes as Wr}from"./handlers/inbox.js";import{feedbackCommentRoutes as jr}from"./handlers/feedback-comments.js";import{objectRoutes as Vr}from"./handlers/objects.js";import{shareRoutes as Gr}from"./handlers/shares.js";import{customObjectRoutes as Yr}from"./handlers/custom-objects.js";import{docRoutes as Kr}from"./handlers/docs.js";import{deliveryRoutes as Se}from"./handlers/delivery.js";import{deliveryRetryRoutes as Xr}from"./handlers/delivery-retry.js";import{packageDocRoutes as Zr}from"./handlers/package-docs.js";import{documentAccessRoutes as Qr}from"./handlers/document-access.js";import{pluginAppRoutes as qr}from"./handlers/plugin-app-token.js";import{brokerMailRoutes as be,messageRoutes as et}from"./handlers/messages.js";import{modelAuthRoutes as rt}from"./handlers/modelauth.js";import{llmRoutes as tt}from"./handlers/llm.js";import{providerRoutes as nt}from"./handlers/providers.js";import{modelConfigRoutes as ot}from"./handlers/model-config.js";import{settingsRoutes as it}from"./handlers/settings.js";import{nodeRoutes as st}from"./handlers/nodes.js";import{nodeRecordRoutes as at}from"./handlers/node-records.js";import{nodeOutcomeRoutes as lt}from"./handlers/node-outcomes.js";import{nodeEventRoutes as ct}from"./handlers/node-events.js";import{profileRoutes as ut}from"./handlers/profiles.js";import{environmentRoutes as pt}from"./handlers/environments.js";import{appEnvironmentRoutes as dt}from"./handlers/app-environments.js";import{prospectiveChatInventoryRoutes as mt}from"./handlers/prospective-chat-inventory.js";import{reportRoutes as ft}from"./handlers/reports.js";import{runRoutes as gt}from"./handlers/run-routes.js";import{reviewCommentRoutes as ht}from"./handlers/review-comments.js";import{reviewRoutes as Rt}from"./handlers/reviews.js";import{subscriptionRoutes as At}from"./handlers/subscriptions.js";import{structuredRequestRoutes as vt}from"./handlers/structured-requests.js";import{cronRoutes as yt}from"./handlers/crons.js";import{setCronRequestHandler as Te}from"../cron/run-socket.js";import{RUN_TOKEN_PREFIX as _t,cronPrincipalForRunToken as wt}from"../cron/run-token.js";import{worktreeRoutes as Et}from"./handlers/worktree.js";import{limitsRoutes as St}from"./handlers/limits.js";import{chargeRoutes as bt,spendLimitRoutes as Tt}from"./handlers/charges.js";import{executionStartRoutes as Ct}from"./handlers/execution-start.js";import{machineCredentialRoutes as kt}from"./handlers/machine-credential.js";import{machineRoutes as Pt}from"./handlers/machines.js";import{importRoutes as Ut}from"./handlers/imports.js";import{gitCredentialRoutes as Ot}from"./handlers/git-credential.js";import{feedbackRoutes as Nt}from"./handlers/feedback.js";function It(e){return new ve().registerAll($r(e)).registerAll(Lr).registerAll(Gr).registerAll(st).registerAll(at).registerAll(lt).registerAll(Xr).registerAll(ct).registerAll(Tr).registerAll(Cr).registerAll(kr).registerAll(Pr).registerAll(we).registerAll(Ur).registerAll(Se).registerAll(Ee).registerAll(Nr).registerAll(Et).registerAll(St).registerAll(bt).registerAll(Ct).registerAll(kt).registerAll(Pt).registerAll(Ut).registerAll(Ot).registerAll(Nt).registerAll(Tt).registerAll(be).registerAll(et).registerAll(ft).registerAll(gt).registerAll(vt).registerAll(Sr).registerAll(Ir).registerAll(Hr).registerAll(Dr).registerAll(Fr).registerAll(Mr).registerAll(Br).registerAll(Vr).registerAll(Yr).registerAll(Kr).registerAll(Zr).registerAll(Qr).registerAll(qr).registerAll(xr).registerAll(At).registerAll(yt).registerAll(ut).registerAll(pt).registerAll(dt).registerAll(rt).registerAll(tt).registerAll(nt).registerAll(ot).registerAll(it).registerAll(Rt).registerAll(ht).registerAll(Wr).registerAll(Jr).registerAll(zr).registerAll(mt).registerAll(jr).registerAll(br)}i(It,"buildRouter");function Ht(e,r){if(e.toUpperCase()!=="GET")return null;const s=r.split("/").filter(u=>u.length>0);if(s.length!==4||s[0]!=="v1"||s[1]!=="nodes"||s[3]!=="attach")return null;const a=s[2];return a===void 0||a===""?null:decodeURIComponent(a)}i(Ht,"attachNodeId");function zt(e){const r=e.trim();if(r==="")return null;const s=r.lastIndexOf(":");if(s<0)return null;const a=r.slice(0,s),u=r.slice(s+1),d=Number(u);return!Number.isInteger(d)||d<0||d>65535?null:{host:a===""?"0.0.0.0":a,port:d}}i(zt,"parseTcp");function Lt(e,r){return`${e.includes(":")?`[${e}]`:e}:${r}`}i(Lt,"formatTcpAddress");const M={code:"unauthorized",message:"missing or invalid bearer token"},L={code:"owner_only",message:"attach is owner-only; a scoped token does not reach it"},$={code:"person_bearer_not_supported",message:"this listener accepts a person bearer only on a cloud role with CRTR_DIRECTORY_URL and CRTR_PUBLIC_API_URL set; call with a node, app or public token"},te={class:"anonymous",app:"",node:"",run:null,uid:-1,sub:"",grant:null,client_id:null,scopes:[]},B=new WeakMap;function J(e){return B.get(e)}i(J,"socketPrincipal");async function Ce(e,r){const s=process.platform==="linux"?pr(e.socket):null,a=e.headers.authorization;if(a===void 0)return s===null||r.has(s)?{class:"person"}:"unauthorized";if(typeof a!="string"||!a.startsWith("Bearer "))return"unauthorized";if(a.slice(7).startsWith("crtr_pub_"))return te;if(a.slice(7).startsWith(ne)){const u=Oe(a.slice(7));return u!==void 0&&(s===null||r.has(s))?u.principal:"unauthorized"}return ke(a.slice(7),s)}i(Ce,"resolveSocketPrincipal");async function ke(e,r){const s=await Ye(e);if(!s||r!==null&&r!==s.uid)return"unauthorized";const a=ur();if(a&&!I()&&!await cr(a))return"runtime_starting";const u=s.grant??(await lr("app:terminal",s.sub))?.id??null;return{class:"broker",...s,grant:u}}i(ke,"brokerPrincipal");function Pe(e){if(!(e.class==="anonymous"||e.class==="import"))return e.sub!==void 0&&e.sub!==""?e.sub:void 0}i(Pe,"requestPerson");function Ue(e,r){r.class==="broker"&&A({event:"api.request.principal",level:r.app==="app:terminal"?"debug":"info",node_id:r.node,fields:{principal:`${r.app} node:${r.node}`,method:e.method,path:e.url}})}i(Ue,"noteBrokerRequest");const ne="crtr_app_";function Oe(e){const r=e.startsWith(ne)?dr(e):void 0;return r===void 0?void 0:{principal:{class:"app",app:r.grantee,scopes:r.scopes},ceiling:r.scopes}}i(Oe,"appBearer");function Bt(e){const r=new Map;for(const s of fr("user"))r.set(s.token,{principal:{class:"app",app:s.grantee,scopes:s.scopes},ceiling:s.scopes});return e!==void 0&&r.set(e,{principal:{class:"person"},ceiling:null}),r}i(Bt,"resolveBearers");function xt(e){try{return qe(e).act!==void 0}catch{return!1}}i(xt,"carriesAct");const Dt=/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/;function U(e,r){return e!==void 0&&(e.reason=r),"unauthorized"}i(U,"deny");async function Ne(e,r,s){const a=e.headers.authorization;if(a===void 0&&(e.method??"GET").toUpperCase()==="GET"&&(e.url??"").split("?")[0]==="/healthz")return{principal:te,ceiling:null};if(typeof a!="string"||!a.startsWith("Bearer "))return U(s,a===void 0?"no_authorization_header":"not_a_bearer");const u=a.slice(7);if(u.startsWith("crtr_pub_"))return{principal:te,ceiling:null};if(u.startsWith(ne))return Oe(u)??U(s,"app_token_unknown");if(u.startsWith(_t)){const S=await wt(u);return S===null?U(s,"run_token_invalid_or_settled"):{principal:S,ceiling:null}}const d=r.get(u);if(d!==void 0)return d;const g=$e(u);if(g!==null)return{principal:g,ceiling:null};if(u.startsWith(Me))return U(s,"import_token_invalid");if(Dt.test(u)){if(I()&&xt(u)){const x=K();if(x===null)return"person_bearer";try{const w=await x.verifyCall(a);return w.chain[0]?.sub.startsWith("app:")?{call:w}:U(s,"call_token_presenter_not_an_app")}catch(w){return w instanceof C&&w.status===503?"runtime_starting":U(s,`call_token_${w instanceof C?w.code:"invalid"}`)}}const S=I()?Re():null;if(S===null)return"person_bearer";const O=await S.verify(u);return O===null?U(s,"person_bearer_not_verified"):{principal:{class:"person",sub:O},ceiling:null}}const f=await ke(u,null);return f==="unauthorized"?U(s,"node_token_unknown"):typeof f=="string"?f:{principal:f,ceiling:null}}i(Ne,"authorizeTcp");let Y;function K(){if(Y!==void 0)return Y;const e=process.env.CRTR_DIRECTORY_URL||void 0,r=process.env.CRTR_PUBLIC_API_URL||void 0;return Y=e===void 0||r===void 0?null:new Ze(e,r,async()=>{}),Y}i(K,"cloudCallResolver");let Ie;function Ft(){const e=K();if(e===null)throw new C(503,"runtime_starting","app calls are not configured on this listener");return Ie??=Qe(e,async()=>!0,async()=>{}),Ie}i(Ft,"cloudAppCalls");async function Mt(e,r){H(r),z(r);const s=K();try{if(s===null)throw new C(503,"runtime_starting","sign-in is not configured on this listener");await er(e,r,new URL(e.url??"/","http://runtime.local"),s)}catch(a){if(!(a instanceof C))throw a;if(r.headersSent){r.destroy();return}r.writeHead(a.status,{"content-type":"application/json; charset=utf-8","cache-control":"no-store"}),r.end(JSON.stringify({error:{code:a.code,message:a.message,...a.param?{param:a.param}:{},origin:"runtime"}}))}}i(Mt,"serveRuntimeSignIn");function $t(){const e=process.env.CRTRD_TLS_CERT||void 0,r=process.env.CRTRD_TLS_KEY||void 0;if(e===void 0&&r===void 0)return null;if(e===void 0||r===void 0)throw new Error("CRTRD_TLS_CERT and CRTRD_TLS_KEY must be set together");return{cert:de(e),key:de(r)}}i($t,"tcpTls");function H(e){e.setHeader(Z,q()),e.setHeader(Q,ge)}i(H,"advertiseRuntime");function z(e){e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Expose-Headers",`${Z}, ${Q}`)}i(z,"exposeRuntimeHeaders");function Jt(e,r){return(e.method??"GET").toUpperCase()!=="OPTIONS"?!1:(H(r),r.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Expose-Headers":`${Z}, ${Q}`,"Access-Control-Allow-Headers":`authorization, content-type, ${fe.toLowerCase()}, ${he.toLowerCase()}`,"Access-Control-Allow-Methods":"GET, POST, PATCH, PUT, DELETE, OPTIONS","Access-Control-Max-Age":"600"}),r.end(),!0)}i(Jt,"answerPreflight");function oe(e,r=!1){H(e),r&&z(e),e.writeHead(401,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{...M,origin:"runtime"}}))}i(oe,"writeUnauthorized");function Wt(e){H(e),z(e),e.writeHead(401,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{...$,origin:"runtime"}}))}i(Wt,"writePersonBearerRefused");const jt={"/v1/runtime/vendor-status":{method:"GET",purpose:"vendor_status"},"/v1/runtime/vendor-account-remove":{method:"POST",purpose:"vendor_account_remove"}};async function Vt(e,r){if(!I())return!1;const s=new URL(e.url??"/","http://runtime.local").pathname,a=jt[s];if(a===void 0||e.method!==a.method)return!1;const u=i((d,g)=>{H(r),z(r),r.writeHead(d,{"content-type":"application/json; charset=utf-8"}),r.end(JSON.stringify(g))},"answer");try{const d=Re();if(d===null)throw new C(401,$.code,$.message);const g=e.headers.authorization,f=g?.startsWith("Bearer ")?await d.verifyPurpose(g.slice(7),a.purpose):null;if(f===null)throw new C(401,"unauthorized","invalid directory token");const S=a.purpose==="vendor_status"?void 0:await Gt(e);u(200,await G(f,async()=>a.purpose==="vendor_status"?ir():await or(S)))}catch(d){const{status:g,body:f}=sr(d);u(g,f)}return!0}i(Vt,"serveCloudVendorRoute");async function Gt(e){const r=[];let s=0;for await(const a of e){if(s+=a.length,s>ar)throw new C(400,"invalid_request","request body too large");r.push(a)}if(s!==0)try{return JSON.parse(Buffer.concat(r).toString("utf8"))}catch{throw new C(400,"invalid_request","invalid JSON body")}}i(Gt,"readVendorBody");function ie(e){H(e),e.writeHead(503,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{code:"runtime_starting",message:"runtime is not ready",type:"server_error",origin:"runtime",retryable:!0}}))}i(ie,"writeRuntimeStarting");function Yt(e,r){e.writeHead(503,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{code:"startup_blocked",message:r,origin:"runtime"}}))}i(Yt,"writeStartupBlocked");function He(e,r,s){return new Promise(a=>{for(const f of r)f.destroy();if(s===void 0){try{e.closeAllConnections()}catch{}e.close(()=>a());return}const u=[];e.close(()=>{for(const f of u)clearTimeout(f);a()});const d=setInterval(()=>e.closeIdleConnections(),250),g=setTimeout(()=>e.closeAllConnections(),s);u.push(d,g),e.closeIdleConnections()})}i(He,"closeServer");function Jo(e={}){let r=null;const s=It(()=>r),a=new ve().registerAll(we).registerAll(Se).registerAll(Ee).registerAll(be),u=i((t,n)=>{const c=Er()?.startupBlock()??null;return c===null||t==="GET"&&(n==="/healthz"||n==="/v1/status"||n==="/v1/ready")||t==="POST"&&(n==="/v1/daemon/migrate"||n==="/v1/daemon/admit")||c.phase==="recovering"&&a.match(t,n)!==null?null:c},"startupBlockFor"),d=e.socketPath??Ge(),g=new Set([process.getuid?.()??0,...Ae("user").runtime?.person_uids??[]]),f=i((t,n,c)=>{H(n);const p=i(m=>Array.isArray(m)?m[0]:m,"first"),N=p(t.headers[fe.toLowerCase()]),h=je(N,q())??Ve(p(t.headers[he.toLowerCase()]),ge,{legacyMinimum:N,runtimeVersion:q()});if(h!==null){n.writeHead(h.status,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:h.code,message:h.message,type:"invalid_request_error",origin:"runtime",retryable:!1,..."param"in h?{param:h.param}:{details:h.details}}}));return}const T=i(m=>{const E=J(t);A({event:"api.request.failed",level:"error",...E?.class==="broker"?{node_id:E.node}:{},error:m instanceof Error?m:new Error(String(m))});try{n.headersSent||n.writeHead(500,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:"internal",message:"internal error",origin:"runtime"}}))}catch{}},"internalFailure");let k;try{k=new URL(t.url??"/","http://127.0.0.1")}catch{try{n.writeHead(400,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:"invalid_request",message:"request URL is invalid",origin:"runtime"}}))}catch{}return}try{const m=u((t.method??"GET").toUpperCase(),k.pathname);if(m!==null){Yt(n,m.message);return}const E=J(t)??{class:"person"},o=Pe(E),l=i(()=>s.handle(t,n,c,E),"handled");(o===void 0?l():G(o,i(async()=>{ee()||await re(o),await l()},"handledAsPerson"))).catch(T)}catch(m){T(m)}},"onRequest"),S=i(async(t,n,c)=>{const p=J(t);return p===void 0||ye(p)||await _e(p,"either",c)?!0:(y(n,404,"Not Found","node_not_found",`no node ${c}`),!1)},"authorizeAttachUpgrade"),O=new Set,x=i(t=>{O.add(t),t.once("close",()=>O.delete(t)),t.on("error",()=>{})},"trackUpgrade"),w=i((t,n,c)=>{try{const p=new URL(t.url??"/","http://127.0.0.1"),N=u((t.method??"GET").toUpperCase(),p.pathname);if(N!==null){y(n,503,"Service Unavailable","startup_blocked",N.message);return}const h=Ht(t.method??"GET",p.pathname);if(h===null){n.destroy();return}const T=(()=>{const m=J(t);return m===void 0?void 0:Pe(m)})(),k=i(()=>S(t,n,h).then(m=>m?Rr(t,n,c,h,async E=>{const o=J(t);return o===void 0||ye(o)||await _e(o,E,h)}):void 0),"attach");(T===void 0?k():G(T,async()=>{ee()||await re(T),await k()})).catch(()=>{try{n.destroy()}catch{}})}catch{try{n.destroy()}catch{}}},"onUpgrade"),ze=i(t=>{t.on("error",n=>{A({event:"api.server.failed",level:"error",error:n})})},"bindErrorHandler"),Le=i(async(t,n)=>{V(t);try{const c=await Ce(t,g);if(j(t),c==="unauthorized"){A({event:"api.principal.denied",level:"warn",fields:{method:t.method}}),oe(n);return}if(c==="runtime_starting"){ie(n);return}B.set(t,c),Ue(t,c),f(t,n,c.class==="app"?c.scopes:null)}catch(c){A({event:"api.principal.failed",level:"error",error:c instanceof Error?c:new Error(String(c))}),ie(n)}},"onSocketRequest"),D=pe((t,n)=>{Le(t,n).catch(c=>A({event:"api.principal.failed",level:"error",error:c instanceof Error?c:new Error(String(c))}))}),Be=i(async(t,n,c)=>{V(t);try{const p=await Ce(t,g);if(j(t),p==="unauthorized"||p==="runtime_starting"){p==="unauthorized"&&A({event:"api.principal.denied",level:"warn",fields:{method:t.method}}),y(n,p==="unauthorized"?401:503,"Unauthorized",p,"socket principal unavailable");return}if(p.class!=="person"&&p.class!=="broker"){y(n,403,"Forbidden",L.code,L.message);return}B.set(t,p),w(t,n,c)}catch(p){A({event:"api.principal.failed",level:"error",error:p instanceof Error?p:new Error(String(p))}),y(n,503,"Service Unavailable","runtime_starting","socket principal unavailable")}},"onSocketUpgrade");D.on("upgrade",(t,n,c)=>{x(n),Be(t,n,c).catch(p=>A({event:"api.principal.failed",level:"error",error:p instanceof Error?p:new Error(String(p))}))}),Te((t,n,c)=>{B.set(t,c),f(t,n,null)});let se=!1,ae,le;const xe=new Promise((t,n)=>{ae=t,le=n});D.once("listening",()=>{se=!0,ae()}),D.on("error",t=>{A({event:"api.server.failed",level:"error",error:t}),se||le(t)});try{X(d)&&me(d)}catch{}D.listen(d,()=>{try{We(d,process.platform==="linux"&&X("/run/crtr/launcher.sock")?438:384)}catch(t){A({event:"api.socket.chmod_failed",level:"error",error:t instanceof Error?t:new Error(String(t))})}});let b,ce=Promise.resolve();const W=e.tcp??gr()??Ae("user").api.tcp;if(W!==void 0&&W!==""){const t=zt(W);if(t===null)A({event:"api.tcp.invalid",level:"error",error:new Error(`invalid CRTRD_TCP/--tcp spec: ${W}`)});else{I()&&K();const n=I()?tr():null,c=e.token??hr()??mr("user"),p=Bt(c),N=i(async(o,l)=>{if(V(o),Ke(o)){await Xe(o,l);return}if(Jt(o,l))return;if(I()&&rr(new URL(o.url??"/","http://runtime.local").pathname)){await Mt(o,l);return}if(await Vt(o,l))return;if(n!==null&&nr(new URL(o.url??"/","http://runtime.local").pathname)){await n(o,l);return}const v={},R=await Ne(o,p,v);if(j(o),R==="runtime_starting"){z(l),ie(l);return}if(R==="person_bearer"){Wt(l);return}if(R==="unauthorized"){A({event:"api.principal.denied",level:"warn",fields:{method:o.method,listener:"tcp",path:new URL(o.url??"/","http://runtime.local").pathname,reason:v.reason??"unknown"}}),oe(l,!0);return}if("call"in R){z(l);const F=R.call.sub;await G(F,async()=>{ee()||await re(F),await Ft()(o,l,R.call)});return}B.set(o,R.principal),Ue(o,R.principal),z(l),f(o,l,R.ceiling)},"tcpOnRequest"),h=i(async(o,l,v)=>{V(o);const R=vr(o);if(R!==null){const _=await Ar(o,l,v,R);_!==null&&y(l,_.status,_.text,_.code,_.message);return}const F=wr(o);if(F!==null){const _=_r(o,l,v,F);_!==null&&y(l,_.status,_.text,_.code,_.message);return}const P=await Ne(o,p);if(j(o),P==="runtime_starting"){y(l,503,"Service Unavailable","runtime_starting","grant sync is not ready");return}if(P==="person_bearer"){y(l,401,"Unauthorized",$.code,$.message);return}if(P==="unauthorized"){y(l,401,"Unauthorized",M.code,M.message);return}if("call"in P){y(l,403,"Forbidden",L.code,L.message);return}if(P.ceiling!==null||P.principal.class==="anonymous"||P.principal.class==="import"){y(l,403,"Forbidden",L.code,L.message);return}B.set(o,P.principal),w(o,l,v)},"tcpOnUpgrade"),T=i(o=>{A({event:"api.principal.failed",level:"error",error:o instanceof Error?o:new Error(String(o))})},"failed"),k=i((o,l)=>{N(o,l).catch(v=>{T(v),l.headersSent?l.destroy():oe(l,!0)})},"listener"),m=$t();b=m===null?pe(k):Je(m,k),b.on("upgrade",(o,l,v)=>{x(l),h(o,l,v).catch(R=>{T(R),y(l,401,"Unauthorized",M.code,M.message)})}),ze(b),b.once("listening",()=>{const o=b?.address();if(o!==null&&typeof o=="object"){const{address:l,port:v}=o;r=Lt(l,v),l!=="0.0.0.0"&&l!=="::"&&yr(r)}});const E=b;ce=new Promise(o=>{E.once("listening",o),E.once("error",()=>o())}),b.listen(t.port,t.host)}}let ue=!1;const De=i(async(t={})=>{if(!ue){ue=!0,Te(null),Or.close(),await Promise.all([He(D,O,t.graceMs),b!==void 0?He(b,O,t.graceMs):Promise.resolve()]);try{X(d)&&me(d)}catch{}}},"close");return{ready:xe.then(()=>ce),tcpAddress:i(()=>r,"tcpAddress"),close:De}}i(Jo,"createApiServer");export{It as buildRouter,He as closeServer,Jo as createApiServer,J as socketPrincipal};