@agimon-ai/po-cloudflare 0.0.2-alpha.63 → 0.0.2-alpha.64

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 (193) hide show
  1. package/README.md +13 -0
  2. package/dist/apiContracts-CNEgbJwj.js +1715 -0
  3. package/dist/assets/assets/{CodeEditorView-CNdPF2Z8.js → CodeEditorView-D7pzNIoH.js} +2 -2
  4. package/dist/assets/assets/{abnfDiagram-WEYOIA3C-BpEuH9tc.js → abnfDiagram-WEYOIA3C-CxtSKgjr.js} +2 -2
  5. package/dist/assets/assets/{architecture-WOLXFQ4H-CO9IcYuJ.js → architecture-WOLXFQ4H-CtnQTAsr.js} +1 -1
  6. package/dist/assets/assets/{architectureDiagram-ZHVYKT53-B94avglc.js → architectureDiagram-ZHVYKT53-DE2dNllJ.js} +2 -2
  7. package/dist/assets/assets/{blockDiagram-RJAE7QA3-Dyj_IG8P.js → blockDiagram-RJAE7QA3-Cw4dFyL6.js} +2 -2
  8. package/dist/assets/assets/{c4Diagram-XDPPPE54-kCCb9Nvu.js → c4Diagram-XDPPPE54-BX8ZmJNh.js} +2 -2
  9. package/dist/assets/assets/channel-CMUucV-0.js +2 -0
  10. package/dist/assets/assets/{chunk-2E7WHVMD-aabTbQRn.js → chunk-2E7WHVMD-CjyWoAjP.js} +2 -2
  11. package/dist/assets/assets/{chunk-4EMNKR2T-BfyoxA4A.js → chunk-4EMNKR2T-BGT3YuPv.js} +2 -2
  12. package/dist/assets/assets/{chunk-55XCU76K-Cb2-H5PY.js → chunk-55XCU76K-zOmV9K85.js} +2 -2
  13. package/dist/assets/assets/{chunk-7S6XSTFO-DF4Vz0iS.js → chunk-7S6XSTFO-CT9Du8QX.js} +2 -2
  14. package/dist/assets/assets/{chunk-AQDTSKZB-DYfgedyG.js → chunk-AQDTSKZB-DlFeSSC4.js} +2 -2
  15. package/dist/assets/assets/{chunk-DSNLSHJZ-ELMVWOH-.js → chunk-DSNLSHJZ-C-ZPBYet.js} +2 -2
  16. package/dist/assets/assets/{chunk-HAGFOTED-BfFyqWkw.js → chunk-HAGFOTED-BoAjQX39.js} +2 -2
  17. package/dist/assets/assets/{chunk-HNE4Q36P-brfLLH1k.js → chunk-HNE4Q36P-DIq-EGSJ.js} +2 -2
  18. package/dist/assets/assets/{chunk-NQOKRVIF-BPeBTdMj.js → chunk-NQOKRVIF-DCZggr3o.js} +2 -2
  19. package/dist/assets/assets/{chunk-UHW7PFBP-Pm1hUsoy.js → chunk-UHW7PFBP-Do_Zzrrp.js} +2 -2
  20. package/dist/assets/assets/{chunk-VQ5W62QI-DNrJHI3b.js → chunk-VQ5W62QI-CTQ1DMtJ.js} +2 -2
  21. package/dist/assets/assets/{chunk-WQQL4CDK-Bn-i8xPd.js → chunk-WQQL4CDK-Ki6uR6r0.js} +2 -2
  22. package/dist/assets/assets/chunk-XXDRQBXY-CQICwlCf.js +2 -0
  23. package/dist/assets/assets/{chunk-YZO67HFG-Bm3Y2k41.js → chunk-YZO67HFG-B296g6FE.js} +2 -2
  24. package/dist/assets/assets/{chunk-ZAUX2LTX-wKlSN4SY.js → chunk-ZAUX2LTX-BpPT7rvX.js} +2 -2
  25. package/dist/assets/assets/{chunk-ZCHMQSOR-vvsZwzKx.js → chunk-ZCHMQSOR-Di0VGZer.js} +2 -2
  26. package/dist/assets/assets/{classDiagram-v2-4MYWR3UA-B4fv93fc.js → classDiagram-v2-4MYWR3UA-CGj_lJO_.js} +2 -2
  27. package/dist/assets/assets/{cose-bilkent-JH36ORCC-CakncvlM.js → cose-bilkent-JH36ORCC-DY0BbQbd.js} +2 -2
  28. package/dist/assets/assets/{cynefin-EF2NZ3EQ-BmPuG-jp.js → cynefin-EF2NZ3EQ-CMMUJeFf.js} +1 -1
  29. package/dist/assets/assets/{cynefinDiagram-WF24UDRP-w05E3pMy.js → cynefinDiagram-WF24UDRP-BbOif1OC.js} +2 -2
  30. package/dist/assets/assets/{dagre-NK4GIZVX-DtBjSPFH.js → dagre-NK4GIZVX-CphjGdnN.js} +2 -2
  31. package/dist/assets/assets/{diagram-CBK3MWTC-BFSVYioV.js → diagram-CBK3MWTC-DpGUyRf7.js} +2 -2
  32. package/dist/assets/assets/{diagram-I5XIIV2D-BDvStF0J.js → diagram-I5XIIV2D-DcYA8tlL.js} +2 -2
  33. package/dist/assets/assets/{diagram-ODIL2UCW-DARMBHRQ.js → diagram-ODIL2UCW-ChPOrrmO.js} +2 -2
  34. package/dist/assets/assets/{diagram-PFBEJUXE-Pj4fyqwM.js → diagram-PFBEJUXE-BfPiSQ9L.js} +2 -2
  35. package/dist/assets/assets/{diagram-RJA3I4VV-BaKg3wpn.js → diagram-RJA3I4VV-rLXVMix5.js} +2 -2
  36. package/dist/assets/assets/{diagram-TYUNFSNR-CefzxlNs.js → diagram-TYUNFSNR-BTmEjrYt.js} +2 -2
  37. package/dist/assets/assets/{dist-DEWrC__B.js → dist-1L_Ajly9.js} +2 -2
  38. package/dist/assets/assets/{dist-Cghv4o0_.js → dist-48390Dmg.js} +2 -2
  39. package/dist/assets/assets/{dist-CHFfGcfR.js → dist-BAD8d1kv.js} +2 -2
  40. package/dist/assets/assets/{dist-B9ZDItnO.js → dist-BJLZuu6S.js} +2 -2
  41. package/dist/assets/assets/{dist-EAEtfW9R.js → dist-BlSnUUI6.js} +2 -2
  42. package/dist/assets/assets/{dist-D5maITN-.js → dist-CobUSto6.js} +2 -2
  43. package/dist/assets/assets/{dist-CxVXLY-8.js → dist-DAGWxegY.js} +2 -2
  44. package/dist/assets/assets/{dist-CGCZs-fG.js → dist-DLPWqzfx.js} +2 -2
  45. package/dist/assets/assets/{dist-DtehQ6Vh.js → dist-QjSb6UwP.js} +2 -2
  46. package/dist/assets/assets/{ebnfDiagram-V4P3TTPT-YewZYnYk.js → ebnfDiagram-V4P3TTPT-BN1myPAM.js} +2 -2
  47. package/dist/assets/assets/{elk-QONTBCTQ-dVpXxU0t.js → elk-QONTBCTQ-C4yJXrim.js} +2 -2
  48. package/dist/assets/assets/{erDiagram-KYQIGQAA-DppuSwGu.js → erDiagram-KYQIGQAA-BLGAHUjY.js} +2 -2
  49. package/dist/assets/assets/{eventmodeling-K75KTNOO-CjOlr5k9.js → eventmodeling-K75KTNOO-BNsbrLPW.js} +1 -1
  50. package/dist/assets/assets/flowDiagram-IUGLLWBU-GEvUvJMe.js +1 -0
  51. package/dist/assets/assets/{ganttDiagram-R7GPNTJY-BiP9tCoR.js → ganttDiagram-R7GPNTJY-Dtt1cLvU.js} +2 -2
  52. package/dist/assets/assets/{gitGraph-VSP46ZUC-D_37KmzW.js → gitGraph-VSP46ZUC-BB3jyory.js} +1 -1
  53. package/dist/assets/assets/{gitGraphDiagram-PDYL7XHY-BpPyCOnT.js → gitGraphDiagram-PDYL7XHY-5dxhMcQJ.js} +2 -2
  54. package/dist/assets/assets/index-BEh1IFrK.js +256 -0
  55. package/dist/assets/assets/{info-OHQRW6UA-BzB_vPCs.js → info-OHQRW6UA-B6a4Z_NG.js} +1 -1
  56. package/dist/assets/assets/{infoDiagram-MVDRKAX5-H2O0q8Pc.js → infoDiagram-MVDRKAX5-D4WPnECO.js} +2 -2
  57. package/dist/assets/assets/{ishikawaDiagram-HPEHV2GE-CxgN92Oj.js → ishikawaDiagram-HPEHV2GE-7qHvZhsy.js} +2 -2
  58. package/dist/assets/assets/{journeyDiagram-BOSHW7O7-Cgi2OOJn.js → journeyDiagram-BOSHW7O7-CX3Bn1wZ.js} +2 -2
  59. package/dist/assets/assets/{kanban-definition-FNSA4HC5-DfNFv9yJ.js → kanban-definition-FNSA4HC5-DhEPG70e.js} +2 -2
  60. package/dist/assets/assets/{line-BsuG8Uxt.js → line-ChDBcVMC.js} +2 -2
  61. package/dist/assets/assets/{linear-5ygNOtpj.js → linear-BnYwLNuy.js} +2 -2
  62. package/dist/assets/assets/{mermaid-parser.core-BQKUlQNj.js → mermaid-parser.core-CqVdBIHT.js} +4 -4
  63. package/dist/assets/assets/{mermaid.core-mIsoHdG8.js → mermaid.core-q29P4JOO.js} +5 -5
  64. package/dist/assets/assets/{mindmap-definition-6OY57UG3-CwRI3Joj.js → mindmap-definition-6OY57UG3-C74KuyjY.js} +2 -2
  65. package/dist/assets/assets/{packet-JDAUHWVQ-DA3pnTHc.js → packet-JDAUHWVQ-B4LCADWh.js} +1 -1
  66. package/dist/assets/assets/{pegDiagram-ECIUJNBX-CDCKGOxK.js → pegDiagram-ECIUJNBX-Cv2MJ170.js} +2 -2
  67. package/dist/assets/assets/{pie-XZMESJXO-BLhJFhYu.js → pie-XZMESJXO-DotbpRpk.js} +1 -1
  68. package/dist/assets/assets/{pieDiagram-GNMPY74T-DYR-R-dX.js → pieDiagram-GNMPY74T-CChjMnDW.js} +2 -2
  69. package/dist/assets/assets/{quadrantDiagram-D57K4MC3-Bc1eK1F-.js → quadrantDiagram-D57K4MC3-DEYttxps.js} +2 -2
  70. package/dist/assets/assets/{radar-ABXABTNO-EtUBQBSs.js → radar-ABXABTNO-4s5FAd4E.js} +1 -1
  71. package/dist/assets/assets/{railroad-I3PHUGI6-B21qPap-.js → railroad-I3PHUGI6-DBTlhGxt.js} +1 -1
  72. package/dist/assets/assets/{railroad-abnf-LNEFI6M7-BIiwJieY.js → railroad-abnf-LNEFI6M7-D6ziSuiX.js} +1 -1
  73. package/dist/assets/assets/{railroad-ebnf-DWYD2UWJ-DqZK9K0J.js → railroad-ebnf-DWYD2UWJ-CqEIKDB8.js} +1 -1
  74. package/dist/assets/assets/{railroad-peg-JR7BVNR7-CIQgGVCU.js → railroad-peg-JR7BVNR7-CJtfKFNH.js} +1 -1
  75. package/dist/assets/assets/{railroadDiagram-Y72NRBL7-BD_lzGk4.js → railroadDiagram-Y72NRBL7-4mBAJ-Jl.js} +2 -2
  76. package/dist/assets/assets/{requirementDiagram-EQYSW5RA-aDbnnoHS.js → requirementDiagram-EQYSW5RA-BEhHi0QF.js} +2 -2
  77. package/dist/assets/assets/{sankeyDiagram-SY24JHO5-DDdGARNy.js → sankeyDiagram-SY24JHO5-nj_cSwlP.js} +2 -2
  78. package/dist/assets/assets/{sequenceDiagram-BLEHNHQU-BIH_jN1c.js → sequenceDiagram-BLEHNHQU-DNY4na4z.js} +2 -2
  79. package/dist/assets/assets/{src-BaA7Sf5p.js → src-WiWJj6f2.js} +2 -2
  80. package/dist/assets/assets/{stateDiagram-v2-A6IESKWZ-C-dVVPfs.js → stateDiagram-v2-A6IESKWZ-BB9jYF4B.js} +2 -2
  81. package/dist/assets/assets/{swimlanes-B3ENRKFQ-Bw5IOyh7.js → swimlanes-B3ENRKFQ-D87jJRda.js} +2 -2
  82. package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-DehW4Jm2.js +9 -0
  83. package/dist/assets/assets/{timeline-definition-JXYKGLGB-By_uqQTe.js → timeline-definition-JXYKGLGB-C2a6EPko.js} +2 -2
  84. package/dist/assets/assets/{treeView-D4JQ5SDB-BZU7wRHU.js → treeView-D4JQ5SDB-BdB3JJaH.js} +1 -1
  85. package/dist/assets/assets/{treemap-SAJKECNS-N8z3Rl5u.js → treemap-SAJKECNS-BJjjYPG9.js} +1 -1
  86. package/dist/assets/assets/{usecaseDiagram-WPOLBNNX-CuUha2nb.js → usecaseDiagram-WPOLBNNX-DlLWyckj.js} +2 -2
  87. package/dist/assets/assets/{vennDiagram-Q3Y3IDCW-g3YaAylz.js → vennDiagram-Q3Y3IDCW-D6fIfwd9.js} +2 -2
  88. package/dist/assets/assets/{wardley-7MLQ67FV-BvmZvcdT.js → wardley-7MLQ67FV-CSM_VWdu.js} +1 -1
  89. package/dist/assets/assets/{wardleyDiagram-IVAIDKWA-CvNsC8vq.js → wardleyDiagram-IVAIDKWA-CTsqqv0l.js} +2 -2
  90. package/dist/assets/assets/{webpack-mxF5RTCn.js → webpack-Dliwyah1.js} +2 -2
  91. package/dist/assets/assets/{xychartDiagram-4URNHDU4-vCSk0HHw.js → xychartDiagram-4URNHDU4-D49cqPPi.js} +2 -2
  92. package/dist/assets/bundle-asset-policy.json +1 -1
  93. package/dist/assets/index.html +1 -1
  94. package/dist/assets/plugins/assets/base-BsvoTtxC.css +2 -0
  95. package/dist/assets/plugins/chunks/po-web-runtime-B5XS1Vkn.js +1 -0
  96. package/dist/assets/plugins/compositions.json +1 -1
  97. package/dist/assets/plugins/slots/approval.09e72f36-vdtrYSJE.js +2 -0
  98. package/dist/assets/plugins/slots/artifacts.50b639bb-Difr6PJG.js +1 -0
  99. package/dist/assets/plugins/slots/author.fe075392-1ypXiPa9.js +93 -0
  100. package/dist/assets/plugins/slots/{autocompact.f08b6833-BLrybOV_.js → autocompact.6f428144-Da_u6U6S.js} +1 -1
  101. package/dist/assets/plugins/slots/backdrop-bamboo.6e4c928d-BJmw6J1H.js +1 -0
  102. package/dist/assets/plugins/slots/browse.fa1f1a50-DVXthO2Y.js +1 -0
  103. package/dist/assets/plugins/slots/builtin-tools.75108f21-CZVTaRlo.js +7 -0
  104. package/dist/assets/plugins/slots/calendar.d8b70190-It_2gT_o.js +2 -0
  105. package/dist/assets/plugins/slots/codemode.c58fb583--R-ayMy6.js +11 -0
  106. package/dist/assets/plugins/slots/domain.753f9f92-CTWPJ3K3.js +1 -0
  107. package/dist/assets/plugins/slots/edit.804fec90-CnhEiTi_.js +7 -0
  108. package/dist/assets/plugins/slots/files.66ffc636-bPZ6eGF5.js +2 -0
  109. package/dist/assets/plugins/slots/goal.45dffa01-hcQ21LSV.js +1 -0
  110. package/dist/assets/plugins/slots/grep.98262cff-zdlPKmsW.js +1 -0
  111. package/dist/assets/plugins/slots/help.5fbd20f7-DmUDRYKt.js +3 -0
  112. package/dist/assets/plugins/slots/log.cb964209-j2FTMopd.js +4 -0
  113. package/dist/assets/plugins/slots/mcp.82cc1ff5-DJAarFoV.js +55 -0
  114. package/dist/assets/plugins/slots/plan.3852ba52-BAjhNPLw.js +3 -0
  115. package/dist/assets/plugins/slots/{profile.1b4aeee4-NbT6f8xl.js → profile.ab16dcec-DcqHKZZu.js} +1 -1
  116. package/dist/assets/plugins/slots/{prompts.a5509377-D8btnu7Y.js → prompts.ae48c07a-DSpV7n6y.js} +21 -21
  117. package/dist/assets/plugins/slots/read.4560591a-B3vKeI4d.js +1 -0
  118. package/dist/assets/plugins/slots/runner.6e494d59-D7Z9dlE2.js +9 -0
  119. package/dist/assets/plugins/slots/scaffold.d87a6ee0-Cvh_qC8k.js +1 -0
  120. package/dist/assets/plugins/slots/sessions.6f47cb4c-feejch_0.js +1 -0
  121. package/dist/assets/plugins/slots/skill.62a0a1b3-DLuQV0P-.js +4 -0
  122. package/dist/assets/plugins/slots/space.65a27e5a-iOxXji2v.js +1 -0
  123. package/dist/assets/plugins/slots/subagents.8bb9992c-ChTnezHO.js +7 -0
  124. package/dist/assets/plugins/slots/template-advanced.59f3f98a-VbYOjCWb.js +1 -0
  125. package/dist/assets/plugins/slots/template-desktop.0f0b8491-D_LDs6R3.js +7 -0
  126. package/dist/assets/plugins/slots/template-elegant.0e3b0acf-C_Aw5CVD.js +1 -0
  127. package/dist/assets/plugins/slots/vault.3cbfcdc3-BLLijqYx.js +1 -0
  128. package/dist/assets/plugins/slots/voice.a952113d-0N-vCkeV.js +1 -0
  129. package/dist/assets/plugins/slots/web-search.65013836-DSo04wY4.js +1 -0
  130. package/dist/assets/plugins/slots/workflows.cbc5c5c0-pDf69-fN.js +16 -0
  131. package/dist/{index.edge-B0YYwNF0.js → index.edge-CSOYqxQ2.js} +2 -1
  132. package/dist/{server-CCqvf6yh.js → server-BKJC6UYx.js} +1 -2
  133. package/dist/{server-1LZR9ZRX.js → server-BOiCHhpU.js} +1 -1
  134. package/dist/{server-D97tm0wK.js → server-BQxIPMSa.js} +2 -3
  135. package/dist/{server-DhuzpcVR.js → server-BVW5OV5j.js} +1 -1
  136. package/dist/{server-3HPXqwI6.js → server-C8gWYGFl.js} +1 -1
  137. package/dist/{server-rIQkmCUx.js → server-CFLUZq0Z.js} +1 -1
  138. package/dist/{server-DSe28Ebi.js → server-CGUm_4c6.js} +1 -1
  139. package/dist/{server-Nb7tgHv2.js → server-CjL_6u1x.js} +1 -1
  140. package/dist/{server-DNtprCHS.js → server-CkBvJEiI.js} +2 -2
  141. package/dist/{server-COD1HYtb.js → server-CyiKrR7j.js} +1 -1
  142. package/dist/{server-38vPt49q.js → server-DBN_CZxx.js} +1 -1
  143. package/dist/{server-DeBXj3re.js → server-DKFXelb3.js} +2 -2
  144. package/dist/{server-B7ow4_os.js → server-DOI9mJ00.js} +1 -1
  145. package/dist/{server-bO3F28gq.js → server-D_v7Nt6L.js} +1 -1
  146. package/dist/{server-D_0XHzYJ.js → server-DjBZj5Be.js} +1 -1
  147. package/dist/{server-SR4ElcIH.js → server-DpuKPbyY.js} +1 -1
  148. package/dist/{server-CqsGbX44.js → server-DrbaM9P2.js} +2 -3
  149. package/dist/{server-KzfsJGF8.js → server-DykrhovZ.js} +1 -1
  150. package/dist/{server-CR3v0zcN.js → server-EPw6De2W.js} +2 -2
  151. package/dist/{server-B_g35a-5.js → server-FD4p5fz5.js} +1 -1
  152. package/dist/{server-D1_V9Vmd.js → server-XTBK1WrD.js} +1 -1
  153. package/dist/server-c93sCvo3.js +466 -0
  154. package/dist/{server-B7FH93rx.js → server-g9_wMnMD.js} +1 -1
  155. package/dist/worker.js +267 -122
  156. package/package.json +48 -43
  157. package/dist/apiContracts-C5xYJZfw.js +0 -561
  158. package/dist/assets/assets/channel-BDLbYxu3.js +0 -2
  159. package/dist/assets/assets/chunk-XXDRQBXY-D9IZWvba.js +0 -2
  160. package/dist/assets/assets/flowDiagram-IUGLLWBU-9R5zxYVV.js +0 -1
  161. package/dist/assets/assets/index-Dus9Cw5p.js +0 -256
  162. package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-coH9laQJ.js +0 -9
  163. package/dist/assets/plugins/assets/base-ByEdw6HI.css +0 -2
  164. package/dist/assets/plugins/chunks/po-web-runtime-DZvTbTGl.js +0 -1
  165. package/dist/assets/plugins/slots/approval.72ae703a-MJpYBBW3.js +0 -2
  166. package/dist/assets/plugins/slots/artifacts.77a5ce89-BqGpkxIz.js +0 -1
  167. package/dist/assets/plugins/slots/author.1714bd0b-vpvWaIsO.js +0 -93
  168. package/dist/assets/plugins/slots/backdrop-bamboo.8ee8a555-Djii7v-K.js +0 -1
  169. package/dist/assets/plugins/slots/browse.59782354-BCYYZIGg.js +0 -1
  170. package/dist/assets/plugins/slots/builtin-tools.abc3edcc-QrPdFMQO.js +0 -7
  171. package/dist/assets/plugins/slots/calendar.d83ca386-BsY3VUmV.js +0 -2
  172. package/dist/assets/plugins/slots/codemode.c68822dc-BUQr5ZVr.js +0 -11
  173. package/dist/assets/plugins/slots/domain.d3fc60b5-CG6iqO2H.js +0 -1
  174. package/dist/assets/plugins/slots/edit.2aa43041-Bkj7M18J.js +0 -7
  175. package/dist/assets/plugins/slots/files.c1e584ee-CxGGfZ7q.js +0 -2
  176. package/dist/assets/plugins/slots/goal.0d58b5cd-B93fwx0M.js +0 -1
  177. package/dist/assets/plugins/slots/grep.b067b8cb-BH487fbj.js +0 -1
  178. package/dist/assets/plugins/slots/help.e5f29767-Cc-1UAi2.js +0 -3
  179. package/dist/assets/plugins/slots/log.24faf8a0-BmKGSUhs.js +0 -4
  180. package/dist/assets/plugins/slots/mcp.a6805ffa-B1pF9U1U.js +0 -55
  181. package/dist/assets/plugins/slots/plan.cf1a06d8-Bp6s-HU-.js +0 -3
  182. package/dist/assets/plugins/slots/read.a43eeb4a-D8J587IR.js +0 -1
  183. package/dist/assets/plugins/slots/runner.03b699da-kZzobG85.js +0 -9
  184. package/dist/assets/plugins/slots/scaffold.f3763f9c-DSiG8h1F.js +0 -1
  185. package/dist/assets/plugins/slots/sessions.dc7ce5f8-Pqp4CAW1.js +0 -1
  186. package/dist/assets/plugins/slots/skill.2b6ba429-BPCu7SmU.js +0 -4
  187. package/dist/assets/plugins/slots/space.a8901278-DmJaW-f6.js +0 -1
  188. package/dist/assets/plugins/slots/subagents.6f67a972-9xrGKpLe.js +0 -7
  189. package/dist/assets/plugins/slots/vault.593b32bd-BOhqzgok.js +0 -1
  190. package/dist/assets/plugins/slots/voice.fa8f3d31-PQ3c795m.js +0 -1
  191. package/dist/assets/plugins/slots/workflows.41d5eec7-DACCrvVZ.js +0 -16
  192. package/dist/presets-JqH9Fwy9.js +0 -1
  193. package/dist/sessionApiContracts-BDVrjHG1.js +0 -1157
@@ -1 +0,0 @@
1
- import{Er as e,F as t,Fn as n,Fr as r,I as i,J as a,Jn as o,Kr as s,L as c,Ln as l,Mr as u,Nr as d,On as f,Or as p,P as m,Pr as h,Qn as g,Qr as _,R as v,Tr as y,Ut as b,V as x,Vr as S,Wr as C,X as w,Xn as T,Y as E,Yn as ee,Z as te,Zn as ne,_ as D,a as O,ar as re,c as k,cn as ie,er as A,f as ae,g as oe,gt as j,i as M,in as N,it as se,k as ce,n as le,nr as ue,o as de,qn as fe,qr as pe,rt as me,s as P,xn as he,z as ge,zr as _e}from"../chunks/po-web-runtime-DZvTbTGl.js";var ve=`x-po-client-metadata`,ye=`poClient`,be=64;function xe(e){return typeof e==`string`&&/^[A-Za-z0-9_-]{1,64}$/u.test(e)}function Se(e){if(typeof e!=`string`)return;let t=e.replaceAll(/[\p{Cc}\p{Cf}]/gu,``).trim(),n=Array.from(t).length;return n>=1&&n<=be?t:void 0}function Ce(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function we(e){if(!Ce(e))return{status:`invalid`};if(Number.isSafeInteger(e.version)&&e.version!==1)return{status:`unsupported`};let t=Se(e.deviceName);if(e.version!==1||!xe(e.deviceId)||e.instanceId!==void 0&&!xe(e.instanceId)||typeof e.clientKind!=`string`||![`web`,`desktop`,`ios`,`android`].includes(e.clientKind)||t===void 0||!Number.isSafeInteger(e.nameUpdatedAt)||typeof e.nameUpdatedAt!=`number`||e.nameUpdatedAt<0)return{status:`invalid`};for(let t of[`browser`,`platform`])if(e[t]!==void 0&&(Se(e[t])===void 0||Se(e[t])!==e[t]))return{status:`invalid`};return{status:`ok`,metadata:{version:1,deviceId:e.deviceId,...e.instanceId===void 0?{}:{instanceId:e.instanceId},clientKind:e.clientKind,deviceName:t,nameUpdatedAt:e.nameUpdatedAt,...e.browser===void 0?{}:{browser:e.browser},...e.platform===void 0?{}:{platform:e.platform}}}}function Te(e){let t=new TextEncoder().encode(JSON.stringify(e));return btoa(String.fromCharCode(...t)).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replace(/=+$/u,``)}function Ee(e){let t=we(e);if(t.status!==`ok`)throw Error(`Invalid Po client metadata`);let n=Te(t.metadata);if(n.length>2048)throw Error(`Po client metadata exceeds encoded limit`);return n}function De(e){try{if(`preface`in e)return!Ce(e.preface)||!Object.hasOwn(e.preface,`poClient`)?{status:`absent`}:Object.keys(e.preface).length!==1||Te(e.preface.poClient).length>2048?{status:`invalid`}:we(e.preface.poClient);let t;if(`query`in e){let n=e.query.getAll(ye);if(n.length>1)return{status:`invalid`};t=n[0]}else t=e.header;if(t==null)return{status:`absent`};if(t.length>2048||!/^[A-Za-z0-9_-]+$/u.test(t))return{status:`invalid`};let n=atob(t.replaceAll(`-`,`+`).replaceAll(`_`,`/`)),r=Uint8Array.from(n,e=>e.charCodeAt(0)),i=new TextDecoder(`utf-8`,{fatal:!0}).decode(r);return btoa(n).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replace(/=+$/u,``)===t?we(JSON.parse(i)):{status:`invalid`}}catch{return{status:`invalid`}}}var F=16e3,Oe=`application/vnd.po.pcm-s16le`,ke=`x-po-voice-activity-state`,Ae=`x-po-voice-activity-level`,je=`x-po-voice-activity-elapsed`,Me=`x-po-voice-activity-epoch`,Ne=`x-po-voice-activity-speech-ms`,Pe=`x-po-voice-activity-echo-speech-ms`,Fe=`voice_media_wake`,I={clientConnect:`/client/connect`,clientDisconnect:`/client/disconnect`,clientEvents:`/client/events`,clientHeartbeat:`/client/heartbeat`,clientAudio:`/client/audio`,clientCaptureStopped:`/client/capture-stopped`,clientPlaybackAudio:`/client/playback-audio`,clientPlaybackResult:`/client/playback-result`,hostCaptureStart:`/host/capture/start`,hostCaptureAudio:`/host/capture/audio`,hostCaptureStop:`/host/capture/stop`,hostCaptureAbort:`/host/capture/abort`,hostPlaybackStart:`/host/playback/start`,hostPlaybackAudio:`/host/playback/audio`,hostPlaybackAudioEnd:`/host/playback/audio-end`,hostPlaybackResult:`/host/playback/result`,hostPlaybackStop:`/host/playback/stop`,hostPlaybackAbort:`/host/playback/abort`},L={audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},video:!1};function Ie(e){return{...L,audio:{...L.audio,deviceId:{exact:e}}}}function Le(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=e;return Object.keys(t).some(e=>![`deviceId`,`eventEpoch`,`sequence`].includes(e))||t.deviceId!==void 0&&!xe(t.deviceId)||typeof t.eventEpoch!=`string`||t.eventEpoch.length===0||t.eventEpoch.length>200||!Number.isSafeInteger(t.sequence)||t.sequence<0?null:{eventEpoch:t.eventEpoch,sequence:t.sequence,...t.deviceId===void 0?{}:{deviceId:t.deviceId}}}function Re(e,t,n,r,i,a){let o=()=>{let i=e.select(e.store.state,t);return i?.eventEpoch===n&&i.sequence>r?i:void 0},s=o();return s!==void 0||a.aborted?Promise.resolve(s):new Promise(t=>{let n=!1,r,s,c=e=>{n||(n=!0,r!==void 0&&clearTimeout(r),a.removeEventListener(`abort`,l),s?.unsubscribe(),t(e))},l=()=>c();if(s=e.store.subscribe(()=>{let e=o();e!==void 0&&c(e)}),a.addEventListener(`abort`,l,{once:!0}),a.aborted){c();return}r=setTimeout(()=>c(),i);let u=o();u!==void 0&&c(u)})}function ze(e,t){let n=De({header:t});return n.status===`ok`&&n.metadata.deviceId===e}var Be=`voice_ownership`,Ve=/^[A-Za-z0-9._:-]+$/u;function He(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function Ue(e,t){return Object.keys(e).every(e=>t.includes(e))}function We(e,t=128){return typeof e==`string`&&e.length>0&&e.length<=t&&Ve.test(e)}function Ge(e){return We(e,200)||typeof e==`string`&&/^peer\/[A-Za-z0-9][A-Za-z0-9._-]{0,127}\/[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(e)}function Ke(e){let t=He(e);if(t!==void 0&&Ue(t,[`type`,`version`,`deviceId`,`activeSessionId`,`handoff`])&&t.type===`browser-media-session`&&xe(t.deviceId)&&t.version===5&&(t.activeSessionId===null||Ge(t.activeSessionId))){if(t.handoff!==void 0){let e=He(t.handoff);if(e===void 0||!Ue(e,[`id`,`phase`,`sourceSessionId`,`targetSessionId`])||!We(e.id)||![`preparing`,`rebinding`,`failed`].includes(e.phase)||!Ge(e.sourceSessionId)||e.targetSessionId!==void 0&&!Ge(e.targetSessionId)||e.phase===`rebinding`&&e.targetSessionId===void 0)return}return t}}var qe=4,Je=Symbol.for(`@agimon-ai/po-voice:web-media-page-state.v4`);function Ye(){return{version:qe,wakes:_e(void 0),activeSession:d(null),handoff:d(void 0),browserState:d(void 0),realtimeControls:d(void 0),switchPending:d(void 0),runtime:d(void 0)}}function Xe(){let e=globalThis,t=e[Je];if(t?.version===qe)return t;let n=Ye();return e[Je]=n,n}var R=Xe(),Ze=R.wakes,z=R.activeSession,Qe=R.handoff,B=R.browserState,$e=R.runtime,et=R.switchPending,V=R.realtimeControls,tt={subscribe(e){let t=[B,z,et].map(t=>t.store.subscribe(e));return()=>{for(let e of t)e.unsubscribe()}},isActive(e){let t=B.store.state,n=t?.sessionId===null&&t.realtime!==void 0&&t.realtime.connection!==`closed`,r=e!==null&&et.store.state?.sessionId===e;return n||z.store.state!==null||r}},nt={subscribe(e){let t=B.store.subscribe(e);return()=>t.unsubscribe()},isActive(){let e=B.store.state;return e?.sessionId===null&&e.realtime!==void 0&&e.realtime.connection!==`closed`}},rt={channel:Fe,parse:Le,apply(e,t){ze(t.deviceId,M())&&Ze.update(e,e=>e?.eventEpoch===t.eventEpoch&&t.sequence<=e.sequence?e:t)},drop(e){Ze.drop(e)}},it={channel:Be,parse(e){return Ke(e)??null},apply(e,t){ze(t.deviceId,M())&&(Qe.update(()=>t.handoff),z.update(e=>e===t.activeSessionId?e:t.activeSessionId))},drop(e){Qe.store.state===void 0&&z.update(t=>t===e?null:t)}};function at(e,t,n,r,i){return Re(Ze,e,t,n,r,i)}var ot=`/manual/transcribe`,st=`x-po-audio-duration-ms`,ct=3e5,lt={sdpBytes:65536,eventBytes:65536,instructionsCharacters:16384,textCharacters:8192,identifierCharacters:256,pendingRequests:1,retainedRequests:128},ut=new Set([`session.started`,`session.updated`,`input_transcript.added`,`output_transcript.added`,`turn.done`,`delegation.created`]),H={hostStart:`/host/realtime/start`,hostStop:`/host/realtime/stop`,hostPoll:`/host/realtime/poll`,hostSend:`/host/realtime/send`,hostControl:`/host/realtime/control`,clientNegotiate:`/client/realtime/negotiate`,clientEvent:`/client/realtime/event`,clientState:`/client/realtime/state`},dt={status:{method:`GET`,path:`/status`,response:void 0},control:{method:`POST`,path:`/control`,response:void 0},readiness:{method:`GET`,path:`/readiness`,response:void 0},liveStatus:{method:`GET`,path:`/live/status`,response:void 0},liveControl:{method:`POST`,path:`/live/control`,response:void 0},relayBinding:{method:`POST`,path:`/relay-binding`,response:void 0},relay:{method:`POST`,path:`/relay`,query:[`binding`],response:void 0},clientConnect:{method:`POST`,path:I.clientConnect,response:void 0},clientDisconnect:{method:`POST`,path:I.clientDisconnect},clientHeartbeat:{method:`POST`,path:I.clientHeartbeat,response:void 0},clientEvents:{method:`GET`,path:I.clientEvents,query:[`clientId`,`connectionId`,`after`,`wait`],response:void 0},clientAudio:{method:`POST`,path:I.clientAudio,query:[`clientId`,`connectionId`,`captureId`]},clientCaptureStopped:{method:`POST`,path:I.clientCaptureStopped},clientPlaybackAudio:{method:`GET`,path:I.clientPlaybackAudio,query:[`clientId`,`connectionId`,`playbackId`,`wait`]},clientPlaybackResult:{method:`POST`,path:I.clientPlaybackResult},realtimeNegotiate:{method:`POST`,path:H.clientNegotiate,response:void 0},realtimeEvent:{method:`POST`,path:H.clientEvent},realtimeState:{method:`POST`,path:H.clientState},manualTranscribe:{method:`POST`,path:ot,response:void 0}},U=y(dt,{scopes:[`host`,`workspace`,`session`],basePath:`voice`,transport:(e,t)=>le.fetch(e,t),sessionAddress:_}),W=y(dt,{scopes:[`host`,`workspace`,`session`],basePath:`voice-media`,transport:(e,t)=>le.fetch(e,t),sessionAddress:_}),ft=/^[⠀-⣿]\s*/u,pt=`voice auto:`,mt=`voice live:`,ht=`voice:`,gt=/\b(\d+:[0-5]\d)\b/u,_t={mode:`off`,phase:`idle`,label:`not listening`,detail:`start autonomous capture from the modes, or dictate one message with the voice tool.`,tone:`idle`,active:!1,microphoneMuted:!1,elapsed:``},vt=[{match:`sending composed prompt`,phase:`sending`,label:`sending draft`,detail:`handing the complete composed prompt to Pi.`,tone:`live`},{match:`composing`,phase:`composing`,label:`composing prompt`,detail:`speech segments are buffered until you say Po send or Po cancel.`,tone:`attention`},{match:`hearing speech`,phase:`hearing`,label:`hearing you`,detail:`speech detected; it will transcribe when you pause.`,tone:`live`},{match:`processing while listening`,phase:`processing`,label:`transcribing`,detail:`still listening while it works out what you said.`,tone:`live`},{match:`narrating`,phase:`narrating`,label:`narrating`,detail:`reading the reply aloud.`,tone:`live`},{match:`microphone muted`,phase:`muted`,label:`microphone muted`,detail:`narration remains active; unmute to start a fresh capture.`,tone:`idle`},{match:`confirmation needed`,phase:`confirming`,label:`needs confirmation`,detail:`it is waiting on an answer before it acts.`,tone:`attention`},{match:`waiting for keyboard input`,phase:`waiting`,label:`waiting for the keyboard`,detail:`something asked for typed input, so capture is paused.`,tone:`attention`},{match:`draining`,phase:`draining`,label:`stopping`,detail:`finishing what it already heard.`,tone:`attention`},{match:`starting`,phase:`starting`,label:`starting`,detail:`preparing autonomous microphone capture.`,tone:`live`},{match:`listening`,phase:`listening`,label:`listening`,detail:``,tone:`live`}];function yt(e){let t=(e??``).replace(ft,``).trim();if(t===``)return _t;if(t.startsWith(pt)){let e=t.slice(11).trim(),n=e.includes(`microphone muted`),r=vt.find(t=>e.includes(t.match));return r?{mode:`auto`,phase:r.phase,label:r.label,detail:r.detail,tone:r.tone,active:r.phase!==`muted`,microphoneMuted:n,elapsed:``}:{..._t,mode:`auto`,label:e||`listening`,detail:``,tone:`live`,active:!0,microphoneMuted:n}}if(t.startsWith(mt))return{mode:`live`,phase:`listening`,label:`talking`,detail:``,tone:`live`,active:!0,microphoneMuted:!1,elapsed:``};if(t.startsWith(ht)){let e=t.slice(6).trim(),n=e.startsWith(`recording`);return{mode:`manual`,phase:n?`recording`:`transcribing`,label:n?`recording`:`transcribing`,detail:n?`the microphone is open; it sends when you stop.`:`turning what you said into text.`,tone:n?`attention`:`live`,active:!0,microphoneMuted:!1,elapsed:n?gt.exec(e)?.[1]??``:``}}return{mode:`auto`,phase:`listening`,label:t,detail:``,tone:`live`,active:!0,microphoneMuted:!1,elapsed:``}}function bt({state:e,takeOver:t,retry:n,mute:r,end:i,pending:a,error:o}){let s=e.kind===`deviceLive`,c=e.kind===`standby`,l=e.ownerName??`another device`;return k(`section`,{"aria-label":`Voice`,className:`flex flex-col gap-3`,children:[P(`h3`,{className:`text-lg font-semibold text-po-hi`,children:`Voice`}),k(`div`,{className:`flex items-center gap-2`,children:[P(ue,{tone:s?`cyan`:c?`muted`:`magenta`}),P(`span`,{className:`text-base font-semibold text-po-hi`,children:c?`Voice is on standby`:s?`Live on this device`:`Voice is active on ${l}`})]}),P(`p`,{className:`text-sm leading-relaxed text-po-dim`,children:c?`Another window on this device is using voice. This window is not listening.`:s?`${e.deviceName??`This device`} · Microphone live. Other devices can run their own Live conversations separately.`:e.kind===`stale`?`Voice moved since you last checked. Take over from ${l} whenever you are ready.`:`This device is not listening. You can move this session’s voice here whenever you are ready.`}),e.kind===`conflict`||e.kind===`stale`?P(`div`,{children:P(N,{variant:`secondary`,disabled:a||!t,onClick:t,children:`Take over`})}):s?k(`div`,{className:`flex gap-2`,children:[P(N,{variant:`subtle`,disabled:a||!r,onClick:r,children:`Mute`}),P(N,{variant:`subtle`,disabled:a||!i,onClick:i,children:`End Live on this device`})]}):null,s?P(`p`,{className:`text-sm text-po-dim`,children:`Each device’s Live conversation is billed separately.`}):null,o?P(`p`,{role:`alert`,className:`text-sm text-po-red`,children:o}):null,o&&n?P(`div`,{children:P(N,{variant:`subtle`,disabled:a,onClick:n,children:`Try again`})}):null]})}var xt={idle:`muted`,live:`cyan`,attention:`yellow`},St={idle:`text-po-dim`,live:`text-po-cyan`,attention:`text-po-yellow`};function Ct({tone:e}){return P(`span`,{"aria-hidden":!0,className:`flex h-3 items-end gap-[2px]`,children:[3,7,5,9,4].map((t,n)=>P(`span`,{className:`w-[2px] animate-pulse rounded-xs ${e===`attention`?`bg-po-yellow`:`bg-po-cyan`}`,style:{height:`${String(t)}px`,animationDelay:`${String(n*120)}ms`}},n))})}function G({label:e,onClick:t,pending:n,...r}){return t===void 0?null:P(N,{variant:`subtle`,size:`xs`,disabled:n,onClick:t,...r,children:e})}function wt(e,t){return e===void 0?``:t?`output interrupted locally and will stay silent until this realtime session ends.`:e.error?e.error:e.speaking?`assistant speaking`:e.muted?`microphone muted`:e.listening?`microphone live`:`establishing secure media`}function Tt(e){switch(e.kind){case`switching`:return{phase:`switching`,tone:`live`,pulse:!0,label:`switching to ${e.mode===`live`?`live conversation`:`daily work`}`,detail:e.mode===`live`?`daily work stopped listening. Live opens the microphone once it connects.`:`live has ended. Daily work starts listening in a moment.`,meter:!1};case`conflict`:return{phase:`conflict`,tone:`attention`,pulse:!1,label:`microphone unavailable`,detail:`another Po window (the desktop app or a browser tab) is using the microphone. Close that window to use it here.`,meter:!1};case`daily`:return{phase:e.view.phase,tone:e.view.tone,pulse:e.view.active,label:e.view.label,detail:e.view.detail||(e.view.phase===`listening`&&!e.signInHint?`speak whenever you are ready`:``),meter:e.view.active};case`live`:{let t=e.realtime?.connection??`connected`,n=t===`connected`;return{phase:`realtime-${t}`,tone:n?`live`:`attention`,pulse:n,label:n?`talking`:`connecting live conversation`,detail:wt(e.realtime,e.interrupted),meter:n&&e.realtime!==void 0&&!e.realtime.muted}}case`live-failed`:return{phase:`realtime-failed`,tone:`attention`,pulse:!1,label:`live could not connect`,detail:e.error,meter:!1};case`live-elsewhere`:return{phase:`live-elsewhere`,tone:`idle`,pulse:!1,label:`live is talking in another session`,detail:``,meter:!1};case`daily-elsewhere`:return{phase:`daily-elsewhere`,tone:`idle`,pulse:!1,label:`daily work is listening in another session`,detail:``,meter:!1};case`manual`:case`idle`:return{phase:e.view.phase,tone:e.view.tone,pulse:e.view.active,label:e.view.label,detail:e.view.detail,meter:e.view.active,elapsed:e.view.elapsed}}}function Et({state:e,picker:t,actions:n,pending:r,error:i,ownership:a,ownershipActions:o}){if(a)return P(bt,{state:a,takeOver:o?.takeOver,retry:o?.retry,mute:n.mute,end:n.end,pending:r,error:i});let s=Tt(e),c=e.kind===`daily`&&e.view.microphoneMuted,l=e.kind===`live`&&e.realtime?.muted===!0,u=c||l?`unmute`:`mute`,d=e.kind===`live-failed`,f=e.kind===`daily`&&e.signInHint;return k(`div`,{"data-testid":`voice-activity`,"data-voice-phase":s.phase,className:`flex flex-col gap-2 px-1`,children:[t===void 0?null:k(me,{"aria-label":`Voice for this session`,value:t.value,disabled:t.disabled||r,onValueChange:e=>t.onPick(e),className:`grid grid-cols-2 gap-1.5`,children:[P(se,{value:`live`,"data-testid":`voice-pick-live`,className:`px-2 py-1 text-center text-sm font-medium text-po-hi`,children:`Live`}),P(se,{value:`legacy`,"data-testid":`voice-pick-legacy`,className:`px-2 py-1 text-center text-sm font-medium text-po-hi`,children:`Daily work`})]}),k(`span`,{className:`flex min-w-0 items-center gap-2`,children:[P(ue,{tone:xt[s.tone],pulse:s.pulse}),P(`span`,{"data-testid":`voice-label`,className:`flex-1 truncate text-base font-semibold ${St[s.tone]}`,children:s.label}),s.elapsed?P(`span`,{"data-testid":`voice-elapsed`,className:`shrink-0 text-sm tabular-nums text-po-yellow`,children:s.elapsed}):null,s.meter?P(Ct,{tone:s.tone}):null]}),e.kind===`daily`||e.kind===`live`?k(`span`,{className:`flex flex-wrap gap-1.5`,children:[P(G,{label:u,onClick:n.mute,pending:r,"aria-pressed":c||l,...e.kind===`daily`?{"data-testid":`voice-autonomous-microphone-toggle`,"aria-label":`${u} autonomous voice microphone`,title:`${u} autonomous voice microphone`}:{}}),P(G,{label:`interrupt`,onClick:e.kind===`live`?n.interrupt:void 0,pending:r,title:`Interrupt local output. Output stays silent until this realtime session ends.`}),P(G,{label:`end`,onClick:n.end,pending:r,"data-testid":`voice-end`})]}):null,s.detail&&!f?P(`span`,{"data-testid":`voice-detail`,role:d?`alert`:void 0,className:`text-sm leading-relaxed text-po-dim`,children:d&&n.useDailyWork!==void 0?`${s.detail} You can keep talking with daily work.`:s.detail}):null,f?k(`span`,{className:`flex flex-col items-start gap-2`,children:[P(`span`,{"data-testid":`voice-sign-in-hint`,className:`text-sm leading-relaxed text-po-dim`,children:`live needs your ChatGPT for Po features sign-in. Daily work keeps listening meanwhile.`}),n.signIn===void 0?null:P(N,{variant:`secondary`,size:`xs`,"data-testid":`voice-sign-in`,onClick:n.signIn,children:`sign in`})]}):null,d?k(`span`,{className:`flex flex-wrap gap-1.5`,children:[P(G,{label:`use daily work`,onClick:n.useDailyWork,pending:r,"data-testid":`voice-use-daily`}),P(G,{label:`end`,onClick:n.end,pending:r,"data-testid":`voice-end`})]}):null,e.kind===`live-elsewhere`||e.kind===`daily-elsewhere`?P(`span`,{className:`flex`,children:P(G,{label:e.kind===`live-elsewhere`?`move Live here`:`move daily work here`,onClick:e.kind===`live-elsewhere`?n.routeLiveHere:n.moveDailyWorkHere,pending:r,"data-testid":e.kind===`live-elsewhere`?`voice-global-live-transfer`:`voice-daily-move`})}):null,i===null?null:P(`span`,{role:`alert`,className:`text-sm leading-relaxed text-po-yellow`,children:i})]})}function Dt(e){return e instanceof Error?e.message:String(e)}function Ot({sessionId:e,statuses:t,openSettings:n,registeredModes:r}){let i=yt(t[`po-voice`]),a=O(B.store),o=O(V.store),s=O(z.store),c=O(et.store),[l,u]=D(!1),[d,f]=D(null),[p,m]=D(!1),[h,g]=D(),_=r?.includes(`voice-auto`)===!0;ae(()=>{if(e===null||!_)return;let t=!1;return U.session(e).status().then(n=>{!t&&n.ok&&g({sessionId:e,realtime:n.data.media.realtime})}).catch(()=>{t||g({sessionId:e,realtime:!1})}),()=>{t=!0}},[_,e]);let v=e===null||(h?.sessionId===e?h.realtime:a?.realtime!==void 0||i.mode===`live`||c?.sessionId===e&&c?.mode===`live`),y=e!==null&&a?.sessionId===e?a.realtime:void 0,b=a?.sessionId===null?a.realtime:void 0,x=y??b,S=x!==void 0&&x.connection!==`closed`,C=o?.sessionId===null||o?.sessionId===e?o:void 0,w=e!==null&&c?.sessionId===e?{kind:`switching`,mode:c.mode}:e!==null&&a?.sessionId===e&&a.phase===`conflict`&&i.mode!==`off`?{kind:`conflict`}:i.mode===`auto`?{kind:`daily`,view:i,signInHint:p}:x?.connection===`failed`&&i.mode!==`manual`?{kind:`live-failed`,error:x.error??`the live provider did not answer.`}:e!==null&&i.mode!==`live`&&y===void 0&&b?.connection===`connected`?{kind:`live-elsewhere`}:i.mode===`live`||S?{kind:`live`,...x===void 0?{}:{realtime:x},interrupted:a?.realtimeOutputInterrupted===!0}:s!==null&&s!==e&&i.mode===`off`?{kind:`daily-elsewhere`}:i.mode===`manual`?{kind:`manual`,view:i}:{kind:`idle`,view:i},T=async e=>{if(!l){u(!0),f(null);try{await e()}catch(e){f(Dt(e))}finally{u(!1)}}},E=async(t,n,r,i)=>{if(e===null)throw Error(`Voice controls need a session.`);if((t===`activate`||t===`switch`)&&n!==`live`){let a=$e.store.state;if(!a)throw Error(`Voice media is not ready in this browser.`);try{r=await a.prepareSessionActivation(e,i)}catch(r){throw B.update(r=>{if(r?.sessionId!==e||!r.ownershipConflict)return r;let i=r.ownershipConflict.owner.generation;return{...r,actions:{takeOver:()=>{T(()=>E(t,n,void 0,i))},retry:()=>{T(()=>E(t,n))}}}}),r}}if(t===`switch`&&n===`live`&&!r){let e=$e.store.state;if(!e)throw Error(`Voice media is not ready in this browser.`);r=await e.prepareLiveActivation(i)}let a=await U.session(e).control({body:{action:t,...n?{mode:n}:{},...r?{browser:r}:{},...i===void 0?{}:{takeoverGeneration:i}}});if(a.ok&&a.data.ownershipConflict){let r=a.data.ownershipConflict,o=i!==void 0;B.update(()=>({sessionId:e,phase:`conflict`,ownershipConflict:r,ownership:{kind:o?`stale`:`conflict`,ownerName:r.owner.deviceName},actions:{takeOver:()=>{T(()=>E(t,n,void 0,r.owner.generation))},retry:()=>{T(()=>E(t,n))}}}))}else if(!a.ok)throw Error(a.error||`Voice control request failed.`)},ee=async(t,n)=>{if(e===null)return;m(!1);let r={sessionId:e,mode:t};et.update(()=>r);try{await n()}finally{et.update(e=>e===r?void 0:e)}},te=(e,t)=>T(()=>ee(e,t)),ne=()=>T(async()=>{let e=await U.host.liveStatus();if(e.ok&&e.data.signedIn===!1){m(!0);return}if(!e.ok)throw Error(e.error);if(e.data.state!==`disabled`)return;let t=$e.store.state;if(!t)throw Error(`Voice media is not ready in this browser.`);let n=await t.prepareLiveActivation();await ee(`live`,()=>E(`switch`,`live`,n))}),re=()=>te(`legacy`,async()=>{v&&await k(`end`),await E(`activate`,`legacy`)}),k=async e=>{let t=await U.host.liveControl({body:{action:e}});if(!t.ok)throw Error(t.error||`Live control request failed.`)},ie=()=>C?C.end():void T(()=>k(`end`)),A={},oe,j=(t,n,r=!1)=>{e!==null&&v&&(oe={value:n,disabled:r,onPick:t})};switch(w.kind){case`switching`:j(()=>void 0,w.mode,!0);break;case`daily`:if(e===null)break;j(e=>void(e===`live`?ne():void 0),`legacy`),i.phase!==`starting`&&i.phase!==`draining`&&(A.mute=()=>void T(()=>E(i.microphoneMuted?`unmute`:`mute`))),A.end=()=>void T(()=>E(`deactivate`)),n&&(A.signIn=()=>n(`providers`));break;case`live`:{let e=w.realtime?.muted===!0;j(e=>void(e===`legacy`?re():void 0),`live`),A.mute=()=>C?C.mute(!e):void T(()=>k(e?`unmute`:`mute`)),A.interrupt=()=>C?C.interrupt():void T(()=>k(`interrupt`)),A.end=ie;break}case`live-failed`:j(e=>void(e===`legacy`?re():void 0),`live`),e!==null&&(A.useDailyWork=()=>void re()),A.end=ie;break;case`live-elsewhere`:j(()=>void 0,`live`,!0),e!==null&&(A.routeLiveHere=()=>void T(async()=>{let t=await U.host.liveControl({body:{action:`transfer`,sessionId:e}});if(!t.ok)throw Error(t.error||`Moving Live here failed.`)}));break;case`daily-elsewhere`:j(()=>void 0,`legacy`,!0),e!==null&&(A.moveDailyWorkHere=()=>void T(()=>E(`activate`,`legacy`)))}let M=a?.sessionId===e||a?.sessionId===null?a:void 0;return P(Et,{state:w,picker:oe,actions:A,pending:l,error:d,ownership:M?.ownership,ownershipActions:M?.actions})}function kt(e){let t=O(B.store);return e.sessionId!==null||t?.sessionId!==null||t.realtime?.connection===`closed`||t.realtime===void 0?null:P(Ot,{...e})}var At=u({slot:`activity`,id:`voice-global-live`,component:kt}),jt=1e4,Mt=15e3,Nt=15e3;function Pt(e){return new TextEncoder().encode(e).byteLength}function Ft(e){if(typeof e!=`object`||!e)return;let t=e.type;return typeof t==`string`?t:void 0}function K(e){return e instanceof Error?`${e.name}: ${e.message}`:String(e)}var It=class{options;microphoneConstraints;browser;output;state={connection:`closed`,listening:!1,speaking:!1,muted:!1};generation=0;started=!1;stream;peer;channel;audio;abortController;suppressOutput=!1;announcements=new Map;announcementFlushScheduled=!1;constructor(e,t=async()=>L,n=window,r){this.options=e,this.microphoneConstraints=t,this.browser=n,this.output=r,this.state.muted=e.muted===!0,r&&(r.onPlaybackState=e=>{this.state.connection!==`closed`&&this.state.connection!==`failed`&&(this.publish({speaking:e&&!this.suppressOutput}),e||this.scheduleAnnouncementFlush())})}async start(){if(this.started)throw Error(`Realtime browser session has already started.`);this.started=!0;let e=++this.generation,t=new AbortController;this.abortController=t,this.publish({connection:`connecting`,error:void 0});try{if(typeof this.browser.RTCPeerConnection!=`function`||this.browser.navigator.mediaDevices?.getUserMedia===void 0)throw Error(`Browser realtime media is unavailable.`);let n=this.microphoneConstraints().then(e=>this.browser.navigator.mediaDevices.getUserMedia(e));n.then(t=>{if(!this.isCurrent(e))for(let e of t.getTracks())e.stop()},()=>void 0);let r=await this.abortable(n,t.signal);if(!this.isCurrent(e)){for(let e of r.getTracks())e.stop();throw Error(`Realtime browser session was closed.`)}this.stream=r;for(let t of r.getTracks())t.kind===`audio`&&(t.enabled=!this.state.muted),t.onended=()=>this.fail(e,`Microphone permission or input was lost.`);let i=new this.browser.RTCPeerConnection;this.peer=i,i.onconnectionstatechange=()=>{this.isCurrent(e)&&(i.connectionState===`failed`||i.connectionState===`disconnected`?this.fail(e,`Realtime connection ${i.connectionState}.`):i.connectionState===`closed`&&this.state.connection!==`closed`&&this.fail(e,`Realtime connection closed unexpectedly.`))},i.ontrack=t=>this.attachRemoteAudio(e,t);let a=i.createDataChannel(`oai-events`);this.channel=a,a.onmessage=t=>this.receive(e,t.data),a.onerror=()=>this.fail(e,`Realtime event channel failed.`),a.onclose=()=>{this.isCurrent(e)&&this.fail(e,`Realtime event channel closed unexpectedly.`)};for(let e of r.getTracks())i.addTrack(e,r);let o=await i.createOffer();this.assertSdp(o.sdp),await i.setLocalDescription(o),await this.waitForIce(i,e,t.signal);let s=i.localDescription?.sdp;this.assertSdp(s);let c=await this.bounded(this.options.negotiate(s,t.signal),Nt,`Realtime negotiation timed out.`,t.signal);if(this.assertSdp(c),!this.isCurrent(e)||(await i.setRemoteDescription({type:`answer`,sdp:c}),await this.waitForConnection(i,a,e,t.signal),!this.isCurrent(e)))throw Error(`Realtime browser session was closed.`);this.publish({connection:`connected`,listening:!this.state.muted})}catch(t){throw this.isCurrent(e)&&this.fail(e,K(t)),t}}send(e){if(this.validateEvent(e),this.channel?.readyState!==`open`||this.state.connection!==`connected`)throw Error(`Realtime event channel is not open.`);let t=JSON.parse(e);if(t.type===`po.announce`){if(typeof t.key!=`string`||t.key.length===0||t.text!==void 0&&typeof t.text!=`string`)throw Error(`Realtime announcement requires a key and optional text.`);t.text===void 0?this.announcements.delete(t.key):this.announcements.set(t.key,t.text),this.scheduleAnnouncementFlush()}else this.channel.send(e)}mute(e){for(let t of this.stream?.getAudioTracks()??[])t.enabled=!e;this.publish({muted:e,listening:this.state.connection===`connected`&&!e})}interruptSpeech(){this.suppressOutput=!0,this.audio!==void 0&&(this.audio.muted=!0),this.output?.suppress(!0),this.publish({speaking:!1})}close(){this.state.connection===`closed`&&this.generation>0||(this.started=!0,this.generation+=1,this.cleanup(),this.publish({connection:`closed`,listening:!1,speaking:!1,error:void 0}))}receive(e,t){if(!this.isCurrent(e))return;if(typeof t!=`string`||Pt(t)>lt.eventBytes){this.fail(e,`Realtime provider sent an invalid or oversized event.`);return}let n;try{n=JSON.parse(t)}catch{this.fail(e,`Realtime provider sent malformed JSON.`);return}let r=Ft(n);if(r===void 0)this.fail(e,`Realtime provider sent an event without a type.`);else if(r===`error`)this.fail(e,`Realtime provider reported an error.`);else if(r===`input_transcript.added`&&this.suppressOutput&&(this.suppressOutput=!1,this.audio!==void 0&&(this.audio.muted=!1),this.output?.suppress(!1)),ut.has(r))try{this.options.onEvent(t)}catch(t){this.fail(e,`Realtime event consumer failed: ${K(t)}`)}}attachRemoteAudio(e,t){if(!this.isCurrent(e)||t.track.kind!==`audio`)return;let n=t.streams[0]??new this.browser.MediaStream([t.track]);if(this.output){this.output.suppress(this.suppressOutput);try{Promise.resolve(this.output.attach(n,t.track)).catch(t=>this.fail(e,`Remote audio playback failed: ${K(t)}`))}catch(t){this.fail(e,`Remote audio playback failed: ${K(t)}`)}return}let r=this.browser.document.createElement(`audio`);r.autoplay=!0,r.muted=this.suppressOutput,r.srcObject=n,r.onplaying=()=>{this.isCurrent(e)&&this.audio===r&&!r.muted&&this.publish({speaking:!0})};let i=()=>{this.isCurrent(e)&&this.audio===r&&(this.publish({speaking:!1}),this.scheduleAnnouncementFlush())};r.onpause=i,r.onended=i,r.onwaiting=i,this.detachAudio(),this.audio=r,r.play().catch(t=>this.fail(e,`Remote audio playback failed: ${K(t)}`))}scheduleAnnouncementFlush(){if(this.announcementFlushScheduled||this.announcements.size===0)return;this.announcementFlushScheduled=!0;let e=this.generation;queueMicrotask(()=>{if(this.announcementFlushScheduled=!1,!this.isCurrent(e)||this.state.connection!==`connected`||this.channel?.readyState!==`open`||this.suppressOutput)return;let t=e=>JSON.stringify({type:`session.context.append`,channel:`speakable`,content:[{type:`input_text`,text:`Share these updates only at a conversational pause. Stop and listen when the user speaks.\n\n${e}`}]}),n=[],r=``;for(let e of this.announcements.values()){let i=Array.from(e);for(let e=0;e<i.length;e+=4096){let a=i.slice(e,e+4096).join(``),o=r?`${r}\n\n${a}`:a;Pt(t(o))>lt.eventBytes?(n.push(t(r)),r=a):r=o}}r&&n.push(t(r)),this.announcements.clear();try{for(let e of n)this.channel.send(e)}catch(t){this.fail(e,`Realtime announcement failed: ${K(t)}`)}})}validateEvent(e){if(Pt(e)>lt.eventBytes)throw Error(`Realtime event exceeds the maximum size.`);let t;try{t=JSON.parse(e)}catch{throw Error(`Realtime event must be valid JSON.`)}if(Ft(t)===void 0)throw Error(`Realtime event must contain a type.`)}assertSdp(e){if(typeof e!=`string`||e.length===0)throw Error(`Realtime SDP is missing.`);if(Pt(e)>lt.sdpBytes)throw Error(`Realtime SDP exceeds the maximum size.`)}async waitForIce(e,t,n){if(e.iceGatheringState===`complete`)return;let r=()=>{this.isCurrent(t)&&e.iceGatheringState===`complete`&&i?.()},i;try{await this.bounded(new Promise(t=>{i=t,e.addEventListener(`icegatheringstatechange`,r),r()}),jt,`Realtime ICE gathering timed out.`,n)}finally{e.removeEventListener(`icegatheringstatechange`,r)}}async waitForConnection(e,t,n,r){let i=()=>e.connectionState===`connected`&&t.readyState===`open`;if(i())return;let a=()=>{this.isCurrent(n)&&(e.connectionState===`failed`||e.connectionState===`disconnected`?s?.(Error(`Realtime connection ${e.connectionState}.`)):i()&&o?.())},o,s;try{await this.bounded(new Promise((n,r)=>{o=n,s=r,e.addEventListener(`connectionstatechange`,a),t.addEventListener(`open`,a),t.addEventListener(`close`,a),a()}),Mt,`Realtime connection timed out.`,r)}finally{e.removeEventListener(`connectionstatechange`,a),t.removeEventListener(`open`,a),t.removeEventListener(`close`,a)}}abortable(e,t){return new Promise((n,r)=>{let i=!1,a=e=>{i||(i=!0,t.removeEventListener(`abort`,o),e())},o=()=>a(()=>r(Error(`Realtime browser session was closed.`)));t.addEventListener(`abort`,o,{once:!0}),t.aborted&&o(),e.then(e=>a(()=>n(e)),e=>a(()=>r(e)))})}bounded(e,t,n,r){return new Promise((i,a)=>{let o=!1,s=e=>{o||(o=!0,clearTimeout(l),r.removeEventListener(`abort`,c),e())},c=()=>s(()=>a(Error(`Realtime browser session was closed.`))),l=setTimeout(()=>s(()=>a(Error(n))),t);r.addEventListener(`abort`,c,{once:!0}),r.aborted&&c(),e.then(e=>s(()=>i(e)),e=>s(()=>a(e)))})}fail(e,t){this.isCurrent(e)&&(this.generation+=1,this.cleanup(),this.publish({connection:`failed`,listening:!1,speaking:!1,error:t}))}cleanup(){this.announcements.clear(),this.abortController?.abort(),this.abortController=void 0,this.channel!==void 0&&(this.channel.onmessage=null,this.channel.onerror=null,this.channel.onclose=null,this.channel.close()),this.peer!==void 0&&(this.peer.ontrack=null,this.peer.onconnectionstatechange=null,this.peer.close());for(let e of this.stream?.getTracks()??[])e.onended=null,e.stop();this.detachAudio(),this.output&&(this.output.onPlaybackState=null,this.output.dispose()),this.channel=void 0,this.peer=void 0,this.stream=void 0,this.suppressOutput=!1}detachAudio(){this.audio!==void 0&&(this.audio.onplaying=null,this.audio.onpause=null,this.audio.onended=null,this.audio.onwaiting=null,this.audio.pause(),this.audio.srcObject=null,this.audio=void 0)}publish(e){this.state={...this.state,...e};try{this.options.onState({...this.state})}catch(e){queueMicrotask(()=>{throw e})}}isCurrent(e){return this.generation===e}},Lt=600,Rt=F*120/1e3,zt=-120,Bt=32768,Vt=2,Ht=F*1*Vt;function Ut(e,t,n){return Math.min(n,Math.max(t,e))}function Wt(e){return Math.round(e*10)/10}function Gt(e){if(e.byteLength===0||e.byteLength%Vt!==0)throw Error(`PCM activity input must contain complete 16-bit samples.`);let t=0;for(let n=0;n<e.byteLength;n+=Vt){let r=e[n]|e[n+1]<<8,i=(r>=32768?r-65536:r)/Bt;t+=i*i}let n=Math.sqrt(t/(e.byteLength/Vt));return n===0?zt:20*Math.log10(n)}var Kt=class{endpointSilenceMs;elapsedBytes=0;activityEpoch=0;consecutiveSpeechSamples=0;consecutiveEchoSpeechSamples=0;classifiedSpeechSamples=0;echoDiscriminatedSpeechSamples=0;trailingSilenceSamples=0;speechStarted=!1;endpointReached=!1;previousEchoDiscriminated=!1;constructor(e=Lt){if(this.endpointSilenceMs=e,!Number.isSafeInteger(e)||e<250)throw Error(`Client endpoint silence must be an integer of at least 250 ms.`)}push(e,t=[],n){let r=Gt(e);this.elapsedBytes+=e.byteLength;let i=n?.echoReferenceActive===!0&&n.echoDiscriminated&&this.previousEchoDiscriminated;for(let e of t){if(!Number.isSafeInteger(e.sampleCount)||e.sampleCount<=0)throw Error(`Speech-presence windows must contain a positive integer sample count.`);if(this.endpointReached){if(!e.speech){this.consecutiveSpeechSamples=0,this.consecutiveEchoSpeechSamples=0;continue}if(this.consecutiveSpeechSamples+=e.sampleCount,i&&(this.consecutiveEchoSpeechSamples+=e.sampleCount),this.consecutiveSpeechSamples<Rt)continue;this.activityEpoch+=1,this.classifiedSpeechSamples=this.consecutiveSpeechSamples,this.echoDiscriminatedSpeechSamples=this.consecutiveEchoSpeechSamples,this.consecutiveSpeechSamples=0,this.consecutiveEchoSpeechSamples=0,this.trailingSilenceSamples=0,this.speechStarted=!0,this.endpointReached=!1;continue}e.speech?(this.classifiedSpeechSamples+=e.sampleCount,i&&(this.echoDiscriminatedSpeechSamples+=e.sampleCount),this.consecutiveSpeechSamples+=e.sampleCount,i&&(this.consecutiveEchoSpeechSamples+=e.sampleCount),this.consecutiveSpeechSamples>=Rt&&(this.speechStarted=!0,this.consecutiveSpeechSamples=0,this.consecutiveEchoSpeechSamples=0,this.trailingSilenceSamples=0)):(this.speechStarted&&(this.trailingSilenceSamples+=this.consecutiveSpeechSamples+e.sampleCount),this.consecutiveSpeechSamples=0,this.consecutiveEchoSpeechSamples=0);let t=this.trailingSilenceSamples/F*1e3;this.speechStarted&&t>=this.endpointSilenceMs&&(this.endpointReached=!0)}return this.previousEchoDiscriminated=n?.echoReferenceActive===!0&&n.echoDiscriminated,{state:this.endpointReached?`endpoint`:this.speechStarted?`speech`:`listening`,levelDbfs:Wt(Ut(r,zt,0)),elapsedMs:Math.round(this.elapsedBytes/Ht*1e3),epoch:this.activityEpoch,classifiedSpeechMs:Math.round(this.classifiedSpeechSamples/F*1e3),...n?.echoReferenceActive===!0?{echoDiscriminatedSpeechMs:Math.round(this.echoDiscriminatedSpeechSamples/F*1e3)}:{}}}resetActivity(){this.activityEpoch+=1,this.consecutiveSpeechSamples=0,this.consecutiveEchoSpeechSamples=0,this.classifiedSpeechSamples=0,this.echoDiscriminatedSpeechSamples=0,this.trailingSilenceSamples=0,this.speechStarted=!1,this.endpointReached=!1,this.previousEchoDiscriminated=!1}},qt=2e3,Jt=16e3,Yt=200,Xt=128,Zt=2097152,Qt=409;function $t(e){return e instanceof Error&&`status`in e&&e.status===Qt}function en(e){if(!(e instanceof Error)||!(`conflict`in e))return!1;let t=e.conflict;return typeof t==`object`&&!!t&&`code`in t&&t.code===`VOICE_OWNERSHIP_CONFLICT`}function tn(e,t){return{playbackId:e,outcome:`failed`,error:t instanceof Error?`${t.name}: ${t.message}`:String(t)}}function nn(e){return{...e}}function rn(e,t){return e.capture===t.capture&&e.playback===t.playback&&e.captureActivity===t.captureActivity&&e.autonomousOrchestration===t.autonomousOrchestration&&e.playbackDucking===t.playbackDucking&&e.realtime===t.realtime}function an(e,t){return new Promise(n=>{if(t.aborted){n();return}let r=()=>{clearTimeout(i),t.removeEventListener(`abort`,r),n()},i=setTimeout(r,e);t.addEventListener(`abort`,r,{once:!0})})}var on=class{clientId;connectionId;transport;device;onConnectionState;onRealtimeState;createRealtimeSession;onOpenSession;abortController=new AbortController;capture;captureId;advertisedCapabilities;captureGeneration=0;speechDetector;activityLifecycle;playback;playbackAudioController;audioUploads=Promise.resolve();audioUploadError;activeConnectionId;connectionAttempt=0;ownershipError;connectionWaiters=new Set;failAttempt;runOperation;realtime;realtimeActivationId;realtimeGeneration=0;realtimePosts=Promise.resolve();pendingRealtimePosts=0;listeningWaiters=new Set;captureEndWaiters=new Set;constructor(e,t,n,r,i=()=>void 0,a=()=>void 0,o,s){this.clientId=e,this.connectionId=t,this.transport=n,this.device=r,this.onConnectionState=i,this.onRealtimeState=a,this.createRealtimeSession=o,this.onOpenSession=s}start(){this.onConnectionState(`connecting`),this.runOperation??=this.run()}waitForConnection(){return this.activeConnectionId===void 0?this.ownershipError?Promise.reject(this.ownershipError):this.abortController.signal.aborted?Promise.reject(Error(`Voice media client is closed.`)):new Promise((e,t)=>{let n=i=>{clearTimeout(r),this.connectionWaiters.delete(n),i?t(i):this.activeConnectionId===void 0?t(Error(`Voice media connection is unavailable.`)):e({clientId:this.clientId,connectionId:this.activeConnectionId})},r=setTimeout(()=>n(Error(`The requesting browser did not connect to Voice.`)),1e4);this.connectionWaiters.add(n)}):Promise.resolve({clientId:this.clientId,connectionId:this.activeConnectionId})}get listening(){return this.capture!==void 0}waitForListening(){return this.listening?Promise.resolve(!0):this.abortController.signal.aborted?Promise.resolve(!1):new Promise(e=>this.listeningWaiters.add(e))}waitForCaptureEnd(){return this.captureId===void 0||this.abortController.signal.aborted?Promise.resolve():new Promise(e=>this.captureEndWaiters.add(e))}async stop(e=!0){this.closeRealtime(),this.abortController.abort();for(let e of this.connectionWaiters)e(Error(`Voice media client is closed.`));await this.runOperation?.catch(()=>void 0),await this.releaseMedia(e);let t=this.activeConnectionId;t!==void 0&&await this.transport.disconnect(this.clientId,t).catch(()=>void 0),this.activeConnectionId=void 0,this.advertisedCapabilities=void 0,this.resolveListening(!1),this.resolveCaptureEnd(),this.onConnectionState(`disconnected`)}async run(){let e=this.abortController.signal,t=qt;for(;!e.aborted;){let n=this.nextConnectionId(),r=new AbortController,i=()=>r.abort();e.addEventListener(`abort`,i,{once:!0});let a,o=new Promise((e,t)=>{a=t});this.failAttempt=a;try{let i=nn(this.device.capabilities),a=await this.transport.connect(this.clientId,n,i);if(e.aborted){await this.transport.disconnect(this.clientId,n).catch(()=>void 0);return}this.activeConnectionId=n,this.advertisedCapabilities=i,t=qt,this.onConnectionState(`connected`);for(let e of this.connectionWaiters)e();this.prepareCapabilities(n,i,r.signal);let s=a.cursor;for(;!e.aborted;){let e=await Promise.race([this.transport.nextEvent(this.clientId,n,s,r.signal),o]);e!==void 0&&(s=e.sequence,await this.handle(e,n))}}catch(i){for(let e of this.connectionWaiters)e(i instanceof Error?i:Error(String(i)));if(e.aborted)return;if($t(i)&&(this.activeConnectionId!==n||en(i))&&this.onConnectionState(`conflict`,i),r.abort(),this.closeRealtime($t(i)),await this.releaseMedia(),this.activeConnectionId===n&&(await this.transport.disconnect(this.clientId,n).catch(()=>void 0),this.activeConnectionId=void 0,this.advertisedCapabilities=void 0),$t(i)&&en(i)){this.ownershipError=i;return}await an(t,e),t=Math.min(t*2,Jt)}finally{e.removeEventListener(`abort`,i),this.failAttempt===a&&(this.failAttempt=void 0)}}}prepareCapabilities(e,t,n){(async()=>{try{if(await this.device.prepare?.(),n.aborted||this.abortController.signal.aborted||this.activeConnectionId!==e)return;let r=nn(this.device.capabilities);if(rn(t,r)||!this.transport.refreshCapabilities)return;await this.transport.refreshCapabilities(this.clientId,e,r),this.activeConnectionId===e&&(this.advertisedCapabilities=r)}catch{}})()}async handle(e,t){switch(e.type){case`realtime-start`:this.startRealtime(e.activationId,t,e.muted===!0);return;case`realtime-stop`:this.realtimeActivationId===e.activationId&&this.closeRealtime();return;case`realtime-control`:if(this.realtimeActivationId!==e.activationId)return;e.action===`mute`?this.realtime?.mute(!0):e.action===`unmute`?this.realtime?.mute(!1):this.realtime?.interruptSpeech();return;case`realtime-send`:if(this.realtimeActivationId!==e.activationId)return;for(let t of e.messages)this.realtime?.send(t);return;case`open-session`:this.realtimeActivationId===e.activationId&&this.onOpenSession?.(e.sessionId);return;case`capture-start`:this.closeRealtime(),await this.startCapture(e,t);return;case`capture-stop`:this.captureId===e.captureId&&await this.finishCapture(e.captureId,t,!0);return;case`capture-abort`:this.captureId===e.captureId&&await this.finishCapture(e.captureId,t,!1);return;case`playback-start`:this.closeRealtime(),await this.startPlayback(e,t);return;case`playback-stop`:this.playbackAudioController?.abort(),this.playback?.stop(`stopped`);return;case`playback-abort`:this.playbackAudioController?.abort(),this.playback?.stop(`aborted`);return}}muteRealtime(e){this.realtime?.mute(e)}interruptRealtime(){this.realtime?.interruptSpeech()}endRealtime(){this.closeRealtime()}startRealtime(e,t,n){this.closeRealtime();let r=++this.realtimeGeneration;this.realtimeActivationId=e,this.beginRealtime(e,t,r,n).catch(e=>this.failRealtime(r,e))}async beginRealtime(e,t,n,r){if(await this.releaseMedia(!1),!this.isCurrentRealtime(e,t,n))return;let{realtimeNegotiate:i,realtimeEvent:a,realtimeState:o}=this.transport;if(i===void 0||a===void 0||o===void 0)throw Error(`Realtime browser transport is unavailable.`);let s;if(!this.createRealtimeSession)throw Error(`Realtime media device is unavailable.`);s=this.createRealtimeSession({muted:r,negotiate:(n,r)=>i.call(this.transport,this.clientId,t,e,n,r),onEvent:r=>{this.realtime===s&&this.isCurrentRealtime(e,t,n)&&this.enqueueRealtimePost(n,()=>a.call(this.transport,this.clientId,t,e,r))},onState:r=>{this.realtime===s&&this.isCurrentRealtime(e,t,n)&&(this.onRealtimeState(r),this.enqueueRealtimePost(n,()=>o.call(this.transport,this.clientId,t,e,r)))}}),this.realtime=s,await s.start()}closeRealtime(e=!1){let t=this.realtime,n=this.realtimeActivationId;if(t===void 0&&n===void 0)return;let r=this.activeConnectionId,i=this.realtimeGeneration;this.realtime=void 0,this.realtimeActivationId=void 0,this.realtimeGeneration+=1,t?.close(),this.onRealtimeState(void 0,e);let a=this.transport.realtimeState;n!==void 0&&r!==void 0&&a!==void 0&&this.enqueueRealtimePost(i,()=>a.call(this.transport,this.clientId,r,n,{connection:`closed`,listening:!1,speaking:!1,muted:!1}),!0)}isCurrentRealtime(e,t,n){return this.realtimeGeneration===n&&this.realtimeActivationId===e&&this.activeConnectionId===t&&!this.abortController.signal.aborted}enqueueRealtimePost(e,t,n=!1){if(this.pendingRealtimePosts>=Xt){this.failRealtime(e,Error(`Realtime browser event queue exceeded its limit.`));return}this.pendingRealtimePosts+=1;let r=this.realtimePosts.then(()=>{if(n||e===this.realtimeGeneration)return t()});this.realtimePosts=r.catch(()=>void 0),r.then(()=>{--this.pendingRealtimePosts},t=>{--this.pendingRealtimePosts,this.failRealtime(e,t)})}failRealtime(e,t){e===this.realtimeGeneration&&(this.closeRealtime(),this.onRealtimeState({connection:`failed`,listening:!1,speaking:!1,muted:!1,error:t instanceof Error?t.message:String(t)}),this.failAttempt?.(t instanceof Error?t:Error(String(t))))}async startCapture(e,t){let{captureId:n,configuration:r}=e;this.capture!==void 0&&await this.finishCapture(this.captureId??n,t,!1);let i=++this.captureGeneration;this.captureId=n,this.audioUploads=Promise.resolve(),this.audioUploadError=void 0;let a=0,o=r.activityControl===`client`?this.device.createSpeechPresenceDetector?.():void 0,s=r.activityControl===`client`&&o!==void 0?new Kt(r.endpointSilenceMs):void 0;this.speechDetector=o,this.activityLifecycle=s;try{let e=await this.device.startCapture((e,r)=>{if(i!==this.captureGeneration||this.captureId!==n||this.audioUploadError!==void 0)return;if(a+e.byteLength>Zt){let e=Error(`Voice PCM upload queue exceeded its limit. The local recording is retained.`);this.audioUploadError=e,this.failActiveCapture(n,t,i,e);return}a+=e.byteLength;let c=new Uint8Array(e),l=r===void 0?c:new Uint8Array(r.speechPcm),u=r===void 0?void 0:{echoReferenceActive:r.echoReferenceActive,echoDiscriminated:r.echoDiscriminated};this.audioUploads=this.audioUploads.then(async()=>{if(a-=c.byteLength,this.audioUploadError===void 0&&i===this.captureGeneration&&this.captureId===n)try{if(l.byteLength!==c.byteLength)throw Error(`Local speech analysis must preserve the capture sample count.`);let e=await o?.push(l);if(i!==this.captureGeneration||this.captureId!==n)return;let r=s?.push(c,e,u);await this.transport.sendAudio(this.clientId,t,n,c,r)}catch(e){if(i!==this.captureGeneration||this.captureId!==n)return;let r=e instanceof Error?e:Error(String(e));$t(r)||(this.audioUploadError=r),await this.failActiveCapture(n,t,i,r)}})});if(i!==this.captureGeneration||this.captureId!==n||this.abortController.signal.aborted){await e.stop();return}this.capture=e,e.completion?.catch(e=>this.failActiveCapture(n,t,i,e instanceof Error?e:Error(String(e)))),this.resolveListening(!0)}catch(e){let r=e instanceof Error?`${e.name}: ${e.message}`:String(e);throw await this.transport.captureStopped(this.clientId,t,n,r).catch(()=>void 0),this.captureId=void 0,this.captureGeneration+=1,this.resolveCaptureEnd(),e}}async failActiveCapture(e,t,n,r){if(n!==this.captureGeneration||this.captureId!==e)return;let i=this.capture;this.capture=void 0,await i?.stop().catch(()=>void 0),n===this.captureGeneration&&this.captureId===e&&(this.captureId=void 0,this.captureGeneration+=1,this.resolveCaptureEnd(),$t(r)?await this.speechDetector?.reset().catch(()=>void 0):(this.transport.captureStopped(this.clientId,t,e,`${r.name}: ${r.message}`).catch(()=>void 0),this.failAttempt?.(r)))}async finishCapture(e,t,n){let r=this.advertisedCapabilities;await this.capture?.stop(),this.capture=void 0,await this.audioUploads,await this.speechDetector?.reset().catch(()=>void 0),this.speechDetector=void 0,this.activityLifecycle=void 0;let i=nn(this.device.capabilities);if(r!==void 0&&!rn(r,i)&&this.transport.refreshCapabilities)try{await this.transport.refreshCapabilities(this.clientId,t,i),this.activeConnectionId===t&&(this.advertisedCapabilities=i)}catch{}if(this.audioUploadError!==void 0){let n=this.audioUploadError;throw await this.transport.captureStopped(this.clientId,t,e,`${n.name}: ${n.message}`).catch(()=>void 0),this.captureId=void 0,this.captureGeneration+=1,this.resolveCaptureEnd(),n}this.captureId=void 0,this.captureGeneration+=1,this.resolveListening(!1);try{n&&await this.transport.captureStopped(this.clientId,t,e)}finally{this.resolveCaptureEnd()}}async startPlayback(e,t){this.playbackAudioController?.abort(),this.playback?.stop(`aborted`),this.scheduleActivityReset();let n=e.delivery===`streamed`?new AbortController:void 0;this.playbackAudioController=n;let r=n?this.transport.receivePlaybackAudio?.(this.clientId,t,e.playbackId,n.signal):void 0,i;try{i=this.device.speak(e,r)}catch(r){n?.abort(),await this.transport.playbackFinished(this.clientId,t,tn(e.playbackId,r)),this.scheduleActivityReset();return}this.playback=i,i.completion.then(e=>this.transport.playbackFinished(this.clientId,t,e),n=>this.transport.playbackFinished(this.clientId,t,tn(e.playbackId,n))).catch(e=>{this.activeConnectionId!==t||this.abortController.signal.aborted||this.failAttempt?.(e instanceof Error?e:Error(String(e)))}).finally(()=>{this.playback===i&&(n?.abort(),this.playbackAudioController===n&&(this.playbackAudioController=void 0),this.playback=void 0,this.scheduleActivityReset())})}scheduleActivityReset(){let e=this.captureGeneration,t=this.activityLifecycle,n=this.speechDetector;t&&n&&(this.audioUploads=this.audioUploads.then(async()=>{e===this.captureGeneration&&t===this.activityLifecycle&&n===this.speechDetector&&(t.resetActivity(),await n.reset().catch(()=>void 0))}))}async releaseMedia(e=!0){this.captureGeneration+=1;let t=this.capture,n=this.audioUploads,r=this.speechDetector;this.capture=void 0,this.audioUploads=Promise.resolve(),this.speechDetector=void 0,this.activityLifecycle=void 0,this.captureId=void 0,this.resolveCaptureEnd(),this.audioUploadError=void 0,await t?.stop().catch(()=>void 0),this.resolveListening(!1),n.catch(()=>void 0),r?.reset().catch(()=>void 0),this.playbackAudioController?.abort(),this.playbackAudioController=void 0,this.playback?.stop(`aborted`),this.playback=void 0,e&&await this.device.close().catch(()=>void 0)}resolveListening(e){for(let t of this.listeningWaiters)t(e);this.listeningWaiters.clear()}resolveCaptureEnd(){for(let e of this.captureEndWaiters)e();this.captureEndWaiters.clear()}nextConnectionId(){let e=`:${(++this.connectionAttempt).toString(36)}`;return`${this.connectionId.slice(0,Yt-e.length)}${e}`}},sn=globalThis,cn=Symbol.for(`@agimon-ai/po-voice:microphone-preferences.v2`),ln=globalThis,q=ln[cn]??=d({inputs:[]}),un=`po.voice.microphone.v1`;function dn(){try{let e=sn.localStorage.getItem(un);if(e===null)return;let t=JSON.parse(e);if(typeof t!=`object`||!t)return;let{deviceId:n,inputs:r}=t;return n!==null&&typeof n!=`string`||!Array.isArray(r)||r.some(e=>typeof e!=`string`)?void 0:{deviceId:n,inputs:r}}catch{return}}function fn(e){try{sn.localStorage.setItem(un,JSON.stringify(e))}catch{}}async function pn(){let e=(await sn.navigator.mediaDevices.enumerateDevices().catch(()=>[])).filter(e=>e.kind===`audioinput`&&e.deviceId&&e.deviceId!=="default"&&e.deviceId!==`communications`).map(({deviceId:e,groupId:t,label:n})=>({deviceId:e,groupId:t,label:n}));return q.update(t=>({...t,inputs:e})),e}function mn(){return q.store.state.choice===void 0?new Promise(e=>{q.update(t=>({...t,choice:(t,n)=>{q.update(e=>({...e,choice:void 0})),e({deviceId:t,remember:n})}}))}):Promise.resolve({deviceId:null,remember:!1})}function hn(){q.store.state.choice?.(null,!1)}async function gn(){let e;try{(await sn.navigator.mediaDevices.enumerateDevices().catch(()=>[])).some(e=>e.kind===`audioinput`&&e.label)||(e=await sn.navigator.mediaDevices.getUserMedia(L));let t=await pn();if(t.length<2)return L;let n=t.map(e=>e.deviceId).sort(),r=dn();if(r!==void 0&&r.inputs.join()===n.join())return r.deviceId===null?L:Ie(r.deviceId);let{deviceId:i,remember:a}=await mn();return a&&fn({deviceId:i,inputs:n}),i===null?L:Ie(i)}finally{e?.getTracks().forEach(e=>e.stop())}}var _n=new URL(new URL(`../assets/browserCaptureWorklet-Droj0fW0-Droj0fW0.js`,import.meta.url).href,``+import.meta.url).href,vn=2,yn=32768,bn=2e3,xn=300,Sn=500,Cn=800,wn=20,Tn=4,En=16,Dn=-55,On=-50,kn=.65,An=.75,jn=.25,Mn=.35,Nn=.35,Pn=.5,Fn=4,In=.98,Ln=.01,Rn=F*bn/1e3,zn=F*xn/1e3,Bn=F*Sn/1e3,Vn=Cn/1e3,Hn=F*wn/1e3;function Un(e,t,n){return Math.min(n,Math.max(t,e))}function Wn(e){if(e.byteLength===0||e.byteLength%vn!==0)throw Error(`Echo-discrimination input must contain complete PCM16 samples.`);let t=new Float32Array(e.byteLength/vn),n=new DataView(e.buffer,e.byteOffset,e.byteLength);for(let e=0;e<t.length;e+=1)t[e]=n.getInt16(e*2,!0)/yn;return t}function Gn(e){let t=new Uint8Array(e.length*vn),n=new DataView(t.buffer);for(let t=0;t<e.length;t+=1){let r=Un(e[t]??0,-1,1);n.setInt16(t*vn,Math.round(r<0?r*yn:r*32767),!0)}return t}function Kn(e,t){let n=Math.min(e.length,Math.max(0,Rn-t.length)),r=new Float32Array(n+t.length);return n>0&&r.set(e.subarray(e.length-n)),r.set(t,n),r}function qn(e){return e<=0?-1/0:10*Math.log10(e)}function Jn(e){if(e.length===0)return 0;let t=0;for(let n of e)t+=n*n;return t/e.length}function Yn(e){if(e.length===0)return 0;let t=0;for(let n of e)Math.abs(n)>=In&&(t+=1);return t/e.length}function Xn(e,t,n,r,i,a){let o=0,s=0,c=0;for(let l=0;l<i;l+=a){let i=e[n+l],a=t[r+l];i!==void 0&&a!==void 0&&(o+=i,s+=a,c+=1)}if(c<2)return 0;let l=o/c,u=s/c,d=0,f=0,p=0;for(let o=0;o<i;o+=a){let i=e[n+o],a=t[r+o];if(i===void 0||a===void 0)continue;let s=i-l,c=a-u;d+=s*c,f+=s*s,p+=c*c}let m=Math.sqrt(f*p);return m<=2**-52?0:d/m}function Zn(e,t,n,r,i){let a=[],o=[];for(let s=0;s+Hn<=i;s+=Hn){let i=0,c=0;for(let a=0;a<Hn;a+=1){let o=e[n+s+a]??0,l=t[r+s+a]??0;i+=o*o,c+=l*l}a.push(Math.log10(Math.max(2**-52,i/Hn))),o.push(Math.log10(Math.max(2**-52,c/Hn)))}return a.length<3?0:Xn(Float32Array.from(a),Float32Array.from(o),0,0,a.length,1)}function Qn(e){return new Uint8Array(e.byteLength)}var $n=class{references=[];microphoneHistory=new Float32Array;referenceHistory=new Float32Array;beginPlayback(e,t,n){if(e&&t.length!==0&&Number.isFinite(n)){for(let e of this.references)e.endedAt===void 0&&this.finishReference(e,n);this.references.push({playbackId:e,samples:t,startedAt:n})}}endPlayback(e,t){if(!Number.isFinite(t))return;let n=this.references.slice().reverse().find(t=>t.playbackId===e);n!==void 0&&n.endedAt===void 0&&this.finishReference(n,t)}process(e,t){let n=Wn(e);if(!Number.isFinite(t))return this.unavailable(e,n);let r=t-n.length/F;this.pruneReferences(r);let i=this.renderReference(r,n.length);if(this.microphoneHistory=Kn(this.microphoneHistory,n),this.referenceHistory=Kn(this.referenceHistory,i.samples),!i.tracked)return{speechPcm:new Uint8Array(e),referenceActive:!1,speechDiscriminated:!1,state:`unavailable`};let a=Math.min(zn,this.microphoneHistory.length),o=this.microphoneHistory.length-a,s=this.referenceHistory.length-a,c=Math.min(Bn,s),l=Math.max(0,s-c),u=this.referenceHistory.subarray(l),d=this.microphoneHistory.subarray(o),f=qn(Jn(d));if(qn(Jn(u))<Dn)return f>=On?{speechPcm:new Uint8Array(e),referenceActive:!0,speechDiscriminated:!0,state:`near-end`}:{speechPcm:Qn(e),referenceActive:!0,speechDiscriminated:!1,state:`echo`};if(a<zn||c<=0||Yn(d)>Ln)return{speechPcm:Qn(e),referenceActive:!0,speechDiscriminated:!1,state:`uncertain`};let p=0,m=0;for(let e=0;e<=c;e+=En){let t=Xn(this.microphoneHistory,this.referenceHistory,o,s-e,a,Tn);Math.abs(t)>Math.abs(m)&&(m=t,p=e)}let h=Math.max(0,p-En),g=Math.min(c,p+En);for(let e=h;e<=g;e+=1){let t=Xn(this.microphoneHistory,this.referenceHistory,o,s-e,a,2);Math.abs(t)>Math.abs(m)&&(m=t,p=e)}let _=s-p,v=Math.abs(Zn(this.microphoneHistory,this.referenceHistory,o,_,a)),y=Math.abs(m),b=0,x=0,S=0;for(let e=0;e<a;e+=1){let t=this.microphoneHistory[o+e]??0,n=this.referenceHistory[_+e]??0;b+=t*n,x+=n*n,S+=t*t}let C=Un(x<=2**-52?0:b/x,0,Fn),w=0;for(let e=0;e<a;e+=1){let t=(this.microphoneHistory[o+e]??0)-C*(this.referenceHistory[_+e]??0);w+=t*t}let T=S<=2**-52?0:w/S,E=new Float32Array(n.length),ee=this.microphoneHistory.length-n.length,te=this.referenceHistory.length-n.length-p;for(let e=0;e<n.length;e+=1)E[e]=(this.microphoneHistory[ee+e]??0)-C*(this.referenceHistory[te+e]??0);let ne=Gn(E),D=qn(Jn(E));return m>=kn&&T<=Nn?{speechPcm:Qn(e),referenceActive:!0,speechDiscriminated:!1,state:`echo`}:m>=kn&&v<An&&T>=Pn&&D>=On?{speechPcm:ne,referenceActive:!0,speechDiscriminated:!0,state:`mixed`}:y<jn&&v<Mn&&f>=On?{speechPcm:new Uint8Array(e),referenceActive:!0,speechDiscriminated:!0,state:`near-end`}:v>=An?{speechPcm:Qn(e),referenceActive:!0,speechDiscriminated:!1,state:`echo`}:{speechPcm:Qn(e),referenceActive:!0,speechDiscriminated:!1,state:`uncertain`}}resetCapture(){this.microphoneHistory=new Float32Array,this.referenceHistory=new Float32Array}reset(){this.references=[],this.resetCapture()}unavailable(e,t=Wn(e)){return this.microphoneHistory=Kn(this.microphoneHistory,t),this.referenceHistory=Kn(this.referenceHistory,new Float32Array(t.length)),{speechPcm:new Uint8Array(e),referenceActive:!1,speechDiscriminated:!1,state:`unavailable`}}renderReference(e,t){let n=new Float32Array(t),r=!1;for(let i of this.references){let a=i.startedAt+i.samples.length/F,o=Math.min(i.endedAt??a,a);e<o+Vn&&e+t/16e3>=i.startedAt&&(r=!0);let s=Math.round((e-i.startedAt)*F),c=Math.round((o-i.startedAt)*F);for(let e=0;e<t;e+=1){let t=s+e;t<0||t>=c||(n[e]+=i.samples[t]??0)}}return{samples:n,tracked:r}}finishReference(e,t){let n=e.startedAt+e.samples.length/F;e.endedAt=Math.max(e.startedAt,Math.min(t,n));let r=Math.ceil((e.endedAt-e.startedAt)*F),i=Math.max(0,r-Bn-zn);e.samples=new Float32Array(e.samples.subarray(i,r)),e.startedAt+=i/F}pruneReferences(e){this.references=this.references.filter(t=>t.endedAt===void 0||e<=t.endedAt+Vn)}},er=5e3,tr=class extends Error{};function nr(e){return typeof e==`object`&&!!e&&Number.isSafeInteger(e.id)}var rr=class{worker;onTerminalFailure;responseTimeoutMs;nextRequestId=0;generation=0;operation=Promise.resolve();pending=new Map;closed=!1;failure;constructor(e,t=()=>void 0,n=er){this.worker=e,this.onTerminalFailure=t,this.responseTimeoutMs=n,e.onmessage=e=>{if(!nr(e.data)){this.failTerminal(Error(`Silero worker returned a malformed response.`));return}let t=this.pending.get(e.data.id);t!==void 0&&(e.data.error===void 0?(this.pending.delete(e.data.id),t.timer!==void 0&&clearTimeout(t.timer),t.resolve(e.data.result)):this.failTerminal(Error(e.data.error)))},e.onerror=e=>this.failTerminal(Error(e.message||`Silero worker failed.`))}async initialize(e){if(await this.enqueue(()=>this.request({type:`initialize`,modelUrl:e}))!==!0){let e=Error(`Silero worker returned an invalid initialization response.`);throw this.failTerminal(e),e}}async push(e){let t=this.generation,n=new Uint8Array(e),r;try{r=await this.enqueue(()=>this.request({type:`push`,pcm:n.buffer},[n.buffer],this.responseTimeoutMs))}catch(e){if(e instanceof tr)return[];throw e}if(t!==this.generation)return[];if(!Array.isArray(r))throw Error(`Silero worker returned invalid speech windows.`);return r}async reset(){this.generation+=1,await this.enqueue(()=>this.request({type:`reset`},void 0,this.responseTimeoutMs))}async close(){this.closed||(this.closed=!0,this.generation+=1,this.worker.onmessage=null,this.worker.onerror=null,this.worker.terminate(),this.failAll(Error(`Silero worker closed.`)))}enqueue(e){let t=this.operation.then(e,e);return this.operation=t,t}request(e,t,n){if(this.closed)return Promise.reject(this.failure??Error(`Silero worker is closed.`));let r=++this.nextRequestId;return new Promise((i,a)=>{let o={resolve:i,reject:a};n!==void 0&&(o.timer=setTimeout(()=>{this.pending.has(r)&&this.failTerminal(new tr(`Silero worker response timed out.`))},n)),this.pending.set(r,o),this.worker.postMessage({id:r,...e},t)})}failTerminal(e){this.closed||(this.failure=e,this.closed=!0,this.generation+=1,this.worker.onmessage=null,this.worker.onerror=null,this.worker.terminate(),this.failAll(e),this.onTerminalFailure())}failAll(e){for(let t of this.pending.values())t.timer!==void 0&&clearTimeout(t.timer),t.reject(e);this.pending.clear()}},ir=new URL(new URL(`../assets/silero_vad_v6.2.1-SjbCxFXk-SjbCxFXk.onnx`,import.meta.url).href,``+import.meta.url).href,ar=new URL(new URL(`../assets/sileroVadWorker-D894njUe-DjN_BMWf.mjs`,import.meta.url).href,``+import.meta.url).href,or=4096,sr=100,cr=`po-voice-capture`,lr=180,ur=5e3,dr=1e4,fr=.1,pr=10,mr=2,hr=32767,gr=F*mr*sr/1e3,_r=1e-8,vr=.05,yr=F*300/1e3;function br(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.samples instanceof Float32Array&&typeof t.capturedAt==`number`}function xr(){return typeof window<`u`&&typeof window.speechSynthesis?.speak==`function`}function Sr(){return typeof AudioContext==`function`}function Cr(){if(typeof SpeechSynthesisUtterance==`function`)return SpeechSynthesisUtterance;if(typeof window>`u`)return;let e=window.SpeechSynthesisUtterance;return typeof e==`function`?e:void 0}var wr=class{sourceRate;sourceIndex=0;nextOutputAt=0;constructor(e){if(this.sourceRate=e,!Number.isFinite(e)||e<=0)throw Error(`Audio source rate must be positive.`)}push(e){let t=[],n=this.sourceRate/F;for(let r=0;r<e.length;r+=1){let i=this.sourceIndex+r;for(;this.nextOutputAt<=i;){let i=Math.max(-1,Math.min(1,e[r]??0));t.push(Math.round(i<0?i*32768:i*hr)),this.nextOutputAt+=n}}this.sourceIndex+=e.length;let r=new Uint8Array(t.length*2),i=new DataView(r.buffer);return t.forEach((e,t)=>i.setInt16(t*2,e,!0)),r}},Tr=class{synthesis;utterance;playbackId;completion;requestedOutcome;settleCompletion;settled=!1;ducked=!1;fadeTimer;restoreTimer;startTimer;constructor(e,t,n){this.synthesis=e,this.utterance=t,this.playbackId=n,this.completion=new Promise(e=>{this.settleCompletion=e}),t.onstart=()=>{this.startTimer!==void 0&&clearTimeout(this.startTimer),this.startTimer=void 0},t.onend=()=>this.settle(this.requestedOutcome??`completed`),t.onerror=e=>this.settle(this.requestedOutcome??`failed`,e.error||`Browser speech synthesis failed.`),this.startTimer=setTimeout(()=>{this.synthesis.cancel(),this.settle(`failed`,`Browser speech synthesis did not start.`)},ur)}stop(e){this.settled||(this.requestedOutcome=e,this.synthesis.cancel(),this.settle(e))}duck(e,t,n){if(this.settled||this.ducked)return;this.ducked=!0;let r=Math.max(0,Math.min(1,e));this.fadeTo(r,Math.max(0,t),()=>{this.restoreTimer=setTimeout(()=>{this.restoreTimer=void 0,this.fadeTo(1,600,()=>{this.ducked=!1})},Math.max(0,n))})}fadeTo(e,t,n){this.fadeTimer!==void 0&&clearInterval(this.fadeTimer),this.fadeTimer=void 0;let r=this.utterance.volume,i=Math.max(1,Math.ceil(t/50)),a=0,o=()=>{a+=1,this.utterance.volume=r+(e-r)*Math.min(1,a/i),!(a<i)&&(this.fadeTimer!==void 0&&clearInterval(this.fadeTimer),this.fadeTimer=void 0,n())};t===0?o():this.fadeTimer=setInterval(o,t/i)}settle(e,t){this.settled||(this.settled=!0,this.fadeTimer!==void 0&&clearInterval(this.fadeTimer),this.restoreTimer!==void 0&&clearTimeout(this.restoreTimer),this.startTimer!==void 0&&clearTimeout(this.startTimer),this.fadeTimer=void 0,this.restoreTimer=void 0,this.startTimer=void 0,this.utterance.onstart=null,this.utterance.onend=null,this.utterance.onerror=null,this.settleCompletion({playbackId:this.playbackId,outcome:e,...t?{error:t}:{}}))}},Er=class{context;playbackId;echoDiscriminator;completion;source;gain;settled=!1;settleCompletion;restoreTimer;startedAt;constructor(e,t,n,r){this.context=e,this.playbackId=n,this.echoDiscriminator=r,this.completion=new Promise(e=>{this.settleCompletion=e}),this.start(t)}stop(e){this.settled||(this.source!==void 0&&(this.source.onended=null),this.source?.stop(),this.settle(e))}duck(e,t,n){this.settled||this.gain===void 0||(this.gain.gain.value=Math.max(0,Math.min(1,e)),this.restoreTimer!==void 0&&clearTimeout(this.restoreTimer),this.restoreTimer=setTimeout(()=>{this.restoreTimer=void 0,this.gain!==void 0&&(this.gain.gain.value=1)},Math.max(0,n)))}async start(e){try{let t=await e;if(this.settled)return;if(t.byteLength===0||t.byteLength%mr!==0)throw Error(`Streamed narration audio is empty or incomplete.`);if(this.context.state!==`running`)throw Error(`Browser audio playback is suspended. Tap the voice control.`);let n=new Float32Array(t.byteLength/mr),r=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let e=0;e<n.length;e+=1)n[e]=r.getInt16(e*2,!0)/32768;let i=this.context.createBuffer(1,n.length,F);i.copyToChannel(n,0);let a=this.context.createBufferSource(),o=this.context.createGain();o.gain.value=1,a.buffer=i,a.onended=()=>this.settle(`completed`),a.connect(o),o.connect(this.context.destination),this.source=a,this.gain=o;let s=this.context.currentTime;this.startedAt=s,this.echoDiscriminator.beginPlayback(this.playbackId,i.getChannelData(0),s),a.start(s)}catch(e){let t=e instanceof Error?`${e.name}: ${e.message}`:String(e);this.settle(`failed`,t)}}settle(e,t){this.settled||(this.settled=!0,this.restoreTimer!==void 0&&clearTimeout(this.restoreTimer),this.source!==void 0&&(this.source.onended=null),this.startedAt!==void 0&&this.echoDiscriminator.endPlayback(this.playbackId,this.context.currentTime),this.source?.disconnect(),this.gain?.disconnect(),this.source=void 0,this.gain=void 0,this.settleCompletion({playbackId:this.playbackId,outcome:e,...t?{error:t}:{}}))}},Dr=class{rebindProtocolSupported;microphoneConstraints;capabilities={capture:typeof navigator<`u`&&navigator.mediaDevices?.getUserMedia!==void 0,playback:xr()||Sr(),captureActivity:!1,autonomousOrchestration:!1,playbackDucking:xr()||Sr(),realtime:typeof RTCPeerConnection==`function`&&typeof navigator<`u`&&navigator.mediaDevices?.getUserMedia!==void 0};captureGeneration=0;captureDeviceId;constructor(e=!1,t=async()=>L){this.rebindProtocolSupported=e,this.microphoneConstraints=t}armUserGesture(){this.listenForMediaUnlock()}stream;context;workletInstalled=!1;activeCapture;activePlayback;speechDetector;preparingSpeechDetector;speechPreparation;listeningForMediaUnlock=!1;speechWarmup;speechWarmupTimer;echoDiscriminator=new $n;unlockMedia=()=>{if(typeof AudioContext<`u`)try{this.context??=new AudioContext;let e=this.context;e.resume().then(()=>{e.state===`running`&&this.stopListeningForMediaUnlock()}).catch(()=>void 0)}catch{}this.warmSpeechSynthesis()};async prepare(){this.armUserGesture(),this.speechPreparation??=this.prepareSpeechDetector(),await this.speechPreparation}createSpeechPresenceDetector(){return this.speechDetector}async startCapture(e){if(!this.capabilities.capture)throw Error(`This browser cannot capture microphone audio.`);if(this.activeCapture!==void 0)throw Error(`Browser microphone capture is already active.`);let t=this.captureGeneration,n=await this.microphoneConstraints();if(t!==this.captureGeneration)throw Error(`Microphone capture was cancelled.`);let r=n.audio.deviceId?.exact;if(this.stream&&this.captureDeviceId!==r){for(let e of this.stream.getTracks())e.stop();this.stream=void 0}if(this.stream??=await navigator.mediaDevices.getUserMedia(n),t!==this.captureGeneration){for(let e of this.stream.getTracks())e.stop();throw this.stream=void 0,Error(`Microphone capture was cancelled.`)}if(this.captureDeviceId=r,this.context??=new AudioContext,await this.context.resume(),this.context.state!==`running`)throw Error(`Browser audio capture is suspended. Tap the voice control and try again.`);this.stopListeningForMediaUnlock();let i=this.stream,a=this.context.createMediaStreamSource(i),o=this.context.createGain();o.gain.value=_r;let s=new wr(this.context.sampleRate);this.echoDiscriminator.resetCapture();let c=[],l=0,u,d=0,f,p=0,m=t=>{let n=new Uint8Array(t),r=0;for(;r<t;){let e=c[0];if(e===void 0)break;let i=Math.min(e.byteLength,t-r);n.set(e.subarray(0,i),r),r+=i,i===e.byteLength?c.shift():c[0]=e.subarray(i)}l-=t;let i=t/mr,a=(u??this.context.currentTime)+(d+i)/F;d+=i;let o=this.echoDiscriminator.process(n,a),s=p>0;p=Math.max(0,p-i),e(n,{speechPcm:s?new Uint8Array(n.byteLength):o.speechPcm,echoReferenceActive:o.referenceActive,echoDiscriminated:!s&&o.speechDiscriminated})},h=(e,t)=>{let n=t!==void 0&&Number.isFinite(t)?t:void 0;n!==void 0&&f!==void 0&&Math.abs(n-f)>vr&&(this.echoDiscriminator.resetCapture(),p=l/mr+yr,u=n-(d+l/mr)/F),n!==void 0&&(f=n+e.length/this.context.sampleRate),u??=n??this.context.currentTime-e.length/this.context.sampleRate;let r=s.push(e);if(r.byteLength!==0)for(c.push(r),l+=r.byteLength;l>=gr;)m(gr)},g,_;if(typeof AudioWorkletNode<`u`&&this.context.audioWorklet!==void 0){this.workletInstalled||=(await this.context.audioWorklet.addModule(_n),!0);let e=new AudioWorkletNode(this.context,cr);e.port.onmessage=e=>{br(e.data)&&h(e.data.samples,e.data.capturedAt)},g=e,_=()=>{e.port.onmessage=null,e.port.close()}}else{let e=this.context.createScriptProcessor(or,1,1);e.onaudioprocess=e=>h(e.inputBuffer.getChannelData(0),e.playbackTime),g=e,_=()=>{e.onaudioprocess=null}}a.connect(g),g.connect(o),o.connect(this.context.destination);let v=!1,y,b,x=new Promise((e,t)=>{y=e,b=t});for(let e of i.getTracks())e.onended=()=>b(Error(`The selected microphone was disconnected.`));let S={completion:x,stop:async()=>{if(!v){v=!0;for(let e of i.getTracks())e.onended=null;if(y(),_(),l>0&&m(l),a.disconnect(),g.disconnect(),o.disconnect(),!this.rebindProtocolSupported||this.stream!==i)for(let e of i.getTracks())e.stop();!this.rebindProtocolSupported&&this.stream===i&&(this.stream=void 0),this.activeCapture===S&&(this.activeCapture=void 0)}}};return this.activeCapture=S,S}speak(e,t){if(!this.capabilities.playback)throw Error(`This browser cannot play speech narration.`);this.activePlayback?.stop(`aborted`);let n;if(e.delivery===`streamed`){if(t===void 0)throw Error(`Streamed narration audio is unavailable.`);if(typeof AudioContext!=`function`)throw Error(`This browser cannot play streamed narration audio.`);if(this.context===void 0||this.context.state!==`running`)throw Error(`Browser audio playback is not unlocked. Tap the voice control and try again.`);n=new Er(this.context,t,e.playbackId,this.echoDiscriminator)}else{this.finishSpeechWarmup(!1);let t=window.speechSynthesis,r=Cr();if(r===void 0)throw Error(`This browser does not expose speech utterance playback.`);t.resume();let i=new r(e.text);e.rate!==void 0&&(i.rate=Math.max(fr,Math.min(pr,e.rate/lr))),e.voice&&(i.voice=t.getVoices().find(t=>t.name===e.voice||t.voiceURI===e.voice)??null),n=new Tr(t,i,e.playbackId),t.speak(i)}return this.activePlayback=n,n.completion.finally(()=>{this.activePlayback===n&&(this.activePlayback=void 0)}),n}async close(){this.captureGeneration+=1;let e=this.speechDetector,t=this.preparingSpeechDetector,n=this.speechPreparation;this.speechDetector=void 0,this.preparingSpeechDetector=void 0,this.speechPreparation=void 0,this.capabilities.captureActivity=!1,this.capabilities.autonomousOrchestration=!1,await e?.close().catch(()=>void 0),t!==e&&await t?.close().catch(()=>void 0),await n?.catch(()=>void 0),this.stopListeningForMediaUnlock(),this.finishSpeechWarmup(!0),await this.activeCapture?.stop(),this.activePlayback?.stop(`aborted`);for(let e of this.stream?.getTracks()??[])e.stop();this.stream=void 0,this.context!==void 0&&this.context.state!==`closed`&&await this.context.close(),this.echoDiscriminator.reset(),this.context=void 0,this.workletInstalled=!1}listenForMediaUnlock(){this.listeningForMediaUnlock||typeof window>`u`||!this.capabilities.capture&&!this.capabilities.playback||(this.listeningForMediaUnlock=!0,window.addEventListener(`pointerdown`,this.unlockMedia,{capture:!0,passive:!0}),window.addEventListener(`keydown`,this.unlockMedia,{capture:!0}))}stopListeningForMediaUnlock(){this.listeningForMediaUnlock&&typeof window<`u`&&(this.listeningForMediaUnlock=!1,window.removeEventListener(`pointerdown`,this.unlockMedia,!0),window.removeEventListener(`keydown`,this.unlockMedia,!0))}warmSpeechSynthesis(){if(!xr()||this.activePlayback!==void 0||this.speechWarmup!==void 0)return;let e=window.speechSynthesis,t=Cr();if(t===void 0||(e.resume(),e.speaking||e.pending))return;let n=new t(`a`);n.volume=.01,n.rate=pr,n.onend=()=>this.finishSpeechWarmup(!1),n.onerror=()=>this.finishSpeechWarmup(!1),this.speechWarmup=n,this.speechWarmupTimer=setTimeout(()=>this.finishSpeechWarmup(!0),dr),e.speak(n)}finishSpeechWarmup(e){let t=this.speechWarmup;t!==void 0&&(this.speechWarmupTimer!==void 0&&clearTimeout(this.speechWarmupTimer),this.speechWarmupTimer=void 0,this.speechWarmup=void 0,t.onend=null,t.onerror=null,e&&window.speechSynthesis.cancel())}async prepareSpeechDetector(){if(typeof Worker>`u`||typeof WebAssembly>`u`)return;let e;try{if(e=new rr(new Worker(ar,{type:`module`,name:`po-silero-vad`}),()=>{(this.preparingSpeechDetector===e||this.speechDetector===e)&&(this.preparingSpeechDetector===e&&(this.preparingSpeechDetector=void 0),this.speechDetector===e&&(this.speechDetector=void 0),this.capabilities.captureActivity=!1,this.capabilities.autonomousOrchestration=!1)}),this.preparingSpeechDetector=e,await e.initialize(ir),this.preparingSpeechDetector!==e){await e.close().catch(()=>void 0);return}this.preparingSpeechDetector=void 0,this.speechDetector=e,this.capabilities.captureActivity=!0,this.capabilities.autonomousOrchestration=this.rebindProtocolSupported}catch{this.preparingSpeechDetector===e&&(this.preparingSpeechDetector=void 0),this.speechDetector===e&&(this.speechDetector=void 0),await e?.close().catch(()=>void 0)}}};function Or(){let e=De({header:M()});if(e.status!==`ok`||!e.metadata.instanceId)throw Error(`Voice requires the shell client instance identity.`);return e.metadata.instanceId}var kr=`application/json`,Ar=6e4,jr=200,Mr=8e3,Nr=2e4;function Pr(e){return typeof e.eventEpoch==`string`&&e.eventEpoch.length>0&&e.eventEpoch.length<=jr&&Number.isSafeInteger(e.heartbeatMs)&&(e.heartbeatMs??0)>0&&(e.heartbeatMs??0)<=Ar?{eventEpoch:e.eventEpoch,heartbeatMs:e.heartbeatMs}:void 0}function J(e){return Object.assign(Error(e.error===``?`Voice media request failed with status ${String(e.status)}.`:e.error),{status:e.status,conflict:e.data})}function Fr(e){if(!e.ok)throw J(e);if(`standby`in e.data)throw Object.assign(Error(`Another client owns voice media for this session.`),{status:409,standby:!0,conflict:e.data.conflict});return e.data}async function Ir(e){let t=`Voice media request failed with status ${String(e.status)}.`,n;try{let r=await e.json();n=r,typeof r==`object`&&r&&`error`in r&&typeof r.error==`string`&&(t=r.error)}catch{}return Object.assign(Error(t),{status:e.status,conflict:n})}function Y(e){return{method:`POST`,headers:{"content-type":kr},body:JSON.stringify(e)}}function Lr(e,t={}){let n=new URL(e,`http://po.local`);for(let[e,r]of Object.entries(t))r!==void 0&&n.searchParams.set(e,String(r));return`${n.pathname}${n.search}`}function Rr(e){try{e?.body?.cancel().catch(()=>void 0)}catch{}}async function zr(e,t,n,r,i,a=(e,t)=>le.fetch(e,t)){let o=new AbortController,s=i??o.signal,c,l=!1,u,d,f=new Promise((e,t)=>{d=t}),p=e=>{l||(l=!0,u=e,o.abort(e),Rr(c),d(e))},m=()=>p(i?.reason??new DOMException(`Voice media control request was aborted.`,`AbortError`)),h=setTimeout(()=>p(Error(`Voice media control request timed out.`)),n);i?.addEventListener(`abort`,m,{once:!0});let g;try{g=a(e,{...t,signal:s})}catch(e){throw clearTimeout(h),i?.removeEventListener(`abort`,m),e}let _=g.then(async e=>{if(c=e,l)throw Rr(e),u;return r(e)});try{return i?.aborted&&m(),await Promise.race([_,f])}finally{clearTimeout(h),i?.removeEventListener(`abort`,m)}}var Br=class{sessionId;claimForActivation;takeoverGeneration;push;controlLocation;binding;constructor(e,t=!1,n){this.sessionId=e,this.claimForActivation=t,this.takeoverGeneration=n}media(){if(this.sessionId===null)throw Error(`PCM routes are session-scoped, not global live media.`);return W.session(this.sessionId)}remote(){return this.sessionId!==null&&/^peer\/[A-Za-z0-9][A-Za-z0-9._-]{0,127}\/[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(this.sessionId)}async fetch(e,t,n={}){if(!this.remote())return le.fetch(t,n);let r=new Headers(n.headers),i=De({header:M()});i.status===`ok`&&r.set(ve,Ee(i.metadata));let a=new Request(new URL(e,`http://po.local`),{...n,headers:r}),o=new Uint8Array(await a.arrayBuffer()),s=new URL(a.url).searchParams.get(`connectionId`)??void 0;if(!s&&o.byteLength>0)try{let e=JSON.parse(new TextDecoder().decode(o));typeof e.connectionId==`string`&&(s=e.connectionId)}catch{s=void 0}if(!s)throw Error(`Paired Voice request has no connection binding.`);if(!this.binding||this.binding.connectionId!==s||this.binding.expiresAt<=Date.now()+Mr){let e=await U.host.relayBinding({body:{target:this.sessionId,connectionId:s}});if(!e.ok)throw J(e);let t=e.data;if(typeof t.binding!=`string`||!Number.isSafeInteger(t.expiresAt))throw Error(`Paired Voice media binding is invalid.`);this.binding={id:t.binding,connectionId:s,expiresAt:t.expiresAt}}let c=``;for(let e of o)c+=String.fromCharCode(e);let l=await U.host.relay({query:{binding:this.binding.id},body:{targetSessionId:``,method:a.method===`GET`?`GET`:`POST`,path:e,headers:[...a.headers.entries()],body:btoa(c)}});if(!l.ok)throw J(l);let u=l.data;if(!Number.isSafeInteger(u.status)||!Array.isArray(u.headers)||typeof u.body!=`string`)throw Error(`Paired Voice relay response is invalid.`);let d=atob(u.body),f=Uint8Array.from(d,e=>e.charCodeAt(0));return new Response(f.byteLength===0?null:f,{status:u.status,headers:u.headers})}async remoteResult(e,t,n){let r=await this.fetch(e,t,n),i;try{i=r.status===204?void 0:await r.json()}catch{i=void 0}return r.ok?{ok:!0,status:r.status,data:i,response:r}:{ok:!1,status:r.status,error:typeof i==`object`&&i&&`error`in i&&typeof i.error==`string`?i.error:`Voice media request failed with status ${String(r.status)}.`,data:i,response:r}}async connect(e,t,n){this.push=void 0;let r=le.active()?`remote`:`local`,i=this.claimForActivation;this.claimForActivation=!1;let a=this.takeoverGeneration;this.takeoverGeneration=void 0;let o=Fr(await this.declareClient(e,t,n,r,i,a));return this.controlLocation=r,this.push=this.sessionId===null?void 0:Pr(o),o}async refreshCapabilities(e,t,n){let r=this.controlLocation;if(r===void 0)throw Error(`Voice media client is not connected.`);let i=this.claimForActivation;this.claimForActivation=!1,Fr(await this.declareClient(e,t,n,r,i))}async disconnect(e,t){try{let n={clientId:e,connectionId:t},r=this.sessionId===null?await W.host.clientDisconnect({body:n}):this.remote()?await this.remoteResult(I.clientDisconnect,``,Y(n)):await this.media().clientDisconnect({body:n});if(!r.ok&&r.status!==409)throw J(r)}finally{this.push=void 0,this.controlLocation=void 0,this.binding=void 0}}async nextEvent(e,t,n,r){let i=this.push,a=this.sessionId;if(i===void 0||a===null)return this.fetchEvent(e,t,n,r,!1);for(;!r.aborted;){let o=await at(a,i.eventEpoch,n,i.heartbeatMs,r);if(r.aborted)return;let s=o??await this.heartbeat(e,t);if(s.eventEpoch!==i.eventEpoch)throw Error(`Voice media broker changed.`);if(s.sequence<=n)continue;let c=await this.fetchEvent(e,t,n,r,!0);if(c===void 0)throw Error(`Voice media wake could not be resolved.`);return c}}declareClient(e,t,n,r,i=!1,a){let o={version:7,clientId:e,connectionId:t,clientKind:`browser`,controlLocation:r,capabilities:n,acceptStandby:!0,...i?{claimForActivation:!0}:{},...a===void 0?{}:{takeoverGeneration:a}};return this.sessionId===null?W.host.clientConnect({body:o}):this.remote()?this.remoteResult(I.clientConnect,``,Y(o)):this.media().clientConnect({body:o})}async fetchEvent(e,t,n,r,i){let a=Lr(I.clientEvents,{clientId:e,connectionId:t,after:n,...i?{wait:`0`}:{}}),o={clientId:e,connectionId:t,after:n,...i?{wait:`0`}:{}},s=this.sessionId===null?W.host.clientEvents.url({query:o}):this.remote()?``:this.media().clientEvents.url({query:o});return zr(s,{},Mr,async e=>{if(e.status!==204){if(!e.ok)throw await Ir(e);return await e.json()}},r,(e,t)=>this.fetch(a,s,t))}heartbeat(e,t){let n=I.clientHeartbeat,r=this.sessionId===null?W.host.clientHeartbeat.url():this.remote()?``:this.media().clientHeartbeat.url();return zr(r,Y({clientId:e,connectionId:t}),Mr,async e=>{if(!e.ok)throw await Ir(e);let t=Le(await e.json());if(t===null)throw Error(`Voice media heartbeat response is invalid.`);return t},void 0,(e,t)=>this.fetch(n,r,t))}async sendAudio(e,t,n,r,i){let a={clientId:e,connectionId:t,captureId:n},o={"content-type":Oe,...i===void 0?{}:{[ke]:i.state,[Ae]:String(i.levelDbfs),[je]:String(i.elapsedMs),...i.epoch===void 0?{}:{[Me]:String(i.epoch)},...i.classifiedSpeechMs===void 0?{}:{[Ne]:String(i.classifiedSpeechMs)},...i.echoDiscriminatedSpeechMs===void 0?{}:{[Pe]:String(i.echoDiscriminatedSpeechMs)}}},s=new Blob([new Uint8Array(r)],{type:Oe}),c=this.remote()?await this.remoteResult(Lr(I.clientAudio,a),``,{method:`POST`,headers:o,body:s}):await this.media().clientAudio({query:a,headers:o,body:s});if(!c.ok)throw J(c)}async captureStopped(e,t,n,r){let i={clientId:e,connectionId:t,captureId:n,...r===void 0?{}:{error:r}},a=this.remote()?await this.remoteResult(I.clientCaptureStopped,``,Y(i)):await this.media().clientCaptureStopped({body:i});if(!a.ok)throw J(a)}async receivePlaybackAudio(e,t,n,r){let i=[],a=0,o=Lr(I.clientPlaybackAudio,{clientId:e,connectionId:t,playbackId:n}),s=this.remote()?``:this.media().clientPlaybackAudio.url({query:{clientId:e,connectionId:t,playbackId:n}});for(;!r.aborted;){let e=await this.fetch(o,s,{signal:r});if(e.status===200&&e.headers.get(`content-type`)?.startsWith(`application/vnd.po.pcm-s16le`)){let t=new Uint8Array(await e.arrayBuffer());i.push(t),a+=t.byteLength}else{if(e.status===204&&e.headers.get(`x-po-playback-state`)===`sealed`){let e=new Uint8Array(a),t=0;for(let n of i)e.set(n,t),t+=n.byteLength;return e}if(e.status!==204)throw await Ir(e)}}throw new DOMException(`Voice playback audio was aborted.`,`AbortError`)}async playbackFinished(e,t,n){let r={clientId:e,connectionId:t,...n},i=this.remote()?await this.remoteResult(I.clientPlaybackResult,``,Y(r)):await this.media().clientPlaybackResult({body:r});if(!i.ok)throw J(i)}async realtimeNegotiate(e,t,n,r,i){let a=H.clientNegotiate,o=this.sessionId===null?W.host.realtimeNegotiate.url():this.remote()?``:this.media().realtimeNegotiate.url();return zr(o,Y({clientId:e,connectionId:t,activationId:n,sdp:r}),Nr,async e=>{if(!e.ok)throw await Ir(e);let t=await e.json();if(typeof t!=`object`||!t||typeof t.sdp!=`string`)throw Error(`Realtime negotiation response is invalid.`);return t.sdp},i,(e,t)=>this.fetch(a,o,t))}async realtimeEvent(e,t,n,r){let i=this.sessionId===null?W.host.realtimeEvent.url():this.remote()?``:this.media().realtimeEvent.url();await this.postRealtime(H.clientEvent,i,{clientId:e,connectionId:t,activationId:n,event:r})}async realtimeState(e,t,n,r){let i=this.sessionId===null?W.host.realtimeState.url():this.remote()?``:this.media().realtimeState.url();await this.postRealtime(H.clientState,i,{clientId:e,connectionId:t,activationId:n,state:r})}postRealtime(e,t,n){return zr(t,Y(n),Mr,async e=>{if(!e.ok)throw await Ir(e)},void 0,(n,r)=>this.fetch(e,t,r))}},Vr=class{device=new Dr(!0,gn);clientId=Or();ownedSessionId=null;handoffActive=!1;releaseAudioPending=!1;selectionGeneration=0;client;globalClient;boundSessionId;operation=Promise.resolve();unsubscribe;closeOnPageHide=()=>this.close();closed=!1;openSession;constructor(){this.device.armUserGesture();let e=()=>this.select(z.store.state),t=z.store.subscribe(e),n=Qe.store.subscribe(e);this.unsubscribe=()=>{t.unsubscribe(),n.unsubscribe()},window.addEventListener(`pagehide`,this.closeOnPageHide,{once:!0}),this.select(z.store.state)}focus(e){}close(){if(this.closed)return;this.closed=!0,hn(),window.removeEventListener(`pagehide`,this.closeOnPageHide),this.unsubscribe(),this.client?.endRealtime(),this.globalClient?.endRealtime();let e=async()=>{try{await this.detach(),await this.globalClient?.stop(!1),this.globalClient=void 0}finally{await this.device.close()}};this.operation=this.operation.then(e,e).then(()=>void 0,()=>void 0)}async prepareLiveActivation(e){if(this.closed)throw Error(`Voice media page is closed.`);if(e!==void 0&&this.globalClient){let e=this.globalClient;this.globalClient=void 0,await e.stop(!1)}if(this.globalClient||this.startGlobalClient(!0,e),!this.globalClient)throw Error(`Global Voice media is unavailable.`);return this.globalClient.waitForConnection()}async prepareSessionActivation(e,t){if(this.closed)throw Error(`Voice media page is closed.`);if(await this.operation,(t!==void 0||B.store.state?.phase===`conflict`)&&await this.detach(),await this.attach(e,this.selectionGeneration,!0,t),!this.client)throw Error(`Session Voice media is unavailable.`);return this.client.waitForConnection()}startGlobalClient(e=!1,t){try{if(this.closed)return;let n={capabilities:{capture:!1,playback:!1,captureActivity:!1,autonomousOrchestration:!1,realtime:!0},async startCapture(){throw Error(`Global live Voice does not accept PCM capture.`)},speak(){throw Error(`Global live Voice does not accept PCM playback.`)},async close(){}},r;r=new on(this.clientId,`global-${crypto.randomUUID()}`,new Br(null,e,t),n,(e,n)=>{if(this.globalClient!==r)return;e===`conflict`&&this.reportOwnership(null,n,t);let i=B.store.state;i?.sessionId===null&&(e===`disconnected`&&i.realtime?.connection!==`failed`?B.reset():e!==`disconnected`&&B.update(()=>({...i,phase:e})))},(e,t)=>{if(this.globalClient!==r)return;if(e===void 0){if(B.store.state?.sessionId===null&&B.reset(),V.store.state?.sessionId===null&&V.reset(),t)return;this.globalClient=void 0,r.stop(!1);return}let n=B.store.state;B.update(()=>({sessionId:null,phase:n?.sessionId===null?n.phase:`connected`,realtime:e,realtimeOutputInterrupted:n?.sessionId===null?n.realtimeOutputInterrupted:void 0})),V.update(()=>({sessionId:null,mute:e=>this.controlGlobal(e?`mute`:`unmute`),interrupt:()=>{r.interruptRealtime(),this.controlGlobal(`interrupt`);let e=B.store.state;e?.sessionId===null&&B.update(()=>({...e,realtimeOutputInterrupted:!0}))},end:()=>{r.endRealtime(),this.controlGlobal(`end`)}}))},e=>new It(e,gn),e=>this.openSession?.(e)),this.globalClient=r,r.start()}catch(e){if(this.closed||B.store.state?.sessionId)return;let t=e instanceof Error?e.message:String(e);B.update(()=>({sessionId:null,phase:`conflict`,realtime:{connection:`failed`,listening:!1,speaking:!1,muted:!1,error:t}}))}}controlGlobal(e){U.host.liveControl({body:{action:e}}).then(e=>{if(!e.ok)throw Error(e.error)}).catch(e=>{let t=B.store.state;(t===void 0||t.sessionId===null)&&B.update(()=>({sessionId:null,phase:`conflict`,realtime:{connection:`failed`,listening:!1,speaking:!1,muted:!1,error:e instanceof Error?e.message:String(e)}}))})}select(e){let t=Qe.store.state,n=z.store.state;this.releaseAudioPending||=(this.ownedSessionId!==null||this.handoffActive)&&n===null&&t===void 0,this.ownedSessionId=n,this.handoffActive=t!==void 0;let r=++this.selectionGeneration;e??=(t?.phase===`rebinding`?t.targetSessionId:void 0)??t?.sourceSessionId??null,e!==this.boundSessionId&&t===void 0&&this.client?.endRealtime();let i=async()=>{this.closed||r!==this.selectionGeneration||(this.releaseAudioPending&&=(await this.detach(),await this.device.close(),!1),!(this.closed||r!==this.selectionGeneration)&&(e===null?await this.detach():await this.attach(e,r)))};this.operation=this.operation.then(i,i).then(()=>void 0,()=>void 0)}async attach(e,t,n=!1,r){if(this.client!==void 0&&this.boundSessionId===e||(await this.detach(),this.closed||t!==this.selectionGeneration))return;let i;i=new on(this.clientId,`connection-${crypto.randomUUID()}`,new Br(e,n,r),this.device,(t,n)=>{this.client===i&&this.boundSessionId===e&&(t===`disconnected`?B.store.state?.sessionId===e&&B.reset():(B.update(n=>n?.sessionId===null&&n.realtime!==void 0&&n.realtime.connection!==`failed`?n:n?.sessionId===e?{...n,phase:t}:{sessionId:e,phase:t}),t===`conflict`?this.reportOwnership(e,n,r):t===`connected`&&B.update(t=>t?.sessionId===e?{...t,ownership:void 0,ownershipConflict:void 0,actions:void 0}:t)))},t=>{if(this.client!==i||this.boundSessionId!==e)return;let n=B.store.state;n?.sessionId===e&&B.update(()=>({...n,...t===void 0?{}:{realtime:t},...t===void 0?{realtime:void 0,realtimeOutputInterrupted:void 0}:{}}))},e=>new It(e,gn)),this.client=i,this.boundSessionId=e,V.store.state?.sessionId!==null&&V.update(()=>({sessionId:e,mute:e=>i.muteRealtime(e),interrupt:()=>{i.interruptRealtime();let t=B.store.state;t?.sessionId===e&&B.update(()=>({...t,realtimeOutputInterrupted:!0}))},end:()=>i.endRealtime()})),i.start()}reportOwnership(e,t,n){let r=t instanceof Error&&`conflict`in t?t.conflict:void 0;if(r?.code!==`VOICE_OWNERSHIP_CONFLICT`)return;let i=De({header:M()}),a=i.status===`ok`&&i.metadata.deviceId===r.owner.deviceId;B.update(t=>({...t?.sessionId===e?t:{sessionId:e,phase:`conflict`},ownership:{kind:n===void 0?a?`standby`:`conflict`:`stale`,ownerName:r.owner.deviceName,deviceName:i.status===`ok`?i.metadata.deviceName:void 0},ownershipConflict:r,actions:{takeOver:()=>{this.retryOwnership(e,r.owner.generation)},retry:()=>{this.retryOwnership(e)}}}))}async retryOwnership(e,t){try{if(e===null){let e=this.globalClient;this.globalClient=void 0,await e?.stop(!1),this.startGlobalClient(!0,t)}else await this.prepareSessionActivation(e,t)}catch(n){this.reportOwnership(e,n,t)}}async detach(){let e=this.client,t=this.boundSessionId;this.client=void 0,this.boundSessionId=void 0,t!==void 0&&B.store.state?.sessionId===t&&B.reset(),t!==void 0&&V.store.state?.sessionId===t&&V.reset(),await e?.stop(!1)}};function Hr(e){let t=$e.store.state;return t===void 0&&(t=new Vr,$e.update(()=>t)),e.mount?.scope===`session`&&t.focus(e.mount.sessionId),e.openSession&&(t.openSession=t=>e.openSession?.(t)),()=>void 0}var Ur=s(Hr),Wr={id:`voice`,label:`voice`,detail:`Speak requests and hear Po narrate its work. Available voice features depend on the session host.`,order:60,groups:[{id:`start`,label:`New sessions start with`,detail:`Press v e in a session to start voice.`},{id:`live`,label:`Live conversation`,detail:`Live handles the talking. Po still does the work in your session.`,signInProvider:`po-chatgpt`},{id:`daily`,label:`Daily work`,detail:`Listens with the session host’s transcriber. Dictation from the composer uses the same transcriber.`},{id:`narration`,label:`Narration`,detail:`How daily work corrects what it heard and speaks back.`}],fields:[{id:`mode`,localOnly:!0,label:`New sessions start with`,kind:`select`,keyPath:[`voice`,`mode`],group:`start`,presentation:`cards`,defaultValue:`legacy`,options:[{value:`live`,label:`Live conversation`,detail:`Experimental. Back-and-forth talk that answers as you speak. Best for thinking out loud with Po.`},{value:`legacy`,label:`Daily work`,detail:`Say a request, Po transcribes it and narrates as it works. Best while Po is busy.`}]},{id:`live-voice`,localOnly:!0,label:`Voice`,kind:`select`,keyPath:[`voice`,`live`,`voice`],group:`live`,placeholder:`Default (cove)`,options:[`juniper`,`maple`,`spruce`,`ember`,`vale`,`breeze`,`arbor`,`sol`,`cove`,`aube`,`bubbie`,`haetsal`,`hanul`,`himari`,`leher`,`miko`,`neer`,`porto`,`rindo`,`rio`,`rivage`,`selva`,`sonna`,`tinta`,`viola`].map(e=>({value:e,label:e}))},{id:`live-model`,localOnly:!0,label:`Model`,kind:`text`,keyPath:[`voice`,`live`,`model`],group:`live`,placeholder:`gpt-live-1-codex`},{id:`engine`,localOnly:!0,label:`Transcriber`,kind:`select`,keyPath:[`voice`,`engine`],group:`daily`,detail:`Auto uses the first one it finds.`,options:[`auto`,`whisper-cpp`,`openai-whisper`,`mlx-whisper`].map(e=>({value:e,label:e}))},{id:`language`,label:`Language`,kind:`text`,keyPath:[`voice`,`language`],group:`daily`,placeholder:`en`},...[`whisper-cpp`,`openai-whisper`,`mlx-whisper`].flatMap(e=>[{id:`${e}-binary`,localOnly:!0,label:`${e} executable`,kind:`text`,keyPath:[`voice`,`adapters`,e,`binary`],group:`daily`},{id:`${e}-model`,localOnly:!0,label:`${e} model`,kind:`text`,keyPath:[`voice`,`adapters`,e,`model`,e===`whisper-cpp`?`path`:`id`],group:`daily`}]),{id:`correction-model`,label:`Correction and narration model`,kind:`select`,optionsFrom:`models`,keyPath:[`voice`,`autoCapture`,`model`],group:`narration`},{id:`endpoint`,label:`Silence before sending (ms)`,kind:`number`,keyPath:[`voice`,`autoCapture`,`utteranceIdleMs`],group:`daily`},{id:`transcription-timeout`,label:`Transcription timeout (ms)`,kind:`number`,keyPath:[`voice`,`autoCapture`,`transcriptionTimeoutMs`],group:`daily`},{id:`narration-engine`,localOnly:!0,label:`Narration engine`,kind:`select`,keyPath:[`voice`,`autoCapture`,`tts`,`engine`],group:`narration`,options:[{value:`macos-say`,label:`macOS say`}]},{id:`narration-voice`,localOnly:!0,label:`Narration voice`,kind:`text`,keyPath:[`voice`,`autoCapture`,`tts`,`voice`],group:`narration`},{id:`narration-rate`,localOnly:!0,label:`Narration rate`,kind:`number`,keyPath:[`voice`,`autoCapture`,`tts`,`rate`],group:`narration`}]},Gr=S({...Wr,icon:ge}),Kr=S({...Wr,icon:ge}),qr=e({name:`voice`,keys:`v e`,statusKey:`po-voice`,activeSource:tt,hideWhenEmpty:!0,marksBackgroundWork:!1,placement:`bottom`,order:60}),Jr=p(rt),Yr=p(it),Xr=u({data:nt}),Zr=u({slot:`activity.voice`,id:`voice`,component:Ot}),Qr=1e3,$r=100,ei=1e4,ti=3e3,ni=.01,ri=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`],ii=class{startedAt;lastSpeechAt;get speechDetected(){return this.lastSpeechAt!==void 0}observe(e,t){this.startedAt??=t;let n=0;for(let t of e)n+=t*t;if((e.length===0?0:Math.sqrt(n/e.length))>=ni)return this.lastSpeechAt=t,!1;let r=this.lastSpeechAt??this.startedAt,i=this.speechDetected?ti:ei;return t-r>=i}};function ai(e,t){let n=globalThis.AudioContext;if(n===void 0)return()=>void 0;let r,i,a;try{r=new n,i=r.createMediaStreamSource(e);let o=r.createAnalyser();o.fftSize=2048,o.smoothingTimeConstant=.2,i.connect(o);let s=new Float32Array(o.fftSize),c=new ii;a=setInterval(()=>{o.getFloatTimeDomainData(s),c.observe(s,Date.now())&&t(c.speechDetected)},$r),r.resume().catch(()=>void 0)}catch{return i?.disconnect(),r?.close().catch(()=>void 0),()=>void 0}return()=>{a!==void 0&&clearInterval(a),i?.disconnect(),r?.close().catch(()=>void 0)}}function oi(){let e=globalThis,t=e.MediaRecorder,n=e.navigator?.mediaDevices;if(t===void 0||n===void 0)throw Error(`This browser cannot record microphone audio.`);return{getUserMedia:async()=>await n.getUserMedia(L),createRecorder:(e,n)=>new t(e,n),isTypeSupported:e=>t.isTypeSupported(e),setTimer:(e,t)=>setTimeout(e,t),clearTimer:e=>clearTimeout(e),now:()=>Date.now(),watchSilence:ai}}async function si(e){e??=oi();let t=ri.find(t=>e.isTypeSupported(t)),n=await e.getUserMedia(),r;try{r=e.createRecorder(n,t===void 0?void 0:{mimeType:t})}catch(e){for(let e of n.getTracks())e.stop();throw e}let i=[],a=0,o,s=!1,c=!1,l=!1,u=0,d=()=>void 0,f=()=>void 0,p=()=>void 0,m=new Promise((e,t)=>{f=e,p=t}),h=()=>{e.clearTimer(y),d(),r.ondataavailable=null,r.onerror=null,r.onstop=null;for(let e of n.getTracks())e.onended=null,e.stop()},g=(t,n)=>{s||(s=!0,h(),n===void 0?f(c||t===void 0?void 0:{audio:t,durationMs:Math.min(ct,Math.max(0,Math.round(e.now()-u)))}):p(n))},_=()=>{let e=r.mimeType||i.find(e=>e.type.length>0)?.type||``;return new Blob(i,{type:e})},v=()=>{if(!(s||l)&&r.state!==`inactive`){l=!0;try{r.stop()}catch(e){g(void 0,e instanceof Error?e:Error(`Browser audio recording failed.`))}}},y=e.setTimer(v,ct);for(let e of n.getTracks())e.onended=()=>g(void 0,Error(`The selected microphone was disconnected.`));r.ondataavailable=e=>{if(s||c||o!==void 0||e.data.size===0)return;let t=a+e.data.size;t>4194304?(o=Error(`The recording exceeds the 4 MiB transcription limit.`),v()):(a=t,i.push(e.data))},r.onerror=e=>g(void 0,o??e.error??Error(`Browser audio recording failed.`)),r.onstop=()=>g(o===void 0?_():void 0,o);try{u=e.now(),r.start(Qr);let t=e.watchSilence?.(n,e=>{e||(c=!0),v()});t!==void 0&&(d=t,s&&d())}catch(e){g(void 0,e instanceof Error?e:Error(`Browser audio recording failed.`)),await m}return{result:m,stop:v,cancel:()=>{c=!0,v()}}}function ci(e){if(typeof e!=`object`||!e||!(`transcript`in e))return;let t=e.transcript;return typeof t==`string`?t:void 0}async function li(e,t,n,r){if(e.size===0)throw Error(`The recording is empty.`);if(e.size>4194304)throw Error(`The recording exceeds the 4 MiB transcription limit.`);if(!Number.isSafeInteger(n)||n<0||n>3e5)throw Error(`The recording duration is invalid.`);let i=await W.session(t).manualTranscribe({headers:{"content-type":e.type,[st]:String(n)},body:e,...r===void 0?{}:{signal:r}}),a=ci(i.data);if(!i.ok)throw Error(i.error===``?`Voice transcription failed with status ${String(i.status)}.`:i.error);if(a===void 0)throw Error(`Voice transcription returned an invalid response.`);return a}var ui={start:si,transcribe:async(e,t,n,r)=>await li(e,t,n,r)},di=class{append;changed;dependencies;state={phase:`idle`};recording;transcription;generation=0;constructor(e,t,n=ui){this.append=e,this.changed=t,this.dependencies=n}snapshot(){return this.state}setAppend(e){this.append=e}reset(){this.invalidate(),this.publish({phase:`idle`})}dispose(){this.invalidate(),this.state={phase:`idle`}}async toggle(e){if(e===null||this.state.phase===`starting`||this.state.phase===`transcribing`)return;if(this.state.phase===`recording`){this.publish({phase:`transcribing`}),this.recording?.stop();return}let t=this.append,n=++this.generation;this.publish({phase:`starting`});try{let r=await this.dependencies.start();if(this.generation!==n){r.cancel();return}this.recording=r,this.publish({phase:`recording`}),this.finish(r,n,e,t)}catch(e){if(this.generation!==n)return;this.publish({phase:`idle`,error:e instanceof Error?e.message:`Voice recording failed.`})}}async finish(e,t,n,r){let i;try{let a=await e.result;if(this.generation!==t)return;if(a===void 0){this.recording=void 0,this.publish({phase:`idle`});return}this.recording===e&&(this.recording=void 0),this.publish({phase:`transcribing`}),i=new AbortController,this.transcription=i;let o=await this.dependencies.transcribe(a.audio,n,a.durationMs,i.signal);if(this.generation!==t)return;r(o),this.publish({phase:`idle`})}catch(n){if(this.generation!==t)return;this.recording===e&&(this.recording=void 0),this.publish({phase:`idle`,error:n instanceof Error?n.message:`Voice recording failed.`})}finally{i!==void 0&&this.transcription===i&&(this.transcription=void 0)}}invalidate(){this.generation+=1,this.recording?.cancel(),this.recording=void 0,this.transcription?.abort(),this.transcription=void 0}publish(e){this.state=e,this.changed()}},fi=`manual voice is unavailable while autonomous voice is active`;function pi({error:e,onDismiss:t,children:n}){return k(a,{open:e!==void 0,onOpenChange:e=>{e||t()},children:[P(E,{asChild:!0,children:n}),k(te,{side:`top`,align:`end`,sideOffset:8,collisionPadding:12,role:`alert`,"data-testid":`composer-voice-error`,onOpenAutoFocus:e=>e.preventDefault(),className:`w-64 flex-row items-start gap-2 border-po-edge-red bg-po-tint-red p-2.5 text-sm leading-relaxed text-po-red`,children:[P(re,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0`}),P(`span`,{className:`min-w-0 flex-1 break-words`,children:e}),P(w,{"aria-label":`dismiss`,className:`shrink-0 rounded-sm p-0.5 hover:bg-po-tint-red`,children:P(l,{"aria-hidden":!0,className:`size-3.5`})})]})]})}function mi({sessionId:e,appendComposerDraft:t,statuses:n,registeredModes:r}){let i=O(z.store,e=>e),a=O(B.store),o=yt(n[`po-voice`]),[s,c]=D({phase:`idle`}),l=oe(void 0);l.current??=new di(t,()=>{c(l.current?.snapshot()??{phase:`idle`})});let u=s.phase,d=s.error,f=a?.sessionId===null&&a.realtime!==void 0&&a.realtime.connection!==`closed`,p=o.mode===`auto`||o.mode===`live`||i!==null||f;ae(()=>{let e=l.current;return()=>e?.dispose()},[]),ae(()=>{l.current?.setAppend(t)},[t]),ae(()=>{l.current?.reset()},[e,p]);let m=()=>{p||l.current?.toggle(e)},h=!p&&u===`recording`,g=p?fi:d??(h?`stop voice recording and fill the prompt`:u===`transcribing`?`transcribing voice recording`:u===`starting`?`starting voice recording`:`start voice recording`),_=p?`blocked`:u,v=d&&!p?`text-po-red`:`text-po-dim`;return r?.includes(`voice-auto`)?P(pi,{error:p?void 0:d,onDismiss:()=>l.current?.reset(),children:P(N,{variant:h?`danger-outline`:`ghost`,size:`icon-md`,"data-testid":`composer-voice-action`,"data-voice-mode":p?`auto`:h?`manual`:`off`,"data-voice-phase":_,"aria-label":g,title:g,disabled:e===null||p||u===`starting`||u===`transcribing`,onClick:m,className:`shrink-0 ${v}`,children:h?P(b,{className:`size-3 fill-current`}):u===`starting`||u===`transcribing`?P(ce,{className:`size-4 animate-spin`}):P(d&&!p?re:ge,{className:`size-4`})})}):null}var hi=u({slot:`composer-actions`,id:`voice`,component:mi});function gi(e){let t=t=>e[t]?.label||`Microphone`;return e.map((n,r)=>e.some((e,n)=>n!==r&&t(n)===t(r))?`${t(r)} · ${n.deviceId.slice(0,6)}`:t(r))}function _i(){let{inputs:e,choice:t}=O(q.store,e=>e),[n,r]=D(0);if(t===void 0)return null;let i=gi(e),a=n<i.length?n:0,s=n=>{let r=e[i.indexOf(n)];r!==void 0&&t(r.deviceId,!0)};return P(fe,{open:!0,onOpenChange:e=>{e||t(null,!1)},children:k(ee,{width:`sm`,"data-testid":`voice-microphone-dialog`,"aria-describedby":void 0,onKeyDown:e=>he(e,{options:i,cursor:a,onCursorChange:r,onSelect:s}),children:[P(g,{children:P(A,{children:`choose a microphone`})}),k(o,{children:[P(T,{children:`autonomous voice found more than one input. this browser remembers the one you pick.`}),P(x,{options:i,cursor:a,onCursorChange:r,onSelect:s,testIdPrefix:`voice-microphone-option`}),k(ne,{className:`flex-col items-stretch`,children:[k(`span`,{className:`w-full text-sm text-po-dim`,children:[f(i.length),` · esc uses the browser default once`]}),P(N,{variant:`outline`,size:`md`,"data-testid":`voice-microphone-default`,onClick:()=>t(null,!0),children:`always use browser default`})]})]})]})})}var vi=u({slot:`overlay`,id:`voice`,component:_i}),yi=h({id:`voice.toggle`,path:[{key:`v`,label:`voice`,detail:`autonomous voice capture`},{key:`e`,label:`toggle`,detail:`start or stop autonomous capture`}],command:`mode voice-auto`}),bi=s(Hr),xi=r({name:`voice`,modeId:`voice-auto`,keys:`v e`,icon:ge,statusKey:`po-voice`,order:60}),Si=`describe_voice_tools`,Ci=`use_voice_tools`,wi=`narrate`,Ti=`transfer_voice`,Ei=6,Di=8,Oi=72,ki={tone:`error`,glyph:`✗`,label:`failed`},Ai={playing:{tone:`warning`,glyph:`◐`,label:`playing`},completed:{tone:`success`,glyph:`✓`,label:`completed`},interrupted:{tone:`warning`,glyph:`⊘`,label:`interrupted`},superseded:{tone:`dim`,glyph:`○`,label:`superseded`},failed:ki,rejected:{tone:`error`,glyph:`✗`,label:`rejected`},cancelled:{tone:`warning`,glyph:`⊘`,label:`cancelled`},stopped:{tone:`warning`,glyph:`■`,label:`stopped`},not_executed:{tone:`dim`,glyph:`○`,label:`not executed`},preflight_failed:{tone:`error`,glyph:`✗`,label:`preflight failed`}};function X(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function ji(e){return e!==void 0}function Mi(e){let t=``;for(let n of e){let e=n.codePointAt(0)??0;t+=e<=31||e===127?` `:n}return t.replace(/\s+/gu,` `).trim()}function Z(e,t){let n=e?.[t];return typeof n==`string`&&Mi(n)||void 0}function Ni(e,t){let n=e?.[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function Pi(e){return e?e.content.flatMap(e=>{let t=X(e);return t?.type===`text`&&typeof t.text==`string`?[t.text]:[]}):[]}function Fi(e){if(e)try{return X(JSON.parse(e))}catch{return}}function Ii(e){return X(e?.details)??Fi(Pi(e)[0])}function Li(e,t,n=`${t}s`){return e===1?t:n}function Q(e,t,n={}){return{text:e,tone:t,...n}}function Ri(e){let t=e.names;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function zi(e){let t=e.calls;return Array.isArray(t)?t.map(X).filter(ji):[]}function Bi(e,t){if(e===`narrate`){let e=typeof t.text==`string`?Mi(t.text):``,n=e.length>Oi?`${e.slice(0,69)}…`:e;return{action:`narrate`,...n?{detail:n}:{},detailIsName:!1}}if(e===`transfer_voice`){let e=Ni(t,`target`);return{glyph:`↪`,action:`hand off`,...e===void 0?{}:{detail:`target ${e}`},detailIsName:!1}}if(e===`describe_voice_tools`){let e=Ri(t);return e.length===1?{glyph:`☰`,action:`discover`,detail:e[0],detailIsName:!0}:e.length>1?{glyph:`☰`,action:`discover`,detail:`· ${e.length} capabilities`,detailIsName:!1}:{glyph:`☰`,action:`discover`,detailIsName:!1}}let n=zi(t);if(n.length===1){let e=Z(n[0],`name`);return{glyph:`▶`,action:`run`,...e?{detail:e}:{},detailIsName:e!==void 0}}return n.length>1?{glyph:`▶`,action:`run`,detail:`· ${n.length} capabilities`,detailIsName:!1}:{glyph:`▶`,action:`run`,detailIsName:!1}}function Vi(e){let t=e.enum;if(Array.isArray(t)){let e=t.filter(e=>[`string`,`number`,`boolean`].includes(typeof e));if(e.length>0)return e.join(` | `)}let n=e.const;if([`string`,`number`,`boolean`].includes(typeof n))return String(n);let r=e.type;if(typeof r==`string`)return r;if(Array.isArray(r))return r.filter(e=>typeof e==`string`).join(` | `);if(Array.isArray(e.anyOf)){let t=e.anyOf.map(X).filter(ji).map(Vi).filter(Boolean);if(t.length>0)return t.join(` | `)}return`value`}function Hi(e){let t=X(e),n=X(t?.properties);if(!t||!n)return;let r=new Set(Array.isArray(t.required)?t.required.filter(e=>typeof e==`string`):[]),i=Object.entries(n).map(([e,t])=>{let n=X(t),i=n?Vi(n):`value`;return`${e}${r.has(e)?``:`?`}: ${i}`});return i.length>0?i.join(`, `):`{}`}function Ui(e,t){let n=e.enabled===!0,r=Z(e,`name`)??`capability`,i=Z(e,`label`)??r,a=[Q(`${n?`●`:`○`} ${i} · ${r}${n?``:` · disabled`}`,n?`text`:`dim`)];if(!t)return a;let o=Z(e,`description`),s=Hi(e.inputSchema);return o&&a.push(Q(o,`muted`,{indent:!0})),s&&a.push(Q(`input ${s}`,`dim`,{indent:!0})),a}function Wi(e,t){let n=Array.isArray(e.tools)?e.tools.map(X).filter(ji):[],r=Array.isArray(e.conflicts)?e.conflicts.map(X).filter(ji):[],i=Array.isArray(e.unknownNames)?e.unknownNames.filter(e=>typeof e==`string`):[],a=Ni(e,`catalogRevision`),o=`${n.length} voice ${Li(n.length,`capability`,`capabilities`)}${a===void 0?``:` · catalog rev ${a}`}`,s=t?n:n.slice(0,Ei),c=[Q(o,`muted`),...s.flatMap(e=>Ui(e,t))],l=n.length-s.length;l>0&&c.push(Q(`… ${l} more`,`dim`)),n.length===0&&c.push(Q(`No voice capabilities are currently registered.`,`dim`));for(let e of r){let t=Z(e,`name`)??`capability`,n=Z(e,`message`)??`Conflicting registrations.`;c.push(Q(`! ${t} · ${n}`,`warning`))}return i.length>0&&c.push(Q(`? Unknown: ${i.join(`, `)}`,`warning`)),c}function Gi(e){if(typeof e==`string`)return Mi(e);if(typeof e==`number`&&Number.isFinite(e)||typeof e==`boolean`)return String(e);if(e===null)return`null`;if(Array.isArray(e)){let t=e.map(Gi);return t.every(e=>e!==void 0)?t.join(`, `)||`none`:void 0}}function Ki(e){let t=Gi(e);if(t!==void 0)return[Q(t,`text`,{indent:!0})];let n=X(e);return n?Object.entries(n).flatMap(([e,t])=>{let n=Gi(t);return n===void 0?[]:[Q(`${e} ${n}`,`text`,{indent:!0})]}):[]}function qi(e){return Z(X(e.error),`message`)}function Ji(e,t){let n=Z(e,`name`)??`capability`,r=Z(e,`status`)??`failed`,i=Ai[r]??ki,a=qi(e),o=[Q(`${i.glyph} ${n} · ${i.label}${a?` · ${a}`:``}`,i.tone)];return r===`completed`&&(t||e.result!==void 0)&&o.push(...Ki(e.result)),o}function Yi(e,t){let n=Array.isArray(e.results)?e.results.map(X).filter(ji):[],r=Array.isArray(e.errors)?e.errors.map(X).filter(ji):[],i=Ai[Z(e,`status`)??`failed`]??ki,a=`${i.glyph} Voice batch ${i.label} · ${n.length} ${Li(n.length,`call`)}`,o=t?n:n.slice(0,Di),s=[Q(a,i.tone,{bold:!0}),...o.flatMap(e=>Ji(e,t))],c=n.length-o.length;c>0&&s.push(Q(`… ${c} more`,`dim`));for(let e of r){let t=Z(e,`message`);t&&!n.some(e=>qi(e)===t)&&s.push(Q(`✗ ${t}`,`error`))}return s}function Xi(e){let t=X(e.error);if(t)return[Q(`✗ ${Z(t,`message`)??`Voice capability failed.`}${t.retryable===!0?` · retryable`:``}`,`error`)]}function Zi(e,t){let n=Mi(Pi(e)[0]??(t.isPartial?`running`:`No result details.`)),r=t.isPartial?`◐`:t.isError?`✗`:`✓`,i=t.isPartial?`warning`:t.isError?`error`:`muted`;return[Q(`${r} ${n}`,i)]}function Qi(e,t){let n=Ii(e),r=n?Xi(n):void 0;if(r)return r;let i=Z(n,`outcome`)??(t.isPartial?`playing`:void 0);if(!i)return Zi(e,t);let a=Ai[i]??ki;return[Q(`${a.glyph} Narration ${a.label}`,a.tone)]}function $i(e){let t=Z(e,`state`),n=Z(e,`mode`);if(!t||!n||typeof e.muted!=`boolean`)return;let r=Z(e,`manual`),i=Z(e,`error`);return{state:t,phase:t===`active`?`active`:t===`starting`||t===`stopping`?`pending`:`idle`,mode:n,muted:e.muted,...r?{manual:r}:{},...i?{error:i}:{}}}function ea(e){return Object.entries(e).flatMap(([e,t])=>{let n=Gi(t);if(n!==void 0)return[{key:e,value:n||`empty`}];if(Array.isArray(t))return[{key:e,value:`${t.length} ${Li(t.length,`item`)}`}];let r=X(t);if(!r)return[];let i=Object.keys(r).length;return[{key:e,value:`${i} ${Li(i,`field`)}`}]})}function ta(e,t,n){let r=e===`narrate`?void 0:Ii(t);if(!(!r||X(r.error)!==void 0||e===`describe_voice_tools`&&Array.isArray(r.tools)||e===`use_voice_tools`&&Array.isArray(r.results))){let e=$i(r);return e?{kind:`status`,status:e}:{kind:`fields`,fields:ea(r)}}return{kind:`lines`,lines:ia(e,t,n)}}function na(e){return typeof e.text==`string`?e.text.normalize(`NFKC`).replace(/\s+/gu,` `).trim():``}function ra(e){return Z(X(Ii(e)?.error),`message`)||Mi(Pi(e)[0]??``)}function ia(e,t,n){if(e===`narrate`)return Qi(t,n);let r=Ii(t);return(r?Xi(r):void 0)||(e===`describe_voice_tools`&&r&&Array.isArray(r.tools)?Wi(r,n.expanded):e===`use_voice_tools`&&r&&Array.isArray(r.results)?Yi(r,n.expanded):Zi(t,n))}function aa({toolName:e,args:r,result:a,running:o,isError:s}){if(e===`narrate`){let e=na(r);return k(`div`,{role:`group`,"aria-label":`narration`,"data-testid":`narration-message`,"data-narration-state":o?`playing`:s?`failed`:`complete`,className:`flex min-w-0 items-start gap-2 text-base text-po-text`,children:[P(ie,{"aria-hidden":`true`,className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-po-magenta`}),P(`p`,{className:`min-w-0 flex-1 whitespace-pre-wrap break-words`,children:e||`Narration unavailable.`})]})}let l=Bi(e,r),u=ia(e,a,{expanded:!1,isError:s,isPartial:o}),d=ia(e,a,{expanded:!0,isError:s,isPartial:o}),f=ta(e,a,{expanded:!1,isError:s,isPartial:o}),p=s?ra(a):``;return P(m,{tone:n({running:o,isError:s}),expandable:!s&&d.length>u.length,children:({expanded:n})=>k(de,{children:[P(i,{title:e,children:k(`span`,{"data-testid":`tool-call-${e}`,className:`flex min-w-0 flex-1 items-center gap-2`,children:[k(`span`,{className:`shrink-0 font-semibold text-po-hi`,children:[l.glyph,` `,l.action]}),l.detail?P(`span`,{className:`min-w-0 truncate ${l.detailIsName?`text-po-blue`:`text-po-dim`}`,children:l.detail}):null]})}),s?p.length>0?P(t,{"data-testid":`tool-result-${e}`,children:P(`p`,{className:`whitespace-pre-wrap break-words text-po-red`,children:p})}):null:P(t,{"data-testid":`tool-result-${e}`,children:o&&a===null?P(c,{tone:`running`,children:`running`}):f.kind===`status`?P(sa,{status:f.status}):f.kind===`fields`?P(ca,{fields:f.fields}):P(v,{lines:n?d:u})})]})})}var oa={active:`green`,pending:`yellow`,idle:`neutral`};function sa({status:e}){return k(`div`,{className:`flex flex-col gap-2`,children:[k(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[P(j,{tone:oa[e.phase],children:`voice ${e.state}`}),P(j,{tone:`blue`,children:`mode ${e.mode}`}),P(j,{tone:e.muted?`yellow`:`neutral`,children:e.muted?`mic muted`:`mic on`}),e.manual===void 0?null:P(j,{children:`dictation ${e.manual}`})]}),e.error===void 0?null:P(`p`,{className:`break-words text-po-red`,children:e.error})]})}function ca({fields:e}){return e.length===0?P(`p`,{className:`text-po-faint`,children:`No result details.`}):P(`dl`,{className:`grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)] gap-x-4 gap-y-0.5`,children:e.map(e=>k(`div`,{className:`contents`,children:[P(`dt`,{className:`truncate text-po-dim`,children:e.key}),P(`dd`,{className:`break-words text-po-text`,children:e.value})]},e.key))})}var la=C({tools:[wi],timelinePresentation:`message`,message:aa}),ua=C({tools:[Si,Ci,Ti],message:aa}),$=(e,t)=>t===void 0?void 0:{...e,...t},da=pe({id:`voice`,packageName:`@agimon-ai/po-voice`,host:{get fills(){return[$({slot:`activity`,id:`voice`},At)]},get settingsSections(){return[$({id:`voice`},Gr)]},get start(){return Ur}},workspace:{get settingsSections(){return[$({id:`voice`},Kr)]}},session:{get activityGroups(){return[$({name:`voice`},qr)]},get channels(){return[$({channel:`voice_media_wake`},Jr),$({channel:`voice_ownership`},Yr)]},get fills(){return[$({slot:`approval.voice-hint`,id:`approval-voice-hint`},Xr),$({slot:`activity.voice`,id:`voice`},Zr),$({slot:`composer-actions`,id:`voice`},hi),$({slot:`overlay`,id:`voice`},vi)]},get leaderBindings(){return[$({id:`voice.toggle`},yi)]},get modes(){return[$({name:`voice`},xi)]},get start(){return bi},get toolRenderers(){return[$({tools:[`narrate`]},la),$({tools:[`voice`]},ua)]}}});export{da as webPlugin};
@@ -1,16 +0,0 @@
1
- import{$ as e,Ar as t,B as n,C as r,Er as i,F as a,Fn as o,H as s,Ht as c,I as l,J as u,Jn as d,L as f,Ln as p,Lt as m,M as h,Mr as g,Or as _,P as v,Pr as ee,Pt as te,Q as ne,Qn as re,Qr as ie,R as y,Rr as ae,S as oe,Tr as se,U as ce,Wr as le,Wt as ue,Yn as de,Z as fe,Zn as pe,_ as b,_r as me,a as x,c as S,cr as he,ct as ge,dr as C,er as _e,et as ve,f as w,g as ye,gt as T,h as be,in as E,ir as xe,j as Se,jn as Ce,jt as we,kn as Te,kr as Ee,ln as De,lr as Oe,lt as ke,n as Ae,nn as je,nr as D,o as O,or as k,p as Me,pn as A,qn as Ne,qr as Pe,rr as Fe,s as j,sr as Ie,st as Le,u as Re,w as ze,zr as Be}from"../chunks/po-web-runtime-DZvTbTGl.js";var Ve=`diagnose step`,He=`workflow_runs`,Ue=`workflow_catalog`;function We(e,t){if(t===null)return;let n;for(let r of e)for(let e of r.jobs){let i=e.steps.find(e=>e.ref?.kind===`session`&&e.ref.id===t);i!==void 0&&(n===void 0||Date.parse(r.startedAt)>Date.parse(n.run.startedAt))&&(n={run:r,job:e.name,jobLabel:Ge(r,e.name),step:i.name})}return n}function Ge(e,t){for(let{invocations:n}of e.children??[])for(let e of n)if(`${e.job}:${e.invocationId}`===t)return e.job;return t}var Ke=6e4,qe=60*Ke;function Je(e){if(e<Ke)return`<1m`;if(e<qe)return`${Math.floor(e/Ke)}m`;let t=Math.floor(e/qe),n=Math.floor(e%qe/Ke);return`${t}h ${String(n).padStart(2,`0`)}m`}var Ye=new Set([`paused`,`pause_requested`]);function M(e){return`${e.workspace}/${e.routeKey??e.runKey}`}function Xe(e,t){return t!==null&&(e.ownerSessionId??t)===t}function Ze(e){return e.stage===`running`?e.executionState!==void 0&&Ye.has(e.executionState)?`paused`:`running`:e.stage===`error`?`failed`:e.outcome!==void 0&&e.outcome!==`success`?e.outcome===`failed`?`failed`:`skipped`:`done`}function Qe(e,t){return t===`paused`?`paused; resume it from the owning session`:t===`failed`?e.errorMessage??(e.failedJob===void 0?`failed`:`job '${e.failedJob}' failed`):t===`running`?e.position===void 0?`starting`:e.position.step===void 0?e.position.job:`${e.position.job} · ${e.position.step}`:e.outcome??`done`}function $e(e,t){let n=Date.parse(e.startedAt);if(!Number.isFinite(n))return``;let r=e.finishedAt===void 0?t:Date.parse(e.finishedAt);return Je(Math.max(0,(Number.isFinite(r)?r:t)-n))}function et(e,t,n=null){return e.map(e=>{let r=Ze(e);return{identity:M(e),runKey:e.runKey,name:e.displayName,tone:r,elapsed:$e(e,t),startedAt:e.startedAt,finishedAt:e.finishedAt,detail:Qe(e,r),...e.ownerSessionId===void 0||e.ownerSessionId===n?{}:{ownerSessionId:e.ownerSessionId}}})}var tt={running:`running`,paused:`running`,failed:`failed`,done:`successful`,skipped:`successful`},nt=[`running`,`failed`,`successful`];function rt(e){return nt.map(t=>({name:t,rows:e.filter(e=>tt[e.tone]===t),openByDefault:t!==`successful`})).filter(e=>e.rows.length>0)}var N=Be({runs:[],parentRuns:[],focusedRun:void 0,pendingLaunch:void 0});function it(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function at(e,t){N.update(e,e=>({...e,focusedRun:t}))}function ot(e,t){N.update(e,e=>{let n=e.runs.filter(e=>M(e)!==t);return{...e,runs:n,focusedRun:e.focusedRun===t?n[0]===void 0?void 0:M(n[0]):e.focusedRun}})}function st(e,t,n,r){e(t,{type:`prompt`,message:n}),N.update(t,e=>({...e,pendingLaunch:{workflowPath:r,knownRuns:e.runs.map(M)}}))}var ct=N.channel({channel:He,parse(e){if(!it(e)||!Array.isArray(e.runs))return null;let t=Array.isArray(e.parentRuns)?e.parentRuns.filter(it):[];return{runs:e.runs.filter(it),parentRuns:t}},reduce:(e,{runs:t,parentRuns:n=[]})=>{let r={...e,parentRuns:n},i=r.pendingLaunch;if(i===void 0)return{...r,runs:t};let a=new Set(i.knownRuns),o=t.find(e=>!a.has(M(e)));return o===void 0?{...r,runs:t}:{...r,runs:t,focusedRun:M(o),pendingLaunch:void 0}}}),P=`/runs/:workspace/:runKey`,lt=`:name{.+}`,ut=`step`,dt=`download`,ft=se({snapshot:{method:`GET`,path:`${P}/screen`,query:[ut],response:void 0},screen:{method:`GET`,path:`${P}/screen/stream`,query:[ut],stream:!0},control:{method:`POST`,path:`${P}/control`,response:void 0},keys:{method:`POST`,path:`${P}/keys`},resize:{method:`POST`,path:`${P}/resize`,response:void 0},remove:{method:`DELETE`,path:P,response:void 0},stop:{method:`POST`,path:`${P}/stop`,response:void 0},steer:{method:`POST`,path:`${P}/steer`,response:void 0},launch:{method:`POST`,path:`/launch`,response:void 0},openRunDirectory:{method:`POST`,path:`${P}/open-directory`,response:void 0},artifacts:{method:`GET`,path:`${P}/artifacts`,query:[`directory`],response:void 0},stepRuns:{method:`GET`,path:`/step-runs/:sessionId`,response:void 0},artifact:{method:`GET`,path:`${P}/artifacts/${lt}`,query:[`raw`,dt],response:void 0}},{scopes:[`host`,`workspace`,`session`],basePath:`workflow`,transport:(e,t)=>Ae.fetch(e,t),sessionAddress:ie}),pt=`screen`,mt=`The cockpit hub is unreachable.`;function F(e){return e==null?ft.host:ft.session(e)}function I(e,t){return{workspace:e,runKey:t}}function ht(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function gt(e,t){return e.status===0?mt:e.error===void 0||e.error===``?t:e.error}function _t(e,t,n,r,i){return e.artifact.url({params:I(t,n),...i===void 0?{}:{query:i}}).replace(lt,r.split(`/`).map(encodeURIComponent).join(`/`))}function vt(e){return e===void 0?{}:{step:e}}function yt(e,t,n,r,i,a){let o=new EventSource(F(r).screen.url({params:I(e,t),...i===void 0?{}:{query:{[ut]:i}}})),s=()=>{o.removeEventListener(pt,c),o.removeEventListener(`error`,l),o.close()},c=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(!ht(t)||!Array.isArray(t.lines))return;let r=t;n(r),r.ended===!0&&s()},l=()=>{o.readyState===EventSource.CLOSED&&(s(),a?.(`The run's screen could not be opened. Close this tab and open it again to retry.`))};return o.addEventListener(pt,c),o.addEventListener(`error`,l),s}async function bt(e,t,n,r,i){let a=await F(r).control({params:I(e,t),body:{token:n,...vt(i)}});return a.status===0?{held:!1,reason:mt}:ht(a.data)&&typeof a.data.held==`boolean`?a.data:{held:!1,reason:gt(a,`The run refused the keyboard.`)}}async function xt(e,t,n,r,i){await F(r).control({params:I(e,t),body:{token:n,release:!0,...vt(i)}})}async function St(e,t,n,r,i,a){let o=await F(i).keys({params:I(e,t),body:{token:n,data:r,...vt(a)}});return o.ok?{}:{error:gt(o,`The run would not take those keys.`)}}async function Ct(e,t,n){let r=await F(n).remove({params:I(e,t)});return r.ok?r.data.deleted===!0?{result:{deleted:!0}}:{error:`The workflow hub returned an invalid deletion response.`}:{error:gt(r,`The workflow could not be deleted.`)}}async function wt(e,t,n){let r=await F(n).stop({params:I(e,t)});return r.ok?r.data.requested===!0?{result:{requested:!0}}:{error:`The workflow hub returned an invalid stop response.`}:{error:gt(r,`The workflow could not be stopped.`)}}async function Tt(e,t,n){let r=await F(n).openRunDirectory({params:I(e,t)});return r.ok?r.data.opened===!0?{}:{error:`The workflow hub returned an invalid folder response.`}:{error:gt(r,`The run folder could not be opened in Finder.`)}}async function Et(e){let t=await ft.host.stepRuns({params:{sessionId:e}});return t.ok?t.data.runs:void 0}async function Dt(e,t,n,r,i){let a=await F(n).artifacts({params:I(e,t),query:{directory:r},signal:i});return a.ok?{artifacts:a.data}:{error:gt(a,`This run has no directory to read.`)}}function Ot(e,t,n,r=!1,i){return _t(F(i),e,t,n,{raw:1,...r?{[dt]:1}:{}})}async function kt(e,t,n,r){try{let i=await Ae.fetch(_t(F(r),e,t,n)),a=await i.json();if(!i.ok){let e=ht(a)&&typeof a.error==`string`&&a.error!==``?a.error:``;return{error:e===``?`That file has not been written.`:e}}return{artifact:a}}catch{return{error:mt}}}var At=`workflows-artifact-`,jt=1024,Mt=[`B`,`KB`,`MB`];function Nt(e){if(e===void 0)return``;let t=e,n=0;for(;t>=jt&&n<Mt.length-1;)t/=jt,n+=1;return`${n===0?t:t.toFixed(1)} ${Mt[n]}`}function Pt(e){if(e===void 0)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``}var Ft={written:{glyph:`✓`,className:`text-po-green`},empty:{glyph:`○`,className:`text-po-yellow`},pending:{glyph:`○`,className:`text-po-faint`},unreadable:{glyph:`!`,className:`text-po-red`}};function It(e,t){let n=[],r=[],i=``,a=!1;for(let o=0;o<=e.length&&n.length<500;o+=1){let s=e[o]??`
2
- `;a?s===`"`&&e[o+1]===`"`?(i+=`"`,o+=1):s===`"`?a=!1:i+=s:s===`"`&&i===``?a=!0:s===t?(r.push(i),i=``):s===`
3
- `?(r.push(i.replace(/\r$/,``)),n.push(r),r=[],i=``):i+=s}return n}function Lt({text:e,delimiter:t}){let[n=[],...r]=It(e,t);return j(`div`,{className:`overflow-auto`,children:S(`table`,{"data-testid":`artifact-table`,className:`min-w-full border-collapse font-mono text-sm`,children:[j(`thead`,{className:`sticky top-0 bg-po-panel text-po-hi`,children:j(`tr`,{children:n.map((e,t)=>j(`th`,{className:`border border-po-border px-2 py-1.5 text-left font-semibold`,children:e},t))})}),j(`tbody`,{children:r.map((e,t)=>j(`tr`,{children:e.map((e,t)=>j(`td`,{className:`border border-po-border px-2 py-1 align-top text-po-text`,children:e},t))},t))})]})})}function Rt(e){if(e.mimeType!==void 0)return e.mimeType;let t=e.path.split(`.`).pop()?.toLowerCase();return t===`md`||t===`markdown`?`text/markdown`:t===`json`?`application/json`:t===`csv`?`text/csv`:t===`tsv`?`text/tab-separated-values`:t===`html`||t===`htm`?`text/html`:t===`pdf`?`application/pdf`:[`bmp`,`gif`,`ico`,`jpeg`,`jpg`,`png`,`svg`,`webp`].includes(t??``)?`image/unknown`:[`aac`,`m4a`,`mp3`,`oga`,`ogg`,`wav`].includes(t??``)?`audio/unknown`:[`mov`,`mp4`,`ogv`,`webm`].includes(t??``)?`video/unknown`:e.text===void 0?`application/octet-stream`:`text/plain`}function zt({content:e,rawUrl:t,raw:n}){let r=e.text??``,i=Rt(e);if(e.size===0)return j(C,{"data-testid":`artifact-empty`,title:`this artifact is empty`,description:`The workflow created the file but did not write any content.`});if(i===`text/markdown`)return n?j(`pre`,{"data-testid":`artifact-raw`,className:`whitespace-pre-wrap break-words font-mono text-sm leading-snug text-po-text`,children:r}):j(`div`,{"data-testid":`artifact-markdown`,className:`max-w-5xl text-base text-po-text`,children:j(Se,{text:r})});if(i===`application/json`){let e=r;try{e=JSON.stringify(JSON.parse(r),null,2)}catch{}return j(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-sm leading-snug text-po-text`,children:e})}return i===`text/csv`||i===`text/tab-separated-values`?j(Lt,{text:r,delimiter:i===`text/csv`?`,`:` `}):i===`text/html`?j(`iframe`,{"data-testid":`artifact-html`,title:e.path,sandbox:``,referrerPolicy:`no-referrer`,srcDoc:r,className:`min-h-[520px] w-full rounded bg-white`}):i.startsWith(`image/`)?j(`img`,{"data-testid":`artifact-image`,src:t,alt:e.path,className:`max-h-full max-w-full object-contain`}):i===`application/pdf`?j(`object`,{"data-testid":`artifact-pdf`,data:t,type:`application/pdf`,"aria-label":`PDF artifact`,className:`min-h-[600px] w-full`}):i.startsWith(`audio/`)?j(`audio`,{"data-testid":`artifact-audio`,src:t,controls:!0,preload:`metadata`,className:`w-full`,children:j(`track`,{kind:`captions`})}):i.startsWith(`video/`)?j(`video`,{"data-testid":`artifact-video`,src:t,controls:!0,preload:`metadata`,className:`max-h-full max-w-full`,children:j(`track`,{kind:`captions`})}):e.text===void 0?j(C,{title:`preview unavailable`,description:`Download this artifact to open it with a local application.`}):j(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-sm leading-snug text-po-text`,children:r})}function Bt(e,t,n){return{id:`${At}${e.workspace}-${e.routeKey??e.runKey}-${t}`.replace(/[^\w-]+/g,`-`),label:t.split(`/`).pop()??t,panel:r=>j(Vt,{...r,sessionId:n===void 0?r.sessionId:n,workspace:e.workspace,runKey:e.routeKey??e.runKey,path:t})}}function Vt({workspace:e,runKey:t,path:n,sessionId:r}){let[i,a]=b(),[o,s]=b(),[c,l]=b(0),[u,d]=b(!1);w(()=>{let i=!0;return kt(e,t,n,r).then(e=>{i&&(`error`in e?(s(e.error),a(void 0)):(s(void 0),a(e.artifact)))}),()=>{i=!1}},[e,t,n,c,r]);let f=Ot(e,t,n,!1,r),p=Ot(e,t,n,!0,r),m=i===void 0?void 0:Rt(i),h=m===`text/markdown`;return S(`div`,{"data-testid":`artifact-viewer`,className:`flex min-h-0 flex-1 flex-col px-[26px] py-[18px]`,children:[S(`div`,{className:`flex items-center gap-2.5 pb-3`,children:[j(`span`,{className:`truncate text-base font-semibold text-po-hi`,children:n}),j(T,{size:`xs`,children:m??`artifact`}),j(`span`,{className:`text-sm text-po-dim`,children:i===void 0?``:`${Nt(i.size)} · written ${Pt(i.modifiedAt)}`}),j(`span`,{className:`min-w-0 flex-1`}),h?S(`div`,{className:`flex items-center`,children:[j(E,{variant:u?`outline`:`primary`,size:`xs`,"data-testid":`artifact-rendered-toggle`,onClick:()=>d(!1),children:`rendered`}),j(E,{variant:u?`primary`:`outline`,size:`xs`,"data-testid":`artifact-raw-toggle`,onClick:()=>d(!0),children:`raw`})]}):null,j(E,{asChild:!0,variant:`ghost`,size:`xs`,children:j(`a`,{"data-testid":`artifact-download`,href:p,download:!0,children:`download`})}),j(E,{variant:`ghost`,size:`xs`,"data-testid":`artifact-reload`,onClick:()=>l(e=>e+1),children:`reload`})]}),j(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-md border border-po-border bg-po-deep p-4`,children:o===void 0?i===void 0?j(`span`,{className:`text-sm text-po-dim`,children:`loading preview`}):j(zt,{content:i,rawUrl:f,raw:u}):j(`span`,{"data-testid":`artifact-error`,className:`text-base text-po-yellow`,children:o})}),i?.truncated===!0?S(`span`,{className:`pt-2 text-sm text-po-dim`,children:[`this preview shows the first `,Nt(i.text?.length),`; download the artifact for the complete file`]}):null]})}function Ht({run:e,sessionId:t,onOpen:n}){let r=x(N.store,e=>N.select(e,t).runs),[i,a]=b(),[o,s]=b(),c=ye(void 0);return w(()=>{let n=new AbortController,r=!1,i=!1,o=async()=>{if(r)i=!0;else{r=!0;try{do{i=!1;let r=await Dt(e.workspace,e.routeKey??e.runKey,t,void 0,n.signal);if(n.signal.aborted)return;`error`in r?s(r.error):(s(void 0),a(r.artifacts))}while(i)}catch(e){n.signal.aborted||s(String(e))}finally{r=!1}}};return c.current=()=>{o()},()=>{c.current=void 0,n.abort()}},[e.workspace,e.runKey,e.routeKey,t]),w(()=>{c.current?.()},[e.workspace,e.runKey,e.routeKey,t,r]),j(Ut,{listing:i,error:o,onLoadDirectory:n=>Dt(e.workspace,e.routeKey??e.runKey,t,n),onOpen:n,onOpenDirectory:()=>Tt(e.workspace,e.routeKey??e.runKey,t)})}function Ut({listing:e,error:t,onOpen:n,onOpenDirectory:r,onLoadDirectory:i}){let[a,o]=b(!1),[s,c]=b(),l=async()=>{if(!(r===void 0||a)){o(!0),c(void 0);try{let e=await r();c(e.error)}catch{c(`The run folder could not be opened in Finder.`)}finally{o(!1)}}},[u,d]=b(new Set),[f,p]=b({}),[m,h]=b({}),[g,_]=b(new Set),v=new Map;for(let t of[...Object.values(f).flat(),...e?.artifacts??[]])v.set(t.path,t);for(let e of v.values()){let t=e.path.split(`/`);for(t.pop();t.length>0;){let n=t.join(`/`);v.has(n)||v.set(n,{path:n,kind:`directory`,description:``,producedBy:[],declared:!1,state:e.state===`pending`?`pending`:`written`}),t.pop()}}let ee=async e=>{let t=u.has(e.path);if(d(n=>{let r=new Set(n);return t?r.delete(e.path):r.add(e.path),r}),!(t||g.has(e.path)||i===void 0||e.state===`pending`)){_(t=>new Set(t).add(e.path));try{let t=await i(e.path);`error`in t?h(n=>({...n,[e.path]:t.error})):(p(n=>({...n,[e.path]:t.artifacts.artifacts})),h(t=>({...t,[e.path]:``})))}catch{h(t=>({...t,[e.path]:`The folder cannot be read.`}))}finally{_(t=>{let n=new Set(t);return n.delete(e.path),n})}}},te=e=>{let t=Ft[e.state],r=e.kind===`directory`||e.state!==`pending`;return S(`button`,{type:`button`,"data-testid":`artifact-row-${e.path}`,"data-artifact-state":e.state,disabled:!r,"aria-expanded":e.kind===`directory`?u.has(e.path):void 0,onClick:()=>e.kind===`directory`?void ee(e):n(e.path),className:`flex flex-col gap-0.5 px-3 py-1.5 text-left ${r?`cursor-pointer hover:bg-po-panel`:`cursor-default`}`,children:[S(`span`,{className:`flex min-w-0 items-center gap-2`,children:[j(`span`,{className:`w-3 shrink-0 text-xs ${t.className}`,children:e.kind===`directory`?u.has(e.path)?`▾`:`▸`:t.glyph}),S(`span`,{title:e.path,className:`min-w-0 flex-1 truncate text-base font-semibold ${e.state===`pending`?`text-po-dim`:`text-po-hi`}`,children:[e.path.split(`/`).pop(),e.kind===`directory`?`/`:``]}),j(`span`,{className:`shrink-0 text-sm text-po-dim`,children:e.state===`pending`?`pending`:e.kind===`directory`?``:[Nt(e.size),Pt(e.modifiedAt)].filter(Boolean).join(` · `)})]}),e.declared||e.producedBy.length>0||e.description!==``?S(`span`,{className:`flex min-w-0 items-center gap-1 pl-5 text-sm text-po-dim`,children:[e.declared?j(T,{size:`xs`,tone:`violet`,className:`shrink-0`,children:`declared`}):null,e.producedBy.length===0?null:j(`span`,{title:e.producedBy.join(`, `),className:`truncate`,children:e.producedBy.join(`, `)}),e.description===``?null:j(`span`,{title:e.description,className:`truncate`,children:e.description})]}):null]})},ne=e=>[...v.values()].filter(t=>{let n=t.path.lastIndexOf(`/`);return(n===-1?``:t.path.slice(0,n))===e}).sort((e,t)=>Number(t.kind===`directory`)-Number(e.kind===`directory`)||e.path.localeCompare(t.path)).map(e=>S(`div`,{className:`flex flex-col`,children:[te(e),e.kind===`directory`&&u.has(e.path)?S(`div`,{className:`ml-3 border-l border-po-border pl-1`,children:[g.has(e.path)?j(`span`,{className:`px-3 text-sm text-po-dim`,children:`loading…`}):null,m[e.path]?j(`span`,{role:`alert`,className:`px-3 text-base text-po-yellow`,children:m[e.path]}):null,ne(e.path)]}):null]},e.path));return S(`div`,{"data-testid":`artifacts-pane`,className:`flex min-h-0 flex-1 flex-col`,children:[t===void 0?null:j(C,{className:`py-4`,title:`the run directory cannot be read`,description:t}),v.size===0&&t===void 0?j(C,{className:`py-4`,title:`nothing in the run directory yet`}):null,e?.description?j(`span`,{className:`px-3 py-2 text-sm text-po-dim`,children:e.description}):null,ne(``),s===void 0?null:j(`span`,{role:`alert`,className:`px-3 text-base text-po-yellow`,children:s}),e===void 0?null:j(`button`,{type:`button`,"data-testid":`workflow-open-directory`,"aria-label":`Open workflow folder in Finder`,title:`${e.runDir} (open in Finder)`,disabled:a||r===void 0,onClick:()=>void l(),className:`truncate px-3 py-2 text-left text-base text-po-dim hover:text-po-hi disabled:cursor-default`,children:e.runDir})]})}var Wt=`dynamic_workflow_runs`,Gt=[`pending`,`running`,`completed`,`failed`,`stopped`,`skipped`],Kt=[`step`,`sequence`,`parallel`,`branch`,`foreach`];function qt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Jt(e){return typeof e==`number`&&Number.isFinite(e)}function Yt(e){return Jt(e)&&Number.isSafeInteger(e)&&e>=0}function Xt(e){return typeof e==`string`&&Gt.includes(e)}function Zt(e){return qt(e)&&typeof e.key==`string`&&typeof e.label==`string`}function Qt(e){return(e.startedAt===void 0||Jt(e.startedAt))&&(e.finishedAt===void 0||Jt(e.finishedAt))&&(e.error===void 0||typeof e.error==`string`)}function $t(e,t=0){return t<128&&Zt(e)&&typeof e.kind==`string`&&Kt.includes(e.kind)&&Array.isArray(e.children)&&e.children.every(e=>$t(e,t+1))}function en(e){return qt(e)&&typeof e.runId==`string`&&e.runId.length>0&&Xt(e.status)&&e.status!==`pending`&&e.status!==`skipped`}function tn(e){return Zt(e)&&Xt(e.status)&&Xt(e.executionStatus)&&Qt(e)&&Array.isArray(e.agents)&&e.agents.every(en)}function nn(e){return Zt(e)&&Yt(e.index)&&Xt(e.status)&&Array.isArray(e.phases)&&e.phases.every(tn)}function rn(e){return Zt(e)&&Yt(e.total)&&typeof e.truncated==`boolean`&&(e.concurrency===void 0||Yt(e.concurrency)&&e.concurrency!==0)&&qt(e.counts)&&Gt.every(t=>Yt(e.counts[t]))&&Array.isArray(e.items)&&e.items.every(nn)}function an(e){return Zt(e)&&typeof e.workflowId==`string`&&Xt(e.status)&&Xt(e.executionStatus)&&Jt(e.startedAt)&&Qt(e)&&$t(e.shape)&&Array.isArray(e.groups)&&e.groups.every(rn)}function on(e){return!qt(e)||e.version!==1||!Yt(e.revision)||typeof e.sessionId!=`string`||!Array.isArray(e.runs)||!e.runs.every(an)||e.unlinkedAgents!==void 0&&(!Array.isArray(e.unlinkedAgents)||e.unlinkedAgents.length>1e3||!e.unlinkedAgents.every(en))?null:e}function sn(e,t){return e!==null&&t.revision<=e.revision?e:t}var L=Be(null),cn=ae({channel:Wt,parse:on,apply(e,t){t.sessionId===e&&L.update(e,e=>sn(e,t))},drop(e){L.drop(e)}}),R={pending:{label:`Pending`,tone:`neutral`},running:{label:`Running`,tone:`running`},completed:{label:`Done`,tone:`ok`},failed:{label:`Failed`,tone:`error`},stopped:{label:`Stopped`,tone:`neutral`},skipped:{label:`Skipped`,tone:`neutral`}};function ln(e){return e.length?`${e.filter(e=>e.status===`running`).length} running · ${e.filter(e=>e.status!==`running`&&e.status!==`pending`).length} finished`:`Workflows appear here when Po starts them.`}function un(e){let t=e.filter(e=>e.status===`running`).length,n=e.filter(e=>e.status===`failed`).length,r=[`${e.length} dynamic ${e.length===1?`run`:`runs`}`];return t&&r.push(`${t} running`),{text:r.join(` · `),failed:n}}function dn(e,t,n=0){if(e===void 0)return`Not started`;let r=Math.max(0,Math.floor(((t??n)-e)/1e3));return r<60?`${r}s`:`${Math.floor(r/60)}m ${r%60}s`}var fn=e=>e===`completed`?`green`:e===`running`?`yellow`:e===`failed`?`red`:`neutral`;function pn(e){let t=e.groups.filter(e=>e.concurrency!==void 0),n=t.reduce((e,t)=>e+t.total,0),r=e=>t.reduce((t,n)=>t+n.counts[e],0);return{total:n,running:r(`running`),done:r(`completed`),failed:r(`failed`)}}function mn(e){let t=(e,t,n)=>({id:`${e}->${t}`,source:e,target:t,status:n.find(e=>e.id===t)?.data.status??`pending`}),n=e=>e.includes(`running`)?`running`:e.includes(`failed`)?`failed`:e.length&&e.some(e=>e===`completed`)&&e.every(e=>e===`completed`||e===`skipped`)?`completed`:e.includes(`stopped`)?`stopped`:e.length&&e.every(e=>e===`skipped`)?`skipped`:`pending`,r=(a,o,s)=>{let c=`${s??e.key}:${a.key}`;if(a.kind===`step`){let e=o?.phases.find(e=>e.key===a.key);return{nodes:[{id:c,parentId:s,position:{x:0,y:0},width:200,height:e?.error?88:64,data:{label:a.label,kind:a.kind,status:e?.status??`pending`,phase:e}}],edges:[],width:200,height:e?.error?88:64,entry:[c],exit:[c]}}if(a.kind===`foreach`){let t=e.groups.find(e=>o?e.key===`${o.key}/${a.key}`:e.key.endsWith(`/${a.key}`)),l=t?.items.find(e=>e.status===`running`)??t?.items[0],u=i(a.children.map(e=>r(e,l,c)),!1),d=Math.max(360,u.width+48),f=Math.ceil(Math.min(t?.items.length??0,24)/8),p=u.height+112+f*40+(t&&t.total>24?32:0),m=t?n(Object.entries(t.counts).filter(([,e])=>e>0).map(([e])=>e)):`pending`,h={id:c,parentId:s,position:{x:0,y:0},width:d,height:p,data:{label:a.label,kind:a.kind,status:m,group:t}};return u.nodes.forEach(e=>{e.parentId===c&&(e.position.x+=(d-u.width)/2,e.position.y+=72)}),{nodes:[h,...u.nodes],edges:u.edges,width:d,height:p,entry:[c],exit:[c]}}let l=a.children.map(e=>r(e,o,s)),u=i(l,a.kind!==`sequence`);if(a.kind!==`branch`)return u;u.nodes.forEach(e=>{e.parentId===s&&(e.position.y+=144)});let d=n(l.flatMap(e=>e.nodes.filter(e=>e.parentId===s).map(e=>e.data.status))),f={id:c,parentId:s,position:{x:(u.width-160)/2,y:0},width:160,height:96,data:{label:`Branch`,kind:`branch`,status:d}};return u.edges.push(...u.entry.map(e=>t(c,e,u.nodes))),{...u,nodes:[f,...u.nodes],height:u.height+144,entry:[c]}};function i(e,n){let r=n?e.reduce((e,t)=>e+t.width,0)+Math.max(0,e.length-1)*48:Math.max(200,...e.map(e=>e.width)),i=[],a=[],o=0;return e.forEach((s,c)=>{let l=new Set(s.nodes.map(e=>e.id));if(s.nodes.forEach(e=>{(!e.parentId||!l.has(e.parentId))&&(e.position.x+=n?o:(r-s.width)/2,e.position.y+=n?0:o)}),i.push(...s.nodes),a.push(...s.edges),!n&&c)for(let n of e[c-1].exit)for(let e of s.entry)a.push(t(n,e,s.nodes));o+=(n?s.width:s.height)+48}),{nodes:i,edges:a,width:r,height:n?Math.max(0,...e.map(e=>e.height)):Math.max(0,o-48),entry:n?e.flatMap(e=>e.entry):e[0]?.entry??[],exit:n?e.flatMap(e=>e.exit):e.at(-1)?.exit??[]}}let a=e.groups.flatMap(e=>e.items).find(t=>t.phases.some(t=>{let n=e=>e.kind===`foreach`?!1:e.key===t.key||e.children.some(n);return n(e.shape)}));return r(e.shape,a)}function z({startedAt:e,endedAt:t,now:n,seconds:r=!1,running:i=!0}){let a=ye(null),[o]=b(Date.now),s=typeof e==`string`?Date.parse(e):e,c=typeof t==`string`?Date.parse(t):t,l=Re(e=>s===void 0||!Number.isFinite(s)?r?`Not started`:``:c!==void 0&&!Number.isFinite(c)?``:r?dn(s,c,e):Je(Math.max(0,(c??e)-s)),[s,c,r]);return w(()=>{if(n!==void 0||!i||s===void 0||!Number.isFinite(s)||c!==void 0)return;let e=()=>{let e=a.current?.firstChild;e&&(e.nodeValue=l(Date.now()))};e();let t=setInterval(e,r?1e3:1e4);return()=>clearInterval(t)},[s,c,n,r,i,l]),j(`span`,{ref:a,children:l(n??o)})}var hn=e=>`var(--po-${fn(e)===`neutral`?`dim`:fn(e)})`;function gn({runs:e,connected:t=!0,onOpen:n}){return S(`div`,{className:`space-y-2`,children:[j(`p`,{className:`px-3 text-sm text-po-dim`,children:t?ln(e):`Connection paused. Showing last update.`}),!e.length&&S(E,{variant:`ghost`,size:`card`,onClick:n,"aria-label":`Open dynamic workflows`,children:[j(`span`,{className:`text-base font-semibold text-po-hi`,children:`No workflows yet`}),j(`span`,{className:`text-sm text-po-dim`,children:`Idle`}),j(`span`,{className:`text-sm text-po-blue`,children:`View workflows →`})]}),e.map(e=>{let t=pn(e);return S(E,{variant:`ghost`,size:`card`,onClick:n,"aria-label":`Open ${e.label}`,children:[S(`span`,{className:`flex w-full items-center gap-3`,children:[j(D,{tone:fn(e.status),size:`md`}),j(`span`,{className:`min-w-0 flex-1 break-words text-base font-semibold text-po-hi`,children:e.label}),S(`span`,{className:`shrink-0 text-sm text-po-dim`,children:[R[e.status].label,` ›`]})]}),t.total>0&&S(O,{children:[S(`span`,{className:`pl-5 text-sm text-po-dim`,children:[e.status===`running`?`${t.running} of ${t.total} running`:`${t.total} items`,` `,`· `,t.done,` done`,t.failed>0&&S(`span`,{className:`text-po-red`,children:[` · `,t.failed,` failed`]})]}),S(`span`,{className:`ml-5 flex h-1.5 overflow-hidden rounded-full bg-po-deep`,role:`img`,"aria-label":`${t.done} done, ${t.running} running, ${t.total} total`,children:[j(`span`,{className:`bg-po-green`,style:{width:`${t.done/t.total*100}%`}}),j(`span`,{className:`bg-po-yellow`,style:{width:`${t.running/t.total*100}%`}})]})]})]},e.key)})]})}function _n({data:e,now:t,expanded:n,onOpenAgent:r}){let i=e.group,a=i?.items.slice(0,24)??[];return S(`div`,{className:e.kind===`branch`?`relative flex h-full items-center justify-center text-base text-po-text`:`h-full rounded-lg border bg-po-panel p-3 text-base text-po-text`,style:{borderColor:e.kind===`foreach`&&e.status===`running`?hn(e.status):`var(--po-border)`},children:[e.kind===`branch`&&j(`svg`,{viewBox:`0 0 160 96`,className:`absolute inset-0 h-full w-full`,"aria-hidden":`true`,children:j(`polygon`,{points:`80,1 159,48 80,95 1,48`,fill:`var(--po-panel)`,stroke:`var(--po-border)`})}),S(`div`,{className:`relative flex items-center gap-3`,children:[j(`span`,{"aria-hidden":`true`,style:{color:hn(e.status)},children:e.kind===`branch`?`◇`:e.status===`completed`?`✓`:e.status===`running`?`●`:e.status===`failed`?`×`:`○`}),S(`div`,{className:`min-w-0 flex-1`,children:[S(`p`,{className:`truncate font-semibold text-po-hi`,title:e.label,children:[e.kind===`foreach`?`foreach · `:``,e.label]}),j(`p`,{className:`text-sm text-po-dim`,children:i?`${i.total} items${i.concurrency?` · up to ${i.concurrency} at once`:``}`:S(O,{children:[R[e.status].label,e.phase?.startedAt===void 0?null:S(O,{children:[` `,`·`,` `,j(z,{seconds:!0,startedAt:e.phase.startedAt,endedAt:e.phase.finishedAt,now:t,running:e.status===`running`})]})]})})]}),e.phase?.agents.map((t,n)=>j(E,{variant:`link`,size:`sm`,className:`shrink-0 px-1`,"aria-label":`Open ${e.label} agent ${n+1} transcript`,onClick:()=>r(t.runId),children:`↗`},t.runId))]}),e.phase?.error&&j(`p`,{className:e.phase.status===`failed`?`truncate text-sm text-po-red`:`truncate text-sm text-po-dim`,title:e.phase.error,role:e.phase.status===`failed`?`alert`:void 0,children:e.phase.error}),e.kind===`foreach`&&S(`div`,{className:`absolute inset-x-3 bottom-3 flex flex-wrap gap-1.5`,children:[a.map(e=>S(u,{defaultOpen:n.includes(e.key),children:[j(ve,{asChild:!0,children:j(`button`,{type:`button`,"aria-label":`${e.label}, ${R[e.status].label}`,className:`h-8 min-w-8 rounded-md border bg-po-bg px-2 text-sm font-semibold outline-none focus-visible:ring-2 focus-visible:ring-po-green`,style:{color:hn(e.status),borderColor:hn(e.status)},children:e.index+1})}),S(fe,{className:`max-w-sm gap-3 p-3`,children:[j(`h3`,{className:`text-base font-semibold text-po-hi`,children:e.label}),e.phases.map(e=>S(`div`,{className:`space-y-1 text-sm`,children:[S(`p`,{className:`flex items-center gap-2 text-po-text`,children:[j(D,{tone:fn(e.status)}),e.label,` · `,R[e.status].label,e.startedAt!==void 0&&S(O,{children:[` `,`·`,` `,j(z,{seconds:!0,startedAt:e.startedAt,endedAt:e.finishedAt,now:t,running:e.status===`running`})]})]}),e.error&&j(`p`,{className:e.status===`failed`?`text-po-red`:`text-po-dim`,children:e.error}),e.agents.map((t,n)=>j(E,{variant:`link`,size:`sm`,onClick:()=>r(t.runId),"aria-label":`Open ${e.label} agent ${n+1} transcript`,children:`Open transcript ↗`},t.runId)),!e.agents.length&&j(`p`,{className:`text-po-dim`,children:`No agent transcript`})]},e.key))]})]},e.key)),i&&i.total>a.length&&S(`span`,{className:`self-center text-sm text-po-dim`,children:[`+`,i.total-a.length,` more`]})]})]})}function vn({run:e,now:t,defaultExpandedKeys:n=[],onOpenAgent:r}){let i=mn(e);return j(me,{nodes:i.nodes,edges:i.edges.map(({status:e,...t})=>({...t,tone:e===`running`?`active`:e===`pending`?`pending`:`idle`})),renderNode:e=>j(_n,{data:e.data,now:t,expanded:n,onOpenAgent:r})})}function yn({runs:e,connected:t=!0,...n}){return S(`section`,{className:`min-w-0 space-y-4 bg-po-bg p-4 text-po-text`,"aria-label":`Dynamic workflows`,children:[!t&&j(`p`,{role:`status`,className:`text-sm text-po-dim`,children:`Connection paused. These are the last reported workflow states.`}),!e.length&&S(`div`,{className:`space-y-2 py-6`,children:[j(`h2`,{className:`text-lg font-semibold text-po-hi`,children:`No workflows yet`}),j(`p`,{className:`text-base text-po-dim`,children:`Workflows appear here when Po starts them. You can carry on with your conversation.`})]}),e.map(e=>S(`article`,{className:`overflow-hidden rounded-lg border border-po-border`,children:[S(`header`,{className:`space-y-1 p-4`,children:[S(`div`,{className:`flex flex-wrap items-center gap-3`,children:[j(`h2`,{className:`break-words text-lg font-semibold text-po-hi`,children:e.label}),j(c,{tone:R[e.status].tone,children:R[e.status].label})]}),S(`p`,{className:`text-sm text-po-dim`,children:[`Started `,j(z,{seconds:!0,startedAt:e.startedAt,now:n.now}),` ago`]}),e.executionStatus!==e.status&&S(`p`,{className:`text-sm text-po-dim`,children:[`Workflow execution: `,R[e.executionStatus].label]}),e.error&&j(`p`,{className:e.status===`failed`?`text-sm text-po-red`:`text-sm text-po-dim`,role:e.status===`failed`?`alert`:void 0,children:e.error})]}),j(vn,{run:e,...n})]},e.key))]})}function bn(e,t){let n=t.join(`
4
- `);w(()=>{if(e===void 0||n===``)return;let t=n.split(`
5
- `).map(t=>e(t,e=>{if(e.type!==cn.channel)return;let n=cn.parse(e.payload);n!==null&&cn.apply(t,n)}));return()=>{for(let e of t)e()}},[e,n])}function xn(e){return x(L.store,t=>L.select(t,e)?.runs)}function Sn({stepSessionId:e}){let t=xn(e);if(t===void 0||t.length===0)return null;let n=un(t);return S(`span`,{"data-testid":`step-dynamic-note-${e}`,className:`truncate pl-5 text-sm text-po-dim`,children:[n.text,n.failed>0&&S(`span`,{className:`text-po-red`,children:[` · `,n.failed,` failed`]})]})}function Cn({stepSessionId:e,holdSessionChannels:t,openSession:n}){let r=xn(e),[i,a]=b(!1);if(bn(t,[e]),r===void 0||r.length===0)return null;let o=un(r);return S(`section`,{"data-testid":`step-dynamic-runs`,"aria-label":`dynamic workflows`,className:`flex flex-col border-t border-po-border ${i?`min-h-0 flex-1`:`shrink-0`}`,children:[S(`button`,{type:`button`,"data-testid":`step-dynamic-runs-toggle`,"aria-expanded":i,onClick:()=>a(!i),className:`flex w-full shrink-0 cursor-pointer items-center gap-2 rounded px-2 py-2 text-left hover:bg-po-panel`,children:[j(i?Te:Ce,{className:`h-2.5 w-2.5 shrink-0 text-po-faint`}),j(`span`,{className:`text-base font-semibold text-po-hi`,children:`Dynamic workflows`}),S(`span`,{className:`min-w-0 flex-1 truncate text-sm text-po-dim`,children:[o.text,o.failed>0&&S(`span`,{className:`text-po-red`,children:[` · `,o.failed,` failed`]})]})]}),i&&j(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:j(yn,{runs:r,onOpenAgent:()=>n?.(e)})})]})}function wn(e){let t=``,n=!1,r=async()=>{for(n=!0;t!==``;){let n=t;t=``,await e(n)||(t=``)}n=!1};return e=>{t+=e,n||r()}}var Tn=`workflows-step-`,En={Enter:`\r`,Backspace:``,Tab:` `,Escape:`\x1B`,ArrowUp:`\x1B[A`,ArrowDown:`\x1B[B`,ArrowRight:`\x1B[C`,ArrowLeft:`\x1B[D`},Dn=``,On=``,kn=64;function An(e){return`${Tn}${e.workspace}-${e.runKey}-${e.job}${e.step===void 0?``:`-${e.step}`}`.replace(/[^\w-]+/g,`-`)}function jn(e,t,n){let r={workspace:e.workspace,runKey:e.routeKey??e.runKey,job:t,...n===void 0?{}:{step:n}},i=n??t,a=Fn(e,r);return{id:An(r),targetSessionId:a?.id,activityScope:Ve,retainComposer:a!==void 0&&e.stage===`running`&&Nn(e,r)?.status===`running`,label:`${e.displayName} › ${i}`,panel:e=>j(Rn,{...e,target:r})}}function Mn(e,t,n,{openSession:r,openTransientTab:i}){let a=Fn(e,{workspace:e.workspace,runKey:e.routeKey??e.runKey,job:t,...n===void 0?{}:{step:n}});a!==void 0&&r!==void 0?r(a.id):i(jn(e,t,n))}function Nn(e,t){let n=e?.jobs.find(e=>e.name===t.job)?.steps??[];return t.step===void 0?n.at(-1):n.find(e=>e.name===t.step)}function Pn(e,t){let n=Nn(e,t)?.ref;return n?.kind===`pane`?n.id:void 0}function Fn(e,t){let n=Nn(e,t);return n?.ref?.kind===`session`?n.ref:void 0}function In({line:e}){return e.length===0?j(`span`,{className:`block h-[15px]`}):j(Oe,{line:e,className:`block whitespace-pre`})}function Ln({run:e,target:t,children:n}){return S(`div`,{"data-testid":`step-terminal-head`,className:`flex items-center gap-2.5 pb-3`,children:[j(`span`,{className:`shrink-0 truncate text-base font-semibold text-po-hi`,children:e?.displayName??t.runKey}),j(`span`,{className:`text-xs text-po-faint`,children:`›`}),j(`span`,{className:`shrink-0 truncate text-base font-semibold text-po-hi`,children:t.job}),t.step===void 0?null:S(O,{children:[j(`span`,{className:`text-xs text-po-faint`,children:`›`}),j(`span`,{className:`min-w-0 truncate text-base text-po-text`,children:t.step})]}),e===void 0?null:j(c,{tone:e.stage===`running`?`running`:e.stage===`error`?`error`:`ok`,"data-testid":`step-terminal-stage`,children:e.stage}),j(`span`,{className:`min-w-0 flex-1`}),n]})}function Rn(e){let{sessionId:t,target:n,renderSessionTranscript:r,setTransientTabSession:i,holdSessionChannels:a,openSession:o}=e,s=x(N.store,e=>N.select(e,t).runs).find(e=>e.workspace===n.workspace&&(e.routeKey??e.runKey)===n.runKey),c=Fn(s,n),l=c?.id,u=s?.stage===`running`&&Nn(s,n)?.status===`running`;return w(()=>{i?.(An(n),l,l!==void 0&&u)},[i,n,l,u]),c!==void 0&&r!==void 0?S(`div`,{"data-testid":`step-conversation-panel`,className:`flex min-h-0 flex-1 flex-col px-[26px] py-[18px]`,children:[j(Ln,{run:s,target:n,children:j(T,{size:`xs`,tone:`blue`,"data-testid":`step-conversation-session`,children:`agent session`})}),j(`div`,{"data-testid":`step-conversation`,className:`flex min-h-0 flex-1 flex-col`,children:r(c.id)}),j(Cn,{stepSessionId:c.id,holdSessionChannels:a,openSession:o})]}):j(zn,{sessionId:t,target:n,run:s})}function zn({sessionId:e,target:t,run:n}){let[r,i]=b([]),[a,o]=b(),[s,c]=b(!1),[l,u]=b(),[d,f]=b(),[p,m]=b(),h=ye(null),g=Pn(n,t),_=`${e??``}\0${t.workspace}\0${t.runKey}\0${g??``}`,v=ye(_);w(()=>(v.current=_,()=>{v.current=void 0}),[_]),w(()=>(c(!1),u(void 0),yt(t.workspace,t.runKey,e=>{i(e.lines),o(e.capabilities),e.ended===!0&&c(!0)},e,g,u)),[e,t.workspace,t.runKey,g]),w(()=>{if(d!==void 0)return()=>{xt(t.workspace,t.runKey,d,e,g)}},[e,d,t.workspace,t.runKey,g]),w(()=>{h.current?.scrollTo({top:h.current.scrollHeight})},[r]);let ee=Re(async()=>{let n=_,r=await bt(t.workspace,t.runKey,void 0,e,g);v.current===n?r.held&&r.token!==void 0?(f(r.token),m(void 0)):m(r.reason??`The keyboard is not available for this run.`):r.held&&r.token!==void 0&&xt(t.workspace,t.runKey,r.token,e,g)},[e,t.workspace,t.runKey,_,g]),te=Re(()=>{f(void 0)},[]),ne=be(()=>d===void 0?void 0:wn(async n=>{let{error:r}=await St(t.workspace,t.runKey,d,n,e,g);return r===void 0||(m(r),f(void 0),!1)}),[d,t.workspace,t.runKey,e,g]),re=e=>ne?.(e),ie=e=>{if(d===void 0)return;if(e.key===`Escape`&&!e.ctrlKey){e.preventDefault(),te();return}let t=En[e.key];if(t!==void 0)e.preventDefault(),re(t);else if(e.ctrlKey&&e.key.length===1){e.preventDefault();let t=e.key.toUpperCase().charCodeAt(0);re(e.key===`c`?Dn:e.key===`d`?On:String.fromCharCode(t-kn))}else e.key.length===1&&!e.metaKey&&!e.altKey&&(e.preventDefault(),re(e.key))},y=d!==void 0,ae=a?.writable===!0;return S(`div`,{"data-testid":`step-terminal-panel`,className:`flex min-h-0 flex-1 flex-col px-[26px] py-[18px]`,children:[S(Ln,{run:n,target:t,children:[j(T,{size:`xs`,tone:y?`blue`:`neutral`,"data-testid":`step-terminal-control`,className:y?`border-po-blue/60 bg-po-tint-blue text-po-hi`:``,children:y?`keyboard yours`:`watching`}),ae?j(E,{variant:y?`outline`:`primary`,size:`xs`,"data-testid":`step-terminal-arm`,onClick:()=>y?te():void ee(),children:y?`release keyboard`:`take control`}):null]}),S(`div`,{ref:h,"data-testid":`step-terminal-screen`,role:`textbox`,"aria-label":`Workflow terminal`,"aria-multiline":`true`,"aria-readonly":d===void 0,tabIndex:0,onKeyDown:ie,className:`min-h-0 flex-1 overflow-y-auto rounded-md border bg-po-deep px-4 py-3 font-mono text-sm leading-tight text-po-text outline-none ${y?`border-po-blue/60`:`border-po-border`}`,children:[r.length===0?j(`span`,{"data-testid":`step-terminal-waiting`,className:`text-sm ${l?`text-po-red`:`text-po-dim`}`,children:l??(a?.readable===!1?a.reason??`This run has no terminal to read.`:`waiting for the run to paint…`)}):r.map((e,t)=>j(In,{line:e},t)),y&&!s?j(ue,{className:`mt-0.5 h-[12px] w-1.5`}):null]}),S(`div`,{className:`flex items-center gap-3 pt-2.5`,children:[j(`span`,{"data-testid":`step-terminal-hint`,className:`text-sm text-po-dim`,children:y?`keys go to the run · ctrl-c and ctrl-d pass through · esc releases the keyboard`:a?.writable===!1?a.reason??`this run cannot be typed into`:`read-only until you take control · the run keeps going either way`}),j(`span`,{className:`min-w-0 flex-1`}),s?j(`span`,{"data-testid":`step-terminal-ended`,className:`text-sm text-po-dim`,children:`the run has settled; this is its last screen`}):null,p===void 0?null:j(`span`,{"data-testid":`step-terminal-notice`,className:`text-sm text-po-yellow`,children:p})]})]})}var B={pending:`○`,running:`●`,resumed:`●`,completed:`✓`,failed:`✕`,skipped:`↷`,pause_requested:`!`,paused:`!`},Bn=new Set([`running`,`resumed`,`pause_requested`,`paused`]);function Vn(e){if(e.stage===`error`){let t=e.errorMessage??`the run ended in the error stage`;return{kind:`error`,text:e.failedJob===void 0?t:`job '${e.failedJob}' failed: ${t}`}}if(e.stale===!0)return{kind:`stale`,text:e.staleReason??`the process that ran this workflow is gone`};if(e.executionState===`paused`||e.executionState===`pause_requested`)return{kind:`paused`,text:`the run is paused and will not move until it is resumed`}}function Hn(e){return e.stage===`error`?`failed`:e.executionState===`paused`||e.executionState===`pause_requested`?`paused`:e.stage===`running`?`running`:e.outcome??e.stage}function Un(e){return e.jobs.flatMap(e=>e.steps.filter(e=>Bn.has(e.status)).map(t=>({job:e.name,step:t})))}var Wn=[`all`,`running`,`paused`,`failed`,`done`];function Gn(e){return e.stage===`error`||e.outcome===`failed`?`failed`:e.executionState===`paused`||e.executionState===`pause_requested`?`paused`:e.stage===`running`?`running`:`done`}function Kn(e){return Vn(e)===void 0?e.stage===`running`?1:2:0}function qn(e){return[e.displayName,e.workflowName,e.stage,e.outcome,e.executionState,e.position?.job,e.position?.step].filter(e=>typeof e==`string`).join(` `).toLowerCase()}function Jn(e){return e.stage===`error`||e.stale===!0||e.outcome===`failed`||e.outcome===`interrupted`}function Yn(e){let t=JSON.stringify({action:`recover`,runKey:e.runKey,workspace:e.workspace});return`Recover the workflow run "${e.displayName}" (${e.runKey}). Check why it stopped first; if the cause is transient or fixed, call workflow_run ${t}, otherwise tell me what needs fixing.`}var Xn={pending:{glyph:B.pending,className:`text-po-faint`},running:{glyph:B.running,className:`text-po-blue`},resumed:{glyph:B.resumed,className:`text-po-blue`},completed:{glyph:B.completed,className:`text-po-green`},failed:{glyph:B.failed,className:`text-po-red`},skipped:{glyph:B.skipped,className:`text-po-faint`},pause_requested:{glyph:B.pause_requested,className:`text-po-yellow`},paused:{glyph:B.paused,className:`text-po-yellow`}};function Zn(e){return e.stage===`error`?`red`:e.executionState===`paused`||e.executionState===`pause_requested`?`yellow`:e.stage===`running`?`blue`:e.outcome===`success`?`green`:`neutral`}function Qn({runs:t,selected:r,onSelect:i,className:a}){let[o,c]=b(!1),[l,d]=b(``),[f,p]=b(`all`),m=be(()=>[...t].sort((e,t)=>Kn(e)-Kn(t)),[t]),h=l.trim().toLowerCase(),g=m.filter(e=>(f===`all`||Gn(e)===f)&&qn(e).includes(h));return S(u,{open:o,onOpenChange:e=>{c(e),e||d(``)},children:[j(ve,{asChild:!0,children:S(E,{variant:`outline`,size:`sm`,"data-testid":`workflow-picker`,className:A(`h-8 w-full max-w-[360px] justify-start border-po-border bg-po-deep px-2.5`,a),children:[j(ge,{className:`h-3 w-3 shrink-0 text-po-faint`}),j(`span`,{className:`min-w-0 flex-1 truncate text-left text-base font-semibold text-po-hi`,children:r.displayName}),S(`span`,{className:`shrink-0 text-sm font-normal text-po-dim`,children:[t.length,` workflows`]}),j(Te,{className:`h-3 w-3 shrink-0 text-po-dim`})]})}),S(fe,{side:`bottom`,align:`start`,"data-testid":`workflow-picker-popover`,className:`w-[440px] border-po-edge-blue`,children:[S(e,{children:[j(ke,{className:`text-po-blue`,children:`workflow`}),j(`span`,{className:`truncate text-sm text-po-dim`,children:r.displayName})]}),j(`div`,{className:`border-b border-po-border-soft p-1.5`,children:j(oe,{autoFocus:!0,"data-testid":`workflow-picker-search`,value:l,onChange:e=>d(e.target.value),placeholder:`filter workflows…`,className:`w-full px-2 py-1 text-sm`})}),S(`div`,{role:`listbox`,"aria-label":`workflows`,className:`flex max-h-[300px] flex-col gap-0.5 overflow-y-auto p-1.5`,children:[g.length===0?j(C,{className:`py-4`,title:`no workflow matches`}):null,g.map(e=>{let t=M(e)===M(r);return S(s,{density:`compact`,active:t,"data-testid":`workflow-option-${e.runKey}`,"data-run-stage":e.stage,"data-active":t,onClick:()=>{i(e),c(!1)},className:A(`w-full gap-2.5 py-1.5 transition-colors hover:bg-po-deep focus-visible:bg-po-deep`,t&&`bg-po-tint-blue hover:brightness-125`),children:[j(`span`,{className:`w-14 shrink-0 truncate text-sm text-po-dim`,children:Hn(e)}),j(n,{density:`compact`,className:t?`text-po-blue`:`text-po-hi`,children:e.displayName}),j(`span`,{className:`max-w-[40%] truncate text-sm text-po-dim`,children:[e.position?.job,e.position?.step].filter(Boolean).join(` · `)}),j(D,{tone:Zn(e),pulse:e.stage===`running`})]},M(e))})]}),S(ne,{className:`flex-wrap justify-start gap-1 py-1.5`,children:[j(ke,{className:`mr-1`,children:`status`}),Wn.map(e=>{let t=f===e;return j(E,{variant:`ghost`,size:`xs`,"data-testid":`workflow-filter-${e}`,"data-current":t,onClick:()=>p(e),className:A(t&&`bg-po-blue/25 font-semibold text-po-blue hover:bg-po-blue/25`),children:e},e)})]})]})]})}function $n({step:e,now:t,selected:n,onSelect:r,note:i,here:a=!1}){let o=Xn[e.status];return S(`button`,{type:`button`,disabled:e.status===`pending`,title:`${e.name}: ${e.status}`,"data-testid":`step-row-${e.name}`,"data-step-status":e.status,"data-active":n,"data-here":a||void 0,"aria-current":a?`step`:void 0,onClick:r,className:A(`flex w-full cursor-pointer flex-col gap-0.5 rounded px-2 py-1.5 text-left enabled:hover:bg-po-deep disabled:cursor-default`,n&&`bg-po-tint-blue ring-1 ring-inset ring-po-blue/40`,a&&`bg-po-tint-green ring-1 ring-inset ring-po-edge-green`),children:[S(`span`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`w-3 shrink-0 text-xs ${o.className}`,children:o.glyph}),j(`span`,{className:A(`min-w-0 flex-1 truncate text-base font-medium`,e.status===`failed`?`text-po-red`:`text-po-text`),children:e.name}),e.group===void 0?null:S(`span`,{"data-testid":`step-group-${e.name}`,className:`max-w-24 shrink-0 truncate text-sm text-po-dim`,children:[`∥ `,e.group]}),a?j(`span`,{className:`shrink-0 rounded-full bg-po-panel px-2 text-sm font-medium text-po-green`,children:`You are here`}):j(`span`,{className:`shrink-0 text-sm text-po-dim`,children:e.status===`pending`?`pending`:j(z,{startedAt:e.startedAt,endedAt:e.endedAt,now:t})})]}),e.reason===void 0?null:j(`span`,{"data-testid":`step-reason-${e.name}`,title:e.reason,className:A(`truncate pl-5 text-sm`,e.status===`failed`?`text-po-red`:`text-po-dim`),children:e.reason}),i]})}function er({run:e,sessionId:t,onClose:n,onDeleted:r}){let[i,a]=b(!1),[o,s]=b();return j(Ne,{open:!0,onOpenChange:e=>{!e&&!i&&n()},children:S(de,{width:`md`,"data-testid":`delete-workflow-dialog`,"aria-describedby":void 0,children:[j(re,{children:S(_e,{children:[`Delete `,e.displayName,`?`]})}),S(d,{children:[j(`p`,{className:`text-sm leading-relaxed text-po-dim`,children:`This permanently removes the workflow run, including its logs and artifacts. This action cannot be undone.`}),o===void 0?null:j(`p`,{"data-testid":`delete-workflow-error`,className:`text-base text-po-red`,children:o}),S(pe,{children:[j(`span`,{className:`min-w-0 flex-1`}),j(E,{variant:`outline`,size:`xs`,"data-testid":`delete-workflow-cancel`,disabled:i,onClick:n,children:`cancel`}),j(E,{variant:`danger`,size:`xs`,"data-testid":`delete-workflow-confirm`,loading:i,loadingLabel:`deleting workflow`,onClick:()=>{a(!0),s(void 0),Ct(e.workspace,e.routeKey??e.runKey,t).then(e=>{`error`in e?(a(!1),s(e.error)):r()})},children:`delete permanently`})]})]})]})})}function tr({run:e,sessionId:t}){let[n,r]=b(!1),[i,a]=b();return S(`div`,{className:`flex shrink-0 flex-col gap-1 border-t border-po-border-soft p-1.5`,children:[i===void 0?null:j(`span`,{"data-testid":`stop-workflow-error`,className:`px-1 text-base text-po-red`,children:i}),j(E,{variant:`danger-outline`,size:`xs`,"data-testid":`stop-workflow`,loading:n,loadingLabel:`stopping workflow`,onClick:()=>{r(!0),a(void 0),wt(e.workspace,e.routeKey??e.runKey,t).then(e=>{`error`in e&&(r(!1),a(e.error))})},className:`w-full`,children:`stop workflow`})]})}var V=Be({cwd:``,workflows:[],warning:void 0,open:!1,filter:``,prompt:``,selected:void 0,inspected:void 0,launch:void 0});function nr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function rr(e,t=``){V.update(e,e=>({...e,open:!0,prompt:t}))}function ir(e){e.sessionId!==null&&rr(e.sessionId,e.item.content)}function ar(e){V.update(e,e=>({...e,open:!1,prompt:``,launch:void 0}))}function or(e,t){V.update(e,e=>({...e,filter:t}))}function sr(e,t){V.update(e,e=>({...e,selected:t}))}function cr(e,t){V.update(e,e=>({...e,inspected:e.inspected===t?void 0:t}))}function lr(e,t){V.update(e,e=>({...e,selected:t,launch:t}))}function ur(e){V.update(e,e=>({...e,launch:void 0}))}function dr(e,t){let n=t.trim().toLowerCase();return n===``?[...e]:e.filter(e=>[e.name,e.relativePath,e.description,...e.tags,...e.jobs.map(e=>e.name)].join(`
6
- `).toLowerCase().includes(n))}var fr=V.channel({channel:Ue,parse(e){return!nr(e)||typeof e.cwd!=`string`||!Array.isArray(e.workflows)?null:{cwd:e.cwd,workflows:e.workflows.filter(nr),...typeof e.warning==`string`?{warning:e.warning}:{}}},reduce(e,t){let n=new Set(t.workflows.map(e=>e.path));return{...e,cwd:t.cwd,workflows:t.workflows,warning:t.warning,selected:e.selected!==void 0&&n.has(e.selected)?e.selected:void 0,inspected:e.inspected!==void 0&&n.has(e.inspected)?e.inspected:void 0,launch:e.launch!==void 0&&n.has(e.launch)?e.launch:void 0}}}),pr={running:`info`,paused:`running`,failed:`error`,success:`ok`};function mr(e){return e in pr?pr[e]:`neutral`}function hr(e){return e.jobs.flatMap(e=>e.steps.flatMap(e=>e.ref?.kind===`session`?[e.ref.id]:[]))}function gr({label:e,meta:t}){return S(`div`,{className:`flex items-center px-4 pb-1 pt-3`,children:[j(`span`,{className:`text-lg font-semibold text-po-hi`,children:e}),j(`span`,{className:`min-w-0 flex-1`}),t===void 0?null:j(`span`,{className:`text-sm text-po-dim`,children:t})]})}function _r({run:e,runs:t,now:n,onSelectRun:r}){let i=Hn(e),a=[e.position?.job,e.position?.step].filter(Boolean).join(` › `);return S(`div`,{"data-testid":`workflow-dock-run`,className:`flex shrink-0 flex-col gap-1.5 border-b border-po-border px-4 py-3`,children:[S(`div`,{className:`flex min-w-0 items-center gap-2`,children:[j(D,{tone:Zn(e),pulse:e.stage===`running`&&i===`running`}),j(`span`,{title:e.displayName,className:`min-w-0 flex-1 truncate text-base font-semibold text-po-hi`,children:e.displayName}),j(c,{size:`xs`,tone:mr(i),"data-testid":`workflow-dock-state`,"data-run-state":i,children:i})]}),S(`div`,{className:`flex min-w-0 items-center gap-1.5 text-sm text-po-dim`,children:[j(`span`,{title:a,className:`min-w-0 flex-1 truncate`,children:a||(e.stage===`running`?`starting`:e.workflowPath)}),j(`span`,{className:`shrink-0`,children:j(z,{startedAt:e.startedAt,endedAt:e.finishedAt,now:n})})]}),t.length>1?j(Qn,{runs:t,selected:e,onSelect:r,className:`max-w-none`}):null]})}function vr({run:e}){let t=Vn(e);if(t===void 0)return null;let n=t.kind===`paused`;return S(`div`,{"data-testid":`workflow-dock-attention`,"data-attention":t.kind,className:A(`mx-3 mt-3 flex flex-col gap-1 rounded-md border px-3 py-2`,n?`border-po-edge-yellow bg-po-tint-yellow/40`:`border-po-edge-red bg-po-tint-red/40`),children:[S(`div`,{className:`flex items-center gap-2`,children:[j(c,{size:`xs`,tone:n?`running`:`error`,children:t.kind}),j(`span`,{className:`min-w-0 flex-1 text-sm text-po-dim`,children:n?`waiting to be resumed`:`needs a look`})]}),j(`span`,{className:`break-words text-base text-po-text`,children:t.text}),j(`span`,{className:`text-sm text-po-dim`,children:n?`ask the agent in this conversation to resume it`:`ask the agent in this conversation to diagnose or recover it`})]})}function yr({run:e,now:t,onOpenStep:n}){let r=Un(e);return r.length===0?null:S(`section`,{"data-testid":`workflow-dock-active`,"aria-label":`active steps`,children:[j(gr,{label:`Active now`,meta:String(r.length)}),j(`div`,{className:`flex flex-col gap-0.5 px-2`,children:r.map(({job:e,step:r})=>{let i=r.status===`paused`||r.status===`pause_requested`;return S(`button`,{type:`button`,"data-testid":`workflow-dock-active-${r.name}`,title:`open ${r.name}`,onClick:()=>n(e,r.name),className:`flex w-full cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-left hover:bg-po-panel`,children:[j(D,{tone:i?`yellow`:`blue`,pulse:!i}),S(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[j(`span`,{className:`truncate text-base font-semibold text-po-hi`,children:r.name}),S(`span`,{className:`truncate text-sm text-po-dim`,children:[e,r.group===void 0?``:` · ∥ ${r.group}`]})]}),j(`span`,{className:`shrink-0 text-sm text-po-dim`,children:j(z,{startedAt:r.startedAt,endedAt:r.endedAt,now:t})})]},`${e}/${r.name}`)})})]})}function br({run:e,now:t,onOpenStep:n,initiallyCollapsed:r=[],current:i}){let[a,o]=b({}),s=(e.children??[]).flatMap(({lead:e,invocations:t})=>t.map(t=>({lead:e,child:t,name:`${t.job}:${t.invocationId}`}))),c=new Set(s.map(({name:e})=>e)),l=e.jobs.filter(e=>!c.has(e.name)),u=l.filter(e=>e.status===`completed`||e.status===`skipped`).length,d=new Set,f=t=>{d.has(t)||(d.add(t),e.jobs.some(e=>e.name===t)&&s.filter(({lead:e})=>e===t).forEach(e=>f(e.name)))};l.forEach(e=>f(e.name));let p=(c,l=[],u=c.name)=>{if(l.includes(c.name))return S(`p`,{className:`px-2 text-sm text-po-red`,children:[`Cyclic child ownership: `,c.name]},c.name);let d=s.filter(({lead:e})=>e===c.name),f=a[c.name]??(i?.job===c.name||!r.includes(c.name)),m=Xn[c.status];return S(`div`,{className:`flex flex-col`,children:[S(`button`,{type:`button`,"data-testid":`job-row-${c.name}`,"data-job-status":c.status,"aria-expanded":f,title:`${c.name}: ${c.status}`,onClick:()=>o(e=>({...e,[c.name]:!f})),className:`flex w-full cursor-pointer items-center gap-2 rounded px-2 py-2 text-left hover:bg-po-panel focus-visible:outline focus-visible:outline-2 focus-visible:outline-po-green`,children:[j(f?Te:Ce,{className:`h-3 w-3 shrink-0 text-po-dim`}),j(`span`,{"aria-hidden":`true`,className:`w-3 shrink-0 ${m.className}`,children:m.glyph}),j(`span`,{className:`min-w-0 flex-1 truncate text-base font-semibold text-po-hi`,children:u}),j(`span`,{className:c.status===`failed`?`shrink-0 text-sm text-po-red`:`shrink-0 text-sm text-po-dim`,children:c.status})]}),f?S(`div`,{className:`ml-4 border-l border-po-border-soft pl-1`,children:[c.reason===void 0?null:j(`p`,{className:A(`px-2 text-sm`,c.status===`failed`?`text-po-red`:`text-po-dim`),children:c.reason}),c.steps.map(e=>j($n,{step:e,now:t,selected:!1,here:i?.job===c.name&&i.step===e.name,onSelect:()=>n(c.name,e.name),note:e.ref?.kind===`session`?j(Sn,{stepSessionId:e.ref.id}):void 0},e.name)),d.length===0?null:S(`section`,{"aria-label":`Child jobs of ${c.name}`,children:[S(`h3`,{className:`flex items-center justify-between px-2 pb-1 pt-3 text-sm font-medium text-po-dim`,children:[j(`span`,{children:`Child jobs`}),j(`span`,{children:d.length})]}),d.map(({child:t,name:n},r)=>S(`div`,{"data-child-invocation":t.invocationId,title:n,children:[s.filter(e=>e.name===n).length>1?S(`p`,{className:`px-2 text-sm text-po-red`,children:[`Duplicate child identity: `,n,`. Recorded parent: `,c.name,`.`]}):null,e.jobs.filter(e=>e.name===n).map(e=>p(e,[...l,c.name],t.job)),e.jobs.some(e=>e.name===n)?null:S(`p`,{className:`px-2 text-sm text-po-dim`,children:[n,`: `,t.state,`. No progress recorded.`]}),(t.state===`failed`||t.state===`interrupted`)&&e.jobs.some(e=>e.name===n&&e.status!==t.state)?S(`p`,{className:`px-2 text-sm text-po-red`,children:[`Invocation `,n,`: `,t.state,`.`]}):null,t.error===void 0?null:j(`p`,{className:`px-2 text-sm text-po-red`,children:t.error})]},`${n}/${r}`))]})]}):null]},c.name)};return S(`section`,{"data-testid":`workflow-dock-jobs`,"aria-label":`jobs`,className:`py-3`,children:[S(`div`,{className:`mb-2 flex items-center justify-between px-4`,children:[j(`h2`,{className:`text-lg font-semibold text-po-hi`,children:`Jobs`}),S(`span`,{className:`text-sm text-po-dim`,children:[u,`/`,l.length]})]}),e.jobs.length===0&&s.length===0?j(C,{className:`py-3`,title:`no progress recorded yet`}):null,S(`div`,{className:`px-2`,children:[l.map(e=>p(e)),s.filter(({name:e})=>!d.has(e)).map(({child:t,lead:n,name:r},i)=>S(`div`,{children:[S(`p`,{className:`px-2 text-sm text-po-red`,children:[`Unattached child `,r,`: parent `,n,` is missing or cyclic. State: `,t.state,`.`]}),e.jobs.filter(e=>e.name===r).map(e=>p(e)),t.error===void 0?null:j(`p`,{className:`px-2 text-sm text-po-red`,children:t.error})]},`${r}/${i}`)),e.childStatusErrors?.length?j(`p`,{className:`px-2 text-sm text-po-dim`,children:`Incomplete child hierarchy: journal evidence is unavailable. Unmatched progress is retained in Jobs.`}):null,e.childStatusErrors?.map((e,t)=>S(`p`,{className:`px-2 text-sm text-po-red`,children:[`Child journal`,e.lead===void 0?``:` (${e.lead})`,`: `,e.message]},t))]})]})}function xr({runs:e,run:t,now:n,sessionId:r,onSelectRun:i,onOpenStep:a,onDeleted:o,artifacts:s,current:c}){let[l,u]=b(!1);return S(`div`,{"data-testid":`workflow-dock`,className:`flex h-full min-h-0 flex-1 flex-col`,children:[j(_r,{run:t,runs:e,now:n,onSelectRun:i}),S(`div`,{"data-testid":`workflow-dock-scroll`,className:`min-h-0 flex-1 overflow-y-auto pb-3`,children:[j(vr,{run:t}),j(yr,{run:t,now:n,onOpenStep:a}),j(br,{run:t,now:n,onOpenStep:a,current:c},M(t)),S(`section`,{"data-testid":`workflow-dock-artifacts`,"aria-label":`artifacts`,children:[j(gr,{label:`Artifacts`}),j(`div`,{className:`px-1`,children:s})]})]}),c===void 0?t.stage===`running`?S(`div`,{className:`shrink-0`,children:[j(tr,{run:t,sessionId:r},M(t)),j(`p`,{className:`px-3 pb-2 text-sm text-po-dim`,children:`this session runs the workflow; removing or restarting it stops the run`})]}):j(`div`,{className:`flex shrink-0 border-t border-po-border-soft p-1.5`,children:j(E,{variant:`danger-outline`,size:`xs`,"data-testid":`delete-workflow`,disabled:r===null,onClick:()=>u(!0),className:`w-full`,children:`delete run`})}):j(`p`,{"data-testid":`workflow-dock-viewer-note`,className:`shrink-0 border-t border-po-border-soft px-3 py-2 text-sm text-po-dim`,children:`The workflow session runs this workflow, so stopping or deleting it happens there.`}),r!==null&&l?j(er,{run:t,sessionId:r,onClose:()=>u(!1),onDeleted:()=>{u(!1),o()}}):null]})}function Sr({sessionId:e,openSession:t,openTransientTab:n,holdSessionChannels:r}){let i=x(N.store,t=>N.select(t,e).runs),a=x(N.store,t=>N.select(t,e).parentRuns),o=x(N.store,t=>N.select(t,e).focusedRun),s=be(()=>i.filter(t=>Xe(t,e)),[i,e]),c=s.length===0?We(a,e):void 0,l=c===void 0?s:[c.run],u=l.find(e=>M(e)===o)??l[0];if(bn(r,u===void 0?[]:hr(u)),u===void 0)return j(C,{"data-testid":`workflow-dock-empty`,className:`px-4 py-5`,title:`this session has no workflow run`,description:`a run launched from here shows its jobs, steps and artifacts in this face.`,children:j(E,{variant:`outline`,size:`sm`,"data-testid":`workflow-dock-launch`,onClick:()=>{e!==null&&rr(e)},children:`launch workflow`})});let d=c===void 0?e:null;return j(xr,{runs:l,run:u,sessionId:e,current:c===void 0?void 0:{job:c.job,step:c.step},onSelectRun:t=>{e!==null&&at(e,M(t))},onOpenStep:(e,r)=>Mn(u,e,r,{openSession:t,openTransientTab:n}),onDeleted:()=>{e!==null&&ot(e,M(u))},artifacts:j(Ht,{run:u,sessionId:d,onOpen:e=>n(Bt(u,e,d))},`${M(u)}/${d}`)})}var Cr=t({id:`workflow`,label:`Workflow`,icon:De,order:20,panel:Sr,visibility:{subscribe(e){let t=N.store.subscribe(e);return()=>t.unsubscribe()},isVisible(e){let t=N.select(N.store.state,e);return t.runs.some(t=>Xe(t,e))||We(t.parentRuns,e)!==void 0}}});function wr({workflow:e,job:t,onBack:n}){return S(`div`,{"data-testid":`step-parent-strip`,className:`flex min-w-0 items-center gap-2 rounded-lg border border-po-border-soft bg-po-panel/60 px-3 py-1.5`,children:[j(De,{"aria-hidden":!0,className:`size-4 shrink-0 text-po-dim`}),e===void 0?j(`span`,{className:`min-w-0 flex-1 truncate text-sm text-po-dim`,children:`Step of a workflow run that is no longer available`}):S(`span`,{className:`min-w-0 flex-1 truncate text-sm text-po-dim`,children:[`Step of `,j(`span`,{className:`font-semibold text-po-hi`,children:e}),t===void 0?null:S(O,{children:[` · `,t]})]}),e===void 0||n===void 0?null:j(E,{variant:`link`,size:`sm`,"data-testid":`step-parent-back`,onClick:n,className:`h-auto shrink-0 px-0 text-po-text`,children:`Back to run`})]})}function Tr({sessionId:e,sessionContext:t,openSession:n,holdSessionChannels:r}){let i=e!==null&&t?.provenance===`workflow`,a=i?t.parentSessionId:void 0;w(()=>{if(r===void 0)return;let t=[e,a].flatMap(e=>!i||e==null?[]:[r(e,t=>{if(t.type!==ct.channel)return;let n=ct.parse(t.payload);n!==null&&ct.apply(e,n)})]);return()=>t.forEach(e=>e())},[i,e,a,r]);let o=x(N.store,t=>N.select(t,e).parentRuns),s=x(N.store,e=>N.select(e,a??null).runs),c=i?We(s,e)?.run:void 0,l=We(o,e);w(()=>{e!==null&&c!==void 0&&l===void 0&&N.update(e,e=>({...e,parentRuns:[c]}))},[e,c,l]);let u=i&&l===void 0&&c===void 0;w(()=>{if(!u||e===null)return;let t=!0;return Et(e).then(n=>{t&&n!==void 0&&N.update(e,e=>e.parentRuns?.length?e:{...e,parentRuns:n})}).catch(()=>void 0),()=>{t=!1}},[u,e]);let d=x(N.store,t=>e!==null&&e in t||a!==void 0&&a in t);if(!i)return null;let f=l??We(c===void 0?[]:[c],e);if(f===void 0)return d?j(wr,{}):null;let p=f.run.ownerSessionId??t.parentSessionId;return j(wr,{workflow:f.run.displayName,job:f.jobLabel,onBack:p===void 0||n===void 0?void 0:()=>{at(p,M(f.run)),n(p)}})}var Er=g({component:Tr}),Dr=g({data:{version:1,label:`Workflows`,source:`workflow_runs`,destination:`workflows`,icon:De}}),Or=`workflows-runs`,kr={running:`info`,paused:`running`,failed:`error`,done:`ok`};function Ar(e,t,n){!Xe(e,t)&&e.ownerSessionId!==void 0&&n.openSession?n.openSession(e.ownerSessionId):(at(t,M(e)),e.position!==void 0&&Mn(e,e.position.job,e.position.step,n))}function jr({run:e,sessionId:t,delegated:n,onOpen:r,onDelete:i,onOpenOwner:a,onRecover:o}){let s=e.executionState===`paused`||e.executionState===`pause_requested`,[c,l]=b(!1),[u,d]=b(),f=e.routeKey??e.runKey,p=e=>{e.error!==void 0&&d(e.error)};return S(O,{children:[u?j(`span`,{role:`alert`,"data-testid":`workflow-menu-error-${e.runKey}`,title:u,className:`min-w-0 truncate text-sm text-po-red`,children:u}):null,S(Fe,{children:[j(he,{asChild:!0,children:j(E,{variant:`ghost`,size:`icon`,"data-testid":`workflow-menu-${e.runKey}`,title:`what this run can do`,"aria-label":`workflow actions`,onClick:e=>e.stopPropagation(),children:j(ze,{className:`h-3 w-3`})})}),S(xe,{"data-testid":`workflow-menu-content-${e.runKey}`,children:[j(k,{"data-testid":`workflow-open-${e.runKey}`,onSelect:r,children:n?`open workflow session`:e.position?`open current step`:`show in workflow dock`}),j(k,{"data-testid":`workflow-folder-${e.runKey}`,onSelect:()=>{d(void 0),Tt(e.workspace,f,t).then(p)},children:`open run folder`}),a&&e.stage===`running`?j(k,{"data-testid":`workflow-pause-resume-${e.runKey}`,onSelect:a,children:s?`resume in its session`:`pause in its session`}):null,Jn(e)?j(k,{"data-testid":`workflow-recover-${e.runKey}`,onSelect:o,children:`recover with the agent`}):null,j(Ie,{}),e.stage===`running`?j(k,{variant:`destructive`,"data-testid":`workflow-stop-${e.runKey}`,disabled:c,onSelect:()=>{l(!0),d(void 0),wt(e.workspace,f,t).then(e=>{`error`in e&&(l(!1),d(e.error))})},children:c?`stopping…`:`stop`}):j(k,{variant:`destructive`,"data-testid":`workflow-delete-${e.runKey}`,onSelect:i,children:`delete`})]})]})]})}function Mr({run:e,sessionId:t,now:n,onOpen:r,onDelete:i,onOpenOwner:a,onRecover:o}){let s=Gn(e),l=Hn(e),u=Vn(e),d=!Xe(e,t),f=[e.position?.job,e.position?.step].filter(Boolean).join(` › `);return j(ce,{asChild:!0,className:A(`flex min-w-0 flex-col text-left transition-colors outline-none hover:border-po-blue/50 focus-within:border-po-blue`,Le[kr[s]]),children:S(`div`,{"data-testid":`workflow-card-${e.runKey}`,"data-run-filter":s,children:[S(`div`,{role:`button`,tabIndex:0,"data-testid":`workflow-open-card-${e.runKey}`,className:`flex min-w-0 cursor-pointer flex-col gap-1 px-3 pt-2.5 pb-2 outline-none`,onClick:r,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())},children:[S(`div`,{className:`flex min-w-0 items-center gap-2`,children:[j(D,{tone:Zn(e),pulse:s===`running`}),j(`span`,{title:e.displayName,className:`min-w-0 flex-1 truncate text-base font-semibold text-po-hi`,children:e.displayName}),j(c,{size:`xs`,tone:kr[s],"data-testid":`workflow-card-state`,children:l})]}),S(`div`,{className:`flex min-w-0 items-center gap-2 text-sm text-po-dim`,children:[j(`span`,{title:f||e.workflowPath,className:`min-w-0 flex-1 truncate`,children:f||(e.stage===`running`?`starting`:e.workflowPath)}),j(`span`,{className:`shrink-0`,children:j(z,{startedAt:e.startedAt,endedAt:e.finishedAt,now:n})})]}),e.prompt?j(`span`,{className:`truncate text-sm text-po-text`,children:e.prompt}):null,u?j(`span`,{"data-testid":`workflow-card-attention`,title:u.text,className:A(`truncate text-sm`,u.kind===`error`?`text-po-red`:`text-po-yellow`),children:u.text}):null]}),S(`div`,{className:`flex shrink-0 items-center gap-3 border-t border-po-border-soft px-3 py-1.5`,children:[S(`span`,{className:`truncate text-sm text-po-dim`,children:[e.jobs.length===0?`no progress yet`:`${e.jobs.filter(e=>e.status===`completed`||e.status===`skipped`).length}/${e.jobs.length} jobs`,d?` · own session`:``,e.worktreeBranch?` · ${e.worktreeBranch}`:``]}),j(`span`,{className:`min-w-0 flex-1`}),j(jr,{run:e,sessionId:t,delegated:d,onOpen:r,onDelete:i,onOpenOwner:a,onRecover:o})]})]})})}function Nr({sessionId:e,openSession:t,openTransientTab:n,sendSessionFrame:r,now:i}){let a=x(N.store,t=>N.select(t,e).runs),[o,s]=b(`all`),[c,l]=b(``),[u,d]=b(),f=be(()=>[...a].sort((e,t)=>Kn(e)-Kn(t)),[a]),p=be(()=>{let e={all:a.length,running:0,paused:0,failed:0,done:0};for(let t of a)e[Gn(t)]+=1;return e},[a]),m=c.trim().toLowerCase(),h=f.filter(e=>(o===`all`||Gn(e)===o)&&qn(e).includes(m));return S(`div`,{"data-testid":`workflows-panel`,className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:[S(`div`,{className:`@container flex min-w-0 flex-1 flex-col overflow-y-auto px-3 py-3 sm:px-[26px] sm:py-[18px]`,children:[S(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 pb-3`,children:[j(`span`,{className:`text-lg font-semibold text-po-hi`,children:`Workflows · this session`}),j(`span`,{className:`min-w-0 flex-1`}),j(E,{variant:`primary`,"data-testid":`workflows-launch`,title:`pick a workflow from the catalog and launch it`,onClick:()=>{e!==null&&rr(e)},children:`Launch workflow`})]}),S(`div`,{className:`flex flex-wrap items-center gap-2 pb-3`,children:[j(`div`,{role:`group`,"aria-label":`filter by status`,className:`flex flex-wrap gap-1`,children:Wn.map(e=>{let t=o===e;return S(E,{variant:`ghost`,size:`xs`,"aria-pressed":t,"data-testid":`workflows-filter-${e}`,onClick:()=>s(e),className:A(t&&`bg-po-blue/25 font-semibold text-po-blue hover:bg-po-blue/25`),children:[e,` `,p[e]]},e)})}),j(oe,{"aria-label":`search workflows`,"data-testid":`workflows-search`,value:c,onChange:e=>l(e.target.value),placeholder:`search workflows…`,className:`ml-auto w-full px-2 py-1 text-sm sm:w-56`})]}),a.length===0?j(C,{"data-testid":`workflows-empty`,className:`py-16`,title:`No workflow runs yet`,description:`Runs this session launches appear here.`}):h.length===0?j(C,{"data-testid":`workflows-no-match`,className:`py-16`,title:`No workflow matches`}):j(`div`,{"data-testid":`workflows-grid`,className:`grid grid-cols-1 gap-3 @2xl:grid-cols-2`,children:e===null?null:h.map(a=>j(Mr,{run:a,sessionId:e,now:i,onOpen:()=>Ar(a,e,{openSession:t,openTransientTab:n}),onDelete:()=>d(a),onOpenOwner:t&&a.ownerSessionId!==void 0&&!Xe(a,e)?()=>t(a.ownerSessionId):void 0,onRecover:()=>{let n=a.ownerSessionId??e;n!==e&&t?.(n),r(n,{type:`prompt`,message:Yn(a)})}},M(a)))})]}),e!==null&&u?j(er,{run:u,sessionId:e,onClose:()=>d(void 0),onDeleted:()=>{ot(e,M(u)),d(void 0)}}):null]})}function Pr(){return{id:Or,label:`Workflows`,panel:Nr}}var Fr=[];function Ir(){return{id:`dynamic-workflow-runs`,label:`Dynamic workflows`,panel:Rr,retainComposer:!0}}function Lr(e){return{id:`dynamic-workflow-agent-${encodeURIComponent(e)}`,label:`Agent transcript`,panel:({renderThread:t})=>j(O,{children:t(e)}),retainComposer:!0}}function Rr({sessionId:e,openTransientTab:t}){let n=x(L.store,t=>L.select(t,e));return j(yn,{runs:n?.runs??Fr,onOpenAgent:n=>{e!==null&&t(Lr(n))}})}var zr={running:`yellow`,paused:`yellow`,failed:`red`,done:`green`,skipped:`muted`},Br={running:`text-po-dim`,paused:`text-po-yellow`,failed:`text-po-red`,done:`text-po-dim`,skipped:`text-po-dim`},Vr={running:`text-po-yellow`,failed:`text-po-red`,successful:`text-po-green`};function Hr({sessionId:e,openSession:t,openTransientTab:n}){let r=x(N.store,t=>N.select(t,e).runs),i=x(L.store,t=>L.select(t,e)?.runs),[a]=b(Date.now),[o,s]=b({}),c=rt(et(r,a,e)),l=S(E,{variant:`link`,size:`sm`,"data-testid":`activity-workflow-launch`,className:`h-auto gap-1 self-start px-0 text-po-green`,onClick:()=>{e!==null&&rr(e)},children:[`Launch a workflow`,j(h,{"aria-hidden":!0,className:`size-3.5`})]}),u=i===void 0||i.length===0?null:S(`div`,{"data-testid":`activity-dynamic-workflows`,className:`flex flex-col gap-0.5`,children:[j(`span`,{className:`px-1 py-0.5 text-sm font-semibold text-po-hi`,children:`Dynamic`}),j(gn,{runs:i,onOpen:()=>n(Ir())})]});if(c.length===0&&u===null)return S(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1`,children:[j(`p`,{"data-testid":`activity-summary-workflows`,className:`text-sm text-po-dim`,children:`Idle`}),l]});let d=({row:n})=>{let r=n.ownerSessionId!==void 0&&t!==void 0;return S(E,{variant:`ghost`,size:`card`,"data-testid":`activity-workflow-${n.runKey}`,"data-run-tone":n.tone,"data-delegated":r,title:r?`open its workflow session`:`show this run in the workflow dock`,onClick:()=>{n.ownerSessionId!==void 0&&t!==void 0?t(n.ownerSessionId):e!==null&&at(e,n.identity)},className:`min-w-0 gap-0.5 rounded-md px-1 py-1 hover:bg-po-panel`,children:[S(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[j(D,{tone:zr[n.tone],pulse:n.tone===`running`}),j(`span`,{className:`min-w-0 flex-1 truncate text-base font-semibold ${n.tone===`running`||n.tone===`paused`?`text-po-hi`:`text-po-dim`}`,children:n.name}),j(`span`,{className:`shrink-0 text-sm text-po-dim`,children:j(z,{startedAt:n.startedAt,endedAt:n.finishedAt})})]}),j(`span`,{className:`truncate pl-3 text-sm ${Br[n.tone]}`,children:n.detail})]})};return S(`div`,{"data-testid":`activity-workflow-runs`,className:`flex flex-col gap-0.5`,children:[c.map(e=>{let t=o[e.name]??e.openByDefault;return S(`div`,{className:`flex flex-col gap-0.5`,children:[S(E,{variant:`ghost`,size:`xs`,"data-testid":`activity-workflow-group-${e.name}`,"data-open":t,"aria-expanded":t,onClick:()=>s(n=>({...n,[e.name]:!t})),className:`justify-start gap-1.5 rounded-md px-1 py-0.5 hover:bg-po-panel`,children:[j(t?Te:Ce,{className:`h-2.5 w-2.5 text-po-faint`}),j(`span`,{className:`inline-block text-sm font-semibold first-letter:uppercase ${Vr[e.name]}`,children:e.name}),j(`span`,{className:`text-2xs text-po-faint`,children:e.rows.length})]}),t?j(`div`,{className:`flex flex-col gap-0.5 pl-2`,children:e.rows.map(e=>j(d,{row:e},e.identity))}):S(`span`,{className:`truncate pl-5 text-sm text-po-dim`,children:[e.rows.slice(0,2).map(e=>e.name).join(`, `),e.rows.length>2?`, and ${e.rows.length-2} more`:``]})]},e.name)}),u,j(`div`,{className:`pt-1.5 pl-1`,children:l})]})}var Ur=6,Wr=8,Gr=[`list_workflows`,`workflow_requirements`,`launch_workflow`,`workflow_run`,`workflow_tools`,`scaffold_workflow`];function Kr(e){return Gr.includes(e)?e:`workflow_run`}function H(e){if(e&&typeof e==`object`&&!Array.isArray(e))return e}function qr(e){let t=``;for(let n of e){let e=n.codePointAt(0)??0;t+=e<=31||e===127?` `:n}return t.replace(/\s+/gu,` `).trim()}function U(e,t){let n=e?.[t];if(typeof n==`string`)return qr(n)||void 0}function W(e,t){let n=e?.[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function G(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}function Jr(e,t){let n=e?.[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function Yr(e){if(e)try{return H(JSON.parse(e))}catch{return}}function Xr(e){return e?e.content.flatMap(e=>{let t=H(e);return t?.type===`text`&&typeof t.text==`string`?[t.text]:[]}):[]}function Zr(e){return Xr(e).flatMap(e=>e.split(`
7
- `)).map(e=>e.trimEnd()).filter(e=>e.length>0)}function Qr(e){return Yr(Xr(e)[0])}function K(e,t,n=`${t}s`){return e===1?t:n}function q(e,t,n={}){return{text:e,tone:t,...n}}function J(e,t){return q(`${e} ${t}`,`text`)}function $r(e){return q(`… ${e} more`,`dim`)}function ei(e){let t=U(e,`runKey`);if(!t)return;let n=U(e,`workspace`);return n?`${n}/${t}`:t}function ti(e,t){return e===`list_workflows`?`list`:e===`workflow_requirements`?`requirements`:e===`launch_workflow`?`launch`:e===`scaffold_workflow`?`scaffold`:U(t,`action`)??`run`}function ni(e,t){return e===`list_workflows`?U(t,`directory`):e===`launch_workflow`||e===`workflow_requirements`?U(t,`workflowPath`):e===`scaffold_workflow`?U(t,`path`):ei(t)}function ri(e){return e.replace(`T`,` `).replace(/\.\d{3}Z$/,`Z`)}function ii(e){if(!e)return`workflow`;let t=e.split(`/`).at(-1)??e;return t.replace(/\.workflow\.ya?ml$/u,``)||t}function ai(e,t){let n=[];if(e===`list_workflows`){let e=W(t,`page`),r=W(t,`pageSize`);e!==void 0&&n.push(`page ${e}`),r!==void 0&&n.push(`${r}/page`),U(t,`filter`)&&n.push(`filtered`);let i=Jr(t,`tags`);i.length>0&&n.push(`${i.length} ${K(i.length,`tag`)}`)}else if(e===`launch_workflow`){let e=U(t,`job`),r=U(t,`runner`),i=U(t,`workspace`),a=Object.keys(H(t.inputs)??{}).length,o=Object.keys(H(t.env)??{}).length;i&&n.push(`workspace ${i}`),e&&n.push(`job ${e}`),r&&n.push(`runner ${r}`),G(t,`dryRun`)&&n.push(`dry run`),U(t,`prompt`)&&n.push(`with prompt`),a>0&&n.push(`${a} ${K(a,`input`)}`),o>0&&n.push(`${o} env`)}else e===`scaffold_workflow`?G(t,`force`)&&n.push(`overwrite allowed`):(U(t,`expectedRunId`)&&n.push(`generation checked`),U(t,`reason`)&&n.push(`with reason`),G(t,`dryRun`)&&n.push(`dry run`),U(t,`job`)&&n.push(`job override`),U(t,`runner`)&&n.push(`runner override`));return n}function oi(e,t){let n=ni(e,t);return{action:ti(e,t),...n===void 0?{}:{target:n},metadata:ai(e,t)}}function si(e){if(!Array.isArray(e?.workflows))return;let t=e.workflows.flatMap(e=>{let t=H(e),n=U(t,`path`);return!t||!n?[]:[{description:U(t,`description`)??``,name:U(t,`name`)??``,path:n,tags:Jr(t,`tags`)}]}),n=Array.isArray(e.tags)?e.tags.flatMap(e=>{let t=H(e),n=U(t,`tag`),r=W(t,`count`);return n&&r!==void 0?[{count:r,tag:n}]:[]}):[],r=U(e,`directory`);return{...r===void 0?{}:{directory:r},page:W(e,`page`)??1,pageSize:W(e,`pageSize`)??t.length,tags:n,total:W(e,`total`)??t.length,totalPages:W(e,`totalPages`)??+(t.length>0),workflows:t}}function ci(e,t){let n=[q(`› ${e.name||ii(e.path)} · ${e.path}`,`text`)];return t&&(e.description&&n.push(q(e.description,`muted`,{indent:!0})),e.tags.length>0&&n.push(q(`tags ${e.tags.join(`, `)}`,`dim`,{indent:!0}))),n}function li(e,t){let n=si(Qr(e));if(!n)return;let r=`page ${n.page}/${n.totalPages}`,i=q(`${n.total>0?`✓`:`○`} ${n.total} ${K(n.total,`workflow`)} · ${r}`,`hi`,{bold:!0}),a=t.expanded?n.workflows:n.workflows.slice(0,Ur),o=[i,...a.flatMap(e=>ci(e,t.expanded))],s=n.workflows.length-a.length;if(s>0&&o.push($r(s)),t.expanded){if(n.tags.length>0){let e=n.tags.map(({count:e,tag:t})=>`${t} (${e})`).join(`, `);o.push(J(`available tags`,e))}n.directory&&o.push(J(`directory`,n.directory)),o.push(J(`page size`,String(n.pageSize)))}return o}function ui(e){let t=U(e,`effectiveStage`)??U(e,`stage`)??`unknown`,n=U(e,`effectiveOutcome`)??U(e,`outcome`),r=U(e,`executionState`);return n===`interrupted`?{tone:`warning`,glyph:`!`,label:`interrupted`}:t===`error`||n===`failed`?{tone:`error`,glyph:`✗`,label:`failed`}:t===`completed`&&n===`skipped`?{tone:`muted`,glyph:`○`,label:`skipped`}:t===`completed`?{tone:`success`,glyph:`✓`,label:`completed`}:r===`paused`?{tone:`warning`,glyph:`Ⅱ`,label:`paused`}:r===`pause_requested`?{tone:`warning`,glyph:`◐`,label:`pause requested`}:r===`resume_requested`?{tone:`warning`,glyph:`◐`,label:`resume requested`}:t===`running`?{tone:`accent`,glyph:`◐`,label:`running`}:{tone:`muted`,glyph:`○`,label:t}}function di(e){let t=H(e.position),n=H(e.executionCursor),r=U(t,`job`)??U(n,`job`)??U(e,`job`),i=U(t,`step`)??U(n,`stepName`),a=U(n,`phase`);if(r||i||a)return q(`[${r??a??`workflow`}] ${i??a??`current job`}`,`text`,{indent:!0})}function fi(e){let t=H(e.launcher),n=U(t,`type`);if(!n)return;let r=U(t,`sessionName`)??U(t,`workspaceId`);return r?`${n} ${r}`:n}function pi(e,t){let n=U(e,`runKey`),r=U(e,`stage`);if(!n||!r)return;let i=ui(e),a=[q(`Status retrieved · ${U(e,`displayName`)??n} · workflow: ${i.label}`,i.tone,{bold:!0}),J(`workspace`,U(e,`workspace`)??`unknown`),J(`runKey`,n)],o=di(e);o&&a.push(o);let s=U(e,`errorMessage`)??U(e,`failureReason`);s&&a.push(q(`error ${s}`,`error`));let c=U(e,`staleReason`);c&&a.push(q(`stale ${c}`,`warning`));let l=U(e,`startedAt`),u=W(e,`exitCode`),d=[U(e,`runner`)?`runner ${U(e,`runner`)}`:void 0,G(e,`dryRun`)?`dry run`:void 0,u===void 0?void 0:`exit ${u}`,l?`started ${ri(l)}`:void 0].filter(e=>!!e);if(d.length>0&&a.push(q(d.join(` · `),`dim`)),!t)return a;let f=U(e,`finishedAt`),p=U(e,`activeRepairId`),m=[[`workflow`,U(e,`workflowPath`)],[`workflow id`,U(e,`workflowId`)],[`run id`,U(e,`runId`)],[`launcher`,fi(e)],[`job`,U(e,`job`)],[`outcome`,U(e,`effectiveOutcome`)??U(e,`outcome`)],[`finished`,f?ri(f):void 0],[`pid`,W(e,`pid`)?.toString()],[`repair`,p?`#${p}`:void 0],[`worktree`,U(e,`worktreeBranch`)??U(e,`worktreePath`)]];for(let[e,t]of m)t&&a.push(J(e,t));let h=e.jobs;if(Array.isArray(h))for(let e of h){let t=H(e),n=U(t,`name`),r=U(t,`status`);if(n&&r&&(a.push(J(`job`,`${n} · ${r}`)),Array.isArray(t?.steps)))for(let e of t.steps){let t=H(e),n=U(t,`name`),r=U(t,`status`);n&&r&&a.push(q(`step ${n} · ${r}`,`text`,{indent:!0}))}}return a}function mi(e,t){let n=Qr(e);if(n)return pi(n,t.expanded)}function hi(e){return U(H(e?.request),`requestedAt`)??U(e,`requestedAt`)}function gi(e,t,n,r){let i=Qr(n),a=ei(t)??U(i,`runKey`)??`workflow`,o=U(i,`workspace`),s=[q(`◐ ${e} requested · ${o&&!a.includes(`/`)?`${o}/${a}`:a}`,`warning`,{bold:!0})],c=hi(i);return c&&s.push(J(`requested`,ri(c))),r.expanded&&s.push(q(`verify the transition with workflow_run status`,`dim`)),s}function _i(e,t){return e.match(t)?.[1]?.trim()}function vi(e,t){let n=_i(e,/^Started (.+) in workspace .+\.$/mu),r=_i(e,/^Started .+ in workspace (.+)\.$/mu)??U(t,`workspace`),i=_i(e,/^Run key:\s*(.+)$/mu),a=U(t,`workflowPath`),o=n??ii(a),s=i?r?`${r}/${i}`:i:r??a??`workflow`;return/Workflow completed successfully/iu.test(e)?{name:o,scope:s,state:{tone:`success`,glyph:`✓`,label:`completed`}}:/Workflow skipped/iu.test(e)?{name:o,scope:s,state:{tone:`muted`,glyph:`○`,label:`skipped`}}:/no run was registered/iu.test(e)?{name:o,scope:s,state:{tone:`warning`,glyph:`◐`,label:`starting · run key pending`}}:{name:o,scope:s,state:{tone:`accent`,glyph:`◐`,label:i?`started`:`launch accepted`}}}function yi(e,t,n){let r=vi(Xr(t).join(`
8
- `),e),i=[q(`${r.state.glyph} ${r.name} · ${r.scope} · ${r.state.label}`,r.state.tone,{bold:!0})],a=[U(e,`job`)?`job ${U(e,`job`)}`:void 0,U(e,`runner`)?`runner ${U(e,`runner`)}`:void 0,G(e,`dryRun`)?`dry run`:void 0].filter(e=>!!e);if(a.length>0&&i.push(q(a.join(` · `),`dim`)),n.expanded){let e=Zr(t).filter(e=>!e.startsWith(`Next steps for the agent:`));i.push(...e.map(e=>q(e,`text`)))}return i}function bi(e){let t=[],n;for(let r of e.split(`
9
- `)){let e=r.match(/^--- (.+) ---$/u);e?.[1]?(n={body:[],name:e[1]},t.push(n)):n?.body.push(r)}return t}function xi(e,t,n){let r=bi(Xr(t).join(`
10
- `)),i=Yr(r.find(e=>e.name===`run.json`)?.body.join(`
11
- `)),a=i?pi(i,n.expanded):void 0,o=r.filter(e=>e.name!==`run.json`),s=ei(e)??`workflow`,c=a??[q(`✓ recovery evidence · ${s}`,`success`,{bold:!0})],l=o.map(e=>e.name);if(c.push(l.length>0?J(`evidence`,l.join(`, `)):q(`no durable evidence files recorded`,`muted`)),n.expanded)for(let e of o)c.push(q(e.name,`hi`,{bold:!0})),c.push(...e.body.filter(e=>e.length>0).map(e=>q(e,`text`)));return c}function Si(e,t,n,r){let i=ei(t)??`workflow`,a={follow:`following output`,open:`launcher opened`,recover:G(t,`dryRun`)?`recovery dry run finished`:`recovery accepted`,tail:`launcher output checked`},o=e===`recover`?{tone:`accent`,glyph:`◐`,label:a[e]??e}:{tone:`success`,glyph:`✓`,label:a[e]??e},s=[q(`${o.glyph} ${o.label} · ${i}`,o.tone,{bold:!0})],c=Zr(n);if(e===`tail`){let e=c.find(e=>e.startsWith(`Workflow:`)),t=c.find(e=>e.startsWith(`Stage:`));e&&s.push(q(e,`text`)),t&&s.push(q(t,`text`))}return r.expanded&&s.push(...c.map(e=>q(e,`text`))),s}function Ci(e,t,n,r){let i=ti(e,t),a=ni(e,t),o=Zr(n),s=r.expanded?o:o.slice(0,Wr),c=[q(e===`workflow_run`&&i===`status`?`✗ Status lookup failed${a?` · ${a}`:``}`:`✗ ${i} failed${a?` · ${a}`:``}`,`error`,{bold:!0}),...s.length>0?s.map(e=>q(e,`text`)):[q(`Unknown workflow error`,`error`)]],l=o.length-s.length;return l>0&&c.push($r(l)),c}function wi(e,t,n){let r=Zr(n),i=r.slice(-4),a=ti(e,t),o=ni(e,t),s=r.length-i.length,c=[q(`◐ ${a}${o?` · ${o}`:``}`,`accent`,{bold:!0})];return s>0&&c.push(q(`… ${s} earlier`,`dim`)),c.push(...i.map(e=>q(e,`text`))),c}function Ti(e,t){let n=Zr(e);if(n.length===0)return[q(`No workflow output.`,`muted`)];let r=t.expanded?n:n.slice(0,Wr),i=r.map(e=>q(e,`text`)),a=n.length-r.length;return a>0&&i.push($r(a)),i}function Ei(e,t,n,r){if(r.isPartial)return wi(e,t,n);if(r.isError)return Ci(e,t,n,r);if(e===`list_workflows`)return li(n,r)??Ti(n,r);if(e===`launch_workflow`)return yi(t,n,r);let i=U(t,`action`);return i===`status`?mi(n,r)??Ti(n,r):i===`pause`||i===`resume`||i===`stop`?gi(i,t,n,r):i===`recovery-evidence`?xi(t,n,r):i===`follow`||i===`open`||i===`recover`||i===`tail`?Si(i,t,n,r):Ti(n,r)}function Di(e,t=``){let n=(Xr(e).join(`
12
- `)||t).trim();return U(Yr(n),`error`)||n||`Unknown workflow error`}function Oi(e){try{return JSON.parse(e)}catch{return}}function ki(e){if(!Array.isArray(e))return;let t=e.flatMap(e=>{let t=H(e),n=U(t,`runKey`);if(!n)return[];let r=U(t,`workspace`),i=U(t,`failedJob`),a=U(t,`updatedAt`),o=U(t,`outcome`)??`failed`,s=[r?`${r}/${n}`:n,i?`job ${i}`:void 0,a?ri(a):void 0].filter(e=>!!e);return[{key:`${r??``}/${n}`,title:U(t,`displayName`)??n,detail:s.join(` · `),chip:{label:o,tone:o===`interrupted`?`yellow`:`red`}}]});if(t.length===e.length)return{headline:t.length===0?`No failed runs`:`${t.length} failed ${K(t.length,`run`)}`,facts:[],rows:t,...t.length>0?{note:`Read recovery-evidence before recover.`}:{}}}function Ai(e){if(typeof e==`string`)return qr(e)||void 0;if(typeof e==`number`&&Number.isFinite(e))return String(e);if(typeof e==`boolean`)return e?`yes`:`no`}function ji(e){if(Array.isArray(e)){let t=e.map((e,t)=>{let n=H(e),r=Object.values(n??{}).flatMap(e=>Ai(e)??[]),i=Ai(e)??r[0]??`item ${t+1}`,a=r.slice(1).join(` · `);return{key:String(t),title:i,...a?{detail:a}:{}}});return{headline:`${t.length} ${K(t.length,`item`)}`,facts:[],rows:t}}let t=H(e)??{},n=Object.entries(t).flatMap(([e,t])=>{let n=Ai(t);if(n!==void 0)return[{label:e,value:n}];if(Array.isArray(t))return[{label:e,value:`${t.length} ${K(t.length,`item`)}`}];let r=H(t);if(r){let t=Object.keys(r).length;return[{label:e,value:`${t} ${K(t,`field`)}`}]}return[]});return{headline:n.length===0?`No details returned`:`Result`,facts:n,rows:[]}}function Mi(e,t,n){let r=Xr(n).join(`
13
- `).trim();if(!r.startsWith(`{`)&&!r.startsWith(`[`))return;let i=Oi(r);if(i===void 0)return;let a=U(t,`action`);if(e===`workflow_tools`&&a===`list-failed`)return ki(i)??ji(i);let o=H(i);if(!(e===`list_workflows`&&si(o))&&e!==`launch_workflow`&&!(a===`status`&&o&&pi(o,!1))&&a!==`pause`&&a!==`resume`&&a!==`stop`)return ji(i)}var Ni=new Set([`list_workflows`,`workflow_run`,`workflow_tools`]);function Pi({view:e,expanded:t}){return S(`div`,{className:`flex flex-col gap-3`,children:[j(`span`,{className:`font-semibold text-po-hi`,children:e.headline}),t&&e.facts.length>0?j(`dl`,{className:`flex flex-wrap gap-x-6 gap-y-2`,children:e.facts.map(e=>S(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[j(`dt`,{children:j(ke,{children:e.label})}),j(`dd`,{className:`truncate font-mono text-sm text-po-text`,children:e.value})]},e.label))}):null,t&&e.rows.length>0?j(`ul`,{className:`flex flex-col gap-2`,children:e.rows.map(e=>S(`li`,{className:`flex min-w-0 items-center gap-3`,children:[j(`span`,{className:`shrink-0 text-po-text`,children:e.title}),e.detail===void 0?j(`span`,{className:`flex-1`}):j(`span`,{className:`min-w-0 flex-1 truncate text-sm text-po-faint`,children:e.detail}),e.chip===void 0?null:j(T,{tone:e.chip.tone,size:`xs`,className:`shrink-0`,children:e.chip.label})]},e.key))}):null,t&&e.note!==void 0?j(`span`,{className:`text-sm text-po-faint`,children:e.note}):null]})}function Fi({toolName:e,args:t,result:n,output:r,running:i,isError:s}){let c=Kr(e),u=oi(c,t),d=[u.target,...u.metadata].filter(e=>e!==void 0),f=s&&!i&&Ni.has(c),p=i||s?void 0:Mi(c,t,n),m=Ei(c,t,n,{expanded:!1,isError:s,isPartial:i}),h=Ei(c,t,n,{expanded:!0,isError:s,isPartial:i}),g=f?!1:p===void 0?h.length>m.length:p.facts.length+p.rows.length>0||p.note!==void 0;return j(v,{tone:o({running:i,isError:s}),expandable:g,children:({expanded:t})=>S(O,{children:[j(l,{title:e,children:S(`span`,{"data-testid":`tool-call-${e}`,className:`flex min-w-0 flex-1 items-center gap-2`,children:[j(`span`,{className:`shrink-0 font-semibold text-po-hi`,children:u.action}),d.length>0?j(`span`,{className:`min-w-0 truncate text-po-dim`,children:d.join(` · `)}):null]})}),f?j(a,{"data-testid":`tool-result-${e}`,children:j(`p`,{className:`whitespace-pre-wrap break-words text-po-red`,children:Di(n,r)})}):p===void 0?(t?h:m).length>0?j(a,{"data-testid":`tool-result-${e}`,children:j(y,{lines:t?h:m})}):null:j(a,{"data-testid":`tool-result-${e}`,children:j(Pi,{view:p,expanded:t})})]})})}var Y={channels:[ct,fr],contextActions:[{id:`launch-workflow`,label:`Launch Workflow`,detail:`Choose a workflow, review its inputs, then launch it.`,kinds:[`work-item`],order:20,run:e=>ir(e)}],activityGroups:[{name:`workflows`,keys:`w r`,icon:De,widgetKeys:[`workflow-mcp-progress`,`workflow-mcp-follow`],activeSource:{subscribe(e){let t=N.store.subscribe(e),n=L.store.subscribe(e);return()=>{t.unsubscribe(),n.unsubscribe()}},isActive(e){return N.select(N.store.state,e).runs.some(e=>e.stage===`running`)||(L.select(L.store.state,e)?.runs.some(e=>e.status===`running`)??!1)}},order:30,transientTab:Pr}],activitySections:[{id:`workflows`,component:Hr}],toolRenderers:[{tools:[`list_workflows`,`workflow_requirements`,`launch_workflow`,`workflow_run`,`workflow_tools`,`scaffold_workflow`],message:Fi}],leaderBindings:[{id:`po-workflow.catalog`,path:[{key:`w`,label:`workflows`,detail:`multi-step agent runs`},{key:`l`,label:`launch`,detail:`pick a workflow and launch it`}],run:e=>{e.sessionId!==null&&rr(e.sessionId)}}]},Ii=Ee(Y.contextActions[0]),Li=i(Y.activityGroups[0]),Ri=_(cn),zi=_(Y.channels[1]),Bi=_(Y.channels[0]),Vi=`/workflow-launch`,Hi=`runner`,Ui=`command`,Wi=`choice`,Gi=`profile`,Ki=`assign.`;function qi(e){return/\s/.test(e)?`"${e}"`:e}function Ji(e,t){return t===void 0||t===``?[]:[`${e}=${qi(t)}`]}function Yi(e){let t=[...Ji(Hi,e.runner),...Ji(Ui,e.command),...Ji(Wi,e.choice),...Ji(Gi,e.profile),...Object.entries(e.assignments??{}).flatMap(([e,t])=>Ji(`${Ki}${e}`,t)),...Object.entries(e.inputs).filter(([,e])=>e!==``).map(([e,t])=>`${e}=${qi(t)}`)],n=e.prompt?.trim();return[Vi,qi(e.workflow),...t,...n?[`--`,n]:[]].join(` `)}function Xi(e){return Object.fromEntries(e.inputs.map(e=>[e.name,e.default??``]))}function Zi(e){return e.runners?.[0]}function Qi({sessionId:e,workflow:t,initialPrompt:n,send:r,onClose:i,onLaunched:a}){let[o,s]=b(n),[c,l]=b(()=>Zi(t)),u=Me(),f=Me(),p=Me(),m=t.error??(t.runners?.length===0?`This workflow has no compatible runner.`:void 0);return j(Ne,{open:!0,onOpenChange:e=>{e||i()},children:S(de,{width:`lg`,"data-testid":`launch-workflow-dialog`,"aria-describedby":p,children:[j(re,{children:S(_e,{"data-testid":`launch-workflow-name`,children:[`Start `,t.name]})}),S(`form`,{onSubmit:n=>{n.preventDefault(),o.trim()&&m===void 0&&(st(r,e,Yi({workflow:t.relativePath,...c===void 0?{}:{runner:c},inputs:Xi(t),prompt:o.trim()}),t.path),a())},children:[S(d,{children:[j(`p`,{id:p,className:`text-base text-po-dim`,children:t.description||`Tell Po what you want this workflow to do.`}),S(`div`,{className:`flex flex-col gap-2`,children:[j(`label`,{htmlFor:f,className:`text-base font-medium text-po-hi`,children:`Runner`}),j(`select`,{id:f,"data-testid":`launch-runner`,value:c??``,onChange:e=>l(e.target.value),disabled:t.runners===void 0||t.runners.length===0,className:`h-11 w-full rounded-md border border-po-border bg-po-deep px-3 text-base text-po-text focus-visible:outline focus-visible:outline-2 focus-visible:outline-po-green`,children:t.runners===void 0?j(`option`,{value:``,children:`Workflow default`}):t.runners.map(e=>j(`option`,{value:e,children:e},e))})]}),S(`div`,{className:`flex flex-col gap-2`,children:[j(`label`,{htmlFor:u,className:`text-base font-medium text-po-hi`,children:`Prompt`}),j(je,{id:u,"data-testid":`launch-prompt`,rows:5,required:!0,value:o,onChange:e=>s(e.target.value),placeholder:`What would you like this workflow to do?`,className:`text-lg`})]}),m===void 0?null:j(`p`,{role:`alert`,className:`text-base text-po-red`,children:m})]}),S(pe,{className:`px-4 pb-4`,children:[j(E,{type:`button`,variant:`outline`,className:`h-11 px-4`,"data-testid":`launch-cancel`,onClick:i,children:`Cancel`}),j(E,{type:`submit`,variant:`primary`,className:`h-11 px-4`,"data-testid":`launch-submit`,disabled:!o.trim()||m!==void 0,children:`Start workflow`})]})]})]})})}var $i=`INPUT`;function ea({workflow:e}){let t=[[`triggers`,e.triggers.length>0?e.triggers.join(`, `):`none declared`],[`inputs`,e.inputs.length>0?e.inputs.map(e=>`${e.name}${e.required?`*`:``}${e.default?` = ${e.default}`:``}`).join(`, `):`none declared`],[`jobs`,e.jobs.length>0?e.jobs.map(e=>e.name).join(` → `):`none declared`],[`artifacts`,e.artifacts.length>0?e.artifacts.map(e=>e.path).join(`, `):`none declared`],[`runners`,e.runners===void 0?`any runner`:e.runners.join(`, `)||`none in common`],[`file`,e.relativePath]];return j(`dl`,{"data-testid":`catalog-detail-${e.name}`,className:`flex flex-col gap-1 pt-1 text-sm`,children:t.map(([e,t])=>S(`div`,{className:`flex gap-2`,children:[j(`dt`,{className:`w-16 shrink-0 text-po-dim`,children:e}),j(`dd`,{className:`min-w-0 break-words text-po-dim`,children:t})]},e))})}function ta({workflow:e,selected:t,inspected:n,onSelect:i,onLaunch:a,onInspect:o}){let s=e.jobs.length;return S(`div`,{role:`option`,"aria-selected":t,tabIndex:-1,"data-testid":`catalog-workflow-${e.name}`,"data-selected":t,onClick:i,onDoubleClick:a,className:`flex cursor-pointer flex-col gap-1 border-l-2 px-4 py-2 ${t?`border-po-blue bg-po-panel`:`border-transparent hover:bg-po-panel/60`}`,children:[S(`div`,{className:`flex min-w-0 items-center gap-2`,children:[j(`span`,{className:`truncate text-base font-semibold text-po-hi`,children:e.name}),e.tags.map(e=>j(T,{size:`xs`,className:`shrink-0`,children:e},e)),j(`span`,{className:`min-w-0 flex-1`}),j(`span`,{className:`shrink-0 text-sm ${e.error===void 0?`text-po-cyan`:`text-po-red`}`,children:e.error===void 0?`${s} job${s===1?``:`s`}`:`needs fixing`})]}),j(`span`,{className:`truncate text-sm text-po-dim`,children:e.description||e.relativePath}),e.error===void 0?S(`span`,{className:`truncate text-sm text-po-dim`,children:[e.inputs.length,` input`,e.inputs.length===1?``:`s`,` ·`,` `,e.runners===void 0?`any runner`:e.runners.join(`, `)||`no runner in common`,e.artifacts.length>0?` · ${e.artifacts.length} artifacts`:``]}):j(`span`,{className:`truncate text-base text-po-red`,children:e.error}),t?S(`div`,{className:`flex items-center gap-3 pt-0.5`,children:[S(E,{variant:`link`,size:`xs`,"data-testid":`catalog-launch-${e.name}`,className:`px-0`,disabled:e.error!==void 0,onClick:e=>{e.stopPropagation(),a()},children:[`launch `,j(r,{children:`↵`})]}),S(E,{variant:`link`,size:`xs`,"data-testid":`catalog-inspect-${e.name}`,className:`px-0 text-po-dim`,onClick:e=>{e.stopPropagation(),o()},children:[`inspect `,j(r,{children:`i`})]})]}):null,t&&n?j(ea,{workflow:e}):null]})}function na({sessionId:e,onClose:t,onLaunch:n}){let i=x(V.store,t=>V.select(t,e)),a=dr(i.workflows,i.filter),o=a.find(e=>e.path===i.selected)??a[0],s=t=>{if(a.length===0)return;let n=o===void 0?-1:a.findIndex(e=>e.path===o.path),r=a[(n+t+a.length)%a.length];r&&sr(e,r.path)};return S(`aside`,{"data-testid":`workflow-catalog-drawer`,tabIndex:0,onKeyDown:r=>{let i=r.target.tagName===$i;r.key===`ArrowDown`||r.key===`ArrowUp`?(r.preventDefault(),s(r.key===`ArrowDown`?1:-1)):r.key===`Escape`?(r.preventDefault(),t()):o!==void 0&&(r.key===`Enter`?(r.preventDefault(),o.error===void 0&&n(o)):i||r.key===`i`&&cr(e,o.path))},className:`flex w-[min(440px,calc(100vw-24px))] max-w-full shrink-0 flex-col overflow-hidden border-l border-po-border bg-po-rail outline-none`,children:[S(`div`,{className:`flex h-11 shrink-0 items-center gap-2.5 border-b border-po-border px-4`,children:[j(`span`,{className:`text-lg font-semibold text-po-hi`,children:`workflow catalog`}),S(T,{size:`xs`,"data-testid":`catalog-count`,children:[i.workflows.length,` workflow`,i.workflows.length===1?``:`s`]}),j(`span`,{className:`min-w-0 flex-1`}),j(r,{children:`SPC w l`}),j(E,{variant:`ghost`,size:`icon`,"data-testid":`catalog-close`,title:`close the catalog`,onClick:t,children:j(p,{className:`h-3 w-3`})})]}),j(`div`,{className:`px-4 pt-2.5 pb-1.5`,children:j(oe,{"data-testid":`catalog-filter`,value:i.filter,placeholder:`filter by name, tag, or job…`,autoFocus:!0,onChange:t=>or(e,t.target.value)})}),S(`div`,{role:`listbox`,className:`flex min-h-0 flex-1 flex-col overflow-y-auto pb-2`,children:[a.length===0?j(`p`,{"data-testid":`catalog-empty`,className:`px-4 py-3 text-sm text-po-dim`,children:i.warning??(i.workflows.length===0?`no workflows found for this session; add one under automations/workflows`:`nothing matches the filter`)}):null,a.map(t=>j(ta,{workflow:t,selected:o?.path===t.path,inspected:i.inspected===t.path,onSelect:()=>sr(e,t.path),onLaunch:()=>n(t),onInspect:()=>cr(e,t.path)},t.path))]}),S(`div`,{className:`flex h-8 shrink-0 items-center justify-between border-t border-po-border-soft bg-po-deep px-4`,children:[j(`span`,{className:`shrink-0 text-sm text-po-dim`,children:`↑↓ choose · enter launch · i inspect · esc close`}),j(`span`,{className:`min-w-0 truncate font-mono text-sm text-po-dim`,children:i.cwd})]})]})}function ra({sessionId:e,sendSessionFrame:t}){let n=x(V.store,t=>V.select(t,e));if(e===null)return null;let r=n.workflows.find(e=>e.path===n.launch);return S(O,{children:[j(we,{open:n.open,onOpenChange:t=>{t||ar(e)},children:S(te,{side:`right`,width:`md`,"aria-describedby":void 0,className:`border-l-0`,children:[j(m,{className:`sr-only`,children:`workflow catalog`}),j(`div`,{"data-testid":`workflow-launcher-sheet`,className:`flex min-h-0 flex-1`,children:j(na,{sessionId:e,onClose:()=>ar(e),onLaunch:t=>lr(e,t.path)})})]})}),r===void 0?null:j(Qi,{sessionId:e,workflow:r,cwd:n.cwd,initialPrompt:n.prompt,send:t,onClose:()=>ur(e),onLaunched:()=>{ur(e),ar(e)}})]})}var ia=g({component:ra}),aa=g({slot:`activity.workflows`,...Y.activitySections[0]}),oa=ee(Y.leaderBindings[0]),sa=[`workflow_spawn_child`,`workflow_child_status`,`workflow_children`,`workflow_report_criteria`,`workflow_review_artifacts`];function ca(e){return sa.includes(e)}function X(e){if(e&&typeof e==`object`&&!Array.isArray(e))return e}function Z(e,t){let n=e?.[t];if(typeof n==`string`)return n.replace(/\s+/gu,` `).trim()||void 0}function la(e,t){let n=e?.[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function Q(e,t,n=`${t}s`){return e===1?t:n}function ua(e){return e.replace(`T`,` `).replace(/\.\d{3}Z$/u,`Z`)}function da(e){return e?e.content.flatMap(e=>{let t=X(e);return t?.type===`text`&&typeof t.text==`string`?[t.text]:[]}).join(`
14
- `).trim():``}function fa(e){let t=da(e);if(t)try{return{ok:!0,value:JSON.parse(t)}}catch{return{ok:!1}}return e&&e.details!==void 0?{ok:!0,value:e.details}:{ok:!1}}function pa(e){let t=X(e.results);return t?Object.entries(t).flatMap(([e,t])=>{let n=Z(X(t),`status`);return n?[{key:e,status:n}]:[]}):[]}function ma(e,t){if(e===`workflow_spawn_child`){let e=Object.keys(X(t.inputs)??{}).length,n=Z(t,`job`);return{...n===void 0?{}:{primary:n},detail:e>0?[`${e} ${Q(e,`input`)}`]:[]}}if(e===`workflow_child_status`){let e=Z(t,`invocationId`);return{...e===void 0?{}:{primary:e},detail:[]}}if(e===`workflow_report_criteria`){let e=pa(t);if(e.length===0)return{detail:[]};let n=e.filter(e=>e.status===`not-met`).length;return{primary:`${e.length} ${Q(e.length,`criterion`,`criteria`)}`,detail:n>0?[`${n} not met`]:[]}}return{detail:[]}}function ha(e){return e===`workflow_spawn_child`?`Starting the child`:e===`workflow_child_status`?`Reading the child`:e===`workflow_children`?`Reading the children`:e===`workflow_report_criteria`?`Reporting criteria`:e===`workflow_review_artifacts`?`Reading the artifacts`:`Running`}var ga={running:{label:`running`,tone:`blue`},completed:{label:`completed`,tone:`green`},failed:{label:`failed`,tone:`red`},interrupted:{label:`interrupted`,tone:`yellow`}},_a={checked:{label:`checked`,tone:`green`},"not-met":{label:`not met`,tone:`yellow`},unchecked:{label:`unchecked`,tone:`neutral`}};function va(e){return ga[e]??{label:e,tone:`neutral`}}function ya(e){let t=X(e),n=Z(t,`invocationId`),r=Z(t,`job`),i=Z(t,`state`);if(!t||!n||!r||!i)return;let a=Array.isArray(t.sessionIds)?t.sessionIds.filter(e=>typeof e==`string`):[],o=Z(t,`startedAt`),s=Z(t,`endedAt`),c=[{label:`invocation`,value:n}];o&&c.push({label:`started`,value:ua(o)}),s&&c.push({label:`ended`,value:ua(s)}),a.length>0&&c.push({label:`sessions`,value:String(a.length)});let l=Z(t,`error`);return{headline:r,chip:va(i),facts:c,sections:[],...l===void 0?{}:{error:l},...i===`running`?{note:`Check back with childStatus; a started child is not a finished one.`}:{}}}function ba(e){let t=X(e),n=Z(t,`key`),r=Z(t,`status`);if(!n||!r)return;let i=Z(t,`verifiedBy`);return{key:n,title:n,...i===void 0?{}:{detail:`verified by ${i}`},chip:_a[r]??{label:r,tone:`neutral`}}}function xa(e){let t=X(e),n=Z(t,`invocationId`),r=Z(t,`job`),i=Z(t,`state`);if(n&&r&&i)return{key:n,title:r,detail:n,chip:va(i)}}function Sa(e){let t=X(e),n=Z(t,`lead`);if(!t||!n||!Array.isArray(t.criteria)||!Array.isArray(t.invocations))return;let r=t.criteria.flatMap(e=>ba(e)??[]),i=t.invocations.flatMap(e=>xa(e)??[]),a=r.filter(e=>e.chip?.label===`checked`).length,o=la(t,`continuations`),s=la(t,`maxContinuations`),c=[{label:`lead`,value:n}];o!==void 0&&s!==void 0&&c.push({label:`continuations`,value:`${o}/${s}`});let l=[];return r.length>0&&l.push({title:`Criteria`,rows:r}),i.length>0&&l.push({title:`Children`,rows:i}),{headline:r.length>0?`${a}/${r.length} ${Q(r.length,`criterion`,`criteria`)} checked`:`${i.length} ${Q(i.length,`child`,`children`)}`,facts:c,sections:l,...l.length===0?{note:`No children spawned yet.`}:{}}}function Ca(e){let t=pa(e).map(e=>({key:e.key,title:e.key,chip:_a[e.status]??{label:e.status,tone:`neutral`}}));return{headline:`${t.length} ${Q(t.length,`criterion`,`criteria`)} reported`,facts:[],sections:t.length>0?[{title:`Criteria`,rows:t}]:[],note:`The lead reads these on its next look at the children.`}}function wa(e){let t=X(e),n=Z(t,`revision`),r=X(t?.artifacts);if(!n||!r)return;let i=Object.entries(r).map(([e,t])=>{let n=typeof t==`string`&&t.length>0?t.split(`
15
- `).length:0;return{key:e,title:e,detail:`${n} ${Q(n,`line`)}`}});return{headline:`${i.length} ${Q(i.length,`artifact`)}`,facts:[{label:`revision`,value:n}],sections:i.length>0?[{title:`Artifacts`,rows:i}]:[],...i.length===0?{note:`No artifacts recorded for review.`}:{}}}function Ta(e){let t=da(e).split(`
16
- `).map(e=>e.trimEnd()).filter(e=>e.length>0);return{headline:``,facts:[],sections:[],text:t.length>0?t:[`No output.`]}}function Ea(e,t,n){if(e===`workflow_report_criteria`)return Ca(t);let r=fa(n);if(!r.ok)return Ta(n);let i=e===`workflow_spawn_child`||e===`workflow_child_status`?ya(r.value):e===`workflow_children`?Sa(r.value):e===`workflow_review_artifacts`?wa(r.value):void 0;if(i)return i;let a=ji(r.value);return{headline:a.headline,facts:a.facts,sections:a.rows.length>0?[{title:`Items`,rows:a.rows}]:[]}}function Da({text:e,chip:t}){return S(`div`,{className:`flex min-w-0 items-center gap-2`,children:[e?j(`span`,{className:`min-w-0 truncate font-semibold text-po-hi`,children:e}):null,t?j(T,{tone:t.tone,size:`xs`,children:t.label}):null]})}function Oa({facts:e}){return e.length===0?null:j(`dl`,{className:`flex flex-wrap gap-x-5 gap-y-2`,children:e.map(e=>S(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[j(`dt`,{className:`font-semibold text-po-dim text-xs uppercase`,children:e.label}),j(`dd`,{className:`truncate font-mono text-po-text text-sm`,children:e.value})]},e.label))})}function ka({title:e,rows:t}){return S(`div`,{className:`flex flex-col gap-2`,children:[j(`span`,{className:`font-semibold text-po-dim text-xs uppercase`,children:e}),j(`ul`,{className:`flex flex-col gap-1.5`,children:t.map(e=>S(`li`,{className:`flex min-w-0 items-center gap-2`,children:[j(`span`,{className:`min-w-0 truncate text-po-text`,children:e.title}),e.chip?j(T,{tone:e.chip.tone,size:`xs`,children:e.chip.label}):null,e.detail?j(`span`,{className:`min-w-0 truncate text-po-faint text-sm`,children:e.detail}):null]},e.key))})]})}function Aa({toolName:e,args:t,result:n,output:r,running:i,isError:s}){let c=ma(e,t),u=i||s?void 0:Ea(e,t,n),d=u!==void 0&&(u.facts.length>0||u.sections.length>0||u.error!==void 0||u.note!==void 0||(u.text?.length??0)>1);return j(v,{tone:o({running:i,isError:s}),expandable:d,children:({expanded:t})=>S(O,{children:[j(l,{title:e,children:S(`span`,{"data-testid":`tool-call-${e}`,className:`flex min-w-0 flex-1 items-center gap-2`,children:[c.primary?j(`span`,{className:`shrink-0 font-semibold text-po-hi`,children:c.primary}):null,c.detail.map(e=>j(`span`,{className:`min-w-0 truncate text-po-dim`,children:c.primary?`· ${e}`:e},e))]})}),s?j(a,{"data-testid":`tool-result-${e}`,children:j(`div`,{className:`whitespace-pre-wrap break-words text-po-red`,children:Di(n,r)})}):i?j(a,{"data-testid":`tool-result-${e}`,children:j(f,{tone:`running`,children:ha(e)})}):u===void 0?null:u.text?j(a,{"data-testid":`tool-result-${e}`,children:j(`div`,{className:`flex flex-col gap-0.5 text-po-text`,children:(t?u.text:u.text.slice(0,1)).map((e,t)=>j(`div`,{className:`whitespace-pre-wrap break-words`,children:e},`${String(t)}-${e}`))})}):j(a,{"data-testid":`tool-result-${e}`,children:S(`div`,{className:`flex flex-col gap-3`,children:[j(Da,{text:u.headline,chip:u.chip}),t?S(O,{children:[u.error?j(`div`,{className:`whitespace-pre-wrap break-words text-po-red`,children:u.error}):null,j(Oa,{facts:u.facts}),u.sections.map(e=>j(ka,{title:e.title,rows:e.rows},e.title)),u.note?j(`p`,{className:`text-po-faint text-sm`,children:u.note}):null]}):null]})})]})})}var ja=le({tools:[...sa],matches:ca,message:Aa}),Ma=le(Y.toolRenderers[0]),$=(e,t)=>t===void 0?void 0:{...e,...t},Na=Pe({id:`workflows`,packageName:`@agimon-ai/po-workflow`,workspace:{get dockFaces(){return[$({id:`workflow`},Cr)]},get fills(){return[$({slot:`conversation-strip`,id:`step-parent`},Er),$({slot:`home`,id:`workflows`},Dr)]}},session:{get activityGroups(){return[$({name:`workflows`},Li)]},get channels(){return[$({channel:`dynamic_workflow_runs`},Ri),$({channel:`workflow_catalog`},zi),$({channel:`workflow_runs`},Bi)]},get contextActions(){return[$({id:`launch-workflow`},Ii)]},get fills(){return[$({slot:`overlay`,id:`workflow-launcher`},ia),$({slot:`activity.workflows`,id:`workflows`},aa)]},get leaderBindings(){return[$({id:`workflows.catalog`},oa)]},get toolRenderers(){return[$({tools:[`workflow_child`]},ja),$({tools:[`workflow`]},Ma)]}}});export{Na as webPlugin};
@@ -1 +0,0 @@
1
- import "./presetConfig-DN-SWudD.js";