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

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 (113) hide show
  1. package/bootstrap.json +1 -1
  2. package/dist/admin/admin.module.js +3 -0
  3. package/dist/admin/health.service.d.ts +2 -2
  4. package/dist/admin/health.service.js +6 -2
  5. package/dist/catalog/marketplaces.service.d.ts +1 -1
  6. package/dist/config/schema.d.ts +7 -0
  7. package/dist/config/schema.js +60 -2
  8. package/dist/conversations/access.d.ts +15 -7
  9. package/dist/conversations/access.js +59 -10
  10. package/dist/conversations/conversation-agent.d.ts +18 -0
  11. package/dist/conversations/conversation-agent.js +23 -0
  12. package/dist/conversations/conversation-ref.d.ts +3 -2
  13. package/dist/conversations/conversation-ref.js +6 -1
  14. package/dist/conversations/conversations.controller.d.ts +28 -5
  15. package/dist/conversations/conversations.controller.js +99 -10
  16. package/dist/conversations/conversations.module.js +10 -0
  17. package/dist/conversations/conversations.schemas.d.ts +6 -0
  18. package/dist/conversations/conversations.schemas.js +15 -0
  19. package/dist/conversations/conversations.service.d.ts +125 -21
  20. package/dist/conversations/conversations.service.js +260 -90
  21. package/dist/conversations/event-log.d.ts +9 -1
  22. package/dist/conversations/event-log.js +2 -0
  23. package/dist/conversations/events.d.ts +57 -0
  24. package/dist/conversations/events.js +73 -1
  25. package/dist/conversations/external/external-calls.d.ts +75 -0
  26. package/dist/conversations/external/external-calls.js +91 -0
  27. package/dist/conversations/external/external-calls.processor.d.ts +45 -0
  28. package/dist/conversations/external/external-calls.processor.js +144 -0
  29. package/dist/conversations/external/external-conversations.service.d.ts +266 -0
  30. package/dist/conversations/external/external-conversations.service.js +1138 -0
  31. package/dist/conversations/external/external.schemas.d.ts +63 -0
  32. package/dist/conversations/external/external.schemas.js +52 -0
  33. package/dist/conversations/external/token.d.ts +6 -0
  34. package/dist/conversations/external/token.js +6 -0
  35. package/dist/conversations/permission-profile-store.d.ts +4 -1
  36. package/dist/conversations/permission-profiles.controller.d.ts +33 -9
  37. package/dist/conversations/permission-profiles.controller.js +86 -6
  38. package/dist/conversations/prompt-suggestions.js +2 -1
  39. package/dist/conversations/queue.js +2 -1
  40. package/dist/conversations/titles.js +4 -3
  41. package/dist/ctx/create-ctx.d.ts +7 -0
  42. package/dist/ctx/create-ctx.js +45 -2
  43. package/dist/db/extension-db.d.ts +8 -3
  44. package/dist/db/extension-db.js +107 -7
  45. package/dist/db/extension-role-provision.d.ts +9 -0
  46. package/dist/db/extension-role-provision.js +89 -0
  47. package/dist/db/extension-schema-transfer.d.ts +2 -1
  48. package/dist/db/extension-schema-transfer.js +103 -19
  49. package/dist/db/kernel-schema.d.ts +31 -4
  50. package/dist/db/migrator.d.ts +2 -0
  51. package/dist/db/migrator.js +4 -3
  52. package/dist/device-access/host-services.js +3 -2
  53. package/dist/device-access/person-handles.d.ts +16 -7
  54. package/dist/device-access/person-handles.js +14 -9
  55. package/dist/devices/conversation-devices.d.ts +5 -0
  56. package/dist/devices/conversation-devices.js +16 -0
  57. package/dist/erasure/org-catalog.js +2 -2
  58. package/dist/errors.d.ts +34 -0
  59. package/dist/errors.js +34 -0
  60. package/dist/evals/snapshot.js +3 -1
  61. package/dist/evals/trajectory.service.d.ts +2 -2
  62. package/dist/evals/trajectory.service.js +11 -7
  63. package/dist/extensions/admin-ops.js +17 -1
  64. package/dist/extensions/extensions.module.js +3 -0
  65. package/dist/extensions/host.d.ts +9 -1
  66. package/dist/extensions/host.js +14 -2
  67. package/dist/extensions/migrate-lock.js +1 -0
  68. package/dist/extensions/permission-view.d.ts +3 -1
  69. package/dist/extensions/permission-view.js +4 -1
  70. package/dist/extensions/point-defaults.d.ts +13 -21
  71. package/dist/extensions/point-defaults.js +32 -72
  72. package/dist/extensions/point-serving.d.ts +56 -0
  73. package/dist/extensions/point-serving.js +120 -0
  74. package/dist/inbox/inbox-items.service.d.ts +11 -0
  75. package/dist/inbox/inbox-items.service.js +39 -0
  76. package/dist/index.d.ts +3 -1
  77. package/dist/index.js +3 -1
  78. package/dist/infra/database/rls-role.d.ts +4 -11
  79. package/dist/infra/database/rls-role.js +71 -27
  80. package/dist/infra/outbox/registry.d.ts +70 -0
  81. package/dist/infra/outbox/registry.js +44 -0
  82. package/dist/infra/queue/queue-names.d.ts +1 -1
  83. package/dist/infra/queue/queue-names.js +1 -0
  84. package/dist/kernel.d.ts +2 -0
  85. package/dist/kernel.js +12 -2
  86. package/dist/kernel.module.js +4 -0
  87. package/dist/lifecycle/kernel-lifecycle.js +2 -3
  88. package/dist/platform/exclusions.js +10 -0
  89. package/dist/platform/ops/conversations.ops.d.ts +8 -1
  90. package/dist/platform/ops/conversations.ops.js +52 -14
  91. package/dist/plugin-reads/plugin-reads.service.js +4 -1
  92. package/dist/push/recipients.js +5 -2
  93. package/dist/retention/worker.js +2 -1
  94. package/dist/roles/worker-role.d.ts +3 -1
  95. package/dist/roles/worker-role.js +8 -2
  96. package/dist/roles/worker.module.js +3 -0
  97. package/dist/runtime/context/build.js +8 -0
  98. package/dist/runtime/context/compaction.js +7 -0
  99. package/dist/runtime/idle-arm.js +3 -1
  100. package/dist/runtime/idle-compaction.js +2 -1
  101. package/dist/runtime/run-finish.js +2 -1
  102. package/dist/runtime/run-jobs.js +2 -1
  103. package/dist/runtime/run-queue.js +4 -2
  104. package/dist/runtime/run-worker.js +5 -2
  105. package/dist/runtime/stream.js +10 -0
  106. package/dist/runtime/usage-report.js +2 -1
  107. package/dist/runtime/waits.js +2 -1
  108. package/dist/tools/approvals.service.js +6 -2
  109. package/dist/tools/builtins/skill-load.js +3 -2
  110. package/dist/tools/tool-watch.service.js +3 -1
  111. package/package.json +3 -3
  112. package/src/migrations/0226_enable_kernel_rls.sql +30 -0
  113. package/src/migrations/0227_external_conversations.sql +33 -0
@@ -113,6 +113,11 @@ export declare class ConversationDevices {
113
113
  * has no default device and none can be made (no default provider on in the org).
114
114
  */
115
115
  forNew(orgId: string, accountId: string, pick?: NewConversationDevice): Promise<string | null>;
116
+ /**
117
+ * The person's default device in the org when they already have one, else null; unlike
118
+ * {@link forNew}, never makes one (no access check: a caller binding it checks it as a choice).
119
+ */
120
+ existingDefault(orgId: string, accountId: string): Promise<string | null>;
116
121
  /**
117
122
  * The device a sandbox tool call of the conversation tree rooted at `rootConversationId`
118
123
  * enters, checked for its owner now. A conversation still unbound (created before
@@ -149,6 +149,22 @@ let ConversationDevices = class ConversationDevices {
149
149
  return null;
150
150
  return this.defaultFor(orgId, accountId, pick.im === true);
151
151
  }
152
+ /**
153
+ * The person's default device in the org when they already have one, else null; unlike
154
+ * {@link forNew}, never makes one (no access check: a caller binding it checks it as a choice).
155
+ */
156
+ async existingDefault(orgId, accountId) {
157
+ const row = await this.db
158
+ .selectFrom("devices")
159
+ .select("id")
160
+ .where("org_id", "=", orgId)
161
+ .where("owner_kind", "=", "personal")
162
+ .where("owner_account_id", "=", accountId)
163
+ .where("is_default", "=", true)
164
+ .where("deleted_at", "is", null)
165
+ .executeTakeFirst();
166
+ return row?.id ?? null;
167
+ }
152
168
  /**
153
169
  * The device a sandbox tool call of the conversation tree rooted at `rootConversationId`
154
170
  * enters, checked for its owner now. A conversation still unbound (created before
@@ -1,5 +1,5 @@
1
1
  import { sql } from "kysely";
2
- // PostgreSQL 17 after 0225. Re-review the ownership map before updating this fingerprint.
2
+ // PostgreSQL 17 after 0227. Re-review the ownership map before updating this fingerprint.
3
3
  // It includes relation/column identities and ordered PK, UNIQUE and inbound/outbound FK
4
4
  // columns and actions, including FKs from outside the kernel schema.
5
5
  export async function orgCatalogDrift(db) {
@@ -30,5 +30,5 @@ WITH catalog AS (
30
30
  )
31
31
  SELECT md5(string_agg(entry, chr(10) ORDER BY entry COLLATE "C")) AS fingerprint FROM catalog
32
32
  `.execute(db);
33
- return rows[0]?.fingerprint === "3693e0b7004dae3c5721abfadc80e1e8" ? undefined : "schema-drift";
33
+ return rows[0]?.fingerprint === "15f8fa57ad75a52e2d08e08ad7742eb9" ? undefined : "schema-drift";
34
34
  }
package/dist/errors.d.ts CHANGED
@@ -402,6 +402,12 @@ export declare const ERROR_CODES: {
402
402
  readonly "conversation.queue_item_not_found": 404;
403
403
  /** A sub-agent's conversation takes no messages from people (sub-agents spec §6.1). */
404
404
  readonly "conversation.read_only": 409;
405
+ /**
406
+ * The conversation is with a local agent (an external conversation, local agents spec Part 2): it
407
+ * does not run here, so Capybara's run controls (queue, compaction, model switch, extension UI
408
+ * actions) do not apply to it.
409
+ */
410
+ readonly "conversation.external_read_only": 409;
405
411
  /**
406
412
  * A referenced project file is not there to reference (composer menus §5): the conversation has
407
413
  * no device project, the path leaves it, or the device reports no file there;
@@ -422,6 +428,34 @@ export declare const ERROR_CODES: {
422
428
  * "not_offered" }]`.
423
429
  */
424
430
  readonly "conversation.connector_unavailable": 422;
431
+ /**
432
+ * The conversation target cannot be used now (local agents spec Part 2): its extension does not
433
+ * serve `conversation-target@1` in the org, it does not list the target (or the chosen device),
434
+ * or it did not answer.
435
+ */
436
+ readonly "conversation.target_unavailable": 409;
437
+ /**
438
+ * A first message mixes the fields of the two kinds: `permission` (or a message model, effort,
439
+ * skill, tokens or files) with a `target`, or a target's `model` / `effort` / `mode` with an
440
+ * `agentId`.
441
+ */
442
+ readonly "conversation.target_fields": 400;
443
+ /**
444
+ * No device for an external conversation: the chosen one is not among the target's devices, or
445
+ * without a choice neither the default device nor any ready device the target lists fits.
446
+ */
447
+ readonly "conversation.target_device": 409;
448
+ /** The local agent never started this external conversation (its `start` was dropped). */
449
+ readonly "conversation.external_ended": 409;
450
+ /**
451
+ * A message to an external conversation carries more than its text (tokens, files, a model or
452
+ * effort switch, a skill, a retry); `interrupt` is for external conversations only.
453
+ */
454
+ readonly "conversation.external_fields": 400;
455
+ /** The external conversation has no request of that id (`external_request`). */
456
+ readonly "conversation.request_not_found": 404;
457
+ /** The request was already answered; the first answer stands. */
458
+ readonly "conversation.request_answered": 409;
425
459
  readonly "run.not_active": 409;
426
460
  /** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
427
461
  readonly "run.not_found": 404;
package/dist/errors.js CHANGED
@@ -402,6 +402,12 @@ export const ERROR_CODES = {
402
402
  "conversation.queue_item_not_found": 404,
403
403
  /** A sub-agent's conversation takes no messages from people (sub-agents spec §6.1). */
404
404
  "conversation.read_only": 409,
405
+ /**
406
+ * The conversation is with a local agent (an external conversation, local agents spec Part 2): it
407
+ * does not run here, so Capybara's run controls (queue, compaction, model switch, extension UI
408
+ * actions) do not apply to it.
409
+ */
410
+ "conversation.external_read_only": 409,
405
411
  /**
406
412
  * A referenced project file is not there to reference (composer menus §5): the conversation has
407
413
  * no device project, the path leaves it, or the device reports no file there;
@@ -422,6 +428,34 @@ export const ERROR_CODES = {
422
428
  * "not_offered" }]`.
423
429
  */
424
430
  "conversation.connector_unavailable": 422,
431
+ /**
432
+ * The conversation target cannot be used now (local agents spec Part 2): its extension does not
433
+ * serve `conversation-target@1` in the org, it does not list the target (or the chosen device),
434
+ * or it did not answer.
435
+ */
436
+ "conversation.target_unavailable": 409,
437
+ /**
438
+ * A first message mixes the fields of the two kinds: `permission` (or a message model, effort,
439
+ * skill, tokens or files) with a `target`, or a target's `model` / `effort` / `mode` with an
440
+ * `agentId`.
441
+ */
442
+ "conversation.target_fields": 400,
443
+ /**
444
+ * No device for an external conversation: the chosen one is not among the target's devices, or
445
+ * without a choice neither the default device nor any ready device the target lists fits.
446
+ */
447
+ "conversation.target_device": 409,
448
+ /** The local agent never started this external conversation (its `start` was dropped). */
449
+ "conversation.external_ended": 409,
450
+ /**
451
+ * A message to an external conversation carries more than its text (tokens, files, a model or
452
+ * effort switch, a skill, a retry); `interrupt` is for external conversations only.
453
+ */
454
+ "conversation.external_fields": 400,
455
+ /** The external conversation has no request of that id (`external_request`). */
456
+ "conversation.request_not_found": 404,
457
+ /** The request was already answered; the first answer stands. */
458
+ "conversation.request_answered": 409,
425
459
  "run.not_active": 409,
426
460
  /** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
427
461
  "run.not_found": 404,
@@ -1,4 +1,5 @@
1
1
  import { normalizeStoredDefinition } from "../agents/definition.js";
2
+ import { agentIdOf } from "../conversations/conversation-agent.js";
2
3
  import { ApiError } from "../errors.js";
3
4
  import { childRunDefinition } from "../runtime/subagents/definition.js";
4
5
  import { storedToolSpec } from "../tools/specs.js";
@@ -40,7 +41,8 @@ async function conversationRun(db, orgId, conversationId, runId) {
40
41
  if (!conv || !run) {
41
42
  throw new ApiError("conversation.not_found", "Conversation or run not found");
42
43
  }
43
- return { conv, agentVersion: run.agent_version };
44
+ // the run makes it an agent conversation (an external one has no runs)
45
+ return { conv: { ...conv, agent_id: agentIdOf(conv) }, agentVersion: run.agent_version };
44
46
  }
45
47
  /**
46
48
  * The snapshot of `events`: the agent versions they reference (each `run_started` and the run's
@@ -1,5 +1,5 @@
1
+ import { type AgentConversationKind } from "../conversations/conversation-agent.js";
1
2
  import { EventLog } from "../conversations/event-log.js";
2
- import type { ConversationKind } from "../db/kernel-schema.js";
3
3
  import type { PersonRef } from "../identity/account-avatar.js";
4
4
  import { KernelDb } from "../infra/database/kernel-db.js";
5
5
  import { type TrajectoryRun } from "./trajectory.js";
@@ -23,7 +23,7 @@ export interface TrajectoryDetail {
23
23
  agentId: string;
24
24
  accountId: string;
25
25
  title: string | null;
26
- kind: ConversationKind;
26
+ kind: AgentConversationKind;
27
27
  /**
28
28
  * A sub-agent's conversation (phase C, spec §15.4): the parent conversation and the `agent`
29
29
  * call that first dispatched it, for the link back. Visible exactly when the child is (the
@@ -11,6 +11,7 @@ var TrajectoryService_1;
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
13
  import { isAgentVisibleTo } from "../agents/agent-lookup.js";
14
+ import { agentIdOf, agentKindOf, } from "../conversations/conversation-agent.js";
14
15
  import { EventLog } from "../conversations/event-log.js";
15
16
  import { peopleOfEvents } from "../conversations/event-people.js";
16
17
  import { ApiError } from "../errors.js";
@@ -147,7 +148,7 @@ let TrajectoryService = TrajectoryService_1 = class TrajectoryService {
147
148
  const run = byConv.get(r.id);
148
149
  return {
149
150
  conversationId: r.id,
150
- agentId: r.agent_id,
151
+ agentId: agentIdOf(r),
151
152
  agentName: r.agent_name ?? "",
152
153
  accountId: r.account_id,
153
154
  title: r.title,
@@ -184,16 +185,19 @@ let TrajectoryService = TrajectoryService_1 = class TrajectoryService {
184
185
  const authAgentId = conv?.kind === "subagent"
185
186
  ? await this.rootAgentId(orgId, conv.parent_conversation_id)
186
187
  : conv?.agent_id;
187
- if (!conv || authAgentId === null || authAgentId === undefined)
188
+ // an external conversation has no agent and no runs: it has no trajectory
189
+ if (!conv || conv.kind === "external" || authAgentId === null || authAgentId === undefined) {
188
190
  throw notFound();
191
+ }
192
+ const agentId = agentIdOf(conv);
189
193
  if (!(await this.canView(orgId, accountId, authAgentId)))
190
194
  throw notFound();
191
195
  // an org agent child also needs that agent to be visible to a non-admin viewer, as on the
192
196
  // conversation read path (batch 9 ruling; final review m3)
193
- if (conv.kind === "subagent" && conv.agent_id !== authAgentId) {
197
+ if (conv.kind === "subagent" && agentId !== authAgentId) {
194
198
  const role = await this.role(orgId, accountId);
195
199
  if ((role === null || !roleAtLeast(role, "admin")) &&
196
- !(await isAgentVisibleTo(this.db.db, conv.agent_id, accountId))) {
200
+ !(await isAgentVisibleTo(this.db.db, agentId, accountId))) {
197
201
  throw notFound();
198
202
  }
199
203
  }
@@ -241,15 +245,15 @@ let TrajectoryService = TrajectoryService_1 = class TrajectoryService {
241
245
  orgId,
242
246
  action: "trajectory.viewed",
243
247
  target: conversationId,
244
- detail: { agentId: conv.agent_id },
248
+ detail: { agentId },
245
249
  });
246
250
  return {
247
251
  conversation: {
248
252
  id: conv.id,
249
- agentId: conv.agent_id,
253
+ agentId,
250
254
  accountId: conv.account_id,
251
255
  title: conv.title,
252
- kind: conv.kind,
256
+ kind: agentKindOf(conv.kind),
253
257
  ...(parent !== undefined && { parent }),
254
258
  },
255
259
  runs: buildTrajectory(events),
@@ -15,6 +15,7 @@ import { itemRemovedError } from "../catalog/ownership.js";
15
15
  import { oweDeployedExtensionSync } from "../catalog/scope-jobs.js";
16
16
  import { pluginSchemaName } from "../ctx/create-ctx.js";
17
17
  import { ConfiguredExtensionDbIdentity } from "../db/extension-db.js";
18
+ import { EMPTY_EXTENSION_SCHEMA_COMMENT } from "../db/extension-role-provision.js";
18
19
  import { oweHostServicesStop } from "../device-access/host-service-stop.js";
19
20
  import { revokeSiteGrantsOfExtensionEverywhere } from "../device-access/site-grants.js";
20
21
  import { ApiError } from "../errors.js";
@@ -22,6 +23,7 @@ import { audit } from "../identity/audit.js";
22
23
  import { SuperAdminLock } from "../identity/super-admin.js";
23
24
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
24
25
  import { afterCommit } from "../infra/database/after-commit.js";
26
+ import { EXTENSION_EFFECT_HANDOFF } from "../infra/database/extension-handoff.js";
25
27
  import { KernelDb } from "../infra/database/kernel-db.js";
26
28
  import { asPlatform } from "../infra/database/org-scope.js";
27
29
  import { TransactionHost } from "../infra/database/transaction-host.js";
@@ -579,7 +581,21 @@ function fallbackView(name, known, err) {
579
581
  /** 插件名已留下的数据:权限快照、部署配置、任一组织的配置,或插件 schema(`plugin_<name>`)。 */
580
582
  async function hasRetainedData(db, name) {
581
583
  return asPlatform("whether any org kept config for a plugin", async () => {
582
- const schema = await sql `SELECT 1 AS x FROM pg_namespace WHERE nspname = ${pluginSchemaName(name)}`.execute(db);
584
+ const schema = await sql `SELECT 1 AS x FROM pg_catalog.pg_namespace n
585
+ WHERE n.nspname = ${pluginSchemaName(name)} AND (
586
+ pg_catalog.obj_description(n.oid, 'pg_namespace') IS DISTINCT FROM ${EMPTY_EXTENSION_SCHEMA_COMMENT}
587
+ OR EXISTS (
588
+ SELECT FROM pg_catalog.pg_depend d
589
+ WHERE d.refclassid = 'pg_catalog.pg_namespace'::regclass AND d.refobjid = n.oid
590
+ AND d.deptype = 'n'
591
+ AND NOT EXISTS (
592
+ SELECT FROM pg_catalog.pg_class c
593
+ WHERE d.classid = 'pg_catalog.pg_class'::regclass AND c.oid = d.objid
594
+ AND c.relname = ${EXTENSION_EFFECT_HANDOFF} AND c.relkind = 'r'
595
+ AND c.relowner <> n.nspowner
596
+ )
597
+ )
598
+ )`.execute(db);
583
599
  if (schema.rows.length > 0)
584
600
  return true;
585
601
  // org-filter: whether any org kept config for the plugin name (a deployment-wide existence check)
@@ -32,6 +32,7 @@ import { OrgOverrides } from "./org-overrides.js";
32
32
  import { PluginGuides } from "./plugin-guides.js";
33
33
  import { PluginIcons } from "./plugin-icons.js";
34
34
  import { ExtensionPointDefaults } from "./point-defaults.js";
35
+ import { ExtensionPointServingModule } from "./point-serving.js";
35
36
  import { ExtensionRegistryModule } from "./registry.js";
36
37
  import { SingleProviderGuard } from "./single-provider.js";
37
38
  import { ReplicaStatusStore } from "./sources.js";
@@ -50,6 +51,8 @@ ExtensionsModule = __decorate([
50
51
  Module({
51
52
  imports: [
52
53
  ExtensionRegistryModule,
54
+ // one provider's candidacy for a point, shared with the conversation access check
55
+ ExtensionPointServingModule,
53
56
  TriggerEventsModule,
54
57
  InboxItemsModule,
55
58
  SuperAdminLockModule,
@@ -3,6 +3,9 @@ import type { Redis } from "ioredis";
3
3
  import type { core } from "zod";
4
4
  import type { KernelAppOptions } from "../app.js";
5
5
  import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
6
+ import type { KernelConfig } from "../config/schema.js";
7
+ import type { ExternalConversationsBackend } from "../conversations/external/external-conversations.service.js";
8
+ import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.js";
6
9
  import type { BusSubscriber } from "../ctx/bus.js";
7
10
  import { type DeviceAccessBackend, type InboxBackend, type PluginReadsBackend, type Route, type TriggersBackend } from "../ctx/create-ctx.js";
8
11
  import { ExtensionEffects } from "../ctx/durable-effects.service.js";
@@ -149,8 +152,8 @@ export declare class ExtensionHost {
149
152
  */
150
153
  static migrateOnly(specifiers: string[], opts: {
151
154
  dbUrl: string;
152
- handoffRuntimeLogin?: string;
153
155
  extensionIdentity?: ExtensionDbIdentity;
156
+ extensionProvisioning?: KernelConfig["db"];
154
157
  resolveFrom?: string;
155
158
  connectTimeoutMs?: number;
156
159
  autoApprove?: boolean;
@@ -302,6 +305,8 @@ export declare class ExtensionHost {
302
305
  * `TriggerEventsService` (`ctx.triggers`, {@link TRIGGER_EVENTS_BACKEND}) and
303
306
  * `InboxItemsService` (`ctx.inbox`, {@link INBOX_ITEMS_BACKEND}) and `PluginReadsService`
304
307
  * (`ctx.agents`, `ctx.conversations`, `ctx.people`, {@link PLUGIN_READS_BACKEND}) and
308
+ * `ExternalConversationsService` (`ctx.conversations`' external methods,
309
+ * {@link EXTERNAL_CONVERSATIONS_BACKEND}) and
305
310
  * `ServiceEvents` (`ctx.devices.serviceEvent`, {@link SERVICE_EVENTS_BACKEND}) likewise.
306
311
  */
307
312
  modules?: {
@@ -323,6 +328,9 @@ export declare class ExtensionHost {
323
328
  get(token: typeof PLUGIN_READS_BACKEND, opts: {
324
329
  strict: false;
325
330
  }): PluginReadsBackend;
331
+ get(token: typeof EXTERNAL_CONVERSATIONS_BACKEND, opts: {
332
+ strict: false;
333
+ }): ExternalConversationsBackend;
326
334
  },
327
335
  /** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
328
336
  netSeams?: ExtensionNetSeams, dbIdentity?: ExtensionDbIdentity);
@@ -16,6 +16,7 @@ import { Inject, Injectable, Optional } from "@nestjs/common";
16
16
  import { ModuleRef } from "@nestjs/core";
17
17
  import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
18
18
  import { changedPaths, configFields, getPath, secretValues, unreachableSecrets, } from "../config/fields.js";
19
+ import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.js";
19
20
  import { pluginSchemaName, queryEnabledPlugins, } from "../ctx/create-ctx.js";
20
21
  import { ExtensionEffects } from "../ctx/durable-effects.service.js";
21
22
  import { EXTENSION_NET_SEAMS } from "../ctx/net.js";
@@ -194,6 +195,7 @@ async function migratePlugin(connection, manifest, migrationsDir, connectTimeout
194
195
  connectTimeoutMs,
195
196
  signal,
196
197
  extensionLogin: connection.separate ? connection.login : undefined,
198
+ extensionDedicated: connection.dedicated,
197
199
  });
198
200
  return { schema, applied };
199
201
  }
@@ -264,8 +266,8 @@ let ExtensionHost = class ExtensionHost {
264
266
  for (const manifest of ordered)
265
267
  assertSecretsReachable(manifest);
266
268
  const identity = opts.extensionIdentity ?? extensionDbIdentity({ url: opts.dbUrl });
267
- if (opts.extensionIdentity) {
268
- await transferKnownExtensionSchemas(opts.dbUrl, identity, dirs.keys(), opts.connectTimeoutMs, opts.handoffRuntimeLogin);
269
+ if (opts.extensionProvisioning?.extensionProvisioningUrl) {
270
+ await transferKnownExtensionSchemas(opts.extensionProvisioning.extensionProvisioningUrl, identity, dirs.keys(), opts.connectTimeoutMs, opts.extensionProvisioning);
269
271
  }
270
272
  let toMigrate = ordered;
271
273
  if (!opts.autoApprove && ordered.length > 0) {
@@ -453,6 +455,8 @@ let ExtensionHost = class ExtensionHost {
453
455
  * `TriggerEventsService` (`ctx.triggers`, {@link TRIGGER_EVENTS_BACKEND}) and
454
456
  * `InboxItemsService` (`ctx.inbox`, {@link INBOX_ITEMS_BACKEND}) and `PluginReadsService`
455
457
  * (`ctx.agents`, `ctx.conversations`, `ctx.people`, {@link PLUGIN_READS_BACKEND}) and
458
+ * `ExternalConversationsService` (`ctx.conversations`' external methods,
459
+ * {@link EXTERNAL_CONVERSATIONS_BACKEND}) and
456
460
  * `ServiceEvents` (`ctx.devices.serviceEvent`, {@link SERVICE_EVENTS_BACKEND}) likewise.
457
461
  */
458
462
  modules,
@@ -541,6 +545,14 @@ let ExtensionHost = class ExtensionHost {
541
545
  return undefined;
542
546
  }
543
547
  },
548
+ externalConversations: () => {
549
+ try {
550
+ return modules?.get(EXTERNAL_CONVERSATIONS_BACKEND, { strict: false });
551
+ }
552
+ catch {
553
+ return undefined;
554
+ }
555
+ },
544
556
  locks,
545
557
  runWorkers: c.roles.includes("worker"),
546
558
  log,
@@ -47,6 +47,7 @@ export async function ensureMigrated(d, name, sha256, dir) {
47
47
  connectTimeoutMs: d.connectTimeoutMs,
48
48
  signal: signals.length > 0 ? AbortSignal.any(signals) : undefined,
49
49
  extensionLogin: d.extensionDb?.separate ? d.extensionDb.login : undefined,
50
+ extensionDedicated: d.extensionDb?.dedicated,
50
51
  ...(d.timeoutMs !== undefined && {
51
52
  statementTimeoutMs: d.timeoutMs,
52
53
  lockTimeoutMs: Math.min(d.timeoutMs, MIGRATION_LOCK_TIMEOUT_MS),
@@ -49,7 +49,9 @@ export interface PermissionItem {
49
49
  * their accounts and identities), `identity-source@1` decides who can sign in as which account;
50
50
  * `context@1` adds text to the model's context in conversations of orgs that enable it (memory
51
51
  * plugin spec §6.1); `push-provider@1` receives the title and in-app path of every push
52
- * notification and the device tokens it delivers to (mobile app spec §9). A plugin providing any
52
+ * notification and the device tokens it delivers to (mobile app spec §9);
53
+ * `conversation-target@1` receives the messages people send to their local agents (local agents
54
+ * spec, part 2). A plugin providing any
53
55
  * of them has its "provides" group marked sensitive and `sensitive` true in the admin plugin
54
56
  * list, for the super admin to approve. Display only: the keys of the permission snapshot do not
55
57
  * change.
@@ -25,7 +25,9 @@ export function reviewHash(set, warnings = []) {
25
25
  * their accounts and identities), `identity-source@1` decides who can sign in as which account;
26
26
  * `context@1` adds text to the model's context in conversations of orgs that enable it (memory
27
27
  * plugin spec §6.1); `push-provider@1` receives the title and in-app path of every push
28
- * notification and the device tokens it delivers to (mobile app spec §9). A plugin providing any
28
+ * notification and the device tokens it delivers to (mobile app spec §9);
29
+ * `conversation-target@1` receives the messages people send to their local agents (local agents
30
+ * spec, part 2). A plugin providing any
29
31
  * of them has its "provides" group marked sensitive and `sensitive` true in the admin plugin
30
32
  * list, for the super admin to approve. Display only: the keys of the permission snapshot do not
31
33
  * change.
@@ -38,6 +40,7 @@ export const SENSITIVE_EXTENSION_POINTS = [
38
40
  "object-store@1",
39
41
  "context@1",
40
42
  "push-provider@1",
43
+ "conversation-target@1",
41
44
  ];
42
45
  /** The one item of the "client" group (client extensions spec §5.4). */
43
46
  const CLIENT_ITEM = "client code";
@@ -1,8 +1,8 @@
1
1
  import { KernelDb } from "../infra/database/kernel-db.js";
2
2
  import { TransactionHost } from "../infra/database/transaction-host.js";
3
3
  import type { KernelLogger } from "../log.js";
4
- import { EffectiveConfigs } from "./effective-config.js";
5
4
  import { OrgExtensionConfigs } from "./org-config.js";
5
+ import { ExtensionPointServing, type PointProvider } from "./point-serving.js";
6
6
  import { ExtensionRegistry } from "./registry.js";
7
7
  /**
8
8
  * The outcome of {@link ExtensionPointDefaults.resolve}: the provider with its effective deployment
@@ -17,15 +17,7 @@ export type PointResolution<T> = {
17
17
  ok: false;
18
18
  reason: "none" | "ambiguous";
19
19
  };
20
- /**
21
- * One provider of a multi-provider extension point for an org ({@link ExtensionPointDefaults.providersFor}),
22
- * with its effective deployment config for the org, to pass back to it.
23
- */
24
- export interface PointProvider<T> {
25
- extension: string;
26
- impl: T;
27
- config: unknown;
28
- }
20
+ export type { PointProvider } from "./point-serving.js";
29
21
  /** One `org-default` extension point of an org (the admin view). */
30
22
  export interface OrgPointDefaultView {
31
23
  point: string;
@@ -50,9 +42,12 @@ export declare class ExtensionPointDefaults {
50
42
  readonly txHost: TransactionHost;
51
43
  private readonly registry;
52
44
  private readonly orgConfigs;
53
- private readonly effective;
45
+ /** One provider's candidacy (shared with the access checks, below the extensions module). */
46
+ private readonly serving;
54
47
  private readonly log;
55
- constructor(kdb: KernelDb, txHost: TransactionHost, registry: Pick<ExtensionRegistry, "list">, orgConfigs: Pick<OrgExtensionConfigs, "get">, effective: Pick<EffectiveConfigs, "get">, log: KernelLogger);
48
+ constructor(kdb: KernelDb, txHost: TransactionHost, registry: Pick<ExtensionRegistry, "list">, orgConfigs: Pick<OrgExtensionConfigs, "get">,
49
+ /** One provider's candidacy (shared with the access checks, below the extensions module). */
50
+ serving: Pick<ExtensionPointServing, "evaluate" | "serves" | "providerOf">, log: KernelLogger);
56
51
  /**
57
52
  * The provider of `point` (the name without the major, e.g. `web-search`) for `orgId`, with the
58
53
  * effective deployment config for the org to pass back to it. Throws when the point has no
@@ -94,19 +89,16 @@ export declare class ExtensionPointDefaults {
94
89
  */
95
90
  private candidates;
96
91
  /**
97
- * Whether the one provider `extension` of `point` evaluates as a candidate in `orgId`. The
98
- * provider must be loaded on this replica and provide `point`; the org must have it enabled; its
99
- * effective config must be valid; and its `configured()` must not return false.
100
- * These are exactly the criteria of {@link providersFor} / {@link resolve}, with only that one
101
- * provider evaluated. A provider whose status cannot be read counts as not serving (logged).
92
+ * Whether the one provider `extension` of `point` evaluates as a candidate in `orgId`: the
93
+ * criteria of {@link providersFor} / {@link resolve}, with only that provider evaluated
94
+ * ({@link ExtensionPointServing.serves}).
102
95
  */
103
96
  serves(orgId: string, point: string, extension: string): Promise<boolean>;
104
97
  /**
105
- * One enabled provider's candidacy: enabled, a valid effective config and `configured(config)`
106
- * not false. Undefined when it is off; a provider whose status could not be read is also added
107
- * to `failed`.
98
+ * The one provider `extension` of `point` when it {@link serves} `orgId` now (same criteria),
99
+ * with its implementation and effective config for the org; null otherwise.
108
100
  */
109
- private evaluate;
101
+ providerOf<T>(orgId: string, point: string, extension: string): Promise<PointProvider<T> | null>;
110
102
  private choose;
111
103
  /** The org's stored defaults, point → extension. */
112
104
  private storedDefaults;
@@ -15,9 +15,9 @@ import { KernelDb } from "../infra/database/kernel-db.js";
15
15
  import { TransactionHost } from "../infra/database/transaction-host.js";
16
16
  import { Transactional } from "../infra/database/transactional.decorator.js";
17
17
  import { KERNEL_LOGGER } from "../infra/tokens.js";
18
- import { EffectiveConfigs } from "./effective-config.js";
19
18
  import { enabledExtensionsQuery, isExtensionEnabled } from "./enabled.js";
20
19
  import { OrgExtensionConfigs } from "./org-config.js";
20
+ import { ExtensionPointServing } from "./point-serving.js";
21
21
  import { ExtensionRegistry } from "./registry.js";
22
22
  /** The extension points whose provider each org chooses (`selection: "org-default"`). */
23
23
  function selectionPoints() {
@@ -40,14 +40,16 @@ let ExtensionPointDefaults = class ExtensionPointDefaults {
40
40
  txHost;
41
41
  registry;
42
42
  orgConfigs;
43
- effective;
43
+ serving;
44
44
  log;
45
- constructor(kdb, txHost, registry, orgConfigs, effective, log) {
45
+ constructor(kdb, txHost, registry, orgConfigs,
46
+ /** One provider's candidacy (shared with the access checks, below the extensions module). */
47
+ serving, log) {
46
48
  this.kdb = kdb;
47
49
  this.txHost = txHost;
48
50
  this.registry = registry;
49
51
  this.orgConfigs = orgConfigs;
50
- this.effective = effective;
52
+ this.serving = serving;
51
53
  this.log = log;
52
54
  }
53
55
  /**
@@ -167,7 +169,23 @@ let ExtensionPointDefaults = class ExtensionPointDefaults {
167
169
  const out = [];
168
170
  const failed = new Set();
169
171
  for (const [extension, impl] of providers) {
170
- const c = await this.evaluate(orgId, point, extension, impl, failed);
172
+ let cfg;
173
+ try {
174
+ cfg = await this.orgConfigs.get(orgId, extension);
175
+ }
176
+ catch (err) {
177
+ this.log.warn("extension point provider excluded, cannot read whether it is enabled", {
178
+ orgId,
179
+ point,
180
+ extension,
181
+ err,
182
+ });
183
+ failed.add(extension);
184
+ continue;
185
+ }
186
+ if (!cfg?.enabled)
187
+ continue;
188
+ const c = await this.serving.evaluate(orgId, point, extension, impl, failed, this.log);
171
189
  if (c)
172
190
  out.push(c);
173
191
  }
@@ -175,77 +193,19 @@ let ExtensionPointDefaults = class ExtensionPointDefaults {
175
193
  return { candidates: out, failed };
176
194
  }
177
195
  /**
178
- * Whether the one provider `extension` of `point` evaluates as a candidate in `orgId`. The
179
- * provider must be loaded on this replica and provide `point`; the org must have it enabled; its
180
- * effective config must be valid; and its `configured()` must not return false.
181
- * These are exactly the criteria of {@link providersFor} / {@link resolve}, with only that one
182
- * provider evaluated. A provider whose status cannot be read counts as not serving (logged).
196
+ * Whether the one provider `extension` of `point` evaluates as a candidate in `orgId`: the
197
+ * criteria of {@link providersFor} / {@link resolve}, with only that provider evaluated
198
+ * ({@link ExtensionPointServing.serves}).
183
199
  */
184
200
  async serves(orgId, point, extension) {
185
- const entry = this.registry.list(point).find((e) => e.plugin === extension);
186
- if (!entry || !(await isExtensionEnabled(this.kdb.db, orgId, extension)))
187
- return false;
188
- return (await this.evaluate(orgId, point, extension, entry.impl, new Set())) !== undefined;
201
+ return this.serving.serves(orgId, point, extension, this.log);
189
202
  }
190
203
  /**
191
- * One enabled provider's candidacy: enabled, a valid effective config and `configured(config)`
192
- * not false. Undefined when it is off; a provider whose status could not be read is also added
193
- * to `failed`.
204
+ * The one provider `extension` of `point` when it {@link serves} `orgId` now (same criteria),
205
+ * with its implementation and effective config for the org; null otherwise.
194
206
  */
195
- async evaluate(orgId, point, extension, impl, failed) {
196
- let cfg;
197
- try {
198
- cfg = await this.orgConfigs.get(orgId, extension);
199
- }
200
- catch (err) {
201
- this.log.warn("extension point provider excluded, cannot read whether it is enabled", {
202
- orgId,
203
- point,
204
- extension,
205
- err,
206
- });
207
- failed.add(extension);
208
- return undefined;
209
- }
210
- if (!cfg?.enabled)
211
- return undefined;
212
- // spec A §6: an org whose effective config is not valid gets no call from this extension
213
- let effective;
214
- try {
215
- effective = await this.effective.get(orgId, extension);
216
- }
217
- catch (err) {
218
- this.log.warn("extension point provider excluded, cannot read its effective config", {
219
- orgId,
220
- point,
221
- extension,
222
- err,
223
- });
224
- failed.add(extension);
225
- return undefined;
226
- }
227
- if (!effective.ok)
228
- return undefined;
229
- const configured = impl.configured;
230
- if (typeof configured === "function") {
231
- let ok;
232
- try {
233
- ok = configured.call(impl, effective.config) !== false;
234
- }
235
- catch (err) {
236
- this.log.warn("extension point provider excluded, configured() threw", {
237
- orgId,
238
- point,
239
- extension,
240
- err,
241
- });
242
- failed.add(extension);
243
- return undefined;
244
- }
245
- if (!ok)
246
- return undefined;
247
- }
248
- return { extension, impl, config: effective.config };
207
+ providerOf(orgId, point, extension) {
208
+ return this.serving.providerOf(orgId, point, extension, this.log);
249
209
  }
250
210
  async choose(orgId, point, candidates) {
251
211
  if (candidates.length < 2)
@@ -271,7 +231,7 @@ ExtensionPointDefaults = __decorate([
271
231
  __param(1, Inject(TransactionHost)),
272
232
  __param(2, Inject(ExtensionRegistry)),
273
233
  __param(3, Inject(OrgExtensionConfigs)),
274
- __param(4, Inject(EffectiveConfigs)),
234
+ __param(4, Inject(ExtensionPointServing)),
275
235
  __param(5, Inject(KERNEL_LOGGER))
276
236
  ], ExtensionPointDefaults);
277
237
  export { ExtensionPointDefaults };