@capybara-hq/kernel 0.1.0-rc.23 → 0.1.0-rc.25
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 +25 -25
- package/dist/admin/admin.module.d.ts +2 -1
- package/dist/admin/admin.module.js +9 -3
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +6 -2
- package/dist/admin/outbox-dead.controller.d.ts +23 -0
- package/dist/admin/outbox-dead.controller.js +62 -0
- package/dist/admin/outbox-dead.schemas.d.ts +8 -0
- package/dist/admin/outbox-dead.schemas.js +18 -0
- package/dist/admin/outbox-dead.service.d.ts +66 -0
- package/dist/admin/outbox-dead.service.js +179 -0
- package/dist/admin/overview.service.d.ts +40 -5
- package/dist/admin/overview.service.js +41 -7
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.service.d.ts +6 -1
- package/dist/agents/agents.service.js +11 -2
- package/dist/agents/from-template.js +1 -1
- package/dist/background/finish.d.ts +5 -2
- package/dist/background/finish.js +14 -3
- package/dist/background/launch.d.ts +2 -1
- package/dist/background/launch.js +5 -2
- package/dist/background/store.d.ts +8 -0
- package/dist/background/store.js +24 -0
- package/dist/catalog/admin-catalog.controller.d.ts +21 -2
- package/dist/catalog/admin-catalog.controller.js +45 -6
- package/dist/catalog/admin-catalog.schemas.d.ts +5 -0
- package/dist/catalog/admin-catalog.schemas.js +8 -0
- package/dist/catalog/catalog-import.module.js +0 -4
- package/dist/catalog/catalog-scope.service.d.ts +63 -26
- package/dist/catalog/catalog-scope.service.js +146 -71
- package/dist/catalog/catalog.module.d.ts +2 -1
- package/dist/catalog/catalog.module.js +9 -4
- package/dist/catalog/catalog.service.d.ts +11 -4
- package/dist/catalog/catalog.service.js +21 -5
- package/dist/catalog/cli.d.ts +4 -3
- package/dist/catalog/cli.js +8 -13
- package/dist/catalog/job-ids.d.ts +8 -20
- package/dist/catalog/job-ids.js +11 -16
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-plugin-uploads.d.ts +11 -4
- package/dist/catalog/org-plugin-uploads.js +21 -6
- package/dist/catalog/owned-items.d.ts +6 -13
- package/dist/catalog/owned-items.js +11 -29
- package/dist/catalog/owned-plugin-cleanup.d.ts +8 -17
- package/dist/catalog/owned-plugin-cleanup.js +12 -66
- package/dist/catalog/platform-components.d.ts +56 -34
- package/dist/catalog/platform-components.js +68 -78
- package/dist/catalog/platform-import-update.d.ts +50 -0
- package/dist/catalog/platform-import-update.js +116 -0
- package/dist/catalog/plugin-import.d.ts +64 -26
- package/dist/catalog/plugin-import.js +113 -77
- package/dist/catalog/plugin-upgrade.d.ts +22 -4
- package/dist/catalog/plugin-upgrade.js +26 -19
- package/dist/catalog/scope-jobs.d.ts +59 -0
- package/dist/catalog/scope-jobs.js +65 -0
- package/dist/catalog/scope-sync-workers.d.ts +22 -0
- package/dist/catalog/scope-sync-workers.js +58 -2
- package/dist/catalog/scope-sync.d.ts +40 -65
- package/dist/catalog/scope-sync.js +114 -122
- package/dist/channels/channels.module.d.ts +5 -2
- package/dist/channels/channels.module.js +9 -2
- package/dist/channels/deliver-job.d.ts +25 -0
- package/dist/channels/deliver-job.js +25 -0
- package/dist/channels/inbound.d.ts +1 -1
- package/dist/channels/inbound.js +4 -17
- package/dist/channels/jobs.d.ts +28 -18
- package/dist/channels/jobs.js +63 -26
- package/dist/channels/threads.d.ts +4 -3
- package/dist/channels/threads.js +4 -3
- package/dist/config/schema.d.ts +0 -3
- package/dist/config/schema.js +11 -20
- package/dist/conversations/agent-tree.d.ts +16 -0
- package/dist/conversations/agent-tree.js +36 -0
- package/dist/conversations/conversations.controller.js +4 -2
- package/dist/conversations/conversations.service.d.ts +61 -19
- package/dist/conversations/conversations.service.js +69 -43
- package/dist/conversations/event-log.d.ts +7 -10
- package/dist/conversations/event-log.js +24 -15
- package/dist/conversations/events.d.ts +21 -0
- package/dist/conversations/events.js +26 -2
- package/dist/conversations/queue.service.d.ts +8 -3
- package/dist/conversations/queue.service.js +37 -13
- package/dist/conversations/source.d.ts +10 -0
- package/dist/conversations/source.js +17 -0
- package/dist/conversations/titles.d.ts +21 -8
- package/dist/conversations/titles.js +42 -15
- package/dist/conversations/tree.d.ts +10 -0
- package/dist/conversations/tree.js +35 -0
- package/dist/db/kernel-schema.d.ts +35 -22
- package/dist/devices/devices.service.d.ts +23 -11
- package/dist/devices/devices.service.js +34 -26
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +11 -0
- package/dist/evals/run-replay.d.ts +13 -2
- package/dist/evals/run-replay.js +42 -9
- package/dist/evals/snapshot.d.ts +7 -1
- package/dist/evals/snapshot.js +2 -1
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/hooks.d.ts +22 -3
- package/dist/extensions/hooks.js +15 -1
- package/dist/extensions/lifecycle-hooks.d.ts +99 -0
- package/dist/extensions/lifecycle-hooks.js +273 -0
- package/dist/extensions/lifecycle.d.ts +6 -1
- package/dist/extensions/lifecycle.js +9 -2
- package/dist/extensions/org-config.d.ts +13 -1
- package/dist/extensions/org-config.js +19 -2
- package/dist/extensions/permission-view.d.ts +9 -5
- package/dist/extensions/permission-view.js +9 -4
- package/dist/extensions/point-defaults.d.ts +28 -1
- package/dist/extensions/point-defaults.js +44 -13
- package/dist/extensions/usage-subscribers.d.ts +43 -0
- package/dist/extensions/usage-subscribers.js +108 -0
- package/dist/http/api.module.js +2 -0
- package/dist/inbox/inbox.service.d.ts +6 -20
- package/dist/inbox/inbox.service.js +0 -3
- package/dist/inbox/org-notices.d.ts +1 -1
- package/dist/inbox/platform-inbox.service.d.ts +3 -32
- package/dist/inbox/platform-inbox.service.js +5 -54
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/infra/cli/kernel-cli.module.js +5 -0
- package/dist/infra/events/kernel-events.d.ts +9 -35
- package/dist/infra/outbox/outbox-relay.module.d.ts +6 -0
- package/dist/infra/outbox/outbox-relay.module.js +18 -0
- package/dist/infra/outbox/outbox.dispatcher.d.ts +103 -0
- package/dist/infra/outbox/outbox.dispatcher.js +310 -0
- package/dist/infra/outbox/outbox.module.d.ts +24 -0
- package/dist/infra/outbox/outbox.module.js +50 -0
- package/dist/infra/outbox/outbox.relay.d.ts +31 -0
- package/dist/infra/outbox/outbox.relay.js +76 -0
- package/dist/infra/outbox/outbox.service.d.ts +51 -0
- package/dist/infra/outbox/outbox.service.js +131 -0
- package/dist/infra/outbox/registry.d.ts +244 -0
- package/dist/infra/outbox/registry.js +234 -0
- package/dist/infra/queue/queue-names.d.ts +8 -0
- package/dist/infra/queue/queue-names.js +17 -0
- package/dist/kernel.module.js +3 -0
- package/dist/local-devices/device-policy.service.d.ts +4 -0
- package/dist/local-devices/device-policy.service.js +61 -3
- package/dist/local-devices/machines.d.ts +13 -5
- package/dist/local-devices/machines.js +45 -7
- package/dist/local-devices/policy-summary.d.ts +44 -1
- package/dist/local-devices/policy-summary.js +69 -0
- package/dist/models/embeddings.d.ts +9 -9
- package/dist/models/embeddings.js +11 -18
- package/dist/models/models.module.js +3 -0
- package/dist/orgs/directory-sync.js +1 -1
- package/dist/orgs/members.service.js +1 -1
- package/dist/orgs/offboarding.d.ts +50 -57
- package/dist/orgs/offboarding.js +117 -162
- package/dist/orgs/orgs.module.js +3 -0
- package/dist/orgs/orgs.service.d.ts +11 -5
- package/dist/orgs/orgs.service.js +22 -6
- package/dist/overrides.d.ts +23 -3
- package/dist/overrides.js +12 -2
- package/dist/platform/exclusions.js +5 -0
- package/dist/platform/ops/admin.ops.js +18 -2
- package/dist/platform/ops/catalog-admin.ops.d.ts +3 -1
- package/dist/platform/ops/catalog-admin.ops.js +32 -4
- package/dist/platform/ops/inbox.ops.js +4 -20
- package/dist/platform/ops/outbox.ops.d.ts +21 -0
- package/dist/platform/ops/outbox.ops.js +125 -0
- package/dist/platform/ops/platform.ops.d.ts +1 -0
- package/dist/platform/ops/platform.ops.js +6 -3
- package/dist/platform/ops/schedules.ops.js +40 -1
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +3 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker-role.d.ts +10 -5
- package/dist/roles/worker-role.js +19 -9
- package/dist/roles/worker.module.js +11 -8
- package/dist/runtime/context/build.d.ts +3 -0
- package/dist/runtime/context/build.js +15 -0
- package/dist/runtime/context/plugin-context.d.ts +20 -0
- package/dist/runtime/context/plugin-context.js +30 -0
- package/dist/runtime/langgraph-loop.js +17 -5
- package/dist/runtime/limits.d.ts +15 -0
- package/dist/runtime/limits.js +25 -0
- package/dist/runtime/loop.d.ts +16 -3
- package/dist/runtime/loop.js +2 -1
- package/dist/runtime/maintenance.d.ts +7 -3
- package/dist/runtime/maintenance.js +52 -12
- package/dist/runtime/model-call.d.ts +20 -17
- package/dist/runtime/model-call.js +15 -24
- package/dist/runtime/plugin-context.service.d.ts +69 -0
- package/dist/runtime/plugin-context.service.js +208 -0
- package/dist/runtime/queue-lost-jobs.d.ts +24 -0
- package/dist/runtime/queue-lost-jobs.js +51 -0
- package/dist/runtime/run-control.d.ts +47 -5
- package/dist/runtime/run-control.js +79 -12
- package/dist/runtime/run-finish.d.ts +39 -12
- package/dist/runtime/run-finish.js +97 -14
- package/dist/runtime/run-jobs.d.ts +95 -13
- package/dist/runtime/run-jobs.js +199 -28
- package/dist/runtime/run-orphan-check.job.d.ts +142 -0
- package/dist/runtime/run-orphan-check.job.js +339 -0
- package/dist/runtime/run-processors.d.ts +16 -9
- package/dist/runtime/run-processors.js +1 -1
- package/dist/runtime/run-queue.d.ts +75 -53
- package/dist/runtime/run-queue.js +189 -263
- package/dist/runtime/run-steps.d.ts +1 -2
- package/dist/runtime/run-steps.js +8 -11
- package/dist/runtime/run-worker.d.ts +26 -16
- package/dist/runtime/run-worker.js +132 -37
- package/dist/runtime/runtime.module.d.ts +2 -3
- package/dist/runtime/runtime.module.js +7 -6
- package/dist/runtime/step-log.d.ts +16 -4
- package/dist/runtime/step-log.js +26 -6
- package/dist/runtime/stream.controller.d.ts +2 -4
- package/dist/runtime/stream.controller.js +5 -11
- package/dist/runtime/subagents/child.js +1 -1
- package/dist/runtime/subagents/definition.d.ts +2 -1
- package/dist/runtime/subagents/definition.js +4 -2
- package/dist/runtime/subagents/deliveries.d.ts +6 -3
- package/dist/runtime/subagents/deliveries.js +16 -7
- package/dist/runtime/subagents/dispatch.d.ts +12 -12
- package/dist/runtime/subagents/dispatch.js +14 -38
- package/dist/runtime/subagents/messages.d.ts +5 -1
- package/dist/runtime/subagents/messages.js +11 -3
- package/dist/runtime/subagents/skill-fork.d.ts +3 -3
- package/dist/runtime/subagents/skill-fork.js +8 -5
- package/dist/runtime/subagents/subagents.service.js +1 -1
- package/dist/runtime/subagents/tree-jobs.d.ts +61 -0
- package/dist/runtime/subagents/tree-jobs.js +86 -0
- package/dist/runtime/usage-report-jobs.d.ts +23 -48
- package/dist/runtime/usage-report-jobs.js +67 -119
- package/dist/runtime/usage-report.d.ts +28 -77
- package/dist/runtime/usage-report.js +35 -213
- package/dist/runtime/waits.d.ts +48 -198
- package/dist/runtime/waits.js +103 -805
- package/dist/sandbox/jobs.d.ts +20 -10
- package/dist/sandbox/jobs.js +23 -17
- package/dist/sandbox/sandbox.service.d.ts +17 -4
- package/dist/sandbox/sandbox.service.js +55 -14
- package/dist/schedules/calendar.d.ts +134 -0
- package/dist/schedules/calendar.js +410 -0
- package/dist/schedules/fire.d.ts +26 -7
- package/dist/schedules/fire.js +91 -22
- package/dist/schedules/job-ids.d.ts +66 -17
- package/dist/schedules/job-ids.js +81 -13
- package/dist/schedules/run-tracker.d.ts +0 -5
- package/dist/schedules/run-tracker.js +2 -14
- package/dist/schedules/scan.job.d.ts +13 -32
- package/dist/schedules/scan.job.js +50 -164
- package/dist/schedules/schedule-math.d.ts +42 -0
- package/dist/schedules/schedule-math.js +52 -0
- package/dist/schedules/scheduled-tasks.service.d.ts +22 -6
- package/dist/schedules/scheduled-tasks.service.js +70 -14
- package/dist/schedules/schedules.controller.d.ts +5 -1
- package/dist/schedules/schedules.controller.js +15 -1
- package/dist/schedules/schedules.module.js +0 -4
- package/dist/schedules/schedules.schemas.d.ts +35 -0
- package/dist/schedules/schedules.schemas.js +27 -0
- package/dist/schedules/store.d.ts +5 -0
- package/dist/schedules/store.js +20 -0
- package/dist/skills/changes.controller.d.ts +1 -1
- package/dist/skills/changes.controller.js +1 -1
- package/dist/tools/approvals.service.d.ts +41 -11
- package/dist/tools/approvals.service.js +108 -14
- package/dist/tools/builtin-names.d.ts +5 -3
- package/dist/tools/builtin-names.js +12 -4
- package/dist/tools/builtins/builtin-tools.d.ts +1 -2
- package/dist/tools/builtins/builtin-tools.js +21 -17
- package/dist/tools/builtins/sandbox/bash.js +9 -3
- package/dist/tools/builtins/sandbox/common.d.ts +18 -1
- package/dist/tools/builtins/sandbox/common.js +14 -1
- package/dist/tools/builtins/sandbox/index.d.ts +2 -1
- package/dist/tools/builtins/sandbox/index.js +4 -1
- package/dist/tools/builtins/sandbox/task-list.d.ts +12 -0
- package/dist/tools/builtins/sandbox/task-list.js +130 -0
- package/dist/tools/builtins/sandbox/task-output.d.ts +8 -1
- package/dist/tools/builtins/sandbox/task-output.js +21 -3
- package/dist/tools/builtins/web/extract.d.ts +2 -4
- package/dist/tools/builtins/web/extract.js +2 -5
- package/dist/tools/pipeline.d.ts +12 -3
- package/dist/tools/pipeline.js +6 -1
- package/dist/tools/questions.service.d.ts +30 -10
- package/dist/tools/questions.service.js +41 -27
- package/dist/tools/registry.d.ts +12 -3
- package/dist/tools/registry.js +13 -3
- package/dist/tools/tools.module.js +4 -3
- package/package.json +3 -3
- package/src/migrations/0118_device_policy_ops.sql +6 -0
- package/src/migrations/0119_outbox.sql +22 -0
- package/src/migrations/0120_drop_usage_report_sweep.sql +7 -0
- package/src/migrations/0121_drop_platform_migration_runs.sql +12 -0
- package/src/migrations/0122_drop_scheduled_task_runs_rechecked_at.sql +5 -0
- package/src/migrations/0123_pgvector.sql +27 -0
- package/src/migrations/0124_conversation_source.sql +36 -0
- package/dist/catalog/platform-migration.d.ts +0 -115
- package/dist/catalog/platform-migration.js +0 -583
- package/dist/infra/queue/add-job-once.d.ts +0 -14
- package/dist/infra/queue/add-job-once.js +0 -16
|
@@ -17,9 +17,9 @@ import { ModelsModule } from "../models/models.module.js";
|
|
|
17
17
|
import { OrgLockModule } from "../orgs/org-lock.js";
|
|
18
18
|
import { PlatformModule } from "../platform/platform.module.js";
|
|
19
19
|
import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
|
|
20
|
+
import { RunJobsModule } from "../runtime/run-jobs.js";
|
|
20
21
|
import { StepLogModule } from "../runtime/step-log.js";
|
|
21
22
|
import { SubagentsModule } from "../runtime/subagents/subagents.service.js";
|
|
22
|
-
import { UsageReportModule } from "../runtime/usage-report.js";
|
|
23
23
|
import { SandboxModule } from "../sandbox/sandbox.module.js";
|
|
24
24
|
import { ScheduledTaskStoreModule } from "../schedules/store.module.js";
|
|
25
25
|
import { SkillsModule } from "../skills/skills.module.js";
|
|
@@ -72,10 +72,11 @@ ToolsModule = __decorate([
|
|
|
72
72
|
BackgroundModule,
|
|
73
73
|
// the conversation page's tool metadata reads only what the viewer may see
|
|
74
74
|
ConversationAccessModule,
|
|
75
|
-
// the WebFetch extraction call: its purpose
|
|
75
|
+
// the WebFetch extraction call: its purpose and step writes (its usage report owed with them)
|
|
76
76
|
ModelsModule,
|
|
77
|
-
UsageReportModule,
|
|
78
77
|
StepLogModule,
|
|
78
|
+
// a decision resumes its waiting run in the decision's transaction (`RunResume`)
|
|
79
|
+
RunJobsModule,
|
|
79
80
|
// the `Platform` tool's operations, actor facts and agent docs (imports no domain module)
|
|
80
81
|
PlatformModule,
|
|
81
82
|
QueueModule.registerQueue(MAINTENANCE_QUEUE_NAME),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.25",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"yaml": "^2.9.1",
|
|
66
66
|
"yauzl": "3.4.0",
|
|
67
67
|
"zod": "^4.6.7",
|
|
68
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
68
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.19"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@types/ws": "^8.18.2",
|
|
75
75
|
"@types/yauzl": "3.4.0",
|
|
76
76
|
"ws": "^8.22.0",
|
|
77
|
-
"@capybara-hq/testing": "0.1.0-rc.
|
|
77
|
+
"@capybara-hq/testing": "0.1.0-rc.17"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"build": "tsc -b"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- The `policy` ops the platform sent to a machine whose answer may not be recorded yet (sandbox dev
|
|
2
|
+
-- tiers spec §10.4): a summary the machine reports by itself (a `policy` frame, the next hello)
|
|
3
|
+
-- that is such an op's change is not listed again as a change made on the machine. A JSON array of
|
|
4
|
+
-- `{ id, add, remove, tier?, isolation?, until }`; an entry leaves when its answer is recorded or,
|
|
5
|
+
-- unanswered, when `until` (epoch ms) has passed.
|
|
6
|
+
ALTER TABLE device_machines ADD COLUMN IF NOT EXISTS pending_policy_ops jsonb NOT NULL DEFAULT '[]'::jsonb;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
-- Transactional outbox (transactional outbox spec §4): work that must follow a commit is written
|
|
2
|
+
-- here in the same transaction as the state that owes it, and a relay delivers it to BullMQ. Rows are
|
|
3
|
+
-- deleted on delivery; only dead rows (`dead_at` set) stay.
|
|
4
|
+
|
|
5
|
+
CREATE TABLE IF NOT EXISTS outbox (
|
|
6
|
+
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
7
|
+
queue text NOT NULL,
|
|
8
|
+
job_name text NOT NULL,
|
|
9
|
+
job_id text NOT NULL,
|
|
10
|
+
data jsonb NOT NULL,
|
|
11
|
+
run_at timestamptz,
|
|
12
|
+
org_id text, -- for the overview and for org deletion; NULL for platform work
|
|
13
|
+
attempts integer NOT NULL DEFAULT 0,
|
|
14
|
+
next_attempt_at timestamptz NOT NULL DEFAULT now(),
|
|
15
|
+
last_error text,
|
|
16
|
+
dead_at timestamptz,
|
|
17
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
18
|
+
);
|
|
19
|
+
-- one pending row per job: a second add of the same job before delivery is a no-op; a dead row
|
|
20
|
+
-- does not count, so it never blocks the same job owed again
|
|
21
|
+
CREATE UNIQUE INDEX IF NOT EXISTS outbox_job_uniq ON outbox (queue, job_id) WHERE dead_at IS NULL;
|
|
22
|
+
CREATE INDEX IF NOT EXISTS outbox_due ON outbox (next_attempt_at) WHERE dead_at IS NULL;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- 0120, transactional outbox spec §8.1 / §8.2: a `usage.report` delivery is owed in the outbox
|
|
2
|
+
-- with the usage it reports, so the usage sweeper is gone, and with it its watermark table and the
|
|
3
|
+
-- index it found unreported `model_usage` rows by. (`conversation_events_usage_idx` stays: the
|
|
4
|
+
-- admin usage aggregate reads usage events by time.)
|
|
5
|
+
-- capybara:allow-destructive the sweeper that read and wrote this single-row watermark is removed in this release (project not released, no compatibility layer)
|
|
6
|
+
DROP TABLE IF EXISTS usage_report_sweep;
|
|
7
|
+
DROP INDEX IF EXISTS model_usage_unreported;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- 0121, transactional outbox spec §8.2: the platform components migration job is gone (an import
|
|
2
|
+
-- writes its platform components in its transaction), so nothing writes its runs table any more and
|
|
3
|
+
-- the platform inbox no longer shows a run; the org notice kind `skill_renamed`, which only that job
|
|
4
|
+
-- wrote, goes with it.
|
|
5
|
+
-- capybara:allow-destructive the job that wrote this table is removed in this release and nothing reads it (project not released, no compatibility layer)
|
|
6
|
+
DROP TABLE IF EXISTS platform_migration_runs;
|
|
7
|
+
-- capybara:allow-destructive notices of a kind only the removed job wrote; the inbox no longer renders the kind (project not released)
|
|
8
|
+
DELETE FROM org_notices WHERE kind = 'skill_renamed';
|
|
9
|
+
-- capybara:allow-destructive the check is added back without `skill_renamed` in the next statement; no row has that kind any more
|
|
10
|
+
ALTER TABLE org_notices DROP CONSTRAINT IF EXISTS org_notices_kind_check;
|
|
11
|
+
ALTER TABLE org_notices ADD CONSTRAINT org_notices_kind_check
|
|
12
|
+
CHECK (kind IN ('item_shared', 'shared_item_updated', 'upload_confirmed', 'upload_rejected'));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- 0122, transactional outbox spec §8.1 / §8.2: the transaction that writes a pending task run owes
|
|
2
|
+
-- its fire job in the outbox, so the scheduled task scan's repair is gone, and with it the column
|
|
3
|
+
-- that rotated the repair's rechecks of started runs.
|
|
4
|
+
-- capybara:allow-destructive the repair that read and wrote this column is removed in this release and nothing else reads it (project not released, no compatibility layer)
|
|
5
|
+
ALTER TABLE scheduled_task_runs DROP COLUMN IF EXISTS rechecked_at;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- pgvector, when the server offers it (memory plugin spec §6.4). Plugins store embeddings in a
|
|
2
|
+
-- `vector` column when the type is visible from their search_path (`plugin_<name>, public`) and fall
|
|
3
|
+
-- back to `real[]` otherwise, so pgvector is recommended, not required:
|
|
4
|
+
-- - not offered by the server (no row in pg_available_extensions): nothing to do;
|
|
5
|
+
-- - already installed, in whatever schema a DBA put it: left where it is;
|
|
6
|
+
-- - refused (insufficient_privilege: the migrating role may not create it; feature_not_supported:
|
|
7
|
+
-- a managed server lists it but its vendor allow-list refuses it, e.g. Azure Flexible Server):
|
|
8
|
+
-- a notice naming the SQLSTATE, the migration succeeds. Any other error still fails it.
|
|
9
|
+
-- `SCHEMA public` matters: the migrator's search_path is `capybara, public`, and a bare
|
|
10
|
+
-- CREATE EXTENSION would put the type and `<=>` in `capybara`, invisible to plugin schemas.
|
|
11
|
+
-- capybara:allow-destructive not destructive: a DO block is the only way to make CREATE EXTENSION conditional on availability and to turn a refused CREATE EXTENSION into a notice
|
|
12
|
+
DO $$
|
|
13
|
+
BEGIN
|
|
14
|
+
IF NOT EXISTS (SELECT 1 FROM pg_available_extensions WHERE name = 'vector') THEN
|
|
15
|
+
RAISE NOTICE 'pgvector is not available on this server; plugins fall back to real[] embeddings';
|
|
16
|
+
RETURN;
|
|
17
|
+
END IF;
|
|
18
|
+
IF EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector') THEN
|
|
19
|
+
RETURN;
|
|
20
|
+
END IF;
|
|
21
|
+
BEGIN
|
|
22
|
+
EXECUTE 'CREATE EXTENSION IF NOT EXISTS vector SCHEMA public';
|
|
23
|
+
EXCEPTION WHEN insufficient_privilege OR feature_not_supported THEN
|
|
24
|
+
RAISE NOTICE 'pgvector not installed: CREATE EXTENSION was refused (SQLSTATE %: %); plugins fall back to real[] embeddings', SQLSTATE, SQLERRM;
|
|
25
|
+
END;
|
|
26
|
+
END
|
|
27
|
+
$$;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
-- Memory plugin spec §6.2: where a conversation comes from (web, channel_dm, channel_group,
|
|
2
|
+
-- subagent), set once at creation and never changed; extension tools and context@1 providers are
|
|
3
|
+
-- offered by it.
|
|
4
|
+
-- The column is added with a constant default, so existing rows read 'web' without a rewrite.
|
|
5
|
+
-- The backfill then sets the other sources, each UPDATE touching only rows still at 'web', so a
|
|
6
|
+
-- re-run updates nothing; later UPDATEs skip rows an earlier one set:
|
|
7
|
+
-- 1. kind 'subagent' -> subagent;
|
|
8
|
+
-- 2. a channel thread row of any archive state (DM /new archives the row, the conversation stays
|
|
9
|
+
-- a DM's): only 'dm:' keys -> channel_dm, any other key -> channel_group (a conversation with
|
|
10
|
+
-- both is a group's: the safer of the two);
|
|
11
|
+
-- 3. a scheduled group run whose thread is still to bind at its first post (no thread row yet):
|
|
12
|
+
-- its delivery's target chat type.
|
|
13
|
+
-- The rest stays web. The CHECK is added last (dropped first, so a re-run re-adds it).
|
|
14
|
+
ALTER TABLE conversations ADD COLUMN IF NOT EXISTS source text NOT NULL DEFAULT 'web';
|
|
15
|
+
|
|
16
|
+
UPDATE conversations SET source = 'subagent'
|
|
17
|
+
WHERE kind = 'subagent' AND source = 'web';
|
|
18
|
+
|
|
19
|
+
UPDATE conversations c
|
|
20
|
+
SET source = CASE WHEN t.dm THEN 'channel_dm' ELSE 'channel_group' END
|
|
21
|
+
FROM (
|
|
22
|
+
SELECT conversation_id, bool_and(thread_key LIKE 'dm:%') AS dm
|
|
23
|
+
FROM channel_threads
|
|
24
|
+
GROUP BY conversation_id
|
|
25
|
+
) t
|
|
26
|
+
WHERE t.conversation_id = c.id AND c.source = 'web';
|
|
27
|
+
|
|
28
|
+
UPDATE conversations c
|
|
29
|
+
SET source = CASE WHEN d.target->>'chatType' = 'dm' THEN 'channel_dm' ELSE 'channel_group' END
|
|
30
|
+
FROM channel_deliveries d
|
|
31
|
+
WHERE d.conversation_id = c.id AND d.target->>'chatType' IN ('dm', 'group') AND c.source = 'web';
|
|
32
|
+
|
|
33
|
+
-- capybara:allow-destructive the CHECK is re-added unchanged right below (a re-run of this file)
|
|
34
|
+
ALTER TABLE conversations DROP CONSTRAINT IF EXISTS conversations_source_check;
|
|
35
|
+
ALTER TABLE conversations ADD CONSTRAINT conversations_source_check
|
|
36
|
+
CHECK (source IN ('web', 'channel_dm', 'channel_group', 'subagent'));
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
2
|
-
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
4
|
-
import { LockService } from "../infra/lock/lock.service.js";
|
|
5
|
-
import type { KernelLogger } from "../log.js";
|
|
6
|
-
import { OrgLock } from "../orgs/org-lock.js";
|
|
7
|
-
import { PlatformComponents } from "./platform-components.js";
|
|
8
|
-
/** The job's name (`@LockedInterval`, run lock `cron:platform-components-migrate`). */
|
|
9
|
-
export declare const PLATFORM_MIGRATION_JOB = "platform-components-migrate";
|
|
10
|
-
/** The audit action and inbox notice of a renamed skill. */
|
|
11
|
-
export declare const SKILL_RENAMED = "skill_renamed";
|
|
12
|
-
/** What one run changed (also stored in `platform_migration_runs.stats`). */
|
|
13
|
-
export interface PlatformMigrationStats {
|
|
14
|
-
/** Catalog items whose platform rows were written (`<name>@<version>`). */
|
|
15
|
-
itemsSynced: string[];
|
|
16
|
-
/** Catalog items whose sync failed (logged; tried again by the next run). */
|
|
17
|
-
itemsFailed: string[];
|
|
18
|
-
/** Org skill copies linked to their platform skill, and how many of them were pinned. */
|
|
19
|
-
skillsLinked: number;
|
|
20
|
-
skillsPinned: number;
|
|
21
|
-
/** Org skills renamed because a platform skill of the same name is on in their org. */
|
|
22
|
-
skillsRenamed: number;
|
|
23
|
-
/** Org template copies linked to their platform template, and how many of them were pinned. */
|
|
24
|
-
templatesLinked: number;
|
|
25
|
-
templatesPinned: number;
|
|
26
|
-
/** Connectors linked to the platform connector template they were made from. */
|
|
27
|
-
connectorsLinked: number;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* The name a renamed skill gets: `<name>-org`, then `-org-2`, `-org-3`, … (the base shortened
|
|
31
|
-
* when the result would be longer than a skill name may be), the first one not in `taken`.
|
|
32
|
-
*/
|
|
33
|
-
export declare function renamedSkillName(name: string, taken: ReadonlySet<string>): string;
|
|
34
|
-
/**
|
|
35
|
-
* The platform components migration (spec §6, §13.5), a worker job (`platform-components-migrate`,
|
|
36
|
-
* `@LockedInterval` with `runOnStart`: once across replicas at every worker start, then daily).
|
|
37
|
-
* Steps, each on the rows that still need it:
|
|
38
|
-
* 1. every live catalog item never synced (`platform_synced_version` null) gets its platform rows
|
|
39
|
-
* (`syncFromVersion`, which records the version) at the highest
|
|
40
|
-
* version installed in an org (spec §6: "the plugin's version becomes the highest installed
|
|
41
|
-
* one"), else its latest version;
|
|
42
|
-
* 2. an org skill copy with plugin provenance (on the skill and its current version) links to the
|
|
43
|
-
* platform skill of its plugin and name; it is pinned to its own current version when its files
|
|
44
|
-
* differ from the platform version's. A copy whose platform skill is not on in its org is left
|
|
45
|
-
* unlinked (it keeps serving what it served) until a later run finds it on: a linked copy,
|
|
46
|
-
* pinned or not, follows its platform skill's availability (ruling P2-18);
|
|
47
|
-
* 3. one-shot (spec §5 rule 10, ruling P2-5: nothing is renamed outside the migration): only while
|
|
48
|
-
* no run has finished (the first run's own execution), an org skill of the org's own (no
|
|
49
|
-
* provenance) whose name a platform skill on in its org has stays the org's: it is renamed (`<name>-org`, `-org-2`, …), the org admins get an inbox notice
|
|
50
|
-
* (`skill_renamed`) and that platform skill is switched off in the org (a switch the org already
|
|
51
|
-
* has is kept). Agents select skills by id, so they keep it; the name changes in new runs. Once a
|
|
52
|
-
* run has finished, a clash is only logged as a warning and left alone (the org's skill wins);
|
|
53
|
-
* 4. an org agent template links to the platform template of its plugin and name, pinned like
|
|
54
|
-
* skills (definitions compared as canonical JSON). Templates are never renamed: an org template
|
|
55
|
-
* always has its plugin's type, which is the platform template's;
|
|
56
|
-
* 5. a connector made from a connector template (the install ledger's `template_id`) links to that
|
|
57
|
-
* platform connector template (ruling E2).
|
|
58
|
-
* Plugin switches exist since phase 1 and new platform rows follow the plugin's scope, so nothing
|
|
59
|
-
* else is written. Writes run per org under its row lock and re-check each row; nothing is deleted
|
|
60
|
-
* or overwritten except the renamed skill's name. Each run is recorded in `platform_migration_runs`
|
|
61
|
-
* (rows older than 30 days are pruned, except the first finished run: it marks the renames done).
|
|
62
|
-
*/
|
|
63
|
-
export declare class PlatformMigration {
|
|
64
|
-
private readonly kdb;
|
|
65
|
-
private readonly orgLock;
|
|
66
|
-
private readonly platform;
|
|
67
|
-
readonly txHost: TransactionHost;
|
|
68
|
-
readonly config: KernelConfigService;
|
|
69
|
-
readonly lockService: LockService;
|
|
70
|
-
readonly log: KernelLogger;
|
|
71
|
-
constructor(kdb: KernelDb, orgLock: OrgLock, platform: PlatformComponents, txHost: TransactionHost, config: KernelConfigService, lockService: LockService, log: KernelLogger);
|
|
72
|
-
private get db();
|
|
73
|
-
/** The scheduled run (see the class). */
|
|
74
|
-
migrate(signal?: AbortSignal): Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* One run of every step; returns what it changed. `signal` (the stop, or a lost run lock) is
|
|
77
|
-
* read between items and orgs: an aborted run stops there and its row is deleted (every step is
|
|
78
|
-
* idempotent, so the next run carries on; an unfinished run never counts as the first one).
|
|
79
|
-
*/
|
|
80
|
-
runOnce(signal?: AbortSignal): Promise<PlatformMigrationStats>;
|
|
81
|
-
/** Deletes finished runs older than {@link RUNS_KEPT_MS}, never the first one (`first`). */
|
|
82
|
-
private pruneRuns;
|
|
83
|
-
/**
|
|
84
|
-
* Step 1: the live catalog items whose platform components were never written
|
|
85
|
-
* (`platform_synced_version` null; `syncFromVersion` sets it). An item whose components were
|
|
86
|
-
* removed since is not synced again.
|
|
87
|
-
*/
|
|
88
|
-
private syncItems;
|
|
89
|
-
/** The highest version of the item installed in an org (and still stored), else `latest`. */
|
|
90
|
-
private platformVersion;
|
|
91
|
-
/** Step 2: org skill copies with plugin provenance, not linked yet. */
|
|
92
|
-
private linkSkills;
|
|
93
|
-
/** Links `links` of one org under its row lock (each only while it is still as read). */
|
|
94
|
-
private linkSkillsIn;
|
|
95
|
-
/**
|
|
96
|
-
* Step 3 (one-shot): org skills of the org's own whose name a platform skill on in their org has,
|
|
97
|
-
* renamed only in the first run (`rename`: no run has finished yet); later ones are only logged.
|
|
98
|
-
*/
|
|
99
|
-
private renameClashes;
|
|
100
|
-
/**
|
|
101
|
-
* Renames the clashing skills of one org under its row lock (each only while it still has the
|
|
102
|
-
* name and no provenance), switches the clashing platform skills off in the org (unless the org
|
|
103
|
-
* has a switch for them already), and writes one inbox notice and one audit event per skill.
|
|
104
|
-
*/
|
|
105
|
-
private renameIn;
|
|
106
|
-
/** Step 4: org agent templates not linked yet, by plugin and name. */
|
|
107
|
-
private linkTemplates;
|
|
108
|
-
/** Links `links` of one org under its row lock (each only while it is still as read). */
|
|
109
|
-
private linkTemplatesIn;
|
|
110
|
-
/**
|
|
111
|
-
* Step 5: connectors not linked yet whose install ledger row names the connector template they
|
|
112
|
-
* were made from; one statement (a connector only gains a link, nothing else changes).
|
|
113
|
-
*/
|
|
114
|
-
private linkConnectors;
|
|
115
|
-
}
|