@kingsoftcloud/ksadk-web 0.3.16 → 0.3.18

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 (230) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -2
  3. package/RELEASE_PROVENANCE.json +2 -2
  4. package/dist-ksadk/assets/{ArtifactsPanel-BuQ9Y_JK.js → ArtifactsPanel-Cdr5C_vM.js} +1 -1
  5. package/dist-ksadk/assets/{CodeBlock-ClmrpVUK.js → CodeBlock-BWRafud9.js} +1 -1
  6. package/dist-ksadk/assets/{MathMessageMarkdown-DYg6qEqQ.js → MathMessageMarkdown-CFKeJIvy.js} +1 -1
  7. package/dist-ksadk/assets/{MermaidBlock-B8QsBFET.js → MermaidBlock-BneAGUOd.js} +6 -6
  8. package/dist-ksadk/assets/{NativeTerminalPanel-Dkm61i5S.js → NativeTerminalPanel-BHI85zDO.js} +1 -1
  9. package/dist-ksadk/assets/{OfficialA2uiRenderer-SMVbkx2W.js → OfficialA2uiRenderer-BOmT36lJ.js} +1 -1
  10. package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-CQ5-2gHs.js → abnfDiagram-VCTEODGH-DQvlOsBI.js} +1 -1
  11. package/dist-ksadk/assets/{arc-CHdgzwmb.js → arc-CGx0e4pN.js} +1 -1
  12. package/dist-ksadk/assets/architecture-7GRP2DOG-CFWjFkDL.js +1 -0
  13. package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-MnCOPhnl.js → architectureDiagram-5GKGNRK7-WyybcNKX.js} +1 -1
  14. package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-DZ61ECd8.js → blockDiagram-NRAW4CY4-C9Cx_GVs.js} +1 -1
  15. package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-D9FYHHhU.js → c4Diagram-UCG6FXSJ-Bh7X3bGr.js} +1 -1
  16. package/dist-ksadk/assets/channel-D6Dp_l74.js +1 -0
  17. package/dist-ksadk/assets/chunk-2Q5K7J3B-CwmjhFYK.js +1 -0
  18. package/dist-ksadk/assets/{chunk-5VM5RSS4-AIv2klim.js → chunk-5VM5RSS4-cP9XupZj.js} +1 -1
  19. package/dist-ksadk/assets/{chunk-F27PBJKO-D_sWJ7f-.js → chunk-F27PBJKO-Bm77fvR9.js} +1 -1
  20. package/dist-ksadk/assets/{chunk-G27WJ6UU-DQzToglM.js → chunk-G27WJ6UU-DDKNPesQ.js} +1 -1
  21. package/dist-ksadk/assets/{chunk-JWPE2WC7-lOgv6BXZ.js → chunk-JWPE2WC7-BqiUDB7s.js} +1 -1
  22. package/dist-ksadk/assets/{chunk-LCL6LL3I-Cbx6jBtE.js → chunk-LCL6LL3I-C528mMZy.js} +1 -1
  23. package/dist-ksadk/assets/{chunk-POPQ4Y6H-DNJ22Jtx.js → chunk-POPQ4Y6H-CzZ9g_Uf.js} +1 -1
  24. package/dist-ksadk/assets/{chunk-RHFEMEQ7-BhICgqzs.js → chunk-RHFEMEQ7-CXj4tUZ-.js} +1 -1
  25. package/dist-ksadk/assets/{chunk-SVP7TREG-r-bF-HGi.js → chunk-SVP7TREG-BHyd85pS.js} +1 -1
  26. package/dist-ksadk/assets/{chunk-XXDRQBXY-OjeFK9EX.js → chunk-XXDRQBXY-Qe29PHGe.js} +1 -1
  27. package/dist-ksadk/assets/classDiagram-DTDB5LWJ-DsbvkCAV.js +1 -0
  28. package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-DsbvkCAV.js +1 -0
  29. package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-LkMJR5TN.js → cose-bilkent-JH36ORCC-maRKgeec.js} +1 -1
  30. package/dist-ksadk/assets/cynefin-OW5HDTMX-CBZRVuc4.js +1 -0
  31. package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-B6wd-M91.js → cynefinDiagram-5FMLGOSQ-CoD0bEvn.js} +1 -1
  32. package/dist-ksadk/assets/{dagre-3AP2YEHR-Yo8czwSH.js → dagre-3AP2YEHR-BkpgQqyW.js} +1 -1
  33. package/dist-ksadk/assets/{dagre-IpjZOTvn.js → dagre-BUaTFrYa.js} +1 -1
  34. package/dist-ksadk/assets/{diagram-S7CK7UJ4-CAkqzyfj.js → diagram-S7CK7UJ4-25HdTbjE.js} +1 -1
  35. package/dist-ksadk/assets/{diagram-UQ7AKVKN-JyEZmDlh.js → diagram-UQ7AKVKN-KO-WqOIg.js} +1 -1
  36. package/dist-ksadk/assets/{diagram-VSXAHHWV-DGBXNEif.js → diagram-VSXAHHWV-B360BkDQ.js} +1 -1
  37. package/dist-ksadk/assets/{diagram-VX7I27RA-KljR5Glh.js → diagram-VX7I27RA-COr1Oqsg.js} +1 -1
  38. package/dist-ksadk/assets/{diagram-Z3DM3KII-8FQ2FrUP.js → diagram-Z3DM3KII-CgaKrIwB.js} +1 -1
  39. package/dist-ksadk/assets/{dist-AnEuKlWI.js → dist--HftQyp9.js} +1 -1
  40. package/dist-ksadk/assets/{dist-BmrsRv90.js → dist-B3Jp5r1e.js} +1 -1
  41. package/dist-ksadk/assets/{dist-Bls_5FN6.js → dist-BEbS8Bag.js} +1 -1
  42. package/dist-ksadk/assets/{dist-DRAbZJl6.js → dist-BQ116UdZ.js} +1 -1
  43. package/dist-ksadk/assets/{dist-BRaujO8W.js → dist-BoRn8a_t.js} +1 -1
  44. package/dist-ksadk/assets/{dist-CAnMW8ay.js → dist-Brbrdmff.js} +1 -1
  45. package/dist-ksadk/assets/{dist-Cs1lGsiM.js → dist-Bsuusoi0.js} +1 -1
  46. package/dist-ksadk/assets/{dist-BUvPmCJJ.js → dist-Bxcu8Ca0.js} +1 -1
  47. package/dist-ksadk/assets/{dist-CSguAs4w.js → dist-By-MVndb.js} +1 -1
  48. package/dist-ksadk/assets/{dist-Bo4bAcyo.js → dist-C9BTMVwS.js} +1 -1
  49. package/dist-ksadk/assets/{dist-dxCMjEJX.js → dist-CBo9AHUv.js} +1 -1
  50. package/dist-ksadk/assets/{dist-CTkYhw0e.js → dist-CR61WJFC.js} +1 -1
  51. package/dist-ksadk/assets/{dist-Bnqrfpu2.js → dist-CwnkOyDn.js} +1 -1
  52. package/dist-ksadk/assets/{dist-BblTQEdU.js → dist-CxIl4t92.js} +1 -1
  53. package/dist-ksadk/assets/{dist-87AsLuzD.js → dist-DKG0OYnk.js} +1 -1
  54. package/dist-ksadk/assets/{dist-Cj5PFf9x.js → dist-DSw5Ju6-.js} +1 -1
  55. package/dist-ksadk/assets/{dist-Ps_8XMpQ.js → dist-DXOlCAay.js} +1 -1
  56. package/dist-ksadk/assets/{dist-C-4NaB6S.js → dist-DgJ57sRe.js} +1 -1
  57. package/dist-ksadk/assets/{dist-DWRPGuTp.js → dist-DmWw0IXB.js} +1 -1
  58. package/dist-ksadk/assets/{dist-DrFtl2Jz.js → dist-DzdXSBJb.js} +1 -1
  59. package/dist-ksadk/assets/{dist-DQSR5gJm.js → dist-HHvdjADB.js} +1 -1
  60. package/dist-ksadk/assets/{dist-DW_Mhac3.js → dist-_0Xgu_07.js} +1 -1
  61. package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-BDy_T6BJ.js → ebnfDiagram-PWID7BFC-DogDP2db.js} +1 -1
  62. package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-Cb9mxU2v.js → erDiagram-SSCWMZ5O-CeBDnUjR.js} +1 -1
  63. package/dist-ksadk/assets/eventmodeling-NTZA5JFV-vXZWMkpn.js +1 -0
  64. package/dist-ksadk/assets/flowDiagram-A5DVABFB-5LRgzKLv.js +1 -0
  65. package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-CI-NY47s.js → ganttDiagram-EL5Y4UJY-oIQL3MCp.js} +1 -1
  66. package/dist-ksadk/assets/gitGraph-4MIJSDKK-BUWSkncI.js +1 -0
  67. package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-DZBPuEz2.js → gitGraphDiagram-WWUBYQGX-B7qz0cmZ.js} +1 -1
  68. package/dist-ksadk/assets/index-4g1ndaxW.js +1132 -0
  69. package/dist-ksadk/assets/index-DEVfafsU.css +2 -0
  70. package/dist-ksadk/assets/info-A6RAGUB7-CzJ_YrOs.js +1 -0
  71. package/dist-ksadk/assets/{infoDiagram-RXCK75RN-BGVB1ufk.js → infoDiagram-RXCK75RN-yQRC41Ya.js} +1 -1
  72. package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-C-pPrser.js → ishikawaDiagram-5VMMS53U-BCu4HiwL.js} +1 -1
  73. package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-mqH7Ax1g.js → journeyDiagram-EYS64GPL-JaqmO73K.js} +1 -1
  74. package/dist-ksadk/assets/{kanban-definition-3QL26DDD-D1g0NfmY.js → kanban-definition-3QL26DDD-DQo4X8NO.js} +1 -1
  75. package/dist-ksadk/assets/{katex-DBFpex0b.js → katex-t_DWylQw.js} +1 -1
  76. package/dist-ksadk/assets/{linear-H9vrIL3e.js → linear-DWdnI35B.js} +1 -1
  77. package/dist-ksadk/assets/{mermaid-parser.core-CTwOsmSy.js → mermaid-parser.core-BHrT2Pfe.js} +2 -2
  78. package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-P24ajxwA.js → mindmap-definition-FBJOCRG2-PBVAhZYV.js} +1 -1
  79. package/dist-ksadk/assets/packet-AYTQ26CC-CXoos6fx.js +1 -0
  80. package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-CIAjyVaA.js → pegDiagram-XKGWAZYB-CU_cLfow.js} +1 -1
  81. package/dist-ksadk/assets/pie-WAS4IAKB-CjF9NoIt.js +1 -0
  82. package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-Cpg76g41.js → pieDiagram-E7YTZNPT-B1h0-_pW.js} +1 -1
  83. package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-COa_uah3.js → quadrantDiagram-AXDQQJYC-DEMoGo5a.js} +1 -1
  84. package/dist-ksadk/assets/radar-RG4KPBEZ-BQGWs9nw.js +1 -0
  85. package/dist-ksadk/assets/railroad-74A4TZTK-B6znvLUK.js +1 -0
  86. package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-Bzquz0As.js +1 -0
  87. package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-1IikGkb5.js +1 -0
  88. package/dist-ksadk/assets/railroad-peg-WCYAUIDC-BKKgHzdc.js +1 -0
  89. package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-CDiUen7V.js → railroadDiagram-O6MQD6OU-BTAob2wg.js} +1 -1
  90. package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-4tmvHR-z.js → requirementDiagram-EFPCY7ZU-Dl0Q2SuO.js} +1 -1
  91. package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-cmOQFKfb.js → sankeyDiagram-P5KCCOFB-DeaTWkur.js} +1 -1
  92. package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-C87BVo37.js → sequenceDiagram-WJ2MYXX4-gFQYrsOd.js} +1 -1
  93. package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-BD2400H2.js → sizeCapture-X5ZJPWSS-pGQzddMB.js} +1 -1
  94. package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-DaxlblQk.js → stateDiagram-HBIQ2CUA-DmpYOZt1.js} +1 -1
  95. package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-Dolxgkw3.js +1 -0
  96. package/dist-ksadk/assets/{swimlanes-XN3QIQJK-M7GAwJZ9.js → swimlanes-XN3QIQJK-BfuSAsrr.js} +1 -1
  97. package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-BuI1erYj.js +8 -0
  98. package/dist-ksadk/assets/{timeline-definition-24CTP7MA-Cq_BUN6-.js → timeline-definition-24CTP7MA-CgJwrrxf.js} +1 -1
  99. package/dist-ksadk/assets/treeView-Q6P3EWNA-DtMdDH8N.js +1 -0
  100. package/dist-ksadk/assets/treemap-WGGIJYW6-VoU8QtLZ.js +1 -0
  101. package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-BTAMWn-b.js → vennDiagram-4TSXK5OY-CBSAgXDd.js} +1 -1
  102. package/dist-ksadk/assets/wardley-WFR3VGLG-YWSRB0Zm.js +1 -0
  103. package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-Dnvpr9wl.js → wardleyDiagram-VM6X3IG4-013TZ2JZ.js} +1 -1
  104. package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-D838CKvY.js → xychartDiagram-S5SC5T6Z-u6Frp8xp.js} +1 -1
  105. package/dist-ksadk/index.html +2 -2
  106. package/dist-lib/App.d.ts.map +1 -1
  107. package/dist-lib/AttachmentPreview-Dhc6ulFv.js +1956 -0
  108. package/dist-lib/{ConnectedComposer-B2lm1bBF.js → ConnectedComposer-Cc6bqJmu.js} +354 -351
  109. package/dist-lib/{ConnectedMessageList-BumlD3Zk.js → ConnectedMessageList-Bdd-qjs-.js} +427 -422
  110. package/dist-lib/{WorkspacePanelContainer-CcI-iqlE.js → WorkspacePanelContainer-_PuvSz_J.js} +319 -319
  111. package/dist-lib/{a2ui-CWVTKJ6O.js → a2ui-DihCxdtQ.js} +1467 -410
  112. package/dist-lib/{capabilities-lJRDfRg9.js → capabilities-CHy70QGW.js} +5 -2
  113. package/dist-lib/capabilities.js +1 -1
  114. package/dist-lib/chat-composer.js +2 -2
  115. package/dist-lib/chat-timeline.js +3 -3
  116. package/dist-lib/components/chat/A2UIActivityMessage.d.ts +1 -0
  117. package/dist-lib/components/chat/A2UIActivityMessage.d.ts.map +1 -1
  118. package/dist-lib/components/chat/ChatComposer.d.ts +2 -1
  119. package/dist-lib/components/chat/ChatComposer.d.ts.map +1 -1
  120. package/dist-lib/components/chat/ChatMessageList.d.ts.map +1 -1
  121. package/dist-lib/components/chat/ConnectedComposer.d.ts +2 -1
  122. package/dist-lib/components/chat/ConnectedComposer.d.ts.map +1 -1
  123. package/dist-lib/components/chat/ExecutionPermissionMenu.d.ts.map +1 -1
  124. package/dist-lib/components/chat/InteractionA2uiSurface.d.ts +6 -1
  125. package/dist-lib/components/chat/InteractionA2uiSurface.d.ts.map +1 -1
  126. package/dist-lib/components/chat/InteractionTray.d.ts +3 -1
  127. package/dist-lib/components/chat/InteractionTray.d.ts.map +1 -1
  128. package/dist-lib/components/chat/JsonSchemaInputForm.d.ts.map +1 -1
  129. package/dist-lib/components/chat/McpAuthorizationCard.d.ts +8 -0
  130. package/dist-lib/components/chat/McpAuthorizationCard.d.ts.map +1 -0
  131. package/dist-lib/components/chat/ProcessingBlocksView.d.ts +1 -1
  132. package/dist-lib/components/chat/ProcessingBlocksView.d.ts.map +1 -1
  133. package/dist-lib/components/chat/submitted-interaction-history.d.ts.map +1 -1
  134. package/dist-lib/components/ui/button.d.ts +12 -0
  135. package/dist-lib/components/ui/button.d.ts.map +1 -0
  136. package/dist-lib/components.js +5 -5
  137. package/dist-lib/conversation.js +2 -2
  138. package/dist-lib/core/api/facade.d.ts +1 -0
  139. package/dist-lib/core/api/facade.d.ts.map +1 -1
  140. package/dist-lib/core/api/types.d.ts +1 -0
  141. package/dist-lib/core/api/types.d.ts.map +1 -1
  142. package/dist-lib/core/conversation/presentation.d.ts.map +1 -1
  143. package/dist-lib/core/conversation/runtime-ingress.d.ts.map +1 -1
  144. package/dist-lib/core/interaction/a2ui-approval.d.ts +20 -0
  145. package/dist-lib/core/interaction/a2ui-approval.d.ts.map +1 -0
  146. package/dist-lib/core/interaction/adapters/agui.d.ts.map +1 -1
  147. package/dist-lib/core/interaction/adapters/normalize.d.ts +2 -0
  148. package/dist-lib/core/interaction/adapters/normalize.d.ts.map +1 -1
  149. package/dist-lib/core/interaction/adapters/session-events.d.ts.map +1 -1
  150. package/dist-lib/core/interaction/client.d.ts.map +1 -1
  151. package/dist-lib/core/interaction/legacy-a2ui.d.ts +5 -0
  152. package/dist-lib/core/interaction/legacy-a2ui.d.ts.map +1 -0
  153. package/dist-lib/core/interaction/pending.d.ts +4 -0
  154. package/dist-lib/core/interaction/pending.d.ts.map +1 -0
  155. package/dist-lib/core/mcp-authorization/contract.d.ts +5 -0
  156. package/dist-lib/core/mcp-authorization/contract.d.ts.map +1 -0
  157. package/dist-lib/core/mcp-authorization/normalize.d.ts +4 -0
  158. package/dist-lib/core/mcp-authorization/normalize.d.ts.map +1 -0
  159. package/dist-lib/core/mcp-authorization/recovery.d.ts +5 -0
  160. package/dist-lib/core/mcp-authorization/recovery.d.ts.map +1 -0
  161. package/dist-lib/core/mcp-authorization/types.d.ts +20 -0
  162. package/dist-lib/core/mcp-authorization/types.d.ts.map +1 -0
  163. package/dist-lib/core/run/agui.d.ts.map +1 -1
  164. package/dist-lib/core/run/blocks.d.ts +4 -2
  165. package/dist-lib/core/run/blocks.d.ts.map +1 -1
  166. package/dist-lib/core/run/dispatcher.d.ts.map +1 -1
  167. package/dist-lib/core/run/engine.d.ts.map +1 -1
  168. package/dist-lib/core/run/types.d.ts +12 -0
  169. package/dist-lib/core/run/types.d.ts.map +1 -1
  170. package/dist-lib/core/stream/types.d.ts +7 -0
  171. package/dist-lib/core/stream/types.d.ts.map +1 -1
  172. package/dist-lib/core/teams/cloudContracts.d.ts +15 -15
  173. package/dist-lib/{feedback-CuC5jRi_.js → feedback-BBJKMdF2.js} +98 -86
  174. package/dist-lib/hooks/useAgentChat.d.ts +1 -1
  175. package/dist-lib/hooks/useAgentChat.d.ts.map +1 -1
  176. package/dist-lib/hooks/useInteractions.d.ts +2 -1
  177. package/dist-lib/hooks/useInteractions.d.ts.map +1 -1
  178. package/dist-lib/hooks/useRunAgent.d.ts.map +1 -1
  179. package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
  180. package/dist-lib/hooks.js +19 -18
  181. package/dist-lib/permission-DGyt7wBj.js +25 -0
  182. package/dist-lib/{persisted-session-history-Mg7yqvHj.js → persisted-session-history-Bh_6zSKC.js} +626 -1479
  183. package/dist-lib/runtime.js +258 -255
  184. package/dist-lib/session-events-DvFsVXpD.js +1463 -0
  185. package/dist-lib/stores/bootstrap.d.ts.map +1 -1
  186. package/dist-lib/stores/execution-permission.d.ts +2 -0
  187. package/dist-lib/stores/execution-permission.d.ts.map +1 -1
  188. package/dist-lib/styles.css +1 -1
  189. package/dist-lib/types/capabilities.d.ts +4 -0
  190. package/dist-lib/types/capabilities.d.ts.map +1 -1
  191. package/dist-lib/{useSessionLifecycle-BsS84-O4.js → useSessionLifecycle-u7i_h_io.js} +1018 -1987
  192. package/dist-lib/utils/capabilities.d.ts +1 -0
  193. package/dist-lib/utils/capabilities.d.ts.map +1 -1
  194. package/dist-lib/utils/persisted-session-history.d.ts.map +1 -1
  195. package/dist-lib/utils/responses-stream.d.ts +3 -1
  196. package/dist-lib/utils/responses-stream.d.ts.map +1 -1
  197. package/dist-lib/utils/run-progress.d.ts.map +1 -1
  198. package/dist-lib/utils/session-event-history.d.ts +11 -0
  199. package/dist-lib/utils/session-event-history.d.ts.map +1 -1
  200. package/dist-lib/utils/session-events.d.ts.map +1 -1
  201. package/dist-lib/utils/workspace.d.ts +1 -1
  202. package/package.json +1 -1
  203. package/dist-ksadk/assets/architecture-7GRP2DOG-B_LhRes-.js +0 -1
  204. package/dist-ksadk/assets/channel-Bq55bwo_.js +0 -1
  205. package/dist-ksadk/assets/chunk-2Q5K7J3B-Dace2ujW.js +0 -1
  206. package/dist-ksadk/assets/classDiagram-DTDB5LWJ-l9qDDu33.js +0 -1
  207. package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-l9qDDu33.js +0 -1
  208. package/dist-ksadk/assets/cynefin-OW5HDTMX-jtPBpAp-.js +0 -1
  209. package/dist-ksadk/assets/eventmodeling-NTZA5JFV-DMz2Fvu-.js +0 -1
  210. package/dist-ksadk/assets/flowDiagram-A5DVABFB-clcQL_nf.js +0 -1
  211. package/dist-ksadk/assets/gitGraph-4MIJSDKK-DDQIXIFD.js +0 -1
  212. package/dist-ksadk/assets/index-4lKAP0g-.js +0 -1132
  213. package/dist-ksadk/assets/index-DMqhW2cV.css +0 -2
  214. package/dist-ksadk/assets/info-A6RAGUB7-CnWfuiwa.js +0 -1
  215. package/dist-ksadk/assets/packet-AYTQ26CC-C1REqCW5.js +0 -1
  216. package/dist-ksadk/assets/pie-WAS4IAKB-CzQ5iT3d.js +0 -1
  217. package/dist-ksadk/assets/radar-RG4KPBEZ-d5WzegFP.js +0 -1
  218. package/dist-ksadk/assets/railroad-74A4TZTK-fRIdWxzy.js +0 -1
  219. package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-7joOoyeT.js +0 -1
  220. package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-BAgBPuog.js +0 -1
  221. package/dist-ksadk/assets/railroad-peg-WCYAUIDC-Bq9jPeDZ.js +0 -1
  222. package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-BAnVAqLb.js +0 -1
  223. package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-DzYhp6ae.js +0 -8
  224. package/dist-ksadk/assets/treeView-Q6P3EWNA-Kl6y61te.js +0 -1
  225. package/dist-ksadk/assets/treemap-WGGIJYW6-Bt1G2wC0.js +0 -1
  226. package/dist-ksadk/assets/wardley-WFR3VGLG-CNYQTyja.js +0 -1
  227. package/dist-lib/AttachmentPreview-DkgZ9Upi.js +0 -1545
  228. package/dist-lib/execution-permission-UqLwHTJS.js +0 -89
  229. package/dist-lib/json-value-DnHp0582.js +0 -186
  230. 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 { S as e, b as t, f as n, n as r, r as i } from "./session-events-DvFsVXpD.js";
2
+ import { d as a, i as o, l as s, o as c, p as l, t as u, u as d } from "./reducer-mbYiX0wz.js";
4
3
  //#region src/core/conversation/safe-tool-value.ts
5
- var u = [
4
+ var f = [
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) {
22
+ function p(e) {
24
23
  return e.normalize("NFKC").toLowerCase().replace(/[^a-z0-9]/g, "");
25
24
  }
26
- function f(e) {
27
- let t = d(e);
28
- return u.some((e) => t.includes(e));
25
+ function m(e) {
26
+ let t = p(e);
27
+ return f.some((e) => t.includes(e));
29
28
  }
30
- function p(e) {
29
+ function h(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 g(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 _(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) : h(n || t);
54
+ if (i !== null) return g(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 v(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) || _(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 y(e, t = 0) {
70
+ return x(e, t, 8192);
72
71
  }
73
- function v(e, t, n) {
74
- return y(e, 0, [
72
+ function b(e, t, n) {
73
+ return x(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 x(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) || v(e) ? "[redacted]" : e.length > n ? `${e.slice(0, n)}[truncated]` : e : Array.isArray(e) ? e.slice(0, 128).map((e) => x(e, t + 1, n)) : e && typeof e == "object" ? Object.fromEntries(Object.entries(e).slice(0, 128).filter(([e]) => !m(e)).map(([e, r]) => [e, x(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 S = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, C = (e, t, n) => JSON.stringify([
86
85
  e,
87
86
  t,
88
87
  n
89
- ]), S = class {
88
+ ]), w = class {
90
89
  runtime = new e();
91
- flatChildren = new c();
90
+ flatChildren = new u();
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 u(), 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 ? C(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 = S(e.source), s = [
124
123
  "adk",
125
124
  "langgraph",
126
125
  "codex"
127
- ].includes(String(s.framework)) && !this.descriptors.has(n);
128
- if (c && a && i === "run.progress") return null;
129
- if (i.startsWith("run.") && (a || !c && this.rootScope && n !== this.rootScope)) throw Error("Child scope cannot transition root run");
126
+ ].includes(String(o.framework)) && !this.descriptors.has(n);
127
+ if (s && a && i === "run.progress") return null;
128
+ if (i.startsWith("run.") && (a || !s && 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 = S(S(e.source).metadata), m = p.conversation_visibility ?? p.visibility;
157
156
  if ([
158
157
  "public",
159
158
  "internal",
@@ -168,35 +167,35 @@ 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 = S(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 = S(e.snapshot || e.initial), p = i === "item.updated" ? [S(e.update)] : Array.isArray(d.parts) ? d.parts : [], h = p.map((e) => {
178
+ let t = S(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");
187
- if (a && !g && !c) {
185
+ }), g = p.map((e) => S(S(e).data)).find((e) => e.schema === "execution.scope/v1");
186
+ if (a && !g && !s) {
188
187
  let e = this.descriptorItemIds.get(n);
189
188
  if (!e) throw Error("Child content requires its scope descriptor first");
190
189
  f.parentItemId = 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 = S(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) => S(t.value).call_id === e.call_id)) throw Error("Scope trigger call mismatch");
198
197
  let r = this.descriptors.get(n);
199
- o({
198
+ c({
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 = S(e.trigger_ref);
211
+ if (t.scope_id === n && t.item_id === l && h.length && !h.some((e) => S(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 && !s && _ && _.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 v = {
220
219
  type: i.replaceAll(".", "_"),
221
220
  runId: t,
222
221
  scopeId: n,
@@ -232,52 +231,52 @@ 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);
236
- let S = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
237
- if (!S || a && S.itemKind === "status" && S.status === "open" && !S.parts.length) return null;
234
+ this.runtime.apply(v);
235
+ let x = this.runtime.snapshot().items.find((e) => e.scopeId === n && e.itemId === l);
236
+ if (!x || a && x.itemKind === "status" && x.status === "open" && !x.parts.length) return null;
238
237
  if (a && [
239
238
  "artifact",
240
239
  "tool_call",
241
240
  "tool_result"
242
- ].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";
245
- else if (S.itemKind === "tool_call" || S.itemKind === "tool_result") {
241
+ ].includes(x.itemKind) && !x.parts.length) return this.runId = t, this.parents.set(n, a), this.seen.add(r), null;
242
+ let C = x.parts.map((e) => S(e.value)), w = C.map((e) => S(e.data)).find((e) => e.schema === "execution.scope/v1");
243
+ if (f.lifecycle = x.status === "open" ? i === "item.started" ? "pending" : "streaming" : x.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(S(w.trigger_ref).scope_id), String(S(w.trigger_ref).item_id), !!this.parents.get(String(S(w.trigger_ref).scope_id))), f.capabilityRef = "agent.block";
244
+ else if (x.itemKind === "tool_call" || x.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: y(e.arguments)
252
251
  } : {},
253
252
  ...t ? {
254
253
  callId: t.call_id,
255
- output: v(t.result, s.framework, s.protocol),
254
+ output: b(t.result, o.framework, o.protocol),
256
255
  isError: t.is_error
257
256
  } : {},
258
- executionStatus: S.status === "failed" ? "failed" : t && S.status !== "open" ? t.is_error ? "failed" : "completed" : S.itemKind === "tool_result" ? "unknown" : "running",
259
- sourceKind: S.itemKind
257
+ executionStatus: x.status === "failed" ? "failed" : t && x.status !== "open" ? t.is_error ? "failed" : "completed" : x.itemKind === "tool_result" ? "unknown" : "running",
258
+ sourceKind: x.itemKind
260
259
  };
261
- } else if (S.itemKind === "data" && s.protocol === "a2ui") {
260
+ } else if (x.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(S(o.metadata).surface_id || ""),
264
+ ...typeof S(o.metadata).interaction_id == "string" ? { interactionId: S(o.metadata).interaction_id } : {},
266
265
  data: Array.isArray(e) ? e : []
267
266
  };
268
- } 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 || "");
272
- } else if (S.itemKind === "artifact") {
267
+ } else if (x.itemKind === "message" || x.itemKind === "reasoning" || x.itemKind === "artifact" && x.parts.length > 0 && x.parts.every((e) => e.contentType === "text")) {
268
+ f.kind = x.itemKind === "reasoning" ? "reasoning" : S(S(e.source).metadata).native_item_kind === "userMessage" ? "user_message" : "assistant_text", f.payloadSchemaRef = `conversation.item.${f.kind}/v1`, f.payload = { text: x.parts.map((e) => e.text || "").join("") };
269
+ let t = S(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 = S(e.update).text || "");
271
+ } else if (x.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 = {
275
274
  name: e.name,
276
275
  mimeType: e.mime_type,
277
276
  uri: e.uri
278
277
  };
279
- } else if (S.status === "failed") {
280
- let t = b(e.error);
278
+ } else if (x.status === "failed") {
279
+ let t = S(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 T(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 ee(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 ? T(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 E(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 te(e, t) {
322
+ let n = e.filter((e) => E(e, t));
324
323
  return n.length === 1 ? n[0] : void 0;
325
324
  }
326
- function te(e) {
325
+ function ne(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 = te(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 = T(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 re = {
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 ie(e) {
373
372
  return e.lifecycle === "completed" || e.lifecycle === "failed";
374
373
  }
375
- var ie = new Set([
374
+ var ae = 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 D(e) {
383
+ if (e.parentItemId || e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || e.kind !== "progress" && e.kind !== "error" || !ie(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 (ae.has(t)) return "failed";
388
387
  }
389
- function ae(e) {
390
- let t = ne[e.kind];
388
+ function oe(e) {
389
+ let t = re[e.kind];
391
390
  return t === void 0 || t === e.payloadSchemaRef;
392
391
  }
393
- function oe(e) {
392
+ function se(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 ce(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 le(e) {
412
+ let t = typeof e.payload.artifactId == "string" && e.payload.artifactId ? e.payload.artifactId : e.itemId, n = e.payload.sizeBytes ?? e.payload.size, r = typeof n == "number" && Number.isFinite(n) && n >= 0 ? n : null, i = se(e.payload.uri);
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 O(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 k(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 = O(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 = O(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 = O(e, "surfaceId");
446
445
  if (t) return `a2ui:${JSON.stringify([e.runId, t])}`;
447
446
  }
448
447
  return `item:${e.itemId}`;
449
448
  }
450
449
  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) } : {};
450
+ let n = ie(e) && !ie(t), r = e.kind === "a2ui" && t.kind === "a2ui" && Array.isArray(e.payload.data) && Array.isArray(t.payload.data) ? { data: T(e.payload.data, t.payload.data) } : {};
452
451
  return {
453
452
  ...e,
454
453
  ...t,
@@ -475,36 +474,48 @@ function ue(e, t) {
475
474
  };
476
475
  }
477
476
  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") || "",
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" ? k(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 = k(t);
484
+ i.set(e, (i.get(e) ?? 0) + 1);
485
+ }
486
+ t.kind === "tool_call" && t.payload.sourceKind === "tool_result" && a.add(k(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 = k(c), l = s(c), u = l && !i.has(e) && !a.has(l) && i.get(l) === 1 && o.get(l) === 1 ? l : e, d = c.kind === "a2ui" ? {
492
+ surfaceId: O(c, "surfaceId") || "",
482
493
  messages: [],
483
- ...D(i, "interactionId") ? { interactionId: D(i, "interactionId") } : {}
484
- } : null, o = a ? {
494
+ ...O(c, "interactionId") ? { interactionId: O(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 ? te(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: ue(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" ? {
@@ -540,7 +551,7 @@ function pe(e) {
540
551
  function me(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) => fe(e, n).map((e) => e.itemId))), r = (t) => e.some((e) => e.runId === t.runId && (t.parentItemId === e.itemId || typeof e.payload.scope_id == "string" && e.payload.scope_id.length > 0 && e.payload.scope_id === (t.nativeRef.scopeId || t.nativeRef.scope_id))), i = n.find((e) => D(e)), a = n.filter((e) => e.kind !== "agent" && (e.kind === "error" || !r(e) && !t.has(e.itemId))), o = i?.payload.outputRefs || i?.payload.output_refs;
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,11 +567,11 @@ 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(oe), i = n.filter((e) => !oe(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(ce), s = (e) => e.nativeRef.parentScopeId || e.nativeRef.parent_scope_id || r.some((t) => t.kind === "agent" && (e.parentItemId === t.itemId || t.runId === e.runId && t.payload.scope_id === (e.nativeRef.scopeId || e.nativeRef.scope_id))), c = (e) => r.filter((t) => t.kind === e && !s(t)).map((e) => typeof e.payload.text == "string" ? e.payload.text : "").join(""), l = [...r.filter((e) => e.kind === "unknown"), ...i], u = r.filter((e) => e.kind === "error"), d = [...r].reverse().find((e) => D(e) !== void 0);
564
575
  return {
565
576
  timeline: pe(r.filter((e) => e.kind !== "progress")),
566
577
  output: c("assistant_text"),
@@ -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(le),
574
585
  fallbacks: [...l.map((e) => ({
575
586
  id: e.itemId,
576
587
  title: "Unsupported content",
@@ -583,17 +594,17 @@ 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 ? D(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 A = 8;
603
+ function j(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 M(e) {
607
+ if (e?.aborted) throw new l("conversation_aborted", "Conversation request was aborted.");
597
608
  }
598
609
  function he(e, t) {
599
610
  return t?.aborted === !0 || e instanceof Error && e.name === "AbortError";
@@ -607,7 +618,7 @@ 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 l("conversation_contract_mismatch", "Conversation base URL must be an HTTP(S) URL without embedded credentials.", { cause: e });
611
622
  }
612
623
  }
613
624
  function _e(e) {
@@ -619,18 +630,18 @@ function ve(e) {
619
630
  });
620
631
  }
621
632
  async function ye(e, t, n) {
622
- if (A(n), !n) {
633
+ if (M(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 l("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 N(e, t, n, r, i) {
634
645
  let a = i ? i.snapshot() : e.snapshot();
635
646
  return {
636
647
  cursor: t,
@@ -639,49 +650,49 @@ function be(e, t, n, r, i) {
639
650
  presentation: me(a, { profile: r })
640
651
  };
641
652
  }
642
- function xe(e, t) {
653
+ function be(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 l("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 l("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 o = j(a), c = j(o?.runtimeEvent) || j(o?.runtime_event) || (o?.schema_version === 2 ? o : null);
674
+ if (!o || o.conversationItem === void 0 && !c) {
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 l("conversation_stream_error", "Canonical conversation items require an SSE replay cursor.");
679
+ let u = o.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" ? s(o.conversationItem) : t.runtime.apply(c);
676
687
  } catch (e) {
677
- throw new s("conversation_contract_mismatch", "Runtime conversation identity or lifecycle invariant failed.", { cause: e });
688
+ throw new l("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 l("conversation_contract_mismatch", "Conversation stream item does not match conversation.ksadk.io/v1.");
695
+ if (t.runId && t.runId !== d.runId) throw new l("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 l("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?.(N(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 xe(e, t) {
709
+ if (!e.body) throw new l("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
+ M(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
+ be(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() && be(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 l ? e : (he(e, t.options.signal) && M(t.options.signal), new l("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 Se(e) {
735
+ return e.state.items.some((e) => D(e) !== void 0);
725
736
  }
726
- var we = class {
737
+ var Ce = class {
727
738
  fetcher;
728
739
  ingressLane;
729
740
  rendererCatalog;
@@ -732,64 +743,64 @@ 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 ?? A) || (e.maxReconnects ?? A) < 0 || (e.maxReconnects ?? A) > 32) throw new l("conversation_contract_mismatch", "Conversation reconnect limit must be an integer from 0 to 32.");
747
+ this.fetcher = e.fetch, this.rendererCatalog = e.rendererCatalog, this.ingressLane = e.ingressLane, this.baseUrl = ge(e.baseUrl || ""), this.maxReconnects = e.maxReconnects ?? A, this.sleep = e.sleep || ve, this.retryDelayMs = e.retryDelayMs || _e;
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 l("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
+ M(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 l ? e : (he(e, n) && M(n), new l(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 l("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 l("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 l("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 = j(a), s = d(o?.surface);
779
+ if (!o || typeof o.buildId != "string" || !o.buildId || !s) throw new l("conversation_contract_mismatch", "Conversation surface response does not match conversation.ksadk.io/v1.");
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
+ M(e.signal);
787
+ let t = o(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
+ a(e.bootstrap.surface, n);
795
+ let r = e.bootstrap.surface.outputs.find((e) => e.name === "agent.block"), i = r?.mode === "native" ? "native" : r?.mode === "translated" ? "runtime" : void 0;
796
+ if (i && this.ingressLane && i !== this.ingressLane) throw new l("conversation_contract_mismatch", "Configured ingress lane disagrees with the conversation surface.");
797
+ let s = i || this.ingressLane || "native", c = new u(), d = {
787
798
  profile: t,
788
- lane: l,
789
- runtime: new S(n.sessionId, u, t),
799
+ lane: s,
800
+ runtime: new w(n.sessionId, c, t),
790
801
  cursor: 0,
791
802
  runId: "",
792
- reducer: u,
803
+ reducer: c,
793
804
  options: e
794
805
  }, f = {
795
806
  method: "POST",
@@ -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 xe(p, d);
806
817
  } catch (e) {
807
- if (!(e instanceof s) || e.code !== "conversation_stream_error" || !d.runId) throw e;
818
+ if (!(e instanceof l) || 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 = N(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0);
821
+ if (Se(m)) return m;
822
+ if (!d.runId) throw new l("conversation_run_identity_missing", "The stream ended before a canonical item supplied its run identity.", { cursor: d.cursor });
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 ye(this.sleep, this.retryDelayMs(t), e.signal), M(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 xe(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 l && e.code === "conversation_aborted" || e instanceof l && e.code === "conversation_contract_mismatch" || e instanceof l && e.code === "conversation_http_error" && e.status !== void 0 && e.status < 500) throw e;
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 = N(d.reducer, d.cursor, d.runId, d.profile, d.lane === "runtime" ? d.runtime : void 0), Se(m)) return m;
826
837
  }
827
- throw new s("conversation_reconnect_exhausted", "Conversation replay stopped after the configured reconnect limit.", {
838
+ throw new l("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 we(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 Te(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 (we(n.id, "id"), we(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 Ee = Te([{
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 P(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 F(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
+ ...P(t, r)
900
911
  } : {
901
912
  ...r,
902
913
  ...t,
903
- ...j(r, t)
914
+ ...P(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 I = (e) => e.runId || e.invocationId;
954
+ function L(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 = I(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(I(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 De(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 Oe(e, t, n) {
985
+ let r = new Map(t.map((e) => [e.id, e])), i = n.filter((e) => r.has(e.id) && r.get(e.id)?.feedback !== e.feedback), a = new Map(i.map((e) => [e.id, e.feedback])), o = (e) => JSON.stringify([I(e), e.responseId]), s = new Map(i.filter((e) => e.responseId).map((e) => [o(e), e.feedback])), c = (e) => e.map((e) => {
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) => De(e, r.get(e.id)));
996
+ if (!l.length) return ne(F(c(e)));
997
+ let u = new Set(l.map(I).filter(Boolean)), d = new Set(l.map((e) => e.id)), f = n.filter((e) => u.has(I(e)) || d.has(e.id)), p = e;
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) => I(e) === t), r = e.filter((e) => I(e) === t), i = p.findIndex((e) => I(e) === t), a = n.some((e) => e.role === "user") ? [] : r.filter((e) => e.role === "user");
1000
+ p = p.filter((e) => I(e) !== t);
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) => !I(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 ne(F(c(L(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 ke = "conversation_item_v1";
1026
+ function R(e) {
1016
1027
  return typeof e == "object" && e && !Array.isArray(e) ? e : null;
1017
1028
  }
1018
- function F(e) {
1029
+ function z(e) {
1019
1030
  return typeof e == "string" && e.trim() ? e : null;
1020
1031
  }
1021
- function I(e) {
1032
+ function B(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 V(e) {
1031
1042
  return {
1032
1043
  id: `conversation:${e.runId}:${e.itemId}`,
1033
1044
  timestamp: 0,
1034
- eventType: Ae,
1045
+ eventType: ke,
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 Ae(e) {
1042
1053
  return e.lifecycle === "failed" ? "error" : e.lifecycle === "completed" ? "done" : "streaming";
1043
1054
  }
1044
- function Ne(e) {
1055
+ function je(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
+ ...V(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: Ae(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: Ae(e)
1063
1074
  };
1064
1075
  return {
1065
- ...L(e),
1076
+ ...V(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 Me(e, t = !1) {
1084
+ let n = z(e.payload.tool) || (e.payload.sourceKind === "tool_result" ? "Tool result" : "Tool"), r = z(e.payload.callId), i = B(y(e.payload.args)), a = Object.prototype.hasOwnProperty.call(e.payload, "output") ? B(b(e.payload.output, e.nativeRef.framework, e.nativeRef.protocol)) : void 0, o = {
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
+ ...V(e),
1081
1092
  role: "model",
1082
1093
  content: "",
1083
1094
  blocks: [{
@@ -1098,13 +1109,13 @@ function Pe(e, t = !1) {
1098
1109
  } }
1099
1110
  };
1100
1111
  }
1101
- function Fe(e) {
1112
+ function Ne(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 Pe(e) {
1116
+ let n = z(e.payload.interactionId), r = e.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 = {};
1118
+ let i = B(e.payload.detail), a = z(e.payload.prompt) || i, o = Ne(e.payload.interactionKind), s = e.lifecycle === "completed", c = {};
1108
1119
  if (s && Object.hasOwn(e.payload, "response")) try {
1109
1120
  c = { response: t(e.payload.response) };
1110
1121
  } catch {}
@@ -1113,16 +1124,16 @@ function Ie(e) {
1113
1124
  sessionId: e.sessionId,
1114
1125
  runId: e.runId,
1115
1126
  kind: o,
1116
- title: F(e.payload.title) || (o === "approval" ? `审批:${F(e.payload.kind) || "操作"}` : "需要补充信息"),
1127
+ title: z(e.payload.title) || (o === "approval" ? `审批:${z(e.payload.kind) || "操作"}` : "需要补充信息"),
1117
1128
  message: a || "运行需要人工确认。",
1118
- requestSchema: je(e.payload.inputSchema),
1129
+ requestSchema: R(e.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: z(e.payload.createdAt) || "",
1134
+ expiresAt: z(e.payload.expiresAt),
1135
+ resolvedAt: s ? z(e.payload.resolvedAt) : null,
1136
+ actor: s ? z(e.payload.actor) : null,
1126
1137
  outcome: s && [
1127
1138
  "approved",
1128
1139
  "rejected",
@@ -1130,23 +1141,23 @@ function Ie(e) {
1130
1141
  "cancelled",
1131
1142
  "expired"
1132
1143
  ].includes(String(e.payload.outcome || "")) ? e.payload.outcome : null,
1133
- responseSummary: s ? F(e.payload.responseSummary) : null,
1144
+ responseSummary: s ? z(e.payload.responseSummary) : null,
1134
1145
  ...c,
1135
1146
  source: "interaction_v1",
1136
1147
  extensions: {
1137
1148
  conversation_item_id: e.itemId,
1138
- ...F(e.payload.callId) ? { call_id: F(e.payload.callId) } : {}
1149
+ ...z(e.payload.callId) ? { call_id: z(e.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 Fe(e, t) {
1154
+ let n = z(e.payload.kind) || "approval", r = B(e.payload.detail), i = t.status === "resolved" ? t.outcome === "rejected" ? "rejected" : t.outcome === "cancelled" || t.outcome === "expired" ? "cancelled" : "approved" : "pending", a = t.status === "pending" ? "paused" : "completed", o = {
1144
1155
  approvalRequestId: t.interactionId,
1145
1156
  approvalStatus: i,
1146
1157
  approvalMessage: t.message
1147
1158
  };
1148
1159
  return {
1149
- ...L(e),
1160
+ ...V(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 Ie(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 = z(R(e[t])?.surfaceId);
1178
1189
  if (n) return n;
1179
1190
  }
1180
1191
  return null;
1181
1192
  }
1182
- function ze(e) {
1193
+ function Le(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(R);
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 = z(e.payload.surfaceId) || r.map(Ie).find((e) => e !== null) || null;
1188
1199
  return i ? {
1189
- ...L(e),
1200
+ ...V(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 H(e, t, n, r = !1) {
1200
1211
  return {
1201
- ...L(e),
1212
+ ...V(e),
1202
1213
  role: "system",
1203
1214
  content: n ? `${t}: ${n}` : t,
1204
- status: r ? "failed" : L(e).status
1215
+ status: r ? "failed" : V(e).status
1205
1216
  };
1206
1217
  }
1207
- function Be(e) {
1218
+ function Re(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 = y(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 U(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(H(f, "Remote agent", String(f.payload.status || "submitted")));
1225
1236
  continue;
1226
1237
  }
1227
- let n = z({
1238
+ let n = U({
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
+ ...V(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: Re(d.children || [])
1242
1253
  },
1243
- status: f.payload.status === "cancelled" ? "cancelled" : L(f).status
1254
+ status: f.payload.status === "cancelled" ? "cancelled" : V(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(je(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(Me(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 = Pe(f);
1268
+ e ? (u.push(e), l.push(Fe(f, e))) : l.push(H(f, "Interaction unavailable", "The server did not provide a durable interaction revision; this card is read-only."));
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 = Le(f);
1273
+ l.push(e || H(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
+ ...V(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
+ ...V(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
+ } : H(f, "Artifact unavailable", p.status === "failed" ? "The artifact failed to generate or its URI is not a safe HTTP(S) link." : "The artifact URI is not a safe HTTP(S) link."));
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(H(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 ze(e, t, n) {
1321
+ let r = U(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,51 +1334,57 @@ 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 Be = 0;
1338
+ function W(e) {
1339
+ return Be += 1, `${e}-${Be}`;
1329
1340
  }
1330
- function V(e) {
1341
+ function G(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) {
1337
- let n = [...e ?? []], r = n[n.length - 1];
1338
- return r?.type === "thinking" && r.status === "streaming" ? (n[n.length - 1] = {
1339
- ...r,
1340
- content: r.content + t
1341
- }, n) : [...n, {
1342
- id: B("thinking"),
1347
+ function Ve(e, t, n) {
1348
+ let r = [...e ?? []], i = r[r.length - 1];
1349
+ return i?.type === "thinking" && i.status === "streaming" && i.itemId === n ? (r[r.length - 1] = {
1350
+ ...i,
1351
+ content: i.content + t
1352
+ }, r) : [...G(r), {
1353
+ id: W("thinking"),
1343
1354
  type: "thinking",
1344
1355
  content: t,
1345
- status: "streaming"
1356
+ status: "streaming",
1357
+ ...n && { itemId: n }
1346
1358
  }];
1347
1359
  }
1348
- function We(e, t) {
1349
- let n = [...V(e ?? [])], r = n[n.length - 1];
1360
+ function He(e, t, n) {
1361
+ let r = (e) => e.type === "thinking" && e.itemId === t, i = e.findLastIndex(r), a = 0;
1362
+ return e.flatMap((e, t) => {
1363
+ if (!r(e)) return [e];
1364
+ let o = t === i ? n.length : a + e.content.length, s = n.slice(a, o);
1365
+ return a = o, s ? [{
1366
+ ...e,
1367
+ content: s
1368
+ }] : [];
1369
+ });
1370
+ }
1371
+ function Ue(e, t) {
1372
+ let n = [...G(e ?? [])], r = n[n.length - 1];
1350
1373
  return r?.type === "text" && r.status === "streaming" ? (n[n.length - 1] = {
1351
1374
  ...r,
1352
1375
  content: r.content + t
1353
1376
  }, n) : [...n, {
1354
- id: B("text"),
1377
+ id: W("text"),
1355
1378
  type: "text",
1356
1379
  content: t,
1357
1380
  status: "streaming"
1358
1381
  }];
1359
1382
  }
1360
- function Ge(e, t) {
1383
+ function We(e, t) {
1361
1384
  let n = e ?? [], r = n.filter((e) => e.type === "text").map((e) => e.content).join("");
1362
1385
  if (r === t) return n;
1363
- let i = n.flatMap((e, t) => e.type === "text" ? [t] : []);
1364
- if (!i.length) return [...n, {
1365
- id: B("text"),
1366
- type: "text",
1367
- content: t,
1368
- status: "streaming"
1369
- }];
1370
- let a = 0;
1386
+ if (t.startsWith(r) && n.at(-1)?.type !== "text") return Ue(n, t.slice(r.length));
1387
+ let i = n.flatMap((e, t) => e.type === "text" ? [t] : []), a = 0;
1371
1388
  for (; a < r.length && a < t.length && r[a] === t[a];) a++;
1372
1389
  let o = 0;
1373
1390
  for (; o < r.length - a && o < t.length - a && r[r.length - o - 1] === t[t.length - o - 1];) o++;
@@ -1386,25 +1403,29 @@ function Ge(e, t) {
1386
1403
  };
1387
1404
  });
1388
1405
  }
1389
- function Ke(e, t) {
1390
- let n = V(e ?? []);
1391
- if (n.filter((e) => e.type === "text").map((e) => e.content).join("") === t) return n.map((e) => e.type === "text" && e.status === "streaming" ? {
1406
+ function Ge(e, t) {
1407
+ let n = G(e ?? []), r = n.flatMap((e) => e.type === "text" ? [e.content] : []).join(""), i = n.at(-1), a = n;
1408
+ if (t !== r && i?.type !== "text") {
1409
+ let e = t.startsWith(r) ? t.slice(r.length) : t;
1410
+ e && (a = [...n, {
1411
+ id: W("text"),
1412
+ type: "text",
1413
+ content: e,
1414
+ status: "done"
1415
+ }]);
1416
+ } else if (i?.type === "text" && t !== r && t !== i.content) {
1417
+ let e = r.slice(0, r.length - i.content.length), o = t.startsWith(e) ? t.slice(e.length) : t;
1418
+ a = [...n.slice(0, -1), {
1419
+ ...i,
1420
+ content: o
1421
+ }];
1422
+ }
1423
+ return a.map((e) => e.type === "text" && e.status === "streaming" ? {
1392
1424
  ...e,
1393
1425
  status: "done"
1394
1426
  } : e);
1395
- let r = [...n], i = r.map((e) => e.type).lastIndexOf("text");
1396
- return i >= 0 && r[i].type === "text" ? (r[i] = {
1397
- ...r[i],
1398
- content: t,
1399
- status: "done"
1400
- }, r) : [...r, {
1401
- id: B("text"),
1402
- type: "text",
1403
- content: t,
1404
- status: "done"
1405
- }];
1406
1427
  }
1407
- function qe(e, t) {
1428
+ function Ke(e, t) {
1408
1429
  if (!t) return [...e ?? []];
1409
1430
  let n = [...e ?? []], r = n[n.length - 1];
1410
1431
  if (r?.type !== "thinking" || !r.content.endsWith(t)) return n;
@@ -1414,20 +1435,23 @@ function qe(e, t) {
1414
1435
  content: i
1415
1436
  }, n) : (n.pop(), n);
1416
1437
  }
1417
- function Je(e, t, n) {
1418
- let r = [...V(e ?? [])], i = r.findIndex((e) => e.type === "tool" && e.toolName === t);
1419
- if (i >= 0 && r[i].type === "tool") {
1420
- 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
- if (t && !a && !o) return r;
1422
- let s = n.extra ?? e.extra;
1423
- return r[i] = {
1438
+ function qe(e, t, n) {
1439
+ let r = [...e ?? []], i = n.extra?.callId, a = i ? r.findIndex((e) => e.type === "tool" && e.extra?.callId === i && e.toolName === t) : -1;
1440
+ if (a < 0 && (a = r.findLastIndex((e) => e.type === "tool" && e.toolName === t && (!i || !e.extra?.callId && (e.status === "running" || e.status === "paused")))), a >= 0 && r[a].type === "tool") {
1441
+ let e = r[a], t = e.status === "error" || e.status === "completed", i = n.output !== void 0, o = n.extra && (n.extra.approvalRequestId || n.extra.approvalStatus);
1442
+ if (t && !i && !o) return r;
1443
+ let s = n.extra ? {
1444
+ ...e.extra,
1445
+ ...n.extra
1446
+ } : e.extra;
1447
+ return r[a] = {
1424
1448
  ...e,
1425
1449
  ...n,
1426
1450
  extra: s
1427
1451
  }, r;
1428
1452
  }
1429
- return [...r, {
1430
- id: B("tool"),
1453
+ return [...G(r), {
1454
+ id: W("tool"),
1431
1455
  type: "tool",
1432
1456
  toolName: t,
1433
1457
  args: n.args ?? "",
@@ -1436,19 +1460,19 @@ function Je(e, t, n) {
1436
1460
  extra: n.extra
1437
1461
  }];
1438
1462
  }
1439
- function Ye(e) {
1440
- return V(e ?? []);
1463
+ function Je(e) {
1464
+ return G(e ?? []);
1441
1465
  }
1442
- function Xe(e) {
1466
+ function Ye(e) {
1443
1467
  let t = [];
1444
1468
  if (e.reasoning && e.reasoning.trim() && t.push({
1445
- id: B("thinking"),
1469
+ id: W("thinking"),
1446
1470
  type: "thinking",
1447
1471
  content: e.reasoning,
1448
1472
  status: "done",
1449
1473
  ...e.reasoningSource ? { source: e.reasoningSource } : {}
1450
1474
  }), e.tools) for (let n of Object.values(e.tools)) t.push({
1451
- id: B("tool"),
1475
+ id: W("tool"),
1452
1476
  type: "tool",
1453
1477
  toolName: n.name,
1454
1478
  args: n.args ?? "",
@@ -1460,7 +1484,7 @@ function Xe(e) {
1460
1484
  } } : {}
1461
1485
  });
1462
1486
  return e.content && e.content.trim() && t.push({
1463
- id: B("text"),
1487
+ id: W("text"),
1464
1488
  type: "text",
1465
1489
  content: e.content,
1466
1490
  status: "done"
@@ -1468,40 +1492,40 @@ function Xe(e) {
1468
1492
  }
1469
1493
  //#endregion
1470
1494
  //#region src/core/stream/kernel-events.ts
1471
- var Ze = {
1495
+ var Xe = {
1472
1496
  "run.started": "in_progress",
1473
1497
  "run.progress": "in_progress",
1474
1498
  "run.completed": "completed",
1475
1499
  "run.failed": "failed",
1476
1500
  "run.canceled": "cancelled",
1477
1501
  "run.interrupted": "interrupted"
1478
- }, Qe = new Set([
1502
+ }, Ze = new Set([
1479
1503
  "completed",
1480
1504
  "failed",
1481
1505
  "cancelled",
1482
1506
  "canceled"
1483
1507
  ]);
1484
- function H(e) {
1508
+ function K(e) {
1485
1509
  return typeof e == "object" && e && !Array.isArray(e) ? e : null;
1486
1510
  }
1487
- function $e(e) {
1488
- let t = H(e.source), n = t ? H(t.metadata) : null;
1511
+ function Qe(e) {
1512
+ let t = K(e.source), n = t ? K(t.metadata) : null;
1489
1513
  return String(n?.native_item_kind || "");
1490
1514
  }
1491
- function U(e, t) {
1492
- let n = H(e[t]);
1515
+ function q(e, t) {
1516
+ let n = K(e[t]);
1493
1517
  if (!n) return [];
1494
1518
  let r = n?.parts;
1495
1519
  return Array.isArray(r) ? r : t === "update" ? [n] : [];
1496
1520
  }
1497
- function et(e) {
1498
- let t = H(e);
1521
+ function $e(e) {
1522
+ let t = K(e);
1499
1523
  if (!t) return "";
1500
1524
  if (typeof t.text == "string") return t.text;
1501
- let n = H(t.data);
1525
+ let n = K(t.data);
1502
1526
  if (n) {
1503
1527
  let e = n.content;
1504
- if (Array.isArray(e)) return e.map((e) => String(H(e)?.text || "")).join("");
1528
+ if (Array.isArray(e)) return e.map((e) => String(K(e)?.text || "")).join("");
1505
1529
  for (let e of [
1506
1530
  "text",
1507
1531
  "output",
@@ -1511,31 +1535,31 @@ function et(e) {
1511
1535
  }
1512
1536
  return "";
1513
1537
  }
1514
- function W(e) {
1515
- return e.map(et).join("");
1538
+ function J(e) {
1539
+ return e.map($e).join("");
1516
1540
  }
1517
- function tt(e) {
1518
- return e.some((e) => H(H(e)?.data)?.type === "userMessage");
1541
+ function et(e) {
1542
+ return e.some((e) => K(K(e)?.data)?.type === "userMessage");
1519
1543
  }
1520
- function G(e) {
1544
+ function Y(e) {
1521
1545
  if (e.length === 1) {
1522
- let t = H(H(e[0])?.data);
1546
+ let t = K(K(e[0])?.data);
1523
1547
  if (t) return t;
1524
1548
  }
1525
- return W(e) || null;
1549
+ return J(e) || null;
1526
1550
  }
1527
- function nt(e) {
1528
- let t = H(e);
1529
- return t ? H(t.data) || t : null;
1551
+ function X(e) {
1552
+ let t = K(e);
1553
+ return t ? K(t.data) || t : null;
1530
1554
  }
1531
- function rt(e) {
1532
- let t = nt(e);
1555
+ function tt(e) {
1556
+ let t = X(e);
1533
1557
  return String(t?.content_type || t?.type || "").trim().toLowerCase();
1534
1558
  }
1535
- function it(e) {
1559
+ function nt(e) {
1536
1560
  for (let t of e) {
1537
- let e = nt(t);
1538
- if (!e || rt(t) !== "tool_call") continue;
1561
+ let e = X(t);
1562
+ if (!e || tt(t) !== "tool_call") continue;
1539
1563
  let n = String(e.call_id || "").trim(), r = String(e.name || e.tool_name || "").trim();
1540
1564
  if (!(!n && !r)) return {
1541
1565
  callId: n,
@@ -1545,10 +1569,10 @@ function it(e) {
1545
1569
  }
1546
1570
  return null;
1547
1571
  }
1548
- function at(e) {
1572
+ function rt(e) {
1549
1573
  for (let t of e) {
1550
- let e = nt(t);
1551
- if (!e || rt(t) !== "tool_result") continue;
1574
+ let e = X(t);
1575
+ if (!e || tt(t) !== "tool_result") continue;
1552
1576
  let n = String(e.call_id || e.tool_call_id || "").trim(), r = e.is_error === !0 || e.error != null;
1553
1577
  return {
1554
1578
  callId: n,
@@ -1558,7 +1582,7 @@ function at(e) {
1558
1582
  }
1559
1583
  return null;
1560
1584
  }
1561
- function K(e, t, n, r) {
1585
+ function Z(e, t, n, r) {
1562
1586
  let i = String(e.item_id || ""), a = String(r || i);
1563
1587
  return { RuntimeItem: {
1564
1588
  RunId: String(e.run_id || ""),
@@ -1570,7 +1594,7 @@ function K(e, t, n, r) {
1570
1594
  ...i && i !== a ? { SourceItemId: i } : {}
1571
1595
  } };
1572
1596
  }
1573
- var ot = class {
1597
+ var it = class {
1574
1598
  textByPart = /* @__PURE__ */ new Map();
1575
1599
  toolNameByCallId = /* @__PURE__ */ new Map();
1576
1600
  toolCallByItemId = /* @__PURE__ */ new Map();
@@ -1580,7 +1604,7 @@ var ot = class {
1580
1604
  this.sessionId = e;
1581
1605
  }
1582
1606
  translate(e) {
1583
- if (!H(e)) return null;
1607
+ if (!K(e)) return null;
1584
1608
  let t = Number(e.seq);
1585
1609
  if (!Number.isFinite(t) || t <= 0) return null;
1586
1610
  let n = String(e.family || ""), r = String(e.event_type || ""), i = String(e.run_id || ""), a = () => ({
@@ -1589,7 +1613,7 @@ var ot = class {
1589
1613
  InvocationId: i || void 0,
1590
1614
  SeqId: t
1591
1615
  });
1592
- if (n === "interaction") return {
1616
+ if (n === "interaction" || r.startsWith("mcp.authorization.")) return {
1593
1617
  ...a(),
1594
1618
  EventType: r,
1595
1619
  payload: e
@@ -1602,7 +1626,7 @@ var ot = class {
1602
1626
  };
1603
1627
  if (r === "control.run_transition") {
1604
1628
  let t = String(e.state || "").toLowerCase();
1605
- if (Qe.has(t)) return {
1629
+ if (Ze.has(t)) return {
1606
1630
  ...a(),
1607
1631
  EventType: "run_status",
1608
1632
  Content: { status: t }
@@ -1611,19 +1635,19 @@ var ot = class {
1611
1635
  return null;
1612
1636
  }
1613
1637
  if (n !== "runtime") return null;
1614
- let o = H(H(e.source)?.metadata), s = o?.conversation_visibility ?? o?.visibility;
1638
+ let o = K(K(e.source)?.metadata), s = o?.conversation_visibility ?? o?.visibility;
1615
1639
  if (r.startsWith("item.") && ["internal", "hidden"].includes(String(s))) return null;
1616
- let c = Ze[r];
1640
+ let c = Xe[r];
1617
1641
  if (c) return {
1618
1642
  ...a(),
1619
1643
  EventType: "run_status",
1620
1644
  Content: { status: c }
1621
1645
  };
1622
- let l = $e(e);
1646
+ let l = Qe(e);
1623
1647
  if (r === "item.started") {
1624
- let t = U(e, "initial");
1648
+ let t = q(e, "initial");
1625
1649
  if (e.item_kind === "tool_call") {
1626
- let n = it(t);
1650
+ let n = nt(t);
1627
1651
  if (!n) return null;
1628
1652
  let r = n?.callId || String(e.item_id || ""), o = n?.name || "tool";
1629
1653
  return r && this.toolNameByCallId.set(r, o), e.item_id && this.toolCallByItemId.set(String(e.item_id), {
@@ -1633,42 +1657,42 @@ var ot = class {
1633
1657
  ...a(),
1634
1658
  EventType: "tool_call",
1635
1659
  Metadata: {
1636
- ...K(e, "replace", void 0, r),
1660
+ ...Z(e, "replace", void 0, r),
1637
1661
  call_id: r,
1638
1662
  tool_name: o,
1639
1663
  run_id: i,
1640
- tool_args: n?.arguments ?? G(t)
1664
+ tool_args: n?.arguments ?? Y(t)
1641
1665
  }
1642
1666
  };
1643
1667
  }
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" ? {
1668
+ return e.item_kind === "tool_result" || l === "userMessage" || et(t) || l === "reasoning" || e.item_kind === "reasoning" ? null : l === "agentMessage" || !l && e.item_kind === "message" ? {
1645
1669
  ...a(),
1646
1670
  EventType: "assistant_stream_snapshot",
1647
1671
  Content: { parts: [{ text: "" }] },
1648
- Metadata: K(e, "replace")
1672
+ Metadata: Z(e, "replace")
1649
1673
  } : l && l !== "notification" ? {
1650
1674
  ...a(),
1651
1675
  EventType: "tool_call",
1652
1676
  Metadata: {
1653
- ...K(e, "replace"),
1677
+ ...Z(e, "replace"),
1654
1678
  call_id: String(e.item_id || ""),
1655
1679
  tool_name: l,
1656
1680
  run_id: i,
1657
- tool_args: G(t)
1681
+ tool_args: Y(t)
1658
1682
  }
1659
1683
  } : null;
1660
1684
  }
1661
1685
  if (r === "item.updated") {
1662
- let n = U(e, "update");
1686
+ let n = q(e, "update");
1663
1687
  if (e.item_kind === "tool_call") {
1664
- let t = at(n);
1688
+ let t = rt(n);
1665
1689
  if (!t) return null;
1666
1690
  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
1691
  return e.item_id && this.toolResultByItemId.set(String(e.item_id), c), {
1668
1692
  ...a(),
1669
1693
  EventType: "tool_result",
1670
1694
  Metadata: {
1671
- ...K(e, "completed", void 0, o),
1695
+ ...Z(e, "completed", void 0, o),
1672
1696
  call_id: o,
1673
1697
  tool_name: s,
1674
1698
  run_id: i,
@@ -1676,44 +1700,44 @@ var ot = class {
1676
1700
  }
1677
1701
  };
1678
1702
  }
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;
1703
+ let r = K(n[0]), o = String(r?.part_id || e.item_id || t), s = String(e.op || "replace"), c = J(n), u = this.textByPart.get(o) || "", d = s === "append" ? u + c : c;
1680
1704
  return this.textByPart.set(o, d), l === "agentMessage" || !l && e.item_kind === "message" ? {
1681
1705
  ...a(),
1682
1706
  EventType: "assistant_stream_snapshot",
1683
1707
  Content: { parts: [{ text: d }] },
1684
- Metadata: K(e, "replace", o)
1708
+ Metadata: Z(e, "replace", o)
1685
1709
  } : l === "reasoning" || e.item_kind === "reasoning" ? {
1686
1710
  ...a(),
1687
1711
  EventType: "reasoning",
1688
1712
  Content: { parts: [{ text: c }] },
1689
- Metadata: K(e, s === "append" ? "append" : "replace", o)
1713
+ Metadata: Z(e, s === "append" ? "append" : "replace", o)
1690
1714
  } : null;
1691
1715
  }
1692
1716
  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);
1717
+ let n = q(e, "snapshot"), r = String(K(n[0])?.part_id || e.item_id || t), i = J(n);
1694
1718
  return this.textByPart.set(r, i), l === "agentMessage" || !l && e.item_kind === "message" ? {
1695
1719
  ...a(),
1696
1720
  EventType: "assistant_stream_snapshot",
1697
1721
  Content: { parts: [{ text: i }] },
1698
- Metadata: K(e, "replace", r)
1722
+ Metadata: Z(e, "replace", r)
1699
1723
  } : l === "reasoning" || e.item_kind === "reasoning" ? {
1700
1724
  ...a(),
1701
1725
  EventType: "reasoning",
1702
1726
  Content: { parts: [{ text: i }] },
1703
- Metadata: K(e, "replace", r)
1727
+ Metadata: Z(e, "replace", r)
1704
1728
  } : null;
1705
1729
  }
1706
1730
  if (r === "item.completed") {
1707
- let n = U(e, "snapshot");
1731
+ let n = q(e, "snapshot");
1708
1732
  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";
1733
+ let t = nt(n), r = rt(n), o = this.toolCallByItemId.get(String(e.item_id || "")), s = r?.callId || t?.callId || o?.callId || String(e.item_id || ""), c = t?.name || o?.name || this.toolNameByCallId.get(s) || "tool";
1710
1734
  if (s && this.toolNameByCallId.set(s, c), r) {
1711
1735
  let t = r.isError ? { error: r.result } : r.result;
1712
1736
  return {
1713
1737
  ...a(),
1714
1738
  EventType: "tool_result",
1715
1739
  Metadata: {
1716
- ...K(e, "completed", void 0, s),
1740
+ ...Z(e, "completed", void 0, s),
1717
1741
  call_id: s,
1718
1742
  tool_name: c,
1719
1743
  run_id: i,
@@ -1725,21 +1749,21 @@ var ot = class {
1725
1749
  ...a(),
1726
1750
  EventType: "tool_call",
1727
1751
  Metadata: {
1728
- ...K(e, "replace", void 0, s),
1752
+ ...Z(e, "replace", void 0, s),
1729
1753
  call_id: s,
1730
1754
  tool_name: c,
1731
1755
  run_id: i,
1732
- tool_args: t?.arguments ?? G(n)
1756
+ tool_args: t?.arguments ?? Y(n)
1733
1757
  }
1734
1758
  };
1735
1759
  }
1736
1760
  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);
1761
+ let t = rt(n), r = t?.callId || String(e.item_id || ""), o = this.toolNameByCallId.get(r) || l || "tool", s = t?.isError ? { error: t.result } : t?.result ?? Y(n);
1738
1762
  return {
1739
1763
  ...a(),
1740
1764
  EventType: "tool_result",
1741
1765
  Metadata: {
1742
- ...K(e, "completed", void 0, r),
1766
+ ...Z(e, "completed", void 0, r),
1743
1767
  call_id: r,
1744
1768
  tool_name: o,
1745
1769
  run_id: i,
@@ -1747,38 +1771,38 @@ var ot = class {
1747
1771
  }
1748
1772
  };
1749
1773
  }
1750
- if (l === "userMessage" || tt(n)) return {
1774
+ if (l === "userMessage" || et(n)) return {
1751
1775
  ...a(),
1752
1776
  EventType: "user_message",
1753
- Content: { parts: [{ text: W(n) }] }
1777
+ Content: { parts: [{ text: J(n) }] }
1754
1778
  };
1755
1779
  if (l === "agentMessage" || !l && e.item_kind === "message") {
1756
- let r = W(n), i = String(H(n[0])?.part_id || e.item_id || t);
1780
+ let r = J(n), i = String(K(n[0])?.part_id || e.item_id || t);
1757
1781
  return this.textByPart.set(i, r), {
1758
1782
  ...a(),
1759
1783
  EventType: "assistant_message",
1760
1784
  Content: { parts: [{ text: r }] },
1761
- Metadata: K(e, "completed", i)
1785
+ Metadata: Z(e, "completed", i)
1762
1786
  };
1763
1787
  }
1764
1788
  if (l === "reasoning" || e.item_kind === "reasoning") {
1765
- let r = String(H(n[0])?.part_id || e.item_id || t);
1789
+ let r = String(K(n[0])?.part_id || e.item_id || t);
1766
1790
  return {
1767
1791
  ...a(),
1768
1792
  EventType: "reasoning",
1769
- Content: { parts: [{ text: W(n) }] },
1770
- Metadata: K(e, "completed", r)
1793
+ Content: { parts: [{ text: J(n) }] },
1794
+ Metadata: Z(e, "completed", r)
1771
1795
  };
1772
1796
  }
1773
1797
  return l && l !== "notification" ? {
1774
1798
  ...a(),
1775
1799
  EventType: "tool_result",
1776
1800
  Metadata: {
1777
- ...K(e, "completed"),
1801
+ ...Z(e, "completed"),
1778
1802
  call_id: String(e.item_id || ""),
1779
1803
  tool_name: l,
1780
1804
  run_id: i,
1781
- tool_output: G(n)
1805
+ tool_output: Y(n)
1782
1806
  }
1783
1807
  } : null;
1784
1808
  }
@@ -1789,11 +1813,11 @@ var ot = class {
1789
1813
  ...a(),
1790
1814
  EventType: "tool_result",
1791
1815
  Metadata: {
1792
- ...K(e, "completed", void 0, n),
1816
+ ...Z(e, "completed", void 0, n),
1793
1817
  call_id: n,
1794
1818
  tool_name: r,
1795
1819
  run_id: i,
1796
- tool_output: o ?? { error: H(e.error) || e.error || "item failed" }
1820
+ tool_output: o ?? { error: K(e.error) || e.error || "item failed" }
1797
1821
  }
1798
1822
  };
1799
1823
  }
@@ -1801,18 +1825,18 @@ var ot = class {
1801
1825
  ...a(),
1802
1826
  EventType: "tool_result",
1803
1827
  Metadata: {
1804
- ...K(e, "completed"),
1828
+ ...Z(e, "completed"),
1805
1829
  call_id: String(e.item_id || ""),
1806
1830
  tool_name: l,
1807
1831
  run_id: i,
1808
- tool_output: { error: H(e.error) || e.error || "item failed" }
1832
+ tool_output: { error: K(e.error) || e.error || "item failed" }
1809
1833
  }
1810
1834
  } : null;
1811
1835
  }
1812
1836
  return null;
1813
1837
  }
1814
1838
  };
1815
- async function st(e) {
1839
+ async function at(e) {
1816
1840
  let t = e.getReader(), n = new TextDecoder(), r = "", i = null, a = !1, o = (e) => e.includes("data:") || e.includes("event:") || e.includes(":");
1817
1841
  try {
1818
1842
  for (;;) {
@@ -1822,8 +1846,8 @@ async function st(e) {
1822
1846
  break;
1823
1847
  }
1824
1848
  if (r.trimStart().startsWith("{")) {
1825
- if (ct(r)) {
1826
- i = lt(r);
1849
+ if (ot(r)) {
1850
+ i = st(r);
1827
1851
  break;
1828
1852
  }
1829
1853
  } else if (o(r)) break;
@@ -1859,7 +1883,7 @@ async function st(e) {
1859
1883
  stream: c
1860
1884
  };
1861
1885
  }
1862
- function ct(e) {
1886
+ function ot(e) {
1863
1887
  let t = e.trim();
1864
1888
  if (!t.endsWith("}")) return !1;
1865
1889
  let n = 0, r = !1, i = !1;
@@ -1876,11 +1900,11 @@ function ct(e) {
1876
1900
  }
1877
1901
  return n === 0;
1878
1902
  }
1879
- function lt(e) {
1903
+ function st(e) {
1880
1904
  try {
1881
- let t = H(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
1905
+ let t = K(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
1882
1906
  if (!n) return null;
1883
- let r = H(t?.Error);
1907
+ let r = K(t?.Error);
1884
1908
  return {
1885
1909
  status: n,
1886
1910
  presentationProfile: t?.PresentationProfile === "agent-block-v1" ? "agent-block-v1" : "flat-v1",
@@ -1898,1006 +1922,130 @@ function lt(e) {
1898
1922
  }
1899
1923
  }
1900
1924
  //#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);
1925
+ //#region src/utils/persisted-session-history.ts
1926
+ function Q(e) {
1927
+ return e && typeof e == "object" && !Array.isArray(e) ? e : null;
1941
1928
  }
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;
1929
+ function ct(e) {
1930
+ let t = e.map(dt), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t, n) => JSON.stringify([
1931
+ e,
1932
+ t,
1933
+ n
1934
+ ]);
1935
+ for (let e of t) {
1936
+ if (!e || Q(e.source)?.framework !== "langgraph" || e.item_kind !== "tool_call" && e.item_kind !== "tool_result") continue;
1937
+ let t = Q(e.snapshot ?? e.initial)?.parts;
1938
+ if (!Array.isArray(t)) continue;
1939
+ let a = t.map(Q).find((t) => t?.content_type === e.item_kind)?.call_id;
1940
+ if (!(typeof a != "string" || !a)) if (e.item_kind === "tool_result") r.set(i(e.run_id, e.scope_id, e.item_id), a);
1941
+ else {
1942
+ let t = i(e.run_id, e.scope_id, a);
1943
+ n.has(t) ? n.get(t)?.item_id !== e.item_id && n.set(t, null) : n.set(t, e);
1944
+ }
1949
1945
  }
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 : [];
1946
+ return t.map((e) => {
1947
+ if (!e || e.item_kind !== "tool_result" || !e.parent_scope_id) return e;
1948
+ let t = r.get(i(e.run_id, e.scope_id, e.item_id));
1949
+ if (!t || n.has(i(e.run_id, e.scope_id, t))) return e;
1950
+ let a = n.get(i(e.run_id, e.parent_scope_id, t));
1951
+ return a ? {
1952
+ ...e,
1953
+ scope_id: a.scope_id,
1954
+ parent_scope_id: a.parent_scope_id
1955
+ } : e;
1956
+ });
1955
1957
  }
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
- }] : [];
1958
+ function lt(e) {
1959
+ if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
1960
+ if (typeof e == "string" && e.trim()) {
1961
+ let t = Number(e.trim());
1962
+ if (Number.isFinite(t)) return t > 0 && t < 1e11 ? t * 1e3 : t;
2026
1963
  }
2027
- return [];
1964
+ let t = Date.parse(String(e || ""));
1965
+ return Number.isFinite(t) ? t : Date.now();
2028
1966
  }
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
- }] : [];
1967
+ function ut(e, t, r, i, a) {
1968
+ let o = /* @__PURE__ */ new Set(), s = (e, t) => JSON.stringify([e, t]), c = /* @__PURE__ */ new Set();
1969
+ for (let e of t) {
1970
+ let t = n(e, i);
1971
+ t?.kind === "approval" && t.outcome === "rejected" && t.runId && (o.add(t.runId), c.add(s(t.runId, t.interactionId)));
2094
1972
  }
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"
1973
+ let l = /* @__PURE__ */ new Map();
1974
+ for (let e of r) {
1975
+ if (e?.item_kind !== "data" || e.event_type !== "item.completed" || typeof e.run_id != "string" || typeof e.scope_id != "string" || Q(e.source)?.framework !== "langgraph") continue;
1976
+ let t = Q(e.snapshot)?.parts;
1977
+ if (Array.isArray(t)) for (let n of t) {
1978
+ let t = Q(Q(Q(n)?.data)?.["HumanInTheLoopMiddleware.after_model"]);
1979
+ if (Array.isArray(t?.messages)) for (let n of t.messages.map(Q)) {
1980
+ if (n?.type !== "tool" || n.status !== "error" || typeof n.tool_call_id != "string") continue;
1981
+ o.add(e.run_id);
1982
+ let t = s(e.run_id, n.tool_call_id), r = l.get(t) ?? /* @__PURE__ */ new Set();
1983
+ r.add(e.scope_id), l.set(t, r);
2123
1984
  }
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
1985
  }
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
1986
  }
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
- }
1987
+ if (!o.size) return e;
1988
+ let u = /* @__PURE__ */ new Set();
1989
+ for (let t of e) {
1990
+ let e = t.invocationId || t.runId;
1991
+ if (!(!t.scopeId || !e || !o.has(e))) for (let n of Object.values(t.tools || {})) n.callId && u.add(s(e, n.callId));
2422
1992
  }
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
1993
+ let d = (e) => {
1994
+ if (e.agentBlock) return {
1995
+ ...e,
1996
+ agentBlock: {
1997
+ ...e.agentBlock,
1998
+ messages: e.agentBlock.messages.map(d)
1999
+ }
2430
2000
  };
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" } : {}
2001
+ let t = e.invocationId || e.runId;
2002
+ if (!t || !o.has(t) || e.role !== "model") return e;
2003
+ let n = (n, r, i) => {
2004
+ if (![
2005
+ "running",
2006
+ "paused",
2007
+ "unknown"
2008
+ ].includes(i)) return;
2009
+ let o = typeof n == "string" ? s(t, n) : "", d = l.get(o);
2010
+ if (typeof r == "string" && c.has(s(t, r)) || d && (e.scopeId ? d.has(e.scopeId) : d.size === 1 && !u.has(o))) return {
2011
+ status: "completed",
2012
+ approvalStatus: "rejected"
2468
2013
  };
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
- }
2536
- 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));
2014
+ if (i !== "unknown" && a.has(t)) return { status: "unknown" };
2015
+ };
2561
2016
  return {
2562
- ...a,
2563
- output: t,
2564
- status: n(t) ? "error" : "completed"
2017
+ ...e,
2018
+ tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e, t]) => [e, {
2019
+ ...t,
2020
+ ...n(t.callId, t.approvalRequestId, t.status)
2021
+ }])),
2022
+ blocks: e.blocks?.map((e) => {
2023
+ if (e.type !== "tool") return e;
2024
+ let t = n(e.extra?.callId, e.extra?.approvalRequestId, e.status);
2025
+ return t ? {
2026
+ ...e,
2027
+ status: t.status,
2028
+ extra: {
2029
+ ...e.extra,
2030
+ ...t.approvalStatus ? { approvalStatus: t.approvalStatus } : {}
2031
+ }
2032
+ } : e;
2033
+ })
2565
2034
  };
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
2035
  };
2036
+ return e.map(d);
2696
2037
  }
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);
2859
- }
2860
- n.push(i);
2861
- }
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);
2865
- });
2866
- }
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) {
2882
- if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
2883
- if (typeof e == "string" && e.trim()) {
2884
- let t = Number(e.trim());
2885
- if (Number.isFinite(t)) return t > 0 && t < 1e11 ? t * 1e3 : t;
2886
- }
2887
- let t = Date.parse(String(e || ""));
2888
- return Number.isFinite(t) ? t : Date.now();
2889
- }
2890
- function $t(e) {
2891
- let t = $(e?.Content?.runtime_event || e?.Content?.runtimeEvent);
2038
+ function dt(e) {
2039
+ let t = Q(e?.Content?.runtime_event || e?.Content?.runtimeEvent);
2892
2040
  if (t && String(t.event_type || "")) return {
2893
2041
  ...t,
2894
2042
  family: "runtime",
2895
2043
  seq: Number(e.SeqId || t.seq || 0),
2896
2044
  timestamp: e.Timestamp || t.timestamp
2897
2045
  };
2898
- let n = $(e?.Content?.session_event || e?.Content?.sessionEvent);
2046
+ let n = Q(e?.Content?.session_event || e?.Content?.sessionEvent);
2899
2047
  if (!n || String(n.family || "") !== "runtime") return null;
2900
- let r = $(n.payload);
2048
+ let r = Q(n.payload);
2901
2049
  return !r || !String(r.event_type || n.event_type || "") ? null : {
2902
2050
  ...r,
2903
2051
  family: "runtime",
@@ -2907,31 +2055,31 @@ function $t(e) {
2907
2055
  timestamp: e.Timestamp || n.timestamp || r.timestamp
2908
2056
  };
2909
2057
  }
2910
- function en(e, t, n) {
2911
- let r = /* @__PURE__ */ new Map();
2058
+ function ft(e, t, n) {
2059
+ let i = /* @__PURE__ */ new Map();
2912
2060
  for (let e of t) {
2913
- if (e.EventType !== "run_status" || $t(e)) continue;
2061
+ if (e.EventType !== "run_status" || dt(e)) continue;
2914
2062
  let t = String(e.InvocationId || e.Metadata?.run_id || "").trim();
2915
- t && !n.has(t) && r.set(t, e);
2063
+ t && !n.has(t) && i.set(t, e);
2916
2064
  }
2917
- let i = e;
2918
- for (let [e, t] of r) {
2919
- let n = Kt({
2065
+ let a = e;
2066
+ for (let [e, t] of i) {
2067
+ let n = r({
2920
2068
  ...t,
2921
2069
  EventId: t.EventId || `legacy-terminal:${e}:${t.SeqId || 0}`,
2922
- Timestamp: Qt(t.Timestamp)
2070
+ Timestamp: lt(t.Timestamp)
2923
2071
  });
2924
2072
  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 = "运行已结束,未记录此工具的最终结果。";
2073
+ let i = (t) => (t.invocationId || t.runId) === e;
2074
+ a = a.filter((e) => !(i(e) && e.role === "system" && e.eventType === "run_status")).map((e) => {
2075
+ if (!i(e) || e.role !== "model") return e;
2076
+ let t = (e) => e === "running" || e === "paused", r = "运行已结束,未记录此工具的最终结果。";
2929
2077
  return {
2930
2078
  ...e,
2931
2079
  tools: e.tools && Object.fromEntries(Object.entries(e.tools).map(([e, n]) => [e, t(n.status) ? {
2932
2080
  ...n,
2933
2081
  status: "unknown",
2934
- summary: n.summary || i
2082
+ summary: n.summary || r
2935
2083
  } : n])),
2936
2084
  blocks: e.blocks?.map((e) => e.type === "thinking" && e.status === "streaming" ? {
2937
2085
  ...e,
@@ -2939,7 +2087,7 @@ function en(e, t, n) {
2939
2087
  } : e.type !== "tool" || !t(e.status) ? e : {
2940
2088
  ...e,
2941
2089
  status: "unknown",
2942
- summary: e.summary || i,
2090
+ summary: e.summary || r,
2943
2091
  extra: {
2944
2092
  ...e.extra,
2945
2093
  persistedToolStatus: e.status,
@@ -2947,18 +2095,18 @@ function en(e, t, n) {
2947
2095
  }
2948
2096
  })
2949
2097
  };
2950
- }), i.push({
2098
+ }), a.push({
2951
2099
  ...n,
2952
2100
  invocationId: e,
2953
2101
  eventId: t.EventId
2954
2102
  });
2955
2103
  }
2956
- return i === e ? e : P(i);
2104
+ return a === e ? e : L(a);
2957
2105
  }
2958
- function tn(e) {
2106
+ function $(e) {
2959
2107
  return e.role === "model" ? {
2960
2108
  ...e,
2961
- blocks: e.blocks?.length ? e.blocks : Xe({
2109
+ blocks: e.blocks?.length ? e.blocks : Ye({
2962
2110
  content: e.content,
2963
2111
  reasoning: e.reasoning,
2964
2112
  reasoningSource: e.reasoningSource,
@@ -2966,12 +2114,12 @@ function tn(e) {
2966
2114
  })
2967
2115
  } : e;
2968
2116
  }
2969
- function nn(e, t) {
2117
+ function pt(e, t) {
2970
2118
  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
2119
  ...e,
2972
2120
  ...n,
2973
2121
  invocationId: e.invocationId || n.invocationId
2974
- } : tn(e === a && o ? {
2122
+ } : $(e === a && o ? {
2975
2123
  ...e,
2976
2124
  responseId: o.responseId || e.responseId,
2977
2125
  traceId: o.traceId || e.traceId,
@@ -2979,7 +2127,7 @@ function nn(e, t) {
2979
2127
  } : e));
2980
2128
  return n && !r ? [n, ...s] : s;
2981
2129
  }
2982
- function rn(e, t) {
2130
+ function mt(e, t) {
2983
2131
  let n = t.filter((e) => e.role === "model"), r = n.flatMap((e) => Object.values(e.tools || {}).map((t) => ({
2984
2132
  tool: t,
2985
2133
  scope: e.scopeId
@@ -2994,7 +2142,7 @@ function rn(e, t) {
2994
2142
  return [t, r ? {
2995
2143
  ...n,
2996
2144
  ...r,
2997
- ...j(n, r),
2145
+ ...P(n, r),
2998
2146
  name: n.name
2999
2147
  } : n];
3000
2148
  })), n = e === s ? a : [];
@@ -3007,10 +2155,10 @@ function rn(e, t) {
3007
2155
  let n = t.extra?.callId, r = typeof n == "string" ? i(n, e.scopeId) : void 0;
3008
2156
  return r ? {
3009
2157
  ...t,
3010
- ...j(t, r)
2158
+ ...P(t, r)
3011
2159
  } : 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({
2160
+ }), c = Ye({ tools: Object.fromEntries(n.map(({ tool: e, scope: t }) => [JSON.stringify([t || "", e.callId || e.name]), e])) }), l = r?.findIndex((e) => e.type === "text") ?? -1;
2161
+ return $({
3014
2162
  ...e,
3015
2163
  ...e === s ? { reasoning: e.reasoning || o || void 0 } : {},
3016
2164
  tools: Object.keys(t).length ? t : e.tools,
@@ -3022,21 +2170,21 @@ function rn(e, t) {
3022
2170
  });
3023
2171
  });
3024
2172
  }
3025
- function an(e) {
2173
+ function ht(e) {
3026
2174
  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
2175
  }
3028
- var on = new Set([
2176
+ var gt = new Set([
3029
2177
  "approval.resolved",
3030
2178
  "interaction.resolved",
3031
2179
  "interaction.cancelled",
3032
2180
  "interaction.canceled",
3033
2181
  "a2ui.action"
3034
2182
  ]);
3035
- function sn(e) {
2183
+ function _t(e) {
3036
2184
  let t = /* @__PURE__ */ new Set();
3037
2185
  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;
2186
+ let e = Q(n.Content) || {}, r = Q(e.runtime_event || e.runtimeEvent) || {}, i = Q(e.payload) || Q(r.payload) || {}, a = String(n.EventType || e.event_type || e.eventType || r.event_type || "").toLowerCase();
2187
+ if (!gt.has(a)) continue;
3040
2188
  let o = String(e.outcome || e.action || e.name || e.status || i.outcome || i.action || i.name || i.status || "").toLowerCase();
3041
2189
  if (![
3042
2190
  "cancel",
@@ -3048,65 +2196,64 @@ function sn(e) {
3048
2196
  }
3049
2197
  return t;
3050
2198
  }
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);
2199
+ function vt(e, t, n, r = "flat-v1") {
2200
+ e = F(e);
2201
+ let a = new it(n), o = [], s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = [...t || []].filter((e) => {
2202
+ let t = e.Content, r = Q(t?.session_event || t?.sessionEvent), i = Q(t?.runtime_event || t?.runtimeEvent);
3055
2203
  return [
3056
2204
  e.SessionId,
3057
2205
  r?.session_id,
3058
2206
  i?.session_id
3059
2207
  ].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 && [
2208
+ }).sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), d = Number(u[0]?.SeqId || 0) <= 1, f = ct(u);
2209
+ for (let [e, t] of u.entries()) {
2210
+ let n = f[e];
2211
+ if (!n) continue;
2212
+ let r = String(n.run_id || "").trim();
2213
+ if (r) {
2214
+ s.add(r), !n.parent_scope_id && [
3067
2215
  "run.completed",
3068
2216
  "run.failed",
3069
2217
  "run.cancelled",
3070
2218
  "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);
2219
+ ].includes(String(n.event_type)) && c.add(r);
2220
+ let e = Q(Q(n.source)?.metadata), t = String(n.event_type || "") === "run.started", i = e?.native_item_kind === "userMessage";
2221
+ (d || t || i) && l.add(r);
3074
2222
  }
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)
2223
+ let i = a.translate(n);
2224
+ i && o.push({
2225
+ ...i,
2226
+ SeqId: Number(t.SeqId || i.SeqId || 0),
2227
+ Timestamp: lt(t.Timestamp || i.Timestamp)
3080
2228
  });
3081
2229
  }
3082
- let d = Jt(a).filter((e) => e.invocationId && o.has(e.invocationId)), f = /* @__PURE__ */ new Map();
2230
+ let p = i(o).filter((e) => e.invocationId && s.has(e.invocationId)), m = /* @__PURE__ */ new Map();
3083
2231
  for (let t of e) {
3084
2232
  let e = String(t.invocationId || "");
3085
- e && f.set(e, [...f.get(e) || [], t]);
3086
- }
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;
2233
+ e && m.set(e, [...m.get(e) || [], t]);
2234
+ }
2235
+ let h = new Set([...ht(p)].filter((e) => l.has(e))), g = /* @__PURE__ */ new Map();
2236
+ for (let e of f) {
2237
+ if (e?.schema_version !== 2 || !e.run_id) continue;
2238
+ let t = String(e.run_id), n = g.get(t) || [];
2239
+ n.push(e), g.set(t, n);
2240
+ }
2241
+ let _ = (e) => [
2242
+ Q(e.initial),
2243
+ Q(e.snapshot),
2244
+ Q(e.update)
2245
+ ].some((e) => Q(e?.data)?.schema === "execution.scope/v1" || Array.isArray(e?.parts) && e.parts.some((e) => Q(Q(e)?.data)?.schema === "execution.scope/v1")), v = new Set([...g].filter(([, e]) => e.some(_)).map(([e]) => e)), y = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Set();
2246
+ for (let [e, t] of g) {
2247
+ if (!v.has(e) && !h.has(e) && !t.some((e) => ["item.failed", "run.failed"].includes(String(e.event_type)))) continue;
3101
2248
  let i = t.some((e) => e.event_type === "run.started" && !e.parent_scope_id), a = /* @__PURE__ */ new Set(), o = t.every((e) => {
3102
2249
  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);
2250
+ return e.event_type === "item.started" && a.add(t), !_(e) || a.has(t);
3104
2251
  });
3105
2252
  if (!(!i || !o)) try {
3106
- let i = new S(n, void 0, r);
2253
+ let i = new w(n, void 0, r);
3107
2254
  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({
2255
+ let a = i.snapshot(), o = me(a, { profile: r }), s = lt(t[0].timestamp);
2256
+ y.set(e, U({
3110
2257
  state: a,
3111
2258
  presentation: o,
3112
2259
  runId: e,
@@ -3124,36 +2271,36 @@ function cn(e, t, n, r = "flat-v1") {
3124
2271
  };
3125
2272
  }));
3126
2273
  } catch (t) {
3127
- v.add(e), console.warn(`[SessionHistory] strict replay skipped for run ${e}:`, t instanceof Error ? t.message : "invalid runtime history");
2274
+ b.add(e), console.warn(`[SessionHistory] strict replay skipped for run ${e}:`, t instanceof Error ? t.message : "invalid runtime history");
3128
2275
  }
3129
2276
  }
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
2277
+ for (let e of new Set([...v, ...b])) y.has(e) || h.delete(e);
2278
+ let x = _t(u), S = [...h].flatMap((e) => pt(p.filter((t) => t.invocationId === e), m.get(e) || [])), C = /* @__PURE__ */ new Map(), T = [];
2279
+ for (let [e, t] of m) {
2280
+ if (h.has(e) || !s.has(e)) continue;
2281
+ let n = p.filter((t) => t.invocationId === e), r = t.some((e) => e.role === "model" && String(e.content || "").trim());
2282
+ C.set(e, r ? mt(t, n) : t), r || T.push(...n.map($));
2283
+ }
2284
+ for (let e of s) h.has(e) || m.has(e) || T.push(...p.filter((t) => t.invocationId === e).map($));
2285
+ let ee = new Map([...C.values()].flat().map((e) => [e.id, e])), E = L([
2286
+ ...e.filter((e) => !(e.role === "model" && e.invocationId && x.has(e.invocationId)) && (e.role === "a2ui" || !e.invocationId || !h.has(e.invocationId))).map((e) => ee.get(e.id) || e),
2287
+ ...S,
2288
+ ...T
3142
2289
  ]);
3143
- for (let [e, t] of _) {
2290
+ for (let [e, t] of y) {
3144
2291
  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 = [
2292
+ let n = (t) => t.invocationId === e || t.runId === e, r = E.findIndex(n), i = E.filter(n), a = i.find((e) => e.role === "user"), o = v.has(e) ? a && !t.some((e) => e.role === "user") ? [a, ...t] : t : pt(t, i), s = E.filter((e) => !n(e)), c = r < 0 ? s.length : r;
2293
+ E = [
3147
2294
  ...s.slice(0, c),
3148
2295
  ...o,
3149
2296
  ...s.slice(c)
3150
- ], p.add(e);
2297
+ ], h.add(e);
3151
2298
  }
3152
2299
  return {
3153
- messages: M(P(en(T, l, s))),
3154
- canonicalRunIds: [...p],
3155
- translatedEvents: a
2300
+ messages: ut(F(L(ft(E, u, c))), u, f, n, c),
2301
+ canonicalRunIds: [...h],
2302
+ translatedEvents: o
3156
2303
  };
3157
2304
  }
3158
2305
  //#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 };
2306
+ export { te as C, C as E, ne as S, w as T, F as _, Ue as a, Ce as b, Ge as c, He as d, Ke as f, Oe as g, U as h, at as i, Je as l, ze as m, vt as n, Ve as o, qe as p, it as r, Ye as s, dt as t, We as u, Ee as v, ee as w, me as x, Te as y };