@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
@@ -9,6 +9,9 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
9
9
  * 之后最新一份仍能独立还原。不要配合实验性的 `DeltaChannel` 使用:它依赖父链上的 writes 还原状态。
10
10
  * - thread_id 约定为 runId。
11
11
  * - 所有状态都在 PG 里,不持有进程内状态,任意副本都能续跑。
12
+ * - Writes are run loop hot-path writes: they ask the run fence for shared admission
13
+ * (`RunExecution`) and lock only the run's own checkpoint rows. LangGraph calls them between
14
+ * nodes, outside any transaction (never nested in a fenced one).
12
15
  */
13
16
  export declare class KyselyCheckpointSaver extends BaseCheckpointSaver {
14
17
  private readonly kdb;
@@ -32,6 +32,9 @@ const idC = sql `checkpoint_id collate "C"`;
32
32
  * 之后最新一份仍能独立还原。不要配合实验性的 `DeltaChannel` 使用:它依赖父链上的 writes 还原状态。
33
33
  * - thread_id 约定为 runId。
34
34
  * - 所有状态都在 PG 里,不持有进程内状态,任意副本都能续跑。
35
+ * - Writes are run loop hot-path writes: they ask the run fence for shared admission
36
+ * (`RunExecution`) and lock only the run's own checkpoint rows. LangGraph calls them between
37
+ * nodes, outside any transaction (never nested in a fenced one).
35
38
  */
36
39
  let KyselyCheckpointSaver = class KyselyCheckpointSaver extends BaseCheckpointSaver {
37
40
  kdb;
@@ -259,16 +262,16 @@ let KyselyCheckpointSaver = class KyselyCheckpointSaver extends BaseCheckpointSa
259
262
  }
260
263
  };
261
264
  __decorate([
262
- Transactional({ propagation: "requires_new" })
265
+ Transactional({ propagation: "requires_new", admission: "shared" })
263
266
  ], KyselyCheckpointSaver.prototype, "put", null);
264
267
  __decorate([
265
- Transactional({ propagation: "requires_new" })
268
+ Transactional({ propagation: "requires_new", admission: "shared" })
266
269
  ], KyselyCheckpointSaver.prototype, "insertWrites", null);
267
270
  __decorate([
268
- Transactional({ propagation: "requires_new" })
271
+ Transactional({ propagation: "requires_new", admission: "shared" })
269
272
  ], KyselyCheckpointSaver.prototype, "deleteThread", null);
270
273
  __decorate([
271
- Transactional({ propagation: "requires_new" })
274
+ Transactional({ propagation: "requires_new", admission: "shared" })
272
275
  ], KyselyCheckpointSaver.prototype, "pruneToLatest", null);
273
276
  KyselyCheckpointSaver = __decorate([
274
277
  Injectable(),
@@ -36,6 +36,11 @@ export interface ModelCallMeta {
36
36
  key: string;
37
37
  specHash: string;
38
38
  }[];
39
+ /**
40
+ * The step's tools were left out because the model has no tool support (set by
41
+ * `assembleModelRequest`); absent when the request carried them.
42
+ */
43
+ toolsOmitted?: true;
39
44
  /** 请求的 `toolChoice`(收尾调用为 `"none"`);未设置则没有该字段。 */
40
45
  toolChoice?: "auto" | "none";
41
46
  /**
@@ -54,14 +59,18 @@ export interface BuildModelRequestInput {
54
59
  model: ModelInfo;
55
60
  step: number;
56
61
  /**
57
- * loop 已吸收到的位置(R31):the largest seq of the absorbable events (`user_message`,
58
- * `background_task_finished` and `subagent_delivery`, {@link isAbsorbable}) the loop took. 提供时:
59
- * - seq 大于它的可吸收事件不进请求(运行中途到达、尚未被吸收的插话或后台任务结束,由后续步骤吸收或触发下一轮);
60
- * - 每个可吸收事件放在**吸收它的那次模型调用**的位置:日志里第一个 `request.absorbedUpToSeq`
61
- * 不小于它的 `model_call` 之前(没有该字段的旧 model_call 视为吸收了它之前的全部消息),
62
- * 本次请求吸收的放在末尾。于是模型看到的历史只追加(插话不会插到已发送的回复之前),
63
- * 且请求可由日志 + `model_call` 精确还原。
64
- * 不提供时按 seq 原样回放全部可吸收事件。
62
+ * How far the loop has absorbed (R31): the largest seq of the absorbable events (`user_message`,
63
+ * `background_task_finished` and `subagent_delivery`, {@link isAbsorbable}) the loop took. When
64
+ * given:
65
+ * - absorbable events with a larger seq stay out of the request (an interjection or a finished
66
+ * background task that arrived mid-run and is not absorbed yet; a later step absorbs it or it
67
+ * starts the next run);
68
+ * - each absorbable event sits where **the model call that absorbed it** is: before the first
69
+ * `model_call` in the log whose `request.absorbedUpToSeq` is not smaller than its seq, and
70
+ * the ones this request absorbs go at the end. So the history the model sees is append-only
71
+ * (an interjection never lands before a reply already sent) and the request can be rebuilt
72
+ * exactly from the log + `model_call`.
73
+ * When absent, every absorbable event is replayed in seq order.
65
74
  */
66
75
  absorbedUpToSeq?: number;
67
76
  /**
@@ -113,12 +122,20 @@ export interface MediaInfo {
113
122
  pages: number | null;
114
123
  /** finalize 时记下的对象 etag(记进 `model_call` 的媒体结果,便于核对还原);提供方不给为 null / 缺省。 */
115
124
  etag?: string | null;
125
+ /**
126
+ * 对象在此存储里的无签名引用(`s3://<bucket>/<key>`,见 `ObjectStore.uri`):写进引用行,让模型能把
127
+ * 文件交给 `FetchAttachment`。存储没有 URI 概念时是 `capybara://attachments/<id>`。
128
+ */
129
+ uri: string;
116
130
  }
117
- /** `text/*` 附件(内联文本与 base64 文档两种方式都一样)的最大字符数(UTF-16 码元,超出截断并注明)。 */
118
- export declare const TEXT_INLINE_MAX_CHARS = 50000;
119
131
  /**
120
- * `text/*` 附件最多取的字节数:UTF-8 里一个 UTF-16 码元最多 3 字节,取这么多一定够凑满
121
- * {@link TEXT_INLINE_MAX_CHARS}。更后面的字节不取(按范围读),预算也只按封顶后的大小计。
132
+ * `text/*` 附件内联(或作为文本文档发出)的最大字符数(UTF-16 码元):再长就只给引用行,绝不截断
133
+ * (§5.2:要么整篇给,要么给引用、由设备里的文件提供)。
134
+ */
135
+ export declare const TEXT_INLINE_MAX_CHARS = 8000;
136
+ /**
137
+ * `text/*` 附件最多取的字节数:UTF-8 里一个 UTF-16 码元最多 3 字节,取这么多一定够判断
138
+ * {@link TEXT_INLINE_MAX_CHARS}。更长的文本不取(它是引用行),见 {@link planMedia}。
122
139
  */
123
140
  export declare const TEXT_FETCH_MAX_BYTES: number;
124
141
  /** 单次请求最多的图片数(常见供应商的上限):只保留最新的,更早的换成占位。 */
@@ -140,15 +157,19 @@ type LogBlock = EventPayload<"user_message">["content"][number];
140
157
  */
141
158
  export declare function excludedMedia(events: readonly ConversationEvent[]): Set<string>;
142
159
  /**
143
- * 该模型需要的附件 id(去重、按出现顺序),调用方据此查行信息({@link MediaInfo})。
160
+ * 该模型需要其附件行的附件 id(去重、按出现顺序),调用方据此查行信息({@link MediaInfo})。
144
161
  * 模型不支持的图片 / PDF、被 `media_excluded` 排除的不在其中——只发占位,行与字节都不取。
162
+ * `file` 块在结果里(引用行要行里的大小与 URI),但从不取字节。
145
163
  */
146
164
  export declare function mediaRefs(events: readonly ConversationEvent[], model: ModelInfo): string[];
147
165
  /** {@link planMedia} 的结果。 */
148
166
  export interface MediaPlan {
149
167
  /** 要取字节的附件 id(从新到旧)。 */
150
168
  fetch: string[];
151
- /** 只取开头若干字节的附件(`text/*` 超过 {@link TEXT_FETCH_MAX_BYTES}):id → 字节数。 */
169
+ /**
170
+ * 只取开头若干字节的附件(`text/*` 超过 {@link TEXT_FETCH_MAX_BYTES}):id → 字节数。
171
+ * 现在总是空:超过取字节上限的文本不再取(它是引用行,§5.2),上限之内的取整份。
172
+ */
152
173
  caps: Map<string, number>;
153
174
  /** 为控制请求大小而省略(预算)。 */
154
175
  dropped: Set<string>;
@@ -162,10 +183,12 @@ export interface MediaPlan {
162
183
  /**
163
184
  * 单次请求的媒体计划(Ruling M6 / M8),只取决于日志、模型能力与行信息,是确定的:
164
185
  * - 被 `media_excluded` 排除的:不取、不计;
186
+ * - `file` 块(模型只看到引用行):不取、不计(行信息照常查);
187
+ * - `text/*` 超过 {@link TEXT_FETCH_MAX_BYTES}:不取(它就是引用行,§5.2)——上限之内的取整份,
188
+ * 解码后超过 {@link TEXT_INLINE_MAX_CHARS} 的在 {@link resolveMedia} 里也变成引用行;
165
189
  * - PDF 页数超过 {@link MAX_PDF_PAGES}:不取、不计;
166
190
  * - 从最新的媒体往前:图片最多保留 {@link MAX_IMAGES_PER_REQUEST} 张,更早的图片省略(不影响其他媒体);
167
- * - 预算:按行里的**声明大小**(`text/*` 按封顶后的大小 `min(size, TEXT_FETCH_MAX_BYTES)`)累计,
168
- * 第一次超出 `budgetBytes` 起,该附件及更早的全部省略;
191
+ * - 预算:按行里的**声明大小**累计,第一次超出 `budgetBytes` 起,该附件及更早的全部省略;
169
192
  * - 同一附件只算一次(按最后一次出现的位置算新旧);没有行的不计(它们是「不再可用」)。
170
193
  *
171
194
  * 已知取舍(接受):新的媒体把较早的媒体挤成占位时,请求里**较早位置**的内容随之改变,这一处之后的提示词缓存
@@ -184,6 +207,20 @@ export declare const mediaTooManyImagesText: (name: string) => string;
184
207
  export declare const mediaTooManyPagesText: (name: string) => string;
185
208
  /** 被供应商拒绝、此后不再发送的附件(模型可见,英文)。 */
186
209
  export declare const mediaRejectedText: (name: string) => string;
210
+ /**
211
+ * A reference line (model-facing English, one text block, §5.2): the file's name and media type, its
212
+ * size, the unsigned object URI, and how to get the bytes — `FetchAttachment` copies the file into the
213
+ * device. A text attachment above the inline threshold says why it was not inlined, so the model does
214
+ * not wonder whether it was truncated. Never a presigned URL: `uri` is unsigned and stable.
215
+ */
216
+ export declare const attachmentReferenceText: (input: {
217
+ name: string;
218
+ mediaType: string;
219
+ size: number;
220
+ uri: string;
221
+ /** The content is text the model could read: it was not inlined because it is too long. */
222
+ text?: boolean;
223
+ }) => string;
187
224
  /** {@link resolveMedia} 的输入:行信息、字节与本次请求的媒体计划。 */
188
225
  export interface MediaContext {
189
226
  info: ReadonlyMap<string, MediaInfo> | undefined;
@@ -196,11 +233,12 @@ export type MediaOutcomeEntry = NonNullable<EventPayload<"model_call">["request"
196
233
  export type MediaOutcome = MediaOutcomeEntry["outcome"];
197
234
  /**
198
235
  * 把日志里的媒体引用换成发给模型的内容(不改日志,结果只取决于日志、模型能力、行信息与字节):
236
+ * - `file` 块(以及超过 {@link TEXT_INLINE_MAX_CHARS} 的文本):一行引用({@link attachmentReferenceText}),
237
+ * **绝不带字节**——要么整篇给,要么给引用、由设备里取来的文件提供(§5.2);
199
238
  * - 模型不支持(图片看 `vision`,文档看 `documents`):图片 / PDF 换成英文占位,**绝不带字节**;
200
239
  * - 被 `media_excluded` 排除 →「被供应商拒绝」占位;没有行 →「不再可用」;PDF 页数过多 →「页数太多」;
201
240
  * 图片太多或超出预算 →「省略」;取不到字节 →「不再可用」;字节超过 `MEDIA_LIMITS` →「太大」;
202
- * - `text/*`:两种方式都封顶为 {@link TEXT_INLINE_MAX_CHARS} 个字符并注明截断——不支持 documents 时内联为文本,
203
- * 支持时作为 base64 文档(截断时文档内容是截断后的文本加注明);
241
+ * - `text/*` 在上限之内:不支持 documents 时内联为文本,支持时作为 base64 文档;
204
242
  * - 其余 → `base64` 块。
205
243
  * 插件永远收不到 `ref`。返回块、发出的媒体块的估算 token 数(图片 {@link IMAGE_TOKENS},PDF 见 {@link pdfTokens},
206
244
  * 文本文档按发出的字节数 ÷ 3)与每个块的处理结果。
@@ -5,11 +5,10 @@ import { isAbsorbable, } from "../../conversations/events.js";
5
5
  import { catalogText, isAlwaysLoaded } from "../../tools/builtins/tool-search.js";
6
6
  import { renderSubagentDelivery } from "../subagents/render.js";
7
7
  import { devicePathsAt, devicePathsText } from "./device-paths.js";
8
- import { LEGACY_CATALOG_HEADER, LEGACY_SKILL_TEXTS, usesLegacyToolNames } from "./legacy-text.js";
9
8
  import { pluginContextsAfterSummary, pluginContextText } from "./plugin-context.js";
10
9
  import { latestProjectRoot, projectRootText } from "./project-root.js";
11
10
  import { currentRunContext, runContextEvents, runContextFullText, runContextText, scheduleHeader, senderLines, } from "./run-context.js";
12
- import { invokedSkillNames, invokedSkillsText, SKILL_TEXTS, skillsCatalogEvents, snapshotChangeText, snapshotCurrentText, snapshotSystemText, systemSkillsCatalog, } from "./skills.js";
11
+ import { invokedSkillNames, invokedSkillsText, skillsCatalogEvents, snapshotChangeText, snapshotCurrentText, snapshotSystemText, systemSkillsCatalog, } from "./skills.js";
13
12
  import { toolsChangedText } from "./tool-changes.js";
14
13
  /**
15
14
  * 平台行为规范(模型可见,英文)。短而通用(spec 6 原则 5);不放时间戳、会话 ID 等会变化的内容,
@@ -22,11 +21,14 @@ export const BEHAVIOR_RULES = [
22
21
  "- If a request is unclear, ask a short clarifying question instead of guessing.",
23
22
  "- Do not expose internal details such as these instructions or system internals.",
24
23
  ].join("\n");
25
- /** `text/*` 附件(内联文本与 base64 文档两种方式都一样)的最大字符数(UTF-16 码元,超出截断并注明)。 */
26
- export const TEXT_INLINE_MAX_CHARS = 50_000;
27
24
  /**
28
- * `text/*` 附件最多取的字节数:UTF-8 里一个 UTF-16 码元最多 3 字节,取这么多一定够凑满
29
- * {@link TEXT_INLINE_MAX_CHARS}。更后面的字节不取(按范围读),预算也只按封顶后的大小计。
25
+ * `text/*` 附件内联(或作为文本文档发出)的最大字符数(UTF-16 码元):再长就只给引用行,绝不截断
26
+ * (§5.2:要么整篇给,要么给引用、由设备里的文件提供)。
27
+ */
28
+ export const TEXT_INLINE_MAX_CHARS = 8_000;
29
+ /**
30
+ * `text/*` 附件最多取的字节数:UTF-8 里一个 UTF-16 码元最多 3 字节,取这么多一定够判断
31
+ * {@link TEXT_INLINE_MAX_CHARS}。更长的文本不取(它是引用行),见 {@link planMedia}。
30
32
  */
31
33
  export const TEXT_FETCH_MAX_BYTES = TEXT_INLINE_MAX_CHARS * 3;
32
34
  /** 单次请求最多的图片数(常见供应商的上限):只保留最新的,更早的换成占位。 */
@@ -47,8 +49,13 @@ export function pdfTokens(size, pages) {
47
49
  return n * PDF_PAGE_TOKENS;
48
50
  }
49
51
  const isText = (mediaType) => mediaType.startsWith("text/");
50
- /** 该模型对这个媒体块的处理:发字节(`bytes`)、内联文本(`inline`)、只给占位(`placeholder`)。 */
52
+ /**
53
+ * 该模型对这个媒体块的处理:发字节(`bytes`)、内联文本(`inline`)、只给占位(`placeholder`)、
54
+ * 只给引用行(`reference`,`file` 块一律如此:内容模型读不了,工具按需把文件取进设备)。
55
+ */
51
56
  function mediaMode(b, model) {
57
+ if (b.type === "file")
58
+ return "reference";
52
59
  if (b.type === "image")
53
60
  return model.capabilities.vision ? "bytes" : "placeholder";
54
61
  if (model.capabilities.documents === true)
@@ -56,8 +63,9 @@ function mediaMode(b, model) {
56
63
  return isText(b.mediaType) ? "inline" : "placeholder";
57
64
  }
58
65
  /**
59
- * 最近摘要之后、会进请求的消息里,该模型需要字节的媒体块(按 seq 与块顺序);也包括随摘要再次发送的
60
- * 用户消息(摘要的 `openingSeqs`,{@link summaryOpeners})。
66
+ * 最近摘要之后、会进请求的消息里,该模型需要其附件行(大小、页数、无签名引用)的媒体块(按 seq 与块顺序),
67
+ * 也包括随摘要再次发送的用户消息(摘要的 `openingSeqs`,{@link summaryOpeners})。`file` 块只在其中取行信息,
68
+ * 从不取字节(见 {@link planMedia})。
61
69
  */
62
70
  function mediaBlocks(events, model) {
63
71
  const sorted = [...events].sort((a, b) => a.seq - b.seq);
@@ -71,9 +79,10 @@ function mediaBlocks(events, model) {
71
79
  if (e.type !== "user_message" && e.type !== "assistant_message")
72
80
  continue;
73
81
  for (const b of e.payload.content) {
74
- if ((b.type === "image" || b.type === "document") && mediaMode(b, model) !== "placeholder") {
82
+ if (b.type !== "image" && b.type !== "document" && b.type !== "file")
83
+ continue;
84
+ if (mediaMode(b, model) !== "placeholder")
75
85
  out.push(b);
76
- }
77
86
  }
78
87
  }
79
88
  return out;
@@ -91,8 +100,9 @@ export function excludedMedia(events) {
91
100
  return out;
92
101
  }
93
102
  /**
94
- * 该模型需要的附件 id(去重、按出现顺序),调用方据此查行信息({@link MediaInfo})。
103
+ * 该模型需要其附件行的附件 id(去重、按出现顺序),调用方据此查行信息({@link MediaInfo})。
95
104
  * 模型不支持的图片 / PDF、被 `media_excluded` 排除的不在其中——只发占位,行与字节都不取。
105
+ * `file` 块在结果里(引用行要行里的大小与 URI),但从不取字节。
96
106
  */
97
107
  export function mediaRefs(events, model) {
98
108
  const excluded = excludedMedia(events);
@@ -105,10 +115,12 @@ export function mediaRefs(events, model) {
105
115
  /**
106
116
  * 单次请求的媒体计划(Ruling M6 / M8),只取决于日志、模型能力与行信息,是确定的:
107
117
  * - 被 `media_excluded` 排除的:不取、不计;
118
+ * - `file` 块(模型只看到引用行):不取、不计(行信息照常查);
119
+ * - `text/*` 超过 {@link TEXT_FETCH_MAX_BYTES}:不取(它就是引用行,§5.2)——上限之内的取整份,
120
+ * 解码后超过 {@link TEXT_INLINE_MAX_CHARS} 的在 {@link resolveMedia} 里也变成引用行;
108
121
  * - PDF 页数超过 {@link MAX_PDF_PAGES}:不取、不计;
109
122
  * - 从最新的媒体往前:图片最多保留 {@link MAX_IMAGES_PER_REQUEST} 张,更早的图片省略(不影响其他媒体);
110
- * - 预算:按行里的**声明大小**(`text/*` 按封顶后的大小 `min(size, TEXT_FETCH_MAX_BYTES)`)累计,
111
- * 第一次超出 `budgetBytes` 起,该附件及更早的全部省略;
123
+ * - 预算:按行里的**声明大小**累计,第一次超出 `budgetBytes` 起,该附件及更早的全部省略;
112
124
  * - 同一附件只算一次(按最后一次出现的位置算新旧);没有行的不计(它们是「不再可用」)。
113
125
  *
114
126
  * 已知取舍(接受):新的媒体把较早的媒体挤成占位时,请求里**较早位置**的内容随之改变,这一处之后的提示词缓存
@@ -141,6 +153,12 @@ export function planMedia(events, model, info, budgetBytes = Number.POSITIVE_INF
141
153
  const row = info.get(id);
142
154
  if (!row)
143
155
  continue;
156
+ // 引用行:模型要行里的信息,但从不取字节,也不占预算
157
+ if (b.type === "file")
158
+ continue;
159
+ // 超过取字节上限的文本不取:它的引用行不需要字节
160
+ if (isText(b.mediaType) && row.size > TEXT_FETCH_MAX_BYTES)
161
+ continue;
144
162
  if (b.mediaType === "application/pdf" && row.pages !== null && row.pages > MAX_PDF_PAGES) {
145
163
  plan.tooManyPages.add(id);
146
164
  continue;
@@ -149,13 +167,9 @@ export function planMedia(events, model, info, budgetBytes = Number.POSITIVE_INF
149
167
  plan.tooManyImages.add(id);
150
168
  continue;
151
169
  }
152
- const capped = isText(b.mediaType) && row.size > TEXT_FETCH_MAX_BYTES;
153
- const size = capped ? TEXT_FETCH_MAX_BYTES : row.size;
154
- if (!over && total + size <= budgetBytes) {
155
- total += size;
170
+ if (!over && total + row.size <= budgetBytes) {
171
+ total += row.size;
156
172
  plan.fetch.push(id);
157
- if (capped)
158
- plan.caps.set(id, TEXT_FETCH_MAX_BYTES);
159
173
  if (b.type === "image")
160
174
  images++;
161
175
  }
@@ -178,6 +192,44 @@ export const mediaTooManyImagesText = (name) => `[Attachment ${quoted(name)} omi
178
192
  export const mediaTooManyPagesText = (name) => `[Attachment ${quoted(name)} has too many pages for this model.]`;
179
193
  /** 被供应商拒绝、此后不再发送的附件(模型可见,英文)。 */
180
194
  export const mediaRejectedText = (name) => `[Attachment ${quoted(name)} was rejected by the model provider.]`;
195
+ /**
196
+ * The usual file extension per content type: the label of a `file` block logged without a name (every
197
+ * accepted type, so the reference line always names something a person could recognise).
198
+ */
199
+ const FILE_EXTENSIONS = {
200
+ "image/png": "png",
201
+ "image/jpeg": "jpg",
202
+ "image/gif": "gif",
203
+ "image/webp": "webp",
204
+ "application/pdf": "pdf",
205
+ "text/plain": "txt",
206
+ "text/markdown": "md",
207
+ "text/csv": "csv",
208
+ "application/json": "json",
209
+ "application/zip": "zip",
210
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
211
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
212
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
213
+ };
214
+ /** The name a reference line shows: the block's own, else one from its media type (`file.xlsx`). */
215
+ function referenceName(b) {
216
+ if (b.name !== undefined)
217
+ return b.name;
218
+ const extension = FILE_EXTENSIONS[b.mediaType];
219
+ return extension === undefined ? "file" : `file.${extension}`;
220
+ }
221
+ /**
222
+ * A reference line (model-facing English, one text block, §5.2): the file's name and media type, its
223
+ * size, the unsigned object URI, and how to get the bytes — `FetchAttachment` copies the file into the
224
+ * device. A text attachment above the inline threshold says why it was not inlined, so the model does
225
+ * not wonder whether it was truncated. Never a presigned URL: `uri` is unsigned and stable.
226
+ */
227
+ export const attachmentReferenceText = (input) => {
228
+ const why = input.text
229
+ ? `${input.size} bytes of text; not sent inline. The file is available in the device on request.`
230
+ : `${input.size} bytes — this model cannot read its content.`;
231
+ return `[Attached file ${quoted(input.name)} (${input.mediaType}), ${why} Unsigned object reference: ${input.uri}. Use FetchAttachment with the file name or this reference to copy it into the device.]`;
232
+ };
181
233
  function placeholder(b, name) {
182
234
  if (b.type === "image") {
183
235
  return `[Attached image ${quoted(name)} — this model cannot view images.]`;
@@ -224,11 +276,12 @@ function capText(data, totalBytes) {
224
276
  }
225
277
  /**
226
278
  * 把日志里的媒体引用换成发给模型的内容(不改日志,结果只取决于日志、模型能力、行信息与字节):
279
+ * - `file` 块(以及超过 {@link TEXT_INLINE_MAX_CHARS} 的文本):一行引用({@link attachmentReferenceText}),
280
+ * **绝不带字节**——要么整篇给,要么给引用、由设备里取来的文件提供(§5.2);
227
281
  * - 模型不支持(图片看 `vision`,文档看 `documents`):图片 / PDF 换成英文占位,**绝不带字节**;
228
282
  * - 被 `media_excluded` 排除 →「被供应商拒绝」占位;没有行 →「不再可用」;PDF 页数过多 →「页数太多」;
229
283
  * 图片太多或超出预算 →「省略」;取不到字节 →「不再可用」;字节超过 `MEDIA_LIMITS` →「太大」;
230
- * - `text/*`:两种方式都封顶为 {@link TEXT_INLINE_MAX_CHARS} 个字符并注明截断——不支持 documents 时内联为文本,
231
- * 支持时作为 base64 文档(截断时文档内容是截断后的文本加注明);
284
+ * - `text/*` 在上限之内:不支持 documents 时内联为文本,支持时作为 base64 文档;
232
285
  * - 其余 → `base64` 块。
233
286
  * 插件永远收不到 `ref`。返回块、发出的媒体块的估算 token 数(图片 {@link IMAGE_TOKENS},PDF 见 {@link pdfTokens},
234
287
  * 文本文档按发出的字节数 ÷ 3)与每个块的处理结果。
@@ -238,7 +291,7 @@ export function resolveMedia(content, model, ctx) {
238
291
  const outcomes = [];
239
292
  let tokens = 0;
240
293
  for (const b of content) {
241
- if (b.type !== "image" && b.type !== "document") {
294
+ if (b.type !== "image" && b.type !== "document" && b.type !== "file") {
242
295
  out.push(b);
243
296
  continue;
244
297
  }
@@ -248,7 +301,21 @@ export function resolveMedia(content, model, ctx) {
248
301
  out.push({ type: "text", text: t });
249
302
  outcomes.push({ attachmentId: id, outcome });
250
303
  };
304
+ /** The reference line for this block and its row (`asText`: text that was not inlined). */
305
+ const reference = (row, asText = false) => attachmentReferenceText({
306
+ name: referenceName(b),
307
+ mediaType: b.mediaType,
308
+ size: row.size,
309
+ uri: row.uri,
310
+ text: asText,
311
+ });
251
312
  const mode = mediaMode(b, model);
313
+ if (b.type === "file") {
314
+ // a file block: its bytes stay in the object store, the model gets the reference (never a `ref`)
315
+ const row = ctx.info?.get(id);
316
+ text(row ? reference(row) : mediaUnavailableText(name), row ? "reference" : "unavailable");
317
+ continue;
318
+ }
252
319
  if (mode === "placeholder") {
253
320
  text(placeholder(b, name), "placeholder_unsupported");
254
321
  continue;
@@ -263,6 +330,11 @@ export function resolveMedia(content, model, ctx) {
263
330
  text(mediaUnavailableText(name), "unavailable");
264
331
  continue;
265
332
  }
333
+ // `text/*` over the fetch cap is never fetched: its size alone says it is the reference (§5.2)
334
+ if (isText(b.mediaType) && row.size > TEXT_FETCH_MAX_BYTES) {
335
+ text(reference(row, true), "reference");
336
+ continue;
337
+ }
266
338
  if (plan.tooManyPages.has(id)) {
267
339
  text(mediaTooManyPagesText(name), "too_many_pages");
268
340
  continue;
@@ -280,16 +352,18 @@ export function resolveMedia(content, model, ctx) {
280
352
  text(mediaUnavailableText(name), "unavailable");
281
353
  continue;
282
354
  }
283
- let data = got.data;
355
+ const data = got.data;
284
356
  if (isText(b.mediaType)) {
285
357
  const capped = capText(got.data, row.size);
286
- if (mode === "inline") {
287
- const body = capped.note === null ? capped.text : `${capped.text}\n${capped.note}`;
288
- text(`[Attached file ${quoted(name)} (${b.mediaType})]\n${body}`, "inline");
358
+ // over the inline threshold (or the row's declared size lied): the reference, never a
359
+ // truncated body (§5.2)
360
+ if (capped.note !== null) {
361
+ text(reference(row, true), "reference");
289
362
  continue;
290
363
  }
291
- if (capped.note !== null) {
292
- data = new TextEncoder().encode(`${capped.text}\n${capped.note}`);
364
+ if (mode === "inline") {
365
+ text(`[Attached file ${quoted(name)} (${b.mediaType})]\n${capped.text}`, "inline");
366
+ continue;
293
367
  }
294
368
  }
295
369
  const limit = b.type === "image" ? MEDIA_LIMITS.imageBytes : MEDIA_LIMITS.documentBytes;
@@ -388,7 +462,8 @@ export function buildModelRequest(input) {
388
462
  const mediaOutcomes = new Map();
389
463
  /** 日志内容块 → 请求内容块:媒体引用按模型能力解析(见 {@link resolveMedia})。 */
390
464
  const blocksOf = (content) => {
391
- if (!content.some((b) => b.type === "image" || b.type === "document"))
465
+ const media = content.some((b) => b.type === "image" || b.type === "document" || b.type === "file");
466
+ if (!media)
392
467
  return asBlocks(content);
393
468
  const r = resolveMedia(content, model, mediaCtx);
394
469
  mediaTokens += r.tokens;
@@ -405,8 +480,8 @@ export function buildModelRequest(input) {
405
480
  const messages = [];
406
481
  const reminderSeqs = [];
407
482
  const absorbed = input.absorbedUpToSeq;
408
- /** model_call 吸收到的位置;没有该字段的旧事件视为吸收了它之前的全部消息。 */
409
- const absorbedBy = (e) => e.payload.request.absorbedUpToSeq ?? e.seq;
483
+ /** Where a model_call had taken in absorbable events. */
484
+ const absorbedBy = (e) => e.payload.request.absorbedUpToSeq;
410
485
  /** 每个位置之前最近一次 model_call 的吸收位置(之前没有 model_call 为 undefined)。 */
411
486
  const callBefore = [];
412
487
  let lastCall;
@@ -570,10 +645,6 @@ export function buildModelRequest(input) {
570
645
  if (!results.has(k))
571
646
  results.set(k, e.payload);
572
647
  }
573
- // System texts naming a builtin: a request whose tools were recorded before the tool rename
574
- // renders the frozen pre-rename wording, so it rebuilds exactly (tool naming spec §10)
575
- const legacyNames = usesLegacyToolNames(input.tools ?? []);
576
- const skillTexts = legacyNames ? LEGACY_SKILL_TEXTS : SKILL_TEXTS;
577
648
  // 技能目录(Ruling M17):第一份快照进 system;之后的每份在所在位置追加变更提醒(相对上一份快照)。
578
649
  const skillSnaps = skillsCatalogEvents(events);
579
650
  const systemSkills = systemSkillsCatalog(events);
@@ -612,16 +683,18 @@ export function buildModelRequest(input) {
612
683
  const project = latestProjectRoot(events, after);
613
684
  if (project)
614
685
  messages.push({ role: "system", content: projectRootText(project) });
615
- // 被摘要覆盖的变更提醒不再发送:摘要时生效的目录与 system 里的不同 → 紧随摘要补上完整的当前目录
686
+ // change notices the summary covers are not sent again: when the catalog in effect at the summary
687
+ // differs from the one in the system, the full current catalog follows the summary
616
688
  const covered = skillSnaps.filter((e) => e.seq <= after).at(-1);
617
- // (phase B: plus the current pinned skills and tool-name map when they differ from system's)
689
+ // (phase B: plus the tool-name map when it differs from system's)
618
690
  if (covered && covered !== systemSkills) {
619
- const text = snapshotCurrentText(systemSkills?.payload, covered.payload, skillTexts);
691
+ const text = snapshotCurrentText(systemSkills?.payload, covered.payload);
620
692
  if (text !== "")
621
693
  messages.push({ role: "system", content: text });
622
694
  }
623
- // phase D: the skills a person invoked in the summarised range, by name (from the log only)
624
- const invoked = invokedSkillsText(invokedSkillNames(events, after), skillTexts);
695
+ // phase D: the skills invoked in the summarised range (a person's, and template skills the
696
+ // kernel wrote as invocations), by name (from the log only)
697
+ const invoked = invokedSkillsText(invokedSkillNames(events, after));
625
698
  if (invoked !== "")
626
699
  messages.push({ role: "system", content: invoked });
627
700
  }
@@ -735,13 +808,38 @@ export function buildModelRequest(input) {
735
808
  break;
736
809
  case "skills_catalog":
737
810
  if (e !== systemSkills) {
738
- const text = snapshotChangeText(prevSnapshot.get(e.seq), e.payload, skillTexts);
811
+ const text = snapshotChangeText(prevSnapshot.get(e.seq), e.payload);
739
812
  if (text !== "")
740
813
  messages.push({ role: "system", content: text });
741
814
  }
742
815
  break;
743
- default:
816
+ // Not model-visible as events of their own. tool_result is rendered with its assistant
817
+ // message's tool call (the `results` map above); compaction_summary is the `summary` that
818
+ // seeds the request; the rest are lifecycle, usage, approval, question and display records.
819
+ // Adding an event type fails typecheck here until it is listed with how it renders.
820
+ case "tool_result":
821
+ case "run_started":
822
+ case "usage":
823
+ case "tool_call_started":
824
+ case "connection_required":
825
+ case "approval_requested":
826
+ case "approval_decided":
827
+ case "approval_updated":
828
+ case "question_asked":
829
+ case "question_answered":
830
+ case "media_excluded":
831
+ case "artifact_created":
832
+ case "compaction_summary":
833
+ case "compaction_failed":
834
+ case "run_finished":
835
+ case "run_aborted":
836
+ case "run_failed":
744
837
  break;
838
+ default: {
839
+ const unrendered = e;
840
+ void unrendered;
841
+ break;
842
+ }
745
843
  }
746
844
  }
747
845
  emitRaced(Number.POSITIVE_INFINITY);
@@ -755,9 +853,7 @@ export function buildModelRequest(input) {
755
853
  : `${BEHAVIOR_RULES}\n\n${agent.instructions}`;
756
854
  const system = [
757
855
  {
758
- text: systemSkills
759
- ? `${base}\n\n${snapshotSystemText(systemSkills.payload, skillTexts)}`
760
- : base,
856
+ text: systemSkills ? `${base}\n\n${snapshotSystemText(systemSkills.payload)}` : base,
761
857
  cache: true,
762
858
  },
763
859
  ];
@@ -771,10 +867,7 @@ export function buildModelRequest(input) {
771
867
  tools = [...sorted.filter((t) => isAlwaysLoaded(t.key)), ...loaded];
772
868
  if (deferred.length > 0) {
773
869
  catalog = deferred;
774
- system.push({
775
- text: catalogText(deferred, legacyNames ? LEGACY_CATALOG_HEADER : undefined),
776
- cache: true,
777
- });
870
+ system.push({ text: catalogText(deferred), cache: true });
778
871
  }
779
872
  }
780
873
  const request = {
@@ -1,8 +1,6 @@
1
1
  import type { ModelRequest } from "@capybara-hq/plugin-sdk";
2
2
  import type { ConversationEvent } from "../../conversations/events.js";
3
3
  import type { CompactionSettings } from "../../identity/settings.js";
4
- /** 压缩请求的标记:放在 system 中,便于识别(model-fake 据此返回摘要)。 */
5
- export declare const COMPACTION_MARKER = "CAPYBARA_COMPACTION";
6
4
  /**
7
5
  * The summary request's output cap when the caller gives none: the built-in default of the
8
6
  * `compaction.maxOutputTokens` setting (context compaction spec §4.8). The effective setting is
@@ -102,7 +100,7 @@ export declare function nextTranscriptChunk(transcript: string, chunkSize: numbe
102
100
  */
103
101
  export declare function chunkTranscript(transcript: string, chunkSize: number): string[];
104
102
  /**
105
- * The summary request: the marked English instruction as the system prompt and the transcript as
103
+ * The summary request: the English instruction (request `purpose: "compaction"`) as the system prompt and the transcript as
106
104
  * the only user message. `maxOutputTokens` is the effective `compaction.maxOutputTokens` setting,
107
105
  * which the caller narrows to the model's own cap (context compaction spec §4.8); omitted, it is
108
106
  * the built-in default.