@capybara-hq/kernel 0.1.0-rc.4 → 0.1.0-rc.6
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 +51 -14
- package/dist/admin/admin.controller.js +60 -19
- package/dist/admin/extensions.controller.d.ts +16 -2
- package/dist/admin/extensions.controller.js +26 -6
- 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 +16 -0
- package/dist/agents/agent-lookup.js +11 -0
- package/dist/agents/agents.controller.d.ts +76 -1
- package/dist/agents/agents.controller.js +90 -11
- package/dist/agents/agents.module.d.ts +4 -1
- package/dist/agents/agents.module.js +32 -6
- package/dist/agents/agents.service.d.ts +54 -23
- package/dist/agents/agents.service.js +180 -76
- package/dist/agents/definition.d.ts +49 -0
- package/dist/agents/definition.js +45 -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/models.controller.d.ts +34 -5
- package/dist/agents/models.controller.js +50 -6
- 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/readiness.controller.d.ts +5 -5
- package/dist/agents/readiness.controller.js +6 -6
- 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 +475 -52
- package/dist/background/background.module.js +8 -1
- package/dist/background/finish.d.ts +3 -2
- package/dist/background/launch-lock.d.ts +4 -3
- package/dist/background/launch-lock.js +4 -3
- package/dist/background/poll.job.d.ts +9 -6
- package/dist/background/poll.job.js +30 -22
- package/dist/background/session.d.ts +13 -2
- package/dist/background/session.js +13 -0
- package/dist/background/stop.d.ts +12 -6
- package/dist/background/stop.js +57 -39
- package/dist/background/store.d.ts +18 -6
- package/dist/background/store.js +12 -6
- package/dist/background/tasks.service.d.ts +15 -5
- package/dist/background/tasks.service.js +42 -17
- package/dist/background/wake-rules.d.ts +27 -18
- package/dist/background/wake-rules.js +52 -22
- package/dist/background/wake.d.ts +13 -11
- package/dist/background/wake.js +20 -14
- 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/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 +622 -82
- 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 +1147 -1136
- 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 +20 -2
- package/dist/channels/channels.module.js +2 -0
- 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/config/docs.js +3 -1
- package/dist/config/schema.d.ts +10 -2
- package/dist/config/schema.js +70 -22
- package/dist/conversations/access.d.ts +6 -4
- package/dist/conversations/access.js +27 -5
- package/dist/conversations/agent-tree.d.ts +46 -0
- package/dist/conversations/agent-tree.js +92 -0
- package/dist/conversations/conversations.controller.d.ts +43 -18
- package/dist/conversations/conversations.controller.js +79 -38
- package/dist/conversations/conversations.module.d.ts +1 -1
- package/dist/conversations/conversations.module.js +7 -7
- package/dist/conversations/conversations.service.d.ts +73 -15
- package/dist/conversations/conversations.service.js +115 -35
- package/dist/conversations/environment-status.d.ts +24 -0
- package/dist/conversations/environment-status.js +71 -0
- package/dist/conversations/event-log.d.ts +20 -5
- package/dist/conversations/event-log.js +60 -0
- package/dist/conversations/events.d.ts +84 -2
- package/dist/conversations/events.js +91 -17
- package/dist/conversations/queue.service.d.ts +1 -1
- package/dist/conversations/queue.service.js +5 -0
- package/dist/conversations/titles.d.ts +5 -3
- package/dist/conversations/titles.js +21 -8
- package/dist/conversations/tree.d.ts +17 -0
- package/dist/conversations/tree.js +42 -0
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +38 -7
- package/dist/db/kernel-schema.d.ts +386 -18
- 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 +85 -2
- package/dist/errors.js +85 -2
- package/dist/evals/reconstruct.d.ts +18 -9
- package/dist/evals/reconstruct.js +26 -7
- package/dist/evals/run-replay.d.ts +4 -2
- package/dist/evals/run-replay.js +20 -6
- package/dist/evals/runs.service.d.ts +2 -1
- package/dist/evals/runs.service.js +13 -12
- package/dist/evals/step-replay.d.ts +4 -6
- package/dist/evals/step-replay.js +4 -3
- 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 +65 -42
- package/dist/extensions/admin-view.d.ts +37 -10
- package/dist/extensions/admin-view.js +103 -20
- 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-hash.d.ts +10 -0
- package/dist/extensions/config-hash.js +38 -0
- package/dist/extensions/deployment-config.d.ts +28 -5
- package/dist/extensions/deployment-config.js +48 -7
- package/dist/extensions/effective-config.d.ts +127 -0
- package/dist/extensions/effective-config.js +368 -0
- package/dist/extensions/extensions.module.js +11 -11
- package/dist/extensions/hooks.d.ts +37 -4
- package/dist/extensions/hooks.js +82 -16
- package/dist/extensions/host.d.ts +24 -10
- package/dist/extensions/host.js +49 -54
- package/dist/extensions/installs.d.ts +20 -8
- package/dist/extensions/installs.js +37 -15
- package/dist/extensions/org-config.d.ts +75 -6
- package/dist/extensions/org-config.js +184 -32
- 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/permission-view.d.ts +16 -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.d.ts +12 -5
- package/dist/extensions/point-defaults.js +37 -9
- package/dist/extensions/resolve.d.ts +5 -1
- package/dist/extensions/resolve.js +15 -2
- package/dist/extensions/state.module.d.ts +9 -0
- package/dist/extensions/state.module.js +38 -0
- package/dist/files/previewers.d.ts +8 -1
- package/dist/files/previewers.js +35 -6
- package/dist/http/api.module.js +25 -3
- package/dist/http/app.d.ts +11 -2
- package/dist/http/app.js +31 -5
- package/dist/http/plugin-dispatch.d.ts +4 -1
- package/dist/http/plugin-dispatch.js +14 -2
- 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.guard.d.ts +13 -5
- package/dist/identity/auth.guard.js +26 -9
- package/dist/identity/identity.module.d.ts +1 -1
- package/dist/identity/identity.module.js +4 -4
- package/dist/identity/me.controller.js +1 -1
- package/dist/identity/principal.d.ts +3 -3
- package/dist/identity/principal.js +3 -3
- 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 +1 -1
- package/dist/index.js +1 -1
- package/dist/infra/cli/kernel-cli.module.js +9 -1
- package/dist/infra/config/kernel-config.service.js +24 -1
- 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/queue/add-job-once.d.ts +14 -0
- package/dist/infra/queue/add-job-once.js +16 -0
- 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/models/embeddings.d.ts +82 -0
- package/dist/models/embeddings.js +326 -0
- package/dist/models/enablement.controller.d.ts +40 -0
- package/dist/models/enablement.controller.js +74 -0
- package/dist/models/enablement.d.ts +99 -0
- package/dist/models/enablement.js +263 -0
- package/dist/models/models.module.d.ts +5 -1
- package/dist/models/models.module.js +16 -4
- 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 +37 -12
- package/dist/models/purposes.js +63 -17
- package/dist/orgs/directory-sync.d.ts +14 -5
- package/dist/orgs/directory-sync.js +41 -17
- package/dist/orgs/offboarding.d.ts +9 -7
- package/dist/orgs/offboarding.js +28 -17
- 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 +15 -3
- package/dist/orgs/settings.service.js +6 -2
- 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 +1405 -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 +9 -1
- package/dist/runtime/context/build.d.ts +6 -4
- package/dist/runtime/context/build.js +26 -7
- package/dist/runtime/context/claude-tools.d.ts +2 -1
- package/dist/runtime/context/claude-tools.js +5 -4
- package/dist/runtime/context/compaction.js +9 -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.d.ts +8 -1
- package/dist/runtime/hook-calls.js +40 -7
- package/dist/runtime/langgraph-loop.d.ts +3 -1
- package/dist/runtime/langgraph-loop.js +35 -17
- package/dist/runtime/loop.d.ts +32 -4
- package/dist/runtime/maintenance.d.ts +7 -4
- package/dist/runtime/maintenance.js +23 -8
- package/dist/runtime/model-call.d.ts +38 -11
- package/dist/runtime/model-call.js +97 -24
- package/dist/runtime/providers.d.ts +146 -32
- package/dist/runtime/providers.js +321 -67
- 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 +37 -3
- package/dist/runtime/run-queue.js +188 -11
- package/dist/runtime/run-worker.d.ts +12 -6
- package/dist/runtime/run-worker.js +58 -35
- package/dist/runtime/runtime.module.js +3 -0
- package/dist/runtime/step-log.d.ts +9 -4
- package/dist/runtime/step-log.js +8 -5
- 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 +46 -32
- 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-jobs.d.ts +88 -0
- package/dist/runtime/usage-report-jobs.js +158 -0
- package/dist/runtime/usage-report.d.ts +33 -38
- package/dist/runtime/usage-report.js +169 -96
- package/dist/runtime/waits.d.ts +140 -37
- package/dist/runtime/waits.js +394 -106
- 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 +4 -3
- package/dist/sandbox/sandbox.service.d.ts +229 -134
- package/dist/sandbox/sandbox.service.js +630 -409
- 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 +23 -4
- package/dist/tools/builtin-names.d.ts +21 -5
- package/dist/tools/builtin-names.js +30 -5
- 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 +6 -2
- package/dist/tools/builtins/builtin-tools.js +37 -12
- 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.js +13 -3
- package/dist/tools/builtins/sandbox/common.d.ts +43 -24
- package/dist/tools/builtins/sandbox/common.js +80 -45
- 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 +1 -1
- package/dist/tools/builtins/sandbox/index.js +1 -1
- package/dist/tools/builtins/sandbox/read.js +1 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +14 -3
- package/dist/tools/builtins/sandbox/task-output.js +30 -5
- package/dist/tools/builtins/sandbox/task-stop.js +2 -1
- 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/extract.js +5 -1
- package/dist/tools/builtins/web/fetch.js +1 -0
- package/dist/tools/builtins/web/search.js +1 -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/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 +193 -364
- package/dist/tools/policy.d.ts +1 -1
- package/dist/tools/policy.js +36 -16
- package/dist/tools/registry.d.ts +98 -5
- package/dist/tools/registry.js +87 -9
- package/dist/tools/tools.module.js +12 -2
- package/dist/ui/views.d.ts +2 -1
- package/dist/ui/views.js +17 -3
- package/package.json +3 -3
- 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/src/migrations/0089_model_kinds_usage.sql +38 -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 -32
- package/dist/extensions/org-config.controller.js +0 -70
package/dist/tools/pipeline.js
CHANGED
|
@@ -9,9 +9,10 @@ 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 { ApiError } from "../errors.js";
|
|
15
|
+
import { EffectiveConfigs, NEEDS_CONFIG_REASON } from "../extensions/effective-config.js";
|
|
15
16
|
import { clipText } from "../extensions/hooks.js";
|
|
16
17
|
import { ExtensionHost } from "../extensions/host.js";
|
|
17
18
|
import { ExtensionUnloadedError, PLUGIN_UNLOADED_TOOL_ERROR } from "../extensions/inflight.js";
|
|
@@ -23,22 +24,26 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
23
24
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
24
25
|
import { UNKNOWN_RESULT_TEXT } from "../runtime/context/pairing.js";
|
|
25
26
|
import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookScope, } from "../runtime/hook-calls.js";
|
|
26
|
-
import {
|
|
27
|
+
import { subagentWaitingIdemKey } from "../runtime/loop.js";
|
|
27
28
|
import { assistantIdemKey, MAX_MODEL_ATTEMPTS, modelCallIdemKey } from "../runtime/model-call.js";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
29
|
+
import { rootSurfaceOf } from "../runtime/subagents/child.js";
|
|
30
|
+
import { SubagentMessages } from "../runtime/subagents/messages.js";
|
|
31
|
+
import { pairStoppedForks } from "../runtime/subagents/skill-fork.js";
|
|
31
32
|
import { SubagentsService } from "../runtime/subagents/subagents.service.js";
|
|
32
33
|
import { skillLoadOfferedIn } from "../skills/catalog.js";
|
|
33
34
|
import { ApprovalsService } from "./approvals.service.js";
|
|
34
35
|
import { Breaker, breakerOpenMessage } from "./breaker.js";
|
|
35
|
-
import { TOOL_SEARCH } from "./builtin-names.js";
|
|
36
|
-
import {
|
|
36
|
+
import { SEND_MESSAGE, SUBAGENT_HANDBACK, TOOL_SEARCH } from "./builtin-names.js";
|
|
37
|
+
import { AGENT_TOOL, AgentToolInput } from "./builtins/agent.js";
|
|
38
|
+
import { HandbackInput } from "./builtins/handback.js";
|
|
39
|
+
import { SendMessageInput } from "./builtins/send-message.js";
|
|
37
40
|
import { isAlwaysLoaded, notLoadedText } from "./builtins/tool-search.js";
|
|
41
|
+
import { canonicalJson } from "./canonical-json.js";
|
|
38
42
|
import { CredentialMissing, Credentials } from "./credentials.js";
|
|
39
43
|
import { ToolDrift } from "./drift.js";
|
|
40
44
|
import { ElicitationSession } from "./elicitation.js";
|
|
41
45
|
import { legacyHint, legacyToolInput, legacyToolKey } from "./legacy-keys.js";
|
|
46
|
+
import { OrgToolSwitches, toolTurnedOffReason } from "./org-tool-switches.js";
|
|
42
47
|
import { renderResult, resolveOutputRefs, spillIfLarge, ToolOutputs } from "./outputs.js";
|
|
43
48
|
import { createDecidePolicy } from "./policy.js";
|
|
44
49
|
import { QuestionsService } from "./questions.service.js";
|
|
@@ -69,11 +74,6 @@ export const RUN_STOPPED_TEXT = "The run was stopped before this tool call was e
|
|
|
69
74
|
export const RUN_STOPPED_DURING_TEXT = "The run was stopped while this tool call was running; its outcome is unknown. Verify before retrying.";
|
|
70
75
|
const timeoutText = (key, ms) => `Tool ${key} timed out after ${ms / 1000}s. The operation may or may not have completed; verify before retrying.`;
|
|
71
76
|
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
77
|
/** The connector slugs and extension names among the run's tools (to read old `<x>__<tool>` keys). */
|
|
78
78
|
const legacyScopeOf = (tools) => {
|
|
79
79
|
const connectorSlugs = new Set();
|
|
@@ -91,7 +91,10 @@ const unknownToolText = (name, keys, toolSearch, hint = null) => `Unknown tool "
|
|
|
91
91
|
(toolSearch ? " Use ToolSearch to load other tools." : "") +
|
|
92
92
|
(hint === null ? "" : ` ${hint}`);
|
|
93
93
|
const unavailableText = (name, reason) => `Tool "${name}" is unavailable: ${reason}.`;
|
|
94
|
-
|
|
94
|
+
/** With a per-call policy key (`Platform:<operation>`), the text names it. */
|
|
95
|
+
const deniedText = (key, policyKey) => policyKey === undefined || policyKey === key
|
|
96
|
+
? `Tool ${key} is denied by policy.`
|
|
97
|
+
: `Tool ${key} is denied by policy for ${policyKey}.`;
|
|
95
98
|
/** Longest hook reason quoted in {@link hookDeniedText}. */
|
|
96
99
|
const HOOK_REASON_MAX = 500;
|
|
97
100
|
/**
|
|
@@ -105,8 +108,6 @@ const personalMissingText = (connectorName) => `The user has not connected ${con
|
|
|
105
108
|
const orgMissingText = (connectorName) => `${connectorName} has no organization credential configured; ask an organization admin to set it up.`;
|
|
106
109
|
/** Optional provider: the pipeline's {@link ToolPipelineHooks} (tests). */
|
|
107
110
|
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
111
|
const approvalAuthorization = (a) => ({
|
|
111
112
|
approvalId: a.id,
|
|
112
113
|
approvedByAccountId: a.decidedBy,
|
|
@@ -181,9 +182,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
181
182
|
deps;
|
|
182
183
|
constructor(kdb, eventLog,
|
|
183
184
|
/** The `Agent` tool's sub-agent dispatch; absent (tests): `Agent` calls are refused. */
|
|
184
|
-
subagents,
|
|
185
|
+
subagents,
|
|
186
|
+
/** The message tools between agents; absent (tests): their calls are refused. */
|
|
187
|
+
messages, registry, credentials, breaker, outputs, approvals, questions, config, log,
|
|
185
188
|
/** Plugin hooks and inline ui contributions; absent (tests): no hooks, cards dropped. */
|
|
186
|
-
host, drift, txHost, hooks) {
|
|
189
|
+
host, drift, effective, switches, txHost, hooks) {
|
|
187
190
|
this.config = config;
|
|
188
191
|
this.txHost = txHost;
|
|
189
192
|
this.deps = {
|
|
@@ -202,6 +205,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
202
205
|
get pluginHooks() {
|
|
203
206
|
return host?.hooks;
|
|
204
207
|
},
|
|
208
|
+
effective,
|
|
209
|
+
switches,
|
|
205
210
|
inlineViews: (plugin) => new Set((host?.current(plugin)?.manifest.ui ?? [])
|
|
206
211
|
.filter((c) => c.place === "inline" && c.aliasOf === undefined)
|
|
207
212
|
.map((c) => c.id)),
|
|
@@ -211,6 +216,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
211
216
|
get subagents() {
|
|
212
217
|
return subagents ? { dispatch: (a) => subagents.dispatch(a) } : undefined;
|
|
213
218
|
},
|
|
219
|
+
messages,
|
|
214
220
|
};
|
|
215
221
|
const decide = hooks?.decidePolicy;
|
|
216
222
|
// the default policy reads live, on the context's handle
|
|
@@ -240,322 +246,34 @@ let ToolPipeline = class ToolPipeline {
|
|
|
240
246
|
tools: ctx.agent.tools ?? [],
|
|
241
247
|
skillLoad,
|
|
242
248
|
subagents: ctx.agent.subagents,
|
|
249
|
+
child: ctx.parent !== undefined,
|
|
250
|
+
forkChild: ctx.parent?.forSkill === true,
|
|
243
251
|
});
|
|
244
252
|
}
|
|
245
253
|
return resolved;
|
|
246
254
|
};
|
|
247
|
-
// `Agent`
|
|
248
|
-
//
|
|
249
|
-
let open = 0;
|
|
255
|
+
// an `Agent` call's dispatch writes its result (the sub-agent runs in the background, agent
|
|
256
|
+
// map spec §4.1), so no call keeps the step waiting on a sub-agent
|
|
250
257
|
for (const call of calls) {
|
|
251
258
|
if (await eventLog.findByIdem(ctx.conversationId, idem.result(ctx.runId, call.id)))
|
|
252
259
|
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
260
|
const waitingFor = await this.processCall(ctx, call, resolve);
|
|
262
|
-
if (waitingFor
|
|
263
|
-
open++;
|
|
264
|
-
else if (waitingFor)
|
|
261
|
+
if (waitingFor)
|
|
265
262
|
return { kind: "suspended", waitingFor };
|
|
266
263
|
}
|
|
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
264
|
return { kind: "done" };
|
|
285
265
|
}
|
|
286
266
|
/**
|
|
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).
|
|
267
|
+
* Writes, in the caller's transaction (`mandatory`), what a run that is being stopped (a person,
|
|
268
|
+
* its deadline, a failure, the wait sweep) still owes its log: the report of its fork invocation
|
|
269
|
+
* (phase D, `pairStoppedForks`; a still active fork child is stopped by the caller after its
|
|
270
|
+
* commit). An `Agent` call has its result from its dispatch (agent map spec §4.1), so there is
|
|
271
|
+
* nothing to write for it. Returns the fork's call id (the caller must not write a "not executed"
|
|
272
|
+
* result for it), the highest seq written, and `fire`, a no-op kept for the callers' hook phase.
|
|
295
273
|
*/
|
|
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
|
-
};
|
|
274
|
+
async stopOpenAgentCalls(runId) {
|
|
275
|
+
const forks = await pairStoppedForks(this.deps.db, this.deps.eventLog, runId);
|
|
276
|
+
return { steps: [], callIds: new Set(forks.callIds), toSeq: forks.toSeq, fire: () => { } };
|
|
559
277
|
}
|
|
560
278
|
/**
|
|
561
279
|
* 处理一个尚无结果的调用。先看输入请求的轮次:最近一轮仍 pending → 继续等;否则本次是第
|
|
@@ -640,9 +358,10 @@ let ToolPipeline = class ToolPipeline {
|
|
|
640
358
|
if (sent !== null && !sent.has(tool.key))
|
|
641
359
|
return fail(notLoadedText(tool.key), outKey);
|
|
642
360
|
}
|
|
361
|
+
const rawInput = legacy ? legacyToolInput(call.name, call.input) : call.input;
|
|
643
362
|
let input;
|
|
644
363
|
try {
|
|
645
|
-
input = await resolveOutputRefs(
|
|
364
|
+
input = await resolveOutputRefs(rawInput, (id) => this.deps.outputs.load({ orgId: ctx.orgId, conversationId: ctx.conversationId }, id));
|
|
646
365
|
}
|
|
647
366
|
catch (e) {
|
|
648
367
|
if (e instanceof ToolError)
|
|
@@ -656,6 +375,21 @@ let ToolPipeline = class ToolPipeline {
|
|
|
656
375
|
});
|
|
657
376
|
if (invalid !== null)
|
|
658
377
|
return fail(invalid, outKey);
|
|
378
|
+
// the per-call policy key (Platform tool spec §6.2): key and summary come from the resolved
|
|
379
|
+
// input, while the approval binding below compares the raw call.input
|
|
380
|
+
const callPolicy = (await tool.callPolicy?.(input, {
|
|
381
|
+
orgId: ctx.orgId,
|
|
382
|
+
accountId: ctx.accountId,
|
|
383
|
+
agentId: ctx.agentId,
|
|
384
|
+
conversationId: ctx.conversationId,
|
|
385
|
+
runId: ctx.runId,
|
|
386
|
+
rawInput,
|
|
387
|
+
})) ?? null;
|
|
388
|
+
// a deny with a reason (e.g. an unavailable operation): the reason is the tool error
|
|
389
|
+
if (callPolicy?.policy === "deny" && callPolicy.denyReason !== undefined) {
|
|
390
|
+
return fail(callPolicy.denyReason, outKey);
|
|
391
|
+
}
|
|
392
|
+
const policyKey = callPolicy?.key ?? tool.key;
|
|
659
393
|
const decision = await this.decide(tool, ctx.agent, {
|
|
660
394
|
orgId: ctx.orgId,
|
|
661
395
|
accountId: ctx.accountId,
|
|
@@ -664,11 +398,13 @@ let ToolPipeline = class ToolPipeline {
|
|
|
664
398
|
runId: ctx.runId,
|
|
665
399
|
...(ctx.parent !== undefined && {
|
|
666
400
|
parentConversationId: ctx.parent.conversationId,
|
|
401
|
+
rootConversationId: ctx.parent.rootConversationId,
|
|
667
402
|
...(ctx.parent.otherAgent !== undefined && { parentAgentDiffers: ctx.parent.otherAgent }),
|
|
668
403
|
}),
|
|
404
|
+
callPolicy,
|
|
669
405
|
});
|
|
670
406
|
if (decision === "deny")
|
|
671
|
-
return fail(deniedText(tool.key), outKey);
|
|
407
|
+
return fail(deniedText(tool.key, callPolicy?.key), outKey);
|
|
672
408
|
if (typeof decision === "object" && "unavailable" in decision) {
|
|
673
409
|
return fail(unavailableText(tool.key, decision.unavailable), outKey);
|
|
674
410
|
}
|
|
@@ -679,7 +415,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
679
415
|
// An in-flight rc call (spec §9) is the exception: its approval was asked under the rc definition
|
|
680
416
|
// of the same call, and the rename changed every builtin's definition; the person approved this
|
|
681
417
|
// very call, so the approval stands.
|
|
682
|
-
|
|
418
|
+
// An approval binds the exact input it showed (Platform tool spec §6.3): an approved record
|
|
419
|
+
// whose stored input differs from the call's is not used.
|
|
420
|
+
const approvedHere = approval?.status === "approved" &&
|
|
421
|
+
(legacy || approval.specHash === tool.specHash) &&
|
|
422
|
+
canonicalJson(approval.input) === canonicalJson(call.input ?? {});
|
|
683
423
|
const stale = approval?.status === "approved" && !approvedHere;
|
|
684
424
|
if ((!approval || stale) && typeof decision === "object" && "ask" in decision) {
|
|
685
425
|
approval = await this.deps.approvals.request({
|
|
@@ -689,13 +429,15 @@ let ToolPipeline = class ToolPipeline {
|
|
|
689
429
|
runId: ctx.runId,
|
|
690
430
|
step: ctx.step,
|
|
691
431
|
callId: call.id,
|
|
692
|
-
toolKey:
|
|
432
|
+
toolKey: policyKey,
|
|
693
433
|
specHash: decision.ask.specHash,
|
|
694
434
|
connectorId: decision.ask.connectorId,
|
|
695
435
|
input: call.input,
|
|
696
436
|
requestedFor: decision.ask.requestedFor,
|
|
697
437
|
approverRole: decision.ask.approverRole,
|
|
698
438
|
policy: decision.ask.policy,
|
|
439
|
+
...(callPolicy?.summary !== undefined && { summary: callPolicy.summary }),
|
|
440
|
+
...(callPolicy !== null && !callPolicy.remember && { scopes: ["once"] }),
|
|
699
441
|
});
|
|
700
442
|
}
|
|
701
443
|
if (approval && approval.status !== "approved") {
|
|
@@ -762,16 +504,72 @@ let ToolPipeline = class ToolPipeline {
|
|
|
762
504
|
return undefined;
|
|
763
505
|
}
|
|
764
506
|
}
|
|
765
|
-
// `Agent` (sub-agents spec §7.1): no tool_call_started;
|
|
766
|
-
//
|
|
507
|
+
// `Agent` (sub-agents spec §7.1, agent map spec §4.1): no tool_call_started; one transaction
|
|
508
|
+
// makes the dispatch durable (its marker is the subagent_dispatches row) and writes the call's
|
|
509
|
+
// immediate result, while the sub-agent runs in the background
|
|
767
510
|
const dispatcher = this.deps.subagents;
|
|
768
511
|
if (tool.source.kind === "builtin" && tool.key === AGENT_TOOL && dispatcher) {
|
|
769
512
|
const parsed = AgentToolInput.safeParse(input);
|
|
770
513
|
if (!parsed.success) {
|
|
771
|
-
return fail("Invalid agent call: pass description and prompt, and optionally subagent_type
|
|
514
|
+
return fail("Invalid agent call: pass description and prompt, and optionally subagent_type and model.", outKey);
|
|
772
515
|
}
|
|
773
|
-
const r = await dispatcher.dispatch({
|
|
774
|
-
|
|
516
|
+
const r = await dispatcher.dispatch({
|
|
517
|
+
ctx,
|
|
518
|
+
callId: call.id,
|
|
519
|
+
input: parsed.data,
|
|
520
|
+
call: { toolKey: outKey, authorization, startedAt: Date.now() },
|
|
521
|
+
});
|
|
522
|
+
if (r.kind === "refused")
|
|
523
|
+
return fail(r.content, outKey);
|
|
524
|
+
if (hooks && hookBase) {
|
|
525
|
+
fireObserve(hooks, "tool.postExecute", {
|
|
526
|
+
...hookBase,
|
|
527
|
+
isError: false,
|
|
528
|
+
content: r.content,
|
|
529
|
+
durationMs: 0,
|
|
530
|
+
}, ctx.signal, this.deps.log);
|
|
531
|
+
}
|
|
532
|
+
return undefined;
|
|
533
|
+
}
|
|
534
|
+
// `SendMessage` and `SubagentHandback` (agent map spec §4.2, §4.3): no tool_call_started; each
|
|
535
|
+
// write is idempotent by the call (the message in the sub-agent's log, the delivery in the
|
|
536
|
+
// parent's), so a call retried after a crash sends nothing twice. A send that starts an idle
|
|
537
|
+
// sub-agent writes its result with the dispatch, like `Agent`
|
|
538
|
+
const messenger = this.deps.messages;
|
|
539
|
+
if (tool.source.kind === "builtin" &&
|
|
540
|
+
(tool.key === SEND_MESSAGE || tool.key === SUBAGENT_HANDBACK) &&
|
|
541
|
+
messenger) {
|
|
542
|
+
const t0 = Date.now();
|
|
543
|
+
let r;
|
|
544
|
+
if (tool.key === SEND_MESSAGE) {
|
|
545
|
+
const parsed = SendMessageInput.safeParse(input);
|
|
546
|
+
if (!parsed.success) {
|
|
547
|
+
return fail("Invalid SendMessage call: pass to and message.", outKey);
|
|
548
|
+
}
|
|
549
|
+
r = await messenger.toChild(ctx, call.id, parsed.data.to, parsed.data.message, {
|
|
550
|
+
authorization,
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
const parsed = HandbackInput.safeParse(input);
|
|
555
|
+
if (!parsed.success)
|
|
556
|
+
return fail("Invalid SubagentHandback call: pass message.", outKey);
|
|
557
|
+
r = await messenger.toParent(ctx, "report", parsed.data.message, call.id);
|
|
558
|
+
}
|
|
559
|
+
if (r.isError)
|
|
560
|
+
return fail(r.content, outKey);
|
|
561
|
+
const durationMs = Date.now() - t0;
|
|
562
|
+
if (r.logged !== true) {
|
|
563
|
+
await this.writeResult(ctx, call.id, outKey, { content: r.content, isError: false }, [], {
|
|
564
|
+
durationMs,
|
|
565
|
+
connectorId: null,
|
|
566
|
+
authorization,
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
if (hooks && hookBase) {
|
|
570
|
+
fireObserve(hooks, "tool.postExecute", { ...hookBase, isError: false, content: r.content, durationMs }, ctx.signal, this.deps.log);
|
|
571
|
+
}
|
|
572
|
+
return undefined;
|
|
775
573
|
}
|
|
776
574
|
await this.deps.eventLog.append(ctx.conversationId, [
|
|
777
575
|
{
|
|
@@ -852,24 +650,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
852
650
|
connectorId: tool.source.kind === "connector" ? tool.source.connectorId : null,
|
|
853
651
|
authorization,
|
|
854
652
|
});
|
|
855
|
-
// a sub-agent that needs a personal connection: mirrored in the
|
|
856
|
-
// not a wait, the child got the connect
|
|
653
|
+
// a sub-agent that needs a personal connection: mirrored in the root conversation of its tree
|
|
654
|
+
// for display (sub-agents spec §9, agent map spec §7; not a wait, the child got the connect
|
|
655
|
+
// text as its result)
|
|
857
656
|
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", {
|
|
657
|
+
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
658
|
runId: ctx.runId,
|
|
874
659
|
err,
|
|
875
660
|
}));
|
|
@@ -879,6 +664,26 @@ let ToolPipeline = class ToolPipeline {
|
|
|
879
664
|
}
|
|
880
665
|
return undefined;
|
|
881
666
|
}
|
|
667
|
+
/** Appends a sub-agent's connect card to its root conversation ({@link rootSurfaceOf}). */
|
|
668
|
+
async surfaceConnectInRoot(ctx, parent, callId, toolKey) {
|
|
669
|
+
const target = await rootSurfaceOf(this.deps.db, ctx.conversationId, ctx.runId, parent);
|
|
670
|
+
if (!target)
|
|
671
|
+
return;
|
|
672
|
+
await this.deps.eventLog.append(target.conversationId, [
|
|
673
|
+
{
|
|
674
|
+
type: "subagent_waiting",
|
|
675
|
+
runId: target.runId,
|
|
676
|
+
idemKey: subagentWaitingIdemKey(ctx.runId, `connect-${callId}`),
|
|
677
|
+
payload: {
|
|
678
|
+
subagentId: ctx.conversationId,
|
|
679
|
+
childRunId: ctx.runId,
|
|
680
|
+
path: target.path,
|
|
681
|
+
kind: "connect",
|
|
682
|
+
toolKey,
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
]);
|
|
686
|
+
}
|
|
882
687
|
/**
|
|
883
688
|
* Every tool key the request that issued this step's calls offered (`request.tools` plus the
|
|
884
689
|
* `catalog` keys), in any mode; null when its model_call is not found. Used to tell a call to an
|
|
@@ -982,11 +787,13 @@ let ToolPipeline = class ToolPipeline {
|
|
|
982
787
|
...(tool.source.kind === "builtin" && { runId: ctx.runId }),
|
|
983
788
|
...(tool.source.kind === "builtin" &&
|
|
984
789
|
ctx.deadline !== undefined && { runDeadline: ctx.deadline }),
|
|
985
|
-
// a sub-agent works in its
|
|
790
|
+
// a sub-agent works in its root conversation's sandbox (spec §10.1, at every depth)
|
|
986
791
|
...(tool.source.kind === "builtin" &&
|
|
987
|
-
ctx.parent !== undefined && { sandboxConversationId: ctx.parent.
|
|
792
|
+
ctx.parent !== undefined && { sandboxConversationId: ctx.parent.rootConversationId }),
|
|
988
793
|
...(tool.source.kind === "builtin" &&
|
|
989
794
|
ctx.parent !== undefined && { parentRunId: ctx.parent.runId }),
|
|
795
|
+
...(tool.source.kind === "builtin" &&
|
|
796
|
+
ctx.parent?.budgetRunId !== undefined && { budgetRunId: ctx.parent.budgetRunId }),
|
|
990
797
|
// the hook scope of a builtin's own model call (the WebFetch extraction)
|
|
991
798
|
...(tool.source.kind === "builtin" && {
|
|
992
799
|
step: ctx.step,
|
|
@@ -1004,7 +811,24 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1004
811
|
// 内置工具可按输入给自己的时限(沙箱 bash 按命令超时加余量);缺省 tools.timeoutMs
|
|
1005
812
|
const timeoutMs = tool.timeoutMs?.(input) ?? this.config.get().tools.timeoutMs;
|
|
1006
813
|
try {
|
|
1007
|
-
|
|
814
|
+
// a plugin tool runs with the extension's effective config for the org, never without it
|
|
815
|
+
// (layering spec A §6): one read per call, cached by EffectiveConfigs
|
|
816
|
+
let config = {};
|
|
817
|
+
if (tool.source.kind === "plugin") {
|
|
818
|
+
// turned off in the org since the step resolved its tools (spec A §7)
|
|
819
|
+
if (await this.deps.switches.isToolOff(ctx.orgId, tool.source.plugin, tool.source.name)) {
|
|
820
|
+
return { kind: "error", message: `${toolTurnedOffReason(tool.key)}.` };
|
|
821
|
+
}
|
|
822
|
+
const effective = await this.deps.effective.get(ctx.orgId, tool.source.plugin);
|
|
823
|
+
if (!effective.ok) {
|
|
824
|
+
// unloaded or disabled since the step resolved its tools: the documented unloaded error
|
|
825
|
+
if (effective.notRunning)
|
|
826
|
+
return { kind: "error", message: PLUGIN_UNLOADED_TOOL_ERROR };
|
|
827
|
+
return { kind: "error", message: unavailableText(tool.key, NEEDS_CONFIG_REASON) };
|
|
828
|
+
}
|
|
829
|
+
config = { config: effective.config };
|
|
830
|
+
}
|
|
831
|
+
const r = await this.bounded(ctx.signal, (signal) => handler(input, { ...base, ...config, signal }), undefined, timeoutMs);
|
|
1008
832
|
if (r === "timeout") {
|
|
1009
833
|
return { kind: "error", message: timeoutText(tool.key, timeoutMs) };
|
|
1010
834
|
}
|
|
@@ -1189,6 +1013,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1189
1013
|
thrown(key, e) {
|
|
1190
1014
|
if (e instanceof ToolError)
|
|
1191
1015
|
return { kind: "error", message: e.message };
|
|
1016
|
+
// an extension tool's ctx.models.embed denied by a policy hook (spec B §5.4): the model sees the
|
|
1017
|
+
// deny text (sanitized reason), as for a denied tool call, not a generic failure
|
|
1018
|
+
if (e instanceof ApiError && e.code === "model.hook_denied") {
|
|
1019
|
+
return { kind: "error", message: e.message };
|
|
1020
|
+
}
|
|
1192
1021
|
// 提供工具的插件实例在调用进行中被撤销(停用 / 升级),排空时限到后中止(C17)
|
|
1193
1022
|
if (e instanceof ExtensionUnloadedError) {
|
|
1194
1023
|
this.deps.log.warn("tool call aborted: plugin unloaded", { toolKey: key, plugin: e.plugin });
|
|
@@ -1359,9 +1188,6 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1359
1188
|
return out;
|
|
1360
1189
|
}
|
|
1361
1190
|
};
|
|
1362
|
-
__decorate([
|
|
1363
|
-
Transactional()
|
|
1364
|
-
], ToolPipeline.prototype, "stopOpenAgentCallsNow", null);
|
|
1365
1191
|
__decorate([
|
|
1366
1192
|
Transactional({ propagation: "mandatory" })
|
|
1367
1193
|
], ToolPipeline.prototype, "stopOpenAgentCalls", null);
|
|
@@ -1373,18 +1199,21 @@ ToolPipeline = __decorate([
|
|
|
1373
1199
|
__param(0, Inject(KernelDb)),
|
|
1374
1200
|
__param(1, Inject(EventLog)),
|
|
1375
1201
|
__param(2, Inject(SubagentsService)),
|
|
1376
|
-
__param(3, Inject(
|
|
1377
|
-
__param(4, Inject(
|
|
1378
|
-
__param(5, Inject(
|
|
1379
|
-
__param(6, Inject(
|
|
1380
|
-
__param(7, Inject(
|
|
1381
|
-
__param(8, Inject(
|
|
1382
|
-
__param(9, Inject(
|
|
1383
|
-
__param(10, Inject(
|
|
1384
|
-
__param(11, Inject(
|
|
1385
|
-
__param(12, Inject(
|
|
1386
|
-
__param(13, Inject(
|
|
1387
|
-
__param(14,
|
|
1388
|
-
__param(
|
|
1202
|
+
__param(3, Inject(SubagentMessages)),
|
|
1203
|
+
__param(4, Inject(ToolRegistry)),
|
|
1204
|
+
__param(5, Inject(Credentials)),
|
|
1205
|
+
__param(6, Inject(Breaker)),
|
|
1206
|
+
__param(7, Inject(ToolOutputs)),
|
|
1207
|
+
__param(8, Inject(ApprovalsService)),
|
|
1208
|
+
__param(9, Inject(QuestionsService)),
|
|
1209
|
+
__param(10, Inject(KernelConfigService)),
|
|
1210
|
+
__param(11, Inject(KERNEL_LOGGER)),
|
|
1211
|
+
__param(12, Inject(ExtensionHost)),
|
|
1212
|
+
__param(13, Inject(ToolDrift)),
|
|
1213
|
+
__param(14, Inject(EffectiveConfigs)),
|
|
1214
|
+
__param(15, Inject(OrgToolSwitches)),
|
|
1215
|
+
__param(16, Inject(TransactionHost)),
|
|
1216
|
+
__param(17, Optional()),
|
|
1217
|
+
__param(17, Inject(TOOL_PIPELINE_HOOKS))
|
|
1389
1218
|
], ToolPipeline);
|
|
1390
1219
|
export { ToolPipeline };
|