@capybara-hq/kernel 0.1.0-rc.13 → 0.1.0-rc.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.json +55 -28
- package/dist/admin/account-erasures.d.ts +37 -0
- package/dist/admin/account-erasures.js +119 -0
- package/dist/admin/admin-agents.controller.d.ts +28 -0
- package/dist/admin/admin-agents.controller.js +79 -0
- package/dist/admin/admin-connectors.controller.d.ts +29 -0
- package/dist/admin/admin-connectors.controller.js +79 -0
- package/dist/admin/admin-items.schemas.d.ts +42 -0
- package/dist/admin/admin-items.schemas.js +48 -0
- package/dist/admin/admin.controller.d.ts +58 -29
- package/dist/admin/admin.controller.js +110 -46
- package/dist/admin/admin.module.d.ts +6 -1
- package/dist/admin/admin.module.js +84 -4
- package/dist/admin/admin.schemas.d.ts +122 -13
- package/dist/admin/admin.schemas.js +26 -2
- package/dist/admin/audit-log.service.d.ts +52 -0
- package/dist/admin/audit-log.service.js +81 -0
- package/dist/admin/audit.controller.d.ts +26 -0
- package/dist/admin/audit.controller.js +72 -0
- package/dist/admin/audit.schemas.d.ts +16 -0
- package/dist/admin/audit.schemas.js +37 -0
- package/dist/admin/erasure-dispositions.d.ts +23 -0
- package/dist/admin/erasure-dispositions.js +76 -0
- package/dist/admin/extensions.controller.d.ts +34 -11
- package/dist/admin/extensions.controller.js +74 -27
- package/dist/admin/extensions.schemas.d.ts +21 -0
- package/dist/admin/extensions.schemas.js +39 -0
- package/dist/admin/health.service.d.ts +117 -0
- package/dist/admin/health.service.js +312 -0
- package/dist/admin/login-sources.controller.d.ts +30 -0
- package/dist/admin/login-sources.controller.js +77 -0
- package/dist/admin/login-sources.schemas.d.ts +25 -0
- package/dist/admin/login-sources.schemas.js +49 -0
- package/dist/admin/org-network.controller.d.ts +30 -0
- package/dist/admin/org-network.controller.js +77 -0
- package/dist/admin/org-network.schemas.d.ts +16 -0
- package/dist/admin/org-network.schemas.js +27 -0
- package/dist/admin/org-network.service.d.ts +43 -0
- package/dist/admin/org-network.service.js +109 -0
- package/dist/admin/outbox-dead.controller.d.ts +21 -0
- package/dist/admin/outbox-dead.controller.js +65 -0
- package/dist/admin/outbox-dead.schemas.d.ts +24 -0
- package/dist/admin/outbox-dead.schemas.js +42 -0
- package/dist/admin/outbox-dead.service.d.ts +81 -0
- package/dist/admin/outbox-dead.service.js +264 -0
- package/dist/admin/overview.controller.d.ts +31 -0
- package/dist/admin/overview.controller.js +78 -0
- package/dist/admin/overview.schemas.d.ts +8 -0
- package/dist/admin/overview.schemas.js +13 -0
- package/dist/admin/overview.service.d.ts +147 -0
- package/dist/admin/overview.service.js +256 -0
- package/dist/admin/usage.service.d.ts +139 -0
- package/dist/admin/usage.service.js +337 -0
- package/dist/agents/admin-agents.d.ts +106 -0
- package/dist/agents/admin-agents.js +234 -0
- package/dist/agents/agent-lookup.d.ts +5 -2
- package/dist/agents/agent-lookup.js +11 -11
- package/dist/agents/agent-profile.service.d.ts +5 -2
- package/dist/agents/agent-profile.service.js +16 -2
- package/dist/agents/agents.controller.d.ts +18 -14
- package/dist/agents/agents.controller.js +33 -19
- package/dist/agents/agents.module.d.ts +4 -3
- package/dist/agents/agents.module.js +20 -3
- package/dist/agents/agents.schemas.d.ts +79 -21
- package/dist/agents/agents.schemas.js +21 -1
- package/dist/agents/agents.service.d.ts +74 -9
- package/dist/agents/agents.service.js +230 -71
- package/dist/agents/avatar-view.d.ts +8 -0
- package/dist/agents/avatar-view.js +12 -0
- package/dist/agents/definition.d.ts +53 -37
- package/dist/agents/definition.js +96 -231
- package/dist/agents/from-template.d.ts +6 -3
- package/dist/agents/from-template.js +58 -45
- package/dist/agents/instruction-files.js +0 -3
- package/dist/agents/models.controller.d.ts +2 -2
- package/dist/agents/onboarding-checklist.d.ts +31 -0
- package/dist/agents/onboarding-checklist.js +189 -0
- package/dist/agents/org-templates.js +96 -39
- package/dist/agents/pending-connector-requests.js +6 -0
- package/dist/agents/pending-connectors.service.js +2 -0
- package/dist/agents/profile.d.ts +38 -13
- package/dist/agents/profile.js +31 -20
- package/dist/agents/readiness.controller.d.ts +10 -19
- package/dist/agents/readiness.controller.js +24 -27
- package/dist/agents/readiness.service.d.ts +90 -0
- package/dist/agents/readiness.service.js +132 -0
- package/dist/agents/templates.js +9 -20
- package/dist/app.d.ts +6 -0
- package/dist/app.js +4 -0
- package/dist/attribution/platform-attribution.d.ts +113 -0
- package/dist/attribution/platform-attribution.js +166 -0
- package/dist/automations/acceptance.controller.d.ts +29 -0
- package/dist/automations/acceptance.controller.js +87 -0
- package/dist/automations/automations.controller.d.ts +77 -0
- package/dist/automations/automations.controller.js +267 -0
- package/dist/automations/automations.module.d.ts +16 -0
- package/dist/automations/automations.module.js +69 -0
- package/dist/automations/automations.schemas.d.ts +498 -0
- package/dist/automations/automations.schemas.js +284 -0
- package/dist/automations/automations.service.d.ts +406 -0
- package/dist/automations/automations.service.js +1407 -0
- package/dist/automations/calendar.d.ts +134 -0
- package/dist/automations/calendar.js +410 -0
- package/dist/automations/effective-settings.d.ts +22 -0
- package/dist/automations/effective-settings.js +23 -0
- package/dist/automations/errors.d.ts +24 -0
- package/dist/automations/errors.js +24 -0
- package/dist/automations/events/acceptance.d.ts +212 -0
- package/dist/automations/events/acceptance.js +839 -0
- package/dist/automations/events/coalesce.d.ts +28 -0
- package/dist/automations/events/coalesce.js +131 -0
- package/dist/automations/events/deadline.d.ts +10 -0
- package/dist/automations/events/deadline.js +24 -0
- package/dist/automations/events/deliver.d.ts +39 -0
- package/dist/automations/events/deliver.js +112 -0
- package/dist/automations/events/dispatcher.d.ts +90 -0
- package/dist/automations/events/dispatcher.js +352 -0
- package/dist/automations/events/events.module.d.ts +7 -0
- package/dist/automations/events/events.module.js +26 -0
- package/dist/automations/events/guards.d.ts +32 -0
- package/dist/automations/events/guards.js +87 -0
- package/dist/automations/events/sweep.job.d.ts +102 -0
- package/dist/automations/events/sweep.job.js +347 -0
- package/dist/automations/events/token.d.ts +5 -0
- package/dist/automations/events/token.js +5 -0
- package/dist/automations/events/trigger-events.service.d.ts +76 -0
- package/dist/automations/events/trigger-events.service.js +337 -0
- package/dist/automations/fire.d.ts +189 -0
- package/dist/automations/fire.js +966 -0
- package/dist/automations/grant-rules.d.ts +103 -0
- package/dist/automations/grant-rules.js +159 -0
- package/dist/automations/job-ids.d.ts +113 -0
- package/dist/automations/job-ids.js +117 -0
- package/dist/automations/pause.d.ts +9 -0
- package/dist/automations/pause.js +35 -0
- package/dist/automations/run-tracker.d.ts +95 -0
- package/dist/automations/run-tracker.js +362 -0
- package/dist/automations/scan.job.d.ts +49 -0
- package/dist/automations/scan.job.js +211 -0
- package/dist/automations/schedule-math.d.ts +80 -0
- package/dist/automations/schedule-math.js +304 -0
- package/dist/automations/store.d.ts +120 -0
- package/dist/automations/store.js +477 -0
- package/dist/automations/store.module.d.ts +6 -0
- package/dist/automations/store.module.js +21 -0
- package/dist/automations/types.d.ts +183 -0
- package/dist/automations/types.js +1 -0
- package/dist/automations/unattended.d.ts +99 -0
- package/dist/automations/unattended.js +223 -0
- package/dist/background/finish.d.ts +21 -4
- package/dist/background/finish.js +88 -9
- package/dist/background/launch.d.ts +30 -23
- package/dist/background/launch.js +57 -46
- package/dist/background/managed-output.d.ts +110 -0
- package/dist/background/managed-output.js +219 -0
- package/dist/background/managed.d.ts +56 -0
- package/dist/background/managed.js +128 -0
- package/dist/background/poll.job.d.ts +29 -11
- package/dist/background/poll.job.js +141 -71
- package/dist/background/render.d.ts +3 -0
- package/dist/background/render.js +6 -0
- package/dist/background/session.d.ts +3 -44
- package/dist/background/session.js +3 -76
- package/dist/background/stop.d.ts +88 -27
- package/dist/background/stop.js +224 -112
- package/dist/background/store.d.ts +148 -71
- package/dist/background/store.js +348 -154
- package/dist/background/tasks.service.d.ts +56 -5
- package/dist/background/tasks.service.js +125 -67
- package/dist/background/wake-rules.d.ts +5 -0
- package/dist/background/wake-rules.js +22 -6
- package/dist/background/wake.js +3 -2
- package/dist/catalog/admin-catalog.controller.d.ts +71 -30
- package/dist/catalog/admin-catalog.controller.js +134 -43
- package/dist/catalog/admin-catalog.schemas.d.ts +17 -0
- package/dist/catalog/admin-catalog.schemas.js +21 -0
- package/dist/catalog/appearance.schemas.d.ts +10 -0
- package/dist/catalog/appearance.schemas.js +20 -0
- package/dist/catalog/appearance.service.d.ts +105 -0
- package/dist/catalog/appearance.service.js +304 -0
- package/dist/catalog/catalog-content.d.ts +62 -23
- package/dist/catalog/catalog-content.js +23 -70
- package/dist/catalog/catalog-files.d.ts +3 -2
- package/dist/catalog/catalog-files.js +8 -5
- package/dist/catalog/catalog-import.module.d.ts +1 -1
- package/dist/catalog/catalog-import.module.js +4 -5
- package/dist/catalog/catalog-items.d.ts +20 -10
- package/dist/catalog/catalog-items.js +41 -36
- package/dist/catalog/catalog-scope.service.d.ts +20 -113
- package/dist/catalog/catalog-scope.service.js +51 -521
- package/dist/catalog/catalog.module.d.ts +5 -5
- package/dist/catalog/catalog.module.js +31 -13
- package/dist/catalog/catalog.service.d.ts +31 -12
- package/dist/catalog/catalog.service.js +71 -32
- package/dist/catalog/claude/report.d.ts +9 -2
- package/dist/catalog/claude/report.js +1 -0
- package/dist/catalog/claude/translate.js +2 -2
- package/dist/catalog/cli.d.ts +7 -10
- package/dist/catalog/cli.js +13 -29
- package/dist/catalog/component-promotion.js +3 -2
- package/dist/catalog/component-scope.controller.d.ts +9 -15
- package/dist/catalog/component-scope.controller.js +14 -9
- package/dist/catalog/component-scope.schemas.js +2 -0
- package/dist/catalog/component-scope.service.d.ts +23 -1
- package/dist/catalog/component-scope.service.js +36 -4
- package/dist/catalog/component-state.d.ts +38 -1
- package/dist/catalog/component-state.js +59 -8
- package/dist/catalog/credential-key.d.ts +10 -0
- package/dist/catalog/credential-key.js +28 -0
- package/dist/catalog/git-source.d.ts +21 -0
- package/dist/catalog/git-source.js +57 -11
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +26 -31
- package/dist/catalog/job-ids.js +26 -26
- package/dist/catalog/jobs.d.ts +12 -3
- package/dist/catalog/jobs.js +28 -7
- package/dist/catalog/marketplace-fetch.d.ts +15 -3
- package/dist/catalog/marketplace-fetch.js +14 -7
- package/dist/catalog/marketplaces.controller.d.ts +3 -2
- package/dist/catalog/marketplaces.controller.js +5 -2
- package/dist/catalog/marketplaces.schemas.d.ts +7 -0
- package/dist/catalog/marketplaces.schemas.js +13 -0
- package/dist/catalog/marketplaces.service.d.ts +70 -11
- package/dist/catalog/marketplaces.service.js +218 -33
- package/dist/catalog/org-catalog.controller.d.ts +29 -42
- package/dist/catalog/org-catalog.controller.js +52 -51
- package/dist/catalog/org-catalog.schemas.d.ts +60 -20
- package/dist/catalog/org-catalog.schemas.js +88 -8
- package/dist/catalog/org-catalog.service.d.ts +11 -1
- package/dist/catalog/org-catalog.service.js +109 -62
- package/dist/catalog/org-extension.controller.d.ts +34 -57
- package/dist/catalog/org-extension.controller.js +64 -106
- package/dist/catalog/org-extension.schemas.d.ts +29 -8
- package/dist/catalog/org-extension.schemas.js +56 -11
- package/dist/catalog/org-plugin-uploads.controller.d.ts +4 -19
- package/dist/catalog/org-plugin-uploads.controller.js +6 -35
- package/dist/catalog/org-plugin-uploads.d.ts +9 -19
- package/dist/catalog/org-plugin-uploads.js +13 -33
- package/dist/catalog/org-plugin-uploads.schemas.d.ts +0 -1
- package/dist/catalog/org-plugin-uploads.schemas.js +2 -3
- package/dist/catalog/owned-items.d.ts +9 -21
- package/dist/catalog/owned-items.js +27 -48
- package/dist/catalog/ownership.d.ts +3 -29
- package/dist/catalog/ownership.js +6 -54
- package/dist/catalog/platform-components.d.ts +50 -35
- package/dist/catalog/platform-components.js +80 -89
- package/dist/catalog/platform-import-update.d.ts +50 -0
- package/dist/catalog/platform-import-update.js +116 -0
- package/dist/catalog/plugin-connectors.d.ts +35 -0
- package/dist/catalog/plugin-connectors.js +81 -0
- package/dist/catalog/plugin-import.d.ts +112 -71
- package/dist/catalog/plugin-import.js +260 -312
- package/dist/catalog/plugin-install.d.ts +129 -135
- package/dist/catalog/plugin-install.js +337 -413
- package/dist/catalog/plugin-package.d.ts +19 -13
- package/dist/catalog/plugin-package.js +101 -35
- package/dist/catalog/plugin-upgrade.d.ts +115 -45
- package/dist/catalog/plugin-upgrade.js +304 -213
- package/dist/catalog/request-rules.js +10 -6
- package/dist/catalog/requests.service.d.ts +72 -10
- package/dist/catalog/requests.service.js +237 -16
- package/dist/catalog/reserved-names.js +3 -9
- package/dist/catalog/schema-path.d.ts +4 -6
- package/dist/catalog/schema-path.js +48 -21
- package/dist/catalog/scope-jobs.d.ts +59 -0
- package/dist/catalog/scope-jobs.js +78 -0
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +2 -2
- package/dist/catalog/scope-sync-workers.d.ts +23 -0
- package/dist/catalog/scope-sync-workers.js +73 -2
- package/dist/catalog/scope-sync.d.ts +89 -111
- package/dist/catalog/scope-sync.js +189 -255
- package/dist/catalog/scope.d.ts +2 -5
- package/dist/catalog/template-connector-ensure.d.ts +97 -0
- package/dist/catalog/template-connector-ensure.js +281 -0
- package/dist/catalog/template-connector-jobs.d.ts +28 -0
- package/dist/catalog/template-connector-jobs.js +54 -0
- package/dist/catalog/template-connectors.processor.d.ts +32 -0
- package/dist/catalog/template-connectors.processor.js +101 -0
- package/dist/catalog/template-description.d.ts +17 -0
- package/dist/catalog/template-description.js +18 -0
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +8 -8
- package/dist/channels/actions.d.ts +2 -0
- package/dist/channels/actions.js +44 -5
- package/dist/channels/cards.d.ts +65 -3
- package/dist/channels/cards.js +224 -12
- package/dist/channels/channels.module.d.ts +13 -9
- package/dist/channels/channels.module.js +35 -11
- package/dist/channels/channels.schemas.d.ts +17 -0
- package/dist/channels/channels.schemas.js +17 -0
- package/dist/channels/connections.controller.d.ts +6 -4
- package/dist/channels/connections.controller.js +7 -5
- package/dist/channels/connections.service.d.ts +93 -15
- package/dist/channels/connections.service.js +193 -28
- package/dist/channels/deliver-job.d.ts +32 -0
- package/dist/channels/deliver-job.js +29 -0
- package/dist/channels/features.d.ts +20 -1
- package/dist/channels/features.js +31 -5
- package/dist/channels/file-delivery.d.ts +91 -0
- package/dist/channels/file-delivery.js +197 -0
- package/dist/channels/inbound.d.ts +15 -31
- package/dist/channels/inbound.js +65 -26
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/jobs.d.ts +39 -22
- package/dist/channels/jobs.js +83 -29
- package/dist/channels/outbound.d.ts +57 -5
- package/dist/channels/outbound.js +907 -40
- package/dist/channels/phrases.d.ts +252 -11
- package/dist/channels/phrases.js +204 -12
- package/dist/channels/progress.d.ts +75 -0
- package/dist/channels/progress.js +216 -0
- package/dist/channels/supervisor.d.ts +9 -4
- package/dist/channels/supervisor.js +61 -27
- package/dist/channels/threads.d.ts +16 -3
- package/dist/channels/threads.js +39 -3
- package/dist/channels/webhook.d.ts +22 -1
- package/dist/channels/webhook.js +49 -9
- package/dist/client/client-access.service.d.ts +102 -0
- package/dist/client/client-access.service.js +303 -0
- package/dist/client/client-builds.service.d.ts +109 -0
- package/dist/client/client-builds.service.js +229 -0
- package/dist/client/client-delivery.controller.d.ts +25 -0
- package/dist/client/client-delivery.controller.js +66 -0
- package/dist/client/client-files.d.ts +48 -0
- package/dist/client/client-files.js +136 -0
- package/dist/client/client-reports.cron.d.ts +13 -0
- package/dist/client/client-reports.cron.js +42 -0
- package/dist/client/client-reports.service.d.ts +30 -0
- package/dist/client/client-reports.service.js +118 -0
- package/dist/client/client-sign-in.service.d.ts +21 -0
- package/dist/client/client-sign-in.service.js +49 -0
- package/dist/client/client.controller.d.ts +49 -0
- package/dist/client/client.controller.js +129 -0
- package/dist/client/client.module.d.ts +8 -0
- package/dist/client/client.module.js +28 -0
- package/dist/client/client.schemas.d.ts +61 -0
- package/dist/client/client.schemas.js +27 -0
- package/dist/config/docs.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/fields.js +20 -4
- package/dist/config/load.d.ts +7 -2
- package/dist/config/load.js +48 -4
- package/dist/config/product-name.d.ts +8 -0
- package/dist/config/product-name.js +9 -0
- package/dist/config/schema.d.ts +175 -56
- package/dist/config/schema.js +855 -132
- package/dist/conversations/access.d.ts +14 -5
- package/dist/conversations/access.js +30 -20
- package/dist/conversations/agent-tree.d.ts +16 -0
- package/dist/conversations/agent-tree.js +36 -0
- package/dist/conversations/approval-profile.d.ts +37 -0
- package/dist/conversations/approval-profile.js +82 -0
- package/dist/conversations/artifacts.d.ts +20 -17
- package/dist/conversations/artifacts.js +30 -37
- package/dist/conversations/attachments.controller.d.ts +12 -17
- package/dist/conversations/attachments.controller.js +19 -57
- package/dist/conversations/attachments.service.d.ts +174 -59
- package/dist/conversations/attachments.service.js +564 -260
- package/dist/conversations/conversation-ref.d.ts +58 -0
- package/dist/conversations/conversation-ref.js +103 -0
- package/dist/conversations/conversations.controller.d.ts +95 -57
- package/dist/conversations/conversations.controller.js +175 -82
- package/dist/conversations/conversations.module.js +20 -0
- package/dist/conversations/conversations.schemas.d.ts +21 -0
- package/dist/conversations/conversations.schemas.js +26 -0
- package/dist/conversations/conversations.service.d.ts +471 -83
- package/dist/conversations/conversations.service.js +1223 -170
- package/dist/conversations/delivery-scope.d.ts +34 -0
- package/dist/conversations/delivery-scope.js +23 -0
- package/dist/conversations/event-log.d.ts +96 -17
- package/dist/conversations/event-log.js +278 -34
- package/dist/conversations/event-org-backfill.d.ts +111 -0
- package/dist/conversations/event-org-backfill.js +264 -0
- package/dist/conversations/event-org-backfill.module.d.ts +3 -0
- package/dist/conversations/event-org-backfill.module.js +18 -0
- package/dist/conversations/event-people.d.ts +12 -0
- package/dist/conversations/event-people.js +28 -0
- package/dist/conversations/events.d.ts +1177 -60
- package/dist/conversations/events.js +1290 -116
- package/dist/conversations/files.d.ts +98 -26
- package/dist/conversations/files.js +225 -87
- package/dist/conversations/inline-tokens.d.ts +87 -0
- package/dist/conversations/inline-tokens.js +154 -0
- package/dist/conversations/job-org.d.ts +5 -0
- package/dist/conversations/job-org.js +23 -0
- package/dist/conversations/leak-check.d.ts +26 -0
- package/dist/conversations/leak-check.js +70 -0
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/message-context.d.ts +6 -3
- package/dist/conversations/message-context.js +14 -10
- package/dist/conversations/model-image.d.ts +39 -0
- package/dist/conversations/model-image.js +80 -0
- package/dist/conversations/permission-profile-store.d.ts +51 -0
- package/dist/conversations/permission-profile-store.js +67 -0
- package/dist/conversations/permission-profile-store.module.d.ts +2 -0
- package/dist/conversations/permission-profile-store.module.js +19 -0
- package/dist/conversations/permission-profiles.controller.d.ts +114 -0
- package/dist/conversations/permission-profiles.controller.js +106 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +36 -0
- package/dist/conversations/permission-profiles.schemas.js +31 -0
- package/dist/conversations/permission-profiles.service.d.ts +76 -0
- package/dist/conversations/permission-profiles.service.js +203 -0
- package/dist/conversations/prompt-suggestion-request.d.ts +95 -0
- package/dist/conversations/prompt-suggestion-request.js +215 -0
- package/dist/conversations/prompt-suggestion-store.d.ts +53 -0
- package/dist/conversations/prompt-suggestion-store.js +141 -0
- package/dist/conversations/prompt-suggestions.d.ts +148 -0
- package/dist/conversations/prompt-suggestions.js +571 -0
- package/dist/conversations/queue.d.ts +21 -5
- package/dist/conversations/queue.js +35 -3
- package/dist/conversations/queue.service.d.ts +20 -9
- package/dist/conversations/queue.service.js +117 -41
- package/dist/conversations/selection.js +1 -0
- package/dist/conversations/source.d.ts +10 -0
- package/dist/conversations/source.js +19 -0
- package/dist/conversations/titles.d.ts +24 -12
- package/dist/conversations/titles.js +87 -53
- package/dist/conversations/tree.d.ts +10 -0
- package/dist/conversations/tree.js +41 -0
- package/dist/ctx/bus.js +5 -3
- package/dist/ctx/create-ctx.d.ts +150 -18
- package/dist/ctx/create-ctx.js +490 -55
- package/dist/ctx/device-provider-check.d.ts +11 -0
- package/dist/ctx/device-provider-check.js +36 -0
- package/dist/ctx/net.d.ts +50 -0
- package/dist/ctx/net.js +67 -0
- package/dist/ctx/queue.js +4 -2
- package/dist/ctx/secrets.d.ts +41 -5
- package/dist/ctx/secrets.js +140 -30
- package/dist/db/kernel-schema.d.ts +1082 -107
- package/dist/db/migrator.d.ts +6 -0
- package/dist/db/migrator.js +58 -6
- package/dist/db/pool.d.ts +6 -0
- package/dist/db/pool.js +8 -2
- package/dist/device-access/conversation-notice-delivery.d.ts +116 -0
- package/dist/device-access/conversation-notice-delivery.js +344 -0
- package/dist/device-access/conversation-notices.d.ts +27 -0
- package/dist/device-access/conversation-notices.js +42 -0
- package/dist/device-access/device-access.module.d.ts +7 -0
- package/dist/device-access/device-access.module.js +43 -0
- package/dist/device-access/device-access.service.d.ts +276 -0
- package/dist/device-access/device-access.service.js +985 -0
- package/dist/device-access/site-access-request.d.ts +14 -0
- package/dist/device-access/site-access-request.js +35 -0
- package/dist/device-access/site-grants.d.ts +53 -0
- package/dist/device-access/site-grants.js +268 -0
- package/dist/device-access/site-grants.module.d.ts +2 -0
- package/dist/device-access/site-grants.module.js +14 -0
- package/dist/device-access/token.d.ts +6 -0
- package/dist/device-access/token.js +6 -0
- package/dist/device-access/viewer-routes.d.ts +45 -0
- package/dist/device-access/viewer-routes.js +81 -0
- package/dist/device-access/viewer.d.ts +249 -0
- package/dist/device-access/viewer.js +867 -0
- package/dist/devices/access.d.ts +15 -46
- package/dist/devices/access.js +26 -63
- package/dist/devices/access.module.d.ts +2 -0
- package/dist/devices/access.module.js +19 -0
- package/dist/devices/conversation-devices.d.ts +102 -19
- package/dist/devices/conversation-devices.js +178 -56
- package/dist/devices/default-provider-setting.d.ts +45 -0
- package/dist/devices/default-provider-setting.js +59 -0
- package/dist/devices/device-project-files.service.d.ts +88 -0
- package/dist/devices/device-project-files.service.js +249 -0
- package/dist/devices/device-projects.service.d.ts +188 -0
- package/dist/devices/device-projects.service.js +474 -0
- package/dist/devices/device-provider-selection.d.ts +36 -0
- package/dist/devices/device-provider-selection.js +85 -0
- package/dist/devices/device-provider-selection.module.d.ts +3 -0
- package/dist/devices/device-provider-selection.module.js +22 -0
- package/dist/devices/devices.controller.d.ts +36 -11
- package/dist/devices/devices.controller.js +101 -21
- package/dist/devices/devices.module.js +36 -6
- package/dist/devices/devices.schemas.d.ts +5 -1
- package/dist/devices/devices.schemas.js +21 -4
- package/dist/devices/devices.service.d.ts +372 -118
- package/dist/devices/devices.service.js +843 -322
- package/dist/devices/dto.d.ts +97 -3
- package/dist/devices/dto.js +102 -2
- package/dist/devices/errors.d.ts +14 -0
- package/dist/devices/errors.js +14 -0
- package/dist/devices/label.d.ts +3 -5
- package/dist/devices/label.js +3 -14
- package/dist/devices/project-paths.d.ts +29 -0
- package/dist/devices/project-paths.js +66 -0
- package/dist/devices/project-rules.d.ts +34 -0
- package/dist/devices/project-rules.js +20 -0
- package/dist/devices/public-suffix.d.ts +6 -0
- package/dist/devices/public-suffix.js +79 -0
- package/dist/devices/working-root.d.ts +43 -0
- package/dist/devices/working-root.js +56 -0
- package/dist/dial-in/access.d.ts +45 -0
- package/dist/dial-in/access.js +90 -0
- package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +13 -7
- package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +33 -17
- package/dist/dial-in/auth.module.d.ts +7 -0
- package/dist/dial-in/auth.module.js +27 -0
- package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +52 -13
- package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +108 -33
- package/dist/dial-in/dial-in.module.d.ts +9 -0
- package/dist/dial-in/dial-in.module.js +37 -0
- package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
- package/dist/{local-devices → dial-in}/dto.js +14 -2
- package/dist/dial-in/envelope.d.ts +95 -0
- package/dist/dial-in/envelope.js +89 -0
- package/dist/dial-in/gateway.d.ts +272 -0
- package/dist/dial-in/gateway.js +1061 -0
- package/dist/dial-in/handlers.d.ts +56 -0
- package/dist/dial-in/handlers.js +100 -0
- package/dist/{local-devices → dial-in}/keys.d.ts +12 -0
- package/dist/{local-devices → dial-in}/keys.js +12 -0
- package/dist/{local-devices → dial-in}/machines.d.ts +55 -29
- package/dist/{local-devices → dial-in}/machines.js +86 -115
- package/dist/dial-in/relay.d.ts +167 -0
- package/dist/dial-in/relay.js +517 -0
- package/dist/dial-in/relay.module.d.ts +7 -0
- package/dist/dial-in/relay.module.js +24 -0
- package/dist/dial-in/routes.d.ts +56 -0
- package/dist/dial-in/routes.js +133 -0
- package/dist/dial-in/streams.d.ts +66 -0
- package/dist/dial-in/streams.js +296 -0
- package/dist/dial-in/targets.d.ts +45 -0
- package/dist/dial-in/targets.js +91 -0
- package/dist/erasure/account-batches.d.ts +9 -0
- package/dist/erasure/account-batches.js +567 -0
- package/dist/erasure/account-files.d.ts +34 -0
- package/dist/erasure/account-files.js +217 -0
- package/dist/erasure/account-residual.d.ts +15 -0
- package/dist/erasure/account-residual.js +149 -0
- package/dist/erasure/account-worker.d.ts +32 -0
- package/dist/erasure/account-worker.js +392 -0
- package/dist/erasure/device-cleanup.d.ts +23 -0
- package/dist/erasure/device-cleanup.js +221 -0
- package/dist/erasure/erasure.module.d.ts +2 -0
- package/dist/erasure/erasure.module.js +14 -0
- package/dist/erasure/external-evidence.d.ts +4 -0
- package/dist/erasure/external-evidence.js +28 -0
- package/dist/erasure/jobs.d.ts +5 -0
- package/dist/erasure/jobs.js +20 -0
- package/dist/erasure/org-batches.d.ts +11 -0
- package/dist/erasure/org-batches.js +159 -0
- package/dist/erasure/org-catalog.d.ts +2 -0
- package/dist/erasure/org-catalog.js +34 -0
- package/dist/erasure/org-rules.d.ts +14 -0
- package/dist/erasure/org-rules.js +227 -0
- package/dist/erasure/org-worker.d.ts +38 -0
- package/dist/erasure/org-worker.js +501 -0
- package/dist/erasure/requests.d.ts +61 -0
- package/dist/erasure/requests.js +180 -0
- package/dist/erasure/sweep.job.d.ts +19 -0
- package/dist/erasure/sweep.job.js +130 -0
- package/dist/erasure/worker.d.ts +17 -0
- package/dist/erasure/worker.js +110 -0
- package/dist/errors.d.ts +419 -19
- package/dist/errors.js +419 -19
- package/dist/evals/budget.js +14 -1
- package/dist/evals/canonical-json.d.ts +7 -0
- package/dist/evals/canonical-json.js +21 -0
- package/dist/evals/evals.module.js +16 -3
- package/dist/evals/jobs.d.ts +14 -6
- package/dist/evals/jobs.js +21 -19
- package/dist/evals/judge.d.ts +8 -0
- package/dist/evals/judge.js +16 -1
- package/dist/evals/plan.d.ts +23 -16
- package/dist/evals/plan.js +54 -11
- package/dist/evals/reconstruct.d.ts +103 -23
- package/dist/evals/reconstruct.js +203 -74
- package/dist/evals/recorded-permission-context.d.ts +79 -0
- package/dist/evals/recorded-permission-context.js +155 -0
- package/dist/evals/recorded-tools.d.ts +22 -36
- package/dist/evals/recorded-tools.js +32 -111
- package/dist/evals/run-replay.d.ts +34 -9
- package/dist/evals/run-replay.js +139 -62
- package/dist/evals/runs.service.d.ts +5 -6
- package/dist/evals/runs.service.js +27 -42
- package/dist/evals/sets.service.d.ts +18 -11
- package/dist/evals/sets.service.js +71 -30
- package/dist/evals/snapshot.d.ts +34 -6
- package/dist/evals/snapshot.js +119 -74
- package/dist/evals/step-replay.d.ts +14 -4
- package/dist/evals/step-replay.js +26 -8
- package/dist/evals/trajectory.d.ts +26 -13
- package/dist/evals/trajectory.js +46 -24
- package/dist/evals/trajectory.service.d.ts +5 -8
- package/dist/evals/trajectory.service.js +13 -19
- package/dist/evals/worker.d.ts +17 -1
- package/dist/evals/worker.js +162 -51
- package/dist/extensions/admin-ops.d.ts +10 -2
- package/dist/extensions/admin-ops.js +69 -23
- package/dist/extensions/admin-view.d.ts +16 -7
- package/dist/extensions/admin-view.js +113 -30
- package/dist/extensions/blobs.d.ts +14 -1
- package/dist/extensions/blobs.js +48 -5
- package/dist/extensions/bootstrap-defaults.d.ts +24 -0
- package/dist/extensions/bootstrap-defaults.js +78 -0
- package/dist/extensions/bootstrap-extra.d.ts +84 -0
- package/dist/extensions/bootstrap-extra.js +151 -0
- package/dist/extensions/bootstrap-manifest.d.ts +14 -0
- package/dist/extensions/bootstrap-manifest.js +23 -0
- package/dist/extensions/bootstrap-packages.d.ts +98 -0
- package/dist/extensions/bootstrap-packages.js +303 -0
- package/dist/extensions/bootstrap.d.ts +161 -51
- package/dist/extensions/bootstrap.js +470 -256
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/config-hash.d.ts +2 -0
- package/dist/extensions/config-hash.js +1 -1
- package/dist/extensions/config-json-schema.d.ts +2 -2
- package/dist/extensions/config-json-schema.js +1 -3
- package/dist/extensions/deployed-snapshots.d.ts +19 -0
- package/dist/extensions/deployed-snapshots.js +59 -0
- package/dist/extensions/deployment-config-store.js +18 -14
- package/dist/extensions/deployment-config.d.ts +11 -5
- package/dist/extensions/deployment-config.js +38 -26
- package/dist/extensions/effective-config.d.ts +6 -9
- package/dist/extensions/effective-config.js +6 -9
- package/dist/extensions/enabled.d.ts +24 -4
- package/dist/extensions/enabled.js +48 -10
- package/dist/extensions/extensions.module.js +15 -0
- package/dist/extensions/guide-places.d.ts +82 -0
- package/dist/extensions/guide-places.js +175 -0
- package/dist/extensions/hooks.d.ts +30 -6
- package/dist/extensions/hooks.js +24 -4
- package/dist/extensions/host.d.ts +71 -16
- package/dist/extensions/host.js +151 -54
- package/dist/extensions/installs.d.ts +7 -17
- package/dist/extensions/installs.js +17 -33
- package/dist/extensions/instance.d.ts +9 -5
- package/dist/extensions/instance.js +16 -5
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/lifecycle-hooks.d.ts +113 -0
- package/dist/extensions/lifecycle-hooks.js +308 -0
- package/dist/extensions/lifecycle.d.ts +6 -1
- package/dist/extensions/lifecycle.js +9 -2
- package/dist/extensions/locks.d.ts +1 -1
- package/dist/extensions/locks.js +1 -1
- package/dist/extensions/org-config.d.ts +88 -86
- package/dist/extensions/org-config.js +158 -326
- package/dist/extensions/org-levels.d.ts +22 -9
- package/dist/extensions/org-levels.js +100 -20
- package/dist/extensions/org-overrides.d.ts +16 -15
- package/dist/extensions/org-overrides.js +23 -22
- package/dist/extensions/package.d.ts +6 -5
- package/dist/extensions/package.js +6 -6
- package/dist/extensions/permission-set.d.ts +129 -11
- package/dist/extensions/permission-set.js +125 -15
- package/dist/extensions/permission-view.d.ts +56 -16
- package/dist/extensions/permission-view.js +103 -20
- package/dist/extensions/plugin-guides.d.ts +244 -54
- package/dist/extensions/plugin-guides.js +516 -165
- package/dist/extensions/plugin-icons.d.ts +87 -2
- package/dist/extensions/plugin-icons.js +218 -4
- package/dist/extensions/plugin-items.d.ts +37 -1
- package/dist/extensions/plugin-items.js +63 -0
- package/dist/extensions/point-defaults.d.ts +48 -8
- package/dist/extensions/point-defaults.js +102 -51
- package/dist/extensions/registry.js +1 -0
- package/dist/extensions/resolve.js +7 -2
- package/dist/extensions/run-lifecycle-owe.d.ts +70 -0
- package/dist/extensions/run-lifecycle-owe.js +88 -0
- package/dist/extensions/sources.d.ts +6 -0
- package/dist/extensions/sources.js +2 -0
- package/dist/extensions/state.module.js +9 -1
- package/dist/extensions/sync.d.ts +9 -5
- package/dist/extensions/sync.js +33 -32
- package/dist/extensions/unavailable.js +0 -1
- package/dist/extensions/usage-subscribers.d.ts +43 -0
- package/dist/extensions/usage-subscribers.js +108 -0
- package/dist/files/blob-objects.d.ts +128 -0
- package/dist/files/blob-objects.js +358 -0
- package/dist/files/blob-references.d.ts +8 -0
- package/dist/files/blob-references.js +19 -0
- package/dist/files/blob-sweep.job.d.ts +124 -0
- package/dist/files/blob-sweep.job.js +418 -0
- package/dist/files/blobs.service.d.ts +135 -0
- package/dist/files/blobs.service.js +300 -0
- package/dist/files/conversation-media.d.ts +41 -0
- package/dist/files/conversation-media.js +124 -0
- package/dist/files/deliveries.d.ts +64 -0
- package/dist/files/deliveries.js +156 -0
- package/dist/files/deliveries.module.d.ts +6 -0
- package/dist/files/deliveries.module.js +24 -0
- package/dist/files/draft-cleanup.job.d.ts +26 -0
- package/dist/files/draft-cleanup.job.js +93 -0
- package/dist/files/files.module.d.ts +4 -1
- package/dist/files/files.module.js +7 -2
- package/dist/files/hash-job.d.ts +117 -0
- package/dist/files/hash-job.js +428 -0
- package/dist/files/library-files.service.d.ts +268 -0
- package/dist/files/library-files.service.js +914 -0
- package/dist/files/library-jobs.module.d.ts +3 -0
- package/dist/files/library-jobs.module.js +21 -0
- package/dist/files/library-query.d.ts +127 -0
- package/dist/files/library-query.js +322 -0
- package/dist/files/library-read.module.d.ts +9 -0
- package/dist/files/library-read.module.js +30 -0
- package/dist/files/library.controller.d.ts +77 -0
- package/dist/files/library.controller.js +235 -0
- package/dist/files/library.module.d.ts +9 -0
- package/dist/files/library.module.js +29 -0
- package/dist/files/library.schemas.d.ts +46 -0
- package/dist/files/library.schemas.js +49 -0
- package/dist/files/previewers.controller.d.ts +32 -0
- package/dist/files/previewers.controller.js +99 -0
- package/dist/files/previewers.d.ts +112 -11
- package/dist/files/previewers.js +215 -43
- package/dist/files/referenced-files.d.ts +150 -0
- package/dist/files/referenced-files.js +234 -0
- package/dist/git/gateway.d.ts +109 -0
- package/dist/git/gateway.js +828 -0
- package/dist/git/gateway.route.d.ts +16 -0
- package/dist/git/gateway.route.js +39 -0
- package/dist/git/git.module.d.ts +9 -0
- package/dist/git/git.module.js +31 -0
- package/dist/git/identity.d.ts +80 -0
- package/dist/git/identity.js +209 -0
- package/dist/git/pkt-line.d.ts +53 -0
- package/dist/git/pkt-line.js +146 -0
- package/dist/git/run-end.d.ts +29 -0
- package/dist/git/run-end.js +121 -0
- package/dist/git/sources.d.ts +42 -0
- package/dist/git/sources.js +134 -0
- package/dist/git/tickets.d.ts +69 -0
- package/dist/git/tickets.js +194 -0
- package/dist/handoff/app-schemes.d.ts +28 -0
- package/dist/handoff/app-schemes.js +41 -0
- package/dist/handoff/handoff-paths.d.ts +26 -0
- package/dist/handoff/handoff-paths.js +25 -0
- package/dist/handoff/handoff-tickets.d.ts +28 -0
- package/dist/handoff/handoff-tickets.js +111 -0
- package/dist/handoff/handoff.controller.d.ts +24 -0
- package/dist/handoff/handoff.controller.js +74 -0
- package/dist/handoff/handoff.module.d.ts +7 -0
- package/dist/handoff/handoff.module.js +26 -0
- package/dist/handoff/handoff.schemas.d.ts +13 -0
- package/dist/handoff/handoff.schemas.js +3 -0
- package/dist/handoff/handoff.service.d.ts +49 -0
- package/dist/handoff/handoff.service.js +96 -0
- package/dist/html/csp.d.ts +13 -0
- package/dist/html/csp.js +33 -0
- package/dist/html/html-document.controller.d.ts +38 -0
- package/dist/html/html-document.controller.js +96 -0
- package/dist/html/html-document.service.d.ts +64 -0
- package/dist/html/html-document.service.js +166 -0
- package/dist/html/html-token.d.ts +67 -0
- package/dist/html/html-token.js +168 -0
- package/dist/html/html-type.d.ts +15 -0
- package/dist/html/html-type.js +44 -0
- package/dist/html/html.module.d.ts +6 -0
- package/dist/html/html.module.js +33 -0
- package/dist/http/api.module.js +112 -9
- package/dist/http/app.d.ts +14 -2
- package/dist/http/app.js +27 -3
- package/dist/http/error.filter.d.ts +2 -0
- package/dist/http/error.filter.js +11 -2
- package/dist/http/gateway-routes.d.ts +9 -5
- package/dist/http/gateway-routes.js +5 -4
- package/dist/http/meta.controller.d.ts +50 -0
- package/dist/http/meta.controller.js +121 -0
- package/dist/http/plugin-dispatch.d.ts +55 -18
- package/dist/http/plugin-dispatch.js +132 -29
- package/dist/http/plugin-route-access.d.ts +57 -0
- package/dist/http/plugin-route-access.js +213 -0
- package/dist/http/request-signal.d.ts +8 -0
- package/dist/http/request-signal.js +14 -0
- package/dist/identity/account-avatar.controller.d.ts +30 -0
- package/dist/identity/account-avatar.controller.js +119 -0
- package/dist/identity/account-avatar.d.ts +67 -0
- package/dist/identity/account-avatar.js +136 -0
- package/dist/identity/account-avatars.service.d.ts +77 -0
- package/dist/identity/account-avatars.service.js +321 -0
- package/dist/identity/accounts.d.ts +48 -10
- package/dist/identity/accounts.js +164 -24
- package/dist/identity/api-tokens.d.ts +2 -0
- package/dist/identity/api-tokens.js +67 -36
- package/dist/identity/app-auth.controller.d.ts +26 -0
- package/dist/identity/app-auth.controller.js +65 -0
- package/dist/identity/app-auth.d.ts +84 -0
- package/dist/identity/app-auth.js +212 -0
- package/dist/identity/app-auth.schemas.d.ts +60 -0
- package/dist/identity/app-auth.schemas.js +46 -0
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +10 -32
- package/dist/identity/auth.controller.d.ts +2 -0
- package/dist/identity/auth.controller.js +6 -10
- package/dist/identity/auth.guard.d.ts +27 -12
- package/dist/identity/auth.guard.js +75 -35
- package/dist/identity/binding.d.ts +1 -1
- package/dist/identity/binding.js +19 -10
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/erasure-admission.d.ts +3 -0
- package/dist/identity/erasure-admission.js +14 -0
- package/dist/identity/external.d.ts +78 -40
- package/dist/identity/external.js +169 -73
- package/dist/identity/identity.module.d.ts +2 -1
- package/dist/identity/identity.module.js +21 -1
- package/dist/identity/initial-passwords.controller.d.ts +8 -6
- package/dist/identity/initial-passwords.controller.js +13 -7
- package/dist/identity/initial-passwords.d.ts +23 -14
- package/dist/identity/initial-passwords.job.d.ts +3 -2
- package/dist/identity/initial-passwords.job.js +11 -5
- package/dist/identity/initial-passwords.js +26 -31
- package/dist/identity/linked-accounts.d.ts +42 -0
- package/dist/identity/linked-accounts.js +78 -0
- package/dist/identity/login-sources.d.ts +160 -0
- package/dist/identity/login-sources.js +403 -0
- package/dist/identity/me.controller.d.ts +33 -7
- package/dist/identity/me.controller.js +61 -8
- package/dist/identity/me.schemas.d.ts +39 -0
- package/dist/identity/me.schemas.js +35 -0
- package/dist/identity/principal.d.ts +2 -2
- package/dist/identity/principal.js +2 -2
- package/dist/identity/sessions.d.ts +7 -6
- package/dist/identity/sessions.js +38 -25
- package/dist/identity/settings.d.ts +394 -29
- package/dist/identity/settings.js +720 -21
- package/dist/identity/sso-decisions.d.ts +75 -0
- package/dist/identity/sso-decisions.js +42 -0
- package/dist/identity/sso-link.d.ts +61 -0
- package/dist/identity/sso-link.js +157 -0
- package/dist/identity/sso-paths.d.ts +7 -0
- package/dist/identity/sso-paths.js +13 -0
- package/dist/identity/sso.controller.d.ts +122 -14
- package/dist/identity/sso.controller.js +261 -33
- package/dist/identity/sso.d.ts +87 -28
- package/dist/identity/sso.js +155 -69
- package/dist/identity/write-actor.d.ts +11 -0
- package/dist/identity/write-actor.js +7 -0
- package/dist/inbox/inbox-item-actions.d.ts +37 -0
- package/dist/inbox/inbox-item-actions.js +69 -0
- package/dist/inbox/inbox-items.controller.d.ts +27 -0
- package/dist/inbox/inbox-items.controller.js +80 -0
- package/dist/inbox/inbox-items.service.d.ts +112 -0
- package/dist/inbox/inbox-items.service.js +332 -0
- package/dist/inbox/inbox.module.d.ts +2 -1
- package/dist/inbox/inbox.module.js +16 -4
- package/dist/inbox/inbox.schemas.d.ts +20 -1
- package/dist/inbox/inbox.schemas.js +16 -1
- package/dist/inbox/inbox.service.d.ts +55 -32
- package/dist/inbox/inbox.service.js +40 -11
- package/dist/inbox/org-notices.d.ts +1 -15
- package/dist/inbox/platform-inbox.service.d.ts +54 -42
- package/dist/inbox/platform-inbox.service.js +97 -67
- package/dist/inbox/platform-notices.d.ts +18 -4
- package/dist/inbox/platform-notices.js +20 -0
- package/dist/inbox/token.d.ts +5 -0
- package/dist/inbox/token.js +5 -0
- package/dist/index.d.ts +16 -4
- package/dist/index.js +16 -4
- package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
- package/dist/infra/cli/kernel-cli.module.js +10 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.d.ts +8 -1
- package/dist/infra/config/kernel-config.service.js +102 -26
- package/dist/infra/database/database.module.js +2 -0
- package/dist/infra/database/org-scope.d.ts +61 -0
- package/dist/infra/database/org-scope.js +74 -0
- package/dist/infra/database/rls-role.d.ts +11 -0
- package/dist/infra/database/rls-role.js +33 -0
- package/dist/infra/database/scoped-dialect.d.ts +20 -0
- package/dist/infra/database/scoped-dialect.js +257 -0
- package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
- package/dist/infra/database/startup-activation-transaction.js +242 -0
- package/dist/infra/database/transaction-host.d.ts +79 -0
- package/dist/infra/database/transaction-host.js +159 -3
- package/dist/infra/database/xact-lock.d.ts +17 -0
- package/dist/infra/database/xact-lock.js +34 -1
- package/dist/infra/events/kernel-events.d.ts +19 -36
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/lock/lock.service.d.ts +13 -1
- package/dist/infra/lock/lock.service.js +37 -4
- package/dist/infra/metrics/kernel-metrics.d.ts +18 -0
- package/dist/infra/metrics/kernel-metrics.js +54 -0
- package/dist/infra/metrics/operational-metrics.d.ts +31 -0
- package/dist/infra/metrics/operational-metrics.js +188 -0
- package/dist/infra/outbox/outbox-relay.module.d.ts +6 -0
- package/dist/infra/outbox/outbox-relay.module.js +18 -0
- package/dist/infra/outbox/outbox.dispatcher.d.ts +103 -0
- package/dist/infra/outbox/outbox.dispatcher.js +321 -0
- package/dist/infra/outbox/outbox.module.d.ts +24 -0
- package/dist/infra/outbox/outbox.module.js +50 -0
- package/dist/infra/outbox/outbox.relay.d.ts +31 -0
- package/dist/infra/outbox/outbox.relay.js +76 -0
- package/dist/infra/outbox/outbox.service.d.ts +62 -0
- package/dist/infra/outbox/outbox.service.js +176 -0
- package/dist/infra/outbox/registry.d.ts +624 -0
- package/dist/infra/outbox/registry.js +566 -0
- package/dist/infra/presence/presence.module.d.ts +6 -0
- package/dist/infra/presence/presence.module.js +22 -0
- package/dist/infra/presence/replica-presence.d.ts +87 -0
- package/dist/infra/presence/replica-presence.js +189 -0
- package/dist/infra/queue/queue-names.d.ts +8 -0
- package/dist/infra/queue/queue-names.js +22 -0
- package/dist/infra/queue/run-job.d.ts +8 -2
- package/dist/infra/queue/run-job.js +16 -3
- package/dist/infra/schedule/locked-tick.js +12 -4
- package/dist/infra/schedule/scheduled-runs.js +3 -1
- package/dist/infra/throttler/credential-throttler.d.ts +4 -1
- package/dist/infra/throttler/credential-throttler.js +13 -3
- package/dist/infra/throttler/named-throttlers.d.ts +26 -3
- package/dist/infra/throttler/named-throttlers.js +110 -3
- package/dist/infra/throttler/principal-throttler.guard.d.ts +10 -0
- package/dist/infra/throttler/principal-throttler.guard.js +50 -0
- package/dist/infra/throttler/redis-throttler-storage.d.ts +1 -0
- package/dist/infra/throttler/redis-throttler-storage.js +27 -5
- package/dist/infra/throttler/throttler.guard.d.ts +2 -2
- package/dist/infra/throttler/throttler.guard.js +3 -3
- package/dist/infra/throttler/throttler.module.js +3 -2
- package/dist/kernel.d.ts +6 -0
- package/dist/kernel.js +31 -2
- package/dist/kernel.module.js +33 -4
- package/dist/lifecycle/kernel-lifecycle.d.ts +21 -2
- package/dist/lifecycle/kernel-lifecycle.js +186 -54
- package/dist/log.d.ts +6 -0
- package/dist/log.js +47 -19
- package/dist/media/image-header.d.ts +10 -0
- package/dist/media/image-header.js +87 -0
- package/dist/models/budget-admission.d.ts +31 -0
- package/dist/models/budget-admission.js +149 -0
- package/dist/models/budget-counters.d.ts +28 -0
- package/dist/models/budget-counters.js +117 -0
- package/dist/models/budget-policy.d.ts +88 -0
- package/dist/models/budget-policy.js +78 -0
- package/dist/models/cache-write-usage.d.ts +3 -0
- package/dist/models/cache-write-usage.js +26 -0
- package/dist/models/embeddings.d.ts +10 -14
- package/dist/models/embeddings.js +59 -54
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/models/image-usable.d.ts +46 -0
- package/dist/models/image-usable.js +60 -0
- package/dist/models/images.d.ts +123 -0
- package/dist/models/images.js +448 -0
- package/dist/models/models.module.d.ts +3 -2
- package/dist/models/models.module.js +18 -4
- package/dist/models/org-models.schemas.js +1 -0
- package/dist/models/price-snapshot.d.ts +43 -0
- package/dist/models/price-snapshot.js +145 -0
- package/dist/models/prices.d.ts +8 -6
- package/dist/models/prices.js +28 -3
- package/dist/models/purposes.controller.d.ts +7 -0
- package/dist/models/purposes.controller.js +9 -0
- package/dist/models/purposes.d.ts +73 -52
- package/dist/models/purposes.js +236 -38
- package/dist/net/public-address.d.ts +38 -8
- package/dist/net/public-address.js +83 -24
- package/dist/net/safe-fetch.d.ts +28 -6
- package/dist/net/safe-fetch.js +105 -8
- package/dist/orgs/device-network-setting.d.ts +38 -0
- package/dist/orgs/device-network-setting.js +59 -0
- package/dist/orgs/directory-sync.d.ts +18 -11
- package/dist/orgs/directory-sync.js +28 -21
- package/dist/orgs/invitations.controller.d.ts +3 -11
- package/dist/orgs/invitations.controller.js +9 -10
- package/dist/orgs/invitations.service.d.ts +13 -3
- package/dist/orgs/invitations.service.js +49 -36
- package/dist/orgs/members.service.d.ts +43 -4
- package/dist/orgs/members.service.js +101 -22
- package/dist/orgs/network-allowances.service.d.ts +79 -0
- package/dist/orgs/network-allowances.service.js +371 -0
- package/dist/orgs/offboarding.d.ts +58 -57
- package/dist/orgs/offboarding.js +165 -169
- package/dist/orgs/org-lock.d.ts +34 -2
- package/dist/orgs/org-lock.js +65 -4
- package/dist/orgs/org-owner.d.ts +9 -0
- package/dist/orgs/org-owner.js +31 -0
- package/dist/orgs/org.guard.js +4 -0
- package/dist/orgs/orgs.controller.d.ts +36 -13
- package/dist/orgs/orgs.controller.js +52 -12
- package/dist/orgs/orgs.module.d.ts +3 -2
- package/dist/orgs/orgs.module.js +21 -5
- package/dist/orgs/orgs.schemas.d.ts +38 -0
- package/dist/orgs/orgs.schemas.js +37 -0
- package/dist/orgs/orgs.service.d.ts +21 -7
- package/dist/orgs/orgs.service.js +100 -28
- package/dist/orgs/roles.d.ts +1 -1
- package/dist/orgs/roles.js +7 -0
- package/dist/orgs/security-settings.service.d.ts +94 -0
- package/dist/orgs/security-settings.service.js +223 -0
- package/dist/orgs/settings.controller.d.ts +37 -14
- package/dist/orgs/settings.controller.js +56 -10
- package/dist/orgs/settings.service.d.ts +566 -89
- package/dist/orgs/settings.service.js +787 -88
- package/dist/overrides.d.ts +68 -5
- package/dist/overrides.js +38 -2
- package/dist/packages/npm.d.ts +37 -10
- package/dist/packages/npm.js +67 -24
- package/dist/packages/provenance.d.ts +3 -1
- package/dist/packages/provenance.js +7 -3
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/availability.d.ts +5 -0
- package/dist/platform/availability.js +7 -3
- package/dist/platform/connector-person-fields.d.ts +67 -0
- package/dist/platform/connector-person-fields.js +129 -0
- package/dist/platform/exclusions.js +338 -191
- package/dist/platform/file-ref.d.ts +105 -0
- package/dist/platform/file-ref.js +173 -0
- package/dist/platform/method.js +1 -0
- package/dist/platform/operation.d.ts +98 -4
- package/dist/platform/operation.js +27 -7
- package/dist/platform/ops/accounts.ops.d.ts +1 -1
- package/dist/platform/ops/accounts.ops.js +61 -3
- package/dist/platform/ops/admin-items.ops.d.ts +37 -0
- package/dist/platform/ops/admin-items.ops.js +279 -0
- package/dist/platform/ops/admin.ops.d.ts +12 -10
- package/dist/platform/ops/admin.ops.js +352 -56
- package/dist/platform/ops/agent-skills.ops.d.ts +31 -3
- package/dist/platform/ops/agent-skills.ops.js +454 -12
- package/dist/platform/ops/agent-templates.ops.js +2 -2
- package/dist/platform/ops/agents.ops.d.ts +10 -3
- package/dist/platform/ops/agents.ops.js +128 -49
- package/dist/platform/ops/approvals.ops.d.ts +1 -1
- package/dist/platform/ops/approvals.ops.js +7 -2
- package/dist/platform/ops/automations.ops.d.ts +23 -0
- package/dist/platform/ops/automations.ops.js +602 -0
- package/dist/platform/ops/background.ops.js +5 -2
- package/dist/platform/ops/catalog-admin.ops.d.ts +29 -1
- package/dist/platform/ops/catalog-admin.ops.js +197 -11
- package/dist/platform/ops/channels.ops.d.ts +10 -3
- package/dist/platform/ops/channels.ops.js +246 -9
- package/dist/platform/ops/components.ops.d.ts +3 -1
- package/dist/platform/ops/components.ops.js +61 -2
- package/dist/platform/ops/connectors.ops.d.ts +22 -4
- package/dist/platform/ops/connectors.ops.js +740 -13
- package/dist/platform/ops/conversations.ops.js +46 -8
- package/dist/platform/ops/devices.ops.d.ts +5 -1
- package/dist/platform/ops/devices.ops.js +312 -36
- package/dist/platform/ops/evals.ops.js +5 -57
- package/dist/platform/ops/extensions-admin.ops.d.ts +45 -4
- package/dist/platform/ops/extensions-admin.ops.js +407 -13
- package/dist/platform/ops/extensions.ops.d.ts +23 -7
- package/dist/platform/ops/extensions.ops.js +282 -103
- package/dist/platform/ops/files.ops.d.ts +18 -0
- package/dist/platform/ops/files.ops.js +267 -0
- package/dist/platform/ops/inbox.ops.d.ts +4 -2
- package/dist/platform/ops/inbox.ops.js +144 -55
- package/dist/platform/ops/list-handoff.d.ts +10 -0
- package/dist/platform/ops/list-handoff.js +11 -0
- package/dist/platform/ops/marketplaces.ops.js +29 -5
- package/dist/platform/ops/models.ops.js +13 -3
- package/dist/platform/ops/org-plugins.ops.d.ts +19 -5
- package/dist/platform/ops/org-plugins.ops.js +209 -57
- package/dist/platform/ops/org-settings.ops.d.ts +5 -1
- package/dist/platform/ops/org-settings.ops.js +128 -19
- package/dist/platform/ops/orgs.ops.d.ts +48 -3
- package/dist/platform/ops/orgs.ops.js +465 -9
- package/dist/platform/ops/outbox.ops.d.ts +21 -0
- package/dist/platform/ops/outbox.ops.js +126 -0
- package/dist/platform/ops/person-inputs.d.ts +61 -0
- package/dist/platform/ops/person-inputs.js +121 -0
- package/dist/platform/ops/platform-icons.ops.d.ts +14 -0
- package/dist/platform/ops/platform-icons.ops.js +117 -0
- package/dist/platform/ops/platform.ops.d.ts +15 -2
- package/dist/platform/ops/platform.ops.js +111 -21
- package/dist/platform/ops/plugins.ops.d.ts +5 -1
- package/dist/platform/ops/plugins.ops.js +15 -37
- package/dist/platform/ops/requests.ops.js +13 -3
- package/dist/platform/ops/retention.d.ts +16 -0
- package/dist/platform/ops/retention.js +21 -0
- package/dist/platform/ops/setup.ops.d.ts +24 -0
- package/dist/platform/ops/setup.ops.js +212 -0
- package/dist/platform/ops/shares.ops.d.ts +16 -0
- package/dist/platform/ops/shares.ops.js +107 -0
- package/dist/platform/ops/skills.ops.d.ts +7 -1
- package/dist/platform/ops/skills.ops.js +111 -48
- package/dist/platform/ops/summary.d.ts +5 -0
- package/dist/platform/ops/summary.js +10 -0
- package/dist/platform/ops/themes.ops.js +1 -1
- package/dist/platform/ops/ui.ops.js +1 -1
- package/dist/platform/parity.d.ts +13 -6
- package/dist/platform/parity.js +139 -51
- package/dist/platform/person-fields.d.ts +120 -0
- package/dist/platform/person-fields.js +404 -0
- package/dist/platform/platform-ops.module.d.ts +8 -1
- package/dist/platform/platform-ops.module.js +35 -0
- package/dist/platform/platform.module.d.ts +4 -3
- package/dist/platform/platform.module.js +8 -5
- package/dist/platform/route-schemas.js +41 -0
- package/dist/platform/sealed-inputs.d.ts +44 -0
- package/dist/platform/sealed-inputs.js +116 -0
- package/dist/platform/sealed-reveals.controller.d.ts +17 -0
- package/dist/platform/sealed-reveals.controller.js +48 -0
- package/dist/platform/sealed-reveals.d.ts +54 -0
- package/dist/platform/sealed-reveals.js +155 -0
- package/dist/plugin-reads/plugin-reads.service.d.ts +29 -0
- package/dist/plugin-reads/plugin-reads.service.js +211 -0
- package/dist/plugin-reads/token.d.ts +5 -0
- package/dist/plugin-reads/token.js +5 -0
- package/dist/push/delivery.d.ts +88 -0
- package/dist/push/delivery.js +269 -0
- package/dist/push/fanout.d.ts +30 -0
- package/dist/push/fanout.js +102 -0
- package/dist/push/jobs.d.ts +48 -0
- package/dist/push/jobs.js +21 -0
- package/dist/push/preferences.service.d.ts +18 -0
- package/dist/push/preferences.service.js +88 -0
- package/dist/push/provider-host.d.ts +34 -0
- package/dist/push/provider-host.js +94 -0
- package/dist/push/push-owed.d.ts +35 -0
- package/dist/push/push-owed.js +102 -0
- package/dist/push/push-processor.d.ts +40 -0
- package/dist/push/push-processor.js +114 -0
- package/dist/push/push.controller.d.ts +28 -0
- package/dist/push/push.controller.js +92 -0
- package/dist/push/push.module.d.ts +6 -0
- package/dist/push/push.module.js +29 -0
- package/dist/push/push.schemas.d.ts +91 -0
- package/dist/push/push.schemas.js +54 -0
- package/dist/push/recipients.d.ts +33 -0
- package/dist/push/recipients.js +321 -0
- package/dist/push/registration-cleanup.d.ts +9 -0
- package/dist/push/registration-cleanup.js +16 -0
- package/dist/push/registrations.service.d.ts +55 -0
- package/dist/push/registrations.service.js +254 -0
- package/dist/push/stale.job.d.ts +25 -0
- package/dist/push/stale.job.js +76 -0
- package/dist/push/texts.d.ts +46 -0
- package/dist/push/texts.js +50 -0
- package/dist/push/token-store.d.ts +31 -0
- package/dist/push/token-store.js +52 -0
- package/dist/push/triggers.d.ts +19 -0
- package/dist/push/triggers.js +30 -0
- package/dist/retention/jobs.d.ts +21 -0
- package/dist/retention/jobs.js +48 -0
- package/dist/retention/policy.d.ts +70 -0
- package/dist/retention/policy.js +103 -0
- package/dist/retention/purge-batch.d.ts +17 -0
- package/dist/retention/purge-batch.js +355 -0
- package/dist/retention/report-obligations.d.ts +12 -0
- package/dist/retention/report-obligations.js +71 -0
- package/dist/retention/sweep.job.d.ts +17 -0
- package/dist/retention/sweep.job.js +95 -0
- package/dist/retention/worker.d.ts +29 -0
- package/dist/retention/worker.js +306 -0
- package/dist/roles/gateway-role.d.ts +18 -7
- package/dist/roles/gateway-role.js +37 -11
- package/dist/roles/gateway.module.d.ts +3 -2
- package/dist/roles/gateway.module.js +16 -6
- package/dist/roles/worker-role.d.ts +26 -9
- package/dist/roles/worker-role.js +66 -31
- package/dist/roles/worker.module.d.ts +1 -1
- package/dist/roles/worker.module.js +82 -11
- package/dist/runtime/abort.d.ts +22 -3
- package/dist/runtime/abort.js +37 -17
- package/dist/runtime/checkpointer.d.ts +3 -0
- package/dist/runtime/checkpointer.js +9 -3
- package/dist/runtime/compaction-model.d.ts +57 -0
- package/dist/runtime/compaction-model.js +87 -0
- package/dist/runtime/compaction-progress.d.ts +62 -0
- package/dist/runtime/compaction-progress.js +82 -0
- package/dist/runtime/compaction-settings.service.d.ts +36 -0
- package/dist/runtime/compaction-settings.service.js +63 -0
- package/dist/runtime/compaction.service.d.ts +101 -0
- package/dist/runtime/compaction.service.js +127 -0
- package/dist/runtime/context/build.d.ts +210 -45
- package/dist/runtime/context/build.js +552 -107
- package/dist/runtime/context/cache-expiry.d.ts +31 -0
- package/dist/runtime/context/cache-expiry.js +60 -0
- package/dist/runtime/context/cache-ttl.d.ts +18 -0
- package/dist/runtime/context/cache-ttl.js +30 -0
- package/dist/runtime/context/compaction.d.ts +175 -16
- package/dist/runtime/context/compaction.js +631 -70
- package/dist/runtime/context/device-paths.d.ts +7 -32
- package/dist/runtime/context/device-paths.js +6 -40
- package/dist/runtime/context/fit.d.ts +111 -0
- package/dist/runtime/context/fit.js +278 -0
- package/dist/runtime/context/idle-compaction-rules.d.ts +109 -0
- package/dist/runtime/context/idle-compaction-rules.js +99 -0
- package/dist/runtime/context/in-context-compaction.d.ts +156 -0
- package/dist/runtime/context/in-context-compaction.js +310 -0
- package/dist/runtime/context/output-truncated.d.ts +16 -0
- package/dist/runtime/context/output-truncated.js +19 -0
- package/dist/runtime/context/permission-profile.d.ts +45 -0
- package/dist/runtime/context/permission-profile.js +264 -0
- package/dist/runtime/context/plugin-context.d.ts +20 -0
- package/dist/runtime/context/plugin-context.js +30 -0
- package/dist/runtime/context/project-root.d.ts +43 -0
- package/dist/runtime/context/project-root.js +85 -0
- package/dist/runtime/context/run-context.d.ts +61 -0
- package/dist/runtime/context/run-context.js +134 -0
- package/dist/runtime/context/run-outcome.d.ts +10 -0
- package/dist/runtime/context/run-outcome.js +92 -0
- package/dist/runtime/context/skills.d.ts +38 -54
- package/dist/runtime/context/skills.js +76 -117
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/conversation-lock.d.ts +4 -11
- package/dist/runtime/conversation-lock.js +14 -18
- package/dist/runtime/hook-calls.d.ts +31 -13
- package/dist/runtime/hook-calls.js +61 -13
- package/dist/runtime/idle-arm.d.ts +48 -0
- package/dist/runtime/idle-arm.js +320 -0
- package/dist/runtime/idle-compaction-jobs.d.ts +46 -0
- package/dist/runtime/idle-compaction-jobs.js +21 -0
- package/dist/runtime/idle-compaction.d.ts +51 -0
- package/dist/runtime/idle-compaction.js +351 -0
- package/dist/runtime/idle-return.d.ts +62 -0
- package/dist/runtime/idle-return.js +173 -0
- package/dist/runtime/langgraph-loop.js +48 -9
- package/dist/runtime/limits.d.ts +15 -0
- package/dist/runtime/limits.js +25 -0
- package/dist/runtime/loop.d.ts +21 -5
- package/dist/runtime/loop.js +2 -1
- package/dist/runtime/maintenance.d.ts +47 -16
- package/dist/runtime/maintenance.js +284 -42
- package/dist/runtime/model-call.d.ts +403 -27
- package/dist/runtime/model-call.js +1472 -393
- package/dist/runtime/permission-context-errors.d.ts +39 -0
- package/dist/runtime/permission-context-errors.js +67 -0
- package/dist/runtime/permission-context.service.d.ts +60 -0
- package/dist/runtime/permission-context.service.js +289 -0
- package/dist/runtime/plugin-context.service.d.ts +75 -0
- package/dist/runtime/plugin-context.service.js +211 -0
- package/dist/runtime/project/knowledge.d.ts +135 -0
- package/dist/runtime/project/knowledge.js +256 -0
- package/dist/runtime/project/knowledge.service.d.ts +103 -0
- package/dist/runtime/project/knowledge.service.js +367 -0
- package/dist/runtime/providers.d.ts +116 -47
- package/dist/runtime/providers.js +266 -131
- package/dist/runtime/queue-lost-jobs.d.ts +24 -0
- package/dist/runtime/queue-lost-jobs.js +51 -0
- package/dist/runtime/quota.d.ts +12 -12
- package/dist/runtime/quota.js +42 -37
- package/dist/runtime/run-context.service.d.ts +21 -4
- package/dist/runtime/run-context.service.js +55 -31
- package/dist/runtime/run-control.d.ts +52 -5
- package/dist/runtime/run-control.js +86 -12
- package/dist/runtime/run-deletion.d.ts +30 -0
- package/dist/runtime/run-deletion.js +161 -0
- package/dist/runtime/run-drafts.d.ts +68 -4
- package/dist/runtime/run-drafts.js +174 -9
- package/dist/runtime/run-execution.d.ts +80 -0
- package/dist/runtime/run-execution.js +191 -0
- package/dist/runtime/run-finish.d.ts +71 -10
- package/dist/runtime/run-finish.js +196 -18
- package/dist/runtime/run-jobs.d.ts +123 -14
- package/dist/runtime/run-jobs.js +276 -29
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.d.ts +146 -0
- package/dist/runtime/run-orphan-check.job.js +427 -0
- package/dist/runtime/run-principal.d.ts +9 -0
- package/dist/runtime/run-principal.js +18 -0
- package/dist/runtime/run-processors.d.ts +33 -24
- package/dist/runtime/run-processors.js +44 -9
- package/dist/runtime/run-queue.d.ts +155 -70
- package/dist/runtime/run-queue.js +611 -298
- package/dist/runtime/run-status.d.ts +12 -0
- package/dist/runtime/run-status.js +21 -0
- package/dist/runtime/run-steps.d.ts +18 -5
- package/dist/runtime/run-steps.js +51 -16
- package/dist/runtime/run-worker.d.ts +85 -25
- package/dist/runtime/run-worker.js +572 -152
- package/dist/runtime/runtime.module.d.ts +3 -4
- package/dist/runtime/runtime.module.js +74 -7
- package/dist/runtime/step-log.d.ts +23 -5
- package/dist/runtime/step-log.js +37 -10
- package/dist/runtime/stream.controller.d.ts +9 -9
- package/dist/runtime/stream.controller.js +15 -17
- package/dist/runtime/stream.d.ts +7 -1
- package/dist/runtime/stream.js +90 -9
- package/dist/runtime/subagents/child.js +3 -1
- package/dist/runtime/subagents/definition.d.ts +38 -23
- package/dist/runtime/subagents/definition.js +118 -114
- package/dist/runtime/subagents/deliveries.d.ts +6 -3
- package/dist/runtime/subagents/deliveries.js +26 -8
- package/dist/runtime/subagents/dispatch.d.ts +23 -16
- package/dist/runtime/subagents/dispatch.js +48 -43
- package/dist/runtime/subagents/messages.d.ts +8 -2
- package/dist/runtime/subagents/messages.js +22 -9
- package/dist/runtime/subagents/org-agents.d.ts +1 -1
- package/dist/runtime/subagents/org-agents.js +3 -3
- package/dist/runtime/subagents/preamble.d.ts +3 -1
- package/dist/runtime/subagents/preamble.js +3 -1
- package/dist/runtime/subagents/progress.js +1 -0
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +5 -7
- package/dist/runtime/subagents/skill-fork.js +11 -5
- package/dist/runtime/subagents/status.js +2 -0
- package/dist/runtime/subagents/subagents.service.js +1 -1
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +77 -0
- package/dist/runtime/subagents/tree-jobs.d.ts +62 -0
- package/dist/runtime/subagents/tree-jobs.js +86 -0
- package/dist/runtime/usage-report-jobs.d.ts +24 -46
- package/dist/runtime/usage-report-jobs.js +86 -114
- package/dist/runtime/usage-report.d.ts +47 -84
- package/dist/runtime/usage-report.js +135 -241
- package/dist/runtime/waits.d.ts +65 -205
- package/dist/runtime/waits.js +209 -830
- package/dist/runtime/write-base.d.ts +178 -0
- package/dist/runtime/write-base.js +540 -0
- package/dist/runtime/write-base.service.d.ts +75 -0
- package/dist/runtime/write-base.service.js +216 -0
- package/dist/sandbox/attachments-path.d.ts +15 -0
- package/dist/sandbox/attachments-path.js +15 -0
- package/dist/sandbox/browse-roots.d.ts +8 -0
- package/dist/sandbox/browse-roots.js +22 -0
- package/dist/sandbox/device-reports.d.ts +110 -0
- package/dist/sandbox/device-reports.js +317 -0
- package/dist/sandbox/device-reports.module.d.ts +7 -0
- package/dist/sandbox/device-reports.module.js +25 -0
- package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
- package/dist/sandbox/device-sandbox-settings.js +227 -0
- package/dist/sandbox/device-sandbox.d.ts +230 -0
- package/dist/sandbox/device-sandbox.js +251 -0
- package/dist/sandbox/device-services.d.ts +146 -0
- package/dist/sandbox/device-services.js +373 -0
- package/dist/sandbox/held-operations.d.ts +43 -0
- package/dist/sandbox/held-operations.js +137 -0
- package/dist/sandbox/jobs.d.ts +21 -11
- package/dist/sandbox/jobs.js +24 -18
- package/dist/sandbox/kernel-read.d.ts +85 -0
- package/dist/sandbox/kernel-read.js +87 -0
- package/dist/sandbox/leases.d.ts +25 -5
- package/dist/sandbox/leases.js +92 -12
- package/dist/sandbox/loopback-expiry.job.d.ts +23 -0
- package/dist/sandbox/loopback-expiry.job.js +56 -0
- package/dist/sandbox/loopback-grant-records.d.ts +144 -0
- package/dist/sandbox/loopback-grant-records.js +266 -0
- package/dist/sandbox/loopback-grants.d.ts +119 -0
- package/dist/sandbox/loopback-grants.js +454 -0
- package/dist/sandbox/loopback-live-ports.d.ts +12 -0
- package/dist/sandbox/loopback-live-ports.js +43 -0
- package/dist/sandbox/managed-device-context.d.ts +118 -0
- package/dist/sandbox/managed-device-context.js +375 -0
- package/dist/sandbox/managed-device-context.module.d.ts +6 -0
- package/dist/sandbox/managed-device-context.module.js +37 -0
- package/dist/sandbox/modes.d.ts +170 -0
- package/dist/sandbox/modes.js +196 -0
- package/dist/sandbox/network-grants.d.ts +69 -0
- package/dist/sandbox/network-grants.js +227 -0
- package/dist/sandbox/network-grants.module.d.ts +2 -0
- package/dist/sandbox/network-grants.module.js +14 -0
- package/dist/sandbox/operation-authority-types.d.ts +27 -0
- package/dist/sandbox/operation-authority-types.js +50 -0
- package/dist/sandbox/operation-authority.d.ts +174 -0
- package/dist/sandbox/operation-authority.js +952 -0
- package/dist/sandbox/operation-authority.module.d.ts +2 -0
- package/dist/sandbox/operation-authority.module.js +29 -0
- package/dist/sandbox/operation-intents.d.ts +288 -0
- package/dist/sandbox/operation-intents.js +1685 -0
- package/dist/sandbox/operation-intents.module.d.ts +2 -0
- package/dist/sandbox/operation-intents.module.js +22 -0
- package/dist/sandbox/operation-payloads.d.ts +33 -0
- package/dist/sandbox/operation-payloads.js +332 -0
- package/dist/sandbox/operation-reconcile.job.d.ts +71 -0
- package/dist/sandbox/operation-reconcile.job.js +418 -0
- package/dist/sandbox/operation-revoke.d.ts +20 -0
- package/dist/sandbox/operation-revoke.js +3 -0
- package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
- package/dist/sandbox/permission-authority-epochs.js +83 -0
- package/dist/sandbox/permission-authority-lock.d.ts +44 -0
- package/dist/sandbox/permission-authority-lock.js +167 -0
- package/dist/sandbox/permission-authority.module.d.ts +9 -0
- package/dist/sandbox/permission-authority.module.js +55 -0
- package/dist/sandbox/permission-auto-grants.d.ts +42 -0
- package/dist/sandbox/permission-auto-grants.js +145 -0
- package/dist/sandbox/permission-availability.d.ts +63 -0
- package/dist/sandbox/permission-availability.js +71 -0
- package/dist/sandbox/permission-call-grants.d.ts +47 -0
- package/dist/sandbox/permission-call-grants.js +429 -0
- package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
- package/dist/sandbox/permission-call-grants.module.js +28 -0
- package/dist/sandbox/permission-call-types.d.ts +151 -0
- package/dist/sandbox/permission-call-types.js +1 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +65 -0
- package/dist/sandbox/permission-ceiling-writes.js +354 -0
- package/dist/sandbox/permission-config-publication.d.ts +109 -0
- package/dist/sandbox/permission-config-publication.js +354 -0
- package/dist/sandbox/permission-context-types.d.ts +60 -0
- package/dist/sandbox/permission-context-types.js +11 -0
- package/dist/sandbox/permission-facts.d.ts +396 -0
- package/dist/sandbox/permission-facts.js +790 -0
- package/dist/sandbox/permission-facts.module.d.ts +2 -0
- package/dist/sandbox/permission-facts.module.js +20 -0
- package/dist/sandbox/permission-instance-writes.d.ts +76 -0
- package/dist/sandbox/permission-instance-writes.js +232 -0
- package/dist/sandbox/permission-runtime-reports.d.ts +92 -0
- package/dist/sandbox/permission-runtime-reports.js +337 -0
- package/dist/sandbox/permission-transitions.d.ts +31 -0
- package/dist/sandbox/permission-transitions.js +158 -0
- package/dist/sandbox/providers.d.ts +48 -32
- package/dist/sandbox/providers.js +68 -48
- package/dist/sandbox/providers.module.d.ts +2 -0
- package/dist/sandbox/providers.module.js +19 -0
- package/dist/sandbox/request-not-sent.d.ts +15 -0
- package/dist/sandbox/request-not-sent.js +20 -0
- package/dist/sandbox/review/classifier.d.ts +252 -0
- package/dist/sandbox/review/classifier.js +635 -0
- package/dist/sandbox/review/index.d.ts +13 -0
- package/dist/sandbox/review/index.js +10 -0
- package/dist/sandbox/review/permission-candidate.d.ts +143 -0
- package/dist/sandbox/review/permission-candidate.js +449 -0
- package/dist/sandbox/review/review.service.d.ts +260 -0
- package/dist/sandbox/review/review.service.js +761 -0
- package/dist/sandbox/review/rules.d.ts +96 -0
- package/dist/sandbox/review/rules.js +5427 -0
- package/dist/sandbox/review/types.d.ts +122 -0
- package/dist/sandbox/review/types.js +48 -0
- package/dist/sandbox/sandbox-file-reader.d.ts +47 -0
- package/dist/sandbox/sandbox-file-reader.js +125 -0
- package/dist/sandbox/sandbox.module.d.ts +3 -2
- package/dist/sandbox/sandbox.module.js +57 -7
- package/dist/sandbox/sandbox.service.d.ts +647 -160
- package/dist/sandbox/sandbox.service.js +2197 -470
- package/dist/sandbox/unreachable.js +20 -3
- package/dist/sandbox/use-context.d.ts +20 -0
- package/dist/sandbox/use-context.js +1 -0
- package/dist/setup/kernel-checks.d.ts +91 -0
- package/dist/setup/kernel-checks.js +296 -0
- package/dist/setup/oauth-token-probe.d.ts +40 -0
- package/dist/setup/oauth-token-probe.js +96 -0
- package/dist/setup/redact-check.d.ts +18 -0
- package/dist/setup/redact-check.js +46 -0
- package/dist/setup/setup-check-registry.d.ts +86 -0
- package/dist/setup/setup-check-registry.js +75 -0
- package/dist/setup/setup-checks.controller.d.ts +28 -0
- package/dist/setup/setup-checks.controller.js +78 -0
- package/dist/setup/setup-checks.schemas.d.ts +67 -0
- package/dist/setup/setup-checks.schemas.js +75 -0
- package/dist/setup/setup-checks.service.d.ts +168 -0
- package/dist/setup/setup-checks.service.js +781 -0
- package/dist/setup/setup-guides.controller.d.ts +18 -0
- package/dist/setup/setup-guides.controller.js +48 -0
- package/dist/setup/setup-guides.schemas.d.ts +10 -0
- package/dist/setup/setup-guides.schemas.js +6 -0
- package/dist/setup/setup-guides.service.d.ts +141 -0
- package/dist/setup/setup-guides.service.js +348 -0
- package/dist/setup/setup.module.d.ts +8 -0
- package/dist/setup/setup.module.js +31 -0
- package/dist/shares/liveness.d.ts +73 -0
- package/dist/shares/liveness.js +236 -0
- package/dist/shares/revoke.d.ts +31 -0
- package/dist/shares/revoke.js +47 -0
- package/dist/shares/settings.d.ts +76 -0
- package/dist/shares/settings.js +117 -0
- package/dist/shares/share-code.d.ts +4 -0
- package/dist/shares/share-code.js +28 -0
- package/dist/shares/share-open.controller.d.ts +35 -0
- package/dist/shares/share-open.controller.js +107 -0
- package/dist/shares/share-open.service.d.ts +111 -0
- package/dist/shares/share-open.service.js +293 -0
- package/dist/shares/share-previews.controller.d.ts +50 -0
- package/dist/shares/share-previews.controller.js +115 -0
- package/dist/shares/shares.controller.d.ts +45 -0
- package/dist/shares/shares.controller.js +148 -0
- package/dist/shares/shares.module.d.ts +7 -0
- package/dist/shares/shares.module.js +39 -0
- package/dist/shares/shares.schemas.d.ts +35 -0
- package/dist/shares/shares.schemas.js +27 -0
- package/dist/shares/shares.service.d.ts +222 -0
- package/dist/shares/shares.service.js +721 -0
- package/dist/shares/sweep.job.d.ts +53 -0
- package/dist/shares/sweep.job.js +173 -0
- package/dist/skills/agent-skills.controller.d.ts +48 -0
- package/dist/skills/agent-skills.controller.js +131 -0
- package/dist/skills/agent-skills.service.d.ts +258 -0
- package/dist/skills/agent-skills.service.js +971 -0
- package/dist/skills/catalog.d.ts +83 -71
- package/dist/skills/catalog.js +148 -215
- package/dist/skills/changes.controller.d.ts +6 -23
- package/dist/skills/changes.controller.js +8 -56
- package/dist/skills/changes.service.d.ts +70 -115
- package/dist/skills/changes.service.js +261 -606
- package/dist/skills/conversation-catalog.d.ts +52 -0
- package/dist/skills/conversation-catalog.js +142 -0
- package/dist/skills/invocable.controller.d.ts +4 -0
- package/dist/skills/invocable.controller.js +5 -1
- package/dist/skills/invocation-keys.d.ts +1 -1
- package/dist/skills/invocation-keys.js +1 -1
- package/dist/skills/invoke.d.ts +153 -5
- package/dist/skills/invoke.js +288 -6
- package/dist/skills/package.d.ts +0 -5
- package/dist/skills/package.js +0 -14
- package/dist/skills/skill-files.d.ts +91 -0
- package/dist/skills/skill-files.js +144 -0
- package/dist/skills/skills.controller.d.ts +28 -10
- package/dist/skills/skills.controller.js +77 -31
- package/dist/skills/skills.module.js +23 -2
- package/dist/skills/skills.schemas.d.ts +69 -15
- package/dist/skills/skills.schemas.js +117 -18
- package/dist/skills/skills.service.d.ts +106 -71
- package/dist/skills/skills.service.js +330 -204
- package/dist/skills/usable.d.ts +59 -7
- package/dist/skills/usable.js +234 -36
- package/dist/storage/purge.d.ts +1 -1
- package/dist/storage/purge.js +7 -3
- package/dist/storage/storage.service.d.ts +19 -1
- package/dist/storage/storage.service.js +87 -5
- package/dist/themes/avatar-preset-key.d.ts +6 -0
- package/dist/themes/avatar-preset-key.js +9 -0
- package/dist/themes/platform-icon-objects.d.ts +51 -0
- package/dist/themes/platform-icon-objects.js +113 -0
- package/dist/themes/platform-icon-public.controller.d.ts +17 -0
- package/dist/themes/platform-icon-public.controller.js +58 -0
- package/dist/themes/platform-icon.controller.d.ts +22 -0
- package/dist/themes/platform-icon.controller.js +65 -0
- package/dist/themes/platform-icon.schemas.d.ts +48 -0
- package/dist/themes/platform-icon.schemas.js +53 -0
- package/dist/themes/platform-icon.service.d.ts +83 -0
- package/dist/themes/platform-icon.service.js +301 -0
- package/dist/themes/render-css.d.ts +2 -1
- package/dist/themes/render-css.js +14 -4
- package/dist/themes/theme-delivery.service.d.ts +14 -4
- package/dist/themes/theme-delivery.service.js +34 -14
- package/dist/themes/theme-state.d.ts +71 -9
- package/dist/themes/theme-state.js +85 -10
- package/dist/themes/themes-public.controller.d.ts +10 -5
- package/dist/themes/themes-public.controller.js +14 -8
- package/dist/themes/themes.module.d.ts +4 -1
- package/dist/themes/themes.module.js +9 -4
- package/dist/themes/themes.service.d.ts +28 -1
- package/dist/themes/themes.service.js +38 -4
- package/dist/tools/admin-connectors.d.ts +71 -0
- package/dist/tools/admin-connectors.js +139 -0
- package/dist/tools/approvals.controller.d.ts +6 -2
- package/dist/tools/approvals.controller.js +36 -2
- package/dist/tools/approvals.schemas.d.ts +2 -0
- package/dist/tools/approvals.schemas.js +5 -1
- package/dist/tools/approvals.service.d.ts +669 -18
- package/dist/tools/approvals.service.js +1972 -55
- package/dist/tools/builtin-names.d.ts +29 -20
- package/dist/tools/builtin-names.js +60 -31
- package/dist/tools/builtins/agent.js +13 -5
- package/dist/tools/builtins/artifacts.d.ts +77 -0
- package/dist/tools/builtins/artifacts.js +173 -0
- package/dist/tools/builtins/ask-user.js +3 -2
- package/dist/tools/builtins/automations.d.ts +111 -0
- package/dist/tools/builtins/automations.js +1083 -0
- package/dist/tools/builtins/builtin-tools.d.ts +38 -7
- package/dist/tools/builtins/builtin-tools.js +191 -32
- package/dist/tools/builtins/conversation-files.d.ts +58 -0
- package/dist/tools/builtins/conversation-files.js +141 -0
- package/dist/tools/builtins/image/generate.d.ts +71 -0
- package/dist/tools/builtins/image/generate.js +586 -0
- package/dist/tools/builtins/image/index.d.ts +2 -0
- package/dist/tools/builtins/image/index.js +2 -0
- package/dist/tools/builtins/image/paths.d.ts +12 -0
- package/dist/tools/builtins/image/paths.js +26 -0
- package/dist/tools/builtins/image/size.d.ts +12 -0
- package/dist/tools/builtins/image/size.js +36 -0
- package/dist/tools/builtins/platform.d.ts +47 -2
- package/dist/tools/builtins/platform.js +355 -39
- package/dist/tools/builtins/sandbox/bash.d.ts +53 -1
- package/dist/tools/builtins/sandbox/bash.js +372 -206
- package/dist/tools/builtins/sandbox/common.d.ts +216 -59
- package/dist/tools/builtins/sandbox/common.js +386 -185
- package/dist/tools/builtins/sandbox/deliver.d.ts +3 -0
- package/dist/tools/builtins/sandbox/deliver.js +112 -71
- package/dist/tools/builtins/sandbox/device-code.d.ts +40 -0
- package/dist/tools/builtins/sandbox/device-code.js +57 -0
- package/dist/tools/builtins/sandbox/device-owner.d.ts +12 -0
- package/dist/tools/builtins/sandbox/device-owner.js +13 -0
- package/dist/tools/builtins/sandbox/edit.js +14 -7
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +11 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +133 -0
- package/dist/tools/builtins/sandbox/file-state.d.ts +31 -1
- package/dist/tools/builtins/sandbox/file-state.js +33 -3
- package/dist/tools/builtins/sandbox/glob.js +15 -10
- package/dist/tools/builtins/sandbox/grep.d.ts +8 -1
- package/dist/tools/builtins/sandbox/grep.js +35 -40
- package/dist/tools/builtins/sandbox/index.d.ts +9 -7
- package/dist/tools/builtins/sandbox/index.js +13 -7
- package/dist/tools/builtins/sandbox/read.d.ts +56 -2
- package/dist/tools/builtins/sandbox/read.js +272 -50
- package/dist/tools/builtins/sandbox/search-command.d.ts +44 -0
- package/dist/tools/builtins/sandbox/search-command.js +94 -0
- package/dist/tools/builtins/sandbox/task-list.d.ts +12 -0
- package/dist/tools/builtins/sandbox/task-list.js +136 -0
- package/dist/tools/builtins/sandbox/task-output.d.ts +22 -41
- package/dist/tools/builtins/sandbox/task-output.js +255 -201
- package/dist/tools/builtins/sandbox/task-stop.d.ts +4 -3
- package/dist/tools/builtins/sandbox/task-stop.js +51 -26
- package/dist/tools/builtins/sandbox/write.js +17 -9
- package/dist/tools/builtins/send-message.d.ts +1 -1
- package/dist/tools/builtins/send-message.js +4 -3
- package/dist/tools/builtins/size-text.d.ts +2 -0
- package/dist/tools/builtins/size-text.js +8 -0
- package/dist/tools/builtins/skill-load.d.ts +57 -5
- package/dist/tools/builtins/skill-load.js +246 -13
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +10 -13
- package/dist/tools/builtins/vision/read-image.d.ts +59 -0
- package/dist/tools/builtins/vision/read-image.js +222 -0
- package/dist/tools/builtins/web/extract.d.ts +2 -4
- package/dist/tools/builtins/web/extract.js +15 -16
- package/dist/tools/builtins/web/fetch.js +1 -1
- package/dist/tools/builtins/web/search.js +3 -5
- package/dist/tools/call-scope.d.ts +116 -0
- package/dist/tools/call-scope.js +82 -0
- package/dist/tools/connector-account-policies.d.ts +36 -1
- package/dist/tools/connector-account-policies.js +67 -6
- package/dist/tools/connector-content.controller.d.ts +6 -2
- package/dist/tools/connector-content.controller.js +13 -3
- package/dist/tools/connector-content.d.ts +55 -15
- package/dist/tools/connector-content.js +113 -54
- package/dist/tools/connector-setup.d.ts +32 -0
- package/dist/tools/connector-setup.js +47 -0
- package/dist/tools/connector-tools-jobs.d.ts +36 -0
- package/dist/tools/connector-tools-jobs.js +40 -0
- package/dist/tools/connector-tools.processor.d.ts +32 -0
- package/dist/tools/connector-tools.processor.js +97 -0
- package/dist/tools/connectors.controller.d.ts +100 -40
- package/dist/tools/connectors.controller.js +149 -72
- package/dist/tools/connectors.schemas.d.ts +188 -2
- package/dist/tools/connectors.schemas.js +114 -5
- package/dist/tools/connectors.service.d.ts +288 -33
- package/dist/tools/connectors.service.js +861 -133
- package/dist/tools/credentials.d.ts +80 -0
- package/dist/tools/credentials.js +249 -2
- package/dist/tools/credentials.module.d.ts +7 -0
- package/dist/tools/credentials.module.js +22 -0
- package/dist/tools/drift.d.ts +12 -3
- package/dist/tools/drift.js +85 -47
- package/dist/tools/editable-endpoint.d.ts +23 -0
- package/dist/tools/editable-endpoint.js +92 -0
- package/dist/tools/elicitation.d.ts +2 -0
- package/dist/tools/elicitation.js +1 -1
- package/dist/tools/fixed-ask.d.ts +7 -0
- package/dist/tools/fixed-ask.js +9 -0
- package/dist/tools/git-asks.d.ts +113 -0
- package/dist/tools/git-asks.js +174 -0
- package/dist/tools/git-push-policy.d.ts +89 -0
- package/dist/tools/git-push-policy.js +179 -0
- package/dist/tools/info.d.ts +28 -13
- package/dist/tools/info.js +60 -30
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/loopback-asks.d.ts +52 -0
- package/dist/tools/loopback-asks.js +70 -0
- package/dist/tools/mentionable-connectors.d.ts +88 -0
- package/dist/tools/mentionable-connectors.js +218 -0
- package/dist/tools/network-asks.d.ts +276 -0
- package/dist/tools/network-asks.js +427 -0
- package/dist/tools/oauth/authorization-params.d.ts +7 -0
- package/dist/tools/oauth/authorization-params.js +19 -0
- package/dist/tools/oauth/discovery.d.ts +40 -16
- package/dist/tools/oauth/discovery.js +62 -34
- package/dist/tools/oauth/flow.d.ts +18 -3
- package/dist/tools/oauth/flow.js +42 -9
- package/dist/tools/oauth/oauth.controller.d.ts +20 -11
- package/dist/tools/oauth/oauth.controller.js +44 -23
- package/dist/tools/oauth/oauth.schemas.d.ts +27 -0
- package/dist/tools/oauth/oauth.schemas.js +30 -0
- package/dist/tools/oauth/tokens.d.ts +20 -0
- package/dist/tools/oauth/tokens.js +51 -25
- package/dist/tools/org-tool-policies.d.ts +24 -0
- package/dist/tools/org-tool-policies.js +113 -0
- package/dist/tools/org-tool-switches.d.ts +5 -69
- package/dist/tools/org-tool-switches.js +13 -141
- package/dist/tools/outputs.d.ts +6 -4
- package/dist/tools/outputs.js +33 -29
- package/dist/tools/permission-approval-jobs.d.ts +18 -0
- package/dist/tools/permission-approval-jobs.js +95 -0
- package/dist/tools/pipeline.d.ts +577 -30
- package/dist/tools/pipeline.js +3172 -171
- package/dist/tools/policy.d.ts +31 -15
- package/dist/tools/policy.js +91 -54
- package/dist/tools/questions.controller.js +2 -2
- package/dist/tools/questions.service.d.ts +128 -12
- package/dist/tools/questions.service.js +284 -18
- package/dist/tools/registry.d.ts +179 -20
- package/dist/tools/registry.js +128 -37
- package/dist/tools/result-images.d.ts +91 -0
- package/dist/tools/result-images.js +195 -0
- package/dist/tools/specs.d.ts +13 -4
- package/dist/tools/specs.js +22 -8
- package/dist/tools/tool-review.d.ts +113 -0
- package/dist/tools/tool-review.js +303 -0
- package/dist/tools/tool-watch-queue.d.ts +45 -0
- package/dist/tools/tool-watch-queue.js +28 -0
- package/dist/tools/tool-watch-queue.module.d.ts +7 -0
- package/dist/tools/tool-watch-queue.module.js +24 -0
- package/dist/tools/tool-watch.processor.d.ts +35 -0
- package/dist/tools/tool-watch.processor.js +114 -0
- package/dist/tools/tool-watch.service.d.ts +46 -0
- package/dist/tools/tool-watch.service.js +214 -0
- package/dist/tools/tools.module.js +76 -6
- package/dist/tools/watched-waits-lock.d.ts +15 -0
- package/dist/tools/watched-waits-lock.js +40 -0
- package/dist/ui/admin-ui.controller.d.ts +5 -2
- package/dist/ui/admin-ui.controller.js +14 -1
- package/dist/ui/arrangement.d.ts +41 -50
- package/dist/ui/arrangement.js +88 -15
- package/dist/ui/call-extension.d.ts +6 -4
- package/dist/ui/call-extension.js +5 -4
- package/dist/ui/embed-token.d.ts +2 -2
- package/dist/ui/embed-token.js +83 -6
- package/dist/ui/registry.d.ts +34 -8
- package/dist/ui/registry.js +38 -9
- package/dist/ui/ui.schemas.d.ts +38 -0
- package/dist/ui/ui.schemas.js +32 -4
- package/dist/ui/views.controller.d.ts +18 -6
- package/dist/ui/views.controller.js +54 -5
- package/dist/ui/views.d.ts +98 -14
- package/dist/ui/views.js +253 -44
- package/dist/until-aborted.d.ts +5 -0
- package/dist/until-aborted.js +16 -0
- package/package.json +6 -3
- package/src/migrations/0106_setup_guides_v2.sql +10 -0
- package/src/migrations/0107_extension_client_builds.sql +50 -0
- package/src/migrations/0108_question_skipped.sql +6 -0
- package/src/migrations/0109_audit_platform_idx.sql +5 -0
- package/src/migrations/0110_usage_time_idx.sql +8 -0
- package/src/migrations/0111_agent_skill_sharing.sql +22 -0
- package/src/migrations/0112_skill_share_requests.sql +4 -0
- package/src/migrations/0113_scheduled_tasks.sql +108 -0
- package/src/migrations/0114_network_asks.sql +23 -0
- package/src/migrations/0115_network_requests.sql +28 -0
- package/src/migrations/0116_skills_default_on.sql +37 -0
- package/src/migrations/0117_sandbox_tiers.sql +11 -0
- package/src/migrations/0118_device_policy_ops.sql +6 -0
- package/src/migrations/0119_outbox.sql +22 -0
- package/src/migrations/0120_drop_usage_report_sweep.sql +7 -0
- package/src/migrations/0121_drop_platform_migration_runs.sql +12 -0
- package/src/migrations/0122_drop_scheduled_task_runs_rechecked_at.sql +5 -0
- package/src/migrations/0123_pgvector.sql +27 -0
- package/src/migrations/0124_conversation_source.sql +36 -0
- package/src/migrations/0125_conversation_tree_stopped_at.sql +5 -0
- package/src/migrations/0126_git_gateway.sql +10 -0
- package/src/migrations/0127_git_push_policy.sql +12 -0
- package/src/migrations/0128_scheduled_task_plugin_disabled.sql +10 -0
- package/src/migrations/0129_connector_plugin_disabled.sql +5 -0
- package/src/migrations/0130_auto_mode.sql +48 -0
- package/src/migrations/0131_device_mode.sql +9 -0
- package/src/migrations/0132_compact_runs.sql +6 -0
- package/src/migrations/0133_project_root.sql +30 -0
- package/src/migrations/0134_org_cloud_network_delta.sql +38 -0
- package/src/migrations/0135_run_execution_claim.sql +2 -0
- package/src/migrations/0136_run_recovery_cursor.sql +6 -0
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/src/migrations/0145_org_network_allowances.sql +12 -0
- package/src/migrations/0146_permission_authority_epochs.sql +6 -0
- package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
- package/src/migrations/0148_first_message_request_hash.sql +2 -0
- package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
- package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
- package/src/migrations/0151_starting_execution_grants.sql +8 -0
- package/src/migrations/0152_background_launch_identity.sql +66 -0
- package/src/migrations/0153_background_cancel_requester.sql +13 -0
- package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
- package/src/migrations/0155_device_instance_generations.sql +30 -0
- package/src/migrations/0156_device_owner_report.sql +7 -0
- package/src/migrations/0157_legacy_retirement.sql +116 -0
- package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
- package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
- package/src/migrations/0160_model_usage_image_kind.sql +10 -0
- package/src/migrations/0161_file_shares.sql +35 -0
- package/src/migrations/0162_permission_call_escalation.sql +9 -0
- package/src/migrations/0163_read_attachments.sql +10 -0
- package/src/migrations/0164_platform_icons.sql +10 -0
- package/src/migrations/0165_device_network_columns.sql +50 -0
- package/src/migrations/0166_permission_grant_full_access.sql +17 -0
- package/src/migrations/0167_device_network_backfill.sql +32 -0
- package/src/migrations/0168_binding_installed_connection.sql +6 -0
- package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
- package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
- package/src/migrations/0171_account_avatar.sql +26 -0
- package/src/migrations/0172_push.sql +40 -0
- package/src/migrations/0173_push_auth_notice.sql +10 -0
- package/src/migrations/0174_marketplace_managed_username.sql +4 -0
- package/src/migrations/0175_secure_input_kind.sql +8 -0
- package/src/migrations/0176_device_report.sql +6 -0
- package/src/migrations/0177_dial_in_contract.sql +32 -0
- package/src/migrations/0178_bootstrap_run_extra.sql +17 -0
- package/src/migrations/0179_device_report_limit_text.sql +28 -0
- package/src/migrations/0180_device_instance_abandoned.sql +6 -0
- package/src/migrations/0181_connector_description.sql +3 -0
- package/src/migrations/0182_rls_policies.sql +202 -0
- package/src/migrations/0183_connectors_created_by_nullable.sql +5 -0
- package/src/migrations/0184_background_cancel_failure.sql +10 -0
- package/src/migrations/0185_channel_process_display.sql +13 -0
- package/src/migrations/0186_question_woken.sql +5 -0
- package/src/migrations/0187_device_conversation_notices.sql +35 -0
- package/src/migrations/0188_automations_rename.sql +309 -0
- package/src/migrations/0189_event_automations.sql +136 -0
- package/src/migrations/0190_file_library.sql +285 -0
- package/src/migrations/0191_file_library_copy.sql +4 -0
- package/src/migrations/0192_inbox_items.sql +50 -0
- package/src/migrations/0193_trigger_cause_handles.sql +49 -0
- package/src/migrations/0194_automation_acceptance.sql +83 -0
- package/src/migrations/0195_idle_compaction.sql +7 -0
- package/src/migrations/0196_conversation_events_compaction_summary_idx.sql +8 -0
- package/src/migrations/0197_inbox_item_localized_text.sql +8 -0
- package/src/migrations/0198_acceptance_prompt.sql +10 -0
- package/src/migrations/0199_device_loopback_grants.sql +59 -0
- package/src/migrations/0200_runs_idle_mode.sql +4 -0
- package/src/migrations/0201_tool_specs_text.sql +8 -0
- package/src/migrations/0202_connector_endpoint_changed_at.sql +1 -0
- package/src/migrations/0203_model_cache_write_pricing.sql +5 -0
- package/src/migrations/0204_device_instance_retirement_identities.sql +46 -0
- package/src/migrations/0205_device_site_grants.sql +30 -0
- package/src/migrations/0206_retire_org_extension_uploads.sql +125 -0
- package/src/migrations/0207_confirm_device_instance_destruction.sql +25 -0
- package/src/migrations/0208_convert_stored_permission_settings.sql +189 -0
- package/src/migrations/0209_onboarding_checklist.sql +5 -0
- package/src/migrations/0210_normalize_conversation_history.sql +1012 -0
- package/src/migrations/0211_pre_release_cleanup.sql +154 -0
- package/src/migrations/0212_org_security_policy.sql +234 -0
- package/src/migrations/0213_contract_org_security_policy.sql +43 -0
- package/src/migrations/0214_model_usage_price_snapshot.sql +2 -0
- package/src/migrations/0215_conversation_events_org_id.sql +48 -0
- package/src/migrations/0216_model_budget_counters.sql +24 -0
- package/src/migrations/0217_retention.sql +44 -0
- package/src/migrations/0218_data_erasure.sql +41 -0
- package/dist/background/status.d.ts +0 -35
- package/dist/background/status.js +0 -57
- package/dist/catalog/org-extension-switch.d.ts +0 -41
- package/dist/catalog/org-extension-switch.js +0 -115
- package/dist/catalog/owned-plugin-cleanup.d.ts +0 -56
- package/dist/catalog/owned-plugin-cleanup.js +0 -194
- package/dist/catalog/platform-migration.d.ts +0 -115
- package/dist/catalog/platform-migration.js +0 -583
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/devices/legacy-cleanup.job.d.ts +0 -34
- package/dist/devices/legacy-cleanup.job.js +0 -141
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/add-job-once.d.ts +0 -14
- package/dist/infra/queue/add-job-once.js +0 -16
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/local-devices/device-auth.module.d.ts +0 -7
- package/dist/local-devices/device-auth.module.js +0 -25
- package/dist/local-devices/device-routes.d.ts +0 -36
- package/dist/local-devices/device-routes.js +0 -90
- package/dist/local-devices/local-device-gateway.d.ts +0 -128
- package/dist/local-devices/local-device-gateway.js +0 -530
- package/dist/local-devices/local-device-provider.d.ts +0 -89
- package/dist/local-devices/local-device-provider.js +0 -151
- package/dist/local-devices/local-devices.module.d.ts +0 -16
- package/dist/local-devices/local-devices.module.js +0 -44
- package/dist/local-devices/relay.d.ts +0 -100
- package/dist/local-devices/relay.js +0 -373
- package/dist/local-devices/targets.d.ts +0 -28
- package/dist/local-devices/targets.js +0 -73
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/builtins/skill-write.d.ts +0 -59
- package/dist/tools/builtins/skill-write.js +0 -244
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -115
|
@@ -8,28 +8,172 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
|
-
import { connectorToolKey, parseToolKey } from "@capybara-hq/plugin-sdk";
|
|
12
|
-
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
+
import { connectorToolKey, parseToolKey, validateAllowHost, } from "@capybara-hq/plugin-sdk";
|
|
12
|
+
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
13
13
|
import { sql } from "kysely";
|
|
14
|
+
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
15
|
+
import { GIT_GRANT_SPEC_HASH, gitGrantRefusal, gitPushGrantKey, grantRefusalOf, NETWORK_GRANT_PREFIX, NETWORK_GRANT_SPEC_HASH, networkGrantRefusal, normalizeGitRepo, } from "../automations/grant-rules.js";
|
|
16
|
+
import { AutomationStore } from "../automations/store.js";
|
|
17
|
+
import { unattendedRunOf, unattendedTaskRunOf } from "../automations/unattended.js";
|
|
14
18
|
import { EventLog } from "../conversations/event-log.js";
|
|
19
|
+
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, SECURE_INPUT_MAX_FIELDS, } from "../conversations/events.js";
|
|
20
|
+
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
21
|
+
import { conversationSourceOf } from "../conversations/source.js";
|
|
22
|
+
import { siteAccessDetailHash, siteAccessInstallActive, } from "../device-access/site-access-request.js";
|
|
23
|
+
import { DeviceSiteGrants } from "../device-access/site-grants.js";
|
|
24
|
+
import { DevicesService } from "../devices/devices.service.js";
|
|
15
25
|
import { ApiError } from "../errors.js";
|
|
26
|
+
import { isExtensionEnabled } from "../extensions/enabled.js";
|
|
27
|
+
import { clipText } from "../extensions/hooks.js";
|
|
28
|
+
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
29
|
+
import { loadPeople } from "../identity/account-avatar.js";
|
|
16
30
|
import { audit } from "../identity/audit.js";
|
|
31
|
+
import { sha256Hex } from "../identity/hash.js";
|
|
17
32
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
18
33
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
19
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
34
|
+
import { queueAfterCommit, TransactionHost, withOrderedLocks, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
20
35
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
21
36
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
37
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
38
|
+
import { WithLock } from "../infra/lock/with-lock.decorator.js";
|
|
39
|
+
import { OrgLock } from "../orgs/org-lock.js";
|
|
22
40
|
import { ORG_ROLES, roleAtLeast } from "../orgs/roles.js";
|
|
41
|
+
import { checkPersonValue } from "../platform/person-fields.js";
|
|
42
|
+
import { SealedInputs } from "../platform/sealed-inputs.js";
|
|
43
|
+
import { RunResume } from "../runtime/run-jobs.js";
|
|
23
44
|
import { rootConversationOf } from "../runtime/subagents/child.js";
|
|
45
|
+
import { LoopbackGrants, LoopbackLimitError } from "../sandbox/loopback-grants.js";
|
|
46
|
+
import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
|
|
47
|
+
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
48
|
+
import { isSessionGrantableRule } from "../sandbox/review/types.js";
|
|
49
|
+
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
50
|
+
import { gitPushPolicyName, personalAuth } from "./connector-account-policies.js";
|
|
24
51
|
import { pluginDisplayNames } from "./display-names.js";
|
|
52
|
+
import { readOrgGitPushDenials, readOrgToolPolicy, } from "./org-tool-policies.js";
|
|
53
|
+
import { ToolRegistry } from "./registry.js";
|
|
25
54
|
export { APPROVAL_DENY_REASON_MAX_CHARS } from "../conversations/events.js";
|
|
26
55
|
/** `list` 一次最多返回的审批数(收件箱据此判断这个来源是否取满)。 */
|
|
27
56
|
export const APPROVALS_LIST_MAX = 100;
|
|
57
|
+
/** The hosts a network ask asked about, whichever kind it is (a loopback port ask: none). */
|
|
58
|
+
export function networkAskHosts(detail) {
|
|
59
|
+
if (detail.kind === "loopback" || detail.kind === "site")
|
|
60
|
+
return [];
|
|
61
|
+
return detail.kind === "service"
|
|
62
|
+
? [...detail.hosts]
|
|
63
|
+
: detail.hosts.map((h) => h.host);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The model-visible note written after a network ask's kept result when its run is stopped before
|
|
67
|
+
* the device owner answered (spec §6.7).
|
|
68
|
+
*/
|
|
69
|
+
export const NETWORK_ASK_CANCELLED_NOTE = "[network] The run was stopped before the user answered; access stays blocked.";
|
|
70
|
+
/** The model-visible note after a git ask's kept result when its run is stopped before the answer. */
|
|
71
|
+
export const GIT_ASK_CANCELLED_NOTE = "[git] The run was stopped before the user answered; the push was not made.";
|
|
72
|
+
/**
|
|
73
|
+
* The record without an ask's kept command result (what routes and cards may show). A secure
|
|
74
|
+
* input request shows its fields and target, never the call's input it binds.
|
|
75
|
+
*/
|
|
76
|
+
export function publicRecord(r) {
|
|
77
|
+
const strip = (d) => {
|
|
78
|
+
if (d === null)
|
|
79
|
+
return null;
|
|
80
|
+
const { result: _result, ...rest } = d;
|
|
81
|
+
return rest;
|
|
82
|
+
};
|
|
83
|
+
const { orgAskRevisions: _internalBinding, ...visible } = r;
|
|
84
|
+
return {
|
|
85
|
+
...visible,
|
|
86
|
+
// never offered, even from a row stored before the catch-all was excluded: a `command` ask
|
|
87
|
+
// remembers one concrete rule class, and a classifier ask (no rule) remembers nothing
|
|
88
|
+
scopes: r.command !== null && !isSessionGrantableRule(r.command.rule)
|
|
89
|
+
? r.scopes.filter((s) => s !== "session")
|
|
90
|
+
: r.scopes,
|
|
91
|
+
detail: strip(r.detail),
|
|
92
|
+
git: strip(r.git),
|
|
93
|
+
...(r.kind === "secure_input" && { input: null }),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Whether a tool ask's stored `detail` says the review model could not decide it. */
|
|
97
|
+
function reviewUnsureOf(detail) {
|
|
98
|
+
return typeof detail === "object" &&
|
|
99
|
+
detail !== null &&
|
|
100
|
+
detail.reviewUnsure === true
|
|
101
|
+
? { reviewUnsure: true }
|
|
102
|
+
: null;
|
|
103
|
+
}
|
|
104
|
+
/** A tool ask's file from its stored `detail` (none: the call takes no file). */
|
|
105
|
+
function fileOf(detail) {
|
|
106
|
+
if (typeof detail !== "object" || detail === null)
|
|
107
|
+
return null;
|
|
108
|
+
const f = detail.file;
|
|
109
|
+
if (typeof f !== "object" || f === null)
|
|
110
|
+
return null;
|
|
111
|
+
return { file: f };
|
|
112
|
+
}
|
|
113
|
+
/** The person fields of a secure input request from its stored `detail`. */
|
|
114
|
+
function personFieldsOf(detail) {
|
|
115
|
+
if (typeof detail !== "object" || detail === null)
|
|
116
|
+
return null;
|
|
117
|
+
const d = detail;
|
|
118
|
+
if (!Array.isArray(d.personFields) || d.personFields.length === 0 || d.target === undefined) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
personFields: d.personFields,
|
|
123
|
+
personTarget: d.target,
|
|
124
|
+
...(Array.isArray(d.leakedFields) &&
|
|
125
|
+
d.leakedFields.length > 0 && { leakedFields: d.leakedFields }),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const NETWORK_APPLIES_AT = new Set([
|
|
129
|
+
"next-command",
|
|
130
|
+
"next-use",
|
|
131
|
+
"files-reset",
|
|
132
|
+
]);
|
|
133
|
+
/** The spec hash of a network ask (no tool definition is approved). */
|
|
134
|
+
const NETWORK_ASK_SPEC_HASH = "network";
|
|
135
|
+
/** The tool key a git ask is recorded under (the push ran in a `Bash` command). */
|
|
136
|
+
export const GIT_ASK_TOOL_KEY = "Bash";
|
|
137
|
+
/** The spec hash of a git ask (no tool definition is approved). */
|
|
138
|
+
const GIT_ASK_SPEC_HASH = "git";
|
|
139
|
+
/**
|
|
140
|
+
* The tool key a command ask is recorded under (a command runs in `Bash`; a write under `Write`, a
|
|
141
|
+
* read under `Read`).
|
|
142
|
+
*/
|
|
143
|
+
export const COMMAND_ASK_TOOL_KEY = "Bash";
|
|
144
|
+
/** The spec hash of a command ask (no tool definition is approved). */
|
|
145
|
+
const COMMAND_ASK_SPEC_HASH = "command";
|
|
146
|
+
/** The tool key a file-write ask is recorded under. */
|
|
147
|
+
export const COMMAND_WRITE_TOOL_KEY = "Write";
|
|
148
|
+
/** The tool key a file-read ask is recorded under. */
|
|
149
|
+
export const COMMAND_READ_TOOL_KEY = "Read";
|
|
150
|
+
/** The tool key of a command ask of `kind`. */
|
|
151
|
+
const commandAskToolKey = (kind) => kind === "write"
|
|
152
|
+
? COMMAND_WRITE_TOOL_KEY
|
|
153
|
+
: kind === "read"
|
|
154
|
+
? COMMAND_READ_TOOL_KEY
|
|
155
|
+
: COMMAND_ASK_TOOL_KEY;
|
|
28
156
|
const notFound = () => new ApiError("approval.not_found", "Approval not found");
|
|
157
|
+
const inputsNotExpected = () => new ApiError("approval.inputs_not_expected", "The inputs name fields this approval does not ask for.");
|
|
29
158
|
const iso = (v) => new Date(v).toISOString();
|
|
30
159
|
const isRole = (v) => v !== null && ORG_ROLES.includes(v);
|
|
31
160
|
/** The scopes of an approval without stored ones: a role escalation is approved only once. */
|
|
32
161
|
const derivedScopes = (requestedFor) => requestedFor === null ? ["once"] : ["once", "session", "always"];
|
|
162
|
+
function orgAskRevisionsOf(detail) {
|
|
163
|
+
if (typeof detail !== "object" || detail === null || !("orgAskRevisions" in detail))
|
|
164
|
+
return null;
|
|
165
|
+
const rows = detail.orgAskRevisions;
|
|
166
|
+
if (!Array.isArray(rows) || rows.length === 0)
|
|
167
|
+
return null;
|
|
168
|
+
if (!rows.every((row) => typeof row === "object" &&
|
|
169
|
+
row !== null &&
|
|
170
|
+
"toolKey" in row &&
|
|
171
|
+
"rowRevision" in row &&
|
|
172
|
+
typeof row.toolKey === "string" &&
|
|
173
|
+
typeof row.rowRevision === "string"))
|
|
174
|
+
return null;
|
|
175
|
+
return { orgAskRevisions: rows };
|
|
176
|
+
}
|
|
33
177
|
function toRecord(r) {
|
|
34
178
|
return {
|
|
35
179
|
id: r.id,
|
|
@@ -38,6 +182,14 @@ function toRecord(r) {
|
|
|
38
182
|
runId: r.run_id,
|
|
39
183
|
callId: r.call_id,
|
|
40
184
|
attempt: r.attempt,
|
|
185
|
+
kind: r.kind,
|
|
186
|
+
detail: r.kind === "network" ? (r.detail ?? null) : null,
|
|
187
|
+
git: r.kind === "git" ? (r.detail ?? null) : null,
|
|
188
|
+
command: r.kind === "command" ? (r.detail ?? null) : null,
|
|
189
|
+
...(r.kind === "secure_input" && personFieldsOf(r.detail)),
|
|
190
|
+
...(r.kind === "tool" && fileOf(r.detail)),
|
|
191
|
+
...(r.kind === "tool" && reviewUnsureOf(r.detail)),
|
|
192
|
+
...(r.kind === "tool" && orgAskRevisionsOf(r.detail)),
|
|
41
193
|
toolKey: r.tool_key,
|
|
42
194
|
specHash: r.spec_hash,
|
|
43
195
|
connectorId: r.connector_id,
|
|
@@ -45,6 +197,8 @@ function toRecord(r) {
|
|
|
45
197
|
requestedFor: r.requested_for,
|
|
46
198
|
approverRole: isRole(r.approver_role) ? r.approver_role : null,
|
|
47
199
|
status: r.status,
|
|
200
|
+
supersededRevision: r.superseded_revision,
|
|
201
|
+
supersededReason: r.superseded_reason,
|
|
48
202
|
scope: r.scope,
|
|
49
203
|
decidedBy: r.decided_by,
|
|
50
204
|
decidedAt: r.decided_at === null ? null : iso(r.decided_at),
|
|
@@ -60,8 +214,11 @@ function toRecord(r) {
|
|
|
60
214
|
* - 指定了 `requested_for` → 只有那个人;
|
|
61
215
|
* - 按角色升级(`approver_role`)→ 当前角色不低于它、且不是该运行发起人的成员(发起人不能批准按角色升级到别人的请求)。
|
|
62
216
|
* agent / 服务令牌不能处理任何审批(路由动作 `approvals.decide` 仅限用户主体)。
|
|
217
|
+
* A secure input request is only ever its `requested_for` person's, never a role's.
|
|
63
218
|
*/
|
|
64
219
|
function canHandle(a, initiator, accountId, role) {
|
|
220
|
+
if (a.kind === "secure_input")
|
|
221
|
+
return a.requestedFor !== null && a.requestedFor === accountId;
|
|
65
222
|
if (a.requestedFor !== null)
|
|
66
223
|
return a.requestedFor === accountId;
|
|
67
224
|
return (a.approverRole !== null &&
|
|
@@ -73,10 +230,12 @@ function canHandle(a, initiator, accountId, role) {
|
|
|
73
230
|
* 工具调用审批:新建(loop 调用)、列出 / 查看 / 处理(HTTP),以及「以后都允许」授权的查看与撤销。
|
|
74
231
|
* 状态全部在 PG:处理决定在事务里 `SELECT … FOR UPDATE` 审批行,多副本并发处理同一审批时恰好一个生效。
|
|
75
232
|
*
|
|
76
|
-
* A decision
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
233
|
+
* A decision resumes its waiting run in the decision's transaction (`RunResume.resumeIn`, after the
|
|
234
|
+
* decided row: lock order approval, then run; transactional outbox spec §6). It is announced after
|
|
235
|
+
* the commit as the domain event `approval.decided` (exactly once: only the decision that changed
|
|
236
|
+
* the row from pending; no kernel subscriber: the IM card update is owed by the `approval_decided`
|
|
237
|
+
* append, transactional outbox spec §8.1). Events are appended in the context's transaction
|
|
238
|
+
* (`EventLog.appendIn`) and published after the commit.
|
|
80
239
|
*/
|
|
81
240
|
let ApprovalsService = class ApprovalsService {
|
|
82
241
|
db;
|
|
@@ -84,12 +243,56 @@ let ApprovalsService = class ApprovalsService {
|
|
|
84
243
|
eventLog;
|
|
85
244
|
events;
|
|
86
245
|
txHost;
|
|
87
|
-
|
|
246
|
+
automations;
|
|
247
|
+
registry;
|
|
248
|
+
lockService;
|
|
249
|
+
sandbox;
|
|
250
|
+
resumes;
|
|
251
|
+
leakCheck;
|
|
252
|
+
sealed;
|
|
253
|
+
devices;
|
|
254
|
+
permissionLocks;
|
|
255
|
+
permissionGrants;
|
|
256
|
+
loopback;
|
|
257
|
+
site;
|
|
258
|
+
orgLock;
|
|
259
|
+
extensions;
|
|
260
|
+
constructor(db, config, eventLog, events, txHost, automations,
|
|
261
|
+
/** A trial approval is kept only for a tool the task may hold as a grant (its agent's tools). */
|
|
262
|
+
registry,
|
|
263
|
+
/** One decision of a network ask at a time, across replicas. */
|
|
264
|
+
lockService,
|
|
265
|
+
/** A trial run's 「这次允许」 becomes a task grant only within the org's egress. */
|
|
266
|
+
sandbox,
|
|
267
|
+
/** A decision resumes its waiting run in the decision's transaction. */
|
|
268
|
+
resumes,
|
|
269
|
+
/** An entered person value seen in the conversation is refused (§4.5). */
|
|
270
|
+
leakCheck,
|
|
271
|
+
/** A person's entered values are sealed in the decision's transaction (§4.3). */
|
|
272
|
+
sealed,
|
|
273
|
+
/** A network ask's "add to this device's list" writes the device's own network list. */
|
|
274
|
+
devices, permissionLocks, permissionGrants,
|
|
275
|
+
/** A loopback port ask's approval writes the root conversation's grant (absent: refused). */
|
|
276
|
+
loopback, site, orgLock, extensions) {
|
|
88
277
|
this.db = db;
|
|
89
278
|
this.config = config;
|
|
90
279
|
this.eventLog = eventLog;
|
|
91
280
|
this.events = events;
|
|
92
281
|
this.txHost = txHost;
|
|
282
|
+
this.automations = automations;
|
|
283
|
+
this.registry = registry;
|
|
284
|
+
this.lockService = lockService;
|
|
285
|
+
this.sandbox = sandbox;
|
|
286
|
+
this.resumes = resumes;
|
|
287
|
+
this.leakCheck = leakCheck;
|
|
288
|
+
this.sealed = sealed;
|
|
289
|
+
this.devices = devices;
|
|
290
|
+
this.permissionLocks = permissionLocks;
|
|
291
|
+
this.permissionGrants = permissionGrants;
|
|
292
|
+
this.loopback = loopback;
|
|
293
|
+
this.site = site;
|
|
294
|
+
this.orgLock = orgLock;
|
|
295
|
+
this.extensions = extensions;
|
|
93
296
|
}
|
|
94
297
|
/**
|
|
95
298
|
* 新建 pending 审批(`expires_at` = 现在 + `tools.approvalTimeoutHours`)并写 `approval_requested`,同一事务。
|
|
@@ -113,8 +316,21 @@ let ApprovalsService = class ApprovalsService {
|
|
|
113
316
|
.selectFrom("conversations")
|
|
114
317
|
.select("id")
|
|
115
318
|
.where("id", "=", input.conversationId)
|
|
319
|
+
.where("org_id", "=", input.orgId)
|
|
116
320
|
.forUpdate()
|
|
117
321
|
.execute();
|
|
322
|
+
if (input.supersedesOrgAsk !== undefined) {
|
|
323
|
+
await t
|
|
324
|
+
.updateTable("approvals")
|
|
325
|
+
.set({ status: "superseded", superseded_reason: "The organization’s tool policy changed" })
|
|
326
|
+
.where("org_id", "=", input.orgId)
|
|
327
|
+
.where("run_id", "=", input.runId)
|
|
328
|
+
.where("call_id", "=", input.callId)
|
|
329
|
+
.where("kind", "=", "tool")
|
|
330
|
+
.where("id", "=", input.supersedesOrgAsk)
|
|
331
|
+
.where("status", "in", ["pending", "approved"])
|
|
332
|
+
.execute();
|
|
333
|
+
}
|
|
118
334
|
await t
|
|
119
335
|
.insertInto("approvals")
|
|
120
336
|
.values({
|
|
@@ -131,7 +347,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
131
347
|
requested_for: input.requestedFor,
|
|
132
348
|
approver_role: input.approverRole,
|
|
133
349
|
summary: input.summary === undefined ? null : JSON.stringify(input.summary),
|
|
134
|
-
scopes: input.scopes ?? null,
|
|
350
|
+
scopes: input.detail?.orgAskRevisions ? ["once"] : (input.scopes ?? null),
|
|
351
|
+
...(input.detail !== undefined && { detail: JSON.stringify(input.detail) }),
|
|
135
352
|
scope: null,
|
|
136
353
|
decided_by: null,
|
|
137
354
|
expires_at: sql `now() + ${hours}::integer * interval '1 hour'`,
|
|
@@ -141,6 +358,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
141
358
|
const row = await t
|
|
142
359
|
.selectFrom("approvals")
|
|
143
360
|
.selectAll()
|
|
361
|
+
.where("org_id", "=", input.orgId)
|
|
144
362
|
.where("run_id", "=", input.runId)
|
|
145
363
|
.where("call_id", "=", input.callId)
|
|
146
364
|
.where("attempt", "=", input.attempt ?? 1)
|
|
@@ -165,8 +383,513 @@ let ApprovalsService = class ApprovalsService {
|
|
|
165
383
|
]);
|
|
166
384
|
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
167
385
|
}
|
|
168
|
-
/**
|
|
169
|
-
|
|
386
|
+
/**
|
|
387
|
+
* A secure input request (profiles govern every approval, R4): a pending approval of kind
|
|
388
|
+
* `secure_input` asking `requestedFor` for the call's secret fields, expiring like a tool
|
|
389
|
+
* approval, and its `approval_requested` (the display-only `secureInput`: the target and the
|
|
390
|
+
* field paths), in one transaction. It carries no consent: scopes `["once"]`, and Submit is a
|
|
391
|
+
* decision `approve` with the values, Cancel a `deny`. The raw call input is stored for binding
|
|
392
|
+
* only and shown nowhere. Idempotent per (run, call, attempt); an attempt already held by
|
|
393
|
+
* another kind is refused.
|
|
394
|
+
*/
|
|
395
|
+
async requestSecureInput(input) {
|
|
396
|
+
const n = input.personFields.length;
|
|
397
|
+
if (n === 0 || n > SECURE_INPUT_MAX_FIELDS) {
|
|
398
|
+
throw new Error(`a secure input asks for 1 to ${SECURE_INPUT_MAX_FIELDS} fields`);
|
|
399
|
+
}
|
|
400
|
+
if (input.requestedFor.length === 0)
|
|
401
|
+
throw new Error("a secure input names its person");
|
|
402
|
+
const { record, toSeq } = await this.requestSecureInputIn(input);
|
|
403
|
+
if (toSeq !== null)
|
|
404
|
+
await this.eventLog.notify(record.conversationId, toSeq);
|
|
405
|
+
return record;
|
|
406
|
+
}
|
|
407
|
+
async requestSecureInputIn(input) {
|
|
408
|
+
const hours = this.config.get().tools.approvalTimeoutHours;
|
|
409
|
+
const t = this.db.db;
|
|
410
|
+
// the conversation row first (the append's lock), as `requestIn`
|
|
411
|
+
await t
|
|
412
|
+
.selectFrom("conversations")
|
|
413
|
+
.select("id")
|
|
414
|
+
.where("id", "=", input.conversationId)
|
|
415
|
+
.where("org_id", "=", input.orgId)
|
|
416
|
+
.forUpdate()
|
|
417
|
+
.execute();
|
|
418
|
+
const detail = { personFields: input.personFields, target: input.target };
|
|
419
|
+
const inserted = await t
|
|
420
|
+
.insertInto("approvals")
|
|
421
|
+
.values({
|
|
422
|
+
id: randomUUID(),
|
|
423
|
+
org_id: input.orgId,
|
|
424
|
+
conversation_id: input.conversationId,
|
|
425
|
+
run_id: input.runId,
|
|
426
|
+
call_id: input.callId,
|
|
427
|
+
attempt: input.attempt,
|
|
428
|
+
kind: "secure_input",
|
|
429
|
+
detail: JSON.stringify(detail),
|
|
430
|
+
tool_key: input.toolKey,
|
|
431
|
+
spec_hash: input.specHash,
|
|
432
|
+
connector_id: input.connectorId,
|
|
433
|
+
input: JSON.stringify(input.input ?? {}),
|
|
434
|
+
requested_for: input.requestedFor,
|
|
435
|
+
approver_role: null,
|
|
436
|
+
scopes: ["once"],
|
|
437
|
+
scope: null,
|
|
438
|
+
decided_by: null,
|
|
439
|
+
expires_at: sql `now() + ${hours}::integer * interval '1 hour'`,
|
|
440
|
+
})
|
|
441
|
+
.onConflict((oc) => oc.columns(["run_id", "call_id", "attempt"]).doNothing())
|
|
442
|
+
.returningAll()
|
|
443
|
+
.executeTakeFirst();
|
|
444
|
+
if (inserted === undefined) {
|
|
445
|
+
const row = await t
|
|
446
|
+
.selectFrom("approvals")
|
|
447
|
+
.selectAll()
|
|
448
|
+
.where("org_id", "=", input.orgId)
|
|
449
|
+
.where("run_id", "=", input.runId)
|
|
450
|
+
.where("call_id", "=", input.callId)
|
|
451
|
+
.where("attempt", "=", input.attempt)
|
|
452
|
+
.executeTakeFirstOrThrow();
|
|
453
|
+
if (row.kind !== "secure_input") {
|
|
454
|
+
throw new Error(`attempt ${input.attempt} of call ${input.callId} is an approval of kind ${row.kind}`);
|
|
455
|
+
}
|
|
456
|
+
return { record: toRecord(row), toSeq: null };
|
|
457
|
+
}
|
|
458
|
+
const rec = toRecord(inserted);
|
|
459
|
+
const written = await this.eventLog.appendIn(rec.conversationId, [
|
|
460
|
+
{
|
|
461
|
+
type: "approval_requested",
|
|
462
|
+
runId: rec.runId,
|
|
463
|
+
idemKey: `approval_requested:${rec.id}`,
|
|
464
|
+
payload: {
|
|
465
|
+
step: input.step,
|
|
466
|
+
callId: rec.callId,
|
|
467
|
+
approvalId: rec.id,
|
|
468
|
+
toolKey: rec.toolKey,
|
|
469
|
+
expiresAt: rec.expiresAt,
|
|
470
|
+
secureInput: { target: input.target, fields: input.personFields.map((f) => f.path) },
|
|
471
|
+
requestedFor: rec.requestedFor,
|
|
472
|
+
approverRole: null,
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
]);
|
|
476
|
+
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* A network ask (network ask-to-allow spec §6.2): a pending approval of kind `network` for the
|
|
480
|
+
* device owner, expiring like a tool approval (`tools.approvalTimeoutHours`), and its
|
|
481
|
+
* `approval_requested` (the call's tool key, the display-only `network.hosts`), in one transaction.
|
|
482
|
+
* It takes the attempt after the call's other approvals (P-D4: the command ran, so no tool
|
|
483
|
+
* approval of the call follows it). One per call: a second request returns the first.
|
|
484
|
+
*/
|
|
485
|
+
async requestNetwork(input) {
|
|
486
|
+
const hosts = networkAskHosts(input.detail);
|
|
487
|
+
if (hosts.length === 0 || hosts.length > NETWORK_ASK_MAX_HOSTS) {
|
|
488
|
+
throw new Error(`a network ask lists 1 to ${NETWORK_ASK_MAX_HOSTS} hosts`);
|
|
489
|
+
}
|
|
490
|
+
if (hosts.some((h) => h.length === 0 || h.length > NETWORK_HOST_MAX_CHARS)) {
|
|
491
|
+
throw new Error("a network ask's host is 1 to 255 characters");
|
|
492
|
+
}
|
|
493
|
+
if (input.toolKey.length === 0)
|
|
494
|
+
throw new Error("a network ask names its call's tool key");
|
|
495
|
+
// a service's ask offers only the device's own list (a run grant cannot reach its process)
|
|
496
|
+
if (input.detail.kind === "service" && input.scopes.some((k) => k !== "always")) {
|
|
497
|
+
throw new Error('a device service\'s network ask offers only "always"');
|
|
498
|
+
}
|
|
499
|
+
const scopes = new Set(input.scopes);
|
|
500
|
+
if (scopes.size === 0 ||
|
|
501
|
+
scopes.size !== input.scopes.length ||
|
|
502
|
+
[...scopes].some((k) => k !== "once" && k !== "always")) {
|
|
503
|
+
throw new Error('a network ask offers "once", "always" or both, each once');
|
|
504
|
+
}
|
|
505
|
+
if (!NETWORK_APPLIES_AT.has(input.detail.appliesAt)) {
|
|
506
|
+
throw new Error(`a network ask's appliesAt is one of ${[...NETWORK_APPLIES_AT].join(", ")}`);
|
|
507
|
+
}
|
|
508
|
+
const { record, toSeq } = await this.requestNetworkIn(input);
|
|
509
|
+
if (toSeq !== null)
|
|
510
|
+
await this.eventLog.notify(record.conversationId, toSeq);
|
|
511
|
+
return record;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* A loopback port ask (browser loopback port grants): a pending approval of kind `network` for
|
|
515
|
+
* the device owner, offering only `session`, expiring like a tool approval, and its
|
|
516
|
+
* `approval_requested` (the call's tool key, the display-only `loopback`: service, port and
|
|
517
|
+
* whether it is a database port; no `network` field), in one transaction. One per call: a
|
|
518
|
+
* second request returns the first (whatever its kind).
|
|
519
|
+
*/
|
|
520
|
+
async requestLoopback(input) {
|
|
521
|
+
const d = input.detail;
|
|
522
|
+
if (d.kind !== "loopback")
|
|
523
|
+
throw new Error("a loopback port ask has a loopback detail");
|
|
524
|
+
if (!(Number.isInteger(d.port) && d.port >= 1 && d.port <= 65535))
|
|
525
|
+
throw new Error("a loopback port ask names a port from 1 to 65535");
|
|
526
|
+
if (input.toolKey.length === 0)
|
|
527
|
+
throw new Error("a loopback port ask names its call's tool key");
|
|
528
|
+
if (!(Number.isInteger(d.attempt) && d.attempt >= 1))
|
|
529
|
+
throw new Error("a loopback port ask names the attempt that asked");
|
|
530
|
+
const { record, toSeq } = await this.requestNetworkIn({ ...input, scopes: ["session"] });
|
|
531
|
+
if (toSeq !== null)
|
|
532
|
+
await this.eventLog.notify(record.conversationId, toSeq);
|
|
533
|
+
return record;
|
|
534
|
+
}
|
|
535
|
+
async requestSiteAccess(input, recordReview) {
|
|
536
|
+
await recordReview();
|
|
537
|
+
const { record, toSeq } = await this.requestNetworkIn(input);
|
|
538
|
+
if (toSeq !== null)
|
|
539
|
+
queueAfterCommit(() => this.eventLog.notify(record.conversationId, toSeq));
|
|
540
|
+
return record;
|
|
541
|
+
}
|
|
542
|
+
async requestNetworkIn(input) {
|
|
543
|
+
const hours = this.config.get().tools.approvalTimeoutHours;
|
|
544
|
+
const t = this.db.db;
|
|
545
|
+
// Authority precedes the conversation row (as `requestIn`): it also serializes two asks of one call
|
|
546
|
+
await t
|
|
547
|
+
.selectFrom("conversations")
|
|
548
|
+
.select("id")
|
|
549
|
+
.where("id", "=", input.conversationId)
|
|
550
|
+
.where("org_id", "=", input.orgId)
|
|
551
|
+
.forUpdate()
|
|
552
|
+
.execute();
|
|
553
|
+
// only the device's owner is ever asked: never another account the caller names
|
|
554
|
+
const owner = await this.deviceOwnerOf(input.orgId, input.detail.deviceId);
|
|
555
|
+
if (owner === null || owner !== input.requestedFor) {
|
|
556
|
+
throw new Error(`a network ask is for the owner of a live device of the org (device ${input.detail.deviceId})`);
|
|
557
|
+
}
|
|
558
|
+
const existing = await this.networkForCall(input.runId, input.callId);
|
|
559
|
+
if (existing !== null)
|
|
560
|
+
return { record: existing, toSeq: null };
|
|
561
|
+
const last = await t
|
|
562
|
+
.selectFrom("approvals")
|
|
563
|
+
.select(sql `max(attempt)`.as("attempt"))
|
|
564
|
+
.where("org_id", "=", input.orgId)
|
|
565
|
+
.where("run_id", "=", input.runId)
|
|
566
|
+
.where("call_id", "=", input.callId)
|
|
567
|
+
.executeTakeFirst();
|
|
568
|
+
const row = await t
|
|
569
|
+
.insertInto("approvals")
|
|
570
|
+
.values({
|
|
571
|
+
id: randomUUID(),
|
|
572
|
+
org_id: input.orgId,
|
|
573
|
+
conversation_id: input.conversationId,
|
|
574
|
+
run_id: input.runId,
|
|
575
|
+
call_id: input.callId,
|
|
576
|
+
attempt: Number(last?.attempt ?? 0) + 1,
|
|
577
|
+
kind: "network",
|
|
578
|
+
detail: JSON.stringify(input.detail),
|
|
579
|
+
tool_key: input.toolKey,
|
|
580
|
+
spec_hash: NETWORK_ASK_SPEC_HASH,
|
|
581
|
+
connector_id: null,
|
|
582
|
+
input: JSON.stringify({}),
|
|
583
|
+
requested_for: input.requestedFor,
|
|
584
|
+
approver_role: null,
|
|
585
|
+
scopes: [...new Set(input.scopes)],
|
|
586
|
+
scope: null,
|
|
587
|
+
decided_by: null,
|
|
588
|
+
expires_at: sql `now() + ${hours}::integer * interval '1 hour'`,
|
|
589
|
+
})
|
|
590
|
+
.returningAll()
|
|
591
|
+
.executeTakeFirstOrThrow();
|
|
592
|
+
const rec = toRecord(row);
|
|
593
|
+
const written = await this.eventLog.appendIn(rec.conversationId, [
|
|
594
|
+
{
|
|
595
|
+
type: "approval_requested",
|
|
596
|
+
runId: rec.runId,
|
|
597
|
+
idemKey: `approval_requested:${rec.id}`,
|
|
598
|
+
payload: {
|
|
599
|
+
step: input.step,
|
|
600
|
+
callId: rec.callId,
|
|
601
|
+
approvalId: rec.id,
|
|
602
|
+
toolKey: rec.toolKey,
|
|
603
|
+
expiresAt: rec.expiresAt,
|
|
604
|
+
...(input.detail.kind === "loopback"
|
|
605
|
+
? {
|
|
606
|
+
loopback: {
|
|
607
|
+
service: input.detail.service,
|
|
608
|
+
port: input.detail.port,
|
|
609
|
+
database: input.detail.database,
|
|
610
|
+
},
|
|
611
|
+
}
|
|
612
|
+
: input.detail.kind === "site"
|
|
613
|
+
? {
|
|
614
|
+
site: {
|
|
615
|
+
service: input.detail.service,
|
|
616
|
+
action: input.detail.action,
|
|
617
|
+
origin: input.detail.origin,
|
|
618
|
+
},
|
|
619
|
+
}
|
|
620
|
+
: { network: { hosts: networkAskHosts(input.detail) } }),
|
|
621
|
+
requestedFor: rec.requestedFor,
|
|
622
|
+
approverRole: null,
|
|
623
|
+
},
|
|
624
|
+
},
|
|
625
|
+
]);
|
|
626
|
+
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* A git push ask (sandbox git credentials spec §7): a pending approval of kind `git` for the
|
|
630
|
+
* actor whose credential the push used, expiring like a tool approval, and its
|
|
631
|
+
* `approval_requested` (tool key `Bash`, the display-only `git` field), in one transaction. The
|
|
632
|
+
* scopes are `once` (a run grant) and, for a personal connector (the push used the actor's own
|
|
633
|
+
* connection), `always` (the actor's standing allow for the repository); an org connector's push
|
|
634
|
+
* acts as the org, so no member allow applies to it. Takes the attempt after the call's other
|
|
635
|
+
* approvals; one per call: a second request returns the first.
|
|
636
|
+
*/
|
|
637
|
+
async requestGit(input) {
|
|
638
|
+
const d = input.detail;
|
|
639
|
+
const repo = normalizeGitRepo(d.repo);
|
|
640
|
+
if (repo === null || repo !== d.repo) {
|
|
641
|
+
throw new Error(`a git ask names a normalized <owner>/<repo> (got ${d.repo})`);
|
|
642
|
+
}
|
|
643
|
+
if (d.host.length === 0 || d.host.length > NETWORK_HOST_MAX_CHARS) {
|
|
644
|
+
throw new Error("a git ask's host is 1 to 255 characters");
|
|
645
|
+
}
|
|
646
|
+
if (d.refs.length > GIT_ASK_MAX_REFS ||
|
|
647
|
+
d.refs.some((r) => r.length === 0 || r.length > GIT_REF_MAX_CHARS)) {
|
|
648
|
+
throw new Error(`a git ask lists at most ${GIT_ASK_MAX_REFS} refs of 1 to 255 characters`);
|
|
649
|
+
}
|
|
650
|
+
const { record, toSeq } = await this.requestGitIn(input);
|
|
651
|
+
if (toSeq !== null)
|
|
652
|
+
await this.eventLog.notify(record.conversationId, toSeq);
|
|
653
|
+
return record;
|
|
654
|
+
}
|
|
655
|
+
async requestGitIn(input) {
|
|
656
|
+
const hours = this.config.get().tools.approvalTimeoutHours;
|
|
657
|
+
const t = this.db.db;
|
|
658
|
+
// Authority precedes the conversation row (as `requestIn`): it also serializes two asks of one call
|
|
659
|
+
await t
|
|
660
|
+
.selectFrom("conversations")
|
|
661
|
+
.select("id")
|
|
662
|
+
.where("id", "=", input.conversationId)
|
|
663
|
+
.where("org_id", "=", input.orgId)
|
|
664
|
+
.forUpdate()
|
|
665
|
+
.execute();
|
|
666
|
+
// only a member of the org is asked, and only about a live connector of the org
|
|
667
|
+
const member = await this.roleOf(input.orgId, input.requestedFor);
|
|
668
|
+
const connector = await t
|
|
669
|
+
.selectFrom("connectors")
|
|
670
|
+
.select("auth")
|
|
671
|
+
.where("id", "=", input.connectorId)
|
|
672
|
+
.where("org_id", "=", input.orgId)
|
|
673
|
+
.where("deleted_at", "is", null)
|
|
674
|
+
.executeTakeFirst();
|
|
675
|
+
if (member === null || connector === undefined) {
|
|
676
|
+
throw new Error(`a git ask is for a member of the org about one of its connectors (connector ${input.connectorId})`);
|
|
677
|
+
}
|
|
678
|
+
const existing = await this.gitForCall(input.runId, input.callId);
|
|
679
|
+
if (existing !== null)
|
|
680
|
+
return { record: existing, toSeq: null };
|
|
681
|
+
const last = await t
|
|
682
|
+
.selectFrom("approvals")
|
|
683
|
+
.select(sql `max(attempt)`.as("attempt"))
|
|
684
|
+
.where("org_id", "=", input.orgId)
|
|
685
|
+
.where("run_id", "=", input.runId)
|
|
686
|
+
.where("call_id", "=", input.callId)
|
|
687
|
+
.executeTakeFirst();
|
|
688
|
+
const scopes = personalAuth(connector.auth) ? ["once", "always"] : ["once"];
|
|
689
|
+
const row = await t
|
|
690
|
+
.insertInto("approvals")
|
|
691
|
+
.values({
|
|
692
|
+
id: randomUUID(),
|
|
693
|
+
org_id: input.orgId,
|
|
694
|
+
conversation_id: input.conversationId,
|
|
695
|
+
run_id: input.runId,
|
|
696
|
+
call_id: input.callId,
|
|
697
|
+
attempt: Number(last?.attempt ?? 0) + 1,
|
|
698
|
+
kind: "git",
|
|
699
|
+
detail: JSON.stringify(input.detail),
|
|
700
|
+
tool_key: GIT_ASK_TOOL_KEY,
|
|
701
|
+
spec_hash: GIT_ASK_SPEC_HASH,
|
|
702
|
+
connector_id: input.connectorId,
|
|
703
|
+
input: JSON.stringify({}),
|
|
704
|
+
requested_for: input.requestedFor,
|
|
705
|
+
approver_role: null,
|
|
706
|
+
scopes,
|
|
707
|
+
scope: null,
|
|
708
|
+
decided_by: null,
|
|
709
|
+
expires_at: sql `now() + ${hours}::integer * interval '1 hour'`,
|
|
710
|
+
})
|
|
711
|
+
.returningAll()
|
|
712
|
+
.executeTakeFirstOrThrow();
|
|
713
|
+
const rec = toRecord(row);
|
|
714
|
+
const written = await this.eventLog.appendIn(rec.conversationId, [
|
|
715
|
+
{
|
|
716
|
+
type: "approval_requested",
|
|
717
|
+
runId: rec.runId,
|
|
718
|
+
idemKey: `approval_requested:${rec.id}`,
|
|
719
|
+
payload: {
|
|
720
|
+
step: input.step,
|
|
721
|
+
callId: rec.callId,
|
|
722
|
+
approvalId: rec.id,
|
|
723
|
+
toolKey: rec.toolKey,
|
|
724
|
+
expiresAt: rec.expiresAt,
|
|
725
|
+
git: { host: input.detail.host, repo: input.detail.repo, refs: input.detail.refs },
|
|
726
|
+
requestedFor: rec.requestedFor,
|
|
727
|
+
approverRole: null,
|
|
728
|
+
},
|
|
729
|
+
},
|
|
730
|
+
]);
|
|
731
|
+
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* A command review ask (auto mode spec §5.4): a pending approval of kind `command` for the
|
|
735
|
+
* device's owner, expiring like a tool approval, and its `approval_requested` (the display-only
|
|
736
|
+
* `command` field), in one transaction. The scopes are `once` always and `session` only for a
|
|
737
|
+
* rule ask (P-D2: `本会话允许同类` remembers the rule, and a classifier ask has none). It takes
|
|
738
|
+
* the attempt after the call's other approvals; one per call: a second request returns the first.
|
|
739
|
+
*/
|
|
740
|
+
async requestCommand(input) {
|
|
741
|
+
const d = input.detail;
|
|
742
|
+
if (input.scopes.length === 0 || !input.scopes.includes("once")) {
|
|
743
|
+
throw new Error('a command ask offers at least "once"');
|
|
744
|
+
}
|
|
745
|
+
if (input.scopes.includes("session") && !isSessionGrantableRule(d.rule)) {
|
|
746
|
+
throw new Error('a command ask offers "session" only for a concrete rule, never a catch-all or a classifier ask');
|
|
747
|
+
}
|
|
748
|
+
if (d.command.length === 0 || d.reason.length === 0) {
|
|
749
|
+
throw new Error("a command ask names the command and the review's reason");
|
|
750
|
+
}
|
|
751
|
+
const subject = await this.commandSubject(input.orgId, input.conversationId, input.detail.deviceId);
|
|
752
|
+
const permissionLocks = this.permissionLocks;
|
|
753
|
+
const { record, toSeq } = permissionLocks
|
|
754
|
+
? await withTransactionFencePrelude(() => permissionLocks.acquire(subject, { kind: "admit" }), () => this.requestCommandIn(input))
|
|
755
|
+
: await this.requestCommandIn(input);
|
|
756
|
+
if (toSeq !== null)
|
|
757
|
+
await this.eventLog.notify(record.conversationId, toSeq);
|
|
758
|
+
return record;
|
|
759
|
+
}
|
|
760
|
+
async requestCommandIn(input) {
|
|
761
|
+
if (input.detail.permissionCandidate) {
|
|
762
|
+
const b = input.detail.permissionCandidate.binding;
|
|
763
|
+
if (b.orgId !== input.orgId ||
|
|
764
|
+
b.conversationId !== input.conversationId ||
|
|
765
|
+
b.runId !== input.runId ||
|
|
766
|
+
b.callId !== input.callId ||
|
|
767
|
+
b.accountId !== input.requestedFor ||
|
|
768
|
+
b.deviceId !== input.detail.deviceId)
|
|
769
|
+
throw new ApiError("forbidden", "The approval does not match its exact permission candidate");
|
|
770
|
+
if (!this.permissionGrants)
|
|
771
|
+
throw new Error("Permission grants are unavailable");
|
|
772
|
+
await this.permissionGrants.assertCurrent(b);
|
|
773
|
+
}
|
|
774
|
+
const hours = this.config.get().tools.approvalTimeoutHours;
|
|
775
|
+
const t = this.db.db;
|
|
776
|
+
// Authority precedes the conversation row (as `requestIn`): it also serializes two asks of one call
|
|
777
|
+
await t
|
|
778
|
+
.selectFrom("conversations")
|
|
779
|
+
.select("id")
|
|
780
|
+
.where("id", "=", input.conversationId)
|
|
781
|
+
.where("org_id", "=", input.orgId)
|
|
782
|
+
.forUpdate()
|
|
783
|
+
.execute();
|
|
784
|
+
// only the device's owner is ever asked: never another account the caller names
|
|
785
|
+
const owner = await this.deviceOwnerOf(input.orgId, input.detail.deviceId);
|
|
786
|
+
if (owner === null || owner !== input.requestedFor) {
|
|
787
|
+
throw new Error(`a command ask is for the owner of a live device of the org (device ${input.detail.deviceId})`);
|
|
788
|
+
}
|
|
789
|
+
const existing = await this.commandForCall(input.runId, input.callId);
|
|
790
|
+
if (existing !== null &&
|
|
791
|
+
existing.status !== "superseded" &&
|
|
792
|
+
(!input.detail.permissionCandidate ||
|
|
793
|
+
existing.command?.permissionCandidate?.candidateHash ===
|
|
794
|
+
input.detail.permissionCandidate.candidateHash))
|
|
795
|
+
return { record: existing, toSeq: null };
|
|
796
|
+
const last = await t
|
|
797
|
+
.selectFrom("approvals")
|
|
798
|
+
.select(sql `max(attempt)`.as("attempt"))
|
|
799
|
+
.where("org_id", "=", input.orgId)
|
|
800
|
+
.where("run_id", "=", input.runId)
|
|
801
|
+
.where("call_id", "=", input.callId)
|
|
802
|
+
.executeTakeFirst();
|
|
803
|
+
const candidate = input.detail.permissionCandidate;
|
|
804
|
+
const detail = {
|
|
805
|
+
...input.detail,
|
|
806
|
+
...(candidate
|
|
807
|
+
? {
|
|
808
|
+
permissionScope: candidate.permissionScope,
|
|
809
|
+
candidateHash: candidate.candidateHash,
|
|
810
|
+
...(candidate.targetPath
|
|
811
|
+
? { targetPath: candidate.targetPath, path: candidate.targetPath }
|
|
812
|
+
: {}),
|
|
813
|
+
...(candidate.escalation ? { escalation: candidate.escalation } : {}),
|
|
814
|
+
}
|
|
815
|
+
: {}),
|
|
816
|
+
};
|
|
817
|
+
const row = await t
|
|
818
|
+
.insertInto("approvals")
|
|
819
|
+
.values({
|
|
820
|
+
id: randomUUID(),
|
|
821
|
+
org_id: input.orgId,
|
|
822
|
+
conversation_id: input.conversationId,
|
|
823
|
+
run_id: input.runId,
|
|
824
|
+
call_id: input.callId,
|
|
825
|
+
attempt: input.attempt ?? Number(last?.attempt ?? 0) + 1,
|
|
826
|
+
kind: "command",
|
|
827
|
+
detail: JSON.stringify(detail),
|
|
828
|
+
tool_key: commandAskToolKey(detail.kind),
|
|
829
|
+
spec_hash: COMMAND_ASK_SPEC_HASH,
|
|
830
|
+
connector_id: null,
|
|
831
|
+
input: JSON.stringify({}),
|
|
832
|
+
requested_for: input.requestedFor,
|
|
833
|
+
approver_role: null,
|
|
834
|
+
scopes: [...new Set(input.scopes)],
|
|
835
|
+
scope: null,
|
|
836
|
+
decided_by: null,
|
|
837
|
+
expires_at: sql `now() + ${hours}::integer * interval '1 hour'`,
|
|
838
|
+
})
|
|
839
|
+
.returningAll()
|
|
840
|
+
.executeTakeFirstOrThrow();
|
|
841
|
+
const rec = toRecord(row);
|
|
842
|
+
const written = await this.eventLog.appendIn(rec.conversationId, [
|
|
843
|
+
{
|
|
844
|
+
type: "approval_requested",
|
|
845
|
+
runId: rec.runId,
|
|
846
|
+
idemKey: `approval_requested:${rec.id}`,
|
|
847
|
+
payload: {
|
|
848
|
+
step: input.step,
|
|
849
|
+
callId: rec.callId,
|
|
850
|
+
approvalId: rec.id,
|
|
851
|
+
toolKey: rec.toolKey,
|
|
852
|
+
expiresAt: rec.expiresAt,
|
|
853
|
+
command: {
|
|
854
|
+
...(detail.permissionCandidate
|
|
855
|
+
? {
|
|
856
|
+
permissionScope: detail.permissionCandidate.permissionScope,
|
|
857
|
+
candidateHash: detail.permissionCandidate.candidateHash,
|
|
858
|
+
...(detail.permissionCandidate.targetPath
|
|
859
|
+
? { targetPath: detail.permissionCandidate.targetPath }
|
|
860
|
+
: {}),
|
|
861
|
+
// an escalation shows its justification and the directory the command runs in
|
|
862
|
+
...(detail.permissionCandidate.escalation
|
|
863
|
+
? {
|
|
864
|
+
escalation: detail.permissionCandidate.escalation,
|
|
865
|
+
...(detail.workingRoot !== undefined && {
|
|
866
|
+
workingRoot: detail.workingRoot,
|
|
867
|
+
}),
|
|
868
|
+
}
|
|
869
|
+
: {}),
|
|
870
|
+
}
|
|
871
|
+
: {}),
|
|
872
|
+
kind: detail.kind,
|
|
873
|
+
// the profile the call was reviewed under: the card words the ask from it, never from
|
|
874
|
+
// the kernel's English reason
|
|
875
|
+
...(detail.permissionCandidate && {
|
|
876
|
+
profile: detail.permissionCandidate.binding.profile,
|
|
877
|
+
}),
|
|
878
|
+
// the approval's detail holds the whole command; the event is display only and clamped
|
|
879
|
+
command: clipText(detail.command, COMMAND_ASK_TEXT_MAX_CHARS),
|
|
880
|
+
...(detail.path !== undefined && { path: detail.path }),
|
|
881
|
+
rule: detail.rule,
|
|
882
|
+
reason: clipText(detail.reason, COMMAND_ASK_TEXT_MAX_CHARS),
|
|
883
|
+
mode: detail.mode,
|
|
884
|
+
},
|
|
885
|
+
requestedFor: rec.requestedFor,
|
|
886
|
+
approverRole: null,
|
|
887
|
+
},
|
|
888
|
+
},
|
|
889
|
+
]);
|
|
890
|
+
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
891
|
+
}
|
|
892
|
+
/** 当前用户能处理的审批(新的在前,最多 {@link APPROVALS_LIST_MAX} 条);`status` 缺省为全部。 */ async list(orgId, accountId, status) {
|
|
170
893
|
const role = await this.roleOf(orgId, accountId);
|
|
171
894
|
const roles = role === null ? [] : ORG_ROLES.filter((r) => roleAtLeast(role, r));
|
|
172
895
|
let q = this.db
|
|
@@ -191,39 +914,510 @@ let ApprovalsService = class ApprovalsService {
|
|
|
191
914
|
.orderBy("approvals.created_at", "desc")
|
|
192
915
|
.limit(APPROVALS_LIST_MAX)
|
|
193
916
|
.execute();
|
|
194
|
-
return this.views(rows.map(toRecord));
|
|
917
|
+
return this.views(rows.map(toRecord));
|
|
918
|
+
}
|
|
919
|
+
/** 详情;当前用户不能处理的一律 `approval.not_found`(不泄露存在)。 */
|
|
920
|
+
async get(orgId, id, accountId) {
|
|
921
|
+
const row = await this.db
|
|
922
|
+
.selectFrom("approvals")
|
|
923
|
+
.innerJoin("runs", "runs.id", "approvals.run_id")
|
|
924
|
+
.selectAll("approvals")
|
|
925
|
+
.select("runs.trigger_account_id")
|
|
926
|
+
.where("approvals.id", "=", id)
|
|
927
|
+
.where("approvals.org_id", "=", orgId)
|
|
928
|
+
.executeTakeFirst();
|
|
929
|
+
if (!row)
|
|
930
|
+
throw notFound();
|
|
931
|
+
const role = await this.roleOf(orgId, accountId);
|
|
932
|
+
const rec = toRecord(row);
|
|
933
|
+
if (!canHandle(rec, row.trigger_account_id, accountId, role))
|
|
934
|
+
throw notFound();
|
|
935
|
+
const [view] = await this.views([rec]);
|
|
936
|
+
if (!view)
|
|
937
|
+
throw notFound();
|
|
938
|
+
return view;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* 处理审批:事务内 `SELECT … FOR UPDATE` 审批行并实时重读处理人角色(R5);不能处理 → `approval.not_found`,
|
|
942
|
+
* 非 pending 或已过期 → `approval.already_decided`。同一事务写状态、授权(`session` → 会话授权,
|
|
943
|
+
* `always` → 发起人 × agent × 工具)、`approval_decided` 事件(幂等键 `approval_decided:<id>`)与审计;
|
|
944
|
+
* 提交后发布事件并调用 `onDecided`。
|
|
945
|
+
*/
|
|
946
|
+
async decide(orgId, id, accountId, body, actorTokenId, via = "web") {
|
|
947
|
+
const kind = await this.db
|
|
948
|
+
.selectFrom("approvals")
|
|
949
|
+
.select("kind")
|
|
950
|
+
.where("id", "=", id)
|
|
951
|
+
.where("org_id", "=", orgId)
|
|
952
|
+
.executeTakeFirst();
|
|
953
|
+
if (!kind)
|
|
954
|
+
throw notFound();
|
|
955
|
+
if (kind.kind === "network") {
|
|
956
|
+
return this.decideNetwork(orgId, id, accountId, body, actorTokenId, via);
|
|
957
|
+
}
|
|
958
|
+
if (body.hosts !== undefined) {
|
|
959
|
+
throw new ApiError("validation_failed", "hosts are only for network asks", [
|
|
960
|
+
{ path: "hosts", message: "Only a network ask takes hosts" },
|
|
961
|
+
]);
|
|
962
|
+
}
|
|
963
|
+
if (kind.kind === "git") {
|
|
964
|
+
return this.decideGit(orgId, id, accountId, body, actorTokenId, via);
|
|
965
|
+
}
|
|
966
|
+
if (kind.kind === "command") {
|
|
967
|
+
return this.decideCommand(orgId, id, accountId, body, actorTokenId, via);
|
|
968
|
+
}
|
|
969
|
+
const outcome = await this.decideToolIn(orgId, id, accountId, body, actorTokenId, via);
|
|
970
|
+
// a leak refusal committed only the leaked paths (the approval stays pending), then refuses
|
|
971
|
+
if ("leaked" in outcome) {
|
|
972
|
+
throw new ApiError("approval.input_leaked", "This value appeared in the conversation, so it counts as leaked. Create a new one at the provider and enter that.", [{ fields: outcome.leaked }]);
|
|
973
|
+
}
|
|
974
|
+
await this.announceDecided(outcome.record, outcome.toSeq);
|
|
975
|
+
return outcome.record;
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
* A network ask's decision (network ask-to-allow spec §5.2), one at a time per ask across
|
|
979
|
+
* replicas: only the device owner (`requested_for`) decides, in a signed-in session (a personal
|
|
980
|
+
* access token is refused; the route already refuses service and embed tokens); the allowed
|
|
981
|
+
* hosts are a subset of those asked, and the scope one the ask offers (device-provider spec
|
|
982
|
+
* §6.3). `once` is a run grant (the row itself); `always` adds the hosts to the device's own
|
|
983
|
+
* network list in the decision's transaction (`DevicesService.addNetworkHostsIn`, no run grant;
|
|
984
|
+
* the command that asked is not run again and the hosts apply at the ask's `appliesAt`). For
|
|
985
|
+
* `always` the transaction opens with the device's ordered prelude (`lockNetworkAddSubject`: the
|
|
986
|
+
* owner's membership, the device row, its permission write lock) before the conversation,
|
|
987
|
+
* approval and run rows; this method's distributed lock stays outside it. Every decision
|
|
988
|
+
* resumes the run in its transaction and is announced after the commit.
|
|
989
|
+
*/
|
|
990
|
+
async decideNetwork(orgId, id, accountId, body, actorTokenId, via,
|
|
991
|
+
/** A panel grant settling the ask: approve only while that grant is still live. */
|
|
992
|
+
opts = {}) {
|
|
993
|
+
const row = await this.db
|
|
994
|
+
.selectFrom("approvals")
|
|
995
|
+
.selectAll()
|
|
996
|
+
.select(sql `expires_at <= now()`.as("expired"))
|
|
997
|
+
.where("id", "=", id)
|
|
998
|
+
.where("org_id", "=", orgId)
|
|
999
|
+
.executeTakeFirst();
|
|
1000
|
+
if (!row)
|
|
1001
|
+
throw notFound();
|
|
1002
|
+
const ask = toRecord(row);
|
|
1003
|
+
const detail = ask.detail;
|
|
1004
|
+
if (detail === null)
|
|
1005
|
+
throw new Error(`network ask ${id} has no detail`);
|
|
1006
|
+
// the device's owner now (an ownership change since the ask is honored), never anyone else
|
|
1007
|
+
const owner = await this.deviceOwnerOf(orgId, detail.deviceId);
|
|
1008
|
+
if (ask.requestedFor !== accountId || owner !== accountId) {
|
|
1009
|
+
// named only to the people the ask is shown to (the run's starter, the asked owner); any
|
|
1010
|
+
// other member learns nothing about it, as `get` (approval.not_found)
|
|
1011
|
+
const trigger = await this.db
|
|
1012
|
+
.selectFrom("runs")
|
|
1013
|
+
.select("trigger_account_id")
|
|
1014
|
+
.where("id", "=", ask.runId)
|
|
1015
|
+
.executeTakeFirst();
|
|
1016
|
+
if (accountId !== ask.requestedFor && accountId !== trigger?.trigger_account_id) {
|
|
1017
|
+
throw notFound();
|
|
1018
|
+
}
|
|
1019
|
+
const name = owner === null ? null : await this.displayNameOf(owner);
|
|
1020
|
+
throw new ApiError("approval.not_yours", `Only ${name ?? "the device's owner"} can allow network access on this device.`);
|
|
1021
|
+
}
|
|
1022
|
+
if (actorTokenId !== undefined) {
|
|
1023
|
+
throw new ApiError("auth.session_required", "Network access is decided in a signed-in session, not with a personal access token.");
|
|
1024
|
+
}
|
|
1025
|
+
if (ask.status !== "pending") {
|
|
1026
|
+
throw new ApiError("approval.already_decided", "Approval has already been decided");
|
|
1027
|
+
}
|
|
1028
|
+
if (row.expired)
|
|
1029
|
+
throw new ApiError("approval.already_decided", "Approval has expired");
|
|
1030
|
+
if (detail.kind === "loopback")
|
|
1031
|
+
return this.decideLoopback(orgId, ask, detail, accountId, body, via, opts.panelGrantOnly);
|
|
1032
|
+
if (detail.kind === "site") {
|
|
1033
|
+
if (via !== "web") {
|
|
1034
|
+
throw new ApiError("auth.session_required", "Review this site action in the signed-in web app.");
|
|
1035
|
+
}
|
|
1036
|
+
const decided = await withOrderedLocks(async () => {
|
|
1037
|
+
if (body.decision === "approve") {
|
|
1038
|
+
if (!this.orgLock)
|
|
1039
|
+
throw new ApiError("conflict", "Site approval is unavailable");
|
|
1040
|
+
await this.orgLock.lock(orgId);
|
|
1041
|
+
await this.devices.lockNetworkAddSubject(orgId, accountId, detail.deviceId);
|
|
1042
|
+
}
|
|
1043
|
+
}, () => this.decideSiteIn(orgId, ask, detail, accountId, body, via));
|
|
1044
|
+
await this.announceDecided(decided.record, decided.toSeq);
|
|
1045
|
+
return decided.record;
|
|
1046
|
+
}
|
|
1047
|
+
const asked = [...new Set(networkAskHosts(detail))];
|
|
1048
|
+
let network;
|
|
1049
|
+
if (body.decision === "approve") {
|
|
1050
|
+
const scope = body.scope ?? "once";
|
|
1051
|
+
// only what the ask offers: what the device's provider enforces (device-provider spec §6.3)
|
|
1052
|
+
if ((scope !== "once" && scope !== "always") || !ask.scopes.includes(scope)) {
|
|
1053
|
+
throw new ApiError("approval.scope_not_allowed", `Scope "${scope}" is not allowed for this approval; allowed: ${ask.scopes.join(", ")}`);
|
|
1054
|
+
}
|
|
1055
|
+
const unknown = (body.hosts ?? []).filter((h) => !asked.includes(h));
|
|
1056
|
+
if (unknown.length > 0) {
|
|
1057
|
+
throw new ApiError("validation_failed", "hosts must be among the hosts asked about", [
|
|
1058
|
+
{ path: "hosts", message: `Not asked about: ${unknown.join(", ")}` },
|
|
1059
|
+
]);
|
|
1060
|
+
}
|
|
1061
|
+
// exact hosts only: the device and the run grants never take anything else
|
|
1062
|
+
const granted = [...new Set(body.hosts ?? asked)].filter((h) => !h.startsWith("*.") && validateAllowHost(h).length === 0);
|
|
1063
|
+
if (granted.length === 0) {
|
|
1064
|
+
throw new ApiError("validation_failed", "No host to allow", [
|
|
1065
|
+
{ path: "hosts", message: "Choose at least one host" },
|
|
1066
|
+
]);
|
|
1067
|
+
}
|
|
1068
|
+
network = { wanted: granted, granted, outcome: scope, via };
|
|
1069
|
+
}
|
|
1070
|
+
else {
|
|
1071
|
+
if (body.hosts !== undefined) {
|
|
1072
|
+
throw new ApiError("validation_failed", "hosts are only given when allowing", [
|
|
1073
|
+
{ path: "hosts", message: "Only an approval takes hosts" },
|
|
1074
|
+
]);
|
|
1075
|
+
}
|
|
1076
|
+
network = { wanted: [], granted: [], outcome: null, via };
|
|
1077
|
+
}
|
|
1078
|
+
const decide = () => this.decideIn(orgId, id, accountId, body, actorTokenId, network);
|
|
1079
|
+
let decided;
|
|
1080
|
+
if (network.outcome === "always") {
|
|
1081
|
+
const granted = network.granted;
|
|
1082
|
+
// the decider is the device's owner (checked above; the prelude checks it again under the
|
|
1083
|
+
// device row's lock). The device write is the prelude's, before any conversation row: a
|
|
1084
|
+
// widening locks the device's Full access root conversations (global order device →
|
|
1085
|
+
// authority → root conversation → conversation), so it must precede the asking
|
|
1086
|
+
// conversation's row. A refusal of the decision below rolls the addition back with it.
|
|
1087
|
+
decided = await withOrderedLocks(async () => {
|
|
1088
|
+
await this.devices.lockNetworkAddSubject(orgId, accountId, detail.deviceId);
|
|
1089
|
+
await this.devices.addNetworkHostsIn(orgId, accountId, detail.deviceId, granted, via);
|
|
1090
|
+
}, decide);
|
|
1091
|
+
}
|
|
1092
|
+
else
|
|
1093
|
+
decided = await decide();
|
|
1094
|
+
await this.announceDecided(decided.record, decided.toSeq);
|
|
1095
|
+
return decided.record;
|
|
1096
|
+
}
|
|
1097
|
+
async decideSiteIn(orgId, ask, detail, accountId, body, via) {
|
|
1098
|
+
if (body.hosts !== undefined) {
|
|
1099
|
+
throw new ApiError("validation_failed", "A site action takes no hosts");
|
|
1100
|
+
}
|
|
1101
|
+
const approved = body.decision === "approve";
|
|
1102
|
+
let scope = approved ? (body.scope ?? "once") : null;
|
|
1103
|
+
if (scope !== null &&
|
|
1104
|
+
((scope !== "once" && scope !== "session") || !ask.scopes.includes(scope))) {
|
|
1105
|
+
throw new ApiError("approval.scope_not_allowed", "This site action does not offer that scope");
|
|
1106
|
+
}
|
|
1107
|
+
if (approved) {
|
|
1108
|
+
if (!this.site || !this.orgLock || !this.extensions) {
|
|
1109
|
+
throw new ApiError("conflict", "Site approval is unavailable");
|
|
1110
|
+
}
|
|
1111
|
+
const instance = this.extensions.current(detail.extension);
|
|
1112
|
+
const permissions = instance?.manifest.permissions?.deviceAccess;
|
|
1113
|
+
const active = instance !== undefined &&
|
|
1114
|
+
(await siteAccessInstallActive(this.db.db, detail.extension, instance.sha256, true));
|
|
1115
|
+
const root = await this.db
|
|
1116
|
+
.selectFrom("conversations")
|
|
1117
|
+
.select(["device_id", "account_id", "automation_id"])
|
|
1118
|
+
.where("org_id", "=", orgId)
|
|
1119
|
+
.where("id", "=", detail.rootConversationId)
|
|
1120
|
+
.where("deleted_at", "is", null)
|
|
1121
|
+
.forNoKeyUpdate()
|
|
1122
|
+
.executeTakeFirst();
|
|
1123
|
+
const unattended = await unattendedRunOf(this.db.db, this.config, orgId, ask.runId);
|
|
1124
|
+
if (root?.device_id !== detail.deviceId ||
|
|
1125
|
+
root.account_id !== accountId ||
|
|
1126
|
+
root.automation_id !== null ||
|
|
1127
|
+
(unattended !== null && !unattended.trial) ||
|
|
1128
|
+
!active ||
|
|
1129
|
+
permissions?.siteAccess !== true ||
|
|
1130
|
+
!permissions.services.some((name) => `${detail.extension}.${name}` === detail.service) ||
|
|
1131
|
+
!(await isExtensionEnabled(this.db.db, orgId, detail.extension))) {
|
|
1132
|
+
throw new ApiError("conflict", "This site action is no longer available");
|
|
1133
|
+
}
|
|
1134
|
+
if (scope === "session") {
|
|
1135
|
+
const granted = await this.site.grantIn({
|
|
1136
|
+
orgId,
|
|
1137
|
+
deviceId: detail.deviceId,
|
|
1138
|
+
serviceId: detail.service,
|
|
1139
|
+
rootConversationId: detail.rootConversationId,
|
|
1140
|
+
origin: detail.origin,
|
|
1141
|
+
action: detail.action,
|
|
1142
|
+
}, { approvalId: ask.id, actorAccountId: accountId });
|
|
1143
|
+
if (granted === null)
|
|
1144
|
+
scope = "once";
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
const decision = await this.decideTx(orgId, ask.id, accountId, scope === null ? body : { ...body, scope }, undefined, { wanted: [], granted: [], outcome: scope, via });
|
|
1148
|
+
if ("leaked" in decision)
|
|
1149
|
+
throw new Error("Unexpected site approval leak outcome");
|
|
1150
|
+
return decision;
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* A loopback port ask's decision (browser loopback port grants), under {@link decideNetwork}'s
|
|
1154
|
+
* lock and checks (the device owner, a signed-in session, still pending): an approval takes
|
|
1155
|
+
* scope `session` and no hosts. The device's ceilings are read again first; refused, the ask
|
|
1156
|
+
* stays pending (`approval.loopback_unavailable`). The grant
|
|
1157
|
+
* (`LoopbackGrants.grantIn`, source `human`, the call and the attempt that asked) is written in
|
|
1158
|
+
* the decision's transaction before its conversation, approval and run rows: the grant reads the
|
|
1159
|
+
* root conversation `FOR SHARE` and a conversation's deletion locks its runs after its own row.
|
|
1160
|
+
*/
|
|
1161
|
+
async decideLoopback(orgId, ask, detail, accountId, body, via,
|
|
1162
|
+
/**
|
|
1163
|
+
* Settled by the owner's panel grant: the grant is that live row (read `FOR SHARE` in the
|
|
1164
|
+
* decision's transaction), never a new one; a grant revoked meanwhile refuses the approval.
|
|
1165
|
+
*/
|
|
1166
|
+
panelGrantOnly = false) {
|
|
1167
|
+
if (body.hosts !== undefined) {
|
|
1168
|
+
throw new ApiError("validation_failed", "A loopback port ask takes no hosts", [
|
|
1169
|
+
{ path: "hosts", message: "A loopback port ask takes no hosts" },
|
|
1170
|
+
]);
|
|
1171
|
+
}
|
|
1172
|
+
const id = ask.id;
|
|
1173
|
+
if (body.decision !== "approve") {
|
|
1174
|
+
const network = { wanted: [], granted: [], outcome: null, via };
|
|
1175
|
+
const decided = await this.decideIn(orgId, id, accountId, body, undefined, network);
|
|
1176
|
+
await this.announceDecided(decided.record, decided.toSeq);
|
|
1177
|
+
return decided.record;
|
|
1178
|
+
}
|
|
1179
|
+
const scope = body.scope ?? "session";
|
|
1180
|
+
if (scope !== "session" || !ask.scopes.includes("session")) {
|
|
1181
|
+
throw new ApiError("approval.scope_not_allowed", `Scope "${scope}" is not allowed for this approval; allowed: ${ask.scopes.join(", ")}`);
|
|
1182
|
+
}
|
|
1183
|
+
const loopback = this.loopback;
|
|
1184
|
+
if (loopback === undefined)
|
|
1185
|
+
throw new Error("Loopback grants are unavailable");
|
|
1186
|
+
const why = await loopback.refusalNow(orgId, detail.deviceId);
|
|
1187
|
+
if (why !== null) {
|
|
1188
|
+
throw new ApiError("approval.loopback_unavailable", `Port ${detail.port} on the device cannot be opened to the browser now: ${why}.`);
|
|
1189
|
+
}
|
|
1190
|
+
const conv = await this.db
|
|
1191
|
+
.selectFrom("conversations")
|
|
1192
|
+
.select("parent_conversation_id")
|
|
1193
|
+
.where("id", "=", ask.conversationId)
|
|
1194
|
+
.where("org_id", "=", orgId)
|
|
1195
|
+
.executeTakeFirst();
|
|
1196
|
+
if (!conv)
|
|
1197
|
+
throw notFound();
|
|
1198
|
+
const rootConversationId = conv.parent_conversation_id === null
|
|
1199
|
+
? ask.conversationId
|
|
1200
|
+
: await rootConversationOf(this.db.db, conv.parent_conversation_id);
|
|
1201
|
+
const network = { wanted: [], granted: [], outcome: "session", via };
|
|
1202
|
+
const decided = await this.decideLoopbackIn(orgId, id, accountId, body, network, rootConversationId, async () => {
|
|
1203
|
+
const key = {
|
|
1204
|
+
orgId,
|
|
1205
|
+
deviceId: detail.deviceId,
|
|
1206
|
+
serviceId: detail.service,
|
|
1207
|
+
rootConversationId,
|
|
1208
|
+
port: detail.port,
|
|
1209
|
+
};
|
|
1210
|
+
if (panelGrantOnly) {
|
|
1211
|
+
if ((await loopback.liveLockedIn(key)) === null)
|
|
1212
|
+
throw new ApiError("approval.loopback_unavailable", `The grant of port ${detail.port} on the device ended before this approval was settled.`);
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
await loopback.grantIn(key, {
|
|
1216
|
+
source: "human",
|
|
1217
|
+
actorAccountId: accountId,
|
|
1218
|
+
approvalId: id,
|
|
1219
|
+
call: { runId: ask.runId, callId: ask.callId, attempt: detail.attempt },
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1222
|
+
await this.announceDecided(decided.record, decided.toSeq);
|
|
1223
|
+
return decided.record;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* The owner granted a port from the browser panel (`ctx.deviceAccess.grantLoopbackPort`): the
|
|
1227
|
+
* pending loopback asks for that port of the same device service in the same conversation tree
|
|
1228
|
+
* are approved as the owner's decision (the grant they find is the panel's), so their calls run
|
|
1229
|
+
* again now instead of waiting for the approval timeout, and only while the panel's grant is
|
|
1230
|
+
* still live (a revoke in the meantime wins). An ask decided meanwhile, or one the owner may no
|
|
1231
|
+
* longer decide, is left as it is; any other failure leaves that ask pending and is returned (the
|
|
1232
|
+
* caller logs it), and the others are still settled.
|
|
1233
|
+
*/
|
|
1234
|
+
async settleLoopbackAsks(orgId, accountId, key) {
|
|
1235
|
+
const rows = await this.db
|
|
1236
|
+
.selectFrom("approvals")
|
|
1237
|
+
.innerJoin("conversations", "conversations.id", "approvals.conversation_id")
|
|
1238
|
+
.select(["approvals.id", "approvals.conversation_id", "conversations.parent_conversation_id"])
|
|
1239
|
+
.where("approvals.org_id", "=", orgId)
|
|
1240
|
+
.where("approvals.kind", "=", "network")
|
|
1241
|
+
.where("approvals.status", "=", "pending")
|
|
1242
|
+
.where("approvals.requested_for", "=", accountId)
|
|
1243
|
+
.where(sql `approvals.detail->>'kind'`, "=", "loopback")
|
|
1244
|
+
.where(sql `approvals.detail->>'deviceId'`, "=", key.deviceId)
|
|
1245
|
+
.where(sql `approvals.detail->>'service'`, "=", key.serviceId)
|
|
1246
|
+
.where(sql `approvals.detail->>'port'`, "=", String(key.port))
|
|
1247
|
+
.execute();
|
|
1248
|
+
let approved = 0;
|
|
1249
|
+
const failed = [];
|
|
1250
|
+
for (const r of rows) {
|
|
1251
|
+
try {
|
|
1252
|
+
const root = r.parent_conversation_id === null
|
|
1253
|
+
? r.conversation_id
|
|
1254
|
+
: await rootConversationOf(this.db.db, r.parent_conversation_id);
|
|
1255
|
+
if (root !== key.rootConversationId)
|
|
1256
|
+
continue;
|
|
1257
|
+
await this.decideNetwork(orgId, r.id, accountId, { decision: "approve", scope: "session" }, undefined, "web", { panelGrantOnly: true });
|
|
1258
|
+
approved += 1;
|
|
1259
|
+
}
|
|
1260
|
+
catch (e) {
|
|
1261
|
+
if (e instanceof ApiError &&
|
|
1262
|
+
["approval.already_decided", "approval.not_found", "approval.not_yours"].includes(e.code))
|
|
1263
|
+
continue;
|
|
1264
|
+
failed.push({ approvalId: r.id, err: e });
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return { approved, failed };
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* A loopback port ask's approval in one transaction: the tree's root conversation row first
|
|
1271
|
+
* (`FOR NO KEY UPDATE`, the order a run's fence takes it in), then the grant, then the decision.
|
|
1272
|
+
* Taking the root before the grant's `FOR SHARE` read and its (device, service) lock keeps one
|
|
1273
|
+
* lock order with a concurrent panel grant (root share, then that lock): without it the
|
|
1274
|
+
* decision held the root shared, the panel waited on the service lock, and the decision's
|
|
1275
|
+
* append then waited to update the root behind the panel's share (a deadlock).
|
|
1276
|
+
*/
|
|
1277
|
+
async decideLoopbackIn(orgId, id, accountId, body, network, rootConversationId, grant) {
|
|
1278
|
+
await this.db.db
|
|
1279
|
+
.selectFrom("conversations")
|
|
1280
|
+
.select("id")
|
|
1281
|
+
.where("id", "=", rootConversationId)
|
|
1282
|
+
.where("org_id", "=", orgId)
|
|
1283
|
+
.forNoKeyUpdate()
|
|
1284
|
+
.execute();
|
|
1285
|
+
try {
|
|
1286
|
+
await grant();
|
|
1287
|
+
}
|
|
1288
|
+
catch (e) {
|
|
1289
|
+
// the conversation was deleted meanwhile
|
|
1290
|
+
if (e instanceof ApiError && e.code === "conversation.not_found")
|
|
1291
|
+
throw notFound();
|
|
1292
|
+
if (e instanceof LoopbackLimitError)
|
|
1293
|
+
throw new ApiError("approval.loopback_unavailable", e.message);
|
|
1294
|
+
throw e;
|
|
1295
|
+
}
|
|
1296
|
+
const o = await this.decideTx(orgId, id, accountId, body, undefined, network);
|
|
1297
|
+
if ("leaked" in o)
|
|
1298
|
+
throw new Error(`approval ${id}: a leak outcome outside a secure input`);
|
|
1299
|
+
return o;
|
|
195
1300
|
}
|
|
196
|
-
/**
|
|
197
|
-
|
|
1301
|
+
/**
|
|
1302
|
+
* A git push ask's decision (sandbox git credentials spec §7): only the asked actor
|
|
1303
|
+
* (`requested_for`) decides, in a signed-in session (a personal access token is refused, as for
|
|
1304
|
+
* network asks); `once` is a run grant (the row itself), `always` also writes the actor's
|
|
1305
|
+
* standing allow for the repository on that host (`connector_tool_account_policies`,
|
|
1306
|
+
* `git_push:<host>/<owner>/<repo>`) in the decision's transaction. The run resumes after the
|
|
1307
|
+
* commit.
|
|
1308
|
+
*/
|
|
1309
|
+
async decideGit(orgId, id, accountId, body, actorTokenId, via) {
|
|
198
1310
|
const row = await this.db
|
|
199
1311
|
.selectFrom("approvals")
|
|
200
|
-
.
|
|
201
|
-
.
|
|
202
|
-
.
|
|
203
|
-
.where("approvals.id", "=", id)
|
|
204
|
-
.where("approvals.org_id", "=", orgId)
|
|
1312
|
+
.selectAll()
|
|
1313
|
+
.where("id", "=", id)
|
|
1314
|
+
.where("org_id", "=", orgId)
|
|
205
1315
|
.executeTakeFirst();
|
|
206
1316
|
if (!row)
|
|
207
1317
|
throw notFound();
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
1318
|
+
const ask = toRecord(row);
|
|
1319
|
+
if (ask.requestedFor !== accountId) {
|
|
1320
|
+
// named only to the people the ask is shown to (the run's starter); any other member
|
|
1321
|
+
// learns nothing about it, as `get` (approval.not_found)
|
|
1322
|
+
const trigger = await this.db
|
|
1323
|
+
.selectFrom("runs")
|
|
1324
|
+
.select("trigger_account_id")
|
|
1325
|
+
.where("id", "=", ask.runId)
|
|
1326
|
+
.executeTakeFirst();
|
|
1327
|
+
if (accountId !== trigger?.trigger_account_id)
|
|
1328
|
+
throw notFound();
|
|
1329
|
+
const name = ask.requestedFor === null ? null : await this.displayNameOf(ask.requestedFor);
|
|
1330
|
+
throw new ApiError("approval.not_yours", `Only ${name ?? "the person whose connection the push used"} can allow this push.`);
|
|
1331
|
+
}
|
|
1332
|
+
if (actorTokenId !== undefined) {
|
|
1333
|
+
throw new ApiError("auth.session_required", "Git pushes are decided in a signed-in session, not with a personal access token.");
|
|
1334
|
+
}
|
|
1335
|
+
let git = { outcome: null, via };
|
|
1336
|
+
if (body.decision === "approve") {
|
|
1337
|
+
const scope = body.scope ?? "once";
|
|
1338
|
+
if (scope === "session" || !ask.scopes.includes(scope)) {
|
|
1339
|
+
throw new ApiError("approval.scope_not_allowed", `Scope "${scope}" is not allowed for this approval; allowed: ${ask.scopes.join(", ")}`);
|
|
1340
|
+
}
|
|
1341
|
+
git = { outcome: scope, via };
|
|
1342
|
+
}
|
|
1343
|
+
const decided = await this.decideIn(orgId, id, accountId, body, actorTokenId, undefined, git);
|
|
1344
|
+
await this.announceDecided(decided.record, decided.toSeq);
|
|
1345
|
+
return decided.record;
|
|
216
1346
|
}
|
|
217
1347
|
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* `
|
|
221
|
-
*
|
|
1348
|
+
* A command review ask's decision (auto mode spec §5.4): only the device's owner (`requested_for`)
|
|
1349
|
+
* decides, in a signed-in session (a personal access token is refused, as for network asks).
|
|
1350
|
+
* `once` lets this call run; `session` is offered only for a rule ask and also records the rule as
|
|
1351
|
+
* the conversation's grant (`command:<rule>`, P-D2: 本会话允许同类 remembers the rule, never a
|
|
1352
|
+
* deny). The decision is written in its transaction; the run resumes after the commit.
|
|
222
1353
|
*/
|
|
223
|
-
async
|
|
224
|
-
const
|
|
1354
|
+
async decideCommand(orgId, id, accountId, body, actorTokenId, via) {
|
|
1355
|
+
const row = await this.db
|
|
1356
|
+
.selectFrom("approvals")
|
|
1357
|
+
.selectAll()
|
|
1358
|
+
.where("id", "=", id)
|
|
1359
|
+
.where("org_id", "=", orgId)
|
|
1360
|
+
.executeTakeFirst();
|
|
1361
|
+
if (!row)
|
|
1362
|
+
throw notFound();
|
|
1363
|
+
const ask = toRecord(row);
|
|
1364
|
+
if (ask.command === null)
|
|
1365
|
+
throw new Error(`command ask ${id} has no detail`);
|
|
1366
|
+
if (ask.requestedFor !== accountId) {
|
|
1367
|
+
// named only to the people the ask is shown to (the run's starter); any other member
|
|
1368
|
+
// learns nothing about it, as `get` (approval.not_found)
|
|
1369
|
+
const trigger = await this.db
|
|
1370
|
+
.selectFrom("runs")
|
|
1371
|
+
.select("trigger_account_id")
|
|
1372
|
+
.where("id", "=", ask.runId)
|
|
1373
|
+
.executeTakeFirst();
|
|
1374
|
+
if (accountId !== trigger?.trigger_account_id)
|
|
1375
|
+
throw notFound();
|
|
1376
|
+
const name = ask.requestedFor === null ? null : await this.displayNameOf(ask.requestedFor);
|
|
1377
|
+
throw new ApiError("approval.not_yours", `Only ${name ?? "the device's owner"} can allow this command on this device.`);
|
|
1378
|
+
}
|
|
1379
|
+
if (actorTokenId !== undefined) {
|
|
1380
|
+
throw new ApiError("auth.session_required", "Commands are decided in a signed-in session, not with a personal access token.");
|
|
1381
|
+
}
|
|
1382
|
+
let command = { scope: null, via };
|
|
1383
|
+
if (body.decision === "approve") {
|
|
1384
|
+
const scope = body.scope ?? "once";
|
|
1385
|
+
if (scope === "always" || !ask.scopes.includes(scope)) {
|
|
1386
|
+
throw new ApiError("approval.scope_not_allowed", `Scope "${scope}" is not allowed for this approval; allowed: ${ask.scopes.join(", ")}`);
|
|
1387
|
+
}
|
|
1388
|
+
command = { scope, via };
|
|
1389
|
+
}
|
|
1390
|
+
const decide = () => this.decideIn(orgId, id, accountId, body, actorTokenId, undefined, undefined, command);
|
|
1391
|
+
const subject = await this.commandSubject(orgId, ask.conversationId, ask.command.deviceId);
|
|
1392
|
+
const permissionLocks = this.permissionLocks;
|
|
1393
|
+
const decided = permissionLocks
|
|
1394
|
+
? await withTransactionFencePrelude(() => permissionLocks.acquire(subject, { kind: "admit" }), decide)
|
|
1395
|
+
: await decide();
|
|
1396
|
+
await this.announceDecided(decided.record, decided.toSeq);
|
|
1397
|
+
return decided.record;
|
|
1398
|
+
}
|
|
1399
|
+
async commandSubject(orgId, conversationId, deviceId) {
|
|
1400
|
+
return {
|
|
1401
|
+
orgId,
|
|
1402
|
+
deviceId,
|
|
1403
|
+
rootConversationId: await rootConversationOf(this.db.db, conversationId),
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
/** The owner of a live device of the org (null: none, deleted, or of another org). */
|
|
1407
|
+
async deviceOwnerOf(orgId, deviceId) {
|
|
1408
|
+
const d = await this.db
|
|
1409
|
+
.selectFrom("devices")
|
|
1410
|
+
.select("owner_account_id")
|
|
1411
|
+
.where("id", "=", deviceId)
|
|
1412
|
+
.where("org_id", "=", orgId)
|
|
1413
|
+
.where("deleted_at", "is", null)
|
|
1414
|
+
.executeTakeFirst();
|
|
1415
|
+
return d?.owner_account_id ?? null;
|
|
1416
|
+
}
|
|
1417
|
+
/** After the commit: the decision's events reach the page, the run's waits and IM delivery. */
|
|
1418
|
+
async announceDecided(record, toSeq) {
|
|
225
1419
|
await this.eventLog.notify(record.conversationId, toSeq);
|
|
226
|
-
//
|
|
1420
|
+
// its IM delivery is enqueued (handler failures are logged); the run resumed in the decision
|
|
227
1421
|
await this.events.emit("approval.decided", {
|
|
228
1422
|
id: record.id,
|
|
229
1423
|
orgId: record.orgId,
|
|
@@ -231,12 +1425,45 @@ let ApprovalsService = class ApprovalsService {
|
|
|
231
1425
|
runId: record.runId,
|
|
232
1426
|
status: record.status === "approved" ? "approved" : "denied",
|
|
233
1427
|
});
|
|
234
|
-
|
|
1428
|
+
}
|
|
1429
|
+
/** An account's display name (null when unknown). */
|
|
1430
|
+
async displayNameOf(accountId) {
|
|
1431
|
+
const a = await this.db
|
|
1432
|
+
.selectFrom("accounts")
|
|
1433
|
+
.select("display_name")
|
|
1434
|
+
.where("id", "=", accountId)
|
|
1435
|
+
.executeTakeFirst();
|
|
1436
|
+
return a?.display_name ?? null;
|
|
235
1437
|
}
|
|
236
1438
|
// its own transaction (as the legacy one was): `approval.decided` is emitted only after the
|
|
237
1439
|
// decision committed, even when a caller has a transaction open
|
|
238
|
-
|
|
1440
|
+
decideIn(orgId, id, accountId, body, actorTokenId, network, git, command) {
|
|
1441
|
+
return this.decideTx(orgId, id, accountId, body, actorTokenId, network, git, command).then((o) => {
|
|
1442
|
+
// only a secure input takes inputs (refused for every other kind before)
|
|
1443
|
+
if ("leaked" in o) {
|
|
1444
|
+
throw new Error(`approval ${id}: a leak outcome outside a secure input request`);
|
|
1445
|
+
}
|
|
1446
|
+
return o;
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* A tool ask's or a secure input's decision in its own transaction. For a secure input, a leak
|
|
1451
|
+
* refusal commits the leaked paths in `detail.leakedFields` and returns them (the caller refuses
|
|
1452
|
+
* after the commit, the request still pending); the same transaction cannot both keep that write
|
|
1453
|
+
* and throw.
|
|
1454
|
+
*/
|
|
1455
|
+
decideToolIn(orgId, id, accountId, body, actorTokenId, via) {
|
|
1456
|
+
return this.decideTx(orgId, id, accountId, body, actorTokenId, undefined, undefined, undefined, via);
|
|
1457
|
+
}
|
|
1458
|
+
/**
|
|
1459
|
+
* A decision in the caller's transaction: lock order conversation → approval → run (the resume).
|
|
1460
|
+
* Refuses (`approval.already_decided`, `approval.not_found`, …) before any write.
|
|
1461
|
+
*/
|
|
1462
|
+
async decideTx(orgId, id, accountId, body, actorTokenId, network, git, command, via = "web") {
|
|
239
1463
|
const t = this.db.db;
|
|
1464
|
+
// lock order: the conversation, the approval, then the run (as a stop of the waiting run)
|
|
1465
|
+
if (!(await this.lockConversationOf(id, orgId)))
|
|
1466
|
+
throw notFound();
|
|
240
1467
|
const locked = await t
|
|
241
1468
|
.selectFrom("approvals")
|
|
242
1469
|
.selectAll()
|
|
@@ -267,9 +1494,89 @@ let ApprovalsService = class ApprovalsService {
|
|
|
267
1494
|
if (locked.expired) {
|
|
268
1495
|
throw new ApiError("approval.already_decided", "Approval has expired");
|
|
269
1496
|
}
|
|
1497
|
+
// a network ask is decided only through decideNetwork (its policy op went first), a git ask
|
|
1498
|
+
// only through decideGit, a command ask only through decideCommand
|
|
1499
|
+
if ((before.kind === "network") !== (network !== undefined) ||
|
|
1500
|
+
(before.kind === "git") !== (git !== undefined) ||
|
|
1501
|
+
(before.kind === "command") !== (command !== undefined)) {
|
|
1502
|
+
throw new Error(`approval ${id} is of kind ${before.kind}`);
|
|
1503
|
+
}
|
|
1504
|
+
if (before.command?.permissionCandidate) {
|
|
1505
|
+
if (!this.permissionGrants)
|
|
1506
|
+
throw new Error("Permission grants are unavailable");
|
|
1507
|
+
await this.permissionGrants.assertCurrent(before.command.permissionCandidate.binding);
|
|
1508
|
+
}
|
|
270
1509
|
const approved = body.decision === "approve";
|
|
1510
|
+
if (approved && before.orgAskRevisions && actorTokenId !== undefined) {
|
|
1511
|
+
throw new ApiError("auth.session_required", "A fixed organization ask must be confirmed by a person");
|
|
1512
|
+
}
|
|
1513
|
+
// only a secure input request takes values
|
|
1514
|
+
const person = before.kind === "secure_input" ? before.personFields : undefined;
|
|
1515
|
+
if (body.inputs !== undefined && (person === undefined || !approved)) {
|
|
1516
|
+
throw inputsNotExpected();
|
|
1517
|
+
}
|
|
1518
|
+
// a secure input (platform web parity spec §4.2, §4.3, R5; profiles govern every approval R4):
|
|
1519
|
+
// submitted only by its person, in a web session, with every asked value, valid and never seen in the
|
|
1520
|
+
// conversation; the values are sealed before the status changes. A deny takes no values.
|
|
1521
|
+
let inputsProvided;
|
|
1522
|
+
if (person !== undefined && approved) {
|
|
1523
|
+
if (actorTokenId !== undefined) {
|
|
1524
|
+
throw new ApiError("auth.session_required", "Values for this approval are entered in a signed-in web session, not with a personal access token.");
|
|
1525
|
+
}
|
|
1526
|
+
if (via === "im") {
|
|
1527
|
+
throw new ApiError("auth.session_required", "This approval asks for values entered on the web; it cannot be approved from IM.");
|
|
1528
|
+
}
|
|
1529
|
+
if (before.requestedFor !== accountId)
|
|
1530
|
+
throw notFound();
|
|
1531
|
+
const inputs = body.inputs ?? {};
|
|
1532
|
+
const asked = new Set(person.map((f) => f.path));
|
|
1533
|
+
if (Object.keys(inputs).some((p) => !asked.has(p)))
|
|
1534
|
+
throw inputsNotExpected();
|
|
1535
|
+
const problems = person.flatMap((f) => {
|
|
1536
|
+
const v = Object.hasOwn(inputs, f.path) ? inputs[f.path] : undefined;
|
|
1537
|
+
const problem = v === undefined ? `${f.label.en} is required.` : checkPersonValue(f, v);
|
|
1538
|
+
return problem === null ? [] : [{ path: f.path, problem }];
|
|
1539
|
+
});
|
|
1540
|
+
if (problems.length > 0) {
|
|
1541
|
+
throw new ApiError("approval.inputs_invalid", "Some entered values are not valid.", [
|
|
1542
|
+
{ fields: problems },
|
|
1543
|
+
]);
|
|
1544
|
+
}
|
|
1545
|
+
// a read in the decision's transaction: one indexed scan of the conversation tree per value
|
|
1546
|
+
const leaked = await this.leakCheck.leaked(before.conversationId, inputs);
|
|
1547
|
+
if (leaked.length > 0) {
|
|
1548
|
+
await t
|
|
1549
|
+
.updateTable("approvals")
|
|
1550
|
+
.set({
|
|
1551
|
+
detail: JSON.stringify({
|
|
1552
|
+
...locked.detail,
|
|
1553
|
+
leakedFields: [...new Set([...(before.leakedFields ?? []), ...leaked])],
|
|
1554
|
+
}),
|
|
1555
|
+
})
|
|
1556
|
+
.where("id", "=", id)
|
|
1557
|
+
.where("org_id", "=", orgId)
|
|
1558
|
+
.execute();
|
|
1559
|
+
return { leaked };
|
|
1560
|
+
}
|
|
1561
|
+
await this.sealed.sealIn({
|
|
1562
|
+
approvalId: id,
|
|
1563
|
+
recipientAccountId: accountId,
|
|
1564
|
+
conversationId: before.conversationId,
|
|
1565
|
+
runId: before.runId,
|
|
1566
|
+
callId: before.callId,
|
|
1567
|
+
}, inputs);
|
|
1568
|
+
inputsProvided = person.map((f) => f.path);
|
|
1569
|
+
}
|
|
271
1570
|
const reason = approved ? undefined : body.reason?.trim() || undefined;
|
|
272
|
-
const scope = approved
|
|
1571
|
+
const scope = !approved
|
|
1572
|
+
? null
|
|
1573
|
+
: git !== undefined
|
|
1574
|
+
? (git.outcome ?? "once")
|
|
1575
|
+
: command !== undefined
|
|
1576
|
+
? (command.scope ?? "once")
|
|
1577
|
+
: network === undefined
|
|
1578
|
+
? (body.scope ?? "once")
|
|
1579
|
+
: (network.outcome ?? "once");
|
|
273
1580
|
// 按角色升级的批准只对这一次有效:授权记在发起人名下会让其以后绕过角色要求
|
|
274
1581
|
if (scope !== null && scope !== "once" && before.requestedFor === null) {
|
|
275
1582
|
throw new ApiError("validation_failed", 'Only scope "once" is allowed for role-escalated approvals', [{ path: "scope", message: 'Only "once" is allowed for role-escalated approvals' }]);
|
|
@@ -279,6 +1586,13 @@ let ApprovalsService = class ApprovalsService {
|
|
|
279
1586
|
if (scope !== null && !before.scopes.includes(scope)) {
|
|
280
1587
|
throw new ApiError("approval.scope_not_allowed", `Scope "${scope}" is not allowed for this approval; allowed: ${before.scopes.join(", ")}`);
|
|
281
1588
|
}
|
|
1589
|
+
// 本会话允许同类 remembers one concrete rule class: a catch-all (`unsure.*`) or a classifier
|
|
1590
|
+
// ask (no rule) never writes a `command:` grant, even from a row offered it before the fix
|
|
1591
|
+
if (command !== undefined &&
|
|
1592
|
+
scope === "session" &&
|
|
1593
|
+
!isSessionGrantableRule(before.command?.rule ?? null)) {
|
|
1594
|
+
throw new ApiError("approval.scope_not_allowed", 'Scope "session" is not allowed for a command with no concrete rule');
|
|
1595
|
+
}
|
|
282
1596
|
const updated = await t
|
|
283
1597
|
.updateTable("approvals")
|
|
284
1598
|
.set({
|
|
@@ -287,29 +1601,72 @@ let ApprovalsService = class ApprovalsService {
|
|
|
287
1601
|
decided_by: accountId,
|
|
288
1602
|
decided_at: sql `now()`,
|
|
289
1603
|
deny_reason: reason ?? null,
|
|
1604
|
+
...(network?.outcome != null &&
|
|
1605
|
+
before.detail !== null && {
|
|
1606
|
+
// what took effect; run grants read grantedHosts (a loopback port ask: its grant row)
|
|
1607
|
+
detail: JSON.stringify((before.detail.kind === "loopback"
|
|
1608
|
+
? { ...before.detail, outcome: "session" }
|
|
1609
|
+
: before.detail.kind === "site"
|
|
1610
|
+
? {
|
|
1611
|
+
...before.detail,
|
|
1612
|
+
outcome: network.outcome === "session" ? "session" : "once",
|
|
1613
|
+
}
|
|
1614
|
+
: {
|
|
1615
|
+
...before.detail,
|
|
1616
|
+
grantedHosts: network.granted,
|
|
1617
|
+
outcome: network.outcome === "always" ? "always" : "once",
|
|
1618
|
+
})),
|
|
1619
|
+
}),
|
|
1620
|
+
...(git?.outcome != null &&
|
|
1621
|
+
before.git !== null && {
|
|
1622
|
+
detail: JSON.stringify({ ...before.git, outcome: git.outcome }),
|
|
1623
|
+
}),
|
|
290
1624
|
})
|
|
291
1625
|
.where("id", "=", id)
|
|
1626
|
+
.where("org_id", "=", orgId)
|
|
292
1627
|
.returningAll()
|
|
293
1628
|
.executeTakeFirstOrThrow();
|
|
1629
|
+
if (approved && before.command?.permissionCandidate) {
|
|
1630
|
+
if (!this.permissionGrants)
|
|
1631
|
+
throw new Error("Permission grants are unavailable");
|
|
1632
|
+
await this.permissionGrants.issueLocked(before.command.permissionCandidate, {
|
|
1633
|
+
source: "human",
|
|
1634
|
+
approvalId: id,
|
|
1635
|
+
decidedBy: accountId,
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
294
1638
|
// 授权绑定所批准的定义指纹与来源连接器(同 slug 重新安装的连接器 id 不同,不继承)
|
|
295
1639
|
const hash = before.specHash;
|
|
296
1640
|
const connectorId = before.connectorId;
|
|
297
|
-
if (
|
|
1641
|
+
if (network !== undefined) {
|
|
1642
|
+
// a network ask grants nothing of the tool kind: its run grant is the row itself (`once`);
|
|
1643
|
+
// `always` added the hosts to the device's list in the decision's prelude
|
|
1644
|
+
}
|
|
1645
|
+
else if (git !== undefined) {
|
|
1646
|
+
// a git ask's run grant is the row itself; `always` is the actor's standing allow for the
|
|
1647
|
+
// repository on the connector (a row the connector's deletion removes with it)
|
|
1648
|
+
if (git.outcome === "always" && before.git !== null && connectorId !== null) {
|
|
1649
|
+
await this.allowRepoIn(orgId, connectorId, accountId, before.git.host, before.git.repo);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
else if (scope === "session") {
|
|
298
1653
|
// a sub-agent's grant is the root conversation's (agent map spec §7): the root and every
|
|
299
|
-
// agent of its tree, at any depth, are not asked again for the same call
|
|
1654
|
+
// agent of its tree, at any depth, are not asked again for the same call. A command ask
|
|
1655
|
+
// remembers the rule hit, not the command (auto mode spec §5.4, P-D2).
|
|
300
1656
|
await t
|
|
301
1657
|
.insertInto("conversation_tool_grants")
|
|
302
1658
|
.values({
|
|
303
1659
|
conversation_id: ctx.parent_conversation_id === null
|
|
304
1660
|
? before.conversationId
|
|
305
1661
|
: await rootConversationOf(t, ctx.parent_conversation_id),
|
|
306
|
-
tool_key: before.toolKey,
|
|
307
|
-
spec_hash: hash,
|
|
308
|
-
connector_id: connectorId,
|
|
1662
|
+
tool_key: command !== undefined ? `command:${before.command?.rule ?? ""}` : before.toolKey,
|
|
1663
|
+
spec_hash: command !== undefined ? COMMAND_ASK_SPEC_HASH : hash,
|
|
1664
|
+
connector_id: command !== undefined ? null : connectorId,
|
|
309
1665
|
})
|
|
310
|
-
.onConflict((oc) => oc
|
|
311
|
-
|
|
312
|
-
|
|
1666
|
+
.onConflict((oc) => oc.columns(["conversation_id", "tool_key"]).doUpdateSet({
|
|
1667
|
+
spec_hash: command !== undefined ? COMMAND_ASK_SPEC_HASH : hash,
|
|
1668
|
+
connector_id: command !== undefined ? null : connectorId,
|
|
1669
|
+
}))
|
|
313
1670
|
.execute();
|
|
314
1671
|
}
|
|
315
1672
|
else if (scope === "always" && before.requestedFor !== null) {
|
|
@@ -330,6 +1687,21 @@ let ApprovalsService = class ApprovalsService {
|
|
|
330
1687
|
}))
|
|
331
1688
|
.execute();
|
|
332
1689
|
}
|
|
1690
|
+
if (approved &&
|
|
1691
|
+
scope !== null &&
|
|
1692
|
+
network === undefined &&
|
|
1693
|
+
git === undefined &&
|
|
1694
|
+
command === undefined) {
|
|
1695
|
+
await this.keepTrialGrant(before, accountId);
|
|
1696
|
+
}
|
|
1697
|
+
// "Allow once" of a push in a trial run: the task's grant for that repository; a standing
|
|
1698
|
+
// allow needs none (the member's policy already allows it)
|
|
1699
|
+
if (git?.outcome === "once")
|
|
1700
|
+
await this.keepTrialGitGrant(before, accountId);
|
|
1701
|
+
// "Allow once" in a trial run: the task's grants (network ask-to-allow spec §8.1)
|
|
1702
|
+
if (network?.outcome === "once" && before.detail?.kind !== "site") {
|
|
1703
|
+
await this.keepTrialNetworkGrant(before, accountId, network.granted);
|
|
1704
|
+
}
|
|
333
1705
|
const written = await this.eventLog.appendIn(before.conversationId, [
|
|
334
1706
|
{
|
|
335
1707
|
type: "approval_decided",
|
|
@@ -342,9 +1714,107 @@ let ApprovalsService = class ApprovalsService {
|
|
|
342
1714
|
...(scope !== null && { scope }),
|
|
343
1715
|
byAccountId: accountId,
|
|
344
1716
|
...(reason !== undefined && { reason }),
|
|
1717
|
+
...(inputsProvided !== undefined && { inputsProvided }),
|
|
345
1718
|
},
|
|
346
1719
|
},
|
|
347
1720
|
]);
|
|
1721
|
+
if (network !== undefined && before.detail?.kind === "loopback") {
|
|
1722
|
+
// an approval's grant audited itself (`device.loopback_granted`, with this approval's id)
|
|
1723
|
+
if (!approved) {
|
|
1724
|
+
await audit(t, {
|
|
1725
|
+
actorAccountId: accountId,
|
|
1726
|
+
orgId,
|
|
1727
|
+
action: "device.network_denied",
|
|
1728
|
+
target: before.detail.deviceId,
|
|
1729
|
+
detail: {
|
|
1730
|
+
approvalId: id,
|
|
1731
|
+
deviceId: before.detail.deviceId,
|
|
1732
|
+
serviceId: before.detail.service,
|
|
1733
|
+
port: before.detail.port,
|
|
1734
|
+
outcome: "denied",
|
|
1735
|
+
by: accountId,
|
|
1736
|
+
via: network.via,
|
|
1737
|
+
conversationId: before.conversationId,
|
|
1738
|
+
runId: before.runId,
|
|
1739
|
+
...(reason !== undefined && { reason }),
|
|
1740
|
+
},
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
await this.resumes.resumeIn(before.runId, id);
|
|
1744
|
+
return { record: toRecord(updated), toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
1745
|
+
}
|
|
1746
|
+
if (network !== undefined && before.detail?.kind === "site") {
|
|
1747
|
+
await audit(t, {
|
|
1748
|
+
actorAccountId: accountId,
|
|
1749
|
+
orgId,
|
|
1750
|
+
action: "device.site_access_decided",
|
|
1751
|
+
target: before.detail.deviceId,
|
|
1752
|
+
detail: {
|
|
1753
|
+
approvalId: id,
|
|
1754
|
+
action: before.detail.action,
|
|
1755
|
+
origin: before.detail.origin,
|
|
1756
|
+
detailSha256: siteAccessDetailHash(before.detail.detail),
|
|
1757
|
+
outcome: approved ? network.outcome : "denied",
|
|
1758
|
+
source: "human",
|
|
1759
|
+
},
|
|
1760
|
+
});
|
|
1761
|
+
await this.resumes.resumeIn(before.runId, id);
|
|
1762
|
+
return { record: toRecord(updated), toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
1763
|
+
}
|
|
1764
|
+
if (network !== undefined && before.detail !== null) {
|
|
1765
|
+
const asked = [...new Set(networkAskHosts(before.detail))];
|
|
1766
|
+
const refused = asked.filter((h) => !network.wanted.includes(h));
|
|
1767
|
+
await audit(t, {
|
|
1768
|
+
actorAccountId: accountId,
|
|
1769
|
+
orgId,
|
|
1770
|
+
action: approved ? "device.network_allowed" : "device.network_denied",
|
|
1771
|
+
target: before.detail.deviceId,
|
|
1772
|
+
detail: {
|
|
1773
|
+
approvalId: id,
|
|
1774
|
+
deviceId: before.detail.deviceId,
|
|
1775
|
+
hosts: approved ? network.wanted : asked,
|
|
1776
|
+
...(approved && refused.length > 0 && { refused }),
|
|
1777
|
+
scope,
|
|
1778
|
+
outcome: approved ? network.outcome : "denied",
|
|
1779
|
+
by: accountId,
|
|
1780
|
+
via: network.via,
|
|
1781
|
+
conversationId: before.conversationId,
|
|
1782
|
+
runId: before.runId,
|
|
1783
|
+
...(reason !== undefined && { reason }),
|
|
1784
|
+
},
|
|
1785
|
+
});
|
|
1786
|
+
await this.resumes.resumeIn(before.runId, id);
|
|
1787
|
+
return { record: toRecord(updated), toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
1788
|
+
}
|
|
1789
|
+
if (command !== undefined && before.command !== null) {
|
|
1790
|
+
await audit(t, {
|
|
1791
|
+
actorAccountId: accountId,
|
|
1792
|
+
...(actorTokenId !== undefined && { actorTokenId }),
|
|
1793
|
+
orgId,
|
|
1794
|
+
action: approved ? "device.command_allowed" : "device.command_denied",
|
|
1795
|
+
target: before.command.deviceId,
|
|
1796
|
+
detail: {
|
|
1797
|
+
approvalId: id,
|
|
1798
|
+
deviceId: before.command.deviceId,
|
|
1799
|
+
kind: before.command.kind,
|
|
1800
|
+
rule: before.command.rule,
|
|
1801
|
+
mode: before.command.mode,
|
|
1802
|
+
// the hash of the whole command the approval holds: an audit can match it to the text
|
|
1803
|
+
...(before.command.kind === "command" && {
|
|
1804
|
+
commandHash: sha256Hex(before.command.command),
|
|
1805
|
+
}),
|
|
1806
|
+
scope,
|
|
1807
|
+
by: accountId,
|
|
1808
|
+
via: command.via,
|
|
1809
|
+
conversationId: before.conversationId,
|
|
1810
|
+
runId: before.runId,
|
|
1811
|
+
...(reason !== undefined && { reason }),
|
|
1812
|
+
},
|
|
1813
|
+
});
|
|
1814
|
+
// The decision owes continuation in its own commit, even if this process dies immediately.
|
|
1815
|
+
await this.resumes.resumeIn(before.runId, id);
|
|
1816
|
+
return { record: toRecord(updated), toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
1817
|
+
}
|
|
348
1818
|
await audit(t, {
|
|
349
1819
|
actorAccountId: accountId,
|
|
350
1820
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
@@ -352,6 +1822,15 @@ let ApprovalsService = class ApprovalsService {
|
|
|
352
1822
|
action: "approval.decided",
|
|
353
1823
|
target: id,
|
|
354
1824
|
detail: {
|
|
1825
|
+
...(before.kind === "secure_input" && { kind: "secure_input" }),
|
|
1826
|
+
...(git !== undefined &&
|
|
1827
|
+
before.git !== null && {
|
|
1828
|
+
kind: "git",
|
|
1829
|
+
host: before.git.host,
|
|
1830
|
+
repo: before.git.repo,
|
|
1831
|
+
connectorId,
|
|
1832
|
+
via: git.via,
|
|
1833
|
+
}),
|
|
355
1834
|
toolKey: before.toolKey,
|
|
356
1835
|
conversationId: before.conversationId,
|
|
357
1836
|
runId: before.runId,
|
|
@@ -361,14 +1840,171 @@ let ApprovalsService = class ApprovalsService {
|
|
|
361
1840
|
scope,
|
|
362
1841
|
...(body.note !== undefined && { note: body.note }),
|
|
363
1842
|
...(reason !== undefined && { reason }),
|
|
1843
|
+
...(inputsProvided !== undefined && { inputsProvided }),
|
|
364
1844
|
},
|
|
365
1845
|
});
|
|
1846
|
+
// the run last (lock order: the decided row, then `runs`); a still-running run is resumed by
|
|
1847
|
+
// its suspend's re-check
|
|
1848
|
+
await this.resumes.resumeIn(before.runId, id);
|
|
366
1849
|
return { record: toRecord(updated), toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
367
1850
|
}
|
|
1851
|
+
/**
|
|
1852
|
+
* A trial run of an automation (scheduled tasks spec §7): an approval its creator granted, in
|
|
1853
|
+
* any scope, is also added to the task's grants with the approved definition's hash, so its
|
|
1854
|
+
* unattended runs do not ask again. Kept only by the rule `addGrants` applies
|
|
1855
|
+
* (`grantRefusalOf`, against the task agent's tools now): never a role-escalated approval
|
|
1856
|
+
* (`requestedFor` null, it stays `once`), one another account decided, one whose scopes never
|
|
1857
|
+
* allowed remembering (an org / platform operation: "once" only), a per-call key
|
|
1858
|
+
* (`Platform:<operation>`, a skill change among them), a fixed ask, a tool the org forbids (its key or the
|
|
1859
|
+
* call's), or a tool the task's agent does not have. In the decision's transaction.
|
|
1860
|
+
*/
|
|
1861
|
+
async keepTrialGrant(a, decidedBy) {
|
|
1862
|
+
if (a.requestedFor === null || a.requestedFor !== decidedBy)
|
|
1863
|
+
return;
|
|
1864
|
+
if (!a.scopes.includes("always"))
|
|
1865
|
+
return;
|
|
1866
|
+
const t = this.db.db;
|
|
1867
|
+
const served = await unattendedTaskRunOf(t, a.runId);
|
|
1868
|
+
if (served === null || !served.trial)
|
|
1869
|
+
return;
|
|
1870
|
+
const task = await t
|
|
1871
|
+
.selectFrom("automations as s")
|
|
1872
|
+
.innerJoin("agents as ag", "ag.id", "s.agent_id")
|
|
1873
|
+
.leftJoin("agent_versions as v", (j) => j.onRef("v.agent_id", "=", "ag.id").onRef("v.version", "=", "ag.current_version"))
|
|
1874
|
+
.select(["s.account_id", "v.definition"])
|
|
1875
|
+
.where("s.id", "=", served.taskId)
|
|
1876
|
+
.where("s.org_id", "=", a.orgId)
|
|
1877
|
+
.where("s.deleted_at", "is", null)
|
|
1878
|
+
.executeTakeFirst();
|
|
1879
|
+
if (task?.account_id !== decidedBy)
|
|
1880
|
+
return;
|
|
1881
|
+
const member = await t
|
|
1882
|
+
.selectFrom("memberships")
|
|
1883
|
+
.select("role")
|
|
1884
|
+
.where("org_id", "=", a.orgId)
|
|
1885
|
+
.where("account_id", "=", decidedBy)
|
|
1886
|
+
.executeTakeFirst();
|
|
1887
|
+
if (!member)
|
|
1888
|
+
return;
|
|
1889
|
+
const def = task.definition === null ? undefined : normalizeStoredDefinition(task.definition);
|
|
1890
|
+
const { tools } = await this.registry.forAgent(a.orgId, {
|
|
1891
|
+
disabledTools: def?.disabledTools ?? [],
|
|
1892
|
+
subagentTools: def?.subagentTools,
|
|
1893
|
+
subagents: def?.subagents,
|
|
1894
|
+
// the tools of the trial run's conversation, where the approval was asked
|
|
1895
|
+
source: await conversationSourceOf(t, a.conversationId),
|
|
1896
|
+
});
|
|
1897
|
+
const tool = tools.find((x) => x.key === a.toolKey);
|
|
1898
|
+
const orgPolicy = await readOrgToolPolicy(t, a.orgId, tool?.key ?? a.toolKey, a.toolKey, true);
|
|
1899
|
+
const why = grantRefusalOf(a.toolKey, tool, {
|
|
1900
|
+
role: member.role,
|
|
1901
|
+
orgPolicy: orgPolicy.policy,
|
|
1902
|
+
});
|
|
1903
|
+
if (why !== null)
|
|
1904
|
+
return;
|
|
1905
|
+
await this.automations.addGrant(t, served.taskId, {
|
|
1906
|
+
toolKey: a.toolKey,
|
|
1907
|
+
specHash: a.specHash,
|
|
1908
|
+
connectorId: a.connectorId,
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* A trial run of an automation (network ask-to-allow spec §8.1): the hosts its creator allowed
|
|
1913
|
+
* for this run (「这次允许」) on a network ask about one of their devices become the task's
|
|
1914
|
+
* `network:<host>` grants, each only when `networkGrantRefusal` allows it (exact host, within the
|
|
1915
|
+
* org's effective egress, the device takes remote grants). Never for an ask another account
|
|
1916
|
+
* decided or one asked of someone else. In the decision's transaction.
|
|
1917
|
+
*/
|
|
1918
|
+
async keepTrialNetworkGrant(a, decidedBy, hosts) {
|
|
1919
|
+
if (hosts.length === 0 || a.detail === null)
|
|
1920
|
+
return;
|
|
1921
|
+
if (a.requestedFor === null || a.requestedFor !== decidedBy)
|
|
1922
|
+
return;
|
|
1923
|
+
const t = this.db.db;
|
|
1924
|
+
const served = await unattendedTaskRunOf(t, a.runId);
|
|
1925
|
+
if (served === null || !served.trial)
|
|
1926
|
+
return;
|
|
1927
|
+
const task = await t
|
|
1928
|
+
.selectFrom("automations")
|
|
1929
|
+
.select("account_id")
|
|
1930
|
+
.where("id", "=", served.taskId)
|
|
1931
|
+
.where("org_id", "=", a.orgId)
|
|
1932
|
+
.where("deleted_at", "is", null)
|
|
1933
|
+
.executeTakeFirst();
|
|
1934
|
+
if (task?.account_id !== decidedBy)
|
|
1935
|
+
return;
|
|
1936
|
+
const limits = await this.sandbox.ceilingLimits(a.orgId);
|
|
1937
|
+
for (const host of hosts) {
|
|
1938
|
+
if (networkGrantRefusal(host, { limits }) !== null) {
|
|
1939
|
+
continue;
|
|
1940
|
+
}
|
|
1941
|
+
await this.automations.addGrant(t, served.taskId, {
|
|
1942
|
+
toolKey: `${NETWORK_GRANT_PREFIX}${host}`,
|
|
1943
|
+
specHash: NETWORK_GRANT_SPEC_HASH,
|
|
1944
|
+
connectorId: null,
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* The actor's standing allow for pushes to `repo` through the connector (sandbox git
|
|
1950
|
+
* credentials spec §7, 「一直允许」): a `connector_tool_account_policies` row named
|
|
1951
|
+
* `git_push:<host>/<owner>/<repo>` with policy `allow`, in the decision's transaction.
|
|
1952
|
+
*/
|
|
1953
|
+
async allowRepoIn(orgId, connectorId, accountId, host, repo) {
|
|
1954
|
+
await this.db.db
|
|
1955
|
+
.insertInto("connector_tool_account_policies")
|
|
1956
|
+
.values({
|
|
1957
|
+
org_id: orgId,
|
|
1958
|
+
connector_id: connectorId,
|
|
1959
|
+
account_id: accountId,
|
|
1960
|
+
tool_name: gitPushPolicyName(host, repo),
|
|
1961
|
+
policy: "allow",
|
|
1962
|
+
})
|
|
1963
|
+
.onConflict((oc) => oc
|
|
1964
|
+
.columns(["connector_id", "account_id", "tool_name"])
|
|
1965
|
+
.doUpdateSet({ policy: "allow", updated_at: sql `now()` }))
|
|
1966
|
+
.execute();
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* A trial run of an automation (sandbox git credentials spec §7): a push its creator allowed
|
|
1970
|
+
* for this run (「这次允许」) becomes the task's `git:push:<owner>/<repo>` grant, when
|
|
1971
|
+
* `gitGrantRefusal` allows it (the org does not forbid it). Never for an ask another account
|
|
1972
|
+
* decided or one asked of someone else. In the decision's transaction.
|
|
1973
|
+
*/
|
|
1974
|
+
async keepTrialGitGrant(a, decidedBy) {
|
|
1975
|
+
if (a.git === null)
|
|
1976
|
+
return;
|
|
1977
|
+
if (a.requestedFor === null || a.requestedFor !== decidedBy)
|
|
1978
|
+
return;
|
|
1979
|
+
const t = this.db.db;
|
|
1980
|
+
const served = await unattendedTaskRunOf(t, a.runId);
|
|
1981
|
+
if (served === null || !served.trial)
|
|
1982
|
+
return;
|
|
1983
|
+
const task = await t
|
|
1984
|
+
.selectFrom("automations")
|
|
1985
|
+
.select("account_id")
|
|
1986
|
+
.where("id", "=", served.taskId)
|
|
1987
|
+
.where("org_id", "=", a.orgId)
|
|
1988
|
+
.where("deleted_at", "is", null)
|
|
1989
|
+
.executeTakeFirst();
|
|
1990
|
+
if (task?.account_id !== decidedBy)
|
|
1991
|
+
return;
|
|
1992
|
+
const key = gitPushGrantKey(a.git.repo);
|
|
1993
|
+
const gitDenials = await readOrgGitPushDenials(t, a.orgId);
|
|
1994
|
+
if (gitGrantRefusal(key, { gitDenials }) !== null)
|
|
1995
|
+
return;
|
|
1996
|
+
await this.automations.addGrant(t, served.taskId, {
|
|
1997
|
+
toolKey: key,
|
|
1998
|
+
specHash: GIT_GRANT_SPEC_HASH,
|
|
1999
|
+
connectorId: null,
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
368
2002
|
/**
|
|
369
2003
|
* 详情,不做处理人校验(内核内部用:渠道出站投递组装 IM 审批卡片);不存在返回 null。
|
|
370
2004
|
* 不得直接回给请求方——HTTP 接口用 {@link get}。
|
|
371
2005
|
*/
|
|
2006
|
+
// org-filter: approvalId comes from an approval event payload in the conversation's own event
|
|
2007
|
+
// log (channel outbound cards), kernel-written, never caller input
|
|
372
2008
|
async describe(id) {
|
|
373
2009
|
const row = await this.db
|
|
374
2010
|
.selectFrom("approvals")
|
|
@@ -380,13 +2016,76 @@ let ApprovalsService = class ApprovalsService {
|
|
|
380
2016
|
const [view] = await this.views([toRecord(row)]);
|
|
381
2017
|
return view ?? null;
|
|
382
2018
|
}
|
|
383
|
-
/**
|
|
2019
|
+
/** 某个工具调用最近一次的工具审批(attempt 最大者,网络询问除外);没有则返回 null。 */
|
|
2020
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
2021
|
+
// never caller input
|
|
384
2022
|
async forCall(runId, callId) {
|
|
385
2023
|
const row = await this.db
|
|
386
2024
|
.selectFrom("approvals")
|
|
387
2025
|
.selectAll()
|
|
388
2026
|
.where("run_id", "=", runId)
|
|
389
2027
|
.where("call_id", "=", callId)
|
|
2028
|
+
.where("kind", "=", "tool")
|
|
2029
|
+
.orderBy("attempt", "desc")
|
|
2030
|
+
.limit(1)
|
|
2031
|
+
.executeTakeFirst();
|
|
2032
|
+
return row ? toRecord(row) : null;
|
|
2033
|
+
}
|
|
2034
|
+
/** The latest secure input request of a tool call (highest attempt); null when it has none. */
|
|
2035
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
2036
|
+
// never caller input
|
|
2037
|
+
async secureInputForCall(runId, callId) {
|
|
2038
|
+
const row = await this.db
|
|
2039
|
+
.selectFrom("approvals")
|
|
2040
|
+
.selectAll()
|
|
2041
|
+
.where("run_id", "=", runId)
|
|
2042
|
+
.where("call_id", "=", callId)
|
|
2043
|
+
.where("kind", "=", "secure_input")
|
|
2044
|
+
.orderBy("attempt", "desc")
|
|
2045
|
+
.limit(1)
|
|
2046
|
+
.executeTakeFirst();
|
|
2047
|
+
return row ? toRecord(row) : null;
|
|
2048
|
+
}
|
|
2049
|
+
/** The network ask of a tool call (at most one per call); null when it has none. */
|
|
2050
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
2051
|
+
// never caller input
|
|
2052
|
+
async networkForCall(runId, callId) {
|
|
2053
|
+
const row = await this.db
|
|
2054
|
+
.selectFrom("approvals")
|
|
2055
|
+
.selectAll()
|
|
2056
|
+
.where("run_id", "=", runId)
|
|
2057
|
+
.where("call_id", "=", callId)
|
|
2058
|
+
.where("kind", "=", "network")
|
|
2059
|
+
.orderBy("attempt", "desc")
|
|
2060
|
+
.limit(1)
|
|
2061
|
+
.executeTakeFirst();
|
|
2062
|
+
return row ? toRecord(row) : null;
|
|
2063
|
+
}
|
|
2064
|
+
/** The git push ask of a tool call (at most one per call); null when it has none. */
|
|
2065
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
2066
|
+
// never caller input
|
|
2067
|
+
async gitForCall(runId, callId) {
|
|
2068
|
+
const row = await this.db
|
|
2069
|
+
.selectFrom("approvals")
|
|
2070
|
+
.selectAll()
|
|
2071
|
+
.where("run_id", "=", runId)
|
|
2072
|
+
.where("call_id", "=", callId)
|
|
2073
|
+
.where("kind", "=", "git")
|
|
2074
|
+
.orderBy("attempt", "desc")
|
|
2075
|
+
.limit(1)
|
|
2076
|
+
.executeTakeFirst();
|
|
2077
|
+
return row ? toRecord(row) : null;
|
|
2078
|
+
}
|
|
2079
|
+
/** The command review ask of a tool call (at most one per call); null when it has none. */
|
|
2080
|
+
// org-filter: runId is the runtime's own run (a uuid) whose call the tool pipeline is handling;
|
|
2081
|
+
// never caller input
|
|
2082
|
+
async commandForCall(runId, callId) {
|
|
2083
|
+
const row = await this.db
|
|
2084
|
+
.selectFrom("approvals")
|
|
2085
|
+
.selectAll()
|
|
2086
|
+
.where("run_id", "=", runId)
|
|
2087
|
+
.where("call_id", "=", callId)
|
|
2088
|
+
.where("kind", "=", "command")
|
|
390
2089
|
.orderBy("attempt", "desc")
|
|
391
2090
|
.limit(1)
|
|
392
2091
|
.executeTakeFirst();
|
|
@@ -404,8 +2103,11 @@ let ApprovalsService = class ApprovalsService {
|
|
|
404
2103
|
}
|
|
405
2104
|
return r.record ? { outcome: r.outcome, record: r.record } : { outcome: r.outcome };
|
|
406
2105
|
}
|
|
2106
|
+
// org-filter: id is the approval of the kernel-written timeout job payload (Waits), not caller input
|
|
407
2107
|
async expireIn(id) {
|
|
408
2108
|
const t = this.db.db;
|
|
2109
|
+
if (!(await this.lockConversationOf(id)))
|
|
2110
|
+
return { outcome: "settled" };
|
|
409
2111
|
const locked = await t
|
|
410
2112
|
.selectFrom("approvals")
|
|
411
2113
|
.selectAll()
|
|
@@ -433,6 +2135,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
433
2135
|
* 在调用方的事务内(`mandatory`)取消运行的全部 pending 审批(运行在等待中被中止),各写
|
|
434
2136
|
* `approval_decided{cancelled}`(处理人为 null)。返回被取消的记录;调用方提交后发布事件。
|
|
435
2137
|
*/
|
|
2138
|
+
// org-filter: runId is the run the kernel is stopping or finishing (Waits, RunFinish), not caller
|
|
2139
|
+
// input
|
|
436
2140
|
async cancelPendingIn(runId) {
|
|
437
2141
|
const t = this.db.db;
|
|
438
2142
|
const rows = await t
|
|
@@ -457,16 +2161,41 @@ let ApprovalsService = class ApprovalsService {
|
|
|
457
2161
|
return out;
|
|
458
2162
|
}
|
|
459
2163
|
/**
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
2164
|
+
* The conversations of `orgId` holding a pending approval `accountId` is asked to decide
|
|
2165
|
+
* (`requested_for`), read without locks: offboarding locks them, by tree root first
|
|
2166
|
+
* (`lockConversationTrees`), before {@link cancelPendingFor}.
|
|
2167
|
+
*/
|
|
2168
|
+
async pendingConversationsFor(orgId, accountId) {
|
|
2169
|
+
const rows = await this.db
|
|
2170
|
+
.selectFrom("approvals")
|
|
2171
|
+
.select("conversation_id")
|
|
2172
|
+
.distinct()
|
|
2173
|
+
.where("org_id", "=", orgId)
|
|
2174
|
+
.where("requested_for", "=", accountId)
|
|
2175
|
+
.where("status", "=", "pending")
|
|
2176
|
+
.execute();
|
|
2177
|
+
return rows.map((r) => r.conversation_id);
|
|
2178
|
+
}
|
|
2179
|
+
/**
|
|
2180
|
+
* In the caller's transaction (`mandatory`; offboarding): cancels every pending approval of
|
|
2181
|
+
* `orgId` that `accountId` is asked to decide (`requested_for`) in `conversationIds`, the
|
|
2182
|
+
* conversations the caller already locked (by tree root first, `lockConversationTrees`; lock
|
|
2183
|
+
* order: conversations, then approval rows), along the same path as {@link cancelPendingIn}:
|
|
2184
|
+
* `cancelled`, `approval_decided{cancelled}` with no decider. An approval asked meanwhile in
|
|
2185
|
+
* another conversation is left to its run's stop, so no conversation is locked after a row.
|
|
2186
|
+
* Returns the cancelled records and the highest seq written per conversation; the caller
|
|
2187
|
+
* publishes after the commit.
|
|
463
2188
|
*/
|
|
464
|
-
async cancelPendingFor(orgId, accountId) {
|
|
2189
|
+
async cancelPendingFor(orgId, accountId, conversationIds) {
|
|
465
2190
|
const t = this.db.db;
|
|
2191
|
+
const convs = [...conversationIds];
|
|
2192
|
+
if (convs.length === 0)
|
|
2193
|
+
return { records: [], seqs: new Map() };
|
|
466
2194
|
const rows = await t
|
|
467
2195
|
.selectFrom("approvals")
|
|
468
2196
|
.selectAll()
|
|
469
2197
|
.where("org_id", "=", orgId)
|
|
2198
|
+
.where("conversation_id", "in", convs)
|
|
470
2199
|
.where("requested_for", "=", accountId)
|
|
471
2200
|
.where("status", "=", "pending")
|
|
472
2201
|
.orderBy("created_at")
|
|
@@ -479,6 +2208,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
479
2208
|
.updateTable("approvals")
|
|
480
2209
|
.set({ status: "cancelled", decided_at: sql `now()` })
|
|
481
2210
|
.where("id", "=", row.id)
|
|
2211
|
+
.where("org_id", "=", orgId)
|
|
482
2212
|
.returningAll()
|
|
483
2213
|
.executeTakeFirstOrThrow();
|
|
484
2214
|
const seq = await this.decidedEvent(toRecord(row), "cancelled");
|
|
@@ -487,14 +2217,131 @@ let ApprovalsService = class ApprovalsService {
|
|
|
487
2217
|
}
|
|
488
2218
|
return { records, seqs };
|
|
489
2219
|
}
|
|
490
|
-
/**
|
|
491
|
-
|
|
2220
|
+
/**
|
|
2221
|
+
* In the caller's transaction (`mandatory`; it wrote `authorAccountId`'s message in
|
|
2222
|
+
* `conversationId` and holds that conversation's row lock): the message skips the pending
|
|
2223
|
+
* network and git asks it closes (network ask-to-allow spec §6.7; a git push ask follows the
|
|
2224
|
+
* same flow, sandbox git credentials spec §7), as it skips questions: the asks of
|
|
2225
|
+
* active runs `authorAccountId` started, in the conversation and in its sub-agents'
|
|
2226
|
+
* conversations at any depth (their asks are shown in the root). Each becomes `skipped` with
|
|
2227
|
+
* `approval_decided{skipped}` by the author; access stays blocked. Returns the skipped records and
|
|
2228
|
+
* the highest seq written per conversation; the caller resumes their waiting runs in this
|
|
2229
|
+
* transaction once every skipped row is locked (`ConversationsService.skipWaitsIn`), and notifies
|
|
2230
|
+
* and emits the domain event `approval.decided{skipped}` after the commit (its IM card update is
|
|
2231
|
+
* owed by the append, transactional outbox spec §8.1).
|
|
2232
|
+
*/
|
|
2233
|
+
// org-filter: conversationId is the conversation the caller wrote the author's message in and
|
|
2234
|
+
// holds locked (ConversationsService, checked in its org); the tree is its sub-agents'
|
|
2235
|
+
// conversations, and every row below is read from that tree
|
|
2236
|
+
async skipNetworkIn(conversationId, authorAccountId) {
|
|
2237
|
+
const t = this.db.db;
|
|
2238
|
+
const tree = await this.subtreeOf(conversationId);
|
|
2239
|
+
// the sub-agents' conversations with a pending ask first, in id order (lock order:
|
|
2240
|
+
// conversation, then approval rows; the caller holds `conversationId`'s already)
|
|
2241
|
+
const convs = await this.lockConversations(t
|
|
2242
|
+
.selectFrom("approvals")
|
|
2243
|
+
.select("conversation_id")
|
|
2244
|
+
.where("conversation_id", "in", tree)
|
|
2245
|
+
.where("kind", "in", ["network", "git"])
|
|
2246
|
+
.where("status", "=", "pending"));
|
|
2247
|
+
if (convs.length === 0)
|
|
2248
|
+
return { records: [], seqs: new Map() };
|
|
2249
|
+
const rows = await t
|
|
2250
|
+
.selectFrom("approvals as a")
|
|
2251
|
+
.innerJoin("runs as r", "r.id", "a.run_id")
|
|
2252
|
+
.selectAll("a")
|
|
2253
|
+
.where("a.conversation_id", "in", convs)
|
|
2254
|
+
.where("a.kind", "in", ["network", "git"])
|
|
2255
|
+
.where("a.status", "=", "pending")
|
|
2256
|
+
.where(sql `a.expires_at > now()`)
|
|
2257
|
+
.where("r.status", "in", ["running", "waiting"])
|
|
2258
|
+
.where("r.trigger_account_id", "=", authorAccountId)
|
|
2259
|
+
.orderBy("a.created_at")
|
|
2260
|
+
.orderBy("a.id")
|
|
2261
|
+
.forUpdate("a")
|
|
2262
|
+
.execute();
|
|
2263
|
+
const records = [];
|
|
2264
|
+
const seqs = new Map();
|
|
2265
|
+
for (const row of rows) {
|
|
2266
|
+
const updated = await t
|
|
2267
|
+
.updateTable("approvals")
|
|
2268
|
+
.set({ status: "skipped", decided_by: authorAccountId, decided_at: sql `now()` })
|
|
2269
|
+
.where("id", "=", row.id)
|
|
2270
|
+
.returningAll()
|
|
2271
|
+
.executeTakeFirstOrThrow();
|
|
2272
|
+
const seq = await this.decidedEvent(toRecord(row), "skipped", authorAccountId);
|
|
2273
|
+
seqs.set(row.conversation_id, Math.max(seqs.get(row.conversation_id) ?? 0, seq));
|
|
2274
|
+
records.push(toRecord(updated));
|
|
2275
|
+
}
|
|
2276
|
+
return { records, seqs };
|
|
2277
|
+
}
|
|
2278
|
+
/**
|
|
2279
|
+
* Locks the conversation row of approval `id` (`SELECT … FOR UPDATE`; re-entrant with the lock
|
|
2280
|
+
* `EventLog.appendIn` takes later). Every write to an approval row takes its conversation's lock
|
|
2281
|
+
* first, then the approval row, then the run row, as the stop of a waiting run
|
|
2282
|
+
* (`Waits.abortWaitingIn`) and the questions do, so no two of them can deadlock. False: no such
|
|
2283
|
+
* approval (in `orgId`).
|
|
2284
|
+
*/
|
|
2285
|
+
async lockConversationOf(id, orgId) {
|
|
2286
|
+
const t = this.db.db;
|
|
2287
|
+
let q = t.selectFrom("approvals").select("conversation_id").where("id", "=", id);
|
|
2288
|
+
if (orgId !== undefined)
|
|
2289
|
+
q = q.where("org_id", "=", orgId);
|
|
2290
|
+
const row = await q.executeTakeFirst();
|
|
2291
|
+
if (!row)
|
|
2292
|
+
return false;
|
|
2293
|
+
// org-filter: the conversation of the approval row read just above (org-filtered when the
|
|
2294
|
+
// caller passes orgId; otherwise a kernel-written approval id, see expireIn)
|
|
2295
|
+
await t
|
|
2296
|
+
.selectFrom("conversations")
|
|
2297
|
+
.select("id")
|
|
2298
|
+
.where("id", "=", row.conversation_id)
|
|
2299
|
+
.forUpdate()
|
|
2300
|
+
.executeTakeFirst();
|
|
2301
|
+
return true;
|
|
2302
|
+
}
|
|
2303
|
+
/** Locks, in id order, the conversations `ids` selects; returns their ids. */
|
|
2304
|
+
async lockConversations(ids) {
|
|
2305
|
+
const found = [...new Set((await ids.execute()).map((r) => r.conversation_id))];
|
|
2306
|
+
if (found.length === 0)
|
|
2307
|
+
return [];
|
|
2308
|
+
// org-filter: the ids come from the caller's query over approvals of a conversation tree it
|
|
2309
|
+
// already holds (skipNetworkIn)
|
|
2310
|
+
const rows = await this.db.db
|
|
2311
|
+
.selectFrom("conversations")
|
|
2312
|
+
.select("id")
|
|
2313
|
+
.where("id", "in", found)
|
|
2314
|
+
.orderBy("id")
|
|
2315
|
+
.forUpdate()
|
|
2316
|
+
.execute();
|
|
2317
|
+
return rows.map((r) => r.id);
|
|
2318
|
+
}
|
|
2319
|
+
/** `conversationId` and its sub-agents' conversations at any depth (at most 16 levels). */
|
|
2320
|
+
// org-filter: sub-agent conversations live in their parent's org; the root is the caller's
|
|
2321
|
+
async subtreeOf(conversationId) {
|
|
2322
|
+
const all = [conversationId];
|
|
2323
|
+
let level = [conversationId];
|
|
2324
|
+
for (let depth = 0; depth < 16 && level.length > 0; depth++) {
|
|
2325
|
+
const rows = await this.db
|
|
2326
|
+
.selectFrom("conversations")
|
|
2327
|
+
.select("id")
|
|
2328
|
+
.where("parent_conversation_id", "in", level)
|
|
2329
|
+
.execute();
|
|
2330
|
+
level = rows.map((r) => r.id).filter((id) => !all.includes(id));
|
|
2331
|
+
all.push(...level);
|
|
2332
|
+
}
|
|
2333
|
+
return all;
|
|
2334
|
+
}
|
|
2335
|
+
/**
|
|
2336
|
+
* 系统写的 `approval_decided`(超时 / 取消,处理人为 null;跳过,处理人为消息作者),在当前事务内;返回事件 seq。
|
|
2337
|
+
*/
|
|
2338
|
+
async decidedEvent(a, decision, byAccountId = null) {
|
|
492
2339
|
const written = await this.eventLog.appendIn(a.conversationId, [
|
|
493
2340
|
{
|
|
494
2341
|
type: "approval_decided",
|
|
495
2342
|
runId: a.runId,
|
|
496
2343
|
idemKey: `approval_decided:${a.id}`,
|
|
497
|
-
payload: { approvalId: a.id, callId: a.callId, decision, byAccountId
|
|
2344
|
+
payload: { approvalId: a.id, callId: a.callId, decision, byAccountId },
|
|
498
2345
|
},
|
|
499
2346
|
]);
|
|
500
2347
|
return Math.max(...written.map((e) => e.seq));
|
|
@@ -552,6 +2399,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
552
2399
|
return m?.role ?? null;
|
|
553
2400
|
}
|
|
554
2401
|
/** agent id → 当前版本定义里的名字。 */
|
|
2402
|
+
// org-filter: the agent ids come from the conversations of approval rows the callers already
|
|
2403
|
+
// read in their org (views)
|
|
555
2404
|
async agentNames(ids) {
|
|
556
2405
|
if (ids.length === 0)
|
|
557
2406
|
return new Map();
|
|
@@ -591,9 +2440,11 @@ let ApprovalsService = class ApprovalsService {
|
|
|
591
2440
|
roots.set(p, await rootConversationOf(db.db, p));
|
|
592
2441
|
}
|
|
593
2442
|
const names = await this.agentNames([...new Set(ctxRows.map((r) => r.agent_id))]);
|
|
2443
|
+
const people = await loadPeople(db.db, recs.flatMap((r) => (r.decidedBy === null ? [] : [r.decidedBy])));
|
|
594
2444
|
const connectorIds = [
|
|
595
2445
|
...new Set(recs.flatMap((r) => (r.connectorId === null ? [] : [r.connectorId]))),
|
|
596
2446
|
];
|
|
2447
|
+
// org-filter: connector ids from approval rows the callers already read in their org
|
|
597
2448
|
const apps = connectorIds.length === 0
|
|
598
2449
|
? []
|
|
599
2450
|
: await db
|
|
@@ -620,7 +2471,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
620
2471
|
const prefix = app ? connectorToolKey(app.slug, "") : undefined;
|
|
621
2472
|
return [
|
|
622
2473
|
{
|
|
623
|
-
...r,
|
|
2474
|
+
...publicRecord(r),
|
|
2475
|
+
decidedByPerson: r.decidedBy === null ? null : (people.get(r.decidedBy) ?? null),
|
|
624
2476
|
toolName: prefix !== undefined && r.toolKey.startsWith(prefix)
|
|
625
2477
|
? r.toolKey.slice(prefix.length)
|
|
626
2478
|
: r.toolKey,
|
|
@@ -647,9 +2499,51 @@ let ApprovalsService = class ApprovalsService {
|
|
|
647
2499
|
__decorate([
|
|
648
2500
|
Transactional()
|
|
649
2501
|
], ApprovalsService.prototype, "requestIn", null);
|
|
2502
|
+
__decorate([
|
|
2503
|
+
Transactional()
|
|
2504
|
+
], ApprovalsService.prototype, "requestSecureInputIn", null);
|
|
2505
|
+
__decorate([
|
|
2506
|
+
Transactional()
|
|
2507
|
+
], ApprovalsService.prototype, "requestSiteAccess", null);
|
|
2508
|
+
__decorate([
|
|
2509
|
+
Transactional()
|
|
2510
|
+
], ApprovalsService.prototype, "requestNetworkIn", null);
|
|
2511
|
+
__decorate([
|
|
2512
|
+
Transactional()
|
|
2513
|
+
], ApprovalsService.prototype, "requestGitIn", null);
|
|
2514
|
+
__decorate([
|
|
2515
|
+
Transactional()
|
|
2516
|
+
], ApprovalsService.prototype, "requestCommandIn", null);
|
|
2517
|
+
__decorate([
|
|
2518
|
+
WithLock({ key: "network-ask-#{1}", ttl: 60_000, waitTimeout: 45_000 })
|
|
2519
|
+
], ApprovalsService.prototype, "decideNetwork", null);
|
|
2520
|
+
__decorate([
|
|
2521
|
+
Transactional({ propagation: "requires_new" })
|
|
2522
|
+
], ApprovalsService.prototype, "decideSiteIn", null);
|
|
2523
|
+
__decorate([
|
|
2524
|
+
Transactional({ propagation: "requires_new" })
|
|
2525
|
+
], ApprovalsService.prototype, "decideLoopbackIn", null);
|
|
650
2526
|
__decorate([
|
|
651
2527
|
Transactional({ propagation: "requires_new" })
|
|
652
2528
|
], ApprovalsService.prototype, "decideIn", null);
|
|
2529
|
+
__decorate([
|
|
2530
|
+
Transactional({ propagation: "requires_new" })
|
|
2531
|
+
], ApprovalsService.prototype, "decideToolIn", null);
|
|
2532
|
+
__decorate([
|
|
2533
|
+
Transactional({ propagation: "mandatory" })
|
|
2534
|
+
], ApprovalsService.prototype, "decideTx", null);
|
|
2535
|
+
__decorate([
|
|
2536
|
+
Transactional({ propagation: "mandatory" })
|
|
2537
|
+
], ApprovalsService.prototype, "keepTrialGrant", null);
|
|
2538
|
+
__decorate([
|
|
2539
|
+
Transactional({ propagation: "mandatory" })
|
|
2540
|
+
], ApprovalsService.prototype, "keepTrialNetworkGrant", null);
|
|
2541
|
+
__decorate([
|
|
2542
|
+
Transactional({ propagation: "mandatory" })
|
|
2543
|
+
], ApprovalsService.prototype, "allowRepoIn", null);
|
|
2544
|
+
__decorate([
|
|
2545
|
+
Transactional({ propagation: "mandatory" })
|
|
2546
|
+
], ApprovalsService.prototype, "keepTrialGitGrant", null);
|
|
653
2547
|
__decorate([
|
|
654
2548
|
Transactional()
|
|
655
2549
|
], ApprovalsService.prototype, "expireIn", null);
|
|
@@ -659,6 +2553,9 @@ __decorate([
|
|
|
659
2553
|
__decorate([
|
|
660
2554
|
Transactional({ propagation: "mandatory" })
|
|
661
2555
|
], ApprovalsService.prototype, "cancelPendingFor", null);
|
|
2556
|
+
__decorate([
|
|
2557
|
+
Transactional({ propagation: "mandatory" })
|
|
2558
|
+
], ApprovalsService.prototype, "skipNetworkIn", null);
|
|
662
2559
|
__decorate([
|
|
663
2560
|
Transactional()
|
|
664
2561
|
], ApprovalsService.prototype, "revokeGrantIn", null);
|
|
@@ -668,6 +2565,26 @@ ApprovalsService = __decorate([
|
|
|
668
2565
|
__param(1, Inject(KernelConfigService)),
|
|
669
2566
|
__param(2, Inject(EventLog)),
|
|
670
2567
|
__param(3, Inject(KernelEvents)),
|
|
671
|
-
__param(4, Inject(TransactionHost))
|
|
2568
|
+
__param(4, Inject(TransactionHost)),
|
|
2569
|
+
__param(5, Inject(AutomationStore)),
|
|
2570
|
+
__param(6, Inject(ToolRegistry)),
|
|
2571
|
+
__param(7, Inject(LockService)),
|
|
2572
|
+
__param(8, Inject(SandboxService)),
|
|
2573
|
+
__param(9, Inject(RunResume)),
|
|
2574
|
+
__param(10, Inject(ConversationLeakCheck)),
|
|
2575
|
+
__param(11, Inject(SealedInputs)),
|
|
2576
|
+
__param(12, Inject(DevicesService)),
|
|
2577
|
+
__param(13, Optional()),
|
|
2578
|
+
__param(13, Inject(PermissionAuthorityLock)),
|
|
2579
|
+
__param(14, Optional()),
|
|
2580
|
+
__param(14, Inject(PermissionCallGrants)),
|
|
2581
|
+
__param(15, Optional()),
|
|
2582
|
+
__param(15, Inject(LoopbackGrants)),
|
|
2583
|
+
__param(16, Optional()),
|
|
2584
|
+
__param(16, Inject(DeviceSiteGrants)),
|
|
2585
|
+
__param(17, Optional()),
|
|
2586
|
+
__param(17, Inject(OrgLock)),
|
|
2587
|
+
__param(18, Optional()),
|
|
2588
|
+
__param(18, Inject(ExtensionRegistry))
|
|
672
2589
|
], ApprovalsService);
|
|
673
2590
|
export { ApprovalsService };
|