@qwen-code/qwen-code 0.20.1-preview.7215 → 0.20.1

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 (326) hide show
  1. package/bundled/qc-helper/docs/configuration/settings.md +1 -1
  2. package/bundled/qc-helper/docs/features/auto-mode.md +19 -16
  3. package/bundled/qc-helper/docs/features/commands.md +54 -0
  4. package/bundled/qc-helper/docs/features/sub-agents.md +16 -7
  5. package/bundled/qc-helper/docs/integration-github-action.md +10 -10
  6. package/bundled/qc-helper/docs/qwen-serve.md +2 -1
  7. package/bundled/review/DESIGN.md +2 -2
  8. package/bundled/review/SKILL.md +4 -4
  9. package/chunks/{MaxSizedBox-EH6G5AEH.js → MaxSizedBox-4WZYPSRU.js} +40 -36
  10. package/chunks/{StandaloneSessionPicker-264A3TEA.js → StandaloneSessionPicker-PE4JAIFA.js} +58 -54
  11. package/chunks/{acpAgent-6RBIJFDI.js → acpAgent-BVIKGJ2C.js} +1503 -520
  12. package/chunks/{agent-QURXGAA3.js → agent-DHLFAOUV.js} +36 -32
  13. package/chunks/{agent-headless-CRGX4ICQ.js → agent-headless-ZP5WTNXZ.js} +36 -32
  14. package/chunks/{anthropicContentGenerator-BWBAZGTW.js → anthropicContentGenerator-NMSS7IMV.js} +11 -11
  15. package/chunks/{artifact-tool-IUJ7QWCX.js → artifact-tool-56T5IMBP.js} +3 -3
  16. package/chunks/{askUserQuestion-IUMUUTDQ.js → askUserQuestion-E25OBIC2.js} +3 -3
  17. package/chunks/{bridge-MNFVKPMI.js → bridge-XAK7JKMD.js} +41 -37
  18. package/chunks/{build-SSCNEHZZ.js → build-GHIZ4MSZ.js} +1 -1
  19. package/chunks/{ca-2SL2BXTK.js → ca-N6VVUFVB.js} +611 -201
  20. package/chunks/{channel-worker-group-53CMOPFT.js → channel-worker-group-LFBT7K64.js} +5 -5
  21. package/chunks/{channel-worker-manager-UTXILKC2.js → channel-worker-manager-3RUPERG2.js} +5 -5
  22. package/chunks/{channel-worker-supervisor-ZGO2W2MD.js → channel-worker-supervisor-A3KVATD3.js} +4 -4
  23. package/chunks/{chunk-IUSNI6IX.js → chunk-27CLX4FV.js} +1 -1
  24. package/chunks/{chunk-2HOVDT7W.js → chunk-2LI23QA6.js} +1 -1
  25. package/chunks/chunk-2RFKHEXL.js +74 -0
  26. package/chunks/{chunk-LZYWWWCZ.js → chunk-3KQSDUK3.js} +3 -3
  27. package/chunks/{chunk-NOWTNYC7.js → chunk-3LH5Q2AR.js} +8 -8
  28. package/chunks/{chunk-IB35C3IL.js → chunk-3SXF4GMQ.js} +1 -1
  29. package/chunks/chunk-43T5WDQ7.js +127 -0
  30. package/chunks/{chunk-KXEGCGUG.js → chunk-4BRH6FP5.js} +31 -6
  31. package/chunks/{chunk-TTSKHF43.js → chunk-4DSBFQMI.js} +2 -2
  32. package/chunks/{chunk-JD3MKVKL.js → chunk-4K56OJFJ.js} +1 -1
  33. package/chunks/{chunk-KTUQMDEP.js → chunk-4K7VDKAD.js} +1 -1
  34. package/chunks/{chunk-QKYTTBYW.js → chunk-4LVZNIDO.js} +1 -1
  35. package/chunks/{chunk-OF2BBLYQ.js → chunk-52T5UHAZ.js} +2 -2
  36. package/chunks/{chunk-ZEOZL37W.js → chunk-57FIIFJN.js} +1 -1
  37. package/chunks/{chunk-WAX3ITOA.js → chunk-5EA5NVXS.js} +1 -1
  38. package/chunks/chunk-5G2SK2OO.js +20600 -0
  39. package/chunks/{chunk-6EFTQYW7.js → chunk-5I5BM454.js} +1 -1
  40. package/chunks/{chunk-GMGDLUC7.js → chunk-6IL7KRLE.js} +1 -1
  41. package/chunks/{chunk-26LLB6FM.js → chunk-6NHK6HS7.js} +2 -2
  42. package/chunks/{chunk-FVS747N7.js → chunk-6PRNSLMB.js} +11 -6
  43. package/chunks/chunk-6PVPNMXU.js +29 -0
  44. package/chunks/{chunk-BDBMYST4.js → chunk-6X4GWOPW.js} +1 -1
  45. package/chunks/{chunk-4ODB7WIB.js → chunk-6ZBPS62S.js} +1 -1
  46. package/chunks/{chunk-E5GIFWE3.js → chunk-766HLFAG.js} +54 -33
  47. package/chunks/{chunk-SDXIH6OA.js → chunk-76OFFG6L.js} +137 -5
  48. package/chunks/{chunk-ANHT55MR.js → chunk-7LH6CHKG.js} +1 -1
  49. package/chunks/{chunk-Y4CRUWFZ.js → chunk-7NDXG4MB.js} +60 -35
  50. package/chunks/{chunk-KPZNOZPC.js → chunk-7SWFAKVH.js} +22 -22
  51. package/chunks/{chunk-AYCDXHZB.js → chunk-7Z6JQEL6.js} +1 -1
  52. package/chunks/{chunk-5NWV4NFB.js → chunk-AZD6KAV7.js} +3 -3
  53. package/chunks/{chunk-7YBZGNEC.js → chunk-BKZEHVPV.js} +176 -168
  54. package/chunks/{chunk-WXAXH7IJ.js → chunk-BWQRDISK.js} +1 -1
  55. package/chunks/{chunk-X4CGDBKA.js → chunk-BZAEENUV.js} +3 -3
  56. package/chunks/{chunk-BF32GYSY.js → chunk-CHXKGIMK.js} +1 -1
  57. package/chunks/{chunk-4SLLEAQP.js → chunk-D53NR4GO.js} +562 -301
  58. package/chunks/{chunk-FLTN6NRU.js → chunk-D6ZOVZLF.js} +5 -1
  59. package/chunks/{chunk-NBMIC7DR.js → chunk-D7WXIW7H.js} +4 -4
  60. package/chunks/{chunk-MKLKHZAK.js → chunk-DPRMI6NU.js} +1 -1
  61. package/chunks/{chunk-AR27OPIU.js → chunk-DRIXALGM.js} +2 -2
  62. package/chunks/{chunk-5SCI6E3E.js → chunk-E4IMU4Y5.js} +1 -1
  63. package/chunks/{chunk-Z5Q65RVH.js → chunk-EC2ET5ZZ.js} +1 -1
  64. package/chunks/{chunk-B453NMZJ.js → chunk-EFIOE2EH.js} +3 -3
  65. package/chunks/{chunk-OKWRU4NO.js → chunk-EWXXMRMP.js} +3 -3
  66. package/chunks/{chunk-NEEB7UEN.js → chunk-FFFM6NJV.js} +1 -2
  67. package/chunks/{chunk-JVTCARQ6.js → chunk-G6LRTI62.js} +4 -4
  68. package/chunks/{chunk-6OH6A5EX.js → chunk-GEB2CGUV.js} +20262 -17752
  69. package/chunks/{chunk-OONJNQ42.js → chunk-GPSKDNEE.js} +3 -3
  70. package/chunks/{chunk-FNGK2Z5B.js → chunk-H4AR2JQF.js} +3 -3
  71. package/chunks/chunk-HTR4WV6U.js +327 -0
  72. package/chunks/chunk-IS2SBY6T.js +2256 -0
  73. package/chunks/{chunk-G45X5TRN.js → chunk-JCW2R7WC.js} +1 -72
  74. package/chunks/{chunk-6GUTHAN7.js → chunk-JHFVJQRO.js} +1 -1
  75. package/chunks/{chunk-IE4JSQ5L.js → chunk-JIBBZH37.js} +27 -23
  76. package/chunks/{chunk-UJEZQ562.js → chunk-JJEFX6U5.js} +3 -3
  77. package/chunks/{chunk-QOK6RMIP.js → chunk-JKFHJK5U.js} +4 -4
  78. package/chunks/{chunk-GA7VRJVN.js → chunk-JO7FGOSY.js} +5 -5
  79. package/chunks/{chunk-WOT64EP2.js → chunk-JTUAAVUT.js} +2 -2
  80. package/chunks/{chunk-MAQQGNQ5.js → chunk-JYS55H6Z.js} +66 -7
  81. package/chunks/{chunk-DA7OOKVN.js → chunk-KDPIV6WC.js} +29 -2
  82. package/chunks/{chunk-EIAK6Q2B.js → chunk-KHOVYUHX.js} +2 -2
  83. package/chunks/{chunk-OLMETXLX.js → chunk-KQQ757OQ.js} +2 -2
  84. package/chunks/{chunk-Z6UEAQTP.js → chunk-KSZZBDVD.js} +165 -48
  85. package/chunks/chunk-KWK7UE6L.js +6194 -0
  86. package/chunks/{chunk-OOCI5VVU.js → chunk-LIZRAKPB.js} +1 -1
  87. package/chunks/{chunk-VFAE4AGH.js → chunk-LPMBFOWH.js} +73 -68
  88. package/chunks/{chunk-IKP5DXZY.js → chunk-LYEKAAEH.js} +5 -5
  89. package/chunks/chunk-M7WBGLYP.js +151 -0
  90. package/chunks/{chunk-P2YAOGJD.js → chunk-MTSYH4MB.js} +3 -3
  91. package/chunks/{chunk-WKRXIHD6.js → chunk-N5ARKAVE.js} +8 -8
  92. package/chunks/chunk-NABLFI57.js +82 -0
  93. package/chunks/{chunk-CVDW42JT.js → chunk-NNFK277W.js} +1 -1
  94. package/chunks/{chunk-467G3SV5.js → chunk-NPQDJGKU.js} +1 -1
  95. package/chunks/chunk-OQ5SYCPE.js +10017 -0
  96. package/chunks/{chunk-C27BYUX6.js → chunk-OQB4EXO4.js} +14 -11
  97. package/chunks/{chunk-RELYEO3R.js → chunk-OUDZVU7H.js} +242 -1607
  98. package/chunks/{chunk-3EUZWNWA.js → chunk-PBED7USE.js} +1 -1
  99. package/chunks/{chunk-WBTZGWQ6.js → chunk-PIHKWN7M.js} +1 -1
  100. package/chunks/{chunk-XNP57UDV.js → chunk-PPIHLGNE.js} +2 -2
  101. package/chunks/{chunk-Q4RBU7WX.js → chunk-PSVSP2OS.js} +6 -6
  102. package/chunks/{chunk-BRXIO5WY.js → chunk-Q2V2ADXF.js} +7 -7
  103. package/chunks/{chunk-JDI67JFB.js → chunk-Q2YKNMLS.js} +3 -3
  104. package/chunks/{chunk-BAIEQKR5.js → chunk-Q3GGJDYN.js} +5 -5
  105. package/chunks/{chunk-PBATSWUQ.js → chunk-QBUDF33N.js} +1 -1
  106. package/chunks/{chunk-OMH3276Y.js → chunk-QD6BRERJ.js} +7 -7
  107. package/chunks/{chunk-Y2ENGUD6.js → chunk-QKTHJXCS.js} +1 -1
  108. package/chunks/{chunk-BVLROR2T.js → chunk-QLJUC7TG.js} +1 -1
  109. package/chunks/{chunk-UEY4AYUL.js → chunk-QNLNLENL.js} +2 -2
  110. package/chunks/{chunk-7KDI2IB2.js → chunk-QSJ6JIF5.js} +4 -4
  111. package/chunks/{chunk-Q3ZBFXK4.js → chunk-QUHJRRUA.js} +126 -30
  112. package/chunks/{chunk-N6YTEVLV.js → chunk-R3BCL5XW.js} +10 -4
  113. package/chunks/{chunk-EVSTCA7S.js → chunk-R7MPKABX.js} +307 -86
  114. package/chunks/{chunk-RFIAR4YL.js → chunk-RV4C2ZFG.js} +1 -1
  115. package/chunks/{chunk-NIJEXGV6.js → chunk-RVLZCXEE.js} +79 -10
  116. package/chunks/{chunk-T7DDD7CZ.js → chunk-RYSMKY43.js} +4 -4
  117. package/chunks/{chunk-MC2DOZS7.js → chunk-S3YQCNJE.js} +3 -3
  118. package/chunks/{chunk-4WUAQ2DO.js → chunk-SP32MK6J.js} +2 -2
  119. package/chunks/{chunk-JNWZQ27S.js → chunk-SP5WRGVG.js} +3 -3
  120. package/chunks/{chunk-FSL5W5TI.js → chunk-T2L47JJK.js} +3 -3
  121. package/chunks/{chunk-TB6UDU4T.js → chunk-THJNPLI4.js} +16 -16
  122. package/chunks/{chunk-TCKTNY66.js → chunk-TPR35HHZ.js} +6 -6
  123. package/chunks/{chunk-UQES76OO.js → chunk-TXRKCFWS.js} +6 -6
  124. package/chunks/chunk-U7ZFW55U.js +2098 -0
  125. package/chunks/{chunk-W7H223ZZ.js → chunk-UGYMA4EI.js} +1 -1
  126. package/chunks/{chunk-X6YQWCIJ.js → chunk-UH3WSE5L.js} +13 -1
  127. package/chunks/{chunk-R3VWUU2E.js → chunk-VYPFXUCB.js} +1 -1
  128. package/chunks/{chunk-2DXOIVUI.js → chunk-WCFTQD7H.js} +11 -11
  129. package/chunks/chunk-WHGVTP7Q.js +1049 -0
  130. package/chunks/{chunk-PWVTCGBP.js → chunk-WML6JOGQ.js} +31 -19
  131. package/chunks/{chunk-D2VIDMVM.js → chunk-X6N25LXS.js} +2 -2
  132. package/chunks/{chunk-Z5R4JMOL.js → chunk-X7XWGRDT.js} +4 -4
  133. package/chunks/chunk-XHATNRQA.js +1500 -0
  134. package/chunks/{chunk-V25Z5UUB.js → chunk-Y2DAH52F.js} +7 -6
  135. package/chunks/{chunk-S35ZDXOS.js → chunk-YM3SZTH4.js} +2 -1
  136. package/chunks/{chunk-GKY2OJ7R.js → chunk-ZHERRXZJ.js} +1 -1
  137. package/chunks/{computer-use-R7KA6UJ6.js → computer-use-MV4K6WJM.js} +41 -37
  138. package/chunks/{config-utils-6FXFJUYB.js → config-utils-WYUQ7II4.js} +3 -3
  139. package/chunks/{contextCommand-KAQQPHZ4.js → contextCommand-TQD36VNX.js} +38 -34
  140. package/chunks/{create-sub-session-X5RVIHCK.js → create-sub-session-AZ77LBL3.js} +3 -3
  141. package/chunks/{create-sub-session-TDPDBU4K.js → create-sub-session-JOW4BKMC.js} +36 -32
  142. package/chunks/{cron-create-AC5FFLN7.js → cron-create-KTWJM7QT.js} +5 -5
  143. package/chunks/{cron-delete-JEB3FAHA.js → cron-delete-2P3I5ULL.js} +5 -5
  144. package/chunks/{cron-list-NBYPCNIB.js → cron-list-PXDPGEDQ.js} +5 -5
  145. package/chunks/{daemon-RG2MAI6T.js → daemon-KLPTQIE4.js} +138 -81
  146. package/chunks/daemon-status-provider-TII4SMCZ.js +81 -0
  147. package/chunks/{de-I7ZIYXZC.js → de-4IBXM7CN.js} +5 -1
  148. package/chunks/{dist-2BHAYBKP.js → dist-HMU6CYS4.js} +2 -2
  149. package/chunks/{dist-AU7NQQRP.js → dist-OAV7LJGJ.js} +1 -1
  150. package/chunks/{dist-FUTEXY6A.js → dist-OMW6WDEO.js} +1 -1
  151. package/chunks/{dist-2MIU4UUH.js → dist-PJLG2XYX.js} +1 -1
  152. package/chunks/{dist-53PZYC5B.js → dist-UIFWIFRO.js} +2 -2
  153. package/chunks/{dist-WGTQO7F2.js → dist-XRYV6TJP.js} +65 -25
  154. package/chunks/{earlyInputCapture-WC7RI5HV.js → earlyInputCapture-2V57RG6H.js} +37 -33
  155. package/chunks/{edit-6MHKCJCM.js → edit-TTUH7PWR.js} +43 -41
  156. package/chunks/{en-XE34GKAA.js → en-USMCCJAJ.js} +5 -1
  157. package/chunks/{enter-worktree-O7VJ2E7A.js → enter-worktree-D4IVCXYB.js} +41 -37
  158. package/chunks/{enterPlanMode-5XYAALIO.js → enterPlanMode-WRUJTVYN.js} +47 -38
  159. package/chunks/{environment-LSKFNLBU.js → environment-SEPKXB2C.js} +38 -34
  160. package/chunks/{errors-ZFVCY6HG.js → errors-YSVGBLBU.js} +38 -34
  161. package/chunks/{exit-worktree-MYIK66T7.js → exit-worktree-MZ4JSSP6.js} +41 -37
  162. package/chunks/{exitPlanMode-7MBNU76O.js → exitPlanMode-HAZLSSOJ.js} +41 -37
  163. package/chunks/{fast-path-RNLIB64C.js → fast-path-EVBVIE2U.js} +4 -3
  164. package/chunks/{fast-path-settings-DAOVFADC.js → fast-path-settings-XB3CPUJT.js} +2 -2
  165. package/chunks/{fr-X7KDVZIY.js → fr-WVHEBDDB.js} +5 -1
  166. package/chunks/{gemini-WK5ISEAQ.js → gemini-APQ76464.js} +100 -95
  167. package/chunks/{geminiContentGenerator-NUJQBZBW.js → geminiContentGenerator-LB4MA2LI.js} +5 -5
  168. package/chunks/{getMachineId-bsd-EXV7SWPA.js → getMachineId-bsd-QFVLPUPT.js} +1 -1
  169. package/chunks/{getMachineId-darwin-IUOMFXU3.js → getMachineId-darwin-DGMQQE2E.js} +1 -1
  170. package/chunks/{getMachineId-linux-K7XJYFHL.js → getMachineId-linux-R4Z6CSWC.js} +1 -1
  171. package/chunks/{getMachineId-unsupported-EA5FDRJ6.js → getMachineId-unsupported-Z3SBVBUV.js} +1 -1
  172. package/chunks/{getMachineId-win-KBA6RAI5.js → getMachineId-win-SCK5UFDT.js} +1 -1
  173. package/chunks/{glob-7P6RYY4L.js → glob-LABYMYKG.js} +43 -39
  174. package/chunks/{grep-V3QHNP2J.js → grep-HKIKJCAS.js} +43 -39
  175. package/chunks/{handleAutoUpdate-AAQ6PL3E.js → handleAutoUpdate-RWAAL2UM.js} +40 -36
  176. package/chunks/{i18n-B7IO7WQT.js → i18n-ZUVDAJIJ.js} +37 -33
  177. package/chunks/{initializer-E5TIC3CW.js → initializer-7YUHIC36.js} +43 -39
  178. package/chunks/{installationInfo-XLPNAISK.js → installationInfo-DVEOMWDE.js} +39 -33
  179. package/chunks/{ja-2ICT3KXF.js → ja-KY4ROZTE.js} +5 -1
  180. package/chunks/{keychain-token-storage-DWRJMNH3.js → keychain-token-storage-6ACJDYIB.js} +3 -3
  181. package/chunks/list-WHCZSIR2.js +82 -0
  182. package/chunks/{loadedSettingsAdapter-X5BSC6CE.js → loadedSettingsAdapter-YCWN6AK3.js} +42 -38
  183. package/chunks/{loop-wakeup-HMHCT5GU.js → loop-wakeup-RNMRVA66.js} +6 -6
  184. package/chunks/{ls-IW5HYDG4.js → ls-J2ZI5XYK.js} +5 -5
  185. package/chunks/{lsp-4RL52YIZ.js → lsp-UMS3NUB5.js} +3 -3
  186. package/chunks/managed-npm-update-PG3463CJ.js +333 -0
  187. package/chunks/{mcp-4C4HWXAR.js → mcp-VLHDCKAN.js} +42 -38
  188. package/chunks/{monitor-3CJDNZB2.js → monitor-GG4F4YM6.js} +41 -37
  189. package/chunks/nonInteractiveCli-UYXYV4YX.js +133 -0
  190. package/chunks/{notebook-edit-MX366HCT.js → notebook-edit-US4VLN6Q.js} +44 -42
  191. package/chunks/{openaiContentGenerator-KRPNNJGZ.js → openaiContentGenerator-CVEDTMDB.js} +20 -18
  192. package/chunks/{pidfile-K7T2JLUJ.js → pidfile-QQ45OIOY.js} +37 -33
  193. package/chunks/{processUtils-YXL3VIBR.js → processUtils-3WMHLQE5.js} +2 -2
  194. package/chunks/{pt-JJ4XPIBP.js → pt-OK455PLH.js} +5 -1
  195. package/chunks/{qwenContentGenerator-GJVXFZ3U.js → qwenContentGenerator-Y2GRNYZQ.js} +42 -38
  196. package/chunks/{qwenOAuth2-UZTIBQLY.js → qwenOAuth2-J2X6E5VO.js} +18 -16
  197. package/chunks/{read-file-S5XQSYOW.js → read-file-C7Z266CU.js} +13 -11
  198. package/chunks/{read-mcp-resource-OIBCNIX7.js → read-mcp-resource-F6HYMDUY.js} +3 -3
  199. package/chunks/{record-artifact-HDMK4LHG.js → record-artifact-7GCFLDD7.js} +3 -3
  200. package/chunks/{resumeHistoryUtils-IKR6XD2S.js → resumeHistoryUtils-KBQWX77U.js} +43 -39
  201. package/chunks/{ripGrep-H65GRSQX.js → ripGrep-RW26MTQ3.js} +36 -32
  202. package/chunks/{ru-STR4KTW7.js → ru-7SPDGMGD.js} +5 -1
  203. package/chunks/{run-qwen-serve-7SKAQOAA.js → run-qwen-serve-MXFMOMEL.js} +104 -82
  204. package/chunks/{runtime-I2STBGPR.js → runtime-APNO3V6D.js} +48 -42
  205. package/chunks/{scheduler-6F7HETNO.js → scheduler-L6FYCGVO.js} +36 -32
  206. package/chunks/sdk-exporters-grpc-ETLH47EP.js +23214 -0
  207. package/chunks/sdk-exporters-http-IDGLRBGP.js +563 -0
  208. package/chunks/sdk-impl-5ESZBGJQ.js +9186 -0
  209. package/chunks/{send-message-WXVVK4DB.js → send-message-PYIJ2PZL.js} +6 -4
  210. package/chunks/{serve-4ATEWSEA.js → serve-6QBXDVWT.js} +42 -38
  211. package/chunks/{server-YPUPFV2O.js → server-5TJJEMVQ.js} +1006 -305
  212. package/chunks/{session-AZFIERIY.js → session-BWEUHKQB.js} +92 -176
  213. package/chunks/{settings-EFQHLTM3.js → settings-O7IUQNRR.js} +45 -41
  214. package/chunks/{shell-FWXWBJ4Q.js → shell-R5L4NQYY.js} +36 -32
  215. package/chunks/{skill-A634MNCD.js → skill-ITEOSNW6.js} +24 -20
  216. package/chunks/{spawnChannel-KKBGGR47.js → spawnChannel-E7NTWSGW.js} +38 -34
  217. package/chunks/{src-BVROLD6N.js → src-FFXGUTNL.js} +303 -237
  218. package/chunks/{standalone-update-ERLA3BDC.js → standalone-update-JCJOXW4P.js} +38 -34
  219. package/chunks/{startInteractiveUI-3VZ23WAY.js → startInteractiveUI-IJSBLZFO.js} +1057 -864
  220. package/chunks/{syntheticOutput-HCUFXSIA.js → syntheticOutput-H7RTI5KL.js} +4 -4
  221. package/chunks/{task-create-RIY5JTFC.js → task-create-7474AJJD.js} +10 -8
  222. package/chunks/{task-list-XBUCV3CO.js → task-list-633HGOIB.js} +6 -6
  223. package/chunks/{task-stop-QDFCCYR5.js → task-stop-MNUGHPIA.js} +3 -3
  224. package/chunks/{task-update-7PXKJQOI.js → task-update-66GQB5LI.js} +10 -8
  225. package/chunks/{team-create-ZZO7QFQ7.js → team-create-OVSZTJZO.js} +44 -40
  226. package/chunks/{team-delete-TNSSE2S5.js → team-delete-BB3CG3QF.js} +6 -6
  227. package/chunks/{team-plan-approval-3BZBJ46K.js → team-plan-approval-SLEVDLT5.js} +41 -37
  228. package/chunks/{theme-manager-FSFWNXFJ.js → theme-manager-V6ZQISHM.js} +37 -33
  229. package/chunks/{todoWrite-OMAIGB6V.js → todoWrite-KRAUN54W.js} +5 -5
  230. package/chunks/{tool-search-VYXAAIDW.js → tool-search-KYIF6C6E.js} +21 -17
  231. package/chunks/{total-session-admission-PSMLQICS.js → total-session-admission-EU77XTL7.js} +42 -38
  232. package/chunks/{trustedFolders-QA3RK2NV.js → trustedFolders-DDEF3ADH.js} +37 -33
  233. package/chunks/{update-relaunch-LNLZFX3J.js → update-relaunch-XEZTDP6K.js} +17 -17
  234. package/chunks/updateCheck-KZ5LZ545.js +89 -0
  235. package/chunks/{useAutoAcceptIndicator-DIWN27LT.js → useAutoAcceptIndicator-47EZERGQ.js} +47 -43
  236. package/chunks/{validateNonInterActiveAuth-LOEOFCAF.js → validateNonInterActiveAuth-J2DM4LWZ.js} +79 -75
  237. package/chunks/{version-HBF2VBLE.js → version-PN7WYXHP.js} +1 -1
  238. package/chunks/{web-fetch-BWGSD2BD.js → web-fetch-WRI5QRFR.js} +100 -42
  239. package/chunks/{web-search-OOHTCVR3.js → web-search-2HCXNAVX.js} +111 -60
  240. package/chunks/{workflow-LJAJBOR4.js → workflow-U5XBPGQZ.js} +48 -43
  241. package/chunks/workspace-providers-status-2T54GIJZ.js +79 -0
  242. package/chunks/{workspace-registration-store-4EHGQW4Y.js → workspace-registration-store-F3V4KBIW.js} +8 -2
  243. package/chunks/{workspace-registry-BKD7VC4Y.js → workspace-registry-U6QVZ5BU.js} +42 -38
  244. package/chunks/{workspace-service-75RHX6KR.js → workspace-service-734D36QD.js} +49 -45
  245. package/chunks/{workspace-skills-status-WBZBZI6A.js → workspace-skills-status-5ABUKOAQ.js} +43 -39
  246. package/chunks/write-file-CIH4I4CS.js +66 -0
  247. package/chunks/{zh-TW-4RR3YHNN.js → zh-TW-BM47YBFH.js} +5 -1
  248. package/chunks/{zh-6ANG2HTL.js → zh-WY5DWYZD.js} +5 -1
  249. package/cli-entry.js +164 -12
  250. package/cli.js +18 -11
  251. package/locales/ca.js +772 -203
  252. package/locales/de.js +8 -2
  253. package/locales/en.js +8 -2
  254. package/locales/fr.js +8 -2
  255. package/locales/ja.js +8 -2
  256. package/locales/pt.js +8 -2
  257. package/locales/ru.js +8 -2
  258. package/locales/zh-TW.js +8 -2
  259. package/locales/zh.js +8 -2
  260. package/package.json +3 -3
  261. package/web-shell/assets/{arc-Buk1besA.js → arc-ByltRugA.js} +1 -1
  262. package/web-shell/assets/{architectureDiagram-3BPJPVTR-B1aUKYDC.js → architectureDiagram-3BPJPVTR-CCRTto5d.js} +1 -1
  263. package/web-shell/assets/{blockDiagram-GPEHLZMM-CRTdg3Zx.js → blockDiagram-GPEHLZMM-Jfy36u1L.js} +1 -1
  264. package/web-shell/assets/{c4Diagram-AAUBKEIU-DFdRMp5g.js → c4Diagram-AAUBKEIU-4d5FfEZ0.js} +1 -1
  265. package/web-shell/assets/channel-4N2UIFcG.js +1 -0
  266. package/web-shell/assets/{chunk-2J33WTMH-4rYQdkEI.js → chunk-2J33WTMH-BPwxCEro.js} +1 -1
  267. package/web-shell/assets/{chunk-4BX2VUAB-Coi-pQJy.js → chunk-4BX2VUAB-jY7ZmJWY.js} +1 -1
  268. package/web-shell/assets/{chunk-55IACEB6-BtBjz02t.js → chunk-55IACEB6-C98HgCsS.js} +1 -1
  269. package/web-shell/assets/{chunk-727SXJPM-CGYOWorl.js → chunk-727SXJPM-cDu-ge-q.js} +1 -1
  270. package/web-shell/assets/{chunk-AQP2D5EJ-CH5AKhqx.js → chunk-AQP2D5EJ-BKdJwxXK.js} +1 -1
  271. package/web-shell/assets/{chunk-FMBD7UC4-Cd50-w85.js → chunk-FMBD7UC4-DnuxqwMu.js} +1 -1
  272. package/web-shell/assets/{chunk-ND2GUHAM-C2wF3KCK.js → chunk-ND2GUHAM-C4fZNPv0.js} +1 -1
  273. package/web-shell/assets/{chunk-QZHKN3VN-pCeRTaWi.js → chunk-QZHKN3VN-Cf4XWOmz.js} +1 -1
  274. package/web-shell/assets/classDiagram-4FO5ZUOK-Q4dYOtsh.js +1 -0
  275. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-Q4dYOtsh.js +1 -0
  276. package/web-shell/assets/{cose-bilkent-S5V4N54A-B-_fAB6D.js → cose-bilkent-S5V4N54A-C82mFiqj.js} +1 -1
  277. package/web-shell/assets/{dagre-BM42HDAG-ChSPNHpL.js → dagre-BM42HDAG-Df8KACER.js} +1 -1
  278. package/web-shell/assets/{diagram-2AECGRRQ-BX7cFOF3.js → diagram-2AECGRRQ-EzNs7s_2.js} +1 -1
  279. package/web-shell/assets/{diagram-5GNKFQAL-BQUTW92n.js → diagram-5GNKFQAL-BRLNvreg.js} +1 -1
  280. package/web-shell/assets/{diagram-KO2AKTUF-BkYPh3e4.js → diagram-KO2AKTUF-2HLYHRjC.js} +1 -1
  281. package/web-shell/assets/{diagram-LMA3HP47-Cl6jsNyx.js → diagram-LMA3HP47-DeH0NzSp.js} +1 -1
  282. package/web-shell/assets/{diagram-OG6HWLK6-DRWoHz8n.js → diagram-OG6HWLK6-k5Gn47-G.js} +1 -1
  283. package/web-shell/assets/{erDiagram-TEJ5UH35-CGvFcZco.js → erDiagram-TEJ5UH35-gPHFo79f.js} +1 -1
  284. package/web-shell/assets/{flowDiagram-I6XJVG4X-vms6oVdv.js → flowDiagram-I6XJVG4X-DYBOiTRW.js} +1 -1
  285. package/web-shell/assets/{ganttDiagram-6RSMTGT7-ukT_sfmi.js → ganttDiagram-6RSMTGT7-cxjAuic9.js} +1 -1
  286. package/web-shell/assets/{gitGraphDiagram-PVQCEYII-Bn2ZE2Ut.js → gitGraphDiagram-PVQCEYII-3nPqpmCP.js} +1 -1
  287. package/web-shell/assets/index-B7jzUZ_s.css +5 -0
  288. package/web-shell/assets/{index-wFXp7W68.js → index-Cl8d-1bK.js} +1 -1
  289. package/web-shell/assets/index-gE8OWwj_.js +1197 -0
  290. package/web-shell/assets/{infoDiagram-5YYISTIA-DHJdSi7x.js → infoDiagram-5YYISTIA-Dph21pR5.js} +1 -1
  291. package/web-shell/assets/{ishikawaDiagram-YF4QCWOH-DOvd2Wph.js → ishikawaDiagram-YF4QCWOH-Cjg1hSaG.js} +1 -1
  292. package/web-shell/assets/{journeyDiagram-JHISSGLW-CH_urMCT.js → journeyDiagram-JHISSGLW-CR-IzvnU.js} +1 -1
  293. package/web-shell/assets/{kanban-definition-UN3LZRKU-FKiBdgbH.js → kanban-definition-UN3LZRKU-BYmuybuC.js} +1 -1
  294. package/web-shell/assets/{linear-0ZVQFVKf.js → linear-CngEEoy8.js} +1 -1
  295. package/web-shell/assets/{mermaid.core-DJ05ZZIK.js → mermaid.core-G6fbZRPf.js} +5 -5
  296. package/web-shell/assets/{mindmap-definition-RKZ34NQL-BPuUhkUm.js → mindmap-definition-RKZ34NQL-BtnqnUwJ.js} +1 -1
  297. package/web-shell/assets/{pieDiagram-4H26LBE5-yLFKcXyG.js → pieDiagram-4H26LBE5-XTq6UHIA.js} +1 -1
  298. package/web-shell/assets/{quadrantDiagram-W4KKPZXB-irWqc1pE.js → quadrantDiagram-W4KKPZXB-D1J5PrsS.js} +1 -1
  299. package/web-shell/assets/{requirementDiagram-4Y6WPE33-B_4uMoIV.js → requirementDiagram-4Y6WPE33-CLcBUy3t.js} +1 -1
  300. package/web-shell/assets/{sankeyDiagram-5OEKKPKP-ciA4GPwk.js → sankeyDiagram-5OEKKPKP-iwKV02_6.js} +1 -1
  301. package/web-shell/assets/{sequenceDiagram-3UESZ5HK-CRdZvy0U.js → sequenceDiagram-3UESZ5HK-7NFYQcEX.js} +1 -1
  302. package/web-shell/assets/{stateDiagram-AJRCARHV-DaYIkCCn.js → stateDiagram-AJRCARHV-Bvm4Wih6.js} +1 -1
  303. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-xXU_zO2Z.js +1 -0
  304. package/web-shell/assets/{timeline-definition-PNZ67QCA-oBUKv6iH.js → timeline-definition-PNZ67QCA-B4FZFE9O.js} +1 -1
  305. package/web-shell/assets/{vennDiagram-CIIHVFJN-CGW9Sdmb.js → vennDiagram-CIIHVFJN-CvMBpmtL.js} +1 -1
  306. package/web-shell/assets/{wardley-L42UT6IY-CvwKJOCm.js → wardley-L42UT6IY-E3ag2327.js} +1 -1
  307. package/web-shell/assets/{wardleyDiagram-YWT4CUSO-Ipc260sN.js → wardleyDiagram-YWT4CUSO-BEXWlgxC.js} +1 -1
  308. package/web-shell/assets/{xychartDiagram-2RQKCTM6-D6-CM7pK.js → xychartDiagram-2RQKCTM6-CICK05gI.js} +1 -1
  309. package/web-shell/index.html +2 -2
  310. package/chunks/chunk-ETD6K42I.js +0 -358
  311. package/chunks/chunk-I5NLVPZJ.js +0 -45
  312. package/chunks/chunk-ONWW74X6.js +0 -74639
  313. package/chunks/chunk-W7FJ3N32.js +0 -49
  314. package/chunks/daemon-status-provider-LVTVJGAD.js +0 -77
  315. package/chunks/list-3CZR5I42.js +0 -78
  316. package/chunks/nonInteractiveCli-QTEHDDFH.js +0 -129
  317. package/chunks/updateCheck-JJEUQ54U.js +0 -73
  318. package/chunks/workspace-providers-status-FYV7TTHA.js +0 -75
  319. package/chunks/write-file-M2DTFILF.js +0 -599
  320. package/web-shell/assets/channel-04R0vLbG.js +0 -1
  321. package/web-shell/assets/classDiagram-4FO5ZUOK-Bw9SOwAV.js +0 -1
  322. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-Bw9SOwAV.js +0 -1
  323. package/web-shell/assets/index-DgkKrjw3.js +0 -1187
  324. package/web-shell/assets/index-Rv6mOAN9.css +0 -5
  325. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-DWBoO4UY.js +0 -1
  326. package/chunks/{chunk-PEJWA3QQ.js → chunk-QZJY47IE.js} +5 -5
@@ -0,0 +1,2256 @@
1
+ // Force strict mode and setup for ESM
2
+ "use strict";
3
+ import {
4
+ DEFAULT_SENSITIVE_SPAN_ATTRIBUTE_MAX_LENGTH,
5
+ EVENT_CHAT_COMPRESSION,
6
+ SERVICE_NAME,
7
+ SPAN_HOOK,
8
+ SPAN_INTERACTION,
9
+ SPAN_LLM_REQUEST,
10
+ SPAN_SUBAGENT,
11
+ SPAN_TOOL,
12
+ SPAN_TOOL_BLOCKED_ON_USER,
13
+ SPAN_TOOL_EXECUTION,
14
+ safeJsonStringify
15
+ } from "./chunk-M7WBGLYP.js";
16
+ import {
17
+ createDebugLogger,
18
+ getCurrentSessionId,
19
+ setSessionContext,
20
+ setShellTracePropagation
21
+ } from "./chunk-OQB4EXO4.js";
22
+ import {
23
+ DiagLogLevel,
24
+ ROOT_CONTEXT,
25
+ SpanKind,
26
+ SpanStatusCode,
27
+ TraceFlags,
28
+ ValueType,
29
+ context,
30
+ diag,
31
+ init_esm,
32
+ metrics,
33
+ trace
34
+ } from "./chunk-THJNPLI4.js";
35
+ import {
36
+ init_esbuild_shims
37
+ } from "./chunk-5O2XNYP6.js";
38
+ import {
39
+ __name
40
+ } from "./chunk-J2S4EL5Y.js";
41
+
42
+ // packages/core/src/telemetry/metrics.ts
43
+ init_esbuild_shims();
44
+ init_esm();
45
+ var TOOL_CALL_COUNT = `${SERVICE_NAME}.tool.call.count`;
46
+ var TOOL_CALL_LATENCY = `${SERVICE_NAME}.tool.call.latency`;
47
+ var API_REQUEST_COUNT = `${SERVICE_NAME}.api.request.count`;
48
+ var API_REQUEST_LATENCY = `${SERVICE_NAME}.api.request.latency`;
49
+ var TOKEN_USAGE = `${SERVICE_NAME}.token.usage`;
50
+ var SESSION_COUNT = `${SERVICE_NAME}.session.count`;
51
+ var FILE_OPERATION_COUNT = `${SERVICE_NAME}.file.operation.count`;
52
+ var INVALID_CHUNK_COUNT = `${SERVICE_NAME}.chat.invalid_chunk.count`;
53
+ var CONTENT_RETRY_COUNT = `${SERVICE_NAME}.chat.content_retry.count`;
54
+ var CONTENT_RETRY_FAILURE_COUNT = `${SERVICE_NAME}.chat.content_retry_failure.count`;
55
+ var API_RETRY_COUNT = `${SERVICE_NAME}.api.retry.count`;
56
+ var MODEL_SLASH_COMMAND_CALL_COUNT = `${SERVICE_NAME}.slash_command.model.call_count`;
57
+ var SUBAGENT_EXECUTION_COUNT = `${SERVICE_NAME}.subagent.execution.count`;
58
+ var ARENA_SESSION_COUNT = `${SERVICE_NAME}.arena.session.count`;
59
+ var ARENA_SESSION_DURATION = `${SERVICE_NAME}.arena.session.duration`;
60
+ var ARENA_AGENT_COUNT = `${SERVICE_NAME}.arena.agent.count`;
61
+ var ARENA_AGENT_DURATION = `${SERVICE_NAME}.arena.agent.duration`;
62
+ var ARENA_AGENT_TOKENS = `${SERVICE_NAME}.arena.agent.tokens`;
63
+ var ARENA_RESULT_SELECTED = `${SERVICE_NAME}.arena.result.selected`;
64
+ var STARTUP_TIME = `${SERVICE_NAME}.startup.duration`;
65
+ var MEMORY_USAGE = `${SERVICE_NAME}.memory.usage`;
66
+ var CPU_USAGE = `${SERVICE_NAME}.cpu.usage`;
67
+ var TOOL_QUEUE_DEPTH = `${SERVICE_NAME}.tool.queue.depth`;
68
+ var TOOL_EXECUTION_BREAKDOWN = `${SERVICE_NAME}.tool.execution.breakdown`;
69
+ var TOKEN_EFFICIENCY = `${SERVICE_NAME}.token.efficiency`;
70
+ var API_REQUEST_BREAKDOWN = `${SERVICE_NAME}.api.request.breakdown`;
71
+ var PERFORMANCE_SCORE = `${SERVICE_NAME}.performance.score`;
72
+ var REGRESSION_DETECTION = `${SERVICE_NAME}.performance.regression`;
73
+ var REGRESSION_PERCENTAGE_CHANGE = `${SERVICE_NAME}.performance.regression.percentage_change`;
74
+ var BASELINE_COMPARISON = `${SERVICE_NAME}.performance.baseline.comparison`;
75
+ var MEMORY_EXTRACT_COUNT = `${SERVICE_NAME}.memory.extract.count`;
76
+ var MEMORY_EXTRACT_DURATION = `${SERVICE_NAME}.memory.extract.duration`;
77
+ var MEMORY_DREAM_COUNT = `${SERVICE_NAME}.memory.dream.count`;
78
+ var MEMORY_DREAM_DURATION = `${SERVICE_NAME}.memory.dream.duration`;
79
+ var MEMORY_RECALL_COUNT = `${SERVICE_NAME}.memory.recall.count`;
80
+ var MEMORY_RECALL_DURATION = `${SERVICE_NAME}.memory.recall.duration`;
81
+ var CHANNEL_MEMORY_RECALL_COUNT = `${SERVICE_NAME}.channel.memory.recall.count`;
82
+ var CHANNEL_MEMORY_RECALL_DURATION = `${SERVICE_NAME}.channel.memory.recall.duration`;
83
+ var CHANNEL_MEMORY_RECALL_SELECTED_COUNT = `${SERVICE_NAME}.channel.memory.recall.selected_count`;
84
+ var baseMetricDefinition = {
85
+ // session.id on metrics is opt-in: each session is a new value, so
86
+ // attaching it by default would create unbounded time-series fan-out on
87
+ // every metric backend. Operators who need session-level metric slicing
88
+ // can enable QWEN_TELEMETRY_METRICS_INCLUDE_SESSION_ID or
89
+ // telemetry.metrics.includeSessionId. Spans and logs always carry
90
+ // session.id for trace/log correlation.
91
+ getCommonAttributes: /* @__PURE__ */ __name((config) => {
92
+ const out = {};
93
+ if (config.getTelemetryMetricsIncludeSessionId()) {
94
+ out["session.id"] = config.getSessionId();
95
+ }
96
+ return out;
97
+ }, "getCommonAttributes")
98
+ };
99
+ var COUNTER_DEFINITIONS = {
100
+ [TOOL_CALL_COUNT]: {
101
+ description: "Counts tool calls, tagged by function name and success.",
102
+ valueType: ValueType.INT,
103
+ assign: /* @__PURE__ */ __name((c) => toolCallCounter = c, "assign"),
104
+ attributes: {}
105
+ },
106
+ [API_REQUEST_COUNT]: {
107
+ description: "Counts API requests, tagged by model and status.",
108
+ valueType: ValueType.INT,
109
+ assign: /* @__PURE__ */ __name((c) => apiRequestCounter = c, "assign"),
110
+ attributes: {}
111
+ },
112
+ [TOKEN_USAGE]: {
113
+ description: "Counts the total number of tokens used.",
114
+ valueType: ValueType.INT,
115
+ assign: /* @__PURE__ */ __name((c) => tokenUsageCounter = c, "assign"),
116
+ attributes: {}
117
+ },
118
+ [SESSION_COUNT]: {
119
+ description: "Count of CLI sessions started.",
120
+ valueType: ValueType.INT,
121
+ assign: /* @__PURE__ */ __name((c) => sessionCounter = c, "assign"),
122
+ attributes: {}
123
+ },
124
+ [FILE_OPERATION_COUNT]: {
125
+ description: "Counts file operations (create, read, update).",
126
+ valueType: ValueType.INT,
127
+ assign: /* @__PURE__ */ __name((c) => fileOperationCounter = c, "assign"),
128
+ attributes: {}
129
+ },
130
+ [INVALID_CHUNK_COUNT]: {
131
+ description: "Counts invalid chunks received from a stream.",
132
+ valueType: ValueType.INT,
133
+ assign: /* @__PURE__ */ __name((c) => invalidChunkCounter = c, "assign"),
134
+ attributes: {}
135
+ },
136
+ [CONTENT_RETRY_COUNT]: {
137
+ description: "Counts retries due to content errors (e.g., empty stream).",
138
+ valueType: ValueType.INT,
139
+ assign: /* @__PURE__ */ __name((c) => contentRetryCounter = c, "assign"),
140
+ attributes: {}
141
+ },
142
+ [CONTENT_RETRY_FAILURE_COUNT]: {
143
+ description: "Counts occurrences of all content retries failing.",
144
+ valueType: ValueType.INT,
145
+ assign: /* @__PURE__ */ __name((c) => contentRetryFailureCounter = c, "assign"),
146
+ attributes: {}
147
+ },
148
+ [API_RETRY_COUNT]: {
149
+ description: "Counts HTTP-status retries (429/5xx) at LLM call sites, emitted by retryWithBackoff onRetry callback.",
150
+ valueType: ValueType.INT,
151
+ assign: /* @__PURE__ */ __name((c) => apiRetryCounter = c, "assign"),
152
+ attributes: {}
153
+ },
154
+ [MODEL_SLASH_COMMAND_CALL_COUNT]: {
155
+ description: "Counts model slash command calls.",
156
+ valueType: ValueType.INT,
157
+ assign: /* @__PURE__ */ __name((c) => modelSlashCommandCallCounter = c, "assign"),
158
+ attributes: {}
159
+ },
160
+ [EVENT_CHAT_COMPRESSION]: {
161
+ description: "Counts chat compression events.",
162
+ valueType: ValueType.INT,
163
+ assign: /* @__PURE__ */ __name((c) => chatCompressionCounter = c, "assign"),
164
+ attributes: {}
165
+ }
166
+ };
167
+ var HISTOGRAM_DEFINITIONS = {
168
+ [TOOL_CALL_LATENCY]: {
169
+ description: "Latency of tool calls in milliseconds.",
170
+ unit: "ms",
171
+ valueType: ValueType.INT,
172
+ assign: /* @__PURE__ */ __name((h) => toolCallLatencyHistogram = h, "assign"),
173
+ attributes: {}
174
+ },
175
+ [API_REQUEST_LATENCY]: {
176
+ description: "Latency of API requests in milliseconds.",
177
+ unit: "ms",
178
+ valueType: ValueType.INT,
179
+ assign: /* @__PURE__ */ __name((h) => apiRequestLatencyHistogram = h, "assign"),
180
+ attributes: {}
181
+ }
182
+ };
183
+ var PERFORMANCE_COUNTER_DEFINITIONS = {
184
+ [REGRESSION_DETECTION]: {
185
+ description: "Performance regression detection events.",
186
+ valueType: ValueType.INT,
187
+ assign: /* @__PURE__ */ __name((c) => regressionDetectionCounter = c, "assign"),
188
+ attributes: {}
189
+ }
190
+ };
191
+ var PERFORMANCE_HISTOGRAM_DEFINITIONS = {
192
+ [STARTUP_TIME]: {
193
+ description: "CLI startup time in milliseconds, broken down by initialization phase.",
194
+ unit: "ms",
195
+ valueType: ValueType.DOUBLE,
196
+ assign: /* @__PURE__ */ __name((h) => startupTimeHistogram = h, "assign"),
197
+ attributes: {}
198
+ },
199
+ [MEMORY_USAGE]: {
200
+ description: "Memory usage in bytes.",
201
+ unit: "bytes",
202
+ valueType: ValueType.INT,
203
+ assign: /* @__PURE__ */ __name((h) => memoryUsageGauge = h, "assign"),
204
+ attributes: {}
205
+ },
206
+ [CPU_USAGE]: {
207
+ description: "CPU usage percentage.",
208
+ unit: "percent",
209
+ valueType: ValueType.DOUBLE,
210
+ assign: /* @__PURE__ */ __name((h) => cpuUsageGauge = h, "assign"),
211
+ attributes: {}
212
+ },
213
+ [TOOL_QUEUE_DEPTH]: {
214
+ description: "Number of tools in execution queue.",
215
+ unit: "count",
216
+ valueType: ValueType.INT,
217
+ assign: /* @__PURE__ */ __name((h) => toolQueueDepthGauge = h, "assign"),
218
+ attributes: {}
219
+ },
220
+ [TOOL_EXECUTION_BREAKDOWN]: {
221
+ description: "Tool execution time breakdown by phase in milliseconds.",
222
+ unit: "ms",
223
+ valueType: ValueType.INT,
224
+ assign: /* @__PURE__ */ __name((h) => toolExecutionBreakdownHistogram = h, "assign"),
225
+ attributes: {}
226
+ },
227
+ [TOKEN_EFFICIENCY]: {
228
+ description: "Token efficiency metrics (tokens per operation, cache hit rate, etc.).",
229
+ unit: "ratio",
230
+ valueType: ValueType.DOUBLE,
231
+ assign: /* @__PURE__ */ __name((h) => tokenEfficiencyHistogram = h, "assign"),
232
+ attributes: {}
233
+ },
234
+ [API_REQUEST_BREAKDOWN]: {
235
+ description: "API request time breakdown by phase in milliseconds.",
236
+ unit: "ms",
237
+ valueType: ValueType.INT,
238
+ assign: /* @__PURE__ */ __name((h) => apiRequestBreakdownHistogram = h, "assign"),
239
+ attributes: {}
240
+ },
241
+ [PERFORMANCE_SCORE]: {
242
+ description: "Composite performance score (0-100).",
243
+ unit: "score",
244
+ valueType: ValueType.DOUBLE,
245
+ assign: /* @__PURE__ */ __name((h) => performanceScoreGauge = h, "assign"),
246
+ attributes: {}
247
+ },
248
+ [REGRESSION_PERCENTAGE_CHANGE]: {
249
+ description: "Percentage change compared to baseline for detected regressions.",
250
+ unit: "percent",
251
+ valueType: ValueType.DOUBLE,
252
+ assign: /* @__PURE__ */ __name((h) => regressionPercentageChangeHistogram = h, "assign"),
253
+ attributes: {}
254
+ },
255
+ [BASELINE_COMPARISON]: {
256
+ description: "Performance comparison to established baseline (percentage change).",
257
+ unit: "percent",
258
+ valueType: ValueType.DOUBLE,
259
+ assign: /* @__PURE__ */ __name((h) => baselineComparisonHistogram = h, "assign"),
260
+ attributes: {}
261
+ }
262
+ };
263
+ var FileOperation = /* @__PURE__ */ ((FileOperation2) => {
264
+ FileOperation2["CREATE"] = "create";
265
+ FileOperation2["READ"] = "read";
266
+ FileOperation2["UPDATE"] = "update";
267
+ return FileOperation2;
268
+ })(FileOperation || {});
269
+ var PerformanceMetricType = /* @__PURE__ */ ((PerformanceMetricType2) => {
270
+ PerformanceMetricType2["STARTUP"] = "startup";
271
+ PerformanceMetricType2["MEMORY"] = "memory";
272
+ PerformanceMetricType2["CPU"] = "cpu";
273
+ PerformanceMetricType2["TOOL_EXECUTION"] = "tool_execution";
274
+ PerformanceMetricType2["API_REQUEST"] = "api_request";
275
+ PerformanceMetricType2["TOKEN_EFFICIENCY"] = "token_efficiency";
276
+ return PerformanceMetricType2;
277
+ })(PerformanceMetricType || {});
278
+ var MemoryMetricType = /* @__PURE__ */ ((MemoryMetricType2) => {
279
+ MemoryMetricType2["HEAP_USED"] = "heap_used";
280
+ MemoryMetricType2["HEAP_TOTAL"] = "heap_total";
281
+ MemoryMetricType2["EXTERNAL"] = "external";
282
+ MemoryMetricType2["RSS"] = "rss";
283
+ return MemoryMetricType2;
284
+ })(MemoryMetricType || {});
285
+ var ToolExecutionPhase = /* @__PURE__ */ ((ToolExecutionPhase2) => {
286
+ ToolExecutionPhase2["VALIDATION"] = "validation";
287
+ ToolExecutionPhase2["PREPARATION"] = "preparation";
288
+ ToolExecutionPhase2["EXECUTION"] = "execution";
289
+ ToolExecutionPhase2["RESULT_PROCESSING"] = "result_processing";
290
+ return ToolExecutionPhase2;
291
+ })(ToolExecutionPhase || {});
292
+ var ApiRequestPhase = /* @__PURE__ */ ((ApiRequestPhase2) => {
293
+ ApiRequestPhase2["REQUEST_PREPARATION"] = "request_preparation";
294
+ ApiRequestPhase2["NETWORK_LATENCY"] = "network_latency";
295
+ ApiRequestPhase2["RESPONSE_PROCESSING"] = "response_processing";
296
+ ApiRequestPhase2["TOKEN_PROCESSING"] = "token_processing";
297
+ return ApiRequestPhase2;
298
+ })(ApiRequestPhase || {});
299
+ var cliMeter;
300
+ var toolCallCounter;
301
+ var toolCallLatencyHistogram;
302
+ var apiRequestCounter;
303
+ var apiRequestLatencyHistogram;
304
+ var tokenUsageCounter;
305
+ var sessionCounter;
306
+ var fileOperationCounter;
307
+ var chatCompressionCounter;
308
+ var invalidChunkCounter;
309
+ var contentRetryCounter;
310
+ var contentRetryFailureCounter;
311
+ var apiRetryCounter;
312
+ var subagentExecutionCounter;
313
+ var modelSlashCommandCallCounter;
314
+ var startupTimeHistogram;
315
+ var memoryUsageGauge;
316
+ var cpuUsageGauge;
317
+ var toolQueueDepthGauge;
318
+ var toolExecutionBreakdownHistogram;
319
+ var tokenEfficiencyHistogram;
320
+ var apiRequestBreakdownHistogram;
321
+ var performanceScoreGauge;
322
+ var regressionDetectionCounter;
323
+ var regressionPercentageChangeHistogram;
324
+ var baselineComparisonHistogram;
325
+ var arenaSessionCounter;
326
+ var arenaSessionDurationHistogram;
327
+ var arenaAgentCounter;
328
+ var arenaAgentDurationHistogram;
329
+ var arenaAgentTokensCounter;
330
+ var arenaResultSelectedCounter;
331
+ var memoryExtractCounter;
332
+ var memoryExtractDurationHistogram;
333
+ var memoryDreamCounter;
334
+ var memoryDreamDurationHistogram;
335
+ var memoryRecallCounter;
336
+ var memoryRecallDurationHistogram;
337
+ var channelMemoryRecallCounter;
338
+ var channelMemoryRecallDurationHistogram;
339
+ var channelMemoryRecallSelectedCountHistogram;
340
+ var isMetricsInitialized = false;
341
+ var isPerformanceMonitoringEnabled = false;
342
+ function getMeter() {
343
+ if (!cliMeter) {
344
+ cliMeter = metrics.getMeter(SERVICE_NAME);
345
+ }
346
+ return cliMeter;
347
+ }
348
+ __name(getMeter, "getMeter");
349
+ function initializeMetrics(config) {
350
+ if (isMetricsInitialized) return;
351
+ const meter = getMeter();
352
+ if (!meter) return;
353
+ Object.entries(COUNTER_DEFINITIONS).forEach(
354
+ ([name, { description, valueType, assign }]) => {
355
+ assign(meter.createCounter(name, { description, valueType }));
356
+ }
357
+ );
358
+ subagentExecutionCounter = meter.createCounter(SUBAGENT_EXECUTION_COUNT, {
359
+ description: "Counts subagent execution events, tagged by status and subagent name.",
360
+ valueType: ValueType.INT
361
+ });
362
+ arenaSessionCounter = meter.createCounter(ARENA_SESSION_COUNT, {
363
+ description: "Counts arena sessions by status and display backend.",
364
+ valueType: ValueType.INT
365
+ });
366
+ arenaSessionDurationHistogram = meter.createHistogram(
367
+ ARENA_SESSION_DURATION,
368
+ {
369
+ description: "Duration of arena sessions in milliseconds.",
370
+ unit: "ms",
371
+ valueType: ValueType.INT
372
+ }
373
+ );
374
+ arenaAgentCounter = meter.createCounter(ARENA_AGENT_COUNT, {
375
+ description: "Counts arena agent completions by status and model.",
376
+ valueType: ValueType.INT
377
+ });
378
+ arenaAgentDurationHistogram = meter.createHistogram(ARENA_AGENT_DURATION, {
379
+ description: "Duration of arena agent execution in milliseconds.",
380
+ unit: "ms",
381
+ valueType: ValueType.INT
382
+ });
383
+ arenaAgentTokensCounter = meter.createCounter(ARENA_AGENT_TOKENS, {
384
+ description: "Token usage by arena agents.",
385
+ valueType: ValueType.INT
386
+ });
387
+ arenaResultSelectedCounter = meter.createCounter(ARENA_RESULT_SELECTED, {
388
+ description: "Counts arena result selections by model.",
389
+ valueType: ValueType.INT
390
+ });
391
+ Object.entries(HISTOGRAM_DEFINITIONS).forEach(
392
+ ([name, { description, unit, valueType, assign }]) => {
393
+ assign(meter.createHistogram(name, { description, unit, valueType }));
394
+ }
395
+ );
396
+ sessionCounter?.add(1, baseMetricDefinition.getCommonAttributes(config));
397
+ memoryExtractCounter = meter.createCounter(MEMORY_EXTRACT_COUNT, {
398
+ description: "Counts auto-memory extraction runs, tagged by trigger and status.",
399
+ valueType: ValueType.INT
400
+ });
401
+ memoryExtractDurationHistogram = meter.createHistogram(
402
+ MEMORY_EXTRACT_DURATION,
403
+ {
404
+ description: "Duration of auto-memory extraction in milliseconds.",
405
+ unit: "ms",
406
+ valueType: ValueType.INT
407
+ }
408
+ );
409
+ memoryDreamCounter = meter.createCounter(MEMORY_DREAM_COUNT, {
410
+ description: "Counts auto-memory dream (consolidation) runs, tagged by trigger and status.",
411
+ valueType: ValueType.INT
412
+ });
413
+ memoryDreamDurationHistogram = meter.createHistogram(MEMORY_DREAM_DURATION, {
414
+ description: "Duration of auto-memory dream runs in milliseconds.",
415
+ unit: "ms",
416
+ valueType: ValueType.INT
417
+ });
418
+ memoryRecallCounter = meter.createCounter(MEMORY_RECALL_COUNT, {
419
+ description: "Counts auto-memory recall operations, tagged by strategy.",
420
+ valueType: ValueType.INT
421
+ });
422
+ memoryRecallDurationHistogram = meter.createHistogram(
423
+ MEMORY_RECALL_DURATION,
424
+ {
425
+ description: "Duration of auto-memory recall operations in milliseconds.",
426
+ unit: "ms",
427
+ valueType: ValueType.INT
428
+ }
429
+ );
430
+ channelMemoryRecallCounter = meter.createCounter(
431
+ CHANNEL_MEMORY_RECALL_COUNT,
432
+ {
433
+ description: "Counts channel memory recall attempts by cache path and bounded result.",
434
+ valueType: ValueType.INT
435
+ }
436
+ );
437
+ channelMemoryRecallDurationHistogram = meter.createHistogram(
438
+ CHANNEL_MEMORY_RECALL_DURATION,
439
+ {
440
+ description: "Duration of channel memory recall attempts.",
441
+ unit: "ms",
442
+ valueType: ValueType.DOUBLE,
443
+ advice: {
444
+ explicitBucketBoundaries: [0.1, 0.5, 1, 2, 5, 10, 25, 50, 100, 250]
445
+ }
446
+ }
447
+ );
448
+ channelMemoryRecallSelectedCountHistogram = meter.createHistogram(
449
+ CHANNEL_MEMORY_RECALL_SELECTED_COUNT,
450
+ {
451
+ description: "Number of channel memory entries selected per attempt.",
452
+ valueType: ValueType.INT
453
+ }
454
+ );
455
+ initializePerformanceMonitoring(config);
456
+ isMetricsInitialized = true;
457
+ }
458
+ __name(initializeMetrics, "initializeMetrics");
459
+ function recordChatCompressionMetrics(config, attributes) {
460
+ if (!chatCompressionCounter || !isMetricsInitialized) return;
461
+ chatCompressionCounter.add(1, {
462
+ ...baseMetricDefinition.getCommonAttributes(config),
463
+ ...attributes
464
+ });
465
+ }
466
+ __name(recordChatCompressionMetrics, "recordChatCompressionMetrics");
467
+ function recordToolCallMetrics(config, durationMs, attributes) {
468
+ if (!toolCallCounter || !toolCallLatencyHistogram || !isMetricsInitialized)
469
+ return;
470
+ const metricAttributes = {
471
+ ...baseMetricDefinition.getCommonAttributes(config),
472
+ ...attributes
473
+ };
474
+ toolCallCounter.add(1, metricAttributes);
475
+ toolCallLatencyHistogram.record(durationMs, {
476
+ ...baseMetricDefinition.getCommonAttributes(config),
477
+ function_name: attributes.function_name
478
+ });
479
+ }
480
+ __name(recordToolCallMetrics, "recordToolCallMetrics");
481
+ function recordTokenUsageMetrics(config, tokenCount, attributes) {
482
+ if (!tokenUsageCounter || !isMetricsInitialized) return;
483
+ tokenUsageCounter.add(tokenCount, {
484
+ ...baseMetricDefinition.getCommonAttributes(config),
485
+ ...attributes
486
+ });
487
+ }
488
+ __name(recordTokenUsageMetrics, "recordTokenUsageMetrics");
489
+ function recordApiResponseMetrics(config, durationMs, attributes) {
490
+ if (!apiRequestCounter || !apiRequestLatencyHistogram || !isMetricsInitialized)
491
+ return;
492
+ const metricAttributes = {
493
+ ...baseMetricDefinition.getCommonAttributes(config),
494
+ model: attributes.model,
495
+ status_code: attributes.status_code ?? "ok"
496
+ };
497
+ apiRequestCounter.add(1, metricAttributes);
498
+ apiRequestLatencyHistogram.record(durationMs, {
499
+ ...baseMetricDefinition.getCommonAttributes(config),
500
+ model: attributes.model
501
+ });
502
+ }
503
+ __name(recordApiResponseMetrics, "recordApiResponseMetrics");
504
+ function recordApiErrorMetrics(config, durationMs, attributes) {
505
+ if (!apiRequestCounter || !apiRequestLatencyHistogram || !isMetricsInitialized)
506
+ return;
507
+ const metricAttributes = {
508
+ ...baseMetricDefinition.getCommonAttributes(config),
509
+ model: attributes.model,
510
+ status_code: attributes.status_code ?? "error",
511
+ error_type: attributes.error_type ?? "unknown"
512
+ };
513
+ apiRequestCounter.add(1, metricAttributes);
514
+ apiRequestLatencyHistogram.record(durationMs, {
515
+ ...baseMetricDefinition.getCommonAttributes(config),
516
+ model: attributes.model
517
+ });
518
+ }
519
+ __name(recordApiErrorMetrics, "recordApiErrorMetrics");
520
+ function recordFileOperationMetric(config, attributes) {
521
+ if (!fileOperationCounter || !isMetricsInitialized) return;
522
+ fileOperationCounter.add(1, {
523
+ ...baseMetricDefinition.getCommonAttributes(config),
524
+ ...attributes
525
+ });
526
+ }
527
+ __name(recordFileOperationMetric, "recordFileOperationMetric");
528
+ function recordInvalidChunk(config) {
529
+ if (!invalidChunkCounter || !isMetricsInitialized) return;
530
+ invalidChunkCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
531
+ }
532
+ __name(recordInvalidChunk, "recordInvalidChunk");
533
+ function recordContentRetry(config) {
534
+ if (!contentRetryCounter || !isMetricsInitialized) return;
535
+ contentRetryCounter.add(1, baseMetricDefinition.getCommonAttributes(config));
536
+ }
537
+ __name(recordContentRetry, "recordContentRetry");
538
+ function recordContentRetryFailure(config) {
539
+ if (!contentRetryFailureCounter || !isMetricsInitialized) return;
540
+ contentRetryFailureCounter.add(
541
+ 1,
542
+ baseMetricDefinition.getCommonAttributes(config)
543
+ );
544
+ }
545
+ __name(recordContentRetryFailure, "recordContentRetryFailure");
546
+ function recordApiRetry(config, attributes) {
547
+ if (!apiRetryCounter || !isMetricsInitialized) return;
548
+ apiRetryCounter.add(1, {
549
+ ...baseMetricDefinition.getCommonAttributes(config),
550
+ ...attributes
551
+ });
552
+ }
553
+ __name(recordApiRetry, "recordApiRetry");
554
+ function recordModelSlashCommand(config, event) {
555
+ if (!modelSlashCommandCallCounter || !isMetricsInitialized) return;
556
+ modelSlashCommandCallCounter.add(1, {
557
+ ...baseMetricDefinition.getCommonAttributes(config),
558
+ "slash_command.model.model_name": event.model_name
559
+ });
560
+ }
561
+ __name(recordModelSlashCommand, "recordModelSlashCommand");
562
+ function initializePerformanceMonitoring(config) {
563
+ const meter = getMeter();
564
+ if (!meter) return;
565
+ isPerformanceMonitoringEnabled = config.getTelemetryEnabled();
566
+ if (!isPerformanceMonitoringEnabled) return;
567
+ Object.entries(PERFORMANCE_COUNTER_DEFINITIONS).forEach(
568
+ ([name, { description, valueType, assign }]) => {
569
+ assign(meter.createCounter(name, { description, valueType }));
570
+ }
571
+ );
572
+ Object.entries(PERFORMANCE_HISTOGRAM_DEFINITIONS).forEach(
573
+ ([name, { description, unit, valueType, assign }]) => {
574
+ assign(meter.createHistogram(name, { description, unit, valueType }));
575
+ }
576
+ );
577
+ }
578
+ __name(initializePerformanceMonitoring, "initializePerformanceMonitoring");
579
+ function recordStartupPerformance(config, durationMs, attributes) {
580
+ if (!startupTimeHistogram || !isPerformanceMonitoringEnabled) return;
581
+ const metricAttributes = {
582
+ ...baseMetricDefinition.getCommonAttributes(config),
583
+ phase: attributes.phase,
584
+ ...attributes.details
585
+ };
586
+ startupTimeHistogram.record(durationMs, metricAttributes);
587
+ }
588
+ __name(recordStartupPerformance, "recordStartupPerformance");
589
+ function recordMemoryUsage(config, bytes, attributes) {
590
+ if (!memoryUsageGauge || !isPerformanceMonitoringEnabled) return;
591
+ const metricAttributes = {
592
+ ...baseMetricDefinition.getCommonAttributes(config),
593
+ ...attributes
594
+ };
595
+ memoryUsageGauge.record(bytes, metricAttributes);
596
+ }
597
+ __name(recordMemoryUsage, "recordMemoryUsage");
598
+ function recordCpuUsage(config, percentage, attributes) {
599
+ if (!cpuUsageGauge || !isPerformanceMonitoringEnabled) return;
600
+ const metricAttributes = {
601
+ ...baseMetricDefinition.getCommonAttributes(config),
602
+ ...attributes
603
+ };
604
+ cpuUsageGauge.record(percentage, metricAttributes);
605
+ }
606
+ __name(recordCpuUsage, "recordCpuUsage");
607
+ function recordToolQueueDepth(config, queueDepth) {
608
+ if (!toolQueueDepthGauge || !isPerformanceMonitoringEnabled) return;
609
+ const attributes = {
610
+ ...baseMetricDefinition.getCommonAttributes(config)
611
+ };
612
+ toolQueueDepthGauge.record(queueDepth, attributes);
613
+ }
614
+ __name(recordToolQueueDepth, "recordToolQueueDepth");
615
+ function recordToolExecutionBreakdown(config, durationMs, attributes) {
616
+ if (!toolExecutionBreakdownHistogram || !isPerformanceMonitoringEnabled)
617
+ return;
618
+ const metricAttributes = {
619
+ ...baseMetricDefinition.getCommonAttributes(config),
620
+ ...attributes
621
+ };
622
+ toolExecutionBreakdownHistogram.record(durationMs, metricAttributes);
623
+ }
624
+ __name(recordToolExecutionBreakdown, "recordToolExecutionBreakdown");
625
+ function recordTokenEfficiency(config, value, attributes) {
626
+ if (!tokenEfficiencyHistogram || !isPerformanceMonitoringEnabled) return;
627
+ const metricAttributes = {
628
+ ...baseMetricDefinition.getCommonAttributes(config),
629
+ ...attributes
630
+ };
631
+ tokenEfficiencyHistogram.record(value, metricAttributes);
632
+ }
633
+ __name(recordTokenEfficiency, "recordTokenEfficiency");
634
+ function recordApiRequestBreakdown(config, durationMs, attributes) {
635
+ if (!apiRequestBreakdownHistogram || !isPerformanceMonitoringEnabled) return;
636
+ const metricAttributes = {
637
+ ...baseMetricDefinition.getCommonAttributes(config),
638
+ ...attributes
639
+ };
640
+ apiRequestBreakdownHistogram.record(durationMs, metricAttributes);
641
+ }
642
+ __name(recordApiRequestBreakdown, "recordApiRequestBreakdown");
643
+ function recordPerformanceScore(config, score, attributes) {
644
+ if (!performanceScoreGauge || !isPerformanceMonitoringEnabled) return;
645
+ const metricAttributes = {
646
+ ...baseMetricDefinition.getCommonAttributes(config),
647
+ ...attributes
648
+ };
649
+ performanceScoreGauge.record(score, metricAttributes);
650
+ }
651
+ __name(recordPerformanceScore, "recordPerformanceScore");
652
+ function recordPerformanceRegression(config, attributes) {
653
+ if (!regressionDetectionCounter || !isPerformanceMonitoringEnabled) return;
654
+ const metricAttributes = {
655
+ ...baseMetricDefinition.getCommonAttributes(config),
656
+ ...attributes
657
+ };
658
+ regressionDetectionCounter.add(1, metricAttributes);
659
+ if (attributes.baseline_value !== 0 && regressionPercentageChangeHistogram) {
660
+ const percentageChange = (attributes.current_value - attributes.baseline_value) / attributes.baseline_value * 100;
661
+ regressionPercentageChangeHistogram.record(
662
+ percentageChange,
663
+ metricAttributes
664
+ );
665
+ }
666
+ }
667
+ __name(recordPerformanceRegression, "recordPerformanceRegression");
668
+ function recordBaselineComparison(config, attributes) {
669
+ if (!baselineComparisonHistogram || !isPerformanceMonitoringEnabled) return;
670
+ if (attributes.baseline_value === 0) {
671
+ diag.warn("Baseline value is zero, skipping comparison.");
672
+ return;
673
+ }
674
+ const percentageChange = (attributes.current_value - attributes.baseline_value) / attributes.baseline_value * 100;
675
+ const metricAttributes = {
676
+ ...baseMetricDefinition.getCommonAttributes(config),
677
+ ...attributes
678
+ };
679
+ baselineComparisonHistogram.record(percentageChange, metricAttributes);
680
+ }
681
+ __name(recordBaselineComparison, "recordBaselineComparison");
682
+ function isPerformanceMonitoringActive() {
683
+ return isPerformanceMonitoringEnabled && isMetricsInitialized;
684
+ }
685
+ __name(isPerformanceMonitoringActive, "isPerformanceMonitoringActive");
686
+ function recordSubagentExecutionMetrics(config, subagentName, status, terminateReason) {
687
+ if (!subagentExecutionCounter || !isMetricsInitialized) return;
688
+ const attributes = {
689
+ ...baseMetricDefinition.getCommonAttributes(config),
690
+ subagent_name: subagentName,
691
+ status
692
+ };
693
+ if (terminateReason) {
694
+ attributes["terminate_reason"] = terminateReason;
695
+ }
696
+ subagentExecutionCounter.add(1, attributes);
697
+ }
698
+ __name(recordSubagentExecutionMetrics, "recordSubagentExecutionMetrics");
699
+ function recordArenaSessionStartedMetrics(config) {
700
+ if (!isMetricsInitialized) return;
701
+ arenaSessionCounter?.add(1, {
702
+ ...baseMetricDefinition.getCommonAttributes(config),
703
+ status: "started"
704
+ });
705
+ }
706
+ __name(recordArenaSessionStartedMetrics, "recordArenaSessionStartedMetrics");
707
+ function recordArenaAgentCompletedMetrics(config, modelId, status, durationMs, inputTokens, outputTokens) {
708
+ if (!isMetricsInitialized) return;
709
+ const common = baseMetricDefinition.getCommonAttributes(config);
710
+ arenaAgentCounter?.add(1, {
711
+ ...common,
712
+ status,
713
+ model_id: modelId
714
+ });
715
+ arenaAgentDurationHistogram?.record(durationMs, {
716
+ ...common,
717
+ model_id: modelId
718
+ });
719
+ if (inputTokens > 0) {
720
+ arenaAgentTokensCounter?.add(inputTokens, {
721
+ ...common,
722
+ model_id: modelId,
723
+ type: "input"
724
+ });
725
+ }
726
+ if (outputTokens > 0) {
727
+ arenaAgentTokensCounter?.add(outputTokens, {
728
+ ...common,
729
+ model_id: modelId,
730
+ type: "output"
731
+ });
732
+ }
733
+ }
734
+ __name(recordArenaAgentCompletedMetrics, "recordArenaAgentCompletedMetrics");
735
+ function recordArenaSessionEndedMetrics(config, status, displayBackend, durationMs, winnerModelId) {
736
+ if (!isMetricsInitialized) return;
737
+ const common = baseMetricDefinition.getCommonAttributes(config);
738
+ arenaSessionCounter?.add(1, {
739
+ ...common,
740
+ status,
741
+ ...displayBackend ? { display_backend: displayBackend } : {}
742
+ });
743
+ if (durationMs !== void 0 && arenaSessionDurationHistogram) {
744
+ arenaSessionDurationHistogram.record(durationMs, {
745
+ ...common,
746
+ status
747
+ });
748
+ }
749
+ if (winnerModelId) {
750
+ arenaResultSelectedCounter?.add(1, {
751
+ ...common,
752
+ model_id: winnerModelId
753
+ });
754
+ }
755
+ }
756
+ __name(recordArenaSessionEndedMetrics, "recordArenaSessionEndedMetrics");
757
+ function recordMemoryExtractMetrics(config, durationMs, attrs) {
758
+ if (!isMetricsInitialized) return;
759
+ const common = baseMetricDefinition.getCommonAttributes(config);
760
+ memoryExtractCounter?.add(1, {
761
+ ...common,
762
+ trigger: attrs.trigger,
763
+ status: attrs.status
764
+ });
765
+ memoryExtractDurationHistogram?.record(durationMs, {
766
+ ...common,
767
+ trigger: attrs.trigger,
768
+ status: attrs.status
769
+ });
770
+ }
771
+ __name(recordMemoryExtractMetrics, "recordMemoryExtractMetrics");
772
+ function recordMemoryDreamMetrics(config, durationMs, attrs) {
773
+ if (!isMetricsInitialized) return;
774
+ const common = baseMetricDefinition.getCommonAttributes(config);
775
+ memoryDreamCounter?.add(1, {
776
+ ...common,
777
+ trigger: attrs.trigger,
778
+ status: attrs.status
779
+ });
780
+ memoryDreamDurationHistogram?.record(durationMs, {
781
+ ...common,
782
+ trigger: attrs.trigger,
783
+ status: attrs.status
784
+ });
785
+ }
786
+ __name(recordMemoryDreamMetrics, "recordMemoryDreamMetrics");
787
+ function recordMemoryRecallMetrics(config, durationMs, attrs) {
788
+ if (!isMetricsInitialized) return;
789
+ const common = baseMetricDefinition.getCommonAttributes(config);
790
+ memoryRecallCounter?.add(1, { ...common, strategy: attrs.strategy });
791
+ memoryRecallDurationHistogram?.record(durationMs, {
792
+ ...common,
793
+ strategy: attrs.strategy
794
+ });
795
+ }
796
+ __name(recordMemoryRecallMetrics, "recordMemoryRecallMetrics");
797
+ function recordChannelMemoryRecallMetrics(observation) {
798
+ if (!isMetricsInitialized) return;
799
+ const attributes = {
800
+ cache: observation.cache,
801
+ result: observation.result
802
+ };
803
+ channelMemoryRecallCounter?.add(1, attributes);
804
+ channelMemoryRecallDurationHistogram?.record(
805
+ observation.durationMs,
806
+ attributes
807
+ );
808
+ channelMemoryRecallSelectedCountHistogram?.record(
809
+ observation.selectedCount,
810
+ attributes
811
+ );
812
+ }
813
+ __name(recordChannelMemoryRecallMetrics, "recordChannelMemoryRecallMetrics");
814
+
815
+ // packages/core/src/telemetry/detailed-span-attributes.ts
816
+ init_esbuild_shims();
817
+ import { createHash as createHash2 } from "node:crypto";
818
+
819
+ // packages/core/src/telemetry/sdk.ts
820
+ init_esbuild_shims();
821
+ init_esm();
822
+
823
+ // packages/core/src/telemetry/tracer.ts
824
+ init_esbuild_shims();
825
+ init_esm();
826
+
827
+ // packages/core/src/telemetry/trace-id-utils.ts
828
+ init_esbuild_shims();
829
+ import { createHash } from "node:crypto";
830
+ function deriveTraceId(sessionId) {
831
+ return createHash("sha256").update(sessionId).digest("hex").slice(0, 32);
832
+ }
833
+ __name(deriveTraceId, "deriveTraceId");
834
+ function randomSpanId() {
835
+ const bytes = new Uint8Array(8);
836
+ crypto.getRandomValues(bytes);
837
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
838
+ }
839
+ __name(randomSpanId, "randomSpanId");
840
+ function randomHexString(length) {
841
+ const bytes = new Uint8Array(Math.ceil(length / 2));
842
+ crypto.getRandomValues(bytes);
843
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("").slice(0, length);
844
+ }
845
+ __name(randomHexString, "randomHexString");
846
+
847
+ // packages/core/src/telemetry/tracer.ts
848
+ var tracer = trace.getTracer(SERVICE_NAME);
849
+ var debugLogger = createDebugLogger("OTEL_TRACER");
850
+ var TELEMETRY_WARNING_INTERVAL_MS = 3e4;
851
+ var API_CALL_FAILED_SPAN_STATUS_MESSAGE = "API call failed";
852
+ var API_CALL_ABORTED_SPAN_STATUS_MESSAGE = "API call aborted";
853
+ var lastTelemetryWarningMs;
854
+ var suppressedTelemetryWarnings = 0;
855
+ function warnTelemetryOperationFailed(operation, error) {
856
+ const now = Date.now();
857
+ if (lastTelemetryWarningMs !== void 0 && now - lastTelemetryWarningMs < TELEMETRY_WARNING_INTERVAL_MS) {
858
+ suppressedTelemetryWarnings += 1;
859
+ return;
860
+ }
861
+ const suppressedSuffix = suppressedTelemetryWarnings > 0 ? `; suppressed ${suppressedTelemetryWarnings} similar warning(s)` : "";
862
+ suppressedTelemetryWarnings = 0;
863
+ lastTelemetryWarningMs = now;
864
+ try {
865
+ debugLogger.warn(
866
+ `OTel span ${operation} failed: ${error instanceof Error ? error.message : String(error)}${suppressedSuffix}`
867
+ );
868
+ } catch {
869
+ }
870
+ }
871
+ __name(warnTelemetryOperationFailed, "warnTelemetryOperationFailed");
872
+ function safeSetStatus(span, status) {
873
+ try {
874
+ span.setStatus(status);
875
+ } catch (error) {
876
+ warnTelemetryOperationFailed("setStatus", error);
877
+ }
878
+ }
879
+ __name(safeSetStatus, "safeSetStatus");
880
+ function shouldForceSampled() {
881
+ const sampler = process.env["OTEL_TRACES_SAMPLER"]?.trim().toLowerCase() ?? "";
882
+ if (!sampler || sampler.startsWith("parentbased_")) {
883
+ if (sampler.includes("always_off")) return false;
884
+ return true;
885
+ }
886
+ return sampler === "always_on";
887
+ }
888
+ __name(shouldForceSampled, "shouldForceSampled");
889
+ function createSessionRootContext(sessionId) {
890
+ const traceId = deriveTraceId(sessionId);
891
+ const spanId = randomSpanId();
892
+ const rootSpan = trace.wrapSpanContext({
893
+ traceId,
894
+ spanId,
895
+ traceFlags: shouldForceSampled() ? TraceFlags.SAMPLED : TraceFlags.NONE,
896
+ isRemote: false
897
+ });
898
+ return trace.setSpan(ROOT_CONTEXT, rootSpan);
899
+ }
900
+ __name(createSessionRootContext, "createSessionRootContext");
901
+
902
+ // packages/core/src/telemetry/session-tracing.ts
903
+ init_esbuild_shims();
904
+ init_esm();
905
+ import { AsyncLocalStorage } from "node:async_hooks";
906
+ var debugLogger2 = createDebugLogger("SESSION_TRACING");
907
+ function resolveParentContext(parent) {
908
+ if (parent) {
909
+ return trace.setSpan(context.active(), parent.span);
910
+ }
911
+ return context.active();
912
+ }
913
+ __name(resolveParentContext, "resolveParentContext");
914
+ var NOOP_SPAN = trace.wrapSpanContext({
915
+ traceId: "0".repeat(32),
916
+ spanId: "0".repeat(16),
917
+ traceFlags: 0
918
+ });
919
+ var interactionContext = new AsyncLocalStorage();
920
+ var toolContext = new AsyncLocalStorage();
921
+ var subagentContext = new AsyncLocalStorage();
922
+ function isInNativeSubagentSpan() {
923
+ const ctx = subagentContext.getStore();
924
+ return ctx !== void 0 && !ctx.ended;
925
+ }
926
+ __name(isInNativeSubagentSpan, "isInNativeSubagentSpan");
927
+ function resolveSessionId(parentCtx) {
928
+ const fromParent = parentCtx?.attributes?.["session.id"];
929
+ return typeof fromParent === "string" && fromParent ? fromParent : getCurrentSessionId();
930
+ }
931
+ __name(resolveSessionId, "resolveSessionId");
932
+ var activeSpans = /* @__PURE__ */ new Map();
933
+ var strongSpans = /* @__PURE__ */ new Map();
934
+ var interactionSequence = 0;
935
+ var lastInteractionCtx;
936
+ var cleanupIntervalStarted = false;
937
+ var SPAN_TTL_MS_DEFAULT = 30 * 60 * 1e3;
938
+ var SPAN_TTL_MS_LONG = 4 * 60 * 60 * 1e3;
939
+ var LONG_TTL_SUBAGENT_KINDS = /* @__PURE__ */ new Set([
940
+ "fork",
941
+ "background"
942
+ ]);
943
+ function ttlFor(ctx) {
944
+ if (ctx.type === "subagent") {
945
+ const kind = ctx.attributes["qwen-code.subagent.invocation_kind"];
946
+ if (typeof kind === "string" && LONG_TTL_SUBAGENT_KINDS.has(kind)) {
947
+ return SPAN_TTL_MS_LONG;
948
+ }
949
+ }
950
+ return SPAN_TTL_MS_DEFAULT;
951
+ }
952
+ __name(ttlFor, "ttlFor");
953
+ function sweepStaleSpans(now) {
954
+ for (const [spanId, weakRef] of activeSpans) {
955
+ const ctx = weakRef.deref();
956
+ if (ctx === void 0) {
957
+ activeSpans.delete(spanId);
958
+ strongSpans.delete(spanId);
959
+ continue;
960
+ }
961
+ if (now - ctx.startTime < ttlFor(ctx)) continue;
962
+ if (!ctx.ended) {
963
+ ctx.ended = true;
964
+ const ageMs = now - ctx.startTime;
965
+ const toolName = ctx.attributes["tool.name"];
966
+ const callId = ctx.attributes["tool.call_id"];
967
+ try {
968
+ ctx.span.setAttributes({
969
+ "qwen-code.span.ttl_expired": true,
970
+ "qwen-code.span.duration_ms": ageMs,
971
+ ...ctx.type === "tool.blocked_on_user" ? {
972
+ decision: "aborted",
973
+ source: "system"
974
+ } : {},
975
+ ...ctx.type === "subagent" ? {
976
+ "qwen-code.subagent.status": "aborted",
977
+ "qwen-code.subagent.terminate_reason": "ttl_swept",
978
+ // Mirror the subagent-specific duration_ms key that
979
+ // endSubagentSpan stamps so dashboards querying that
980
+ // namespace see TTL-swept spans too (they currently
981
+ // only get the generic qwen-code.span.duration_ms
982
+ // above). wenshao @ #4410.
983
+ "qwen-code.subagent.duration_ms": ageMs
984
+ } : {}
985
+ });
986
+ } catch (error) {
987
+ debugLogger2.warn(
988
+ `Failed to stamp TTL attrs on stale span ${spanId}: ${error instanceof Error ? error.message : String(error)}`
989
+ );
990
+ }
991
+ const ctxLabel = toolName && callId ? `${ctx.type} (tool.name=${toolName}, tool.call_id=${callId})` : ctx.type;
992
+ debugLogger2.warn(
993
+ `Stale ${ctxLabel} span ended by TTL safety net (age=${ageMs}ms, spanId=${spanId})`
994
+ );
995
+ try {
996
+ ctx.span.end();
997
+ } catch (error) {
998
+ debugLogger2.warn(
999
+ `Failed to end stale span ${spanId}: ${error instanceof Error ? error.message : String(error)}`
1000
+ );
1001
+ }
1002
+ }
1003
+ activeSpans.delete(spanId);
1004
+ strongSpans.delete(spanId);
1005
+ }
1006
+ }
1007
+ __name(sweepStaleSpans, "sweepStaleSpans");
1008
+ function ensureCleanupInterval() {
1009
+ if (cleanupIntervalStarted) return;
1010
+ cleanupIntervalStarted = true;
1011
+ const interval = setInterval(() => sweepStaleSpans(Date.now()), 6e4);
1012
+ if (typeof interval.unref === "function") {
1013
+ interval.unref();
1014
+ }
1015
+ }
1016
+ __name(ensureCleanupInterval, "ensureCleanupInterval");
1017
+ function getSpanId(span) {
1018
+ return span.spanContext().spanId || "";
1019
+ }
1020
+ __name(getSpanId, "getSpanId");
1021
+ var SPAN_ERROR_MAX_CHARS = 1024;
1022
+ function truncateSpanError(s) {
1023
+ if (s.length <= SPAN_ERROR_MAX_CHARS) return s;
1024
+ let end = SPAN_ERROR_MAX_CHARS;
1025
+ const code = s.charCodeAt(end - 1);
1026
+ if (code >= 55296 && code <= 56319) end--;
1027
+ return s.slice(0, end) + "\u2026[truncated]";
1028
+ }
1029
+ __name(truncateSpanError, "truncateSpanError");
1030
+ function getTracer() {
1031
+ return trace.getTracer(SERVICE_NAME, "1.0.0");
1032
+ }
1033
+ __name(getTracer, "getTracer");
1034
+ function startInteractionSpan(config, options) {
1035
+ if (!isTelemetrySdkInitialized()) return;
1036
+ ensureCleanupInterval();
1037
+ interactionSequence++;
1038
+ const attributes = {
1039
+ "session.id": config.getSessionId(),
1040
+ "qwen-code.prompt_id": options.promptId,
1041
+ "qwen-code.message_type": options.messageType,
1042
+ "qwen-code.model": options.model,
1043
+ "qwen-code.approval_mode": config.getApprovalMode(),
1044
+ "interaction.sequence": interactionSequence
1045
+ };
1046
+ const span = getTracer().startSpan(
1047
+ SPAN_INTERACTION,
1048
+ { kind: SpanKind.INTERNAL, attributes },
1049
+ ROOT_CONTEXT
1050
+ );
1051
+ const spanId = getSpanId(span);
1052
+ const spanContextObj = {
1053
+ span,
1054
+ startTime: Date.now(),
1055
+ attributes,
1056
+ type: "interaction"
1057
+ };
1058
+ activeSpans.set(spanId, new WeakRef(spanContextObj));
1059
+ strongSpans.set(spanId, spanContextObj);
1060
+ lastInteractionCtx = spanContextObj;
1061
+ interactionContext.enterWith(spanContextObj);
1062
+ }
1063
+ __name(startInteractionSpan, "startInteractionSpan");
1064
+ function endInteractionSpan(status, metadata) {
1065
+ const spanCtx = interactionContext.getStore() ?? lastInteractionCtx;
1066
+ if (!spanCtx) return;
1067
+ if (spanCtx.ended) {
1068
+ debugLogger2.debug(
1069
+ `endInteractionSpan: span ${getSpanId(spanCtx.span)} already ended (possible TTL sweep race)`
1070
+ );
1071
+ return;
1072
+ }
1073
+ spanCtx.ended = true;
1074
+ lastInteractionCtx = void 0;
1075
+ const duration = Date.now() - spanCtx.startTime;
1076
+ spanCtx.span.setAttributes({
1077
+ "interaction.duration_ms": duration,
1078
+ "qwen-code.turn_status": status
1079
+ });
1080
+ if (status === "error") {
1081
+ spanCtx.span.setStatus({
1082
+ code: SpanStatusCode.ERROR,
1083
+ message: metadata?.errorMessage ?? "unknown error"
1084
+ });
1085
+ } else {
1086
+ spanCtx.span.setStatus({ code: SpanStatusCode.OK });
1087
+ }
1088
+ spanCtx.span.end();
1089
+ const spanId = getSpanId(spanCtx.span);
1090
+ activeSpans.delete(spanId);
1091
+ strongSpans.delete(spanId);
1092
+ interactionContext.enterWith(void 0);
1093
+ }
1094
+ __name(endInteractionSpan, "endInteractionSpan");
1095
+ async function withInteractionSpan(config, options, fn, getResultStatus) {
1096
+ if (!isTelemetrySdkInitialized()) return await fn();
1097
+ ensureCleanupInterval();
1098
+ interactionSequence++;
1099
+ const attributes = {
1100
+ "session.id": config.getSessionId(),
1101
+ "qwen-code.prompt_id": options.promptId,
1102
+ "qwen-code.message_type": options.messageType,
1103
+ "qwen-code.model": options.model,
1104
+ "qwen-code.approval_mode": config.getApprovalMode(),
1105
+ "interaction.sequence": interactionSequence
1106
+ };
1107
+ const parentContext = options.parentContext ?? ROOT_CONTEXT;
1108
+ const span = getTracer().startSpan(
1109
+ SPAN_INTERACTION,
1110
+ {
1111
+ kind: SpanKind.INTERNAL,
1112
+ attributes
1113
+ },
1114
+ parentContext
1115
+ );
1116
+ const spanId = getSpanId(span);
1117
+ const spanContextObj = {
1118
+ span,
1119
+ startTime: Date.now(),
1120
+ attributes,
1121
+ type: "interaction"
1122
+ };
1123
+ activeSpans.set(spanId, new WeakRef(spanContextObj));
1124
+ strongSpans.set(spanId, spanContextObj);
1125
+ const activeContext = trace.setSpan(parentContext, span);
1126
+ return await context.with(
1127
+ activeContext,
1128
+ async () => interactionContext.run(spanContextObj, async () => {
1129
+ let terminalStatus = "ok";
1130
+ let errorStatusSet = false;
1131
+ try {
1132
+ const result = await fn();
1133
+ terminalStatus = getResultStatus?.(result) ?? "ok";
1134
+ return result;
1135
+ } catch (error) {
1136
+ terminalStatus = "error";
1137
+ span.setStatus({
1138
+ code: SpanStatusCode.ERROR,
1139
+ message: truncateSpanError(
1140
+ error instanceof Error ? error.message : String(error)
1141
+ )
1142
+ });
1143
+ errorStatusSet = true;
1144
+ throw error;
1145
+ } finally {
1146
+ if (!spanContextObj.ended) {
1147
+ spanContextObj.ended = true;
1148
+ const duration = Date.now() - spanContextObj.startTime;
1149
+ span.setAttributes({
1150
+ "interaction.duration_ms": duration,
1151
+ "qwen-code.turn_status": terminalStatus
1152
+ });
1153
+ if (terminalStatus === "ok") {
1154
+ span.setStatus({ code: SpanStatusCode.OK });
1155
+ } else if (terminalStatus === "error" && !errorStatusSet) {
1156
+ span.setStatus({
1157
+ code: SpanStatusCode.ERROR,
1158
+ message: "interaction error"
1159
+ });
1160
+ }
1161
+ span.end();
1162
+ activeSpans.delete(spanId);
1163
+ strongSpans.delete(spanId);
1164
+ }
1165
+ }
1166
+ })
1167
+ );
1168
+ }
1169
+ __name(withInteractionSpan, "withInteractionSpan");
1170
+ function startLLMRequestSpan(model, promptId) {
1171
+ if (!isTelemetrySdkInitialized()) {
1172
+ return NOOP_SPAN;
1173
+ }
1174
+ const parentCtx = subagentContext.getStore() ?? interactionContext.getStore();
1175
+ const ctx = resolveParentContext(parentCtx);
1176
+ const sessionId = resolveSessionId(parentCtx);
1177
+ const attributes = {
1178
+ ...sessionId ? { "session.id": sessionId } : {},
1179
+ "qwen-code.model": model,
1180
+ "qwen-code.prompt_id": promptId,
1181
+ "llm_request.context": subagentContext.getStore() ? "subagent" : interactionContext.getStore() ? "interaction" : "standalone",
1182
+ // Dual-emit OTel GenAI semantic convention (Stable). Private name
1183
+ // (qwen-code.model) remains authoritative; gen_ai.* is a compat layer
1184
+ // for spec-aware backends. See docs/design/telemetry-llm-request-timing-design.md (D8).
1185
+ "gen_ai.request.model": model
1186
+ };
1187
+ const span = getTracer().startSpan(
1188
+ SPAN_LLM_REQUEST,
1189
+ { kind: SpanKind.INTERNAL, attributes },
1190
+ ctx
1191
+ );
1192
+ const spanId = getSpanId(span);
1193
+ const spanContextObj = {
1194
+ span,
1195
+ startTime: Date.now(),
1196
+ attributes,
1197
+ type: "llm_request"
1198
+ };
1199
+ activeSpans.set(spanId, new WeakRef(spanContextObj));
1200
+ strongSpans.set(spanId, spanContextObj);
1201
+ return span;
1202
+ }
1203
+ __name(startLLMRequestSpan, "startLLMRequestSpan");
1204
+ function endLLMRequestSpan(span, metadata) {
1205
+ const spanId = getSpanId(span);
1206
+ const spanCtx = activeSpans.get(spanId)?.deref();
1207
+ if (!spanCtx) return;
1208
+ if (spanCtx.ended) {
1209
+ debugLogger2.debug(
1210
+ `endLLMRequestSpan: span ${spanId} already ended (possible TTL sweep race)`
1211
+ );
1212
+ return;
1213
+ }
1214
+ spanCtx.ended = true;
1215
+ try {
1216
+ const duration = metadata?.durationMs ?? Date.now() - spanCtx.startTime;
1217
+ const endAttributes = { duration_ms: duration };
1218
+ if (metadata) {
1219
+ if (metadata.inputTokens !== void 0) {
1220
+ endAttributes["input_tokens"] = metadata.inputTokens;
1221
+ endAttributes["gen_ai.usage.input_tokens"] = metadata.inputTokens;
1222
+ }
1223
+ if (metadata.outputTokens !== void 0) {
1224
+ endAttributes["output_tokens"] = metadata.outputTokens;
1225
+ endAttributes["gen_ai.usage.output_tokens"] = metadata.outputTokens;
1226
+ }
1227
+ if (metadata.cachedInputTokens !== void 0) {
1228
+ endAttributes["cached_input_tokens"] = metadata.cachedInputTokens;
1229
+ endAttributes["gen_ai.usage.cached_tokens"] = metadata.cachedInputTokens;
1230
+ }
1231
+ if (metadata.ttftMs !== void 0) {
1232
+ endAttributes["ttft_ms"] = metadata.ttftMs;
1233
+ endAttributes["gen_ai.server.time_to_first_token"] = metadata.ttftMs / 1e3;
1234
+ }
1235
+ if (metadata.requestSetupMs !== void 0) {
1236
+ endAttributes["request_setup_ms"] = metadata.requestSetupMs;
1237
+ }
1238
+ if (metadata.attempt !== void 0) {
1239
+ endAttributes["attempt"] = metadata.attempt;
1240
+ }
1241
+ if (metadata.retryTotalDelayMs !== void 0) {
1242
+ endAttributes["retry_total_delay_ms"] = metadata.retryTotalDelayMs;
1243
+ }
1244
+ if (metadata.ttftMs !== void 0) {
1245
+ const samplingMs = Math.max(0, duration - metadata.ttftMs);
1246
+ endAttributes["sampling_ms"] = samplingMs;
1247
+ if (samplingMs > 0 && metadata.outputTokens !== void 0) {
1248
+ endAttributes["output_tokens_per_second"] = Math.round(metadata.outputTokens / (samplingMs / 1e3) * 100) / 100;
1249
+ }
1250
+ }
1251
+ endAttributes["success"] = metadata.success;
1252
+ if (metadata.error !== void 0)
1253
+ endAttributes["error"] = truncateSpanError(metadata.error);
1254
+ if (metadata.responseId !== void 0) {
1255
+ endAttributes["response_id"] = metadata.responseId;
1256
+ endAttributes["gen_ai.response.id"] = metadata.responseId;
1257
+ }
1258
+ if (metadata.finishReason !== void 0) {
1259
+ endAttributes["finish_reason"] = metadata.finishReason;
1260
+ endAttributes["gen_ai.response.finish_reasons"] = [
1261
+ metadata.finishReason
1262
+ ];
1263
+ }
1264
+ if (metadata.thoughtsTokenCount !== void 0) {
1265
+ endAttributes["thoughts_token_count"] = metadata.thoughtsTokenCount;
1266
+ endAttributes["gen_ai.usage.reasoning_tokens"] = metadata.thoughtsTokenCount;
1267
+ }
1268
+ if (metadata.subagentName !== void 0) {
1269
+ endAttributes["subagent_name"] = metadata.subagentName;
1270
+ }
1271
+ if (metadata.errorType !== void 0) {
1272
+ endAttributes["error_type"] = metadata.errorType;
1273
+ endAttributes["error.type"] = metadata.errorType;
1274
+ }
1275
+ if (metadata.errorStatusCode !== void 0) {
1276
+ endAttributes["error_status_code"] = metadata.errorStatusCode;
1277
+ }
1278
+ }
1279
+ spanCtx.span.setAttributes(endAttributes);
1280
+ try {
1281
+ if (metadata?.config && metadata.success) {
1282
+ const model = String(spanCtx.attributes["qwen-code.model"] ?? "");
1283
+ if (metadata.requestSetupMs !== void 0) {
1284
+ recordApiRequestBreakdown(metadata.config, metadata.requestSetupMs, {
1285
+ model,
1286
+ phase: "request_preparation" /* REQUEST_PREPARATION */
1287
+ });
1288
+ }
1289
+ if (metadata.ttftMs !== void 0) {
1290
+ recordApiRequestBreakdown(metadata.config, metadata.ttftMs, {
1291
+ model,
1292
+ phase: "network_latency" /* NETWORK_LATENCY */
1293
+ });
1294
+ }
1295
+ const breakdownSamplingMs = metadata.ttftMs !== void 0 ? Math.max(0, duration - metadata.ttftMs) : void 0;
1296
+ if (breakdownSamplingMs !== void 0 && breakdownSamplingMs > 0) {
1297
+ recordApiRequestBreakdown(metadata.config, breakdownSamplingMs, {
1298
+ model,
1299
+ phase: "response_processing" /* RESPONSE_PROCESSING */
1300
+ });
1301
+ }
1302
+ }
1303
+ } catch (error) {
1304
+ debugLogger2.warn(
1305
+ `Failed to record API request breakdown histogram: ${error instanceof Error ? error.message : String(error)}`
1306
+ );
1307
+ }
1308
+ if (metadata === void 0 || metadata.success) {
1309
+ spanCtx.span.setStatus({ code: SpanStatusCode.OK });
1310
+ } else {
1311
+ spanCtx.span.setStatus({
1312
+ code: SpanStatusCode.ERROR,
1313
+ message: metadata.error ? truncateSpanError(metadata.error) : "unknown error"
1314
+ });
1315
+ }
1316
+ } catch (error) {
1317
+ debugLogger2.warn(
1318
+ `Failed to update LLM request span attributes/status: ${error instanceof Error ? error.message : String(error)}`
1319
+ );
1320
+ }
1321
+ try {
1322
+ spanCtx.span.end();
1323
+ } catch (error) {
1324
+ debugLogger2.warn(
1325
+ `Failed to end LLM request span: ${error instanceof Error ? error.message : String(error)}`
1326
+ );
1327
+ }
1328
+ activeSpans.delete(spanId);
1329
+ strongSpans.delete(spanId);
1330
+ }
1331
+ __name(endLLMRequestSpan, "endLLMRequestSpan");
1332
+ function startToolSpan(toolName, attrs) {
1333
+ if (!isTelemetrySdkInitialized()) {
1334
+ return NOOP_SPAN;
1335
+ }
1336
+ const parentCtx = subagentContext.getStore() ?? interactionContext.getStore();
1337
+ const ctx = resolveParentContext(parentCtx);
1338
+ const sessionId = resolveSessionId(parentCtx);
1339
+ const attributes = {
1340
+ ...sessionId ? { "session.id": sessionId } : {},
1341
+ "tool.name": toolName,
1342
+ ...attrs
1343
+ };
1344
+ const span = getTracer().startSpan(
1345
+ SPAN_TOOL,
1346
+ { kind: SpanKind.INTERNAL, attributes },
1347
+ ctx
1348
+ );
1349
+ const spanId = getSpanId(span);
1350
+ const spanContextObj = {
1351
+ span,
1352
+ startTime: Date.now(),
1353
+ attributes,
1354
+ type: "tool"
1355
+ };
1356
+ activeSpans.set(spanId, new WeakRef(spanContextObj));
1357
+ strongSpans.set(spanId, spanContextObj);
1358
+ return span;
1359
+ }
1360
+ __name(startToolSpan, "startToolSpan");
1361
+ function runInToolSpanContext(span, fn) {
1362
+ const spanId = getSpanId(span);
1363
+ const spanCtx = activeSpans.get(spanId)?.deref();
1364
+ if (!spanCtx) return fn();
1365
+ const otelCtxWithSpan = trace.setSpan(context.active(), span);
1366
+ return toolContext.run(spanCtx, () => context.with(otelCtxWithSpan, fn));
1367
+ }
1368
+ __name(runInToolSpanContext, "runInToolSpanContext");
1369
+ function endToolSpan(span, metadata) {
1370
+ const spanId = getSpanId(span);
1371
+ const spanCtx = activeSpans.get(spanId)?.deref();
1372
+ if (!spanCtx) return;
1373
+ if (spanCtx.ended) {
1374
+ debugLogger2.debug(
1375
+ `endToolSpan: span ${spanId} already ended (possible TTL sweep race)`
1376
+ );
1377
+ return;
1378
+ }
1379
+ spanCtx.ended = true;
1380
+ try {
1381
+ const duration = Date.now() - spanCtx.startTime;
1382
+ const endAttributes = { duration_ms: duration };
1383
+ if (metadata) {
1384
+ if (metadata.success !== void 0)
1385
+ endAttributes["success"] = metadata.success;
1386
+ if (metadata.error !== void 0)
1387
+ endAttributes["error"] = truncateSpanError(metadata.error);
1388
+ }
1389
+ spanCtx.span.setAttributes(endAttributes);
1390
+ if (metadata) {
1391
+ if (metadata.success !== false) {
1392
+ spanCtx.span.setStatus({ code: SpanStatusCode.OK });
1393
+ } else {
1394
+ spanCtx.span.setStatus({
1395
+ code: SpanStatusCode.ERROR,
1396
+ message: metadata.error ? truncateSpanError(metadata.error) : "tool error"
1397
+ });
1398
+ }
1399
+ }
1400
+ } catch (error) {
1401
+ debugLogger2.warn(
1402
+ `Failed to update tool span attributes/status: ${error instanceof Error ? error.message : String(error)}`
1403
+ );
1404
+ }
1405
+ try {
1406
+ spanCtx.span.end();
1407
+ } catch (error) {
1408
+ debugLogger2.warn(
1409
+ `Failed to end tool span: ${error instanceof Error ? error.message : String(error)}`
1410
+ );
1411
+ }
1412
+ activeSpans.delete(spanId);
1413
+ strongSpans.delete(spanId);
1414
+ }
1415
+ __name(endToolSpan, "endToolSpan");
1416
+ function startToolExecutionSpan() {
1417
+ if (!isTelemetrySdkInitialized()) {
1418
+ return NOOP_SPAN;
1419
+ }
1420
+ const parentCtx = toolContext.getStore();
1421
+ if (!parentCtx) {
1422
+ debugLogger2.warn(
1423
+ "startToolExecutionSpan called outside runInToolSpanContext \u2014 span will not be parented to tool span"
1424
+ );
1425
+ }
1426
+ const ctx = resolveParentContext(parentCtx);
1427
+ const sessionId = resolveSessionId(
1428
+ parentCtx ?? interactionContext.getStore()
1429
+ );
1430
+ const span = getTracer().startSpan(
1431
+ SPAN_TOOL_EXECUTION,
1432
+ {
1433
+ kind: SpanKind.INTERNAL,
1434
+ attributes: sessionId ? { "session.id": sessionId } : {}
1435
+ },
1436
+ ctx
1437
+ );
1438
+ const spanId = getSpanId(span);
1439
+ const spanContextObj = {
1440
+ span,
1441
+ startTime: Date.now(),
1442
+ attributes: sessionId ? { "session.id": sessionId } : {},
1443
+ type: "tool.execution"
1444
+ };
1445
+ activeSpans.set(spanId, new WeakRef(spanContextObj));
1446
+ strongSpans.set(spanId, spanContextObj);
1447
+ return span;
1448
+ }
1449
+ __name(startToolExecutionSpan, "startToolExecutionSpan");
1450
+ function endToolExecutionSpan(span, metadata) {
1451
+ const spanId = getSpanId(span);
1452
+ const spanCtx = activeSpans.get(spanId)?.deref();
1453
+ if (!spanCtx) return;
1454
+ if (spanCtx.ended) {
1455
+ debugLogger2.debug(
1456
+ `endToolExecutionSpan: span ${spanId} already ended (possible TTL sweep race)`
1457
+ );
1458
+ return;
1459
+ }
1460
+ spanCtx.ended = true;
1461
+ try {
1462
+ const duration = Date.now() - spanCtx.startTime;
1463
+ const endAttributes = {};
1464
+ if (metadata?.attributes) {
1465
+ Object.assign(endAttributes, metadata.attributes);
1466
+ }
1467
+ endAttributes["duration_ms"] = duration;
1468
+ if (metadata) {
1469
+ if (metadata.success !== void 0)
1470
+ endAttributes["success"] = metadata.success;
1471
+ if (metadata.error !== void 0)
1472
+ endAttributes["error"] = truncateSpanError(metadata.error);
1473
+ }
1474
+ spanCtx.span.setAttributes(endAttributes);
1475
+ if (metadata && !metadata.cancelled) {
1476
+ if (metadata.success !== false) {
1477
+ spanCtx.span.setStatus({ code: SpanStatusCode.OK });
1478
+ } else {
1479
+ spanCtx.span.setStatus({
1480
+ code: SpanStatusCode.ERROR,
1481
+ message: metadata.error ? truncateSpanError(metadata.error) : "tool execution error"
1482
+ });
1483
+ }
1484
+ }
1485
+ } catch (error) {
1486
+ debugLogger2.warn(
1487
+ `Failed to update tool execution span attributes/status: ${error instanceof Error ? error.message : String(error)}`
1488
+ );
1489
+ }
1490
+ try {
1491
+ spanCtx.span.end();
1492
+ } catch (error) {
1493
+ debugLogger2.warn(
1494
+ `Failed to end tool execution span: ${error instanceof Error ? error.message : String(error)}`
1495
+ );
1496
+ }
1497
+ activeSpans.delete(spanId);
1498
+ strongSpans.delete(spanId);
1499
+ }
1500
+ __name(endToolExecutionSpan, "endToolExecutionSpan");
1501
+ function startToolBlockedOnUserSpan(toolSpan, attrs) {
1502
+ if (!isTelemetrySdkInitialized()) {
1503
+ return NOOP_SPAN;
1504
+ }
1505
+ ensureCleanupInterval();
1506
+ const parentSpanId = getSpanId(toolSpan);
1507
+ const parentSpanCtx = activeSpans.get(parentSpanId)?.deref();
1508
+ if (!parentSpanCtx) {
1509
+ debugLogger2.debug(
1510
+ "startToolBlockedOnUserSpan: tool span not in activeSpans (already ended?) \u2014 using resolveParentContext fallback"
1511
+ );
1512
+ }
1513
+ const ctx = parentSpanCtx ? trace.setSpan(context.active(), parentSpanCtx.span) : resolveParentContext(void 0);
1514
+ const sessionParentCtx = parentSpanCtx ?? subagentContext.getStore() ?? interactionContext.getStore() ?? void 0;
1515
+ const sessionId = resolveSessionId(sessionParentCtx);
1516
+ const attributes = {
1517
+ ...sessionId ? { "session.id": sessionId } : {}
1518
+ };
1519
+ if (attrs?.tool_name !== void 0) attributes["tool.name"] = attrs.tool_name;
1520
+ if (attrs?.call_id !== void 0) attributes["tool.call_id"] = attrs.call_id;
1521
+ const span = getTracer().startSpan(
1522
+ SPAN_TOOL_BLOCKED_ON_USER,
1523
+ { kind: SpanKind.INTERNAL, attributes },
1524
+ ctx
1525
+ );
1526
+ const spanId = getSpanId(span);
1527
+ const spanContextObj = {
1528
+ span,
1529
+ startTime: Date.now(),
1530
+ attributes,
1531
+ type: "tool.blocked_on_user"
1532
+ };
1533
+ activeSpans.set(spanId, new WeakRef(spanContextObj));
1534
+ strongSpans.set(spanId, spanContextObj);
1535
+ return span;
1536
+ }
1537
+ __name(startToolBlockedOnUserSpan, "startToolBlockedOnUserSpan");
1538
+ function endToolBlockedOnUserSpan(span, metadata) {
1539
+ const spanId = getSpanId(span);
1540
+ const spanCtx = activeSpans.get(spanId)?.deref();
1541
+ if (!spanCtx) return;
1542
+ if (spanCtx.ended) {
1543
+ debugLogger2.debug(
1544
+ `endToolBlockedOnUserSpan: span ${spanId} already ended (possible TTL sweep race)`
1545
+ );
1546
+ return;
1547
+ }
1548
+ spanCtx.ended = true;
1549
+ try {
1550
+ const duration = Date.now() - spanCtx.startTime;
1551
+ const endAttributes = { duration_ms: duration };
1552
+ if (metadata?.decision !== void 0)
1553
+ endAttributes["decision"] = metadata.decision;
1554
+ if (metadata?.source !== void 0)
1555
+ endAttributes["source"] = metadata.source;
1556
+ spanCtx.span.setAttributes(endAttributes);
1557
+ } catch (error) {
1558
+ debugLogger2.warn(
1559
+ `Failed to update blocked_on_user span attributes: ${error instanceof Error ? error.message : String(error)}`
1560
+ );
1561
+ }
1562
+ try {
1563
+ spanCtx.span.end();
1564
+ } catch (error) {
1565
+ debugLogger2.warn(
1566
+ `Failed to end blocked_on_user span: ${error instanceof Error ? error.message : String(error)}`
1567
+ );
1568
+ }
1569
+ activeSpans.delete(spanId);
1570
+ strongSpans.delete(spanId);
1571
+ }
1572
+ __name(endToolBlockedOnUserSpan, "endToolBlockedOnUserSpan");
1573
+ function startHookSpan(opts) {
1574
+ if (!isTelemetrySdkInitialized()) {
1575
+ return NOOP_SPAN;
1576
+ }
1577
+ ensureCleanupInterval();
1578
+ const parentCtx = toolContext.getStore() ?? subagentContext.getStore() ?? interactionContext.getStore() ?? void 0;
1579
+ const ctx = resolveParentContext(parentCtx);
1580
+ const sessionId = resolveSessionId(parentCtx);
1581
+ const attributes = {
1582
+ ...sessionId ? { "session.id": sessionId } : {},
1583
+ hook_event: opts.hookEvent,
1584
+ "tool.name": opts.toolName
1585
+ };
1586
+ if (opts.toolUseId !== void 0) attributes["tool.use_id"] = opts.toolUseId;
1587
+ if (opts.isInterrupt !== void 0)
1588
+ attributes["is_interrupt"] = opts.isInterrupt;
1589
+ const span = getTracer().startSpan(
1590
+ SPAN_HOOK,
1591
+ { kind: SpanKind.INTERNAL, attributes },
1592
+ ctx
1593
+ );
1594
+ const spanId = getSpanId(span);
1595
+ const spanContextObj = {
1596
+ span,
1597
+ startTime: Date.now(),
1598
+ attributes,
1599
+ type: "hook"
1600
+ };
1601
+ activeSpans.set(spanId, new WeakRef(spanContextObj));
1602
+ strongSpans.set(spanId, spanContextObj);
1603
+ return span;
1604
+ }
1605
+ __name(startHookSpan, "startHookSpan");
1606
+ function endHookSpan(span, metadata) {
1607
+ const spanId = getSpanId(span);
1608
+ const spanCtx = activeSpans.get(spanId)?.deref();
1609
+ if (!spanCtx) return;
1610
+ if (spanCtx.ended) {
1611
+ debugLogger2.debug(
1612
+ `endHookSpan: span ${spanId} already ended (possible TTL sweep race)`
1613
+ );
1614
+ return;
1615
+ }
1616
+ spanCtx.ended = true;
1617
+ try {
1618
+ const duration = Date.now() - spanCtx.startTime;
1619
+ const endAttributes = { duration_ms: duration };
1620
+ if (metadata) {
1621
+ if (metadata.success !== void 0)
1622
+ endAttributes["success"] = metadata.success;
1623
+ if (metadata.shouldProceed !== void 0)
1624
+ endAttributes["should_proceed"] = metadata.shouldProceed;
1625
+ if (metadata.shouldStop !== void 0)
1626
+ endAttributes["should_stop"] = metadata.shouldStop;
1627
+ if (metadata.blockType !== void 0)
1628
+ endAttributes["block_type"] = metadata.blockType;
1629
+ if (metadata.hasAdditionalContext !== void 0)
1630
+ endAttributes["has_additional_context"] = metadata.hasAdditionalContext;
1631
+ if (metadata.postBatchStop !== void 0)
1632
+ endAttributes["post_batch_stop"] = metadata.postBatchStop;
1633
+ if (metadata.postBatchStopReason !== void 0)
1634
+ endAttributes["post_batch_stop_reason"] = truncateSpanError(
1635
+ metadata.postBatchStopReason
1636
+ );
1637
+ if (metadata.error !== void 0)
1638
+ endAttributes["error"] = truncateSpanError(metadata.error);
1639
+ }
1640
+ spanCtx.span.setAttributes(endAttributes);
1641
+ if (metadata?.error !== void 0) {
1642
+ spanCtx.span.setStatus({
1643
+ code: SpanStatusCode.ERROR,
1644
+ message: truncateSpanError(metadata.error)
1645
+ });
1646
+ }
1647
+ } catch (error) {
1648
+ debugLogger2.warn(
1649
+ `Failed to update hook span attributes/status: ${error instanceof Error ? error.message : String(error)}`
1650
+ );
1651
+ }
1652
+ try {
1653
+ spanCtx.span.end();
1654
+ } catch (error) {
1655
+ debugLogger2.warn(
1656
+ `Failed to end hook span: ${error instanceof Error ? error.message : String(error)}`
1657
+ );
1658
+ }
1659
+ activeSpans.delete(spanId);
1660
+ strongSpans.delete(spanId);
1661
+ }
1662
+ __name(endHookSpan, "endHookSpan");
1663
+ function startSubagentSpan(opts) {
1664
+ if (!isTelemetrySdkInitialized()) return NOOP_SPAN;
1665
+ ensureCleanupInterval();
1666
+ const attributes = {
1667
+ // Spec-aligned (OTel GenAI Agent Spans, Development status).
1668
+ "gen_ai.operation.name": "invoke_agent",
1669
+ "gen_ai.provider.name": SERVICE_NAME,
1670
+ "gen_ai.agent.id": opts.agentId,
1671
+ "gen_ai.agent.name": opts.subagentName,
1672
+ "gen_ai.conversation.id": opts.sessionId,
1673
+ // Vendor (qwen-code-specific). Dual-emit id/name so dashboards already
1674
+ // querying spec keys still work.
1675
+ "qwen-code.subagent.id": opts.agentId,
1676
+ "qwen-code.subagent.name": opts.subagentName,
1677
+ "qwen-code.subagent.invocation_kind": opts.invocationKind,
1678
+ "qwen-code.subagent.is_built_in": opts.isBuiltIn,
1679
+ "qwen-code.subagent.depth": opts.depth
1680
+ };
1681
+ if (opts.modelOverride !== void 0) {
1682
+ attributes["gen_ai.request.model"] = opts.modelOverride;
1683
+ }
1684
+ if (opts.parentAgentId !== void 0) {
1685
+ attributes["qwen-code.subagent.parent_agent_id"] = opts.parentAgentId;
1686
+ }
1687
+ if (opts.invokingRequestId !== void 0) {
1688
+ attributes["qwen-code.subagent.invoking_request_id"] = opts.invokingRequestId;
1689
+ }
1690
+ const tracer2 = getTracer();
1691
+ let span;
1692
+ if (opts.invocationKind === "foreground") {
1693
+ span = tracer2.startSpan(SPAN_SUBAGENT, {
1694
+ kind: SpanKind.INTERNAL,
1695
+ attributes
1696
+ });
1697
+ } else {
1698
+ span = tracer2.startSpan(SPAN_SUBAGENT, {
1699
+ kind: SpanKind.INTERNAL,
1700
+ attributes,
1701
+ root: true,
1702
+ links: opts.invokerSpanContext ? [
1703
+ {
1704
+ context: opts.invokerSpanContext,
1705
+ attributes: { "qwen-code.link.kind": "invoker" }
1706
+ }
1707
+ ] : void 0
1708
+ });
1709
+ }
1710
+ const spanId = getSpanId(span);
1711
+ const spanContextObj = {
1712
+ span,
1713
+ startTime: Date.now(),
1714
+ attributes,
1715
+ type: "subagent"
1716
+ };
1717
+ activeSpans.set(spanId, new WeakRef(spanContextObj));
1718
+ strongSpans.set(spanId, spanContextObj);
1719
+ return span;
1720
+ }
1721
+ __name(startSubagentSpan, "startSubagentSpan");
1722
+ function runInSubagentSpanContext(span, fn) {
1723
+ const spanId = getSpanId(span);
1724
+ const spanCtx = activeSpans.get(spanId)?.deref();
1725
+ if (!spanCtx) return fn();
1726
+ const otelCtxWithSpan = trace.setSpan(context.active(), span);
1727
+ return subagentContext.run(
1728
+ spanCtx,
1729
+ () => toolContext.run(void 0, () => context.with(otelCtxWithSpan, fn))
1730
+ );
1731
+ }
1732
+ __name(runInSubagentSpanContext, "runInSubagentSpanContext");
1733
+ function endSubagentSpan(span, metadata) {
1734
+ const spanId = getSpanId(span);
1735
+ const spanCtx = activeSpans.get(spanId)?.deref();
1736
+ if (!spanCtx) {
1737
+ if (isTelemetrySdkInitialized()) {
1738
+ debugLogger2.warn(
1739
+ `endSubagentSpan: span ${spanId} not found in activeSpans (already swept?) \u2014 intended status=${metadata.status}, reason=${metadata.terminateReason ?? "none"}`
1740
+ );
1741
+ }
1742
+ return;
1743
+ }
1744
+ if (spanCtx.ended) {
1745
+ debugLogger2.warn(
1746
+ `endSubagentSpan: span ${spanId} already ended \u2014 intended status=${metadata.status}, reason=${metadata.terminateReason ?? "none"} (possible TTL sweep race)`
1747
+ );
1748
+ return;
1749
+ }
1750
+ spanCtx.ended = true;
1751
+ try {
1752
+ const duration = Date.now() - spanCtx.startTime;
1753
+ const endAttributes = {
1754
+ duration_ms: duration,
1755
+ "qwen-code.subagent.duration_ms": duration,
1756
+ "qwen-code.subagent.status": metadata.status
1757
+ };
1758
+ if (metadata.terminateReason !== void 0) {
1759
+ endAttributes["qwen-code.subagent.terminate_reason"] = metadata.terminateReason;
1760
+ }
1761
+ if (metadata.resultSummaryPresent !== void 0) {
1762
+ endAttributes["qwen-code.subagent.result_summary_present"] = metadata.resultSummaryPresent;
1763
+ }
1764
+ if (metadata.error !== void 0) {
1765
+ const truncated = truncateSpanError(metadata.error);
1766
+ endAttributes["exception.message"] = truncated;
1767
+ }
1768
+ if (metadata.errorType !== void 0) {
1769
+ endAttributes["error.type"] = metadata.errorType;
1770
+ }
1771
+ spanCtx.span.setAttributes(endAttributes);
1772
+ if (metadata.status === "completed") {
1773
+ spanCtx.span.setStatus({ code: SpanStatusCode.OK });
1774
+ } else if (metadata.status === "failed") {
1775
+ spanCtx.span.setStatus({
1776
+ code: SpanStatusCode.ERROR,
1777
+ message: metadata.error ? truncateSpanError(metadata.error) : "subagent failed"
1778
+ });
1779
+ }
1780
+ } catch (error) {
1781
+ debugLogger2.warn(
1782
+ `Failed to update subagent span attributes/status: ${error instanceof Error ? error.message : String(error)}`
1783
+ );
1784
+ }
1785
+ try {
1786
+ spanCtx.span.end();
1787
+ } catch (error) {
1788
+ debugLogger2.warn(
1789
+ `Failed to end subagent span: ${error instanceof Error ? error.message : String(error)}`
1790
+ );
1791
+ }
1792
+ activeSpans.delete(spanId);
1793
+ strongSpans.delete(spanId);
1794
+ }
1795
+ __name(endSubagentSpan, "endSubagentSpan");
1796
+ function getActiveInteractionSpan() {
1797
+ const ctx = interactionContext.getStore() ?? lastInteractionCtx;
1798
+ if (!ctx || ctx.ended) return void 0;
1799
+ return ctx.span;
1800
+ }
1801
+ __name(getActiveInteractionSpan, "getActiveInteractionSpan");
1802
+
1803
+ // packages/core/src/telemetry/sdk.ts
1804
+ function createTelemetryDiagLogger() {
1805
+ const debugLogger3 = createDebugLogger("OTEL");
1806
+ return {
1807
+ error: /* @__PURE__ */ __name((message, ...args) => debugLogger3.error(message, ...args), "error"),
1808
+ warn: /* @__PURE__ */ __name((message, ...args) => debugLogger3.warn(message, ...args), "warn"),
1809
+ info: /* @__PURE__ */ __name((message, ...args) => debugLogger3.info(message, ...args), "info"),
1810
+ debug: /* @__PURE__ */ __name((message, ...args) => debugLogger3.debug(message, ...args), "debug"),
1811
+ verbose: /* @__PURE__ */ __name((message, ...args) => debugLogger3.debug(message, ...args), "verbose")
1812
+ };
1813
+ }
1814
+ __name(createTelemetryDiagLogger, "createTelemetryDiagLogger");
1815
+ diag.setLogger(createTelemetryDiagLogger(), DiagLogLevel.WARN);
1816
+ var SHUTDOWN_TIMEOUT_MS = 1e4;
1817
+ var sdk;
1818
+ var telemetryInitialized = false;
1819
+ var telemetryInitPromise;
1820
+ var telemetryShutdownPromise;
1821
+ var activeMetricReader;
1822
+ function isTelemetrySdkInitialized() {
1823
+ return telemetryInitialized;
1824
+ }
1825
+ __name(isTelemetrySdkInitialized, "isTelemetrySdkInitialized");
1826
+ function initializeTelemetry(config) {
1827
+ if (telemetryInitialized || !config.getTelemetryEnabled()) {
1828
+ return Promise.resolve();
1829
+ }
1830
+ telemetryInitPromise ??= (async () => {
1831
+ const debugLogger3 = createDebugLogger("OTEL");
1832
+ try {
1833
+ const { startTelemetrySdk } = await import("./sdk-impl-5ESZBGJQ.js");
1834
+ if (telemetryInitialized) return;
1835
+ const started = await startTelemetrySdk(config);
1836
+ if (!started) return;
1837
+ sdk = started.sdk;
1838
+ sdk.start();
1839
+ debugLogger3.debug("OpenTelemetry SDK started successfully.");
1840
+ telemetryInitialized = true;
1841
+ activeMetricReader = started.metricReader;
1842
+ const sessionId = config.getSessionId();
1843
+ setSessionContext(createSessionRootContext(sessionId), sessionId);
1844
+ setShellTracePropagation(
1845
+ config.getOutboundCorrelationPropagateTraceContext()
1846
+ );
1847
+ initializeMetrics(config);
1848
+ } catch (error) {
1849
+ debugLogger3.error("Error starting OpenTelemetry SDK:", error);
1850
+ }
1851
+ })().finally(() => {
1852
+ telemetryInitPromise = void 0;
1853
+ });
1854
+ return telemetryInitPromise;
1855
+ }
1856
+ __name(initializeTelemetry, "initializeTelemetry");
1857
+ function refreshSessionContext(sessionId) {
1858
+ if (!telemetryInitialized) return;
1859
+ try {
1860
+ setSessionContext(createSessionRootContext(sessionId), sessionId);
1861
+ } catch (error) {
1862
+ createDebugLogger("OTEL").warn("Failed to refresh session context:", error);
1863
+ }
1864
+ }
1865
+ __name(refreshSessionContext, "refreshSessionContext");
1866
+ function shutdownTelemetry() {
1867
+ if (telemetryShutdownPromise) {
1868
+ return telemetryShutdownPromise;
1869
+ }
1870
+ const pendingInit = telemetryInitPromise;
1871
+ if (!pendingInit && (!telemetryInitialized || !sdk)) {
1872
+ return Promise.resolve();
1873
+ }
1874
+ telemetryShutdownPromise = (async () => {
1875
+ if (pendingInit) {
1876
+ await pendingInit.catch(() => {
1877
+ });
1878
+ }
1879
+ if (!telemetryInitialized || !sdk) {
1880
+ telemetryShutdownPromise = void 0;
1881
+ return;
1882
+ }
1883
+ endInteractionSpan("cancelled");
1884
+ const currentSdk = sdk;
1885
+ const debugLogger3 = createDebugLogger("OTEL");
1886
+ let timer;
1887
+ let timedOut = false;
1888
+ try {
1889
+ const sdkShutdown = Promise.resolve(currentSdk.shutdown());
1890
+ sdkShutdown.catch((err) => {
1891
+ if (timedOut) {
1892
+ debugLogger3.warn(
1893
+ "SDK shutdown rejected after timeout:",
1894
+ err instanceof Error ? err.message : err
1895
+ );
1896
+ }
1897
+ });
1898
+ const timeout = new Promise((resolve) => {
1899
+ timer = setTimeout(() => {
1900
+ timedOut = true;
1901
+ resolve("timeout");
1902
+ }, SHUTDOWN_TIMEOUT_MS);
1903
+ timer.unref?.();
1904
+ });
1905
+ const result = await Promise.race([sdkShutdown, timeout]);
1906
+ clearTimeout(timer);
1907
+ if (result === "timeout") {
1908
+ const msg = `Telemetry shutdown timed out after ${SHUTDOWN_TIMEOUT_MS}ms.`;
1909
+ diag.warn(msg);
1910
+ debugLogger3.warn(msg);
1911
+ } else {
1912
+ debugLogger3.debug("OpenTelemetry SDK shut down successfully.");
1913
+ }
1914
+ } catch (error) {
1915
+ clearTimeout(timer);
1916
+ diag.error("Error shutting down SDK:", error);
1917
+ debugLogger3.error("Error shutting down SDK:", error);
1918
+ } finally {
1919
+ telemetryInitialized = false;
1920
+ sdk = void 0;
1921
+ activeMetricReader = void 0;
1922
+ telemetryShutdownPromise = void 0;
1923
+ setSessionContext(void 0);
1924
+ setShellTracePropagation(false);
1925
+ }
1926
+ })();
1927
+ return telemetryShutdownPromise;
1928
+ }
1929
+ __name(shutdownTelemetry, "shutdownTelemetry");
1930
+ var FORCE_FLUSH_TIMEOUT_MS = 2e3;
1931
+ async function forceFlushMetrics() {
1932
+ if (!telemetryInitialized || !activeMetricReader) return;
1933
+ const flush = activeMetricReader.forceFlush();
1934
+ flush.catch(() => {
1935
+ });
1936
+ let timer;
1937
+ const timeout = new Promise((_, reject) => {
1938
+ timer = setTimeout(
1939
+ () => reject(
1940
+ new Error(
1941
+ `forceFlushMetrics timed out after ${FORCE_FLUSH_TIMEOUT_MS}ms`
1942
+ )
1943
+ ),
1944
+ FORCE_FLUSH_TIMEOUT_MS
1945
+ );
1946
+ timer.unref?.();
1947
+ });
1948
+ try {
1949
+ await Promise.race([flush, timeout]);
1950
+ } finally {
1951
+ clearTimeout(timer);
1952
+ }
1953
+ }
1954
+ __name(forceFlushMetrics, "forceFlushMetrics");
1955
+
1956
+ // packages/core/src/telemetry/detailed-span-attributes.ts
1957
+ var SYSTEM_PROMPT_PREVIEW_LENGTH = 500;
1958
+ var SHORT_TRUNCATION_SUFFIX = "...[TRUNCATED]";
1959
+ var seenHashes = /* @__PURE__ */ new Set();
1960
+ function areSensitiveSpanAttributesEnabled(config) {
1961
+ return isTelemetrySdkInitialized() && config.getTelemetryIncludeSensitiveSpanAttributes();
1962
+ }
1963
+ __name(areSensitiveSpanAttributesEnabled, "areSensitiveSpanAttributesEnabled");
1964
+ function truncateContent(content, maxSize = DEFAULT_SENSITIVE_SPAN_ATTRIBUTE_MAX_LENGTH, originalLength = content.length) {
1965
+ if (!Number.isSafeInteger(maxSize) || maxSize < 1) {
1966
+ throw new TypeError(
1967
+ `maxSize must be a positive safe integer, got ${String(maxSize)}`
1968
+ );
1969
+ }
1970
+ if (!Number.isSafeInteger(originalLength) || originalLength < 0) {
1971
+ throw new TypeError(
1972
+ `originalLength must be a non-negative safe integer, got ${String(
1973
+ originalLength
1974
+ )}`
1975
+ );
1976
+ }
1977
+ if (originalLength < content.length) {
1978
+ throw new TypeError(
1979
+ `originalLength must be greater than or equal to content length, got ${originalLength} for content length ${content.length}`
1980
+ );
1981
+ }
1982
+ if (originalLength <= maxSize && content.length <= maxSize) {
1983
+ return { content, truncated: false };
1984
+ }
1985
+ if (originalLength > content.length && content.length <= maxSize) {
1986
+ return { content, truncated: true };
1987
+ }
1988
+ const suffix = `
1989
+
1990
+ [TRUNCATED - Content exceeds configured limit of ${maxSize} characters]`;
1991
+ if (suffix.length >= maxSize) {
1992
+ if (SHORT_TRUNCATION_SUFFIX.length >= maxSize) {
1993
+ return {
1994
+ content: SHORT_TRUNCATION_SUFFIX.slice(0, maxSize),
1995
+ truncated: true
1996
+ };
1997
+ }
1998
+ return {
1999
+ content: content.slice(0, maxSize - SHORT_TRUNCATION_SUFFIX.length) + SHORT_TRUNCATION_SUFFIX,
2000
+ truncated: true
2001
+ };
2002
+ }
2003
+ return {
2004
+ content: content.slice(0, maxSize - suffix.length) + suffix,
2005
+ truncated: true
2006
+ };
2007
+ }
2008
+ __name(truncateContent, "truncateContent");
2009
+ function getMaxContentSize(config) {
2010
+ return config.getTelemetrySensitiveSpanAttributeMaxLength();
2011
+ }
2012
+ __name(getMaxContentSize, "getMaxContentSize");
2013
+ function truncatePrefixedContent(prefix, content, maxSize) {
2014
+ const prefixedContent = `${prefix}${content}`;
2015
+ const result = truncateContent(prefixedContent, maxSize);
2016
+ return {
2017
+ ...result,
2018
+ originalLength: content.length
2019
+ };
2020
+ }
2021
+ __name(truncatePrefixedContent, "truncatePrefixedContent");
2022
+ function shortHash(content) {
2023
+ return createHash2("sha256").update(content).digest("hex").slice(0, 12);
2024
+ }
2025
+ __name(shortHash, "shortHash");
2026
+ function stringifyContentUnion(value) {
2027
+ if (typeof value === "string") return value;
2028
+ return safeJsonStringify(value) ?? "";
2029
+ }
2030
+ __name(stringifyContentUnion, "stringifyContentUnion");
2031
+ function addUserPromptAttributes(config, span, promptText) {
2032
+ if (!areSensitiveSpanAttributesEnabled(config) || !promptText) return;
2033
+ const { content, truncated, originalLength } = truncatePrefixedContent(
2034
+ `[USER PROMPT]
2035
+ `,
2036
+ promptText,
2037
+ getMaxContentSize(config)
2038
+ );
2039
+ span.setAttributes({
2040
+ new_context: content,
2041
+ ...truncated && {
2042
+ new_context_truncated: true,
2043
+ new_context_original_length: originalLength
2044
+ }
2045
+ });
2046
+ }
2047
+ __name(addUserPromptAttributes, "addUserPromptAttributes");
2048
+ function addSystemPromptAttributes(config, span, systemInstruction) {
2049
+ if (!areSensitiveSpanAttributesEnabled(config) || !systemInstruction) return;
2050
+ const text = stringifyContentUnion(systemInstruction);
2051
+ if (!text) return;
2052
+ const hash = `sp_${shortHash(text)}`;
2053
+ span.setAttributes({
2054
+ system_prompt_hash: hash,
2055
+ system_prompt_preview: text.slice(0, SYSTEM_PROMPT_PREVIEW_LENGTH),
2056
+ system_prompt_length: text.length
2057
+ });
2058
+ if (!seenHashes.has(hash)) {
2059
+ seenHashes.add(hash);
2060
+ const { content, truncated } = truncateContent(
2061
+ text,
2062
+ getMaxContentSize(config)
2063
+ );
2064
+ span.setAttribute("system_prompt", content);
2065
+ if (truncated) {
2066
+ span.setAttribute("system_prompt_truncated", true);
2067
+ }
2068
+ }
2069
+ }
2070
+ __name(addSystemPromptAttributes, "addSystemPromptAttributes");
2071
+ function addToolSchemaAttributes(config, span, tools) {
2072
+ if (!areSensitiveSpanAttributesEnabled(config) || !tools?.length) return;
2073
+ const declarations = [];
2074
+ for (const tool of tools) {
2075
+ const inner = tool["functionDeclarations"];
2076
+ if (Array.isArray(inner)) {
2077
+ declarations.push(...inner);
2078
+ } else {
2079
+ declarations.push(tool);
2080
+ }
2081
+ }
2082
+ const summary = [];
2083
+ for (const decl of declarations) {
2084
+ const declObj = decl;
2085
+ const name = typeof declObj["name"] === "string" ? declObj["name"] : "unknown_tool";
2086
+ const declJson = safeJsonStringify(decl) ?? `unstringifiable_${name}`;
2087
+ const hash = shortHash(declJson);
2088
+ summary.push({ name, hash });
2089
+ const hashKey = `tool_${hash}`;
2090
+ if (!seenHashes.has(hashKey)) {
2091
+ seenHashes.add(hashKey);
2092
+ const { content, truncated } = truncateContent(
2093
+ declJson,
2094
+ getMaxContentSize(config)
2095
+ );
2096
+ span.addEvent("tool_schema", {
2097
+ tool_name: name,
2098
+ tool_hash: hash,
2099
+ tool_definition: content,
2100
+ ...truncated && {
2101
+ tool_definition_truncated: true,
2102
+ tool_definition_original_length: declJson.length
2103
+ }
2104
+ });
2105
+ }
2106
+ }
2107
+ span.setAttributes({
2108
+ tools: safeJsonStringify(summary) ?? "[]",
2109
+ tools_count: summary.length
2110
+ });
2111
+ }
2112
+ __name(addToolSchemaAttributes, "addToolSchemaAttributes");
2113
+ function addModelOutputAttributes(config, span, responseText, originalLength) {
2114
+ if (!areSensitiveSpanAttributesEnabled(config) || !responseText) return;
2115
+ const responseTextOriginalLength = originalLength ?? responseText.length;
2116
+ const { content, truncated } = truncateContent(
2117
+ responseText,
2118
+ getMaxContentSize(config),
2119
+ responseTextOriginalLength
2120
+ );
2121
+ span.setAttributes({
2122
+ "response.model_output": content,
2123
+ ...truncated && {
2124
+ "response.model_output_truncated": true,
2125
+ "response.model_output_original_length": responseTextOriginalLength
2126
+ }
2127
+ });
2128
+ }
2129
+ __name(addModelOutputAttributes, "addModelOutputAttributes");
2130
+ function addToolInputAttributes(config, span, toolName, toolInput) {
2131
+ if (!areSensitiveSpanAttributesEnabled(config)) return;
2132
+ const { content, truncated, originalLength } = truncatePrefixedContent(
2133
+ `[TOOL INPUT: ${toolName}]
2134
+ `,
2135
+ toolInput,
2136
+ getMaxContentSize(config)
2137
+ );
2138
+ span.setAttributes({
2139
+ tool_input: content,
2140
+ ...truncated && {
2141
+ tool_input_truncated: true,
2142
+ tool_input_original_length: originalLength
2143
+ }
2144
+ });
2145
+ }
2146
+ __name(addToolInputAttributes, "addToolInputAttributes");
2147
+ function addToolResultAttributes(config, span, toolName, toolResult) {
2148
+ if (!areSensitiveSpanAttributesEnabled(config)) return;
2149
+ const { content, truncated, originalLength } = truncatePrefixedContent(
2150
+ `[TOOL RESULT: ${toolName}]
2151
+ `,
2152
+ toolResult,
2153
+ getMaxContentSize(config)
2154
+ );
2155
+ span.setAttributes({
2156
+ tool_result: content,
2157
+ ...truncated && {
2158
+ tool_result_truncated: true,
2159
+ tool_result_original_length: originalLength
2160
+ }
2161
+ });
2162
+ }
2163
+ __name(addToolResultAttributes, "addToolResultAttributes");
2164
+ function clearDetailedSpanState() {
2165
+ seenHashes.clear();
2166
+ }
2167
+ __name(clearDetailedSpanState, "clearDetailedSpanState");
2168
+
2169
+ export {
2170
+ FileOperation,
2171
+ PerformanceMetricType,
2172
+ MemoryMetricType,
2173
+ ToolExecutionPhase,
2174
+ ApiRequestPhase,
2175
+ getMeter,
2176
+ recordChatCompressionMetrics,
2177
+ recordToolCallMetrics,
2178
+ recordTokenUsageMetrics,
2179
+ recordApiResponseMetrics,
2180
+ recordApiErrorMetrics,
2181
+ recordFileOperationMetric,
2182
+ recordInvalidChunk,
2183
+ recordContentRetry,
2184
+ recordContentRetryFailure,
2185
+ recordApiRetry,
2186
+ recordModelSlashCommand,
2187
+ recordStartupPerformance,
2188
+ recordMemoryUsage,
2189
+ recordCpuUsage,
2190
+ recordToolQueueDepth,
2191
+ recordToolExecutionBreakdown,
2192
+ recordTokenEfficiency,
2193
+ recordApiRequestBreakdown,
2194
+ recordPerformanceScore,
2195
+ recordPerformanceRegression,
2196
+ recordBaselineComparison,
2197
+ isPerformanceMonitoringActive,
2198
+ recordSubagentExecutionMetrics,
2199
+ recordArenaSessionStartedMetrics,
2200
+ recordArenaAgentCompletedMetrics,
2201
+ recordArenaSessionEndedMetrics,
2202
+ recordMemoryExtractMetrics,
2203
+ recordMemoryDreamMetrics,
2204
+ recordMemoryRecallMetrics,
2205
+ recordChannelMemoryRecallMetrics,
2206
+ deriveTraceId,
2207
+ randomSpanId,
2208
+ randomHexString,
2209
+ API_CALL_FAILED_SPAN_STATUS_MESSAGE,
2210
+ API_CALL_ABORTED_SPAN_STATUS_MESSAGE,
2211
+ safeSetStatus,
2212
+ areSensitiveSpanAttributesEnabled,
2213
+ truncateContent,
2214
+ addUserPromptAttributes,
2215
+ addSystemPromptAttributes,
2216
+ addToolSchemaAttributes,
2217
+ addModelOutputAttributes,
2218
+ addToolInputAttributes,
2219
+ addToolResultAttributes,
2220
+ clearDetailedSpanState,
2221
+ isInNativeSubagentSpan,
2222
+ truncateSpanError,
2223
+ startInteractionSpan,
2224
+ endInteractionSpan,
2225
+ withInteractionSpan,
2226
+ startLLMRequestSpan,
2227
+ endLLMRequestSpan,
2228
+ startToolSpan,
2229
+ runInToolSpanContext,
2230
+ endToolSpan,
2231
+ startToolExecutionSpan,
2232
+ endToolExecutionSpan,
2233
+ startToolBlockedOnUserSpan,
2234
+ endToolBlockedOnUserSpan,
2235
+ startHookSpan,
2236
+ endHookSpan,
2237
+ startSubagentSpan,
2238
+ runInSubagentSpanContext,
2239
+ endSubagentSpan,
2240
+ getActiveInteractionSpan,
2241
+ isTelemetrySdkInitialized,
2242
+ initializeTelemetry,
2243
+ refreshSessionContext,
2244
+ shutdownTelemetry,
2245
+ forceFlushMetrics
2246
+ };
2247
+ /**
2248
+ * @license
2249
+ * Copyright 2025 Google LLC
2250
+ * SPDX-License-Identifier: Apache-2.0
2251
+ */
2252
+ /**
2253
+ * @license
2254
+ * Copyright 2026 Qwen Team
2255
+ * SPDX-License-Identifier: Apache-2.0
2256
+ */