@capybara-hq/kernel 0.1.0-rc.1 → 0.1.0-rc.3
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/dist/admin/admin.controller.d.ts +17 -17
- package/dist/admin/admin.controller.js +43 -26
- package/dist/admin/admin.module.d.ts +3 -0
- package/dist/admin/admin.module.js +22 -0
- package/dist/admin/extensions.controller.d.ts +14 -14
- package/dist/admin/extensions.controller.js +30 -17
- package/dist/admin/setup-lock.d.ts +16 -0
- package/dist/admin/setup-lock.js +47 -0
- package/dist/admin/setup.controller.d.ts +8 -8
- package/dist/admin/setup.controller.js +27 -25
- package/dist/admin/setup.service.d.ts +19 -27
- package/dist/admin/setup.service.js +61 -61
- package/dist/agents/agent-lookup.d.ts +53 -0
- package/dist/agents/agent-lookup.js +187 -0
- package/dist/agents/agents.controller.d.ts +1 -1
- package/dist/agents/agents.controller.js +14 -8
- package/dist/agents/agents.module.d.ts +7 -0
- package/dist/agents/agents.module.js +41 -0
- package/dist/agents/agents.service.d.ts +39 -58
- package/dist/agents/agents.service.js +280 -335
- package/dist/agents/definition.d.ts +39 -8
- package/dist/agents/definition.js +201 -17
- package/dist/agents/models.controller.d.ts +1 -1
- package/dist/agents/models.controller.js +2 -2
- package/dist/agents/templates.controller.d.ts +1 -1
- package/dist/agents/templates.controller.js +2 -2
- package/dist/agents/templates.d.ts +6 -8
- package/dist/agents/templates.js +39 -8
- package/dist/app.d.ts +93 -0
- package/dist/app.js +150 -0
- package/dist/catalog/admin-catalog.controller.d.ts +3 -3
- package/dist/catalog/admin-catalog.controller.js +27 -13
- package/dist/catalog/catalog-content.d.ts +185 -0
- package/dist/catalog/catalog-content.js +326 -0
- package/dist/catalog/catalog-items.d.ts +186 -0
- package/dist/catalog/catalog-items.js +410 -0
- package/dist/catalog/catalog.module.d.ts +14 -0
- package/dist/catalog/catalog.module.js +71 -0
- package/dist/catalog/catalog.service.d.ts +34 -188
- package/dist/catalog/catalog.service.js +155 -489
- package/dist/catalog/claude/agents.js +13 -10
- package/dist/catalog/cli.d.ts +3 -2
- package/dist/catalog/cli.js +13 -31
- package/dist/catalog/job-ids.d.ts +15 -0
- package/dist/catalog/job-ids.js +15 -0
- package/dist/catalog/jobs.d.ts +27 -0
- package/dist/catalog/jobs.js +70 -0
- package/dist/catalog/locks.d.ts +24 -0
- package/dist/catalog/locks.js +63 -0
- package/dist/catalog/marketplaces.controller.d.ts +4 -4
- package/dist/catalog/marketplaces.controller.js +22 -11
- package/dist/catalog/marketplaces.service.d.ts +31 -14
- package/dist/catalog/marketplaces.service.js +330 -256
- package/dist/catalog/org-catalog.controller.d.ts +4 -3
- package/dist/catalog/org-catalog.controller.js +29 -14
- package/dist/catalog/org-catalog.service.d.ts +32 -198
- package/dist/catalog/org-catalog.service.js +159 -400
- package/dist/catalog/plugin-import.d.ts +73 -34
- package/dist/catalog/plugin-import.js +356 -217
- package/dist/catalog/plugin-install.d.ts +83 -41
- package/dist/catalog/plugin-install.js +421 -269
- package/dist/catalog/plugin-upgrade.d.ts +59 -4
- package/dist/catalog/plugin-upgrade.js +407 -282
- package/dist/catalog/requests.service.d.ts +27 -15
- package/dist/catalog/requests.service.js +201 -145
- package/dist/catalog/upgrade-targets.d.ts +4 -7
- package/dist/channels/actions.d.ts +6 -4
- package/dist/channels/actions.js +1 -1
- package/dist/channels/cards.d.ts +10 -4
- package/dist/channels/cards.js +16 -8
- package/dist/channels/channels.module.d.ts +40 -0
- package/dist/channels/channels.module.js +128 -0
- package/dist/channels/connections.controller.d.ts +1 -1
- package/dist/channels/connections.controller.js +11 -6
- package/dist/channels/connections.service.d.ts +43 -21
- package/dist/channels/connections.service.js +236 -131
- package/dist/channels/inbound.d.ts +34 -38
- package/dist/channels/inbound.js +107 -41
- package/dist/channels/job-ids.d.ts +10 -0
- package/dist/channels/job-ids.js +10 -0
- package/dist/channels/jobs.d.ts +85 -0
- package/dist/channels/jobs.js +157 -0
- package/dist/channels/outbound.d.ts +60 -82
- package/dist/channels/outbound.js +165 -194
- package/dist/channels/supervisor.d.ts +88 -46
- package/dist/channels/supervisor.js +230 -132
- package/dist/channels/threads.d.ts +29 -8
- package/dist/channels/threads.js +71 -13
- package/dist/channels/webhook.d.ts +20 -14
- package/dist/channels/webhook.js +51 -20
- package/dist/config/load.d.ts +3 -2
- package/dist/config/load.js +3 -2
- package/dist/config/nacos-source.js +11 -2
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.js +12 -6
- package/dist/conversations/access.d.ts +29 -0
- package/dist/conversations/access.js +86 -0
- package/dist/conversations/artifacts.d.ts +11 -11
- package/dist/conversations/artifacts.js +36 -10
- package/dist/conversations/attachments.controller.d.ts +1 -1
- package/dist/conversations/attachments.controller.js +8 -6
- package/dist/conversations/attachments.module.d.ts +7 -0
- package/dist/conversations/attachments.module.js +25 -0
- package/dist/conversations/attachments.service.d.ts +30 -22
- package/dist/conversations/attachments.service.js +119 -46
- package/dist/conversations/conversations.controller.d.ts +8 -7
- package/dist/conversations/conversations.controller.js +59 -29
- package/dist/conversations/conversations.module.d.ts +8 -0
- package/dist/conversations/conversations.module.js +69 -0
- package/dist/conversations/conversations.service.d.ts +40 -38
- package/dist/conversations/conversations.service.js +130 -140
- package/dist/conversations/event-log.d.ts +39 -18
- package/dist/conversations/event-log.js +93 -27
- package/dist/conversations/events.d.ts +23 -3
- package/dist/conversations/events.js +26 -14
- package/dist/conversations/files.d.ts +10 -10
- package/dist/conversations/files.js +37 -11
- package/dist/conversations/idem-keys.d.ts +5 -0
- package/dist/conversations/idem-keys.js +5 -0
- package/dist/conversations/job-ids.d.ts +6 -0
- package/dist/conversations/job-ids.js +6 -0
- package/dist/conversations/outputs-read.d.ts +11 -11
- package/dist/conversations/outputs-read.js +31 -7
- package/dist/conversations/queue.d.ts +48 -56
- package/dist/conversations/queue.js +13 -289
- package/dist/conversations/queue.service.d.ts +60 -0
- package/dist/conversations/queue.service.js +343 -0
- package/dist/conversations/sandbox-status.d.ts +13 -10
- package/dist/conversations/sandbox-status.js +36 -8
- package/dist/conversations/titles.d.ts +71 -24
- package/dist/conversations/titles.js +159 -63
- package/dist/ctx/bus.js +9 -3
- package/dist/ctx/create-ctx.d.ts +6 -0
- package/dist/ctx/create-ctx.js +7 -9
- package/dist/ctx/lock.d.ts +7 -3
- package/dist/ctx/lock.js +9 -20
- package/dist/ctx/secrets.d.ts +10 -2
- package/dist/ctx/secrets.js +7 -3
- package/dist/db/kernel-schema.d.ts +4 -4
- package/dist/db/pool.d.ts +5 -0
- package/dist/db/pool.js +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +1 -0
- package/dist/evals/budget.d.ts +42 -21
- package/dist/evals/budget.js +114 -62
- package/dist/evals/evals.module.d.ts +31 -0
- package/dist/evals/evals.module.js +114 -0
- package/dist/evals/jobs.d.ts +20 -0
- package/dist/evals/jobs.js +45 -0
- package/dist/evals/recorded-tools.d.ts +27 -1
- package/dist/evals/recorded-tools.js +85 -10
- package/dist/evals/run-replay.d.ts +61 -8
- package/dist/evals/run-replay.js +159 -85
- package/dist/evals/runs.controller.d.ts +1 -1
- package/dist/evals/runs.controller.js +17 -8
- package/dist/evals/runs.service.d.ts +23 -45
- package/dist/evals/runs.service.js +245 -234
- package/dist/evals/sets.controller.d.ts +1 -1
- package/dist/evals/sets.controller.js +17 -8
- package/dist/evals/sets.service.d.ts +22 -6
- package/dist/evals/sets.service.js +248 -194
- package/dist/evals/snapshot.d.ts +2 -2
- package/dist/evals/step-replay.d.ts +2 -2
- package/dist/evals/step-replay.js +1 -1
- package/dist/evals/trajectory.controller.d.ts +1 -1
- package/dist/evals/trajectory.controller.js +11 -7
- package/dist/evals/trajectory.d.ts +2 -2
- package/dist/evals/trajectory.service.d.ts +5 -4
- package/dist/evals/trajectory.service.js +30 -7
- package/dist/evals/worker.d.ts +44 -27
- package/dist/evals/worker.js +220 -121
- package/dist/extensions/admin-ops.d.ts +61 -33
- package/dist/extensions/admin-ops.js +248 -154
- package/dist/extensions/admin-view.d.ts +38 -27
- package/dist/extensions/admin-view.js +126 -55
- package/dist/extensions/approvals.d.ts +12 -8
- package/dist/extensions/approvals.js +73 -46
- package/dist/extensions/blobs.d.ts +27 -10
- package/dist/extensions/blobs.js +111 -45
- package/dist/extensions/bootstrap.d.ts +58 -31
- package/dist/extensions/bootstrap.js +175 -121
- package/dist/extensions/cli.d.ts +20 -10
- package/dist/extensions/cli.js +41 -96
- package/dist/extensions/config-issues.d.ts +7 -0
- package/dist/extensions/config-issues.js +31 -0
- package/dist/extensions/deployment-config-store.d.ts +49 -0
- package/dist/extensions/deployment-config-store.js +133 -0
- package/dist/extensions/deployment-config.d.ts +58 -67
- package/dist/extensions/deployment-config.js +202 -230
- package/dist/extensions/enabled.d.ts +5 -5
- package/dist/extensions/extensions.module.d.ts +8 -0
- package/dist/extensions/extensions.module.js +77 -0
- package/dist/extensions/hooks.d.ts +3 -2
- package/dist/extensions/hooks.js +1 -1
- package/dist/extensions/host.d.ts +72 -68
- package/dist/extensions/host.js +191 -152
- package/dist/extensions/installs.d.ts +49 -16
- package/dist/extensions/installs.js +128 -32
- package/dist/extensions/job-ids.d.ts +6 -0
- package/dist/extensions/job-ids.js +6 -0
- package/dist/extensions/lifecycle-topics.d.ts +18 -0
- package/dist/extensions/lifecycle-topics.js +18 -0
- package/dist/extensions/lifecycle.d.ts +35 -47
- package/dist/extensions/lifecycle.js +103 -39
- package/dist/extensions/locks.d.ts +33 -0
- package/dist/extensions/locks.js +86 -0
- package/dist/extensions/migrate-lock.d.ts +3 -4
- package/dist/extensions/org-config.controller.d.ts +1 -1
- package/dist/extensions/org-config.controller.js +8 -5
- package/dist/extensions/org-config.d.ts +48 -46
- package/dist/extensions/org-config.js +284 -226
- package/dist/extensions/registry.d.ts +50 -2
- package/dist/extensions/registry.js +89 -4
- package/dist/extensions/sources.d.ts +12 -8
- package/dist/extensions/sources.js +34 -13
- package/dist/files/files.module.d.ts +3 -0
- package/dist/files/files.module.js +22 -0
- package/dist/files/previewers.controller.d.ts +7 -2
- package/dist/files/previewers.controller.js +17 -9
- package/dist/files/previewers.d.ts +13 -18
- package/dist/files/previewers.js +83 -36
- package/dist/http/adapter.d.ts +3 -0
- package/dist/http/adapter.js +25 -0
- package/dist/http/api.module.d.ts +3 -110
- package/dist/http/api.module.js +47 -355
- package/dist/http/app.d.ts +11 -15
- package/dist/http/app.js +17 -62
- package/dist/http/error-filter.module.d.ts +5 -0
- package/dist/http/error-filter.module.js +18 -0
- package/dist/http/error.filter.js +2 -2
- package/dist/identity/accounts.d.ts +82 -29
- package/dist/identity/accounts.js +294 -175
- package/dist/identity/api-tokens.d.ts +11 -7
- package/dist/identity/api-tokens.js +71 -44
- package/dist/identity/audit.d.ts +7 -4
- package/dist/identity/audit.js +5 -1
- package/dist/identity/auth.controller.d.ts +11 -10
- package/dist/identity/auth.controller.js +31 -25
- package/dist/identity/auth.guard.d.ts +3 -3
- package/dist/identity/auth.guard.js +6 -4
- package/dist/identity/binding.d.ts +9 -11
- package/dist/identity/binding.js +41 -13
- package/dist/identity/enterprise-admin.d.ts +18 -12
- package/dist/identity/enterprise-admin.js +67 -13
- package/dist/identity/external-identity-lock.d.ts +17 -0
- package/dist/identity/external-identity-lock.js +39 -0
- package/dist/identity/external.d.ts +19 -15
- package/dist/identity/external.js +163 -125
- package/dist/identity/identity.module.d.ts +6 -0
- package/dist/identity/identity.module.js +56 -0
- package/dist/identity/me.controller.d.ts +16 -15
- package/dist/identity/me.controller.js +37 -31
- package/dist/identity/sessions.d.ts +12 -10
- package/dist/identity/sessions.js +74 -42
- package/dist/identity/settings.d.ts +20 -14
- package/dist/identity/settings.js +86 -58
- package/dist/identity/sso.controller.d.ts +7 -7
- package/dist/identity/sso.controller.js +13 -9
- package/dist/identity/sso.d.ts +9 -12
- package/dist/identity/sso.js +54 -24
- package/dist/inbox/inbox.module.d.ts +3 -0
- package/dist/inbox/inbox.module.js +22 -0
- package/dist/inbox/inbox.service.d.ts +7 -9
- package/dist/inbox/inbox.service.js +32 -11
- package/dist/index.d.ts +16 -11
- package/dist/index.js +9 -6
- package/dist/infra/cache/cache.module.d.ts +3 -0
- package/dist/infra/cache/cache.module.js +16 -0
- package/dist/infra/cache/cache.service.d.ts +21 -0
- package/dist/infra/cache/cache.service.js +80 -0
- package/dist/infra/cache/cacheable.decorator.d.ts +32 -0
- package/dist/infra/cache/cacheable.decorator.js +83 -0
- package/dist/infra/cli/kernel-cli.module.d.ts +66 -0
- package/dist/infra/cli/kernel-cli.module.js +165 -0
- package/dist/infra/close-within.d.ts +15 -0
- package/dist/infra/close-within.js +36 -0
- package/dist/infra/config/config.module.d.ts +13 -0
- package/dist/infra/config/config.module.js +39 -0
- package/dist/infra/config/kernel-config.service.d.ts +25 -0
- package/dist/infra/config/kernel-config.service.js +126 -0
- package/dist/infra/database/after-commit.d.ts +6 -0
- package/dist/infra/database/after-commit.js +9 -0
- package/dist/infra/database/database.module.d.ts +25 -0
- package/dist/infra/database/database.module.js +90 -0
- package/dist/infra/database/kernel-db.d.ts +22 -0
- package/dist/infra/database/kernel-db.js +65 -0
- package/dist/infra/database/transaction-host.d.ts +50 -0
- package/dist/infra/database/transaction-host.js +125 -0
- package/dist/infra/database/transactional.decorator.d.ts +15 -0
- package/dist/infra/database/transactional.decorator.js +27 -0
- package/dist/infra/database/xact-lock.d.ts +17 -0
- package/dist/infra/database/xact-lock.js +43 -0
- package/dist/infra/events/kernel-events.d.ts +96 -0
- package/dist/infra/events/kernel-events.js +65 -0
- package/dist/infra/health/health.controller.d.ts +26 -0
- package/dist/infra/health/health.controller.js +104 -0
- package/dist/infra/health/health.module.d.ts +9 -0
- package/dist/infra/health/health.module.js +24 -0
- package/dist/infra/health/health.options.d.ts +10 -0
- package/dist/infra/health/health.options.js +15 -0
- package/dist/infra/health/shutdown-state.d.ts +6 -0
- package/dist/infra/health/shutdown-state.js +2 -0
- package/dist/infra/lifecycle/graceful-shutdown.module.d.ts +6 -0
- package/dist/infra/lifecycle/graceful-shutdown.module.js +23 -0
- package/dist/infra/lifecycle/graceful-shutdown.service.d.ts +70 -0
- package/dist/infra/lifecycle/graceful-shutdown.service.js +135 -0
- package/dist/infra/lifecycle/process-guards.d.ts +52 -0
- package/dist/infra/lifecycle/process-guards.js +86 -0
- package/dist/infra/lifecycle/shutdown-signals.d.ts +30 -0
- package/dist/infra/lifecycle/shutdown-signals.js +48 -0
- package/dist/infra/lock/key-template.d.ts +13 -0
- package/dist/infra/lock/key-template.js +46 -0
- package/dist/infra/lock/lock.module.d.ts +3 -0
- package/dist/infra/lock/lock.module.js +16 -0
- package/dist/infra/lock/lock.service.d.ts +120 -0
- package/dist/infra/lock/lock.service.js +343 -0
- package/dist/infra/lock/shared-lease.d.ts +44 -0
- package/dist/infra/lock/shared-lease.js +121 -0
- package/dist/infra/lock/with-lock.decorator.d.ts +28 -0
- package/dist/infra/lock/with-lock.decorator.js +49 -0
- package/dist/infra/logging/logging.module.d.ts +16 -0
- package/dist/infra/logging/logging.module.js +34 -0
- package/dist/infra/queue/configured-processor.d.ts +18 -0
- package/dist/infra/queue/configured-processor.js +23 -0
- package/dist/infra/queue/job-failure.d.ts +18 -0
- package/dist/infra/queue/job-failure.js +26 -0
- package/dist/infra/queue/queue-shutdown.d.ts +27 -0
- package/dist/infra/queue/queue-shutdown.js +81 -0
- package/dist/infra/queue/queue.module.d.ts +16 -0
- package/dist/infra/queue/queue.module.js +61 -0
- package/dist/infra/queue/redis-connection.d.ts +7 -0
- package/dist/infra/queue/redis-connection.js +18 -0
- package/dist/infra/queue/retired-schedulers.d.ts +7 -0
- package/dist/infra/queue/retired-schedulers.js +9 -0
- package/dist/infra/queue/run-job.d.ts +16 -0
- package/dist/infra/queue/run-job.js +19 -0
- package/dist/infra/redis/redis.module.d.ts +24 -0
- package/dist/infra/redis/redis.module.js +87 -0
- package/dist/infra/schedule/cron-tick.d.ts +12 -0
- package/dist/infra/schedule/cron-tick.js +25 -0
- package/dist/infra/schedule/locked-cron.decorator.d.ts +27 -0
- package/dist/infra/schedule/locked-cron.decorator.js +53 -0
- package/dist/infra/schedule/locked-interval.d.ts +69 -0
- package/dist/infra/schedule/locked-interval.js +190 -0
- package/dist/infra/schedule/locked-tick.d.ts +90 -0
- package/dist/infra/schedule/locked-tick.js +137 -0
- package/dist/infra/schedule/schedule.module.d.ts +8 -0
- package/dist/infra/schedule/schedule.module.js +27 -0
- package/dist/infra/schedule/scheduled-runs.d.ts +69 -0
- package/dist/infra/schedule/scheduled-runs.js +163 -0
- package/dist/infra/swagger/swagger.d.ts +16 -0
- package/dist/infra/swagger/swagger.js +31 -0
- package/dist/infra/throttler/credential-throttler.d.ts +35 -0
- package/dist/infra/throttler/credential-throttler.js +77 -0
- package/dist/infra/throttler/named-throttlers.d.ts +31 -0
- package/dist/infra/throttler/named-throttlers.js +119 -0
- package/dist/infra/throttler/redis-throttler-storage.d.ts +38 -0
- package/dist/infra/throttler/redis-throttler-storage.js +130 -0
- package/dist/infra/throttler/throttler.guard.d.ts +23 -0
- package/dist/infra/throttler/throttler.guard.js +68 -0
- package/dist/infra/throttler/throttler.module.d.ts +15 -0
- package/dist/infra/throttler/throttler.module.js +53 -0
- package/dist/infra/tokens.d.ts +15 -0
- package/dist/infra/tokens.js +15 -0
- package/dist/infra/validation/create-zod-dto.d.ts +23 -0
- package/dist/infra/validation/create-zod-dto.js +35 -0
- package/dist/infra/validation/parse-with-zod.d.ts +7 -0
- package/dist/infra/validation/parse-with-zod.js +12 -0
- package/dist/infra/validation/validation.module.d.ts +3 -0
- package/dist/infra/validation/validation.module.js +16 -0
- package/dist/infra/validation/zod-params.d.ts +7 -0
- package/dist/infra/validation/zod-params.js +42 -0
- package/dist/infra/validation/zod-validation.pipe.d.ts +11 -0
- package/dist/infra/validation/zod-validation.pipe.js +31 -0
- package/dist/kernel.d.ts +9 -244
- package/dist/kernel.js +8 -1305
- package/dist/kernel.module.d.ts +17 -0
- package/dist/kernel.module.js +136 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +140 -0
- package/dist/lifecycle/kernel-lifecycle.js +456 -0
- package/dist/lifecycle/tokens.d.ts +3 -0
- package/dist/lifecycle/tokens.js +3 -0
- package/dist/log-context.d.ts +2 -0
- package/dist/log-context.js +4 -0
- package/dist/models/models.module.d.ts +3 -0
- package/dist/models/models.module.js +24 -0
- package/dist/models/prices.d.ts +8 -2
- package/dist/models/prices.js +65 -37
- package/dist/models/purposes.controller.d.ts +1 -1
- package/dist/models/purposes.controller.js +5 -6
- package/dist/models/purposes.d.ts +35 -13
- package/dist/models/purposes.js +101 -51
- package/dist/orgs/directory-sync.controller.d.ts +1 -1
- package/dist/orgs/directory-sync.controller.js +2 -2
- package/dist/orgs/directory-sync.d.ts +61 -31
- package/dist/orgs/directory-sync.js +212 -125
- package/dist/orgs/invitations.controller.d.ts +8 -8
- package/dist/orgs/invitations.controller.js +27 -26
- package/dist/orgs/invitations.service.d.ts +12 -9
- package/dist/orgs/invitations.service.js +130 -92
- package/dist/orgs/job-ids.d.ts +8 -0
- package/dist/orgs/job-ids.js +8 -0
- package/dist/orgs/members.service.d.ts +19 -12
- package/dist/orgs/members.service.js +161 -117
- package/dist/orgs/offboarding.d.ts +54 -57
- package/dist/orgs/offboarding.js +161 -71
- package/dist/orgs/org-lock.d.ts +28 -19
- package/dist/orgs/org-lock.js +81 -35
- package/dist/orgs/org.guard.d.ts +1 -1
- package/dist/orgs/org.guard.js +2 -2
- package/dist/orgs/orgs.controller.d.ts +13 -13
- package/dist/orgs/orgs.controller.js +29 -17
- package/dist/orgs/orgs.module.d.ts +6 -0
- package/dist/orgs/orgs.module.js +68 -0
- package/dist/orgs/orgs.service.d.ts +30 -19
- package/dist/orgs/orgs.service.js +139 -86
- package/dist/orgs/settings.controller.d.ts +1 -1
- package/dist/orgs/settings.controller.js +8 -6
- package/dist/orgs/settings.service.d.ts +16 -10
- package/dist/orgs/settings.service.js +77 -48
- package/dist/overrides.d.ts +56 -0
- package/dist/overrides.js +30 -0
- package/dist/roles/gateway-role.d.ts +43 -0
- package/dist/roles/gateway-role.js +98 -0
- package/dist/roles/gateway.module.d.ts +8 -0
- package/dist/roles/gateway.module.js +28 -0
- package/dist/roles/worker-role.d.ts +63 -0
- package/dist/roles/worker-role.js +144 -0
- package/dist/roles/worker.module.d.ts +14 -0
- package/dist/roles/worker.module.js +90 -0
- package/dist/runtime/abort.js +19 -2
- package/dist/runtime/checkpointer.d.ts +8 -3
- package/dist/runtime/checkpointer.js +87 -55
- package/dist/runtime/context/build.d.ts +6 -6
- package/dist/runtime/context/build.js +18 -8
- package/dist/runtime/context/claude-tools.d.ts +2 -1
- package/dist/runtime/context/claude-tools.js +9 -10
- package/dist/runtime/context/legacy-text.d.ts +22 -0
- package/dist/runtime/context/legacy-text.js +37 -0
- package/dist/runtime/context/skills.d.ts +29 -11
- package/dist/runtime/context/skills.js +37 -30
- package/dist/runtime/conversation-lock.d.ts +20 -11
- package/dist/runtime/conversation-lock.js +62 -72
- package/dist/runtime/hook-calls.d.ts +3 -3
- package/dist/runtime/hook-calls.js +1 -6
- package/dist/runtime/job-ids.d.ts +10 -0
- package/dist/runtime/job-ids.js +10 -0
- package/dist/runtime/langgraph-loop.js +1 -1
- package/dist/runtime/loop.d.ts +8 -1
- package/dist/runtime/loop.js +14 -0
- package/dist/runtime/maintenance-queue.d.ts +10 -0
- package/dist/runtime/maintenance-queue.js +10 -0
- package/dist/runtime/maintenance.d.ts +45 -74
- package/dist/runtime/maintenance.js +139 -137
- package/dist/runtime/model-call.d.ts +7 -4
- package/dist/runtime/model-call.js +25 -58
- package/dist/runtime/providers.d.ts +17 -6
- package/dist/runtime/providers.js +66 -25
- package/dist/runtime/quota.d.ts +17 -3
- package/dist/runtime/quota.js +27 -2
- package/dist/runtime/retired-schedulers.d.ts +7 -0
- package/dist/runtime/retired-schedulers.js +31 -0
- package/dist/runtime/run-control.d.ts +33 -0
- package/dist/runtime/run-control.js +77 -0
- package/dist/runtime/run-finish.d.ts +27 -18
- package/dist/runtime/run-finish.js +98 -51
- package/dist/runtime/run-jobs.d.ts +48 -0
- package/dist/runtime/run-jobs.js +95 -0
- package/dist/runtime/run-processors.d.ts +60 -0
- package/dist/runtime/run-processors.js +185 -0
- package/dist/runtime/run-queue.d.ts +32 -57
- package/dist/runtime/run-queue.js +291 -295
- package/dist/runtime/run-steps.d.ts +39 -0
- package/dist/runtime/run-steps.js +96 -0
- package/dist/runtime/run-worker.d.ts +122 -76
- package/dist/runtime/run-worker.js +343 -229
- package/dist/runtime/runtime.module.d.ts +10 -0
- package/dist/runtime/runtime.module.js +112 -0
- package/dist/runtime/step-log.d.ts +40 -0
- package/dist/runtime/step-log.js +94 -0
- package/dist/runtime/stream.controller.d.ts +5 -8
- package/dist/runtime/stream.controller.js +14 -12
- package/dist/runtime/stream.d.ts +24 -6
- package/dist/runtime/stream.js +78 -7
- package/dist/runtime/subagents/child.d.ts +3 -44
- package/dist/runtime/subagents/child.js +0 -79
- package/dist/runtime/subagents/definition.d.ts +5 -10
- package/dist/runtime/subagents/definition.js +13 -14
- package/dist/runtime/subagents/dispatch.d.ts +89 -8
- package/dist/runtime/subagents/dispatch.js +137 -142
- package/dist/runtime/subagents/limits.d.ts +9 -4
- package/dist/runtime/subagents/limits.js +4 -2
- package/dist/runtime/subagents/org-agents.d.ts +4 -4
- package/dist/runtime/subagents/org-agents.js +3 -2
- package/dist/runtime/subagents/progress.d.ts +2 -2
- package/dist/runtime/subagents/roster.d.ts +4 -4
- package/dist/runtime/subagents/roster.js +2 -2
- package/dist/runtime/subagents/skill-fork.d.ts +8 -9
- package/dist/runtime/subagents/skill-fork.js +17 -6
- package/dist/runtime/subagents/subagents.service.d.ts +40 -0
- package/dist/runtime/subagents/subagents.service.js +101 -0
- package/dist/runtime/usage-report.d.ts +94 -52
- package/dist/runtime/usage-report.js +200 -100
- package/dist/runtime/waits.d.ts +127 -59
- package/dist/runtime/waits.js +433 -210
- package/dist/sandbox/job-ids.d.ts +10 -0
- package/dist/sandbox/job-ids.js +10 -0
- package/dist/sandbox/jobs.d.ts +41 -0
- package/dist/sandbox/jobs.js +113 -0
- package/dist/sandbox/leases.d.ts +39 -31
- package/dist/sandbox/leases.js +117 -257
- package/dist/sandbox/providers.d.ts +19 -0
- package/dist/sandbox/providers.js +38 -0
- package/dist/sandbox/sandbox.module.d.ts +8 -0
- package/dist/sandbox/sandbox.module.js +30 -0
- package/dist/sandbox/sandbox.service.d.ts +24 -29
- package/dist/sandbox/sandbox.service.js +106 -75
- package/dist/skills/catalog.d.ts +37 -24
- package/dist/skills/catalog.js +100 -57
- package/dist/skills/changes.controller.d.ts +4 -4
- package/dist/skills/changes.controller.js +15 -9
- package/dist/skills/changes.service.d.ts +30 -20
- package/dist/skills/changes.service.js +425 -367
- package/dist/skills/invocable.controller.d.ts +1 -1
- package/dist/skills/invocable.controller.js +8 -5
- package/dist/skills/invocation-keys.d.ts +1 -1
- package/dist/skills/invocation-keys.js +1 -1
- package/dist/skills/invoke.d.ts +17 -16
- package/dist/skills/invoke.js +53 -21
- package/dist/skills/skills.controller.d.ts +1 -1
- package/dist/skills/skills.controller.js +11 -6
- package/dist/skills/skills.module.d.ts +6 -0
- package/dist/skills/skills.module.js +30 -0
- package/dist/skills/skills.service.d.ts +47 -30
- package/dist/skills/skills.service.js +221 -158
- package/dist/storage/job-ids.d.ts +6 -0
- package/dist/storage/job-ids.js +6 -0
- package/dist/storage/purge.d.ts +22 -7
- package/dist/storage/purge.js +55 -3
- package/dist/storage/storage.module.d.ts +6 -0
- package/dist/storage/storage.module.js +23 -0
- package/dist/storage/storage.service.d.ts +18 -4
- package/dist/storage/storage.service.js +44 -3
- package/dist/tools/approvals.controller.d.ts +1 -1
- package/dist/tools/approvals.controller.js +12 -8
- package/dist/tools/approvals.service.d.ts +33 -25
- package/dist/tools/approvals.service.js +343 -259
- package/dist/tools/breaker.d.ts +2 -2
- package/dist/tools/breaker.js +21 -3
- package/dist/tools/builtin-names.d.ts +73 -0
- package/dist/tools/builtin-names.js +116 -0
- package/dist/tools/builtins/agent.d.ts +7 -7
- package/dist/tools/builtins/agent.js +7 -11
- package/dist/tools/builtins/ask-user.d.ts +3 -3
- package/dist/tools/builtins/ask-user.js +3 -3
- package/dist/tools/builtins/builtin-tools.d.ts +21 -0
- package/dist/tools/builtins/builtin-tools.js +80 -0
- package/dist/tools/builtins/read-tool-output.d.ts +3 -3
- package/dist/tools/builtins/read-tool-output.js +3 -3
- package/dist/tools/builtins/sandbox/bash.d.ts +5 -5
- package/dist/tools/builtins/sandbox/bash.js +33 -30
- package/dist/tools/builtins/sandbox/common.d.ts +5 -4
- package/dist/tools/builtins/sandbox/common.js +2 -2
- package/dist/tools/builtins/sandbox/deliver.d.ts +1 -1
- package/dist/tools/builtins/sandbox/deliver.js +13 -13
- package/dist/tools/builtins/sandbox/edit.d.ts +1 -1
- package/dist/tools/builtins/sandbox/edit.js +42 -31
- package/dist/tools/builtins/sandbox/file-state.d.ts +34 -0
- package/dist/tools/builtins/sandbox/file-state.js +34 -0
- package/dist/tools/builtins/sandbox/glob-match.d.ts +1 -1
- package/dist/tools/builtins/sandbox/glob-match.js +1 -1
- package/dist/tools/builtins/sandbox/glob.d.ts +1 -1
- package/dist/tools/builtins/sandbox/glob.js +6 -6
- package/dist/tools/builtins/sandbox/grep.d.ts +7 -4
- package/dist/tools/builtins/sandbox/grep.js +149 -32
- 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.d.ts +2 -2
- package/dist/tools/builtins/sandbox/read.js +22 -15
- package/dist/tools/builtins/sandbox/write.d.ts +1 -1
- package/dist/tools/builtins/sandbox/write.js +38 -34
- package/dist/tools/builtins/skill-load.d.ts +6 -6
- package/dist/tools/builtins/skill-load.js +33 -17
- package/dist/tools/builtins/skill-write.d.ts +4 -4
- package/dist/tools/builtins/skill-write.js +10 -10
- package/dist/tools/builtins/tool-search.d.ts +13 -9
- package/dist/tools/builtins/tool-search.js +25 -14
- package/dist/tools/canonical-json.d.ts +6 -0
- package/dist/tools/canonical-json.js +16 -0
- package/dist/tools/connector-content.controller.d.ts +1 -1
- package/dist/tools/connector-content.controller.js +11 -6
- package/dist/tools/connector-content.d.ts +12 -15
- package/dist/tools/connector-content.js +53 -18
- package/dist/tools/connectors.controller.d.ts +1 -1
- package/dist/tools/connectors.controller.js +21 -10
- package/dist/tools/connectors.service.d.ts +31 -13
- package/dist/tools/connectors.service.js +438 -348
- package/dist/tools/credentials.d.ts +17 -20
- package/dist/tools/credentials.js +55 -34
- package/dist/tools/display-names.d.ts +9 -0
- package/dist/tools/display-names.js +24 -0
- package/dist/tools/drift.d.ts +29 -41
- package/dist/tools/drift.js +116 -84
- package/dist/tools/elicitation.js +1 -1
- package/dist/tools/info.d.ts +32 -13
- package/dist/tools/info.js +88 -39
- package/dist/tools/job-ids.d.ts +13 -0
- package/dist/tools/job-ids.js +15 -0
- package/dist/tools/jobs.d.ts +24 -0
- package/dist/tools/jobs.js +69 -0
- package/dist/tools/legacy-data.d.ts +34 -0
- package/dist/tools/legacy-data.js +76 -0
- package/dist/tools/legacy-keys.d.ts +51 -0
- package/dist/tools/legacy-keys.js +115 -0
- package/dist/tools/naming.d.ts +1 -5
- package/dist/tools/naming.js +1 -7
- package/dist/tools/oauth/flow-paths.d.ts +16 -0
- package/dist/tools/oauth/flow-paths.js +38 -0
- package/dist/tools/oauth/flow.d.ts +30 -30
- package/dist/tools/oauth/flow.js +109 -81
- package/dist/tools/oauth/oauth.controller.d.ts +3 -3
- package/dist/tools/oauth/oauth.controller.js +12 -9
- package/dist/tools/oauth/tokens.d.ts +11 -3
- package/dist/tools/oauth/tokens.js +15 -14
- package/dist/tools/outputs.d.ts +13 -4
- package/dist/tools/outputs.js +48 -4
- package/dist/tools/pipeline.d.ts +72 -50
- package/dist/tools/pipeline.js +239 -100
- package/dist/tools/policy.d.ts +3 -16
- package/dist/tools/policy.js +13 -19
- package/dist/tools/questions.controller.d.ts +2 -2
- package/dist/tools/questions.controller.js +9 -6
- package/dist/tools/questions.service.d.ts +26 -25
- package/dist/tools/questions.service.js +201 -142
- package/dist/tools/registry.d.ts +43 -38
- package/dist/tools/registry.js +100 -72
- package/dist/tools/resources.d.ts +1 -1
- package/dist/tools/resources.js +1 -1
- package/dist/tools/specs.d.ts +5 -4
- package/dist/tools/specs.js +3 -1
- package/dist/tools/tools.module.d.ts +10 -0
- package/dist/tools/tools.module.js +91 -0
- package/dist/ui/call-extension.d.ts +16 -0
- package/dist/ui/call-extension.js +38 -0
- package/dist/ui/embed-token.d.ts +9 -5
- package/dist/ui/embed-token.js +34 -6
- package/dist/ui/ui-stream.d.ts +22 -17
- package/dist/ui/ui-stream.js +72 -12
- package/dist/ui/ui.module.d.ts +7 -0
- package/dist/ui/ui.module.js +28 -0
- package/dist/ui/views.controller.d.ts +14 -12
- package/dist/ui/views.controller.js +32 -25
- package/dist/ui/views.d.ts +9 -57
- package/dist/ui/views.js +43 -45
- package/package.json +10 -3
- package/src/migrations/0063_tool_keys_claude_code.sql +220 -0
- package/dist/http/health.controller.d.ts +0 -26
- package/dist/http/health.controller.js +0 -79
- package/dist/http/tokens.d.ts +0 -131
- package/dist/http/tokens.js +0 -131
- package/dist/http/zod.pipe.d.ts +0 -8
- package/dist/http/zod.pipe.js +0 -14
- package/dist/identity/rate-limit.d.ts +0 -55
- package/dist/identity/rate-limit.js +0 -121
- package/dist/sandbox/lifecycle.d.ts +0 -21
- package/dist/sandbox/lifecycle.js +0 -68
- package/dist/tools/builtins/sandbox/names.d.ts +0 -7
- package/dist/tools/builtins/sandbox/names.js +0 -20
- /package/dist/http/{gateway.module.d.ts → gateway-routes.d.ts} +0 -0
- /package/dist/http/{gateway.module.js → gateway-routes.js} +0 -0
package/dist/tools/pipeline.js
CHANGED
|
@@ -1,25 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { parseToolKey, ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
2
12
|
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
13
|
+
import { EventLog } from "../conversations/event-log.js";
|
|
3
14
|
import { ToolViewSchema } from "../conversations/events.js";
|
|
4
15
|
import { clipText } from "../extensions/hooks.js";
|
|
16
|
+
import { ExtensionHost } from "../extensions/host.js";
|
|
5
17
|
import { ExtensionUnloadedError, PLUGIN_UNLOADED_TOOL_ERROR } from "../extensions/inflight.js";
|
|
6
18
|
import { audit } from "../identity/audit.js";
|
|
19
|
+
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
20
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
21
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
22
|
+
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
23
|
+
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
7
24
|
import { UNKNOWN_RESULT_TEXT } from "../runtime/context/pairing.js";
|
|
8
25
|
import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookScope, } from "../runtime/hook-calls.js";
|
|
9
|
-
import {
|
|
26
|
+
import { subagentsWait, subagentWaitingIdemKey, } from "../runtime/loop.js";
|
|
10
27
|
import { assistantIdemKey, MAX_MODEL_ATTEMPTS, modelCallIdemKey } from "../runtime/model-call.js";
|
|
11
28
|
import { TERMINAL_STATUSES } from "../runtime/run-finish.js";
|
|
12
29
|
import { childResult, dispatchOfCall, finishedEvent, } from "../runtime/subagents/child.js";
|
|
13
30
|
import { forkSeqOfCall, pairStoppedForks } from "../runtime/subagents/skill-fork.js";
|
|
31
|
+
import { SubagentsService } from "../runtime/subagents/subagents.service.js";
|
|
14
32
|
import { skillLoadOfferedIn } from "../skills/catalog.js";
|
|
15
|
-
import {
|
|
33
|
+
import { ApprovalsService } from "./approvals.service.js";
|
|
34
|
+
import { Breaker, breakerOpenMessage } from "./breaker.js";
|
|
35
|
+
import { TOOL_SEARCH } from "./builtin-names.js";
|
|
16
36
|
import { AGENT_STOPPED_WITH_RUN_TEXT, AGENT_TOOL, AgentToolInput, } from "./builtins/agent.js";
|
|
17
37
|
import { isAlwaysLoaded, notLoadedText } from "./builtins/tool-search.js";
|
|
18
|
-
import { CredentialMissing } from "./credentials.js";
|
|
38
|
+
import { CredentialMissing, Credentials } from "./credentials.js";
|
|
39
|
+
import { ToolDrift } from "./drift.js";
|
|
19
40
|
import { ElicitationSession } from "./elicitation.js";
|
|
20
|
-
import {
|
|
41
|
+
import { legacyHint, legacyToolInput, legacyToolKey } from "./legacy-keys.js";
|
|
42
|
+
import { renderResult, resolveOutputRefs, spillIfLarge, ToolOutputs } from "./outputs.js";
|
|
21
43
|
import { createDecidePolicy } from "./policy.js";
|
|
44
|
+
import { QuestionsService } from "./questions.service.js";
|
|
22
45
|
import { redactDeep, redactorFor } from "./redact.js";
|
|
46
|
+
import { ToolRegistry, } from "./registry.js";
|
|
23
47
|
import { runResourceTool } from "./resources.js";
|
|
24
48
|
import { validateInput } from "./validate.js";
|
|
25
49
|
// ---- 模型可见文案(英文) ----
|
|
@@ -45,8 +69,27 @@ export const RUN_STOPPED_TEXT = "The run was stopped before this tool call was e
|
|
|
45
69
|
export const RUN_STOPPED_DURING_TEXT = "The run was stopped while this tool call was running; its outcome is unknown. Verify before retrying.";
|
|
46
70
|
const timeoutText = (key, ms) => `Tool ${key} timed out after ${ms / 1000}s. The operation may or may not have completed; verify before retrying.`;
|
|
47
71
|
const failedText = (key, errName) => `Tool ${key} failed (${errName}). The operation may not have completed; check before retrying or try another approach.`;
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
/** The connector slugs and extension names among the run's tools (to read old `<x>__<tool>` keys). */
|
|
78
|
+
const legacyScopeOf = (tools) => {
|
|
79
|
+
const connectorSlugs = new Set();
|
|
80
|
+
const extensionNames = new Set();
|
|
81
|
+
for (const t of tools) {
|
|
82
|
+
const p = parseToolKey(t.key);
|
|
83
|
+
if (p?.kind === "connector")
|
|
84
|
+
connectorSlugs.add(p.slug);
|
|
85
|
+
else if (p?.kind === "extension")
|
|
86
|
+
extensionNames.add(p.plugin);
|
|
87
|
+
}
|
|
88
|
+
return { connectorSlugs, extensionNames };
|
|
89
|
+
};
|
|
90
|
+
const unknownToolText = (name, keys, toolSearch, hint = null) => `Unknown tool "${name}". Available tools: ${keys.length === 0 ? "(none)" : keys.join(", ")}.` +
|
|
91
|
+
(toolSearch ? " Use ToolSearch to load other tools." : "") +
|
|
92
|
+
(hint === null ? "" : ` ${hint}`);
|
|
50
93
|
const unavailableText = (name, reason) => `Tool "${name}" is unavailable: ${reason}.`;
|
|
51
94
|
const deniedText = (key) => `Tool ${key} is denied by policy.`;
|
|
52
95
|
/** Longest hook reason quoted in {@link hookDeniedText}. */
|
|
@@ -60,22 +103,10 @@ const invalidFormText = (key, problems) => `Tool ${key} returned an invalid inpu
|
|
|
60
103
|
const stateTooLargeText = (key) => `Tool ${key} returned input state larger than ${MAX_INPUT_STATE_BYTES / 1024} KB.`;
|
|
61
104
|
const personalMissingText = (connectorName) => `The user has not connected ${connectorName}. A connect card was shown; ask the user to connect, then retry.`;
|
|
62
105
|
const orgMissingText = (connectorName) => `${connectorName} has no organization credential configured; ask an organization admin to set it up.`;
|
|
106
|
+
/** Optional provider: the pipeline's {@link ToolPipelineHooks} (tests). */
|
|
107
|
+
export const TOOL_PIPELINE_HOOKS = Symbol("TOOL_PIPELINE_HOOKS");
|
|
63
108
|
/** `runCall` dispatched a sub-agent: the call stays open until the child run finishes. */
|
|
64
109
|
const OPEN = "open";
|
|
65
|
-
/**
|
|
66
|
-
* The wait of a step whose sub-agents still run (spec §7.2): id `sa-<runId>-<step>`, expiring after
|
|
67
|
-
* the approval timeout plus one run's duration plus 10 minutes (a child may itself wait for an
|
|
68
|
-
* approval); the timeout is a safety net.
|
|
69
|
-
*/
|
|
70
|
-
export function subagentsWait(runId, step, config, now = Date.now()) {
|
|
71
|
-
const ms = config.tools.approvalTimeoutHours * 3_600_000 + config.runtime.maxRunSeconds * 1000 + 600_000;
|
|
72
|
-
return {
|
|
73
|
-
kind: "subagents",
|
|
74
|
-
id: subagentsWaitId(runId, step),
|
|
75
|
-
expiresAt: new Date(now + ms).toISOString(),
|
|
76
|
-
step,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
110
|
const approvalAuthorization = (a) => ({
|
|
80
111
|
approvalId: a.id,
|
|
81
112
|
approvedByAccountId: a.decidedBy,
|
|
@@ -143,12 +174,47 @@ const inputWait = (q) => ({
|
|
|
143
174
|
*
|
|
144
175
|
* 有副作用不盲目重跑(spec 4.3):执行前写 `tool_call_started`;续跑时「有开始无结果」的调用记为结果未知,不再执行。
|
|
145
176
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
177
|
+
let ToolPipeline = class ToolPipeline {
|
|
178
|
+
config;
|
|
179
|
+
txHost;
|
|
148
180
|
decide;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
181
|
+
deps;
|
|
182
|
+
constructor(kdb, eventLog,
|
|
183
|
+
/** The `Agent` tool's sub-agent dispatch; absent (tests): `Agent` calls are refused. */
|
|
184
|
+
subagents, registry, credentials, breaker, outputs, approvals, questions, config, log,
|
|
185
|
+
/** Plugin hooks and inline ui contributions; absent (tests): no hooks, cards dropped. */
|
|
186
|
+
host, drift, txHost, hooks) {
|
|
187
|
+
this.config = config;
|
|
188
|
+
this.txHost = txHost;
|
|
189
|
+
this.deps = {
|
|
190
|
+
get db() {
|
|
191
|
+
return kdb.db;
|
|
192
|
+
},
|
|
193
|
+
eventLog,
|
|
194
|
+
registry,
|
|
195
|
+
credentials,
|
|
196
|
+
breaker,
|
|
197
|
+
outputs,
|
|
198
|
+
approvals,
|
|
199
|
+
questions,
|
|
200
|
+
log,
|
|
201
|
+
hooks,
|
|
202
|
+
get pluginHooks() {
|
|
203
|
+
return host?.hooks;
|
|
204
|
+
},
|
|
205
|
+
inlineViews: (plugin) => new Set((host?.current(plugin)?.manifest.ui ?? [])
|
|
206
|
+
.filter((c) => c.place === "inline" && c.aliasOf === undefined)
|
|
207
|
+
.map((c) => c.id)),
|
|
208
|
+
onToolsChanged: (orgId, connectorId) => {
|
|
209
|
+
void drift?.onToolsChanged(orgId, connectorId);
|
|
210
|
+
},
|
|
211
|
+
get subagents() {
|
|
212
|
+
return subagents ? { dispatch: (a) => subagents.dispatch(a) } : undefined;
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
const decide = hooks?.decidePolicy;
|
|
216
|
+
// the default policy reads live, on the context's handle
|
|
217
|
+
this.decide = decide ?? ((tool, def, c) => createDecidePolicy(kdb.db)(tool, def, c));
|
|
152
218
|
}
|
|
153
219
|
/**
|
|
154
220
|
* tools 节点:按顺序处理本步 assistant 消息里的全部 `tool_call`,每个调用都以一条 `tool_result` 结束
|
|
@@ -168,7 +234,7 @@ export class ToolPipeline {
|
|
|
168
234
|
// 每步实时解析(连接器 / 插件状态可能在模型调用之后变化)
|
|
169
235
|
if (!resolved) {
|
|
170
236
|
// the request builder's rule: a skills catalog snapshot (even an empty one) or a person's
|
|
171
|
-
// skill invocation in the log →
|
|
237
|
+
// skill invocation in the log → Skill is offered (see skillLoadOffered)
|
|
172
238
|
const skillLoad = await skillLoadOfferedIn(this.deps.db, this.deps.eventLog, ctx.conversationId);
|
|
173
239
|
resolved = await this.deps.registry.forAgent(ctx.orgId, {
|
|
174
240
|
tools: ctx.agent.tools ?? [],
|
|
@@ -178,13 +244,13 @@ export class ToolPipeline {
|
|
|
178
244
|
}
|
|
179
245
|
return resolved;
|
|
180
246
|
};
|
|
181
|
-
// `
|
|
247
|
+
// `Agent` calls whose sub-agent still runs (spec §7.1): a dispatch never blocks later calls;
|
|
182
248
|
// once every call was handled, the step waits for them
|
|
183
249
|
let open = 0;
|
|
184
250
|
for (const call of calls) {
|
|
185
251
|
if (await eventLog.findByIdem(ctx.conversationId, idem.result(ctx.runId, call.id)))
|
|
186
252
|
continue;
|
|
187
|
-
if (call.name
|
|
253
|
+
if (isAgentCallKey(call.name)) {
|
|
188
254
|
const row = await dispatchOfCall(this.deps.db, ctx.runId, call.id);
|
|
189
255
|
if (row) {
|
|
190
256
|
if (!(await this.finishAgentCall(ctx, row, call, resolve)))
|
|
@@ -203,9 +269,7 @@ export class ToolPipeline {
|
|
|
203
269
|
// their calls get their results now, and the children are stopped after the run's terminal
|
|
204
270
|
// commit (spec §12)
|
|
205
271
|
if (ctx.signal.aborted) {
|
|
206
|
-
const stopped = await this.
|
|
207
|
-
.transaction()
|
|
208
|
-
.execute((t) => this.stopOpenAgentCalls(t, ctx.runId, ctx.agent));
|
|
272
|
+
const stopped = await this.stopOpenAgentCallsNow(ctx.runId, ctx.agent);
|
|
209
273
|
if (stopped.toSeq !== null) {
|
|
210
274
|
await eventLog.notify(ctx.conversationId, stopped.toSeq);
|
|
211
275
|
}
|
|
@@ -214,13 +278,13 @@ export class ToolPipeline {
|
|
|
214
278
|
}
|
|
215
279
|
return {
|
|
216
280
|
kind: "suspended",
|
|
217
|
-
waitingFor: subagentsWait(ctx.runId, ctx.step, this.
|
|
281
|
+
waitingFor: subagentsWait(ctx.runId, ctx.step, this.config.get()),
|
|
218
282
|
};
|
|
219
283
|
}
|
|
220
284
|
return { kind: "done" };
|
|
221
285
|
}
|
|
222
286
|
/**
|
|
223
|
-
* An `
|
|
287
|
+
* An `Agent` call that was dispatched (spec §7.1 "already dispatched"): when its child run is
|
|
224
288
|
* terminal, writes the parent's `subagent_finished` (if the child's finisher did not) and the
|
|
225
289
|
* call's `tool_result` from the child's log, and returns true; else false (still open).
|
|
226
290
|
*
|
|
@@ -236,12 +300,13 @@ export class ToolPipeline {
|
|
|
236
300
|
const r = await childResult(this.deps.eventLog, row, { modelGiven });
|
|
237
301
|
if (!r)
|
|
238
302
|
return false;
|
|
239
|
-
// No spec-hash check as in processCall: an `
|
|
303
|
+
// No spec-hash check as in processCall: an `Agent` call writes no tool_call_started holding
|
|
240
304
|
// the executed definition's hash, and its description changes with the roster and limits
|
|
241
305
|
// while the child runs. The call's approval (forCall: its latest) is by construction the one
|
|
242
306
|
// that let this dispatch start, since a dispatch happens only after an approved decision.
|
|
243
307
|
const approval = await this.deps.approvals.forCall(ctx.runId, call.id);
|
|
244
|
-
|
|
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)], {
|
|
245
310
|
durationMs: r.finished.durationMs,
|
|
246
311
|
connectorId: null,
|
|
247
312
|
...(approval?.status === "approved" && {
|
|
@@ -268,19 +333,25 @@ export class ToolPipeline {
|
|
|
268
333
|
}
|
|
269
334
|
return true;
|
|
270
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
|
+
}
|
|
271
340
|
/**
|
|
272
|
-
* Writes, in `
|
|
341
|
+
* Writes, in the caller's transaction (`mandatory`), the `tool_result` of every open `Agent` call
|
|
342
|
+
* of a run that is being stopped
|
|
273
343
|
* (sub-agents spec §12: a person stopped it while it waited on sub-agents, or its deadline or a
|
|
274
344
|
* stop hit its tools node after a dispatch). A call whose child already ended gets the child's
|
|
275
345
|
* result (and the missing `subagent_finished`); one whose child is still active gets
|
|
276
346
|
* {@link AGENT_STOPPED_WITH_RUN_TEXT}. The caller stops those children after its commit.
|
|
277
347
|
*
|
|
278
|
-
* Like every `
|
|
348
|
+
* Like every `Agent` result (see {@link finishAgentCall}), each is audited `tool.called` in it
|
|
279
349
|
* (duration: the child's, or the time since the dispatch) and fires `tool.postExecute`, through
|
|
280
350
|
* `fire()`, which the caller runs after its commit. Returns the steps and calls written (the
|
|
281
351
|
* caller must not write a "not executed" result for them) and the highest seq written.
|
|
282
352
|
*/
|
|
283
|
-
async stopOpenAgentCalls(
|
|
353
|
+
async stopOpenAgentCalls(runId, agent) {
|
|
354
|
+
const t = this.deps.db;
|
|
284
355
|
// phase D: the run's fork invocation without a report gets one (a fork has no tool call)
|
|
285
356
|
const forks = await pairStoppedForks(t, this.deps.eventLog, runId);
|
|
286
357
|
const none = {
|
|
@@ -324,6 +395,8 @@ export class ToolPipeline {
|
|
|
324
395
|
return none;
|
|
325
396
|
const conversationId = run.conversation_id;
|
|
326
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();
|
|
327
400
|
const events = [];
|
|
328
401
|
const calls = [];
|
|
329
402
|
for (const d of dispatches) {
|
|
@@ -345,8 +418,11 @@ export class ToolPipeline {
|
|
|
345
418
|
.executeTakeFirst();
|
|
346
419
|
const content = msg?.payload?.content ?? [];
|
|
347
420
|
for (const b of content) {
|
|
348
|
-
if (b.type === "tool_call" && b.id !== undefined)
|
|
421
|
+
if (b.type === "tool_call" && b.id !== undefined) {
|
|
349
422
|
inputs.set(b.id, b.input);
|
|
423
|
+
if (b.name !== undefined)
|
|
424
|
+
names.set(b.id, b.name);
|
|
425
|
+
}
|
|
350
426
|
}
|
|
351
427
|
}
|
|
352
428
|
const input = inputs.get(d.parent_call_id);
|
|
@@ -386,7 +462,7 @@ export class ToolPipeline {
|
|
|
386
462
|
payload: {
|
|
387
463
|
step: d.step,
|
|
388
464
|
callId: d.parent_call_id,
|
|
389
|
-
toolKey: AGENT_TOOL,
|
|
465
|
+
toolKey: names.get(d.parent_call_id) ?? AGENT_TOOL,
|
|
390
466
|
content: r.content,
|
|
391
467
|
isError: r.isError,
|
|
392
468
|
},
|
|
@@ -395,7 +471,7 @@ export class ToolPipeline {
|
|
|
395
471
|
}
|
|
396
472
|
if (calls.length === 0)
|
|
397
473
|
return none;
|
|
398
|
-
const written = await this.deps.eventLog.
|
|
474
|
+
const written = await this.deps.eventLog.appendIn(conversationId, events);
|
|
399
475
|
for (const c of calls) {
|
|
400
476
|
const approval = await t
|
|
401
477
|
.selectFrom("approvals")
|
|
@@ -529,36 +605,48 @@ export class ToolPipeline {
|
|
|
529
605
|
await this.writeResult(ctx, call.id, key, { content, isError: true });
|
|
530
606
|
return undefined;
|
|
531
607
|
};
|
|
532
|
-
|
|
608
|
+
let tool = resolved.tools.find((t) => t.key === call.name);
|
|
609
|
+
// A call logged before the tool keys were renamed (spec 8.1): the request that issued it offered
|
|
610
|
+
// the old key. It runs as the current tool with translated input; the result keeps the logged key.
|
|
611
|
+
let legacy = false;
|
|
612
|
+
if (!tool) {
|
|
613
|
+
const next = legacyToolKey(call.name, legacyScopeOf(resolved.tools));
|
|
614
|
+
const current = next === null ? undefined : resolved.tools.find((t) => t.key === next);
|
|
615
|
+
if (current && (await this.requestToolKeys(ctx))?.has(call.name) === true) {
|
|
616
|
+
tool = current;
|
|
617
|
+
legacy = true;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
533
620
|
if (!tool) {
|
|
534
621
|
const why = resolved.unavailable.find((u) => u.ref === call.name) ??
|
|
535
622
|
resolved.hidden?.find((u) => u.ref === call.name);
|
|
536
623
|
if (why)
|
|
537
624
|
return fail(unavailableText(call.name, why.reason));
|
|
538
625
|
let keys = resolved.tools.map((t) => t.key);
|
|
539
|
-
//
|
|
626
|
+
// ToolSearch 模式:目录可能很大,只列内置工具与发出本次调用的请求里带了定义的工具
|
|
540
627
|
if (resolved.toolSearch === true) {
|
|
541
628
|
const sent = await this.sentTools(ctx);
|
|
542
629
|
if (sent !== null)
|
|
543
630
|
keys = keys.filter((k) => isAlwaysLoaded(k) || sent.has(k));
|
|
544
631
|
}
|
|
545
632
|
keys.sort();
|
|
546
|
-
return fail(unknownToolText(call.name, keys, keys.includes(
|
|
633
|
+
return fail(unknownToolText(call.name, keys, keys.includes(TOOL_SEARCH), legacyHint(call.name)));
|
|
547
634
|
}
|
|
548
|
-
|
|
549
|
-
//
|
|
550
|
-
|
|
635
|
+
const outKey = legacy ? call.name : tool.key;
|
|
636
|
+
// ToolSearch 模式下,模型只能调用请求里带了完整定义的工具:目录里有、但发出本次调用的请求没加载 →
|
|
637
|
+
// 明确错误,不自动加载(spec 5.5 / 6.3)。同一步里先 ToolSearch 再调用刚加载的工具同样报错。
|
|
638
|
+
if (!legacy && resolved.toolSearch === true && !isAlwaysLoaded(tool.key)) {
|
|
551
639
|
const sent = await this.sentTools(ctx);
|
|
552
640
|
if (sent !== null && !sent.has(tool.key))
|
|
553
|
-
return fail(notLoadedText(tool.key),
|
|
641
|
+
return fail(notLoadedText(tool.key), outKey);
|
|
554
642
|
}
|
|
555
643
|
let input;
|
|
556
644
|
try {
|
|
557
|
-
input = await resolveOutputRefs(call.input, (id) => this.deps.outputs.load({ orgId: ctx.orgId, conversationId: ctx.conversationId }, id));
|
|
645
|
+
input = await resolveOutputRefs(legacy ? legacyToolInput(call.name, call.input) : call.input, (id) => this.deps.outputs.load({ orgId: ctx.orgId, conversationId: ctx.conversationId }, id));
|
|
558
646
|
}
|
|
559
647
|
catch (e) {
|
|
560
648
|
if (e instanceof ToolError)
|
|
561
|
-
return fail(e.message,
|
|
649
|
+
return fail(e.message, outKey);
|
|
562
650
|
throw e;
|
|
563
651
|
}
|
|
564
652
|
// 连接器工具的 schema 来自连接器(不受信任):去掉有风险的关键字并限制大小 / 层数
|
|
@@ -567,7 +655,7 @@ export class ToolPipeline {
|
|
|
567
655
|
log: this.deps.log,
|
|
568
656
|
});
|
|
569
657
|
if (invalid !== null)
|
|
570
|
-
return fail(invalid,
|
|
658
|
+
return fail(invalid, outKey);
|
|
571
659
|
const decision = await this.decide(tool, ctx.agent, {
|
|
572
660
|
orgId: ctx.orgId,
|
|
573
661
|
accountId: ctx.accountId,
|
|
@@ -580,15 +668,19 @@ export class ToolPipeline {
|
|
|
580
668
|
}),
|
|
581
669
|
});
|
|
582
670
|
if (decision === "deny")
|
|
583
|
-
return fail(deniedText(tool.key),
|
|
671
|
+
return fail(deniedText(tool.key), outKey);
|
|
584
672
|
if (typeof decision === "object" && "unavailable" in decision) {
|
|
585
|
-
return fail(unavailableText(tool.key, decision.unavailable),
|
|
673
|
+
return fail(unavailableText(tool.key, decision.unavailable), outKey);
|
|
586
674
|
}
|
|
587
675
|
// 该调用已有审批(续跑)→ 按审批结果;没有且策略为 ask → 建审批并等待
|
|
588
676
|
// (不写 tool_call_started:此时尚未开始执行)。
|
|
589
677
|
let approval = await this.deps.approvals.forCall(ctx.runId, call.id);
|
|
590
678
|
// 批准的是旧定义(等待期间工具定义变了):原批准不适用于当前定义,策略仍需审批时按新定义重新审批。
|
|
591
|
-
|
|
679
|
+
// An in-flight rc call (spec §9) is the exception: its approval was asked under the rc definition
|
|
680
|
+
// of the same call, and the rename changed every builtin's definition; the person approved this
|
|
681
|
+
// very call, so the approval stands.
|
|
682
|
+
const approvedHere = approval?.status === "approved" && (legacy || approval.specHash === tool.specHash);
|
|
683
|
+
const stale = approval?.status === "approved" && !approvedHere;
|
|
592
684
|
if ((!approval || stale) && typeof decision === "object" && "ask" in decision) {
|
|
593
685
|
approval = await this.deps.approvals.request({
|
|
594
686
|
attempt: (approval?.attempt ?? 0) + 1,
|
|
@@ -608,10 +700,10 @@ export class ToolPipeline {
|
|
|
608
700
|
}
|
|
609
701
|
if (approval && approval.status !== "approved") {
|
|
610
702
|
const refused = this.refusalText(approval);
|
|
611
|
-
return refused === null ? approvalWait(approval) : fail(refused,
|
|
703
|
+
return refused === null ? approvalWait(approval) : fail(refused, outKey);
|
|
612
704
|
}
|
|
613
705
|
// 走到这里即放行:在(与当前定义一致的)审批下执行,否则是授权或策略放行
|
|
614
|
-
const authorization = approval?.status === "approved" &&
|
|
706
|
+
const authorization = approval?.status === "approved" && approvedHere
|
|
615
707
|
? approvalAuthorization(approval)
|
|
616
708
|
: typeof decision === "object" && "grant" in decision
|
|
617
709
|
? { grant: decision.grant }
|
|
@@ -626,7 +718,7 @@ export class ToolPipeline {
|
|
|
626
718
|
// written with the call's tool_result, so a call with a logged denial never runs again anyway.
|
|
627
719
|
const prior = await this.deps.eventLog.findByIdem(ctx.conversationId, idem.hookDenied(ctx.runId, call.id));
|
|
628
720
|
if (prior?.type === "hook_denied") {
|
|
629
|
-
return fail(hookDeniedText(prior.payload.plugin, prior.payload.reason),
|
|
721
|
+
return fail(hookDeniedText(prior.payload.plugin, prior.payload.reason), outKey);
|
|
630
722
|
}
|
|
631
723
|
}
|
|
632
724
|
// payload only built when a tool hook is registered (zero overhead otherwise)
|
|
@@ -648,7 +740,7 @@ export class ToolPipeline {
|
|
|
648
740
|
catch (e) {
|
|
649
741
|
// run() rejects only when the run's signal aborted: an abort, never a deny
|
|
650
742
|
if (ctx.signal.aborted)
|
|
651
|
-
return fail(RUN_STOPPED_TEXT,
|
|
743
|
+
return fail(RUN_STOPPED_TEXT, outKey);
|
|
652
744
|
throw e;
|
|
653
745
|
}
|
|
654
746
|
if (!verdict.allowed) {
|
|
@@ -666,20 +758,20 @@ export class ToolPipeline {
|
|
|
666
758
|
step: ctx.step,
|
|
667
759
|
callId: call.id,
|
|
668
760
|
});
|
|
669
|
-
await this.writeResult(ctx, call.id,
|
|
761
|
+
await this.writeResult(ctx, call.id, outKey, { content: hookDeniedText(verdict.plugin, verdict.reason), isError: true }, [event], undefined, [hookDeniedAudit(site, event.payload, verdict)]);
|
|
670
762
|
return undefined;
|
|
671
763
|
}
|
|
672
764
|
}
|
|
673
|
-
// `
|
|
765
|
+
// `Agent` (sub-agents spec §7.1): no tool_call_started; the dispatch is made durable in one
|
|
674
766
|
// transaction (its marker is the subagent_dispatches row) and the call stays open
|
|
675
767
|
const dispatcher = this.deps.subagents;
|
|
676
768
|
if (tool.source.kind === "builtin" && tool.key === AGENT_TOOL && dispatcher) {
|
|
677
769
|
const parsed = AgentToolInput.safeParse(input);
|
|
678
770
|
if (!parsed.success) {
|
|
679
|
-
return fail("Invalid agent call: pass description and prompt, and optionally subagent_type, model or resume.",
|
|
771
|
+
return fail("Invalid agent call: pass description and prompt, and optionally subagent_type, model or resume.", outKey);
|
|
680
772
|
}
|
|
681
773
|
const r = await dispatcher.dispatch({ ctx, callId: call.id, input: parsed.data });
|
|
682
|
-
return r.kind === "refused" ? fail(r.content,
|
|
774
|
+
return r.kind === "refused" ? fail(r.content, outKey) : OPEN;
|
|
683
775
|
}
|
|
684
776
|
await this.deps.eventLog.append(ctx.conversationId, [
|
|
685
777
|
{
|
|
@@ -702,7 +794,7 @@ export class ToolPipeline {
|
|
|
702
794
|
const rendered = outcome.kind === "result"
|
|
703
795
|
? renderResult(outcome.result)
|
|
704
796
|
: { text: outcome.message, contentTypes: [], isError: true };
|
|
705
|
-
// 内置工具(
|
|
797
|
+
// 内置工具(ToolSearch)报告的已加载工具:只认本步可用、非内置的 key,写进 tool_result(日志即事实源)
|
|
706
798
|
const loadedTools = outcome.kind === "result" && tool.source.kind === "builtin"
|
|
707
799
|
? loadedFrom(outcome.result, resolved.tools)
|
|
708
800
|
: [];
|
|
@@ -719,7 +811,7 @@ export class ToolPipeline {
|
|
|
719
811
|
const card = outcome.kind === "result" && tool.source.kind === "plugin"
|
|
720
812
|
? this.cardOf(outcome.result, tool.source.plugin, tool.key)
|
|
721
813
|
: undefined;
|
|
722
|
-
const cfg = this.
|
|
814
|
+
const cfg = this.config.get().tools;
|
|
723
815
|
const spilled = await spillIfLarge(rendered.text, {
|
|
724
816
|
// 内置工具可给更低的转存阈值(沙箱 bash 30000 字符)
|
|
725
817
|
spillChars: Math.min(cfg.outputSpillChars, tool.spillChars ?? Number.POSITIVE_INFINITY),
|
|
@@ -746,7 +838,7 @@ export class ToolPipeline {
|
|
|
746
838
|
},
|
|
747
839
|
]
|
|
748
840
|
: [];
|
|
749
|
-
await this.writeResult(ctx, call.id,
|
|
841
|
+
await this.writeResult(ctx, call.id, outKey, {
|
|
750
842
|
content: spilled.content,
|
|
751
843
|
isError: rendered.isError,
|
|
752
844
|
...(spilled.outputId !== undefined && { outputId: spilled.outputId }),
|
|
@@ -787,9 +879,24 @@ export class ToolPipeline {
|
|
|
787
879
|
}
|
|
788
880
|
return undefined;
|
|
789
881
|
}
|
|
882
|
+
/**
|
|
883
|
+
* Every tool key the request that issued this step's calls offered (`request.tools` plus the
|
|
884
|
+
* `catalog` keys), in any mode; null when its model_call is not found. Used to tell a call to an
|
|
885
|
+
* old key that was offered (in flight across the rename) from one that never was.
|
|
886
|
+
*/
|
|
887
|
+
async requestToolKeys(ctx) {
|
|
888
|
+
for (let attempt = MAX_MODEL_ATTEMPTS; attempt >= 1; attempt--) {
|
|
889
|
+
const e = await this.deps.eventLog.findByIdem(ctx.conversationId, modelCallIdemKey(ctx.runId, ctx.step, attempt));
|
|
890
|
+
if (e?.type !== "model_call")
|
|
891
|
+
continue;
|
|
892
|
+
const { tools, catalog } = e.payload.request;
|
|
893
|
+
return new Set([...(tools ?? []), ...(catalog ?? [])].map((t) => t.key));
|
|
894
|
+
}
|
|
895
|
+
return null;
|
|
896
|
+
}
|
|
790
897
|
/**
|
|
791
898
|
* 发出本步调用的请求里带了完整定义的工具 key:本步最后一次尝试的 `model_call.request.tools`
|
|
792
|
-
* (`assistant_message` 来自最后一次尝试)。该请求不在
|
|
899
|
+
* (`assistant_message` 来自最后一次尝试)。该请求不在 ToolSearch 模式(没有 `catalog`,工具全部发送)
|
|
793
900
|
* 或找不到 model_call 时返回 null(不做加载检查)。已加载集合由此从日志得出,不放进程内存。
|
|
794
901
|
*/
|
|
795
902
|
async sentTools(ctx) {
|
|
@@ -863,7 +970,7 @@ export class ToolPipeline {
|
|
|
863
970
|
const handler = this.deps.registry.handler(tool.source);
|
|
864
971
|
if (!handler)
|
|
865
972
|
return { kind: "error", message: `Tool ${tool.key} is no longer available.` };
|
|
866
|
-
// 插件处理函数只拿到 SDK 的 ToolCallContext;内置工具另外拿到本步解析出的工具(
|
|
973
|
+
// 插件处理函数只拿到 SDK 的 ToolCallContext;内置工具另外拿到本步解析出的工具(ToolSearch 用)
|
|
867
974
|
const base = {
|
|
868
975
|
orgId: ctx.orgId,
|
|
869
976
|
accountId: ctx.accountId,
|
|
@@ -880,7 +987,7 @@ export class ToolPipeline {
|
|
|
880
987
|
ctx.parent !== undefined && { sandboxConversationId: ctx.parent.conversationId }),
|
|
881
988
|
};
|
|
882
989
|
// 内置工具可按输入给自己的时限(沙箱 bash 按命令超时加余量);缺省 tools.timeoutMs
|
|
883
|
-
const timeoutMs = tool.timeoutMs?.(input) ?? this.
|
|
990
|
+
const timeoutMs = tool.timeoutMs?.(input) ?? this.config.get().tools.timeoutMs;
|
|
884
991
|
try {
|
|
885
992
|
const r = await this.bounded(ctx.signal, (signal) => handler(input, { ...base, signal }), undefined, timeoutMs);
|
|
886
993
|
if (r === "timeout") {
|
|
@@ -898,7 +1005,7 @@ export class ToolPipeline {
|
|
|
898
1005
|
}
|
|
899
1006
|
}
|
|
900
1007
|
async executeConnector(tool, source, input, ctx, resume) {
|
|
901
|
-
const { db, registry, breaker, credentials
|
|
1008
|
+
const { db, registry, breaker, credentials } = this.deps;
|
|
902
1009
|
const { orgId } = ctx;
|
|
903
1010
|
const connectorId = source.connectorId;
|
|
904
1011
|
const app = await db
|
|
@@ -1011,7 +1118,7 @@ export class ToolPipeline {
|
|
|
1011
1118
|
onElicit: elicit.handle,
|
|
1012
1119
|
onToolsChanged: () => {
|
|
1013
1120
|
try {
|
|
1014
|
-
this.deps.onToolsChanged
|
|
1121
|
+
this.deps.onToolsChanged(orgId, connectorId);
|
|
1015
1122
|
}
|
|
1016
1123
|
catch (err) {
|
|
1017
1124
|
this.deps.log.warn("tools changed notification failed", {
|
|
@@ -1037,7 +1144,7 @@ export class ToolPipeline {
|
|
|
1037
1144
|
return ask;
|
|
1038
1145
|
if (r === "timeout") {
|
|
1039
1146
|
await breaker.failure(orgId, connectorId);
|
|
1040
|
-
return { kind: "error", message: timeoutText(tool.key, config().tools.timeoutMs) };
|
|
1147
|
+
return { kind: "error", message: timeoutText(tool.key, this.config.get().tools.timeoutMs) };
|
|
1041
1148
|
}
|
|
1042
1149
|
// 工具自己报告的错误(isError)说明服务可用,也算成功。
|
|
1043
1150
|
await breaker.success(orgId, connectorId);
|
|
@@ -1084,7 +1191,7 @@ export class ToolPipeline {
|
|
|
1084
1191
|
/** 额外参与竞速的信号(不传给 work):中止时以 `Stopped` 抛出,由调用方判断原因。 */
|
|
1085
1192
|
interrupt,
|
|
1086
1193
|
/** 时限(毫秒),缺省 `tools.timeoutMs`。 */
|
|
1087
|
-
timeoutMs = this.
|
|
1194
|
+
timeoutMs = this.config.get().tools.timeoutMs) {
|
|
1088
1195
|
if (runSignal.aborted)
|
|
1089
1196
|
return "aborted";
|
|
1090
1197
|
const timeout = new AbortController();
|
|
@@ -1157,7 +1264,7 @@ export class ToolPipeline {
|
|
|
1157
1264
|
if (c === undefined)
|
|
1158
1265
|
return undefined;
|
|
1159
1266
|
const x = (typeof c === "object" && c !== null ? c : {});
|
|
1160
|
-
const views = this.deps.inlineViews
|
|
1267
|
+
const views = this.deps.inlineViews(plugin);
|
|
1161
1268
|
const keyOk = x.key === undefined || (typeof x.key === "string" && x.key !== "" && x.key.length <= 200);
|
|
1162
1269
|
if (typeof x.view !== "string" || !views?.has(x.view) || !keyOk) {
|
|
1163
1270
|
this.deps.log.warn("tool returned an inline card that is not an inline view of its extension; dropped", {
|
|
@@ -1205,32 +1312,64 @@ export class ToolPipeline {
|
|
|
1205
1312
|
await this.deps.eventLog.append(ctx.conversationId, events);
|
|
1206
1313
|
return;
|
|
1207
1314
|
}
|
|
1208
|
-
const written = await this.
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
target: ctx.conversationId,
|
|
1219
|
-
detail: {
|
|
1220
|
-
toolKey,
|
|
1221
|
-
isError: r.isError,
|
|
1222
|
-
durationMs: callAudit.durationMs,
|
|
1223
|
-
agentId: ctx.agentId,
|
|
1224
|
-
agentVersion: ctx.agentVersion,
|
|
1225
|
-
conversationId: ctx.conversationId,
|
|
1226
|
-
runId: ctx.runId,
|
|
1227
|
-
callId,
|
|
1228
|
-
...(callAudit.connectorId !== null && { connectorId: callAudit.connectorId }),
|
|
1229
|
-
...callAudit.authorization,
|
|
1230
|
-
},
|
|
1231
|
-
});
|
|
1315
|
+
const written = await this.writeResultIn(ctx, callId, toolKey, r, events, callAudit, audits);
|
|
1316
|
+
await this.deps.eventLog.notify(ctx.conversationId, Math.max(...written.map((e) => e.seq)));
|
|
1317
|
+
}
|
|
1318
|
+
/** The result's events and audit rows in one transaction (see {@link writeResult}). */
|
|
1319
|
+
async writeResultIn(ctx, callId, toolKey, r, events, callAudit, audits) {
|
|
1320
|
+
const t = this.deps.db;
|
|
1321
|
+
const out = await this.deps.eventLog.appendIn(ctx.conversationId, events);
|
|
1322
|
+
for (const a of audits)
|
|
1323
|
+
await audit(t, a);
|
|
1324
|
+
if (callAudit === undefined)
|
|
1232
1325
|
return out;
|
|
1326
|
+
await audit(t, {
|
|
1327
|
+
actorAccountId: ctx.accountId,
|
|
1328
|
+
orgId: ctx.orgId,
|
|
1329
|
+
action: "tool.called",
|
|
1330
|
+
target: ctx.conversationId,
|
|
1331
|
+
detail: {
|
|
1332
|
+
toolKey,
|
|
1333
|
+
isError: r.isError,
|
|
1334
|
+
durationMs: callAudit.durationMs,
|
|
1335
|
+
agentId: ctx.agentId,
|
|
1336
|
+
agentVersion: ctx.agentVersion,
|
|
1337
|
+
conversationId: ctx.conversationId,
|
|
1338
|
+
runId: ctx.runId,
|
|
1339
|
+
callId,
|
|
1340
|
+
...(callAudit.connectorId !== null && { connectorId: callAudit.connectorId }),
|
|
1341
|
+
...callAudit.authorization,
|
|
1342
|
+
},
|
|
1233
1343
|
});
|
|
1234
|
-
|
|
1344
|
+
return out;
|
|
1235
1345
|
}
|
|
1236
|
-
}
|
|
1346
|
+
};
|
|
1347
|
+
__decorate([
|
|
1348
|
+
Transactional()
|
|
1349
|
+
], ToolPipeline.prototype, "stopOpenAgentCallsNow", null);
|
|
1350
|
+
__decorate([
|
|
1351
|
+
Transactional({ propagation: "mandatory" })
|
|
1352
|
+
], ToolPipeline.prototype, "stopOpenAgentCalls", null);
|
|
1353
|
+
__decorate([
|
|
1354
|
+
Transactional()
|
|
1355
|
+
], ToolPipeline.prototype, "writeResultIn", null);
|
|
1356
|
+
ToolPipeline = __decorate([
|
|
1357
|
+
Injectable(),
|
|
1358
|
+
__param(0, Inject(KernelDb)),
|
|
1359
|
+
__param(1, Inject(EventLog)),
|
|
1360
|
+
__param(2, Inject(SubagentsService)),
|
|
1361
|
+
__param(3, Inject(ToolRegistry)),
|
|
1362
|
+
__param(4, Inject(Credentials)),
|
|
1363
|
+
__param(5, Inject(Breaker)),
|
|
1364
|
+
__param(6, Inject(ToolOutputs)),
|
|
1365
|
+
__param(7, Inject(ApprovalsService)),
|
|
1366
|
+
__param(8, Inject(QuestionsService)),
|
|
1367
|
+
__param(9, Inject(KernelConfigService)),
|
|
1368
|
+
__param(10, Inject(KERNEL_LOGGER)),
|
|
1369
|
+
__param(11, Inject(ExtensionHost)),
|
|
1370
|
+
__param(12, Inject(ToolDrift)),
|
|
1371
|
+
__param(13, Inject(TransactionHost)),
|
|
1372
|
+
__param(14, Optional()),
|
|
1373
|
+
__param(14, Inject(TOOL_PIPELINE_HOOKS))
|
|
1374
|
+
], ToolPipeline);
|
|
1375
|
+
export { ToolPipeline };
|