@sixb/core 0.2.5 → 0.2.6

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 (385) hide show
  1. package/dist/actions/index.js +36 -35
  2. package/dist/actions/index.js.map +1 -1
  3. package/dist/actions/validation.d.ts.map +1 -1
  4. package/dist/agents/errors.d.ts +1 -1
  5. package/dist/agents/errors.d.ts.map +1 -1
  6. package/dist/agents/execution.d.ts +17 -2
  7. package/dist/agents/execution.d.ts.map +1 -1
  8. package/dist/agents/index.d.ts +2 -2
  9. package/dist/agents/index.d.ts.map +1 -1
  10. package/dist/agents/index.js +50 -44
  11. package/dist/agents/index.js.map +1 -1
  12. package/dist/agents/model-routing.d.ts +5 -2
  13. package/dist/agents/model-routing.d.ts.map +1 -1
  14. package/dist/agents/request.d.ts +45 -4
  15. package/dist/agents/request.d.ts.map +1 -1
  16. package/dist/agents/run-events.d.ts +4 -0
  17. package/dist/agents/run-events.d.ts.map +1 -1
  18. package/dist/agents/run-session-children.d.ts.map +1 -1
  19. package/dist/agents/run-turn.d.ts +9 -1
  20. package/dist/agents/run-turn.d.ts.map +1 -1
  21. package/dist/agents/streams/index.d.ts +1 -1
  22. package/dist/agents/streams/index.d.ts.map +1 -1
  23. package/dist/agents/streams/index.js +1 -1
  24. package/dist/agents/streams/internal.d.ts +2 -1
  25. package/dist/agents/streams/internal.d.ts.map +1 -1
  26. package/dist/agents/streams/internal.js +22 -2
  27. package/dist/agents/streams/internal.js.map +1 -1
  28. package/dist/agents/streams/protocol.d.ts +37 -0
  29. package/dist/agents/streams/protocol.d.ts.map +1 -1
  30. package/dist/agents/streams/steps.d.ts +24 -0
  31. package/dist/agents/streams/steps.d.ts.map +1 -0
  32. package/dist/agents/thread-access.d.ts +44 -2
  33. package/dist/agents/thread-access.d.ts.map +1 -1
  34. package/dist/artifacts/live/server.js +19 -18
  35. package/dist/artifacts/live/server.js.map +1 -1
  36. package/dist/artifacts/publish/index.js +18 -17
  37. package/dist/artifacts/publish/index.js.map +1 -1
  38. package/dist/artifacts/publish/merge.d.ts +2 -1
  39. package/dist/artifacts/publish/merge.d.ts.map +1 -1
  40. package/dist/artifacts/run-query.d.ts.map +1 -1
  41. package/dist/auth/index.js +6 -6
  42. package/dist/authorization/index.js +2 -2
  43. package/dist/bootstrap/index.js +40 -38
  44. package/dist/bootstrap/index.js.map +2 -2
  45. package/dist/calendar.d.ts +55 -0
  46. package/dist/calendar.d.ts.map +1 -0
  47. package/dist/calendar.js +19 -0
  48. package/dist/calendar.js.map +9 -0
  49. package/dist/{chunk-5a4a52tq.js → chunk-0pmpwn3g.js} +18 -2
  50. package/dist/chunk-0pmpwn3g.js.map +10 -0
  51. package/dist/{chunk-xcrnrpfh.js → chunk-394zjzjs.js} +20 -10
  52. package/dist/{chunk-xcrnrpfh.js.map → chunk-394zjzjs.js.map} +5 -5
  53. package/dist/{chunk-stmxh0hv.js → chunk-3neam1y5.js} +2 -2
  54. package/dist/{chunk-zeykm8my.js → chunk-3qtk0070.js} +16 -42
  55. package/dist/chunk-3qtk0070.js.map +14 -0
  56. package/dist/{chunk-0mvjpgvm.js → chunk-425ydk65.js} +4 -4
  57. package/dist/{chunk-s5pj68fa.js → chunk-5sswe5ej.js} +2 -2
  58. package/dist/chunk-6hfbz4d0.js +98 -0
  59. package/dist/chunk-6hfbz4d0.js.map +10 -0
  60. package/dist/{chunk-3zagkr6w.js → chunk-7mhbs9yy.js} +4 -4
  61. package/dist/{chunk-3zagkr6w.js.map → chunk-7mhbs9yy.js.map} +1 -1
  62. package/dist/{chunk-fpf57gca.js → chunk-7r9mqpva.js} +273 -66
  63. package/dist/{chunk-fpf57gca.js.map → chunk-7r9mqpva.js.map} +5 -5
  64. package/dist/{chunk-ewqn51gr.js → chunk-88xeh6zx.js} +6 -4
  65. package/dist/{chunk-ewqn51gr.js.map → chunk-88xeh6zx.js.map} +4 -4
  66. package/dist/chunk-90nqenq8.js +386 -0
  67. package/dist/chunk-90nqenq8.js.map +14 -0
  68. package/dist/{chunk-gjhrz66x.js → chunk-9c9yknwt.js} +247 -20
  69. package/dist/{chunk-gjhrz66x.js.map → chunk-9c9yknwt.js.map} +6 -6
  70. package/dist/{chunk-q9nkpr8k.js → chunk-9tpmfh3n.js} +1 -1
  71. package/dist/chunk-9wr3yajk.js.map +2 -2
  72. package/dist/{chunk-z1njfqqs.js → chunk-ats8y3d9.js} +721 -156
  73. package/dist/{chunk-z1njfqqs.js.map → chunk-ats8y3d9.js.map} +13 -13
  74. package/dist/{chunk-68hm50qh.js → chunk-bcz9dxtf.js} +16 -46
  75. package/dist/chunk-bcz9dxtf.js.map +12 -0
  76. package/dist/{chunk-naxjka9v.js → chunk-brhp9d97.js} +2 -2
  77. package/dist/{chunk-8a8k38tz.js → chunk-brybqw5k.js} +1 -1
  78. package/dist/{chunk-s1mqyqmm.js → chunk-bs1sd0e0.js} +12 -8
  79. package/dist/chunk-bs1sd0e0.js.map +18 -0
  80. package/dist/{chunk-vehcr9eb.js → chunk-cg7cygfj.js} +1 -1
  81. package/dist/chunk-dq3t5sr3.js +114 -0
  82. package/dist/chunk-dq3t5sr3.js.map +11 -0
  83. package/dist/{chunk-r2psmn42.js → chunk-eg6xqef7.js} +1 -1
  84. package/dist/{chunk-zxhym8tr.js → chunk-f05994as.js} +1 -1
  85. package/dist/{chunk-5t9gm5tt.js → chunk-fmgf9h5e.js} +38 -14
  86. package/dist/chunk-fmgf9h5e.js.map +22 -0
  87. package/dist/{chunk-ey1p8w68.js → chunk-gaj8djsw.js} +80 -4
  88. package/dist/chunk-gaj8djsw.js.map +13 -0
  89. package/dist/{chunk-1yh6jgtz.js → chunk-grt2j5vp.js} +2 -2
  90. package/dist/{chunk-zft9bzbc.js → chunk-hkbks1xm.js} +2 -1
  91. package/dist/{chunk-zft9bzbc.js.map → chunk-hkbks1xm.js.map} +3 -3
  92. package/dist/{chunk-rtdrm592.js → chunk-htdzx40w.js} +2 -2
  93. package/dist/{chunk-bc3y6gff.js → chunk-jka26v8c.js} +1 -1
  94. package/dist/{chunk-m3qx2pns.js → chunk-jt012fxq.js} +28 -12
  95. package/dist/{chunk-m3qx2pns.js.map → chunk-jt012fxq.js.map} +5 -5
  96. package/dist/{chunk-k3jh8gsg.js → chunk-kft7mp7z.js} +20 -3
  97. package/dist/chunk-kft7mp7z.js.map +10 -0
  98. package/dist/{chunk-qavwr628.js → chunk-n1hbwc6y.js} +5 -6
  99. package/dist/chunk-n1hbwc6y.js.map +12 -0
  100. package/dist/chunk-nxysqbt0.js.map +2 -2
  101. package/dist/{chunk-pqvvqc65.js → chunk-pqj8vff9.js} +3 -3
  102. package/dist/{chunk-wqe9shx2.js → chunk-qbd282aa.js} +2 -2
  103. package/dist/{chunk-e91fmg6t.js → chunk-qsa7nw6f.js} +2 -1
  104. package/dist/{chunk-e91fmg6t.js.map → chunk-qsa7nw6f.js.map} +3 -3
  105. package/dist/{chunk-rg725hry.js → chunk-s8xxef60.js} +83 -33
  106. package/dist/{chunk-rg725hry.js.map → chunk-s8xxef60.js.map} +5 -5
  107. package/dist/{chunk-fzae1jpq.js → chunk-t19wjmnc.js} +5 -5
  108. package/dist/{chunk-paxabbqd.js → chunk-tapdssb5.js} +1 -1
  109. package/dist/{chunk-dhkc9b23.js → chunk-v8a1qjzp.js} +1 -1
  110. package/dist/{chunk-q8d9p0tb.js → chunk-wzcjhv54.js} +8 -1
  111. package/dist/{chunk-q8d9p0tb.js.map → chunk-wzcjhv54.js.map} +3 -3
  112. package/dist/{chunk-pc7kra3k.js → chunk-xavet0qs.js} +1 -1
  113. package/dist/{chunk-0hkdtwqk.js → chunk-xf76csps.js} +5 -5
  114. package/dist/{chunk-m9ketb51.js → chunk-ygvay56w.js} +1 -1
  115. package/dist/{chunk-b4escq4c.js → chunk-ykchk644.js} +6 -6
  116. package/dist/{chunk-k29n4176.js → chunk-ym1bqd98.js} +6 -6
  117. package/dist/connectors/connections/capability.d.ts +11 -0
  118. package/dist/connectors/connections/capability.d.ts.map +1 -1
  119. package/dist/connectors/connections/internal.d.ts +2 -1
  120. package/dist/connectors/connections/internal.d.ts.map +1 -1
  121. package/dist/connectors/connections/internal.js +8 -4
  122. package/dist/connectors/connections/internal.js.map +1 -1
  123. package/dist/connectors/connections/service.d.ts +9 -1
  124. package/dist/connectors/connections/service.d.ts.map +1 -1
  125. package/dist/connectors/execution.d.ts +7 -1
  126. package/dist/connectors/execution.d.ts.map +1 -1
  127. package/dist/connectors/service.d.ts +5 -1
  128. package/dist/connectors/service.d.ts.map +1 -1
  129. package/dist/deploy/types.d.ts +4 -1
  130. package/dist/deploy/types.d.ts.map +1 -1
  131. package/dist/events/execution.d.ts +8 -1
  132. package/dist/events/execution.d.ts.map +1 -1
  133. package/dist/events/types/syncs.d.ts +4 -0
  134. package/dist/events/types/syncs.d.ts.map +1 -1
  135. package/dist/execution/agent.js +37 -36
  136. package/dist/execution/agent.js.map +1 -1
  137. package/dist/execution/authorized-object-reader.d.ts +4 -0
  138. package/dist/execution/authorized-object-reader.d.ts.map +1 -1
  139. package/dist/execution/object-reader-ontology.d.ts +3 -0
  140. package/dist/execution/object-reader-ontology.d.ts.map +1 -1
  141. package/dist/execution/primitive.js +36 -35
  142. package/dist/execution/primitive.js.map +1 -1
  143. package/dist/execution/request.d.ts +1 -1
  144. package/dist/execution/request.d.ts.map +1 -1
  145. package/dist/execution/request.js +33 -32
  146. package/dist/execution/request.js.map +3 -3
  147. package/dist/http/api-routes.d.ts.map +1 -1
  148. package/dist/http/index.js +1 -1
  149. package/dist/index.d.ts +5 -5
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.js +61 -59
  152. package/dist/index.js.map +1 -1
  153. package/dist/maintenance/index.js +1 -1
  154. package/dist/materializer/index.js +22 -21
  155. package/dist/materializer/index.js.map +1 -1
  156. package/dist/models/audio/runtime.d.ts.map +1 -1
  157. package/dist/models/audio/types.d.ts +19 -0
  158. package/dist/models/audio/types.d.ts.map +1 -1
  159. package/dist/models/execution/index.js +20 -19
  160. package/dist/models/execution/index.js.map +1 -1
  161. package/dist/models/index.d.ts +1 -1
  162. package/dist/models/index.d.ts.map +1 -1
  163. package/dist/objects/index.js +36 -35
  164. package/dist/objects/index.js.map +1 -1
  165. package/dist/objects/query/executor.d.ts +3 -1
  166. package/dist/objects/query/executor.d.ts.map +1 -1
  167. package/dist/objects/query/explain.d.ts +3 -1
  168. package/dist/objects/query/explain.d.ts.map +1 -1
  169. package/dist/objects/query/index.d.ts +1 -1
  170. package/dist/objects/query/index.d.ts.map +1 -1
  171. package/dist/objects/query/index.js +19 -18
  172. package/dist/objects/query/index.js.map +1 -1
  173. package/dist/objects/query/link-query-clearance.d.ts +3 -0
  174. package/dist/objects/query/link-query-clearance.d.ts.map +1 -1
  175. package/dist/objects/query/links.d.ts +1 -1
  176. package/dist/objects/query/links.d.ts.map +1 -1
  177. package/dist/objects/query/validate.d.ts +17 -0
  178. package/dist/objects/query/validate.d.ts.map +1 -1
  179. package/dist/objects/sdk/runtime-query-executor.d.ts +1 -1
  180. package/dist/objects/sdk/runtime-query-executor.d.ts.map +1 -1
  181. package/dist/ontology/index.js +3 -3
  182. package/dist/ontology/internal.js +3 -3
  183. package/dist/pipelines/index.js +21 -20
  184. package/dist/pipelines/index.js.map +1 -1
  185. package/dist/projections/internal.js +20 -19
  186. package/dist/projections/internal.js.map +1 -1
  187. package/dist/queues/in-memory.d.ts +1 -1
  188. package/dist/queues/in-memory.d.ts.map +1 -1
  189. package/dist/runtime/host.d.ts.map +1 -1
  190. package/dist/runtime/internal.js +24 -23
  191. package/dist/runtime/internal.js.map +2 -2
  192. package/dist/runtime/locale.d.ts +0 -2
  193. package/dist/runtime/locale.d.ts.map +1 -1
  194. package/dist/runtime/sixb.d.ts.map +1 -1
  195. package/dist/sandboxes/auth.d.ts +26 -4
  196. package/dist/sandboxes/auth.d.ts.map +1 -1
  197. package/dist/sandboxes/index.d.ts +3 -1
  198. package/dist/sandboxes/index.d.ts.map +1 -1
  199. package/dist/sandboxes/index.js +5 -5
  200. package/dist/security/view-conditions.d.ts.map +1 -1
  201. package/dist/shares/internal.js +16 -15
  202. package/dist/shares/internal.js.map +2 -2
  203. package/dist/storage/agents/in-memory.d.ts +18 -1
  204. package/dist/storage/agents/in-memory.d.ts.map +1 -1
  205. package/dist/storage/agents/index.d.ts +1 -1
  206. package/dist/storage/agents/index.d.ts.map +1 -1
  207. package/dist/storage/agents/provider.d.ts +43 -9
  208. package/dist/storage/agents/provider.d.ts.map +1 -1
  209. package/dist/storage/agents/provider.js +18 -2
  210. package/dist/storage/agents/provider.js.map +1 -1
  211. package/dist/storage/agents/types.d.ts +136 -3
  212. package/dist/storage/agents/types.d.ts.map +1 -1
  213. package/dist/storage/ai-cost/analytics.d.ts +3 -2
  214. package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
  215. package/dist/storage/ai-cost/provider.js +4 -3
  216. package/dist/storage/ai-cost/provider.js.map +1 -1
  217. package/dist/storage/ai-cost/types.d.ts +5 -1
  218. package/dist/storage/ai-cost/types.d.ts.map +1 -1
  219. package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
  220. package/dist/storage/artifacts/record.d.ts +3 -1
  221. package/dist/storage/artifacts/record.d.ts.map +1 -1
  222. package/dist/storage/artifacts/types.d.ts +7 -0
  223. package/dist/storage/artifacts/types.d.ts.map +1 -1
  224. package/dist/storage/file-upload-sessions/provider.js +7 -7
  225. package/dist/storage/index.d.ts +2 -2
  226. package/dist/storage/index.d.ts.map +1 -1
  227. package/dist/storage/index.js +22 -21
  228. package/dist/storage/index.js.map +1 -1
  229. package/dist/storage/internal.js +8 -8
  230. package/dist/storage/operation-scope.d.ts.map +1 -1
  231. package/dist/storage/operation-scope.js +1 -1
  232. package/dist/storage/sync-runs/idempotency.d.ts.map +1 -1
  233. package/dist/storage/sync-runs/in-memory.d.ts +2 -1
  234. package/dist/storage/sync-runs/in-memory.d.ts.map +1 -1
  235. package/dist/storage/sync-runs/index.d.ts +1 -1
  236. package/dist/storage/sync-runs/index.d.ts.map +1 -1
  237. package/dist/storage/sync-runs/types.d.ts +27 -2
  238. package/dist/storage/sync-runs/types.d.ts.map +1 -1
  239. package/dist/storage/workflow-runs/provider.js +7 -7
  240. package/dist/syncs/accounts.d.ts +36 -0
  241. package/dist/syncs/accounts.d.ts.map +1 -0
  242. package/dist/syncs/builders.d.ts.map +1 -1
  243. package/dist/syncs/connections.d.ts +36 -0
  244. package/dist/syncs/connections.d.ts.map +1 -0
  245. package/dist/syncs/execution.d.ts +14 -4
  246. package/dist/syncs/execution.d.ts.map +1 -1
  247. package/dist/syncs/index.d.ts +2 -1
  248. package/dist/syncs/index.d.ts.map +1 -1
  249. package/dist/syncs/index.js +22 -21
  250. package/dist/syncs/index.js.map +1 -1
  251. package/dist/syncs/request.d.ts +16 -2
  252. package/dist/syncs/request.d.ts.map +1 -1
  253. package/dist/syncs/run-dispatch.d.ts +14 -2
  254. package/dist/syncs/run-dispatch.d.ts.map +1 -1
  255. package/dist/testing/agent-approval-storage-contract.d.ts.map +1 -1
  256. package/dist/testing/agent-inbox-storage-contract.d.ts.map +1 -1
  257. package/dist/testing/agent-storage-contract.d.ts.map +1 -1
  258. package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -1
  259. package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
  260. package/dist/testing/index.js +1051 -58
  261. package/dist/testing/index.js.map +8 -8
  262. package/dist/testing/run-claim-storage-contract.d.ts.map +1 -1
  263. package/dist/webhooks/internal.js +17 -16
  264. package/dist/webhooks/internal.js.map +2 -2
  265. package/dist/workers/index.js +66 -13
  266. package/dist/workers/index.js.map +4 -4
  267. package/dist/workers/queue-worker.d.ts +5 -0
  268. package/dist/workers/queue-worker.d.ts.map +1 -1
  269. package/dist/workers/worker.d.ts +8 -0
  270. package/dist/workers/worker.d.ts.map +1 -1
  271. package/dist/workflows/index.js +42 -40
  272. package/dist/workflows/index.js.map +1 -1
  273. package/package.json +7 -1
  274. package/src/actions/validation.ts +3 -1
  275. package/src/agents/children.ts +6 -0
  276. package/src/agents/errors.ts +3 -0
  277. package/src/agents/execution.ts +170 -20
  278. package/src/agents/index.ts +4 -0
  279. package/src/agents/model-routing.ts +25 -9
  280. package/src/agents/request.ts +759 -40
  281. package/src/agents/run-events.ts +235 -38
  282. package/src/agents/run-session-children.ts +13 -2
  283. package/src/agents/run-turn.ts +140 -23
  284. package/src/agents/streams/index.ts +2 -0
  285. package/src/agents/streams/internal.ts +12 -0
  286. package/src/agents/streams/protocol.ts +69 -1
  287. package/src/agents/streams/steps.ts +131 -0
  288. package/src/agents/thread-access.ts +57 -2
  289. package/src/artifacts/publish/merge.ts +14 -3
  290. package/src/artifacts/run-query.ts +5 -2
  291. package/src/calendar.ts +195 -0
  292. package/src/connectors/connections/capability.ts +40 -0
  293. package/src/connectors/connections/internal.ts +3 -0
  294. package/src/connectors/connections/service.ts +74 -5
  295. package/src/connectors/execution.ts +5 -6
  296. package/src/connectors/service.ts +23 -0
  297. package/src/deploy/types.ts +4 -1
  298. package/src/events/execution.ts +42 -2
  299. package/src/events/types/syncs.ts +4 -0
  300. package/src/execution/authorized-object-reader.ts +33 -5
  301. package/src/execution/object-reader-ontology.ts +6 -0
  302. package/src/execution/request.ts +1 -0
  303. package/src/http/api-routes.ts +8 -0
  304. package/src/index.ts +18 -2
  305. package/src/models/audio/runtime.ts +57 -14
  306. package/src/models/audio/types.ts +20 -0
  307. package/src/models/index.ts +1 -0
  308. package/src/objects/query/executor.ts +4 -0
  309. package/src/objects/query/explain.ts +5 -0
  310. package/src/objects/query/index.ts +1 -0
  311. package/src/objects/query/link-query-clearance.ts +4 -1
  312. package/src/objects/query/links.ts +5 -1
  313. package/src/objects/query/validate.ts +33 -1
  314. package/src/objects/sdk/runtime-query-executor.ts +7 -3
  315. package/src/runtime/host.ts +13 -7
  316. package/src/runtime/locale.ts +0 -10
  317. package/src/runtime/sixb.ts +12 -2
  318. package/src/sandboxes/README.md +3 -1
  319. package/src/sandboxes/auth.ts +32 -4
  320. package/src/sandboxes/index.ts +15 -1
  321. package/src/security/view-conditions.ts +2 -1
  322. package/src/storage/agents/in-memory.ts +271 -6
  323. package/src/storage/agents/index.ts +10 -0
  324. package/src/storage/agents/provider.ts +170 -13
  325. package/src/storage/agents/types.ts +148 -3
  326. package/src/storage/ai-cost/analytics.ts +22 -43
  327. package/src/storage/ai-cost/types.ts +5 -1
  328. package/src/storage/artifacts/in-memory.ts +20 -5
  329. package/src/storage/artifacts/record.ts +8 -2
  330. package/src/storage/artifacts/types.ts +7 -0
  331. package/src/storage/index.ts +11 -0
  332. package/src/storage/operation-scope.ts +1 -0
  333. package/src/storage/sync-runs/idempotency.ts +1 -0
  334. package/src/storage/sync-runs/in-memory.ts +43 -1
  335. package/src/storage/sync-runs/index.ts +1 -0
  336. package/src/storage/sync-runs/types.ts +30 -1
  337. package/src/syncs/accounts.ts +85 -0
  338. package/src/syncs/builders.ts +18 -1
  339. package/src/syncs/connections.ts +123 -0
  340. package/src/syncs/execution.ts +64 -22
  341. package/src/syncs/index.ts +3 -0
  342. package/src/syncs/request.ts +81 -23
  343. package/src/syncs/run-dispatch.ts +69 -7
  344. package/src/testing/agent-approval-storage-contract.ts +123 -0
  345. package/src/testing/agent-inbox-storage-contract.ts +59 -0
  346. package/src/testing/agent-storage-contract.ts +767 -8
  347. package/src/testing/ai-cost-storage-contract.ts +80 -0
  348. package/src/testing/artifact-storage-contract.ts +129 -0
  349. package/src/testing/run-claim-storage-contract.ts +116 -0
  350. package/src/workers/README.md +4 -1
  351. package/src/workers/lost-runs.ts +1 -0
  352. package/src/workers/queue-worker.ts +16 -5
  353. package/src/workers/worker.ts +67 -7
  354. package/dist/chunk-5a4a52tq.js.map +0 -10
  355. package/dist/chunk-5t9gm5tt.js.map +0 -22
  356. package/dist/chunk-68hm50qh.js.map +0 -13
  357. package/dist/chunk-aw1z0gre.js +0 -234
  358. package/dist/chunk-aw1z0gre.js.map +0 -12
  359. package/dist/chunk-ey1p8w68.js.map +0 -13
  360. package/dist/chunk-k3jh8gsg.js.map +0 -10
  361. package/dist/chunk-qavwr628.js.map +0 -12
  362. package/dist/chunk-s1mqyqmm.js.map +0 -18
  363. package/dist/chunk-zeykm8my.js.map +0 -14
  364. /package/dist/{chunk-stmxh0hv.js.map → chunk-3neam1y5.js.map} +0 -0
  365. /package/dist/{chunk-0mvjpgvm.js.map → chunk-425ydk65.js.map} +0 -0
  366. /package/dist/{chunk-s5pj68fa.js.map → chunk-5sswe5ej.js.map} +0 -0
  367. /package/dist/{chunk-q9nkpr8k.js.map → chunk-9tpmfh3n.js.map} +0 -0
  368. /package/dist/{chunk-naxjka9v.js.map → chunk-brhp9d97.js.map} +0 -0
  369. /package/dist/{chunk-8a8k38tz.js.map → chunk-brybqw5k.js.map} +0 -0
  370. /package/dist/{chunk-vehcr9eb.js.map → chunk-cg7cygfj.js.map} +0 -0
  371. /package/dist/{chunk-r2psmn42.js.map → chunk-eg6xqef7.js.map} +0 -0
  372. /package/dist/{chunk-zxhym8tr.js.map → chunk-f05994as.js.map} +0 -0
  373. /package/dist/{chunk-1yh6jgtz.js.map → chunk-grt2j5vp.js.map} +0 -0
  374. /package/dist/{chunk-rtdrm592.js.map → chunk-htdzx40w.js.map} +0 -0
  375. /package/dist/{chunk-bc3y6gff.js.map → chunk-jka26v8c.js.map} +0 -0
  376. /package/dist/{chunk-pqvvqc65.js.map → chunk-pqj8vff9.js.map} +0 -0
  377. /package/dist/{chunk-wqe9shx2.js.map → chunk-qbd282aa.js.map} +0 -0
  378. /package/dist/{chunk-fzae1jpq.js.map → chunk-t19wjmnc.js.map} +0 -0
  379. /package/dist/{chunk-paxabbqd.js.map → chunk-tapdssb5.js.map} +0 -0
  380. /package/dist/{chunk-dhkc9b23.js.map → chunk-v8a1qjzp.js.map} +0 -0
  381. /package/dist/{chunk-pc7kra3k.js.map → chunk-xavet0qs.js.map} +0 -0
  382. /package/dist/{chunk-0hkdtwqk.js.map → chunk-xf76csps.js.map} +0 -0
  383. /package/dist/{chunk-m9ketb51.js.map → chunk-ygvay56w.js.map} +0 -0
  384. /package/dist/{chunk-b4escq4c.js.map → chunk-ykchk644.js.map} +0 -0
  385. /package/dist/{chunk-k29n4176.js.map → chunk-ym1bqd98.js.map} +0 -0
@@ -35,11 +35,11 @@ import {
35
35
  normalizeLinkProperties2,
36
36
  validateLinkProperties2,
37
37
  assertTelemetryProperty2
38
- } from "./chunk-3zagkr6w.js";
38
+ } from "./chunk-7mhbs9yy.js";
39
39
  import {
40
40
  isObjectRefSchema2,
41
41
  validateSchemaOrRefValue2
42
- } from "./chunk-8a8k38tz.js";
42
+ } from "./chunk-brybqw5k.js";
43
43
  import {
44
44
  ActionDefinitionError2,
45
45
  missingActionMutationMessage,
@@ -60,7 +60,7 @@ import {
60
60
  createUsersRuntime,
61
61
  SYSTEM_PRINCIPAL2,
62
62
  principalsEqual2
63
- } from "./chunk-xcrnrpfh.js";
63
+ } from "./chunk-394zjzjs.js";
64
64
  import {
65
65
  ActionValidationError2,
66
66
  SIXB_ERROR_CODES2,
@@ -97,7 +97,7 @@ import {
97
97
  canViewProjectionRun2,
98
98
  canViewPrimitiveRun2,
99
99
  canViewProjection2
100
- } from "./chunk-paxabbqd.js";
100
+ } from "./chunk-tapdssb5.js";
101
101
  import {
102
102
  compileSelectedObjectReadScope2
103
103
  } from "./chunk-rt9deb92.js";
@@ -107,7 +107,7 @@ import {
107
107
  resolveAgentExecutionAuthorization2,
108
108
  userCanRunAgent2,
109
109
  resolveInheritedAgentExecutionAuthorization2
110
- } from "./chunk-s5pj68fa.js";
110
+ } from "./chunk-5sswe5ej.js";
111
111
  import {
112
112
  ACTION_RUN_FAILURE_CODES2,
113
113
  parseActionRunFailure2
@@ -145,15 +145,22 @@ import {
145
145
  createAgentMessageId2,
146
146
  createAgentInboxItemId,
147
147
  AGENT_REASONING_LEVELS2,
148
+ countsAsThreadMessage2,
148
149
  movesComputerPlace2,
150
+ turnPlace2,
151
+ runPlaceKey2,
149
152
  isAgentApprovalMode2,
150
153
  agentApprovalHoldsRun2
151
- } from "./chunk-ey1p8w68.js";
154
+ } from "./chunk-gaj8djsw.js";
155
+ import {
156
+ canonicalLocale,
157
+ canonicalTimeZone2
158
+ } from "./chunk-dq3t5sr3.js";
152
159
  import {
153
160
  actionRunRequestsEqual,
154
161
  ObjectNotFoundError2,
155
162
  ArtifactStorageError
156
- } from "./chunk-ewqn51gr.js";
163
+ } from "./chunk-88xeh6zx.js";
157
164
  import {
158
165
  ExecutionStorageError2
159
166
  } from "./chunk-c29729me.js";
@@ -167,20 +174,22 @@ import {
167
174
  objectBatchKey2,
168
175
  matchesPredicate,
169
176
  WORKFLOW_RUN_FAILURE_CODES2
170
- } from "./chunk-gjhrz66x.js";
177
+ } from "./chunk-9c9yknwt.js";
171
178
  import {
172
179
  explainObjectQuery2
173
- } from "./chunk-s1mqyqmm.js";
180
+ } from "./chunk-bs1sd0e0.js";
174
181
  import {
175
182
  redactDomainEvent,
176
183
  uniqueLookupKeyOf,
177
184
  assertAuthorizedObjectReaderBinding,
178
185
  getAuthorizedOntologyView,
186
+ getQueryDiscovery,
179
187
  readerClearance,
180
188
  readerEventClearance,
181
189
  readerViewConditions
182
- } from "./chunk-5t9gm5tt.js";
190
+ } from "./chunk-fmgf9h5e.js";
183
191
  import {
192
+ agentRunEndedShort,
184
193
  createAgentThreadAccessRule,
185
194
  assertConversationThread2,
186
195
  agentThreadViews,
@@ -191,7 +200,7 @@ import {
191
200
  transactionArtifactAccessRules,
192
201
  updatableArtifactIds,
193
202
  createArtifactsRuntime
194
- } from "./chunk-m3qx2pns.js";
203
+ } from "./chunk-jt012fxq.js";
195
204
  import {
196
205
  shareSixbErrorReporter2,
197
206
  reportActionPhaseFailure2,
@@ -213,14 +222,14 @@ import {
213
222
  createActivityCaptureRuntime,
214
223
  registerActivityCaptureRuntime,
215
224
  ModelExecutionSession
216
- } from "./chunk-k29n4176.js";
225
+ } from "./chunk-ym1bqd98.js";
217
226
  import {
218
227
  publishAgentThreadMoved2,
219
228
  publishAgentApprovalActivity,
220
229
  publishAgentRunActivity2,
221
230
  publishAgentRunCancel2,
222
231
  publishAgentRunFinished2
223
- } from "./chunk-k3jh8gsg.js";
232
+ } from "./chunk-kft7mp7z.js";
224
233
  import {
225
234
  aiLimitSubjectsFromAttribution2,
226
235
  applicableAiLimitPolicyStatuses2,
@@ -236,10 +245,10 @@ import {
236
245
  } from "./chunk-8ncg20rd.js";
237
246
  import {
238
247
  registerConnectorConnectionsRuntime
239
- } from "./chunk-5a4a52tq.js";
248
+ } from "./chunk-0pmpwn3g.js";
240
249
  import {
241
250
  createConnectorRuntime
242
- } from "./chunk-qavwr628.js";
251
+ } from "./chunk-n1hbwc6y.js";
243
252
  import {
244
253
  DatasetValidationError2
245
254
  } from "./chunk-wx7smkn2.js";
@@ -256,7 +265,7 @@ import {
256
265
  aiModelCallOutputTokenAllowance,
257
266
  ModelUsageRecordingError2,
258
267
  LanguageModelCallMeter
259
- } from "./chunk-1yh6jgtz.js";
268
+ } from "./chunk-grt2j5vp.js";
260
269
  import {
261
270
  createLinkScopeFingerprint2,
262
271
  normalizeJsonProperties2,
@@ -266,7 +275,15 @@ import {
266
275
  resolveEffectiveLink,
267
276
  resolveEffectiveLinkSlotMember,
268
277
  linkCardinality
269
- } from "./chunk-b4escq4c.js";
278
+ } from "./chunk-ykchk644.js";
279
+ import {
280
+ createSyncConnections,
281
+ mayRunConnection,
282
+ visibleSyncConnectionIds,
283
+ seesConnection,
284
+ SyncValidationError2,
285
+ requestSyncRun2
286
+ } from "./chunk-90nqenq8.js";
270
287
  import {
271
288
  resolveLoggingService2
272
289
  } from "./chunk-1vg43g9q.js";
@@ -274,13 +291,15 @@ import {
274
291
  EditBatchError2,
275
292
  lowerEditBatch2
276
293
  } from "./chunk-m427qgq0.js";
277
- import {
278
- SyncValidationError2,
279
- requestSyncRun2
280
- } from "./chunk-aw1z0gre.js";
281
294
  import {
282
295
  compileShareAccessPlan
283
- } from "./chunk-wqe9shx2.js";
296
+ } from "./chunk-qbd282aa.js";
297
+ import {
298
+ requestPipelineRun2
299
+ } from "./chunk-pqj8vff9.js";
300
+ import {
301
+ PipelineError2
302
+ } from "./chunk-hke9aeen.js";
284
303
  import {
285
304
  createObjectQueryBuilder2,
286
305
  decorateObjectQueryExecutor
@@ -289,25 +308,19 @@ import {
289
308
  SandboxError2,
290
309
  sandboxCredentialIssue2,
291
310
  staticSandboxRecipe2
292
- } from "./chunk-rtdrm592.js";
311
+ } from "./chunk-htdzx40w.js";
312
+ import {
313
+ executionRecordInputFromRuntime,
314
+ ensureExecutionRecord2,
315
+ createPrimitiveExecutionRecord,
316
+ restoreTrustedPrimitiveExecutionScope
317
+ } from "./chunk-xavet0qs.js";
293
318
  import {
294
319
  resolveLanguageModel2
295
320
  } from "./chunk-3723kgba.js";
296
321
  import {
297
322
  schemaRecordToJsonSchema2
298
323
  } from "./chunk-0kgrghqx.js";
299
- import {
300
- requestPipelineRun2
301
- } from "./chunk-pqvvqc65.js";
302
- import {
303
- PipelineError2
304
- } from "./chunk-hke9aeen.js";
305
- import {
306
- executionRecordInputFromRuntime,
307
- ensureExecutionRecord2,
308
- createPrimitiveExecutionRecord,
309
- restoreTrustedPrimitiveExecutionScope
310
- } from "./chunk-pc7kra3k.js";
311
324
  import {
312
325
  lineageColumn,
313
326
  isUnknownLineage,
@@ -340,18 +353,25 @@ import {
340
353
  import {
341
354
  eventAttribution2
342
355
  } from "./chunk-q7g9cqwt.js";
356
+ import {
357
+ isOAuthConnectorDefinition2
358
+ } from "./chunk-pvpq483h.js";
343
359
  import {
344
360
  ObjectQueryPlanningError2
345
361
  } from "./chunk-0k1h5hmr.js";
346
362
  import {
347
363
  normalizeParams
348
- } from "./chunk-stmxh0hv.js";
364
+ } from "./chunk-3neam1y5.js";
349
365
  import {
350
366
  MaterializationValidationError2,
351
367
  MaterializationObjectNotFoundError2,
352
368
  UniqueValueViolationError2,
353
369
  isMaterializationConflictError2
354
370
  } from "./chunk-y7dbmaqh.js";
371
+ import {
372
+ OntologyValidationError2,
373
+ OntologyNotFoundError2
374
+ } from "./chunk-cqr3acm1.js";
355
375
  import {
356
376
  ModelProviderError2,
357
377
  ModelStreamError2,
@@ -359,10 +379,6 @@ import {
359
379
  StructuredOutputError2,
360
380
  sameEmbeddingModel
361
381
  } from "./chunk-rtkqczbr.js";
362
- import {
363
- OntologyValidationError2,
364
- OntologyNotFoundError2
365
- } from "./chunk-cqr3acm1.js";
366
382
  import {
367
383
  AgentRequestError2,
368
384
  AgentMemoryError2
@@ -1941,10 +1957,16 @@ async function questionState(agents, conversationId, thread, runs) {
1941
1957
  const waiting = [...runs].reverse().find((run) => run.status !== "failed" && run.status !== "cancelled");
1942
1958
  if (!waiting || !isAwaitingAnswerRun2(waiting))
1943
1959
  return {};
1960
+ const { total } = await agents.messages.list({
1961
+ projectId: waiting.projectId,
1962
+ threadId: conversationId,
1963
+ limit: 1
1964
+ });
1944
1965
  const [latest] = await agents.runs.listThreadSubagents({
1945
1966
  projectId: waiting.projectId,
1946
1967
  threadId: conversationId,
1947
1968
  spawnKey: waiting.spawnKey,
1969
+ ...total > 0 ? { retainedTurnsOnly: true } : {},
1948
1970
  limit: 1
1949
1971
  });
1950
1972
  if (latest && latest.threadId !== thread.id)
@@ -2323,11 +2345,11 @@ function createTurnModelRouter(models, decision) {
2323
2345
  if (!language || language.tiers.length === 0 || !models?.decision)
2324
2346
  return;
2325
2347
  return {
2326
- async choose(text, previous) {
2348
+ async choose(text, previous, place) {
2327
2349
  const tierProbabilities = text.trim() ? await askTier(decision, text) : undefined;
2328
2350
  const tier = tierProbabilities ? tierFor(tierProbabilities) : "standard";
2329
2351
  return {
2330
- model: turnModel(language, tier, previous),
2352
+ model: turnModel(language, tier, previous, place),
2331
2353
  ...tierProbabilities ? { tierProbabilities } : {}
2332
2354
  };
2333
2355
  }
@@ -2361,9 +2383,9 @@ function tierFor(probabilities) {
2361
2383
  return "light";
2362
2384
  return "standard";
2363
2385
  }
2364
- function turnModel(language, tier, previous) {
2386
+ function turnModel(language, tier, previous, place) {
2365
2387
  const target = language.getByTier(tier);
2366
- const last = previous && previousTurn(language, previous);
2388
+ const last = previous && previousTurn(language, previous, place);
2367
2389
  if (!last)
2368
2390
  return target;
2369
2391
  const change = tierRank(target.tier ?? tier) - tierRank(last.tier);
@@ -2373,7 +2395,7 @@ function turnModel(language, tier, previous) {
2373
2395
  return last.model;
2374
2396
  return target;
2375
2397
  }
2376
- function previousTurn(language, run) {
2398
+ function previousTurn(language, run, place) {
2377
2399
  if (!run.spec)
2378
2400
  return;
2379
2401
  const model = language.getByRef(run.spec.model);
@@ -2381,7 +2403,12 @@ function previousTurn(language, run) {
2381
2403
  if (tier === undefined)
2382
2404
  return;
2383
2405
  const lastCallAt = run.completedAt ?? run.startedAt ?? run.createdAt;
2384
- return { model, tier, cacheWarm: Date.now() - lastCallAt.getTime() < PROMPT_CACHE_TTL_MS };
2406
+ const samePlace = runPlaceKey2(run.spec) === runPlaceKey2(place);
2407
+ return {
2408
+ model,
2409
+ tier,
2410
+ cacheWarm: samePlace && Date.now() - lastCallAt.getTime() < PROMPT_CACHE_TTL_MS
2411
+ };
2385
2412
  }
2386
2413
  function tierRank(tier) {
2387
2414
  return LANGUAGE_MODEL_TIERS2.indexOf(tier);
@@ -2538,29 +2565,6 @@ function startQueuedAgentTurn2(sixb, runId, options) {
2538
2565
  // src/agents/request.ts
2539
2566
  import { randomUUID as randomUUID5 } from "crypto";
2540
2567
 
2541
- // src/runtime/locale.ts
2542
- var DEFAULT_PROJECT_LOCALE = "en";
2543
- var DEFAULT_PROJECT_TIME_ZONE = "UTC";
2544
- function canonicalLocale(value) {
2545
- if (typeof value !== "string")
2546
- return;
2547
- try {
2548
- const [locale] = Intl.getCanonicalLocales(value);
2549
- return locale;
2550
- } catch {
2551
- return;
2552
- }
2553
- }
2554
- function canonicalTimeZone(value) {
2555
- if (typeof value !== "string" || value.trim() !== value || value === "")
2556
- return;
2557
- try {
2558
- return new Intl.DateTimeFormat("en-US", { timeZone: value }).resolvedOptions().timeZone;
2559
- } catch {
2560
- return;
2561
- }
2562
- }
2563
-
2564
2568
  // src/agents/context-resolution.ts
2565
2569
  async function resolveAgentContextParts2(runtime, input) {
2566
2570
  const entries = normalizeAgentContextEntries2(input);
@@ -2713,18 +2717,15 @@ async function requestAgentRun2(runtime, execution, models, input) {
2713
2717
  assertComputerPlaceRequest(input.runsOn, input.computer);
2714
2718
  const runsOn = existingThread ? existingThread.runsOn : input.runsOn;
2715
2719
  const approvalMode = input.approvalMode ?? (await resolveAgentApprovalMode(agents, { projectId, principal, threadId: existingThread?.id })).approvalMode;
2716
- const selected = "router" in requested ? await routedConversationRunSpec(agents, {
2720
+ const place = turnPlace2(runsOn, existingThread ? existingThread.computer : input.computer);
2721
+ const selected = "router" in requested ? await routedConversationRunSpec({
2717
2722
  ...requested,
2718
- projectId,
2719
- threadId: existingThread?.id,
2723
+ previous: existingThread ? await latestConversationRun(agents, projectId, existingThread.id) : undefined,
2724
+ place,
2720
2725
  settings,
2721
2726
  language: models.language
2722
2727
  }) : requested;
2723
- const spec = Object.freeze({
2724
- ...selected,
2725
- approvalMode,
2726
- ...runsOn === undefined ? {} : { runsOn }
2727
- });
2728
+ const spec = Object.freeze({ ...selected, approvalMode, ...place });
2728
2729
  const createdThread = existingThread === null;
2729
2730
  const thread = existingThread ?? await createThread(agents, {
2730
2731
  projectId,
@@ -2788,11 +2789,354 @@ async function requestAgentRun2(runtime, execution, models, input) {
2788
2789
  createdThread
2789
2790
  };
2790
2791
  }
2792
+ function isEditableAgentMessage2(message) {
2793
+ if (message.role !== "user")
2794
+ return false;
2795
+ if (message.parts.some((part) => part.type === "continuation"))
2796
+ return false;
2797
+ return countsAsThreadMessage2(message);
2798
+ }
2799
+ async function editAgentMessage2(runtime, execution, models, input, blobStorage) {
2800
+ const authority = resolveExecutionScopeAuthorization(runtime.projectId, {
2801
+ execution,
2802
+ authorization: runtime.runtimeAuthorization
2803
+ });
2804
+ assertNoAgentSelector(input);
2805
+ assertAuthorized2(runtime, { kind: "agent.run" });
2806
+ assertRequestAuthorityCanRunAgent(runtime);
2807
+ const trigger = triggerParts(input);
2808
+ const selection = { model: input.model, reasoning: input.reasoning };
2809
+ const settings = requesterSettings(input);
2810
+ if (input.approvalMode !== undefined)
2811
+ assertAgentApprovalMode(input.approvalMode);
2812
+ const routed = routedTurn(models.router, selection, input);
2813
+ const requested = routed ?? await resolveConversationRunSpec({ models: models.language, selection, settings });
2814
+ assertAttachments(input.attachments);
2815
+ const contextParts = await resolveAgentContextParts2(runtime, input.context);
2816
+ const agents = requireAgentStorage(runtime);
2817
+ const projectId = runtime.projectId;
2818
+ const principal = authority.type === "principal" ? authority.context.principal : input.principal ?? SYSTEM_PRINCIPAL2;
2819
+ const thread = await agents.threads.getById({ projectId, id: input.threadId });
2820
+ if (!thread) {
2821
+ throw new AgentRequestError2("thread_not_found", `[Sixb] Agent thread '${input.threadId}' not found.`);
2822
+ }
2823
+ assertThreadAcceptsMessages(thread, principal);
2824
+ const target = await agents.messages.getById({ projectId, id: input.messageId });
2825
+ if (!target || target.threadId !== thread.id) {
2826
+ throw new AgentRequestError2("message_not_found", `[Sixb] Agent message '${input.messageId}' not found in thread '${thread.id}'.`);
2827
+ }
2828
+ assertEditableMessageAuthority(thread, target, principal);
2829
+ const tail = await listAllThreadMessagesFromSeq(agents, projectId, thread.id, target.seq);
2830
+ assertParticipantCanRewindTail(thread, tail, principal);
2831
+ const rewoundRuns = await listRewoundConversationRuns(agents, projectId, thread.id, tail);
2832
+ assertRewindsWholeTurns(target, tail, rewoundRuns);
2833
+ const approvalMode = input.approvalMode ?? (await resolveAgentApprovalMode(agents, { projectId, principal, threadId: thread.id })).approvalMode;
2834
+ const place = turnPlace2(thread.runsOn, thread.computer);
2835
+ const selected = "router" in requested ? await routedConversationRunSpec({
2836
+ ...requested,
2837
+ previous: await latestRetainedConversationRun(agents, projectId, thread.id, tail),
2838
+ place,
2839
+ settings,
2840
+ language: models.language
2841
+ }) : requested;
2842
+ const spec = Object.freeze({ ...selected, approvalMode, ...place });
2843
+ const edit = {
2844
+ target,
2845
+ messageId: input.nextMessageId ?? createAgentMessageId2(),
2846
+ authorPrincipal: principal,
2847
+ parts: [
2848
+ ...contextParts,
2849
+ ...trigger,
2850
+ ...(input.attachments ?? []).map((fileRef) => ({ type: "file", fileRef }))
2851
+ ]
2852
+ };
2853
+ const runId = createAgentRunId2();
2854
+ const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId);
2855
+ await assertAiLimitPreflight(runtime, durableExecution);
2856
+ if (thread.activeRunId !== null) {
2857
+ const item = await deferAgentMessageEdit(runtime, execution, thread, edit, {
2858
+ spec,
2859
+ settings,
2860
+ blobStorage
2861
+ });
2862
+ return { kind: "inbox", item };
2863
+ }
2864
+ const documents = await rewoundTurnDocuments(runtime, blobStorage, rewoundRuns, tail);
2865
+ let run;
2866
+ let rewind;
2867
+ let superseded = [];
2868
+ try {
2869
+ run = await runtime.storage.transaction(async (tx) => {
2870
+ const txAgents = tx.agents;
2871
+ if (!txAgents) {
2872
+ throw new AgentRequestError2("storage_unavailable", "[Sixb] Agent storage is not configured.");
2873
+ }
2874
+ rewind = await rewindAgentThread(tx, txAgents, {
2875
+ projectId,
2876
+ thread,
2877
+ messageId: edit.target.id,
2878
+ editor: principal,
2879
+ documents
2880
+ });
2881
+ await tx.executions.create(durableExecution);
2882
+ const reported = await reportAgentApprovals(txAgents, {
2883
+ projectId,
2884
+ threadId: thread.id,
2885
+ messageId: edit.messageId
2886
+ });
2887
+ superseded = reported.superseded;
2888
+ await txAgents.messages.append({
2889
+ id: edit.messageId,
2890
+ projectId,
2891
+ threadId: thread.id,
2892
+ runId: null,
2893
+ role: "user",
2894
+ parts: [...reported.parts, ...edit.parts],
2895
+ authorPrincipal: principal
2896
+ });
2897
+ return txAgents.runs.create({
2898
+ id: runId,
2899
+ projectId,
2900
+ executionId: durableExecution.id,
2901
+ threadId: thread.id,
2902
+ triggerMessageId: edit.messageId,
2903
+ spec
2904
+ });
2905
+ });
2906
+ } catch (error) {
2907
+ if (error instanceof AgentStorageError2 && error.code === "active_run_exists") {
2908
+ throw new AgentRequestError2("active_run_exists", error.message);
2909
+ }
2910
+ throw error;
2911
+ }
2912
+ await announceAgentThreadRewind(runtime, rewind, superseded);
2913
+ await publishRunActivity(runtime, run);
2914
+ await dispatchAgentRun(runtime, agents, runId);
2915
+ return { kind: "turn", run, createdThread: false };
2916
+ }
2917
+ async function deferAgentMessageEdit(runtime, execution, thread, edit, options) {
2918
+ const { spec, settings } = options;
2919
+ const agents = requireAgentStorage(runtime);
2920
+ const projectId = runtime.projectId;
2921
+ const active = thread.activeRunId ? await agents.runs.getById({ projectId, id: thread.activeRunId }) : null;
2922
+ if (active?.kind !== "conversation") {
2923
+ throw new AgentRequestError2("active_run_exists", `[Sixb] Agent thread '${thread.id}' already has an active run '${thread.activeRunId}'.`);
2924
+ }
2925
+ if (!execution.requestedBy) {
2926
+ throw new AgentRequestError2("active_run_exists", `[Sixb] Agent thread '${thread.id}' is answering, and an edit without a signed-in sender cannot wait for it: stop the answer, then edit.`);
2927
+ }
2928
+ const mayStop = principalsEqual2(edit.authorPrincipal, thread.ownerPrincipal) || await askedForTurn(runtime, active, edit.authorPrincipal);
2929
+ if (!mayStop) {
2930
+ throw new AgentRequestError2("not_run_requester", `[Sixb] Agent thread '${thread.id}' runs a turn someone else asked for: only they or the thread's owner can stop it. Edit the message once it ends.`);
2931
+ }
2932
+ const request = await ensureExecutionRecord2(runtime.storage.executions, executionRecordInputFromRuntime({
2933
+ execution,
2934
+ runtimeAuthorization: runtime.runtimeAuthorization
2935
+ }));
2936
+ for (const waiting of await agents.inbox.list({ projectId, threadId: thread.id })) {
2937
+ if (waiting.replacesMessageId !== undefined && principalsEqual2(waiting.authorPrincipal, edit.authorPrincipal)) {
2938
+ await agents.inbox.remove({ projectId, threadId: thread.id, id: waiting.id });
2939
+ }
2940
+ }
2941
+ const { item } = await agents.inbox.enqueue({
2942
+ id: createAgentInboxItemId(),
2943
+ projectId,
2944
+ threadId: thread.id,
2945
+ messageId: edit.messageId,
2946
+ authorPrincipal: edit.authorPrincipal,
2947
+ mode: "queue",
2948
+ immediate: true,
2949
+ replacesMessageId: edit.target.id,
2950
+ parts: edit.parts,
2951
+ spec: {
2952
+ model: spec.model,
2953
+ ...spec.reasoning === undefined ? {} : { reasoning: spec.reasoning },
2954
+ approvalMode: spec.approvalMode
2955
+ },
2956
+ ...settings,
2957
+ executionId: request.id
2958
+ });
2959
+ await queueWaitingSteers(agents, projectId, thread.id, edit.authorPrincipal);
2960
+ await stopTurnBefore(runtime, execution, active, options.blobStorage);
2961
+ await startIfThreadIdle(runtime, execution, thread.id, options.blobStorage);
2962
+ return item;
2963
+ }
2964
+ async function rewindAgentThread(tx, agents, input) {
2965
+ const { projectId, thread, editor } = input;
2966
+ const target = await agents.messages.getById({ projectId, id: input.messageId });
2967
+ if (!target || target.threadId !== thread.id) {
2968
+ throw new AgentRequestError2("message_not_found", `[Sixb] Agent message '${input.messageId}' not found in thread '${thread.id}'.`);
2969
+ }
2970
+ assertEditableMessageAuthority(thread, target, editor);
2971
+ const tail = await listAllThreadMessagesFromSeq(agents, projectId, thread.id, target.seq);
2972
+ assertParticipantCanRewindTail(thread, tail, editor);
2973
+ const rewoundRuns = await listRewoundConversationRuns(agents, projectId, thread.id, tail);
2974
+ assertRewindsWholeTurns(target, tail, rewoundRuns);
2975
+ const restored = new Map;
2976
+ if (tx.artifacts) {
2977
+ for (const { run, later } of oldestFirst(rewoundRuns, tail)) {
2978
+ const trigger = tail.find((message) => message.id === run.triggerMessageId);
2979
+ const undone = await tx.artifacts.undoTurnWrites({
2980
+ projectId,
2981
+ turnRunId: run.id,
2982
+ laterTurnRunIds: later,
2983
+ documents: input.documents.get(run.id) ?? {},
2984
+ ...trigger?.authorPrincipal ? { requester: trigger.authorPrincipal } : {}
2985
+ });
2986
+ for (const entry of undone.restored)
2987
+ restored.set(entry.artifact.id, entry.version);
2988
+ for (const deletedId of undone.deleted)
2989
+ restored.delete(deletedId);
2990
+ }
2991
+ }
2992
+ const approvals = await agents.approvals.rewind({
2993
+ projectId,
2994
+ threadId: thread.id,
2995
+ runIds: rewoundRuns.map((run) => run.id),
2996
+ clearedMessageIds: tail.map((message) => message.id)
2997
+ });
2998
+ await agents.checkpoints.deleteAfterSeq({
2999
+ projectId,
3000
+ threadId: thread.id,
3001
+ afterSeq: target.seq - 1
3002
+ });
3003
+ await agents.messages.deleteFromSeq({ projectId, threadId: thread.id, fromSeq: target.seq });
3004
+ await queueWaitingSteers(agents, projectId, thread.id, editor);
3005
+ return { restoredVersions: [...restored.values()], cancelledApprovals: approvals.cancelled };
3006
+ }
3007
+ async function queueWaitingSteers(agents, projectId, threadId, editor) {
3008
+ const waiting = await agents.inbox.list({ projectId, threadId, includeClaimed: false });
3009
+ for (const item of waiting) {
3010
+ if (item.mode !== "steer" || item.immediate)
3011
+ continue;
3012
+ if (!principalsEqual2(item.authorPrincipal, editor))
3013
+ continue;
3014
+ try {
3015
+ await agents.inbox.update({ projectId, threadId, id: item.id, mode: "queue" });
3016
+ } catch (error) {
3017
+ if (error instanceof AgentStorageError2 && error.code === "invalid_state")
3018
+ continue;
3019
+ throw error;
3020
+ }
3021
+ }
3022
+ }
3023
+ async function rewoundTurnDocuments(runtime, blobStorage, rewoundRuns, tail) {
3024
+ const documents = new Map;
3025
+ const artifacts = runtime.storage.artifacts;
3026
+ if (!artifacts || !blobStorage)
3027
+ return documents;
3028
+ for (const { run, later } of oldestFirst(rewoundRuns, tail)) {
3029
+ documents.set(run.id, await undoneTurnDocuments({ projectId: runtime.projectId, storage: artifacts, blobStorage }, run.id, later));
3030
+ }
3031
+ return documents;
3032
+ }
3033
+ function oldestFirst(rewoundRuns, tail) {
3034
+ const seqOf = new Map(tail.map((message) => [message.id, message.seq]));
3035
+ const started = (run) => (run.startedAt ?? run.createdAt).getTime();
3036
+ const ordered = [...rewoundRuns].sort((left, right) => (seqOf.get(left.triggerMessageId) ?? 0) - (seqOf.get(right.triggerMessageId) ?? 0) || started(left) - started(right) || left.attempt - right.attempt);
3037
+ return ordered.map((run, index) => ({
3038
+ run,
3039
+ later: ordered.slice(index + 1).map((each) => each.id)
3040
+ }));
3041
+ }
3042
+ async function announceAgentThreadRewind(runtime, rewind, superseded) {
3043
+ await announceArtifactUpdates(runtime.events, rewind?.restoredVersions ?? []);
3044
+ await announceAgentApprovals2(runtime.broker, [
3045
+ ...rewind?.cancelledApprovals ?? [],
3046
+ ...superseded
3047
+ ]);
3048
+ }
3049
+ function assertEditableMessageAuthority(_thread, target, principal) {
3050
+ if (!isEditableAgentMessage2(target)) {
3051
+ throw new AgentRequestError2("message_not_editable", `[Sixb] Only user-authored messages can be edited.`);
3052
+ }
3053
+ if (principal.type === "user" && (!target.authorPrincipal || !principalsEqual2(target.authorPrincipal, principal))) {
3054
+ throw new AgentRequestError2("not_message_author", `[Sixb] Only the author of message '${target.id}' can edit it.`);
3055
+ }
3056
+ }
3057
+ function assertParticipantCanRewindTail(thread, tail, principal) {
3058
+ if (principal.type !== "user" || principalsEqual2(principal, thread.ownerPrincipal))
3059
+ return;
3060
+ const erasesOthers = tail.some((message) => message.role === "user" && countsAsThreadMessage2(message) && message.authorPrincipal !== undefined && !principalsEqual2(message.authorPrincipal, principal));
3061
+ if (erasesOthers) {
3062
+ throw new AgentRequestError2("not_thread_owner", "[Sixb] Only the thread's owner can rewind past another person's messages.");
3063
+ }
3064
+ }
3065
+ function assertRewindsWholeTurns(target, tail, rewoundRuns) {
3066
+ const removed = new Set(tail.map((message) => message.id));
3067
+ const cut = rewoundRuns.find((run) => !removed.has(run.triggerMessageId));
3068
+ if (!cut)
3069
+ return;
3070
+ throw new AgentRequestError2("message_not_editable", `[Sixb] Agent message '${target.id}' came in while the Agent was answering message '${cut.triggerMessageId}': edit that message instead.`);
3071
+ }
3072
+ async function listAllThreadMessagesFromSeq(agents, projectId, threadId, fromSeq) {
3073
+ const messages = [];
3074
+ const afterSeq = fromSeq - 1;
3075
+ for (;; ) {
3076
+ const page = await agents.messages.list({
3077
+ projectId,
3078
+ threadId,
3079
+ afterSeq,
3080
+ order: "asc",
3081
+ limit: 200,
3082
+ offset: messages.length
3083
+ });
3084
+ messages.push(...page.messages);
3085
+ if (!page.hasMore || page.messages.length === 0)
3086
+ return messages;
3087
+ }
3088
+ }
3089
+ async function listRewoundConversationRuns(agents, projectId, threadId, tail) {
3090
+ const removedMessageIds = new Set(tail.map((message) => message.id));
3091
+ const removedRunIds = new Set(tail.flatMap((message) => message.runId === null ? [] : [message.runId]));
3092
+ const found = [];
3093
+ for (let offset = 0;; ) {
3094
+ const page = await agents.runs.list({
3095
+ projectId,
3096
+ threadId,
3097
+ kinds: ["conversation"],
3098
+ order: "desc",
3099
+ limit: 100,
3100
+ offset
3101
+ });
3102
+ for (const run of page.runs) {
3103
+ if (run.kind === "conversation" && (removedMessageIds.has(run.triggerMessageId) || removedRunIds.has(run.id))) {
3104
+ found.push(run);
3105
+ }
3106
+ }
3107
+ offset += page.runs.length;
3108
+ if (!page.hasMore || page.runs.length === 0)
3109
+ return found;
3110
+ }
3111
+ }
3112
+ async function latestRetainedConversationRun(agents, projectId, threadId, tail) {
3113
+ const notRetained = new Set(tail.map((message) => message.id));
3114
+ for (let offset = 0;; ) {
3115
+ const page = await agents.runs.list({
3116
+ projectId,
3117
+ threadId,
3118
+ kinds: ["conversation"],
3119
+ order: "desc",
3120
+ limit: 50,
3121
+ offset
3122
+ });
3123
+ for (const run of page.runs) {
3124
+ if (run.kind !== "conversation" || notRetained.has(run.triggerMessageId))
3125
+ continue;
3126
+ if (await agents.messages.getById({ projectId, id: run.triggerMessageId }))
3127
+ return run;
3128
+ notRetained.add(run.triggerMessageId);
3129
+ }
3130
+ offset += page.runs.length;
3131
+ if (!page.hasMore || page.runs.length === 0)
3132
+ return;
3133
+ }
3134
+ }
2791
3135
  function isRetryableAgentRun2(run) {
2792
3136
  return run.status === "failed" || run.status === "cancelled" && run.finishReason === "interrupted";
2793
3137
  }
2794
3138
  async function retryAgentRun2(runtime, execution, models, failedRun, blobStorage) {
2795
- resolveExecutionScopeAuthorization(runtime.projectId, {
3139
+ const authority = resolveExecutionScopeAuthorization(runtime.projectId, {
2796
3140
  execution,
2797
3141
  authorization: runtime.runtimeAuthorization
2798
3142
  });
@@ -2810,6 +3154,9 @@ async function retryAgentRun2(runtime, execution, models, failedRun, blobStorage
2810
3154
  throw new AgentRequestError2("thread_not_found", `[Sixb] Agent thread '${failedRun.threadId}' was not found.`);
2811
3155
  }
2812
3156
  assertSandboxExecutionAvailable(thread);
3157
+ if (authority.type === "principal" && thread.runsOn === "computer" && !principalsEqual2(authority.context.principal, thread.ownerPrincipal)) {
3158
+ throw new AgentRequestError2("not_thread_owner", `[Sixb] Agent thread '${thread.id}' runs on its owner's computer, as them: only its owner can retry a turn in it.`);
3159
+ }
2813
3160
  const runId = createAgentRunId2();
2814
3161
  const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId);
2815
3162
  await assertAiLimitPreflight(runtime, durableExecution);
@@ -2853,7 +3200,7 @@ async function retryAgentRun2(runtime, execution, models, failedRun, blobStorage
2853
3200
  return { run, ...jobId ? { jobId } : {}, createdThread: false };
2854
3201
  }
2855
3202
  var AGENT_MESSAGE_DELIVERIES2 = ["auto", "steer", "queue", "send_now"];
2856
- async function sendAgentMessage2(runtime, execution, models, input) {
3203
+ async function sendAgentMessage2(runtime, execution, models, input, blobStorage) {
2857
3204
  const delivery = input.delivery ?? "auto";
2858
3205
  const agents = requireAgentStorage(runtime);
2859
3206
  const projectId = runtime.projectId;
@@ -2904,12 +3251,12 @@ async function sendAgentMessage2(runtime, execution, models, input) {
2904
3251
  executionId: request.id
2905
3252
  });
2906
3253
  if (delivery === "send_now") {
2907
- await stopTurnBefore(runtime, execution, active);
3254
+ await stopTurnBefore(runtime, execution, active, blobStorage);
2908
3255
  }
2909
- await startIfThreadIdle(runtime, execution, thread.id);
3256
+ await startIfThreadIdle(runtime, execution, thread.id, blobStorage);
2910
3257
  return { kind: "inbox", item };
2911
3258
  }
2912
- async function promoteAgentInboxItem2(runtime, execution, input) {
3259
+ async function promoteAgentInboxItem2(runtime, execution, input, blobStorage) {
2913
3260
  const agents = requireAgentStorage(runtime);
2914
3261
  const projectId = runtime.projectId;
2915
3262
  const thread = await agents.threads.getById({ projectId, id: input.threadId });
@@ -2956,9 +3303,9 @@ async function promoteAgentInboxItem2(runtime, execution, input) {
2956
3303
  throw new AgentRequestError2("invalid_message", `[Sixb] Agent inbox item '${item.id}' is no longer waiting in thread '${thread.id}'.`);
2957
3304
  }
2958
3305
  if (input.immediate === true && turn) {
2959
- await stopTurnBefore(runtime, execution, turn);
3306
+ await stopTurnBefore(runtime, execution, turn, blobStorage);
2960
3307
  }
2961
- await startIfThreadIdle(runtime, execution, thread.id);
3308
+ await startIfThreadIdle(runtime, execution, thread.id, blobStorage);
2962
3309
  return updated;
2963
3310
  }
2964
3311
  async function withdrawAgentInboxItem2(runtime, execution, input) {
@@ -2992,7 +3339,7 @@ async function askedForTurn(runtime, run, principal) {
2992
3339
  const requester = (await runtime.storage.executions.getById({ projectId: runtime.projectId, id: run.executionId }))?.requestedBy;
2993
3340
  return requester !== undefined && principalsEqual2(requester, principal);
2994
3341
  }
2995
- async function stopTurnBefore(runtime, execution, active) {
3342
+ async function stopTurnBefore(runtime, execution, active, blobStorage) {
2996
3343
  if (active.status === "running") {
2997
3344
  await cancelAgentRun(runtime, active);
2998
3345
  return;
@@ -3000,9 +3347,9 @@ async function stopTurnBefore(runtime, execution, active) {
3000
3347
  await cancelAgentRun(runtime, active).catch(() => {
3001
3348
  return;
3002
3349
  });
3003
- await startQueuedAgentTurnFromInbox2(runtime, execution, active, { onlyImmediate: true });
3350
+ await startQueuedAgentTurnFromInbox2(runtime, execution, active, { onlyImmediate: true }, blobStorage);
3004
3351
  }
3005
- async function startIfThreadIdle(runtime, execution, threadId) {
3352
+ async function startIfThreadIdle(runtime, execution, threadId, blobStorage) {
3006
3353
  const agents = requireAgentStorage(runtime);
3007
3354
  const projectId = runtime.projectId;
3008
3355
  try {
@@ -3021,7 +3368,7 @@ async function startIfThreadIdle(runtime, execution, threadId) {
3021
3368
  if (last?.kind !== "conversation")
3022
3369
  return;
3023
3370
  const onlyImmediate = isAwaitingApprovalRun2(last) || !await turnAnsweredEveryMessage(agents, last);
3024
- await startQueuedAgentTurnFromInbox2(runtime, execution, last, { onlyImmediate });
3371
+ await startQueuedAgentTurnFromInbox2(runtime, execution, last, { onlyImmediate }, blobStorage);
3025
3372
  } catch (error) {
3026
3373
  console.error(`[Sixb] Could not start what waits in Agent thread '${threadId}'; the repair pass retries.`, error);
3027
3374
  }
@@ -3038,7 +3385,7 @@ function deliveredParts(input, delivery) {
3038
3385
  }
3039
3386
  return [...text, ...files];
3040
3387
  }
3041
- async function startQueuedAgentTurnFromInbox2(runtime, execution, finishedRun, input) {
3388
+ async function startQueuedAgentTurnFromInbox2(runtime, execution, finishedRun, input, blobStorage) {
3042
3389
  resolveExecutionScopeAuthorization(runtime.projectId, {
3043
3390
  execution,
3044
3391
  authorization: runtime.runtimeAuthorization
@@ -3063,7 +3410,10 @@ async function startQueuedAgentTurnFromInbox2(runtime, execution, finishedRun, i
3063
3410
  const runId = createAgentRunId2();
3064
3411
  const durableExecution = await prepareResumedExecution(runtime, execution, runId);
3065
3412
  await assertAiLimitPreflight(runtime, durableExecution);
3413
+ const documents = await waitingEditDocuments(runtime, blobStorage, thread, principal);
3066
3414
  let started;
3415
+ let rewind;
3416
+ let dropped;
3067
3417
  let superseded = [];
3068
3418
  try {
3069
3419
  started = await runtime.storage.transaction(async (tx) => {
@@ -3079,6 +3429,22 @@ async function startQueuedAgentTurnFromInbox2(runtime, execution, finishedRun, i
3079
3429
  });
3080
3430
  if (!item)
3081
3431
  return null;
3432
+ if (item.replacesMessageId !== undefined) {
3433
+ try {
3434
+ rewind = await rewindAgentThread(tx, agents, {
3435
+ projectId,
3436
+ thread,
3437
+ messageId: item.replacesMessageId,
3438
+ editor: item.authorPrincipal,
3439
+ documents
3440
+ });
3441
+ } catch (error) {
3442
+ if (!(error instanceof AgentRequestError2))
3443
+ throw error;
3444
+ dropped = { item, reason: error };
3445
+ return null;
3446
+ }
3447
+ }
3082
3448
  const inherited = await resolveAgentApprovalMode(agents, {
3083
3449
  projectId,
3084
3450
  principal,
@@ -3124,16 +3490,35 @@ async function startQueuedAgentTurnFromInbox2(runtime, execution, finishedRun, i
3124
3490
  }
3125
3491
  throw error;
3126
3492
  }
3493
+ if (dropped) {
3494
+ console.warn(`[Sixb] Dropped the edit of Agent message '${dropped.item.replacesMessageId}' waiting in thread '${thread.id}': it no longer applies.`, dropped.reason);
3495
+ }
3127
3496
  if (!started)
3128
3497
  return { status: "nothing" };
3129
- await announceAgentApprovals2(runtime.broker, superseded);
3498
+ await announceAgentThreadRewind(runtime, rewind, superseded);
3130
3499
  await publishRunActivity(runtime, started);
3131
3500
  await dispatchAgentRun(runtime, agents, runId);
3132
3501
  return { status: "started", run: started };
3133
3502
  }
3503
+ async function waitingEditDocuments(runtime, blobStorage, thread, principal) {
3504
+ if (!runtime.storage.artifacts || !blobStorage)
3505
+ return new Map;
3506
+ const agents = requireAgentStorage(runtime);
3507
+ const projectId = runtime.projectId;
3508
+ const waiting = await agents.inbox.list({ projectId, threadId: thread.id, includeClaimed: false });
3509
+ const next = waiting.filter((item) => item.immediate && principalsEqual2(item.authorPrincipal, principal)).sort((left, right) => left.seq - right.seq)[0];
3510
+ if (next?.replacesMessageId === undefined)
3511
+ return new Map;
3512
+ const target = await agents.messages.getById({ projectId, id: next.replacesMessageId });
3513
+ if (!target || target.threadId !== thread.id)
3514
+ return new Map;
3515
+ const tail = await listAllThreadMessagesFromSeq(agents, projectId, thread.id, target.seq);
3516
+ const rewoundRuns = await listRewoundConversationRuns(agents, projectId, thread.id, tail);
3517
+ return rewoundTurnDocuments(runtime, blobStorage, rewoundRuns, tail);
3518
+ }
3134
3519
  function queuedConversationRunSpec(thread, kept, item, approvalMode) {
3135
3520
  const model = item.spec?.model ?? kept.model;
3136
- const reasoning = item.spec?.reasoning ?? kept.reasoning;
3521
+ const reasoning = item.spec?.reasoning ?? (item.replacesMessageId === undefined ? kept.reasoning : undefined);
3137
3522
  const timeZone = item.timeZone ?? kept.timeZone;
3138
3523
  const locale = item.locale ?? kept.locale;
3139
3524
  return inPlace(thread, {
@@ -3244,8 +3629,8 @@ async function prepareResumedExecution(runtime, execution, runId) {
3244
3629
  return createInheritedAgentExecutionRecord2({ id: `exec_${randomUUID5()}`, parent, runId });
3245
3630
  }
3246
3631
  function inPlace(thread, spec) {
3247
- const { runsOn: _runsOn, ...rest } = spec;
3248
- return Object.freeze(thread.runsOn === undefined ? rest : { ...rest, runsOn: thread.runsOn });
3632
+ const { runsOn: _runsOn, computer: _computer, ...rest } = spec;
3633
+ return Object.freeze({ ...rest, ...turnPlace2(thread.runsOn, thread.computer) });
3249
3634
  }
3250
3635
  async function resumedConversationRunSpec(models, paused, approvalMode) {
3251
3636
  const kept = paused && models?.getByRef(paused.model) ? paused : await resolveConversationRunSpec({
@@ -3281,9 +3666,8 @@ function routedTurn(router, selection, input) {
3281
3666
  return;
3282
3667
  return { router, text: input.text ?? "" };
3283
3668
  }
3284
- async function routedConversationRunSpec(agents, input) {
3285
- const previous = input.threadId ? await latestConversationRun(agents, input.projectId, input.threadId) : undefined;
3286
- const choice = await input.router.choose(input.text, previous);
3669
+ async function routedConversationRunSpec(input) {
3670
+ const choice = await input.router.choose(input.text, input.previous, input.place);
3287
3671
  return resolveConversationRunSpec({
3288
3672
  models: input.language,
3289
3673
  selection: { model: choice.model },
@@ -3323,17 +3707,20 @@ function assertAttachments(attachments) {
3323
3707
  }
3324
3708
  }
3325
3709
  function assertThreadAcceptsRun(thread, principal) {
3710
+ assertThreadAcceptsMessages(thread, principal);
3711
+ if (thread.activeRunId !== null) {
3712
+ throw new AgentRequestError2("active_run_exists", `[Sixb] Agent thread '${thread.id}' already has an active run '${thread.activeRunId}'.`);
3713
+ }
3714
+ }
3715
+ function assertThreadAcceptsMessages(thread, principal) {
3326
3716
  assertConversationThread2(thread);
3327
3717
  assertSandboxExecutionAvailable(thread);
3328
3718
  if (thread.runsOn === "computer" && !principalsEqual2(principal, thread.ownerPrincipal)) {
3329
3719
  throw new AgentRequestError2("not_thread_owner", `[Sixb] Agent thread '${thread.id}' runs on its owner's computer, as them: only its owner can message it. Shared with you, it is yours to read and follow.`);
3330
3720
  }
3331
- if (thread.activeRunId !== null) {
3332
- throw new AgentRequestError2("active_run_exists", `[Sixb] Agent thread '${thread.id}' already has an active run '${thread.activeRunId}'.`);
3333
- }
3334
3721
  }
3335
3722
  function assertSandboxExecutionAvailable(thread) {
3336
- if (thread.sandboxState && !["new", "ready"].includes(thread.sandboxState.status)) {
3723
+ if (thread.runsOn !== "computer" && thread.sandboxState && !["new", "ready"].includes(thread.sandboxState.status)) {
3337
3724
  throw new AgentRequestError2("sandbox_execution_unavailable", "[Sixb] Sandbox recovery is required before another run. Reload the thread, then resume its previous sandbox or recreate it to start fresh.");
3338
3725
  }
3339
3726
  }
@@ -3383,7 +3770,7 @@ async function resolveConversationRunSpec(input) {
3383
3770
  });
3384
3771
  }
3385
3772
  function requesterSettings(input) {
3386
- const timeZone = requestedSetting("timeZone", input.timeZone, canonicalTimeZone, "an IANA time zone");
3773
+ const timeZone = requestedSetting("timeZone", input.timeZone, canonicalTimeZone2, "an IANA time zone");
3387
3774
  const locale = requestedSetting("locale", input.locale, canonicalLocale, "a BCP 47 language tag");
3388
3775
  return {
3389
3776
  ...timeZone === undefined ? {} : { timeZone },
@@ -3734,7 +4121,7 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3734
4121
  try {
3735
4122
  if (!await rule.read(run.threadId))
3736
4123
  return { status: "closed" };
3737
- return await startQueuedAgentTurnFromInbox2(runtime, execution, run, options);
4124
+ return await startQueuedAgentTurnFromInbox2(runtime, execution, run, options, blobStorage);
3738
4125
  } catch (error) {
3739
4126
  console.error(`[Sixb] Could not start a queued message of Agent run '${run.id}'.`, error);
3740
4127
  return { status: "closed" };
@@ -3762,6 +4149,47 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3762
4149
  return preferences.get();
3763
4150
  }
3764
4151
  };
4152
+ const readViewer = () => principal.type === "user" ? principal : undefined;
4153
+ const lastRunView = async (run) => {
4154
+ const view = {
4155
+ id: run.id,
4156
+ status: run.status,
4157
+ ...run.finishReason === undefined ? {} : { finishReason: run.finishReason },
4158
+ ...run.error === undefined ? {} : { errorCode: run.error.code },
4159
+ ...run.completedAt === undefined ? {} : { completedAt: run.completedAt }
4160
+ };
4161
+ if (!agentRunEndedShort(run))
4162
+ return view;
4163
+ const execution = await runtime.storage.executions.getById({
4164
+ projectId: runtime.projectId,
4165
+ id: run.executionId
4166
+ });
4167
+ if (!execution?.requestedBy)
4168
+ return view;
4169
+ return { ...view, requestedBy: structuredClone(execution.requestedBy) };
4170
+ };
4171
+ const withThreadState = async (threads, viewer) => {
4172
+ const agents = runtime.storage.agents;
4173
+ if (!viewer || !agents || threads.length === 0)
4174
+ return threads;
4175
+ const threadIds = threads.map((thread) => thread.id);
4176
+ const [reads, runs] = await Promise.all([
4177
+ agents.reads.list({ projectId: runtime.projectId, threadIds, principal: viewer }),
4178
+ agents.runs.latestByThread({ projectId: runtime.projectId, threadIds })
4179
+ ]);
4180
+ const lastRuns = await Promise.all(runs.map(lastRunView));
4181
+ const readOf = new Map(reads.map((read) => [read.threadId, read]));
4182
+ const runOf = new Map(runs.map((run, index) => [run.threadId, lastRuns[index]]));
4183
+ return threads.map((thread) => {
4184
+ const read = readOf.get(thread.id);
4185
+ const lastRun = runOf.get(thread.id);
4186
+ return {
4187
+ ...thread,
4188
+ ...read === undefined ? {} : { read },
4189
+ ...lastRun === undefined ? {} : { lastRun }
4190
+ };
4191
+ });
4192
+ };
3765
4193
  const recoverSandbox = async (threadId, choice, transition) => {
3766
4194
  const readable = await rule.read(threadId);
3767
4195
  if (!readable)
@@ -3776,19 +4204,17 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3776
4204
  }
3777
4205
  const thread = readable.thread;
3778
4206
  const sandboxState = await transition(storage);
3779
- const [view] = await agentThreadViews(runtime, [{ ...thread, sandboxState }]);
4207
+ const [view] = await withThreadState(await agentThreadViews(runtime, [{ ...thread, sandboxState }]), readViewer());
3780
4208
  return view ?? thread;
3781
4209
  };
3782
- const ownedComputerThread = async (threadId) => {
4210
+ const ownedMovableThread = async (threadId) => {
3783
4211
  const readable = await rule.read(threadId);
3784
4212
  if (!readable)
3785
4213
  throw new AgentRequestError2("thread_not_found", "[Sixb] Agent thread not found.");
4214
+ assertConversationThread2(readable.thread);
3786
4215
  if (readable.access !== "owner") {
3787
4216
  throw new AgentRequestError2("not_thread_owner", `[Sixb] Only the owner of Agent thread '${threadId}' moves it.`);
3788
4217
  }
3789
- if (readable.thread.runsOn !== "computer") {
3790
- throw new AgentRequestError2("invalid_message", `[Sixb] Agent thread '${threadId}' runs in the cloud, on no computer.`);
3791
- }
3792
4218
  return readable.thread;
3793
4219
  };
3794
4220
  const moveThread = (thread, moves, move) => runtime.storage.transaction(async (tx) => {
@@ -3797,7 +4223,7 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3797
4223
  throw new AgentRequestError2("storage_unavailable", "[Sixb] Agent storage is not configured.");
3798
4224
  }
3799
4225
  const moved = await move(agents).catch((error) => {
3800
- throw error instanceof AgentStorageError2 && error.code === "active_run_exists" ? new AgentRequestError2("active_run_exists", "[Sixb] A turn is running on the computer: stop it, or let it end, first.") : error;
4226
+ throw error instanceof AgentStorageError2 && error.code === "active_run_exists" ? new AgentRequestError2("active_run_exists", thread.runsOn === "computer" ? "[Sixb] A turn is running on the computer: stop it, or let it end, first." : "[Sixb] A turn is running in the cloud: stop it, or let it end, first.") : error;
3801
4227
  });
3802
4228
  if (moves && await threadHoldsPausedTurn(agents, thread)) {
3803
4229
  throw new AgentRequestError2("active_run_exists", "[Sixb] A turn is waiting for your approval: answer or stop it first.");
@@ -3833,21 +4259,24 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3833
4259
  name: input.expectedSandboxName
3834
4260
  })),
3835
4261
  moveToComputer: async (threadId, computer) => {
3836
- const thread = await ownedComputerThread(threadId);
4262
+ const thread = await ownedMovableThread(threadId);
3837
4263
  const moves = movesComputerPlace2(thread, computer);
3838
4264
  const moved = await moveThread(thread, moves, (agents) => agents.threads.assignComputer({ projectId: runtime.projectId, id: threadId, computer }));
3839
4265
  if (moves)
3840
4266
  await announceThreadMoved(thread);
3841
- const [view] = await agentThreadViews(runtime, [moved]);
4267
+ const [view] = await withThreadState(await agentThreadViews(runtime, [moved]), readViewer());
3842
4268
  return view ?? moved;
3843
4269
  },
3844
4270
  moveToCloud: async (threadId) => {
3845
- const thread = await ownedComputerThread(threadId);
4271
+ const thread = await ownedMovableThread(threadId);
4272
+ if (thread.runsOn !== "computer") {
4273
+ throw new AgentRequestError2("invalid_message", `[Sixb] Agent thread '${threadId}' runs in the cloud, on no computer.`);
4274
+ }
3846
4275
  const { thread: moved, queued } = await moveThread(thread, true, (agents) => agents.threads.moveToCloud({ projectId: runtime.projectId, id: threadId }));
3847
4276
  if (queued)
3848
4277
  await dispatchAgentRun(runtime, requireAgents(), queued.id);
3849
4278
  await announceThreadMoved(thread);
3850
- const [view] = await agentThreadViews(runtime, [moved]);
4279
+ const [view] = await withThreadState(await agentThreadViews(runtime, [moved]), readViewer());
3851
4280
  return view ?? moved;
3852
4281
  },
3853
4282
  create: async (input) => {
@@ -3880,7 +4309,8 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3880
4309
  ...input.runsOn === undefined ? {} : { runsOn: input.runsOn },
3881
4310
  ...input.computer === undefined ? {} : { computer: input.computer }
3882
4311
  });
3883
- return { ...created, participants: [] };
4312
+ const [view] = await withThreadState([{ ...created, participants: [] }], readViewer());
4313
+ return view ?? { ...created, participants: [] };
3884
4314
  },
3885
4315
  listChildren: async (threadId, { runId } = {}) => {
3886
4316
  const thread = await getVisibleThreadRecord(threadId);
@@ -3911,10 +4341,36 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3911
4341
  ownerPrincipal: principal,
3912
4342
  sandbox
3913
4343
  });
3914
- const [view] = await agentThreadViews(runtime, [fork]);
4344
+ const [view] = await withThreadState(await agentThreadViews(runtime, [fork]), readViewer());
3915
4345
  return view ?? { ...fork, participants: [] };
3916
4346
  },
3917
- getById: getVisibleThreadRecord,
4347
+ getById: async (threadId) => {
4348
+ const thread = await getVisibleThreadRecord(threadId);
4349
+ if (!thread)
4350
+ return null;
4351
+ const [view] = await withThreadState([thread], readViewer());
4352
+ return view ?? null;
4353
+ },
4354
+ markRead: async (threadId, input = {}) => {
4355
+ const readable = await rule.read(threadId);
4356
+ if (!readable) {
4357
+ throw new AgentRequestError2("thread_not_found", "[Sixb] Agent thread not found.");
4358
+ }
4359
+ assertConversationThread2(readable.thread);
4360
+ const reader = settingsPrincipal();
4361
+ if (reader.type !== "user") {
4362
+ throw new AgentRequestError2("agent_not_found", "[Sixb] The project Agent is unavailable.");
4363
+ }
4364
+ if (input.throughMessageId !== undefined && input.throughMessageId.trim().length === 0) {
4365
+ throw new AgentRequestError2("invalid_message", "[Sixb] 'throughMessageId' must name a message of the thread.");
4366
+ }
4367
+ return requireAgents().reads.mark({
4368
+ projectId: runtime.projectId,
4369
+ threadId,
4370
+ principal: reader,
4371
+ ...input.throughMessageId === undefined ? {} : { throughMessageId: input.throughMessageId }
4372
+ });
4373
+ },
3918
4374
  list: async ({ sharedWithMe, ...input } = {}) => {
3919
4375
  assertNoAgentSelector(input);
3920
4376
  const none = { threads: [], hasMore: false, total: 0 };
@@ -3931,7 +4387,8 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3931
4387
  projectId: runtime.projectId,
3932
4388
  ...sharedWithMe && caller?.type === "user" ? { participantPrincipal: caller } : { ownerPrincipal: caller }
3933
4389
  });
3934
- return { ...result, threads: await agentThreadViews(runtime, result.threads) };
4390
+ const views = await agentThreadViews(runtime, result.threads);
4391
+ return { ...result, threads: await withThreadState(views, readViewer()) };
3935
4392
  },
3936
4393
  participants: {
3937
4394
  add: (threadId, users) => addAgentThreadParticipants(runtime, rule, security, threadId, users),
@@ -3956,7 +4413,7 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3956
4413
  if (!await getVisibleThreadRecord(threadId)) {
3957
4414
  throw new AgentRequestError2("thread_not_found", `[Sixb] Agent thread '${threadId}' not found.`);
3958
4415
  }
3959
- return promoteAgentInboxItem2(runtime, execution, { ...input, threadId, itemId });
4416
+ return promoteAgentInboxItem2(runtime, execution, { ...input, threadId, itemId }, blobStorage);
3960
4417
  },
3961
4418
  remove: async (threadId, itemId) => {
3962
4419
  if (!await getVisibleThreadRecord(threadId)) {
@@ -3975,7 +4432,7 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3975
4432
  if (!await getVisibleThreadRecord(input.threadId)) {
3976
4433
  throw new AgentRequestError2("thread_not_found", `[Sixb] Agent thread '${input.threadId}' not found.`);
3977
4434
  }
3978
- const result = await sendAgentMessage2(runtime, execution, turnModels, input);
4435
+ const result = await sendAgentMessage2(runtime, execution, turnModels, input, blobStorage);
3979
4436
  return result.kind === "turn" ? { ...result, run: await attachRunView(runtime, result.run) } : result;
3980
4437
  },
3981
4438
  request: async (input) => {
@@ -3994,6 +4451,19 @@ function createAgentRuntime(runtime, execution, models, decision, sandbox, secur
3994
4451
  });
3995
4452
  return { ...result, run: await attachRunView(runtime, result.run) };
3996
4453
  },
4454
+ editMessage: async (input) => {
4455
+ assertNoAgentSelector(input);
4456
+ const agent = getAgent();
4457
+ if (!agent) {
4458
+ throw new AgentRequestError2("agent_not_found", "[Sixb] The project Agent is unavailable.");
4459
+ }
4460
+ assertAuthorized2(runtime, { kind: "agent.run" });
4461
+ if (!await getVisibleThreadRecord(input.threadId)) {
4462
+ throw new AgentRequestError2("thread_not_found", `[Sixb] Agent thread '${input.threadId}' not found.`);
4463
+ }
4464
+ const result = await editAgentMessage2(runtime, execution, turnModels, { ...input, principal }, blobStorage);
4465
+ return result.kind === "turn" ? { ...result, run: await attachRunView(runtime, result.run) } : result;
4466
+ },
3997
4467
  retry: async (runId) => {
3998
4468
  const failedRun = await getControllableRun(runId, "retry");
3999
4469
  const agent = getAgent();
@@ -4696,7 +5166,7 @@ function lastState(changes) {
4696
5166
  }
4697
5167
 
4698
5168
  // src/events/execution.ts
4699
- function createEventsRuntime(runtime) {
5169
+ function createEventsRuntime(runtime, access) {
4700
5170
  const authority = resolveRuntimeAuthorizationForProject(runtime);
4701
5171
  const history = {
4702
5172
  existing: async (objects) => {
@@ -4720,7 +5190,8 @@ function createEventsRuntime(runtime) {
4720
5190
  case "unrestricted":
4721
5191
  return events;
4722
5192
  case "principal": {
4723
- const shown = await visibleByGrants(authority.context, events);
5193
+ const granted = await visibleByGrants(authority.context, events);
5194
+ const shown = await withoutHiddenSyncRuns(granted, access);
4724
5195
  if (!events.some((event) => event.topic === "artifacts"))
4725
5196
  return shown;
4726
5197
  const readable = await readableArtifactEvents(runtime, events);
@@ -4821,6 +5292,20 @@ async function readableArtifactEvents(runtime, events) {
4821
5292
  }
4822
5293
  return shown;
4823
5294
  }
5295
+ async function withoutHiddenSyncRuns(events, access) {
5296
+ const connectionOf = (event) => event.topic === "syncs" ? event.payload.connectionId : undefined;
5297
+ const syncIds = new Set(events.flatMap((event) => event.topic === "syncs" && connectionOf(event) !== undefined ? [event.payload.syncId] : []));
5298
+ if (syncIds.size === 0)
5299
+ return events;
5300
+ const visible = await access.visibleSyncConnectionIds([...syncIds]);
5301
+ if (visible === undefined)
5302
+ return events;
5303
+ const shown = new Set(visible);
5304
+ return events.filter((event) => {
5305
+ const connectionId = connectionOf(event);
5306
+ return connectionId === undefined || shown.has(connectionId);
5307
+ });
5308
+ }
4824
5309
  async function eventClearances(reader, events, clearance) {
4825
5310
  const kinds = new Map;
4826
5311
  for (const event of events) {
@@ -7254,17 +7739,38 @@ function createAudioRuntime(runtime, execution, catalog, session, blobs) {
7254
7739
  }
7255
7740
  const event = await recordTranscription(accounting, model, callId, result ?? {});
7256
7741
  signal.throwIfAborted();
7257
- if (typeof result?.output?.text !== "string") {
7258
- throw new TranscriptionModelResponseError2("[SixbModels] Invalid transcription response.", model.providerId, model.modelId, result ?? {});
7259
- }
7260
- return {
7261
- output: { text: result.output.text },
7262
- usage: event.usage,
7263
- cost: event.cost,
7264
- callId
7265
- };
7266
- }
7267
- };
7742
+ const output = transcriptOutput(result, model);
7743
+ return { output, usage: event.usage, cost: event.cost, callId };
7744
+ }
7745
+ };
7746
+ }
7747
+ function transcriptOutput(result, model) {
7748
+ const refuse = () => new TranscriptionModelResponseError2("[SixbModels] Invalid transcription response.", model.providerId, model.modelId, result ?? {});
7749
+ const output = result?.output;
7750
+ if (typeof output?.text !== "string")
7751
+ throw refuse();
7752
+ const words = output.words;
7753
+ if (words === undefined)
7754
+ return { text: output.text };
7755
+ if (!Array.isArray(words))
7756
+ throw refuse();
7757
+ const timed = [];
7758
+ for (const word of words) {
7759
+ const entry = word;
7760
+ if (typeof entry?.text !== "string" || !entry.text || !isMillisecond(entry.startMs) || !isMillisecond(entry.endMs) || entry.endMs < entry.startMs || entry.speaker !== undefined && (typeof entry.speaker !== "string" || !entry.speaker)) {
7761
+ throw refuse();
7762
+ }
7763
+ timed.push({
7764
+ text: entry.text,
7765
+ startMs: entry.startMs,
7766
+ endMs: entry.endMs,
7767
+ ...entry.speaker === undefined ? {} : { speaker: entry.speaker }
7768
+ });
7769
+ }
7770
+ return timed.length ? { text: output.text, words: timed } : { text: output.text };
7771
+ }
7772
+ function isMillisecond(value) {
7773
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
7268
7774
  }
7269
7775
  function prepareAudio(input, blobs) {
7270
7776
  if (typeof input === "object" && input !== null && "data" in input) {
@@ -9391,6 +9897,7 @@ function resolveLinkContext2(objCtx, linkId) {
9391
9897
  // src/objects/sdk/runtime-query-executor.ts
9392
9898
  function createRuntimeQueryExecutor(params) {
9393
9899
  const { ontology, objectReader } = params;
9900
+ const discovery = getQueryDiscovery(objectReader);
9394
9901
  return {
9395
9902
  async list(query, options) {
9396
9903
  try {
@@ -9425,10 +9932,10 @@ function createRuntimeQueryExecutor(params) {
9425
9932
  };
9426
9933
  },
9427
9934
  validate(query) {
9428
- return validateObjectQuery2(query, { ontology, normalize: false });
9935
+ return validateObjectQuery2(query, { ontology, discovery, normalize: false });
9429
9936
  },
9430
9937
  explain(query) {
9431
- return explainObjectQuery2(query, { ontology, normalize: false });
9938
+ return explainObjectQuery2(query, { ontology, discovery, normalize: false });
9432
9939
  }
9433
9940
  };
9434
9941
  }
@@ -10295,26 +10802,70 @@ function storageFailure(operation, cause) {
10295
10802
  });
10296
10803
  }
10297
10804
 
10805
+ // src/syncs/accounts.ts
10806
+ function createSyncAccountsRuntime(input) {
10807
+ const { runtime, execution, connections } = input;
10808
+ const latestByConnection = (syncIds, connectionIds) => runtime.storage.syncRuns ? runtime.storage.syncRuns.listLatestByConnection({
10809
+ projectId: runtime.projectId,
10810
+ syncIds,
10811
+ ...connectionIds === undefined ? {} : { connectionIds }
10812
+ }).then(({ runs }) => runs) : Promise.resolve([]);
10813
+ return {
10814
+ async list(connectorId) {
10815
+ const syncs = input.syncs().filter((sync) => sync.connector.id === connectorId && input.runnable(sync.id));
10816
+ const connector = syncs[0]?.connector;
10817
+ if (!connections || !connector || !isOAuthConnectorDefinition2(connector))
10818
+ return [];
10819
+ const accounts = (await connections.list(connector)).filter((connection) => mayRunConnection(runtime, execution, connection));
10820
+ const runs = await latestByConnection(syncs.map(({ id }) => id), accounts.map(({ id }) => id));
10821
+ return accounts.map((connection) => ({
10822
+ connection,
10823
+ latestRuns: runs.filter((run) => run.connectionId === connection.id)
10824
+ }));
10825
+ },
10826
+ async latestRuns(connectorId, connectionId) {
10827
+ const syncs = input.syncs().filter((sync) => sync.connector.id === connectorId);
10828
+ const connector = syncs[0]?.connector;
10829
+ if (!connections || !connector || !isOAuthConnectorDefinition2(connector))
10830
+ return [];
10831
+ const connection = (await connections.list(connector)).find(({ id }) => id === connectionId);
10832
+ if (!connection || !seesConnection(runtime, execution, connection))
10833
+ return [];
10834
+ return latestByConnection(syncs.map(({ id }) => id), [connection.id]);
10835
+ }
10836
+ };
10837
+ }
10838
+
10298
10839
  // src/syncs/execution.ts
10299
- function createSyncsRuntime(runtime, execution, source) {
10840
+ function createSyncsRuntime(runtime, execution, source, connections) {
10300
10841
  const authority = resolveRuntimeAuthorizationForProject(runtime);
10301
10842
  const allowed = (syncId) => isRuntimeAllowed2(runtime, { kind: "sync.run", syncId });
10302
10843
  const visibleIds = () => source.list().filter((sync) => allowed(sync.id)).map((sync) => sync.id);
10303
10844
  const historyFilterIds = () => authority.type === "unrestricted" ? undefined : authority.type === "principal" ? visibleIds() : [];
10845
+ const getById = (syncId) => {
10846
+ if (authority.type === "denied" || authority.type === "delegated")
10847
+ return null;
10848
+ const sync = source.getById(syncId);
10849
+ return sync && allowed(syncId) ? sync : null;
10850
+ };
10851
+ const visibleConnectionIds = (syncs) => visibleSyncConnectionIds(runtime, execution, syncs, connections);
10304
10852
  return {
10305
10853
  list: () => authority.type === "denied" || authority.type === "delegated" ? [] : source.list().filter((sync) => allowed(sync.id)),
10306
- getById: (syncId) => {
10307
- if (authority.type === "denied" || authority.type === "delegated")
10308
- return null;
10309
- const sync = source.getById(syncId);
10310
- return sync && allowed(syncId) ? sync : null;
10311
- },
10854
+ getById,
10855
+ accounts: createSyncAccountsRuntime({
10856
+ runtime,
10857
+ execution,
10858
+ syncs: () => source.list(),
10859
+ runnable: getById,
10860
+ ...connections === undefined ? {} : { connections }
10861
+ }),
10312
10862
  request: async (input) => {
10313
10863
  assertAuthorized2(runtime, { kind: "sync.run", syncId: input.syncId });
10314
10864
  const sync = source.getById(input.syncId);
10315
10865
  if (!sync)
10316
10866
  throw new SyncValidationError2(`[Sixb] Unknown sync '${input.syncId}'`);
10317
- return requestSyncRun2(runtime, execution, sync, input);
10867
+ const { syncId: _syncId, ...options } = input;
10868
+ return requestSyncRun2(runtime, execution, sync, options, connections);
10318
10869
  },
10319
10870
  runs: {
10320
10871
  getById: async (runId) => {
@@ -10324,30 +10875,41 @@ function createSyncsRuntime(runtime, execution, source) {
10324
10875
  projectId: runtime.projectId,
10325
10876
  id: runId
10326
10877
  }) ?? null;
10327
- return run && allowed(run.syncId) ? run : null;
10878
+ if (!run || !allowed(run.syncId))
10879
+ return null;
10880
+ const visible = await visibleConnectionIds([source.getById(run.syncId)]);
10881
+ const hidden = run.connectionId !== undefined && visible?.includes(run.connectionId) === false;
10882
+ return hidden ? null : run;
10328
10883
  },
10329
- list: (input = {}) => {
10884
+ list: async (input = {}) => {
10330
10885
  if (authority.type === "denied" || authority.type === "delegated") {
10331
- return Promise.resolve({ runs: [], hasMore: false, total: 0 });
10886
+ return { runs: [], hasMore: false, total: 0 };
10332
10887
  }
10333
10888
  const storage = runtime.storage.syncRuns;
10334
10889
  if (!storage)
10335
- return Promise.resolve({ runs: [], hasMore: false, total: 0 });
10890
+ return { runs: [], hasMore: false, total: 0 };
10891
+ const syncs = input.syncId === undefined ? source.list().filter((sync) => allowed(sync.id)) : [getById(input.syncId)];
10892
+ const visible = await visibleConnectionIds(syncs);
10336
10893
  return storage.list({
10337
10894
  ...input,
10338
10895
  syncIds: historyFilterIds(),
10896
+ ...visible === undefined ? {} : { visibleConnectionIds: visible },
10339
10897
  projectId: runtime.projectId
10340
10898
  });
10341
10899
  },
10342
- listLatest: (syncIds) => {
10343
- if (authority.type === "denied" || authority.type === "delegated") {
10344
- return Promise.resolve({ runs: [] });
10345
- }
10900
+ listLatest: async (syncIds) => {
10901
+ if (authority.type === "denied" || authority.type === "delegated")
10902
+ return { runs: [] };
10346
10903
  const storage = runtime.storage.syncRuns;
10347
- if (!storage || syncIds.length === 0)
10348
- return Promise.resolve({ runs: [] });
10349
10904
  const allowedIds = syncIds.filter(allowed);
10350
- return allowedIds.length === 0 ? Promise.resolve({ runs: [] }) : storage.listLatestBySyncIds({ projectId: runtime.projectId, syncIds: allowedIds });
10905
+ if (!storage || allowedIds.length === 0)
10906
+ return { runs: [] };
10907
+ const visible = await visibleConnectionIds(allowedIds.map((syncId) => source.getById(syncId)));
10908
+ return storage.listLatestBySyncIds({
10909
+ projectId: runtime.projectId,
10910
+ syncIds: allowedIds,
10911
+ ...visible === undefined ? {} : { visibleConnectionIds: visible }
10912
+ });
10351
10913
  }
10352
10914
  }
10353
10915
  };
@@ -10581,6 +11143,7 @@ function isBoundSixb(value) {
10581
11143
  }
10582
11144
  function createExecutionFacades(runtime, execution, dependencies) {
10583
11145
  const actions = createActionsRuntime(runtime, execution);
11146
+ const syncConnections = createSyncConnections(dependencies.connectorService);
10584
11147
  const workflows = createWorkflowsRuntime(runtime, execution, dependencies.definitions.workflows);
10585
11148
  const session = runtime.modelExecution ?? new ModelExecutionSession(runtime, execution);
10586
11149
  const agent = createAgentRuntime(runtime, execution, dependencies.definitions.models, createDecisionRuntime(runtime, execution, dependencies.definitions.models, session, "agent.run"), dependencies.sandbox, dependencies.definitions.security, dependencies.blobStorage);
@@ -10592,7 +11155,7 @@ function createExecutionFacades(runtime, execution, dependencies) {
10592
11155
  actions,
10593
11156
  datasets: createDatasetsRuntime(runtime, execution, dependencies.definitions.datasets, dependencies.lakeStorage, dependencies.blobStorage, dependencies.datasetVersionMarkings, dependencies.datasetIngest),
10594
11157
  workflows,
10595
- syncs: createSyncsRuntime(runtime, execution, dependencies.definitions.syncs),
11158
+ syncs: createSyncsRuntime(runtime, execution, dependencies.definitions.syncs, syncConnections),
10596
11159
  pipelines: createPipelinesRuntime(runtime, execution, dependencies.definitions.pipelines),
10597
11160
  projections: createProjectionsRuntime(runtime, dependencies.definitions.projections),
10598
11161
  rules: createRulesRuntime(runtime, dependencies.definitions.rules),
@@ -10606,7 +11169,9 @@ function createExecutionFacades(runtime, execution, dependencies) {
10606
11169
  canViewAgentRun: async (id) => await agent.runs.getById(id) !== null
10607
11170
  }, dependencies.blobStorage),
10608
11171
  aiUsage: createAiUsageRuntime(runtime, dependencies.definitions.security),
10609
- events: createEventsRuntime(runtime),
11172
+ events: createEventsRuntime(runtime, {
11173
+ visibleSyncConnectionIds: (syncIds) => visibleSyncConnectionIds(runtime, execution, syncIds.map((syncId) => dependencies.definitions.syncs.getById(syncId)), syncConnections)
11174
+ }),
10610
11175
  logs: createLogsRuntime(runtime, dependencies.logging),
10611
11176
  activity: createActivityRuntime(runtime, dependencies.activity),
10612
11177
  schedules: createSchedulesRuntime(runtime, dependencies.definitions.schedules),
@@ -12324,6 +12889,6 @@ function snapshotActionRequest(input) {
12324
12889
  ...onRequested === undefined ? {} : { onRequested }
12325
12890
  };
12326
12891
  }
12327
- export { defineAction2, param2, optional2, ActionRegistry2, bindRequestClient, bindModelExecutionAttempt, canInheritAgentRequestAuthorization2, createAgentExecutionRecord2, createInheritedAgentExecutionRecord2, bindDurableAgentExecution2, bindAgentRunRequestExecution2, bindAgentModelExecution2, restoreAgentExecutionScope2, assertAgentExecutionRecord2, resumeDecidedAgentTurn2, agentRunApprovalMode2, holdAgentApprovalCall2, approvalCallSummary2, listChildApprovalsAwaiting2, isAwaitingApprovalRun2, isPausedSubagentRun2, AGENT_APPROVAL_EXECUTION_LEASE_MS2, turnResumeReadiness2, turnPausesOnHeldCalls2, hasActiveChildren2, listTurnApprovals2, stopAgentTurn2, announceAgentApprovals2, agentApprovalCallers2, AgentRunScopeError2, resolveAgentRunExecutionScope2, createAgentApprovalExecutor, registerAgentApprovalExecutor, getAgentApprovalExecutor2, requestAgentRunCancel2, cancelQueuedRun, AGENT_QUESTION_LIMITS2, agentQuestionsText2, isChildAskTool2, isAwaitingAnswerRun2, deferredChildQuestion2, listSubagentThreadRuns2, subagentSandboxFiles2, assertTurnModelRouting, registerAgentQueuedTurn2, startQueuedAgentTurn2, DEFAULT_PROJECT_LOCALE, DEFAULT_PROJECT_TIME_ZONE, canonicalLocale, canonicalTimeZone, resolveAgentContextParts2, agentRunQueueJobId2, workflowAgentNodeQueueJobId2, dispatchQueuedAgentRuns2, assertNoAgentDefinitions, turnAnsweredEveryMessage, requestAgentRun2, isRetryableAgentRun2, retryAgentRun2, AGENT_MESSAGE_DELIVERIES2, sendAgentMessage2, promoteAgentInboxItem2, withdrawAgentInboxItem2, startQueuedAgentTurnFromInbox2, WorkflowDefinitionError2, WorkflowValidationError2, assertNonEmpty, isStepDefinition2, isAgentStepDefinition2, isInterventionDefinition2, isWorkflowDefinition2, validateWorkflowDefinition2, validateWorkflowsAtStartup2, validateWorkflowAgentStepGroupReferences2, validateWorkflowInput2, validateWorkflowStepInput2, validateWorkflowStepOutput2, validateWorkflowInterventionInput2, validateWorkflowInterventionResponse2, validateWorkflowInterventionDefaultResponse2, assertAgentStepSandbox, validateWorkflowAgentStepInput2, validateWorkflowAgentStepOutput2, snapshotWorkflowAgentStepInput2, snapshotWorkflowAgentStepOutput2, snapshotWorkflowInput2, snapshotWorkflowStepInput2, snapshotWorkflowStepOutput2, snapshotWorkflowInterventionInput2, snapshotWorkflowInterventionResponse2, snapshotWorkflowInterventionDefaultResponse2, snapshotWorkflowActionInput2, WorkflowRunDispatcher2, requestWorkflowRun2, prepareBoundActionRequest2, prepareBoundWorkflowRequest2, runModelLoop2, requestAction2, ObjectError2, removeLink2, upsertLink2, upsertLinkBatch2, deleteObject2, restoreObject2, upsertObject2, upsertObjectBatch2, writeTelemetryBatch2, appendTelemetryBatch2, getTelemetryHistoryBatch2, requireLinkDefinition2, resolveObjectContext2, resolveLinkContext2, createObjectSet2, exports_service, ShareError2, createBoundSixb, isBoundSixb, bindDurablePrimitiveExecution2, ACTION_RUN_DRAIN_TIMEOUT_MS2, ActionRunExecutor, registerActionRunExecutor, drainActionRuns2, requestAction3 };
12892
+ export { defineAction2, param2, optional2, ActionRegistry2, bindRequestClient, bindModelExecutionAttempt, canInheritAgentRequestAuthorization2, createAgentExecutionRecord2, createInheritedAgentExecutionRecord2, bindDurableAgentExecution2, bindAgentRunRequestExecution2, bindAgentModelExecution2, restoreAgentExecutionScope2, assertAgentExecutionRecord2, resumeDecidedAgentTurn2, agentRunApprovalMode2, holdAgentApprovalCall2, approvalCallSummary2, listChildApprovalsAwaiting2, isAwaitingApprovalRun2, isPausedSubagentRun2, AGENT_APPROVAL_EXECUTION_LEASE_MS2, turnResumeReadiness2, turnPausesOnHeldCalls2, hasActiveChildren2, listTurnApprovals2, stopAgentTurn2, announceAgentApprovals2, agentApprovalCallers2, AgentRunScopeError2, resolveAgentRunExecutionScope2, createAgentApprovalExecutor, registerAgentApprovalExecutor, getAgentApprovalExecutor2, requestAgentRunCancel2, cancelQueuedRun, AGENT_QUESTION_LIMITS2, agentQuestionsText2, isChildAskTool2, isAwaitingAnswerRun2, deferredChildQuestion2, listSubagentThreadRuns2, subagentSandboxFiles2, assertTurnModelRouting, registerAgentQueuedTurn2, startQueuedAgentTurn2, resolveAgentContextParts2, agentRunQueueJobId2, workflowAgentNodeQueueJobId2, dispatchQueuedAgentRuns2, assertNoAgentDefinitions, turnAnsweredEveryMessage, requestAgentRun2, isEditableAgentMessage2, editAgentMessage2, isRetryableAgentRun2, retryAgentRun2, AGENT_MESSAGE_DELIVERIES2, sendAgentMessage2, promoteAgentInboxItem2, withdrawAgentInboxItem2, startQueuedAgentTurnFromInbox2, WorkflowDefinitionError2, WorkflowValidationError2, assertNonEmpty, isStepDefinition2, isAgentStepDefinition2, isInterventionDefinition2, isWorkflowDefinition2, validateWorkflowDefinition2, validateWorkflowsAtStartup2, validateWorkflowAgentStepGroupReferences2, validateWorkflowInput2, validateWorkflowStepInput2, validateWorkflowStepOutput2, validateWorkflowInterventionInput2, validateWorkflowInterventionResponse2, validateWorkflowInterventionDefaultResponse2, assertAgentStepSandbox, validateWorkflowAgentStepInput2, validateWorkflowAgentStepOutput2, snapshotWorkflowAgentStepInput2, snapshotWorkflowAgentStepOutput2, snapshotWorkflowInput2, snapshotWorkflowStepInput2, snapshotWorkflowStepOutput2, snapshotWorkflowInterventionInput2, snapshotWorkflowInterventionResponse2, snapshotWorkflowInterventionDefaultResponse2, snapshotWorkflowActionInput2, WorkflowRunDispatcher2, requestWorkflowRun2, prepareBoundActionRequest2, prepareBoundWorkflowRequest2, runModelLoop2, requestAction2, ObjectError2, removeLink2, upsertLink2, upsertLinkBatch2, deleteObject2, restoreObject2, upsertObject2, upsertObjectBatch2, writeTelemetryBatch2, appendTelemetryBatch2, getTelemetryHistoryBatch2, requireLinkDefinition2, resolveObjectContext2, resolveLinkContext2, createObjectSet2, exports_service, ShareError2, createBoundSixb, isBoundSixb, bindDurablePrimitiveExecution2, ACTION_RUN_DRAIN_TIMEOUT_MS2, ActionRunExecutor, registerActionRunExecutor, drainActionRuns2, requestAction3 };
12328
12893
 
12329
- //# debugId=769CBCF3562DBFDA64756E2164756E21
12894
+ //# debugId=6AB827512C16B65C64756E2164756E21