@tangle-network/agent-eval 0.129.0 → 0.130.0

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 (427) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -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-DviOvUNr.js +754 -0
  36. package/dist/benchmarks-DviOvUNr.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-CBKZvQ1H.js +3885 -0
  46. package/dist/campaign-CBKZvQ1H.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-CAPUUKaM.d.ts +335 -0
  116. package/dist/index-CAPUUKaM.d.ts.map +1 -0
  117. package/dist/index-DE5fb3EC.d.ts +2244 -0
  118. package/dist/index-DE5fb3EC.d.ts.map +1 -0
  119. package/dist/index-DSC51roc.d.ts +102 -0
  120. package/dist/index-DSC51roc.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-B7wX7XkF.d.ts +1739 -0
  253. package/dist/skillopt-optimization-method-B7wX7XkF.d.ts.map +1 -0
  254. package/dist/skillopt-optimization-method-D4ODwFVV.js +7712 -0
  255. package/dist/skillopt-optimization-method-D4ODwFVV.js.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/package.json +17 -9
  301. package/dist/benchmarks/index.js.map +0 -1
  302. package/dist/campaign/index.js.map +0 -1
  303. package/dist/chunk-2QU3YOPR.js +0 -7374
  304. package/dist/chunk-2QU3YOPR.js.map +0 -1
  305. package/dist/chunk-3OCR4R5I.js +0 -728
  306. package/dist/chunk-3OCR4R5I.js.map +0 -1
  307. package/dist/chunk-3RF76KTD.js +0 -84
  308. package/dist/chunk-3RF76KTD.js.map +0 -1
  309. package/dist/chunk-56TAVBOK.js +0 -698
  310. package/dist/chunk-5DTSBUL2.js +0 -159
  311. package/dist/chunk-5DTSBUL2.js.map +0 -1
  312. package/dist/chunk-7FO3TNPI.js +0 -232
  313. package/dist/chunk-7FO3TNPI.js.map +0 -1
  314. package/dist/chunk-7ZZMD7UK.js +0 -386
  315. package/dist/chunk-7ZZMD7UK.js.map +0 -1
  316. package/dist/chunk-BOD4O7OF.js +0 -40
  317. package/dist/chunk-BOD4O7OF.js.map +0 -1
  318. package/dist/chunk-BSO5JDQH.js +0 -2335
  319. package/dist/chunk-BSO5JDQH.js.map +0 -1
  320. package/dist/chunk-C6LXANRU.js +0 -1550
  321. package/dist/chunk-C6LXANRU.js.map +0 -1
  322. package/dist/chunk-DODXQREJ.js +0 -752
  323. package/dist/chunk-DODXQREJ.js.map +0 -1
  324. package/dist/chunk-DRYIUNWY.js +0 -622
  325. package/dist/chunk-DRYIUNWY.js.map +0 -1
  326. package/dist/chunk-E7QXT7SX.js +0 -183
  327. package/dist/chunk-E7QXT7SX.js.map +0 -1
  328. package/dist/chunk-EG66UGL4.js +0 -341
  329. package/dist/chunk-EG66UGL4.js.map +0 -1
  330. package/dist/chunk-FXTVJPYD.js +0 -576
  331. package/dist/chunk-FXTVJPYD.js.map +0 -1
  332. package/dist/chunk-G7MGMCZD.js +0 -153
  333. package/dist/chunk-G7MGMCZD.js.map +0 -1
  334. package/dist/chunk-GGE4NNQT.js +0 -65
  335. package/dist/chunk-GGE4NNQT.js.map +0 -1
  336. package/dist/chunk-H23X7XKK.js +0 -181
  337. package/dist/chunk-H23X7XKK.js.map +0 -1
  338. package/dist/chunk-HHWE3POT.js +0 -94
  339. package/dist/chunk-HHWE3POT.js.map +0 -1
  340. package/dist/chunk-HPWUNB47.js +0 -289
  341. package/dist/chunk-HPWUNB47.js.map +0 -1
  342. package/dist/chunk-IYCLP2N2.js +0 -766
  343. package/dist/chunk-IYCLP2N2.js.map +0 -1
  344. package/dist/chunk-JHCHEVET.js +0 -274
  345. package/dist/chunk-JHCHEVET.js.map +0 -1
  346. package/dist/chunk-JQSF5DQT.js +0 -701
  347. package/dist/chunk-JQSF5DQT.js.map +0 -1
  348. package/dist/chunk-K4DBDHLK.js +0 -158
  349. package/dist/chunk-K4DBDHLK.js.map +0 -1
  350. package/dist/chunk-K6N6XJJX.js +0 -306
  351. package/dist/chunk-K6N6XJJX.js.map +0 -1
  352. package/dist/chunk-M4YBQKIJ.js +0 -1040
  353. package/dist/chunk-M4YBQKIJ.js.map +0 -1
  354. package/dist/chunk-MA6HLL3S.js +0 -65
  355. package/dist/chunk-MA6HLL3S.js.map +0 -1
  356. package/dist/chunk-MAZ26DC7.js +0 -99
  357. package/dist/chunk-MAZ26DC7.js.map +0 -1
  358. package/dist/chunk-NPCTHQIO.js +0 -91
  359. package/dist/chunk-NPCTHQIO.js.map +0 -1
  360. package/dist/chunk-NY44NC4A.js +0 -1056
  361. package/dist/chunk-NY44NC4A.js.map +0 -1
  362. package/dist/chunk-OIUOT4QD.js +0 -44
  363. package/dist/chunk-OIUOT4QD.js.map +0 -1
  364. package/dist/chunk-ONWEPEDO.js +0 -57
  365. package/dist/chunk-ONWEPEDO.js.map +0 -1
  366. package/dist/chunk-OWN5NPMC.js +0 -152
  367. package/dist/chunk-OWN5NPMC.js.map +0 -1
  368. package/dist/chunk-P6FYH6K4.js +0 -1161
  369. package/dist/chunk-P6FYH6K4.js.map +0 -1
  370. package/dist/chunk-PC4UYEBM.js +0 -166
  371. package/dist/chunk-PC4UYEBM.js.map +0 -1
  372. package/dist/chunk-PC5DOSM7.js +0 -579
  373. package/dist/chunk-PC5DOSM7.js.map +0 -1
  374. package/dist/chunk-PXE2VKMX.js +0 -140
  375. package/dist/chunk-PXE2VKMX.js.map +0 -1
  376. package/dist/chunk-PZ5AY32C.js +0 -10
  377. package/dist/chunk-PZ5AY32C.js.map +0 -1
  378. package/dist/chunk-QB6BDBP2.js +0 -4464
  379. package/dist/chunk-QB6BDBP2.js.map +0 -1
  380. package/dist/chunk-RXHCETDZ.js +0 -536
  381. package/dist/chunk-RXHCETDZ.js.map +0 -1
  382. package/dist/chunk-RZTMDUO7.js +0 -49
  383. package/dist/chunk-RZTMDUO7.js.map +0 -1
  384. package/dist/chunk-SFLLL76A.js +0 -669
  385. package/dist/chunk-SFLLL76A.js.map +0 -1
  386. package/dist/chunk-SZLVEKMJ.js +0 -1446
  387. package/dist/chunk-SZLVEKMJ.js.map +0 -1
  388. package/dist/chunk-T4SQEITX.js +0 -95
  389. package/dist/chunk-T4SQEITX.js.map +0 -1
  390. package/dist/chunk-T6RLYGAD.js +0 -158
  391. package/dist/chunk-T6RLYGAD.js.map +0 -1
  392. package/dist/chunk-TJVT4QFF.js +0 -911
  393. package/dist/chunk-TJVT4QFF.js.map +0 -1
  394. package/dist/chunk-TQ7LNKZ3.js +0 -136
  395. package/dist/chunk-TQ7LNKZ3.js.map +0 -1
  396. package/dist/chunk-U4L7JRPZ.js +0 -1706
  397. package/dist/chunk-U4L7JRPZ.js.map +0 -1
  398. package/dist/chunk-U4PHLT2N.js +0 -419
  399. package/dist/chunk-U4PHLT2N.js.map +0 -1
  400. package/dist/chunk-VCZ5FQYW.js +0 -928
  401. package/dist/chunk-VCZ5FQYW.js.map +0 -1
  402. package/dist/chunk-VI2UW6B6.js +0 -162
  403. package/dist/chunk-VI2UW6B6.js.map +0 -1
  404. package/dist/chunk-VQMK5FMP.js +0 -247
  405. package/dist/chunk-VQMK5FMP.js.map +0 -1
  406. package/dist/chunk-WGXIEX7P.js +0 -116
  407. package/dist/chunk-WGXIEX7P.js.map +0 -1
  408. package/dist/chunk-WVATSFCP.js +0 -1553
  409. package/dist/chunk-WVATSFCP.js.map +0 -1
  410. package/dist/chunk-X4YIBDER.js +0 -1662
  411. package/dist/chunk-X4YIBDER.js.map +0 -1
  412. package/dist/chunk-YQN4ICPP.js +0 -355
  413. package/dist/chunk-YQN4ICPP.js.map +0 -1
  414. package/dist/chunk-ZET2UAYW.js +0 -89
  415. package/dist/chunk-ZET2UAYW.js.map +0 -1
  416. package/dist/chunk-ZHTZ4EYI.js +0 -1212
  417. package/dist/chunk-ZHTZ4EYI.js.map +0 -1
  418. package/dist/control.js.map +0 -1
  419. package/dist/hosted/index.js.map +0 -1
  420. package/dist/matrix/index.js.map +0 -1
  421. package/dist/reporting.js.map +0 -1
  422. package/dist/rollout/index.js.map +0 -1
  423. package/dist/run-campaign-OJJ7CZF4.js +0 -18
  424. package/dist/run-campaign-OJJ7CZF4.js.map +0 -1
  425. package/dist/supervisor-run/index.js.map +0 -1
  426. package/dist/traces.js.map +0 -1
  427. package/dist/wire/index.js.map +0 -1
@@ -0,0 +1,1085 @@
1
+ import { a as NotFoundError } from "./errors-8YnH8WlF.js";
2
+ import { INPUT_VALUE, LLM_MODEL_ATTR_KEYS, OUTPUT_VALUE, SPAN_KIND_ATTR_KEYS, TOOL_ARGS_CAPTURED, TOOL_LATENCY_MS, TOOL_NAME, TOOL_NAME_ATTR_KEYS } from "./trace-attributes.js";
3
+ import { AxJSRuntime, agent, f, fn } from "@ax-llm/ax";
4
+ import { readFile, stat } from "node:fs/promises";
5
+ //#region src/trace/otlp-attributes.ts
6
+ /** Canonical OpenInference-over-OTLP attribute vocabulary used at the trace boundary. */
7
+ const TOOL_SPAN_ATTRIBUTE_KEYS = [
8
+ TOOL_NAME,
9
+ TOOL_ARGS_CAPTURED,
10
+ TOOL_LATENCY_MS,
11
+ INPUT_VALUE,
12
+ OUTPUT_VALUE
13
+ ];
14
+ const EXPLICIT_SPAN_ROLES = /* @__PURE__ */ new Set([
15
+ "AGENT",
16
+ "CHAIN",
17
+ "EVALUATOR",
18
+ "GUARDRAIL",
19
+ "LLM",
20
+ "SPAN",
21
+ "TOOL"
22
+ ]);
23
+ /**
24
+ * Classify a span once for both measurement and error accounting.
25
+ * An explicit OpenInference kind wins; untyped spans use the same tool and
26
+ * model signals in online and offline intake.
27
+ */
28
+ function classifyOtlpSpanRole(input) {
29
+ const explicitKind = input.kind ?? firstStringAttribute(input.attributes, SPAN_KIND_ATTR_KEYS);
30
+ if (explicitKind) {
31
+ const normalized = explicitKind.toUpperCase();
32
+ if (EXPLICIT_SPAN_ROLES.has(normalized)) return normalized;
33
+ }
34
+ if (firstStringAttribute(input.attributes, TOOL_NAME_ATTR_KEYS) !== void 0 || /^(?:function|tool)[.:/]/i.test(input.name)) return "TOOL";
35
+ const spanType = input.attributes["span.type"];
36
+ 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") return "LLM";
37
+ return "UNKNOWN";
38
+ }
39
+ function isOtlpModelCall(input) {
40
+ return classifyOtlpSpanRole(input) === "LLM";
41
+ }
42
+ function toolSpanOtlpAttributes(span) {
43
+ const argsCaptured = span.argsCaptured !== false;
44
+ const attributes = {
45
+ [TOOL_NAME]: span.toolName,
46
+ [TOOL_ARGS_CAPTURED]: argsCaptured
47
+ };
48
+ if (span.latencyMs !== void 0) attributes[TOOL_LATENCY_MS] = span.latencyMs;
49
+ if (argsCaptured) attributes[INPUT_VALUE] = stringifyTraceValue(span.args);
50
+ if (span.result !== void 0) attributes[OUTPUT_VALUE] = stringifyTraceValue(span.result);
51
+ return attributes;
52
+ }
53
+ function applyToolSpanOtlpAttributes(attributes, span) {
54
+ for (const key of TOOL_SPAN_ATTRIBUTE_KEYS) delete attributes[key];
55
+ Object.assign(attributes, toolSpanOtlpAttributes(span));
56
+ }
57
+ function traceSpanKindToOpenInferenceKind(kind) {
58
+ switch (kind) {
59
+ case "llm": return "LLM";
60
+ case "tool": return "TOOL";
61
+ case "retrieval": return "CHAIN";
62
+ case "judge": return "EVALUATOR";
63
+ case "sandbox": return "CHAIN";
64
+ case "agent": return "AGENT";
65
+ default: return "SPAN";
66
+ }
67
+ }
68
+ function firstStringAttribute(attributes, keys) {
69
+ for (const key of keys) {
70
+ const value = attributes[key];
71
+ if (typeof value === "string" && value.length > 0) return value;
72
+ }
73
+ }
74
+ function stringifyTraceValue(value) {
75
+ if (value === void 0) return "null";
76
+ if (typeof value === "string") return value;
77
+ try {
78
+ return JSON.stringify(value) ?? String(value);
79
+ } catch {
80
+ return String(value);
81
+ }
82
+ }
83
+ //#endregion
84
+ //#region src/trace-analyst/otlp-span.ts
85
+ /**
86
+ * Canonical OTLP-flat-line readers shared by every consumer of the
87
+ * OTLP-JSONL wire shape (one OTLP span per line; the form
88
+ * `flattenOtlpExportToNdjson` produces and the form AppWorld / HALO
89
+ * emit via their OpenInference OTLP exporter).
90
+ *
91
+ * `OtlpFileTraceStore` indexes spans with these; `otlpToRunRecords`
92
+ * aggregates spans into `RunRecord`s with the same readers. One parser,
93
+ * one vocabulary — a divergence between the analyst's view of a trace and
94
+ * the RunRecord projected from it is a class of bug this consolidation
95
+ * removes by construction.
96
+ *
97
+ * Vocabulary. The readers understand BOTH dialects that appear in the
98
+ * wild:
99
+ * - the substrate's own `llm.*` / `tool.*` / `span.kind` attributes
100
+ * (`flattenSpanAttributes` in `trace/otel.ts`), and
101
+ * - the OpenInference / inference-export attributes AppWorld / HALO
102
+ * emit (`openinference.span.kind`, `inference.observation_kind`,
103
+ * `inference.llm.input_tokens`, `llm.token_count.prompt`, …).
104
+ *
105
+ * Pure, no I/O.
106
+ */
107
+ /**
108
+ * Project one parsed OTLP-JSONL object to `ProjectedOtlpSpan`, or `null`
109
+ * when the line is missing the mandatory `trace_id` + `span_id`.
110
+ */
111
+ function projectOtlpFlatLine(raw) {
112
+ const trace_id = stringField(raw, "trace_id") ?? stringField(raw, "traceId");
113
+ const span_id = stringField(raw, "span_id") ?? stringField(raw, "spanId");
114
+ if (!trace_id || !span_id) return null;
115
+ const parent_id = normalizeParentSpanId(trace_id, span_id, stringField(raw, "parent_span_id") ?? stringField(raw, "parentSpanId") ?? null);
116
+ const name = stringField(raw, "name") ?? "unknown";
117
+ const start_time = stringField(raw, "start_time") ?? stringField(raw, "startTime") ?? "";
118
+ const end_time = stringField(raw, "end_time") ?? stringField(raw, "endTime") ?? start_time;
119
+ const status = readOtlpStatus(raw);
120
+ const attributes = extractOtlpAttributes(raw);
121
+ const service_name = asString(attributes["service.name"]) ?? asString(attributes["resource.attributes.service.name"]) ?? null;
122
+ const agent_name = asString(attributes["agent.name"]) ?? asString(attributes["inference.agent.name"]) ?? asString(attributes["inference.agent_name"]) ?? null;
123
+ const model_name = firstStringAttr(attributes, LLM_MODEL_ATTR_KEYS);
124
+ const tool_name = firstStringAttr(attributes, TOOL_NAME_ATTR_KEYS);
125
+ const kind = inferOtlpKind(attributes);
126
+ let duration_ms = 0;
127
+ if (start_time && end_time) {
128
+ const a = spanEpochMillis(start_time);
129
+ const b = spanEpochMillis(end_time);
130
+ if (a !== null && b !== null) duration_ms = Math.max(0, b - a);
131
+ }
132
+ return {
133
+ trace_id,
134
+ span_id,
135
+ parent_span_id: parent_id && parent_id.length > 0 ? parent_id : null,
136
+ name,
137
+ kind,
138
+ start_time,
139
+ end_time,
140
+ duration_ms,
141
+ status: status.code,
142
+ status_message: status.message,
143
+ service_name,
144
+ agent_name,
145
+ model_name,
146
+ tool_name,
147
+ attributes
148
+ };
149
+ }
150
+ function normalizeParentSpanId(traceId, spanId, parentId) {
151
+ if (!parentId) return null;
152
+ const prefix = `${traceId}:`;
153
+ return spanId.startsWith(prefix) && !parentId.startsWith(prefix) ? `${prefix}${parentId}` : parentId;
154
+ }
155
+ function readOtlpStatus(raw) {
156
+ const status = raw.status;
157
+ if (status && typeof status === "object" && !Array.isArray(status)) {
158
+ const codeRaw = status.code;
159
+ const code = codeRaw === "STATUS_CODE_OK" || codeRaw === "OK" ? "OK" : codeRaw === "STATUS_CODE_ERROR" || codeRaw === "ERROR" ? "ERROR" : "UNSET";
160
+ const messageRaw = status.message;
161
+ return {
162
+ code,
163
+ message: typeof messageRaw === "string" && messageRaw.length > 0 ? messageRaw : void 0
164
+ };
165
+ }
166
+ return {
167
+ code: "UNSET",
168
+ message: void 0
169
+ };
170
+ }
171
+ function inferOtlpKind(attrs) {
172
+ const opik = firstStringAttr(attrs, SPAN_KIND_ATTR_KEYS);
173
+ if (opik) {
174
+ const upper = opik.toUpperCase();
175
+ if (upper === "AGENT" || upper === "LLM" || upper === "TOOL" || upper === "CHAIN" || upper === "EVALUATOR" || upper === "GUARDRAIL" || upper === "SPAN") return upper;
176
+ }
177
+ return "UNKNOWN";
178
+ }
179
+ /**
180
+ * Flatten OTLP `attributes` + `resource.attributes` into a single
181
+ * dotted-key map. Span attributes override resource attributes when keys
182
+ * overlap. Nested objects/arrays are preserved as-is.
183
+ */
184
+ function extractOtlpAttributes(raw) {
185
+ const out = {};
186
+ const resource = raw.resource;
187
+ if (resource && typeof resource === "object" && !Array.isArray(resource)) {
188
+ const ra = resource.attributes;
189
+ if (ra && typeof ra === "object" && !Array.isArray(ra)) for (const [k, v] of Object.entries(ra)) out[k] = v;
190
+ }
191
+ const spanAttrs = raw.attributes;
192
+ if (spanAttrs && typeof spanAttrs === "object" && !Array.isArray(spanAttrs)) for (const [k, v] of Object.entries(spanAttrs)) out[k] = v;
193
+ return out;
194
+ }
195
+ function stringField(raw, key) {
196
+ const v = raw[key];
197
+ return typeof v === "string" ? v : void 0;
198
+ }
199
+ function asString(v) {
200
+ return typeof v === "string" && v.length > 0 ? v : null;
201
+ }
202
+ /** First non-empty string value across a list of candidate attribute keys. */
203
+ function firstStringAttr(attrs, keys) {
204
+ for (const k of keys) {
205
+ const s = asString(attrs[k]);
206
+ if (s !== null) return s;
207
+ }
208
+ return null;
209
+ }
210
+ /**
211
+ * Parse a span timestamp to epoch millis, or null when empty/unparseable. The
212
+ * OTLP readers accept BOTH ISO-8601 and epoch-millis-string dialects, so raw
213
+ * string comparison (`<`, `localeCompare`) mis-orders across dialects and
214
+ * `Date.parse` returns NaN for a bare epoch-millis string.
215
+ */
216
+ function spanEpochMillis(ts) {
217
+ if (!ts) return null;
218
+ if (/^\d+$/.test(ts)) return Number(ts);
219
+ const n = Date.parse(ts);
220
+ return Number.isNaN(n) ? null : n;
221
+ }
222
+ /**
223
+ * Order comparator for span timestamps across mixed ISO/epoch dialects.
224
+ * Unparseable timestamps sort as epoch 0 (earliest), never NaN (which would
225
+ * make the sort non-deterministic).
226
+ */
227
+ function compareSpanTime(a, b) {
228
+ return (spanEpochMillis(a) ?? 0) - (spanEpochMillis(b) ?? 0);
229
+ }
230
+ //#endregion
231
+ //#region src/trace-analyst/store.ts
232
+ /** Compile a regex with the same anchoring + flags semantics across
233
+ * implementations. Throws on invalid pattern — callers should surface
234
+ * that to the agent so it can refine instead of looping. */
235
+ function compileSearchRegex(pattern) {
236
+ let source = pattern;
237
+ let flags = "m";
238
+ if (source.startsWith("(?i)")) {
239
+ source = source.slice(4);
240
+ flags += "i";
241
+ }
242
+ return new RegExp(source, flags);
243
+ }
244
+ /** Truncate string payload deterministically for tool responses.
245
+ * Marker is parseable so downstream consumers can detect truncation
246
+ * and decide whether to fetch surgically. */
247
+ function truncateForBudget(value, byteCap) {
248
+ const original = Buffer.byteLength(value, "utf8");
249
+ if (original <= byteCap) return value;
250
+ const ratio = byteCap / original;
251
+ let cut = Math.max(0, Math.floor(value.length * ratio));
252
+ while (cut > 0 && Buffer.byteLength(value.slice(0, cut), "utf8") > byteCap) cut -= 1;
253
+ return `${value.slice(0, cut)}\n[trace-analyst truncated: original ${original} bytes]`;
254
+ }
255
+ //#endregion
256
+ //#region src/trace-analyst/types.ts
257
+ const DEFAULT_TRACE_ANALYST_BUDGETS = {
258
+ perCallByteCeiling: 15e4,
259
+ perAttributeViewBudget: 4096,
260
+ perAttributeSpanBudget: 16384,
261
+ perMatchTextBudget: 1024
262
+ };
263
+ /** Marker substituted in place of truncated string payloads. Callers
264
+ * parsing tool output can detect it deterministically. */
265
+ const TRACE_ANALYST_TRUNCATION_MARKER_PREFIX = "[trace-analyst truncated:";
266
+ //#endregion
267
+ //#region src/trace-analyst/store-otlp.ts
268
+ /**
269
+ * `OtlpFileTraceStore` — read-only OTLP-JSONL trace store for the
270
+ * trace-analyst.
271
+ *
272
+ * Wire shape. Each line of the input file is one OTLP-shaped span. The
273
+ * store understands flattened OTLP JSONL plus the OpenInference vocab.
274
+ * We project upstream's full
275
+ * span shape down to `TraceAnalystSpan` lazily — full materialisation
276
+ * only happens for the spans the agent actually requests.
277
+ *
278
+ * Indexing. On first read the store builds an in-memory index keyed
279
+ * by `trace_id` carrying:
280
+ * - byte offsets + lengths for each span line (for surgical reads
281
+ * without re-parsing the whole file)
282
+ * - a `TraceAnalystTraceSummary` rollup
283
+ * - sets of services / agents / models / tools / has_errors
284
+ * - byte size of the trace's JSONL slab
285
+ *
286
+ * Memory bound. The index keeps span metadata only — names, kinds,
287
+ * offsets, status. Attribute payloads stay on disk until requested.
288
+ * For a 50MB JSONL with 50k spans, the index is ~5MB.
289
+ *
290
+ * Concurrency. The store builds the index once on first read and
291
+ * caches it. Subsequent reads reuse the index. The file is opened on
292
+ * each read; we never hold a long-lived FD.
293
+ */
294
+ /** Lines indexed between event-loop yields. Bounded synchronous work per
295
+ * tick keeps the index build from starving other tasks on large files
296
+ * while staying coarse enough that the yields are cheap. */
297
+ const INDEX_YIELD_LINES = 5e3;
298
+ /** Hand control back to the event loop without busy-waiting. */
299
+ function yieldToEventLoop() {
300
+ return new Promise((resolve) => setImmediate(resolve));
301
+ }
302
+ var OtlpFileTraceStore = class {
303
+ path;
304
+ perAttributeViewBudget;
305
+ perAttributeSpanBudget;
306
+ perCallByteCeiling;
307
+ perMatchTextBudget;
308
+ maxFileBytes;
309
+ indexPromise;
310
+ /** Cached UTF-8 buffer of the file. We pin it once because every
311
+ * read needs slice access and re-reading on each call balloons the
312
+ * syscall count. */
313
+ bufferPromise;
314
+ constructor(opts) {
315
+ this.path = opts.path;
316
+ this.perAttributeViewBudget = opts.perAttributeViewBudget ?? DEFAULT_TRACE_ANALYST_BUDGETS.perAttributeViewBudget;
317
+ this.perAttributeSpanBudget = opts.perAttributeSpanBudget ?? DEFAULT_TRACE_ANALYST_BUDGETS.perAttributeSpanBudget;
318
+ this.perCallByteCeiling = opts.perCallByteCeiling ?? DEFAULT_TRACE_ANALYST_BUDGETS.perCallByteCeiling;
319
+ this.perMatchTextBudget = opts.perMatchTextBudget ?? DEFAULT_TRACE_ANALYST_BUDGETS.perMatchTextBudget;
320
+ this.maxFileBytes = opts.maxFileBytes ?? 268435456;
321
+ }
322
+ async getOverview(filters) {
323
+ const idx = await this.index();
324
+ const matched = await this.matchedTraces(idx, filters);
325
+ const services = /* @__PURE__ */ new Set();
326
+ const agents = /* @__PURE__ */ new Set();
327
+ const models = /* @__PURE__ */ new Set();
328
+ const tools = /* @__PURE__ */ new Set();
329
+ let rawBytes = 0;
330
+ let earliest = null;
331
+ let latest = null;
332
+ let errorTraceCount = 0;
333
+ let errorSpanCount = 0;
334
+ const clusters = /* @__PURE__ */ new Map();
335
+ for (const t of matched) {
336
+ if (t.service_name) services.add(t.service_name);
337
+ if (t.agent_name) agents.add(t.agent_name);
338
+ for (const m of t.models) models.add(m);
339
+ for (const tn of t.tools) tools.add(tn);
340
+ rawBytes += t.raw_jsonl_bytes;
341
+ if (!earliest || compareSpanTime(t.start_time, earliest) < 0) earliest = t.start_time;
342
+ if (!latest || compareSpanTime(t.end_time, latest) > 0) latest = t.end_time;
343
+ if (t.has_errors) {
344
+ errorTraceCount += 1;
345
+ for (const s of t.spans) {
346
+ if (s.status !== "ERROR") continue;
347
+ errorSpanCount += 1;
348
+ accumulateErrorCluster(clusters, t.trace_id, s);
349
+ }
350
+ }
351
+ }
352
+ const sample_trace_ids = matched.slice(0, 20).map((t) => t.trace_id);
353
+ return {
354
+ total_traces: matched.length,
355
+ raw_jsonl_bytes: rawBytes,
356
+ services: [...services].sort(),
357
+ agents: [...agents].sort(),
358
+ models: [...models].sort(),
359
+ tool_names: [...tools].sort(),
360
+ sample_trace_ids,
361
+ errors: {
362
+ trace_count: errorTraceCount,
363
+ span_count: errorSpanCount
364
+ },
365
+ error_clusters: finalizeErrorClusters(clusters, errorTraceCount),
366
+ time_range: earliest && latest ? {
367
+ earliest,
368
+ latest
369
+ } : null
370
+ };
371
+ }
372
+ async queryTraces(opts) {
373
+ if (!Number.isInteger(opts.limit) || opts.limit < 1 || opts.limit > 200) throw new RangeError(`queryTraces.limit must be 1..200, got ${opts.limit}`);
374
+ const offset = opts.offset ?? 0;
375
+ if (!Number.isInteger(offset) || offset < 0) throw new RangeError(`queryTraces.offset must be >=0, got ${offset}`);
376
+ const idx = await this.index();
377
+ const matched = await this.matchedTraces(idx, opts.filters);
378
+ const slice = matched.slice(offset, offset + opts.limit);
379
+ return {
380
+ traces: slice.map((t) => this.toSummary(t)),
381
+ total: matched.length,
382
+ has_more: offset + slice.length < matched.length
383
+ };
384
+ }
385
+ async countTraces(filters) {
386
+ const idx = await this.index();
387
+ return (await this.matchedTraces(idx, filters)).length;
388
+ }
389
+ async viewTrace(opts) {
390
+ const trace = (await this.index()).byTrace.get(opts.trace_id);
391
+ if (!trace) throw new TraceNotFoundError(opts.trace_id);
392
+ const cap = opts.per_attribute_byte_cap ?? this.perAttributeViewBudget;
393
+ const buf = await this.buffer();
394
+ const spans = [];
395
+ let runningBytes = 0;
396
+ let span_response_bytes_max = 0;
397
+ const counter = { value: 0 };
398
+ for (const s of trace.spans) {
399
+ const projected = this.projectSpan(buf, trace.trace_id, s, cap, counter);
400
+ const bytes = Buffer.byteLength(JSON.stringify(projected), "utf8");
401
+ span_response_bytes_max = Math.max(span_response_bytes_max, bytes);
402
+ runningBytes += bytes;
403
+ if (runningBytes > this.perCallByteCeiling) return {
404
+ trace_id: trace.trace_id,
405
+ oversized: this.buildOversizedSummary(trace, span_response_bytes_max)
406
+ };
407
+ spans.push(projected);
408
+ }
409
+ return {
410
+ trace_id: trace.trace_id,
411
+ spans
412
+ };
413
+ }
414
+ async viewSpans(opts) {
415
+ const trace = (await this.index()).byTrace.get(opts.trace_id);
416
+ if (!trace) throw new TraceNotFoundError(opts.trace_id);
417
+ if (opts.span_ids.length === 0) return {
418
+ trace_id: trace.trace_id,
419
+ spans: [],
420
+ missing_span_ids: [],
421
+ truncated_attribute_count: 0
422
+ };
423
+ if (opts.span_ids.length > 100) throw new RangeError(`viewSpans.span_ids cap is 100, got ${opts.span_ids.length}`);
424
+ const cap = opts.per_attribute_byte_cap ?? this.perAttributeSpanBudget;
425
+ const wantSet = new Set(opts.span_ids);
426
+ const found = trace.spans.filter((s) => wantSet.has(s.span_id));
427
+ const missing = opts.span_ids.filter((id) => !found.some((f) => f.span_id === id));
428
+ const buf = await this.buffer();
429
+ const spans = [];
430
+ const counter = { value: 0 };
431
+ let runningBytes = 0;
432
+ for (const s of found) {
433
+ const projected = this.projectSpan(buf, trace.trace_id, s, cap, counter);
434
+ const bytes = Buffer.byteLength(JSON.stringify(projected), "utf8");
435
+ runningBytes += bytes;
436
+ if (runningBytes > this.perCallByteCeiling) break;
437
+ spans.push(projected);
438
+ }
439
+ return {
440
+ trace_id: trace.trace_id,
441
+ spans,
442
+ missing_span_ids: missing,
443
+ truncated_attribute_count: counter.value
444
+ };
445
+ }
446
+ async searchTrace(opts) {
447
+ const max_matches = opts.max_matches ?? 50;
448
+ if (!Number.isInteger(max_matches) || max_matches < 1 || max_matches > 500) throw new RangeError(`searchTrace.max_matches must be 1..500, got ${max_matches}`);
449
+ const trace = (await this.index()).byTrace.get(opts.trace_id);
450
+ if (!trace) throw new TraceNotFoundError(opts.trace_id);
451
+ const re = compileSearchRegex(opts.regex_pattern);
452
+ const buf = await this.buffer();
453
+ const hits = [];
454
+ let total = 0;
455
+ let capped = false;
456
+ for (const s of trace.spans) {
457
+ const remaining = max_matches - hits.length;
458
+ const localHits = await this.scanSpanForMatches(buf, trace.trace_id, s, re, this.perMatchTextBudget, remaining);
459
+ total += localHits.total;
460
+ for (const h of localHits.records) {
461
+ if (hits.length >= max_matches) break;
462
+ hits.push(h);
463
+ }
464
+ if (hits.length >= max_matches) {
465
+ capped = true;
466
+ break;
467
+ }
468
+ }
469
+ return {
470
+ trace_id: trace.trace_id,
471
+ hits,
472
+ total_matches: capped ? hits.length : total,
473
+ has_more: capped || total > hits.length
474
+ };
475
+ }
476
+ async searchSpan(opts) {
477
+ const max_matches = opts.max_matches ?? 50;
478
+ if (!Number.isInteger(max_matches) || max_matches < 1 || max_matches > 500) throw new RangeError(`searchSpan.max_matches must be 1..500, got ${max_matches}`);
479
+ const trace = (await this.index()).byTrace.get(opts.trace_id);
480
+ if (!trace) throw new TraceNotFoundError(opts.trace_id);
481
+ const span = trace.spans.find((s) => s.span_id === opts.span_id);
482
+ if (!span) throw new SpanNotFoundError(opts.trace_id, opts.span_id);
483
+ const re = compileSearchRegex(opts.regex_pattern);
484
+ const buf = await this.buffer();
485
+ const localHits = await this.scanSpanForMatches(buf, trace.trace_id, span, re, this.perMatchTextBudget, max_matches);
486
+ return {
487
+ trace_id: trace.trace_id,
488
+ span_id: span.span_id,
489
+ hits: localHits.records,
490
+ total_matches: localHits.total,
491
+ has_more: localHits.total > localHits.records.length
492
+ };
493
+ }
494
+ /** Force the index to materialise. Useful to amortise startup cost
495
+ * before the first agent call. */
496
+ async ensureIndexed() {
497
+ await this.index();
498
+ }
499
+ async buffer() {
500
+ if (!this.bufferPromise) this.bufferPromise = this.readGuarded();
501
+ return this.bufferPromise;
502
+ }
503
+ /** Stat-then-read so an oversized file fails loud BEFORE we allocate a
504
+ * multi-hundred-MB Buffer and OOM the process. A missing file surfaces
505
+ * as TraceFileMissingError; any other stat/read error propagates. */
506
+ async readGuarded() {
507
+ let stats;
508
+ try {
509
+ stats = await stat(this.path);
510
+ } catch (err) {
511
+ if (err?.code === "ENOENT") throw new TraceFileMissingError(this.path);
512
+ throw err;
513
+ }
514
+ if (stats.size > this.maxFileBytes) throw new TraceFileTooLargeError(this.path, stats.size, this.maxFileBytes);
515
+ return readFile(this.path);
516
+ }
517
+ async index() {
518
+ if (!this.indexPromise) this.indexPromise = this.buildIndex();
519
+ return this.indexPromise;
520
+ }
521
+ async buildIndex() {
522
+ const buf = await this.buffer();
523
+ const byTrace = /* @__PURE__ */ new Map();
524
+ let cursor = 0;
525
+ let sinceYield = 0;
526
+ while (cursor < buf.length) {
527
+ if (++sinceYield >= INDEX_YIELD_LINES) {
528
+ sinceYield = 0;
529
+ await yieldToEventLoop();
530
+ }
531
+ const newlineIndex = buf.indexOf(10, cursor);
532
+ const lineEnd = newlineIndex === -1 ? buf.length : newlineIndex;
533
+ const lineLength = lineEnd - cursor;
534
+ if (lineLength === 0) {
535
+ cursor = lineEnd + 1;
536
+ continue;
537
+ }
538
+ const lineSlice = buf.subarray(cursor, lineEnd).toString("utf8");
539
+ const lineOffset = cursor;
540
+ cursor = lineEnd + 1;
541
+ let parsed;
542
+ try {
543
+ parsed = JSON.parse(lineSlice);
544
+ } catch {
545
+ continue;
546
+ }
547
+ if (!parsed || typeof parsed !== "object") continue;
548
+ const span = projectOtlpFlatLine(parsed);
549
+ if (!span) continue;
550
+ let entry = byTrace.get(span.trace_id);
551
+ if (!entry) {
552
+ entry = {
553
+ trace_id: span.trace_id,
554
+ service_name: span.service_name,
555
+ agent_name: span.agent_name,
556
+ span_count: 0,
557
+ has_errors: false,
558
+ start_time: span.start_time,
559
+ end_time: span.end_time,
560
+ duration_ms: 0,
561
+ raw_jsonl_bytes: 0,
562
+ models: /* @__PURE__ */ new Set(),
563
+ tools: /* @__PURE__ */ new Set(),
564
+ spans: []
565
+ };
566
+ byTrace.set(span.trace_id, entry);
567
+ } else {
568
+ if (!entry.service_name && span.service_name) entry.service_name = span.service_name;
569
+ if (!entry.agent_name && span.agent_name) entry.agent_name = span.agent_name;
570
+ }
571
+ const indexEntry = {
572
+ span_id: span.span_id,
573
+ parent_span_id: span.parent_span_id,
574
+ name: span.name,
575
+ kind: span.kind,
576
+ start_time: span.start_time,
577
+ end_time: span.end_time,
578
+ duration_ms: span.duration_ms,
579
+ status: span.status,
580
+ status_message: span.status_message,
581
+ service_name: span.service_name,
582
+ agent_name: span.agent_name,
583
+ model_name: span.model_name,
584
+ tool_name: span.tool_name,
585
+ line_byte_offset: lineOffset,
586
+ line_byte_length: lineLength
587
+ };
588
+ entry.spans.push(indexEntry);
589
+ entry.span_count += 1;
590
+ entry.raw_jsonl_bytes += lineLength + 1;
591
+ if (span.status === "ERROR") entry.has_errors = true;
592
+ if (compareSpanTime(span.start_time, entry.start_time) < 0) entry.start_time = span.start_time;
593
+ if (compareSpanTime(span.end_time, entry.end_time) > 0) entry.end_time = span.end_time;
594
+ if (span.model_name) entry.models.add(span.model_name);
595
+ if (span.tool_name) entry.tools.add(span.tool_name);
596
+ }
597
+ let totalRawBytes = 0;
598
+ for (const t of byTrace.values()) {
599
+ totalRawBytes += t.raw_jsonl_bytes;
600
+ t.spans.sort((a, b) => compareSpanTime(a.start_time, b.start_time) || a.line_byte_offset - b.line_byte_offset);
601
+ const startMs = spanEpochMillis(t.start_time);
602
+ const endMs = spanEpochMillis(t.end_time);
603
+ t.duration_ms = startMs === null || endMs === null ? 0 : Math.max(0, endMs - startMs);
604
+ }
605
+ const sortedTraceIds = [...byTrace.keys()].sort();
606
+ return {
607
+ byTrace,
608
+ totalRawBytes,
609
+ sortedTraceIds
610
+ };
611
+ }
612
+ async matchedTraces(idx, filters) {
613
+ const traces = idx.sortedTraceIds.map((id) => idx.byTrace.get(id)).filter(isPresent);
614
+ if (!filters) return traces;
615
+ const indexedFiltered = traces.filter((t) => {
616
+ if (filters.has_errors !== void 0 && t.has_errors !== filters.has_errors) return false;
617
+ if (filters.service_names && filters.service_names.length > 0) {
618
+ if (!t.service_name || !filters.service_names.includes(t.service_name)) return false;
619
+ }
620
+ if (filters.agent_names && filters.agent_names.length > 0) {
621
+ if (!t.agent_name || !filters.agent_names.includes(t.agent_name)) return false;
622
+ }
623
+ if (filters.model_names && filters.model_names.length > 0) {
624
+ if (![...t.models].some((m) => filters.model_names.includes(m))) return false;
625
+ }
626
+ if (filters.tool_names && filters.tool_names.length > 0) {
627
+ if (![...t.tools].some((tn) => filters.tool_names.includes(tn))) return false;
628
+ }
629
+ if (filters.start_time_after && t.start_time < filters.start_time_after) return false;
630
+ if (filters.start_time_before && t.start_time > filters.start_time_before) return false;
631
+ return true;
632
+ });
633
+ if (!filters.regex_pattern) return indexedFiltered;
634
+ const re = compileSearchRegex(filters.regex_pattern);
635
+ const buf = await this.buffer();
636
+ const out = [];
637
+ for (const t of indexedFiltered) {
638
+ let matched = false;
639
+ for (const s of t.spans) {
640
+ const slice = buf.subarray(s.line_byte_offset, s.line_byte_offset + s.line_byte_length);
641
+ if (re.test(slice.toString("utf8"))) {
642
+ matched = true;
643
+ break;
644
+ }
645
+ }
646
+ if (matched) out.push(t);
647
+ }
648
+ return out;
649
+ }
650
+ toSummary(t) {
651
+ return {
652
+ trace_id: t.trace_id,
653
+ service_name: t.service_name,
654
+ agent_name: t.agent_name,
655
+ span_count: t.span_count,
656
+ has_errors: t.has_errors,
657
+ start_time: t.start_time,
658
+ end_time: t.end_time,
659
+ duration_ms: t.duration_ms,
660
+ raw_jsonl_bytes: t.raw_jsonl_bytes,
661
+ models: [...t.models].sort(),
662
+ tools: [...t.tools].sort()
663
+ };
664
+ }
665
+ projectSpan(buf, trace_id, s, perAttrCap, counter) {
666
+ const slice = buf.subarray(s.line_byte_offset, s.line_byte_offset + s.line_byte_length).toString("utf8");
667
+ let raw = {};
668
+ try {
669
+ const parsed = JSON.parse(slice);
670
+ if (parsed && typeof parsed === "object") raw = parsed;
671
+ } catch {}
672
+ const attrs = extractOtlpAttributes(raw);
673
+ const projected = {};
674
+ for (const [k, v] of Object.entries(attrs)) if (typeof v === "string") {
675
+ const trunc = truncateForBudget(v, perAttrCap);
676
+ if (trunc !== v) counter.value += 1;
677
+ projected[k] = trunc;
678
+ } else if (Array.isArray(v) || v && typeof v === "object") {
679
+ const json = JSON.stringify(v);
680
+ const trunc = truncateForBudget(json, perAttrCap);
681
+ if (trunc !== json) {
682
+ counter.value += 1;
683
+ projected[k] = trunc;
684
+ } else projected[k] = v;
685
+ } else projected[k] = v;
686
+ return {
687
+ trace_id,
688
+ span_id: s.span_id,
689
+ parent_span_id: s.parent_span_id,
690
+ name: s.name,
691
+ kind: s.kind,
692
+ start_time: s.start_time,
693
+ end_time: s.end_time,
694
+ duration_ms: s.duration_ms,
695
+ status: s.status,
696
+ status_message: s.status_message,
697
+ service_name: s.service_name,
698
+ agent_name: s.agent_name,
699
+ model_name: s.model_name,
700
+ tool_name: s.tool_name,
701
+ attributes: projected
702
+ };
703
+ }
704
+ buildOversizedSummary(t, span_response_bytes_max) {
705
+ const counts = /* @__PURE__ */ new Map();
706
+ let errorCount = 0;
707
+ for (const s of t.spans) {
708
+ counts.set(s.name, (counts.get(s.name) ?? 0) + 1);
709
+ if (s.status === "ERROR") errorCount += 1;
710
+ }
711
+ const top = [...counts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 20);
712
+ return {
713
+ span_count: t.span_count,
714
+ top_span_names: top,
715
+ span_response_bytes_max,
716
+ error_span_count: errorCount
717
+ };
718
+ }
719
+ async scanSpanForMatches(buf, trace_id, s, re, textBudget, recordCap) {
720
+ const slice = buf.subarray(s.line_byte_offset, s.line_byte_offset + s.line_byte_length).toString("utf8");
721
+ const records = [];
722
+ const globalRe = new RegExp(re.source, re.flags.includes("g") ? re.flags : `${re.flags}g`);
723
+ let total = 0;
724
+ let hasMore = false;
725
+ let m = globalRe.exec(slice);
726
+ while (m !== null) {
727
+ total += 1;
728
+ if (m.index === globalRe.lastIndex) globalRe.lastIndex += 1;
729
+ if (records.length >= recordCap) {
730
+ hasMore = true;
731
+ break;
732
+ }
733
+ const before = slice.slice(Math.max(0, m.index - textBudget / 2), m.index);
734
+ const after = slice.slice(m.index + m[0].length, m.index + m[0].length + Math.floor(textBudget / 2));
735
+ records.push({
736
+ trace_id,
737
+ span_id: s.span_id,
738
+ span_name: s.name,
739
+ span_kind: s.kind,
740
+ attribute_path: bestAttributePathForOffset(slice, m.index) ?? "span.raw",
741
+ matched_text: truncateForBudget(m[0], textBudget),
742
+ context_before: truncateForBudget(before, textBudget),
743
+ context_after: truncateForBudget(after, textBudget),
744
+ match_offset: m.index
745
+ });
746
+ m = globalRe.exec(slice);
747
+ }
748
+ return {
749
+ records,
750
+ total,
751
+ hasMore
752
+ };
753
+ }
754
+ };
755
+ var TraceFileMissingError = class extends NotFoundError {
756
+ constructor(path) {
757
+ super(`trace file not found: ${path}`);
758
+ }
759
+ };
760
+ var TraceFileTooLargeError = class extends Error {
761
+ path;
762
+ size_bytes;
763
+ max_bytes;
764
+ constructor(path, size_bytes, max_bytes) {
765
+ super(`trace file ${path} is ${size_bytes} bytes, over the ${max_bytes}-byte limit; raise OtlpFileTraceStoreOptions.maxFileBytes or pre-split the file`);
766
+ this.path = path;
767
+ this.size_bytes = size_bytes;
768
+ this.max_bytes = max_bytes;
769
+ }
770
+ };
771
+ var TraceNotFoundError = class extends NotFoundError {
772
+ trace_id;
773
+ constructor(trace_id) {
774
+ super(`trace not found: ${trace_id}`);
775
+ this.trace_id = trace_id;
776
+ }
777
+ };
778
+ var SpanNotFoundError = class extends NotFoundError {
779
+ trace_id;
780
+ span_id;
781
+ constructor(trace_id, span_id) {
782
+ super(`span ${span_id} not found in trace ${trace_id}`);
783
+ this.trace_id = trace_id;
784
+ this.span_id = span_id;
785
+ }
786
+ };
787
+ function isPresent(v) {
788
+ return v !== void 0;
789
+ }
790
+ /** A `"` at `idx` is a real JSON delimiter only when the run of `\`
791
+ * immediately preceding it is even-length; an odd run means the quote
792
+ * is escaped (`\"`) and is part of a string value, not a boundary. */
793
+ function isUnescapedQuote(slice, idx) {
794
+ if (slice[idx] !== "\"") return false;
795
+ let backslashes = 0;
796
+ let b = idx - 1;
797
+ while (b >= 0 && slice[b] === "\\") {
798
+ backslashes += 1;
799
+ b -= 1;
800
+ }
801
+ return backslashes % 2 === 0;
802
+ }
803
+ /** Scan backwards from `from` (inclusive) for the nearest UNescaped `"`.
804
+ * Returns its index, or -1 when none is found. */
805
+ function prevUnescapedQuote(slice, from) {
806
+ for (let i = from; i >= 0; i -= 1) if (slice[i] === "\"" && isUnescapedQuote(slice, i)) return i;
807
+ return -1;
808
+ }
809
+ /**
810
+ * Best-effort: locate the JSON path for the substring at `offset` in
811
+ * a single span's JSONL slice. The slice is '...,"key":"value..."' — we
812
+ * walk back from `offset` to the value-opening quote, past the `:`, to
813
+ * the key's closing then opening quote, skipping `\"`-escaped quotes that
814
+ * live inside string values. Returns `null` when the offset doesn't fall
815
+ * inside a recognisable string field.
816
+ */
817
+ function bestAttributePathForOffset(slice, offset) {
818
+ const valueQuote = prevUnescapedQuote(slice, Math.min(offset, slice.length - 1));
819
+ if (valueQuote < 1) return null;
820
+ let j = valueQuote - 1;
821
+ while (j >= 0 && slice[j] !== ":") j -= 1;
822
+ if (j < 1) return null;
823
+ const keyClose = prevUnescapedQuote(slice, j - 1);
824
+ if (keyClose < 1) return null;
825
+ const keyOpen = prevUnescapedQuote(slice, keyClose - 1);
826
+ if (keyOpen < 0) return null;
827
+ return slice.slice(keyOpen + 1, keyClose);
828
+ }
829
+ const ERROR_CLUSTER_MAX = 50;
830
+ const ERROR_CLUSTER_EXEMPLARS = 5;
831
+ const SIGNATURE_MAX_CHARS = 160;
832
+ /** Collapse volatile tokens so semantically identical failures share a key:
833
+ * hex/uuid ids → <id>, numbers → #, quoted/abs paths → <path>, durations →
834
+ * <dur>, whitespace collapsed. Empty/absent messages fall back to the span
835
+ * name so a no-message error still forms a real cluster. */
836
+ function normalizeErrorSignature(message, spanName) {
837
+ const raw = (message ?? "").trim();
838
+ const norm = (raw.length > 0 ? raw : `(${spanName || "error"} — no message)`).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();
839
+ return norm.length > SIGNATURE_MAX_CHARS ? `${norm.slice(0, SIGNATURE_MAX_CHARS)}…` : norm;
840
+ }
841
+ function bump(map, key) {
842
+ if (!key) return;
843
+ map.set(key, (map.get(key) ?? 0) + 1);
844
+ }
845
+ function topKey(map) {
846
+ let best = null;
847
+ let bestN = 0;
848
+ for (const [k, n] of map) if (n > bestN) {
849
+ best = k;
850
+ bestN = n;
851
+ }
852
+ return best;
853
+ }
854
+ function accumulateErrorCluster(clusters, traceId, span) {
855
+ const signature = normalizeErrorSignature(span.status_message, span.name);
856
+ let acc = clusters.get(signature);
857
+ if (!acc) {
858
+ acc = {
859
+ signature,
860
+ sample: (span.status_message ?? span.name ?? "").slice(0, 500),
861
+ traceIds: /* @__PURE__ */ new Set(),
862
+ spanIds: [],
863
+ spanCount: 0,
864
+ spanNames: /* @__PURE__ */ new Map(),
865
+ toolNames: /* @__PURE__ */ new Map()
866
+ };
867
+ clusters.set(signature, acc);
868
+ }
869
+ acc.traceIds.add(traceId);
870
+ acc.spanCount += 1;
871
+ if (acc.spanIds.length < ERROR_CLUSTER_EXEMPLARS && !acc.spanIds.includes(span.span_id)) acc.spanIds.push(span.span_id);
872
+ bump(acc.spanNames, span.name);
873
+ bump(acc.toolNames, span.tool_name);
874
+ }
875
+ function finalizeErrorClusters(clusters, errorTraceCount) {
876
+ const out = [...clusters.values()].map((acc) => ({
877
+ signature: acc.signature,
878
+ status_message_sample: acc.sample,
879
+ span_name: topKey(acc.spanNames),
880
+ tool_name: topKey(acc.toolNames),
881
+ trace_count: acc.traceIds.size,
882
+ span_count: acc.spanCount,
883
+ prevalence: errorTraceCount > 0 ? acc.traceIds.size / errorTraceCount : 0,
884
+ exemplar_trace_ids: [...acc.traceIds].slice(0, ERROR_CLUSTER_EXEMPLARS),
885
+ exemplar_span_ids: acc.spanIds.slice(0, ERROR_CLUSTER_EXEMPLARS)
886
+ }));
887
+ out.sort((a, b) => b.trace_count - a.trace_count || b.span_count - a.span_count);
888
+ return out.slice(0, ERROR_CLUSTER_MAX);
889
+ }
890
+ const 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.
891
+
892
+ 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.
893
+
894
+ When the analysis is complete, call \`await final(${JSON.stringify("Submit the completed trace analysis.")}, { report, findings })\` exactly once. Do not return a one-argument string from \`final(...)\`.`;
895
+ var TraceAnalysisTurnLimitError = class extends Error {
896
+ analystId;
897
+ maxTurns;
898
+ constructor(analystId, maxTurns, cause) {
899
+ super(`Trace analyst '${analystId}' reached maxTurns=${maxTurns} without a structured final result`, { cause });
900
+ this.name = "TraceAnalysisTurnLimitError";
901
+ this.analystId = analystId;
902
+ this.maxTurns = maxTurns;
903
+ }
904
+ };
905
+ async function runTraceAnalysisLoop(options) {
906
+ validateLoopLimits(options);
907
+ const config = {
908
+ agentIdentity: {
909
+ name: options.id,
910
+ description: options.description
911
+ },
912
+ contextFields: [],
913
+ runtime: new AxJSRuntime({
914
+ permissions: [],
915
+ blockDynamicImport: true,
916
+ allowedModules: [],
917
+ freezeIntrinsics: true,
918
+ blockShadowRealm: true,
919
+ preventGlobalThisExtensions: false
920
+ }),
921
+ maxSubAgentCalls: options.maxSubqueries,
922
+ maxTurns: options.maxTurns,
923
+ maxRuntimeChars: options.maxRuntimeChars,
924
+ maxBatchedLlmQueryConcurrency: options.maxParallelSubqueries,
925
+ promptLevel: "detailed",
926
+ contextPolicy: {
927
+ preset: "full",
928
+ budget: "balanced"
929
+ },
930
+ functions: options.tools,
931
+ executorOptions: {
932
+ description: `${options.prompt.trim()}\n\n${TRACE_ANALYSIS_COMPLETION_INSTRUCTION}`,
933
+ ...options.model ? { model: options.model } : {},
934
+ showThoughts: false,
935
+ thinkingTokenBudget: "none"
936
+ },
937
+ ...options.onTurn ? { actorTurnCallback: options.onTurn } : {},
938
+ bubbleErrors: [TraceFileMissingError]
939
+ };
940
+ const analyst = options.findingType === "string" ? agent("question:string -> report:string, findings:string[]", config) : agent("question:string -> report:string, findings:json[]", config);
941
+ const state = await analyst.executor.run(options.ai, { question: options.question }, options.signal ? { abortSignal: options.signal } : void 0);
942
+ let completed;
943
+ try {
944
+ completed = options.findingType === "string" ? readTraceAnalysisCompletion(state.executorResult, "string") : readTraceAnalysisCompletion(state.executorResult, "object");
945
+ } catch (error) {
946
+ if (state.turnCount >= options.maxTurns) throw new TraceAnalysisTurnLimitError(options.id, options.maxTurns, error);
947
+ throw new Error(`Trace analyst '${options.id}' stopped without a structured final result`, { cause: error });
948
+ }
949
+ return {
950
+ ...completed,
951
+ usage: analyst.executor.getUsage(),
952
+ chatLog: analyst.executor.getChatLog(),
953
+ turnCount: state.turnCount
954
+ };
955
+ }
956
+ function readTraceAnalysisCompletion(value, findingType) {
957
+ if (!value || typeof value !== "object") throw new Error("Trace analyst did not return a structured final result");
958
+ const completion = value;
959
+ if (completion.type !== "final" || !Array.isArray(completion.args) || completion.args.length !== 2 || completion.args[0] !== "Submit the completed trace analysis.") throw new Error("Trace analyst did not return a structured final result");
960
+ const payload = completion.args[1];
961
+ if (!payload || typeof payload !== "object") throw new Error("Trace analyst final result must contain report and findings");
962
+ const { report, findings } = payload;
963
+ if (typeof report !== "string" || !Array.isArray(findings)) throw new Error("Trace analyst final result must contain report and findings");
964
+ if (findingType === "string") {
965
+ if (findings.some((finding) => typeof finding !== "string")) throw new Error("Trace analyst final result must contain string findings");
966
+ return {
967
+ report,
968
+ findings
969
+ };
970
+ }
971
+ if (findings.some((finding) => !finding || typeof finding !== "object" || Array.isArray(finding))) throw new Error("Trace analyst final result must contain object findings");
972
+ return {
973
+ report,
974
+ findings
975
+ };
976
+ }
977
+ function validateLoopLimits(options) {
978
+ if (!Number.isSafeInteger(options.maxSubqueries) || options.maxSubqueries < 0) throw new TypeError("maxSubqueries must be a non-negative integer");
979
+ if (!Number.isSafeInteger(options.maxParallelSubqueries) || options.maxParallelSubqueries < 1) throw new TypeError("maxParallelSubqueries must be a positive integer");
980
+ }
981
+ //#endregion
982
+ //#region src/trace-analyst/tools.ts
983
+ const NAMESPACE = "traces";
984
+ const filtersField = f.json("Filter set. ALL fields are AND-composed. Leave empty to scan everything.").optional();
985
+ /**
986
+ * Build the trace-analyst function set. Pass the result into
987
+ * `agent(...).functions.local`.
988
+ */
989
+ function buildTraceAnalystTools(opts) {
990
+ const { store } = opts;
991
+ return [
992
+ fn("getDatasetOverview").description("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.").namespace(NAMESPACE).arg("filters", filtersField).returns(f.json("DatasetOverview")).handler(async ({ filters }) => store.getOverview(parseFilters(filters))).build(),
993
+ fn("queryTraces").description("Paginated trace summaries. Each summary carries raw_jsonl_bytes — use it to size traces BEFORE calling viewTrace. Narrow with indexed filters before adding regex_pattern.").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(async ({ filters, limit, offset }) => store.queryTraces({
994
+ filters: parseFilters(filters),
995
+ limit: assertPageLimit(limit),
996
+ offset: assertOffset(offset)
997
+ })).build(),
998
+ fn("countTraces").description("Count traces matching `filters`. Use as a cheap pre-flight before opting into a regex_pattern scan.").namespace(NAMESPACE).arg("filters", filtersField).returns(f.number("count")).handler(async ({ filters }) => store.countTraces(parseFilters(filters))).build(),
999
+ fn("viewTrace").description("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` — DO NOT retry with the same trace_id; switch to searchTrace / viewSpans.").namespace(NAMESPACE).arg("trace_id", f.string("Real trace id from a prior overview/query")).returns(f.json("ViewTraceResult")).handler(async ({ trace_id }) => store.viewTrace({ trace_id: assertString(trace_id, "trace_id") })).build(),
1000
+ fn("viewSpans").description("Surgical read of specific spans within a trace, with each attribute capped at ~16KB (4× the discovery cap). Use after searchTrace narrows to specific span_ids.").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(async ({ trace_id, span_ids }) => store.viewSpans({
1001
+ trace_id: assertString(trace_id, "trace_id"),
1002
+ span_ids: assertStringArray(span_ids, "span_ids")
1003
+ })).build(),
1004
+ fn("searchTrace").description("Regex search across all spans of one trace. Returns `{trace_id, hits: SpanMatchRecord[], total_matches, has_more}`. **Iterate `result.hits`, NOT `result.matches`** — 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.").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(async ({ trace_id, regex_pattern, max_matches }) => store.searchTrace({
1005
+ trace_id: assertString(trace_id, "trace_id"),
1006
+ regex_pattern: assertRegex(regex_pattern),
1007
+ max_matches: assertMaxMatches(max_matches)
1008
+ })).build(),
1009
+ fn("searchSpan").description("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}` — iterate `result.hits`, NOT `result.matches`.").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(async ({ trace_id, span_id, regex_pattern, max_matches }) => store.searchSpan({
1010
+ trace_id: assertString(trace_id, "trace_id"),
1011
+ span_id: assertString(span_id, "span_id"),
1012
+ regex_pattern: assertRegex(regex_pattern),
1013
+ max_matches: assertMaxMatches(max_matches)
1014
+ })).build()
1015
+ ];
1016
+ }
1017
+ /**
1018
+ * Convenience: same shape as `buildTraceAnalystTools` but returns the
1019
+ * grouped form expected when registering trace tools alongside other
1020
+ * agent function modules. */
1021
+ function traceAnalystFunctionGroup(opts) {
1022
+ return {
1023
+ namespace: NAMESPACE,
1024
+ title: "Trace Analysis",
1025
+ selectionCriteria: "Use for any inspection of OTLP-shaped trace data.",
1026
+ description: "Discovery → narrow → deep-read tools over a JSONL trace dataset. Always call getDatasetOverview first.",
1027
+ functions: buildTraceAnalystTools(opts)
1028
+ };
1029
+ }
1030
+ function parseFilters(input) {
1031
+ if (input == null) return void 0;
1032
+ if (typeof input !== "object" || Array.isArray(input)) throw new TypeError(`filters must be an object, got ${typeof input}`);
1033
+ const f = input;
1034
+ const out = {};
1035
+ if (typeof f.has_errors === "boolean") out.has_errors = f.has_errors;
1036
+ out.service_names = stringArrayOrUndefined(f.service_names, "service_names");
1037
+ out.agent_names = stringArrayOrUndefined(f.agent_names, "agent_names");
1038
+ out.model_names = stringArrayOrUndefined(f.model_names, "model_names");
1039
+ out.tool_names = stringArrayOrUndefined(f.tool_names, "tool_names");
1040
+ if (typeof f.start_time_after === "string") out.start_time_after = f.start_time_after;
1041
+ if (typeof f.start_time_before === "string") out.start_time_before = f.start_time_before;
1042
+ if (typeof f.regex_pattern === "string") {
1043
+ if (f.regex_pattern.length === 0) throw new TypeError("filters.regex_pattern cannot be empty");
1044
+ out.regex_pattern = f.regex_pattern;
1045
+ }
1046
+ return out;
1047
+ }
1048
+ function stringArrayOrUndefined(v, label) {
1049
+ if (v === void 0 || v === null) return void 0;
1050
+ if (!Array.isArray(v)) throw new TypeError(`${label} must be an array of strings`);
1051
+ if (v.some((x) => typeof x !== "string")) throw new TypeError(`${label} entries must be strings`);
1052
+ return v;
1053
+ }
1054
+ function assertPageLimit(limit) {
1055
+ if (typeof limit !== "number" || !Number.isInteger(limit) || limit < 1 || limit > 200) throw new RangeError(`limit must be an integer 1..200`);
1056
+ return limit;
1057
+ }
1058
+ function assertOffset(offset) {
1059
+ if (offset === void 0) return void 0;
1060
+ if (typeof offset !== "number" || !Number.isInteger(offset) || offset < 0) throw new RangeError(`offset must be a non-negative integer`);
1061
+ return offset;
1062
+ }
1063
+ function assertRegex(pattern) {
1064
+ if (typeof pattern !== "string" || pattern.length === 0) throw new TypeError(`regex_pattern must be a non-empty string`);
1065
+ new RegExp(pattern, "m");
1066
+ return pattern;
1067
+ }
1068
+ function assertMaxMatches(n) {
1069
+ if (n === void 0) return void 0;
1070
+ if (typeof n !== "number" || !Number.isInteger(n) || n < 1 || n > 500) throw new RangeError(`max_matches must be an integer 1..500`);
1071
+ return n;
1072
+ }
1073
+ function assertString(v, label) {
1074
+ if (typeof v !== "string" || v.length === 0) throw new TypeError(`${label} must be a non-empty string`);
1075
+ return v;
1076
+ }
1077
+ function assertStringArray(v, label) {
1078
+ if (!Array.isArray(v)) throw new TypeError(`${label} must be an array of strings`);
1079
+ if (v.some((x) => typeof x !== "string")) throw new TypeError(`${label} entries must be strings`);
1080
+ return v;
1081
+ }
1082
+ //#endregion
1083
+ export { traceSpanKindToOpenInferenceKind as S, spanEpochMillis as _, SpanNotFoundError as a, classifyOtlpSpanRole as b, DEFAULT_TRACE_ANALYST_BUDGETS as c, compareSpanTime as d, extractOtlpAttributes as f, readOtlpStatus as g, projectOtlpFlatLine as h, OtlpFileTraceStore as i, TRACE_ANALYST_TRUNCATION_MARKER_PREFIX as l, inferOtlpKind as m, traceAnalystFunctionGroup as n, TraceFileMissingError as o, firstStringAttr as p, runTraceAnalysisLoop as r, TraceNotFoundError as s, buildTraceAnalystTools as t, asString as u, stringField as v, isOtlpModelCall as x, applyToolSpanOtlpAttributes as y };
1084
+
1085
+ //# sourceMappingURL=tools-BmuN627J.js.map