@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
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { SKILL_LOAD } from "../../tools/builtin-names.js";
|
|
2
|
+
/**
|
|
3
|
+
* The model-visible skills texts that name the skill-loading builtin:
|
|
4
|
+
* - `skillsCatalogHeader`: the header of the first catalog (in the system cache segment);
|
|
5
|
+
* - `newSkills` / `updatedSkills`: the headings of the added and updated skills in a change notice;
|
|
6
|
+
* - `currentSkills`: the heading of the current catalog after a compaction summary;
|
|
7
|
+
* - `invokedSkills`: the line restored after a compaction summary for the skills invoked in its
|
|
8
|
+
* range (`names` non-empty): a person's invocations and the template skills the kernel wrote as
|
|
9
|
+
* invocations at a child's start (`user_message.skill.template`), so it names no invoker.
|
|
10
|
+
*/
|
|
2
11
|
export const SKILL_TEXTS = Object.freeze({
|
|
3
12
|
skillsCatalogHeader: "Skills are available in this conversation. A skill is a set of instructions, sometimes with " +
|
|
4
13
|
"scripts or other files, for a specific kind of task. When a task matches a skill's description, " +
|
|
@@ -8,10 +17,7 @@ export const SKILL_TEXTS = Object.freeze({
|
|
|
8
17
|
updatedSkills: `Updated skills (call ${SKILL_LOAD} again before relying on earlier instructions):`,
|
|
9
18
|
currentSkills: "Skills available in this conversation now (this replaces any earlier list of skills; call " +
|
|
10
19
|
`${SKILL_LOAD} with a name to read a skill's instructions):`,
|
|
11
|
-
invokedSkills: (names) => `Skills
|
|
12
|
-
pinnedSkillsHeader: "Pinned skills: the owner of this agent pinned these skills, so their instructions apply " +
|
|
13
|
-
`throughout this conversation. Follow them without calling ${SKILL_LOAD}; call ${SKILL_LOAD} ` +
|
|
14
|
-
"only to copy a pinned skill's files into the sandbox.",
|
|
20
|
+
invokedSkills: (names) => `Skills invoked earlier in this conversation: ${names.join(", ")}. Call ${SKILL_LOAD} with a name to read its instructions again.`,
|
|
15
21
|
});
|
|
16
22
|
/** 目录开头的说明(system 缓存段里的第一份目录)。 */
|
|
17
23
|
export const SKILLS_CATALOG_HEADER = SKILL_TEXTS.skillsCatalogHeader;
|
|
@@ -33,8 +39,7 @@ export const catalogLine = (s) => `- ${s.name}: ${shortDescription(s.description
|
|
|
33
39
|
* The heading of the name-only entries of a listing (skills default-on spec §7): the entries a
|
|
34
40
|
* snapshot recorded past the catalog budget (`nameOnly`). Every listing (the system catalog, a
|
|
35
41
|
* change notice's new or updated skills, the current catalog after a compaction) puts them after
|
|
36
|
-
* its described lines under this heading, names in code point order joined by ", ".
|
|
37
|
-
* with phase 2: no request before it has a name-only entry, so the legacy texts need no copy.
|
|
42
|
+
* its described lines under this heading, names in code point order joined by ", ".
|
|
38
43
|
*/
|
|
39
44
|
export const MORE_SKILLS_HEADER = `More skills (names only; call ${SKILL_LOAD} with the name to read one):`;
|
|
40
45
|
/**
|
|
@@ -55,8 +60,8 @@ function lines(skills) {
|
|
|
55
60
|
return head === "" ? more : `${head}\n${more}`;
|
|
56
61
|
}
|
|
57
62
|
/** 第一份目录(进 system 缓存段),按名字排序。 */
|
|
58
|
-
export function skillsCatalogText(skills
|
|
59
|
-
return `${
|
|
63
|
+
export function skillsCatalogText(skills) {
|
|
64
|
+
return `${SKILL_TEXTS.skillsCatalogHeader}\n${lines(skills)}`;
|
|
60
65
|
}
|
|
61
66
|
/**
|
|
62
67
|
* 两份快照是否相同(按 id、版本、名字、描述与来源)。顺序无关。 Also by `nameOnly` (absent = false):
|
|
@@ -79,34 +84,14 @@ export function sameSkills(a, b) {
|
|
|
79
84
|
});
|
|
80
85
|
}
|
|
81
86
|
/**
|
|
82
|
-
* Two
|
|
83
|
-
*
|
|
84
|
-
* renders no message ({@link pinnedChangeText} is "" and the catalog part is skipped), and only the
|
|
85
|
-
* system segment of a new conversation or a compaction restore shows the new order. This is
|
|
86
|
-
* deliberate and consistent from the log: do not "fix" the missing message.
|
|
87
|
-
*/
|
|
88
|
-
export function samePinned(a, b) {
|
|
89
|
-
const x = a ?? [];
|
|
90
|
-
const y = b ?? [];
|
|
91
|
-
return (x.length === y.length &&
|
|
92
|
-
x.every((p, i) => {
|
|
93
|
-
const q = y[i];
|
|
94
|
-
return q !== undefined && p.id === q.id && p.version === q.version && p.source === q.source;
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Two snapshots are the same: {@link sameSkills} (`plugin` is not compared, so a snapshot written
|
|
99
|
-
* before phase B stays current), {@link samePinned} and the same `toolMap` (absent = undefined).
|
|
87
|
+
* Two snapshots are the same: {@link sameSkills} (`plugin` is not compared) and the same `toolMap`
|
|
88
|
+
* (absent = undefined).
|
|
100
89
|
*/
|
|
101
90
|
export function sameSnapshot(a, b) {
|
|
102
|
-
return
|
|
91
|
+
return sameSkills(a.skills, b.skills) && a.toolMap === b.toolMap;
|
|
103
92
|
}
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
* B) are left out of `updated`: a pinned skill's new body is rendered by {@link pinnedChangeText},
|
|
107
|
-
* and the pinned header says not to call `Skill` for it.
|
|
108
|
-
*/
|
|
109
|
-
function catalogChanges(prev, next, pinnedIds) {
|
|
93
|
+
/** The catalog differences between two snapshots. */
|
|
94
|
+
function catalogChanges(prev, next) {
|
|
110
95
|
const before = new Map(prev.map((s) => [s.id, s]));
|
|
111
96
|
const after = new Map(next.map((s) => [s.id, s]));
|
|
112
97
|
// A skill renamed under its id (the platform components migration renames a clashing org skill)
|
|
@@ -121,7 +106,6 @@ function catalogChanges(prev, next, pinnedIds) {
|
|
|
121
106
|
const p = before.get(s.id);
|
|
122
107
|
return (p !== undefined &&
|
|
123
108
|
p.name === s.name &&
|
|
124
|
-
!pinnedIds?.has(s.id) &&
|
|
125
109
|
(p.version !== s.version ||
|
|
126
110
|
p.description !== s.description ||
|
|
127
111
|
p.source !== s.source ||
|
|
@@ -134,14 +118,14 @@ function catalogChanges(prev, next, pinnedIds) {
|
|
|
134
118
|
* 试用草稿被拒绝 / 批准了别人的同号版本时,内容变了而版本号可能不变)。
|
|
135
119
|
* `prev` 为上一份快照(没有为空)。
|
|
136
120
|
*/
|
|
137
|
-
export function skillsChangeText(prev, next
|
|
138
|
-
const { added, updated, removed } = catalogChanges(prev, next
|
|
121
|
+
export function skillsChangeText(prev, next) {
|
|
122
|
+
const { added, updated, removed } = catalogChanges(prev, next);
|
|
139
123
|
const parts = ["The skills available in this conversation have changed."];
|
|
140
124
|
if (added.length > 0) {
|
|
141
|
-
parts.push(`${
|
|
125
|
+
parts.push(`${SKILL_TEXTS.newSkills}\n${lines(added)}`);
|
|
142
126
|
}
|
|
143
127
|
if (updated.length > 0) {
|
|
144
|
-
parts.push(`${
|
|
128
|
+
parts.push(`${SKILL_TEXTS.updatedSkills}\n${lines(updated)}`);
|
|
145
129
|
}
|
|
146
130
|
if (removed.length > 0) {
|
|
147
131
|
parts.push(`Removed skills (no longer available; do not use them): ${[...removed]
|
|
@@ -154,21 +138,22 @@ export function skillsChangeText(prev, next, pinnedIds, texts = SKILL_TEXTS) {
|
|
|
154
138
|
return parts.join("\n\n");
|
|
155
139
|
}
|
|
156
140
|
/** 压缩摘要之后补上的「当前目录」(与 system 里的第一份不同时):完整列出,替代之前的目录与提醒。 */
|
|
157
|
-
export function skillsCurrentText(skills
|
|
141
|
+
export function skillsCurrentText(skills) {
|
|
158
142
|
if (skills.length === 0) {
|
|
159
143
|
return "No skills are available in this conversation now (this replaces any earlier list of skills).";
|
|
160
144
|
}
|
|
161
|
-
return `${
|
|
145
|
+
return `${SKILL_TEXTS.currentSkills}\n${lines(skills)}`;
|
|
162
146
|
}
|
|
163
|
-
// ----
|
|
147
|
+
// ---- Invoked skills (phase D spec §4.4; model-visible, English) ----
|
|
164
148
|
/**
|
|
165
149
|
* The line restored after a compaction summary whose range holds inline skill invocations
|
|
166
|
-
* (`names`: distinct, code point order
|
|
150
|
+
* (`names`: distinct, code point order; a person's and the template skills the kernel wrote as
|
|
151
|
+
* invocations); empty for none. Bodies are not re-injected.
|
|
167
152
|
*/
|
|
168
|
-
export function invokedSkillsText(names
|
|
153
|
+
export function invokedSkillsText(names) {
|
|
169
154
|
if (names.length === 0)
|
|
170
155
|
return "";
|
|
171
|
-
return
|
|
156
|
+
return SKILL_TEXTS.invokedSkills(names);
|
|
172
157
|
}
|
|
173
158
|
/** The distinct names (code point order) of the inline invocations in `events` up to `upToSeq`. */
|
|
174
159
|
export function invokedSkillNames(events, upToSeq) {
|
|
@@ -225,48 +210,7 @@ export function systemSkillsCatalog(events) {
|
|
|
225
210
|
const earlierCall = events.some((e) => e.type === "model_call" && e.seq < first.seq);
|
|
226
211
|
return earlierCall ? null : first;
|
|
227
212
|
}
|
|
228
|
-
// ----
|
|
229
|
-
/** The header of the pinned skills in the system cache segment. */
|
|
230
|
-
export const PINNED_SKILLS_HEADER = SKILL_TEXTS.pinnedSkillsHeader;
|
|
231
|
-
/** One pinned skill with its body. */
|
|
232
|
-
export function pinnedBlock(p) {
|
|
233
|
-
return `<pinned_skill name="${p.name}" version="${p.version}">\n${p.body.trim()}\n</pinned_skill>`;
|
|
234
|
-
}
|
|
235
|
-
/** The pinned skills of the system snapshot (non-empty), after the catalog. */
|
|
236
|
-
export function pinnedSystemText(pinned, texts = SKILL_TEXTS) {
|
|
237
|
-
return `${texts.pinnedSkillsHeader}\n\n${pinned.map(pinnedBlock).join("\n\n")}`;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* The pinned change notice between two snapshots ({@link samePinned} false): each entry that is new
|
|
241
|
-
* or has another version or source, with its whole body; then the names of the removed ones.
|
|
242
|
-
* Empty when nothing changed.
|
|
243
|
-
*/
|
|
244
|
-
export function pinnedChangeText(prev, next) {
|
|
245
|
-
const before = new Map((prev ?? []).map((p) => [p.id, p]));
|
|
246
|
-
const after = new Set((next ?? []).map((p) => p.id));
|
|
247
|
-
const parts = [];
|
|
248
|
-
for (const p of next ?? []) {
|
|
249
|
-
const was = before.get(p.id);
|
|
250
|
-
if (was && was.version === p.version && was.source === p.source)
|
|
251
|
-
continue;
|
|
252
|
-
parts.push(`Pinned skill "${p.name}" (version ${p.version}) now applies to this conversation and ` +
|
|
253
|
-
`replaces any previous version of it:\n\n${pinnedBlock(p)}`);
|
|
254
|
-
}
|
|
255
|
-
const removed = (prev ?? []).filter((p) => !after.has(p.id)).map((p) => p.name);
|
|
256
|
-
if (removed.length > 0) {
|
|
257
|
-
parts.push(`Pinned skills removed (their pinned instructions no longer apply): ${removed.join(", ")}`);
|
|
258
|
-
}
|
|
259
|
-
return parts.join("\n\n");
|
|
260
|
-
}
|
|
261
|
-
/** The pinned skills after a compaction summary, when they differ from the system snapshot's. */
|
|
262
|
-
export function pinnedCurrentText(pinned) {
|
|
263
|
-
if (!pinned || pinned.length === 0) {
|
|
264
|
-
return "No skills are pinned now (this replaces any earlier pinned skills).";
|
|
265
|
-
}
|
|
266
|
-
return `Pinned skills now (this replaces any earlier pinned skills):\n\n${pinned
|
|
267
|
-
.map(pinnedBlock)
|
|
268
|
-
.join("\n\n")}`;
|
|
269
|
-
}
|
|
213
|
+
// ---- The tool-name map (phase B, spec §9.4; model-visible, English) ----
|
|
270
214
|
/** The tool-name map change notice (the map differs from the previous one). */
|
|
271
215
|
export function toolMapChangeText(next) {
|
|
272
216
|
return next === undefined
|
|
@@ -275,53 +219,37 @@ export function toolMapChangeText(next) {
|
|
|
275
219
|
}
|
|
276
220
|
/**
|
|
277
221
|
* The one system message of a later snapshot: the catalog change (when the skills differ, or when
|
|
278
|
-
*
|
|
279
|
-
* tool-name map change; joined by blank lines.
|
|
222
|
+
* the map does not), the tool-name map change; joined by blank lines.
|
|
280
223
|
*/
|
|
281
|
-
export function snapshotChangeText(prev, next
|
|
224
|
+
export function snapshotChangeText(prev, next) {
|
|
282
225
|
const prevSkills = prev?.skills ?? [];
|
|
283
|
-
const pinnedDiff = !samePinned(prev?.pinned, next.pinned);
|
|
284
226
|
const mapDiff = prev?.toolMap !== next.toolMap;
|
|
285
|
-
// a snapshot with pinned skills leaves them out of the "Updated skills" list; when that leaves no
|
|
286
|
-
// catalog change, the catalog text is skipped (the pinned change carries the message). Logs
|
|
287
|
-
// without `pinned` render exactly as before.
|
|
288
|
-
const pinnedIds = next.pinned && next.pinned.length > 0 ? new Set(next.pinned.map((p) => p.id)) : undefined;
|
|
289
|
-
const c = catalogChanges(prevSkills, next.skills, pinnedIds);
|
|
290
|
-
const catalogDiff = pinnedIds
|
|
291
|
-
? c.added.length + c.updated.length + c.removed.length > 0
|
|
292
|
-
: !sameSkills(prevSkills, next.skills);
|
|
293
227
|
const parts = [];
|
|
294
|
-
if (
|
|
295
|
-
parts.push(skillsChangeText(prevSkills, next.skills
|
|
228
|
+
if (!sameSkills(prevSkills, next.skills) || !mapDiff) {
|
|
229
|
+
parts.push(skillsChangeText(prevSkills, next.skills));
|
|
296
230
|
}
|
|
297
|
-
if (pinnedDiff)
|
|
298
|
-
parts.push(pinnedChangeText(prev?.pinned, next.pinned));
|
|
299
231
|
if (mapDiff)
|
|
300
232
|
parts.push(toolMapChangeText(next.toolMap));
|
|
301
|
-
return parts.
|
|
233
|
+
return parts.join("\n\n");
|
|
302
234
|
}
|
|
303
235
|
/**
|
|
304
236
|
* What follows a compaction summary when the covered snapshot is not the system one: today's
|
|
305
|
-
* current catalog (when the skills differ from the system snapshot's)
|
|
306
|
-
*
|
|
237
|
+
* current catalog (when the skills differ from the system snapshot's) and the tool-name map (when
|
|
238
|
+
* it differs); joined by blank lines, "" for nothing.
|
|
307
239
|
*/
|
|
308
|
-
export function snapshotCurrentText(system, covered
|
|
240
|
+
export function snapshotCurrentText(system, covered) {
|
|
309
241
|
const parts = [];
|
|
310
242
|
if (!sameSkills(system?.skills ?? [], covered.skills)) {
|
|
311
|
-
parts.push(skillsCurrentText(covered.skills
|
|
243
|
+
parts.push(skillsCurrentText(covered.skills));
|
|
312
244
|
}
|
|
313
|
-
if (!samePinned(system?.pinned, covered.pinned))
|
|
314
|
-
parts.push(pinnedCurrentText(covered.pinned));
|
|
315
245
|
if (system?.toolMap !== covered.toolMap) {
|
|
316
246
|
parts.push(toolMapChangeText(covered.toolMap));
|
|
317
247
|
}
|
|
318
248
|
return parts.join("\n\n");
|
|
319
249
|
}
|
|
320
|
-
/** The system snapshot's text after the agent's instructions: catalog,
|
|
321
|
-
export function snapshotSystemText(s
|
|
322
|
-
let text = skillsCatalogText(s.skills
|
|
323
|
-
if (s.pinned && s.pinned.length > 0)
|
|
324
|
-
text += `\n\n${pinnedSystemText(s.pinned, texts)}`;
|
|
250
|
+
/** The system snapshot's text after the agent's instructions: the catalog, then the tool map. */
|
|
251
|
+
export function snapshotSystemText(s) {
|
|
252
|
+
let text = skillsCatalogText(s.skills);
|
|
325
253
|
if (s.toolMap !== undefined)
|
|
326
254
|
text += `\n\n${s.toolMap}`;
|
|
327
255
|
return text;
|
|
@@ -13,9 +13,9 @@ export type ToolsChange = Pick<EventPayload<"tools_changed">, "added" | "removed
|
|
|
13
13
|
* `model_call`'s `tools` and `catalog` keys (with `ToolSearch` the catalog holds the deferred
|
|
14
14
|
* tools, so the union is the whole resolved set), then any `tools_changed` logged after it (a
|
|
15
15
|
* step that logged its change and crashed before its request: the change is not logged twice).
|
|
16
|
-
* Skipped: a
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Skipped: a call whose tools the kernel left out because its model has no tool support
|
|
17
|
+
* (`toolsOmitted`): it says nothing about the resolved set. Null when no request offered a known
|
|
18
|
+
* set yet.
|
|
19
19
|
*/
|
|
20
20
|
export declare function previousToolSet(events: readonly ConversationEvent[]): Set<string> | null;
|
|
21
21
|
/**
|
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
import { TOOLS_UNSUPPORTED_REMINDER } from "./reminders.js";
|
|
2
1
|
/**
|
|
3
2
|
* The tool set the conversation's previous model request offered, from the log alone: the last
|
|
4
3
|
* `model_call`'s `tools` and `catalog` keys (with `ToolSearch` the catalog holds the deferred
|
|
5
4
|
* tools, so the union is the whole resolved set), then any `tools_changed` logged after it (a
|
|
6
5
|
* step that logged its change and crashed before its request: the change is not logged twice).
|
|
7
|
-
* Skipped: a
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Skipped: a call whose tools the kernel left out because its model has no tool support
|
|
7
|
+
* (`toolsOmitted`): it says nothing about the resolved set. Null when no request offered a known
|
|
8
|
+
* set yet.
|
|
10
9
|
*/
|
|
11
10
|
export function previousToolSet(events) {
|
|
12
|
-
const unsupported = new Set();
|
|
13
|
-
for (const e of events) {
|
|
14
|
-
if (e.type === "reminder" && e.payload.text === TOOLS_UNSUPPORTED_REMINDER) {
|
|
15
|
-
unsupported.add(`${e.runId ?? ""}\u0000${e.payload.step}`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
11
|
let known = null;
|
|
19
12
|
for (const e of events) {
|
|
20
13
|
if (e.type === "model_call") {
|
|
21
|
-
const { tools, catalog } = e.payload.request;
|
|
22
|
-
if (
|
|
23
|
-
continue;
|
|
24
|
-
const keys = [...tools, ...(catalog ?? [])].map((t) => t.key);
|
|
25
|
-
if (keys.length === 0 && unsupported.has(`${e.runId ?? ""}\u0000${e.payload.step}`))
|
|
14
|
+
const { tools, catalog, toolsOmitted } = e.payload.request;
|
|
15
|
+
if (toolsOmitted === true)
|
|
26
16
|
continue;
|
|
27
|
-
known = new Set(
|
|
17
|
+
known = new Set([...tools, ...(catalog ?? [])].map((t) => t.key));
|
|
28
18
|
}
|
|
29
19
|
else if (e.type === "tools_changed" && known !== null) {
|
|
30
20
|
for (const k of e.payload.removed)
|
|
@@ -36,12 +36,12 @@ export declare function hookScope(hooks: HookRunner | undefined, s: {
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function fireObserve<K extends "model.response" | "tool.postExecute">(hooks: HookRunner, mount: K, payload: HookPayloads[K], signal: AbortSignal, log: Pick<Logger, "warn">): void;
|
|
38
38
|
/**
|
|
39
|
-
* The `model.request` payload's request (F10, I-3): the request sent to the provider with every image
|
|
40
|
-
* and
|
|
41
|
-
* so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
|
|
42
|
-
* messages, but every message is projected anyway. Building the copy also keeps the per-call
|
|
43
|
-
* and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
|
|
44
|
-
* before sending); it becomes a placeholder of size 0 and logs a warning.
|
|
39
|
+
* The `model.request` payload's request (F10, I-3): the request sent to the provider with every image,
|
|
40
|
+
* document and file block replaced by a {@link HookMediaPlaceholder} (`kind`, `mediaType`, decoded
|
|
41
|
+
* `size`), so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
|
|
42
|
+
* user messages, but every message is projected anyway. Building the copy also keeps the per-call
|
|
43
|
+
* clone and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
|
|
44
|
+
* refs before sending); it becomes a placeholder of size 0 and logs a warning.
|
|
45
45
|
*/
|
|
46
46
|
export declare function hookRequestOf(request: ModelRequest, log?: Pick<Logger, "warn">): HookModelRequest;
|
|
47
47
|
/** Where a denial is recorded (conversation, run, actor and the idem key of its `hook_denied`). */
|
|
@@ -43,17 +43,17 @@ const base64Bytes = (data) => {
|
|
|
43
43
|
return Math.max(0, Math.floor(data.length / 4) * 3 - pad);
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
|
-
* The `model.request` payload's request (F10, I-3): the request sent to the provider with every image
|
|
47
|
-
* and
|
|
48
|
-
* so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
|
|
49
|
-
* messages, but every message is projected anyway. Building the copy also keeps the per-call
|
|
50
|
-
* and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
|
|
51
|
-
* before sending); it becomes a placeholder of size 0 and logs a warning.
|
|
46
|
+
* The `model.request` payload's request (F10, I-3): the request sent to the provider with every image,
|
|
47
|
+
* document and file block replaced by a {@link HookMediaPlaceholder} (`kind`, `mediaType`, decoded
|
|
48
|
+
* `size`), so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
|
|
49
|
+
* user messages, but every message is projected anyway. Building the copy also keeps the per-call
|
|
50
|
+
* clone and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
|
|
51
|
+
* refs before sending); it becomes a placeholder of size 0 and logs a warning.
|
|
52
52
|
*/
|
|
53
53
|
export function hookRequestOf(request, log) {
|
|
54
54
|
let refs = 0;
|
|
55
55
|
const project = (b) => {
|
|
56
|
-
if (b.type !== "image" && b.type !== "document")
|
|
56
|
+
if (b.type !== "image" && b.type !== "document" && b.type !== "file")
|
|
57
57
|
return b;
|
|
58
58
|
if (b.source.kind === "ref")
|
|
59
59
|
refs++;
|
|
@@ -145,6 +145,7 @@ export class LangGraphLoop {
|
|
|
145
145
|
sink: ctx.sink,
|
|
146
146
|
absorbedUpToSeq,
|
|
147
147
|
...(maxSteps !== undefined && { maxSteps }),
|
|
148
|
+
...(ctx.limits.deadline !== undefined && { deadline: ctx.limits.deadline }),
|
|
148
149
|
mediaCache,
|
|
149
150
|
agentId: ctx.agentId,
|
|
150
151
|
accountId: ctx.triggerAccountId,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WorkerHost } from "@nestjs/bullmq";
|
|
2
|
-
import type { Job,
|
|
2
|
+
import type { Job, Worker } from "bullmq";
|
|
3
3
|
import { OwnedPluginCleanup } from "../catalog/owned-plugin-cleanup.js";
|
|
4
4
|
import { ScheduledRuns } from "../infra/schedule/scheduled-runs.js";
|
|
5
5
|
import type { KernelLogger } from "../log.js";
|
|
@@ -42,14 +42,7 @@ export declare class MaintenanceProcessor extends WorkerHost<Worker> {
|
|
|
42
42
|
private readonly deviceOps;
|
|
43
43
|
private readonly scheduled;
|
|
44
44
|
private readonly log;
|
|
45
|
-
|
|
46
|
-
constructor(waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, deviceOps: Pick<DeviceOpResolver, "resolve">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, queue: Pick<Queue, "removeJobScheduler">);
|
|
47
|
-
/**
|
|
48
|
-
* Removes the retired job schedulers (`RETIRED_SCHEDULER_IDS`, runtime/retired-schedulers.ts): every fixed-period
|
|
49
|
-
* maintenance job is a `@LockedCron` / `@LockedInterval` now. Idempotent; called once when a
|
|
50
|
-
* worker role starts.
|
|
51
|
-
*/
|
|
52
|
-
removeRetiredSchedulers(): Promise<void>;
|
|
45
|
+
constructor(waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, deviceOps: Pick<DeviceOpResolver, "resolve">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">);
|
|
53
46
|
process(job: Job, token?: string): Promise<void>;
|
|
54
47
|
/** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
|
|
55
48
|
start(): void;
|
|
@@ -60,8 +53,7 @@ export declare class MaintenanceProcessor extends WorkerHost<Worker> {
|
|
|
60
53
|
/**
|
|
61
54
|
* The maintenance queue's consumer: {@link MaintenanceProcessor}. Imported only by the worker role
|
|
62
55
|
* (`WorkerModule`), so other roles get no processor and no BullMQ worker. It never starts by
|
|
63
|
-
* itself: the worker role (`WorkerRole`)
|
|
64
|
-
* extensions loaded.
|
|
56
|
+
* itself: the worker role (`WorkerRole`) starts it after the extensions loaded.
|
|
65
57
|
*/
|
|
66
58
|
export declare class MaintenanceModule {
|
|
67
59
|
}
|
|
@@ -7,14 +7,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { OnWorkerEvent, WorkerHost } from "@nestjs/bullmq";
|
|
11
11
|
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
12
12
|
import { BG_WAKE_JOB } from "../background/wake-rules.js";
|
|
13
13
|
import { OWNED_PLUGIN_CLEANUP_JOB } from "../catalog/job-ids.js";
|
|
14
14
|
import { OwnedPluginCleanup, OwnedPluginCleanupModule } from "../catalog/owned-plugin-cleanup.js";
|
|
15
15
|
import { configuredProcessor } from "../infra/queue/configured-processor.js";
|
|
16
16
|
import { QueueModule } from "../infra/queue/queue.module.js";
|
|
17
|
-
import { removeRetiredSchedulers } from "../infra/queue/retired-schedulers.js";
|
|
18
17
|
import { runJob } from "../infra/queue/run-job.js";
|
|
19
18
|
import { KernelScheduleModule } from "../infra/schedule/schedule.module.js";
|
|
20
19
|
import { ScheduledRuns } from "../infra/schedule/scheduled-runs.js";
|
|
@@ -33,7 +32,6 @@ import { ToolDrift } from "../tools/drift.js";
|
|
|
33
32
|
import { DRIFT_CONNECTOR_JOB } from "../tools/job-ids.js";
|
|
34
33
|
import { ToolsModule } from "../tools/tools.module.js";
|
|
35
34
|
import { MAINTENANCE_QUEUE_NAME } from "./maintenance-queue.js";
|
|
36
|
-
import { RETIRED_SCHEDULER_IDS } from "./retired-schedulers.js";
|
|
37
35
|
import { RunDeletion, STOP_DELETED_ORG_JOB } from "./run-deletion.js";
|
|
38
36
|
import { ENSURE_RUN_JOB, RunQueue } from "./run-queue.js";
|
|
39
37
|
import { RuntimeModule } from "./runtime.module.js";
|
|
@@ -69,8 +67,7 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
|
|
|
69
67
|
deviceOps;
|
|
70
68
|
scheduled;
|
|
71
69
|
log;
|
|
72
|
-
|
|
73
|
-
constructor(waits, sandbox, drift, directory, deletion, offboarding, runs, ownedCleanup, scheduledTasks, deviceOps, scheduled, log, queue) {
|
|
70
|
+
constructor(waits, sandbox, drift, directory, deletion, offboarding, runs, ownedCleanup, scheduledTasks, deviceOps, scheduled, log) {
|
|
74
71
|
super();
|
|
75
72
|
this.waits = waits;
|
|
76
73
|
this.sandbox = sandbox;
|
|
@@ -84,15 +81,6 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
|
|
|
84
81
|
this.deviceOps = deviceOps;
|
|
85
82
|
this.scheduled = scheduled;
|
|
86
83
|
this.log = log;
|
|
87
|
-
this.queue = queue;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Removes the retired job schedulers (`RETIRED_SCHEDULER_IDS`, runtime/retired-schedulers.ts): every fixed-period
|
|
91
|
-
* maintenance job is a `@LockedCron` / `@LockedInterval` now. Idempotent; called once when a
|
|
92
|
-
* worker role starts.
|
|
93
|
-
*/
|
|
94
|
-
removeRetiredSchedulers() {
|
|
95
|
-
return removeRetiredSchedulers(this.queue, RETIRED_SCHEDULER_IDS);
|
|
96
84
|
}
|
|
97
85
|
process(job, token) {
|
|
98
86
|
return runJob(MAINTENANCE_QUEUE_NAME, job, () => this.dispatch(job, token));
|
|
@@ -180,8 +168,7 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
|
|
|
180
168
|
return;
|
|
181
169
|
// never completed unrun: in a rolling deploy an old worker meets a job a newer replica
|
|
182
170
|
// owed (its outbox row is gone once added); failing it leaves it to BullMQ's retries, so a
|
|
183
|
-
// newer replica can take it within the job's attempts
|
|
184
|
-
// docs/deploy/upgrade.md)
|
|
171
|
+
// newer replica can take it within the job's attempts
|
|
185
172
|
throw new Error(`unknown maintenance job "${job.name}"`);
|
|
186
173
|
}
|
|
187
174
|
}
|
|
@@ -211,15 +198,13 @@ MaintenanceProcessor = __decorate([
|
|
|
211
198
|
__param(8, Inject(ScheduledTaskFirer)),
|
|
212
199
|
__param(9, Inject(DeviceOpResolver)),
|
|
213
200
|
__param(10, Inject(ScheduledRuns)),
|
|
214
|
-
__param(11, Inject(KERNEL_LOGGER))
|
|
215
|
-
__param(12, Inject(getQueueToken(MAINTENANCE_QUEUE_NAME)))
|
|
201
|
+
__param(11, Inject(KERNEL_LOGGER))
|
|
216
202
|
], MaintenanceProcessor);
|
|
217
203
|
export { MaintenanceProcessor };
|
|
218
204
|
/**
|
|
219
205
|
* The maintenance queue's consumer: {@link MaintenanceProcessor}. Imported only by the worker role
|
|
220
206
|
* (`WorkerModule`), so other roles get no processor and no BullMQ worker. It never starts by
|
|
221
|
-
* itself: the worker role (`WorkerRole`)
|
|
222
|
-
* extensions loaded.
|
|
207
|
+
* itself: the worker role (`WorkerRole`) starts it after the extensions loaded.
|
|
223
208
|
*/
|
|
224
209
|
let MaintenanceModule = class MaintenanceModule {
|
|
225
210
|
};
|
|
@@ -148,6 +148,11 @@ export interface ModelStepInput {
|
|
|
148
148
|
* reminder is sent.
|
|
149
149
|
*/
|
|
150
150
|
maxSteps?: number;
|
|
151
|
+
/**
|
|
152
|
+
* The run's deadline in epoch ms (`LoopContext.limits.deadline`); absent: no deadline. A
|
|
153
|
+
* provider's retry-after is honoured when it fits the time left.
|
|
154
|
+
*/
|
|
155
|
+
deadline?: number;
|
|
151
156
|
}
|
|
152
157
|
export interface ModelStepResult {
|
|
153
158
|
content: ContentBlock[];
|
|
@@ -51,10 +51,25 @@ export const contextTooLargeText = (model, target, estimate) => `The request is
|
|
|
51
51
|
/** 可重试错误在同一模型上重试前的默认等待(供应商未给 retryAfterMs 时)。 */
|
|
52
52
|
const DEFAULT_RETRY_DELAY_MS = 1000;
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
54
|
+
* Longest provider-suggested wait (retryAfterMs) honoured on the same model. With a run deadline
|
|
55
|
+
* the wait must also fit the time the run has left.
|
|
56
56
|
*/
|
|
57
|
-
const MAX_RETRY_AFTER_MS =
|
|
57
|
+
const MAX_RETRY_AFTER_MS = 5 * 60_000;
|
|
58
|
+
/**
|
|
59
|
+
* Whether waiting `retryAfterMs` on the same model is allowed, and which limit decided it:
|
|
60
|
+
* the ceiling, or the run's remaining deadline (absent: no deadline, only the ceiling applies).
|
|
61
|
+
*/
|
|
62
|
+
function retryAfterDecision(retryAfterMs, deadline) {
|
|
63
|
+
const wait = retryAfterMs ?? 0;
|
|
64
|
+
const remainingMs = deadline === undefined ? undefined : deadline - Date.now();
|
|
65
|
+
if (wait > MAX_RETRY_AFTER_MS)
|
|
66
|
+
return { fits: false, limit: "ceiling", remainingMs };
|
|
67
|
+
// the wait must leave time for the retry itself: a wait that ends at the deadline is no wait
|
|
68
|
+
if (remainingMs !== undefined && wait >= remainingMs) {
|
|
69
|
+
return { fits: false, limit: "deadline", remainingMs };
|
|
70
|
+
}
|
|
71
|
+
return { fits: true, limit: remainingMs === undefined ? "ceiling" : "deadline", remainingMs };
|
|
72
|
+
}
|
|
58
73
|
/** 读事件日志的分页大小。 */
|
|
59
74
|
const READ_PAGE = 1000;
|
|
60
75
|
/**
|
|
@@ -492,6 +507,9 @@ export function assembleModelRequest(input) {
|
|
|
492
507
|
tools: input.model.capabilities.tools ? [...tools] : [],
|
|
493
508
|
});
|
|
494
509
|
const { request } = built;
|
|
510
|
+
// the omission is recorded, so readers never infer it from the reminder text
|
|
511
|
+
if (tools.length > 0 && !input.model.capabilities.tools)
|
|
512
|
+
built.meta.toolsOmitted = true;
|
|
495
513
|
request.messages = guardToolPairs(request.messages);
|
|
496
514
|
const knob = request.params.maxOutputTokens;
|
|
497
515
|
request.maxOutputTokens = Math.min(input.model.maxOutputTokens, typeof knob === "number" ? knob : defaultMaxOutputTokens);
|
|
@@ -621,39 +639,25 @@ function consecutiveCompactionFailures(events) {
|
|
|
621
639
|
}
|
|
622
640
|
return n;
|
|
623
641
|
}
|
|
624
|
-
/** The step an event of a run belongs to, when its payload names one. */
|
|
625
|
-
function stepOf(e) {
|
|
626
|
-
const step = e.payload.step;
|
|
627
|
-
return typeof step === "number" ? step : undefined;
|
|
628
|
-
}
|
|
629
642
|
/**
|
|
630
643
|
* The ordinal of the next compaction of this run's `step`: 1 + the `compaction_summary` /
|
|
631
644
|
* `compaction_failed` events the step already wrote (context compaction spec §4.4, revision
|
|
632
645
|
* 2026-11-15). It keys the compaction's events (summary, failure, usage, hook denial), so every
|
|
633
646
|
* compaction of a step writes its own, while a crash-retried compaction (nothing written yet) gets
|
|
634
|
-
* the same keys again.
|
|
635
|
-
* have none: a run's step N compacts after every event of its earlier steps, so those are counted
|
|
636
|
-
* from the run's last event of an earlier step on. The backoff keeps counting consecutive failures
|
|
647
|
+
* the same keys again. The backoff keeps counting consecutive failures
|
|
637
648
|
* ({@link consecutiveCompactionFailures}).
|
|
638
649
|
*/
|
|
639
650
|
function compactionOrdinal(events, runId, step) {
|
|
640
651
|
let recorded = 0;
|
|
641
|
-
let legacy = 0;
|
|
642
652
|
for (const e of events) {
|
|
643
653
|
if (e.runId !== runId)
|
|
644
654
|
continue;
|
|
645
|
-
|
|
646
|
-
if (e.type === "compaction_summary" || e.type === "compaction_failed") {
|
|
647
|
-
if (of === undefined)
|
|
648
|
-
legacy++;
|
|
649
|
-
else if (of === step)
|
|
650
|
-
recorded++;
|
|
655
|
+
if (e.type !== "compaction_summary" && e.type !== "compaction_failed")
|
|
651
656
|
continue;
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
legacy = 0;
|
|
657
|
+
if (e.payload.step === step)
|
|
658
|
+
recorded++;
|
|
655
659
|
}
|
|
656
|
-
return recorded +
|
|
660
|
+
return recorded + 1;
|
|
657
661
|
}
|
|
658
662
|
/** Estimated input tokens of a plain text (a user message's only content). */
|
|
659
663
|
function textTokens(text) {
|
|
@@ -1069,12 +1073,15 @@ async function mergeWritten(eventLog, conversationId, events, written) {
|
|
|
1069
1073
|
return out.sort((a, b) => a.seq - b.seq);
|
|
1070
1074
|
}
|
|
1071
1075
|
/**
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1076
|
-
*
|
|
1077
|
-
*
|
|
1076
|
+
* The degradation ladder: the main model -> one retry of the main model (waiting
|
|
1077
|
+
* `retryAfterMs ?? 1000`, abortable) -> `agent.fallback` (when set). The same-model retry is
|
|
1078
|
+
* skipped when the suggested wait does not fit the run's remaining time or exceeds
|
|
1079
|
+
* `MAX_RETRY_AFTER_MS`. After each attempt resolves its model and before it writes `model_call`,
|
|
1080
|
+
* the step's trailing reminders are written (each idempotent per step, written once): the model has
|
|
1081
|
+
* no tool support while the step has tools -> {@link TOOLS_UNSUPPORTED_REMINDER}; then the turn
|
|
1082
|
+
* reminder or the wrap-up reminder (which therefore ends the request). Every real attempt writes
|
|
1083
|
+
* its own `model_call` (attempt counts up from 1, skipped ones not counted); a retry first sends
|
|
1084
|
+
* `step_reset` through the sink. A non-retryable failure or an exhausted ladder -> `RunError`; except that the agent's own model failing to resolve as
|
|
1078
1085
|
* `agent.model_unavailable` (gone from the list, disabled since the agent was saved, its provider
|
|
1079
1086
|
* not configured in the org: spec B §5.3) goes straight to `agent.fallback` when there is one,
|
|
1080
1087
|
* without the same-model retry.
|
|
@@ -1109,14 +1116,19 @@ async function ladder(deps, input, events, runtime, compaction, tools, wrapUpRea
|
|
|
1109
1116
|
for (const rung of rungs) {
|
|
1110
1117
|
if ((mainUnavailable || skipToFallback) && !rung.fallback)
|
|
1111
1118
|
continue;
|
|
1112
|
-
if (last && !rung.fallback
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1119
|
+
if (last && !rung.fallback) {
|
|
1120
|
+
const d = retryAfterDecision(last.retryAfterMs, input.deadline);
|
|
1121
|
+
if (!d.fits) {
|
|
1122
|
+
deps.log.warn("model retry skipped: suggested wait exceeds the limit", {
|
|
1123
|
+
conversationId,
|
|
1124
|
+
runId,
|
|
1125
|
+
step,
|
|
1126
|
+
retryAfterMs: last.retryAfterMs,
|
|
1127
|
+
limit: d.limit,
|
|
1128
|
+
...(d.remainingMs !== undefined && { remainingMs: d.remainingMs }),
|
|
1129
|
+
});
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1120
1132
|
}
|
|
1121
1133
|
// reactive `model.context_overflow` fix-ups, at most one of each per rung (context compaction
|
|
1122
1134
|
// spec §4.4): media exclusion, forced compaction, then a progressive trim
|