@capybara-hq/kernel 0.1.0-rc.35 → 0.1.0-rc.37
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 +5 -5
- package/dist/admin/admin.module.d.ts +3 -3
- package/dist/admin/admin.module.js +6 -6
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +8 -19
- package/dist/agents/readiness.controller.js +11 -25
- package/dist/agents/readiness.service.d.ts +42 -0
- package/dist/agents/readiness.service.js +78 -0
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +53 -47
- package/dist/config/schema.js +190 -40
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.js +1 -2
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +17 -6
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +5 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/host.d.ts +2 -3
- package/dist/extensions/host.js +1 -5
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +2 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/orgs/orgs.module.d.ts +2 -2
- package/dist/orgs/orgs.module.js +2 -2
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +3 -7
- package/dist/overrides.js +2 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.d.ts +3 -3
- package/dist/platform/ops/agents.ops.js +7 -10
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +5 -3
- package/dist/platform/ops/orgs.ops.js +19 -4
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +1 -0
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.js +4 -3
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +56 -0
- package/dist/tools/drift.d.ts +1 -1
- package/dist/tools/drift.js +1 -1
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +16 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
|
@@ -21,6 +21,7 @@ import { ScheduledTaskRunTracker } from "../schedules/run-tracker.js";
|
|
|
21
21
|
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
22
22
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
23
23
|
import { ACTIVE_RUN_STATUSES, lockWaitRowsIn, oweEnsureRun, TERMINAL_STATUSES, } from "./run-jobs.js";
|
|
24
|
+
import { isLive } from "./run-liveness.js";
|
|
24
25
|
import { pairStoppedForks } from "./subagents/skill-fork.js";
|
|
25
26
|
import { oweDeliverToParent, oweStopChildren } from "./subagents/tree-jobs.js";
|
|
26
27
|
/**
|
|
@@ -149,7 +150,7 @@ let RunFinish = class RunFinish {
|
|
|
149
150
|
// ensureRun); owed here too, for when that never happens (an eval's hidden conversation never
|
|
150
151
|
// starts runs)
|
|
151
152
|
if (conv?.org_live &&
|
|
152
|
-
conv.deleted_at
|
|
153
|
+
isLive(conv.deleted_at) &&
|
|
153
154
|
(conv.kind === "chat" || conv.kind === "subagent")) {
|
|
154
155
|
await oweEnsureRun(this.outbox, a.conversationId, seq, conv.org_id);
|
|
155
156
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
|
+
/**
|
|
3
|
+
* The one definition of "live" for runs: an org or conversation is live while it is not
|
|
4
|
+
* soft-deleted. Every path that decides from an org's or a conversation's deletion whether a run
|
|
5
|
+
* may start, keep executing or be stopped (queueing, wakes, the post-run ensure, the execution
|
|
6
|
+
* fence, the orphan check, deletion) goes through here; other rows' deletion (agents, accounts,
|
|
7
|
+
* devices) is not run liveness.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isLive(...deletedAt: ReadonlyArray<unknown>): boolean;
|
|
10
|
+
/** Whether the org exists and is live (a plain read; the fence takes its own lock variant). */
|
|
11
|
+
export declare function orgIsLive(t: Pick<KernelDb, "selectFrom">, orgId: string): Promise<boolean>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one definition of "live" for runs: an org or conversation is live while it is not
|
|
3
|
+
* soft-deleted. Every path that decides from an org's or a conversation's deletion whether a run
|
|
4
|
+
* may start, keep executing or be stopped (queueing, wakes, the post-run ensure, the execution
|
|
5
|
+
* fence, the orphan check, deletion) goes through here; other rows' deletion (agents, accounts,
|
|
6
|
+
* devices) is not run liveness.
|
|
7
|
+
*/
|
|
8
|
+
export function isLive(...deletedAt) {
|
|
9
|
+
return deletedAt.every((d) => d === null);
|
|
10
|
+
}
|
|
11
|
+
/** Whether the org exists and is live (a plain read; the fence takes its own lock variant). */
|
|
12
|
+
export async function orgIsLive(t, orgId) {
|
|
13
|
+
const org = await t
|
|
14
|
+
.selectFrom("orgs")
|
|
15
|
+
.select("deleted_at")
|
|
16
|
+
.where("id", "=", orgId)
|
|
17
|
+
.executeTakeFirst();
|
|
18
|
+
return org !== undefined && isLive(org.deleted_at);
|
|
19
|
+
}
|
|
@@ -24,6 +24,7 @@ import { QueueLostJobs } from "./queue-lost-jobs.js";
|
|
|
24
24
|
import { RunDeletion } from "./run-deletion.js";
|
|
25
25
|
import { notifyFinished, RunFinish } from "./run-finish.js";
|
|
26
26
|
import { RunJobs, runJobId, runQueueNameFor } from "./run-jobs.js";
|
|
27
|
+
import { isLive } from "./run-liveness.js";
|
|
27
28
|
import { RunQueue } from "./run-queue.js";
|
|
28
29
|
import { Waits } from "./waits.js";
|
|
29
30
|
/** The check's `@LockedInterval` job name (its run lock key: `cron:run-orphan-check`). */
|
|
@@ -83,7 +84,7 @@ export async function orphanCandidates(db, statuses, minAgeMs, limit, after) {
|
|
|
83
84
|
orgId: r.org_id,
|
|
84
85
|
kind: r.kind,
|
|
85
86
|
status: r.status,
|
|
86
|
-
deleted: r.conversation_deleted
|
|
87
|
+
deleted: !isLive(r.conversation_deleted, r.org_deleted),
|
|
87
88
|
jobId: r.job_id ?? runJobId(r.conversation_id, Number(r.trigger_seq)),
|
|
88
89
|
queue: runQueueNameFor(r.kind),
|
|
89
90
|
since: r.since,
|
|
@@ -27,6 +27,7 @@ import { KyselyCheckpointSaver } from "./checkpointer.js";
|
|
|
27
27
|
import { ConversationLock } from "./conversation-lock.js";
|
|
28
28
|
import { notifyFinished, RunFinish } from "./run-finish.js";
|
|
29
29
|
import { ACTIVE_RUN_STATUSES, RunJobs, runJobId, runQueueNameFor } from "./run-jobs.js";
|
|
30
|
+
import { isLive, orgIsLive } from "./run-liveness.js";
|
|
30
31
|
import { rootConversationOf } from "./subagents/child.js";
|
|
31
32
|
import { budgetWindowOf } from "./subagents/limits.js";
|
|
32
33
|
export { ACTIVE_RUN_STATUSES, ENSURE_RUN_BACKSTOP_MS, ENSURE_RUN_JOB, ensureRunJobId, RUN_QUEUE_NAME, runJobId, runQueueNameFor, SUBAGENT_RUN_QUEUE_NAME, } from "./run-jobs.js";
|
|
@@ -141,16 +142,12 @@ let RunQueue = class RunQueue {
|
|
|
141
142
|
.forUpdate()
|
|
142
143
|
.executeTakeFirst();
|
|
143
144
|
// a deleted conversation, or a sub-agent's / eval one, has no manual compaction
|
|
144
|
-
if (!conv || conv.deleted_at
|
|
145
|
+
if (!conv || !isLive(conv.deleted_at) || conv.kind !== "chat") {
|
|
145
146
|
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
-
.selectFrom("orgs")
|
|
149
|
-
.select("deleted_at")
|
|
150
|
-
.where("id", "=", conv.org_id)
|
|
151
|
-
.executeTakeFirst();
|
|
152
|
-
if (!org || org.deleted_at !== null)
|
|
148
|
+
if (!(await orgIsLive(t, conv.org_id))) {
|
|
153
149
|
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
150
|
+
}
|
|
154
151
|
const active = await t
|
|
155
152
|
.selectFrom("runs")
|
|
156
153
|
.select(["id", "compact"])
|
|
@@ -217,14 +214,9 @@ let RunQueue = class RunQueue {
|
|
|
217
214
|
if (conv?.kind !== "chat" && conv?.kind !== "subagent")
|
|
218
215
|
return null;
|
|
219
216
|
// A deleted conversation starts no run, whatever is still unconsumed or queued
|
|
220
|
-
if (conv.deleted_at
|
|
217
|
+
if (!isLive(conv.deleted_at))
|
|
221
218
|
return null;
|
|
222
|
-
|
|
223
|
-
.selectFrom("orgs")
|
|
224
|
-
.select("deleted_at")
|
|
225
|
-
.where("id", "=", conv.org_id)
|
|
226
|
-
.executeTakeFirst();
|
|
227
|
-
if (!org || org.deleted_at !== null)
|
|
219
|
+
if (!(await orgIsLive(t, conv.org_id)))
|
|
228
220
|
return null;
|
|
229
221
|
if (conv.kind === "subagent")
|
|
230
222
|
return this.childWakeIn(conversationId, conv, st);
|
|
@@ -515,7 +507,7 @@ let RunQueue = class RunQueue {
|
|
|
515
507
|
.select(["queue_paused", "deleted_at"])
|
|
516
508
|
.where("id", "=", rootId)
|
|
517
509
|
.executeTakeFirst();
|
|
518
|
-
if (!root || root.queue_paused || root.deleted_at
|
|
510
|
+
if (!root || root.queue_paused || !isLive(root.deleted_at))
|
|
519
511
|
return null;
|
|
520
512
|
const accountId = message.payload.authorAccountId;
|
|
521
513
|
if (!(await authorCanSend(t, rootId, accountId)))
|
|
@@ -552,7 +544,7 @@ let RunQueue = class RunQueue {
|
|
|
552
544
|
.select(["queue_paused", "deleted_at"])
|
|
553
545
|
.where("id", "=", rootId)
|
|
554
546
|
.executeTakeFirst();
|
|
555
|
-
if (!root || root.queue_paused || root.deleted_at
|
|
547
|
+
if (!root || root.queue_paused || !isLive(root.deleted_at))
|
|
556
548
|
return;
|
|
557
549
|
for (const c of await this.heldTree(rootId)) {
|
|
558
550
|
await this.jobs.oweEnsureRun(c.id, c.seq, c.org_id);
|
|
@@ -73,7 +73,7 @@ export declare class RunWorker {
|
|
|
73
73
|
private readonly titles;
|
|
74
74
|
/** Resolves a switched-to model at run start (fallback when it is gone; UI refresh B). */
|
|
75
75
|
private readonly models;
|
|
76
|
-
/** Run start's skills catalog snapshot
|
|
76
|
+
/** Run start's skills catalog snapshot. */
|
|
77
77
|
private readonly skillsCatalog;
|
|
78
78
|
/** Run start's run context (run context spec §5): who the agent is, the day, the person. */
|
|
79
79
|
private readonly runContext;
|
|
@@ -109,7 +109,7 @@ export declare class RunWorker {
|
|
|
109
109
|
titles: Pick<TitleQueue, "maybeEnqueue">,
|
|
110
110
|
/** Resolves a switched-to model at run start (fallback when it is gone; UI refresh B). */
|
|
111
111
|
models: Pick<ProviderRegistry, "resolve">,
|
|
112
|
-
/** Run start's skills catalog snapshot
|
|
112
|
+
/** Run start's skills catalog snapshot. */
|
|
113
113
|
skillsCatalog: Pick<SkillsCatalogService, "record">,
|
|
114
114
|
/** Run start's run context (run context spec §5): who the agent is, the day, the person. */
|
|
115
115
|
runContext: Pick<RunContextService, "record">,
|
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
11
11
|
import { DelayedError } from "bullmq";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
13
14
|
import { EventLog } from "../conversations/event-log.js";
|
|
14
15
|
import { isAbsorbable, } from "../conversations/events.js";
|
|
15
16
|
import { effectiveDefinition, NO_SELECTION, readSelection, sameModel, sameSelection, } from "../conversations/selection.js";
|
|
@@ -24,7 +25,6 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
24
25
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
25
26
|
import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
|
|
26
27
|
import { SkillsCatalogService } from "../skills/catalog.js";
|
|
27
|
-
import { normalizeStoredDefinitionIn } from "../tools/legacy-data.js";
|
|
28
28
|
import { ToolRegistry } from "../tools/registry.js";
|
|
29
29
|
import { RunAbort } from "./abort.js";
|
|
30
30
|
import { KyselyCheckpointSaver } from "./checkpointer.js";
|
|
@@ -58,8 +58,10 @@ const FOLLOW_UP_MIN_WAIT_MS = 250;
|
|
|
58
58
|
/** 读插话的分页大小。 */
|
|
59
59
|
const READ_PAGE = 500;
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
61
|
+
* Retry delays when the post-run ensureRun fails (3 retries after the first try). In-process timers:
|
|
62
|
+
* this is follow-up work for a job this process just finished, tracked and time-bounded by close().
|
|
63
|
+
* If every try fails the conversation is not stuck: the `run-orphan-check` repairs it (SSE and reads
|
|
64
|
+
* no longer call ensureRun). The ladder only shortens recovery from common transient failures.
|
|
63
65
|
*/
|
|
64
66
|
const ENSURE_RETRY_DELAYS_MS = [200, 1000, 3000];
|
|
65
67
|
/** Optional provider: the run worker's {@link RunHooks} (tests). */
|
|
@@ -130,7 +132,7 @@ let RunWorker = class RunWorker {
|
|
|
130
132
|
titles,
|
|
131
133
|
/** Resolves a switched-to model at run start (fallback when it is gone; UI refresh B). */
|
|
132
134
|
models,
|
|
133
|
-
/** Run start's skills catalog snapshot
|
|
135
|
+
/** Run start's skills catalog snapshot. */
|
|
134
136
|
skillsCatalog,
|
|
135
137
|
/** Run start's run context (run context spec §5): who the agent is, the day, the person. */
|
|
136
138
|
runContext,
|
|
@@ -596,7 +598,7 @@ let RunWorker = class RunWorker {
|
|
|
596
598
|
// a follow-up runs with its task message's narrowing (final review I1): the frozen tools
|
|
597
599
|
// and org skills the current version still allows, recorded at its dispatch
|
|
598
600
|
const trigger = (await this.eventLog.readAfter(conversationId, Number(run.trigger_seq) - 1, 1))[0];
|
|
599
|
-
agent = childRunDefinition(
|
|
601
|
+
agent = childRunDefinition(normalizeStoredDefinition(started.payload.definition), trigger?.type === "user_message" && trigger.seq === Number(run.trigger_seq)
|
|
600
602
|
? trigger.payload.dispatch?.narrowed
|
|
601
603
|
: undefined);
|
|
602
604
|
// the tighter of the logged limit and the deployment's (0 in either = no limit there)
|
|
@@ -643,7 +645,7 @@ let RunWorker = class RunWorker {
|
|
|
643
645
|
.where("agent_id", "=", conv.agent_id)
|
|
644
646
|
.where("version", "=", run.agent_version)
|
|
645
647
|
.executeTakeFirstOrThrow();
|
|
646
|
-
saved =
|
|
648
|
+
saved = normalizeStoredDefinition(version.definition);
|
|
647
649
|
agent = saved;
|
|
648
650
|
}
|
|
649
651
|
// the trigger account's role, read once per run for the plugin context and plugin tool
|
|
@@ -23,16 +23,24 @@ export interface EffectiveDefinition {
|
|
|
23
23
|
/** The child's step limit; 0 = no limit. */
|
|
24
24
|
maxSteps: number;
|
|
25
25
|
/**
|
|
26
|
-
* The
|
|
27
|
-
*
|
|
26
|
+
* The template's `skills` the child has, in the template's order: the dispatch writes each as a
|
|
27
|
+
* skill invocation message after the task (no model step spent loading them).
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
skills: TemplateSkill[];
|
|
30
30
|
/**
|
|
31
31
|
* Dispatch warnings (a template skill the child does not have), recorded in
|
|
32
32
|
* `subagent_started.warnings`.
|
|
33
33
|
*/
|
|
34
34
|
warnings: string[];
|
|
35
35
|
}
|
|
36
|
+
/** A template skill the child starts with: its catalog entry (the version its catalog lists). */
|
|
37
|
+
export interface TemplateSkill {
|
|
38
|
+
id: string;
|
|
39
|
+
version: number;
|
|
40
|
+
source: string;
|
|
41
|
+
name: string;
|
|
42
|
+
plugin?: string;
|
|
43
|
+
}
|
|
36
44
|
export interface EffectiveDefinitionDeps {
|
|
37
45
|
db: KernelSchemaDb;
|
|
38
46
|
purposes: Pick<ModelPurposesService, "resolve">;
|
|
@@ -54,8 +62,6 @@ export declare function stricterPolicies(base: Record<string, string>, over: Rec
|
|
|
54
62
|
* and an entry that is no valid reference (stored template data is not re-validated) are dropped.
|
|
55
63
|
*/
|
|
56
64
|
export declare function disallowedSkillRefs(db: KernelSchemaDb, orgId: string, refs: readonly unknown[] | undefined): Promise<DisabledSkillRef[]>;
|
|
57
|
-
/** The preamble line naming the skills a template child loads first (skills default-on §6.1). */
|
|
58
|
-
export declare const loadSkillsFirstText: (names: readonly string[]) => string;
|
|
59
65
|
/** An org agent's version and definition as checked by its gates. */
|
|
60
66
|
export interface CheckedOrgAgent {
|
|
61
67
|
version: number;
|
|
@@ -72,8 +78,8 @@ export interface ChildDepth {
|
|
|
72
78
|
* The effective definition of a sub-agent at its first dispatch (spec §5.3–§5.5):
|
|
73
79
|
* - `general` / `inline` / `plugin`: the parent's definition narrowed by the template (tools by
|
|
74
80
|
* resolved key, `disallowedTools`, {@link CHILD_REMOVED_TOOLS}; policies stricter-wins; skills
|
|
75
|
-
* by its `disallowedSkills`), the template's instructions, its `skills` the child has
|
|
76
|
-
*
|
|
81
|
+
* by its `disallowedSkills`), the template's instructions, its `skills` the child has (written
|
|
82
|
+
* as skill invocations at dispatch; general has none), `maxSteps` = the tighter of the template's and `runtime.maxSteps` (0 = no limit), and the model tier
|
|
77
83
|
* `tier` (the call's) → the template's → `inherit`; an unmapped tier runs on the parent's model
|
|
78
84
|
* (`tierFallback`); a template `effort` is set when the resolved model declares it;
|
|
79
85
|
* - `agent`: the org agent's version that passed the gates (`orgAgent`, from {@link checkOrgAgent}),
|
|
@@ -102,15 +108,8 @@ export declare function effectiveDefinition(d: EffectiveDefinitionDeps, a: Child
|
|
|
102
108
|
* the run and its replay read it from the log.
|
|
103
109
|
*/
|
|
104
110
|
export interface FollowUpNarrowing {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/** Absent in logs from before skills were on by default (skills default-on spec §6.1). */
|
|
108
|
-
disabledSkills?: DisabledSkillRef[] | undefined;
|
|
109
|
-
/** Older logs only: the frozen org skills intersected with the current ones. */
|
|
110
|
-
skills?: {
|
|
111
|
-
orgSkills: string[];
|
|
112
|
-
pinned?: string[] | undefined;
|
|
113
|
-
} | undefined;
|
|
111
|
+
disabledTools: DisabledToolRef[];
|
|
112
|
+
disabledSkills: DisabledSkillRef[];
|
|
114
113
|
}
|
|
115
114
|
/**
|
|
116
115
|
* The narrowing of a follow-up (final review I1): `frozen` (the child's `subagent_started`
|
|
@@ -120,8 +119,5 @@ export interface FollowUpNarrowing {
|
|
|
120
119
|
* `disabledTools` and `disabledSkills` are both lists together.
|
|
121
120
|
*/
|
|
122
121
|
export declare function narrowFollowUp(frozen: Pick<AgentDefinition, "disabledTools" | "disabledSkills">, current: Pick<AgentDefinition, "disabledTools" | "disabledSkills">): FollowUpNarrowing;
|
|
123
|
-
/**
|
|
124
|
-
* The definition a child run uses: the frozen one with its trigger's follow-up narrowing. A
|
|
125
|
-
* narrowing logged before tools (or skills) were on by default narrows nothing of that kind.
|
|
126
|
-
*/
|
|
122
|
+
/** The definition a child run uses: the frozen one with its trigger's follow-up narrowing. */
|
|
127
123
|
export declare function childRunDefinition(frozen: AgentDefinition, narrowed: FollowUpNarrowing | undefined): AgentDefinition;
|
|
@@ -7,7 +7,6 @@ import { invocationOf, resolveSkills } from "../../skills/catalog.js";
|
|
|
7
7
|
import { agentSkills, usableSkills } from "../../skills/usable.js";
|
|
8
8
|
import { AGENT_TOOL, CHILD_REMOVED_TOOLS } from "../../tools/builtin-names.js";
|
|
9
9
|
import { tightestLimit } from "../limits.js";
|
|
10
|
-
import { SUBAGENT_PREAMBLE } from "./preamble.js";
|
|
11
10
|
export { CHILD_REMOVED_TOOLS } from "../../tools/builtin-names.js";
|
|
12
11
|
/**
|
|
13
12
|
* The roster entry's template is gone (an inline template edited away, a plugin template
|
|
@@ -101,27 +100,25 @@ export async function disallowedSkillRefs(db, orgId, refs) {
|
|
|
101
100
|
return out;
|
|
102
101
|
}
|
|
103
102
|
/** The warning of a template skill the child does not have. */
|
|
104
|
-
const skillNotLoadedText = (ref) => `The skill "${ref}" is not among the sub-agent's skills, so it is not
|
|
105
|
-
/** The preamble line naming the skills a template child loads first (skills default-on §6.1). */
|
|
106
|
-
export const loadSkillsFirstText = (names) => `Before you start, load these skills with Skill: ${names.join(", ")}.`;
|
|
103
|
+
const skillNotLoadedText = (ref) => `The skill "${ref}" is not among the sub-agent's skills, so it is not loaded.`;
|
|
107
104
|
/**
|
|
108
|
-
* The template's `skills` the child has (skills default-on spec §6.1: they are
|
|
109
|
-
*
|
|
110
|
-
*
|
|
105
|
+
* The template's `skills` the child has (skills default-on spec §6.1: they are never pinned), as
|
|
106
|
+
* the entries its catalog lists, in the template's order: the catalog its first run records (the
|
|
107
|
+
* agent `agentId` with the child's `disabledSkills`, model-invocable skills only).
|
|
111
108
|
* Inline templates name skill ids (`byId`; a platform skill's id names its linked copy too), plugin
|
|
112
109
|
* templates names (`<name>`, or `<plugin>:<name>` when the catalog's skill of that name is from
|
|
113
110
|
* that plugin). The others become warnings.
|
|
114
111
|
*/
|
|
115
112
|
async function skillsToLoad(db, a, refs, byId) {
|
|
116
113
|
if (refs.length === 0)
|
|
117
|
-
return {
|
|
114
|
+
return { skills: [], warnings: [] };
|
|
118
115
|
const input = { orgId: a.orgId, agentId: a.agentId, disabledSkills: [...a.disabledSkills] };
|
|
119
116
|
const catalog = (await resolveSkills(db, { ...input, agent: input }))
|
|
120
117
|
.filter((r) => invocationOf(r.manifest).model)
|
|
121
118
|
.slice(0, SKILLS_CATALOG_MAX)
|
|
122
119
|
.map((r) => r.skill);
|
|
123
120
|
const rows = byId ? await agentSkills(db, input) : [];
|
|
124
|
-
const
|
|
121
|
+
const skills = [];
|
|
125
122
|
const warnings = [];
|
|
126
123
|
for (const ref of refs) {
|
|
127
124
|
let found;
|
|
@@ -136,12 +133,20 @@ async function skillsToLoad(db, a, refs, byId) {
|
|
|
136
133
|
? catalog.find((c) => c.name === ref)
|
|
137
134
|
: catalog.find((c) => c.name === ref.slice(i + 1) && c.plugin === ref.slice(0, i));
|
|
138
135
|
}
|
|
139
|
-
|
|
136
|
+
const f = found;
|
|
137
|
+
if (f === undefined)
|
|
140
138
|
warnings.push(skillNotLoadedText(ref));
|
|
141
|
-
else if (!
|
|
142
|
-
|
|
139
|
+
else if (!skills.some((s) => s.id === f.id)) {
|
|
140
|
+
skills.push({
|
|
141
|
+
id: f.id,
|
|
142
|
+
version: f.version,
|
|
143
|
+
source: f.source,
|
|
144
|
+
name: f.name,
|
|
145
|
+
...(f.plugin !== undefined && { plugin: f.plugin }),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
143
148
|
}
|
|
144
|
-
return {
|
|
149
|
+
return { skills, warnings };
|
|
145
150
|
}
|
|
146
151
|
/** The `effort` declaration of `model`, or null (or when the model cannot be resolved). */
|
|
147
152
|
async function effortDecl(registry, orgId, model) {
|
|
@@ -212,7 +217,7 @@ function orgAgentDefinition(d, a) {
|
|
|
212
217
|
definition,
|
|
213
218
|
template: { source: "agent", id: agentId, version: a.orgAgent.version },
|
|
214
219
|
maxSteps: d.config.get().runtime.maxSteps,
|
|
215
|
-
|
|
220
|
+
skills: [],
|
|
216
221
|
warnings: [],
|
|
217
222
|
model: own.model,
|
|
218
223
|
tierFallback: false,
|
|
@@ -222,8 +227,8 @@ function orgAgentDefinition(d, a) {
|
|
|
222
227
|
* The effective definition of a sub-agent at its first dispatch (spec §5.3–§5.5):
|
|
223
228
|
* - `general` / `inline` / `plugin`: the parent's definition narrowed by the template (tools by
|
|
224
229
|
* resolved key, `disallowedTools`, {@link CHILD_REMOVED_TOOLS}; policies stricter-wins; skills
|
|
225
|
-
* by its `disallowedSkills`), the template's instructions, its `skills` the child has
|
|
226
|
-
*
|
|
230
|
+
* by its `disallowedSkills`), the template's instructions, its `skills` the child has (written
|
|
231
|
+
* as skill invocations at dispatch; general has none), `maxSteps` = the tighter of the template's and `runtime.maxSteps` (0 = no limit), and the model tier
|
|
227
232
|
* `tier` (the call's) → the template's → `inherit`; an unmapped tier runs on the parent's model
|
|
228
233
|
* (`tierFallback`); a template `effort` is set when the resolved model declares it;
|
|
229
234
|
* - `agent`: the org agent's version that passed the gates (`orgAgent`, from {@link checkOrgAgent}),
|
|
@@ -260,12 +265,12 @@ export async function effectiveDefinition(d, a) {
|
|
|
260
265
|
}
|
|
261
266
|
const toolPolicies = stricterPolicies(parent.toolPolicies ?? {}, template?.toolPolicies ?? {});
|
|
262
267
|
// skills default-on (spec §6.1): the parent's catalog, narrowed by the template's
|
|
263
|
-
// `disallowedSkills`; the template's `skills` are
|
|
268
|
+
// `disallowedSkills`; the template's `skills` are written as invocations, never pinned
|
|
264
269
|
const narrowing = await disallowedSkillRefs(d.db, a.orgId, template?.disallowedSkills);
|
|
265
270
|
const disabledSkills = narrowing.length === 0
|
|
266
271
|
? (parent.disabledSkills ?? [])
|
|
267
272
|
: canonicalDisabledSkills([...(parent.disabledSkills ?? []), ...narrowing]);
|
|
268
|
-
const {
|
|
273
|
+
const { skills, warnings } = await skillsToLoad(d.db, { orgId: a.orgId, agentId: a.parentAgentId, disabledSkills }, template?.skills ?? [], entry.source === "inline");
|
|
269
274
|
const tier = a.tier ?? template?.model ?? "inherit";
|
|
270
275
|
const m = await resolveTier(d, a.orgId, parent, tier);
|
|
271
276
|
let modelParams = m.modelParams;
|
|
@@ -301,9 +306,7 @@ export async function effectiveDefinition(d, a) {
|
|
|
301
306
|
template: ref,
|
|
302
307
|
// the tighter of the template's and the deployment's, 0 = no limit (`runtime.maxSteps` 0)
|
|
303
308
|
maxSteps: tightestLimit(template?.maxSteps, runtimeMax) ?? 0,
|
|
304
|
-
|
|
305
|
-
? SUBAGENT_PREAMBLE
|
|
306
|
-
: `${SUBAGENT_PREAMBLE}\n\n${loadSkillsFirstText(names)}`,
|
|
309
|
+
skills,
|
|
307
310
|
warnings,
|
|
308
311
|
model: m.model,
|
|
309
312
|
tierFallback: m.tierFallback,
|
|
@@ -328,16 +331,13 @@ export function narrowFollowUp(frozen, current) {
|
|
|
328
331
|
]),
|
|
329
332
|
};
|
|
330
333
|
}
|
|
331
|
-
/**
|
|
332
|
-
* The definition a child run uses: the frozen one with its trigger's follow-up narrowing. A
|
|
333
|
-
* narrowing logged before tools (or skills) were on by default narrows nothing of that kind.
|
|
334
|
-
*/
|
|
334
|
+
/** The definition a child run uses: the frozen one with its trigger's follow-up narrowing. */
|
|
335
335
|
export function childRunDefinition(frozen, narrowed) {
|
|
336
336
|
if (narrowed === undefined)
|
|
337
337
|
return frozen;
|
|
338
338
|
return {
|
|
339
339
|
...frozen,
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
disabledTools: narrowed.disabledTools,
|
|
341
|
+
disabledSkills: narrowed.disabledSkills,
|
|
342
342
|
};
|
|
343
343
|
}
|
|
@@ -5,6 +5,7 @@ import type { ConversationEvent, EventPayload } from "../../conversations/events
|
|
|
5
5
|
import type { ConversationKind, KernelSchemaDb } from "../../db/kernel-schema.js";
|
|
6
6
|
import type { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
7
7
|
import type { ModelPurposesService } from "../../models/purposes.js";
|
|
8
|
+
import { type SkillInvoker } from "../../skills/invoke.js";
|
|
8
9
|
import { AGENT_REFUSALS, type AgentToolInputT } from "../../tools/builtins/agent.js";
|
|
9
10
|
import type { ToolStepContext } from "../../tools/pipeline.js";
|
|
10
11
|
import type { ProviderRegistry } from "../providers.js";
|
|
@@ -24,6 +25,8 @@ export interface DispatchDeps {
|
|
|
24
25
|
*/
|
|
25
26
|
owe: (data: RunJobData, jobId: string, kind: ConversationKind, orgId: string) => Promise<boolean>;
|
|
26
27
|
log: Pick<Logger, "error" | "warn">;
|
|
28
|
+
/** Renders a template's skills into the child's first messages ({@link templateSkillMessages}). */
|
|
29
|
+
invoker: Pick<SkillInvoker, "renderTask">;
|
|
27
30
|
/**
|
|
28
31
|
* Runs {@link commitDispatchIn} in a transaction of its own (`SubagentsService.commitDispatch`,
|
|
29
32
|
* a `@Transactional` method).
|
|
@@ -121,8 +124,8 @@ export interface DispatchPlan {
|
|
|
121
124
|
* Dispatches the sub-agent of one `Agent` call (spec §7.1, agent map spec §4.1), after the
|
|
122
125
|
* pipeline's validation, policy, approval and `tool.preExecute` stages: resolves its type and
|
|
123
126
|
* effective definition, then in one transaction (holding the parent run's row lock, so the
|
|
124
|
-
* dispatches of one run serialize) inserts the child conversation, appends `subagent_started
|
|
125
|
-
* the task message, inserts the child run (`queued`) and the `subagent_dispatches` row, appends
|
|
127
|
+
* dispatches of one run serialize) inserts the child conversation, appends `subagent_started`,
|
|
128
|
+
* the task message and the template's skill invocations ({@link templateSkillMessages}), inserts the child run (`queued`) and the `subagent_dispatches` row, appends
|
|
126
129
|
* `subagent_dispatched` and the call's `tool_result` ({@link agentStartedText}: the sub-agent runs
|
|
127
130
|
* in the background) to the parent and audits `subagent.dispatched` and `tool.called`. The child
|
|
128
131
|
* run's job is owed in the same transaction (transactional outbox spec §6), so the committed
|
|
@@ -173,6 +176,7 @@ export declare const taskMessage: (ctx: ToolStepContext, callId: string, prompt:
|
|
|
173
176
|
arguments: string;
|
|
174
177
|
mode: "fork" | "inline";
|
|
175
178
|
agentType?: string | undefined;
|
|
179
|
+
template?: true | undefined;
|
|
176
180
|
};
|
|
177
181
|
authorAccountId: string;
|
|
178
182
|
dispatch: {
|
|
@@ -9,7 +9,9 @@ import { childResult, finishedEvent } from "./child.js";
|
|
|
9
9
|
import { effectiveDefinition, SubagentTypeGoneError, } from "./definition.js";
|
|
10
10
|
import { subagentLimits } from "./limits.js";
|
|
11
11
|
import { auditRefusal, checkOrgAgent, currentAgentDefinition } from "./org-agents.js";
|
|
12
|
+
import { SUBAGENT_PREAMBLE } from "./preamble.js";
|
|
12
13
|
import { findType, GENERAL_PURPOSE_DESCRIPTION, resolveRoster, } from "./roster.js";
|
|
14
|
+
import { templateSkillMessages } from "./template-skills.js";
|
|
13
15
|
const refused = (content) => ({ kind: "refused", content });
|
|
14
16
|
/** The `general-purpose` roster entry (a fork invocation always has it). */
|
|
15
17
|
const GENERAL_ENTRY = {
|
|
@@ -28,8 +30,8 @@ export const dispatchedIdemKey = (runId, callId) => `subagent_dispatched:${runId
|
|
|
28
30
|
* Dispatches the sub-agent of one `Agent` call (spec §7.1, agent map spec §4.1), after the
|
|
29
31
|
* pipeline's validation, policy, approval and `tool.preExecute` stages: resolves its type and
|
|
30
32
|
* effective definition, then in one transaction (holding the parent run's row lock, so the
|
|
31
|
-
* dispatches of one run serialize) inserts the child conversation, appends `subagent_started
|
|
32
|
-
* the task message, inserts the child run (`queued`) and the `subagent_dispatches` row, appends
|
|
33
|
+
* dispatches of one run serialize) inserts the child conversation, appends `subagent_started`,
|
|
34
|
+
* the task message and the template's skill invocations ({@link templateSkillMessages}), inserts the child run (`queued`) and the `subagent_dispatches` row, appends
|
|
33
35
|
* `subagent_dispatched` and the call's `tool_result` ({@link agentStartedText}: the sub-agent runs
|
|
34
36
|
* in the background) to the parent and audits `subagent.dispatched` and `tool.called`. The child
|
|
35
37
|
* run's job is owed in the same transaction (transactional outbox spec §6), so the committed
|
|
@@ -92,6 +94,17 @@ export async function dispatchSubagent(d, a) {
|
|
|
92
94
|
}
|
|
93
95
|
throw e;
|
|
94
96
|
}
|
|
97
|
+
// read and rendered before the transaction (object storage): the template's skills as the
|
|
98
|
+
// child's invocation messages, after its task
|
|
99
|
+
const loaded = await templateSkillMessages(d, {
|
|
100
|
+
ctx,
|
|
101
|
+
child: eff.definition,
|
|
102
|
+
skills: eff.skills,
|
|
103
|
+
});
|
|
104
|
+
// the parent run was stopped: nothing is dispatched (as when the commit finds it not running)
|
|
105
|
+
if (loaded === null)
|
|
106
|
+
return refused(AGENT_REFUSALS.notAvailableHere);
|
|
107
|
+
warnings.push(...loaded.warnings);
|
|
95
108
|
const childId = randomUUID();
|
|
96
109
|
const plan = {
|
|
97
110
|
childConversationId: childId,
|
|
@@ -147,7 +160,7 @@ export async function dispatchSubagent(d, a) {
|
|
|
147
160
|
},
|
|
148
161
|
},
|
|
149
162
|
definition: eff.definition,
|
|
150
|
-
preamble:
|
|
163
|
+
preamble: SUBAGENT_PREAMBLE,
|
|
151
164
|
maxSteps: eff.maxSteps,
|
|
152
165
|
...([...eff.warnings, ...warnings].length > 0 && {
|
|
153
166
|
warnings: [...eff.warnings, ...warnings],
|
|
@@ -155,6 +168,7 @@ export async function dispatchSubagent(d, a) {
|
|
|
155
168
|
},
|
|
156
169
|
},
|
|
157
170
|
taskMessage(ctx, a.callId, fork === undefined ? input.prompt : fork.task(eff.definition), undefined, fork?.skill),
|
|
171
|
+
...loaded.messages,
|
|
158
172
|
]);
|
|
159
173
|
return task;
|
|
160
174
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isAgentVisibleTo } from "../../agents/agent-lookup.js";
|
|
2
2
|
import { normalizeStoredDefinition } from "../../agents/definition.js";
|
|
3
3
|
import { audit } from "../../identity/audit.js";
|
|
4
|
-
import { normalizeStoredDefinitionIn } from "../../tools/legacy-data.js";
|
|
5
4
|
/**
|
|
6
5
|
* Checks the gates for dispatching `agentId` from a parent whose current definition is
|
|
7
6
|
* `parentDefinition` (read live by the caller: R5, removing an allowlist entry stops new
|
|
@@ -24,7 +23,7 @@ export async function checkOrgAgent(db, a) {
|
|
|
24
23
|
if (!(a.parentDefinition.subagents?.agents ?? []).some((x) => x.agentId === a.agentId)) {
|
|
25
24
|
return { ok: false, gate: "allowlist" };
|
|
26
25
|
}
|
|
27
|
-
const definition =
|
|
26
|
+
const definition = normalizeStoredDefinition(row.definition);
|
|
28
27
|
if (definition.subagents?.dispatchable !== true)
|
|
29
28
|
return { ok: false, gate: "dispatchable" };
|
|
30
29
|
if (!(await isAgentVisibleTo(db, a.agentId, a.triggerAccountId))) {
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* The sub-agent preamble (spec §6.3, agent map spec §4.4, model-visible): rendered in a child's
|
|
3
3
|
* system text after `BEHAVIOR_RULES` and before its instructions. Frozen into each child's
|
|
4
4
|
* `subagent_started` at dispatch, and request building reads it from there, so changing this text
|
|
5
|
-
* never alters an old child's requests.
|
|
6
|
-
* template's skills to load first
|
|
5
|
+
* never alters an old child's requests. Older children's preambles may end with a line naming the
|
|
6
|
+
* template's skills to load first; a template's skills are now written as skill invocation
|
|
7
|
+
* messages after the task (`template-skills.ts`).
|
|
7
8
|
*/
|
|
8
9
|
export declare const SUBAGENT_PREAMBLE: string;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* The sub-agent preamble (spec §6.3, agent map spec §4.4, model-visible): rendered in a child's
|
|
3
3
|
* system text after `BEHAVIOR_RULES` and before its instructions. Frozen into each child's
|
|
4
4
|
* `subagent_started` at dispatch, and request building reads it from there, so changing this text
|
|
5
|
-
* never alters an old child's requests.
|
|
6
|
-
* template's skills to load first
|
|
5
|
+
* never alters an old child's requests. Older children's preambles may end with a line naming the
|
|
6
|
+
* template's skills to load first; a template's skills are now written as skill invocation
|
|
7
|
+
* messages after the task (`template-skills.ts`).
|
|
7
8
|
*/
|
|
8
9
|
export const SUBAGENT_PREAMBLE = "You are a sub-agent. Another agent dispatched you with the task in the first user message. " +
|
|
9
10
|
"Work on it on your own: the user does not watch this conversation and you cannot ask them " +
|
|
@@ -23,8 +23,7 @@ type Delivery = EventPayload<"subagent_delivery">;
|
|
|
23
23
|
*
|
|
24
24
|
* A run that handed back and then `completed` no longer gets a finished delivery (acceptance
|
|
25
25
|
* 2026-11-07, `SubagentDeliveries.finishIn`); the "already delivered" line stays for the other
|
|
26
|
-
* statuses after a handback
|
|
27
|
-
* byte. The switch is the delivery's absence in the log, so it needs no `DriftReason`.
|
|
26
|
+
* statuses after a handback.
|
|
28
27
|
*/
|
|
29
28
|
export declare function renderSubagentDelivery(p: Delivery): string;
|
|
30
29
|
export {};
|
|
@@ -22,8 +22,7 @@ import { subagentStatusText } from "./status.js";
|
|
|
22
22
|
*
|
|
23
23
|
* A run that handed back and then `completed` no longer gets a finished delivery (acceptance
|
|
24
24
|
* 2026-11-07, `SubagentDeliveries.finishIn`); the "already delivered" line stays for the other
|
|
25
|
-
* statuses after a handback
|
|
26
|
-
* byte. The switch is the delivery's absence in the log, so it needs no `DriftReason`.
|
|
25
|
+
* statuses after a handback.
|
|
27
26
|
*/
|
|
28
27
|
export function renderSubagentDelivery(p) {
|
|
29
28
|
const head = `Sub-agent ${p.subagentId} (${JSON.stringify(p.description)})`;
|
|
@@ -2,7 +2,6 @@ import type { EventLog } from "../../conversations/event-log.js";
|
|
|
2
2
|
import type { ConversationEvent, EventPayload } from "../../conversations/events.js";
|
|
3
3
|
import type { KernelSchemaDb } from "../../db/kernel-schema.js";
|
|
4
4
|
import { ApiError } from "../../errors.js";
|
|
5
|
-
import type { SkillInvoker } from "../../skills/invoke.js";
|
|
6
5
|
import { type LoopContext, type WaitingFor } from "../loop.js";
|
|
7
6
|
import { type DispatchDeps } from "./dispatch.js";
|
|
8
7
|
/**
|
|
@@ -82,9 +81,8 @@ export interface SkillForks {
|
|
|
82
81
|
fork: ForkInvocation;
|
|
83
82
|
}): Promise<SkillForkStep>;
|
|
84
83
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
84
|
+
/** The fork's dependencies: the dispatch's (its `invoker` renders the task). */
|
|
85
|
+
export type SkillForkDeps = DispatchDeps;
|
|
88
86
|
/**
|
|
89
87
|
* In `prepare`, for the run's fork invocation: dispatch it when it has no dispatch row (rendering
|
|
90
88
|
* the task from the recorded version, `SkillInvoker.renderTask`) and suspend; append the report once
|