@kingsoftcloud/ksadk-web 0.3.3 → 0.3.5

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 (282) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +31 -0
  3. package/RELEASE_PROVENANCE.json +2 -2
  4. package/dist-ksadk/assets/{ArtifactsPanel-CytJCLMc.js → ArtifactsPanel-9RUQms_7.js} +1 -1
  5. package/dist-ksadk/assets/{CodeBlock-D6tEbvd9.js → CodeBlock-iq6mFygx.js} +1 -1
  6. package/dist-ksadk/assets/{MathMessageMarkdown-BBnihmbC.js → MathMessageMarkdown-DSd_MMwp.js} +1 -1
  7. package/dist-ksadk/assets/{MermaidBlock-CI9NjqQx.js → MermaidBlock-B1tXyzN9.js} +6 -6
  8. package/dist-ksadk/assets/{NativeTerminalPanel-Czpx2MSS.js → NativeTerminalPanel-BTTm24gh.js} +1 -1
  9. package/dist-ksadk/assets/{abnfDiagram-VCTEODGH-CNsXewmF.js → abnfDiagram-VCTEODGH-CrPuGQ-J.js} +1 -1
  10. package/dist-ksadk/assets/{arc-x-74isv6.js → arc-LSpozW7f.js} +1 -1
  11. package/dist-ksadk/assets/architecture-7GRP2DOG-DlLqIl7c.js +1 -0
  12. package/dist-ksadk/assets/{architectureDiagram-5GKGNRK7-tZ3w1B6m.js → architectureDiagram-5GKGNRK7-BiBddfc6.js} +1 -1
  13. package/dist-ksadk/assets/{blockDiagram-NRAW4CY4-BEhGFh0b.js → blockDiagram-NRAW4CY4-Cfpt59CA.js} +1 -1
  14. package/dist-ksadk/assets/{c4Diagram-UCG6FXSJ-zrSgZM44.js → c4Diagram-UCG6FXSJ-TtkMYecK.js} +1 -1
  15. package/dist-ksadk/assets/channel-cg7jYcXF.js +1 -0
  16. package/dist-ksadk/assets/chunk-2Q5K7J3B-C4iMKTWb.js +1 -0
  17. package/dist-ksadk/assets/{chunk-5VM5RSS4-VZAcej21.js → chunk-5VM5RSS4-QNTrS1KC.js} +1 -1
  18. package/dist-ksadk/assets/{chunk-F27PBJKO-DNUQP5bs.js → chunk-F27PBJKO-CHsVsbjO.js} +1 -1
  19. package/dist-ksadk/assets/{chunk-G27WJ6UU-BVuLv5Os.js → chunk-G27WJ6UU-BiyNaPce.js} +1 -1
  20. package/dist-ksadk/assets/{chunk-JWPE2WC7-CEttzwEN.js → chunk-JWPE2WC7-EjVrwIfj.js} +1 -1
  21. package/dist-ksadk/assets/{chunk-LCL6LL3I-BT3bzrVf.js → chunk-LCL6LL3I-BCXNTVwQ.js} +1 -1
  22. package/dist-ksadk/assets/{chunk-POPQ4Y6H-BvutC1JH.js → chunk-POPQ4Y6H-BNP6opFp.js} +1 -1
  23. package/dist-ksadk/assets/{chunk-RHFEMEQ7-BIXm03MG.js → chunk-RHFEMEQ7-CroPk1q-.js} +1 -1
  24. package/dist-ksadk/assets/{chunk-SVP7TREG--LDO57tP.js → chunk-SVP7TREG-8eF2thNo.js} +1 -1
  25. package/dist-ksadk/assets/{chunk-XXDRQBXY-WtVtVhpq.js → chunk-XXDRQBXY-CfKEfSWB.js} +1 -1
  26. package/dist-ksadk/assets/classDiagram-DTDB5LWJ-RtbaG_Dz.js +1 -0
  27. package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-RtbaG_Dz.js +1 -0
  28. package/dist-ksadk/assets/{cose-bilkent-JH36ORCC-CnqJMsPI.js → cose-bilkent-JH36ORCC-NYLLr4y3.js} +1 -1
  29. package/dist-ksadk/assets/cynefin-OW5HDTMX-BRs0UJ32.js +1 -0
  30. package/dist-ksadk/assets/{cynefinDiagram-5FMLGOSQ-Ci9qjtA_.js → cynefinDiagram-5FMLGOSQ-1t2bjASn.js} +1 -1
  31. package/dist-ksadk/assets/{dagre-3AP2YEHR-Ll3LkcYP.js → dagre-3AP2YEHR-CyCcpGXQ.js} +1 -1
  32. package/dist-ksadk/assets/{dagre-CKrj2THw.js → dagre-DIBkWWe5.js} +1 -1
  33. package/dist-ksadk/assets/{diagram-S7CK7UJ4-BQ1slPEx.js → diagram-S7CK7UJ4-Qnyx09fY.js} +1 -1
  34. package/dist-ksadk/assets/{diagram-UQ7AKVKN-BXz7DvIg.js → diagram-UQ7AKVKN-BBuBi2BK.js} +1 -1
  35. package/dist-ksadk/assets/{diagram-VSXAHHWV-DOno97OL.js → diagram-VSXAHHWV-Cu2pi7DX.js} +1 -1
  36. package/dist-ksadk/assets/{diagram-VX7I27RA-CU2kHvv3.js → diagram-VX7I27RA-D1hy0wPv.js} +1 -1
  37. package/dist-ksadk/assets/{diagram-Z3DM3KII-mhpvOavV.js → diagram-Z3DM3KII-DG_ukeOg.js} +1 -1
  38. package/dist-ksadk/assets/{dist-DeO3Qj-D.js → dist-32Woo6w8.js} +1 -1
  39. package/dist-ksadk/assets/{dist-Byl0QKIY.js → dist-39frJg8c.js} +1 -1
  40. package/dist-ksadk/assets/{dist-DwwtGqH9.js → dist-7mNpnBIq.js} +1 -1
  41. package/dist-ksadk/assets/{dist-BvMDy0Xp.js → dist-BDYKkv8k.js} +1 -1
  42. package/dist-ksadk/assets/{dist-4j-rswH6.js → dist-BRFE6wml.js} +1 -1
  43. package/dist-ksadk/assets/{dist-B-VEMnGR.js → dist-Bami3Hbn.js} +1 -1
  44. package/dist-ksadk/assets/{dist-CoCI5ZIy.js → dist-BbqgJcRm.js} +1 -1
  45. package/dist-ksadk/assets/{dist-C-V2Wj4x.js → dist-Bo0uuYGj.js} +1 -1
  46. package/dist-ksadk/assets/{dist-CUFAKgYs.js → dist-BoDw8sHC.js} +1 -1
  47. package/dist-ksadk/assets/{dist-hRISJdRx.js → dist-Bzd96FWg.js} +1 -1
  48. package/dist-ksadk/assets/{dist-2cbEIexW.js → dist-C6YcRSBB.js} +1 -1
  49. package/dist-ksadk/assets/{dist-BxjBfG2w.js → dist-C8E2u2Gy.js} +1 -1
  50. package/dist-ksadk/assets/{dist-BZiMQVbN.js → dist-CgpyS7Tw.js} +1 -1
  51. package/dist-ksadk/assets/{dist-oPMjOYRU.js → dist-CsdC51-G.js} +1 -1
  52. package/dist-ksadk/assets/{dist-CTeZLI0m.js → dist-D0t-jg0i.js} +1 -1
  53. package/dist-ksadk/assets/{dist-C-Q0Ulfg.js → dist-D2l4f5Dh.js} +1 -1
  54. package/dist-ksadk/assets/{dist-BQCggVji.js → dist-Dbb1c9iJ.js} +1 -1
  55. package/dist-ksadk/assets/{dist-CaTDm1g0.js → dist-_RQDZ9v3.js} +1 -1
  56. package/dist-ksadk/assets/{dist-DGFsOxe9.js → dist-dLCAHoLT.js} +1 -1
  57. package/dist-ksadk/assets/{dist-B6XMlZpc.js → dist-mo17RERT.js} +1 -1
  58. package/dist-ksadk/assets/{dist-CPZHorum.js → dist-snMJ4dAH.js} +1 -1
  59. package/dist-ksadk/assets/{dist-DgSf2VGQ.js → dist-vM3yu1Iv.js} +1 -1
  60. package/dist-ksadk/assets/{ebnfDiagram-PWID7BFC-DAH8tjOy.js → ebnfDiagram-PWID7BFC-DuBo2W05.js} +1 -1
  61. package/dist-ksadk/assets/{erDiagram-SSCWMZ5O-JvDkJGJ3.js → erDiagram-SSCWMZ5O-ZJrJetMD.js} +1 -1
  62. package/dist-ksadk/assets/eventmodeling-NTZA5JFV-DCJzsswd.js +1 -0
  63. package/dist-ksadk/assets/flowDiagram-A5DVABFB-485rByL2.js +1 -0
  64. package/dist-ksadk/assets/{ganttDiagram-EL5Y4UJY-B-SEC706.js → ganttDiagram-EL5Y4UJY-Bwk2yIEM.js} +1 -1
  65. package/dist-ksadk/assets/gitGraph-4MIJSDKK-C5VB4yJL.js +1 -0
  66. package/dist-ksadk/assets/{gitGraphDiagram-WWUBYQGX-D7OJf_No.js → gitGraphDiagram-WWUBYQGX-DWYLIagz.js} +1 -1
  67. package/dist-ksadk/assets/index-Cp5NEP4y.css +2 -0
  68. package/dist-ksadk/assets/index-j3aFdsSv.js +244 -0
  69. package/dist-ksadk/assets/info-A6RAGUB7-tqDdMmNT.js +1 -0
  70. package/dist-ksadk/assets/{infoDiagram-RXCK75RN-CTIHOSud.js → infoDiagram-RXCK75RN-DMPen5_h.js} +1 -1
  71. package/dist-ksadk/assets/{ishikawaDiagram-5VMMS53U-HMO7FchJ.js → ishikawaDiagram-5VMMS53U-DsPNKFIz.js} +1 -1
  72. package/dist-ksadk/assets/{journeyDiagram-EYS64GPL-DeFbDr5t.js → journeyDiagram-EYS64GPL-BNbTP-8a.js} +1 -1
  73. package/dist-ksadk/assets/{kanban-definition-3QL26DDD-D3OeNqXY.js → kanban-definition-3QL26DDD-BKR6Itkv.js} +1 -1
  74. package/dist-ksadk/assets/{katex-DCJHF0vD.js → katex-B0oLa8CR.js} +1 -1
  75. package/dist-ksadk/assets/{linear-D3-vxS4W.js → linear-B3_la4oE.js} +1 -1
  76. package/dist-ksadk/assets/{mermaid-parser.core-C-Sc5_7E.js → mermaid-parser.core-B6PQSAV-.js} +2 -2
  77. package/dist-ksadk/assets/{mindmap-definition-FBJOCRG2-D-XtspHN.js → mindmap-definition-FBJOCRG2-By8qFxGO.js} +1 -1
  78. package/dist-ksadk/assets/packet-AYTQ26CC-BxA-7Hkq.js +1 -0
  79. package/dist-ksadk/assets/{pegDiagram-XKGWAZYB-BYbAq9Nb.js → pegDiagram-XKGWAZYB-K1kvFBKC.js} +1 -1
  80. package/dist-ksadk/assets/pie-WAS4IAKB-3Tmx9EyU.js +1 -0
  81. package/dist-ksadk/assets/{pieDiagram-E7YTZNPT-DQ2yX4VQ.js → pieDiagram-E7YTZNPT-5XFtDn56.js} +1 -1
  82. package/dist-ksadk/assets/{quadrantDiagram-AXDQQJYC-rvRPUN0j.js → quadrantDiagram-AXDQQJYC-DQwy74C1.js} +1 -1
  83. package/dist-ksadk/assets/radar-RG4KPBEZ-D_bZK5Bu.js +1 -0
  84. package/dist-ksadk/assets/railroad-74A4TZTK-COy6RdCd.js +1 -0
  85. package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-CrdA8h6r.js +1 -0
  86. package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-BnDti7-r.js +1 -0
  87. package/dist-ksadk/assets/railroad-peg-WCYAUIDC-DmYdbc7f.js +1 -0
  88. package/dist-ksadk/assets/{railroadDiagram-O6MQD6OU-2OVn6qwA.js → railroadDiagram-O6MQD6OU-cozhldnA.js} +1 -1
  89. package/dist-ksadk/assets/{requirementDiagram-EFPCY7ZU-ChWVLAKz.js → requirementDiagram-EFPCY7ZU-CElPZjXR.js} +1 -1
  90. package/dist-ksadk/assets/{sankeyDiagram-P5KCCOFB-Cb5gXi_j.js → sankeyDiagram-P5KCCOFB-y_USXv4y.js} +1 -1
  91. package/dist-ksadk/assets/{sequenceDiagram-WJ2MYXX4-D7g_-PUM.js → sequenceDiagram-WJ2MYXX4-BJbQk7Za.js} +1 -1
  92. package/dist-ksadk/assets/{sizeCapture-X5ZJPWSS-D__whCj3.js → sizeCapture-X5ZJPWSS-DAaf435S.js} +1 -1
  93. package/dist-ksadk/assets/{stateDiagram-HBIQ2CUA-CpKIc0dl.js → stateDiagram-HBIQ2CUA-BiLbLu1I.js} +1 -1
  94. package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-5rxHhPTD.js +1 -0
  95. package/dist-ksadk/assets/{swimlanes-XN3QIQJK-CFJohC2b.js → swimlanes-XN3QIQJK-DxhmU8aj.js} +1 -1
  96. package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-B3Po2rui.js +8 -0
  97. package/dist-ksadk/assets/{timeline-definition-24CTP7MA-Dg4AY0KC.js → timeline-definition-24CTP7MA-D18EWv7u.js} +1 -1
  98. package/dist-ksadk/assets/treeView-Q6P3EWNA-6G5wA0pE.js +1 -0
  99. package/dist-ksadk/assets/treemap-WGGIJYW6-BE9GnPbg.js +1 -0
  100. package/dist-ksadk/assets/{vennDiagram-4TSXK5OY-A6cRoCBU.js → vennDiagram-4TSXK5OY-rUBCuIGM.js} +1 -1
  101. package/dist-ksadk/assets/wardley-WFR3VGLG-BYh81kWC.js +1 -0
  102. package/dist-ksadk/assets/{wardleyDiagram-VM6X3IG4-BVD1hMYl.js → wardleyDiagram-VM6X3IG4-CDZQ5sZK.js} +1 -1
  103. package/dist-ksadk/assets/{xychartDiagram-S5SC5T6Z-BlBLXETg.js → xychartDiagram-S5SC5T6Z-CH_HdHYk.js} +1 -1
  104. package/dist-ksadk/index.html +2 -2
  105. package/dist-lib/App.d.ts.map +1 -1
  106. package/dist-lib/{ArtifactsPanel-D2EtX4X_.js → ArtifactsPanel-BX-TQaOJ.js} +18 -17
  107. package/dist-lib/AttachmentPreview-D8BjnDTd.js +694 -0
  108. package/dist-lib/{CodeBlock-CPaeJbtf.js → CodeBlock-D3-ZCOb_.js} +44 -41
  109. package/dist-lib/ConnectedComposer-BgTxuTfq.js +743 -0
  110. package/dist-lib/ConnectedMessageList-BwRiSswQ.js +1504 -0
  111. package/dist-lib/{MathMessageMarkdown-Bpp4hI6Q.js → MathMessageMarkdown-DwgeFqKs.js} +32 -31
  112. package/dist-lib/MenuChip-BXivncgX.js +43 -0
  113. package/dist-lib/{MermaidBlock-BFNE1NN8.js → MermaidBlock-DBFTztfQ.js} +15 -13
  114. package/dist-lib/{NativeTerminalPanel-CJXzKV0z.js → NativeTerminalPanel-DyPvD5ij.js} +166 -172
  115. package/dist-lib/WorkspacePanelContainer-C-na8Ns1.js +1617 -0
  116. package/dist-lib/a2ui-TSXmGrT-.js +486 -0
  117. package/dist-lib/api/client.d.ts +48 -14
  118. package/dist-lib/api/client.d.ts.map +1 -1
  119. package/dist-lib/{capabilities-njdklP3r.js → capabilities-CXle1R-K.js} +60 -30
  120. package/dist-lib/capabilities.js +1 -1
  121. package/dist-lib/chat-composer.js +4 -0
  122. package/dist-lib/chat-timeline.js +3 -0
  123. package/dist-lib/components/chat/A2UIActivityMessage.d.ts.map +1 -1
  124. package/dist-lib/components/chat/ChatComposer.d.ts +4 -3
  125. package/dist-lib/components/chat/ChatComposer.d.ts.map +1 -1
  126. package/dist-lib/components/chat/ChatMessageList.d.ts +16 -4
  127. package/dist-lib/components/chat/ChatMessageList.d.ts.map +1 -1
  128. package/dist-lib/components/chat/ConnectedComposer.d.ts +4 -3
  129. package/dist-lib/components/chat/ConnectedComposer.d.ts.map +1 -1
  130. package/dist-lib/components/chat/ConnectedMessageList.d.ts +6 -3
  131. package/dist-lib/components/chat/ConnectedMessageList.d.ts.map +1 -1
  132. package/dist-lib/components/chat/ContextUsageIndicator.d.ts +4 -8
  133. package/dist-lib/components/chat/ContextUsageIndicator.d.ts.map +1 -1
  134. package/dist-lib/components/chat/ExecutionModeMenu.d.ts.map +1 -1
  135. package/dist-lib/components/chat/InteractionHistoryAnchor.d.ts +1 -1
  136. package/dist-lib/components/chat/InteractionHistoryAnchor.d.ts.map +1 -1
  137. package/dist-lib/components/chat/InteractionSchemaForm.d.ts.map +1 -1
  138. package/dist-lib/components/chat/InteractionTray.d.ts +4 -4
  139. package/dist-lib/components/chat/InteractionTray.d.ts.map +1 -1
  140. package/dist-lib/components/chat/MenuChip.d.ts +19 -0
  141. package/dist-lib/components/chat/MenuChip.d.ts.map +1 -0
  142. package/dist-lib/components/chat/ModelSettingsMenu.d.ts.map +1 -1
  143. package/dist-lib/components/chat/PermissionMenu.d.ts.map +1 -1
  144. package/dist-lib/components/chat/ProcessingBlocksView.d.ts +3 -3
  145. package/dist-lib/components/chat/ProcessingBlocksView.d.ts.map +1 -1
  146. package/dist-lib/components/chat/schema-fields.d.ts +4 -1
  147. package/dist-lib/components/chat/schema-fields.d.ts.map +1 -1
  148. package/dist-lib/components/chat/types.d.ts +4 -1
  149. package/dist-lib/components/chat/types.d.ts.map +1 -1
  150. package/dist-lib/components.js +38 -30
  151. package/dist-lib/conversation.js +5 -5
  152. package/dist-lib/core/api/facade.d.ts +70 -13
  153. package/dist-lib/core/api/facade.d.ts.map +1 -1
  154. package/dist-lib/core/api/types.d.ts +4 -1
  155. package/dist-lib/core/api/types.d.ts.map +1 -1
  156. package/dist-lib/core/conversation/client.d.ts.map +1 -1
  157. package/dist-lib/core/conversation/hosted.d.ts +4 -2
  158. package/dist-lib/core/conversation/hosted.d.ts.map +1 -1
  159. package/dist-lib/core/conversation/index.d.ts +1 -1
  160. package/dist-lib/core/conversation/index.d.ts.map +1 -1
  161. package/dist-lib/core/conversation/presentation.d.ts +9 -1
  162. package/dist-lib/core/conversation/presentation.d.ts.map +1 -1
  163. package/dist-lib/core/interaction/adapters/normalize.d.ts +2 -2
  164. package/dist-lib/core/interaction/adapters/normalize.d.ts.map +1 -1
  165. package/dist-lib/core/interaction/adapters/responses.d.ts.map +1 -1
  166. package/dist-lib/core/interaction/adapters/session-events.d.ts.map +1 -1
  167. package/dist-lib/core/interaction/client.d.ts.map +1 -1
  168. package/dist-lib/core/interaction/index.d.ts +8 -0
  169. package/dist-lib/core/interaction/index.d.ts.map +1 -1
  170. package/dist-lib/core/interaction/store.d.ts +0 -0
  171. package/dist-lib/core/interaction/store.d.ts.map +1 -1
  172. package/dist-lib/core/run/a2ui.d.ts +2 -0
  173. package/dist-lib/core/run/a2ui.d.ts.map +1 -1
  174. package/dist-lib/core/run/blocks.d.ts +8 -0
  175. package/dist-lib/core/run/blocks.d.ts.map +1 -1
  176. package/dist-lib/core/run/dispatcher.d.ts.map +1 -1
  177. package/dist-lib/core/run/engine.d.ts.map +1 -1
  178. package/dist-lib/core/run/types.d.ts +4 -1
  179. package/dist-lib/core/run/types.d.ts.map +1 -1
  180. package/dist-lib/core/stream/kernel-events.d.ts +3 -0
  181. package/dist-lib/core/stream/kernel-events.d.ts.map +1 -1
  182. package/dist-lib/core/stream/types.d.ts +7 -0
  183. package/dist-lib/core/stream/types.d.ts.map +1 -1
  184. package/dist-lib/feedback-D256P415.js +239 -0
  185. package/dist-lib/hooks/useAgentChat.d.ts +95 -0
  186. package/dist-lib/hooks/useAgentChat.d.ts.map +1 -0
  187. package/dist-lib/hooks/useBootstrap.d.ts +3 -2
  188. package/dist-lib/hooks/useBootstrap.d.ts.map +1 -1
  189. package/dist-lib/hooks/useRunAgent.d.ts +7 -0
  190. package/dist-lib/hooks/useRunAgent.d.ts.map +1 -1
  191. package/dist-lib/hooks/useSessionLifecycle.d.ts +2 -0
  192. package/dist-lib/hooks/useSessionLifecycle.d.ts.map +1 -1
  193. package/dist-lib/hooks.js +167 -0
  194. package/dist-lib/permission-BWkTcIzC.js +24 -0
  195. package/dist-lib/persisted-session-history-Bb3ScKrL.js +2230 -0
  196. package/dist-lib/public/chat-composer.d.ts +15 -0
  197. package/dist-lib/public/chat-composer.d.ts.map +1 -0
  198. package/dist-lib/public/chat-timeline.d.ts +12 -0
  199. package/dist-lib/public/chat-timeline.d.ts.map +1 -0
  200. package/dist-lib/public/components.d.ts +23 -0
  201. package/dist-lib/public/components.d.ts.map +1 -1
  202. package/dist-lib/public/conversation.d.ts +3 -0
  203. package/dist-lib/public/conversation.d.ts.map +1 -1
  204. package/dist-lib/public/hooks.d.ts +3 -0
  205. package/dist-lib/public/hooks.d.ts.map +1 -0
  206. package/dist-lib/public/runtime.d.ts +2 -0
  207. package/dist-lib/public/runtime.d.ts.map +1 -1
  208. package/dist-lib/public/styles.d.ts +1 -1
  209. package/dist-lib/rolldown-runtime-Dy4uBu1J.js +11 -0
  210. package/dist-lib/runtime-items-q6tMjfGU.js +0 -0
  211. package/dist-lib/runtime.js +264 -6148
  212. package/dist-lib/sandbox-BTRIKAO6.js +92 -0
  213. package/dist-lib/stores/model.d.ts +1 -0
  214. package/dist-lib/stores/model.d.ts.map +1 -1
  215. package/dist-lib/styles.css +1 -1
  216. package/dist-lib/tool-display-DTiRdghE.js +64 -0
  217. package/dist-lib/types/capabilities.d.ts +1 -0
  218. package/dist-lib/types/capabilities.d.ts.map +1 -1
  219. package/dist-lib/useSessionLifecycle-DuzkfGgL.js +4233 -0
  220. package/dist-lib/utils/capabilities.d.ts.map +1 -1
  221. package/dist-lib/utils/chat-message-grouping.d.ts +4 -0
  222. package/dist-lib/utils/chat-message-grouping.d.ts.map +1 -0
  223. package/dist-lib/utils/chat-scroll.d.ts +14 -0
  224. package/dist-lib/utils/chat-scroll.d.ts.map +1 -0
  225. package/dist-lib/utils/context.d.ts +12 -7
  226. package/dist-lib/utils/context.d.ts.map +1 -1
  227. package/dist-lib/utils/messages.d.ts.map +1 -1
  228. package/dist-lib/utils/persisted-session-history.d.ts +29 -0
  229. package/dist-lib/utils/persisted-session-history.d.ts.map +1 -0
  230. package/dist-lib/utils/recovered-run.d.ts.map +1 -1
  231. package/dist-lib/utils/responses-stream.d.ts +2 -0
  232. package/dist-lib/utils/responses-stream.d.ts.map +1 -1
  233. package/dist-lib/utils/session-event-history.d.ts.map +1 -1
  234. package/dist-lib/utils/session-events.d.ts.map +1 -1
  235. package/dist-lib/utils/session.d.ts +1 -0
  236. package/dist-lib/utils/session.d.ts.map +1 -1
  237. package/dist-lib/utils/workspace.d.ts +1 -1
  238. package/package.json +16 -2
  239. package/dist-ksadk/assets/architecture-7GRP2DOG-C3S9W0aD.js +0 -1
  240. package/dist-ksadk/assets/channel-CdffTTpb.js +0 -1
  241. package/dist-ksadk/assets/chunk-2Q5K7J3B-B6k89qGR.js +0 -1
  242. package/dist-ksadk/assets/classDiagram-DTDB5LWJ-C0BU8Yr9.js +0 -1
  243. package/dist-ksadk/assets/classDiagram-v2-JRS7N3AN-C0BU8Yr9.js +0 -1
  244. package/dist-ksadk/assets/cynefin-OW5HDTMX-BckONr__.js +0 -1
  245. package/dist-ksadk/assets/eventmodeling-NTZA5JFV-vjy4Z61x.js +0 -1
  246. package/dist-ksadk/assets/flowDiagram-A5DVABFB-CvJ64Qzs.js +0 -1
  247. package/dist-ksadk/assets/gitGraph-4MIJSDKK-CX3KwgqY.js +0 -1
  248. package/dist-ksadk/assets/index-BkDx9KsG.js +0 -241
  249. package/dist-ksadk/assets/index-DW7rZ4ml.css +0 -2
  250. package/dist-ksadk/assets/info-A6RAGUB7-CYHIOuL5.js +0 -1
  251. package/dist-ksadk/assets/packet-AYTQ26CC-Ctg2wH4o.js +0 -1
  252. package/dist-ksadk/assets/pie-WAS4IAKB-CU6GnSzI.js +0 -1
  253. package/dist-ksadk/assets/radar-RG4KPBEZ-Bhe0us4A.js +0 -1
  254. package/dist-ksadk/assets/railroad-74A4TZTK-DEgiNGfx.js +0 -1
  255. package/dist-ksadk/assets/railroad-abnf-HS5TGJTU-GK7ct0QX.js +0 -1
  256. package/dist-ksadk/assets/railroad-ebnf-LZEXJU2U-BzlcTUmk.js +0 -1
  257. package/dist-ksadk/assets/railroad-peg-WCYAUIDC-7ESM96BW.js +0 -1
  258. package/dist-ksadk/assets/stateDiagram-v2-4QOOHH4V-D7ulg6TV.js +0 -1
  259. package/dist-ksadk/assets/swimlanesDiagram-VK2B7HYN-A-oZaquE.js +0 -8
  260. package/dist-ksadk/assets/treeView-Q6P3EWNA-D6u1mSx1.js +0 -1
  261. package/dist-ksadk/assets/treemap-WGGIJYW6-CM87Vav0.js +0 -1
  262. package/dist-ksadk/assets/wardley-WFR3VGLG-BPoQUTzr.js +0 -1
  263. package/dist-lib/WorkspacePanelContainer-DbD-6xqx.js +0 -4616
  264. package/dist-lib/api/bootstrap.d.ts +0 -2
  265. package/dist-lib/api/bootstrap.d.ts.map +0 -1
  266. package/dist-lib/api/checkpoints.d.ts +0 -38
  267. package/dist-lib/api/checkpoints.d.ts.map +0 -1
  268. package/dist-lib/api/events.d.ts +0 -20
  269. package/dist-lib/api/events.d.ts.map +0 -1
  270. package/dist-lib/api/messages.d.ts +0 -73
  271. package/dist-lib/api/messages.d.ts.map +0 -1
  272. package/dist-lib/api/model.d.ts +0 -2
  273. package/dist-lib/api/model.d.ts.map +0 -1
  274. package/dist-lib/api/run.d.ts +0 -36
  275. package/dist-lib/api/run.d.ts.map +0 -1
  276. package/dist-lib/api/session.d.ts +0 -61
  277. package/dist-lib/api/session.d.ts.map +0 -1
  278. package/dist-lib/api/upload.d.ts +0 -12
  279. package/dist-lib/api/upload.d.ts.map +0 -1
  280. package/dist-lib/api/workspace.d.ts +0 -8
  281. package/dist-lib/api/workspace.d.ts.map +0 -1
  282. package/dist-lib/client-1WQCunUo.js +0 -616
@@ -0,0 +1,2230 @@
1
+ import { n as e } from "./tool-display-DTiRdghE.js";
2
+ //#region src/core/conversation/errors.ts
3
+ var t = class extends Error {
4
+ code;
5
+ status;
6
+ capability;
7
+ runId;
8
+ cursor;
9
+ cause;
10
+ constructor(e, t, n = {}) {
11
+ super(t), this.name = "ConversationClientError", this.code = e, this.status = n.status, this.capability = n.capability, this.runId = n.runId, this.cursor = n.cursor, this.cause = n.cause;
12
+ }
13
+ }, n = "conversation.ksadk.io/v1", r = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/, i = new Set([
14
+ "native",
15
+ "translated",
16
+ "degraded",
17
+ "unavailable"
18
+ ]), a = new Set([
19
+ "user_message",
20
+ "assistant_text",
21
+ "reasoning",
22
+ "tool_call",
23
+ "approval",
24
+ "progress",
25
+ "plan",
26
+ "goal",
27
+ "artifact",
28
+ "a2ui",
29
+ "error",
30
+ "unknown"
31
+ ]), o = new Set([
32
+ "append",
33
+ "replace",
34
+ "completed"
35
+ ]), s = new Set([
36
+ "pending",
37
+ "streaming",
38
+ "completed",
39
+ "failed"
40
+ ]), c = new Set([
41
+ "public",
42
+ "internal",
43
+ "hidden"
44
+ ]), l = new Set([
45
+ "apiVersion",
46
+ "kind",
47
+ "inputId",
48
+ "sessionId",
49
+ "idempotencyKey",
50
+ "parts",
51
+ "modelRef",
52
+ "reasoning",
53
+ "extensions"
54
+ ]), u = new Set(["kind", "text"]), d = new Set([
55
+ "kind",
56
+ "attachmentRef",
57
+ "mediaType",
58
+ "name"
59
+ ]), f = "ksadk.approval", p = "ksadk.collaboration", m = "ksadk.goal";
60
+ function h(e) {
61
+ return typeof e == "object" && e && !Array.isArray(e) ? e : null;
62
+ }
63
+ function g(e, t) {
64
+ return typeof e == "string" && e.length > 0 && e.length <= t;
65
+ }
66
+ function _(e, t, n = !1) {
67
+ return e == null || typeof e == "string" && e.length <= t && (n || e.length > 0);
68
+ }
69
+ function v(e, t) {
70
+ return Object.keys(e).every((e) => t.has(e));
71
+ }
72
+ function y(e) {
73
+ let t = h(e);
74
+ return !t || typeof t.kind != "string" ? null : t.kind === "text" ? !v(t, u) || !g(t.text, 131072) ? null : {
75
+ kind: "text",
76
+ text: t.text
77
+ } : t.kind === "attachment" ? !v(t, d) || !g(t.attachmentRef, 2048) || !g(t.mediaType, 256) || !_(t.name, 1024, !0) ? null : {
78
+ kind: "attachment",
79
+ attachmentRef: t.attachmentRef,
80
+ mediaType: t.mediaType,
81
+ ...t.name === void 0 ? {} : { name: t.name }
82
+ } : null;
83
+ }
84
+ function b(e) {
85
+ if (e === void 0) return {};
86
+ let t = h(e);
87
+ if (!t || Object.keys(t).some((e) => !r.test(e) || !e.includes("."))) return null;
88
+ let n = t[f], i = t[p], a = t[m];
89
+ return n !== void 0 && ![
90
+ "ask",
91
+ "risk",
92
+ "full"
93
+ ].includes(String(n)) || i !== void 0 && !["default", "plan"].includes(String(i)) || a !== void 0 && !g(a, 4096) ? null : { ...t };
94
+ }
95
+ function ee(e) {
96
+ let t = h(e);
97
+ if (!t || !v(t, l) || t.apiVersion !== n || t.kind !== "ConversationInput" || !g(t.inputId, 256) || !g(t.sessionId, 256) || !g(t.idempotencyKey, 512) || !Array.isArray(t.parts) || t.parts.length === 0 || !_(t.modelRef, 256) || !_(t.reasoning, 64)) return null;
98
+ let r = t.parts.map(y), i = b(t.extensions);
99
+ return r.some((e) => e === null) || i === null ? null : {
100
+ apiVersion: n,
101
+ kind: "ConversationInput",
102
+ inputId: t.inputId,
103
+ sessionId: t.sessionId,
104
+ idempotencyKey: t.idempotencyKey,
105
+ parts: r,
106
+ ...t.modelRef === void 0 ? {} : { modelRef: t.modelRef },
107
+ ...t.reasoning === void 0 ? {} : { reasoning: t.reasoning },
108
+ ...t.extensions === void 0 ? {} : { extensions: i }
109
+ };
110
+ }
111
+ function te(e) {
112
+ let r = ee({
113
+ ...e,
114
+ apiVersion: e.apiVersion || n,
115
+ kind: e.kind || "ConversationInput"
116
+ });
117
+ if (!r) throw new t("conversation_contract_mismatch", "Conversation input does not match conversation.ksadk.io/v1.");
118
+ return r;
119
+ }
120
+ function ne(e) {
121
+ let t = e.parts.map((e) => e.kind === "text" ? "text" : e.mediaType.toLowerCase().startsWith("image/") ? "attachment.image" : "attachment.file");
122
+ e.modelRef && t.push("model.select"), e.reasoning && t.push("reasoning.effort");
123
+ for (let n of Object.keys(e.extensions || {})) n === f ? t.push("approval") : n === p ? e.extensions?.[n] === "plan" && t.push("plan") : n === m ? t.push("goal") : t.push(n);
124
+ return [...new Set(t)];
125
+ }
126
+ function re(e, n) {
127
+ if (e.sessionId !== n.sessionId) throw new t("conversation_session_mismatch", "Conversation input session does not match the active surface.");
128
+ for (let r of ne(n)) if (!ce(e, r)) throw new t("conversation_input_unsupported", "Conversation input is not declared by the active surface.", { capability: r });
129
+ return n;
130
+ }
131
+ function ie(e) {
132
+ let t = h(e);
133
+ return !t || !g(t.name, 128) || !r.test(t.name) || !i.has(t.mode) || !_(t.reason, 512, !0) || (t.mode === "degraded" || t.mode === "unavailable") && !g(t.reason, 512) ? null : {
134
+ name: t.name,
135
+ mode: t.mode,
136
+ ...t.reason === void 0 ? {} : { reason: t.reason }
137
+ };
138
+ }
139
+ function ae(e) {
140
+ if (e === void 0) return [];
141
+ if (!Array.isArray(e)) return null;
142
+ let t = e.map(ie);
143
+ if (t.some((e) => e === null)) return null;
144
+ let n = t;
145
+ return new Set(n.map((e) => e.name)).size === n.length ? n : null;
146
+ }
147
+ function oe(e) {
148
+ let t = h(e);
149
+ if (!t || t.apiVersion !== n || t.kind !== "ConversationSurface" || !g(t.surfaceId, 256) || !g(t.sessionId, 256) || !g(t.providerRef, 256)) return null;
150
+ let r = ae(t.inputs), i = ae(t.outputs);
151
+ return !r || !i ? null : {
152
+ apiVersion: n,
153
+ kind: "ConversationSurface",
154
+ surfaceId: t.surfaceId,
155
+ sessionId: t.sessionId,
156
+ providerRef: t.providerRef,
157
+ inputs: r,
158
+ outputs: i
159
+ };
160
+ }
161
+ function se(e) {
162
+ let t = h(e);
163
+ if (!t || t.apiVersion !== n || t.kindVersion !== 1 || !g(t.itemId, 512) || !_(t.parentItemId, 512) || !Array.isArray(t.sourceEventIds) || t.sourceEventIds.length === 0 || t.sourceEventIds.some((e) => typeof e != "string" || e.length === 0) || new Set(t.sourceEventIds).size !== t.sourceEventIds.length || !g(t.sessionId, 256) || !g(t.runId, 256) || !g(t.kind, 128) || !o.has(t.operation) || !s.has(t.lifecycle) || t.visibility !== void 0 && !c.has(t.visibility) || !g(t.payloadSchemaRef, 256) || !_(t.capabilityRef, 256, !0)) return null;
164
+ let r = t.operation, i = t.lifecycle;
165
+ if (r === "completed" && i !== "completed" && i !== "failed") return null;
166
+ let l = t.payload === void 0 ? {} : h(t.payload), u = t.nativeRef === void 0 ? {} : h(t.nativeRef);
167
+ if (!l || !u) return null;
168
+ let d = String(t.kind || "unknown"), f = a.has(d) ? d : "unknown";
169
+ return {
170
+ apiVersion: n,
171
+ kindVersion: 1,
172
+ itemId: t.itemId,
173
+ ...t.parentItemId === void 0 ? {} : { parentItemId: t.parentItemId },
174
+ sourceEventIds: [...t.sourceEventIds],
175
+ sessionId: t.sessionId,
176
+ runId: t.runId,
177
+ kind: f,
178
+ operation: r,
179
+ lifecycle: i,
180
+ visibility: f === "unknown" && d !== "unknown" ? "hidden" : t.visibility || "public",
181
+ payloadSchemaRef: t.payloadSchemaRef,
182
+ payload: f === "unknown" && d !== "unknown" ? {
183
+ originalKind: d,
184
+ summary: "This content type is not supported by the current renderer."
185
+ } : { ...l },
186
+ ...t.capabilityRef === void 0 ? {} : { capabilityRef: t.capabilityRef },
187
+ nativeRef: { ...u }
188
+ };
189
+ }
190
+ function ce(e, ...t) {
191
+ return e.inputs.some((e) => t.includes(e.name) && (e.mode === "native" || e.mode === "translated"));
192
+ }
193
+ //#endregion
194
+ //#region src/core/conversation/presentation.ts
195
+ var le = {
196
+ user_message: "conversation.item.user_message/v1",
197
+ assistant_text: "conversation.item.assistant_text/v1",
198
+ reasoning: "conversation.item.reasoning/v1",
199
+ tool_call: "conversation.item.tool-call/v1",
200
+ approval: "conversation.item.approval/v1",
201
+ artifact: "conversation.item.artifact/v1",
202
+ a2ui: "conversation.item.a2ui/v1",
203
+ error: "conversation.item.error/v1"
204
+ };
205
+ function x(e) {
206
+ return e.lifecycle === "completed" || e.lifecycle === "failed";
207
+ }
208
+ var ue = new Set([
209
+ "aborted",
210
+ "canceled",
211
+ "cancelled",
212
+ "failed",
213
+ "incomplete",
214
+ "interrupted"
215
+ ]);
216
+ function S(e) {
217
+ if (e.kind !== "progress" && e.kind !== "error" || !x(e)) return;
218
+ let t = typeof e.payload.status == "string" ? e.payload.status.toLowerCase() : "";
219
+ if (t === "completed") return "completed";
220
+ if (ue.has(t)) return "failed";
221
+ }
222
+ function de(e) {
223
+ let t = le[e.kind];
224
+ return t === void 0 || t === e.payloadSchemaRef;
225
+ }
226
+ function fe(e) {
227
+ if (typeof e != "string" || e.length === 0) return null;
228
+ try {
229
+ let t = new URL(e);
230
+ return t.protocol !== "http:" && t.protocol !== "https:" || t.username || t.password ? null : t.toString();
231
+ } catch {
232
+ return null;
233
+ }
234
+ }
235
+ function pe(e) {
236
+ return {
237
+ id: e.itemId,
238
+ parentId: e.parentItemId || null,
239
+ runId: e.runId,
240
+ kind: e.kind,
241
+ text: typeof e.payload.text == "string" ? e.payload.text : "",
242
+ lifecycle: e.lifecycle
243
+ };
244
+ }
245
+ function me(e) {
246
+ return {
247
+ id: e.itemId,
248
+ name: typeof e.payload.name == "string" && e.payload.name ? e.payload.name : "Artifact",
249
+ mimeType: typeof e.payload.mimeType == "string" && e.payload.mimeType ? e.payload.mimeType : "application/octet-stream",
250
+ uri: fe(e.payload.uri)
251
+ };
252
+ }
253
+ function C(e, t) {
254
+ let n = e.payload[t];
255
+ return typeof n == "string" && n ? n : null;
256
+ }
257
+ function he(e) {
258
+ if (e.kind === "tool_call") {
259
+ let t = C(e, "callId");
260
+ if (t) return `tool:${t}`;
261
+ }
262
+ if (e.kind === "approval") {
263
+ let t = C(e, "interactionId");
264
+ if (t) return `approval:${t}`;
265
+ }
266
+ if (e.kind === "a2ui") {
267
+ let t = C(e, "surfaceId");
268
+ if (t) return `a2ui:${t}`;
269
+ }
270
+ return `item:${e.itemId}`;
271
+ }
272
+ function ge(e, t) {
273
+ let n = x(e) && !x(t);
274
+ return {
275
+ ...e,
276
+ ...t,
277
+ itemId: e.itemId,
278
+ parentItemId: e.parentItemId,
279
+ sourceEventIds: [...new Set([...e.sourceEventIds, ...t.sourceEventIds])],
280
+ payload: {
281
+ ...e.payload,
282
+ ...t.payload
283
+ },
284
+ nativeRef: {
285
+ ...e.nativeRef,
286
+ ...t.nativeRef
287
+ },
288
+ ...n ? {
289
+ lifecycle: e.lifecycle,
290
+ operation: e.operation
291
+ } : {}
292
+ };
293
+ }
294
+ function _e(e) {
295
+ let t = [], n = /* @__PURE__ */ new Map();
296
+ for (let r of e) {
297
+ let e = he(r), i = n.get(e);
298
+ if (i === void 0) {
299
+ n.set(e, t.length), t.push({
300
+ key: e,
301
+ item: r,
302
+ sourceItemIds: [r.itemId]
303
+ });
304
+ continue;
305
+ }
306
+ let a = t[i];
307
+ t[i] = {
308
+ key: e,
309
+ item: ge(a.item, r),
310
+ sourceItemIds: [...new Set([...a.sourceItemIds, r.itemId])]
311
+ };
312
+ }
313
+ return t;
314
+ }
315
+ function ve(e, t = {}) {
316
+ let n = e.items.filter((e) => e.visibility === "public" || t.includeInternal === !0 && e.visibility === "internal"), r = n.filter(de), i = n.filter((e) => !de(e)), a = new Set([
317
+ "user_message",
318
+ "assistant_text",
319
+ "reasoning"
320
+ ]), o = r.filter((e) => a.has(e.kind)).map(pe), s = (e) => r.filter((t) => t.kind === e).map((e) => typeof e.payload.text == "string" ? e.payload.text : "").join(""), c = [...r.filter((e) => e.kind === "unknown"), ...i], l = r.filter((e) => e.kind === "error"), u = [...r].reverse().find((e) => S(e) !== void 0);
321
+ return {
322
+ timeline: _e(r.filter((e) => e.kind !== "progress")),
323
+ output: s("assistant_text"),
324
+ reasoning: s("reasoning"),
325
+ textItems: o,
326
+ toolItems: r.filter((e) => e.kind === "tool_call"),
327
+ approvalItems: r.filter((e) => e.kind === "approval"),
328
+ structuredInputItems: r.filter((e) => e.kind === "progress" && e.payloadSchemaRef === "conversation.item.structured-input/v1"),
329
+ a2uiItems: r.filter((e) => e.kind === "a2ui"),
330
+ artifacts: r.filter((e) => e.kind === "artifact").map(me),
331
+ fallbacks: [...c.map((e) => ({
332
+ id: e.itemId,
333
+ title: "Unsupported content",
334
+ detail: String(e.payload.summary || e.payload.originalKind || e.payloadSchemaRef),
335
+ failed: e.lifecycle === "failed"
336
+ })), ...l.map((e) => ({
337
+ id: e.itemId,
338
+ title: "Run failed",
339
+ detail: String(e.payload.error || "The agent run failed."),
340
+ failed: !0
341
+ }))],
342
+ runId: n.at(-1)?.runId || "",
343
+ terminalStatus: u ? S(u) : void 0
344
+ };
345
+ }
346
+ //#endregion
347
+ //#region src/core/conversation/reducer.ts
348
+ function ye() {
349
+ return {
350
+ items: [],
351
+ appliedSources: []
352
+ };
353
+ }
354
+ function be(e) {
355
+ return e.lifecycle === "completed" || e.lifecycle === "failed";
356
+ }
357
+ function xe(e, t) {
358
+ let n = {
359
+ ...e,
360
+ ...t
361
+ };
362
+ typeof e.text == "string" && typeof t.text == "string" && (n.text = e.text + t.text);
363
+ for (let r of ["data", "operations"]) Array.isArray(e[r]) && Array.isArray(t[r]) && (n[r] = [...e[r], ...t[r]]);
364
+ return n;
365
+ }
366
+ function Se(e, t) {
367
+ let n = t.sourceEventIds.map((e) => JSON.stringify([t.itemId, e])), r = new Set(e.appliedSources);
368
+ if (n.every((e) => r.has(e))) return e;
369
+ n.forEach((e) => r.add(e));
370
+ let i = e.items.findIndex((e) => e.itemId === t.itemId), a = i >= 0 ? e.items[i] : void 0;
371
+ if (a && be(a) && !be(t)) return {
372
+ ...e,
373
+ appliedSources: [...r]
374
+ };
375
+ let o = [...e.items];
376
+ if (!a) o.push(t);
377
+ else {
378
+ let e = [...new Set([...a.sourceEventIds, ...t.sourceEventIds])];
379
+ a.kind === t.kind ? t.operation === "append" ? o[i] = {
380
+ ...t,
381
+ payload: xe(a.payload, t.payload),
382
+ sourceEventIds: e
383
+ } : o[i] = {
384
+ ...t,
385
+ sourceEventIds: e
386
+ } : o[i] = {
387
+ ...t,
388
+ kind: "unknown",
389
+ operation: "replace",
390
+ payloadSchemaRef: "conversation.item.unknown/v1",
391
+ payload: { summary: "The content type changed for the same item and was safely degraded." },
392
+ sourceEventIds: e
393
+ };
394
+ }
395
+ return {
396
+ items: o,
397
+ appliedSources: [...r]
398
+ };
399
+ }
400
+ var Ce = class {
401
+ state = ye();
402
+ apply(e) {
403
+ let t = Se(this.state, e);
404
+ if (t === this.state) return !1;
405
+ let n = t.items !== this.state.items;
406
+ return this.state = t, n;
407
+ }
408
+ applyAll(e) {
409
+ for (let t of e) this.apply(t);
410
+ }
411
+ snapshot() {
412
+ return {
413
+ items: this.state.items.map((e) => ({
414
+ ...e,
415
+ sourceEventIds: [...e.sourceEventIds],
416
+ payload: { ...e.payload },
417
+ nativeRef: { ...e.nativeRef }
418
+ })),
419
+ appliedSources: [...this.state.appliedSources]
420
+ };
421
+ }
422
+ }, w = 8;
423
+ function T(e) {
424
+ return typeof e == "object" && e && !Array.isArray(e) ? e : null;
425
+ }
426
+ function E(e) {
427
+ if (e?.aborted) throw new t("conversation_aborted", "Conversation request was aborted.");
428
+ }
429
+ function we(e, t) {
430
+ return t?.aborted === !0 || e instanceof Error && e.name === "AbortError";
431
+ }
432
+ function Te(e) {
433
+ let n = e.trim().replace(/\/+$/, "");
434
+ if (!n) return "";
435
+ if (!n.includes("://")) return n.startsWith("/") ? n : `/${n}`;
436
+ try {
437
+ let e = new URL(n);
438
+ if (e.protocol !== "http:" && e.protocol !== "https:" || e.username || e.password) throw Error("unsafe URL");
439
+ return e.toString().replace(/\/$/, "");
440
+ } catch (e) {
441
+ throw new t("conversation_contract_mismatch", "Conversation base URL must be an HTTP(S) URL without embedded credentials.", { cause: e });
442
+ }
443
+ }
444
+ function Ee(e) {
445
+ return Math.min(200 * 2 ** Math.max(0, e - 1), 2e3);
446
+ }
447
+ function De(e) {
448
+ return new Promise((t) => {
449
+ setTimeout(t, e);
450
+ });
451
+ }
452
+ async function Oe(e, n, r) {
453
+ if (E(r), !r) {
454
+ await e(n);
455
+ return;
456
+ }
457
+ await new Promise((i, a) => {
458
+ let o = () => a(new t("conversation_aborted", "Conversation request was aborted."));
459
+ r.addEventListener("abort", o, { once: !0 }), e(n).then(i, a).finally(() => {
460
+ r.removeEventListener("abort", o);
461
+ });
462
+ });
463
+ }
464
+ function D(e, t, n) {
465
+ let r = e.snapshot();
466
+ return {
467
+ cursor: t,
468
+ runId: n,
469
+ state: r,
470
+ presentation: ve(r)
471
+ };
472
+ }
473
+ function ke(e, n) {
474
+ let r, i = [];
475
+ for (let n of e.split(/\r?\n/)) {
476
+ let e = n.endsWith("\r") ? n.slice(0, -1) : n;
477
+ if (!e || e.startsWith(":")) continue;
478
+ let a = e.indexOf(":"), o = a < 0 ? e : e.slice(0, a), s = a < 0 ? "" : e.slice(a + 1), c = s.startsWith(" ") ? s.slice(1) : s;
479
+ if (o === "id") {
480
+ if (!/^\d+$/.test(c) || !Number.isSafeInteger(Number(c))) throw new t("conversation_stream_error", "Conversation stream contains an invalid replay cursor.");
481
+ r = Number(c);
482
+ } else o === "data" && i.push(c);
483
+ }
484
+ if (i.length === 0) return;
485
+ let a = i.join("\n");
486
+ if (!a || a === "[DONE]") return;
487
+ let o;
488
+ try {
489
+ o = JSON.parse(a);
490
+ } catch (e) {
491
+ throw new t("conversation_contract_mismatch", "Conversation stream contains invalid JSON.", { cause: e });
492
+ }
493
+ let s = T(o);
494
+ if (!s || s.conversationItem === void 0) {
495
+ r !== void 0 && (n.cursor = Math.max(n.cursor, r));
496
+ return;
497
+ }
498
+ if (r === void 0) throw new t("conversation_stream_error", "Canonical conversation items require an SSE replay cursor.");
499
+ let c = se(s.conversationItem);
500
+ if (!c) throw new t("conversation_contract_mismatch", "Conversation stream item does not match conversation.ksadk.io/v1.");
501
+ if (n.runId && n.runId !== c.runId) throw new t("conversation_contract_mismatch", "Conversation stream changed canonical run identity.", {
502
+ runId: n.runId,
503
+ cursor: n.cursor
504
+ });
505
+ n.runId = c.runId;
506
+ let l = n.reducer.apply(c);
507
+ n.cursor = Math.max(n.cursor, r), l && n.options.onItem?.(c), n.options.onUpdate?.(D(n.reducer, n.cursor, n.runId));
508
+ }
509
+ async function Ae(e, n) {
510
+ if (!e.body) throw new t("conversation_stream_error", "Conversation response has no event stream body.");
511
+ let r = e.body.getReader(), i = new TextDecoder(), a = "";
512
+ try {
513
+ for (;;) {
514
+ E(n.options.signal);
515
+ let { value: e, done: t } = await r.read();
516
+ if (t) break;
517
+ a += i.decode(e, { stream: !0 });
518
+ let o = /\r?\n\r?\n/.exec(a);
519
+ for (; o?.index !== void 0;) {
520
+ let e = o.index, t = o[0].length;
521
+ ke(a.slice(0, e), n), a = a.slice(e + t), o = /\r?\n\r?\n/.exec(a);
522
+ }
523
+ }
524
+ a += i.decode(), a.trim() && ke(a, n);
525
+ } catch (e) {
526
+ throw e instanceof t ? e : (we(e, n.options.signal) && E(n.options.signal), new t("conversation_stream_error", "Conversation event stream was interrupted.", {
527
+ cause: e,
528
+ runId: n.runId || void 0,
529
+ cursor: n.cursor
530
+ }));
531
+ } finally {
532
+ r.releaseLock();
533
+ }
534
+ }
535
+ function je(e) {
536
+ return e.state.items.some((e) => S(e) !== void 0);
537
+ }
538
+ var Me = class {
539
+ fetcher;
540
+ baseUrl;
541
+ maxReconnects;
542
+ sleep;
543
+ retryDelayMs;
544
+ constructor(e = {}) {
545
+ if (!Number.isInteger(e.maxReconnects ?? w) || (e.maxReconnects ?? w) < 0 || (e.maxReconnects ?? w) > 32) throw new t("conversation_contract_mismatch", "Conversation reconnect limit must be an integer from 0 to 32.");
546
+ this.fetcher = e.fetch, this.baseUrl = Te(e.baseUrl || ""), this.maxReconnects = e.maxReconnects ?? w, this.sleep = e.sleep || De, this.retryDelayMs = e.retryDelayMs || Ee;
547
+ }
548
+ fetch() {
549
+ if (this.fetcher) return this.fetcher;
550
+ if (typeof globalThis.fetch == "function") return globalThis.fetch.bind(globalThis);
551
+ throw new t("conversation_http_error", "No fetch implementation is available for the conversation client.");
552
+ }
553
+ url(e) {
554
+ return `${this.baseUrl}${e}`;
555
+ }
556
+ async request(e, n, r, i = "conversation_stream_error") {
557
+ E(r);
558
+ try {
559
+ return await this.fetch()(e, n);
560
+ } catch (e) {
561
+ throw e instanceof t ? e : (we(e, r) && E(r), new t(i, "Conversation network request failed.", { cause: e }));
562
+ }
563
+ }
564
+ assertOk(e) {
565
+ if (!e.ok) throw new t("conversation_http_error", `Conversation endpoint returned HTTP ${e.status}.`, { status: e.status });
566
+ }
567
+ async getSurface(e, n, r = {}) {
568
+ if (!e || !n) throw new t("conversation_contract_mismatch", "Agent and session identities are required to get a conversation surface.");
569
+ let i = r.signal ? { signal: r.signal } : void 0, a = await this.request(this.url(`/api/v1/agents/${encodeURIComponent(e)}/conversation-surface?sessionId=${encodeURIComponent(n)}`), i, r.signal, "conversation_http_error");
570
+ this.assertOk(a);
571
+ let o;
572
+ try {
573
+ o = await a.json();
574
+ } catch (e) {
575
+ throw new t("conversation_contract_mismatch", "Conversation surface response is not valid JSON.", { cause: e });
576
+ }
577
+ let s = T(o), c = oe(s?.surface);
578
+ if (!s || typeof s.buildId != "string" || !s.buildId || !c) throw new t("conversation_contract_mismatch", "Conversation surface response does not match conversation.ksadk.io/v1.");
579
+ return {
580
+ buildId: s.buildId,
581
+ surface: c
582
+ };
583
+ }
584
+ async streamTurn(e) {
585
+ E(e.signal), re(e.bootstrap.surface, e.input);
586
+ let n = {
587
+ cursor: 0,
588
+ runId: "",
589
+ reducer: new Ce(),
590
+ options: e
591
+ }, r = {
592
+ method: "POST",
593
+ headers: {
594
+ "Content-Type": "application/json",
595
+ "Idempotency-Key": e.input.idempotencyKey
596
+ },
597
+ body: JSON.stringify({ input: e.input }),
598
+ ...e.signal ? { signal: e.signal } : {}
599
+ }, i = await this.request(this.url(`/api/v1/builds/${encodeURIComponent(e.bootstrap.buildId)}/conversation:stream`), r, e.signal);
600
+ this.assertOk(i);
601
+ try {
602
+ await Ae(i, n);
603
+ } catch (e) {
604
+ if (!(e instanceof t) || e.code !== "conversation_stream_error" || !n.runId) throw e;
605
+ }
606
+ let a = D(n.reducer, n.cursor, n.runId);
607
+ if (je(a)) return a;
608
+ if (!n.runId) throw new t("conversation_run_identity_missing", "The stream ended before a canonical item supplied its run identity.", { cursor: n.cursor });
609
+ for (let r = 1; r <= this.maxReconnects; r += 1) {
610
+ await Oe(this.sleep, this.retryDelayMs(r), e.signal), E(e.signal);
611
+ let i;
612
+ try {
613
+ i = await this.request(this.url(`/api/v1/runs/${encodeURIComponent(n.runId)}/events?after=${n.cursor}`), {
614
+ method: "GET",
615
+ headers: { "Last-Event-ID": String(n.cursor) },
616
+ ...e.signal ? { signal: e.signal } : {}
617
+ }, e.signal), this.assertOk(i), await Ae(i, n);
618
+ } catch (e) {
619
+ if (e instanceof t && e.code === "conversation_aborted" || e instanceof t && e.code === "conversation_contract_mismatch" || e instanceof t && e.code === "conversation_http_error" && e.status !== void 0 && e.status < 500) throw e;
620
+ continue;
621
+ }
622
+ if (a = D(n.reducer, n.cursor, n.runId), je(a)) return a;
623
+ }
624
+ throw new t("conversation_reconnect_exhausted", "Conversation replay stopped after the configured reconnect limit.", {
625
+ runId: n.runId,
626
+ cursor: n.cursor
627
+ });
628
+ }
629
+ }, Ne = 0;
630
+ function O(e) {
631
+ return Ne += 1, `${e}-${Ne}`;
632
+ }
633
+ function k(e) {
634
+ return e.map((e) => e.type === "thinking" && e.status === "streaming" ? {
635
+ ...e,
636
+ status: "done"
637
+ } : e);
638
+ }
639
+ function Pe(e, t) {
640
+ let n = [...e ?? []], r = n[n.length - 1];
641
+ return r?.type === "thinking" && r.status === "streaming" ? (n[n.length - 1] = {
642
+ ...r,
643
+ content: r.content + t
644
+ }, n) : [...n, {
645
+ id: O("thinking"),
646
+ type: "thinking",
647
+ content: t,
648
+ status: "streaming"
649
+ }];
650
+ }
651
+ function Fe(e, t) {
652
+ let n = [...k(e ?? [])], r = n[n.length - 1];
653
+ return r?.type === "text" && r.status === "streaming" ? (n[n.length - 1] = {
654
+ ...r,
655
+ content: r.content + t
656
+ }, n) : [...n, {
657
+ id: O("text"),
658
+ type: "text",
659
+ content: t,
660
+ status: "streaming"
661
+ }];
662
+ }
663
+ function Ie(e, t) {
664
+ let n = k(e ?? []);
665
+ if (n.filter((e) => e.type === "text").map((e) => e.content).join("") === t) return n.map((e) => e.type === "text" && e.status === "streaming" ? {
666
+ ...e,
667
+ status: "done"
668
+ } : e);
669
+ let r = [...n], i = r.map((e) => e.type).lastIndexOf("text");
670
+ return i >= 0 && r[i].type === "text" ? (r[i] = {
671
+ ...r[i],
672
+ content: t,
673
+ status: "done"
674
+ }, r) : [...r, {
675
+ id: O("text"),
676
+ type: "text",
677
+ content: t,
678
+ status: "done"
679
+ }];
680
+ }
681
+ function Le(e, t) {
682
+ if (!t) return [...e ?? []];
683
+ let n = [...e ?? []], r = n[n.length - 1];
684
+ if (r?.type !== "thinking" || !r.content.endsWith(t)) return n;
685
+ let i = r.content.slice(0, -t.length);
686
+ return i ? (n[n.length - 1] = {
687
+ ...r,
688
+ content: i
689
+ }, n) : (n.pop(), n);
690
+ }
691
+ function Re(e, t, n) {
692
+ let r = [...k(e ?? [])], i = r.findIndex((e) => e.type === "tool" && e.toolName === t);
693
+ if (i >= 0 && r[i].type === "tool") {
694
+ 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);
695
+ if (t && !a && !o) return r;
696
+ let s = n.extra ?? e.extra;
697
+ return r[i] = {
698
+ ...e,
699
+ ...n,
700
+ extra: s
701
+ }, r;
702
+ }
703
+ return [...r, {
704
+ id: O("tool"),
705
+ type: "tool",
706
+ toolName: t,
707
+ args: n.args ?? "",
708
+ output: n.output,
709
+ status: n.status ?? "running",
710
+ extra: n.extra
711
+ }];
712
+ }
713
+ function ze(e) {
714
+ return k(e ?? []);
715
+ }
716
+ function Be(e) {
717
+ let t = [];
718
+ if (e.reasoning && e.reasoning.trim() && t.push({
719
+ id: O("thinking"),
720
+ type: "thinking",
721
+ content: e.reasoning,
722
+ status: "done"
723
+ }), e.tools) for (let n of Object.values(e.tools)) t.push({
724
+ id: O("tool"),
725
+ type: "tool",
726
+ toolName: n.name,
727
+ args: n.args ?? "",
728
+ output: n.output,
729
+ status: n.status ?? "completed",
730
+ ...n.callId ? { extra: { callId: n.callId } } : {}
731
+ });
732
+ return e.content && e.content.trim() && t.push({
733
+ id: O("text"),
734
+ type: "text",
735
+ content: e.content,
736
+ status: "done"
737
+ }), t;
738
+ }
739
+ //#endregion
740
+ //#region src/core/stream/kernel-events.ts
741
+ var Ve = {
742
+ "run.started": "in_progress",
743
+ "run.progress": "in_progress",
744
+ "run.completed": "completed",
745
+ "run.failed": "failed",
746
+ "run.canceled": "cancelled",
747
+ "run.interrupted": "interrupted"
748
+ }, He = new Set([
749
+ "completed",
750
+ "failed",
751
+ "cancelled",
752
+ "canceled"
753
+ ]);
754
+ function A(e) {
755
+ return typeof e == "object" && e && !Array.isArray(e) ? e : null;
756
+ }
757
+ function Ue(e) {
758
+ let t = A(e.source), n = t ? A(t.metadata) : null;
759
+ return String(n?.native_item_kind || "");
760
+ }
761
+ function j(e, t) {
762
+ let n = A(e[t]);
763
+ if (!n) return [];
764
+ let r = n?.parts;
765
+ return Array.isArray(r) ? r : t === "update" ? [n] : [];
766
+ }
767
+ function We(e) {
768
+ let t = A(e);
769
+ if (!t) return "";
770
+ if (typeof t.text == "string") return t.text;
771
+ let n = A(t.data);
772
+ if (n) {
773
+ let e = n.content;
774
+ if (Array.isArray(e)) return e.map((e) => String(A(e)?.text || "")).join("");
775
+ for (let e of [
776
+ "text",
777
+ "output",
778
+ "stdout",
779
+ "stderr"
780
+ ]) if (n[e] != null) return String(n[e]);
781
+ }
782
+ return "";
783
+ }
784
+ function M(e) {
785
+ return e.map(We).join("");
786
+ }
787
+ function Ge(e) {
788
+ return e.some((e) => A(A(e)?.data)?.type === "userMessage");
789
+ }
790
+ function N(e) {
791
+ if (e.length === 1) {
792
+ let t = A(A(e[0])?.data);
793
+ if (t) return t;
794
+ }
795
+ return M(e) || null;
796
+ }
797
+ function P(e) {
798
+ let t = A(e);
799
+ return t ? A(t.data) || t : null;
800
+ }
801
+ function F(e) {
802
+ let t = P(e);
803
+ return String(t?.content_type || t?.type || "").trim().toLowerCase();
804
+ }
805
+ function I(e) {
806
+ for (let t of e) {
807
+ let e = P(t);
808
+ if (!e || F(t) !== "tool_call") continue;
809
+ let n = String(e.call_id || "").trim(), r = String(e.name || e.tool_name || "").trim();
810
+ if (!(!n && !r)) return {
811
+ callId: n,
812
+ name: r,
813
+ arguments: e.arguments ?? e.args ?? {}
814
+ };
815
+ }
816
+ return null;
817
+ }
818
+ function L(e) {
819
+ for (let t of e) {
820
+ let e = P(t);
821
+ if (!e || F(t) !== "tool_result") continue;
822
+ let n = String(e.call_id || e.tool_call_id || "").trim(), r = e.is_error === !0 || e.error != null;
823
+ return {
824
+ callId: n,
825
+ result: e.result ?? e.output ?? e.error ?? null,
826
+ isError: r
827
+ };
828
+ }
829
+ return null;
830
+ }
831
+ function R(e, t, n, r) {
832
+ let i = String(e.item_id || ""), a = String(r || i);
833
+ return { RuntimeItem: {
834
+ RunId: String(e.run_id || ""),
835
+ ScopeId: String(e.scope_id || e.run_id || ""),
836
+ ItemId: a,
837
+ ...n ? { PartId: n } : {},
838
+ Operation: t,
839
+ SourceEventId: String(e.event_id || ""),
840
+ ...i && i !== a ? { SourceItemId: i } : {}
841
+ } };
842
+ }
843
+ var Ke = class {
844
+ textByPart = /* @__PURE__ */ new Map();
845
+ toolNameByCallId = /* @__PURE__ */ new Map();
846
+ toolCallByItemId = /* @__PURE__ */ new Map();
847
+ toolResultByItemId = /* @__PURE__ */ new Map();
848
+ sessionId;
849
+ constructor(e) {
850
+ this.sessionId = e;
851
+ }
852
+ translate(e) {
853
+ if (!A(e)) return null;
854
+ let t = Number(e.seq);
855
+ if (!Number.isFinite(t) || t <= 0) return null;
856
+ let n = String(e.family || ""), r = String(e.event_type || ""), i = String(e.run_id || ""), a = () => ({
857
+ EventId: e.event_id ? String(e.event_id) : `kernel-${t}`,
858
+ SessionId: this.sessionId,
859
+ InvocationId: i || void 0,
860
+ SeqId: t
861
+ });
862
+ if (n === "interaction") return {
863
+ ...a(),
864
+ EventType: r,
865
+ payload: e
866
+ };
867
+ if (n === "control") {
868
+ if (r === "control.run_transition") {
869
+ let t = String(e.state || "").toLowerCase();
870
+ if (He.has(t)) return {
871
+ ...a(),
872
+ EventType: "run_status",
873
+ Content: { status: t }
874
+ };
875
+ }
876
+ return null;
877
+ }
878
+ if (n !== "runtime") return null;
879
+ let o = Ve[r];
880
+ if (o) return {
881
+ ...a(),
882
+ EventType: "run_status",
883
+ Content: { status: o }
884
+ };
885
+ let s = Ue(e);
886
+ if (r === "item.started") {
887
+ let t = j(e, "initial");
888
+ if (e.item_kind === "tool_call") {
889
+ let n = I(t), r = n?.callId || String(e.item_id || ""), o = n?.name || "tool";
890
+ return r && this.toolNameByCallId.set(r, o), e.item_id && this.toolCallByItemId.set(String(e.item_id), {
891
+ callId: r,
892
+ name: o
893
+ }), {
894
+ ...a(),
895
+ EventType: "tool_call",
896
+ Metadata: {
897
+ ...R(e, "replace", void 0, r),
898
+ call_id: r,
899
+ tool_name: o,
900
+ run_id: i,
901
+ tool_args: n?.arguments ?? N(t)
902
+ }
903
+ };
904
+ }
905
+ return e.item_kind === "tool_result" || s === "userMessage" || Ge(t) || s === "reasoning" || e.item_kind === "reasoning" ? null : s === "agentMessage" || !s && e.item_kind === "message" ? {
906
+ ...a(),
907
+ EventType: "assistant_stream_snapshot",
908
+ Content: { parts: [{ text: "" }] },
909
+ Metadata: R(e, "replace")
910
+ } : s && s !== "notification" ? {
911
+ ...a(),
912
+ EventType: "tool_call",
913
+ Metadata: {
914
+ ...R(e, "replace"),
915
+ call_id: String(e.item_id || ""),
916
+ tool_name: s,
917
+ run_id: i,
918
+ tool_args: N(t)
919
+ }
920
+ } : null;
921
+ }
922
+ if (r === "item.updated") {
923
+ let n = j(e, "update");
924
+ if (e.item_kind === "tool_call") {
925
+ let t = L(n);
926
+ if (!t) return null;
927
+ 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;
928
+ return e.item_id && this.toolResultByItemId.set(String(e.item_id), c), {
929
+ ...a(),
930
+ EventType: "tool_result",
931
+ Metadata: {
932
+ ...R(e, "completed", void 0, o),
933
+ call_id: o,
934
+ tool_name: s,
935
+ run_id: i,
936
+ tool_output: c
937
+ }
938
+ };
939
+ }
940
+ let r = A(n[0]), o = String(r?.part_id || e.item_id || t), c = String(e.op || "replace"), l = M(n), u = this.textByPart.get(o) || "", d = c === "append" ? u + l : l;
941
+ return this.textByPart.set(o, d), s === "agentMessage" || !s && e.item_kind === "message" ? {
942
+ ...a(),
943
+ EventType: "assistant_stream_snapshot",
944
+ Content: { parts: [{ text: d }] },
945
+ Metadata: R(e, "replace", o)
946
+ } : s === "reasoning" || e.item_kind === "reasoning" ? {
947
+ ...a(),
948
+ EventType: "reasoning",
949
+ Content: { parts: [{ text: l }] },
950
+ Metadata: R(e, c === "append" ? "append" : "replace", o)
951
+ } : null;
952
+ }
953
+ if (r === "item.snapshot_replaced") {
954
+ let n = j(e, "snapshot"), r = String(A(n[0])?.part_id || e.item_id || t), i = M(n);
955
+ return this.textByPart.set(r, i), s === "agentMessage" || !s && e.item_kind === "message" ? {
956
+ ...a(),
957
+ EventType: "assistant_stream_snapshot",
958
+ Content: { parts: [{ text: i }] },
959
+ Metadata: R(e, "replace", r)
960
+ } : s === "reasoning" || e.item_kind === "reasoning" ? {
961
+ ...a(),
962
+ EventType: "reasoning",
963
+ Content: { parts: [{ text: i }] },
964
+ Metadata: R(e, "replace", r)
965
+ } : null;
966
+ }
967
+ if (r === "item.completed") {
968
+ let n = j(e, "snapshot");
969
+ if (e.item_kind === "tool_call") {
970
+ let t = I(n), r = L(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";
971
+ if (s && this.toolNameByCallId.set(s, c), r) {
972
+ let t = r.isError ? { error: r.result } : r.result;
973
+ return {
974
+ ...a(),
975
+ EventType: "tool_result",
976
+ Metadata: {
977
+ ...R(e, "completed", void 0, s),
978
+ call_id: s,
979
+ tool_name: c,
980
+ run_id: i,
981
+ tool_output: t
982
+ }
983
+ };
984
+ }
985
+ return {
986
+ ...a(),
987
+ EventType: "tool_call",
988
+ Metadata: {
989
+ ...R(e, "replace", void 0, s),
990
+ call_id: s,
991
+ tool_name: c,
992
+ run_id: i,
993
+ tool_args: t?.arguments ?? N(n)
994
+ }
995
+ };
996
+ }
997
+ if (e.item_kind === "tool_result") {
998
+ let t = L(n), r = t?.callId || String(e.item_id || ""), o = this.toolNameByCallId.get(r) || s || "tool", c = t?.isError ? { error: t.result } : t?.result ?? N(n);
999
+ return {
1000
+ ...a(),
1001
+ EventType: "tool_result",
1002
+ Metadata: {
1003
+ ...R(e, "completed", void 0, r),
1004
+ call_id: r,
1005
+ tool_name: o,
1006
+ run_id: i,
1007
+ tool_output: c
1008
+ }
1009
+ };
1010
+ }
1011
+ if (s === "userMessage" || Ge(n)) return {
1012
+ ...a(),
1013
+ EventType: "user_message",
1014
+ Content: { parts: [{ text: M(n) }] }
1015
+ };
1016
+ if (s === "agentMessage" || !s && e.item_kind === "message") {
1017
+ let r = M(n), i = String(A(n[0])?.part_id || e.item_id || t);
1018
+ return this.textByPart.set(i, r), {
1019
+ ...a(),
1020
+ EventType: "assistant_message",
1021
+ Content: { parts: [{ text: r }] },
1022
+ Metadata: R(e, "completed", i)
1023
+ };
1024
+ }
1025
+ if (s === "reasoning" || e.item_kind === "reasoning") {
1026
+ let r = String(A(n[0])?.part_id || e.item_id || t);
1027
+ return {
1028
+ ...a(),
1029
+ EventType: "reasoning",
1030
+ Content: { parts: [{ text: M(n) }] },
1031
+ Metadata: R(e, "completed", r)
1032
+ };
1033
+ }
1034
+ return s && s !== "notification" ? {
1035
+ ...a(),
1036
+ EventType: "tool_result",
1037
+ Metadata: {
1038
+ ...R(e, "completed"),
1039
+ call_id: String(e.item_id || ""),
1040
+ tool_name: s,
1041
+ run_id: i,
1042
+ tool_output: N(n)
1043
+ }
1044
+ } : null;
1045
+ }
1046
+ if (r === "item.failed") {
1047
+ if (e.item_kind === "tool_call") {
1048
+ let t = this.toolCallByItemId.get(String(e.item_id || "")), n = t?.callId || String(e.item_id || ""), r = t?.name || this.toolNameByCallId.get(n) || "tool", o = this.toolResultByItemId.get(String(e.item_id || ""));
1049
+ return {
1050
+ ...a(),
1051
+ EventType: "tool_result",
1052
+ Metadata: {
1053
+ ...R(e, "completed", void 0, n),
1054
+ call_id: n,
1055
+ tool_name: r,
1056
+ run_id: i,
1057
+ tool_output: o ?? { error: A(e.error) || e.error || "item failed" }
1058
+ }
1059
+ };
1060
+ }
1061
+ return s && s !== "notification" && s !== "agentMessage" && s !== "reasoning" ? {
1062
+ ...a(),
1063
+ EventType: "tool_result",
1064
+ Metadata: {
1065
+ ...R(e, "completed"),
1066
+ call_id: String(e.item_id || ""),
1067
+ tool_name: s,
1068
+ run_id: i,
1069
+ tool_output: { error: A(e.error) || e.error || "item failed" }
1070
+ }
1071
+ } : null;
1072
+ }
1073
+ return null;
1074
+ }
1075
+ };
1076
+ async function qe(e) {
1077
+ let t = e.getReader(), n = new TextDecoder(), r = "", i = null, a = !1, o = (e) => e.includes("data:") || e.includes("event:") || e.includes(":");
1078
+ try {
1079
+ for (;;) {
1080
+ let { value: e, done: s } = await t.read();
1081
+ if (e && (r += n.decode(e, { stream: !0 })), s) {
1082
+ a = !0;
1083
+ break;
1084
+ }
1085
+ if (r.trimStart().startsWith("{")) {
1086
+ if (Je(r)) {
1087
+ i = Ye(r);
1088
+ break;
1089
+ }
1090
+ } else if (o(r)) break;
1091
+ }
1092
+ } catch {}
1093
+ let s = new TextEncoder().encode(r), c = new ReadableStream({
1094
+ start(e) {
1095
+ if (s.length > 0 && e.enqueue(s), a || i) {
1096
+ e.close();
1097
+ return;
1098
+ }
1099
+ let n = () => t.read().then(({ value: t, done: r }) => {
1100
+ if (t && e.enqueue(t), r) {
1101
+ e.close();
1102
+ return;
1103
+ }
1104
+ return n();
1105
+ }).catch(() => {
1106
+ try {
1107
+ e.close();
1108
+ } catch {}
1109
+ });
1110
+ n();
1111
+ },
1112
+ cancel() {
1113
+ t.cancel();
1114
+ }
1115
+ });
1116
+ return {
1117
+ receipt: i,
1118
+ stream: c
1119
+ };
1120
+ }
1121
+ function Je(e) {
1122
+ let t = e.trim();
1123
+ if (!t.endsWith("}")) return !1;
1124
+ let n = 0, r = !1, i = !1;
1125
+ for (let e of t) {
1126
+ if (i) {
1127
+ i = !1;
1128
+ continue;
1129
+ }
1130
+ if (e === "\\") {
1131
+ i = !0;
1132
+ continue;
1133
+ }
1134
+ e === "\"" && (r = !r), !r && ((e === "{" || e === "[") && (n += 1), (e === "}" || e === "]") && --n);
1135
+ }
1136
+ return n === 0;
1137
+ }
1138
+ function Ye(e) {
1139
+ try {
1140
+ let t = A(JSON.parse(e).Data), n = String(t?.ReceiptStatus || "");
1141
+ if (!n) return null;
1142
+ let r = A(t?.Error);
1143
+ return {
1144
+ status: n,
1145
+ messageId: t?.MessageId ?? null,
1146
+ runId: t?.RunId ?? null,
1147
+ acceptedSeq: t?.AcceptedSeq ?? null,
1148
+ error: r ? {
1149
+ code: String(r.code || ""),
1150
+ message: String(r.message || "")
1151
+ } : null
1152
+ };
1153
+ } catch {
1154
+ return null;
1155
+ }
1156
+ }
1157
+ //#endregion
1158
+ //#region src/utils/responses-stream.js
1159
+ function Xe() {
1160
+ return {
1161
+ toolNames: /* @__PURE__ */ new Map(),
1162
+ toolArguments: /* @__PURE__ */ new Map(),
1163
+ callIds: /* @__PURE__ */ new Map(),
1164
+ currentResponseId: "",
1165
+ sawTextDelta: !1,
1166
+ sawReasoningDelta: !1
1167
+ };
1168
+ }
1169
+ function Ze(e) {
1170
+ 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 : "";
1171
+ }
1172
+ function z(e) {
1173
+ return e == null ? "" : typeof e == "string" ? e : typeof e == "object" ? JSON.stringify(e, null, 2) : String(e);
1174
+ }
1175
+ function B(...e) {
1176
+ for (let t of e) {
1177
+ let e = Ze(t);
1178
+ if (e) return e;
1179
+ }
1180
+ return "";
1181
+ }
1182
+ function Qe(e, t) {
1183
+ return String(e?.id || e?.item_id || e?.call_id || t?.item_id || t?.call_id || t?.output_index || "");
1184
+ }
1185
+ function $e(e, t, n, r, i) {
1186
+ t && (e.toolNames.set(t, r), e.toolArguments.set(t, i));
1187
+ let a = String(n?.call_id || "");
1188
+ a && (e.callIds.set(a, t || r), e.toolNames.set(a, r), e.toolArguments.set(a, i));
1189
+ }
1190
+ function V(e, t, n, r = "tool") {
1191
+ let i = String(n?.call_id || "");
1192
+ return String(n?.name || n?.tool_name || (t ? e.toolNames.get(t) : "") || (i ? e.toolNames.get(i) : "") || r);
1193
+ }
1194
+ function H(e) {
1195
+ if (!e || typeof e != "object") return "";
1196
+ let t = Ze(e.content);
1197
+ return B(e.output_text, e.text, e.summary_text, e.summary, e.delta, t);
1198
+ }
1199
+ function et(e) {
1200
+ let t = e?.response && typeof e.response == "object" ? e.response : e, n = B(t?.output_text, t?.text);
1201
+ if (n) return n;
1202
+ let r = Array.isArray(t?.output) ? t.output : [];
1203
+ for (let e of r) {
1204
+ let t = H(e);
1205
+ if (t) return t;
1206
+ }
1207
+ return "";
1208
+ }
1209
+ function tt(e) {
1210
+ let t = e?.response && typeof e.response == "object" ? e.response : e;
1211
+ return Array.isArray(t?.output) ? t.output : [];
1212
+ }
1213
+ function nt(e) {
1214
+ let t = e;
1215
+ if (typeof t == "string") try {
1216
+ t = JSON.parse(t);
1217
+ } catch {
1218
+ return {};
1219
+ }
1220
+ return Array.isArray(t) && (t = t[0] || {}), !t || typeof t != "object" ? {} : t.value && typeof t.value == "object" && !Array.isArray(t.value) ? {
1221
+ ...t.value,
1222
+ approval_request_id: t.value.approval_request_id || t.value.id || t.id
1223
+ } : t;
1224
+ }
1225
+ function U({ data: e, state: t, status: n }) {
1226
+ let r = e?.item || e?.output_item || e || {}, i = String(r.type || "").trim(), a = Qe(r, e);
1227
+ if (i === "function_call") {
1228
+ let e = V(t, a, r), i = z(r.arguments ?? r.args ?? r.input);
1229
+ return $e(t, a, r, e, i), [{
1230
+ type: "tool_upsert",
1231
+ name: e,
1232
+ args: i,
1233
+ status: n
1234
+ }];
1235
+ }
1236
+ if (i === "function_call_output") return [{
1237
+ type: "tool_result",
1238
+ name: V(t, a, r),
1239
+ output: z(r.output ?? r.result ?? r.content)
1240
+ }];
1241
+ if (i === "mcp_approval_request") {
1242
+ let n = String(r.name || "approval"), i = z(r.arguments ?? r.args), a = String(r.id || r.approval_request_id || ""), o = String(r.run_id || r.runId || e?.run_id || e?.runId || "");
1243
+ return [{
1244
+ type: "tool_upsert",
1245
+ name: n,
1246
+ args: i,
1247
+ status: "paused",
1248
+ approvalRequestId: a,
1249
+ previousResponseId: String(e?.response_id || t.currentResponseId || ""),
1250
+ serverLabel: String(r.server_label || "")
1251
+ }, {
1252
+ type: "approval_request",
1253
+ approvalRequestId: a,
1254
+ previousResponseId: String(e?.response_id || t.currentResponseId || ""),
1255
+ ...o ? { runId: o } : {},
1256
+ name: n,
1257
+ args: i
1258
+ }];
1259
+ }
1260
+ if (i === "reasoning" || i === "reasoning_summary" || i === "reasoning_summary_text") {
1261
+ let e = H(r);
1262
+ return e ? [{
1263
+ type: "reasoning_delta",
1264
+ text: e
1265
+ }] : [];
1266
+ }
1267
+ if (i === "message") {
1268
+ let e = H(r);
1269
+ return e ? [{
1270
+ type: n === "completed" ? "text_final" : "text_delta",
1271
+ text: e
1272
+ }] : [];
1273
+ }
1274
+ return [];
1275
+ }
1276
+ function rt({ eventName: e, data: t, state: n }) {
1277
+ let r = String(t?.type || e || "").trim(), i = String(t?.id || t?.response?.id || t?.response_id || "");
1278
+ if (i.startsWith("resp_") && (n.currentResponseId = i), r === "response.tool_call") return [{
1279
+ type: "tool_upsert",
1280
+ name: String(t?.name || t?.tool_name || "tool"),
1281
+ args: z(t?.args ?? t?.arguments),
1282
+ status: "running"
1283
+ }];
1284
+ if (r === "response.tool_result" || r === "response.ksadk.tool_result") return [{
1285
+ type: "tool_result",
1286
+ name: String(t?.name || t?.tool_name || "tool"),
1287
+ output: z(t?.output ?? t?.result)
1288
+ }];
1289
+ if (r === "response.output_item.added") return U({
1290
+ data: t,
1291
+ state: n,
1292
+ status: "running"
1293
+ });
1294
+ if (r === "response.output_item.done") return U({
1295
+ data: t,
1296
+ state: n,
1297
+ status: "completed"
1298
+ });
1299
+ if (r === "response.function_call_arguments.delta") {
1300
+ let e = String(t?.item_id || t?.call_id || ""), r = V(n, e, t), i = `${n.toolArguments.get(e) || ""}${String(t?.delta || "")}`;
1301
+ return n.toolArguments.set(e, i), [{
1302
+ type: "tool_upsert",
1303
+ name: r,
1304
+ args: i,
1305
+ status: "running"
1306
+ }];
1307
+ }
1308
+ if (r === "response.function_call_arguments.done") {
1309
+ let e = String(t?.item_id || t?.call_id || ""), r = V(n, e, t), i = z(t?.arguments ?? n.toolArguments.get(e));
1310
+ return n.toolArguments.set(e, i), [{
1311
+ type: "tool_upsert",
1312
+ name: r,
1313
+ args: i,
1314
+ status: "running"
1315
+ }];
1316
+ }
1317
+ if (r === "response.reasoning.delta" || r === "response.reasoning_text.delta" || r === "response.reasoning_summary.delta" || r === "response.reasoning_summary_text.delta") {
1318
+ let e = B(t?.delta, t?.text);
1319
+ return e && (n.sawReasoningDelta = !0), e ? [{
1320
+ type: "reasoning_delta",
1321
+ text: e
1322
+ }] : [];
1323
+ }
1324
+ if (r === "response.output_text.delta") {
1325
+ let e = B(t?.delta, t?.text);
1326
+ return e && (n.sawTextDelta = !0), e ? [{
1327
+ type: "text_delta",
1328
+ text: e
1329
+ }] : [];
1330
+ }
1331
+ if (r === "response.output_text.done") {
1332
+ let e = B(t?.text, t?.delta);
1333
+ return e ? [{
1334
+ type: "text_final",
1335
+ text: e
1336
+ }] : [];
1337
+ }
1338
+ if (r === "response.content_part.delta") {
1339
+ let e = String(t?.part?.type || t?.delta?.type || t?.content_type || ""), r = B(t?.delta?.text, t?.delta, t?.text);
1340
+ return r ? e.includes("reasoning") ? (n.sawReasoningDelta = !0, [{
1341
+ type: "reasoning_delta",
1342
+ text: r
1343
+ }]) : (n.sawTextDelta = !0, [{
1344
+ type: "text_delta",
1345
+ text: r
1346
+ }]) : [];
1347
+ }
1348
+ if (r === "response.completed") {
1349
+ let e = et(t), r = tt(t).flatMap((e) => U({
1350
+ data: {
1351
+ ...t,
1352
+ item: e
1353
+ },
1354
+ state: n,
1355
+ status: "completed"
1356
+ })).filter((e) => !(n.sawTextDelta && e.type === "text_final") && !(n.sawReasoningDelta && e.type === "reasoning_delta")), i = r.some((e) => e.type === "text_final");
1357
+ return [
1358
+ ...r,
1359
+ ...e && !n.sawTextDelta && !i ? [{
1360
+ type: "text_final",
1361
+ text: e
1362
+ }] : [],
1363
+ {
1364
+ type: "terminal",
1365
+ status: "completed"
1366
+ }
1367
+ ];
1368
+ }
1369
+ if (r === "response.failed") return [{
1370
+ type: "failed",
1371
+ message: t?.error?.message || "Agent 运行失败"
1372
+ }, {
1373
+ type: "terminal",
1374
+ status: "failed"
1375
+ }];
1376
+ if (r === "response.incomplete") return [{ type: "incomplete" }, {
1377
+ type: "terminal",
1378
+ status: "incomplete"
1379
+ }];
1380
+ if (r === "response.cancelled") return [{
1381
+ type: "terminal",
1382
+ status: "cancelled"
1383
+ }];
1384
+ if (r === "response.approval_request" || r === "response.ksadk.approval_request") {
1385
+ let e = nt(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 : [];
1386
+ if (s.length > 0) {
1387
+ let e = s.map((e) => ({
1388
+ type: "tool_upsert",
1389
+ name: String(e?.name || "tool"),
1390
+ args: JSON.stringify(e?.args ?? {}),
1391
+ status: "paused",
1392
+ approvalRequestId: r,
1393
+ previousResponseId: i
1394
+ })), t = s[0] || {};
1395
+ return [...e, {
1396
+ type: "approval_request",
1397
+ approvalRequestId: r,
1398
+ previousResponseId: i,
1399
+ ...a ? { runId: a } : {},
1400
+ name: String(t?.name || "人工确认"),
1401
+ args: JSON.stringify(t?.args ?? {})
1402
+ }];
1403
+ }
1404
+ return [{
1405
+ type: "approval_request",
1406
+ approvalRequestId: r,
1407
+ previousResponseId: i,
1408
+ ...a ? { runId: a } : {}
1409
+ }];
1410
+ }
1411
+ if (r === "response.approval_resolved" || r === "response.ksadk.approval_resolved") {
1412
+ let e = String(t?.decision || t?.outcome || "").toLowerCase(), n = e === "reject" || e === "rejected" || e === "denied" ? "rejected" : e === "cancel" || e === "cancelled" || e === "canceled" ? "cancelled" : "approved";
1413
+ return [{
1414
+ type: "approval_resolved",
1415
+ approvalRequestId: String(t?.approval_request_id || t?.approvalRequestId || t?.approval_id || t?.approvalId || ""),
1416
+ decision: n,
1417
+ revision: Number(t?.revision || 2)
1418
+ }];
1419
+ }
1420
+ if (new Set([
1421
+ "response.ksadk.a2ui_surface_begin",
1422
+ "a2ui.surface.begin",
1423
+ "response.a2ui.createSurface",
1424
+ "a2ui.createSurface",
1425
+ "createSurface"
1426
+ ]).has(r)) {
1427
+ let e = t?.surface && typeof t.surface == "object" ? t.surface : {};
1428
+ return [{
1429
+ type: "a2ui_surface_begin",
1430
+ surfaceId: String(t?.surface_id || t?.surfaceId || e.surface_id || e.surfaceId || ""),
1431
+ surface: e
1432
+ }];
1433
+ }
1434
+ if (new Set([
1435
+ "response.ksadk.a2ui_surface_update",
1436
+ "a2ui.surface.update",
1437
+ "response.a2ui.updateComponents",
1438
+ "a2ui.updateComponents",
1439
+ "updateComponents"
1440
+ ]).has(r)) {
1441
+ let e = t?.surface && typeof t.surface == "object" ? t.surface : {};
1442
+ return [{
1443
+ type: "a2ui_surface_update",
1444
+ surfaceId: String(t?.surface_id || t?.surfaceId || e.surface_id || e.surfaceId || ""),
1445
+ surface: e
1446
+ }];
1447
+ }
1448
+ if (new Set([
1449
+ "response.ksadk.a2ui_surface_end",
1450
+ "a2ui.surface.end",
1451
+ "response.a2ui.deleteSurface",
1452
+ "a2ui.deleteSurface",
1453
+ "deleteSurface"
1454
+ ]).has(r)) return [{
1455
+ type: "a2ui_surface_end",
1456
+ surfaceId: String(t?.surface_id || t?.surfaceId || "")
1457
+ }];
1458
+ if (new Set(["response.ksadk.a2ui_interaction", "a2ui.interaction"]).has(r)) return [{
1459
+ type: "a2ui_interaction",
1460
+ surfaceId: String(t?.surface_id || t?.surfaceId || ""),
1461
+ interactionId: String(t?.interaction_id || t?.interactionId || ""),
1462
+ kind: String(t?.kind || "input"),
1463
+ inputSchema: t?.input_schema && typeof t.input_schema == "object" ? t.input_schema : {}
1464
+ }];
1465
+ let a = t?.content?.parts?.[0]?.text;
1466
+ return a && !t?.actions?.finishReason ? [{
1467
+ type: "text_delta",
1468
+ text: String(a)
1469
+ }] : [];
1470
+ }
1471
+ //#endregion
1472
+ //#region src/utils/session-events.js
1473
+ var it = new Set([
1474
+ "completed",
1475
+ "failed",
1476
+ "error",
1477
+ "cancelled",
1478
+ "canceled",
1479
+ "aborted",
1480
+ "interrupted",
1481
+ "resume_failed"
1482
+ ]), W = new Set([
1483
+ "tool_call",
1484
+ "tool_result",
1485
+ "stage_tool_call",
1486
+ "stage_tool_result"
1487
+ ]), G = {
1488
+ "run.started": "in_progress",
1489
+ "run.progress": "in_progress",
1490
+ "run.interrupted": "interrupted",
1491
+ "run.completed": "completed",
1492
+ "run.failed": "failed",
1493
+ "run.canceled": "cancelled"
1494
+ };
1495
+ function K(e) {
1496
+ let t = e?.Content?.payload;
1497
+ return t && typeof t == "object" ? t : {};
1498
+ }
1499
+ function at(e, t) {
1500
+ let n = String(e || ""), r = String(t || "");
1501
+ return n ? !r || n.endsWith(r) ? n : r.startsWith(n) ? r : `${n}${r}` : r;
1502
+ }
1503
+ function ot(e) {
1504
+ let t = String(e?.EventType || ""), n = K(e);
1505
+ return G[t] ? {
1506
+ ...e,
1507
+ EventType: "run_status",
1508
+ Content: {
1509
+ status: String(n.status || G[t]),
1510
+ ...n.detail ? { detail: String(n.detail) } : {}
1511
+ }
1512
+ } : t === "reasoning.delta" || t === "reasoning.completed" ? {
1513
+ ...e,
1514
+ EventType: "reasoning",
1515
+ Content: {
1516
+ role: "model",
1517
+ parts: [{ text: String(n.text || "") }]
1518
+ }
1519
+ } : t === "tool.call.begin" ? {
1520
+ ...e,
1521
+ EventType: "tool_call",
1522
+ Metadata: {
1523
+ ...e.Metadata || {},
1524
+ tool_name: n.name,
1525
+ tool_args: n.args,
1526
+ tool_call_id: n.call_id
1527
+ },
1528
+ Content: {
1529
+ role: "model",
1530
+ parts: []
1531
+ }
1532
+ } : t === "tool.call.end" ? {
1533
+ ...e,
1534
+ EventType: "tool_result",
1535
+ Metadata: {
1536
+ ...e.Metadata || {},
1537
+ tool_name: n.name,
1538
+ tool_output: n.error || n.result,
1539
+ tool_call_id: n.call_id
1540
+ },
1541
+ Content: {
1542
+ role: "model",
1543
+ parts: []
1544
+ }
1545
+ } : e;
1546
+ }
1547
+ function st(e) {
1548
+ let t = [], n = /* @__PURE__ */ new Map();
1549
+ for (let r of Array.isArray(e) ? e : []) {
1550
+ let e = String(r?.EventType || "");
1551
+ if (e === "text.delta" || e === "text.completed") {
1552
+ let e = String(r?.InvocationId || "").trim();
1553
+ if (!e) continue;
1554
+ let t = n.get(e);
1555
+ n.set(e, {
1556
+ event: r,
1557
+ text: at(t?.text, K(r).text)
1558
+ });
1559
+ continue;
1560
+ }
1561
+ t.push(ot(r));
1562
+ }
1563
+ for (let { event: e, text: r } of n.values()) t.push({
1564
+ ...e,
1565
+ EventType: "assistant_stream_snapshot",
1566
+ Content: {
1567
+ role: "model",
1568
+ parts: [{ text: r }]
1569
+ },
1570
+ Metadata: {
1571
+ ...e.Metadata || {},
1572
+ stream_snapshot: !0
1573
+ }
1574
+ });
1575
+ return t.sort((e, t) => Q(e) - Q(t));
1576
+ }
1577
+ function ct(e) {
1578
+ let t = String(e?.EventType || "").trim();
1579
+ if (t !== "run_status" && !t.startsWith("run.")) return "";
1580
+ let n = K(e);
1581
+ return String(e?.Content?.status || n.status || G[t] || "").trim().toLowerCase();
1582
+ }
1583
+ function q(e) {
1584
+ 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("") : "";
1585
+ }
1586
+ function J(e) {
1587
+ let t = String(e || "").trim();
1588
+ return t ? `/agentengine/api/v1/AttachmentContent?FileUri=${encodeURIComponent(t)}` : "";
1589
+ }
1590
+ function lt(e) {
1591
+ return String(e || "").match(/^data:([^;,]+)/)?.[1] || "";
1592
+ }
1593
+ function ut(e, t) {
1594
+ let n = String(e || "").trim(), r = String(t || "").trim();
1595
+ return !n || !r || n === r ? !0 : n.endsWith("/*") ? r.startsWith(n.slice(0, -1)) : r.endsWith("/*") ? n.startsWith(r.slice(0, -1)) : !1;
1596
+ }
1597
+ function Y(e) {
1598
+ let t = e?.Content?.parts || [], n = [], r = /* @__PURE__ */ new Map(), i = (e) => {
1599
+ let t = `${e.fileUri || e.url || e.name}|${e.type}`;
1600
+ r.has(t) || r.set(t, e);
1601
+ };
1602
+ for (let e of t) {
1603
+ if (e?.type === "input_text" || e?.text) {
1604
+ n.push(e.text || "");
1605
+ continue;
1606
+ }
1607
+ if (e?.type === "input_file" && e.inlineData) {
1608
+ i({
1609
+ name: e.inlineData.displayName || "attachment",
1610
+ url: `data:${e.inlineData.mimeType || "application/octet-stream"};base64,${e.inlineData.data}`,
1611
+ type: e.inlineData.mimeType || "application/octet-stream"
1612
+ });
1613
+ continue;
1614
+ }
1615
+ if (e?.type === "input_file" && typeof e.file_data == "string" && e.file_data) {
1616
+ i({
1617
+ name: e.filename || e.displayName || e.display_name || "attachment",
1618
+ url: `data:${e.mime_type || e.mimeType || "application/octet-stream"};base64,${e.file_data}`,
1619
+ type: e.mime_type || e.mimeType || "application/octet-stream"
1620
+ });
1621
+ continue;
1622
+ }
1623
+ if (e?.type === "input_file" && typeof e.file_url == "string" && e.file_url.trim()) {
1624
+ let t = e.file_url.trim();
1625
+ i({
1626
+ name: e.filename || e.displayName || e.display_name || "attachment",
1627
+ url: J(t),
1628
+ type: e.mime_type || e.mimeType || "application/octet-stream",
1629
+ fileUri: t
1630
+ });
1631
+ continue;
1632
+ }
1633
+ if (e?.type === "input_image" || e?.type === "image_url") {
1634
+ let t = typeof e.image_url == "string" ? e.image_url : e.image_url?.url;
1635
+ t && i({
1636
+ name: e.filename || e.displayName || e.display_name || "uploaded_image",
1637
+ url: t,
1638
+ type: e.mime_type || e.mimeType || lt(t) || "image/*"
1639
+ });
1640
+ continue;
1641
+ }
1642
+ if (e?.type === "input_file" && e.fileData) {
1643
+ let t = String(e.fileData.fileUri || "").trim();
1644
+ i({
1645
+ name: e.fileData.displayName || "attachment",
1646
+ url: J(t),
1647
+ type: e.fileData.mimeType || "application/octet-stream",
1648
+ fileUri: t
1649
+ });
1650
+ }
1651
+ }
1652
+ let a = Array.isArray(e?.Metadata?.attachments) ? e.Metadata.attachments : [];
1653
+ for (let e of a) {
1654
+ let t = String(e.file_uri || "").trim(), n = {
1655
+ name: e.display_name || "attachment",
1656
+ url: J(t),
1657
+ type: e.mime_type || "application/octet-stream",
1658
+ fileUri: t
1659
+ };
1660
+ !n.url && !n.fileUri && Array.from(r.values()).some((e) => e.name === n.name && ut(e.type, n.type) && (e.url || e.fileUri)) || i(n);
1661
+ }
1662
+ let o = Array.from(r.values());
1663
+ return {
1664
+ text: n.join(""),
1665
+ attachments: o.length > 0 ? o : void 0
1666
+ };
1667
+ }
1668
+ function dt(t) {
1669
+ let n = t?.Metadata?.responses_output;
1670
+ if (!Array.isArray(n)) return {};
1671
+ let r = Xe(), i = rt({
1672
+ eventName: "response.completed",
1673
+ data: { response: {
1674
+ id: String(t.Metadata?.response_id || ""),
1675
+ output: n
1676
+ } },
1677
+ state: r
1678
+ }), a = "", o = {};
1679
+ for (let t of i) {
1680
+ if (t.type === "reasoning_delta") {
1681
+ a += t.text;
1682
+ continue;
1683
+ }
1684
+ if (t.type === "tool_upsert") {
1685
+ o[t.name] = {
1686
+ ...o[t.name] || {
1687
+ name: t.name,
1688
+ args: ""
1689
+ },
1690
+ name: t.name,
1691
+ args: t.args,
1692
+ status: t.status,
1693
+ ...t.approvalRequestId ? { approvalRequestId: t.approvalRequestId } : {},
1694
+ ...t.previousResponseId ? { previousResponseId: t.previousResponseId } : {},
1695
+ ...t.serverLabel ? { serverLabel: t.serverLabel } : {},
1696
+ ...t.approvalRequestId ? { approvalStatus: "pending" } : {}
1697
+ };
1698
+ continue;
1699
+ }
1700
+ t.type === "tool_result" && (o[t.name] = {
1701
+ ...o[t.name] || {
1702
+ name: t.name,
1703
+ args: ""
1704
+ },
1705
+ name: t.name,
1706
+ output: t.output,
1707
+ status: e(t.output) ? "error" : "completed"
1708
+ });
1709
+ }
1710
+ return {
1711
+ ...a ? { reasoning: a } : {},
1712
+ ...Object.keys(o).length > 0 ? { tools: o } : {}
1713
+ };
1714
+ }
1715
+ function ft(e, t, n) {
1716
+ return t === "running" ? e === "prompt_too_long" ? "检测到上下文过长,正在自动压缩历史后重试" : "正在自动压缩上下文" : n ? e === "prompt_too_long" ? "上下文过长,系统已自动压缩历史并重试" : "系统已自动压缩较早的对话上下文" : t === "failed" ? "自动压缩上下文未完成" : e === "prompt_too_long" ? "已完成上下文压缩,并继续当前回复" : "已完成上下文压缩";
1717
+ }
1718
+ function pt(e, t) {
1719
+ return t?.itemId ? [
1720
+ "runtime-item",
1721
+ t.runId || e,
1722
+ t.scopeId || e,
1723
+ t.itemId
1724
+ ].join("\0") : [
1725
+ e,
1726
+ t.content || "",
1727
+ t.reasoning || ""
1728
+ ].join("\0");
1729
+ }
1730
+ function X(e) {
1731
+ let t = String(e?.InvocationId || "").trim(), n = e?.Metadata?.RuntimeItem;
1732
+ return n?.ItemId ? [
1733
+ "runtime-item",
1734
+ n.RunId || t,
1735
+ n.ScopeId || t,
1736
+ n.ItemId
1737
+ ].join("\0") : t;
1738
+ }
1739
+ function mt(e) {
1740
+ let t = e?.Metadata?.RuntimeItem;
1741
+ return t?.ItemId ? {
1742
+ id: `runtime:${t.RunId || e.InvocationId || "run"}:${t.ScopeId || e.InvocationId || "scope"}:${t.ItemId}`,
1743
+ runId: String(t.RunId || e.InvocationId || ""),
1744
+ scopeId: String(t.ScopeId || e.InvocationId || ""),
1745
+ itemId: String(t.ItemId),
1746
+ partId: t.PartId ? String(t.PartId) : void 0
1747
+ } : null;
1748
+ }
1749
+ function ht(e) {
1750
+ return e?.Metadata?.responses_mirror === !0 || String(e?.Metadata?.responses_mirror || "").trim().toLowerCase() === "true";
1751
+ }
1752
+ function Z(e) {
1753
+ if (e?.EventType !== "user_message") return "";
1754
+ let t = Y(e), n = (t.attachments || []).map((e) => [
1755
+ e.name || "",
1756
+ e.fileUri || "",
1757
+ e.url || "",
1758
+ e.type || ""
1759
+ ].join("")).sort().join("");
1760
+ return [String(t.text || "").trim(), n].join("\0");
1761
+ }
1762
+ function gt(e) {
1763
+ return e?.EventType === "assistant_stream_snapshot";
1764
+ }
1765
+ function Q(e) {
1766
+ let t = Number(e?.SeqId || 0);
1767
+ if (Number.isFinite(t) && t > 0) return t;
1768
+ let n = Number(e?.Timestamp || 0);
1769
+ return Number.isFinite(n) ? n : 0;
1770
+ }
1771
+ function _t(e) {
1772
+ if (typeof e == "string") return e;
1773
+ if (e == null) return "";
1774
+ try {
1775
+ return JSON.stringify(e, null, 2);
1776
+ } catch {
1777
+ return String(e);
1778
+ }
1779
+ }
1780
+ function vt(t) {
1781
+ let n = String(t?.EventType || "");
1782
+ if (!W.has(n)) return null;
1783
+ let r = String(t.Metadata?.tool_name || t.Metadata?.name || t.Metadata?.function_name || q(t.Content?.parts) || "tool").trim() || "tool", i = String(t.Metadata?.call_id || t.Metadata?.callId || t.Metadata?.RuntimeItem?.ToolCallId || "").trim(), a = {
1784
+ name: r,
1785
+ ...i ? { callId: i } : {},
1786
+ args: "",
1787
+ status: "running"
1788
+ }, o = n === "tool_result" || n === "stage_tool_result" ? (() => {
1789
+ let n = _t(t.Metadata?.tool_output ?? t.Metadata?.output ?? t.Metadata?.result ?? q(t.Content?.parts));
1790
+ return {
1791
+ ...a,
1792
+ output: n,
1793
+ status: e(n) ? "error" : "completed"
1794
+ };
1795
+ })() : {
1796
+ ...a,
1797
+ args: _t(t.Metadata?.tool_args ?? t.Metadata?.arguments ?? t.Metadata?.args ?? {})
1798
+ }, s = mt(t);
1799
+ return {
1800
+ id: s?.id || t.EventId || String(Date.now() + Math.random()),
1801
+ role: "model",
1802
+ content: "",
1803
+ timestamp: t.Timestamp || Date.now(),
1804
+ eventType: n,
1805
+ ...s || {},
1806
+ tools: { [r]: o }
1807
+ };
1808
+ }
1809
+ function yt(e = {}, t = {}) {
1810
+ let n = { ...e || {} };
1811
+ for (let [e, r] of Object.entries(t || {})) n[e] = {
1812
+ ...n[e] || {},
1813
+ ...r || {},
1814
+ name: e,
1815
+ args: r?.args || n[e]?.args || ""
1816
+ };
1817
+ return n;
1818
+ }
1819
+ function bt(e = {}, t = "") {
1820
+ let n = String(t || "").trim().toLowerCase(), r = n === "completed" ? "completed" : it.has(n) ? "error" : "";
1821
+ if (!r) return e;
1822
+ let i = !1, a = {};
1823
+ for (let [t, n] of Object.entries(e || {})) n?.status === "running" ? (i = !0, a[t] = {
1824
+ ...n,
1825
+ status: r
1826
+ }) : a[t] = n;
1827
+ return i ? a : e;
1828
+ }
1829
+ function xt(e, t) {
1830
+ return {
1831
+ ...e,
1832
+ reasoning: St(e.reasoning, t.reasoning),
1833
+ tools: yt(e.tools, t.tools),
1834
+ eventId: t.eventId || e.eventId,
1835
+ responseId: t.responseId || e.responseId,
1836
+ traceId: t.traceId || e.traceId,
1837
+ rootSpanId: t.rootSpanId || e.rootSpanId,
1838
+ timestamp: Math.max(Number(e.timestamp || 0), Number(t.timestamp || 0)) || t.timestamp || e.timestamp,
1839
+ id: t.responseId || t.reasoning || t.tools ? t.id : e.id
1840
+ };
1841
+ }
1842
+ function St(e = "", t = "") {
1843
+ let n = String(e || ""), r = String(t || "");
1844
+ return n ? !r || n.endsWith(r) ? n : r.startsWith(n) ? r : `${n}${r}` : r;
1845
+ }
1846
+ function Ct(e) {
1847
+ return {
1848
+ id: e.id,
1849
+ role: "system",
1850
+ eventType: "context_checkpoint",
1851
+ status: e.status,
1852
+ trigger: e.trigger,
1853
+ compactedUntilSeqId: e.compactedUntilSeqId,
1854
+ summary: e.summary,
1855
+ historical: e.historical,
1856
+ timestamp: e.timestamp,
1857
+ content: ft(e.trigger, e.status, e.historical)
1858
+ };
1859
+ }
1860
+ function wt(e) {
1861
+ let t = e?.EventType || "", n = mt(e);
1862
+ if (t === "run_status") return e.Content?.status === "failed" ? {
1863
+ id: e.EventId || String(Date.now() + Math.random()),
1864
+ role: "system",
1865
+ content: e.Content?.detail || "本轮运行失败。",
1866
+ eventType: t,
1867
+ status: "failed",
1868
+ timestamp: e.Timestamp || Date.now()
1869
+ } : e.Content?.status === "cancelled" ? {
1870
+ id: e.EventId || String(Date.now() + Math.random()),
1871
+ role: "system",
1872
+ content: e.Content?.detail || "本轮输出已停止。",
1873
+ eventType: t,
1874
+ status: "cancelled",
1875
+ timestamp: e.Timestamp || Date.now()
1876
+ } : null;
1877
+ if (t === "context_checkpoint") {
1878
+ let t = Y(e);
1879
+ return Ct({
1880
+ id: e.EventId || String(Date.now() + Math.random()),
1881
+ timestamp: e.Timestamp || Date.now(),
1882
+ status: "completed",
1883
+ trigger: String(e.Metadata?.trigger || "auto"),
1884
+ compactedUntilSeqId: Number(e.Metadata?.compacted_until_seq_id || 0) || void 0,
1885
+ summary: t.text || void 0,
1886
+ historical: !0
1887
+ });
1888
+ }
1889
+ if (t === "reasoning") {
1890
+ let r = Y(e).text || q(e.Metadata?.reasoning);
1891
+ return r ? {
1892
+ id: n?.id || e.EventId || String(Date.now() + Math.random()),
1893
+ role: "model",
1894
+ content: "",
1895
+ reasoning: r,
1896
+ timestamp: e.Timestamp || Date.now(),
1897
+ eventType: t,
1898
+ ...n || {}
1899
+ } : null;
1900
+ }
1901
+ if (W.has(t)) return vt(e);
1902
+ if (t !== "user_message" && t !== "assistant_message" && t !== "assistant_stream_snapshot") return null;
1903
+ let r = Y(e), i = t === "assistant_message" ? dt(e) : {};
1904
+ if (!r.text && !r.attachments?.length && !i.reasoning && !i.tools) return null;
1905
+ 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();
1906
+ return {
1907
+ id: n?.id || e.EventId || String(Date.now() + Math.random()),
1908
+ role: t === "user_message" ? "user" : "model",
1909
+ content: r.text,
1910
+ timestamp: e.Timestamp || Date.now(),
1911
+ eventType: t,
1912
+ eventId: e.EventId || void 0,
1913
+ responseId: a || void 0,
1914
+ traceId: o || void 0,
1915
+ rootSpanId: s || void 0,
1916
+ attachments: r.attachments,
1917
+ ...n || {},
1918
+ ...i
1919
+ };
1920
+ }
1921
+ function Tt(e = []) {
1922
+ 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 = st(e), c = [];
1923
+ for (let e of s) {
1924
+ let t = String(e?.EventId || "").trim();
1925
+ if (t) {
1926
+ if (o.has(t)) continue;
1927
+ o.add(t);
1928
+ }
1929
+ c.push(e);
1930
+ }
1931
+ let l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map();
1932
+ for (let e of c) {
1933
+ if (e?.EventType !== "user_message" || ht(e)) {
1934
+ if (e?.EventType === "assistant_message") {
1935
+ let t = X(e);
1936
+ t && u.add(t);
1937
+ }
1938
+ if (gt(e)) {
1939
+ let t = X(e);
1940
+ if (t) {
1941
+ let n = d.get(t);
1942
+ (!n || Q(e) >= Q(n)) && d.set(t, e);
1943
+ }
1944
+ }
1945
+ continue;
1946
+ }
1947
+ let t = Z(e);
1948
+ t && l.add(t);
1949
+ }
1950
+ let f = c.filter((e) => {
1951
+ if (gt(e)) {
1952
+ let t = X(e);
1953
+ return t ? u.has(t) ? !1 : d.get(t) === e : !0;
1954
+ }
1955
+ if (e?.EventType !== "user_message" || !ht(e)) return !0;
1956
+ let t = Z(e);
1957
+ return !t || !l.has(t);
1958
+ });
1959
+ for (let e of f) {
1960
+ let a = String(e.InvocationId || "").trim();
1961
+ a && e.EventType === "user_message" && i.add(a), a && [
1962
+ "assistant_message",
1963
+ "assistant_stream_snapshot",
1964
+ "reasoning",
1965
+ "tool_call",
1966
+ "tool_result",
1967
+ "stage_tool_call",
1968
+ "stage_tool_result"
1969
+ ].includes(String(e.EventType || "")) && r.add(a), e.EventType === "run_status" && a && (t.set(a, String(e.Content?.status || "").trim()), n.set(a, e));
1970
+ }
1971
+ let p = [], m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = null, _ = /* @__PURE__ */ new Map(), v = (e) => {
1972
+ let t = e?.itemId ? `${e.runId || e.invocationId || ""}\u0000${e.scopeId || e.invocationId || ""}\u0000${e.itemId}` : "", n = t ? h.get(t) : void 0;
1973
+ if (n !== void 0) {
1974
+ p[n] = xt(p[n], e);
1975
+ return;
1976
+ }
1977
+ let r = String(e?.responseId || "").trim(), i = r ? m.get(r) : void 0;
1978
+ if (i !== void 0) {
1979
+ p[i] = xt(p[i], e);
1980
+ return;
1981
+ }
1982
+ r && m.set(r, p.length), t && h.set(t, p.length), p.push(e);
1983
+ }, y = () => {
1984
+ g &&= (v(g), null);
1985
+ }, b = (e, n = "") => {
1986
+ let r = String(e || "").trim();
1987
+ if (!r) return {};
1988
+ let i = _.get(r);
1989
+ return i ? (_.delete(r), { tools: bt(i.tools, t.get(r) || n) }) : {};
1990
+ };
1991
+ for (let e of f) {
1992
+ if (e.EventType === "run_status") continue;
1993
+ let t = wt(e);
1994
+ if (!t) continue;
1995
+ let n = String(e.InvocationId || "").trim();
1996
+ if (n && (t.invocationId = n), W.has(t.eventType)) {
1997
+ let n = String(e.InvocationId || "").trim();
1998
+ if (t.itemId) {
1999
+ y(), v(t);
2000
+ continue;
2001
+ }
2002
+ if (!n) {
2003
+ y(), v(t);
2004
+ continue;
2005
+ }
2006
+ let r = _.get(n);
2007
+ _.set(n, {
2008
+ ...r || {
2009
+ id: t.id,
2010
+ role: "model",
2011
+ content: "",
2012
+ timestamp: t.timestamp,
2013
+ invocationId: n
2014
+ },
2015
+ timestamp: Math.max(Number(r?.timestamp || 0), Number(t.timestamp || 0)),
2016
+ tools: yt(r?.tools, t.tools)
2017
+ });
2018
+ continue;
2019
+ }
2020
+ if (t.eventType === "reasoning") {
2021
+ 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);
2022
+ if (g && (i || a)) {
2023
+ g.reasoning = r === "replace" || r === "completed" ? t.reasoning : `${g.reasoning || ""}${t.reasoning || ""}`, g.timestamp = t.timestamp;
2024
+ continue;
2025
+ }
2026
+ y(), g = {
2027
+ ...t,
2028
+ ...n ? { invocationId: n } : {}
2029
+ };
2030
+ continue;
2031
+ }
2032
+ let r = t.eventType === "assistant_message" || t.eventType === "assistant_stream_snapshot";
2033
+ if (r && g) {
2034
+ let n = String(e.InvocationId || "").trim(), r = pt(n, t);
2035
+ if (t.eventType === "assistant_message" && n && a.has(r)) {
2036
+ g = null;
2037
+ continue;
2038
+ }
2039
+ t.eventType === "assistant_message" && n && a.add(r), v({
2040
+ ...t,
2041
+ ...b(n, t.eventType === "assistant_message" ? "completed" : ""),
2042
+ reasoning: St(g.reasoning, t.reasoning)
2043
+ }), g = null;
2044
+ continue;
2045
+ }
2046
+ if (y(), r) {
2047
+ let n = String(e.InvocationId || "").trim(), r = pt(n, t);
2048
+ if (t.eventType === "assistant_message" && n && a.has(r)) continue;
2049
+ t.eventType === "assistant_message" && n && a.add(r), v({
2050
+ ...t,
2051
+ ...b(n, t.eventType === "assistant_message" ? "completed" : "")
2052
+ });
2053
+ continue;
2054
+ }
2055
+ v(t);
2056
+ }
2057
+ y();
2058
+ for (let [e, n] of _.entries()) v({
2059
+ ...n,
2060
+ tools: bt(n.tools, t.get(e))
2061
+ });
2062
+ for (let [e, a] of t.entries()) {
2063
+ if (a !== "in_progress" || r.has(e) || !i.has(e)) continue;
2064
+ let t = n.get(e) || {};
2065
+ v({
2066
+ id: `run-placeholder-${e}`,
2067
+ role: "model",
2068
+ content: "",
2069
+ status: "running",
2070
+ eventType: "run_status",
2071
+ timestamp: t.Timestamp || Date.now()
2072
+ });
2073
+ }
2074
+ return p;
2075
+ }
2076
+ function Et(e = [], t = []) {
2077
+ let n = [], r = /* @__PURE__ */ new Set();
2078
+ for (let i of [...Array.isArray(e) ? e : [], ...Array.isArray(t) ? t : []]) {
2079
+ let e = String(i?.EventId || "").trim();
2080
+ if (e) {
2081
+ if (r.has(e)) continue;
2082
+ r.add(e);
2083
+ }
2084
+ n.push(i);
2085
+ }
2086
+ return n.sort((e, t) => {
2087
+ let n = Number(e?.SeqId || 0), r = Number(t?.SeqId || 0);
2088
+ return Number.isFinite(n) && Number.isFinite(r) && n !== r ? n - r : Number(e?.Timestamp || 0) - Number(t?.Timestamp || 0);
2089
+ });
2090
+ }
2091
+ function Dt(e = []) {
2092
+ return (Array.isArray(e) ? e : []).reduce((e, t) => {
2093
+ let n = Number(t.SeqId || 0);
2094
+ return Number.isFinite(n) ? Math.max(e, n) : e;
2095
+ }, 0);
2096
+ }
2097
+ function Ot(e) {
2098
+ return it.has(ct(e));
2099
+ }
2100
+ //#endregion
2101
+ //#region src/utils/persisted-session-history.ts
2102
+ function $(e) {
2103
+ return e && typeof e == "object" && !Array.isArray(e) ? e : null;
2104
+ }
2105
+ function kt(e) {
2106
+ if (typeof e == "number" && Number.isFinite(e)) return e > 0 && e < 1e11 ? e * 1e3 : e;
2107
+ if (typeof e == "string" && e.trim()) {
2108
+ let t = Number(e.trim());
2109
+ if (Number.isFinite(t)) return t > 0 && t < 1e11 ? t * 1e3 : t;
2110
+ }
2111
+ let t = Date.parse(String(e || ""));
2112
+ return Number.isFinite(t) ? t : Date.now();
2113
+ }
2114
+ function At(e) {
2115
+ let t = $(e?.Content?.runtime_event || e?.Content?.runtimeEvent);
2116
+ if (t && String(t.event_type || "")) return {
2117
+ ...t,
2118
+ family: "runtime",
2119
+ seq: Number(e.SeqId || t.seq || 0),
2120
+ timestamp: e.Timestamp || t.timestamp
2121
+ };
2122
+ let n = $(e?.Content?.session_event || e?.Content?.sessionEvent);
2123
+ if (!n || String(n.family || "") !== "runtime") return null;
2124
+ let r = $(n.payload);
2125
+ return !r || !String(r.event_type || n.event_type || "") ? null : {
2126
+ ...r,
2127
+ family: "runtime",
2128
+ event_type: r.event_type || n.event_type,
2129
+ run_id: r.run_id || n.run_id,
2130
+ seq: Number(e.SeqId || n.seq || r.seq || 0),
2131
+ timestamp: e.Timestamp || n.timestamp || r.timestamp
2132
+ };
2133
+ }
2134
+ function jt(e) {
2135
+ return e.role === "model" ? {
2136
+ ...e,
2137
+ blocks: e.blocks?.length ? e.blocks : Be({
2138
+ content: e.content,
2139
+ reasoning: e.reasoning,
2140
+ tools: e.tools
2141
+ })
2142
+ } : e;
2143
+ }
2144
+ function Mt(e, t) {
2145
+ 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 ? {
2146
+ ...e,
2147
+ ...n,
2148
+ invocationId: e.invocationId || n.invocationId
2149
+ } : jt(e === a && o ? {
2150
+ ...e,
2151
+ responseId: o.responseId || e.responseId,
2152
+ traceId: o.traceId || e.traceId,
2153
+ rootSpanId: o.rootSpanId || e.rootSpanId
2154
+ } : e));
2155
+ return n && !r ? [n, ...s] : s;
2156
+ }
2157
+ function Nt(e, t) {
2158
+ let n = t.filter((e) => e.role === "model"), r = n.reduce((e, t) => ({
2159
+ ...e,
2160
+ ...t.tools || {}
2161
+ }), {}), i = n.map((e) => String(e.reasoning || "").trim()).filter(Boolean).join("\n\n"), a = [...e].reverse().find((e) => e.role === "model");
2162
+ return !a || Object.keys(r).length === 0 && !i ? e : e.map((e) => e === a ? jt({
2163
+ ...e,
2164
+ reasoning: e.reasoning || i || void 0,
2165
+ tools: Object.keys(r).length > 0 ? {
2166
+ ...e.tools || {},
2167
+ ...r
2168
+ } : e.tools
2169
+ }) : e);
2170
+ }
2171
+ function Pt(e) {
2172
+ return new Set(e.filter((e) => e.role === "model" && e.eventType === "assistant_message" && !!String(e.content || "").trim() && !!e.invocationId).map((e) => String(e.invocationId)));
2173
+ }
2174
+ var Ft = new Set([
2175
+ "approval.resolved",
2176
+ "interaction.resolved",
2177
+ "interaction.cancelled",
2178
+ "interaction.canceled",
2179
+ "a2ui.action"
2180
+ ]);
2181
+ function It(e) {
2182
+ let t = /* @__PURE__ */ new Set();
2183
+ for (let n of e) {
2184
+ 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();
2185
+ if (!Ft.has(a)) continue;
2186
+ let o = String(e.outcome || e.action || e.name || e.status || i.outcome || i.action || i.name || i.status || "").toLowerCase();
2187
+ if (![
2188
+ "cancel",
2189
+ "cancelled",
2190
+ "canceled"
2191
+ ].includes(o)) continue;
2192
+ let s = String(n.InvocationId || e.runId || e.run_id || i.runId || i.run_id || r.run_id || "").trim();
2193
+ s && t.add(s);
2194
+ }
2195
+ return t;
2196
+ }
2197
+ function Lt(e, t, n) {
2198
+ let r = new Ke(n), i = [], a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = [...t || []].sort((e, t) => Number(e.SeqId || 0) - Number(t.SeqId || 0)), c = Number(s[0]?.SeqId || 0) <= 1;
2199
+ for (let e of s) {
2200
+ let t = At(e);
2201
+ if (!t) continue;
2202
+ let n = String(t.run_id || "").trim();
2203
+ if (n) {
2204
+ a.add(n);
2205
+ let e = $($(t.source)?.metadata), r = String(t.event_type || "") === "run.started", i = e?.native_item_kind === "userMessage";
2206
+ (c || r || i) && o.add(n);
2207
+ }
2208
+ let s = r.translate(t);
2209
+ s && i.push({
2210
+ ...s,
2211
+ SeqId: Number(e.SeqId || s.SeqId || 0),
2212
+ Timestamp: kt(e.Timestamp || s.Timestamp)
2213
+ });
2214
+ }
2215
+ let l = Tt(i).filter((e) => e.invocationId && a.has(e.invocationId)), u = /* @__PURE__ */ new Map();
2216
+ for (let t of e) {
2217
+ let e = String(t.invocationId || "");
2218
+ e && u.set(e, [...u.get(e) || [], t]);
2219
+ }
2220
+ let d = new Set([...Pt(l)].filter((e) => o.has(e))), f = It(s), p = [...d].flatMap((e) => Mt(l.filter((t) => t.invocationId === e), u.get(e) || [])), m = /* @__PURE__ */ new Map();
2221
+ for (let [e, t] of u) d.has(e) || !a.has(e) || m.set(e, Nt(t, l.filter((t) => t.invocationId === e)));
2222
+ let h = new Map([...m.values()].flat().map((e) => [e.id, e]));
2223
+ return {
2224
+ messages: [...e.filter((e) => !(e.role === "model" && e.invocationId && f.has(e.invocationId)) && (e.role === "a2ui" || !e.invocationId || !d.has(e.invocationId))).map((e) => h.get(e.id) || e), ...p].sort((e, t) => Number(e.timestamp || 0) - Number(t.timestamp || 0)),
2225
+ canonicalRunIds: [...d],
2226
+ translatedEvents: i
2227
+ };
2228
+ }
2229
+ //#endregion
2230
+ export { ce as A, Se as C, se as D, ee as E, oe as O, ye as S, te as T, ze as _, Ot as a, Me as b, ct as c, Ke as d, qe as f, Ie as g, Be as h, Tt as i, t as j, re as k, Xe as l, Pe as m, Lt as n, Dt as o, Fe as p, Ct as r, Et as s, At as t, rt as u, Le as v, ve as w, Ce as x, Re as y };