@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38

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 (351) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -2
  3. package/dist/admin/admin.module.js +9 -5
  4. package/dist/admin/audit-log.service.d.ts +51 -0
  5. package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
  6. package/dist/admin/audit.controller.d.ts +18 -6
  7. package/dist/admin/audit.controller.js +36 -6
  8. package/dist/admin/audit.schemas.d.ts +9 -1
  9. package/dist/admin/audit.schemas.js +22 -2
  10. package/dist/admin/org-network.controller.d.ts +30 -0
  11. package/dist/admin/org-network.controller.js +77 -0
  12. package/dist/admin/org-network.schemas.d.ts +16 -0
  13. package/dist/admin/org-network.schemas.js +27 -0
  14. package/dist/admin/org-network.service.d.ts +41 -0
  15. package/dist/admin/org-network.service.js +101 -0
  16. package/dist/admin/outbox-dead.controller.d.ts +4 -6
  17. package/dist/admin/outbox-dead.controller.js +9 -6
  18. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  19. package/dist/admin/outbox-dead.schemas.js +25 -1
  20. package/dist/admin/outbox-dead.service.d.ts +16 -7
  21. package/dist/admin/outbox-dead.service.js +34 -10
  22. package/dist/admin/overview.service.d.ts +3 -3
  23. package/dist/admin/overview.service.js +0 -1
  24. package/dist/agents/agent-lookup.js +2 -10
  25. package/dist/agents/agents.service.js +9 -20
  26. package/dist/agents/definition.d.ts +3 -51
  27. package/dist/agents/definition.js +4 -254
  28. package/dist/agents/org-templates.js +2 -6
  29. package/dist/agents/readiness.controller.d.ts +4 -12
  30. package/dist/agents/readiness.controller.js +4 -12
  31. package/dist/agents/readiness.service.d.ts +23 -11
  32. package/dist/agents/readiness.service.js +31 -14
  33. package/dist/agents/templates.d.ts +0 -6
  34. package/dist/agents/templates.js +8 -34
  35. package/dist/background/store.d.ts +2 -0
  36. package/dist/background/store.js +3 -1
  37. package/dist/background/wake-rules.js +2 -1
  38. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  39. package/dist/catalog/admin-catalog.controller.js +1 -2
  40. package/dist/catalog/appearance.service.js +1 -3
  41. package/dist/catalog/catalog-content.d.ts +1 -1
  42. package/dist/catalog/catalog-content.js +1 -4
  43. package/dist/catalog/catalog-items.js +3 -3
  44. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  45. package/dist/catalog/catalog-scope.service.js +22 -73
  46. package/dist/catalog/cli.d.ts +0 -11
  47. package/dist/catalog/cli.js +0 -20
  48. package/dist/catalog/component-scope.service.js +0 -2
  49. package/dist/catalog/component-state.js +2 -2
  50. package/dist/catalog/install-status.d.ts +6 -0
  51. package/dist/catalog/install-status.js +6 -0
  52. package/dist/catalog/job-ids.d.ts +0 -4
  53. package/dist/catalog/job-ids.js +0 -4
  54. package/dist/catalog/marketplaces.service.d.ts +1 -1
  55. package/dist/catalog/org-catalog.service.d.ts +2 -0
  56. package/dist/catalog/org-catalog.service.js +8 -3
  57. package/dist/catalog/org-extension-switch.d.ts +7 -2
  58. package/dist/catalog/org-extension-switch.js +56 -9
  59. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  60. package/dist/catalog/org-plugin-uploads.js +9 -27
  61. package/dist/catalog/owned-items.js +1 -3
  62. package/dist/catalog/platform-import-update.js +1 -1
  63. package/dist/catalog/plugin-import.d.ts +15 -13
  64. package/dist/catalog/plugin-import.js +21 -30
  65. package/dist/catalog/plugin-install.d.ts +3 -43
  66. package/dist/catalog/plugin-install.js +8 -150
  67. package/dist/catalog/plugin-package.d.ts +5 -10
  68. package/dist/catalog/plugin-package.js +12 -33
  69. package/dist/catalog/plugin-upgrade.js +5 -4
  70. package/dist/catalog/scope-jobs.d.ts +34 -34
  71. package/dist/catalog/scope-jobs.js +50 -37
  72. package/dist/catalog/scope-orgs.d.ts +1 -1
  73. package/dist/catalog/scope-orgs.js +1 -2
  74. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  75. package/dist/catalog/scope-sync-workers.js +18 -6
  76. package/dist/catalog/scope-sync.d.ts +56 -59
  77. package/dist/catalog/scope-sync.js +96 -166
  78. package/dist/catalog/unshare.d.ts +3 -4
  79. package/dist/catalog/unshare.js +5 -8
  80. package/dist/channels/job-ids.d.ts +2 -6
  81. package/dist/channels/job-ids.js +2 -6
  82. package/dist/channels/outbound.d.ts +1 -1
  83. package/dist/channels/outbound.js +1 -1
  84. package/dist/channels/supervisor.d.ts +2 -3
  85. package/dist/channels/supervisor.js +2 -3
  86. package/dist/client/client-access.service.js +1 -1
  87. package/dist/config/env.js +19 -1
  88. package/dist/config/load.d.ts +0 -6
  89. package/dist/config/load.js +8 -27
  90. package/dist/config/schema.d.ts +54 -47
  91. package/dist/config/schema.js +198 -42
  92. package/dist/conversations/attachments.service.d.ts +10 -3
  93. package/dist/conversations/attachments.service.js +49 -16
  94. package/dist/conversations/conversations.controller.d.ts +0 -39
  95. package/dist/conversations/conversations.controller.js +0 -39
  96. package/dist/conversations/event-log.js +4 -1
  97. package/dist/conversations/events.d.ts +71 -46
  98. package/dist/conversations/events.js +124 -112
  99. package/dist/conversations/media-types.d.ts +25 -0
  100. package/dist/conversations/media-types.js +38 -0
  101. package/dist/conversations/queue.d.ts +3 -1
  102. package/dist/conversations/queue.service.js +9 -2
  103. package/dist/conversations/titles.js +6 -0
  104. package/dist/ctx/create-ctx.d.ts +8 -1
  105. package/dist/ctx/create-ctx.js +13 -3
  106. package/dist/ctx/net.d.ts +50 -0
  107. package/dist/ctx/net.js +67 -0
  108. package/dist/ctx/secrets.d.ts +24 -7
  109. package/dist/ctx/secrets.js +97 -30
  110. package/dist/db/kernel-schema.d.ts +27 -6
  111. package/dist/devices/devices.service.js +2 -1
  112. package/dist/errors.d.ts +10 -2
  113. package/dist/errors.js +10 -2
  114. package/dist/evals/reconstruct.d.ts +4 -17
  115. package/dist/evals/reconstruct.js +13 -53
  116. package/dist/evals/recorded-tools.d.ts +0 -27
  117. package/dist/evals/recorded-tools.js +2 -92
  118. package/dist/evals/run-replay.d.ts +1 -6
  119. package/dist/evals/run-replay.js +10 -17
  120. package/dist/evals/sets.service.d.ts +17 -5
  121. package/dist/evals/sets.service.js +33 -12
  122. package/dist/evals/snapshot.d.ts +1 -2
  123. package/dist/evals/snapshot.js +4 -17
  124. package/dist/extensions/admin-ops.d.ts +6 -1
  125. package/dist/extensions/admin-ops.js +17 -4
  126. package/dist/extensions/admin-view.d.ts +7 -4
  127. package/dist/extensions/admin-view.js +27 -21
  128. package/dist/extensions/bootstrap.js +0 -1
  129. package/dist/extensions/cli.js +0 -1
  130. package/dist/extensions/extensions.module.js +3 -0
  131. package/dist/extensions/host.d.ts +9 -4
  132. package/dist/extensions/host.js +14 -8
  133. package/dist/extensions/installs.d.ts +1 -3
  134. package/dist/extensions/instance.d.ts +0 -2
  135. package/dist/extensions/instance.js +0 -3
  136. package/dist/extensions/org-config.d.ts +4 -4
  137. package/dist/extensions/org-config.js +13 -22
  138. package/dist/extensions/package.d.ts +6 -6
  139. package/dist/extensions/package.js +3 -7
  140. package/dist/extensions/permission-view.d.ts +2 -4
  141. package/dist/extensions/plugin-items.d.ts +21 -1
  142. package/dist/extensions/plugin-items.js +28 -0
  143. package/dist/extensions/sync.js +5 -10
  144. package/dist/extensions/unavailable.js +0 -1
  145. package/dist/http/api.module.js +4 -1
  146. package/dist/identity/audit.d.ts +0 -12
  147. package/dist/identity/audit.js +0 -27
  148. package/dist/identity/auth.controller.js +5 -9
  149. package/dist/identity/cookies.d.ts +4 -9
  150. package/dist/identity/cookies.js +8 -32
  151. package/dist/identity/initial-passwords.d.ts +1 -1
  152. package/dist/identity/initial-passwords.js +1 -2
  153. package/dist/identity/sessions.d.ts +0 -6
  154. package/dist/identity/sessions.js +0 -18
  155. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  156. package/dist/inbox/platform-inbox.service.js +56 -6
  157. package/dist/index.d.ts +4 -2
  158. package/dist/index.js +4 -2
  159. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  160. package/dist/infra/cli/master-key-rewrap.js +24 -0
  161. package/dist/infra/config/kernel-config.service.js +0 -17
  162. package/dist/infra/database/transaction-host.d.ts +32 -1
  163. package/dist/infra/database/transaction-host.js +30 -4
  164. package/dist/infra/database/xact-lock.d.ts +16 -0
  165. package/dist/infra/database/xact-lock.js +28 -1
  166. package/dist/infra/health/health.controller.js +8 -0
  167. package/dist/infra/health/process-fault.d.ts +16 -0
  168. package/dist/infra/health/process-fault.js +49 -0
  169. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  170. package/dist/infra/lifecycle/process-guards.js +12 -3
  171. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  172. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  173. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  174. package/dist/infra/outbox/outbox.service.js +22 -26
  175. package/dist/infra/outbox/registry.d.ts +15 -7
  176. package/dist/infra/outbox/registry.js +39 -23
  177. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  178. package/dist/models/enablement.d.ts +5 -6
  179. package/dist/models/enablement.js +7 -14
  180. package/dist/net/public-address.d.ts +21 -1
  181. package/dist/net/public-address.js +56 -10
  182. package/dist/net/safe-fetch.d.ts +4 -1
  183. package/dist/net/safe-fetch.js +15 -4
  184. package/dist/orgs/directory-sync.js +2 -0
  185. package/dist/orgs/members.service.js +5 -0
  186. package/dist/orgs/network-allowances.service.d.ts +79 -0
  187. package/dist/orgs/network-allowances.service.js +371 -0
  188. package/dist/orgs/offboarding.d.ts +3 -1
  189. package/dist/orgs/offboarding.js +9 -2
  190. package/dist/orgs/org-lock.d.ts +28 -2
  191. package/dist/orgs/org-lock.js +59 -4
  192. package/dist/orgs/orgs.controller.d.ts +11 -2
  193. package/dist/orgs/orgs.controller.js +19 -3
  194. package/dist/orgs/orgs.module.d.ts +3 -2
  195. package/dist/orgs/orgs.module.js +6 -2
  196. package/dist/orgs/orgs.schemas.d.ts +12 -0
  197. package/dist/orgs/orgs.schemas.js +5 -0
  198. package/dist/orgs/orgs.service.js +6 -1
  199. package/dist/orgs/settings.controller.d.ts +3 -2
  200. package/dist/orgs/settings.service.d.ts +59 -14
  201. package/dist/orgs/settings.service.js +102 -20
  202. package/dist/overrides.d.ts +7 -7
  203. package/dist/overrides.js +4 -4
  204. package/dist/packages/tgz.d.ts +0 -2
  205. package/dist/packages/tgz.js +0 -2
  206. package/dist/platform/exclusions.js +0 -5
  207. package/dist/platform/operation.js +1 -1
  208. package/dist/platform/ops/admin.ops.d.ts +2 -2
  209. package/dist/platform/ops/admin.ops.js +9 -6
  210. package/dist/platform/ops/agents.ops.js +1 -1
  211. package/dist/platform/ops/connectors.ops.js +46 -1
  212. package/dist/platform/ops/evals.ops.js +1 -64
  213. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  214. package/dist/platform/ops/inbox.ops.js +16 -3
  215. package/dist/platform/ops/org-plugins.ops.js +1 -1
  216. package/dist/platform/ops/orgs.ops.d.ts +11 -3
  217. package/dist/platform/ops/orgs.ops.js +139 -5
  218. package/dist/platform/ops/outbox.ops.js +5 -5
  219. package/dist/platform/route-schemas.js +3 -0
  220. package/dist/roles/worker-role.d.ts +2 -3
  221. package/dist/roles/worker-role.js +3 -13
  222. package/dist/runtime/checkpointer.d.ts +3 -0
  223. package/dist/runtime/checkpointer.js +7 -4
  224. package/dist/runtime/context/build.d.ts +56 -18
  225. package/dist/runtime/context/build.js +143 -50
  226. package/dist/runtime/context/compaction.d.ts +1 -3
  227. package/dist/runtime/context/compaction.js +42 -8
  228. package/dist/runtime/context/run-context.js +1 -2
  229. package/dist/runtime/context/skills.d.ts +27 -56
  230. package/dist/runtime/context/skills.js +42 -114
  231. package/dist/runtime/context/tool-changes.d.ts +3 -3
  232. package/dist/runtime/context/tool-changes.js +6 -16
  233. package/dist/runtime/hook-calls.d.ts +6 -6
  234. package/dist/runtime/hook-calls.js +7 -7
  235. package/dist/runtime/langgraph-loop.js +9 -3
  236. package/dist/runtime/maintenance.d.ts +3 -11
  237. package/dist/runtime/maintenance.js +5 -20
  238. package/dist/runtime/model-call.d.ts +5 -0
  239. package/dist/runtime/model-call.js +48 -36
  240. package/dist/runtime/providers.d.ts +33 -35
  241. package/dist/runtime/providers.js +64 -109
  242. package/dist/runtime/run-context.service.js +7 -22
  243. package/dist/runtime/run-deletion.d.ts +6 -0
  244. package/dist/runtime/run-deletion.js +39 -16
  245. package/dist/runtime/run-execution.d.ts +56 -3
  246. package/dist/runtime/run-execution.js +81 -11
  247. package/dist/runtime/run-finish.js +2 -1
  248. package/dist/runtime/run-liveness.d.ts +11 -0
  249. package/dist/runtime/run-liveness.js +19 -0
  250. package/dist/runtime/run-orphan-check.job.js +2 -1
  251. package/dist/runtime/run-queue.js +8 -16
  252. package/dist/runtime/run-worker.d.ts +2 -2
  253. package/dist/runtime/run-worker.js +8 -6
  254. package/dist/runtime/step-log.d.ts +5 -0
  255. package/dist/runtime/step-log.js +9 -4
  256. package/dist/runtime/subagents/definition.d.ts +16 -20
  257. package/dist/runtime/subagents/definition.js +27 -27
  258. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  259. package/dist/runtime/subagents/dispatch.js +17 -3
  260. package/dist/runtime/subagents/org-agents.js +1 -2
  261. package/dist/runtime/subagents/preamble.d.ts +3 -2
  262. package/dist/runtime/subagents/preamble.js +3 -2
  263. package/dist/runtime/subagents/render.d.ts +1 -2
  264. package/dist/runtime/subagents/render.js +1 -2
  265. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  266. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  267. package/dist/runtime/subagents/template-skills.js +76 -0
  268. package/dist/runtime/waits.js +3 -1
  269. package/dist/schedules/effective-settings.d.ts +9 -3
  270. package/dist/schedules/effective-settings.js +5 -4
  271. package/dist/schedules/fire.js +11 -0
  272. package/dist/schedules/scheduled-tasks.service.js +5 -0
  273. package/dist/schedules/unattended.d.ts +2 -0
  274. package/dist/schedules/unattended.js +6 -1
  275. package/dist/skills/agent-skills.service.js +1 -2
  276. package/dist/skills/catalog.d.ts +1 -3
  277. package/dist/skills/catalog.js +1 -3
  278. package/dist/skills/conversation-catalog.d.ts +1 -2
  279. package/dist/skills/conversation-catalog.js +1 -2
  280. package/dist/skills/usable.js +2 -3
  281. package/dist/storage/storage.service.js +9 -1
  282. package/dist/tools/approvals.service.js +2 -4
  283. package/dist/tools/builtin-names.d.ts +2 -9
  284. package/dist/tools/builtin-names.js +4 -13
  285. package/dist/tools/builtins/sandbox/bash.js +3 -3
  286. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  287. package/dist/tools/builtins/sandbox/common.js +8 -115
  288. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  289. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  290. package/dist/tools/builtins/sandbox/glob.js +1 -3
  291. package/dist/tools/builtins/sandbox/grep.js +3 -5
  292. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  293. package/dist/tools/builtins/sandbox/index.js +10 -5
  294. package/dist/tools/builtins/sandbox/read.js +3 -2
  295. package/dist/tools/builtins/tool-search.d.ts +4 -7
  296. package/dist/tools/builtins/tool-search.js +6 -10
  297. package/dist/tools/connector-account-policies.d.ts +30 -3
  298. package/dist/tools/connector-account-policies.js +54 -7
  299. package/dist/tools/connector-content.js +1 -0
  300. package/dist/tools/connectors.controller.d.ts +24 -11
  301. package/dist/tools/connectors.controller.js +35 -6
  302. package/dist/tools/connectors.schemas.d.ts +14 -1
  303. package/dist/tools/connectors.schemas.js +14 -2
  304. package/dist/tools/connectors.service.d.ts +22 -0
  305. package/dist/tools/connectors.service.js +65 -6
  306. package/dist/tools/drift.d.ts +6 -2
  307. package/dist/tools/drift.js +10 -5
  308. package/dist/tools/git-push-policy.d.ts +4 -1
  309. package/dist/tools/git-push-policy.js +3 -1
  310. package/dist/tools/info.d.ts +1 -7
  311. package/dist/tools/info.js +5 -18
  312. package/dist/tools/job-ids.d.ts +0 -4
  313. package/dist/tools/job-ids.js +1 -6
  314. package/dist/tools/pipeline.d.ts +4 -10
  315. package/dist/tools/pipeline.js +17 -62
  316. package/dist/tools/policy.d.ts +6 -2
  317. package/dist/tools/policy.js +14 -12
  318. package/dist/tools/registry.js +1 -5
  319. package/dist/ui/views.d.ts +5 -5
  320. package/dist/ui/views.js +10 -16
  321. package/package.json +3 -3
  322. package/src/migrations/0137_audit_org_idx.sql +5 -0
  323. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  324. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  325. package/src/migrations/0140_retire_history_forms.sql +148 -0
  326. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  327. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  328. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  329. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  330. package/src/migrations/0145_org_network_allowances.sql +12 -0
  331. package/dist/admin/platform-audit.service.d.ts +0 -41
  332. package/dist/conversations/job-ids.d.ts +0 -6
  333. package/dist/conversations/job-ids.js +0 -6
  334. package/dist/extensions/job-ids.d.ts +0 -6
  335. package/dist/extensions/job-ids.js +0 -6
  336. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  337. package/dist/infra/queue/retired-schedulers.js +0 -9
  338. package/dist/orgs/job-ids.d.ts +0 -8
  339. package/dist/orgs/job-ids.js +0 -8
  340. package/dist/runtime/context/legacy-text.d.ts +0 -22
  341. package/dist/runtime/context/legacy-text.js +0 -37
  342. package/dist/runtime/job-ids.d.ts +0 -10
  343. package/dist/runtime/job-ids.js +0 -10
  344. package/dist/runtime/retired-schedulers.d.ts +0 -7
  345. package/dist/runtime/retired-schedulers.js +0 -31
  346. package/dist/storage/job-ids.d.ts +0 -6
  347. package/dist/storage/job-ids.js +0 -6
  348. package/dist/tools/legacy-data.d.ts +0 -34
  349. package/dist/tools/legacy-data.js +0 -76
  350. package/dist/tools/legacy-keys.d.ts +0 -51
  351. package/dist/tools/legacy-keys.js +0 -114
@@ -19,13 +19,13 @@ const RefMediaSourceSchema = z.object({
19
19
  attachmentId: AttachmentIdSchema,
20
20
  });
21
21
  /**
22
- * Who may decide an approval, as the approval row says (display only, absent in older logs): the
23
- * assigned account (`requestedFor`), else the escalation role (`approverRole`). Pages word the
24
- * waiting state with it ("等待 张三 批准") for viewers who cannot decide.
22
+ * Who may decide an approval, as the approval row says (display only): the assigned account
23
+ * (`requestedFor`), else the escalation role (`approverRole`). Pages word the waiting state with it
24
+ * ("Waiting for Alice to approve") for viewers who cannot decide.
25
25
  */
26
26
  const ApproverFields = {
27
- requestedFor: z.string().nullable().optional(),
28
- approverRole: z.enum(ORG_ROLES).nullable().optional(),
27
+ requestedFor: z.string().nullable(),
28
+ approverRole: z.enum(ORG_ROLES).nullable(),
29
29
  };
30
30
  /** The most hosts one network ask (and one `network_blocked` event) lists. */
31
31
  export const NETWORK_ASK_MAX_HOSTS = 20;
@@ -87,8 +87,6 @@ export const CommandAskSchema = z
87
87
  export const MEDIA_EXCLUDED_MAX_IDS = 50;
88
88
  /** 一份 `skills_catalog` 快照最多的技能数(组织技能引用上限 100,余量给 agent 自己的技能)。 */
89
89
  export const SKILLS_CATALOG_MAX = 1000;
90
- /** The longest pinned skill body in a `skills_catalog` snapshot (the pinned total is ≤ 32768 bytes). */
91
- export const PINNED_BODY_MAX_CHARS = 32768;
92
90
  /** 媒体块的名字:与 plugin-sdk `validateMediaBlock` 同规则(≤255 字符、不含控制字符)。 */
93
91
  const MediaNameSchema = z
94
92
  .string()
@@ -98,8 +96,18 @@ const ArtifactNameSchema = MediaNameSchema.min(1);
98
96
  /** 产物名(`artifact_created.name`)是否合法:与日志 schema 同一规则(非空、≤255、不含控制字符)。 */
99
97
  export const isValidArtifactName = (name) => ArtifactNameSchema.safeParse(name).success;
100
98
  /**
101
- * 日志里的内容块:plugin-sdk 的 `ContentBlock`,但 image / document 的 `source` 只能是 `ref`
102
- * (写入时用这个 schema 校验,带 `base64` 的块被拒绝)。
99
+ * A `file` block's media type: any non-empty `type/subtype` with no whitespace or control
100
+ * characters, the rule of plugin-sdk's `validateMediaBlock`.
101
+ */
102
+ const FileMediaTypeSchema = z
103
+ .string()
104
+ .regex(/^[^/\s]+\/[^/\s]+$/, "mediaType must be a non-empty type/subtype string")
105
+ .refine((s) => !hasControlChars(s), "mediaType must not contain control characters");
106
+ /** `size` on a media block: display metadata (the UI chip, the reference line), never sent. */
107
+ const MediaBlockSizeSchema = z.number().int().nonnegative().optional();
108
+ /**
109
+ * A content block as the log carries it: plugin-sdk's `ContentBlock`, but the source of an image,
110
+ * document or file block may only be a `ref` (blocks written with a `base64` source are rejected).
103
111
  */
104
112
  export const ContentBlockSchema = z.discriminatedUnion("type", [
105
113
  z.object({ type: z.literal("text"), text: z.string(), opaque: ProviderOpaqueSchema.optional() }),
@@ -126,12 +134,21 @@ export const ContentBlockSchema = z.discriminatedUnion("type", [
126
134
  mediaType: z.enum(IMAGE_MEDIA_TYPES),
127
135
  source: RefMediaSourceSchema,
128
136
  name: MediaNameSchema.optional(),
137
+ size: MediaBlockSizeSchema,
129
138
  }),
130
139
  z.object({
131
140
  type: z.literal("document"),
132
141
  mediaType: z.enum(DOCUMENT_MEDIA_TYPES),
133
142
  source: RefMediaSourceSchema,
134
143
  name: MediaNameSchema.optional(),
144
+ size: MediaBlockSizeSchema,
145
+ }),
146
+ z.object({
147
+ type: z.literal("file"),
148
+ mediaType: FileMediaTypeSchema,
149
+ source: RefMediaSourceSchema,
150
+ name: MediaNameSchema.optional(),
151
+ size: MediaBlockSizeSchema,
135
152
  }),
136
153
  ]);
137
154
  const STOP_REASONS = ["end_turn", "tool_use", "max_tokens", "refusal", "other"];
@@ -283,8 +300,8 @@ export const RunContextSchema = z.object({
283
300
  /**
284
301
  * The attribution a run's requests carry for git commits and pull requests it creates (spec
285
302
  * 2026-11-14-agent-attribution): the effective values fixed at run start (platform defaults or
286
- * the agent's override), so request building never reads config or the database. Absent in older
287
- * logs. An empty `commit` / `pr` turns that line off; `sessionUrl` is the resolved conversation
303
+ * the agent's override), so request building never reads config or the database. Absent when it
304
+ * did not change (as every field here). An empty `commit` / `pr` turns that line off; `sessionUrl` is the resolved conversation
288
305
  * link, or null.
289
306
  */
290
307
  attribution: z
@@ -312,21 +329,6 @@ export const PluginContextSchema = z.object({
312
329
  }),
313
330
  hash: z.string().regex(/^[0-9a-f]{64}$/),
314
331
  });
315
- /**
316
- * An agent definition frozen into a log (`subagent_started`): the current schema, with the
317
- * selected and pinned skills of older logs still accepted (skills default-on spec §4: history
318
- * keeps the old fields; new definitions never carry them).
319
- */
320
- const LoggedAgentDefinition = AgentDefinitionSchema.extend({
321
- skills: z
322
- .object({
323
- writePolicy: z.enum(["allow", "ask"]).optional(),
324
- orgSkills: z.array(z.string()).optional(),
325
- pinned: z.array(z.string()).optional(),
326
- })
327
- .strict()
328
- .optional(),
329
- });
330
332
  /**
331
333
  * 会话事件(`type` + `payload`)的判别联合。事件日志只追加,写入前用它校验 payload;
332
334
  * 读出时按写入时的形状原样返回。
@@ -345,8 +347,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
345
347
  authorAccountId: z.string(),
346
348
  /**
347
349
  * Who wrote the message, at send time (run context spec §3.2): display name and org role
348
- * only (never email or ids). Absent in older logs, on a sub-agent's task or `SendMessage`
349
- * message. Model-visible only through the sender line, written when the sender changes
350
+ * only (never email or ids). Absent on a sub-agent's task or `SendMessage` message. Model-visible only through the sender line, written when the sender changes
350
351
  * (`senderLines`, runtime/context/run-context.ts).
351
352
  */
352
353
  sender: MessageSenderSchema.optional(),
@@ -365,10 +366,15 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
365
366
  */
366
367
  retryOf: seqNo.optional(),
367
368
  /**
368
- * A person's skill invocation (`/name args`, phase D spec §4.3): which skill version was
369
- * rendered into `content[0]`, with the arguments as typed (trimmed). Not model-visible (the
370
- * rendered text is); the web renders the chip and the arguments from it. `name` is the
371
- * skill's bare name, `plugin` its catalog item; `agentType` is set for `mode: "fork"`.
369
+ * A skill invocation: which skill version was rendered into `content[0]`, with the
370
+ * arguments (trimmed). Not model-visible (the rendered text is). `name` is the skill's bare
371
+ * name, `plugin` its catalog item; `agentType` is set for `mode: "fork"`.
372
+ * - A person's (`/name args`, phase D spec §4.3): the arguments as typed; the web renders
373
+ * the chip and the arguments from it.
374
+ * - `template: true`: written by the kernel at a template sub-agent's dispatch, after its
375
+ * task, for each of the template's skills (`runtime/subagents/template-skills.ts`;
376
+ * `mode: "inline"`, no arguments, `authorAccountId` the person whose run dispatched it);
377
+ * nobody typed it: the web shows it with the task, never as a person's message.
372
378
  */
373
379
  skill: z
374
380
  .object({
@@ -380,8 +386,17 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
380
386
  arguments: z.string(),
381
387
  mode: z.enum(["inline", "fork"]),
382
388
  agentType: z.string().optional(),
389
+ template: z.literal(true).optional(),
383
390
  })
384
391
  .optional(),
392
+ /**
393
+ * The kernel's notice, written at a template sub-agent's dispatch in place of a template
394
+ * skill's invocation, that the skill (`name`) could not be read
395
+ * (`runtime/subagents/template-skills.ts`). Display only (the model sees the text): nobody
396
+ * typed it, so the web shows it with the task and eval case titles skip it, as a `template`
397
+ * invocation. It carries no `skill` record: nothing was rendered from a version.
398
+ */
399
+ templateSkillNotice: z.object({ name: z.string() }).optional(),
385
400
  /**
386
401
  * A scheduled task's message (scheduled tasks spec §6, §12): which task and tick posted it.
387
402
  * Not model-visible as such: request building renders only `taskName` and `localTime`, fixed
@@ -406,24 +421,13 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
406
421
  kind: z.enum(["task", "message"]).optional(),
407
422
  /**
408
423
  * A follow-up (`resume`, final review I1): the frozen and the current version's
409
- * turned-off tools and skills together (`narrowFollowUp`; older logs: the frozen org
410
- * skills intersected with the current ones); the child's run uses these instead of the
411
- * frozen ones.
412
- * Absent on a first dispatch and in older logs; logs from before tools were on by
413
- * default carry an enabled `tools` list instead of `disabledTools` (read as no tool
414
- * narrowing).
424
+ * turned-off tools and skills together (`narrowFollowUp`); the child's run uses these
425
+ * instead of the frozen ones. Absent on a first dispatch.
415
426
  */
416
427
  narrowed: z
417
428
  .object({
418
- disabledTools: z.array(DisabledToolRef).optional(),
419
- /**
420
- * Skills default-on (spec §6.1): the frozen and the current version's turned-off
421
- * skills together. Logs from before carry `skills` (`orgSkills` / `pinned`) instead.
422
- */
423
- disabledSkills: z.array(DisabledSkillRef).optional(),
424
- skills: z
425
- .object({ orgSkills: z.array(z.string()), pinned: z.array(z.string()).optional() })
426
- .optional(),
429
+ disabledTools: z.array(DisabledToolRef),
430
+ disabledSkills: z.array(DisabledSkillRef),
427
431
  })
428
432
  .optional(),
429
433
  })
@@ -470,52 +474,73 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
470
474
  provider: z.string(),
471
475
  model: z.string(),
472
476
  fallback: z.boolean(),
473
- request: z.object({
477
+ request: z
478
+ .object({
474
479
  fromSeq: seqNo,
475
480
  toSeq: seqNo,
476
481
  summarySeq: seqNo.nullable(),
477
482
  systemHash: z.string(),
478
483
  reminderSeqs: z.array(seqNo),
479
- /** 本次请求的输出上限(`min(模型上限, maxOutputTokens 旋钮 ?? runtime.maxOutputTokens)`)。较早的事件可能没有。 */
480
- maxOutputTokens: count.optional(),
481
484
  /**
482
- * 本次请求的模型参数(`ModelRequest.params`):agent 保存的参数按该模型声明 sanitize 后的结果
483
- * (已补默认值)。主模型尝试来自 `modelParams`,兜底尝试来自 `fallbackParams`。较早的事件可能没有。
485
+ * The request's output cap: `min(model cap, maxOutputTokens knob ??
486
+ * runtime.maxOutputTokens)`, clamped by the hard fit guard.
487
+ */
488
+ maxOutputTokens: count,
489
+ /**
490
+ * The request's model parameters (`ModelRequest.params`): the agent's saved parameters
491
+ * sanitized against the model's declarations (defaults filled in), from `modelParams` for
492
+ * the agent's model and `fallbackParams` for a fallback attempt.
484
493
  */
485
- params: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
486
- /** sanitize 时丢弃的参数键(未声明或值不再合法,如插件升级后);没有丢弃时不写。 */
494
+ params: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
495
+ /** Parameter keys sanitizing dropped (undeclared or no longer valid, e.g. after a plugin upgrade); absent when none were dropped. */
487
496
  droppedParams: z.array(z.string()).optional(),
488
497
  /**
489
- * 发出请求时的输入 token 估算(未校正)。与随后 `usage.inputTokens` 一起供下一次
490
- * `calibrate` 使用。较早的事件可能没有。
498
+ * The input token estimate (uncalibrated) when the request went out. With the later
499
+ * `usage.inputTokens` it feeds the next `calibrate`. The runtime always writes it; calls
500
+ * logged before it was recorded lack it, and no value would stand in for them (a made-up
501
+ * estimate would skew the calibration), so it stays optional and such a call calibrates
502
+ * nothing.
491
503
  */
492
504
  estimatedInputTokens: count.optional(),
493
505
  /**
494
- * 发出请求时 loop 已吸收到的 user_message seq(R31):seq 更大的 user_message 不进本次请求
495
- * (由后续步骤吸收或触发下一轮)。还原请求时据此放置 / 排除用户消息。较早的事件可能没有。
506
+ * The largest absorbable event seq the loop had taken in when the request went out (R31):
507
+ * absorbable events with a larger seq are not in this request (a later step takes them in
508
+ * or they start the next run). Reconstruction places and leaves out messages by it.
509
+ */
510
+ absorbedUpToSeq: seqNo,
511
+ /**
512
+ * The tools the request carried, in sending order (sorted by key without ToolSearch; with
513
+ * it, the builtin tools sorted by key, then the loaded tools in first-load order), with
514
+ * their definition fingerprints (`ResolvedTool.specHash`). Empty when the model has no
515
+ * tool support (see `toolsOmitted`).
496
516
  */
497
- absorbedUpToSeq: seqNo.optional(),
517
+ tools: z.array(z.object({ key: z.string(), specHash: z.string() })),
498
518
  /**
499
- * 本次请求带给模型的工具(按发送顺序:未启用 ToolSearch 时按 key 排序;启用时为内置工具按 key 排序,
500
- * 其后是已加载工具按首次加载顺序)及其定义指纹(`ResolvedTool.specHash`)。
501
- * 模型不支持工具时为空数组。较早的事件可能没有。
519
+ * The kernel left this step's tools out because the model has no tool support
520
+ * (`capabilities.tools` false while the step had tools): `tools` is empty and says nothing
521
+ * about the step's resolved set. Absent when the request carried the step's tools.
502
522
  */
503
- tools: z.array(z.object({ key: z.string(), specHash: z.string() })).optional(),
523
+ toolsOmitted: z.literal(true).optional(),
504
524
  /**
505
- * 启用 ToolSearch 时 system 第二块目录里的工具(按 key 排序)及定义指纹;定义同样存在
506
- * `capybara.tool_specs`,目录文本可由它们还原。未启用时不写。
525
+ * With ToolSearch on, the tools of the catalog in the system's second block (sorted by
526
+ * key) with their definition fingerprints; the definitions are in `capybara.tool_specs`
527
+ * too, so the catalog text can be rebuilt from them. Absent without ToolSearch.
507
528
  */
508
529
  catalog: z.array(z.object({ key: z.string(), specHash: z.string() })).optional(),
509
530
  /**
510
- * 本次请求的 `toolChoice`:收尾调用为 `"none"`(照常带工具,但不得调用);普通步骤不写(由模型决定)。
511
- * 定义本身按 specHash 存在 `capybara.tool_specs`。
531
+ * The request's `toolChoice`: `"none"` on the wrap-up call (tools carried as usual, but
532
+ * none may be called); absent on ordinary steps (the model decides). The definitions
533
+ * themselves are in `capybara.tool_specs` by specHash.
512
534
  */
513
535
  toolChoice: z.enum(["auto", "none"]).optional(),
514
536
  /**
515
- * 请求里每个附件的处理结果(Ruling M8,按首次出现,同一附件一条):发了字节(`bytes`,带 finalize 时的
516
- * etag)、内联文本、模型不支持的占位、因请求媒体预算省略(`omitted`)、图片太多(`too_many_images`)、
517
- * 单个超过供应商上限(`too_large`)、不再可用、PDF 页数太多、
518
- * 被 `media_excluded` 排除。没有媒体时不写;较早的事件没有。
537
+ * What became of each attachment in the request (Ruling M8, in first-seen order, one
538
+ * entry per attachment): bytes sent (`bytes`, with the etag at finalize), inline text, a
539
+ * reference line only (`reference`: a `file` block, or text over the inline cap), a
540
+ * placeholder for an unsupported kind, left out for the request's media budget
541
+ * (`omitted`), too many images (`too_many_images`), one over the provider's limit
542
+ * (`too_large`), no longer available, too many PDF pages, or excluded by
543
+ * `media_excluded`. Absent without media; written together with `mediaBudgetBytes`.
519
544
  */
520
545
  media: z
521
546
  .array(z.object({
@@ -523,6 +548,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
523
548
  outcome: z.enum([
524
549
  "bytes",
525
550
  "inline",
551
+ "reference",
526
552
  "placeholder_unsupported",
527
553
  "omitted",
528
554
  "too_many_images",
@@ -535,8 +561,9 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
535
561
  }))
536
562
  .optional(),
537
563
  /**
538
- * 本次请求的媒体字节预算(`attachments.requestMediaBytes`,见 planMedia):请求里有媒体时才写,
539
- * 还原时用它重现同样的省略结果。较早的事件没有。
564
+ * The request's media byte budget (`attachments.requestMediaBytes`, see planMedia):
565
+ * written only when the request has media (together with `media`); reconstruction uses
566
+ * it to repeat the same omissions.
540
567
  */
541
568
  mediaBudgetBytes: count.optional(),
542
569
  /**
@@ -553,6 +580,9 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
553
580
  truncated: z.array(z.object({ messageIndex: count, block: count, note: z.string() })),
554
581
  })
555
582
  .optional(),
583
+ })
584
+ .refine((r) => (r.media === undefined) === (r.mediaBudgetBytes === undefined), {
585
+ message: "media and mediaBudgetBytes are recorded together",
556
586
  }),
557
587
  })),
558
588
  ev("assistant_message", z.object({
@@ -579,7 +609,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
579
609
  /**
580
610
  * The chunk a chunked compaction call summarised (1-based), with the number of calls the
581
611
  * compaction attempted (the full chunk count on a completed one; on a failed or hook-denied
582
- * run only the calls that were made). Absent on a single-call compaction: older logs have none.
612
+ * run only the calls that were made). Absent on a single-call compaction.
583
613
  */
584
614
  chunk: count.optional(),
585
615
  chunks: count.optional(),
@@ -771,7 +801,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
771
801
  approvalId: z.string(),
772
802
  toolKey: z.string(),
773
803
  expiresAt: z.string(),
774
- /** Which rule asked (UI refresh B; display only, absent in older logs). */
804
+ /** Which rule asked a tool approval (UI refresh B; display only; absent on the other asks). */
775
805
  policy: z.enum(["agent", "connector", "default", "role", "org", "fixed"]).optional(),
776
806
  /**
777
807
  * A network ask (network ask-to-allow spec §6.1): the hosts the device owner is asked to
@@ -904,21 +934,6 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
904
934
  nameOnly: z.literal(true).optional(),
905
935
  }))
906
936
  .max(SKILLS_CATALOG_MAX),
907
- /**
908
- * Pinned skills (phase B, spec §9.1) in the agent's order: each a skill of `skills` (same
909
- * id, version and source) with its SKILL.md body as read at run start or written by
910
- * a skill registration. Absent means none (every snapshot before phase B).
911
- */
912
- pinned: z
913
- .array(z.object({
914
- id: z.string().min(1).max(100),
915
- version: z.number().int().positive(),
916
- name: z.string().refine(isSkillName, "invalid skill name"),
917
- source: z.string().min(1).max(512),
918
- body: z.string().max(PINNED_BODY_MAX_CHARS),
919
- }))
920
- .max(3)
921
- .optional(),
922
937
  /**
923
938
  * The Claude Code tool-name map text (`CLAUDE_CODE_TOOL_MAP`), present iff a skill in
924
939
  * `skills` came from a Claude Code plugin.
@@ -993,7 +1008,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
993
1008
  /**
994
1009
  * Plugin scope phase 2: the platform template whose content a `plugin` child ran (a
995
1010
  * platform template, or an org copy linked to one, recorded under the copy's `id`). Absent
996
- * = the org's own template (and in every older event). Eval metadata, not model-visible.
1011
+ * = the org's own template. Eval metadata, not model-visible.
997
1012
  */
998
1013
  platformTemplateId: z.string().optional(),
999
1014
  /**
@@ -1004,14 +1019,12 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1004
1019
  .object({ id: z.string(), version: z.number().int(), name: z.string() })
1005
1020
  .optional(),
1006
1021
  }),
1022
+ /** The effective (narrowed) definition, frozen at dispatch. */
1023
+ definition: AgentDefinitionSchema,
1007
1024
  /**
1008
- * The effective (narrowed) definition, frozen at dispatch. Logs from before skills were on
1009
- * by default also carry `skills.orgSkills` / `skills.pinned` (skills default-on spec §4).
1010
- */
1011
- definition: LoggedAgentDefinition,
1012
- /**
1013
- * `SUBAGENT_PREAMBLE` at dispatch time; since skills were on by default, followed by the line
1014
- * naming a template's skills the child loads first (skills default-on spec §6.1).
1025
+ * `SUBAGENT_PREAMBLE` at dispatch time. Children dispatched between skills default-on and
1026
+ * template skills written as invocations end it with the line naming a template's skills
1027
+ * the child loads first (`Before you start, load these skills with Skill: …`).
1015
1028
  */
1016
1029
  preamble: z.string(),
1017
1030
  /** The child's step limit; 0 = no limit (`runtime.maxSteps` 0, no template limit). */
@@ -1054,8 +1067,9 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1054
1067
  questionId: z.string().optional(),
1055
1068
  toolKey: z.string(),
1056
1069
  expiresAt: z.string().optional(),
1057
- /** An approval's approver (`kind: "approval"`), as in `approval_requested`. */
1058
- ...ApproverFields,
1070
+ /** An approval's approver (`kind: "approval"` only), as in `approval_requested`. */
1071
+ requestedFor: ApproverFields.requestedFor.optional(),
1072
+ approverRole: ApproverFields.approverRole.optional(),
1059
1073
  })),
1060
1074
  /** Parent log: a sub-agent's run ended. Not model-visible (its reply is the call's tool_result). */
1061
1075
  ev("subagent_finished", z.object({
@@ -1074,8 +1088,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1074
1088
  * `childRunId` finished. **Model-visible**: absorbed like an interjection and rendered as a system
1075
1089
  * message (`renderSubagentDelivery`). A finish after a handback carries `text: ""` and
1076
1090
  * `handedBack: true` and renders as one status line, except that a run that handed back and
1077
- * `completed` writes no finished delivery at all (acceptance 2026-11-07; older logs have one and
1078
- * keep rendering it); a finish without a handback carries the child's
1091
+ * `completed` writes no finished delivery at all (acceptance 2026-11-07); a finish without a handback carries the child's
1079
1092
  * final reply, a failed finish its error message (`errorCode` the code), an aborted one no text
1080
1093
  * (`abortedBy` who stopped it), with `subagent_finished`'s vocabulary. `status` is present exactly
1081
1094
  * on `kind: "finished"`. `triggerAccountId`: the child run's trigger account, the one a wake runs
@@ -1150,29 +1163,28 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1150
1163
  text: z.string(),
1151
1164
  /**
1152
1165
  * The estimated transcript input minus the stored summary output (context compaction spec
1153
- * §4.9), so the UI needs no chunked usage to show what compaction saved. Optional: older
1154
- * logs have none.
1166
+ * §4.9), so the UI needs no chunked usage to show what compaction saved.
1155
1167
  */
1156
- savedTokens: count.optional(),
1168
+ savedTokens: count,
1157
1169
  /**
1158
1170
  * The user messages that started the run being compacted, when the summary covers them
1159
1171
  * (context compaction spec §4.2, revision 2026-11-15), in seq order: request building
1160
1172
  * re-renders exactly these after the summary text. Decided when the summary is written, so a
1161
- * request never depends on later events. Optional: older logs (and summaries that cover no
1162
- * opening message) have none and re-render nothing.
1173
+ * request never depends on later events. Absent when the summary covers no opening message
1174
+ * (nothing re-rendered).
1163
1175
  */
1164
1176
  openingSeqs: z.array(seqNo).optional(),
1165
1177
  /**
1166
1178
  * The step the compaction ran in (0 for a manual compact run), so a later compaction in the
1167
- * same step takes the next idempotency key. Optional: older logs have none.
1179
+ * same step takes the next idempotency key.
1168
1180
  */
1169
- step: count.optional(),
1181
+ step: count,
1170
1182
  })),
1171
1183
  ev("compaction_failed", z.object({
1172
1184
  attempt: count,
1173
1185
  reason: z.string(),
1174
- /** The step the compaction ran in, as on `compaction_summary`. Optional: older logs. */
1175
- step: count.optional(),
1186
+ /** The step the compaction ran in, as on `compaction_summary`. */
1187
+ step: count,
1176
1188
  })),
1177
1189
  ev("run_finished", z.object({
1178
1190
  /** `budget`: a sub-agent stopped at its parent run's token cap (phase C, spec §8.3). */
@@ -1183,7 +1195,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1183
1195
  ev("run_aborted", z.object({
1184
1196
  byAccountId: z.string().nullable(),
1185
1197
  /** `eval_stopped`:评测整轮回放被评测运行停下(只出现在 `kind = 'eval'` 的对话里),原因见 `detail`。 */
1186
- reason: z.enum(["user", "shutdown_exhausted", "eval_stopped"]),
1198
+ reason: z.enum(["user", "shutdown_exhausted", "eval_stopped", "org_deleted"]),
1187
1199
  /**
1188
1200
  * Why an eval replay stopped (`eval_stopped`), or `wait_timeout`: a sub-agent run stopped
1189
1201
  * (`user`, no account) because its parent's sub-agents wait timed out (phase C).
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Whether a chat attachment with this content type becomes an `image` block: one of the four image
3
+ * types a model can view.
4
+ */
5
+ export declare function isImageContentType(ct: string): boolean;
6
+ /**
7
+ * Whether the model can consume the content itself, so the attachment becomes an `image` or
8
+ * `document` block: the image types, a PDF, and the text types (inlined, or sent as a document).
9
+ * Every other accepted type is a `file` attachment the model only ever gets a reference to.
10
+ */
11
+ export declare function isMediaContentType(ct: string): boolean;
12
+ /**
13
+ * The extension of a file name, lower case and without the dot: `null` when it has none or when the
14
+ * suffix is not an extension-shaped word (`a.`, `a.verylongsuffix`).
15
+ */
16
+ export declare function attachmentExtension(name: string): string | null;
17
+ /**
18
+ * Whether a chat upload is accepted: its declared content type, or else the extension of its file
19
+ * name (`attachments.allowedExtensions`, for source files and office documents whose content types
20
+ * disagree across browsers and systems). The web applies the same rule before uploading.
21
+ */
22
+ export declare function acceptedContent(cfg: {
23
+ allowedTypes: readonly string[];
24
+ allowedExtensions: readonly string[];
25
+ }, name: string, contentType: string): boolean;
@@ -0,0 +1,38 @@
1
+ import { DOCUMENT_MEDIA_TYPES, IMAGE_MEDIA_TYPES } from "@capybara-hq/plugin-sdk";
2
+ /**
3
+ * Whether a chat attachment with this content type becomes an `image` block: one of the four image
4
+ * types a model can view.
5
+ */
6
+ export function isImageContentType(ct) {
7
+ return IMAGE_MEDIA_TYPES.includes(ct);
8
+ }
9
+ /**
10
+ * Whether the model can consume the content itself, so the attachment becomes an `image` or
11
+ * `document` block: the image types, a PDF, and the text types (inlined, or sent as a document).
12
+ * Every other accepted type is a `file` attachment the model only ever gets a reference to.
13
+ */
14
+ export function isMediaContentType(ct) {
15
+ return isImageContentType(ct) || DOCUMENT_MEDIA_TYPES.includes(ct);
16
+ }
17
+ /**
18
+ * The extension of a file name, lower case and without the dot: `null` when it has none or when the
19
+ * suffix is not an extension-shaped word (`a.`, `a.verylongsuffix`).
20
+ */
21
+ export function attachmentExtension(name) {
22
+ const dot = name.lastIndexOf(".");
23
+ if (dot <= 0 || dot === name.length - 1)
24
+ return null;
25
+ const ext = name.slice(dot + 1).toLowerCase();
26
+ return /^[a-z0-9]{1,12}$/.test(ext) ? ext : null;
27
+ }
28
+ /**
29
+ * Whether a chat upload is accepted: its declared content type, or else the extension of its file
30
+ * name (`attachments.allowedExtensions`, for source files and office documents whose content types
31
+ * disagree across browsers and systems). The web applies the same rule before uploading.
32
+ */
33
+ export function acceptedContent(cfg, name, contentType) {
34
+ if (cfg.allowedTypes.includes(contentType))
35
+ return true;
36
+ const ext = attachmentExtension(name);
37
+ return ext !== null && cfg.allowedExtensions.includes(ext);
38
+ }
@@ -73,8 +73,10 @@ export interface QueuedFile {
73
73
  attachmentId: string;
74
74
  name: string;
75
75
  mediaType: string;
76
+ /** The attachment's size in bytes when the block carries it (the chip shows it). */
77
+ size?: number;
76
78
  }
77
- /** What `POST …/queue` takes (the message fields that can be queued). */
79
+ /** A queued message's fields (leftover items; tests seed them through the service). */
78
80
  export interface QueueInput {
79
81
  text: string;
80
82
  clientMessageId: string;
@@ -135,8 +135,15 @@ let ConversationQueue = class ConversationQueue {
135
135
  if (Number(n) >= QUEUE_MAX_ITEMS)
136
136
  throw queueFull();
137
137
  const blocks = await this.conversations.bindIn(orgId, conversationId, accountId, files);
138
- const fileMeta = blocks.flatMap((b) => (b.type === "image" || b.type === "document") && b.source.kind === "ref"
139
- ? [{ attachmentId: b.source.attachmentId, name: b.name ?? "", mediaType: b.mediaType }]
138
+ const fileMeta = blocks.flatMap((b) => (b.type === "image" || b.type === "document" || b.type === "file") && b.source.kind === "ref"
139
+ ? [
140
+ {
141
+ attachmentId: b.source.attachmentId,
142
+ name: b.name ?? "",
143
+ mediaType: b.mediaType,
144
+ ...(b.size !== undefined && { size: b.size }),
145
+ },
146
+ ]
140
147
  : []);
141
148
  const row = await t
142
149
  .insertInto("conversation_queue")
@@ -506,6 +506,12 @@ let TitleQueue = class TitleQueue {
506
506
  const attempt = await titleAttemptDue(this.kdb.db, conversationId);
507
507
  if (attempt === null)
508
508
  return;
509
+ // The previous attempt claims its number before calling the model, so a run completing
510
+ // while that call is in flight would see the next attempt due and pay for a second title
511
+ // call. Its job stays in the shared queue until it finishes (removeOnComplete/Fail): wait
512
+ // for it; if it fails, the next completed run enqueues the next attempt.
513
+ if (attempt > 0 && (await this.queue.getJob(titleJobId(conversationId, attempt - 1))))
514
+ return;
509
515
  await this.queue.add(JOB, { conversationId, attempt }, {
510
516
  jobId: titleJobId(conversationId, attempt),
511
517
  attempts: 1,
@@ -10,6 +10,7 @@ import type { HookRunner } from "../runtime/hook-calls.js";
10
10
  import type { EmbedTokens } from "../ui/embed-token.js";
11
11
  import { type UiActionHandler, type UiRender } from "../ui/registry.js";
12
12
  import { type BusSubscriber } from "./bus.js";
13
+ import { type ExtensionNetServices } from "./net.js";
13
14
  import { type Keyring } from "./secrets.js";
14
15
  /** 内核提供给插件宿主的共享依赖。 */
15
16
  export interface KernelDeps {
@@ -30,6 +31,11 @@ export interface KernelDeps {
30
31
  * test): `ctx.models` calls reject.
31
32
  */
32
33
  models?: Pick<ModelEmbeddings, "embed" | "describe">;
34
+ /**
35
+ * What `ctx.net` reads per call: the kernel config (`net.*`) and the org network allowances.
36
+ * Absent (a ctx built alone in a test): `ctx.net.fetch` rejects every request.
37
+ */
38
+ net?: ExtensionNetServices;
33
39
  /**
34
40
  * The host's hook registry: `ctx.models.embed` fires `model.request` through it (spec B §5.4).
35
41
  * A required key, so no builder leaves policy hooks out by omission (fail closed by
@@ -157,7 +163,8 @@ export declare class LiveConfig {
157
163
  * registered routes, provided extension points and a close function.
158
164
  * `deploymentConfig` may be a {@link LiveConfig} (shared by the instance, replaceable in place);
159
165
  * otherwise a fixed value is wrapped.
160
- * - Granted automatically: `kv`, `lock`, `bus`, `queue`, `log`, `db`, `config`, `provide`;
166
+ * - Granted automatically: `kv`, `lock`, `bus`, `queue`, `log`, `db`, `config`, `provide`, `net`
167
+ * (through `deps.net`, see `ctx/net.ts`);
161
168
  * - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
162
169
  * only with `permissions.models` (and only its `embedding` purposes, through `deps.models`); `http.route`
163
170
  * only the method + path declared in `permissions.http` (the record carries the declared access and
@@ -11,6 +11,7 @@ import { canUseSlot, orgUiTopic, PLATFORM_UI_TOPIC, PluginUiRegistration, } from
11
11
  import { createBus } from "./bus.js";
12
12
  import { createKv } from "./kv.js";
13
13
  import { createLock } from "./lock.js";
14
+ import { createExtensionNet } from "./net.js";
14
15
  import { createQueue } from "./queue.js";
15
16
  import { createSecrets } from "./secrets.js";
16
17
  /**
@@ -180,7 +181,8 @@ export class LiveConfig {
180
181
  * registered routes, provided extension points and a close function.
181
182
  * `deploymentConfig` may be a {@link LiveConfig} (shared by the instance, replaceable in place);
182
183
  * otherwise a fixed value is wrapped.
183
- * - Granted automatically: `kv`, `lock`, `bus`, `queue`, `log`, `db`, `config`, `provide`;
184
+ * - Granted automatically: `kv`, `lock`, `bus`, `queue`, `log`, `db`, `config`, `provide`, `net`
185
+ * (through `deps.net`, see `ctx/net.ts`);
184
186
  * - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
185
187
  * only with `permissions.models` (and only its `embedding` purposes, through `deps.models`); `http.route`
186
188
  * only the method + path declared in `permissions.http` (the record carries the declared access and
@@ -399,6 +401,15 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
399
401
  },
400
402
  },
401
403
  extensionPoints,
404
+ // the kernel's guarded client for person-supplied URLs, no permission needed; without the
405
+ // services (a ctx built alone in a test) it refuses rather than reaching the network unguarded
406
+ net: deps.net
407
+ ? createExtensionNet({ ...deps.net, log: deps.log, plugin: name, signal: lifecycle.signal })
408
+ : {
409
+ async fetch() {
410
+ throw new Error(`plugin ${name}: ctx.net is not available`);
411
+ },
412
+ },
402
413
  bus: {
403
414
  publish: bus.publish,
404
415
  async subscribe(topic, handler) {
@@ -705,8 +716,7 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
705
716
  /**
706
717
  * A `file-preview@1` provider must be valid when it is provided (setup fails otherwise): the shape
707
718
  * ({@link validateFilePreviewProvider}), and every `embed` names a ui contribution of this extension
708
- * with `kind: "embed"` that resolved to the slot `file.preview` (from `slot` or the deprecated
709
- * `place`). A previewer whose embed names an embed contribution dropped at load (unknown slot or
719
+ * with `kind: "embed"` that resolved to the slot `file.preview`. A previewer whose embed names an embed contribution dropped at load (unknown slot or
710
720
  * slot version, UI slots spec §3.2) is left out instead, with one warn per load: the returned
711
721
  * provider is what the kernel serves.
712
722
  */