@capybara-hq/kernel 0.1.0-rc.77 → 0.1.0-rc.79

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 (247) hide show
  1. package/bootstrap.json +6 -6
  2. package/dist/admin/outbox-dead.service.js +4 -1
  3. package/dist/agents/admin-agents.js +2 -0
  4. package/dist/agents/agent-lookup.js +4 -0
  5. package/dist/agents/agent-profile.service.js +3 -0
  6. package/dist/agents/agents.service.js +7 -0
  7. package/dist/agents/org-templates.js +1 -0
  8. package/dist/agents/pending-connector-requests.js +6 -0
  9. package/dist/agents/pending-connectors.service.js +2 -0
  10. package/dist/agents/readiness.service.d.ts +9 -3
  11. package/dist/agents/readiness.service.js +3 -3
  12. package/dist/agents/templates.js +1 -0
  13. package/dist/background/finish.js +3 -0
  14. package/dist/background/stop.js +2 -0
  15. package/dist/background/store.js +44 -0
  16. package/dist/background/tasks.service.js +3 -2
  17. package/dist/background/wake-rules.js +1 -0
  18. package/dist/catalog/admin-catalog.controller.d.ts +6 -0
  19. package/dist/catalog/admin-catalog.controller.js +13 -0
  20. package/dist/catalog/catalog-content.d.ts +9 -0
  21. package/dist/catalog/catalog-content.js +3 -1
  22. package/dist/catalog/catalog-items.js +4 -0
  23. package/dist/catalog/catalog-scope.service.js +4 -1
  24. package/dist/catalog/component-promotion.js +2 -0
  25. package/dist/catalog/component-scope.controller.d.ts +9 -15
  26. package/dist/catalog/component-scope.controller.js +14 -9
  27. package/dist/catalog/component-scope.service.js +5 -0
  28. package/dist/catalog/component-state.d.ts +4 -1
  29. package/dist/catalog/component-state.js +4 -2
  30. package/dist/catalog/marketplace-fetch.d.ts +1 -1
  31. package/dist/catalog/marketplace-fetch.js +1 -1
  32. package/dist/catalog/marketplaces.service.d.ts +6 -1
  33. package/dist/catalog/marketplaces.service.js +8 -3
  34. package/dist/catalog/org-catalog.controller.d.ts +9 -0
  35. package/dist/catalog/org-catalog.controller.js +18 -0
  36. package/dist/catalog/org-catalog.schemas.d.ts +2 -4
  37. package/dist/catalog/org-catalog.schemas.js +2 -3
  38. package/dist/catalog/org-catalog.service.d.ts +10 -1
  39. package/dist/catalog/org-catalog.service.js +34 -23
  40. package/dist/catalog/org-extension-switch.d.ts +3 -10
  41. package/dist/catalog/org-extension-switch.js +14 -60
  42. package/dist/catalog/org-extension.controller.d.ts +6 -7
  43. package/dist/catalog/org-extension.controller.js +4 -4
  44. package/dist/catalog/org-extension.schemas.d.ts +1 -2
  45. package/dist/catalog/org-extension.schemas.js +1 -3
  46. package/dist/catalog/owned-items.js +10 -1
  47. package/dist/catalog/ownership.js +2 -0
  48. package/dist/catalog/plugin-import.d.ts +3 -0
  49. package/dist/catalog/plugin-import.js +10 -1
  50. package/dist/catalog/plugin-install.d.ts +1 -4
  51. package/dist/catalog/plugin-install.js +11 -12
  52. package/dist/catalog/plugin-upgrade.js +4 -1
  53. package/dist/catalog/request-rules.js +6 -0
  54. package/dist/catalog/requests.service.js +4 -0
  55. package/dist/catalog/scope-orgs.js +1 -0
  56. package/dist/catalog/scope-sync.d.ts +8 -5
  57. package/dist/catalog/scope-sync.js +21 -23
  58. package/dist/catalog/template-description.d.ts +17 -0
  59. package/dist/catalog/template-description.js +18 -0
  60. package/dist/catalog/unshare.js +3 -0
  61. package/dist/channels/connections.service.js +1 -0
  62. package/dist/channels/inbound.js +1 -0
  63. package/dist/channels/jobs.js +1 -0
  64. package/dist/channels/outbound.js +6 -0
  65. package/dist/channels/supervisor.js +1 -0
  66. package/dist/channels/threads.js +1 -0
  67. package/dist/client/client-reports.service.js +1 -0
  68. package/dist/config/fields.js +20 -4
  69. package/dist/config/schema.d.ts +1 -1
  70. package/dist/config/schema.js +13 -13
  71. package/dist/conversations/access.js +1 -0
  72. package/dist/conversations/attachments.service.js +16 -4
  73. package/dist/conversations/conversations.service.js +17 -3
  74. package/dist/conversations/event-log.js +2 -0
  75. package/dist/conversations/events.d.ts +1 -0
  76. package/dist/conversations/events.js +3 -1
  77. package/dist/conversations/files.js +3 -2
  78. package/dist/conversations/permission-profiles.service.js +1 -0
  79. package/dist/conversations/prompt-suggestions.js +2 -0
  80. package/dist/conversations/queue.js +8 -0
  81. package/dist/conversations/queue.service.js +6 -2
  82. package/dist/conversations/source.js +2 -0
  83. package/dist/conversations/titles.js +10 -2
  84. package/dist/conversations/tree.js +6 -0
  85. package/dist/db/kernel-schema.d.ts +5 -1
  86. package/dist/devices/conversation-devices.js +3 -0
  87. package/dist/devices/device-projects.service.js +2 -0
  88. package/dist/devices/devices.service.js +5 -0
  89. package/dist/devices/legacy-cleanup.job.js +5 -2
  90. package/dist/dial-in/handlers.js +2 -0
  91. package/dist/dial-in/machines.js +11 -2
  92. package/dist/dial-in/targets.d.ts +0 -2
  93. package/dist/dial-in/targets.js +0 -10
  94. package/dist/errors.d.ts +0 -1
  95. package/dist/errors.js +0 -1
  96. package/dist/evals/budget.js +14 -1
  97. package/dist/evals/run-replay.js +4 -0
  98. package/dist/evals/runs.service.js +13 -7
  99. package/dist/evals/sets.service.js +23 -8
  100. package/dist/evals/trajectory.service.d.ts +1 -1
  101. package/dist/evals/trajectory.service.js +1 -0
  102. package/dist/evals/worker.js +5 -1
  103. package/dist/extensions/admin-ops.js +1 -0
  104. package/dist/extensions/admin-view.js +3 -1
  105. package/dist/extensions/bootstrap-packages.d.ts +12 -1
  106. package/dist/extensions/bootstrap-packages.js +49 -9
  107. package/dist/extensions/bootstrap.d.ts +17 -2
  108. package/dist/extensions/bootstrap.js +41 -9
  109. package/dist/extensions/config-json-schema.d.ts +2 -2
  110. package/dist/extensions/config-json-schema.js +1 -3
  111. package/dist/extensions/deployment-config.d.ts +5 -3
  112. package/dist/extensions/deployment-config.js +3 -3
  113. package/dist/extensions/effective-config.d.ts +8 -7
  114. package/dist/extensions/effective-config.js +8 -7
  115. package/dist/extensions/enabled.js +1 -0
  116. package/dist/extensions/host.d.ts +4 -3
  117. package/dist/extensions/host.js +11 -12
  118. package/dist/extensions/instance.d.ts +1 -1
  119. package/dist/extensions/instance.js +17 -2
  120. package/dist/extensions/org-config.d.ts +35 -97
  121. package/dist/extensions/org-config.js +48 -315
  122. package/dist/extensions/org-levels.d.ts +22 -9
  123. package/dist/extensions/org-levels.js +100 -20
  124. package/dist/extensions/org-overrides.d.ts +14 -15
  125. package/dist/extensions/org-overrides.js +20 -20
  126. package/dist/extensions/package.js +1 -1
  127. package/dist/extensions/permission-set.d.ts +1 -3
  128. package/dist/extensions/permission-set.js +3 -7
  129. package/dist/extensions/permission-view.d.ts +3 -1
  130. package/dist/extensions/permission-view.js +5 -4
  131. package/dist/extensions/plugin-icons.d.ts +80 -1
  132. package/dist/extensions/plugin-icons.js +211 -2
  133. package/dist/extensions/point-defaults.d.ts +17 -18
  134. package/dist/extensions/point-defaults.js +25 -28
  135. package/dist/git/gateway.js +1 -1
  136. package/dist/git/identity.d.ts +1 -1
  137. package/dist/git/identity.js +2 -2
  138. package/dist/identity/accounts.js +6 -0
  139. package/dist/identity/api-tokens.js +8 -0
  140. package/dist/infra/outbox/outbox.dispatcher.js +4 -1
  141. package/dist/infra/outbox/outbox.service.js +2 -0
  142. package/dist/net/public-address.d.ts +3 -3
  143. package/dist/net/public-address.js +3 -3
  144. package/dist/orgs/directory-sync.d.ts +9 -6
  145. package/dist/orgs/directory-sync.js +15 -12
  146. package/dist/orgs/invitations.service.js +2 -0
  147. package/dist/orgs/members.service.js +2 -0
  148. package/dist/orgs/offboarding.js +2 -0
  149. package/dist/packages/npm.d.ts +10 -2
  150. package/dist/packages/npm.js +38 -6
  151. package/dist/platform/exclusions.js +20 -0
  152. package/dist/platform/ops/admin-items.ops.js +1 -0
  153. package/dist/platform/ops/agents.ops.js +1 -0
  154. package/dist/platform/ops/connectors.ops.js +7 -1
  155. package/dist/platform/ops/extensions.ops.d.ts +6 -8
  156. package/dist/platform/ops/extensions.ops.js +18 -97
  157. package/dist/platform/ops/org-plugins.ops.d.ts +3 -6
  158. package/dist/platform/ops/org-plugins.ops.js +14 -65
  159. package/dist/platform/ops/outbox.ops.js +1 -0
  160. package/dist/platform/ops/person-inputs.d.ts +0 -4
  161. package/dist/platform/ops/person-inputs.js +0 -8
  162. package/dist/platform/ops/plugins.ops.d.ts +4 -1
  163. package/dist/platform/ops/plugins.ops.js +27 -34
  164. package/dist/platform/person-fields.d.ts +1 -1
  165. package/dist/platform/person-fields.js +1 -1
  166. package/dist/platform/sealed-reveals.js +2 -0
  167. package/dist/push/recipients.js +9 -2
  168. package/dist/runtime/permission-context.service.js +1 -0
  169. package/dist/runtime/plugin-context.service.js +1 -0
  170. package/dist/runtime/project/knowledge.service.js +1 -0
  171. package/dist/runtime/run-context.service.js +1 -0
  172. package/dist/runtime/run-deletion.js +4 -0
  173. package/dist/runtime/run-execution.js +2 -0
  174. package/dist/runtime/run-finish.js +3 -0
  175. package/dist/runtime/run-jobs.js +3 -0
  176. package/dist/runtime/run-orphan-check.job.js +7 -0
  177. package/dist/runtime/run-queue.js +21 -2
  178. package/dist/runtime/run-worker.js +5 -0
  179. package/dist/runtime/step-log.js +1 -0
  180. package/dist/runtime/subagents/child.js +2 -0
  181. package/dist/runtime/subagents/deliveries.js +3 -0
  182. package/dist/runtime/subagents/dispatch.js +5 -1
  183. package/dist/runtime/subagents/messages.js +2 -0
  184. package/dist/runtime/subagents/org-agents.d.ts +1 -1
  185. package/dist/runtime/subagents/org-agents.js +2 -1
  186. package/dist/runtime/usage-report-jobs.js +1 -0
  187. package/dist/runtime/usage-report.js +3 -0
  188. package/dist/runtime/waits.js +5 -0
  189. package/dist/sandbox/cloud-permission-snapshot.js +9 -3
  190. package/dist/sandbox/device-reports.js +3 -0
  191. package/dist/sandbox/legacy-retirement.js +5 -1
  192. package/dist/sandbox/managed-device-context.js +1 -0
  193. package/dist/sandbox/modes.d.ts +5 -2
  194. package/dist/sandbox/modes.js +8 -4
  195. package/dist/sandbox/network-grants.js +2 -0
  196. package/dist/sandbox/operation-intents.js +58 -0
  197. package/dist/sandbox/operation-reconcile.job.js +2 -0
  198. package/dist/sandbox/permission-authority-lock.js +12 -6
  199. package/dist/sandbox/permission-call-grants.js +6 -0
  200. package/dist/sandbox/permission-ceiling-writes.js +5 -0
  201. package/dist/sandbox/permission-config-publication.js +5 -0
  202. package/dist/sandbox/permission-instance-writes.js +4 -0
  203. package/dist/sandbox/permission-runtime-reports.js +10 -1
  204. package/dist/sandbox/permission-transitions.js +3 -0
  205. package/dist/sandbox/review/review.service.js +8 -5
  206. package/dist/sandbox/sandbox.service.d.ts +14 -0
  207. package/dist/sandbox/sandbox.service.js +195 -29
  208. package/dist/sandbox/unreachable.js +4 -1
  209. package/dist/schedules/fire.js +9 -3
  210. package/dist/schedules/pause.js +2 -0
  211. package/dist/schedules/run-tracker.js +16 -1
  212. package/dist/schedules/scheduled-tasks.service.js +4 -2
  213. package/dist/schedules/store.js +8 -0
  214. package/dist/schedules/unattended.js +4 -0
  215. package/dist/setup/setup-checks.service.d.ts +1 -10
  216. package/dist/setup/setup-checks.service.js +19 -29
  217. package/dist/shares/share-open.service.js +1 -0
  218. package/dist/shares/shares.service.js +2 -0
  219. package/dist/skills/agent-skills.service.d.ts +1 -1
  220. package/dist/skills/agent-skills.service.js +13 -2
  221. package/dist/skills/catalog.js +3 -0
  222. package/dist/skills/changes.service.js +10 -2
  223. package/dist/skills/conversation-catalog.js +1 -0
  224. package/dist/skills/skills.service.js +4 -0
  225. package/dist/tools/approvals.service.js +40 -0
  226. package/dist/tools/builtins/schedules.js +11 -6
  227. package/dist/tools/builtins/web/fetch.js +1 -1
  228. package/dist/tools/builtins/web/search.js +1 -1
  229. package/dist/tools/connector-account-policies.js +3 -0
  230. package/dist/tools/connectors.controller.d.ts +37 -9
  231. package/dist/tools/connectors.controller.js +47 -12
  232. package/dist/tools/connectors.schemas.d.ts +4 -0
  233. package/dist/tools/connectors.schemas.js +13 -1
  234. package/dist/tools/connectors.service.d.ts +17 -0
  235. package/dist/tools/connectors.service.js +36 -2
  236. package/dist/tools/drift.js +5 -0
  237. package/dist/tools/git-push-policy.js +3 -0
  238. package/dist/tools/oauth/discovery.d.ts +2 -2
  239. package/dist/tools/oauth/discovery.js +2 -2
  240. package/dist/tools/oauth/flow.js +1 -0
  241. package/dist/tools/outputs.js +2 -0
  242. package/dist/tools/permission-approval-jobs.js +3 -0
  243. package/dist/tools/pipeline.js +2 -0
  244. package/dist/tools/policy.js +3 -0
  245. package/dist/tools/questions.service.js +13 -0
  246. package/package.json +3 -3
  247. package/src/migrations/0181_connector_description.sql +3 -0
@@ -9,6 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable, Optional } from "@nestjs/common";
11
11
  import { ApiError } from "../errors.js";
12
+ import { EffectiveConfigs } from "../extensions/effective-config.js";
12
13
  import { ExtensionRegistry } from "../extensions/registry.js";
13
14
  import { audit } from "../identity/audit.js";
14
15
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -97,17 +98,19 @@ let PluginScopeSync = class PluginScopeSync {
97
98
  outbox;
98
99
  installer;
99
100
  registry;
101
+ effective;
100
102
  locks;
101
103
  log;
102
104
  txHost;
103
105
  chunkSize;
104
- constructor(kdb, outbox, installer, registry, locks, log, txHost,
106
+ constructor(kdb, outbox, installer, registry, effective, locks, log, txHost,
105
107
  /** Orgs per chunk job (a test seam; default {@link SCOPE_ORG_CHUNK}). */
106
108
  chunkSize = SCOPE_ORG_CHUNK) {
107
109
  this.kdb = kdb;
108
110
  this.outbox = outbox;
109
111
  this.installer = installer;
110
112
  this.registry = registry;
113
+ this.effective = effective;
111
114
  this.locks = locks;
112
115
  this.log = log;
113
116
  this.txHost = txHost;
@@ -341,7 +344,7 @@ let PluginScopeSync = class PluginScopeSync {
341
344
  // enqueue)
342
345
  if (live?.status !== "installed")
343
346
  return "unchanged";
344
- const deps = await this.createdDependencies(live.id);
347
+ const deps = await this.createdDependencies(orgId, live.id);
345
348
  try {
346
349
  await this.installer.uninstall(orgId, null, live.id, { via: "scope" });
347
350
  }
@@ -373,8 +376,8 @@ let PluginScopeSync = class PluginScopeSync {
373
376
  .executeTakeFirst();
374
377
  return row !== undefined;
375
378
  }
376
- /** The items of the dependency installs this install created. */
377
- async createdDependencies(installId) {
379
+ /** The items of the dependency installs this install (of `orgId`) created. */
380
+ async createdDependencies(orgId, installId) {
378
381
  // `ref` is text: the child install ids are read first, then their items
379
382
  const refs = await this.db
380
383
  .selectFrom("plugin_install_components")
@@ -388,14 +391,15 @@ let PluginScopeSync = class PluginScopeSync {
388
391
  const rows = await this.db
389
392
  .selectFrom("plugin_installs")
390
393
  .select("item_id")
394
+ .where("org_id", "=", orgId)
391
395
  .where("id", "in", refs.map((r) => r.ref))
392
396
  .execute();
393
397
  return rows.map((r) => r.item_id);
394
398
  }
395
399
  /**
396
400
  * Whether installing the item (with the dependencies the org lacks) needs the org's input: a
397
- * connector template, or an extension whose org config is required and not set in the org. The
398
- * same rule as the org catalog's `needs_config`, applied to the whole tree.
401
+ * connector template, or an extension whose effective config for the org is not valid. The same
402
+ * rule as the org catalog's `needs_config`, applied to the whole tree.
399
403
  */
400
404
  async needsInput(orgId, itemId, version) {
401
405
  const v = await this.db
@@ -424,7 +428,8 @@ let PluginScopeSync = class PluginScopeSync {
424
428
  /**
425
429
  * Whether installing plugin `itemId` (manifest `m`) needs the org's input: a connector template
426
430
  * on in the org (ruling P2-6: templates switched off there, outside their own scope or disabled
427
- * make no connector), or a required org config of its extension not set yet.
431
+ * make no connector), or its extension's effective config for the org is not valid (a required
432
+ * overridable field the platform leaves empty and the org has no copy of).
428
433
  */
429
434
  async manifestNeedsInput(orgId, m, itemId) {
430
435
  const ids = (m.connectorTemplates ?? []).map((t) => templateIdOfPath(t.path));
@@ -432,18 +437,10 @@ let PluginScopeSync = class PluginScopeSync {
432
437
  return true;
433
438
  if (!m.extension)
434
439
  return false;
435
- const ext = this.registry.manifests().find((x) => x.name === m.name);
436
- const schema = ext?.config?.org;
437
- if (schema === undefined || schema.safeParse({}).success)
440
+ // not loaded here: `extensionReady` decides; an extension without overridable fields is ok
441
+ if (!this.registry.manifests().some((x) => x.name === m.name))
438
442
  return false;
439
- const configured = await this.db
440
- .selectFrom("extension_org_configs")
441
- .select("plugin")
442
- .where("org_id", "=", orgId)
443
- .where("plugin", "=", m.name)
444
- .where("config", "is not", null)
445
- .executeTakeFirst();
446
- return configured === undefined;
443
+ return !(await this.effective.get(orgId, m.name)).ok;
447
444
  }
448
445
  /**
449
446
  * Logs and audits a failed install or uninstall (`plugin.scope_sync_failed`, actor null) and
@@ -490,10 +487,11 @@ PluginScopeSync = __decorate([
490
487
  __param(1, Inject(OutboxService)),
491
488
  __param(2, Inject(PluginInstaller)),
492
489
  __param(3, Inject(ExtensionRegistry)),
493
- __param(4, Inject(LockService)),
494
- __param(5, Inject(KERNEL_LOGGER)),
495
- __param(6, Inject(TransactionHost)),
496
- __param(7, Optional()),
497
- __param(7, Inject(SCOPE_ORG_CHUNK_SIZE))
490
+ __param(4, Inject(EffectiveConfigs)),
491
+ __param(5, Inject(LockService)),
492
+ __param(6, Inject(KERNEL_LOGGER)),
493
+ __param(7, Inject(TransactionHost)),
494
+ __param(8, Optional()),
495
+ __param(8, Inject(SCOPE_ORG_CHUNK_SIZE))
498
496
  ], PluginScopeSync);
499
497
  export { PluginScopeSync };
@@ -0,0 +1,17 @@
1
+ /** A connector template's description as the API returns it: the text for every language and the Chinese one. */
2
+ export interface TemplateDescription {
3
+ /** The English text, or the one text a plain-string description has; null without one. */
4
+ description: string | null;
5
+ /** The Chinese text of a `{ zh, en }` description; null: `description` serves both languages. */
6
+ descriptionZh: string | null;
7
+ }
8
+ /**
9
+ * Splits a template file's `description` (a string, or `{ zh, en }`; read from stored JSON, so any
10
+ * other shape counts as none) into the API's `description` / `descriptionZh` pair.
11
+ */
12
+ export declare function templateDescription(v: unknown): TemplateDescription;
13
+ /** {@link templateDescription} with "" rather than null without one (the wizard and the review). */
14
+ export declare function templateDescriptionText(v: unknown): {
15
+ description: string;
16
+ descriptionZh: string | null;
17
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Splits a template file's `description` (a string, or `{ zh, en }`; read from stored JSON, so any
3
+ * other shape counts as none) into the API's `description` / `descriptionZh` pair.
4
+ */
5
+ export function templateDescription(v) {
6
+ if (typeof v === "string")
7
+ return { description: v === "" ? null : v, descriptionZh: null };
8
+ const d = v;
9
+ if (typeof d?.en === "string" && typeof d.zh === "string") {
10
+ return { description: d.en, descriptionZh: d.zh };
11
+ }
12
+ return { description: null, descriptionZh: null };
13
+ }
14
+ /** {@link templateDescription} with "" rather than null without one (the wizard and the review). */
15
+ export function templateDescriptionText(v) {
16
+ const d = templateDescription(v);
17
+ return { description: d.description ?? "", descriptionZh: d.descriptionZh };
18
+ }
@@ -17,6 +17,8 @@ async function liveOrgIds(db) {
17
17
  * `catalog.scope_changed`; returns whether the scope changed (the caller enqueues the item's
18
18
  * scope sync after the commit).
19
19
  */
20
+ // org-filter: unsharing narrows the item to every org where it is on now, so it reads and rewrites
21
+ // the item's installs, switches and named list across orgs (keyed by the locked item id)
20
22
  export async function narrowItemOnUnshare(db, actor, item) {
21
23
  if (item.owner_org_id === null || item.scope === "named")
22
24
  return false;
@@ -70,6 +72,7 @@ export async function narrowItemOnUnshare(db, actor, item) {
70
72
  * to `named` = owner + the live orgs where it is on now ({@link componentOn}). A component that
71
73
  * follows its plugin is narrowed with the plugin. Audits `component.scope_changed`.
72
74
  */
75
+ // org-filter: unsharing narrows the component's whole named list to every org where it is on now
73
76
  export async function narrowComponentOnUnshare(db, actor, c) {
74
77
  if (c.ownerOrgId === null || c.scopeMode !== "own" || c.scope === "named")
75
78
  return false;
@@ -835,6 +835,7 @@ let ChannelConnections = class ChannelConnections {
835
835
  .selectFrom("channel_connections")
836
836
  .select("config")
837
837
  .where("id", "=", id)
838
+ .where("org_id", "=", row.orgId)
838
839
  .executeTakeFirstOrThrow();
839
840
  const full = structuredClone(stored.config ?? {});
840
841
  for (const [p, v] of Object.entries(await this.readSecrets(row.orgId, id)))
@@ -271,6 +271,7 @@ let ChannelInbound = class ChannelInbound {
271
271
  await db
272
272
  .deleteFrom("conversations")
273
273
  .where("id", "=", created)
274
+ .where("org_id", "=", row.orgId)
274
275
  .where("last_seq", "=", "0")
275
276
  .execute();
276
277
  }
@@ -97,6 +97,7 @@ let ChannelJobs = class ChannelJobs {
97
97
  .selectFrom("conversations")
98
98
  .select("last_seq")
99
99
  .where("id", "=", conversationId)
100
+ .where("org_id", "=", orgId)
100
101
  .forUpdate()
101
102
  .executeTakeFirst();
102
103
  if (!conv)
@@ -137,6 +137,7 @@ export async function conversationLocale(db, orgId, conversationId, uptoSeq) {
137
137
  .selectFrom("conversations")
138
138
  .select("account_id")
139
139
  .where("id", "=", conversationId)
140
+ .where("org_id", "=", orgId)
140
141
  .executeTakeFirst();
141
142
  accountId = c?.account_id ?? null;
142
143
  }
@@ -369,6 +370,7 @@ let ChannelOutbound = class ChannelOutbound {
369
370
  }
370
371
  }
371
372
  /** 会话日志当前的最后位置(会话不存在时 undefined)。 */
373
+ // org-filter: conversationId comes from the kernel-written delivery job payload, not caller input
372
374
  async lastSeq(conversationId) {
373
375
  const conv = await this.kdb
374
376
  .selectFrom("conversations")
@@ -387,6 +389,7 @@ let ChannelOutbound = class ChannelOutbound {
387
389
  async recordError(connectionId, message) {
388
390
  const text = `delivery failed: ${message}`.slice(0, MAX_ERROR_CHARS);
389
391
  this.log.warn("channel delivery failed", { connectionId, error: text });
392
+ // org-filter: connectionId is the delivery's own connection (kernel-written job / row)
390
393
  await this.kdb
391
394
  .updateTable("channel_connections")
392
395
  .set({ last_error: text })
@@ -721,6 +724,7 @@ class Delivery {
721
724
  .selectFrom("channel_connections")
722
725
  .select(["status", "updated_at"])
723
726
  .where("id", "=", this.s.row.id)
727
+ .where("org_id", "=", this.s.row.orgId)
724
728
  .where("deleted_at", "is", null)
725
729
  .executeTakeFirst();
726
730
  return r?.status === "active" ? r.updated_at.getTime() : undefined;
@@ -801,6 +805,7 @@ class Delivery {
801
805
  .selectFrom("conversations")
802
806
  .select("last_seq")
803
807
  .where("id", "=", this.conversationId)
808
+ .where("org_id", "=", this.s.row.orgId)
804
809
  .executeTakeFirst();
805
810
  return !conv || Number(conv.last_seq) <= this.seen;
806
811
  }
@@ -942,6 +947,7 @@ class Delivery {
942
947
  .selectFrom("questions")
943
948
  .select("spec")
944
949
  .where("id", "=", p.questionId)
950
+ .where("org_id", "=", this.s.row.orgId)
945
951
  .executeTakeFirst();
946
952
  const form = q?.spec?.form;
947
953
  if (!form)
@@ -521,6 +521,7 @@ let ChannelSupervisor = class ChannelSupervisor {
521
521
  await this.redis.expire(channelFailsKey(id), FAILS_TTL_SECONDS);
522
522
  const delay = Math.min(MAX_BACKOFF_MS, this.config.get().channels.retryBaseMs * 2 ** Math.min(fails - 1, 20));
523
523
  await this.redis.set(channelBackoffKey(id), "1", "PX", delay);
524
+ // org-filter: id is a connection this gateway supervisor holds the lease of, not caller input
524
525
  await this.db
525
526
  .updateTable("channel_connections")
526
527
  .set({ last_error: message })
@@ -163,6 +163,7 @@ export async function findOrBindThread(db, k, target, create) {
163
163
  const id = await create();
164
164
  const winner = await insertThread(db, k, id);
165
165
  if (winner !== id) {
166
+ // org-filter: id is the empty conversation create() just made in this transaction
166
167
  await db.deleteFrom("conversations").where("id", "=", id).where("last_seq", "=", "0").execute();
167
168
  return { conversationId: winner, created: false };
168
169
  }
@@ -82,6 +82,7 @@ let ClientReports = class ClientReports {
82
82
  }
83
83
  /** Deletes the reports last seen more than {@link REPORT_RETENTION_DAYS} days ago; the count. */
84
84
  async prune() {
85
+ // org-filter: deployment-wide retention sweep over every org's reports (maintenance job)
85
86
  const r = await this.db.db
86
87
  .deleteFrom("extension_client_reports")
87
88
  .where("last_at", "<", sql `now() - make_interval(days => ${REPORT_RETENTION_DAYS})`)
@@ -46,15 +46,31 @@ export function describeSchema(schema) {
46
46
  return { type, hasDefault, defaultValue, optional };
47
47
  }
48
48
  const WRAPPERS = new Set(["default", "prefault", "optional", "nullable", "readonly", "catch"]);
49
- /** 剥掉 default / optional 等包装,返回内层 schema 与沿途遇到的第一个(最外层)元信息。 */
49
+ /**
50
+ * Strips default / optional and the other wrappers: the inner schema and the meta merged across the
51
+ * chain (an outer key wins over an inner one), except `secret`, which holds when any node carries
52
+ * it, so a wrapper's meta (`platformOnly(secret(x).optional())`) never hides a secret.
53
+ */
50
54
  function unwrap(schema) {
55
+ const chain = [schema];
51
56
  let node = schema;
52
- let found = z.globalRegistry.get(node);
53
57
  while (WRAPPERS.has(node._zod.def.type)) {
54
58
  node = node._zod.def.innerType;
55
- found ??= z.globalRegistry.get(node);
59
+ chain.push(node);
60
+ }
61
+ let merged;
62
+ let secret = false;
63
+ for (const n of chain.reverse()) {
64
+ const m = z.globalRegistry.get(n);
65
+ if (!m)
66
+ continue;
67
+ if (m.secret === true)
68
+ secret = true;
69
+ merged = { ...merged, ...m };
56
70
  }
57
- return { inner: node, meta: found };
71
+ if (merged && secret)
72
+ merged.secret = true;
73
+ return { inner: node, meta: merged };
58
74
  }
59
75
  /** 列出 schema 的所有叶子字段(对象递归展开;数组、record 等视作叶子)。 */
60
76
  export function configFields(schema, prefix = "", inheritedSecret = false) {
@@ -108,11 +108,11 @@ export declare const KernelConfigSchema: z.ZodObject<{
108
108
  refreshIntervalMinutes: z.ZodDefault<z.ZodNumber>;
109
109
  maxIndexBytes: z.ZodDefault<z.ZodNumber>;
110
110
  allowInsecureLoopback: z.ZodDefault<z.ZodBoolean>;
111
- allowPrivateHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
112
111
  allowedHosts: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
113
112
  }, z.core.$strict>>;
114
113
  net: z.ZodPrefault<z.ZodObject<{
115
114
  allowInsecureLoopback: z.ZodDefault<z.ZodBoolean>;
115
+ allowPrivateHosts: z.ZodDefault<z.ZodArray<z.ZodString>>;
116
116
  httpsProxy: z.ZodOptional<z.ZodString>;
117
117
  noProxy: z.ZodDefault<z.ZodArray<z.ZodString>>;
118
118
  }, z.core.$strict>>;
@@ -538,17 +538,6 @@ export const KernelConfigSchema = z.strictObject({
538
538
  .meta(meta({
539
539
  description: "Testing only: allow plain http for marketplace and tarball URLs on loopback addresses",
540
540
  })),
541
- allowPrivateHosts: z
542
- .array(z.string().superRefine((entry, ctx) => {
543
- const problem = privateHostEntryProblem(entry);
544
- if (problem !== null)
545
- ctx.addIssue({ code: "custom", message: problem });
546
- }))
547
- .max(100)
548
- .default([])
549
- .meta(meta({
550
- description: "Hosts or CIDRs that marketplace and git downloads may reach although they resolve to private addresses, e.g. an internal GitLab mirror. CIDR and IP entries match IP-literal hosts only; list internal DNS names as hostnames. Link-local addresses (169.254.0.0/16, fe80::/10) are always refused",
551
- })),
552
541
  allowedHosts: z
553
542
  .array(z
554
543
  .string()
@@ -575,6 +564,17 @@ export const KernelConfigSchema = z.strictObject({
575
564
  .meta(meta({
576
565
  description: "Testing only: lift every loopback and unspecified-address refusal for extensions' ctx.net.fetch (127.0.0.0/8, ::1, 0.0.0.0/8, ::), including plain http to them (fake servers in test stacks). Link-local and cloud metadata addresses stay refused. Never set it in production",
577
566
  })),
567
+ allowPrivateHosts: z
568
+ .array(z.string().superRefine((entry, ctx) => {
569
+ const problem = privateHostEntryProblem(entry);
570
+ if (problem !== null)
571
+ ctx.addIssue({ code: "custom", message: problem });
572
+ }))
573
+ .max(100)
574
+ .default([])
575
+ .meta(meta({
576
+ description: "Hosts or CIDRs that the kernel's own outbound requests may reach although they resolve to private addresses, e.g. an internal GitLab mirror or identity provider: marketplace, archive and git downloads, npm registry downloads (packages, provenance, bootstrap plugins), OAuth requests (discovery, registration, token endpoints) and git identity checks. CIDR and IP entries match IP-literal hosts only; list internal DNS names as hostnames. Link-local addresses (169.254.0.0/16, fe80::/10) are always refused. Extensions' ctx.net.fetch requests use an organization's allowed internal endpoints instead",
577
+ })),
578
578
  httpsProxy: z
579
579
  .string()
580
580
  .superRefine((value, ctx) => {
@@ -585,7 +585,7 @@ export const KernelConfigSchema = z.strictObject({
585
585
  .optional()
586
586
  .meta(meta({
587
587
  secret: true,
588
- description: "HTTP(S) egress proxy for marketplace, archive and git downloads, npm registry downloads (packages, provenance, bootstrap plugins) OAuth requests (discovery, registration, token endpoints) and extensions' ctx.net.fetch requests (person-supplied URLs such as connector endpoints), e.g. http://user:password@proxy.internal:3128. https downloads tunnel through it with CONNECT and the kernel no longer resolves their hosts: the proxy does, so blocking private and internal addresses becomes the proxy's job, including for organizations' ctx.net requests (IP-literal URLs are still checked against marketplaces.allowPrivateHosts, or for ctx.net against the organization's allowed internal endpoints). Loopback hosts never use it, nor does an http:// npm registry; list an internal https registry in net.noProxy, and likewise every internal https host an organization's allowed internal endpoints name (with a proxy set the proxy resolves it, so the organization's allowances do not apply unless the host is in net.noProxy). HTTPS_PROXY / NODE_USE_ENV_PROXY are not read. Credentials in the URL are sent as Basic Proxy-Authorization and never logged",
588
+ description: "HTTP(S) egress proxy for marketplace, archive and git downloads, npm registry downloads (packages, provenance, bootstrap plugins) OAuth requests (discovery, registration, token endpoints) and extensions' ctx.net.fetch requests (person-supplied URLs such as connector endpoints), e.g. http://user:password@proxy.internal:3128. https downloads tunnel through it with CONNECT and the kernel no longer resolves their hosts: the proxy does, so blocking private and internal addresses becomes the proxy's job, including for organizations' ctx.net requests (IP-literal URLs are still checked against net.allowPrivateHosts, or for ctx.net against the organization's allowed internal endpoints). Loopback hosts never use it, nor does an http:// npm registry; list an internal https registry in net.noProxy, and likewise every internal https host an organization's allowed internal endpoints name (with a proxy set the proxy resolves it, so the organization's allowances do not apply unless the host is in net.noProxy). HTTPS_PROXY / NODE_USE_ENV_PROXY are not read. Credentials in the URL are sent as Basic Proxy-Authorization and never logged",
589
589
  })),
590
590
  noProxy: z
591
591
  .array(z
@@ -600,7 +600,7 @@ export const KernelConfigSchema = z.strictObject({
600
600
  .max(100)
601
601
  .default([])
602
602
  .meta(meta({
603
- description: "Hostnames or IP addresses that bypass net.httpsProxy (an entry also matches its subdomains; a leading dot is allowed). These hosts are resolved locally and must resolve to public addresses unless listed in marketplaces.allowPrivateHosts (marketplace downloads) or in an organization's allowed internal endpoints (ctx.net.fetch). List an organization's allowed internal https hosts here when net.httpsProxy is set, otherwise the proxy resolves them and the allowances do not apply",
603
+ description: "Hostnames or IP addresses that bypass net.httpsProxy (an entry also matches its subdomains; a leading dot is allowed). These hosts are resolved locally and must resolve to public addresses unless listed in net.allowPrivateHosts (the kernel's own requests) or in an organization's allowed internal endpoints (ctx.net.fetch). List an organization's allowed internal https hosts here when net.httpsProxy is set, otherwise the proxy resolves them and the allowances do not apply",
604
604
  })),
605
605
  })
606
606
  .prefault({}),
@@ -76,6 +76,7 @@ export const accessibleTo = (viewer) => (eb) => eb.and([
76
76
  .selectFrom("agents")
77
77
  .select(sql `1`.as("one"))
78
78
  .whereRef("agents.id", "=", "conversations.agent_id")
79
+ .whereRef("agents.org_id", "=", "conversations.org_id")
79
80
  .where("agents.deleted_at", "is", null)
80
81
  .where(visibleTo(viewer))),
81
82
  ]);
@@ -307,7 +307,7 @@ let AttachmentsService = class AttachmentsService {
307
307
  ttlHours,
308
308
  });
309
309
  const head = await this.storage.kernel(orgId).put(key, file.bytes, { contentType, size });
310
- await this.markStored(id, head.size, head.etag ?? null);
310
+ await this.markStored(orgId, id, head.size, head.etag ?? null);
311
311
  return { id };
312
312
  }
313
313
  /**
@@ -329,11 +329,12 @@ let AttachmentsService = class AttachmentsService {
329
329
  .execute();
330
330
  }
331
331
  /** The last step of {@link createFromBytes}: the stored object's size and etag, `ready`. */
332
- async markStored(id, size, etag) {
332
+ async markStored(orgId, id, size, etag) {
333
333
  await this.db.db
334
334
  .updateTable("attachments")
335
335
  .set({ status: "ready", size, etag })
336
336
  .where("id", "=", id)
337
+ .where("org_id", "=", orgId)
337
338
  .where("status", "=", "pending")
338
339
  .execute();
339
340
  }
@@ -412,6 +413,7 @@ let AttachmentsService = class AttachmentsService {
412
413
  .updateTable("attachments")
413
414
  .set({ status: "ready", etag: got?.head.etag ?? head.etag ?? null, pages })
414
415
  .where("id", "=", id)
416
+ .where("org_id", "=", orgId)
415
417
  .where("status", "=", "pending")
416
418
  .execute();
417
419
  return view;
@@ -623,6 +625,7 @@ let AttachmentsService = class AttachmentsService {
623
625
  .updateTable("attachments")
624
626
  .set({ conversation_id: conversationId, expires_at: null })
625
627
  .where("id", "in", toBind)
628
+ .where("org_id", "=", orgId)
626
629
  .execute();
627
630
  }
628
631
  return blocks;
@@ -764,6 +767,7 @@ let AttachmentsService = class AttachmentsService {
764
767
  .updateTable("attachments")
765
768
  .set({ expires_at: sql `now() + make_interval(hours => ${SKILL_PACKAGE_TTL_HOURS})` })
766
769
  .where("id", "=", id)
770
+ .where("org_id", "=", orgId)
767
771
  .where("status", "=", "ready")
768
772
  .where("purpose", "=", "skill-package")
769
773
  .returning(["object_key", "size", "etag"])
@@ -801,6 +805,7 @@ let AttachmentsService = class AttachmentsService {
801
805
  .updateTable("attachments")
802
806
  .set({ status: "deleting", expires_at: sql `now()` })
803
807
  .where("id", "=", id)
808
+ .where("org_id", "=", orgId)
804
809
  .execute();
805
810
  }
806
811
  /**
@@ -838,6 +843,7 @@ let AttachmentsService = class AttachmentsService {
838
843
  .updateTable("attachments")
839
844
  .set({ expires_at: sql `now() + make_interval(hours => ${AGENT_AVATAR_TTL_HOURS})` })
840
845
  .where("id", "=", id)
846
+ .where("org_id", "=", orgId)
841
847
  .where("status", "=", "ready")
842
848
  .where("agent_id", "is", null)
843
849
  .where("expires_at", "is not", null)
@@ -867,6 +873,7 @@ let AttachmentsService = class AttachmentsService {
867
873
  .updateTable("attachments")
868
874
  .set({ agent_id: agentId, expires_at: null })
869
875
  .where("id", "=", id)
876
+ .where("org_id", "=", orgId)
870
877
  .execute();
871
878
  }
872
879
  /**
@@ -937,7 +944,7 @@ let AttachmentsService = class AttachmentsService {
937
944
  const head = await this.storage
938
945
  .kernel(orgId)
939
946
  .put(key, file.data, { contentType: contentType || "application/octet-stream" });
940
- await this.bindRead(id, conversationId, head.size, head.etag ?? null);
947
+ await this.bindRead(orgId, id, conversationId, head.size, head.etag ?? null);
941
948
  return { ok: true, attachmentId: id, size: head.size };
942
949
  }
943
950
  /**
@@ -984,11 +991,12 @@ let AttachmentsService = class AttachmentsService {
984
991
  }
985
992
  }
986
993
  /** Step 4 of {@link storeRead}: binds the unbound row in one transaction. */
987
- async bindRead(id, conversationId, size, etag) {
994
+ async bindRead(orgId, id, conversationId, size, etag) {
988
995
  const bound = await this.db.db
989
996
  .updateTable("attachments")
990
997
  .set({ conversation_id: conversationId, status: "ready", expires_at: null, size, etag })
991
998
  .where("id", "=", id)
999
+ .where("org_id", "=", orgId)
992
1000
  .where("purpose", "=", "read")
993
1001
  .where("status", "=", "pending")
994
1002
  .where("conversation_id", "is", null)
@@ -1006,6 +1014,8 @@ let AttachmentsService = class AttachmentsService {
1006
1014
  * Chat attachments of deleted conversations are not touched. Does nothing without an object
1007
1015
  * store. Returns the number of rows deleted.
1008
1016
  */
1017
+ // org-filter: deployment-wide cleanup job across all orgs; each claimed row is deleted by its
1018
+ // own id and handled in its own org (r.org_id)
1009
1019
  async purgeRead() {
1010
1020
  if (!this.storage.available)
1011
1021
  return 0;
@@ -1070,6 +1080,8 @@ let AttachmentsService = class AttachmentsService {
1070
1080
  * 解出的文件 `skills/<id>/` 只在没有任何技能版本引用时一并删除。
1071
1081
  * 没有对象存储时什么也不做。返回删除的附件数。
1072
1082
  */
1083
+ // org-filter: deployment-wide cleanup job across all orgs; each claimed row is deleted by its
1084
+ // own id and handled in its own org (r.org_id)
1073
1085
  async deleteExpired() {
1074
1086
  if (!this.storage.available)
1075
1087
  return 0;
@@ -309,7 +309,12 @@ let ConversationsService = class ConversationsService {
309
309
  }
310
310
  await this.eventLog.notify(id, written.seq);
311
311
  await this.startRun(id);
312
- return { conversation: await this.rowView(id), event: written, events: all, created: true };
312
+ return {
313
+ conversation: await this.rowView(orgId, id),
314
+ event: written,
315
+ events: all,
316
+ created: true,
317
+ };
313
318
  }
314
319
  /** The conversation row and its first message (undefined: a concurrent retry committed first). */
315
320
  // its own transaction: the caller notifies and publishes after the commit
@@ -403,11 +408,12 @@ let ConversationsService = class ConversationsService {
403
408
  startRun(conversationId) {
404
409
  return this.runs.ensureRunAfterCommit(conversationId);
405
410
  }
406
- async rowView(id) {
411
+ async rowView(orgId, id) {
407
412
  return toView(await this.db
408
413
  .selectFrom("conversations")
409
414
  .select(viewColumns())
410
415
  .where("id", "=", id)
416
+ .where("org_id", "=", orgId)
411
417
  .executeTakeFirstOrThrow());
412
418
  }
413
419
  /**
@@ -420,6 +426,7 @@ let ConversationsService = class ConversationsService {
420
426
  .updateTable("conversations")
421
427
  .set({ title, title_source: "manual" })
422
428
  .where("id", "=", conversationId)
429
+ .where("org_id", "=", orgId)
423
430
  .returning(viewColumns())
424
431
  .executeTakeFirstOrThrow();
425
432
  await this.eventLog.publishChanged(conversationId, "title");
@@ -435,6 +442,7 @@ let ConversationsService = class ConversationsService {
435
442
  .updateTable("conversations")
436
443
  .set({ archived_at: archived ? sql `now()` : null })
437
444
  .where("id", "=", conversationId)
445
+ .where("org_id", "=", orgId)
438
446
  .returning(viewColumns())
439
447
  .executeTakeFirstOrThrow();
440
448
  await this.eventLog.publishChanged(conversationId, "archived");
@@ -489,6 +497,7 @@ let ConversationsService = class ConversationsService {
489
497
  .selectFrom("conversations")
490
498
  .select("device_id")
491
499
  .where("id", "=", rootId)
500
+ .where("org_id", "=", orgId)
492
501
  .executeTakeFirstOrThrow();
493
502
  return {
494
503
  orgId,
@@ -521,6 +530,7 @@ let ConversationsService = class ConversationsService {
521
530
  .updateTable("conversations")
522
531
  .set({ deleted_at: sql `now()` })
523
532
  .where("id", "=", conversationId)
533
+ .where("org_id", "=", orgId)
524
534
  .execute();
525
535
  await this.runs.oweStopDeletedTree(conversationId, accountId, orgId);
526
536
  // Queued messages must not start a run on a deleted conversation
@@ -770,7 +780,8 @@ let ConversationsService = class ConversationsService {
770
780
  ? sql ``
771
781
  : sql `AND (c.created_at, c.id) < (
772
782
  SELECT c2.created_at, c2.id FROM capybara.conversations c2
773
- WHERE c2.id = ${opts.after} AND c2.parent_conversation_id = ${conversationId}
783
+ WHERE c2.id = ${opts.after} AND c2.org_id = ${orgId}
784
+ AND c2.parent_conversation_id = ${conversationId}
774
785
  )`;
775
786
  const { rows } = await sql `
776
787
  WITH page AS (
@@ -965,6 +976,7 @@ let ConversationsService = class ConversationsService {
965
976
  .updateTable("conversations")
966
977
  .set({ archived_at: null })
967
978
  .where("id", "=", conversationId)
979
+ .where("org_id", "=", orgId)
968
980
  .execute();
969
981
  await this.eventLog.publishChanged(conversationId, "archived");
970
982
  }
@@ -1138,6 +1150,7 @@ let ConversationsService = class ConversationsService {
1138
1150
  .updateTable("conversations")
1139
1151
  .set({ selection: JSON.stringify(await readSelection(t, conversationId)) })
1140
1152
  .where("id", "=", conversationId)
1153
+ .where("org_id", "=", orgId)
1141
1154
  .execute();
1142
1155
  }
1143
1156
  return { events: written, skipped: skips.skipped, skippedToSeq: skips.toSeq };
@@ -1288,6 +1301,7 @@ let ConversationsService = class ConversationsService {
1288
1301
  * Marks a person's stop of the root's tree (`tree_stopped_at`, see {@link abort}); committed
1289
1302
  * before any stop, so every wake decided after it (under the root's row lock) sees it.
1290
1303
  */
1304
+ // org-filter: conversationId was checked by get(orgId, ...) in abort, the only entry point
1291
1305
  async holdTree(conversationId) {
1292
1306
  await this.db
1293
1307
  .updateTable("conversations")
@@ -382,6 +382,8 @@ let EventLog = class EventLog {
382
382
  return r.data;
383
383
  }
384
384
  /** The append itself, in the context's transaction (both callers open or join one). */
385
+ // org-filter: the log writer is keyed by conversation id only; every append path resolved the
386
+ // conversation in its org first (access check, run claim, channel binding)
385
387
  async write(conversationId, events, bodies) {
386
388
  const t = this.db;
387
389
  // 先锁会话行:之后的幂等查询与 seq 分配都在这把锁内,并发 append 依次执行。The same statement
@@ -1517,6 +1517,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1517
1517
  connector: "connector";
1518
1518
  default: "default";
1519
1519
  fixed: "fixed";
1520
+ member: "member";
1520
1521
  org: "org";
1521
1522
  role: "role";
1522
1523
  }>>;
@@ -1320,7 +1320,9 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1320
1320
  toolKey: z.string(),
1321
1321
  expiresAt: z.string(),
1322
1322
  /** Which rule asked a tool approval (UI refresh B; display only; absent on the other asks). */
1323
- policy: z.enum(["agent", "connector", "default", "role", "org", "fixed"]).optional(),
1323
+ policy: z
1324
+ .enum(["agent", "connector", "member", "default", "role", "org", "fixed"])
1325
+ .optional(),
1324
1326
  /**
1325
1327
  * A network ask (network ask-to-allow spec §6.1): the hosts the device owner is asked to
1326
1328
  * allow. Display only, never model-visible: the model sees the call's `tool_result` only.
@@ -215,7 +215,7 @@ let ConversationFiles = class ConversationFiles {
215
215
  start = at + 1;
216
216
  }
217
217
  const page = ordered.slice(start, start + opts.limit);
218
- const shares = await this.viewerShares(conversationId, viewer);
218
+ const shares = await this.viewerShares(orgId, conversationId, viewer);
219
219
  const store = this.storage.kernel(orgId);
220
220
  const files = await mapLimit(page, HEAD_CONCURRENCY, async (e) => {
221
221
  if (e.origin === "uploaded") {
@@ -331,10 +331,11 @@ let ConversationFiles = class ConversationFiles {
331
331
  * The source paths and attachments the viewer has a share of in the conversation that is not
332
332
  * revoked or expired ({@link FileOutput.shared}).
333
333
  */
334
- async viewerShares(conversationId, viewer) {
334
+ async viewerShares(orgId, conversationId, viewer) {
335
335
  const rows = await this.db
336
336
  .selectFrom("file_shares")
337
337
  .select(["source_path", "file_id"])
338
+ .where("org_id", "=", orgId)
338
339
  .where("conversation_id", "=", conversationId)
339
340
  .where("created_by", "=", viewer)
340
341
  .where("revoked_at", "is", null)