kiki-agent 0.5.1 → 0.6.0

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 (1283) hide show
  1. package/dist/builtin/examples/custom-json.mjs +7 -1
  2. package/dist/builtin/rules/claude/entry.mjs +8 -7
  3. package/dist/builtin/rules/codex/entry.mjs +8 -7
  4. package/dist/builtin/rules/files.mjs +6 -1
  5. package/dist/builtin/rules/grok.mjs +2 -2
  6. package/dist/builtin/rules/opencode.mjs +2 -2
  7. package/dist/builtin/rules/pi.mjs +3 -3
  8. package/dist/cpu-worker.mjs +7964 -3067
  9. package/dist/docs/en/configuration/config-files.md +180 -23
  10. package/dist/docs/en/configuration/data-locations.md +7 -4
  11. package/dist/docs/en/configuration/env-vars.md +1 -1
  12. package/dist/docs/en/configuration/providers.md +65 -17
  13. package/dist/docs/en/customization/agent-profiles.md +2 -2
  14. package/dist/docs/en/customization/agents-and-subagents.md +77 -15
  15. package/dist/docs/en/customization/hooks.md +77 -21
  16. package/dist/docs/en/customization/personas.md +3 -3
  17. package/dist/docs/en/customization/plugins.md +157 -7
  18. package/dist/docs/en/customization/prompt-fields.md +7 -5
  19. package/dist/docs/en/customization/recipes.md +3 -3
  20. package/dist/docs/en/customization/skills.md +1 -1
  21. package/dist/docs/en/customization/skins.md +1 -1
  22. package/dist/docs/en/features/agent-workflows.md +1 -1
  23. package/dist/docs/en/features/daily.md +5 -3
  24. package/dist/docs/en/features/ecosystem.md +1 -1
  25. package/dist/docs/en/features/freedom.md +4 -4
  26. package/dist/docs/en/features/index.md +4 -3
  27. package/dist/docs/en/features/long-work.md +4 -2
  28. package/dist/docs/en/features/look.md +1 -1
  29. package/dist/docs/en/features/people.md +2 -2
  30. package/dist/docs/en/features/phone.md +1 -1
  31. package/dist/docs/en/features/spaces.md +38 -26
  32. package/dist/docs/en/features/workbench.md +2 -0
  33. package/dist/docs/en/getting-started/first-launch.md +11 -9
  34. package/dist/docs/en/getting-started/installation.md +65 -2
  35. package/dist/docs/en/getting-started/use-cases.md +2 -2
  36. package/dist/docs/en/guides/interaction.md +12 -10
  37. package/dist/docs/en/guides/interface.md +22 -12
  38. package/dist/docs/en/guides/memory.md +3 -3
  39. package/dist/docs/en/guides/sessions.md +8 -4
  40. package/dist/docs/en/guides/settings.md +53 -52
  41. package/dist/docs/en/index.md +9 -6
  42. package/dist/docs/en/reference/command.md +58 -11
  43. package/dist/docs/en/reference/keyboard.md +32 -15
  44. package/dist/docs/en/reference/model-vocabulary.md +5 -9
  45. package/dist/docs/en/reference/slash-commands.md +10 -4
  46. package/dist/docs/en/reference/tools.md +80 -44
  47. package/dist/docs/en/server/local-server.md +11 -5
  48. package/dist/docs/en/server/mcp.md +2 -2
  49. package/dist/docs/en/server/rest-api.md +185 -59
  50. package/dist/docs/en/server/script-tools.md +1 -1
  51. package/dist/docs/zh/configuration/config-files.md +180 -23
  52. package/dist/docs/zh/configuration/data-locations.md +7 -4
  53. package/dist/docs/zh/configuration/env-vars.md +1 -1
  54. package/dist/docs/zh/configuration/providers.md +65 -17
  55. package/dist/docs/zh/customization/agent-profiles.md +2 -2
  56. package/dist/docs/zh/customization/agents-and-subagents.md +77 -15
  57. package/dist/docs/zh/customization/hooks.md +78 -22
  58. package/dist/docs/zh/customization/personas.md +3 -3
  59. package/dist/docs/zh/customization/plugins.md +157 -7
  60. package/dist/docs/zh/customization/prompt-fields.md +7 -5
  61. package/dist/docs/zh/customization/recipes.md +3 -3
  62. package/dist/docs/zh/customization/skills.md +1 -1
  63. package/dist/docs/zh/customization/skins.md +1 -1
  64. package/dist/docs/zh/features/agent-workflows.md +1 -1
  65. package/dist/docs/zh/features/daily.md +5 -3
  66. package/dist/docs/zh/features/ecosystem.md +1 -1
  67. package/dist/docs/zh/features/freedom.md +4 -4
  68. package/dist/docs/zh/features/index.md +4 -3
  69. package/dist/docs/zh/features/long-work.md +4 -2
  70. package/dist/docs/zh/features/look.md +1 -1
  71. package/dist/docs/zh/features/people.md +2 -2
  72. package/dist/docs/zh/features/phone.md +1 -1
  73. package/dist/docs/zh/features/spaces.md +39 -27
  74. package/dist/docs/zh/features/workbench.md +2 -0
  75. package/dist/docs/zh/getting-started/first-launch.md +11 -9
  76. package/dist/docs/zh/getting-started/installation.md +65 -2
  77. package/dist/docs/zh/getting-started/use-cases.md +2 -2
  78. package/dist/docs/zh/guides/interaction.md +12 -10
  79. package/dist/docs/zh/guides/interface.md +22 -12
  80. package/dist/docs/zh/guides/memory.md +4 -4
  81. package/dist/docs/zh/guides/sessions.md +8 -4
  82. package/dist/docs/zh/guides/settings.md +54 -53
  83. package/dist/docs/zh/index.md +9 -6
  84. package/dist/docs/zh/reference/command.md +58 -11
  85. package/dist/docs/zh/reference/keyboard.md +32 -15
  86. package/dist/docs/zh/reference/model-vocabulary.md +5 -9
  87. package/dist/docs/zh/reference/slash-commands.md +10 -4
  88. package/dist/docs/zh/reference/tools.md +79 -43
  89. package/dist/docs/zh/server/local-server.md +11 -5
  90. package/dist/docs/zh/server/mcp.md +2 -2
  91. package/dist/docs/zh/server/rest-api.md +176 -52
  92. package/dist/docs/zh/server/script-tools.md +1 -1
  93. package/dist/external-harness/agy-cli-acp.mjs +3859 -857
  94. package/dist/external-harness/agy-hook-registration.mjs +72 -20
  95. package/dist/external-harness/agy-permission-hook.mjs +10 -1
  96. package/dist/history-navigation-worker.mjs +25565 -0
  97. package/dist/hostRunner.mjs +753 -7
  98. package/dist/mailbox-worker.mjs +158 -57
  99. package/dist/main.mjs +2 -2
  100. package/dist/memory-worker.mjs +240 -64
  101. package/dist/native/windows-process-helper.exe +0 -0
  102. package/dist/plugin-isolation-worker.mjs +57 -0
  103. package/dist/query-store-worker.mjs +766 -53
  104. package/dist/sqlite-indexer.mjs +6088 -294
  105. package/dist/sqlite-query-worker.mjs +5896 -234
  106. package/dist/usage-parser-worker.mjs +36 -0
  107. package/dist/usage-read-model-worker.mjs +135 -37
  108. package/dist/web/assets/App-DCxEkgD4.js +181 -0
  109. package/dist/web/assets/App-DCxEkgD4.js.br +0 -0
  110. package/dist/web/assets/App-DCxEkgD4.js.gz +0 -0
  111. package/dist/web/assets/AppErrorBoundary-C2kI_Mfb.js +1 -0
  112. package/dist/web/assets/AppErrorBoundary-C2kI_Mfb.js.br +0 -0
  113. package/dist/web/assets/AppErrorBoundary-C2kI_Mfb.js.gz +0 -0
  114. package/dist/web/assets/ArchivedSessionsPage-CJQBRKlz.js +1 -0
  115. package/dist/web/assets/ArchivedSessionsPage-CJQBRKlz.js.br +0 -0
  116. package/dist/web/assets/ArchivedSessionsPage-CJQBRKlz.js.gz +0 -0
  117. package/dist/web/assets/CapabilitiesPage-C4ggBXI7.js +15 -0
  118. package/dist/web/assets/CapabilitiesPage-C4ggBXI7.js.br +0 -0
  119. package/dist/web/assets/CapabilitiesPage-C4ggBXI7.js.gz +0 -0
  120. package/dist/web/assets/CodeEditor-BAdDaRcl.js +4 -0
  121. package/dist/web/assets/CodeEditor-BAdDaRcl.js.br +0 -0
  122. package/dist/web/assets/CodeEditor-BAdDaRcl.js.gz +0 -0
  123. package/dist/web/assets/ExternalEnginesSection-Ci1_RIkB.js +2 -0
  124. package/dist/web/assets/ExternalEnginesSection-Ci1_RIkB.js.br +0 -0
  125. package/dist/web/assets/ExternalEnginesSection-Ci1_RIkB.js.gz +0 -0
  126. package/dist/web/assets/GlobalCronPanel-DEYDD-iB.js +1 -0
  127. package/dist/web/assets/GlobalCronPanel-DEYDD-iB.js.br +0 -0
  128. package/dist/web/assets/GlobalCronPanel-DEYDD-iB.js.gz +0 -0
  129. package/dist/web/assets/ImageViewport-osmMzHUM.js +1 -0
  130. package/dist/web/assets/ImageViewport-osmMzHUM.js.br +0 -0
  131. package/dist/web/assets/ImageViewport-osmMzHUM.js.gz +0 -0
  132. package/dist/web/assets/ListParts-DL6n2vZD.js +1 -0
  133. package/dist/web/assets/ListParts-DL6n2vZD.js.br +0 -0
  134. package/dist/web/assets/ListParts-DL6n2vZD.js.gz +0 -0
  135. package/dist/web/assets/MediaLightbox-DfDTfyyo.js +1 -0
  136. package/dist/web/assets/MediaLightbox-DfDTfyyo.js.br +0 -0
  137. package/dist/web/assets/MediaLightbox-DfDTfyyo.js.gz +0 -0
  138. package/dist/web/assets/MemoryPage-C4VM8pO8.js +1 -0
  139. package/dist/web/assets/MemoryPage-C4VM8pO8.js.br +0 -0
  140. package/dist/web/assets/MemoryPage-C4VM8pO8.js.gz +0 -0
  141. package/dist/web/assets/Middleware-CQ3TZHhI.js +67 -0
  142. package/dist/web/assets/Middleware-CQ3TZHhI.js.br +0 -0
  143. package/dist/web/assets/Middleware-CQ3TZHhI.js.gz +0 -0
  144. package/dist/web/assets/MobileAppShell-CPW83S2x.js +23 -0
  145. package/dist/web/assets/MobileAppShell-CPW83S2x.js.br +0 -0
  146. package/dist/web/assets/MobileAppShell-CPW83S2x.js.gz +0 -0
  147. package/dist/web/assets/ModelConnectCard-CY1w-R_8.js +2 -0
  148. package/dist/web/assets/ModelConnectCard-CY1w-R_8.js.br +0 -0
  149. package/dist/web/assets/ModelConnectCard-CY1w-R_8.js.gz +0 -0
  150. package/dist/web/assets/NavScopeBoundary-7FLzmaAe.js +1 -0
  151. package/dist/web/assets/NavScopeBoundary-7FLzmaAe.js.br +0 -0
  152. package/dist/web/assets/NavScopeBoundary-7FLzmaAe.js.gz +0 -0
  153. package/dist/web/assets/PersonasPage-CB5q8dUU.js +3 -0
  154. package/dist/web/assets/PersonasPage-CB5q8dUU.js.br +0 -0
  155. package/dist/web/assets/PersonasPage-CB5q8dUU.js.gz +0 -0
  156. package/dist/web/assets/PluginPanelHost-BNSzFpXj.js +1 -0
  157. package/dist/web/assets/PluginPanelHost-BNSzFpXj.js.br +0 -0
  158. package/dist/web/assets/PluginPanelHost-BNSzFpXj.js.gz +0 -0
  159. package/dist/web/assets/PreviewWorkspace-itdg7TxB.js +1 -0
  160. package/dist/web/assets/PreviewWorkspace-itdg7TxB.js.br +0 -0
  161. package/dist/web/assets/PreviewWorkspace-itdg7TxB.js.gz +0 -0
  162. package/dist/web/assets/RoomPage-DqICeoEq.js +1 -0
  163. package/dist/web/assets/RoomPage-DqICeoEq.js.br +0 -0
  164. package/dist/web/assets/RoomPage-DqICeoEq.js.gz +0 -0
  165. package/dist/web/assets/SecretField-DhvasDWA.js +1 -0
  166. package/dist/web/assets/SecretField-DhvasDWA.js.br +0 -0
  167. package/dist/web/assets/SecretField-DhvasDWA.js.gz +0 -0
  168. package/dist/web/assets/SectionCard-CDWn1QiO.js +1 -0
  169. package/dist/web/assets/SectionCard-CDWn1QiO.js.br +0 -0
  170. package/dist/web/assets/SectionCard-CDWn1QiO.js.gz +0 -0
  171. package/dist/web/assets/SettingsPage-BhaVVzpG.js +259 -0
  172. package/dist/web/assets/SettingsPage-BhaVVzpG.js.br +0 -0
  173. package/dist/web/assets/SettingsPage-BhaVVzpG.js.gz +0 -0
  174. package/dist/web/assets/ShellEntry-DNaOXNB7.js +2 -0
  175. package/dist/web/assets/ShellEntry-DNaOXNB7.js.br +0 -0
  176. package/dist/web/assets/ShellEntry-DNaOXNB7.js.gz +0 -0
  177. package/dist/web/assets/TasksPage-HHJ20hzK.js +1 -0
  178. package/dist/web/assets/TasksPage-HHJ20hzK.js.br +0 -0
  179. package/dist/web/assets/TasksPage-HHJ20hzK.js.gz +0 -0
  180. package/dist/web/assets/TerminalPanel-D7EDH4hR.js +9 -0
  181. package/dist/web/assets/TerminalPanel-D7EDH4hR.js.br +0 -0
  182. package/dist/web/assets/TerminalPanel-D7EDH4hR.js.gz +0 -0
  183. package/dist/web/assets/UsagePage-CyB5c-8F.js +1 -0
  184. package/dist/web/assets/UsagePage-CyB5c-8F.js.br +0 -0
  185. package/dist/web/assets/UsagePage-CyB5c-8F.js.gz +0 -0
  186. package/dist/web/assets/WorkPage-hiw_Nngy.js +1 -0
  187. package/dist/web/assets/WorkPage-hiw_Nngy.js.br +0 -0
  188. package/dist/web/assets/WorkPage-hiw_Nngy.js.gz +0 -0
  189. package/dist/web/assets/abap-BdImnpbu.js.br +0 -0
  190. package/dist/web/assets/abap-BdImnpbu.js.gz +0 -0
  191. package/dist/web/assets/actionscript-3-CoDkCxhg.js.br +0 -0
  192. package/dist/web/assets/actionscript-3-CoDkCxhg.js.gz +0 -0
  193. package/dist/web/assets/ada-bCR0ucgS.js.br +0 -0
  194. package/dist/web/assets/ada-bCR0ucgS.js.gz +0 -0
  195. package/dist/web/assets/androidBridge-DgaAG2Pi.js +1 -0
  196. package/dist/web/assets/androidBridge-DgaAG2Pi.js.br +0 -0
  197. package/dist/web/assets/androidBridge-DgaAG2Pi.js.gz +0 -0
  198. package/dist/web/assets/andromeeda-C4gqWexZ.js.br +0 -0
  199. package/dist/web/assets/andromeeda-C4gqWexZ.js.gz +0 -0
  200. package/dist/web/assets/angular-html-CU67Zn6k.js.br +0 -0
  201. package/dist/web/assets/angular-html-CU67Zn6k.js.gz +0 -0
  202. package/dist/web/assets/angular-ts-BwZT4LLn.js.br +0 -0
  203. package/dist/web/assets/angular-ts-BwZT4LLn.js.gz +0 -0
  204. package/dist/web/assets/apache-Pmp26Uib.js.br +0 -0
  205. package/dist/web/assets/apache-Pmp26Uib.js.gz +0 -0
  206. package/dist/web/assets/apex-D8_7TLub.js.br +0 -0
  207. package/dist/web/assets/apex-D8_7TLub.js.gz +0 -0
  208. package/dist/web/assets/apl-B4CMkyY2.js.br +0 -0
  209. package/dist/web/assets/apl-B4CMkyY2.js.gz +0 -0
  210. package/dist/web/assets/apl-dKokRX4l.js.br +0 -0
  211. package/dist/web/assets/apl-dKokRX4l.js.gz +0 -0
  212. package/dist/web/assets/applescript-Co6uUVPk.js.br +0 -0
  213. package/dist/web/assets/applescript-Co6uUVPk.js.gz +0 -0
  214. package/dist/web/assets/ara-BRHolxvo.js.br +0 -0
  215. package/dist/web/assets/ara-BRHolxvo.js.gz +0 -0
  216. package/dist/web/assets/arc-DoGfTGgR.js +1 -0
  217. package/dist/web/assets/arc-DoGfTGgR.js.br +0 -0
  218. package/dist/web/assets/arc-DoGfTGgR.js.gz +0 -0
  219. package/dist/web/assets/asciiarmor-Df11BRmG.js.br +0 -0
  220. package/dist/web/assets/asciiarmor-Df11BRmG.js.gz +0 -0
  221. package/dist/web/assets/asciidoc-Ve4PFQV2.js.br +0 -0
  222. package/dist/web/assets/asciidoc-Ve4PFQV2.js.gz +0 -0
  223. package/dist/web/assets/askKiki-CgAsWGRZ.js +2 -0
  224. package/dist/web/assets/askKiki-CgAsWGRZ.js.br +0 -0
  225. package/dist/web/assets/askKiki-CgAsWGRZ.js.gz +0 -0
  226. package/dist/web/assets/asm-D_Q5rh1f.js.br +0 -0
  227. package/dist/web/assets/asm-D_Q5rh1f.js.gz +0 -0
  228. package/dist/web/assets/asn1-EdZsLKOL.js.br +0 -0
  229. package/dist/web/assets/asn1-EdZsLKOL.js.gz +0 -0
  230. package/dist/web/assets/asterisk-B-8jnY81.js.br +0 -0
  231. package/dist/web/assets/asterisk-B-8jnY81.js.gz +0 -0
  232. package/dist/web/assets/astro-CbQHKStN.js.br +0 -0
  233. package/dist/web/assets/astro-CbQHKStN.js.gz +0 -0
  234. package/dist/web/assets/aurora-x-D-2ljcwZ.js.br +0 -0
  235. package/dist/web/assets/aurora-x-D-2ljcwZ.js.gz +0 -0
  236. package/dist/web/assets/awk-DMzUqQB5.js.br +0 -0
  237. package/dist/web/assets/awk-DMzUqQB5.js.gz +0 -0
  238. package/dist/web/assets/ayu-dark-DYE7WIF3.js.br +0 -0
  239. package/dist/web/assets/ayu-dark-DYE7WIF3.js.gz +0 -0
  240. package/dist/web/assets/ayu-light-BA47KaF1.js.br +0 -0
  241. package/dist/web/assets/ayu-light-BA47KaF1.js.gz +0 -0
  242. package/dist/web/assets/ayu-mirage-32ctXXKs.js.br +0 -0
  243. package/dist/web/assets/ayu-mirage-32ctXXKs.js.gz +0 -0
  244. package/dist/web/assets/ballerina-BFfxhgS-.js.br +0 -0
  245. package/dist/web/assets/ballerina-BFfxhgS-.js.gz +0 -0
  246. package/dist/web/assets/band-dPffDWoQ.js +1 -0
  247. package/dist/web/assets/band-dPffDWoQ.js.br +0 -0
  248. package/dist/web/assets/band-dPffDWoQ.js.gz +0 -0
  249. package/dist/web/assets/bat-BkioyH1T.js.br +0 -0
  250. package/dist/web/assets/bat-BkioyH1T.js.gz +0 -0
  251. package/dist/web/assets/beancount-k_qm7-4y.js.br +0 -0
  252. package/dist/web/assets/beancount-k_qm7-4y.js.gz +0 -0
  253. package/dist/web/assets/berry-uYugtg8r.js.br +0 -0
  254. package/dist/web/assets/berry-uYugtg8r.js.gz +0 -0
  255. package/dist/web/assets/bibtex-CHM0blh-.js.br +0 -0
  256. package/dist/web/assets/bibtex-CHM0blh-.js.gz +0 -0
  257. package/dist/web/assets/bicep-Bmn6On1c.js.br +0 -0
  258. package/dist/web/assets/bicep-Bmn6On1c.js.gz +0 -0
  259. package/dist/web/assets/bird2-DPOp833l.js.br +0 -0
  260. package/dist/web/assets/bird2-DPOp833l.js.gz +0 -0
  261. package/dist/web/assets/blade-D4QpJJKB.js.br +0 -0
  262. package/dist/web/assets/blade-D4QpJJKB.js.gz +0 -0
  263. package/dist/web/assets/brainfuck-C4LP7Hcl.js.br +0 -0
  264. package/dist/web/assets/brainfuck-C4LP7Hcl.js.gz +0 -0
  265. package/dist/web/assets/bsl-BO_Y6i37.js.br +0 -0
  266. package/dist/web/assets/bsl-BO_Y6i37.js.gz +0 -0
  267. package/dist/web/assets/c-BIGW1oBm.js.br +0 -0
  268. package/dist/web/assets/c-BIGW1oBm.js.gz +0 -0
  269. package/dist/web/assets/c3-eo99z4R2.js.br +0 -0
  270. package/dist/web/assets/c3-eo99z4R2.js.gz +0 -0
  271. package/dist/web/assets/cadence-Bv_4Rxtq.js.br +0 -0
  272. package/dist/web/assets/cadence-Bv_4Rxtq.js.gz +0 -0
  273. package/dist/web/assets/cairo-KRGpt6FW.js.br +0 -0
  274. package/dist/web/assets/cairo-KRGpt6FW.js.gz +0 -0
  275. package/dist/web/assets/catppuccin-frappe-DFWUc33u.js.br +0 -0
  276. package/dist/web/assets/catppuccin-frappe-DFWUc33u.js.gz +0 -0
  277. package/dist/web/assets/catppuccin-latte-C9dUb6Cb.js.br +0 -0
  278. package/dist/web/assets/catppuccin-latte-C9dUb6Cb.js.gz +0 -0
  279. package/dist/web/assets/catppuccin-macchiato-DQyhUUbL.js.br +0 -0
  280. package/dist/web/assets/catppuccin-macchiato-DQyhUUbL.js.gz +0 -0
  281. package/dist/web/assets/catppuccin-mocha-D87Tk5Gz.js.br +0 -0
  282. package/dist/web/assets/catppuccin-mocha-D87Tk5Gz.js.gz +0 -0
  283. package/dist/web/assets/channel-BwCaPRlV.js +1 -0
  284. package/dist/web/assets/channel-BwCaPRlV.js.br +0 -0
  285. package/dist/web/assets/channel-BwCaPRlV.js.gz +0 -0
  286. package/dist/web/assets/clarity-D53aC0YG.js.br +0 -0
  287. package/dist/web/assets/clarity-D53aC0YG.js.gz +0 -0
  288. package/dist/web/assets/client-cAizUM-b.js +7 -0
  289. package/dist/web/assets/client-cAizUM-b.js.br +0 -0
  290. package/dist/web/assets/client-cAizUM-b.js.gz +0 -0
  291. package/dist/web/assets/clike-B9uivgTg.js.br +0 -0
  292. package/dist/web/assets/clike-B9uivgTg.js.gz +0 -0
  293. package/dist/web/assets/clojure-BMjYHr_A.js.br +0 -0
  294. package/dist/web/assets/clojure-BMjYHr_A.js.gz +0 -0
  295. package/dist/web/assets/clojure-P80f7IUj.js.br +0 -0
  296. package/dist/web/assets/clojure-P80f7IUj.js.gz +0 -0
  297. package/dist/web/assets/clone-JiRK1kR-.js +1 -0
  298. package/dist/web/assets/clone-JiRK1kR-.js.br +0 -0
  299. package/dist/web/assets/clone-JiRK1kR-.js.gz +0 -0
  300. package/dist/web/assets/cmake-BQqOBYOt.js.br +0 -0
  301. package/dist/web/assets/cmake-BQqOBYOt.js.gz +0 -0
  302. package/dist/web/assets/cmake-D1j8_8rp.js.br +0 -0
  303. package/dist/web/assets/cmake-D1j8_8rp.js.gz +0 -0
  304. package/dist/web/assets/cobol-CWcv1MsR.js.br +0 -0
  305. package/dist/web/assets/cobol-CWcv1MsR.js.gz +0 -0
  306. package/dist/web/assets/cobol-nwyudZeR.js.br +0 -0
  307. package/dist/web/assets/cobol-nwyudZeR.js.gz +0 -0
  308. package/dist/web/assets/codeowners-Bp6g37R7.js.br +0 -0
  309. package/dist/web/assets/codeowners-Bp6g37R7.js.gz +0 -0
  310. package/dist/web/assets/codeql-DsOJ9woJ.js.br +0 -0
  311. package/dist/web/assets/codeql-DsOJ9woJ.js.gz +0 -0
  312. package/dist/web/assets/coffee-Ch7k5sss.js.br +0 -0
  313. package/dist/web/assets/coffee-Ch7k5sss.js.gz +0 -0
  314. package/dist/web/assets/coffeescript-S37ZYGWr.js.br +0 -0
  315. package/dist/web/assets/coffeescript-S37ZYGWr.js.gz +0 -0
  316. package/dist/web/assets/common-lisp-Cg-RD9OK.js.br +0 -0
  317. package/dist/web/assets/common-lisp-Cg-RD9OK.js.gz +0 -0
  318. package/dist/web/assets/commonlisp-DBKNyK5s.js.br +0 -0
  319. package/dist/web/assets/commonlisp-DBKNyK5s.js.gz +0 -0
  320. package/dist/web/assets/connection-5XKg4sL2.js +404 -0
  321. package/dist/web/assets/connection-5XKg4sL2.js.br +0 -0
  322. package/dist/web/assets/connection-5XKg4sL2.js.gz +0 -0
  323. package/dist/web/assets/controls-C3UrNiBn.js +1 -0
  324. package/dist/web/assets/controls-C3UrNiBn.js.br +0 -0
  325. package/dist/web/assets/controls-C3UrNiBn.js.gz +0 -0
  326. package/dist/web/assets/coq-DkFqJrB1.js.br +0 -0
  327. package/dist/web/assets/coq-DkFqJrB1.js.gz +0 -0
  328. package/dist/web/assets/cpp-CofmeUqb.js.br +0 -0
  329. package/dist/web/assets/cpp-CofmeUqb.js.gz +0 -0
  330. package/dist/web/assets/crystal-SjHAIU92.js.br +0 -0
  331. package/dist/web/assets/crystal-SjHAIU92.js.gz +0 -0
  332. package/dist/web/assets/crystal-tKQVLTB8.js.br +0 -0
  333. package/dist/web/assets/crystal-tKQVLTB8.js.gz +0 -0
  334. package/dist/web/assets/csharp-COcwbKMJ.js.br +0 -0
  335. package/dist/web/assets/csharp-COcwbKMJ.js.gz +0 -0
  336. package/dist/web/assets/css-BnMrqG3P.js.br +0 -0
  337. package/dist/web/assets/css-BnMrqG3P.js.gz +0 -0
  338. package/dist/web/assets/css-DPfMkruS.js.br +0 -0
  339. package/dist/web/assets/css-DPfMkruS.js.gz +0 -0
  340. package/dist/web/assets/csv-fuZLfV_i.js.br +0 -0
  341. package/dist/web/assets/csv-fuZLfV_i.js.gz +0 -0
  342. package/dist/web/assets/cue-D82EKSYY.js.br +0 -0
  343. package/dist/web/assets/cue-D82EKSYY.js.gz +0 -0
  344. package/dist/web/assets/cypher-COkxafJQ.js.br +0 -0
  345. package/dist/web/assets/cypher-COkxafJQ.js.gz +0 -0
  346. package/dist/web/assets/cypher-C_CwsFkJ.js.br +0 -0
  347. package/dist/web/assets/cypher-C_CwsFkJ.js.gz +0 -0
  348. package/dist/web/assets/cytoscape-cose-bilkent-CGdh9URw.js +1 -0
  349. package/dist/web/assets/cytoscape-cose-bilkent-CGdh9URw.js.br +0 -0
  350. package/dist/web/assets/cytoscape-cose-bilkent-CGdh9URw.js.gz +0 -0
  351. package/dist/web/assets/cytoscape-fcose-ZavmgdCc.js +1 -0
  352. package/dist/web/assets/cytoscape-fcose-ZavmgdCc.js.br +0 -0
  353. package/dist/web/assets/cytoscape-fcose-ZavmgdCc.js.gz +0 -0
  354. package/dist/web/assets/cytoscape.esm-nFXppDBa.js.br +0 -0
  355. package/dist/web/assets/cytoscape.esm-nFXppDBa.js.gz +0 -0
  356. package/dist/web/assets/d-85-TOEBH.js.br +0 -0
  357. package/dist/web/assets/d-85-TOEBH.js.gz +0 -0
  358. package/dist/web/assets/d-pRatUO7H.js.br +0 -0
  359. package/dist/web/assets/d-pRatUO7H.js.gz +0 -0
  360. package/dist/web/assets/dark-plus-C3mMm8J8.js.br +0 -0
  361. package/dist/web/assets/dark-plus-C3mMm8J8.js.gz +0 -0
  362. package/dist/web/assets/dart-CF10PKvl.js.br +0 -0
  363. package/dist/web/assets/dart-CF10PKvl.js.gz +0 -0
  364. package/dist/web/assets/dax-CEL-wOlO.js.br +0 -0
  365. package/dist/web/assets/dax-CEL-wOlO.js.gz +0 -0
  366. package/dist/web/assets/{defaultLocale-DX6XiGOO.js → defaultLocale-5voVPcsN.js} +1 -1
  367. package/dist/web/assets/defaultLocale-5voVPcsN.js.br +0 -0
  368. package/dist/web/assets/defaultLocale-5voVPcsN.js.gz +0 -0
  369. package/dist/web/assets/desktop-BmXAJ9_W.js.br +0 -0
  370. package/dist/web/assets/desktop-BmXAJ9_W.js.gz +0 -0
  371. package/dist/web/assets/diff-D97Zzqfu.js.br +0 -0
  372. package/dist/web/assets/diff-D97Zzqfu.js.gz +0 -0
  373. package/dist/web/assets/diff-DbItnlRl.js.br +0 -0
  374. package/dist/web/assets/diff-DbItnlRl.js.gz +0 -0
  375. package/dist/web/assets/docker-BcOcwvcX.js.br +0 -0
  376. package/dist/web/assets/docker-BcOcwvcX.js.gz +0 -0
  377. package/dist/web/assets/dockerfile-BKs6k2Af.js.br +0 -0
  378. package/dist/web/assets/dockerfile-BKs6k2Af.js.gz +0 -0
  379. package/dist/web/assets/dotenv-Da5cRb03.js.br +0 -0
  380. package/dist/web/assets/dotenv-Da5cRb03.js.gz +0 -0
  381. package/dist/web/assets/dracula-BzJJZx-M.js.br +0 -0
  382. package/dist/web/assets/dracula-BzJJZx-M.js.gz +0 -0
  383. package/dist/web/assets/dracula-soft-BXkSAIEj.js.br +0 -0
  384. package/dist/web/assets/dracula-soft-BXkSAIEj.js.gz +0 -0
  385. package/dist/web/assets/dream-maker-BtqSS_iP.js.br +0 -0
  386. package/dist/web/assets/dream-maker-BtqSS_iP.js.gz +0 -0
  387. package/dist/web/assets/dtd-DF_7sFjM.js.br +0 -0
  388. package/dist/web/assets/dtd-DF_7sFjM.js.gz +0 -0
  389. package/dist/web/assets/duration-BNAPaH6N.js +1 -0
  390. package/dist/web/assets/duration-BNAPaH6N.js.br +0 -0
  391. package/dist/web/assets/duration-BNAPaH6N.js.gz +0 -0
  392. package/dist/web/assets/dylan-DwRh75JA.js.br +0 -0
  393. package/dist/web/assets/dylan-DwRh75JA.js.gz +0 -0
  394. package/dist/web/assets/ebnf-CDyGwa7X.js.br +0 -0
  395. package/dist/web/assets/ebnf-CDyGwa7X.js.gz +0 -0
  396. package/dist/web/assets/ecl-Cabwm37j.js.br +0 -0
  397. package/dist/web/assets/ecl-Cabwm37j.js.gz +0 -0
  398. package/dist/web/assets/edge-BkV0erSs.js.br +0 -0
  399. package/dist/web/assets/edge-BkV0erSs.js.gz +0 -0
  400. package/dist/web/assets/eiffel-CnydiIhH.js.br +0 -0
  401. package/dist/web/assets/eiffel-CnydiIhH.js.gz +0 -0
  402. package/dist/web/assets/elixir-CDX3lj18.js.br +0 -0
  403. package/dist/web/assets/elixir-CDX3lj18.js.gz +0 -0
  404. package/dist/web/assets/elm-DbKCFpqz.js.br +0 -0
  405. package/dist/web/assets/elm-DbKCFpqz.js.gz +0 -0
  406. package/dist/web/assets/elm-vLlmbW-K.js.br +0 -0
  407. package/dist/web/assets/elm-vLlmbW-K.js.gz +0 -0
  408. package/dist/web/assets/emacs-lisp-C9XAeP06.js.br +0 -0
  409. package/dist/web/assets/emacs-lisp-C9XAeP06.js.gz +0 -0
  410. package/dist/web/assets/erb-B12qg9BL.js.br +0 -0
  411. package/dist/web/assets/erb-B12qg9BL.js.gz +0 -0
  412. package/dist/web/assets/erlang-BNw1qcRV.js.br +0 -0
  413. package/dist/web/assets/erlang-BNw1qcRV.js.gz +0 -0
  414. package/dist/web/assets/erlang-DsQrWhSR.js.br +0 -0
  415. package/dist/web/assets/erlang-DsQrWhSR.js.gz +0 -0
  416. package/dist/web/assets/everforest-dark-BgDCqdQA.js.br +0 -0
  417. package/dist/web/assets/everforest-dark-BgDCqdQA.js.gz +0 -0
  418. package/dist/web/assets/everforest-light-C8M2exoo.js.br +0 -0
  419. package/dist/web/assets/everforest-light-C8M2exoo.js.gz +0 -0
  420. package/dist/web/assets/export-BlURphmw.js +2 -0
  421. package/dist/web/assets/export-BlURphmw.js.br +0 -0
  422. package/dist/web/assets/export-BlURphmw.js.gz +0 -0
  423. package/dist/web/assets/factor-kuTfRLto.js.br +0 -0
  424. package/dist/web/assets/factor-kuTfRLto.js.gz +0 -0
  425. package/dist/web/assets/fcl-Kvtd6kyn.js.br +0 -0
  426. package/dist/web/assets/fcl-Kvtd6kyn.js.gz +0 -0
  427. package/dist/web/assets/fennel-BYunw83y.js.br +0 -0
  428. package/dist/web/assets/fennel-BYunw83y.js.gz +0 -0
  429. package/dist/web/assets/fish-BvzEVeQv.js.br +0 -0
  430. package/dist/web/assets/fish-BvzEVeQv.js.gz +0 -0
  431. package/dist/web/assets/fluent-C4IJs8-o.js.br +0 -0
  432. package/dist/web/assets/fluent-C4IJs8-o.js.gz +0 -0
  433. package/dist/web/assets/forth-Ffai-XNe.js.br +0 -0
  434. package/dist/web/assets/forth-Ffai-XNe.js.gz +0 -0
  435. package/dist/web/assets/fortran-DYz_wnZ1.js.br +0 -0
  436. package/dist/web/assets/fortran-DYz_wnZ1.js.gz +0 -0
  437. package/dist/web/assets/fortran-fixed-form-CkoXwp7k.js.br +0 -0
  438. package/dist/web/assets/fortran-fixed-form-CkoXwp7k.js.gz +0 -0
  439. package/dist/web/assets/fortran-free-form-BxgE0vQu.js.br +0 -0
  440. package/dist/web/assets/fortran-free-form-BxgE0vQu.js.gz +0 -0
  441. package/dist/web/assets/fsharp-CXgrBDvD.js.br +0 -0
  442. package/dist/web/assets/fsharp-CXgrBDvD.js.gz +0 -0
  443. package/dist/web/assets/gas-Bneqetm1.js.br +0 -0
  444. package/dist/web/assets/gas-Bneqetm1.js.gz +0 -0
  445. package/dist/web/assets/gdresource-BOOCDP_w.js.br +0 -0
  446. package/dist/web/assets/gdresource-BOOCDP_w.js.gz +0 -0
  447. package/dist/web/assets/gdscript-C5YyOfLZ.js.br +0 -0
  448. package/dist/web/assets/gdscript-C5YyOfLZ.js.gz +0 -0
  449. package/dist/web/assets/gdshader-DkwncUOv.js.br +0 -0
  450. package/dist/web/assets/gdshader-DkwncUOv.js.gz +0 -0
  451. package/dist/web/assets/genie-D0YGMca9.js.br +0 -0
  452. package/dist/web/assets/genie-D0YGMca9.js.gz +0 -0
  453. package/dist/web/assets/gherkin-DyxjwDmM.js.br +0 -0
  454. package/dist/web/assets/gherkin-DyxjwDmM.js.gz +0 -0
  455. package/dist/web/assets/gherkin-heZmZLOM.js.br +0 -0
  456. package/dist/web/assets/gherkin-heZmZLOM.js.gz +0 -0
  457. package/dist/web/assets/git-commit-F4YmCXRG.js.br +0 -0
  458. package/dist/web/assets/git-commit-F4YmCXRG.js.gz +0 -0
  459. package/dist/web/assets/git-rebase-r7XF79zn.js.br +0 -0
  460. package/dist/web/assets/git-rebase-r7XF79zn.js.gz +0 -0
  461. package/dist/web/assets/github-dark-DHJKELXO.js.br +0 -0
  462. package/dist/web/assets/github-dark-DHJKELXO.js.gz +0 -0
  463. package/dist/web/assets/github-dark-default-Cuk6v7N8.js.br +0 -0
  464. package/dist/web/assets/github-dark-default-Cuk6v7N8.js.gz +0 -0
  465. package/dist/web/assets/github-dark-dimmed-DH5Ifo-i.js.br +0 -0
  466. package/dist/web/assets/github-dark-dimmed-DH5Ifo-i.js.gz +0 -0
  467. package/dist/web/assets/github-dark-high-contrast-E3gJ1_iC.js.br +0 -0
  468. package/dist/web/assets/github-dark-high-contrast-E3gJ1_iC.js.gz +0 -0
  469. package/dist/web/assets/github-light-DAi9KRSo.js.br +0 -0
  470. package/dist/web/assets/github-light-DAi9KRSo.js.gz +0 -0
  471. package/dist/web/assets/github-light-default-D7oLnXFd.js.br +0 -0
  472. package/dist/web/assets/github-light-default-D7oLnXFd.js.gz +0 -0
  473. package/dist/web/assets/github-light-high-contrast-BfjtVDDH.js.br +0 -0
  474. package/dist/web/assets/github-light-high-contrast-BfjtVDDH.js.gz +0 -0
  475. package/dist/web/assets/gleam-BspZqrRM.js.br +0 -0
  476. package/dist/web/assets/gleam-BspZqrRM.js.gz +0 -0
  477. package/dist/web/assets/glimmer-js-Rg0-pVw9.js.br +0 -0
  478. package/dist/web/assets/glimmer-js-Rg0-pVw9.js.gz +0 -0
  479. package/dist/web/assets/glimmer-ts-U6CK756n.js.br +0 -0
  480. package/dist/web/assets/glimmer-ts-U6CK756n.js.gz +0 -0
  481. package/dist/web/assets/glsl-DplSGwfg.js.br +0 -0
  482. package/dist/web/assets/glsl-DplSGwfg.js.gz +0 -0
  483. package/dist/web/assets/gn-n2N0HUVH.js.br +0 -0
  484. package/dist/web/assets/gn-n2N0HUVH.js.gz +0 -0
  485. package/dist/web/assets/gnuplot-DdkO51Og.js.br +0 -0
  486. package/dist/web/assets/gnuplot-DdkO51Og.js.gz +0 -0
  487. package/dist/web/assets/go-CxLEBnE3.js.br +0 -0
  488. package/dist/web/assets/go-CxLEBnE3.js.gz +0 -0
  489. package/dist/web/assets/graph--OzhPTMs.js.br +0 -0
  490. package/dist/web/assets/graph--OzhPTMs.js.gz +0 -0
  491. package/dist/web/assets/graphql-ChdNCCLP.js.br +0 -0
  492. package/dist/web/assets/graphql-ChdNCCLP.js.gz +0 -0
  493. package/dist/web/assets/groovy-D9Dt4D0W.js.br +0 -0
  494. package/dist/web/assets/groovy-D9Dt4D0W.js.gz +0 -0
  495. package/dist/web/assets/groovy-gcz8RCvz.js.br +0 -0
  496. package/dist/web/assets/groovy-gcz8RCvz.js.gz +0 -0
  497. package/dist/web/assets/gruvbox-dark-hard-CFHQjOhq.js.br +0 -0
  498. package/dist/web/assets/gruvbox-dark-hard-CFHQjOhq.js.gz +0 -0
  499. package/dist/web/assets/gruvbox-dark-medium-GsRaNv29.js.br +0 -0
  500. package/dist/web/assets/gruvbox-dark-medium-GsRaNv29.js.gz +0 -0
  501. package/dist/web/assets/gruvbox-dark-soft-CVdnzihN.js.br +0 -0
  502. package/dist/web/assets/gruvbox-dark-soft-CVdnzihN.js.gz +0 -0
  503. package/dist/web/assets/gruvbox-light-hard-CH1njM8p.js.br +0 -0
  504. package/dist/web/assets/gruvbox-light-hard-CH1njM8p.js.gz +0 -0
  505. package/dist/web/assets/gruvbox-light-medium-DRw_LuNl.js.br +0 -0
  506. package/dist/web/assets/gruvbox-light-medium-DRw_LuNl.js.gz +0 -0
  507. package/dist/web/assets/gruvbox-light-soft-hJgmCMqR.js.br +0 -0
  508. package/dist/web/assets/gruvbox-light-soft-hJgmCMqR.js.gz +0 -0
  509. package/dist/web/assets/hack-CaT9iCJl.js.br +0 -0
  510. package/dist/web/assets/hack-CaT9iCJl.js.gz +0 -0
  511. package/dist/web/assets/haml-B8DHNrY2.js.br +0 -0
  512. package/dist/web/assets/haml-B8DHNrY2.js.gz +0 -0
  513. package/dist/web/assets/handlebars-BL8al0AC.js.br +0 -0
  514. package/dist/web/assets/handlebars-BL8al0AC.js.gz +0 -0
  515. package/dist/web/assets/haskell-Cw1EW3IL.js.br +0 -0
  516. package/dist/web/assets/haskell-Cw1EW3IL.js.gz +0 -0
  517. package/dist/web/assets/haskell-Df6bDoY_.js.br +0 -0
  518. package/dist/web/assets/haskell-Df6bDoY_.js.gz +0 -0
  519. package/dist/web/assets/haxe-CzTSHFRz.js.br +0 -0
  520. package/dist/web/assets/haxe-CzTSHFRz.js.gz +0 -0
  521. package/dist/web/assets/haxe-H-WmDvRZ.js.br +0 -0
  522. package/dist/web/assets/haxe-H-WmDvRZ.js.gz +0 -0
  523. package/dist/web/assets/hcl-BWvSN4gD.js.br +0 -0
  524. package/dist/web/assets/hcl-BWvSN4gD.js.gz +0 -0
  525. package/dist/web/assets/highlighted-body-OFNGDK62-CF-6XyfM.js +1 -0
  526. package/dist/web/assets/highlighted-body-OFNGDK62-CF-6XyfM.js.br +0 -0
  527. package/dist/web/assets/highlighted-body-OFNGDK62-CF-6XyfM.js.gz +0 -0
  528. package/dist/web/assets/hjson-D5-asLiD.js.br +0 -0
  529. package/dist/web/assets/hjson-D5-asLiD.js.gz +0 -0
  530. package/dist/web/assets/hlsl-D3lLCCz7.js.br +0 -0
  531. package/dist/web/assets/hlsl-D3lLCCz7.js.gz +0 -0
  532. package/dist/web/assets/horizon-BUw7H-hv.js.br +0 -0
  533. package/dist/web/assets/horizon-BUw7H-hv.js.gz +0 -0
  534. package/dist/web/assets/horizon-bright-Cn-bp-IR.js.br +0 -0
  535. package/dist/web/assets/horizon-bright-Cn-bp-IR.js.gz +0 -0
  536. package/dist/web/assets/houston-DnULxvSX.js.br +0 -0
  537. package/dist/web/assets/houston-DnULxvSX.js.gz +0 -0
  538. package/dist/web/assets/html-GMplVEZG.js.br +0 -0
  539. package/dist/web/assets/html-GMplVEZG.js.gz +0 -0
  540. package/dist/web/assets/html-derivative-BFtXZ54Q.js.br +0 -0
  541. package/dist/web/assets/html-derivative-BFtXZ54Q.js.gz +0 -0
  542. package/dist/web/assets/http-DBlCnlav.js.br +0 -0
  543. package/dist/web/assets/http-DBlCnlav.js.gz +0 -0
  544. package/dist/web/assets/http-jrhK8wxY.js.br +0 -0
  545. package/dist/web/assets/http-jrhK8wxY.js.gz +0 -0
  546. package/dist/web/assets/hurl-irOxFIW8.js.br +0 -0
  547. package/dist/web/assets/hurl-irOxFIW8.js.gz +0 -0
  548. package/dist/web/assets/hxml-Bvhsp5Yf.js.br +0 -0
  549. package/dist/web/assets/hxml-Bvhsp5Yf.js.gz +0 -0
  550. package/dist/web/assets/hy-DFXneXwc.js.br +0 -0
  551. package/dist/web/assets/hy-DFXneXwc.js.gz +0 -0
  552. package/dist/web/assets/idl-BEugSyMb.js.br +0 -0
  553. package/dist/web/assets/idl-BEugSyMb.js.gz +0 -0
  554. package/dist/web/assets/imba-DGztddWO.js.br +0 -0
  555. package/dist/web/assets/imba-DGztddWO.js.gz +0 -0
  556. package/dist/web/assets/{index-DmwFFSkV.js → index-AtrTtxWl.js} +1 -1
  557. package/dist/web/assets/index-AtrTtxWl.js.br +0 -0
  558. package/dist/web/assets/index-AtrTtxWl.js.gz +0 -0
  559. package/dist/web/assets/index-BBEGEj83.js +1 -0
  560. package/dist/web/assets/index-BBEGEj83.js.br +0 -0
  561. package/dist/web/assets/index-BBEGEj83.js.gz +0 -0
  562. package/dist/web/assets/index-BDdIDEp4.js +1 -0
  563. package/dist/web/assets/index-BDdIDEp4.js.br +0 -0
  564. package/dist/web/assets/index-BDdIDEp4.js.gz +0 -0
  565. package/dist/web/assets/index-BIfumokk.js +1 -0
  566. package/dist/web/assets/index-BIfumokk.js.br +0 -0
  567. package/dist/web/assets/index-BIfumokk.js.gz +0 -0
  568. package/dist/web/assets/index-BLi2nTxe.js +206 -0
  569. package/dist/web/assets/index-BLi2nTxe.js.br +0 -0
  570. package/dist/web/assets/index-BLi2nTxe.js.gz +0 -0
  571. package/dist/web/assets/index-BNFiIuBC.js +1 -0
  572. package/dist/web/assets/index-BNFiIuBC.js.br +0 -0
  573. package/dist/web/assets/index-BNFiIuBC.js.gz +0 -0
  574. package/dist/web/assets/index-BOXDlCpS.js +1 -0
  575. package/dist/web/assets/index-BOXDlCpS.js.br +0 -0
  576. package/dist/web/assets/index-BOXDlCpS.js.gz +0 -0
  577. package/dist/web/assets/{index-CBvwNH_H.js → index-BPG2nU9y.js} +1 -1
  578. package/dist/web/assets/index-BPG2nU9y.js.br +0 -0
  579. package/dist/web/assets/index-BPG2nU9y.js.gz +0 -0
  580. package/dist/web/assets/index-BSVOVe3D.js +1 -0
  581. package/dist/web/assets/index-BSVOVe3D.js.br +0 -0
  582. package/dist/web/assets/index-BSVOVe3D.js.gz +0 -0
  583. package/dist/web/assets/{index-CPSWYh_R.js → index-BT8zjpNF.js} +5 -5
  584. package/dist/web/assets/index-BT8zjpNF.js.br +0 -0
  585. package/dist/web/assets/index-BT8zjpNF.js.gz +0 -0
  586. package/dist/web/assets/index-BTHoDcN1.js +7 -0
  587. package/dist/web/assets/index-BTHoDcN1.js.br +0 -0
  588. package/dist/web/assets/index-BTHoDcN1.js.gz +0 -0
  589. package/dist/web/assets/{index-DRo5Y_9p.js → index-BWFj-16K.js} +1 -1
  590. package/dist/web/assets/index-BWFj-16K.js.br +0 -0
  591. package/dist/web/assets/index-BWFj-16K.js.gz +0 -0
  592. package/dist/web/assets/index-BYkQjRc-.js +1 -0
  593. package/dist/web/assets/index-BYkQjRc-.js.br +0 -0
  594. package/dist/web/assets/index-BYkQjRc-.js.gz +0 -0
  595. package/dist/web/assets/{index-BxYCSNg_.js → index-BbmM2LEW.js} +2 -2
  596. package/dist/web/assets/index-BbmM2LEW.js.br +0 -0
  597. package/dist/web/assets/index-BbmM2LEW.js.gz +0 -0
  598. package/dist/web/assets/index-C6n6XERd.js +1 -0
  599. package/dist/web/assets/index-C6n6XERd.js.br +0 -0
  600. package/dist/web/assets/index-C6n6XERd.js.gz +0 -0
  601. package/dist/web/assets/index-C83WoUbd.js +1 -0
  602. package/dist/web/assets/index-C83WoUbd.js.br +0 -0
  603. package/dist/web/assets/index-C83WoUbd.js.gz +0 -0
  604. package/dist/web/assets/index-C8DDOUJx.css +1 -0
  605. package/dist/web/assets/index-C8DDOUJx.css.br +0 -0
  606. package/dist/web/assets/index-C8DDOUJx.css.gz +0 -0
  607. package/dist/web/assets/index-C9DdZFNJ.js +1 -0
  608. package/dist/web/assets/index-C9DdZFNJ.js.br +0 -0
  609. package/dist/web/assets/index-C9DdZFNJ.js.gz +0 -0
  610. package/dist/web/assets/index-CP99-KdF.js +1 -0
  611. package/dist/web/assets/index-CP99-KdF.js.br +0 -0
  612. package/dist/web/assets/index-CP99-KdF.js.gz +0 -0
  613. package/dist/web/assets/index-CVrtusX9.js +1 -0
  614. package/dist/web/assets/index-CVrtusX9.js.br +0 -0
  615. package/dist/web/assets/index-CVrtusX9.js.gz +0 -0
  616. package/dist/web/assets/{index-DfUpwUTM.js → index-ChTpz7dO.js} +2 -2
  617. package/dist/web/assets/index-ChTpz7dO.js.br +0 -0
  618. package/dist/web/assets/index-ChTpz7dO.js.gz +0 -0
  619. package/dist/web/assets/index-CjceQ8Nh.js +1 -0
  620. package/dist/web/assets/index-CjceQ8Nh.js.br +0 -0
  621. package/dist/web/assets/index-CjceQ8Nh.js.gz +0 -0
  622. package/dist/web/assets/{index-CjvqtF2I.js → index-CsKZwkF5.js} +1 -1
  623. package/dist/web/assets/index-CsKZwkF5.js.br +0 -0
  624. package/dist/web/assets/index-CsKZwkF5.js.gz +0 -0
  625. package/dist/web/assets/index-CvYzv8kf.js +1 -0
  626. package/dist/web/assets/index-CvYzv8kf.js.br +0 -0
  627. package/dist/web/assets/index-CvYzv8kf.js.gz +0 -0
  628. package/dist/web/assets/index-D2CHDVPg.js +1 -0
  629. package/dist/web/assets/index-D2CHDVPg.js.br +0 -0
  630. package/dist/web/assets/index-D2CHDVPg.js.gz +0 -0
  631. package/dist/web/assets/index-D4M-EXnj.js +1 -0
  632. package/dist/web/assets/index-D4M-EXnj.js.br +0 -0
  633. package/dist/web/assets/index-D4M-EXnj.js.gz +0 -0
  634. package/dist/web/assets/{index-BvRBCpc6.js → index-DHqpUC48.js} +2 -2
  635. package/dist/web/assets/index-DHqpUC48.js.br +0 -0
  636. package/dist/web/assets/index-DHqpUC48.js.gz +0 -0
  637. package/dist/web/assets/index-Da0Nrt28.js +1 -0
  638. package/dist/web/assets/index-Da0Nrt28.js.br +0 -0
  639. package/dist/web/assets/index-Da0Nrt28.js.gz +0 -0
  640. package/dist/web/assets/index-DyWRj5df.js +1 -0
  641. package/dist/web/assets/index-DyWRj5df.js.br +0 -0
  642. package/dist/web/assets/index-DyWRj5df.js.gz +0 -0
  643. package/dist/web/assets/{index-Dkbz748K.js → index-DyZAPivK.js} +4 -4
  644. package/dist/web/assets/index-DyZAPivK.js.br +0 -0
  645. package/dist/web/assets/index-DyZAPivK.js.gz +0 -0
  646. package/dist/web/assets/index-FqFCN7CT.js +13 -0
  647. package/dist/web/assets/index-FqFCN7CT.js.br +0 -0
  648. package/dist/web/assets/index-FqFCN7CT.js.gz +0 -0
  649. package/dist/web/assets/{index-Br3AlBrQ.js → index-L9ABPsXe.js} +1 -1
  650. package/dist/web/assets/index-L9ABPsXe.js.br +0 -0
  651. package/dist/web/assets/index-L9ABPsXe.js.gz +0 -0
  652. package/dist/web/assets/ini-BEwlwnbL.js.br +0 -0
  653. package/dist/web/assets/ini-BEwlwnbL.js.gz +0 -0
  654. package/dist/web/assets/init-Gi6I4Gst.js.br +0 -0
  655. package/dist/web/assets/init-Gi6I4Gst.js.gz +0 -0
  656. package/dist/web/assets/java-CylS5w8V.js.br +0 -0
  657. package/dist/web/assets/java-CylS5w8V.js.gz +0 -0
  658. package/dist/web/assets/javascript-iXu5QeM3.js.br +0 -0
  659. package/dist/web/assets/javascript-iXu5QeM3.js.gz +0 -0
  660. package/dist/web/assets/javascript-wDzz0qaB.js.br +0 -0
  661. package/dist/web/assets/javascript-wDzz0qaB.js.gz +0 -0
  662. package/dist/web/assets/jinja-4LBKfQ-Z.js.br +0 -0
  663. package/dist/web/assets/jinja-4LBKfQ-Z.js.gz +0 -0
  664. package/dist/web/assets/jison-wvAkD_A8.js.br +0 -0
  665. package/dist/web/assets/jison-wvAkD_A8.js.gz +0 -0
  666. package/dist/web/assets/json-Cp-IABpG.js.br +0 -0
  667. package/dist/web/assets/json-Cp-IABpG.js.gz +0 -0
  668. package/dist/web/assets/json-DQCdPPbD.js +1 -0
  669. package/dist/web/assets/json-DQCdPPbD.js.br +0 -0
  670. package/dist/web/assets/json-DQCdPPbD.js.gz +0 -0
  671. package/dist/web/assets/json5-C9tS-k6U.js.br +0 -0
  672. package/dist/web/assets/json5-C9tS-k6U.js.gz +0 -0
  673. package/dist/web/assets/jsonc-Des-eS-w.js.br +0 -0
  674. package/dist/web/assets/jsonc-Des-eS-w.js.gz +0 -0
  675. package/dist/web/assets/jsonl-DcaNXYhu.js.br +0 -0
  676. package/dist/web/assets/jsonl-DcaNXYhu.js.gz +0 -0
  677. package/dist/web/assets/jsonnet-DFQXde-d.js.br +0 -0
  678. package/dist/web/assets/jsonnet-DFQXde-d.js.gz +0 -0
  679. package/dist/web/assets/jssm-C2t-YnRu.js.br +0 -0
  680. package/dist/web/assets/jssm-C2t-YnRu.js.gz +0 -0
  681. package/dist/web/assets/jsx-g9-lgVsj.js.br +0 -0
  682. package/dist/web/assets/jsx-g9-lgVsj.js.gz +0 -0
  683. package/dist/web/assets/julia-CxzCAyBv.js.br +0 -0
  684. package/dist/web/assets/julia-CxzCAyBv.js.gz +0 -0
  685. package/dist/web/assets/julia-DuME0IfC.js.br +0 -0
  686. package/dist/web/assets/julia-DuME0IfC.js.gz +0 -0
  687. package/dist/web/assets/just-Cw27pwNe.js.br +0 -0
  688. package/dist/web/assets/just-Cw27pwNe.js.gz +0 -0
  689. package/dist/web/assets/kanagawa-dragon-CkXjmgJE.js.br +0 -0
  690. package/dist/web/assets/kanagawa-dragon-CkXjmgJE.js.gz +0 -0
  691. package/dist/web/assets/kanagawa-lotus-CfQXZHmo.js.br +0 -0
  692. package/dist/web/assets/kanagawa-lotus-CfQXZHmo.js.gz +0 -0
  693. package/dist/web/assets/kanagawa-wave-DWedfzmr.js.br +0 -0
  694. package/dist/web/assets/kanagawa-wave-DWedfzmr.js.gz +0 -0
  695. package/dist/web/assets/katex-HP8lGamR.js.br +0 -0
  696. package/dist/web/assets/katex-HP8lGamR.js.gz +0 -0
  697. package/dist/web/assets/kdl-DV7GczEv.js.br +0 -0
  698. package/dist/web/assets/kdl-DV7GczEv.js.gz +0 -0
  699. package/dist/web/assets/kotlin-BdnUsdx6.js.br +0 -0
  700. package/dist/web/assets/kotlin-BdnUsdx6.js.gz +0 -0
  701. package/dist/web/assets/kusto-DZf3V79B.js.br +0 -0
  702. package/dist/web/assets/kusto-DZf3V79B.js.gz +0 -0
  703. package/dist/web/assets/laserwave-DUszq2jm.js.br +0 -0
  704. package/dist/web/assets/laserwave-DUszq2jm.js.gz +0 -0
  705. package/dist/web/assets/latex-CWtU0Tv5.js.br +0 -0
  706. package/dist/web/assets/latex-CWtU0Tv5.js.gz +0 -0
  707. package/dist/web/assets/layout-SsrduOYp.js.br +0 -0
  708. package/dist/web/assets/layout-SsrduOYp.js.gz +0 -0
  709. package/dist/web/assets/layoutHooks-BzE4xDdh.js +1 -0
  710. package/dist/web/assets/layoutHooks-BzE4xDdh.js.br +0 -0
  711. package/dist/web/assets/layoutHooks-BzE4xDdh.js.gz +0 -0
  712. package/dist/web/assets/lean-BZvkOJ9d.js.br +0 -0
  713. package/dist/web/assets/lean-BZvkOJ9d.js.gz +0 -0
  714. package/dist/web/assets/less-B1dDrJ26.js.br +0 -0
  715. package/dist/web/assets/less-B1dDrJ26.js.gz +0 -0
  716. package/dist/web/assets/light-plus-B7mTdjB0.js.br +0 -0
  717. package/dist/web/assets/light-plus-B7mTdjB0.js.gz +0 -0
  718. package/dist/web/assets/linear-8XOvhBtb.js +1 -0
  719. package/dist/web/assets/linear-8XOvhBtb.js.br +0 -0
  720. package/dist/web/assets/linear-8XOvhBtb.js.gz +0 -0
  721. package/dist/web/assets/liquid-DYVedYrR.js.br +0 -0
  722. package/dist/web/assets/liquid-DYVedYrR.js.gz +0 -0
  723. package/dist/web/assets/livescript-BwQOo05w.js.br +0 -0
  724. package/dist/web/assets/livescript-BwQOo05w.js.gz +0 -0
  725. package/dist/web/assets/llvm-DjAJT7YJ.js.br +0 -0
  726. package/dist/web/assets/llvm-DjAJT7YJ.js.gz +0 -0
  727. package/dist/web/assets/log-2UxHyX5q.js.br +0 -0
  728. package/dist/web/assets/log-2UxHyX5q.js.gz +0 -0
  729. package/dist/web/assets/logo-BtOb2qkB.js.br +0 -0
  730. package/dist/web/assets/logo-BtOb2qkB.js.gz +0 -0
  731. package/dist/web/assets/lua-BaeVxFsk.js.br +0 -0
  732. package/dist/web/assets/lua-BaeVxFsk.js.gz +0 -0
  733. package/dist/web/assets/lua-VAEuO923.js.br +0 -0
  734. package/dist/web/assets/lua-VAEuO923.js.gz +0 -0
  735. package/dist/web/assets/luau-C-HG3fhB.js.br +0 -0
  736. package/dist/web/assets/luau-C-HG3fhB.js.gz +0 -0
  737. package/dist/web/assets/make-CHLpvVh8.js.br +0 -0
  738. package/dist/web/assets/make-CHLpvVh8.js.gz +0 -0
  739. package/dist/web/assets/markdown-Cvjx9yec.js.br +0 -0
  740. package/dist/web/assets/markdown-Cvjx9yec.js.gz +0 -0
  741. package/dist/web/assets/marko-CnJfTvn9.js.br +0 -0
  742. package/dist/web/assets/marko-CnJfTvn9.js.gz +0 -0
  743. package/dist/web/assets/material-theme-D5KoaKCx.js.br +0 -0
  744. package/dist/web/assets/material-theme-D5KoaKCx.js.gz +0 -0
  745. package/dist/web/assets/material-theme-darker-BfHTSMKl.js.br +0 -0
  746. package/dist/web/assets/material-theme-darker-BfHTSMKl.js.gz +0 -0
  747. package/dist/web/assets/material-theme-lighter-B0m2ddpp.js.br +0 -0
  748. package/dist/web/assets/material-theme-lighter-B0m2ddpp.js.gz +0 -0
  749. package/dist/web/assets/material-theme-ocean-CyktbL80.js.br +0 -0
  750. package/dist/web/assets/material-theme-ocean-CyktbL80.js.gz +0 -0
  751. package/dist/web/assets/material-theme-palenight-Csfq5Kiy.js.br +0 -0
  752. package/dist/web/assets/material-theme-palenight-Csfq5Kiy.js.gz +0 -0
  753. package/dist/web/assets/mathematica-DTrFuWx2.js.br +0 -0
  754. package/dist/web/assets/mathematica-DTrFuWx2.js.gz +0 -0
  755. package/dist/web/assets/matlab-D7o27uSR.js.br +0 -0
  756. package/dist/web/assets/matlab-D7o27uSR.js.gz +0 -0
  757. package/dist/web/assets/mbox-CNhZ1qSd.js.br +0 -0
  758. package/dist/web/assets/mbox-CNhZ1qSd.js.gz +0 -0
  759. package/dist/web/assets/mdc-BMNejdWA.js.br +0 -0
  760. package/dist/web/assets/mdc-BMNejdWA.js.gz +0 -0
  761. package/dist/web/assets/mdx-Cmh6b_Ma.js.br +0 -0
  762. package/dist/web/assets/mdx-Cmh6b_Ma.js.gz +0 -0
  763. package/dist/web/assets/memoryAuthority-B8YSN2MI.js +1 -0
  764. package/dist/web/assets/memoryAuthority-B8YSN2MI.js.br +0 -0
  765. package/dist/web/assets/memoryAuthority-B8YSN2MI.js.gz +0 -0
  766. package/dist/web/assets/mermaid-GHXKKRXX-D3Z62_uv.css +1 -0
  767. package/dist/web/assets/mermaid-GHXKKRXX-D3Z62_uv.css.br +0 -0
  768. package/dist/web/assets/mermaid-GHXKKRXX-D3Z62_uv.css.gz +0 -0
  769. package/dist/web/assets/mermaid-GHXKKRXX-DmcDxWiS.js +190 -0
  770. package/dist/web/assets/mermaid-GHXKKRXX-DmcDxWiS.js.br +0 -0
  771. package/dist/web/assets/mermaid-GHXKKRXX-DmcDxWiS.js.gz +0 -0
  772. package/dist/web/assets/mermaid-engine-AE7SfXFQ.js +2547 -0
  773. package/dist/web/assets/mermaid-engine-AE7SfXFQ.js.br +0 -0
  774. package/dist/web/assets/mermaid-engine-AE7SfXFQ.js.gz +0 -0
  775. package/dist/web/assets/mermaid-mWjccvbQ.js.br +0 -0
  776. package/dist/web/assets/mermaid-mWjccvbQ.js.gz +0 -0
  777. package/dist/web/assets/min-dark-CafNBF8u.js.br +0 -0
  778. package/dist/web/assets/min-dark-CafNBF8u.js.gz +0 -0
  779. package/dist/web/assets/min-light-CTRr51gU.js.br +0 -0
  780. package/dist/web/assets/min-light-CTRr51gU.js.gz +0 -0
  781. package/dist/web/assets/mipsasm-CKIfxQSi.js.br +0 -0
  782. package/dist/web/assets/mipsasm-CKIfxQSi.js.gz +0 -0
  783. package/dist/web/assets/mirc-CjQqDB4T.js.br +0 -0
  784. package/dist/web/assets/mirc-CjQqDB4T.js.gz +0 -0
  785. package/dist/web/assets/mllike-CXdrOF99.js.br +0 -0
  786. package/dist/web/assets/mllike-CXdrOF99.js.gz +0 -0
  787. package/dist/web/assets/modelica-Dc1JOy9r.js.br +0 -0
  788. package/dist/web/assets/modelica-Dc1JOy9r.js.gz +0 -0
  789. package/dist/web/assets/mojo-rZm6bMo-.js.br +0 -0
  790. package/dist/web/assets/mojo-rZm6bMo-.js.gz +0 -0
  791. package/dist/web/assets/monokai-D4h5O-jR.js.br +0 -0
  792. package/dist/web/assets/monokai-D4h5O-jR.js.gz +0 -0
  793. package/dist/web/assets/moonbit-_H4v1dQx.js.br +0 -0
  794. package/dist/web/assets/moonbit-_H4v1dQx.js.gz +0 -0
  795. package/dist/web/assets/move-IF9eRakj.js.br +0 -0
  796. package/dist/web/assets/move-IF9eRakj.js.gz +0 -0
  797. package/dist/web/assets/mscgen-BA5vi2Kp.js.br +0 -0
  798. package/dist/web/assets/mscgen-BA5vi2Kp.js.gz +0 -0
  799. package/dist/web/assets/mumps-BT43cFF4.js.br +0 -0
  800. package/dist/web/assets/mumps-BT43cFF4.js.gz +0 -0
  801. package/dist/web/assets/narrat-DRg8JJMk.js.br +0 -0
  802. package/dist/web/assets/narrat-DRg8JJMk.js.gz +0 -0
  803. package/dist/web/assets/nextflow-Zz6hmt5N.js.br +0 -0
  804. package/dist/web/assets/nextflow-Zz6hmt5N.js.gz +0 -0
  805. package/dist/web/assets/nextflow-groovy-BeH2EWoN.js.br +0 -0
  806. package/dist/web/assets/nextflow-groovy-BeH2EWoN.js.gz +0 -0
  807. package/dist/web/assets/nginx-BpAMiNFr.js.br +0 -0
  808. package/dist/web/assets/nginx-BpAMiNFr.js.gz +0 -0
  809. package/dist/web/assets/nginx-DdIZxoE0.js.br +0 -0
  810. package/dist/web/assets/nginx-DdIZxoE0.js.gz +0 -0
  811. package/dist/web/assets/night-owl-C39BiMTA.js.br +0 -0
  812. package/dist/web/assets/night-owl-C39BiMTA.js.gz +0 -0
  813. package/dist/web/assets/night-owl-light-CMTm3GFP.js.br +0 -0
  814. package/dist/web/assets/night-owl-light-CMTm3GFP.js.gz +0 -0
  815. package/dist/web/assets/nim-CVrawwO9.js.br +0 -0
  816. package/dist/web/assets/nim-CVrawwO9.js.gz +0 -0
  817. package/dist/web/assets/nix-CwoSXNpI.js.br +0 -0
  818. package/dist/web/assets/nix-CwoSXNpI.js.gz +0 -0
  819. package/dist/web/assets/nord-Ddv68eIx.js.br +0 -0
  820. package/dist/web/assets/nord-Ddv68eIx.js.gz +0 -0
  821. package/dist/web/assets/nsis-LdVXkNf5.js.br +0 -0
  822. package/dist/web/assets/nsis-LdVXkNf5.js.gz +0 -0
  823. package/dist/web/assets/ntriples-BfvgReVJ.js.br +0 -0
  824. package/dist/web/assets/ntriples-BfvgReVJ.js.gz +0 -0
  825. package/dist/web/assets/nushell-Cz2AlsmD.js.br +0 -0
  826. package/dist/web/assets/nushell-Cz2AlsmD.js.gz +0 -0
  827. package/dist/web/assets/objective-c-DXmwc3jG.js.br +0 -0
  828. package/dist/web/assets/objective-c-DXmwc3jG.js.gz +0 -0
  829. package/dist/web/assets/objective-cpp-CLxacb5B.js.br +0 -0
  830. package/dist/web/assets/objective-cpp-CLxacb5B.js.gz +0 -0
  831. package/dist/web/assets/ocaml-C0hk2d4L.js.br +0 -0
  832. package/dist/web/assets/ocaml-C0hk2d4L.js.gz +0 -0
  833. package/dist/web/assets/octave-Ck1zUtKM.js.br +0 -0
  834. package/dist/web/assets/octave-Ck1zUtKM.js.gz +0 -0
  835. package/dist/web/assets/odin-BBf5iR-q.js.br +0 -0
  836. package/dist/web/assets/odin-BBf5iR-q.js.gz +0 -0
  837. package/dist/web/assets/one-dark-pro-DVMEJ2y_.js.br +0 -0
  838. package/dist/web/assets/one-dark-pro-DVMEJ2y_.js.gz +0 -0
  839. package/dist/web/assets/one-light-C3Wv6jpd.js.br +0 -0
  840. package/dist/web/assets/one-light-C3Wv6jpd.js.gz +0 -0
  841. package/dist/web/assets/openscad-C4EeE6gA.js.br +0 -0
  842. package/dist/web/assets/openscad-C4EeE6gA.js.gz +0 -0
  843. package/dist/web/assets/ordinal-Cboi1Yqb.js.br +0 -0
  844. package/dist/web/assets/ordinal-Cboi1Yqb.js.gz +0 -0
  845. package/dist/web/assets/oz-BzwKVEFT.js.br +0 -0
  846. package/dist/web/assets/oz-BzwKVEFT.js.gz +0 -0
  847. package/dist/web/assets/packs-Bee69jWU.js +1 -0
  848. package/dist/web/assets/packs-Bee69jWU.js.br +0 -0
  849. package/dist/web/assets/packs-Bee69jWU.js.gz +0 -0
  850. package/dist/web/assets/pascal--L3eBynH.js.br +0 -0
  851. package/dist/web/assets/pascal--L3eBynH.js.gz +0 -0
  852. package/dist/web/assets/pascal-D93ZcfNL.js.br +0 -0
  853. package/dist/web/assets/pascal-D93ZcfNL.js.gz +0 -0
  854. package/dist/web/assets/pdf-CIFzrehN.js +13 -0
  855. package/dist/web/assets/pdf-CIFzrehN.js.br +0 -0
  856. package/dist/web/assets/pdf-CIFzrehN.js.gz +0 -0
  857. package/dist/web/assets/perl-C0TMdlhV.js.br +0 -0
  858. package/dist/web/assets/perl-C0TMdlhV.js.gz +0 -0
  859. package/dist/web/assets/perl-CdXCOZ3F.js.br +0 -0
  860. package/dist/web/assets/perl-CdXCOZ3F.js.gz +0 -0
  861. package/dist/web/assets/php-Dhbhpdrm.js.br +0 -0
  862. package/dist/web/assets/php-Dhbhpdrm.js.gz +0 -0
  863. package/dist/web/assets/pie-DJOJsNN1.js +1 -0
  864. package/dist/web/assets/pie-DJOJsNN1.js.br +0 -0
  865. package/dist/web/assets/pie-DJOJsNN1.js.gz +0 -0
  866. package/dist/web/assets/pig-CevX1Tat.js.br +0 -0
  867. package/dist/web/assets/pig-CevX1Tat.js.gz +0 -0
  868. package/dist/web/assets/pkl-u5AG7uiY.js.br +0 -0
  869. package/dist/web/assets/pkl-u5AG7uiY.js.gz +0 -0
  870. package/dist/web/assets/plastic-3e1v2bzS.js.br +0 -0
  871. package/dist/web/assets/plastic-3e1v2bzS.js.gz +0 -0
  872. package/dist/web/assets/plsql-ChMvpjG-.js.br +0 -0
  873. package/dist/web/assets/plsql-ChMvpjG-.js.gz +0 -0
  874. package/dist/web/assets/po-BTJTHyun.js.br +0 -0
  875. package/dist/web/assets/po-BTJTHyun.js.gz +0 -0
  876. package/dist/web/assets/poimandres-CS3Unz2-.js.br +0 -0
  877. package/dist/web/assets/poimandres-CS3Unz2-.js.gz +0 -0
  878. package/dist/web/assets/polar-C0HS_06l.js.br +0 -0
  879. package/dist/web/assets/polar-C0HS_06l.js.gz +0 -0
  880. package/dist/web/assets/postcss-CXtECtnM.js.br +0 -0
  881. package/dist/web/assets/postcss-CXtECtnM.js.gz +0 -0
  882. package/dist/web/assets/powerquery-CEu0bR-o.js.br +0 -0
  883. package/dist/web/assets/powerquery-CEu0bR-o.js.gz +0 -0
  884. package/dist/web/assets/powershell-CFHJl5sT.js.br +0 -0
  885. package/dist/web/assets/powershell-CFHJl5sT.js.gz +0 -0
  886. package/dist/web/assets/powershell-Dpen1YoG.js.br +0 -0
  887. package/dist/web/assets/powershell-Dpen1YoG.js.gz +0 -0
  888. package/dist/web/assets/prisma-Dd19v3D-.js.br +0 -0
  889. package/dist/web/assets/prisma-Dd19v3D-.js.gz +0 -0
  890. package/dist/web/assets/prolog-CbFg5uaA.js.br +0 -0
  891. package/dist/web/assets/prolog-CbFg5uaA.js.gz +0 -0
  892. package/dist/web/assets/properties-C78fOPTZ.js.br +0 -0
  893. package/dist/web/assets/properties-C78fOPTZ.js.gz +0 -0
  894. package/dist/web/assets/proto-C7zT0LnQ.js.br +0 -0
  895. package/dist/web/assets/proto-C7zT0LnQ.js.gz +0 -0
  896. package/dist/web/assets/protobuf-ChK-085T.js.br +0 -0
  897. package/dist/web/assets/protobuf-ChK-085T.js.gz +0 -0
  898. package/dist/web/assets/pug-CGlum2m_.js.br +0 -0
  899. package/dist/web/assets/pug-CGlum2m_.js.gz +0 -0
  900. package/dist/web/assets/pug-DeIclll2.js.br +0 -0
  901. package/dist/web/assets/pug-DeIclll2.js.gz +0 -0
  902. package/dist/web/assets/puppet-BMWR74SV.js.br +0 -0
  903. package/dist/web/assets/puppet-BMWR74SV.js.gz +0 -0
  904. package/dist/web/assets/puppet-DMA9R1ak.js.br +0 -0
  905. package/dist/web/assets/puppet-DMA9R1ak.js.gz +0 -0
  906. package/dist/web/assets/purescript-CklMAg4u.js.br +0 -0
  907. package/dist/web/assets/purescript-CklMAg4u.js.gz +0 -0
  908. package/dist/web/assets/python-B6aJPvgy.js.br +0 -0
  909. package/dist/web/assets/python-B6aJPvgy.js.gz +0 -0
  910. package/dist/web/assets/python-BuPzkPfP.js.br +0 -0
  911. package/dist/web/assets/python-BuPzkPfP.js.gz +0 -0
  912. package/dist/web/assets/q-pXgVlZs6.js.br +0 -0
  913. package/dist/web/assets/q-pXgVlZs6.js.gz +0 -0
  914. package/dist/web/assets/qml-3beO22l8.js.br +0 -0
  915. package/dist/web/assets/qml-3beO22l8.js.gz +0 -0
  916. package/dist/web/assets/qmldir-C8lEn-DE.js.br +0 -0
  917. package/dist/web/assets/qmldir-C8lEn-DE.js.gz +0 -0
  918. package/dist/web/assets/qss-IeuSbFQv.js.br +0 -0
  919. package/dist/web/assets/qss-IeuSbFQv.js.gz +0 -0
  920. package/dist/web/assets/r-B6wPVr8A.js.br +0 -0
  921. package/dist/web/assets/r-B6wPVr8A.js.gz +0 -0
  922. package/dist/web/assets/r-Dspwwk_N.js.br +0 -0
  923. package/dist/web/assets/r-Dspwwk_N.js.gz +0 -0
  924. package/dist/web/assets/racket-BqYA7rlc.js.br +0 -0
  925. package/dist/web/assets/racket-BqYA7rlc.js.gz +0 -0
  926. package/dist/web/assets/raku-DXvB9xmW.js.br +0 -0
  927. package/dist/web/assets/raku-DXvB9xmW.js.gz +0 -0
  928. package/dist/web/assets/razor-Uh8Bk_45.js.br +0 -0
  929. package/dist/web/assets/razor-Uh8Bk_45.js.gz +0 -0
  930. package/dist/web/assets/red-bN70gL4F.js.br +0 -0
  931. package/dist/web/assets/red-bN70gL4F.js.gz +0 -0
  932. package/dist/web/assets/reg-C-SQnVFl.js.br +0 -0
  933. package/dist/web/assets/reg-C-SQnVFl.js.gz +0 -0
  934. package/dist/web/assets/regexp-CDVJQ6XC.js.br +0 -0
  935. package/dist/web/assets/regexp-CDVJQ6XC.js.gz +0 -0
  936. package/dist/web/assets/rel-C3B-1QV4.js.br +0 -0
  937. package/dist/web/assets/rel-C3B-1QV4.js.gz +0 -0
  938. package/dist/web/assets/riscv-BM1_JUlF.js.br +0 -0
  939. package/dist/web/assets/riscv-BM1_JUlF.js.gz +0 -0
  940. package/dist/web/assets/ron-D8l8udqQ.js.br +0 -0
  941. package/dist/web/assets/ron-D8l8udqQ.js.gz +0 -0
  942. package/dist/web/assets/rose-pine-dawn-DHQR4-dF.js.br +0 -0
  943. package/dist/web/assets/rose-pine-dawn-DHQR4-dF.js.gz +0 -0
  944. package/dist/web/assets/rose-pine-moon-D4_iv3hh.js.br +0 -0
  945. package/dist/web/assets/rose-pine-moon-D4_iv3hh.js.gz +0 -0
  946. package/dist/web/assets/rose-pine-qdsjHGoJ.js.br +0 -0
  947. package/dist/web/assets/rose-pine-qdsjHGoJ.js.gz +0 -0
  948. package/dist/web/assets/rosmsg-BJDFO7_C.js.br +0 -0
  949. package/dist/web/assets/rosmsg-BJDFO7_C.js.gz +0 -0
  950. package/dist/web/assets/rpm-CTu-6PCP.js.br +0 -0
  951. package/dist/web/assets/rpm-CTu-6PCP.js.gz +0 -0
  952. package/dist/web/assets/rst-BrH8l1NY.js.br +0 -0
  953. package/dist/web/assets/rst-BrH8l1NY.js.gz +0 -0
  954. package/dist/web/assets/ruby-B2Rjki9n.js.br +0 -0
  955. package/dist/web/assets/ruby-B2Rjki9n.js.gz +0 -0
  956. package/dist/web/assets/ruby-Dw2BHqvy.js.br +0 -0
  957. package/dist/web/assets/ruby-Dw2BHqvy.js.gz +0 -0
  958. package/dist/web/assets/rust-B1yitclQ.js.br +0 -0
  959. package/dist/web/assets/rust-B1yitclQ.js.gz +0 -0
  960. package/dist/web/assets/sankeyLinkHorizontal-FH_jDQz2.js +1 -0
  961. package/dist/web/assets/sankeyLinkHorizontal-FH_jDQz2.js.br +0 -0
  962. package/dist/web/assets/sankeyLinkHorizontal-FH_jDQz2.js.gz +0 -0
  963. package/dist/web/assets/sas-B4kiWyti.js.br +0 -0
  964. package/dist/web/assets/sas-B4kiWyti.js.gz +0 -0
  965. package/dist/web/assets/sas-cz2c8ADy.js.br +0 -0
  966. package/dist/web/assets/sas-cz2c8ADy.js.gz +0 -0
  967. package/dist/web/assets/sass-Cj5Yp3dK.js.br +0 -0
  968. package/dist/web/assets/sass-Cj5Yp3dK.js.gz +0 -0
  969. package/dist/web/assets/scala-C151Ov-r.js.br +0 -0
  970. package/dist/web/assets/scala-C151Ov-r.js.gz +0 -0
  971. package/dist/web/assets/scheme-C41bIUwD.js.br +0 -0
  972. package/dist/web/assets/scheme-C41bIUwD.js.gz +0 -0
  973. package/dist/web/assets/scheme-C98Dy4si.js.br +0 -0
  974. package/dist/web/assets/scheme-C98Dy4si.js.gz +0 -0
  975. package/dist/web/assets/scss-OYdSNvt2.js.br +0 -0
  976. package/dist/web/assets/scss-OYdSNvt2.js.gz +0 -0
  977. package/dist/web/assets/sdbl-DVxCFoDh.js.br +0 -0
  978. package/dist/web/assets/sdbl-DVxCFoDh.js.gz +0 -0
  979. package/dist/web/assets/shaderlab-Dg9Lc6iA.js.br +0 -0
  980. package/dist/web/assets/shaderlab-Dg9Lc6iA.js.gz +0 -0
  981. package/dist/web/assets/shell-CjFT_Tl9.js.br +0 -0
  982. package/dist/web/assets/shell-CjFT_Tl9.js.gz +0 -0
  983. package/dist/web/assets/shellscript-Yzrsuije.js.br +0 -0
  984. package/dist/web/assets/shellscript-Yzrsuije.js.gz +0 -0
  985. package/dist/web/assets/shellsession-BADoaaVG.js.br +0 -0
  986. package/dist/web/assets/shellsession-BADoaaVG.js.gz +0 -0
  987. package/dist/web/assets/sieve-C3Gn_uJK.js.br +0 -0
  988. package/dist/web/assets/sieve-C3Gn_uJK.js.gz +0 -0
  989. package/dist/web/assets/simple-mode-GW_nhZxv.js.br +0 -0
  990. package/dist/web/assets/simple-mode-GW_nhZxv.js.gz +0 -0
  991. package/dist/web/assets/slack-dark-BthQWCQV.js.br +0 -0
  992. package/dist/web/assets/slack-dark-BthQWCQV.js.gz +0 -0
  993. package/dist/web/assets/slack-ochin-DqwNpetd.js.br +0 -0
  994. package/dist/web/assets/slack-ochin-DqwNpetd.js.gz +0 -0
  995. package/dist/web/assets/smalltalk-BERRCDM3.js.br +0 -0
  996. package/dist/web/assets/smalltalk-BERRCDM3.js.gz +0 -0
  997. package/dist/web/assets/smalltalk-CnHTOXQT.js.br +0 -0
  998. package/dist/web/assets/smalltalk-CnHTOXQT.js.gz +0 -0
  999. package/dist/web/assets/snazzy-light-Bw305WKR.js.br +0 -0
  1000. package/dist/web/assets/snazzy-light-Bw305WKR.js.gz +0 -0
  1001. package/dist/web/assets/solarized-dark-DXbdFlpD.js.br +0 -0
  1002. package/dist/web/assets/solarized-dark-DXbdFlpD.js.gz +0 -0
  1003. package/dist/web/assets/solarized-light-L9t79GZl.js.br +0 -0
  1004. package/dist/web/assets/solarized-light-L9t79GZl.js.gz +0 -0
  1005. package/dist/web/assets/solidity-rGO070M0.js.br +0 -0
  1006. package/dist/web/assets/solidity-rGO070M0.js.gz +0 -0
  1007. package/dist/web/assets/solr-DehyRSwq.js.br +0 -0
  1008. package/dist/web/assets/solr-DehyRSwq.js.gz +0 -0
  1009. package/dist/web/assets/soy-Brmx7dQM.js.br +0 -0
  1010. package/dist/web/assets/soy-Brmx7dQM.js.gz +0 -0
  1011. package/dist/web/assets/spaces-wH3o95f_.js +1 -0
  1012. package/dist/web/assets/spaces-wH3o95f_.js.br +0 -0
  1013. package/dist/web/assets/spaces-wH3o95f_.js.gz +0 -0
  1014. package/dist/web/assets/sparql-DkYu6x3z.js.br +0 -0
  1015. package/dist/web/assets/sparql-DkYu6x3z.js.gz +0 -0
  1016. package/dist/web/assets/sparql-rVzFXLq3.js.br +0 -0
  1017. package/dist/web/assets/sparql-rVzFXLq3.js.gz +0 -0
  1018. package/dist/web/assets/splunk-BtCnVYZw.js.br +0 -0
  1019. package/dist/web/assets/splunk-BtCnVYZw.js.gz +0 -0
  1020. package/dist/web/assets/spreadsheet-BCZA_wO0.js.br +0 -0
  1021. package/dist/web/assets/spreadsheet-BCZA_wO0.js.gz +0 -0
  1022. package/dist/web/assets/sql-BLtJtn59.js.br +0 -0
  1023. package/dist/web/assets/sql-BLtJtn59.js.gz +0 -0
  1024. package/dist/web/assets/sql-D0XecflT.js.br +0 -0
  1025. package/dist/web/assets/sql-D0XecflT.js.gz +0 -0
  1026. package/dist/web/assets/ssh-config-_ykCGR6B.js.br +0 -0
  1027. package/dist/web/assets/ssh-config-_ykCGR6B.js.gz +0 -0
  1028. package/dist/web/assets/stata-BH5u7GGu.js.br +0 -0
  1029. package/dist/web/assets/stata-BH5u7GGu.js.gz +0 -0
  1030. package/dist/web/assets/stex-C3f8Ysf7.js.br +0 -0
  1031. package/dist/web/assets/stex-C3f8Ysf7.js.gz +0 -0
  1032. package/dist/web/assets/stylus-B533Al4x.js.br +0 -0
  1033. package/dist/web/assets/stylus-B533Al4x.js.gz +0 -0
  1034. package/dist/web/assets/stylus-BEDo0Tqx.js.br +0 -0
  1035. package/dist/web/assets/stylus-BEDo0Tqx.js.gz +0 -0
  1036. package/dist/web/assets/surrealql-Bq5Q-fJD.js.br +0 -0
  1037. package/dist/web/assets/surrealql-Bq5Q-fJD.js.gz +0 -0
  1038. package/dist/web/assets/svelte-C_ipcX3V.js.br +0 -0
  1039. package/dist/web/assets/svelte-C_ipcX3V.js.gz +0 -0
  1040. package/dist/web/assets/swift-BzpIVaGY.js.br +0 -0
  1041. package/dist/web/assets/swift-BzpIVaGY.js.gz +0 -0
  1042. package/dist/web/assets/swift-D82vCrfD.js.br +0 -0
  1043. package/dist/web/assets/swift-D82vCrfD.js.gz +0 -0
  1044. package/dist/web/assets/synthwave-84-CbfX1IO0.js.br +0 -0
  1045. package/dist/web/assets/synthwave-84-CbfX1IO0.js.gz +0 -0
  1046. package/dist/web/assets/system-verilog-CnnmHF94.js.br +0 -0
  1047. package/dist/web/assets/system-verilog-CnnmHF94.js.gz +0 -0
  1048. package/dist/web/assets/systemd-4A_iFExJ.js.br +0 -0
  1049. package/dist/web/assets/systemd-4A_iFExJ.js.gz +0 -0
  1050. package/dist/web/assets/talonscript-CkByrt1z.js.br +0 -0
  1051. package/dist/web/assets/talonscript-CkByrt1z.js.gz +0 -0
  1052. package/dist/web/assets/tasl-QIJgUcNo.js.br +0 -0
  1053. package/dist/web/assets/tasl-QIJgUcNo.js.gz +0 -0
  1054. package/dist/web/assets/tcl-DVfN8rqt.js.br +0 -0
  1055. package/dist/web/assets/tcl-DVfN8rqt.js.gz +0 -0
  1056. package/dist/web/assets/tcl-dwOrl1Do.js.br +0 -0
  1057. package/dist/web/assets/tcl-dwOrl1Do.js.gz +0 -0
  1058. package/dist/web/assets/templ-P3uqSqPl.js.br +0 -0
  1059. package/dist/web/assets/templ-P3uqSqPl.js.gz +0 -0
  1060. package/dist/web/assets/terraform-BETggiCN.js.br +0 -0
  1061. package/dist/web/assets/terraform-BETggiCN.js.gz +0 -0
  1062. package/dist/web/assets/tex-idrVyKtj.js.br +0 -0
  1063. package/dist/web/assets/tex-idrVyKtj.js.gz +0 -0
  1064. package/dist/web/assets/textile-CnDTJFAw.js.br +0 -0
  1065. package/dist/web/assets/textile-CnDTJFAw.js.gz +0 -0
  1066. package/dist/web/assets/theme-DVIt3W-5.js +1 -0
  1067. package/dist/web/assets/theme-DVIt3W-5.js.br +0 -0
  1068. package/dist/web/assets/theme-DVIt3W-5.js.gz +0 -0
  1069. package/dist/web/assets/tiddlywiki-DO-Gjzrf.js.br +0 -0
  1070. package/dist/web/assets/tiddlywiki-DO-Gjzrf.js.gz +0 -0
  1071. package/dist/web/assets/tiki-DGYXhP31.js.br +0 -0
  1072. package/dist/web/assets/tiki-DGYXhP31.js.gz +0 -0
  1073. package/dist/web/assets/tokyo-night-hegEt444.js.br +0 -0
  1074. package/dist/web/assets/tokyo-night-hegEt444.js.gz +0 -0
  1075. package/dist/web/assets/toml-Bm5Em-hy.js.br +0 -0
  1076. package/dist/web/assets/toml-Bm5Em-hy.js.gz +0 -0
  1077. package/dist/web/assets/toml-vGWfd6FD.js.br +0 -0
  1078. package/dist/web/assets/toml-vGWfd6FD.js.gz +0 -0
  1079. package/dist/web/assets/troff-wAsdV37c.js.br +0 -0
  1080. package/dist/web/assets/troff-wAsdV37c.js.gz +0 -0
  1081. package/dist/web/assets/ts-tags-zn1MmPIZ.js.br +0 -0
  1082. package/dist/web/assets/ts-tags-zn1MmPIZ.js.gz +0 -0
  1083. package/dist/web/assets/tsv-B_m7g4N7.js.br +0 -0
  1084. package/dist/web/assets/tsv-B_m7g4N7.js.gz +0 -0
  1085. package/dist/web/assets/tsx-COt5Ahok.js.br +0 -0
  1086. package/dist/web/assets/tsx-COt5Ahok.js.gz +0 -0
  1087. package/dist/web/assets/ttcn-CfJYG6tj.js.br +0 -0
  1088. package/dist/web/assets/ttcn-CfJYG6tj.js.gz +0 -0
  1089. package/dist/web/assets/ttcn-cfg-B9xdYoR4.js.br +0 -0
  1090. package/dist/web/assets/ttcn-cfg-B9xdYoR4.js.gz +0 -0
  1091. package/dist/web/assets/turtle-B1tBg_DP.js.br +0 -0
  1092. package/dist/web/assets/turtle-B1tBg_DP.js.gz +0 -0
  1093. package/dist/web/assets/turtle-BsS91CYL.js.br +0 -0
  1094. package/dist/web/assets/turtle-BsS91CYL.js.gz +0 -0
  1095. package/dist/web/assets/twig-DNn4PbVi.js.br +0 -0
  1096. package/dist/web/assets/twig-DNn4PbVi.js.gz +0 -0
  1097. package/dist/web/assets/typescript-BPQ3VLAy.js.br +0 -0
  1098. package/dist/web/assets/typescript-BPQ3VLAy.js.gz +0 -0
  1099. package/dist/web/assets/typespec-BGHnOYBU.js.br +0 -0
  1100. package/dist/web/assets/typespec-BGHnOYBU.js.gz +0 -0
  1101. package/dist/web/assets/typst-DHCkPAjA.js.br +0 -0
  1102. package/dist/web/assets/typst-DHCkPAjA.js.gz +0 -0
  1103. package/dist/web/assets/uiZoom-CfR9h3Dy.js +1 -0
  1104. package/dist/web/assets/uiZoom-CfR9h3Dy.js.br +0 -0
  1105. package/dist/web/assets/uiZoom-CfR9h3Dy.js.gz +0 -0
  1106. package/dist/web/assets/v-BcVCzyr7.js.br +0 -0
  1107. package/dist/web/assets/v-BcVCzyr7.js.gz +0 -0
  1108. package/dist/web/assets/v4-Dnyct6Ft.js +1 -0
  1109. package/dist/web/assets/v4-Dnyct6Ft.js.br +0 -0
  1110. package/dist/web/assets/v4-Dnyct6Ft.js.gz +0 -0
  1111. package/dist/web/assets/vala-CsfeWuGM.js.br +0 -0
  1112. package/dist/web/assets/vala-CsfeWuGM.js.gz +0 -0
  1113. package/dist/web/assets/vb-CmGdzxic.js.br +0 -0
  1114. package/dist/web/assets/vb-CmGdzxic.js.gz +0 -0
  1115. package/dist/web/assets/vb-D17OF-Vu.js.br +0 -0
  1116. package/dist/web/assets/vb-D17OF-Vu.js.gz +0 -0
  1117. package/dist/web/assets/vbscript-BuJXcnF6.js.br +0 -0
  1118. package/dist/web/assets/vbscript-BuJXcnF6.js.gz +0 -0
  1119. package/dist/web/assets/velocity-D8B20fx6.js.br +0 -0
  1120. package/dist/web/assets/velocity-D8B20fx6.js.gz +0 -0
  1121. package/dist/web/assets/vendor-react-BqVzR-It.js +61 -0
  1122. package/dist/web/assets/vendor-react-BqVzR-It.js.br +0 -0
  1123. package/dist/web/assets/vendor-react-BqVzR-It.js.gz +0 -0
  1124. package/dist/web/assets/venn.esm-D6tdiC58.js +7 -0
  1125. package/dist/web/assets/venn.esm-D6tdiC58.js.br +0 -0
  1126. package/dist/web/assets/venn.esm-D6tdiC58.js.gz +0 -0
  1127. package/dist/web/assets/verilog-BQ8w6xss.js.br +0 -0
  1128. package/dist/web/assets/verilog-BQ8w6xss.js.gz +0 -0
  1129. package/dist/web/assets/verilog-C6RDOZhf.js.br +0 -0
  1130. package/dist/web/assets/verilog-C6RDOZhf.js.gz +0 -0
  1131. package/dist/web/assets/vesper-DU1UobuO.js.br +0 -0
  1132. package/dist/web/assets/vesper-DU1UobuO.js.gz +0 -0
  1133. package/dist/web/assets/vhdl-CeAyd5Ju.js.br +0 -0
  1134. package/dist/web/assets/vhdl-CeAyd5Ju.js.gz +0 -0
  1135. package/dist/web/assets/vhdl-lSbBsy5d.js.br +0 -0
  1136. package/dist/web/assets/vhdl-lSbBsy5d.js.gz +0 -0
  1137. package/dist/web/assets/viml-CJc9bBzg.js.br +0 -0
  1138. package/dist/web/assets/viml-CJc9bBzg.js.gz +0 -0
  1139. package/dist/web/assets/vitesse-black-Bkuqu6BP.js.br +0 -0
  1140. package/dist/web/assets/vitesse-black-Bkuqu6BP.js.gz +0 -0
  1141. package/dist/web/assets/vitesse-dark-D0r3Knsf.js.br +0 -0
  1142. package/dist/web/assets/vitesse-dark-D0r3Knsf.js.gz +0 -0
  1143. package/dist/web/assets/vitesse-light-CVO1_9PV.js.br +0 -0
  1144. package/dist/web/assets/vitesse-light-CVO1_9PV.js.gz +0 -0
  1145. package/dist/web/assets/vue-DN_0RTcg.js.br +0 -0
  1146. package/dist/web/assets/vue-DN_0RTcg.js.gz +0 -0
  1147. package/dist/web/assets/vue-html-AaS7Mt5G.js.br +0 -0
  1148. package/dist/web/assets/vue-html-AaS7Mt5G.js.gz +0 -0
  1149. package/dist/web/assets/vue-vine-CQOfvN7w.js.br +0 -0
  1150. package/dist/web/assets/vue-vine-CQOfvN7w.js.gz +0 -0
  1151. package/dist/web/assets/vyper-CDx5xZoG.js.br +0 -0
  1152. package/dist/web/assets/vyper-CDx5xZoG.js.gz +0 -0
  1153. package/dist/web/assets/{wardley-L42UT6IY-Bp3q2izt.js → wardley-L42UT6IY-CptWIPkK.js} +1 -1
  1154. package/dist/web/assets/wardley-L42UT6IY-CptWIPkK.js.br +0 -0
  1155. package/dist/web/assets/wardley-L42UT6IY-CptWIPkK.js.gz +0 -0
  1156. package/dist/web/assets/wasm-CG6Dc4jp.js.br +0 -0
  1157. package/dist/web/assets/wasm-CG6Dc4jp.js.gz +0 -0
  1158. package/dist/web/assets/wasm-MzD3tlZU.js.br +0 -0
  1159. package/dist/web/assets/wasm-MzD3tlZU.js.gz +0 -0
  1160. package/dist/web/assets/webidl-ZXfAyPTL.js.br +0 -0
  1161. package/dist/web/assets/webidl-ZXfAyPTL.js.gz +0 -0
  1162. package/dist/web/assets/wenyan-BV7otONQ.js.br +0 -0
  1163. package/dist/web/assets/wenyan-BV7otONQ.js.gz +0 -0
  1164. package/dist/web/assets/wgsl-Dx-B1_4e.js.br +0 -0
  1165. package/dist/web/assets/wgsl-Dx-B1_4e.js.gz +0 -0
  1166. package/dist/web/assets/wikitext-BhOHFoWU.js.br +0 -0
  1167. package/dist/web/assets/wikitext-BhOHFoWU.js.gz +0 -0
  1168. package/dist/web/assets/wit-5i3qLPDT.js.br +0 -0
  1169. package/dist/web/assets/wit-5i3qLPDT.js.gz +0 -0
  1170. package/dist/web/assets/wolfram-lXgVvXCa.js.br +0 -0
  1171. package/dist/web/assets/wolfram-lXgVvXCa.js.gz +0 -0
  1172. package/dist/web/assets/xml-sdJ4AIDG.js.br +0 -0
  1173. package/dist/web/assets/xml-sdJ4AIDG.js.gz +0 -0
  1174. package/dist/web/assets/xquery-DzFWVndE.js.br +0 -0
  1175. package/dist/web/assets/xquery-DzFWVndE.js.gz +0 -0
  1176. package/dist/web/assets/xsl-CtQFsRM5.js.br +0 -0
  1177. package/dist/web/assets/xsl-CtQFsRM5.js.gz +0 -0
  1178. package/dist/web/assets/yacas-BJ4BC0dw.js.br +0 -0
  1179. package/dist/web/assets/yacas-BJ4BC0dw.js.gz +0 -0
  1180. package/dist/web/assets/yaml-Buea-lGh.js.br +0 -0
  1181. package/dist/web/assets/yaml-Buea-lGh.js.gz +0 -0
  1182. package/dist/web/assets/z80-Hz9HOZM7.js.br +0 -0
  1183. package/dist/web/assets/z80-Hz9HOZM7.js.gz +0 -0
  1184. package/dist/web/assets/zenscript-DVFEvuxE.js.br +0 -0
  1185. package/dist/web/assets/zenscript-DVFEvuxE.js.gz +0 -0
  1186. package/dist/web/assets/zig-VOosw3JB.js.br +0 -0
  1187. package/dist/web/assets/zig-VOosw3JB.js.gz +0 -0
  1188. package/dist/web/index.html +12 -17
  1189. package/dist/web/index.html.br +0 -0
  1190. package/dist/web/index.html.gz +0 -0
  1191. package/dist/web/pdfjs/pdf.worker.min.mjs +1 -1
  1192. package/dist/web/pdfjs/pdf.worker.min.mjs.br +0 -0
  1193. package/dist/web/pdfjs/pdf.worker.min.mjs.gz +0 -0
  1194. package/dist/web/theme-boot.js +20 -0
  1195. package/dist/web/theme-boot.js.br +0 -0
  1196. package/dist/web/theme-boot.js.gz +0 -0
  1197. package/native/auth-native/index.cjs +6 -0
  1198. package/native/auth-native/index.d.ts +14 -0
  1199. package/native/auth-native/package.json +1 -2
  1200. package/native/auth-native/prebuilds/darwin-arm64/auth-native.node +0 -0
  1201. package/native/auth-native/prebuilds/darwin-x64/auth-native.node +0 -0
  1202. package/native/auth-native/prebuilds/linux-arm64/auth-native.node +0 -0
  1203. package/native/auth-native/prebuilds/linux-x64/auth-native.node +0 -0
  1204. package/native/auth-native/prebuilds/win32-arm64/auth-native.node +0 -0
  1205. package/native/auth-native/prebuilds/win32-x64/auth-native.node +0 -0
  1206. package/package.json +1 -1
  1207. package/dist/web/assets/AppErrorBoundary-B5Fc4f6-.js +0 -1
  1208. package/dist/web/assets/NavScopeBoundary-C7MnGQio.js +0 -1
  1209. package/dist/web/assets/arc-DGB9OVgQ.js +0 -1
  1210. package/dist/web/assets/architectureDiagram-3BPJPVTR-glnQCMub.js +0 -36
  1211. package/dist/web/assets/blockDiagram-GPEHLZMM-bM0tnGby.js +0 -132
  1212. package/dist/web/assets/c4Diagram-AAUBKEIU-DMf_rTtt.js +0 -10
  1213. package/dist/web/assets/channel-Cj8SKJ38.js +0 -1
  1214. package/dist/web/assets/chunk-2J33WTMH-mTccJ3tW.js +0 -1
  1215. package/dist/web/assets/chunk-4BX2VUAB-DhqPYMjY.js +0 -1
  1216. package/dist/web/assets/chunk-55IACEB6-BujrYRoO.js +0 -1
  1217. package/dist/web/assets/chunk-727SXJPM-ciMmSI4G.js +0 -206
  1218. package/dist/web/assets/chunk-AQP2D5EJ-CZW9pKTc.js +0 -231
  1219. package/dist/web/assets/chunk-FMBD7UC4-hdALNnnU.js +0 -15
  1220. package/dist/web/assets/chunk-ND2GUHAM-CgKyqUdb.js +0 -1
  1221. package/dist/web/assets/chunk-QZHKN3VN-B2mmUz_E.js +0 -1
  1222. package/dist/web/assets/classDiagram-4FO5ZUOK-f8V9p-dD.js +0 -1
  1223. package/dist/web/assets/classDiagram-v2-Q7XG4LA2-f8V9p-dD.js +0 -1
  1224. package/dist/web/assets/client-ClWQBErG.js +0 -3
  1225. package/dist/web/assets/connection-C0J3BPgk.js +0 -1
  1226. package/dist/web/assets/cose-bilkent-S5V4N54A-UV3uPjkK.js +0 -1
  1227. package/dist/web/assets/dagre-BM42HDAG-Zjy-gQ6C.js +0 -4
  1228. package/dist/web/assets/diagram-2AECGRRQ-DL-kilIf.js +0 -43
  1229. package/dist/web/assets/diagram-5GNKFQAL-CjB_xR5B.js +0 -10
  1230. package/dist/web/assets/diagram-KO2AKTUF-CjN4i3b9.js +0 -3
  1231. package/dist/web/assets/diagram-LMA3HP47-CPCAMndo.js +0 -24
  1232. package/dist/web/assets/diagram-OG6HWLK6-DVeBWBKd.js +0 -24
  1233. package/dist/web/assets/erDiagram-TEJ5UH35-CHKzBHrr.js +0 -85
  1234. package/dist/web/assets/export-CXoWon32.js +0 -2
  1235. package/dist/web/assets/flowDiagram-I6XJVG4X-C5rQa2pq.js +0 -162
  1236. package/dist/web/assets/ganttDiagram-6RSMTGT7-BrLjEsNJ.js +0 -292
  1237. package/dist/web/assets/gitGraphDiagram-PVQCEYII-3DRR5VZj.js +0 -106
  1238. package/dist/web/assets/highlighted-body-OFNGDK62-Bdj5SJfv.js +0 -1
  1239. package/dist/web/assets/index-2Vx5mHRn.js +0 -1
  1240. package/dist/web/assets/index-B1UXw2C9.js +0 -1
  1241. package/dist/web/assets/index-BJxtlf4P.js +0 -309
  1242. package/dist/web/assets/index-BY7jPurv.js +0 -1
  1243. package/dist/web/assets/index-Bq79v-Sa.js +0 -1
  1244. package/dist/web/assets/index-BqD3iTIl.js +0 -1
  1245. package/dist/web/assets/index-C62wjCF_.js +0 -1
  1246. package/dist/web/assets/index-CG9e6lgq.js +0 -1
  1247. package/dist/web/assets/index-CS4xJLZV.js +0 -1
  1248. package/dist/web/assets/index-CprdjRRk.js +0 -13
  1249. package/dist/web/assets/index-CypTtrCB.js +0 -1
  1250. package/dist/web/assets/index-DDJQGcUL.js +0 -1
  1251. package/dist/web/assets/index-DLWzxUOO.js +0 -1
  1252. package/dist/web/assets/index-DQxkxZmn.js +0 -7
  1253. package/dist/web/assets/index-De_LkTZx.js +0 -1
  1254. package/dist/web/assets/index-DpcWEDhW.js +0 -1
  1255. package/dist/web/assets/index-Dqq1RDP4.js +0 -1
  1256. package/dist/web/assets/index-H1uMvIoa.css +0 -1
  1257. package/dist/web/assets/index-ICHWJ2SM.js +0 -1
  1258. package/dist/web/assets/index-O5fSd569.js +0 -229
  1259. package/dist/web/assets/index-odjtqLLS.js +0 -1
  1260. package/dist/web/assets/index-v_yAQ0Am.js +0 -1
  1261. package/dist/web/assets/infoDiagram-5YYISTIA-CCwV4Z0v.js +0 -2
  1262. package/dist/web/assets/ishikawaDiagram-YF4QCWOH-BwwZcGyZ.js +0 -70
  1263. package/dist/web/assets/journeyDiagram-JHISSGLW-Dc6WqniQ.js +0 -139
  1264. package/dist/web/assets/kanban-definition-UN3LZRKU-DVUqULOS.js +0 -89
  1265. package/dist/web/assets/linear-d6rWsNOU.js +0 -1
  1266. package/dist/web/assets/memoryAdvisor-DBQXJB1o.js +0 -1
  1267. package/dist/web/assets/mermaid-GHXKKRXX-Ik6SkVDT.js +0 -642
  1268. package/dist/web/assets/mindmap-definition-RKZ34NQL-_JHAkhHL.js +0 -96
  1269. package/dist/web/assets/navViewState-DaCMIYWA.js +0 -1
  1270. package/dist/web/assets/pdf-C-olXVQ4.js +0 -12
  1271. package/dist/web/assets/pieDiagram-4H26LBE5-BlhlygGy.js +0 -30
  1272. package/dist/web/assets/quadrantDiagram-W4KKPZXB-jn6R_C0S.js +0 -7
  1273. package/dist/web/assets/requirementDiagram-4Y6WPE33-B9fXCHBr.js +0 -84
  1274. package/dist/web/assets/sankeyDiagram-5OEKKPKP-fPJwIxkl.js +0 -40
  1275. package/dist/web/assets/sequenceDiagram-3UESZ5HK-1v1DTNGt.js +0 -162
  1276. package/dist/web/assets/spaces-CvL2DRZM.js +0 -1
  1277. package/dist/web/assets/stateDiagram-AJRCARHV-CEc_PLov.js +0 -1
  1278. package/dist/web/assets/stateDiagram-v2-BHNVJYJU-iAMctzaT.js +0 -1
  1279. package/dist/web/assets/theme-LRSmy8mD.js +0 -1
  1280. package/dist/web/assets/timeline-definition-PNZ67QCA-CEjhuitj.js +0 -120
  1281. package/dist/web/assets/vennDiagram-CIIHVFJN-CActt9h9.js +0 -34
  1282. package/dist/web/assets/wardleyDiagram-YWT4CUSO-C_zutiQ2.js +0 -78
  1283. package/dist/web/assets/xychartDiagram-2RQKCTM6-CRafvv33.js +0 -7
@@ -0,0 +1,404 @@
1
+ import{r as E,j as A}from"./vendor-react-BqVzR-It.js";import{fm as ot,fn as Wc,fo as Dt,fp as mn,a5 as hs,fq as pi,fr as Uc,fs as Vc,ft as Kc,fu as Gc,fv as Qc,fw as Jc,fx as vt,fy as Xo,fz as gr,fA as Lt,fB as Zo,fC as Yc,fD as vr,fE as Xc,fF as yr,fG as kr,fH as Zc,fI as Ir,fJ as wr,fK as el,fL as zn,fM as tl,fN as mi,fO as ea,fP as ta,cX as hn,ac as nl,fQ as Pt,fR as sl,fS as il,fT as na,k as sa,E as Vi,t as ia,u as Kn,fU as ra,fV as rl,S as oe,fW as ol,fX as gi,fY as oa,b as al,fZ as dl,s as cl,f_ as ll,f$ as ul,g0 as fl,g1 as hl,g2 as ln,g3 as pl,g4 as ml,g5 as gl,g6 as vl,g7 as Zn,g8 as Bs,f as Ls,g9 as yl,ga as kl,gb as Il,gc as wl,e as un,gd as bl,ge as Sl,gf as xl,gg as br,gh as _l}from"./index-BLi2nTxe.js";import{u as on}from"./index-C9DdZFNJ.js";import{t as Ki,f as M,g as Gi,s as aa,D as Tl,G as be,h as Cl,j as rt,a as Ce,A as Ee,R as mt,k as Sr,H as Rl,e as vi,K as pn,i as Al,w as Ml}from"./client-cAizUM-b.js";function Ae(t,e){return ps(t,e,!1)}function Pl(t,e){return ps(t,e,!0)}function ps(t,e,n){if(Object.is(t,e))return!0;if(typeof t!=typeof e||t===null||e===null||typeof t!="object")return!1;if(Array.isArray(t)||Array.isArray(e)){if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let a=0;a<t.length;a+=1)if(!ps(t[a],e[a],n))return!1;return!0}const s=t,i=e,r=n?Object.keys(s).filter(a=>s[a]!==void 0):Object.keys(s),o=n?Object.keys(i).filter(a=>i[a]!==void 0):Object.keys(i);if(r.length!==o.length)return!1;for(const a of r)if(!Object.hasOwn(i,a)||!ps(s[a],i[a],n))return!1;return!0}function El(t){const e=t.findIndex(n=>n.kind!=="text"||n.role!=="user");return e<0?t.length:e}const yi=new Set,Ol=2048,jn=new WeakMap,Dl={items:[],tasks:new Map,interactions:new Map,attachments:new Map,todos:new Map,prompts:new Map,toolCallCount:0,meta:{},pendingInteractions:new Set,hasMoreOlder:!1};function ql(t,e){let n;switch(e.op){case"reset":n=$l(t,e);break;case"turn.upsert":n=Wl(t,e.turn);break;case"step.upsert":n=Ul(t,e.turnId,e.step);break;case"frame.upsert":n=Kl(t,e);break;case"frame.remove":n=Gl(t,e);break;case"tool.count.set":n=jl(t,e.count);break;case"append":n=Jl(t,e);break;case"marker.upsert":n=_r(t,e.item,e.item.markerId,e.beforeTurn);break;case"taskref.upsert":n=_r(t,e.item,e.item.refId,e.beforeTurn);break;case"task.upsert":n=eu(t,e.task);break;case"interaction.upsert":n=tu(t,e.interaction);break;case"attachment.upsert":n=su(t,e.attachment);break;case"todo.upsert":n=ru(t,e.todo);break;case"prompt.upsert":n=au(t,e.prompt);break;case"meta.merge":n=lu(t,e.meta);break;case"items.remove":n=Zl(t,e.ids);break}return n=Fl(e,n),Nl(t,n.state,e),n}function Fl(t,e){return e.toolCallCountDelta!==void 0||t.op==="reset"||t.op==="tool.count.set"||t.op==="items.remove"?e:{...e,toolCallCountDelta:0}}function Nl(t,e,n){if(n.op==="reset"&&(n.coverage??da(n.snapshot.hasMoreOlder??!1)).kind==="full"){jn.set(e,yi);return}if(e===t)return;const s=jn.get(t);if(n.op==="items.remove"){const i=new Set(s??yi);for(const r of n.ids)if(i.add(r),i.size>Ol){const o=i.values().next().value;o!==void 0&&i.delete(o)}jn.set(e,i);return}s!==void 0&&jn.set(e,s)}function $l(t,e){const n=e.coverage??da(e.snapshot.hasMoreOlder??!1),s=e.read?.source==="live"&&e.read.stale===void 0&&e.read.watermark?.transcript?.epoch!==void 0,i=Hl(t.items,e.snapshot.items,n,s,e.grade),r=n.kind==="unknown",o=Mn(t.tasks,e.snapshot.tasks,k=>k.taskId,r,s),a=Mn(t.interactions,e.snapshot.interactions,k=>k.interactionId,r,s),d=Mn(t.attachments,e.snapshot.attachments,k=>k.attachmentId,r,s),l=Mn(t.todos,e.snapshot.todos,k=>k.todoId,r,s),c=Mn(t.prompts,e.snapshot.prompts,k=>k.promptId,r,s),u=r?s?{...t.meta,...e.snapshot.meta}:{...e.snapshot.meta,...t.meta}:e.snapshot.meta,f=Ae(t.meta,u)?t.meta:u,g=Ll(t,e.snapshot.toolCallCount,e.snapshot.toolCallCountKnown,e.grade,i,n),h=new Set;for(const k of a.values())k.state==="pending"&&h.add(k.interactionId);const v=n.hasMoreOlder,m={items:i,tasks:o,interactions:a,attachments:d,todos:l,prompts:c,toolCallCount:g,meta:f,pendingInteractions:h,hasMoreOlder:v};return i!==t.items||o!==t.tasks||a!==t.interactions||d!==t.attachments||l!==t.todos||c!==t.prompts||g!==t.toolCallCount||f!==t.meta||v!==t.hasMoreOlder?{state:m,changed:!0,toolCallCountDelta:void 0}:{state:t,changed:!1,toolCallCountDelta:0}}function jl(t,e){return t.toolCallCount===e?{state:t,changed:!1,toolCallCountDelta:void 0}:{state:{...t,toolCallCount:e},changed:!0,toolCallCountDelta:void 0}}function da(t){return t?{kind:"tail",hasMoreOlder:!0}:{kind:"full",hasMoreOlder:!1}}function ca(t){let e=0;for(const n of t)if(n.kind==="turn")for(const s of n.steps)for(const i of s.frames)i.kind==="tool"&&(e+=1);return e}function Bl(t){return t.hasMoreOlder||t.items.some(e=>e.kind==="turn")}function Ll(t,e,n,s,i,r){if(n===!1||s==="turn"&&n!==!0&&e===void 0)return;const o=ca(i);if(r.kind==="full")return e??o;if(e!==void 0)return Math.max(e,o);if(!(t.toolCallCount===void 0||!Bl(t)))return Math.max(t.toolCallCount,o)}function ms(t,e){return t===void 0?void 0:Math.max(0,t+e)}function Hl(t,e,n,s,i){const r=new Map(t.map(c=>[nn(c),c])),o=e.map(c=>{const u=r.get(nn(c));let f=c;if(c.kind==="turn"&&u?.kind==="turn"){const g=Dt(u,s&&n.kind==="unknown"&&i==="turn"?{...c,steps:u.steps,stepsPartial:u.stepsPartial}:c);f=ot(g,{...g,steps:g.steps.map(h=>{const v=u.steps.find(m=>m.stepId===h.stepId);return v===void 0?h:{...h,frames:h.frames.map(m=>{const p=v.frames.find(k=>k.frameId===m.frameId);return p===void 0?m:Dt(p,m)})}})})}return u!==void 0&&Ae(u,f)?u:f});if(n.kind==="full")return Ae(t,o)?t:o;if(n.kind==="unknown"){const c=[...t];for(const u of o){const f=c.findIndex(g=>nn(g)===nn(u));if(f!==-1){s&&(c[f]=u);continue}if(u.kind==="turn"){const g=c.findIndex(h=>h.kind==="turn"&&h.ordinal>u.ordinal);c.splice(g===-1?c.length:g,0,u)}else c.push(u)}return Ae(t,c)?t:c}if(n.fromTurnId===void 0)return o.length===0?t:o;const a=Ki(n.fromTurnId),d=[];for(const c of t){if(c.kind==="turn"&&c.ordinal>=a)break;d.push(c)}const l=[...d,...o];return Ae(t,l)?t:l}function Mn(t,e,n,s=!1,i=!1){const r=s?new Map(t):new Map;for(const o of e){const a=n(o),d=t.get(a);r.set(a,s&&!i&&d!==void 0||d!==void 0&&Ae(d,o)?d:o)}if(t.size!==r.size)return r;for(const[o,a]of r)if(t.get(o)!==a)return r;return t}function xr(t,e){return ot(t,{...t,kind:"turn",steps:[...e]})}function la(t){return{kind:"turn",turnId:t,ordinal:Ki(t),state:"running",origin:{kind:"other"},steps:[]}}function zl(t,e){const n=Number(t.slice(e.length+1))||0;return{kind:"step",stepId:t,turnId:e,ordinal:n,state:"running",frames:[]}}function Gn(t,e){for(let n=t.length-1;n>=0;n-=1){const s=t[n];if(s?.kind==="turn"&&s.turnId===e)return{index:n,turn:s}}}function gs(t,e){const n=[...t];let s=n.length;for(let i=0;i<n.length;i+=1){const r=n[i];if(r?.kind==="turn"&&r.ordinal>e.ordinal){s=i;break}}return n.splice(s,0,e),n}function kt(t,e,n){const s=[...t];return s[e]=n,s}function Wl(t,e){const n=Gn(t.items,e.turnId);if(n!==void 0){const s=e.stepsPartial===void 0&&n.turn.stepsPartial!==void 0?{...e,stepsPartial:n.turn.stepsPartial}:e,i=Dt(n.turn,xr(s,n.turn.steps));return Ae(n.turn,i)?{state:t,changed:!1}:{state:{...t,items:kt(t.items,n.index,i)},changed:!0}}return{state:{...t,items:gs(t.items,xr(e,[]))},changed:!0}}function Ul(t,e,n){const s=Gn(t.items,e),i=s?.turn??la(e),r=i.steps.findIndex(u=>u.stepId===n.stepId),o=i.contentRefs?.find(u=>u.direction==="backward"&&u.path.length===1&&u.path[0]==="steps");if(r<0&&o!==void 0&&n.ordinal<o.offset)return{state:t,changed:!1,toolCallCountDelta:0};let a,d=!0;if(r>=0){const u=i.steps[r];u&&Vl(u,n)?(d=!1,a=i.steps):a=kt(i.steps,r,{...n,kind:"step",frames:u?.frames??[]})}else a=[...i.steps,{...n,kind:"step",frames:[]}].toSorted((u,f)=>u.ordinal-f.ordinal);if(!d)return{state:t,changed:!1};const l=ot(i,{...i,steps:[...a]}),c=s!==void 0?kt(t.items,s.index,l):gs(t.items,l);return{state:{...t,items:c},changed:!0}}function Vl(t,e){const{frames:n,...s}=t;return Ae(s,e)}function Kl(t,e){const n=Gn(t.items,e.turnId),s=n?.turn??la(e.turnId),i=s.steps.findIndex(k=>k.stepId===e.stepId),r=s.steps[i]??zl(e.stepId,e.turnId),o=r.frames.findIndex(k=>k.frameId===e.frame.frameId),a=s.contentRefs?.find(k=>k.direction==="backward"&&k.path.length===1&&k.path[0]==="steps"),d=s.contentRefs?.find(k=>k.direction==="backward"&&k.path.length===3&&k.path[0]==="steps"&&k.path[1]===(e.stepIndex??r.ordinal)&&k.path[2]==="frames"),l=o<0&&i<0&&a!==void 0&&(e.stepIndex??r.ordinal)<a.offset,c=o<0&&e.frameIndex!==void 0&&d!==void 0&&e.frameIndex<d.offset;if(l)return{state:t,changed:!1,toolCallCountDelta:0};if(c&&e.place!=="safety_boundary")return{state:t,changed:!1,toolCallCountDelta:0};if(c&&d!==void 0){const k=s.contentRefs?.map(x=>x===d?{...x,offset:x.offset+1,total:x.total+1}:x),S=ot(s,{...s,contentRefs:k});if(!Wc(s,S,e.frame.frameId))return{state:t,changed:!1,toolCallCountDelta:0};const w=n!==void 0?kt(t.items,n.index,S):gs(t.items,S);return{state:{...t,items:w},changed:!0,toolCallCountDelta:0}}let u,f=t.toolCallCount,g=0;if(o>=0){const k=r.frames[o],S=k===void 0?e.frame:Dt(k,e.frame);if(k!==void 0&&Ql(k,S))return{state:t,changed:!1,toolCallCountDelta:0};k!==void 0&&k.kind==="tool"!=(e.frame.kind==="tool")&&(g=e.frame.kind==="tool"?1:-1,f=ms(f,g)),u=kt(r.frames,o,S)}else{e.frame.kind==="tool"&&(g=1,f=ms(f,1));const k=d?.offset;let S=r.frames.length;e.place==="safety_boundary"&&(k===void 0||k===0?S=El(r.frames):e.frameIndex!==void 0&&(S=Math.min(r.frames.length,Math.max(0,e.frameIndex-k)))),u=S>=r.frames.length?[...r.frames,e.frame]:[...r.frames.slice(0,S),e.frame,...r.frames.slice(S)]}const h={...r,frames:[...u]},v=i>=0?kt(s.steps,i,h):[...s.steps,h].toSorted((k,S)=>k.ordinal-S.ordinal),m=ot(s,{...s,steps:v}),p=n!==void 0?kt(t.items,n.index,m):gs(t.items,m);return{state:{...t,items:p,toolCallCount:f},changed:!0,toolCallCountDelta:g}}function Gl(t,e){const n=Gn(t.items,e.turnId),s=n?.turn.steps.findIndex(l=>l.stepId===e.stepId)??-1,i=n?.turn.steps[s],r=i?.frames.find(l=>l.frameId===e.frameId);if(n===void 0||i===void 0||r===void 0)return{state:t,changed:!1,toolCallCountDelta:0};const o=r.kind==="tool"?-1:0,a={...i,frames:i.frames.filter(l=>l.frameId!==e.frameId)},d=ot(n.turn,{...n.turn,steps:kt(n.turn.steps,s,a)});return{state:{...t,items:kt(t.items,n.index,d),toolCallCount:ms(t.toolCallCount,o)},changed:!0,toolCallCountDelta:o}}function Ql(t,e){return Ae(t,e)}function Jl(t,e){if(e.target.type==="task")return Yl(t,e);const{turnId:n,stepId:s,frameId:i}=e.target,r=Gn(t.items,n);if(r===void 0)return{state:t,changed:!1,gap:{expected:0,got:e.offset}};const o=r.turn,a=o.steps.findIndex(v=>v.stepId===s),d=o.steps[a],l=d?.frames.findIndex(v=>v.frameId===i)??-1,c=d?.frames[l];if(c===void 0&&(e.stepIndex!==void 0&&o.contentRefs?.some(v=>v.direction==="backward"&&v.path.length===1&&v.path[0]==="steps"&&e.stepIndex<v.offset)||e.frameIndex!==void 0&&o.contentRefs?.some(v=>v.direction==="backward"&&v.path.length===3&&v.path[0]==="steps"&&v.path[1]===(e.stepIndex??d?.ordinal)&&v.path[2]==="frames"&&e.frameIndex<v.offset)))return{state:t,changed:!1,toolCallCountDelta:0};if(!d||!c||c.kind!=="text"&&c.kind!=="thinking")return{state:t,changed:!1,gap:{expected:0,got:e.offset}};const u=ua(c.text,e.offset,e.text);if(u.gap)return{state:t,changed:!1,gap:u.gap};if(!u.changed)return{state:t,changed:!1};const f={...c,text:u.text},g={...d,frames:kt(d.frames,l,f)},h=ot(o,{...o,steps:kt(o.steps,a,g)});return{state:{...t,items:kt(t.items,r.index,h)},changed:!0}}function Yl(t,e){if(e.target.type!=="task")throw new Error("unreachable");const n=e.target.taskId,s=t.tasks.get(n),i=s?.outputTail??"",r=ua(i,e.offset,e.text);if(r.gap)return{state:t,changed:!1,gap:r.gap};if(!r.changed)return{state:t,changed:!1};const o=s?{...s,outputTail:r.text}:{taskId:n,kind:"other",state:"running",detached:!1,outputTail:r.text},a=new Map(t.tasks);return a.set(n,o),{state:{...t,tasks:a},changed:!0}}function ua(t,e,n){if(e>t.length)return{text:t,changed:!1,gap:{expected:t.length,got:e}};if(t.slice(e,e+n.length)===n)return{text:t,changed:!1};const s=t.length-e;return t.slice(e)!==n.slice(0,s)?{text:t,changed:!1,gap:{expected:t.length,got:e}}:(s>0?n.slice(s):n).length===0?{text:t,changed:!1}:{text:t.slice(0,e)+n,changed:!0}}function _r(t,e,n,s){const i=t.items.findIndex(r=>nn(r)===n);if(i>=0){const r=t.items[i],o=e.kind==="taskref"&&r?.kind==="taskref"?{...e,at:Xl(r.at,e.at)}:e;return r===o||r!==void 0&&Ae(r,o)?{state:t,changed:!1}:{state:{...t,items:kt(t.items,i,o)},changed:!0}}if(s!==void 0){const r=[...t.items];let o=r.length;for(let a=0;a<r.length;a+=1){const d=r[a];if(d?.kind==="turn"&&d.ordinal>=s){o=a;break}}return r.splice(o,0,e),{state:{...t,items:r},changed:!0}}return{state:{...t,items:[...t.items,e]},changed:!0}}function Xl(t,e){if(t===void 0||t==="")return e;if(e===void 0||e==="")return t;const n=Date.parse(t),s=Date.parse(e);return Number.isNaN(n)?e:Number.isNaN(s)||n<=s?t:e}function nn(t){switch(t.kind){case"turn":return t.turnId;case"marker":return t.markerId;case"taskref":return t.refId}}function Zl(t,e){const n=new Set(e),s=t.items.filter(h=>h.kind==="turn"&&n.has(h.turnId)),i=t.items.filter(h=>!n.has(nn(h))),r=ca(s),o=jn.get(t)??yi,a=t.hasMoreOlder&&e.some(h=>!t.items.some(v=>nn(v)===h)&&!o.has(h)),d=a||r===0?a?void 0:0:-r,l=a?void 0:ms(t.toolCallCount,-r),c=i.length!==t.items.length,u=l!==t.toolCallCount;if(!c&&!u)return a?{state:{...t},changed:!0,toolCallCountDelta:d}:{state:t,changed:!1,toolCallCountDelta:d};let f=t.pendingInteractions,g=t.interactions;if(s.length>0){const h=new Set,v=new Set(f),m=new Set;for(const p of s)for(const k of p.steps)for(const S of k.frames)S.kind==="tool"&&h.add(S.toolCallId);for(const p of g.values())p.toolCallId!==void 0&&h.has(p.toolCallId)&&(m.add(p.interactionId),v.delete(p.interactionId));if(m.size>0){const p=new Map(g);for(const k of m)p.delete(k);g=p}f=v}return{state:{...t,items:i,interactions:g,pendingInteractions:f,toolCallCount:l},changed:!0,toolCallCountDelta:d}}function eu(t,e){const n=t.tasks.get(e.taskId);if(n&&cu(n,e))return{state:t,changed:!1};const s=new Map(t.tasks);return s.set(e.taskId,e),{state:{...t,tasks:s},changed:!0}}function tu(t,e){const n=t.interactions.get(e.interactionId);if(n&&nu(n,e))return{state:t,changed:!1};const s=new Map(t.interactions);s.set(e.interactionId,e);let i=t.pendingInteractions;if(e.state==="pending"){if(!i.has(e.interactionId)){const r=new Set(i);r.add(e.interactionId),i=r}}else if(i.has(e.interactionId)){const r=new Set(i);r.delete(e.interactionId),i=r}return{state:{...t,interactions:s,pendingInteractions:i},changed:!0}}function nu(t,e){return Ae(t,e)}function su(t,e){const n=t.attachments.get(e.attachmentId);if(n&&iu(n,e))return{state:t,changed:!1};const s=new Map(t.attachments);return s.set(e.attachmentId,e),{state:{...t,attachments:s},changed:!0}}function iu(t,e){return Ae(t,e)}function ru(t,e){const n=t.todos.get(e.todoId);if(n&&ou(n,e))return{state:t,changed:!1};const s=new Map(t.todos);return s.set(e.todoId,e),{state:{...t,todos:s},changed:!0}}function ou(t,e){return Ae(t,e)}function au(t,e){const n=t.prompts.get(e.promptId);if(n&&du(n,e))return{state:t,changed:!1};const s=new Map(t.prompts);return s.set(e.promptId,e),{state:{...t,prompts:s},changed:!0}}function du(t,e){return Ae(t,e)}function cu(t,e){return Ae(t,e)}function lu(t,e){const n=e.modes!==void 0?{plan:e.modes.plan===null?void 0:e.modes.plan??t.meta.modes?.plan}:t.meta.modes,s=e.agent!==void 0?{...t.meta.agent,...e.agent}:t.meta.agent,i={goal:e.goal===null?void 0:e.goal??t.meta.goal,activity:e.activity??t.meta.activity,modes:n!==void 0&&n.plan===void 0?void 0:n,agent:s,promptQueueHold:e.promptQueueHold===null?void 0:e.promptQueueHold??t.meta.promptQueueHold,modelSwitchQueuePositions:e.modelSwitchQueuePositions===null?void 0:e.modelSwitchQueuePositions??t.meta.modelSwitchQueuePositions};return Ae(i,t.meta)?{state:t,changed:!1}:{state:{...t,meta:i},changed:!0}}const Tr=new WeakMap;function Pn(t){const e=Tr.get(t);if(e!==void 0)return e;const n=Object.freeze([...t.values()]);return Tr.set(t,n),n}class uu{constructor(e,n){this.agentId=e,this.residentLimits=n}#e=Dl;#t=0;#n=!1;#r=new Set;#s=new Set;#i=new Map;#o=new Map;receive(e){return this.apply(e)}apply(e){const n=[];let s,i=0,r=!0,o=this.#e;for(let a=0;a<e.length&&e[a]!==void 0;){const l=gu(o,e,a),c=l.op,u=ql(o,c);if(u.gap){s={target:c.target,...u.gap},a=l.nextIndex;continue}u.toolCallCountDelta===void 0?r=!1:u.changed&&r&&(i+=u.toolCallCountDelta);const f=ku(c);if(!u.changed){f!==void 0&&(c.op==="frame.upsert"||c.op==="task.upsert")&&this.#s.delete(f)&&n.push(...l.originals),a=l.nextIndex;continue}o=u.state,this.syncToolCallIndex(c,o),n.push(...l.originals),c.op==="append"&&f!==void 0?this.#s.add(f):f!==void 0?this.#s.delete(f):(c.op==="reset"||c.op==="items.remove")&&this.#s.clear(),c.op==="reset"&&(this.#n=!1),a=l.nextIndex}if(this.#e=o,n.length>0){const a={agentId:this.agentId,ops:n};for(const d of this.#r)d(a)}return{accepted:n,toolCallCountDelta:r?i:void 0,gap:s}}onChange(e){return this.#r.add(e),{dispose:()=>void this.#r.delete(e)}}getItems(){return this.#e.items}getTurn(e){for(let n=this.#e.items.length-1;n>=0;n-=1){const s=this.#e.items[n];if(s?.kind==="turn"&&s.turnId===e)return s}}getToolCall(e){return this.#i.get(e)}getTasks(){return this.#e.tasks}getTask(e){return this.#e.tasks.get(e)}getInteractions(){return this.#e.interactions}getInteraction(e){return this.#e.interactions.get(e)}getAttachments(){return this.#e.attachments}getAttachment(e){return this.#e.attachments.get(e)}getTodos(){return this.#e.todos}getTodo(e){return this.#e.todos.get(e)}getPrompts(){return this.#e.prompts}getPrompt(e){return this.#e.prompts.get(e)}getMeta(){return this.#e.meta}listPendingInteractions(){return[...this.#e.pendingInteractions]}get hasMoreOlder(){return this.#e.hasMoreOlder}noteOlderHistory(){this.#e.hasMoreOlder||(this.#e={...this.#e,hasMoreOlder:!0})}setHasMoreOlder(e){this.#e.hasMoreOlder!==e&&(this.#e={...this.#e,hasMoreOlder:e})}replaceItems(e,n){if(e===this.#e.items){const a=n!==this.#e.hasMoreOlder;return this.setHasMoreOlder(n),a}const s=this.snapshot(),i=[...this.#s],r=this.apply([{op:"reset",agentId:this.agentId,snapshot:{...s,items:e,hasMoreOlder:n},coverage:n?{kind:"tail",hasMoreOlder:!0}:{kind:"full",hasMoreOlder:!1}}]).accepted.length>0,o=this.#e.items.flatMap(a=>a.kind==="turn"?[`frame:${a.turnId}:`]:[]);for(const a of i)(a.startsWith("task:")||o.some(d=>a.startsWith(d)))&&this.#s.add(a);return r}releaseBefore(e){const n=this.#e.items,s=n.findIndex(r=>r.kind==="turn"&&r.turnId===e);if(s<=0)return[];const i=n.slice(0,s);return this.replaceItems(n.slice(s),!0),i}snapshot(e={}){let n=this.#e.items,s=this.#e.hasMoreOlder;if(e.tailTurns!==void 0){const r=Math.max(0,e.tailTurns);let o=0,a=n.length,d=!1;for(let l=n.length-1;l>=0;l-=1)if(n[l]?.kind==="turn")if(o+=1,o<=r)a=l;else{d=!0;break}(d||this.#t>0||s&&a>0&&a<n.length)&&(n=r===0?[]:n.slice(a),s=!0)}const i=e.globalWindow===void 0?{tasks:Pn(this.#e.tasks),attachments:Pn(this.#e.attachments),prompts:Pn(this.#e.prompts),taskRefs:[],attachmentRefs:[],promptRefs:[],coverage:{version:1,tasks:gn(this.#e.tasks.size,this.#e.tasks.size),attachments:gn(this.#e.attachments.size,this.#e.attachments.size),prompts:gn(this.#e.prompts.size,this.#e.prompts.size)}}:Rr(this.#e,n,e.globalWindow);return{items:n,tasks:i.tasks,interactions:Pn(this.#e.interactions),attachments:i.attachments,todos:Pn(this.#e.todos),prompts:i.prompts,...e.globalWindow===void 0?{}:{taskRefs:i.taskRefs,attachmentRefs:i.attachmentRefs,promptRefs:i.promptRefs,globalCoverage:i.coverage},toolCallCount:this.#e.toolCallCount,toolCallCountKnown:this.#e.toolCallCount!==void 0,meta:this.#e.meta,hasMoreOlder:s}}residentReport(){const e=this.#e.items.filter(i=>i.kind==="turn").length,n=Ar(this.#e),s=this.residentLimits;return{turns:e,estimatedBytes:n,trimmedTurns:this.#t,overBudget:s!==void 0&&(n>s.maxBytes||e>s.tailTurns)}}get hasEvictedTail(){return this.#n}releaseDurableHistory(e,n){const s=new Map(e.items.filter(i=>i.kind==="turn").map(i=>[i.turnId,i]));return s.size===0?[]:this.releaseDurableMatchedTurns(i=>{const r=s.get(i.turnId);return r!==void 0&&fa(i,r)},n,e.tasks,e.attachments,e.prompts)}releaseDurableTurns(e,n,s){const i=e instanceof Set?e:new Set(e);return i.size===0?[]:this.releaseDurableMatchedTurns(r=>i.has(r),n,s?.tasks??[],s?.attachments??[],s?.prompts??[])}releaseDurableMatchedTurns(e,n,s,i,r){let o=0,a;for(const p of this.#e.items)p.kind==="turn"&&(o+=1,a=p);let d=Ar(this.#e);const l=[];for(const p of this.#e.items){if(o<=n.tailTurns&&d<=n.maxBytes)break;p.kind!=="turn"||p.state==="running"||p===a&&n.tailTurns>0||e(p)&&(l.push(p.turnId),o-=1,d-=tn(p))}if(l.length===0)return l;const c=new Set(l);let u=-1;for(const p of this.#e.items)p.kind==="turn"&&c.has(p.turnId)&&p.ordinal>u&&(u=p.ordinal);const f=this.#e.items.filter(p=>p.kind!=="turn"||!c.has(p.turnId));(a!==void 0&&c.has(a.turnId)||u>=0&&f.some(p=>p.kind==="turn"&&p.ordinal<u))&&(this.#n=!0);const g=Rr(this.#e,f,{taskLimit:n.tailTurns,attachmentLimit:n.tailTurns,promptLimit:n.tailTurns}),h=zs(this.#e.tasks,s,p=>p.taskId,new Set(g.tasks.map(p=>p.taskId))),v=zs(this.#e.attachments,i,p=>p.attachmentId,new Set(g.attachments.map(p=>p.attachmentId))),m=zs(this.#e.prompts,r,p=>p.promptId,new Set(g.prompts.map(p=>p.promptId)));if(this.#e={...this.#e,items:f,tasks:h,attachments:v,prompts:m,hasMoreOlder:!0},this.rebuildToolCallIndex(f),this.#t+=l.length,this.#s.size>0){const p=l.some(k=>k.includes(":"));for(const k of this.#s){if(k.startsWith("task:")){h.has(k.slice(5))||this.#s.delete(k);continue}if(k.startsWith("frame:"))if(p)l.some(S=>k.startsWith(`frame:${S}:`))&&this.#s.delete(k);else{const S=k.indexOf(":",6);S>6&&c.has(k.slice(6,S))&&this.#s.delete(k)}}}return l}syncToolCallIndex(e,n){if(e.op==="reset"){this.rebuildToolCallIndex(n.items);return}if(e.op==="items.remove"){const r=new Set(e.ids);for(const[o,a]of this.#i)r.has(a.turnId)&&(this.#i.delete(o),this.#o.delete(es(a.turnId,a.stepId,a.frame.frameId)));return}if(e.op==="frame.remove"){const r=es(e.turnId,e.stepId,e.frameId),o=this.#o.get(r);o!==void 0&&this.#i.delete(o),this.#o.delete(r);return}if(e.op!=="frame.upsert")return;const s=es(e.turnId,e.stepId,e.frame.frameId),i=this.#o.get(s);i!==void 0&&this.#i.delete(i),this.#o.delete(s),e.frame.kind==="tool"&&(this.#i.set(e.frame.toolCallId,{turnId:e.turnId,stepId:e.stepId,frame:e.frame}),this.#o.set(s,e.frame.toolCallId))}rebuildToolCallIndex(e){this.#i.clear(),this.#o.clear();for(const n of e)if(n.kind==="turn")for(const s of n.steps)for(const i of s.frames)i.kind==="tool"&&(this.#i.set(i.toolCallId,{turnId:n.turnId,stepId:s.stepId,frame:i}),this.#o.set(es(n.turnId,s.stepId,i.frameId),i.toolCallId))}}function Cr(t,e,n){if(e.length===0)return t;const s=new Map(t.map(u=>[Hs(u),u])),i=new Set,r=[];for(const u of e){const f=Hs(u);if(i.has(f))continue;i.add(f);const g=s.get(f);r.push(g===void 0?u:n(g,u))}let o=Number.NEGATIVE_INFINITY;for(const u of r)u.kind==="turn"&&u.ordinal>o&&(o=u.ordinal);const a=t.find(u=>u.kind==="turn"&&u.ordinal>o),d=[],l=(u,f,g,h)=>{let v=g;const m=[];for(let p=u.length-1;p>=0;p-=1){const k=u[p];k.kind==="turn"&&(v=k.ordinal),m[p]=v}u.forEach((p,k)=>{h?.has(Hs(p))!==!0&&d.push({item:p,anchor:m[k],turn:p.kind==="turn",source:f,order:k})})};l(r,0,a?.kind==="turn"?a.ordinal:Number.POSITIVE_INFINITY),l(t,1,Number.POSITIVE_INFINITY,i),d.sort((u,f)=>u.anchor-f.anchor||Number(u.turn)-Number(f.turn)||u.source-f.source||u.order-f.order);const c=d.map(u=>u.item);return c.length===t.length&&c.every((u,f)=>u===t[f])?t:c}function Hs(t){return t.kind==="turn"?`turn:${t.turnId}`:t.kind==="marker"?`marker:${t.markerId}`:`taskref:${t.refId}`}function fa(t,e){return Pl(t,e)}function zs(t,e,n,s){const i=new Map(e.map(r=>[n(r),r]));return new Map([...t].filter(([r,o])=>s.has(r)||!i.has(r)||!fa(o,i.get(r))))}function Rr(t,e,n){const s=new Set,i=new Set,r=new Set;for(const v of e){if(v.kind==="taskref"&&s.add(v.taskId),v.kind==="marker"&&v.marker==="message.delivery"){const m=v.payload;if(typeof m?.messageId=="string"){r.add(m.messageId);for(const[p,k]of t.prompts)k.userMessageId===m.messageId&&r.add(p)}}if(v.kind==="turn"){v.promptId!==void 0&&r.add(v.promptId);for(const m of v.attachmentIds??[])i.add(m);for(const m of v.steps)for(const p of m.frames){if(p.kind==="text"||p.kind==="tool")for(const k of p.attachmentIds??[])i.add(k);p.kind==="tool"&&p.taskId!==void 0&&s.add(p.taskId)}}}const o=Ws(t.tasks,s,v=>v.state==="running",n.taskLimit),a=Ws(t.attachments,i,()=>!1,n.attachmentLimit),d=Ws(t.prompts,r,v=>v.status==="running"||v.status==="queued",n.promptLimit),l=[...t.tasks.entries()].filter(([v])=>o.has(v)).map(([,v])=>fu(v,n.taskOutputTailChars??1024)),c=[...t.attachments.entries()].filter(([v])=>a.has(v)).map(([,v])=>hu(v,n.attachmentSourceBytes??2048)),u=[...t.prompts.entries()].filter(([v])=>d.has(v)).map(([,v])=>pu(v,n.promptContentBytes??4096)),f=[...t.tasks.keys()].filter(v=>!o.has(v)).map(v=>({kind:"task",taskId:v})),g=[...t.attachments.keys()].filter(v=>!a.has(v)).map(v=>({kind:"attachment",attachmentId:v})),h=[...t.prompts.keys()].filter(v=>!d.has(v)).map(v=>({kind:"prompt",promptId:v}));return{tasks:l,attachments:c,prompts:u,taskRefs:f,attachmentRefs:g,promptRefs:h,coverage:{version:1,tasks:gn(o.size,t.tasks.size),attachments:gn(a.size,t.attachments.size),prompts:gn(d.size,t.prompts.size)}}}function Ws(t,e,n,s){const i=s===void 0?Number.POSITIVE_INFINITY:Math.max(0,Math.floor(s)),r=new Set;for(const[a,d]of t)(e.has(a)||n(d))&&r.add(a);if(r.size>=i)return r;const o=[...t.keys()];for(let a=o.length-1;a>=0&&r.size<i;a-=1){const d=o[a];d!==void 0&&r.add(d)}return r}function gn(t,e){return{returned:t,total:e,hasMore:t<e}}function fu(t,e){return t.outputTail.length<=e?t:{...t,outputTail:t.outputTail.slice(-e),detailRef:{kind:"task",taskId:t.taskId}}}function hu(t,e){const n=t.source;return n===void 0||n.kind!=="url"||n.url.length<=e?t:{...t,source:void 0,detailRef:{kind:"attachment",attachmentId:t.attachmentId}}}function pu(t,e){return t.content===void 0||mu(t.content)<=e?t:{...t,content:void 0,detailRef:{kind:"prompt",promptId:t.promptId}}}function mu(t){try{return JSON.stringify(t)?.length??0}catch{return Number.POSITIVE_INFINITY}}function es(t,e,n){return`${t}\0${e}\0${n}`}function gu(t,e,n){const s=e[n];if(s===void 0)throw new RangeError("operation index out of bounds");if(s.op!=="append"||s.text.length===0||vu(t,s.target)!==s.offset)return{op:s,originals:[s],nextIndex:n+1};const i=[s],r=[s.text];let o=s.offset+s.text.length,a=n+1;for(;a<e.length;){const d=e[a];if(d===void 0||d.op!=="append"||d.text.length===0||!yu(s.target,d.target)||d.offset!==o)break;i.push(d),r.push(d.text),o+=d.text.length,a+=1}return i.length===1?{op:s,originals:i,nextIndex:a}:{op:{...s,text:r.join("")},originals:i,nextIndex:a}}function vu(t,e){if(e.type==="task")return t.tasks.get(e.taskId)?.outputTail?.length??0;let n;for(let r=t.items.length-1;r>=0;r-=1){const o=t.items[r];if(o?.kind==="turn"&&o.turnId===e.turnId){n=o;break}}if(n===void 0)return;const i=n.steps.find(r=>r.stepId===e.stepId)?.frames.find(r=>r.frameId===e.frameId);return i?.kind==="text"||i?.kind==="thinking"?i.text.length:void 0}function yu(t,e){return t.type!==e.type?!1:t.type==="task"?e.type==="task"&&t.taskId===e.taskId:e.type==="frame"&&t.turnId===e.turnId&&t.stepId===e.stepId&&t.frameId===e.frameId}function ku(t){if(t.op==="append")return t.target.type==="frame"?`frame:${t.target.turnId}:${t.target.stepId}:${t.target.frameId}`:`task:${t.target.taskId}`;if(t.op==="frame.upsert")return`frame:${t.turnId}:${t.stepId}:${t.frame.frameId}`;if(t.op==="frame.remove")return`frame:${t.turnId}:${t.stepId}:${t.frameId}`;if(t.op==="task.upsert")return`task:${t.task.taskId}`}function Ar(t){return tn({items:t.items,tasks:t.tasks,interactions:t.interactions,attachments:t.attachments,todos:t.todos,prompts:t.prompts,toolCallCount:t.toolCallCount,meta:t.meta,pendingInteractions:t.pendingInteractions,hasMoreOlder:t.hasMoreOlder})}function tn(t,e=new WeakSet){if(t==null)return 8;if(typeof t=="string")return 24+t.length*2;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint")return 8;if(typeof t!="object")return 16;if(e.has(t))return 8;if(e.add(t),Array.isArray(t)){let s=32+t.length*8;for(const i of t)s+=tn(i,e);return s}if(t instanceof Map){let s=48+t.size*24;for(const[i,r]of t)s+=tn(i,e),s+=tn(r,e);return s}if(t instanceof Set){let s=48+t.size*16;for(const i of t)s+=tn(i,e);return s}let n=48;for(const[s,i]of Object.entries(t))n+=16+s.length*2+tn(i,e);return n}function ki(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function vs(t){return typeof t=="string"?t:void 0}function Iu(t){if(vs(t?.kind)!=="peer_thread")return!1;if(t?.notification===!0)return!0;const e=ki(t?.source),n=vs(e?.name);return n!==void 0&&n.startsWith("thread-watch:")}function ha(t){const e=ki(t),n=ki(e?.payload),s=n!==void 0&&typeof n.kind=="string"?n:e,i=vs(s?.kind);return i==="merged"?(Array.isArray(s?.origins)?s.origins:[]).some(ha):Iu(s)?!1:i===void 0||i==="user"||i==="peer_thread"||i==="bridged_peer"||i==="agent_message"||i==="branch_fold"||i==="external_thread"||i==="unknown"||i==="system_trigger"&&vs(s?.name)==="thread_create"||i==="room_message"&&s?.targeted===!0?!0:(i==="skill_activation"||i==="plugin_command")&&s?.trigger==="user-slash"}const Mr="kimi-file://";function wu(t){if(!t.startsWith(Mr))return;const e=t.slice(Mr.length),n=e.indexOf("?"),s=n===-1?e:e.slice(0,n);return s.length>0?{fileId:s}:void 0}function Iv(t){return wu(t)?.fileId}function ys(t){const e=/^blobref:([A-Za-z0-9][A-Za-z0-9_-]{0,255})[/:]([0-9a-f]{64})$/u.exec(t);if(e!==null)return{kind:"agent",agentId:e[1],hash:e[2]};const n=/^blobref:((?:image|video|audio)\/[A-Za-z0-9.+_*-]+);([0-9a-f]{64})$/u.exec(t);return n===null?void 0:{kind:"mime",mime:n[1],hash:n[2]}}function bu(t){if(t===null||typeof t!="object"||Array.isArray(t))return;const e=t;for(const n of["image","video","audio"]){if(e.type===`${n}_url`)for(const s of[`${n}Url`,`${n}_url`]){const i=e[s];if(typeof i?.url=="string"&&i.url!=="")return{kind:n,url:i.url}}if(e.type===n){const s=e.source;if(s?.kind==="url"&&typeof s.url=="string")return{kind:n,url:s.url};if(s?.kind==="base64"&&typeof s.data=="string"&&typeof s.media_type=="string")return{kind:n,url:`data:${s.media_type};base64,${s.data}`}}}}function pa(t){const e=t.contentRefs;if(e===void 0||e.length===0)return t;const n=[],s=new Map;for(const i of e){const[r,o,a,d]=i.path;if(i.source.kind!=="turn"||i.source.id!==t.turnId||r!=="steps"||typeof o!="number"||a!=="frames"||typeof d!="number"||i.path.length<=4){n.push(i);continue}const l=mn(t,["steps",o]),c=mn(t,i.path.slice(0,4));if(l===void 0||c===void 0){n.push(i);continue}const u=`${l.stepId}/${c.frameId}`,f={...i,source:{kind:"frame",id:c.frameId,turnId:t.turnId,stepId:l.stepId},path:i.path.slice(4)},g=s.get(u)??[];g.push(f),s.set(u,g)}return s.size===0?t:{...t,contentRefs:n,steps:t.steps.map(i=>({...i,frames:i.frames.map(r=>{const o=s.get(`${i.stepId}/${r.frameId}`);return o===void 0?r:{...r,contentRefs:[...r.contentRefs??[],...o]}})}))}}const Ii="kiki.unconfirmedSubmissions";function ks(t){try{const e=JSON.parse(t.getItem(Ii)??"[]");return Array.isArray(e)?e.flatMap(n=>{if(typeof n!="object"||n===null||typeof n.sessionId!="string"||typeof n.agentId!="string"||typeof n.promptId!="string"||typeof n.createdAt!="string")return[];const s=pi.array().safeParse(n.content);return s.success?[{...n,content:s.data}]:[]}):[]}catch{return[]}}const wi=new Set;function Su(){for(const t of wi)t()}function wv(t){return wi.add(t),()=>{wi.delete(t)}}function bi(t,e){e.length===0?t.removeItem(Ii):t.setItem(Ii,JSON.stringify(e)),Su()}function Pr(t,e={}){const n=e.persist===!1?void 0:hs.capture();if(n===void 0)return{persisted:!1,acknowledge:()=>{}};let s=!1;try{const i=ks(n).filter(r=>r.sessionId!==t.sessionId||r.agentId!==t.agentId||r.promptId!==t.promptId);bi(n,[...i,t]),s=!0}catch{}return{persisted:s,acknowledge:()=>{try{bi(n,ks(n).filter(i=>i.sessionId!==t.sessionId||i.agentId!==t.agentId||i.promptId!==t.promptId))}catch{}}}}function bv(t,e){return ks(hs).filter(n=>n.sessionId===t&&(e===void 0||n.agentId===e))}function Er(t,e,n){typeof localStorage>"u"||bi(hs,ks(hs).filter(s=>s.sessionId!==t||s.promptId!==e||n!==void 0&&s.agentId!==n))}function Or(t){return{onFetch:(e,n)=>{const s=e.options,i=e.fetchOptions?.meta?.fetchMore?.direction,r=e.state.data?.pages||[],o=e.state.data?.pageParams||[];let a={pages:[],pageParams:[]},d=0;const l=async()=>{let c=!1;const u=h=>{Gc(h,()=>e.signal,()=>c=!0)},f=Uc(e.options,e.fetchOptions),g=async(h,v,m)=>{if(c)return Promise.reject();if(v==null&&h.pages.length)return Promise.resolve(h);const k=(()=>{const b={client:e.client,queryKey:e.queryKey,pageParam:v,direction:m?"backward":"forward",meta:e.options.meta};return u(b),b})(),S=await f(k),{maxPages:w}=e.options,x=m?Vc:Kc;return{pages:x(h.pages,S,w),pageParams:x(h.pageParams,v,w)}};if(i&&r.length){const h=i==="backward",v=h?ma:Si,m={pages:r,pageParams:o},p=v(s,m);a=await g(m,p,h)}else{const h=t??r.length;do{const v=d===0?o[0]??s.initialPageParam:Si(s,a);if(d>0&&v==null)break;a=await g(a,v),d++}while(d<h)}return a};e.options.persister?e.fetchFn=()=>e.options.persister?.(l,{client:e.client,queryKey:e.queryKey,meta:e.options.meta,signal:e.signal},n):e.fetchFn=l}}}function Si(t,{pages:e,pageParams:n}){const s=e.length-1;return e.length>0?t.getNextPageParam(e[s],e,n[s],n):void 0}function ma(t,{pages:e,pageParams:n}){return e.length>0?t.getPreviousPageParam?.(e[0],e,n[0],n):void 0}function Sv(t,e){return e?Si(t,e)!=null:!1}function xv(t,e){return!e||!t.getPreviousPageParam?!1:ma(t,e)!=null}var xu=class extends Qc{#e;#t;#n;#r;constructor(t){super(),this.#e=t.client,this.mutationId=t.mutationId,this.#n=t.mutationCache,this.#t=[],this.state=t.state||_u(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){this.#t.includes(t)||(this.#t.push(t),this.clearGcTimeout(),this.#n.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#t=this.#t.filter(e=>e!==t),this.scheduleGc(),this.#n.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#t.length||(this.state.status==="pending"?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(t){const e=()=>{this.#s({type:"continue"})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=Jc({fn:()=>this.options.mutationFn?this.options.mutationFn(t,n):Promise.reject(new Error("No mutationFn found")),onFail:(r,o)=>{this.#s({type:"failed",failureCount:r,error:o})},onPause:()=>{this.#s({type:"pause"})},onContinue:e,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});const s=this.state.status==="pending",i=!this.#r.canStart();try{if(s)e();else{this.#s({type:"pending",variables:t,isPaused:i}),this.#n.config.onMutate&&await this.#n.config.onMutate(t,this,n);const o=await this.options.onMutate?.(t,n);o!==this.state.context&&this.#s({type:"pending",context:o,variables:t,isPaused:i})}const r=await this.#r.start();return await this.#n.config.onSuccess?.(r,t,this.state.context,this,n),await this.options.onSuccess?.(r,t,this.state.context,n),await this.#n.config.onSettled?.(r,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(r,null,t,this.state.context,n),this.#s({type:"success",data:r}),r}catch(r){try{await this.#n.config.onError?.(r,t,this.state.context,this,n)}catch(o){Promise.reject(o)}try{await this.options.onError?.(r,t,this.state.context,n)}catch(o){Promise.reject(o)}try{await this.#n.config.onSettled?.(void 0,r,this.state.variables,this.state.context,this,n)}catch(o){Promise.reject(o)}try{await this.options.onSettled?.(void 0,r,t,this.state.context,n)}catch(o){Promise.reject(o)}throw this.#s({type:"error",error:r}),r}finally{this.#n.runNext(this)}}#s(t){const e=n=>{switch(t.type){case"failed":return{...n,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...n,isPaused:!0};case"continue":return{...n,isPaused:!1};case"pending":return{...n,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...n,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...n,data:void 0,error:t.error,failureCount:n.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=e(this.state),vt.batch(()=>{this.#t.forEach(n=>{n.onMutationUpdate(t)}),this.#n.notify({mutation:this,type:"updated",action:t})})}};function _u(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var Tu=class extends Xo{constructor(t={}){super(),this.config=t,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(t,e,n){const s=new xu({client:t,mutationCache:this,mutationId:++this.#n,options:t.defaultMutationOptions(e),state:n});return this.add(s),s}add(t){this.#e.add(t);const e=ts(t);if(typeof e=="string"){const n=this.#t.get(e);n?n.push(t):this.#t.set(e,[t])}this.notify({type:"added",mutation:t})}remove(t){if(this.#e.delete(t)){const e=ts(t);if(typeof e=="string"){const n=this.#t.get(e);if(n)if(n.length>1){const s=n.indexOf(t);s!==-1&&n.splice(s,1)}else n[0]===t&&this.#t.delete(e)}}this.notify({type:"removed",mutation:t})}canRun(t){const e=ts(t);if(typeof e=="string"){const s=this.#t.get(e)?.find(i=>i.state.status==="pending");return!s||s===t}else return!0}runNext(t){const e=ts(t);return typeof e=="string"?this.#t.get(e)?.find(s=>s!==t&&s.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){vt.batch(()=>{this.#e.forEach(t=>{this.notify({type:"removed",mutation:t})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(t){const e={exact:!0,...t};return this.getAll().find(n=>gr(e,n))}findAll(t={}){return this.getAll().filter(e=>gr(t,e))}notify(t){vt.batch(()=>{this.listeners.forEach(e=>{e(t)})})}resumePausedMutations(){const t=this.getAll().filter(e=>e.state.isPaused);return vt.batch(()=>Promise.all(t.map(e=>e.continue().catch(Lt))))}};function ts(t){return t.options.scope?.id}var Cu=class extends Xo{constructor(t={}){super(),this.config=t,this.#e=new Map}#e;build(t,e,n){const s=e.queryKey,i=e.queryHash??Zo(s,e);let r=this.get(i);return r||(r=new Yc({client:t,queryKey:s,queryHash:i,options:t.defaultQueryOptions(e),state:n,defaultOptions:t.getQueryDefaults(s)}),this.add(r)),r}add(t){this.#e.has(t.queryHash)||(this.#e.set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const e=this.#e.get(t.queryHash);e&&(t.destroy(),e===t&&this.#e.delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){vt.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return this.#e.get(t)}getAll(){return[...this.#e.values()]}find(t){const e={exact:!0,...t};return this.getAll().find(n=>vr(e,n))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter(n=>vr(t,n)):e}notify(t){vt.batch(()=>{this.listeners.forEach(e=>{e(t)})})}onFocus(){vt.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){vt.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},Ru=class{#e;#t;#n;#r;#s;#i;#o;#a;constructor(t={}){this.#e=t.queryCache||new Cu,this.#t=t.mutationCache||new Tu,this.#n=t.defaultOptions||{},this.#r=new Map,this.#s=new Map,this.#i=0}mount(){this.#i++,this.#i===1&&(this.#o=Xc.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#a=yr.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#i--,this.#i===0&&(this.#o?.(),this.#o=void 0,this.#a?.(),this.#a=void 0)}isFetching(t){return this.#e.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#t.findAll({...t,status:"pending"}).length}getQueryData(t){const e=this.defaultQueryOptions({queryKey:t});return this.#e.get(e.queryHash)?.state.data}ensureQueryData(t){const e=this.defaultQueryOptions(t),n=this.#e.build(this,e),s=n.state.data;return s===void 0?this.fetchQuery(t):(t.revalidateIfStale&&n.isStaleByTime(kr(e.staleTime,n))&&this.prefetchQuery(e),Promise.resolve(s))}getQueriesData(t){return this.#e.findAll(t).map(({queryKey:e,state:n})=>{const s=n.data;return[e,s]})}setQueryData(t,e,n){const s=this.defaultQueryOptions({queryKey:t}),r=this.#e.get(s.queryHash)?.state.data,o=Zc(e,r);if(o!==void 0)return this.#e.build(this,s).setData(o,{...n,manual:!0})}setQueriesData(t,e,n){return vt.batch(()=>this.#e.findAll(t).map(({queryKey:s})=>[s,this.setQueryData(s,e,n)]))}getQueryState(t){const e=this.defaultQueryOptions({queryKey:t});return this.#e.get(e.queryHash)?.state}removeQueries(t){const e=this.#e;vt.batch(()=>{e.findAll(t).forEach(n=>{e.remove(n)})})}resetQueries(t,e){const n=this.#e;return vt.batch(()=>(n.findAll(t).forEach(s=>{s.reset()}),this.refetchQueries({type:"active",...t},e)))}cancelQueries(t,e={}){const n={revert:!0,...e},s=vt.batch(()=>this.#e.findAll(t).map(i=>i.cancel(n)));return Promise.all(s).then(Lt).catch(Lt)}invalidateQueries(t,e={}){return vt.batch(()=>(this.#e.findAll(t).forEach(n=>{n.invalidate()}),t?.refetchType==="none"?Promise.resolve():this.refetchQueries({...t,type:t?.refetchType??t?.type??"active"},e)))}refetchQueries(t,e={}){const n={...e,cancelRefetch:e.cancelRefetch??!0},s=vt.batch(()=>this.#e.findAll(t).filter(i=>!i.isDisabled()&&!i.isStatic()).map(i=>{let r=i.fetch(void 0,n);return n.throwOnError||(r=r.catch(Lt)),i.state.fetchStatus==="paused"?Promise.resolve():r}));return Promise.all(s).then(Lt)}fetchQuery(t){const e=this.defaultQueryOptions(t);e.retry===void 0&&(e.retry=!1);const n=this.#e.build(this,e);return n.isStaleByTime(kr(e.staleTime,n))?n.fetch(e):Promise.resolve(n.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(Lt).catch(Lt)}fetchInfiniteQuery(t){return t.behavior=Or(t.pages),this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(Lt).catch(Lt)}ensureInfiniteQueryData(t){return t.behavior=Or(t.pages),this.ensureQueryData(t)}resumePausedMutations(){return yr.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(t){this.#n=t}setQueryDefaults(t,e){this.#r.set(Ir(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#r.values()],n={};return e.forEach(s=>{wr(t,s.queryKey)&&Object.assign(n,s.defaultOptions)}),n}setMutationDefaults(t,e){this.#s.set(Ir(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#s.values()],n={};return e.forEach(s=>{wr(t,s.mutationKey)&&Object.assign(n,s.defaultOptions)}),n}defaultQueryOptions(t){if(t._defaulted)return t;const e={...this.#n.queries,...this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=Zo(e.queryKey,e)),e.refetchOnReconnect===void 0&&(e.refetchOnReconnect=e.networkMode!=="always"),e.throwOnError===void 0&&(e.throwOnError=!!e.suspense),!e.networkMode&&e.persister&&(e.networkMode="offlineFirst"),e.queryFn===el&&(e.enabled=!1),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#n.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}};function ga(t){return t===void 0?void 0:/^data:([^;,]+)/.exec(t)?.[1]}function va(t,e){switch(e.kind){case"base64":return{kind:t,url:`data:${e.media_type};base64,${e.data}`,mime:e.media_type};case"url":return ka(t,e.url);case"file":case"session_media":return{kind:t,fileId:e.file_id}}}const ya=/^kimi-file:\/\/([^?]*)/;function ka(t,e,n){const s=ys(e);if(s?.kind==="mime")return{kind:t,name:n?.name,size:n?.size,mime:s.mime,blobHash:s.hash};const i=ya.exec(e);if(i!==null){const r=i[1]??"";return{kind:t,...n,fileId:r===""?void 0:r}}return Ia.test(e)?{kind:t,...n,url:e,mime:n?.mime??ga(e)}:{kind:t,...n}}function _v(t,e){if(t.kind!=="file")return t;const n=e.mediaType.startsWith("image/")?"image":e.mediaType.startsWith("video/")?"video":e.mediaType.startsWith("audio/")?"audio":void 0;return n===void 0?t:{...t,kind:n,name:t.name??e.name,mime:e.mediaType.endsWith("/*")?t.mime:e.mediaType}}function Au(t){const e=[];for(const n of t)n.type==="image"||n.type==="video"||n.type==="audio"?e.push({...va(n.type,n.source),name:n.name}):n.type==="file"&&e.push({kind:"file",fileId:n.file_id,name:n.name,mime:n.media_type,size:n.size});return e}function Dr(t,e,n){const s=/^(inline|inline-content):([^:]+):[A-Za-z0-9_-]+:([0-9a-f]{64})$/u,i=s.exec(t),r=s.exec(e);return i!==null&&r!==null&&i[1]!==r[1]&&i[2]===r[2]&&i[3]===r[3]&&(n===void 0||i[2]===n)}function Tv(t,e,n,s=!1,i=!1){const r=(f,g)=>f.kind==="file"&&f.detail!==void 0&&f.fileId===void 0&&f.blobHash===void 0&&f.url===void 0&&f.mime===void 0&&f.name===void 0&&(g.kind==="image"||g.kind==="video"||g.kind==="audio"),o=t!==void 0&&e!==void 0&&t.length===e.length,a=i&&t!==void 0&&e!==void 0&&e.length>0&&t.length>e.length&&e.every((f,g)=>{const h=t[g];return h.detail!==void 0&&h.fileId===void 0?(h.kind===f.kind||r(h,f))&&(n===void 0||h.detail.agentId===n):h.kind===f.kind&&h.fileId!==void 0&&f.fileId!==void 0&&(h.fileId===f.fileId||Dr(h.fileId,f.fileId,n))}),l=s&&(o||a)&&e!==void 0&&t!==void 0&&e.every((f,g)=>{const h=t[g],v=h.fileId===void 0?void 0:ys(h.fileId),m=h.blobHash??v?.hash,p=r(h,f);return(h.kind===f.kind||p)&&(v?.kind!=="agent"||n===void 0||v.agentId===n)&&(h.detail===void 0||n===void 0||h.detail.agentId===n)&&(m===void 0||f.blobHash===void 0||m===f.blobHash)&&(h.fileId===void 0||f.fileId===void 0||h.fileId===f.fileId||Dr(h.fileId,f.fileId,n))&&(h.url===void 0||f.url===void 0||h.url===f.url)})?t.map((f,g)=>{const h=e[g];if(h===void 0)return f;const v=f.url??h.url,m=f.fileId??h.fileId,p=f.blobHash??h.blobHash,k=h.url!==void 0||h.fileId!==void 0||h.blobHash!==void 0;return{...h,...f,kind:f.kind==="file"&&f.detail!==void 0&&(h.kind==="image"||h.kind==="video"||h.kind==="audio")?h.kind:f.kind,url:v,path:f.path??h.path,fileId:m,blobHash:p,detail:k?void 0:f.detail??h.detail,name:f.name??h.name,mime:f.mime??h.mime,size:f.size??h.size}}):[...t??[],...e??[]],c=[],u=new Map;for(const f of l){const g=f.fileId===void 0?void 0:ys(f.fileId),h=g?.kind==="agent"?g.agentId:f.detail?.agentId??n,v=f.blobHash??g?.hash,m=[f.fileId===void 0?void 0:["file",f.fileId],v===void 0?void 0:["blob",v],f.url===void 0?void 0:["url",f.url],f.detail===void 0?void 0:["detail",f.detail.attachmentId]].filter(w=>w!==void 0).map(w=>JSON.stringify([f.kind,h,...w])),p=m.map(w=>u.get(w)).find(w=>w!==void 0),k=p??c.length;for(const w of m)u.set(w,k);if(p===void 0){c.push(f);continue}const S=c[p];c[p]={...S,url:S.url??f.url,path:S.path??f.path,fileId:S.fileId??f.fileId,blobHash:S.blobHash??f.blobHash,detail:S.detail??f.detail,name:S.name??f.name,mime:S.mime??f.mime,size:S.size??f.size}}return c}const qr=/<(\/?)(image|video|audio)\b([^>]*)>/gi,Mu=/\bpath=(?:"([^"]*)"|'([^']*)')/i,Ia=/^(?:data:|blob:|https?:\/\/)/i;function Fr(t,e){const n=t.url;if(n?.startsWith("blobref:")){const i=ys(n);return i?.kind==="mime"&&i.mime.startsWith(`${t.kind}/`)?{...t,url:void 0,path:e,mime:i.mime,blobHash:i.hash}:{...t,url:void 0,path:void 0,name:e,mime:void 0}}const s=n===void 0?null:ya.exec(n);if(s!==null){const i=s[1]??"";return{...t,url:void 0,path:e,fileId:i===""?void 0:i}}return{...t,url:n!==void 0&&Ia.test(n)?n:void 0,path:e}}function Cv(t){if(!Array.isArray(t))return;const e=[],n=[];let s;for(const i of t){if(typeof i!="object"||i===null)continue;const r=i,o=r.type,a=o==="image_url"?r.imageUrl:o==="audio_url"?r.audioUrl:o==="video_url"?r.videoUrl:void 0,l=(typeof a=="object"&&a!==null?a:void 0)?.attachment??r.attachment;if(typeof l=="object"&&l!==null){const u=l;if(typeof u.fileId=="string"&&(e.push({kind:o==="image_url"||o==="image"?"image":o==="video_url"||o==="video"?"video":o==="audio_url"||o==="audio"?"audio":"file",fileId:u.fileId,name:typeof u.name=="string"?u.name:void 0,mime:typeof u.mimeType=="string"?u.mimeType:void 0,size:typeof u.size=="number"?u.size:void 0}),o!=="text"))continue}if(r.type==="text"){const u=r.text;if(typeof u!="string")continue;for(const g of u.matchAll(qr)){const h=g[2]?.toLowerCase();if(g[1]==="/")s?.kind===h&&(s=void 0);else{const v=Mu.exec(g[3]??"")?.slice(1).find(m=>m!==void 0&&m!=="");s=v===void 0?void 0:{kind:h,path:v}}}const f=u.replaceAll(qr,"").trim();f!==""&&n.push(f);continue}const c=o==="image_url"||o==="video_url"||o==="audio_url"?bu(r):void 0;if(c!==void 0){e.push(Fr({kind:c.kind,url:c.url,mime:ga(c.url)},s?.kind===c.kind?s.path:void 0)),s=void 0;continue}if(r.type==="image"||r.type==="video"||r.type==="audio"){const u=r.source;typeof u=="object"&&u!==null&&(e.push(Fr(va(r.type,u),s?.kind===r.type?s.path:void 0)),s=void 0)}}if(e.length!==0)return{text:n.join(`
2
+ `),media:e}}const an=/^[A-Za-z]:[\\/]/,xi=/^\/[A-Za-z]:[\\/]/,As=/^\\\\/,Ms=/^~[\\/]/,Pu=/^[a-z][a-z\d+.-]*:/i,Eu=/^(?:https?|ftp|mailto|ms|app|blob|data|javascript|file):/i,Qi=/^\.?\.?[\\/]|^(?:[^/\\]+[/\\])*[^/\\]+\.[A-Za-z0-9]{1,10}(?:$|[^A-Za-z0-9])/u,Ou=/(?:^|[\\/])[^/\\\s.][^/\\\s]*\.[A-Za-z][A-Za-z0-9]{0,9}(?:$|[^A-Za-z0-9])/u;function Wn(t){return!Pu.test(t)||an.test(t)||/^file:\/\//i.test(t)?!1:t.includes("://")||Eu.test(t)}function Nr(t){return/^file:\/\//i.test(t)||an.test(t)||As.test(t)||Ms.test(t)||t.startsWith("/")||t.startsWith("./")||t.startsWith("../")||/[\\/]/u.test(t)||Qi.test(t)}function Du(t){const e=t.slice(Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"))+1);return/\.(?:md|markdown|mdx)$/i.test(e)}function wa(t){try{return decodeURIComponent(t)}catch{return t}}function Us(t){if(!/^\d+$/u.test(t))return;const e=Number(t);return Number.isSafeInteger(e)&&e>0?e:void 0}function Vs(t,e,n,s){const i=Us(e),r=n===void 0?void 0:Us(n),o=s===void 0?void 0:Us(s);return i===void 0||n!==void 0&&r===void 0||s!==void 0&&(o===void 0||o<i)?{path:t,invalidTarget:!0}:s===void 0?{path:t,line:i,column:r}:{path:t,line:i,column:r,endLine:o}}function Is(t){if(Wn(t))return{path:t};const e=/^(.*?):(\d+)(?::(\d+))?$/u.exec(t);if(e!==null&&Nr(e[1]))return Vs(e[1],e[2],e[3]);const n=t.indexOf("#");if(n===-1)return{path:t};const s=t.slice(0,n),i=t.slice(n+1);if(!Nr(s))return{path:t};const r=/^L(\d+)-L(\d+)$/u.exec(i);if(r!==null)return Vs(s,r[1],void 0,r[2]);const o=/^L(\d+)(?:C(\d+))?$/u.exec(i);return o!==null?Vs(s,o[1],o[2]):Du(s)&&i!==""?{path:s,heading:wa(i)}:/^L(?:\d|$)/u.test(i)?{path:s,invalidTarget:!0}:{path:t}}const ba="/__kiki-file/",_i="/__kiki-reference/";function qu(t){const e=Is(t).path;return/^file:\/\//i.test(e)?!0:Wn(e)?!1:an.test(e)||As.test(e)||/^\/[A-Za-z]:[\\/]/.test(e)||Ms.test(e)?!0:e.startsWith("/")?!1:Qi.test(e)}function Rv(t,e=!1){return qu(t)?`${e?_i:ba}${encodeURIComponent(t)}`:void 0}function Av(t){const e=t.startsWith(_i)?_i:ba;if(t.startsWith(e))try{return decodeURIComponent(t.slice(e.length))}catch{return}}const Fu=["/new","/s","/r","/rooms","/board","/cron","/memory","/activity","/personas","/settings","/usage","/capabilities"];function $r(t){const e=t.split(/[?#]/,1)[0];return e==="/"?!0:Fu.some(n=>e===n||e.startsWith(`${n}/`))}function Nu(t){if(!/^file:\/\//i.test(t))return;const e=t.indexOf("#"),n=t.indexOf("?"),s=[e,n].filter(o=>o>=0).toSorted((o,a)=>o-a)[0],i=s===void 0?t:t.slice(0,s),r=s===void 0?"":t.slice(s);try{const o=new URL(i);let a=decodeURIComponent(o.pathname);return/^\/[A-Za-z]:\//.test(a)&&(a=a.slice(1)),o.hostname!==""&&o.hostname!=="localhost"&&(a=`//${o.hostname}${a}`),a===""?void 0:{path:a,suffix:r}}catch{return}}function Sa(t,...e){const n=`${t.replace(/[\\/]+$/,"")}/${e.join("/")}`.replaceAll("\\","/"),s=an.test(n),i=s||n.startsWith("/"),r=n.startsWith("//"),o=r?2:s?1:0,a=[];for(const d of n.split("/"))if(!(d===""||d===".")){if(d===".."){a.length>o&&a.at(-1)!==".."?a.pop():i||a.push("..");continue}a.push(d)}return`${r?"//":i&&!s?"/":""}${a.join("/")}${s&&a.length===1?"/":""}`}function Mv(t,e){const n=xi.test(t)?t.slice(1):t;if(n===""||an.test(n)||As.test(n)||Ms.test(n)||n.startsWith("//")||n.startsWith("/")||e===void 0)return n;const s=e.trim();return s===""?n:Sa(xi.test(s)?s.slice(1):s,n)}function Pv(t,e,n=!1){const s=t.trim();if(s===""||s.startsWith("#")||s.startsWith("//")||$r(s))return;let i=Is(s),r=i.path;const o=Nu(r);if(o!==void 0&&(r=o.path,o.suffix!==""&&(i=Is(`${r}${o.suffix}`))),Wn(r))return;if(o===void 0&&!n&&(r=wa(r)),/^\/[A-Za-z]:[\\/]/.test(r)&&(r=r.slice(1)),an.test(r)||As.test(r)||Ms.test(r))return{...i,path:r};if(r.startsWith("/"))return $r(r)?void 0:{...i,path:r};if(e===void 0||e.trim()===""||!Qi.test(r))return;const a=/^\/[A-Za-z]:[\\/]/.test(e)?e.slice(1):e;return{...i,path:Sa(a,r)}}function $u(t){const e=[],n=/`+/gu;let s;for(const i of t.matchAll(n)){const r=i.index??0,o=i[0].length;s===void 0?s={start:r,length:o}:o===s.length&&(e.push([s.start,r+o]),s=void 0)}return s!==void 0&&e.push([s.start,t.length]),e}function ju(t,e,n){return n.some(([s,i])=>t<i&&e>s)}function Bu(t){let e=0,n=t.length;for(;e<n&&/[<([{"'“‘*_(【]/u.test(t[e]);)e+=1;for(;n>e&&/[)\]}>.,;:!?"'”’*_,。;:!?、)】]/u.test(t[n-1]);)n-=1;return{start:e,end:n}}function Lu(t){if(t===""||t.startsWith("-")||t.includes("@")||t.includes("=")||t.startsWith("//")||t.startsWith("/")&&!an.test(t)&&!xi.test(t)||Wn(t))return!1;const e=Is(t).path;return Wn(e)?!1:Ou.test(e)}function Ev(t){const e=[],n=$u(t),s=/[^\s<>"'()`\u005B\u005D{},;!?]+/gu;for(const i of t.matchAll(s)){const r=i.index??0,o=i[0],a=Bu(o),d=r+a.start,l=r+a.end;if(d>=l||ju(d,l,n))continue;const c=t.slice(d,l);Lu(c)&&e.push({start:d,end:l,target:c})}return e}function Ov(t){const e=t.replace(/[\\/]+$/,""),n=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return n===-1?e:e.slice(n+1)}function jr(t,e){if(t===void 0||e===void 0)return!0;const n=t.epoch;return n===void 0||n!==e.epoch||n.startsWith("cold:")?!0:t.seq>=e.seq}function ht(t){return t.kind==="turn"?`turn:${t.turnId}`:t.kind==="marker"?`marker:${t.markerId}`:`taskref:${t.refId}`}function Ti(t){return t.origin.kind==="other"&&t.message===void 0&&t.promptId===void 0&&t.startedAt===void 0}function Hu(t,e,n){const s=Ti(t),i=Ti(e);if(s&&e.startedAt!==void 0){const r=Br(t,e);return{turn:r,fromIncoming:!1,join:r.stepsPartial===!0?Lr(e,t):void 0}}if(i&&!s){if(t.stepsPartial!==!0)return{turn:t,fromIncoming:!1};const r=Br(e,t);return{turn:r,fromIncoming:!1,join:r.stepsPartial===!0?Lr(t,e):void 0}}if(e.stepsPartial===!0&&t.stepsPartial!==!0)return{turn:t,fromIncoming:!1};if(!n)return{turn:t,fromIncoming:!1};if(e.steps.length===0&&t.steps.length>0){const{steps:r,...o}=e;return{turn:ot(t,{...o,steps:t.steps,stepsPartial:t.stepsPartial,contentRefs:[...(t.contentRefs??[]).filter(d=>d.path[0]==="steps"),...(e.contentRefs??[]).filter(d=>d.path[0]!=="steps")]}),fromIncoming:!1}}if(e.stepsPartial===!0&&t.stepsPartial===!0){const r=new Map(t.steps.map(a=>[a.stepId,a]));for(const a of e.steps)r.set(a.stepId,a);return{turn:Ci(t,{...e,steps:[...r.values()].toSorted((a,d)=>a.ordinal-d.ordinal)}),fromIncoming:!0}}return{turn:Ci(t,e),fromIncoming:!0}}function Br(t,e){const n=new Map(e.steps.map(o=>[o.stepId,o]));for(const o of t.steps){const a=n.get(o.stepId);n.set(o.stepId,a===void 0?o:{...a,...o,ordinal:a.ordinal,frames:[...new Map([...a.frames,...o.frames].map(d=>[d.frameId,d])).values()]})}const s=e.contentRefs?.filter(o=>o.path.length===1&&o.path[0]==="steps")??[],r=e.steps.some((o,a)=>t.steps[a]?.stepId!==o.stepId)?[...s.map(o=>({...o,direction:"forward",offset:0})),...(e.contentRefs??[]).filter(o=>o.path[0]!=="steps"||o.path.length>1)]:[...(t.contentRefs??[]).filter(o=>o.path[0]==="steps"),...(e.contentRefs??[]).filter(o=>o.path[0]!=="steps")];return ot(t,{...t,origin:e.origin,prompt:e.prompt,promptId:e.promptId,message:e.message,delivery:e.delivery,presentation:e.presentation,attachmentIds:e.attachmentIds,startedAt:e.startedAt,stepsPartial:t.stepsPartial===!0||e.stepsPartial===!0?!0:void 0,steps:e.steps.length===0?t.steps:[...n.values()].toSorted((o,a)=>o.ordinal-a.ordinal),contentRefs:r})}function Ci(t,e){const n=Dt(t,e);return ot(n,{...n,steps:n.steps.map(s=>{const i=t.steps.find(r=>r.stepId===s.stepId);return i===void 0?s:{...s,frames:s.frames.map(r=>{const o=i.frames.find(a=>a.frameId===r.frameId);return o===void 0?r:Dt(o,r)})}})})}function Lr(t,e){const n=new Set(e.steps.map(i=>i.stepId));return t.steps.filter(i=>!n.has(i.stepId)).toSorted((i,r)=>i.ordinal-r.ordinal).at(-1)?.stepId??null}function zu(t,e,n){const s=n?e:t;if(t.kind!=="taskref"||e.kind!=="taskref"||s.kind!=="taskref")return s;const i=Wu(t.at,e.at);return i===s.at?s:{...s,at:i}}function Wu(t,e){if(t===void 0||t==="")return e;if(e===void 0||e==="")return t;const n=Date.parse(t),s=Date.parse(e);return Number.isNaN(s)?t:Number.isNaN(n)||s<n?e:t}function Ri(t,e,n){if(e)return{at:"turn",reason:"stale"};if(t.stepsPartial===!0)return Ti(t)?{at:"start",reason:"partial"}:n===null?{at:"start",reason:"partial"}:n!==void 0&&t.steps.some(s=>s.stepId===n)?{at:"between",afterStepId:n,reason:"partial"}:{at:"turn",reason:"partial"}}const xa="\0model-switch:";function ws(t){return t.startsWith(xa)}function _a(t){return`${xa}${t}`}function Dv(t,e,n){return e<0?e:n?.[_a(t)]?.queuePosition??e}function qv(t,e){const n=[],s=e.toSorted((i,r)=>i.queueIndex-r.queueIndex);for(const i of t){const r=i.queuePosition??n.length+1;for(;s.length>0&&s[0].queueIndex<r;)n.push({kind:"modelSwitch",operationId:s.shift().operationId});n.push({kind:"message",promptId:i.promptId})}for(const i of s)n.push({kind:"modelSwitch",operationId:i.operationId});return n}function Fv(t){return t.from===void 0||t.from!==t.to?"model":t.targetThinking===null||t.targetThinking!==void 0&&t.originalThinking!==void 0&&t.targetThinking!==t.originalThinking?"effort":t.mode==="direct"?"binding":t.mode}const Ta=/<system-reminder>([\s\S]*?)<\/system-reminder>/gi,Uu=/<\\\/system-reminder>/gi;function Ca(t){return t.replace(Uu,"</system-reminder>")}function Ji(t,e=!1){if(!e)return{text:t,reminders:[]};const n=t.trim();if(!/^<system-reminder>/i.test(n)||!/<\/system-reminder>$/i.test(n))return{text:t,reminders:[]};const s=[];let i=0;for(const r of n.matchAll(Ta)){if(n.slice(i,r.index).trim()!=="")return{text:t,reminders:[]};s.push(Ca(r[1]).trim()),i=r.index+r[0].length}return s.length===0||n.slice(i).trim()!==""?{text:t,reminders:[]}:{text:"",reminders:s}}function dn(t){if(t!==void 0){if(typeof t.payload=="object"&&t.payload!==null){const e=t.payload;if(typeof e.kind=="string")return dn(e)}return t}}function Qt(t){if(typeof t!="object"||t===null)return;const e=t.origin;if(!(typeof e!="object"||e===null))return dn(e)}const Vu=new Set(["injection","system_trigger","compaction_summary","hook_result","cron_job","cron_missed","task","background_task","thread_watch","retry"]),Ku=new Set(["injection","system_trigger","compaction_summary","hook_result","cron_job","cron_missed","task","thread_watch","retry","agent_message","system"]);function Ra(t){const e=dn(t);return e===void 0?!1:e.kind==="thread_watch"?!0:e.kind!=="peer_thread"?!1:e.notification===!0||(e.source?.name?.startsWith("thread-watch:")??!1)}function Gu(t){return t==="background_task"?"task":t!==void 0&&Ku.has(t)?t:"system"}function Qu(t){if(t!==void 0)return t.variant??t.name??t.skillName??t.commandName??t.pluginId}const Ju=/<bash-input>([\s\S]*?)<\/bash-input>/i,Yu=/<bash-stdout>([\s\S]*?)<\/bash-stdout>/i,Xu=/<bash-stderr>([\s\S]*?)<\/bash-stderr>/i,Aa=/<cron-fire\b[\s\S]*?<\/cron-fire>/gi,Ma=/<prompt>\s*([\s\S]*?)\s*<\/prompt>/i,Zu=/<script-output\b[^>]*>([\s\S]*?)<\/script-output>/gi,ef=/<hook_context>([\s\S]*?)<\/hook_context>/gi,tf=/<hook_result\b[^>]*>([\s\S]*?)<\/hook_result>/gi,Yi=/<notification\b([^>]*)>([\s\S]*?)<\/notification>/i,nf=/<notification\b([^>]*)>([\s\S]*?)<\/notification>/gi;function Pa(t){const e=Ma.exec(t)?.[1];return e!==void 0?e.trim():t.replace(/^<cron-fire\b[^>]*>\s*/i,"").replace(/\s*<\/cron-fire>$/i,"").replace(Zu,(s,i)=>ct(i).trim()).trim()}function sf(t){const e=[...t.matchAll(Aa)];if(e.length===0){const s=Ma.exec(t)?.[1];return s!==void 0?s.trim():t}const n=e.map(s=>Pa(s[0])).filter(s=>s!=="");return n.length>0?n.join(`
3
+
4
+ `):t}function rf(t){return/<hook_context>/i.test(t)?t.replace(ef,(e,n)=>ct(n).trim()).trim():t}function Ea(t){const e=Ji(t,!0);return e.reminders.length>0?e.reminders.join(`
5
+
6
+ `):t}function Oa(t){const e=Ea(t),n=/<hook_result\b/i.test(e)?e.replace(tf,(s,i)=>i.trim()).trim():e;return rf(n)}function ct(t){return t.replaceAll("&lt;","<").replaceAll("&gt;",">").replaceAll("&quot;",'"').replaceAll("&amp;","&")}function Et(t,e){const s=new RegExp(`\\b${e}\\s*=\\s*["']([^"']*)["']`,"i").exec(t)?.[1];return s===void 0||s===""||s==="unknown"?void 0:ct(s)}const of=/<output-preview\b([^>]*)>([\s\S]*?)<\/output-preview>/i,af=/<output-file\b([^>]*)>[\s\S]*?<\/output-file>/i,df=/<answer>([\s\S]*?)<\/answer>/i;function cf(t){try{const e=JSON.parse(t);if(typeof e!="object"||e===null||Array.isArray(e))return{};const n=e.answers;if(typeof n!="object"||n===null||Array.isArray(n))return{};const s={};for(const[r,o]of Object.entries(n))if(typeof o=="string")s[r]=o;else if(typeof o=="object"&&o!==null){const a=o;typeof a.text=="string"?s[r]=a.text:typeof a.option_id=="string"&&(s[r]=a.option_id)}const i=Object.keys(s);return{answers:i.length>0?s:void 0,outcome:i.length>0?"answered":"dismissed"}}catch{return{}}}function Bn(t,e){const n=Yi.exec(t),s=n?.[1]??"",i=(n?.[2]??t).trim(),r=Et(s,"id"),o=Et(s,"category"),a=Et(s,"type"),d=Et(s,"source_kind"),l=Et(s,"source_id")??e?.taskId,c=Et(s,"agent_id");let u,f;const g=[];let h;const v=i.split(`
7
+ `);for(let ee=0;ee<v.length;ee+=1){const re=v[ee],le=re.trim();if(u===void 0&&/^Title:\s*/i.test(le)){u=ct(le.replace(/^Title:\s*/i,"").trim());continue}if(f===void 0&&/^Severity:\s*/i.test(le)){f=ct(le.replace(/^Severity:\s*/i,"").trim());continue}if(ee===0&&u===void 0&&/^Background (?:process|agent|question|media|\S+) (?:completed|failed|timed_out|killed|lost|answered|dismissed)\b/i.test(le)){u=ct(le);continue}if(le==="Result data, not authorization or request acceptance."||/^<(?:output-preview|output-file|answer)\b/i.test(le))break;if((o==="thread"||d==="thread"||a?.startsWith("thread."))&&/^Latest output:\s*$/i.test(le)){const Oe=ct(v.slice(ee+1).join(`
8
+ `)).trim();Oe!==""&&(h=Oe);break}g.push(ct(re))}const m=g.join(`
9
+ `).trim()||void 0;let p=a==="task.completed"?"completed":a==="task.failed"?"failed":a==="task.timed_out"?"timed_out":a==="task.killed"?"killed":a==="task.lost"?"lost":a==="thread.attention"?"attention":a==="thread.watch_stopped"?"stopped":void 0;p===void 0&&u!==void 0&&(/\b(?:completed|answered|dismissed)\b/i.test(u)?p="completed":/\btimed_out\b/i.test(u)?p="timed_out":/\bkilled\b/i.test(u)?p="killed":/\blost\b/i.test(u)?p="lost":/\bcancelled\b/i.test(u)?p="cancelled":/\barchived\b/i.test(u)?p="archived":/\bdeleted\b/i.test(u)?p="deleted":/\bneeds attention\b/i.test(u)?p="attention":/\bwatch stopped\b/i.test(u)?p="stopped":/\bfailed\b/i.test(u)&&(p="failed"));let k,S,w,x;if(m!==void 0){const ee=/\bExit code:\s*(-?\d+|unavailable)\.\s*Duration:\s*(\d+|unknown)\s*ms\.$/i.exec(m),re=ee===null?m:m.slice(0,ee.index).trim();ee!==null&&(w=ee[1]==="unavailable"?null:Number(ee[1]),ee[2]!=="unknown"&&(x=Number(ee[2])));const le=/^The user answered "([\s\S]*)"\.$/i.exec(re),Oe=/^The user dismissed "([\s\S]*)" without answering\.$/i.exec(re);if(le!==null)k=le[1];else if(Oe!==null)k=Oe[1];else{const Ze=/^(.*?)\s+(completed|failed|timed_out|was stopped|lost)\.\s*Reason:\s*([\s\S]+)$/i.exec(re);if(Ze!==null)k=Ze[1]?.trim(),S=Ze[3]?.trim();else{const Je=/^(.*?)\s+(completed|failed|timed out|was stopped by user|was stopped|lost)\.$/i.exec(re);Je!==null&&(k=Je[1]?.trim())}}}const b=of.exec(i);let _=h,C,F,N;if(b!==null){const ee=b[1]??"";C=Et(ee,"truncated")==="true";const re=Et(ee,"bytes"),le=Et(ee,"total_bytes");re!==void 0&&/^\d+$/.test(re)&&(F=Number(re)),le!==void 0&&/^\d+$/.test(le)&&(N=Number(le));const Oe=(b[2]??"").trim().split(`
10
+ `);Oe.length>0&&/^(?:Truncated tail only; this is not the complete report\.|Final agent receipt\.|Process output\.|Partial output before termination; not a final result\.)$/.test(Oe[0].trim())&&Oe.shift(),_=ct(Oe.join(`
11
+ `)).trim()}const me=af.exec(i),V=me===null?void 0:Et(me[1]??"","path"),we=df.exec(i),ye=we?.[1]===void 0?void 0:ct(we[1].trim()),Fe=ye===void 0?{}:cf(ye),te=Fe.outcome??(u!==void 0&&/\bquestion answered\b/i.test(u)?"answered":u!==void 0&&/\bquestion dismissed\b/i.test(u)?"dismissed":void 0);if(!(r===void 0&&a===void 0&&l===void 0&&c===void 0&&u===void 0))return{id:r,category:o,type:a,sourceKind:d,sourceId:l,agentId:c,title:u,severity:f,body:m,description:k,status:p,stopReason:S,exitCode:w,durationMs:x,outputPreview:_,outputTruncated:C,outputBytes:F,totalBytes:N,outputFile:V,answerRaw:ye,answers:Fe.answers,questionOutcome:te}}function Da(t,e){if(t!==void 0){const s=[t.body,t.outputPreview!==void 0&&t.outputPreview!==""?t.outputPreview:void 0].filter(i=>i!==void 0&&i!=="");if(s.length>0)return s.join(`
12
+
13
+ `);if(t.title!==void 0&&t.title!=="")return t.title}const n=Yi.exec(e);return n===null?e:ct((n[2]??"").trim())}function lf(t,e){let n=t;const s=new Set(e);return s.has("cron_job")&&(n=n.replace(Aa,i=>Pa(i))),(s.has("thread_watch")||s.has("task"))&&(n=n.replace(nf,(i,r,o)=>{if(/\bcategory\s*=\s*["'](?:task|thread)["']/i.test(r)||/\btype\s*=\s*["'](?:task|thread)\./i.test(r)||/\btask_id\s*=/i.test(r)||/\bsource_kind\s*=\s*["'](?:background_task|task|thread)["']/i.test(r)){const a=Bn(i);if(a?.category==="thread"||a?.sourceKind==="thread"||a?.type?.startsWith("thread.")){const d=a.title,l=Da(a,i);return d!==void 0&&l!==d?`${d}
14
+ ${l}`:l}return ct(o.trim())}return i})),(s.has("injection")||s.has("system_trigger")||s.has("hook_result"))&&(n=n.replace(Ta,(i,r)=>Ca(r).trim())),s.has("hook_result")&&(n=Oa(n)),n.trim()}function uf(t){const e=Yi.exec(t);if(e===null)return;const n=e[1]??"";if(!/\bcategory\s*=\s*["']task["']/i.test(n)&&!/\btype\s*=\s*["']task\./i.test(n)&&!/\btask_id\s*=/i.test(n)&&!/\bsource_kind\s*=\s*["'](?:background_task|task)["']/i.test(n))return;const s=(e[2]??"").trim(),i=`${t.slice(0,e.index)}${t.slice(e.index+e[0].length)}`.trim();return s===""?i===""?void 0:i:i===""?s:`${i}
15
+
16
+ ${s}`}function ff(t,e){const n=Ju.exec(t),s=Yu.exec(t),i=Xu.exec(t);if(n===null&&s===null&&i===null)return;const r=n?.[1]===void 0?"":ct(n[1]).trim(),o=r===""?void 0:r,a=s?.[1]===void 0?"":ct(s[1]),d=i?.[1]===void 0?"":ct(i[1]),l=[a===""?void 0:a,d===""?void 0:d].filter(u=>u!==void 0).join(`
17
+ `),c=r.slice(0,40)||"shell";return{commandId:e!==void 0&&e!==""?`history-${e}-${c}`:`history-${c}`,command:o,output:l,isError:d!==""?!0:void 0}}const qa=/<skill-loaded\b([^>]*)>([\s\S]*?)(?:<\/skill-loaded>|$)/i;function Hr(t,e){const s=(e==="name"?/\bname\s*=\s*"([^"]*)"/i:/\bargs\s*=\s*"([^"]*)"/i).exec(t)?.[1];return s===void 0||s===""?void 0:ct(s)}function hf(t){const e=qa.exec(t);if(e===null)return;const n=Hr(e[1]??"","name");return n===void 0?void 0:{source:"skill",name:n,args:Hr(e[1]??"","args")}}function pf(t){const e=qa.exec(t);return e===null?t:(e[2]??"").trim()}function zr(t){if(t?.kind==="skill_activation")return{source:"skill",name:t.skillName??"skill",args:t.skillArgs};if(t?.kind==="plugin_command")return{source:"plugin",name:t.commandName??t.pluginId??"plugin",args:t.commandArgs}}function qt(t){const e=dn(t.origin),n=e?.kind;if(n==="unknown"||n==="external_thread"||n==="system_trigger"&&e?.name==="thread_create")return{lane:"peer",origin:e,text:t.text,presentation:t.presentation,reminders:[]};if(n==="merged"){const r=(e?.origins??[]).map(d=>qt({text:"",role:t.role,origin:d,subagentPromptAsUser:t.subagentPromptAsUser})),o=r.map(d=>d.lane),a=o.length>0&&o.every(d=>d==="you")?"you":o.some(d=>d==="you"||d==="peer"||d==="skill")?"peer":"system";if(a==="system"){const d=r.map(f=>f.systemVariant).filter(f=>f!==void 0),c=new Set(d).size===1?d[0]:"system",u=lf(t.text,d);return{lane:"system",origin:e,text:u,presentation:t.presentation,reminders:[],systemVariant:c,taskNotification:c==="thread_watch"||c==="task"?Bn(t.text,e):void 0}}return{lane:a,origin:e,text:t.text,presentation:t.presentation,reminders:[]}}const s=Ji(t.text,n==="injection");if(Ra(e)){const r=Bn(s.text,e);return{lane:"system",origin:e,text:Da(r,s.text),reminders:s.reminders,systemVariant:"thread_watch",taskNotification:r}}const i=n==="task"||n==="background_task"?uf(s.text):void 0;if(i!==void 0)return{lane:"system",origin:e,text:i,reminders:s.reminders,systemVariant:"task",taskNotification:Bn(s.text,e)};if(n==="user"||t.subagentPromptAsUser===!0&&n==="system_trigger"&&e?.name==="subagent")return{lane:"you",origin:e,text:s.text,presentation:t.presentation,reminders:s.reminders};if(n==="peer_thread"||n==="bridged_peer"||n==="agent_message"||n==="branch_fold"||n==="room_message"&&e?.targeted===!0)return{lane:"peer",origin:e,text:s.text,presentation:t.presentation,reminders:s.reminders};if(n==="skill_activation"||n==="plugin_command")return{lane:"skill",origin:e,text:pf(s.text),reminders:s.reminders,userInput:e?.trigger!=="user-slash"?void 0:n==="skill_activation"?e.userInput:e.commandName===void 0?void 0:`/${e.commandName}${e.commandArgs?` ${e.commandArgs}`:""}`,skill:e?.skillName===void 0&&e?.commandName===void 0?hf(s.text)??zr(e):zr(e)};if(n==="shell_command"){const r=ff(t.text,t.id)??{commandId:`shell-${t.id??e?.phase??"cmd"}`,command:void 0,output:s.text,isError:e?.isError===!0?!0:void 0};return{lane:"shell",origin:e,text:s.text,reminders:s.reminders,shell:r}}if(n!==void 0&&Vu.has(n)){const r=Gu(n);return{lane:"system",origin:e,text:n==="cron_job"?sf(s.text):n==="hook_result"?Oa(s.text):n==="system_trigger"?Ea(s.text):s.text,reminders:s.reminders,systemVariant:r,taskNotification:r==="task"?Bn(s.text,e):void 0}}return n!==void 0?{lane:"system",origin:e,text:s.text,reminders:s.reminders,systemVariant:"system"}:t.role==="system"?{lane:"system",origin:e,text:s.text,reminders:s.reminders,systemVariant:"system"}:t.role==="user"||t.role===void 0?{lane:"you",origin:e,text:s.text,presentation:t.presentation,reminders:s.reminders}:{lane:"system",origin:e,text:s.text,reminders:s.reminders,systemVariant:"system"}}function mf(t){return(t?.spans??[]).flatMap(e=>e.kind!=="attachment"||e.attachment===void 0?[]:[{kind:"file",...e.attachment}])}function Wr(t){let e=t.replaceAll(/[\\/:*?"<>|]/g,"_").replaceAll(/[\u0000-\u001F\u007F]/g,"").replace(/^\.+/,"").trim().replace(/[ .]+$/u,"").slice(0,100);return/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(e)&&(e=`_${e}`),e.length>0?e:"attachment"}function gf(t){const e=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return e>=0?t.slice(e+1):t}function Ur(t){return t.replace(/\.[^./\\]*$/u,"")}function Vr(t){if(t===void 0)return;const e=t.toLowerCase();if(e.startsWith("image/"))return"image";if(e.startsWith("video/"))return"video";if(e.startsWith("audio/"))return"audio"}function vf(t,e){if(t===void 0||t===""||t.startsWith("inline:")||t.startsWith("inline-content:")||t.startsWith("blobref:"))return!1;if(e.startsWith(`${t}-`)||e===`${t}.wav`)return!0;const n=t.replace(/[^A-Za-z0-9_-]/gu,"_").slice(0,120)||"media";return e===`${n}.wav`}function Kr(t,e){if(t===void 0||e===void 0)return!1;const n=Wr(t).toLowerCase(),s=Wr(e).toLowerCase();return n===s||Ur(n)===Ur(s)}function Fa(t,e){const n=mf(e);if(n.length===0)return t??[];const s=[...t??[]],i=new Set,r=new Set,o=new Set,a=[];for(const d of s)d.path!==void 0&&d.path!==""&&o.add(d.path);for(const d of n){const l=d.path===void 0?"":gf(d.path),c=Vr(d.mime),u=d.mime?.toLowerCase()==="audio/wav"||l.toLowerCase().endsWith(".wav");let f=s.findIndex(g=>vf(g.fileId,l));if(f<0&&c!==void 0&&(f=s.findIndex((g,h)=>(c==="audio"&&u?r:i).has(h)?!1:(g.kind===c||g.kind==="file"&&g.detail!==void 0&&(g.mime===void 0||Vr(g.mime)===c))&&Kr(g.name,d.name)),f<0)){const g=s.flatMap((h,v)=>(c==="audio"&&u?r:i).has(v)?[]:h.kind===c&&h.name===void 0||h.kind==="file"&&h.detail!==void 0&&h.name===void 0&&h.mime===void 0?[v]:[]);g.length===1&&(f=g[0])}if(f<0&&(f=s.findIndex((g,h)=>!i.has(h)&&g.kind==="file"&&Kr(g.name,d.name)&&(g.size===void 0||d.size===void 0||g.size===d.size))),f>=0){const g=s[f],h=g.kind==="file"&&g.detail!==void 0&&c!==void 0?c:g.kind;h==="audio"&&u&&i.has(f)?r.add(f):i.add(f);const v=g.fileId!==void 0||g.blobHash!==void 0||g.detail!==void 0,m=h==="audio"&&u&&g.mime!==void 0&&g.mime.toLowerCase()!=="audio/wav";s[f]={...g,kind:h,name:g.name??d.name,mime:m?g.mime:g.mime??d.mime,size:g.size??d.size,path:v?g.path:g.path??d.path},d.path!==void 0&&d.path!==""&&o.add(d.path);continue}if(d.path!==void 0&&d.path!==""){if(o.has(d.path))continue;o.add(d.path)}a.push(d)}return[...s,...a]}function yf(t,e){const n=[];let s=0,i=0;for(let r=0;r<t.length;r+=1){const o=t[r];if(o===void 0||o.type!=="text")continue;i++>0&&(s+=1);const a=e?.find(c=>c.kind==="text"&&c.path.length===3&&c.path[0]==="content"&&c.path[1]===r&&c.path[2]==="text"),d=a!==void 0?Math.max(o.text.length,a.total):o.text.length,l=zn(o.presentation);for(const c of l?.spans??[]){const u=Math.max(0,c.start),f=Math.min(o.text.length,d,c.end);f>u&&n.push({...c,start:s+u,end:s+f})}s+=o.text.length}return n.length===0?void 0:{spans:n}}function dt(t,e){const n=[];for(const i of t)i.type==="text"&&n.push(i.text);const s=yf(t,e);return{text:n.join(`
18
+ `),presentation:s,media:Fa(Au(t),s)}}function Na(t){return typeof t=="object"&&t!==null?t:void 0}function kf(t){const e=t?.summary;if(typeof e=="string"&&e!=="")return e;const n=Na(t?.result)?.summary;return typeof n=="string"&&n!==""?n:void 0}function If(t){const e=new Map,n=new Map;let s;for(const i of t){if(i.kind==="turn"&&s!==void 0&&(e.set(s,"hidden"),s=void 0),i.kind!=="marker"||i.marker!=="compaction"||i.markerId===void 0)continue;const r=Na(i.payload),o=r?.phase;if(o==="started"){s!==void 0&&e.set(s,"hidden"),s=i.markerId,e.set(i.markerId,"pending");continue}if(o==="blocked"){e.set(i.markerId,"hidden");continue}s!==void 0&&(e.set(s,"hidden"),s=void 0);const a=kf(r);if(a===void 0)continue;const d=r?.type==="context.apply_compaction",l=r?.time,c=d?`${typeof l=="number"||typeof l=="string"?l:i.markerId}\0${a}`:a,u=n.get(a),f=n.get(c)??(d&&u?.durable?void 0:u);if(f===void 0){n.set(c,{markerId:i.markerId,durable:d}),d&&n.set(a,{markerId:i.markerId,durable:d});continue}if(d&&!f.durable){e.set(f.markerId,"hidden"),n.set(c,{markerId:i.markerId,durable:d}),n.set(a,{markerId:i.markerId,durable:d});continue}e.set(i.markerId,"hidden")}return e}function wf(t,e){return`${t}:${e}`}function Ai(t){return{version:0,transcriptResetVersion:0,sessionId:t,session:void 0,blocks:[],cursor:{seq:0,epoch:void 0},busy:!1,turnStartedAt:void 0,turnFirstTokenAt:void 0,turnTail:void 0,turnRetry:void 0,pendingInteraction:"none",activePromptId:void 0,abortablePromptId:void 0,abortableTurnId:void 0,queuedPromptIds:[],promptQueueHold:void 0,queuedPromptMeta:{},durableIngress:[],model:void 0,profile:void 0,thinkingEffort:void 0,permissionMode:void 0,planMode:!1,goal:void 0,goalUpdatedAt:void 0,contextTokens:void 0,maxContextTokens:void 0,contextBreakdown:void 0,usage:void 0,turnExecutions:{},todos:[],todoNotes:void 0,todoNotesMeta:void 0,todoNotesStatus:void 0,todoRead:void 0,tasks:[],snapshotSubagents:[],globalCoverage:void 0,detailLoads:{},resyncing:!1,resyncFailed:!1,resyncAttempt:0,loaded:!1,transcriptReady:!1,loadError:void 0,hasMoreHistory:!1,incompleteTurnIds:[],nonUserTurnIds:[],historyCoverageKind:void 0,historyRead:void 0,oldestMessageId:void 0,loadingOlder:!1,fetchedOlder:!1,olderError:void 0}}function wn(t,e){return{...t,...e,version:t.version+1}}function bf(t,e,n){let s=0;for(;s<t.length;){const i=t.indexOf('"',s);if(i===-1)return null;const r=Un(t,i,!1);if(!r)return null;s=r.end;let o=Kt(t,r.end);if(t[o]!==":")continue;if(o=Kt(t,o+1),r.value!==e){s=o;continue}if(t[o]!=='"')return null;const a=Un(t,o,n);return a===null?null:{value:a.value,complete:a.complete}}return null}function Un(t,e,n){if(t[e]!=='"')return null;let s="",i=e+1;for(;i<t.length;){const r=t[i];if(r==="\\"){if(i+1>=t.length)return n?{value:Ks(s,!1),end:t.length,complete:!1}:null;s+=t.slice(i,i+2),i+=2;continue}if(r==='"')return{value:Ks(s,!0),end:i+1,complete:!0};s+=r,i+=1}return n?{value:Ks(s,!1),end:t.length,complete:!1}:null}function Ks(t,e){let n=t;e||(n=n.replace(/\\u[0-9a-fA-F]{0,3}$/,""),n.endsWith("\\")&&(n=n.slice(0,-1)));for(let s=0;s<8;s+=1)try{return JSON.parse(`"${n}"`)}catch{if(n.length===0)break;n=n.slice(0,-1)}return n.replaceAll("\\n",`
19
+ `).replaceAll("\\r","\r").replaceAll("\\t"," ").replaceAll('\\"','"').replaceAll("\\\\","\\")}function Kt(t,e){let n=e;for(;n<t.length&&/\s/.test(t[n]??"");)n+=1;return n}function $a(t,e){if(t[Kt(t,0)]!=="{")return;let n=0;for(let s=0;s<t.length;s+=1){const i=t[s];if(i==='"'){const r=Un(t,s,!1);if(r===null)return;const o=Kt(t,r.end);if(n===1&&r.value===e&&t[o]===":")return Kt(t,o+1);s=r.end-1}else i==="{"||i==="["?n+=1:(i==="}"||i==="]")&&(n-=1);if(n===0&&i==="}")break}}function ja(t,e){const n=$a(t,e);if(n===void 0||t[n]!=="[")return null;const s=[];let i=Kt(t,n+1);for(;i<t.length&&t[i]!=="]";){const r=i;let o=0;for(;i<t.length;){const d=t[i];if(o===0&&(d===","||d==="]"))break;if(d==='"'){if(i=Un(t,i,!1)?.end??t.length,o===0)break;continue}if(i+=1,d==="{"||d==="[")o+=1;else if((d==="}"||d==="]")&&(o-=1,o===0))break}const a=t.slice(r,i).trim();if(a!==""&&s.push(a),i=Kt(t,i),t[i]!==",")break;i=Kt(t,i+1)}return s}function Sf(t,e,n,s,i){if(!Number.isSafeInteger(n)||n<0)return null;const r=ja(t,e)?.[n];if(r===void 0)return null;const o=$a(r,s);if(o===void 0||r[o]!=='"')return null;const a=Un(r,o,i);return a===null?null:{value:a.value,complete:a.complete}}function xf(t,e){return e===void 0?bf(t,"text",!0)?.value??"":Sf(t,"messages",e,"text",!0)?.value??""}function Xe(t){if(typeof t=="string")try{return Xe(JSON.parse(t))}catch{return}return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:void 0}function Pe(t){return typeof t=="string"?t:void 0}function Mi(t){return Array.isArray(t)?t.filter(e=>typeof e=="string"):[]}function _f(t){return Array.isArray(t)?t.flatMap(e=>{const n=Xe(e),s=Pe(n?.blob_id),i=Pe(n?.path);return s===void 0||i===void 0?[]:[{blobId:s,sourceId:Pe(n?.source_id),path:i,title:Pe(n?.title),mimeType:Pe(n?.mime_type),size:typeof n?.size=="number"?n.size:void 0,kind:Pe(n?.kind)}]}):[]}const Tf={delivered:"delivered",partial:"partial",unsupported:"unsupported",failed:"failed",unknown:"unknown"};function Cf(t){return Array.isArray(t)?t.flatMap(e=>{const n=Xe(e),s=Pe(n?.channel_id);if(s===void 0)return[];const i=Pe(n?.status),r=Mi(n?.message_ids),o=Mi(n?.unsupported);return[{channelId:s,status:i===void 0?"unknown":Tf[i]??"unknown",messageIds:r.length===0?void 0:r,unsupported:o.length===0?void 0:o,detail:Pe(n?.detail)}]}):[]}function Rf(t){return t.some(e=>e.channelId==="internal"&&e.status==="delivered")?"here":t.some(e=>e.status==="delivered"||e.status==="partial")?"elsewhere":t.some(e=>e.status==="unknown")?"unconfirmed":"nowhere"}function Ba(t){if(t.toolCallId.startsWith("external:")||t.name!=="SendMessage")return[];const e=Xe(t.args)??Xe(t.argsText),n=e?.messages,s=Array.isArray(n)?n:ja(t.argsText,"messages")?.map((o,a)=>Xe(o)??(o.startsWith("{")?{text:xf(t.argsText,a)}:void 0));if(s==null){const o=Gr(t);return o===void 0?[]:[o]}const i=t.outputPending===!0?void 0:Xe(t.output),r=Array.isArray(i?.messages)?i.messages:[];return s.flatMap((o,a)=>{const d=Xe(o);if(d===void 0)return[];const l=r.filter(g=>Xe(g)?.index===a),c=l.length===1?Xe(l[0]):void 0,u={...t,id:`${t.id}:message:${a}`,args:{to:e?.to,channel:e?.channel,channels:e?.channels,voice_mode:e?.voice_mode,tts:e?.tts,...d},argsText:"",output:c===void 0?void 0:JSON.stringify(c)},f=Gr(u);return f===void 0?[]:[{...f,itemIndex:a,sourceTool:t}]})}function Gr(t){if(t.toolCallId.startsWith("external:")||t.name!=="SendMessage")return;const e=Xe(t.args)??Xe(t.argsText),n=t.outputPending===!0?void 0:Xe(t.output),s=Pe(n?.message_id),i=t.status==="done"&&t.isError!==!0&&s!==void 0,r=Cf(n?.channels),o=r.length===0?void 0:Rf(r),a=Pe(n?.delivery),d=t.status==="running"?"sending":t.status==="stopped"||a==="cancelled"?"cancelled":t.status==="done"&&t.isError!==!0&&t.outputPending===!0?"pending":!i||o==="nowhere"||a==="undeliverable"||a==="not_sent"?"failed":o==="unconfirmed"||a==="pending"?"pending":"sent",l=d==="sent"||d==="sending"||d==="pending",c=Xe(e?.tts),u=Pe(c?.mode)??Pe(e?.voice_mode),f=n?.voice_only===!0||n===void 0&&u==="only",g=Pe(e?.text),h=u==="append"?Pe(c?.text):void 0,v=f?"":g!==void 0&&g.trim().length>0?g:h??g??"",m=typeof t.output=="string"&&Xe(t.output)===void 0?t.output.trim():void 0,p=d==="failed"?Pe(n?.error)??Pe(n?.detail)??(m===void 0||m===""?void 0:m):void 0,k=Xe(n?.sender),S=Xe(n?.handoff),w=Pe(S?.target_persona_id),x=Pe(S?.target_session_id),b=Pe(S?.target_name);return{kind:"message",id:t.id,toolCallId:t.toolCallId,messageId:s,origin:"send_message",status:d,text:l?v:"",to:Pe(e?.to),replyTo:Pe(e?.reply_to),attachments:d==="sent"?_f(n?.attachments):[],deliveredTo:d==="sent"?Mi(n?.delivered_to):[],channels:r.length===0?void 0:r,reached:o===void 0||o==="nowhere"?void 0:o,personaId:Pe(k?.persona_id),senderName:Pe(k?.name),sourceSessionId:Pe(k?.session_id),handoff:d==="sent"&&w!==void 0&&x!==void 0&&b!==void 0?{targetPersonaId:w,targetSessionId:x,targetName:b,messageId:Pe(S?.message_id)}:void 0,startedAt:t.startedAt,turnId:t.turnId,failureDetail:p,sourceTool:t}}function Af(t){if(t.kind==="user")return t.promptOutcome?.status==="failed"?t.turnId:void 0;if(t.kind==="notice"&&t.i18n?.key==="notice.turnFailedDetail")return t.turnId}function Mf(t,e){const n=t.createdAt===void 0?Number.NaN:Date.parse(t.createdAt);return{kind:"message",id:`ordinary-final-${t.id}`,messageId:t.messageId,origin:"ordinary_final",status:"sent",text:t.text,attachments:[],deliveredTo:[],startedAt:Number.isNaN(n)?void 0:n,turnId:e,sourceBlock:t}}function Qr(t){return t.kind==="subagent"?t.parentTurnId:t.kind==="question"||t.kind==="approval"?t.request.turn_id===void 0?void 0:`t${t.request.turn_id}`:t.turnId}function Pf(t){return t.kind==="tool"?t.name==="SendMessage"&&!t.toolCallId.startsWith("external:"):t.kind==="message"&&t.origin==="send_message"&&t.toolCallId!==void 0&&!t.toolCallId.startsWith("external:")}const Ef=new Set(["spawned","completed","failed","cancelled"]);function Of(t){const e=Xe(t.args)??Xe(t.argsText),n=Pe(e?.description)?.trim();return n!==void 0&&n!==""?n:void 0}function Df(t){const e=new Set,n=new Set,s=new Map,i=new Map,r=new Set,o=new Set;for(const g of t){if(g.kind==="subagent-event"){g.event==="sent"&&g.anchorToolCallId!==void 0&&r.add(g.anchorToolCallId),g.event==="resumed"&&g.anchorToolCallId!==void 0&&o.add(g.anchorToolCallId);continue}g.kind==="subagent"&&(e.add(g.subagentId),s.set(g.subagentId,(s.get(g.subagentId)??0)+1),g.taskId!==void 0&&g.taskId!==""&&n.add(g.taskId),g.parentToolCallId!==void 0&&g.parentToolCallId!==""&&i.set(g.parentToolCallId,g.id))}if(e.size===0&&r.size===0&&o.size===0)return{blocks:t,absorbedDurationByBlockId:new Map};const a=new Map,d=new Map,l=new Map,c=(g,h)=>{const v=Of(g);if(v!==void 0){h!==void 0&&!a.has(h)&&a.set(h,v);for(const m of g.agentRefs??[])d.has(m.agentId)||d.set(m.agentId,v)}h!==void 0&&g.durationSource==="frame"&&g.durationMs!==void 0&&l.set(h,(l.get(h)??0)+g.durationMs)},u=[];for(const g of t){if(g.kind==="subagent-event"){if(g.event==="resumed"&&g.anchorToolCallId!==void 0&&i.has(g.anchorToolCallId))continue;if(e.has(g.subagentId)&&Ef.has(g.event)){const h=`subagent-event-${g.subagentId}-${g.event}-`;if(g.id.startsWith(h)){const v=g.id.slice(h.length);if(v!==""&&n.size>0&&(s.get(g.subagentId)??0)>1){if(n.has(v))continue}else continue}else continue}u.push(g);continue}if(g.kind==="tool"&&g.status!=="error"&&g.isError!==!0){const h=i.get(g.toolCallId);if(h!==void 0){c(g,h);continue}if(g.status==="done"&&(r.has(g.toolCallId)||o.has(g.toolCallId)))continue;const v=g.agentRefs??[];if(v.length>0&&v.every(m=>e.has(m.agentId)&&(s.get(m.agentId)??0)<=1)){const m=t.find(p=>p.kind==="subagent"&&p.subagentId===v[0].agentId);c(g,m?.id);continue}}u.push(g)}return{blocks:u.map(g=>{if(g.kind!=="subagent"||g.description!==void 0&&g.description.trim()!=="")return g;const h=a.get(g.id)??d.get(g.subagentId);return h===void 0?g:{...g,description:h}}),absorbedDurationByBlockId:l}}function qf(t,e,n){const s={tools:0,reads:0,commands:0,thinking:0,subagents:0,memories:0},i=new Set,r=new Map;let o=0,a=!1,d;for(const c of t)if(c.kind==="tool"){s.tools+=1;const u=c.toolCallId.startsWith("external:");(u?c.display?.kind==="file_io"&&c.display.operation==="read":c.name==="Read")&&(s.reads+=1),(u?c.display?.kind==="command":c.name==="Bash")&&(s.commands+=1),!u&&c.name==="MemoryWrite"&&c.status==="done"&&c.isError!==!0&&(s.memories+=1),(c.status==="error"||c.isError===!0)&&(o+=1),c.status==="running"&&(a=!0),c.durationSource==="frame"&&c.durationMs!==void 0&&(d=(d??0)+c.durationMs);for(const f of c.agentRefs??[])i.add(f.agentId)}else if(c.kind==="shell")s.commands+=1,c.done||(a=!0),c.isError===!0&&(o+=1);else if(c.kind==="thinking")s.thinking+=1,c.streaming&&(a=!0);else if(c.kind==="assistant")c.streaming&&(a=!0);else if(c.kind==="subagent"){i.add(c.subagentId),c.status==="running"&&(a=!0),c.status==="failed"&&(o+=1);const u=n?.get(c.id);u!==void 0&&(d=(d??0)+u)}else if(c.kind==="subagent-event"){if(i.add(c.subagentId),c.event==="sent"){const u=r.get(c.subagentId);u===void 0?r.set(c.subagentId,{subagentId:c.subagentId,name:c.name,count:1}):r.set(c.subagentId,{...u,count:u.count+1})}}else c.kind==="notice"&&c.tone==="danger"&&(o+=1);s.subagents=i.size;const l=r.size>0?[...r.values()]:void 0;return{kind:"activity-summary",id:`activity-${t[0].id}`,turnId:e,members:t,counts:s,running:a,failed:o,durationMs:d,sentMessages:l}}function Ff(t){return t.taskRef!==void 0||t.id.startsWith("agent-taskref-")}function Nf(t){for(let e=t.length-1;e>=0;e-=1){const n=t[e];if(n?.kind==="notice"){if(n.compactionPhase==="completed"||n.i18n?.key==="transcript.marker.compaction"||n.i18n?.key==="transcript.marker.compactionSummarize"||n.i18n?.key==="transcript.marker.compactionFresh")return;if(n.compactionPhase==="failed"||n.compactionFailure!==void 0||n.i18n?.key==="transcript.marker.compactionFailed")return n.id}}}function $f(t,e){return Ff(t)?!1:t.compactionPhase!==void 0?t.id===e:t.tone==="danger"||t.reasonCodes?.some(n=>/cancel|stop|fail|delivery/.test(n))===!0}function Nv(t,e={}){const n=[];let s=[],i;const r=new Set(e.completedTurnIds??[]),o=[],a=new Set,d=new Set,l=new Set(e.failedTurnIds??[]),c=new Set,u=new Map,f=Nf(t);for(const b of t){const _=Qr(b),C=Af(b);C!==void 0&&l.add(C),b.kind==="user"&&b.promptOutcome?.status==="failed"&&b.turnId!==void 0&&c.add(b.turnId),b.kind==="notice"&&b.i18n?.key==="notice.turnFailedDetail"&&b.turnId!==void 0&&c.add(b.turnId),_!==void 0&&!a.has(_)&&(a.add(_),o.push(_)),_!==void 0&&Pf(b)&&d.add(_),b.kind==="assistant"&&b.text.trim()!==""&&b.turnId!==void 0&&u.set(b.turnId,b)}const g=new Map,h=new Set;for(const b of o){const _=u.get(b);_===void 0||!r.has(b)||d.has(b)||l.has(b)||_.streaming||_.stopped===!0||(g.set(b,Mf(_,b)),h.add(_.id))}const v=b=>{if(b===void 0||!r.has(b))return;const _=g.get(b);if(_!==void 0){n.push(_);return}if(l.has(b)){c.has(b)||n.push({kind:"notice",id:`message-turn-failed-${b}`,turnId:b,text:"轮次失败",tone:"danger",i18n:{key:"notice.turnFailedDetail",params:{detail:""}},reasonCodes:["message.turn_failed"]});return}d.has(b)||u.get(b)===void 0||n.push({kind:"notice",id:`message-no-reply-${b}`,turnId:b,text:`${e.personaName??""} 没有回复 · 查看过程`.trim(),tone:"neutral",i18n:{key:"message.noReply",params:{name:e.personaName??""}},reasonCodes:["message.no_reply"]})},m=()=>{s.length>0&&n.push(qf(s,i,x)),s=[],i=void 0};let p;const k=new Set;for(const b of t)b.kind==="question"&&b.request.tool_call_id!==void 0&&b.request.tool_call_id!==""&&k.add(b.request.tool_call_id);const S=t.flatMap(b=>{if(b.kind!=="tool")return[b];if(b.status!=="error"&&b.isError!==!0&&k.has(b.toolCallId))return[];const _=Ba(b);return _.length===0?[b]:_}),{blocks:w,absorbedDurationByBlockId:x}=Df(S);for(const b of w){const _=Qr(b);if(_!==void 0&&p!==void 0&&_!==p&&(m(),v(p)),_!==void 0&&(p=_),h.has(b.id))continue;b.kind==="user"||b.kind==="message"||b.kind==="question"||b.kind==="approval"||b.kind==="notice"&&$f(b,f)?(m(),n.push(b)):(s.length>0&&_!==void 0&&i!==void 0&&i!==_&&m(),i===void 0&&_!==void 0&&(i=_),s.push(b))}return m(),v(p),n}function $v(t){if(!(t.greeting===void 0||t.greeting.trim()===""))return{kind:"message",id:`persona-greeting-${t.id}`,messageId:`persona-greeting-${t.id}`,origin:"persona_greeting",status:"sent",text:t.greeting,attachments:[],deliveredTo:["user"],personaId:t.id,senderName:t.name}}function Xi(t,e){if(typeof e!="object"||e===null||Array.isArray(e))return;const n=e,s={};for(const i of t){const r=n[i.id]??n[i.question];if(typeof r=="string"){s[i.id]=r;continue}const o=tl.safeParse(r);if(!o.success)continue;const a=o.data,d=l=>i.options.find(c=>c.id===l)?.label;switch(a.kind){case"single":{const l=d(a.option_id);l!==void 0&&(s[i.id]=l);break}case"multi":case"multi_with_other":{const l=a.option_ids.map(d);if(l.some(c=>c===void 0))break;s[i.id]=[...l,...a.kind==="multi_with_other"?[a.other_text]:[]].join(", ");break}case"other":s[i.id]=a.text;break}}return Object.keys(s).length===0?void 0:s}function jf(t,e){return{agent_id:t,items:e.items,interactions:Array.isArray(e.interactions)?e.interactions:[...e.interactions.values()],attachments:Array.isArray(e.attachments)?e.attachments:[...e.attachments.values()],meta:e.meta,prompts:Array.isArray(e.prompts)?e.prompts:[...e.prompts.values()],tasks:Array.isArray(e.tasks)?e.tasks:[...e.tasks.values()]}}const Bf=new Set(["directive","renew","rebuild","history","progress"]);function Lf(t){if(typeof t!="object"||t===null)return;const e=t,n=e.kind;if(typeof n!="string"||!Bf.has(n))return;const s=Array.isArray(e.triggers)?e.triggers.filter(o=>typeof o=="string"):[],i=typeof e.epoch=="number"&&Number.isFinite(e.epoch)?e.epoch:void 0,r=typeof e.userTurn=="string"&&e.userTurn!==""?e.userTurn:void 0;return{kind:n,triggers:s,epoch:i,userTurn:r}}function La(t,e,n,s,i,r){const o=Lf(i?.disclosure);return n.map((a,d)=>({kind:"system-reminder",id:`reminder-${t}-${d}`,contentSource:r,text:a,createdAt:e,turnId:s,variant:i?.variant,ownerPromptId:i?.ownerPromptId,disclosure:i?.disclosure,category:o}))}function Ha(t){if(typeof t!="object"||t===null)return;const e=t.via;if(typeof e!="object"||e===null)return;const{client:n,channel:s}=e;return typeof n=="string"&&n!==""&&(s==="owner"||s==="terminal")?{client:n,channel:s}:void 0}function vn(t){const{classified:e}=t,n=[];switch(e.lane){case"you":case"peer":if(e.text!==""||t.media!==void 0&&t.media.length>0||t.contentPending===!0){const s=t.userMessageId??t.clientRequestId??t.id;n.push({kind:"user",id:`user-${s}`,contentSource:t.contentSource,contentPending:t.contentPending,promptTextParts:t.promptTextParts,sourceOrigin:e.origin,via:Ha(e.origin),text:e.text,presentation:e.presentation??t.presentation,media:t.media!==void 0&&t.media.length>0?t.media:void 0,createdAt:t.createdAt,promptId:t.promptId,userMessageId:t.userMessageId,clientRequestId:t.clientRequestId,promptStatus:t.promptStatus,turnId:t.turnId,agentMessage:e.origin?.kind==="agent_message"?{senderAgentId:e.origin.senderAgentId,senderTaskName:e.origin.senderTaskName}:void 0,bridgedPeer:e.origin?.kind==="bridged_peer"?{source:e.origin.source,sourceHomeId:e.origin.sourceHomeId,targetHomeId:e.origin.targetHomeId,bridgeId:e.origin.bridgeId,revision:e.origin.revision,location:e.origin.location,messageId:e.origin.messageId}:void 0,peerThread:e.origin?.kind==="peer_thread"?{hostId:e.origin.source?.hostId,workspaceId:e.origin.source?.workspaceId,sessionId:e.origin.source?.sessionId,personaId:e.origin.source?.personaId,senderName:e.origin.source?.name,messageId:e.origin.messageId}:void 0,branchFold:e.origin?.kind==="branch_fold"&&typeof e.origin.branchId=="string"?{foldId:e.origin.foldId,branchId:e.origin.branchId,branchTitle:e.origin.branchTitle,asks:e.origin.asks,throughTurnId:e.origin.throughTurnId,done:e.origin.done}:void 0})}break;case"skill":{e.userInput!==void 0&&n.push(...vn({...t,classified:{lane:"you",origin:e.origin,text:e.userInput,reminders:[]}}));const s=e.skill??{source:"skill",name:"skill",args:void 0};n.push({kind:"skill",id:`skill-${t.id}`,contentSource:t.contentSource,source:s.source,name:s.name,args:s.args,text:e.text,createdAt:t.createdAt,turnId:t.turnId});break}case"shell":{const s=e.shell??{commandId:t.id,command:void 0,output:e.text,isError:void 0};n.push({kind:"shell",id:`shell-${s.commandId}`,commandId:s.commandId,command:s.command,output:s.output,done:!0,isError:s.isError,turnId:t.turnId});break}case"system":(e.text!==""||t.contentPending===!0)&&n.push({kind:"system",id:`system-${t.id}`,contentSource:t.contentSource,variant:e.systemVariant??"system",text:e.text,createdAt:t.createdAt,turnId:t.turnId,source:Qu(e.origin),ownerPromptId:e.origin?.kind==="injection"?e.origin.ownerPromptId:void 0,taskId:e.systemVariant==="task"?e.origin?.taskId??e.taskNotification?.sourceId:void 0,taskNotification:e.taskNotification,hookEvent:e.systemVariant==="hook_result"?e.origin?.event:void 0});break}return n.push(...La(t.id,t.createdAt,e.reminders,t.turnId,e.origin?.kind==="injection"?e.origin:void 0,t.contentSource)),n}function Pi(t){if(!(typeof t!="object"||t===null))return dn(t.origin)}function Hf(t){return Qt(t)}function za(t){const e=dn(t),n=e?.kind;return n==="merged"?(e?.origins??[]).some(za):Ra(e)?!1:n==="user"||n==="peer_thread"||n==="bridged_peer"||n==="branch_fold"||n==="external_thread"||n==="unknown"||n==="system_trigger"&&e?.name==="thread_create"}function Wa(t){const e=dn(t),n=e!==void 0&&typeof e.payload=="object"&&e.payload!==null?e.payload:e!==void 0?e:void 0,s=typeof n?.promptId=="string"?n.promptId:void 0,i=typeof n?.userMessageId=="string"?n.userMessageId:typeof n?.user_message_id=="string"?n.user_message_id:void 0;return{promptId:s,userMessageId:i}}function Ei(t){return t.message?.messageId}function Gs(t){return t.part?.messageId}function Ua(t){const e=t.input,n=typeof e=="object"&&e!==null?e.command:void 0;if(typeof n=="string"&&n.trim()!=="")return n;const s=t.inputText;if(!(typeof s!="string"||s.trim()==="")){try{const i=JSON.parse(s);if(typeof i=="object"&&i!==null){const r=i.command;if(typeof r=="string"&&r.trim()!=="")return r}}catch{return s}return s}}function Jr(t){return t.kind!=="text"||t.role!=="assistant"?!1:(t.text?.trim()??"")!==""||(t.attachmentIds?.length??0)>0||(t.contentRefs?.length??0)>0||t.resourceLink!==void 0}function Yr(t){return t.kind!=="thinking"?!1:(t.text?.trim()??"")!==""||(t.contentRefs?.length??0)>0}function Xr(t,e,n,s,i){if(t.state!=="running"&&t.state!=="queued"||e.state!=="running"||n.kind!=="text"&&n.kind!=="thinking"||s!==n.frameId)return!1;if(i===void 0||typeof i!="object"||i===null)return!0;const r=i,o=typeof r.stepId=="string"?r.stepId.trim():"";return o!==""&&o!==e.stepId||r.turnId!==void 0&&!gt(String(r.turnId),t.turnId)?!1:r.kind==="running"?!0:r.kind!=="streaming"?!1:r.stream==="assistant"?n.kind==="text":r.stream==="thinking"?n.kind==="thinking":!1}function En(t,e,n){if(t===void 0||t.length===0)return;const s=[];for(const i of t){const r=e?.get(i);if(r===void 0){n!==void 0&&s.push({kind:"file",detail:{agentId:n,attachmentId:i}});continue}const o=r.source,a=r.mediaType.startsWith("video/")?"video":r.mediaType.startsWith("image/")?"image":r.mediaType.startsWith("audio/")?"audio":"file",d=r.mediaType.endsWith("/*")?void 0:r.mediaType,l={name:r.name,mime:d,size:r.size};if(o===void 0&&r.detailRef!==void 0&&n!==void 0){s.push({kind:a,...l,detail:{agentId:n,attachmentId:r.attachmentId}});continue}if(o?.kind==="url"&&a!=="file"){const c=ka(a,o.url,l);s.push(c.blobHash!==void 0&&n!==void 0?{...c,fileId:`blobref:${n}:${c.blobHash}`}:c);continue}s.push({kind:a,url:o?.kind==="url"?o.url:void 0,fileId:o?.kind==="file"||o?.kind==="session_media"?o.fileId:void 0,...l})}return s.length>0?s:void 0}function Qs(t,e){const n=Fa(t,e);return n.length>0?n:void 0}function zf(t){if(!Array.isArray(t))return[];const e=[];for(const[n,s]of t.entries()){if(typeof s!="object"||s===null)continue;const i=s,r=Array.isArray(i.options)?i.options:[];e.push({id:typeof i.id=="string"?i.id:`q_${n}`,header:typeof i.header=="string"?i.header:void 0,question:typeof i.question=="string"?i.question:"",body:typeof i.body=="string"?i.body:void 0,options:r.flatMap((o,a)=>{if(typeof o!="object"||o===null)return[];const d=o;return[{id:typeof d.id=="string"?d.id:`opt_${n}_${a}`,label:typeof d.label=="string"?d.label:"",description:typeof d.description=="string"?d.description:void 0}]}),multi_select:(i.multi_select??i.multiSelect)===!0?!0:void 0,allow_other:(i.allow_other??i.allowOther)===!0?!0:void 0})}return e}function Wf(t){const e=t.origin;if(typeof e=="string"&&e!=="")return e;if(typeof e=="object"&&e!==null){const s=e;if(typeof s.agentId=="string")return s.agentId;if(typeof s.agent_id=="string")return s.agent_id}const n=t.request;if(typeof n=="object"&&n!==null){const s=n;if(typeof s.agentId=="string")return s.agentId;if(typeof s.agent_id=="string")return s.agent_id;if(typeof s.originAgentId=="string")return s.originAgentId}}function je(t,...e){for(const n of e){const s=t[n];if(typeof s=="string"&&s!=="")return s}}function Gt(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const e=/^t?(\d+)$/.exec(t);if(e?.[1]!==void 0)return Number(e[1])}}function Zr(t,e){const n=typeof t.origin=="object"&&t.origin!==null?t.origin:void 0,s=typeof t.anchor=="object"&&t.anchor!==null?t.anchor:void 0;return Gt(e.turnId??e.turn_id)??Gt(n?.turnId??n?.turn_id)??Gt(s?.turnId??s?.turn_id)}function Va(t,e){const n=Wf(t);if(t.interactionKind==="approval"){const s=typeof t.request=="object"&&t.request!==null?t.request:{},i=Zr(t,s),r=t.toolCallId??je(s,"toolCallId","tool_call_id")??t.interactionId,o=je(s,"createdAt","created_at")??"",a=je(s,"expiresAt","expires_at")??o,d=s.display??s.toolInputDisplay??s.tool_input_display,l=typeof d=="string"?d:typeof d=="object"&&d!==null?je(d,"summary","command"):void 0;return{kind:"approval",id:`approval-${t.interactionId}`,request:{approval_id:t.interactionId,session_id:je(s,"sessionId","session_id")??"",turn_id:i,tool_call_id:r,tool_name:je(s,"toolName","tool_name","sender")??"tool",action:je(s,"action","description")??l??je(s,"command")??"Approve the action",tool_input_display:d,approval_rule:je(s,"approvalRule","approval_rule"),...typeof s.ssh=="object"&&s.ssh!==null?{ssh:s.ssh}:{},created_at:o,expires_at:a},resolution:t.state==="pending"?void 0:{decision:t.state==="approved"||t.state==="rejected"||t.state==="cancelled"?t.state:"resolved_elsewhere",resolvedAt:typeof t.response=="object"&&t.response!==null?je(t.response,"resolvedAt","resolved_at")??o:o,...t.reviewer!==void 0?{reviewer:t.reviewer}:{}},originAgentId:n,originUnknown:n===void 0&&e===M}}if(t.interactionKind==="question"){const s=typeof t.request=="object"&&t.request!==null?t.request:{},i=Zr(t,s),r=je(s,"createdAt","created_at")??"",o=zf(s.questions),a=typeof t.response=="object"&&t.response!==null?t.response:{},d=je(a,"resolvedAt","resolved_at","dismissed_at")??r;return{kind:"question",id:`question-${t.interactionId}`,request:{question_id:t.interactionId,session_id:je(s,"sessionId","session_id")??"",turn_id:i,tool_call_id:t.toolCallId??je(s,"toolCallId","tool_call_id"),questions:o,created_at:r},outcome:t.state==="pending"?void 0:a.cancelled===!0?{kind:"cancelled",at:d,reason:je(a,"reason")}:t.state==="answered"?{kind:"answered",at:d,answers:Xi(o,a.answers)}:t.state==="dismissed"?{kind:"dismissed",at:d}:{kind:"expired"},originAgentId:n,originUnknown:n===void 0&&e===M}}}const Uf=new Set(["undo","clear","cron.fired","agent_message.delivered"]),Vf={compaction:"transcript.marker.compaction",hook:"transcript.marker.hook",skill:"transcript.marker.skill",notice:"transcript.marker.notice",cron:"transcript.marker.cron",cron_fired:"transcript.marker.cron",goal:"transcript.marker.goal","plan.revision":"transcript.marker.plan","plan.enter":"transcript.marker.plan","plan.exit":"transcript.marker.plan",interruption:"transcript.marker.interruption","model.switch":"transcript.marker.modelSwitch","branch.base":"transcript.marker.branchBase"},eo=new Set(["executor.session","executor.usage"]);function Kf(t,e){switch(t){case"executor.degradation":{const n=e?.value,s=typeof n=="object"&&n!==null?n:void 0;return{kind:"unknown",updateType:typeof s?.updateType=="string"?s.updateType:void 0,method:typeof s?.method=="string"?s.method:void 0,payload:s?.payload}}case"executor.compaction":return{kind:"compaction"};case"executor.diff":{const n=e?.value;return typeof n=="string"?{kind:"diff",diff:n}:{kind:"unknown"}}case"executor.prompt.delivery":{const n=e?.method,s=e?.status;if(n!=="native_steer"&&n!=="next_turn_preamble"&&n!=="undelivered"||s!=="delivered"&&s!=="queued"&&s!=="undelivered")return;const i=e?.origin;return{kind:"hint",method:n,status:s,...typeof i=="string"?{origin:i}:{}}}case"executor.usage":{const n=ns(e?.value),s=n?.used;if(typeof s!="number"||!Number.isFinite(s)||s<0)return;const i=n?.size;return{kind:"usage",used:s,size:typeof i=="number"&&Number.isFinite(i)&&i>0?i:void 0}}case"executor.session":{const n=ns(e?.value),s=ns(n?.meta),i=ns(s?.imageDropped),r=i?.reason,o=Array.isArray(i?.notes)?i.notes.filter(c=>typeof c=="string"&&c!==""):void 0,a=i===void 0?void 0:{reason:typeof r=="string"&&r!==""?r:void 0,notes:o===void 0||o.length===0?void 0:o},d=s?.actualModel,l=typeof d=="string"&&d!==""?{source:typeof s?.source=="string"?s.source:void 0,model:d,provider:typeof s?.modelProvider=="string"&&s.modelProvider!==""?s.modelProvider:void 0,version:typeof s?.agentVersion=="string"&&s.agentVersion!==""?s.agentVersion:void 0}:void 0;return a===void 0&&l===void 0?void 0:{kind:"session",observed:l,droppedImage:a}}default:return}}function ns(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:void 0}function to(t,e){if(e===void 0)return;const n=e.recordId,s=e.text,i=e.kind,r=e.source;if(typeof n!="string"||typeof s!="string"||s.trim()===""||i!=="note"&&i!=="user_excerpt"&&i!=="assistant_excerpt"&&i!=="handoff"||typeof r!="object"||r===null)return;const o=r,a=o.driver,d=o.connectionId,l=o.clientName,c=o.sessionRef;if(a!=="external"||typeof d!="string"||typeof l!="string"||typeof c!="string")return;const u=e.title,f=e.sourceUrl,g=e.clientTime,h=e.turnId;return{recordId:n,markerId:t,kind:i,text:s,title:typeof u=="string"?u:void 0,sourceUrl:typeof f=="string"?f:void 0,clientTime:typeof g=="string"?g:void 0,source:{driver:a,connectionId:d,clientName:l,sessionRef:c},turn:typeof h=="number"?h:void 0}}function no(t){if(t!==void 0)for(const e of["summary","contextSummary"]){const n=t[e];if(typeof n=="string"&&n.trim()!=="")return n;if(typeof n=="object"&&n!==null&&!Array.isArray(n)){const s=n.content;if(typeof s=="string"&&s.trim()!=="")return s;if(Array.isArray(s)){const i=s.map(r=>typeof r=="object"&&r!==null&&typeof r.text=="string"?r.text:void 0).filter(r=>r!==void 0&&r!=="").join(`
20
+ `);if(i.trim()!=="")return i}}}}function Gf(t){if(t!=null){if(typeof t=="string")return t.trim()===""?void 0:t;if(typeof t=="object"){const e=t;if(typeof e.errorDetails=="string"&&e.errorDetails.trim()!=="")return e.errorDetails;try{const n=JSON.stringify(t,null,2);return n===void 0||n==="{}"||n==="[]"?void 0:n}catch{return}}if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint")return String(t)}}function Qf(t){if(Uf.has(t.marker))return;const e=Vf[t.marker],n=t.payload,s=typeof n=="object"&&n!==null?n:void 0,i={kind:"notice",id:`agent-marker-${t.markerId}`,tone:"neutral",createdAt:t.at,turnId:fe(s?.turnId)};if(t.marker==="goal"){const a=s?.change;if(typeof a=="object"&&a!==null&&"kind"in a&&(a.kind==="created"||a.kind==="updated"||a.kind==="paused"||a.kind==="resumed"||a.kind==="blocked"||a.kind==="completed"||a.kind==="cleared"))return{...i,text:t.marker,i18n:{key:"transcript.marker.goal"},goalChange:{kind:a.kind,reason:"reason"in a&&typeof a.reason=="string"?a.reason:void 0,actor:"actor"in a&&typeof a.actor=="string"?a.actor:void 0}};if(s?.type==="goal.update"&&!["objective","completionCriterion","status","budgetLimits","followUpTiming"].some(d=>d in s))return}if(t.marker==="branch.base"){const a=s?.seedMode,d=typeof s?.sourceAgentId=="string"?s.sourceAgentId:"main",l=typeof s?.inheritedMessages=="number"?s.inheritedMessages:0,c=typeof s?.baseTurnId=="number"?s.baseTurnId:void 0,u=a==="fresh"||a==="compact"||a==="verbatim"?a:"fresh",f=u==="verbatim"?"transcript.marker.branchBase.verbatim":u==="compact"?"transcript.marker.branchBase.compact":"transcript.marker.branchBase.fresh";return{...i,text:t.marker,branchBase:{seedMode:u,sourceAgentId:d,inheritedMessages:l,baseTurnId:c},i18n:{key:f,params:{source:d}}}}if(t.marker==="model.switch"){const a=s?.from,d=s?.to;if(typeof a!="string"||typeof d!="string")return;const l=s?.operationId,c=s?.mode,u=s?.state,f=s?.error,g=typeof l=="string"&&(c==="direct"||c==="compact"||c==="fresh")&&(u==="pending"||u==="preparing"||u==="completed"||u==="failed"||u==="cancelled")?{operationId:l,mode:c,state:u,from:a,to:d,change:s?.change==="effort"?"effort":a!==d?"model":c!=="direct"?"context":typeof l=="string"&&l.startsWith("resume:")?"resume":"binding",summaryGenerated:typeof s?.summaryGenerated=="boolean"?s.summaryGenerated:void 0,windowEpoch:typeof s?.windowEpoch=="number"?s.windowEpoch:void 0,error:typeof f=="object"&&f!==null&&"code"in f&&"message"in f&&typeof f.code=="string"&&typeof f.message=="string"?{code:f.code,message:f.message}:void 0}:void 0;return{...i,text:t.marker,modelSwitch:g,i18n:g===void 0||g.state==="completed"?{key:a!==d?"transcript.marker.modelSwitch":g?.change==="effort"?"transcript.modelSwitch.done.effort":g?.change==="resume"?"transcript.modelSwitch.done.resume":"transcript.modelSwitch.done.binding",params:{from:a,to:d}}:void 0}}if(t.marker==="skill"&&typeof s?.activationId=="string"&&s?.text===void 0)return;if(t.marker==="skill"&&e!==void 0)return{...i,text:t.marker,i18n:{key:e}};const r=Kf(t.marker,s);if(r!==void 0)return{...i,text:t.marker,executor:r};if(eo.has(t.marker))return;if(t.marker==="external.text"){const a=to(t.markerId,s);if(a!==void 0)return{...i,text:a.text,externalText:a}}if(t.marker==="external.text"){const a=to(t.markerId,s);if(a!==void 0)return{...i,text:a.text,externalText:a}}if(eo.has(t.marker))return;if(t.marker==="compaction"){const a=s?.result,d=typeof a=="object"&&a!==null?a:s,l=no(d)??no(s),c=t.contentRefs?.some(S=>S.path[0]==="payload")===!0,u=d?.fallbackFrom,f=d?.strategy==="relay"?u==="summarize"?"transcript.marker.compactionRescue":"transcript.marker.compactionFresh":d?.strategy==="summarize"?u==="relay"?"transcript.marker.compactionFallback":"transcript.marker.compactionSummarize":"transcript.marker.compaction",g=Array.isArray(d?.reasonCodes)?d.reasonCodes.filter(S=>typeof S=="string"):void 0,h=s?.phase,v=h==="started"||h==="blocked"?"running":h==="queued"||h==="running"||h==="failed"||h==="cancelled"||h==="interrupted"?h:"completed",m=typeof s?.reason=="string"?s.reason:void 0,p=v==="cancelled"&&m!==void 0?"failed":v,k=p==="running"?"transcript.marker.compactionRunning":p==="queued"?"transcript.marker.compactionQueued":p==="failed"?"transcript.marker.compactionFailed":p==="cancelled"?"transcript.marker.compactionCancelled":p==="interrupted"?"transcript.marker.compactionInterrupted":f;return{...i,markerId:t.markerId,summary:l,summaryPending:c||void 0,text:t.marker,tone:p==="failed"?"danger":i.tone,i18n:{key:k},reasonCodes:g,compactionPhase:p,compactionFailure:m,compactionHistory:p==="completed"?[{id:i.id,markerId:t.markerId,createdAt:t.at,startedAt:typeof s?.startedAt=="string"?s.startedAt:void 0,source:s?.source==="auto"||s?.source==="manual"?s.source:void 0,reasonCodes:g,summary:l,summaryPending:c||void 0}]:void 0}}const o=typeof n=="string"?n:typeof s?.text=="string"?s.text:typeof s?.message=="string"?s.message:void 0;return o!==void 0&&o.trim()!==""?{...i,text:o}:e===void 0?{...i,text:t.marker}:{...i,text:t.marker,i18n:{key:e}}}function Oi(t){if(typeof t!="object"||t===null||!("type"in t))return!1;const e=t.type;return e==="text"||e==="image"||e==="video"||e==="audio"||e==="file"||e==="thinking"||e==="tool_use"||e==="tool_result"}function yn(t){return Array.isArray(t)?t.filter(Oi):[]}function Jf(t,e){if(t===void 0)return;const n=t.spans.filter(s=>s.end>0&&s.start<e).map(s=>{const i=Math.max(0,s.start),r=Math.min(e,s.end);return i===s.start&&r===s.end?s:{...s,start:i,end:r}}).filter(s=>s.end>s.start);return n.length>0?{spans:n}:void 0}function bs(t,e){if(!Array.isArray(t))return;const n=t.some(r=>Oi(r)&&r.type==="text"&&r.presentation!==void 0),s=[];let i=0;for(let r=0;r<t.length;r+=1){const o=t[r];if(Oi(o)&&o.type==="text"){const a=e?.find(c=>c.kind==="text"&&c.path.length===3&&c.path[0]==="content"&&c.path[1]===r&&c.path[2]==="text"),d=a!==void 0?Math.max(o.text.length,a.total):o.text.length,l=Jf(zn(o.presentation),d);s.push({partIndex:r,text:o.text,offset:i,totalLength:d,hasOwnPresentation:n,presentation:l}),i+=d+1}}return s.length>1?s:void 0}function Js(t,e){if(typeof t!="object"||t===null)return;const n=t,s=n.prompt??n.instruction;if(typeof s=="string"&&s.trim()!=="")return s.trim();const i=n.resume_agent_ids;if(typeof i=="object"&&i!==null){const o=i[e];if(typeof o=="string"&&o.trim()!=="")return o.trim()}const r=n.prompt_template;if(typeof r=="string"&&r.trim()!=="")return r.trim()}function Ut(t){return t==="running"?"running":t==="failed"||t==="lost"||t==="timed_out"?"failed":t==="killed"||t==="cancelled"?"cancelled":t==="completed"?"completed":t==="suspended"?"suspended":"unknown"}function Yf(t,e){if(typeof t!="object"||t===null)return;const n=t,s=r=>{const o=n[r];return typeof o=="string"&&o!==""?o:void 0},i=e?["stderr","stdout","text"]:["stdout","stderr","text"];for(const r of i){const o=s(r);if(o!==void 0)return o}return e?ta(t):void 0}function ne(t){return t!==void 0&&t!==""?t:void 0}function Rt(t){return ne(t.agent_id)??t.id}function Xf(t){const e=t.activity_status??(t.subagent_phase==="suspended"?"suspended":Ut(t.status));return t.live===!1&&(e==="running"||e==="suspended")?"unknown":e}function Zf(t,e){const n=e.tool_call_count,s=ne(e.label)??ne(e.description)??ne(e.profile);return{...t,label:t.label??ne(e.label),name:t.name!==t.subagentId?t.name:s??t.name,model:t.model??ne(e.model),thinkingEffort:t.thinkingEffort??ne(e.thinking_effort),thinkingEffortExplicit:t.thinkingEffortExplicit??e.thinking_effort_explicit,executorId:t.executorId??ne(e.executor_id),executorProtocol:t.executorProtocol??ne(e.executor_protocol),status:t.status==="unknown"?Xf(e):t.status,description:t.description??ne(e.description),parentToolCallId:t.parentToolCallId??ne(e.parent_tool_call_id),parentAgentId:t.parentAgentId??ne(e.parent_agent_id),startedAt:t.startedAt??ne(e.started_at),endedAt:t.endedAt??ne(e.completed_at),summary:t.summary??ne(e.output_preview),toolCallCount:n===void 0?t.toolCallCount:Math.max(t.toolCallCount,n),toolCallCountKnown:n===void 0?t.toolCallCountKnown:!0}}const so=new WeakMap;function eh(t,e){if(e===void 0||e.length===0)return t;let n=!1;for(const i of t)if(i.kind==="subagent"){n=!0;break}if(!n)return t;let s=so.get(e);if(s===void 0){s=new Map;for(const i of e){const r=Rt(i);r!==""&&s.set(r,i)}so.set(e,s)}return s.size===0?[...t]:t.map(i=>{if(i.kind!=="subagent")return i;const r=s.get(i.subagentId);return r===void 0?i:Zf(i,r)})}function ve(t){if(t===void 0||t==="")return;const e=Date.parse(t);return Number.isNaN(e)?void 0:e}function We(t){switch(t.kind){case"user":case"assistant":case"thinking":case"system":case"system-reminder":case"skill":return ve(t.createdAt);case"tool":case"message":return t.startedAt!==void 0&&t.startedAt>0?t.startedAt:void 0;case"subagent":return ve(t.startedAt);case"subagent-event":return ve(t.at);case"approval":return ve(t.request.created_at);case"question":return ve(t.request.created_at);case"shell":return t.startedAt!==void 0&&t.startedAt>0?t.startedAt:void 0;case"notice":return ve(t.createdAt)}}function fe(t){if(typeof t=="number"&&Number.isFinite(t))return`t${t}`;if(!(typeof t!="string"||t===""))return t.startsWith("t")?t:`t${t}`}function gt(t,e){return t===void 0||e===void 0?!1:fe(t)===fe(e)}function Qe(t){switch(t.kind){case"user":case"assistant":case"thinking":case"system":case"system-reminder":case"skill":case"tool":case"message":case"shell":case"notice":return t.turnId;case"subagent":return t.parentTurnId;case"subagent-event":return t.turnId;case"approval":return fe(t.request.turn_id);case"question":return fe(t.request.turn_id)}}function bn(t,e){return t===e?0:t<e?-1:1}function Ht(t,e){const n=We(t),s=We(e);return n!==void 0&&s!==void 0&&n!==s?n-s:n!==void 0?-1:s!==void 0?1:bn(t.id,e.id)}function Sn(t,e){if(t.length===0)return;const n=new Map,s=Array.from({length:t.length},()=>-1),i=Array.from({length:t.length},()=>-1);let r=-1;for(let a=0;a<t.length;a+=1){s[a]=r;const d=t[a]?.id;if(d!==void 0){n.has(d)||n.set(d,a);const l=e.get(d);l!==void 0&&(r=l)}}let o=-1;for(let a=t.length-1;a>=0;a-=1){i[a]=o;const d=t[a]?.id;if(d!==void 0){const l=e.get(d);l!==void 0&&(o=l)}}return{indexById:n,prevExisting:s,nextExisting:i}}function th(t,e){if(t===void 0)return;const n=t.indexById.get(e);if(n===void 0)return;const s=t.prevExisting[n];if(s>=0)return{slot:s+1,side:"after"};const i=t.nextExisting[n];if(i>=0)return{slot:i,side:"before"}}function Ka(t,e){const n=We(t);if(n!==void 0)return n;if("frameId"in t&&t.frameId!==void 0)return e?.get(t.frameId)}class rn{constructor(e,n){this.base=e,this.frameTimes=n,this.beforeSlots=Array.from({length:e.length+1},()=>[]),this.afterSlots=Array.from({length:e.length+1},()=>[])}beforeSlots;afterSlots;trailing=[];insertBefore(e,n){if(e>=this.base.length){this.trailing.push(n);return}this.beforeSlots[Math.max(0,e)].push(n)}insertAfter(e,n){const s=Math.max(0,Math.min(this.base.length,e));if(s>=this.base.length){this.trailing.push(n);return}this.afterSlots[s].push(n)}insertPreviousPosition(e,n,s=!0){const i=th(e,n.id);if(i===void 0)return!1;const r=i.side==="after"?this.afterSlots[i.slot]:this.beforeSlots[i.slot];return s?r.unshift(n):r.push(n),!0}materialize(e=[],n=Ht){if(e.length>0){const o=[...e].toSorted(n),a=[],d=[];for(let c=0;c<this.base.length;c+=1){const u=Ka(this.base[c],this.frameTimes);u!==void 0&&(a.push(c),d.push(u))}let l=0;for(const c of o){const u=We(c);if(u===void 0){this.trailing.push(c);continue}for(;l<d.length&&(d[l]<u||d[l]===u&&bn(this.base[a[l]].id,c.id)<=0);)l+=1;l<d.length?this.beforeSlots[a[l]].push(c):this.trailing.push(c)}}const s=[];for(let o=0;o<this.base.length;o+=1){const a=this.afterSlots[o],d=this.beforeSlots[o];a.length>0&&s.push(...a),d.length>0&&s.push(...d),s.push(this.base[o])}const i=this.afterSlots[this.base.length],r=this.beforeSlots[this.base.length];return i.length>0&&s.push(...i),r.length>0&&s.push(...r),this.trailing.length>0&&s.push(...this.trailing),s}}function Ps(t){const e=new Map;for(let n=0;n<t.length;n+=1){const s=t[n],i=fe(Qe(s));if(i===void 0)continue;let r=e.get(i);r===void 0&&(r={first:n,last:n,lastWork:-1,firstOpeningFallback:-1,timedIndices:[],timedValues:[]},e.set(i,r)),r.last=n,s.kind!=="assistant"&&s.kind!=="user"&&(r.lastWork=n);const o=We(s);o!==void 0?(r.timedIndices.push(n),r.timedValues.push(o)):r.firstOpeningFallback<0&&r.timedIndices.length===0&&(s.kind==="user"||s.kind==="system"||s.kind==="system-reminder"||s.kind==="skill")&&(r.firstOpeningFallback=n)}return e}function Ss(t,e,n){const s=We(n);if(s===void 0)return;let i=-1;for(let r=0;r<e.timedValues.length;r+=1){const o=e.timedValues[r],a=e.timedIndices[r];if(o>s||o===s&&bn(t[a].id,n.id)>0)break;i=a}return i<0?e.timedValues.length===0&&e.firstOpeningFallback>=0?e.firstOpeningFallback+1:e.first:i+1}function nh(t,e,n){const s=n.findIndex(i=>i.id===e.id);if(s<0)return!1;for(let i=s-1;i>=0;i-=1){const r=n[i]?.id;if(r===void 0)continue;const o=t.findLastIndex(a=>a.id===r);if(o>=0)return t.splice(o+1,0,e),!0}for(let i=s+1;i<n.length;i+=1){const r=n[i]?.id;if(r===void 0)continue;const o=t.findIndex(a=>a.id===r);if(o>=0)return t.splice(o,0,e),!0}return!1}function sh(t,e){const n=We(e);if(n!==void 0){const s=t.findIndex(i=>{const r=We(i);return r===void 0?!1:r!==n?r>n:bn(i.id,e.id)>0});if(s>=0){t.splice(s,0,e);return}}t.push(e)}function ih(t){switch(t.kind){case"assistant":case"thinking":case"tool":case"shell":return t.stepId;default:return}}function io(t){if(typeof t!="object"||t===null)return[];const e=t,n=[],s=e.resume;typeof s=="string"&&s.trim()!==""&&n.push(s.trim());const i=e.resume_agent_ids;return typeof i=="object"&&i!==null&&n.push(...Object.keys(i).filter(r=>r!=="")),n}function Ys(t,e,n,s){return e.has(t)||n.has(t)?t:s.get(t)}function rh(t){if(typeof t!="object"||t===null)return;const e=t.target;return typeof e=="string"&&e.trim()!==""?e.trim():void 0}function oh(t){if(typeof t!="object"||t===null)return;const e=t.message;return typeof e=="string"&&e.trim()!==""?e:void 0}function ah(t){let e=t;if(typeof e=="string")try{e=JSON.parse(e)}catch{return{}}if(typeof e!="object"||e===null)return{};const n=e,s=n.status,i=n.target,r=typeof i=="object"&&i!==null?i.agent_id:void 0;return{messageId:typeof n.message_id=="string"?n.message_id:void 0,targetAgentId:typeof r=="string"?r:void 0,delivery:s==="queued"||s==="delivered"?s:void 0}}function ro(t){if(t==="completed"||t==="failed"||t==="cancelled")return t}const oo=new WeakMap;function ao(t){const e="state"in t&&t.state==="running";if(!e){const i=oo.get(t);if(i!==void 0)return i}const n=[];let s=!1;for(const i of t.frames)"state"in i&&i.state==="running"&&(s=!0),!(i.kind!=="tool"||i.toolCallId.startsWith("external:"))&&(i.name==="AgentRun"||i.name==="Agent"||i.name==="AgentSend"||i.agentRefs!==void 0&&i.agentRefs.length>0)&&n.push(i);return!e&&!s&&oo.set(t,n),n}function Xs(t){return t!==void 0&&t.startsWith("agent-phase-")}function co(t){return t!==void 0&&t.startsWith("agent-receipt-")}function lo(t,e){let n;const s=new Set(t);for(const i of e)i===""||s.has(i)||(s.add(i),n??=t===void 0?[]:[...t],n.push(i));return n??t}function Zs(t,e,n,s){const i=ne(t?.name);return i!==void 0?i:e!==void 0&&e!==""&&e!==s?e:n!==void 0&&n!==""&&n!==s?n:ne(t?.subagentName)??s}function dh(t,e,n){const s=t.tasks??[],i=new Map(s.map(P=>[P.taskId,P])),r=new Map;for(const P of s){if(P.kind!=="subagent"||P.agentId===void 0||P.agentId==="")continue;const I=r.get(P.agentId);I===void 0?r.set(P.agentId,[P]):I.push(P)}const o=new Map;for(const[P,I]of r){const y=I.filter(R=>!Xs(R.taskId));o.set(P,y.length>0?y:I)}const a=new Map([...o.entries()].map(([P,I])=>[P,I.at(-1)])),d=new Set(o.keys()),l=new Map([...o.entries()].map(([P,I])=>{let y=I[0];for(const R of I){const z=ve(R.startedAt),W=ve(y.startedAt);z!==void 0&&W!==void 0&&z<W&&(y=R)}return[P,y.taskId]})),c=new Set,u=new Map,f=[],g=[];{const P=[];for(let I=0;I<t.items.length;I+=1){const y=t.items[I];if(y.kind!=="turn")continue;const R=ve(y.startedAt);R!==void 0&&P.push({at:R,turnId:y.turnId,order:I})}P.sort((I,y)=>I.at-y.at||I.order-y.order);for(let I=0;I<P.length;I+=1){const y=P[I];f.length>0&&f.at(-1)===y.at||(f.push(y.at),g.push(y.turnId))}}const h=(P,I)=>{const y=ve(P);if(y===void 0||f.length===0)return I;let R=0,z=f.length-1,W=-1;for(;R<=z;){const B=R+z>>1;f[B]<=y?(W=B,R=B+1):z=B-1}return W<0?I:g[W]},v=new Map(s.flatMap(P=>P.agentId===void 0||P.name===void 0?[]:[[P.name,P.agentId]])),m=new Map,p=new Map,k=new Map,S=(P,I)=>{const y=!p.has(P);if(p.set(P,I),m.set(I.subagentId,I),y){const R=k.get(I.subagentId);R===void 0?k.set(I.subagentId,[P]):R.push(P)}},w=new Map,x=new Map,b=new Map,_=n?.length??0,C=new Int32Array(_+1);if(n!==void 0)for(let P=0;P<n.length;P+=1){const I=n[P],y=I.kind==="user"||I.kind==="assistant"||I.kind==="message"||I.kind==="question"||I.kind==="approval"||I.kind==="notice"&&(I.externalText!==void 0||I.tone!=="neutral"||I.executor===void 0||I.executor.kind==="compaction");C[P+1]=C[P]+(y?1:0);const R=fe(Qe(I));if(R!==void 0&&!b.has(R)&&b.set(R,P),I.kind==="tool"&&ne(I.toolCallId)!==void 0&&x.set(I.toolCallId,P),I.kind==="system"&&I.variant==="task"){const z=ne(I.taskId)??ne(I.taskNotification?.sourceId);if(z===void 0||!co(z))continue;const W=i.get(z),B=ne(W?.agentId)??ne(I.taskNotification?.agentId);if(B===void 0)continue;const K=w.get(B),$={taskId:z,turnId:fe(I.turnId),index:P};K===void 0?w.set(B,[$]):K.push($)}}const F=(P,I)=>{const y=fe(P.parentTurnId);if(y!==void 0&&I.turnId!==void 0&&!gt(y,I.turnId))return!0;const R=ne(P.parentToolCallId)!==void 0&&x.has(P.parentToolCallId)?x.get(P.parentToolCallId):y!==void 0?b.get(y)??-1:-1;if(R>=0){const z=Math.min(R,I.index)+1,W=Math.max(R,I.index)-1;if(z<=W&&C[W+1]-C[z]>0)return!0}return!1},N=new Set,me=(P,I)=>{const y=Ut(P.state),R=ne(P.resultSummary)??ne(P.outputTail),z=ne(P.error)??ne(P.stateReason),W=ve(P.startedAt),B=ve(P.endedAt);return I.find(K=>{if(N.has(K.taskId))return!1;const $=i.get(K.taskId);if($!==void 0&&Ut($.state)!==y)return!1;const se=ve($?.startedAt),ce=ve($?.endedAt);if(W!==void 0&&ce!==void 0&&ce<W||B!==void 0&&se!==void 0&&se>B)return!1;const Te=ne($?.resultSummary)??ne($?.outputTail);if(R!==void 0&&Te!==void 0&&R!==Te)return!1;if(y==="failed"){const ke=ne($?.error)??ne($?.stateReason);if(z!==void 0&&ke!==void 0&&z!==ke)return!1}return!0})},V=new Set;for(const P of o.values())for(const I of P){const y=ne(I.parentToolCallId);y!==void 0&&V.add(y)}const we=Array.from({length:t.items.length});{let P;for(let I=t.items.length-1;I>=0;I-=1){const y=t.items[I];we[I]=P,y.kind==="turn"&&(P={turnId:y.turnId,startedAt:ve(y.startedAt)})}}const ye=new Set(d),Fe=new Map;for(const P of t.items)if(P.kind==="turn")for(const I of P.steps)for(const y of ao(I)){if(y.agentRefs!==void 0)for(const W of y.agentRefs)ye.add(W.agentId);if(y.name!=="AgentRun"&&y.name!=="Agent"||y.state==="error"||y.state==="interrupted"||ne(y.error)!==void 0||ne(y.errorCode)!==void 0)continue;const R=y.startedAt??I.startedAt??P.startedAt,z=new Set;for(const W of io(y.input)){const B=Ys(W,m,ye,v);if(B===void 0||z.has(B))continue;z.add(B);const K={toolCallId:y.toolCallId,turnId:P.turnId,instruction:Js(y.input,B),at:R,claimed:!1},$=Fe.get(B);$===void 0?Fe.set(B,[K]):$.push(K)}}const te=(P,I,y,R,z,W)=>{const B=Fe.get(P);if(B===void 0||B.length===0)return;if(I!==void 0){const D=B.find(De=>!De.claimed&&De.toolCallId===I);return D!==void 0&&(D.claimed=!0),D}const K=fe(y.ownerTurnId),$=h(R??y.startedAt),se=we[z],ce=ve(y.endedAt),Te=ce!==void 0&&se?.startedAt!==void 0&&ce<se.startedAt,ke=B.find(D=>{if(D.claimed||V.has(D.toolCallId))return!1;const De=ve(D.at);return ce!==void 0&&De!==void 0&&ce<De?!1:K!==void 0?gt(D.turnId,K):$!==void 0&&gt(D.turnId,$)||!Te&&se!==void 0&&gt(D.turnId,se.turnId)?!0:$===void 0&&gt(D.turnId,W)});return ke!==void 0&&(ke.claimed=!0),ke},ee=[],re=new Set;let le;for(let P=0;P<t.items.length;P+=1){const I=t.items[P];if(I.kind==="taskref"){const y=i.get(I.taskId);if(y?.kind!=="subagent"||y.agentId===void 0||y.agentId===""||Xs(y.taskId)&&(o.get(y.agentId)?.some(de=>!Xs(de.taskId))??!1))continue;const R=ne(y.parentToolCallId),z=m.get(y.agentId),W=te(y.agentId,R,y,I.at,P,le),B=o.get(y.agentId)??[],K=ve(y.endedAt),$=B.some(de=>{if(de.taskId===y.taskId||de.state!=="running")return!1;const J=ve(de.startedAt);return K===void 0||J===void 0?!0:J<=K}),se=w.get(y.agentId)??[],ce=p.get(`task:${y.taskId}`),Te=[`agent:${y.agentId}`,...k.get(y.agentId)??[]].find(de=>{if(de===`task:${y.taskId}`)return!1;const J=p.get(de);return J===void 0?!1:R!==void 0&&J.parentToolCallId===R?!0:(J.taskId===void 0||J.taskId===y.taskId)&&!c.has(J.taskId??"")&&ne(J.parentToolCallId)!==void 0&&gt(J.parentTurnId,le)}),ke=Te===void 0?void 0:p.get(Te);if(ce===void 0&&ke===void 0&&z!==void 0&&R===void 0&&W===void 0){const de=k.get(y.agentId)?.at(-1),J=de===void 0?void 0:p.get(de);if(de!==void 0&&J!==void 0){const L=Ut(y.state),_e=L==="running"?void 0:me(y,se);_e!==void 0&&N.add(_e.taskId);const Z=lo(J.absorbedTaskIds,_e===void 0?[y.taskId]:[y.taskId,_e.taskId]),Ne=ve(J.endedAt),nt=L!=="running"&&Ne!==void 0&&K!==void 0&&K<Ne;if(L!=="running"&&(J.status==="running"||$||nt)){S(de,{...J,absorbedTaskIds:Z});continue}const He=_e!==void 0&&F(J,_e),ge=ne(y.resultSummary)??ne(y.outputTail),O=L==="running"||He?J.summary:ge??J.summary,Se=L==="running"||He?J.resultTaskId:ge!==void 0?y.taskId:J.resultTaskId,qe=L==="failed"?He?J.error:ne(y.error)??ne(y.stateReason):L==="running"||L==="completed"?He?J.error:void 0:ne(y.error)??ne(y.stateReason)??J.error,et=He&&J.status!=="running"?J.status:L;S(de,{...J,absorbedTaskIds:Z,resultTaskId:Se,name:Zs(y,J.name,z.name,y.agentId),model:y.model??J.model,thinkingEffort:y.thinkingEffort??J.thinkingEffort,thinkingEffortExplicit:y.thinkingEffortExplicit??J.thinkingEffortExplicit,executorId:y.executorId??J.executorId,executorProtocol:y.executorProtocol??J.executorProtocol,status:et,summary:O,error:qe,usage:y.usage??J.usage,endedAt:et==="running"?void 0:He?J.endedAt??y.endedAt:y.endedAt??J.endedAt});continue}}if(ce===void 0&&ke===void 0&&z===void 0&&R===void 0&&W===void 0&&l.get(y.agentId)!==y.taskId&&Ut(y.state)!=="running"){const de=me(y,se);if(de!==void 0){N.add(de.taskId);continue}}if(Te!==void 0&&ke!==void 0){p.delete(Te);const de=k.get(y.agentId);if(de!==void 0){const J=de.indexOf(Te);J>=0&&de.splice(J,1)}}const D=ce??ke,De=k.get(y.agentId)?.length??0,tt=D?.id??(De===0?`subagent-${y.agentId}`:`subagent-${y.agentId}-${y.taskId}`),Me=I.at??y.startedAt??D?.startedAt??W?.at,H=l.get(y.agentId)===y.taskId,Ie=R??ne(D?.parentToolCallId)??W?.toolCallId,ae=D?.parentTurnId??W?.turnId??fe(y.ownerTurnId)??h(Me,le);S(`task:${y.taskId}`,{kind:"subagent",id:tt,subagentId:y.agentId,taskId:y.taskId,resumed:!H||W!==void 0||D?.resumed===!0?!0:void 0,parentAgentId:e,parentToolCallId:Ie,parentTurnId:ae,name:Zs(y,D?.name,z?.name,y.agentId),description:D?.description??y.description??W?.instruction??z?.description,instruction:D?.instruction??W?.instruction??z?.instruction,model:y.model??D?.model??z?.model,thinkingEffort:y.thinkingEffort??D?.thinkingEffort??z?.thinkingEffort,thinkingEffortExplicit:y.thinkingEffortExplicit??D?.thinkingEffortExplicit??z?.thinkingEffortExplicit,executorId:y.executorId??D?.executorId??z?.executorId,executorProtocol:y.executorProtocol??D?.executorProtocol??z?.executorProtocol,status:Ut(y.state),summary:ne(y.resultSummary)??ne(y.outputTail)??D?.summary,error:y.error??y.stateReason??D?.error,usage:y.usage??D?.usage,startedAt:Me,endedAt:y.endedAt??D?.endedAt,toolCallCount:D?.toolCallCount??0,toolCallCountKnown:D?.toolCallCountKnown??!1,transcript:[]}),c.add(y.taskId),u.set(y.taskId,ae??le);const ze=!H||W!==void 0||D?.resumed===!0;!re.has(y.agentId)&&!ze&&(re.add(y.agentId),ee.push({id:`subagent-event-${y.agentId}-spawned-${y.taskId}`,subagentId:y.agentId,event:"spawned",at:Me,turnId:ae??le}));continue}if(I.kind==="turn"){le=I.turnId;for(const y of I.steps)for(const R of ao(y)){const z=R.startedAt??y.startedAt??I.startedAt,W=new Set,B=(R.name==="AgentRun"||R.name==="Agent")&&R.state!=="error"&&R.state!=="interrupted"&&ne(R.error)===void 0&&ne(R.errorCode)===void 0?io(R.input):[];for(const K of B){const $=Ys(K,m,ye,v);if($===void 0||W.has($))continue;W.add($);const se=Js(R.input,$),Te=(k.get($)??[]).findLast(ke=>{const D=p.get(ke);return D===void 0?!1:D.parentToolCallId===R.toolCallId?!0:D.resumed===!0&&D.parentToolCallId===void 0&&(D.parentTurnId===void 0||gt(D.parentTurnId,I.turnId))});if(Te!==void 0){const ke=p.get(Te);S(Te,{...ke,resumed:!0,parentToolCallId:ke.parentToolCallId??R.toolCallId,parentTurnId:ke.parentTurnId??I.turnId,instruction:se??ke.instruction,description:ke.description??se})}ee.push({id:`subagent-event-${$}-resume-${R.toolCallId}`,subagentId:$,event:"resumed",at:z,turnId:I.turnId,anchorToolCallId:R.toolCallId})}if(R.name==="AgentSend"){const K=ah(R.output),$=rh(R.input),se=K.targetAgentId??($===void 0?void 0:Ys($,m,d,v));se!==void 0&&ee.push({id:`subagent-event-${se}-send-${R.toolCallId}`,contentSource:{kind:"frame",id:R.frameId,turnId:I.turnId,stepId:y.stepId},subagentId:se,event:"sent",at:z,turnId:I.turnId,message:oh(R.input),messageId:K.messageId,delivery:K.delivery,anchorToolCallId:R.toolCallId})}if(R.agentRefs!==void 0)for(const K of R.agentRefs){const $=m.get(K.agentId),se=o.get(K.agentId)??[],ce=se.find(ze=>ne(ze.parentToolCallId)===R.toolCallId),Te=B.length>0,ke=l.get(K.agentId),D=ce??(se.length===1&&!c.has(se[0].taskId)?se[0]:!Te&&ke!==void 0?i.get(ke)??a.get(K.agentId):Te?se.findLast(ze=>!c.has(ze.taskId))??a.get(K.agentId):a.get(K.agentId)),De=Js(R.input,K.agentId),Me=(D!==void 0&&p.has(`task:${D.taskId}`)?`task:${D.taskId}`:(k.get(K.agentId)??[]).find(ze=>{const de=p.get(ze);return de!==void 0&&(ne(de.parentToolCallId)===R.toolCallId||ne(de.parentToolCallId)===void 0&&(D===void 0||de.taskId===void 0||de.taskId===D.taskId||!c.has(D.taskId)))}))??(D!==void 0?`task:${D.taskId}`:`agent:${K.agentId}`),H=p.get(Me),Ie=k.get(K.agentId)?.length??0,ae=H?.id??(Ie===0?`subagent-${K.agentId}`:`subagent-${K.agentId}-${D?.taskId??R.toolCallId}`);S(Me,{kind:"subagent",id:ae,subagentId:K.agentId,taskId:D?.taskId??H?.taskId,resumed:Te||H?.resumed===!0?!0:void 0,parentAgentId:e,parentToolCallId:R.toolCallId,parentTurnId:I.turnId,name:Zs(D,H?.name,$?.name,K.agentId),description:H?.description??D?.description??De??$?.description,instruction:De??H?.instruction??$?.instruction,model:D?.model??H?.model??$?.model,thinkingEffort:D?.thinkingEffort??H?.thinkingEffort??$?.thinkingEffort,thinkingEffortExplicit:D?.thinkingEffortExplicit??H?.thinkingEffortExplicit??$?.thinkingEffortExplicit,executorId:D?.executorId??H?.executorId??$?.executorId,executorProtocol:D?.executorProtocol??H?.executorProtocol??$?.executorProtocol,status:D===void 0?H?.status??(R.state==="running"?"running":"unknown"):Ut(D.state),summary:D?.resultSummary??(D?.outputTail===""?void 0:D?.outputTail)??H?.summary,error:D?.error??D?.stateReason??H?.error,usage:D?.usage??H?.usage,startedAt:D?.startedAt??H?.startedAt??R.startedAt,endedAt:D?.endedAt??H?.endedAt,toolCallCount:H?.toolCallCount??0,toolCallCountKnown:H?.toolCallCountKnown??!1,transcript:[]})}}}}for(const[P,I]of k){const y=I.at(-1),R=y===void 0?void 0:p.get(y);if(y===void 0||R===void 0)continue;const z=(o.get(P)??[]).filter(B=>co(B.taskId)&&!c.has(B.taskId)).map(B=>B.taskId);if(z.length===0)continue;const W=lo(R.absorbedTaskIds,z);W!==R.absorbedTaskIds&&S(y,{...R,absorbedTaskIds:W})}const Oe=new Set;for(const[P,I]of o)for(const y of I){if(!c.has(y.taskId))continue;const R=ro(Ut(y.state));R!==void 0&&(Oe.add(P),ee.push({id:`subagent-event-${P}-${R}-${y.taskId}`,contentSource:{kind:"task",id:y.taskId},subagentId:P,event:R,at:y.endedAt,turnId:h(y.endedAt,u.get(y.taskId)),error:y.error??y.stateReason}))}for(const P of p.values()){if(Oe.has(P.subagentId))continue;const I=ro(P.status);I!==void 0&&ee.push({id:`subagent-event-${P.subagentId}-${I}`,contentSource:P.taskId===void 0?void 0:{kind:"task",id:P.taskId},subagentId:P.subagentId,event:I,at:P.endedAt,turnId:h(P.endedAt,P.parentTurnId),error:P.error})}const Ze=new Map;for(const P of t.items){if(P.kind!=="marker"||P.marker!=="agent_message.delivered")continue;const I=ea.safeParse(P.payload);if(!I.success)continue;const{targetAgentId:y,messageId:R,deliveredAt:z}=I.data;let W=Ze.get(y);W===void 0&&(W=new Map,Ze.set(y,W));const B=W.get(R);(B===void 0||z<B)&&W.set(R,z)}const Je=ee.map(P=>{const I=m.get(P.subagentId),y=P.messageId===void 0?void 0:Ze.get(P.subagentId)?.get(P.messageId);return{kind:"subagent-event",id:P.id,contentSource:P.contentSource,subagentId:P.subagentId,parentAgentId:e,name:I?.name??P.subagentId,event:P.event,status:I?.status??"unknown",at:P.at,turnId:P.turnId,error:P.error,message:P.message,messageId:P.messageId,delivery:y===void 0?P.delivery:"delivered",deliveredAt:y,anchorToolCallId:P.anchorToolCallId}});return{blocks:[...p.values()],events:Je}}function xs(t,e){const n=We(t),s=We(e);return n!==void 0&&s!==void 0&&n!==s?n-s:n!==void 0?-1:s!==void 0?1:bn(t.id,e.id)}function uo(t,e){const n=[];for(let s=0;s<t.length;s+=1){const i=t[s],r=Qe(i);if(r===void 0)continue;const o=Ka(i,e);o!==void 0&&n.push({at:o,turnId:r,order:s})}return n.sort((s,i)=>s.at-i.at||s.order-i.order),{times:n.map(s=>s.at),turnIds:n.map(s=>s.turnId)}}function fo(t,e){if(e===void 0||t.times.length===0)return;let n=0,s=t.times.length-1,i=-1;for(;n<=s;){const r=n+s>>1;t.times[r]<=e?(i=r,n=r+1):s=r-1}return i<0?void 0:t.turnIds[i]}function ch(t,e,n){const s=We(n);if(s===void 0)return{slot:e.last+1,side:"after"};let i=e.firstOpeningFallback;for(let r=0;r<e.timedValues.length;r+=1){const o=e.timedIndices[r],a=t[o];if(a.kind==="subagent"&&gt(a.parentTurnId,n.parentTurnId)){if(xs(a,n)>0)break;i=o;continue}if(e.timedValues[r]>s)break;i=o}if(i<0)return{slot:e.first,side:"before"};for(;t[i+1]?.kind==="subagent"&&gt(t[i+1].parentTurnId,n.parentTurnId)&&xs(t[i+1],n)<=0;)i+=1;return{slot:i+1,side:"after"}}function lh(t,e,n,s){if(e.length===0)return t.filter(m=>m.kind!=="subagent");const i=[...e].toSorted(xs),r=new Map;for(const m of i){const p=new Set([m.parentToolCallId,m.parentToolCallUuid].filter(k=>k!==void 0&&k!==""));for(const k of p){const S=r.get(k)??[];S.push(m),r.set(k,S)}}let o;const a=new Set,d=[];let l;for(let m=0;m<t.length;m+=1){const p=t[m];if(p.kind==="subagent")continue;d.push(p);const k=Qe(p),S=p.kind==="tool"?p.toolCallId:p.kind==="shell"?p.commandId:void 0;if(S!==void 0){const w=r.get(S);if(w!==void 0)for(const x of w){if(a.has(x.id))continue;const b=x.parentTurnId??l??fo(o??=uo(t,s),We(x));d.push(b===void 0?x:{...x,parentTurnId:b}),a.add(x.id)}}k!==void 0&&(l=k)}if(a.size===i.length)return d;const c=uo(d,s),u=Ps(d),f=new Map;for(let m=0;m<d.length;m+=1)f.set(d[m].id,m);const g=Sn(n,f),h=new rn(d,s),v=[];for(const m of i){if(a.has(m.id))continue;const p=m.parentTurnId??fo(c,We(m)),k=p===void 0?m:{...m,parentTurnId:p};if(!(p===void 0&&h.insertPreviousPosition(g,k,!0))){if(k.parentTurnId!==void 0){const S=u.get(fe(k.parentTurnId));if(S!==void 0){const w=ch(d,S,k);w.side==="before"?h.insertBefore(w.slot,k):h.insertAfter(w.slot,k);continue}}v.push(k)}}return h.materialize(v,(m,p)=>m.kind==="subagent"&&p.kind==="subagent"?xs(m,p):Ht(m,p))}function uh(t,e,n,s){const i=t.filter(h=>h.kind!=="subagent-event");if(e.length===0)return i;const r=new Map,o=new Map,a=new Map;for(let h=0;h<i.length;h+=1){const v=i[h];if(a.set(v.id,h),v.kind==="tool"&&!r.has(v.toolCallId))r.set(v.toolCallId,h);else if(v.kind==="shell"&&!r.has(v.commandId))r.set(v.commandId,h);else if(v.kind==="subagent"){const m=o.get(v.subagentId);m===void 0?o.set(v.subagentId,[{index:h,block:v}]):m.push({index:h,block:v})}}const d=Ps(i),l=Sn(n,a),c=new rn(i,s),u=[],f=new Map,g=new Map;for(const h of e){const v=h.anchorToolCallId;if(v!==void 0){const p=r.get(v);if(p!==void 0){c.insertAfter(p+1,h);continue}}const m=h.event==="completed"||h.event==="failed"||h.event==="cancelled";if(h.event==="spawned"){const k=o.get(h.subagentId)?.find(({block:S})=>h.id===`subagent-event-${h.subagentId}-spawned-${S.taskId??""}`||gt(S.parentTurnId,h.turnId));if(k!==void 0){let S=g.get(k.index+1);S===void 0&&(S=[],g.set(k.index+1,S)),S.unshift(h);continue}if(h.turnId!==void 0){const S=d.get(fe(h.turnId)),w=S===void 0?void 0:Ss(i,S,h);if(w!==void 0){let x=f.get(w);x===void 0&&(x=[],f.set(w,x)),x.push(h);continue}}}if(m&&h.turnId!==void 0){const p=d.get(fe(h.turnId)),k=p===void 0?void 0:Ss(i,p,h);if(k!==void 0){let S=f.get(k);S===void 0&&(S=[],f.set(k,S)),S.push(h);continue}}if(We(h)===void 0){if(c.insertPreviousPosition(l,h,!0))continue;if(m){const p=o.get(h.subagentId)?.[0];if(p!==void 0){let k=g.get(p.index+1);k===void 0&&(k=[],g.set(p.index+1,k)),k.unshift(h);continue}}}u.push(h)}for(const[h,v]of g)for(const m of v)c.insertAfter(h,m);for(const[h,v]of f)for(const m of v.toSorted(Ht))c.insertBefore(h,m);return c.materialize(u,Ht)}function fh(t,e){const n=typeof t.anchor=="object"&&t.anchor!==null?t.anchor:void 0,s=typeof t.origin=="object"&&t.origin!==null?t.origin:void 0,i=typeof t.request=="object"&&t.request!==null?t.request:void 0,r=n===void 0?void 0:je(n,"kind"),a=(t.toolCallId===void 0||t.toolCallId===""?void 0:t.toolCallId)??(r==="tool_call"&&n!==void 0?je(n,"toolCallId","tool_call_id"):void 0)??(i===void 0?void 0:je(i,"toolCallId","tool_call_id"))??e.request.tool_call_id,d=n===void 0?void 0:n.turnId??n.turn_id,l=fe(d)??fe(s?.turnId??s?.turn_id)??fe(i?.turnId??i?.turn_id)??fe(e.request.turn_id),c=r==="frame"&&n!==void 0?je(n,"frameId","frame_id"):void 0,u=n!==void 0?je(n,"stepId","step_id"):void 0;return{block:e,toolCallId:a,turnId:l,stepId:u,frameId:c}}function hh(t,e){const n=We(t.block),s=We(e.block);return n!==void 0&&s!==void 0&&n!==s?n-s:n!==void 0?-1:s!==void 0?1:bn(t.block.id,e.block.id)}function On(t){return t.kind==="approval"?t.resolution!==void 0:t.outcome!==void 0}function ph(t,e,n,s,i,r){const o=t.filter(b=>b.kind!=="approval"&&b.kind!=="question");if(e.length===0)return o;const a=new Map(s.map(b=>[b.id,b])),d=e.flatMap(b=>{let _=Va(b,n);const F=b.contentRefs?.some(N=>N.path[0]==="request")===!0;if(_?.kind==="approval"){const N=a.get(_.id);N?.kind==="approval"&&(b.request===void 0||b.request===null)&&(_={..._,request:{...N.request,..._.request.turn_id!==void 0?{turn_id:_.request.turn_id}:{},..._.request.created_at!==""?{created_at:_.request.created_at}:{}}})}else if(_?.kind==="question"){const N=a.get(_.id);N?.kind==="question"&&(b.request===void 0||b.request===null||F&&_.request.questions.length===0&&N.request.questions.length>0)&&(_={..._,request:{...N.request,..._.request.turn_id!==void 0?{turn_id:_.request.turn_id}:{},..._.request.created_at!==""?{created_at:_.request.created_at}:{}}})}return _?.kind==="approval"||_?.kind==="question"?[fh(b,_)]:[]}).toSorted(hh);if(d.length===0)return o;const l=new Set,c=new Map,u=new Map,f=new Map,g=new Map;for(let b=0;b<o.length;b+=1){const _=o[b];l.add(_.id),c.set(_.id,b),_.kind==="tool"?u.set(_.toolCallId,b):_.kind==="shell"&&u.set(_.commandId,b);const C=ih(_);if(C!==void 0){f.set(C,b);const F=fe(Qe(_));F!==void 0&&g.set(`${F}\0${C}`,b)}}const h=Ps(o),v=Sn(s,c),m=new rn(o,i),p=new Map,k=[],S=r?.firstTurnOrdinal,w=r?.firstTurnStartedMs,x=S!==void 0&&S>0;for(const b of d){if(l.has(b.block.id))continue;if(l.add(b.block.id),b.frameId!==void 0){const C=c.get(`agent-frame-${b.frameId}`);if(C!==void 0){m.insertAfter(C+1,b.block);continue}}if(b.toolCallId!==void 0){const C=u.get(b.toolCallId);if(C!==void 0){m.insertAfter(C+1,b.block);continue}}if(b.stepId!==void 0){const C=b.turnId===void 0?f.get(b.stepId):g.get(`${fe(b.turnId)}\0${b.stepId}`);if(C!==void 0){m.insertAfter(C+1,b.block);continue}}if(b.turnId!==void 0){const C=fe(b.turnId),F=h.get(C);if(F!==void 0){if(b.block.kind==="question"||On(b.block)){const me=Ss(o,F,b.block);if(me!==void 0){let V=p.get(me);V===void 0&&(V=[],p.set(me,V)),V.push(b.block);continue}}F.lastWork>=0?m.insertAfter(F.lastWork+1,b.block):On(b.block)&&F.last>F.first&&o[F.last]?.kind==="assistant"?m.insertBefore(F.last,b.block):m.insertAfter(F.last+1,b.block);continue}const N=Gt(C);if(On(b.block)&&x&&N!==void 0&&N<S)continue;if(N!==void 0&&(S===void 0||N>=S)&&We(b.block)===void 0){const me=o.findIndex(V=>{const we=Gt(Qe(V));return we!==void 0&&we>N});if(me>=0){m.insertBefore(me,b.block);continue}}}const _=We(b.block);if(!(On(b.block)&&_===void 0)&&!(On(b.block)&&b.turnId===void 0&&x&&w!==void 0&&_!==void 0&&_<w)){if(b.block.kind==="question"&&_!==void 0){k.push(b.block);continue}m.insertPreviousPosition(v,b.block,!0)||k.push(b.block)}}for(const[b,_]of p)for(const C of _.toSorted(Ht))m.insertBefore(b,C);return m.materialize(k,Ht)}function Qn(t,e,n){return t.kind!=="user"?!1:t.promptId===e||t.userMessageId===e||n!==void 0&&t.userMessageId===n}function mh(t,e){return t.kind==="user"&&t.turnId===void 0&&(t.promptId!==void 0?t.promptId===e.promptId:Qn(t,e.promptId,e.userMessageId))}function gh(t,e){return t===e?!0:t===void 0||e===void 0||t.length!==e.length?!1:t.every((n,s)=>{const i=e[s];return i!==void 0&&n.kind===i.kind&&n.url===i.url&&n.path===i.path&&n.name===i.name&&n.mime===i.mime&&n.size===i.size&&n.fileId===i.fileId})}function Zi(t,e,n,s){const i=dt(e.content,s?.contentRefs),r=n??i.media,o=r.length===0?void 0:r,a=e.status==="queued"?e.content:void 0,d=t.findIndex(x=>x.kind==="user"&&(x.userMessageId===e.user_message_id||x.promptId===e.prompt_id)),l=d<0?void 0:t[d],c=e.origin===void 0?l?.sourceOrigin:e.origin,u=s?.contentSource!==void 0&&(l?.contentSource===void 0||l.contentSource.kind==="marker"),f=u?s.contentSource:s?.contentSource??l?.contentSource,g=u?s.contentPending:s?.contentPending??l?.contentPending,h=s?.promptTextParts??bs(e.content)??l?.promptTextParts,v=c===void 0?{kind:"user"}:Qt({origin:c})??{kind:"unknown"},m=qt({text:i.text,presentation:i.presentation,role:"user",origin:v}),p=m.text,k=vn({id:e.user_message_id,classified:m,createdAt:e.created_at,media:r,contentSource:f,contentPending:g,promptTextParts:h,promptId:e.prompt_id,userMessageId:e.user_message_id,promptStatus:e.status}).map(x=>x.kind==="user"?{...x,queuedContent:a,sourceOrigin:c}:x),S=k.find(x=>x.kind==="user");if(l!==void 0&&m.lane!=="you"&&m.lane!=="peer")return Zi(t.filter(x=>x!==l),{...e,origin:c},n,s);if(d>=0){const x=t[d],b=Ja(x,{promptId:e.prompt_id,userMessageId:e.user_message_id,status:e.status})?void 0:e.status,_=La(e.user_message_id,e.created_at,m.reminders,x.turnId,m.origin?.kind==="injection"?m.origin:void 0,f),C=`reminder-${e.user_message_id}-`,F=V=>V.kind==="system-reminder"&&V.id.startsWith(C);if(x.promptStatus===b&&x.text===p&&Ae(x.presentation,i.presentation)&&gh(x.media,o)&&Ae(x.queuedContent,a)&&Ae(x.sourceOrigin,c)&&Ae(x.via,S?.via??x.via)&&Ae(x.contentSource,f)&&x.contentPending===g&&Ae(x.promptTextParts,h)&&Ae(t.filter(F),_))return t;const N=t.filter(V=>!F(V)),me=N.indexOf(x);return N.splice(me,1,{...x,text:p,presentation:i.presentation,promptStatus:b,media:o,queuedContent:a,sourceOrigin:c,contentSource:f,contentPending:g,promptTextParts:h,via:S?.via??x.via,agentMessage:S?.agentMessage,bridgedPeer:S?.bridgedPeer,peerThread:S?.peerThread},..._),N}const w=e.status==="running"?t.findLastIndex(x=>x.kind==="user"&&x.userMessageId===void 0&&x.promptId===void 0&&x.text===p):-1;if(w>=0&&k[0]?.kind==="user"){const x=t.slice();return x.splice(w,1,...k),x}return k.length===0?t:[...t,...k]}function vh(t,e,n){const s=[...t],i=s.findIndex(d=>Qn(d,e.promptId,e.userMessageId));if(i>=0){const d=s[i];if(d.kind!=="user")return s;const l=d.userMessageId??e.userMessageId;if(d.userMessageId===l&&d.promptStatus===n&&d.queuedContent===void 0)return s;const c=l??d.id.replace(/^user-/,"");return s[i]={...d,id:`user-${c}`,promptId:d.promptId??e.promptId,userMessageId:l,promptStatus:n,queuedContent:void 0},s}const r=s.findLastIndex(d=>d.kind==="user"&&d.turnId!==void 0&&d.promptId===void 0&&d.userMessageId===void 0);if(r<0)return s;const o=s[r],a=e.userMessageId??o.userMessageId??o.id.replace(/^user-/,"");return s[r]={...o,id:`user-${a}`,promptId:e.promptId,userMessageId:e.userMessageId??o.userMessageId,promptStatus:n},s}function yh(t,e,n){if(e===void 0)return[...t];if(t.some(i=>i.id===e.id||i.kind==="user"&&Qn(i,e.promptId??"",e.userMessageId)))return[...t];const s=[...t];return nh(s,e,n)||sh(s,e),s}function kh(t){const e=new Map;for(const n of t){if(n.userMessageId===void 0||n.status==="aborted"&&n.abortedBeforeStart===!0)continue;const s=ve(n.finishedAt??n.createdAt)??0,i=e.get(n.userMessageId);(i===void 0||s>i)&&e.set(n.userMessageId,s)}return e}function Ih(t,e){if(t.userMessageId===void 0)return!1;const n=ve(t.finishedAt??t.createdAt)??0;return(e.get(t.userMessageId)??n)>n}function Vt(t,e,n){if(e===void 0)return;const s=t.get(e);s===void 0?t.set(e,[n]):s.includes(n)||s.push(n)}function Ln(t){const e=[...t],n=new Set,s=new Map,i=new Map,r=[];for(let o=0;o<e.length;o+=1){const a=e[o];a.kind==="user"&&(Vt(s,a.promptId,o),Vt(i,a.userMessageId,o),a.turnId!==void 0&&a.promptId===void 0&&a.userMessageId===void 0&&r.push(o))}return{slots:e,removed:n,byPromptId:s,byUserMessageId:i,unattributedTurnUserIndices:r}}function _s(t,e,n){const s=[],i=r=>{if(t.removed.has(r)||s.includes(r))return;const o=t.slots[r];o?.kind==="user"&&Qn(o,e,n)&&s.push(r)};for(const r of t.byPromptId.get(e)??[])i(r);for(const r of t.byUserMessageId.get(e)??[])i(r);if(n!==void 0)for(const r of t.byUserMessageId.get(n)??[])i(r);return s.sort((r,o)=>r-o),s}function Ga(t,e,n){const s=_s(t,e.promptId,e.userMessageId);if(s.length>0){const i=s[0],r=t.slots[i];if(r?.kind!=="user")return;const o=r.userMessageId??e.userMessageId;if(r.userMessageId===o&&r.promptStatus===n&&r.queuedContent===void 0)return;const a=o??r.id.replace(/^user-/,""),d=r.promptId??e.promptId;t.slots[i]={...r,id:`user-${a}`,promptId:d,userMessageId:o,promptStatus:n,queuedContent:void 0},Vt(t.byPromptId,d,i),Vt(t.byUserMessageId,o,i);return}for(;t.unattributedTurnUserIndices.length>0;){const i=t.unattributedTurnUserIndices.at(-1),r=t.slots[i];if(t.removed.has(i)||r?.kind!=="user"||r.turnId===void 0||r.promptId!==void 0||r.userMessageId!==void 0){t.unattributedTurnUserIndices.pop();continue}t.unattributedTurnUserIndices.pop();const o=e.userMessageId??r.userMessageId??r.id.replace(/^user-/,""),a=e.userMessageId??r.userMessageId;t.slots[i]={...r,id:`user-${o}`,promptId:e.promptId,userMessageId:a,promptStatus:n},Vt(t.byPromptId,e.promptId,i),Vt(t.byUserMessageId,a,i);return}}function Qa(t,e){Ga(t,e,void 0);const n=_s(t,e.promptId,e.userMessageId);if(n.length!==0){if(n[0],n.length>1){const s=n.find(r=>t.slots[r].turnId!==void 0)??n[0],i=t.slots[s].id;for(const r of n)t.slots[r].id!==i&&t.removed.add(r)}for(const s of n){if(t.removed.has(s))continue;const i=t.slots[s];(i.promptStatus!==void 0||i.queuedContent!==void 0)&&(t.slots[s]={...i,promptStatus:void 0,queuedContent:void 0})}}}function ds(t){return t.removed.size===0?t.slots:t.slots.filter((e,n)=>!t.removed.has(n))}function wh(t,e){const n=e.filter(i=>i.status==="completed");if(n.length===0)return[...t];const s=Ln(t);for(const i of n)Qa(s,i);return ds(s)}function Ja(t,e){return t!==void 0&&t.userMessageId!==void 0&&t.userMessageId===e.userMessageId&&t.promptId!==void 0&&t.promptId!==e.promptId}const bh="notice-prompt-outcomes-earlier";function Sh(t,e){const n=new Map,s=new Set;let i;for(const r of e){if(r.kind==="marker"){const c=r;if(c.marker==="message.delivery"){const u=typeof c.payload=="object"&&c.payload!==null?c.payload:void 0,f=(u===void 0?void 0:je(u,"messageId"))??(c.markerId?.startsWith("message-delivery:")?c.markerId.slice(17):void 0);f!==void 0&&s.add(f)}continue}if(r.kind!=="turn")continue;const o=r,a=ve(o.startedAt);a!==void 0&&(i===void 0||a<i)&&(i=a);const d=Wa(o.origin),l={turnId:o.turnId,error:o.error,errorDetails:o.errorDetails};for(const c of[o.promptId,d.promptId,d.userMessageId,Ei(o)])c!==void 0&&(n.set(c,l),s.add(c))}if(i===void 0)for(const r of t){const o=r.kind==="user"?ve(r.createdAt):void 0;o!==void 0&&(i===void 0||o<i)&&(i=o)}return{windowStartMs:i,turns:n,historyIds:s}}function Ya(t,e,n){const s=e.turns.get(t.promptId)??(t.userMessageId===void 0?void 0:e.turns.get(t.userMessageId)),i=s!==void 0||n?.turnId!==void 0,r=i||n?.promptOutcome?.inHistory===!0||n?.contentSource?.kind==="marker"||n?.contentSource?.kind==="turn"||n?.contentSource?.kind==="frame"||e.historyIds.has(t.promptId)||t.userMessageId!==void 0&&e.historyIds.has(t.userMessageId)||n?.userMessageId!==void 0&&e.historyIds.has(n.userMessageId);return{status:t.status,at:t.finishedAt,error:s?.error??t.error,errorDetails:s?.errorDetails??t.errorDetails,delivered:i,inHistory:r}}function ho(t,e,n){const s=yn(e.content),i=e.contentRefs?.some(k=>k.path[0]==="content")===!0,r=bs(e.content,e.contentRefs),o=s.length>0?dt(s,e.contentRefs):void 0,a=o===void 0?void 0:qt({text:o.text,presentation:o.presentation,role:"user",origin:t.sourceOrigin!==void 0?Qt({origin:t.sourceOrigin})??{kind:"user"}:Qt(e)??{kind:"user"}}),d=t.contentSource===void 0||t.contentSource.kind==="marker"||t.contentSource.kind==="prompt"&&t.contentSource.id===e.promptId,l=a!==void 0&&(t.turnId===void 0?a.text.length>=t.text.length||t.contentSource?.kind==="marker"&&t.contentPending===!0&&!i:a.text.length>t.text.length&&d),c=l?a.text:t.text,u=l?a.presentation??t.presentation:t.presentation??a?.presentation,f=t.media!==void 0&&t.media.length>0?t.media:o!==void 0&&o.media.length>0?o.media:t.media,g=s.length>0||i?{kind:"prompt",id:e.promptId}:void 0,h=g!==void 0&&d&&(l||s.length===0||t.contentSource?.kind==="prompt"||t.contentPending===!0&&i),v=h?g:t.contentSource,m=v?.kind==="prompt"&&v.id===e.promptId?(l||s.length===0||t.contentPending===!0)&&i:t.contentPending,p=h&&l?r:t.promptTextParts;return{...t,text:c,presentation:u,media:f,promptId:t.promptId??e.promptId,userMessageId:t.userMessageId??e.userMessageId,contentSource:v,contentPending:m,promptTextParts:p,promptStatus:void 0,queuedContent:void 0,promptOutcome:Ya(e,n,t)}}function xh(t){const e=t.toSorted((n,s)=>(ve(n.finishedAt??n.createdAt)??0)-(ve(s.finishedAt??s.createdAt)??0)).map(n=>{const s=Ji(dt(yn(n.content),n.contentRefs).text).text;return{promptId:n.promptId,userMessageId:n.userMessageId,status:n.status,at:n.finishedAt,text:s===""?void 0:s.slice(0,280)}});return{kind:"notice",id:bh,text:`${e.length} earlier prompts did not complete`,tone:"neutral",i18n:{key:"notice.earlierPromptOutcomes",params:{count:e.length}},earlierPromptOutcomes:e}}function _h(t,e,n=[],s=[],i){if(e.length===0)return t;const r=Sh(t,s),o=kh(e),a=new Map,d=new Map;for(const m of n)m.kind==="user"&&(m.promptId!==void 0&&!a.has(m.promptId)&&a.set(m.promptId,m),m.userMessageId!==void 0&&!d.has(m.userMessageId)&&d.set(m.userMessageId,m));const l=m=>a.get(m.promptId)??d.get(m.promptId)??(m.userMessageId===void 0?void 0:d.get(m.userMessageId));let c=Ln(t);const u=()=>{const m=ds(c);return c=Ln(m),m},f=[],g=[],h=[];for(const m of e){if(m.originKind==="cron_job")continue;if(m.status==="completed"){Qa(c,m);continue}if(m.status==="aborted"||m.status==="failed"||m.status==="blocked"){const _=_s(c,m.promptId,m.userMessageId);if(m.status==="aborted"&&m.abortedBeforeStart===!0){for(const ee of _)mh(c.slots[ee],m)&&c.removed.add(ee);continue}for(const ee of _){const re=c.slots[ee];(re.promptStatus!==void 0||re.queuedContent!==void 0)&&(c.slots[ee]={...re,promptStatus:void 0,queuedContent:void 0})}if(Ih(m,o))continue;const C={...m,status:m.status};if(_.length>0){const ee=_[0],re=c.slots[ee],le=ho(re,C,r);c.slots[ee]=le,Vt(c.byPromptId,le.promptId,ee),Vt(c.byUserMessageId,le.userMessageId,ee);continue}const F=l(C);if(F!==void 0&&F.turnId===void 0){f.push(ho(F,C,r));continue}const N=ve(C.createdAt);if(!(r.windowStartMs===void 0||N!==void 0&&N>=r.windowStartMs)||r.turns.has(C.promptId)){h.push(C);continue}const V=yn(C.content),we=C.contentRefs?.some(ee=>ee.path[0]==="content")===!0;if(V.length===0&&!we){h.push(C);continue}const ye=dt(V,C.contentRefs),Fe=C.userMessageId??C.promptId,te=vn({id:Fe,classified:qt({text:ye.text,presentation:ye.presentation,role:"user",origin:Qt(C)??{kind:"user"}}),createdAt:C.createdAt,media:ye.media,promptId:C.promptId,userMessageId:C.userMessageId,contentSource:{kind:"prompt",id:C.promptId},contentPending:we,promptTextParts:bs(C.content,C.contentRefs)});for(const ee of te)g.push(ee.kind==="user"?{...ee,promptOutcome:Ya(C,r)}:ee);continue}if(m.status!=="queued"&&m.status!=="running")continue;const p=yn(m.content),k=dt(p,m.contentRefs),S=m.contentRefs?.some(_=>_.path[0]==="content")===!0;if(m.status==="running"){const _=l(m);if(Ja(_,m)){const C=yh(ds(c),_,n),F=vh(C,m,void 0);c=Ln(F);continue}if(Ga(c,m,"running"),_s(c,m.promptId,m.userMessageId).some(C=>c.slots[C].turnId!==void 0)||p.length===0&&!S)continue}if(m.steeredAt!==void 0||p.length===0&&m.userMessageId===void 0&&!S)continue;const w={prompt_id:m.promptId,user_message_id:m.userMessageId??m.promptId,status:m.status,content:p.length>0?p:[{type:"text",text:k.text}],created_at:m.createdAt,append_timing:m.appendTiming,revision:m.revision};let x=[...Zi(u(),w,k.media.length>0?k.media:void 0,{contentSource:{kind:"prompt",id:m.promptId},contentPending:S,promptTextParts:bs(m.content,m.contentRefs),contentRefs:m.contentRefs})];const b=m.status==="running"?r.turns.get(m.promptId):void 0;if(b!==void 0){const _=x.findIndex(F=>F.kind==="user"&&F.turnId===void 0&&Qn(F,m.promptId,m.userMessageId)),C=x.findIndex(F=>gt(Qe(F),b.turnId));if(_>=0&&C>=0&&C<_){const F=x[_];x.splice(_,1),x.splice(C,0,{...F,turnId:b.turnId})}}c=Ln(x)}let v=ds(c);if(f.length>0||g.length>0){const m=new Map;for(let w=0;w<v.length;w+=1)m.set(v[w].id,w);const p=Sn(n,m),k=new rn(v,i),S=[...g];for(const w of f)k.insertPreviousPosition(p,w,!0)||S.push(w);v=k.materialize(S,Ht)}return h.length>0&&(v=[xh(h),...v]),v}function Th(t,e){const n=new Set;for(const d of e)d.kind==="user"&&(d.promptId!==void 0&&n.add(`p:${d.promptId}`),d.userMessageId!==void 0&&n.add(`u:${d.userMessageId}`));const s=[];for(const d of t)d.kind==="user"&&(d.promptStatus!=="queued"&&d.promptStatus!=="running"||d.promptId!==void 0&&n.has(`p:${d.promptId}`)||d.userMessageId!==void 0&&n.has(`u:${d.userMessageId}`)||(d.promptId!==void 0||d.userMessageId!==void 0)&&s.push(d));if(s.length===0)return e;const i=new Map;for(let d=0;d<e.length;d+=1)i.set(e[d].id,d);const r=Sn(t,i),o=new rn(e),a=[];for(const d of s)o.insertPreviousPosition(r,d,!0)||a.push(d);return o.materialize(a,Ht)}function Ch(t,e){const n=new Set,s=new Set;for(const i of e)i.status!=="aborted"||i.abortedBeforeStart!==!0||(n.add(i.promptId),i.userMessageId!==void 0&&s.add(i.userMessageId));return n.size===0?[...t]:t.filter(i=>i.kind!=="user"||i.turnId!==void 0?!0:i.promptId!==void 0?!n.has(i.promptId):i.userMessageId===void 0||!n.has(i.userMessageId)&&!s.has(i.userMessageId))}function Rh(t,e){return t.length===0||e.length===0?e:Xa(t,e)}function Xa(t,e){let n,s=t.length===e.length;const i=e.map((r,o)=>{let a=t[o];return a?.id!==r.id&&(s=!1,n??=new Map(t.map(d=>[d.id,d])),a=n.get(r.id)),a!==void 0&&Ae(a,r)?a:(s=!1,r)});return s?t:i}function Bt(t,e){return Ae(t,e)?t:e}function Ah(t){const e=t.execution;if(typeof e!="object"||e===null)return;const n=e,s=n.executorId??n.executor_id,i=n.protocol;if(typeof s!="string"||s===""||typeof i!="string"||i==="")return;const r=n.resumeMode??n.resume_mode,o=n.profileDelivery??n.profile_delivery,a=Array.isArray(n.losses)?n.losses.filter(d=>typeof d=="string"):[];return{executorId:s,protocol:i,resumeMode:typeof r=="string"?r:void 0,...typeof o=="string"&&o!==""?{profileDelivery:o}:{},fidelity:n.fidelity==="degraded"?"degraded":"full",losses:a}}function Mh(t,e){return t!==void 0&&t.executorId===e.executorId&&t.protocol===e.protocol&&t.resumeMode===e.resumeMode&&t.profileDelivery===e.profileDelivery&&t.fidelity===e.fidelity&&t.losses.length===e.losses.length&&t.losses.every((n,s)=>n===e.losses[s])}function po(t){if(t.state!=="completed"&&t.state!=="failed"&&t.state!=="cancelled"||t.endedAt===void 0)return;const e=t.steps.find(s=>s.timing?.llmFirstTokenLatencyMs!==void 0)?.timing,n=t.steps.reduce((s,i)=>s+(i.usage?.output??0),0);return{turnId:t.turnId,state:t.state,cancellation:t.state==="cancelled"?t.cancellation??"unknown":void 0,error:t.error,errorDetails:t.errorDetails,endedAt:t.endedAt,durationMs:t.durationMs,ttftMs:e?.llmFirstTokenLatencyMs,usage:t.usage===void 0?void 0:{inputOther:t.usage.inputTokens??0,output:t.usage.outputTokens??0,inputCacheRead:0,inputCacheCreation:0},tokensPerSecond:t.durationMs!==void 0&&t.durationMs>0&&n>0?n/t.durationMs*1e3:void 0}}function Ph(t){if(t===void 0||t.state!=="running")return;const e=t.steps.at(-1);if(!(e?.state!=="running"||e.retry===void 0))return{failedAttempt:e.retry.failedAttempt,maxAttempts:e.retry.maxAttempts,delayMs:e.retry.delayMs,errorName:e.retry.errorName,statusCode:e.retry.statusCode}}function Za(t,e){if(t.state!=="failed")return!1;const n=t.error?.trim(),s=e.trim();return n===void 0||n===""||s===""?!1:n===s||n.includes(s)}function Eh(t,e){if(e?.kind!=="turn"||e.turnId===void 0||e.state!=="failed")return;const n=t.findLastIndex(s=>s.kind==="user");for(let s=t.length-1;s>=0;s-=1){const i=t[s];i.kind==="notice"&&i.tone==="danger"&&i.compactionPhase===void 0&&i.compactionFailure===void 0&&i.taskRef===void 0&&(i.turnId===e.turnId||i.turnId===void 0&&s>n)&&(i.id.startsWith("agent-frame-")&&Za(e,i.text)||i.i18n?.key==="notice.turnFailedDetail"||i.i18n?.key==="notice.turnFailed"||i.i18n?.key==="notice.promptFailed")&&t.splice(s,1)}}function er(t){if(t.state!=="failed"&&t.state!=="cancelled")return;const e=t.steps.findLast(n=>n.retry!==void 0)?.retry;return{turnId:t.turnId,state:t.state,endedAt:t.endedAt,error:t.error,errorDetails:t.errorDetails,lastRetry:e}}function ed(t){const e=t.items.findLast(r=>r.kind==="turn");if(e?.kind!=="turn")return;const n=t.meta?.agent?.phase,s=n!==void 0&&"turnId"in n?n.turnId:void 0,i="ordinal"in e&&typeof e.ordinal=="number"?e.ordinal:Number(e.turnId.replace(/^t/,""));if(!(typeof s=="number"&&s>i))return er(e)}const Di=new WeakMap,qi=new WeakMap;function Oh(t){const e=t.state;return e==="completed"||e==="failed"||e==="cancelled"}function td(t){for(const e of t.frames){const n=e.attachmentIds;if(n!==void 0&&n.length>0)return!0}return!1}function Dh(t){if(t.attachmentIds!==void 0&&t.attachmentIds.length>0)return!0;for(const e of t.steps)if(td(e))return!0;return!1}function nd(t){for(const e of t.frames){const n=e;if(n.kind==="tool"&&typeof n.taskId=="string"&&n.taskId!=="")return!0}return!1}function qh(t){return t.steps.some(nd)}function Fh(t){if(t.state==="running"||td(t)||nd(t))return!1;for(const e of t.frames){const n=e;if(n.state==="running"||n.kind==="tool"&&typeof n.toolCallId=="string"&&!n.toolCallId.startsWith("external:")&&(n.name==="Bash"||n.view==="shell")&&Ua(e)===void 0)return!1}return!0}function Nh(t,e,n){const s=Di.get(t);if(s!==void 0){s.set(e,n);return}Di.set(t,new Map([[e,n]]))}function $h(t,e,n){const s=qi.get(t);if(s!==void 0){s.set(e,n);return}qi.set(t,new Map([[e,n]]))}const mo=new WeakMap;function jh(t,e=[]){const n=[],s=[],i=[],r=new Set,o=t.agent_id!==M,a=t.meta?.agent?.phase,d=t.prompts??[],l=t.tasks??[],c=new Map(l.map(I=>[I.taskId,I])),u=new Set,f=new Map,g=new Map;for(let I=e.length-1;I>=0;I-=1){const y=e[I];y.kind==="shell"&&y.commandId!==void 0&&y.command!==void 0&&!g.has(y.commandId)&&g.set(y.commandId,y.command)}const h=t.attachments??[],v=h.length===0?void 0:new Map(h.map(I=>[I.attachmentId,I])),m=If(t.items),p=I=>"ordinal"in I?I.ordinal:Number(I.turnId.replace(/^t/,""));let k;const S=[],w=[];for(const I of t.items){if(I.kind==="marker"){const L=m.get(I.markerId);if(L==="hidden")continue;const _e=ve(I.at)===void 0?n:i;if(L==="pending"){_e.push({kind:"notice",id:`agent-marker-${I.markerId}`,text:I.marker,tone:"neutral",createdAt:I.at,i18n:{key:"notice.compacting"}});continue}if(I.marker==="message.delivery"&&typeof I.payload=="object"&&I.payload!==null){const Ne=I.payload,nt=I.contentRefs?.some(qe=>qe.path[0]==="payload")===!0,ge=je(Ne,"messageId")??(I.markerId.startsWith("message-delivery:")?I.markerId.slice(17):void 0),O=je(Ne,"text")??(nt?"":void 0),Se=zn(Ne.presentation);if(ge!==void 0&&O!==void 0){const qe=vn({id:ge,classified:qt({text:O,presentation:Se,role:"user",origin:Qt(Ne),subagentPromptAsUser:o}),createdAt:I.at??"",turnId:fe(Ne.turnId),userMessageId:ge,contentSource:{kind:"marker",id:I.markerId},contentPending:nt,media:Qs(En(Array.isArray(Ne.attachmentIds)?Ne.attachmentIds.filter(et=>typeof et=="string"):void 0,v,t.agent_id),Se)});for(const et of qe)r.add(et);_e.push(...qe)}continue}const Z=Qf(I);Z!==void 0&&_e.push(Z);continue}if(I.kind==="taskref"){const L=c.get(I.taskId);if(L===void 0||L.kind==="subagent")continue;if(L.kind==="shell"){S.push({item:I,task:L});continue}w.push({item:I,task:L});continue}if(I.kind!=="turn")continue;(k===void 0||p(I)<p(k))&&(k=I);const y=Oh(I),R=y&&!Dh(I)&&!qh(I);if(R){const L=Di.get(I)?.get(t.agent_id),_e=mo.get(I);if(L!==void 0&&_e!==void 0){n.push(...L);for(const[Z,Ne]of _e.frameTimes)f.set(Z,Ne);for(const Z of _e.shellFrameTaskIds)u.add(Z);continue}}const z=[],W=[],B=n.length,K=Pi(I),$=Wa(K),se=zn(I.presentation),ce=Ei(I)??$.userMessageId,Te=Qs(En(I.attachmentIds,v,t.agent_id),se),ke=I.contentRefs?.some(L=>["prompt","presentation","origin","attachmentIds"].includes(String(L.path[0])))===!0;let D=!1,De,tt;const Me=!!I.prompt?.trim(),Ie=!Me&&ce!==void 0&&((Te?.length??0)>0||ke)&&I.steps.some(L=>L.frames.some(_e=>_e.kind==="text"&&_e.role==="user"&&Gs(_e)===ce));if(Me||!Ie&&((Te?.length??0)>0||ke)){const L=vn({id:ce??`agent-turn-${I.turnId}-prompt`,classified:qt({text:I.prompt??"",presentation:se,role:"user",origin:K,subagentPromptAsUser:o}),createdAt:I.delivery?.deliveredAt??I.startedAt??"",turnId:I.turnId,contentSource:{kind:"turn",id:I.turnId},contentPending:ke,promptId:I.promptId??$.promptId,userMessageId:ce,media:Te}),_e=L.findIndex(Z=>Z.kind==="user");D=_e>=0,D&&(De=n.length+_e),n.push(...L)}const ae="state"in I&&I.state==="cancelled",ze=ae?I.steps.flatMap(L=>L.frames).findLast(L=>Jr(L))?.frameId:void 0,de=y?void 0:`${t.agent_id}\0${I.turnId}\0${D?ce??"":""}\0${Ei(I)??""}\0${I.startedAt??""}\0${I.endedAt??""}\0${I.durationMs??""}`;for(const L of I.steps){if(de!==void 0&&(!("state"in L)||L.state!=="running")){const O=qi.get(L)?.get(de);if(O!==void 0){n.push(...O.blocks),tt??=O.openingVia;for(const Se of O.frameTimes)f.set(Se[0],Se[1]),z.push([Se[0],Se[1]]);for(const Se of O.shellFrameTaskIds)u.add(Se),W.push(Se);continue}}const _e=n.length,Z=[];let Ne;const nt=[];let He,ge;for(let O=L.frames.length-1;O>=0;O-=1){const Se=L.frames[O];if(He===void 0&&Se.kind==="text"&&(He=Se.frameId),ge===void 0&&Yr(Se)&&(ge=Se.frameId),He!==void 0&&ge!==void 0)break}for(const O of L.frames){const Se=ve("startedAt"in O?O.startedAt:L.startedAt)??ve(L.startedAt);if(Se!==void 0&&(f.set(O.frameId,Se),z.push([O.frameId,Se]),Z.push([O.frameId,Se])),O.kind==="tool"){const qe=O.taskId;qe!==void 0&&c.get(qe)?.kind==="shell"&&(u.add(qe),W.push(qe),nt.push(qe))}switch(O.kind){case"text":if(O.role==="user"){const qe=Hf(O),et=Pi(I),It=O.taskId!==void 0?{kind:"task",taskId:O.taskId}:void 0,St=qe??It??(za(et)?et:void 0),$e=zn(O.presentation),lt=Gs(O);if(D&&lt!==void 0&&ce!==void 0&&lt===ce){Ne??=Ha(qe);break}n.push(...vn({id:lt??`agent-frame-${O.frameId}`,classified:qt({text:O.text,presentation:$e,role:"user",origin:St,id:O.frameId,subagentPromptAsUser:o}),createdAt:O.delivery?.deliveredAt??L.startedAt??I.startedAt??"",turnId:I.turnId,contentSource:{kind:"frame",id:O.frameId,turnId:I.turnId,stepId:L.stepId},contentPending:O.contentRefs?.some(yt=>["text","presentation","origin","attachmentIds"].includes(String(yt.path[0]))),userMessageId:lt,media:Qs(En(O.attachmentIds,v,t.agent_id),$e)}));break}{if(!Jr(O))break;const qe=Gs(O)??L.stepId;n.push({kind:"assistant",id:`agent-frame-${O.frameId}`,frameId:O.frameId,stepId:L.stepId,text:O.text,streaming:Xr(I,L,O,He,a),stopped:ae&&O.frameId===ze,createdAt:L.endedAt??I.endedAt,turnId:I.turnId,messageId:qe,media:En(O.attachmentIds,v,t.agent_id)})}break;case"thinking":if(!Yr(O))break;n.push({kind:"thinking",responseInstanceId:O.responseInstanceId??(O.recordedStepId!==L.stepId||L.providerResponseId===void 0?void 0:`provider:${L.providerResponseId}`),id:`agent-frame-${O.frameId}`,frameId:O.frameId,stepId:L.stepId,text:O.text,streaming:Xr(I,L,O,ge,a),createdAt:L.endedAt??I.endedAt,turnId:I.turnId});break;case"tool":{const qe=ve(O.startedAt),et=ve(O.endedAt),It=O,St=It.taskId===void 0?void 0:c.get(It.taskId),$e=St?.kind==="shell"?St:void 0;if(!O.toolCallId.startsWith("external:")&&(It.name==="Bash"||It.view==="shell"||It.taskId!==void 0&&It.name.toLowerCase().includes("shell"))&&($e!==void 0||O.output!==void 0||O.inputText!==void 0||typeof O.input=="object")){const Ft=g.get(O.toolCallId),Nt=Ua(O)??Ft,zt=typeof O.output=="string"?O.output:Yf(O.output,O.state==="error")??ta(O.error)??"",At=$e?.outputTail!==""&&$e?.outputTail!==void 0,$t=At?$e.outputTail:zt;n.push({kind:"shell",id:`shell-${O.toolCallId}`,frameId:O.frameId,stepId:L.stepId,outputTaskId:At?$e.taskId:void 0,commandId:O.toolCallId,command:Nt,output:$t,outputDetail:At&&$e.detailRef!==void 0?{agentId:t.agent_id,taskId:$e.taskId}:void 0,done:$e===void 0?O.state!=="running":$e.state!=="running",isError:$e===void 0?O.state==="error":$e.state==="failed"||$e.state==="timed_out"||$e.state==="killed"||$e.state==="lost",startedAt:ve($e?.startedAt)??qe,turnId:I.turnId});break}const yt={kind:"tool",id:`tool-${O.toolCallId}`,frameId:O.frameId,stepId:L.stepId,toolCallId:O.toolCallId,name:O.name,argsText:O.inputText??"",args:O.input,display:O.display,description:void 0,status:O.state==="error"?"error":O.state==="interrupted"?"stopped":O.state,output:O.output??O.error,outputPending:O.contentRefs?.some(Ft=>Ft.path[0]==="output"),media:En(O.attachmentIds,v,t.agent_id),isError:O.state==="error",errorCode:O.errorCode,startedAt:qe,durationMs:qe!==void 0&&et!==void 0?Math.max(0,et-qe):I.durationMs,durationSource:qe!==void 0&&et!==void 0?"frame":I.durationMs===void 0?void 0:"turn",progressText:O.progress?.text,agentRefs:O.agentRefs,turnId:I.turnId},pt=Ba(yt);n.push(...pt.length===0?[yt]:pt);break}case"notice":if(o&&O.level==="error"&&Za(I,O.message))break;n.push({kind:"notice",id:`agent-frame-${O.frameId}`,turnId:I.turnId,text:O.message,tone:O.level==="error"?"danger":"neutral",errorDetails:Gf("detail"in O?O.detail:void 0)});break}}tt??=Ne,de!==void 0&&Fh(L)&&$h(L,de,{blocks:n.slice(_e),frameTimes:Z,shellFrameTaskIds:nt,openingVia:Ne})}if(De!==void 0&&tt!==void 0){const L=n[De];L?.kind==="user"&&L.via===void 0&&(n[De]={...L,via:tt})}const J=o?er(I):void 0;if(J!==void 0&&(n.push({kind:"notice",id:`agent-turn-outcome-${I.turnId}`,turnId:I.turnId,createdAt:I.endedAt,text:J.error??"",tone:J.state==="failed"?"danger":"neutral",errorDetails:J.errorDetails,i18n:{key:J.state==="failed"?"notice.turnFailedDetail":"notice.turnCancelledDetail",params:{detail:J.error===void 0?"":`: ${J.error}`}}}),J.lastRetry!==void 0&&J.error===void 0)){const L=J.lastRetry;n.push({kind:"notice",id:`agent-turn-last-retry-${I.turnId}`,turnId:I.turnId,createdAt:I.endedAt,text:L.errorMessage,tone:"neutral",i18n:{key:"transcript.lastRetryFailed",params:{cause:L.errorName,error:L.errorMessage,attempt:String(L.failedAttempt),max:String(L.maxAttempts)}}})}R&&(Nh(I,t.agent_id,n.slice(B)),mo.set(I,{frameTimes:z,shellFrameTaskIds:W}))}o||Eh(n,t.items.findLast(I=>I.kind==="turn"));for(const{item:I,task:y}of S)u.has(y.taskId)||s.push({kind:"shell",id:`shell-${y.taskId}`,commandId:y.taskId,command:y.command,commandTaskId:y.taskId,turnId:fe(y.ownerTurnId),output:y.outputTail,outputTaskId:y.taskId,outputDetail:y.detailRef===void 0?void 0:{agentId:t.agent_id,taskId:y.taskId},done:y.state!=="running",isError:y.state==="failed"||y.state==="timed_out"||y.state==="killed"||y.state==="lost",startedAt:ve(I.at??y.startedAt)});const x=ve(k?.startedAt),b=k===void 0?0:p(k);for(const{item:I,task:y}of w){const R=fe(y.ownerTurnId),z=Gt(R),W=I.at??y.startedAt,B=ve(W);if(k!==void 0&&b>0&&(z!==void 0&&z<b||z===void 0&&x!==void 0&&B!==void 0&&B<x))continue;const K=y.state==="failed"||y.state==="lost"||y.state==="timed_out",$=y.error??y.stateReason,se=$===void 0?void 0:$.replace(/^(?:Error:\s*){2,}/i,"Error: ").trim(),ce=K&&se!==void 0&&se!==""?`${y.description??y.taskId} — ${se}`:y.description??y.taskId;s.push({kind:"notice",id:`agent-taskref-${I.refId}`,text:ce,tone:K?"danger":"neutral",createdAt:W,turnId:R,taskRef:{taskId:y.taskId,kind:y.kind,state:y.state}})}const _=new Map,C=new Map;for(const I of d)if(I.steeredAt!==void 0&&(_.has(I.promptId)||_.set(I.promptId,I),I.status==="completed")){const y=C.get(I.steeredAt);y===void 0?C.set(I.steeredAt,[I]):y.push(I)}let F;if(C.size>0){F=new Set;for(const I of n)!r.has(I)&&I.kind==="user"&&I.turnId!==void 0&&I.userMessageId!==void 0&&F.add(I.userMessageId)}const N=C.size===0?n:n.flatMap(I=>{if(r.has(I))return[I];if(I.kind!=="user"||I.turnId===void 0||I.userMessageId===void 0)return[I];const y=_.get(I.userMessageId);if(y?.steeredAt===void 0)return[I];const R=C.get(y.steeredAt);if(R===void 0||R.length<2||R[0]?.promptId!==y.promptId||R.slice(1).some(B=>F.has(B.promptId)))return[I];const z=R.map(B=>yn(B.content));return z.flat().filter(B=>B.type==="text").map(B=>B.text).join("")!==I.text?[I]:R.map((B,K)=>{const $=dt(z[K]);return{...I,id:`user-${B.userMessageId??B.promptId}`,text:$.text,presentation:$.presentation,media:$.media.length>0?$.media:void 0,userMessageId:B.userMessageId??B.promptId,promptId:B.promptId,contentSource:{kind:"prompt",id:B.promptId}}})}),me=new Set;for(const I of N)r.has(I)||me.add(I.id);const V=N.filter(I=>!r.has(I)||!me.has(I.id));let we;if(i.length===0)we=V;else{const I=ve(k?.startedAt),y=k===void 0?0:p(k),R=new Map,z=H=>(R.has(H)||R.set(H,"frameId"in H&&H.frameId!==void 0?f.get(H.frameId)??We(H):We(H)),R.get(H)),W=Array.from({length:V.length}),B=new Set,K=new Map,$=new Map,se=new Set;for(const H of d)H.promptId!==void 0&&se.add(H.promptId),H.userMessageId!==void 0&&se.add(H.userMessageId);const ce=new Set;for(let H=0;H<V.length;H+=1){const Ie=V[H];ce.add(Ie.id);const ae=z(Ie);W[H]=ae,ae!==void 0&&B.add(ae);const ze=fe(Qe(Ie));ze!==void 0&&(K.has(ze)||K.set(ze,H),$.set(ze,H)),Ie.kind==="user"&&(Ie.promptId!==void 0&&se.add(Ie.promptId),Ie.userMessageId!==void 0&&se.add(Ie.userMessageId))}const Te=new Map;let ke;for(let H=t.items.length-1;H>=0;H-=1){const Ie=t.items[H];if(Ie.kind==="turn")ke=Ie.turnId;else if(Ie.kind==="marker"){Te.set(`agent-marker-${Ie.markerId}`,ke);const ae=typeof Ie.payload=="object"&&Ie.payload!==null?je(Ie.payload,"messageId"):void 0;ae!==void 0&&Te.set(`user-${ae}`,ke)}}const D=H=>{if(H===void 0)return-1;const Ie=fe(H);return Ie===void 0?-1:K.get(Ie)??-1},De=new rn(V);let tt=0;const Me=new Map;for(const H of i.toSorted((Ie,ae)=>z(Ie)-z(ae))){if(r.has(H)&&ce.has(H.id))continue;const Ie=z(H),ae=H.kind==="system-reminder"||H.kind==="system"?H.ownerPromptId:void 0,ze=ae!==void 0&&se.has(ae);if(!ze&&k!==void 0&&y>0&&I!==void 0&&Ie<I)continue;for(;tt<V.length;){const ge=W[tt];if(ge!==void 0&&ge>Ie)break;tt+=1}const de=fe(Qe(H)),J=Gt(de);if(!ze&&k!==void 0&&y>0&&J!==void 0&&J<y)continue;const L=D(de),_e=de===void 0?void 0:$.get(de);let Z;if(L<0||tt>=L)Z=tt<V.length?tt:-1;else{let ge=Math.max(L,Me.get(de)??L);const O=_e??V.length-1;for(;ge<=O;){const Se=W[ge];if(Se!==void 0&&Se>Ie)break;ge+=1}Me.set(de,ge),Z=ge<=O?ge:O+1}const Ne=D(Te.get(H.id)),nt=(B.has(Ie)||B.size===0)&&Ne>=0?Ne:Z;let He=nt<0?V.length:nt;if(_e!==void 0&&He>_e+1)He=_e+1;else if(L<0&&J!==void 0){const ge=V.findIndex(O=>{const Se=Gt(Qe(O));return Se!==void 0&&Se>J});ge>=0&&He>ge&&(He=ge)}De.insertBefore(He,H),de!==void 0&&(L<0||He<L)&&K.set(de,He),H.kind==="user"&&(H.promptId!==void 0&&se.add(H.promptId),H.userMessageId!==void 0&&se.add(H.userMessageId)),B.add(Ie),ce.add(H.id)}we=De.materialize()}const ye=_h(we,d,e,t.items,f);let Fe;if(s.length===0)Fe=ye;else{const I=new Map;for(let B=0;B<ye.length;B+=1)I.set(ye[B].id,B);const y=Sn(e,I),R=new rn(ye,f),z=Ps(ye),W=[];for(const B of s){const K=fe(Qe(B)),$=K===void 0?void 0:z.get(K);if($!==void 0){const ce=Ss(ye,$,B)??$.last+1;R.insertBefore(Math.min(ce,$.last+1),B);continue}We(B)===void 0&&R.insertPreviousPosition(y,B,!0)||W.push(B)}Fe=R.materialize(W,Ht)}const te=dh(t,t.agent_id,Fe),ee=new Map;for(const I of te.events){if(I.anchorToolCallId===void 0)continue;const y=ee.get(I.anchorToolCallId)??new Set;y.add(I.subagentId),ee.set(I.anchorToolCallId,y)}const re=Fe.map(I=>{if(I.kind!=="tool")return I;const y=ee.get(I.toolCallId);if(y===void 0)return I;const R=[...I.agentRefs??[]];for(const z of y)R.some(W=>W.agentId===z)||R.push({agentId:z});return R.length===I.agentRefs?.length?I:{...I,agentRefs:R}}),le=k===void 0?void 0:{firstTurnOrdinal:p(k),firstTurnStartedMs:ve(k.startedAt)},Oe=lh(re,te.blocks,e,f),Ze=uh(Oe,te.events,e,f),Je=ph(Ze,t.interactions??[],t.agent_id,e,f,le),P=Kh(Gh(Uh(Je,t.items)),l);return Bh(Qh(Lh(P)))}function Bh(t){const e=[];for(const n of t){const s=e.at(-1);if(n.kind!=="thinking"||s?.kind!=="thinking"||n.responseInstanceId===void 0||n.responseInstanceId===""||s.responseInstanceId!==n.responseInstanceId||s.turnId!==n.turnId||s.stepId!==n.stepId){e.push(n);continue}const i=[...s.fragments??[s],...n.fragments??[n]];e[e.length-1]={...s,text:i.map(r=>r.text).join(`
21
+
22
+ `),streaming:i.some(r=>r.streaming),fragments:i}}return e}function Lh(t){const e=new Map;let n;for(const i of t)if(i.kind==="notice"){if(i.executor?.kind==="usage"){e.set(i.turnId??"",i.id);continue}i.executor?.kind==="session"&&i.executor.observed!==void 0&&(n=i.id)}if(e.size===0&&n===void 0)return[...t];const s=new Set(e.values());return n!==void 0&&s.add(n),t.flatMap(i=>{if(i.kind!=="notice")return[i];const r=i.executor;return r?.kind==="usage"?s.has(i.id)?[i]:[]:r?.kind==="session"&&r.observed!==void 0&&!s.has(i.id)?r.droppedImage===void 0?[]:[{...i,executor:{...r,observed:void 0}}]:[i]})}const Hh=new Set(["SessionStart","UserPromptSubmit","PreInvocation"]);function sd(t){return t===void 0?!1:Hh.has(t.slice(t.lastIndexOf(":")+1))}function zh(t){return t.kind==="system"&&t.variant==="hook_result"&&sd(t.hookEvent)}function Wh(t,e){for(let n=e-1;n>=0;n-=1){const s=t[n];if(!(s.kind==="system"||s.kind==="system-reminder"||s.kind==="notice"))return}for(let n=e+1;n<t.length;n+=1){const s=t[n];if(s.kind==="user"){const i=Qt({origin:s.sourceOrigin});if(i!==void 0&&i.kind!=="user")continue;return n}if(!(s.kind==="system"||s.kind==="system-reminder"||s.kind==="notice"))return}}function Uh(t,e){const n=new Map,s=new Map,i=new Map,r=new Set(e.flatMap(l=>l.kind==="turn"&&Pi(l)?.kind==="user"?[l.turnId]:[])),o=new Set;for(const[l,c]of t.entries()){const u=Qe(c);if(c.kind!=="user"){const g=c.kind==="system-reminder"||c.kind==="system"&&c.variant==="injection"||zh(c);u!==void 0&&!g&&o.add(u);continue}const f=Qt({origin:c.sourceOrigin});if(!(f!==void 0&&f.kind!=="user")){for(const[g,h]of[[c.promptId,n],[c.userMessageId,s]]){if(g===void 0)continue;const v=h.get(g)??[];v.push(l),h.set(g,v)}u!==void 0&&r.has(u)&&!i.has(u)&&!o.has(u)&&i.set(u,l)}}const a=new Map,d=new Set;for(const[l,c]of t.entries()){if(c.kind!=="system-reminder"&&c.kind!=="system"||c.kind==="system"&&c.variant!=="injection"&&!(c.variant==="hook_result"&&sd(c.hookEvent)))continue;let u;if(c.ownerPromptId!==void 0){const h=n.get(c.ownerPromptId)??s.get(c.ownerPromptId)??[],v=h.filter(m=>c.turnId!==void 0&&gt(Qe(t[m]),c.turnId));u=h.length===1?h[0]:v.length===1?v[0]:void 0}else c.turnId!==void 0?u=i.get(c.turnId):c.kind==="system"&&c.variant==="hook_result"&&(u=Wh(t,l));if(u===void 0||u<=l)continue;const f=a.get(u)??[],g=Qe(t[u]);f.push(g===c.turnId?c:{...c,turnId:g}),a.set(u,f),d.add(l)}return t.flatMap((l,c)=>d.has(c)?[]:[l,...a.get(c)??[]])}function Vh(t,e){if(t.variant!=="task")return!1;if(e?.taskKind==="question"||(t.taskId?.startsWith("question-")??!1))return!0;const n=t.taskNotification;return n===void 0?!1:n.answerRaw!==void 0||n.questionOutcome!==void 0||n.title!==void 0&&/^Background question\b/i.test(n.title)}function go(t,e,n){const s=t.taskNotification,i=e?.endedAt??t.createdAt??"";if(e?.state==="killed"||e?.state==="failed"||e?.state==="timed_out"||e?.state==="lost")return{kind:"cancelled",at:i,reason:e.error??e.stateReason??s?.stopReason};if(s?.questionOutcome==="dismissed"||s?.title!==void 0&&/\bdismissed\b/i.test(s.title))return{kind:"dismissed",at:i};if(s?.questionOutcome==="answered"||s?.answers!==void 0){let r;if(s.answerRaw!==void 0)try{const a=JSON.parse(s.answerRaw);if(typeof a=="object"&&a!==null&&!Array.isArray(a)){const d=a.answers;typeof d=="object"&&d!==null&&!Array.isArray(d)&&(r=Object.fromEntries(Object.entries(d).flatMap(([l,c])=>typeof c=="string"?[[l,c]]:[])))}}catch{r=void 0}const o=n.length>0&&r!==void 0?Xi(n,r)??s.answers:s.answers;return{kind:"answered",at:i,answers:o}}}function Kh(t,e){const n=new Map(e.map(a=>[a.taskId,a])),s=new Map,i=new Map,r=[...t];for(const[a,d]of r.entries())d.kind==="question"&&(i.set(d.request.question_id,a),d.request.tool_call_id!==void 0&&d.request.tool_call_id!==""&&s.set(d.request.tool_call_id,a));const o=new Set;for(const[a,d]of r.entries()){if(d.kind!=="system"||d.variant!=="task")continue;const l=d.taskId===void 0?void 0:n.get(d.taskId);if(!Vh(d,l))continue;const c=l?.toolCallId??l?.parentToolCallId,u=d.taskId?.endsWith("-background")?d.taskId.slice(0,-11):void 0,f=(c!==void 0?s.get(c):void 0)??(d.taskId!==void 0?i.get(d.taskId):void 0)??(u!==void 0?i.get(u):void 0);if(f!==void 0){const x=r[f],b=go(d,l,x.request.questions);b!==void 0&&(x.outcome===void 0?r[f]={...x,outcome:b}:x.outcome.kind==="answered"&&b.kind==="answered"&&x.outcome.answers===void 0&&b.answers!==void 0&&(r[f]={...x,outcome:{...x.outcome,answers:b.answers}})),o.add(a);continue}const g=d.taskNotification,h=l?.description??g?.description,v=g?.answers===void 0?[]:Object.entries(g.answers),m=v.length>0?v.map(([x,b],_)=>({id:`q_${_}`,question:x,options:[]})):h!==void 0&&h!==""?[{id:"q_0",question:h,options:[]}]:[],p=go(d,l,m);if(p===void 0||m.length===0)continue;const k=p.kind==="answered"&&g?.answers!==void 0?Object.fromEntries(v.map(([x,b],_)=>[`q_${_}`,b])):void 0,S=d.turnId!==void 0&&/^t?\d+$/.test(d.turnId)?Number(d.turnId.replace(/^t/,"")):void 0,w=d.taskId??c??d.id;r[a]={kind:"question",id:`question-${w}`,request:{question_id:w,session_id:"",turn_id:S,tool_call_id:c,questions:m,created_at:l?.startedAt??d.createdAt??""},outcome:p.kind==="answered"&&k!==void 0?{...p,answers:k}:p}}return o.size===0?r:r.filter((a,d)=>!o.has(d))}function Gh(t){const e=[],n=new Map;for(const s of t){if(s.kind!=="system"||s.variant!=="task"||s.taskId===void 0||s.taskId===""){e.push(s);continue}const i=n.get(s.taskId);i===void 0?(n.set(s.taskId,e.length),e.push(s)):e[i].id.startsWith("system-agent-frame-task-notified:")&&!s.id.startsWith("system-agent-frame-task-notified:")&&(e[i]=s)}return e}function vo(t){return t?.kind==="notice"&&t.id.startsWith("agent-marker-")&&t.i18n?.key.startsWith("transcript.marker.")===!0}function Qh(t){const e=[];for(const n of t){const s=e.at(-1);vo(n)&&vo(s)&&n.goalChange===void 0&&s.goalChange===void 0&&(n.compactionPhase===void 0||n.compactionPhase==="completed"&&s.compactionPhase==="completed")&&n.text===s.text&&n.tone===s.tone&&n.turnId===s.turnId&&n.i18n?.key===s.i18n?.key&&JSON.stringify(n.i18n?.params)===JSON.stringify(s.i18n?.params)?e[e.length-1]={...n,markerRepeatCount:(s.markerRepeatCount??1)+(n.markerRepeatCount??1),compactionHistory:n.compactionHistory===void 0?void 0:[...s.compactionHistory??[],...n.compactionHistory]}:e.push(n)}return e}function jv(t,e={}){const n=t.findLast(l=>Qe(l)!==void 0),s=n===void 0?void 0:Qe(n),i=fe(e.liveTurnId??(e.busy?s:void 0)),r=new Set((e.incompleteTurnIds??[]).map(fe)),o=new Set,a=new Set;let d=0;for(let l=t.length-1;l>=0;l-=1){const c=t[l],u=fe(Qe(c)),f=u??`unscoped-${d}`;if((c.kind==="tool"||c.kind==="shell"||c.kind==="approval"||c.kind==="question"||c.kind==="subagent"||c.kind==="subagent-event"&&c.event==="sent"||c.kind==="message"&&c.origin==="send_message")&&o.add(f),c.kind==="assistant"&&(c.streaming&&a.add(f),!c.streaming&&!o.has(f)&&!a.has(f)&&!r.has(u)&&(i===void 0||u!==i)&&!(e.busy&&u===void 0&&d===0)))return id(c)===void 0?void 0:c.id;if(c.kind==="user"){if(c.promptStatus===void 0&&c.steerStatus===void 0&&c.optimisticStatus===void 0&&(c.promptOutcome===void 0||(c.promptOutcome.inHistory??c.promptOutcome.delivered))&&ha(c.sourceOrigin))return;u===void 0&&(d+=1)}}}function Bv(t,e={}){const n=t.findLast(u=>Qe(u)!==void 0),s=n===void 0?void 0:Qe(n),i=fe(e.liveTurnId??(e.busy?s:void 0)),r=new Set((e.incompleteTurnIds??[]).map(fe)),o=new Set,a=new Set,d=new Set,l=new Set;let c=0;for(let u=t.length-1;u>=0;u-=1){const f=t[u],g=fe(Qe(f)),h=g??`unscoped-${c}`;(f.kind==="tool"||f.kind==="shell"||f.kind==="approval"||f.kind==="question"||f.kind==="subagent"||f.kind==="subagent-event"&&f.event==="sent"||f.kind==="message"&&f.origin==="send_message")&&o.add(h),f.kind==="assistant"&&(f.streaming&&a.add(h),!f.streaming&&!o.has(h)&&!a.has(h)&&!d.has(h)&&!r.has(g)&&(i===void 0||g!==i)&&!(e.busy&&g===void 0&&c===0)&&(d.add(h),id(f)!==void 0&&l.add(f.id))),f.kind==="user"&&g===void 0&&(c+=1)}return l}function Jh(t){return t.startsWith("assistant-live-")||t.startsWith("agent-frame-")?void 0:/^assistant-(.+)-(?:\d+|media)$/.exec(t)?.[1]}function id(t){return t.messageId??Jh(t.id)}function Dn(t,e){if(t.blocks.some(o=>o.kind==="user"&&o.turnId!==void 0&&(o.userMessageId===e.userMessageId||o.promptId===e.promptId)))return t;const n={prompt_id:e.promptId,user_message_id:e.userMessageId,status:e.status,origin:e.origin,content:e.content??[{type:"text",text:e.text}],created_at:e.createdAt},s=e.status==="queued"?t.queuedPromptIds.includes(e.promptId)?t.queuedPromptIds:[...t.queuedPromptIds,e.promptId]:t.queuedPromptIds.filter(o=>o!==e.promptId),i={...t.queuedPromptMeta};if(e.status==="queued"){const o=i[e.promptId];i[e.promptId]={appendTiming:e.appendTiming??o?.appendTiming??"agent_idle",revision:o?.revision}}else delete i[e.promptId];let r=Zi(t.blocks,n,e.media);return e.clientRequestId!==void 0&&(r=r.map(o=>o.kind==="user"&&(o.userMessageId===e.userMessageId||o.promptId===e.promptId)?{...o,clientRequestId:e.clientRequestId,id:`user-${e.userMessageId}`}:o)),wn(t,{busy:e.status==="running"?!0:t.busy,activePromptId:e.status==="running"?e.promptId:t.activePromptId,abortablePromptId:e.status==="running"&&t.abortableTurnId===void 0?e.promptId:t.abortablePromptId,queuedPromptIds:s,queuedPromptMeta:i,blocks:[...r]})}function Yh(t){const e=t.budgetLimit??null,n=t.turnBudget??null,s=t.wallClockBudgetMs??null,i=t.budgetUsed??0,r=t.turnsUsed??0,o=t.wallClockMs??0,a=e!==null&&i>=e,d=n!==null&&r>=n,l=s!==null&&o>=s;return{goalId:t.goalId??"transcript",objective:t.objective,completionCriterion:t.completionCriterion,status:t.status,followUpTiming:t.followUpTiming,controlRevision:t.controlRevision,terminalReason:t.terminalReason,turnsUsed:r,tokensUsed:i,wallClockMs:o,budget:{tokenBudget:e,turnBudget:n,wallClockBudgetMs:s,remainingTokens:e===null?null:Math.max(0,e-i),remainingTurns:n===null?null:Math.max(0,n-r),remainingWallClockMs:s===null?null:Math.max(0,s-o),tokenBudgetReached:a,turnBudgetReached:d,wallClockBudgetReached:l,overBudget:a||d||l}}}function Xh(t){if(t==="manual"||t==="auto"||t==="review"||t==="yolo")return t}function ei(t){return{inputOther:t.inputOther,output:t.output,inputCacheRead:t.inputCacheRead,inputCacheCreation:t.inputCacheCreation}}function Zh(t){if(t===void 0)return;let e;if(t.byModel!==void 0){const n={};for(const[s,i]of Object.entries(t.byModel))n[s]=ei(i);e=n}return{byModel:e,currentTurn:t.currentTurn===void 0?void 0:ei(t.currentTurn),total:t.total===void 0?void 0:ei(t.total)}}function ep(t){const e=t.kind==="subagent"?"subagent":t.kind==="shell"?"bash":"tool",n=t.state==="running"?"running":t.state==="failed"||t.state==="lost"||t.state==="timed_out"?"failed":t.state==="killed"?"cancelled":"completed",s=t.resultSummary!==void 0&&t.resultSummary!==""?t.resultSummary:t.outputTail;return{id:t.taskId,session_id:"",kind:e,description:t.description??"",status:n,command:t.command,created_at:t.startedAt??"",started_at:t.startedAt,completed_at:t.endedAt,output_preview:s,model:t.model,thinking_effort:t.thinkingEffort,thinking_effort_explicit:t.thinkingEffortExplicit,executor_id:t.executorId,executor_protocol:t.executorProtocol,agent_id:t.agentId,profile:t.subagentName,parent_tool_call_id:t.parentToolCallId,tool_call_id:t.toolCallId,question_count:t.questionCount,task_kind:t.taskKind,source_ref:t.sourceRef,run_in_background:t.detached,exit_code:t.exitCode,stop_reason:t.error??t.stateReason??(t.state==="timed_out"?"timeout":void 0)}}function tp(t,e,n,s={}){const i=jf(e,n),r=jh(i,t.blocks),o=Array.isArray(n.prompts)?n.prompts:[...n.prompts.values()],a=s.retainPendingPrompts===!1?r:Th(t.blocks,r),d=Ch(a,o),l=new Set(o.filter(y=>y.status==="completed"&&y.steeredAt!==void 0).map(y=>y.promptId)),c=l.size===0?d:d.filter(y=>y.kind!=="user"||y.turnId!==void 0||y.promptId===void 0||!l.has(y.promptId)),u=new Map;for(const y of o)y.runtimeControls!==void 0&&(u.set(y.promptId,y.runtimeControls),y.userMessageId!==void 0&&u.set(y.userMessageId,y.runtimeControls));const f=wh(c,o).map(y=>{if(y.kind!=="user")return y;const R=u.get(y.promptId??"")??u.get(y.userMessageId??y.id)??y.runtimeControls;return R===y.runtimeControls?y:{...y,runtimeControls:R}}),g=eh(f,t.snapshotSubagents),h=Rh(t.blocks,g);let v,m;const p=t.turnExecutions,k={};let S;for(const y of n.items){if(y.kind!=="turn")continue;v??=y,m=y,y.state==="running"&&(S=y);const R=Ah(y);R!==void 0&&(k[y.turnId]=Mh(p[y.turnId],R)?p[y.turnId]:R)}const w=S?.startedAt===void 0?Number.NaN:Date.parse(S.startedAt),x=n.meta.agent,b=o.filter(y=>y.status==="queued"&&(!y.steerAccepted||y.originKind==="cron_job")&&!ws(y.promptId)).toSorted((y,R)=>(y.queuePosition??Number.MAX_SAFE_INTEGER)-(R.queuePosition??Number.MAX_SAFE_INTEGER)),_=b.map(y=>y.promptId),C=t.queuedPromptMeta,F={};for(const y of b){const R=C[y.promptId],z=y.appendTiming??R?.appendTiming??"agent_idle",W=y.revision??R?.revision,B=y.queuePosition??R?.queuePosition,K=y.runtimeControls??R?.runtimeControls,$=y.userMessageId??R?.userMessageId,se=yn(y.content);if(y.originKind==="cron_job"){const ce=y.steerAccepted===!0?!0:void 0;F[y.promptId]={appendTiming:z,revision:W,queuePosition:B,runtimeControls:K,userMessageId:$,steerAccepted:ce,originKind:y.originKind,content:se,cronDeliveryMode:y.originDeliveryMode??R?.cronDeliveryMode}}else{const ce=se.length>0?se:R?.content;F[y.promptId]=R!==void 0&&R.appendTiming===z&&R.revision===W&&R.queuePosition===B&&R.runtimeControls===K&&R.userMessageId===$&&R.content===ce?R:{appendTiming:z,revision:W,queuePosition:B,runtimeControls:K,userMessageId:$,content:ce}}}const N=n.meta.modelSwitchQueuePositions;if(N!==void 0)for(const[y,R]of Object.entries(N)){const z=_a(y),W=C[z];F[z]=W!==void 0&&W.appendTiming==="agent_idle"&&W.queuePosition===R?W:{appendTiming:"agent_idle",queuePosition:R}}let me;for(const y of o)me===void 0&&y.status==="running"&&(me=y);const V=Array.isArray(n.interactions)?n.interactions:[...n.interactions.values()],we=Array.isArray(n.todos)?n.todos:[...n.todos.values()],ye=we.find(y=>y.todoId==="todo"),Fe=Array.isArray(n.tasks)?n.tasks:[...n.tasks.values()];let te="none";for(const y of V)if(y.state==="pending"){if(y.interactionKind==="approval"){te="approval";break}y.interactionKind==="question"&&(te="question")}const ee=n.meta.goal,re=x?.phase,le=re?.kind==="ended"&&re.reason==="failed"||re?.kind==="interrupted"&&re.reason==="error",Oe=m===void 0?void 0:po(m)??(le&&re.turnId===m.ordinal?po({...m,state:"failed",endedAt:new Date(re.at).toISOString(),error:re.kind==="interrupted"?re.message:void 0,durationMs:re.kind==="ended"?re.durationMs:void 0}):void 0),Ze=s.gapOf??(y=>Ri(y,!1,void 0)),Je={};for(const y of n.items){if(y.kind!=="turn")continue;const R=Ze(y);R!==void 0&&(Je[y.turnId]=R)}const P=Object.keys(Je),I={};for(const y of n.items){if(y.kind!=="marker"||y.marker!=="agent_message.delivered")continue;const R=ea.safeParse(y.payload);if(!R.success)continue;const{messageId:z,deliveredAt:W}=R.data,B=I[z];(B===void 0||W<B)&&(I[z]=W)}return{...t,version:t.version+1,blocks:h,loaded:!0,transcriptReady:!0,loadError:void 0,busy:s.cold!==!0&&rd(i)===!0,turnStartedAt:s.cold===!0||Number.isNaN(w)?void 0:w,model:x?.model??t.model,thinkingEffort:x?.thinkingEffort,contextTokens:x?.contextTokens??t.contextTokens,maxContextTokens:x?.maxContextTokens??(x?.model!==void 0&&t.model!==void 0&&x.model!==t.model?void 0:t.maxContextTokens),usage:Bt(t.usage,Zh(x?.usage)),permissionMode:Xh(x?.permission)??t.permissionMode,planMode:n.meta.modes?.plan!==void 0?!0:s.cold===!0&&n.hasMoreOlder===!0?t.session?.agent_config.plan_mode??t.planMode:!1,queuedPromptIds:Bt(t.queuedPromptIds,_),promptQueueHold:n.meta.promptQueueHold,queuedPromptMeta:F,activePromptId:s.cold===!0?void 0:me?.promptId,abortablePromptId:s.cold===!0?void 0:S===void 0?me?.promptId:S.promptId??(S.origin.kind==="user"?me?.promptId:void 0),abortableTurnId:s.cold===!0?void 0:S?.ordinal,pendingInteraction:te,todos:Bt(t.todos,(ye??we.find(y=>y.todoId==="external-plan"))?.items??[]),todoNotes:ye?.notes,todoNotesMeta:ye?.notesMeta,todoNotesStatus:ye?.notesStatus,tasks:Xa(t.tasks,Fe.map(ep)),goal:Bt(t.goal,ee===void 0?null:Yh(ee)),hasMoreHistory:n.hasMoreOlder===!0||v!==void 0&&Je[v.turnId]!==void 0||v?.contentRefs?.some(y=>y.direction==="backward")===!0,incompleteTurnIds:Bt(t.incompleteTurnIds,P),turnGaps:Bt(t.turnGaps??{},Je),oldestMessageId:v?.turnId,turnExecutions:k,turnTail:Oe??(m!==void 0&&m.state!=="running"&&gt(t.turnTail?.turnId,m.turnId)?t.turnTail:void 0),failedTurnIds:Bt(t.failedTurnIds,n.items.flatMap(y=>y.kind==="turn"&&y.state==="failed"?[y.turnId]:[])),deliveredAgentMessages:Bt(t.deliveredAgentMessages??{},I),lostTaskCount:(Array.isArray(n.tasks)?n.tasks:[...n.tasks.values()]).filter(y=>y.state==="lost").length,nonUserTurnIds:Bt(t.nonUserTurnIds??[],n.items.flatMap(y=>y.kind==="turn"&&y.origin!==void 0&&y.origin.kind!=="user"?[y.turnId]:[])),turnRetry:Ph(m)}}function np(t,e){const n={seq:t.as_of_seq,epoch:t.epoch};return e===void 0||e.cursor.epoch!==void 0&&t.epoch!==e.cursor.epoch?n:e.cursor.seq>t.as_of_seq?e.cursor:n}function sp(t,e,n){const s=n??Ai(t),i=np(e,n),r=Math.max(e.session.last_seq,e.as_of_seq,i.seq,n?.session?.last_seq??0),o=r>e.session.last_seq?{...e.session,last_seq:r}:e.session;return{...s,version:s.version+1,session:o,cursor:i,busy:s.transcriptReady?s.busy:e.session.main_turn_active??e.in_flight_turn!==null,abortablePromptId:e.in_flight_turn?.current_prompt_id,abortableTurnId:e.in_flight_turn?.turn_id,model:e.session.agent_config.model!==""?e.session.agent_config.model:s.model,profile:e.session.agent_config.profile??s.profile,permissionMode:e.session.agent_config.permission_mode??s.permissionMode,planMode:e.session.agent_config.plan_mode??s.planMode,contextTokens:e.context_tokens!==void 0&&(e.context_tokens>0||s.contextTokens===void 0||!s.transcriptReady)?e.context_tokens:s.contextTokens,maxContextTokens:e.max_context_tokens??s.maxContextTokens,snapshotSubagents:e.subagents??s.snapshotSubagents,agentCounts:e.agent_counts,loaded:!0,loadError:void 0,resyncFailed:!1,resyncAttempt:0,resyncError:void 0}}function ip(t,e){const n=t.state==="running"||e.state==="running",s=t.origin.kind==="other"&&t.message===void 0&&t.promptId===void 0&&t.startedAt===void 0,i=s?{origin:e.origin,prompt:e.prompt,promptId:e.promptId,message:e.message,delivery:e.delivery,presentation:e.presentation,attachmentIds:e.attachmentIds,startedAt:e.startedAt}:{},r=new Map(t.steps.map(d=>[d.stepId,d])),o=e.steps.map(d=>{const l=r.get(d.stepId);if(l===void 0)return d;const c=new Map(l.frames.map(h=>[h.frameId,h])),u=d.frames.map(h=>{const v=c.get(h.frameId);if(v===void 0)return h;if(n)return v;let m=Dt(v,h);for(const p of h.contentRefs??[])!(v.contentRefs??[]).some(k=>k.path.every((S,w)=>p.path[w]===S)||p.path.every((S,w)=>k.path[w]===S))&&mn(v,p.path)!==void 0&&(m=mi(m,v,p.path));return m}),f=new Set(u.map(h=>h.frameId));return{...n?{...d,...l,ordinal:d.ordinal}:d,frames:[...u,...l.frames.filter(h=>!f.has(h.frameId))]}}),a=new Set(o.map(d=>d.stepId));return ot(t,{...t,...i,stepsPartial:void 0,steps:[...o,...t.steps.filter(d=>!a.has(d.stepId))],contentRefs:[...(t.contentRefs??[]).filter(d=>d.path[0]!=="steps"&&(!s||d.path[0]!=="prompt"&&d.path[0]!=="attachmentIds")),...s?(e.contentRefs??[]).filter(d=>d.path[0]==="prompt"||d.path[0]==="attachmentIds"):[]]})}function rd(t){if(t===void 0)return;if(ed(t)!==void 0)return!1;const e=t.meta?.agent?.phase?.kind;if(e==="running"||e==="streaming"||e==="tool_call"||e==="retrying"||e==="awaiting_approval")return!0;if(e==="idle"||e==="ended"||e==="interrupted")return od(t,t.meta?.agent?.phase)!==void 0;if(t.meta?.activity==="turn")return!0;if(t.meta?.activity==="idle"||t.meta?.activity==="disposing")return!1;if(t.prompts?.some(n=>n.status==="running")||t.interactions?.some(n=>n.state==="pending"))return!0;for(const n of t.items){if(n.kind!=="turn")continue;const s="state"in n?n.state:void 0;if(s==="running"||s==="queued")return!0;for(const i of n.steps)if(("state"in i?i.state:void 0)==="running"||i.frames.some(o=>o.kind==="tool"&&o.state==="running"))return!0}}function od(t,e){const n=typeof e=="object"&&e!==null&&"turnId"in e?e.turnId:void 0;for(let s=t.items.length-1;s>=0;s-=1){const i=t.items[s];if(i.kind!=="turn")continue;if(!("state"in i)||i.state!=="running")return;const r=i.ordinal;return typeof r!="number"||typeof n=="number"&&r<=n?void 0:{ordinal:r}}}class rp{constructor(e){this.onCancel=e}flights=new Map;request(e,n,s){if(s?.aborted)return Promise.resolve({kind:"cancelled",changed:!1});let i=this.flights.get(e);if(i===void 0){const a=new AbortController;i={controller:a,consumers:new Set,promise:Promise.resolve({kind:"cancelled",changed:!1})},this.flights.set(e,i);const d=i;d.promise=n(a.signal).finally(()=>{this.flights.get(e)===d&&this.flights.delete(e)})}const r=i,o=Symbol();return r.consumers.add(o),new Promise(a=>{let d=!1;const l=u=>{d||(d=!0,s?.removeEventListener("abort",c),r.consumers.delete(o),u.kind==="cancelled"&&r.consumers.size===0&&this.flights.get(e)===r&&this.cancel(e),a(u))},c=()=>{l({kind:"cancelled",changed:!1})};s?.addEventListener("abort",c,{once:!0}),s?.aborted&&c(),r.promise.then(l,()=>{l({kind:"failed",changed:!1})})})}hasActive(){return this.flights.size>0}cancel(e){const n=this.flights.get(e);this.flights.delete(e),n?.controller.abort(),n!==void 0&&this.onCancel(e)}cancelAll(){for(const e of this.flights.keys())this.cancel(e)}}const op=3,ap=128;class dp{active=0;waiting=[];read(e,n,s="normal"){return n?.aborted?Promise.reject(n.reason):this.active<op?this.run(e,n):this.waiting.length>=ap?Promise.reject(new Error("History reads are busy. Retry after the current reads finish.")):new Promise((i,r)=>{const o={priority:s,enter:()=>{n?.removeEventListener("abort",o.cancel),i(this.run(e,n))},cancel:()=>{const a=this.waiting.indexOf(o);a>=0&&this.waiting.splice(a,1),n?.removeEventListener("abort",o.cancel),r(n?.reason??new DOMException("History read cancelled","AbortError"))}};if(s==="high"){const a=this.waiting.findIndex(d=>d.priority!=="high");a>=0?this.waiting.splice(a,0,o):this.waiting.push(o)}else this.waiting.push(o);n?.addEventListener("abort",o.cancel,{once:!0})})}async run(e,n){this.active+=1;try{return n?.throwIfAborted(),await e()}finally{this.active-=1,this.waiting.shift()?.enter()}}}const yo=new WeakMap;function cp(t,e,n,s="normal"){let i=yo.get(t);return i===void 0&&(i=new dp,yo.set(t,i)),i.read(e,n,s)}function lp(t){return t.queuedPromptIds.filter(e=>!ws(e)).map(e=>{const n=t.queuedPromptMeta[e],s=t.blocks.find(c=>c.kind==="user"&&c.promptId===e)??(n?.userMessageId===void 0?void 0:t.blocks.find(c=>c.kind==="user"&&c.promptStatus==="queued"&&c.userMessageId===n.userMessageId)),i=n?.content??s?.queuedContent;if(n?.originKind==="cron_job"){const c=dt(i??[]);return{promptId:e,userMessageId:s?.userMessageId??n.userMessageId,originKind:n.originKind,steerAccepted:n.steerAccepted,cronDeliveryMode:n.cronDeliveryMode,text:qt({text:c.text,origin:{kind:"cron_job"}}).text,presentation:c.presentation??s?.presentation,media:c.media,content:i,runtimeControls:n.runtimeControls??s?.runtimeControls,appendTiming:n.appendTiming??"agent_idle",revision:n.revision,queuePosition:n.queuePosition}}const o=(s===void 0||s.text==="")&&i!==void 0&&i.length>0?dt(i):void 0,a=o!==void 0&&o.text!==""?qt({text:o.text,presentation:o.presentation,role:"user",origin:{kind:"user"}}):void 0,d=a===void 0?"":a.text!==""?a.text:a.skill!==void 0?a.skill.args===void 0?`/${a.skill.name}`:`/${a.skill.name} ${a.skill.args}`:o.text,l=(s===void 0||s.text==="")&&d!=="";return{promptId:e,userMessageId:s?.userMessageId??n?.userMessageId,originKind:n?.originKind,cronDeliveryMode:n?.cronDeliveryMode,text:l?d:s?.text??"",presentation:l?a?.presentation??o?.presentation:s?.presentation,media:s?.media??(o!==void 0&&o.media.length>0?o.media:void 0),content:i,runtimeControls:n?.runtimeControls??s?.runtimeControls,appendTiming:n?.appendTiming??"agent_idle",revision:n?.revision,queuePosition:n?.queuePosition}})}function Lv(t){return t.originKind!=="cron_job"||!t.steerAccepted&&(t.cronDeliveryMode===void 0||t.cronDeliveryMode==="queue")}function up(t){return t.blocks.filter(e=>e.kind==="approval"&&e.resolution===void 0).length}function fp(t){return t.blocks.filter(e=>e.kind==="question"&&e.outcome===void 0).length}function ad(t){return up(t)>0?"approval":fp(t)>0?"question":"none"}function hp(t,e){return t.some(n=>n.kind!=="assistant"&&n.kind!=="message"&&n.kind!=="tool"||fe(n.turnId)!==e?!1:n.kind==="message"?!0:(n.media?.length??0)>0||n.kind==="assistant"&&n.text.trim()!=="")}function pp(t,e){return t.turnGaps!==void 0&&Object.keys(t.turnGaps).some(n=>fe(n)===e)||t.incompleteTurnIds?.some(n=>fe(n)===e)===!0?!0:t.contentRefs?.some(n=>{if(n.source.kind==="turn")return fe(n.source.id)===e&&n.path[0]==="steps";if(n.source.kind!=="frame"||n.path[0]!=="text")return!1;const s=n.source;return fe(s.turnId)===e||t.blocks.some(i=>i.kind==="assistant"&&fe(i.turnId)===e&&i.frameId===s.id)})===!0}function Hv(t,e={}){const n=t.turnTail;if(!t.loaded||!t.transcriptReady||t.resyncing||t.resyncFailed||t.loadError!==void 0||t.busy||n===void 0||n.state!=="completed")return;const s=fe(n.turnId);if(s===void 0||hp(t.blocks,s)||pp(t,s))return;const i=t.session?.executing;return{turnId:n.turnId,endedAt:n.endedAt,work:e.connected===!1||i===void 0?"unknown":i?"running":"idle"}}function mp(t){return t.blocks.filter(e=>e.kind==="subagent")}function Ct(t,e){const n=e?void 0:t.olderError;return t.loadingOlder===e&&t.olderError===n?t:wn(t,{loadingOlder:e,olderError:n})}function ss(t,e){return t.olderError===e&&!t.loadingOlder?t:wn(t,{olderError:e,loadingOlder:!1})}function Jt(t,e){return t.resyncing===e?t:{...t,resyncing:e,version:t.version+1}}function ko(t,e,n){return t.resyncFailed===e&&t.resyncAttempt===n?t:{...t,resyncFailed:e,resyncAttempt:n,version:t.version+1}}function qn(t,e){return{...t,loadError:e,loaded:e===void 0?t.loaded:!1,version:t.version+1}}function Io(t,e){const n=t.session?.id===e.id?t.session:void 0,s=Math.max(e.last_seq,n?.last_seq??0,t.cursor.seq),i=n?.agent_config,r=e.agent_config,o=i===void 0?r:{...i,...r,model:r.model||i.model,execution:r.execution??i.execution,profile:r.profile??i.profile,persona:r.persona??i.persona,permission_mode:r.permission_mode??i.permission_mode,plan_mode:r.plan_mode??i.plan_mode,plan_gate:r.plan_gate??i.plan_gate},a=n?.usage,d=e.usage,l=a===void 0?d:{...d,context_tokens:d.context_tokens>0?d.context_tokens:a.context_tokens,context_limit:d.context_limit>0?d.context_limit:a.context_limit,turn_count:d.turn_count>0?d.turn_count:a.turn_count},c={...e,last_seq:s,executor_id:e.executor_id??n?.executor_id,allow_kiki_subagents:e.allow_kiki_subagents??n?.allow_kiki_subagents,agent_config:o,usage:l},u=o.model||t.model;return wn(t,{session:c,model:u,thinkingEffort:o.execution?.effective.thinking??t.thinkingEffort,maxContextTokens:u===t.model?t.maxContextTokens:void 0,profile:o.profile??t.profile,permissionMode:o.permission_mode??t.permissionMode,planMode:o.plan_mode??t.planMode})}function dd(t,e){const n=t.findIndex(i=>i.id===e.id);if(n<0)return[...t,e];const s=t.slice();return s[n]=e,s}function gp(t,e,n){const s=`approval-${e}`,i=t.blocks.find(o=>o.id===s);if(i===void 0)return t;const r=dd(t.blocks,{...i,resolution:n});return wn(t,{blocks:r,pendingInteraction:ad({...t,blocks:r})})}function wo(t,e,n){const s=`question-${e}`,i=t.blocks.find(o=>o.id===s);if(i===void 0)return t;const r=dd(t.blocks,{...i,outcome:n});return wn(t,{blocks:r,pendingInteraction:ad({...t,blocks:r})})}const bo=24;function vp(t){const e=t.split(`
23
+ `,1)[0]??"",n=Array.from(e.trim());return n.length>bo?`${n.slice(0,bo).join("")}…`:n.join("")}function zv(t){const e=[];for(const n of t)n.kind==="user"&&e.push({blockId:n.id,preview:vp(n.text)});return e}function Wv(t,e,n){const s=e.byId[n],i=s===void 0?void 0:new Set(s.childIds);return t.filter(r=>{if(r.kind!=="subagent"&&r.kind!=="subagent-event")return!0;if(i!==void 0)return i.has(r.subagentId);const o=e.byId[r.subagentId]?.parentAgentId??r.parentAgentId;return o===void 0||o===n})}function So(t){const e=t?.meta?.agent?.phase,n=t===void 0?void 0:ed(t);if(n!==void 0)return n.state;if(t!==void 0&&(e?.kind==="ended"||e?.kind==="interrupted"||e?.kind==="idle")&&od(t,e)!==void 0)return"running";switch(e?.kind){case"running":case"streaming":case"tool_call":case"retrying":return"running";case"awaiting_approval":return"suspended";case"ended":switch(e.reason){case"completed":return"completed";case"cancelled":return"cancelled";case"failed":return"failed";case"blocked":return"suspended";default:return"unknown"}case"interrupted":return e.reason==="aborted"?"cancelled":"failed";case"idle":default:return"unknown"}}function yp(t,e){if(t?.kind!=="interrupted"||typeof t.message!="string"||typeof t.at!="number"||e!=="failed")return{};const n=new Date(t.at);return Number.isNaN(n.getTime())?{}:{statusSource:"runtime",error:t.message,endedAt:n.toISOString()}}function kp(t,e){return t===void 0?[]:t.flatMap(n=>{const s=n.agentId!==void 0&&n.agentId!==""?n.agentId:e;if(s===void 0||s===""||(n.agentId===void 0||n.agentId==="")&&n.state!=="running")return[];const i=e!==void 0&&e!==""&&s!==e?e:void 0;return[{id:n.taskId,agentId:s,parentAgentId:i,parentToolCallId:n.parentToolCallId,kind:n.kind,name:n.name??n.subagentName,explicitName:n.name,description:n.description,status:n.state,model:n.model,thinkingEffort:n.thinkingEffort,thinkingEffortExplicit:n.thinkingEffortExplicit,executorId:n.executorId,executorProtocol:n.executorProtocol,startedAt:n.startedAt,endedAt:n.endedAt,summary:n.resultSummary,output_preview:n.outputTail,detached:n.detached}]})}function cd(t,e){return t.flatMap(n=>{if(n.kind!=="subagent"||n.agent_id===void 0||n.agent_id==="")return[];const s=e!==void 0&&e!==""&&n.agent_id!==e?e:void 0;return[{id:n.id,agentId:n.agent_id,parentAgentId:s,kind:n.kind,description:n.description,status:n.status,model:n.model,thinking_effort:n.thinking_effort,thinking_effort_explicit:n.thinking_effort_explicit,executor_id:n.executor_id,executor_protocol:n.executor_protocol,started_at:n.started_at,completed_at:n.completed_at,output_preview:n.output_preview}]})}function ld(t){return t.map(e=>({subagentId:e.subagentId,parentAgentId:e.parentAgentId,parentToolCallId:e.parentToolCallId,name:e.name,label:e.label,model:e.model,thinkingEffort:e.thinkingEffort,thinkingEffortExplicit:e.thinkingEffortExplicit,executorId:e.executorId,executorProtocol:e.executorProtocol,status:e.status,description:e.description,summary:e.summary,error:e.error,startedAt:e.startedAt,endedAt:e.endedAt,toolCallCount:e.toolCallCount,toolCallCountKnown:e.toolCallCountKnown}))}function tr(t){return t===void 0?[]:t.flatMap(e=>{const n=Rt(e);if(n==="")return[];const s=Re(e.label),i=Re(e.description),r=s??i??Re(e.profile)??n,o=e.started_at;return[{agentId:n,createdAt:e.created_at,parentAgentId:Re(e.parent_agent_id),parentToolCallId:Re(e.parent_tool_call_id),name:r,label:s,isBranch:e.is_branch,branchSeed:e.branch_seed,branchInitiator:e.branch_initiator,toolsLocked:e.tools_locked,branchSealed:e.branch_sealed,branchBaseTurnId:e.branch_base_turn_id,branchBaseMessageId:Re(e.branch_base_message_id),model:Re(e.model),thinkingEffort:Re(e.thinking_effort),thinkingEffortExplicit:e.thinking_effort_explicit,executorId:Re(e.executor_id),executorProtocol:Re(e.executor_protocol),status:e.activity_status??(e.subagent_phase==="suspended"?"suspended":e.status),statusSource:e.status_source,nameSource:e.name_source,refreshing:e.refreshing,refreshingUntil:e.refreshing_until,detached:e.run_in_background,disposedAt:e.live===!1?o:void 0,toolCallCount:e.tool_call_count,toolCallCountKnown:e.tool_call_count===void 0?void 0:!0,startedAt:o,endedAt:e.completed_at,description:i,summary:Re(e.output_preview),error:Re(e.stop_reason)??(e.status==="failed"?Re(e.output_preview):void 0)}]})}function Re(t){return t!==void 0&&t!==""?t:void 0}function nr(t,e,n){if(t.length===0||e===void 0||e.length===0)return t;const s=n??tr(e),i=new Map;for(const r of s)i.set(r.agentId,r);return i.size===0?t:t.map(r=>{const o=i.get(r.subagentId);if(o===void 0)return r;const a=r.toolCallCountAuthoritative===!0,d=o.toolCallCount,l=a?r.toolCallCount??0:d===void 0?r.toolCallCount:Math.max(r.toolCallCount??0,d),c=a?r.toolCallCount===void 0?!1:r.toolCallCountKnown!==!1:Ip(r.toolCallCountKnown,o.toolCallCountKnown),u=o.statusSource==="runtime"&&(o.status==="running"||o.status==="suspended"||o.status==="background"),f=r.status==="completed"||r.status==="failed"||r.status==="cancelled",g=u&&f,h=o.statusSource==="runtime"&&(o.status==="completed"||o.status==="failed"||o.status==="cancelled");return{...r,createdAt:Re(r.createdAt)??o.createdAt,parentAgentId:r.parentAgentId??o.parentAgentId,parentToolCallId:r.parentToolCallId??o.parentToolCallId,name:r.name!==r.subagentId?r.name:o.name??r.name,label:r.label??o.label,model:r.model??o.model,thinkingEffort:r.thinkingEffort??o.thinkingEffort,thinkingEffortExplicit:r.thinkingEffortExplicit??o.thinkingEffortExplicit,executorId:r.executorId??o.executorId,executorProtocol:r.executorProtocol??o.executorProtocol,status:o.statusSource==="runtime"||r.status==="unknown"?o.status??r.status:r.status,disposedAt:r.disposedAt??o.disposedAt,description:r.description??o.description,summary:g?void 0:r.summary??o.summary,error:g?void 0:r.error??o.error,startedAt:g?Re(o.startedAt)??Re(r.startedAt):Re(r.startedAt)??o.startedAt,endedAt:g?void 0:h?o.endedAt??r.endedAt:r.endedAt??o.endedAt,toolCallCount:l,toolCallCountKnown:c}})}function Ip(t,e){return t===!0||e===!0?!0:t??e}function Ts(t){const e=t.toolCallCount;return{toolCallCount:e??0,toolCallCountKnown:e!==void 0&&t.toolCallCountKnown!==!1}}function sr(t,e){if(e.length===0)return t;const n=new Map(e.map(r=>[r.subagentId,r]));let s=!1;const i={...t.byId};for(const[r,o]of Object.entries(i)){const a=n.get(r);if(a===void 0)continue;const d=a.toolCallCountAuthoritative===!0,l=d?a.toolCallCount??0:o.toolCallCount,c=d?a.toolCallCount===void 0?!1:a.toolCallCountKnown!==!1:o.toolCallCountKnown,u=o.name!==o.agentId?o.name:a.name,f=o.label!==o.name&&o.label!==o.agentId?o.label:a.label??(a.name!==a.subagentId?a.name:o.label),g=o.status==="running"||o.status==="suspended"||o.status==="background",h={...o,name:u,label:f,model:o.model??a.model,thinkingEffort:o.thinkingEffort??a.thinkingEffort,thinkingEffortExplicit:o.thinkingEffortExplicit??a.thinkingEffortExplicit,executorId:o.executorId??a.executorId,executorProtocol:o.executorProtocol??a.executorProtocol,toolCallCount:l,toolCallCountKnown:c,startedAt:Re(o.startedAt)??a.startedAt,endedAt:g?o.endedAt:o.endedAt??a.endedAt,description:o.description??a.description,summary:g?o.summary:o.summary??a.summary,error:g?o.error:o.error??a.error};(h.model!==o.model||h.thinkingEffort!==o.thinkingEffort||h.thinkingEffortExplicit!==o.thinkingEffortExplicit||h.executorId!==o.executorId||h.executorProtocol!==o.executorProtocol||h.toolCallCount!==o.toolCallCount||h.toolCallCountKnown!==o.toolCallCountKnown||h.label!==o.label||h.name!==o.name||h.startedAt!==o.startedAt||h.endedAt!==o.endedAt||h.description!==o.description||h.summary!==o.summary||h.error!==o.error)&&(i[r]=h,s=!0)}return s?{byId:i,roots:t.roots.map(r=>i[r.agentId]??r)}:t}function Uv(t,e,n){const s=tr(t.snapshotSubagents),i=nr(ld(mp(t)),t.snapshotSubagents,s);return sr(Gi(i,[...s],[...cd(t.tasks)]),i)}function Vv(t,e,n){if(e===""||e===M)return t;const s=n.blocks.filter(u=>u.kind==="subagent"),i=n.tasks.filter(u=>u.kind==="subagent"&&u.agent_id!==void 0&&u.agent_id!==""&&u.agent_id!==e);if(s.length===0&&i.length===0)return t;const r=nr(ld(s).map(u=>({...u,parentAgentId:u.parentAgentId??e})),n.snapshotSubagents),o=cd(i,e),a=Object.values(t.byId).map(u=>({agentId:u.agentId,createdAt:u.createdAt,parentAgentId:u.parentAgentId,parentToolCallId:u.parentToolCallId,name:u.name,label:u.label,isBranch:u.isBranch,branchSeed:u.branchSeed,branchInitiator:u.branchInitiator,toolsLocked:u.toolsLocked,branchSealed:u.branchSealed,branchBaseTurnId:u.branchBaseTurnId,branchBaseMessageId:u.branchBaseMessageId,nameSource:u.nameSource,statusSource:u.statusSource,model:u.model,thinkingEffort:u.thinkingEffort,thinkingEffortExplicit:u.thinkingEffortExplicit,executorId:u.executorId,executorProtocol:u.executorProtocol,contextTokens:u.contextTokens,maxContextTokens:u.maxContextTokens,usage:u.usage,status:u.status==="unknown"?void 0:u.status,refreshing:u.refreshing,refreshingUntil:u.refreshingUntil,busy:u.busy,toolCallCount:u.toolCallCount,toolCallCountKnown:u.toolCallCountKnown,startedAt:u.startedAt,endedAt:u.endedAt,description:u.description,summary:u.summary,error:u.error}));t.byId[e]===void 0&&a.push({agentId:e,name:e});const d=sr(Gi(r,a,o),r),l={...d.byId};for(const[u,f]of Object.entries(t.byId)){const g=l[u];g!==void 0&&(f.nameSource!==void 0||f.statusSource!==void 0||f.turnOutcome!==void 0)&&(l[u]={...g,nameSource:g.nameSource??f.nameSource,statusSource:g.statusSource??f.statusSource,turnOutcome:g.turnOutcome??f.turnOutcome})}const c={byId:l,roots:d.roots.map(u=>l[u.agentId]??u)};return aa(t,c)}const xo=new WeakMap,_o=new WeakMap;function wp(t){const e=xo.get(t);if(e!==void 0)return e;const n=new Map;for(const i of t){if(i.kind!=="turn")continue;let r=_o.get(i);if(r===void 0){const o=new Map;for(const a of i.steps)for(const d of a.frames)if(d.kind==="tool")for(const l of d.agentRefs??[])o.set(l.agentId,{agentId:l.agentId,toolCallId:d.toolCallId,startedAt:o.get(l.agentId)?.startedAt??a.startedAt??i.startedAt});r=[...o.values()],_o.set(i,r)}for(const o of r)n.set(o.agentId,{...o,startedAt:n.get(o.agentId)?.startedAt??o.startedAt})}const s=[...n.values()];return xo.set(t,s),s}function bp(t){return t.startsWith("agent-phase-")}function Sp(t){return t.startsWith("agent-receipt-")}function is(t){if(t===void 0||t==="")return;const e=Date.parse(t);return Number.isFinite(e)?e:void 0}function To(t){return t==="completed"||t==="failed"||t==="killed"||t==="timed_out"||t==="lost"?2:t==="running"?1:0}function Co(t,e){const n=is(t.startedAt),s=is(e.startedAt),i=is(t.endedAt),r=is(e.endedAt);if(t.taskId!==e.taskId){if(n!==void 0&&r!==void 0&&n>r)return!0;if(s!==void 0&&i!==void 0&&s>i)return!1;if(i!==void 0&&r!==void 0&&i!==r)return i>r}if(n!==s)return n===void 0?!1:s===void 0?!0:n>s;const o=To(t.state),a=To(e.state);return o!==a?o>a:i!==r?i===void 0?!1:r===void 0?!0:i>r:t.taskId>=e.taskId}function xp(t){const e=new Map;for(const[n,s]of t){const i=Array.isArray(s.tasks)?s.tasks:[...s.tasks.values()],r=new Map;for(const o of i){if(o.kind!=="subagent"||o.agentId===void 0||o.agentId==="")continue;const a=r.get(o.agentId);a===void 0?r.set(o.agentId,[o]):a.push(o)}for(const[o,a]of r){const d=a.filter(_=>!bp(_.taskId)),l=d.length>0?d:a,c=l.filter(_=>_.state==="running"),u=c.length>0?c:l;let f=u[0],g=l[0],h,v,m;for(const _ of u)_!==f&&Co(_,f)&&(f=_);for(const _ of l){_!==g&&Co(g,_)&&(g=_),h===void 0&&Re(_.parentToolCallId)!==void 0&&(h=_);const C=Re(_.name);C!==void 0&&(v=C);const F=Re(_.subagentName);F!==void 0&&(m=F)}const p=e.get(o),k=h??g,S=Re(f.parentToolCallId),w=k!==f&&Re(k.description)!==void 0&&(Sp(f.taskId)||S===void 0&&h!==void 0),x=v??(p?.name!==void 0&&p.name!==o?p.name:void 0)??m??o,b=w?k.description:Re(f.description)??Re(k.description)??p?.description;e.set(o,{subagentId:o,parentAgentId:n,parentToolCallId:S??Re(k.parentToolCallId)??p?.parentToolCallId,name:x,model:f.model??k.model??p?.model,thinkingEffort:f.thinkingEffort??k.thinkingEffort??p?.thinkingEffort,thinkingEffortExplicit:f.thinkingEffortExplicit??k.thinkingEffortExplicit??p?.thinkingEffortExplicit,executorId:f.executorId??k.executorId??p?.executorId,executorProtocol:f.executorProtocol??k.executorProtocol??p?.executorProtocol,status:f.state,description:b,summary:Re(f.resultSummary)??Re(f.outputTail)??p?.summary,error:f.error??f.stateReason,startedAt:f.startedAt??k.startedAt??p?.startedAt,endedAt:f.endedAt,toolCallCount:p?.toolCallCount,toolCallCountKnown:p?.toolCallCountKnown,toolCallCountAuthoritative:p?.toolCallCountAuthoritative})}for(const o of wp(s.items)){const a=e.get(o.agentId);e.set(o.agentId,{...a,subagentId:o.agentId,parentAgentId:n,parentToolCallId:o.toolCallId,name:a?.name??o.agentId,status:a?.status??"unknown",startedAt:a?.startedAt??o.startedAt})}}for(const[n,s]of t){const i=s.meta.agent,r=e.get(n);if(r===void 0)continue;const o=Ts(s);e.set(n,{...r,model:i?.model??r.model,thinkingEffort:i?.thinkingEffort??r.thinkingEffort,toolCallCount:o.toolCallCount,toolCallCountKnown:o.toolCallCountKnown,toolCallCountAuthoritative:!0})}return[...e.values()]}function _p(t,e,n,s){const i=tr(e),r=nr(xp(t),e,i),o=[],a=[],d=r.length===0?void 0:new Map(r.map(h=>[h.subagentId,h]));for(const[h,v]of t){const m=v.meta.agent,p=Ts(v),k=d?.get(h),S=So({items:v.items,meta:v.meta});a.push({agentId:h,parentAgentId:k?.parentAgentId,parentToolCallId:k?.parentToolCallId,name:k?.name??h,model:m?.model,thinkingEffort:m?.thinkingEffort,contextTokens:m?.contextTokens,maxContextTokens:m?.maxContextTokens,usage:m?.usage,toolCallCount:p.toolCallCount,toolCallCountKnown:p.toolCallCountKnown,toolCallCountAuthoritative:!0,status:S,...yp(m?.phase,S),busy:rd({items:v.items,meta:v.meta})});const w=Array.isArray(v.tasks)?v.tasks:[...v.tasks.values()];w.length>0&&o.push(...kp(w,h))}for(const h of i)a.push(h);const l=sr(Gi(r,Cp(a,t),o),r),c={...l.byId},u=new Map,f=new Set;for(const h of e??[]){const v=Rt(h);u.set(v,h),h.live===!0&&f.add(v);const m=c[v];if(m===void 0)continue;const p=m.status===(h.activity_status??h.status)?h.status_source:void 0;(m.nameSource!==h.name_source||m.statusSource!==p)&&(c[v]={...m,nameSource:h.name_source,statusSource:p})}for(const[h,v]of t){let m=c[h];if(m===void 0)continue;const p=u.get(h),k=v.meta.agent,S=n?.has(h)===!0||s?.has(h)===!0,w=m.isBranch===!0||p?.is_branch===!0,x=S?p?.model??k?.model:k?.model??(w?p?.model:void 0),b=S?p?.thinking_effort??k?.thinkingEffort:k?.thinkingEffort??(w?p?.thinking_effort:void 0);(x!==void 0||b!==void 0)&&(m={...m,model:x??m.model,thinkingEffort:b??m.thinkingEffort},c[h]=m);const _=v.items.findLast(we=>we.kind==="turn"),C=So({items:v.items,meta:v.meta}),F=!S&&(C==="running"||C==="suspended");if(F&&p?.live!==!1&&(m.status==="idle"||m.status==="unknown")){const we=k?.phase,ye=we!==void 0&&"since"in we?we.since:_?.kind==="turn"&&_.state==="running"?Date.parse(_.startedAt??""):NaN,Fe=Date.parse(p?.completed_at??p?.started_at??"");(C==="running"||C==="suspended")&&Number.isFinite(ye)&&(!Number.isFinite(Fe)||ye>Fe)&&(m={...m,status:C,busy:!0,statusSource:"runtime",endedAt:void 0},c[h]=m)}if(F&&(m.status==="running"||m.status==="suspended"||m.status==="background")&&f.add(h),_?.kind!=="turn")continue;const N=er(_);if(N===void 0)continue;const me=Date.parse(m.startedAt??""),V=Date.parse(N.endedAt??"");Number.isFinite(me)&&Number.isFinite(V)&&me>V||(c[h]={...m,turnOutcome:N})}const g=new Set(n);for(const h of n??[]){const v=t.get(h);if(v===void 0)continue;const m=Array.isArray(v.tasks)?v.tasks:[...v.tasks.values()];for(const p of m)p.agentId!==void 0&&g.add(p.agentId)}for(const h of g){const v=c[h];if(v===void 0||f.has(h))continue;const m=v.branchSealed===!0?"completed":v.isBranch===!0?"idle":"unknown";c[h]={...v,busy:!1,status:v.status==="running"||v.status==="suspended"||v.status==="unknown"?m:v.status}}for(const[h,v]of Object.entries(c))v.status==="unknown"&&(v.branchSealed===!0||v.isBranch===!0)&&(c[h]={...v,status:v.branchSealed===!0?"completed":"idle"});return{byId:c,roots:l.roots.map(h=>c[h.agentId])}}class Tp{snapshots=new Map;subagents;coldAgents=new Set;rosterCurrentAgents=new Set;forest;validUntil=1/0;read(e,n,s,i){const r=[...this.snapshots.keys()];if(this.forest!==void 0&&Date.now()<this.validUntil&&this.subagents===n&&this.snapshots.size===e.size&&this.coldAgents.size===(s?.size??0)&&[...this.coldAgents].every(a=>s?.has(a)===!0)&&this.rosterCurrentAgents.size===(i?.size??0)&&[...this.rosterCurrentAgents].every(a=>i?.has(a)===!0)&&[...e].every(([a,d],l)=>{const c=this.snapshots.get(a);return r[l]===a&&c!==void 0&&c.items===d.items&&c.tasks===d.tasks&&c.meta===d.meta&&c.toolCallCount===d.toolCallCount&&Ts(c).toolCallCountKnown===Ts(d).toolCallCountKnown}))return this.forest;this.forest=aa(this.forest,_p(e,n,s,i)),this.snapshots=new Map(e),this.subagents=n,this.coldAgents=new Set(s),this.rosterCurrentAgents=new Set(i),this.validUntil=1/0;const o=Date.now();for(const a of n??[]){if(a.refreshing!==!0)continue;const d=Date.parse(a.refreshing_until??"");d>o&&(this.validUntil=Math.min(this.validUntil,d))}return this.forest}}function Cp(t,e){if(e.size===0)return t;const n=Date.now();return t.filter(s=>s.statusSource!==void 0||e.has(s.agentId)||s.isBranch===!0||s.branchSealed===!0||s.status==="failed"||s.status==="cancelled"||s.disposedAt===void 0&&(s.refreshing===!0&&Date.parse(s.refreshingUntil??"")>n||s.status==="running"||s.status==="suspended"||s.status==="unknown"))}function Fn(t){const e=[],n=s=>{e.push(...s.contentRefs??[])};for(const s of t.items)if(s.kind!=="taskref"&&(n(s),s.kind==="turn"))for(const i of s.steps)for(const r of i.frames)n(r);for(const s of[t.tasks,t.attachments,t.prompts,t.interactions,t.todos])for(const i of s)n(i);return n(t.meta),e}function cs(t,e){switch(e.kind){case"turn":return t.getTurn(e.id);case"frame":return t.getTurn(e.turnId??"")?.steps.find(n=>n.stepId===e.stepId)?.frames.find(n=>n.frameId===e.id);case"task":return t.getTask(e.id);case"attachment":return t.getAttachment(e.id);case"prompt":return t.getPrompt(e.id);case"interaction":return t.getInteraction(e.id);case"todo":return t.getTodo(e.id);case"meta":return t.getMeta();case"marker":return t.getItems().find(n=>n.kind==="marker"&&n.markerId===e.id);default:return}}function Rp(t,e){const n=()=>t.items.find(s=>s.kind==="turn"&&s.turnId===(e.kind==="turn"?e.id:e.turnId));switch(e.kind){case"turn":return n();case"frame":{const s=n();return s?.kind==="turn"?s.steps.find(i=>i.stepId===e.stepId)?.frames.find(i=>i.frameId===e.id):void 0}case"task":return t.tasks.find(s=>s.taskId===e.id);case"attachment":return t.attachments.find(s=>s.attachmentId===e.id);case"prompt":return t.prompts.find(s=>s.promptId===e.id);case"interaction":return t.interactions.find(s=>s.interactionId===e.id);case"todo":return t.todos.find(s=>s.todoId===e.id);case"marker":return t.items.find(s=>s.kind==="marker"&&s.markerId===e.id);case"meta":return t.meta;default:return}}function Ap(t,e){const n=e.ref.source,s=cs(t,n);if(s===void 0)return!1;const i=hn(s,e);return i===s?!1:Fi(t,n,i)}function Fi(t,e,n){let s;switch(e.kind){case"turn":{const i=ot(n,pa(n)),r=t.snapshot();s=[{op:"reset",agentId:t.agentId,snapshot:{...r,items:r.items.map(o=>o.kind==="turn"&&o.turnId===e.id?i:o)}}];break}case"frame":s=[{op:"frame.upsert",turnId:e.turnId,stepId:e.stepId,frame:n}];break;case"task":s=[{op:"task.upsert",task:n}];break;case"attachment":s=[{op:"attachment.upsert",attachment:n}];break;case"prompt":s=[{op:"prompt.upsert",prompt:n}];break;case"interaction":s=[{op:"interaction.upsert",interaction:n}];break;case"todo":s=[{op:"todo.upsert",todo:n}];break;case"meta":s=[{op:"meta.merge",meta:n}];break;case"marker":s=[{op:"marker.upsert",item:n}];break;default:return!1}return t.apply(s).accepted.length>0}function ti(){return`msg_now_${nl().replaceAll("-","")}`}function ud(t,e){return t.promptId===e||t.userMessageId===e}function fd(t,e){const n=Date.parse(e.createdAt);return t.some(s=>s.kind!=="user"||s.steerStatus!==void 0?!1:ud(s,e.promptId)?s.turnId!==void 0||s.promptStatus==="running"||s.promptStatus==="blocked"||s.promptOutcome!==void 0:e.phase==="waiting"&&s.turnId!==void 0&&s.text===e.text&&s.promptId===void 0&&Date.parse(s.createdAt)>=n)}function Mp(t,e){const n=Date.parse(e);if(!Number.isFinite(n))return!1;for(let s=t.length-1;s>=0;s-=1){const i=t[s];if(i?.kind!=="turn")continue;const r=i.startedAt===void 0?Number.NaN:Date.parse(i.startedAt);if(Number.isFinite(r)&&r>n)return!0;if(!(i.stepsPartial===!0||i.contentRefs?.some(d=>d.path.length===1&&d.path[0]==="steps"&&d.direction==="backward")===!0))continue;const a=i.endedAt===void 0?Number.NaN:Date.parse(i.endedAt);if(Number.isFinite(a)&&a>n||i.steps.some(d=>{const l=d.startedAt===void 0?Number.NaN:Date.parse(d.startedAt);return Number.isFinite(l)&&l>n}))return!0}return!1}function Pp(t){return{kind:"user",id:`user-${t.userMessageId??t.promptId}`,text:t.text,presentation:t.presentation,media:t.media,createdAt:t.createdAt,promptId:t.promptId,userMessageId:t.userMessageId??t.promptId,steerStatus:t.phase}}function Ep(t,e){const n=e.filter(o=>!fd(t.blocks,o));if(n.length===0)return t;const s=new Set(n.map(o=>o.promptId)),i=t.blocks.filter(o=>o.kind!=="user"||![...s].some(a=>ud(o,a))),r=t.queuedPromptIds.some(o=>s.has(o))?t.queuedPromptIds.filter(o=>!s.has(o)):t.queuedPromptIds;return{...t,blocks:[...i,...n.map(Pp)],queuedPromptIds:r}}const Op=["session","cursor","snapshotSubagents","agentCounts","resyncing","resyncFailed","resyncAttempt","resyncError","loaded","loadError","durableIngress"];function Dp(){return{version:0,session:void 0,cursor:{seq:0,epoch:void 0},snapshotSubagents:[],agentCounts:void 0,resyncing:!1,resyncFailed:!1,resyncAttempt:0,resyncError:void 0,loaded:!1,loadError:void 0,durableIngress:[]}}function qp(t,e){return Op.every(n=>e[n]===t[n])?t:{version:t.version+1,session:e.session,cursor:e.cursor,snapshotSubagents:e.snapshotSubagents,agentCounts:e.agentCounts,resyncing:e.resyncing,resyncFailed:e.resyncFailed,resyncAttempt:e.resyncAttempt,resyncError:e.resyncError,loaded:e.loaded,loadError:e.loadError,durableIngress:e.durableIngress}}function Fp(t,e){return{...t,version:t.version+e.version,session:e.session,cursor:e.cursor,snapshotSubagents:e.snapshotSubagents,agentCounts:e.agentCounts,resyncing:e.resyncing,resyncFailed:e.resyncFailed,resyncAttempt:e.resyncAttempt,resyncError:e.resyncError,loaded:e.loaded,loadError:e.loadError,durableIngress:e.durableIngress}}function rs(t,e){return t.agent_id!==void 0||e===M?t:{...t,agent_id:e}}const Np=512*1024,ni=4096,Ro=2*1024*1024,os=8*1024*1024,$p="Session is resyncing; sending is paused";function Yt(t){if(t.resyncing||t.resyncFailed)throw new Error($p)}const as=[250,500,1e3,2e3,4e3],Ni=80,jp=40,Bp=60,Lp=40,Hp=1e4,zp=1e3,Ao=32,si=1200;let $i=0;function Kv(t=160){const e=Date.now()+Math.max(0,t);e>$i&&($i=e)}function Cs(){const t=$i-Date.now();return t>0?t:0}const Wp=3,Up=3,Vp=200,Kp=100,ji=globalThis,Mo=128;function Po(t){const e=[];for(const n of t){if(n.kind!=="turn")continue;const s=n.steps.flatMap(i=>{const r=i.frames.filter(o=>o.kind==="tool"&&(o.agentRefs?.length??0)>0);return r.length===0?[]:[{...i,frames:r}]});s.length>0&&e.push({kind:"turn",turnId:n.turnId,ordinal:n.ordinal,state:n.state,origin:n.origin,startedAt:n.startedAt,steps:s})}return e}function Gp(t){switch(t.op){case"turn.upsert":return`turn:${t.turn.turnId}`;case"step.upsert":case"frame.upsert":case"frame.remove":return`turn:${t.turnId}`;case"append":return t.target.type==="frame"?`turn:${t.target.turnId}`:void 0;case"marker.upsert":return`marker:${t.item.markerId}`;case"taskref.upsert":return`taskref:${t.item.refId}`;default:return}}const Qp={schedule(t){const{requestAnimationFrame:e}=ji;return typeof e=="function"?e(t):setTimeout(t,24)},cancel(t){const{cancelAnimationFrame:e}=ji;typeof e=="function"&&typeof t=="number"?e(t):clearTimeout(t)}};function Jp(){return ji.document}function Eo(t){try{return(JSON.stringify(t)?.length??0)*2}catch{return 0}}function Ot(t,e){return t instanceof Ee||t instanceof Error?t.message:e}function ii(t){return t instanceof Error&&t.name==="AbortError"}const Oo=1e3;function Bi(t,e){return new Promise(n=>{if(e?.aborted===!0){n();return}const s=()=>{clearTimeout(i),e?.removeEventListener("abort",s),n()},i=setTimeout(s,t);e?.addEventListener("abort",s,{once:!0})})}class fn{attempt=0;progressed(){this.attempt=0}wait(e){const n=Math.min(Oo,Ni*2**this.attempt);return n<Oo&&(this.attempt+=1),Bi(n,e)}}function Nn(t,e){if(t===void 0||t.length!==e.length)return e;for(let n=0;n<e.length;n+=1){const s=e[n],i=t[n];if(s!==i&&JSON.stringify(s)!==JSON.stringify(i))return e}return t}class Do extends Map{writes=0;set(e,n){return this.writes+=1,super.set(e,n)}delete(e){const n=super.delete(e);return n&&(this.writes+=1),n}clear(){this.size>0&&(this.writes+=1),super.clear()}}function Yp(t){return t.length===0?void 0:t}class Xt extends Error{constructor(e,n){super(n instanceof Error?n.message:String(n)),this.reason=e,this.cause=n,this.name="SendNowError"}}class Gv{constructor(e,n,s,i={}){this.view=n,this.client=e,this.sessionId=s,this.ephemeralHint=i.ephemeral,this.persistenceHint=i.persistenceHint??(i.ephemeral===void 0?"unknown":i.ephemeral?"temporary":"saved"),this.scheduler=i.scheduler??Qp,this.usesBrowserScheduler=i.scheduler===void 0,this.visibilityDocument=this.usesBrowserScheduler?Jp():void 0,this.rewriteResetTimeoutMs=i.rewriteResetTimeoutMs??Hp,this.main=this.timeline(M),this.main.view=Ai(s),this.main.published=this.sessionView(),this.emptyAgentState=Ai(s),this.visibilityDocument?.addEventListener?.("visibilitychange",this.onVisibilityChange)}client;viewHandle;viewAttachPending=!1;connectionGeneration;viewAttachment=0;openGeneration=0;bootstrapOpening;sessionId;shell=Dp();timelines=new Map;main;composedSession;listeners=new Set;interruptedPromptListeners=new Set;scheduler;usesBrowserScheduler;visibilityDocument;rewriteResetTimeoutMs;frameHandle=null;visibleBurstTimer=null;lastVisibleFlushAt=0;typingDeferStartAt=0;inFrameFlush=!1;frameFlushContentDirty=!1;frameFlushForestChanged=!1;frameFlushPublishedMain=!1;hiddenFrameTimer=null;resyncInFlight=!1;resyncInFlightRewrite=!1;resyncDeferredBySuspend;resyncGeneration=0;resyncIdleWaiters=new Set;rosterRefreshInFlight=!1;rosterRefreshDirty=!1;pendingHintRosterAgents=new Set;rosterReadQueued=!1;rosterReadInFlight=!1;rosterReadController;pendingRosterPublish=!1;lastRosterFlushAt=0;rosterRevisionRefreshes=0;subagentLookupsInFlight=new Map;turnStructureRefreshKeys=new Set;rosterRefreshQueuedCursor;rosterTranscriptBindings=new Map;requestedRosterAgents=new Map;rosterAgentIds=new Set;rosterLeaseTimer=null;resyncTimer=null;rewriteHold;rewriteHoldToken=0;closed=!1;abortActiveInFlight;lastRestoredPromptId;snapshotControllers=new Set;dirtyAgents=new Set;storeTimelines=new Set;transcriptBaselineClock=0;toolCountObservations=new Map;toolCountSpans=new Map;pendingTranscriptBatches=new Map;pendingTranscriptAgents=new Set;forestDirtyAgents=new Set;olderLoads=new rp(e=>{const n=this.viewOf(e);n.loadingOlder&&this.publishView(e,Ct(n,!1))});emptyAgentState;unprojectedQueueReceipts=new Map;publishedForest;forestQuery=new Tp;transcriptGrades=Tl;focusedAgentId=M;agentViews=new Map;catchupByAgent=new Map;catchupControllers=new Map;firstScreenSeedControllers=new Map;detailReads=new Map;measuredBytes=new WeakMap;queuedTimingWriteSequence=0;queuedTimingWrites=new Map;contentControllers=new Map;contentReaders=new Map;contentPumpRunning=!1;contentPumpReads=new Map;contentRanges=new Map;contentRangeBytes=0;rangeControllers=new Map;contentBodies=new Do;toolDetails=new Do;contentRevision=0;contentInputs=[];contentListeners=new Set;toolDetailEpochs=new Map;toolDetailReads=new Map;entityPageCursors=new Map;latestSnapshot;durableIngressReadInFlight;durableSteerReads=new Map;durablePromptReads=new Map;durableSteerReadTimer;durableSteerReadInFlight=!1;durableSteerReadGeneration=0;catchupReplay=new Map;ephemeralHint;persistenceHint;getForest=()=>this.publishedForest;onVisibilityChange=()=>{this.closed||(this.isDocumentHidden()?this.cancelVisibleFrameFlush():this.clearHiddenFrameTimer(),(this.pendingTranscriptAgents.size>0||this.pendingTranscriptBatches.size>0)&&this.scheduleFrameFlush())};getState=()=>this.main.published;subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));getContentRevision=()=>this.contentRevision;subscribeContent=e=>(this.contentListeners.add(e),()=>this.contentListeners.delete(e));subscribeInterruptedPrompt=e=>(this.interruptedPromptListeners.add(e),()=>this.interruptedPromptListeners.delete(e));getAgentState=e=>{const n=this.timelines.get(e);return n?.published??n?.view??this.emptyAgentState};getAgentTranscriptCursor=e=>this.timelines.get(e)?.publishedCursor;subscribeAgent=(e,n)=>{const s=this.timeline(e),i=s.listeners;return i.add(n),()=>{i.delete(n),i.size===0&&s.listeners===i&&(s.listeners=new Set)}};timeline(e){let n=this.timelines.get(e);return n===void 0&&(n={agentId:e,store:void 0,marks:new Map,stale:new Set,joins:new Map,windowGrade:void 0,windowEpoch:void 0,refreshing:!1,viewLeases:new Map,paging:0,pagedPin:void 0,readerVisitedOld:!1,relations:[],forestInput:void 0,cursor:void 0,publishedCursor:void 0,olderCursor:void 0,olderTurn:void 0,appliedGrade:void 0,baselineSerial:void 0,generation:0,historyRead:void 0,todoRead:void 0,globalCoverage:void 0,view:void 0,published:void 0,listeners:new Set,steers:[]},this.timelines.set(e,n)),n}viewOf(e){return this.timelines.get(e)?.view??this.emptyAgentState}generationOf(e){return this.timelines.get(e)?.generation??0}sessionView(){const e=this.viewOf(M),n=this.composedSession;if(n?.shell===this.shell&&n.view===e)return n.state;const s=Fp(e,this.shell);return this.composedSession={shell:this.shell,view:e,state:s},s}writeView(e,n){this.timeline(e).view=n,e===M&&this.queueAutomaticRosterRead()}publishView(e,n){n!==this.viewOf(e)&&(this.writeView(e,n),this.publish(e))}publish(e){if(e===M){this.publishTimeline(M),this.inFrameFlush?this.frameFlushContentDirty=!0:this.publishContentRevision();return}this.dirtyAgents.add(e),this.publishDirtyAgents()}publishDirtyAgents(){for(const e of this.dirtyAgents)this.publishTimeline(e);this.dirtyAgents.clear(),this.inFrameFlush?this.frameFlushContentDirty=!0:this.publishContentRevision()}publishTimeline(e){const n=this.timelines.get(e),s=n?.view;if(!(n===void 0||s===void 0)){if(this.retireSettledSteers(e,s),n.published=Ep(e===M?this.sessionView():s,n.steers),e===M)for(const i of this.listeners)i();for(const i of n.listeners)i()}}setShell(e,n=!0){if(e===this.shell)return;const s=e.snapshotSubagents!==this.shell.snapshotSubagents;this.shell=e,s&&(this.rosterAgentIds=new Set(e.snapshotSubagents.map(Rt)),this.scheduleRosterLease()),this.queueAutomaticRosterRead(),n&&this.publish(M)}publishShell(){this.setShell({...this.shell,version:this.shell.version+1})}setSessionView(e,n=!0){if(e===this.sessionView())return;const s=qp(this.shell,e),i=s.snapshotSubagents!==this.shell.snapshotSubagents;this.shell=s,this.main.view={...e,version:this.viewOf(M).version+1},i&&(this.rosterAgentIds=new Set(s.snapshotSubagents.map(Rt)),this.scheduleRosterLease()),this.queueAutomaticRosterRead(),n&&this.publish(M)}publishContentRevision(){const e=this.main.published,n=[this.latestSnapshot,this.toolDetails.writes,this.contentBodies.writes,e.contentRefs,e.detailLoads,e.transcriptResetVersion];for(const{agentId:i,published:r}of this.timelines.values())i===M||r===void 0||n.push(i,r.contentRefs,r.detailLoads);const s=this.contentInputs;if(this.contentInputs=n,!(n.length===s.length&&n.every((i,r)=>i===s[r]))){this.contentRevision+=1;for(const i of this.contentListeners)i()}}clearRosterLeaseTimer(){this.rosterLeaseTimer!==null&&(clearTimeout(this.rosterLeaseTimer),this.rosterLeaseTimer=null)}scheduleRosterLease(){if(this.clearRosterLeaseTimer(),this.closed)return;let e=1/0;for(const n of this.shell.snapshotSubagents){if(n.refreshing!==!0)continue;const s=Date.parse(n.refreshing_until??"");e=Math.min(e,Number.isFinite(s)?s:0)}e!==1/0&&(this.rosterLeaseTimer=setTimeout(()=>{if(this.rosterLeaseTimer=null,this.closed)return;const n=Date.now();let s=!1;const i=this.shell.snapshotSubagents.map(r=>{if(r.refreshing!==!0||Date.parse(r.refreshing_until??"")>n)return r;s=!0;const o=r.status==="completed"||r.status==="failed"||r.status==="cancelled";return{...r,refreshing:void 0,refreshing_until:void 0,live:o?!1:r.live}});if(!s){this.scheduleRosterLease();return}this.setShell({...this.shell,version:this.shell.version+1,snapshotSubagents:i},!1),this.publishForest(),this.publish(M)},Math.min(2147483647,Math.max(0,e-Date.now()))))}isDocumentHidden(){return this.usesBrowserScheduler&&this.visibilityDocument?.visibilityState==="hidden"}cancelVisibleFrameFlush(){this.visibleBurstTimer!==null&&(clearTimeout(this.visibleBurstTimer),this.visibleBurstTimer=null),this.frameHandle!==null&&(this.scheduler.cancel(this.frameHandle),this.frameHandle=null)}clearHiddenFrameTimer(){this.hiddenFrameTimer!==null&&(clearTimeout(this.hiddenFrameTimer),this.hiddenFrameTimer=null)}scheduleFrameFlush(){if(this.frameHandle!==null||this.visibleBurstTimer!==null||this.hiddenFrameTimer!==null||this.closed)return;if(this.isDocumentHidden()){this.hiddenFrameTimer=setTimeout(()=>{this.hiddenFrameTimer=null,this.flushFrames()},zp);return}const e=Date.now(),n=this.usesBrowserScheduler?Cs():0;let s=0;if(this.usesBrowserScheduler)if(n>0){this.typingDeferStartAt===0&&(this.typingDeferStartAt=e);const i=e-this.typingDeferStartAt;i<si&&(s=Math.min(n,si-i))}else{this.typingDeferStartAt=0;const i=this.lastVisibleFlushAt>0?e-this.lastVisibleFlushAt:Ao;s=Ao-i}if(s>0){this.visibleBurstTimer=setTimeout(()=>{if(this.visibleBurstTimer=null,this.closed)return;if(this.isDocumentHidden()){this.scheduleFrameFlush();return}if(Cs()>0&&(this.typingDeferStartAt===0&&(this.typingDeferStartAt=Date.now()),Date.now()-this.typingDeferStartAt<si)){this.scheduleFrameFlush();return}this.typingDeferStartAt=0,this.lastVisibleFlushAt=Date.now(),this.flushFrames()},s);return}this.typingDeferStartAt=0,this.frameHandle=this.scheduler.schedule(()=>{this.frameHandle=null,this.usesBrowserScheduler&&(this.lastVisibleFlushAt=Date.now()),this.flushFrames()})}flushFrames=()=>{if(!this.closed&&(this.flushPendingTranscriptBatches(),this.pendingTranscriptAgents.size>0)){const e=[...this.pendingTranscriptAgents];this.pendingTranscriptAgents.clear();const n=this.inFrameFlush;this.inFrameFlush=!0,n||(this.frameFlushContentDirty=!1,this.frameFlushForestChanged=!1,this.frameFlushPublishedMain=!1);try{const s=e.length>1&&e.includes(M)?[...e.filter(r=>r!==M),M]:e;let i=this.publishedForest===void 0;for(const r of s)this.forestDirtyAgents.delete(r)&&(i=!0);i&&this.publishForest()&&(this.frameFlushForestChanged=!0);for(const r of s){const o=this.timelines.get(r)?.store;o!==void 0&&(r===M&&(this.frameFlushPublishedMain=!0),this.publishProjectedAgent(r,o))}}finally{if(!n){this.inFrameFlush=!1;const s=this.frameFlushForestChanged&&!this.frameFlushPublishedMain,i=this.frameFlushContentDirty;this.frameFlushContentDirty=!1,this.frameFlushForestChanged=!1,this.frameFlushPublishedMain=!1,s?this.publishShell():i&&this.publishContentRevision()}}}};async readSnapshot(e=!1){const n=new AbortController;this.snapshotControllers.add(n);const s=this.viewAttachment;try{let i=await this.view.snapshot({signal:n.signal});if(!e&&!this.closed&&!n.signal.aborted&&s===this.viewAttachment&&(!this.shell.loaded||this.resyncInFlight||i.epoch===this.shell.cursor.epoch&&i.as_of_seq>=this.shell.cursor.seq)){this.latestSnapshot?.epoch===i.epoch&&(i=Dt(this.latestSnapshot,i)),this.latestSnapshot=i;const r=this.viewOf(M);this.main.view={...r,contentRefs:Nn(r.contentRefs,[...Fn(this.windowSnapshot(M)),...i.contentRefs??[]])}}return i}finally{this.snapshotControllers.delete(n)}}async open(){if(this.closed||this.isSuspended)return;if(this.view.bootstrap!==void 0){this.finishBootstrapOpening(),this.transcriptGrades=this.requestedTranscriptGrades();for(const[s,i]of Object.entries(this.transcriptGrades))s==="*"||s===M||i===void 0||be[i]>=be.block&&!this.transcriptPresentable(s)&&this.seedAgentFirstScreen(s);await new Promise(s=>{this.bootstrapOpening={attachment:this.viewAttachment+1,resolve:s};try{this.attachView({seq:0},!0)}catch(i){this.finishBootstrapOpening(),this.setShell({...qn(this.shell,Ot(i,"Could not load session")),loaded:this.shell.loaded})}});return}const e=++this.openGeneration,n=this.viewAttachment;try{const s=await this.readSnapshot();if(this.closed||this.isSuspended||e!==this.openGeneration||n!==this.viewAttachment)return;this.setSessionView(this.applyTranscriptShellSnapshot(s)),this.transcriptGrades=this.requestedTranscriptGrades(),this.attachView({seq:s.as_of_seq,epoch:s.epoch}),this.refreshDurableIngress()}catch(s){if(this.closed||this.isSuspended||e!==this.openGeneration||n!==this.viewAttachment||ii(s))return;this.setShell({...qn(this.shell,Ot(s,"Could not load session")),loaded:this.shell.loaded})}}finishBootstrapOpening(){const e=this.bootstrapOpening;this.bootstrapOpening=void 0,e?.resolve()}attachView(e,n=!1){const s=++this.viewAttachment;this.droppedLiveAgents.clear();const i=this.viewHandle;this.viewHandle=void 0,this.viewAttachPending=!1,i?.close();const r=[...this.timelines.values()].flatMap(({agentId:d,cursor:l})=>l!==void 0&&this.hasTranscriptBaseline(d)?[[d,l]]:[]);this.lowerBaselinesTo(this.transcriptGrades);const o={sessionCursor:e,transcriptGrades:this.transcriptGrades,transcriptSince:r.length===0?void 0:Object.fromEntries(r)},a=d=>{s===this.viewAttachment&&this.handleSignal(d)};this.viewAttachPending=!0,this.viewHandle=n&&this.view.bootstrap!==void 0?this.view.bootstrap(o,a):this.view.subscribe(o,a),n&&this.bootstrapOpening===void 0&&this.viewHandle.updateSessionCursor(this.shell.cursor)}nudge(){if(this.viewHandle?.nudge(),!(this.closed||this.isSuspended)){if(this.shell.loadError!==void 0){this.retryOpen();return}this.shell.resyncFailed&&this.shell.resyncError?.retryable!==!1&&this.resync()}}get suspended(){return this.isSuspended}isSuspended=!1;get parked(){return this.isParked}isParked=!1;suspend(){if(this.closed||this.isSuspended)return;const e=this.resyncDeferredBySuspend?.rewrite===!0||this.resyncInFlightRewrite||this.rewriteHold!==void 0||this.rewriteResyncQueued;(this.resyncDeferredBySuspend!==void 0||this.resyncInFlight||this.shell.resyncing||this.resyncTimer!==null||this.hardResyncQueued||this.rewriteResyncQueued||this.rewriteHold!==void 0)&&(this.resyncDeferredBySuspend={rewrite:e}),this.isParked=!1,this.isSuspended=!0,this.finishBootstrapOpening(),this.pauseDurableSteerReads(),this.resolveResyncIdleWaiters();for(const s of this.snapshotControllers)s.abort();this.snapshotControllers.clear(),this.abortAutomaticRosterRead(),this.cancelAllFirstScreenSeeds(),this.clearResyncTimer(),this.clearRosterLeaseTimer(),this.clearRewriteHold(),this.hardResyncQueued=!1,this.rewriteResyncQueued=!1,this.setShell(Jt(this.shell,!1)),this.cancelVisibleFrameFlush(),this.clearHiddenFrameTimer(),this.pendingTranscriptBatches.clear(),this.catchupReplay.clear(),this.flushFrames();for(const{agentId:s}of this.storeTimelines)this.bumpHistoryGeneration(s);for(const s of this.timelines.values())s.refreshing=!1;this.olderLoads.cancelAll();const n=this.viewOf(M);(n.loadingOlder||n.olderError!==void 0)&&this.writeView(M,{...n,loadingOlder:!1,olderError:void 0}),this.viewAttachment+=1,this.viewAttachPending=!1,this.viewHandle?.close(),this.viewHandle=void 0}cancelParkedReads(){if(this.closed)return;this.isParked=!0,this.abortAutomaticRosterRead(),this.olderLoads.cancelAll(),this.cancelAllFirstScreenSeeds();const e=new Set([M,...this.timelines.keys()]);for(const n of e){const s=this.viewOf(n);(s.loadingOlder||s.olderError!==void 0)&&this.publishView(n,{...s,loadingOlder:!1,olderError:void 0})}for(const n of this.contentReaders.keys())this.retireContentRead(n);for(const[n,s]of this.contentControllers){this.contentControllers.delete(n),this.detailReads.delete(n),s.abort(new DOMException("Read cancelled","AbortError"));const i=n.indexOf("/");i>0&&this.setDetailLoad(n.slice(0,i),n.slice(i+1),void 0)}for(const[n,s]of this.toolDetailReads)this.toolDetailReads.delete(n),s.controller.abort(new DOMException("Read cancelled","AbortError"));for(const n of this.rangeControllers.keys())n.abort(new DOMException("Read cancelled","AbortError"));this.rangeControllers.clear()}unpark(){this.closed||!this.isParked||(this.isParked=!1,this.isSuspended||(this.queueAutomaticRosterRead(),this.contentReaders.size>0&&this.pumpContentReads()))}resume(){if(this.closed||(this.isParked&&this.unpark(),!this.isSuspended))return Promise.resolve();this.isSuspended=!1,this.scheduleDurableSteerRead();const e=this.resyncDeferredBySuspend;return e!==void 0?(this.transcriptGrades=this.requestedTranscriptGrades(),this.resyncInFlight?this.waitForResyncIdle().then(n=>{if(!(n==="cancelled"||this.closed||this.isSuspended))return this.resyncDeferredBySuspend=void 0,this.resync({rewrite:e.rewrite})}):(this.resyncDeferredBySuspend=void 0,this.resync({rewrite:e.rewrite}))):this.shell.loaded?(this.transcriptGrades=this.requestedTranscriptGrades(),this.shell.resyncFailed?this.resync():(this.attachView(this.shell.cursor),this.pumpContentReads(),this.refreshShell())):this.open()}async refreshShell(){const e=this.viewAttachment;try{const n=await this.readSnapshot();if(this.closed||this.isSuspended||e!==this.viewAttachment)return;if(this.shell.cursor.epoch!==void 0&&n.epoch!==this.shell.cursor.epoch){this.resync();return}this.setSessionView(Jt(this.applyTranscriptShellSnapshot(n),this.resyncInFlight),!1),this.publishForest(),this.publish(M)}catch(n){if(this.closed||this.isSuspended||e!==this.viewAttachment||ii(n))return;const s=Ot(n,"Could not load session");this.setShell({...qn(this.shell,s),loaded:this.shell.loaded})}}residentBytes(){let e=0;for(const{store:n}of this.storeTimelines)e+=n.residentReport().estimatedBytes;return e}bytesOf(e){if(e===null||typeof e!="object")return Eo(e);let n=this.measuredBytes.get(e);return n===void 0&&(n=Eo(e),this.measuredBytes.set(e,n)),n}async retryOpen(){this.closed||(this.setShell(qn(this.shell,void 0)),this.shell.loaded&&this.viewHandle!==void 0?await this.refreshShell():await this.open())}close(){this.closed=!0,this.finishBootstrapOpening(),this.pauseDurableSteerReads(),this.durableSteerReads.clear(),this.durablePromptReads.clear(),this.cancelAllFirstScreenSeeds(),this.resolveResyncIdleWaiters();for(const n of this.snapshotControllers)n.abort();this.snapshotControllers.clear(),this.abortAutomaticRosterRead(),this.pendingRosterPublish=!1,this.subagentLookupsInFlight.clear(),this.agentViews.clear(),this.visibilityDocument?.removeEventListener?.("visibilitychange",this.onVisibilityChange),this.clearResyncTimer(),this.clearRosterLeaseTimer(),this.clearRewriteHold(),this.cancelVisibleFrameFlush(),this.clearHiddenFrameTimer(),this.pendingTranscriptBatches.clear(),this.pendingTranscriptAgents.clear();for(const{agentId:n}of this.storeTimelines)this.bumpHistoryGeneration(n);for(const n of this.timelines.values())n.generation=0,n.viewLeases.clear(),n.refreshing=!1;this.contentReaders.clear(),this.contentBodies.clear(),this.toolDetails.clear(),this.contentRanges.clear(),this.contentRangeBytes=0,this.olderLoads.cancelAll(),this.queuedTimingWrites.clear();const e=this.viewOf(M);(e.loadingOlder||e.olderError!==void 0)&&(this.main.view={...e,loadingOlder:!1,olderError:void 0}),this.viewAttachment+=1,this.viewAttachPending=!1,this.viewHandle?.close(),this.viewHandle=void 0}clearResyncTimer(){this.resyncTimer!==null&&(clearTimeout(this.resyncTimer),this.resyncTimer=null)}beginRewriteHold(){if(this.rewriteHold!==void 0)return;const e=this.rewriteHoldToken+=1,n=this.connectionGeneration,s=this.pendingTranscriptBatches.get(M),i={token:e,mainEpoch:(s?.cursor??this.timelines.get(M)?.cursor)?.epoch,generation:Number.isInteger(n)?n:void 0,subscribeToken:void 0,deferredBatches:[],timer:null};s?.ops.some(r=>r.op==="items.remove")===!0&&(this.pendingTranscriptBatches.delete(M),i.deferredBatches.push(s)),i.timer=setTimeout(()=>this.recoverRewriteHold(e),this.rewriteResetTimeoutMs),this.rewriteHold=i}armRewriteSubscription(e){const n=this.rewriteHold;if(n===void 0||n.token!==e||(n.subscribeToken=e,n.mainEpoch!==void 0))return;const s=this.connectionGeneration;n.generation=s===void 0?void 0:s+1,this.viewHandle?.restart()}clearRewriteHold(e){const n=this.rewriteHold;n===void 0||e!==void 0&&n.token!==e||(n.timer!==null&&clearTimeout(n.timer),this.rewriteHold=void 0)}recoverRewriteHold(e){if(!(this.closed||this.rewriteHold?.token!==e)){if(this.clearRewriteHold(e),this.viewHandle?.restart(),this.resyncInFlight){this.hardResyncQueued=!0;return}this.resync()}}matchesRewriteGeneration(e){const n=this.rewriteHold?.generation;return n===void 0||e===n}completesRewriteHold(e,n){return e.mainEpoch!==void 0?n.epoch!==void 0&&n.epoch!==e.mainEpoch:e.subscribeToken===e.token}handleTranscript(e,n){if(this.closed||e.session_id!==this.sessionId)return;const s=this.rewriteHold;if(e.type==="transcript.reset"){if(s!==void 0&&e.agent_id===M){if(!this.matchesRewriteGeneration(n)||!this.completesRewriteHold(s,e.cursor))return;this.clearRewriteHold(s.token)}const i=this.timelines.get(e.agent_id)?.cursor,r=this.timelines.get(e.agent_id)?.appliedGrade,o=this.pendingTranscriptBatches.get(e.agent_id),a=Math.max(i?.seq??-1,o?.throughSeq??-1);if(s===void 0&&!this.catchupByAgent.has(e.agent_id)&&i?.epoch!==void 0&&e.cursor.epoch===i.epoch&&(e.cursor.seq<a||e.cursor.seq===a&&r!==void 0&&be[e.grade]<=be[r])){this.settleRefresh(e.agent_id);return}this.applyTranscriptReset(e.agent_id,e.snapshot,e.coverage,e.cursor,e.grade,e.read);return}if(s!==void 0&&e.agent_id===M){if(!this.matchesRewriteGeneration(n))return;if(s.deferredBatches.length>0||e.ops.some(i=>i.op==="items.remove")){s.deferredBatches.push({ops:[...e.ops],cursor:e.cursor,throughSeq:e.through_seq});return}}this.applyTranscriptOps(e.agent_id,e.ops,e.cursor,e.through_seq)}advanceSessionCursor(e){const n=this.shell.cursor;if(e.seq<n.seq||e.seq===n.seq&&e.epoch===n.epoch)return;const s=this.shell.session!==void 0&&e.seq>this.shell.session.last_seq?{...this.shell.session,last_seq:e.seq}:this.shell.session;this.setShell({...this.shell,version:this.shell.version+1,session:s,cursor:{seq:e.seq,epoch:e.epoch}}),this.viewHandle?.updateSessionCursor(e)}setFocusedAgent(e){this.closed||e===this.focusedAgentId||(this.focusedAgentId=e,this.refreshTranscriptGrades(),e!==void 0&&e!==M&&!this.hasRosterRow(e)&&this.hasTruncatedRoster()&&this.lookupMissingRosterAgent(e))}retainAgentView(e,n,s){if(!this.closed){if(e.trim()===""||n.trim()===""||n==="*")throw new Error("Agent views require a view ID and a concrete agent ID");this.agentViews.set(e,{agentId:n,grade:s}),this.refreshTranscriptGrades(),n!==M&&!this.hasRosterRow(n)&&this.hasTruncatedRoster()&&this.lookupMissingRosterAgent(n)}}updateAgentView(e,n){if(this.closed)return;const s=this.agentViews.get(e);s===void 0||s.grade===n||(this.agentViews.set(e,{agentId:s.agentId,grade:n}),this.refreshTranscriptGrades())}releaseAgentView(e){this.agentViews.delete(e)&&this.refreshTranscriptGrades()}requestedTranscriptGrades(){const e=this.focusedAgentId;return Cl(e===void 0?this.agentViews.values():[{agentId:e,grade:"delta"},...this.agentViews.values()])}lowerBaselinesTo(e){for(const n of this.timelines.values()){const s=n.appliedGrade,i=rt(e,n.agentId);s!==void 0&&i!=="off"&&be[i]<be[s]&&(n.appliedGrade=i)}}scheduledTranscriptGrades;refreshTranscriptGrades(){if(this.closed)return;const e=this.requestedTranscriptGrades(),n=this.transcriptGrades;if(Object.keys(n).length===Object.keys(e).length&&Object.entries(e).every(([r,o])=>n[r]===o))return;for(const{agentId:r}of this.storeTimelines)rt(this.transcriptGrades,r)!==rt(e,r)&&(this.bumpHistoryGeneration(r),this.catchupReplay.delete(r));this.transcriptGrades=e;for(const[r,o]of this.firstScreenSeedControllers)be[rt(e,r)]<be.block&&(this.firstScreenSeedControllers.delete(r),o.abort());for(const r of this.storeTimelines){const o=be[rt(n,r.agentId)],a=be[rt(e,r.agentId)];if(o===a)continue;const d=this.viewHandle!==void 0&&a>be.off&&r.appliedGrade!==void 0&&be[r.appliedGrade]<a;r.refreshing=d,this.publishProjectedAgent(r.agentId,r.store)}const s=this.viewHandle;if(s===void 0||this.scheduledTranscriptGrades?.handle===s)return;const i={handle:s,previous:n};this.scheduledTranscriptGrades=i,queueMicrotask(()=>{if(this.scheduledTranscriptGrades===i&&(this.scheduledTranscriptGrades=void 0,!(this.closed||this.isSuspended||this.viewHandle!==s))){if(Object.keys(i.previous).length===Object.keys(this.transcriptGrades).length&&Object.entries(this.transcriptGrades).every(([r,o])=>i.previous[r]===o)){for(const r of this.timelines.values())r.refreshing&&this.hasTranscriptBaseline(r.agentId)&&this.settleRefresh(r.agentId);return}this.lowerBaselinesTo(this.transcriptGrades);for(const r of this.storeTimelines){const o=be[rt(this.transcriptGrades,r.agentId)],a=o>be.off&&r.appliedGrade!==void 0&&be[r.appliedGrade]<o;a&&!r.refreshing?(r.refreshing=!0,this.publishProjectedAgent(r.agentId,r.store)):!a&&r.refreshing&&this.settleRefresh(r.agentId)}if(this.viewAttachPending=!0,s.setTranscriptGrades(this.transcriptGrades),this.view.bootstrap!==void 0)for(const[r,o]of Object.entries(this.transcriptGrades))r==="*"||r===M||o===void 0||be[o]>=be.block&&!this.transcriptPresentable(r)&&this.seedAgentFirstScreen(r)}})}cancelFirstScreenSeed(e){const n=this.firstScreenSeedControllers.get(e);n!==void 0&&(this.firstScreenSeedControllers.delete(e),n.abort())}cancelAllFirstScreenSeeds(){for(const e of this.firstScreenSeedControllers.values())e.abort();this.firstScreenSeedControllers.clear()}async seedAgentFirstScreen(e){if(this.closed||this.isSuspended||this.firstScreenSeedControllers.has(e)||typeof this.view.transcript?.page!="function")return;const n=new AbortController;this.firstScreenSeedControllers.set(e,n);const s=n.signal,i=new fn;let r;try{for(;;){if(this.closed||this.isSuspended||s.aborted||this.hasTranscriptBaseline(e))return;const o=rt(this.transcriptGrades,e);if(be[o]<be.block)return;const a=await this.readPreparedContent(()=>this.view.transcript.page({agentId:e,beforeItem:r,pageSize:20},{signal:s}),s,"high");if(this.closed||this.isSuspended||s.aborted||this.hasTranscriptBaseline(e))return;const d=rt(this.transcriptGrades,e);if(be[d]<be.block||a.agent_id!==e)return;if(a.has_more&&a.items.length===0&&(a.read?.readiness==="preparing"||a.read?.readiness==="partial")){a.next_cursor!==void 0&&a.next_cursor!==r&&(i.progressed(),r=a.next_cursor),await i.wait(s);continue}const c=this.timeline(e);if(c.paging>0)return;this.pendingTranscriptBatches.delete(e),this.pendingTranscriptAgents.delete(e),this.catchupReplay.delete(e);const u=this.ensureAgentTranscript(e);this.bumpHistoryGeneration(e);const f=a.coverage??{kind:a.has_more?"tail":"full",hasMoreOlder:a.has_more},g={items:a.items,hasMoreOlder:a.has_more,olderCursor:a.next_cursor,toolCallCount:a.tool_call_count,toolCallCountKnown:f.kind!=="unknown",tasks:a.tasks??[],interactions:a.interactions??[],attachments:a.attachments??[],todos:a.todos??[],prompts:a.prompts??[],meta:a.meta??{}},h=a.read?.watermark?.transcript??a.cursor;u.apply([{op:"reset",agentId:e,snapshot:g,coverage:f,grade:d==="off"?void 0:d,read:a.read}]),u.setHasMoreOlder(a.has_more),c.olderCursor=a.next_cursor,c.olderTurn=a.items.find(v=>v.kind==="turn")?.turnId,c.globalCoverage=a.globalCoverage,c.marks=new Map(a.items.flatMap(v=>h===void 0?[]:[[ht(v),h]])),c.stale.clear(),c.joins.clear(),c.windowGrade=d,c.windowEpoch=h?.epoch,h!==void 0&&h.epoch?.startsWith("cold:")!==!0&&(c.cursor=h),c.appliedGrade??="turn",c.refreshing=this.viewHandle!==void 0&&this.viewAttachPending&&!this.hasTranscriptBaseline(e),a.read!==void 0&&(c.historyRead=a.read),this.forestDirtyAgents.add(e),this.publishProjectedAgent(e,u,{loadingOlder:!1,olderError:void 0,retainPendingPrompts:!0,historyCoverageKind:f.kind==="full"?"full":f.kind==="unknown"?"unknown":"tail"});return}}catch{}finally{this.firstScreenSeedControllers.get(e)===n&&this.firstScreenSeedControllers.delete(e)}}settleRefresh(e){const n=this.timelines.get(e);if(n===void 0||!n.refreshing)return;n.refreshing=!1;const s=n.view;s!==void 0&&s.refreshing===!0&&this.publishView(e,{...s,version:s.version+1,refreshing:!1}),this.contentReaders.size>0&&this.pumpContentReads()}hasTranscriptBaseline(e){const n=this.timelines.get(e)?.appliedGrade;return n!==void 0&&be[n]>=be[rt(this.transcriptGrades,e)]}transcriptPresentable(e){if(this.hasTranscriptBaseline(e))return!0;const n=this.timelines.get(e);return n?.appliedGrade!==void 0&&n.windowGrade!==void 0&&be[n.windowGrade]>=be[rt(this.transcriptGrades,e)]}handleSignal(e){if(!(this.closed||this.connectionGeneration!==void 0&&e.generation<this.connectionGeneration))switch(this.connectionGeneration=e.generation,e.type){case"status":e.status!=="open"?this.handleWsDrop():this.viewHandle!==void 0&&(this.viewAttachPending=!0);return;case"snapshot":{if(this.bootstrapOpening?.attachment!==this.viewAttachment)return;const n=e.snapshot;if(n.session.id!==this.sessionId){this.handleSignal({type:"protocolError",detail:"Session snapshot identity changed",recoverable:!1,generation:e.generation});return}this.latestSnapshot=n,this.setSessionView(this.applyTranscriptShellSnapshot(n),!1),this.viewHandle?.updateSessionCursor(this.shell.cursor),this.finishBootstrapOpening();const s=this.timelines.get(M)?.store;s!==void 0&&this.hasTranscriptBaseline(M)&&this.publishProjectedAgent(M,s),this.retireRequestedRosterAgents(),this.publishForest(),this.publish(M);const i=this.rosterRefreshQueuedCursor;this.rosterRefreshQueuedCursor=void 0,this.rosterRefreshDirty=!1,i!==void 0&&(this.requestedRosterAgents.size>0||i.epoch===n.epoch&&i.seq>n.as_of_seq)&&this.refreshRoster(i),this.refreshDurableIngress();return}case"ready":if(this.scheduledTranscriptGrades===void 0){this.viewAttachPending=!1;for(const{agentId:n}of this.timelines.values())this.settleRefresh(n)}else for(const{agentId:n}of this.timelines.values())this.hasTranscriptBaseline(n)&&this.settleRefresh(n);if(this.resyncInFlight)return;if(this.shell.cursor.epoch!==void 0&&e.currentSessionCursor.epoch!==this.shell.cursor.epoch){this.handleSubscribeRejected(e.generation);return}this.advanceSessionCursor(e.currentSessionCursor),e.reconnected&&(this.handleReconnectAck(),this.refreshDurableIngress(),this.shell.snapshotSubagents.length>0&&this.refreshRoster(e.currentSessionCursor));return;case"sessionCursorAdvanced":this.advanceSessionCursor(e.cursor),e.title!==void 0&&this.shell.session!==void 0&&this.setSessionView(Io(this.sessionView(),{...this.shell.session,title:e.title})),e.rosterAgentId!==void 0&&(this.pendingHintRosterAgents.add(e.rosterAgentId),this.hasRosterRow(e.rosterAgentId)?this.refreshRoster(e.cursor):this.requestRosterRows([e.rosterAgentId],e.cursor));return;case"historyRewritten":this.advanceSessionCursor(e.cursor),this.shell.resyncError?.retryable!==!1&&this.resync({rewrite:!0});return;case"transcript":this.handleTranscript(e.event,e.generation);return;case"protocolError":{if(this.shell.resyncError?.retryable===!1)return;if(this.bootstrapOpening!==void 0&&(this.finishBootstrapOpening(),this.setShell(qn(this.shell,e.detail),!1)),this.setShell({...ko(Jt(this.shell,!1),!0,this.shell.resyncAttempt+1),resyncError:{message:e.detail,code:Ce.INVALID_RESPONSE,retryable:e.recoverable}}),e.recoverable)this.resync();else{this.viewAttachPending=!1;for(const{agentId:n}of this.timelines.values())this.settleRefresh(n);this.clearResyncTimer(),this.clearRewriteHold(),this.hardResyncQueued=!1,this.rewriteResyncQueued=!1,this.viewAttachment+=1,this.viewHandle?.close(),this.viewHandle=void 0}return}case"resyncRequired":if(this.shell.resyncError?.retryable===!1)return;this.rewriteHold!==void 0?this.handleSubscribeRejected(e.generation):this.resync({rewrite:e.reason==="history_rewritten"});return}}abortAutomaticRosterRead(){const e=this.rosterReadController;this.rosterReadController=void 0,e?.abort(new DOMException("Read cancelled","AbortError"))}hasTruncatedRoster(){return(this.shell.agentCounts?.subagents??0)>this.shell.snapshotSubagents.length?!0:this.latestSnapshot?.contentRefs?.some(e=>e.source.kind==="snapshot"&&e.kind==="array"&&e.path.length===1&&e.path[0]==="subagents")===!0}flushSnapshotRoster(e){this.pendingRosterPublish=!1,this.lastRosterFlushAt=Date.now();const n=Nn(this.viewOf(M).contentRefs,[...Fn(this.windowSnapshot(M)),...e.contentRefs??[]]);this.setSessionView({...this.sessionView(),snapshotSubagents:this.mergeRosterRows(e),contentRefs:n},!1),this.publishForest(),this.publish(M)}flushPendingRosterPublish(){if(!this.pendingRosterPublish||this.closed)return;const e=this.latestSnapshot;this.pendingRosterPublish=!1,e!==void 0&&this.flushSnapshotRoster(e)}mergeSupplementalRosterRows(e){if(e.length===0)return!1;const n=this.shell.snapshotSubagents,s=new Map;for(let o=0;o<n.length;o+=1)s.set(Rt(n[o]),o);const i=[...n];let r=!1;for(const o of e){const a=Rt(o);if(a==="")continue;const d=s.get(a);d===void 0?(s.set(a,i.length),i.push(o),r=!0):i[d]!==o&&(i[d]=o,r=!0)}return r?(this.setShell({...this.shell,version:this.shell.version+1,snapshotSubagents:i},!1),this.retireRequestedRosterAgents(),this.publishForest(),this.publish(M),!0):!1}async lookupMissingRosterAgent(e,n=!1){if(this.closed||this.isSuspended||e===""||e===M||!n&&this.hasRosterRow(e)||!(this.view.subagents!==void 0||this.client.searchSubagents!==void 0))return;const i=this.subagentLookupsInFlight.get(e);if(i!==void 0)return i;let r;return r=(async()=>{try{const o=this.view.subagents!==void 0?await this.view.subagents({agentId:e,limit:1}):await this.client.searchSubagents(this.sessionId,{agent_id:e,limit:1});if(this.closed||this.isSuspended)return;this.mergeSupplementalRosterRows(o.items)}catch{}finally{this.subagentLookupsInFlight.get(e)===r&&this.subagentLookupsInFlight.delete(e)}})(),this.subagentLookupsInFlight.set(e,r),r}async searchSubagents(e,n={}){if(this.closed)return[];const s=e.trim(),i=n.status?.trim(),r=n.limit===void 0?void 0:Math.min(500,Math.max(1,n.limit)),o=r??32;if(this.view.subagents!==void 0||this.client.searchSubagents!==void 0){const u=this.view.subagents!==void 0?await this.view.subagents({q:s===""?void 0:s,status:i===""?void 0:i,limit:r},{signal:n.signal}):await this.client.searchSubagents(this.sessionId,{q:s===""?void 0:s,status:i===""?void 0:i,limit:r},{signal:n.signal});if(this.closed||n.signal?.aborted)return[];this.mergeSupplementalRosterRows(u.items),this.publishedForest===void 0&&this.publishForest();const f=this.publishedForest,g=[];for(const h of u.items){const v=Rt(h),m=f?.byId[v];m!==void 0&&g.push(m)}return g}this.publishedForest===void 0&&this.publishForest();const a=this.publishedForest;if(a===void 0)return[];const d=s.toLowerCase(),l=i?.toLowerCase()??"",c=[];for(const u of Object.values(a.byId))if(u.agentId!==M&&!(l!==""&&!(l==="active"?u.status==="running"||u.status==="suspended"||u.status==="background":l==="branch"?u.isBranch===!0:u.status===l))&&!(d!==""&&!(u.agentId.toLowerCase().includes(d)||u.label.toLowerCase().includes(d)||u.name.toLowerCase().includes(d)||(u.description?.toLowerCase().includes(d)??!1)||(u.model?.toLowerCase().includes(d)??!1)||(u.summary?.toLowerCase().includes(d)??!1)))&&(c.push(u),c.length>=o))break;return c}queueAutomaticRosterRead(){if(this.closed||this.isSuspended||this.isParked||!this.shell.loaded||this.shell.resyncing||this.rosterReadQueued||this.rosterReadInFlight||this.olderLoads.hasActive())return;const e=this.latestSnapshot?.contentRefs?.find(n=>n.source.kind==="snapshot"&&n.kind==="array"&&n.path.length===1&&n.path[0]==="subagents");if(e===void 0||e.total>Vp||this.view.transcript.content===void 0||this.viewOf(M).detailLoads[`content:${JSON.stringify(e)}`]?.status==="error"){this.flushPendingRosterPublish();return}this.rosterReadQueued=!0,queueMicrotask(()=>{if(this.rosterReadQueued=!1,this.closed||this.isSuspended||this.isParked||this.shell.resyncing||this.olderLoads.hasActive()){this.flushPendingRosterPublish();return}this.rosterReadInFlight=!0,this.loadContentSegmentInternal(M,e,!0).then(n=>{this.rosterReadInFlight=!1,n||!this.latestSnapshot?.contentRefs?.some(s=>Pt(s,e))?this.queueAutomaticRosterRead():this.flushPendingRosterPublish()})})}mergeRosterRows(e){const n=e.subagents??[],s=new Map(n.map(a=>[Rt(a),a])),i=e.contentRefs?.some(a=>a.path[0]==="subagents"&&a.kind==="array")===!0,o=[...this.shell.snapshotSubagents.flatMap(a=>{const d=Rt(a),l=s.get(d);return s.delete(d),l===void 0?i?[a]:[]:[l]}),...s.values()];return o.length>this.shell.snapshotSubagents.length&&(this.rosterRevisionRefreshes=0),o}applyTranscriptShellSnapshot(e){return{...sp(this.sessionId,e,this.sessionView()),snapshotSubagents:this.mergeRosterRows(e)}}async refreshRoster(e){if(this.closed||this.isSuspended||this.resyncInFlight)return;const n=e.epoch!==void 0||this.shell.cursor.epoch===void 0?e:{seq:e.seq,epoch:this.shell.cursor.epoch};if(this.rosterRefreshInFlight||this.bootstrapOpening!==void 0){const d=this.rosterRefreshQueuedCursor;(d===void 0||n.epoch!==d.epoch||n.seq>=d.seq)&&(this.rosterRefreshQueuedCursor=n),this.rosterRefreshDirty=!0;return}this.rosterRefreshInFlight=!0;const s=[...this.pendingHintRosterAgents];this.pendingHintRosterAgents.clear();let i=!1;const r=this.viewAttachment,o=this.connectionGeneration,a=new Map([...this.storeTimelines].map(({agentId:d,store:l})=>[d,l.getMeta().agent]));try{const d=await this.readSnapshot(!0),l=this.rosterRefreshQueuedCursor,c=n.epoch??this.shell.cursor.epoch;if(this.closed||this.isSuspended||this.resyncInFlight||r!==this.viewAttachment||o!==this.connectionGeneration||c!==void 0&&d.epoch!==c||this.shell.cursor.epoch!==void 0&&d.epoch!==this.shell.cursor.epoch||d.as_of_seq<n.seq||l!==void 0&&c!==void 0&&l.epoch===c&&d.as_of_seq<l.seq||d.subagents===void 0)return;const u=this.latestSnapshot,f=u?.epoch===d.epoch?Dt(u,d):d;this.latestSnapshot=u?.epoch===f.epoch?ot(f,{...u,subagents:f.subagents,contentRefs:[...(u.contentRefs??[]).filter(h=>h.path[0]!=="subagents"),...(f.contentRefs??[]).filter(h=>h.path[0]==="subagents")]}):f,this.setSessionView({...this.sessionView(),snapshotSubagents:this.mergeRosterRows(f),agentCounts:d.agent_counts,contentRefs:Nn(this.viewOf(M).contentRefs,[...Fn(this.windowSnapshot(M)),...this.latestSnapshot.contentRefs??[]])},!1);const g=new Set;for(const h of f.subagents??[]){const v=Rt(h);g.add(v);const m=this.timelines.get(v)?.store?.getMeta().agent;rt(this.transcriptGrades,v)==="off"&&m!==void 0&&m===a.get(v)&&this.rosterTranscriptBindings.set(v,m)}if(this.retireRequestedRosterAgents(),this.publishForest(),this.publish(M),i=!0,s.length>0&&this.hasTruncatedRoster()&&(this.view.subagents!==void 0||this.client.searchSubagents!==void 0))for(const h of s)h!==""&&h!==M&&!g.has(h)&&this.hasRosterRow(h)&&this.lookupMissingRosterAgent(h,!0)}catch{}finally{if(!i&&!this.closed&&!this.isSuspended&&r===this.viewAttachment&&o===this.connectionGeneration)for(const c of s)this.pendingHintRosterAgents.add(c);this.rosterRefreshInFlight=!1;const d=this.rosterRefreshQueuedCursor,l=this.rosterRefreshDirty;this.rosterRefreshQueuedCursor=void 0,this.rosterRefreshDirty=!1,d!==void 0&&(l||d.seq>n.seq||d.epoch!==n.epoch)&&!this.closed&&!this.resyncInFlight&&this.refreshRoster(d)}}hasRosterRow(e){return this.rosterAgentIds.has(e)}retireRequestedRosterAgents(){for(const e of this.requestedRosterAgents.keys())this.hasRosterRow(e)&&this.requestedRosterAgents.delete(e)}requestRosterRows(e,n,s=!1){if(this.closed||this.isSuspended)return;let i=!1,r=!1;const o=[];for(const a of e){if(a===""||a===M||this.hasRosterRow(a))continue;const d=this.requestedRosterAgents.get(a)??0;if(!(d>=Wp)){if(!s&&d>0){(this.rosterRefreshInFlight||this.bootstrapOpening!==void 0)&&(r=!0);continue}this.requestedRosterAgents.set(a,d+1),i=!0,o.push(a)}}if(!i){r&&this.refreshRoster(n??this.shell.cursor);return}if(this.hasTruncatedRoster()&&(this.view.subagents!==void 0||this.client.searchSubagents!==void 0)){for(const a of o)this.lookupMissingRosterAgent(a);return}this.refreshRoster(n??this.shell.cursor)}handleSubscribeRejected(e){if(this.closed||this.shell.resyncError?.retryable===!1)return;const n=this.rewriteHold;if(n===void 0){this.resync();return}this.matchesRewriteGeneration(e)&&this.recoverRewriteHold(n.token)}droppedLiveAgents=new Set;handleWsDrop(){if(!this.closed){for(const{agentId:e,view:n}of this.timelines.values()){if(n===void 0||rt(this.transcriptGrades,e)==="off")continue;const s=n.blocks.some(i=>(i.kind==="assistant"||i.kind==="thinking")&&i.streaming);(n.busy||s)&&this.droppedLiveAgents.add(e)}this.shell.session?.busy===!0&&rt(this.transcriptGrades,"main")!=="off"&&this.droppedLiveAgents.add("main")}}handleReconnectAck(){if(this.closed||this.droppedLiveAgents.size===0||this.shell.resyncError?.retryable===!1)return;const e=new Set(this.droppedLiveAgents);this.droppedLiveAgents.clear(),this.refreshDurableIngress();const n=[...this.storeTimelines].map(({agentId:s})=>s);if(n.length===0){this.resync();return}for(const s of n)(e.has(s)||!this.hasTranscriptBaseline(s))&&this.catchUpAgent(s)}rewriteResyncQueued=!1;hardResyncQueued=!1;resolveResyncIdleWaiters(){const e=[...this.resyncIdleWaiters];this.resyncIdleWaiters.clear();for(const n of e)n()}waitForResyncIdle(e){const n=()=>this.closed||this.isSuspended||e?.aborted?"cancelled":this.shell.resyncFailed?"failed":"ready";return e?.aborted||this.closed||this.isSuspended||!this.resyncInFlight?Promise.resolve(n()):new Promise(s=>{let i=!1;const r=()=>{i||(i=!0,this.resyncIdleWaiters.delete(r),e?.removeEventListener("abort",r),s(n()))};this.resyncIdleWaiters.add(r),e?.addEventListener("abort",r,{once:!0}),this.resyncInFlight||r()})}async resync(e={}){if(this.closed||this.isSuspended)return;this.finishBootstrapOpening();const n=e.rewrite===!0;n&&this.beginRewriteHold();const s=n?this.rewriteHold?.token:void 0;if(this.resyncInFlight){n&&(this.rewriteResyncQueued=!0);return}this.resyncInFlight=!0,this.resyncInFlightRewrite=n,this.resyncGeneration+=1,this.abortAutomaticRosterRead(),this.pendingRosterPublish=!1;for(const{agentId:a}of this.storeTimelines)this.bumpHistoryGeneration(a);n&&(this.rewriteResyncQueued=!1),this.clearResyncTimer(),this.setShell(Jt(this.shell,!0));const i=this.viewAttachment,r=new Map([...this.timelines.values()].map(({agentId:a,baselineSerial:d})=>[a,d])),o=n?new Map([...this.timelines.values()].map(({agentId:a,cursor:d})=>[a,d])):void 0;try{const a=await this.readSnapshot();if(this.closed||i!==this.viewAttachment)return;for(const{agentId:c}of this.storeTimelines)this.bumpHistoryGeneration(c);this.catchupReplay.clear();const d=new Set([...this.storeTimelines].map(({agentId:c})=>c).filter(c=>{const u=this.timelines.get(c)?.cursor?.epoch;return this.timelines.get(c)?.baselineSerial!==r.get(c)&&this.hasTranscriptBaseline(c)&&(!n||u!==void 0&&u!==o?.get(c)?.epoch)}));for(const c of this.pendingTranscriptBatches.keys())d.has(c)||this.pendingTranscriptBatches.delete(c);for(const c of this.pendingTranscriptAgents)d.has(c)||this.pendingTranscriptAgents.delete(c);for(const c of this.timelines.values()){const{agentId:u,view:f}=c;if(c.refreshing=!1,u===M||f===void 0)continue;const g=d.has(u);f.transcriptReady===g&&f.refreshing!==!0&&!f.loadingOlder&&f.olderError===void 0||(c.view={...f,version:f.version+1,transcriptReady:g,refreshing:!1,loadingOlder:!1,olderError:void 0},this.dirtyAgents.add(u))}const l=d.has(M);for(const c of this.timelines.values())d.has(c.agentId)||(c.cursor=void 0,c.appliedGrade=void 0);this.setSessionView(Jt({...this.applyTranscriptShellSnapshot(a),transcriptReady:l,refreshing:!1,loadingOlder:!1,olderError:void 0},!1)),this.publishDirtyAgents(),this.attachView({seq:a.as_of_seq,epoch:a.epoch}),s!==void 0&&this.armRewriteSubscription(s)}catch(a){if(s!==void 0&&this.clearRewriteHold(s),!this.closed&&!this.isSuspended&&!(i!==this.viewAttachment&&ii(a))&&(i===this.viewAttachment||this.shell.resyncError?.retryable!==!1)){const d=this.shell.resyncAttempt+1,l=a instanceof Ee||a instanceof mt?a.code:void 0,c=l===void 0||l===-1||l===Ce.TIMEOUT||l===Ce.SESSION_INDEX_BUILDING||l===408||l===429||l>=500&&l<600||l>=5e4;if(this.setShell({...ko(Jt(this.shell,!1),!0,d),resyncError:{message:Ot(a,"Could not restore session"),code:l,requestId:a instanceof Ee?a.requestId:void 0,retryable:c}}),c)this.scheduleResyncRetry();else{for(const{agentId:u}of this.timelines.values())this.settleRefresh(u);this.clearRewriteHold(),this.hardResyncQueued=!1,this.rewriteResyncQueued=!1}}}finally{this.resyncInFlight=!1,this.resyncInFlightRewrite=!1;let a=!1;!this.closed&&!this.isSuspended?this.hardResyncQueued?(a=!0,this.hardResyncQueued=!1,this.rewriteResyncQueued=!1,queueMicrotask(()=>void this.resync())):this.rewriteResyncQueued&&(a=!0,this.rewriteResyncQueued=!1,queueMicrotask(()=>void this.resync({rewrite:!0}))):this.isSuspended&&(this.resyncDeferredBySuspend={rewrite:this.resyncDeferredBySuspend?.rewrite===!0||n||this.rewriteResyncQueued},this.hardResyncQueued=!1,this.rewriteResyncQueued=!1),a||(this.closed||this.setShell(Jt(this.shell,!1)),this.resolveResyncIdleWaiters())}}scheduleResyncRetry(){if(this.closed||this.isSuspended||this.resyncTimer!==null)return;const e=Math.min(this.shell.resyncAttempt,as.length)-1,n=as[Math.max(0,e)]??4e3;this.resyncTimer=setTimeout(()=>{this.resyncTimer=null,this.closed||this.resync()},n)}setPersistenceHint(e){e!==void 0&&(e==="unknown"&&this.persistenceHint!==void 0&&this.persistenceHint!=="unknown"||e==="temporary"&&this.persistenceHint==="saved"||(this.persistenceHint=e))}setEphemeralHint(e){e!==void 0&&(e&&this.persistenceHint==="saved"||(this.ephemeralHint=e,this.setPersistenceHint(e?"temporary":"saved")))}usesDurableSubmission(){return this.persistenceHint==="temporary"||this.persistenceHint==="unknown"?!1:this.persistenceHint==="saved"?!0:this.ephemeralHint!==!0&&this.shell.session?.ephemeral!==!0}hasKnownSavedSession(){return this.persistenceHint!==void 0?this.persistenceHint==="saved":this.ephemeralHint===!1||this.shell.session?.ephemeral===!1}handleSessionRecord=e=>{if(e.id!==this.sessionId||this.closed)return;const n=this.shell.session;(n===void 0||e.updated_at>=n.updated_at)&&(e.ephemeral!==void 0&&this.setEphemeralHint(e.ephemeral),this.setSessionView(Io(this.sessionView(),e)))};setDurableIngress(e){for(const s of e){const i=s.agent_id??M;if(s.admission==="failed"||s.admission==="cancelled"||s.delivery_state==="failed"||s.delivery_state==="cancelled"||s.admission==="admitted"&&s.delivery_state==="queued"){this.reconcileSteerOutcome(i,s.prompt_id,this.settledSteerOutcome(i,s.prompt_id));continue}const r=this.findPendingSteer(i,s.prompt_id);if(r===void 0)continue;const o=s.admission==="held"?"held":s.admission==="admitted"?"waiting":(s.admission==="restoring"||s.admission==="waiting_switch")&&r.phase!=="waiting"?"preparing":r.phase;o!==r.phase&&this.setPendingSteer(i,{...r,phase:o}),s.admission!==void 0&&Er(this.sessionId,s.prompt_id,i)}const n=this.shell.durableIngress??[];n.length===e.length&&n.every((s,i)=>{const r=e[i];return r!==void 0&&s.prompt_id===r.prompt_id&&(s.agent_id??M)===(r.agent_id??M)&&s.status===r.status&&s.admission===r.admission&&s.delivery_state===r.delivery_state&&s.delivery_reason===r.delivery_reason&&s.revision===r.revision&&s.admission_content_truncated===r.admission_content_truncated&&s.admission_error?.code===r.admission_error?.code&&s.admission_error?.message===r.admission_error?.message&&s.admission_duplicate_of===r.admission_duplicate_of&&s.restore_progress?.phase===r.restore_progress?.phase&&s.restore_progress?.elapsed_ms===r.restore_progress?.elapsed_ms&&s.restore_progress?.queue_position===r.restore_progress?.queue_position})||this.setShell({...this.shell,version:this.shell.version+1,durableIngress:[...e]})}observeDurableSteer(e,n){if(this.client.getDurableIngress===void 0||this.closed)return;const s=JSON.stringify([e,n]);this.durableSteerReads.has(s)||(this.durableSteerReads.set(s,{agentId:e,promptId:n}),this.scheduleDurableSteerRead())}scheduleDurableSteerRead(){this.durableSteerReads.size===0||this.durableSteerReadTimer!==void 0||this.durableSteerReadInFlight||this.closed||this.isSuspended||(this.durableSteerReadTimer=setTimeout(()=>{this.durableSteerReadTimer=void 0,this.readDurableSteer()},500))}async readDurableSteer(){const e=this.durableSteerReads.entries().next().value;if(e===void 0||this.closed||this.isSuspended)return;const[n,s]=e,i=this.durablePromptReads.get(n),r=i!==void 0&&(this.timelines.get(s.agentId)?.store?.getPrompt(s.promptId)!==void 0||this.viewOf(s.agentId).blocks.some(a=>a.kind==="user"&&a.promptId===s.promptId));if(r&&this.durablePromptReads.delete(n),this.findPendingSteer(s.agentId,s.promptId)===void 0&&(i===void 0||r)){this.durableSteerReads.delete(n),this.scheduleDurableSteerRead();return}const o=this.durableSteerReadGeneration;this.durableSteerReadInFlight=!0;try{const a=await this.client.getDurableIngress(this.sessionId,s.promptId,s.agentId);if(this.closed||this.isSuspended||o!==this.durableSteerReadGeneration)return;const d=rs(a,s.agentId);if(this.setDurableIngress([...this.getDurableIngress().filter(l=>l.prompt_id!==d.prompt_id||(l.agent_id??M)!==s.agentId),d]),a.admission!=="restoring"&&a.admission!=="waiting_switch"&&(this.durableSteerReads.delete(n),this.durablePromptReads.delete(n),a.admission==="admitted")){if(i!==void 0)if(s.agentId===M)this.adoptAdmittedMainPrompt(a,i);else{const l=this.viewOf(s.agentId);if(this.timelines.get(s.agentId)?.store?.getPrompt(a.prompt_id)===void 0&&!l.blocks.some(c=>c.kind==="user"&&c.promptId===a.prompt_id)){const c=dt(a.content);this.publishView(s.agentId,Dn(l,{userMessageId:a.user_message_id,promptId:a.prompt_id,text:c.text===""?i:c.text,createdAt:a.created_at,status:a.status,origin:a.origin,media:c.media,content:a.content,appendTiming:a.append_timing}))}}this.shell.cursor.epoch?.startsWith("cold:")===!0&&this.resync()}}catch{}finally{this.durableSteerReadInFlight=!1,this.durableSteerReads.delete(n)&&!this.closed&&this.durableSteerReads.set(n,s),this.scheduleDurableSteerRead()}}pauseDurableSteerReads(){this.durableSteerReadGeneration+=1,this.durableSteerReadTimer!==void 0&&clearTimeout(this.durableSteerReadTimer),this.durableSteerReadTimer=void 0}async refreshDurableIngress(){const e=this.client.listDurableIngress?.bind(this.client);if(e===void 0||!this.hasKnownSavedSession()||this.closed||this.isSuspended)return;if(this.durableIngressReadInFlight!==void 0)return this.durableIngressReadInFlight;let n;return n=(async()=>{try{const s=[],i=new Set;let r;for(;;){const o=await e(this.sessionId,{cursor:r});if(this.closed||this.isSuspended)return;s.push(...o.ingress??[]);const a=o.ingress_next_cursor;if(a===void 0||i.has(a))break;i.add(a),r=a}if(!this.closed&&!this.isSuspended){const o=this.getDurableIngress().filter(a=>(a.agent_id??M)!==M&&!s.some(d=>d.prompt_id===a.prompt_id&&(d.agent_id??M)===(a.agent_id??M)));this.setDurableIngress(o.length===0?s:[...o,...s])}}catch{}finally{this.durableIngressReadInFlight===n&&(this.durableIngressReadInFlight=void 0)}})(),this.durableIngressReadInFlight=n,n}async refreshDurablePrompt(e,n=M){const s=this.client.getDurableIngress?.bind(this.client);if(s===void 0||this.closed||this.isSuspended)return;const i=n===M?await s(this.sessionId,e):await s(this.sessionId,e,n);if(this.closed||this.isSuspended)return;const r=rs(i,n);this.setDurableIngress([...this.getDurableIngress().filter(o=>o.prompt_id!==e||(o.agent_id??M)!==n),r])}getDurableIngress(){return this.shell.durableIngress??[]}async resumeDurableIngress(e,n,s=M){const i=this.client.resumeDurableIngress?.bind(this.client);if(i===void 0)throw new Error("Durable prompt recovery is unavailable on this transport");const r=await i(this.sessionId,e,{...n,admission:"durable",prompt_id:e,agent_id:n.agent_id??(s===M?void 0:s)},s),o=r.admission==="failed"||r.admission==="cancelled",a=r.agent_id??n.agent_id??s;o||Er(this.sessionId,e,a);const d=rs(r,a);if(r.admission!==void 0&&this.setDurableIngress([...this.getDurableIngress().filter(u=>u.prompt_id!==e||(u.agent_id??M)!==a),d]),(r.admission===void 0||r.admission==="admitted")&&this.shell.cursor.epoch?.startsWith("cold:")===!0&&this.resync(),(r.admission==="restoring"||r.admission==="waiting_switch")&&(this.durablePromptReads.set(JSON.stringify([a,r.prompt_id]),dt(r.content).text),this.observeDurableSteer(a,r.prompt_id)),o||r.admission==="restoring"||r.admission==="waiting_switch"||r.admission==="held")return d;const c=this.viewOf(a);if(!c.blocks.some(u=>u.kind==="user"&&u.promptId===r.prompt_id)){const u=dt(r.content);this.publishView(a,Dn(c,{userMessageId:r.user_message_id,promptId:r.prompt_id,text:u.text,createdAt:r.created_at,status:r.status,origin:r.origin,media:u.media,content:r.content,appendTiming:r.append_timing}))}return r}async refreshPrompts(){await this.refreshDurableIngress()}async refreshTasks(){}async refreshGoal(){}async refreshSession(){try{const e=await this.client.getSession(this.sessionId);this.closed||this.handleSessionRecord(e)}catch{}}retainHistoryStructure(e,n){const s=this.beginContentRead(e,{kind:"turn",id:n},["steps"],!1);return()=>{s.release()}}retainHistoryPreview(e,n){const s=this.timeline(e),i=s.viewLeases;if(i.set(n,(i.get(n)??0)+1),s.pagedPin!==void 0&&!s.readerVisitedOld){const o=s.store?.getTurn(n)?.ordinal;o!==void 0&&o<s.pagedPin&&(s.readerVisitedOld=!0)}let r=!1;return()=>{if(r)return;r=!0;const o=(i.get(n)??1)-1;o>0?i.set(n,o):i.delete(n)}}cancelHistoryRead(e){this.olderLoads.cancel(e);const n=this.viewOf(e);n.loadingOlder&&this.publishView(e,Ct(n,!1))}async loadOlderMessages(e=M,n){return(await this.loadOlderHistory(e,n)).changed}olderLoadFailedByResync(e){const n=this.viewOf(e);return this.publishView(e,ss(n,this.shell.resyncError?.message??"Could not restore session")),{kind:"failed",changed:!1}}loadOlderHistory(e=M,n){if(this.closed||this.isSuspended)return Promise.resolve({kind:"cancelled",changed:!1});const s=new fn,i=()=>{const r=this.resyncGeneration;return this.olderLoads.request(e,o=>this.loadOlderTranscript(e,o),n).then(o=>o.kind!=="cancelled"&&o.kind!=="preparing"||n?.aborted||this.closed||this.isSuspended||r===this.resyncGeneration?o:this.resumeOlderLoadAfterResync(e,s,i,n)).finally(()=>{this.queueAutomaticRosterRead()})};return this.resyncInFlight?this.waitForResyncIdle(n).then(r=>r==="cancelled"?{kind:"cancelled",changed:!1}:r==="failed"?this.olderLoadFailedByResync(e):i()):i()}async resumeOlderLoadAfterResync(e,n,s,i){const r=await this.waitForResyncIdle(i);return r==="cancelled"?{kind:"cancelled",changed:!1}:r==="failed"?this.olderLoadFailedByResync(e):(await n.wait(i),i?.aborted===!0||this.closed||this.isSuspended?{kind:"cancelled",changed:!1}:s())}locateTurn(e=M,n,s){if(this.closed||this.isSuspended)return Promise.resolve({kind:"cancelled",changed:!1});const i=new fn,r=()=>{const o=this.resyncGeneration;return this.olderLoads.request(e,a=>this.loadOlderTranscript(e,a,n),s).then(a=>a.kind!=="cancelled"&&a.kind!=="preparing"||s?.aborted||this.closed||this.isSuspended||o===this.resyncGeneration?a:this.resumeOlderLoadAfterResync(e,i,r,s)).finally(()=>{this.queueAutomaticRosterRead()})};return this.resyncInFlight?this.waitForResyncIdle(s).then(o=>o==="cancelled"?{kind:"cancelled",changed:!1}:o==="failed"?this.olderLoadFailedByResync(e):r()):r()}async loadOlderTranscript(e,n,s){this.cancelFirstScreenSeed(e);const i=this.timeline(e);i.paging+=1;try{return await this.readOlderTranscript(e,n,s)}finally{i.paging-=1}}async readOlderTranscript(e,n,s){if(this.resyncInFlight){const h=await this.waitForResyncIdle(n);if(h==="cancelled")return{kind:"cancelled",changed:!1};if(h==="failed")return this.olderLoadFailedByResync(e)}if(!this.flushPendingTranscriptBatch(e))return{kind:"cancelled",changed:!1};const i=this.ensureAgentTranscript(e),r=this.generationOf(e),o=()=>this.closed||n.aborted||this.timelines.get(e)?.store!==i||this.generationOf(e)!==r;this.pendingTranscriptAgents.delete(e)&&this.publishProjectedAgent(e,i);let a=this.windowSnapshot(e);const d=h=>{if(s===void 0)return!1;const v=h.items.find(p=>p.kind==="turn"&&p.turnId===s);return v===void 0?!1:!(v.origin.kind==="other"&&v.message===void 0&&v.promptId===void 0&&v.startedAt===void 0)||!h.hasMoreOlder};if(d(a))return this.publishProjectedAgent(e,i),{kind:"advanced",changed:!0};const l=a.items.find(h=>h.kind==="turn"),c=(()=>{if(s!==void 0||l===void 0||this.turnHasGap(e,l.turnId))return;const h=(l.contentRefs??[]).filter(p=>p.direction==="backward"),v=l.steps[0]?.ordinal;return h.find(p=>p.path.length===3&&p.path[1]===v)??h.find(p=>p.path.length===1)??h.toSorted((p,k)=>Number(p.path[1])-Number(k.path[1]))[0]})();if(c!==void 0){const h=this.beginContentRead(e,c.source,[String(c.path[0])],!1),v=this.viewOf(e);this.publishView(e,Ct(v,!0));const m=()=>{this.cancelContentSegment(e,c)};n.addEventListener("abort",m,{once:!0});try{const p=!n.aborted&&await this.loadContentSegment(e,c);if(o())return{kind:"cancelled",changed:!1};const k=this.viewOf(e);if(p)return this.publishView(e,{...Ct(k,!1),olderError:void 0}),{kind:"advanced",changed:!0};const S=k.detailLoads[`content:${JSON.stringify(c)}`];return this.publishView(e,ss(k,S?.status==="error"?S.message:"Could not load earlier content")),{kind:"failed",changed:!1}}finally{if(n.removeEventListener("abort",m),h.release(),!o()){const p=this.viewOf(e);p.loadingOlder&&this.publishView(e,Ct(p,!1))}}}let u=this.timelines.get(e)?.olderCursor,f=u===void 0?this.timelines.get(e)?.olderTurn??a.items.find(h=>h.kind==="turn")?.turnId:void 0;if(!a.hasMoreOlder){if(l!==void 0&&this.turnHasGap(e,l.turnId))return this.loadOldestTurnStructure(e,l.turnId,n,o);const h=this.viewOf(e);return(h.olderError!==void 0||h.loadingOlder)&&this.publishView(e,{...Ct(h,!1),olderError:void 0}),{kind:"exhausted",changed:!1}}u===void 0&&f===void 0&&a.items.length>0&&(u=ht(a.items[0]));const g=this.viewOf(e);this.publishView(e,Ct(g,!0));try{const h=k=>{k!==void 0&&(u=k,f=void 0,this.timeline(e).olderCursor=k,this.timeline(e).olderTurn=void 0)};let v=!1;const m=new fn,p=k=>{if(!(k===void 0||k.startsWith("~")||k.includes(":")))try{const S=typeof atob=="function"?Uint8Array.from(atob(k.replaceAll("-","+").replaceAll("_","/")),b=>b.codePointAt(0)??0):void 0,w=S===void 0?void 0:new TextDecoder().decode(S),x=w===void 0?void 0:JSON.parse(w);return x?.v===2&&typeof x.orphanTurn=="string"&&/^t\d+$/.test(x.orphanTurn)?x.orphanTurn:void 0}catch{return}};for(;;){const k=()=>this.view.transcript.page({agentId:e,beforeTurn:f,beforeItem:u,pageSize:jp},{signal:n}),S=this.timelines.get(e)?.cursor;let w=await this.readPreparedContent(k,n,"high");if(o())return{kind:"cancelled",changed:!1};if(w.agent_id!==e)throw new Error("History page returned a different agent");if(w.read?.stale!==void 0){this.timeline(e).historyRead=w.read,this.publishProjectedAgent(e,i,{historyCoverageKind:"unknown"}),u=void 0;const te=a.items.find(re=>re.kind==="turn");if(f=te?.turnId,w.read.stale.retry==="resync"||f===void 0)return this.publishProjectedAgent(e,i,{loadingOlder:!1,historyCoverageKind:"unknown"}),this.resync(),{kind:"preparing",changed:!1};let ee;if(te?.origin.kind==="other"&&te.message===void 0&&te.promptId===void 0&&te.startedAt===void 0){const re=await this.readTurnContentPreview(e,te.turnId,n,!0);if(o())return{kind:"cancelled",changed:!1};if(re?.startedAt===void 0)throw new Error("Could not recover the earlier message opening");const{steps:le,contentRefs:Oe,...Ze}=re;ee={...te,...Ze,state:te.state,endedAt:te.endedAt,contentRefs:[...(te.contentRefs??[]).filter(Je=>Je.path[0]==="steps"),...(Oe??[]).filter(Je=>Je.path[0]!=="steps")]}}if(w=await this.readAuthoritativeTranscriptContinuation(k,"History continuation is still stale",n,"high"),o())return{kind:"cancelled",changed:!1};if(w.agent_id!==e)throw new Error("History page returned a different agent");ee!==void 0&&(w={...w,items:[...w.items.filter(re=>re.kind!=="turn"||re.turnId!==ee.turnId),ee]})}const x=w.items.find(te=>te.kind==="turn")?.turnId,b=w.read?.readiness,_=w.has_more&&w.items.length===0,C=_&&b==="preparing",F=_&&b==="partial";let N=!1;const me=new Set(a.items.map(te=>te.kind==="turn"?`turn:${te.turnId}`:te.kind==="marker"?`marker:${te.markerId}`:`taskref:${te.refId}`)),V=w.items.some(te=>!me.has(te.kind==="turn"?`turn:${te.turnId}`:te.kind==="marker"?`marker:${te.markerId}`:`taskref:${te.refId}`));for(const te of w.items){if(te.kind!=="turn"||te.startedAt===void 0)continue;const re=i.getTurn(te.turnId)??a.items.find(Oe=>Oe.kind==="turn"&&Oe.turnId===te.turnId);!(re?.origin.kind==="other"&&re.message===void 0&&re.promptId===void 0&&re.startedAt===void 0)&&(V||(w.next_cursor===void 0?w.has_more:w.next_cursor===u))||(N=!0)}if(w.has_more&&!C&&!F&&!V&&!N&&(w.next_cursor!==void 0?w.next_cursor===u:x===void 0||x===f))throw new Error("History page did not advance its cursor");if(w.read!==void 0&&(this.timeline(e).historyRead=w.read),this.flushPendingTranscriptBatch(e)&&this.observeToolCount(e,w),C||F){if(w.next_cursor!==void 0&&w.next_cursor!==u&&m.progressed(),h(w.next_cursor),this.publishProjectedAgent(e,i,{loadingOlder:!0,fetchedOlder:!0,olderError:void 0,historyCoverageKind:"unknown"}),await m.wait(n),o())return{kind:"cancelled",changed:!1};continue}m.progressed(),this.placeOlderPage(e,i,w,w.read?.watermark?.transcript??w.cursor??S),w.next_cursor!==void 0?this.timeline(e).olderCursor=w.next_cursor:this.timeline(e).olderCursor=void 0,x!==void 0?this.timeline(e).olderTurn=x:this.timeline(e).olderTurn=void 0,this.forestDirtyAgents.add(e),(w.items.length>0||w.next_cursor!==u)&&(v=!0),a=this.windowSnapshot(e);const we=s===void 0?p(w.next_cursor):void 0;if(w.has_more&&w.next_cursor!==void 0&&w.next_cursor!==u&&(N&&!V||s!==void 0&&!d(a)||we!==void 0&&w.items.length===1&&w.items[0]?.kind==="turn"&&w.items[0].turnId===we)){if(u=w.next_cursor,f=void 0,s===void 0&&this.publishProjectedAgent(e,i,{loadingOlder:!0,fetchedOlder:!0,olderError:void 0,historyCoverageKind:w.coverage?.kind==="unknown"?"unknown":void 0}),await new Promise(te=>{setTimeout(te,0)}),o())return{kind:"cancelled",changed:!1};continue}this.publishProjectedAgent(e,i,{loadingOlder:!1,fetchedOlder:!0,olderError:void 0,historyCoverageKind:w.coverage?.kind==="unknown"?"unknown":!w.has_more&&w.coverage!==void 0?"full":void 0});const Fe=v||w.items.length>0||w.next_cursor!==u;return w.has_more?{kind:"advanced",changed:!0}:{kind:"exhausted",changed:Fe}}}catch(h){if(o())return{kind:"cancelled",changed:!1};const v=h instanceof Ee||h instanceof mt?h.code:void 0,m=this.viewOf(e);return v===40922||v===40923||v===Ce.SESSION_BUSY||v===Ce.SESSION_INDEX_BUILDING?(this.publishView(e,{...Ct(m,!1),olderError:void 0}),{kind:"preparing",changed:!1}):(this.publishView(e,ss(m,Ot(h,"Could not load earlier messages"))),{kind:"failed",changed:!1})}}async loadOldestTurnStructure(e,n,s,i){const r={kind:"turn",id:n},o=()=>this.viewOf(e),a=o().detailLoads[`structure:${n}`],d=this.beginContentRead(e,r,["steps"]);this.publishView(e,Ct(o(),!0));try{for(;;){if(await Bi(10,s),i())return{kind:"cancelled",changed:!1};if(!this.turnHasGap(e,n))return this.publishView(e,{...Ct(o(),!1),olderError:void 0}),{kind:"advanced",changed:!0};const l=o().detailLoads[`structure:${n}`];if(l?.status==="error"&&l!==a)return this.publishView(e,ss(o(),l.message)),{kind:"failed",changed:!1}}}finally{d.release(),!i()&&o().loadingOlder&&this.publishView(e,Ct(o(),!1))}}applyTranscriptReset(e,n,s,i,r,o){this.cancelFirstScreenSeed(e),this.pendingTranscriptBatches.delete(e),this.pendingTranscriptAgents.delete(e),this.catchupReplay.delete(e);const a=this.ensureAgentTranscript(e),d=[...this.contentBodies.entries()].filter(([,w])=>w.agentId===e);this.bumpHistoryGeneration(e);for(const w of this.entityPageCursors.keys())w.startsWith(`${e}/`)&&this.entityPageCursors.delete(w);this.timeline(e).todoRead=void 0;for(const w of["task","attachment","prompt","interaction","todo"]){const x=`entities:${w}`,b=`${e}/${x}`;this.detailReads.delete(b),this.setDetailLoad(e,x,void 0)}const l=this.timeline(e),c=this.viewOf(e).historyCoverageKind,u=this.resetWindow(l,a,n,s,i,r);a.apply([{op:"reset",agentId:e,snapshot:{...n,items:u.incoming},coverage:s,grade:r==="off"?void 0:r,read:o}]);const f=a.getItems(),g=new Map(f.map(w=>[ht(w),w])),h=s.kind!=="unknown"?f.filter(w=>u.resetKeys.has(ht(w))):u.incoming.map(w=>{const x=g.get(ht(w));return x!==void 0&&(x===w||Ae(x,w))?x:w}),v=u.kept.length===0?h:Cr(h,u.kept,w=>w),m=u.kept.length>0,p=n.hasMoreOlder??s.hasMoreOlder,k=s.kind==="unknown"&&p,S=m?u.held.hasMoreOlder||k:p;v.length!==f.length||v.some((w,x)=>w!==f[x])?a.replaceItems(v,S):a.setHasMoreOlder(S),m||(l.olderCursor=n.olderCursor,l.olderTurn=n.items.find(w=>w.kind==="turn")?.turnId),this.settleWindowAfterReset(l,a,u,i,r);for(const w of this.contentReaders.values())w.agentId===e&&(w.blocked=!1);for(const[w,x]of d){const b=this.contentEntity(e,x.source);b===void 0?this.contentBodies.delete(w):this.contentBodies.set(w,{...x,base:Rp(n,x.source)??x.base,bytes:this.bytesOf(b)})}this.timeline(e).cursor=i,o!==void 0?this.timeline(e).historyRead=o:this.timeline(e).historyRead=void 0,this.timeline(e).appliedGrade=r,this.timeline(e).baselineSerial=++this.transcriptBaselineClock,this.hasTranscriptBaseline(e)&&this.viewHandle?.updateTranscriptCursor(e,i),this.forestDirtyAgents.add(e),this.timeline(e).globalCoverage=n.globalCoverage,this.publishProjectedAgent(e,a,{loadingOlder:!1,olderError:void 0,retainPendingPrompts:!0,transcriptReset:s.kind==="full",historyCoverageKind:s.kind==="full"||m&&!S&&c==="full"&&s.kind!=="unknown"?"full":s.kind==="unknown"||c==="unknown"?"unknown":"tail"});for(const w of n.prompts)w.detailRef===void 0||w.content!==void 0||w.status!=="queued"&&w.status!=="running"||this.loadTranscriptDetail(e,"prompt",w.promptId)}async loadTranscriptDetail(e,n,s,i){const r=this.view.transcript.detail?.bind(this.view.transcript),o=wf(n,s);if(this.closed||r===void 0)return!1;const a=this.detailReads.get(`${e}/${o}`);if(a!==void 0)return a;const d=this.generationOf(e),l=new AbortController;this.snapshotControllers.add(l);const c=(async()=>{this.setDetailLoad(e,o,{status:"loading"});try{const u=await this.readPreparedContent(()=>r({agentId:e,kind:n,id:s,turnId:i},{signal:l.signal}),l.signal);if(this.closed||this.generationOf(e)!==d)return!1;const f=this.applyTranscriptDetail(e,u);return this.setDetailLoad(e,o,void 0),f}catch(u){return this.closed||this.setDetailLoad(e,o,{status:"error",message:Ot(u,"Could not load the full content")}),!1}})().finally(()=>{this.snapshotControllers.delete(l),this.detailReads.delete(`${e}/${o}`)});return this.detailReads.set(`${e}/${o}`,c),c}async copyToolCallField(e,n,s,i,r){const o=await this.lookupToolCallForCopy(e,n,i,r),a={kind:"frame",id:o.frame.frameId,turnId:o.turnId,stepId:o.stepId},d=s==="input"&&o.frame.input===void 0?"inputText":s==="output"&&o.frame.output===void 0?"error":s;return this.copyResolvedContentField(e,a,[d],i)}async lookupToolCallForCopy(e,n,s,i){for(;;){s?.throwIfAborted();const r=await this.lookupToolCall(e,n,s,i);if(r.status==="preparing"){await this.waitForToolDetailPreparation(s);continue}if(r.status!=="found")throw new Error("Invocation is not ready");return r}}waitForToolDetailPreparation(e){return e?.throwIfAborted(),new Promise((n,s)=>{let i;const r=()=>{i!==void 0&&clearTimeout(i),s(new DOMException("Read cancelled","AbortError"))};i=setTimeout(()=>{e?.removeEventListener("abort",r),n()},Ni),e?.addEventListener("abort",r,{once:!0}),e?.aborted&&r()})}getToolCallDetail(e,n){return this.toolDetails.get(`${e}/${n}`)}async lookupToolCall(e,n,s,i){s?.throwIfAborted();const r=`${e}/${n}`,o=this.timelines.get(e)?.store?.getToolCall(n);if(o!==void 0){const u={status:"found",...o};return this.toolDetails.set(r,u),u}this.toolDetails.get(r)?.status==="found"&&this.invalidateToolDetail(r);let a=this.toolDetailReads.get(r);if(a===void 0){const u=this.generationOf(e),f=this.toolDetailEpochs.get(r)??0,g=this.view.transcript.detail?.bind(this.view.transcript);if(this.closed||g===void 0)throw new Error("Tool details are unavailable on this connection");const h=new AbortController;this.snapshotControllers.add(h);const v=(async()=>{const m=await this.readPreparedContent(()=>g.call(this.view.transcript,{agentId:e,kind:"tool",id:n,turnId:i},{signal:h.signal}),h.signal);if(h.signal.throwIfAborted(),this.closed||this.generationOf(e)!==u)throw new Error("Tool detail scope changed");if(m.kind!=="tool"||m.agent_id!==e||m.session_id!==this.sessionId)throw new Error("Tool detail target mismatch");const p=this.timelines.get(e)?.store?.getToolCall(n);if(p!==void 0){const k={status:"found",...p};return this.toolDetails.set(r,k),k}if((this.toolDetailEpochs.get(r)??0)!==f)throw new Error("Tool detail scope changed");return this.toolDetails.set(r,m.lookup),m.lookup})().finally(()=>{this.snapshotControllers.delete(h),this.toolDetailReads.get(r)?.controller===h&&this.toolDetailReads.delete(r)});v.catch(()=>{}),a={promise:v,controller:h,readers:0},this.toolDetailReads.set(r,a)}const d=a;d.readers+=1;let l;const c=new Promise((u,f)=>{l=()=>f(new DOMException("Read cancelled","AbortError"))});s?.addEventListener("abort",l,{once:!0});try{return await(s===void 0?d.promise:Promise.race([d.promise,c]))}finally{s?.removeEventListener("abort",l),d.readers-=1,d.readers===0&&this.toolDetailReads.get(r)===d&&(this.toolDetailReads.delete(r),d.controller.abort())}}isContentRange(e,n){return n.kind==="text"&&(n.total>Np||(this.contentBodies.get(JSON.stringify([e,n.source]))?.bytes??0)>=os/2||this.contentMemoryReport().bodyBytes>=os)}contentRefsFor(e,n){return this.contentEntity(e,n)?.contentRefs??[]}turnStructurePending(e,n){return this.turnHasGap(e,n)}contentEntity(e,n){if(n.kind==="snapshot")return this.latestSnapshot;if(n.kind==="frame"){for(const[i,r]of this.toolDetails)if(i.startsWith(`${e}/`)&&r.status==="found"&&r.frame.frameId===n.id&&r.turnId===n.turnId&&r.stepId===n.stepId)return r.frame}const s=this.timelines.get(e)?.store;return s===void 0?void 0:cs(s,n)}stepCanonicalIndex(e,n,s){const r=this.windowSnapshot(e).items.find(o=>o.kind==="turn"&&o.turnId===n)?.steps.findIndex(o=>o.stepId===s)??-1;if(!(r<0))return r}residentRangeText(e,n){if(n.kind!=="text"||n.direction==="backward")return;const s=this.contentEntity(e,n.source);if(s===void 0||s.contentRefs?.some(o=>o.revision===n.revision&&o.kind==="text"&&o.path.length===n.path.length&&o.path.every((a,d)=>a===n.path[d]))!==!0)return;const r=mn(s,n.path);return typeof r=="string"&&r.length>0?r:void 0}peekContentRange(e,n,s){const i=JSON.stringify([e,n.source,n.path,n.revision,s]),r=this.contentRanges.get(i);if(r!==void 0)return r;if(s<0)return;const o=this.residentRangeText(e,n);if(o===void 0||s>=o.length)return;const a=Math.min(n.total,s+ni);if(o.length<a)return;let d=s,l=a;return d>0&&/[\uD800-\uDBFF]/u.test(o[d-1])&&(d+=1),l<o.length&&/[\uD800-\uDBFF]/u.test(o[l-1])&&(l+=1),o.slice(d,l)}peekContentPrefix(e,n){const s=this.residentRangeText(e,n);if(s===void 0)return;let i=Math.min(s.length,ni);return i<s.length&&/[\uD800-\uDBFF]/u.test(s[i-1])&&(i+=1),s.slice(0,i)}async readContentRange(e,n,s,i){i?.throwIfAborted();const r=JSON.stringify([e,n.source,n.path,n.revision,s]),o=this.contentRanges.get(r);if(o!==void 0)return this.contentRanges.delete(r),this.contentRanges.set(r,o),o;const a=this.peekContentRange(e,n,s);if(a!==void 0)return a;const d=this.view.transcript.content?.bind(this.view.transcript);if(this.closed||d===void 0)throw new Error("Content reader unavailable");const l=this.generationOf(e),c=new AbortController,u=()=>{c.abort()};i?.addEventListener("abort",u,{once:!0}),this.snapshotControllers.add(c),this.rangeControllers.set(c,e);try{const f=await this.readPreparedContent(()=>d.call(this.view.transcript,{agentId:e,ref:{...n,offset:s},range:!0},{signal:c.signal}),c.signal);if(c.signal.throwIfAborted(),this.closed||this.generationOf(e)!==l||f.ref.revision!==n.revision||typeof f.value!="string")throw new Error("Content range changed");let g=s-f.ref.offset,h=Math.min(f.value.length,s+ni-f.ref.offset);g>0&&/[\uD800-\uDBFF]/u.test(f.value[g-1])&&(g+=1),h<f.value.length&&/[\uD800-\uDBFF]/u.test(f.value[h-1])&&(h+=1);const v=f.value.slice(g,h),m=this.contentRanges.get(r);for(m!==void 0&&(this.contentRangeBytes-=m.length*2),this.contentRanges.set(r,v),this.contentRangeBytes+=v.length*2;this.contentRangeBytes>Ro;){const p=this.contentRanges.entries().next().value;if(p===void 0)break;this.contentRanges.delete(p[0]),this.contentRangeBytes-=p[1].length*2}return v}finally{i?.removeEventListener("abort",u),this.snapshotControllers.delete(c),this.rangeControllers.delete(c)}}async copyContentField(e,n,s,i){if(i?.throwIfAborted(),n.kind==="frame")for(const[r,o]of this.toolDetails){if(!r.startsWith(`${e}/`)||o.status!=="found"||o.frame.frameId!==n.id||o.turnId!==n.turnId||o.stepId!==n.stepId)continue;const a=await this.lookupToolCallForCopy(e,o.frame.toolCallId,i,n.turnId);if(a.frame.frameId!==n.id||a.turnId!==n.turnId||a.stepId!==n.stepId)throw new Error("Copy target changed");break}return this.copyResolvedContentField(e,n,s,i)}async copyResolvedContentField(e,n,s,i){const r=g=>{for(const h of s){if(g===null||typeof g!="object")return;g=g[h]}return g};i?.throwIfAborted();const o=this.contentEntity(e,n);if(o===void 0)throw new Error("Copy target unavailable");let a=o;const d=this.view.transcript.content?.bind(this.view.transcript),l=new AbortController,c=()=>{l.abort()};i?.addEventListener("abort",c,{once:!0}),this.snapshotControllers.add(l),this.rangeControllers.set(l,e);const u=this.generationOf(e),f=()=>{if(l.signal.throwIfAborted(),this.closed||this.generationOf(e)!==u)throw new Error("Copy scope changed")};try{for(;;){f();const h=a.contentRefs?.find(v=>s.every((m,p)=>v.path[p]===m)||v.path.every((m,p)=>s[p]===m));if(h===void 0)break;if(d===void 0)throw new Error("Content reader unavailable");if(h.kind==="text"){const v=[];let m=h.offset;for(;m<h.total;){const p=await this.readPreparedContent(()=>d({agentId:e,ref:{...h,offset:m}},{signal:l.signal}),l.signal);if(f(),p.ref.revision!==h.revision||p.ref.offset!==m||typeof p.value!="string"||p.value.length===0)throw new Error("Copy content changed");v.push(p.value),m+=p.value.length,await new Promise(k=>setTimeout(k,0))}if(m!==h.total)throw new Error("Copy content length mismatch");a=hn(a,{ref:h,value:v.join(""),contentRefs:[]})}else{const v=await this.readPreparedContent(()=>d({agentId:e,ref:h},{signal:l.signal}),l.signal);f();const m=hn(a,v);if(m===a||v.next!==void 0&&v.next.offset<=h.offset)throw new Error("Copy content made no progress");a=m,await new Promise(p=>setTimeout(p,0))}}f();const g=r(a);return typeof g=="string"?g:JSON.stringify(g,null,2)??""}finally{i?.removeEventListener("abort",c),this.snapshotControllers.delete(l),this.rangeControllers.delete(l)}}contentMemoryReport(){return{bodies:this.contentBodies.size,bodyBytes:[...this.contentBodies.values()].reduce((e,n)=>e+n.bytes,0),rangeBytes:this.contentRangeBytes,bodyBudget:os,rangeBudget:Ro}}incompleteTurnOrdinals(e){const n=new Set;for(const s of this.windowSnapshot(e).items)s.kind==="turn"&&(this.turnHasGap(e,s.turnId)||s.contentRefs?.length||s.steps.some(i=>i.frames.some(r=>r.contentRefs?.length)))&&n.add(s.ordinal);return n}async completeTurnContent(e,n,s,i=!1){let r=this.windowSnapshot(e).items.find(o=>o.kind==="turn"&&o.ordinal===n);if(r?.kind!=="turn")throw new Error("Search target is not loaded");if(await this.completeContentRead(e,{kind:"turn",id:r.turnId},["steps","prompt"],s),r=this.windowSnapshot(e).items.find(o=>o.kind==="turn"&&o.ordinal===n),r?.kind==="turn")for(const o of r.steps)for(const a of o.frames){if(a.kind!=="text"&&!(a.kind==="tool"&&i))continue;const d=a.kind==="tool"?"output":"text";(a.contentRefs??[]).some(l=>l.path[0]===d)&&await this.completeContentRead(e,{kind:"frame",id:a.frameId,turnId:r.turnId,stepId:o.stepId},[d],s)}}async findTurnContentRange(e,n,s,i,r=!1){await this.completeTurnContent(e,n,i,r);const o=this.windowSnapshot(e).items.find(d=>d.kind==="turn"&&d.ordinal===n);if(o?.kind!=="turn")throw new Error("Search target changed");const a=[...(o.contentRefs??[]).map(d=>({ref:d,toolCallId:void 0})),...o.steps.flatMap(d=>d.frames.flatMap(l=>l.kind==="thinking"||l.kind==="notice"?[]:l.kind==="tool"&&!r?[]:l.kind==="text"&&l.role!=="assistant"&&l.role!=="user"?[]:(l.contentRefs??[]).map(c=>({ref:c,toolCallId:l.kind==="tool"?l.toolCallId:void 0}))))];for(const{ref:d,toolCallId:l}of a){if(d.kind!=="text")continue;const c=String(d.path[0]);if(l===void 0?c!=="prompt"&&c!=="text":c!=="output")continue;let u="";for(let f=0;f<d.total;){i?.throwIfAborted();const g=await this.readContentRange(e,d,f,i);if(g.length===0)throw new Error("Search content made no progress");const h=u+g,v=new RegExp(s.source,s.flags);for(const m of h.matchAll(v))if(!(f>0&&m.index===0||f+g.length<d.total&&m.index+m[0].length===h.length))return{ref:d,offset:f-u.length+m.index,toolCallId:l};u=h.slice(-512),f+=g.length,await new Promise(m=>setTimeout(m,0))}}}async completeContentRead(e,n,s,i){const r=this.beginContentRead(e,n,s);try{for(;;){if(i?.throwIfAborted(),this.closed)throw new Error("Content reader unavailable");if(n.kind==="turn"&&s.includes("steps")&&this.turnHasGap(e,n.id)){await new Promise(l=>{setTimeout(l,10)});const d=this.viewOf(e).detailLoads[`structure:${n.id}`];if(d?.status==="error")throw new Error(d.message);continue}const o=this.contentRefsFor(e,n).find(a=>s.includes(String(a.path[0]))&&!this.isContentRange(e,a));if(o===void 0)return;if(!await this.loadContentSegment(e,o))throw new Error("Could not read the complete content");await new Promise(a=>setTimeout(a,0))}}finally{r.release()}}observeContentPreview(e,n){const i=(()=>{switch(n.op){case"frame.upsert":return[{kind:"frame",id:n.frame.frameId,turnId:n.turnId,stepId:n.stepId},n.frame];case"turn.upsert":return[{kind:"turn",id:n.turn.turnId},n.turn];case"task.upsert":return[{kind:"task",id:n.task.taskId},n.task];case"attachment.upsert":return[{kind:"attachment",id:n.attachment.attachmentId},n.attachment];case"prompt.upsert":return[{kind:"prompt",id:n.prompt.promptId},n.prompt];case"interaction.upsert":return[{kind:"interaction",id:n.interaction.interactionId},n.interaction];case"todo.upsert":return[{kind:"todo",id:n.todo.todoId},n.todo];case"marker.upsert":return[{kind:"marker",id:n.item.markerId},n.item];case"meta.merge":return[{kind:"meta",id:""},n.meta];default:return}})();if(i===void 0)return;const[r,o]=i,a=JSON.stringify([e,r]),d=this.contentBodies.get(a);if(d===void 0)return;const l=JSON.stringify(d.base.contentRefs??[])!==JSON.stringify(o.contentRefs??[]);this.contentBodies.set(a,{...d,base:r.kind==="turn"||r.kind==="meta"?{...d.base,...o}:o,bytes:l?this.bytesOf(this.contentEntity(e,r)):d.bytes})}accountContentBody(e,n,s){if(n.kind==="snapshot")return;const i=JSON.stringify([e,n]),r=this.contentBodies.get(i),o=this.contentEntity(e,n);if(o===void 0)return;this.contentBodies.delete(i),this.contentBodies.set(i,{agentId:e,source:n,base:r?.base??s??o,bytes:this.bytesOf(o)});let a=[...this.contentBodies.values()].reduce((d,l)=>d+l.bytes,0);for(const[d,l]of this.contentBodies){if(a<=os)break;if([...this.contentReaders.values()].some(h=>h.agentId===l.agentId&&JSON.stringify(h.source)===JSON.stringify(l.source)))continue;const c=this.contentEntity(l.agentId,l.source),u=l.source.kind==="turn"&&l.base.stepsPartial===!0;if(u&&c?.state==="running")continue;let f=c===void 0?void 0:sl(c,l.base);if(f!==void 0&&u){const h=mi(f,l.base,["steps"]);f=ot(h,{...h,stepsPartial:!0})}const g=this.timelines.get(l.agentId)?.store;f!==void 0&&g!==void 0&&cs(g,l.source)!==void 0&&Fi(g,l.source,f);for(const[h,v]of this.toolDetails)h.startsWith(`${l.agentId}/`)&&v.status==="found"&&v.frame.frameId===l.source.id&&this.toolDetails.delete(h);this.contentBodies.delete(d),a-=l.bytes,this.pendingTranscriptAgents.add(l.agentId)}this.flushFrames()}beginContentRead(e,n,s,i=!0,r){const o=JSON.stringify([e,n,s,i,r]),a=this.contentReaders.get(o)??{agentId:e,source:n,roots:s,paths:r,includeOlder:i,readers:0,blocked:!1,retryVersion:0,ref:void 0,controller:void 0};a.readers+=1,a.retryVersion+=1,a.retryAttempt=0,a.retryTimer!==void 0&&(clearTimeout(a.retryTimer),a.retryTimer=void 0),a.blocked=!1,this.contentReaders.set(o,a),this.pumpContentReads();let d=!1;return{release:()=>{d||(d=!0,a.readers-=1,!(a.readers>0)&&(this.retireContentRead(o),this.contentReaders.delete(o),this.accountContentBody(e,n),a.ref!==void 0&&![...this.contentReaders.values()].some(l=>l.agentId===e&&JSON.stringify(l.source)===JSON.stringify(n)&&l.roots.includes(String(a.ref.path[0])))&&this.cancelContentSegment(e,a.ref)))},retry:()=>{d||(a.retryVersion+=1,a.retryAttempt=0,a.retryTimer!==void 0&&(clearTimeout(a.retryTimer),a.retryTimer=void 0),a.blocked=!1,this.pumpContentReads())}}}retryTurnStructureRead(e,n){for(const s of this.contentReaders.values())s.agentId===e&&s.source.kind==="turn"&&s.source.id===n&&s.roots.includes("steps")&&(s.retryVersion+=1,s.retryAttempt=0,s.retryTimer!==void 0&&(clearTimeout(s.retryTimer),s.retryTimer=void 0),s.blocked=!1);this.pumpContentReads()}retireContentRead(e){const n=this.contentReaders.get(e);n!==void 0&&(n.retryTimer!==void 0&&(clearTimeout(n.retryTimer),n.retryTimer=void 0),n.retryAttempt=0,n.controller!==void 0&&(n.controller.abort(),this.snapshotControllers.delete(n.controller),n.controller=void 0,this.closed||this.setDetailLoad(n.agentId,`structure:${n.source.id}`,void 0)),this.contentPumpReads.delete(e),n.blocked=!1)}async pumpContentReads(){if(!(this.contentPumpRunning||this.closed||this.isSuspended||this.isParked)){this.contentPumpRunning=!0;try{if(await new Promise(e=>setTimeout(e,0)),this.closed||this.isSuspended||this.isParked)return;for(const[e,n]of this.contentReaders){if(this.contentPumpReads.size>=4)break;if(n.readers===0||n.blocked||n.retryTimer!==void 0||this.contentPumpReads.has(e))continue;const s=this.contentEntity(n.agentId,n.source),i=this.timelines.get(n.agentId),r=n.source.kind==="turn"&&n.includeOlder&&n.roots.includes("steps")&&(s?.stepsPartial===!0||s!==void 0&&i?.stale.has(n.source.id)===!0&&!i.refreshing);if(n.source.kind==="turn"&&n.includeOlder&&n.roots.includes("steps")&&!r&&s!==void 0&&i?.stale.has(n.source.id)===!0)continue;const o=r?void 0:s?.contentRefs?.find(u=>!n.roots.includes(String(u.path[0]))||this.isContentRange(n.agentId,u)||n.paths!==void 0&&!n.paths.some(f=>f.length===1&&n.source.kind==="turn"&&f[0]==="steps"?u.path.length===1&&u.path[0]==="steps":f.every((g,h)=>u.path[h]===g))||!n.includeOlder&&u.direction==="backward"?!1:u.path[0]!=="steps"||u.path.length===1||u.path.length===3&&u.path[2]==="frames");if(!r&&o===void 0)continue;const a=r?new AbortController:void 0;n.controller=a,n.ref=o;const d={},l=n.retryVersion;this.contentPumpReads.set(e,d),(a===void 0?this.loadContentSegment(n.agentId,o).then(u=>u?"applied":"blocked"):this.loadPartialTurnStructure(n.agentId,n.source.id,a)).then(u=>{if(this.contentPumpReads.get(e)!==d)return;const f=u==="applied";if(n.ref=f?void 0:o,f){n.retryAttempt=0;return}if(n.readers>0&&n.retryVersion===l){if(u==="retry"){const g=n.retryAttempt??0;n.retryAttempt=g+1;const h=Math.min(2e3,Ni*2**Math.min(g,5));n.retryTimer=setTimeout(()=>{n.retryTimer=void 0,!this.closed&&!this.isSuspended&&!this.isParked&&n.readers>0&&n.retryVersion===l&&this.pumpContentReads()},h);return}if(n.blocked=r||this.contentRefsFor(n.agentId,n.source).some(g=>Pt(g,o)),n.blocked&&o!==void 0){const g=`content:${JSON.stringify(o)}`;this.viewOf(n.agentId).detailLoads[g]?.status!=="error"&&this.setDetailLoad(n.agentId,g,{status:"error",message:"Content did not advance. Retry to continue."})}}}).finally(()=>{this.contentPumpReads.get(e)===d&&(n.controller=void 0,this.contentPumpReads.delete(e),this.contentReaders.get(e)===n&&(this.contentReaders.delete(e),this.contentReaders.set(e,n)),this.pumpContentReads())})}}finally{this.contentPumpRunning=!1}}}async readAuthoritativeTranscriptContinuation(e,n,s,i="normal"){const r=await this.readPreparedContent(e,s,i);if(r.read?.stale!==void 0)throw new Error(n);return r}async readPreparedContent(e,n,s="normal"){let i=0;const r=new fn;for(;;){n?.throwIfAborted();try{return await cp(this.client,e,n,s)}catch(o){n?.throwIfAborted();const a=o instanceof mt||o instanceof Ee?o.code:void 0,d=a===40923,l=a===-1||a===Ce.SESSION_BUSY||a===Ce.SESSION_INDEX_BUILDING||o instanceof TypeError;if(!d&&(!l||i>=as.length))throw o;d?await r.wait(n):await Bi(as[i++],n)}}}async loadPartialTurnStructure(e,n,s){const i={kind:"turn",id:n},r=this.generationOf(e),o=`structure:${n}`;this.snapshotControllers.add(s),this.setDetailLoad(e,o,{status:"loading"});try{let a=await this.readTurnContentPreview(e,n,s.signal);if(this.closed||s.signal.aborted||this.generationOf(e)!==r)return"blocked";if(a?.stepsPartial===!0)return"retry";if(a===void 0){if(this.resyncInFlight)return"retry";throw new Error("Could not load turn step structure. Retry to continue.")}const d=this.view.transcript.content?.bind(this.view.transcript);for(;;){s.signal.throwIfAborted();const m=a.contentRefs?.find(k=>this.isTurnStructureRef(k));if(m===void 0)break;if(d===void 0)throw new Error("Step structure content is unavailable. Retry to continue.");const p=await this.readPreparedContent(()=>d({agentId:e,ref:m},{signal:s.signal}),s.signal);s.signal.throwIfAborted(),a=hn(a,p)}if(this.closed||s.signal.aborted||this.generationOf(e)!==r)return"blocked";const l=this.contentEntity(e,i);if(l===void 0)return this.setDetailLoad(e,o,void 0),"blocked";const c=pa(a),u=this.timeline(e),f=u.stale.has(n)?(()=>{const{steps:m,contentRefs:p,stepsPartial:k,...S}=c;return ot(l,{...l,...S,contentRefs:[...(l.contentRefs??[]).filter(w=>w.path[0]==="steps"),...(p??[]).filter(w=>w.path[0]!=="steps")]})})():l,g=ip(f,c),h=u.stale.delete(n),v=u.joins.get(n);return u.joins.delete(n),this.replaceTimelineContentEntity(e,i,g)?(this.accountContentBody(e,i,l),this.setDetailLoad(e,o,void 0),"applied"):(h&&u.stale.add(n),v!==void 0&&u.joins.set(n,v),this.setDetailLoad(e,o,void 0),"blocked")}catch(a){if(this.closed||s.signal.aborted||this.generationOf(e)!==r)return"blocked";const d=a instanceof mt||a instanceof Ee?a.code:void 0;return d===40922||d===40923||d===Ce.SESSION_BUSY||d===Ce.SESSION_INDEX_BUILDING?"retry":(this.setDetailLoad(e,o,{status:"error",message:a instanceof Error?a.message:String(a)}),"blocked")}finally{this.snapshotControllers.delete(s)}}turnStructureRefreshKey(e,n){return`${e}/${n.source.kind}/${n.source.id}/${JSON.stringify(n.path)}`}isTurnStructureRef(e){return e.source.kind==="turn"&&e.kind==="array"&&e.path[0]==="steps"&&(e.path.length===1||e.path.length===3&&e.path[2]==="frames")}async refreshTurnStructurePreview(e,n,s){if(n.source.kind!=="turn"||s.aborted||this.closed)return;const i=await this.readTurnContentPreview(e,n.source.id,s);if(i===void 0)return;const r=i.contentRefs?.find(a=>a.kind==="array"&&a.path.length===n.path.length&&a.path.every((d,l)=>d===n.path[l])&&a.source.kind===n.source.kind&&a.source.id===n.source.id);if(r===void 0){const a=n.path.length===3&&mn(i,n.path)===void 0,d=a?["steps"]:n.path;return s.aborted||!this.adoptTimelinePreviewField(e,n,i,d)?void 0:a?this.contentEntity(e,n.source)?.contentRefs?.find(l=>l.kind==="array"&&l.path.length===1&&l.path[0]==="steps")??"complete":"complete"}if(r.revision===n.revision&&r.offset===n.offset&&r.total===n.total)return;const o=n.direction==="backward"?r:{...r,direction:"forward",offset:0};if(!(!this.installTurnStructureRef(e,n,o)||s.aborted))return this.contentEntity(e,n.source)?.contentRefs?.find(a=>Pt(a,o))}async readTurnContentPreview(e,n,s,i=!1){const r=()=>{const g=this.windowSnapshot(e).items,h=g.findIndex(p=>p.kind==="turn"&&p.turnId===n);if(h<0)return;const v=g[h+1],m=v!==void 0&&v.kind!=="turn"?ht(v):void 0;return{turn:g[h],nextTurn:g.slice(h+1).find(p=>p.kind==="turn"),immediateBeforeItem:m!==void 0&&m.length<=512?m:void 0}};let o=r();if(o===void 0)return;let a,d=o.immediateBeforeItem,l=0;const c=new Set,u=new fn;let f;for(;;){const g=a??d;let h;try{h=await this.readPreparedContent(()=>this.view.transcript.page({agentId:e,beforeTurn:g===void 0?o?.nextTurn?.turnId:void 0,beforeItem:g,pageSize:1},{signal:s}),s)}catch(p){const k=p instanceof mt||p instanceof Ee?p.code:void 0;if(a===void 0&&d!==void 0&&k===40001){d=void 0;continue}throw p}if(this.closed||s.aborted||h.agent_id!==e)return;if(h.read?.stale!==void 0){if(this.timeline(e).historyRead=h.read,this.publishProjectedAgent(e,this.ensureAgentTranscript(e),{historyCoverageKind:"unknown"}),h.read.stale.retry==="resync"){this.resync();return}if(l>=3||(l+=1,a=void 0,c.clear(),o=r(),o===void 0))return;d=o.immediateBeforeItem;continue}const v=h.items.find(p=>p.kind==="turn"&&p.turnId===n);if(v!==void 0&&(i?v.startedAt!==void 0:v.stepsPartial!==!0))return v;const m=h.items.length===0&&h.has_more&&(h.read?.readiness==="preparing"||h.read?.readiness==="partial");if(m||v!==void 0&&!i){if(m&&a===void 0&&d!==void 0&&o?.nextTurn!==void 0){d=void 0;continue}const p=m?h.next_cursor??a:a,k={continuation:m?p:h.next_cursor,turn:v};(f===void 0||!Ae(f,k))&&u.progressed(),f=k,a=p,await u.wait(s),s.throwIfAborted();continue}if(h.items.some(p=>p.kind==="turn"&&p.ordinal<o.turn.ordinal)||!h.has_more||h.next_cursor===void 0||c.has(h.next_cursor))return;c.add(h.next_cursor),a=h.next_cursor}}async refreshTimelineFieldPreview(e,n,s){const i=n.source;if(i.kind!=="turn"&&i.kind!=="frame"||s.aborted||this.closed)return;const r=i.kind==="turn"?i.id:i.turnId;if(r===void 0)return;const o=await this.readTurnContentPreview(e,r,s),a=o===void 0?void 0:i.kind==="turn"?o:o.steps.find(c=>c.stepId===i.stepId)?.frames.find(c=>c.frameId===i.id),d=c=>c.path.length===n.path.length&&c.path.every((u,f)=>u===n.path[f]),l=a?.contentRefs?.find(c=>d(c)&&c.kind===n.kind);if(!(a===void 0||l?.revision===n.revision||l===void 0&&mn(a,n.path)===void 0)&&!(s.aborted||!this.adoptTimelinePreviewField(e,n,a)))return l===void 0?"complete":this.contentEntity(e,i)?.contentRefs?.find(c=>Pt(c,l))}adoptTimelinePreviewField(e,n,s,i=n.path){const r=n.source,o=this.contentEntity(e,r);if(o===void 0||!(o.contentRefs??[]).some(d=>Pt(d,n)))return!1;let a;try{a=mi(o,s,i)}catch{return!1}return this.replaceTimelineContentEntity(e,r,a)}replaceTimelineContentEntity(e,n,s){const i=this.timelines.get(e)?.store;return i!==void 0&&cs(i,n)!==void 0&&Fi(i,n,s)?(this.forestDirtyAgents.add(e),this.pendingTranscriptAgents.add(e),this.flushFrames(),!0):!1}installTurnStructureRef(e,n,s){if(n.source.kind!=="turn")return!1;const i=n.source.id,r=u=>(u.contentRefs??[]).flatMap(f=>{const g=n.path.every((h,v)=>f.path[v]===h);return Pt(f,n)?[s]:n.direction!=="backward"&&g?[]:[f]}),o=this.ensureAgentTranscript(e),a=o.getTurn(i);if(a===void 0)return!1;const{steps:d,...l}=a,c=ot(a,{...l,contentRefs:r(a)});return o.apply([{op:"turn.upsert",turn:c}]).accepted.length>0}loadContentSegment(e,n){return this.loadContentSegmentInternal(e,n,!1)}async loadContentSegmentInternal(e,n,s){const i=this.view.transcript.content?.bind(this.view.transcript);if(this.closed||i===void 0)return!1;const r=`content:${JSON.stringify(n)}`,o=`${e}/${r}`,a=this.detailReads.get(o);if(a!==void 0)return a;const d=new AbortController;this.snapshotControllers.add(d);const l=n.source.kind==="snapshot"&&n.path[0]==="subagents",c=l&&n.kind==="array"&&n.path.length===1,u=c?this.latestSnapshot:void 0;c&&!this.rosterReadInFlight&&(this.rosterRevisionRefreshes=0),s&&c&&(this.rosterReadController=d),l||this.contentControllers.set(o,d);const f=this.generationOf(e),g=(async()=>{s||this.setDetailLoad(e,r,{status:"loading"});try{const h=this.contentEntity(e,n.source);if(!(h?.contentRefs??[]).some(p=>Pt(p,n)))return!1;const m=await this.readPreparedContent(()=>i({agentId:e,ref:n},{signal:d.signal}),d.signal);if(this.closed||d.signal.aborted||!l&&this.generationOf(e)!==f)return!1;if(m.next!==void 0&&(n.direction==="backward"?m.next.offset>=n.offset:m.next.offset<=n.offset)||m.contentRefs.some(p=>Pt(p,n)))throw new Error("Content segment did not advance its reference");if(n.source.kind==="snapshot"){const p=this.latestSnapshot;if(p===void 0)return!1;const k=hn(p,m);if(k===p)return!1;if(this.latestSnapshot=k,s&&c)!(k.contentRefs?.some(w=>w.source.kind==="snapshot"&&w.kind==="array"&&w.path.length===1&&w.path[0]==="subagents")===!0)||this.lastRosterFlushAt>0&&Date.now()-this.lastRosterFlushAt>=Kp?this.flushSnapshotRoster(k):this.pendingRosterPublish=!0;else{this.pendingRosterPublish=!1;const S=Nn(this.viewOf(M).contentRefs,[...Fn(this.windowSnapshot(M)),...k.contentRefs??[]]);this.setSessionView(l?{...this.sessionView(),snapshotSubagents:this.mergeRosterRows(k),contentRefs:S}:{...this.applyTranscriptShellSnapshot(k),contentRefs:S}),this.publishForest()}}else{const p=this.ensureAgentTranscript(e);let k=!1;if(n.source.kind==="frame")for(const[S,w]of this.toolDetails){if(!S.startsWith(`${e}/`)||w.status!=="found"||w.frame.frameId!==n.source.id||w.turnId!==n.source.turnId||w.stepId!==n.source.stepId)continue;const x=hn(w.frame,m);x!==w.frame&&(this.toolDetails.set(S,{...w,frame:x}),k=!0)}if(k=Ap(p,m)||k,!k)return!1;this.forestDirtyAgents.add(e),this.pendingTranscriptAgents.add(e),this.flushFrames(),(n.source.kind!=="turn"||n.path[0]!=="steps")&&this.accountContentBody(e,n.source,h)}return!0}catch(h){if(!this.closed&&!d.signal.aborted&&!l&&!this.contentRefsFor(e,n.source).some(p=>Pt(p,n)))return!0;if(c&&h instanceof mt&&h.code===40922&&!this.closed&&!d.signal.aborted&&this.latestSnapshot===u&&this.rosterRevisionRefreshes<Up&&(this.flushPendingRosterPublish(),this.rosterRevisionRefreshes+=1,await this.refreshRoster(this.shell.cursor),!this.closed&&!d.signal.aborted&&this.latestSnapshot!==u))return this.setDetailLoad(e,r,void 0),!0;const v=this.turnStructureRefreshKey(e,n),m=this.isTurnStructureRef(n);if((m||n.source.kind==="turn"||n.source.kind==="frame")&&h instanceof mt&&h.code===40922&&!this.closed&&!d.signal.aborted&&!this.turnStructureRefreshKeys.has(v)){this.turnStructureRefreshKeys.add(v);try{const p=m?await this.refreshTurnStructurePreview(e,n,d.signal):await this.refreshTimelineFieldPreview(e,n,d.signal);if(p==="complete"&&!this.closed&&!d.signal.aborted)return this.setDetailLoad(e,r,void 0),!0;if(p!==void 0&&p!=="complete"&&!this.closed&&!d.signal.aborted){const k=this.loadContentSegment(e,p),S=()=>{this.cancelContentSegment(e,p)};d.signal.addEventListener("abort",S,{once:!0});try{const w=await k;if(this.closed||d.signal.aborted)return!1;if(w)return!0;const b=this.viewOf(e).detailLoads[`content:${JSON.stringify(p)}`];return!this.closed&&!d.signal.aborted&&this.setDetailLoad(e,r,{status:"error",message:b?.status==="error"?b.message:Ot(h,"Could not load the next content segment")}),!1}finally{d.signal.removeEventListener("abort",S)}}}catch(p){return this.closed||d.signal.aborted||this.setDetailLoad(e,r,{status:"error",message:Ot(p,"Could not load the next content segment")}),!1}finally{this.turnStructureRefreshKeys.delete(v)}}return c&&this.flushPendingRosterPublish(),!this.closed&&!d.signal.aborted&&this.setDetailLoad(e,r,{status:"error",message:Ot(h,"Could not load the next content segment")}),!1}finally{this.snapshotControllers.delete(d),this.rosterReadController===d&&(this.rosterReadController=void 0),this.contentControllers.get(o)===d&&this.contentControllers.delete(o);const h=this.viewOf(e);!this.closed&&!d.signal.aborted&&(l||this.generationOf(e)===f)&&h.detailLoads[r]?.status==="loading"&&this.setDetailLoad(e,r,void 0)}})().finally(()=>{this.detailReads.get(o)===g&&this.detailReads.delete(o)});return this.detailReads.set(o,g),g}cancelContentSegment(e,n){const s=`content:${JSON.stringify(n)}`,i=`${e}/${s}`,r=this.contentControllers.get(i);r!==void 0&&(this.contentControllers.delete(i),this.detailReads.delete(i),r.abort(),this.setDetailLoad(e,s,void 0))}todoPageWins(e,n,s,i){if(n===void 0||s.todoId==="todo"&&i?.stale===void 0&&n.notes===void 0&&n.notesMeta===void 0&&n.notesStatus===void 0&&(s.notes!==void 0||s.notesMeta!==void 0||s.notesStatus!==void 0))return!0;if(s.todoId!=="todo"||i?.readiness!=="ready"||i.stale!==void 0||s.notesStatus!==void 0||s.contentRefs?.some(d=>d.path[0]!=="items")===!0||s.notesMeta===void 0||s.notesMeta.rev<=(n.notesMeta?.rev??-1))return!1;const r=i.watermark?.transcript,o=this.timelines.get(e)?.cursor,a=this.timelines.get(e)?.todoRead?.watermark?.transcript;return r!==void 0&&o!==void 0&&r.epoch!==void 0&&r.epoch===o.epoch&&r.seq>=o.seq&&(a===void 0||a.epoch===r.epoch&&r.seq>=a.seq)}observeCanonicalTodoRead(e,n,s,i){const r=this.timelines.get(e)?.cursor;for(const o of s){if(o.op!=="todo.upsert"||o.todo.todoId!=="todo")continue;const a=o.todo,d=a.notesMeta!==void 0&&a.notesMeta.rev>(n?.notesMeta?.rev??-1);n=a;const l=this.timelines.get(e)?.todoRead?.watermark?.transcript??r,c=l!==void 0&&l.epoch!==void 0&&l.epoch===i.epoch&&i.seq>l.seq&&(r===void 0||r.epoch===i.epoch&&i.seq>r.seq);if(!d||!c)continue;const u=a.notes!==void 0&&a.notesStatus===void 0&&a.contentRefs?.some(f=>f.path[0]!=="items")!==!0;this.timeline(e).todoRead={source:i.epoch?.startsWith("cold:")===!0?"cold":"live",readiness:u?"ready":"partial",reason:u?void 0:"source_unverified",watermark:{transcript:i}}}}async loadTranscriptEntities(e,n){const s=this.view.transcript.entities?.bind(this.view.transcript),i=`entities:${n}`,r=`${e}/${i}`;if(this.closed||s===void 0||this.entityPageCursors.get(r)===null)return!1;const o=this.detailReads.get(r);if(o!==void 0)return o;const a=this.generationOf(e);let d=this.entityPageCursors.get(r)??void 0;const l=new AbortController;this.snapshotControllers.add(l);const c=(async()=>{this.setDetailLoad(e,i,{status:"loading"});try{let u=await s({agentId:e,kind:n,cursor:d,limit:20},{signal:l.signal});if(this.closed||l.signal.aborted||u.agent_id!==e||u.kind!==n||this.generationOf(e)!==a)return!1;if(u.read?.stale!==void 0){if(this.entityPageCursors.delete(r),d=void 0,u.read.stale.retry==="resync")return this.resync(),!1;if(u=await this.readAuthoritativeTranscriptContinuation(()=>s({agentId:e,kind:n,cursor:d,limit:20},{signal:l.signal}),"Transcript entity continuation is still stale",l.signal),this.closed||l.signal.aborted||u.agent_id!==e||u.kind!==n||this.generationOf(e)!==a)return!1}const f=u.read!==void 0&&u.read.readiness!=="ready";if(u.has_more&&!(f&&u.items.length===0)&&(u.next_cursor===void 0||u.next_cursor===""||u.next_cursor===d))throw new Error("Transcript entity page did not advance its cursor");if(!this.flushPendingTranscriptBatch(e))return!1;const g=this.ensureAgentTranscript(e),h=[];switch(u.kind){case"task":for(const x of u.items)g.getTask(x.taskId)===void 0&&h.push({op:"task.upsert",task:x});break;case"attachment":for(const x of u.items)g.getAttachment(x.attachmentId)===void 0&&h.push({op:"attachment.upsert",attachment:x});break;case"prompt":for(const x of u.items)g.getPrompt(x.promptId)===void 0&&h.push({op:"prompt.upsert",prompt:x});break;case"interaction":for(const x of u.items)g.getInteractions().has(x.interactionId)||h.push({op:"interaction.upsert",interaction:x});break;case"todo":for(const x of u.items)this.todoPageWins(e,g.getTodo(x.todoId),x,u.read)&&h.push({op:"todo.upsert",todo:x});break}g.apply(h).accepted.some(x=>x.op==="todo.upsert"&&x.todo.todoId==="todo")?u.read===void 0?this.timeline(e).todoRead=void 0:this.timeline(e).todoRead=u.read:u.kind==="todo"&&!u.has_more&&u.items.length===0&&g.getTodo("todo")===void 0&&u.read!==void 0&&(this.timeline(e).todoRead=u.read),this.entityPageCursors.set(r,u.has_more?u.next_cursor??null:null);const m=g.snapshot(),p={task:"tasks",attachment:"attachments",prompt:"prompts",interaction:"interactions",todo:"todos"}[n],k=m[p].length,S=x=>({returned:x,total:x,hasMore:!1}),w=this.timelines.get(e)?.globalCoverage??{version:1,tasks:S(m.tasks.length),attachments:S(m.attachments.length),prompts:S(m.prompts.length)};return this.timeline(e).globalCoverage={...w,[p]:{returned:k,total:Math.max(k,u.total??w[p]?.total??k),hasMore:u.has_more}},this.forestDirtyAgents.add(e),this.publishProjectedAgent(e,g),u.items.length>0}catch(u){return!this.closed&&!l.signal.aborted&&this.generationOf(e)===a&&this.setDetailLoad(e,i,{status:"error",message:Ot(u,"Could not load the next transcript entities")}),!1}finally{this.snapshotControllers.delete(l);const u=this.viewOf(e);!this.closed&&this.generationOf(e)===a&&u.detailLoads[i]?.status==="loading"&&this.setDetailLoad(e,i,void 0)}})();return this.detailReads.set(r,c),c.finally(()=>{this.detailReads.get(r)===c&&this.detailReads.delete(r)}),c}applyTranscriptDetail(e,n){const s=this.timelines.get(e)?.store;if(s===void 0||n.agent_id!==e||n.kind==="tool")return!1;let i;if(n.kind==="task")s.getTask(n.task.taskId)?.detailRef!==void 0&&(i={op:"task.upsert",task:n.task});else if(n.kind==="attachment"){const r=s.getAttachment(n.attachment.attachmentId),o=this.windowSnapshot(e).items.some(a=>a.kind==="turn"&&(a.attachmentIds?.includes(n.attachment.attachmentId)||a.steps.some(d=>d.frames.some(l=>"attachmentIds"in l&&l.attachmentIds?.includes(n.attachment.attachmentId)))));(r?.detailRef!==void 0||r===void 0&&o)&&(i={op:"attachment.upsert",attachment:n.attachment})}else s.getPrompt(n.prompt.promptId)?.detailRef!==void 0&&(i={op:"prompt.upsert",prompt:n.prompt});return i===void 0?!1:(s.apply([i]),this.forestDirtyAgents.add(e),this.pendingTranscriptAgents.add(e),this.flushFrames(),!0)}setDetailLoad(e,n,s){const i=this.viewOf(e);if(i.detailLoads[n]===s)return;const o={...i.detailLoads};s===void 0?delete o[n]:o[n]=s,this.publishView(e,{...i,version:i.version+1,detailLoads:o})}applyTranscriptOps(e,n,s,i){const r=this.pendingTranscriptBatches.get(e),o=r?.cursor??this.timelines.get(e)?.cursor;if(o?.epoch!==void 0&&s.epoch!==void 0&&s.epoch!==o.epoch){this.shell.resyncError?.retryable!==!1&&this.resync();return}const a=r===void 0?o?.seq:Math.max(r.cursor.seq,r.throughSeq);if(a!==void 0&&i<=a)return;const d=a!==void 0&&s.seq<=a?[]:n;r===void 0?this.pendingTranscriptBatches.set(e,{ops:[...d],cursor:s,throughSeq:i}):(r.ops.push(...d),s.seq>=r.cursor.seq&&(r.cursor=s),i>r.throughSeq&&(r.throughSeq=i)),this.scheduleFrameFlush()}flushPendingTranscriptBatches(){if(this.pendingTranscriptBatches.size===0)return;const e=[...this.pendingTranscriptBatches.keys()];for(const n of e)this.flushPendingTranscriptBatch(n)}flushPendingTranscriptBatch(e,n=!0){const s=this.pendingTranscriptBatches.get(e);if(s===void 0)return!0;this.pendingTranscriptBatches.delete(e);const i=s.throughSeq>s.cursor.seq?{seq:s.throughSeq,epoch:s.cursor.epoch}:s.cursor,r=this.ensureAgentTranscript(e),o=this.timelines.get(e)?.cursor,a=new Set(s.ops.flatMap(f=>f.op==="task.upsert"&&f.task.kind==="subagent"&&r.getTask(f.task.taskId)?.state!==f.task.state?[f.task.taskId]:[])),d=r.getTodo("todo"),l=this.applyAgentTranscriptOps(e,r,s.ops);if(l.gap!==void 0){this.toolCountSpans.delete(e),this.toolCountObservations.delete(e);const f=this.catchupReplay.get(e);return this.catchupReplay.set(e,{ops:f===void 0?s.ops:[...f.ops,...s.ops],cursor:f===void 0||i.seq>=f.cursor.seq?i:f.cursor}),n&&this.catchUpAgent(e),!1}this.observeCanonicalTodoRead(e,d,l.accepted,s.cursor),this.recordToolCountSpan(e,o,i,l.toolCallCountDelta),this.noteAppliedOps(this.timeline(e),l.accepted,i,this.timelines.get(e)?.appliedGrade??rt(this.transcriptGrades,e));const c=this.timeline(e);c.cursor=i,this.hasTranscriptBaseline(e)&&(this.viewHandle?.updateTranscriptCursor(e,i),c.refreshing&&c.stale.size===0&&this.settleRefresh(e));const u=this.adoptToolCountObservation(e);if(l.accepted.length>0||u){for(const f of l.accepted){if(f.op==="frame.upsert"&&f.frame.kind==="tool"){const g=`${e}/${f.frame.toolCallId}`,h=r.getToolCall(f.frame.toolCallId);this.toolDetails.has(g)&&h!==void 0&&this.toolDetails.set(g,{status:"found",...h})}this.observeContentPreview(e,f)}for(const f of this.contentReaders.values()){if(f.agentId!==e||(f.retryAttempt=0,f.retryTimer!==void 0&&(clearTimeout(f.retryTimer),f.retryTimer=void 0),!f.blocked))continue;const g=this.contentRefsFor(e,f.source);(f.ref===void 0||!g.some(h=>Pt(h,f.ref)))&&(f.blocked=!1)}this.pumpContentReads(),ri(l.accepted)&&this.forestDirtyAgents.add(e),this.requestRosterRows(Xp(l.accepted),void 0,!0),this.shell.agentCounts!==void 0&&l.accepted.some(f=>f.op==="task.upsert"&&a.has(f.task.taskId)&&f.task.agentId!==void 0)&&this.refreshRoster(this.shell.cursor),this.pendingTranscriptAgents.add(e)}return!0}catchUpAgent(e){const n=this.catchupByAgent.get(e);if(n!==void 0)return this.flushPendingTranscriptBatch(e,!1),n;this.flushPendingTranscriptBatch(e,!1);const s=this.runCatchUpAgent(e).finally(()=>{this.catchupByAgent.get(e)===s&&this.catchupByAgent.delete(e)});return this.catchupByAgent.set(e,s),s}async runCatchUpAgent(e){if(this.closed||this.resyncInFlight||this.rewriteHold!==void 0||this.shell.resyncError?.retryable===!1)return;const n=this.generationOf(e),s=new AbortController;this.catchupControllers.set(e,s);const i=()=>!this.closed&&!this.isSuspended&&!s.signal.aborted&&this.generationOf(e)===n;try{if(!this.hasTranscriptBaseline(e)){this.catchupReplay.delete(e),await this.resync();return}const r=this.timelines.get(e)?.cursor??{seq:0},o=rt(this.transcriptGrades,e);let a=await this.view.transcript.catchUp({agentId:e,since:r,grade:o==="off"?"turn":o},{signal:s.signal});const d=[a];let l=r;for(;a.has_more===!0;){if(!i())return;if(!a.complete||l.epoch!==void 0&&a.epoch!==l.epoch||a.through_seq<=l.seq){this.catchupReplay.delete(e),await this.resync();return}l={seq:a.through_seq,epoch:a.epoch},a=await this.view.transcript.catchUp({agentId:e,since:l,grade:o==="off"?"turn":o},{signal:s.signal}),d.push(a)}if(!i())return;if(!a.complete||l.epoch!==void 0&&a.epoch!==l.epoch){this.catchupReplay.delete(e),await this.resync();return}const c=this.ensureAgentTranscript(e),u=[];for(const x of d)for(const b of x.batches)u.push(...b.ops);let f=c.getTodo("todo");const g=this.applyAgentTranscriptOps(e,c,u);if(g.gap!==void 0){this.catchupReplay.delete(e),await this.resync();return}const h=new Set(g.accepted);for(const x of d)for(const b of x.batches){const _=b.ops.filter(C=>h.has(C));this.observeCanonicalTodoRead(e,f,_,{seq:b.seq,epoch:x.epoch});for(const C of _)C.op==="todo.upsert"&&C.todo.todoId==="todo"&&(f=C.todo)}let v=g.accepted.length>0;ri(g.accepted)&&this.forestDirtyAgents.add(e);let m={seq:a.through_seq,epoch:a.epoch};const p=this.timelines.get(e)?.cursor;p!==void 0&&p.epoch===a.epoch&&p.seq>m.seq&&(m=p);const k=this.catchupReplay.get(e);this.catchupReplay.delete(e);let S=[];if(k!==void 0){const x=c.getTodo("todo"),b=this.applyAgentTranscriptOps(e,c,k.ops);if(S=b.accepted,b.gap!==void 0){await this.resync();return}this.observeCanonicalTodoRead(e,x,b.accepted,k.cursor),k.cursor.seq>m.seq&&(m=k.cursor),b.accepted.length>0&&(v=!0),ri(b.accepted)&&this.forestDirtyAgents.add(e)}this.toolCountSpans.delete(e),this.noteAppliedOps(this.timeline(e),[...g.accepted,...S],m,o==="off"?"turn":o),this.timeline(e).cursor=m,this.viewHandle?.updateTranscriptCursor(e,m);const w=this.adoptToolCountObservation(e);(v||w)&&(this.pendingTranscriptAgents.add(e),this.scheduleFrameFlush())}catch{if(!i())return;this.catchupReplay.delete(e),await this.resync()}finally{this.catchupControllers.get(e)===s&&this.catchupControllers.delete(e)}}applyAgentTranscriptOps(e,n,s){const i=new Set;for(const a of s)if(a.op==="items.remove")for(const d of a.ids)i.add(d);const r=[];if(i.size>0){r.push(...this.residentToolDetailsOnTurns(e,n,i));for(const d of s)d.op==="frame.upsert"&&d.frame.kind==="tool"&&i.has(d.turnId)&&r.push({key:`${e}/${d.frame.toolCallId}`,turnId:d.turnId});const a=`${e}/`;for(const[d,l]of this.toolDetails)d.startsWith(a)&&l.status==="found"&&i.has(l.turnId)&&r.push({key:d,turnId:l.turnId})}const o=n.apply(s);if(i.size>0){const a=new Set;for(const l of o.accepted)if(l.op==="items.remove")for(const c of l.ids)a.add(c);const d=new Set;for(const l of r)a.has(l.turnId)&&d.add(l.key);for(const l of d)this.invalidateToolDetail(l);if(a.size>0){this.forgetWindowItems(e,a);for(const[l,c]of this.contentBodies)c.agentId===e&&(c.source.kind==="turn"&&a.has(c.source.id)||c.source.kind==="frame"&&c.source.turnId!==void 0&&a.has(c.source.turnId))&&this.contentBodies.delete(l);this.timeline(e).olderCursor=void 0,a.has(this.timelines.get(e)?.olderTurn??"")&&(this.timeline(e).olderTurn=void 0),this.cancelHistoryRead(e)}}return o}residentToolDetailsOnTurns(e,n,s){const i=[];for(const r of s){const o=n.getTurn(r);if(o!==void 0)for(const a of o.steps)for(const d of a.frames)d.kind==="tool"&&i.push({key:`${e}/${d.toolCallId}`,turnId:r})}return i}invalidateToolDetail(e){this.toolDetails.delete(e),this.toolDetailEpochs.set(e,(this.toolDetailEpochs.get(e)??0)+1);const n=this.toolDetailReads.get(e);n!==void 0&&(this.toolDetailReads.delete(e),n.controller.abort())}bumpHistoryGeneration(e){this.timeline(e).generation+=1;for(const[n,s]of this.contentReaders)s.agentId===e&&(this.retireContentRead(n),s.ref=void 0);for(const[n,s]of this.contentControllers)n.startsWith(`${e}/`)&&(this.contentControllers.delete(n),this.detailReads.delete(n),s.abort(),this.setDetailLoad(e,n.slice(e.length+1),void 0));this.pumpContentReads();for(const[n,s]of this.toolDetailReads)n.startsWith(`${e}/`)&&(this.toolDetailReads.delete(n),s.controller.abort());for(const n of this.toolDetails.keys())n.startsWith(`${e}/`)&&this.toolDetails.delete(n);for(const[n,s]of this.rangeControllers)s===e&&n.abort();this.contentRanges.clear(),this.contentRangeBytes=0,this.cancelHistoryRead(e),this.catchupControllers.get(e)?.abort(),this.catchupControllers.delete(e),this.catchupByAgent.delete(e),this.toolCountSpans.delete(e),this.toolCountObservations.delete(e)}observeToolCount(e,n){const s=n.tool_call_count,i=n.cursor;s===void 0||!Number.isSafeInteger(s)||s<0||typeof i?.epoch!="string"||!Number.isSafeInteger(i.seq)||i.seq<0||(this.toolCountObservations.set(e,{count:s,cursor:i}),this.adoptToolCountObservation(e))}adoptToolCountObservation(e){const n=this.toolCountObservations.get(e);if(n===void 0)return!1;const s=this.timelines.get(e)?.store,i=this.timelines.get(e)?.cursor;if(s===void 0||i===void 0||i.epoch===void 0||i.epoch!==n.cursor.epoch)return this.toolCountObservations.delete(e),!1;if(s.snapshot().toolCallCount!==void 0)return this.toolCountObservations.delete(e),!1;if(i.seq<n.cursor.seq)return!1;let r=n.count,o=n.cursor.seq;for(const d of this.toolCountSpans.get(e)??[]){if(o===i.seq)break;if(!(d.through.seq<=o)){if(d.from.epoch!==i.epoch||d.from.seq!==o||d.through.seq>i.seq||d.delta===void 0)break;r+=d.delta,o=d.through.seq}}return this.toolCountObservations.delete(e),o!==i.seq||!Number.isSafeInteger(r)||r<0||s.apply([{op:"tool.count.set",count:r}]).accepted.length===0?!1:(this.toolCountSpans.delete(e),this.forestDirtyAgents.add(e),!0)}recordToolCountSpan(e,n,s,i){if(this.timelines.get(e)?.store?.snapshot().toolCallCount!==void 0){this.toolCountSpans.delete(e);return}if(n===void 0||n.epoch!==s.epoch||n.seq>=s.seq)return;const r=this.toolCountSpans.get(e)??[],o=rt(this.transcriptGrades,e);r.push({from:n,through:s,delta:o==="block"||o==="delta"?i:void 0}),r.length>Mo&&r.splice(0,r.length-Mo),this.toolCountSpans.set(e,r)}ensureAgentTranscript(e){const n=this.timeline(e);if(n.store!==void 0)return n.store;const s=new uu(e);return n.store=s,this.storeTimelines.add(n),s}windowSnapshot(e){return this.ensureAgentTranscript(e).snapshot()}resetWindow(e,n,s,i,r,o){const a=n.getItems(),d={items:a,hasMoreOlder:n.hasMoreOlder},l=a.length>0&&(e.windowEpoch===void 0||e.windowEpoch===r.epoch),c=e.windowGrade,u=l&&o==="turn"&&c!==void 0&&be[c]>be.turn,f=l&&c!==void 0&&be[o]>be[c]&&be[c]<=be.turn,g=new Map(l?a.map(_=>[ht(_),_]):[]),h=new Set,v=new Set,m=s.items.map(_=>{const C=ht(_),F=g.get(C);if(F===void 0)return u&&_.kind==="turn"&&v.add(_.turnId),_;if(!jr(r,e.marks.get(C)))return h.add(C),F;if(_.kind!=="turn"||F.kind!=="turn")return i.kind==="unknown"&&_.kind==="marker"&&F.kind==="marker"?Dt(F,_):_;let N=i.kind==="unknown"?Ci(F,_):_;if(o==="turn"&&F.steps.length>0){const{steps:me,...V}=_;N=ot(F,{...V,steps:F.steps,stepsPartial:F.stepsPartial,contentRefs:[...(F.contentRefs??[]).filter(we=>we.path[0]==="steps"),...(_.contentRefs??[]).filter(we=>we.path[0]!=="steps")]})}return u&&!Ae(F,N)&&v.add(_.turnId),N}),p=new Set(m.map(ht)),k=s.items.find(_=>_.kind==="turn"),S=i.kind==="tail"?i.fromTurnId:void 0,w=S===void 0?k?.ordinal:s.items.find(_=>_.kind==="turn"&&_.turnId===S)?.ordinal??Ki(S),x=w!==void 0&&Number.isFinite(w)?w:k?.ordinal;let b=[];if(l&&i.kind!=="full"&&!f&&(x===void 0||a.some(_=>_.kind==="turn"&&_.ordinal>=x-1))){const _=x===void 0?-1:a.findIndex(F=>F.kind==="turn"&&F.ordinal>=x),C=_<0?a.length:_;b=a.filter((F,N)=>!p.has(ht(F))&&(N<C||i.kind==="unknown"));for(const F of b)F.kind==="turn"&&F.state==="running"&&x!==void 0&&F.ordinal<x&&v.add(F.turnId)}return{held:d,continuity:l,full:i.kind==="full",lowered:u,incoming:m,resetKeys:p,heldWins:h,kept:b,staleTurns:v}}settleWindowAfterReset(e,n,s,i,r){const o=n.getItems(),a=new Map,d=new Set;for(const f of o){const g=ht(f);d.add(g);const h=e.marks.get(g);s.resetKeys.has(g)&&!s.heldWins.has(g)?a.set(g,i):h!==void 0&&a.set(g,h)}e.marks=a;const l=f=>s.resetKeys.has(`turn:${f}`)&&!s.heldWins.has(`turn:${f}`),c=new Set;if(s.continuity)for(const f of e.stale)d.has(`turn:${f}`)&&!l(f)&&c.add(f);for(const f of s.staleTurns)d.has(`turn:${f}`)&&c.add(f);e.stale=c;const u=new Map;if(s.continuity)for(const[f,g]of e.joins)d.has(`turn:${f}`)&&!l(f)&&u.set(f,g);e.joins=u,s.lowered||(e.windowGrade=r==="off"?e.windowGrade:r),e.windowEpoch=i.epoch,s.kept.length===0&&(e.pagedPin=void 0,e.readerVisitedOld=!1),!s.continuity||s.full?e.relations=[]:e.relations=[...e.relations,...Po(s.held.items.filter(f=>!d.has(ht(f))))],e.relations=e.relations.filter(f=>!d.has(`turn:${f.turnId}`)),e.refreshing=!1}placeOlderPage(e,n,s,i){const r=this.timeline(e),o=new Set(n.getItems().map(ht)),a=n.getItems().find(u=>u.kind==="turn")?.ordinal,d=new Set,l=Cr(n.getItems(),s.items,(u,f)=>{const g=ht(f),h=jr(i,r.marks.get(g));if(u.kind!=="turn"||f.kind!=="turn")return h&&d.add(g),zu(u,f,h);const v=Hu(u,f,h);return v.join!==void 0&&r.joins.set(f.turnId,v.join),v.fromIncoming&&d.add(g),v.turn});for(const u of s.items){const f=ht(u);o.has(f)&&!d.has(f)||(i===void 0?r.marks.delete(f):r.marks.set(f,i),u.kind==="turn"&&o.has(f)&&(r.stale.delete(u.turnId),r.joins.delete(u.turnId)))}n.replaceItems(l,s.has_more);const c=(s.attachments??[]).filter(u=>n.getAttachment(u.attachmentId)===void 0);c.length>0&&n.apply(c.map(u=>({op:"attachment.upsert",attachment:u}))),r.relations=r.relations.filter(u=>n.getTurn(u.turnId)===void 0),r.windowEpoch===void 0&&i?.epoch!==void 0&&(r.windowEpoch=i.epoch),r.pagedPin===void 0&&(r.pagedPin=a??Number.POSITIVE_INFINITY,r.readerVisitedOld=!1)}forgetWindowItems(e,n){const s=this.timelines.get(e);if(s===void 0)return;const i=new Set(n);for(const r of i){for(const o of["turn","marker","taskref"])s.marks.delete(`${o}:${r}`);s.stale.delete(r),s.joins.delete(r)}s.relations.some(r=>i.has(r.turnId))&&(s.relations=s.relations.filter(r=>!i.has(r.turnId)))}noteAppliedOps(e,n,s,i){const r=i==="turn"&&e.windowGrade!==void 0&&be[e.windowGrade]>be.turn;for(const o of n){const a=Gp(o);a!==void 0&&(e.marks.set(a,s),r&&a.startsWith("turn:")&&e.stale.add(a.slice(5)))}e.windowEpoch===void 0&&(e.windowEpoch=s.epoch)}turnHasGap(e,n){const s=this.timelines.get(e),i=s?.store?.getTurn(n);return i!==void 0&&Ri(i,s.stale.has(n),s.joins.get(n))!==void 0}trimWindow(e,n,s){const i=s.getItems(),r=[];for(const p of i)p.kind==="turn"&&r.push(p);if(r.length<=Bp||n.paging>0||n.viewLeases.size===0)return!1;let o=r.length-Lp;const a=new Map(r.map((p,k)=>[p.turnId,k]));let d=!1;for(const p of n.viewLeases.keys()){const k=a.get(p);if(k!==void 0){if(k<o)return!1;k>=r.length-2&&(d=!0)}}if(!d)return!1;if(n.pagedPin!==void 0){if(!n.readerVisitedOld)return!1;n.pagedPin=void 0,n.readerVisitedOld=!1}const l=p=>p!==void 0&&(a.get(p)??Number.POSITIVE_INFINITY)<o;for(const p of this.contentReaders.values())if(!(p.agentId!==e||p.readers===0)&&l(p.source.kind==="turn"?p.source.id:p.source.kind==="frame"?p.source.turnId:void 0))return!1;const c=`${e}/content:`;for(const p of this.contentControllers.keys()){if(!p.startsWith(c))continue;const k=JSON.parse(p.slice(c.length)).source;if(l(k.kind==="turn"?k.id:k.kind==="frame"?k.turnId:void 0))return!1}const u=r.findIndex((p,k)=>k<o&&p.state==="running");if(u>=0&&(o=u),o<=0)return!1;const f=s.releaseBefore(r[o].turnId);if(f.length===0)return!1;const g=f.map(p=>p.kind==="turn"?p.turnId:p.kind==="marker"?p.markerId:p.refId);this.forgetWindowItems(e,g);const h=Po(f);h.length>0&&(n.relations=[...n.relations,...h]);const v=new Set(g),m=n.view;m!==void 0&&Object.keys(m.detailLoads).some(p=>p.startsWith("structure:")&&v.has(p.slice(10)))&&(n.view={...m,detailLoads:Object.fromEntries(Object.entries(m.detailLoads).filter(([p])=>!p.startsWith("structure:")||!v.has(p.slice(10))))});for(const[p,k]of this.contentBodies)k.agentId===e&&(k.source.kind==="turn"&&v.has(k.source.id)||k.source.kind==="frame"&&k.source.turnId!==void 0&&v.has(k.source.turnId))&&this.contentBodies.delete(p);return n.olderCursor=void 0,n.olderTurn=r[o].turnId,this.forestDirtyAgents.add(e),!0}publishProjectedAgent(e,n,s){const i=this.timeline(e),r=this.trimWindow(e,i,this.ensureAgentTranscript(e)),o=this.windowSnapshot(e),a=this.viewOf(e),d=a.snapshotSubagents===this.shell.snapshotSubagents?a:{...a,snapshotSubagents:this.shell.snapshotSubagents};let l=tp(d,e,o,{retainPendingPrompts:s?.retainPendingPrompts,cold:i.cursor?.epoch?.startsWith("cold:")===!0,gapOf:m=>Ri(m,i.stale.has(m.turnId),i.joins.get(m.turnId))});if(r&&l.historyCoverageKind==="full"&&(l={...l,historyCoverageKind:"tail"}),e===M){for(const m of o.prompts)this.unprojectedQueueReceipts.delete(m.promptId);for(const m of this.unprojectedQueueReceipts.values()){const p=dt(m.content);l=Dn(l,{userMessageId:m.user_message_id,promptId:m.prompt_id,text:p.text,media:p.media,content:m.content,createdAt:m.created_at,status:m.status,origin:m.origin,appendTiming:m.append_timing}),l={...l,queuedPromptMeta:{...l.queuedPromptMeta,[m.prompt_id]:{appendTiming:m.append_timing??"agent_idle",revision:m.revision,queuePosition:d.queuedPromptMeta[m.prompt_id]?.queuePosition}}}}}for(const m of l.blocks){if(m.kind!=="question"||m.outcome!==void 0)continue;const p=this.questionOutcomes.get(m.request.question_id);p!==void 0&&(l=wo(l,m.request.question_id,p))}const c=s===void 0?l:{...l,transcriptResetVersion:s.transcriptReset===!0?l.transcriptResetVersion+1:l.transcriptResetVersion,loadingOlder:s.loadingOlder??l.loadingOlder,fetchedOlder:s.fetchedOlder??l.fetchedOlder,olderError:Object.hasOwn(s,"olderError")?s.olderError:l.olderError,historyCoverageKind:s.historyCoverageKind??l.historyCoverageKind},u=Nn(d.contentRefs,[...Fn(o),...e===M?this.latestSnapshot?.contentRefs??[]:[]]),f=this.transcriptPresentable(e),g={...c,globalCoverage:i.globalCoverage,contentRefs:u,historyRead:i.historyRead,todoRead:i.todoRead,transcriptReady:f,refreshing:f&&i.refreshing},h=this.inFrameFlush?!1:this.forestDirtyAgents.delete(e)||this.publishedForest===void 0?this.publishForest():!1;i.cursor!==void 0&&(i.publishedCursor=i.cursor);const v=this.adoptAcceptedSteers(e,g);e===M&&(!this.shell.loaded||this.shell.loadError!==void 0)&&this.setShell({...this.shell,version:this.shell.version+1,loaded:!0,loadError:void 0},!1),v&&g===this.viewOf(e)?this.republishSteers(e):this.publishView(e,g),e===M&&(d.transcriptReady||d.busy)&&!l.busy&&l.turnTail!==void 0&&(d.busy||l.turnTail.turnId!==d.turnTail?.turnId)&&this.refreshSession(),this.contentReaders.size>0&&this.pumpContentReads(),h&&e!==M&&this.publishShell()}forestPublishCount=0;publishForest(){const e=new Map;for(const r of this.storeTimelines){const o=r.store.snapshot();if(r.relations.length===0){e.set(r.agentId,o);continue}const a=r.forestInput;(a?.relations!==r.relations||a.window!==o)&&(r.forestInput={relations:r.relations,window:o,snapshot:{...o,items:[...r.relations,...o.items]}}),e.set(r.agentId,r.forestInput.snapshot)}const n=this.publishedForest,s=new Set([...this.timelines.values()].filter(({cursor:r})=>r?.epoch?.startsWith("cold:")===!0).map(({agentId:r})=>r)),i=new Set;for(const[r,o]of this.rosterTranscriptBindings)o===this.timelines.get(r)?.store?.getMeta().agent?i.add(r):this.rosterTranscriptBindings.delete(r);return this.publishedForest=this.forestQuery.read(e,this.shell.snapshotSubagents,s,i),this.forestPublishCount+=1,n!==this.publishedForest}async sendPrompt(e){const n=e.content??[{type:"text",text:e.text}],s=e.promptId??ti(),i=this.usesDurableSubmission(),r=Pr({sessionId:this.sessionId,agentId:M,promptId:s,content:n,createdAt:new Date().toISOString()},{persist:i});e.onPreservation?.(r.persisted);const o=await this.client.submitPrompt(this.sessionId,{admission:i?"durable":void 0,content:n,profile:e.profile,execution:e.execution,model:e.model,thinking:e.thinking,permission_mode:e.permissionMode,plan_gate:e.planGate,plan_mode:e.planMode,goal_objective:e.goalObjective!==void 0&&e.goalObjective.trim()!==""?e.goalObjective.trim():void 0,goal_control:e.goalControl,append_timing:e.appendTiming,after_model_switch:e.afterModelSwitch,model_switch_mode:e.modelSwitchMode,prompt_id:s,skills:e.skills===void 0?void 0:[...e.skills],persona_greeting_reply:e.personaGreetingReply}),a=o.admission==="failed"||o.admission==="cancelled";a||(r.acknowledge(),e.onAcknowledged?.()),o.admission!==void 0&&this.setDurableIngress([...(this.shell.durableIngress??[]).filter(c=>c.prompt_id!==o.prompt_id||(c.agent_id??M)!==M),o]);const d=o.admission===void 0||o.admission==="admitted";d&&this.shell.cursor.epoch?.startsWith("cold:")===!0&&this.resync(),(o.admission==="restoring"||o.admission==="waiting_switch")&&(this.durablePromptReads.set(JSON.stringify([M,o.prompt_id]),e.text),this.observeDurableSteer(M,o.prompt_id));const l=this.timelines.get(M)?.store?.getPrompt(o.prompt_id);return d&&o.status==="queued"&&l===void 0&&this.unprojectedQueueReceipts.set(o.prompt_id,o),!d||a||l!==void 0||this.adoptAdmittedMainPrompt(o,e.text,e.appendTiming),o}adoptAdmittedMainPrompt(e,n,s){const i=this.timelines.get(M)?.store?.getPrompt(e.prompt_id);if(e.status==="queued"&&i===void 0&&this.unprojectedQueueReceipts.set(e.prompt_id,e),i!==void 0)return;const r=dt(e.content);this.publishView(M,Dn(this.viewOf(M),{userMessageId:e.user_message_id,promptId:e.prompt_id,text:r.text===""?n:r.text,createdAt:e.created_at,status:e.status,origin:e.origin,media:r.media,content:e.content,appendTiming:e.append_timing??s}))}expectedCursor(){return{seq:this.shell.cursor.seq,epoch:this.shell.cursor.epoch}}async editMessage(e,n){await this.runMessageRewrite("edit",e,{content:n.content??[{type:"text",text:n.text}],model:n.model,thinking:n.thinking,permission_mode:n.permissionMode,plan_gate:n.planGate,plan_mode:n.planMode===!0?!0:void 0}),this.resync({rewrite:!0})}async regenerateMessage(e,n={}){await this.runMessageRewrite("regenerate",e,{model:n.model,thinking:n.thinking,permission_mode:n.permissionMode,plan_gate:n.planGate,plan_mode:n.planMode===!0?!0:void 0}),this.resync({rewrite:!0})}messageRewrites=new Map;async runMessageRewrite(e,n,s){const i=`${e}:${n}`,r=JSON.stringify(s);let o=this.messageRewrites.get(i);if(o?.fingerprint!==r&&(o=void 0),o?.result!==void 0){if(JSON.stringify(o.body.expected_cursor)===JSON.stringify(this.expectedCursor()))return o.result;o=void 0}if(o?.flight!==void 0)return o.flight;Yt(this.shell),o===void 0&&(o={fingerprint:r,body:{...s,operation_id:ti(),expected_cursor:this.expectedCursor()}},this.messageRewrites.set(i,o));const a=o,d=e==="edit"?this.client.editMessage(this.sessionId,n,a.body):this.client.regenerateMessage(this.sessionId,n,a.body);a.flight=d;try{return a.result=await d,a.result}catch(l){const c=l instanceof Ee||l instanceof mt?l.code:void 0;throw c!==void 0&&c>0&&c!==50001&&this.messageRewrites.get(i)===a&&this.messageRewrites.delete(i),l}finally{a.flight=void 0}}async forkFromMessage(e,n){return await this.client.forkSession(this.sessionId,{through_message_id:e,expected_cursor:this.expectedCursor(),seed:n})}async abortActive(){if(this.abortActiveInFlight!==void 0)return this.abortActiveInFlight;const e=this.abortActiveAndRestore();this.abortActiveInFlight=e;try{await e}finally{this.abortActiveInFlight=void 0}}unansweredPromptContent(e,n=!1){const s=this.timelines.get(M)?.store;if(s===void 0||this.timelines.get(M)?.appliedGrade!=="delta")return;const i=s.snapshot(),r=i.prompts.find(d=>d.promptId===e);if(r===void 0||r.steeredAt!==void 0||r.status!=="running"&&!(n&&r.status==="aborted"))return;const o=i.items.find(d=>d.kind==="turn"&&(d.promptId===e||d.origin.kind==="user"&&typeof d.origin.payload=="object"&&d.origin.payload!==null&&"promptId"in d.origin.payload&&d.origin.payload.promptId===e));if(o?.kind==="turn"&&(o.origin.kind!=="user"||o.steps.some(d=>d.frames.some(l=>l.kind==="tool"||l.kind==="text"&&l.role==="assistant"&&(l.text!==""||(l.attachmentIds?.length??0)>0)))))return;const a=pi.array().safeParse(r.content);if(!(!a.success||a.data.length===0||a.data.some(d=>d.type!=="text"&&d.type!=="image"&&d.type!=="video"&&d.type!=="file")))return a.data}async abortActiveAndRestore(){const e=this.viewOf(M);if(!e.busy)return;const n=e.abortablePromptId;if(n!==void 0){const i=this.unansweredPromptContent(n),r=await this.client.abortPrompt(this.sessionId,n);if(await this.refreshPrompts(),r.aborted&&i!==void 0&&this.lastRestoredPromptId!==n&&this.unansweredPromptContent(n,!0)!==void 0){this.lastRestoredPromptId=n;for(const o of this.interruptedPromptListeners)o(i)}return}const s=e.abortableTurnId;s!==void 0&&await this.client.abortTurn(this.sessionId,s)}async abortPrompt(e,n=M){const s=await this.client.abortPrompt(this.sessionId,e,n===M?void 0:n,!0).catch(a=>{if(a instanceof Ee&&a.code===Ce.PROMPT_NOT_FOUND)return{aborted:!1};throw a});if(this.clearPendingSteer(n,e),!s.aborted)return await this.resync(),!1;if(n!==M)return!0;this.unprojectedQueueReceipts.delete(e);const i=this.viewOf(M),r=i.queuedPromptMeta[e]?.queuePosition,o={};for(const[a,d]of Object.entries(i.queuedPromptMeta))a!==e&&(o[a]=r!==void 0&&d.queuePosition!==void 0&&d.queuePosition>r?{...d,queuePosition:d.queuePosition-1}:d);return this.publishView(M,{...i,version:i.version+1,queuedPromptIds:i.queuedPromptIds.filter(a=>a!==e),queuedPromptMeta:o,blocks:i.blocks.filter(a=>!(a.kind==="user"&&a.promptId===e&&a.promptStatus==="queued"&&a.turnId===void 0))}),await this.refreshPrompts(),!0}async readQueuedPromptContent(e,n){const s={kind:"prompt",id:e},i=this.beginContentRead(M,s,["content"]);try{for(;;){n?.throwIfAborted();const a=this.contentRefsFor(M,s).find(d=>d.path[0]==="content");if(a===void 0)break;if(!await this.loadContentSegment(M,a))throw new Error("Could not read the complete queued prompt")}const r=this.timelines.get(M)?.store?.getPrompt(e);if(r?.status!=="queued"&&r?.status!=="blocked")return;const o=pi.array().safeParse(r.content);if(!o.success)throw new Error("Could not read the original queued prompt attachments");return o.data}finally{i.release()}}async replaceQueued(e,n,s,i){Yt(this.shell);const r=await this.client.replacePrompt(this.sessionId,e,{content:[...n.trim()===""?[]:[{type:"text",text:n,presentation:i}],...s??[]],replace_attachments:s===void 0?void 0:!0});this.unprojectedQueueReceipts.has(e)&&this.unprojectedQueueReceipts.set(e,r);const o=dt(r.content);this.publishView(M,Dn(this.viewOf(M),{userMessageId:r.user_message_id,promptId:r.prompt_id,text:o.text,createdAt:r.created_at,status:r.status,origin:r.origin,media:o.media,content:r.content}))}async moveQueued(e,n){Yt(this.shell);const s=await this.client.movePrompt(this.sessionId,e,{target_index:n}),i=this.viewOf(M),r={...i.queuedPromptMeta};s.queued_prompt_ids.forEach((o,a)=>{if(ws(o)){const c=r[o];r[o]=c!==void 0&&c.appendTiming==="agent_idle"&&c.queuePosition===a?c:{appendTiming:"agent_idle",queuePosition:a};return}const d=this.unprojectedQueueReceipts.get(o);d!==void 0&&(this.unprojectedQueueReceipts.delete(o),this.unprojectedQueueReceipts.set(o,d));const l=r[o];r[o]={...l,appendTiming:l?.appendTiming??"agent_idle",queuePosition:a}}),this.publishView(M,{...i,version:i.version+1,queuedPromptIds:s.queued_prompt_ids.filter(o=>!ws(o)),queuedPromptMeta:r})}async setQueuedTiming(e,n){Yt(this.shell);const s=this.viewOf(M).queuedPromptMeta[e],i=s?.appendTiming??"agent_idle",r=s?.revision,o=++this.queuedTimingWriteSequence;this.queuedTimingWrites.set(e,o);const a=r;let d;try{d=await this.client.timingPrompt(this.sessionId,e,{append_timing:n,expected_revision:a})}catch(u){throw this.queuedTimingWrites.get(e)===o&&this.queuedTimingWrites.delete(e),u}const l=this.viewOf(M),c=l.queuedPromptMeta[e];if(this.queuedTimingWrites.get(e)===o){if(!l.queuedPromptIds.includes(e)||(c?.appendTiming??"agent_idle")!==i||c?.revision!==r){this.queuedTimingWrites.delete(e);return}this.queuedTimingWrites.delete(e),this.publishView(M,{...l,version:l.version+1,queuedPromptMeta:{...l.queuedPromptMeta,[e]:{...c,appendTiming:d.append_timing??n,revision:d.revision}}})}}async holdQueued(e,n){return this.client.holdPrompt===void 0?!1:(Yt(this.shell),await this.client.holdPrompt(this.sessionId,e,{held:n}),!0)}async steerQueued(e){if(Yt(this.shell),this.findPendingSteer(M,e)?.phase==="waiting")return{outcome:"accepted"};if(this.timelines.get(M)?.store?.getPrompt(e)?.steerAccepted===!0)return{outcome:"accepted"};const n=this.viewOf(M),s=n.blocks.find(a=>a.kind==="user"&&a.promptId===e&&a.promptStatus==="queued"),i=s?.kind==="user"?void 0:lp(n).find(a=>a.promptId===e);s?.kind==="user"?this.setPendingSteer(M,{promptId:e,userMessageId:s.userMessageId,text:s.text,presentation:s.presentation,media:s.media,createdAt:new Date().toISOString(),phase:"sending"}):i!==void 0&&i.originKind!=="cron_job"&&this.setPendingSteer(M,{promptId:e,userMessageId:i.userMessageId,text:i.text,presentation:i.presentation,media:i.media,createdAt:new Date().toISOString(),phase:"sending"});let r;try{r=await this.client.steerPrompt(this.sessionId,e)}catch(a){if(Sr(a)){const d=this.settledSteerOutcome(M,e);if(d!==void 0)return{outcome:d};const l=this.findPendingSteer(M,e);return l?.phase==="waiting"?{outcome:"accepted"}:(l!==void 0&&this.setPendingSteer(M,{...l,phase:"unconfirmed"}),{outcome:"unconfirmed"})}if(this.clearPendingSteer(M,e),a instanceof Ee&&a.code===Ce.PROMPT_NOT_FOUND)return await this.resync(),{outcome:"not_pending",reason:"prompt_no_longer_pending"};throw await this.refreshPrompts(),a}this.unprojectedQueueReceipts.delete(e);const o=this.settledSteerOutcome(M,e);if(o==="failed"||o==="cancelled")return this.clearPendingSteer(M,e),{outcome:o};if(r.steered||r.delivery_state==="accepted"){const a=this.findPendingSteer(M,e);a!==void 0&&this.setPendingSteer(M,{...a,phase:"waiting"})}else this.clearPendingSteer(M,e);if(r.delivery_state==="accepted"){if(this.findPendingSteer(M,e)===void 0){const a=this.timelines.get(M)?.store,d=a?.getPrompt(e);a!==void 0&&d?.status==="queued"&&!d.steerAccepted&&(a.apply([{op:"prompt.upsert",prompt:{...d,steerAccepted:!0}}]),this.publishProjectedAgent(M,a)),await this.refreshPrompts()}return{outcome:"accepted"}}return await this.refreshPrompts(),!r.steered&&r.delivery_state!=="queued"&&await this.resync(),{outcome:r.steered?"steered":r.delivery_state??"not_pending",reason:r.delivery_reason}}getPendingSteers(e=M){return this.timelines.get(e)?.steers??[]}async sendPromptNow(e){Yt(this.shell);const n=e.agentId??M,s=e.promptId??ti(),i=e.content??[{type:"text",text:e.text}],r=dt(i),o=this.usesDurableSubmission(),a=Pr({sessionId:this.sessionId,agentId:n,promptId:s,content:i,createdAt:new Date().toISOString()},{persist:o});e.onPreservation?.(a.persisted),this.setPendingSteer(n,{promptId:s,text:e.text,presentation:r.presentation,media:e.media??Yp(r.media),createdAt:new Date().toISOString(),phase:"sending"});let d;try{d=await this.client.submitPrompt(this.sessionId,{admission:o?"durable":void 0,delivery_mode:"steer",after_model_switch:e.afterModelSwitch,content:i,prompt_id:s,...n===M?{}:{agent_id:n},profile:e.profile,execution:e.execution,model:e.model,model_switch_mode:e.modelSwitchMode,thinking:e.thinking,permission_mode:e.permissionMode,plan_mode:e.planMode,plan_gate:e.planGate,skills:e.skills===void 0?void 0:[...e.skills]})}catch(g){if(Sr(g)){const h=this.findPendingSteer(n,s),v=this.settledSteerOutcome(n,s)??(h?.phase==="waiting"?"accepted":void 0);if(v!==void 0)return a.acknowledge(),e.onAcknowledged?.(),{promptId:s,outcome:v};throw h!==void 0&&this.setPendingSteer(n,{...h,phase:"unconfirmed"}),o&&this.observeDurableSteer(n,s),new Xt("unknown",g)}throw a.acknowledge(),this.clearPendingSteer(n,s),new Xt("submit",g)}const l=d.admission,c=l==="failed"||l==="cancelled";if(c||(a.acknowledge(),e.onAcknowledged?.()),l!==void 0){const g=rs(d,n);this.setDurableIngress([...(this.shell.durableIngress??[]).filter(h=>h.prompt_id!==g.prompt_id||(h.agent_id??M)!==n),g])}const u=this.settledSteerOutcome(n,d.prompt_id);if(u!==void 0)return this.reconcileSteerOutcome(n,s,u),{promptId:d.prompt_id,outcome:u};if(c)return this.clearPendingSteer(n,s),{promptId:d.prompt_id,outcome:l};if(l==="restoring"||l==="waiting_switch"||l==="held")return l!=="held"&&this.observeDurableSteer(n,s),{promptId:d.prompt_id,outcome:l==="waiting_switch"?"restoring":l};if(o||d.delivery_state!==void 0){l==="admitted"&&this.shell.cursor.epoch?.startsWith("cold:")===!0&&this.resync();const g=d.delivery_state??(d.status==="queued"?"queued":"started"),h=this.findPendingSteer(n,s);return g==="accepted"||g==="steered"?h!==void 0&&this.setPendingSteer(n,{...h,phase:"waiting"}):g!=="started"&&this.clearPendingSteer(n,s),{promptId:d.prompt_id,outcome:g,reason:d.delivery_reason}}if(d.status!=="queued")return this.clearPendingSteer(n,s),{promptId:d.prompt_id,outcome:"started"};try{const g=await this.client.steerPrompt(this.sessionId,d.prompt_id,n),h=this.settledSteerOutcome(n,d.prompt_id);if(h!==void 0||g.delivery_state==="queued")return this.reconcileSteerOutcome(n,s,h),{promptId:d.prompt_id,outcome:h??"queued",reason:h===void 0?g.delivery_reason:void 0};if(!g.steered){this.clearPendingSteer(n,s),await this.resync();const v=this.settledSteerOutcome(n,d.prompt_id);return{promptId:d.prompt_id,outcome:v??"not_pending",reason:v===void 0?g.delivery_reason??"prompt_no_longer_pending":void 0}}}catch(g){const h=this.settledSteerOutcome(n,d.prompt_id);if(this.reconcileSteerOutcome(n,s,h),h!==void 0)return{promptId:d.prompt_id,outcome:h};if(g instanceof Ee&&g.code===Ce.PROMPT_NOT_FOUND){await this.resync();const v=this.settledSteerOutcome(n,d.prompt_id);return v!==void 0?{promptId:d.prompt_id,outcome:v}:{promptId:d.prompt_id,outcome:"not_pending",reason:"prompt_no_longer_pending"}}if(g instanceof Ee&&g.code===Ce.REQUEST_INVALID){let v;try{v=await this.client.abortPrompt(this.sessionId,d.prompt_id,n,!0)}catch(p){throw new Xt("unknown",p)}if(v.aborted===!0)throw new Xt("refused",g);let m;try{m=(await this.view.transcript.page({agentId:n})).prompts?.find(p=>p.promptId===d.prompt_id)}catch(p){throw new Xt("unknown",p)}if(m?.status==="running"||m?.status==="completed")return{promptId:d.prompt_id,outcome:m.steeredAt===void 0?"started":"steered"};throw new Xt("unknown",g)}throw new Xt("unknown",g)}const f=this.findPendingSteer(n,s);return f!==void 0&&this.setPendingSteer(n,{...f,phase:"waiting"}),{promptId:d.prompt_id,outcome:"steered"}}settledSteerOutcome(e,n){const s=this.timelines.get(e)?.store?.getPrompt(n);if(!(s===void 0||s.status==="queued"))return s.status==="aborted"?"cancelled":s.status==="failed"||s.status==="blocked"?"failed":s.steeredAt!==void 0?"steered":"started"}reconcileSteerOutcome(e,n,s){if(s!=="steered"){this.clearPendingSteer(e,n);return}const i=this.findPendingSteer(e,n);i!==void 0&&this.setPendingSteer(e,{...i,phase:"waiting"})}findPendingSteer(e,n){return this.timelines.get(e)?.steers.find(s=>s.promptId===n)}setPendingSteer(e,n){const s=this.timeline(e),i=s.steers,r=i.findIndex(o=>o.promptId===n.promptId);s.steers=r<0?[...i,n]:i.map((o,a)=>a===r?n:o),this.republishSteers(e)}clearPendingSteer(e,n){const s=this.timelines.get(e);s===void 0||!s.steers.some(i=>i.promptId===n)||(s.steers=s.steers.filter(i=>i.promptId!==n),this.republishSteers(e))}adoptAcceptedSteers(e,n){const s=this.timelines.get(e)?.store;if(s===void 0)return!1;const i=this.timelines.get(e)?.steers??[];let r=i;for(const o of s.getPrompts().values()){if(!o.steerAccepted||o.status!=="queued"||o.originKind==="cron_job")continue;const a=r.find(u=>u.promptId===o.promptId);if(a!==void 0){a.phase!=="waiting"&&(r=r.map(u=>u===a?{...u,phase:"waiting"}:u));continue}const d=n.blocks.find(u=>u.kind==="user"&&u.promptId===o.promptId&&u.promptStatus==="queued");if(d?.kind==="user"){r=[...r,{promptId:o.promptId,userMessageId:d.userMessageId,text:d.text,presentation:d.presentation,media:d.media,createdAt:d.createdAt,phase:"waiting"}];continue}const l=dt(o.content??[],o.contentRefs),c=qt({text:l.text,presentation:l.presentation,role:"user",origin:{kind:"user"}});r=[...r,{promptId:o.promptId,userMessageId:o.userMessageId,text:c.text!==""?c.text:l.text,presentation:c.presentation??l.presentation,media:l.media.length>0?l.media:void 0,createdAt:o.createdAt,phase:"waiting"}]}return r!==i?(this.timeline(e).steers=r,!0):!1}retireSettledSteers(e,n){const s=this.timelines.get(e),i=s?.steers??[];if(s===void 0||i.length===0)return;const r=this.timelines.get(e)?.store,o=i.filter(a=>{const d=r?.getPrompt(a.promptId);return!(fd(n.blocks,a)||d!==void 0&&(d.status==="blocked"||d.status==="failed"||d.status==="aborted"||!n.busy&&d.status!=="queued"||d.steeredAt!==void 0&&r!==void 0&&Mp(r.getItems(),d.steeredAt)))});o.length!==i.length&&(s.steers=o)}republishSteers(e){if(this.closed)return;const n=this.viewOf(e);this.publishView(e,{...n,version:n.version+1})}async clearQueue(){const e=this.getState().queuedPromptIds;if(e.length===0)return{total:0,failed:0};const n=await Promise.allSettled(e.map(s=>this.abortPrompt(s)));return await this.refreshPrompts(),{total:e.length,failed:n.filter(s=>s.status==="rejected").length}}async resolveApproval(e,n,s,i,r){const o=new Date().toISOString();try{await this.client.resolveApproval(this.sessionId,e,{decision:n,scope:s,selected_option_id:i,...r?.feedback===void 0?{}:{feedback:r.feedback},...r?.selectedLabel===void 0?{}:{selected_label:r.selectedLabel}}),this.markApprovalInViews(e,{decision:n,resolvedAt:o})}catch(a){if(a instanceof Ee&&a.code===Ce.APPROVAL_ALREADY_RESOLVED){this.markApprovalInViews(e,{decision:"resolved_elsewhere",resolvedAt:o});return}if(a instanceof Ee&&a.code===Ce.APPROVAL_EXPIRED){this.markApprovalInViews(e,{decision:"expired",resolvedAt:o});return}throw a}}markApprovalInViews(e,n){for(const{agentId:s,view:i}of this.timelines.values())i!==void 0&&this.publishView(s,gp(i,e,n))}questionOutcomes=new Map;questionBlock(e){const n=[...this.timelines.values()].flatMap(s=>s.view?.blocks??[]).find(s=>s.kind==="question"&&s.request.question_id===e);if(n?.kind==="question"){if(n.request.session_id!==""&&n.request.session_id!==this.sessionId)throw new Error("The question belongs to a different session.");return n}}setQuestionOutcome(e,n){this.questionOutcomes.set(e,n);for(const{agentId:s,view:i}of this.timelines.values()){if(i===void 0)continue;const r=wo(i,e,n);r!==i&&this.publishView(s,r)}}async reconcileQuestionOutcome(e,n){const s=this.questionBlock(e);this.setQuestionOutcome(e,n);try{const i=await this.view.transcript.page({agentId:s?.originAgentId??M,pageSize:1});if(this.closed)return;const r=i.interactions?.find(a=>a.interactionId===e),o=r===void 0?void 0:Va(r,i.agent_id);o?.kind==="question"&&o.outcome!==void 0&&this.setQuestionOutcome(e,o.outcome)}catch{}}async handleQuestionError(e,n){if(!(n instanceof Ee))return!1;const s=new Date().toISOString();return n.code===Ce.APPROVAL_ALREADY_RESOLVED?(await this.reconcileQuestionOutcome(e,{kind:"resolvedElsewhere",at:s}),!0):n.code===Ce.QUESTION_NOT_FOUND||n.code===Ce.SESSION_NOT_FOUND?(await this.reconcileQuestionOutcome(e,{kind:"unavailable",at:s}),!0):n.code===Ce.QUESTION_EXPIRED?(await this.reconcileQuestionOutcome(e,{kind:"expired"}),!0):!1}async answerQuestion(e,n){const s=this.questionBlock(e);if(s?.outcome!==void 0)return;const i=new Date().toISOString();try{await this.client.resolveQuestion(this.sessionId,e,{answers:n,method:"click"});const r=s===void 0?void 0:Xi(s.request.questions,n);this.setQuestionOutcome(e,{kind:"answered",at:i,answers:r})}catch(r){if(!await this.handleQuestionError(e,r))throw r}}async dismissQuestion(e){if(this.questionBlock(e)?.outcome!==void 0)return;const s=new Date().toISOString();try{await this.client.dismissQuestion(this.sessionId,e),this.setQuestionOutcome(e,{kind:"dismissed",at:s})}catch(i){if(!await this.handleQuestionError(e,i))throw i}}async cancelTask(e){try{await this.client.cancelTask(this.sessionId,e)}finally{await this.refreshTasks()}}}function ri(t){return t.some(e=>{switch(e.op){case"reset":case"tool.count.set":case"task.upsert":case"meta.merge":case"turn.upsert":case"step.upsert":case"frame.upsert":case"frame.remove":case"items.remove":return!0;default:return!1}})}function Xp(t){const e=[];for(const n of t){if(n.op==="task.upsert"){n.task.kind==="subagent"&&n.task.agentId!==void 0&&n.task.agentId!==""&&e.push(n.task.agentId);continue}if(n.op==="frame.upsert"){if(n.frame.kind!=="tool")continue;for(const s of n.frame.agentRefs??[])s.agentId!==""&&e.push(s.agentId)}}return e}/**
24
+ * @license lucide-react v1.76.0 - ISC
25
+ *
26
+ * This source code is licensed under the ISC license.
27
+ * See the LICENSE file in the root directory of this source tree.
28
+ */const Zp=t=>(t.match(/\d+[xX]\d+|[A-Z]?[a-z]+|[A-Z]|\d+/g)??[]).join("-").toLowerCase();/**
29
+ * @license lucide-react v1.76.0 - ISC
30
+ *
31
+ * This source code is licensed under the ISC license.
32
+ * See the LICENSE file in the root directory of this source tree.
33
+ */function em(t,e,n=[]){if(e==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:Zp(t),size:24,node:e,...n.length>0?{aliases:n}:{}}}/**
34
+ * @license lucide-react v1.76.0 - ISC
35
+ *
36
+ * This source code is licensed under the ISC license.
37
+ * See the LICENSE file in the root directory of this source tree.
38
+ */const tm=t=>{let e="",n=!1;for(const s of t){if(s==="-"||s==="_"||s<=" "){n=e.length>0;continue}e.length===0?e+=s.toLowerCase():e+=n?s.toUpperCase():s,n=!1}return e};/**
39
+ * @license lucide-react v1.76.0 - ISC
40
+ *
41
+ * This source code is licensed under the ISC license.
42
+ * See the LICENSE file in the root directory of this source tree.
43
+ */const nm=t=>{const e=tm(t);return e.charAt(0).toUpperCase()+e.slice(1)};/**
44
+ * @license lucide-react v1.76.0 - ISC
45
+ *
46
+ * This source code is licensed under the ISC license.
47
+ * See the LICENSE file in the root directory of this source tree.
48
+ */const Li=(...t)=>{const e=new Set;for(const n of t)if(typeof n=="string")for(const s of n.split(/\s+/))s&&e.add(s);return[...e].join(" ")};/**
49
+ * @license lucide-react v1.76.0 - ISC
50
+ *
51
+ * This source code is licensed under the ISC license.
52
+ * See the LICENSE file in the root directory of this source tree.
53
+ */const Zt={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};/**
54
+ * @license lucide-react v1.76.0 - ISC
55
+ *
56
+ * This source code is licensed under the ISC license.
57
+ * See the LICENSE file in the root directory of this source tree.
58
+ */function oi(t){return t!=null}function sm(t,e={}){const n=e.attributeNames??{},s=f=>n[f]??f,i=t.size??t.width??Zt.width,r=t.size??t.height??Zt.height,o=t.aliases?.filter(f=>typeof f=="string"&&f.trim()!=="").map(f=>`lucide-${f}`)??[],a=[...t.name?[`lucide-${t.name}`]:[],...o],d=e.className?.split(" ").filter(Boolean)??[],l=e.includeDefaultClasses===!1?Li(...d):Li("lucide",...a,...d),c=e.absoluteStrokeWidth?Number(e.strokeWidth??Zt["stroke-width"])*Number(t.size??t.width??Zt.width)/Number(e.size??e.width??Zt.width):e.strokeWidth??Zt["stroke-width"];return["svg",{...Object.entries(Zt).reduce((f,[g,h])=>(f[s(g)]=h,f),{}),..."color"in e&&e.color&&{[s("stroke")]:e.color},..."size"in e&&oi(e.size)&&{[s("width")]:e.size,[s("height")]:e.size},..."width"in e&&oi(e.width)&&{[s("width")]:e.width},..."height"in e&&oi(e.height)&&{[s("height")]:e.height},[s("stroke-width")]:c,...l&&{[s("class")]:l},[s("viewBox")]:`0 0 ${i} ${r}`,...e.hasA11yProp===!1?{[s("aria-hidden")]:"true"}:{},..."attributes"in e&&e.attributes},t.node.map(f=>{const[g,h,v]=f,m=e.nonScalingStroke?{[s("vector-effect")]:"non-scaling-stroke",...h}:h;return v?[g,m,v]:[g,m]})]}/**
59
+ * @license lucide-react v1.76.0 - ISC
60
+ *
61
+ * This source code is licensed under the ISC license.
62
+ * See the LICENSE file in the root directory of this source tree.
63
+ */function im(t,e={}){return sm(t,{...e,attributeNames:{...e.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}/**
64
+ * @license lucide-react v1.76.0 - ISC
65
+ *
66
+ * This source code is licensed under the ISC license.
67
+ * See the LICENSE file in the root directory of this source tree.
68
+ */const rm=t=>{if(t==null||typeof t!="object")return!1;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&(e.startsWith("aria-")||e==="role"||e==="title")&&t[e]!=null)return!0;return!1},om=E.createContext({}),am=()=>E.useContext(om),dm=E.forwardRef(({color:t,size:e,width:n,height:s,strokeWidth:i,absoluteStrokeWidth:r,nonScalingStroke:o,className:a="",children:d,iconNode:l=[],icon:c={node:l,aliases:[],size:24},...u},f)=>{const{size:g=24,strokeWidth:h=2,absoluteStrokeWidth:v=!1,nonScalingStroke:m=!1,color:p="currentColor",className:k=""}=am()??{},S=!!d||rm(u),[w,x,b=[]]=im(c,{color:t??p,width:n??e??g,height:s??e??g,strokeWidth:i??h,absoluteStrokeWidth:r??v,nonScalingStroke:o??m,className:Li(k,a),hasA11yProp:S,attributes:u});return E.createElement(w,{ref:f,...x},[...b.map(([_,C])=>E.createElement(_,C)),...Array.isArray(d)?d:[d]])});/**
69
+ * @license lucide-react v1.76.0 - ISC
70
+ *
71
+ * This source code is licensed under the ISC license.
72
+ * See the LICENSE file in the root directory of this source tree.
73
+ */function Q(t,e=[],n=[]){const s=typeof t=="string"?em(t,e,n):t,i=E.forwardRef(({className:r,...o},a)=>E.createElement(dm,{ref:a,icon:s,className:r,...o}));return s.name&&(i.displayName=nm(s.name)),i}/**
74
+ * @license lucide-react v1.76.0 - ISC
75
+ *
76
+ * This source code is licensed under the ISC license.
77
+ * See the LICENSE file in the root directory of this source tree.
78
+ */const hd={name:"archive-arrow-up",size:24,node:[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]],aliases:["archive-restore"]};hd.node;const cm=Q(hd);/**
79
+ * @license lucide-react v1.76.0 - ISC
80
+ *
81
+ * This source code is licensed under the ISC license.
82
+ * See the LICENSE file in the root directory of this source tree.
83
+ */const pd={name:"archive",size:24,node:[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]};pd.node;const lm=Q(pd);/**
84
+ * @license lucide-react v1.76.0 - ISC
85
+ *
86
+ * This source code is licensed under the ISC license.
87
+ * See the LICENSE file in the root directory of this source tree.
88
+ */const md={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};md.node;const um=Q(md);/**
89
+ * @license lucide-react v1.76.0 - ISC
90
+ *
91
+ * This source code is licensed under the ISC license.
92
+ * See the LICENSE file in the root directory of this source tree.
93
+ */const gd={name:"arrow-left",size:24,node:[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]};gd.node;const fm=Q(gd);/**
94
+ * @license lucide-react v1.76.0 - ISC
95
+ *
96
+ * This source code is licensed under the ISC license.
97
+ * See the LICENSE file in the root directory of this source tree.
98
+ */const vd={name:"arrow-right",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]};vd.node;const hm=Q(vd);/**
99
+ * @license lucide-react v1.76.0 - ISC
100
+ *
101
+ * This source code is licensed under the ISC license.
102
+ * See the LICENSE file in the root directory of this source tree.
103
+ */const yd={name:"arrow-up-right",size:24,node:[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]]};yd.node;const pm=Q(yd);/**
104
+ * @license lucide-react v1.76.0 - ISC
105
+ *
106
+ * This source code is licensed under the ISC license.
107
+ * See the LICENSE file in the root directory of this source tree.
108
+ */const kd={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};kd.node;const mm=Q(kd);/**
109
+ * @license lucide-react v1.76.0 - ISC
110
+ *
111
+ * This source code is licensed under the ISC license.
112
+ * See the LICENSE file in the root directory of this source tree.
113
+ */const Id={name:"bell",size:24,node:[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]]};Id.node;const gm=Q(Id);/**
114
+ * @license lucide-react v1.76.0 - ISC
115
+ *
116
+ * This source code is licensed under the ISC license.
117
+ * See the LICENSE file in the root directory of this source tree.
118
+ */const wd={name:"chart-column",size:24,node:[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],aliases:["bar-chart-3"]};wd.node;const vm=Q(wd);/**
119
+ * @license lucide-react v1.76.0 - ISC
120
+ *
121
+ * This source code is licensed under the ISC license.
122
+ * See the LICENSE file in the root directory of this source tree.
123
+ */const bd={name:"check",size:24,node:[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]};bd.node;const ym=Q(bd);/**
124
+ * @license lucide-react v1.76.0 - ISC
125
+ *
126
+ * This source code is licensed under the ISC license.
127
+ * See the LICENSE file in the root directory of this source tree.
128
+ */const Sd={name:"chevron-right",size:24,node:[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]};Sd.node;const km=Q(Sd);/**
129
+ * @license lucide-react v1.76.0 - ISC
130
+ *
131
+ * This source code is licensed under the ISC license.
132
+ * See the LICENSE file in the root directory of this source tree.
133
+ */const xd={name:"circle-pause",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]],aliases:["pause-circle"]};xd.node;const Im=Q(xd);/**
134
+ * @license lucide-react v1.76.0 - ISC
135
+ *
136
+ * This source code is licensed under the ISC license.
137
+ * See the LICENSE file in the root directory of this source tree.
138
+ */const _d={name:"circle-play",size:24,node:[["path",{d:"M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z",key:"kmsa83"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],aliases:["play-circle"]};_d.node;const wm=Q(_d);/**
139
+ * @license lucide-react v1.76.0 - ISC
140
+ *
141
+ * This source code is licensed under the ISC license.
142
+ * See the LICENSE file in the root directory of this source tree.
143
+ */const Td={name:"circle-question-mark",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9 9.5a3 2.5 0 016 0c0 2-2 2-3 3.5",key:"1awbb0"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["help-circle","circle-help"]};Td.node;const bm=Q(Td);/**
144
+ * @license lucide-react v1.76.0 - ISC
145
+ *
146
+ * This source code is licensed under the ISC license.
147
+ * See the LICENSE file in the root directory of this source tree.
148
+ */const Cd={name:"clock",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]]};Cd.node;const Sm=Q(Cd);/**
149
+ * @license lucide-react v1.76.0 - ISC
150
+ *
151
+ * This source code is licensed under the ISC license.
152
+ * See the LICENSE file in the root directory of this source tree.
153
+ */const Rd={name:"columns-3",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],aliases:["panels-left-right"]};Rd.node;const xm=Q(Rd);/**
154
+ * @license lucide-react v1.76.0 - ISC
155
+ *
156
+ * This source code is licensed under the ISC license.
157
+ * See the LICENSE file in the root directory of this source tree.
158
+ */const Ad={name:"compass",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16.24 7.76-1.804 5.411a2 2 0 0 1-1.265 1.265L7.76 16.24l1.804-5.411a2 2 0 0 1 1.265-1.265z",key:"9ktpf1"}]]};Ad.node;const _m=Q(Ad);/**
159
+ * @license lucide-react v1.76.0 - ISC
160
+ *
161
+ * This source code is licensed under the ISC license.
162
+ * See the LICENSE file in the root directory of this source tree.
163
+ */const Md={name:"copy",size:24,node:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]};Md.node;const Tm=Q(Md);/**
164
+ * @license lucide-react v1.76.0 - ISC
165
+ *
166
+ * This source code is licensed under the ISC license.
167
+ * See the LICENSE file in the root directory of this source tree.
168
+ */const Pd={name:"corner-down-right",size:24,node:[["path",{d:"m15 10 5 5-5 5",key:"qqa56n"}],["path",{d:"M4 4v7a4 4 0 0 0 4 4h12",key:"z08zvw"}]]};Pd.node;const Cm=Q(Pd);/**
169
+ * @license lucide-react v1.76.0 - ISC
170
+ *
171
+ * This source code is licensed under the ISC license.
172
+ * See the LICENSE file in the root directory of this source tree.
173
+ */const Ed={name:"cpu",size:24,node:[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]]};Ed.node;const Rm=Q(Ed);/**
174
+ * @license lucide-react v1.76.0 - ISC
175
+ *
176
+ * This source code is licensed under the ISC license.
177
+ * See the LICENSE file in the root directory of this source tree.
178
+ */const Od={name:"ellipsis",size:24,node:[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],aliases:["more-horizontal"]};Od.node;const Am=Q(Od);/**
179
+ * @license lucide-react v1.76.0 - ISC
180
+ *
181
+ * This source code is licensed under the ISC license.
182
+ * See the LICENSE file in the root directory of this source tree.
183
+ */const Dd={name:"external-link",size:24,node:[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]};Dd.node;const Mm=Q(Dd);/**
184
+ * @license lucide-react v1.76.0 - ISC
185
+ *
186
+ * This source code is licensed under the ISC license.
187
+ * See the LICENSE file in the root directory of this source tree.
188
+ */const qd={name:"eye-off",size:24,node:[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]};qd.node;const Pm=Q(qd);/**
189
+ * @license lucide-react v1.76.0 - ISC
190
+ *
191
+ * This source code is licensed under the ISC license.
192
+ * See the LICENSE file in the root directory of this source tree.
193
+ */const Fd={name:"eye",size:24,node:[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};Fd.node;const Em=Q(Fd);/**
194
+ * @license lucide-react v1.76.0 - ISC
195
+ *
196
+ * This source code is licensed under the ISC license.
197
+ * See the LICENSE file in the root directory of this source tree.
198
+ */const Nd={name:"file-text",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]};Nd.node;const Om=Q(Nd);/**
199
+ * @license lucide-react v1.76.0 - ISC
200
+ *
201
+ * This source code is licensed under the ISC license.
202
+ * See the LICENSE file in the root directory of this source tree.
203
+ */const $d={name:"file",size:24,node:[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]]};$d.node;const Dm=Q($d);/**
204
+ * @license lucide-react v1.76.0 - ISC
205
+ *
206
+ * This source code is licensed under the ISC license.
207
+ * See the LICENSE file in the root directory of this source tree.
208
+ */const jd={name:"folder",size:24,node:[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]};jd.node;const qm=Q(jd);/**
209
+ * @license lucide-react v1.76.0 - ISC
210
+ *
211
+ * This source code is licensed under the ISC license.
212
+ * See the LICENSE file in the root directory of this source tree.
213
+ */const Bd={name:"funnel",size:24,node:[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],aliases:["filter"]};Bd.node;const Fm=Q(Bd);/**
214
+ * @license lucide-react v1.76.0 - ISC
215
+ *
216
+ * This source code is licensed under the ISC license.
217
+ * See the LICENSE file in the root directory of this source tree.
218
+ */const Ld={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};Ld.node;const Nm=Q(Ld);/**
219
+ * @license lucide-react v1.76.0 - ISC
220
+ *
221
+ * This source code is licensed under the ISC license.
222
+ * See the LICENSE file in the root directory of this source tree.
223
+ */const Hd={name:"globe",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]};Hd.node;const $m=Q(Hd);/**
224
+ * @license lucide-react v1.76.0 - ISC
225
+ *
226
+ * This source code is licensed under the ISC license.
227
+ * See the LICENSE file in the root directory of this source tree.
228
+ */const zd={name:"grip-vertical",size:24,node:[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]};zd.node;const jm=Q(zd);/**
229
+ * @license lucide-react v1.76.0 - ISC
230
+ *
231
+ * This source code is licensed under the ISC license.
232
+ * See the LICENSE file in the root directory of this source tree.
233
+ */const Wd={name:"hash",size:24,node:[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]};Wd.node;const Bm=Q(Wd);/**
234
+ * @license lucide-react v1.76.0 - ISC
235
+ *
236
+ * This source code is licensed under the ISC license.
237
+ * See the LICENSE file in the root directory of this source tree.
238
+ */const Ud={name:"layers-2",size:24,node:[["path",{d:"M13 13.74a2 2 0 0 1-2 0L2.5 8.87a1 1 0 0 1 0-1.74L11 2.26a2 2 0 0 1 2 0l8.5 4.87a1 1 0 0 1 0 1.74z",key:"15q6uc"}],["path",{d:"m20 14.285 1.5.845a1 1 0 0 1 0 1.74L13 21.74a2 2 0 0 1-2 0l-8.5-4.87a1 1 0 0 1 0-1.74l1.5-.845",key:"byia6g"}]]};Ud.node;const Lm=Q(Ud);/**
239
+ * @license lucide-react v1.76.0 - ISC
240
+ *
241
+ * This source code is licensed under the ISC license.
242
+ * See the LICENSE file in the root directory of this source tree.
243
+ */const Vd={name:"lightbulb",size:24,node:[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]};Vd.node;const Hm=Q(Vd);/**
244
+ * @license lucide-react v1.76.0 - ISC
245
+ *
246
+ * This source code is licensed under the ISC license.
247
+ * See the LICENSE file in the root directory of this source tree.
248
+ */const Kd={name:"list",size:24,node:[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]};Kd.node;const zm=Q(Kd);/**
249
+ * @license lucide-react v1.76.0 - ISC
250
+ *
251
+ * This source code is licensed under the ISC license.
252
+ * See the LICENSE file in the root directory of this source tree.
253
+ */const Gd={name:"lock",size:24,node:[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]};Gd.node;const Wm=Q(Gd);/**
254
+ * @license lucide-react v1.76.0 - ISC
255
+ *
256
+ * This source code is licensed under the ISC license.
257
+ * See the LICENSE file in the root directory of this source tree.
258
+ */const Qd={name:"maximize-2",size:24,node:[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]};Qd.node;const Um=Q(Qd);/**
259
+ * @license lucide-react v1.76.0 - ISC
260
+ *
261
+ * This source code is licensed under the ISC license.
262
+ * See the LICENSE file in the root directory of this source tree.
263
+ */const Jd={name:"menu",size:24,node:[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]]};Jd.node;const Vm=Q(Jd);/**
264
+ * @license lucide-react v1.76.0 - ISC
265
+ *
266
+ * This source code is licensed under the ISC license.
267
+ * See the LICENSE file in the root directory of this source tree.
268
+ */const Yd={name:"message-square",size:24,node:[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]]};Yd.node;const Km=Q(Yd);/**
269
+ * @license lucide-react v1.76.0 - ISC
270
+ *
271
+ * This source code is licensed under the ISC license.
272
+ * See the LICENSE file in the root directory of this source tree.
273
+ */const Xd={name:"minimize-2",size:24,node:[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]]};Xd.node;const Gm=Q(Xd);/**
274
+ * @license lucide-react v1.76.0 - ISC
275
+ *
276
+ * This source code is licensed under the ISC license.
277
+ * See the LICENSE file in the root directory of this source tree.
278
+ */const Zd={name:"minus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}]]};Zd.node;const Qm=Q(Zd);/**
279
+ * @license lucide-react v1.76.0 - ISC
280
+ *
281
+ * This source code is licensed under the ISC license.
282
+ * See the LICENSE file in the root directory of this source tree.
283
+ */const ec={name:"notebook-text",size:24,node:[["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["path",{d:"M9.5 8h5",key:"11mslq"}],["path",{d:"M9.5 12H16",key:"ktog6x"}],["path",{d:"M9.5 16H14",key:"p1seyn"}]]};ec.node;const Jm=Q(ec);/**
284
+ * @license lucide-react v1.76.0 - ISC
285
+ *
286
+ * This source code is licensed under the ISC license.
287
+ * See the LICENSE file in the root directory of this source tree.
288
+ */const tc={name:"panel-right",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]};tc.node;const Ym=Q(tc);/**
289
+ * @license lucide-react v1.76.0 - ISC
290
+ *
291
+ * This source code is licensed under the ISC license.
292
+ * See the LICENSE file in the root directory of this source tree.
293
+ */const nc={name:"pencil",size:24,node:[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]};nc.node;const Xm=Q(nc);/**
294
+ * @license lucide-react v1.76.0 - ISC
295
+ *
296
+ * This source code is licensed under the ISC license.
297
+ * See the LICENSE file in the root directory of this source tree.
298
+ */const sc={name:"pin",size:24,node:[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]};sc.node;const Zm=Q(sc);/**
299
+ * @license lucide-react v1.76.0 - ISC
300
+ *
301
+ * This source code is licensed under the ISC license.
302
+ * See the LICENSE file in the root directory of this source tree.
303
+ */const ic={name:"plus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]};ic.node;const eg=Q(ic);/**
304
+ * @license lucide-react v1.76.0 - ISC
305
+ *
306
+ * This source code is licensed under the ISC license.
307
+ * See the LICENSE file in the root directory of this source tree.
308
+ */const rc={name:"puzzle",size:24,node:[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]]};rc.node;const tg=Q(rc);/**
309
+ * @license lucide-react v1.76.0 - ISC
310
+ *
311
+ * This source code is licensed under the ISC license.
312
+ * See the LICENSE file in the root directory of this source tree.
313
+ */const oc={name:"quote",size:24,node:[["path",{d:"M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"rib7q0"}],["path",{d:"M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z",key:"1ymkrd"}]]};oc.node;const ng=Q(oc);/**
314
+ * @license lucide-react v1.76.0 - ISC
315
+ *
316
+ * This source code is licensed under the ISC license.
317
+ * See the LICENSE file in the root directory of this source tree.
318
+ */const ac={name:"refresh-cw",size:24,node:[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]};ac.node;const sg=Q(ac);/**
319
+ * @license lucide-react v1.76.0 - ISC
320
+ *
321
+ * This source code is licensed under the ISC license.
322
+ * See the LICENSE file in the root directory of this source tree.
323
+ */const dc={name:"search",size:24,node:[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]};dc.node;const ig=Q(dc);/**
324
+ * @license lucide-react v1.76.0 - ISC
325
+ *
326
+ * This source code is licensed under the ISC license.
327
+ * See the LICENSE file in the root directory of this source tree.
328
+ */const cc={name:"settings",size:24,node:[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]};cc.node;const rg=Q(cc);/**
329
+ * @license lucide-react v1.76.0 - ISC
330
+ *
331
+ * This source code is licensed under the ISC license.
332
+ * See the LICENSE file in the root directory of this source tree.
333
+ */const lc={name:"shield",size:24,node:[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]};lc.node;const og=Q(lc);/**
334
+ * @license lucide-react v1.76.0 - ISC
335
+ *
336
+ * This source code is licensed under the ISC license.
337
+ * See the LICENSE file in the root directory of this source tree.
338
+ */const uc={name:"sliders-horizontal",size:24,node:[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]};uc.node;const ag=Q(uc);/**
339
+ * @license lucide-react v1.76.0 - ISC
340
+ *
341
+ * This source code is licensed under the ISC license.
342
+ * See the LICENSE file in the root directory of this source tree.
343
+ */const fc={name:"smartphone",size:24,node:[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]]};fc.node;const dg=Q(fc);/**
344
+ * @license lucide-react v1.76.0 - ISC
345
+ *
346
+ * This source code is licensed under the ISC license.
347
+ * See the LICENSE file in the root directory of this source tree.
348
+ */const hc={name:"sparkle",size:24,node:[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}]]};hc.node;const cg=Q(hc);/**
349
+ * @license lucide-react v1.76.0 - ISC
350
+ *
351
+ * This source code is licensed under the ISC license.
352
+ * See the LICENSE file in the root directory of this source tree.
353
+ */const pc={name:"sparkles",size:24,node:[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],aliases:["stars"]};pc.node;const lg=Q(pc);/**
354
+ * @license lucide-react v1.76.0 - ISC
355
+ *
356
+ * This source code is licensed under the ISC license.
357
+ * See the LICENSE file in the root directory of this source tree.
358
+ */const mc={name:"square-menu",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 8h10",key:"1jw688"}],["path",{d:"M7 12h10",key:"b7w52i"}],["path",{d:"M7 16h10",key:"wp8him"}]],aliases:["menu-square"]};mc.node;const ug=Q(mc);/**
359
+ * @license lucide-react v1.76.0 - ISC
360
+ *
361
+ * This source code is licensed under the ISC license.
362
+ * See the LICENSE file in the root directory of this source tree.
363
+ */const gc={name:"square-terminal",size:24,node:[["path",{d:"m7 11 2-2-2-2",key:"1lz0vl"}],["path",{d:"M11 13h4",key:"1p7l4v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}]],aliases:["terminal-square"]};gc.node;const fg=Q(gc);/**
364
+ * @license lucide-react v1.76.0 - ISC
365
+ *
366
+ * This source code is licensed under the ISC license.
367
+ * See the LICENSE file in the root directory of this source tree.
368
+ */const vc={name:"square-user-round",size:24,node:[["path",{d:"M18 21a6 6 0 0 0-12 0",key:"kaz2du"}],["circle",{cx:"12",cy:"11",r:"4",key:"1gt34v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],aliases:["user-square-2"]};vc.node;const hg=Q(vc);/**
369
+ * @license lucide-react v1.76.0 - ISC
370
+ *
371
+ * This source code is licensed under the ISC license.
372
+ * See the LICENSE file in the root directory of this source tree.
373
+ */const yc={name:"square",size:24,node:[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]};yc.node;const pg=Q(yc);/**
374
+ * @license lucide-react v1.76.0 - ISC
375
+ *
376
+ * This source code is licensed under the ISC license.
377
+ * See the LICENSE file in the root directory of this source tree.
378
+ */const kc={name:"star",size:24,node:[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]};kc.node;const qo=Q(kc);/**
379
+ * @license lucide-react v1.76.0 - ISC
380
+ *
381
+ * This source code is licensed under the ISC license.
382
+ * See the LICENSE file in the root directory of this source tree.
383
+ */const Ic={name:"target",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]};Ic.node;const mg=Q(Ic);/**
384
+ * @license lucide-react v1.76.0 - ISC
385
+ *
386
+ * This source code is licensed under the ISC license.
387
+ * See the LICENSE file in the root directory of this source tree.
388
+ */const wc={name:"triangle-exclamation-point",size:24,node:[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["alert-triangle","triangle-alert"]};wc.node;const gg=Q(wc);/**
389
+ * @license lucide-react v1.76.0 - ISC
390
+ *
391
+ * This source code is licensed under the ISC license.
392
+ * See the LICENSE file in the root directory of this source tree.
393
+ */const bc={name:"undo-2",size:24,node:[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]};bc.node;const vg=Q(bc);/**
394
+ * @license lucide-react v1.76.0 - ISC
395
+ *
396
+ * This source code is licensed under the ISC license.
397
+ * See the LICENSE file in the root directory of this source tree.
398
+ */const Sc={name:"wrench",size:24,node:[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]]};Sc.node;const yg=Q(Sc);/**
399
+ * @license lucide-react v1.76.0 - ISC
400
+ *
401
+ * This source code is licensed under the ISC license.
402
+ * See the LICENSE file in the root directory of this source tree.
403
+ */const xc={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};xc.node;const Fo=Q(xc),_c={12:"h-3 w-3",14:"h-3.5 w-3.5",16:"h-4 w-4"},kg={read:{component:Dm},search:{component:ig},edit:{component:Xm},terminal:{component:fg},web:{component:$m},agent:{component:Lm},skill:{component:cg},plan:{component:zm},task:{component:wm},goal:{component:mg},memory:{component:lg},think:{component:Hm},system:{component:ug},clock:{component:Sm},gate:{component:og},ask:{component:Km},file:{component:Om},tool:{component:yg},check:{component:ym},cross:{component:Fo},dash:{component:Qm},warning:{component:gg},info:{component:bm},hold:{component:Im},chevron:{component:km},close:{component:Fo},menu:{component:Vm},more:{component:Am},plus:{component:eg},arrowRight:{component:hm},arrowDown:{component:um},external:{component:Mm},folder:{component:qm},panel:{component:Ym},filter:{component:Fm},sliders:{component:ag},pin:{component:Zm},board:{component:xm},usage:{component:vm},notes:{component:Jm},settings:{component:rg},arrowLeft:{component:fm},arrowUp:{component:mm},arrowUpRight:{component:pm},expand:{component:Um},collapse:{component:Gm},grip:{component:jm},stop:{component:pg,fill:"currentColor"},quote:{component:ng},star:{component:qo},starFilled:{component:qo,fill:"currentColor"},bell:{component:gm},branch:{component:Nm},eye:{component:Em},eyeOff:{component:Pm},copy:{component:Tm},refresh:{component:sg},archive:{component:lm},archiveRestore:{component:cm},undo:{component:vg},thread:{component:Cm},room:{component:Bm},persona:{component:hg},compass:{component:_m},smartphone:{component:dg},plugin:{component:tg},lock:{component:Wm},cpu:{component:Rm}},No={dot:A.jsx("circle",{cx:"8",cy:"8",r:"3",fill:"currentColor",stroke:"none"}),ring:A.jsx("circle",{cx:"8",cy:"8",r:"4.5"}),partial:A.jsxs(A.Fragment,{children:[A.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),A.jsx("path",{d:"M8 8V2.2A5.8 5.8 0 0 1 13.8 8z",fill:"currentColor"})]}),profileMain:A.jsxs(A.Fragment,{children:[A.jsx("path",{d:"M7 2.5 8.3 6.2 12 7.5 8.3 8.8 7 12.5 5.7 8.8 2 7.5 5.7 6.2z"}),A.jsx("path",{d:"M12.2 2.5v2.4M11 3.7h2.4"})]}),profileCode:A.jsx("path",{d:"M5.2 5.2 2.3 8l2.9 2.8M10.8 5.2 13.7 8l-2.9 2.8M9 3.6 7 12.4"}),profileFrontend:A.jsxs(A.Fragment,{children:[A.jsx("rect",{x:"2.3",y:"3",width:"11.4",height:"10",rx:"1.7"}),A.jsx("path",{d:"M2.3 6.3h11.4M6.2 6.3V13"})]}),profileResearch:A.jsxs(A.Fragment,{children:[A.jsx("path",{d:"M2.3 4.1c1.9-.5 3.9-.2 5.7.9 1.8-1.1 3.8-1.4 5.7-.9v8.3c-1.9-.5-3.9-.2-5.7.9-1.8-1.1-3.8-1.4-5.7-.9z"}),A.jsx("path",{d:"M8 5v8.3"})]}),profileReview:A.jsxs(A.Fragment,{children:[A.jsx("path",{d:"M8 2.3 13 4.1v3.6c0 3-2.1 5.1-5 6.1-2.9-1-5-3.1-5-6.1V4.1z"}),A.jsx("path",{d:"m5.8 8 1.6 1.6 3-3"})]}),profileThink:A.jsxs(A.Fragment,{children:[A.jsx("path",{d:"M8 2.2 13.3 8 8 13.8 2.7 8z"}),A.jsx("path",{d:"M8 2.2 6.1 8 8 13.8M2.7 8h10.6"})]}),profileOperator:A.jsxs(A.Fragment,{children:[A.jsx("path",{d:"M13.4 7.8V4.4a1.5 1.5 0 0 0-1.5-1.5H4.1a1.5 1.5 0 0 0-1.5 1.5v5.8a1.5 1.5 0 0 0 1.5 1.5h3.7"}),A.jsx("path",{d:"M2.6 5.6h10.8"}),A.jsx("path",{d:"m9.4 8.6 1.1 4.9 1.1-1.7 1.9-.5z"})]}),profileWorker:A.jsxs(A.Fragment,{children:[A.jsx("path",{d:"M8 2.6 13.5 5.4 8 8.2 2.5 5.4z"}),A.jsx("path",{d:"m2.5 8.4 5.5 2.8 5.5-2.8"}),A.jsx("path",{d:"m2.5 11.1 5.5 2.7 5.5-2.7"})]}),profileWriter:A.jsxs(A.Fragment,{children:[A.jsx("path",{d:"M8 2.3 11.8 8.4 9.9 13.5H6.1L4.2 8.4z"}),A.jsx("path",{d:"M8 2.3v5.3"}),A.jsx("circle",{cx:"8",cy:"8.5",r:"0.9"})]}),profileDirector:A.jsxs(A.Fragment,{children:[A.jsx("path",{d:"M2.5 5.5V3.8a1.2 1.2 0 0 1 1.2-1.2h1.8M10.5 2.6h1.8a1.2 1.2 0 0 1 1.2 1.2v1.7M13.5 10.5v1.7a1.2 1.2 0 0 1-1.2 1.2h-1.8M5.5 13.4H3.7a1.2 1.2 0 0 1-1.2-1.2v-1.7"}),A.jsx("polygon",{points:"6.7,5.8 10.5,8 6.7,10.2"})]})};function Hi({name:t,size:e=14,className:n=""}){const i=`shrink-0 ${/(^|\s)h-/.test(n)?"":_c[e]} ${n}`.trim();if(Object.hasOwn(No,t))return A.jsx("svg",{"aria-hidden":!0,"data-icon":t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.35,strokeLinecap:"round",strokeLinejoin:"round",className:i,children:No[t]});const r=kg[t],o=r.component;return A.jsx(o,{"aria-hidden":"true","data-icon":t,strokeWidth:1.75,absoluteStrokeWidth:!0,fill:r.fill??"none",className:i})}function Ig({open:t,size:e=12,className:n="text-ink-faint"}){return A.jsx(Hi,{name:"chevron",size:e,className:`transition-transform duration-[var(--kiki-motion-quick)] ease-out motion-reduce:transition-none ${t?"rotate-90":""} ${n}`})}function wg({label:t,size:e=14}){return A.jsxs("svg",{role:"img","aria-label":t,viewBox:"0 0 16 16",fill:"none",className:`spinner shrink-0 text-ink-soft ${_c[e]}`,children:[A.jsx("circle",{cx:"8",cy:"8",r:"5.8",stroke:"currentColor",strokeOpacity:"0.22",strokeWidth:1.35}),A.jsx("path",{d:"M13.8 8A5.8 5.8 0 0 0 8 2.2",stroke:"currentColor",strokeWidth:1.35,strokeLinecap:"round"})]})}function Qv({state:t,labels:e,title:n}){switch(t){case"running":return A.jsx(wg,{label:e.running});case"failed":return A.jsx("span",{role:"img","aria-label":e.failed,title:n,"data-outcome":"failed",className:"text-danger",children:A.jsx(Hi,{name:"cross"})});case"stopped":return A.jsx("span",{role:"img","aria-label":e.stopped,title:n,"data-outcome":"stopped",className:"text-amber-rule",children:A.jsx(Hi,{name:"dash"})});case"done":return A.jsx("span",{className:"sr-only",children:e.done})}}const bg={smartphone:"smartphone",phone:"smartphone",mobile:"smartphone",device:"smartphone",plugin:"plugin",plug:"plugin",puzzle:"plugin",terminal:"terminal",board:"board",grid:"board",web:"web",globe:"web",browser:"compass",compass:"compass",file:"file",read:"read",notes:"notes",search:"search",edit:"edit",clock:"clock",usage:"usage",settings:"settings",sliders:"sliders",tool:"tool",panel:"panel",folder:"folder",branch:"branch",star:"star"};function Jv(t){const{icon:e,pluginId:n,panelId:s,fallback:i="star"}=t;if(typeof e=="string"){const o=e.trim().toLowerCase();if(o!==""){const a=bg[o];if(a!==void 0)return a}}const r=`${n??""}:${s??""}`.toLowerCase();return r.includes("phone")||r.includes("mobile")||r.includes("android")||r.includes("ios")?"smartphone":i}function Jn({size:t="md",life:e,echo:n}){const s=il("wordmark",e),i=e==="idle"?void 0:e,r=t==="xl"?"text-[44px] sm:text-[56px]":t==="lg"?"text-4xl":"text-[22px]",o=t==="xl"?"h-2.5 w-2.5 sm:h-3 sm:w-3":t==="lg"?"h-2 w-2":"h-1.5 w-1.5";return A.jsxs("span",{className:"inline-flex items-baseline select-none","aria-label":"kiki",children:[A.jsx("span",{className:`font-display ${r} leading-none font-semibold tracking-tight text-ink`,style:{fontVariationSettings:t==="xl"?'"opsz" 60':'"opsz" 40'},children:"kiki"}),A.jsx("span",{className:`kiki-wordmark-echo inline-block ${t==="xl"?"ml-1":"ml-[3px]"}`,"data-echo":n===void 0?void 0:n===0?"arrive":n%2===0?"a":"b",children:A.jsx("span",{"data-life":i,"data-life-changed":s?"":void 0,className:`kiki-wordmark-dot block ${o} translate-y-[-1px] rounded-full bg-accent`})})]})}function Yv({className:t=""}){return A.jsx("span",{"aria-hidden":!0,className:`inline-block h-2.5 w-2.5 rounded-[3px] bg-accent ${t}`})}function Sg({problem:t,onRetry:e}){const{t:n}=on(),[s,i]=E.useState(!1),r=na();return A.jsxs("div",{className:"px-7 pt-6 pb-7","data-web-link-problem":t,children:[A.jsx(Jn,{size:"lg"}),A.jsx("p",{className:"mt-3 text-[14px] font-medium text-ink",children:n(t==="retargeted"?"connect.webLinkRetargeted":"connect.webLinkRefused")}),A.jsx("p",{className:"mt-1.5 max-w-[46ch] text-[13px] leading-relaxed text-ink-soft",children:n(t==="retargeted"?"connect.webLinkRetargetedBody":"connect.webLinkRefusedBody")}),r!==null?A.jsx("a",{href:r,"data-web-link-app-connect":!0,className:"mt-5 block w-full rounded-md bg-accent px-3 py-2 text-center text-[14px] font-medium text-on-accent transition-colors hover:bg-accent-deep focus-visible:ring-2 focus-visible:ring-selected-ink/50 focus-visible:outline-none",children:n("connect.webLinkEnterNew")}):e!==void 0?A.jsx("button",{type:"button","data-web-link-retry":!0,onClick:e,className:"mt-5 w-full rounded-md bg-accent px-3 py-2 text-[14px] font-medium text-on-accent transition-colors hover:bg-accent-deep focus-visible:ring-2 focus-visible:ring-selected-ink/50 focus-visible:outline-none",children:n("connect.webLinkRetry")}):null,A.jsx("button",{type:"button","data-web-link-connect":!0,"aria-expanded":s,onClick:()=>{i(o=>!o)},className:"mt-3 w-full rounded-md px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:text-ink",children:n(s?"connect.webLinkHideConnect":"connect.webLinkUseConnect")})]})}function xg({initial:t,connecting:e,error:n,onConnect:s,onBack:i,desktopBoot:r,desktopFailure:o,onRetryDesktop:a,onCancelDesktopBoot:d,onConnectSsh:l,onSwitchLocal:c,sshProfile:u,webLink:f,onRetryWebLink:g,onRetryPaired:h,pairedAuthRevoked:v}){return c!==void 0?A.jsx($n,{children:o!==null?A.jsx($o,{failure:o,onRetry:a,onSwitchLocal:c}):A.jsx(Tg,{onSwitchLocal:c})}):r!==null?A.jsx($n,{children:A.jsx(Cg,{boot:r,onCancel:d})}):o!==null?A.jsx($n,{children:A.jsx($o,{failure:o,onRetry:a})}):f!==void 0?A.jsx($n,{children:A.jsx(Sg,{problem:f,onRetry:g})}):A.jsx($n,{children:A.jsx(Mg,{initial:t,connecting:e,error:n,onConnect:s,onBack:i,onRetryPaired:h,pairedAuthRevoked:v})})}function $n({children:t}){return A.jsx("div",{className:"flex h-full overflow-y-auto bg-paper px-4 py-4",children:A.jsx("div",{className:"anim-enter m-auto w-full max-w-[420px]",children:A.jsx("div",{className:"rounded-2xl border border-hairline bg-panel shadow-[0_1px_2px_rgba(28,25,23,0.04),0_12px_32px_-16px_rgba(28,25,23,0.12)]",children:t})})})}function _g(t){const[e,n]=E.useState(()=>Date.now());return E.useEffect(()=>{n(Date.now());const s=window.setInterval(()=>{n(Date.now())},1e3);return()=>{window.clearInterval(s)}},[t]),Math.max(0,Math.floor((e-t)/1e3))}function Tg({onSwitchLocal:t}){const{t:e}=on();return A.jsxs("div",{className:"px-7 pt-6 pb-7",children:[A.jsx(Jn,{size:"lg"}),A.jsx("p",{className:"mt-2 text-[13px] text-ink-soft",children:e("connect.sshChecking")}),A.jsx("button",{type:"button",onClick:t,className:"mt-5 w-full rounded-lg border border-hairline-strong bg-paper px-3 py-2 text-[13px] font-medium text-ink transition-colors hover:border-accent hover:text-ink",children:e("connect.switchLocal")})]})}function Cg({boot:t,onCancel:e}){const{t:n}=on(),s=_g(t.startedAtMs);return A.jsxs("div",{className:"px-7 pt-6 pb-7",children:[A.jsx(Jn,{size:"lg"}),A.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-soft",children:t.stage==="spawning"?n("connect.desktopBootingSpawning"):n("connect.desktopBootingWaiting")}),A.jsx("p",{className:"mt-1 font-mono text-[12px] text-ink-faint","aria-live":"polite",children:n("connect.desktopElapsed",{seconds:s})}),A.jsx("button",{type:"button",onClick:e,className:"mt-5 w-full rounded-lg border border-hairline-strong bg-paper px-3 py-2 text-[13px] font-medium text-ink transition-colors hover:border-accent hover:text-ink",children:n("connect.desktopCancel")})]})}function $o({failure:t,onRetry:e,onSwitchLocal:n}){const{t:s}=on(),[i,r]=E.useState(!1);E.useEffect(()=>{if(!i)return;const a=window.setTimeout(()=>{r(!1)},1500);return()=>{window.clearTimeout(a)}},[i]);const o=async()=>{try{await navigator.clipboard.writeText(t.message),r(!0)}catch{}};return A.jsxs("div",{className:"px-7 pt-6 pb-7",children:[A.jsx(Jn,{size:"lg"}),A.jsx("p",{className:"mt-2 text-[13px] font-semibold text-danger",children:s(n===void 0?"connect.desktopFailedTitle":"connect.sshFailedTitle")}),A.jsx("pre",{className:"mt-3 max-h-56 overflow-auto whitespace-pre-wrap rounded-lg border border-danger/30 bg-danger/5 px-3 py-2 font-mono text-[12px] leading-relaxed text-danger",children:t.message}),t.logPath!==null?A.jsxs("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-soft",children:[s("connect.desktopLogPathLabel")," ",A.jsx("span",{className:"font-mono",children:t.logPath})]}):null,A.jsxs("div",{className:"mt-4 flex gap-2",children:[A.jsx("button",{type:"button",onClick:n??e,className:"flex-1 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-on-accent transition-colors hover:bg-accent-deep",children:s(n===void 0?"connect.desktopRetry":"connect.switchLocal")}),A.jsx("button",{type:"button",onClick:()=>{o()},className:"flex-1 rounded-lg border border-hairline-strong bg-paper px-3 py-2 text-[13px] font-medium text-ink transition-colors hover:border-accent hover:text-ink",children:s(i?"connect.desktopCopied":"connect.desktopCopyDiagnostics")})]})]})}function Rg(t=globalThis.location?.hostname){if(t===void 0)return!0;const e=t.toLowerCase();return e==="localhost"||e.endsWith(".localhost")||e==="::1"||e==="[::1]"||/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(e)}function Ag({error:t}){const{t:e}=on(),n=/\(code -[12]\)$/.test(t);return A.jsxs("div",{role:"alert",className:"mb-4 rounded-md border-l-2 border-danger bg-danger/5 px-3 py-2 text-[13px] text-danger",children:[A.jsx("p",{children:e(n?"connect.errorUnreachable":"connect.errorFailed")}),A.jsxs("details",{className:"mt-1 text-[12px] text-ink-soft","data-connect-error-details":!0,children:[A.jsx("summary",{className:"cursor-pointer select-none",children:e("connect.errorDetails")}),A.jsx("p",{className:"mt-1 break-words font-mono",children:t})]})]})}function Mg({initial:t,connecting:e,error:n,onConnect:s,onBack:i,onRetryPaired:r,pairedAuthRevoked:o}){const a=sa(),{t:d}=on(),l=na(),c=a.kind!=="browser"||Rg(),[u,f]=E.useState(t.url),[g,h]=E.useState(t.token),[v,m]=E.useState(!1),[p,k]=E.useState(t.url!==""||t.token!==""||l===null&&(n!==null||!c));E.useEffect(()=>{n!==null&&l===null&&k(!0)},[n,l]);const[S,w]=E.useState(!1),[x,b]=E.useState(null),_=N=>{N.preventDefault(),s({url:u.trim(),token:g.trim()})},C=async()=>{w(!0),b(null);try{const N=await a.connection.discover();if(N===null){b(d("connect.noneFound"));return}s(N.config,N.persist)}catch(N){b(a.kind==="tauri"?d("connect.desktopStartFailed",{detail:N instanceof Error?N.message:String(N)}):d("connect.detectNeedsDev"))}finally{w(!1)}},F=l!==null?o?"connect.shellAuthRevoked":e?"connect.shellConnecting":r!==void 0&&n!==null?"connect.shellUnreachable":"connect.shellTagline":c?"connect.tagline":"connect.taglineRemote";return A.jsxs("div",{className:"px-7 pt-6 pb-7",children:[A.jsx(Jn,{size:"lg"}),A.jsx("p",{className:"mt-3 font-display text-[18px] leading-snug text-ink-soft",children:d(F)}),A.jsxs("form",{onSubmit:_,className:"mt-6",children:[l!==null?A.jsxs("div",{className:"flex flex-col gap-2",children:[r!==void 0&&!o?A.jsx("button",{type:"button","data-app-shell-retry":!0,onClick:r,disabled:e,className:"w-full rounded-md bg-accent px-3 py-2 text-[14px] font-medium text-on-accent transition-colors hover:bg-accent-deep focus-visible:ring-2 focus-visible:ring-selected-ink/50 focus-visible:outline-none disabled:opacity-60",children:d(e?"connect.connecting":"app.reconnectNow")}):null,A.jsx("a",{href:l,"data-app-shell-connect":!0,className:"block w-full rounded-md border border-hairline-strong bg-paper px-3 py-2 text-center text-[13px] font-medium text-ink no-underline transition-colors hover:border-ink-faint focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none",children:d("connect.switchComputer")})]}):c?A.jsx("button",{type:"button","data-connect-detect":!0,onClick:()=>{C()},disabled:S||e,className:"w-full rounded-md bg-accent px-3 py-2 text-[14px] font-medium text-on-accent transition-colors hover:bg-accent-deep focus-visible:ring-2 focus-visible:ring-selected-ink/50 focus-visible:outline-none disabled:opacity-60",children:d(S?"connect.detecting":"connect.detect")}):null,x!==null?A.jsx("p",{role:"status",className:"mt-2 text-[13px] leading-relaxed text-ink-soft",children:x}):null,l===null?A.jsxs(A.Fragment,{children:[A.jsxs("button",{type:"button","aria-expanded":p,"aria-controls":"connect-manual",onClick:()=>{k(N=>!N)},className:"mt-5 flex items-center gap-1.5 rounded-md py-1 text-[13px] text-ink-soft transition-colors hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none",children:[A.jsx(Ig,{open:p,className:"text-current"}),d("connect.otherMachine")]}),A.jsxs("div",{id:"connect-manual",hidden:!p,className:"mt-3",children:[A.jsx("label",{htmlFor:"connect-server-url",className:"mb-1 block text-[12px] font-medium text-ink-soft",children:d("connect.serverUrl")}),A.jsx("input",{id:"connect-server-url",className:"mb-4 w-full rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[13px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent",placeholder:d("connect.urlPlaceholder",{target:"http://127.0.0.1:58627"}),value:u,onChange:N=>{f(N.target.value)},spellCheck:!1}),A.jsxs("label",{htmlFor:"connect-token",className:"mb-1 flex items-baseline justify-between gap-2 text-[12px] font-medium text-ink-soft",children:[d("connect.accessToken"),A.jsx("span",{title:d("connect.accessTokenHelp"),className:"cursor-help text-[12px] font-normal text-ink-faint underline decoration-dotted underline-offset-2",children:d("connect.accessTokenWhere")})]}),A.jsxs("div",{className:"mb-5 flex gap-2",children:[A.jsx("input",{id:"connect-token",className:"min-w-0 flex-1 rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[13px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent","aria-describedby":"connect-token-help",value:g,onChange:N=>{h(N.target.value)},spellCheck:!1,type:v?"text":"password"}),A.jsx("button",{type:"button",className:"rounded-lg border border-hairline px-3 text-[12px] text-ink-soft transition-colors hover:border-accent hover:text-ink","aria-label":`${d(v?"st.providers.hideKey":"st.providers.showKey")} ${d("connect.token")}`,onClick:()=>{m(N=>!N)},children:d(v?"st.providers.hideKey":"st.providers.showKey")})]}),A.jsx("p",{id:"connect-token-help",className:"sr-only",children:d("connect.accessTokenHelp")}),n!==null?A.jsx(Ag,{error:n}):null,A.jsx("button",{type:"submit",disabled:e,className:"w-full rounded-md border border-hairline-strong bg-paper px-3 py-2 text-[13px] font-medium text-ink transition-colors hover:border-ink-faint focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none disabled:opacity-60",children:d(e?"connect.connecting":"connect.connect")})]})]}):null,i!==void 0&&l===null?A.jsx("button",{type:"button",onClick:i,className:"mt-2 w-full rounded-lg px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:text-ink",children:d("connect.back")}):null]})]})}function Pg(t){return t==="app-shell"||t==="remote"}function Vn(t){if(typeof t!="object"||t===null)return!1;const e=t;if(e.code===40101||e.code==="40101")return!0;const n=typeof e.message=="string"?e.message:typeof e.msg=="string"?e.msg:"";return/local_owner_required/i.test(n)?!0:e.status===403&&/\b40101\b/.test(n)}const jo=new WeakMap;let Eg=0;function ai(t){if(t===null)return null;let e=jo.get(t);return e===void 0&&(e=++Eg,jo.set(t,e)),e}const Es={all:["portable-spaces"],sources:t=>["portable-spaces","sources",ai(t)],centerSources:t=>["portable-spaces","center-sources",ai(t)],inspect:(t,e,n="")=>["portable-spaces","inspect",ai(t),e===null?null:qg(e),n]};function Og(t){if(t instanceof mt){const e=t.reason===Rl;return new Ee({code:e?Ce.TIMEOUT:t.code,msg:e?t.message.replace("call timed out",ia("en","common.requestTimedOut")):t.message,data:t.data??null,details:t.details,request_id:t.requestId,source:t.source,reason:t.reason})}return t}function Dg(t){const e=n=>async(...s)=>{try{return await n(...s)}catch(i){throw Og(i)}};return{listSources:e(t.listSources.bind(t)),registerSource:e(t.registerSource.bind(t)),previewSubscribe:e(t.previewSubscribe.bind(t)),subscribe:e(t.subscribe.bind(t)),previewSource:e(t.previewSource.bind(t)),syncSubscription:e(t.syncSubscription.bind(t)),patchSource:e(t.patchSource.bind(t)),reorderSources:e(t.reorderSources.bind(t)),previewRemoveSource:e(t.previewRemoveSource.bind(t)),removeSource:e(t.removeSource.bind(t)),removeReviewedSource:e(t.removeReviewedSource.bind(t)),inspect:e(t.inspect.bind(t)),exportSpace:e(t.exportSpace.bind(t)),preview:e(t.preview.bind(t)),apply:e(t.apply.bind(t)),pack:e(t.pack.bind(t)),unpack:e(t.unpack.bind(t)),fork:e(t.fork.bind(t)),delta:e(t.delta.bind(t)),mutate:e(t.mutate.bind(t)),rekey:e(t.rekey.bind(t)),addRecipient:e(t.addRecipient.bind(t))}}const Bo=new WeakMap;function Tc(t){const e=t.portableSpaces;if(e!==void 0)return e;const n=t.klient?.rest?.portableSpaces;if(n===void 0)throw new Error("Portable spaces require an HTTP connection to the local Kiki server.");let s=Bo.get(n);return s===void 0&&(s=Dg(n),Bo.set(n,s)),s}function Xv(t){return Kn({queryKey:Es.centerSources(t),queryFn:({signal:e})=>{if(t===null)throw new Error("The local space connection is not ready.");return Tc(t).listSources({view:"center-v1",signal:e})},enabled:t!==null,staleTime:2e4,retry:!1})}function Zv(t,e,n){const s=`${n?.unlockNonce??0}:${e?.unlock?.passphrase?"pw":""}:${e?.unlock?.identity?"id":""}`;return Kn({queryKey:Es.inspect(t,e?.endpoint??null,s),queryFn:({signal:i})=>{if(t===null||e===null)throw new Error("Inspect input is unavailable.");return Tc(t).inspect(e,{signal:i})},enabled:(n?.enabled??!0)&&t!==null&&e!==null,staleTime:1e4,retry:!1})}function Os(t){if(typeof t=="object"&&t!==null&&typeof t.code=="number")return t.code;const e=t instanceof Error?t.message:String(t??""),n=/\(code (-?\d+)\)\s*$/u.exec(e);return n!==null?Number(n[1]):void 0}function e0(t){return Os(t)===Vi.PORTABLE_UNLOCK_REQUIRED}function t0(t){return Os(t)===Vi.PORTABLE_PREVIEW_STALE}function n0(t){return Os(t)===Vi.PORTABLE_PREVIEW_EXPIRED}function s0(t){if(t instanceof Error&&/404|not found/iu.test(t.message)&&Os(t)===void 0)return!0;if(typeof t=="object"&&t!==null){const e=t.status;if(e===404||e===501)return!0}return!1}const i0={models_providers:"st.portable.scope.models_providers",extensions_search:"st.portable.scope.extensions_search",agents_recipes:"st.portable.scope.agents_recipes",personas:"st.portable.scope.personas",instructions:"st.portable.scope.instructions",settings:"st.portable.scope.settings"},Cc=[{id:"config",labelKey:"st.portable.domainGroup.config",domains:["config"]},{id:"instructions_agents",labelKey:"st.portable.domainGroup.instructionsAgents",domains:["instructions","agents"]},{id:"recipes_personas",labelKey:"st.portable.domainGroup.recipesPersonas",domains:["recipes","personas"]},{id:"mcp_plugins",labelKey:"st.portable.domainGroup.mcpPlugins",domains:["mcp","plugins"]},{id:"skills",labelKey:"st.portable.domainGroup.skills",domains:["skills"]},{id:"memories",labelKey:"st.portable.domainGroup.memories",domains:["memories"]},{id:"appearance",labelKey:"st.portable.domainGroup.appearance",domains:["appearance"]}],r0=Cc.map(t=>t.id);function o0(t,e){const n=[];for(const s of Cc)t.has(s.id)&&n.push(...s.domains);return e.includeCredentials&&n.push("credentials"),e.includeSessions&&n.push("sessions"),[...new Set(n)]}const a0={config:"st.portable.domain.config",credentials:"st.portable.domain.credentials",instructions:"st.portable.domain.instructions",agents:"st.portable.domain.agents",recipes:"st.portable.domain.recipes",personas:"st.portable.domain.personas",mcp:"st.portable.domain.mcp",skills:"st.portable.domain.skills",plugins:"st.portable.domain.plugins",memories:"st.portable.domain.memories",appearance:"st.portable.domain.appearance",sessions:"st.portable.domain.sessions"};function qg(t){switch(t.kind){case"live":return`live:${t.spaceId}`;case"dir":return`dir:${t.path}`;case"archive":return`archive:${t.path}`;case"git":return`git:${t.repo}#${t.ref??""}#${t.subpath??""}`;case"url":return`url:${t.url}`}}function Fg(t){try{const e=new URL(t),n=e.pathname.split("/").map(s=>{const i=/^([a-z0-9_-]{12,})(\.(?:kiki\.)?(?:tgz|tar\.gz|age))?$/iu.exec(s);if(i===null)return s;const r=i[1],o=i[2]??"";return`${r.slice(0,4)}…${r.slice(-4)}${o}`}).join("/");return`${e.origin}${n}`}catch{return t.replace(/\?.*$/u,"")}}function d0(t){try{const e=new URL(t);return e.host||e.origin}catch{return t}}const Ng=/\.(?:kiki\.)?(?:tgz|tar\.gz|age)$/iu;function c0(t){const e=t.trim();return e.length>0&&Ng.test(e)}function l0(t,e){switch(t.kind){case"live":return t.spaceId;case"dir":case"archive":return t.path;case"git":{const n=t.ref??e,s=[n?`@${n}`:"",t.subpath?`/${t.subpath.replace(/^\/+/u,"")}`:""].join("");return`${t.repo}${s}`}case"url":return Fg(t.url)}}function Lo(t){return`'${t.replaceAll("'",`'"'"'`)}'`}function Ho(t){switch(t.kind){case"live":return t.spaceId;case"dir":case"archive":return t.path;case"git":{const e=t.repo,n=t.subpath?.replace(/^\/+/u,"");if(n){const s=t.ref||"HEAD";return`${e}#${s}//${n}`}return t.ref?`${e}#${t.ref}`:e}case"url":return t.url}}function u0(t){const e=["# Set KIKI_AGE_PASSPHRASE (or KIKI_AGE_KEY) in Colab Secrets if encrypted","curl -fsSL https://raw.githubusercontent.com/X-T-E-R/kiki/kiki/scripts/install.sh | sh -s -- \\"," --channel beta \\",` --apply ${Lo(Ho(t.source))} \\`];return t.overlay!==void 0&&e.push(` --apply ${Lo(Ho(t.overlay))} \\`),e.push(" --override"),e.join(`
404
+ `)}function f0(t,e,n){const s=t.includes("\\")?"\\":"/",i=t.replace(/[\\/]+$/u,""),r=i.slice(0,Math.max(i.lastIndexOf("\\"),i.lastIndexOf("/"))),o=r===""?i||".":r,a=e.trim().toLowerCase().normalize("NFKD").replace(/[^\p{Letter}\p{Number}]+/gu,"-").replace(/^-+|-+$/gu,"")||"space";return`${o}${s}kiki-exports${s}${a}${n==="age"?".kiki.age":n==="tgz"?".kiki.tgz":""}`}function h0(t,e){const n=t.trim().replace(/[\\/]+$/u,"");if(n==="")return"";if(e==="pack")return n.endsWith(".kiki.age")?n:`${n}.kiki.age`;const s=n.replace(/\.(?:kiki\.age|kiki\.tgz|age|tgz)$/iu,"");return s===n?`${n}-unpacked`:s}function p0(t,e){const n=t.trim();if(typeof e=="boolean"){if(n==="true")return!0;if(n==="false")return!1}if(typeof e=="number"){const s=Number(n);if(n!==""&&Number.isFinite(s))return s}return n==="null"&&e===null?null:t}const zi="remote:",$g=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,jg=6e4;function Bg(t){return $g.test(t)}function Lg(t){return`${zi}${t}`}function m0(t){if(!t.startsWith(zi))return null;const e=t.slice(zi.length);return Bg(e)?e:null}function g0(t){const e=Lg(t);return{homeId:e,scopeId:e}}const kn={all:["remote-connections"],list:()=>[...kn.all,"list"],inbound:()=>[...kn.all,"inbound"]};function Rc(t){const e=t.klient.rest;if(e===void 0)throw new Error("Remote connections need an HTTP connection to the server.");return e.connections}function v0(t,e){const n=e?.poll!==!1;return Kn({queryKey:[...kn.list(),t?.baseUrl??null],queryFn:async()=>{if(t===null)throw new Error("The local control connection is not ready.");return Rc(t).list()},placeholderData:s=>s!==void 0&&s.length>0?s:void 0,enabled:t!==null&&t.klient?.rest?.connections!==void 0,retry:(s,i)=>!Vn(i)&&s<2,refetchInterval:s=>!n||Vn(s.state.error)?!1:8e3,refetchIntervalInBackground:!1,refetchOnReconnect:!0,refetchOnWindowFocus:n,staleTime:e?.staleTime??5e3})}function y0(t){return Kn({queryKey:[...kn.inbound(),t?.baseUrl??null],queryFn:async()=>{if(t===null)throw new Error("The local control connection is not ready.");return Rc(t).inbound()},enabled:t!==null&&t.klient?.rest?.connections!==void 0,retry:(e,n)=>!Vn(n)&&e<2,refetchInterval:e=>Vn(e.state.error)?!1:8e3,staleTime:4e3})}function Hg(t){return t.purposes.includes("gui")}function k0(t){return Hg(t)&&t.enabled&&t.state!=="disabled"}function I0(t){return`st.remote.state.${t}`}function w0(t){return t==="online"?"online":t==="authentication_required"||t==="identity_changed"?"attention":t==="disabled"?"muted":"offline"}function b0(t){switch(t){case"win32":return"Windows";case"linux":return"Linux";case"darwin":return"macOS";default:return}}function S0(t,e=Date.now()){const n=t.summary;return n===void 0?null:{busy:n.value.busy_sessions,needsYou:n.value.needs_you_sessions,asOf:n.lastSeen,stale:n.stale||e-n.lastSeen>jg,platform:n.value.platform,borrowableTools:n.value.borrowable_tool_count,rttMs:t.rttMs}}function x0(t){try{const e=new URL(t);return e.port===""?e.hostname:`${e.hostname}:${e.port}`}catch{return t}}function _0(t){try{const e=new URL(t),n=e.hostname.toLowerCase().replace(/^\[|\]$/g,"");if(n.endsWith(".ts.net")||n.endsWith(".tailscale.net")||n.startsWith("fd7a:115c:a1e0:"))return"tailscale";const s=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(n);if(s!==null){const i=Number(s[1]),r=Number(s[2]);if(i===100&&r>=64&&r<=127)return"tailscale";if(i===10||i===192&&r===168||i===172&&r>=16&&r<=31)return"lan"}return n.endsWith(".local")?"lan":e.protocol==="https:"?"https":"other"}catch{return"other"}}function T0(t,e=8,n=4){const s=t.trim();return s.length<=e+n+1?s:`${s.slice(0,e)}…${s.slice(-n)}`}const zg="kiki.identity/1";function C0(t,e){return JSON.stringify({kiki:zg,identity:t,label:e})}function R0(t,e){const s=((t.roots??[])[0]??e).replace(/^home@/,"");return{id:t.id,label:t.name,target:t.hostname===void 0||t.hostname===""?{kind:"alias",alias:t.id}:{kind:"host",hostname:t.hostname,username:t.user,port:t.port},identityFile:t.identityFile,releaseChannel:"stable",remoteHome:s,remoteExecutable:"kiki",remoteShell:"posix"}}function A0(t){return`home@${t.target.kind==="host"?t.target.hostname:t.target.alias}${t.target.kind==="host"&&t.target.port!==void 0?`:${t.target.port}`:""}`}function M0(t){const e=t.trim();if(e===""||/^[a-z][a-z0-9+.-]*:\/\//i.test(e))return e;const n=e.split("/")[0]??e,s=n.startsWith("[")?n.slice(1,n.indexOf("]")):n.split(":")[0]??n;return`${ra(s)?"http":"https"}://${e}`}function P0(t){const e=t.trim();if(e==="")return"st.remote.endpoint.required";let n;try{n=new URL(e)}catch{return"st.remote.endpoint.invalid"}return n.protocol!=="http:"&&n.protocol!=="https:"||n.username!==""||n.password!==""||n.search!==""||n.hash!==""||n.pathname!=="/"&&n.pathname!==""?"st.remote.endpoint.invalid":n.protocol!=="https:"&&!ra(n.hostname)?"st.remote.endpoint.tls":null}function E0(t){const e=t.trim();return e===""?null:e.length>128?"st.remote.label.tooLong":null}function O0(t){const e=t.trim();return e===""?"st.remote.code.required":rl(e)===void 0?"st.remote.code.invalid":null}function D0(t){const e=t.toUpperCase().replace(/[^23456789ABCDEFGHJKLMNPQRSTUVWXYZ]/g,"").slice(0,8);return e.length<=4?e:`${e.slice(0,4)}-${e.slice(4)}`}const Rs={all:["thread-bridges"],status:()=>[...Rs.all,"status"],localWorkspaces:()=>[...Rs.all,"local-workspaces"]};function Wg(t){return t!==null&&t.klient?.rest?.threadBridges!==void 0}function Ug(t){const e=t.klient.rest;if(e?.threadBridges===void 0)throw new Error("Thread-message permissions need an HTTP connection to the server.");return e.threadBridges}function q0(t){return Kn({queryKey:[...Rs.status(),t?.baseUrl??null],queryFn:async()=>{if(t===null)throw new Error("The local control connection is not ready.");return Ug(t).status()},enabled:Wg(t),refetchInterval:8e3,staleTime:4e3})}function In(t,e){return t.homeId===e.homeId&&t.hostId===e.hostId}function Ac(t,e){return t.enabled&&!t.grant.revoked&&t.grant.enabled&&t.grant.expiresAt>e}function Mc(t,e){return!t.revoked&&t.enabled&&t.expiresAt>e}function F0(t,e,n=Date.now()){const s=e.outbound.some(r=>r.connectionId===t.id&&Ac(r,n)),i=e.inbound.some(r=>In(r.source,t.target)&&Mc(r,n));return s&&i?"both":s?"outgoing":i?"incoming":"none"}function N0(t,e,n=Date.now()){const s=e.inbound.some(r=>In(r.source,t.source)&&Mc(r,n)),i=e.outbound.some(r=>In(r.grant.target,t.source)&&Ac(r,n));return i&&s?"both":i?"outgoing":s?"incoming":"none"}function $0(t){switch(t){case"both":return"st.remote.threadMessages.both";case"outgoing":return"st.remote.threadMessages.outgoing";case"incoming":return"st.remote.threadMessages.incoming";case"none":return"st.remote.threadMessages.none";case"unreadable":return"st.remote.threadMessages.unreadable"}}function j0(t,e,n=Date.now()){const s=[];for(const i of e.outbound)i.connectionId!==t.id||i.grant.revoked||s.push({id:i.grant.id,direction:"outbound",grant:i.grant,enabled:i.enabled&&i.grant.enabled,expired:i.grant.expiresAt<=n,localScope:i.grant.sourceScope,remoteScope:i.grant.targetScope,operations:i.grant.operations,borrowTools:i.borrowTools??!0});for(const i of e.inbound)!In(i.source,t.target)||i.revoked||s.push({id:i.id,direction:"inbound",grant:i,enabled:i.enabled,expired:i.expiresAt<=n,localScope:i.targetScope,remoteScope:i.sourceScope,operations:i.operations});return s}function B0(t,e,n=Date.now()){const s=[];for(const i of e.inbound)!In(i.source,t.source)||i.revoked||s.push({id:i.id,direction:"inbound",grant:i,enabled:i.enabled,expired:i.expiresAt<=n,localScope:i.targetScope,remoteScope:i.sourceScope,operations:i.operations});for(const i of e.outbound)!In(i.grant.target,t.source)||i.grant.revoked||s.push({id:i.grant.id,direction:"outbound",grant:i.grant,enabled:i.enabled&&i.grant.enabled,expired:i.grant.expiresAt<=n,localScope:i.grant.sourceScope,remoteScope:i.grant.targetScope,operations:i.grant.operations,borrowTools:i.borrowTools??!0});return s}const Vg=/^wd_([a-z0-9._-]+)_[0-9a-f]{12}$/i,zo=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function L0(t){const e=t.trim();if(e===""||e==="*"||zo.test(e))return null;const n=Vg.exec(e);if(n!==null){const s=n[1]?.trim()??"";return s===""||zo.test(s)?null:s}return/^[0-9a-f]{16,}$/i.test(e)?null:e}const Wo=64,Kg=256,Wi=new WeakMap;function Pc(t){let e=Wi.get(t);return e===void 0&&Wi.set(t,e={attached:!1,sequence:0,sessions:new Map}),e}function Uo(t){if(!(t.size<=Wo)){for(const[e,n]of t)if(!(n.listeners.size>0)&&(t.delete(e),t.size<=Wo))break}}function H0(t,e,n){const{sessions:s}=Pc(t);let i=s.get(e);return i===void 0?(Uo(s),s.set(e,i={byAgent:new Map,listeners:new Set})):(s.delete(e),s.set(e,i)),i.listeners.add(n),()=>{i.listeners.delete(n),i.listeners.size===0&&Uo(s)}}function z0(t,e,n){const s=Wi.get(t)?.sessions.get(e);return s?.byAgent.get(n)??s?.revision}function Vo(t,e,n){if(n===void 0)t.revision=e,t.byAgent.clear();else{if(t.byAgent.has(n))t.byAgent.delete(n);else if(t.byAgent.size>=Kg){const s=t.byAgent.keys().next().value;s!==void 0&&t.byAgent.delete(s)}t.byAgent.set(n,e)}for(const s of t.listeners)s()}function Gg(t,e){const[n,s]=t.queryKey;if(n==="usage-v2"||n==="usage-v2-strip"||n==="usage-v2-strip-session"||n==="sessions")return!0;if(n==="session")return e?.sessionId===void 0||s===e.sessionId;if(n!=="agentCapabilities"||t.queryKey.at(-1)==="catalog")return!1;if(e===void 0)return!0;const{sessionId:i,agentId:r}=e;return i!==void 0&&typeof s=="object"&&s!==null&&"session_id"in s&&s.session_id===i&&(r===void 0||"agent_id"in s&&s.agent_id===r)}function Ko(t,e){let n=!0,s=!1;const i=new Map,r=async()=>{s=!0;try{for(;i.size>0;){if(!n)return;const l=[...i.values()];i.clear();const c={predicate:u=>l.some(f=>Gg(u,f))};await e.cancelQueries(c),n&&await e.invalidateQueries(c,{cancelRefetch:!1})}}finally{s=!1}},o=l=>{i.set(JSON.stringify(l),l),s||r().catch(()=>{})},a=Pc(t),d=t.events.on("usage.settled",l=>{if(!n)return;const c=l.sessionId===void 0?void 0:a.sessions.get(l.sessionId);c!==void 0&&Vo(c,++a.sequence,l.agentId),o(l)});return d.ready.then(()=>{if(n){if(a.attached)for(const l of a.sessions.values())Vo(l,++a.sequence);a.attached=!0,o()}}).catch(()=>{}),()=>{n=!1,d.dispose()}}const Qg=[["plugin"],["plugin-usage"],["plugin-panels"],["plugin-commands"],["plugin-panel-document"],["plugin-marketplace"],["plugin-recommendations"],["plugins"],["skins"],["agentCapabilities"],["workspace-skills"],["mcp-servers"],["mcp-managed-servers"]];async function Jg(t){await Promise.all(Qg.map(e=>t.invalidateQueries({queryKey:[...e]})))}function Go(t,e){let n=!0;const s=()=>{Jg(e).catch(()=>{})},i=t.events.on("plugins.changed",()=>{n&&s()});return i.ready.then(()=>{n&&s()}).catch(()=>{}),()=>{n=!1,i.dispose()}}const Ec=[["persona-session-heads"],["persona-switcher-sessions"]],Yg=[["personas"],["persona"],["persona-avatar"],["personas","directory"],["bots"],...Ec];function W0(t){for(const e of Ec)t.invalidateQueries({queryKey:[...e]})}async function Xg(t){await Promise.all(Yg.map(e=>t.invalidateQueries({queryKey:[...e]})))}function Qo(t,e){let n=!0;const s=()=>{Xg(e).catch(()=>{})},i=t.events.on("personas.changed",()=>{n&&s()});return Promise.resolve(i.ready).then(()=>{n&&s()}).catch(()=>{}),()=>{n=!1,i.dispose()}}class di extends Error{constructor(e,n){super(n),this.kind=e}}function ci(t){if(t!==null&&typeof t=="object"&&"message"in t){const e=t;if(typeof e.message=="string")return{message:e.message,stderrTail:Array.isArray(e.stderrTail)?e.stderrTail.filter(n=>typeof n=="string"):[],logPath:typeof e.logPath=="string"?e.logPath:null,kind:e.kind==="identity"||e.kind==="authentication"||e.kind==="protocol"?e.kind:t instanceof Ee&&t.code===Ce.UNAUTHORIZED?"authentication":t instanceof Ee&&t.code===Ce.INVALID_RESPONSE?"protocol":void 0}}return{message:t instanceof Error?t.message:String(t),stderrTail:[],logPath:null}}const Zg=new Map([["inbound_disabled","remote-closed"],["connection_paused","remote-paused"],["connection_disabled","remote-paused"],["identity_changed","remote-identity-changed"],["registered_space_identity_changed","remote-identity-changed"],["connection_not_approved","remote-not-approved"],["authentication_required","remote-not-approved"],["invalid_owner_credential","remote-not-approved"],["target_daemon_unavailable_start_registered_space","remote-not-running"]]);function ev(t){const e=` (code ${t.code})`;return t instanceof Ee&&t.message.endsWith(e)?t.message.slice(0,-e.length):t.message}function Ui(t){if(t instanceof oe||t instanceof DOMException&&t.name==="AbortError")return t;const e=(t instanceof Ee||t instanceof mt)&&t.code===Ce.UNAUTHORIZED?Zg.get(ev(t)):void 0;return new oe(e??"remote-unreachable")}function sn(t,e){return e.aborted?Promise.reject(e.reason instanceof Error?e.reason:new DOMException("Aborted","AbortError")):new Promise((n,s)=>{const i=()=>{s(e.reason instanceof Error?e.reason:new DOMException("Aborted","AbortError"))};e.addEventListener("abort",i,{once:!0}),t.then(r=>{e.removeEventListener("abort",i),n(r)},r=>{e.removeEventListener("abort",i),s(r)})})}function Oc(t){return t!=="web-cookie"&&t!=="app-shell"&&t!=="remote"}function li(t){return Oc(t?.source)?"auth-required":"session-expired"}function ui(t,e){if(!Oc(t.source))throw new oe("session-expired");const n=e.trim();if(n===""||/[\u0000-\u001F\u007F]/.test(n))throw new oe("auth-required");return{...t,config:{...t.config,token:n}}}function tv(t){t.persist&&t.source!=="remote"&&t.source!=="ssh"&&t.source!=="web-cookie"&&t.source!=="app-shell"&&t.source!=="desktop"&&oa(t.config)}async function U0(t,e,n){n.throwIfAborted();const s=e.scopeId.slice(7);if(e.homeId!==e.scopeId||!e.scopeId.startsWith("remote:")||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(s))throw new oe("scope-invalid");if(t.openRemoteSpace===void 0)throw new oe("scope-invalid");await t.openRemoteSpace(s),n.throwIfAborted()}async function fi(t,e,n,s=!1,i="auth-required"){n.throwIfAborted();const r=new URL(e,"http://example.test").pathname,o=/^\/s\/([^/]+)/.exec(r)?.[1],a=/^\/(?:rooms|r)\/([^/]+)$/.exec(r)?.[1];try{if(o!==void 0){await sn(t.getSession(decodeURIComponent(o)),n),n.throwIfAborted();const d=/^\/s\/[^/]+\/agent\/([^/]+)$/.exec(r)?.[1];if(d!==void 0&&decodeURIComponent(d)!=="main"){const l=await sn(t.klient.session(decodeURIComponent(o)).agents(),n);if(!Object.hasOwn(l,decodeURIComponent(d)))throw new oe("target-missing")}}if(a!==void 0){const d=t.klient.rest;if(d===void 0)throw new oe("offline");if(await sn(d.rooms.get(decodeURIComponent(a)),n)===void 0)throw new oe("target-missing")}}catch(d){throw o!==void 0&&d instanceof Ee&&Al(d.message)?new oe("target-missing"):a!==void 0&&d instanceof mt&&d.code===Ce.REQUEST_INVALID&&d.message===`Room '${decodeURIComponent(a)}' does not exist.`?new oe("target-missing"):s?Ui(d):(d instanceof Ee||d instanceof mt)&&d.code===Ce.UNAUTHORIZED?new oe(i):d}n.throwIfAborted()}function nv(t){return{async prepare(e,n,s){n.throwIfAborted();const i=t.active(),r=i.scope.homeId!==e.homeId,o=e.scopeId.startsWith("remote:")||e.homeId.startsWith("remote:");if(!r&&e.scopeId===i.scope.scopeId&&s===void 0){const m=li(i.selection);let p;try{p=await sn(i.client.meta(),n)}catch(S){throw o?Ui(S):(S instanceof Ee||S instanceof mt)&&S.code===Ce.UNAUTHORIZED?new oe(m):S}n.throwIfAborted();const k=e.serverHomeId??i.scope.serverHomeId;if(k!==void 0&&k!==p.server_home_id||e.connectionRef!==void 0&&e.connectionRef!==i.scope.connectionRef)throw new oe("identity-mismatch");return{scope:{...i.scope,serverHomeId:p.server_home_id},validate:(S,w)=>fi(i.client,S,w,o,m),commit:()=>{n.throwIfAborted()},dispose:()=>{}}}let a,d=i.selection,l,c=!1,u=!1,f=i.scope.homeId,g=!1,h;t.preparing?.(!0);const v=async()=>{try{if(c&&l!==void 0&&(c=!1,l.klient.close().catch(()=>{})),h!==void 0){const m=h;h=void 0,await t.host.connection.disconnectSshProfile?.(m.id,m.tunnelId)}u&&(u=!1,await t.host.prepareSpace?.(f))}finally{t.preparing?.(!1)}};try{if(o){const S=e.scopeId.slice(7);if(e.homeId!==e.scopeId||!e.scopeId.startsWith("remote:")||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(S))throw new oe("scope-invalid");const w=t.control?.()??t.local();if(w===null||w.selection.source==="remote"||w.selection.source==="ssh")throw new oe("offline");const x=w.client.klient.rest?.connections;if(x===void 0)throw new oe("offline");const b=await sn(x.list(),n);n.throwIfAborted();const _=b.find(N=>N.id===S);if(_===void 0)throw new oe("scope-invalid");if(_.enabled!==!0||_.state==="disabled")throw new oe("remote-paused");if(_.target.protocol!==ol)throw new oe("remote-protocol");if(_.state==="identity_changed")throw new oe("remote-identity-changed");a={config:w.selection.config,persist:!1,source:"remote",scopeId:e.scopeId,connectionId:_.id,serverHomeId:_.target.homeId},d=a,l=t.createClient?.(a)??vi({endpoint:a.config.url,token:a.config.token,connectionId:_.id}),c=!0;let C;try{C=await sn(l.meta(),n)}catch(N){throw Ui(N)}if(n.throwIfAborted(),C.server_home_id!==_.target.homeId||e.serverHomeId!==void 0&&e.serverHomeId!==C.server_home_id||e.connectionRef!==void 0&&e.connectionRef!==_.id)throw new oe("identity-mismatch");const F=l;return{scope:{...e,serverHomeId:C.server_home_id,connectionRef:_.id},validate:(N,me)=>fi(F,N,me,!0),commit:()=>{n.throwIfAborted(),t.commit(a,F,C),c=!1,t.preparing?.(!1)},dispose:v}}if(e.scopeId.startsWith("ssh:")&&!s&&!e.connectionRef)throw new oe("auth-required");if(r&&i.selection.source==="remote"&&(f=t.host.activeSpace===void 0?"main":gi(await t.host.activeSpace())?.homeId??"main",n.throwIfAborted(),g=e.homeId===f&&(e.scopeId==="local"||e.scopeId.startsWith("direct:"))),r&&!g){if(!t.host.prepareSpace)throw new oe("scope-invalid");const S=await t.host.prepareSpace(e.homeId);if(u=!0,n.throwIfAborted(),S.homeId!==e.homeId)throw new oe("identity-mismatch")}if(e.scopeId.startsWith("ssh:")){const S=e.scopeId.slice(4),w=await t.host.connection.listSshProfiles?.();n.throwIfAborted();const x=w?.find(C=>C.id===S);if(x===void 0)throw new oe("scope-invalid");if(!x.serverHomeId||!x.remotePort)throw new oe("scope-invalid");let b;if(s!==void 0){if(!/^[A-Za-z0-9_-]{43}$/.test(s))throw new oe("auth-required");if(!t.host.connection.prepareSshProfile)throw new oe("scope-invalid");try{b=await t.host.connection.prepareSshProfile(S,s)}catch(C){if(C instanceof oe)throw C;const F=C instanceof Error?C.message:String(C);throw F.includes("rejected the bearer token")?new oe("auth-required"):F.includes("home identity")||F.includes("authentication; SSH connection blocked")||F.includes("build identity")||F.includes("release channel")?new oe("identity-mismatch"):C}b.tunnelId&&(h={id:S,tunnelId:b.tunnelId})}else{if(!e.connectionRef||!t.host.connection.resumeScopeConnection)throw new oe("auth-required");try{b=(await t.host.connection.resumeScopeConnection(e.homeId,S,e.connectionRef)).connection}catch(C){const F=C instanceof Error?C.message:String(C);throw new oe(F.includes("offline")?"offline":F.includes("identity changed")?"identity-mismatch":"auth-required")}if(b.tunnelId!==e.connectionRef)throw new oe("identity-mismatch")}n.throwIfAborted();let _;try{_=new URL(b.config.url)}catch{throw new oe("identity-mismatch")}if(_.protocol!=="http:"||_.hostname!=="127.0.0.1"||_.username||_.password||!_.port||!b.tunnelId||s!==void 0&&b.config.token!==s||b.serverHomeId!==x.serverHomeId)throw new oe("identity-mismatch");a={config:b.config,persist:!1,source:"ssh",scopeId:e.scopeId,profile:x,tunnelId:b.tunnelId,serverHomeId:b.serverHomeId,serverInstanceId:b.serverInstanceId,serverVersion:b.serverVersion,buildId:b.buildId,buildChannel:b.buildChannel},d=a}else if(e.scopeId==="local"||g&&e.scopeId.startsWith("direct:"))if(r&&!g){const S=await t.host.connection.discover();if(S===null)throw new oe("offline");a={config:S.config,persist:!1,source:"desktop",scopeId:"local"},d=a,s!==void 0&&(a=ui(a,s))}else{const S=g?t.control?.()??t.local():t.local();if(S===null)throw new oe("offline");if(e.scopeId.startsWith("direct:")&&e.scopeId!==(S.selection.scopeId??`direct:${S.selection.config.url.trim().replace(/\/+$/,"")}`))throw new oe("scope-invalid");d=S.selection,s!==void 0?a=ui(S.selection,s):(a=S.selection,l=S.client)}else if(e.homeId===i.scope.homeId&&e.scopeId===i.scope.scopeId)d=i.selection,s!==void 0?a=ui(i.selection,s):(a=i.selection,l=i.client);else throw new oe("scope-invalid");n.throwIfAborted(),l===void 0&&(l=t.createClient?.(a)??new pn({baseUrl:a.config.url,token:a.config.token}),c=!0);const m=await sn(l.meta(),n);if(n.throwIfAborted(),e.serverHomeId!==void 0&&m.server_home_id!==e.serverHomeId)throw new oe("identity-mismatch");if(a.source==="ssh"&&(m.server_home_id!==a.serverHomeId||m.server_id!==a.serverInstanceId||m.server_version!==a.serverVersion||m.dangerous_bypass_auth!==!1||(m.build_id??null)!==a.buildId||(m.build_channel??null)!==a.buildChannel))throw new oe("identity-mismatch");const p=l,k=li(a);return{scope:{...e,serverHomeId:m.server_home_id,connectionRef:a.source==="ssh"?a.tunnelId:void 0},validate:(S,w)=>fi(p,S,w,!1,k),commit:async()=>{if(n.throwIfAborted(),a.source==="ssh"&&a.profile&&a.tunnelId){if(!t.host.connection.commitScopeConnection)throw new oe("scope-invalid");await t.host.connection.commitScopeConnection(e.homeId,a.profile.id,a.tunnelId,r),h=void 0,u=!1}s!==void 0&&tv(a),r&&!g?(c&&(c=!1,await p.klient.close()),t.reload()):t.commit(a,p,m),c=!1,u=!1,h=void 0,t.preparing?.(!1)},dispose:v}}catch(m){throw await v(),(m instanceof Ee||m instanceof mt)&&m.code===Ce.UNAUTHORIZED?new oe(o?"offline":li(d)):m}}}}const sv={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1,VITE_APP_VERSION:"0.6.0",VITE_BUILD_SHA:"",VITE_UPDATE_CHANNEL:"stable"};function hi(){const t=`${window.location.pathname}${window.location.search}${window.location.hash}`,e=bl(window.location);if(e!==t)try{window.history.replaceState(window.history.state,"",e)}catch{}}function ls(t,e){return t.type==="event.remote_connections.changed"?(e.invalidateQueries({queryKey:kn.all}),e.invalidateQueries({queryKey:Rs.all}),!0):t.type==="event.portable_spaces.changed"?(e.invalidateQueries({queryKey:Es.all}),!0):t.type==="event.plugin.changed"?(e.invalidateQueries({queryKey:["models"]}),e.invalidateQueries({queryKey:["providers"]}),e.invalidateQueries({queryKey:["provider-quotas"]}),!0):t.type!=="event.model_catalog.changed"?!1:(e.invalidateQueries({queryKey:["models"]}),e.invalidateQueries({queryKey:["providers"]}),e.invalidateQueries({queryKey:["model-entity"]}),e.invalidateQueries({queryKey:["provider-entity"]}),e.invalidateQueries({queryKey:["discovered-models"]}),e.invalidateQueries({queryKey:["provider-quotas"]}),!0)}function us(t,e){t.invalidateQueries({queryKey:["sessions"]}),t.invalidateQueries({queryKey:["rooms"]}),t.invalidateQueries({queryKey:["activity-prompts",e]}),t.invalidateQueries({queryKey:["activity-tasks",e]})}const Dc=3,ir=64*1024*1024,iv=ir/2,qc=5*6e4,Fc=4,rv=8;function Hn(t,e,n=1,s=Number.MAX_SAFE_INTEGER){const r=sv?.[t];if(typeof r!="string"||r.trim()==="")return e;const o=Number.parseInt(r,10);return!Number.isFinite(o)||o<n?e:Math.min(s,o)}function fs(t){const e=t.getState();return e.busy||e.pendingInteraction!=="none"||e.tasks.some(n=>n.status==="running")}function ov(t){const e=t.getState();return e.loaded&&e.loadError===void 0&&!(e.resyncFailed&&e.resyncError?.retryable===!1)}class Nc{controllers=new Set;retained=new WeakMap;parked=new Map;listeners=new Set;generation=0;limits;now;setTimer;clearTimer;ttlTimer=null;constructor(e={}){const n=e.maxBytes??Hn("VITE_KIKI_VIEW_CACHE_MAX_BYTES",ir,1048576,1073741824);this.limits={maxParked:e.maxParked??Hn("VITE_KIKI_VIEW_CACHE_MAX_PARKED",Dc,0,64),maxBytes:n,maxEntryBytes:e.maxEntryBytes??Math.floor(n/2),ttlMs:e.ttlMs??Hn("VITE_KIKI_VIEW_CACHE_TTL_MS",qc,1e3,1440*6e4),maxLiveParked:e.maxLiveParked??Hn("VITE_KIKI_VIEW_CACHE_MAX_LIVE_PARKED",Fc,0,64)},this.now=e.now??Date.now,this.setTimer=e.setTimer??((s,i)=>setTimeout(s,i)),this.clearTimer=e.clearTimer??(s=>{clearTimeout(s)})}acquire(e,n,s,i){let r=this.retained.get(n);r===void 0&&(r=new Map,this.retained.set(n,r));let o=r.get(e);if(o===void 0){const l=s();if(l.sessionId!==e||this.controllers.has(l))throw new Error("Controller factory must return a fresh controller for the requested session");i!==void 0&&l.setFocusedAgent(i),o={controller:l,ready:l.open(),references:1,sessions:r,sessionId:e},r.set(e,o),this.add(l)}else i!==void 0&&o.controller.setFocusedAgent(i),o.parked!==void 0?(this.unpark(o),o.controller.unpark?.(),o.references=1,o.ready=o.controller.resume(),this.add(o.controller)):o.references+=1;const a=o;let d=!1;return{controller:a.controller,ready:a.ready,release:()=>{d||(d=!0,a.references-=1,!(a.references>0)&&(this.park(a,n)||this.dispose(a)))}}}get parkedCount(){return this.parked.size}hasRetained(e,n){return e===""?!1:this.retained.get(n)?.has(e)===!0}evictScope(e){for(const[n,s]of Array.from(this.parked))s===e&&this.dispose(n)}clearParked(){for(const e of Array.from(this.parked.keys()))this.dispose(e)}park(e,n){const{controller:s}=e;if(typeof s.getState!="function"||typeof s.suspend!="function"||!ov(s))return!1;const i=s.residentBytes();if(i>this.limits.maxEntryBytes)return!1;const r=s.subscribe(()=>{this.onParkedChange(e)});return e.parked={at:this.now(),bytes:i,unsubscribe:r},this.parked.set(e,n),fs(s)?(typeof s.setFocusedAgent=="function"&&s.setFocusedAgent(void 0),s.cancelParkedReads?.()):s.suspend(),this.delete(s),this.enforceLimits(),!0}unpark(e){e.parked?.unsubscribe(),e.parked=void 0,this.parked.delete(e),this.scheduleTtl()}dispose(e){e.parked!==void 0&&this.unpark(e),e.sessions.get(e.sessionId)===e&&e.sessions.delete(e.sessionId),e.controller.close(),this.delete(e.controller)}onParkedChange(e){const n=e.parked;if(n===void 0||e.controller.suspended||fs(e.controller))return;const s=e.controller.residentBytes();if(s>this.limits.maxEntryBytes){this.dispose(e);return}const i=this.parked.get(e)??{};e.parked={...n,at:this.now(),bytes:s},this.parked.delete(e),this.parked.set(e,i),e.controller.suspend(),this.enforceLimits()}isLiveProtected(e){return!e.controller.suspended&&fs(e.controller)}enforceLimits(){const e=this.now(),n=Array.from(this.parked.keys()).filter(o=>this.isLiveProtected(o));for(const o of n.slice(0,Math.max(0,n.length-this.limits.maxLiveParked)))o.controller.suspend();for(const o of Array.from(this.parked.keys()))!this.isLiveProtected(o)&&e-(o.parked?.at??e)>=this.limits.ttlMs&&this.dispose(o);const s=()=>Array.from(this.parked.keys()).filter(o=>!this.isLiveProtected(o));let i=s(),r=i.reduce((o,a)=>o+(a.parked?.bytes??0),0);for(;i.length>0&&(i.length>this.limits.maxParked||r>this.limits.maxBytes);){const o=i[0];r-=o.parked?.bytes??0,this.dispose(o),i=s()}this.scheduleTtl()}scheduleTtl(){this.ttlTimer!==null&&(this.clearTimer(this.ttlTimer),this.ttlTimer=null);let e=1/0;for(const n of this.parked.keys())this.isLiveProtected(n)||(e=Math.min(e,(n.parked?.at??0)+this.limits.ttlMs));e!==1/0&&(this.ttlTimer=this.setTimer(()=>{this.ttlTimer=null,this.enforceLimits()},Math.max(0,e-this.now())))}add(e){this.controllers.add(e),this.emit()}delete(e){this.controllers.delete(e)&&this.emit()}[Symbol.iterator](){return this.controllers.values()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}snapshot(){return this.generation}emit(){this.generation+=1;for(const e of this.listeners)e()}}const Yn=E.createContext(null),av=15e3;let Jo=0;function $c(t=Date.now()){return Jo+=1,`gui-${t.toString(36)}-${Jo.toString(36)}`}function en(t){return t?.source==="desktop"}function Yo(t,e){return t.url.trim().replace(/\/+$/,"")===e.url.trim().replace(/\/+$/,"")&&t.token.trim()===e.token.trim()}function dv(t,e){for(const n of["server_id","server_home_id","current_space_id","dangerous_bypass_auth","started_at"])if(t[n]!==void 0&&e[n]!==void 0&&t[n]!==e[n])return"changed";return!t.server_id||!e.server_id||!t.server_home_id||!e.server_home_id||typeof t.dangerous_bypass_auth!="boolean"||typeof e.dangerous_bypass_auth!="boolean"||t.current_space_id!==e.current_space_id?"unknown":"same"}function cv({children:t}){const e=sa(),n=e.kind==="tauri",s=wl(),i=!n&&!s&&al(),{locale:r,t:o}=on(),a=E.useRef(new Map),d=dl(),l=E.useRef(d?.scopeId.startsWith("remote:")?d:null),c=E.useRef((()=>{const T=un();return T!==null&&T.homeId.startsWith("remote:")?null:T})()),f=E.useSyncExternalStore(cl,ll,ul).requestTimeoutSeconds*1e3,[g,h]=E.useState(()=>fl()),[v,m]=E.useState(g.kind==="failed"?hl(g.reason):void 0),[p,k]=E.useState(()=>{if(n||s)return null;if(g.kind==="signed-in")return ln(window),{config:{url:"",token:""},persist:!1,source:"web-cookie"};pl(q=>{if(!q)return;const G=Z.current;G!==null&&G.source!=="app-shell"&&(G.source!=="stored"||G.persist)||(ln(window),D.current+=1,N(null),V(null),k({config:{url:"",token:""},persist:!1,source:"web-cookie"}))});const T=ml({deepLink:vl(),stored:gl()});if(T!==null)return T;const j=Zn(window);return j!==null?{config:{url:"",token:j},persist:!1,source:i?"local-detection":"app-shell",scopeId:i?"local":"direct:"}:null}),S=p?.config??null,w=p?.scopeId??(n?"local":`direct:${S?.url.trim().replace(/\/+$/,"")??""}`),x=p?.source==="remote"?p.connectionId??null:null,b=p?.source??null,_=x===null?un()?.homeId??"main":`remote:${x}`;let C=a.current.get(w);if(C!==void 0)a.current.delete(w),a.current.set(w,C);else{C=new Ru({defaultOptions:{queries:{retry:1,staleTime:0,refetchOnWindowFocus:!1}}}),a.current.set(w,C);const T=Hn("VITE_KIKI_MAX_SCOPE_QUERY_CLIENTS",rv,2,64);for(const[j,q]of Array.from(a.current)){if(a.current.size<=T)break;j===w||j==="local"||(a.current.delete(j),q.clear(),q.unmount())}}const[F,N]=E.useState(null),[me,V]=E.useState(null),[we,ye]=E.useState(()=>n?{stage:"spawning",startedAtMs:Date.now()}:null),[Fe,te]=E.useState(null),[ee,re]=E.useState(0),le=E.useRef(!1),[Oe,Ze]=E.useState("closed"),[Je,P]=E.useState(!0),I=E.useRef("closed"),y=E.useRef(!1),[R,z]=E.useState(0),[W,B]=E.useState(!1),K=E.useRef(null),$=E.useRef(null),se=E.useRef(!1),ce=E.useRef(null),Te=E.useRef(null),ke=E.useRef(new Nc),D=E.useRef(0),De=E.useRef(0),tt=i&&p?.source==="local-detection"?p:null,Me=E.useRef(tt),[H,Ie]=E.useState(tt),ae=E.useCallback(T=>{Me.current=T,Ie(T)},[]),ze=E.useRef(null),de=E.useRef(new Map),J=E.useRef(null),L=E.useRef(!1),_e=E.useRef({promise:null,consumed:!1}),Z=E.useRef(p);Z.current=p;const Ne=T=>T==="app-shell"||i&&T==="local-detection",nt=E.useRef(Ne(p?.source)?p.config.token.trim():null);Ne(p?.source)&&p.config.token.trim()!==""&&(nt.current=p.config.token.trim());const He=E.useRef($c()),ge=E.useRef(void 0),O=E.useRef(void 0);E.useEffect(()=>(e.connection.setWorkspaceScope?.(p?.source==="ssh"?"ssh":"local"),()=>e.connection.setWorkspaceScope?.("local")),[e,p?.source]),E.useEffect(()=>{if(!s)return;let T=!1;return e.connection.discover().then(j=>{T||j!==null&&(D.current+=1,k({config:j.config,persist:j.persist,source:"local-detection"}))},j=>{T||V({kind:"raw",text:j instanceof Error?j.message:String(j)})}),()=>{T=!0}},[e,s]),E.useEffect(()=>{if(e.kind!=="tauri")return;let T=!1,j=0;le.current=!1;let q,G,U=0;const Y=()=>{if(T||le.current||G!==void 0||$.current?.phase==="blocked")return;const ue=Math.min(1e3*2**Math.min(U++,4),1e4);G=setTimeout(()=>{if(G=void 0,T||le.current||L.current)return;const Ue=Z.current?.source;Ue!==void 0&&Ue!=="desktop"&&Ue!=="ssh"&&Ue!=="remote"||it()},ue)},X=()=>{G!==void 0&&clearTimeout(G),G=void 0,U=0},Be=()=>{const ue=K.current;return ue!==null&&ue.selection===Z.current&&ue.client===pt.current&&ue.homeId===(un()?.homeId??"main")&&ue.scopeId===(Z.current?.scopeId??"local")?ue:null},at=ue=>{const Ue=Be();if(Ue===null)return!1;const ie=ci(ue);return $.current={client:Ue.client,phase:ie.kind===void 0?"failed":"blocked",suspended:ie.kind!==void 0||$.current?.suspended===!0},Ze("closed"),P(!1),ye(null),te(ie),ie.kind===void 0?Y():(X(),Ue.client.suspendDesktop()),!0};let Le=!1;const it=ue=>{if(T||Le&&ue===void 0||le.current)return;Le=!0;const Ue=++j,ie=Be(),_t=$.current?.suspended===!0;ie!==null?I.current==="open"&&!_t||($.current={client:ie.client,phase:"checking",suspended:_t},Ze("connecting")):en(Z.current)||ae(null),Z.current===null&&ye(Ke=>({stage:"waiting",startedAtMs:Ke?.startedAtMs??Date.now()}));const pe=Z.current,Ve=D.current,Ye=()=>!T&&!le.current&&Ue===j&&Z.current===pe&&D.current===Ve,ft=_e.current;ue===void 0&&(ft.promise??=(e.connection.takeScopeConnection?.()??Promise.resolve(null)).then(Ke=>{if(Ke===null)return null;const Ge=Ke.connection;return{config:Ge.config,persist:!1,source:"ssh",scopeId:`ssh:${Ke.profile.id}`,profile:Ke.profile,tunnelId:Ge.tunnelId,serverHomeId:Ge.serverHomeId,serverInstanceId:Ge.serverInstanceId,serverVersion:Ge.serverVersion,buildId:Ge.buildId,buildChannel:Ge.buildChannel}}).catch(()=>null));const zc=ue===void 0?e.connection.discover():Promise.resolve({config:ue,persist:!1});Promise.all([zc,ft.consumed||ue!==void 0?Promise.resolve(null):ft.promise]).then(async([Ke,Ge])=>{if(T||le.current||Ue!==j||Ge===null&&!Ye())return;ye(null);const hr=!en(Z.current)&&Z.current!==null;if(Ke===null){if(at(new Error("Desktop connection discovery returned no verified endpoint."))||(ae(null),hr))return;V({kind:"key",key:"conn.desktopNoServer"}),Y();return}if(ie!==null&&Ge===null){const pr=Yo(ie.selection.config,Ke.config),js=pr&&!_t?ie.client:new pn({baseUrl:Ke.config.url.trim().replace(/\/+$/,""),token:Ke.config.token.trim(),timeoutMs:f});let Tt;try{Tt=await js.meta()}finally{js!==ie.client&&js.klient.close()}if(!Ye()||Be()!==ie)return;const mr=dv(ie.meta,Tt);if(!ie.meta.server_home_id||ie.meta.server_home_id!==Tt.server_home_id||ie.meta.current_space_id!==Tt.current_space_id||Tt.current_space_id!==ie.homeId)throw new di("identity","The desktop backend home or space changed. Reopen the intended space to connect.");if(ie.meta.dangerous_bypass_auth!==Tt.dangerous_bypass_auth||Tt.dangerous_bypass_auth!==!1)throw new di("authentication","The desktop backend authentication mode changed. This connection is blocked.");if(mr==="unknown")throw new di("identity","The desktop backend identity could not be verified.");if(_t||!pr||mr==="changed"){const An={config:Ke.config,persist:!1,source:"desktop",scopeId:ie.scopeId};$.current=null,se.current=!0;try{ie.client.rebindDesktop(Ke.config)}finally{se.current=!1}D.current+=1,Ft.current={client:ie.client,meta:Tt},lt.current={selection:An,client:ie.client,timeoutMs:f},$e(lt.current),ae(An),$t({endpoint:Ke.config.url.trim().replace(/\/+$/,""),token:Ke.config.token.trim(),scopeId:ie.scopeId,client:ie.client}),Z.current=An,k(An),K.current={...ie,selection:An,meta:Tt},C.invalidateQueries()}else K.current={...ie,meta:Tt},$.current=null;X(),te(null),N(Tt),V(null),Ze(I.current),I.current!=="open"&&ie.client.klient.terminal.nudge();return}X(),te(null);const $s={config:Ke.config,persist:!1,source:"desktop",scopeId:"local"};if(ae($s),Ge!==null&&!ft.consumed){ft.consumed=!0,ft.promise=Promise.resolve(null),Z.current=Ge,Ge.profile&&Ge.tunnelId&&(J.current={id:Ge.profile.id,tunnelId:Ge.tunnelId}),D.current+=1,k(Ge);return}hr||!Ye()||(ie!==null&&a.current.get(ie.scopeId)?.clear(),K.current=null,$.current=null,N(null),V(null),D.current+=1,Z.current=$s,k($s))}).catch(Ke=>{if(!Ye()||at(Ke)||(ae(null),!en(Z.current)&&Z.current!==null))return;D.current+=1,ye(null),N(null),Z.current=null,k(null);const Ge=ci(Ke);te(Ge),Ge.kind===void 0?Y():X()}).finally(()=>{Ue===j&&(Le=!1)})};let he;ge.current=void 0;const jt=()=>{if(T||$.current?.phase==="blocked")return;const ue=Z.current?.source;!en(Z.current)&&ue!=="ssh"&&ue!=="remote"||L.current||it()},bt=(ue=!1)=>{if(ue){he!==void 0&&(clearTimeout(he),he=void 0),G!==void 0&&(clearTimeout(G),G=void 0),U=0,jt();return}he===void 0&&(he=setTimeout(()=>{he=void 0,jt()},250))};ge.current=bt,O.current=Y;const xt=()=>Z.current?.source==="ssh"||Z.current?.source==="remote",ut=()=>Z.current===null||en(Z.current);return e.connection.onBackendStage(ue=>{if(T||le.current||L.current)return;if(ue==="waiting"){if(!Le||!ut())return;ye(ie=>({stage:"waiting",startedAtMs:ie?.startedAtMs??Date.now()}));return}if(ue!==null&&typeof ue=="object"&&"stage"in ue&&ue.stage==="ready"&&"connection"in ue){if(!ut()&&!xt()||Le&&Be()===null)return;const ie=ue.connection;if(ie===null||typeof ie!="object"||!("url"in ie)||typeof ie.url!="string"||!("token"in ie)||typeof ie.token!="string")return;xt()?ae({config:{url:ie.url,token:ie.token},persist:!1,source:"desktop",scopeId:"local"}):it({url:ie.url,token:ie.token});return}if(ue===null||typeof ue!="object"||!("stage"in ue)||ue.stage!=="failed"||!("failure"in ue)||!ut()||(j+=1,Le=!1,at(ue.failure)))return;ae(null),D.current+=1,N(null),k(null),V(null),ye(null);const Ue=ci(ue.failure);te(Ue),Ue.kind===void 0?Y():X()}).then(ue=>{T?ue():(q=ue,it())},()=>{it()}),()=>{T=!0,j+=1,he!==void 0&&clearTimeout(he),G!==void 0&&clearTimeout(G),O.current===Y&&(O.current=void 0),ge.current===bt&&(ge.current=void 0),q?.()}},[e,ee,ae,f]);const Se=E.useCallback(()=>{te(null),V(null),ye({stage:"spawning",startedAtMs:Date.now()}),re(T=>T+1)},[]),qe=E.useCallback(()=>{le.current=!0,ye(null),te({message:o("connect.desktopCancelled"),stderrTail:[],logPath:null}),e.connection.cancelStartup?.().catch(()=>{})},[e,o]),et=H?.config.url.trim().replace(/\/+$/,"")??null,It=H?.config.token.trim()??null,[St,$e]=E.useState(null),lt=E.useRef(St);lt.current=St;const yt=H!==null&&St?.selection===H?St.client:null,pt=E.useRef(yt);pt.current=yt;const Ft=E.useRef(null);E.useEffect(()=>{if(H===null||et===null||It===null||!Bs(et)){$e(null);return}if(lt.current?.selection===H&&lt.current.timeoutMs===f)return;let T;try{T=new pn({baseUrl:et,token:It,timeoutMs:f,onSessionMutation:j=>{const q=a.current.get(H.scopeId??"local");q!==void 0&&us(q,j)}})}catch{$e(null);return}lt.current={selection:H,client:T,timeoutMs:f},$e(lt.current)},[H,et,It,f]),E.useEffect(()=>{const T=ke.current,j=a.current;return()=>{T.clearParked();for(const q of j.values())q.clear()}},[]),E.useEffect(()=>{const T=St?.client,j=ke.current;return()=>{T!==void 0&&(K.current?.client===T&&(K.current=null),$.current?.client===T&&($.current=null),j.evictScope(T),typeof T.dispose=="function"?T.dispose():T.klient.close())}},[St?.client]),E.useEffect(()=>{if(!(e.kind!=="tauri"||yt===null||p?.source!=="ssh"&&p?.source!=="remote"))return yt.klient.terminal.onStatus(T=>{T==="closed"&&ge.current?.()})},[e,yt,p?.source]);const Nt=S?.url.trim().replace(/\/+$/,"")??null,zt=S?.token.trim()??null,[At,$t]=E.useState(null),xn=p?.source==="desktop"||H!==null&&p===H,_n=ze.current?.selection===p?ze.current:null,Tn=xn?yt:null,xe=_n?.client??(At?.endpoint===Nt&&At.token===zt&&At.scopeId===w&&(!xn||At.client===Tn)?At.client:null);Te.current=xe;const st=xe?.klient??null;E.useEffect(()=>{if(e.kind==="tauri"||p?.source!=="local-detection"||i)return;let T=!1,j=!1,q=0,G,U,Y=0;const X=()=>{U!==void 0&&(clearTimeout(U),U=void 0),Y=0},Be=()=>{const he=K.current;return he!==null&&he.selection===Z.current&&he.selection.source==="local-detection"&&he.client===Te.current?he:null},at=()=>{if(T||U!==void 0||I.current==="open")return;const he=Math.min(1e3*2**Math.min(Y++,4),1e4);U=setTimeout(()=>{U=void 0,!(T||L.current||I.current==="open")&&Z.current?.source==="local-detection"&&Le()},he)},Le=()=>{if(T||j||L.current)return;const he=Be();if(he===null)return;j=!0;const jt=++q,bt=D.current,xt=()=>!T&&jt===q&&D.current===bt&&Be()===he;e.connection.discover().then(async ut=>{if(!xt())return;if(ut===null){at();return}if(Yo(he.selection.config,ut.config)){X(),I.current!=="open"&&he.client.klient.terminal.nudge();return}const Ue=ut.config.url.trim().replace(/\/+$/,""),ie=ut.config.token.trim(),_t=new pn({baseUrl:Ue,token:ie,timeoutMs:f});let pe;try{pe=await _t.meta()}finally{_t.klient.close()}if(!xt()||he.meta.server_home_id&&pe.server_home_id&&he.meta.server_home_id!==pe.server_home_id||he.meta.current_space_id!==void 0&&pe.current_space_id!==void 0&&he.meta.current_space_id!==pe.current_space_id)return;X();const Ve={config:ut.config,persist:!1,source:"local-detection",scopeId:he.scopeId};se.current=!0;try{he.client.rebindDesktop(ut.config)}finally{se.current=!1}ce.current=he.client,D.current+=1,Ft.current={client:he.client,meta:pe},$t({endpoint:Ue,token:ie,scopeId:he.scopeId,client:he.client}),Z.current=Ve,k(Ve),K.current={...he,selection:Ve,meta:pe},N(pe),V(null),C.invalidateQueries()}).catch(()=>{xt()&&at()}).finally(()=>{jt===q&&(j=!1)})},it=(he=!1)=>{if(he){G!==void 0&&(clearTimeout(G),G=void 0),X(),Le();return}G===void 0&&(G=setTimeout(()=>{G=void 0,Le()},250))};return ge.current=it,()=>{T=!0,q+=1,G!==void 0&&clearTimeout(G),U!==void 0&&clearTimeout(U),ge.current===it&&(ge.current=void 0)}},[e,p?.source,f,C]),E.useEffect(()=>{if(Nt===null||zt===null||xn&&Tn===null)return;if(!Bs(Nt)){$t(null),N(null),V({kind:"key",key:"st.conn.urlInvalid"});return}const T=U=>{us(C,U)},j=ce.current!==null&&At?.client===ce.current?ce.current:null;let q;try{q=_n?.client??Tn??j??(p?.source==="remote"?vi({endpoint:Nt,token:zt,connectionId:p.connectionId,timeoutMs:f,onSessionMutation:T}):new pn({baseUrl:Nt,token:zt,timeoutMs:f,onSessionMutation:T}))}catch(U){$t(null),N(null),V({kind:"raw",text:U instanceof Error?U.message:String(U)});return}ce.current===q&&(ce.current=null),$t({endpoint:Nt,token:zt,scopeId:w,client:q});const G=ke.current;return()=>{q===Tn||q===pt.current||q===ce.current||(K.current?.client===q&&(K.current=null),$.current?.client===q&&($.current=null),G.evictScope(q),typeof q.dispose=="function"?q.dispose():q.klient.close())}},[Nt,zt,w,f,C,xn,Tn,_n?.client]),E.useEffect(()=>{if(xe===null||l.current!==null&&p?.source!=="remote")return;let T=!1,j;const q=D.current;V(null);const G=_n?.client===xe?_n:Ft.current?.client===xe?Ft.current:null;return G!==null&&(Ft.current=null),(G!==null?Promise.resolve(G.meta):xe.meta()).then(U=>{if(!(T||q!==D.current)){if(B(!1),hi(),p?.source==="ssh"){const Y=p.serverHomeId,X=de.current.get(w);if(!Y||!p.serverInstanceId||!p.serverVersion||U.server_home_id!==Y||U.server_id!==p.serverInstanceId||U.server_version!==p.serverVersion||U.dangerous_bypass_auth!==!1||(U.build_id??null)!==p.buildId||(U.build_channel??null)!==p.buildChannel||X!==void 0&&X!==Y){N(null),V({kind:"raw",text:"SSH server identity changed or could not be verified. This connection is blocked."});return}de.current.set(w,Y)}if(p?.source==="remote"&&(!p.serverHomeId||U.server_home_id!==p.serverHomeId)){N(null),V({kind:"raw",text:"identity-mismatch"});return}p?.source!=="remote"&&p?.source!=="stored"&&p?.source!=="app-shell"&&p?.persist===!0&&S!==null&&oa(S),(p?.source==="desktop"||p?.source==="local-detection")&&p===Z.current&&(K.current={selection:p,client:xe,meta:U,homeId:_,scopeId:w},$.current=null),N(U)}},U=>{if(T||q!==D.current)return;N(null);const Y=U instanceof Ee||U instanceof Error?U.message:String(U),X=U instanceof Ee||typeof U?.code=="number"?U.code:typeof U?.status=="number"?U.status:void 0,Be=X===401||X===403||X===40100||X===Ce.UNAUTHORIZED||X===40300||X===40301;p?.source==="app-shell"||i&&p?.source==="local-detection"?(B(Be),Be||(j=setTimeout(()=>{!T&&q===D.current&&z(at=>at+1)},1500))):B(!1),V({kind:"raw",text:Y}),hi(),p?.source==="desktop"&&O.current?.()}),()=>{T=!0,j!==void 0&&clearTimeout(j)}},[xe,S,p?.persist,p?.source,R]);const Wt=S!==null&&F!==null&&xe!==null;E.useEffect(()=>{if(!Wt||xe===null||Pg(p?.source))return;let T;const j=()=>{xe.renewLease({clientId:He.current,kind:"gui"}).catch(q=>{Vn(q)&&T!==void 0&&(window.clearInterval(T),T=void 0)})};return j(),T=window.setInterval(j,av),()=>{T!==void 0&&window.clearInterval(T)}},[xe,Wt,p?.source]),E.useEffect(()=>{if(!Wt||p?.source!=="ssh"||!e.connection.sshTunnelRunning)return;const T=p.profile?.id,j=p.tunnelId;if(!T||!j)return;let q=!0,G=!1;const U=()=>{G||(G=!0,e.connection.sshTunnelRunning(T,j).then(X=>{!q||X||(D.current+=1,N(null),V({kind:"raw",text:"SSH tunnel disconnected. Check the remote service and connect again."}))},X=>{q&&(D.current+=1,N(null),V({kind:"raw",text:`Cannot check the SSH tunnel: ${String(X)}`}))}).finally(()=>{G=!1}))};U();const Y=window.setInterval(U,2e3);return()=>{q=!1,window.clearInterval(Y)}},[Wt,p?.source,p?.profile?.id,p?.tunnelId,e]);const rr=xn||p?.source==="local-detection",wt=E.useMemo(()=>{const T=Wt?st?.terminal??null:null;return T===null||!rr?T:{...T,nudge:()=>{$.current?.client===xe&&$.current.phase==="blocked"||(T.nudge(),($.current?.client===xe||I.current!=="open")&&ge.current?.(!0))}}},[Wt,st,xe,rr]);E.useEffect(()=>{if(wt===null||st===null)return;let T=!0,j=!1;y.current=!1,P(!0);let q,G=setTimeout(()=>{G=void 0,!(!T||y.current)&&(y.current=!0,P(!1))},2500);const U=()=>{const pe=st.events.on("search.indexStateChanged",Ve=>{C.cancelQueries({queryKey:["search-index-state"]}).then(()=>{T&&Y===pe&&C.setQueryData(["search-index-state"],Ve)})});return pe.ready.then(()=>{if(T&&Y===pe)return C.invalidateQueries({queryKey:["search-index-state"]})}).catch(()=>{}),pe};let Y=U(),X=Ko(st,C),Be=Go(st,C),at=Qo(st,C);const Le=new Map;let it,he=0;const jt=120,bt=pe=>{!T||pe.length===0||(he=Date.now(),E.startTransition(()=>{C.setQueriesData({queryKey:["sessions"]},Ve=>{let Ye=Ve;for(const ft of pe)Ye=Sl(Ye,ft);return Ye}),C.setQueriesData({queryKey:["thread-ref"]},Ve=>{if(Ve===void 0)return Ve;let Ye=Ve;for(const ft of pe)Ye=xl(Ye,ft);return Ye})}))},xt=()=>{if(it=void 0,!T||Le.size===0)return;const pe=Cs();if(pe>0){it=setTimeout(xt,pe);return}const Ve=[...Le.values()];Le.clear(),bt(Ve)},ut=st.events.on("session.workChanged",pe=>{const Ve=Cs(),Ye=he>0?Math.max(0,jt-(Date.now()-he)):0,ft=Math.max(Ve,Ye);if(ft<=0&&Le.size===0&&it===void 0){bt([pe]);return}Le.set(pe.sessionId,pe),it===void 0&&(it=setTimeout(xt,ft))}),ue=wt.onStatus(pe=>{if(!T)return;I.current=pe;const Ve=$.current?.client===xe?$.current:null;pe==="open"?(j=!0,y.current=!0,G!==void 0&&(clearTimeout(G),G=void 0),q!==void 0&&(clearTimeout(q),q=void 0),P(!0)):j?Ve?.phase==="blocked"||Ve?.phase==="failed"?(q!==void 0&&(clearTimeout(q),q=void 0),P(!1)):q===void 0&&(q=setTimeout(()=>{q=void 0,T&&I.current!=="open"&&P(!1)},1500)):pe==="closed"&&(y.current=!0,G!==void 0&&(clearTimeout(G),G=void 0),P(!1)),pe==="closed"&&!se.current&&$.current?.phase!=="blocked"&&(e.kind==="tauri"&&en(Z.current)?(xe!==null&&K.current?.client===xe&&$.current===null&&($.current={client:xe,phase:"checking"}),ge.current?.()):e.kind!=="tauri"&&Z.current?.source==="local-detection"&&ge.current?.()),pe==="open"&&$.current?.client===xe&&$.current.phase==="checking"&&$.current.suspended!==!0&&($.current=null);const Ye=$.current?.client===xe?$.current:null,ft=Ye?.phase==="blocked"||Ye?.phase==="failed"?"closed":Ye!==null&&pe==="open"?"connecting":pe;Ze(ft),pe==="open"&&Ye?.phase==="failed"&&ge.current?.(),pe==="open"&&(Y.dispose(),Y=U(),X(),X=Ko(st,C),Be(),Be=Go(st,C),at(),at=Qo(st,C),C.invalidateQueries({queryKey:kn.all}),C.invalidateQueries({queryKey:Es.all}))}),Ue=st.events.on("kosong.changed",()=>{ls({type:"event.model_catalog.changed"},C)});let ie,_t;try{const pe=st.events;typeof pe.on=="function"&&(ie=pe.on("remoteConnections.changed",()=>{ls({type:"event.remote_connections.changed"},C)}),_t=pe.on("portableSpaces.changed",()=>{ls({type:"event.portable_spaces.changed"},C)}))}catch{ie=void 0,_t=void 0}return()=>{T=!1,G!==void 0&&clearTimeout(G),q!==void 0&&clearTimeout(q),it!==void 0&&clearTimeout(it),Le.clear(),ue(),Ue.dispose(),ie?.dispose(),_t?.dispose(),Y.dispose(),ut.dispose(),X(),Be(),at()}},[wt,st,C]),E.useEffect(()=>{if(wt!==null)return Ml()},[wt]);const Xn=E.useCallback(()=>{wt?.nudge();for(const T of ke.current)T.nudge();C.invalidateQueries({queryKey:["sessions"]})},[wt,C]);E.useEffect(()=>{if(wt===null)return;let T;const j=(Y=!1)=>{!Y&&typeof navigator<"u"&&navigator.onLine===!1||(T!==void 0&&clearTimeout(T),T=setTimeout(()=>{T=void 0,!(!Y&&typeof navigator<"u"&&navigator.onLine===!1)&&Xn()},150))},q=()=>{j(!0)},G=()=>{j(!1)},U=()=>{document.visibilityState==="visible"&&j(!1)};return window.addEventListener("online",q),window.addEventListener("focus",G),window.addEventListener("pageshow",G),document.addEventListener("visibilitychange",U),()=>{T!==void 0&&clearTimeout(T),window.removeEventListener("online",q),window.removeEventListener("focus",G),window.removeEventListener("pageshow",G),document.removeEventListener("visibilitychange",U)}},[wt,Xn]),E.useEffect(()=>{if(Wt||p?.source!=="app-shell"&&!(i&&p?.source==="local-detection")||W)return;const T=()=>{V(null),z(q=>q+1)},j=()=>{document.visibilityState==="visible"&&T()};return window.addEventListener("online",T),window.addEventListener("focus",T),window.addEventListener("pageshow",T),document.addEventListener("visibilitychange",j),()=>{window.removeEventListener("online",T),window.removeEventListener("focus",T),window.removeEventListener("pageshow",T),document.removeEventListener("visibilitychange",j)}},[Wt,p?.source,W]);const[or,ar]=E.useState(!1),dr=E.useCallback(()=>{ar(!1)},[]),Mt=E.useRef({scope:{homeId:_,scopeId:w},selection:p,client:xe});Mt.current={scope:{homeId:_,scopeId:w},selection:p,client:xe};const cn=E.useMemo(()=>nv({host:e,active:()=>{const T=Mt.current;if(T.selection===null||T.client===null)throw new Error("No active connection");return{scope:T.scope,selection:T.selection,client:T.client}},local:()=>Me.current!==null&&pt.current!==null?{selection:Me.current,client:pt.current}:null,control:()=>{if(Me.current!==null&&pt.current!==null)return{selection:Me.current,client:pt.current};const T=Mt.current;return T.selection!==null&&T.client!==null&&T.selection.source!=="remote"&&T.selection.source!=="ssh"?{selection:T.selection,client:T.client}:null},createClient:T=>T.source==="remote"?vi({endpoint:T.config.url,token:T.config.token,connectionId:T.connectionId,timeoutMs:f,onSessionMutation:j=>{const q=a.current.get(T.scopeId);q!==void 0&&us(q,j)}}):new pn({baseUrl:T.config.url,token:T.config.token,timeoutMs:f}),reload:()=>{l.current===null&&ar(!0)},preparing:T=>{L.current=T},commit:(T,j,q)=>{if(De.current+=1,D.current+=1,T===Mt.current.selection&&j===Mt.current.client){N(q);return}const G=Mt.current.selection;if(T.source!=="remote"){const X=un();X!==null&&!X.homeId.startsWith("remote:")&&(c.current=X),br(c.current)}else{const X=un();X!==null&&!X.homeId.startsWith("remote:")?c.current=X:br(c.current)}const U=Mt.current.client;if(T.source==="remote"&&G!==null&&G.source!=="remote"&&G.source!=="ssh"&&(!n||Me.current===null||pt.current===null)){const X={...G,scopeId:Mt.current.scope.scopeId};ae(X),U!==null&&(lt.current={selection:X,client:U,timeoutMs:f},pt.current=U,$e(lt.current))}else!n&&T.source!=="remote"&&T.source!=="ssh"&&Me.current!==null&&ae(T);const Y=T.source==="ssh"&&T.profile&&T.tunnelId?{id:T.profile.id,tunnelId:T.tunnelId}:null;J.current=Y,ze.current={selection:T,client:j,meta:q},Z.current=T,k(T),$t({endpoint:T.config.url.trim().replace(/\/+$/,""),token:T.config.token.trim(),scopeId:T.scopeId??"local",client:j}),V(null),N(q)}}),[e,f,n,ae]);E.useEffect(()=>{const T=l.current;if(T===null||xe===null||p?.source==="remote")return;const j=new AbortController;return(async()=>{const q=await cn.prepare(T,j.signal);try{await q.validate(`${window.location.pathname}${window.location.search}${window.location.hash}`,j.signal),j.signal.throwIfAborted(),await q.commit(),l.current=null}catch(G){throw await q.dispose(),G}})().catch(q=>{j.signal.aborted||(N(null),V({kind:"raw",text:q instanceof Error?q.message:String(q)}))}),()=>{j.abort()}},[xe,p?.source,cn]);const cr=E.useCallback(async(T=new AbortController().signal)=>{const j=pt.current,q=Z.current,G=De.current,U=q?.source==="remote"?e.activeSpace===void 0?"main":gi(await e.activeSpace())?.homeId??"main":un()?.homeId??"main",Y=Me.current?.scopeId??"local",X=await cn.prepare({homeId:U,scopeId:Y},T);try{if(T.throwIfAborted(),j!==pt.current||q!==Z.current||G!==De.current)throw new DOMException("Local connection restoration was superseded.","AbortError");await X.commit()}catch(Be){throw await X.dispose(),Be}},[cn,e]),Cn=E.useCallback(()=>{if(F!==null&&xe!==null){Z.current?.source==="remote"?(async()=>{const j=e.activeSpace===void 0?"main":gi(await e.activeSpace())?.homeId??"main";await Ls({homeId:j,scopeId:Me.current?.scopeId??"local"})})().catch(()=>{}):Ls({scopeId:"local"}).catch(()=>{});return}De.current+=1,D.current+=1;const T=J.current;J.current=null,T!==null&&e.connection.disconnectSshProfile?.(T.id,T.tunnelId).catch(()=>{}),N(null),V(null),k(Me.current),Me.current===null&&n&&Se()},[F,xe,e,n,Se]),qs=E.useCallback(async(T,j)=>{if(Mt.current.client!==null&&Mt.current.selection!==null){await Ls({scopeId:`ssh:${T}`,token:j});return}if(!e.connection.connectSshProfile||!e.connection.listSshProfiles)throw new Error("SSH connections are available only in the desktop application.");const q=++De.current,U=(await e.connection.listSshProfiles()).find(Be=>Be.id===T);if(!U)throw new Error("SSH profile no longer exists.");if(!U.serverHomeId||!U.remotePort||!/^[A-Za-z0-9_-]{43}$/.test(j))throw new Error("Set the remote Kiki port, expected home ID and bearer token first.");const Y=await e.connection.connectSshProfile(T,j);if(q!==De.current){Y.tunnelId&&e.connection.disconnectSshProfile?.(T,Y.tunnelId).catch(()=>{});return}let X;try{X=new URL(Y.config.url)}catch{X=null}if(X?.protocol!=="http:"||X.hostname!=="127.0.0.1"||X.username||X.password||!X.port||!Y.tunnelId||Y.config.token!==j||Y.serverHomeId!==U.serverHomeId)throw Y.tunnelId&&e.connection.disconnectSshProfile?.(T,Y.tunnelId).catch(()=>{}),new Error("SSH tunnel endpoint or server home ID could not be verified.");J.current={id:T,tunnelId:Y.tunnelId},D.current+=1,N(null),V(null),k({config:Y.config,persist:!1,source:"ssh",scopeId:`ssh:${T}`,profile:U,tunnelId:Y.tunnelId,serverHomeId:Y.serverHomeId,serverInstanceId:Y.serverInstanceId,serverVersion:Y.serverVersion,buildId:Y.buildId,buildChannel:Y.buildChannel})},[e]),Fs=E.useCallback(()=>{if(Z.current?.source==="ssh"){Cn();return}D.current+=1,ln(window),yl(),i&&ae(null),N(null),k(null),V(null),hi()},[Cn,i,ae]),jc=E.useCallback(()=>{_l(),h({kind:"none"}),m(void 0)},[]),Ns=E.useCallback((T,j=!0)=>{const q=Z.current,G=q?.source==="app-shell"||i&&q?.source==="local-detection",U=(G?q.config.token.trim():null)??nt.current??Zn(window)?.trim()??null,Y=T.url.trim(),X=Y.replace(/\/+$/,""),Be=typeof window<"u"?window.location.origin.replace(/\/+$/,""):"",at=X===""||X===Be,Le=T.token.trim();if(!Bs(Y)){const bt=++D.current;$t(null),N(null),V({kind:"key",key:"st.conn.urlInvalid"}),k({config:{url:Y,token:Le},persist:!1,source:j?"manual":"local-detection",scopeId:`direct:${X}:${bt}`});return}if(U!==null&&U!==""&&(Le===U||G&&Le==="")){const bt=++D.current;if(V(null),N(null),at){if(i){const ut={config:{url:Y,token:U},persist:!1,source:"local-detection",scopeId:"local"};ae(ut),k(ut);return}const xt=q!==null&&q.source==="app-shell"&&q.config.url.trim().replace(/\/+$/,"")===X&&q.config.token.trim()===U;k({config:{url:Y,token:U},persist:!1,source:"app-shell",scopeId:xt?q.scopeId:`direct:${X}:${bt}`});return}i&&ae(null),k({config:{url:Y,token:""},persist:!1,source:"local-detection",scopeId:`direct:${X}:${bt}`});return}j&&(nt.current=null,ln(window),i&&ae(null));const he=++D.current,jt=q!==null&&q.config.url.trim().replace(/\/+$/,"")===X&&q.config.token.trim()===Le;V(null),N(null),k({config:{url:Y,token:Le},persist:j,source:j?"manual":"local-detection",scopeId:jt?q.scopeId:`direct:${X}:${he}`})},[i,ae]),lr=E.useCallback(T=>{const j=T.trim();if(!j)return;const q=Z.current;if(q?.source==="web-cookie"){ln(window);return}nt.current=j,B(!1);const G=typeof window<"u"?window.location.origin.replace(/\/+$/,""):"",U=q?.config.url.trim().replace(/\/+$/,"")??"",Y=i?"local-detection":"app-shell";if(q!==null&&q.source===Y&&(U===""||U===G)&&q.config.token.trim()===j){i&&Me.current===null&&ae(q),V(null),z(at=>at+1);return}const X=++D.current;V(null),N(null);const Be=i?{config:{url:"",token:j},persist:!1,source:"local-detection",scopeId:"local"}:{config:{url:"",token:j},persist:!1,source:"app-shell",scopeId:`direct::${X}`};i&&ae(Be),k(Be)},[i,ae]),Bc=E.useCallback(()=>{const T=Z.current,j=T?.source==="app-shell"||i&&T?.source==="local-detection",q=(j?T.config.token.trim():null)??nt.current??Zn(window)?.trim()??null;if(!q)return;if(B(!1),V(null),j){i&&Me.current===null&&T!==null&&ae(T),z(Y=>Y+1);return}const G=++D.current;N(null);const U=i?{config:{url:"",token:q},persist:!1,source:"local-detection",scopeId:"local"}:{config:{url:"",token:q},persist:!1,source:"app-shell",scopeId:`direct::${G}`};i&&ae(U),k(U)},[i,ae]),ur=E.useCallback(T=>{const j=Z.current;j?.source==="ssh"||j?.source==="remote"||Ns(T,!0)},[Ns]);E.useEffect(()=>{if(!(n||s)){if(Z.current?.source==="web-cookie"){ln(window);return}return kl(window,({token:T})=>{lr(T)})}},[n,s,lr]);const fr=E.useMemo(()=>{if(S===null||xe===null||st===null||wt===null||F===null)return null;const T=p?.source==="desktop"&&$.current?.client===xe?$.current:null,j=c.current?.homeId??(x===null?_:"main"),q=H?.scopeId??Me.current?.scopeId??(p?.source!=="remote"&&p?.source!=="ssh"?w:"local");return{connectionId:x,connectionSource:p?.source??null,spaceKey:_,localSpaceKey:j,localScopeId:q,localServerHomeId:p?.source==="remote"?void 0:F.server_home_id,scopeId:w,connectionRef:p?.source==="remote"?p.connectionId:p?.source==="ssh"?p.tunnelId:void 0,sshLabel:p?.profile?.label??null,activateSshProfile:qs,activateLocal:Cn,restoreLocal:cr,scopeAdapter:cn,needsScopeReload:or,clearScopeReload:dr,config:S,client:xe,localClient:yt,klient:st,socket:wt,meta:F,wsStatus:Oe,wsBannerSuppressed:Je,recovery:T===null||T.phase==="checking"&&Je?void 0:{status:T.phase==="blocked"?"blocked":"retrying",failure:Fe},nudge:Xn,disconnect:Fs,applyConnection:ur}},[x,b,_,w,H?.scopeId,p?.source,p?.tunnelId,p?.profile?.label,qs,Cn,cr,cn,or,dr,S,xe,yt,st,wt,F,Oe,Je,Fe,Xn,Fs,ur]),Rn=me===null?null:me.kind==="key"?ia(r,me.key,me.params):me.text,Lc=p?.source==="ssh"?Rn===null?null:{message:Rn,stderrTail:[],logPath:null}:Fe??(n&&Rn!==null?{message:Rn,stderrTail:[],logPath:null}:null),Hc=Ne(p?.source)||nt.current!==null||Zn(typeof window<"u"?window:void 0)!==null;return A.jsx(Yn.Provider,{value:fr,children:fr!==null?A.jsx(Il,{client:C,children:A.jsx(Ds.Provider,{value:ke.current,children:t})}):A.jsx(xg,{initial:Ne(p?.source)?{url:S?.url??"",token:""}:S??{url:"",token:""},connecting:we!==null||S!==null&&me===null,error:n?null:Rn,onConnect:Ns,onBack:n?void 0:S!==null?Fs:void 0,desktopBoot:we,desktopFailure:Lc,onRetryDesktop:Se,onCancelDesktopBoot:qe,onConnectSsh:qs,onSwitchLocal:p?.source==="ssh"?Cn:void 0,sshProfile:p?.source==="ssh"?p.profile:void 0,webLink:v,onRetryWebLink:jc,onRetryPaired:Hc?Bc:void 0,pairedAuthRevoked:W})})}const Ds=E.createContext(null),lv=Ds.Provider;function uv(){const t=E.useContext(Ds);if(t===null)throw new Error("useControllerRegistry outside provider");return t}function fv(){return E.useContext(Ds)}function hv({value:t,children:e}){return A.jsx(Yn.Provider,{value:t,children:e})}function pv(){const t=E.useContext(Yn);if(t===null)throw new Error("useConnection used before connecting");return t}function mv(){return E.useContext(Yn)}const V0=Object.freeze(Object.defineProperty({__proto__:null,ConnectionContext:Yn,ConnectionProvider:cv,ConnectionScope:hv,ControllerRegistryProvider:lv,LiveControllerRegistry:Nc,VIEW_CACHE_MAX_BYTES:ir,VIEW_CACHE_MAX_ENTRY_BYTES:iv,VIEW_CACHE_MAX_LIVE_PARKED:Fc,VIEW_CACHE_MAX_PARKED:Dc,VIEW_CACHE_TTL_MS:qc,handleGlobalConnectionFrame:ls,isDesktopSelection:en,isProtectedView:fs,nextGuiLeaseClientId:$c,refreshSessionAttention:us,useConnection:pv,useControllerRegistry:uv,useOptionalConnection:mv,useOptionalControllerRegistry:fv},Symbol.toStringTag,{value:"Module"}));export{Zv as $,v0 as A,q0 as B,Rs as C,Ig as D,j0 as E,B0 as F,L0 as G,Ug as H,Hi as I,y0 as J,Wg as K,N0 as L,$0 as M,C0 as N,Hg as O,F0 as P,k0 as Q,T0 as R,wg as S,qg as T,r0 as U,f0 as V,Cc as W,o0 as X,Tc as Y,h0 as Z,u0 as _,mv as a,e0 as a$,l0 as a0,a0 as a1,p0 as a2,Es as a3,t0 as a4,n0 as a5,Xv as a6,c0 as a7,s0 as a8,_u as a9,Hv as aA,Nv as aB,jv as aC,Bv as aD,id as aE,ha as aF,Av as aG,Iv as aH,ys as aI,Yv as aJ,Uv as aK,Wv as aL,Xt as aM,Xg as aN,Yt as aO,Au as aP,_v as aQ,lp as aR,fp as aS,I0 as aT,w0 as aU,R0 as aV,A0 as aW,E0 as aX,P0 as aY,O0 as aZ,i0 as a_,Gh as aa,Tv as ab,Cv as ac,Cs as ad,qv as ae,Dv as af,Fv as ag,Lv as ah,Kv as ai,Jg as aj,Ru as ak,Jn as al,bv as am,wv as an,Er as ao,Rt as ap,fv as aq,H0 as ar,z0 as as,Qv as at,Vv as au,zv as av,dt as aw,Dn as ax,Ai as ay,xf as az,Ov as b,d0 as b0,Fg as b1,Or as b2,xv as b3,Sv as b4,us as b5,hv as b6,wf as b7,Ev as b8,_i as b9,Rv as ba,ba as bb,ni as bc,V0 as bd,m0 as c,Vn as d,Pg as e,Pv as f,Mv as g,Jv as h,W0 as i,Sa as j,Q as k,uv as l,Gv as m,Lg as n,U0 as o,$v as p,S0 as q,kn as r,b0 as s,_0 as t,pv as u,D0 as v,x0 as w,M0 as x,Rc as y,g0 as z};