@kingsoftcloud/ksadk-web 0.3.18 → 0.3.19

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 (188) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +2 -2
  3. package/RELEASE_PROVENANCE.json +2 -2
  4. package/dist-ksadk/assets/{ArtifactsPanel-Cdr5C_vM.js → ArtifactsPanel-cjsDWTLW.js} +1 -1
  5. package/dist-ksadk/assets/{CodeBlock-BWRafud9.js → CodeBlock-DTtT6SBI.js} +1 -1
  6. package/dist-ksadk/assets/{MathMessageMarkdown-CFKeJIvy.js → MathMessageMarkdown-Dap7DsE1.js} +1 -1
  7. package/dist-ksadk/assets/{MermaidBlock-BneAGUOd.js → MermaidBlock-C2QkLej8.js} +6 -6
  8. package/dist-ksadk/assets/{NativeTerminalPanel-BHI85zDO.js → NativeTerminalPanel-CeLWBCnF.js} +1 -1
  9. package/dist-ksadk/assets/{OfficialA2uiRenderer-BOmT36lJ.js → OfficialA2uiRenderer-BshRBsxZ.js} +1 -1
  10. package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-DQvlOsBI.js → abnfDiagram-VCTEODGH-RvCk4kKS.js} +1 -1
  11. package/dist-ksadk/assets/{arc-CGx0e4pN.js → arc-R-NvbHBi.js} +1 -1
  12. package/dist-ksadk/assets/architecture-7GRP2DOG-BgT_ltgS.js +1 -0
  13. package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-WyybcNKX.js → architectureDiagram-5GKGNRK7-CWyeEVzn.js} +1 -1
  14. package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-C9Cx_GVs.js → blockDiagram-NRAW4CY4-CHbhUWj9.js} +1 -1
  15. package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-Bh7X3bGr.js → c4Diagram-UCG6FXSJ-BJAftB45.js} +1 -1
  16. package/dist-ksadk/assets/channel-CO8jKUdU.js +1 -0
  17. package/dist-ksadk/assets/chunk-2Q5K7J3B-BQ7ktM_H.js +1 -0
  18. package/dist-ksadk/assets/{chunk-5VM5RSS4-cP9XupZj.js → chunk-5VM5RSS4-BHufOSfh.js} +1 -1
  19. package/dist-ksadk/assets/{chunk-F27PBJKO-Bm77fvR9.js → chunk-F27PBJKO-BNPW42o9.js} +1 -1
  20. package/dist-ksadk/assets/{chunk-G27WJ6UU-DDKNPesQ.js → chunk-G27WJ6UU-D_eOFZiC.js} +1 -1
  21. package/dist-ksadk/assets/{chunk-JWPE2WC7-BqiUDB7s.js → chunk-JWPE2WC7-DEVN_PSR.js} +1 -1
  22. package/dist-ksadk/assets/{chunk-LCL6LL3I-C528mMZy.js → chunk-LCL6LL3I-DjGV_Lnh.js} +1 -1
  23. package/dist-ksadk/assets/{chunk-POPQ4Y6H-CzZ9g_Uf.js → chunk-POPQ4Y6H-C2i8ZB07.js} +1 -1
  24. package/dist-ksadk/assets/{chunk-RHFEMEQ7-CXj4tUZ-.js → chunk-RHFEMEQ7-DMk7_iWC.js} +1 -1
  25. package/dist-ksadk/assets/{chunk-SVP7TREG-BHyd85pS.js → chunk-SVP7TREG-wHQkXddN.js} +1 -1
  26. package/dist-ksadk/assets/{chunk-XXDRQBXY-Qe29PHGe.js → chunk-XXDRQBXY-gvpc9yiQ.js} +1 -1
  27. package/dist-ksadk/assets/classDiagram-DTDB5LWJ-HRhUD6oW.js +1 -0
  28. package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-HRhUD6oW.js +1 -0
  29. package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-maRKgeec.js → cose-bilkent-JH36ORCC-BF-zBbK8.js} +1 -1
  30. package/dist-ksadk/assets/cynefin-OW5HDTMX-DlLbgFtT.js +1 -0
  31. package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-CoD0bEvn.js → cynefinDiagram-5FMLGOSQ-0_hg7nkA.js} +1 -1
  32. package/dist-ksadk/assets/{dagre-3AP2YEHR-BkpgQqyW.js → dagre-3AP2YEHR-uSuKjV2i.js} +1 -1
  33. package/dist-ksadk/assets/{dagre-BUaTFrYa.js → dagre-BCQPdEAN.js} +1 -1
  34. package/dist-ksadk/assets/{diagram-S7CK7UJ4-25HdTbjE.js → diagram-S7CK7UJ4-ay17NfAC.js} +1 -1
  35. package/dist-ksadk/assets/{diagram-UQ7AKVKN-KO-WqOIg.js → diagram-UQ7AKVKN-CaUhPrNE.js} +1 -1
  36. package/dist-ksadk/assets/{diagram-VSXAHHWV-B360BkDQ.js → diagram-VSXAHHWV-upF8B0NL.js} +1 -1
  37. package/dist-ksadk/assets/{diagram-VX7I27RA-COr1Oqsg.js → diagram-VX7I27RA-B4t46LEt.js} +1 -1
  38. package/dist-ksadk/assets/{diagram-Z3DM3KII-CgaKrIwB.js → diagram-Z3DM3KII-BeHjswE7.js} +1 -1
  39. package/dist-ksadk/assets/{dist-DKG0OYnk.js → dist-58qYwY0M.js} +1 -1
  40. package/dist-ksadk/assets/{dist-Bsuusoi0.js → dist-AF7gi0D5.js} +1 -1
  41. package/dist-ksadk/assets/{dist-DgJ57sRe.js → dist-B0PMHWqd.js} +1 -1
  42. package/dist-ksadk/assets/{dist-DXOlCAay.js → dist-B0s4RUpo.js} +1 -1
  43. package/dist-ksadk/assets/{dist-_0Xgu_07.js → dist-BGzoFqM2.js} +1 -1
  44. package/dist-ksadk/assets/{dist-DzdXSBJb.js → dist-BLCD6xMk.js} +1 -1
  45. package/dist-ksadk/assets/{dist-DmWw0IXB.js → dist-Be3VXZq8.js} +1 -1
  46. package/dist-ksadk/assets/{dist-B3Jp5r1e.js → dist-Bt0YWq2H.js} +1 -1
  47. package/dist-ksadk/assets/{dist-CwnkOyDn.js → dist-Bt4Xk1Ro.js} +1 -1
  48. package/dist-ksadk/assets/{dist-BQ116UdZ.js → dist-Bx4az-XW.js} +1 -1
  49. package/dist-ksadk/assets/{dist-Brbrdmff.js → dist-C577ALLK.js} +1 -1
  50. package/dist-ksadk/assets/{dist-CR61WJFC.js → dist-CIZ7o8ol.js} +1 -1
  51. package/dist-ksadk/assets/{dist-BEbS8Bag.js → dist-COzkztpc.js} +1 -1
  52. package/dist-ksadk/assets/{dist-By-MVndb.js → dist-CW5ZHS5y.js} +1 -1
  53. package/dist-ksadk/assets/{dist-C9BTMVwS.js → dist-CdhMAiGd.js} +1 -1
  54. package/dist-ksadk/assets/{dist-HHvdjADB.js → dist-DIeaHG12.js} +1 -1
  55. package/dist-ksadk/assets/{dist-DSw5Ju6-.js → dist-DfFlb9ip.js} +1 -1
  56. package/dist-ksadk/assets/{dist-CBo9AHUv.js → dist-DvOmTQAV.js} +1 -1
  57. package/dist-ksadk/assets/{dist-BoRn8a_t.js → dist-Dze75pZq.js} +1 -1
  58. package/dist-ksadk/assets/{dist-Bxcu8Ca0.js → dist-h0bOCJVW.js} +1 -1
  59. package/dist-ksadk/assets/{dist--HftQyp9.js → dist-mkEF0-z9.js} +1 -1
  60. package/dist-ksadk/assets/{dist-CxIl4t92.js → dist-uAoeCAZ2.js} +1 -1
  61. package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-DogDP2db.js → ebnfDiagram-PWID7BFC-CZKqGdhK.js} +1 -1
  62. package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-CeBDnUjR.js → erDiagram-SSCWMZ5O-CfQ9oOg4.js} +1 -1
  63. package/dist-ksadk/assets/eventmodeling-NTZA5JFV-BgSxiUqa.js +1 -0
  64. package/dist-ksadk/assets/flowDiagram-A5DVABFB-Dcg0DKL0.js +1 -0
  65. package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-oIQL3MCp.js → ganttDiagram-EL5Y4UJY-CWdRcbsA.js} +1 -1
  66. package/dist-ksadk/assets/gitGraph-4MIJSDKK-DiYbIL_1.js +1 -0
  67. package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-B7qz0cmZ.js → gitGraphDiagram-WWUBYQGX-S2TxceQ8.js} +1 -1
  68. package/dist-ksadk/assets/index-CK5of5EC.js +1135 -0
  69. package/dist-ksadk/assets/index-ofLgkIsP.css +2 -0
  70. package/dist-ksadk/assets/info-A6RAGUB7-CIUhUhPM.js +1 -0
  71. package/dist-ksadk/assets/{infoDiagram-RXCK75RN-yQRC41Ya.js → infoDiagram-RXCK75RN-7M0hPUvw.js} +1 -1
  72. package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-BCu4HiwL.js → ishikawaDiagram-5VMMS53U-DApt_KC9.js} +1 -1
  73. package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-JaqmO73K.js → journeyDiagram-EYS64GPL-03NWnwcI.js} +1 -1
  74. package/dist-ksadk/assets/{kanban-definition-3QL26DDD-DQo4X8NO.js → kanban-definition-3QL26DDD-CWrM-ciB.js} +1 -1
  75. package/dist-ksadk/assets/{katex-t_DWylQw.js → katex-CVJEnrQQ.js} +1 -1
  76. package/dist-ksadk/assets/{linear-DWdnI35B.js → linear-CuvdttYn.js} +1 -1
  77. package/dist-ksadk/assets/{mermaid-parser.core-BHrT2Pfe.js → mermaid-parser.core-CyiGaINC.js} +2 -2
  78. package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-PBVAhZYV.js → mindmap-definition-FBJOCRG2-Cx8x9zok.js} +1 -1
  79. package/dist-ksadk/assets/packet-AYTQ26CC-CVt8vTzN.js +1 -0
  80. package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-CU_cLfow.js → pegDiagram-XKGWAZYB-BvMeLOBU.js} +1 -1
  81. package/dist-ksadk/assets/pie-WAS4IAKB-BmY8d_KC.js +1 -0
  82. package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-B1h0-_pW.js → pieDiagram-E7YTZNPT-BTEiUEUk.js} +1 -1
  83. package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-DEMoGo5a.js → quadrantDiagram-AXDQQJYC-CEMfGgSc.js} +1 -1
  84. package/dist-ksadk/assets/radar-RG4KPBEZ-D-vxRTHO.js +1 -0
  85. package/dist-ksadk/assets/railroad-74A4TZTK-hDbxS9Gl.js +1 -0
  86. package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-6j4dsPir.js +1 -0
  87. package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-f3r0amOv.js +1 -0
  88. package/dist-ksadk/assets/railroad-peg-WCYAUIDC-DpGM5wUK.js +1 -0
  89. package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-BTAob2wg.js → railroadDiagram-O6MQD6OU-DjL0Ielv.js} +1 -1
  90. package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-Dl0Q2SuO.js → requirementDiagram-EFPCY7ZU-Da11svpD.js} +1 -1
  91. package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-DeaTWkur.js → sankeyDiagram-P5KCCOFB-DtKGEnlF.js} +1 -1
  92. package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-gFQYrsOd.js → sequenceDiagram-WJ2MYXX4-CR6Ct1Vm.js} +1 -1
  93. package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-pGQzddMB.js → sizeCapture-X5ZJPWSS-DaQE2An6.js} +1 -1
  94. package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-DmpYOZt1.js → stateDiagram-HBIQ2CUA-Ct2KGWos.js} +1 -1
  95. package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-IHXiAplS.js +1 -0
  96. package/dist-ksadk/assets/{swimlanes-XN3QIQJK-BfuSAsrr.js → swimlanes-XN3QIQJK-BpIOaZ-N.js} +1 -1
  97. package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-ByC69bCd.js +8 -0
  98. package/dist-ksadk/assets/{timeline-definition-24CTP7MA-CgJwrrxf.js → timeline-definition-24CTP7MA-CdwbtpKP.js} +1 -1
  99. package/dist-ksadk/assets/treeView-Q6P3EWNA-Bm72pNZV.js +1 -0
  100. package/dist-ksadk/assets/treemap-WGGIJYW6-Dpgkdt4o.js +1 -0
  101. package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-CBSAgXDd.js → vennDiagram-4TSXK5OY-Dr_5LEwY.js} +1 -1
  102. package/dist-ksadk/assets/wardley-WFR3VGLG-C9w6FZRL.js +1 -0
  103. package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-013TZ2JZ.js → wardleyDiagram-VM6X3IG4-DYojPjE8.js} +1 -1
  104. package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-u6Frp8xp.js → xychartDiagram-S5SC5T6Z-DV3dpSiv.js} +1 -1
  105. package/dist-ksadk/index.html +2 -2
  106. package/dist-lib/App.d.ts.map +1 -1
  107. package/dist-lib/{AttachmentPreview-Dhc6ulFv.js → AttachmentPreview-COS-HmHj.js} +76 -76
  108. package/dist-lib/{ConnectedComposer-Cc6bqJmu.js → ConnectedComposer-CB_YmxRQ.js} +47 -47
  109. package/dist-lib/{ConnectedMessageList-Bdd-qjs-.js → ConnectedMessageList-CJgvv-Hi.js} +357 -275
  110. package/dist-lib/{WorkspacePanelContainer-_PuvSz_J.js → WorkspacePanelContainer-DU6mKsi5.js} +16 -16
  111. package/dist-lib/{a2ui-DihCxdtQ.js → a2ui-e0gsVo7e.js} +31 -31
  112. package/dist-lib/api/client.d.ts +2 -1
  113. package/dist-lib/api/client.d.ts.map +1 -1
  114. package/dist-lib/api/messages.d.ts +38 -0
  115. package/dist-lib/api/messages.d.ts.map +1 -1
  116. package/dist-lib/chat-composer.js +2 -2
  117. package/dist-lib/chat-timeline.js +5 -5
  118. package/dist-lib/components/chat/ChatMessageList.d.ts.map +1 -1
  119. package/dist-lib/components/chat/ConnectedMessageList.d.ts.map +1 -1
  120. package/dist-lib/components/chat/DeferredHistoryContent.d.ts +6 -0
  121. package/dist-lib/components/chat/DeferredHistoryContent.d.ts.map +1 -0
  122. package/dist-lib/components/chat/ProcessingBlocksView.d.ts +0 -7
  123. package/dist-lib/components/chat/ProcessingBlocksView.d.ts.map +1 -1
  124. package/dist-lib/components/chat/types.d.ts +11 -0
  125. package/dist-lib/components/chat/types.d.ts.map +1 -1
  126. package/dist-lib/components.js +7 -7
  127. package/dist-lib/conversation.js +2 -2
  128. package/dist-lib/core/api/facade.d.ts +2 -14
  129. package/dist-lib/core/api/facade.d.ts.map +1 -1
  130. package/dist-lib/core/api/types.d.ts +1 -24
  131. package/dist-lib/core/api/types.d.ts.map +1 -1
  132. package/dist-lib/core/run/engine.d.ts +5 -1
  133. package/dist-lib/core/run/engine.d.ts.map +1 -1
  134. package/dist-lib/core/run/types.d.ts +1 -0
  135. package/dist-lib/core/run/types.d.ts.map +1 -1
  136. package/dist-lib/{feedback-BBJKMdF2.js → feedback-nyK8zFEK.js} +1 -1
  137. package/dist-lib/hooks/useAgentChat.d.ts.map +1 -1
  138. package/dist-lib/hooks/useRunAgent.d.ts +1 -0
  139. package/dist-lib/hooks/useRunAgent.d.ts.map +1 -1
  140. package/dist-lib/hooks/useSessionLifecycle.d.ts +3 -1
  141. package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
  142. package/dist-lib/hooks.js +118 -117
  143. package/dist-lib/{permission-DGyt7wBj.js → permission-B9NRAmxP.js} +1 -1
  144. package/dist-lib/{persisted-session-history-Bh_6zSKC.js → persisted-session-history-C8S6Tl-E.js} +309 -291
  145. package/dist-lib/runtime.js +180 -179
  146. package/dist-lib/{session-events-DvFsVXpD.js → session-events-BMRjrPq2.js} +232 -220
  147. package/dist-lib/stores/session.d.ts +4 -0
  148. package/dist-lib/stores/session.d.ts.map +1 -1
  149. package/dist-lib/styles.css +1 -1
  150. package/dist-lib/{useSessionLifecycle-u7i_h_io.js → useSessionLifecycle-DPwSsODU.js} +1548 -814
  151. package/dist-lib/utils/history-content.d.ts +16 -0
  152. package/dist-lib/utils/history-content.d.ts.map +1 -0
  153. package/dist-lib/utils/history-tool-facts.d.ts.map +1 -1
  154. package/dist-lib/utils/persisted-session-history.d.ts +1 -1
  155. package/dist-lib/utils/persisted-session-history.d.ts.map +1 -1
  156. package/dist-lib/utils/session-event-history.d.ts +2 -0
  157. package/dist-lib/utils/session-event-history.d.ts.map +1 -1
  158. package/dist-lib/utils/session-events.d.ts +4 -1
  159. package/dist-lib/utils/session-events.d.ts.map +1 -1
  160. package/dist-lib/utils/session-items.d.ts +36 -0
  161. package/dist-lib/utils/session-items.d.ts.map +1 -0
  162. package/dist-lib/utils/transcript-order.d.ts +2 -1
  163. package/dist-lib/utils/transcript-order.d.ts.map +1 -1
  164. package/package.json +1 -1
  165. package/dist-ksadk/assets/architecture-7GRP2DOG-CFWjFkDL.js +0 -1
  166. package/dist-ksadk/assets/channel-D6Dp_l74.js +0 -1
  167. package/dist-ksadk/assets/chunk-2Q5K7J3B-CwmjhFYK.js +0 -1
  168. package/dist-ksadk/assets/classDiagram-DTDB5LWJ-DsbvkCAV.js +0 -1
  169. package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-DsbvkCAV.js +0 -1
  170. package/dist-ksadk/assets/cynefin-OW5HDTMX-CBZRVuc4.js +0 -1
  171. package/dist-ksadk/assets/eventmodeling-NTZA5JFV-vXZWMkpn.js +0 -1
  172. package/dist-ksadk/assets/flowDiagram-A5DVABFB-5LRgzKLv.js +0 -1
  173. package/dist-ksadk/assets/gitGraph-4MIJSDKK-BUWSkncI.js +0 -1
  174. package/dist-ksadk/assets/index-4g1ndaxW.js +0 -1132
  175. package/dist-ksadk/assets/index-DEVfafsU.css +0 -2
  176. package/dist-ksadk/assets/info-A6RAGUB7-CzJ_YrOs.js +0 -1
  177. package/dist-ksadk/assets/packet-AYTQ26CC-CXoos6fx.js +0 -1
  178. package/dist-ksadk/assets/pie-WAS4IAKB-CjF9NoIt.js +0 -1
  179. package/dist-ksadk/assets/radar-RG4KPBEZ-BQGWs9nw.js +0 -1
  180. package/dist-ksadk/assets/railroad-74A4TZTK-B6znvLUK.js +0 -1
  181. package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-Bzquz0As.js +0 -1
  182. package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-1IikGkb5.js +0 -1
  183. package/dist-ksadk/assets/railroad-peg-WCYAUIDC-BKKgHzdc.js +0 -1
  184. package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-Dolxgkw3.js +0 -1
  185. package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-BuI1erYj.js +0 -8
  186. package/dist-ksadk/assets/treeView-Q6P3EWNA-DtMdDH8N.js +0 -1
  187. package/dist-ksadk/assets/treemap-WGGIJYW6-VoU8QtLZ.js +0 -1
  188. package/dist-ksadk/assets/wardley-WFR3VGLG-YWSRB0Zm.js +0 -1
@@ -1,4 +1,4 @@
1
- import { S as e, b as t, f as n, n as r, r as i } from "./session-events-DvFsVXpD.js";
1
+ import { S as e, b as t, f as n, n as r, r as i } from "./session-events-BMRjrPq2.js";
2
2
  import { d as a, i as o, l as s, o as c, p as l, t as u, u as d } from "./reducer-mbYiX0wz.js";
3
3
  //#region src/core/conversation/safe-tool-value.ts
4
4
  var f = [
@@ -289,7 +289,7 @@ function T(e, t) {
289
289
  let n = e.map((e) => JSON.stringify(e)), r = t.map((e) => JSON.stringify(e));
290
290
  return n.every((e, t) => r[t] === e) ? t : r.every((e, t) => n[t] === e) ? e : [...e, ...t];
291
291
  }
292
- function ee(e, t, n) {
292
+ function E(e, t, n) {
293
293
  let r = {
294
294
  ...t.runId || e?.runId ? { runId: t.runId || e?.runId } : {},
295
295
  ...t.interactionId || e?.interactionId ? { interactionId: t.interactionId || e?.interactionId } : {},
@@ -311,22 +311,22 @@ function ee(e, t, n) {
311
311
  }
312
312
  //#endregion
313
313
  //#region src/core/a2ui/transcript.ts
314
- function E(e, t) {
314
+ function ee(e, t) {
315
315
  if (e.activity.surfaceId !== t.activity.surfaceId) return !1;
316
316
  let n = e.activity.interactionId, r = t.activity.interactionId;
317
317
  if (n && r) return n === r;
318
318
  let i = e.activity.runId || e.message.runId || e.message.invocationId, a = t.activity.runId || t.message.runId || t.message.invocationId;
319
319
  return i && a ? i === a : (e.activity.originMessageId || e.message.id) === (t.activity.originMessageId || t.message.id);
320
320
  }
321
- function te(e, t) {
322
- let n = e.filter((e) => E(e, t));
321
+ function D(e, t) {
322
+ let n = e.filter((e) => ee(e, t));
323
323
  return n.length === 1 ? n[0] : void 0;
324
324
  }
325
- function ne(e) {
325
+ function te(e) {
326
326
  if (!e.some((e) => e.aguiActivity || e.aguiActivities?.length)) return e;
327
327
  let t = /* @__PURE__ */ new Map(), n = !1, r = e.map((e) => {
328
328
  let r = (r) => {
329
- let i = t.get(r.surfaceId) || [], a = te(i, {
329
+ let i = t.get(r.surfaceId) || [], a = D(i, {
330
330
  message: e,
331
331
  activity: r
332
332
  });
@@ -357,7 +357,7 @@ function ne(e) {
357
357
  }
358
358
  //#endregion
359
359
  //#region src/core/conversation/presentation.ts
360
- var re = {
360
+ var ne = {
361
361
  user_message: "conversation.item.user_message/v1",
362
362
  assistant_text: "conversation.item.assistant_text/v1",
363
363
  reasoning: "conversation.item.reasoning/v1",
@@ -368,10 +368,10 @@ var re = {
368
368
  a2ui: "conversation.item.a2ui/v1",
369
369
  error: "conversation.item.error/v1"
370
370
  };
371
- function ie(e) {
371
+ function re(e) {
372
372
  return e.lifecycle === "completed" || e.lifecycle === "failed";
373
373
  }
374
- var ae = new Set([
374
+ var ie = new Set([
375
375
  "aborted",
376
376
  "canceled",
377
377
  "cancelled",
@@ -379,17 +379,17 @@ var ae = new Set([
379
379
  "incomplete",
380
380
  "interrupted"
381
381
  ]);
382
- function D(e) {
383
- if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !ie(e)) return;
382
+ function O(e) {
383
+ if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !re(e)) return;
384
384
  let t = typeof e.payload.status == "string" ? e.payload.status.toLowerCase() : "";
385
385
  if (t === "completed") return "completed";
386
- if (ae.has(t)) return "failed";
386
+ if (ie.has(t)) return "failed";
387
387
  }
388
- function oe(e) {
389
- let t = re[e.kind];
388
+ function ae(e) {
389
+ let t = ne[e.kind];
390
390
  return t === void 0 || t === e.payloadSchemaRef;
391
391
  }
392
- function se(e) {
392
+ function oe(e) {
393
393
  if (typeof e != "string" || e.length === 0) return null;
394
394
  try {
395
395
  let t = new URL(e);
@@ -398,7 +398,7 @@ function se(e) {
398
398
  return null;
399
399
  }
400
400
  }
401
- function ce(e) {
401
+ function se(e) {
402
402
  return {
403
403
  id: e.itemId,
404
404
  parentId: e.parentItemId || null,
@@ -408,8 +408,8 @@ function ce(e) {
408
408
  lifecycle: e.lifecycle
409
409
  };
410
410
  }
411
- function le(e) {
412
- let t = typeof e.payload.artifactId == "string" && e.payload.artifactId ? e.payload.artifactId : e.itemId, n = e.payload.sizeBytes ?? e.payload.size, r = typeof n == "number" && Number.isFinite(n) && n >= 0 ? n : null, i = se(e.payload.uri);
411
+ function ce(e) {
412
+ let t = typeof e.payload.artifactId == "string" && e.payload.artifactId ? e.payload.artifactId : e.itemId, n = e.payload.sizeBytes ?? e.payload.size, r = typeof n == "number" && Number.isFinite(n) && n >= 0 ? n : null, i = oe(e.payload.uri);
413
413
  return {
414
414
  artifactId: t,
415
415
  itemId: e.itemId,
@@ -423,13 +423,13 @@ function le(e) {
423
423
  uri: i
424
424
  };
425
425
  }
426
- function O(e, t) {
426
+ function k(e, t) {
427
427
  let n = e.payload[t];
428
428
  return typeof n == "string" && n ? n : null;
429
429
  }
430
- function k(e, t) {
430
+ function A(e, t) {
431
431
  if (e.kind === "tool_call") {
432
- let n = O(e, "callId");
432
+ let n = k(e, "callId");
433
433
  if (n) return `tool:${JSON.stringify([
434
434
  e.runId,
435
435
  t ?? (e.nativeRef.scopeId || e.nativeRef.scope_id || ""),
@@ -437,17 +437,17 @@ function k(e, t) {
437
437
  ])}`;
438
438
  }
439
439
  if (e.kind === "approval") {
440
- let t = O(e, "interactionId");
440
+ let t = k(e, "interactionId");
441
441
  if (t) return `approval:${t}`;
442
442
  }
443
443
  if (e.kind === "a2ui") {
444
- let t = O(e, "surfaceId");
444
+ let t = k(e, "surfaceId");
445
445
  if (t) return `a2ui:${JSON.stringify([e.runId, t])}`;
446
446
  }
447
447
  return `item:${e.itemId}`;
448
448
  }
449
- function ue(e, t) {
450
- let n = ie(e) && !ie(t), r = e.kind === "a2ui" && t.kind === "a2ui" && Array.isArray(e.payload.data) && Array.isArray(t.payload.data) ? { data: T(e.payload.data, t.payload.data) } : {};
449
+ function le(e, t) {
450
+ let n = re(e) && !re(t), r = e.kind === "a2ui" && t.kind === "a2ui" && Array.isArray(e.payload.data) && Array.isArray(t.payload.data) ? { data: T(e.payload.data, t.payload.data) } : {};
451
451
  return {
452
452
  ...e,
453
453
  ...t,
@@ -473,32 +473,32 @@ function ue(e, t) {
473
473
  } : {}
474
474
  };
475
475
  }
476
- function de(e) {
476
+ function ue(e) {
477
477
  let t = [], n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map(), s = (e) => {
478
478
  let t = e.nativeRef.parentScopeId;
479
- return e.nativeRef.framework === "langgraph" && e.kind === "tool_call" && e.payload.sourceKind === "tool_result" && e.payload.callId && typeof t == "string" ? k(e, t) : void 0;
479
+ return e.nativeRef.framework === "langgraph" && e.kind === "tool_call" && e.payload.sourceKind === "tool_result" && e.payload.callId && typeof t == "string" ? A(e, t) : void 0;
480
480
  };
481
481
  for (let t of e) {
482
482
  if (t.nativeRef.framework === "langgraph" && t.payload.sourceKind === "tool_call") {
483
- let e = k(t);
483
+ let e = A(t);
484
484
  i.set(e, (i.get(e) ?? 0) + 1);
485
485
  }
486
- t.kind === "tool_call" && t.payload.sourceKind === "tool_result" && a.add(k(t));
486
+ t.kind === "tool_call" && t.payload.sourceKind === "tool_result" && a.add(A(t));
487
487
  let e = s(t);
488
488
  e && o.set(e, (o.get(e) ?? 0) + 1);
489
489
  }
490
490
  for (let c of e) {
491
- let e = k(c), l = s(c), u = l && !i.has(e) && !a.has(l) && i.get(l) === 1 && o.get(l) === 1 ? l : e, d = c.kind === "a2ui" ? {
492
- surfaceId: O(c, "surfaceId") || "",
491
+ let e = A(c), l = s(c), u = l && !i.has(e) && !a.has(l) && i.get(l) === 1 && o.get(l) === 1 ? l : e, d = c.kind === "a2ui" ? {
492
+ surfaceId: k(c, "surfaceId") || "",
493
493
  messages: [],
494
- ...O(c, "interactionId") ? { interactionId: O(c, "interactionId") } : {}
494
+ ...k(c, "interactionId") ? { interactionId: k(c, "interactionId") } : {}
495
495
  } : null, f = d ? {
496
496
  message: {
497
497
  id: c.itemId,
498
498
  runId: c.runId
499
499
  },
500
500
  activity: d
501
- } : null, p = r.get(u) || [], m = f ? te(p, f) : void 0, h = f ? m?.index : n.get(u);
501
+ } : null, p = r.get(u) || [], m = f ? D(p, f) : void 0, h = f ? m?.index : n.get(u);
502
502
  if (h === void 0) {
503
503
  f ? r.set(u, [...p, {
504
504
  ...f,
@@ -514,7 +514,7 @@ function de(e) {
514
514
  let g = t[h];
515
515
  t[h] = {
516
516
  key: g.key,
517
- item: ue(g.item, c),
517
+ item: le(g.item, c),
518
518
  sourceItemIds: [...new Set([...g.sourceItemIds, c.itemId])]
519
519
  };
520
520
  }
@@ -529,29 +529,29 @@ function de(e) {
529
529
  }
530
530
  } : t);
531
531
  }
532
- function fe(e, t) {
532
+ function de(e, t) {
533
533
  let n = e.payload.trigger_ref;
534
534
  return n ? t.filter((t) => t.kind === "tool_call" && t.runId === e.runId && (t.nativeRef.scopeId || t.nativeRef.scope_id) === n.scope_id && (t.payload.callId === n.call_id || t.itemId === e.parentItemId)) : [];
535
535
  }
536
- function pe(e) {
537
- let t = e.filter((e) => e.kind === "agent"), n = (e) => String(e.nativeRef.scopeId || e.nativeRef.scope_id || ""), r = (e) => t.find((t) => t.runId === e.runId && t.itemId !== e.itemId && (e.parentItemId === t.itemId || (e.kind === "agent" ? e.payload.parent_scope_id === t.payload.scope_id : n(e) && n(e) === String(t.payload.scope_id)))), i = new Set(t.flatMap((t) => fe(t, e).map((e) => e.itemId))), a = e.filter((e) => !r(e) && !i.has(e.itemId));
536
+ function fe(e) {
537
+ let t = e.filter((e) => e.kind === "agent"), n = (e) => String(e.nativeRef.scopeId || e.nativeRef.scope_id || ""), r = (e) => t.find((t) => t.runId === e.runId && t.itemId !== e.itemId && (e.parentItemId === t.itemId || (e.kind === "agent" ? e.payload.parent_scope_id === t.payload.scope_id : n(e) && n(e) === String(t.payload.scope_id)))), i = new Set(t.flatMap((t) => de(t, e).map((e) => e.itemId))), a = e.filter((e) => !r(e) && !i.has(e.itemId));
538
538
  return a.sort((t, n) => {
539
539
  let r = (t) => t.kind === "agent" && t.parentItemId && e.some((e) => e.itemId === t.parentItemId) ? e.findIndex((e) => e.itemId === t.parentItemId) : e.indexOf(t);
540
540
  return r(t) - r(n);
541
- }), de(a).map((t) => {
541
+ }), ue(a).map((t) => {
542
542
  if (t.item.kind !== "agent") return t;
543
- let n = de(e.filter((e) => r(e) === t.item && !i.has(e.itemId)));
543
+ let n = ue(e.filter((e) => r(e) === t.item && !i.has(e.itemId)));
544
544
  return {
545
545
  ...t,
546
- sourceItemIds: [...new Set([...fe(t.item, e).map((e) => e.itemId), ...t.sourceItemIds])],
546
+ sourceItemIds: [...new Set([...de(t.item, e).map((e) => e.itemId), ...t.sourceItemIds])],
547
547
  children: n
548
548
  };
549
549
  });
550
550
  }
551
- function me(e, t = {}) {
551
+ function j(e, t = {}) {
552
552
  let n = e.items.filter((e) => e.visibility === "public" || t.includeInternal === !0 && e.visibility === "internal");
553
553
  if (t.profile === "flat-v1" && n.some((e) => e.kind === "agent")) {
554
- let e = n.filter((e) => e.kind === "agent"), t = new Set(e.flatMap((e) => fe(e, n).map((e) => e.itemId))), r = (t) => e.some((e) => e.runId === t.runId && (t.parentItemId === e.itemId || typeof e.payload.scope_id == "string" && e.payload.scope_id.length > 0 && e.payload.scope_id === (t.nativeRef.scopeId || t.nativeRef.scope_id))), i = n.find((e) => D(e)), a = n.filter((e) => e.kind !== "agent" && (e.kind === "error" || !r(e) && !t.has(e.itemId))), o = i?.payload.outputRefs || i?.payload.output_refs;
554
+ let e = n.filter((e) => e.kind === "agent"), t = new Set(e.flatMap((e) => de(e, n).map((e) => e.itemId))), r = (t) => e.some((e) => e.runId === t.runId && (t.parentItemId === e.itemId || typeof e.payload.scope_id == "string" && e.payload.scope_id.length > 0 && e.payload.scope_id === (t.nativeRef.scopeId || t.nativeRef.scope_id))), i = n.find((e) => O(e)), a = n.filter((e) => e.kind !== "agent" && (e.kind === "error" || !r(e) && !t.has(e.itemId))), o = i?.payload.outputRefs || i?.payload.output_refs;
555
555
  Array.isArray(o) && o.length && (a = a.filter((e) => e.kind !== "assistant_text" || o.some((t) => e.nativeRef.scopeId === t.scope_id && e.nativeRef.runtimeItemId === t.item_id)));
556
556
  let s = a.filter((e) => e.kind === "assistant_text");
557
557
  if (i && !s.some((e) => e.payload.text) && Array.isArray(o)) {
@@ -567,13 +567,13 @@ function me(e, t = {}) {
567
567
  }
568
568
  n = a.filter((e) => e.kind !== "assistant_text" || !!i);
569
569
  }
570
- let r = n.filter(oe), i = n.filter((e) => !oe(e)), a = new Set([
570
+ let r = n.filter(ae), i = n.filter((e) => !ae(e)), a = new Set([
571
571
  "user_message",
572
572
  "assistant_text",
573
573
  "reasoning"
574
- ]), o = r.filter((e) => a.has(e.kind)).map(ce), s = (e) => e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || r.some((t) => t.kind === "agent" && (e.parentItemId === t.itemId || t.runId === e.runId && t.payload.scope_id === (e.nativeRef.scopeId || e.nativeRef.scope_id))), c = (e) => r.filter((t) => t.kind === e && !s(t)).map((e) => typeof e.payload.text == "string" ? e.payload.text : "").join(""), l = [...r.filter((e) => e.kind === "unknown"), ...i], u = r.filter((e) => e.kind === "error"), d = [...r].reverse().find((e) => D(e) !== void 0);
574
+ ]), o = r.filter((e) => a.has(e.kind)).map(se), s = (e) => e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || r.some((t) => t.kind === "agent" && (e.parentItemId === t.itemId || t.runId === e.runId && t.payload.scope_id === (e.nativeRef.scopeId || e.nativeRef.scope_id))), c = (e) => r.filter((t) => t.kind === e && !s(t)).map((e) => typeof e.payload.text == "string" ? e.payload.text : "").join(""), l = [...r.filter((e) => e.kind === "unknown"), ...i], u = r.filter((e) => e.kind === "error"), d = [...r].reverse().find((e) => O(e) !== void 0);
575
575
  return {
576
- timeline: pe(r.filter((e) => e.kind !== "progress")),
576
+ timeline: fe(r.filter((e) => e.kind !== "progress")),
577
577
  output: c("assistant_text"),
578
578
  reasoning: c("reasoning"),
579
579
  textItems: o,
@@ -581,7 +581,7 @@ function me(e, t = {}) {
581
581
  approvalItems: r.filter((e) => e.kind === "approval"),
582
582
  structuredInputItems: r.filter((e) => e.kind === "progress" && e.payloadSchemaRef === "conversation.item.structured-input/v1"),
583
583
  a2uiItems: r.filter((e) => e.kind === "a2ui"),
584
- artifacts: r.filter((e) => e.kind === "artifact").map(le),
584
+ artifacts: r.filter((e) => e.kind === "artifact").map(ce),
585
585
  fallbacks: [...l.map((e) => ({
586
586
  id: e.itemId,
587
587
  title: "Unsupported content",
@@ -594,22 +594,22 @@ function me(e, t = {}) {
594
594
  failed: !0
595
595
  }))],
596
596
  runId: n.at(-1)?.runId || "",
597
- terminalStatus: d ? D(d) : void 0
597
+ terminalStatus: d ? O(d) : void 0
598
598
  };
599
599
  }
600
600
  //#endregion
601
601
  //#region src/core/conversation/client.ts
602
- var A = 8;
603
- function j(e) {
602
+ var M = 8;
603
+ function N(e) {
604
604
  return typeof e == "object" && e && !Array.isArray(e) ? e : null;
605
605
  }
606
- function M(e) {
606
+ function P(e) {
607
607
  if (e?.aborted) throw new l("conversation_aborted", "Conversation request was aborted.");
608
608
  }
609
- function he(e, t) {
609
+ function pe(e, t) {
610
610
  return t?.aborted === !0 || e instanceof Error && e.name === "AbortError";
611
611
  }
612
- function ge(e) {
612
+ function me(e) {
613
613
  let t = e.trim().replace(/\/+$/, "");
614
614
  if (!t) return "";
615
615
  if (!t.includes("://")) return t.startsWith("/") ? t : `/${t}`;
@@ -621,16 +621,16 @@ function ge(e) {
621
621
  throw new l("conversation_contract_mismatch", "Conversation base URL must be an HTTP(S) URL without embedded credentials.", { cause: e });
622
622
  }
623
623
  }
624
- function _e(e) {
624
+ function he(e) {
625
625
  return Math.min(200 * 2 ** Math.max(0, e - 1), 2e3);
626
626
  }
627
- function ve(e) {
627
+ function ge(e) {
628
628
  return new Promise((t) => {
629
629
  setTimeout(t, e);
630
630
  });
631
631
  }
632
- async function ye(e, t, n) {
633
- if (M(n), !n) {
632
+ async function _e(e, t, n) {
633
+ if (P(n), !n) {
634
634
  await e(t);
635
635
  return;
636
636
  }
@@ -641,16 +641,16 @@ async function ye(e, t, n) {
641
641
  });
642
642
  });
643
643
  }
644
- function N(e, t, n, r, i) {
644
+ function F(e, t, n, r, i) {
645
645
  let a = i ? i.snapshot() : e.snapshot();
646
646
  return {
647
647
  cursor: t,
648
648
  runId: n,
649
649
  state: a,
650
- presentation: me(a, { profile: r })
650
+ presentation: j(a, { profile: r })
651
651
  };
652
652
  }
653
- function be(e, t) {
653
+ function ve(e, t) {
654
654
  let n, r = [];
655
655
  for (let t of e.split(/\r?\n/)) {
656
656
  let e = t.endsWith("\r") ? t.slice(0, -1) : t;
@@ -670,7 +670,7 @@ function be(e, t) {
670
670
  } catch (e) {
671
671
  throw new l("conversation_contract_mismatch", "Conversation stream contains invalid JSON.", { cause: e });
672
672
  }
673
- let o = j(a), c = j(o?.runtimeEvent) || j(o?.runtime_event) || (o?.schema_version === 2 ? o : null);
673
+ let o = N(a), c = N(o?.runtimeEvent) || N(o?.runtime_event) || (o?.schema_version === 2 ? o : null);
674
674
  if (!o || o.conversationItem === void 0 && !c) {
675
675
  n !== void 0 && (t.cursor = Math.max(t.cursor, n));
676
676
  return;
@@ -703,26 +703,26 @@ function be(e, t) {
703
703
  } catch (e) {
704
704
  throw new l("conversation_contract_mismatch", "Conversation identity or lifecycle invariant failed.", { cause: e });
705
705
  }
706
- t.cursor = Math.max(t.cursor, n), f && !(t.profile === "flat-v1" && d.nativeRef.parentScopeId) && t.options.onItem?.(d), t.options.onUpdate?.(N(t.reducer, t.cursor, t.runId, t.profile, t.lane === "runtime" ? t.runtime : void 0));
706
+ t.cursor = Math.max(t.cursor, n), f && !(t.profile === "flat-v1" && d.nativeRef.parentScopeId) && t.options.onItem?.(d), t.options.onUpdate?.(F(t.reducer, t.cursor, t.runId, t.profile, t.lane === "runtime" ? t.runtime : void 0));
707
707
  }
708
- async function xe(e, t) {
708
+ async function ye(e, t) {
709
709
  if (!e.body) throw new l("conversation_stream_error", "Conversation response has no event stream body.");
710
710
  let n = e.body.getReader(), r = new TextDecoder(), i = "";
711
711
  try {
712
712
  for (;;) {
713
- M(t.options.signal);
713
+ P(t.options.signal);
714
714
  let { value: e, done: a } = await n.read();
715
715
  if (a) break;
716
716
  i += r.decode(e, { stream: !0 });
717
717
  let o = /\r?\n\r?\n/.exec(i);
718
718
  for (; o?.index !== void 0;) {
719
719
  let e = o.index, n = o[0].length;
720
- be(i.slice(0, e), t), i = i.slice(e + n), o = /\r?\n\r?\n/.exec(i);
720
+ ve(i.slice(0, e), t), i = i.slice(e + n), o = /\r?\n\r?\n/.exec(i);
721
721
  }
722
722
  }
723
- i += r.decode(), i.trim() && be(i, t);
723
+ i += r.decode(), i.trim() && ve(i, t);
724
724
  } catch (e) {
725
- throw e instanceof l ? e : (he(e, t.options.signal) && M(t.options.signal), new l("conversation_stream_error", "Conversation event stream was interrupted.", {
725
+ throw e instanceof l ? e : (pe(e, t.options.signal) && P(t.options.signal), new l("conversation_stream_error", "Conversation event stream was interrupted.", {
726
726
  cause: e,
727
727
  runId: t.runId || void 0,
728
728
  cursor: t.cursor
@@ -731,10 +731,10 @@ async function xe(e, t) {
731
731
  n.releaseLock();
732
732
  }
733
733
  }
734
- function Se(e) {
735
- return e.state.items.some((e) => D(e) !== void 0);
734
+ function be(e) {
735
+ return e.state.items.some((e) => O(e) !== void 0);
736
736
  }
737
- var Ce = class {
737
+ var xe = class {
738
738
  fetcher;
739
739
  ingressLane;
740
740
  rendererCatalog;
@@ -743,8 +743,8 @@ var Ce = class {
743
743
  sleep;
744
744
  retryDelayMs;
745
745
  constructor(e = {}) {
746
- if (!Number.isInteger(e.maxReconnects ?? A) || (e.maxReconnects ?? A) < 0 || (e.maxReconnects ?? A) > 32) throw new l("conversation_contract_mismatch", "Conversation reconnect limit must be an integer from 0 to 32.");
747
- this.fetcher = e.fetch, this.rendererCatalog = e.rendererCatalog, this.ingressLane = e.ingressLane, this.baseUrl = ge(e.baseUrl || ""), this.maxReconnects = e.maxReconnects ?? A, this.sleep = e.sleep || ve, this.retryDelayMs = e.retryDelayMs || _e;
746
+ if (!Number.isInteger(e.maxReconnects ?? M) || (e.maxReconnects ?? M) < 0 || (e.maxReconnects ?? M) > 32) throw new l("conversation_contract_mismatch", "Conversation reconnect limit must be an integer from 0 to 32.");
747
+ this.fetcher = e.fetch, this.rendererCatalog = e.rendererCatalog, this.ingressLane = e.ingressLane, this.baseUrl = me(e.baseUrl || ""), this.maxReconnects = e.maxReconnects ?? M, this.sleep = e.sleep || ge, this.retryDelayMs = e.retryDelayMs || he;
748
748
  }
749
749
  fetch() {
750
750
  if (this.fetcher) return this.fetcher;
@@ -755,11 +755,11 @@ var Ce = class {
755
755
  return `${this.baseUrl}${e}`;
756
756
  }
757
757
  async request(e, t, n, r = "conversation_stream_error") {
758
- M(n);
758
+ P(n);
759
759
  try {
760
760
  return await this.fetch()(e, t);
761
761
  } catch (e) {
762
- throw e instanceof l ? e : (he(e, n) && M(n), new l(r, "Conversation network request failed.", { cause: e }));
762
+ throw e instanceof l ? e : (pe(e, n) && P(n), new l(r, "Conversation network request failed.", { cause: e }));
763
763
  }
764
764
  }
765
765
  assertOk(e) {
@@ -775,7 +775,7 @@ var Ce = class {
775
775
  } catch (e) {
776
776
  throw new l("conversation_contract_mismatch", "Conversation surface response is not valid JSON.", { cause: e });
777
777
  }
778
- let o = j(a), s = d(o?.surface);
778
+ let o = N(a), s = d(o?.surface);
779
779
  if (!o || typeof o.buildId != "string" || !o.buildId || !s) throw new l("conversation_contract_mismatch", "Conversation surface response does not match conversation.ksadk.io/v1.");
780
780
  return {
781
781
  buildId: o.buildId,
@@ -783,7 +783,7 @@ var Ce = class {
783
783
  };
784
784
  }
785
785
  async streamTurn(e) {
786
- M(e.signal);
786
+ P(e.signal);
787
787
  let t = o(e.bootstrap.surface, this.rendererCatalog), n = {
788
788
  ...e.input,
789
789
  ...t === "agent-block-v1" || e.input.extensions?.["ksadk.presentation"] ? { extensions: {
@@ -813,27 +813,27 @@ var Ce = class {
813
813
  }, p = await this.request(this.url(`/api/v1/builds/${encodeURIComponent(e.bootstrap.buildId)}/conversation:stream`), f, e.signal);
814
814
  this.assertOk(p);
815
815
  try {
816
- await xe(p, d);
816
+ await ye(p, d);
817
817
  } catch (e) {
818
818
  if (!(e instanceof l) || e.code !== "conversation_stream_error" || !d.runId) throw e;
819
819
  }
820
- let m = N(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0);
821
- if (Se(m)) return m;
820
+ let m = F(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0);
821
+ if (be(m)) return m;
822
822
  if (!d.runId) throw new l("conversation_run_identity_missing", "The stream ended before a canonical item supplied its run identity.", { cursor: d.cursor });
823
823
  for (let t = 1; t <= this.maxReconnects; t += 1) {
824
- await ye(this.sleep, this.retryDelayMs(t), e.signal), M(e.signal);
824
+ await _e(this.sleep, this.retryDelayMs(t), e.signal), P(e.signal);
825
825
  let n;
826
826
  try {
827
827
  n = await this.request(this.url(`/api/v1/runs/${encodeURIComponent(d.runId)}/events?after=${d.cursor}${d.profile === "agent-block-v1" ? "&presentationProfile=agent-block-v1" : ""}`), {
828
828
  method: "GET",
829
829
  headers: { "Last-Event-ID": String(d.cursor) },
830
830
  ...e.signal ? { signal: e.signal } : {}
831
- }, e.signal), this.assertOk(n), await xe(n, d);
831
+ }, e.signal), this.assertOk(n), await ye(n, d);
832
832
  } catch (e) {
833
833
  if (e instanceof l && e.code === "conversation_aborted" || e instanceof l && e.code === "conversation_contract_mismatch" || e instanceof l && e.code === "conversation_http_error" && e.status !== void 0 && e.status < 500) throw e;
834
834
  continue;
835
835
  }
836
- if (m = N(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0), Se(m)) return m;
836
+ if (m = F(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0), be(m)) return m;
837
837
  }
838
838
  throw new l("conversation_reconnect_exhausted", "Conversation replay stopped after the configured reconnect limit.", {
839
839
  runId: d.runId,
@@ -843,13 +843,13 @@ var Ce = class {
843
843
  };
844
844
  //#endregion
845
845
  //#region src/core/conversation/renderer-registry.ts
846
- function we(e, t) {
846
+ function Se(e, t) {
847
847
  if (!e.trim()) throw Error(`trusted conversation renderer ${t} must not be empty`);
848
848
  }
849
- function Te(e) {
849
+ function Ce(e) {
850
850
  let t = /* @__PURE__ */ new Map();
851
851
  for (let n of e) {
852
- if (we(n.id, "id"), we(n.schemaRef, "schemaRef"), !n.kinds.length) throw Error("trusted conversation renderer kinds must not be empty");
852
+ if (Se(n.id, "id"), Se(n.schemaRef, "schemaRef"), !n.kinds.length) throw Error("trusted conversation renderer kinds must not be empty");
853
853
  if (t.has(n.schemaRef)) throw Error(`duplicate trusted conversation renderer schemaRef: ${n.schemaRef}`);
854
854
  t.set(n.schemaRef, Object.freeze({
855
855
  ...n,
@@ -867,14 +867,14 @@ function Te(e) {
867
867
  }
868
868
  });
869
869
  }
870
- var Ee = Te([{
870
+ var we = Ce([{
871
871
  id: "ksadk.agent-block",
872
872
  schemaRef: "conversation.item.agent/v1",
873
873
  kinds: ["agent"]
874
874
  }]);
875
875
  //#endregion
876
876
  //#region src/utils/history-tool-facts.ts
877
- function P(e, t) {
877
+ function I(e, t) {
878
878
  let n = (e) => e === "completed" || e === "error", r = t.output === void 0 ? e.output : t.output;
879
879
  return {
880
880
  args: t.args || e.args,
@@ -882,7 +882,7 @@ function P(e, t) {
882
882
  status: n(e.status) && !n(t.status) ? e.status : t.status
883
883
  };
884
884
  }
885
- function F(e) {
885
+ function L(e) {
886
886
  let t = e.map((e) => ({
887
887
  ...e,
888
888
  tools: e.tools ? { ...e.tools } : void 0
@@ -907,13 +907,13 @@ function F(e) {
907
907
  let r = e.message.tools[e.key], i = n ? {
908
908
  ...t,
909
909
  ...r,
910
- ...P(t, r)
910
+ ...I(t, r)
911
911
  } : {
912
912
  ...r,
913
913
  ...t,
914
- ...P(r, t)
914
+ ...I(r, t)
915
915
  };
916
- e.message.tools[e.key] = i, e.message.blocks = e.message.blocks?.map((e) => e.type === "tool" && e.extra?.callId === t.callId ? {
916
+ t.deferredOutput && (i.status = t.status), i.name === "tool" && (i.name = r.name === "tool" ? t.name : r.name), e.message.tools[e.key] = i, e.message.blocks = e.message.blocks?.map((e) => e.type === "tool" && e.extra?.callId === t.callId ? {
917
917
  ...e,
918
918
  args: i.args,
919
919
  output: i.output,
@@ -946,22 +946,38 @@ function F(e) {
946
946
  }
947
947
  o(h, l), s(e, t, l.callId), c = !0;
948
948
  }
949
- return c ? t : e;
949
+ return c ? t.filter((e) => e.itemId || ![
950
+ "tool_result",
951
+ "stage_tool_result",
952
+ "tool_call",
953
+ "stage_tool_call"
954
+ ].includes(e.eventType || "") || e.content || e.reasoning || e.blocks?.length || e.attachments?.length || Object.keys(e.tools || {}).length) : e;
950
955
  }
951
956
  //#endregion
952
957
  //#region src/utils/transcript-order.ts
953
- var I = (e) => e.runId || e.invocationId;
954
- function L(e) {
958
+ var R = (e) => e.runId || e.invocationId;
959
+ function Te(e, t) {
960
+ if (!t) return e;
961
+ let n = R(t);
962
+ if (!n || e.some((e) => e.role === "user" && R(e) === n)) return e;
963
+ let r = e.findIndex((e) => R(e) === n);
964
+ return r < 0 ? e : [
965
+ ...e.slice(0, r),
966
+ t,
967
+ ...e.slice(r)
968
+ ];
969
+ }
970
+ function z(e) {
955
971
  let t = /* @__PURE__ */ new Map();
956
972
  for (let n of e) {
957
- let e = I(n), r = n.historyOrder?.group;
973
+ let e = R(n), r = n.historyOrder?.group;
958
974
  e && r !== void 0 && t.set(e, Math.min(r, t.get(e) ?? r));
959
975
  }
960
976
  let n = e.map((e, n) => ({
961
977
  message: e,
962
978
  index: n,
963
979
  seq: e.historyOrder?.seq,
964
- group: e.historyOrder?.group ?? t.get(I(e) || "") ?? e.historyOrder?.seq,
980
+ group: e.historyOrder?.group ?? t.get(R(e) || "") ?? e.historyOrder?.seq,
965
981
  part: e.historyOrder?.index || 0
966
982
  })), r, i = n.map(() => void 0);
967
983
  for (let e = n.length - 1; e >= 0; e--) i[e] = r, n[e].group !== void 0 && (r = n[e].group);
@@ -976,60 +992,60 @@ function L(e) {
976
992
  side: 0
977
993
  })).sort((e, t) => e.anchor - t.anchor || e.side - t.side || (e.side === 0 ? (e.seq ?? e.anchor) - (t.seq ?? t.anchor) : 0) || (e.side === 0 ? e.part - t.part : 0) || e.index - t.index).map((e) => e.message);
978
994
  }
979
- function De(e, t) {
995
+ function Ee(e, t) {
980
996
  if (!t) return !0;
981
997
  let n = (n) => n === "feedback" ? !1 : n === "historyOrder" ? e.historyOrder?.seq !== t.historyOrder?.seq || e.historyOrder?.index !== t.historyOrder?.index || e.historyOrder?.group !== t.historyOrder?.group : e[n] !== t[n];
982
998
  return Object.keys(e).some(n) || Object.keys(t).some(n);
983
999
  }
984
- function Oe(e, t, n) {
985
- let r = new Map(t.map((e) => [e.id, e])), i = n.filter((e) => r.has(e.id) && r.get(e.id)?.feedback !== e.feedback), a = new Map(i.map((e) => [e.id, e.feedback])), o = (e) => JSON.stringify([I(e), e.responseId]), s = new Map(i.filter((e) => e.responseId).map((e) => [o(e), e.feedback])), c = (e) => e.map((e) => {
986
- if (a.has(e.id)) return {
1000
+ function De(e, t, n, r = !1) {
1001
+ let i = new Map(t.map((e) => [e.id, e])), a = n.filter((e) => i.has(e.id) && i.get(e.id)?.feedback !== e.feedback), o = new Map(a.map((e) => [e.id, e.feedback])), s = (e) => JSON.stringify([R(e), e.responseId]), c = new Map(a.filter((e) => e.responseId).map((e) => [s(e), e.feedback])), l = (e) => e.map((e) => {
1002
+ if (o.has(e.id)) return {
987
1003
  ...e,
988
- feedback: a.get(e.id)
1004
+ feedback: o.get(e.id)
989
1005
  };
990
- let t = o(e);
991
- return e.responseId && s.has(t) ? {
1006
+ let t = s(e);
1007
+ return e.responseId && c.has(t) ? {
992
1008
  ...e,
993
- feedback: s.get(t)
1009
+ feedback: c.get(t)
994
1010
  } : e;
995
- }), l = n.filter((e) => De(e, r.get(e.id)));
996
- if (!l.length) return ne(F(c(e)));
997
- let u = new Set(l.map(I).filter(Boolean)), d = new Set(l.map((e) => e.id)), f = n.filter((e) => u.has(I(e)) || d.has(e.id)), p = e;
998
- for (let t of u) {
999
- let n = f.filter((e) => I(e) === t), r = e.filter((e) => I(e) === t), i = p.findIndex((e) => I(e) === t), a = n.some((e) => e.role === "user") ? [] : r.filter((e) => e.role === "user");
1000
- p = p.filter((e) => I(e) !== t);
1001
- let o = i < 0 ? p.length : Math.min(i, p.length);
1002
- p.splice(o, 0, ...a, ...n.map((e) => ({
1011
+ }), u = n.filter((e) => Ee(e, i.get(e.id)));
1012
+ if (!u.length) return te(L(l(e)));
1013
+ let d = new Set(u.map(R).filter(Boolean)), f = new Set(u.map((e) => e.id)), p = n.filter((e) => d.has(R(e)) || f.has(e.id)), m = e;
1014
+ for (let t of d) {
1015
+ let n = p.filter((e) => R(e) === t), a = e.filter((e) => R(e) === t), o = m.findIndex((e) => R(e) === t), s = new Set(n.map((e) => e.id)), c = r ? a.filter((e) => !s.has(e.id) && !i.has(e.id)) : n.some((e) => e.role === "user") ? [] : a.filter((e) => e.role === "user");
1016
+ m = m.filter((e) => R(e) !== t);
1017
+ let l = o < 0 ? m.length : Math.min(o, m.length);
1018
+ m.splice(l, 0, ...c, ...n.map((e) => ({
1003
1019
  ...e,
1004
- historyOrder: e.historyOrder || r.find((t) => t.id === e.id)?.historyOrder
1020
+ historyOrder: e.historyOrder || a.find((t) => t.id === e.id)?.historyOrder
1005
1021
  })));
1006
1022
  }
1007
- for (let e of f.filter((e) => !I(e))) {
1008
- let t = p.findIndex((t) => t.id === e.id);
1023
+ for (let e of p.filter((e) => !R(e))) {
1024
+ let t = m.findIndex((t) => t.id === e.id);
1009
1025
  if (t < 0) {
1010
- let t = n.indexOf(e), r = n.slice(t + 1).find((e) => p.some((t) => t.id === e.id)), i = n.slice(0, t).findLast((e) => p.some((t) => t.id === e.id)), a = r ? p.findIndex((e) => e.id === r.id) : i ? p.findIndex((e) => e.id === i.id) + 1 : p.length;
1011
- p = [
1012
- ...p.slice(0, a),
1026
+ let t = n.indexOf(e), r = n.slice(t + 1).find((e) => m.some((t) => t.id === e.id)), i = n.slice(0, t).findLast((e) => m.some((t) => t.id === e.id)), a = r ? m.findIndex((e) => e.id === r.id) : i ? m.findIndex((e) => e.id === i.id) + 1 : m.length;
1027
+ m = [
1028
+ ...m.slice(0, a),
1013
1029
  e,
1014
- ...p.slice(a)
1030
+ ...m.slice(a)
1015
1031
  ];
1016
- } else p = p.map((n, r) => r === t ? {
1032
+ } else m = m.map((n, r) => r === t ? {
1017
1033
  ...e,
1018
1034
  historyOrder: e.historyOrder || n.historyOrder
1019
1035
  } : n);
1020
1036
  }
1021
- return ne(F(c(L(p))));
1037
+ return te(L(l(z(m))));
1022
1038
  }
1023
1039
  //#endregion
1024
1040
  //#region src/core/conversation/hosted.ts
1025
- var ke = "conversation_item_v1";
1026
- function R(e) {
1041
+ var Oe = "conversation_item_v1";
1042
+ function ke(e) {
1027
1043
  return typeof e == "object" && e && !Array.isArray(e) ? e : null;
1028
1044
  }
1029
- function z(e) {
1045
+ function B(e) {
1030
1046
  return typeof e == "string" && e.trim() ? e : null;
1031
1047
  }
1032
- function B(e) {
1048
+ function V(e) {
1033
1049
  if (typeof e == "string") return e;
1034
1050
  if (e == null) return "";
1035
1051
  try {
@@ -1038,11 +1054,11 @@ function B(e) {
1038
1054
  return String(e);
1039
1055
  }
1040
1056
  }
1041
- function V(e) {
1057
+ function H(e) {
1042
1058
  return {
1043
1059
  id: `conversation:${e.runId}:${e.itemId}`,
1044
1060
  timestamp: 0,
1045
- eventType: ke,
1061
+ eventType: Oe,
1046
1062
  eventId: e.sourceEventIds.at(-1),
1047
1063
  runId: e.runId,
1048
1064
  itemId: e.itemId,
@@ -1055,7 +1071,7 @@ function Ae(e) {
1055
1071
  function je(e) {
1056
1072
  let t = typeof e.payload.text == "string" ? e.payload.text : "";
1057
1073
  if (e.kind === "user_message") return {
1058
- ...V(e),
1074
+ ...H(e),
1059
1075
  role: "user",
1060
1076
  content: t,
1061
1077
  eventType: "user_message"
@@ -1073,7 +1089,7 @@ function je(e) {
1073
1089
  status: Ae(e)
1074
1090
  };
1075
1091
  return {
1076
- ...V(e),
1092
+ ...H(e),
1077
1093
  role: "model",
1078
1094
  content: e.kind === "assistant_text" ? t : "",
1079
1095
  reasoning: e.kind === "reasoning" ? t : void 0,
@@ -1081,14 +1097,14 @@ function je(e) {
1081
1097
  };
1082
1098
  }
1083
1099
  function Me(e, t = !1) {
1084
- let n = z(e.payload.tool) || (e.payload.sourceKind === "tool_result" ? "Tool result" : "Tool"), r = z(e.payload.callId), i = B(y(e.payload.args)), a = Object.prototype.hasOwnProperty.call(e.payload, "output") ? B(b(e.payload.output, e.nativeRef.framework, e.nativeRef.protocol)) : void 0, o = {
1100
+ let n = B(e.payload.tool) || (e.payload.sourceKind === "tool_result" ? "Tool result" : "Tool"), r = B(e.payload.callId), i = V(y(e.payload.args)), a = Object.prototype.hasOwnProperty.call(e.payload, "output") ? V(b(e.payload.output, e.nativeRef.framework, e.nativeRef.protocol)) : void 0, o = {
1085
1101
  failed: "error",
1086
1102
  completed: "completed",
1087
1103
  running: "running",
1088
1104
  unknown: "unknown"
1089
1105
  }, s = e.payload.executionStatus, c = typeof s == "string" && Object.hasOwn(o, s) ? o[s] : e.lifecycle === "failed" || e.payload.isError === !0 ? "error" : e.lifecycle === "completed" ? "completed" : "running", l = t && c === "running" ? "unknown" : c;
1090
1106
  return {
1091
- ...V(e),
1107
+ ...H(e),
1092
1108
  role: "model",
1093
1109
  content: "",
1094
1110
  blocks: [{
@@ -1113,9 +1129,9 @@ function Ne(e) {
1113
1129
  return e === "structured_input" ? "structured_input" : e === "plan_review" ? "plan_review" : e === "custom" ? "custom" : "approval";
1114
1130
  }
1115
1131
  function Pe(e) {
1116
- let n = z(e.payload.interactionId), r = e.payload.revision;
1132
+ let n = B(e.payload.interactionId), r = e.payload.revision;
1117
1133
  if (!n || !Number.isInteger(r) || Number(r) < 1) return null;
1118
- let i = B(e.payload.detail), a = z(e.payload.prompt) || i, o = Ne(e.payload.interactionKind), s = e.lifecycle === "completed", c = {};
1134
+ let i = V(e.payload.detail), a = B(e.payload.prompt) || i, o = Ne(e.payload.interactionKind), s = e.lifecycle === "completed", c = {};
1119
1135
  if (s && Object.hasOwn(e.payload, "response")) try {
1120
1136
  c = { response: t(e.payload.response) };
1121
1137
  } catch {}
@@ -1124,16 +1140,16 @@ function Pe(e) {
1124
1140
  sessionId: e.sessionId,
1125
1141
  runId: e.runId,
1126
1142
  kind: o,
1127
- title: z(e.payload.title) || (o === "approval" ? `审批:${z(e.payload.kind) || "操作"}` : "需要补充信息"),
1143
+ title: B(e.payload.title) || (o === "approval" ? `审批:${B(e.payload.kind) || "操作"}` : "需要补充信息"),
1128
1144
  message: a || "运行需要人工确认。",
1129
- requestSchema: R(e.payload.inputSchema),
1145
+ requestSchema: ke(e.payload.inputSchema),
1130
1146
  presentation: null,
1131
1147
  status: s ? "resolved" : "pending",
1132
1148
  revision: Number(r),
1133
- createdAt: z(e.payload.createdAt) || "",
1134
- expiresAt: z(e.payload.expiresAt),
1135
- resolvedAt: s ? z(e.payload.resolvedAt) : null,
1136
- actor: s ? z(e.payload.actor) : null,
1149
+ createdAt: B(e.payload.createdAt) || "",
1150
+ expiresAt: B(e.payload.expiresAt),
1151
+ resolvedAt: s ? B(e.payload.resolvedAt) : null,
1152
+ actor: s ? B(e.payload.actor) : null,
1137
1153
  outcome: s && [
1138
1154
  "approved",
1139
1155
  "rejected",
@@ -1141,23 +1157,23 @@ function Pe(e) {
1141
1157
  "cancelled",
1142
1158
  "expired"
1143
1159
  ].includes(String(e.payload.outcome || "")) ? e.payload.outcome : null,
1144
- responseSummary: s ? z(e.payload.responseSummary) : null,
1160
+ responseSummary: s ? B(e.payload.responseSummary) : null,
1145
1161
  ...c,
1146
1162
  source: "interaction_v1",
1147
1163
  extensions: {
1148
1164
  conversation_item_id: e.itemId,
1149
- ...z(e.payload.callId) ? { call_id: z(e.payload.callId) } : {}
1165
+ ...B(e.payload.callId) ? { call_id: B(e.payload.callId) } : {}
1150
1166
  }
1151
1167
  };
1152
1168
  }
1153
1169
  function Fe(e, t) {
1154
- let n = z(e.payload.kind) || "approval", r = B(e.payload.detail), i = t.status === "resolved" ? t.outcome === "rejected" ? "rejected" : t.outcome === "cancelled" || t.outcome === "expired" ? "cancelled" : "approved" : "pending", a = t.status === "pending" ? "paused" : "completed", o = {
1170
+ let n = B(e.payload.kind) || "approval", r = V(e.payload.detail), i = t.status === "resolved" ? t.outcome === "rejected" ? "rejected" : t.outcome === "cancelled" || t.outcome === "expired" ? "cancelled" : "approved" : "pending", a = t.status === "pending" ? "paused" : "completed", o = {
1155
1171
  approvalRequestId: t.interactionId,
1156
1172
  approvalStatus: i,
1157
1173
  approvalMessage: t.message
1158
1174
  };
1159
1175
  return {
1160
- ...V(e),
1176
+ ...H(e),
1161
1177
  role: "model",
1162
1178
  content: "",
1163
1179
  blocks: [{
@@ -1185,7 +1201,7 @@ function Ie(e) {
1185
1201
  "updateDataModel",
1186
1202
  "deleteSurface"
1187
1203
  ]) {
1188
- let n = z(R(e[t])?.surfaceId);
1204
+ let n = B(ke(e[t])?.surfaceId);
1189
1205
  if (n) return n;
1190
1206
  }
1191
1207
  return null;
@@ -1193,11 +1209,11 @@ function Ie(e) {
1193
1209
  function Le(e) {
1194
1210
  let t = Array.isArray(e.payload.data) ? e.payload.data : Array.isArray(e.payload.operations) ? e.payload.operations : null;
1195
1211
  if (!t) return null;
1196
- let n = t.map(R);
1212
+ let n = t.map(ke);
1197
1213
  if (n.some((e) => e === null)) return null;
1198
- let r = n, i = z(e.payload.surfaceId) || r.map(Ie).find((e) => e !== null) || null;
1214
+ let r = n, i = B(e.payload.surfaceId) || r.map(Ie).find((e) => e !== null) || null;
1199
1215
  return i ? {
1200
- ...V(e),
1216
+ ...H(e),
1201
1217
  role: "a2ui",
1202
1218
  content: "",
1203
1219
  aguiActivity: {
@@ -1207,12 +1223,12 @@ function Le(e) {
1207
1223
  }
1208
1224
  } : null;
1209
1225
  }
1210
- function H(e, t, n, r = !1) {
1226
+ function U(e, t, n, r = !1) {
1211
1227
  return {
1212
- ...V(e),
1228
+ ...H(e),
1213
1229
  role: "system",
1214
1230
  content: n ? `${t}: ${n}` : t,
1215
- status: r ? "failed" : V(e).status
1231
+ status: r ? "failed" : H(e).status
1216
1232
  };
1217
1233
  }
1218
1234
  function Re(e) {
@@ -1226,16 +1242,16 @@ function Re(e) {
1226
1242
  return r.length > 160 ? `${r.slice(0, 160).join("")}…` : n;
1227
1243
  }
1228
1244
  }
1229
- function U(e) {
1245
+ function W(e) {
1230
1246
  let t = e.presentation, n = new Map(t.textItems.map((e) => [e.id, e])), r = new Set(t.toolItems.map((e) => e.itemId)), i = new Set(t.approvalItems.map((e) => e.itemId)), a = new Set(t.structuredInputItems.map((e) => e.itemId)), o = new Set(t.a2uiItems.map((e) => e.itemId)), s = new Map(t.artifacts.map((e) => [e.id, e])), c = new Map(t.fallbacks.map((e) => [e.id, e])), l = [], u = [];
1231
1247
  for (let d of t.timeline) {
1232
1248
  let { item: f } = d;
1233
1249
  if (f.kind === "agent") {
1234
1250
  if (!d.children) {
1235
- l.push(H(f, "Remote agent", String(f.payload.status || "submitted")));
1251
+ l.push(U(f, "Remote agent", String(f.payload.status || "submitted")));
1236
1252
  continue;
1237
1253
  }
1238
- let n = U({
1254
+ let n = W({
1239
1255
  ...e,
1240
1256
  presentation: {
1241
1257
  ...t,
@@ -1243,7 +1259,7 @@ function U(e) {
1243
1259
  }
1244
1260
  });
1245
1261
  l.push({
1246
- ...V(f),
1262
+ ...H(f),
1247
1263
  role: "model",
1248
1264
  content: "",
1249
1265
  agentBlock: {
@@ -1251,7 +1267,7 @@ function U(e) {
1251
1267
  messages: n.messages,
1252
1268
  summary: Re(d.children || [])
1253
1269
  },
1254
- status: f.payload.status === "cancelled" ? "cancelled" : V(f).status
1270
+ status: f.payload.status === "cancelled" ? "cancelled" : H(f).status
1255
1271
  }), u.push(...n.interactions);
1256
1272
  continue;
1257
1273
  }
@@ -1265,18 +1281,18 @@ function U(e) {
1265
1281
  }
1266
1282
  if (i.has(f.itemId) || a.has(f.itemId)) {
1267
1283
  let e = Pe(f);
1268
- e ? (u.push(e), l.push(Fe(f, e))) : l.push(H(f, "Interaction unavailable", "The server did not provide a durable interaction revision; this card is read-only."));
1284
+ e ? (u.push(e), l.push(Fe(f, e))) : l.push(U(f, "Interaction unavailable", "The server did not provide a durable interaction revision; this card is read-only."));
1269
1285
  continue;
1270
1286
  }
1271
1287
  if (o.has(f.itemId)) {
1272
1288
  let e = Le(f);
1273
- l.push(e || H(f, "Unsupported content", "A2UI payload is not a valid passive operation list."));
1289
+ l.push(e || U(f, "Unsupported content", "A2UI payload is not a valid passive operation list."));
1274
1290
  continue;
1275
1291
  }
1276
1292
  let p = s.get(f.itemId);
1277
1293
  if (p) {
1278
1294
  l.push(p.status === "pending" ? {
1279
- ...V(f),
1295
+ ...H(f),
1280
1296
  role: "model",
1281
1297
  content: p.name,
1282
1298
  attachments: [{
@@ -1290,7 +1306,7 @@ function U(e) {
1290
1306
  status: "pending"
1291
1307
  }]
1292
1308
  } : p.status === "ready" && p.uri ? {
1293
- ...V(f),
1309
+ ...H(f),
1294
1310
  role: "model",
1295
1311
  content: p.name,
1296
1312
  attachments: [{
@@ -1303,13 +1319,13 @@ function U(e) {
1303
1319
  sizeBytes: p.sizeBytes,
1304
1320
  status: p.status
1305
1321
  }]
1306
- } : H(f, "Artifact unavailable", p.status === "failed" ? "The artifact failed to generate or its URI is not a safe HTTP(S) link." : "The artifact URI is not a safe HTTP(S) link."));
1322
+ } : U(f, "Artifact unavailable", p.status === "failed" ? "The artifact failed to generate or its URI is not a safe HTTP(S) link." : "The artifact URI is not a safe HTTP(S) link."));
1307
1323
  continue;
1308
1324
  }
1309
1325
  let m = c.get(f.itemId);
1310
1326
  if (m) {
1311
1327
  if (f.kind === "error" && ["cancelled", "canceled"].includes(String(f.payload.status || "").toLowerCase())) continue;
1312
- l.push(H(f, m.title, m.detail, m.failed));
1328
+ l.push(U(f, m.title, m.detail, m.failed));
1313
1329
  }
1314
1330
  }
1315
1331
  return {
@@ -1318,7 +1334,7 @@ function U(e) {
1318
1334
  };
1319
1335
  }
1320
1336
  function ze(e, t, n) {
1321
- let r = U(t).messages;
1337
+ let r = W(t).messages;
1322
1338
  if (!r.length) return e;
1323
1339
  let i = e.filter((e) => e.eventType !== "optimistic_assistant_placeholder"), a = (e) => e.runId === t.runId || e.invocationId === t.runId, o = i.findIndex(a), s = n ? i.findIndex((e) => e.id === n) : o < 0 ? i.findLastIndex((e) => e.role === "user" && e.eventType === "optimistic_user_message") : i.findIndex((e) => e.role === "user" && a(e)), c = i[s], l = i.filter((e, t) => t !== s && !a(e)), u = [s, o].filter((e) => e >= 0), d = u.length ? Math.min(...u) : l.length, f = c && !r.some((e) => e.role === "user") ? [{
1324
1340
  ...c,
@@ -1335,10 +1351,10 @@ function ze(e, t, n) {
1335
1351
  //#endregion
1336
1352
  //#region src/core/run/blocks.ts
1337
1353
  var Be = 0;
1338
- function W(e) {
1354
+ function G(e) {
1339
1355
  return Be += 1, `${e}-${Be}`;
1340
1356
  }
1341
- function G(e) {
1357
+ function K(e) {
1342
1358
  return e.map((e) => e.type === "thinking" && e.status === "streaming" ? {
1343
1359
  ...e,
1344
1360
  status: "done"
@@ -1349,8 +1365,8 @@ function Ve(e, t, n) {
1349
1365
  return i?.type === "thinking" && i.status === "streaming" && i.itemId === n ? (r[r.length - 1] = {
1350
1366
  ...i,
1351
1367
  content: i.content + t
1352
- }, r) : [...G(r), {
1353
- id: W("thinking"),
1368
+ }, r) : [...K(r), {
1369
+ id: G("thinking"),
1354
1370
  type: "thinking",
1355
1371
  content: t,
1356
1372
  status: "streaming",
@@ -1369,12 +1385,12 @@ function He(e, t, n) {
1369
1385
  });
1370
1386
  }
1371
1387
  function Ue(e, t) {
1372
- let n = [...G(e ?? [])], r = n[n.length - 1];
1388
+ let n = [...K(e ?? [])], r = n[n.length - 1];
1373
1389
  return r?.type === "text" && r.status === "streaming" ? (n[n.length - 1] = {
1374
1390
  ...r,
1375
1391
  content: r.content + t
1376
1392
  }, n) : [...n, {
1377
- id: W("text"),
1393
+ id: G("text"),
1378
1394
  type: "text",
1379
1395
  content: t,
1380
1396
  status: "streaming"
@@ -1404,11 +1420,11 @@ function We(e, t) {
1404
1420
  });
1405
1421
  }
1406
1422
  function Ge(e, t) {
1407
- let n = G(e ?? []), r = n.flatMap((e) => e.type === "text" ? [e.content] : []).join(""), i = n.at(-1), a = n;
1423
+ let n = K(e ?? []), r = n.flatMap((e) => e.type === "text" ? [e.content] : []).join(""), i = n.at(-1), a = n;
1408
1424
  if (t !== r && i?.type !== "text") {
1409
1425
  let e = t.startsWith(r) ? t.slice(r.length) : t;
1410
1426
  e && (a = [...n, {
1411
- id: W("text"),
1427
+ id: G("text"),
1412
1428
  type: "text",
1413
1429
  content: e,
1414
1430
  status: "done"
@@ -1450,8 +1466,8 @@ function qe(e, t, n) {
1450
1466
  extra: s
1451
1467
  }, r;
1452
1468
  }
1453
- return [...G(r), {
1454
- id: W("tool"),
1469
+ return [...K(r), {
1470
+ id: G("tool"),
1455
1471
  type: "tool",
1456
1472
  toolName: t,
1457
1473
  args: n.args ?? "",
@@ -1461,18 +1477,18 @@ function qe(e, t, n) {
1461
1477
  }];
1462
1478
  }
1463
1479
  function Je(e) {
1464
- return G(e ?? []);
1480
+ return K(e ?? []);
1465
1481
  }
1466
1482
  function Ye(e) {
1467
1483
  let t = [];
1468
1484
  if (e.reasoning && e.reasoning.trim() && t.push({
1469
- id: W("thinking"),
1485
+ id: G("thinking"),
1470
1486
  type: "thinking",
1471
1487
  content: e.reasoning,
1472
1488
  status: "done",
1473
1489
  ...e.reasoningSource ? { source: e.reasoningSource } : {}
1474
1490
  }), e.tools) for (let n of Object.values(e.tools)) t.push({
1475
- id: W("tool"),
1491
+ id: G("tool"),
1476
1492
  type: "tool",
1477
1493
  toolName: n.name,
1478
1494
  args: n.args ?? "",
@@ -1484,7 +1500,7 @@ function Ye(e) {
1484
1500
  } } : {}
1485
1501
  });
1486
1502
  return e.content && e.content.trim() && t.push({
1487
- id: W("text"),
1503
+ id: G("text"),
1488
1504
  type: "text",
1489
1505
  content: e.content,
1490
1506
  status: "done"
@@ -1505,27 +1521,27 @@ var Xe = {
1505
1521
  "cancelled",
1506
1522
  "canceled"
1507
1523
  ]);
1508
- function K(e) {
1524
+ function q(e) {
1509
1525
  return typeof e == "object" && e && !Array.isArray(e) ? e : null;
1510
1526
  }
1511
1527
  function Qe(e) {
1512
- let t = K(e.source), n = t ? K(t.metadata) : null;
1528
+ let t = q(e.source), n = t ? q(t.metadata) : null;
1513
1529
  return String(n?.native_item_kind || "");
1514
1530
  }
1515
- function q(e, t) {
1516
- let n = K(e[t]);
1531
+ function J(e, t) {
1532
+ let n = q(e[t]);
1517
1533
  if (!n) return [];
1518
1534
  let r = n?.parts;
1519
1535
  return Array.isArray(r) ? r : t === "update" ? [n] : [];
1520
1536
  }
1521
1537
  function $e(e) {
1522
- let t = K(e);
1538
+ let t = q(e);
1523
1539
  if (!t) return "";
1524
1540
  if (typeof t.text == "string") return t.text;
1525
- let n = K(t.data);
1541
+ let n = q(t.data);
1526
1542
  if (n) {
1527
1543
  let e = n.content;
1528
- if (Array.isArray(e)) return e.map((e) => String(K(e)?.text || "")).join("");
1544
+ if (Array.isArray(e)) return e.map((e) => String(q(e)?.text || "")).join("");
1529
1545
  for (let e of [
1530
1546
  "text",
1531
1547
  "output",
@@ -1535,31 +1551,31 @@ function $e(e) {
1535
1551
  }
1536
1552
  return "";
1537
1553
  }
1538
- function J(e) {
1554
+ function Y(e) {
1539
1555
  return e.map($e).join("");
1540
1556
  }
1541
1557
  function et(e) {
1542
- return e.some((e) => K(K(e)?.data)?.type === "userMessage");
1558
+ return e.some((e) => q(q(e)?.data)?.type === "userMessage");
1543
1559
  }
1544
- function Y(e) {
1560
+ function X(e) {
1545
1561
  if (e.length === 1) {
1546
- let t = K(K(e[0])?.data);
1562
+ let t = q(q(e[0])?.data);
1547
1563
  if (t) return t;
1548
1564
  }
1549
- return J(e) || null;
1550
- }
1551
- function X(e) {
1552
- let t = K(e);
1553
- return t ? K(t.data) || t : null;
1565
+ return Y(e) || null;
1554
1566
  }
1555
1567
  function tt(e) {
1556
- let t = X(e);
1557
- return String(t?.content_type || t?.type || "").trim().toLowerCase();
1568
+ let t = q(e);
1569
+ return t ? q(t.data) || t : null;
1558
1570
  }
1559
1571
  function nt(e) {
1572
+ let t = tt(e);
1573
+ return String(t?.content_type || t?.type || "").trim().toLowerCase();
1574
+ }
1575
+ function rt(e) {
1560
1576
  for (let t of e) {
1561
- let e = X(t);
1562
- if (!e || tt(t) !== "tool_call") continue;
1577
+ let e = tt(t);
1578
+ if (!e || nt(t) !== "tool_call") continue;
1563
1579
  let n = String(e.call_id || "").trim(), r = String(e.name || e.tool_name || "").trim();
1564
1580
  if (!(!n && !r)) return {
1565
1581
  callId: n,
@@ -1569,10 +1585,10 @@ function nt(e) {
1569
1585
  }
1570
1586
  return null;
1571
1587
  }
1572
- function rt(e) {
1588
+ function it(e) {
1573
1589
  for (let t of e) {
1574
- let e = X(t);
1575
- if (!e || tt(t) !== "tool_result") continue;
1590
+ let e = tt(t);
1591
+ if (!e || nt(t) !== "tool_result") continue;
1576
1592
  let n = String(e.call_id || e.tool_call_id || "").trim(), r = e.is_error === !0 || e.error != null;
1577
1593
  return {
1578
1594
  callId: n,
@@ -1594,7 +1610,7 @@ function Z(e, t, n, r) {
1594
1610
  ...i && i !== a ? { SourceItemId: i } : {}
1595
1611
  } };
1596
1612
  }
1597
- var it = class {
1613
+ var at = class {
1598
1614
  textByPart = /* @__PURE__ */ new Map();
1599
1615
  toolNameByCallId = /* @__PURE__ */ new Map();
1600
1616
  toolCallByItemId = /* @__PURE__ */ new Map();
@@ -1604,7 +1620,7 @@ var it = class {
1604
1620
  this.sessionId = e;
1605
1621
  }
1606
1622
  translate(e) {
1607
- if (!K(e)) return null;
1623
+ if (!q(e)) return null;
1608
1624
  let t = Number(e.seq);
1609
1625
  if (!Number.isFinite(t) || t <= 0) return null;
1610
1626
  let n = String(e.family || ""), r = String(e.event_type || ""), i = String(e.run_id || ""), a = () => ({
@@ -1635,7 +1651,7 @@ var it = class {
1635
1651
  return null;
1636
1652
  }
1637
1653
  if (n !== "runtime") return null;
1638
- let o = K(K(e.source)?.metadata), s = o?.conversation_visibility ?? o?.visibility;
1654
+ let o = q(q(e.source)?.metadata), s = o?.conversation_visibility ?? o?.visibility;
1639
1655
  if (r.startsWith("item.") && ["internal", "hidden"].includes(String(s))) return null;
1640
1656
  let c = Xe[r];
1641
1657
  if (c) return {
@@ -1645,9 +1661,9 @@ var it = class {
1645
1661
  };
1646
1662
  let l = Qe(e);
1647
1663
  if (r === "item.started") {
1648
- let t = q(e, "initial");
1664
+ let t = J(e, "initial");
1649
1665
  if (e.item_kind === "tool_call") {
1650
- let n = nt(t);
1666
+ let n = rt(t);
1651
1667
  if (!n) return null;
1652
1668
  let r = n?.callId || String(e.item_id || ""), o = n?.name || "tool";
1653
1669
  return r && this.toolNameByCallId.set(r, o), e.item_id && this.toolCallByItemId.set(String(e.item_id), {
@@ -1661,7 +1677,7 @@ var it = class {
1661
1677
  call_id: r,
1662
1678
  tool_name: o,
1663
1679
  run_id: i,
1664
- tool_args: n?.arguments ?? Y(t)
1680
+ tool_args: n?.arguments ?? X(t)
1665
1681
  }
1666
1682
  };
1667
1683
  }
@@ -1678,14 +1694,14 @@ var it = class {
1678
1694
  call_id: String(e.item_id || ""),
1679
1695
  tool_name: l,
1680
1696
  run_id: i,
1681
- tool_args: Y(t)
1697
+ tool_args: X(t)
1682
1698
  }
1683
1699
  } : null;
1684
1700
  }
1685
1701
  if (r === "item.updated") {
1686
- let n = q(e, "update");
1702
+ let n = J(e, "update");
1687
1703
  if (e.item_kind === "tool_call") {
1688
- let t = rt(n);
1704
+ let t = it(n);
1689
1705
  if (!t) return null;
1690
1706
  let r = this.toolCallByItemId.get(String(e.item_id || "")), o = t.callId || r?.callId || String(e.item_id || ""), s = r?.name || this.toolNameByCallId.get(o) || "tool", c = t.isError ? { error: t.result } : t.result;
1691
1707
  return e.item_id && this.toolResultByItemId.set(String(e.item_id), c), {
@@ -1700,7 +1716,7 @@ var it = class {
1700
1716
  }
1701
1717
  };
1702
1718
  }
1703
- let r = K(n[0]), o = String(r?.part_id || e.item_id || t), s = String(e.op || "replace"), c = J(n), u = this.textByPart.get(o) || "", d = s === "append" ? u + c : c;
1719
+ let r = q(n[0]), o = String(r?.part_id || e.item_id || t), s = String(e.op || "replace"), c = Y(n), u = this.textByPart.get(o) || "", d = s === "append" ? u + c : c;
1704
1720
  return this.textByPart.set(o, d), l === "agentMessage" || !l && e.item_kind === "message" ? {
1705
1721
  ...a(),
1706
1722
  EventType: "assistant_stream_snapshot",
@@ -1714,7 +1730,7 @@ var it = class {
1714
1730
  } : null;
1715
1731
  }
1716
1732
  if (r === "item.snapshot_replaced") {
1717
- let n = q(e, "snapshot"), r = String(K(n[0])?.part_id || e.item_id || t), i = J(n);
1733
+ let n = J(e, "snapshot"), r = String(q(n[0])?.part_id || e.item_id || t), i = Y(n);
1718
1734
  return this.textByPart.set(r, i), l === "agentMessage" || !l && e.item_kind === "message" ? {
1719
1735
  ...a(),
1720
1736
  EventType: "assistant_stream_snapshot",
@@ -1728,9 +1744,9 @@ var it = class {
1728
1744
  } : null;
1729
1745
  }
1730
1746
  if (r === "item.completed") {
1731
- let n = q(e, "snapshot");
1747
+ let n = J(e, "snapshot");
1732
1748
  if (e.item_kind === "tool_call") {
1733
- let t = nt(n), r = rt(n), o = this.toolCallByItemId.get(String(e.item_id || "")), s = r?.callId || t?.callId || o?.callId || String(e.item_id || ""), c = t?.name || o?.name || this.toolNameByCallId.get(s) || "tool";
1749
+ let t = rt(n), r = it(n), o = this.toolCallByItemId.get(String(e.item_id || "")), s = r?.callId || t?.callId || o?.callId || String(e.item_id || ""), c = t?.name || o?.name || this.toolNameByCallId.get(s) || "tool";
1734
1750
  if (s && this.toolNameByCallId.set(s, c), r) {
1735
1751
  let t = r.isError ? { error: r.result } : r.result;
1736
1752
  return {
@@ -1753,12 +1769,12 @@ var it = class {
1753
1769
  call_id: s,
1754
1770
  tool_name: c,
1755
1771
  run_id: i,
1756
- tool_args: t?.arguments ?? Y(n)
1772
+ tool_args: t?.arguments ?? X(n)
1757
1773
  }
1758
1774
  };
1759
1775
  }
1760
1776
  if (e.item_kind === "tool_result") {
1761
- let t = rt(n), r = t?.callId || String(e.item_id || ""), o = this.toolNameByCallId.get(r) || l || "tool", s = t?.isError ? { error: t.result } : t?.result ?? Y(n);
1777
+ let t = it(n), r = t?.callId || String(e.item_id || ""), o = this.toolNameByCallId.get(r) || l || "tool", s = t?.isError ? { error: t.result } : t?.result ?? X(n);
1762
1778
  return {
1763
1779
  ...a(),
1764
1780
  EventType: "tool_result",
@@ -1774,10 +1790,10 @@ var it = class {
1774
1790
  if (l === "userMessage" || et(n)) return {
1775
1791
  ...a(),
1776
1792
  EventType: "user_message",
1777
- Content: { parts: [{ text: J(n) }] }
1793
+ Content: { parts: [{ text: Y(n) }] }
1778
1794
  };
1779
1795
  if (l === "agentMessage" || !l && e.item_kind === "message") {
1780
- let r = J(n), i = String(K(n[0])?.part_id || e.item_id || t);
1796
+ let r = Y(n), i = String(q(n[0])?.part_id || e.item_id || t);
1781
1797
  return this.textByPart.set(i, r), {
1782
1798
  ...a(),
1783
1799
  EventType: "assistant_message",
@@ -1786,11 +1802,11 @@ var it = class {
1786
1802
  };
1787
1803
  }
1788
1804
  if (l === "reasoning" || e.item_kind === "reasoning") {
1789
- let r = String(K(n[0])?.part_id || e.item_id || t);
1805
+ let r = String(q(n[0])?.part_id || e.item_id || t);
1790
1806
  return {
1791
1807
  ...a(),
1792
1808
  EventType: "reasoning",
1793
- Content: { parts: [{ text: J(n) }] },
1809
+ Content: { parts: [{ text: Y(n) }] },
1794
1810
  Metadata: Z(e, "completed", r)
1795
1811
  };
1796
1812
  }
@@ -1802,7 +1818,7 @@ var it = class {
1802
1818
  call_id: String(e.item_id || ""),
1803
1819
  tool_name: l,
1804
1820
  run_id: i,
1805
- tool_output: Y(n)
1821
+ tool_output: X(n)
1806
1822
  }
1807
1823
  } : null;
1808
1824
  }
@@ -1817,7 +1833,7 @@ var it = class {
1817
1833
  call_id: n,
1818
1834
  tool_name: r,
1819
1835
  run_id: i,
1820
- tool_output: o ?? { error: K(e.error) || e.error || "item failed" }
1836
+ tool_output: o ?? { error: q(e.error) || e.error || "item failed" }
1821
1837
  }
1822
1838
  };
1823
1839
  }
@@ -1829,14 +1845,14 @@ var it = class {
1829
1845
  call_id: String(e.item_id || ""),
1830
1846
  tool_name: l,
1831
1847
  run_id: i,
1832
- tool_output: { error: K(e.error) || e.error || "item failed" }
1848
+ tool_output: { error: q(e.error) || e.error || "item failed" }
1833
1849
  }
1834
1850
  } : null;
1835
1851
  }
1836
1852
  return null;
1837
1853
  }
1838
1854
  };
1839
- async function at(e) {
1855
+ async function ot(e) {
1840
1856
  let t = e.getReader(), n = new TextDecoder(), r = "", i = null, a = !1, o = (e) => e.includes("data:") || e.includes("event:") || e.includes(":");
1841
1857
  try {
1842
1858
  for (;;) {
@@ -1846,8 +1862,8 @@ async function at(e) {
1846
1862
  break;
1847
1863
  }
1848
1864
  if (r.trimStart().startsWith("{")) {
1849
- if (ot(r)) {
1850
- i = st(r);
1865
+ if (st(r)) {
1866
+ i = ct(r);
1851
1867
  break;
1852
1868
  }
1853
1869
  } else if (o(r)) break;
@@ -1883,7 +1899,7 @@ async function at(e) {
1883
1899
  stream: c
1884
1900
  };
1885
1901
  }
1886
- function ot(e) {
1902
+ function st(e) {
1887
1903
  let t = e.trim();
1888
1904
  if (!t.endsWith("}")) return !1;
1889
1905
  let n = 0, r = !1, i = !1;
@@ -1900,11 +1916,11 @@ function ot(e) {
1900
1916
  }
1901
1917
  return n === 0;
1902
1918
  }
1903
- function st(e) {
1919
+ function ct(e) {
1904
1920
  try {
1905
- let t = K(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
1921
+ let t = q(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
1906
1922
  if (!n) return null;
1907
- let r = K(t?.Error);
1923
+ let r = q(t?.Error);
1908
1924
  return {
1909
1925
  status: n,
1910
1926
  presentationProfile: t?.PresentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1",
@@ -1926,8 +1942,8 @@ function st(e) {
1926
1942
  function Q(e) {
1927
1943
  return e && typeof e == "object" && !Array.isArray(e) ? e : null;
1928
1944
  }
1929
- function ct(e) {
1930
- let t = e.map(dt), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t, n) => JSON.stringify([
1945
+ function lt(e) {
1946
+ let t = e.map(ft), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t, n) => JSON.stringify([
1931
1947
  e,
1932
1948
  t,
1933
1949
  n
@@ -1955,7 +1971,7 @@ function ct(e) {
1955
1971
  } : e;
1956
1972
  });
1957
1973
  }
1958
- function lt(e) {
1974
+ function ut(e) {
1959
1975
  if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
1960
1976
  if (typeof e == "string" && e.trim()) {
1961
1977
  let t = Number(e.trim());
@@ -1964,7 +1980,7 @@ function lt(e) {
1964
1980
  let t = Date.parse(String(e || ""));
1965
1981
  return Number.isFinite(t) ? t : Date.now();
1966
1982
  }
1967
- function ut(e, t, r, i, a) {
1983
+ function dt(e, t, r, i, a) {
1968
1984
  let o = /* @__PURE__ */ new Set(), s = (e, t) => JSON.stringify([e, t]), c = /* @__PURE__ */ new Set();
1969
1985
  for (let e of t) {
1970
1986
  let t = n(e, i);
@@ -2035,7 +2051,7 @@ function ut(e, t, r, i, a) {
2035
2051
  };
2036
2052
  return e.map(d);
2037
2053
  }
2038
- function dt(e) {
2054
+ function ft(e) {
2039
2055
  let t = Q(e?.Content?.runtime_event || e?.Content?.runtimeEvent);
2040
2056
  if (t && String(t.event_type || "")) return {
2041
2057
  ...t,
@@ -2055,10 +2071,10 @@ function dt(e) {
2055
2071
  timestamp: e.Timestamp || n.timestamp || r.timestamp
2056
2072
  };
2057
2073
  }
2058
- function ft(e, t, n) {
2074
+ function pt(e, t, n) {
2059
2075
  let i = /* @__PURE__ */ new Map();
2060
2076
  for (let e of t) {
2061
- if (e.EventType !== "run_status" || dt(e)) continue;
2077
+ if (e.EventType !== "run_status" || ft(e)) continue;
2062
2078
  let t = String(e.InvocationId || e.Metadata?.run_id || "").trim();
2063
2079
  t && !n.has(t) && i.set(t, e);
2064
2080
  }
@@ -2067,7 +2083,7 @@ function ft(e, t, n) {
2067
2083
  let n = r({
2068
2084
  ...t,
2069
2085
  EventId: t.EventId || `legacy-terminal:${e}:${t.SeqId || 0}`,
2070
- Timestamp: lt(t.Timestamp)
2086
+ Timestamp: ut(t.Timestamp)
2071
2087
  });
2072
2088
  if (!n) continue;
2073
2089
  let i = (t) => (t.invocationId || t.runId) === e;
@@ -2101,7 +2117,7 @@ function ft(e, t, n) {
2101
2117
  eventId: t.EventId
2102
2118
  });
2103
2119
  }
2104
- return a === e ? e : L(a);
2120
+ return a === e ? e : z(a);
2105
2121
  }
2106
2122
  function $(e) {
2107
2123
  return e.role === "model" ? {
@@ -2114,7 +2130,7 @@ function $(e) {
2114
2130
  })
2115
2131
  } : e;
2116
2132
  }
2117
- function pt(e, t) {
2133
+ function mt(e, t) {
2118
2134
  let n = t.find((e) => e.role === "user"), r = e.some((e) => e.role === "user"), i = t.filter((e) => e.role === "model"), a = e.filter((e) => e.role === "model").at(-1), o = i.at(-1), s = e.map((e) => e.role === "user" && n ? {
2119
2135
  ...e,
2120
2136
  ...n,
@@ -2127,7 +2143,7 @@ function pt(e, t) {
2127
2143
  } : e));
2128
2144
  return n && !r ? [n, ...s] : s;
2129
2145
  }
2130
- function mt(e, t) {
2146
+ function ht(e, t) {
2131
2147
  let n = t.filter((e) => e.role === "model"), r = n.flatMap((e) => Object.values(e.tools || {}).map((t) => ({
2132
2148
  tool: t,
2133
2149
  scope: e.scopeId
@@ -2142,7 +2158,7 @@ function mt(e, t) {
2142
2158
  return [t, r ? {
2143
2159
  ...n,
2144
2160
  ...r,
2145
- ...P(n, r),
2161
+ ...I(n, r),
2146
2162
  name: n.name
2147
2163
  } : n];
2148
2164
  })), n = e === s ? a : [];
@@ -2155,7 +2171,7 @@ function mt(e, t) {
2155
2171
  let n = t.extra?.callId, r = typeof n == "string" ? i(n, e.scopeId) : void 0;
2156
2172
  return r ? {
2157
2173
  ...t,
2158
- ...P(t, r)
2174
+ ...I(t, r)
2159
2175
  } : t;
2160
2176
  }), c = Ye({ tools: Object.fromEntries(n.map(({ tool: e, scope: t }) => [JSON.stringify([t || "", e.callId || e.name]), e])) }), l = r?.findIndex((e) => e.type === "text") ?? -1;
2161
2177
  return $({
@@ -2170,21 +2186,21 @@ function mt(e, t) {
2170
2186
  });
2171
2187
  });
2172
2188
  }
2173
- function ht(e) {
2189
+ function gt(e) {
2174
2190
  return new Set(e.filter((e) => e.role === "model" && e.eventType === "assistant_message" && !!String(e.content || "").trim() && !!e.invocationId).map((e) => String(e.invocationId)));
2175
2191
  }
2176
- var gt = new Set([
2192
+ var _t = new Set([
2177
2193
  "approval.resolved",
2178
2194
  "interaction.resolved",
2179
2195
  "interaction.cancelled",
2180
2196
  "interaction.canceled",
2181
2197
  "a2ui.action"
2182
2198
  ]);
2183
- function _t(e) {
2199
+ function vt(e) {
2184
2200
  let t = /* @__PURE__ */ new Set();
2185
2201
  for (let n of e) {
2186
2202
  let e = Q(n.Content) || {}, r = Q(e.runtime_event || e.runtimeEvent) || {}, i = Q(e.payload) || Q(r.payload) || {}, a = String(n.EventType || e.event_type || e.eventType || r.event_type || "").toLowerCase();
2187
- if (!gt.has(a)) continue;
2203
+ if (!_t.has(a)) continue;
2188
2204
  let o = String(e.outcome || e.action || e.name || e.status || i.outcome || i.action || i.name || i.status || "").toLowerCase();
2189
2205
  if (![
2190
2206
  "cancel",
@@ -2196,64 +2212,66 @@ function _t(e) {
2196
2212
  }
2197
2213
  return t;
2198
2214
  }
2199
- function vt(e, t, n, r = "flat-v1") {
2200
- e = F(e);
2201
- let a = new it(n), o = [], s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = [...t || []].filter((e) => {
2215
+ function yt(e, t, n, r = "flat-v1", a) {
2216
+ e = L(e);
2217
+ let o = new at(n), s = [], c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d = [...t || []].filter((e) => {
2202
2218
  let t = e.Content, r = Q(t?.session_event || t?.sessionEvent), i = Q(t?.runtime_event || t?.runtimeEvent);
2203
2219
  return [
2204
2220
  e.SessionId,
2205
2221
  r?.session_id,
2206
2222
  i?.session_id
2207
2223
  ].every((e) => !e || e === n);
2208
- }).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), d = Number(u[0]?.SeqId || 0) <= 1, f = ct(u);
2209
- for (let [e, t] of u.entries()) {
2210
- let n = f[e];
2224
+ }).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), f = Number(a ?? d[0]?.SeqId ?? 0) <= 1, p = lt(d);
2225
+ for (let [e, t] of d.entries()) {
2226
+ let n = p[e];
2211
2227
  if (!n) continue;
2212
2228
  let r = String(n.run_id || "").trim();
2213
2229
  if (r) {
2214
- s.add(r), !n.parent_scope_id && [
2230
+ c.add(r), !n.parent_scope_id && [
2215
2231
  "run.completed",
2216
2232
  "run.failed",
2217
2233
  "run.cancelled",
2218
2234
  "run.canceled"
2219
- ].includes(String(n.event_type)) && c.add(r);
2235
+ ].includes(String(n.event_type)) && l.add(r);
2220
2236
  let e = Q(Q(n.source)?.metadata), t = String(n.event_type || "") === "run.started", i = e?.native_item_kind === "userMessage";
2221
- (d || t || i) && l.add(r);
2237
+ (f || t || i) && u.add(r);
2222
2238
  }
2223
- let i = a.translate(n);
2224
- i && o.push({
2239
+ let i = o.translate(n);
2240
+ i && s.push({
2225
2241
  ...i,
2226
2242
  SeqId: Number(t.SeqId || i.SeqId || 0),
2227
- Timestamp: lt(t.Timestamp || i.Timestamp)
2243
+ Timestamp: ut(t.Timestamp || i.Timestamp)
2228
2244
  });
2229
2245
  }
2230
- let p = i(o).filter((e) => e.invocationId && s.has(e.invocationId)), m = /* @__PURE__ */ new Map();
2246
+ let m = i(s).filter((e) => e.invocationId && c.has(e.invocationId)), h = /* @__PURE__ */ new Map();
2231
2247
  for (let t of e) {
2232
2248
  let e = String(t.invocationId || "");
2233
- e && m.set(e, [...m.get(e) || [], t]);
2249
+ if (!e) continue;
2250
+ let n = h.get(e);
2251
+ n ? n.push(t) : h.set(e, [t]);
2234
2252
  }
2235
- let h = new Set([...ht(p)].filter((e) => l.has(e))), g = /* @__PURE__ */ new Map();
2236
- for (let e of f) {
2253
+ let g = new Set([...gt(m)].filter((e) => u.has(e))), _ = /* @__PURE__ */ new Map();
2254
+ for (let e of p) {
2237
2255
  if (e?.schema_version !== 2 || !e.run_id) continue;
2238
- let t = String(e.run_id), n = g.get(t) || [];
2239
- n.push(e), g.set(t, n);
2256
+ let t = String(e.run_id), n = _.get(t) || [];
2257
+ n.push(e), _.set(t, n);
2240
2258
  }
2241
- let _ = (e) => [
2259
+ let v = (e) => [
2242
2260
  Q(e.initial),
2243
2261
  Q(e.snapshot),
2244
2262
  Q(e.update)
2245
- ].some((e) => Q(e?.data)?.schema === "execution.scope/v1" || Array.isArray(e?.parts) && e.parts.some((e) => Q(Q(e)?.data)?.schema === "execution.scope/v1")), v = new Set([...g].filter(([, e]) => e.some(_)).map(([e]) => e)), y = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Set();
2246
- for (let [e, t] of g) {
2247
- if (!v.has(e) && !h.has(e) && !t.some((e) => ["item.failed", "run.failed"].includes(String(e.event_type)))) continue;
2263
+ ].some((e) => Q(e?.data)?.schema === "execution.scope/v1" || Array.isArray(e?.parts) && e.parts.some((e) => Q(Q(e)?.data)?.schema === "execution.scope/v1")), y = new Set([..._].filter(([, e]) => e.some(v)).map(([e]) => e)), b = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Set();
2264
+ for (let [e, t] of _) {
2265
+ if (!y.has(e) && !g.has(e) && !t.some((e) => ["item.failed", "run.failed"].includes(String(e.event_type)))) continue;
2248
2266
  let i = t.some((e) => e.event_type === "run.started" && !e.parent_scope_id), a = /* @__PURE__ */ new Set(), o = t.every((e) => {
2249
2267
  let t = JSON.stringify([e.scope_id, e.item_id]);
2250
- return e.event_type === "item.started" && a.add(t), !_(e) || a.has(t);
2268
+ return e.event_type === "item.started" && a.add(t), !v(e) || a.has(t);
2251
2269
  });
2252
2270
  if (!(!i || !o)) try {
2253
2271
  let i = new w(n, void 0, r);
2254
2272
  t.forEach((e) => i.apply(e));
2255
- let a = i.snapshot(), o = me(a, { profile: r }), s = lt(t[0].timestamp);
2256
- y.set(e, U({
2273
+ let a = i.snapshot(), o = j(a, { profile: r }), s = ut(t[0].timestamp);
2274
+ b.set(e, W({
2257
2275
  state: a,
2258
2276
  presentation: o,
2259
2277
  runId: e,
@@ -2271,36 +2289,36 @@ function vt(e, t, n, r = "flat-v1") {
2271
2289
  };
2272
2290
  }));
2273
2291
  } catch (t) {
2274
- b.add(e), console.warn(`[SessionHistory] strict replay skipped for run ${e}:`, t instanceof Error ? t.message : "invalid runtime history");
2292
+ x.add(e), console.warn(`[SessionHistory] strict replay skipped for run ${e}:`, t instanceof Error ? t.message : "invalid runtime history");
2275
2293
  }
2276
2294
  }
2277
- for (let e of new Set([...v, ...b])) y.has(e) || h.delete(e);
2278
- let x = _t(u), S = [...h].flatMap((e) => pt(p.filter((t) => t.invocationId === e), m.get(e) || [])), C = /* @__PURE__ */ new Map(), T = [];
2279
- for (let [e, t] of m) {
2280
- if (h.has(e) || !s.has(e)) continue;
2281
- let n = p.filter((t) => t.invocationId === e), r = t.some((e) => e.role === "model" && String(e.content || "").trim());
2282
- C.set(e, r ? mt(t, n) : t), r || T.push(...n.map($));
2283
- }
2284
- for (let e of s) h.has(e) || m.has(e) || T.push(...p.filter((t) => t.invocationId === e).map($));
2285
- let ee = new Map([...C.values()].flat().map((e) => [e.id, e])), E = L([
2286
- ...e.filter((e) => !(e.role === "model" && e.invocationId && x.has(e.invocationId)) && (e.role === "a2ui" || !e.invocationId || !h.has(e.invocationId))).map((e) => ee.get(e.id) || e),
2287
- ...S,
2288
- ...T
2295
+ for (let e of new Set([...y, ...x])) b.has(e) || g.delete(e);
2296
+ let S = vt(d), C = [...g].flatMap((e) => mt(m.filter((t) => t.invocationId === e), h.get(e) || [])), T = /* @__PURE__ */ new Map(), E = [];
2297
+ for (let [e, t] of h) {
2298
+ if (g.has(e) || !c.has(e)) continue;
2299
+ let n = m.filter((t) => t.invocationId === e), r = t.some((e) => e.role === "model" && String(e.content || "").trim());
2300
+ T.set(e, r ? ht(t, n) : t), r || E.push(...n.map($));
2301
+ }
2302
+ for (let e of c) g.has(e) || h.has(e) || E.push(...m.filter((t) => t.invocationId === e).map($));
2303
+ let ee = new Map([...T.values()].flat().map((e) => [e.id, e])), D = z([
2304
+ ...e.filter((e) => !(e.role === "model" && e.invocationId && S.has(e.invocationId)) && (e.role === "a2ui" || !e.invocationId || !g.has(e.invocationId))).map((e) => ee.get(e.id) || e),
2305
+ ...C,
2306
+ ...E
2289
2307
  ]);
2290
- for (let [e, t] of y) {
2308
+ for (let [e, t] of b) {
2291
2309
  if (!t.length) continue;
2292
- let n = (t) => t.invocationId === e || t.runId === e, r = E.findIndex(n), i = E.filter(n), a = i.find((e) => e.role === "user"), o = v.has(e) ? a && !t.some((e) => e.role === "user") ? [a, ...t] : t : pt(t, i), s = E.filter((e) => !n(e)), c = r < 0 ? s.length : r;
2293
- E = [
2310
+ let n = (t) => t.invocationId === e || t.runId === e, r = D.findIndex(n), i = D.filter(n), a = i.find((e) => e.role === "user"), o = y.has(e) ? a && !t.some((e) => e.role === "user") ? [a, ...t] : t : mt(t, i), s = D.filter((e) => !n(e)), c = r < 0 ? s.length : r;
2311
+ D = [
2294
2312
  ...s.slice(0, c),
2295
2313
  ...o,
2296
2314
  ...s.slice(c)
2297
- ], h.add(e);
2315
+ ], g.add(e);
2298
2316
  }
2299
2317
  return {
2300
- messages: ut(F(L(ft(E, u, c))), u, f, n, c),
2301
- canonicalRunIds: [...h],
2302
- translatedEvents: o
2318
+ messages: dt(L(z(pt(D, d, l))), d, p, n, l),
2319
+ canonicalRunIds: [...g],
2320
+ translatedEvents: s
2303
2321
  };
2304
2322
  }
2305
2323
  //#endregion
2306
- export { te as C, C as E, ne as S, w as T, F as _, Ue as a, Ce as b, Ge as c, He as d, Ke as f, Oe as g, U as h, at as i, Je as l, ze as m, vt as n, Ve as o, qe as p, it as r, Ye as s, dt as t, We as u, Ee as v, ee as w, me as x, Te as y };
2324
+ export { j as C, w as D, E, C as O, xe as S, D as T, z as _, Ue as a, we as b, Ge as c, He as d, Ke as f, De as g, W as h, ot as i, Je as l, ze as m, yt as n, Ve as o, qe as p, at as r, Ye as s, ft as t, We as u, Te as v, te as w, Ce as x, L as y };