@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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
+
/**
|
|
4
|
+
* Plugins that subscribe to `usage.report` according to deployment state: an approved permission
|
|
5
|
+
* snapshot that declares the `usage.report` hook, for a plugin the deployment still knows: an enabled
|
|
6
|
+
* install, or a config-declared plugin with a replica status row that is not `unloaded`. With `orgId`, only plugins
|
|
7
|
+
* the organization enabled (org config rows and required bootstrap plugins).
|
|
8
|
+
*/
|
|
9
|
+
export declare function queryUsageSubscribers(db: KernelSchemaDb, orgId?: string): Promise<Set<string>>;
|
|
10
|
+
/** How long one replica trusts its answer to "does any plugin subscribe" (spec §8.1). */
|
|
11
|
+
export declare const USAGE_SUBSCRIBERS_TTL_MS = 30000;
|
|
12
|
+
/**
|
|
13
|
+
* Test seam (`KernelOverride`): the clock {@link UsageSubscribers} ages its cached answer with
|
|
14
|
+
* (default `Date.now`); the kernel never provides it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const USAGE_SUBSCRIBERS_CLOCK: unique symbol;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the deployment has at least one `usage.report` subscriber ({@link queryUsageSubscribers}
|
|
19
|
+
* without an org), which decides whether a usage write owes a delivery (transactional outbox spec
|
|
20
|
+
* §8.1): a usage event written while no plugin subscribes is never reported, later subscribers
|
|
21
|
+
* included. The answer comes from PG, not from this replica's loaded handlers, so a replica that
|
|
22
|
+
* has no handler still owes the delivery another replica makes.
|
|
23
|
+
*
|
|
24
|
+
* Per-process memoisation of that PG read: kept {@link USAGE_SUBSCRIBERS_TTL_MS} and cleared on
|
|
25
|
+
* `PLUGINS_CHANGED` (`ExtensionLifecycle` calls {@link invalidate}), so an enabled subscriber is
|
|
26
|
+
* seen at once, or within 30 s when the bus message is lost. It holds no state another request or
|
|
27
|
+
* replica relies on.
|
|
28
|
+
*/
|
|
29
|
+
export declare class UsageSubscribers {
|
|
30
|
+
private readonly kdb;
|
|
31
|
+
private readonly now;
|
|
32
|
+
private cached;
|
|
33
|
+
/** Bumped by {@link invalidate}: a read that started before it does not refill the cache. */
|
|
34
|
+
private generation;
|
|
35
|
+
constructor(kdb: KernelDb, now?: () => number);
|
|
36
|
+
/** Whether any plugin subscribes (cached; the read joins the caller's transaction, if any). */
|
|
37
|
+
any(): Promise<boolean>;
|
|
38
|
+
/** Forgets the cached answer (a plugin was installed, enabled, upgraded or removed). */
|
|
39
|
+
invalidate(): void;
|
|
40
|
+
}
|
|
41
|
+
/** {@link UsageSubscribers}: below the extension host, so the model broker and the runtime use it. */
|
|
42
|
+
export declare class UsageSubscribersModule {
|
|
43
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { Inject, Injectable, Module, Optional } from "@nestjs/common";
|
|
11
|
+
import { sql } from "kysely";
|
|
12
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
|
+
import { enabledExtensionsQuery } from "./enabled.js";
|
|
14
|
+
/**
|
|
15
|
+
* Plugins that subscribe to `usage.report` according to deployment state: an approved permission
|
|
16
|
+
* snapshot that declares the `usage.report` hook, for a plugin the deployment still knows: an enabled
|
|
17
|
+
* install, or a config-declared plugin with a replica status row that is not `unloaded`. With `orgId`, only plugins
|
|
18
|
+
* the organization enabled (org config rows and required bootstrap plugins).
|
|
19
|
+
*/
|
|
20
|
+
export async function queryUsageSubscribers(db, orgId) {
|
|
21
|
+
let q = db
|
|
22
|
+
.selectFrom("extension_permission_snapshots as s")
|
|
23
|
+
.select("s.plugin")
|
|
24
|
+
.where(sql `s.permissions -> 'permissions' -> 'hooks' ? 'usage.report'`)
|
|
25
|
+
.where((eb) => eb.or([
|
|
26
|
+
eb.exists(eb
|
|
27
|
+
.selectFrom("extension_installs as i")
|
|
28
|
+
.select(sql `1`.as("one"))
|
|
29
|
+
.whereRef("i.name", "=", "s.plugin")
|
|
30
|
+
.where("i.desired_state", "=", "enabled")),
|
|
31
|
+
// config-declared plugins still declared (and not unloaded) on some replica; installs are
|
|
32
|
+
// covered by desired_state above (their replica rows linger as `unloaded` when disabled)
|
|
33
|
+
eb.exists(eb
|
|
34
|
+
.selectFrom("extension_replica_status as r")
|
|
35
|
+
.select(sql `1`.as("one"))
|
|
36
|
+
.whereRef("r.plugin", "=", "s.plugin")
|
|
37
|
+
.where("r.source", "=", "config")
|
|
38
|
+
.where("r.state", "<>", "unloaded")),
|
|
39
|
+
]));
|
|
40
|
+
if (orgId !== undefined) {
|
|
41
|
+
q = q.where("s.plugin", "in", enabledExtensionsQuery(db, orgId));
|
|
42
|
+
}
|
|
43
|
+
return new Set((await q.execute()).map((r) => r.plugin));
|
|
44
|
+
}
|
|
45
|
+
/** How long one replica trusts its answer to "does any plugin subscribe" (spec §8.1). */
|
|
46
|
+
export const USAGE_SUBSCRIBERS_TTL_MS = 30_000;
|
|
47
|
+
/**
|
|
48
|
+
* Test seam (`KernelOverride`): the clock {@link UsageSubscribers} ages its cached answer with
|
|
49
|
+
* (default `Date.now`); the kernel never provides it.
|
|
50
|
+
*/
|
|
51
|
+
export const USAGE_SUBSCRIBERS_CLOCK = Symbol("USAGE_SUBSCRIBERS_CLOCK");
|
|
52
|
+
/**
|
|
53
|
+
* Whether the deployment has at least one `usage.report` subscriber ({@link queryUsageSubscribers}
|
|
54
|
+
* without an org), which decides whether a usage write owes a delivery (transactional outbox spec
|
|
55
|
+
* §8.1): a usage event written while no plugin subscribes is never reported, later subscribers
|
|
56
|
+
* included. The answer comes from PG, not from this replica's loaded handlers, so a replica that
|
|
57
|
+
* has no handler still owes the delivery another replica makes.
|
|
58
|
+
*
|
|
59
|
+
* Per-process memoisation of that PG read: kept {@link USAGE_SUBSCRIBERS_TTL_MS} and cleared on
|
|
60
|
+
* `PLUGINS_CHANGED` (`ExtensionLifecycle` calls {@link invalidate}), so an enabled subscriber is
|
|
61
|
+
* seen at once, or within 30 s when the bus message is lost. It holds no state another request or
|
|
62
|
+
* replica relies on.
|
|
63
|
+
*/
|
|
64
|
+
let UsageSubscribers = class UsageSubscribers {
|
|
65
|
+
kdb;
|
|
66
|
+
now;
|
|
67
|
+
cached;
|
|
68
|
+
/** Bumped by {@link invalidate}: a read that started before it does not refill the cache. */
|
|
69
|
+
generation = 0;
|
|
70
|
+
constructor(kdb, now = Date.now) {
|
|
71
|
+
this.kdb = kdb;
|
|
72
|
+
this.now = now;
|
|
73
|
+
}
|
|
74
|
+
/** Whether any plugin subscribes (cached; the read joins the caller's transaction, if any). */
|
|
75
|
+
async any() {
|
|
76
|
+
const at = this.now();
|
|
77
|
+
const c = this.cached;
|
|
78
|
+
if (c !== undefined && at - c.at < USAGE_SUBSCRIBERS_TTL_MS)
|
|
79
|
+
return c.any;
|
|
80
|
+
const generation = this.generation;
|
|
81
|
+
const any = (await queryUsageSubscribers(this.kdb.db)).size > 0;
|
|
82
|
+
if (generation === this.generation)
|
|
83
|
+
this.cached = { any, at };
|
|
84
|
+
return any;
|
|
85
|
+
}
|
|
86
|
+
/** Forgets the cached answer (a plugin was installed, enabled, upgraded or removed). */
|
|
87
|
+
invalidate() {
|
|
88
|
+
this.generation++;
|
|
89
|
+
this.cached = undefined;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
UsageSubscribers = __decorate([
|
|
93
|
+
Injectable(),
|
|
94
|
+
__param(0, Inject(KernelDb)),
|
|
95
|
+
__param(1, Optional()),
|
|
96
|
+
__param(1, Inject(USAGE_SUBSCRIBERS_CLOCK))
|
|
97
|
+
], UsageSubscribers);
|
|
98
|
+
export { UsageSubscribers };
|
|
99
|
+
/** {@link UsageSubscribers}: below the extension host, so the model broker and the runtime use it. */
|
|
100
|
+
let UsageSubscribersModule = class UsageSubscribersModule {
|
|
101
|
+
};
|
|
102
|
+
UsageSubscribersModule = __decorate([
|
|
103
|
+
Module({
|
|
104
|
+
providers: [UsageSubscribers],
|
|
105
|
+
exports: [UsageSubscribers],
|
|
106
|
+
})
|
|
107
|
+
], UsageSubscribersModule);
|
|
108
|
+
export { UsageSubscribersModule };
|
package/dist/http/api.module.js
CHANGED
|
@@ -12,6 +12,7 @@ import { AdminAgentsController } from "../admin/admin-agents.controller.js";
|
|
|
12
12
|
import { AdminConnectorsController } from "../admin/admin-connectors.controller.js";
|
|
13
13
|
import { AdminAuditController } from "../admin/audit.controller.js";
|
|
14
14
|
import { AdminExtensionsController } from "../admin/extensions.controller.js";
|
|
15
|
+
import { OutboxDeadController } from "../admin/outbox-dead.controller.js";
|
|
15
16
|
import { AdminOverviewController } from "../admin/overview.controller.js";
|
|
16
17
|
import { SetupController } from "../admin/setup.controller.js";
|
|
17
18
|
import { AgentsController } from "../agents/agents.controller.js";
|
|
@@ -107,6 +108,7 @@ const CONTROLLERS = [
|
|
|
107
108
|
AdminConnectorsController,
|
|
108
109
|
AdminAuditController,
|
|
109
110
|
AdminOverviewController,
|
|
111
|
+
OutboxDeadController,
|
|
110
112
|
AdminExtensionsController,
|
|
111
113
|
AdminCatalogController,
|
|
112
114
|
AdminComponentsController,
|
|
@@ -6,34 +6,20 @@ import { ApprovalsService, type ApprovalView } from "../tools/approvals.service.
|
|
|
6
6
|
import type { OrgNoticeDetails } from "./org-notices.js";
|
|
7
7
|
/** The most open org notices one inbox read returns. */
|
|
8
8
|
export declare const ORG_NOTICES_LIST_MAX = 100;
|
|
9
|
-
/** The skill the platform components migration renamed (`skill_renamed`). */
|
|
10
|
-
export interface SkillRenamedDetail {
|
|
11
|
-
skillId: string;
|
|
12
|
-
from: string;
|
|
13
|
-
to: string;
|
|
14
|
-
platformSkillId: string;
|
|
15
|
-
plugin: string | null;
|
|
16
|
-
}
|
|
17
9
|
/**
|
|
18
|
-
* A notice for the org's admins (`org_notices`), shown until one of them dismisses it
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* name a platform skill on in the org has; agents keep it, by id;
|
|
22
|
-
* - `item_shared`, `shared_item_updated`, `upload_confirmed`, `upload_rejected` (`detail`): the
|
|
23
|
-
* shapes of {@link OrgNoticeDetails} (plugin scope phase 3, P3-22).
|
|
10
|
+
* A notice for the org's admins (`org_notices`), shown until one of them dismisses it:
|
|
11
|
+
* `item_shared`, `shared_item_updated`, `upload_confirmed`, `upload_rejected`, `detail` in the
|
|
12
|
+
* shape of {@link OrgNoticeDetails} (plugin scope phase 3, P3-22).
|
|
24
13
|
*/
|
|
25
14
|
export type OrgNoticeView = {
|
|
26
15
|
id: string;
|
|
27
16
|
createdAt: string;
|
|
28
|
-
} &
|
|
29
|
-
kind: "skill_renamed";
|
|
30
|
-
skillRenamed: SkillRenamedDetail;
|
|
31
|
-
} | {
|
|
17
|
+
} & {
|
|
32
18
|
[K in keyof OrgNoticeDetails]: {
|
|
33
19
|
kind: K;
|
|
34
20
|
detail: OrgNoticeDetails[K];
|
|
35
21
|
};
|
|
36
|
-
}[keyof OrgNoticeDetails]
|
|
22
|
+
}[keyof OrgNoticeDetails];
|
|
37
23
|
/** 收件箱一次最多返回的事项数。 */
|
|
38
24
|
export declare const INBOX_MAX_ITEMS = 100;
|
|
39
25
|
/**
|
|
@@ -51,7 +37,7 @@ export declare const INBOX_MAX_ITEMS = 100;
|
|
|
51
37
|
* - `schedule_attention`: the current user's own scheduled task that needs them (spec §8): paused
|
|
52
38
|
* for any reason but their own pause, its latest run failed, or its latest run was refused tools
|
|
53
39
|
* or connections; derived live, gone once the task is resumed or runs clean;
|
|
54
|
-
* - the org notices (`
|
|
40
|
+
* - the org notices (`item_shared`, `shared_item_updated`, `upload_confirmed`,
|
|
55
41
|
* `upload_rejected`; `type` = the notice's kind): for org admins, until one dismisses it
|
|
56
42
|
* (`POST inbox/notices/:id/dismiss`).
|
|
57
43
|
*/
|
|
@@ -112,9 +112,6 @@ let InboxService = class InboxService {
|
|
|
112
112
|
.execute();
|
|
113
113
|
return rows.map((r) => {
|
|
114
114
|
const base = { id: r.id, createdAt: r.created_at.toISOString() };
|
|
115
|
-
if (r.kind === "skill_renamed") {
|
|
116
|
-
return { ...base, kind: r.kind, skillRenamed: r.detail };
|
|
117
|
-
}
|
|
118
115
|
return { ...base, kind: r.kind, detail: r.detail };
|
|
119
116
|
});
|
|
120
117
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type OwnedRef, type Owner } from "../catalog/ownership.js";
|
|
2
2
|
import type { KernelSchemaDb, OrgNoticeKind } from "../db/kernel-schema.js";
|
|
3
3
|
export type { OrgNoticeKind };
|
|
4
|
-
/** The `detail` of each notice kind
|
|
4
|
+
/** The `detail` of each notice kind. */
|
|
5
5
|
export interface OrgNoticeDetails {
|
|
6
6
|
/** An org was added to the item's list, or its scope widened (`all_orgs`). */
|
|
7
7
|
/** `displayName`: a plugin's display name, which the inbox names it by (null otherwise). */
|
|
@@ -8,11 +8,6 @@ import type { PlatformNoticeDetails } from "./platform-notices.js";
|
|
|
8
8
|
export declare const PLATFORM_INBOX_MAX_ITEMS = 100;
|
|
9
9
|
/** The most open scope sync failures one read takes. */
|
|
10
10
|
export declare const SCOPE_SYNC_FAILURES_LIST_MAX = 200;
|
|
11
|
-
/**
|
|
12
|
-
* A platform components migration run unfinished this long after its start is stuck (its worker
|
|
13
|
-
* stopped mid-run; a run takes seconds, and the next one starts at the next worker start or day).
|
|
14
|
-
*/
|
|
15
|
-
export declare const MIGRATION_RUN_STUCK_MS: number;
|
|
16
11
|
/**
|
|
17
12
|
* An open failure of the plugin scope sync: its last attempt to install the plugin in the org, to
|
|
18
13
|
* uninstall it, or to install the dependencies a platform update added (`dependencies`) failed,
|
|
@@ -34,18 +29,6 @@ export interface ScopeSyncFailureView {
|
|
|
34
29
|
message: string;
|
|
35
30
|
failedAt: string;
|
|
36
31
|
}
|
|
37
|
-
/**
|
|
38
|
-
* The latest platform components migration run (`platform_migration_runs`) when it needs a look:
|
|
39
|
-
* finished with catalog items whose components could not be written (`itemsFailed`,
|
|
40
|
-
* `<name>@<version>`), or `stuck` (unfinished {@link MIGRATION_RUN_STUCK_MS} after its start).
|
|
41
|
-
*/
|
|
42
|
-
export interface MigrationRunView {
|
|
43
|
-
id: string;
|
|
44
|
-
startedAt: string;
|
|
45
|
-
finishedAt: string | null;
|
|
46
|
-
stuck: boolean;
|
|
47
|
-
itemsFailed: string[];
|
|
48
|
-
}
|
|
49
32
|
/**
|
|
50
33
|
* One item of the super admin's inbox (by `type`). Nothing is decided in the inbox: each item is
|
|
51
34
|
* acted on where it lives (the web links to it).
|
|
@@ -56,7 +39,6 @@ export interface MigrationRunView {
|
|
|
56
39
|
* - `org_upload_pending`: an org-owned plugin whose uploaded version (with an extension) waits for
|
|
57
40
|
* the super admin in 待确认 (ruling P3-22; confirmed or rejected there), `id` = the item's;
|
|
58
41
|
* - `scope_sync_failed`: an open scope sync failure, `id` = `<itemId>/<orgId>`;
|
|
59
|
-
* - `platform_migration`: the latest migration run, failed items or stuck, `id` = the run's;
|
|
60
42
|
* - `ownership_transferred`: a deleted org's shared item now belongs to the platform, until a
|
|
61
43
|
* super admin dismisses it (`POST admin/inbox/notices/:id/dismiss`).
|
|
62
44
|
*/
|
|
@@ -80,11 +62,6 @@ export type PlatformInboxItem = {
|
|
|
80
62
|
id: string;
|
|
81
63
|
createdAt: string;
|
|
82
64
|
failure: ScopeSyncFailureView;
|
|
83
|
-
} | {
|
|
84
|
-
type: "platform_migration";
|
|
85
|
-
id: string;
|
|
86
|
-
createdAt: string;
|
|
87
|
-
run: MigrationRunView;
|
|
88
65
|
} | {
|
|
89
66
|
type: "ownership_transferred";
|
|
90
67
|
id: string;
|
|
@@ -92,7 +69,7 @@ export type PlatformInboxItem = {
|
|
|
92
69
|
notice: PlatformNoticeView;
|
|
93
70
|
};
|
|
94
71
|
/** Every {@link PlatformInboxItem} type, in the order the admin overview lists them. */
|
|
95
|
-
export declare const PLATFORM_INBOX_TYPES: readonly ["catalog_request", "permission_confirmation", "org_upload_pending", "scope_sync_failed", "
|
|
72
|
+
export declare const PLATFORM_INBOX_TYPES: readonly ["catalog_request", "permission_confirmation", "org_upload_pending", "scope_sync_failed", "ownership_transferred"];
|
|
96
73
|
/** How many items of each type wait: every type, zeros included. */
|
|
97
74
|
export type PlatformInboxCounts = Record<PlatformInboxItem["type"], number>;
|
|
98
75
|
/** An open platform notice (`platform_notices`, kind `ownership_transferred`). */
|
|
@@ -116,8 +93,8 @@ export interface PlatformInboxView {
|
|
|
116
93
|
/**
|
|
117
94
|
* The super admin's inbox (plugin scope spec §5.1 rule 5, §13.5): what waits on the platform,
|
|
118
95
|
* gathered from the sources the admin pages read (the 待确认 tab's requests and permission
|
|
119
|
-
* confirmations), plus the scope sync's open failures and the platform
|
|
120
|
-
*
|
|
96
|
+
* confirmations), plus the scope sync's open failures and the platform notices. Stateless, read
|
|
97
|
+
* live from PG.
|
|
121
98
|
*/
|
|
122
99
|
export declare class PlatformInboxService {
|
|
123
100
|
private readonly requests;
|
|
@@ -148,10 +125,4 @@ export declare class PlatformInboxService {
|
|
|
148
125
|
private countScopeSyncFailures;
|
|
149
126
|
/** The open scope sync failures ({@link failureRows}), newest first. */
|
|
150
127
|
private scopeSyncFailures;
|
|
151
|
-
/**
|
|
152
|
-
* The latest migration run when it needs a look (see {@link MigrationRunView}); null when it
|
|
153
|
-
* finished without failed items, is still running, or there was none. An earlier run's failure
|
|
154
|
-
* is not shown: each run tries every unwritten item again.
|
|
155
|
-
*/
|
|
156
|
-
private migrationRun;
|
|
157
128
|
}
|
|
@@ -17,11 +17,6 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
17
17
|
export const PLATFORM_INBOX_MAX_ITEMS = 100;
|
|
18
18
|
/** The most open scope sync failures one read takes. */
|
|
19
19
|
export const SCOPE_SYNC_FAILURES_LIST_MAX = 200;
|
|
20
|
-
/**
|
|
21
|
-
* A platform components migration run unfinished this long after its start is stuck (its worker
|
|
22
|
-
* stopped mid-run; a run takes seconds, and the next one starts at the next worker start or day).
|
|
23
|
-
*/
|
|
24
|
-
export const MIGRATION_RUN_STUCK_MS = 60 * 60_000;
|
|
25
20
|
/** Plugin install statuses of a plugin that is on in the org. */
|
|
26
21
|
const LIVE_INSTALL = ["installing", "installed", "upgrading"];
|
|
27
22
|
/** Every {@link PlatformInboxItem} type, in the order the admin overview lists them. */
|
|
@@ -30,14 +25,13 @@ export const PLATFORM_INBOX_TYPES = [
|
|
|
30
25
|
"permission_confirmation",
|
|
31
26
|
"org_upload_pending",
|
|
32
27
|
"scope_sync_failed",
|
|
33
|
-
"platform_migration",
|
|
34
28
|
"ownership_transferred",
|
|
35
29
|
];
|
|
36
30
|
/**
|
|
37
31
|
* The super admin's inbox (plugin scope spec §5.1 rule 5, §13.5): what waits on the platform,
|
|
38
32
|
* gathered from the sources the admin pages read (the 待确认 tab's requests and permission
|
|
39
|
-
* confirmations), plus the scope sync's open failures and the platform
|
|
40
|
-
*
|
|
33
|
+
* confirmations), plus the scope sync's open failures and the platform notices. Stateless, read
|
|
34
|
+
* live from PG.
|
|
41
35
|
*/
|
|
42
36
|
let PlatformInboxService = class PlatformInboxService {
|
|
43
37
|
requests;
|
|
@@ -49,13 +43,12 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
49
43
|
this.kdb = kdb;
|
|
50
44
|
}
|
|
51
45
|
async list() {
|
|
52
|
-
const [requests, requestCount, pending, failures, failureCount,
|
|
46
|
+
const [requests, requestCount, pending, failures, failureCount, notices, noticeCount] = await Promise.all([
|
|
53
47
|
this.requests.listDeployment(),
|
|
54
48
|
this.requests.countPendingDeployment(),
|
|
55
49
|
this.catalog.list({ pending: true }),
|
|
56
50
|
this.scopeSyncFailures(),
|
|
57
51
|
this.countScopeSyncFailures(),
|
|
58
|
-
this.migrationRun(),
|
|
59
52
|
this.notices(),
|
|
60
53
|
this.countNotices(),
|
|
61
54
|
]);
|
|
@@ -84,16 +77,6 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
84
77
|
createdAt: n.createdAt,
|
|
85
78
|
notice: n,
|
|
86
79
|
})),
|
|
87
|
-
...(run === null
|
|
88
|
-
? []
|
|
89
|
-
: [
|
|
90
|
-
{
|
|
91
|
-
type: "platform_migration",
|
|
92
|
-
id: run.id,
|
|
93
|
-
createdAt: run.finishedAt ?? run.startedAt,
|
|
94
|
-
run,
|
|
95
|
-
},
|
|
96
|
-
]),
|
|
97
80
|
];
|
|
98
81
|
// newest first; equal times by id (a stable order)
|
|
99
82
|
all.sort((a, b) => a.createdAt !== b.createdAt
|
|
@@ -111,7 +94,6 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
111
94
|
permission_confirmation: pending.length - orgUploads,
|
|
112
95
|
org_upload_pending: orgUploads,
|
|
113
96
|
scope_sync_failed: failureCount,
|
|
114
|
-
platform_migration: run === null ? 0 : 1,
|
|
115
97
|
ownership_transferred: noticeCount,
|
|
116
98
|
};
|
|
117
99
|
const total = Object.values(byType).reduce((a, b) => a + b, 0);
|
|
@@ -123,14 +105,13 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
123
105
|
* requests and the failures; the permission confirmations are the catalog's pending list).
|
|
124
106
|
*/
|
|
125
107
|
async count() {
|
|
126
|
-
const [requests, pending, failures,
|
|
108
|
+
const [requests, pending, failures, notices] = await Promise.all([
|
|
127
109
|
this.requests.countPendingDeployment(),
|
|
128
110
|
this.catalog.list({ pending: true }),
|
|
129
111
|
this.countScopeSyncFailures(),
|
|
130
|
-
this.migrationRun(),
|
|
131
112
|
this.countNotices(),
|
|
132
113
|
]);
|
|
133
|
-
return requests + pending.length + failures +
|
|
114
|
+
return requests + pending.length + failures + notices;
|
|
134
115
|
}
|
|
135
116
|
async countNotices() {
|
|
136
117
|
const r = await this.kdb.db
|
|
@@ -240,36 +221,6 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
240
221
|
failedAt: r.failed_at.toISOString(),
|
|
241
222
|
}));
|
|
242
223
|
}
|
|
243
|
-
/**
|
|
244
|
-
* The latest migration run when it needs a look (see {@link MigrationRunView}); null when it
|
|
245
|
-
* finished without failed items, is still running, or there was none. An earlier run's failure
|
|
246
|
-
* is not shown: each run tries every unwritten item again.
|
|
247
|
-
*/
|
|
248
|
-
async migrationRun() {
|
|
249
|
-
const run = await this.kdb.db
|
|
250
|
-
.selectFrom("platform_migration_runs")
|
|
251
|
-
.select(["id", "started_at", "finished_at", "stats"])
|
|
252
|
-
.orderBy("started_at", "desc")
|
|
253
|
-
.orderBy("id", "desc")
|
|
254
|
-
.limit(1)
|
|
255
|
-
.executeTakeFirst();
|
|
256
|
-
if (run === undefined)
|
|
257
|
-
return null;
|
|
258
|
-
const failed = run.stats.itemsFailed;
|
|
259
|
-
const itemsFailed = Array.isArray(failed)
|
|
260
|
-
? failed.filter((x) => typeof x === "string")
|
|
261
|
-
: [];
|
|
262
|
-
const stuck = run.finished_at === null && run.started_at.getTime() < Date.now() - MIGRATION_RUN_STUCK_MS;
|
|
263
|
-
if (!stuck && (run.finished_at === null || itemsFailed.length === 0))
|
|
264
|
-
return null;
|
|
265
|
-
return {
|
|
266
|
-
id: run.id,
|
|
267
|
-
startedAt: run.started_at.toISOString(),
|
|
268
|
-
finishedAt: run.finished_at?.toISOString() ?? null,
|
|
269
|
-
stuck,
|
|
270
|
-
itemsFailed,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
224
|
};
|
|
274
225
|
PlatformInboxService = __decorate([
|
|
275
226
|
Injectable(),
|
package/dist/index.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export { ROUTE_SCHEMAS, type RouteSchemas } from "./platform/route-schemas.js";
|
|
|
70
70
|
export { UNKNOWN_RESULT_TEXT } from "./runtime/context/pairing.js";
|
|
71
71
|
export type { AgentLoop, LoopContext, LoopOutcome } from "./runtime/loop.js";
|
|
72
72
|
export { MAINTENANCE_QUEUE_NAME } from "./runtime/maintenance-queue.js";
|
|
73
|
+
export { type OrphanCandidate, queuedRunsWithoutJob } from "./runtime/run-orphan-check.job.js";
|
|
73
74
|
export { runJobId } from "./runtime/run-queue.js";
|
|
74
75
|
export { SANDBOX_DESTROY_JOB, SANDBOX_SUSPEND_JOB, } from "./sandbox/jobs.js";
|
|
75
76
|
export { SANDBOX_LOCK_TTL_MS, SandboxService, type SandboxUseInfo, } from "./sandbox/sandbox.service.js";
|
package/dist/index.js
CHANGED
|
@@ -68,6 +68,7 @@ export { PlatformOperations } from "./platform/registry.js";
|
|
|
68
68
|
export { ROUTE_SCHEMAS } from "./platform/route-schemas.js";
|
|
69
69
|
export { UNKNOWN_RESULT_TEXT } from "./runtime/context/pairing.js";
|
|
70
70
|
export { MAINTENANCE_QUEUE_NAME } from "./runtime/maintenance-queue.js";
|
|
71
|
+
export { queuedRunsWithoutJob } from "./runtime/run-orphan-check.job.js";
|
|
71
72
|
export { runJobId } from "./runtime/run-queue.js";
|
|
72
73
|
export { SANDBOX_DESTROY_JOB, SANDBOX_SUSPEND_JOB, } from "./sandbox/jobs.js";
|
|
73
74
|
export { SANDBOX_LOCK_TTL_MS, SandboxService, } from "./sandbox/sandbox.service.js";
|
|
@@ -21,6 +21,7 @@ import { KernelEventsModule } from "../events/kernel-events.js";
|
|
|
21
21
|
import { GracefulShutdownModule } from "../lifecycle/graceful-shutdown.module.js";
|
|
22
22
|
import { LockModule } from "../lock/lock.module.js";
|
|
23
23
|
import { LoggingModule } from "../logging/logging.module.js";
|
|
24
|
+
import { OutboxModule } from "../outbox/outbox.module.js";
|
|
24
25
|
import { QueueModule } from "../queue/queue.module.js";
|
|
25
26
|
import { KERNEL_BUS, KERNEL_LOGGER, REDIS, REDIS_SUBSCRIBER } from "../tokens.js";
|
|
26
27
|
/** How long the CLI's Redis connection may take before a command fails (a publish only warns). */
|
|
@@ -110,6 +111,10 @@ let KernelCliModule = KernelCliModule_1 = class KernelCliModule {
|
|
|
110
111
|
ConfigModule.forRoot(config, opts.env !== undefined ? { env: opts.env } : {}),
|
|
111
112
|
GracefulShutdownModule,
|
|
112
113
|
DatabaseModule.forRoot(),
|
|
114
|
+
// owed jobs a command's domain writes carry (an extension's embed call owes its usage
|
|
115
|
+
// report); delivered by the fast path when the command's context has the queue, else by a
|
|
116
|
+
// worker's relay
|
|
117
|
+
OutboxModule,
|
|
113
118
|
// QueueModule's root gives the queues a command's modules register (the catalog's scope
|
|
114
119
|
// sync and maintenance queues) the configured Redis; without it BullMQ would connect to
|
|
115
120
|
// its default 127.0.0.1:6379
|
|
@@ -23,8 +23,9 @@ export interface KernelEventMap {
|
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* A person decided a tool call approval (after the commit, exactly once: only the decision that
|
|
26
|
-
* changed it from pending). The
|
|
27
|
-
*
|
|
26
|
+
* changed it from pending). The decision's transaction resumed the run and, for a conversation
|
|
27
|
+
* with a channel target, owed the IM delivery that updates the card (with its `approval_decided`
|
|
28
|
+
* append); the event itself is only the decision's announcement.
|
|
28
29
|
*/
|
|
29
30
|
"approval.decided": {
|
|
30
31
|
id: string;
|
|
@@ -36,8 +37,7 @@ export interface KernelEventMap {
|
|
|
36
37
|
};
|
|
37
38
|
/**
|
|
38
39
|
* A person answered a tool call's input request, or skipped it with a message (after the commit,
|
|
39
|
-
* exactly once).
|
|
40
|
-
* consumers and the same re-derivation as `approval.decided`.
|
|
40
|
+
* exactly once). The same transaction contract as `approval.decided`.
|
|
41
41
|
*/
|
|
42
42
|
"question.answered": {
|
|
43
43
|
id: string;
|
|
@@ -47,38 +47,20 @@ export interface KernelEventMap {
|
|
|
47
47
|
/** `skipped`: the run's starter sent a message instead (reply-while-question spec §6.3). */
|
|
48
48
|
outcome: "answered" | "skipped";
|
|
49
49
|
};
|
|
50
|
-
/**
|
|
51
|
-
* EventAppended: a conversation's event log advanced to `toSeq` (after the commit, from
|
|
52
|
-
* `EventLog.notify`, right after the bus publish). The channel outbound delivery enqueues a job
|
|
53
|
-
* for a conversation with an IM target; a lost event is re-derived by the next append's (and the
|
|
54
|
-
* finished delivery job re-checks the log for content it has not delivered).
|
|
55
|
-
*/
|
|
56
|
-
"conversation.event-appended": {
|
|
57
|
-
conversationId: string;
|
|
58
|
-
toSeq: number;
|
|
59
|
-
};
|
|
60
50
|
/**
|
|
61
51
|
* A run started executing on this replica (its first start, a resume, or a takeover after a
|
|
62
52
|
* stall), after it took the conversation lock and an org quota slot. The channel outbound
|
|
63
|
-
* enqueues the conversation's IM delivery
|
|
53
|
+
* enqueues the conversation's IM delivery at once (a hint: the run's appends owe it, transactional
|
|
54
|
+
* outbox spec §8.1).
|
|
64
55
|
*/
|
|
65
56
|
"run.started": {
|
|
66
57
|
conversationId: string;
|
|
67
58
|
runId: string;
|
|
68
59
|
};
|
|
69
60
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*/
|
|
74
|
-
"run.wait-stopped": {
|
|
75
|
-
conversationId: string;
|
|
76
|
-
runId: string;
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* `ensureRun` marked an orphaned run failed (after the commit): the waits stop its active fork
|
|
80
|
-
* sub-agent at once (background sub-agents keep running, agent map spec §5.4). A lost event is
|
|
81
|
-
* repaired by the wait sweep (fork children of finished runs).
|
|
61
|
+
* The `run-orphan-check` failed an orphaned run (after the commit): the waits stop its active
|
|
62
|
+
* fork sub-agent at once (background sub-agents keep running, agent map spec §5.4). A lost event
|
|
63
|
+
* is repaired by the `stop-tree` job the run's terminal transaction owed.
|
|
82
64
|
*/
|
|
83
65
|
"run.orphaned": {
|
|
84
66
|
runId: string;
|
|
@@ -99,14 +81,6 @@ export interface KernelEventMap {
|
|
|
99
81
|
"background_task.finished": {
|
|
100
82
|
conversationId: string;
|
|
101
83
|
};
|
|
102
|
-
/**
|
|
103
|
-
* An extension's `ctx.models.embed` call wrote a `model_usage` row (after the commit, spec B
|
|
104
|
-
* §5.4). The usage reporter enqueues its `usage.report` delivery; a lost event is re-derived by
|
|
105
|
-
* the usage sweep (rows whose `reported_at` is still null).
|
|
106
|
-
*/
|
|
107
|
-
"model_usage.recorded": {
|
|
108
|
-
id: string;
|
|
109
|
-
};
|
|
110
84
|
}
|
|
111
85
|
type Handler<K extends keyof KernelEventMap> = (payload: KernelEventMap[K]) => Promise<void> | void;
|
|
112
86
|
/** Typed in-process event emitter; handlers run in order, a failing one is logged and skipped. */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from "@nestjs/common";
|
|
8
|
+
import { OutboxRelay } from "./outbox.relay.js";
|
|
9
|
+
/**
|
|
10
|
+
* The outbox relay (`@LockedInterval`), imported only by `WorkerModule`. Its dispatcher comes from
|
|
11
|
+
* the global `OutboxModule`, which every role has (the fast path runs everywhere).
|
|
12
|
+
*/
|
|
13
|
+
let OutboxRelayModule = class OutboxRelayModule {
|
|
14
|
+
};
|
|
15
|
+
OutboxRelayModule = __decorate([
|
|
16
|
+
Module({ providers: [OutboxRelay] })
|
|
17
|
+
], OutboxRelayModule);
|
|
18
|
+
export { OutboxRelayModule };
|