@tangle-network/agent-eval 0.129.0 → 0.130.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 (428) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +2 -0
  3. package/dist/active-curriculum-C4mk67HP.js +214 -0
  4. package/dist/active-curriculum-C4mk67HP.js.map +1 -0
  5. package/dist/adversarial-smnADNFS.d.ts +21 -0
  6. package/dist/adversarial-smnADNFS.d.ts.map +1 -0
  7. package/dist/analyst/index.d.ts +81 -2872
  8. package/dist/analyst/index.d.ts.map +1 -0
  9. package/dist/analyst/index.js +319 -360
  10. package/dist/analyst/index.js.map +1 -1
  11. package/dist/analyst-BkTS3C58.d.ts +89 -0
  12. package/dist/analyst-BkTS3C58.d.ts.map +1 -0
  13. package/dist/analyst-LsnNpSkm.js +152 -0
  14. package/dist/analyst-LsnNpSkm.js.map +1 -0
  15. package/dist/analyze-runs-C1CavBMk.js +1067 -0
  16. package/dist/analyze-runs-C1CavBMk.js.map +1 -0
  17. package/dist/analyze-runs-FsgYCinh.d.ts +72 -0
  18. package/dist/analyze-runs-FsgYCinh.d.ts.map +1 -0
  19. package/dist/attribute-vocabulary-DLJ6303h.d.ts +54 -0
  20. package/dist/attribute-vocabulary-DLJ6303h.d.ts.map +1 -0
  21. package/dist/authenticity/index.d.ts +81 -79
  22. package/dist/authenticity/index.d.ts.map +1 -0
  23. package/dist/authenticity/index.js +209 -193
  24. package/dist/authenticity/index.js.map +1 -1
  25. package/dist/baseline-HsBvw_dk.js +550 -0
  26. package/dist/baseline-HsBvw_dk.js.map +1 -0
  27. package/dist/baseline-hG3K85h4.d.ts +125 -0
  28. package/dist/baseline-hG3K85h4.d.ts.map +1 -0
  29. package/dist/belief-state/index.d.ts +448 -1188
  30. package/dist/belief-state/index.d.ts.map +1 -0
  31. package/dist/belief-state/index.js +1617 -1709
  32. package/dist/belief-state/index.js.map +1 -1
  33. package/dist/benchmarks/index.d.ts +2 -891
  34. package/dist/benchmarks/index.js +2 -60
  35. package/dist/benchmarks-BJgDGkAD.js +754 -0
  36. package/dist/benchmarks-BJgDGkAD.js.map +1 -0
  37. package/dist/builder-eval/index.d.ts +150 -662
  38. package/dist/builder-eval/index.d.ts.map +1 -0
  39. package/dist/builder-eval/index.js +356 -345
  40. package/dist/builder-eval/index.js.map +1 -1
  41. package/dist/calibration-CNWWA6K8.js +94 -0
  42. package/dist/calibration-CNWWA6K8.js.map +1 -0
  43. package/dist/campaign/index.d.ts +5 -6381
  44. package/dist/campaign/index.js +3 -213
  45. package/dist/campaign-aKJt6emI.js +3886 -0
  46. package/dist/campaign-aKJt6emI.js.map +1 -0
  47. package/dist/cli.d.ts +1 -1
  48. package/dist/cli.js +164 -175
  49. package/dist/cli.js.map +1 -1
  50. package/dist/client-C97NMzqi.d.ts +581 -0
  51. package/dist/client-C97NMzqi.d.ts.map +1 -0
  52. package/dist/client-CYzbdJOZ.js +637 -0
  53. package/dist/client-CYzbdJOZ.js.map +1 -0
  54. package/dist/code-agent-session-BjkMTQ7H.js +1390 -0
  55. package/dist/code-agent-session-BjkMTQ7H.js.map +1 -0
  56. package/dist/code-agent-session-DqqgOJaz.d.ts +143 -0
  57. package/dist/code-agent-session-DqqgOJaz.d.ts.map +1 -0
  58. package/dist/concurrency-DIxRZF_J.js +85 -0
  59. package/dist/concurrency-DIxRZF_J.js.map +1 -0
  60. package/dist/contract/index.d.ts +645 -5565
  61. package/dist/contract/index.d.ts.map +1 -0
  62. package/dist/contract/index.js +1730 -1938
  63. package/dist/contract/index.js.map +1 -1
  64. package/dist/control.d.ts +3 -1030
  65. package/dist/control.js +2 -33
  66. package/dist/cost-ledger-DIgQUFZZ.js +801 -0
  67. package/dist/cost-ledger-DIgQUFZZ.js.map +1 -0
  68. package/dist/cost-ledger-Dye6jCgg.d.ts +236 -0
  69. package/dist/cost-ledger-Dye6jCgg.d.ts.map +1 -0
  70. package/dist/dataset-BvtnC8Dc.d.ts +115 -0
  71. package/dist/dataset-BvtnC8Dc.d.ts.map +1 -0
  72. package/dist/default-registry-C-vFCSEc.js +2579 -0
  73. package/dist/default-registry-C-vFCSEc.js.map +1 -0
  74. package/dist/default-registry-CNPo-Vsb.d.ts +540 -0
  75. package/dist/default-registry-CNPo-Vsb.d.ts.map +1 -0
  76. package/dist/emitter-CPBAhxum.js +266 -0
  77. package/dist/emitter-CPBAhxum.js.map +1 -0
  78. package/dist/emitter-DGQGoLyj.d.ts +113 -0
  79. package/dist/emitter-DGQGoLyj.d.ts.map +1 -0
  80. package/dist/errors-8YnH8WlF.js +64 -0
  81. package/dist/errors-8YnH8WlF.js.map +1 -0
  82. package/dist/errors-CEk209JS.d.ts +76 -0
  83. package/dist/errors-CEk209JS.d.ts.map +1 -0
  84. package/dist/eval-campaign-DEm6c8ru.js +349 -0
  85. package/dist/eval-campaign-DEm6c8ru.js.map +1 -0
  86. package/dist/execution-tracks-CpgFPpS5.js +93 -0
  87. package/dist/execution-tracks-CpgFPpS5.js.map +1 -0
  88. package/dist/exporters-q9iL-2Jf.js +148 -0
  89. package/dist/exporters-q9iL-2Jf.js.map +1 -0
  90. package/dist/extract-usage-BrQ8mCLX.js +155 -0
  91. package/dist/extract-usage-BrQ8mCLX.js.map +1 -0
  92. package/dist/failure-cluster-CqcvCcdR.d.ts +59 -0
  93. package/dist/failure-cluster-CqcvCcdR.d.ts.map +1 -0
  94. package/dist/feedback-trajectory-CVaeREXV.d.ts +340 -0
  95. package/dist/feedback-trajectory-CVaeREXV.d.ts.map +1 -0
  96. package/dist/fuzz.d.ts +320 -646
  97. package/dist/fuzz.d.ts.map +1 -0
  98. package/dist/fuzz.js +670 -618
  99. package/dist/fuzz.js.map +1 -1
  100. package/dist/hf-dataset-DBJXXoY1.js +763 -0
  101. package/dist/hf-dataset-DBJXXoY1.js.map +1 -0
  102. package/dist/hosted/index.d.ts +11 -831
  103. package/dist/hosted/index.d.ts.map +1 -0
  104. package/dist/hosted/index.js +2 -37
  105. package/dist/index-2JJSA6-r2.d.ts +926 -0
  106. package/dist/index-2JJSA6-r2.d.ts.map +1 -0
  107. package/dist/index-6N0aYmpW.d.ts +217 -0
  108. package/dist/index-6N0aYmpW.d.ts.map +1 -0
  109. package/dist/index-BAvgST_9.d.ts +131 -0
  110. package/dist/index-BAvgST_9.d.ts.map +1 -0
  111. package/dist/index-BvnJuTGD.d.ts +68 -0
  112. package/dist/index-BvnJuTGD.d.ts.map +1 -0
  113. package/dist/index-C61Wi7yg.d.ts +547 -0
  114. package/dist/index-C61Wi7yg.d.ts.map +1 -0
  115. package/dist/index-CD_WZ_Xr.d.ts +2250 -0
  116. package/dist/index-CD_WZ_Xr.d.ts.map +1 -0
  117. package/dist/index-DSC51roc.d.ts +102 -0
  118. package/dist/index-DSC51roc.d.ts.map +1 -0
  119. package/dist/index-Em67JBjs.d.ts +335 -0
  120. package/dist/index-Em67JBjs.d.ts.map +1 -0
  121. package/dist/index.d.ts +3755 -15555
  122. package/dist/index.d.ts.map +1 -0
  123. package/dist/index.js +11182 -11216
  124. package/dist/index.js.map +1 -1
  125. package/dist/integrity-BzRbCHzi.js +424 -0
  126. package/dist/integrity-BzRbCHzi.js.map +1 -0
  127. package/dist/integrity-rmVhXWA7.d.ts +61 -0
  128. package/dist/integrity-rmVhXWA7.d.ts.map +1 -0
  129. package/dist/judge-calibration-DFtEMlde.d.ts +146 -0
  130. package/dist/judge-calibration-DFtEMlde.d.ts.map +1 -0
  131. package/dist/ledger-core/index.d.ts +2 -0
  132. package/dist/ledger-core/index.js +2 -0
  133. package/dist/ledger-core-DtZz1RG0.js +388 -0
  134. package/dist/ledger-core-DtZz1RG0.js.map +1 -0
  135. package/dist/llm-client--GR4JbZE.js +687 -0
  136. package/dist/llm-client--GR4JbZE.js.map +1 -0
  137. package/dist/llm-client-B_nIBlYo.d.ts +290 -0
  138. package/dist/llm-client-B_nIBlYo.d.ts.map +1 -0
  139. package/dist/matrix/index.d.ts +3 -155
  140. package/dist/matrix/index.js +2 -8
  141. package/dist/matrix-BzQnu2S6.js +270 -0
  142. package/dist/matrix-BzQnu2S6.js.map +1 -0
  143. package/dist/meta-eval/index.d.ts +4 -1027
  144. package/dist/meta-eval/index.js +393 -390
  145. package/dist/meta-eval/index.js.map +1 -1
  146. package/dist/metrics-C9YY1OcL.js +239 -0
  147. package/dist/metrics-C9YY1OcL.js.map +1 -0
  148. package/dist/mint-yN2M2eh0.js +201 -0
  149. package/dist/mint-yN2M2eh0.js.map +1 -0
  150. package/dist/multi-layer-verifier-BHY1gWAc.d.ts +138 -0
  151. package/dist/multi-layer-verifier-BHY1gWAc.d.ts.map +1 -0
  152. package/dist/multishot/index.d.ts +273 -480
  153. package/dist/multishot/index.d.ts.map +1 -0
  154. package/dist/multishot/index.js +595 -548
  155. package/dist/multishot/index.js.map +1 -1
  156. package/dist/off-policy-DvgzvtIx.js +220 -0
  157. package/dist/off-policy-DvgzvtIx.js.map +1 -0
  158. package/dist/off-policy-mskQw8Mb.d.ts +153 -0
  159. package/dist/off-policy-mskQw8Mb.d.ts.map +1 -0
  160. package/dist/openapi.json +1 -1
  161. package/dist/opencode-sqlite-BGrHeDu3.js +318 -0
  162. package/dist/opencode-sqlite-BGrHeDu3.js.map +1 -0
  163. package/dist/outcome-store-BYHIuO0e.d.ts +65 -0
  164. package/dist/outcome-store-BYHIuO0e.d.ts.map +1 -0
  165. package/dist/outcome-store-ChBKlTd_.js +75 -0
  166. package/dist/outcome-store-ChBKlTd_.js.map +1 -0
  167. package/dist/paired-arms-D9D0wXj2.js +260 -0
  168. package/dist/paired-arms-D9D0wXj2.js.map +1 -0
  169. package/dist/pipelines/index.d.ts +95 -532
  170. package/dist/pipelines/index.d.ts.map +1 -0
  171. package/dist/pipelines/index.js +497 -478
  172. package/dist/pipelines/index.js.map +1 -1
  173. package/dist/pre-registration-DakwTRXk.js +96 -0
  174. package/dist/pre-registration-DakwTRXk.js.map +1 -0
  175. package/dist/propose-review-control-LhIWGzHl.js +1458 -0
  176. package/dist/propose-review-control-LhIWGzHl.js.map +1 -0
  177. package/dist/query-CJ_DX8vl.d.ts +28 -0
  178. package/dist/query-CJ_DX8vl.d.ts.map +1 -0
  179. package/dist/query-Di7eEQ79.js +83 -0
  180. package/dist/query-Di7eEQ79.js.map +1 -0
  181. package/dist/raw-provider-sink-BQd7mzyT.js +201 -0
  182. package/dist/raw-provider-sink-BQd7mzyT.js.map +1 -0
  183. package/dist/raw-provider-sink-BU29Sh8h.d.ts +134 -0
  184. package/dist/raw-provider-sink-BU29Sh8h.d.ts.map +1 -0
  185. package/dist/redact-7Aq1ukl-.js +107 -0
  186. package/dist/redact-7Aq1ukl-.js.map +1 -0
  187. package/dist/release-report-Cz9NKH39.js +603 -0
  188. package/dist/release-report-Cz9NKH39.js.map +1 -0
  189. package/dist/release-report-mvB2G4_J.d.ts +244 -0
  190. package/dist/release-report-mvB2G4_J.d.ts.map +1 -0
  191. package/dist/replay-GnyotH0J.js +1741 -0
  192. package/dist/replay-GnyotH0J.js.map +1 -0
  193. package/dist/replay-OoidtG1E.d.ts +749 -0
  194. package/dist/replay-OoidtG1E.d.ts.map +1 -0
  195. package/dist/reporting.d.ts +6 -1312
  196. package/dist/reporting.js +6 -51
  197. package/dist/researcher-CwTdwXG1.d.ts +314 -0
  198. package/dist/researcher-CwTdwXG1.d.ts.map +1 -0
  199. package/dist/reward-hacking-eAnOsynk.d.ts +224 -0
  200. package/dist/reward-hacking-eAnOsynk.d.ts.map +1 -0
  201. package/dist/reward-hacking-qipEpKvY.js +596 -0
  202. package/dist/reward-hacking-qipEpKvY.js.map +1 -0
  203. package/dist/reward-nw2xZGZG.js +137 -0
  204. package/dist/reward-nw2xZGZG.js.map +1 -0
  205. package/dist/rl.d.ts +760 -4010
  206. package/dist/rl.d.ts.map +1 -0
  207. package/dist/rl.js +2325 -1958
  208. package/dist/rl.js.map +1 -1
  209. package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
  210. package/dist/rollout/index.d.ts +3 -2087
  211. package/dist/rollout/index.js +8 -168
  212. package/dist/rollout-BOYjemfR.js +624 -0
  213. package/dist/rollout-BOYjemfR.js.map +1 -0
  214. package/dist/rubric-predictive-validity-B3xmbmS1.js +141 -0
  215. package/dist/rubric-predictive-validity-B3xmbmS1.js.map +1 -0
  216. package/dist/rubric-predictive-validity-Ku_clp_1.d.ts +74 -0
  217. package/dist/rubric-predictive-validity-Ku_clp_1.d.ts.map +1 -0
  218. package/dist/run-evidence-ClRX_8A9.d.ts +225 -0
  219. package/dist/run-evidence-ClRX_8A9.d.ts.map +1 -0
  220. package/dist/run-record-BuoE80Dq.js +467 -0
  221. package/dist/{chunk-56TAVBOK.js.map → run-record-BuoE80Dq.js.map} +1 -1
  222. package/dist/run-record-CnZu_gjl.d.ts +357 -0
  223. package/dist/run-record-CnZu_gjl.d.ts.map +1 -0
  224. package/dist/run-score-iEEAWiBY.js +41 -0
  225. package/dist/run-score-iEEAWiBY.js.map +1 -0
  226. package/dist/runtime-trajectory-1gyaTOoC.js +93 -0
  227. package/dist/runtime-trajectory-1gyaTOoC.js.map +1 -0
  228. package/dist/runtime-trajectory-BvSZcCHD.d.ts +50 -0
  229. package/dist/runtime-trajectory-BvSZcCHD.d.ts.map +1 -0
  230. package/dist/schema-BtVldJ3T.d.ts +206 -0
  231. package/dist/schema-BtVldJ3T.d.ts.map +1 -0
  232. package/dist/schema-C6DW4ZHR.js +821 -0
  233. package/dist/schema-C6DW4ZHR.js.map +1 -0
  234. package/dist/schema-CRhEY1SO.js +69 -0
  235. package/dist/schema-CRhEY1SO.js.map +1 -0
  236. package/dist/schema-Cef2cFmb.d.ts +408 -0
  237. package/dist/schema-Cef2cFmb.d.ts.map +1 -0
  238. package/dist/semantic-concept-judge-B6cWNJ2K.js +725 -0
  239. package/dist/semantic-concept-judge-B6cWNJ2K.js.map +1 -0
  240. package/dist/sequential-Br0mAPHA.js +148 -0
  241. package/dist/sequential-Br0mAPHA.js.map +1 -0
  242. package/dist/sequential-CYwq6Ff_.d.ts +141 -0
  243. package/dist/sequential-CYwq6Ff_.d.ts.map +1 -0
  244. package/dist/series-convergence-CjO2QdRW.js +43 -0
  245. package/dist/series-convergence-CjO2QdRW.js.map +1 -0
  246. package/dist/series-convergence-ofsqPWhs.d.ts +35 -0
  247. package/dist/series-convergence-ofsqPWhs.d.ts.map +1 -0
  248. package/dist/server-m5D9cvnG.js +1040 -0
  249. package/dist/server-m5D9cvnG.js.map +1 -0
  250. package/dist/skill-usage-C_pXm7lP.d.ts +534 -0
  251. package/dist/skill-usage-C_pXm7lP.d.ts.map +1 -0
  252. package/dist/skillopt-optimization-method-CUmHkGbI.js +7718 -0
  253. package/dist/skillopt-optimization-method-CUmHkGbI.js.map +1 -0
  254. package/dist/skillopt-optimization-method-CWKVTnks.d.ts +1740 -0
  255. package/dist/skillopt-optimization-method-CWKVTnks.d.ts.map +1 -0
  256. package/dist/statistics-Cmj6nynr.d.ts +514 -0
  257. package/dist/statistics-Cmj6nynr.d.ts.map +1 -0
  258. package/dist/statistics-CnnxdpOg.js +1437 -0
  259. package/dist/statistics-CnnxdpOg.js.map +1 -0
  260. package/dist/store-CT9YIIve.d.ts +117 -0
  261. package/dist/store-CT9YIIve.d.ts.map +1 -0
  262. package/dist/store-CxJry_cs.d.ts +229 -0
  263. package/dist/store-CxJry_cs.d.ts.map +1 -0
  264. package/dist/storyboard/index.d.ts +84 -203
  265. package/dist/storyboard/index.d.ts.map +1 -0
  266. package/dist/storyboard/index.js +609 -542
  267. package/dist/storyboard/index.js.map +1 -1
  268. package/dist/summary-report-BNs5nmXI.js +862 -0
  269. package/dist/summary-report-BNs5nmXI.js.map +1 -0
  270. package/dist/summary-report-Cj9gdw4i.d.ts +407 -0
  271. package/dist/summary-report-Cj9gdw4i.d.ts.map +1 -0
  272. package/dist/supervisor-run/index.d.ts +2 -959
  273. package/dist/supervisor-run/index.js +2 -65
  274. package/dist/supervisor-run-_lnTLM3z.js +1679 -0
  275. package/dist/supervisor-run-_lnTLM3z.js.map +1 -0
  276. package/dist/task-failure-attributes-CQZlB3et.js +311 -0
  277. package/dist/task-failure-attributes-CQZlB3et.js.map +1 -0
  278. package/dist/test-graded-scenario-BsqWLmPt.js +318 -0
  279. package/dist/test-graded-scenario-BsqWLmPt.js.map +1 -0
  280. package/dist/test-graded-scenario-D1TaI2va.d.ts +141 -0
  281. package/dist/test-graded-scenario-D1TaI2va.d.ts.map +1 -0
  282. package/dist/tools-BmuN627J.js +1085 -0
  283. package/dist/tools-BmuN627J.js.map +1 -0
  284. package/dist/trace-attributes.d.ts +2 -52
  285. package/dist/trace-attributes.js +131 -61
  286. package/dist/trace-attributes.js.map +1 -1
  287. package/dist/traces.d.ts +12 -2365
  288. package/dist/traces.js +12 -252
  289. package/dist/trajectory-D_7rLrvE.js +56 -0
  290. package/dist/trajectory-D_7rLrvE.js.map +1 -0
  291. package/dist/types-DGsxbAEd.d.ts +387 -0
  292. package/dist/types-DGsxbAEd.d.ts.map +1 -0
  293. package/dist/types-k9tZGKUg.d.ts +640 -0
  294. package/dist/types-k9tZGKUg.d.ts.map +1 -0
  295. package/dist/verdict-Dps8_okt.d.ts +37 -0
  296. package/dist/verdict-Dps8_okt.d.ts.map +1 -0
  297. package/dist/wire/index.d.ts +702 -1173
  298. package/dist/wire/index.d.ts.map +1 -0
  299. package/dist/wire/index.js +2 -81
  300. package/docs/campaign-proposers.md +1 -0
  301. package/package.json +17 -9
  302. package/dist/benchmarks/index.js.map +0 -1
  303. package/dist/campaign/index.js.map +0 -1
  304. package/dist/chunk-2QU3YOPR.js +0 -7374
  305. package/dist/chunk-2QU3YOPR.js.map +0 -1
  306. package/dist/chunk-3OCR4R5I.js +0 -728
  307. package/dist/chunk-3OCR4R5I.js.map +0 -1
  308. package/dist/chunk-3RF76KTD.js +0 -84
  309. package/dist/chunk-3RF76KTD.js.map +0 -1
  310. package/dist/chunk-56TAVBOK.js +0 -698
  311. package/dist/chunk-5DTSBUL2.js +0 -159
  312. package/dist/chunk-5DTSBUL2.js.map +0 -1
  313. package/dist/chunk-7FO3TNPI.js +0 -232
  314. package/dist/chunk-7FO3TNPI.js.map +0 -1
  315. package/dist/chunk-7ZZMD7UK.js +0 -386
  316. package/dist/chunk-7ZZMD7UK.js.map +0 -1
  317. package/dist/chunk-BOD4O7OF.js +0 -40
  318. package/dist/chunk-BOD4O7OF.js.map +0 -1
  319. package/dist/chunk-BSO5JDQH.js +0 -2335
  320. package/dist/chunk-BSO5JDQH.js.map +0 -1
  321. package/dist/chunk-C6LXANRU.js +0 -1550
  322. package/dist/chunk-C6LXANRU.js.map +0 -1
  323. package/dist/chunk-DODXQREJ.js +0 -752
  324. package/dist/chunk-DODXQREJ.js.map +0 -1
  325. package/dist/chunk-DRYIUNWY.js +0 -622
  326. package/dist/chunk-DRYIUNWY.js.map +0 -1
  327. package/dist/chunk-E7QXT7SX.js +0 -183
  328. package/dist/chunk-E7QXT7SX.js.map +0 -1
  329. package/dist/chunk-EG66UGL4.js +0 -341
  330. package/dist/chunk-EG66UGL4.js.map +0 -1
  331. package/dist/chunk-FXTVJPYD.js +0 -576
  332. package/dist/chunk-FXTVJPYD.js.map +0 -1
  333. package/dist/chunk-G7MGMCZD.js +0 -153
  334. package/dist/chunk-G7MGMCZD.js.map +0 -1
  335. package/dist/chunk-GGE4NNQT.js +0 -65
  336. package/dist/chunk-GGE4NNQT.js.map +0 -1
  337. package/dist/chunk-H23X7XKK.js +0 -181
  338. package/dist/chunk-H23X7XKK.js.map +0 -1
  339. package/dist/chunk-HHWE3POT.js +0 -94
  340. package/dist/chunk-HHWE3POT.js.map +0 -1
  341. package/dist/chunk-HPWUNB47.js +0 -289
  342. package/dist/chunk-HPWUNB47.js.map +0 -1
  343. package/dist/chunk-IYCLP2N2.js +0 -766
  344. package/dist/chunk-IYCLP2N2.js.map +0 -1
  345. package/dist/chunk-JHCHEVET.js +0 -274
  346. package/dist/chunk-JHCHEVET.js.map +0 -1
  347. package/dist/chunk-JQSF5DQT.js +0 -701
  348. package/dist/chunk-JQSF5DQT.js.map +0 -1
  349. package/dist/chunk-K4DBDHLK.js +0 -158
  350. package/dist/chunk-K4DBDHLK.js.map +0 -1
  351. package/dist/chunk-K6N6XJJX.js +0 -306
  352. package/dist/chunk-K6N6XJJX.js.map +0 -1
  353. package/dist/chunk-M4YBQKIJ.js +0 -1040
  354. package/dist/chunk-M4YBQKIJ.js.map +0 -1
  355. package/dist/chunk-MA6HLL3S.js +0 -65
  356. package/dist/chunk-MA6HLL3S.js.map +0 -1
  357. package/dist/chunk-MAZ26DC7.js +0 -99
  358. package/dist/chunk-MAZ26DC7.js.map +0 -1
  359. package/dist/chunk-NPCTHQIO.js +0 -91
  360. package/dist/chunk-NPCTHQIO.js.map +0 -1
  361. package/dist/chunk-NY44NC4A.js +0 -1056
  362. package/dist/chunk-NY44NC4A.js.map +0 -1
  363. package/dist/chunk-OIUOT4QD.js +0 -44
  364. package/dist/chunk-OIUOT4QD.js.map +0 -1
  365. package/dist/chunk-ONWEPEDO.js +0 -57
  366. package/dist/chunk-ONWEPEDO.js.map +0 -1
  367. package/dist/chunk-OWN5NPMC.js +0 -152
  368. package/dist/chunk-OWN5NPMC.js.map +0 -1
  369. package/dist/chunk-P6FYH6K4.js +0 -1161
  370. package/dist/chunk-P6FYH6K4.js.map +0 -1
  371. package/dist/chunk-PC4UYEBM.js +0 -166
  372. package/dist/chunk-PC4UYEBM.js.map +0 -1
  373. package/dist/chunk-PC5DOSM7.js +0 -579
  374. package/dist/chunk-PC5DOSM7.js.map +0 -1
  375. package/dist/chunk-PXE2VKMX.js +0 -140
  376. package/dist/chunk-PXE2VKMX.js.map +0 -1
  377. package/dist/chunk-PZ5AY32C.js +0 -10
  378. package/dist/chunk-PZ5AY32C.js.map +0 -1
  379. package/dist/chunk-QB6BDBP2.js +0 -4464
  380. package/dist/chunk-QB6BDBP2.js.map +0 -1
  381. package/dist/chunk-RXHCETDZ.js +0 -536
  382. package/dist/chunk-RXHCETDZ.js.map +0 -1
  383. package/dist/chunk-RZTMDUO7.js +0 -49
  384. package/dist/chunk-RZTMDUO7.js.map +0 -1
  385. package/dist/chunk-SFLLL76A.js +0 -669
  386. package/dist/chunk-SFLLL76A.js.map +0 -1
  387. package/dist/chunk-SZLVEKMJ.js +0 -1446
  388. package/dist/chunk-SZLVEKMJ.js.map +0 -1
  389. package/dist/chunk-T4SQEITX.js +0 -95
  390. package/dist/chunk-T4SQEITX.js.map +0 -1
  391. package/dist/chunk-T6RLYGAD.js +0 -158
  392. package/dist/chunk-T6RLYGAD.js.map +0 -1
  393. package/dist/chunk-TJVT4QFF.js +0 -911
  394. package/dist/chunk-TJVT4QFF.js.map +0 -1
  395. package/dist/chunk-TQ7LNKZ3.js +0 -136
  396. package/dist/chunk-TQ7LNKZ3.js.map +0 -1
  397. package/dist/chunk-U4L7JRPZ.js +0 -1706
  398. package/dist/chunk-U4L7JRPZ.js.map +0 -1
  399. package/dist/chunk-U4PHLT2N.js +0 -419
  400. package/dist/chunk-U4PHLT2N.js.map +0 -1
  401. package/dist/chunk-VCZ5FQYW.js +0 -928
  402. package/dist/chunk-VCZ5FQYW.js.map +0 -1
  403. package/dist/chunk-VI2UW6B6.js +0 -162
  404. package/dist/chunk-VI2UW6B6.js.map +0 -1
  405. package/dist/chunk-VQMK5FMP.js +0 -247
  406. package/dist/chunk-VQMK5FMP.js.map +0 -1
  407. package/dist/chunk-WGXIEX7P.js +0 -116
  408. package/dist/chunk-WGXIEX7P.js.map +0 -1
  409. package/dist/chunk-WVATSFCP.js +0 -1553
  410. package/dist/chunk-WVATSFCP.js.map +0 -1
  411. package/dist/chunk-X4YIBDER.js +0 -1662
  412. package/dist/chunk-X4YIBDER.js.map +0 -1
  413. package/dist/chunk-YQN4ICPP.js +0 -355
  414. package/dist/chunk-YQN4ICPP.js.map +0 -1
  415. package/dist/chunk-ZET2UAYW.js +0 -89
  416. package/dist/chunk-ZET2UAYW.js.map +0 -1
  417. package/dist/chunk-ZHTZ4EYI.js +0 -1212
  418. package/dist/chunk-ZHTZ4EYI.js.map +0 -1
  419. package/dist/control.js.map +0 -1
  420. package/dist/hosted/index.js.map +0 -1
  421. package/dist/matrix/index.js.map +0 -1
  422. package/dist/reporting.js.map +0 -1
  423. package/dist/rollout/index.js.map +0 -1
  424. package/dist/run-campaign-OJJ7CZF4.js +0 -18
  425. package/dist/run-campaign-OJJ7CZF4.js.map +0 -1
  426. package/dist/supervisor-run/index.js.map +0 -1
  427. package/dist/traces.js.map +0 -1
  428. package/dist/wire/index.js.map +0 -1
@@ -1,1161 +0,0 @@
1
- import {
2
- NotFoundError
3
- } from "./chunk-ONWEPEDO.js";
4
- import {
5
- INPUT_VALUE,
6
- LLM_MODEL_ATTR_KEYS,
7
- OUTPUT_VALUE,
8
- SPAN_KIND_ATTR_KEYS,
9
- TOOL_ARGS_CAPTURED,
10
- TOOL_LATENCY_MS,
11
- TOOL_NAME,
12
- TOOL_NAME_ATTR_KEYS
13
- } from "./chunk-K4DBDHLK.js";
14
-
15
- // src/trace/otlp-attributes.ts
16
- var TOOL_SPAN_ATTRIBUTE_KEYS = [
17
- TOOL_NAME,
18
- TOOL_ARGS_CAPTURED,
19
- TOOL_LATENCY_MS,
20
- INPUT_VALUE,
21
- OUTPUT_VALUE
22
- ];
23
- var EXPLICIT_SPAN_ROLES = /* @__PURE__ */ new Set([
24
- "AGENT",
25
- "CHAIN",
26
- "EVALUATOR",
27
- "GUARDRAIL",
28
- "LLM",
29
- "SPAN",
30
- "TOOL"
31
- ]);
32
- function classifyOtlpSpanRole(input) {
33
- const explicitKind = input.kind ?? firstStringAttribute(input.attributes, SPAN_KIND_ATTR_KEYS);
34
- if (explicitKind) {
35
- const normalized = explicitKind.toUpperCase();
36
- if (EXPLICIT_SPAN_ROLES.has(normalized)) return normalized;
37
- }
38
- if (firstStringAttribute(input.attributes, TOOL_NAME_ATTR_KEYS) !== void 0 || /^(?:function|tool)[.:/]/i.test(input.name)) {
39
- return "TOOL";
40
- }
41
- const spanType = input.attributes["span.type"];
42
- if (typeof spanType === "string" && spanType.toLowerCase() === "llm_request" || /(?:^|[.:/_-])(?:chat[._-]?completions?|llm)(?:$|[.:/_-])/i.test(input.name) || firstStringAttribute(input.attributes, LLM_MODEL_ATTR_KEYS) !== void 0 || typeof input.attributes["gen_ai.operation.name"] === "string") {
43
- return "LLM";
44
- }
45
- return "UNKNOWN";
46
- }
47
- function isOtlpModelCall(input) {
48
- return classifyOtlpSpanRole(input) === "LLM";
49
- }
50
- function toolSpanOtlpAttributes(span) {
51
- const argsCaptured = span.argsCaptured !== false;
52
- const attributes = {
53
- [TOOL_NAME]: span.toolName,
54
- [TOOL_ARGS_CAPTURED]: argsCaptured
55
- };
56
- if (span.latencyMs !== void 0) attributes[TOOL_LATENCY_MS] = span.latencyMs;
57
- if (argsCaptured) attributes[INPUT_VALUE] = stringifyTraceValue(span.args);
58
- if (span.result !== void 0) attributes[OUTPUT_VALUE] = stringifyTraceValue(span.result);
59
- return attributes;
60
- }
61
- function applyToolSpanOtlpAttributes(attributes, span) {
62
- for (const key of TOOL_SPAN_ATTRIBUTE_KEYS) delete attributes[key];
63
- Object.assign(attributes, toolSpanOtlpAttributes(span));
64
- }
65
- function traceSpanKindToOpenInferenceKind(kind) {
66
- switch (kind) {
67
- case "llm":
68
- return "LLM";
69
- case "tool":
70
- return "TOOL";
71
- case "retrieval":
72
- return "CHAIN";
73
- case "judge":
74
- return "EVALUATOR";
75
- case "sandbox":
76
- return "CHAIN";
77
- case "agent":
78
- return "AGENT";
79
- default:
80
- return "SPAN";
81
- }
82
- }
83
- function firstStringAttribute(attributes, keys) {
84
- for (const key of keys) {
85
- const value = attributes[key];
86
- if (typeof value === "string" && value.length > 0) return value;
87
- }
88
- return void 0;
89
- }
90
- function stringifyTraceValue(value) {
91
- if (value === void 0) return "null";
92
- if (typeof value === "string") return value;
93
- try {
94
- return JSON.stringify(value) ?? String(value);
95
- } catch {
96
- return String(value);
97
- }
98
- }
99
-
100
- // src/trace-analyst/otlp-span.ts
101
- function projectOtlpFlatLine(raw) {
102
- const trace_id = stringField(raw, "trace_id") ?? stringField(raw, "traceId");
103
- const span_id = stringField(raw, "span_id") ?? stringField(raw, "spanId");
104
- if (!trace_id || !span_id) return null;
105
- const rawParentId = stringField(raw, "parent_span_id") ?? stringField(raw, "parentSpanId") ?? null;
106
- const parent_id = normalizeParentSpanId(trace_id, span_id, rawParentId);
107
- const name = stringField(raw, "name") ?? "unknown";
108
- const start_time = stringField(raw, "start_time") ?? stringField(raw, "startTime") ?? "";
109
- const end_time = stringField(raw, "end_time") ?? stringField(raw, "endTime") ?? start_time;
110
- const status = readOtlpStatus(raw);
111
- const attributes = extractOtlpAttributes(raw);
112
- const service_name = asString(attributes["service.name"]) ?? asString(attributes["resource.attributes.service.name"]) ?? null;
113
- const agent_name = asString(attributes["agent.name"]) ?? asString(attributes["inference.agent.name"]) ?? asString(attributes["inference.agent_name"]) ?? null;
114
- const model_name = firstStringAttr(attributes, LLM_MODEL_ATTR_KEYS);
115
- const tool_name = firstStringAttr(attributes, TOOL_NAME_ATTR_KEYS);
116
- const kind = inferOtlpKind(attributes);
117
- let duration_ms = 0;
118
- if (start_time && end_time) {
119
- const a = spanEpochMillis(start_time);
120
- const b = spanEpochMillis(end_time);
121
- if (a !== null && b !== null) duration_ms = Math.max(0, b - a);
122
- }
123
- return {
124
- trace_id,
125
- span_id,
126
- parent_span_id: parent_id && parent_id.length > 0 ? parent_id : null,
127
- name,
128
- kind,
129
- start_time,
130
- end_time,
131
- duration_ms,
132
- status: status.code,
133
- status_message: status.message,
134
- service_name,
135
- agent_name,
136
- model_name,
137
- tool_name,
138
- attributes
139
- };
140
- }
141
- function normalizeParentSpanId(traceId, spanId, parentId) {
142
- if (!parentId) return null;
143
- const prefix = `${traceId}:`;
144
- return spanId.startsWith(prefix) && !parentId.startsWith(prefix) ? `${prefix}${parentId}` : parentId;
145
- }
146
- function readOtlpStatus(raw) {
147
- const status = raw.status;
148
- if (status && typeof status === "object" && !Array.isArray(status)) {
149
- const codeRaw = status.code;
150
- const code = codeRaw === "STATUS_CODE_OK" || codeRaw === "OK" ? "OK" : codeRaw === "STATUS_CODE_ERROR" || codeRaw === "ERROR" ? "ERROR" : "UNSET";
151
- const messageRaw = status.message;
152
- const message = typeof messageRaw === "string" && messageRaw.length > 0 ? messageRaw : void 0;
153
- return { code, message };
154
- }
155
- return { code: "UNSET", message: void 0 };
156
- }
157
- function inferOtlpKind(attrs) {
158
- const opik = firstStringAttr(attrs, SPAN_KIND_ATTR_KEYS);
159
- if (opik) {
160
- const upper = opik.toUpperCase();
161
- if (upper === "AGENT" || upper === "LLM" || upper === "TOOL" || upper === "CHAIN" || upper === "EVALUATOR" || upper === "GUARDRAIL" || upper === "SPAN") {
162
- return upper;
163
- }
164
- }
165
- return "UNKNOWN";
166
- }
167
- function extractOtlpAttributes(raw) {
168
- const out = {};
169
- const resource = raw.resource;
170
- if (resource && typeof resource === "object" && !Array.isArray(resource)) {
171
- const ra = resource.attributes;
172
- if (ra && typeof ra === "object" && !Array.isArray(ra)) {
173
- for (const [k, v] of Object.entries(ra)) {
174
- out[k] = v;
175
- }
176
- }
177
- }
178
- const spanAttrs = raw.attributes;
179
- if (spanAttrs && typeof spanAttrs === "object" && !Array.isArray(spanAttrs)) {
180
- for (const [k, v] of Object.entries(spanAttrs)) {
181
- out[k] = v;
182
- }
183
- }
184
- return out;
185
- }
186
- function stringField(raw, key) {
187
- const v = raw[key];
188
- return typeof v === "string" ? v : void 0;
189
- }
190
- function asString(v) {
191
- return typeof v === "string" && v.length > 0 ? v : null;
192
- }
193
- function firstStringAttr(attrs, keys) {
194
- for (const k of keys) {
195
- const s = asString(attrs[k]);
196
- if (s !== null) return s;
197
- }
198
- return null;
199
- }
200
- function spanEpochMillis(ts) {
201
- if (!ts) return null;
202
- if (/^\d+$/.test(ts)) return Number(ts);
203
- const n = Date.parse(ts);
204
- return Number.isNaN(n) ? null : n;
205
- }
206
- function compareSpanTime(a, b) {
207
- return (spanEpochMillis(a) ?? 0) - (spanEpochMillis(b) ?? 0);
208
- }
209
-
210
- // src/trace-analyst/types.ts
211
- var DEFAULT_TRACE_ANALYST_BUDGETS = {
212
- perCallByteCeiling: 15e4,
213
- perAttributeViewBudget: 4096,
214
- perAttributeSpanBudget: 16384,
215
- perMatchTextBudget: 1024
216
- };
217
- var TRACE_ANALYST_TRUNCATION_MARKER_PREFIX = "[trace-analyst truncated:";
218
-
219
- // src/trace-analyst/store-otlp.ts
220
- import { readFile, stat } from "fs/promises";
221
-
222
- // src/trace-analyst/store.ts
223
- function compileSearchRegex(pattern) {
224
- let source = pattern;
225
- let flags = "m";
226
- if (source.startsWith("(?i)")) {
227
- source = source.slice(4);
228
- flags += "i";
229
- }
230
- return new RegExp(source, flags);
231
- }
232
- function truncateForBudget(value, byteCap) {
233
- const original = Buffer.byteLength(value, "utf8");
234
- if (original <= byteCap) return value;
235
- const ratio = byteCap / original;
236
- let cut = Math.max(0, Math.floor(value.length * ratio));
237
- while (cut > 0 && Buffer.byteLength(value.slice(0, cut), "utf8") > byteCap) {
238
- cut -= 1;
239
- }
240
- return `${value.slice(0, cut)}
241
- [trace-analyst truncated: original ${original} bytes]`;
242
- }
243
-
244
- // src/trace-analyst/store-otlp.ts
245
- var INDEX_YIELD_LINES = 5e3;
246
- function yieldToEventLoop() {
247
- return new Promise((resolve) => setImmediate(resolve));
248
- }
249
- var DEFAULT_MAX_TRACE_FILE_BYTES = 256 * 1024 * 1024;
250
- var OtlpFileTraceStore = class {
251
- path;
252
- perAttributeViewBudget;
253
- perAttributeSpanBudget;
254
- perCallByteCeiling;
255
- perMatchTextBudget;
256
- maxFileBytes;
257
- indexPromise;
258
- /** Cached UTF-8 buffer of the file. We pin it once because every
259
- * read needs slice access and re-reading on each call balloons the
260
- * syscall count. */
261
- bufferPromise;
262
- constructor(opts) {
263
- this.path = opts.path;
264
- this.perAttributeViewBudget = opts.perAttributeViewBudget ?? DEFAULT_TRACE_ANALYST_BUDGETS.perAttributeViewBudget;
265
- this.perAttributeSpanBudget = opts.perAttributeSpanBudget ?? DEFAULT_TRACE_ANALYST_BUDGETS.perAttributeSpanBudget;
266
- this.perCallByteCeiling = opts.perCallByteCeiling ?? DEFAULT_TRACE_ANALYST_BUDGETS.perCallByteCeiling;
267
- this.perMatchTextBudget = opts.perMatchTextBudget ?? DEFAULT_TRACE_ANALYST_BUDGETS.perMatchTextBudget;
268
- this.maxFileBytes = opts.maxFileBytes ?? DEFAULT_MAX_TRACE_FILE_BYTES;
269
- }
270
- // ─── Public API ────────────────────────────────────────────────────
271
- async getOverview(filters) {
272
- const idx = await this.index();
273
- const matched = await this.matchedTraces(idx, filters);
274
- const services = /* @__PURE__ */ new Set();
275
- const agents = /* @__PURE__ */ new Set();
276
- const models = /* @__PURE__ */ new Set();
277
- const tools = /* @__PURE__ */ new Set();
278
- let rawBytes = 0;
279
- let earliest = null;
280
- let latest = null;
281
- let errorTraceCount = 0;
282
- let errorSpanCount = 0;
283
- const clusters = /* @__PURE__ */ new Map();
284
- for (const t of matched) {
285
- if (t.service_name) services.add(t.service_name);
286
- if (t.agent_name) agents.add(t.agent_name);
287
- for (const m of t.models) models.add(m);
288
- for (const tn of t.tools) tools.add(tn);
289
- rawBytes += t.raw_jsonl_bytes;
290
- if (!earliest || compareSpanTime(t.start_time, earliest) < 0) earliest = t.start_time;
291
- if (!latest || compareSpanTime(t.end_time, latest) > 0) latest = t.end_time;
292
- if (t.has_errors) {
293
- errorTraceCount += 1;
294
- for (const s of t.spans) {
295
- if (s.status !== "ERROR") continue;
296
- errorSpanCount += 1;
297
- accumulateErrorCluster(clusters, t.trace_id, s);
298
- }
299
- }
300
- }
301
- const sample_trace_ids = matched.slice(0, 20).map((t) => t.trace_id);
302
- return {
303
- total_traces: matched.length,
304
- raw_jsonl_bytes: rawBytes,
305
- services: [...services].sort(),
306
- agents: [...agents].sort(),
307
- models: [...models].sort(),
308
- tool_names: [...tools].sort(),
309
- sample_trace_ids,
310
- errors: { trace_count: errorTraceCount, span_count: errorSpanCount },
311
- error_clusters: finalizeErrorClusters(clusters, errorTraceCount),
312
- time_range: earliest && latest ? { earliest, latest } : null
313
- };
314
- }
315
- async queryTraces(opts) {
316
- if (!Number.isInteger(opts.limit) || opts.limit < 1 || opts.limit > 200) {
317
- throw new RangeError(`queryTraces.limit must be 1..200, got ${opts.limit}`);
318
- }
319
- const offset = opts.offset ?? 0;
320
- if (!Number.isInteger(offset) || offset < 0) {
321
- throw new RangeError(`queryTraces.offset must be >=0, got ${offset}`);
322
- }
323
- const idx = await this.index();
324
- const matched = await this.matchedTraces(idx, opts.filters);
325
- const slice = matched.slice(offset, offset + opts.limit);
326
- return {
327
- traces: slice.map((t) => this.toSummary(t)),
328
- total: matched.length,
329
- has_more: offset + slice.length < matched.length
330
- };
331
- }
332
- async countTraces(filters) {
333
- const idx = await this.index();
334
- const matched = await this.matchedTraces(idx, filters);
335
- return matched.length;
336
- }
337
- async viewTrace(opts) {
338
- const idx = await this.index();
339
- const trace = idx.byTrace.get(opts.trace_id);
340
- if (!trace) {
341
- throw new TraceNotFoundError(opts.trace_id);
342
- }
343
- const cap = opts.per_attribute_byte_cap ?? this.perAttributeViewBudget;
344
- const buf = await this.buffer();
345
- const spans = [];
346
- let runningBytes = 0;
347
- let span_response_bytes_max = 0;
348
- const counter = { value: 0 };
349
- for (const s of trace.spans) {
350
- const projected = this.projectSpan(buf, trace.trace_id, s, cap, counter);
351
- const bytes = Buffer.byteLength(JSON.stringify(projected), "utf8");
352
- span_response_bytes_max = Math.max(span_response_bytes_max, bytes);
353
- runningBytes += bytes;
354
- if (runningBytes > this.perCallByteCeiling) {
355
- return {
356
- trace_id: trace.trace_id,
357
- oversized: this.buildOversizedSummary(trace, span_response_bytes_max)
358
- };
359
- }
360
- spans.push(projected);
361
- }
362
- return { trace_id: trace.trace_id, spans };
363
- }
364
- async viewSpans(opts) {
365
- const idx = await this.index();
366
- const trace = idx.byTrace.get(opts.trace_id);
367
- if (!trace) throw new TraceNotFoundError(opts.trace_id);
368
- if (opts.span_ids.length === 0) {
369
- return {
370
- trace_id: trace.trace_id,
371
- spans: [],
372
- missing_span_ids: [],
373
- truncated_attribute_count: 0
374
- };
375
- }
376
- if (opts.span_ids.length > 100) {
377
- throw new RangeError(`viewSpans.span_ids cap is 100, got ${opts.span_ids.length}`);
378
- }
379
- const cap = opts.per_attribute_byte_cap ?? this.perAttributeSpanBudget;
380
- const wantSet = new Set(opts.span_ids);
381
- const found = trace.spans.filter((s) => wantSet.has(s.span_id));
382
- const missing = opts.span_ids.filter((id) => !found.some((f2) => f2.span_id === id));
383
- const buf = await this.buffer();
384
- const spans = [];
385
- const counter = { value: 0 };
386
- let runningBytes = 0;
387
- for (const s of found) {
388
- const projected = this.projectSpan(buf, trace.trace_id, s, cap, counter);
389
- const bytes = Buffer.byteLength(JSON.stringify(projected), "utf8");
390
- runningBytes += bytes;
391
- if (runningBytes > this.perCallByteCeiling) {
392
- break;
393
- }
394
- spans.push(projected);
395
- }
396
- return {
397
- trace_id: trace.trace_id,
398
- spans,
399
- missing_span_ids: missing,
400
- truncated_attribute_count: counter.value
401
- };
402
- }
403
- async searchTrace(opts) {
404
- const max_matches = opts.max_matches ?? 50;
405
- if (!Number.isInteger(max_matches) || max_matches < 1 || max_matches > 500) {
406
- throw new RangeError(`searchTrace.max_matches must be 1..500, got ${max_matches}`);
407
- }
408
- const idx = await this.index();
409
- const trace = idx.byTrace.get(opts.trace_id);
410
- if (!trace) throw new TraceNotFoundError(opts.trace_id);
411
- const re = compileSearchRegex(opts.regex_pattern);
412
- const buf = await this.buffer();
413
- const hits = [];
414
- let total = 0;
415
- let capped = false;
416
- for (const s of trace.spans) {
417
- const remaining = max_matches - hits.length;
418
- const localHits = await this.scanSpanForMatches(
419
- buf,
420
- trace.trace_id,
421
- s,
422
- re,
423
- this.perMatchTextBudget,
424
- remaining
425
- );
426
- total += localHits.total;
427
- for (const h of localHits.records) {
428
- if (hits.length >= max_matches) break;
429
- hits.push(h);
430
- }
431
- if (hits.length >= max_matches) {
432
- capped = true;
433
- break;
434
- }
435
- }
436
- return {
437
- trace_id: trace.trace_id,
438
- hits,
439
- // Uncapped: every span scanned to completion, so `total` is exact.
440
- total_matches: capped ? hits.length : total,
441
- has_more: capped || total > hits.length
442
- };
443
- }
444
- async searchSpan(opts) {
445
- const max_matches = opts.max_matches ?? 50;
446
- if (!Number.isInteger(max_matches) || max_matches < 1 || max_matches > 500) {
447
- throw new RangeError(`searchSpan.max_matches must be 1..500, got ${max_matches}`);
448
- }
449
- const idx = await this.index();
450
- const trace = idx.byTrace.get(opts.trace_id);
451
- if (!trace) throw new TraceNotFoundError(opts.trace_id);
452
- const span = trace.spans.find((s) => s.span_id === opts.span_id);
453
- if (!span) {
454
- throw new SpanNotFoundError(opts.trace_id, opts.span_id);
455
- }
456
- const re = compileSearchRegex(opts.regex_pattern);
457
- const buf = await this.buffer();
458
- const localHits = await this.scanSpanForMatches(
459
- buf,
460
- trace.trace_id,
461
- span,
462
- re,
463
- this.perMatchTextBudget,
464
- max_matches
465
- );
466
- return {
467
- trace_id: trace.trace_id,
468
- span_id: span.span_id,
469
- hits: localHits.records,
470
- total_matches: localHits.total,
471
- has_more: localHits.total > localHits.records.length
472
- };
473
- }
474
- // ─── Index building ────────────────────────────────────────────────
475
- /** Force the index to materialise. Useful to amortise startup cost
476
- * before the first agent call. */
477
- async ensureIndexed() {
478
- await this.index();
479
- }
480
- async buffer() {
481
- if (!this.bufferPromise) {
482
- this.bufferPromise = this.readGuarded();
483
- }
484
- return this.bufferPromise;
485
- }
486
- /** Stat-then-read so an oversized file fails loud BEFORE we allocate a
487
- * multi-hundred-MB Buffer and OOM the process. A missing file surfaces
488
- * as TraceFileMissingError; any other stat/read error propagates. */
489
- async readGuarded() {
490
- let stats;
491
- try {
492
- stats = await stat(this.path);
493
- } catch (err) {
494
- if (err?.code === "ENOENT") {
495
- throw new TraceFileMissingError(this.path);
496
- }
497
- throw err;
498
- }
499
- if (stats.size > this.maxFileBytes) {
500
- throw new TraceFileTooLargeError(this.path, stats.size, this.maxFileBytes);
501
- }
502
- return readFile(this.path);
503
- }
504
- async index() {
505
- if (!this.indexPromise) {
506
- this.indexPromise = this.buildIndex();
507
- }
508
- return this.indexPromise;
509
- }
510
- async buildIndex() {
511
- const buf = await this.buffer();
512
- const byTrace = /* @__PURE__ */ new Map();
513
- let cursor = 0;
514
- let sinceYield = 0;
515
- while (cursor < buf.length) {
516
- if (++sinceYield >= INDEX_YIELD_LINES) {
517
- sinceYield = 0;
518
- await yieldToEventLoop();
519
- }
520
- const newlineIndex = buf.indexOf(10, cursor);
521
- const lineEnd = newlineIndex === -1 ? buf.length : newlineIndex;
522
- const lineLength = lineEnd - cursor;
523
- if (lineLength === 0) {
524
- cursor = lineEnd + 1;
525
- continue;
526
- }
527
- const lineSlice = buf.subarray(cursor, lineEnd).toString("utf8");
528
- const lineOffset = cursor;
529
- cursor = lineEnd + 1;
530
- let parsed;
531
- try {
532
- parsed = JSON.parse(lineSlice);
533
- } catch {
534
- continue;
535
- }
536
- if (!parsed || typeof parsed !== "object") continue;
537
- const span = projectOtlpFlatLine(parsed);
538
- if (!span) continue;
539
- let entry = byTrace.get(span.trace_id);
540
- if (!entry) {
541
- entry = {
542
- trace_id: span.trace_id,
543
- service_name: span.service_name,
544
- agent_name: span.agent_name,
545
- span_count: 0,
546
- has_errors: false,
547
- start_time: span.start_time,
548
- end_time: span.end_time,
549
- duration_ms: 0,
550
- raw_jsonl_bytes: 0,
551
- models: /* @__PURE__ */ new Set(),
552
- tools: /* @__PURE__ */ new Set(),
553
- spans: []
554
- };
555
- byTrace.set(span.trace_id, entry);
556
- } else {
557
- if (!entry.service_name && span.service_name) entry.service_name = span.service_name;
558
- if (!entry.agent_name && span.agent_name) entry.agent_name = span.agent_name;
559
- }
560
- const indexEntry = {
561
- span_id: span.span_id,
562
- parent_span_id: span.parent_span_id,
563
- name: span.name,
564
- kind: span.kind,
565
- start_time: span.start_time,
566
- end_time: span.end_time,
567
- duration_ms: span.duration_ms,
568
- status: span.status,
569
- status_message: span.status_message,
570
- service_name: span.service_name,
571
- agent_name: span.agent_name,
572
- model_name: span.model_name,
573
- tool_name: span.tool_name,
574
- line_byte_offset: lineOffset,
575
- line_byte_length: lineLength
576
- };
577
- entry.spans.push(indexEntry);
578
- entry.span_count += 1;
579
- entry.raw_jsonl_bytes += lineLength + 1;
580
- if (span.status === "ERROR") entry.has_errors = true;
581
- if (compareSpanTime(span.start_time, entry.start_time) < 0) entry.start_time = span.start_time;
582
- if (compareSpanTime(span.end_time, entry.end_time) > 0) entry.end_time = span.end_time;
583
- if (span.model_name) entry.models.add(span.model_name);
584
- if (span.tool_name) entry.tools.add(span.tool_name);
585
- }
586
- let totalRawBytes = 0;
587
- for (const t of byTrace.values()) {
588
- totalRawBytes += t.raw_jsonl_bytes;
589
- t.spans.sort(
590
- (a, b) => compareSpanTime(a.start_time, b.start_time) || a.line_byte_offset - b.line_byte_offset
591
- );
592
- const startMs = spanEpochMillis(t.start_time);
593
- const endMs = spanEpochMillis(t.end_time);
594
- t.duration_ms = startMs === null || endMs === null ? 0 : Math.max(0, endMs - startMs);
595
- }
596
- const sortedTraceIds = [...byTrace.keys()].sort();
597
- return { byTrace, totalRawBytes, sortedTraceIds };
598
- }
599
- // ─── Filter pipeline ───────────────────────────────────────────────
600
- async matchedTraces(idx, filters) {
601
- const traces = idx.sortedTraceIds.map((id) => idx.byTrace.get(id)).filter(isPresent);
602
- if (!filters) return traces;
603
- const indexedFiltered = traces.filter((t) => {
604
- if (filters.has_errors !== void 0 && t.has_errors !== filters.has_errors) return false;
605
- if (filters.service_names && filters.service_names.length > 0) {
606
- if (!t.service_name || !filters.service_names.includes(t.service_name)) return false;
607
- }
608
- if (filters.agent_names && filters.agent_names.length > 0) {
609
- if (!t.agent_name || !filters.agent_names.includes(t.agent_name)) return false;
610
- }
611
- if (filters.model_names && filters.model_names.length > 0) {
612
- if (![...t.models].some((m) => filters.model_names.includes(m))) return false;
613
- }
614
- if (filters.tool_names && filters.tool_names.length > 0) {
615
- if (![...t.tools].some((tn) => filters.tool_names.includes(tn))) return false;
616
- }
617
- if (filters.start_time_after && t.start_time < filters.start_time_after) return false;
618
- if (filters.start_time_before && t.start_time > filters.start_time_before) return false;
619
- return true;
620
- });
621
- if (!filters.regex_pattern) return indexedFiltered;
622
- const re = compileSearchRegex(filters.regex_pattern);
623
- const buf = await this.buffer();
624
- const out = [];
625
- for (const t of indexedFiltered) {
626
- let matched = false;
627
- for (const s of t.spans) {
628
- const slice = buf.subarray(s.line_byte_offset, s.line_byte_offset + s.line_byte_length);
629
- if (re.test(slice.toString("utf8"))) {
630
- matched = true;
631
- break;
632
- }
633
- }
634
- if (matched) out.push(t);
635
- }
636
- return out;
637
- }
638
- toSummary(t) {
639
- return {
640
- trace_id: t.trace_id,
641
- service_name: t.service_name,
642
- agent_name: t.agent_name,
643
- span_count: t.span_count,
644
- has_errors: t.has_errors,
645
- start_time: t.start_time,
646
- end_time: t.end_time,
647
- duration_ms: t.duration_ms,
648
- raw_jsonl_bytes: t.raw_jsonl_bytes,
649
- models: [...t.models].sort(),
650
- tools: [...t.tools].sort()
651
- };
652
- }
653
- // ─── Span projection (lazy attribute reads) ────────────────────────
654
- projectSpan(buf, trace_id, s, perAttrCap, counter) {
655
- const slice = buf.subarray(s.line_byte_offset, s.line_byte_offset + s.line_byte_length).toString("utf8");
656
- let raw = {};
657
- try {
658
- const parsed = JSON.parse(slice);
659
- if (parsed && typeof parsed === "object") raw = parsed;
660
- } catch {
661
- }
662
- const attrs = extractOtlpAttributes(raw);
663
- const projected = {};
664
- for (const [k, v] of Object.entries(attrs)) {
665
- if (typeof v === "string") {
666
- const trunc = truncateForBudget(v, perAttrCap);
667
- if (trunc !== v) counter.value += 1;
668
- projected[k] = trunc;
669
- } else if (Array.isArray(v) || v && typeof v === "object") {
670
- const json = JSON.stringify(v);
671
- const trunc = truncateForBudget(json, perAttrCap);
672
- if (trunc !== json) {
673
- counter.value += 1;
674
- projected[k] = trunc;
675
- } else {
676
- projected[k] = v;
677
- }
678
- } else {
679
- projected[k] = v;
680
- }
681
- }
682
- return {
683
- trace_id,
684
- span_id: s.span_id,
685
- parent_span_id: s.parent_span_id,
686
- name: s.name,
687
- kind: s.kind,
688
- start_time: s.start_time,
689
- end_time: s.end_time,
690
- duration_ms: s.duration_ms,
691
- status: s.status,
692
- status_message: s.status_message,
693
- service_name: s.service_name,
694
- agent_name: s.agent_name,
695
- model_name: s.model_name,
696
- tool_name: s.tool_name,
697
- attributes: projected
698
- };
699
- }
700
- buildOversizedSummary(t, span_response_bytes_max) {
701
- const counts = /* @__PURE__ */ new Map();
702
- let errorCount = 0;
703
- for (const s of t.spans) {
704
- counts.set(s.name, (counts.get(s.name) ?? 0) + 1);
705
- if (s.status === "ERROR") errorCount += 1;
706
- }
707
- const top = [...counts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 20);
708
- return {
709
- span_count: t.span_count,
710
- top_span_names: top,
711
- span_response_bytes_max,
712
- error_span_count: errorCount
713
- };
714
- }
715
- async scanSpanForMatches(buf, trace_id, s, re, textBudget, recordCap) {
716
- const slice = buf.subarray(s.line_byte_offset, s.line_byte_offset + s.line_byte_length).toString("utf8");
717
- const records = [];
718
- const globalRe = new RegExp(re.source, re.flags.includes("g") ? re.flags : `${re.flags}g`);
719
- let total = 0;
720
- let hasMore = false;
721
- let m = globalRe.exec(slice);
722
- while (m !== null) {
723
- total += 1;
724
- if (m.index === globalRe.lastIndex) globalRe.lastIndex += 1;
725
- if (records.length >= recordCap) {
726
- hasMore = true;
727
- break;
728
- }
729
- const before = slice.slice(Math.max(0, m.index - textBudget / 2), m.index);
730
- const after = slice.slice(
731
- m.index + m[0].length,
732
- m.index + m[0].length + Math.floor(textBudget / 2)
733
- );
734
- records.push({
735
- trace_id,
736
- span_id: s.span_id,
737
- span_name: s.name,
738
- span_kind: s.kind,
739
- attribute_path: bestAttributePathForOffset(slice, m.index) ?? "span.raw",
740
- matched_text: truncateForBudget(m[0], textBudget),
741
- context_before: truncateForBudget(before, textBudget),
742
- context_after: truncateForBudget(after, textBudget),
743
- match_offset: m.index
744
- });
745
- m = globalRe.exec(slice);
746
- }
747
- return { records, total, hasMore };
748
- }
749
- };
750
- var TraceFileMissingError = class extends NotFoundError {
751
- constructor(path) {
752
- super(`trace file not found: ${path}`);
753
- }
754
- };
755
- var TraceFileTooLargeError = class extends Error {
756
- path;
757
- size_bytes;
758
- max_bytes;
759
- constructor(path, size_bytes, max_bytes) {
760
- super(
761
- `trace file ${path} is ${size_bytes} bytes, over the ${max_bytes}-byte limit; raise OtlpFileTraceStoreOptions.maxFileBytes or pre-split the file`
762
- );
763
- this.path = path;
764
- this.size_bytes = size_bytes;
765
- this.max_bytes = max_bytes;
766
- }
767
- };
768
- var TraceNotFoundError = class extends NotFoundError {
769
- trace_id;
770
- constructor(trace_id) {
771
- super(`trace not found: ${trace_id}`);
772
- this.trace_id = trace_id;
773
- }
774
- };
775
- var SpanNotFoundError = class extends NotFoundError {
776
- trace_id;
777
- span_id;
778
- constructor(trace_id, span_id) {
779
- super(`span ${span_id} not found in trace ${trace_id}`);
780
- this.trace_id = trace_id;
781
- this.span_id = span_id;
782
- }
783
- };
784
- function isPresent(v) {
785
- return v !== void 0;
786
- }
787
- function isUnescapedQuote(slice, idx) {
788
- if (slice[idx] !== '"') return false;
789
- let backslashes = 0;
790
- let b = idx - 1;
791
- while (b >= 0 && slice[b] === "\\") {
792
- backslashes += 1;
793
- b -= 1;
794
- }
795
- return backslashes % 2 === 0;
796
- }
797
- function prevUnescapedQuote(slice, from) {
798
- for (let i = from; i >= 0; i -= 1) {
799
- if (slice[i] === '"' && isUnescapedQuote(slice, i)) return i;
800
- }
801
- return -1;
802
- }
803
- function bestAttributePathForOffset(slice, offset) {
804
- const valueQuote = prevUnescapedQuote(slice, Math.min(offset, slice.length - 1));
805
- if (valueQuote < 1) return null;
806
- let j = valueQuote - 1;
807
- while (j >= 0 && slice[j] !== ":") j -= 1;
808
- if (j < 1) return null;
809
- const keyClose = prevUnescapedQuote(slice, j - 1);
810
- if (keyClose < 1) return null;
811
- const keyOpen = prevUnescapedQuote(slice, keyClose - 1);
812
- if (keyOpen < 0) return null;
813
- return slice.slice(keyOpen + 1, keyClose);
814
- }
815
- var ERROR_CLUSTER_MAX = 50;
816
- var ERROR_CLUSTER_EXEMPLARS = 5;
817
- var SIGNATURE_MAX_CHARS = 160;
818
- function normalizeErrorSignature(message, spanName) {
819
- const raw = (message ?? "").trim();
820
- const base = raw.length > 0 ? raw : `(${spanName || "error"} \u2014 no message)`;
821
- const norm = base.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, "<id>").replace(/\b[0-9a-f]{12,}\b/gi, "<id>").replace(/(?:\/[\w.\-@]+){2,}/g, "<path>").replace(/\b\d+(?:\.\d+)?(ms|s|m|h|kb|mb|gb)?\b/gi, (_m, u) => u ? `#${u}` : "#").replace(/\s+/g, " ").trim();
822
- return norm.length > SIGNATURE_MAX_CHARS ? `${norm.slice(0, SIGNATURE_MAX_CHARS)}\u2026` : norm;
823
- }
824
- function bump(map, key) {
825
- if (!key) return;
826
- map.set(key, (map.get(key) ?? 0) + 1);
827
- }
828
- function topKey(map) {
829
- let best = null;
830
- let bestN = 0;
831
- for (const [k, n] of map)
832
- if (n > bestN) {
833
- best = k;
834
- bestN = n;
835
- }
836
- return best;
837
- }
838
- function accumulateErrorCluster(clusters, traceId, span) {
839
- const signature = normalizeErrorSignature(span.status_message, span.name);
840
- let acc = clusters.get(signature);
841
- if (!acc) {
842
- acc = {
843
- signature,
844
- sample: (span.status_message ?? span.name ?? "").slice(0, 500),
845
- traceIds: /* @__PURE__ */ new Set(),
846
- spanIds: [],
847
- spanCount: 0,
848
- spanNames: /* @__PURE__ */ new Map(),
849
- toolNames: /* @__PURE__ */ new Map()
850
- };
851
- clusters.set(signature, acc);
852
- }
853
- acc.traceIds.add(traceId);
854
- acc.spanCount += 1;
855
- if (acc.spanIds.length < ERROR_CLUSTER_EXEMPLARS && !acc.spanIds.includes(span.span_id)) {
856
- acc.spanIds.push(span.span_id);
857
- }
858
- bump(acc.spanNames, span.name);
859
- bump(acc.toolNames, span.tool_name);
860
- }
861
- function finalizeErrorClusters(clusters, errorTraceCount) {
862
- const out = [...clusters.values()].map(
863
- (acc) => ({
864
- signature: acc.signature,
865
- status_message_sample: acc.sample,
866
- span_name: topKey(acc.spanNames),
867
- tool_name: topKey(acc.toolNames),
868
- trace_count: acc.traceIds.size,
869
- span_count: acc.spanCount,
870
- prevalence: errorTraceCount > 0 ? acc.traceIds.size / errorTraceCount : 0,
871
- exemplar_trace_ids: [...acc.traceIds].slice(0, ERROR_CLUSTER_EXEMPLARS),
872
- exemplar_span_ids: acc.spanIds.slice(0, ERROR_CLUSTER_EXEMPLARS)
873
- })
874
- );
875
- out.sort((a, b) => b.trace_count - a.trace_count || b.span_count - a.span_count);
876
- return out.slice(0, ERROR_CLUSTER_MAX);
877
- }
878
-
879
- // src/trace-analyst/tools.ts
880
- import { f, fn } from "@ax-llm/ax";
881
- var NAMESPACE = "traces";
882
- var filtersField = f.json("Filter set. ALL fields are AND-composed. Leave empty to scan everything.").optional();
883
- function buildTraceAnalystTools(opts) {
884
- const { store } = opts;
885
- const getDatasetOverview = fn("getDatasetOverview").description(
886
- "Dataset rollup: total traces, raw_jsonl_bytes, services, agents, models, tools, and sample_trace_ids (real ids passable to view/search). Always call this FIRST without a regex_pattern."
887
- ).namespace(NAMESPACE).arg("filters", filtersField).returns(f.json("DatasetOverview")).handler(async ({ filters }) => store.getOverview(parseFilters(filters))).build();
888
- const queryTraces = fn("queryTraces").description(
889
- "Paginated trace summaries. Each summary carries raw_jsonl_bytes \u2014 use it to size traces BEFORE calling viewTrace. Narrow with indexed filters before adding regex_pattern."
890
- ).namespace(NAMESPACE).arg("filters", filtersField).arg("limit", f.number("Page size, 1..200")).arg("offset", f.number("Page offset; default 0").optional()).returns(f.json("QueryTracesPage")).handler(
891
- async ({ filters, limit, offset }) => store.queryTraces({
892
- filters: parseFilters(filters),
893
- limit: assertPageLimit(limit),
894
- offset: assertOffset(offset)
895
- })
896
- ).build();
897
- const countTraces = fn("countTraces").description(
898
- "Count traces matching `filters`. Use as a cheap pre-flight before opting into a regex_pattern scan."
899
- ).namespace(NAMESPACE).arg("filters", filtersField).returns(f.number("count")).handler(async ({ filters }) => store.countTraces(parseFilters(filters))).build();
900
- const viewTrace = fn("viewTrace").description(
901
- "Return ALL spans for a single trace, with each attribute capped at ~4KB. If the response would exceed the per-call ceiling the result carries `oversized` instead of `spans` \u2014 DO NOT retry with the same trace_id; switch to searchTrace / viewSpans."
902
- ).namespace(NAMESPACE).arg("trace_id", f.string("Real trace id from a prior overview/query")).returns(f.json("ViewTraceResult")).handler(
903
- async ({ trace_id }) => store.viewTrace({ trace_id: assertString(trace_id, "trace_id") })
904
- ).build();
905
- const viewSpans = fn("viewSpans").description(
906
- "Surgical read of specific spans within a trace, with each attribute capped at ~16KB (4\xD7 the discovery cap). Use after searchTrace narrows to specific span_ids."
907
- ).namespace(NAMESPACE).arg("trace_id", f.string("Real trace id")).arg("span_ids", f.string("Span ids to fetch").array()).returns(f.json("ViewSpansResult")).handler(
908
- async ({ trace_id, span_ids }) => store.viewSpans({
909
- trace_id: assertString(trace_id, "trace_id"),
910
- span_ids: assertStringArray(span_ids, "span_ids")
911
- })
912
- ).build();
913
- const searchTrace = fn("searchTrace").description(
914
- "Regex search across all spans of one trace. Returns `{trace_id, hits: SpanMatchRecord[], total_matches, has_more}`. **Iterate `result.hits`, NOT `result.matches`** \u2014 the field is `hits`. Each hit has `{span_id, span_name, span_kind, attribute_path, matched_text, context_before, context_after, match_offset}`. Bounded regardless of trace size by max_matches (1..500, default 50). If has_more=true, REFINE the regex rather than blindly raising max_matches."
915
- ).namespace(NAMESPACE).arg("trace_id", f.string("Real trace id")).arg("regex_pattern", f.string("JS-compatible regex, multiline")).arg("max_matches", f.number("Max records returned, 1..500; default 50").optional()).returns(f.json("SearchTraceResult")).handler(
916
- async ({ trace_id, regex_pattern, max_matches }) => store.searchTrace({
917
- trace_id: assertString(trace_id, "trace_id"),
918
- regex_pattern: assertRegex(regex_pattern),
919
- max_matches: assertMaxMatches(max_matches)
920
- })
921
- ).build();
922
- const searchSpan = fn("searchSpan").description(
923
- "Regex search inside a single span. Use when viewSpans returned a 16KB-truncated payload and you need to narrow further. Returns `{trace_id, span_id, hits: SpanMatchRecord[], total_matches, has_more}` \u2014 iterate `result.hits`, NOT `result.matches`."
924
- ).namespace(NAMESPACE).arg("trace_id", f.string("Real trace id")).arg("span_id", f.string("Real span id within trace")).arg("regex_pattern", f.string("JS-compatible regex, multiline")).arg("max_matches", f.number("Max records, 1..500; default 50").optional()).returns(f.json("SearchSpanResult")).handler(
925
- async ({ trace_id, span_id, regex_pattern, max_matches }) => store.searchSpan({
926
- trace_id: assertString(trace_id, "trace_id"),
927
- span_id: assertString(span_id, "span_id"),
928
- regex_pattern: assertRegex(regex_pattern),
929
- max_matches: assertMaxMatches(max_matches)
930
- })
931
- ).build();
932
- return [
933
- getDatasetOverview,
934
- queryTraces,
935
- countTraces,
936
- viewTrace,
937
- viewSpans,
938
- searchTrace,
939
- searchSpan
940
- ];
941
- }
942
- function traceAnalystFunctionGroup(opts) {
943
- return {
944
- namespace: NAMESPACE,
945
- title: "Trace Analysis",
946
- selectionCriteria: "Use for any inspection of OTLP-shaped trace data.",
947
- description: "Discovery \u2192 narrow \u2192 deep-read tools over a JSONL trace dataset. Always call getDatasetOverview first.",
948
- functions: buildTraceAnalystTools(opts)
949
- };
950
- }
951
- function parseFilters(input) {
952
- if (input == null) return void 0;
953
- if (typeof input !== "object" || Array.isArray(input)) {
954
- throw new TypeError(`filters must be an object, got ${typeof input}`);
955
- }
956
- const f2 = input;
957
- const out = {};
958
- if (typeof f2.has_errors === "boolean") out.has_errors = f2.has_errors;
959
- out.service_names = stringArrayOrUndefined(f2.service_names, "service_names");
960
- out.agent_names = stringArrayOrUndefined(f2.agent_names, "agent_names");
961
- out.model_names = stringArrayOrUndefined(f2.model_names, "model_names");
962
- out.tool_names = stringArrayOrUndefined(f2.tool_names, "tool_names");
963
- if (typeof f2.start_time_after === "string") out.start_time_after = f2.start_time_after;
964
- if (typeof f2.start_time_before === "string") out.start_time_before = f2.start_time_before;
965
- if (typeof f2.regex_pattern === "string") {
966
- if (f2.regex_pattern.length === 0) {
967
- throw new TypeError("filters.regex_pattern cannot be empty");
968
- }
969
- out.regex_pattern = f2.regex_pattern;
970
- }
971
- return out;
972
- }
973
- function stringArrayOrUndefined(v, label) {
974
- if (v === void 0 || v === null) return void 0;
975
- if (!Array.isArray(v)) throw new TypeError(`${label} must be an array of strings`);
976
- if (v.some((x) => typeof x !== "string")) {
977
- throw new TypeError(`${label} entries must be strings`);
978
- }
979
- return v;
980
- }
981
- function assertPageLimit(limit) {
982
- if (typeof limit !== "number" || !Number.isInteger(limit) || limit < 1 || limit > 200) {
983
- throw new RangeError(`limit must be an integer 1..200`);
984
- }
985
- return limit;
986
- }
987
- function assertOffset(offset) {
988
- if (offset === void 0) return void 0;
989
- if (typeof offset !== "number" || !Number.isInteger(offset) || offset < 0) {
990
- throw new RangeError(`offset must be a non-negative integer`);
991
- }
992
- return offset;
993
- }
994
- function assertRegex(pattern) {
995
- if (typeof pattern !== "string" || pattern.length === 0) {
996
- throw new TypeError(`regex_pattern must be a non-empty string`);
997
- }
998
- new RegExp(pattern, "m");
999
- return pattern;
1000
- }
1001
- function assertMaxMatches(n) {
1002
- if (n === void 0) return void 0;
1003
- if (typeof n !== "number" || !Number.isInteger(n) || n < 1 || n > 500) {
1004
- throw new RangeError(`max_matches must be an integer 1..500`);
1005
- }
1006
- return n;
1007
- }
1008
- function assertString(v, label) {
1009
- if (typeof v !== "string" || v.length === 0) {
1010
- throw new TypeError(`${label} must be a non-empty string`);
1011
- }
1012
- return v;
1013
- }
1014
- function assertStringArray(v, label) {
1015
- if (!Array.isArray(v)) throw new TypeError(`${label} must be an array of strings`);
1016
- if (v.some((x) => typeof x !== "string")) {
1017
- throw new TypeError(`${label} entries must be strings`);
1018
- }
1019
- return v;
1020
- }
1021
-
1022
- // src/trace-analyst/loop.ts
1023
- import {
1024
- AxJSRuntime,
1025
- agent
1026
- } from "@ax-llm/ax";
1027
- var TRACE_ANALYSIS_FINAL_TASK = "Submit the completed trace analysis.";
1028
- var TRACE_ANALYSIS_COMPLETION_INSTRUCTION = `This host consumes your executor result directly; there is no downstream responder for this run. Ignore generic executor guidance that says a responder will format the answer. You must produce the final report and findings yourself.
1029
-
1030
- Return exactly one executable JavaScript program per turn. Never emit multiple JavaScript or code fences; put every tool call and the final call in that one program.
1031
-
1032
- When the analysis is complete, call \`await final(${JSON.stringify(TRACE_ANALYSIS_FINAL_TASK)}, { report, findings })\` exactly once. Do not return a one-argument string from \`final(...)\`.`;
1033
- var TraceAnalysisTurnLimitError = class extends Error {
1034
- analystId;
1035
- maxTurns;
1036
- constructor(analystId, maxTurns, cause) {
1037
- super(
1038
- `Trace analyst '${analystId}' reached maxTurns=${maxTurns} without a structured final result`,
1039
- { cause }
1040
- );
1041
- this.name = "TraceAnalysisTurnLimitError";
1042
- this.analystId = analystId;
1043
- this.maxTurns = maxTurns;
1044
- }
1045
- };
1046
- async function runTraceAnalysisLoop(options) {
1047
- validateLoopLimits(options);
1048
- const config = {
1049
- agentIdentity: { name: options.id, description: options.description },
1050
- contextFields: [],
1051
- runtime: new AxJSRuntime({
1052
- permissions: [],
1053
- blockDynamicImport: true,
1054
- allowedModules: [],
1055
- freezeIntrinsics: true,
1056
- blockShadowRealm: true,
1057
- preventGlobalThisExtensions: false
1058
- }),
1059
- maxSubAgentCalls: options.maxSubqueries,
1060
- maxTurns: options.maxTurns,
1061
- maxRuntimeChars: options.maxRuntimeChars,
1062
- maxBatchedLlmQueryConcurrency: options.maxParallelSubqueries,
1063
- promptLevel: "detailed",
1064
- contextPolicy: { preset: "full", budget: "balanced" },
1065
- functions: options.tools,
1066
- executorOptions: {
1067
- description: `${options.prompt.trim()}
1068
-
1069
- ${TRACE_ANALYSIS_COMPLETION_INSTRUCTION}`,
1070
- ...options.model ? { model: options.model } : {},
1071
- showThoughts: false,
1072
- thinkingTokenBudget: "none"
1073
- },
1074
- ...options.onTurn ? { actorTurnCallback: options.onTurn } : {},
1075
- bubbleErrors: [TraceFileMissingError]
1076
- };
1077
- const analyst = options.findingType === "string" ? agent("question:string -> report:string, findings:string[]", config) : agent("question:string -> report:string, findings:json[]", config);
1078
- const state = await analyst.executor.run(
1079
- options.ai,
1080
- { question: options.question },
1081
- options.signal ? { abortSignal: options.signal } : void 0
1082
- );
1083
- let completed;
1084
- try {
1085
- completed = options.findingType === "string" ? readTraceAnalysisCompletion(state.executorResult, "string") : readTraceAnalysisCompletion(state.executorResult, "object");
1086
- } catch (error) {
1087
- if (state.turnCount >= options.maxTurns) {
1088
- throw new TraceAnalysisTurnLimitError(options.id, options.maxTurns, error);
1089
- }
1090
- throw new Error(`Trace analyst '${options.id}' stopped without a structured final result`, {
1091
- cause: error
1092
- });
1093
- }
1094
- return {
1095
- ...completed,
1096
- usage: analyst.executor.getUsage(),
1097
- chatLog: analyst.executor.getChatLog(),
1098
- turnCount: state.turnCount
1099
- };
1100
- }
1101
- function readTraceAnalysisCompletion(value, findingType) {
1102
- if (!value || typeof value !== "object") {
1103
- throw new Error("Trace analyst did not return a structured final result");
1104
- }
1105
- const completion = value;
1106
- if (completion.type !== "final" || !Array.isArray(completion.args) || completion.args.length !== 2 || completion.args[0] !== TRACE_ANALYSIS_FINAL_TASK) {
1107
- throw new Error("Trace analyst did not return a structured final result");
1108
- }
1109
- const payload = completion.args[1];
1110
- if (!payload || typeof payload !== "object") {
1111
- throw new Error("Trace analyst final result must contain report and findings");
1112
- }
1113
- const { report, findings } = payload;
1114
- if (typeof report !== "string" || !Array.isArray(findings)) {
1115
- throw new Error("Trace analyst final result must contain report and findings");
1116
- }
1117
- if (findingType === "string") {
1118
- if (findings.some((finding) => typeof finding !== "string")) {
1119
- throw new Error("Trace analyst final result must contain string findings");
1120
- }
1121
- return { report, findings };
1122
- }
1123
- if (findings.some((finding) => !finding || typeof finding !== "object" || Array.isArray(finding))) {
1124
- throw new Error("Trace analyst final result must contain object findings");
1125
- }
1126
- return { report, findings };
1127
- }
1128
- function validateLoopLimits(options) {
1129
- if (!Number.isSafeInteger(options.maxSubqueries) || options.maxSubqueries < 0) {
1130
- throw new TypeError("maxSubqueries must be a non-negative integer");
1131
- }
1132
- if (!Number.isSafeInteger(options.maxParallelSubqueries) || options.maxParallelSubqueries < 1) {
1133
- throw new TypeError("maxParallelSubqueries must be a positive integer");
1134
- }
1135
- }
1136
-
1137
- export {
1138
- classifyOtlpSpanRole,
1139
- isOtlpModelCall,
1140
- applyToolSpanOtlpAttributes,
1141
- traceSpanKindToOpenInferenceKind,
1142
- projectOtlpFlatLine,
1143
- readOtlpStatus,
1144
- inferOtlpKind,
1145
- extractOtlpAttributes,
1146
- stringField,
1147
- asString,
1148
- firstStringAttr,
1149
- spanEpochMillis,
1150
- compareSpanTime,
1151
- DEFAULT_TRACE_ANALYST_BUDGETS,
1152
- TRACE_ANALYST_TRUNCATION_MARKER_PREFIX,
1153
- OtlpFileTraceStore,
1154
- TraceFileMissingError,
1155
- TraceNotFoundError,
1156
- SpanNotFoundError,
1157
- runTraceAnalysisLoop,
1158
- buildTraceAnalystTools,
1159
- traceAnalystFunctionGroup
1160
- };
1161
- //# sourceMappingURL=chunk-P6FYH6K4.js.map