@kingsoftcloud/ksadk-web 0.3.16 → 0.3.17

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 (209) 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-BuQ9Y_JK.js → ArtifactsPanel-DYzXIPnl.js} +1 -1
  5. package/dist-ksadk/assets/{CodeBlock-ClmrpVUK.js → CodeBlock-Dpa-tOmG.js} +1 -1
  6. package/dist-ksadk/assets/{MathMessageMarkdown-DYg6qEqQ.js → MathMessageMarkdown-D8kBE9sl.js} +1 -1
  7. package/dist-ksadk/assets/{MermaidBlock-B8QsBFET.js → MermaidBlock-BYOoZB-_.js} +6 -6
  8. package/dist-ksadk/assets/{NativeTerminalPanel-Dkm61i5S.js → NativeTerminalPanel-CAeXHeo6.js} +1 -1
  9. package/dist-ksadk/assets/{OfficialA2uiRenderer-SMVbkx2W.js → OfficialA2uiRenderer-yPb3s23n.js} +1 -1
  10. package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-CQ5-2gHs.js → abnfDiagram-VCTEODGH-DdVxMn2L.js} +1 -1
  11. package/dist-ksadk/assets/{arc-CHdgzwmb.js → arc-DsOMYRTm.js} +1 -1
  12. package/dist-ksadk/assets/architecture-7GRP2DOG-Ds1NB530.js +1 -0
  13. package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-MnCOPhnl.js → architectureDiagram-5GKGNRK7-BCfzi23_.js} +1 -1
  14. package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-DZ61ECd8.js → blockDiagram-NRAW4CY4-gC-Gc2Xv.js} +1 -1
  15. package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-D9FYHHhU.js → c4Diagram-UCG6FXSJ-BAHemGZa.js} +1 -1
  16. package/dist-ksadk/assets/channel-B4PiWfnA.js +1 -0
  17. package/dist-ksadk/assets/chunk-2Q5K7J3B-CI2tn5IS.js +1 -0
  18. package/dist-ksadk/assets/{chunk-5VM5RSS4-AIv2klim.js → chunk-5VM5RSS4-Cthhs8Yv.js} +1 -1
  19. package/dist-ksadk/assets/{chunk-F27PBJKO-D_sWJ7f-.js → chunk-F27PBJKO-BPV04XpW.js} +1 -1
  20. package/dist-ksadk/assets/{chunk-G27WJ6UU-DQzToglM.js → chunk-G27WJ6UU-Cl1n0gHd.js} +1 -1
  21. package/dist-ksadk/assets/{chunk-JWPE2WC7-lOgv6BXZ.js → chunk-JWPE2WC7-DqkIh_LK.js} +1 -1
  22. package/dist-ksadk/assets/{chunk-LCL6LL3I-Cbx6jBtE.js → chunk-LCL6LL3I-DZhAKY7Z.js} +1 -1
  23. package/dist-ksadk/assets/{chunk-POPQ4Y6H-DNJ22Jtx.js → chunk-POPQ4Y6H-BGuhTofV.js} +1 -1
  24. package/dist-ksadk/assets/{chunk-RHFEMEQ7-BhICgqzs.js → chunk-RHFEMEQ7-DhrRHdJ6.js} +1 -1
  25. package/dist-ksadk/assets/{chunk-SVP7TREG-r-bF-HGi.js → chunk-SVP7TREG-CIdm5TIa.js} +1 -1
  26. package/dist-ksadk/assets/{chunk-XXDRQBXY-OjeFK9EX.js → chunk-XXDRQBXY-CNIlGK4v.js} +1 -1
  27. package/dist-ksadk/assets/classDiagram-DTDB5LWJ-BMQzydMm.js +1 -0
  28. package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-BMQzydMm.js +1 -0
  29. package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-LkMJR5TN.js → cose-bilkent-JH36ORCC-BjauSFl3.js} +1 -1
  30. package/dist-ksadk/assets/cynefin-OW5HDTMX-DcGwq_cA.js +1 -0
  31. package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-B6wd-M91.js → cynefinDiagram-5FMLGOSQ-DPszkr1j.js} +1 -1
  32. package/dist-ksadk/assets/{dagre-3AP2YEHR-Yo8czwSH.js → dagre-3AP2YEHR-Ds2xBGA0.js} +1 -1
  33. package/dist-ksadk/assets/{dagre-IpjZOTvn.js → dagre-Dr0YPDPm.js} +1 -1
  34. package/dist-ksadk/assets/{diagram-S7CK7UJ4-CAkqzyfj.js → diagram-S7CK7UJ4-BOQfgaW5.js} +1 -1
  35. package/dist-ksadk/assets/{diagram-UQ7AKVKN-JyEZmDlh.js → diagram-UQ7AKVKN-DMMyB2sa.js} +1 -1
  36. package/dist-ksadk/assets/{diagram-VSXAHHWV-DGBXNEif.js → diagram-VSXAHHWV-DZR1nzPa.js} +1 -1
  37. package/dist-ksadk/assets/{diagram-VX7I27RA-KljR5Glh.js → diagram-VX7I27RA-DzAwLHuI.js} +1 -1
  38. package/dist-ksadk/assets/{diagram-Z3DM3KII-8FQ2FrUP.js → diagram-Z3DM3KII-D98d_Dgt.js} +1 -1
  39. package/dist-ksadk/assets/{dist-87AsLuzD.js → dist-A55dc8b7.js} +1 -1
  40. package/dist-ksadk/assets/{dist-Bnqrfpu2.js → dist-BEzIxZLq.js} +1 -1
  41. package/dist-ksadk/assets/{dist-DrFtl2Jz.js → dist-BHIb3Gvv.js} +1 -1
  42. package/dist-ksadk/assets/{dist-DWRPGuTp.js → dist-BIR7kFKG.js} +1 -1
  43. package/dist-ksadk/assets/{dist-Cj5PFf9x.js → dist-BpZXLW0T.js} +1 -1
  44. package/dist-ksadk/assets/{dist-Cs1lGsiM.js → dist-By8HbjFH.js} +1 -1
  45. package/dist-ksadk/assets/{dist-dxCMjEJX.js → dist-C1uAMNTH.js} +1 -1
  46. package/dist-ksadk/assets/{dist-CSguAs4w.js → dist-CN8MSPvo.js} +1 -1
  47. package/dist-ksadk/assets/{dist-BmrsRv90.js → dist-CpHO1CY1.js} +1 -1
  48. package/dist-ksadk/assets/{dist-Bls_5FN6.js → dist-CxzBVC3N.js} +1 -1
  49. package/dist-ksadk/assets/{dist-DRAbZJl6.js → dist-D9GtQnvz.js} +1 -1
  50. package/dist-ksadk/assets/{dist-CAnMW8ay.js → dist-DHiOUJJ-.js} +1 -1
  51. package/dist-ksadk/assets/{dist-Bo4bAcyo.js → dist-Du5KbDTg.js} +1 -1
  52. package/dist-ksadk/assets/{dist-CTkYhw0e.js → dist-DxBl1V2_.js} +1 -1
  53. package/dist-ksadk/assets/{dist-BUvPmCJJ.js → dist-E1uwqlZY.js} +1 -1
  54. package/dist-ksadk/assets/{dist-C-4NaB6S.js → dist-HuJDn2Nr.js} +1 -1
  55. package/dist-ksadk/assets/{dist-DQSR5gJm.js → dist-MMIlBueM.js} +1 -1
  56. package/dist-ksadk/assets/{dist-Ps_8XMpQ.js → dist-U51Rn7ZW.js} +1 -1
  57. package/dist-ksadk/assets/{dist-BRaujO8W.js → dist-VLWgeZIu.js} +1 -1
  58. package/dist-ksadk/assets/{dist-BblTQEdU.js → dist-X8Mgnqit.js} +1 -1
  59. package/dist-ksadk/assets/{dist-DW_Mhac3.js → dist-glVlUB_d.js} +1 -1
  60. package/dist-ksadk/assets/{dist-AnEuKlWI.js → dist-q8rONmMl.js} +1 -1
  61. package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-BDy_T6BJ.js → ebnfDiagram-PWID7BFC-X4mBLaw3.js} +1 -1
  62. package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-Cb9mxU2v.js → erDiagram-SSCWMZ5O-ClybQoOy.js} +1 -1
  63. package/dist-ksadk/assets/eventmodeling-NTZA5JFV--IdqCKdV.js +1 -0
  64. package/dist-ksadk/assets/flowDiagram-A5DVABFB-BsidNZBX.js +1 -0
  65. package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-CI-NY47s.js → ganttDiagram-EL5Y4UJY-Dc_fWiA_.js} +1 -1
  66. package/dist-ksadk/assets/gitGraph-4MIJSDKK-BTqI4bBo.js +1 -0
  67. package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-DZBPuEz2.js → gitGraphDiagram-WWUBYQGX-0eEV_CEC.js} +1 -1
  68. package/dist-ksadk/assets/index-B0DeBpyZ.js +1132 -0
  69. package/dist-ksadk/assets/index-DEVfafsU.css +2 -0
  70. package/dist-ksadk/assets/info-A6RAGUB7-CXZCoW0H.js +1 -0
  71. package/dist-ksadk/assets/{infoDiagram-RXCK75RN-BGVB1ufk.js → infoDiagram-RXCK75RN-mZoyw4Xh.js} +1 -1
  72. package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-C-pPrser.js → ishikawaDiagram-5VMMS53U-CO8OkxgJ.js} +1 -1
  73. package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-mqH7Ax1g.js → journeyDiagram-EYS64GPL-Ci8GpXLK.js} +1 -1
  74. package/dist-ksadk/assets/{kanban-definition-3QL26DDD-D1g0NfmY.js → kanban-definition-3QL26DDD-lgD5AYON.js} +1 -1
  75. package/dist-ksadk/assets/{katex-DBFpex0b.js → katex-Chn0O-XC.js} +1 -1
  76. package/dist-ksadk/assets/{linear-H9vrIL3e.js → linear-ffygyi0f.js} +1 -1
  77. package/dist-ksadk/assets/{mermaid-parser.core-CTwOsmSy.js → mermaid-parser.core-CGPz1_57.js} +2 -2
  78. package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-P24ajxwA.js → mindmap-definition-FBJOCRG2-DRaJyZGQ.js} +1 -1
  79. package/dist-ksadk/assets/packet-AYTQ26CC-DoZlIRtk.js +1 -0
  80. package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-CIAjyVaA.js → pegDiagram-XKGWAZYB-BbQ2QDD3.js} +1 -1
  81. package/dist-ksadk/assets/pie-WAS4IAKB-Dl-IyMT_.js +1 -0
  82. package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-Cpg76g41.js → pieDiagram-E7YTZNPT-BcB_c4Ka.js} +1 -1
  83. package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-COa_uah3.js → quadrantDiagram-AXDQQJYC-CK3csxHk.js} +1 -1
  84. package/dist-ksadk/assets/radar-RG4KPBEZ-Bp8MemxX.js +1 -0
  85. package/dist-ksadk/assets/railroad-74A4TZTK-BmKyKako.js +1 -0
  86. package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-DhFitwOH.js +1 -0
  87. package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-TB8LQz8q.js +1 -0
  88. package/dist-ksadk/assets/railroad-peg-WCYAUIDC-B3J1Rtq9.js +1 -0
  89. package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-CDiUen7V.js → railroadDiagram-O6MQD6OU-D1YLglVU.js} +1 -1
  90. package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-4tmvHR-z.js → requirementDiagram-EFPCY7ZU-VeyqOcw3.js} +1 -1
  91. package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-cmOQFKfb.js → sankeyDiagram-P5KCCOFB-uskDVCah.js} +1 -1
  92. package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-C87BVo37.js → sequenceDiagram-WJ2MYXX4-CmoPC4aR.js} +1 -1
  93. package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-BD2400H2.js → sizeCapture-X5ZJPWSS-DzV4X5WN.js} +1 -1
  94. package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-DaxlblQk.js → stateDiagram-HBIQ2CUA-BJehrZbH.js} +1 -1
  95. package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-DkujIgVj.js +1 -0
  96. package/dist-ksadk/assets/{swimlanes-XN3QIQJK-M7GAwJZ9.js → swimlanes-XN3QIQJK-Bn4tEi27.js} +1 -1
  97. package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-Blb1TQ9Q.js +8 -0
  98. package/dist-ksadk/assets/{timeline-definition-24CTP7MA-Cq_BUN6-.js → timeline-definition-24CTP7MA-bSkaKxqF.js} +1 -1
  99. package/dist-ksadk/assets/treeView-Q6P3EWNA-C5Ez-6L4.js +1 -0
  100. package/dist-ksadk/assets/treemap-WGGIJYW6-WdNvoGQV.js +1 -0
  101. package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-BTAMWn-b.js → vennDiagram-4TSXK5OY-ClO6s5iT.js} +1 -1
  102. package/dist-ksadk/assets/wardley-WFR3VGLG-DCCceTuX.js +1 -0
  103. package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-Dnvpr9wl.js → wardleyDiagram-VM6X3IG4-CcaYar33.js} +1 -1
  104. package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-D838CKvY.js → xychartDiagram-S5SC5T6Z-DdiPl8uB.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-DHvWB_a-.js +1956 -0
  108. package/dist-lib/{ConnectedComposer-B2lm1bBF.js → ConnectedComposer-CuN3EUnU.js} +220 -217
  109. package/dist-lib/{ConnectedMessageList-BumlD3Zk.js → ConnectedMessageList-CT-MJJkJ.js} +419 -417
  110. package/dist-lib/{WorkspacePanelContainer-CcI-iqlE.js → WorkspacePanelContainer-Jg9bUmLJ.js} +324 -324
  111. package/dist-lib/{a2ui-CWVTKJ6O.js → a2ui-DridcTyF.js} +1656 -408
  112. package/dist-lib/chat-composer.js +2 -2
  113. package/dist-lib/chat-timeline.js +3 -3
  114. package/dist-lib/components/chat/A2UIActivityMessage.d.ts +1 -0
  115. package/dist-lib/components/chat/A2UIActivityMessage.d.ts.map +1 -1
  116. package/dist-lib/components/chat/ChatComposer.d.ts +2 -1
  117. package/dist-lib/components/chat/ChatComposer.d.ts.map +1 -1
  118. package/dist-lib/components/chat/ChatMessageList.d.ts.map +1 -1
  119. package/dist-lib/components/chat/ConnectedComposer.d.ts +2 -1
  120. package/dist-lib/components/chat/ConnectedComposer.d.ts.map +1 -1
  121. package/dist-lib/components/chat/ExecutionPermissionMenu.d.ts.map +1 -1
  122. package/dist-lib/components/chat/InteractionA2uiSurface.d.ts +6 -1
  123. package/dist-lib/components/chat/InteractionA2uiSurface.d.ts.map +1 -1
  124. package/dist-lib/components/chat/InteractionTray.d.ts +3 -1
  125. package/dist-lib/components/chat/InteractionTray.d.ts.map +1 -1
  126. package/dist-lib/components/chat/JsonSchemaInputForm.d.ts.map +1 -1
  127. package/dist-lib/components/chat/McpAuthorizationCard.d.ts +8 -0
  128. package/dist-lib/components/chat/McpAuthorizationCard.d.ts.map +1 -0
  129. package/dist-lib/components/ui/button.d.ts +12 -0
  130. package/dist-lib/components/ui/button.d.ts.map +1 -0
  131. package/dist-lib/components.js +13 -13
  132. package/dist-lib/conversation.js +2 -2
  133. package/dist-lib/core/api/facade.d.ts +1 -0
  134. package/dist-lib/core/api/facade.d.ts.map +1 -1
  135. package/dist-lib/core/api/types.d.ts +1 -0
  136. package/dist-lib/core/api/types.d.ts.map +1 -1
  137. package/dist-lib/core/conversation/presentation.d.ts.map +1 -1
  138. package/dist-lib/core/conversation/runtime-ingress.d.ts.map +1 -1
  139. package/dist-lib/core/interaction/a2ui-approval.d.ts +20 -0
  140. package/dist-lib/core/interaction/a2ui-approval.d.ts.map +1 -0
  141. package/dist-lib/core/interaction/adapters/agui.d.ts.map +1 -1
  142. package/dist-lib/core/interaction/adapters/normalize.d.ts +2 -0
  143. package/dist-lib/core/interaction/adapters/normalize.d.ts.map +1 -1
  144. package/dist-lib/core/interaction/adapters/session-events.d.ts.map +1 -1
  145. package/dist-lib/core/interaction/client.d.ts.map +1 -1
  146. package/dist-lib/core/interaction/legacy-a2ui.d.ts +5 -0
  147. package/dist-lib/core/interaction/legacy-a2ui.d.ts.map +1 -0
  148. package/dist-lib/core/interaction/pending.d.ts +4 -0
  149. package/dist-lib/core/interaction/pending.d.ts.map +1 -0
  150. package/dist-lib/core/mcp-authorization/contract.d.ts +5 -0
  151. package/dist-lib/core/mcp-authorization/contract.d.ts.map +1 -0
  152. package/dist-lib/core/mcp-authorization/normalize.d.ts +4 -0
  153. package/dist-lib/core/mcp-authorization/normalize.d.ts.map +1 -0
  154. package/dist-lib/core/mcp-authorization/recovery.d.ts +5 -0
  155. package/dist-lib/core/mcp-authorization/recovery.d.ts.map +1 -0
  156. package/dist-lib/core/mcp-authorization/types.d.ts +20 -0
  157. package/dist-lib/core/mcp-authorization/types.d.ts.map +1 -0
  158. package/dist-lib/core/run/agui.d.ts.map +1 -1
  159. package/dist-lib/core/run/engine.d.ts.map +1 -1
  160. package/dist-lib/core/teams/cloudContracts.d.ts +15 -15
  161. package/dist-lib/{feedback-CuC5jRi_.js → feedback-CaSZOBD2.js} +98 -86
  162. package/dist-lib/hooks/useAgentChat.d.ts.map +1 -1
  163. package/dist-lib/hooks/useInteractions.d.ts +1 -0
  164. package/dist-lib/hooks/useInteractions.d.ts.map +1 -1
  165. package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
  166. package/dist-lib/hooks.js +19 -18
  167. package/dist-lib/permission-2NpSBuq3.js +25 -0
  168. package/dist-lib/{persisted-session-history-Mg7yqvHj.js → persisted-session-history-D_1AtH5H.js} +536 -1473
  169. package/dist-lib/runtime.js +272 -270
  170. package/dist-lib/session-events-6PXUoAkP.js +1225 -0
  171. package/dist-lib/stores/bootstrap.d.ts.map +1 -1
  172. package/dist-lib/stores/execution-permission.d.ts +2 -0
  173. package/dist-lib/stores/execution-permission.d.ts.map +1 -1
  174. package/dist-lib/styles.css +1 -1
  175. package/dist-lib/types/capabilities.d.ts +4 -0
  176. package/dist-lib/types/capabilities.d.ts.map +1 -1
  177. package/dist-lib/{useSessionLifecycle-BsS84-O4.js → useSessionLifecycle-daQg0sqQ.js} +961 -1974
  178. package/dist-lib/utils/persisted-session-history.d.ts.map +1 -1
  179. package/dist-lib/utils/run-progress.d.ts.map +1 -1
  180. package/dist-lib/utils/workspace.d.ts +1 -1
  181. package/package.json +1 -1
  182. package/dist-ksadk/assets/architecture-7GRP2DOG-B_LhRes-.js +0 -1
  183. package/dist-ksadk/assets/channel-Bq55bwo_.js +0 -1
  184. package/dist-ksadk/assets/chunk-2Q5K7J3B-Dace2ujW.js +0 -1
  185. package/dist-ksadk/assets/classDiagram-DTDB5LWJ-l9qDDu33.js +0 -1
  186. package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-l9qDDu33.js +0 -1
  187. package/dist-ksadk/assets/cynefin-OW5HDTMX-jtPBpAp-.js +0 -1
  188. package/dist-ksadk/assets/eventmodeling-NTZA5JFV-DMz2Fvu-.js +0 -1
  189. package/dist-ksadk/assets/flowDiagram-A5DVABFB-clcQL_nf.js +0 -1
  190. package/dist-ksadk/assets/gitGraph-4MIJSDKK-DDQIXIFD.js +0 -1
  191. package/dist-ksadk/assets/index-4lKAP0g-.js +0 -1132
  192. package/dist-ksadk/assets/index-DMqhW2cV.css +0 -2
  193. package/dist-ksadk/assets/info-A6RAGUB7-CnWfuiwa.js +0 -1
  194. package/dist-ksadk/assets/packet-AYTQ26CC-C1REqCW5.js +0 -1
  195. package/dist-ksadk/assets/pie-WAS4IAKB-CzQ5iT3d.js +0 -1
  196. package/dist-ksadk/assets/radar-RG4KPBEZ-d5WzegFP.js +0 -1
  197. package/dist-ksadk/assets/railroad-74A4TZTK-fRIdWxzy.js +0 -1
  198. package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-7joOoyeT.js +0 -1
  199. package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-BAgBPuog.js +0 -1
  200. package/dist-ksadk/assets/railroad-peg-WCYAUIDC-Bq9jPeDZ.js +0 -1
  201. package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-BAnVAqLb.js +0 -1
  202. package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-DzYhp6ae.js +0 -8
  203. package/dist-ksadk/assets/treeView-Q6P3EWNA-Kl6y61te.js +0 -1
  204. package/dist-ksadk/assets/treemap-WGGIJYW6-Bt1G2wC0.js +0 -1
  205. package/dist-ksadk/assets/wardley-WFR3VGLG-CNYQTyja.js +0 -1
  206. package/dist-lib/AttachmentPreview-DkgZ9Upi.js +0 -1545
  207. package/dist-lib/execution-permission-UqLwHTJS.js +0 -89
  208. package/dist-lib/json-value-DnHp0582.js +0 -186
  209. package/dist-lib/tool-display-DTiRdghE.js +0 -64
@@ -1,8 +1,7 @@
1
- import { n as e, t } from "./json-value-DnHp0582.js";
2
- import { n } from "./tool-display-DTiRdghE.js";
3
- import { d as r, i, l as a, o, p as s, t as c, u as l } from "./reducer-mbYiX0wz.js";
1
+ import { f as e, n as t, p as n, r } from "./session-events-6PXUoAkP.js";
2
+ import { d as i, i as a, l as o, o as s, p as c, t as l, u } from "./reducer-mbYiX0wz.js";
4
3
  //#region src/core/conversation/safe-tool-value.ts
5
- var u = [
4
+ var d = [
6
5
  "authorization",
7
6
  "credential",
8
7
  "password",
@@ -20,14 +19,14 @@ var u = [
20
19
  "stack",
21
20
  "exception"
22
21
  ];
23
- function d(e) {
24
- return e.normalize("NFKC").toLowerCase().replace(/[^a-z0-9]/g, "");
25
- }
26
22
  function f(e) {
27
- let t = d(e);
28
- return u.some((e) => t.includes(e));
23
+ return e.normalize("NFKC").toLowerCase().replace(/[^a-z0-9]/g, "");
29
24
  }
30
25
  function p(e) {
26
+ let t = f(e);
27
+ return d.some((e) => t.includes(e));
28
+ }
29
+ function m(e) {
31
30
  let t = e.split(".");
32
31
  if (t.length > 4 || t.some((e) => e.length === 0)) return null;
33
32
  let n = t.map((e) => {
@@ -40,10 +39,10 @@ function p(e) {
40
39
  let r = n, i = 2 ** (8 * (5 - r.length));
41
40
  return r.slice(0, -1).some((e) => e > 255) || r.at(-1) >= i ? null : r.slice(0, -1).reduce((e, t, n) => e + t * 2 ** (8 * (3 - n)), r.at(-1));
42
41
  }
43
- function m(e) {
42
+ function h(e) {
44
43
  return e >>> 24 == 0 || e >>> 24 == 10 || e >>> 24 == 127 || e >>> 16 == 43518 || e >>> 16 == 49320 || e >>> 20 == 2753;
45
44
  }
46
- function h(e) {
45
+ function g(e) {
47
46
  let t;
48
47
  try {
49
48
  t = decodeURIComponent(e).toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
@@ -51,44 +50,44 @@ function h(e) {
51
50
  return !0;
52
51
  }
53
52
  if (t === "localhost" || t.endsWith(".localhost") || t.endsWith(".local") || t.endsWith(".internal")) return !0;
54
- let n = t.match(/^::ffff:(\d+(?:\.\d+){0,3})$/)?.[1], r = t.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i), i = r ? Number.parseInt(r[1], 16) * 65536 + Number.parseInt(r[2], 16) : p(n || t);
55
- if (i !== null) return m(i);
53
+ let n = t.match(/^::ffff:(\d+(?:\.\d+){0,3})$/)?.[1], r = t.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i), i = r ? Number.parseInt(r[1], 16) * 65536 + Number.parseInt(r[2], 16) : m(n || t);
54
+ if (i !== null) return h(i);
56
55
  let a = Number.parseInt(t.split(":", 1)[0], 16);
57
56
  return t === "::" || t === "::1" || Number.isInteger(a) && (a & 65024) == 64512 || Number.isInteger(a) && (a & 65472) == 65152;
58
57
  }
59
- function g(e) {
58
+ function _(e) {
60
59
  return (e.match(/https?:\/\/\[[^\]]+\](?::\d+)?[^\s<>{}"']*|https?:\/\/[^\s<>{}"'[\]()]+/gi) || []).some((e) => {
61
60
  let t = e.replace(/[.,;:!?]+$/, "").replace(/\\/g, "/");
62
61
  try {
63
62
  let e = new URL(t);
64
- return !!(e.username || e.password) || h(e.hostname);
63
+ return !!(e.username || e.password) || g(e.hostname);
65
64
  } catch {
66
65
  return !0;
67
66
  }
68
67
  });
69
68
  }
70
- function _(e, t = 0) {
71
- return y(e, t, 8192);
69
+ function v(e, t = 0) {
70
+ return b(e, t, 8192);
72
71
  }
73
- function v(e, t, n) {
74
- return y(e, 0, [
72
+ function y(e, t, n) {
73
+ return b(e, 0, [
75
74
  "langgraph",
76
75
  "adk",
77
76
  "codex"
78
77
  ].includes(String(t)) && !String(n || "").toLowerCase().includes("a2a") ? Infinity : 8192);
79
78
  }
80
- function y(e, t, n) {
81
- return t > 8 ? "[truncated]" : typeof e == "string" ? /bearer\s+\S+|traceback|(?:token|authorization|api[_ .-]?key|access[_ .-]?token|refresh[_ .-]?token|secretaccesskey|accesstoken|refreshtoken|cookie|password|secret)\s*["']?\s*[=:]/i.test(e) || g(e) ? "[redacted]" : e.length > n ? `${e.slice(0, n)}[truncated]` : e : Array.isArray(e) ? e.slice(0, 128).map((e) => y(e, t + 1, n)) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).slice(0, 128).filter(([e]) => !f(e)).map(([e, r]) => [e, y(r, t + 1, n)])) : e;
79
+ function b(e, t, n) {
80
+ return t > 8 ? "[truncated]" : typeof e == "string" ? /bearer\s+\S+|traceback|(?:token|authorization|api[_ .-]?key|access[_ .-]?token|refresh[_ .-]?token|secretaccesskey|accesstoken|refreshtoken|cookie|password|secret)\s*["']?\s*[=:]/i.test(e) || _(e) ? "[redacted]" : e.length > n ? `${e.slice(0, n)}[truncated]` : e : Array.isArray(e) ? e.slice(0, 128).map((e) => b(e, t + 1, n)) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).slice(0, 128).filter(([e]) => !p(e)).map(([e, r]) => [e, b(r, t + 1, n)])) : e;
82
81
  }
83
82
  //#endregion
84
83
  //#region src/core/conversation/runtime-ingress.ts
85
- var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e, t, n) => JSON.stringify([
84
+ var x = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, S = (e, t, n) => JSON.stringify([
86
85
  e,
87
86
  t,
88
87
  n
89
- ]), S = class {
90
- runtime = new e();
91
- flatChildren = new c();
88
+ ]), C = class {
89
+ runtime = new n();
90
+ flatChildren = new l();
92
91
  seen = /* @__PURE__ */ new Set();
93
92
  parents = /* @__PURE__ */ new Map();
94
93
  descriptorItemIds = /* @__PURE__ */ new Map();
@@ -98,11 +97,11 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
98
97
  sessionId;
99
98
  conversation;
100
99
  profile;
101
- constructor(e, t = new c(), n = "flat-v1") {
100
+ constructor(e, t = new l(), n = "flat-v1") {
102
101
  this.sessionId = e, this.conversation = t, this.profile = n;
103
102
  }
104
103
  identity(e, t, n, r = !1) {
105
- return this.profile === "agent-block-v1" || r ? x(e, t, n) : n;
104
+ return this.profile === "agent-block-v1" || r ? S(e, t, n) : n;
106
105
  }
107
106
  snapshot() {
108
107
  let e = this.conversation.snapshot();
@@ -120,21 +119,21 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
120
119
  if (!t || !n || !r) throw Error("RuntimeEvent identity missing");
121
120
  if (this.runId && this.runId !== t) throw Error("RuntimeEvent run identity changed");
122
121
  if (this.seen.has(r)) return null;
123
- let a = String(e.parent_scope_id ?? this.descriptors.get(n)?.parent_scope_id ?? this.parents.get(n) ?? ""), s = b(e.source), c = [
122
+ let a = String(e.parent_scope_id ?? this.descriptors.get(n)?.parent_scope_id ?? this.parents.get(n) ?? ""), o = x(e.source), c = [
124
123
  "adk",
125
124
  "langgraph",
126
125
  "codex"
127
- ].includes(String(s.framework)) && !this.descriptors.has(n);
126
+ ].includes(String(o.framework)) && !this.descriptors.has(n);
128
127
  if (c && a && i === "run.progress") return null;
129
128
  if (i.startsWith("run.") && (a || !c && this.rootScope && n !== this.rootScope)) throw Error("Child scope cannot transition root run");
130
129
  if (this.parents.has(n) && this.parents.get(n) !== a) throw Error("Scope parent changed");
131
130
  let l = String(e.item_id || ""), u = this.identity(t, n, l || r, !!a), d = Object.fromEntries(Object.entries({
132
- framework: s.framework,
133
- protocol: s.protocol,
134
- eventId: s.native_event_id,
135
- cursor: s.native_cursor,
136
- runId: s.native_run_id,
137
- itemId: s.native_item_id,
131
+ framework: o.framework,
132
+ protocol: o.protocol,
133
+ eventId: o.native_event_id,
134
+ cursor: o.native_cursor,
135
+ runId: o.native_run_id,
136
+ itemId: o.native_item_id,
138
137
  scopeId: n,
139
138
  runtimeItemId: l || void 0,
140
139
  parentScopeId: a || void 0,
@@ -153,7 +152,7 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
153
152
  payloadSchemaRef: "conversation.item.progress/v1",
154
153
  payload: {},
155
154
  nativeRef: d
156
- }, p = b(b(e.source).metadata), m = p.conversation_visibility ?? p.visibility;
155
+ }, p = x(x(e.source).metadata), m = p.conversation_visibility ?? p.visibility;
157
156
  if ([
158
157
  "public",
159
158
  "internal",
@@ -168,22 +167,22 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
168
167
  "run.failed",
169
168
  "run.canceled",
170
169
  "run.cancelled"
171
- ].includes(i) && (f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload.error = b(e.error).message || e.reason || ""), f.lifecycle = ["run.completed", "run.interrupted"].includes(i) ? "completed" : [
170
+ ].includes(i) && (f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload.error = x(e.error).message || e.reason || ""), f.lifecycle = ["run.completed", "run.interrupted"].includes(i) ? "completed" : [
172
171
  "run.failed",
173
172
  "run.canceled",
174
173
  "run.cancelled"
175
174
  ].includes(i) ? "failed" : "streaming";
176
175
  else {
177
176
  if (!l) throw Error("RuntimeEvent item identity missing");
178
- let d = b(e.snapshot || e.initial), p = i === "item.updated" ? [b(e.update)] : Array.isArray(d.parts) ? d.parts : [], h = p.map((e) => {
179
- let t = b(e);
177
+ let d = x(e.snapshot || e.initial), p = i === "item.updated" ? [x(e.update)] : Array.isArray(d.parts) ? d.parts : [], h = p.map((e) => {
178
+ let t = x(e);
180
179
  return {
181
180
  partId: String(t.part_id || "part"),
182
181
  contentType: String(t.content_type || "data"),
183
182
  ...typeof t.text == "string" ? { text: t.text } : {},
184
183
  value: t
185
184
  };
186
- }), g = p.map((e) => b(b(e).data)).find((e) => e.schema === "execution.scope/v1");
185
+ }), g = p.map((e) => x(x(e).data)).find((e) => e.schema === "execution.scope/v1");
187
186
  if (a && !g && !c) {
188
187
  let e = this.descriptorItemIds.get(n);
189
188
  if (!e) throw Error("Child content requires its scope descriptor first");
@@ -191,12 +190,12 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
191
190
  }
192
191
  if (g) {
193
192
  if (this.descriptorItemIds.has(n) && this.descriptorItemIds.get(n) !== u) throw Error("Scope descriptor item identity changed");
194
- let e = b(g.trigger_ref);
193
+ let e = x(g.trigger_ref);
195
194
  if (g.scope_id !== n || g.parent_scope_id !== a || e.scope_id !== a || !e.item_id || !e.call_id || !a) throw Error("Invalid scope descriptor locator");
196
195
  let t = this.runtime.snapshot().items.find((t) => t.scopeId === e.scope_id && t.itemId === e.item_id);
197
- if (t && !t.parts.some((t) => b(t.value).call_id === e.call_id)) throw Error("Scope trigger call mismatch");
196
+ if (t && !t.parts.some((t) => x(t.value).call_id === e.call_id)) throw Error("Scope trigger call mismatch");
198
197
  let r = this.descriptors.get(n);
199
- o({
198
+ s({
200
199
  ...f,
201
200
  kind: "agent",
202
201
  payloadSchemaRef: "conversation.item.agent/v1",
@@ -208,15 +207,15 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
208
207
  } : void 0), this.descriptors.set(n, g), this.descriptorItemIds.set(n, u);
209
208
  }
210
209
  for (let e of this.descriptors.values()) {
211
- let t = b(e.trigger_ref);
212
- if (t.scope_id === n && t.item_id === l && h.length && !h.some((e) => b(e.value).call_id === t.call_id)) throw Error("Scope trigger call mismatch");
210
+ let t = x(e.trigger_ref);
211
+ if (t.scope_id === n && t.item_id === l && h.length && !h.some((e) => x(e.value).call_id === t.call_id)) throw Error("Scope trigger call mismatch");
213
212
  }
214
- let y = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
215
- if (a && y && y.status !== "open") {
213
+ let _ = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
214
+ if (a && !c && _ && _.status !== "open") {
216
215
  if (i === "item.updated" || i === "item.started") throw Error("Remote item cannot reopen");
217
- if (Array.isArray(d.parts) && JSON.stringify(y.parts) !== JSON.stringify(h)) throw Error("Remote terminal content conflict");
216
+ if (Array.isArray(d.parts) && JSON.stringify(_.parts) !== JSON.stringify(h)) throw Error("Remote terminal content conflict");
218
217
  }
219
- let x = {
218
+ let b = {
220
219
  type: i.replaceAll(".", "_"),
221
220
  runId: t,
222
221
  scopeId: n,
@@ -232,7 +231,7 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
232
231
  op: e.op || "replace"
233
232
  } : {}
234
233
  };
235
- this.runtime.apply(x);
234
+ this.runtime.apply(b);
236
235
  let S = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
237
236
  if (!S || a && S.itemKind === "status" && S.status === "open" && !S.parts.length) return null;
238
237
  if (a && [
@@ -240,35 +239,35 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
240
239
  "tool_call",
241
240
  "tool_result"
242
241
  ].includes(S.itemKind) && !S.parts.length) return this.runId = t, this.parents.set(n, a), this.seen.add(r), null;
243
- let C = S.parts.map((e) => b(e.value)), w = C.map((e) => b(e.data)).find((e) => e.schema === "execution.scope/v1");
244
- if (f.lifecycle = S.status === "open" ? i === "item.started" ? "pending" : "streaming" : S.status, f.operation = ["completed", "failed"].includes(f.lifecycle) ? "completed" : i === "item.started" ? "append" : "replace", w) f.operation = ["completed", "failed"].includes(f.lifecycle) ? "completed" : "replace", f.kind = "agent", f.payloadSchemaRef = "conversation.item.agent/v1", f.payload = w, f.parentItemId = this.identity(t, String(b(w.trigger_ref).scope_id), String(b(w.trigger_ref).item_id), !!this.parents.get(String(b(w.trigger_ref).scope_id))), f.capabilityRef = "agent.block";
242
+ let C = S.parts.map((e) => x(e.value)), w = C.map((e) => x(e.data)).find((e) => e.schema === "execution.scope/v1");
243
+ if (f.lifecycle = S.status === "open" ? i === "item.started" ? "pending" : "streaming" : S.status, f.operation = ["completed", "failed"].includes(f.lifecycle) ? "completed" : i === "item.started" ? "append" : "replace", w) f.operation = ["completed", "failed"].includes(f.lifecycle) ? "completed" : "replace", f.kind = "agent", f.payloadSchemaRef = "conversation.item.agent/v1", f.payload = w, f.parentItemId = this.identity(t, String(x(w.trigger_ref).scope_id), String(x(w.trigger_ref).item_id), !!this.parents.get(String(x(w.trigger_ref).scope_id))), f.capabilityRef = "agent.block";
245
244
  else if (S.itemKind === "tool_call" || S.itemKind === "tool_result") {
246
245
  let e = C.find((e) => e.content_type === "tool_call"), t = C.find((e) => e.content_type === "tool_result");
247
246
  f.kind = "tool_call", f.capabilityRef = "tool.inspect", f.payloadSchemaRef = "conversation.item.tool-call/v1", f.payload = {
248
247
  ...e ? {
249
248
  callId: e.call_id,
250
249
  tool: e.name,
251
- args: _(e.arguments)
250
+ args: v(e.arguments)
252
251
  } : {},
253
252
  ...t ? {
254
253
  callId: t.call_id,
255
- output: v(t.result, s.framework, s.protocol),
254
+ output: y(t.result, o.framework, o.protocol),
256
255
  isError: t.is_error
257
256
  } : {},
258
257
  executionStatus: S.status === "failed" ? "failed" : t && S.status !== "open" ? t.is_error ? "failed" : "completed" : S.itemKind === "tool_result" ? "unknown" : "running",
259
258
  sourceKind: S.itemKind
260
259
  };
261
- } else if (S.itemKind === "data" && s.protocol === "a2ui") {
260
+ } else if (S.itemKind === "data" && o.protocol === "a2ui") {
262
261
  let e = C.find((e) => e.content_type === "data")?.data;
263
262
  f.kind = "a2ui", f.payloadSchemaRef = "conversation.item.a2ui/v1", f.payload = {
264
- surfaceId: String(b(s.metadata).surface_id || ""),
265
- ...typeof b(s.metadata).interaction_id == "string" ? { interactionId: b(s.metadata).interaction_id } : {},
263
+ surfaceId: String(x(o.metadata).surface_id || ""),
264
+ ...typeof x(o.metadata).interaction_id == "string" ? { interactionId: x(o.metadata).interaction_id } : {},
266
265
  data: Array.isArray(e) ? e : []
267
266
  };
268
267
  } else if (S.itemKind === "message" || S.itemKind === "reasoning" || S.itemKind === "artifact" && S.parts.length > 0 && S.parts.every((e) => e.contentType === "text")) {
269
- f.kind = S.itemKind === "reasoning" ? "reasoning" : b(b(e.source).metadata).native_item_kind === "userMessage" ? "user_message" : "assistant_text", f.payloadSchemaRef = `conversation.item.${f.kind}/v1`, f.payload = { text: S.parts.map((e) => e.text || "").join("") };
270
- let t = b(s.metadata);
271
- f.kind === "reasoning" && (t.public_summary === !0 || t.provider_reasoning === !0) && (f.payload.presentationSource = t.public_summary === !0 ? "public_summary" : "provider_reasoning"), i === "item.updated" && e.op === "append" && (f.operation = "append", f.payload.text = b(e.update).text || "");
268
+ f.kind = S.itemKind === "reasoning" ? "reasoning" : x(x(e.source).metadata).native_item_kind === "userMessage" ? "user_message" : "assistant_text", f.payloadSchemaRef = `conversation.item.${f.kind}/v1`, f.payload = { text: S.parts.map((e) => e.text || "").join("") };
269
+ let t = x(o.metadata);
270
+ f.kind === "reasoning" && (t.public_summary === !0 || t.provider_reasoning === !0) && (f.payload.presentationSource = t.public_summary === !0 ? "public_summary" : "provider_reasoning"), i === "item.updated" && e.op === "append" && (f.operation = "append", f.payload.text = x(e.update).text || "");
272
271
  } else if (S.itemKind === "artifact") {
273
272
  let e = C.find((e) => e.content_type === "artifact") || {};
274
273
  f.kind = "artifact", f.payloadSchemaRef = "conversation.item.artifact/v1", f.payload = {
@@ -277,7 +276,7 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
277
276
  uri: e.uri
278
277
  };
279
278
  } else if (S.status === "failed") {
280
- let t = b(e.error);
279
+ let t = x(e.error);
281
280
  f.kind = "error", f.payloadSchemaRef = "conversation.item.error/v1", f.payload = { error: String(t.message || t.code || "Remote call failed") };
282
281
  } else f.visibility = m === "public" ? "public" : "hidden", f.kind = "unknown", f.payloadSchemaRef = "conversation.item.unknown/v1", f.payload = { summary: "Unsupported runtime content" };
283
282
  }
@@ -286,11 +285,11 @@ var b = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, x = (e,
286
285
  };
287
286
  //#endregion
288
287
  //#region src/core/a2ui/history.ts
289
- function C(e, t) {
288
+ function w(e, t) {
290
289
  let n = e.map((e) => JSON.stringify(e)), r = t.map((e) => JSON.stringify(e));
291
290
  return n.every((e, t) => r[t] === e) ? t : r.every((e, t) => n[t] === e) ? e : [...e, ...t];
292
291
  }
293
- function w(e, t, n) {
292
+ function T(e, t, n) {
294
293
  let r = {
295
294
  ...t.runId || e?.runId ? { runId: t.runId || e?.runId } : {},
296
295
  ...t.interactionId || e?.interactionId ? { interactionId: t.interactionId || e?.interactionId } : {},
@@ -302,7 +301,7 @@ function w(e, t, n) {
302
301
  } : {
303
302
  ...t,
304
303
  ...r,
305
- messages: e ? C(e.messages, t.messages) : t.messages,
304
+ messages: e ? w(e.messages, t.messages) : t.messages,
306
305
  ...n || e?.batchIds || t.batchIds ? { batchIds: [...new Set([
307
306
  ...e?.batchIds || [],
308
307
  ...t.batchIds || [],
@@ -312,28 +311,28 @@ function w(e, t, n) {
312
311
  }
313
312
  //#endregion
314
313
  //#region src/core/a2ui/transcript.ts
315
- function T(e, t) {
314
+ function ee(e, t) {
316
315
  if (e.activity.surfaceId !== t.activity.surfaceId) return !1;
317
316
  let n = e.activity.interactionId, r = t.activity.interactionId;
318
317
  if (n && r) return n === r;
319
318
  let i = e.activity.runId || e.message.runId || e.message.invocationId, a = t.activity.runId || t.message.runId || t.message.invocationId;
320
319
  return i && a ? i === a : (e.activity.originMessageId || e.message.id) === (t.activity.originMessageId || t.message.id);
321
320
  }
322
- function ee(e, t) {
323
- let n = e.filter((e) => T(e, t));
321
+ function E(e, t) {
322
+ let n = e.filter((e) => ee(e, t));
324
323
  return n.length === 1 ? n[0] : void 0;
325
324
  }
326
- function te(e) {
325
+ function D(e) {
327
326
  if (!e.some((e) => e.aguiActivity || e.aguiActivities?.length)) return e;
328
327
  let t = /* @__PURE__ */ new Map(), n = !1, r = e.map((e) => {
329
328
  let r = (r) => {
330
- let i = t.get(r.surfaceId) || [], a = ee(i, {
329
+ let i = t.get(r.surfaceId) || [], a = E(i, {
331
330
  message: e,
332
331
  activity: r
333
332
  });
334
333
  if (a) {
335
334
  let t = a.activity;
336
- n = !0, t.messages = C(t.messages, r.messages), t.interactionId = r.interactionId || t.interactionId, t.runId ||= r.runId || e.runId || e.invocationId, t.batchIds = [...new Set([...t.batchIds || [], ...r.batchIds || []])];
335
+ n = !0, t.messages = w(t.messages, r.messages), t.interactionId = r.interactionId || t.interactionId, t.runId ||= r.runId || e.runId || e.invocationId, t.batchIds = [...new Set([...t.batchIds || [], ...r.batchIds || []])];
337
336
  return;
338
337
  }
339
338
  let o = r.runId || e.runId || e.invocationId, s = {
@@ -358,7 +357,7 @@ function te(e) {
358
357
  }
359
358
  //#endregion
360
359
  //#region src/core/conversation/presentation.ts
361
- var ne = {
360
+ var te = {
362
361
  user_message: "conversation.item.user_message/v1",
363
362
  assistant_text: "conversation.item.assistant_text/v1",
364
363
  reasoning: "conversation.item.reasoning/v1",
@@ -369,10 +368,10 @@ var ne = {
369
368
  a2ui: "conversation.item.a2ui/v1",
370
369
  error: "conversation.item.error/v1"
371
370
  };
372
- function re(e) {
371
+ function ne(e) {
373
372
  return e.lifecycle === "completed" || e.lifecycle === "failed";
374
373
  }
375
- var ie = new Set([
374
+ var re = new Set([
376
375
  "aborted",
377
376
  "canceled",
378
377
  "cancelled",
@@ -380,17 +379,17 @@ var ie = new Set([
380
379
  "incomplete",
381
380
  "interrupted"
382
381
  ]);
383
- function E(e) {
384
- if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !re(e)) return;
382
+ function O(e) {
383
+ if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !ne(e)) return;
385
384
  let t = typeof e.payload.status == "string" ? e.payload.status.toLowerCase() : "";
386
385
  if (t === "completed") return "completed";
387
- if (ie.has(t)) return "failed";
386
+ if (re.has(t)) return "failed";
388
387
  }
389
- function ae(e) {
390
- let t = ne[e.kind];
388
+ function ie(e) {
389
+ let t = te[e.kind];
391
390
  return t === void 0 || t === e.payloadSchemaRef;
392
391
  }
393
- function oe(e) {
392
+ function ae(e) {
394
393
  if (typeof e != "string" || e.length === 0) return null;
395
394
  try {
396
395
  let t = new URL(e);
@@ -399,7 +398,7 @@ function oe(e) {
399
398
  return null;
400
399
  }
401
400
  }
402
- function se(e) {
401
+ function oe(e) {
403
402
  return {
404
403
  id: e.itemId,
405
404
  parentId: e.parentItemId || null,
@@ -409,8 +408,8 @@ function se(e) {
409
408
  lifecycle: e.lifecycle
410
409
  };
411
410
  }
412
- function ce(e) {
413
- 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);
411
+ function se(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 = ae(e.payload.uri);
414
413
  return {
415
414
  artifactId: t,
416
415
  itemId: e.itemId,
@@ -424,31 +423,31 @@ function ce(e) {
424
423
  uri: i
425
424
  };
426
425
  }
427
- function D(e, t) {
426
+ function k(e, t) {
428
427
  let n = e.payload[t];
429
428
  return typeof n == "string" && n ? n : null;
430
429
  }
431
- function le(e) {
430
+ function A(e, t) {
432
431
  if (e.kind === "tool_call") {
433
- let t = D(e, "callId");
434
- if (t) return `tool:${JSON.stringify([
432
+ let n = k(e, "callId");
433
+ if (n) return `tool:${JSON.stringify([
435
434
  e.runId,
436
- e.nativeRef.scopeId || e.nativeRef.scope_id || "",
437
- t
435
+ t ?? (e.nativeRef.scopeId || e.nativeRef.scope_id || ""),
436
+ n
438
437
  ])}`;
439
438
  }
440
439
  if (e.kind === "approval") {
441
- let t = D(e, "interactionId");
440
+ let t = k(e, "interactionId");
442
441
  if (t) return `approval:${t}`;
443
442
  }
444
443
  if (e.kind === "a2ui") {
445
- let t = D(e, "surfaceId");
444
+ let t = k(e, "surfaceId");
446
445
  if (t) return `a2ui:${JSON.stringify([e.runId, t])}`;
447
446
  }
448
447
  return `item:${e.itemId}`;
449
448
  }
450
- function ue(e, t) {
451
- let n = re(e) && !re(t), r = e.kind === "a2ui" && t.kind === "a2ui" && Array.isArray(e.payload.data) && Array.isArray(t.payload.data) ? { data: C(e.payload.data, t.payload.data) } : {};
449
+ function ce(e, t) {
450
+ let n = ne(e) && !ne(t), r = e.kind === "a2ui" && t.kind === "a2ui" && Array.isArray(e.payload.data) && Array.isArray(t.payload.data) ? { data: w(e.payload.data, t.payload.data) } : {};
452
451
  return {
453
452
  ...e,
454
453
  ...t,
@@ -474,37 +473,49 @@ function ue(e, t) {
474
473
  } : {}
475
474
  };
476
475
  }
477
- function de(e) {
478
- let t = [], n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
479
- for (let i of e) {
480
- let e = le(i), a = i.kind === "a2ui" ? {
481
- surfaceId: D(i, "surfaceId") || "",
476
+ function le(e) {
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
+ 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" ? A(e, t) : void 0;
480
+ };
481
+ for (let t of e) {
482
+ if (t.nativeRef.framework === "langgraph" && t.payload.sourceKind === "tool_call") {
483
+ let e = A(t);
484
+ i.set(e, (i.get(e) ?? 0) + 1);
485
+ }
486
+ t.kind === "tool_call" && t.payload.sourceKind === "tool_result" && a.add(A(t));
487
+ let e = s(t);
488
+ e && o.set(e, (o.get(e) ?? 0) + 1);
489
+ }
490
+ for (let c of e) {
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") || "",
482
493
  messages: [],
483
- ...D(i, "interactionId") ? { interactionId: D(i, "interactionId") } : {}
484
- } : null, o = a ? {
494
+ ...k(c, "interactionId") ? { interactionId: k(c, "interactionId") } : {}
495
+ } : null, f = d ? {
485
496
  message: {
486
- id: i.itemId,
487
- runId: i.runId
497
+ id: c.itemId,
498
+ runId: c.runId
488
499
  },
489
- activity: a
490
- } : null, s = r.get(e) || [], c = o ? ee(s, o) : void 0, l = o ? c?.index : n.get(e);
491
- if (l === void 0) {
492
- o ? r.set(e, [...s, {
493
- ...o,
500
+ activity: d
501
+ } : null, p = r.get(u) || [], m = f ? E(p, f) : void 0, h = f ? m?.index : n.get(u);
502
+ if (h === void 0) {
503
+ f ? r.set(u, [...p, {
504
+ ...f,
494
505
  index: t.length
495
- }]) : n.set(e, t.length), t.push({
496
- key: o ? `${e}:${i.itemId}` : e,
497
- item: i,
498
- sourceItemIds: [i.itemId]
506
+ }]) : n.set(u, t.length), t.push({
507
+ key: f ? `${u}:${c.itemId}` : u,
508
+ item: c,
509
+ sourceItemIds: [c.itemId]
499
510
  });
500
511
  continue;
501
512
  }
502
- c && a?.interactionId && (c.activity.interactionId = a.interactionId);
503
- let u = t[l];
504
- t[l] = {
505
- key: u.key,
506
- item: ue(u.item, i),
507
- sourceItemIds: [...new Set([...u.sourceItemIds, i.itemId])]
513
+ m && d?.interactionId && (m.activity.interactionId = d.interactionId);
514
+ let g = t[h];
515
+ t[h] = {
516
+ key: g.key,
517
+ item: ce(g.item, c),
518
+ sourceItemIds: [...new Set([...g.sourceItemIds, c.itemId])]
508
519
  };
509
520
  }
510
521
  return t.map((t) => t.item.kind === "tool_call" ? {
@@ -518,29 +529,29 @@ function de(e) {
518
529
  }
519
530
  } : t);
520
531
  }
521
- function fe(e, t) {
532
+ function j(e, t) {
522
533
  let n = e.payload.trigger_ref;
523
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)) : [];
524
535
  }
525
- function pe(e) {
526
- 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 ue(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) => j(t, e).map((e) => e.itemId))), a = e.filter((e) => !r(e) && !i.has(e.itemId));
527
538
  return a.sort((t, n) => {
528
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);
529
540
  return r(t) - r(n);
530
- }), de(a).map((t) => {
541
+ }), le(a).map((t) => {
531
542
  if (t.item.kind !== "agent") return t;
532
- let n = de(e.filter((e) => r(e) === t.item && !i.has(e.itemId)));
543
+ let n = le(e.filter((e) => r(e) === t.item && !i.has(e.itemId)));
533
544
  return {
534
545
  ...t,
535
- sourceItemIds: [...new Set([...fe(t.item, e).map((e) => e.itemId), ...t.sourceItemIds])],
546
+ sourceItemIds: [...new Set([...j(t.item, e).map((e) => e.itemId), ...t.sourceItemIds])],
536
547
  children: n
537
548
  };
538
549
  });
539
550
  }
540
- function me(e, t = {}) {
551
+ function de(e, t = {}) {
541
552
  let n = e.items.filter((e) => e.visibility === "public" || t.includeInternal === !0 && e.visibility === "internal");
542
553
  if (t.profile === "flat-v1" && n.some((e) => e.kind === "agent")) {
543
- 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) => E(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) => j(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;
544
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)));
545
556
  let s = a.filter((e) => e.kind === "assistant_text");
546
557
  if (i && !s.some((e) => e.payload.text) && Array.isArray(o)) {
@@ -556,13 +567,13 @@ function me(e, t = {}) {
556
567
  }
557
568
  n = a.filter((e) => e.kind !== "assistant_text" || !!i);
558
569
  }
559
- let r = n.filter(ae), i = n.filter((e) => !ae(e)), a = new Set([
570
+ let r = n.filter(ie), i = n.filter((e) => !ie(e)), a = new Set([
560
571
  "user_message",
561
572
  "assistant_text",
562
573
  "reasoning"
563
- ]), 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) => E(e) !== void 0);
574
+ ]), o = r.filter((e) => a.has(e.kind)).map(oe), 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);
564
575
  return {
565
- timeline: pe(r.filter((e) => e.kind !== "progress")),
576
+ timeline: ue(r.filter((e) => e.kind !== "progress")),
566
577
  output: c("assistant_text"),
567
578
  reasoning: c("reasoning"),
568
579
  textItems: o,
@@ -570,7 +581,7 @@ function me(e, t = {}) {
570
581
  approvalItems: r.filter((e) => e.kind === "approval"),
571
582
  structuredInputItems: r.filter((e) => e.kind === "progress" && e.payloadSchemaRef === "conversation.item.structured-input/v1"),
572
583
  a2uiItems: r.filter((e) => e.kind === "a2ui"),
573
- artifacts: r.filter((e) => e.kind === "artifact").map(ce),
584
+ artifacts: r.filter((e) => e.kind === "artifact").map(se),
574
585
  fallbacks: [...l.map((e) => ({
575
586
  id: e.itemId,
576
587
  title: "Unsupported content",
@@ -583,22 +594,22 @@ function me(e, t = {}) {
583
594
  failed: !0
584
595
  }))],
585
596
  runId: n.at(-1)?.runId || "",
586
- terminalStatus: d ? E(d) : void 0
597
+ terminalStatus: d ? O(d) : void 0
587
598
  };
588
599
  }
589
600
  //#endregion
590
601
  //#region src/core/conversation/client.ts
591
- var O = 8;
592
- function k(e) {
602
+ var M = 8;
603
+ function N(e) {
593
604
  return typeof e == "object" && e && !Array.isArray(e) ? e : null;
594
605
  }
595
- function A(e) {
596
- if (e?.aborted) throw new s("conversation_aborted", "Conversation request was aborted.");
606
+ function P(e) {
607
+ if (e?.aborted) throw new c("conversation_aborted", "Conversation request was aborted.");
597
608
  }
598
- function he(e, t) {
609
+ function fe(e, t) {
599
610
  return t?.aborted === !0 || e instanceof Error && e.name === "AbortError";
600
611
  }
601
- function ge(e) {
612
+ function pe(e) {
602
613
  let t = e.trim().replace(/\/+$/, "");
603
614
  if (!t) return "";
604
615
  if (!t.includes("://")) return t.startsWith("/") ? t : `/${t}`;
@@ -607,81 +618,81 @@ function ge(e) {
607
618
  if (e.protocol !== "http:" && e.protocol !== "https:" || e.username || e.password) throw Error("unsafe URL");
608
619
  return e.toString().replace(/\/$/, "");
609
620
  } catch (e) {
610
- throw new s("conversation_contract_mismatch", "Conversation base URL must be an HTTP(S) URL without embedded credentials.", { cause: e });
621
+ throw new c("conversation_contract_mismatch", "Conversation base URL must be an HTTP(S) URL without embedded credentials.", { cause: e });
611
622
  }
612
623
  }
613
- function _e(e) {
624
+ function me(e) {
614
625
  return Math.min(200 * 2 ** Math.max(0, e - 1), 2e3);
615
626
  }
616
- function ve(e) {
627
+ function he(e) {
617
628
  return new Promise((t) => {
618
629
  setTimeout(t, e);
619
630
  });
620
631
  }
621
- async function ye(e, t, n) {
622
- if (A(n), !n) {
632
+ async function ge(e, t, n) {
633
+ if (P(n), !n) {
623
634
  await e(t);
624
635
  return;
625
636
  }
626
637
  await new Promise((r, i) => {
627
- let a = () => i(new s("conversation_aborted", "Conversation request was aborted."));
638
+ let a = () => i(new c("conversation_aborted", "Conversation request was aborted."));
628
639
  n.addEventListener("abort", a, { once: !0 }), e(t).then(r, i).finally(() => {
629
640
  n.removeEventListener("abort", a);
630
641
  });
631
642
  });
632
643
  }
633
- function be(e, t, n, r, i) {
644
+ function _e(e, t, n, r, i) {
634
645
  let a = i ? i.snapshot() : e.snapshot();
635
646
  return {
636
647
  cursor: t,
637
648
  runId: n,
638
649
  state: a,
639
- presentation: me(a, { profile: r })
650
+ presentation: de(a, { profile: r })
640
651
  };
641
652
  }
642
- function xe(e, t) {
653
+ function ve(e, t) {
643
654
  let n, r = [];
644
655
  for (let t of e.split(/\r?\n/)) {
645
656
  let e = t.endsWith("\r") ? t.slice(0, -1) : t;
646
657
  if (!e || e.startsWith(":")) continue;
647
- let i = e.indexOf(":"), a = i < 0 ? e : e.slice(0, i), o = i < 0 ? "" : e.slice(i + 1), c = o.startsWith(" ") ? o.slice(1) : o;
658
+ let i = e.indexOf(":"), a = i < 0 ? e : e.slice(0, i), o = i < 0 ? "" : e.slice(i + 1), s = o.startsWith(" ") ? o.slice(1) : o;
648
659
  if (a === "id") {
649
- if (!/^\d+$/.test(c) || !Number.isSafeInteger(Number(c))) throw new s("conversation_stream_error", "Conversation stream contains an invalid replay cursor.");
650
- n = Number(c);
651
- } else a === "data" && r.push(c);
660
+ if (!/^\d+$/.test(s) || !Number.isSafeInteger(Number(s))) throw new c("conversation_stream_error", "Conversation stream contains an invalid replay cursor.");
661
+ n = Number(s);
662
+ } else a === "data" && r.push(s);
652
663
  }
653
664
  if (r.length === 0) return;
654
665
  let i = r.join("\n");
655
666
  if (!i || i === "[DONE]") return;
656
- let o;
667
+ let a;
657
668
  try {
658
- o = JSON.parse(i);
669
+ a = JSON.parse(i);
659
670
  } catch (e) {
660
- throw new s("conversation_contract_mismatch", "Conversation stream contains invalid JSON.", { cause: e });
671
+ throw new c("conversation_contract_mismatch", "Conversation stream contains invalid JSON.", { cause: e });
661
672
  }
662
- let c = k(o), l = k(c?.runtimeEvent) || k(c?.runtime_event) || (c?.schema_version === 2 ? c : null);
663
- if (!c || c.conversationItem === void 0 && !l) {
673
+ let s = N(a), l = N(s?.runtimeEvent) || N(s?.runtime_event) || (s?.schema_version === 2 ? s : null);
674
+ if (!s || s.conversationItem === void 0 && !l) {
664
675
  n !== void 0 && (t.cursor = Math.max(t.cursor, n));
665
676
  return;
666
677
  }
667
- if (n === void 0) throw new s("conversation_stream_error", "Canonical conversation items require an SSE replay cursor.");
668
- let u = c.conversationItem === void 0 ? "runtime" : "native";
678
+ if (n === void 0) throw new c("conversation_stream_error", "Canonical conversation items require an SSE replay cursor.");
679
+ let u = s.conversationItem === void 0 ? "runtime" : "native";
669
680
  if (t.lane && t.lane !== u) {
670
681
  t.cursor = Math.max(t.cursor, n);
671
682
  return;
672
683
  }
673
684
  let d;
674
685
  try {
675
- d = u === "native" ? a(c.conversationItem) : t.runtime.apply(l);
686
+ d = u === "native" ? o(s.conversationItem) : t.runtime.apply(l);
676
687
  } catch (e) {
677
- throw new s("conversation_contract_mismatch", "Runtime conversation identity or lifecycle invariant failed.", { cause: e });
688
+ throw new c("conversation_contract_mismatch", "Runtime conversation identity or lifecycle invariant failed.", { cause: e });
678
689
  }
679
690
  if (u === "runtime" && !d) {
680
691
  t.cursor = Math.max(t.cursor, n);
681
692
  return;
682
693
  }
683
- if (!d) throw new s("conversation_contract_mismatch", "Conversation stream item does not match conversation.ksadk.io/v1.");
684
- if (t.runId && t.runId !== d.runId) throw new s("conversation_contract_mismatch", "Conversation stream changed canonical run identity.", {
694
+ if (!d) throw new c("conversation_contract_mismatch", "Conversation stream item does not match conversation.ksadk.io/v1.");
695
+ if (t.runId && t.runId !== d.runId) throw new c("conversation_contract_mismatch", "Conversation stream changed canonical run identity.", {
685
696
  runId: t.runId,
686
697
  cursor: t.cursor
687
698
  });
@@ -690,28 +701,28 @@ function xe(e, t) {
690
701
  try {
691
702
  f = u === "runtime" ? !0 : t.reducer.apply(d);
692
703
  } catch (e) {
693
- throw new s("conversation_contract_mismatch", "Conversation identity or lifecycle invariant failed.", { cause: e });
704
+ throw new c("conversation_contract_mismatch", "Conversation identity or lifecycle invariant failed.", { cause: e });
694
705
  }
695
- t.cursor = Math.max(t.cursor, n), f && !(t.profile === "flat-v1" && d.nativeRef.parentScopeId) && t.options.onItem?.(d), t.options.onUpdate?.(be(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?.(_e(t.reducer, t.cursor, t.runId, t.profile, t.lane === "runtime" ? t.runtime : void 0));
696
707
  }
697
- async function Se(e, t) {
698
- if (!e.body) throw new s("conversation_stream_error", "Conversation response has no event stream body.");
708
+ async function ye(e, t) {
709
+ if (!e.body) throw new c("conversation_stream_error", "Conversation response has no event stream body.");
699
710
  let n = e.body.getReader(), r = new TextDecoder(), i = "";
700
711
  try {
701
712
  for (;;) {
702
- A(t.options.signal);
713
+ P(t.options.signal);
703
714
  let { value: e, done: a } = await n.read();
704
715
  if (a) break;
705
716
  i += r.decode(e, { stream: !0 });
706
717
  let o = /\r?\n\r?\n/.exec(i);
707
718
  for (; o?.index !== void 0;) {
708
719
  let e = o.index, n = o[0].length;
709
- xe(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);
710
721
  }
711
722
  }
712
- i += r.decode(), i.trim() && xe(i, t);
723
+ i += r.decode(), i.trim() && ve(i, t);
713
724
  } catch (e) {
714
- throw e instanceof s ? e : (he(e, t.options.signal) && A(t.options.signal), new s("conversation_stream_error", "Conversation event stream was interrupted.", {
725
+ throw e instanceof c ? e : (fe(e, t.options.signal) && P(t.options.signal), new c("conversation_stream_error", "Conversation event stream was interrupted.", {
715
726
  cause: e,
716
727
  runId: t.runId || void 0,
717
728
  cursor: t.cursor
@@ -720,10 +731,10 @@ async function Se(e, t) {
720
731
  n.releaseLock();
721
732
  }
722
733
  }
723
- function Ce(e) {
724
- return e.state.items.some((e) => E(e) !== void 0);
734
+ function be(e) {
735
+ return e.state.items.some((e) => O(e) !== void 0);
725
736
  }
726
- var we = class {
737
+ var xe = class {
727
738
  fetcher;
728
739
  ingressLane;
729
740
  rendererCatalog;
@@ -732,61 +743,61 @@ var we = class {
732
743
  sleep;
733
744
  retryDelayMs;
734
745
  constructor(e = {}) {
735
- if (!Number.isInteger(e.maxReconnects ?? O) || (e.maxReconnects ?? O) < 0 || (e.maxReconnects ?? O) > 32) throw new s("conversation_contract_mismatch", "Conversation reconnect limit must be an integer from 0 to 32.");
736
- this.fetcher = e.fetch, this.rendererCatalog = e.rendererCatalog, this.ingressLane = e.ingressLane, this.baseUrl = ge(e.baseUrl || ""), this.maxReconnects = e.maxReconnects ?? O, 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 c("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 = pe(e.baseUrl || ""), this.maxReconnects = e.maxReconnects ?? M, this.sleep = e.sleep || he, this.retryDelayMs = e.retryDelayMs || me;
737
748
  }
738
749
  fetch() {
739
750
  if (this.fetcher) return this.fetcher;
740
751
  if (typeof globalThis.fetch == "function") return globalThis.fetch.bind(globalThis);
741
- throw new s("conversation_http_error", "No fetch implementation is available for the conversation client.");
752
+ throw new c("conversation_http_error", "No fetch implementation is available for the conversation client.");
742
753
  }
743
754
  url(e) {
744
755
  return `${this.baseUrl}${e}`;
745
756
  }
746
757
  async request(e, t, n, r = "conversation_stream_error") {
747
- A(n);
758
+ P(n);
748
759
  try {
749
760
  return await this.fetch()(e, t);
750
761
  } catch (e) {
751
- throw e instanceof s ? e : (he(e, n) && A(n), new s(r, "Conversation network request failed.", { cause: e }));
762
+ throw e instanceof c ? e : (fe(e, n) && P(n), new c(r, "Conversation network request failed.", { cause: e }));
752
763
  }
753
764
  }
754
765
  assertOk(e) {
755
- if (!e.ok) throw new s("conversation_http_error", `Conversation endpoint returned HTTP ${e.status}.`, { status: e.status });
766
+ if (!e.ok) throw new c("conversation_http_error", `Conversation endpoint returned HTTP ${e.status}.`, { status: e.status });
756
767
  }
757
768
  async getSurface(e, t, n = {}) {
758
- if (!e || !t) throw new s("conversation_contract_mismatch", "Agent and session identities are required to get a conversation surface.");
769
+ if (!e || !t) throw new c("conversation_contract_mismatch", "Agent and session identities are required to get a conversation surface.");
759
770
  let r = n.signal ? { signal: n.signal } : void 0, i = await this.request(this.url(`/api/v1/agents/${encodeURIComponent(e)}/conversation-surface?sessionId=${encodeURIComponent(t)}`), r, n.signal, "conversation_http_error");
760
771
  this.assertOk(i);
761
772
  let a;
762
773
  try {
763
774
  a = await i.json();
764
775
  } catch (e) {
765
- throw new s("conversation_contract_mismatch", "Conversation surface response is not valid JSON.", { cause: e });
776
+ throw new c("conversation_contract_mismatch", "Conversation surface response is not valid JSON.", { cause: e });
766
777
  }
767
- let o = k(a), c = l(o?.surface);
768
- if (!o || typeof o.buildId != "string" || !o.buildId || !c) throw new s("conversation_contract_mismatch", "Conversation surface response does not match conversation.ksadk.io/v1.");
778
+ let o = N(a), s = u(o?.surface);
779
+ if (!o || typeof o.buildId != "string" || !o.buildId || !s) throw new c("conversation_contract_mismatch", "Conversation surface response does not match conversation.ksadk.io/v1.");
769
780
  return {
770
781
  buildId: o.buildId,
771
- surface: c
782
+ surface: s
772
783
  };
773
784
  }
774
785
  async streamTurn(e) {
775
- A(e.signal);
776
- let t = i(e.bootstrap.surface, this.rendererCatalog), n = {
786
+ P(e.signal);
787
+ let t = a(e.bootstrap.surface, this.rendererCatalog), n = {
777
788
  ...e.input,
778
789
  ...t === "agent-block-v1" || e.input.extensions?.["ksadk.presentation"] ? { extensions: {
779
790
  ...e.input.extensions,
780
791
  "ksadk.presentation": { profile: t }
781
792
  } } : {}
782
793
  };
783
- r(e.bootstrap.surface, n);
784
- let a = e.bootstrap.surface.outputs.find((e) => e.name === "agent.block"), o = a?.mode === "native" ? "native" : a?.mode === "translated" ? "runtime" : void 0;
785
- if (o && this.ingressLane && o !== this.ingressLane) throw new s("conversation_contract_mismatch", "Configured ingress lane disagrees with the conversation surface.");
786
- let l = o || this.ingressLane || "native", u = new c(), d = {
794
+ i(e.bootstrap.surface, n);
795
+ let r = e.bootstrap.surface.outputs.find((e) => e.name === "agent.block"), o = r?.mode === "native" ? "native" : r?.mode === "translated" ? "runtime" : void 0;
796
+ if (o && this.ingressLane && o !== this.ingressLane) throw new c("conversation_contract_mismatch", "Configured ingress lane disagrees with the conversation surface.");
797
+ let s = o || this.ingressLane || "native", u = new l(), d = {
787
798
  profile: t,
788
- lane: l,
789
- runtime: new S(n.sessionId, u, t),
799
+ lane: s,
800
+ runtime: new C(n.sessionId, u, t),
790
801
  cursor: 0,
791
802
  runId: "",
792
803
  reducer: u,
@@ -802,29 +813,29 @@ var we = class {
802
813
  }, p = await this.request(this.url(`/api/v1/builds/${encodeURIComponent(e.bootstrap.buildId)}/conversation:stream`), f, e.signal);
803
814
  this.assertOk(p);
804
815
  try {
805
- await Se(p, d);
816
+ await ye(p, d);
806
817
  } catch (e) {
807
- if (!(e instanceof s) || e.code !== "conversation_stream_error" || !d.runId) throw e;
818
+ if (!(e instanceof c) || e.code !== "conversation_stream_error" || !d.runId) throw e;
808
819
  }
809
- let m = be(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0);
810
- if (Ce(m)) return m;
811
- if (!d.runId) throw new s("conversation_run_identity_missing", "The stream ended before a canonical item supplied its run identity.", { cursor: d.cursor });
820
+ let m = _e(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0);
821
+ if (be(m)) return m;
822
+ if (!d.runId) throw new c("conversation_run_identity_missing", "The stream ended before a canonical item supplied its run identity.", { cursor: d.cursor });
812
823
  for (let t = 1; t <= this.maxReconnects; t += 1) {
813
- await ye(this.sleep, this.retryDelayMs(t), e.signal), A(e.signal);
824
+ await ge(this.sleep, this.retryDelayMs(t), e.signal), P(e.signal);
814
825
  let n;
815
826
  try {
816
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" : ""}`), {
817
828
  method: "GET",
818
829
  headers: { "Last-Event-ID": String(d.cursor) },
819
830
  ...e.signal ? { signal: e.signal } : {}
820
- }, e.signal), this.assertOk(n), await Se(n, d);
831
+ }, e.signal), this.assertOk(n), await ye(n, d);
821
832
  } catch (e) {
822
- if (e instanceof s && e.code === "conversation_aborted" || e instanceof s && e.code === "conversation_contract_mismatch" || e instanceof s && e.code === "conversation_http_error" && e.status !== void 0 && e.status < 500) throw e;
833
+ if (e instanceof c && e.code === "conversation_aborted" || e instanceof c && e.code === "conversation_contract_mismatch" || e instanceof c && e.code === "conversation_http_error" && e.status !== void 0 && e.status < 500) throw e;
823
834
  continue;
824
835
  }
825
- if (m = be(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0), Ce(m)) return m;
836
+ if (m = _e(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0), be(m)) return m;
826
837
  }
827
- throw new s("conversation_reconnect_exhausted", "Conversation replay stopped after the configured reconnect limit.", {
838
+ throw new c("conversation_reconnect_exhausted", "Conversation replay stopped after the configured reconnect limit.", {
828
839
  runId: d.runId,
829
840
  cursor: d.cursor
830
841
  });
@@ -832,13 +843,13 @@ var we = class {
832
843
  };
833
844
  //#endregion
834
845
  //#region src/core/conversation/renderer-registry.ts
835
- function Te(e, t) {
846
+ function Se(e, t) {
836
847
  if (!e.trim()) throw Error(`trusted conversation renderer ${t} must not be empty`);
837
848
  }
838
- function Ee(e) {
849
+ function Ce(e) {
839
850
  let t = /* @__PURE__ */ new Map();
840
851
  for (let n of e) {
841
- if (Te(n.id, "id"), Te(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");
842
853
  if (t.has(n.schemaRef)) throw Error(`duplicate trusted conversation renderer schemaRef: ${n.schemaRef}`);
843
854
  t.set(n.schemaRef, Object.freeze({
844
855
  ...n,
@@ -856,14 +867,14 @@ function Ee(e) {
856
867
  }
857
868
  });
858
869
  }
859
- var De = Ee([{
870
+ var we = Ce([{
860
871
  id: "ksadk.agent-block",
861
872
  schemaRef: "conversation.item.agent/v1",
862
873
  kinds: ["agent"]
863
874
  }]);
864
875
  //#endregion
865
876
  //#region src/utils/history-tool-facts.ts
866
- function j(e, t) {
877
+ function F(e, t) {
867
878
  let n = (e) => e === "completed" || e === "error", r = t.output === void 0 ? e.output : t.output;
868
879
  return {
869
880
  args: t.args || e.args,
@@ -871,7 +882,7 @@ function j(e, t) {
871
882
  status: n(e.status) && !n(t.status) ? e.status : t.status
872
883
  };
873
884
  }
874
- function M(e) {
885
+ function I(e) {
875
886
  let t = e.map((e) => ({
876
887
  ...e,
877
888
  tools: e.tools ? { ...e.tools } : void 0
@@ -896,11 +907,11 @@ function M(e) {
896
907
  let r = e.message.tools[e.key], i = n ? {
897
908
  ...t,
898
909
  ...r,
899
- ...j(t, r)
910
+ ...F(t, r)
900
911
  } : {
901
912
  ...r,
902
913
  ...t,
903
- ...j(r, t)
914
+ ...F(r, t)
904
915
  };
905
916
  e.message.tools[e.key] = i, e.message.blocks = e.message.blocks?.map((e) => e.type === "tool" && e.extra?.callId === t.callId ? {
906
917
  ...e,
@@ -939,18 +950,18 @@ function M(e) {
939
950
  }
940
951
  //#endregion
941
952
  //#region src/utils/transcript-order.ts
942
- var N = (e) => e.runId || e.invocationId;
943
- function P(e) {
953
+ var L = (e) => e.runId || e.invocationId;
954
+ function R(e) {
944
955
  let t = /* @__PURE__ */ new Map();
945
956
  for (let n of e) {
946
- let e = N(n), r = n.historyOrder?.group;
957
+ let e = L(n), r = n.historyOrder?.group;
947
958
  e && r !== void 0 && t.set(e, Math.min(r, t.get(e) ?? r));
948
959
  }
949
960
  let n = e.map((e, n) => ({
950
961
  message: e,
951
962
  index: n,
952
963
  seq: e.historyOrder?.seq,
953
- group: e.historyOrder?.group ?? t.get(N(e) || "") ?? e.historyOrder?.seq,
964
+ group: e.historyOrder?.group ?? t.get(L(e) || "") ?? e.historyOrder?.seq,
954
965
  part: e.historyOrder?.index || 0
955
966
  })), r, i = n.map(() => void 0);
956
967
  for (let e = n.length - 1; e >= 0; e--) i[e] = r, n[e].group !== void 0 && (r = n[e].group);
@@ -965,13 +976,13 @@ function P(e) {
965
976
  side: 0
966
977
  })).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);
967
978
  }
968
- function Oe(e, t) {
979
+ function Te(e, t) {
969
980
  if (!t) return !0;
970
981
  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];
971
982
  return Object.keys(e).some(n) || Object.keys(t).some(n);
972
983
  }
973
- function ke(e, t, n) {
974
- 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([N(e), e.responseId]), s = new Map(i.filter((e) => e.responseId).map((e) => [o(e), e.feedback])), c = (e) => e.map((e) => {
984
+ function Ee(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([L(e), e.responseId]), s = new Map(i.filter((e) => e.responseId).map((e) => [o(e), e.feedback])), c = (e) => e.map((e) => {
975
986
  if (a.has(e.id)) return {
976
987
  ...e,
977
988
  feedback: a.get(e.id)
@@ -981,19 +992,19 @@ function ke(e, t, n) {
981
992
  ...e,
982
993
  feedback: s.get(t)
983
994
  } : e;
984
- }), l = n.filter((e) => Oe(e, r.get(e.id)));
985
- if (!l.length) return te(M(c(e)));
986
- let u = new Set(l.map(N).filter(Boolean)), d = new Set(l.map((e) => e.id)), f = n.filter((e) => u.has(N(e)) || d.has(e.id)), p = e;
995
+ }), l = n.filter((e) => Te(e, r.get(e.id)));
996
+ if (!l.length) return D(I(c(e)));
997
+ let u = new Set(l.map(L).filter(Boolean)), d = new Set(l.map((e) => e.id)), f = n.filter((e) => u.has(L(e)) || d.has(e.id)), p = e;
987
998
  for (let t of u) {
988
- let n = f.filter((e) => N(e) === t), r = e.filter((e) => N(e) === t), i = p.findIndex((e) => N(e) === t), a = n.some((e) => e.role === "user") ? [] : r.filter((e) => e.role === "user");
989
- p = p.filter((e) => N(e) !== t);
999
+ let n = f.filter((e) => L(e) === t), r = e.filter((e) => L(e) === t), i = p.findIndex((e) => L(e) === t), a = n.some((e) => e.role === "user") ? [] : r.filter((e) => e.role === "user");
1000
+ p = p.filter((e) => L(e) !== t);
990
1001
  let o = i < 0 ? p.length : Math.min(i, p.length);
991
1002
  p.splice(o, 0, ...a, ...n.map((e) => ({
992
1003
  ...e,
993
1004
  historyOrder: e.historyOrder || r.find((t) => t.id === e.id)?.historyOrder
994
1005
  })));
995
1006
  }
996
- for (let e of f.filter((e) => !N(e))) {
1007
+ for (let e of f.filter((e) => !L(e))) {
997
1008
  let t = p.findIndex((t) => t.id === e.id);
998
1009
  if (t < 0) {
999
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;
@@ -1007,18 +1018,18 @@ function ke(e, t, n) {
1007
1018
  historyOrder: e.historyOrder || n.historyOrder
1008
1019
  } : n);
1009
1020
  }
1010
- return te(M(c(P(p))));
1021
+ return D(I(c(R(p))));
1011
1022
  }
1012
1023
  //#endregion
1013
1024
  //#region src/core/conversation/hosted.ts
1014
- var Ae = "conversation_item_v1";
1015
- function je(e) {
1025
+ var De = "conversation_item_v1";
1026
+ function z(e) {
1016
1027
  return typeof e == "object" && e && !Array.isArray(e) ? e : null;
1017
1028
  }
1018
- function F(e) {
1029
+ function B(e) {
1019
1030
  return typeof e == "string" && e.trim() ? e : null;
1020
1031
  }
1021
- function I(e) {
1032
+ function V(e) {
1022
1033
  if (typeof e == "string") return e;
1023
1034
  if (e == null) return "";
1024
1035
  try {
@@ -1027,24 +1038,24 @@ function I(e) {
1027
1038
  return String(e);
1028
1039
  }
1029
1040
  }
1030
- function L(e) {
1041
+ function H(e) {
1031
1042
  return {
1032
1043
  id: `conversation:${e.runId}:${e.itemId}`,
1033
1044
  timestamp: 0,
1034
- eventType: Ae,
1045
+ eventType: De,
1035
1046
  eventId: e.sourceEventIds.at(-1),
1036
1047
  runId: e.runId,
1037
1048
  itemId: e.itemId,
1038
1049
  status: e.lifecycle === "failed" ? "failed" : e.lifecycle === "completed" ? "completed" : "running"
1039
1050
  };
1040
1051
  }
1041
- function Me(e) {
1052
+ function Oe(e) {
1042
1053
  return e.lifecycle === "failed" ? "error" : e.lifecycle === "completed" ? "done" : "streaming";
1043
1054
  }
1044
- function Ne(e) {
1055
+ function ke(e) {
1045
1056
  let t = typeof e.payload.text == "string" ? e.payload.text : "";
1046
1057
  if (e.kind === "user_message") return {
1047
- ...L(e),
1058
+ ...H(e),
1048
1059
  role: "user",
1049
1060
  content: t,
1050
1061
  eventType: "user_message"
@@ -1053,31 +1064,31 @@ function Ne(e) {
1053
1064
  id: `conversation-block:${e.itemId}`,
1054
1065
  type: "thinking",
1055
1066
  content: t,
1056
- status: Me(e),
1067
+ status: Oe(e),
1057
1068
  ...e.payload.presentationSource === "public_summary" || e.payload.presentationSource === "provider_reasoning" ? { source: e.payload.presentationSource } : {}
1058
1069
  } : {
1059
1070
  id: `conversation-block:${e.itemId}`,
1060
1071
  type: "text",
1061
1072
  content: t,
1062
- status: Me(e)
1073
+ status: Oe(e)
1063
1074
  };
1064
1075
  return {
1065
- ...L(e),
1076
+ ...H(e),
1066
1077
  role: "model",
1067
1078
  content: e.kind === "assistant_text" ? t : "",
1068
1079
  reasoning: e.kind === "reasoning" ? t : void 0,
1069
1080
  blocks: [n]
1070
1081
  };
1071
1082
  }
1072
- function Pe(e, t = !1) {
1073
- let n = F(e.payload.tool) || (e.payload.sourceKind === "tool_result" ? "Tool result" : "Tool"), r = F(e.payload.callId), i = I(_(e.payload.args)), a = Object.prototype.hasOwnProperty.call(e.payload, "output") ? I(v(e.payload.output, e.nativeRef.framework, e.nativeRef.protocol)) : void 0, o = {
1083
+ function Ae(e, t = !1) {
1084
+ let n = B(e.payload.tool) || (e.payload.sourceKind === "tool_result" ? "Tool result" : "Tool"), r = B(e.payload.callId), i = V(v(e.payload.args)), a = Object.prototype.hasOwnProperty.call(e.payload, "output") ? V(y(e.payload.output, e.nativeRef.framework, e.nativeRef.protocol)) : void 0, o = {
1074
1085
  failed: "error",
1075
1086
  completed: "completed",
1076
1087
  running: "running",
1077
1088
  unknown: "unknown"
1078
1089
  }, 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;
1079
1090
  return {
1080
- ...L(e),
1091
+ ...H(e),
1081
1092
  role: "model",
1082
1093
  content: "",
1083
1094
  blocks: [{
@@ -1098,55 +1109,55 @@ function Pe(e, t = !1) {
1098
1109
  } }
1099
1110
  };
1100
1111
  }
1101
- function Fe(e) {
1112
+ function je(e) {
1102
1113
  return e === "structured_input" ? "structured_input" : e === "plan_review" ? "plan_review" : e === "custom" ? "custom" : "approval";
1103
1114
  }
1104
- function Ie(e) {
1105
- let n = F(e.payload.interactionId), r = e.payload.revision;
1115
+ function Me(t) {
1116
+ let n = B(t.payload.interactionId), r = t.payload.revision;
1106
1117
  if (!n || !Number.isInteger(r) || Number(r) < 1) return null;
1107
- let i = I(e.payload.detail), a = F(e.payload.prompt) || i, o = Fe(e.payload.interactionKind), s = e.lifecycle === "completed", c = {};
1108
- if (s && Object.hasOwn(e.payload, "response")) try {
1109
- c = { response: t(e.payload.response) };
1118
+ let i = V(t.payload.detail), a = B(t.payload.prompt) || i, o = je(t.payload.interactionKind), s = t.lifecycle === "completed", c = {};
1119
+ if (s && Object.hasOwn(t.payload, "response")) try {
1120
+ c = { response: e(t.payload.response) };
1110
1121
  } catch {}
1111
1122
  return {
1112
1123
  interactionId: n,
1113
- sessionId: e.sessionId,
1114
- runId: e.runId,
1124
+ sessionId: t.sessionId,
1125
+ runId: t.runId,
1115
1126
  kind: o,
1116
- title: F(e.payload.title) || (o === "approval" ? `审批:${F(e.payload.kind) || "操作"}` : "需要补充信息"),
1127
+ title: B(t.payload.title) || (o === "approval" ? `审批:${B(t.payload.kind) || "操作"}` : "需要补充信息"),
1117
1128
  message: a || "运行需要人工确认。",
1118
- requestSchema: je(e.payload.inputSchema),
1129
+ requestSchema: z(t.payload.inputSchema),
1119
1130
  presentation: null,
1120
1131
  status: s ? "resolved" : "pending",
1121
1132
  revision: Number(r),
1122
- createdAt: F(e.payload.createdAt) || "",
1123
- expiresAt: F(e.payload.expiresAt),
1124
- resolvedAt: s ? F(e.payload.resolvedAt) : null,
1125
- actor: s ? F(e.payload.actor) : null,
1133
+ createdAt: B(t.payload.createdAt) || "",
1134
+ expiresAt: B(t.payload.expiresAt),
1135
+ resolvedAt: s ? B(t.payload.resolvedAt) : null,
1136
+ actor: s ? B(t.payload.actor) : null,
1126
1137
  outcome: s && [
1127
1138
  "approved",
1128
1139
  "rejected",
1129
1140
  "submitted",
1130
1141
  "cancelled",
1131
1142
  "expired"
1132
- ].includes(String(e.payload.outcome || "")) ? e.payload.outcome : null,
1133
- responseSummary: s ? F(e.payload.responseSummary) : null,
1143
+ ].includes(String(t.payload.outcome || "")) ? t.payload.outcome : null,
1144
+ responseSummary: s ? B(t.payload.responseSummary) : null,
1134
1145
  ...c,
1135
1146
  source: "interaction_v1",
1136
1147
  extensions: {
1137
- conversation_item_id: e.itemId,
1138
- ...F(e.payload.callId) ? { call_id: F(e.payload.callId) } : {}
1148
+ conversation_item_id: t.itemId,
1149
+ ...B(t.payload.callId) ? { call_id: B(t.payload.callId) } : {}
1139
1150
  }
1140
1151
  };
1141
1152
  }
1142
- function Le(e, t) {
1143
- let n = F(e.payload.kind) || "approval", r = I(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 = {
1153
+ function Ne(e, t) {
1154
+ 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 = {
1144
1155
  approvalRequestId: t.interactionId,
1145
1156
  approvalStatus: i,
1146
1157
  approvalMessage: t.message
1147
1158
  };
1148
1159
  return {
1149
- ...L(e),
1160
+ ...H(e),
1150
1161
  role: "model",
1151
1162
  content: "",
1152
1163
  blocks: [{
@@ -1167,26 +1178,26 @@ function Le(e, t) {
1167
1178
  } }
1168
1179
  };
1169
1180
  }
1170
- function Re(e) {
1181
+ function Pe(e) {
1171
1182
  for (let t of [
1172
1183
  "createSurface",
1173
1184
  "updateComponents",
1174
1185
  "updateDataModel",
1175
1186
  "deleteSurface"
1176
1187
  ]) {
1177
- let n = F(je(e[t])?.surfaceId);
1188
+ let n = B(z(e[t])?.surfaceId);
1178
1189
  if (n) return n;
1179
1190
  }
1180
1191
  return null;
1181
1192
  }
1182
- function ze(e) {
1193
+ function Fe(e) {
1183
1194
  let t = Array.isArray(e.payload.data) ? e.payload.data : Array.isArray(e.payload.operations) ? e.payload.operations : null;
1184
1195
  if (!t) return null;
1185
- let n = t.map(je);
1196
+ let n = t.map(z);
1186
1197
  if (n.some((e) => e === null)) return null;
1187
- let r = n, i = F(e.payload.surfaceId) || r.map(Re).find((e) => e !== null) || null;
1198
+ let r = n, i = B(e.payload.surfaceId) || r.map(Pe).find((e) => e !== null) || null;
1188
1199
  return i ? {
1189
- ...L(e),
1200
+ ...H(e),
1190
1201
  role: "a2ui",
1191
1202
  content: "",
1192
1203
  aguiActivity: {
@@ -1196,18 +1207,18 @@ function ze(e) {
1196
1207
  }
1197
1208
  } : null;
1198
1209
  }
1199
- function R(e, t, n, r = !1) {
1210
+ function U(e, t, n, r = !1) {
1200
1211
  return {
1201
- ...L(e),
1212
+ ...H(e),
1202
1213
  role: "system",
1203
1214
  content: n ? `${t}: ${n}` : t,
1204
- status: r ? "failed" : L(e).status
1215
+ status: r ? "failed" : H(e).status
1205
1216
  };
1206
1217
  }
1207
- function Be(e) {
1218
+ function Ie(e) {
1208
1219
  for (let { item: t } of [...e].reverse()) {
1209
1220
  if (t.visibility !== "public" || t.kind !== "assistant_text" || t.payloadSchemaRef !== "conversation.item.assistant_text/v1" || typeof t.payload.text != "string") continue;
1210
- let e = _(t.payload.text);
1221
+ let e = v(t.payload.text);
1211
1222
  if (typeof e != "string" || e === "[redacted]") continue;
1212
1223
  let n = e.replace(/\s+/g, " ").trim();
1213
1224
  if (!n) continue;
@@ -1215,16 +1226,16 @@ function Be(e) {
1215
1226
  return r.length > 160 ? `${r.slice(0, 160).join("")}…` : n;
1216
1227
  }
1217
1228
  }
1218
- function z(e) {
1229
+ function W(e) {
1219
1230
  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 = [];
1220
1231
  for (let d of t.timeline) {
1221
1232
  let { item: f } = d;
1222
1233
  if (f.kind === "agent") {
1223
1234
  if (!d.children) {
1224
- l.push(R(f, "Remote agent", String(f.payload.status || "submitted")));
1235
+ l.push(U(f, "Remote agent", String(f.payload.status || "submitted")));
1225
1236
  continue;
1226
1237
  }
1227
- let n = z({
1238
+ let n = W({
1228
1239
  ...e,
1229
1240
  presentation: {
1230
1241
  ...t,
@@ -1232,40 +1243,40 @@ function z(e) {
1232
1243
  }
1233
1244
  });
1234
1245
  l.push({
1235
- ...L(f),
1246
+ ...H(f),
1236
1247
  role: "model",
1237
1248
  content: "",
1238
1249
  agentBlock: {
1239
1250
  item: f,
1240
1251
  messages: n.messages,
1241
- summary: Be(d.children || [])
1252
+ summary: Ie(d.children || [])
1242
1253
  },
1243
- status: f.payload.status === "cancelled" ? "cancelled" : L(f).status
1254
+ status: f.payload.status === "cancelled" ? "cancelled" : H(f).status
1244
1255
  }), u.push(...n.interactions);
1245
1256
  continue;
1246
1257
  }
1247
1258
  if (n.has(f.itemId)) {
1248
- l.push(Ne(f));
1259
+ l.push(ke(f));
1249
1260
  continue;
1250
1261
  }
1251
1262
  if (r.has(f.itemId)) {
1252
- l.push(Pe(f, !!t.terminalStatus && f.runId === e.runId));
1263
+ l.push(Ae(f, !!t.terminalStatus && f.runId === e.runId));
1253
1264
  continue;
1254
1265
  }
1255
1266
  if (i.has(f.itemId) || a.has(f.itemId)) {
1256
- let e = Ie(f);
1257
- e ? (u.push(e), l.push(Le(f, e))) : l.push(R(f, "Interaction unavailable", "The server did not provide a durable interaction revision; this card is read-only."));
1267
+ let e = Me(f);
1268
+ e ? (u.push(e), l.push(Ne(f, e))) : l.push(U(f, "Interaction unavailable", "The server did not provide a durable interaction revision; this card is read-only."));
1258
1269
  continue;
1259
1270
  }
1260
1271
  if (o.has(f.itemId)) {
1261
- let e = ze(f);
1262
- l.push(e || R(f, "Unsupported content", "A2UI payload is not a valid passive operation list."));
1272
+ let e = Fe(f);
1273
+ l.push(e || U(f, "Unsupported content", "A2UI payload is not a valid passive operation list."));
1263
1274
  continue;
1264
1275
  }
1265
1276
  let p = s.get(f.itemId);
1266
1277
  if (p) {
1267
1278
  l.push(p.status === "pending" ? {
1268
- ...L(f),
1279
+ ...H(f),
1269
1280
  role: "model",
1270
1281
  content: p.name,
1271
1282
  attachments: [{
@@ -1279,7 +1290,7 @@ function z(e) {
1279
1290
  status: "pending"
1280
1291
  }]
1281
1292
  } : p.status === "ready" && p.uri ? {
1282
- ...L(f),
1293
+ ...H(f),
1283
1294
  role: "model",
1284
1295
  content: p.name,
1285
1296
  attachments: [{
@@ -1292,13 +1303,13 @@ function z(e) {
1292
1303
  sizeBytes: p.sizeBytes,
1293
1304
  status: p.status
1294
1305
  }]
1295
- } : R(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."));
1306
+ } : 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."));
1296
1307
  continue;
1297
1308
  }
1298
1309
  let m = c.get(f.itemId);
1299
1310
  if (m) {
1300
1311
  if (f.kind === "error" && ["cancelled", "canceled"].includes(String(f.payload.status || "").toLowerCase())) continue;
1301
- l.push(R(f, m.title, m.detail, m.failed));
1312
+ l.push(U(f, m.title, m.detail, m.failed));
1302
1313
  }
1303
1314
  }
1304
1315
  return {
@@ -1306,8 +1317,8 @@ function z(e) {
1306
1317
  interactions: u
1307
1318
  };
1308
1319
  }
1309
- function Ve(e, t, n) {
1310
- let r = z(t).messages;
1320
+ function Le(e, t, n) {
1321
+ let r = W(t).messages;
1311
1322
  if (!r.length) return e;
1312
1323
  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") ? [{
1313
1324
  ...c,
@@ -1323,46 +1334,46 @@ function Ve(e, t, n) {
1323
1334
  }
1324
1335
  //#endregion
1325
1336
  //#region src/core/run/blocks.ts
1326
- var He = 0;
1327
- function B(e) {
1328
- return He += 1, `${e}-${He}`;
1337
+ var Re = 0;
1338
+ function G(e) {
1339
+ return Re += 1, `${e}-${Re}`;
1329
1340
  }
1330
- function V(e) {
1341
+ function K(e) {
1331
1342
  return e.map((e) => e.type === "thinking" && e.status === "streaming" ? {
1332
1343
  ...e,
1333
1344
  status: "done"
1334
1345
  } : e);
1335
1346
  }
1336
- function Ue(e, t) {
1347
+ function ze(e, t) {
1337
1348
  let n = [...e ?? []], r = n[n.length - 1];
1338
1349
  return r?.type === "thinking" && r.status === "streaming" ? (n[n.length - 1] = {
1339
1350
  ...r,
1340
1351
  content: r.content + t
1341
1352
  }, n) : [...n, {
1342
- id: B("thinking"),
1353
+ id: G("thinking"),
1343
1354
  type: "thinking",
1344
1355
  content: t,
1345
1356
  status: "streaming"
1346
1357
  }];
1347
1358
  }
1348
- function We(e, t) {
1349
- let n = [...V(e ?? [])], r = n[n.length - 1];
1359
+ function Be(e, t) {
1360
+ let n = [...K(e ?? [])], r = n[n.length - 1];
1350
1361
  return r?.type === "text" && r.status === "streaming" ? (n[n.length - 1] = {
1351
1362
  ...r,
1352
1363
  content: r.content + t
1353
1364
  }, n) : [...n, {
1354
- id: B("text"),
1365
+ id: G("text"),
1355
1366
  type: "text",
1356
1367
  content: t,
1357
1368
  status: "streaming"
1358
1369
  }];
1359
1370
  }
1360
- function Ge(e, t) {
1371
+ function Ve(e, t) {
1361
1372
  let n = e ?? [], r = n.filter((e) => e.type === "text").map((e) => e.content).join("");
1362
1373
  if (r === t) return n;
1363
1374
  let i = n.flatMap((e, t) => e.type === "text" ? [t] : []);
1364
1375
  if (!i.length) return [...n, {
1365
- id: B("text"),
1376
+ id: G("text"),
1366
1377
  type: "text",
1367
1378
  content: t,
1368
1379
  status: "streaming"
@@ -1386,8 +1397,8 @@ function Ge(e, t) {
1386
1397
  };
1387
1398
  });
1388
1399
  }
1389
- function Ke(e, t) {
1390
- let n = V(e ?? []);
1400
+ function He(e, t) {
1401
+ let n = K(e ?? []);
1391
1402
  if (n.filter((e) => e.type === "text").map((e) => e.content).join("") === t) return n.map((e) => e.type === "text" && e.status === "streaming" ? {
1392
1403
  ...e,
1393
1404
  status: "done"
@@ -1398,13 +1409,13 @@ function Ke(e, t) {
1398
1409
  content: t,
1399
1410
  status: "done"
1400
1411
  }, r) : [...r, {
1401
- id: B("text"),
1412
+ id: G("text"),
1402
1413
  type: "text",
1403
1414
  content: t,
1404
1415
  status: "done"
1405
1416
  }];
1406
1417
  }
1407
- function qe(e, t) {
1418
+ function Ue(e, t) {
1408
1419
  if (!t) return [...e ?? []];
1409
1420
  let n = [...e ?? []], r = n[n.length - 1];
1410
1421
  if (r?.type !== "thinking" || !r.content.endsWith(t)) return n;
@@ -1414,8 +1425,8 @@ function qe(e, t) {
1414
1425
  content: i
1415
1426
  }, n) : (n.pop(), n);
1416
1427
  }
1417
- function Je(e, t, n) {
1418
- let r = [...V(e ?? [])], i = r.findIndex((e) => e.type === "tool" && e.toolName === t);
1428
+ function We(e, t, n) {
1429
+ let r = [...K(e ?? [])], i = r.findIndex((e) => e.type === "tool" && e.toolName === t);
1419
1430
  if (i >= 0 && r[i].type === "tool") {
1420
1431
  let e = r[i], t = e.status === "error" || e.status === "completed", a = n.output !== void 0, o = n.extra && (n.extra.approvalRequestId || n.extra.approvalStatus);
1421
1432
  if (t && !a && !o) return r;
@@ -1427,7 +1438,7 @@ function Je(e, t, n) {
1427
1438
  }, r;
1428
1439
  }
1429
1440
  return [...r, {
1430
- id: B("tool"),
1441
+ id: G("tool"),
1431
1442
  type: "tool",
1432
1443
  toolName: t,
1433
1444
  args: n.args ?? "",
@@ -1436,19 +1447,19 @@ function Je(e, t, n) {
1436
1447
  extra: n.extra
1437
1448
  }];
1438
1449
  }
1439
- function Ye(e) {
1440
- return V(e ?? []);
1450
+ function Ge(e) {
1451
+ return K(e ?? []);
1441
1452
  }
1442
- function Xe(e) {
1453
+ function Ke(e) {
1443
1454
  let t = [];
1444
1455
  if (e.reasoning && e.reasoning.trim() && t.push({
1445
- id: B("thinking"),
1456
+ id: G("thinking"),
1446
1457
  type: "thinking",
1447
1458
  content: e.reasoning,
1448
1459
  status: "done",
1449
1460
  ...e.reasoningSource ? { source: e.reasoningSource } : {}
1450
1461
  }), e.tools) for (let n of Object.values(e.tools)) t.push({
1451
- id: B("tool"),
1462
+ id: G("tool"),
1452
1463
  type: "tool",
1453
1464
  toolName: n.name,
1454
1465
  args: n.args ?? "",
@@ -1460,7 +1471,7 @@ function Xe(e) {
1460
1471
  } } : {}
1461
1472
  });
1462
1473
  return e.content && e.content.trim() && t.push({
1463
- id: B("text"),
1474
+ id: G("text"),
1464
1475
  type: "text",
1465
1476
  content: e.content,
1466
1477
  status: "done"
@@ -1468,40 +1479,40 @@ function Xe(e) {
1468
1479
  }
1469
1480
  //#endregion
1470
1481
  //#region src/core/stream/kernel-events.ts
1471
- var Ze = {
1482
+ var qe = {
1472
1483
  "run.started": "in_progress",
1473
1484
  "run.progress": "in_progress",
1474
1485
  "run.completed": "completed",
1475
1486
  "run.failed": "failed",
1476
1487
  "run.canceled": "cancelled",
1477
1488
  "run.interrupted": "interrupted"
1478
- }, Qe = new Set([
1489
+ }, Je = new Set([
1479
1490
  "completed",
1480
1491
  "failed",
1481
1492
  "cancelled",
1482
1493
  "canceled"
1483
1494
  ]);
1484
- function H(e) {
1495
+ function q(e) {
1485
1496
  return typeof e == "object" && e && !Array.isArray(e) ? e : null;
1486
1497
  }
1487
- function $e(e) {
1488
- let t = H(e.source), n = t ? H(t.metadata) : null;
1498
+ function Ye(e) {
1499
+ let t = q(e.source), n = t ? q(t.metadata) : null;
1489
1500
  return String(n?.native_item_kind || "");
1490
1501
  }
1491
- function U(e, t) {
1492
- let n = H(e[t]);
1502
+ function J(e, t) {
1503
+ let n = q(e[t]);
1493
1504
  if (!n) return [];
1494
1505
  let r = n?.parts;
1495
1506
  return Array.isArray(r) ? r : t === "update" ? [n] : [];
1496
1507
  }
1497
- function et(e) {
1498
- let t = H(e);
1508
+ function Xe(e) {
1509
+ let t = q(e);
1499
1510
  if (!t) return "";
1500
1511
  if (typeof t.text == "string") return t.text;
1501
- let n = H(t.data);
1512
+ let n = q(t.data);
1502
1513
  if (n) {
1503
1514
  let e = n.content;
1504
- if (Array.isArray(e)) return e.map((e) => String(H(e)?.text || "")).join("");
1515
+ if (Array.isArray(e)) return e.map((e) => String(q(e)?.text || "")).join("");
1505
1516
  for (let e of [
1506
1517
  "text",
1507
1518
  "output",
@@ -1511,31 +1522,31 @@ function et(e) {
1511
1522
  }
1512
1523
  return "";
1513
1524
  }
1514
- function W(e) {
1515
- return e.map(et).join("");
1525
+ function Y(e) {
1526
+ return e.map(Xe).join("");
1516
1527
  }
1517
- function tt(e) {
1518
- return e.some((e) => H(H(e)?.data)?.type === "userMessage");
1528
+ function Ze(e) {
1529
+ return e.some((e) => q(q(e)?.data)?.type === "userMessage");
1519
1530
  }
1520
- function G(e) {
1531
+ function X(e) {
1521
1532
  if (e.length === 1) {
1522
- let t = H(H(e[0])?.data);
1533
+ let t = q(q(e[0])?.data);
1523
1534
  if (t) return t;
1524
1535
  }
1525
- return W(e) || null;
1536
+ return Y(e) || null;
1526
1537
  }
1527
- function nt(e) {
1528
- let t = H(e);
1529
- return t ? H(t.data) || t : null;
1538
+ function Qe(e) {
1539
+ let t = q(e);
1540
+ return t ? q(t.data) || t : null;
1530
1541
  }
1531
- function rt(e) {
1532
- let t = nt(e);
1542
+ function $e(e) {
1543
+ let t = Qe(e);
1533
1544
  return String(t?.content_type || t?.type || "").trim().toLowerCase();
1534
1545
  }
1535
- function it(e) {
1546
+ function et(e) {
1536
1547
  for (let t of e) {
1537
- let e = nt(t);
1538
- if (!e || rt(t) !== "tool_call") continue;
1548
+ let e = Qe(t);
1549
+ if (!e || $e(t) !== "tool_call") continue;
1539
1550
  let n = String(e.call_id || "").trim(), r = String(e.name || e.tool_name || "").trim();
1540
1551
  if (!(!n && !r)) return {
1541
1552
  callId: n,
@@ -1545,10 +1556,10 @@ function it(e) {
1545
1556
  }
1546
1557
  return null;
1547
1558
  }
1548
- function at(e) {
1559
+ function tt(e) {
1549
1560
  for (let t of e) {
1550
- let e = nt(t);
1551
- if (!e || rt(t) !== "tool_result") continue;
1561
+ let e = Qe(t);
1562
+ if (!e || $e(t) !== "tool_result") continue;
1552
1563
  let n = String(e.call_id || e.tool_call_id || "").trim(), r = e.is_error === !0 || e.error != null;
1553
1564
  return {
1554
1565
  callId: n,
@@ -1558,7 +1569,7 @@ function at(e) {
1558
1569
  }
1559
1570
  return null;
1560
1571
  }
1561
- function K(e, t, n, r) {
1572
+ function Z(e, t, n, r) {
1562
1573
  let i = String(e.item_id || ""), a = String(r || i);
1563
1574
  return { RuntimeItem: {
1564
1575
  RunId: String(e.run_id || ""),
@@ -1570,7 +1581,7 @@ function K(e, t, n, r) {
1570
1581
  ...i && i !== a ? { SourceItemId: i } : {}
1571
1582
  } };
1572
1583
  }
1573
- var ot = class {
1584
+ var nt = class {
1574
1585
  textByPart = /* @__PURE__ */ new Map();
1575
1586
  toolNameByCallId = /* @__PURE__ */ new Map();
1576
1587
  toolCallByItemId = /* @__PURE__ */ new Map();
@@ -1580,7 +1591,7 @@ var ot = class {
1580
1591
  this.sessionId = e;
1581
1592
  }
1582
1593
  translate(e) {
1583
- if (!H(e)) return null;
1594
+ if (!q(e)) return null;
1584
1595
  let t = Number(e.seq);
1585
1596
  if (!Number.isFinite(t) || t <= 0) return null;
1586
1597
  let n = String(e.family || ""), r = String(e.event_type || ""), i = String(e.run_id || ""), a = () => ({
@@ -1589,7 +1600,7 @@ var ot = class {
1589
1600
  InvocationId: i || void 0,
1590
1601
  SeqId: t
1591
1602
  });
1592
- if (n === "interaction") return {
1603
+ if (n === "interaction" || r.startsWith("mcp.authorization.")) return {
1593
1604
  ...a(),
1594
1605
  EventType: r,
1595
1606
  payload: e
@@ -1602,7 +1613,7 @@ var ot = class {
1602
1613
  };
1603
1614
  if (r === "control.run_transition") {
1604
1615
  let t = String(e.state || "").toLowerCase();
1605
- if (Qe.has(t)) return {
1616
+ if (Je.has(t)) return {
1606
1617
  ...a(),
1607
1618
  EventType: "run_status",
1608
1619
  Content: { status: t }
@@ -1611,19 +1622,19 @@ var ot = class {
1611
1622
  return null;
1612
1623
  }
1613
1624
  if (n !== "runtime") return null;
1614
- let o = H(H(e.source)?.metadata), s = o?.conversation_visibility ?? o?.visibility;
1625
+ let o = q(q(e.source)?.metadata), s = o?.conversation_visibility ?? o?.visibility;
1615
1626
  if (r.startsWith("item.") && ["internal", "hidden"].includes(String(s))) return null;
1616
- let c = Ze[r];
1627
+ let c = qe[r];
1617
1628
  if (c) return {
1618
1629
  ...a(),
1619
1630
  EventType: "run_status",
1620
1631
  Content: { status: c }
1621
1632
  };
1622
- let l = $e(e);
1633
+ let l = Ye(e);
1623
1634
  if (r === "item.started") {
1624
- let t = U(e, "initial");
1635
+ let t = J(e, "initial");
1625
1636
  if (e.item_kind === "tool_call") {
1626
- let n = it(t);
1637
+ let n = et(t);
1627
1638
  if (!n) return null;
1628
1639
  let r = n?.callId || String(e.item_id || ""), o = n?.name || "tool";
1629
1640
  return r && this.toolNameByCallId.set(r, o), e.item_id && this.toolCallByItemId.set(String(e.item_id), {
@@ -1633,42 +1644,42 @@ var ot = class {
1633
1644
  ...a(),
1634
1645
  EventType: "tool_call",
1635
1646
  Metadata: {
1636
- ...K(e, "replace", void 0, r),
1647
+ ...Z(e, "replace", void 0, r),
1637
1648
  call_id: r,
1638
1649
  tool_name: o,
1639
1650
  run_id: i,
1640
- tool_args: n?.arguments ?? G(t)
1651
+ tool_args: n?.arguments ?? X(t)
1641
1652
  }
1642
1653
  };
1643
1654
  }
1644
- return e.item_kind === "tool_result" || l === "userMessage" || tt(t) || l === "reasoning" || e.item_kind === "reasoning" ? null : l === "agentMessage" || !l && e.item_kind === "message" ? {
1655
+ return e.item_kind === "tool_result" || l === "userMessage" || Ze(t) || l === "reasoning" || e.item_kind === "reasoning" ? null : l === "agentMessage" || !l && e.item_kind === "message" ? {
1645
1656
  ...a(),
1646
1657
  EventType: "assistant_stream_snapshot",
1647
1658
  Content: { parts: [{ text: "" }] },
1648
- Metadata: K(e, "replace")
1659
+ Metadata: Z(e, "replace")
1649
1660
  } : l && l !== "notification" ? {
1650
1661
  ...a(),
1651
1662
  EventType: "tool_call",
1652
1663
  Metadata: {
1653
- ...K(e, "replace"),
1664
+ ...Z(e, "replace"),
1654
1665
  call_id: String(e.item_id || ""),
1655
1666
  tool_name: l,
1656
1667
  run_id: i,
1657
- tool_args: G(t)
1668
+ tool_args: X(t)
1658
1669
  }
1659
1670
  } : null;
1660
1671
  }
1661
1672
  if (r === "item.updated") {
1662
- let n = U(e, "update");
1673
+ let n = J(e, "update");
1663
1674
  if (e.item_kind === "tool_call") {
1664
- let t = at(n);
1675
+ let t = tt(n);
1665
1676
  if (!t) return null;
1666
1677
  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;
1667
1678
  return e.item_id && this.toolResultByItemId.set(String(e.item_id), c), {
1668
1679
  ...a(),
1669
1680
  EventType: "tool_result",
1670
1681
  Metadata: {
1671
- ...K(e, "completed", void 0, o),
1682
+ ...Z(e, "completed", void 0, o),
1672
1683
  call_id: o,
1673
1684
  tool_name: s,
1674
1685
  run_id: i,
@@ -1676,44 +1687,44 @@ var ot = class {
1676
1687
  }
1677
1688
  };
1678
1689
  }
1679
- let r = H(n[0]), o = String(r?.part_id || e.item_id || t), s = String(e.op || "replace"), c = W(n), u = this.textByPart.get(o) || "", d = s === "append" ? u + c : c;
1690
+ 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;
1680
1691
  return this.textByPart.set(o, d), l === "agentMessage" || !l && e.item_kind === "message" ? {
1681
1692
  ...a(),
1682
1693
  EventType: "assistant_stream_snapshot",
1683
1694
  Content: { parts: [{ text: d }] },
1684
- Metadata: K(e, "replace", o)
1695
+ Metadata: Z(e, "replace", o)
1685
1696
  } : l === "reasoning" || e.item_kind === "reasoning" ? {
1686
1697
  ...a(),
1687
1698
  EventType: "reasoning",
1688
1699
  Content: { parts: [{ text: c }] },
1689
- Metadata: K(e, s === "append" ? "append" : "replace", o)
1700
+ Metadata: Z(e, s === "append" ? "append" : "replace", o)
1690
1701
  } : null;
1691
1702
  }
1692
1703
  if (r === "item.snapshot_replaced") {
1693
- let n = U(e, "snapshot"), r = String(H(n[0])?.part_id || e.item_id || t), i = W(n);
1704
+ let n = J(e, "snapshot"), r = String(q(n[0])?.part_id || e.item_id || t), i = Y(n);
1694
1705
  return this.textByPart.set(r, i), l === "agentMessage" || !l && e.item_kind === "message" ? {
1695
1706
  ...a(),
1696
1707
  EventType: "assistant_stream_snapshot",
1697
1708
  Content: { parts: [{ text: i }] },
1698
- Metadata: K(e, "replace", r)
1709
+ Metadata: Z(e, "replace", r)
1699
1710
  } : l === "reasoning" || e.item_kind === "reasoning" ? {
1700
1711
  ...a(),
1701
1712
  EventType: "reasoning",
1702
1713
  Content: { parts: [{ text: i }] },
1703
- Metadata: K(e, "replace", r)
1714
+ Metadata: Z(e, "replace", r)
1704
1715
  } : null;
1705
1716
  }
1706
1717
  if (r === "item.completed") {
1707
- let n = U(e, "snapshot");
1718
+ let n = J(e, "snapshot");
1708
1719
  if (e.item_kind === "tool_call") {
1709
- let t = it(n), r = at(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";
1720
+ let t = et(n), r = tt(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";
1710
1721
  if (s && this.toolNameByCallId.set(s, c), r) {
1711
1722
  let t = r.isError ? { error: r.result } : r.result;
1712
1723
  return {
1713
1724
  ...a(),
1714
1725
  EventType: "tool_result",
1715
1726
  Metadata: {
1716
- ...K(e, "completed", void 0, s),
1727
+ ...Z(e, "completed", void 0, s),
1717
1728
  call_id: s,
1718
1729
  tool_name: c,
1719
1730
  run_id: i,
@@ -1725,21 +1736,21 @@ var ot = class {
1725
1736
  ...a(),
1726
1737
  EventType: "tool_call",
1727
1738
  Metadata: {
1728
- ...K(e, "replace", void 0, s),
1739
+ ...Z(e, "replace", void 0, s),
1729
1740
  call_id: s,
1730
1741
  tool_name: c,
1731
1742
  run_id: i,
1732
- tool_args: t?.arguments ?? G(n)
1743
+ tool_args: t?.arguments ?? X(n)
1733
1744
  }
1734
1745
  };
1735
1746
  }
1736
1747
  if (e.item_kind === "tool_result") {
1737
- let t = at(n), r = t?.callId || String(e.item_id || ""), o = this.toolNameByCallId.get(r) || l || "tool", s = t?.isError ? { error: t.result } : t?.result ?? G(n);
1748
+ let t = tt(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);
1738
1749
  return {
1739
1750
  ...a(),
1740
1751
  EventType: "tool_result",
1741
1752
  Metadata: {
1742
- ...K(e, "completed", void 0, r),
1753
+ ...Z(e, "completed", void 0, r),
1743
1754
  call_id: r,
1744
1755
  tool_name: o,
1745
1756
  run_id: i,
@@ -1747,38 +1758,38 @@ var ot = class {
1747
1758
  }
1748
1759
  };
1749
1760
  }
1750
- if (l === "userMessage" || tt(n)) return {
1761
+ if (l === "userMessage" || Ze(n)) return {
1751
1762
  ...a(),
1752
1763
  EventType: "user_message",
1753
- Content: { parts: [{ text: W(n) }] }
1764
+ Content: { parts: [{ text: Y(n) }] }
1754
1765
  };
1755
1766
  if (l === "agentMessage" || !l && e.item_kind === "message") {
1756
- let r = W(n), i = String(H(n[0])?.part_id || e.item_id || t);
1767
+ let r = Y(n), i = String(q(n[0])?.part_id || e.item_id || t);
1757
1768
  return this.textByPart.set(i, r), {
1758
1769
  ...a(),
1759
1770
  EventType: "assistant_message",
1760
1771
  Content: { parts: [{ text: r }] },
1761
- Metadata: K(e, "completed", i)
1772
+ Metadata: Z(e, "completed", i)
1762
1773
  };
1763
1774
  }
1764
1775
  if (l === "reasoning" || e.item_kind === "reasoning") {
1765
- let r = String(H(n[0])?.part_id || e.item_id || t);
1776
+ let r = String(q(n[0])?.part_id || e.item_id || t);
1766
1777
  return {
1767
1778
  ...a(),
1768
1779
  EventType: "reasoning",
1769
- Content: { parts: [{ text: W(n) }] },
1770
- Metadata: K(e, "completed", r)
1780
+ Content: { parts: [{ text: Y(n) }] },
1781
+ Metadata: Z(e, "completed", r)
1771
1782
  };
1772
1783
  }
1773
1784
  return l && l !== "notification" ? {
1774
1785
  ...a(),
1775
1786
  EventType: "tool_result",
1776
1787
  Metadata: {
1777
- ...K(e, "completed"),
1788
+ ...Z(e, "completed"),
1778
1789
  call_id: String(e.item_id || ""),
1779
1790
  tool_name: l,
1780
1791
  run_id: i,
1781
- tool_output: G(n)
1792
+ tool_output: X(n)
1782
1793
  }
1783
1794
  } : null;
1784
1795
  }
@@ -1789,11 +1800,11 @@ var ot = class {
1789
1800
  ...a(),
1790
1801
  EventType: "tool_result",
1791
1802
  Metadata: {
1792
- ...K(e, "completed", void 0, n),
1803
+ ...Z(e, "completed", void 0, n),
1793
1804
  call_id: n,
1794
1805
  tool_name: r,
1795
1806
  run_id: i,
1796
- tool_output: o ?? { error: H(e.error) || e.error || "item failed" }
1807
+ tool_output: o ?? { error: q(e.error) || e.error || "item failed" }
1797
1808
  }
1798
1809
  };
1799
1810
  }
@@ -1801,18 +1812,18 @@ var ot = class {
1801
1812
  ...a(),
1802
1813
  EventType: "tool_result",
1803
1814
  Metadata: {
1804
- ...K(e, "completed"),
1815
+ ...Z(e, "completed"),
1805
1816
  call_id: String(e.item_id || ""),
1806
1817
  tool_name: l,
1807
1818
  run_id: i,
1808
- tool_output: { error: H(e.error) || e.error || "item failed" }
1819
+ tool_output: { error: q(e.error) || e.error || "item failed" }
1809
1820
  }
1810
1821
  } : null;
1811
1822
  }
1812
1823
  return null;
1813
1824
  }
1814
1825
  };
1815
- async function st(e) {
1826
+ async function rt(e) {
1816
1827
  let t = e.getReader(), n = new TextDecoder(), r = "", i = null, a = !1, o = (e) => e.includes("data:") || e.includes("event:") || e.includes(":");
1817
1828
  try {
1818
1829
  for (;;) {
@@ -1822,8 +1833,8 @@ async function st(e) {
1822
1833
  break;
1823
1834
  }
1824
1835
  if (r.trimStart().startsWith("{")) {
1825
- if (ct(r)) {
1826
- i = lt(r);
1836
+ if (it(r)) {
1837
+ i = at(r);
1827
1838
  break;
1828
1839
  }
1829
1840
  } else if (o(r)) break;
@@ -1859,7 +1870,7 @@ async function st(e) {
1859
1870
  stream: c
1860
1871
  };
1861
1872
  }
1862
- function ct(e) {
1873
+ function it(e) {
1863
1874
  let t = e.trim();
1864
1875
  if (!t.endsWith("}")) return !1;
1865
1876
  let n = 0, r = !1, i = !1;
@@ -1876,11 +1887,11 @@ function ct(e) {
1876
1887
  }
1877
1888
  return n === 0;
1878
1889
  }
1879
- function lt(e) {
1890
+ function at(e) {
1880
1891
  try {
1881
- let t = H(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
1892
+ let t = q(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
1882
1893
  if (!n) return null;
1883
- let r = H(t?.Error);
1894
+ let r = q(t?.Error);
1884
1895
  return {
1885
1896
  status: n,
1886
1897
  presentationProfile: t?.PresentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1",
@@ -1898,987 +1909,40 @@ function lt(e) {
1898
1909
  }
1899
1910
  }
1900
1911
  //#endregion
1901
- //#region src/utils/responses-stream.js
1902
- function ut() {
1903
- return {
1904
- toolNames: /* @__PURE__ */ new Map(),
1905
- toolArguments: /* @__PURE__ */ new Map(),
1906
- callIds: /* @__PURE__ */ new Map(),
1907
- currentResponseId: "",
1908
- sawTextDelta: !1,
1909
- sawReasoningDelta: !1
1910
- };
1911
- }
1912
- function dt(e) {
1913
- return typeof e == "string" ? e : Array.isArray(e) ? e.map((e) => typeof e == "string" ? e : e && typeof e == "object" && typeof e.text == "string" ? e.text : "").join("") : e && typeof e == "object" && typeof e.text == "string" ? e.text : "";
1914
- }
1915
- function q(e) {
1916
- return e == null ? "" : typeof e == "string" ? e : typeof e == "object" ? JSON.stringify(e, null, 2) : String(e);
1917
- }
1918
- function J(...e) {
1919
- for (let t of e) {
1920
- let e = dt(t);
1921
- if (e) return e;
1922
- }
1923
- return "";
1924
- }
1925
- function ft(e, t) {
1926
- return String(e?.id || e?.item_id || e?.call_id || t?.item_id || t?.call_id || t?.output_index || "");
1927
- }
1928
- function pt(e, t, n, r, i) {
1929
- t && (e.toolNames.set(t, r), e.toolArguments.set(t, i));
1930
- let a = String(n?.call_id || "");
1931
- a && (e.callIds.set(a, t || r), e.toolNames.set(a, r), e.toolArguments.set(a, i));
1932
- }
1933
- function Y(e, t, n, r = "tool") {
1934
- let i = String(n?.call_id || "");
1935
- return String(n?.name || n?.tool_name || (t ? e.toolNames.get(t) : "") || (i ? e.toolNames.get(i) : "") || r);
1936
- }
1937
- function mt(e) {
1938
- if (!e || typeof e != "object") return "";
1939
- let t = dt(e.content);
1940
- return J(e.output_text, e.text, e.summary_text, e.summary, e.delta, t);
1941
- }
1942
- function ht(e) {
1943
- let t = e?.response && typeof e.response == "object" ? e.response : e, n = J(t?.output_text, t?.text);
1944
- if (n) return n;
1945
- let r = Array.isArray(t?.output) ? t.output : [];
1946
- for (let e of r) {
1947
- let t = mt(e);
1948
- if (t) return t;
1949
- }
1950
- return "";
1951
- }
1952
- function gt(e) {
1953
- let t = e?.response && typeof e.response == "object" ? e.response : e;
1954
- return Array.isArray(t?.output) ? t.output : [];
1955
- }
1956
- function _t(e) {
1957
- let t = e;
1958
- if (typeof t == "string") try {
1959
- t = JSON.parse(t);
1960
- } catch {
1961
- return {};
1962
- }
1963
- return Array.isArray(t) && (t = t[0] || {}), !t || typeof t != "object" ? {} : t.value && typeof t.value == "object" && !Array.isArray(t.value) ? {
1964
- ...t.value,
1965
- approval_request_id: t.value.approval_request_id || t.value.id || t.id
1966
- } : t;
1967
- }
1968
- function vt({ data: e, state: t, status: n }) {
1969
- let r = e?.item || e?.output_item || e || {}, i = String(r.type || "").trim(), a = ft(r, e);
1970
- if (i === "function_call") {
1971
- let e = Y(t, a, r), i = q(r.arguments ?? r.args ?? r.input);
1972
- return pt(t, a, r, e, i), [{
1973
- type: "tool_upsert",
1974
- name: e,
1975
- args: i,
1976
- status: n
1977
- }];
1978
- }
1979
- if (i === "function_call_output") return [{
1980
- type: "tool_result",
1981
- name: Y(t, a, r),
1982
- output: q(r.output ?? r.result ?? r.content)
1983
- }];
1984
- if (i === "mcp_user_question") {
1985
- let n = String(r.id || r.question_id || ""), i = Array.isArray(r.questions) ? r.questions : [], a = String(r.run_id || r.runId || e?.run_id || e?.runId || "");
1986
- return [{
1987
- type: "question_request",
1988
- questionId: n,
1989
- questions: i,
1990
- previousResponseId: String(e?.response_id || t.currentResponseId || ""),
1991
- ...a ? { runId: a } : {}
1992
- }];
1993
- }
1994
- if (i === "mcp_approval_request") {
1995
- let n = String(r.name || "approval"), i = q(r.arguments ?? r.args), a = String(r.id || r.approval_request_id || ""), o = String(r.run_id || r.runId || e?.run_id || e?.runId || "");
1996
- return [{
1997
- type: "tool_upsert",
1998
- name: n,
1999
- args: i,
2000
- status: "paused",
2001
- approvalRequestId: a,
2002
- previousResponseId: String(e?.response_id || t.currentResponseId || ""),
2003
- serverLabel: String(r.server_label || "")
2004
- }, {
2005
- type: "approval_request",
2006
- approvalRequestId: a,
2007
- previousResponseId: String(e?.response_id || t.currentResponseId || ""),
2008
- ...o ? { runId: o } : {},
2009
- name: n,
2010
- args: i
2011
- }];
2012
- }
2013
- if (i === "reasoning" || i === "reasoning_summary" || i === "reasoning_summary_text") {
2014
- let e = mt(r);
2015
- return e ? [{
2016
- type: "reasoning_delta",
2017
- text: e
2018
- }] : [];
2019
- }
2020
- if (i === "message") {
2021
- let e = mt(r);
2022
- return e ? [{
2023
- type: n === "completed" ? "text_final" : "text_delta",
2024
- text: e
2025
- }] : [];
2026
- }
2027
- return [];
2028
- }
2029
- function yt({ eventName: e, data: t, state: n }) {
2030
- let r = String(t?.type || e || "").trim(), i = String(t?.id || t?.response?.id || t?.response_id || "");
2031
- if (i.startsWith("resp_") && (n.currentResponseId = i), r === "response.tool_call") return [{
2032
- type: "tool_upsert",
2033
- name: String(t?.name || t?.tool_name || "tool"),
2034
- args: q(t?.args ?? t?.arguments),
2035
- status: "running"
2036
- }];
2037
- if (r === "response.tool_result" || r === "response.ksadk.tool_result") return [{
2038
- type: "tool_result",
2039
- name: String(t?.name || t?.tool_name || "tool"),
2040
- output: q(t?.output ?? t?.result)
2041
- }];
2042
- if (r === "response.output_item.added") return vt({
2043
- data: t,
2044
- state: n,
2045
- status: "running"
2046
- });
2047
- if (r === "response.output_item.done") return vt({
2048
- data: t,
2049
- state: n,
2050
- status: "completed"
2051
- });
2052
- if (r === "response.function_call_arguments.delta") {
2053
- let e = String(t?.item_id || t?.call_id || ""), r = Y(n, e, t), i = `${n.toolArguments.get(e) || ""}${String(t?.delta || "")}`;
2054
- return n.toolArguments.set(e, i), [{
2055
- type: "tool_upsert",
2056
- name: r,
2057
- args: i,
2058
- status: "running"
2059
- }];
2060
- }
2061
- if (r === "response.function_call_arguments.done") {
2062
- let e = String(t?.item_id || t?.call_id || ""), r = Y(n, e, t), i = q(t?.arguments ?? n.toolArguments.get(e));
2063
- return n.toolArguments.set(e, i), [{
2064
- type: "tool_upsert",
2065
- name: r,
2066
- args: i,
2067
- status: "running"
2068
- }];
2069
- }
2070
- if (r === "response.reasoning.delta" || r === "response.reasoning_text.delta" || r === "response.reasoning_summary.delta" || r === "response.reasoning_summary_text.delta") {
2071
- let e = J(t?.delta, t?.text);
2072
- return e && (n.sawReasoningDelta = !0), e ? [{
2073
- type: "reasoning_delta",
2074
- text: e
2075
- }] : [];
2076
- }
2077
- if (r === "response.output_text.delta") {
2078
- if (t?.replace === !0 && (typeof t.delta == "string" || typeof t.text == "string")) return n.sawTextDelta = !0, [{
2079
- type: "text_replace",
2080
- text: typeof t.delta == "string" ? t.delta : t.text
2081
- }];
2082
- let e = J(t?.delta, t?.text);
2083
- return e && (n.sawTextDelta = !0), e ? [{
2084
- type: "text_delta",
2085
- text: e
2086
- }] : [];
2087
- }
2088
- if (r === "response.output_text.done") {
2089
- let e = J(t?.text, t?.delta);
2090
- return e ? [{
2091
- type: "text_final",
2092
- text: e
2093
- }] : [];
2094
- }
2095
- if (r === "response.content_part.delta") {
2096
- let e = String(t?.part?.type || t?.delta?.type || t?.content_type || ""), r = J(t?.delta?.text, t?.delta, t?.text);
2097
- return r ? e.includes("reasoning") ? (n.sawReasoningDelta = !0, [{
2098
- type: "reasoning_delta",
2099
- text: r
2100
- }]) : (n.sawTextDelta = !0, [{
2101
- type: "text_delta",
2102
- text: r
2103
- }]) : [];
2104
- }
2105
- if (r === "response.completed") {
2106
- let e = ht(t), r = gt(t).flatMap((e) => vt({
2107
- data: {
2108
- ...t,
2109
- item: e
2110
- },
2111
- state: n,
2112
- status: "completed"
2113
- })).filter((e) => !(n.sawTextDelta && e.type === "text_final") && !(n.sawReasoningDelta && e.type === "reasoning_delta")), i = r.some((e) => e.type === "text_final");
2114
- return [
2115
- ...r,
2116
- ...e && !n.sawTextDelta && !i ? [{
2117
- type: "text_final",
2118
- text: e
2119
- }] : [],
2120
- {
2121
- type: "terminal",
2122
- status: "completed"
2123
- }
2124
- ];
2125
- }
2126
- if (r === "response.failed") return [{
2127
- type: "failed",
2128
- message: t?.error?.message || "Agent 运行失败"
2129
- }, {
2130
- type: "terminal",
2131
- status: "failed"
2132
- }];
2133
- if (r === "response.incomplete") return [{ type: "incomplete" }, {
2134
- type: "terminal",
2135
- status: "incomplete"
2136
- }];
2137
- if (r === "response.cancelled") return [{
2138
- type: "terminal",
2139
- status: "cancelled"
2140
- }];
2141
- if (r === "response.approval_request" || r === "response.ksadk.approval_request") {
2142
- let e = _t(t?.interrupt_info), r = String(e.approval_request_id || e.id || ""), i = String(t?.response_id || n.currentResponseId || ""), a = String(t?.run_id || t?.runId || ""), o = e.approval_requests && typeof e.approval_requests == "object" ? e.approval_requests : e, s = Array.isArray(o.action_requests) ? o.action_requests : [];
2143
- if (s.length > 0) {
2144
- let e = s.map((e) => ({
2145
- type: "tool_upsert",
2146
- name: String(e?.name || "tool"),
2147
- args: JSON.stringify(e?.args ?? {}),
2148
- status: "paused",
2149
- approvalRequestId: r,
2150
- previousResponseId: i
2151
- })), t = s[0] || {};
2152
- return [...e, {
2153
- type: "approval_request",
2154
- approvalRequestId: r,
2155
- previousResponseId: i,
2156
- ...a ? { runId: a } : {},
2157
- name: String(t?.name || "人工确认"),
2158
- args: JSON.stringify(t?.args ?? {})
2159
- }];
2160
- }
2161
- return [{
2162
- type: "approval_request",
2163
- approvalRequestId: r,
2164
- previousResponseId: i,
2165
- ...a ? { runId: a } : {}
2166
- }];
2167
- }
2168
- if (r === "response.question_resolved" || r === "response.ksadk.question_resolved") return [{
2169
- type: "question_resolved",
2170
- questionId: String(t?.question_id || t?.questionId || ""),
2171
- answers: t?.answers && typeof t.answers == "object" ? t.answers : {},
2172
- revision: Number(t?.revision || 2)
2173
- }];
2174
- if (r === "response.approval_resolved" || r === "response.ksadk.approval_resolved") {
2175
- let e = String(t?.decision || t?.outcome || "").toLowerCase(), n = e === "reject" || e === "rejected" || e === "denied" ? "rejected" : e === "cancel" || e === "cancelled" || e === "canceled" ? "cancelled" : "approved";
2176
- return [{
2177
- type: "approval_resolved",
2178
- approvalRequestId: String(t?.approval_request_id || t?.approvalRequestId || t?.approval_id || t?.approvalId || ""),
2179
- decision: n,
2180
- revision: Number(t?.revision || 2)
2181
- }];
2182
- }
2183
- if (new Set([
2184
- "response.ksadk.a2ui_surface_begin",
2185
- "a2ui.surface.begin",
2186
- "response.a2ui.createSurface",
2187
- "a2ui.createSurface",
2188
- "createSurface"
2189
- ]).has(r)) {
2190
- let e = t?.surface && typeof t.surface == "object" ? t.surface : {};
2191
- return [{
2192
- type: "a2ui_surface_begin",
2193
- surfaceId: String(t?.surface_id || t?.surfaceId || e.surface_id || e.surfaceId || ""),
2194
- surface: e
2195
- }];
2196
- }
2197
- if (new Set([
2198
- "response.ksadk.a2ui_surface_update",
2199
- "a2ui.surface.update",
2200
- "response.a2ui.updateComponents",
2201
- "a2ui.updateComponents",
2202
- "updateComponents"
2203
- ]).has(r)) {
2204
- let e = t?.surface && typeof t.surface == "object" ? t.surface : {};
2205
- return [{
2206
- type: "a2ui_surface_update",
2207
- surfaceId: String(t?.surface_id || t?.surfaceId || e.surface_id || e.surfaceId || ""),
2208
- surface: e
2209
- }];
2210
- }
2211
- if (new Set([
2212
- "response.ksadk.a2ui_surface_end",
2213
- "a2ui.surface.end",
2214
- "response.a2ui.deleteSurface",
2215
- "a2ui.deleteSurface",
2216
- "deleteSurface"
2217
- ]).has(r)) return [{
2218
- type: "a2ui_surface_end",
2219
- surfaceId: String(t?.surface_id || t?.surfaceId || "")
2220
- }];
2221
- if (new Set(["response.ksadk.a2ui_interaction", "a2ui.interaction"]).has(r)) return [{
2222
- type: "a2ui_interaction",
2223
- surfaceId: String(t?.surface_id || t?.surfaceId || ""),
2224
- interactionId: String(t?.interaction_id || t?.interactionId || ""),
2225
- kind: String(t?.kind || "input"),
2226
- inputSchema: t?.input_schema && typeof t.input_schema == "object" ? t.input_schema : {}
2227
- }];
2228
- let a = t?.content?.parts?.[0]?.text;
2229
- return a && !t?.actions?.finishReason ? [{
2230
- type: "text_delta",
2231
- text: String(a)
2232
- }] : [];
2233
- }
2234
- //#endregion
2235
- //#region src/utils/session-events.js
2236
- var bt = new Set([
2237
- "completed",
2238
- "failed",
2239
- "error",
2240
- "cancelled",
2241
- "canceled",
2242
- "aborted",
2243
- "interrupted",
2244
- "resume_failed"
2245
- ]), xt = new Set([
2246
- "tool_call",
2247
- "tool_result",
2248
- "stage_tool_call",
2249
- "stage_tool_result"
2250
- ]), St = {
2251
- "run.started": "in_progress",
2252
- "run.progress": "in_progress",
2253
- "run.interrupted": "interrupted",
2254
- "run.completed": "completed",
2255
- "run.failed": "failed",
2256
- "run.canceled": "cancelled"
2257
- };
2258
- function X(e) {
2259
- let t = e?.Content?.payload;
2260
- return t && typeof t == "object" ? t : {};
2261
- }
2262
- function Ct(e, t) {
2263
- let n = String(e || ""), r = String(t || "");
2264
- return n ? !r || n.endsWith(r) ? n : r.startsWith(n) ? r : `${n}${r}` : r;
2265
- }
2266
- function wt(e) {
2267
- let t = String(e?.EventType || ""), n = X(e);
2268
- return St[t] ? {
2269
- ...e,
2270
- EventType: "run_status",
2271
- Content: {
2272
- status: String(n.status || St[t]),
2273
- ...n.detail ? { detail: String(n.detail) } : {}
2274
- }
2275
- } : t === "reasoning.delta" || t === "reasoning.completed" ? {
2276
- ...e,
2277
- EventType: "reasoning",
2278
- Content: {
2279
- role: "model",
2280
- parts: [{ text: String(n.text || "") }]
2281
- }
2282
- } : t === "tool.call.begin" ? {
2283
- ...e,
2284
- EventType: "tool_call",
2285
- Metadata: {
2286
- ...e.Metadata || {},
2287
- tool_name: n.name,
2288
- tool_args: n.args,
2289
- tool_call_id: n.call_id
2290
- },
2291
- Content: {
2292
- role: "model",
2293
- parts: []
2294
- }
2295
- } : t === "tool.call.end" ? {
2296
- ...e,
2297
- EventType: "tool_result",
2298
- Metadata: {
2299
- ...e.Metadata || {},
2300
- tool_name: n.name,
2301
- tool_output: n.error || n.result,
2302
- tool_call_id: n.call_id
2303
- },
2304
- Content: {
2305
- role: "model",
2306
- parts: []
2307
- }
2308
- } : e;
2309
- }
2310
- function Tt(e) {
2311
- let t = [], n = /* @__PURE__ */ new Map();
2312
- for (let r of Array.isArray(e) ? e : []) {
2313
- let e = String(r?.EventType || "");
2314
- if (e === "text.delta" || e === "text.completed" || e === "message.delta") {
2315
- let e = String(r?.InvocationId || "").trim();
2316
- if (!e) continue;
2317
- let t = n.get(e);
2318
- n.set(e, {
2319
- event: r,
2320
- text: Ct(t?.text, X(r).text || r?.Content?.text)
2321
- });
2322
- continue;
2323
- }
2324
- t.push(wt(r));
2325
- }
2326
- for (let { event: e, text: r } of n.values()) t.push({
2327
- ...e,
2328
- EventType: "assistant_stream_snapshot",
2329
- Content: {
2330
- role: "model",
2331
- parts: [{ text: r }]
2332
- },
2333
- Metadata: {
2334
- ...e.Metadata || {},
2335
- stream_snapshot: !0
2336
- }
2337
- });
2338
- for (let n of Array.isArray(e) ? e : []) String(n?.EventType || "") === "message.completed" && t.push({
2339
- ...n,
2340
- EventType: "assistant_message",
2341
- Content: {
2342
- role: "model",
2343
- parts: [{ text: String(X(n).text || n?.Content?.text || "") }]
2344
- }
2345
- });
2346
- return t.sort((e, t) => Q(e) - Q(t));
2347
- }
2348
- function Et(e) {
2349
- let t = String(e?.EventType || "").trim();
2350
- if (t !== "run_status" && !t.startsWith("run.")) return "";
2351
- let n = X(e);
2352
- return String(e?.Content?.status || n.status || St[t] || "").trim().toLowerCase();
2353
- }
2354
- function Dt(e) {
2355
- return typeof e == "string" ? e : Array.isArray(e) ? e.map((e) => typeof e == "string" ? e : e && typeof e == "object" && typeof e.text == "string" ? e.text : "").join("") : "";
2356
- }
2357
- function Ot(e) {
2358
- let t = String(e || "").trim();
2359
- return t ? `/agentengine/api/v1/AttachmentContent?FileUri=${encodeURIComponent(t)}` : "";
2360
- }
2361
- function kt(e) {
2362
- return String(e || "").match(/^data:([^;,]+)/)?.[1] || "";
2363
- }
2364
- function At(e, t) {
2365
- let n = String(e || "").trim(), r = String(t || "").trim();
2366
- return !n || !r || n === r ? !0 : n.endsWith("/*") ? r.startsWith(n.slice(0, -1)) : r.endsWith("/*") ? n.startsWith(r.slice(0, -1)) : !1;
2367
- }
2368
- function Z(e) {
2369
- let t = e?.Content?.parts || [], n = [], r = /* @__PURE__ */ new Map(), i = (e) => {
2370
- let t = `${e.fileUri || e.url || e.name}|${e.type}`;
2371
- r.has(t) || r.set(t, e);
2372
- };
2373
- for (let e of t) {
2374
- if (e?.type === "input_text" || e?.text) {
2375
- n.push(e.text || "");
2376
- continue;
2377
- }
2378
- if (e?.type === "input_file" && e.inlineData) {
2379
- i({
2380
- name: e.inlineData.displayName || "attachment",
2381
- url: `data:${e.inlineData.mimeType || "application/octet-stream"};base64,${e.inlineData.data}`,
2382
- type: e.inlineData.mimeType || "application/octet-stream"
2383
- });
2384
- continue;
2385
- }
2386
- if (e?.type === "input_file" && typeof e.file_data == "string" && e.file_data) {
2387
- i({
2388
- name: e.filename || e.displayName || e.display_name || "attachment",
2389
- url: `data:${e.mime_type || e.mimeType || "application/octet-stream"};base64,${e.file_data}`,
2390
- type: e.mime_type || e.mimeType || "application/octet-stream"
2391
- });
2392
- continue;
2393
- }
2394
- if (e?.type === "input_file" && typeof e.file_url == "string" && e.file_url.trim()) {
2395
- let t = e.file_url.trim();
2396
- i({
2397
- name: e.filename || e.displayName || e.display_name || "attachment",
2398
- url: Ot(t),
2399
- type: e.mime_type || e.mimeType || "application/octet-stream",
2400
- fileUri: t
2401
- });
2402
- continue;
2403
- }
2404
- if (e?.type === "input_image" || e?.type === "image_url") {
2405
- let t = typeof e.image_url == "string" ? e.image_url : e.image_url?.url;
2406
- t && i({
2407
- name: e.filename || e.displayName || e.display_name || "uploaded_image",
2408
- url: t,
2409
- type: e.mime_type || e.mimeType || kt(t) || "image/*"
2410
- });
2411
- continue;
2412
- }
2413
- if (e?.type === "input_file" && e.fileData) {
2414
- let t = String(e.fileData.fileUri || "").trim();
2415
- i({
2416
- name: e.fileData.displayName || "attachment",
2417
- url: Ot(t),
2418
- type: e.fileData.mimeType || "application/octet-stream",
2419
- fileUri: t
2420
- });
2421
- }
2422
- }
2423
- let a = Array.isArray(e?.Metadata?.attachments) ? e.Metadata.attachments : [];
2424
- for (let e of a) {
2425
- let t = String(e.file_uri || "").trim(), n = {
2426
- name: e.display_name || "attachment",
2427
- url: Ot(t),
2428
- type: e.mime_type || "application/octet-stream",
2429
- fileUri: t
2430
- };
2431
- !n.url && !n.fileUri && Array.from(r.values()).some((e) => e.name === n.name && At(e.type, n.type) && (e.url || e.fileUri)) || i(n);
2432
- }
2433
- let o = Array.from(r.values());
2434
- return {
2435
- text: n.join(""),
2436
- attachments: o.length > 0 ? o : void 0
2437
- };
2438
- }
2439
- function jt(e) {
2440
- let t = e?.Metadata?.responses_output;
2441
- if (!Array.isArray(t)) return {};
2442
- let r = ut(), i = yt({
2443
- eventName: "response.completed",
2444
- data: { response: {
2445
- id: String(e.Metadata?.response_id || ""),
2446
- output: t
2447
- } },
2448
- state: r
2449
- }), a = "", o = {};
2450
- for (let e of i) {
2451
- if (e.type === "reasoning_delta") {
2452
- a += e.text;
2453
- continue;
2454
- }
2455
- if (e.type === "tool_upsert") {
2456
- o[e.name] = {
2457
- ...o[e.name] || {
2458
- name: e.name,
2459
- args: ""
2460
- },
2461
- name: e.name,
2462
- args: e.args,
2463
- status: e.status,
2464
- ...e.approvalRequestId ? { approvalRequestId: e.approvalRequestId } : {},
2465
- ...e.previousResponseId ? { previousResponseId: e.previousResponseId } : {},
2466
- ...e.serverLabel ? { serverLabel: e.serverLabel } : {},
2467
- ...e.approvalRequestId ? { approvalStatus: "pending" } : {}
2468
- };
2469
- continue;
2470
- }
2471
- e.type === "tool_result" && (o[e.name] = {
2472
- ...o[e.name] || {
2473
- name: e.name,
2474
- args: ""
2475
- },
2476
- name: e.name,
2477
- output: e.output,
2478
- status: n(e.output) ? "error" : "completed"
2479
- });
2480
- }
2481
- return {
2482
- ...a ? { reasoning: a } : {},
2483
- ...Object.keys(o).length > 0 ? { tools: o } : {}
2484
- };
2485
- }
2486
- function Mt(e, t, n) {
2487
- return t === "running" ? e === "prompt_too_long" ? "检测到上下文过长,正在自动压缩历史后重试" : "正在自动压缩上下文" : n ? e === "prompt_too_long" ? "上下文过长,系统已自动压缩历史并重试" : "系统已自动压缩较早的对话上下文" : t === "failed" ? "自动压缩上下文未完成" : e === "prompt_too_long" ? "已完成上下文压缩,并继续当前回复" : "已完成上下文压缩";
2488
- }
2489
- function Nt(e, t) {
2490
- return t?.itemId ? [
2491
- "runtime-item",
2492
- t.runId || e,
2493
- t.scopeId || e,
2494
- t.itemId
2495
- ].join("\0") : [
2496
- e,
2497
- t.content || "",
2498
- t.reasoning || ""
2499
- ].join("\0");
2500
- }
2501
- function Pt(e) {
2502
- let t = String(e?.InvocationId || "").trim(), n = e?.Metadata?.RuntimeItem;
2503
- return n?.ItemId ? [
2504
- "runtime-item",
2505
- n.RunId || t,
2506
- n.ScopeId || t,
2507
- n.ItemId
2508
- ].join("\0") : t;
2509
- }
2510
- function Ft(e) {
2511
- let t = e?.Metadata?.RuntimeItem;
2512
- return t?.ItemId ? {
2513
- id: `runtime:${t.RunId || e.InvocationId || "run"}:${t.ScopeId || e.InvocationId || "scope"}:${t.ItemId}`,
2514
- runId: String(t.RunId || e.InvocationId || ""),
2515
- scopeId: String(t.ScopeId || e.InvocationId || ""),
2516
- itemId: String(t.ItemId),
2517
- partId: t.PartId ? String(t.PartId) : void 0
2518
- } : null;
2519
- }
2520
- function It(e) {
2521
- return e?.Metadata?.responses_mirror === !0 || String(e?.Metadata?.responses_mirror || "").trim().toLowerCase() === "true";
2522
- }
2523
- function Lt(e) {
2524
- if (e?.EventType !== "user_message") return "";
2525
- let t = Z(e), n = (t.attachments || []).map((e) => [
2526
- e.name || "",
2527
- e.fileUri || "",
2528
- e.url || "",
2529
- e.type || ""
2530
- ].join("")).sort().join("");
2531
- return [String(t.text || "").trim(), n].join("\0");
2532
- }
2533
- function Rt(e) {
2534
- return e?.EventType === "assistant_stream_snapshot";
2535
- }
1912
+ //#region src/utils/persisted-session-history.ts
2536
1913
  function Q(e) {
2537
- let t = Number(e?.SeqId || 0);
2538
- if (Number.isFinite(t) && t > 0) return t;
2539
- let n = Number(e?.Timestamp || 0);
2540
- return Number.isFinite(n) ? n : 0;
2541
- }
2542
- function zt(e) {
2543
- if (typeof e == "string") return e;
2544
- if (e == null) return "";
2545
- try {
2546
- return JSON.stringify(e, null, 2);
2547
- } catch {
2548
- return String(e);
2549
- }
2550
- }
2551
- function Bt(e) {
2552
- let t = String(e?.EventType || "");
2553
- if (!xt.has(t)) return null;
2554
- let r = String(e.Metadata?.tool_name || e.Metadata?.name || e.Metadata?.function_name || Dt(e.Content?.parts) || "tool").trim() || "tool", i = String(e.Metadata?.call_id || e.Metadata?.callId || e.Metadata?.RuntimeItem?.ToolCallId || "").trim(), a = {
2555
- name: r,
2556
- ...i ? { callId: i } : {},
2557
- args: "",
2558
- status: "running"
2559
- }, o = t === "tool_result" || t === "stage_tool_result" ? (() => {
2560
- let t = zt(e.Metadata?.tool_output ?? e.Metadata?.output ?? e.Metadata?.result ?? Dt(e.Content?.parts));
2561
- return {
2562
- ...a,
2563
- output: t,
2564
- status: n(t) ? "error" : "completed"
2565
- };
2566
- })() : {
2567
- ...a,
2568
- args: zt(e.Metadata?.tool_args ?? e.Metadata?.arguments ?? e.Metadata?.args ?? {})
2569
- }, s = Ft(e);
2570
- return {
2571
- id: s?.id || e.EventId || String(Date.now() + Math.random()),
2572
- role: "model",
2573
- content: "",
2574
- timestamp: e.Timestamp || Date.now(),
2575
- eventType: t,
2576
- ...s || {},
2577
- tools: { [r]: o }
2578
- };
2579
- }
2580
- function Vt(e = {}, t = {}) {
2581
- let n = { ...e || {} };
2582
- for (let [e, r] of Object.entries(t || {})) n[e] = {
2583
- ...n[e] || {},
2584
- ...r || {},
2585
- name: e,
2586
- args: r?.args || n[e]?.args || ""
2587
- };
2588
- return n;
2589
- }
2590
- function Ht(e = {}, t = "") {
2591
- let n = String(t || "").trim().toLowerCase(), r = n === "completed" ? "completed" : bt.has(n) ? "error" : "";
2592
- if (!r) return e;
2593
- let i = !1, a = {};
2594
- for (let [t, n] of Object.entries(e || {})) n?.status === "running" ? (i = !0, a[t] = {
2595
- ...n,
2596
- status: r
2597
- }) : a[t] = n;
2598
- return i ? a : e;
2599
- }
2600
- function Ut(e, t) {
2601
- return {
2602
- ...e,
2603
- reasoning: Wt(e.reasoning, t.reasoning),
2604
- tools: Vt(e.tools, t.tools),
2605
- eventId: t.eventId || e.eventId,
2606
- responseId: t.responseId || e.responseId,
2607
- traceId: t.traceId || e.traceId,
2608
- rootSpanId: t.rootSpanId || e.rootSpanId,
2609
- timestamp: Math.max(Number(e.timestamp || 0), Number(t.timestamp || 0)) || t.timestamp || e.timestamp,
2610
- id: t.responseId || t.reasoning || t.tools ? t.id : e.id
2611
- };
2612
- }
2613
- function Wt(e = "", t = "") {
2614
- let n = String(e || ""), r = String(t || "");
2615
- return n ? !r || n.endsWith(r) ? n : r.startsWith(n) ? r : `${n}${r}` : r;
2616
- }
2617
- function Gt(e) {
2618
- return {
2619
- id: e.id,
2620
- role: "system",
2621
- eventType: "context_checkpoint",
2622
- status: e.status,
2623
- trigger: e.trigger,
2624
- compactedUntilSeqId: e.compactedUntilSeqId,
2625
- summary: e.summary,
2626
- historical: e.historical,
2627
- timestamp: e.timestamp,
2628
- content: Mt(e.trigger, e.status, e.historical)
2629
- };
2630
- }
2631
- function Kt(e) {
2632
- let t = qt(e);
2633
- return t && Number.isSafeInteger(e.SeqId) && e.SeqId > 0 && (t.historyOrder = { seq: e.SeqId }), t;
2634
- }
2635
- function qt(e) {
2636
- let t = e?.EventType || "", n = Ft(e);
2637
- if (t === "run_status") return e.Content?.status === "failed" ? {
2638
- id: e.EventId || String(Date.now() + Math.random()),
2639
- role: "system",
2640
- content: e.Content?.detail || "本轮运行失败。",
2641
- eventType: t,
2642
- status: "failed",
2643
- timestamp: e.Timestamp || Date.now()
2644
- } : e.Content?.status === "cancelled" ? {
2645
- id: e.EventId || String(Date.now() + Math.random()),
2646
- role: "system",
2647
- content: e.Content?.detail || "本轮输出已停止。",
2648
- eventType: t,
2649
- status: "cancelled",
2650
- timestamp: e.Timestamp || Date.now()
2651
- } : null;
2652
- if (t === "context_checkpoint") {
2653
- let t = Z(e);
2654
- return Gt({
2655
- id: e.EventId || String(Date.now() + Math.random()),
2656
- timestamp: e.Timestamp || Date.now(),
2657
- status: "completed",
2658
- trigger: String(e.Metadata?.trigger || "auto"),
2659
- compactedUntilSeqId: Number(e.Metadata?.compacted_until_seq_id || 0) || void 0,
2660
- summary: t.text || void 0,
2661
- historical: !0
2662
- });
2663
- }
2664
- if (t === "reasoning") {
2665
- let r = Z(e).text || Dt(e.Metadata?.reasoning);
2666
- return r ? {
2667
- id: n?.id || e.EventId || String(Date.now() + Math.random()),
2668
- role: "model",
2669
- content: "",
2670
- reasoning: r,
2671
- ...e.Metadata?.presentation_source === "public_summary" ? { reasoningSource: "public_summary" } : e.Metadata?.presentation_source === "provider_reasoning" ? { reasoningSource: "provider_reasoning" } : {},
2672
- timestamp: e.Timestamp || Date.now(),
2673
- eventType: t,
2674
- ...n || {}
2675
- } : null;
2676
- }
2677
- if (xt.has(t)) return Bt(e);
2678
- if (t !== "user_message" && t !== "assistant_message" && t !== "assistant_stream_snapshot") return null;
2679
- let r = Z(e), i = t === "assistant_message" ? jt(e) : {};
2680
- if (!r.text && !r.attachments?.length && !i.reasoning && !i.tools) return null;
2681
- let a = String(e.Metadata?.response_id || e.Metadata?.ResponseId || "").trim(), o = String(e.Metadata?.trace_id || e.Metadata?.TraceId || "").trim(), s = String(e.Metadata?.root_span_id || e.Metadata?.rootSpanId || e.Metadata?.RootSpanId || "").trim();
2682
- return {
2683
- id: n?.id || e.EventId || String(Date.now() + Math.random()),
2684
- role: t === "user_message" ? "user" : "model",
2685
- content: r.text,
2686
- timestamp: e.Timestamp || Date.now(),
2687
- eventType: t,
2688
- eventId: e.EventId || void 0,
2689
- responseId: a || void 0,
2690
- traceId: o || void 0,
2691
- rootSpanId: s || void 0,
2692
- attachments: r.attachments,
2693
- ...n || {},
2694
- ...i
2695
- };
1914
+ return e && typeof e == "object" && !Array.isArray(e) ? e : null;
2696
1915
  }
2697
- function Jt(e = []) {
2698
- let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = Tt(e), c = [];
2699
- for (let e of s) {
2700
- let t = String(e?.EventId || "").trim();
2701
- if (t) {
2702
- if (o.has(t)) continue;
2703
- o.add(t);
2704
- }
2705
- c.push(e);
2706
- }
2707
- let l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map();
2708
- for (let e of c) {
2709
- if (e?.EventType !== "user_message" || It(e)) {
2710
- if (e?.EventType === "assistant_message") {
2711
- let t = Pt(e);
2712
- t && u.add(t);
2713
- }
2714
- if (Rt(e)) {
2715
- let t = Pt(e);
2716
- if (t) {
2717
- let n = d.get(t);
2718
- (!n || Q(e) >= Q(n)) && d.set(t, e);
2719
- }
2720
- }
2721
- continue;
2722
- }
2723
- let t = Lt(e);
2724
- t && l.add(t);
2725
- }
2726
- let f = c.filter((e) => {
2727
- if (Rt(e)) {
2728
- let t = Pt(e);
2729
- return t ? u.has(t) ? !1 : d.get(t) === e : !0;
2730
- }
2731
- if (e?.EventType !== "user_message" || !It(e)) return !0;
2732
- let t = Lt(e);
2733
- return !t || !l.has(t);
2734
- });
2735
- for (let e of f) {
2736
- let a = String(e.InvocationId || "").trim();
2737
- a && e.EventType === "user_message" && i.add(a), a && [
2738
- "assistant_message",
2739
- "assistant_stream_snapshot",
2740
- "reasoning",
2741
- "tool_call",
2742
- "tool_result",
2743
- "stage_tool_call",
2744
- "stage_tool_result"
2745
- ].includes(String(e.EventType || "")) && r.add(a), e.EventType === "run_status" && a && (t.set(a, String(e.Content?.status || "").trim()), n.set(a, e));
2746
- }
2747
- let p = [], m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = null, _ = /* @__PURE__ */ new Map(), v = (e) => {
2748
- let t = e?.itemId ? `${e.runId || e.invocationId || ""}\u0000${e.scopeId || e.invocationId || ""}\u0000${e.itemId}` : "", n = t ? h.get(t) : void 0;
2749
- if (n !== void 0) {
2750
- p[n] = Ut(p[n], e);
2751
- return;
2752
- }
2753
- let r = String(e?.responseId || "").trim(), i = r ? m.get(r) : void 0;
2754
- if (i !== void 0) {
2755
- p[i] = Ut(p[i], e);
2756
- return;
2757
- }
2758
- r && m.set(r, p.length), t && h.set(t, p.length), p.push(e);
2759
- }, y = () => {
2760
- g &&= (v(g), null);
2761
- }, b = (e, n = "") => {
2762
- let r = String(e || "").trim();
2763
- if (!r) return {};
2764
- let i = _.get(r);
2765
- return i ? (_.delete(r), { tools: Ht(i.tools, t.get(r) || n) }) : {};
2766
- };
2767
- for (let e of f) {
2768
- if (e.EventType === "run_status") continue;
2769
- let t = Kt(e);
2770
- if (!t) continue;
2771
- let n = String(e.InvocationId || "").trim();
2772
- if (n && (t.invocationId = n), xt.has(t.eventType)) {
2773
- let n = String(e.InvocationId || "").trim();
2774
- if (t.itemId) {
2775
- y(), v(t);
2776
- continue;
2777
- }
2778
- if (!n) {
2779
- y(), v(t);
2780
- continue;
2781
- }
2782
- let r = _.get(n);
2783
- _.set(n, {
2784
- ...r || {
2785
- id: t.id,
2786
- role: "model",
2787
- content: "",
2788
- timestamp: t.timestamp,
2789
- invocationId: n
2790
- },
2791
- timestamp: Math.max(Number(r?.timestamp || 0), Number(t.timestamp || 0)),
2792
- tools: Vt(r?.tools, t.tools)
2793
- });
2794
- continue;
2795
- }
2796
- if (t.eventType === "reasoning") {
2797
- let n = String(e.InvocationId || "").trim(), r = String(e.Metadata?.RuntimeItem?.Operation || "").toLowerCase(), i = !!(t.itemId && g?.itemId === t.itemId && g?.runId === t.runId && g?.scopeId === t.scopeId), a = !!(!t.itemId && !g?.itemId && n && g?.invocationId === n);
2798
- if (g && (i || a)) {
2799
- g.reasoning = r === "replace" || r === "completed" ? t.reasoning : `${g.reasoning || ""}${t.reasoning || ""}`, g.timestamp = t.timestamp;
2800
- continue;
2801
- }
2802
- y(), g = {
2803
- ...t,
2804
- ...n ? { invocationId: n } : {}
2805
- };
2806
- continue;
2807
- }
2808
- let r = t.eventType === "assistant_message" || t.eventType === "assistant_stream_snapshot";
2809
- if (r && g) {
2810
- let n = String(e.InvocationId || "").trim(), r = Nt(n, t);
2811
- if (t.eventType === "assistant_message" && n && a.has(r)) {
2812
- g = null;
2813
- continue;
2814
- }
2815
- t.eventType === "assistant_message" && n && a.add(r), v({
2816
- ...t,
2817
- ...b(n, t.eventType === "assistant_message" ? "completed" : ""),
2818
- reasoning: Wt(g.reasoning, t.reasoning)
2819
- }), g = null;
2820
- continue;
2821
- }
2822
- if (y(), r) {
2823
- let n = String(e.InvocationId || "").trim(), r = Nt(n, t);
2824
- if (t.eventType === "assistant_message" && n && a.has(r)) continue;
2825
- t.eventType === "assistant_message" && n && a.add(r), v({
2826
- ...t,
2827
- ...b(n, t.eventType === "assistant_message" ? "completed" : "")
2828
- });
2829
- continue;
2830
- }
2831
- v(t);
2832
- }
2833
- y();
2834
- for (let [e, n] of _.entries()) v({
2835
- ...n,
2836
- tools: Ht(n.tools, t.get(e))
2837
- });
2838
- for (let [e, a] of t.entries()) {
2839
- if (a !== "in_progress" || r.has(e) || !i.has(e)) continue;
2840
- let t = n.get(e) || {};
2841
- v({
2842
- id: `run-placeholder-${e}`,
2843
- role: "model",
2844
- content: "",
2845
- status: "running",
2846
- eventType: "run_status",
2847
- timestamp: t.Timestamp || Date.now()
2848
- });
2849
- }
2850
- return p;
2851
- }
2852
- function Yt(e = [], t = []) {
2853
- let n = [], r = /* @__PURE__ */ new Set();
2854
- for (let i of [...Array.isArray(e) ? e : [], ...Array.isArray(t) ? t : []]) {
2855
- let e = String(i?.EventId || "").trim();
2856
- if (e) {
2857
- if (r.has(e)) continue;
2858
- r.add(e);
1916
+ function ot(e) {
1917
+ let t = e.map(ct), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t, n) => JSON.stringify([
1918
+ e,
1919
+ t,
1920
+ n
1921
+ ]);
1922
+ for (let e of t) {
1923
+ if (!e || Q(e.source)?.framework !== "langgraph" || e.item_kind !== "tool_call" && e.item_kind !== "tool_result") continue;
1924
+ let t = Q(e.snapshot ?? e.initial)?.parts;
1925
+ if (!Array.isArray(t)) continue;
1926
+ let a = t.map(Q).find((t) => t?.content_type === e.item_kind)?.call_id;
1927
+ if (!(typeof a != "string" || !a)) if (e.item_kind === "tool_result") r.set(i(e.run_id, e.scope_id, e.item_id), a);
1928
+ else {
1929
+ let t = i(e.run_id, e.scope_id, a);
1930
+ n.has(t) ? n.get(t)?.item_id !== e.item_id && n.set(t, null) : n.set(t, e);
2859
1931
  }
2860
- n.push(i);
2861
1932
  }
2862
- return n.sort((e, t) => {
2863
- let n = Number(e?.SeqId || 0), r = Number(t?.SeqId || 0);
2864
- return Number.isFinite(n) && Number.isFinite(r) && n !== r ? n - r : Number(e?.Timestamp || 0) - Number(t?.Timestamp || 0);
1933
+ return t.map((e) => {
1934
+ if (!e || e.item_kind !== "tool_result" || !e.parent_scope_id) return e;
1935
+ let t = r.get(i(e.run_id, e.scope_id, e.item_id));
1936
+ if (!t || n.has(i(e.run_id, e.scope_id, t))) return e;
1937
+ let a = n.get(i(e.run_id, e.parent_scope_id, t));
1938
+ return a ? {
1939
+ ...e,
1940
+ scope_id: a.scope_id,
1941
+ parent_scope_id: a.parent_scope_id
1942
+ } : e;
2865
1943
  });
2866
1944
  }
2867
- function Xt(e = []) {
2868
- return (Array.isArray(e) ? e : []).reduce((e, t) => {
2869
- let n = Number(t.SeqId || 0);
2870
- return Number.isFinite(n) ? Math.max(e, n) : e;
2871
- }, 0);
2872
- }
2873
- function Zt(e) {
2874
- return bt.has(Et(e));
2875
- }
2876
- //#endregion
2877
- //#region src/utils/persisted-session-history.ts
2878
- function $(e) {
2879
- return e && typeof e == "object" && !Array.isArray(e) ? e : null;
2880
- }
2881
- function Qt(e) {
1945
+ function st(e) {
2882
1946
  if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
2883
1947
  if (typeof e == "string" && e.trim()) {
2884
1948
  let t = Number(e.trim());
@@ -2887,17 +1951,17 @@ function Qt(e) {
2887
1951
  let t = Date.parse(String(e || ""));
2888
1952
  return Number.isFinite(t) ? t : Date.now();
2889
1953
  }
2890
- function $t(e) {
2891
- let t = $(e?.Content?.runtime_event || e?.Content?.runtimeEvent);
1954
+ function ct(e) {
1955
+ let t = Q(e?.Content?.runtime_event || e?.Content?.runtimeEvent);
2892
1956
  if (t && String(t.event_type || "")) return {
2893
1957
  ...t,
2894
1958
  family: "runtime",
2895
1959
  seq: Number(e.SeqId || t.seq || 0),
2896
1960
  timestamp: e.Timestamp || t.timestamp
2897
1961
  };
2898
- let n = $(e?.Content?.session_event || e?.Content?.sessionEvent);
1962
+ let n = Q(e?.Content?.session_event || e?.Content?.sessionEvent);
2899
1963
  if (!n || String(n.family || "") !== "runtime") return null;
2900
- let r = $(n.payload);
1964
+ let r = Q(n.payload);
2901
1965
  return !r || !String(r.event_type || n.event_type || "") ? null : {
2902
1966
  ...r,
2903
1967
  family: "runtime",
@@ -2907,58 +1971,58 @@ function $t(e) {
2907
1971
  timestamp: e.Timestamp || n.timestamp || r.timestamp
2908
1972
  };
2909
1973
  }
2910
- function en(e, t, n) {
2911
- let r = /* @__PURE__ */ new Map();
2912
- for (let e of t) {
2913
- if (e.EventType !== "run_status" || $t(e)) continue;
1974
+ function lt(e, n, r) {
1975
+ let i = /* @__PURE__ */ new Map();
1976
+ for (let e of n) {
1977
+ if (e.EventType !== "run_status" || ct(e)) continue;
2914
1978
  let t = String(e.InvocationId || e.Metadata?.run_id || "").trim();
2915
- t && !n.has(t) && r.set(t, e);
1979
+ t && !r.has(t) && i.set(t, e);
2916
1980
  }
2917
- let i = e;
2918
- for (let [e, t] of r) {
2919
- let n = Kt({
2920
- ...t,
2921
- EventId: t.EventId || `legacy-terminal:${e}:${t.SeqId || 0}`,
2922
- Timestamp: Qt(t.Timestamp)
1981
+ let a = e;
1982
+ for (let [e, n] of i) {
1983
+ let r = t({
1984
+ ...n,
1985
+ EventId: n.EventId || `legacy-terminal:${e}:${n.SeqId || 0}`,
1986
+ Timestamp: st(n.Timestamp)
2923
1987
  });
2924
- if (!n) continue;
2925
- let r = (t) => (t.invocationId || t.runId) === e;
2926
- i = i.filter((e) => !(r(e) && e.role === "system" && e.eventType === "run_status")).map((e) => {
2927
- if (!r(e) || e.role !== "model") return e;
2928
- let t = (e) => e === "running" || e === "paused", i = "运行已结束,未记录此工具的最终结果。";
1988
+ if (!r) continue;
1989
+ let i = (t) => (t.invocationId || t.runId) === e;
1990
+ a = a.filter((e) => !(i(e) && e.role === "system" && e.eventType === "run_status")).map((e) => {
1991
+ if (!i(e) || e.role !== "model") return e;
1992
+ let t = (e) => e === "running" || e === "paused", n = "运行已结束,未记录此工具的最终结果。";
2929
1993
  return {
2930
1994
  ...e,
2931
- tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e, n]) => [e, t(n.status) ? {
2932
- ...n,
1995
+ tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e, r]) => [e, t(r.status) ? {
1996
+ ...r,
2933
1997
  status: "unknown",
2934
- summary: n.summary || i
2935
- } : n])),
1998
+ summary: r.summary || n
1999
+ } : r])),
2936
2000
  blocks: e.blocks?.map((e) => e.type === "thinking" && e.status === "streaming" ? {
2937
2001
  ...e,
2938
2002
  status: "done"
2939
2003
  } : e.type !== "tool" || !t(e.status) ? e : {
2940
2004
  ...e,
2941
2005
  status: "unknown",
2942
- summary: e.summary || i,
2006
+ summary: e.summary || n,
2943
2007
  extra: {
2944
2008
  ...e.extra,
2945
2009
  persistedToolStatus: e.status,
2946
- terminalRunStatus: n.status
2010
+ terminalRunStatus: r.status
2947
2011
  }
2948
2012
  })
2949
2013
  };
2950
- }), i.push({
2951
- ...n,
2014
+ }), a.push({
2015
+ ...r,
2952
2016
  invocationId: e,
2953
- eventId: t.EventId
2017
+ eventId: n.EventId
2954
2018
  });
2955
2019
  }
2956
- return i === e ? e : P(i);
2020
+ return a === e ? e : R(a);
2957
2021
  }
2958
- function tn(e) {
2022
+ function $(e) {
2959
2023
  return e.role === "model" ? {
2960
2024
  ...e,
2961
- blocks: e.blocks?.length ? e.blocks : Xe({
2025
+ blocks: e.blocks?.length ? e.blocks : Ke({
2962
2026
  content: e.content,
2963
2027
  reasoning: e.reasoning,
2964
2028
  reasoningSource: e.reasoningSource,
@@ -2966,12 +2030,12 @@ function tn(e) {
2966
2030
  })
2967
2031
  } : e;
2968
2032
  }
2969
- function nn(e, t) {
2033
+ function ut(e, t) {
2970
2034
  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 ? {
2971
2035
  ...e,
2972
2036
  ...n,
2973
2037
  invocationId: e.invocationId || n.invocationId
2974
- } : tn(e === a && o ? {
2038
+ } : $(e === a && o ? {
2975
2039
  ...e,
2976
2040
  responseId: o.responseId || e.responseId,
2977
2041
  traceId: o.traceId || e.traceId,
@@ -2979,7 +2043,7 @@ function nn(e, t) {
2979
2043
  } : e));
2980
2044
  return n && !r ? [n, ...s] : s;
2981
2045
  }
2982
- function rn(e, t) {
2046
+ function dt(e, t) {
2983
2047
  let n = t.filter((e) => e.role === "model"), r = n.flatMap((e) => Object.values(e.tools || {}).map((t) => ({
2984
2048
  tool: t,
2985
2049
  scope: e.scopeId
@@ -2994,7 +2058,7 @@ function rn(e, t) {
2994
2058
  return [t, r ? {
2995
2059
  ...n,
2996
2060
  ...r,
2997
- ...j(n, r),
2061
+ ...F(n, r),
2998
2062
  name: n.name
2999
2063
  } : n];
3000
2064
  })), n = e === s ? a : [];
@@ -3007,10 +2071,10 @@ function rn(e, t) {
3007
2071
  let n = t.extra?.callId, r = typeof n == "string" ? i(n, e.scopeId) : void 0;
3008
2072
  return r ? {
3009
2073
  ...t,
3010
- ...j(t, r)
2074
+ ...F(t, r)
3011
2075
  } : t;
3012
- }), c = Xe({ 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;
3013
- return tn({
2076
+ }), c = Ke({ 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;
2077
+ return $({
3014
2078
  ...e,
3015
2079
  ...e === s ? { reasoning: e.reasoning || o || void 0 } : {},
3016
2080
  tools: Object.keys(t).length ? t : e.tools,
@@ -3022,21 +2086,21 @@ function rn(e, t) {
3022
2086
  });
3023
2087
  });
3024
2088
  }
3025
- function an(e) {
2089
+ function ft(e) {
3026
2090
  return new Set(e.filter((e) => e.role === "model" && e.eventType === "assistant_message" && !!String(e.content || "").trim() && !!e.invocationId).map((e) => String(e.invocationId)));
3027
2091
  }
3028
- var on = new Set([
2092
+ var pt = new Set([
3029
2093
  "approval.resolved",
3030
2094
  "interaction.resolved",
3031
2095
  "interaction.cancelled",
3032
2096
  "interaction.canceled",
3033
2097
  "a2ui.action"
3034
2098
  ]);
3035
- function sn(e) {
2099
+ function mt(e) {
3036
2100
  let t = /* @__PURE__ */ new Set();
3037
2101
  for (let n of e) {
3038
- let e = $(n.Content) || {}, r = $(e.runtime_event || e.runtimeEvent) || {}, i = $(e.payload) || $(r.payload) || {}, a = String(n.EventType || e.event_type || e.eventType || r.event_type || "").toLowerCase();
3039
- if (!on.has(a)) continue;
2102
+ 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();
2103
+ if (!pt.has(a)) continue;
3040
2104
  let o = String(e.outcome || e.action || e.name || e.status || i.outcome || i.action || i.name || i.status || "").toLowerCase();
3041
2105
  if (![
3042
2106
  "cancel",
@@ -3048,65 +2112,64 @@ function sn(e) {
3048
2112
  }
3049
2113
  return t;
3050
2114
  }
3051
- function cn(e, t, n, r = "flat-v1") {
3052
- e = M(e);
3053
- let i = new ot(n), a = [], o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = [...t || []].filter((e) => {
3054
- let t = e.Content, r = $(t?.session_event || t?.sessionEvent), i = $(t?.runtime_event || t?.runtimeEvent);
2115
+ function ht(e, t, n, i = "flat-v1") {
2116
+ e = I(e);
2117
+ let a = new nt(n), o = [], s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = [...t || []].filter((e) => {
2118
+ let t = e.Content, r = Q(t?.session_event || t?.sessionEvent), i = Q(t?.runtime_event || t?.runtimeEvent);
3055
2119
  return [
3056
2120
  e.SessionId,
3057
2121
  r?.session_id,
3058
2122
  i?.session_id
3059
2123
  ].every((e) => !e || e === n);
3060
- }).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), u = Number(l[0]?.SeqId || 0) <= 1;
3061
- for (let e of l) {
3062
- let t = $t(e);
3063
- if (!t) continue;
3064
- let n = String(t.run_id || "").trim();
3065
- if (n) {
3066
- o.add(n), !t.parent_scope_id && [
2124
+ }).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), d = Number(u[0]?.SeqId || 0) <= 1, f = ot(u);
2125
+ for (let [e, t] of u.entries()) {
2126
+ let n = f[e];
2127
+ if (!n) continue;
2128
+ let r = String(n.run_id || "").trim();
2129
+ if (r) {
2130
+ s.add(r), !n.parent_scope_id && [
3067
2131
  "run.completed",
3068
2132
  "run.failed",
3069
2133
  "run.cancelled",
3070
2134
  "run.canceled"
3071
- ].includes(String(t.event_type)) && s.add(n);
3072
- let e = $($(t.source)?.metadata), r = String(t.event_type || "") === "run.started", i = e?.native_item_kind === "userMessage";
3073
- (u || r || i) && c.add(n);
2135
+ ].includes(String(n.event_type)) && c.add(r);
2136
+ let e = Q(Q(n.source)?.metadata), t = String(n.event_type || "") === "run.started", i = e?.native_item_kind === "userMessage";
2137
+ (d || t || i) && l.add(r);
3074
2138
  }
3075
- let r = i.translate(t);
3076
- r && a.push({
3077
- ...r,
3078
- SeqId: Number(e.SeqId || r.SeqId || 0),
3079
- Timestamp: Qt(e.Timestamp || r.Timestamp)
2139
+ let i = a.translate(n);
2140
+ i && o.push({
2141
+ ...i,
2142
+ SeqId: Number(t.SeqId || i.SeqId || 0),
2143
+ Timestamp: st(t.Timestamp || i.Timestamp)
3080
2144
  });
3081
2145
  }
3082
- let d = Jt(a).filter((e) => e.invocationId && o.has(e.invocationId)), f = /* @__PURE__ */ new Map();
2146
+ let p = r(o).filter((e) => e.invocationId && s.has(e.invocationId)), m = /* @__PURE__ */ new Map();
3083
2147
  for (let t of e) {
3084
2148
  let e = String(t.invocationId || "");
3085
- e && f.set(e, [...f.get(e) || [], t]);
2149
+ e && m.set(e, [...m.get(e) || [], t]);
3086
2150
  }
3087
- let p = new Set([...an(d)].filter((e) => c.has(e))), m = /* @__PURE__ */ new Map();
3088
- for (let e of l) {
3089
- let t = $t(e);
3090
- if (t?.schema_version !== 2 || !t.run_id) continue;
3091
- let n = String(t.run_id), r = m.get(n) || [];
3092
- r.push(t), m.set(n, r);
3093
- }
3094
- let h = (e) => [
3095
- $(e.initial),
3096
- $(e.snapshot),
3097
- $(e.update)
3098
- ].some((e) => $(e?.data)?.schema === "execution.scope/v1" || Array.isArray(e?.parts) && e.parts.some((e) => $($(e)?.data)?.schema === "execution.scope/v1")), g = new Set([...m].filter(([, e]) => e.some(h)).map(([e]) => e)), _ = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Set();
3099
- for (let [e, t] of m) {
3100
- if (!g.has(e) && !p.has(e) && !t.some((e) => ["item.failed", "run.failed"].includes(String(e.event_type)))) continue;
3101
- let i = t.some((e) => e.event_type === "run.started" && !e.parent_scope_id), a = /* @__PURE__ */ new Set(), o = t.every((e) => {
2151
+ let h = new Set([...ft(p)].filter((e) => l.has(e))), g = /* @__PURE__ */ new Map();
2152
+ for (let e of f) {
2153
+ if (e?.schema_version !== 2 || !e.run_id) continue;
2154
+ let t = String(e.run_id), n = g.get(t) || [];
2155
+ n.push(e), g.set(t, n);
2156
+ }
2157
+ let _ = (e) => [
2158
+ Q(e.initial),
2159
+ Q(e.snapshot),
2160
+ Q(e.update)
2161
+ ].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();
2162
+ for (let [e, t] of g) {
2163
+ if (!v.has(e) && !h.has(e) && !t.some((e) => ["item.failed", "run.failed"].includes(String(e.event_type)))) continue;
2164
+ let r = t.some((e) => e.event_type === "run.started" && !e.parent_scope_id), a = /* @__PURE__ */ new Set(), o = t.every((e) => {
3102
2165
  let t = JSON.stringify([e.scope_id, e.item_id]);
3103
- return e.event_type === "item.started" && a.add(t), !h(e) || a.has(t);
2166
+ return e.event_type === "item.started" && a.add(t), !_(e) || a.has(t);
3104
2167
  });
3105
- if (!(!i || !o)) try {
3106
- let i = new S(n, void 0, r);
3107
- t.forEach((e) => i.apply(e));
3108
- let a = i.snapshot(), o = me(a, { profile: r }), s = Qt(t[0].timestamp);
3109
- _.set(e, z({
2168
+ if (!(!r || !o)) try {
2169
+ let r = new C(n, void 0, i);
2170
+ t.forEach((e) => r.apply(e));
2171
+ let a = r.snapshot(), o = de(a, { profile: i }), s = st(t[0].timestamp);
2172
+ y.set(e, W({
3110
2173
  state: a,
3111
2174
  presentation: o,
3112
2175
  runId: e,
@@ -3124,36 +2187,36 @@ function cn(e, t, n, r = "flat-v1") {
3124
2187
  };
3125
2188
  }));
3126
2189
  } catch (t) {
3127
- v.add(e), console.warn(`[SessionHistory] strict replay skipped for run ${e}:`, t instanceof Error ? t.message : "invalid runtime history");
2190
+ b.add(e), console.warn(`[SessionHistory] strict replay skipped for run ${e}:`, t instanceof Error ? t.message : "invalid runtime history");
3128
2191
  }
3129
2192
  }
3130
- for (let e of new Set([...g, ...v])) _.has(e) || p.delete(e);
3131
- let y = sn(l), b = [...p].flatMap((e) => nn(d.filter((t) => t.invocationId === e), f.get(e) || [])), x = /* @__PURE__ */ new Map(), C = [];
3132
- for (let [e, t] of f) {
3133
- if (p.has(e) || !o.has(e)) continue;
3134
- let n = d.filter((t) => t.invocationId === e), r = t.some((e) => e.role === "model" && String(e.content || "").trim());
3135
- x.set(e, r ? rn(t, n) : t), r || C.push(...n.map(tn));
3136
- }
3137
- for (let e of o) p.has(e) || f.has(e) || C.push(...d.filter((t) => t.invocationId === e).map(tn));
3138
- let w = new Map([...x.values()].flat().map((e) => [e.id, e])), T = P([
3139
- ...e.filter((e) => !(e.role === "model" && e.invocationId && y.has(e.invocationId)) && (e.role === "a2ui" || !e.invocationId || !p.has(e.invocationId))).map((e) => w.get(e.id) || e),
3140
- ...b,
3141
- ...C
2193
+ for (let e of new Set([...v, ...b])) y.has(e) || h.delete(e);
2194
+ let x = mt(u), S = [...h].flatMap((e) => ut(p.filter((t) => t.invocationId === e), m.get(e) || [])), w = /* @__PURE__ */ new Map(), T = [];
2195
+ for (let [e, t] of m) {
2196
+ if (h.has(e) || !s.has(e)) continue;
2197
+ let n = p.filter((t) => t.invocationId === e), r = t.some((e) => e.role === "model" && String(e.content || "").trim());
2198
+ w.set(e, r ? dt(t, n) : t), r || T.push(...n.map($));
2199
+ }
2200
+ for (let e of s) h.has(e) || m.has(e) || T.push(...p.filter((t) => t.invocationId === e).map($));
2201
+ let ee = new Map([...w.values()].flat().map((e) => [e.id, e])), E = R([
2202
+ ...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),
2203
+ ...S,
2204
+ ...T
3142
2205
  ]);
3143
- for (let [e, t] of _) {
2206
+ for (let [e, t] of y) {
3144
2207
  if (!t.length) continue;
3145
- let n = (t) => t.invocationId === e || t.runId === e, r = T.findIndex(n), i = T.filter(n), a = i.find((e) => e.role === "user"), o = g.has(e) ? a && !t.some((e) => e.role === "user") ? [a, ...t] : t : nn(t, i), s = T.filter((e) => !n(e)), c = r < 0 ? s.length : r;
3146
- T = [
2208
+ 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 : ut(t, i), s = E.filter((e) => !n(e)), c = r < 0 ? s.length : r;
2209
+ E = [
3147
2210
  ...s.slice(0, c),
3148
2211
  ...o,
3149
2212
  ...s.slice(c)
3150
- ], p.add(e);
2213
+ ], h.add(e);
3151
2214
  }
3152
2215
  return {
3153
- messages: M(P(en(T, l, s))),
3154
- canonicalRunIds: [...p],
3155
- translatedEvents: a
2216
+ messages: I(R(lt(E, u, c))),
2217
+ canonicalRunIds: [...h],
2218
+ translatedEvents: o
3156
2219
  };
3157
2220
  }
3158
2221
  //#endregion
3159
- export { ee as A, ke as C, we as D, Ee as E, S as M, x as N, me as O, z as S, De as T, Ye as _, Zt as a, Je as b, Et as c, ot as d, st as f, Ke as g, Xe as h, Jt as i, w as j, te as k, ut as l, Ue as m, cn as n, Xt as o, We as p, Gt as r, Yt as s, $t as t, yt as u, Ge as v, M as w, Ve as x, qe as y };
2222
+ export { T as C, E as S, S as T, we as _, Be as a, de as b, He as c, Ue as d, We as f, I as g, Ee as h, rt as i, Ge as l, W as m, ht as n, ze as o, Le as p, nt as r, Ke as s, ct as t, Ve as u, Ce as v, C as w, D as x, xe as y };