@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
package/dist/tools/pipeline.js
CHANGED
|
@@ -7,89 +7,228 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { CARD_BADGE_MAX, CARD_TEXT_MAX, DeviceAccessError, ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
|
+
import { sql } from "kysely";
|
|
13
|
+
import { appendMissingGrant, connectionGrantKey, UNATTENDED_CONNECTION_ERROR, UNATTENDED_ELICITATION_NOTE, UNATTENDED_QUESTION_ERROR, unattendedFails, unattendedRules, unattendedRunOf, } from "../automations/unattended.js";
|
|
14
|
+
import { backgroundMaxSeconds } from "../background/launch.js";
|
|
15
|
+
import { ConversationApprovalProfile } from "../conversations/approval-profile.js";
|
|
16
|
+
import { AttachmentsService } from "../conversations/attachments.service.js";
|
|
12
17
|
import { EventLog } from "../conversations/event-log.js";
|
|
13
|
-
import { ToolViewSchema } from "../conversations/events.js";
|
|
18
|
+
import { COMMAND_ASK_MAX_CHARS, COMMAND_ASK_TEXT_MAX_CHARS, ToolViewSchema, } from "../conversations/events.js";
|
|
19
|
+
import { siteAccessDetailHash, siteAccessInstallActive, } from "../device-access/site-access-request.js";
|
|
20
|
+
import { DeviceSiteGrants } from "../device-access/site-grants.js";
|
|
21
|
+
import { ConversationDevices } from "../devices/conversation-devices.js";
|
|
22
|
+
import { pathAgainstWorkingRoot } from "../devices/working-root.js";
|
|
14
23
|
import { ApiError } from "../errors.js";
|
|
15
24
|
import { EffectiveConfigs, NEEDS_CONFIG_REASON } from "../extensions/effective-config.js";
|
|
25
|
+
import { isExtensionEnabled } from "../extensions/enabled.js";
|
|
16
26
|
import { clipText } from "../extensions/hooks.js";
|
|
17
27
|
import { ExtensionHost } from "../extensions/host.js";
|
|
18
28
|
import { ExtensionUnloadedError, PLUGIN_UNLOADED_TOOL_ERROR } from "../extensions/inflight.js";
|
|
29
|
+
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
19
30
|
import { audit } from "../identity/audit.js";
|
|
31
|
+
import { sha256Hex } from "../identity/hash.js";
|
|
20
32
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
21
33
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
22
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
34
|
+
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
23
35
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
24
36
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
37
|
+
import { roleAtLeast } from "../orgs/roles.js";
|
|
25
38
|
import { UNKNOWN_RESULT_TEXT } from "../runtime/context/pairing.js";
|
|
26
39
|
import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookScope, } from "../runtime/hook-calls.js";
|
|
27
40
|
import { subagentWaitingIdemKey } from "../runtime/loop.js";
|
|
28
|
-
import { assistantIdemKey,
|
|
41
|
+
import { assistantIdemKey, MAX_STEP_MODEL_CALLS, modelCallIdemKey } from "../runtime/model-call.js";
|
|
42
|
+
import { currentExecutionClaim } from "../runtime/run-execution.js";
|
|
29
43
|
import { rootSurfaceOf } from "../runtime/subagents/child.js";
|
|
30
44
|
import { SubagentMessages } from "../runtime/subagents/messages.js";
|
|
31
45
|
import { pairStoppedForks } from "../runtime/subagents/skill-fork.js";
|
|
32
46
|
import { SubagentsService } from "../runtime/subagents/subagents.service.js";
|
|
47
|
+
import { LoopbackGrants, LoopbackLimitError, loopbackRefusal, } from "../sandbox/loopback-grants.js";
|
|
48
|
+
import { orgHostOutsideCeiling } from "../sandbox/modes.js";
|
|
49
|
+
import { NetworkGrants } from "../sandbox/network-grants.js";
|
|
50
|
+
import { SandboxOperationAuthority } from "../sandbox/operation-authority.js";
|
|
51
|
+
import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
|
|
52
|
+
import { PermissionAutoGrants } from "../sandbox/permission-auto-grants.js";
|
|
53
|
+
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
54
|
+
import { PermissionFacts, permissionScopeHash } from "../sandbox/permission-facts.js";
|
|
55
|
+
import { isSessionGrantableRule, } from "../sandbox/review/index.js";
|
|
56
|
+
import { approverForCrossing, buildPermissionCandidate, crossingOfCandidate, ESCALATION_RETRY_HINT, ESCALATION_UNATTENDED_WHY, escalationRefusedText, isEscalatedCall, } from "../sandbox/review/permission-candidate.js";
|
|
57
|
+
import { CommandReviewService, LOOPBACK_FULL_ACCESS_REASON, } from "../sandbox/review/review.service.js";
|
|
58
|
+
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
33
59
|
import { skillLoadOfferedIn } from "../skills/catalog.js";
|
|
34
|
-
import { ApprovalsService } from "./approvals.service.js";
|
|
60
|
+
import { ApprovalsService, } from "./approvals.service.js";
|
|
35
61
|
import { Breaker, breakerOpenMessage } from "./breaker.js";
|
|
36
|
-
import { SEND_MESSAGE, SUBAGENT_HANDBACK, TOOL_SEARCH } from "./builtin-names.js";
|
|
62
|
+
import { BUILTIN, SEND_MESSAGE, SUBAGENT_HANDBACK, TOOL_SEARCH } from "./builtin-names.js";
|
|
37
63
|
import { AGENT_TOOL, AgentToolInput } from "./builtins/agent.js";
|
|
38
64
|
import { HandbackInput } from "./builtins/handback.js";
|
|
65
|
+
import { generateImagePaths } from "./builtins/image/paths.js";
|
|
66
|
+
import { admissionUnavailableText } from "./builtins/sandbox/common.js";
|
|
67
|
+
import { DEVICE_CODE_PATTERN, deviceCodeIdemKey, GITHUB_DEVICE_LOGIN_URL, } from "./builtins/sandbox/device-code.js";
|
|
68
|
+
import { DEVICE_OF_ANOTHER_ACCOUNT_TEXT } from "./builtins/sandbox/device-owner.js";
|
|
39
69
|
import { SendMessageInput } from "./builtins/send-message.js";
|
|
40
70
|
import { isAlwaysLoaded, notLoadedText } from "./builtins/tool-search.js";
|
|
71
|
+
import { attachCallScope, mergeServiceHosts, serviceHostKey, stillStartingUnsent, } from "./call-scope.js";
|
|
41
72
|
import { canonicalJson } from "./canonical-json.js";
|
|
42
73
|
import { CredentialMissing, Credentials } from "./credentials.js";
|
|
43
74
|
import { ToolDrift } from "./drift.js";
|
|
44
75
|
import { ElicitationSession } from "./elicitation.js";
|
|
45
|
-
import {
|
|
76
|
+
import { loopbackGrantedNote, loopbackNotAppliedNote, loopbackPendingNote, loopbackReviewDeniedNote, planLoopbackAsk, } from "./loopback-asks.js";
|
|
77
|
+
import { addressEscalationHint, blockedEventHosts, clipKept, denialHintFor, deviceAskTerms, MAX_NETWORK_ASKS_PER_RUN, NETWORK_ASK_KEPT_MAX_BYTES, networkBlockedIdemKey, otherAskPendingNote, planNetworkAsk, serviceAskedNote, serviceAskTerms, settledNetworkNotes, tooManyNote, withNetworkNotes, } from "./network-asks.js";
|
|
78
|
+
import { readOrgToolPolicy, } from "./org-tool-policies.js";
|
|
46
79
|
import { OrgToolSwitches, toolTurnedOffReason } from "./org-tool-switches.js";
|
|
47
80
|
import { renderResult, resolveOutputRefs, spillIfLarge, ToolOutputs } from "./outputs.js";
|
|
48
81
|
import { createDecidePolicy } from "./policy.js";
|
|
49
|
-
import { QuestionsService } from "./questions.service.js";
|
|
82
|
+
import { QuestionsService, TooManyWatchedWaitsError, } from "./questions.service.js";
|
|
50
83
|
import { redactDeep, redactorFor } from "./redact.js";
|
|
51
84
|
import { ToolRegistry, } from "./registry.js";
|
|
52
85
|
import { runResourceTool } from "./resources.js";
|
|
86
|
+
import { storeResultImages } from "./result-images.js";
|
|
87
|
+
import { ToolAskReview } from "./tool-review.js";
|
|
53
88
|
import { validateInput } from "./validate.js";
|
|
54
89
|
// ---- 模型可见文案(英文) ----
|
|
55
90
|
/** 审批被拒绝。 */
|
|
56
91
|
export const APPROVAL_DENIED_TEXT = "The user denied this tool call.";
|
|
57
92
|
/**
|
|
58
93
|
* The denied call's result when the approver gave a reason (model-visible, in the log). "An
|
|
59
|
-
* approver": under role escalation an admin, not the requester, decides.
|
|
60
|
-
* they recorded ("The user denied this tool call. Reason: …"); only new denials use this one.
|
|
94
|
+
* approver": under role escalation an admin, not the requester, decides.
|
|
61
95
|
*/
|
|
62
96
|
export const approvalDeniedText = (reason) => reason === null ? APPROVAL_DENIED_TEXT : `An approver denied this tool call. Reason: ${reason}`;
|
|
63
97
|
/** 审批超时(按拒绝)。 */
|
|
64
98
|
export const approvalExpiredText = (hours) => `Approval timed out after ${hours}h; treated as denied.`;
|
|
65
99
|
/** 等待审批期间 run 被中止。 */
|
|
66
100
|
export const APPROVAL_CANCELLED_TEXT = "The run was stopped while waiting for approval.";
|
|
101
|
+
/** A person field refused on the approval card as leaked, for a call that then did not run. */
|
|
102
|
+
export const leakedOnCardText = (path) => `The person's \`${path}\` appeared in the conversation earlier and was refused as leaked; ask them to rotate it.`;
|
|
103
|
+
/**
|
|
104
|
+
* A call that ended without running: its text, then the leaked-on-card line per person field the
|
|
105
|
+
* approval card refused as leaked (`detail.leakedFields`), so the agent has the key rotated.
|
|
106
|
+
*/
|
|
107
|
+
export const withLeakedOnCard = (text, leakedFields) => leakedFields === undefined || leakedFields.length === 0
|
|
108
|
+
? text
|
|
109
|
+
: [text, ...leakedFields.map(leakedOnCardText)].join("\n");
|
|
110
|
+
/**
|
|
111
|
+
* The command review's deny text (auto mode spec §5.4, P-D12): the model-visible reason and what it
|
|
112
|
+
* can do instead. `kind` says whether a shell command, a file write or a file read was held.
|
|
113
|
+
*/
|
|
114
|
+
export const commandDeniedText = (reason, kind) => kind === "write"
|
|
115
|
+
? `This write is blocked by review: ${reason}. Write it another way or ask the user to allow it.`
|
|
116
|
+
: kind === "read"
|
|
117
|
+
? `This read is blocked by review: ${reason}. Read another file or ask the user to allow it.`
|
|
118
|
+
: `Command blocked by review: ${reason}. Do the work another way or ask the user to run it.`;
|
|
119
|
+
/**
|
|
120
|
+
* A command (or write, or read) the review held in an unattended run: no one can answer, so it is a
|
|
121
|
+
* deny at once — no approval, no grant (P-D3).
|
|
122
|
+
*/
|
|
123
|
+
export const commandUnattendedText = (reason, kind) => kind === "command"
|
|
124
|
+
? `This command needs approval (${reason}), and no one can approve it now; do the work another way or leave it for the person.`
|
|
125
|
+
: `This ${kind} needs approval (${reason}), and no one can approve it now; do it another way or leave it for the person.`;
|
|
126
|
+
/**
|
|
127
|
+
* A command longer than the ask ceiling (`COMMAND_ASK_MAX_CHARS`): it cannot be shown for approval,
|
|
128
|
+
* and an approval must bind the whole text, so the call is refused before any approval exists.
|
|
129
|
+
*/
|
|
130
|
+
export const commandTooLongReason = (chars) => `The command is ${chars} characters long; commands over ${COMMAND_ASK_MAX_CHARS} are too long to review and approve.`;
|
|
131
|
+
/** The model-visible result of a command over the ask ceiling (actionable, English). */
|
|
132
|
+
export const commandTooLongText = (chars) => `This command is too long to review (${chars} characters; the limit is ${COMMAND_ASK_MAX_CHARS}). Split it into shorter commands; long inline scripts are reviewed as code the review cannot read.`;
|
|
133
|
+
/** The person declined a held command, write or read (P-D12); `reason` is what they said, if any. */
|
|
134
|
+
export const commandDeclinedText = (reason, kind) => {
|
|
135
|
+
const what = kind === "write" ? "this write" : kind === "read" ? "this read" : "to run this command";
|
|
136
|
+
return reason === null
|
|
137
|
+
? `The user declined ${what}. Continue without it or ask the user.`
|
|
138
|
+
: `The user declined ${what}: ${reason}. Continue without it or ask the user.`;
|
|
139
|
+
};
|
|
67
140
|
/** 等待用户输入期间 run 被中止。 */
|
|
68
141
|
export const INPUT_CANCELLED_TEXT = "The run was stopped while waiting for user input.";
|
|
142
|
+
/**
|
|
143
|
+
* The result of an `AskUserQuestion` call whose question the user skipped by sending a message
|
|
144
|
+
* (reply-while-question spec §7.1): the message follows in the log as an ordinary user message.
|
|
145
|
+
*/
|
|
146
|
+
export const QUESTION_SKIPPED_TEXT = "The user did not answer this question and sent a message instead; read it below and continue.";
|
|
147
|
+
/** The result of any other tool's input request (extension `input_required`, MCP elicitation) skipped by a message. */
|
|
148
|
+
export const INPUT_SKIPPED_TEXT = "The user did not provide the requested input and sent a message instead; read it below and continue. Call the tool again only if it is still needed.";
|
|
149
|
+
/**
|
|
150
|
+
* The result of a watched wait (`InputRequired.watch`) ended by the person's message (browser long
|
|
151
|
+
* waits spec §5.2): ending a wait by writing is not a tool failure.
|
|
152
|
+
*/
|
|
153
|
+
export const WAIT_SKIPPED_TEXT = "The user sent a message while this wait was running, which ended it; read the message below and continue. Call the tool again only if the wait is still needed.";
|
|
154
|
+
/** A watched ask over `tools.maxWatchedWaitsPerAccount` (spec §5.2). */
|
|
155
|
+
export const TOO_MANY_WATCHED_WAITS_TEXT = "Too many waits are running for this user; end one, or finish and let an automation check later.";
|
|
156
|
+
/** A tool asked for a watched wait without a registered watcher (spec §5.2). */
|
|
157
|
+
export const watchWithoutWatcherText = (key) => `Tool ${key} asked for a watched wait but registers no watcher.`;
|
|
69
158
|
/** 同一调用连续请求输入超过上限。 */
|
|
70
159
|
export const TOO_MANY_INPUT_REQUESTS_TEXT = "Tool requested user input too many times.";
|
|
71
160
|
/** run 已被中止 / 到达截止时间,调用尚未开始执行。 */
|
|
72
161
|
export const RUN_STOPPED_TEXT = "The run was stopped before this tool call was executed.";
|
|
162
|
+
/**
|
|
163
|
+
* A call with person fields in an unattended run (ruling R6): no person is there to type the
|
|
164
|
+
* values on the card.
|
|
165
|
+
*/
|
|
166
|
+
export const PERSON_FIELDS_UNATTENDED_TEXT = "This write needs the person to enter values on the web; it cannot run unattended.";
|
|
167
|
+
/**
|
|
168
|
+
* A call with person fields whose ask would go to a role instead of the person (ruling R5): only the
|
|
169
|
+
* person the run works for may type the values, and they lack the role.
|
|
170
|
+
*/
|
|
171
|
+
export const PERSON_FIELDS_ROLE_TEXT = "This write needs the person you work for to enter values; they lack the role. Ask an admin to do it on the web.";
|
|
172
|
+
/**
|
|
173
|
+
* A call only the person may confirm (`CallPolicy.personOnly`: its result is shown once to the
|
|
174
|
+
* run's person) in an unattended run: nobody is there to read it.
|
|
175
|
+
*/
|
|
176
|
+
export const PERSON_ONLY_UNATTENDED_TEXT = "This write shows its result once, on the web, to the person you work for, and no one is there to read it; it cannot run unattended.";
|
|
177
|
+
/**
|
|
178
|
+
* A call that changes what the person consents to (`CallPolicy.personDecides`) in an unattended
|
|
179
|
+
* run: only that person decides it, and nobody is there.
|
|
180
|
+
*/
|
|
181
|
+
export const PERSON_DECIDES_UNATTENDED_TEXT = "This write changes what the person you work for consents to, so only they can confirm it, and no one is there; it cannot run unattended. Ask them to make the change on the web.";
|
|
182
|
+
/** A call only the person may confirm whose ask would go to a role instead of the person. */
|
|
183
|
+
export const PERSON_ONLY_ROLE_TEXT = "This write shows its result once to the person you work for, so it runs only for them, and they lack the role. Ask an admin to do it on the web.";
|
|
184
|
+
/**
|
|
185
|
+
* The review model declined, under Approve for me, a call whose approval would have gone to the
|
|
186
|
+
* person (profiles govern every approval, R3): nothing ran.
|
|
187
|
+
*/
|
|
188
|
+
export const toolReviewDeniedText = (reason) => `The review model declined this call for the person (Approve for me): ${reason} Nothing ran. Tell the person what you wanted to do and why; they can do it themselves, or switch this conversation to Request approval and approve it when you call again.`;
|
|
189
|
+
/** The reason recorded when Auto runs an approval addressed to the person (R2). */
|
|
190
|
+
export const TOOL_AUTO_REASON = "Auto runs approvals addressed to the person without asking.";
|
|
191
|
+
/** The person cancelled the secure input request of a call with person fields (R4): nothing ran. */
|
|
192
|
+
export const secureInputCancelledText = (id) => `The person cancelled secure input ${id}, so nothing ran. Never ask for the value in the conversation; call the operation again only if the person asks for it.`;
|
|
193
|
+
/** A secure input request expired unanswered (R4): nothing ran. */
|
|
194
|
+
export const secureInputExpiredText = (id, hours) => `Secure input ${id} expired after ${hours} h without the person submitting it, so nothing ran. Call the operation again if it is still needed.`;
|
|
73
195
|
/** 调用执行中 run 被中止 / 到达截止时间。 */
|
|
74
196
|
export const RUN_STOPPED_DURING_TEXT = "The run was stopped while this tool call was running; its outcome is unknown. Verify before retrying.";
|
|
197
|
+
/** The fixed result of a call whose input request was skipped by a message (spec §7.1). */
|
|
198
|
+
const skippedResult = (toolKey, watch = false) => watch
|
|
199
|
+
? {
|
|
200
|
+
content: WAIT_SKIPPED_TEXT,
|
|
201
|
+
isError: false,
|
|
202
|
+
display: { summary: { zh: "等待因新消息结束", en: "Wait ended by your message" } },
|
|
203
|
+
}
|
|
204
|
+
: toolKey === "AskUserQuestion"
|
|
205
|
+
? {
|
|
206
|
+
content: QUESTION_SKIPPED_TEXT,
|
|
207
|
+
isError: false,
|
|
208
|
+
display: {
|
|
209
|
+
summary: {
|
|
210
|
+
zh: "用户没有回答,直接发了消息",
|
|
211
|
+
en: "User sent a message instead of answering",
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
}
|
|
215
|
+
: {
|
|
216
|
+
content: INPUT_SKIPPED_TEXT,
|
|
217
|
+
isError: true,
|
|
218
|
+
display: {
|
|
219
|
+
summary: { zh: "用户没有提供输入,直接发了消息", en: "User sent a message instead" },
|
|
220
|
+
},
|
|
221
|
+
};
|
|
75
222
|
const timeoutText = (key, ms) => `Tool ${key} timed out after ${ms / 1000}s. The operation may or may not have completed; verify before retrying.`;
|
|
223
|
+
/**
|
|
224
|
+
* The timeout of a call whose device was still starting (its instance being created or resumed,
|
|
225
|
+
* or the device service being launched) and that had sent nothing to a device service: its
|
|
226
|
+
* target was not reached. The start was stopped with the call, so a retry starts it again.
|
|
227
|
+
*/
|
|
228
|
+
export const deviceStartingTimeoutText = (key, ms) => `Tool ${key} timed out after ${ms / 1000}s while the device was still starting (its sandbox or the device service), before the call sent anything to its target. The start was stopped with the call; a retry starts the device again, and if it times out the same way the tool's time limit is too short for this device's first start: tell the user.`;
|
|
76
229
|
const failedText = (key, errName) => `Tool ${key} failed (${errName}). The operation may not have completed; check before retrying or try another approach.`;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const connectorSlugs = new Set();
|
|
80
|
-
const extensionNames = new Set();
|
|
81
|
-
for (const t of tools) {
|
|
82
|
-
const p = parseToolKey(t.key);
|
|
83
|
-
if (p?.kind === "connector")
|
|
84
|
-
connectorSlugs.add(p.slug);
|
|
85
|
-
else if (p?.kind === "extension")
|
|
86
|
-
extensionNames.add(p.plugin);
|
|
87
|
-
}
|
|
88
|
-
return { connectorSlugs, extensionNames };
|
|
89
|
-
};
|
|
90
|
-
const unknownToolText = (name, keys, toolSearch, hint = null) => `Unknown tool "${name}". Available tools: ${keys.length === 0 ? "(none)" : keys.join(", ")}.` +
|
|
91
|
-
(toolSearch ? " Use ToolSearch to load other tools." : "") +
|
|
92
|
-
(hint === null ? "" : ` ${hint}`);
|
|
230
|
+
const unknownToolText = (name, keys, toolSearch) => `Unknown tool "${name}". Available tools: ${keys.length === 0 ? "(none)" : keys.join(", ")}.` +
|
|
231
|
+
(toolSearch ? " Use ToolSearch to load other tools." : "");
|
|
93
232
|
const unavailableText = (name, reason) => `Tool "${name}" is unavailable: ${reason}.`;
|
|
94
233
|
/** With a per-call policy key (`Platform:<operation>`), the text names it. */
|
|
95
234
|
const deniedText = (key, policyKey) => policyKey === undefined || policyKey === key
|
|
@@ -105,9 +244,151 @@ export const hookDeniedText = (plugin, reason) => `Tool call blocked by the "${p
|
|
|
105
244
|
const invalidFormText = (key, problems) => `Tool ${key} returned an invalid input form: ${problems.join("; ")}.`;
|
|
106
245
|
const stateTooLargeText = (key) => `Tool ${key} returned input state larger than ${MAX_INPUT_STATE_BYTES / 1024} KB.`;
|
|
107
246
|
const personalMissingText = (connectorName) => `The user has not connected ${connectorName}. A connect card was shown; ask the user to connect, then retry.`;
|
|
108
|
-
|
|
247
|
+
/**
|
|
248
|
+
* A connector lacking its org input (`needs_config`, plugin pages spec §5.2.1): `Credentials`
|
|
249
|
+
* throws an org `CredentialMissing` before any credential is presented, so the call never opens.
|
|
250
|
+
*/
|
|
251
|
+
const ORG_MISSING_TEXT = "This connector needs to be configured by an organization admin before it can be used.";
|
|
252
|
+
const sameOrgAsk = (a, b) => canonicalJson(a ?? []) === canonicalJson(b ?? []);
|
|
253
|
+
class OrgToolPolicyChanged extends Error {
|
|
254
|
+
}
|
|
255
|
+
class OrgToolDenied extends Error {
|
|
256
|
+
}
|
|
109
257
|
/** Optional provider: the pipeline's {@link ToolPipelineHooks} (tests). */
|
|
110
258
|
export const TOOL_PIPELINE_HOOKS = Symbol("TOOL_PIPELINE_HOOKS");
|
|
259
|
+
/** Review usage and hooks retain the same tree ancestry on both review routes. */
|
|
260
|
+
function reviewParentOf(parent) {
|
|
261
|
+
return parent === undefined
|
|
262
|
+
? {}
|
|
263
|
+
: {
|
|
264
|
+
parentRunId: parent.runId,
|
|
265
|
+
...(parent.budgetRunId !== undefined && { budgetRunId: parent.budgetRunId }),
|
|
266
|
+
parent: {
|
|
267
|
+
conversationId: parent.conversationId,
|
|
268
|
+
runId: parent.runId,
|
|
269
|
+
callId: parent.callId,
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The tools the command review covers (auto mode spec §5.1): the shell and the file tools whose
|
|
275
|
+
* writes may leave the workspace, and `GenerateImage` when it writes its images into the device
|
|
276
|
+
* (`file_path`; image generation spec §5.3, reviewed as a `Write`). Any other tool call is not
|
|
277
|
+
* reviewed (the review service answers `allow` for it too; the pipeline skips the facts read).
|
|
278
|
+
*/
|
|
279
|
+
const REVIEWED_TOOL_KEYS = new Set(["Bash", "Write", "Edit", "GenerateImage"]);
|
|
280
|
+
/** Whether the review covers this call ({@link REVIEWED_TOOL_KEYS}; `GenerateImage` with a path). */
|
|
281
|
+
const isReviewedCall = (toolKey, input) => REVIEWED_TOOL_KEYS.has(toolKey) &&
|
|
282
|
+
(toolKey !== "GenerateImage" || generateImagePaths(input).length > 0);
|
|
283
|
+
/** The paths a reviewed write writes: `file_path`, or every path of a `GenerateImage` call. */
|
|
284
|
+
const writePathsOf = (toolKey, input) => toolKey === "GenerateImage" ? generateImagePaths(input) : [textField(input, "file_path")];
|
|
285
|
+
/**
|
|
286
|
+
* A call that needs reach beyond the working directory on a device whose permission support is
|
|
287
|
+
* not verified: no approval could let admission run it, so nothing is offered.
|
|
288
|
+
*/
|
|
289
|
+
export const PERMISSION_SUPPORT_UNVERIFIED_TEXT = "This call needs access outside the working directory, but this device's permission support is not verified yet, so only paths inside the working directory work now. Keep the call inside the working directory, or retry once the device is ready.";
|
|
290
|
+
/**
|
|
291
|
+
* The managed builtins whose review depends on the device's facts (a proposed reach or a
|
|
292
|
+
* sensitive command): their first call starts the device before it is reviewed. The others start
|
|
293
|
+
* it only when they run (a Skill without scripts never does).
|
|
294
|
+
*/
|
|
295
|
+
const REVIEWED_ON_FACTS = new Set([
|
|
296
|
+
BUILTIN.Bash,
|
|
297
|
+
BUILTIN.Read,
|
|
298
|
+
BUILTIN.Write,
|
|
299
|
+
BUILTIN.Edit,
|
|
300
|
+
BUILTIN.GenerateImage,
|
|
301
|
+
]);
|
|
302
|
+
/** The refusals of a permission review that end the call (fail closed), not the run. */
|
|
303
|
+
const FAIL_CLOSED_CODES = new Set([
|
|
304
|
+
"forbidden",
|
|
305
|
+
"conflict",
|
|
306
|
+
"conversation.not_found",
|
|
307
|
+
]);
|
|
308
|
+
/** What the model gets when the permission check of its call refused (fail closed). */
|
|
309
|
+
export const permissionCheckFailedText = (why) => `The permission check for this call could not be completed (${why.replace(/\.$/, "")}), so it did not run. Retry the call once; if it fails again, ask the user to check the conversation's permission profile or to approve the call again.`;
|
|
310
|
+
/** The builtins whose device entry is the managed operation route. */
|
|
311
|
+
const MANAGED_OPERATION_TOOLS = new Set([
|
|
312
|
+
BUILTIN.Bash,
|
|
313
|
+
BUILTIN.Read,
|
|
314
|
+
BUILTIN.Write,
|
|
315
|
+
BUILTIN.Edit,
|
|
316
|
+
BUILTIN.Glob,
|
|
317
|
+
BUILTIN.Grep,
|
|
318
|
+
BUILTIN.Deliver,
|
|
319
|
+
BUILTIN.FetchAttachment,
|
|
320
|
+
BUILTIN.Skill,
|
|
321
|
+
BUILTIN.GenerateImage,
|
|
322
|
+
]);
|
|
323
|
+
/**
|
|
324
|
+
* Whether a managed builtin's call enters the device: every call of the device tools, a
|
|
325
|
+
* `GenerateImage` call only with `file_path` (one without writes nothing into the device, so it
|
|
326
|
+
* takes neither the device-owner guard nor the permission review: image generation spec §5.3),
|
|
327
|
+
* and a `Read` only with `file_path` (a `file_id` read comes from the object store: vision-read
|
|
328
|
+
* design §1.1).
|
|
329
|
+
*/
|
|
330
|
+
const entersDevice = (toolKey, input) => {
|
|
331
|
+
if (toolKey === BUILTIN.Read) {
|
|
332
|
+
return typeof input?.file_path === "string";
|
|
333
|
+
}
|
|
334
|
+
return toolKey !== BUILTIN.GenerateImage || generateImagePaths(input).length > 0;
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* What the review holds, for the texts and the ask's detail: a shell command, a file read (a read
|
|
338
|
+
* tool's crossing asks to read, never to write) or a file write.
|
|
339
|
+
*/
|
|
340
|
+
const reviewKindOf = (toolKey) => toolKey === BUILTIN.Bash
|
|
341
|
+
? "command"
|
|
342
|
+
: toolKey === BUILTIN.Read || toolKey === BUILTIN.Glob || toolKey === BUILTIN.Grep
|
|
343
|
+
? "read"
|
|
344
|
+
: "write";
|
|
345
|
+
/**
|
|
346
|
+
* The working root a reviewed call carries to its tool: a project root only. In free mode the
|
|
347
|
+
* reviewed root is the recorded workspace, which may be stale; the tool then maps it to the held
|
|
348
|
+
* instance's own workspace as it always has.
|
|
349
|
+
*/
|
|
350
|
+
const carriedRoot = (facts) => facts.workingRoot !== undefined && facts.workingRoot !== facts.workspace
|
|
351
|
+
? facts.workingRoot
|
|
352
|
+
: undefined;
|
|
353
|
+
/** The review record of an allowed call. */
|
|
354
|
+
const allowRecord = (v) => ({
|
|
355
|
+
decision: "allow",
|
|
356
|
+
by: v.by,
|
|
357
|
+
rule: v.rule,
|
|
358
|
+
reason: v.reason,
|
|
359
|
+
});
|
|
360
|
+
/** The review record of a denied call (the rule table's, the classifier's or a person's). */
|
|
361
|
+
const denyRecord = (by, rule, reason) => ({
|
|
362
|
+
decision: "deny",
|
|
363
|
+
by,
|
|
364
|
+
rule,
|
|
365
|
+
reason,
|
|
366
|
+
});
|
|
367
|
+
/** A string field of a validated tool input, or "" (never another type). */
|
|
368
|
+
const textField = (input, field) => {
|
|
369
|
+
const v = input?.[field];
|
|
370
|
+
return typeof v === "string" ? v : "";
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* The binding of an automatic decision (R2): the first 16 hex chars of the sha256 of the policy
|
|
374
|
+
* key, the definition and the raw input, as an approval binds them.
|
|
375
|
+
*/
|
|
376
|
+
const askBindingHash = (policyKey, specHash, rawInput) => sha256Hex(canonicalJson([policyKey, specHash, rawInput ?? {}])).slice(0, 16);
|
|
377
|
+
/** The profile step's outcome from a recorded automatic decision. */
|
|
378
|
+
const askDecisionOf = (event) => {
|
|
379
|
+
const p = event.payload;
|
|
380
|
+
return p.outcome === "deny"
|
|
381
|
+
? { kind: "deny", reason: p.reason }
|
|
382
|
+
: {
|
|
383
|
+
kind: "allow",
|
|
384
|
+
decision: {
|
|
385
|
+
source: p.decisionSource,
|
|
386
|
+
revision: p.profileRevision,
|
|
387
|
+
seq: event.seq,
|
|
388
|
+
...(p.fileSha256 !== undefined && { fileSha256: p.fileSha256 }),
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
};
|
|
111
392
|
const approvalAuthorization = (a) => ({
|
|
112
393
|
approvalId: a.id,
|
|
113
394
|
approvedByAccountId: a.decidedBy,
|
|
@@ -124,6 +405,56 @@ const idem = {
|
|
|
124
405
|
connection: (runId, callId) => `connection_required:${runId}:${callId}`,
|
|
125
406
|
hookDenied: (runId, callId) => `hook_denied:${runId}:${callId}`,
|
|
126
407
|
};
|
|
408
|
+
/**
|
|
409
|
+
* `ToolCallContext.idempotencyKey`: one logical call's key (a call id is unique only within its
|
|
410
|
+
* run), the same for every `InputRequired` round of the call.
|
|
411
|
+
*/
|
|
412
|
+
/**
|
|
413
|
+
* The SDK context fields of an extension tool's call (memory plugin spec §6.2: `accountId` stays
|
|
414
|
+
* the trigger account), shared by the pipeline's handler call and a watched wait's watcher call
|
|
415
|
+
* (browser long waits spec §5.3), so a watcher sees the call exactly as its handler did.
|
|
416
|
+
*/
|
|
417
|
+
export function extensionCallContext(f) {
|
|
418
|
+
return {
|
|
419
|
+
orgId: f.orgId,
|
|
420
|
+
accountId: f.accountId,
|
|
421
|
+
agentId: f.agentId,
|
|
422
|
+
conversationId: f.conversationId,
|
|
423
|
+
rootConversationId: f.rootConversationId,
|
|
424
|
+
callId: f.callId,
|
|
425
|
+
idempotencyKey: toolIdempotencyKey(f.conversationId, f.runId, f.callId),
|
|
426
|
+
source: f.source,
|
|
427
|
+
ownerAccountId: f.ownerAccountId,
|
|
428
|
+
role: f.role,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* The pre-call gate of an extension tool's call, one function for the pipeline's handler call and
|
|
433
|
+
* a watched wait's watcher call (browser long waits spec §5.3, R17): the org's single-tool switch
|
|
434
|
+
* not off, the extension loaded on this replica and its effective config for the org valid
|
|
435
|
+
* (`needsConfig` otherwise), and with `checkEnabled` the extension enabled in the org (the
|
|
436
|
+
* pipeline's step already resolved its tools with the org's enablement).
|
|
437
|
+
*/
|
|
438
|
+
export async function extensionCallGate(deps, orgId, toolKey, source, opts = {}) {
|
|
439
|
+
if (opts.checkEnabled !== undefined && !(await opts.checkEnabled(orgId, source.plugin)))
|
|
440
|
+
return { ok: false, message: PLUGIN_UNLOADED_TOOL_ERROR, transient: false };
|
|
441
|
+
// turned off in the org since the step resolved its tools (spec A §7)
|
|
442
|
+
if (await deps.switches.isToolOff(orgId, source.plugin, source.name))
|
|
443
|
+
return { ok: false, message: `${toolTurnedOffReason(toolKey)}.`, transient: false };
|
|
444
|
+
const effective = await deps.effective.get(orgId, source.plugin);
|
|
445
|
+
if (!effective.ok) {
|
|
446
|
+
// unloaded or disabled since the step resolved its tools: the documented unloaded error
|
|
447
|
+
if (effective.notRunning)
|
|
448
|
+
return { ok: false, message: PLUGIN_UNLOADED_TOOL_ERROR, transient: true };
|
|
449
|
+
return {
|
|
450
|
+
ok: false,
|
|
451
|
+
message: unavailableText(toolKey, NEEDS_CONFIG_REASON),
|
|
452
|
+
transient: false,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
return { ok: true, config: effective.config };
|
|
456
|
+
}
|
|
457
|
+
export const toolIdempotencyKey = (conversationId, runId, callId) => sha256Hex(`capybara:tool-call:${conversationId}:${runId}:${callId}`);
|
|
127
458
|
/** 同一调用最多连续请求用户输入的次数。 */
|
|
128
459
|
const MAX_INPUT_ROUNDS = 3;
|
|
129
460
|
/** 输入请求 state 的上限(JSON 序列化后的字节数)。 */
|
|
@@ -142,6 +473,11 @@ function loadedFrom(result, tools) {
|
|
|
142
473
|
const known = new Set(tools.filter((t) => !isAlwaysLoaded(t.key)).map((t) => t.key));
|
|
143
474
|
return [...new Set(raw.filter((k) => typeof k === "string" && known.has(k)))];
|
|
144
475
|
}
|
|
476
|
+
/** A builtin result's `media` (see `BuiltinResult`): a non-empty array, else nothing. */
|
|
477
|
+
function mediaFrom(result) {
|
|
478
|
+
const raw = result?.media;
|
|
479
|
+
return Array.isArray(raw) && raw.length > 0 ? raw : undefined;
|
|
480
|
+
}
|
|
145
481
|
class Stopped extends Error {
|
|
146
482
|
}
|
|
147
483
|
/** 在工具结果末尾附上说明(如被拒绝的 elicitation);结果不是 `{ content: [] }` 形状时原样返回。 */
|
|
@@ -156,6 +492,229 @@ function withNotes(result, notes) {
|
|
|
156
492
|
content: [...content, ...notes.map((text) => ({ type: "text", text }))],
|
|
157
493
|
};
|
|
158
494
|
}
|
|
495
|
+
/** A network ask's kept display fields, written with its result when the ask settles. */
|
|
496
|
+
export const keptExtras = (kept) => ({
|
|
497
|
+
...(kept?.outputId !== undefined && { outputId: kept.outputId }),
|
|
498
|
+
...(kept?.contentTypes !== undefined && { contentTypes: kept.contentTypes }),
|
|
499
|
+
...(kept?.display !== undefined && { display: kept.display }),
|
|
500
|
+
...(kept?.view !== undefined && { view: kept.view }),
|
|
501
|
+
...(kept?.media !== undefined && { media: kept.media }),
|
|
502
|
+
});
|
|
503
|
+
function withBlocked(outcome, scope) {
|
|
504
|
+
if (outcome.kind === "connection_required")
|
|
505
|
+
return outcome;
|
|
506
|
+
const blocked = scope?.blocked;
|
|
507
|
+
const review = scope?.review ?? null;
|
|
508
|
+
return {
|
|
509
|
+
...outcome,
|
|
510
|
+
...(blocked != null &&
|
|
511
|
+
blocked.hosts.size > 0 && {
|
|
512
|
+
blocked: {
|
|
513
|
+
deviceId: blocked.deviceId,
|
|
514
|
+
hosts: [...blocked.hosts].map(([host, layer]) => ({ host, layer })),
|
|
515
|
+
url: blocked.url,
|
|
516
|
+
...(blocked.loopback !== null && { loopback: { ...blocked.loopback } }),
|
|
517
|
+
},
|
|
518
|
+
}),
|
|
519
|
+
// a device service launch's review (ctx.deviceAccess), recorded with the call's result
|
|
520
|
+
...(review !== null && { review }),
|
|
521
|
+
...((outcome.kind === "result" || outcome.kind === "error") &&
|
|
522
|
+
scope?.siteAccess != null && { siteAccess: scope.siteAccess }),
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* What a call's earlier input rounds carried for its result ({@link QuestionCarried}): the latest
|
|
527
|
+
* launch review, and every refused host (the latest device and page) in one report.
|
|
528
|
+
*/
|
|
529
|
+
function carriedOf(rounds) {
|
|
530
|
+
let review;
|
|
531
|
+
let blocked;
|
|
532
|
+
for (const r of rounds) {
|
|
533
|
+
if (r.carried?.review !== undefined)
|
|
534
|
+
review = r.carried.review;
|
|
535
|
+
const b = r.carried?.blocked;
|
|
536
|
+
if (b !== undefined)
|
|
537
|
+
blocked = mergeBlocked(blocked, b);
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
...(review !== undefined && { review }),
|
|
541
|
+
...(blocked !== undefined && { blocked }),
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Two refused-host reports of one call as one: the hosts of both (a host in both keeps the more
|
|
546
|
+
* restrictive layer), the later device and page. A malformed host entry (a record written by
|
|
547
|
+
* another kernel version) is dropped.
|
|
548
|
+
*/
|
|
549
|
+
function mergeBlocked(a, b) {
|
|
550
|
+
const loopback = validLoopback(b.loopback) ?? validLoopback(a?.loopback);
|
|
551
|
+
return {
|
|
552
|
+
deviceId: b.deviceId ?? a?.deviceId ?? null,
|
|
553
|
+
hosts: mergeServiceHosts(validServiceHosts(a?.hosts), validServiceHosts(b.hosts)),
|
|
554
|
+
url: b.url ?? a?.url ?? null,
|
|
555
|
+
...(loopback !== undefined && { loopback }),
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
/** A well-formed loopback refusal ({@link ServiceBlocked.loopback}); a malformed one is dropped. */
|
|
559
|
+
function validLoopback(l) {
|
|
560
|
+
const v = l;
|
|
561
|
+
return v != null &&
|
|
562
|
+
typeof v.serviceId === "string" &&
|
|
563
|
+
typeof v.host === "string" &&
|
|
564
|
+
Number.isInteger(v.port) &&
|
|
565
|
+
v.port >= 1 &&
|
|
566
|
+
v.port <= 65535
|
|
567
|
+
? { serviceId: v.serviceId, host: v.host, port: v.port }
|
|
568
|
+
: undefined;
|
|
569
|
+
}
|
|
570
|
+
/** The well-formed entries of a refused-host list ({@link ServiceBlocked.hosts}). */
|
|
571
|
+
function validServiceHosts(hosts) {
|
|
572
|
+
if (!Array.isArray(hosts))
|
|
573
|
+
return [];
|
|
574
|
+
return hosts.filter((h) => typeof h === "object" &&
|
|
575
|
+
h !== null &&
|
|
576
|
+
typeof h.host === "string" &&
|
|
577
|
+
h.host !== "" &&
|
|
578
|
+
["device", "org", "address", "unknown"].includes(h.layer));
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* The outcome with what earlier input rounds carried: their launch review when this round
|
|
582
|
+
* reviewed none, their refused hosts merged before this round's.
|
|
583
|
+
*/
|
|
584
|
+
function withCarried(outcome, carried) {
|
|
585
|
+
if (outcome.kind === "connection_required")
|
|
586
|
+
return outcome;
|
|
587
|
+
if (carried.review === undefined && carried.blocked === undefined)
|
|
588
|
+
return outcome;
|
|
589
|
+
const blocked = carried.blocked === undefined
|
|
590
|
+
? outcome.blocked
|
|
591
|
+
: outcome.blocked === undefined
|
|
592
|
+
? carried.blocked
|
|
593
|
+
: mergeBlocked(carried.blocked, outcome.blocked);
|
|
594
|
+
const review = outcome.review ?? carried.review;
|
|
595
|
+
return {
|
|
596
|
+
...outcome,
|
|
597
|
+
...(blocked !== undefined && { blocked }),
|
|
598
|
+
...(review !== undefined && { review }),
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* The attempt of a device service's call whose network ask was approved (the person added its
|
|
603
|
+
* hosts to the device's list, browser use spec §7.1) with hosts in force from the next command:
|
|
604
|
+
* the call runs again in the next attempt. Null for any other ask, or none.
|
|
605
|
+
*/
|
|
606
|
+
function serviceRerunAfter(ask) {
|
|
607
|
+
const d = ask?.detail;
|
|
608
|
+
if (ask?.status !== "approved" || ask.scope !== "always" || d?.kind !== "service")
|
|
609
|
+
return null;
|
|
610
|
+
// hosts that apply only at the device's next use or after a files reset are not in force for
|
|
611
|
+
// a re-run now: the kept result is written with the outcome's note instead, as for a command
|
|
612
|
+
if (d.appliesAt !== "next-command")
|
|
613
|
+
return null;
|
|
614
|
+
return d.attempt;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* The attempt of an approved loopback port ask: the call runs again after it whatever became of
|
|
618
|
+
* the grant (the approval is the person's decision; a grant the panel made first, or one that
|
|
619
|
+
* ended since, leaves the re-run to meet the port as it is and report it).
|
|
620
|
+
*/
|
|
621
|
+
function loopbackAskRerunAfter(ask) {
|
|
622
|
+
const d = ask?.detail;
|
|
623
|
+
return ask?.status === "approved" && d?.kind === "loopback" ? d.attempt : null;
|
|
624
|
+
}
|
|
625
|
+
function approvedSiteAsk(ask) {
|
|
626
|
+
const detail = ask?.detail;
|
|
627
|
+
if (ask?.status !== "approved" || detail?.kind !== "site")
|
|
628
|
+
return null;
|
|
629
|
+
return {
|
|
630
|
+
attempt: detail.attempt,
|
|
631
|
+
toolSpecHash: detail.toolSpecHash,
|
|
632
|
+
callInputHash: detail.callInputHash,
|
|
633
|
+
deviceId: detail.deviceId,
|
|
634
|
+
approval: {
|
|
635
|
+
action: detail.action,
|
|
636
|
+
origin: detail.origin,
|
|
637
|
+
detailSha256: siteAccessDetailHash(detail.detail),
|
|
638
|
+
source: "human",
|
|
639
|
+
},
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
const siteReviewIdemKey = (runId, callId) => `permission_reviewed:site_access:${runId}:${callId}`;
|
|
643
|
+
/**
|
|
644
|
+
* Every attempt after which the call ran again: a device service's approved network ask
|
|
645
|
+
* ({@link serviceRerunAfter}), an approved loopback port ask ({@link loopbackAskRerunAfter}), or
|
|
646
|
+
* the call's live loopback port grant (Full access or the review model granted the port to the
|
|
647
|
+
* attempt that was refused it).
|
|
648
|
+
*/
|
|
649
|
+
/** The idempotency key of the `permission_reviewed` event tying a ready-grant rerun to a call. */
|
|
650
|
+
const loopbackReadyRerunIdemKey = (runId, callId) => `permission_reviewed:loopback_ready:${runId}:${callId}`;
|
|
651
|
+
function rerunPoints(ask, grant, readyRerun = null, site = null) {
|
|
652
|
+
const points = [
|
|
653
|
+
serviceRerunAfter(ask),
|
|
654
|
+
loopbackAskRerunAfter(ask),
|
|
655
|
+
grant?.attempt ?? null,
|
|
656
|
+
readyRerun,
|
|
657
|
+
site?.attempt ?? null,
|
|
658
|
+
];
|
|
659
|
+
return new Set(points.filter((p) => p !== null));
|
|
660
|
+
}
|
|
661
|
+
/** An ask whose approval runs the call again: it belongs to the attempt that asked. */
|
|
662
|
+
const asksPerAttempt = (ask) => ask.detail?.kind === "service" || ask.detail?.kind === "loopback" || ask.detail?.kind === "site";
|
|
663
|
+
/** A builtin result's kernel-internal network report (see `BuiltinResult.networkReport`). */
|
|
664
|
+
function networkReportOf(result) {
|
|
665
|
+
const r = result?.networkReport;
|
|
666
|
+
if (r === undefined || typeof r.deviceId !== "string" || !Array.isArray(r.blocked)) {
|
|
667
|
+
return undefined;
|
|
668
|
+
}
|
|
669
|
+
const blocked = r.blocked.filter((b) => typeof b === "object" &&
|
|
670
|
+
b !== null &&
|
|
671
|
+
typeof b.host === "string" &&
|
|
672
|
+
typeof b.port === "number" &&
|
|
673
|
+
["device", "org", "address", "unknown"].includes(b.layer));
|
|
674
|
+
return blocked.length === 0 ? undefined : { deviceId: r.deviceId, blocked };
|
|
675
|
+
}
|
|
676
|
+
/** A builtin result's kernel-internal sandbox denial line (`BuiltinResult.networkReport.denialHint`). */
|
|
677
|
+
function denialHintOf(result) {
|
|
678
|
+
const h = result?.networkReport
|
|
679
|
+
?.denialHint;
|
|
680
|
+
if (h === undefined || typeof h.full !== "string" || typeof h.afterAddressFact !== "string") {
|
|
681
|
+
return undefined;
|
|
682
|
+
}
|
|
683
|
+
return { full: h.full, afterAddressFact: h.afterAddressFact };
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* A kernel-internal device code (see `BuiltinResult.loginCode` and `KeptToolResult.loginCode`):
|
|
687
|
+
* the shape is checked again here so a malformed value never reaches the log (the event schema
|
|
688
|
+
* would throw).
|
|
689
|
+
*/
|
|
690
|
+
function validLoginCode(v) {
|
|
691
|
+
const r = v;
|
|
692
|
+
if (r == null ||
|
|
693
|
+
typeof r.url !== "string" ||
|
|
694
|
+
typeof r.code !== "string" ||
|
|
695
|
+
r.url !== GITHUB_DEVICE_LOGIN_URL ||
|
|
696
|
+
!DEVICE_CODE_PATTERN.test(r.code)) {
|
|
697
|
+
return undefined;
|
|
698
|
+
}
|
|
699
|
+
return { url: r.url, code: r.code };
|
|
700
|
+
}
|
|
701
|
+
/** A builtin result's kernel-internal device code (`{ loginCode: { url, code } }`). */
|
|
702
|
+
function loginCodeOf(result) {
|
|
703
|
+
return validLoginCode(result?.loginCode);
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* The display-only `device_code` event of the call whose output carried the code (auto mode spec
|
|
707
|
+
* §6, P-D13). The key is per (run, call), so a retry of that call appends it once; a different
|
|
708
|
+
* call with the same code is deduplicated by value (`EventLog.deviceCodeShown`).
|
|
709
|
+
*/
|
|
710
|
+
function deviceCodeEvent(runId, step, callId, code) {
|
|
711
|
+
return {
|
|
712
|
+
type: "device_code",
|
|
713
|
+
runId,
|
|
714
|
+
idemKey: deviceCodeIdemKey(runId, callId),
|
|
715
|
+
payload: { step, callId, ...code },
|
|
716
|
+
};
|
|
717
|
+
}
|
|
159
718
|
/** 审批的等待时长(小时,四舍五入,至少 1)。 */
|
|
160
719
|
const approvalHours = (a) => Math.max(1, Math.round((new Date(a.expiresAt).getTime() - new Date(a.createdAt).getTime()) / 3_600_000));
|
|
161
720
|
const approvalWait = (a) => ({
|
|
@@ -178,6 +737,18 @@ const inputWait = (q) => ({
|
|
|
178
737
|
let ToolPipeline = class ToolPipeline {
|
|
179
738
|
config;
|
|
180
739
|
txHost;
|
|
740
|
+
permissionAuthority;
|
|
741
|
+
permissionGrants;
|
|
742
|
+
autoGrants;
|
|
743
|
+
permissionLocks;
|
|
744
|
+
sandboxes;
|
|
745
|
+
approvalProfile;
|
|
746
|
+
toolReview;
|
|
747
|
+
resultImages;
|
|
748
|
+
loopbackGrants;
|
|
749
|
+
permissionFacts;
|
|
750
|
+
siteGrants;
|
|
751
|
+
extensions;
|
|
181
752
|
decide;
|
|
182
753
|
deps;
|
|
183
754
|
constructor(kdb, eventLog,
|
|
@@ -186,10 +757,53 @@ let ToolPipeline = class ToolPipeline {
|
|
|
186
757
|
/** The message tools between agents; absent (tests): their calls are refused. */
|
|
187
758
|
messages, registry, credentials, breaker, outputs, approvals, questions, config, log,
|
|
188
759
|
/** Plugin hooks and inline ui contributions; absent (tests): no hooks, cards dropped. */
|
|
189
|
-
host, drift, effective, switches, txHost, hooks
|
|
760
|
+
host, drift, effective, switches, txHost, hooks, networkGrants,
|
|
761
|
+
/** The command review (auto mode spec §5.4); absent in hand-built pipelines. */
|
|
762
|
+
review,
|
|
763
|
+
/** The reviewed call's device facts; absent in hand-built pipelines. */
|
|
764
|
+
devices, permissionAuthority, permissionGrants,
|
|
765
|
+
/** Full access auto-grants, recorded exactly once (absent in hand-built pipelines). */
|
|
766
|
+
autoGrants, permissionLocks,
|
|
767
|
+
/** Starts a cloud device before its first managed call is reviewed (absent: never). */
|
|
768
|
+
sandboxes,
|
|
769
|
+
/**
|
|
770
|
+
* The profile of an ask addressed to the conversation's person (profiles govern every
|
|
771
|
+
* approval, R1); absent with {@link toolReview} (hand-built pipelines): every ask asks.
|
|
772
|
+
*/
|
|
773
|
+
approvalProfile,
|
|
774
|
+
/** The review model's judgment of an ask under Approve for me (R3); absent: every ask asks. */
|
|
775
|
+
toolReview,
|
|
776
|
+
/**
|
|
777
|
+
* Stores the images a tool result carries as `read` copies of the calling conversation (tool
|
|
778
|
+
* result images design §2); absent (hand-built pipelines): images are named as not stored.
|
|
779
|
+
*/
|
|
780
|
+
resultImages,
|
|
781
|
+
/**
|
|
782
|
+
* A device service's loopback port grants (browser loopback port grants); absent (hand-built
|
|
783
|
+
* pipelines): a loopback refusal keeps the address note.
|
|
784
|
+
*/
|
|
785
|
+
loopbackGrants,
|
|
786
|
+
/** The device's sandbox and its provider's support a loopback grant is checked against. */
|
|
787
|
+
permissionFacts, siteGrants, extensions) {
|
|
190
788
|
this.config = config;
|
|
191
789
|
this.txHost = txHost;
|
|
790
|
+
this.permissionAuthority = permissionAuthority;
|
|
791
|
+
this.permissionGrants = permissionGrants;
|
|
792
|
+
this.autoGrants = autoGrants;
|
|
793
|
+
this.permissionLocks = permissionLocks;
|
|
794
|
+
this.sandboxes = sandboxes;
|
|
795
|
+
this.approvalProfile = approvalProfile;
|
|
796
|
+
this.toolReview = toolReview;
|
|
797
|
+
this.resultImages = resultImages;
|
|
798
|
+
this.loopbackGrants = loopbackGrants;
|
|
799
|
+
this.permissionFacts = permissionFacts;
|
|
800
|
+
this.siteGrants = siteGrants;
|
|
801
|
+
this.extensions = extensions;
|
|
192
802
|
this.deps = {
|
|
803
|
+
// the builtins that enter a device on the managed operation route (common.ts
|
|
804
|
+
// `inToolSandbox`, `inSandboxPreparation`): their review is the permission review, whose
|
|
805
|
+
// approvals issue the exact call grants admission reads
|
|
806
|
+
permissionOperations: MANAGED_OPERATION_TOOLS,
|
|
193
807
|
get db() {
|
|
194
808
|
return kdb.db;
|
|
195
809
|
},
|
|
@@ -208,8 +822,10 @@ let ToolPipeline = class ToolPipeline {
|
|
|
208
822
|
effective,
|
|
209
823
|
switches,
|
|
210
824
|
inlineViews: (plugin) => new Set((host?.current(plugin)?.ui ?? [])
|
|
211
|
-
.filter((r) => r.slot.id === "conversation.tool-result.card"
|
|
212
|
-
r.contribution.
|
|
825
|
+
.filter((r) => r.slot.id === "conversation.tool-result.card")
|
|
826
|
+
.map((r) => r.contribution.id)),
|
|
827
|
+
panels: (plugin) => new Set((host?.current(plugin)?.ui ?? [])
|
|
828
|
+
.filter((r) => r.slot.id === "conversation.panel")
|
|
213
829
|
.map((r) => r.contribution.id)),
|
|
214
830
|
onToolsChanged: (orgId, connectorId) => {
|
|
215
831
|
void drift?.onToolsChanged(orgId, connectorId);
|
|
@@ -218,6 +834,14 @@ let ToolPipeline = class ToolPipeline {
|
|
|
218
834
|
return subagents ? { dispatch: (a) => subagents.dispatch(a) } : undefined;
|
|
219
835
|
},
|
|
220
836
|
messages,
|
|
837
|
+
review,
|
|
838
|
+
devices,
|
|
839
|
+
network: networkGrants
|
|
840
|
+
? {
|
|
841
|
+
grants: networkGrants,
|
|
842
|
+
...(this.sandboxes !== undefined && { sandbox: this.sandboxes }),
|
|
843
|
+
}
|
|
844
|
+
: undefined,
|
|
221
845
|
};
|
|
222
846
|
const decide = hooks?.decidePolicy;
|
|
223
847
|
// the default policy reads live, on the context's handle
|
|
@@ -230,12 +854,21 @@ let ToolPipeline = class ToolPipeline {
|
|
|
230
854
|
* 某个调用需要等人处理(审批 / 用户输入)→ 返回 `suspended`,之后的调用留到续跑时处理;
|
|
231
855
|
* 续跑时重新进入本函数,按 PG 里的审批 / 输入请求结果继续。
|
|
232
856
|
*/
|
|
233
|
-
async runStep(
|
|
857
|
+
async runStep(given) {
|
|
858
|
+
let ctx = given;
|
|
234
859
|
const { eventLog } = this.deps;
|
|
235
860
|
const msg = await eventLog.findByIdem(ctx.conversationId, assistantIdemKey(ctx.runId, ctx.step));
|
|
236
861
|
if (msg?.type !== "assistant_message")
|
|
237
862
|
return { kind: "done" };
|
|
238
863
|
const calls = msg.payload.content.flatMap((b) => b.type === "tool_call" ? [{ id: b.id, name: b.name, input: b.input }] : []);
|
|
864
|
+
// scheduled tasks spec §7: read live for each step (a person's message absorbed since makes the
|
|
865
|
+
// rest of the run attended)
|
|
866
|
+
if (calls.length > 0 && ctx.unattended === undefined) {
|
|
867
|
+
ctx = {
|
|
868
|
+
...ctx,
|
|
869
|
+
unattended: await unattendedRunOf(this.deps.db, this.config, ctx.orgId, ctx.runId),
|
|
870
|
+
};
|
|
871
|
+
}
|
|
239
872
|
let resolved;
|
|
240
873
|
const resolve = async () => {
|
|
241
874
|
// 每步实时解析(连接器 / 插件状态可能在模型调用之后变化)
|
|
@@ -252,6 +885,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
252
885
|
forkChild: ctx.parent?.forSkill === true,
|
|
253
886
|
sandboxConversationId: ctx.parent?.rootConversationId ?? ctx.conversationId,
|
|
254
887
|
replay: ctx.conversationKind === "eval",
|
|
888
|
+
source: ctx.source,
|
|
255
889
|
});
|
|
256
890
|
}
|
|
257
891
|
return resolved;
|
|
@@ -269,7 +903,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
269
903
|
}
|
|
270
904
|
/**
|
|
271
905
|
* Writes, in the caller's transaction (`mandatory`), what a run that is being stopped (a person,
|
|
272
|
-
* its deadline, a failure,
|
|
906
|
+
* its deadline, a failure, an orphan repair) still owes its log: the report of its fork invocation
|
|
273
907
|
* (phase D, `pairStoppedForks`; a still active fork child is stopped by the caller after its
|
|
274
908
|
* commit). An `Agent` call has its result from its dispatch (agent map spec §4.1), so there is
|
|
275
909
|
* nothing to write for it. Returns the fork's call id (the caller must not write a "not executed"
|
|
@@ -289,24 +923,143 @@ let ToolPipeline = class ToolPipeline {
|
|
|
289
923
|
const last = rounds.at(-1);
|
|
290
924
|
if (last?.status === "pending")
|
|
291
925
|
return inputWait(last);
|
|
292
|
-
|
|
293
|
-
|
|
926
|
+
// skipped by the starter's message: the kernel writes the result, the tool is not called again
|
|
927
|
+
// (spec D6: an extension would only see `answer: null`, an MCP call would be re-sent)
|
|
928
|
+
if (last?.status === "skipped") {
|
|
929
|
+
await this.writeResult(ctx, call.id, last.toolKey, skippedResult(last.toolKey, last.watch === true));
|
|
930
|
+
return undefined;
|
|
931
|
+
}
|
|
932
|
+
// a cancelled round is cancelled only by its run's stop, which writes the stopped result
|
|
933
|
+
// itself: it never resumes (browser long waits spec §5.1, R24)
|
|
934
|
+
if (last?.status === "cancelled") {
|
|
935
|
+
this.deps.log.error("a cancelled input round reached a resume; writing the stopped result", {
|
|
936
|
+
runId: ctx.runId,
|
|
937
|
+
callId: call.id,
|
|
938
|
+
questionId: last.id,
|
|
939
|
+
});
|
|
940
|
+
await this.writeResult(ctx, call.id, last.toolKey, {
|
|
941
|
+
content: INPUT_CANCELLED_TEXT,
|
|
942
|
+
isError: true,
|
|
943
|
+
});
|
|
944
|
+
return undefined;
|
|
945
|
+
}
|
|
946
|
+
// the call's network ask (one per call) and its live loopback port grant
|
|
947
|
+
const ask = await this.deps.approvals.networkForCall(ctx.runId, call.id);
|
|
948
|
+
const grant = await this.loopbackGrantOf(ctx.runId, call.id);
|
|
949
|
+
const readyRerun = await this.readyLoopbackRerunOf(ctx.conversationId, ctx.runId, call.id);
|
|
950
|
+
const site = approvedSiteAsk(ask) ?? (await this.siteRerunOf(ctx, call.id));
|
|
951
|
+
let attempt = rounds.length + 1;
|
|
952
|
+
// each time the call ran again (after its network ask, browser use spec §7.1, or a loopback
|
|
953
|
+
// grant or ask) took one attempt more: input rounds asked after a re-run come after it, so
|
|
954
|
+
// every re-run point the count has passed adds one, in order
|
|
955
|
+
const reruns = rerunPoints(ask, grant, readyRerun, site);
|
|
956
|
+
if (rounds.length > 0) {
|
|
957
|
+
for (const p of [...reruns].sort((a, b) => a - b))
|
|
958
|
+
if (attempt > p)
|
|
959
|
+
attempt += 1;
|
|
960
|
+
}
|
|
961
|
+
const resume = last
|
|
962
|
+
? {
|
|
963
|
+
state: last.state,
|
|
964
|
+
answer: last.status === "answered" ? last.answer : null,
|
|
965
|
+
outcome: last.status === "answered" ? "answered" : last.status === "woken" ? "woken" : "expired",
|
|
966
|
+
}
|
|
967
|
+
: undefined;
|
|
968
|
+
let started = await this.deps.eventLog.findByIdem(ctx.conversationId, idem.started(ctx.runId, call.id, attempt));
|
|
969
|
+
// a call that ran again (after a loopback grant or an approved ask) is looked at in its latest
|
|
970
|
+
// attempt: a re-run that asked a network ask of its own resumes from that ask
|
|
971
|
+
while (started?.type === "tool_call_started" && reruns.has(attempt)) {
|
|
972
|
+
const next = await this.deps.eventLog.findByIdem(ctx.conversationId, idem.started(ctx.runId, call.id, attempt + 1));
|
|
973
|
+
if (next?.type !== "tool_call_started")
|
|
974
|
+
break;
|
|
975
|
+
attempt += 1;
|
|
976
|
+
started = next;
|
|
977
|
+
}
|
|
294
978
|
if (started?.type === "tool_call_started") {
|
|
979
|
+
// a command that ran and was refused a network host waits for the device owner (network
|
|
980
|
+
// ask-to-allow spec §6.2, P-D2): pending → wait on; settled → its kept result and the
|
|
981
|
+
// outcome's note (the command is never run again; its tool.called was audited when it ran).
|
|
982
|
+
// A device service's ask (browser use spec §7.1) belongs to the attempt that asked; once
|
|
983
|
+
// the person added its hosts to the device's list the call runs again in the next attempt
|
|
984
|
+
// A loopback port ask (browser loopback port grants) too; a port that Full access or the
|
|
985
|
+
// review model granted to this attempt has no ask: its grant row names the attempt, so the
|
|
986
|
+
// call runs again in the next one, also after a crash between the grant and the re-run
|
|
987
|
+
const askedHere = ask !== null &&
|
|
988
|
+
(!asksPerAttempt(ask) ||
|
|
989
|
+
ask.detail?.attempt === attempt);
|
|
990
|
+
const grantedHere = !askedHere && grant !== null && grant.attempt === attempt;
|
|
991
|
+
const readyRerunHere = !askedHere && !grantedHere && readyRerun === attempt;
|
|
992
|
+
const siteRerunHere = site !== null && site.attempt === attempt;
|
|
993
|
+
if (askedHere || grantedHere || readyRerunHere || siteRerunHere) {
|
|
994
|
+
const notes = askedHere && ask !== null
|
|
995
|
+
? settledNetworkNotes(ask, approvalHours(ask))
|
|
996
|
+
: grantedHere
|
|
997
|
+
? [loopbackGrantedNote(grant.port)]
|
|
998
|
+
: [];
|
|
999
|
+
if (notes === null)
|
|
1000
|
+
return approvalWait(ask);
|
|
1001
|
+
const rerunsHere = !askedHere ||
|
|
1002
|
+
serviceRerunAfter(ask) !== null ||
|
|
1003
|
+
loopbackAskRerunAfter(ask) !== null ||
|
|
1004
|
+
siteRerunHere ||
|
|
1005
|
+
grant?.attempt === attempt;
|
|
1006
|
+
if (askedHere && ask !== null && !rerunsHere) {
|
|
1007
|
+
const kept = ask.detail?.result;
|
|
1008
|
+
// the device code the command printed is carried in the kept result: write its
|
|
1009
|
+
// display-only event here too (a crash before the ask's first write, or an older kept
|
|
1010
|
+
// result; the event's ids and the per-conversation code check keep it to one)
|
|
1011
|
+
const keptCode = validLoginCode(kept?.loginCode);
|
|
1012
|
+
const pre = keptCode !== undefined &&
|
|
1013
|
+
!(await this.deps.eventLog.deviceCodeShown(ctx.conversationId, keptCode.code))
|
|
1014
|
+
? [deviceCodeEvent(ctx.runId, ctx.step, call.id, keptCode)]
|
|
1015
|
+
: [];
|
|
1016
|
+
await this.writeResult(ctx, call.id, call.name, {
|
|
1017
|
+
...keptExtras(kept),
|
|
1018
|
+
content: withNetworkNotes(kept?.content ?? UNKNOWN_RESULT_TEXT, notes),
|
|
1019
|
+
isError: kept?.isError ?? true,
|
|
1020
|
+
...(kept?.review !== undefined && { review: kept.review }),
|
|
1021
|
+
}, pre);
|
|
1022
|
+
return undefined;
|
|
1023
|
+
}
|
|
1024
|
+
const rerun = await this.deps.eventLog.findByIdem(ctx.conversationId, idem.started(ctx.runId, call.id, attempt + 1));
|
|
1025
|
+
if (rerun?.type !== "tool_call_started") {
|
|
1026
|
+
// the asked hosts are settled: only an earlier round's launch review is carried; a
|
|
1027
|
+
// granted loopback port's note goes with the re-run's result
|
|
1028
|
+
const { review: carriedReview } = carriedOf(rounds);
|
|
1029
|
+
const loopback = !siteRerunHere && (!askedHere || ask?.detail?.kind === "loopback");
|
|
1030
|
+
return this.runCall(ctx, call, await resolve(), attempt + 1, resume, { ...(carriedReview !== undefined && { review: carriedReview }) }, siteRerunHere ? { site } : loopback ? { notes, loopbackRerun: true } : {});
|
|
1031
|
+
}
|
|
1032
|
+
// the re-run started and its result was lost: the result is unknown, as below
|
|
1033
|
+
started = rerun;
|
|
1034
|
+
}
|
|
295
1035
|
// 确实开始执行过:照样审计 tool.called(耗时未知);放行依据只认批准了所执行定义的审批记录
|
|
296
1036
|
const key = started.payload.toolKey;
|
|
297
1037
|
const approval = await this.deps.approvals.forCall(ctx.runId, call.id);
|
|
298
1038
|
const approved = approval?.status === "approved" && approval.specHash === started.payload.specHash
|
|
299
1039
|
? approval
|
|
300
1040
|
: null;
|
|
1041
|
+
// a command that ran under the person's `command` approval: its review record and
|
|
1042
|
+
// authorization survive the lost result too (the ask is the whole truth on a resume)
|
|
1043
|
+
const commandAsk = await this.deps.approvals.commandForCall(ctx.runId, call.id);
|
|
1044
|
+
const command = commandAsk?.status === "approved" ? commandAsk : null;
|
|
1045
|
+
const authorization = approved !== null
|
|
1046
|
+
? approvalAuthorization(approved)
|
|
1047
|
+
: command !== null
|
|
1048
|
+
? approvalAuthorization(command)
|
|
1049
|
+
: null;
|
|
301
1050
|
const source = approved ? null : (await resolve()).tools.find((t) => t.key === key)?.source;
|
|
302
|
-
await this.writeResult(ctx, call.id, key, {
|
|
1051
|
+
await this.writeResult(ctx, call.id, key, {
|
|
1052
|
+
content: UNKNOWN_RESULT_TEXT,
|
|
1053
|
+
isError: true,
|
|
1054
|
+
...(command !== null && { review: this.personAllowRecord(command) }),
|
|
1055
|
+
}, [], {
|
|
303
1056
|
durationMs: null,
|
|
304
1057
|
connectorId: approved
|
|
305
1058
|
? approved.connectorId
|
|
306
1059
|
: source?.kind === "connector"
|
|
307
1060
|
? source.connectorId
|
|
308
1061
|
: null,
|
|
309
|
-
...(
|
|
1062
|
+
...(authorization !== null && { authorization }),
|
|
310
1063
|
});
|
|
311
1064
|
return undefined;
|
|
312
1065
|
}
|
|
@@ -317,31 +1070,34 @@ let ToolPipeline = class ToolPipeline {
|
|
|
317
1070
|
});
|
|
318
1071
|
return undefined;
|
|
319
1072
|
}
|
|
320
|
-
|
|
321
|
-
? { state: last.state, answer: last.status === "answered" ? last.answer : null }
|
|
322
|
-
: undefined;
|
|
323
|
-
return this.runCall(ctx, call, await resolve(), attempt, resume);
|
|
1073
|
+
return this.runCall(ctx, call, await resolve(), attempt, resume, carriedOf(rounds));
|
|
324
1074
|
}
|
|
325
|
-
async runCall(ctx, call, resolved, attempt, resume
|
|
326
|
-
|
|
327
|
-
|
|
1075
|
+
async runCall(ctx, call, resolved, attempt, resume,
|
|
1076
|
+
/** What earlier input rounds of the call collected for its result ({@link carriedOf}). */
|
|
1077
|
+
carried = {},
|
|
1078
|
+
/**
|
|
1079
|
+
* A re-run after a granted loopback port: the notes written after its result, and that it is
|
|
1080
|
+
* the re-run (a port still refused is not asked about again in it).
|
|
1081
|
+
*/
|
|
1082
|
+
rerun = {}) {
|
|
1083
|
+
// the command review's record for this call's result (absent: not reviewed, or no device)
|
|
1084
|
+
let review;
|
|
1085
|
+
const fail = async (content, key = call.name, view) => {
|
|
1086
|
+
await this.writeResult(ctx, call.id, key, {
|
|
1087
|
+
content,
|
|
1088
|
+
isError: true,
|
|
1089
|
+
...(view !== undefined && { view }),
|
|
1090
|
+
...(review !== undefined && { review }),
|
|
1091
|
+
});
|
|
328
1092
|
return undefined;
|
|
329
1093
|
};
|
|
330
|
-
|
|
331
|
-
// A call logged before the tool keys were renamed (spec 8.1): the request that issued it offered
|
|
332
|
-
// the old key. It runs as the current tool with translated input; the result keeps the logged key.
|
|
333
|
-
let legacy = false;
|
|
334
|
-
if (!tool) {
|
|
335
|
-
const next = legacyToolKey(call.name, legacyScopeOf(resolved.tools));
|
|
336
|
-
const current = next === null ? undefined : resolved.tools.find((t) => t.key === next);
|
|
337
|
-
if (current && (await this.requestToolKeys(ctx))?.has(call.name) === true) {
|
|
338
|
-
tool = current;
|
|
339
|
-
legacy = true;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
1094
|
+
const tool = resolved.tools.find((t) => t.key === call.name);
|
|
342
1095
|
if (!tool) {
|
|
1096
|
+
// a hidden `<prefix>__*` ref covers every tool of that source (a disabled or needs_config
|
|
1097
|
+
// connector), so a call of one of them gets the reason, not "unknown tool"
|
|
1098
|
+
const covers = (ref) => ref === call.name || (ref.endsWith("__*") && call.name.startsWith(ref.slice(0, -1)));
|
|
343
1099
|
const why = resolved.unavailable.find((u) => u.ref === call.name) ??
|
|
344
|
-
resolved.hidden?.find((u) => u.ref
|
|
1100
|
+
resolved.hidden?.find((u) => covers(u.ref));
|
|
345
1101
|
if (why)
|
|
346
1102
|
return fail(unavailableText(call.name, why.reason));
|
|
347
1103
|
let keys = resolved.tools.map((t) => t.key);
|
|
@@ -352,20 +1108,22 @@ let ToolPipeline = class ToolPipeline {
|
|
|
352
1108
|
keys = keys.filter((k) => isAlwaysLoaded(k) || sent.has(k));
|
|
353
1109
|
}
|
|
354
1110
|
keys.sort();
|
|
355
|
-
|
|
1111
|
+
// In ToolSearch mode a name the model has not loaded (a catalog tool, or one it misspelled) is
|
|
1112
|
+
// the protocol asking it to search, not a failure: the row reads neutral like `not_loaded`.
|
|
1113
|
+
return fail(unknownToolText(call.name, keys, keys.includes(TOOL_SEARCH)), call.name, resolved.toolSearch === true ? { kind: "not_loaded" } : undefined);
|
|
356
1114
|
}
|
|
357
|
-
const outKey =
|
|
1115
|
+
const outKey = tool.key;
|
|
358
1116
|
// ToolSearch 模式下,模型只能调用请求里带了完整定义的工具:目录里有、但发出本次调用的请求没加载 →
|
|
359
1117
|
// 明确错误,不自动加载(spec 5.5 / 6.3)。同一步里先 ToolSearch 再调用刚加载的工具同样报错。
|
|
360
|
-
|
|
1118
|
+
// This is the protocol working, not a failure: the `not_loaded` view lets the row read neutral.
|
|
1119
|
+
if (resolved.toolSearch === true && !isAlwaysLoaded(tool.key)) {
|
|
361
1120
|
const sent = await this.sentTools(ctx);
|
|
362
1121
|
if (sent !== null && !sent.has(tool.key))
|
|
363
|
-
return fail(notLoadedText(tool.key), outKey);
|
|
1122
|
+
return fail(notLoadedText(tool.key), outKey, { kind: "not_loaded" });
|
|
364
1123
|
}
|
|
365
|
-
const rawInput = legacy ? legacyToolInput(call.name, call.input) : call.input;
|
|
366
1124
|
let input;
|
|
367
1125
|
try {
|
|
368
|
-
input = await resolveOutputRefs(
|
|
1126
|
+
input = await resolveOutputRefs(call.input, (id) => this.deps.outputs.load({ orgId: ctx.orgId, conversationId: ctx.conversationId }, id));
|
|
369
1127
|
}
|
|
370
1128
|
catch (e) {
|
|
371
1129
|
if (e instanceof ToolError)
|
|
@@ -386,8 +1144,10 @@ let ToolPipeline = class ToolPipeline {
|
|
|
386
1144
|
accountId: ctx.accountId,
|
|
387
1145
|
agentId: ctx.agentId,
|
|
388
1146
|
conversationId: ctx.conversationId,
|
|
1147
|
+
rootConversationId: ctx.parent?.rootConversationId ?? ctx.conversationId,
|
|
389
1148
|
runId: ctx.runId,
|
|
390
|
-
|
|
1149
|
+
callId: call.id,
|
|
1150
|
+
rawInput: call.input,
|
|
391
1151
|
signal: ctx.signal,
|
|
392
1152
|
})) ?? null;
|
|
393
1153
|
// a deny with a reason (e.g. an unavailable operation): the reason is the tool error
|
|
@@ -395,7 +1155,20 @@ let ToolPipeline = class ToolPipeline {
|
|
|
395
1155
|
return fail(callPolicy.denyReason, outKey);
|
|
396
1156
|
}
|
|
397
1157
|
const policyKey = callPolicy?.key ?? tool.key;
|
|
398
|
-
|
|
1158
|
+
// person fields (platform web parity spec §4.2; profiles govern every approval R4, R5): the
|
|
1159
|
+
// person types the values in a secure input request, so an unattended run (a trial run has its
|
|
1160
|
+
// creator there) cannot make the call at all
|
|
1161
|
+
const personFields = callPolicy?.personFields;
|
|
1162
|
+
// a call whose result is shown once to the run's person is refused there the same way
|
|
1163
|
+
const personOnly = callPolicy?.personOnly === true;
|
|
1164
|
+
if ((personFields !== undefined || personOnly) && unattendedRules(ctx.unattended)) {
|
|
1165
|
+
return fail(personFields !== undefined
|
|
1166
|
+
? PERSON_FIELDS_UNATTENDED_TEXT
|
|
1167
|
+
: callPolicy?.personDecides === true
|
|
1168
|
+
? PERSON_DECIDES_UNATTENDED_TEXT
|
|
1169
|
+
: PERSON_ONLY_UNATTENDED_TEXT, outKey);
|
|
1170
|
+
}
|
|
1171
|
+
let decision = await this.decide(tool, ctx.agent, {
|
|
399
1172
|
orgId: ctx.orgId,
|
|
400
1173
|
accountId: ctx.accountId,
|
|
401
1174
|
agentId: ctx.agentId,
|
|
@@ -407,28 +1180,85 @@ let ToolPipeline = class ToolPipeline {
|
|
|
407
1180
|
...(ctx.parent.otherAgent !== undefined && { parentAgentDiffers: ctx.parent.otherAgent }),
|
|
408
1181
|
}),
|
|
409
1182
|
callPolicy,
|
|
1183
|
+
...(ctx.unattended != null && { unattended: ctx.unattended }),
|
|
410
1184
|
});
|
|
411
1185
|
if (decision === "deny")
|
|
412
1186
|
return fail(deniedText(tool.key, callPolicy?.key), outKey);
|
|
1187
|
+
if (typeof decision === "object" && "refused" in decision) {
|
|
1188
|
+
if (decision.missingGrant !== undefined && ctx.unattended != null) {
|
|
1189
|
+
await appendMissingGrant(this.deps.db, ctx.unattended.taskRunId, decision.missingGrant);
|
|
1190
|
+
}
|
|
1191
|
+
return fail(decision.refused, outKey);
|
|
1192
|
+
}
|
|
413
1193
|
if (typeof decision === "object" && "unavailable" in decision) {
|
|
414
1194
|
return fail(unavailableText(tool.key, decision.unavailable), outKey);
|
|
415
1195
|
}
|
|
1196
|
+
if (personOnly || personFields !== undefined) {
|
|
1197
|
+
// R6: a call only the person may confirm is always their own ask, never a grant or an
|
|
1198
|
+
// `allow` (the default policy already asks for them; this holds for any decision). Person
|
|
1199
|
+
// fields no longer force the consent (R5): it follows the call's policy, grants and profile
|
|
1200
|
+
if (personOnly && (decision === "allow" || "grant" in decision)) {
|
|
1201
|
+
decision = {
|
|
1202
|
+
ask: {
|
|
1203
|
+
toolKey: policyKey,
|
|
1204
|
+
specHash: tool.specHash,
|
|
1205
|
+
connectorId: tool.source.kind === "connector" ? tool.source.connectorId : null,
|
|
1206
|
+
requestedFor: ctx.accountId,
|
|
1207
|
+
approverRole: null,
|
|
1208
|
+
policy: "fixed",
|
|
1209
|
+
},
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
// R5: only the person the run works for types the values or reads the result; a role
|
|
1213
|
+
// escalation cannot ask them
|
|
1214
|
+
if (typeof decision === "object" && "ask" in decision && decision.ask.requestedFor === null) {
|
|
1215
|
+
return fail(personFields !== undefined ? PERSON_FIELDS_ROLE_TEXT : PERSON_ONLY_ROLE_TEXT, outKey);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
416
1218
|
// 该调用已有审批(续跑)→ 按审批结果;没有且策略为 ask → 建审批并等待
|
|
417
1219
|
// (不写 tool_call_started:此时尚未开始执行)。
|
|
418
1220
|
let approval = await this.deps.approvals.forCall(ctx.runId, call.id);
|
|
419
1221
|
// 批准的是旧定义(等待期间工具定义变了):原批准不适用于当前定义,策略仍需审批时按新定义重新审批。
|
|
420
|
-
// An in-flight rc call (spec §9) is the exception: its approval was asked under the rc definition
|
|
421
|
-
// of the same call, and the rename changed every builtin's definition; the person approved this
|
|
422
|
-
// very call, so the approval stands.
|
|
423
1222
|
// An approval binds the exact input it showed (Platform tool spec §6.3): an approved record
|
|
424
1223
|
// whose stored input differs from the call's is not used.
|
|
1224
|
+
const liveAsk = typeof decision === "object" && "ask" in decision ? decision.ask : undefined;
|
|
1225
|
+
const orgAskChanged = approval !== null &&
|
|
1226
|
+
(!sameOrgAsk(approval.orgAskRevisions, liveAsk?.orgAskRevisions) ||
|
|
1227
|
+
(liveAsk?.orgAskRevisions !== undefined &&
|
|
1228
|
+
(approval.toolKey !== policyKey ||
|
|
1229
|
+
approval.specHash !== tool.specHash ||
|
|
1230
|
+
approval.requestedFor !== liveAsk.requestedFor ||
|
|
1231
|
+
approval.approverRole !== liveAsk.approverRole ||
|
|
1232
|
+
canonicalJson(approval.input) !== canonicalJson(call.input ?? {}))));
|
|
1233
|
+
const supersedesOrgAsk = orgAskChanged ? approval?.id : undefined;
|
|
1234
|
+
if (orgAskChanged || approval?.status === "superseded")
|
|
1235
|
+
approval = null;
|
|
425
1236
|
const approvedHere = approval?.status === "approved" &&
|
|
426
|
-
|
|
1237
|
+
approval.specHash === tool.specHash &&
|
|
1238
|
+
(liveAsk?.orgAskRevisions === undefined ||
|
|
1239
|
+
(approval.scope === "once" && approval.decidedBy !== null)) &&
|
|
427
1240
|
canonicalJson(approval.input) === canonicalJson(call.input ?? {});
|
|
428
1241
|
const stale = approval?.status === "approved" && !approvedHere;
|
|
1242
|
+
// the profile step (profiles govern every approval, R1-R3): an ask addressed to the person
|
|
1243
|
+
// with no approval governing the call yet is decided by the conversation's profile
|
|
1244
|
+
let auto;
|
|
1245
|
+
let reviewUnsure = false;
|
|
429
1246
|
if ((!approval || stale) && typeof decision === "object" && "ask" in decision) {
|
|
1247
|
+
const step = await this.profileStep(ctx, call, tool, input, decision.ask, callPolicy);
|
|
1248
|
+
if (step.kind === "deny")
|
|
1249
|
+
return fail(toolReviewDeniedText(step.reason), outKey);
|
|
1250
|
+
if (step.kind === "allow")
|
|
1251
|
+
auto = step.decision;
|
|
1252
|
+
else
|
|
1253
|
+
reviewUnsure = step.unsure;
|
|
1254
|
+
}
|
|
1255
|
+
if ((!approval || stale) &&
|
|
1256
|
+
auto === undefined &&
|
|
1257
|
+
typeof decision === "object" &&
|
|
1258
|
+
"ask" in decision) {
|
|
430
1259
|
approval = await this.deps.approvals.request({
|
|
431
|
-
|
|
1260
|
+
// after every earlier request of the call, whatever its kind (attempts share one key)
|
|
1261
|
+
attempt: (await this.lastAttempt(ctx.runId, call.id)) + 1,
|
|
432
1262
|
orgId: ctx.orgId,
|
|
433
1263
|
conversationId: ctx.conversationId,
|
|
434
1264
|
runId: ctx.runId,
|
|
@@ -442,7 +1272,20 @@ let ToolPipeline = class ToolPipeline {
|
|
|
442
1272
|
approverRole: decision.ask.approverRole,
|
|
443
1273
|
policy: decision.ask.policy,
|
|
444
1274
|
...(callPolicy?.summary !== undefined && { summary: callPolicy.summary }),
|
|
445
|
-
...(
|
|
1275
|
+
...(supersedesOrgAsk !== undefined && { supersedesOrgAsk }),
|
|
1276
|
+
...((decision.ask.orgAskRevisions !== undefined ||
|
|
1277
|
+
(callPolicy !== null && !callPolicy.remember)) && { scopes: ["once"] }),
|
|
1278
|
+
...((callPolicy?.file !== undefined ||
|
|
1279
|
+
reviewUnsure ||
|
|
1280
|
+
decision.ask.orgAskRevisions !== undefined) && {
|
|
1281
|
+
detail: {
|
|
1282
|
+
...(callPolicy?.file !== undefined && { file: callPolicy.file }),
|
|
1283
|
+
...(reviewUnsure && { reviewUnsure: true }),
|
|
1284
|
+
...(decision.ask.orgAskRevisions !== undefined && {
|
|
1285
|
+
orgAskRevisions: decision.ask.orgAskRevisions,
|
|
1286
|
+
}),
|
|
1287
|
+
},
|
|
1288
|
+
}),
|
|
446
1289
|
});
|
|
447
1290
|
}
|
|
448
1291
|
if (approval && approval.status !== "approved") {
|
|
@@ -450,16 +1293,52 @@ let ToolPipeline = class ToolPipeline {
|
|
|
450
1293
|
return refused === null ? approvalWait(approval) : fail(refused, outKey);
|
|
451
1294
|
}
|
|
452
1295
|
// 走到这里即放行:在(与当前定义一致的)审批下执行,否则是授权或策略放行
|
|
453
|
-
|
|
1296
|
+
let authorization = approval?.status === "approved" && approvedHere
|
|
454
1297
|
? approvalAuthorization(approval)
|
|
455
|
-
:
|
|
456
|
-
? {
|
|
457
|
-
:
|
|
1298
|
+
: auto !== undefined
|
|
1299
|
+
? { decisionSource: auto.source, profileRevision: auto.revision, decisionSeq: auto.seq }
|
|
1300
|
+
: typeof decision === "object" && "grant" in decision
|
|
1301
|
+
? { grant: decision.grant }
|
|
1302
|
+
: { policy: "allow" };
|
|
1303
|
+
// the secure input (profiles govern every approval, R4): once the call's consent is settled
|
|
1304
|
+
// (approved here, a grant, an allow or the profile's decision), the person enters the call's
|
|
1305
|
+
// secret fields under every profile, before the command review
|
|
1306
|
+
let secureInputId;
|
|
1307
|
+
if (personFields !== undefined) {
|
|
1308
|
+
const secured = await this.secureInput(ctx, call, tool, policyKey, personFields);
|
|
1309
|
+
if (secured.kind === "wait")
|
|
1310
|
+
return secured.wait;
|
|
1311
|
+
if (secured.kind === "refused")
|
|
1312
|
+
return fail(secured.text, outKey);
|
|
1313
|
+
secureInputId = secured.id;
|
|
1314
|
+
}
|
|
1315
|
+
// Auto mode spec §5.1: the command review, after argument validation and the tool policy (and
|
|
1316
|
+
// its approval), before the plugin hooks and `tool_call_started`. A deny ends the call here; an
|
|
1317
|
+
// ask parks the run on the command approval (attended) or is a deny at once (unattended). An
|
|
1318
|
+
// already decided command approval resumes the call without re-reviewing.
|
|
1319
|
+
const reviewed = await this.reviewCall(ctx, call, tool, input);
|
|
1320
|
+
if (reviewed.kind === "wait")
|
|
1321
|
+
return reviewed.wait;
|
|
1322
|
+
if (reviewed.kind === "result") {
|
|
1323
|
+
review = reviewed.review;
|
|
1324
|
+
return fail(reviewed.content, outKey);
|
|
1325
|
+
}
|
|
1326
|
+
review = reviewed.review;
|
|
1327
|
+
const reviewedRoots = {
|
|
1328
|
+
workingRoot: reviewed.workingRoot,
|
|
1329
|
+
against: reviewed.reviewedAgainst,
|
|
1330
|
+
...(reviewed.sandboxEscalation !== undefined && { escalation: reviewed.sandboxEscalation }),
|
|
1331
|
+
...(reviewed.sandboxEscalationRefusal !== undefined && {
|
|
1332
|
+
escalationRefusal: reviewed.sandboxEscalationRefusal,
|
|
1333
|
+
}),
|
|
1334
|
+
};
|
|
1335
|
+
if (reviewed.commandAsk !== undefined)
|
|
1336
|
+
authorization = approvalAuthorization(reviewed.commandAsk);
|
|
458
1337
|
// tool.preExecute after policy and approval, before tool_call_started (F10)
|
|
459
1338
|
const hooks = this.deps.pluginHooks;
|
|
460
1339
|
const scope = hookScope(hooks, ctx);
|
|
461
1340
|
if (scope && hooks?.has("tool.preExecute")) {
|
|
462
|
-
// sticky: a denial already logged for this call (e.g.
|
|
1341
|
+
// sticky: a denial already logged for this call (e.g. a crash right after it)
|
|
463
1342
|
// is final: fail with the recorded reason, never re-run the hooks or execute the tool. Only
|
|
464
1343
|
// looked up when a tool.preExecute hook could run (M-2: no query without hooks); a denial is
|
|
465
1344
|
// written with the call's tool_result, so a call with a logged denial never runs again anyway.
|
|
@@ -505,10 +1384,27 @@ let ToolPipeline = class ToolPipeline {
|
|
|
505
1384
|
step: ctx.step,
|
|
506
1385
|
callId: call.id,
|
|
507
1386
|
});
|
|
508
|
-
await this.writeResult(ctx, call.id, outKey, {
|
|
1387
|
+
await this.writeResult(ctx, call.id, outKey, {
|
|
1388
|
+
content: hookDeniedText(verdict.plugin, verdict.reason),
|
|
1389
|
+
isError: true,
|
|
1390
|
+
...(review !== undefined && { review }),
|
|
1391
|
+
}, [event], undefined, [hookDeniedAudit(site, event.payload, verdict)]);
|
|
509
1392
|
return undefined;
|
|
510
1393
|
}
|
|
511
1394
|
}
|
|
1395
|
+
const admit = (commit) => this.withOrgToolAdmission(ctx, tool, policyKey, call.input, approvedHere ? approval : null, auto, commit);
|
|
1396
|
+
const admissionError = (error) => {
|
|
1397
|
+
if (error instanceof OrgToolDenied || error instanceof OrgToolPolicyChanged)
|
|
1398
|
+
return error;
|
|
1399
|
+
throw error;
|
|
1400
|
+
};
|
|
1401
|
+
const changedPolicy = (error) => {
|
|
1402
|
+
if (error instanceof OrgToolDenied)
|
|
1403
|
+
return fail(deniedText(tool.key, callPolicy?.key), outKey);
|
|
1404
|
+
if (error instanceof OrgToolPolicyChanged)
|
|
1405
|
+
return this.runCall(ctx, call, resolved, attempt, resume, carried, rerun);
|
|
1406
|
+
throw error;
|
|
1407
|
+
};
|
|
512
1408
|
// `Agent` (sub-agents spec §7.1, agent map spec §4.1): no tool_call_started; one transaction
|
|
513
1409
|
// makes the dispatch durable (its marker is the subagent_dispatches row) and writes the call's
|
|
514
1410
|
// immediate result, while the sub-agent runs in the background
|
|
@@ -518,12 +1414,17 @@ let ToolPipeline = class ToolPipeline {
|
|
|
518
1414
|
if (!parsed.success) {
|
|
519
1415
|
return fail("Invalid agent call: pass description and prompt, and optionally subagent_type and model.", outKey);
|
|
520
1416
|
}
|
|
521
|
-
const r = await dispatcher
|
|
1417
|
+
const r = await dispatcher
|
|
1418
|
+
.dispatch({
|
|
522
1419
|
ctx,
|
|
523
1420
|
callId: call.id,
|
|
524
1421
|
input: parsed.data,
|
|
525
1422
|
call: { toolKey: outKey, authorization, startedAt: Date.now() },
|
|
526
|
-
|
|
1423
|
+
admit,
|
|
1424
|
+
})
|
|
1425
|
+
.catch(admissionError);
|
|
1426
|
+
if (r instanceof Error)
|
|
1427
|
+
return changedPolicy(r);
|
|
527
1428
|
if (r.kind === "refused")
|
|
528
1429
|
return fail(r.content, outKey);
|
|
529
1430
|
if (hooks && hookBase) {
|
|
@@ -551,16 +1452,23 @@ let ToolPipeline = class ToolPipeline {
|
|
|
551
1452
|
if (!parsed.success) {
|
|
552
1453
|
return fail("Invalid SendMessage call: pass to and message.", outKey);
|
|
553
1454
|
}
|
|
554
|
-
r = await messenger
|
|
1455
|
+
r = await messenger
|
|
1456
|
+
.toChild(ctx, call.id, parsed.data.to, parsed.data.message, {
|
|
555
1457
|
authorization,
|
|
556
|
-
|
|
1458
|
+
admit,
|
|
1459
|
+
})
|
|
1460
|
+
.catch(admissionError);
|
|
557
1461
|
}
|
|
558
1462
|
else {
|
|
559
1463
|
const parsed = HandbackInput.safeParse(input);
|
|
560
1464
|
if (!parsed.success)
|
|
561
1465
|
return fail("Invalid SubagentHandback call: pass message.", outKey);
|
|
562
|
-
r = await messenger
|
|
1466
|
+
r = await messenger
|
|
1467
|
+
.toParent(ctx, "report", parsed.data.message, call.id, admit)
|
|
1468
|
+
.catch(admissionError);
|
|
563
1469
|
}
|
|
1470
|
+
if (r instanceof Error)
|
|
1471
|
+
return changedPolicy(r);
|
|
564
1472
|
if (r.isError)
|
|
565
1473
|
return fail(r.content, outKey);
|
|
566
1474
|
const durationMs = Date.now() - t0;
|
|
@@ -576,31 +1484,128 @@ let ToolPipeline = class ToolPipeline {
|
|
|
576
1484
|
}
|
|
577
1485
|
return undefined;
|
|
578
1486
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
1487
|
+
if (rerun.site !== undefined &&
|
|
1488
|
+
(rerun.site.toolSpecHash !== tool.specHash ||
|
|
1489
|
+
rerun.site.callInputHash !== permissionScopeHash(call.input) ||
|
|
1490
|
+
!(await this.siteRetryAllowed(ctx, call.id, tool, input, rerun.site)))) {
|
|
1491
|
+
return fail("This site approval is no longer valid. The action did not run.", outKey);
|
|
1492
|
+
}
|
|
1493
|
+
try {
|
|
1494
|
+
await admit(() => this.deps.eventLog.append(ctx.conversationId, [
|
|
1495
|
+
{
|
|
1496
|
+
type: "tool_call_started",
|
|
1497
|
+
runId: ctx.runId,
|
|
1498
|
+
idemKey: idem.started(ctx.runId, call.id, attempt),
|
|
1499
|
+
payload: {
|
|
1500
|
+
step: ctx.step,
|
|
1501
|
+
callId: call.id,
|
|
1502
|
+
toolKey: tool.key,
|
|
1503
|
+
specHash: tool.specHash,
|
|
1504
|
+
...(this.operationScoped(tool, input)
|
|
1505
|
+
? {
|
|
1506
|
+
permissionInput: {
|
|
1507
|
+
callInputHash: permissionScopeHash(call.input),
|
|
1508
|
+
resolvedInputHash: permissionScopeHash(input),
|
|
1509
|
+
...(isEscalatedCall(tool.key, input)
|
|
1510
|
+
? { sandbox: "escalated" }
|
|
1511
|
+
: {}),
|
|
1512
|
+
},
|
|
1513
|
+
}
|
|
1514
|
+
: {}),
|
|
1515
|
+
},
|
|
1516
|
+
},
|
|
1517
|
+
]));
|
|
1518
|
+
}
|
|
1519
|
+
catch (error) {
|
|
1520
|
+
return changedPolicy(error);
|
|
1521
|
+
}
|
|
587
1522
|
const t0 = Date.now();
|
|
588
|
-
let outcome = await this.execute(tool, input, ctx, call.id, resume, resolved.tools
|
|
1523
|
+
let outcome = await this.execute(tool, input, ctx, call.id, resume, resolved.tools, reviewedRoots,
|
|
1524
|
+
// the approval the call runs under (a Platform write reads the person's values by it)
|
|
1525
|
+
approval?.status === "approved" && approvedHere ? approval.id : undefined,
|
|
1526
|
+
// or the automatic decision and the file bytes it was bound to (R7)
|
|
1527
|
+
auto === undefined
|
|
1528
|
+
? undefined
|
|
1529
|
+
: {
|
|
1530
|
+
source: auto.source,
|
|
1531
|
+
...(auto.fileSha256 !== undefined && { fileSha256: auto.fileSha256 }),
|
|
1532
|
+
},
|
|
1533
|
+
// and the submitted secure input holding the person's values
|
|
1534
|
+
secureInputId, rerun.site?.approval);
|
|
589
1535
|
const durationMs = Date.now() - t0;
|
|
590
1536
|
await this.deps.hooks?.afterExecute?.(ctx.runId, call.id);
|
|
1537
|
+
// what earlier input rounds collected: a launch reviewed in a round that asked, the hosts a
|
|
1538
|
+
// service reported refused there (this round, a resume, finds the service running)
|
|
1539
|
+
outcome = withCarried(outcome, carried);
|
|
1540
|
+
// a device service launch's review during the call (ctx.deviceAccess, the call scope)
|
|
1541
|
+
if (review === undefined && outcome.kind !== "connection_required")
|
|
1542
|
+
review = outcome.review;
|
|
1543
|
+
// the record says a call ran outside the sandbox only when admission gave it that scope
|
|
1544
|
+
if (review !== undefined && isEscalatedCall(tool.key, input)) {
|
|
1545
|
+
const { sandbox: _asked, ...rest } = review;
|
|
1546
|
+
review = (await this.admittedOutsideSandbox(ctx.runId, call.id))
|
|
1547
|
+
? { ...rest, sandbox: "escalated" }
|
|
1548
|
+
: rest;
|
|
1549
|
+
}
|
|
1550
|
+
// scheduled tasks spec §7, `fail` mode: no one answers an input request or connects an app
|
|
1551
|
+
if (unattendedFails(ctx.unattended) && ctx.unattended != null) {
|
|
1552
|
+
// a watched wait needs nobody: it stays allowed (browser long waits spec §5.2, R8)
|
|
1553
|
+
if (outcome.kind === "input_required" && outcome.watch === undefined) {
|
|
1554
|
+
outcome = {
|
|
1555
|
+
kind: "error",
|
|
1556
|
+
message: UNATTENDED_QUESTION_ERROR,
|
|
1557
|
+
...(outcome.blocked !== undefined && { blocked: outcome.blocked }),
|
|
1558
|
+
...(outcome.review !== undefined && { review: outcome.review }),
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
else if (outcome.kind === "connection_required") {
|
|
1562
|
+
await appendMissingGrant(this.deps.db, ctx.unattended.taskRunId, connectionGrantKey(outcome.connectorSlug));
|
|
1563
|
+
outcome = { kind: "error", message: UNATTENDED_CONNECTION_ERROR(outcome.connectorName) };
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
591
1566
|
if (outcome.kind === "input_required") {
|
|
592
|
-
const
|
|
1567
|
+
const open = tool.source.kind === "plugin" && outcome.open !== undefined
|
|
1568
|
+
? this.openOf(outcome.open, tool.source.plugin, tool.key)
|
|
1569
|
+
: undefined;
|
|
1570
|
+
const { open: _raw, ...asking } = outcome;
|
|
1571
|
+
const asked = await this.askInput(ctx, call.id, tool.key, attempt, {
|
|
1572
|
+
...asking,
|
|
1573
|
+
...(open !== undefined && { open }),
|
|
1574
|
+
source: tool.source,
|
|
1575
|
+
});
|
|
593
1576
|
if (typeof asked !== "string")
|
|
594
1577
|
return asked;
|
|
595
|
-
outcome = {
|
|
1578
|
+
outcome = {
|
|
1579
|
+
kind: "error",
|
|
1580
|
+
message: asked,
|
|
1581
|
+
...(outcome.blocked !== undefined && { blocked: outcome.blocked }),
|
|
1582
|
+
...(outcome.review !== undefined && { review: outcome.review }),
|
|
1583
|
+
};
|
|
596
1584
|
}
|
|
1585
|
+
// the images of the result (any tool): stored as `read` copies of the calling conversation,
|
|
1586
|
+
// named in the text and in `tool_result.media`, so a model with vision sees them after the
|
|
1587
|
+
// step's results and the person sees them on the call's row (tool result images design §2)
|
|
1588
|
+
const images = outcome.kind === "result"
|
|
1589
|
+
? await storeResultImages(outcome.result, tool.key, this.storeResultImage(ctx), (err) => this.deps.log.warn("cannot store an image of a tool result", {
|
|
1590
|
+
toolKey: tool.key,
|
|
1591
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1592
|
+
}), ctx.signal)
|
|
1593
|
+
: undefined;
|
|
597
1594
|
const rendered = outcome.kind === "result"
|
|
598
|
-
? renderResult(outcome.result)
|
|
1595
|
+
? renderResult(outcome.result, images?.texts)
|
|
599
1596
|
: { text: outcome.message, contentTypes: [], isError: true };
|
|
600
|
-
//
|
|
1597
|
+
// the tools a builtin (ToolSearch) reports as loaded: only keys available in this step and not
|
|
1598
|
+
// builtin, written to tool_result (the log is the source of truth)
|
|
601
1599
|
const loadedTools = outcome.kind === "result" && tool.source.kind === "builtin"
|
|
602
1600
|
? loadedFrom(outcome.result, resolved.tools)
|
|
603
1601
|
: [];
|
|
1602
|
+
// the images the builtin Read stored for the call (vision-read design §1.2): builtins only,
|
|
1603
|
+
// so a plugin can never name an attachment for request building
|
|
1604
|
+
const builtinMedia = outcome.kind === "result" && tool.source.kind === "builtin"
|
|
1605
|
+
? mediaFrom(outcome.result)
|
|
1606
|
+
: undefined;
|
|
1607
|
+
const allMedia = [...(builtinMedia ?? []), ...(images?.media ?? [])];
|
|
1608
|
+
const media = allMedia.length > 0 ? allMedia : undefined;
|
|
604
1609
|
// 显示摘要:只认插件 / 内置工具与内核的 resources 工具给的(连接器结果来自外部服务,不采信),
|
|
605
1610
|
// 校验不过就丢弃并告警
|
|
606
1611
|
const display = outcome.kind === "result" && (tool.source.kind !== "connector" || tool.source.resources)
|
|
@@ -614,6 +1619,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
614
1619
|
const card = outcome.kind === "result" && tool.source.kind === "plugin"
|
|
615
1620
|
? this.cardOf(outcome.result, tool.source.plugin, tool.key)
|
|
616
1621
|
: undefined;
|
|
1622
|
+
// a `gh auth login --web` device code (`Bash`; auto mode spec §6): display only, written under
|
|
1623
|
+
// this call before its result, never part of the result or the request the model sees
|
|
1624
|
+
const loginCode = outcome.kind === "result" && tool.source.kind === "builtin"
|
|
1625
|
+
? loginCodeOf(outcome.result)
|
|
1626
|
+
: undefined;
|
|
617
1627
|
const cfg = this.config.get().tools;
|
|
618
1628
|
const spilled = await spillIfLarge(rendered.text, {
|
|
619
1629
|
// 内置工具可给更低的转存阈值(沙箱 bash 30000 字符)
|
|
@@ -641,20 +1651,140 @@ let ToolPipeline = class ToolPipeline {
|
|
|
641
1651
|
},
|
|
642
1652
|
]
|
|
643
1653
|
: [];
|
|
644
|
-
|
|
1654
|
+
if (loginCode !== undefined &&
|
|
1655
|
+
!(await this.deps.eventLog.deviceCodeShown(ctx.conversationId, loginCode.code))) {
|
|
1656
|
+
// the per-call id makes a retry or a resumed run append it once; a second call (a task read
|
|
1657
|
+
// again, another command printing the same code) does not show the same code twice (P-D13)
|
|
1658
|
+
pre.push(deviceCodeEvent(ctx.runId, ctx.step, call.id, loginCode));
|
|
1659
|
+
}
|
|
1660
|
+
const callAudit = {
|
|
1661
|
+
durationMs,
|
|
1662
|
+
connectorId: tool.source.kind === "connector" ? tool.source.connectorId : null,
|
|
1663
|
+
authorization,
|
|
1664
|
+
};
|
|
1665
|
+
// a foreground command refused network hosts (network ask-to-allow spec §6.2): display-only
|
|
1666
|
+
// `network_blocked` before the result, then an ask to the device owner (the run waits; the
|
|
1667
|
+
// result is written when the ask settles) or notes after the output
|
|
1668
|
+
const commandReport = outcome.kind === "result" && tool.source.kind === "builtin"
|
|
1669
|
+
? networkReportOf(outcome.result)
|
|
1670
|
+
: undefined;
|
|
1671
|
+
// the denial line `Bash` left out of its content: appended here in the form that goes with
|
|
1672
|
+
// the network notes (`denialHintFor`), after the output (and its truncation line)
|
|
1673
|
+
const denialHint = outcome.kind === "result" && tool.source.kind === "builtin"
|
|
1674
|
+
? denialHintOf(outcome.result)
|
|
1675
|
+
: undefined;
|
|
1676
|
+
// a device service's refusals reported in the call scope (browser use spec §7.1), any source:
|
|
1677
|
+
// asked as "always" only, the call runs again once approved
|
|
1678
|
+
// a report about another device than the conversation's is ignored: only the device the call
|
|
1679
|
+
// works in may be asked about, and only its owner
|
|
1680
|
+
const scoped = commandReport === undefined && (outcome.kind === "result" || outcome.kind === "error")
|
|
1681
|
+
? await this.ownDeviceReport(ctx, outKey, outcome.blocked)
|
|
1682
|
+
: undefined;
|
|
1683
|
+
// the formatted result and its display-only fields, kept by an ask until it settles
|
|
1684
|
+
const keptResult = {
|
|
1685
|
+
text: rendered.text,
|
|
645
1686
|
content: spilled.content,
|
|
646
1687
|
isError: rendered.isError,
|
|
647
1688
|
...(spilled.outputId !== undefined && { outputId: spilled.outputId }),
|
|
648
1689
|
...(rendered.contentTypes.length > 0 && { contentTypes: rendered.contentTypes }),
|
|
1690
|
+
...(display !== undefined && { display }),
|
|
1691
|
+
...(view !== undefined && { view }),
|
|
1692
|
+
...(media !== undefined && { media }),
|
|
1693
|
+
...(review !== undefined && { review }),
|
|
1694
|
+
// carried into the kept result so a resumed run writes the event too (it was written
|
|
1695
|
+
// with `network_blocked` below when the ask was created)
|
|
1696
|
+
...(loginCode !== undefined && { loginCode }),
|
|
1697
|
+
...(denialHint !== undefined && { denialHint }),
|
|
1698
|
+
};
|
|
1699
|
+
const site = outcome.kind === "result" || outcome.kind === "error" ? outcome.siteAccess : undefined;
|
|
1700
|
+
if (site !== undefined) {
|
|
1701
|
+
const handled = await this.handleSiteAccess(ctx, call, tool, input, site, attempt, keptResult, pre, callAudit, rerun.site);
|
|
1702
|
+
if (handled.kind === "wait")
|
|
1703
|
+
return handled.wait;
|
|
1704
|
+
if (handled.kind === "rerun") {
|
|
1705
|
+
return this.runCall(ctx, call, resolved, attempt + 1, resume, carried, {
|
|
1706
|
+
site: handled.site,
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
await this.writeResult(ctx, call.id, outKey, {
|
|
1710
|
+
...keptResult,
|
|
1711
|
+
content: withNetworkNotes(keptResult.content, [handled.note]),
|
|
1712
|
+
isError: true,
|
|
1713
|
+
}, pre, callAudit);
|
|
1714
|
+
return undefined;
|
|
1715
|
+
}
|
|
1716
|
+
// a device service's loopback refusal (browser loopback port grants), decided before the other
|
|
1717
|
+
// hosts: the conversation's permission profile grants the port (the call runs again now),
|
|
1718
|
+
// the run waits for the device owner, or a note says why the port stays closed; its host is
|
|
1719
|
+
// then not one of the address hosts below
|
|
1720
|
+
let serviceHosts = scoped?.hosts;
|
|
1721
|
+
let loopbackNotes = [];
|
|
1722
|
+
if (scoped?.loopback !== undefined) {
|
|
1723
|
+
const lb = scoped.loopback;
|
|
1724
|
+
const otherHosts = scoped.hosts.filter((h) => serviceHostKey(h.host) !== serviceHostKey(lb.host));
|
|
1725
|
+
const handled = await this.loopbackBlocked(ctx, call, tool, input, outKey, { deviceId: scoped.deviceId, loopback: lb, url: scoped.url, otherHosts }, attempt, keptResult, rerun.loopbackRerun === true, pre, callAudit);
|
|
1726
|
+
if (handled.kind !== "none") {
|
|
1727
|
+
serviceHosts = otherHosts;
|
|
1728
|
+
if (handled.kind === "wait") {
|
|
1729
|
+
if (hooks && hookBase) {
|
|
1730
|
+
fireObserve(hooks, "tool.postExecute", { ...hookBase, isError: rendered.isError, content: handled.content, durationMs }, ctx.signal, this.deps.log);
|
|
1731
|
+
}
|
|
1732
|
+
return handled.wait;
|
|
1733
|
+
}
|
|
1734
|
+
if (handled.kind === "rerun") {
|
|
1735
|
+
return this.runCall(ctx, call, resolved, attempt + 1, resume, { ...(carried.review !== undefined && { review: carried.review }) }, { notes: handled.notes, loopbackRerun: true });
|
|
1736
|
+
}
|
|
1737
|
+
loopbackNotes = handled.notes;
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
const report = commandReport ??
|
|
1741
|
+
(scoped === undefined || serviceHosts === undefined || serviceHosts.length === 0
|
|
1742
|
+
? undefined
|
|
1743
|
+
: {
|
|
1744
|
+
deviceId: scoped.deviceId,
|
|
1745
|
+
// a service reports host names with their layers only: the event carries the HTTPS
|
|
1746
|
+
// port. The layer is the service's word: it only chooses the note or the ask, and the
|
|
1747
|
+
// plan still refuses to ask about a host the device list cannot take (an IP literal
|
|
1748
|
+
// or other invalid name is always `address`)
|
|
1749
|
+
blocked: serviceHosts.map(({ host, layer }) => ({ host, port: 443, layer })),
|
|
1750
|
+
});
|
|
1751
|
+
let content = spilled.content;
|
|
1752
|
+
if (report !== undefined) {
|
|
1753
|
+
const handled = await this.networkBlocked(ctx, call.id, outKey, input, report, pre, callAudit, loopbackNotes.length === 0
|
|
1754
|
+
? keptResult
|
|
1755
|
+
: { ...keptResult, content: withNetworkNotes(keptResult.content, loopbackNotes) }, reviewedRoots.escalation, reviewedRoots.escalationRefusal, scoped === undefined
|
|
1756
|
+
? undefined
|
|
1757
|
+
: {
|
|
1758
|
+
name: tool.source.kind === "plugin" ? tool.source.plugin : tool.key,
|
|
1759
|
+
attempt,
|
|
1760
|
+
url: scoped.url,
|
|
1761
|
+
});
|
|
1762
|
+
if (handled.kind === "wait") {
|
|
1763
|
+
if (hooks && hookBase) {
|
|
1764
|
+
fireObserve(hooks, "tool.postExecute", { ...hookBase, isError: rendered.isError, content: handled.content, durationMs }, ctx.signal, this.deps.log);
|
|
1765
|
+
}
|
|
1766
|
+
return handled.wait;
|
|
1767
|
+
}
|
|
1768
|
+
if (handled.event !== null)
|
|
1769
|
+
pre.push(handled.event);
|
|
1770
|
+
content = withNetworkNotes(withNetworkNotes(content, loopbackNotes) + denialHintFor(denialHint, handled.addressNote), handled.notes);
|
|
1771
|
+
}
|
|
1772
|
+
else
|
|
1773
|
+
content = withNetworkNotes(content, loopbackNotes) + denialHintFor(denialHint, undefined);
|
|
1774
|
+
// a re-run after a granted loopback port: its note after the result
|
|
1775
|
+
content = withNetworkNotes(content, rerun.notes ?? []);
|
|
1776
|
+
await this.writeResult(ctx, call.id, outKey, {
|
|
1777
|
+
content,
|
|
1778
|
+
isError: rendered.isError,
|
|
1779
|
+
...(spilled.outputId !== undefined && { outputId: spilled.outputId }),
|
|
1780
|
+
...(rendered.contentTypes.length > 0 && { contentTypes: rendered.contentTypes }),
|
|
649
1781
|
...(loadedTools.length > 0 && { loadedTools }),
|
|
1782
|
+
...(media !== undefined && { media }),
|
|
650
1783
|
...(display !== undefined && { display }),
|
|
651
1784
|
...(view !== undefined && { view }),
|
|
652
1785
|
...(card !== undefined && { card }),
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
connectorId: tool.source.kind === "connector" ? tool.source.connectorId : null,
|
|
656
|
-
authorization,
|
|
657
|
-
});
|
|
1786
|
+
...(review !== undefined && { review }),
|
|
1787
|
+
}, pre, callAudit);
|
|
658
1788
|
// a sub-agent that needs a personal connection: mirrored in the root conversation of its tree
|
|
659
1789
|
// for display (sub-agents spec §9, agent map spec §7; not a wait, the child got the connect
|
|
660
1790
|
// text as its result)
|
|
@@ -665,14 +1795,1558 @@ let ToolPipeline = class ToolPipeline {
|
|
|
665
1795
|
}));
|
|
666
1796
|
}
|
|
667
1797
|
if (hooks && hookBase) {
|
|
668
|
-
fireObserve(hooks, "tool.postExecute", { ...hookBase, isError: rendered.isError, content
|
|
1798
|
+
fireObserve(hooks, "tool.postExecute", { ...hookBase, isError: rendered.isError, content, durationMs }, ctx.signal, this.deps.log);
|
|
669
1799
|
}
|
|
670
1800
|
return undefined;
|
|
671
1801
|
}
|
|
672
|
-
/**
|
|
673
|
-
|
|
674
|
-
const
|
|
675
|
-
|
|
1802
|
+
/** Take the organization authority before the transaction's durable start. */
|
|
1803
|
+
withOrgToolAdmission(ctx, tool, policyKey, input, approval, automatic, commit) {
|
|
1804
|
+
const locks = this.permissionLocks;
|
|
1805
|
+
const recheck = async () => {
|
|
1806
|
+
const db = this.deps.db;
|
|
1807
|
+
// Stabilize the recorded approver's membership before taking the authority lock.
|
|
1808
|
+
const member = approval?.status === "approved" &&
|
|
1809
|
+
approval.orgAskRevisions !== undefined &&
|
|
1810
|
+
approval.decidedBy !== null
|
|
1811
|
+
? await db
|
|
1812
|
+
.selectFrom("memberships")
|
|
1813
|
+
.select("role")
|
|
1814
|
+
.where("org_id", "=", ctx.orgId)
|
|
1815
|
+
.where("account_id", "=", approval.decidedBy)
|
|
1816
|
+
.$if(locks !== undefined, (query) => query.forShare())
|
|
1817
|
+
.executeTakeFirst()
|
|
1818
|
+
: undefined;
|
|
1819
|
+
await locks?.acquire({ orgId: ctx.orgId }, { kind: "admit" });
|
|
1820
|
+
const unattended = unattendedRules(ctx.unattended);
|
|
1821
|
+
const current = await readOrgToolPolicy(db, ctx.orgId, tool.key, policyKey, unattended);
|
|
1822
|
+
if (current.policy === "deny")
|
|
1823
|
+
throw new OrgToolDenied();
|
|
1824
|
+
if (automatic !== undefined && !(await this.canAdmitRecordedProfile(ctx, automatic)))
|
|
1825
|
+
throw new OrgToolPolicyChanged();
|
|
1826
|
+
if (current.policy !== "ask")
|
|
1827
|
+
return;
|
|
1828
|
+
if (approval?.status !== "approved" ||
|
|
1829
|
+
approval.toolKey !== policyKey ||
|
|
1830
|
+
approval.specHash !== tool.specHash ||
|
|
1831
|
+
approval.scope !== "once" ||
|
|
1832
|
+
approval.decidedBy === null ||
|
|
1833
|
+
!sameOrgAsk(approval.orgAskRevisions, current.revisions) ||
|
|
1834
|
+
canonicalJson(approval.input) !== canonicalJson(input ?? {}))
|
|
1835
|
+
throw new OrgToolPolicyChanged();
|
|
1836
|
+
if (!member)
|
|
1837
|
+
throw new OrgToolDenied();
|
|
1838
|
+
if (approval.requestedFor === null) {
|
|
1839
|
+
if (approval.approverRole === null ||
|
|
1840
|
+
approval.decidedBy === ctx.accountId ||
|
|
1841
|
+
!roleAtLeast(member.role, approval.approverRole))
|
|
1842
|
+
throw new OrgToolDenied();
|
|
1843
|
+
}
|
|
1844
|
+
else {
|
|
1845
|
+
if (approval.decidedBy !== approval.requestedFor)
|
|
1846
|
+
throw new OrgToolDenied();
|
|
1847
|
+
if (tool.requiredRole !== undefined && !roleAtLeast(member.role, tool.requiredRole))
|
|
1848
|
+
throw new OrgToolPolicyChanged();
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
return locks === undefined
|
|
1852
|
+
? recheck().then(commit)
|
|
1853
|
+
: withTransactionFencePrelude(recheck, commit);
|
|
1854
|
+
}
|
|
1855
|
+
async canAdmitRecordedProfile(ctx, decision) {
|
|
1856
|
+
const profiles = this.approvalProfile;
|
|
1857
|
+
if (profiles?.canAdmitRecorded === undefined)
|
|
1858
|
+
return true;
|
|
1859
|
+
try {
|
|
1860
|
+
return await profiles.canAdmitRecorded({
|
|
1861
|
+
orgId: ctx.orgId,
|
|
1862
|
+
rootConversationId: ctx.parent?.rootConversationId ?? ctx.conversationId,
|
|
1863
|
+
profile: decision.source === "full-access" ? "full-access" : "approve-for-me",
|
|
1864
|
+
revision: decision.revision,
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
catch (error) {
|
|
1868
|
+
this.deps.log.warn("cannot check a recorded profile decision; asking the person", {
|
|
1869
|
+
conversationId: ctx.conversationId,
|
|
1870
|
+
error,
|
|
1871
|
+
});
|
|
1872
|
+
return false;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* The profile step (profiles govern every approval, R1-R3) of an ask `decide` returned for a call
|
|
1877
|
+
* no approval governs yet. It applies only to an ask addressed to the person (no role, the root
|
|
1878
|
+
* conversation's own owner), in an attended interactive chat, and for a tool that does not
|
|
1879
|
+
* itself require the person's interaction (D3); a call's secret fields are asked afterwards in a
|
|
1880
|
+
* secure input request whatever it decides (R4). Request approval asks; Auto allows; Approve for
|
|
1881
|
+
* me asks the review model, whose unsure answer asks the person. An `allow` or `deny` is recorded
|
|
1882
|
+
* once (`tool_ask_decided` and its audit row). A resumed call reuses an eligible allow or the
|
|
1883
|
+
* recorded deny. If the ceiling invalidates an allow, the person decides instead.
|
|
1884
|
+
*/
|
|
1885
|
+
async profileStep(ctx, call, tool, input, ask, callPolicy) {
|
|
1886
|
+
const asks = { kind: "ask", unsure: false };
|
|
1887
|
+
const profiles = this.approvalProfile;
|
|
1888
|
+
const reviewer = this.toolReview;
|
|
1889
|
+
if (profiles === undefined || reviewer === undefined)
|
|
1890
|
+
return asks;
|
|
1891
|
+
if (ask.orgAskRevisions !== undefined)
|
|
1892
|
+
return asks;
|
|
1893
|
+
if (ask.approverRole !== null || ask.requestedFor === null)
|
|
1894
|
+
return asks;
|
|
1895
|
+
if (ctx.unattended != null)
|
|
1896
|
+
return asks;
|
|
1897
|
+
// a change of what the person consents to: they answer it themself, never their profile
|
|
1898
|
+
if (callPolicy?.personDecides === true)
|
|
1899
|
+
return asks;
|
|
1900
|
+
if (tool.spec.annotations?.requiresUserInteraction === true)
|
|
1901
|
+
return asks;
|
|
1902
|
+
// Reuse the decision if its profile is still eligible. A ceiling change leaves started work alone.
|
|
1903
|
+
const bindingHash = askBindingHash(ask.toolKey, ask.specHash, call.input);
|
|
1904
|
+
const idemKey = `tool_ask_decided:${ctx.runId}:${call.id}:${bindingHash}`;
|
|
1905
|
+
const recorded = await this.deps.eventLog.findByIdem(ctx.conversationId, idemKey);
|
|
1906
|
+
if (recorded?.type === "tool_ask_decided") {
|
|
1907
|
+
const outcome = askDecisionOf(recorded);
|
|
1908
|
+
if (outcome.kind === "allow" && !(await this.canAdmitRecordedProfile(ctx, outcome.decision)))
|
|
1909
|
+
return asks;
|
|
1910
|
+
return outcome;
|
|
1911
|
+
}
|
|
1912
|
+
const rootConversationId = ctx.parent?.rootConversationId ?? ctx.conversationId;
|
|
1913
|
+
let resolved;
|
|
1914
|
+
try {
|
|
1915
|
+
resolved = await profiles.resolve({
|
|
1916
|
+
orgId: ctx.orgId,
|
|
1917
|
+
rootConversationId,
|
|
1918
|
+
requestedFor: ask.requestedFor,
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
catch (err) {
|
|
1922
|
+
this.deps.log.warn("cannot read the conversation's permission profile; asking the person", {
|
|
1923
|
+
conversationId: ctx.conversationId,
|
|
1924
|
+
callId: call.id,
|
|
1925
|
+
err,
|
|
1926
|
+
});
|
|
1927
|
+
return asks;
|
|
1928
|
+
}
|
|
1929
|
+
if (resolved === null || resolved.profile === "request-approval")
|
|
1930
|
+
return asks;
|
|
1931
|
+
let decision;
|
|
1932
|
+
if (resolved.profile === "full-access") {
|
|
1933
|
+
decision = { outcome: "allow", reason: TOOL_AUTO_REASON, source: "full-access" };
|
|
1934
|
+
}
|
|
1935
|
+
else {
|
|
1936
|
+
const parent = ctx.parent;
|
|
1937
|
+
const verdict = await reviewer.review({
|
|
1938
|
+
orgId: ctx.orgId,
|
|
1939
|
+
rootConversationId,
|
|
1940
|
+
conversationId: ctx.conversationId,
|
|
1941
|
+
runId: ctx.runId,
|
|
1942
|
+
step: ctx.step,
|
|
1943
|
+
callId: call.id,
|
|
1944
|
+
accountId: ctx.accountId,
|
|
1945
|
+
signal: ctx.signal,
|
|
1946
|
+
toolKey: ask.toolKey,
|
|
1947
|
+
title: tool.spec.title ?? null,
|
|
1948
|
+
summary: callPolicy?.summary ?? null,
|
|
1949
|
+
input,
|
|
1950
|
+
inputSchema: tool.spec.inputSchema,
|
|
1951
|
+
// a sub-agent's review counts on its parent run, as the command review's does
|
|
1952
|
+
...(parent !== undefined && {
|
|
1953
|
+
parentRunId: parent.runId,
|
|
1954
|
+
...(parent.budgetRunId !== undefined && { budgetRunId: parent.budgetRunId }),
|
|
1955
|
+
}),
|
|
1956
|
+
hookFacts: {
|
|
1957
|
+
accountId: ctx.accountId,
|
|
1958
|
+
agentId: ctx.agentId,
|
|
1959
|
+
agentVersion: ctx.agentVersion,
|
|
1960
|
+
conversationKind: ctx.conversationKind,
|
|
1961
|
+
parent: parent === undefined
|
|
1962
|
+
? undefined
|
|
1963
|
+
: {
|
|
1964
|
+
conversationId: parent.conversationId,
|
|
1965
|
+
runId: parent.runId,
|
|
1966
|
+
callId: parent.callId,
|
|
1967
|
+
},
|
|
1968
|
+
},
|
|
1969
|
+
});
|
|
1970
|
+
if (verdict.decision === "ask")
|
|
1971
|
+
return { kind: "ask", unsure: true };
|
|
1972
|
+
decision = { outcome: verdict.decision, reason: verdict.reason, source: "review-model" };
|
|
1973
|
+
}
|
|
1974
|
+
const fileSha256 = callPolicy?.file?.sha256;
|
|
1975
|
+
const event = await this.recordAskDecision(ctx, idemKey, {
|
|
1976
|
+
step: ctx.step,
|
|
1977
|
+
callId: call.id,
|
|
1978
|
+
toolKey: ask.toolKey,
|
|
1979
|
+
specHash: ask.specHash,
|
|
1980
|
+
bindingHash,
|
|
1981
|
+
outcome: decision.outcome,
|
|
1982
|
+
decisionSource: decision.source,
|
|
1983
|
+
reason: decision.reason,
|
|
1984
|
+
profileRevision: resolved.revision,
|
|
1985
|
+
...(fileSha256 !== undefined && { fileSha256 }),
|
|
1986
|
+
});
|
|
1987
|
+
return askDecisionOf(event);
|
|
1988
|
+
}
|
|
1989
|
+
/** Records an automatic decision once (R2) and announces it after the commit. */
|
|
1990
|
+
async recordAskDecision(ctx, idemKey, payload) {
|
|
1991
|
+
const { event, fresh } = await this.recordAskDecisionIn(ctx, idemKey, payload);
|
|
1992
|
+
if (fresh)
|
|
1993
|
+
await this.deps.eventLog.notify(ctx.conversationId, event.seq);
|
|
1994
|
+
return event;
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* The `tool_ask_decided` event and, when this call wrote it, its audit row
|
|
1998
|
+
* `tool.ask_auto_decided`, in one transaction: a retry or another replica returns the recorded
|
|
1999
|
+
* event and audits nothing (every automatic decision is audited exactly once).
|
|
2000
|
+
*/
|
|
2001
|
+
async recordAskDecisionIn(ctx, idemKey, payload) {
|
|
2002
|
+
const report = await this.deps.eventLog.appendInReport(ctx.conversationId, [
|
|
2003
|
+
{ type: "tool_ask_decided", runId: ctx.runId, idemKey, payload },
|
|
2004
|
+
]);
|
|
2005
|
+
const event = report.events[0];
|
|
2006
|
+
if (event?.type !== "tool_ask_decided")
|
|
2007
|
+
throw new Error("The ask decision was not recorded");
|
|
2008
|
+
const fresh = report.fresh[0] === true;
|
|
2009
|
+
if (fresh) {
|
|
2010
|
+
await audit(this.deps.db, {
|
|
2011
|
+
actorAccountId: ctx.accountId,
|
|
2012
|
+
orgId: ctx.orgId,
|
|
2013
|
+
action: "tool.ask_auto_decided",
|
|
2014
|
+
target: ctx.conversationId,
|
|
2015
|
+
detail: {
|
|
2016
|
+
callId: payload.callId,
|
|
2017
|
+
runId: ctx.runId,
|
|
2018
|
+
toolKey: payload.toolKey,
|
|
2019
|
+
outcome: payload.outcome,
|
|
2020
|
+
decisionSource: payload.decisionSource,
|
|
2021
|
+
profileRevision: payload.profileRevision,
|
|
2022
|
+
reason: payload.reason,
|
|
2023
|
+
},
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
return { event, fresh };
|
|
2027
|
+
}
|
|
2028
|
+
/**
|
|
2029
|
+
* The command review of one call (auto mode spec §5.1, §5.4), after argument validation and the
|
|
2030
|
+
* tool policy (and its approval), before the plugin hooks and execution. The device facts come
|
|
2031
|
+
* from the same `ConversationDevices.forTool` the tool enters; with no device (or a deployment
|
|
2032
|
+
* without a review service) the call runs unreviewed and fails on its own if it cannot. A deny is
|
|
2033
|
+
* final whatever the mode and approvals; an `ask` waits for the device owner's `command` approval
|
|
2034
|
+
* when the run is attended, and is a deny at once when it is not. A command approval already
|
|
2035
|
+
* asked is the whole truth on a resume: the call is never reviewed twice.
|
|
2036
|
+
*/
|
|
2037
|
+
async reviewCall(ctx, call, tool, input) {
|
|
2038
|
+
// a device tool of a run another account triggered never uses the owner's device: refused
|
|
2039
|
+
// here, with no review and no review model call (the tools refuse it the same way)
|
|
2040
|
+
if (this.operationScoped(tool, input) && ctx.ownerAccountId !== ctx.accountId)
|
|
2041
|
+
return {
|
|
2042
|
+
kind: "result",
|
|
2043
|
+
content: DEVICE_OF_ANOTHER_ACCOUNT_TEXT,
|
|
2044
|
+
review: denyRecord("rule", null, "The run's account is not the conversation's owner"),
|
|
2045
|
+
};
|
|
2046
|
+
if (this.operationScoped(tool, input)) {
|
|
2047
|
+
let scoped;
|
|
2048
|
+
try {
|
|
2049
|
+
scoped = await this.reviewPermissionCall(ctx, call, tool, input);
|
|
2050
|
+
}
|
|
2051
|
+
catch (error) {
|
|
2052
|
+
// fail closed: a permission evidence conflict or an owner check that refuses while the
|
|
2053
|
+
// call is asked about, reviewed or matched to its grant is a refusal of this call, never a
|
|
2054
|
+
// run error and never a run of it
|
|
2055
|
+
if (!(error instanceof ApiError) || !FAIL_CLOSED_CODES.has(error.code))
|
|
2056
|
+
throw error;
|
|
2057
|
+
this.deps.log.warn("permission review refused the call", {
|
|
2058
|
+
conversationId: ctx.conversationId,
|
|
2059
|
+
callId: call.id,
|
|
2060
|
+
err: error,
|
|
2061
|
+
});
|
|
2062
|
+
const content = permissionCheckFailedText(error.message);
|
|
2063
|
+
return { kind: "result", content, review: denyRecord("rule", null, error.message) };
|
|
2064
|
+
}
|
|
2065
|
+
if (scoped)
|
|
2066
|
+
return scoped;
|
|
2067
|
+
}
|
|
2068
|
+
const review = this.deps.review;
|
|
2069
|
+
const devices = this.deps.devices;
|
|
2070
|
+
if (review === undefined || devices === undefined)
|
|
2071
|
+
return { kind: "continue" };
|
|
2072
|
+
if (!isReviewedCall(tool.key, input))
|
|
2073
|
+
return { kind: "continue" };
|
|
2074
|
+
const asked = await this.deps.approvals.commandForCall(ctx.runId, call.id);
|
|
2075
|
+
const rootConversationId = ctx.parent?.rootConversationId ?? ctx.conversationId;
|
|
2076
|
+
if (asked !== null && asked.status !== "superseded") {
|
|
2077
|
+
const settled = this.settledCommandAsk(asked, tool.key);
|
|
2078
|
+
// an approved call runs in the root it was reviewed against only while the device still runs
|
|
2079
|
+
// in the mode recorded with the ask; otherwise the tool decides its working root afresh. A
|
|
2080
|
+
// judged root that is the recorded workspace (free mode) is not carried either
|
|
2081
|
+
// ({@link carriedRoot}): the tool maps it to the held instance's workspace as always
|
|
2082
|
+
if (settled.kind === "continue" && settled.workingRoot !== undefined) {
|
|
2083
|
+
const now = await devices.reviewFacts(ctx.orgId, rootConversationId, ctx.conversationId);
|
|
2084
|
+
if (now === null ||
|
|
2085
|
+
now.mode !== asked.command?.mode ||
|
|
2086
|
+
carriedRoot({ workspace: now.workspace, workingRoot: settled.workingRoot }) === undefined) {
|
|
2087
|
+
// the root the person approved stays the one judged (B-18): only the carried root goes
|
|
2088
|
+
return { ...settled, workingRoot: undefined };
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
return settled;
|
|
2092
|
+
}
|
|
2093
|
+
const facts = await devices.reviewFacts(ctx.orgId, rootConversationId, ctx.conversationId);
|
|
2094
|
+
if (facts === null)
|
|
2095
|
+
return { kind: "continue" }; // no device: the tool fails on its own
|
|
2096
|
+
const kind = reviewKindOf(tool.key);
|
|
2097
|
+
const attended = ctx.unattended == null && ctx.accountId === facts.ownerAccountId;
|
|
2098
|
+
// a command over the ceiling is refused before any review: no stage reads it in full, and no
|
|
2099
|
+
// approval could bind a text the person cannot see (hardening spec R8)
|
|
2100
|
+
if (kind === "command") {
|
|
2101
|
+
const text = textField(input, "command");
|
|
2102
|
+
if (text.length > COMMAND_ASK_MAX_CHARS) {
|
|
2103
|
+
return {
|
|
2104
|
+
kind: "result",
|
|
2105
|
+
content: commandTooLongText(text.length),
|
|
2106
|
+
review: denyRecord("rule", null, commandTooLongReason(text.length)),
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
const verdict = await review.review({
|
|
2111
|
+
orgId: ctx.orgId,
|
|
2112
|
+
conversationId: rootConversationId,
|
|
2113
|
+
runId: ctx.runId,
|
|
2114
|
+
accountId: ctx.accountId,
|
|
2115
|
+
toolKey: tool.key,
|
|
2116
|
+
input,
|
|
2117
|
+
mode: facts.mode,
|
|
2118
|
+
// the working root: a bound project's root, where commands start and writes need no ask
|
|
2119
|
+
workspace: facts.workingRoot,
|
|
2120
|
+
// the owner's home, never the project root: the home-level rules stay where they were
|
|
2121
|
+
home: facts.home,
|
|
2122
|
+
// and the device workspace's home, so a project outside every home still protects it
|
|
2123
|
+
deviceHome: facts.deviceHome,
|
|
2124
|
+
attended,
|
|
2125
|
+
step: ctx.step,
|
|
2126
|
+
callId: call.id,
|
|
2127
|
+
signal: ctx.signal,
|
|
2128
|
+
...reviewParentOf(ctx.parent),
|
|
2129
|
+
agentId: ctx.agentId,
|
|
2130
|
+
agentVersion: ctx.agentVersion,
|
|
2131
|
+
...(ctx.conversationKind !== undefined && { conversationKind: ctx.conversationKind }),
|
|
2132
|
+
});
|
|
2133
|
+
if (verdict.decision === "allow") {
|
|
2134
|
+
return {
|
|
2135
|
+
kind: "continue",
|
|
2136
|
+
review: allowRecord(verdict),
|
|
2137
|
+
workingRoot: carriedRoot(facts),
|
|
2138
|
+
reviewedAgainst: facts.workingRoot,
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
if (verdict.decision === "deny") {
|
|
2142
|
+
return {
|
|
2143
|
+
kind: "result",
|
|
2144
|
+
content: commandDeniedText(verdict.reason, kind),
|
|
2145
|
+
review: denyRecord(verdict.by, verdict.rule, verdict.reason),
|
|
2146
|
+
};
|
|
2147
|
+
}
|
|
2148
|
+
// ask
|
|
2149
|
+
const command = kind === "command" ? textField(input, "command") : tool.key;
|
|
2150
|
+
if (!attended) {
|
|
2151
|
+
const reason = verdict.reason;
|
|
2152
|
+
return {
|
|
2153
|
+
kind: "result",
|
|
2154
|
+
content: commandUnattendedText(reason, kind),
|
|
2155
|
+
review: denyRecord(verdict.by, verdict.rule, reason),
|
|
2156
|
+
};
|
|
2157
|
+
}
|
|
2158
|
+
const detail = {
|
|
2159
|
+
deviceId: facts.deviceId,
|
|
2160
|
+
deviceName: facts.deviceName,
|
|
2161
|
+
mode: facts.mode,
|
|
2162
|
+
kind,
|
|
2163
|
+
// the whole command the approval covers (the event keeps a clamped copy for display)
|
|
2164
|
+
command,
|
|
2165
|
+
// a relative path as it will be written: resolved against the working root
|
|
2166
|
+
// (every path a GenerateImage call writes, comma-separated)
|
|
2167
|
+
...(kind === "write" && {
|
|
2168
|
+
path: clipText(writePathsOf(tool.key, input)
|
|
2169
|
+
.map((p) => facts.workingRoot === undefined ? p : pathAgainstWorkingRoot(p, facts.workingRoot))
|
|
2170
|
+
.join(", "), 4096),
|
|
2171
|
+
}),
|
|
2172
|
+
rule: verdict.rule,
|
|
2173
|
+
reason: clipText(verdict.reason, COMMAND_ASK_TEXT_MAX_CHARS),
|
|
2174
|
+
// the root the review judged, always (the workspace in free mode): the approved call runs
|
|
2175
|
+
// against what the person approved, not a later snapshot
|
|
2176
|
+
...(facts.workingRoot !== undefined && { workingRoot: facts.workingRoot }),
|
|
2177
|
+
};
|
|
2178
|
+
let ask;
|
|
2179
|
+
try {
|
|
2180
|
+
ask = await this.deps.approvals.requestCommand({
|
|
2181
|
+
orgId: ctx.orgId,
|
|
2182
|
+
conversationId: ctx.conversationId,
|
|
2183
|
+
runId: ctx.runId,
|
|
2184
|
+
step: ctx.step,
|
|
2185
|
+
callId: call.id,
|
|
2186
|
+
requestedFor: facts.ownerAccountId,
|
|
2187
|
+
detail,
|
|
2188
|
+
// `once` always; `session` only for a concrete rule class, never an `unsure.*` catch-all (P-D2)
|
|
2189
|
+
scopes: isSessionGrantableRule(verdict.rule) ? ["once", "session"] : ["once"],
|
|
2190
|
+
});
|
|
2191
|
+
}
|
|
2192
|
+
catch (err) {
|
|
2193
|
+
// fail closed: an ask that cannot be created is a deny, never a run of the held call
|
|
2194
|
+
this.deps.log.warn("command ask could not be created; denying the call", {
|
|
2195
|
+
conversationId: ctx.conversationId,
|
|
2196
|
+
callId: call.id,
|
|
2197
|
+
err,
|
|
2198
|
+
});
|
|
2199
|
+
const reason = "The approval could not be created";
|
|
2200
|
+
return {
|
|
2201
|
+
kind: "result",
|
|
2202
|
+
content: commandDeniedText(reason, kind),
|
|
2203
|
+
review: denyRecord(verdict.by, verdict.rule, reason),
|
|
2204
|
+
};
|
|
2205
|
+
}
|
|
2206
|
+
return { kind: "wait", wait: approvalWait(ask) };
|
|
2207
|
+
}
|
|
2208
|
+
/**
|
|
2209
|
+
* Whether this call takes the managed route's permission review: a managed builtin once
|
|
2210
|
+
* activated ({@link MANAGED_OPERATION_TOOLS}) whose call enters the device ({@link entersDevice}).
|
|
2211
|
+
*/
|
|
2212
|
+
operationScoped(tool, input) {
|
|
2213
|
+
return (tool.source.kind === "builtin" &&
|
|
2214
|
+
this.deps.permissionOperations?.has(tool.key) === true &&
|
|
2215
|
+
entersDevice(tool.key, input));
|
|
2216
|
+
}
|
|
2217
|
+
/**
|
|
2218
|
+
* The permission review of a managed call, with the escalation state a continued restricted
|
|
2219
|
+
* `Bash` call carries to its tool (its sandbox hints: retry with `sandbox: "escalated"` only
|
|
2220
|
+
* where this device and org allow it).
|
|
2221
|
+
*/
|
|
2222
|
+
async reviewPermissionCall(ctx, call, tool, input) {
|
|
2223
|
+
const note = {};
|
|
2224
|
+
const outcome = await this.reviewPermissionCallWith(ctx, call, tool, input, note);
|
|
2225
|
+
if (outcome?.kind !== "continue")
|
|
2226
|
+
return outcome;
|
|
2227
|
+
return {
|
|
2228
|
+
...outcome,
|
|
2229
|
+
...(note.escalation !== undefined && { sandboxEscalation: note.escalation }),
|
|
2230
|
+
...(note.refusal !== undefined && { sandboxEscalationRefusal: note.refusal }),
|
|
2231
|
+
};
|
|
2232
|
+
}
|
|
2233
|
+
async reviewPermissionCallWith(ctx, call, tool, input, note) {
|
|
2234
|
+
if (!this.permissionAuthority ||
|
|
2235
|
+
!this.permissionGrants ||
|
|
2236
|
+
!this.permissionLocks ||
|
|
2237
|
+
!this.deps.devices ||
|
|
2238
|
+
!this.deps.review)
|
|
2239
|
+
return null;
|
|
2240
|
+
const permissionLocks = this.permissionLocks;
|
|
2241
|
+
const previous = await this.deps.approvals.commandForCall(ctx.runId, call.id);
|
|
2242
|
+
// A settled refusal belongs to this call, not to a replaceable permission revision.
|
|
2243
|
+
if (previous && !["pending", "approved", "superseded"].includes(previous.status))
|
|
2244
|
+
return this.settledCommandAsk(previous, tool.key);
|
|
2245
|
+
const device = await this.deps.devices.reviewFacts(ctx.orgId, ctx.parent?.rootConversationId ?? ctx.conversationId, ctx.conversationId);
|
|
2246
|
+
if (!device)
|
|
2247
|
+
return null;
|
|
2248
|
+
// a run another account triggered never uses the owner's device (the tool refuses it): there
|
|
2249
|
+
// is no permission authority of that account here to review against
|
|
2250
|
+
if (ctx.accountId !== device.ownerAccountId)
|
|
2251
|
+
return null;
|
|
2252
|
+
const use = {
|
|
2253
|
+
orgId: ctx.orgId,
|
|
2254
|
+
deviceId: device.deviceId,
|
|
2255
|
+
holderConversationId: ctx.conversationId,
|
|
2256
|
+
actor: { accountId: ctx.accountId, conversationId: ctx.conversationId, runId: ctx.runId },
|
|
2257
|
+
};
|
|
2258
|
+
const preview = () => this.permissionAuthority.previewCall(use, { runId: ctx.runId, callId: call.id }, ctx.signal);
|
|
2259
|
+
let facts = await preview();
|
|
2260
|
+
// the facts first: a device not yet started (or not yet probed) whose review depends on them
|
|
2261
|
+
// is started under the normal lifecycle lease, which records a cloud instance's permission
|
|
2262
|
+
// evidence or a local one's installed binding, and read again
|
|
2263
|
+
if (facts.availability.state === "unprobed" &&
|
|
2264
|
+
!facts.unattended &&
|
|
2265
|
+
this.sandboxes &&
|
|
2266
|
+
REVIEWED_ON_FACTS.has(tool.key)) {
|
|
2267
|
+
try {
|
|
2268
|
+
await this.sandboxes.ensureRunning(use, ctx.signal);
|
|
2269
|
+
facts = await preview();
|
|
2270
|
+
}
|
|
2271
|
+
catch (err) {
|
|
2272
|
+
// a start that fails leaves the facts unverified (the conservative branch below); the
|
|
2273
|
+
// tool's own entry reports the device's state
|
|
2274
|
+
ctx.signal.throwIfAborted();
|
|
2275
|
+
this.deps.log.warn("cannot start the device before its review; reviewing unverified", {
|
|
2276
|
+
conversationId: ctx.conversationId,
|
|
2277
|
+
deviceId: device.deviceId,
|
|
2278
|
+
err,
|
|
2279
|
+
});
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
if (facts.unattended) {
|
|
2283
|
+
// an unattended run never runs a call outside the sandbox: no one could approve it
|
|
2284
|
+
if (isEscalatedCall(tool.key, input)) {
|
|
2285
|
+
const content = escalationRefusedText(ESCALATION_UNATTENDED_WHY, facts.workingRoot);
|
|
2286
|
+
return { kind: "result", content, review: denyRecord("rule", null, content) };
|
|
2287
|
+
}
|
|
2288
|
+
return null;
|
|
2289
|
+
}
|
|
2290
|
+
if (facts.availability.state !== "supported") {
|
|
2291
|
+
// still unverified: the conservative command review decides (every profile), but a call
|
|
2292
|
+
// that needs more reach is refused now: admission could never run what an approval allowed
|
|
2293
|
+
const unverified = buildPermissionCandidate({ toolKey: tool.key, specHash: tool.specHash, rawInput: call.input, validatedInput: input }, facts, [device.home, device.deviceHome], { backgroundMaxSeconds: backgroundMaxSeconds(this.config.get()) });
|
|
2294
|
+
if (unverified.kind === "in-scope")
|
|
2295
|
+
return null;
|
|
2296
|
+
// a device that cannot run scoped work at all says why (R9); one not checked yet says that
|
|
2297
|
+
const content = unverified.kind !== "proposal"
|
|
2298
|
+
? unverified.message
|
|
2299
|
+
: facts.availability.state === "unsupported"
|
|
2300
|
+
? admissionUnavailableText(facts.availability.cause ?? { kind: "runtime" })
|
|
2301
|
+
: PERMISSION_SUPPORT_UNVERIFIED_TEXT;
|
|
2302
|
+
return { kind: "result", content, review: denyRecord("rule", null, content) };
|
|
2303
|
+
}
|
|
2304
|
+
if (tool.key === "Bash" && textField(input, "command").length > COMMAND_ASK_MAX_CHARS)
|
|
2305
|
+
return {
|
|
2306
|
+
kind: "result",
|
|
2307
|
+
content: commandTooLongText(textField(input, "command").length),
|
|
2308
|
+
review: denyRecord("rule", null, "The command exceeds the review limit"),
|
|
2309
|
+
};
|
|
2310
|
+
const escalated = isEscalatedCall(tool.key, input);
|
|
2311
|
+
// the escalation state the tool's hints read: a Bash call (every profile runs it in the
|
|
2312
|
+
// sandbox) on a device and org whose ceiling allows running outside the sandbox
|
|
2313
|
+
if (tool.key === "Bash" && !facts.escalationRefusal)
|
|
2314
|
+
note.escalation = escalated ? "escalated" : "available";
|
|
2315
|
+
// where it cannot (a layer's outside-sandbox setting is off, the runtime cannot), the hints
|
|
2316
|
+
// say why and who changes it, in the escalation refusal's per-layer words
|
|
2317
|
+
else if (tool.key === "Bash" && facts.escalationRefusal && !escalated)
|
|
2318
|
+
note.refusal = facts.escalationRefusal;
|
|
2319
|
+
// candidate building runs for every profile: the profile only chooses who approves
|
|
2320
|
+
const built = buildPermissionCandidate({
|
|
2321
|
+
toolKey: tool.key,
|
|
2322
|
+
specHash: tool.specHash,
|
|
2323
|
+
rawInput: call.input,
|
|
2324
|
+
validatedInput: input,
|
|
2325
|
+
}, facts, [device.home, device.deviceHome], { backgroundMaxSeconds: backgroundMaxSeconds(this.config.get()) });
|
|
2326
|
+
if (built.kind === "unsupported") {
|
|
2327
|
+
// a Bash reach the restricted scope cannot grant: retrying outside the sandbox may (a
|
|
2328
|
+
// protected location's text names the escalation itself)
|
|
2329
|
+
const content = note.escalation === "available" && built.code === "unbounded-scope"
|
|
2330
|
+
? `${built.message}${ESCALATION_RETRY_HINT}`
|
|
2331
|
+
: built.message;
|
|
2332
|
+
return { kind: "result", content, review: denyRecord("rule", null, content) };
|
|
2333
|
+
}
|
|
2334
|
+
const candidate = built.kind === "proposal" ? built.candidate : undefined;
|
|
2335
|
+
// who approves this call's crossing: the person, the review model, or nobody (Full access
|
|
2336
|
+
// grants it within the device's ceilings); a sub-agent's escalation never goes to nobody
|
|
2337
|
+
const approver = approverForCrossing({
|
|
2338
|
+
profile: facts.profile,
|
|
2339
|
+
crossing: candidate ? crossingOfCandidate(candidate) : "sensitive",
|
|
2340
|
+
subAgent: ctx.parent !== undefined,
|
|
2341
|
+
});
|
|
2342
|
+
// a sensitive-command consent the person settled (no proposed reach): the call runs under
|
|
2343
|
+
// the base scope it was asked under; the approval adds nothing
|
|
2344
|
+
if (previous &&
|
|
2345
|
+
previous.status !== "superseded" &&
|
|
2346
|
+
!candidate &&
|
|
2347
|
+
!previous.command?.permissionCandidate) {
|
|
2348
|
+
const settled = this.settledCommandAsk(previous, tool.key);
|
|
2349
|
+
// the root the person approved is carried only while the device still runs in the mode
|
|
2350
|
+
// recorded with the ask (B-18: the judged root stays the one recorded)
|
|
2351
|
+
if (settled.kind === "continue" &&
|
|
2352
|
+
settled.workingRoot !== undefined &&
|
|
2353
|
+
(device.mode !== previous.command?.mode ||
|
|
2354
|
+
carriedRoot({ workspace: device.workspace, workingRoot: settled.workingRoot }) ===
|
|
2355
|
+
undefined))
|
|
2356
|
+
return { ...settled, workingRoot: undefined };
|
|
2357
|
+
return settled;
|
|
2358
|
+
}
|
|
2359
|
+
if (previous &&
|
|
2360
|
+
previous.status !== "superseded" &&
|
|
2361
|
+
candidate &&
|
|
2362
|
+
previous.command?.permissionCandidate?.candidateHash === candidate.candidateHash) {
|
|
2363
|
+
if (previous.status !== "approved")
|
|
2364
|
+
return this.settledCommandAsk(previous, tool.key);
|
|
2365
|
+
const grant = await withTransactionFencePrelude(() => permissionLocks.acquire({
|
|
2366
|
+
orgId: facts.orgId,
|
|
2367
|
+
deviceId: facts.deviceId,
|
|
2368
|
+
rootConversationId: facts.rootConversationId,
|
|
2369
|
+
}, { kind: "admit" }), () => this.findPermissionGrant(candidate));
|
|
2370
|
+
if (grant)
|
|
2371
|
+
return this.settledCommandAsk(previous, tool.key);
|
|
2372
|
+
}
|
|
2373
|
+
if (candidate) {
|
|
2374
|
+
const existingGrant = await withTransactionFencePrelude(() => permissionLocks.acquire({
|
|
2375
|
+
orgId: facts.orgId,
|
|
2376
|
+
deviceId: facts.deviceId,
|
|
2377
|
+
rootConversationId: facts.rootConversationId,
|
|
2378
|
+
}, { kind: "admit" }), () => this.findPermissionGrant(candidate));
|
|
2379
|
+
if (existingGrant) {
|
|
2380
|
+
if (existingGrant.scopeKind !== candidate.scopeKind ||
|
|
2381
|
+
permissionScopeHash(existingGrant.expansion) !==
|
|
2382
|
+
permissionScopeHash(candidate.permissionScope))
|
|
2383
|
+
return {
|
|
2384
|
+
kind: "result",
|
|
2385
|
+
content: "This call already has different permission evidence; submit a new call with the intended directory scope.",
|
|
2386
|
+
review: denyRecord("rule", null, "Conflicting permission evidence"),
|
|
2387
|
+
};
|
|
2388
|
+
return {
|
|
2389
|
+
kind: "continue",
|
|
2390
|
+
workingRoot: carriedRoot(device),
|
|
2391
|
+
reviewedAgainst: facts.workingRoot,
|
|
2392
|
+
// the evidence's real source: the person's approval, the review model's allow or the
|
|
2393
|
+
// Full access auto-grant
|
|
2394
|
+
review: {
|
|
2395
|
+
decision: "allow",
|
|
2396
|
+
by: existingGrant.source === "human"
|
|
2397
|
+
? "person"
|
|
2398
|
+
: existingGrant.source === "review-model"
|
|
2399
|
+
? "classifier"
|
|
2400
|
+
: "rule",
|
|
2401
|
+
rule: null,
|
|
2402
|
+
reason: "The exact current call already has approved permission evidence.",
|
|
2403
|
+
profile: facts.profile,
|
|
2404
|
+
profileRevision: facts.profileRevision,
|
|
2405
|
+
scopeRevision: facts.scopeRevision,
|
|
2406
|
+
decisionSource: existingGrant.source,
|
|
2407
|
+
crossing: crossingOfCandidate(candidate),
|
|
2408
|
+
...(candidate.escalation ? { sandbox: "escalated" } : {}),
|
|
2409
|
+
},
|
|
2410
|
+
};
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
const verdict = await this.deps.review.review({
|
|
2414
|
+
orgId: ctx.orgId,
|
|
2415
|
+
conversationId: facts.rootConversationId,
|
|
2416
|
+
runId: ctx.runId,
|
|
2417
|
+
accountId: ctx.accountId,
|
|
2418
|
+
toolKey: tool.key,
|
|
2419
|
+
input,
|
|
2420
|
+
mode: device.mode,
|
|
2421
|
+
workspace: facts.workingRoot,
|
|
2422
|
+
home: device.home,
|
|
2423
|
+
deviceHome: device.deviceHome,
|
|
2424
|
+
attended: true,
|
|
2425
|
+
step: ctx.step,
|
|
2426
|
+
callId: call.id,
|
|
2427
|
+
signal: ctx.signal,
|
|
2428
|
+
...reviewParentOf(ctx.parent),
|
|
2429
|
+
agentId: ctx.agentId,
|
|
2430
|
+
agentVersion: ctx.agentVersion,
|
|
2431
|
+
...(ctx.conversationKind ? { conversationKind: ctx.conversationKind } : {}),
|
|
2432
|
+
permissionProfile: facts.profile,
|
|
2433
|
+
...(candidate ? { permissionCandidate: candidate } : {}),
|
|
2434
|
+
...(note.escalation === "available" ? { escalationAvailable: true } : {}),
|
|
2435
|
+
});
|
|
2436
|
+
// who decided: the review knows the call's consents (a credential consent sends a Full access
|
|
2437
|
+
// escalation to the review model); without its answer, the profile's approver
|
|
2438
|
+
const decidedBy = verdict.approver ?? approver;
|
|
2439
|
+
if (candidate && decidedBy === "review-model") {
|
|
2440
|
+
await withTransactionFencePrelude(() => permissionLocks.acquire({
|
|
2441
|
+
orgId: facts.orgId,
|
|
2442
|
+
deviceId: facts.deviceId,
|
|
2443
|
+
rootConversationId: facts.rootConversationId,
|
|
2444
|
+
}, { kind: "admit" }), () => this.recordPermissionReview(candidate, verdict));
|
|
2445
|
+
}
|
|
2446
|
+
// Full access: the crossing is granted for this call, recorded exactly once (its event, the
|
|
2447
|
+
// audit row and the grant in one fenced transaction); a fixed deny never reaches this
|
|
2448
|
+
if (candidate && decidedBy === "none" && verdict.decision === "allow") {
|
|
2449
|
+
if (!this.autoGrants)
|
|
2450
|
+
throw new Error("Permission auto-grants are unavailable");
|
|
2451
|
+
await this.autoGrants.record(candidate, verdict.sensitive ?? []);
|
|
2452
|
+
}
|
|
2453
|
+
const provenance = {
|
|
2454
|
+
profile: facts.profile,
|
|
2455
|
+
profileRevision: facts.profileRevision,
|
|
2456
|
+
scopeRevision: facts.scopeRevision,
|
|
2457
|
+
};
|
|
2458
|
+
if (verdict.decision === "deny")
|
|
2459
|
+
return {
|
|
2460
|
+
kind: "result",
|
|
2461
|
+
content: commandDeniedText(verdict.reason, reviewKindOf(tool.key)),
|
|
2462
|
+
review: { ...denyRecord(verdict.by, verdict.rule, verdict.reason), ...provenance },
|
|
2463
|
+
};
|
|
2464
|
+
if (verdict.decision === "allow")
|
|
2465
|
+
return {
|
|
2466
|
+
kind: "continue",
|
|
2467
|
+
workingRoot: carriedRoot(device),
|
|
2468
|
+
reviewedAgainst: facts.workingRoot,
|
|
2469
|
+
review: {
|
|
2470
|
+
...allowRecord(verdict),
|
|
2471
|
+
...provenance,
|
|
2472
|
+
decisionSource: verdict.by === "classifier"
|
|
2473
|
+
? "review-model"
|
|
2474
|
+
: facts.profile === "full-access"
|
|
2475
|
+
? "full-access"
|
|
2476
|
+
: "scope",
|
|
2477
|
+
...(candidate
|
|
2478
|
+
? { crossing: crossingOfCandidate(candidate) }
|
|
2479
|
+
: verdict.crossing
|
|
2480
|
+
? { crossing: verdict.crossing }
|
|
2481
|
+
: {}),
|
|
2482
|
+
// the review model's allow or Full access issued this call's escalation grant: it runs
|
|
2483
|
+
// outside the sandbox
|
|
2484
|
+
...(candidate?.escalation && (verdict.by === "classifier" || decidedBy === "none")
|
|
2485
|
+
? { sandbox: "escalated" }
|
|
2486
|
+
: {}),
|
|
2487
|
+
},
|
|
2488
|
+
};
|
|
2489
|
+
// an ask: the sensitive-command consent (no proposed reach: approved, the call runs under the
|
|
2490
|
+
// base scope) or the displayed expansion (approved, the call's grant is issued)
|
|
2491
|
+
const kind = reviewKindOf(tool.key);
|
|
2492
|
+
// every path the call writes (a GenerateImage call's suffixed paths, comma-separated)
|
|
2493
|
+
const filePaths = kind === "write" ? writePathsOf(tool.key, input).filter(Boolean) : [];
|
|
2494
|
+
const ask = await this.deps.approvals.requestCommand({
|
|
2495
|
+
orgId: ctx.orgId,
|
|
2496
|
+
conversationId: ctx.conversationId,
|
|
2497
|
+
runId: ctx.runId,
|
|
2498
|
+
step: ctx.step,
|
|
2499
|
+
callId: call.id,
|
|
2500
|
+
requestedFor: ctx.accountId,
|
|
2501
|
+
// `session` only for a consent rule class with no expansion (a grant is per call)
|
|
2502
|
+
scopes: !candidate && isSessionGrantableRule(verdict.rule) ? ["once", "session"] : ["once"],
|
|
2503
|
+
detail: {
|
|
2504
|
+
deviceId: device.deviceId,
|
|
2505
|
+
deviceName: device.deviceName,
|
|
2506
|
+
mode: device.mode,
|
|
2507
|
+
kind,
|
|
2508
|
+
command: tool.key === "Bash" ? textField(input, "command") : tool.key,
|
|
2509
|
+
rule: verdict.rule,
|
|
2510
|
+
reason: clipText(verdict.reason, COMMAND_ASK_TEXT_MAX_CHARS),
|
|
2511
|
+
workingRoot: facts.workingRoot,
|
|
2512
|
+
...(candidate
|
|
2513
|
+
? {
|
|
2514
|
+
permissionCandidate: candidate,
|
|
2515
|
+
permissionScope: candidate.permissionScope,
|
|
2516
|
+
candidateHash: candidate.candidateHash,
|
|
2517
|
+
...(candidate.targetPath
|
|
2518
|
+
? { targetPath: candidate.targetPath, path: candidate.targetPath }
|
|
2519
|
+
: {}),
|
|
2520
|
+
...(candidate.escalation ? { escalation: candidate.escalation } : {}),
|
|
2521
|
+
}
|
|
2522
|
+
: filePaths.length > 0
|
|
2523
|
+
? {
|
|
2524
|
+
path: clipText(filePaths.map((p) => pathAgainstWorkingRoot(p, facts.workingRoot)).join(", "), 4096),
|
|
2525
|
+
}
|
|
2526
|
+
: {}),
|
|
2527
|
+
},
|
|
2528
|
+
});
|
|
2529
|
+
return { kind: "wait", wait: approvalWait(ask) };
|
|
2530
|
+
}
|
|
2531
|
+
/**
|
|
2532
|
+
* Whether an execution of this call was admitted outside the sandbox (a per-call escalation's
|
|
2533
|
+
* full reach, under any profile): an intent past admission, or one revoked after dispatch, whose
|
|
2534
|
+
* device-wide scope came from the call's escalation grant.
|
|
2535
|
+
*/
|
|
2536
|
+
// org-filter: runId is the call context's own run (ctx.runId), a runtime uuid, never caller input
|
|
2537
|
+
async admittedOutsideSandbox(runId, callId) {
|
|
2538
|
+
const rows = await this.deps.db
|
|
2539
|
+
.selectFrom("sandbox_operation_intents as i")
|
|
2540
|
+
.innerJoin("permission_call_grants as g", "g.id", "i.permission_grant_id")
|
|
2541
|
+
.select(["i.scope", "i.state", "i.outcome_unknown"])
|
|
2542
|
+
.where("i.run_id", "=", runId)
|
|
2543
|
+
.where("i.call_id", "=", callId)
|
|
2544
|
+
.where("i.method", "in", ["exec", "backgroundStart"])
|
|
2545
|
+
.where("g.scope_kind", "=", "sandbox-escalation")
|
|
2546
|
+
.execute();
|
|
2547
|
+
return rows.some((r) => {
|
|
2548
|
+
const scope = r.scope;
|
|
2549
|
+
const admitted = r.state === "revoked" ? r.outcome_unknown : r.state !== "pending";
|
|
2550
|
+
return admitted && scope.filesystem?.kind === "device";
|
|
2551
|
+
});
|
|
2552
|
+
}
|
|
2553
|
+
findPermissionGrant(candidate) {
|
|
2554
|
+
if (!this.permissionGrants)
|
|
2555
|
+
throw new Error("Permission grants are unavailable");
|
|
2556
|
+
return this.permissionGrants.findForAdmission(candidate.binding);
|
|
2557
|
+
}
|
|
2558
|
+
async recordPermissionReview(candidate, verdict) {
|
|
2559
|
+
if (!this.permissionGrants)
|
|
2560
|
+
throw new Error("Permission grants are unavailable");
|
|
2561
|
+
await this.permissionGrants.assertCurrent(candidate.binding);
|
|
2562
|
+
const events = await this.deps.eventLog.appendIn(candidate.binding.conversationId, [
|
|
2563
|
+
{
|
|
2564
|
+
type: "permission_reviewed",
|
|
2565
|
+
runId: candidate.binding.runId,
|
|
2566
|
+
payload: {
|
|
2567
|
+
...candidate,
|
|
2568
|
+
outcome: verdict.decision,
|
|
2569
|
+
reason: verdict.reason,
|
|
2570
|
+
// the review model only for its own verdict: a fixed rule's deny, a rule ask (the review
|
|
2571
|
+
// model unmapped or not consulted) and the fail-closed ask are the rules'
|
|
2572
|
+
decisionSource: verdict.by === "classifier" ? "review-model" : "rule",
|
|
2573
|
+
},
|
|
2574
|
+
},
|
|
2575
|
+
]);
|
|
2576
|
+
const event = events[0];
|
|
2577
|
+
if (!event)
|
|
2578
|
+
throw new Error("The review event was not recorded");
|
|
2579
|
+
if (verdict.decision === "allow" && verdict.by === "classifier")
|
|
2580
|
+
await this.permissionGrants.issueLocked(candidate, {
|
|
2581
|
+
source: "review-model",
|
|
2582
|
+
reviewEventSeq: event.seq,
|
|
2583
|
+
decidedBy: null,
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
/** The outcome of a call whose `command` approval was already asked (a resume). */
|
|
2587
|
+
settledCommandAsk(ask, toolKey) {
|
|
2588
|
+
const kind = reviewKindOf(toolKey);
|
|
2589
|
+
const rule = ask.command?.rule ?? null;
|
|
2590
|
+
if (ask.status === "pending")
|
|
2591
|
+
return { kind: "wait", wait: approvalWait(ask) };
|
|
2592
|
+
if (ask.status === "approved") {
|
|
2593
|
+
return {
|
|
2594
|
+
kind: "continue",
|
|
2595
|
+
commandAsk: ask,
|
|
2596
|
+
review: this.personAllowRecord(ask),
|
|
2597
|
+
workingRoot: ask.command?.workingRoot,
|
|
2598
|
+
reviewedAgainst: ask.command?.workingRoot,
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2601
|
+
if (ask.status === "denied") {
|
|
2602
|
+
const reason = ask.denyReason;
|
|
2603
|
+
return {
|
|
2604
|
+
kind: "result",
|
|
2605
|
+
content: commandDeclinedText(reason, kind),
|
|
2606
|
+
review: denyRecord("person", rule, reason ?? "The user declined."),
|
|
2607
|
+
};
|
|
2608
|
+
}
|
|
2609
|
+
const text = ask.status === "expired" ? approvalExpiredText(approvalHours(ask)) : APPROVAL_CANCELLED_TEXT;
|
|
2610
|
+
return { kind: "result", content: text, review: denyRecord("person", rule, text) };
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
* The review record of a command (or write) the person allowed: its scope, and for a shell
|
|
2614
|
+
* command the SHA-256 of the text the ask holds in full, so an audit can match record and text.
|
|
2615
|
+
*/
|
|
2616
|
+
personAllowRecord(ask) {
|
|
2617
|
+
const binding = ask.command?.permissionCandidate?.binding;
|
|
2618
|
+
const escalated = ask.command?.permissionCandidate?.scopeKind === "sandbox-escalation";
|
|
2619
|
+
return {
|
|
2620
|
+
...(escalated ? { sandbox: "escalated" } : {}),
|
|
2621
|
+
...(binding
|
|
2622
|
+
? {
|
|
2623
|
+
profile: binding.profile,
|
|
2624
|
+
profileRevision: binding.profileRevision,
|
|
2625
|
+
scopeRevision: binding.scopeRevision,
|
|
2626
|
+
decisionSource: "human",
|
|
2627
|
+
}
|
|
2628
|
+
: {}),
|
|
2629
|
+
decision: "allow",
|
|
2630
|
+
by: "person",
|
|
2631
|
+
rule: ask.command?.rule ?? null,
|
|
2632
|
+
reason: ask.command?.reason ?? "The user allowed this call.",
|
|
2633
|
+
...((ask.scope === "once" || ask.scope === "session") && { scope: ask.scope }),
|
|
2634
|
+
...(ask.command !== null &&
|
|
2635
|
+
ask.command.kind === "command" && {
|
|
2636
|
+
commandHash: sha256Hex(ask.command.command),
|
|
2637
|
+
}),
|
|
2638
|
+
};
|
|
2639
|
+
}
|
|
2640
|
+
/**
|
|
2641
|
+
* A foreground command's refused network hosts (network ask-to-allow spec §6.2, §6.8, §8.3):
|
|
2642
|
+
* the `network_blocked` event, the missing grants of an unattended run, and either notes for the
|
|
2643
|
+
* result written now, or (device-layer hosts worth asking) `network_blocked` and the call's
|
|
2644
|
+
* `tool.called` audit written now, the result kept in a network ask to the device's owner and
|
|
2645
|
+
* the run's wait. The kept result is the formatted one (≤ 16 KB: larger output is archived)
|
|
2646
|
+
* followed by the notes written now; it is written with the decision's note when the ask
|
|
2647
|
+
* settles (P-D2).
|
|
2648
|
+
*/
|
|
2649
|
+
async networkBlocked(ctx, callId, toolKey, input, report, pre, callAudit, result,
|
|
2650
|
+
/** Admission's verdict for this call: `available` when it may run outside the sandbox. */
|
|
2651
|
+
escalation,
|
|
2652
|
+
/** Why this call could not run outside the sandbox here (absent when it could). */
|
|
2653
|
+
escalationRefusal,
|
|
2654
|
+
/**
|
|
2655
|
+
* A device service's refusals (browser use spec §7.1): the extension whose service asked and
|
|
2656
|
+
* the call's attempt. Only "always" is offered; once approved the call runs again.
|
|
2657
|
+
*/
|
|
2658
|
+
service,
|
|
2659
|
+
/**
|
|
2660
|
+
* Plan-only pass: compute the `network_blocked` event and every refused host's note without
|
|
2661
|
+
* opening a second network ask (used when a loopback ask already takes this call's ask slot).
|
|
2662
|
+
*/
|
|
2663
|
+
planOnly) {
|
|
2664
|
+
const hosts = blockedEventHosts(report.blocked);
|
|
2665
|
+
if (hosts.length === 0)
|
|
2666
|
+
return { kind: "write", event: null, notes: [] };
|
|
2667
|
+
const event = {
|
|
2668
|
+
type: "network_blocked",
|
|
2669
|
+
runId: ctx.runId,
|
|
2670
|
+
idemKey: networkBlockedIdemKey(ctx.runId, callId),
|
|
2671
|
+
payload: { step: ctx.step, callId, hosts },
|
|
2672
|
+
};
|
|
2673
|
+
const network = this.deps.network;
|
|
2674
|
+
if (network === undefined)
|
|
2675
|
+
return { kind: "write", event, notes: [] };
|
|
2676
|
+
const run = hosts.some((h) => h.layer === "device")
|
|
2677
|
+
? await network.grants.runState(ctx.runId, report.deviceId)
|
|
2678
|
+
: null;
|
|
2679
|
+
const limits = this.config.get().sandbox.limits;
|
|
2680
|
+
// the ask offers what the device's provider enforces (device-provider spec §6.3): a run grant
|
|
2681
|
+
// only with per-operation hosts, "add to this device's list" only for hosts its own list can
|
|
2682
|
+
// take; a host neither reaches is unavailable, never asked about
|
|
2683
|
+
const sandbox = await network.sandbox?.hostRefusal({
|
|
2684
|
+
orgId: ctx.orgId,
|
|
2685
|
+
deviceId: report.deviceId,
|
|
2686
|
+
});
|
|
2687
|
+
const plan = planNetworkAsk(hosts, run, {
|
|
2688
|
+
unattended: ctx.unattended,
|
|
2689
|
+
outsideCeiling: (h) => orgHostOutsideCeiling(limits, h),
|
|
2690
|
+
...(sandbox !== undefined &&
|
|
2691
|
+
(service !== undefined
|
|
2692
|
+
? serviceAskTerms(sandbox)
|
|
2693
|
+
: {
|
|
2694
|
+
...deviceAskTerms(sandbox),
|
|
2695
|
+
// the hint follows admission's verdict for this call (never a recomputation), and
|
|
2696
|
+
// only the open network makes a private address the one thing escalation adds
|
|
2697
|
+
escalation: addressEscalationHint(escalation, sandbox.box.networkMode),
|
|
2698
|
+
})),
|
|
2699
|
+
...(service === undefined && escalationRefusal !== undefined && { escalationRefusal }),
|
|
2700
|
+
});
|
|
2701
|
+
if (ctx.unattended != null) {
|
|
2702
|
+
for (const key of plan.missingGrants) {
|
|
2703
|
+
await appendMissingGrant(this.deps.db, ctx.unattended.taskRunId, key);
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
const offer = plan.offer;
|
|
2707
|
+
const addressNote = plan.addressNote;
|
|
2708
|
+
if (plan.ask.length === 0 || offer === undefined)
|
|
2709
|
+
return { kind: "write", event, notes: plan.notes, addressNote };
|
|
2710
|
+
// plan-only pass (loopback ask takes this call's ask slot): keep every other refused host's
|
|
2711
|
+
// note without opening a second ask
|
|
2712
|
+
if (planOnly === true) {
|
|
2713
|
+
return {
|
|
2714
|
+
kind: "write",
|
|
2715
|
+
event,
|
|
2716
|
+
notes: [...plan.notes, serviceAskedNote(plan.ask.map((h) => h.host))],
|
|
2717
|
+
addressNote,
|
|
2718
|
+
};
|
|
2719
|
+
}
|
|
2720
|
+
// one ask per call: a service call that ran again after its ask is not asked again; only a
|
|
2721
|
+
// would-be ask is replaced, the plan's other notes (a host on the list, not yet applied) stay
|
|
2722
|
+
if (service !== undefined &&
|
|
2723
|
+
(await this.deps.approvals.networkForCall(ctx.runId, callId)) !== null) {
|
|
2724
|
+
return {
|
|
2725
|
+
kind: "write",
|
|
2726
|
+
event,
|
|
2727
|
+
notes: [...plan.notes, serviceAskedNote(plan.ask.map((h) => h.host))],
|
|
2728
|
+
addressNote,
|
|
2729
|
+
};
|
|
2730
|
+
}
|
|
2731
|
+
// the device's owner is the only person who may decide (spec §5.2)
|
|
2732
|
+
const owner = await this.deps.db
|
|
2733
|
+
.selectFrom("devices")
|
|
2734
|
+
.select("owner_account_id")
|
|
2735
|
+
.where("id", "=", report.deviceId)
|
|
2736
|
+
.where("org_id", "=", ctx.orgId)
|
|
2737
|
+
.where("deleted_at", "is", null)
|
|
2738
|
+
.executeTakeFirst();
|
|
2739
|
+
if (owner === undefined)
|
|
2740
|
+
return { kind: "write", event, notes: plan.notes, addressNote };
|
|
2741
|
+
let { content, outputId } = result;
|
|
2742
|
+
if (Buffer.byteLength(content, "utf8") > NETWORK_ASK_KEPT_MAX_BYTES && outputId === undefined) {
|
|
2743
|
+
// output under the spill threshold but over what an ask keeps: archive it after all
|
|
2744
|
+
const spilled = await spillIfLarge(result.text, { spillChars: 0, previewChars: this.config.get().tools.outputPreviewChars }, (c) => this.deps.outputs.save({
|
|
2745
|
+
orgId: ctx.orgId,
|
|
2746
|
+
conversationId: ctx.conversationId,
|
|
2747
|
+
callId,
|
|
2748
|
+
content: c,
|
|
2749
|
+
}));
|
|
2750
|
+
content = spilled.content;
|
|
2751
|
+
outputId = spilled.outputId;
|
|
2752
|
+
}
|
|
2753
|
+
const { text: _text, denialHint, ...rest } = result;
|
|
2754
|
+
const kept = {
|
|
2755
|
+
...rest,
|
|
2756
|
+
content: withNetworkNotes(clipKept(content) + denialHintFor(denialHint, addressNote), plan.notes),
|
|
2757
|
+
...(outputId !== undefined && { outputId }),
|
|
2758
|
+
};
|
|
2759
|
+
// the command ran: the call's display-only events (a `device_code`) and network_blocked with
|
|
2760
|
+
// its tool.called now, the result once the ask settles
|
|
2761
|
+
const written = await this.writeResultIn(ctx, callId, toolKey, { isError: result.isError }, [...pre, event], callAudit, []);
|
|
2762
|
+
await this.deps.eventLog.notify(ctx.conversationId, Math.max(...written.map((e) => e.seq)));
|
|
2763
|
+
const given = (input ?? {});
|
|
2764
|
+
const ask = await this.deps.approvals.requestNetwork({
|
|
2765
|
+
orgId: ctx.orgId,
|
|
2766
|
+
conversationId: ctx.conversationId,
|
|
2767
|
+
runId: ctx.runId,
|
|
2768
|
+
step: ctx.step,
|
|
2769
|
+
callId,
|
|
2770
|
+
requestedFor: owner.owner_account_id,
|
|
2771
|
+
toolKey,
|
|
2772
|
+
detail: service === undefined
|
|
2773
|
+
? {
|
|
2774
|
+
kind: "command",
|
|
2775
|
+
deviceId: report.deviceId,
|
|
2776
|
+
hosts: plan.ask,
|
|
2777
|
+
command: typeof given.command === "string" ? clipText(given.command, 2000) : "",
|
|
2778
|
+
description: typeof given.description === "string" ? given.description : null,
|
|
2779
|
+
appliesAt: offer.appliesAt,
|
|
2780
|
+
result: kept,
|
|
2781
|
+
}
|
|
2782
|
+
: {
|
|
2783
|
+
kind: "service",
|
|
2784
|
+
deviceId: report.deviceId,
|
|
2785
|
+
service: service.name,
|
|
2786
|
+
url: service.url,
|
|
2787
|
+
hosts: plan.ask.map((h) => h.host),
|
|
2788
|
+
attempt: service.attempt,
|
|
2789
|
+
appliesAt: offer.appliesAt,
|
|
2790
|
+
result: kept,
|
|
2791
|
+
},
|
|
2792
|
+
scopes: offer.scopes,
|
|
2793
|
+
});
|
|
2794
|
+
return { kind: "wait", wait: approvalWait(ask), content: kept.content };
|
|
2795
|
+
}
|
|
2796
|
+
/** The call's live loopback port grant (null: none, ended, or no grants service). */
|
|
2797
|
+
async loopbackGrantOf(runId, callId) {
|
|
2798
|
+
return (await this.loopbackGrants?.forCall(runId, callId)) ?? null;
|
|
2799
|
+
}
|
|
2800
|
+
/**
|
|
2801
|
+
* The attempt that recorded a ready-grant loopback rerun for this call, or null when none did.
|
|
2802
|
+
*/
|
|
2803
|
+
async readyLoopbackRerunOf(conversationId, runId, callId) {
|
|
2804
|
+
const ev = await this.deps.eventLog.findByIdem(conversationId, loopbackReadyRerunIdemKey(runId, callId));
|
|
2805
|
+
return ev?.type === "permission_reviewed"
|
|
2806
|
+
? (ev.payload.loopback?.readyRerunAttempt ?? null)
|
|
2807
|
+
: null;
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
* A device service's loopback refusal (browser loopback port grants): the port of the person's
|
|
2811
|
+
* own device a service of an extension declaring `permissions.deviceAccess.loopbackPorts` was
|
|
2812
|
+
* refused. Refused by the device's ceilings, its provider or an unattended run → a note
|
|
2813
|
+
* (`write`). A live grant the service had not applied yet → the call runs again, once. Else the
|
|
2814
|
+
* conversation's permission profile decides (`approverForCrossing`, crossing `loopback-port`):
|
|
2815
|
+
* Full access grants it, the review model reviews it (allow grants, deny is a note, an unsure
|
|
2816
|
+
* answer asks), the person is asked (the run waits, the result kept in the ask). A grant is
|
|
2817
|
+
* written with its `permission_reviewed`, the call's display events and its `tool.called` in one
|
|
2818
|
+
* transaction, naming this attempt: the call then runs again in the next one (`rerun`), also
|
|
2819
|
+
* after a crash. `none`: not decidable here (no device of the call's account, a hand-built
|
|
2820
|
+
* pipeline, no facts): the host stays an address host with its note.
|
|
2821
|
+
*/
|
|
2822
|
+
async loopbackBlocked(ctx, call, tool, input, toolKey, report, attempt, kept, rerunning, pre, callAudit) {
|
|
2823
|
+
const grants = this.loopbackGrants;
|
|
2824
|
+
const sandboxFacts = this.permissionFacts;
|
|
2825
|
+
const authority = this.permissionAuthority;
|
|
2826
|
+
const devices = this.deps.devices;
|
|
2827
|
+
if (!grants || !sandboxFacts || !authority || !devices)
|
|
2828
|
+
return { kind: "none" };
|
|
2829
|
+
// only the device the call works in, and only its owner's own run
|
|
2830
|
+
const device = await devices.reviewFacts(ctx.orgId, ctx.parent?.rootConversationId ?? ctx.conversationId, ctx.conversationId);
|
|
2831
|
+
if (!device || device.deviceId !== report.deviceId || device.ownerAccountId !== ctx.accountId)
|
|
2832
|
+
return { kind: "none" };
|
|
2833
|
+
const use = {
|
|
2834
|
+
orgId: ctx.orgId,
|
|
2835
|
+
deviceId: device.deviceId,
|
|
2836
|
+
holderConversationId: ctx.conversationId,
|
|
2837
|
+
actor: { accountId: ctx.accountId, conversationId: ctx.conversationId, runId: ctx.runId },
|
|
2838
|
+
};
|
|
2839
|
+
let facts;
|
|
2840
|
+
try {
|
|
2841
|
+
facts = await authority.previewCall(use, { runId: ctx.runId, callId: call.id }, ctx.signal);
|
|
2842
|
+
}
|
|
2843
|
+
catch (err) {
|
|
2844
|
+
ctx.signal.throwIfAborted();
|
|
2845
|
+
this.deps.log.warn("cannot read the facts of a loopback refusal; noted as an address", {
|
|
2846
|
+
runId: ctx.runId,
|
|
2847
|
+
callId: call.id,
|
|
2848
|
+
err,
|
|
2849
|
+
});
|
|
2850
|
+
return { kind: "none" };
|
|
2851
|
+
}
|
|
2852
|
+
const { serviceId, host, port } = report.loopback;
|
|
2853
|
+
const hp = host.includes(":") ? `[${host}]:${port}` : `${host}:${port}`;
|
|
2854
|
+
// the effective profile's facts: an unattended run's escalation refusal names it
|
|
2855
|
+
const sandbox = await sandboxFacts.deviceSandboxFacts(ctx.orgId, device.deviceId);
|
|
2856
|
+
const plan = planLoopbackAsk({ host, port }, loopbackRefusal(sandbox.box, sandbox.support, facts.escalationRefusal), facts.escalationRefusal == null);
|
|
2857
|
+
if (plan.kind === "none")
|
|
2858
|
+
return { kind: "none" };
|
|
2859
|
+
// refused before the live grants are read: an unattended run is never approved by a grant
|
|
2860
|
+
// the person made earlier in the tree (no grant, no rerun). The device's carve-out stays the
|
|
2861
|
+
// union of the service's live grants; refusing an unattended tab is the browser's check
|
|
2862
|
+
if (plan.kind === "refused")
|
|
2863
|
+
return { kind: "write", notes: [plan.note] };
|
|
2864
|
+
const key = {
|
|
2865
|
+
orgId: ctx.orgId,
|
|
2866
|
+
deviceId: device.deviceId,
|
|
2867
|
+
serviceId,
|
|
2868
|
+
rootConversationId: facts.rootConversationId,
|
|
2869
|
+
port,
|
|
2870
|
+
};
|
|
2871
|
+
const live = await grants.liveForRoot(ctx.orgId, device.deviceId, serviceId, facts.rootConversationId);
|
|
2872
|
+
const binding = {
|
|
2873
|
+
orgId: facts.orgId,
|
|
2874
|
+
rootConversationId: facts.rootConversationId,
|
|
2875
|
+
conversationId: facts.conversationId,
|
|
2876
|
+
deviceId: facts.deviceId,
|
|
2877
|
+
accountId: facts.accountId,
|
|
2878
|
+
runId: facts.runId,
|
|
2879
|
+
callId: facts.callId,
|
|
2880
|
+
toolKey: tool.key,
|
|
2881
|
+
specHash: tool.specHash,
|
|
2882
|
+
callInputHash: permissionScopeHash(call.input),
|
|
2883
|
+
resolvedInputHash: permissionScopeHash(input),
|
|
2884
|
+
profile: facts.profile,
|
|
2885
|
+
profileRevision: facts.profileRevision,
|
|
2886
|
+
scopeRevision: facts.scopeRevision,
|
|
2887
|
+
authorityRevision: facts.authorityRevision,
|
|
2888
|
+
};
|
|
2889
|
+
if (live.some((g) => g.port === port)) {
|
|
2890
|
+
// granted already (the panel, an earlier call): the service had not applied it yet, so the
|
|
2891
|
+
// call runs again once; refused again (or granted to this call), its result stands
|
|
2892
|
+
if (rerunning || (await grants.forCall(ctx.runId, call.id)) !== null)
|
|
2893
|
+
return { kind: "write", notes: [loopbackNotAppliedNote(port)] };
|
|
2894
|
+
const readyCandidate = {
|
|
2895
|
+
binding,
|
|
2896
|
+
permissionScope: { writeDirectories: [], hosts: [] },
|
|
2897
|
+
scopeKind: "loopback-port",
|
|
2898
|
+
loopback: { service: serviceId, port, readyRerunAttempt: attempt },
|
|
2899
|
+
};
|
|
2900
|
+
const readyEvent = {
|
|
2901
|
+
type: "permission_reviewed",
|
|
2902
|
+
runId: ctx.runId,
|
|
2903
|
+
idemKey: loopbackReadyRerunIdemKey(ctx.runId, call.id),
|
|
2904
|
+
payload: {
|
|
2905
|
+
...readyCandidate,
|
|
2906
|
+
candidateHash: permissionScopeHash(readyCandidate),
|
|
2907
|
+
outcome: "allow",
|
|
2908
|
+
reason: "Loopback port already granted for this conversation; retrying after the device applies it.",
|
|
2909
|
+
decisionSource: "rule",
|
|
2910
|
+
crossing: "loopback-port",
|
|
2911
|
+
},
|
|
2912
|
+
};
|
|
2913
|
+
await this.writeResultIn(ctx, call.id, toolKey, kept, [readyEvent, ...pre], callAudit, []);
|
|
2914
|
+
return { kind: "rerun", notes: [] };
|
|
2915
|
+
}
|
|
2916
|
+
// a call that ran again after its grant is not decided again (the port was closed meanwhile)
|
|
2917
|
+
if (rerunning)
|
|
2918
|
+
return { kind: "write", notes: [serviceAskedNote([hp])] };
|
|
2919
|
+
const reviewed = (outcome, reason, decisionSource) => {
|
|
2920
|
+
const candidate = {
|
|
2921
|
+
binding,
|
|
2922
|
+
permissionScope: { writeDirectories: [], hosts: [] },
|
|
2923
|
+
scopeKind: "loopback-port",
|
|
2924
|
+
loopback: { service: serviceId, port },
|
|
2925
|
+
};
|
|
2926
|
+
return {
|
|
2927
|
+
type: "permission_reviewed",
|
|
2928
|
+
runId: ctx.runId,
|
|
2929
|
+
idemKey: `permission_reviewed:loopback:${ctx.runId}:${call.id}:${attempt}`,
|
|
2930
|
+
payload: {
|
|
2931
|
+
...candidate,
|
|
2932
|
+
candidateHash: permissionScopeHash(candidate),
|
|
2933
|
+
outcome,
|
|
2934
|
+
reason,
|
|
2935
|
+
decisionSource,
|
|
2936
|
+
crossing: "loopback-port",
|
|
2937
|
+
},
|
|
2938
|
+
};
|
|
2939
|
+
};
|
|
2940
|
+
const grant = async (source, reason, decisionSource = source) => {
|
|
2941
|
+
try {
|
|
2942
|
+
await this.grantLoopbackIn(ctx, call.id, toolKey, kept, key, { runId: ctx.runId, callId: call.id, attempt }, source, [reviewed("allow", reason, decisionSource), ...pre], callAudit);
|
|
2943
|
+
}
|
|
2944
|
+
catch (e) {
|
|
2945
|
+
// the service holds the most ports it may: the note says so, nothing was granted
|
|
2946
|
+
if (e instanceof LoopbackLimitError)
|
|
2947
|
+
return {
|
|
2948
|
+
kind: "write",
|
|
2949
|
+
notes: [`[network] ${hp} is a local port on the device. ${e.message}`],
|
|
2950
|
+
};
|
|
2951
|
+
throw e;
|
|
2952
|
+
}
|
|
2953
|
+
return { kind: "rerun", notes: [loopbackGrantedNote(port)] };
|
|
2954
|
+
};
|
|
2955
|
+
const approver = approverForCrossing({
|
|
2956
|
+
profile: facts.profile,
|
|
2957
|
+
crossing: "loopback-port",
|
|
2958
|
+
subAgent: ctx.parent !== undefined,
|
|
2959
|
+
});
|
|
2960
|
+
if (approver === "none")
|
|
2961
|
+
return grant("full-access", LOOPBACK_FULL_ACCESS_REASON);
|
|
2962
|
+
if (approver === "review-model" && this.deps.review?.reviewLoopbackPort) {
|
|
2963
|
+
const verdict = await this.deps.review.reviewLoopbackPort({
|
|
2964
|
+
orgId: ctx.orgId,
|
|
2965
|
+
conversationId: ctx.conversationId,
|
|
2966
|
+
runId: ctx.runId,
|
|
2967
|
+
step: ctx.step,
|
|
2968
|
+
callId: call.id,
|
|
2969
|
+
signal: ctx.signal,
|
|
2970
|
+
accountId: ctx.accountId,
|
|
2971
|
+
agentId: ctx.agentId,
|
|
2972
|
+
agentVersion: ctx.agentVersion,
|
|
2973
|
+
conversationKind: ctx.conversationKind,
|
|
2974
|
+
...reviewParentOf(ctx.parent),
|
|
2975
|
+
profile: facts.profile,
|
|
2976
|
+
attended: !facts.unattended,
|
|
2977
|
+
refusal: null,
|
|
2978
|
+
service: serviceId,
|
|
2979
|
+
port,
|
|
2980
|
+
url: report.url,
|
|
2981
|
+
database: plan.database,
|
|
2982
|
+
});
|
|
2983
|
+
const source = verdict.by === "classifier" ? "review-model" : "rule";
|
|
2984
|
+
// the review path's grant; its record names who allowed it (a rule allows only under Full
|
|
2985
|
+
// access, decided above, so a rule's allow here is not expected but recorded as one)
|
|
2986
|
+
if (verdict.decision === "allow")
|
|
2987
|
+
return grant("review-model", verdict.reason, source);
|
|
2988
|
+
if (verdict.decision === "deny") {
|
|
2989
|
+
await this.recordLoopbackReview(ctx, reviewed("deny", verdict.reason, source));
|
|
2990
|
+
return { kind: "write", notes: [loopbackReviewDeniedNote(port, verdict.reason)] };
|
|
2991
|
+
}
|
|
2992
|
+
await this.recordLoopbackReview(ctx, reviewed("ask", verdict.reason, source));
|
|
2993
|
+
}
|
|
2994
|
+
// the person: the device's owner, within the run's network asks; one ask per call (a call
|
|
2995
|
+
// that ran again after its network ask is not asked again)
|
|
2996
|
+
if ((await this.deps.approvals.networkForCall(ctx.runId, call.id)) !== null)
|
|
2997
|
+
return { kind: "write", notes: [serviceAskedNote([hp])] };
|
|
2998
|
+
const run = await this.deps.network?.grants.runState(ctx.runId, device.deviceId);
|
|
2999
|
+
if (run?.pending === true)
|
|
3000
|
+
return { kind: "write", notes: [otherAskPendingNote([hp])] };
|
|
3001
|
+
if ((run?.asks ?? 0) >= MAX_NETWORK_ASKS_PER_RUN)
|
|
3002
|
+
return { kind: "write", notes: [tooManyNote([hp])] };
|
|
3003
|
+
// plan-only pass for other refused hosts reported alongside the loopback port, so their notes
|
|
3004
|
+
// and `network_blocked` event are kept when the loopback ask settles
|
|
3005
|
+
let otherEvent = null;
|
|
3006
|
+
let otherNotes = [];
|
|
3007
|
+
if (report.otherHosts.length > 0) {
|
|
3008
|
+
const other = await this.networkBlocked(ctx, call.id, toolKey, input, {
|
|
3009
|
+
deviceId: report.deviceId,
|
|
3010
|
+
blocked: report.otherHosts.map(({ host, layer }) => ({ host, port: 443, layer })),
|
|
3011
|
+
}, pre, callAudit, kept, undefined, undefined, {
|
|
3012
|
+
name: tool.source.kind === "plugin" ? tool.source.plugin : tool.key,
|
|
3013
|
+
attempt,
|
|
3014
|
+
url: report.url,
|
|
3015
|
+
}, true);
|
|
3016
|
+
if (other.kind === "write") {
|
|
3017
|
+
otherEvent = other.event;
|
|
3018
|
+
otherNotes = other.notes;
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
const keptWithOther = otherNotes.length === 0
|
|
3022
|
+
? kept
|
|
3023
|
+
: { ...kept, content: withNetworkNotes(kept.content, otherNotes) };
|
|
3024
|
+
const { content, outputId } = await this.keptContent(ctx, call.id, keptWithOther);
|
|
3025
|
+
const { text: _text, denialHint: _hint, ...rest } = keptWithOther;
|
|
3026
|
+
const result = {
|
|
3027
|
+
...rest,
|
|
3028
|
+
content: clipKept(content),
|
|
3029
|
+
...(outputId !== undefined && { outputId }),
|
|
3030
|
+
};
|
|
3031
|
+
// the service's call ran: its display-only events and tool.called now, the result once the
|
|
3032
|
+
// ask settles
|
|
3033
|
+
const written = await this.writeResultIn(ctx, call.id, toolKey, keptWithOther, otherEvent !== null ? [...pre, otherEvent] : [...pre], callAudit, []);
|
|
3034
|
+
if (written.length > 0)
|
|
3035
|
+
await this.deps.eventLog.notify(ctx.conversationId, Math.max(...written.map((e) => e.seq)));
|
|
3036
|
+
const ask = await this.deps.approvals.requestLoopback({
|
|
3037
|
+
orgId: ctx.orgId,
|
|
3038
|
+
conversationId: ctx.conversationId,
|
|
3039
|
+
runId: ctx.runId,
|
|
3040
|
+
step: ctx.step,
|
|
3041
|
+
callId: call.id,
|
|
3042
|
+
requestedFor: device.ownerAccountId,
|
|
3043
|
+
toolKey,
|
|
3044
|
+
detail: {
|
|
3045
|
+
kind: "loopback",
|
|
3046
|
+
deviceId: device.deviceId,
|
|
3047
|
+
service: serviceId,
|
|
3048
|
+
url: report.url,
|
|
3049
|
+
port,
|
|
3050
|
+
database: plan.database,
|
|
3051
|
+
attempt,
|
|
3052
|
+
result,
|
|
3053
|
+
},
|
|
3054
|
+
});
|
|
3055
|
+
return { kind: "wait", wait: approvalWait(ask), content: loopbackPendingNote(host, port) };
|
|
3056
|
+
}
|
|
3057
|
+
async siteRetryAllowed(ctx, callId, tool, input, site) {
|
|
3058
|
+
if (tool.source.kind !== "plugin" ||
|
|
3059
|
+
ctx.ownerAccountId !== ctx.accountId ||
|
|
3060
|
+
unattendedRules(ctx.unattended))
|
|
3061
|
+
return false;
|
|
3062
|
+
const plugin = tool.source.plugin;
|
|
3063
|
+
const instance = this.extensions?.current(plugin);
|
|
3064
|
+
if (instance?.manifest.permissions?.deviceAccess?.siteAccess !== true ||
|
|
3065
|
+
!(await siteAccessInstallActive(this.deps.db, plugin, instance.sha256)))
|
|
3066
|
+
return false;
|
|
3067
|
+
const device = await this.deps.devices?.reviewFacts(ctx.orgId, ctx.parent?.rootConversationId ?? ctx.conversationId, ctx.conversationId);
|
|
3068
|
+
if (device?.deviceId !== site.deviceId || device.ownerAccountId !== ctx.accountId)
|
|
3069
|
+
return false;
|
|
3070
|
+
const facts = await this.siteReviewFacts(ctx, callId, site.deviceId);
|
|
3071
|
+
if (facts === null || facts.unattended)
|
|
3072
|
+
return false;
|
|
3073
|
+
const binding = site.binding;
|
|
3074
|
+
if (binding === undefined)
|
|
3075
|
+
return site.approval.source === "human";
|
|
3076
|
+
return (binding.resolvedInputHash === permissionScopeHash(input) &&
|
|
3077
|
+
facts.rootConversationId === binding.rootConversationId &&
|
|
3078
|
+
facts.profile === binding.profile &&
|
|
3079
|
+
facts.profileRevision === binding.profileRevision &&
|
|
3080
|
+
facts.scopeRevision === binding.scopeRevision &&
|
|
3081
|
+
facts.authorityRevision === binding.authorityRevision);
|
|
3082
|
+
}
|
|
3083
|
+
async siteReviewFacts(ctx, callId, deviceId) {
|
|
3084
|
+
const authority = this.permissionAuthority;
|
|
3085
|
+
if (!authority)
|
|
3086
|
+
return null;
|
|
3087
|
+
return authority
|
|
3088
|
+
.previewCall({
|
|
3089
|
+
orgId: ctx.orgId,
|
|
3090
|
+
deviceId,
|
|
3091
|
+
holderConversationId: ctx.conversationId,
|
|
3092
|
+
actor: { accountId: ctx.accountId, conversationId: ctx.conversationId, runId: ctx.runId },
|
|
3093
|
+
}, { runId: ctx.runId, callId }, ctx.signal, "site-access")
|
|
3094
|
+
.catch((err) => {
|
|
3095
|
+
ctx.signal.throwIfAborted();
|
|
3096
|
+
this.deps.log.warn("Site access facts unavailable", { runId: ctx.runId, callId, err });
|
|
3097
|
+
return null;
|
|
3098
|
+
});
|
|
3099
|
+
}
|
|
3100
|
+
async siteRerunOf(ctx, callId) {
|
|
3101
|
+
const event = await this.deps.eventLog.findByIdem(ctx.conversationId, siteReviewIdemKey(ctx.runId, callId));
|
|
3102
|
+
if (event?.type !== "permission_reviewed")
|
|
3103
|
+
return null;
|
|
3104
|
+
const { site, outcome, decisionSource, binding } = event.payload;
|
|
3105
|
+
if (outcome !== "allow" || site === undefined || decisionSource === "rule")
|
|
3106
|
+
return null;
|
|
3107
|
+
return {
|
|
3108
|
+
attempt: site.attempt,
|
|
3109
|
+
toolSpecHash: binding.specHash,
|
|
3110
|
+
callInputHash: binding.callInputHash,
|
|
3111
|
+
deviceId: binding.deviceId,
|
|
3112
|
+
binding,
|
|
3113
|
+
approval: {
|
|
3114
|
+
action: site.action,
|
|
3115
|
+
origin: site.origin,
|
|
3116
|
+
detailSha256: site.detailSha256,
|
|
3117
|
+
source: decisionSource,
|
|
3118
|
+
},
|
|
3119
|
+
};
|
|
3120
|
+
}
|
|
3121
|
+
async handleSiteAccess(ctx, call, tool, input, report, attempt, kept, pre, callAudit, rerunning) {
|
|
3122
|
+
const write = (note) => ({ kind: "write", note });
|
|
3123
|
+
if (rerunning !== undefined ||
|
|
3124
|
+
(await this.deps.eventLog.findByIdem(ctx.conversationId, siteReviewIdemKey(ctx.runId, call.id))))
|
|
3125
|
+
return write("The approved site action no longer matches the active page. It did not run. Call the tool again to review the current page.");
|
|
3126
|
+
if (ctx.ownerAccountId !== ctx.accountId ||
|
|
3127
|
+
tool.source.kind !== "plugin" ||
|
|
3128
|
+
tool.source.plugin !== report.extension ||
|
|
3129
|
+
!this.siteGrants) {
|
|
3130
|
+
return write("Site access is available only to the conversation's owner on their device.");
|
|
3131
|
+
}
|
|
3132
|
+
const facts = await this.siteReviewFacts(ctx, call.id, report.deviceId);
|
|
3133
|
+
if (facts === null)
|
|
3134
|
+
return write("Site access could not be verified. It did not run.");
|
|
3135
|
+
if (facts.unattended) {
|
|
3136
|
+
return write("This site action needs the user's approval, which an unattended run cannot get. It did not run. Use browser_snapshot or browser_network to read the page.");
|
|
3137
|
+
}
|
|
3138
|
+
const verdict = await this.deps.review?.reviewSiteAccess?.({
|
|
3139
|
+
orgId: ctx.orgId,
|
|
3140
|
+
conversationId: ctx.conversationId,
|
|
3141
|
+
runId: ctx.runId,
|
|
3142
|
+
step: ctx.step,
|
|
3143
|
+
callId: call.id,
|
|
3144
|
+
signal: ctx.signal,
|
|
3145
|
+
accountId: ctx.accountId,
|
|
3146
|
+
agentId: ctx.agentId,
|
|
3147
|
+
agentVersion: ctx.agentVersion,
|
|
3148
|
+
conversationKind: ctx.conversationKind,
|
|
3149
|
+
...reviewParentOf(ctx.parent),
|
|
3150
|
+
profile: facts.profile,
|
|
3151
|
+
attended: true,
|
|
3152
|
+
refusal: null,
|
|
3153
|
+
service: report.serviceId,
|
|
3154
|
+
origin: report.origin,
|
|
3155
|
+
action: report.action,
|
|
3156
|
+
detail: report.detail,
|
|
3157
|
+
});
|
|
3158
|
+
if (!verdict)
|
|
3159
|
+
return write("Site approval is unavailable. The action did not run.");
|
|
3160
|
+
const detailSha256 = siteAccessDetailHash(report.detail);
|
|
3161
|
+
const source = verdict.approver === "none"
|
|
3162
|
+
? "full-access"
|
|
3163
|
+
: verdict.by === "classifier"
|
|
3164
|
+
? "review-model"
|
|
3165
|
+
: "rule";
|
|
3166
|
+
const candidate = {
|
|
3167
|
+
binding: {
|
|
3168
|
+
orgId: facts.orgId,
|
|
3169
|
+
rootConversationId: facts.rootConversationId,
|
|
3170
|
+
conversationId: facts.conversationId,
|
|
3171
|
+
deviceId: facts.deviceId,
|
|
3172
|
+
accountId: facts.accountId,
|
|
3173
|
+
runId: facts.runId,
|
|
3174
|
+
callId: facts.callId,
|
|
3175
|
+
toolKey: tool.key,
|
|
3176
|
+
specHash: tool.specHash,
|
|
3177
|
+
callInputHash: permissionScopeHash(call.input),
|
|
3178
|
+
resolvedInputHash: permissionScopeHash(input),
|
|
3179
|
+
profile: facts.profile,
|
|
3180
|
+
profileRevision: facts.profileRevision,
|
|
3181
|
+
scopeRevision: facts.scopeRevision,
|
|
3182
|
+
authorityRevision: facts.authorityRevision,
|
|
3183
|
+
},
|
|
3184
|
+
permissionScope: { writeDirectories: [], hosts: [] },
|
|
3185
|
+
scopeKind: "site-access",
|
|
3186
|
+
site: {
|
|
3187
|
+
service: report.serviceId,
|
|
3188
|
+
action: report.action,
|
|
3189
|
+
origin: report.origin,
|
|
3190
|
+
detailSha256,
|
|
3191
|
+
attempt,
|
|
3192
|
+
},
|
|
3193
|
+
};
|
|
3194
|
+
const review = {
|
|
3195
|
+
type: "permission_reviewed",
|
|
3196
|
+
runId: ctx.runId,
|
|
3197
|
+
idemKey: siteReviewIdemKey(ctx.runId, call.id),
|
|
3198
|
+
payload: {
|
|
3199
|
+
...candidate,
|
|
3200
|
+
candidateHash: permissionScopeHash(candidate),
|
|
3201
|
+
outcome: verdict.decision,
|
|
3202
|
+
reason: verdict.reason,
|
|
3203
|
+
decisionSource: source,
|
|
3204
|
+
crossing: "site-access",
|
|
3205
|
+
},
|
|
3206
|
+
};
|
|
3207
|
+
if (verdict.decision === "deny") {
|
|
3208
|
+
await this.recordLoopbackReview(ctx, review);
|
|
3209
|
+
return write(`The site action on ${report.origin} was denied. ${verdict.reason}`);
|
|
3210
|
+
}
|
|
3211
|
+
if (verdict.decision === "allow" && source !== "rule") {
|
|
3212
|
+
await this.writeResultIn(ctx, call.id, tool.key, kept, [review, ...pre], callAudit, [
|
|
3213
|
+
{
|
|
3214
|
+
orgId: ctx.orgId,
|
|
3215
|
+
actorAccountId: ctx.accountId,
|
|
3216
|
+
action: "device.site_access_decided",
|
|
3217
|
+
target: report.deviceId,
|
|
3218
|
+
detail: {
|
|
3219
|
+
action: report.action,
|
|
3220
|
+
origin: report.origin,
|
|
3221
|
+
detailSha256,
|
|
3222
|
+
source,
|
|
3223
|
+
outcome: "once",
|
|
3224
|
+
},
|
|
3225
|
+
},
|
|
3226
|
+
]);
|
|
3227
|
+
return {
|
|
3228
|
+
kind: "rerun",
|
|
3229
|
+
site: {
|
|
3230
|
+
attempt,
|
|
3231
|
+
toolSpecHash: tool.specHash,
|
|
3232
|
+
callInputHash: permissionScopeHash(call.input),
|
|
3233
|
+
deviceId: report.deviceId,
|
|
3234
|
+
binding: candidate.binding,
|
|
3235
|
+
approval: { action: report.action, origin: report.origin, detailSha256, source },
|
|
3236
|
+
},
|
|
3237
|
+
};
|
|
3238
|
+
}
|
|
3239
|
+
const prior = await this.deps.approvals.networkForCall(ctx.runId, call.id);
|
|
3240
|
+
const run = await this.deps.network?.grants.runState(ctx.runId, report.deviceId);
|
|
3241
|
+
if (prior !== null || run?.pending || (run?.asks ?? 0) >= MAX_NETWORK_ASKS_PER_RUN)
|
|
3242
|
+
return write("The action did not run. This call cannot request another approval.");
|
|
3243
|
+
const canRemember = verdict.approver === "person" &&
|
|
3244
|
+
ctx.parent === undefined &&
|
|
3245
|
+
(await this.siteGrants.canGrant({
|
|
3246
|
+
orgId: ctx.orgId,
|
|
3247
|
+
deviceId: report.deviceId,
|
|
3248
|
+
serviceId: report.serviceId,
|
|
3249
|
+
rootConversationId: facts.rootConversationId,
|
|
3250
|
+
origin: report.origin,
|
|
3251
|
+
action: report.action,
|
|
3252
|
+
}));
|
|
3253
|
+
const { content, outputId } = await this.keptContent(ctx, call.id, kept);
|
|
3254
|
+
const { text: _text, ...result } = kept;
|
|
3255
|
+
const ask = await this.deps.approvals.requestSiteAccess({
|
|
3256
|
+
orgId: ctx.orgId,
|
|
3257
|
+
conversationId: ctx.conversationId,
|
|
3258
|
+
runId: ctx.runId,
|
|
3259
|
+
step: ctx.step,
|
|
3260
|
+
callId: call.id,
|
|
3261
|
+
requestedFor: ctx.accountId,
|
|
3262
|
+
toolKey: tool.key,
|
|
3263
|
+
scopes: canRemember ? ["once", "session"] : ["once"],
|
|
3264
|
+
detail: {
|
|
3265
|
+
kind: "site",
|
|
3266
|
+
deviceId: report.deviceId,
|
|
3267
|
+
extension: report.extension,
|
|
3268
|
+
service: report.serviceId,
|
|
3269
|
+
rootConversationId: facts.rootConversationId,
|
|
3270
|
+
origin: report.origin,
|
|
3271
|
+
action: report.action,
|
|
3272
|
+
detail: report.detail,
|
|
3273
|
+
attempt,
|
|
3274
|
+
toolSpecHash: tool.specHash,
|
|
3275
|
+
callInputHash: permissionScopeHash(call.input),
|
|
3276
|
+
result: {
|
|
3277
|
+
...result,
|
|
3278
|
+
content: clipKept(content),
|
|
3279
|
+
...(outputId !== undefined && { outputId }),
|
|
3280
|
+
},
|
|
3281
|
+
},
|
|
3282
|
+
}, async () => {
|
|
3283
|
+
await this.writeResultIn(ctx, call.id, tool.key, kept, [review, ...pre], callAudit, []);
|
|
3284
|
+
});
|
|
3285
|
+
return { kind: "wait", wait: approvalWait(ask) };
|
|
3286
|
+
}
|
|
3287
|
+
/**
|
|
3288
|
+
* A loopback port grant to this call's attempt and what goes with it, in one transaction: the
|
|
3289
|
+
* grant first (it reads the root conversation `FOR SHARE`, before the conversation row the
|
|
3290
|
+
* appends lock), then `permission_reviewed`, the call's display-only events and its
|
|
3291
|
+
* `tool.called`. The call then runs again in the next attempt.
|
|
3292
|
+
*/
|
|
3293
|
+
async grantLoopbackIn(ctx, callId, toolKey, r, key, call, source, events, callAudit) {
|
|
3294
|
+
const grants = this.loopbackGrants;
|
|
3295
|
+
if (!grants)
|
|
3296
|
+
throw new Error("Loopback grants are unavailable");
|
|
3297
|
+
await grants.grantIn(key, { source, actorAccountId: null, call });
|
|
3298
|
+
await this.writeResultIn(ctx, callId, toolKey, r, events, callAudit, []);
|
|
3299
|
+
}
|
|
3300
|
+
/** A review model's loopback verdict that grants nothing (a deny, an unsure answer). */
|
|
3301
|
+
async recordLoopbackReview(ctx, event) {
|
|
3302
|
+
await this.deps.eventLog.appendIn(ctx.conversationId, [event]);
|
|
3303
|
+
}
|
|
3304
|
+
/**
|
|
3305
|
+
* A kept result's content within what an ask keeps: output under the spill threshold but over
|
|
3306
|
+
* {@link NETWORK_ASK_KEPT_MAX_BYTES} is archived after all.
|
|
3307
|
+
*/
|
|
3308
|
+
async keptContent(ctx, callId, result) {
|
|
3309
|
+
const { content, outputId } = result;
|
|
3310
|
+
if (Buffer.byteLength(content, "utf8") <= NETWORK_ASK_KEPT_MAX_BYTES || outputId !== undefined)
|
|
3311
|
+
return { content, outputId };
|
|
3312
|
+
const spilled = await spillIfLarge(result.text, { spillChars: 0, previewChars: this.config.get().tools.outputPreviewChars }, (c) => this.deps.outputs.save({
|
|
3313
|
+
orgId: ctx.orgId,
|
|
3314
|
+
conversationId: ctx.conversationId,
|
|
3315
|
+
callId,
|
|
3316
|
+
content: c,
|
|
3317
|
+
}));
|
|
3318
|
+
return { content: spilled.content, outputId: spilled.outputId };
|
|
3319
|
+
}
|
|
3320
|
+
/**
|
|
3321
|
+
* A device service's report (the call scope, browser use spec §7.1) on the device the call's
|
|
3322
|
+
* conversation works in (the root conversation's for a sub-agent, as the sandbox tools resolve
|
|
3323
|
+
* it): a report that names no device is about that one; a report naming another device id (the
|
|
3324
|
+
* conversation moved to another device during the call) is ignored with a warning, never asked
|
|
3325
|
+
* about.
|
|
3326
|
+
*/
|
|
3327
|
+
async ownDeviceReport(ctx, toolKey, blocked) {
|
|
3328
|
+
if (blocked === undefined)
|
|
3329
|
+
return undefined;
|
|
3330
|
+
const conv = await this.deps.db
|
|
3331
|
+
.selectFrom("conversations")
|
|
3332
|
+
.select("device_id")
|
|
3333
|
+
.where("id", "=", ctx.parent?.rootConversationId ?? ctx.conversationId)
|
|
3334
|
+
.where("org_id", "=", ctx.orgId)
|
|
3335
|
+
.executeTakeFirst();
|
|
3336
|
+
const deviceId = conv?.device_id ?? null;
|
|
3337
|
+
if (deviceId !== null && (blocked.deviceId === null || blocked.deviceId === deviceId))
|
|
3338
|
+
return { ...blocked, deviceId };
|
|
3339
|
+
this.deps.log.warn("ignored refused hosts reported for another device than the call's", {
|
|
3340
|
+
runId: ctx.runId,
|
|
3341
|
+
toolKey,
|
|
3342
|
+
deviceId: blocked.deviceId,
|
|
3343
|
+
});
|
|
3344
|
+
return undefined;
|
|
3345
|
+
}
|
|
3346
|
+
/** Appends a sub-agent's connect card to its root conversation ({@link rootSurfaceOf}). */
|
|
3347
|
+
async surfaceConnectInRoot(ctx, parent, callId, toolKey) {
|
|
3348
|
+
const target = await rootSurfaceOf(this.deps.db, ctx.conversationId, ctx.runId, parent);
|
|
3349
|
+
if (!target)
|
|
676
3350
|
return;
|
|
677
3351
|
await this.deps.eventLog.append(target.conversationId, [
|
|
678
3352
|
{
|
|
@@ -690,19 +3364,15 @@ let ToolPipeline = class ToolPipeline {
|
|
|
690
3364
|
]);
|
|
691
3365
|
}
|
|
692
3366
|
/**
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
*
|
|
3367
|
+
* How a call's result images are stored: a `read` copy bound to the calling conversation (a
|
|
3368
|
+
* sub-agent's own, never its root), owned by the run's trigger account; absent without the
|
|
3369
|
+
* attachments service.
|
|
696
3370
|
*/
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
const { tools, catalog } = e.payload.request;
|
|
703
|
-
return new Set([...(tools ?? []), ...(catalog ?? [])].map((t) => t.key));
|
|
704
|
-
}
|
|
705
|
-
return null;
|
|
3371
|
+
storeResultImage(ctx) {
|
|
3372
|
+
const attachments = this.resultImages;
|
|
3373
|
+
if (attachments === undefined)
|
|
3374
|
+
return undefined;
|
|
3375
|
+
return (file) => attachments.storeRead(ctx.orgId, ctx.conversationId, ctx.accountId || null, file);
|
|
706
3376
|
}
|
|
707
3377
|
/**
|
|
708
3378
|
* 发出本步调用的请求里带了完整定义的工具 key:本步最后一次尝试的 `model_call.request.tools`
|
|
@@ -710,7 +3380,9 @@ let ToolPipeline = class ToolPipeline {
|
|
|
710
3380
|
* 或找不到 model_call 时返回 null(不做加载检查)。已加载集合由此从日志得出,不放进程内存。
|
|
711
3381
|
*/
|
|
712
3382
|
async sentTools(ctx) {
|
|
713
|
-
|
|
3383
|
+
// attempts can reach MAX_STEP_MODEL_CALLS after reactive overflow fix-ups; the assistant_message
|
|
3384
|
+
// comes from the last attempt, so scan from the top
|
|
3385
|
+
for (let attempt = MAX_STEP_MODEL_CALLS; attempt >= 1; attempt--) {
|
|
714
3386
|
const e = await this.deps.eventLog.findByIdem(ctx.conversationId, modelCallIdemKey(ctx.runId, ctx.step, attempt));
|
|
715
3387
|
if (e?.type !== "model_call")
|
|
716
3388
|
continue;
|
|
@@ -719,13 +3391,82 @@ let ToolPipeline = class ToolPipeline {
|
|
|
719
3391
|
}
|
|
720
3392
|
return null;
|
|
721
3393
|
}
|
|
722
|
-
/**
|
|
3394
|
+
/**
|
|
3395
|
+
* The secure input of a call with person fields (R4): the latest request of the call, bound like
|
|
3396
|
+
* an approval to the definition and the raw input it was made for. None, or a submitted one made
|
|
3397
|
+
* for another definition or input, asks again; a pending one waits. A cancel, an expiry or a
|
|
3398
|
+
* stopped run ends the call with nothing run; a submitted one returns its id, which the tool
|
|
3399
|
+
* reads the sealed values by. The request goes to the run's person, who alone may submit it.
|
|
3400
|
+
*/
|
|
3401
|
+
async secureInput(ctx, call, tool, policyKey, personFields) {
|
|
3402
|
+
let si = await this.deps.approvals.secureInputForCall(ctx.runId, call.id);
|
|
3403
|
+
const current = si !== null &&
|
|
3404
|
+
si.specHash === tool.specHash &&
|
|
3405
|
+
canonicalJson(si.input) === canonicalJson(call.input ?? {});
|
|
3406
|
+
// only a submitted request is re-asked when stale: a pending one keeps waiting (the person
|
|
3407
|
+
// still sees and may submit it; the stale check then asks again), and a cancelled or expired
|
|
3408
|
+
// one ends the call, as a decided approval keeps governing its call
|
|
3409
|
+
if (si === null || (si.status === "approved" && !current)) {
|
|
3410
|
+
si = await this.deps.approvals.requestSecureInput({
|
|
3411
|
+
attempt: (await this.lastAttempt(ctx.runId, call.id)) + 1,
|
|
3412
|
+
orgId: ctx.orgId,
|
|
3413
|
+
conversationId: ctx.conversationId,
|
|
3414
|
+
runId: ctx.runId,
|
|
3415
|
+
step: ctx.step,
|
|
3416
|
+
callId: call.id,
|
|
3417
|
+
toolKey: policyKey,
|
|
3418
|
+
specHash: tool.specHash,
|
|
3419
|
+
connectorId: tool.source.kind === "connector" ? tool.source.connectorId : null,
|
|
3420
|
+
input: call.input,
|
|
3421
|
+
requestedFor: ctx.accountId,
|
|
3422
|
+
target: personFields.target,
|
|
3423
|
+
personFields: personFields.fields,
|
|
3424
|
+
});
|
|
3425
|
+
}
|
|
3426
|
+
switch (si.status) {
|
|
3427
|
+
case "pending":
|
|
3428
|
+
return { kind: "wait", wait: approvalWait(si) };
|
|
3429
|
+
case "approved":
|
|
3430
|
+
return { kind: "submitted", id: si.id };
|
|
3431
|
+
case "denied":
|
|
3432
|
+
return {
|
|
3433
|
+
kind: "refused",
|
|
3434
|
+
text: withLeakedOnCard(secureInputCancelledText(si.id), si.leakedFields),
|
|
3435
|
+
};
|
|
3436
|
+
case "expired":
|
|
3437
|
+
// the request's own wait (creation to expiry), not the current config
|
|
3438
|
+
return {
|
|
3439
|
+
kind: "refused",
|
|
3440
|
+
text: withLeakedOnCard(secureInputExpiredText(si.id, approvalHours(si)), si.leakedFields),
|
|
3441
|
+
};
|
|
3442
|
+
default:
|
|
3443
|
+
return {
|
|
3444
|
+
kind: "refused",
|
|
3445
|
+
text: withLeakedOnCard(APPROVAL_CANCELLED_TEXT, si.leakedFields),
|
|
3446
|
+
};
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
/** The highest attempt of any approval of the call, of every kind (0: none yet). */
|
|
3450
|
+
// org-filter: runId is the call context's own run (ctx.runId), a runtime uuid, never caller input
|
|
3451
|
+
async lastAttempt(runId, callId) {
|
|
3452
|
+
const row = await this.deps.db
|
|
3453
|
+
.selectFrom("approvals")
|
|
3454
|
+
.select(sql `max(attempt)`.as("attempt"))
|
|
3455
|
+
.where("run_id", "=", runId)
|
|
3456
|
+
.where("call_id", "=", callId)
|
|
3457
|
+
.executeTakeFirst();
|
|
3458
|
+
return Number(row?.attempt ?? 0);
|
|
3459
|
+
}
|
|
3460
|
+
/**
|
|
3461
|
+
* A decided tool approval other than approved → the model's text; still pending → null (wait).
|
|
3462
|
+
* A tool approval takes no values (a secure input does), so it never names leaked fields.
|
|
3463
|
+
*/
|
|
723
3464
|
refusalText(a) {
|
|
724
3465
|
switch (a.status) {
|
|
725
3466
|
case "denied":
|
|
726
3467
|
return approvalDeniedText(a.denyReason);
|
|
727
3468
|
case "expired":
|
|
728
|
-
//
|
|
3469
|
+
// Use the approval's own wait (creation to expiry), not the current config: it can be hot-reloaded
|
|
729
3470
|
return approvalExpiredText(approvalHours(a));
|
|
730
3471
|
case "cancelled":
|
|
731
3472
|
return APPROVAL_CANCELLED_TEXT;
|
|
@@ -734,8 +3475,9 @@ let ToolPipeline = class ToolPipeline {
|
|
|
734
3475
|
}
|
|
735
3476
|
}
|
|
736
3477
|
/**
|
|
737
|
-
*
|
|
738
|
-
*
|
|
3478
|
+
* A handler returned `input_required`: past the round limit, an invalid form
|
|
3479
|
+
* (`validateInputForm`) or an oversized state is an error text for the model; otherwise an
|
|
3480
|
+
* input request is made (writing `question_asked`) and its wait returned.
|
|
739
3481
|
*/
|
|
740
3482
|
async askInput(ctx, callId, toolKey, attempt, req) {
|
|
741
3483
|
if (attempt > MAX_INPUT_ROUNDS)
|
|
@@ -743,6 +3485,27 @@ let ToolPipeline = class ToolPipeline {
|
|
|
743
3485
|
const problems = validateInputForm(req.form);
|
|
744
3486
|
if (problems.length > 0)
|
|
745
3487
|
return invalidFormText(toolKey, problems);
|
|
3488
|
+
let watch;
|
|
3489
|
+
if (req.watch !== undefined) {
|
|
3490
|
+
const source = req.source;
|
|
3491
|
+
if (source === undefined || this.deps.registry.watcher(source) === undefined)
|
|
3492
|
+
return watchWithoutWatcherText(toolKey);
|
|
3493
|
+
const deadlineMs = req.watch?.deadlineMs;
|
|
3494
|
+
if (typeof deadlineMs !== "number" || !Number.isSafeInteger(deadlineMs) || deadlineMs <= 0)
|
|
3495
|
+
return invalidFormText(toolKey, [
|
|
3496
|
+
"watch.deadlineMs must be a positive integer number of milliseconds",
|
|
3497
|
+
]);
|
|
3498
|
+
watch = {
|
|
3499
|
+
deadlineMs,
|
|
3500
|
+
accountId: ctx.accountId,
|
|
3501
|
+
// fixed for the wait: each poll builds the watcher's context with them
|
|
3502
|
+
facts: {
|
|
3503
|
+
role: ctx.role,
|
|
3504
|
+
rootConversationId: ctx.parent?.rootConversationId ?? ctx.conversationId,
|
|
3505
|
+
unattended: ctx.unattended != null,
|
|
3506
|
+
},
|
|
3507
|
+
};
|
|
3508
|
+
}
|
|
746
3509
|
let stateJson;
|
|
747
3510
|
try {
|
|
748
3511
|
stateJson = JSON.stringify(req.state ?? null);
|
|
@@ -755,17 +3518,34 @@ let ToolPipeline = class ToolPipeline {
|
|
|
755
3518
|
if (Buffer.byteLength(stateJson, "utf8") > MAX_INPUT_STATE_BYTES) {
|
|
756
3519
|
return stateTooLargeText(toolKey);
|
|
757
3520
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
3521
|
+
let q;
|
|
3522
|
+
try {
|
|
3523
|
+
q = await this.deps.questions.ask({
|
|
3524
|
+
orgId: ctx.orgId,
|
|
3525
|
+
conversationId: ctx.conversationId,
|
|
3526
|
+
runId: ctx.runId,
|
|
3527
|
+
step: ctx.step,
|
|
3528
|
+
callId,
|
|
3529
|
+
attempt,
|
|
3530
|
+
toolKey,
|
|
3531
|
+
form: req.form,
|
|
3532
|
+
state: JSON.parse(stateJson),
|
|
3533
|
+
...(req.open !== undefined && { open: req.open }),
|
|
3534
|
+
// kept for the call's result, which a later round writes
|
|
3535
|
+
...((req.review !== undefined || req.blocked !== undefined) && {
|
|
3536
|
+
carried: {
|
|
3537
|
+
...(req.review !== undefined && { review: req.review }),
|
|
3538
|
+
...(req.blocked !== undefined && { blocked: req.blocked }),
|
|
3539
|
+
},
|
|
3540
|
+
}),
|
|
3541
|
+
...(watch !== undefined && { watch }),
|
|
3542
|
+
});
|
|
3543
|
+
}
|
|
3544
|
+
catch (e) {
|
|
3545
|
+
if (e instanceof TooManyWatchedWaitsError)
|
|
3546
|
+
return TOO_MANY_WATCHED_WAITS_TEXT;
|
|
3547
|
+
throw e;
|
|
3548
|
+
}
|
|
769
3549
|
return inputWait(q);
|
|
770
3550
|
}
|
|
771
3551
|
/**
|
|
@@ -773,28 +3553,71 @@ let ToolPipeline = class ToolPipeline {
|
|
|
773
3553
|
* 带 `tools.timeoutMs` 超时与 run 的中止信号(合并后传给处理函数 / 连接器,不响应信号的也按时结束)。
|
|
774
3554
|
* 熔断只作用于连接器工具(键为组织 × 连接器)。
|
|
775
3555
|
*/
|
|
776
|
-
async execute(tool, input, ctx, callId, resume, stepTools
|
|
3556
|
+
async execute(tool, input, ctx, callId, resume, stepTools, reviewed,
|
|
3557
|
+
/** The approved approval of this call, matching its definition and input (builtins only). */
|
|
3558
|
+
approvalId,
|
|
3559
|
+
/** The automatic decision the call runs under instead of an approval (builtins only, R2). */
|
|
3560
|
+
decision,
|
|
3561
|
+
/** The submitted secure input request of this call (builtins only, R4). */
|
|
3562
|
+
secureInputId, siteAccess) {
|
|
3563
|
+
const reviewedWorkingRoot = reviewed?.workingRoot;
|
|
3564
|
+
const reviewedAgainstRoot = reviewed?.against;
|
|
777
3565
|
if (tool.source.kind === "connector") {
|
|
778
3566
|
return this.executeConnector(tool, tool.source, input, ctx, resume);
|
|
779
3567
|
}
|
|
780
3568
|
const handler = this.deps.registry.handler(tool.source);
|
|
781
3569
|
if (!handler)
|
|
782
3570
|
return { kind: "error", message: `Tool ${tool.key} is no longer available.` };
|
|
783
|
-
|
|
3571
|
+
if (siteAccess !== undefined &&
|
|
3572
|
+
(tool.source.kind !== "plugin" ||
|
|
3573
|
+
this.extensions?.current(tool.source.plugin)?.manifest.permissions?.deviceAccess
|
|
3574
|
+
?.siteAccess !== true)) {
|
|
3575
|
+
return {
|
|
3576
|
+
kind: "error",
|
|
3577
|
+
message: "This site approval is no longer valid. The action did not run.",
|
|
3578
|
+
};
|
|
3579
|
+
}
|
|
3580
|
+
// an extension handler gets only the SDK ToolCallContext; a builtin also gets the step's resolved
|
|
3581
|
+
// tools (ToolSearch)
|
|
3582
|
+
// the tree root the person looks at; every sub-agent run carries it from its start
|
|
3583
|
+
const rootConversationId = ctx.parent?.rootConversationId ?? ctx.conversationId;
|
|
784
3584
|
const base = {
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
3585
|
+
...extensionCallContext({
|
|
3586
|
+
orgId: ctx.orgId,
|
|
3587
|
+
accountId: ctx.accountId,
|
|
3588
|
+
agentId: ctx.agentId,
|
|
3589
|
+
conversationId: ctx.conversationId,
|
|
3590
|
+
rootConversationId,
|
|
3591
|
+
runId: ctx.runId,
|
|
3592
|
+
callId,
|
|
3593
|
+
source: ctx.source,
|
|
3594
|
+
ownerAccountId: ctx.ownerAccountId,
|
|
3595
|
+
role: ctx.role,
|
|
3596
|
+
}),
|
|
790
3597
|
...(resume !== undefined && { resume }),
|
|
3598
|
+
...(siteAccess !== undefined && { siteAccess }),
|
|
791
3599
|
...(tool.source.kind === "builtin" && stepTools !== undefined && { tools: stepTools }),
|
|
792
|
-
...(tool.source.kind === "builtin" && {
|
|
3600
|
+
...(tool.source.kind === "builtin" && {
|
|
3601
|
+
runId: ctx.runId,
|
|
3602
|
+
executionClaim: currentExecutionClaim(),
|
|
3603
|
+
}),
|
|
793
3604
|
...(tool.source.kind === "builtin" &&
|
|
794
3605
|
ctx.deadline !== undefined && { runDeadline: ctx.deadline }),
|
|
795
|
-
|
|
3606
|
+
...(tool.source.kind === "builtin" && approvalId !== undefined && { approvalId }),
|
|
3607
|
+
...(tool.source.kind === "builtin" && decision !== undefined && { decision }),
|
|
3608
|
+
...(tool.source.kind === "builtin" && secureInputId !== undefined && { secureInputId }),
|
|
3609
|
+
// a reviewed call runs in the working root its review judged (project root spec §4.3)
|
|
3610
|
+
...(tool.source.kind === "builtin" &&
|
|
3611
|
+
reviewedWorkingRoot !== undefined && { reviewedWorkingRoot }),
|
|
3612
|
+
// and the root it was judged against, workspace included (B-18, the managed route)
|
|
3613
|
+
...(tool.source.kind === "builtin" &&
|
|
3614
|
+
reviewedAgainstRoot !== undefined && { reviewedAgainstRoot }),
|
|
3615
|
+
...(tool.source.kind === "builtin" &&
|
|
3616
|
+
reviewed?.escalation !== undefined && { sandboxEscalation: reviewed.escalation }),
|
|
796
3617
|
...(tool.source.kind === "builtin" &&
|
|
797
|
-
|
|
3618
|
+
reviewed?.escalationRefusal !== undefined && {
|
|
3619
|
+
sandboxEscalationRefusal: reviewed.escalationRefusal,
|
|
3620
|
+
}),
|
|
798
3621
|
...(tool.source.kind === "builtin" &&
|
|
799
3622
|
ctx.parent !== undefined && { parentRunId: ctx.parent.runId }),
|
|
800
3623
|
...(tool.source.kind === "builtin" &&
|
|
@@ -814,38 +3637,84 @@ let ToolPipeline = class ToolPipeline {
|
|
|
814
3637
|
}),
|
|
815
3638
|
};
|
|
816
3639
|
// 内置工具可按输入给自己的时限(沙箱 bash 按命令超时加余量);缺省 tools.timeoutMs
|
|
817
|
-
const
|
|
3640
|
+
const toolsCfg = this.config.get().tools;
|
|
3641
|
+
const ownMs = tool.timeoutMs?.(input);
|
|
3642
|
+
// an extension tool's declared limit never exceeds the deployment's ceiling
|
|
3643
|
+
const timeoutMs = ownMs === undefined
|
|
3644
|
+
? toolsCfg.timeoutMs
|
|
3645
|
+
: tool.source.kind === "plugin"
|
|
3646
|
+
? Math.min(ownMs, toolsCfg.maxTimeoutMs)
|
|
3647
|
+
: ownMs;
|
|
3648
|
+
let scope;
|
|
818
3649
|
try {
|
|
819
3650
|
// a plugin tool runs with the extension's effective config for the org, never without it
|
|
820
3651
|
// (layering spec A §6): one read per call, cached by EffectiveConfigs
|
|
821
3652
|
let config = {};
|
|
822
3653
|
if (tool.source.kind === "plugin") {
|
|
823
|
-
//
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
return { kind: "error", message: unavailableText(tool.key, NEEDS_CONFIG_REASON) };
|
|
833
|
-
}
|
|
834
|
-
config = { config: effective.config };
|
|
3654
|
+
// the step resolved its tools with the org's enablement; the rest is checked per call
|
|
3655
|
+
const gate = await extensionCallGate(this.deps, ctx.orgId, tool.key, tool.source, {
|
|
3656
|
+
...(siteAccess !== undefined && {
|
|
3657
|
+
checkEnabled: (orgId, plugin) => isExtensionEnabled(this.deps.db, orgId, plugin),
|
|
3658
|
+
}),
|
|
3659
|
+
});
|
|
3660
|
+
if (!gate.ok)
|
|
3661
|
+
return { kind: "error", message: gate.message };
|
|
3662
|
+
config = { config: gate.config };
|
|
835
3663
|
}
|
|
836
|
-
const r = await this.bounded(ctx.signal, (signal) =>
|
|
3664
|
+
const r = await this.bounded(ctx.signal, async (signal) => {
|
|
3665
|
+
await this.txHost.run(async () => { });
|
|
3666
|
+
signal.throwIfAborted();
|
|
3667
|
+
// the call scope lives on this call's own context object (never a module map)
|
|
3668
|
+
const call = { ...base, ...config, signal };
|
|
3669
|
+
scope = attachCallScope(call, {
|
|
3670
|
+
runId: ctx.runId,
|
|
3671
|
+
step: ctx.step,
|
|
3672
|
+
rootConversationId,
|
|
3673
|
+
unattended: ctx.unattended != null,
|
|
3674
|
+
agentVersion: ctx.agentVersion,
|
|
3675
|
+
...(ctx.conversationKind !== undefined && { conversationKind: ctx.conversationKind }),
|
|
3676
|
+
...(ctx.parent !== undefined && {
|
|
3677
|
+
parent: {
|
|
3678
|
+
conversationId: ctx.parent.conversationId,
|
|
3679
|
+
runId: ctx.parent.runId,
|
|
3680
|
+
callId: ctx.parent.callId,
|
|
3681
|
+
...(ctx.parent.budgetRunId !== undefined && {
|
|
3682
|
+
budgetRunId: ctx.parent.budgetRunId,
|
|
3683
|
+
}),
|
|
3684
|
+
},
|
|
3685
|
+
}),
|
|
3686
|
+
});
|
|
3687
|
+
return handler(input, call);
|
|
3688
|
+
}, undefined, timeoutMs);
|
|
837
3689
|
if (r === "timeout") {
|
|
838
|
-
|
|
3690
|
+
const starting = stillStartingUnsent(scope);
|
|
3691
|
+
if (starting)
|
|
3692
|
+
this.deps.log.info("tool call timed out while its device was still starting", {
|
|
3693
|
+
toolKey: tool.key,
|
|
3694
|
+
timeoutMs,
|
|
3695
|
+
});
|
|
3696
|
+
const message = starting
|
|
3697
|
+
? deviceStartingTimeoutText(tool.key, timeoutMs)
|
|
3698
|
+
: timeoutText(tool.key, timeoutMs);
|
|
3699
|
+
return withBlocked({ kind: "error", message }, scope);
|
|
839
3700
|
}
|
|
3701
|
+
// a launch reviewed before the call stopped or asked is kept with its result
|
|
840
3702
|
if (r === "aborted")
|
|
841
|
-
return { kind: "error", message: RUN_STOPPED_DURING_TEXT };
|
|
3703
|
+
return withBlocked({ kind: "error", message: RUN_STOPPED_DURING_TEXT }, scope);
|
|
842
3704
|
if (isInputRequired(r.value)) {
|
|
843
|
-
return {
|
|
3705
|
+
return withBlocked({
|
|
3706
|
+
kind: "input_required",
|
|
3707
|
+
form: r.value.form,
|
|
3708
|
+
state: r.value.state ?? null,
|
|
3709
|
+
...(r.value.open !== undefined && { open: r.value.open }),
|
|
3710
|
+
...(tool.source.kind === "plugin" &&
|
|
3711
|
+
r.value.watch !== undefined && { watch: r.value.watch }),
|
|
3712
|
+
}, scope);
|
|
844
3713
|
}
|
|
845
|
-
return { kind: "result", result: r.value };
|
|
3714
|
+
return withBlocked({ kind: "result", result: r.value }, scope);
|
|
846
3715
|
}
|
|
847
3716
|
catch (e) {
|
|
848
|
-
return this.thrown(tool.key, e);
|
|
3717
|
+
return withBlocked(this.thrown(tool.key, e), scope);
|
|
849
3718
|
}
|
|
850
3719
|
}
|
|
851
3720
|
async executeConnector(tool, source, input, ctx, resume) {
|
|
@@ -854,7 +3723,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
854
3723
|
const connectorId = source.connectorId;
|
|
855
3724
|
const app = await db
|
|
856
3725
|
.selectFrom("connectors")
|
|
857
|
-
.select(["name", "connector", "endpoint", "auth", "status"])
|
|
3726
|
+
.select(["name", "slug", "connector", "endpoint", "auth", "status"])
|
|
858
3727
|
.where("id", "=", connectorId)
|
|
859
3728
|
.where("org_id", "=", orgId)
|
|
860
3729
|
.where("deleted_at", "is", null)
|
|
@@ -890,10 +3759,13 @@ let ToolPipeline = class ToolPipeline {
|
|
|
890
3759
|
// 远端在调用途中向用户要输入(MCP elicitation,见 elicitation.ts):需要问用户时中止本次调用、按 input_required
|
|
891
3760
|
// 处理;续跑时用 ctx.resume 的答案答复远端再次发起的同一请求。resources 工具不续跑,一律拒绝。
|
|
892
3761
|
const suspend = new AbortController();
|
|
3762
|
+
// an unattended run in `fail` mode declines every elicitation: no one is there to answer
|
|
3763
|
+
const unattended = unattendedFails(ctx.unattended);
|
|
893
3764
|
const elicit = new ElicitationSession({
|
|
894
3765
|
resume,
|
|
895
3766
|
onSuspend: () => suspend.abort(),
|
|
896
|
-
declineAll: source.resources === true,
|
|
3767
|
+
declineAll: source.resources === true || unattended,
|
|
3768
|
+
...(unattended && { declineNote: UNATTENDED_ELICITATION_NOTE }),
|
|
897
3769
|
});
|
|
898
3770
|
// 远端可能把收到的凭据回显在结果 / 错误 / elicitation 表单里:写入事件之前按本次注入的值打码(见 redact.ts)
|
|
899
3771
|
const clean = (o) => {
|
|
@@ -929,17 +3801,20 @@ let ToolPipeline = class ToolPipeline {
|
|
|
929
3801
|
kind: "connection_required",
|
|
930
3802
|
connectorId,
|
|
931
3803
|
connectorName: app.name,
|
|
3804
|
+
connectorSlug: app.slug,
|
|
932
3805
|
message: personalMissingText(app.name),
|
|
933
3806
|
}
|
|
934
|
-
: { kind: "error", message:
|
|
935
|
-
//
|
|
3807
|
+
: { kind: "error", message: ORG_MISSING_TEXT };
|
|
3808
|
+
// Read the credential once first: a missing one (or a needs_config connector) is settled before
|
|
3809
|
+
// any session opens, without relying on the connector to rethrow CredentialMissing.
|
|
936
3810
|
try {
|
|
937
3811
|
await getAuth();
|
|
938
3812
|
}
|
|
939
3813
|
catch (e) {
|
|
940
3814
|
if (e instanceof CredentialMissing)
|
|
941
3815
|
return missing(e);
|
|
942
|
-
//
|
|
3816
|
+
// the authorization server is briefly unavailable for the token (OAuth): an actionable
|
|
3817
|
+
// message for the model instead of failing the whole turn
|
|
943
3818
|
if (e instanceof ToolError)
|
|
944
3819
|
return { kind: "error", message: e.message };
|
|
945
3820
|
throw e;
|
|
@@ -959,6 +3834,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
959
3834
|
await credentials.onUnauthorized(orgId, connectorId, auth, ctx.accountId, stale);
|
|
960
3835
|
},
|
|
961
3836
|
signal,
|
|
3837
|
+
orgId,
|
|
962
3838
|
onElicit: elicit.handle,
|
|
963
3839
|
onToolsChanged: () => {
|
|
964
3840
|
try {
|
|
@@ -974,6 +3850,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
974
3850
|
},
|
|
975
3851
|
});
|
|
976
3852
|
const session = await opened;
|
|
3853
|
+
await this.txHost.run(async () => { });
|
|
3854
|
+
signal.throwIfAborted();
|
|
977
3855
|
return source.resources
|
|
978
3856
|
? runResourceTool(session, source.name, input)
|
|
979
3857
|
: // 交回已复核的定义(connector_tools.spec,含 connectorData):连接器按它路由,远端变化须先经漂移复核
|
|
@@ -1018,9 +3896,16 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1018
3896
|
thrown(key, e) {
|
|
1019
3897
|
if (e instanceof ToolError)
|
|
1020
3898
|
return { kind: "error", message: e.message };
|
|
3899
|
+
// a ctx.deviceAccess refusal the handler let through: its message is actionable English
|
|
3900
|
+
if (e instanceof DeviceAccessError)
|
|
3901
|
+
return { kind: "error", message: e.message };
|
|
1021
3902
|
// an extension tool's ctx.models.embed denied by a policy hook (spec B §5.4): the model sees the
|
|
1022
3903
|
// deny text (sanitized reason), as for a denied tool call, not a generic failure
|
|
1023
|
-
if (e instanceof ApiError &&
|
|
3904
|
+
if (e instanceof ApiError &&
|
|
3905
|
+
(e.code === "model.hook_denied" ||
|
|
3906
|
+
e.code === "model.budget_exceeded" ||
|
|
3907
|
+
e.code === "model.budget_currency_mismatch" ||
|
|
3908
|
+
e.code === "model.budget_unavailable")) {
|
|
1024
3909
|
return { kind: "error", message: e.message };
|
|
1025
3910
|
}
|
|
1026
3911
|
// 提供工具的插件实例在调用进行中被撤销(停用 / 升级),排空时限到后中止(C17)
|
|
@@ -1106,7 +3991,9 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1106
3991
|
/**
|
|
1107
3992
|
* A plugin tool's inline card (`ToolResult.card` → `tool_result.card`, display only): `view` must
|
|
1108
3993
|
* be an `inline` ui contribution of the same extension and `key` at most 200 characters; anything
|
|
1109
|
-
* else is dropped with a warning and the result is written as usual.
|
|
3994
|
+
* else is dropped with a warning and the result is written as usual. `placement` is kept when
|
|
3995
|
+
* `pinned` or `process` (an unknown value means `output`); `text` only with `pinned`, 1 to
|
|
3996
|
+
* {@link CARD_TEXT_MAX} characters; `badge` only with `pinned`, 1 to {@link CARD_BADGE_MAX}.
|
|
1110
3997
|
*/
|
|
1111
3998
|
cardOf(result, plugin, toolKey) {
|
|
1112
3999
|
const c = result?.card;
|
|
@@ -1122,7 +4009,76 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1122
4009
|
});
|
|
1123
4010
|
return undefined;
|
|
1124
4011
|
}
|
|
1125
|
-
|
|
4012
|
+
// placement: an unknown value falls back to `output` (recorded as absent)
|
|
4013
|
+
let placement;
|
|
4014
|
+
if (x.placement === "pinned" || x.placement === "process")
|
|
4015
|
+
placement = x.placement;
|
|
4016
|
+
else if (x.placement !== undefined && x.placement !== "output") {
|
|
4017
|
+
this.deps.log.warn("tool returned an inline card with an unknown placement; using output", {
|
|
4018
|
+
toolKey,
|
|
4019
|
+
placement: typeof x.placement === "string" ? x.placement.slice(0, 50) : undefined,
|
|
4020
|
+
});
|
|
4021
|
+
}
|
|
4022
|
+
// text: only a pinned card carries it, at most CARD_TEXT_MAX characters
|
|
4023
|
+
let text;
|
|
4024
|
+
if (x.text !== undefined) {
|
|
4025
|
+
if (placement !== "pinned") {
|
|
4026
|
+
this.deps.log.warn("tool returned inline card text without a pinned placement; text dropped", {
|
|
4027
|
+
toolKey,
|
|
4028
|
+
});
|
|
4029
|
+
}
|
|
4030
|
+
else if (typeof x.text !== "string" || x.text === "" || x.text.length > CARD_TEXT_MAX) {
|
|
4031
|
+
this.deps.log.warn("tool returned inline card text that is empty or too long; text dropped", {
|
|
4032
|
+
toolKey,
|
|
4033
|
+
});
|
|
4034
|
+
}
|
|
4035
|
+
else
|
|
4036
|
+
text = x.text;
|
|
4037
|
+
}
|
|
4038
|
+
// badge: only a pinned card carries it, at most CARD_BADGE_MAX characters
|
|
4039
|
+
let badge;
|
|
4040
|
+
if (x.badge !== undefined) {
|
|
4041
|
+
if (placement !== "pinned") {
|
|
4042
|
+
this.deps.log.warn("tool returned an inline card badge without a pinned placement; badge dropped", { toolKey });
|
|
4043
|
+
}
|
|
4044
|
+
else if (typeof x.badge !== "string" || x.badge === "" || x.badge.length > CARD_BADGE_MAX) {
|
|
4045
|
+
this.deps.log.warn("tool returned an inline card badge that is empty or too long; badge dropped", { toolKey });
|
|
4046
|
+
}
|
|
4047
|
+
else
|
|
4048
|
+
badge = x.badge;
|
|
4049
|
+
}
|
|
4050
|
+
return {
|
|
4051
|
+
plugin,
|
|
4052
|
+
view: x.view,
|
|
4053
|
+
...(x.key !== undefined && { key: x.key }),
|
|
4054
|
+
...(placement !== undefined && { placement }),
|
|
4055
|
+
...(text !== undefined && { text }),
|
|
4056
|
+
...(badge !== undefined && { badge }),
|
|
4057
|
+
};
|
|
4058
|
+
}
|
|
4059
|
+
/**
|
|
4060
|
+
* A plugin tool's `InputRequired.open` (display only): `contribution` must be a
|
|
4061
|
+
* `conversation.panel` of the same extension and `item` at most 200 characters; anything else is
|
|
4062
|
+
* dropped with a warning and the form is asked as usual. The plugin is the tool's, never the
|
|
4063
|
+
* extension's word.
|
|
4064
|
+
*/
|
|
4065
|
+
openOf(open, plugin, toolKey) {
|
|
4066
|
+
const x = (typeof open === "object" && open !== null ? open : {});
|
|
4067
|
+
const itemOk = x.item === undefined || (typeof x.item === "string" && x.item !== "" && x.item.length <= 200);
|
|
4068
|
+
if (typeof x.contribution !== "string" ||
|
|
4069
|
+
!this.deps.panels(plugin).has(x.contribution) ||
|
|
4070
|
+
!itemOk) {
|
|
4071
|
+
this.deps.log.warn("tool asked for input with an open target that is not a panel of its extension; dropped", {
|
|
4072
|
+
toolKey,
|
|
4073
|
+
contribution: typeof x.contribution === "string" ? x.contribution.slice(0, 100) : undefined,
|
|
4074
|
+
});
|
|
4075
|
+
return undefined;
|
|
4076
|
+
}
|
|
4077
|
+
return {
|
|
4078
|
+
plugin,
|
|
4079
|
+
contribution: x.contribution,
|
|
4080
|
+
...(x.item !== undefined && { item: x.item }),
|
|
4081
|
+
};
|
|
1126
4082
|
}
|
|
1127
4083
|
/**
|
|
1128
4084
|
* A builtin's structured view (`tool_result.view`, display only): checked against
|
|
@@ -1196,6 +4152,21 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1196
4152
|
__decorate([
|
|
1197
4153
|
Transactional({ propagation: "mandatory" })
|
|
1198
4154
|
], ToolPipeline.prototype, "stopOpenAgentCalls", null);
|
|
4155
|
+
__decorate([
|
|
4156
|
+
Transactional()
|
|
4157
|
+
], ToolPipeline.prototype, "recordAskDecisionIn", null);
|
|
4158
|
+
__decorate([
|
|
4159
|
+
Transactional()
|
|
4160
|
+
], ToolPipeline.prototype, "findPermissionGrant", null);
|
|
4161
|
+
__decorate([
|
|
4162
|
+
Transactional()
|
|
4163
|
+
], ToolPipeline.prototype, "recordPermissionReview", null);
|
|
4164
|
+
__decorate([
|
|
4165
|
+
Transactional()
|
|
4166
|
+
], ToolPipeline.prototype, "grantLoopbackIn", null);
|
|
4167
|
+
__decorate([
|
|
4168
|
+
Transactional()
|
|
4169
|
+
], ToolPipeline.prototype, "recordLoopbackReview", null);
|
|
1199
4170
|
__decorate([
|
|
1200
4171
|
Transactional()
|
|
1201
4172
|
], ToolPipeline.prototype, "writeResultIn", null);
|
|
@@ -1219,6 +4190,36 @@ ToolPipeline = __decorate([
|
|
|
1219
4190
|
__param(15, Inject(OrgToolSwitches)),
|
|
1220
4191
|
__param(16, Inject(TransactionHost)),
|
|
1221
4192
|
__param(17, Optional()),
|
|
1222
|
-
__param(17, Inject(TOOL_PIPELINE_HOOKS))
|
|
4193
|
+
__param(17, Inject(TOOL_PIPELINE_HOOKS)),
|
|
4194
|
+
__param(18, Optional()),
|
|
4195
|
+
__param(18, Inject(NetworkGrants)),
|
|
4196
|
+
__param(19, Optional()),
|
|
4197
|
+
__param(19, Inject(CommandReviewService)),
|
|
4198
|
+
__param(20, Optional()),
|
|
4199
|
+
__param(20, Inject(ConversationDevices)),
|
|
4200
|
+
__param(21, Optional()),
|
|
4201
|
+
__param(21, Inject(SandboxOperationAuthority)),
|
|
4202
|
+
__param(22, Optional()),
|
|
4203
|
+
__param(22, Inject(PermissionCallGrants)),
|
|
4204
|
+
__param(23, Optional()),
|
|
4205
|
+
__param(23, Inject(PermissionAutoGrants)),
|
|
4206
|
+
__param(24, Optional()),
|
|
4207
|
+
__param(24, Inject(PermissionAuthorityLock)),
|
|
4208
|
+
__param(25, Optional()),
|
|
4209
|
+
__param(25, Inject(SandboxService)),
|
|
4210
|
+
__param(26, Optional()),
|
|
4211
|
+
__param(26, Inject(ConversationApprovalProfile)),
|
|
4212
|
+
__param(27, Optional()),
|
|
4213
|
+
__param(27, Inject(ToolAskReview)),
|
|
4214
|
+
__param(28, Optional()),
|
|
4215
|
+
__param(28, Inject(AttachmentsService)),
|
|
4216
|
+
__param(29, Optional()),
|
|
4217
|
+
__param(29, Inject(LoopbackGrants)),
|
|
4218
|
+
__param(30, Optional()),
|
|
4219
|
+
__param(30, Inject(PermissionFacts)),
|
|
4220
|
+
__param(31, Optional()),
|
|
4221
|
+
__param(31, Inject(DeviceSiteGrants)),
|
|
4222
|
+
__param(32, Optional()),
|
|
4223
|
+
__param(32, Inject(ExtensionRegistry))
|
|
1223
4224
|
], ToolPipeline);
|
|
1224
4225
|
export { ToolPipeline };
|