@capybara-hq/kernel 0.1.0-rc.3 → 0.1.0-rc.5
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 +61 -5
- package/dist/admin/admin.controller.d.ts +47 -16
- package/dist/admin/admin.controller.js +44 -19
- package/dist/admin/extensions.controller.d.ts +24 -3
- package/dist/admin/extensions.controller.js +48 -8
- package/dist/admin/setup-lock.d.ts +1 -1
- package/dist/admin/setup-lock.js +1 -1
- package/dist/admin/setup.controller.d.ts +1 -1
- package/dist/admin/setup.controller.js +1 -1
- package/dist/admin/setup.service.d.ts +4 -4
- package/dist/admin/setup.service.js +8 -8
- package/dist/agents/agent-lookup.d.ts +19 -0
- package/dist/agents/agent-lookup.js +21 -0
- package/dist/agents/agent-profile.service.d.ts +29 -0
- package/dist/agents/agent-profile.service.js +117 -0
- package/dist/agents/agents.controller.d.ts +168 -3
- package/dist/agents/agents.controller.js +201 -12
- package/dist/agents/agents.module.d.ts +4 -1
- package/dist/agents/agents.module.js +36 -6
- package/dist/agents/agents.service.d.ts +64 -27
- package/dist/agents/agents.service.js +199 -74
- package/dist/agents/definition.d.ts +53 -0
- package/dist/agents/definition.js +55 -0
- package/dist/agents/from-template.d.ts +106 -0
- package/dist/agents/from-template.js +649 -0
- package/dist/agents/from-template.service.d.ts +60 -0
- package/dist/agents/from-template.service.js +161 -0
- package/dist/agents/instruction-files.d.ts +60 -0
- package/dist/agents/instruction-files.js +111 -0
- package/dist/agents/models.controller.d.ts +9 -3
- package/dist/agents/models.controller.js +19 -4
- package/dist/agents/org-templates.d.ts +176 -0
- package/dist/agents/org-templates.js +827 -0
- package/dist/agents/pending-connector-requests.d.ts +77 -0
- package/dist/agents/pending-connector-requests.js +215 -0
- package/dist/agents/pending-connectors.controller.d.ts +39 -0
- package/dist/agents/pending-connectors.controller.js +91 -0
- package/dist/agents/pending-connectors.service.d.ts +62 -0
- package/dist/agents/pending-connectors.service.js +282 -0
- package/dist/agents/profile.d.ts +96 -0
- package/dist/agents/profile.js +51 -0
- package/dist/agents/readiness.controller.d.ts +26 -0
- package/dist/agents/readiness.controller.js +56 -0
- package/dist/agents/templates.controller.d.ts +86 -5
- package/dist/agents/templates.controller.js +171 -7
- package/dist/agents/templates.d.ts +127 -23
- package/dist/agents/templates.js +476 -53
- package/dist/background/background.controller.d.ts +38 -0
- package/dist/background/background.controller.js +87 -0
- package/dist/background/background.module.d.ts +10 -0
- package/dist/background/background.module.js +39 -0
- package/dist/background/finish.d.ts +44 -0
- package/dist/background/finish.js +94 -0
- package/dist/background/launch-lock.d.ts +15 -0
- package/dist/background/launch-lock.js +40 -0
- package/dist/background/launch.d.ts +36 -0
- package/dist/background/launch.js +70 -0
- package/dist/background/poll.job.d.ts +56 -0
- package/dist/background/poll.job.js +190 -0
- package/dist/background/render.d.ts +23 -0
- package/dist/background/render.js +48 -0
- package/dist/background/session.d.ts +48 -0
- package/dist/background/session.js +79 -0
- package/dist/background/status.d.ts +35 -0
- package/dist/background/status.js +57 -0
- package/dist/background/stop.d.ts +68 -0
- package/dist/background/stop.js +243 -0
- package/dist/background/store.d.ts +162 -0
- package/dist/background/store.js +357 -0
- package/dist/background/store.module.d.ts +6 -0
- package/dist/background/store.module.js +22 -0
- package/dist/background/tasks.service.d.ts +77 -0
- package/dist/background/tasks.service.js +211 -0
- package/dist/background/wake-rules.d.ts +66 -0
- package/dist/background/wake-rules.js +113 -0
- package/dist/background/wake.d.ts +30 -0
- package/dist/background/wake.js +63 -0
- package/dist/catalog/admin-catalog.controller.d.ts +129 -30
- package/dist/catalog/admin-catalog.controller.js +213 -42
- package/dist/catalog/catalog-content.d.ts +58 -32
- package/dist/catalog/catalog-content.js +34 -8
- package/dist/catalog/catalog-import.module.d.ts +7 -0
- package/dist/catalog/catalog-import.module.js +60 -0
- package/dist/catalog/catalog-items.d.ts +111 -7
- package/dist/catalog/catalog-items.js +279 -13
- package/dist/catalog/catalog-scope.service.d.ts +260 -0
- package/dist/catalog/catalog-scope.service.js +1116 -0
- package/dist/catalog/catalog.module.d.ts +7 -9
- package/dist/catalog/catalog.module.js +41 -31
- package/dist/catalog/catalog.service.d.ts +101 -29
- package/dist/catalog/catalog.service.js +104 -106
- package/dist/catalog/claude/agents.js +2 -0
- package/dist/catalog/cli.d.ts +11 -1
- package/dist/catalog/cli.js +26 -1
- package/dist/catalog/component-promotion.d.ts +96 -0
- package/dist/catalog/component-promotion.js +395 -0
- package/dist/catalog/component-scope.controller.d.ts +152 -0
- package/dist/catalog/component-scope.controller.js +287 -0
- package/dist/catalog/component-scope.service.d.ts +303 -0
- package/dist/catalog/component-scope.service.js +936 -0
- package/dist/catalog/component-state.d.ts +174 -0
- package/dist/catalog/component-state.js +437 -0
- package/dist/catalog/job-ids.d.ts +30 -0
- package/dist/catalog/job-ids.js +25 -0
- package/dist/catalog/marketplace-fetch.d.ts +1 -1
- package/dist/catalog/marketplaces.controller.d.ts +22 -5
- package/dist/catalog/marketplaces.controller.js +56 -7
- package/dist/catalog/marketplaces.service.d.ts +54 -14
- package/dist/catalog/marketplaces.service.js +71 -22
- package/dist/catalog/org-catalog.controller.d.ts +125 -34
- package/dist/catalog/org-catalog.controller.js +181 -65
- package/dist/catalog/org-catalog.service.d.ts +65 -33
- package/dist/catalog/org-catalog.service.js +324 -157
- package/dist/catalog/org-extension-switch.d.ts +41 -0
- package/dist/catalog/org-extension-switch.js +115 -0
- package/dist/catalog/org-extension.controller.d.ts +119 -0
- package/dist/catalog/org-extension.controller.js +266 -0
- package/dist/catalog/org-plugin-uploads.controller.d.ts +98 -0
- package/dist/catalog/org-plugin-uploads.controller.js +213 -0
- package/dist/catalog/org-plugin-uploads.d.ts +63 -0
- package/dist/catalog/org-plugin-uploads.js +116 -0
- package/dist/catalog/owned-items.d.ts +184 -0
- package/dist/catalog/owned-items.js +789 -0
- package/dist/catalog/owned-plugin-cleanup.d.ts +56 -0
- package/dist/catalog/owned-plugin-cleanup.js +194 -0
- package/dist/catalog/ownership.d.ts +172 -0
- package/dist/catalog/ownership.js +326 -0
- package/dist/catalog/platform-components.d.ts +221 -0
- package/dist/catalog/platform-components.js +761 -0
- package/dist/catalog/platform-migration.d.ts +115 -0
- package/dist/catalog/platform-migration.js +582 -0
- package/dist/catalog/plugin-import.d.ts +178 -34
- package/dist/catalog/plugin-import.js +623 -83
- package/dist/catalog/plugin-install.d.ts +185 -41
- package/dist/catalog/plugin-install.js +758 -126
- package/dist/catalog/plugin-upgrade.d.ts +260 -225
- package/dist/catalog/plugin-upgrade.js +1148 -1137
- package/dist/catalog/request-rules.d.ts +65 -0
- package/dist/catalog/request-rules.js +217 -0
- package/dist/catalog/requests.service.d.ts +193 -118
- package/dist/catalog/requests.service.js +526 -343
- package/dist/catalog/reserved-names.d.ts +8 -0
- package/dist/catalog/reserved-names.js +42 -0
- package/dist/catalog/scope-orgs.d.ts +21 -0
- package/dist/catalog/scope-orgs.js +67 -0
- package/dist/catalog/scope-state.d.ts +35 -0
- package/dist/catalog/scope-state.js +87 -0
- package/dist/catalog/scope-sync-workers.d.ts +7 -0
- package/dist/catalog/scope-sync-workers.js +29 -0
- package/dist/catalog/scope-sync.d.ts +176 -0
- package/dist/catalog/scope-sync.js +576 -0
- package/dist/catalog/scope.d.ts +42 -0
- package/dist/catalog/scope.js +42 -0
- package/dist/catalog/unshare.d.ts +22 -0
- package/dist/catalog/unshare.js +118 -0
- package/dist/channels/actions.js +1 -0
- package/dist/channels/cards.js +21 -3
- package/dist/channels/channels.module.js +2 -0
- package/dist/channels/connections.service.d.ts +16 -1
- package/dist/channels/connections.service.js +38 -4
- package/dist/channels/inbound.d.ts +9 -1
- package/dist/channels/inbound.js +67 -5
- package/dist/channels/phrases.d.ts +35 -0
- package/dist/channels/phrases.js +29 -0
- package/dist/channels/threads.d.ts +5 -0
- package/dist/channels/threads.js +8 -0
- package/dist/config/docs.js +3 -1
- package/dist/config/schema.d.ts +24 -2
- package/dist/config/schema.js +145 -19
- package/dist/conversations/access.d.ts +6 -4
- package/dist/conversations/access.js +29 -5
- package/dist/conversations/agent-tree.d.ts +46 -0
- package/dist/conversations/agent-tree.js +92 -0
- package/dist/conversations/attachments.service.d.ts +30 -0
- package/dist/conversations/attachments.service.js +130 -5
- package/dist/conversations/conversations.controller.d.ts +79 -23
- package/dist/conversations/conversations.controller.js +141 -50
- package/dist/conversations/conversations.module.d.ts +1 -1
- package/dist/conversations/conversations.module.js +10 -7
- package/dist/conversations/conversations.service.d.ts +108 -9
- package/dist/conversations/conversations.service.js +237 -30
- package/dist/conversations/environment-status.d.ts +24 -0
- package/dist/conversations/environment-status.js +71 -0
- package/dist/conversations/event-log.d.ts +21 -6
- package/dist/conversations/event-log.js +70 -1
- package/dist/conversations/events.d.ts +140 -0
- package/dist/conversations/events.js +142 -13
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.js +13 -2
- package/dist/conversations/queue.service.d.ts +1 -1
- package/dist/conversations/queue.service.js +8 -1
- package/dist/conversations/titles.d.ts +12 -3
- package/dist/conversations/titles.js +36 -8
- package/dist/conversations/tree.d.ts +17 -0
- package/dist/conversations/tree.js +42 -0
- package/dist/ctx/create-ctx.d.ts +5 -0
- package/dist/ctx/create-ctx.js +15 -5
- package/dist/db/kernel-schema.d.ts +420 -20
- package/dist/db/pool.d.ts +5 -0
- package/dist/db/pool.js +3 -0
- package/dist/environments/access.d.ts +41 -0
- package/dist/environments/access.js +77 -0
- package/dist/environments/conversation-environments.d.ts +61 -0
- package/dist/environments/conversation-environments.js +170 -0
- package/dist/environments/dto.d.ts +25 -0
- package/dist/environments/dto.js +12 -0
- package/dist/environments/environments.controller.d.ts +33 -0
- package/dist/environments/environments.controller.js +110 -0
- package/dist/environments/environments.module.d.ts +8 -0
- package/dist/environments/environments.module.js +27 -0
- package/dist/environments/environments.service.d.ts +153 -0
- package/dist/environments/environments.service.js +541 -0
- package/dist/environments/legacy-cleanup.job.d.ts +34 -0
- package/dist/environments/legacy-cleanup.job.js +141 -0
- package/dist/errors.d.ts +90 -2
- package/dist/errors.js +90 -2
- package/dist/evals/reconstruct.d.ts +18 -9
- package/dist/evals/reconstruct.js +26 -7
- package/dist/evals/run-replay.d.ts +7 -2
- package/dist/evals/run-replay.js +42 -7
- package/dist/evals/step-replay.d.ts +2 -5
- package/dist/evals/step-replay.js +13 -7
- package/dist/evals/trajectory.js +1 -1
- package/dist/evals/trajectory.service.d.ts +8 -3
- package/dist/evals/trajectory.service.js +26 -14
- package/dist/evals/worker.d.ts +5 -5
- package/dist/evals/worker.js +9 -3
- package/dist/extensions/admin-ops.d.ts +36 -10
- package/dist/extensions/admin-ops.js +67 -42
- package/dist/extensions/admin-view.d.ts +39 -10
- package/dist/extensions/admin-view.js +111 -20
- package/dist/extensions/blobs.js +1 -0
- package/dist/extensions/bootstrap.d.ts +17 -4
- package/dist/extensions/bootstrap.js +70 -9
- package/dist/extensions/cli.d.ts +12 -0
- package/dist/extensions/cli.js +11 -2
- package/dist/extensions/config-issues.d.ts +13 -1
- package/dist/extensions/config-issues.js +22 -5
- package/dist/extensions/config-json-schema.d.ts +43 -7
- package/dist/extensions/config-json-schema.js +124 -58
- package/dist/extensions/deployment-config-store.d.ts +6 -0
- package/dist/extensions/deployment-config.d.ts +78 -8
- package/dist/extensions/deployment-config.js +172 -34
- package/dist/extensions/display-name.d.ts +22 -0
- package/dist/extensions/display-name.js +77 -0
- package/dist/extensions/effective-config.d.ts +127 -0
- package/dist/extensions/effective-config.js +368 -0
- package/dist/extensions/extensions.module.js +14 -2
- package/dist/extensions/hooks.d.ts +37 -4
- package/dist/extensions/hooks.js +82 -16
- package/dist/extensions/host.d.ts +45 -2
- package/dist/extensions/host.js +112 -16
- package/dist/extensions/installs.d.ts +20 -8
- package/dist/extensions/installs.js +37 -15
- package/dist/extensions/org-config.d.ts +81 -6
- package/dist/extensions/org-config.js +195 -44
- package/dist/extensions/org-levels.d.ts +37 -0
- package/dist/extensions/org-levels.js +71 -0
- package/dist/extensions/org-overrides.d.ts +151 -0
- package/dist/extensions/org-overrides.js +524 -0
- package/dist/extensions/package.d.ts +14 -1
- package/dist/extensions/package.js +51 -2
- package/dist/extensions/permission-view.d.ts +19 -4
- package/dist/extensions/permission-view.js +4 -4
- package/dist/extensions/plugin-items.d.ts +21 -0
- package/dist/extensions/plugin-items.js +42 -0
- package/dist/extensions/point-defaults.controller.d.ts +34 -0
- package/dist/extensions/point-defaults.controller.js +71 -0
- package/dist/extensions/point-defaults.d.ts +71 -0
- package/dist/extensions/point-defaults.js +234 -0
- package/dist/extensions/registry.d.ts +1 -1
- package/dist/extensions/registry.js +2 -0
- package/dist/extensions/resolve.d.ts +5 -1
- package/dist/extensions/resolve.js +15 -2
- package/dist/files/previewers.d.ts +8 -1
- package/dist/files/previewers.js +35 -6
- package/dist/http/api.module.js +31 -3
- package/dist/http/app.d.ts +11 -2
- package/dist/http/app.js +31 -5
- package/dist/http/nest-logger.d.ts +6 -5
- package/dist/http/nest-logger.js +24 -10
- package/dist/identity/accounts.d.ts +29 -29
- package/dist/identity/accounts.js +47 -47
- package/dist/identity/audit.d.ts +2 -1
- package/dist/identity/auth.controller.js +9 -5
- package/dist/identity/auth.guard.d.ts +13 -5
- package/dist/identity/auth.guard.js +26 -9
- package/dist/identity/cookies.d.ts +20 -5
- package/dist/identity/cookies.js +44 -6
- package/dist/identity/identity.module.d.ts +1 -1
- package/dist/identity/identity.module.js +4 -4
- package/dist/identity/me.controller.d.ts +5 -1
- package/dist/identity/me.controller.js +12 -3
- package/dist/identity/principal.d.ts +3 -3
- package/dist/identity/principal.js +3 -3
- package/dist/identity/sessions.d.ts +12 -0
- package/dist/identity/sessions.js +45 -0
- package/dist/identity/settings.d.ts +22 -11
- package/dist/identity/settings.js +53 -18
- package/dist/identity/{enterprise-admin.d.ts → super-admin.d.ts} +5 -5
- package/dist/identity/{enterprise-admin.js → super-admin.js} +24 -24
- package/dist/inbox/inbox.module.d.ts +4 -1
- package/dist/inbox/inbox.module.js +7 -3
- package/dist/inbox/inbox.service.d.ts +62 -3
- package/dist/inbox/inbox.service.js +74 -4
- package/dist/inbox/org-notices.d.ts +63 -0
- package/dist/inbox/org-notices.js +91 -0
- package/dist/inbox/platform-inbox.controller.d.ts +23 -0
- package/dist/inbox/platform-inbox.controller.js +58 -0
- package/dist/inbox/platform-inbox.service.d.ts +151 -0
- package/dist/inbox/platform-inbox.service.js +263 -0
- package/dist/inbox/platform-notices.d.ts +19 -0
- package/dist/inbox/platform-notices.js +9 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/infra/cli/kernel-cli.module.js +9 -1
- package/dist/infra/config/kernel-config.service.js +27 -1
- package/dist/infra/database/database.module.js +1 -0
- package/dist/infra/database/xact-lock.d.ts +1 -1
- package/dist/infra/database/xact-lock.js +1 -1
- package/dist/infra/events/kernel-events.d.ts +19 -2
- package/dist/infra/lifecycle/process-guards.js +4 -0
- package/dist/infra/logging/logging.module.d.ts +4 -2
- package/dist/infra/logging/logging.module.js +24 -6
- package/dist/infra/queue/add-job-once.d.ts +14 -0
- package/dist/infra/queue/add-job-once.js +16 -0
- package/dist/infra/queue/redis-connection.d.ts +6 -0
- package/dist/infra/queue/redis-connection.js +7 -0
- package/dist/infra/redis/redis.module.js +6 -2
- package/dist/infra/tokens.d.ts +6 -1
- package/dist/infra/tokens.js +6 -1
- package/dist/kernel.module.js +6 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +1 -1
- package/dist/lifecycle/kernel-lifecycle.js +4 -4
- package/dist/log.d.ts +13 -1
- package/dist/log.js +93 -17
- package/dist/models/prices.d.ts +5 -5
- package/dist/models/prices.js +4 -4
- package/dist/models/purposes.controller.d.ts +6 -4
- package/dist/models/purposes.controller.js +13 -7
- package/dist/models/purposes.d.ts +43 -9
- package/dist/models/purposes.js +48 -18
- package/dist/orgs/directory-sync.d.ts +14 -5
- package/dist/orgs/directory-sync.js +41 -17
- package/dist/orgs/offboarding.d.ts +12 -8
- package/dist/orgs/offboarding.js +54 -33
- package/dist/orgs/org-lock.d.ts +5 -0
- package/dist/orgs/org-lock.js +13 -0
- package/dist/orgs/org.guard.d.ts +10 -0
- package/dist/orgs/org.guard.js +43 -32
- package/dist/orgs/orgs.module.js +3 -0
- package/dist/orgs/orgs.service.d.ts +20 -7
- package/dist/orgs/orgs.service.js +32 -12
- package/dist/orgs/roles.d.ts +1 -1
- package/dist/orgs/roles.js +5 -1
- package/dist/orgs/settings.controller.d.ts +1 -1
- package/dist/orgs/settings.service.d.ts +20 -3
- package/dist/orgs/settings.service.js +19 -4
- package/dist/overrides.d.ts +3 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/actor.d.ts +48 -0
- package/dist/platform/actor.js +100 -0
- package/dist/platform/agent-docs.d.ts +18 -0
- package/dist/platform/agent-docs.js +59 -0
- package/dist/platform/availability.d.ts +14 -0
- package/dist/platform/availability.js +43 -0
- package/dist/platform/errors.d.ts +11 -0
- package/dist/platform/errors.js +26 -0
- package/dist/platform/exclusions.d.ts +12 -0
- package/dist/platform/exclusions.js +1387 -0
- package/dist/platform/method.d.ts +6 -0
- package/dist/platform/method.js +15 -0
- package/dist/platform/operation.d.ts +92 -0
- package/dist/platform/operation.js +35 -0
- package/dist/platform/ops/agent-templates.ops.d.ts +14 -0
- package/dist/platform/ops/agent-templates.ops.js +92 -0
- package/dist/platform/ops/agents.ops.d.ts +19 -0
- package/dist/platform/ops/agents.ops.js +294 -0
- package/dist/platform/ops/connectors.ops.d.ts +15 -0
- package/dist/platform/ops/connectors.ops.js +126 -0
- package/dist/platform/ops/errors.d.ts +11 -0
- package/dist/platform/ops/errors.js +22 -0
- package/dist/platform/ops/extensions.ops.d.ts +19 -0
- package/dist/platform/ops/extensions.ops.js +116 -0
- package/dist/platform/ops/marketplaces.ops.d.ts +16 -0
- package/dist/platform/ops/marketplaces.ops.js +157 -0
- package/dist/platform/ops/paging.d.ts +14 -0
- package/dist/platform/ops/paging.js +20 -0
- package/dist/platform/ops/platform.ops.d.ts +23 -0
- package/dist/platform/ops/platform.ops.js +158 -0
- package/dist/platform/ops/plugins.ops.d.ts +33 -0
- package/dist/platform/ops/plugins.ops.js +377 -0
- package/dist/platform/ops/requests.ops.d.ts +14 -0
- package/dist/platform/ops/requests.ops.js +153 -0
- package/dist/platform/ops/role.d.ts +4 -0
- package/dist/platform/ops/role.js +10 -0
- package/dist/platform/ops/skills.ops.d.ts +13 -0
- package/dist/platform/ops/skills.ops.js +98 -0
- package/dist/platform/ops/summary.d.ts +10 -0
- package/dist/platform/ops/summary.js +18 -0
- package/dist/platform/platform-ops.module.d.ts +7 -0
- package/dist/platform/platform-ops.module.js +55 -0
- package/dist/platform/platform.module.d.ts +8 -0
- package/dist/platform/platform.module.js +25 -0
- package/dist/platform/redact-orgs.d.ts +7 -0
- package/dist/platform/redact-orgs.js +52 -0
- package/dist/platform/registry.d.ts +30 -0
- package/dist/platform/registry.js +111 -0
- package/dist/roles/worker-role.d.ts +6 -4
- package/dist/roles/worker-role.js +14 -7
- package/dist/roles/worker.module.d.ts +1 -1
- package/dist/roles/worker.module.js +15 -1
- package/dist/runtime/context/build.d.ts +11 -7
- package/dist/runtime/context/build.js +46 -19
- package/dist/runtime/context/claude-tools.d.ts +3 -1
- package/dist/runtime/context/claude-tools.js +8 -6
- package/dist/runtime/context/compaction.js +13 -0
- package/dist/runtime/context/reminders.d.ts +2 -0
- package/dist/runtime/context/reminders.js +2 -0
- package/dist/runtime/context/skills.js +9 -2
- package/dist/runtime/context/tool-changes.d.ts +27 -0
- package/dist/runtime/context/tool-changes.js +60 -0
- package/dist/runtime/hook-calls.js +2 -0
- package/dist/runtime/langgraph-loop.d.ts +3 -1
- package/dist/runtime/langgraph-loop.js +36 -17
- package/dist/runtime/loop.d.ts +34 -5
- package/dist/runtime/maintenance.d.ts +9 -4
- package/dist/runtime/maintenance.js +35 -8
- package/dist/runtime/model-call.d.ts +46 -8
- package/dist/runtime/model-call.js +72 -21
- package/dist/runtime/providers.d.ts +6 -0
- package/dist/runtime/providers.js +8 -0
- package/dist/runtime/run-control.d.ts +11 -1
- package/dist/runtime/run-control.js +12 -0
- package/dist/runtime/run-drafts.d.ts +85 -0
- package/dist/runtime/run-drafts.js +230 -0
- package/dist/runtime/run-jobs.d.ts +3 -5
- package/dist/runtime/run-jobs.js +3 -7
- package/dist/runtime/run-queue.d.ts +59 -2
- package/dist/runtime/run-queue.js +311 -38
- package/dist/runtime/run-worker.d.ts +11 -5
- package/dist/runtime/run-worker.js +69 -33
- package/dist/runtime/runtime.module.js +11 -3
- package/dist/runtime/step-log.d.ts +15 -4
- package/dist/runtime/step-log.js +24 -7
- package/dist/runtime/stream.controller.d.ts +23 -1
- package/dist/runtime/stream.controller.js +60 -3
- package/dist/runtime/stream.d.ts +4 -1
- package/dist/runtime/stream.js +27 -3
- package/dist/runtime/subagents/child.d.ts +55 -7
- package/dist/runtime/subagents/child.js +105 -7
- package/dist/runtime/subagents/definition.d.ts +12 -3
- package/dist/runtime/subagents/definition.js +44 -28
- package/dist/runtime/subagents/deliveries.d.ts +71 -0
- package/dist/runtime/subagents/deliveries.js +228 -0
- package/dist/runtime/subagents/dispatch.d.ts +115 -26
- package/dist/runtime/subagents/dispatch.js +212 -141
- package/dist/runtime/subagents/limits.d.ts +24 -5
- package/dist/runtime/subagents/limits.js +40 -6
- package/dist/runtime/subagents/messages.d.ts +95 -0
- package/dist/runtime/subagents/messages.js +328 -0
- package/dist/runtime/subagents/preamble.d.ts +4 -4
- package/dist/runtime/subagents/preamble.js +9 -7
- package/dist/runtime/subagents/progress.d.ts +8 -6
- package/dist/runtime/subagents/progress.js +11 -6
- package/dist/runtime/subagents/render.d.ts +30 -0
- package/dist/runtime/subagents/render.js +53 -0
- package/dist/runtime/subagents/roster.d.ts +24 -7
- package/dist/runtime/subagents/roster.js +47 -11
- package/dist/runtime/subagents/skill-fork.d.ts +3 -2
- package/dist/runtime/subagents/skill-fork.js +8 -4
- package/dist/runtime/subagents/status.d.ts +14 -0
- package/dist/runtime/subagents/status.js +23 -0
- package/dist/runtime/subagents/subagents.service.d.ts +7 -4
- package/dist/runtime/subagents/subagents.service.js +11 -6
- package/dist/runtime/usage-report.d.ts +2 -1
- package/dist/runtime/usage-report.js +19 -13
- package/dist/runtime/waits.d.ts +145 -36
- package/dist/runtime/waits.js +423 -109
- package/dist/sandbox/jobs.d.ts +40 -13
- package/dist/sandbox/jobs.js +57 -20
- package/dist/sandbox/leases.d.ts +37 -54
- package/dist/sandbox/leases.js +71 -115
- package/dist/sandbox/providers.d.ts +2 -2
- package/dist/sandbox/providers.js +1 -1
- package/dist/sandbox/sandbox.module.d.ts +3 -2
- package/dist/sandbox/sandbox.module.js +10 -4
- package/dist/sandbox/sandbox.service.d.ts +282 -129
- package/dist/sandbox/sandbox.service.js +736 -381
- package/dist/skills/catalog.d.ts +3 -2
- package/dist/skills/catalog.js +21 -43
- package/dist/skills/changes.controller.d.ts +7 -0
- package/dist/skills/changes.controller.js +19 -1
- package/dist/skills/invoke.js +8 -3
- package/dist/skills/package.d.ts +20 -1
- package/dist/skills/package.js +28 -1
- package/dist/skills/skills.controller.d.ts +39 -4
- package/dist/skills/skills.controller.js +88 -10
- package/dist/skills/skills.module.js +10 -1
- package/dist/skills/skills.service.d.ts +106 -26
- package/dist/skills/skills.service.js +421 -75
- package/dist/skills/usable.d.ts +81 -0
- package/dist/skills/usable.js +379 -0
- package/dist/tools/approvals.service.d.ts +20 -2
- package/dist/tools/approvals.service.js +25 -4
- package/dist/tools/builtin-names.d.ts +41 -7
- package/dist/tools/builtin-names.js +59 -7
- package/dist/tools/builtins/agent.d.ts +23 -21
- package/dist/tools/builtins/agent.js +62 -55
- package/dist/tools/builtins/builtin-tools.d.ts +19 -1
- package/dist/tools/builtins/builtin-tools.js +59 -2
- package/dist/tools/builtins/handback.d.ts +28 -0
- package/dist/tools/builtins/handback.js +53 -0
- package/dist/tools/builtins/platform.d.ts +34 -0
- package/dist/tools/builtins/platform.js +362 -0
- package/dist/tools/builtins/sandbox/bash.d.ts +1 -1
- package/dist/tools/builtins/sandbox/bash.js +241 -4
- package/dist/tools/builtins/sandbox/common.d.ts +69 -27
- package/dist/tools/builtins/sandbox/common.js +87 -48
- package/dist/tools/builtins/sandbox/deliver.js +1 -1
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/glob.js +2 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -4
- package/dist/tools/builtins/sandbox/index.d.ts +3 -1
- package/dist/tools/builtins/sandbox/index.js +7 -1
- package/dist/tools/builtins/sandbox/read.js +1 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +74 -0
- package/dist/tools/builtins/sandbox/task-output.js +329 -0
- package/dist/tools/builtins/sandbox/task-stop.d.ts +10 -0
- package/dist/tools/builtins/sandbox/task-stop.js +113 -0
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/send-message.d.ts +56 -0
- package/dist/tools/builtins/send-message.js +100 -0
- package/dist/tools/builtins/skill-load.d.ts +22 -14
- package/dist/tools/builtins/skill-load.js +86 -57
- package/dist/tools/builtins/skill-write.js +1 -1
- package/dist/tools/builtins/web/errors.d.ts +8 -0
- package/dist/tools/builtins/web/errors.js +53 -0
- package/dist/tools/builtins/web/extract.d.ts +62 -0
- package/dist/tools/builtins/web/extract.js +271 -0
- package/dist/tools/builtins/web/fetch.d.ts +55 -0
- package/dist/tools/builtins/web/fetch.js +175 -0
- package/dist/tools/builtins/web/index.d.ts +13 -0
- package/dist/tools/builtins/web/index.js +12 -0
- package/dist/tools/builtins/web/page-cache.d.ts +25 -0
- package/dist/tools/builtins/web/page-cache.js +77 -0
- package/dist/tools/builtins/web/search.d.ts +25 -0
- package/dist/tools/builtins/web/search.js +210 -0
- package/dist/tools/builtins/web/url.d.ts +17 -0
- package/dist/tools/builtins/web/url.js +43 -0
- package/dist/tools/connectors.controller.d.ts +10 -0
- package/dist/tools/connectors.controller.js +12 -0
- package/dist/tools/connectors.service.d.ts +46 -5
- package/dist/tools/connectors.service.js +94 -15
- package/dist/tools/extension-tools.controller.d.ts +14 -0
- package/dist/tools/extension-tools.controller.js +37 -0
- package/dist/tools/info.d.ts +42 -1
- package/dist/tools/info.js +64 -1
- package/dist/tools/oauth/flow-paths.d.ts +1 -1
- package/dist/tools/oauth/flow-paths.js +1 -1
- package/dist/tools/org-tool-switches.d.ts +74 -0
- package/dist/tools/org-tool-switches.js +184 -0
- package/dist/tools/pipeline.d.ts +46 -40
- package/dist/tools/pipeline.js +202 -364
- package/dist/tools/policy.d.ts +1 -1
- package/dist/tools/policy.js +36 -16
- package/dist/tools/registry.d.ts +120 -8
- package/dist/tools/registry.js +112 -19
- package/dist/tools/tools.module.js +24 -2
- package/dist/tools/validate.js +1 -1
- package/dist/ui/views.d.ts +2 -1
- package/dist/ui/views.js +17 -3
- package/package.json +3 -3
- package/src/migrations/0064_account_last_org.sql +7 -0
- package/src/migrations/0065_conversation_archive.sql +8 -0
- package/src/migrations/0066_extension_display_name.sql +4 -0
- package/src/migrations/0067_agent_profiles.sql +20 -0
- package/src/migrations/0068_agent_avatar_uploads.sql +7 -0
- package/src/migrations/0069_attachments_agent_idx.sql +3 -0
- package/src/migrations/0070_background_tasks.sql +37 -0
- package/src/migrations/0071_background_tasks_reserve.sql +6 -0
- package/src/migrations/0072_background_tasks_stopping.sql +5 -0
- package/src/migrations/0073_org_extension_point_defaults.sql +11 -0
- package/src/migrations/0074_subagent_tree.sql +50 -0
- package/src/migrations/0075_plugin_scope.sql +61 -0
- package/src/migrations/0076_skills_created_by_nullable.sql +6 -0
- package/src/migrations/0077_scope_requests.sql +52 -0
- package/src/migrations/0078_scope_grant_switches.sql +18 -0
- package/src/migrations/0079_scope_live_install_switches.sql +19 -0
- package/src/migrations/0080_rename_enterprise_admin.sql +18 -0
- package/src/migrations/0081_platform_components.sql +129 -0
- package/src/migrations/0082_platform_migration.sql +33 -0
- package/src/migrations/0083_plugin_scope_sync_failures.sql +15 -0
- package/src/migrations/0084_org_owned_items.sql +85 -0
- package/src/migrations/0085_agent_templates_phase4.sql +45 -0
- package/src/migrations/0086_org_layering.sql +30 -0
- package/src/migrations/0087_approval_summary.sql +6 -0
- package/src/migrations/0088_environments.sql +80 -0
- package/dist/catalog/upgrade-targets.d.ts +0 -56
- package/dist/catalog/upgrade-targets.js +0 -90
- package/dist/conversations/sandbox-status.d.ts +0 -24
- package/dist/conversations/sandbox-status.js +0 -52
- package/dist/extensions/org-config.controller.d.ts +0 -24
- package/dist/extensions/org-config.controller.js +0 -62
package/dist/tools/pipeline.js
CHANGED
|
@@ -9,9 +9,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { parseToolKey, ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
|
-
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
13
12
|
import { EventLog } from "../conversations/event-log.js";
|
|
14
13
|
import { ToolViewSchema } from "../conversations/events.js";
|
|
14
|
+
import { EffectiveConfigs, NEEDS_CONFIG_REASON } from "../extensions/effective-config.js";
|
|
15
15
|
import { clipText } from "../extensions/hooks.js";
|
|
16
16
|
import { ExtensionHost } from "../extensions/host.js";
|
|
17
17
|
import { ExtensionUnloadedError, PLUGIN_UNLOADED_TOOL_ERROR } from "../extensions/inflight.js";
|
|
@@ -23,22 +23,26 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
23
23
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
24
24
|
import { UNKNOWN_RESULT_TEXT } from "../runtime/context/pairing.js";
|
|
25
25
|
import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookScope, } from "../runtime/hook-calls.js";
|
|
26
|
-
import {
|
|
26
|
+
import { subagentWaitingIdemKey } from "../runtime/loop.js";
|
|
27
27
|
import { assistantIdemKey, MAX_MODEL_ATTEMPTS, modelCallIdemKey } from "../runtime/model-call.js";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
28
|
+
import { rootSurfaceOf } from "../runtime/subagents/child.js";
|
|
29
|
+
import { SubagentMessages } from "../runtime/subagents/messages.js";
|
|
30
|
+
import { pairStoppedForks } from "../runtime/subagents/skill-fork.js";
|
|
31
31
|
import { SubagentsService } from "../runtime/subagents/subagents.service.js";
|
|
32
32
|
import { skillLoadOfferedIn } from "../skills/catalog.js";
|
|
33
33
|
import { ApprovalsService } from "./approvals.service.js";
|
|
34
34
|
import { Breaker, breakerOpenMessage } from "./breaker.js";
|
|
35
|
-
import { TOOL_SEARCH } from "./builtin-names.js";
|
|
36
|
-
import {
|
|
35
|
+
import { SEND_MESSAGE, SUBAGENT_HANDBACK, TOOL_SEARCH } from "./builtin-names.js";
|
|
36
|
+
import { AGENT_TOOL, AgentToolInput } from "./builtins/agent.js";
|
|
37
|
+
import { HandbackInput } from "./builtins/handback.js";
|
|
38
|
+
import { SendMessageInput } from "./builtins/send-message.js";
|
|
37
39
|
import { isAlwaysLoaded, notLoadedText } from "./builtins/tool-search.js";
|
|
40
|
+
import { canonicalJson } from "./canonical-json.js";
|
|
38
41
|
import { CredentialMissing, Credentials } from "./credentials.js";
|
|
39
42
|
import { ToolDrift } from "./drift.js";
|
|
40
43
|
import { ElicitationSession } from "./elicitation.js";
|
|
41
44
|
import { legacyHint, legacyToolInput, legacyToolKey } from "./legacy-keys.js";
|
|
45
|
+
import { OrgToolSwitches, toolTurnedOffReason } from "./org-tool-switches.js";
|
|
42
46
|
import { renderResult, resolveOutputRefs, spillIfLarge, ToolOutputs } from "./outputs.js";
|
|
43
47
|
import { createDecidePolicy } from "./policy.js";
|
|
44
48
|
import { QuestionsService } from "./questions.service.js";
|
|
@@ -69,11 +73,6 @@ export const RUN_STOPPED_TEXT = "The run was stopped before this tool call was e
|
|
|
69
73
|
export const RUN_STOPPED_DURING_TEXT = "The run was stopped while this tool call was running; its outcome is unknown. Verify before retrying.";
|
|
70
74
|
const timeoutText = (key, ms) => `Tool ${key} timed out after ${ms / 1000}s. The operation may or may not have completed; verify before retrying.`;
|
|
71
75
|
const failedText = (key, errName) => `Tool ${key} failed (${errName}). The operation may not have completed; check before retrying or try another approach.`;
|
|
72
|
-
/**
|
|
73
|
-
* Is a logged call key the `Agent` tool: the current key, or the rc `agent` of a call dispatched
|
|
74
|
-
* before the rename (spec §9; a builtin maps without a scope)?
|
|
75
|
-
*/
|
|
76
|
-
const isAgentCallKey = (key) => key === AGENT_TOOL || legacyToolKey(key) === AGENT_TOOL;
|
|
77
76
|
/** The connector slugs and extension names among the run's tools (to read old `<x>__<tool>` keys). */
|
|
78
77
|
const legacyScopeOf = (tools) => {
|
|
79
78
|
const connectorSlugs = new Set();
|
|
@@ -91,7 +90,10 @@ const unknownToolText = (name, keys, toolSearch, hint = null) => `Unknown tool "
|
|
|
91
90
|
(toolSearch ? " Use ToolSearch to load other tools." : "") +
|
|
92
91
|
(hint === null ? "" : ` ${hint}`);
|
|
93
92
|
const unavailableText = (name, reason) => `Tool "${name}" is unavailable: ${reason}.`;
|
|
94
|
-
|
|
93
|
+
/** With a per-call policy key (`Platform:<operation>`), the text names it. */
|
|
94
|
+
const deniedText = (key, policyKey) => policyKey === undefined || policyKey === key
|
|
95
|
+
? `Tool ${key} is denied by policy.`
|
|
96
|
+
: `Tool ${key} is denied by policy for ${policyKey}.`;
|
|
95
97
|
/** Longest hook reason quoted in {@link hookDeniedText}. */
|
|
96
98
|
const HOOK_REASON_MAX = 500;
|
|
97
99
|
/**
|
|
@@ -105,8 +107,6 @@ const personalMissingText = (connectorName) => `The user has not connected ${con
|
|
|
105
107
|
const orgMissingText = (connectorName) => `${connectorName} has no organization credential configured; ask an organization admin to set it up.`;
|
|
106
108
|
/** Optional provider: the pipeline's {@link ToolPipelineHooks} (tests). */
|
|
107
109
|
export const TOOL_PIPELINE_HOOKS = Symbol("TOOL_PIPELINE_HOOKS");
|
|
108
|
-
/** `runCall` dispatched a sub-agent: the call stays open until the child run finishes. */
|
|
109
|
-
const OPEN = "open";
|
|
110
110
|
const approvalAuthorization = (a) => ({
|
|
111
111
|
approvalId: a.id,
|
|
112
112
|
approvedByAccountId: a.decidedBy,
|
|
@@ -181,9 +181,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
181
181
|
deps;
|
|
182
182
|
constructor(kdb, eventLog,
|
|
183
183
|
/** The `Agent` tool's sub-agent dispatch; absent (tests): `Agent` calls are refused. */
|
|
184
|
-
subagents,
|
|
184
|
+
subagents,
|
|
185
|
+
/** The message tools between agents; absent (tests): their calls are refused. */
|
|
186
|
+
messages, registry, credentials, breaker, outputs, approvals, questions, config, log,
|
|
185
187
|
/** Plugin hooks and inline ui contributions; absent (tests): no hooks, cards dropped. */
|
|
186
|
-
host, drift, txHost, hooks) {
|
|
188
|
+
host, drift, effective, switches, txHost, hooks) {
|
|
187
189
|
this.config = config;
|
|
188
190
|
this.txHost = txHost;
|
|
189
191
|
this.deps = {
|
|
@@ -202,6 +204,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
202
204
|
get pluginHooks() {
|
|
203
205
|
return host?.hooks;
|
|
204
206
|
},
|
|
207
|
+
effective,
|
|
208
|
+
switches,
|
|
205
209
|
inlineViews: (plugin) => new Set((host?.current(plugin)?.manifest.ui ?? [])
|
|
206
210
|
.filter((c) => c.place === "inline" && c.aliasOf === undefined)
|
|
207
211
|
.map((c) => c.id)),
|
|
@@ -211,6 +215,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
211
215
|
get subagents() {
|
|
212
216
|
return subagents ? { dispatch: (a) => subagents.dispatch(a) } : undefined;
|
|
213
217
|
},
|
|
218
|
+
messages,
|
|
214
219
|
};
|
|
215
220
|
const decide = hooks?.decidePolicy;
|
|
216
221
|
// the default policy reads live, on the context's handle
|
|
@@ -240,322 +245,34 @@ let ToolPipeline = class ToolPipeline {
|
|
|
240
245
|
tools: ctx.agent.tools ?? [],
|
|
241
246
|
skillLoad,
|
|
242
247
|
subagents: ctx.agent.subagents,
|
|
248
|
+
child: ctx.parent !== undefined,
|
|
249
|
+
forkChild: ctx.parent?.forSkill === true,
|
|
243
250
|
});
|
|
244
251
|
}
|
|
245
252
|
return resolved;
|
|
246
253
|
};
|
|
247
|
-
// `Agent`
|
|
248
|
-
//
|
|
249
|
-
let open = 0;
|
|
254
|
+
// an `Agent` call's dispatch writes its result (the sub-agent runs in the background, agent
|
|
255
|
+
// map spec §4.1), so no call keeps the step waiting on a sub-agent
|
|
250
256
|
for (const call of calls) {
|
|
251
257
|
if (await eventLog.findByIdem(ctx.conversationId, idem.result(ctx.runId, call.id)))
|
|
252
258
|
continue;
|
|
253
|
-
if (isAgentCallKey(call.name)) {
|
|
254
|
-
const row = await dispatchOfCall(this.deps.db, ctx.runId, call.id);
|
|
255
|
-
if (row) {
|
|
256
|
-
if (!(await this.finishAgentCall(ctx, row, call, resolve)))
|
|
257
|
-
open++;
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
259
|
const waitingFor = await this.processCall(ctx, call, resolve);
|
|
262
|
-
if (waitingFor
|
|
263
|
-
open++;
|
|
264
|
-
else if (waitingFor)
|
|
260
|
+
if (waitingFor)
|
|
265
261
|
return { kind: "suspended", waitingFor };
|
|
266
262
|
}
|
|
267
|
-
if (open > 0) {
|
|
268
|
-
// the run is being stopped (a person, its deadline): it does not wait for its sub-agents;
|
|
269
|
-
// their calls get their results now, and the children are stopped after the run's terminal
|
|
270
|
-
// commit (spec §12)
|
|
271
|
-
if (ctx.signal.aborted) {
|
|
272
|
-
const stopped = await this.stopOpenAgentCallsNow(ctx.runId, ctx.agent);
|
|
273
|
-
if (stopped.toSeq !== null) {
|
|
274
|
-
await eventLog.notify(ctx.conversationId, stopped.toSeq);
|
|
275
|
-
}
|
|
276
|
-
stopped.fire();
|
|
277
|
-
return { kind: "done" };
|
|
278
|
-
}
|
|
279
|
-
return {
|
|
280
|
-
kind: "suspended",
|
|
281
|
-
waitingFor: subagentsWait(ctx.runId, ctx.step, this.config.get()),
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
263
|
return { kind: "done" };
|
|
285
264
|
}
|
|
286
265
|
/**
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
* dispatch time is not recorded, so nothing is guessed) and fires `tool.postExecute` with the
|
|
294
|
-
* result, from the replica that writes it (spec §11).
|
|
266
|
+
* Writes, in the caller's transaction (`mandatory`), what a run that is being stopped (a person,
|
|
267
|
+
* its deadline, a failure, the wait sweep) still owes its log: the report of its fork invocation
|
|
268
|
+
* (phase D, `pairStoppedForks`; a still active fork child is stopped by the caller after its
|
|
269
|
+
* commit). An `Agent` call has its result from its dispatch (agent map spec §4.1), so there is
|
|
270
|
+
* nothing to write for it. Returns the fork's call id (the caller must not write a "not executed"
|
|
271
|
+
* result for it), the highest seq written, and `fire`, a no-op kept for the callers' hook phase.
|
|
295
272
|
*/
|
|
296
|
-
async
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
call.input.model !== undefined;
|
|
300
|
-
const r = await childResult(this.deps.eventLog, row, { modelGiven });
|
|
301
|
-
if (!r)
|
|
302
|
-
return false;
|
|
303
|
-
// No spec-hash check as in processCall: an `Agent` call writes no tool_call_started holding
|
|
304
|
-
// the executed definition's hash, and its description changes with the roster and limits
|
|
305
|
-
// while the child runs. The call's approval (forCall: its latest) is by construction the one
|
|
306
|
-
// that let this dispatch start, since a dispatch happens only after an approved decision.
|
|
307
|
-
const approval = await this.deps.approvals.forCall(ctx.runId, call.id);
|
|
308
|
-
// the result keeps the logged key (`agent` for a call dispatched before the rename, spec §9)
|
|
309
|
-
await this.writeResult(ctx, row.parentCallId, call.name, { content: r.content, isError: r.isError }, [finishedEvent(row, r.finished)], {
|
|
310
|
-
durationMs: r.finished.durationMs,
|
|
311
|
-
connectorId: null,
|
|
312
|
-
...(approval?.status === "approved" && {
|
|
313
|
-
authorization: approvalAuthorization(approval),
|
|
314
|
-
}),
|
|
315
|
-
});
|
|
316
|
-
const hooks = this.deps.pluginHooks;
|
|
317
|
-
const scope = hookScope(hooks, ctx);
|
|
318
|
-
if (hooks && scope && hooks.has("tool.postExecute")) {
|
|
319
|
-
const tool = (await resolve()).tools.find((t) => t.key === AGENT_TOOL);
|
|
320
|
-
if (tool) {
|
|
321
|
-
fireObserve(hooks, "tool.postExecute", {
|
|
322
|
-
...scope,
|
|
323
|
-
step: ctx.step,
|
|
324
|
-
callId: call.id,
|
|
325
|
-
toolKey: AGENT_TOOL,
|
|
326
|
-
specHash: tool.specHash,
|
|
327
|
-
input: call.input,
|
|
328
|
-
isError: r.isError,
|
|
329
|
-
content: r.content,
|
|
330
|
-
durationMs: r.finished.durationMs,
|
|
331
|
-
}, ctx.signal, this.deps.log);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
|
-
/** {@link stopOpenAgentCalls} in a transaction of its own (a stop seen by the tools node). */
|
|
337
|
-
async stopOpenAgentCallsNow(runId, agent) {
|
|
338
|
-
return this.stopOpenAgentCalls(runId, agent);
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Writes, in the caller's transaction (`mandatory`), the `tool_result` of every open `Agent` call
|
|
342
|
-
* of a run that is being stopped
|
|
343
|
-
* (sub-agents spec §12: a person stopped it while it waited on sub-agents, or its deadline or a
|
|
344
|
-
* stop hit its tools node after a dispatch). A call whose child already ended gets the child's
|
|
345
|
-
* result (and the missing `subagent_finished`); one whose child is still active gets
|
|
346
|
-
* {@link AGENT_STOPPED_WITH_RUN_TEXT}. The caller stops those children after its commit.
|
|
347
|
-
*
|
|
348
|
-
* Like every `Agent` result (see {@link finishAgentCall}), each is audited `tool.called` in it
|
|
349
|
-
* (duration: the child's, or the time since the dispatch) and fires `tool.postExecute`, through
|
|
350
|
-
* `fire()`, which the caller runs after its commit. Returns the steps and calls written (the
|
|
351
|
-
* caller must not write a "not executed" result for them) and the highest seq written.
|
|
352
|
-
*/
|
|
353
|
-
async stopOpenAgentCalls(runId, agent) {
|
|
354
|
-
const t = this.deps.db;
|
|
355
|
-
// phase D: the run's fork invocation without a report gets one (a fork has no tool call)
|
|
356
|
-
const forks = await pairStoppedForks(t, this.deps.eventLog, runId);
|
|
357
|
-
const none = {
|
|
358
|
-
steps: [],
|
|
359
|
-
callIds: new Set(forks.callIds),
|
|
360
|
-
toSeq: forks.toSeq,
|
|
361
|
-
fire: () => { },
|
|
362
|
-
};
|
|
363
|
-
const all = await t
|
|
364
|
-
.selectFrom("subagent_dispatches")
|
|
365
|
-
.select([
|
|
366
|
-
"parent_run_id",
|
|
367
|
-
"parent_call_id",
|
|
368
|
-
"parent_conversation_id",
|
|
369
|
-
"child_conversation_id",
|
|
370
|
-
"child_run_id",
|
|
371
|
-
"step",
|
|
372
|
-
"created_at",
|
|
373
|
-
])
|
|
374
|
-
.where("parent_run_id", "=", runId)
|
|
375
|
-
.orderBy("step")
|
|
376
|
-
.orderBy("created_at")
|
|
377
|
-
.execute();
|
|
378
|
-
const dispatches = all.filter((d) => forkSeqOfCall(d.parent_call_id, d.step) === null);
|
|
379
|
-
if (dispatches.length === 0)
|
|
380
|
-
return none;
|
|
381
|
-
const run = await t
|
|
382
|
-
.selectFrom("runs as r")
|
|
383
|
-
.innerJoin("conversations as c", "c.id", "r.conversation_id")
|
|
384
|
-
.select([
|
|
385
|
-
"r.conversation_id",
|
|
386
|
-
"r.trigger_account_id",
|
|
387
|
-
"r.agent_version",
|
|
388
|
-
"c.org_id",
|
|
389
|
-
"c.agent_id",
|
|
390
|
-
"c.kind",
|
|
391
|
-
])
|
|
392
|
-
.where("r.id", "=", runId)
|
|
393
|
-
.executeTakeFirst();
|
|
394
|
-
if (!run)
|
|
395
|
-
return none;
|
|
396
|
-
const conversationId = run.conversation_id;
|
|
397
|
-
const inputs = new Map();
|
|
398
|
-
// the logged key of each call (`agent` for a call dispatched before the rename, spec §9)
|
|
399
|
-
const names = new Map();
|
|
400
|
-
const events = [];
|
|
401
|
-
const calls = [];
|
|
402
|
-
for (const d of dispatches) {
|
|
403
|
-
const written = await t
|
|
404
|
-
.selectFrom("conversation_events")
|
|
405
|
-
.select("seq")
|
|
406
|
-
.where("conversation_id", "=", conversationId)
|
|
407
|
-
.where("idem_key", "=", idem.result(runId, d.parent_call_id))
|
|
408
|
-
.executeTakeFirst();
|
|
409
|
-
if (written)
|
|
410
|
-
continue;
|
|
411
|
-
if (!inputs.has(`step:${d.step}`)) {
|
|
412
|
-
inputs.set(`step:${d.step}`, true);
|
|
413
|
-
const msg = await t
|
|
414
|
-
.selectFrom("conversation_events")
|
|
415
|
-
.select("payload")
|
|
416
|
-
.where("conversation_id", "=", conversationId)
|
|
417
|
-
.where("idem_key", "=", assistantIdemKey(runId, d.step))
|
|
418
|
-
.executeTakeFirst();
|
|
419
|
-
const content = msg?.payload?.content ?? [];
|
|
420
|
-
for (const b of content) {
|
|
421
|
-
if (b.type === "tool_call" && b.id !== undefined) {
|
|
422
|
-
inputs.set(b.id, b.input);
|
|
423
|
-
if (b.name !== undefined)
|
|
424
|
-
names.set(b.id, b.name);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
const input = inputs.get(d.parent_call_id);
|
|
429
|
-
const row = {
|
|
430
|
-
parentRunId: d.parent_run_id,
|
|
431
|
-
parentCallId: d.parent_call_id,
|
|
432
|
-
parentConversationId: d.parent_conversation_id,
|
|
433
|
-
childConversationId: d.child_conversation_id,
|
|
434
|
-
childRunId: d.child_run_id,
|
|
435
|
-
};
|
|
436
|
-
const child = await t
|
|
437
|
-
.selectFrom("runs")
|
|
438
|
-
.select("status")
|
|
439
|
-
.where("id", "=", d.child_run_id)
|
|
440
|
-
.executeTakeFirst();
|
|
441
|
-
// a child that already ended keeps its own result (its log is committed)
|
|
442
|
-
const ended = child !== undefined && TERMINAL_STATUSES.has(child.status)
|
|
443
|
-
? await childResult(this.deps.eventLog, row, {
|
|
444
|
-
modelGiven: typeof input === "object" &&
|
|
445
|
-
input !== null &&
|
|
446
|
-
input.model !== undefined,
|
|
447
|
-
})
|
|
448
|
-
: null;
|
|
449
|
-
if (ended)
|
|
450
|
-
events.push(finishedEvent(row, ended.finished));
|
|
451
|
-
const r = ended
|
|
452
|
-
? { content: ended.content, isError: ended.isError, durationMs: ended.finished.durationMs }
|
|
453
|
-
: {
|
|
454
|
-
content: AGENT_STOPPED_WITH_RUN_TEXT,
|
|
455
|
-
isError: true,
|
|
456
|
-
durationMs: Math.max(0, Date.now() - new Date(d.created_at).getTime()),
|
|
457
|
-
};
|
|
458
|
-
events.push({
|
|
459
|
-
type: "tool_result",
|
|
460
|
-
runId,
|
|
461
|
-
idemKey: idem.result(runId, d.parent_call_id),
|
|
462
|
-
payload: {
|
|
463
|
-
step: d.step,
|
|
464
|
-
callId: d.parent_call_id,
|
|
465
|
-
toolKey: names.get(d.parent_call_id) ?? AGENT_TOOL,
|
|
466
|
-
content: r.content,
|
|
467
|
-
isError: r.isError,
|
|
468
|
-
},
|
|
469
|
-
});
|
|
470
|
-
calls.push({ step: d.step, callId: d.parent_call_id, input, r });
|
|
471
|
-
}
|
|
472
|
-
if (calls.length === 0)
|
|
473
|
-
return none;
|
|
474
|
-
const written = await this.deps.eventLog.appendIn(conversationId, events);
|
|
475
|
-
for (const c of calls) {
|
|
476
|
-
const approval = await t
|
|
477
|
-
.selectFrom("approvals")
|
|
478
|
-
.select(["id", "status", "decided_by", "scope"])
|
|
479
|
-
.where("run_id", "=", runId)
|
|
480
|
-
.where("call_id", "=", c.callId)
|
|
481
|
-
.orderBy("attempt", "desc")
|
|
482
|
-
.limit(1)
|
|
483
|
-
.executeTakeFirst();
|
|
484
|
-
await audit(t, {
|
|
485
|
-
actorAccountId: run.trigger_account_id,
|
|
486
|
-
orgId: run.org_id,
|
|
487
|
-
action: "tool.called",
|
|
488
|
-
target: conversationId,
|
|
489
|
-
detail: {
|
|
490
|
-
toolKey: AGENT_TOOL,
|
|
491
|
-
isError: c.r.isError,
|
|
492
|
-
durationMs: c.r.durationMs,
|
|
493
|
-
agentId: run.agent_id,
|
|
494
|
-
agentVersion: run.agent_version,
|
|
495
|
-
conversationId,
|
|
496
|
-
runId,
|
|
497
|
-
callId: c.callId,
|
|
498
|
-
...(approval?.status === "approved" && {
|
|
499
|
-
approvalId: approval.id,
|
|
500
|
-
approvedByAccountId: approval.decided_by,
|
|
501
|
-
scope: approval.scope,
|
|
502
|
-
}),
|
|
503
|
-
},
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
const fire = () => {
|
|
507
|
-
const hooks = this.deps.pluginHooks;
|
|
508
|
-
const scope = hookScope(hooks, {
|
|
509
|
-
conversationKind: run.kind,
|
|
510
|
-
orgId: run.org_id,
|
|
511
|
-
accountId: run.trigger_account_id,
|
|
512
|
-
agentId: run.agent_id,
|
|
513
|
-
agentVersion: run.agent_version,
|
|
514
|
-
conversationId,
|
|
515
|
-
runId,
|
|
516
|
-
});
|
|
517
|
-
if (!hooks || !scope || !hooks.has("tool.postExecute"))
|
|
518
|
-
return;
|
|
519
|
-
void (async () => {
|
|
520
|
-
const def = agent ??
|
|
521
|
-
normalizeStoredDefinition((await this.deps.db
|
|
522
|
-
.selectFrom("agent_versions")
|
|
523
|
-
.select("definition")
|
|
524
|
-
.where("agent_id", "=", run.agent_id)
|
|
525
|
-
.where("version", "=", run.agent_version)
|
|
526
|
-
.executeTakeFirstOrThrow()).definition);
|
|
527
|
-
const skillLoad = await skillLoadOfferedIn(this.deps.db, this.deps.eventLog, conversationId);
|
|
528
|
-
const resolved = await this.deps.registry.forAgent(run.org_id, {
|
|
529
|
-
tools: def.tools ?? [],
|
|
530
|
-
skillLoad,
|
|
531
|
-
subagents: def.subagents,
|
|
532
|
-
});
|
|
533
|
-
const tool = resolved.tools.find((x) => x.key === AGENT_TOOL);
|
|
534
|
-
if (!tool)
|
|
535
|
-
return;
|
|
536
|
-
// the run is over: nothing aborts these observe hooks but their own timeouts
|
|
537
|
-
const signal = new AbortController().signal;
|
|
538
|
-
for (const c of calls) {
|
|
539
|
-
fireObserve(hooks, "tool.postExecute", {
|
|
540
|
-
...scope,
|
|
541
|
-
step: c.step,
|
|
542
|
-
callId: c.callId,
|
|
543
|
-
toolKey: AGENT_TOOL,
|
|
544
|
-
specHash: tool.specHash,
|
|
545
|
-
input: c.input,
|
|
546
|
-
isError: c.r.isError,
|
|
547
|
-
content: c.r.content,
|
|
548
|
-
durationMs: c.r.durationMs,
|
|
549
|
-
}, signal, this.deps.log);
|
|
550
|
-
}
|
|
551
|
-
})().catch((err) => this.deps.log.warn("cannot fire tool.postExecute for stopped agent calls", { runId, err }));
|
|
552
|
-
};
|
|
553
|
-
return {
|
|
554
|
-
steps: [...new Set(calls.map((c) => c.step))],
|
|
555
|
-
callIds: new Set([...forks.callIds, ...calls.map((c) => c.callId)]),
|
|
556
|
-
toSeq: Math.max(forks.toSeq ?? 0, ...written.map((e) => e.seq)),
|
|
557
|
-
fire,
|
|
558
|
-
};
|
|
273
|
+
async stopOpenAgentCalls(runId) {
|
|
274
|
+
const forks = await pairStoppedForks(this.deps.db, this.deps.eventLog, runId);
|
|
275
|
+
return { steps: [], callIds: new Set(forks.callIds), toSeq: forks.toSeq, fire: () => { } };
|
|
559
276
|
}
|
|
560
277
|
/**
|
|
561
278
|
* 处理一个尚无结果的调用。先看输入请求的轮次:最近一轮仍 pending → 继续等;否则本次是第
|
|
@@ -640,9 +357,10 @@ let ToolPipeline = class ToolPipeline {
|
|
|
640
357
|
if (sent !== null && !sent.has(tool.key))
|
|
641
358
|
return fail(notLoadedText(tool.key), outKey);
|
|
642
359
|
}
|
|
360
|
+
const rawInput = legacy ? legacyToolInput(call.name, call.input) : call.input;
|
|
643
361
|
let input;
|
|
644
362
|
try {
|
|
645
|
-
input = await resolveOutputRefs(
|
|
363
|
+
input = await resolveOutputRefs(rawInput, (id) => this.deps.outputs.load({ orgId: ctx.orgId, conversationId: ctx.conversationId }, id));
|
|
646
364
|
}
|
|
647
365
|
catch (e) {
|
|
648
366
|
if (e instanceof ToolError)
|
|
@@ -656,6 +374,21 @@ let ToolPipeline = class ToolPipeline {
|
|
|
656
374
|
});
|
|
657
375
|
if (invalid !== null)
|
|
658
376
|
return fail(invalid, outKey);
|
|
377
|
+
// the per-call policy key (Platform tool spec §6.2): key and summary come from the resolved
|
|
378
|
+
// input, while the approval binding below compares the raw call.input
|
|
379
|
+
const callPolicy = (await tool.callPolicy?.(input, {
|
|
380
|
+
orgId: ctx.orgId,
|
|
381
|
+
accountId: ctx.accountId,
|
|
382
|
+
agentId: ctx.agentId,
|
|
383
|
+
conversationId: ctx.conversationId,
|
|
384
|
+
runId: ctx.runId,
|
|
385
|
+
rawInput,
|
|
386
|
+
})) ?? null;
|
|
387
|
+
// a deny with a reason (e.g. an unavailable operation): the reason is the tool error
|
|
388
|
+
if (callPolicy?.policy === "deny" && callPolicy.denyReason !== undefined) {
|
|
389
|
+
return fail(callPolicy.denyReason, outKey);
|
|
390
|
+
}
|
|
391
|
+
const policyKey = callPolicy?.key ?? tool.key;
|
|
659
392
|
const decision = await this.decide(tool, ctx.agent, {
|
|
660
393
|
orgId: ctx.orgId,
|
|
661
394
|
accountId: ctx.accountId,
|
|
@@ -664,11 +397,13 @@ let ToolPipeline = class ToolPipeline {
|
|
|
664
397
|
runId: ctx.runId,
|
|
665
398
|
...(ctx.parent !== undefined && {
|
|
666
399
|
parentConversationId: ctx.parent.conversationId,
|
|
400
|
+
rootConversationId: ctx.parent.rootConversationId,
|
|
667
401
|
...(ctx.parent.otherAgent !== undefined && { parentAgentDiffers: ctx.parent.otherAgent }),
|
|
668
402
|
}),
|
|
403
|
+
callPolicy,
|
|
669
404
|
});
|
|
670
405
|
if (decision === "deny")
|
|
671
|
-
return fail(deniedText(tool.key), outKey);
|
|
406
|
+
return fail(deniedText(tool.key, callPolicy?.key), outKey);
|
|
672
407
|
if (typeof decision === "object" && "unavailable" in decision) {
|
|
673
408
|
return fail(unavailableText(tool.key, decision.unavailable), outKey);
|
|
674
409
|
}
|
|
@@ -679,7 +414,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
679
414
|
// An in-flight rc call (spec §9) is the exception: its approval was asked under the rc definition
|
|
680
415
|
// of the same call, and the rename changed every builtin's definition; the person approved this
|
|
681
416
|
// very call, so the approval stands.
|
|
682
|
-
|
|
417
|
+
// An approval binds the exact input it showed (Platform tool spec §6.3): an approved record
|
|
418
|
+
// whose stored input differs from the call's is not used.
|
|
419
|
+
const approvedHere = approval?.status === "approved" &&
|
|
420
|
+
(legacy || approval.specHash === tool.specHash) &&
|
|
421
|
+
canonicalJson(approval.input) === canonicalJson(call.input ?? {});
|
|
683
422
|
const stale = approval?.status === "approved" && !approvedHere;
|
|
684
423
|
if ((!approval || stale) && typeof decision === "object" && "ask" in decision) {
|
|
685
424
|
approval = await this.deps.approvals.request({
|
|
@@ -689,13 +428,15 @@ let ToolPipeline = class ToolPipeline {
|
|
|
689
428
|
runId: ctx.runId,
|
|
690
429
|
step: ctx.step,
|
|
691
430
|
callId: call.id,
|
|
692
|
-
toolKey:
|
|
431
|
+
toolKey: policyKey,
|
|
693
432
|
specHash: decision.ask.specHash,
|
|
694
433
|
connectorId: decision.ask.connectorId,
|
|
695
434
|
input: call.input,
|
|
696
435
|
requestedFor: decision.ask.requestedFor,
|
|
697
436
|
approverRole: decision.ask.approverRole,
|
|
698
437
|
policy: decision.ask.policy,
|
|
438
|
+
...(callPolicy?.summary !== undefined && { summary: callPolicy.summary }),
|
|
439
|
+
...(callPolicy !== null && !callPolicy.remember && { scopes: ["once"] }),
|
|
699
440
|
});
|
|
700
441
|
}
|
|
701
442
|
if (approval && approval.status !== "approved") {
|
|
@@ -762,16 +503,72 @@ let ToolPipeline = class ToolPipeline {
|
|
|
762
503
|
return undefined;
|
|
763
504
|
}
|
|
764
505
|
}
|
|
765
|
-
// `Agent` (sub-agents spec §7.1): no tool_call_started;
|
|
766
|
-
//
|
|
506
|
+
// `Agent` (sub-agents spec §7.1, agent map spec §4.1): no tool_call_started; one transaction
|
|
507
|
+
// makes the dispatch durable (its marker is the subagent_dispatches row) and writes the call's
|
|
508
|
+
// immediate result, while the sub-agent runs in the background
|
|
767
509
|
const dispatcher = this.deps.subagents;
|
|
768
510
|
if (tool.source.kind === "builtin" && tool.key === AGENT_TOOL && dispatcher) {
|
|
769
511
|
const parsed = AgentToolInput.safeParse(input);
|
|
770
512
|
if (!parsed.success) {
|
|
771
|
-
return fail("Invalid agent call: pass description and prompt, and optionally subagent_type
|
|
513
|
+
return fail("Invalid agent call: pass description and prompt, and optionally subagent_type and model.", outKey);
|
|
514
|
+
}
|
|
515
|
+
const r = await dispatcher.dispatch({
|
|
516
|
+
ctx,
|
|
517
|
+
callId: call.id,
|
|
518
|
+
input: parsed.data,
|
|
519
|
+
call: { toolKey: outKey, authorization, startedAt: Date.now() },
|
|
520
|
+
});
|
|
521
|
+
if (r.kind === "refused")
|
|
522
|
+
return fail(r.content, outKey);
|
|
523
|
+
if (hooks && hookBase) {
|
|
524
|
+
fireObserve(hooks, "tool.postExecute", {
|
|
525
|
+
...hookBase,
|
|
526
|
+
isError: false,
|
|
527
|
+
content: r.content,
|
|
528
|
+
durationMs: 0,
|
|
529
|
+
}, ctx.signal, this.deps.log);
|
|
530
|
+
}
|
|
531
|
+
return undefined;
|
|
532
|
+
}
|
|
533
|
+
// `SendMessage` and `SubagentHandback` (agent map spec §4.2, §4.3): no tool_call_started; each
|
|
534
|
+
// write is idempotent by the call (the message in the sub-agent's log, the delivery in the
|
|
535
|
+
// parent's), so a call retried after a crash sends nothing twice. A send that starts an idle
|
|
536
|
+
// sub-agent writes its result with the dispatch, like `Agent`
|
|
537
|
+
const messenger = this.deps.messages;
|
|
538
|
+
if (tool.source.kind === "builtin" &&
|
|
539
|
+
(tool.key === SEND_MESSAGE || tool.key === SUBAGENT_HANDBACK) &&
|
|
540
|
+
messenger) {
|
|
541
|
+
const t0 = Date.now();
|
|
542
|
+
let r;
|
|
543
|
+
if (tool.key === SEND_MESSAGE) {
|
|
544
|
+
const parsed = SendMessageInput.safeParse(input);
|
|
545
|
+
if (!parsed.success) {
|
|
546
|
+
return fail("Invalid SendMessage call: pass to and message.", outKey);
|
|
547
|
+
}
|
|
548
|
+
r = await messenger.toChild(ctx, call.id, parsed.data.to, parsed.data.message, {
|
|
549
|
+
authorization,
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
const parsed = HandbackInput.safeParse(input);
|
|
554
|
+
if (!parsed.success)
|
|
555
|
+
return fail("Invalid SubagentHandback call: pass message.", outKey);
|
|
556
|
+
r = await messenger.toParent(ctx, "report", parsed.data.message, call.id);
|
|
557
|
+
}
|
|
558
|
+
if (r.isError)
|
|
559
|
+
return fail(r.content, outKey);
|
|
560
|
+
const durationMs = Date.now() - t0;
|
|
561
|
+
if (r.logged !== true) {
|
|
562
|
+
await this.writeResult(ctx, call.id, outKey, { content: r.content, isError: false }, [], {
|
|
563
|
+
durationMs,
|
|
564
|
+
connectorId: null,
|
|
565
|
+
authorization,
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
if (hooks && hookBase) {
|
|
569
|
+
fireObserve(hooks, "tool.postExecute", { ...hookBase, isError: false, content: r.content, durationMs }, ctx.signal, this.deps.log);
|
|
772
570
|
}
|
|
773
|
-
|
|
774
|
-
return r.kind === "refused" ? fail(r.content, outKey) : OPEN;
|
|
571
|
+
return undefined;
|
|
775
572
|
}
|
|
776
573
|
await this.deps.eventLog.append(ctx.conversationId, [
|
|
777
574
|
{
|
|
@@ -852,24 +649,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
852
649
|
connectorId: tool.source.kind === "connector" ? tool.source.connectorId : null,
|
|
853
650
|
authorization,
|
|
854
651
|
});
|
|
855
|
-
// a sub-agent that needs a personal connection: mirrored in the
|
|
856
|
-
// not a wait, the child got the connect
|
|
652
|
+
// a sub-agent that needs a personal connection: mirrored in the root conversation of its tree
|
|
653
|
+
// for display (sub-agents spec §9, agent map spec §7; not a wait, the child got the connect
|
|
654
|
+
// text as its result)
|
|
857
655
|
if (outcome.kind === "connection_required" && ctx.parent !== undefined) {
|
|
858
|
-
await this.deps.
|
|
859
|
-
.append(ctx.parent.conversationId, [
|
|
860
|
-
{
|
|
861
|
-
type: "subagent_waiting",
|
|
862
|
-
runId: ctx.parent.runId,
|
|
863
|
-
idemKey: subagentWaitingIdemKey(ctx.runId, `connect-${call.id}`),
|
|
864
|
-
payload: {
|
|
865
|
-
subagentId: ctx.conversationId,
|
|
866
|
-
childRunId: ctx.runId,
|
|
867
|
-
kind: "connect",
|
|
868
|
-
toolKey: tool.key,
|
|
869
|
-
},
|
|
870
|
-
},
|
|
871
|
-
])
|
|
872
|
-
.catch((err) => this.deps.log.warn("cannot surface a sub-agent's connect card in its parent", {
|
|
656
|
+
await this.surfaceConnectInRoot(ctx, ctx.parent, call.id, tool.key).catch((err) => this.deps.log.warn("cannot surface a sub-agent's connect card in its root conversation", {
|
|
873
657
|
runId: ctx.runId,
|
|
874
658
|
err,
|
|
875
659
|
}));
|
|
@@ -879,6 +663,26 @@ let ToolPipeline = class ToolPipeline {
|
|
|
879
663
|
}
|
|
880
664
|
return undefined;
|
|
881
665
|
}
|
|
666
|
+
/** Appends a sub-agent's connect card to its root conversation ({@link rootSurfaceOf}). */
|
|
667
|
+
async surfaceConnectInRoot(ctx, parent, callId, toolKey) {
|
|
668
|
+
const target = await rootSurfaceOf(this.deps.db, ctx.conversationId, ctx.runId, parent);
|
|
669
|
+
if (!target)
|
|
670
|
+
return;
|
|
671
|
+
await this.deps.eventLog.append(target.conversationId, [
|
|
672
|
+
{
|
|
673
|
+
type: "subagent_waiting",
|
|
674
|
+
runId: target.runId,
|
|
675
|
+
idemKey: subagentWaitingIdemKey(ctx.runId, `connect-${callId}`),
|
|
676
|
+
payload: {
|
|
677
|
+
subagentId: ctx.conversationId,
|
|
678
|
+
childRunId: ctx.runId,
|
|
679
|
+
path: target.path,
|
|
680
|
+
kind: "connect",
|
|
681
|
+
toolKey,
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
]);
|
|
685
|
+
}
|
|
882
686
|
/**
|
|
883
687
|
* Every tool key the request that issued this step's calls offered (`request.tools` plus the
|
|
884
688
|
* `catalog` keys), in any mode; null when its model_call is not found. Used to tell a call to an
|
|
@@ -982,14 +786,48 @@ let ToolPipeline = class ToolPipeline {
|
|
|
982
786
|
...(tool.source.kind === "builtin" && { runId: ctx.runId }),
|
|
983
787
|
...(tool.source.kind === "builtin" &&
|
|
984
788
|
ctx.deadline !== undefined && { runDeadline: ctx.deadline }),
|
|
985
|
-
// a sub-agent works in its
|
|
789
|
+
// a sub-agent works in its root conversation's sandbox (spec §10.1, at every depth)
|
|
986
790
|
...(tool.source.kind === "builtin" &&
|
|
987
|
-
ctx.parent !== undefined && { sandboxConversationId: ctx.parent.
|
|
791
|
+
ctx.parent !== undefined && { sandboxConversationId: ctx.parent.rootConversationId }),
|
|
792
|
+
...(tool.source.kind === "builtin" &&
|
|
793
|
+
ctx.parent !== undefined && { parentRunId: ctx.parent.runId }),
|
|
794
|
+
...(tool.source.kind === "builtin" &&
|
|
795
|
+
ctx.parent?.budgetRunId !== undefined && { budgetRunId: ctx.parent.budgetRunId }),
|
|
796
|
+
// the hook scope of a builtin's own model call (the WebFetch extraction)
|
|
797
|
+
...(tool.source.kind === "builtin" && {
|
|
798
|
+
step: ctx.step,
|
|
799
|
+
agentVersion: ctx.agentVersion,
|
|
800
|
+
...(ctx.conversationKind !== undefined && { conversationKind: ctx.conversationKind }),
|
|
801
|
+
...(ctx.parent !== undefined && {
|
|
802
|
+
parent: {
|
|
803
|
+
conversationId: ctx.parent.conversationId,
|
|
804
|
+
runId: ctx.parent.runId,
|
|
805
|
+
callId: ctx.parent.callId,
|
|
806
|
+
},
|
|
807
|
+
}),
|
|
808
|
+
}),
|
|
988
809
|
};
|
|
989
810
|
// 内置工具可按输入给自己的时限(沙箱 bash 按命令超时加余量);缺省 tools.timeoutMs
|
|
990
811
|
const timeoutMs = tool.timeoutMs?.(input) ?? this.config.get().tools.timeoutMs;
|
|
991
812
|
try {
|
|
992
|
-
|
|
813
|
+
// a plugin tool runs with the extension's effective config for the org, never without it
|
|
814
|
+
// (layering spec A §6): one read per call, cached by EffectiveConfigs
|
|
815
|
+
let config = {};
|
|
816
|
+
if (tool.source.kind === "plugin") {
|
|
817
|
+
// turned off in the org since the step resolved its tools (spec A §7)
|
|
818
|
+
if (await this.deps.switches.isToolOff(ctx.orgId, tool.source.plugin, tool.source.name)) {
|
|
819
|
+
return { kind: "error", message: `${toolTurnedOffReason(tool.key)}.` };
|
|
820
|
+
}
|
|
821
|
+
const effective = await this.deps.effective.get(ctx.orgId, tool.source.plugin);
|
|
822
|
+
if (!effective.ok) {
|
|
823
|
+
// unloaded or disabled since the step resolved its tools: the documented unloaded error
|
|
824
|
+
if (effective.notRunning)
|
|
825
|
+
return { kind: "error", message: PLUGIN_UNLOADED_TOOL_ERROR };
|
|
826
|
+
return { kind: "error", message: unavailableText(tool.key, NEEDS_CONFIG_REASON) };
|
|
827
|
+
}
|
|
828
|
+
config = { config: effective.config };
|
|
829
|
+
}
|
|
830
|
+
const r = await this.bounded(ctx.signal, (signal) => handler(input, { ...base, ...config, signal }), undefined, timeoutMs);
|
|
993
831
|
if (r === "timeout") {
|
|
994
832
|
return { kind: "error", message: timeoutText(tool.key, timeoutMs) };
|
|
995
833
|
}
|
|
@@ -1344,9 +1182,6 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1344
1182
|
return out;
|
|
1345
1183
|
}
|
|
1346
1184
|
};
|
|
1347
|
-
__decorate([
|
|
1348
|
-
Transactional()
|
|
1349
|
-
], ToolPipeline.prototype, "stopOpenAgentCallsNow", null);
|
|
1350
1185
|
__decorate([
|
|
1351
1186
|
Transactional({ propagation: "mandatory" })
|
|
1352
1187
|
], ToolPipeline.prototype, "stopOpenAgentCalls", null);
|
|
@@ -1358,18 +1193,21 @@ ToolPipeline = __decorate([
|
|
|
1358
1193
|
__param(0, Inject(KernelDb)),
|
|
1359
1194
|
__param(1, Inject(EventLog)),
|
|
1360
1195
|
__param(2, Inject(SubagentsService)),
|
|
1361
|
-
__param(3, Inject(
|
|
1362
|
-
__param(4, Inject(
|
|
1363
|
-
__param(5, Inject(
|
|
1364
|
-
__param(6, Inject(
|
|
1365
|
-
__param(7, Inject(
|
|
1366
|
-
__param(8, Inject(
|
|
1367
|
-
__param(9, Inject(
|
|
1368
|
-
__param(10, Inject(
|
|
1369
|
-
__param(11, Inject(
|
|
1370
|
-
__param(12, Inject(
|
|
1371
|
-
__param(13, Inject(
|
|
1372
|
-
__param(14,
|
|
1373
|
-
__param(
|
|
1196
|
+
__param(3, Inject(SubagentMessages)),
|
|
1197
|
+
__param(4, Inject(ToolRegistry)),
|
|
1198
|
+
__param(5, Inject(Credentials)),
|
|
1199
|
+
__param(6, Inject(Breaker)),
|
|
1200
|
+
__param(7, Inject(ToolOutputs)),
|
|
1201
|
+
__param(8, Inject(ApprovalsService)),
|
|
1202
|
+
__param(9, Inject(QuestionsService)),
|
|
1203
|
+
__param(10, Inject(KernelConfigService)),
|
|
1204
|
+
__param(11, Inject(KERNEL_LOGGER)),
|
|
1205
|
+
__param(12, Inject(ExtensionHost)),
|
|
1206
|
+
__param(13, Inject(ToolDrift)),
|
|
1207
|
+
__param(14, Inject(EffectiveConfigs)),
|
|
1208
|
+
__param(15, Inject(OrgToolSwitches)),
|
|
1209
|
+
__param(16, Inject(TransactionHost)),
|
|
1210
|
+
__param(17, Optional()),
|
|
1211
|
+
__param(17, Inject(TOOL_PIPELINE_HOOKS))
|
|
1374
1212
|
], ToolPipeline);
|
|
1375
1213
|
export { ToolPipeline };
|