@capybara-hq/kernel 0.1.0-rc.67 → 0.1.0-rc.69

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 (226) hide show
  1. package/bootstrap.json +9 -1
  2. package/dist/admin/admin.module.js +2 -0
  3. package/dist/admin/health.service.d.ts +11 -4
  4. package/dist/admin/health.service.js +33 -17
  5. package/dist/background/poll.job.js +2 -2
  6. package/dist/background/tasks.service.d.ts +5 -5
  7. package/dist/background/tasks.service.js +9 -8
  8. package/dist/catalog/credential-key.d.ts +10 -0
  9. package/dist/catalog/credential-key.js +28 -0
  10. package/dist/catalog/marketplaces.service.d.ts +1 -1
  11. package/dist/catalog/plugin-upgrade.js +1 -19
  12. package/dist/catalog/requests.service.js +1 -1
  13. package/dist/config/schema.d.ts +1 -1
  14. package/dist/config/schema.js +9 -9
  15. package/dist/conversations/conversations.controller.d.ts +8 -3
  16. package/dist/conversations/conversations.controller.js +8 -3
  17. package/dist/conversations/conversations.service.d.ts +33 -15
  18. package/dist/conversations/conversations.service.js +60 -10
  19. package/dist/conversations/events.d.ts +21 -41
  20. package/dist/conversations/events.js +57 -31
  21. package/dist/conversations/permission-profiles.controller.d.ts +6 -4
  22. package/dist/conversations/permission-profiles.service.d.ts +6 -4
  23. package/dist/ctx/create-ctx.d.ts +20 -1
  24. package/dist/ctx/create-ctx.js +77 -6
  25. package/dist/ctx/device-provider-check.d.ts +6 -2
  26. package/dist/ctx/device-provider-check.js +17 -2
  27. package/dist/db/kernel-schema.d.ts +10 -48
  28. package/dist/devices/access.d.ts +3 -4
  29. package/dist/devices/access.js +3 -4
  30. package/dist/devices/conversation-devices.d.ts +1 -3
  31. package/dist/devices/conversation-devices.js +2 -7
  32. package/dist/devices/device-projects.service.js +24 -29
  33. package/dist/devices/device-provider-selection.d.ts +5 -6
  34. package/dist/devices/device-provider-selection.js +8 -9
  35. package/dist/devices/devices.controller.d.ts +8 -21
  36. package/dist/devices/devices.controller.js +9 -34
  37. package/dist/devices/devices.module.js +6 -4
  38. package/dist/devices/devices.schemas.d.ts +1 -5
  39. package/dist/devices/devices.schemas.js +1 -5
  40. package/dist/devices/devices.service.d.ts +84 -147
  41. package/dist/devices/devices.service.js +134 -229
  42. package/dist/devices/dto.d.ts +5 -32
  43. package/dist/devices/dto.js +5 -37
  44. package/dist/devices/errors.d.ts +6 -5
  45. package/dist/devices/errors.js +7 -8
  46. package/dist/devices/project-rules.d.ts +9 -11
  47. package/dist/devices/project-rules.js +7 -7
  48. package/dist/devices/working-root.d.ts +3 -6
  49. package/dist/devices/working-root.js +3 -8
  50. package/dist/dial-in/access.d.ts +23 -0
  51. package/dist/dial-in/access.js +64 -0
  52. package/dist/{local-devices/device-auth.controller.d.ts → dial-in/auth.controller.d.ts} +12 -6
  53. package/dist/{local-devices/device-auth.controller.js → dial-in/auth.controller.js} +30 -15
  54. package/dist/dial-in/auth.module.d.ts +7 -0
  55. package/dist/dial-in/auth.module.js +27 -0
  56. package/dist/{local-devices/device-auth.d.ts → dial-in/auth.service.d.ts} +42 -13
  57. package/dist/{local-devices/device-auth.js → dial-in/auth.service.js} +83 -32
  58. package/dist/dial-in/dial-in.module.d.ts +9 -0
  59. package/dist/dial-in/dial-in.module.js +37 -0
  60. package/dist/{local-devices → dial-in}/dto.d.ts +17 -2
  61. package/dist/{local-devices → dial-in}/dto.js +14 -2
  62. package/dist/dial-in/envelope.d.ts +95 -0
  63. package/dist/dial-in/envelope.js +89 -0
  64. package/dist/dial-in/gateway.d.ts +214 -0
  65. package/dist/{local-devices/local-device-gateway.js → dial-in/gateway.js} +337 -181
  66. package/dist/dial-in/handlers.d.ts +47 -0
  67. package/dist/dial-in/handlers.js +84 -0
  68. package/dist/dial-in/machines.d.ts +155 -0
  69. package/dist/dial-in/machines.js +383 -0
  70. package/dist/dial-in/relay.d.ts +135 -0
  71. package/dist/dial-in/relay.js +444 -0
  72. package/dist/dial-in/relay.module.d.ts +7 -0
  73. package/dist/dial-in/relay.module.js +24 -0
  74. package/dist/{local-devices/device-routes.d.ts → dial-in/routes.d.ts} +19 -11
  75. package/dist/{local-devices/device-routes.js → dial-in/routes.js} +45 -25
  76. package/dist/{local-devices → dial-in}/targets.d.ts +3 -18
  77. package/dist/{local-devices → dial-in}/targets.js +3 -48
  78. package/dist/errors.d.ts +8 -27
  79. package/dist/errors.js +8 -27
  80. package/dist/extensions/bootstrap.d.ts +5 -0
  81. package/dist/extensions/bootstrap.js +10 -1
  82. package/dist/extensions/extensions.module.js +6 -0
  83. package/dist/extensions/host.d.ts +6 -0
  84. package/dist/extensions/host.js +12 -2
  85. package/dist/extensions/permission-set.d.ts +15 -1
  86. package/dist/extensions/permission-set.js +11 -1
  87. package/dist/extensions/permission-view.d.ts +1 -1
  88. package/dist/extensions/permission-view.js +4 -1
  89. package/dist/http/api.module.js +4 -4
  90. package/dist/http/gateway-routes.d.ts +1 -1
  91. package/dist/http/gateway-routes.js +1 -1
  92. package/dist/http/meta.controller.js +1 -1
  93. package/dist/identity/settings.d.ts +1 -1
  94. package/dist/identity/settings.js +6 -8
  95. package/dist/infra/config/kernel-config.service.js +2 -2
  96. package/dist/infra/outbox/registry.d.ts +0 -14
  97. package/dist/infra/outbox/registry.js +0 -15
  98. package/dist/infra/throttler/named-throttlers.d.ts +1 -1
  99. package/dist/infra/throttler/named-throttlers.js +1 -1
  100. package/dist/kernel.module.js +0 -3
  101. package/dist/orgs/settings.service.js +5 -10
  102. package/dist/overrides.d.ts +0 -4
  103. package/dist/overrides.js +0 -2
  104. package/dist/platform/exclusions.js +5 -5
  105. package/dist/platform/ops/admin.ops.js +1 -1
  106. package/dist/platform/ops/conversations.ops.js +5 -2
  107. package/dist/platform/ops/devices.ops.js +11 -24
  108. package/dist/platform/ops/inbox.ops.js +1 -1
  109. package/dist/roles/gateway-role.d.ts +3 -3
  110. package/dist/roles/gateway-role.js +4 -4
  111. package/dist/roles/gateway.module.d.ts +1 -1
  112. package/dist/roles/gateway.module.js +5 -5
  113. package/dist/runtime/context/device-paths.d.ts +4 -1
  114. package/dist/runtime/context/permission-profile.js +5 -5
  115. package/dist/runtime/maintenance.d.ts +2 -5
  116. package/dist/runtime/maintenance.js +9 -19
  117. package/dist/runtime/project/knowledge.js +4 -5
  118. package/dist/runtime/project/knowledge.service.js +2 -1
  119. package/dist/sandbox/cloud-permission-snapshot.d.ts +1 -1
  120. package/dist/sandbox/cloud-permission-snapshot.js +1 -3
  121. package/dist/sandbox/device-reports.d.ts +74 -14
  122. package/dist/sandbox/device-reports.js +190 -33
  123. package/dist/sandbox/device-reports.module.d.ts +7 -0
  124. package/dist/sandbox/device-reports.module.js +25 -0
  125. package/dist/sandbox/device-sandbox.d.ts +39 -41
  126. package/dist/sandbox/device-sandbox.js +44 -83
  127. package/dist/sandbox/kernel-read.d.ts +2 -2
  128. package/dist/sandbox/legacy-retirement.d.ts +11 -59
  129. package/dist/sandbox/legacy-retirement.js +34 -186
  130. package/dist/sandbox/legacy-retirement.module.d.ts +2 -2
  131. package/dist/sandbox/legacy-retirement.module.js +2 -2
  132. package/dist/sandbox/managed-device-context.d.ts +16 -4
  133. package/dist/sandbox/managed-device-context.js +25 -8
  134. package/dist/sandbox/managed-device-context.module.js +4 -0
  135. package/dist/sandbox/modes.d.ts +3 -12
  136. package/dist/sandbox/modes.js +2 -14
  137. package/dist/{local-devices → sandbox}/network-grants.d.ts +2 -21
  138. package/dist/{local-devices → sandbox}/network-grants.js +4 -49
  139. package/dist/sandbox/operation-authority-types.d.ts +2 -1
  140. package/dist/sandbox/operation-authority.d.ts +6 -20
  141. package/dist/sandbox/operation-authority.js +43 -104
  142. package/dist/sandbox/operation-authority.module.js +1 -1
  143. package/dist/sandbox/operation-intents.d.ts +4 -1
  144. package/dist/sandbox/operation-intents.js +11 -2
  145. package/dist/sandbox/operation-reconcile.job.js +2 -4
  146. package/dist/sandbox/permission-availability.d.ts +6 -7
  147. package/dist/sandbox/permission-availability.js +7 -10
  148. package/dist/sandbox/permission-call-grants.d.ts +2 -1
  149. package/dist/sandbox/permission-call-grants.js +1 -7
  150. package/dist/sandbox/permission-call-types.d.ts +4 -4
  151. package/dist/sandbox/permission-ceiling-writes.d.ts +7 -23
  152. package/dist/sandbox/permission-ceiling-writes.js +8 -35
  153. package/dist/sandbox/permission-config-publication.d.ts +9 -1
  154. package/dist/sandbox/permission-config-publication.js +29 -21
  155. package/dist/sandbox/permission-context-types.d.ts +17 -10
  156. package/dist/sandbox/permission-facts.d.ts +98 -95
  157. package/dist/sandbox/permission-facts.js +160 -314
  158. package/dist/sandbox/permission-instance-writes.d.ts +23 -37
  159. package/dist/sandbox/permission-instance-writes.js +44 -121
  160. package/dist/sandbox/permission-runtime-reports.d.ts +38 -30
  161. package/dist/sandbox/permission-runtime-reports.js +105 -122
  162. package/dist/sandbox/providers.d.ts +26 -38
  163. package/dist/sandbox/providers.js +36 -18
  164. package/dist/sandbox/request-not-sent.d.ts +2 -13
  165. package/dist/sandbox/request-not-sent.js +2 -13
  166. package/dist/sandbox/review/permission-candidate.d.ts +13 -8
  167. package/dist/sandbox/review/permission-candidate.js +38 -48
  168. package/dist/sandbox/sandbox.module.js +7 -3
  169. package/dist/sandbox/sandbox.service.d.ts +49 -59
  170. package/dist/sandbox/sandbox.service.js +139 -259
  171. package/dist/schedules/fire.d.ts +15 -6
  172. package/dist/schedules/fire.js +27 -13
  173. package/dist/schedules/grant-rules.js +1 -1
  174. package/dist/schedules/scheduled-tasks.service.d.ts +0 -7
  175. package/dist/schedules/scheduled-tasks.service.js +1 -4
  176. package/dist/schedules/schedules.module.js +5 -3
  177. package/dist/skills/invoke.d.ts +1 -1
  178. package/dist/skills/invoke.js +2 -3
  179. package/dist/tools/approvals.service.d.ts +8 -5
  180. package/dist/tools/approvals.service.js +5 -5
  181. package/dist/tools/builtins/sandbox/bash.js +1 -2
  182. package/dist/tools/builtins/sandbox/common.d.ts +15 -9
  183. package/dist/tools/builtins/sandbox/common.js +37 -38
  184. package/dist/tools/connectors.controller.d.ts +2 -0
  185. package/dist/tools/connectors.schemas.d.ts +2 -0
  186. package/dist/tools/credentials.d.ts +2 -0
  187. package/dist/tools/network-asks.d.ts +19 -22
  188. package/dist/tools/network-asks.js +15 -21
  189. package/dist/tools/oauth/authorization-params.d.ts +7 -0
  190. package/dist/tools/oauth/authorization-params.js +19 -0
  191. package/dist/tools/oauth/flow.js +7 -0
  192. package/dist/tools/oauth/tokens.js +2 -1
  193. package/dist/tools/pipeline.d.ts +6 -7
  194. package/dist/tools/pipeline.js +17 -21
  195. package/dist/tools/tools.module.js +3 -7
  196. package/package.json +3 -4
  197. package/src/migrations/0177_dial_in_contract.sql +32 -0
  198. package/dist/local-devices/device-auth.module.d.ts +0 -7
  199. package/dist/local-devices/device-auth.module.js +0 -25
  200. package/dist/local-devices/device-policy.service.d.ts +0 -213
  201. package/dist/local-devices/device-policy.service.js +0 -605
  202. package/dist/local-devices/instance-bindings.d.ts +0 -82
  203. package/dist/local-devices/instance-bindings.js +0 -307
  204. package/dist/local-devices/local-device-gateway.d.ts +0 -153
  205. package/dist/local-devices/local-device-provider.d.ts +0 -122
  206. package/dist/local-devices/local-device-provider.js +0 -326
  207. package/dist/local-devices/local-devices.module.d.ts +0 -31
  208. package/dist/local-devices/local-devices.module.js +0 -100
  209. package/dist/local-devices/machines.d.ts +0 -211
  210. package/dist/local-devices/machines.js +0 -766
  211. package/dist/local-devices/owner-report.d.ts +0 -81
  212. package/dist/local-devices/owner-report.js +0 -150
  213. package/dist/local-devices/owner-reports.d.ts +0 -48
  214. package/dist/local-devices/owner-reports.js +0 -208
  215. package/dist/local-devices/policy-op-jobs.d.ts +0 -15
  216. package/dist/local-devices/policy-op-jobs.js +0 -12
  217. package/dist/local-devices/policy-summary.d.ts +0 -102
  218. package/dist/local-devices/policy-summary.js +0 -155
  219. package/dist/local-devices/relay.d.ts +0 -166
  220. package/dist/local-devices/relay.js +0 -559
  221. package/dist/tools/device-op-resolver.d.ts +0 -34
  222. package/dist/tools/device-op-resolver.js +0 -120
  223. /package/dist/{local-devices → dial-in}/keys.d.ts +0 -0
  224. /package/dist/{local-devices → dial-in}/keys.js +0 -0
  225. /package/dist/{local-devices → sandbox}/network-grants.module.d.ts +0 -0
  226. /package/dist/{local-devices → sandbox}/network-grants.module.js +0 -0
@@ -83,6 +83,17 @@ function activitySql(ref) {
83
83
  ORDER BY lr.created_at DESC, lr.id DESC LIMIT 1
84
84
  )`;
85
85
  }
86
+ /** A {@link ConversationAgent} from an agent row and its current definition's name. */
87
+ function toConversationAgent(r) {
88
+ return {
89
+ id: r.id,
90
+ name: r.name ?? "",
91
+ profile: {
92
+ avatar: avatarView(r.profile_avatar),
93
+ updatedAt: r.profile_updated_at.toISOString(),
94
+ },
95
+ };
96
+ }
86
97
  const notFound = () => new ApiError("conversation.not_found", "Conversation not found");
87
98
  export const NO_REPLY_SKIPS = { questions: [], network: [], seqs: new Map() };
88
99
  export { userMessageIdemKey } from "./idem-keys.js";
@@ -569,14 +580,21 @@ let ConversationsService = class ConversationsService {
569
580
  return this.access.isAccessible(orgId, conversationId, viewerAccountId);
570
581
  }
571
582
  /**
572
- * 我的会话,最近更新的在前;只含 agent 仍可用的会话。`after` 为上一页最后一个会话的 id,
573
- * 从它当前的 (updated_at, id) 之后继续;游标会话已不存在时返回空页。
583
+ * My conversations, most recently updated first; only those whose agent is in this org, not
584
+ * deleted and visible to me. `after` is the previous page's last conversation id, continued after
585
+ * its current (updated_at, id); a cursor that no longer exists gives an empty page. Each row
586
+ * carries its agent (one batch read for the page). With `total`, also counts every conversation
587
+ * matching the same filters (the cursor aside) in the same statement.
574
588
  */
575
589
  async listMine(orgId, accountId, opts) {
576
590
  let q = this.db
577
591
  .selectFrom("conversations")
578
592
  .select(COLUMNS)
579
593
  .select(activitySql("conversations").as("activity"))
594
+ // The total of every match, computed before LIMIT in this same statement. It costs
595
+ // O(matches) (the window reads every matching row instead of stopping at the page), which
596
+ // is why only the first page asks for it.
597
+ .$if(opts.total === true, (qb) => qb.select(sql `count(*) OVER ()`.as("total_count")))
580
598
  .where("org_id", "=", orgId)
581
599
  .where("account_id", "=", accountId)
582
600
  // 评测回放的隐藏对话(kind = 'eval')不在「我的对话」里
@@ -587,6 +605,7 @@ let ConversationsService = class ConversationsService {
587
605
  .selectFrom("agents")
588
606
  .select(sql `1`.as("one"))
589
607
  .whereRef("agents.id", "=", "conversations.agent_id")
608
+ .where("agents.org_id", "=", orgId)
590
609
  .where("agents.deleted_at", "is", null)
591
610
  .where(visibleTo(accountId))))
592
611
  .orderBy("updated_at", "desc")
@@ -607,7 +626,40 @@ let ConversationsService = class ConversationsService {
607
626
  WHERE c.id = ${after} AND c.org_id = ${orgId} AND c.account_id = ${accountId}
608
627
  )`);
609
628
  }
610
- return (await q.execute()).map(toView);
629
+ const rows = await q.execute();
630
+ const agents = await this.listAgents(orgId, accountId, [
631
+ ...new Set(rows.map((r) => r.agent_id)),
632
+ ]);
633
+ const conversations = rows.map((r) => ({
634
+ ...toView(r),
635
+ agent: agents.get(r.agent_id) ?? null,
636
+ }));
637
+ if (opts.total !== true)
638
+ return { conversations };
639
+ return { conversations, total: Number(rows[0]?.total_count ?? 0) };
640
+ }
641
+ /**
642
+ * The agents of `ids` that are in this org, not deleted and visible to the viewer, by id, in one
643
+ * statement (the same visibility as the agents read path).
644
+ */
645
+ async listAgents(orgId, viewerAccountId, ids) {
646
+ if (ids.length === 0)
647
+ return new Map();
648
+ const rows = await this.db
649
+ .selectFrom("agents")
650
+ .innerJoin("agent_versions as v", (j) => j.onRef("v.agent_id", "=", "agents.id").onRef("v.version", "=", "agents.current_version"))
651
+ .select([
652
+ "agents.id",
653
+ "agents.profile_avatar",
654
+ "agents.profile_updated_at",
655
+ sql `v.definition ->> 'name'`.as("name"),
656
+ ])
657
+ .where("agents.id", "in", ids)
658
+ .where("agents.org_id", "=", orgId)
659
+ .where("agents.deleted_at", "is", null)
660
+ .where(visibleTo(viewerAccountId))
661
+ .execute();
662
+ return new Map(rows.map((r) => [r.id, toConversationAgent(r)]));
611
663
  }
612
664
  /**
613
665
  * My chat conversations grouped by agent (the sidebar, UI refresh spec §5.9), in one statement.
@@ -674,14 +726,12 @@ let ConversationsService = class ConversationsService {
674
726
  for (const r of rows) {
675
727
  if (current?.agent.id !== r.agent_id) {
676
728
  current = {
677
- agent: {
729
+ agent: toConversationAgent({
678
730
  id: r.agent_id,
679
- name: r.agent_name ?? "",
680
- profile: {
681
- avatar: avatarView(r.profile_avatar),
682
- updatedAt: r.profile_updated_at.toISOString(),
683
- },
684
- },
731
+ name: r.agent_name,
732
+ profile_avatar: r.profile_avatar,
733
+ profile_updated_at: r.profile_updated_at,
734
+ }),
685
735
  latestAt: r.latest_at,
686
736
  conversations: [],
687
737
  more: false,
@@ -18,10 +18,6 @@ export declare const PermissionContextSandboxSchema: z.ZodObject<{
18
18
  instance: "instance";
19
19
  operation: "operation";
20
20
  }>;
21
- location: z.ZodEnum<{
22
- cloud: "cloud";
23
- local: "local";
24
- }>;
25
21
  workingRoot: z.ZodString;
26
22
  network: z.ZodObject<{
27
23
  kind: z.ZodEnum<{
@@ -81,16 +77,15 @@ export declare const PermissionContextV2Schema: z.ZodObject<{
81
77
  reason: z.ZodString;
82
78
  }, z.core.$strict>], "state">;
83
79
  scope: z.ZodNullable<z.ZodObject<{
84
- location: z.ZodEnum<{
85
- cloud: "cloud";
86
- local: "local";
80
+ boundary: z.ZodEnum<{
81
+ instance: "instance";
82
+ operation: "operation";
87
83
  }>;
88
84
  workingRoot: z.ZodString;
89
85
  filesystem: z.ZodDiscriminatedUnion<[z.ZodObject<{
90
86
  kind: z.ZodLiteral<"device">;
91
87
  }, z.core.$strict>, z.ZodObject<{
92
88
  kind: z.ZodLiteral<"scoped">;
93
- readDirectories: z.ZodArray<z.ZodString>;
94
89
  writeDirectories: z.ZodArray<z.ZodString>;
95
90
  }, z.core.$strict>], "kind">;
96
91
  network: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -119,10 +114,6 @@ export declare const PermissionContextV2Schema: z.ZodObject<{
119
114
  instance: "instance";
120
115
  operation: "operation";
121
116
  }>;
122
- location: z.ZodEnum<{
123
- cloud: "cloud";
124
- local: "local";
125
- }>;
126
117
  workingRoot: z.ZodString;
127
118
  network: z.ZodObject<{
128
119
  kind: z.ZodEnum<{
@@ -150,7 +141,10 @@ export type PermissionContextV2 = z.infer<typeof PermissionContextV2Schema>;
150
141
  /**
151
142
  * Reads a recorded payload as version 2. Stored v1 rows exist on deployments and the log is never
152
143
  * rewritten: a v1 payload (`version: 1`, never a `sandbox` key) reads as v2 with `sandbox: null`,
153
- * which v2 accepts under exactly v1's rules. Anything else is left for the v2 schema to judge.
144
+ * which v2 accepts under exactly v1's rules. A payload recorded before device providers reported
145
+ * their boundary (a `location` of `local` / `cloud`, read roots in a scoped filesystem) reads with
146
+ * the boundary that location had (`operation` / `instance`) and without its read roots. Anything
147
+ * else is left for the v2 schema to judge.
154
148
  */
155
149
  export declare function upconvertPermissionContext(payload: unknown): unknown;
156
150
  /** A recorded `permission_context` payload as every reader parses it (v1 up-converted). */
@@ -185,16 +179,15 @@ export declare const RecordedPermissionContextSchema: z.ZodPreprocess<z.ZodObjec
185
179
  reason: z.ZodString;
186
180
  }, z.core.$strict>], "state">;
187
181
  scope: z.ZodNullable<z.ZodObject<{
188
- location: z.ZodEnum<{
189
- cloud: "cloud";
190
- local: "local";
182
+ boundary: z.ZodEnum<{
183
+ instance: "instance";
184
+ operation: "operation";
191
185
  }>;
192
186
  workingRoot: z.ZodString;
193
187
  filesystem: z.ZodDiscriminatedUnion<[z.ZodObject<{
194
188
  kind: z.ZodLiteral<"device">;
195
189
  }, z.core.$strict>, z.ZodObject<{
196
190
  kind: z.ZodLiteral<"scoped">;
197
- readDirectories: z.ZodArray<z.ZodString>;
198
191
  writeDirectories: z.ZodArray<z.ZodString>;
199
192
  }, z.core.$strict>], "kind">;
200
193
  network: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -223,10 +216,6 @@ export declare const RecordedPermissionContextSchema: z.ZodPreprocess<z.ZodObjec
223
216
  instance: "instance";
224
217
  operation: "operation";
225
218
  }>;
226
- location: z.ZodEnum<{
227
- cloud: "cloud";
228
- local: "local";
229
- }>;
230
219
  workingRoot: z.ZodString;
231
220
  network: z.ZodObject<{
232
221
  kind: z.ZodEnum<{
@@ -297,11 +286,10 @@ export declare const COMMAND_ASK_MAX_CHARS: number;
297
286
  * `commandHash` is the SHA-256 of the command text the approval holds in full, so an audit can
298
287
  * match a record to what ran.
299
288
  */
300
- export declare const PermissionExpansionSchema: z.ZodObject<{
301
- readDirectories: z.ZodArray<z.ZodString>;
289
+ export declare const PermissionExpansionSchema: z.ZodPreprocess<z.ZodObject<{
302
290
  writeDirectories: z.ZodArray<z.ZodString>;
303
291
  hosts: z.ZodArray<z.ZodString>;
304
- }, z.core.$strict>;
292
+ }, z.core.$strict>, unknown>;
305
293
  export declare const PermissionCallBindingSchema: z.ZodObject<{
306
294
  orgId: z.ZodString;
307
295
  rootConversationId: z.ZodString;
@@ -374,11 +362,10 @@ export declare const ReviewRecordSchema: z.ZodObject<{
374
362
  }, z.core.$strict>;
375
363
  /** The display-only `approval_requested.command` facts of a `command` ask (auto mode spec §5.4). */
376
364
  export declare const CommandAskSchema: z.ZodObject<{
377
- permissionScope: z.ZodOptional<z.ZodObject<{
378
- readDirectories: z.ZodArray<z.ZodString>;
365
+ permissionScope: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
379
366
  writeDirectories: z.ZodArray<z.ZodString>;
380
367
  hosts: z.ZodArray<z.ZodString>;
381
- }, z.core.$strict>>;
368
+ }, z.core.$strict>, unknown>>;
382
369
  targetPath: z.ZodOptional<z.ZodString>;
383
370
  candidateHash: z.ZodOptional<z.ZodString>;
384
371
  escalation: z.ZodOptional<z.ZodObject<{
@@ -706,16 +693,15 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
706
693
  reason: z.ZodString;
707
694
  }, z.core.$strict>], "state">;
708
695
  scope: z.ZodNullable<z.ZodObject<{
709
- location: z.ZodEnum<{
710
- cloud: "cloud";
711
- local: "local";
696
+ boundary: z.ZodEnum<{
697
+ instance: "instance";
698
+ operation: "operation";
712
699
  }>;
713
700
  workingRoot: z.ZodString;
714
701
  filesystem: z.ZodDiscriminatedUnion<[z.ZodObject<{
715
702
  kind: z.ZodLiteral<"device">;
716
703
  }, z.core.$strict>, z.ZodObject<{
717
704
  kind: z.ZodLiteral<"scoped">;
718
- readDirectories: z.ZodArray<z.ZodString>;
719
705
  writeDirectories: z.ZodArray<z.ZodString>;
720
706
  }, z.core.$strict>], "kind">;
721
707
  network: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -744,10 +730,6 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
744
730
  instance: "instance";
745
731
  operation: "operation";
746
732
  }>;
747
- location: z.ZodEnum<{
748
- cloud: "cloud";
749
- local: "local";
750
- }>;
751
733
  workingRoot: z.ZodString;
752
734
  network: z.ZodObject<{
753
735
  kind: z.ZodEnum<{
@@ -815,11 +797,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
815
797
  scopeRevision: z.ZodString;
816
798
  authorityRevision: z.ZodString;
817
799
  }, z.core.$strict>;
818
- permissionScope: z.ZodObject<{
819
- readDirectories: z.ZodArray<z.ZodString>;
800
+ permissionScope: z.ZodPreprocess<z.ZodObject<{
820
801
  writeDirectories: z.ZodArray<z.ZodString>;
821
802
  hosts: z.ZodArray<z.ZodString>;
822
- }, z.core.$strict>;
803
+ }, z.core.$strict>, unknown>;
823
804
  targetPath: z.ZodOptional<z.ZodString>;
824
805
  scopeKind: z.ZodEnum<{
825
806
  "directories-and-hosts": "directories-and-hosts";
@@ -1548,11 +1529,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1548
1529
  refs: z.ZodArray<z.ZodString>;
1549
1530
  }, z.core.$strip>>;
1550
1531
  command: z.ZodOptional<z.ZodObject<{
1551
- permissionScope: z.ZodOptional<z.ZodObject<{
1552
- readDirectories: z.ZodArray<z.ZodString>;
1532
+ permissionScope: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
1553
1533
  writeDirectories: z.ZodArray<z.ZodString>;
1554
1534
  hosts: z.ZodArray<z.ZodString>;
1555
- }, z.core.$strict>>;
1535
+ }, z.core.$strict>, unknown>>;
1556
1536
  targetPath: z.ZodOptional<z.ZodString>;
1557
1537
  candidateHash: z.ZodOptional<z.ZodString>;
1558
1538
  escalation: z.ZodOptional<z.ZodObject<{
@@ -55,16 +55,21 @@ const PermissionReason = z
55
55
  .max(1000)
56
56
  .refine((value) => value.trim().length > 0);
57
57
  const PermissionId = z.string().uuid();
58
+ /**
59
+ * The scope a recorded context reports. `boundary` is the device provider's (device-provider spec
60
+ * §6.7): `operation` runs every operation in its own restricted scope in the host environment,
61
+ * `instance` is a provisioned instance that is itself the sandbox. A scoped filesystem names its
62
+ * write roots only: what a sandboxed operation may read is the provider's rule.
63
+ */
58
64
  const PermissionScopeSchema = z
59
65
  .object({
60
- location: z.enum(["local", "cloud"]),
66
+ boundary: z.enum(["operation", "instance"]),
61
67
  workingRoot: PermissionPath,
62
68
  filesystem: z.discriminatedUnion("kind", [
63
69
  z.object({ kind: z.literal("device") }).strict(),
64
70
  z
65
71
  .object({
66
72
  kind: z.literal("scoped"),
67
- readDirectories: PermissionDirectories,
68
73
  writeDirectories: PermissionDirectories,
69
74
  })
70
75
  .strict(),
@@ -90,7 +95,6 @@ const PermissionScopeSchema = z
90
95
  export const PermissionContextSandboxSchema = z
91
96
  .object({
92
97
  boundary: z.enum(["operation", "instance"]),
93
- location: z.enum(["local", "cloud"]),
94
98
  workingRoot: z.string().min(1).max(4096),
95
99
  network: z
96
100
  .object({
@@ -205,35 +209,31 @@ export const PermissionContextV2Schema = z
205
209
  reject("A sandboxed context requires scoped filesystem and restricted networking");
206
210
  if (p.sandbox !== null) {
207
211
  const box = p.sandbox;
208
- if (box.location !== s.location || box.workingRoot !== s.workingRoot)
209
- reject("The sandbox must match the scope's location and working root");
212
+ if (box.boundary !== s.boundary || box.workingRoot !== s.workingRoot)
213
+ reject("The sandbox must match the scope's boundary and working root");
210
214
  if (canonicalOuter(box.outerNetwork) !== canonicalOuter(s.outerNetwork))
211
215
  reject("The sandbox must match the scope's outer network");
212
216
  // one canonical form: a scope without hosts is `none` in the block too
213
217
  const hosts = s.network.kind === "allowlist" ? s.network.hosts.length : 0;
214
218
  if (box.network.kind !== s.network.kind || box.network.hostsCount !== hosts)
215
219
  reject("The sandbox network must match the scope's network");
216
- if (box.boundary === "instance" && box.location !== "cloud")
217
- reject("An instance boundary is a cloud device's");
218
- // a cloud device has no outside: the provider's instance is the outermost boundary
219
- if (box.location === "cloud" && box.outsideSandbox)
220
- reject("A cloud device cannot run outside its sandbox");
220
+ // an instance boundary has no outside: the provider's instance is the outermost boundary
221
+ if (box.boundary === "instance" && box.outsideSandbox)
222
+ reject("An instance boundary cannot run outside its sandbox");
221
223
  }
222
224
  if (s.filesystem.kind === "scoped") {
223
- const { readDirectories, writeDirectories } = s.filesystem;
224
- if (!readDirectories.includes(s.workingRoot) ||
225
- !writeDirectories.includes(s.workingRoot) ||
226
- writeDirectories.some((p) => !readDirectories.includes(p)))
227
- reject("Writable roots must be readable and both must include the working root");
228
- if (new Set([...readDirectories, ...writeDirectories]).size > 64)
229
- reject("At most 64 combined roots are allowed");
225
+ const { writeDirectories } = s.filesystem;
226
+ if (!writeDirectories.includes(s.workingRoot))
227
+ reject("Writable roots must include the working root");
228
+ if (new Set(writeDirectories).size > 64)
229
+ reject("At most 64 roots are allowed");
230
230
  }
231
- if ((s.location === "local") !== (s.outerNetwork.kind === "host-environment"))
232
- reject("Outer boundary must match the device location");
231
+ if ((s.boundary === "operation") !== (s.outerNetwork.kind === "host-environment"))
232
+ reject("Outer boundary must match the provider's boundary");
233
233
  if (s.network.kind === "open-public" &&
234
234
  (s.outerNetwork.kind === "none" || s.outerNetwork.kind === "allowlist"))
235
235
  reject("An open network exceeds a disabled or allowlisted outer boundary");
236
- if (s.location === "cloud" && s.network.kind === "allowlist") {
236
+ if (s.boundary === "instance" && s.network.kind === "allowlist") {
237
237
  if (s.outerNetwork.kind === "none")
238
238
  reject("Network hosts exceed the disabled outer boundary");
239
239
  if (s.outerNetwork.kind === "allowlist") {
@@ -246,16 +246,35 @@ export const PermissionContextV2Schema = z
246
246
  /**
247
247
  * Reads a recorded payload as version 2. Stored v1 rows exist on deployments and the log is never
248
248
  * rewritten: a v1 payload (`version: 1`, never a `sandbox` key) reads as v2 with `sandbox: null`,
249
- * which v2 accepts under exactly v1's rules. Anything else is left for the v2 schema to judge.
249
+ * which v2 accepts under exactly v1's rules. A payload recorded before device providers reported
250
+ * their boundary (a `location` of `local` / `cloud`, read roots in a scoped filesystem) reads with
251
+ * the boundary that location had (`operation` / `instance`) and without its read roots. Anything
252
+ * else is left for the v2 schema to judge.
250
253
  */
251
254
  export function upconvertPermissionContext(payload) {
252
- if (typeof payload === "object" &&
253
- payload !== null &&
254
- !Array.isArray(payload) &&
255
- payload.version === 1 &&
256
- !Object.hasOwn(payload, "sandbox"))
257
- return { ...payload, version: 2, sandbox: null };
258
- return payload;
255
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload))
256
+ return payload;
257
+ let p = payload;
258
+ if (p.version === 1 && !Object.hasOwn(p, "sandbox"))
259
+ p = { ...p, version: 2, sandbox: null };
260
+ const boundaryOf = (location) => location === "local" ? "operation" : location === "cloud" ? "instance" : location;
261
+ const scope = p.scope;
262
+ if (scope && typeof scope === "object" && Object.hasOwn(scope, "location")) {
263
+ const { location, ...rest } = scope;
264
+ const fs = rest.filesystem;
265
+ let filesystem = fs;
266
+ if (fs && typeof fs === "object" && Object.hasOwn(fs, "readDirectories")) {
267
+ const { readDirectories: _reads, ...kept } = fs;
268
+ filesystem = kept;
269
+ }
270
+ p = { ...p, scope: { boundary: boundaryOf(location), ...rest, filesystem } };
271
+ }
272
+ const box = p.sandbox;
273
+ if (box && typeof box === "object" && Object.hasOwn(box, "location")) {
274
+ const { location: _location, ...kept } = box;
275
+ p = { ...p, sandbox: kept };
276
+ }
277
+ return p;
259
278
  }
260
279
  /** A recorded `permission_context` payload as every reader parses it (v1 up-converted). */
261
280
  export const RecordedPermissionContextSchema = z.preprocess(upconvertPermissionContext, PermissionContextV2Schema);
@@ -342,13 +361,20 @@ export const COMMAND_ASK_MAX_CHARS = 32 * 1024;
342
361
  * `commandHash` is the SHA-256 of the command text the approval holds in full, so an audit can
343
362
  * match a record to what ran.
344
363
  */
345
- export const PermissionExpansionSchema = z
364
+ export const PermissionExpansionSchema = z.preprocess(
365
+ // a scope recorded before read roots left the kernel (reads are the device provider's rule)
366
+ // carried `readDirectories`: read without it, as nothing grants a read any more
367
+ (value) => {
368
+ if (typeof value !== "object" || value === null || !Object.hasOwn(value, "readDirectories"))
369
+ return value;
370
+ const { readDirectories: _reads, ...rest } = value;
371
+ return rest;
372
+ }, z
346
373
  .object({
347
- readDirectories: z.array(z.string().max(4096)).max(64),
348
374
  writeDirectories: z.array(z.string().max(4096)).max(64),
349
375
  hosts: z.array(z.string().max(253)).max(100),
350
376
  })
351
- .strict();
377
+ .strict());
352
378
  export const PermissionCallBindingSchema = z
353
379
  .object({
354
380
  orgId: z.string(),
@@ -62,7 +62,12 @@ export declare class PermissionProfilesController {
62
62
  } | null;
63
63
  scopeRevision: string | null;
64
64
  outsideSandboxCeiling: boolean;
65
- broadProjectReach: boolean;
65
+ consentReach: {
66
+ outsideSandbox: boolean;
67
+ networkCeiling: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
68
+ networkMode: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
69
+ hostCeiling: import("../sandbox/device-sandbox.js").HostGrantCeiling;
70
+ } | null;
66
71
  sandbox: import("../sandbox/device-sandbox.js").DeviceSandbox | null;
67
72
  startingWorkNotice: string;
68
73
  }>;
@@ -78,13 +83,10 @@ export declare class PermissionProfilesController {
78
83
  outsideSandbox: boolean;
79
84
  networkCeiling: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
80
85
  networkMode: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
81
- restrictedProjectReach: "os-user" | "workspace";
82
86
  hostCeiling: import("../sandbox/device-sandbox.js").HostGrantCeiling;
83
87
  };
84
- location: "cloud" | "local";
85
88
  sandbox: import("../sandbox/device-sandbox.js").DeviceSandbox;
86
89
  outsideSandboxCeiling: boolean;
87
- broadProjectReach: boolean;
88
90
  availability: import("../sandbox/permission-availability.js").PermissionAvailability;
89
91
  }>;
90
92
  first(org: OrgContext, p: Principal, body: z.infer<typeof FirstMessageBody>, reply: FastifyReply): Promise<{
@@ -29,13 +29,10 @@ export declare class PermissionProfilesService {
29
29
  outsideSandbox: boolean;
30
30
  networkCeiling: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
31
31
  networkMode: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
32
- restrictedProjectReach: "os-user" | "workspace";
33
32
  hostCeiling: import("../sandbox/device-sandbox.js").HostGrantCeiling;
34
33
  };
35
- location: "cloud" | "local";
36
34
  sandbox: import("../sandbox/device-sandbox.js").DeviceSandbox;
37
35
  outsideSandboxCeiling: boolean;
38
- broadProjectReach: boolean;
39
36
  availability: import("../sandbox/permission-availability.js").PermissionAvailability;
40
37
  }>;
41
38
  get(orgId: string, id: string, accountId: string): Promise<{
@@ -50,7 +47,12 @@ export declare class PermissionProfilesService {
50
47
  } | null;
51
48
  scopeRevision: string | null;
52
49
  outsideSandboxCeiling: boolean;
53
- broadProjectReach: boolean;
50
+ consentReach: {
51
+ outsideSandbox: boolean;
52
+ networkCeiling: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
53
+ networkMode: "none" | import("../sandbox/device-sandbox.js").DeviceNetworkMode;
54
+ hostCeiling: import("../sandbox/device-sandbox.js").HostGrantCeiling;
55
+ } | null;
54
56
  sandbox: import("../sandbox/device-sandbox.js").DeviceSandbox | null;
55
57
  startingWorkNotice: string;
56
58
  }>;
@@ -1,6 +1,7 @@
1
1
  import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec } from "@capybara-hq/plugin-sdk";
2
2
  import type { Redis } from "ioredis";
3
3
  import { Kysely } from "kysely";
4
+ import type { DialInAccess } from "../dial-in/access.js";
4
5
  import { type RegisteredHook } from "../extensions/hooks.js";
5
6
  import { RegistrationLedger } from "../extensions/ledger.js";
6
7
  import type { LockService } from "../infra/lock/lock.service.js";
@@ -8,6 +9,7 @@ import type { ModelEmbeddings } from "../models/embeddings.js";
8
9
  import type { ModelImages } from "../models/images.js";
9
10
  import type { OrgRole } from "../orgs/roles.js";
10
11
  import type { HookRunner } from "../runtime/hook-calls.js";
12
+ import type { DeviceReports } from "../sandbox/device-reports.js";
11
13
  import type { ShareLiveness } from "../shares/liveness.js";
12
14
  import type { EmbedTokens } from "../ui/embed-token.js";
13
15
  import { type UiActionHandler, type UiRender } from "../ui/registry.js";
@@ -55,6 +57,18 @@ export interface KernelDeps {
55
57
  * in a test) verifies no share token (fail closed).
56
58
  */
57
59
  shares: Pick<ShareLiveness, "embedLive"> | undefined;
60
+ /**
61
+ * What `ctx.dialIn` is built from (`DialInAccess`): the relay and the check that a device is
62
+ * served by the calling extension. Absent (a ctx built alone in a test): `ctx.dialIn` calls
63
+ * reject.
64
+ */
65
+ dialIn?: Pick<DialInAccess, "serves" | "request" | "online" | "stop">;
66
+ /**
67
+ * What `ctx.devices` is built from (`DeviceReports`): `changed` reads a device's report again
68
+ * from the calling provider and refuses (`not-served`) a device bound to another one. Absent
69
+ * (a ctx built alone in a test): `ctx.devices` calls reject.
70
+ */
71
+ devices?: Pick<DeviceReports, "changed">;
58
72
  runWorkers: boolean;
59
73
  /** 内核 logger(`debug` 可选:插件 Logger 没有它,测试可不给)。 */
60
74
  log: Logger & {
@@ -180,7 +194,12 @@ export declare class LiveConfig {
180
194
  * (through `deps.net`, see `ctx/net.ts`);
181
195
  * - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
182
196
  * only with `permissions.models` (`embed` only its `embedding` purposes, `generateImage` only its
183
- * `image_generation` ones, through `deps.models`); `http.route`
197
+ * `image_generation` ones, through `deps.models`); `dialIn` only with `permissions.dialIn`, each
198
+ * call only for a device whose provider is this extension and that it serves in the device's org
199
+ * (through `deps.dialIn`; another device throws `ExtensionPermissionError`); `devices` only for
200
+ * an extension that provides `device-provider@1`, `reportChanged` only for a live device bound to
201
+ * this extension (through `deps.devices`; another device throws `ExtensionPermissionError`);
202
+ * `http.route`
184
203
  * only the method + path declared in `permissions.http` (the record carries the declared access and
185
204
  * its mount, see {@link Route}); `tools.register` only names declared in
186
205
  * `permissions.tools`; `ui.view` / `ui.action` only ids declared in `permissions.ui.views` or