@capybara-hq/kernel 0.1.0-rc.133 → 0.1.0-rc.134

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.
Files changed (54) hide show
  1. package/dist/automations/events/trigger-events.service.d.ts +13 -1
  2. package/dist/automations/events/trigger-events.service.js +27 -14
  3. package/dist/catalog/marketplaces.service.d.ts +1 -1
  4. package/dist/config/schema.d.ts +1 -0
  5. package/dist/config/schema.js +7 -0
  6. package/dist/ctx/create-ctx.d.ts +4 -0
  7. package/dist/ctx/create-ctx.js +74 -27
  8. package/dist/ctx/durable-cancellation.d.ts +3 -0
  9. package/dist/ctx/durable-cancellation.js +8 -0
  10. package/dist/ctx/durable-effects.service.d.ts +81 -0
  11. package/dist/ctx/durable-effects.service.js +316 -0
  12. package/dist/ctx/durable-envelope.d.ts +24 -0
  13. package/dist/ctx/durable-envelope.js +80 -0
  14. package/dist/ctx/durable-failure.d.ts +7 -0
  15. package/dist/ctx/durable-failure.js +32 -0
  16. package/dist/ctx/durable-job.d.ts +9 -0
  17. package/dist/ctx/durable-job.js +2 -0
  18. package/dist/ctx/durable-keys.d.ts +27 -0
  19. package/dist/ctx/durable-keys.js +138 -0
  20. package/dist/ctx/durable-relay.d.ts +29 -0
  21. package/dist/ctx/durable-relay.js +250 -0
  22. package/dist/ctx/queue.d.ts +2 -0
  23. package/dist/ctx/queue.js +22 -15
  24. package/dist/db/extension-db.js +2 -0
  25. package/dist/db/extension-handoff-schema.d.ts +6 -0
  26. package/dist/db/extension-handoff-schema.js +72 -0
  27. package/dist/db/extension-schema-transfer.d.ts +1 -1
  28. package/dist/db/extension-schema-transfer.js +18 -6
  29. package/dist/db/kernel-schema.d.ts +16 -0
  30. package/dist/erasure/org-catalog.js +2 -2
  31. package/dist/erasure/org-rules.js +1 -0
  32. package/dist/extensions/extensions.module.js +10 -0
  33. package/dist/extensions/host.d.ts +5 -0
  34. package/dist/extensions/host.js +33 -20
  35. package/dist/extensions/instance.d.ts +2 -0
  36. package/dist/extensions/instance.js +6 -0
  37. package/dist/extensions/sources.d.ts +1 -0
  38. package/dist/extensions/sources.js +9 -0
  39. package/dist/inbox/inbox-items.service.d.ts +5 -0
  40. package/dist/inbox/inbox-items.service.js +57 -33
  41. package/dist/infra/database/extension-effect-key-lock.d.ts +10 -0
  42. package/dist/infra/database/extension-effect-key-lock.js +69 -0
  43. package/dist/infra/database/extension-handoff.d.ts +27 -0
  44. package/dist/infra/database/extension-handoff.js +113 -0
  45. package/dist/infra/outbox/outbox.dispatcher.d.ts +6 -1
  46. package/dist/infra/outbox/outbox.dispatcher.js +64 -4
  47. package/dist/infra/outbox/outbox.module.js +2 -0
  48. package/dist/infra/outbox/registry.d.ts +12 -0
  49. package/dist/infra/outbox/registry.js +12 -0
  50. package/dist/kernel.js +1 -0
  51. package/dist/orgs/orgs.service.js +16 -0
  52. package/dist/roles/worker.module.js +2 -0
  53. package/package.json +2 -2
  54. package/src/migrations/0225_extension_effect_receipts.sql +25 -0
@@ -5,6 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Global, Module } from "@nestjs/common";
8
+ import { ExtensionRegistryModule } from "../../extensions/registry.js";
8
9
  import { OutboxDispatcher } from "./outbox.dispatcher.js";
9
10
  import { OUTBOX_FAST_PATH, OutboxService } from "./outbox.service.js";
10
11
  /**
@@ -35,6 +36,7 @@ let OutboxModule = class OutboxModule {
35
36
  OutboxModule = __decorate([
36
37
  Global(),
37
38
  Module({
39
+ imports: [ExtensionRegistryModule],
38
40
  providers: [
39
41
  OutboxService,
40
42
  OutboxDispatcher,
@@ -19,6 +19,18 @@ export interface OutboxJobSpec {
19
19
  * name without one does not type-check as an `OutboxJobName` (`add` does not check it at runtime).
20
20
  */
21
21
  export declare const OUTBOX_JOBS: {
22
+ readonly "extension-queue-effect": {
23
+ readonly queue: "cap-kernel-maintenance";
24
+ readonly processedIn: "packages/kernel/src/infra/outbox/outbox.dispatcher.ts";
25
+ readonly idempotent: "Adds a plugin queue job with a deterministic destination ID. Plugin job handlers are idempotent.";
26
+ readonly opts: {};
27
+ };
28
+ readonly "extension-effect-redrive": {
29
+ readonly queue: "cap-kernel-maintenance";
30
+ readonly processedIn: "packages/kernel/src/ctx/durable-relay.ts";
31
+ readonly idempotent: "Verifies the original signed effect and checks its durable receipt before applying it.";
32
+ readonly opts: {};
33
+ };
22
34
  readonly "data-erasure": {
23
35
  readonly queue: "cap-kernel-maintenance";
24
36
  readonly idempotent: "Each generation claims the durable request under a row lock. Stale and completed deliveries do nothing.";
@@ -21,6 +21,18 @@ const SCOPE_JOB_OPTS = {
21
21
  * name without one does not type-check as an `OutboxJobName` (`add` does not check it at runtime).
22
22
  */
23
23
  export const OUTBOX_JOBS = {
24
+ "extension-queue-effect": {
25
+ queue: "cap-kernel-maintenance",
26
+ processedIn: "packages/kernel/src/infra/outbox/outbox.dispatcher.ts",
27
+ idempotent: "Adds a plugin queue job with a deterministic destination ID. Plugin job handlers are idempotent.",
28
+ opts: {},
29
+ },
30
+ "extension-effect-redrive": {
31
+ queue: "cap-kernel-maintenance",
32
+ processedIn: "packages/kernel/src/ctx/durable-relay.ts",
33
+ idempotent: "Verifies the original signed effect and checks its durable receipt before applying it.",
34
+ opts: {},
35
+ },
24
36
  "data-erasure": {
25
37
  queue: "cap-kernel-maintenance",
26
38
  idempotent: "Each generation claims the durable request under a row lock. Stale and completed deliveries do nothing.",
package/dist/kernel.js CHANGED
@@ -52,6 +52,7 @@ export async function migrateAll(config, opts = {}) {
52
52
  dbUrl: config.db.url,
53
53
  ...(config.db.extensionsUrl !== undefined && {
54
54
  extensionIdentity: extensionDbIdentity(config.db),
55
+ handoffRuntimeLogin: config.db.extensionEffectRelayLogin ?? "capybara_runtime",
55
56
  }),
56
57
  connectTimeoutMs,
57
58
  autoApprove: config.extensionPermissions.autoApprove,
@@ -13,6 +13,7 @@ import { sql } from "kysely";
13
13
  import { OwnedItems } from "../catalog/owned-items.js";
14
14
  import { cancelPendingRequests } from "../catalog/request-rules.js";
15
15
  import { PluginScopeSync } from "../catalog/scope-sync.js";
16
+ import { EXTENSION_QUEUE_EFFECT_JOB } from "../ctx/durable-job.js";
16
17
  import { ErasureRequests } from "../erasure/requests.js";
17
18
  import { ApiError } from "../errors.js";
18
19
  import { EvalBudget } from "../evals/budget.js";
@@ -270,6 +271,21 @@ let OrgsService = class OrgsService {
270
271
  .set({ deleted_at: sql `now()` })
271
272
  .where("id", "=", orgId)
272
273
  .execute();
274
+ await this.db
275
+ .insertInto("extension_effect_cancellations")
276
+ .columns(["id", "plugin", "reason"])
277
+ .expression((eb) => eb
278
+ .selectFrom("outbox")
279
+ .select([
280
+ "job_id as id",
281
+ sql `data->>'plugin'`.as("plugin"),
282
+ sql `'organization_deleted'`.as("reason"),
283
+ ])
284
+ .where("org_id", "=", orgId)
285
+ .where("job_name", "=", EXTENSION_QUEUE_EFFECT_JOB)
286
+ .where("dead_at", "is", null))
287
+ .onConflict((conflict) => conflict.doNothing())
288
+ .execute();
273
289
  // the org's owed jobs go with it; dead letters stay for the overview, and the deletion's own
274
290
  // cleanup work carries no org_id (transactional outbox spec §9). Usage reports stay owed: the
275
291
  // usage happened, and billing plugins are still told about a deleted org's usage
@@ -23,6 +23,7 @@ import { AttachmentCleanupJob } from "../conversations/attachments.service.js";
23
23
  import { EventLogModule } from "../conversations/event-log.js";
24
24
  import { PromptSuggestionsModule } from "../conversations/prompt-suggestions.js";
25
25
  import { TitlesModule } from "../conversations/titles.js";
26
+ import { ExtensionEffectRelay } from "../ctx/durable-relay.js";
26
27
  import { ConversationNoticeSweepJob, ConversationNoticesModule, } from "../device-access/conversation-notice-delivery.js";
27
28
  import { HostServiceStopSweepJob } from "../device-access/host-service-stop-sweep.js";
28
29
  import { DeviceServiceEventWorkersModule } from "../device-access/service-events.js";
@@ -134,6 +135,7 @@ let WorkerModule = WorkerModule_1 = class WorkerModule {
134
135
  ConversationNoticesModule,
135
136
  ],
136
137
  providers: [
138
+ ExtensionEffectRelay,
137
139
  ...(operationalMetricsEnabled() ? [OperationalMetricsSampler] : []),
138
140
  // the one repair of a run nobody runs (transactional outbox spec §8.3)
139
141
  RunOrphanCheck,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.133",
3
+ "version": "0.1.0-rc.134",
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": {
@@ -70,7 +70,7 @@
70
70
  "yaml": "^2.9.1",
71
71
  "yauzl": "3.4.0",
72
72
  "zod": "^4.6.7",
73
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.98"
73
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.99"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -0,0 +1,25 @@
1
+ CREATE TABLE IF NOT EXISTS extension_effect_receipts (
2
+ org_id text NOT NULL REFERENCES orgs (id) ON DELETE CASCADE,
3
+ plugin text NOT NULL,
4
+ kind text NOT NULL,
5
+ effect_key text NOT NULL,
6
+ payload_hash text NOT NULL,
7
+ result jsonb NOT NULL DEFAULT 'null'::jsonb,
8
+ PRIMARY KEY (org_id, plugin, kind, effect_key)
9
+ );
10
+
11
+ DROP POLICY IF EXISTS org_scope ON extension_effect_receipts;
12
+ CREATE POLICY org_scope ON extension_effect_receipts
13
+ USING (rls_admits(org_id)) WITH CHECK (rls_admits(org_id));
14
+
15
+ -- Cancellation survives a hard delete of the organization. The digest contains no effect data.
16
+ CREATE TABLE IF NOT EXISTS extension_effect_cancellations (
17
+ id text PRIMARY KEY,
18
+ plugin text NOT NULL,
19
+ reason text NOT NULL,
20
+ cancelled_at timestamptz NOT NULL DEFAULT now()
21
+ );
22
+
23
+ CREATE INDEX IF NOT EXISTS outbox_extension_effect_reference
24
+ ON outbox ((data->>'plugin'), (data->>'rowId'))
25
+ WHERE job_name = 'extension-effect-redrive';