@mastra/react 1.7.3-alpha.3 → 1.8.0-alpha.4

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 (510) hide show
  1. package/dist/accumulator-B1MuNX3j.js +1668 -0
  2. package/dist/accumulator-B1MuNX3j.js.map +1 -0
  3. package/dist/accumulator-CsUGDUHk.cjs +1709 -0
  4. package/dist/accumulator-CsUGDUHk.cjs.map +1 -0
  5. package/dist/agent/hooks.d.ts.map +1 -1
  6. package/dist/agent/user-message.d.ts +4 -0
  7. package/dist/agent/user-message.d.ts.map +1 -0
  8. package/dist/chat/index.cjs +3 -0
  9. package/dist/chat/index.d.ts +3 -0
  10. package/dist/chat/index.d.ts.map +1 -0
  11. package/dist/chat/index.js +2 -0
  12. package/dist/feedback-refetch-interval-DLHzQoVV.js +12 -0
  13. package/dist/feedback-refetch-interval-DLHzQoVV.js.map +1 -0
  14. package/dist/feedback-refetch-interval-XD5FVc2k.cjs +17 -0
  15. package/dist/feedback-refetch-interval-XD5FVc2k.cjs.map +1 -0
  16. package/dist/hooks/agents/index.cjs +988 -0
  17. package/dist/hooks/agents/index.cjs.map +1 -0
  18. package/dist/hooks/agents/index.d.ts +19 -0
  19. package/dist/hooks/agents/index.d.ts.map +1 -0
  20. package/dist/hooks/agents/index.js +952 -0
  21. package/dist/hooks/agents/index.js.map +1 -0
  22. package/dist/hooks/agents/is-model-not-allowed.d.ts +15 -0
  23. package/dist/hooks/agents/is-model-not-allowed.d.ts.map +1 -0
  24. package/dist/hooks/agents/use-agent-messages.d.ts +18 -0
  25. package/dist/hooks/agents/use-agent-messages.d.ts.map +1 -0
  26. package/dist/hooks/agents/use-agent-plan.d.ts +14 -0
  27. package/dist/hooks/agents/use-agent-plan.d.ts.map +1 -0
  28. package/dist/hooks/agents/use-agent-skills.d.ts +2021 -0
  29. package/dist/hooks/agents/use-agent-skills.d.ts.map +1 -0
  30. package/dist/hooks/agents/use-agent-versions.d.ts +72 -0
  31. package/dist/hooks/agents/use-agent-versions.d.ts.map +1 -0
  32. package/dist/hooks/agents/use-agent-working-memory.d.ts +11 -0
  33. package/dist/hooks/agents/use-agent-working-memory.d.ts.map +1 -0
  34. package/dist/hooks/agents/use-agent-workspace.d.ts +2022 -0
  35. package/dist/hooks/agents/use-agent-workspace.d.ts.map +1 -0
  36. package/dist/hooks/agents/use-agent.d.ts +12 -0
  37. package/dist/hooks/agents/use-agent.d.ts.map +1 -0
  38. package/dist/hooks/agents/use-agents-model-providers.d.ts +9 -0
  39. package/dist/hooks/agents/use-agents-model-providers.d.ts.map +1 -0
  40. package/dist/hooks/agents/use-agents.d.ts +28 -0
  41. package/dist/hooks/agents/use-agents.d.ts.map +1 -0
  42. package/dist/hooks/agents/use-background-tasks.d.ts +51 -0
  43. package/dist/hooks/agents/use-background-tasks.d.ts.map +1 -0
  44. package/dist/hooks/agents/use-browser-session-probe.d.ts +34 -0
  45. package/dist/hooks/agents/use-browser-session-probe.d.ts.map +1 -0
  46. package/dist/hooks/agents/use-channels.d.ts +34 -0
  47. package/dist/hooks/agents/use-channels.d.ts.map +1 -0
  48. package/dist/hooks/agents/use-close-browser.d.ts +17 -0
  49. package/dist/hooks/agents/use-close-browser.d.ts.map +1 -0
  50. package/dist/hooks/agents/use-execute-agent-tool.d.ts +14 -0
  51. package/dist/hooks/agents/use-execute-agent-tool.d.ts.map +1 -0
  52. package/dist/hooks/agents/use-preview-instructions.d.ts +20 -0
  53. package/dist/hooks/agents/use-preview-instructions.d.ts.map +1 -0
  54. package/dist/hooks/agents/use-stored-agents.d.ts +8023 -0
  55. package/dist/hooks/agents/use-stored-agents.d.ts.map +1 -0
  56. package/dist/hooks/agents/use-stored-skills.d.ts +8 -0
  57. package/dist/hooks/agents/use-stored-skills.d.ts.map +1 -0
  58. package/dist/hooks/auth/fetch-with-refresh.d.ts +28 -0
  59. package/dist/hooks/auth/fetch-with-refresh.d.ts.map +1 -0
  60. package/dist/hooks/auth/get-client-query-key.d.ts +7 -0
  61. package/dist/hooks/auth/get-client-query-key.d.ts.map +1 -0
  62. package/dist/hooks/auth/index.cjs +492 -0
  63. package/dist/hooks/auth/index.cjs.map +1 -0
  64. package/dist/hooks/auth/index.d.ts +11 -0
  65. package/dist/hooks/auth/index.d.ts.map +1 -0
  66. package/dist/hooks/auth/index.js +474 -0
  67. package/dist/hooks/auth/index.js.map +1 -0
  68. package/dist/hooks/auth/sso-login.d.ts +8 -0
  69. package/dist/hooks/auth/sso-login.d.ts.map +1 -0
  70. package/dist/hooks/auth/types.d.ts +107 -0
  71. package/dist/hooks/auth/types.d.ts.map +1 -0
  72. package/dist/hooks/auth/use-auth-actions.d.ts +99 -0
  73. package/dist/hooks/auth/use-auth-actions.d.ts.map +1 -0
  74. package/dist/hooks/auth/use-auth-capabilities.d.ts +43 -0
  75. package/dist/hooks/auth/use-auth-capabilities.d.ts.map +1 -0
  76. package/dist/hooks/auth/use-credentials-login.d.ts +63 -0
  77. package/dist/hooks/auth/use-credentials-login.d.ts.map +1 -0
  78. package/dist/hooks/auth/use-credentials-signup.d.ts +66 -0
  79. package/dist/hooks/auth/use-credentials-signup.d.ts.map +1 -0
  80. package/dist/hooks/auth/use-current-user.d.ts +40 -0
  81. package/dist/hooks/auth/use-current-user.d.ts.map +1 -0
  82. package/dist/hooks/auth/use-permission-patterns.d.ts +24 -0
  83. package/dist/hooks/auth/use-permission-patterns.d.ts.map +1 -0
  84. package/dist/hooks/capabilities/index.cjs +47 -0
  85. package/dist/hooks/capabilities/index.cjs.map +1 -0
  86. package/dist/hooks/capabilities/index.d.ts +4 -0
  87. package/dist/hooks/capabilities/index.d.ts.map +1 -0
  88. package/dist/hooks/capabilities/index.js +44 -0
  89. package/dist/hooks/capabilities/index.js.map +1 -0
  90. package/dist/hooks/capabilities/use-feedback-available.d.ts +9 -0
  91. package/dist/hooks/capabilities/use-feedback-available.d.ts.map +1 -0
  92. package/dist/hooks/capabilities/use-observability-capabilities.d.ts +9 -0
  93. package/dist/hooks/capabilities/use-observability-capabilities.d.ts.map +1 -0
  94. package/dist/hooks/capabilities/use-trace-query-available.d.ts +9 -0
  95. package/dist/hooks/capabilities/use-trace-query-available.d.ts.map +1 -0
  96. package/dist/hooks/configuration/index.cjs +18 -0
  97. package/dist/hooks/configuration/index.cjs.map +1 -0
  98. package/dist/hooks/configuration/index.d.ts +2 -0
  99. package/dist/hooks/configuration/index.d.ts.map +1 -0
  100. package/dist/hooks/configuration/index.js +17 -0
  101. package/dist/hooks/configuration/index.js.map +1 -0
  102. package/dist/hooks/configuration/use-mastra-packages.d.ts +9 -0
  103. package/dist/hooks/configuration/use-mastra-packages.d.ts.map +1 -0
  104. package/dist/hooks/datasets/index.cjs +615 -0
  105. package/dist/hooks/datasets/index.cjs.map +1 -0
  106. package/dist/hooks/datasets/index.d.ts +10 -0
  107. package/dist/hooks/datasets/index.d.ts.map +1 -0
  108. package/dist/hooks/datasets/index.js +600 -0
  109. package/dist/hooks/datasets/index.js.map +1 -0
  110. package/dist/hooks/datasets/use-compare-experiments.d.ts +23 -0
  111. package/dist/hooks/datasets/use-compare-experiments.d.ts.map +1 -0
  112. package/dist/hooks/datasets/use-dataset-experiments.d.ts +49 -0
  113. package/dist/hooks/datasets/use-dataset-experiments.d.ts.map +1 -0
  114. package/dist/hooks/datasets/use-dataset-item-versions.d.ts +31 -0
  115. package/dist/hooks/datasets/use-dataset-item-versions.d.ts.map +1 -0
  116. package/dist/hooks/datasets/use-dataset-items.d.ts +38 -0
  117. package/dist/hooks/datasets/use-dataset-items.d.ts.map +1 -0
  118. package/dist/hooks/datasets/use-dataset-mutations.d.ts +362 -0
  119. package/dist/hooks/datasets/use-dataset-mutations.d.ts.map +1 -0
  120. package/dist/hooks/datasets/use-dataset-versions.d.ts +23 -0
  121. package/dist/hooks/datasets/use-dataset-versions.d.ts.map +1 -0
  122. package/dist/hooks/datasets/use-datasets.d.ts +44 -0
  123. package/dist/hooks/datasets/use-datasets.d.ts.map +1 -0
  124. package/dist/hooks/datasets/use-experiments.d.ts +16 -0
  125. package/dist/hooks/datasets/use-experiments.d.ts.map +1 -0
  126. package/dist/hooks/datasets/use-workflow-schema.d.ts +16 -0
  127. package/dist/hooks/datasets/use-workflow-schema.d.ts.map +1 -0
  128. package/dist/hooks/embedders/index.cjs +19 -0
  129. package/dist/hooks/embedders/index.cjs.map +1 -0
  130. package/dist/hooks/embedders/index.d.ts +2 -0
  131. package/dist/hooks/embedders/index.d.ts.map +1 -0
  132. package/dist/hooks/embedders/index.js +18 -0
  133. package/dist/hooks/embedders/index.js.map +1 -0
  134. package/dist/hooks/embedders/use-embedders.d.ts +17 -0
  135. package/dist/hooks/embedders/use-embedders.d.ts.map +1 -0
  136. package/dist/hooks/experiments/index.cjs +152 -0
  137. package/dist/hooks/experiments/index.cjs.map +1 -0
  138. package/dist/hooks/experiments/index.d.ts +5 -0
  139. package/dist/hooks/experiments/index.d.ts.map +1 -0
  140. package/dist/hooks/experiments/index.js +146 -0
  141. package/dist/hooks/experiments/index.js.map +1 -0
  142. package/dist/hooks/experiments/use-experiment-metrics.d.ts +30 -0
  143. package/dist/hooks/experiments/use-experiment-metrics.d.ts.map +1 -0
  144. package/dist/hooks/experiments/use-experiment-trace.d.ts +13 -0
  145. package/dist/hooks/experiments/use-experiment-trace.d.ts.map +1 -0
  146. package/dist/hooks/experiments/use-experiments-for-dataset-filter.d.ts +22 -0
  147. package/dist/hooks/experiments/use-experiments-for-dataset-filter.d.ts.map +1 -0
  148. package/dist/hooks/experiments/use-infinite-experiments.d.ts +22 -0
  149. package/dist/hooks/experiments/use-infinite-experiments.d.ts.map +1 -0
  150. package/dist/hooks/feedback/feedback-refetch-interval.d.ts +7 -0
  151. package/dist/hooks/feedback/feedback-refetch-interval.d.ts.map +1 -0
  152. package/dist/hooks/feedback/index.cjs +22 -0
  153. package/dist/hooks/feedback/index.cjs.map +1 -0
  154. package/dist/hooks/feedback/index.d.ts +3 -0
  155. package/dist/hooks/feedback/index.d.ts.map +1 -0
  156. package/dist/hooks/feedback/index.js +20 -0
  157. package/dist/hooks/feedback/index.js.map +1 -0
  158. package/dist/hooks/feedback/use-feedback.d.ts +56 -0
  159. package/dist/hooks/feedback/use-feedback.d.ts.map +1 -0
  160. package/dist/hooks/llm/index.cjs +17 -0
  161. package/dist/hooks/llm/index.cjs.map +1 -0
  162. package/dist/hooks/llm/index.d.ts +2 -0
  163. package/dist/hooks/llm/index.d.ts.map +1 -0
  164. package/dist/hooks/llm/index.js +16 -0
  165. package/dist/hooks/llm/index.js.map +1 -0
  166. package/dist/hooks/llm/use-llm-providers.d.ts +7 -0
  167. package/dist/hooks/llm/use-llm-providers.d.ts.map +1 -0
  168. package/dist/hooks/logs/index.cjs +84 -0
  169. package/dist/hooks/logs/index.cjs.map +1 -0
  170. package/dist/hooks/logs/index.d.ts +4 -0
  171. package/dist/hooks/logs/index.d.ts.map +1 -0
  172. package/dist/hooks/logs/index.js +82 -0
  173. package/dist/hooks/logs/index.js.map +1 -0
  174. package/dist/hooks/logs/types.d.ts +36 -0
  175. package/dist/hooks/logs/types.d.ts.map +1 -0
  176. package/dist/hooks/logs/use-logs.d.ts +79 -0
  177. package/dist/hooks/logs/use-logs.d.ts.map +1 -0
  178. package/dist/hooks/mcps/index.cjs +215 -0
  179. package/dist/hooks/mcps/index.cjs.map +1 -0
  180. package/dist/hooks/mcps/index.d.ts +7 -0
  181. package/dist/hooks/mcps/index.d.ts.map +1 -0
  182. package/dist/hooks/mcps/index.js +208 -0
  183. package/dist/hooks/mcps/index.js.map +1 -0
  184. package/dist/hooks/mcps/use-mcp-app-tools.d.ts +21 -0
  185. package/dist/hooks/mcps/use-mcp-app-tools.d.ts.map +1 -0
  186. package/dist/hooks/mcps/use-mcp-server-tool.d.ts +25 -0
  187. package/dist/hooks/mcps/use-mcp-server-tool.d.ts.map +1 -0
  188. package/dist/hooks/mcps/use-mcp-server-tools-by-id.d.ts +13 -0
  189. package/dist/hooks/mcps/use-mcp-server-tools-by-id.d.ts.map +1 -0
  190. package/dist/hooks/mcps/use-mcp-server-tools.d.ts +9 -0
  191. package/dist/hooks/mcps/use-mcp-server-tools.d.ts.map +1 -0
  192. package/dist/hooks/mcps/use-mcp-servers.d.ts +8 -0
  193. package/dist/hooks/mcps/use-mcp-servers.d.ts.map +1 -0
  194. package/dist/hooks/mcps/use-try-connect-mcp.d.ts +15 -0
  195. package/dist/hooks/mcps/use-try-connect-mcp.d.ts.map +1 -0
  196. package/dist/hooks/memory/index.cjs +328 -0
  197. package/dist/hooks/memory/index.cjs.map +1 -0
  198. package/dist/hooks/memory/index.d.ts +5 -0
  199. package/dist/hooks/memory/index.d.ts.map +1 -0
  200. package/dist/hooks/memory/index.js +312 -0
  201. package/dist/hooks/memory/index.js.map +1 -0
  202. package/dist/hooks/memory/use-memory-status.d.ts +12 -0
  203. package/dist/hooks/memory/use-memory-status.d.ts.map +1 -0
  204. package/dist/hooks/memory/use-memory-thread-messages.d.ts +13 -0
  205. package/dist/hooks/memory/use-memory-thread-messages.d.ts.map +1 -0
  206. package/dist/hooks/memory/use-memory.d.ts +159 -0
  207. package/dist/hooks/memory/use-memory.d.ts.map +1 -0
  208. package/dist/hooks/memory/use-observational-memory.d.ts +13 -0
  209. package/dist/hooks/memory/use-observational-memory.d.ts.map +1 -0
  210. package/dist/hooks/metrics/index.cjs +997 -0
  211. package/dist/hooks/metrics/index.cjs.map +1 -0
  212. package/dist/hooks/metrics/index.d.ts +16 -0
  213. package/dist/hooks/metrics/index.d.ts.map +1 -0
  214. package/dist/hooks/metrics/index.js +981 -0
  215. package/dist/hooks/metrics/index.js.map +1 -0
  216. package/dist/hooks/metrics/metrics-interval.d.ts +8 -0
  217. package/dist/hooks/metrics/metrics-interval.d.ts.map +1 -0
  218. package/dist/hooks/metrics/metrics-query-filters.d.ts +62 -0
  219. package/dist/hooks/metrics/metrics-query-filters.d.ts.map +1 -0
  220. package/dist/hooks/metrics/use-active-resources-kpi-metrics.d.ts +12 -0
  221. package/dist/hooks/metrics/use-active-resources-kpi-metrics.d.ts.map +1 -0
  222. package/dist/hooks/metrics/use-active-threads-kpi-metrics.d.ts +12 -0
  223. package/dist/hooks/metrics/use-active-threads-kpi-metrics.d.ts.map +1 -0
  224. package/dist/hooks/metrics/use-agent-runs-kpi-metrics.d.ts +9 -0
  225. package/dist/hooks/metrics/use-agent-runs-kpi-metrics.d.ts.map +1 -0
  226. package/dist/hooks/metrics/use-latency-metrics.d.ts +23 -0
  227. package/dist/hooks/metrics/use-latency-metrics.d.ts.map +1 -0
  228. package/dist/hooks/metrics/use-model-cost-kpi-metrics.d.ts +14 -0
  229. package/dist/hooks/metrics/use-model-cost-kpi-metrics.d.ts.map +1 -0
  230. package/dist/hooks/metrics/use-model-usage-cost-metrics.d.ts +16 -0
  231. package/dist/hooks/metrics/use-model-usage-cost-metrics.d.ts.map +1 -0
  232. package/dist/hooks/metrics/use-scores-metrics.d.ts +24 -0
  233. package/dist/hooks/metrics/use-scores-metrics.d.ts.map +1 -0
  234. package/dist/hooks/metrics/use-token-usage-by-agent-metrics.d.ts +15 -0
  235. package/dist/hooks/metrics/use-token-usage-by-agent-metrics.d.ts.map +1 -0
  236. package/dist/hooks/metrics/use-token-usage-timeseries.d.ts +22 -0
  237. package/dist/hooks/metrics/use-token-usage-timeseries.d.ts.map +1 -0
  238. package/dist/hooks/metrics/use-top-active-threads-metrics.d.ts +21 -0
  239. package/dist/hooks/metrics/use-top-active-threads-metrics.d.ts.map +1 -0
  240. package/dist/hooks/metrics/use-top-resources-by-threads-metrics.d.ts +20 -0
  241. package/dist/hooks/metrics/use-top-resources-by-threads-metrics.d.ts.map +1 -0
  242. package/dist/hooks/metrics/use-total-tokens-kpi-metrics.d.ts +13 -0
  243. package/dist/hooks/metrics/use-total-tokens-kpi-metrics.d.ts.map +1 -0
  244. package/dist/hooks/metrics/use-trace-volume-metrics.d.ts +17 -0
  245. package/dist/hooks/metrics/use-trace-volume-metrics.d.ts.map +1 -0
  246. package/dist/hooks/processors/index.cjs +43 -0
  247. package/dist/hooks/processors/index.cjs.map +1 -0
  248. package/dist/hooks/processors/index.d.ts +2 -0
  249. package/dist/hooks/processors/index.d.ts.map +1 -0
  250. package/dist/hooks/processors/index.js +40 -0
  251. package/dist/hooks/processors/index.js.map +1 -0
  252. package/dist/hooks/processors/use-processors.d.ts +64 -0
  253. package/dist/hooks/processors/use-processors.d.ts.map +1 -0
  254. package/dist/hooks/prompt-blocks/index.cjs +181 -0
  255. package/dist/hooks/prompt-blocks/index.cjs.map +1 -0
  256. package/dist/hooks/prompt-blocks/index.d.ts +3 -0
  257. package/dist/hooks/prompt-blocks/index.d.ts.map +1 -0
  258. package/dist/hooks/prompt-blocks/index.js +172 -0
  259. package/dist/hooks/prompt-blocks/index.js.map +1 -0
  260. package/dist/hooks/prompt-blocks/use-prompt-block-versions.d.ts +59 -0
  261. package/dist/hooks/prompt-blocks/use-prompt-block-versions.d.ts.map +1 -0
  262. package/dist/hooks/prompt-blocks/use-stored-prompt-blocks.d.ts +180 -0
  263. package/dist/hooks/prompt-blocks/use-stored-prompt-blocks.d.ts.map +1 -0
  264. package/dist/hooks/query/index.cjs +34 -0
  265. package/dist/hooks/query/index.cjs.map +1 -0
  266. package/dist/hooks/query/index.d.ts +4 -0
  267. package/dist/hooks/query/index.d.ts.map +1 -0
  268. package/dist/hooks/query/index.js +25 -0
  269. package/dist/hooks/query/index.js.map +1 -0
  270. package/dist/hooks/query/query-client-provider.d.ts +8 -0
  271. package/dist/hooks/query/query-client-provider.d.ts.map +1 -0
  272. package/dist/hooks/query/query-utils.d.ts +48 -0
  273. package/dist/hooks/query/query-utils.d.ts.map +1 -0
  274. package/dist/hooks/review/index.cjs +89 -0
  275. package/dist/hooks/review/index.cjs.map +1 -0
  276. package/dist/hooks/review/index.d.ts +4 -0
  277. package/dist/hooks/review/index.d.ts.map +1 -0
  278. package/dist/hooks/review/index.js +86 -0
  279. package/dist/hooks/review/index.js.map +1 -0
  280. package/dist/hooks/review/types.d.ts +21 -0
  281. package/dist/hooks/review/types.d.ts.map +1 -0
  282. package/dist/hooks/review/use-dataset-review-items.d.ts +19 -0
  283. package/dist/hooks/review/use-dataset-review-items.d.ts.map +1 -0
  284. package/dist/hooks/review/use-review-summary.d.ts +9 -0
  285. package/dist/hooks/review/use-review-summary.d.ts.map +1 -0
  286. package/dist/hooks/schedules/index.cjs +110 -0
  287. package/dist/hooks/schedules/index.cjs.map +1 -0
  288. package/dist/hooks/schedules/index.d.ts +5 -0
  289. package/dist/hooks/schedules/index.d.ts.map +1 -0
  290. package/dist/hooks/schedules/index.js +106 -0
  291. package/dist/hooks/schedules/index.js.map +1 -0
  292. package/dist/hooks/schedules/use-schedule-triggers.d.ts +18 -0
  293. package/dist/hooks/schedules/use-schedule-triggers.d.ts.map +1 -0
  294. package/dist/hooks/schedules/use-schedule.d.ts +11 -0
  295. package/dist/hooks/schedules/use-schedule.d.ts.map +1 -0
  296. package/dist/hooks/schedules/use-schedules.d.ts +7 -0
  297. package/dist/hooks/schedules/use-schedules.d.ts.map +1 -0
  298. package/dist/hooks/schedules/use-toggle-schedule.d.ts +13 -0
  299. package/dist/hooks/schedules/use-toggle-schedule.d.ts.map +1 -0
  300. package/dist/hooks/scores/index.cjs +339 -0
  301. package/dist/hooks/scores/index.cjs.map +1 -0
  302. package/dist/hooks/scores/index.d.ts +6 -0
  303. package/dist/hooks/scores/index.d.ts.map +1 -0
  304. package/dist/hooks/scores/index.js +323 -0
  305. package/dist/hooks/scores/index.js.map +1 -0
  306. package/dist/hooks/scores/use-scorer-versions.d.ts +71 -0
  307. package/dist/hooks/scores/use-scorer-versions.d.ts.map +1 -0
  308. package/dist/hooks/scores/use-scorers.d.ts +34 -0
  309. package/dist/hooks/scores/use-scorers.d.ts.map +1 -0
  310. package/dist/hooks/scores/use-stored-scorers.d.ts +151 -0
  311. package/dist/hooks/scores/use-stored-scorers.d.ts.map +1 -0
  312. package/dist/hooks/scores/use-trace-span-scores.d.ts +20 -0
  313. package/dist/hooks/scores/use-trace-span-scores.d.ts.map +1 -0
  314. package/dist/hooks/scores/use-trigger-scorer.d.ts +17 -0
  315. package/dist/hooks/scores/use-trigger-scorer.d.ts.map +1 -0
  316. package/dist/hooks/shared/cost.d.ts +7 -0
  317. package/dist/hooks/shared/cost.d.ts.map +1 -0
  318. package/dist/hooks/shared/date-format.d.ts +30 -0
  319. package/dist/hooks/shared/date-format.d.ts.map +1 -0
  320. package/dist/hooks/shared/map.d.ts +2 -0
  321. package/dist/hooks/shared/map.d.ts.map +1 -0
  322. package/dist/hooks/shared/query-options.d.ts +19 -0
  323. package/dist/hooks/shared/query-options.d.ts.map +1 -0
  324. package/dist/hooks/shared/use-in-view.d.ts +23 -0
  325. package/dist/hooks/shared/use-in-view.d.ts.map +1 -0
  326. package/dist/hooks/templates/index.cjs +464 -0
  327. package/dist/hooks/templates/index.cjs.map +1 -0
  328. package/dist/hooks/templates/index.d.ts +2 -0
  329. package/dist/hooks/templates/index.d.ts.map +1 -0
  330. package/dist/hooks/templates/index.js +456 -0
  331. package/dist/hooks/templates/index.js.map +1 -0
  332. package/dist/hooks/templates/use-templates.d.ts +139 -0
  333. package/dist/hooks/templates/use-templates.d.ts.map +1 -0
  334. package/dist/hooks/tool-providers/index.cjs +342 -0
  335. package/dist/hooks/tool-providers/index.cjs.map +1 -0
  336. package/dist/hooks/tool-providers/index.d.ts +10 -0
  337. package/dist/hooks/tool-providers/index.d.ts.map +1 -0
  338. package/dist/hooks/tool-providers/index.js +332 -0
  339. package/dist/hooks/tool-providers/index.js.map +1 -0
  340. package/dist/hooks/tool-providers/use-all-connections.d.ts +41 -0
  341. package/dist/hooks/tool-providers/use-all-connections.d.ts.map +1 -0
  342. package/dist/hooks/tool-providers/use-all-provider-tools.d.ts +25 -0
  343. package/dist/hooks/tool-providers/use-all-provider-tools.d.ts.map +1 -0
  344. package/dist/hooks/tool-providers/use-authorize.d.ts +45 -0
  345. package/dist/hooks/tool-providers/use-authorize.d.ts.map +1 -0
  346. package/dist/hooks/tool-providers/use-disconnect-connection.d.ts +24 -0
  347. package/dist/hooks/tool-providers/use-disconnect-connection.d.ts.map +1 -0
  348. package/dist/hooks/tool-providers/use-existing-connections.d.ts +33 -0
  349. package/dist/hooks/tool-providers/use-existing-connections.d.ts.map +1 -0
  350. package/dist/hooks/tool-providers/use-provider-tools.d.ts +17 -0
  351. package/dist/hooks/tool-providers/use-provider-tools.d.ts.map +1 -0
  352. package/dist/hooks/tool-providers/use-tool-providers.d.ts +23 -0
  353. package/dist/hooks/tool-providers/use-tool-providers.d.ts.map +1 -0
  354. package/dist/hooks/tool-providers/use-toolkits.d.ts +13 -0
  355. package/dist/hooks/tool-providers/use-toolkits.d.ts.map +1 -0
  356. package/dist/hooks/tool-providers/use-update-connection.d.ts +24 -0
  357. package/dist/hooks/tool-providers/use-update-connection.d.ts.map +1 -0
  358. package/dist/hooks/tools/index.cjs +49 -0
  359. package/dist/hooks/tools/index.cjs.map +1 -0
  360. package/dist/hooks/tools/index.d.ts +3 -0
  361. package/dist/hooks/tools/index.d.ts.map +1 -0
  362. package/dist/hooks/tools/index.js +46 -0
  363. package/dist/hooks/tools/index.js.map +1 -0
  364. package/dist/hooks/tools/use-all-tools.d.ts +16 -0
  365. package/dist/hooks/tools/use-all-tools.d.ts.map +1 -0
  366. package/dist/hooks/tools/use-execute-tool.d.ts +13 -0
  367. package/dist/hooks/tools/use-execute-tool.d.ts.map +1 -0
  368. package/dist/hooks/traces/discovery-cache.d.ts +12 -0
  369. package/dist/hooks/traces/discovery-cache.d.ts.map +1 -0
  370. package/dist/hooks/traces/index.cjs +1168 -0
  371. package/dist/hooks/traces/index.cjs.map +1 -0
  372. package/dist/hooks/traces/index.d.ts +22 -0
  373. package/dist/hooks/traces/index.d.ts.map +1 -0
  374. package/dist/hooks/traces/index.js +1129 -0
  375. package/dist/hooks/traces/index.js.map +1 -0
  376. package/dist/hooks/traces/types.d.ts +20 -0
  377. package/dist/hooks/traces/types.d.ts.map +1 -0
  378. package/dist/hooks/traces/use-branch.d.ts +18 -0
  379. package/dist/hooks/traces/use-branch.d.ts.map +1 -0
  380. package/dist/hooks/traces/use-create-feedback.d.ts +21 -0
  381. package/dist/hooks/traces/use-create-feedback.d.ts.map +1 -0
  382. package/dist/hooks/traces/use-delete-feedback.d.ts +21 -0
  383. package/dist/hooks/traces/use-delete-feedback.d.ts.map +1 -0
  384. package/dist/hooks/traces/use-entity-names.d.ts +14 -0
  385. package/dist/hooks/traces/use-entity-names.d.ts.map +1 -0
  386. package/dist/hooks/traces/use-environments.d.ts +10 -0
  387. package/dist/hooks/traces/use-environments.d.ts.map +1 -0
  388. package/dist/hooks/traces/use-service-names.d.ts +10 -0
  389. package/dist/hooks/traces/use-service-names.d.ts.map +1 -0
  390. package/dist/hooks/traces/use-span-detail.d.ts +14 -0
  391. package/dist/hooks/traces/use-span-detail.d.ts.map +1 -0
  392. package/dist/hooks/traces/use-span-feedback.d.ts +19 -0
  393. package/dist/hooks/traces/use-span-feedback.d.ts.map +1 -0
  394. package/dist/hooks/traces/use-tags.d.ts +10 -0
  395. package/dist/hooks/traces/use-tags.d.ts.map +1 -0
  396. package/dist/hooks/traces/use-thread-has-other-traces.d.ts +17 -0
  397. package/dist/hooks/traces/use-thread-has-other-traces.d.ts.map +1 -0
  398. package/dist/hooks/traces/use-trace-column-preferences-storage-key.d.ts +6 -0
  399. package/dist/hooks/traces/use-trace-column-preferences-storage-key.d.ts.map +1 -0
  400. package/dist/hooks/traces/use-trace-feedback.d.ts +16 -0
  401. package/dist/hooks/traces/use-trace-feedback.d.ts.map +1 -0
  402. package/dist/hooks/traces/use-trace-light-spans.d.ts +16 -0
  403. package/dist/hooks/traces/use-trace-light-spans.d.ts.map +1 -0
  404. package/dist/hooks/traces/use-trace-metadata-filter-fields.d.ts +36 -0
  405. package/dist/hooks/traces/use-trace-metadata-filter-fields.d.ts.map +1 -0
  406. package/dist/hooks/traces/use-trace-or-branch-spans.d.ts +39 -0
  407. package/dist/hooks/traces/use-trace-or-branch-spans.d.ts.map +1 -0
  408. package/dist/hooks/traces/use-trace-query.d.ts +57 -0
  409. package/dist/hooks/traces/use-trace-query.d.ts.map +1 -0
  410. package/dist/hooks/traces/use-trace-spans.d.ts +46 -0
  411. package/dist/hooks/traces/use-trace-spans.d.ts.map +1 -0
  412. package/dist/hooks/traces/use-trace-usage.d.ts +10 -0
  413. package/dist/hooks/traces/use-trace-usage.d.ts.map +1 -0
  414. package/dist/hooks/traces/use-traces.d.ts +292 -0
  415. package/dist/hooks/traces/use-traces.d.ts.map +1 -0
  416. package/dist/hooks/vectors/index.cjs +19 -0
  417. package/dist/hooks/vectors/index.cjs.map +1 -0
  418. package/dist/hooks/vectors/index.d.ts +2 -0
  419. package/dist/hooks/vectors/index.d.ts.map +1 -0
  420. package/dist/hooks/vectors/index.js +18 -0
  421. package/dist/hooks/vectors/index.js.map +1 -0
  422. package/dist/hooks/vectors/use-vectors.d.ts +14 -0
  423. package/dist/hooks/vectors/use-vectors.d.ts.map +1 -0
  424. package/dist/hooks/voice/index.cjs +87 -0
  425. package/dist/hooks/voice/index.cjs.map +1 -0
  426. package/dist/hooks/voice/index.d.ts +2 -0
  427. package/dist/hooks/voice/index.d.ts.map +1 -0
  428. package/dist/hooks/voice/index.js +86 -0
  429. package/dist/hooks/voice/index.js.map +1 -0
  430. package/dist/hooks/voice/use-read-aloud.d.ts +20 -0
  431. package/dist/hooks/voice/use-read-aloud.d.ts.map +1 -0
  432. package/dist/hooks/workflows/index.cjs +173 -0
  433. package/dist/hooks/workflows/index.cjs.map +1 -0
  434. package/dist/hooks/workflows/index.d.ts +7 -0
  435. package/dist/hooks/workflows/index.d.ts.map +1 -0
  436. package/dist/hooks/workflows/index.js +157 -0
  437. package/dist/hooks/workflows/index.js.map +1 -0
  438. package/dist/hooks/workflows/use-workflow-runs.d.ts +51 -0
  439. package/dist/hooks/workflows/use-workflow-runs.d.ts.map +1 -0
  440. package/dist/hooks/workflows/use-workflow.d.ts +14 -0
  441. package/dist/hooks/workflows/use-workflow.d.ts.map +1 -0
  442. package/dist/hooks/workflows/use-workflows-run-counts.d.ts +25 -0
  443. package/dist/hooks/workflows/use-workflows-run-counts.d.ts.map +1 -0
  444. package/dist/hooks/workflows/use-workflows.d.ts +10 -0
  445. package/dist/hooks/workflows/use-workflows.d.ts.map +1 -0
  446. package/dist/hooks/workspace/client-utils.d.ts +5 -0
  447. package/dist/hooks/workspace/client-utils.d.ts.map +1 -0
  448. package/dist/hooks/workspace/compatibility.d.ts +22 -0
  449. package/dist/hooks/workspace/compatibility.d.ts.map +1 -0
  450. package/dist/hooks/workspace/file-type.d.ts +7 -0
  451. package/dist/hooks/workspace/file-type.d.ts.map +1 -0
  452. package/dist/hooks/workspace/index.cjs +624 -0
  453. package/dist/hooks/workspace/index.cjs.map +1 -0
  454. package/dist/hooks/workspace/index.d.ts +11 -0
  455. package/dist/hooks/workspace/index.d.ts.map +1 -0
  456. package/dist/hooks/workspace/index.js +594 -0
  457. package/dist/hooks/workspace/index.js.map +1 -0
  458. package/dist/hooks/workspace/types.d.ts +199 -0
  459. package/dist/hooks/workspace/types.d.ts.map +1 -0
  460. package/dist/hooks/workspace/use-skills-sh.d.ts +104 -0
  461. package/dist/hooks/workspace/use-skills-sh.d.ts.map +1 -0
  462. package/dist/hooks/workspace/use-stored-workspaces.d.ts +12 -0
  463. package/dist/hooks/workspace/use-stored-workspaces.d.ts.map +1 -0
  464. package/dist/hooks/workspace/use-workspace-directory.d.ts +13 -0
  465. package/dist/hooks/workspace/use-workspace-directory.d.ts.map +1 -0
  466. package/dist/hooks/workspace/use-workspace-file-content.d.ts +15 -0
  467. package/dist/hooks/workspace/use-workspace-file-content.d.ts.map +1 -0
  468. package/dist/hooks/workspace/use-workspace-search.d.ts +20 -0
  469. package/dist/hooks/workspace/use-workspace-search.d.ts.map +1 -0
  470. package/dist/hooks/workspace/use-workspace-skills.d.ts +23 -0
  471. package/dist/hooks/workspace/use-workspace-skills.d.ts.map +1 -0
  472. package/dist/hooks/workspace/use-workspace.d.ts +56 -0
  473. package/dist/hooks/workspace/use-workspace.d.ts.map +1 -0
  474. package/dist/hooks-BFQK_s4g.js +1231 -0
  475. package/dist/hooks-BFQK_s4g.js.map +1 -0
  476. package/dist/hooks-CMjizg6y.cjs +1248 -0
  477. package/dist/hooks-CMjizg6y.cjs.map +1 -0
  478. package/dist/hooks-CjULNHpJ.js +252 -0
  479. package/dist/hooks-CjULNHpJ.js.map +1 -0
  480. package/dist/hooks-DsDYaJ3T.cjs +269 -0
  481. package/dist/hooks-DsDYaJ3T.cjs.map +1 -0
  482. package/dist/index.cjs +21 -3434
  483. package/dist/index.cjs.map +1 -1
  484. package/dist/index.d.ts +1 -0
  485. package/dist/index.d.ts.map +1 -1
  486. package/dist/index.js +6 -3419
  487. package/dist/index.js.map +1 -1
  488. package/dist/lib/mastra-db/fromCoreUserMessage.d.ts +3 -4
  489. package/dist/lib/mastra-db/fromCoreUserMessage.d.ts.map +1 -1
  490. package/dist/map-CDv4fbu4.js +12 -0
  491. package/dist/map-CDv4fbu4.js.map +1 -0
  492. package/dist/map-wjmL1y5O.cjs +17 -0
  493. package/dist/map-wjmL1y5O.cjs.map +1 -0
  494. package/dist/mastra-client-context-Bx_g84YB.js +50 -0
  495. package/dist/mastra-client-context-Bx_g84YB.js.map +1 -0
  496. package/dist/mastra-client-context-DzX3f0RF.cjs +61 -0
  497. package/dist/mastra-client-context-DzX3f0RF.cjs.map +1 -0
  498. package/dist/query-utils-CcrChYgz.cjs +174 -0
  499. package/dist/query-utils-CcrChYgz.cjs.map +1 -0
  500. package/dist/query-utils-D1NgFnWU.js +127 -0
  501. package/dist/query-utils-D1NgFnWU.js.map +1 -0
  502. package/dist/use-in-view-B6eJO9Zi.cjs +37 -0
  503. package/dist/use-in-view-B6eJO9Zi.cjs.map +1 -0
  504. package/dist/use-in-view-C9sYPGRm.js +32 -0
  505. package/dist/use-in-view-C9sYPGRm.js.map +1 -0
  506. package/dist/voice-BOtUdMi8.cjs +281 -0
  507. package/dist/voice-BOtUdMi8.cjs.map +1 -0
  508. package/dist/voice-DgirjEyH.js +264 -0
  509. package/dist/voice-DgirjEyH.js.map +1 -0
  510. package/package.json +32 -3
@@ -0,0 +1,1129 @@
1
+ import { n as useMastraClient } from "../../mastra-client-context-Bx_g84YB.js";
2
+ import { t as useInView } from "../../use-in-view-C9sYPGRm.js";
3
+ import { n as is403ForbiddenError } from "../../query-utils-D1NgFnWU.js";
4
+ import { t as getOrCreate } from "../../map-CDv4fbu4.js";
5
+ import { t as getFeedbackRefetchInterval } from "../../feedback-refetch-interval-DLHzQoVV.js";
6
+ import { MastraClient, MastraClientError } from "@mastra/client-js";
7
+ import { useEffect, useMemo, useRef, useState } from "react";
8
+ import { keepPreviousData, queryOptions, skipToken, useInfiniteQuery, useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
9
+ import { EntityType } from "@mastra/core/observability";
10
+ //#region src/hooks/traces/discovery-cache.ts
11
+ /**
12
+ * How long discovery results (tags, environments, service names, entity
13
+ * names) stay fresh on the client.
14
+ *
15
+ * Discovery values are filter suggestions that change slowly, and the server
16
+ * caches them for 5 minutes anyway. Without a staleTime, React Query refetches
17
+ * on every mount and window focus, which pushes those refetches straight
18
+ * through to the store's discovery refresh. Matching the server TTL keeps the
19
+ * client from asking more often than the answer can change.
20
+ */
21
+ const DISCOVERY_STALE_TIME = 300 * 1e3;
22
+ //#endregion
23
+ //#region src/hooks/traces/use-branch.ts
24
+ /**
25
+ * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
26
+ */
27
+ function useBranch({ traceId, spanId, depth, queryOptions }) {
28
+ const client = useMastraClient();
29
+ return useQuery({
30
+ queryKey: [
31
+ "branch",
32
+ traceId,
33
+ spanId,
34
+ depth
35
+ ],
36
+ queryFn: async () => {
37
+ if (!traceId || !spanId) throw new Error("traceId and spanId are required");
38
+ return client.getBranch({
39
+ traceId,
40
+ spanId,
41
+ depth
42
+ });
43
+ },
44
+ staleTime: 0,
45
+ ...queryOptions
46
+ });
47
+ }
48
+ //#endregion
49
+ //#region src/hooks/traces/types.ts
50
+ const ROOT_ENTITY_TYPES = {
51
+ AGENT: "agent",
52
+ WORKFLOW: "workflow_run",
53
+ SCORER: "scorer",
54
+ INGEST: "rag_ingestion"
55
+ };
56
+ //#endregion
57
+ //#region src/hooks/traces/use-entity-names.ts
58
+ function resolveEntityType(entityType) {
59
+ return Object.values(EntityType).find((candidate) => candidate === entityType);
60
+ }
61
+ const useEntityNames = ({ entityType, rootOnly = false, queryOptions } = {}) => {
62
+ const client = useMastraClient();
63
+ return useQuery({
64
+ queryKey: entityType ? [
65
+ "observability-entity-names",
66
+ "by-type",
67
+ entityType
68
+ ] : [
69
+ "observability-entity-names",
70
+ "all",
71
+ rootOnly ? "root-only" : "all-types"
72
+ ],
73
+ queryFn: async () => {
74
+ try {
75
+ if (entityType) {
76
+ const resolvedEntityType = resolveEntityType(entityType);
77
+ if (!resolvedEntityType) return { names: [] };
78
+ return await client.getEntityNames({ entityType: resolvedEntityType });
79
+ }
80
+ if (!rootOnly) return await client.getEntityNames();
81
+ const responses = await Promise.all(Object.values(ROOT_ENTITY_TYPES).map((rootEntityType) => {
82
+ const resolvedEntityType = resolveEntityType(rootEntityType);
83
+ if (!resolvedEntityType) return { names: [] };
84
+ return client.getEntityNames({ entityType: resolvedEntityType });
85
+ }));
86
+ return { names: Array.from(new Set(responses.flatMap((response) => response?.names ?? []))).sort() };
87
+ } catch {
88
+ return { names: [] };
89
+ }
90
+ },
91
+ select: (data) => data?.names ?? [],
92
+ retry: false,
93
+ staleTime: DISCOVERY_STALE_TIME,
94
+ ...queryOptions
95
+ });
96
+ };
97
+ //#endregion
98
+ //#region src/hooks/traces/use-environments.ts
99
+ const useEnvironments = ({ queryOptions } = {}) => {
100
+ const client = useMastraClient();
101
+ return useQuery({
102
+ queryKey: ["observability-environments"],
103
+ queryFn: async () => {
104
+ try {
105
+ return await client.getEnvironments();
106
+ } catch {
107
+ return { environments: [] };
108
+ }
109
+ },
110
+ select: (data) => data?.environments ?? [],
111
+ retry: false,
112
+ staleTime: DISCOVERY_STALE_TIME,
113
+ ...queryOptions
114
+ });
115
+ };
116
+ //#endregion
117
+ //#region src/hooks/traces/use-service-names.ts
118
+ const useServiceNames = ({ queryOptions } = {}) => {
119
+ const client = useMastraClient();
120
+ return useQuery({
121
+ queryKey: ["observability-service-names"],
122
+ queryFn: async () => {
123
+ try {
124
+ return await client.getServiceNames();
125
+ } catch {
126
+ return { serviceNames: [] };
127
+ }
128
+ },
129
+ select: (data) => data?.serviceNames ?? [],
130
+ retry: false,
131
+ staleTime: DISCOVERY_STALE_TIME,
132
+ ...queryOptions
133
+ });
134
+ };
135
+ //#endregion
136
+ //#region src/hooks/traces/use-span-detail.ts
137
+ const IMMUTABLE_CACHE_TIME$1 = 1e3 * 60 * 60 * 24 * 30;
138
+ /**
139
+ * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
140
+ */
141
+ function useSpanDetail({ traceId, spanId, queryOptions }) {
142
+ const client = useMastraClient();
143
+ return useQuery({
144
+ queryKey: [
145
+ "span-detail",
146
+ traceId,
147
+ spanId
148
+ ],
149
+ queryFn: async () => {
150
+ if (!traceId || !spanId) throw new Error("Trace ID and Span ID are required");
151
+ return client.getSpan(traceId, spanId);
152
+ },
153
+ staleTime: (query) => {
154
+ if (query.state.data?.span?.endedAt) return IMMUTABLE_CACHE_TIME$1;
155
+ return 0;
156
+ },
157
+ ...queryOptions
158
+ });
159
+ }
160
+ //#endregion
161
+ //#region src/hooks/traces/use-tags.ts
162
+ const useTags = ({ queryOptions } = {}) => {
163
+ const client = useMastraClient();
164
+ return useQuery({
165
+ queryKey: ["observability-tags"],
166
+ queryFn: async () => {
167
+ try {
168
+ return await client.getTags();
169
+ } catch {
170
+ return { tags: [] };
171
+ }
172
+ },
173
+ select: (data) => data?.tags ?? [],
174
+ retry: false,
175
+ staleTime: DISCOVERY_STALE_TIME,
176
+ ...queryOptions
177
+ });
178
+ };
179
+ //#endregion
180
+ //#region src/hooks/traces/use-thread-has-other-traces.ts
181
+ /**
182
+ * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
183
+ */
184
+ function useThreadHasOtherTraces({ threadId, queryOptions }) {
185
+ const client = useMastraClient();
186
+ const { data } = useQuery({
187
+ queryKey: ["thread-trace-count", threadId],
188
+ queryFn: () => client.listTracesLight({
189
+ filters: { threadId: threadId ?? "" },
190
+ pagination: {
191
+ page: 0,
192
+ perPage: 25
193
+ }
194
+ }),
195
+ select: (response) => (response.spans?.length ?? 0) > 1,
196
+ ...queryOptions
197
+ });
198
+ return data ?? false;
199
+ }
200
+ //#endregion
201
+ //#region src/hooks/traces/use-trace-light-spans.ts
202
+ const IMMUTABLE_CACHE_TIME = 1e3 * 60 * 60 * 24 * 30;
203
+ /**
204
+ * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
205
+ */
206
+ function useTraceLightSpans({ traceId, queryOptions }) {
207
+ const client = useMastraClient();
208
+ return useQuery({
209
+ queryKey: ["trace-light-spans", traceId],
210
+ queryFn: async () => {
211
+ if (!traceId) throw new Error("Trace ID is required");
212
+ return await client.getTraceLight(traceId);
213
+ },
214
+ staleTime: (query) => {
215
+ if (query.state.data?.spans.every((d) => Boolean(d.endedAt))) return IMMUTABLE_CACHE_TIME;
216
+ return 0;
217
+ },
218
+ ...queryOptions
219
+ });
220
+ }
221
+ //#endregion
222
+ //#region src/hooks/traces/use-trace-spans.ts
223
+ const traceSpansQueryOptions = (client, traceId) => queryOptions({
224
+ queryKey: ["trace-spans", traceId],
225
+ queryFn: async () => {
226
+ if (!traceId) throw new Error("Trace ID is required");
227
+ return await client.getTrace(traceId);
228
+ },
229
+ staleTime: 0
230
+ });
231
+ /**
232
+ * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
233
+ */
234
+ function useTraceSpans({ traceId, passive = false, queryOptions }) {
235
+ const client = useMastraClient();
236
+ const { queryKey, queryFn, enabled, staleTime } = traceSpansQueryOptions(client, traceId);
237
+ return useQuery({
238
+ queryKey,
239
+ queryFn,
240
+ enabled,
241
+ staleTime,
242
+ refetchOnMount: !passive,
243
+ refetchOnWindowFocus: !passive,
244
+ refetchOnReconnect: !passive,
245
+ ...queryOptions
246
+ });
247
+ }
248
+ /**
249
+ * Returns a function that loads a full trace through the shared `trace-spans` cache, so an
250
+ * imperative read (e.g. an export) and the trace panel always see the same payload.
251
+ */
252
+ function useFetchTraceSpans() {
253
+ const client = useMastraClient();
254
+ const queryClient = useQueryClient();
255
+ return (traceId) => queryClient.fetchQuery(traceSpansQueryOptions(client, traceId));
256
+ }
257
+ /**
258
+ * Observes the `trace-spans` query of several traces at once and projects each one with `select`.
259
+ * Traces still loading (or failed) yield `fallback(traceId)` so the result always lines up with `traceIds`.
260
+ */
261
+ function useTraceSpansQueries({ traceIds, select, fallback, queryOptions }) {
262
+ const client = useMastraClient();
263
+ return useQueries({
264
+ queries: traceIds.map((traceId) => ({
265
+ ...traceSpansQueryOptions(client, traceId),
266
+ refetchOnMount: false,
267
+ refetchOnWindowFocus: false,
268
+ refetchOnReconnect: false,
269
+ select: (data) => select(traceId, data),
270
+ ...queryOptions
271
+ })),
272
+ combine: (results) => results.map((result, index) => result.data === void 0 ? fallback(traceIds[index] ?? "") : result.data)
273
+ });
274
+ }
275
+ //#endregion
276
+ //#region src/hooks/traces/use-trace-or-branch-spans.ts
277
+ /**
278
+ * Unified data source for the trace/span detail panel. Returns trace spans (full tree from the
279
+ * root) in traces mode, or branch spans (subtree rooted at `anchorSpanId`) in branches mode.
280
+ * Only the active query fires; the inactive one is disabled via its `enabled` flag.
281
+ *
282
+ * Both modes carry full span payloads: the panel renders and searches them, so a lightweight
283
+ * projection here would hide content from the reader looking straight at it.
284
+ */
285
+ function useTraceOrBranchSpans({ traceId, anchorSpanId, listMode, depth, queryOptions }) {
286
+ const isBranches = listMode === "branches";
287
+ const traceQuery = useTraceSpans({
288
+ traceId: isBranches ? null : traceId,
289
+ queryOptions: {
290
+ enabled: !isBranches && !!traceId,
291
+ ...queryOptions?.trace
292
+ }
293
+ });
294
+ const branchQuery = useBranch({
295
+ traceId: isBranches ? traceId : null,
296
+ spanId: isBranches ? anchorSpanId : null,
297
+ depth,
298
+ queryOptions: {
299
+ enabled: isBranches && !!traceId && !!anchorSpanId,
300
+ ...queryOptions?.branch
301
+ }
302
+ });
303
+ if (isBranches) return {
304
+ spans: branchQuery.data?.spans,
305
+ anchorSpanId: anchorSpanId ?? void 0,
306
+ isLoading: branchQuery.isLoading,
307
+ isError: branchQuery.isError,
308
+ error: branchQuery.error
309
+ };
310
+ return {
311
+ spans: traceQuery.data?.spans,
312
+ anchorSpanId: void 0,
313
+ isLoading: traceQuery.isLoading,
314
+ isError: traceQuery.isError,
315
+ error: traceQuery.error
316
+ };
317
+ }
318
+ //#endregion
319
+ //#region src/hooks/traces/use-trace-query.ts
320
+ const TRACE_QUERY_PER_PAGE = 25;
321
+ function getTraceQueryNextPageParam(lastPage) {
322
+ return lastPage?.page.next ?? void 0;
323
+ }
324
+ function selectTraceQueryTraces(data) {
325
+ const seen = /* @__PURE__ */ new Set();
326
+ return data.pages.flatMap((page) => page.traces.filter((trace) => {
327
+ if (seen.has(trace.traceId)) return false;
328
+ seen.add(trace.traceId);
329
+ return true;
330
+ }));
331
+ }
332
+ const toIsoString = (value) => typeof value === "string" ? value : value.toISOString();
333
+ /** Maps a legacy light root span to a trace-query row. The light record carries no
334
+ * environment, so it stays null. Running spans have no `endedAt` and may carry a
335
+ * status outside the query API's enum; both are kept as-is (the list view handles them), hence the
336
+ * assertion at this compatibility boundary. */
337
+ function lightSpanToTraceQueryTrace(span) {
338
+ return {
339
+ traceId: span.traceId,
340
+ rootSpanId: span.spanId,
341
+ name: span.name,
342
+ entityId: span.entityId ?? null,
343
+ parentSpanId: span.parentSpanId ?? null,
344
+ createdAt: toIsoString(span.createdAt),
345
+ metadata: span.metadata ?? null,
346
+ inputPreview: span.inputPreview ?? null,
347
+ threadId: span.threadId ?? null,
348
+ resourceId: span.resourceId ?? null,
349
+ startedAt: toIsoString(span.startedAt),
350
+ endedAt: span.endedAt == null ? span.endedAt : toIsoString(span.endedAt),
351
+ entityName: span.entityName ?? null,
352
+ entityType: span.entityType ?? null,
353
+ environment: null,
354
+ status: span.status
355
+ };
356
+ }
357
+ function selectLegacyTraceQueryTraces(data) {
358
+ const seen = /* @__PURE__ */ new Set();
359
+ return data.pages.flatMap((page) => page.spans.flatMap((span) => {
360
+ if (seen.has(span.traceId)) return [];
361
+ seen.add(span.traceId);
362
+ return [lightSpanToTraceQueryTrace(span)];
363
+ }));
364
+ }
365
+ function getLegacyTraceQueryNextPageParam(lastPage) {
366
+ return lastPage.pagination?.hasMore ? lastPage.pagination.page + 1 : void 0;
367
+ }
368
+ /** Queries traces with cursor pagination and viewport-driven loading. */
369
+ function useTraceQuery({ query, limit = 25, enabled = true, withQueryTrace = true, legacyFilters, queryOptions }) {
370
+ const client = useMastraClient();
371
+ const { inView, setRef: setEndOfListElement } = useInView();
372
+ const queryResult = useInfiniteQuery({
373
+ queryKey: [
374
+ "trace-query",
375
+ query,
376
+ limit
377
+ ],
378
+ queryFn: query ? async ({ pageParam }) => {
379
+ const response = await new MastraClient({
380
+ ...client.options,
381
+ retries: 0
382
+ }).queryTraces({
383
+ ...query,
384
+ page: {
385
+ limit,
386
+ after: pageParam ?? null
387
+ }
388
+ });
389
+ if ("traces" in response && "page" in response) return response;
390
+ throw new Error("Expected a cursor-paginated trace query response");
391
+ } : skipToken,
392
+ initialPageParam: void 0,
393
+ getNextPageParam: getTraceQueryNextPageParam,
394
+ select: selectTraceQueryTraces,
395
+ retry: false,
396
+ placeholderData: keepPreviousData,
397
+ enabled: enabled && withQueryTrace,
398
+ ...queryOptions?.traceQuery
399
+ });
400
+ const orderBy = query?.orderBy;
401
+ const legacyDirection = orderBy?.[0]?.direction === "asc" ? "ASC" : "DESC";
402
+ const legacyResult = useInfiniteQuery({
403
+ queryKey: [
404
+ "trace-query-legacy",
405
+ legacyFilters,
406
+ limit,
407
+ orderBy
408
+ ],
409
+ queryFn: ({ pageParam }) => client.listTracesLight({
410
+ filters: legacyFilters,
411
+ pagination: {
412
+ page: pageParam,
413
+ perPage: limit
414
+ },
415
+ orderBy: {
416
+ field: "startedAt",
417
+ direction: legacyDirection
418
+ }
419
+ }),
420
+ initialPageParam: 0,
421
+ getNextPageParam: getLegacyTraceQueryNextPageParam,
422
+ select: selectLegacyTraceQueryTraces,
423
+ retry: false,
424
+ placeholderData: keepPreviousData,
425
+ enabled: enabled && !withQueryTrace,
426
+ ...queryOptions?.legacy
427
+ });
428
+ const { data, hasNextPage, isFetchingNextPage, fetchNextPage, isLoading, isPlaceholderData, isFetching, isRefetching, fetchStatus, isError, error, refetch, isFetchNextPageError } = withQueryTrace ? queryResult : legacyResult;
429
+ useEffect(() => {
430
+ if (enabled && inView && hasNextPage && !isFetching && !isFetchNextPageError) fetchNextPage();
431
+ }, [
432
+ enabled,
433
+ inView,
434
+ hasNextPage,
435
+ isFetching,
436
+ isFetchNextPageError,
437
+ fetchNextPage
438
+ ]);
439
+ return {
440
+ data,
441
+ hasNextPage,
442
+ isFetchingNextPage,
443
+ fetchNextPage,
444
+ isLoading,
445
+ isPlaceholderData,
446
+ isFetching,
447
+ isRefetching,
448
+ fetchStatus,
449
+ isError,
450
+ error,
451
+ refetch,
452
+ setEndOfListElement
453
+ };
454
+ }
455
+ //#endregion
456
+ //#region src/hooks/traces/use-trace-usage.ts
457
+ const INPUT_TOKEN_METRIC = "mastra_model_total_input_tokens";
458
+ const OUTPUT_TOKEN_METRIC = "mastra_model_total_output_tokens";
459
+ const TRACE_IDS_PER_REQUEST = 500;
460
+ function chunkTraceIds(traceIds) {
461
+ const chunks = [];
462
+ for (let index = 0; index < traceIds.length; index += TRACE_IDS_PER_REQUEST) chunks.push(traceIds.slice(index, index + TRACE_IDS_PER_REQUEST));
463
+ return chunks;
464
+ }
465
+ function createTraceUsageAccumulator() {
466
+ return {
467
+ estimatedCost: 0,
468
+ hasEstimatedCost: false,
469
+ costUnits: /* @__PURE__ */ new Set(),
470
+ hasUnknownCostUnit: false
471
+ };
472
+ }
473
+ function addBreakdown(accumulators, response) {
474
+ for (const group of response.groups) {
475
+ const traceId = group.dimensions.traceId;
476
+ const metricName = group.dimensions.name;
477
+ if (!traceId || metricName !== INPUT_TOKEN_METRIC && metricName !== OUTPUT_TOKEN_METRIC) continue;
478
+ const accumulator = getOrCreate(accumulators, traceId, createTraceUsageAccumulator);
479
+ const tokenField = metricName === INPUT_TOKEN_METRIC ? "inputTokens" : "outputTokens";
480
+ accumulator[tokenField] = (accumulator[tokenField] ?? 0) + group.value;
481
+ if (group.estimatedCost == null) continue;
482
+ accumulator.estimatedCost += group.estimatedCost;
483
+ accumulator.hasEstimatedCost = true;
484
+ if (group.costUnit) accumulator.costUnits.add(group.costUnit.toLowerCase());
485
+ else accumulator.hasUnknownCostUnit = true;
486
+ }
487
+ }
488
+ function summarizeUsage(accumulators) {
489
+ const summaries = /* @__PURE__ */ new Map();
490
+ for (const [traceId, accumulator] of accumulators) {
491
+ const summary = {
492
+ inputTokens: accumulator.inputTokens,
493
+ outputTokens: accumulator.outputTokens
494
+ };
495
+ if (accumulator.hasEstimatedCost && !accumulator.hasUnknownCostUnit && accumulator.costUnits.size === 1) {
496
+ summary.estimatedCost = accumulator.estimatedCost;
497
+ summary.costUnit = [...accumulator.costUnits][0];
498
+ }
499
+ summaries.set(traceId, summary);
500
+ }
501
+ return summaries;
502
+ }
503
+ function useTraceUsage({ traceIds, enabled, autoRefetch, queryOptions }) {
504
+ const client = useMastraClient();
505
+ const uniqueTraceIds = [...new Set(traceIds)].toSorted();
506
+ const projectKey = `${client.options.baseUrl || (typeof window === "undefined" ? "local" : window.location.origin || "local")}:${client.options.apiPrefix ?? "/api"}`;
507
+ return useQuery({
508
+ queryKey: [
509
+ "trace-usage",
510
+ projectKey,
511
+ uniqueTraceIds
512
+ ],
513
+ enabled: enabled && uniqueTraceIds.length > 0,
514
+ queryFn: async () => {
515
+ const batches = chunkTraceIds(uniqueTraceIds);
516
+ const responses = await Promise.allSettled(batches.map((batch) => client.getMetricBreakdown({
517
+ name: [INPUT_TOKEN_METRIC, OUTPUT_TOKEN_METRIC],
518
+ aggregation: "sum",
519
+ groupBy: ["traceId", "name"],
520
+ filters: { traceIds: batch },
521
+ limit: batch.length * 2
522
+ })));
523
+ const accumulators = /* @__PURE__ */ new Map();
524
+ for (const response of responses) if (response.status === "fulfilled") addBreakdown(accumulators, response.value);
525
+ return summarizeUsage(accumulators);
526
+ },
527
+ placeholderData: (previousData, previousQuery) => previousQuery?.queryKey[1] === projectKey ? previousData : void 0,
528
+ refetchInterval: enabled && autoRefetch ? 1e4 : false,
529
+ ...queryOptions
530
+ });
531
+ }
532
+ //#endregion
533
+ //#region src/hooks/traces/use-traces.tsx
534
+ const deltaSupportByClient = /* @__PURE__ */ new WeakMap();
535
+ const lightListSupportByClient = /* @__PURE__ */ new WeakMap();
536
+ /** When the current run of light-endpoint 500s started, per client. Cleared by any light success. */
537
+ const lightListFirstServerErrorAtByClient = /* @__PURE__ */ new WeakMap();
538
+ /** A 500 is ambiguous — an old core's store throwing, or a transient fault (DB hiccup, timeout).
539
+ * Serve the request from the full endpoint either way, but only pin the session once the 500s
540
+ * have outlasted a blip; a hiccup would otherwise degrade the list until the tab is reloaded.
541
+ * Elapsed time, not a request count: the page refetch, the delta poll and the status refresh can
542
+ * fail in the same instant, and a fallback response still looks like a success to the delta query,
543
+ * so chase mode keeps re-polling every `deltaChaseIntervalMs` throughout the outage. */
544
+ const LIGHT_LIST_SERVER_ERROR_PIN_AFTER_MS = 1e4;
545
+ const DEFAULT_POLLING_CONFIG = {
546
+ deltaPollIntervalMs: 5e3,
547
+ deltaChaseIntervalMs: 100,
548
+ deltaLimit: 100,
549
+ pageModeRefetchIntervalMs: 1e4,
550
+ page0StatusRefreshIntervalMs: 6e4,
551
+ idleGuardThresholdMs: 15 * 6e4,
552
+ minRefetchSpinMs: 400,
553
+ deltaHighlightMs: 1e3
554
+ };
555
+ /** Returns true when the cursor should be considered stale and re-seeded.
556
+ * Exported for testing — pure function of timestamps. */
557
+ function shouldResetAfterIdle(lastSuccessAt, now, thresholdMs) {
558
+ if (lastSuccessAt === 0) return false;
559
+ return now - lastSuccessAt > thresholdMs;
560
+ }
561
+ function isHttp501(error) {
562
+ return error?.status === 501;
563
+ }
564
+ /** Only 404 and 500 can mean the light endpoint isn't served: 404 from servers without
565
+ * the route, 500 from cores whose store throws instead of serving the projection.
566
+ * Anything else (401, 403, 429, other 5xx, the 501 disabled-domain signal) is a
567
+ * condition the full endpoint would hit too, so it propagates instead of falling
568
+ * back — mirroring how the delta-support cache matches exactly 501. */
569
+ function lightListFallbackStatus(error) {
570
+ const status = error?.status;
571
+ return status === 404 || status === 500 ? status : void 0;
572
+ }
573
+ /** Whether a failed light-list request should pin the session to the full endpoint.
574
+ * `firstServerErrorAt` is undefined when this 500 opens a new run of them, so a single
575
+ * fault never pins. Exported for testing — pure function of the status and timestamps. */
576
+ function shouldPinLightList(status, firstServerErrorAt, now) {
577
+ if (status === 404) return true;
578
+ if (status !== 500) return false;
579
+ if (firstServerErrorAt === void 0) return false;
580
+ return now - firstServerErrorAt >= LIGHT_LIST_SERVER_ERROR_PIN_AFTER_MS;
581
+ }
582
+ const fetchTracesFn = async (args) => {
583
+ const { client, filters, listMode = "traces" } = args;
584
+ const params = args.mode === "delta" ? {
585
+ mode: "delta",
586
+ after: args.after,
587
+ limit: args.limit,
588
+ filters
589
+ } : {
590
+ pagination: {
591
+ page: args.page,
592
+ perPage: args.perPage
593
+ },
594
+ filters
595
+ };
596
+ if (listMode === "branches") return client.listBranches(params);
597
+ if (lightListSupportByClient.get(client) === "unsupported") return client.listTraces(params);
598
+ try {
599
+ const response = await client.listTracesLight(params);
600
+ if (args.mode !== "delta") {
601
+ const spans = response.spans ?? [];
602
+ if (spans.length > 0 && spans.every((span) => span.status === void 0)) {
603
+ lightListSupportByClient.set(client, "unsupported");
604
+ return client.listTraces(params);
605
+ }
606
+ }
607
+ lightListFirstServerErrorAtByClient.delete(client);
608
+ return response;
609
+ } catch (error) {
610
+ const status = lightListFallbackStatus(error);
611
+ if (status === void 0) throw error;
612
+ const now = Date.now();
613
+ const firstServerErrorAt = lightListFirstServerErrorAtByClient.get(client);
614
+ if (status === 500 && firstServerErrorAt === void 0) lightListFirstServerErrorAtByClient.set(client, now);
615
+ if (shouldPinLightList(status, firstServerErrorAt, now)) lightListSupportByClient.set(client, "unsupported");
616
+ return client.listTraces(params);
617
+ }
618
+ };
619
+ const TRACES_PER_PAGE = 25;
620
+ /** Returns the next page number if the server indicates more pages are available. */
621
+ function getTracesNextPageParam(lastPage, _allPages, lastPageParam) {
622
+ if (lastPage?.pagination?.hasMore) return lastPageParam + 1;
623
+ }
624
+ /** Branch rows are full spans and trace rows are lightweight; the list only reads the
625
+ * fields they share, so both are surfaced as `LightSpanRecord`. */
626
+ function getPageSpans(page) {
627
+ if ("branches" in page) return page.branches ?? [];
628
+ return page.spans ?? [];
629
+ }
630
+ /** Deduplicates trace/branch rows by traceId + spanId across all loaded pages.
631
+ * Also surfaces page 0's deltaCursor so the live-tail query can read it reactively. */
632
+ function selectUniqueTraces(data) {
633
+ const seen = /* @__PURE__ */ new Set();
634
+ return {
635
+ spans: data.pages.flatMap((page) => getPageSpans(page)).filter((span) => {
636
+ const key = `${span.traceId}:${span.spanId}`;
637
+ if (seen.has(key)) return false;
638
+ seen.add(key);
639
+ return true;
640
+ }),
641
+ deltaCursor: data.pages[0]?.deltaCursor
642
+ };
643
+ }
644
+ function rowKey(row) {
645
+ return `${row.traceId}:${row.spanId}`;
646
+ }
647
+ function indexRowsByKey(rows) {
648
+ return new Map(rows.map((row) => [rowKey(row), row]));
649
+ }
650
+ /** Replaces existing page-0 rows in place (keyed by traceId:spanId) with
651
+ * refreshed copies from the server. Rows the server doesn't return are kept
652
+ * as-is so delta-accumulated rows that have aged off the server's page 0
653
+ * aren't dropped from the UI. New rows aren't added here — delta polling
654
+ * delivers those. */
655
+ function refreshPage0Rows(old, refreshed, listMode) {
656
+ if (!old || old.pages.length === 0) return old;
657
+ const [firstPage, ...rest] = old.pages;
658
+ if (!firstPage) return old;
659
+ let updatedFirst;
660
+ if (listMode === "branches" && "branches" in firstPage && "branches" in refreshed) {
661
+ const refreshedByKey = indexRowsByKey(refreshed.branches ?? []);
662
+ if (refreshedByKey.size === 0) return old;
663
+ updatedFirst = {
664
+ ...firstPage,
665
+ branches: (firstPage.branches ?? []).map((existing) => refreshedByKey.get(rowKey(existing)) ?? existing)
666
+ };
667
+ } else if ("spans" in firstPage && "spans" in refreshed) {
668
+ const refreshedByKey = indexRowsByKey(refreshed.spans ?? []);
669
+ if (refreshedByKey.size === 0) return old;
670
+ updatedFirst = {
671
+ ...firstPage,
672
+ spans: (firstPage.spans ?? []).map((existing) => refreshedByKey.get(rowKey(existing)) ?? existing)
673
+ };
674
+ } else return old;
675
+ return {
676
+ ...old,
677
+ pages: [updatedFirst, ...rest]
678
+ };
679
+ }
680
+ /** Stable `startedAt DESC` sort matching the server's default page-mode
681
+ * ordering for both list endpoints. Rows missing `startedAt` sink to the
682
+ * bottom (compared as time 0). */
683
+ function sortRowsByStartedAtDesc(rows) {
684
+ return [...rows].sort((a, b) => {
685
+ const aTime = a.startedAt ? new Date(a.startedAt).getTime() : 0;
686
+ return (b.startedAt ? new Date(b.startedAt).getTime() : 0) - aTime;
687
+ });
688
+ }
689
+ /** Prepends delta-mode rows into page 0 and advances its deltaCursor.
690
+ * Delta responses come back in server cursor order (insertion order into
691
+ * the per-store delta index), not the `startedAt DESC` order page-mode
692
+ * uses — so we re-sort the merged page 0 to match what the user sees on
693
+ * a fresh page-mode load. Cross-page duplication is handled later by
694
+ * selectUniqueTraces. */
695
+ function mergeDeltaIntoPage0(old, delta, listMode) {
696
+ if (!old || old.pages.length === 0) return old;
697
+ const [firstPage, ...rest] = old.pages;
698
+ if (!firstPage) return old;
699
+ const nextCursor = delta.deltaCursor ?? firstPage.deltaCursor;
700
+ let updatedFirst;
701
+ if (listMode === "branches" && "branches" in firstPage) {
702
+ const newRows = delta.branches ?? [];
703
+ updatedFirst = {
704
+ ...firstPage,
705
+ branches: sortRowsByStartedAtDesc([...newRows, ...firstPage.branches ?? []]),
706
+ deltaCursor: nextCursor
707
+ };
708
+ } else if ("spans" in firstPage) {
709
+ const newRows = delta.spans ?? [];
710
+ updatedFirst = {
711
+ ...firstPage,
712
+ spans: sortRowsByStartedAtDesc([...newRows, ...firstPage.spans ?? []]),
713
+ deltaCursor: nextCursor
714
+ };
715
+ } else return old;
716
+ return {
717
+ ...old,
718
+ pages: [updatedFirst, ...rest]
719
+ };
720
+ }
721
+ const useTraces = ({ filters, listMode = "traces", polling = {}, enabled = true, queryOptions }) => {
722
+ const { deltaPollIntervalMs = DEFAULT_POLLING_CONFIG.deltaPollIntervalMs, deltaChaseIntervalMs = DEFAULT_POLLING_CONFIG.deltaChaseIntervalMs, deltaLimit = DEFAULT_POLLING_CONFIG.deltaLimit, pageModeRefetchIntervalMs = DEFAULT_POLLING_CONFIG.pageModeRefetchIntervalMs, page0StatusRefreshIntervalMs = DEFAULT_POLLING_CONFIG.page0StatusRefreshIntervalMs, idleGuardThresholdMs = DEFAULT_POLLING_CONFIG.idleGuardThresholdMs, minRefetchSpinMs = DEFAULT_POLLING_CONFIG.minRefetchSpinMs, deltaHighlightMs = DEFAULT_POLLING_CONFIG.deltaHighlightMs } = polling;
723
+ const client = useMastraClient();
724
+ const queryClient = useQueryClient();
725
+ const { inView: isEndOfListInView, setRef: setEndOfListElement } = useInView();
726
+ const [deltaSupport, setDeltaSupport] = useState(() => deltaSupportByClient.get(client) ?? "unknown");
727
+ const deltaUnsupported = deltaSupport === "unsupported";
728
+ const [autoRefetch, setAutoRefetch] = useState(true);
729
+ const [recentlyAddedKeys, setRecentlyAddedKeys] = useState(() => /* @__PURE__ */ new Set());
730
+ useEffect(() => {
731
+ setRecentlyAddedKeys(/* @__PURE__ */ new Set());
732
+ }, [listMode, filters]);
733
+ const tracesQueryKey = [
734
+ "traces",
735
+ listMode,
736
+ filters
737
+ ];
738
+ const query = useInfiniteQuery({
739
+ queryKey: tracesQueryKey,
740
+ enabled,
741
+ queryFn: ({ pageParam }) => fetchTracesFn({
742
+ client,
743
+ page: pageParam,
744
+ perPage: 25,
745
+ filters,
746
+ listMode
747
+ }),
748
+ initialPageParam: 0,
749
+ getNextPageParam: getTracesNextPageParam,
750
+ select: selectUniqueTraces,
751
+ retry: false,
752
+ refetchInterval: (q) => {
753
+ if (is403ForbiddenError(q.state.error)) return false;
754
+ if (!autoRefetch) return false;
755
+ return deltaUnsupported ? pageModeRefetchIntervalMs : false;
756
+ },
757
+ ...queryOptions?.traces
758
+ });
759
+ const cursor = query.data?.deltaCursor;
760
+ useEffect(() => {
761
+ if (query.isSuccess && cursor === void 0 && deltaSupport === "unknown") {
762
+ deltaSupportByClient.set(client, "unsupported");
763
+ setDeltaSupport("unsupported");
764
+ }
765
+ }, [
766
+ query.isSuccess,
767
+ cursor,
768
+ deltaSupport,
769
+ client
770
+ ]);
771
+ const deltaQuery = useQuery({
772
+ queryKey: [
773
+ "traces-delta",
774
+ listMode,
775
+ filters
776
+ ],
777
+ queryFn: () => {
778
+ const current = queryClient.getQueryData(tracesQueryKey)?.pages[0]?.deltaCursor;
779
+ if (!current) return null;
780
+ return fetchTracesFn({
781
+ client,
782
+ mode: "delta",
783
+ after: current,
784
+ limit: deltaLimit,
785
+ filters,
786
+ listMode
787
+ });
788
+ },
789
+ enabled: enabled && !!cursor && !deltaUnsupported && autoRefetch,
790
+ retry: false,
791
+ refetchInterval: (q) => {
792
+ if (q.state.error) return false;
793
+ if (q.state.data?.delta?.hasMore) return deltaChaseIntervalMs;
794
+ return deltaPollIntervalMs;
795
+ },
796
+ ...queryOptions?.delta
797
+ });
798
+ useEffect(() => {
799
+ const result = deltaQuery.data;
800
+ if (!result) return;
801
+ queryClient.setQueryData(tracesQueryKey, (old) => mergeDeltaIntoPage0(old, result, listMode));
802
+ const newRows = listMode === "branches" && "branches" in result ? result.branches ?? [] : "spans" in result ? result.spans ?? [] : [];
803
+ if (newRows.length === 0) return;
804
+ const keys = newRows.map((r) => `${r.traceId}:${r.spanId ?? ""}`);
805
+ setRecentlyAddedKeys((prev) => {
806
+ const next = new Set(prev);
807
+ for (const k of keys) next.add(k);
808
+ return next;
809
+ });
810
+ setTimeout(() => {
811
+ setRecentlyAddedKeys((prev) => {
812
+ const next = new Set(prev);
813
+ for (const k of keys) next.delete(k);
814
+ return next;
815
+ });
816
+ }, deltaHighlightMs);
817
+ }, [
818
+ deltaQuery.data,
819
+ queryClient,
820
+ listMode,
821
+ filters,
822
+ deltaHighlightMs
823
+ ]);
824
+ useEffect(() => {
825
+ if (isHttp501(deltaQuery.error)) {
826
+ deltaSupportByClient.set(client, "unsupported");
827
+ setDeltaSupport("unsupported");
828
+ }
829
+ }, [deltaQuery.error, client]);
830
+ const statusRefreshQuery = useQuery({
831
+ queryKey: [
832
+ "traces-status-refresh",
833
+ listMode,
834
+ filters
835
+ ],
836
+ queryFn: () => fetchTracesFn({
837
+ client,
838
+ page: 0,
839
+ perPage: 25,
840
+ filters,
841
+ listMode
842
+ }),
843
+ enabled: enabled && !!cursor && !deltaUnsupported && autoRefetch,
844
+ refetchInterval: page0StatusRefreshIntervalMs,
845
+ refetchOnMount: false,
846
+ retry: false,
847
+ ...queryOptions?.statusRefresh
848
+ });
849
+ useEffect(() => {
850
+ const result = statusRefreshQuery.data;
851
+ if (!result) return;
852
+ queryClient.setQueryData(tracesQueryKey, (old) => refreshPage0Rows(old, result, listMode));
853
+ }, [
854
+ statusRefreshQuery.data,
855
+ queryClient,
856
+ listMode,
857
+ filters
858
+ ]);
859
+ const lastSuccessAtRef = useRef(0);
860
+ useEffect(() => {
861
+ const ts = Math.max(query.dataUpdatedAt, deltaQuery.dataUpdatedAt, statusRefreshQuery.dataUpdatedAt);
862
+ if (ts > lastSuccessAtRef.current) lastSuccessAtRef.current = ts;
863
+ }, [
864
+ query.dataUpdatedAt,
865
+ deltaQuery.dataUpdatedAt,
866
+ statusRefreshQuery.dataUpdatedAt
867
+ ]);
868
+ const autoRefetchRef = useRef(autoRefetch);
869
+ useEffect(() => {
870
+ autoRefetchRef.current = enabled && autoRefetch;
871
+ }, [enabled, autoRefetch]);
872
+ useEffect(() => {
873
+ const handler = () => {
874
+ if (document.visibilityState !== "visible") return;
875
+ if (!autoRefetchRef.current) return;
876
+ if (!shouldResetAfterIdle(lastSuccessAtRef.current, Date.now(), idleGuardThresholdMs)) return;
877
+ queryClient.resetQueries({ queryKey: [
878
+ "traces",
879
+ listMode,
880
+ filters
881
+ ] });
882
+ };
883
+ document.addEventListener("visibilitychange", handler);
884
+ return () => document.removeEventListener("visibilitychange", handler);
885
+ }, [
886
+ queryClient,
887
+ listMode,
888
+ filters,
889
+ idleGuardThresholdMs
890
+ ]);
891
+ const { hasNextPage, isFetchingNextPage, fetchNextPage } = query;
892
+ useEffect(() => {
893
+ if (enabled && isEndOfListInView && hasNextPage && !isFetchingNextPage) fetchNextPage();
894
+ }, [
895
+ enabled,
896
+ isEndOfListInView,
897
+ hasNextPage,
898
+ isFetchingNextPage,
899
+ fetchNextPage
900
+ ]);
901
+ const isFetchingAny = query.isFetching || statusRefreshQuery.isFetching || deltaQuery.isFetching;
902
+ const lastActivityAt = Math.max(query.dataUpdatedAt, query.errorUpdatedAt, deltaQuery.dataUpdatedAt, deltaQuery.errorUpdatedAt, statusRefreshQuery.dataUpdatedAt, statusRefreshQuery.errorUpdatedAt);
903
+ const [pulse, setPulse] = useState(false);
904
+ const prevActivityAtRef = useRef(lastActivityAt);
905
+ useEffect(() => {
906
+ if (lastActivityAt > prevActivityAtRef.current) {
907
+ prevActivityAtRef.current = lastActivityAt;
908
+ setPulse(true);
909
+ const t = setTimeout(() => setPulse(false), minRefetchSpinMs);
910
+ return () => clearTimeout(t);
911
+ }
912
+ }, [lastActivityAt, minRefetchSpinMs]);
913
+ const isRefetching = isFetchingAny || pulse;
914
+ return {
915
+ ...query,
916
+ setEndOfListElement,
917
+ isRefetching,
918
+ autoRefetch,
919
+ setAutoRefetch,
920
+ recentlyAddedKeys
921
+ };
922
+ };
923
+ //#endregion
924
+ //#region src/hooks/traces/use-create-feedback.tsx
925
+ /**
926
+ * Submits a free-text comment as a feedback record, scoped to the trace or to a
927
+ * single span, then invalidates the matching feedback list so it refreshes.
928
+ */
929
+ const useCreateFeedback = ({ traceId, spanId, queryOptions }) => {
930
+ const client = useMastraClient();
931
+ const queryClient = useQueryClient();
932
+ return useMutation({
933
+ mutationFn: ({ text }) => client.createFeedback({ feedback: {
934
+ traceId,
935
+ ...spanId ? { spanId } : {},
936
+ feedbackType: "comment",
937
+ feedbackSource: "user",
938
+ value: text
939
+ } }),
940
+ onSuccess: () => queryClient.invalidateQueries({ queryKey: spanId ? [
941
+ "span-feedback",
942
+ traceId,
943
+ spanId
944
+ ] : ["trace-feedback", traceId] }),
945
+ ...queryOptions
946
+ });
947
+ };
948
+ //#endregion
949
+ //#region src/hooks/traces/use-delete-feedback.tsx
950
+ /**
951
+ * Deletes a single feedback record by id, then invalidates the matching
952
+ * feedback list (trace- or span-scoped) so it refreshes.
953
+ */
954
+ const useDeleteFeedback = ({ traceId, spanId, queryOptions }) => {
955
+ const client = useMastraClient();
956
+ const queryClient = useQueryClient();
957
+ return useMutation({
958
+ mutationFn: ({ feedbackId }) => client.deleteFeedback({ feedbackIds: [feedbackId] }),
959
+ onSuccess: () => queryClient.invalidateQueries({ queryKey: spanId ? [
960
+ "span-feedback",
961
+ traceId,
962
+ spanId
963
+ ] : ["trace-feedback", traceId] }),
964
+ ...queryOptions
965
+ });
966
+ };
967
+ //#endregion
968
+ //#region src/hooks/traces/use-span-feedback.tsx
969
+ /**
970
+ * Feedback scoped to a single span. Both identifiers are required: without a `spanId`
971
+ * the query stays disabled rather than falling back to trace-wide feedback.
972
+ *
973
+ * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
974
+ */
975
+ const useSpanFeedback = ({ traceId = "", spanId = "", page, queryOptions }) => {
976
+ const client = useMastraClient();
977
+ const pageNumber = page ?? 0;
978
+ return useQuery({
979
+ queryKey: [
980
+ "span-feedback",
981
+ traceId,
982
+ spanId,
983
+ pageNumber
984
+ ],
985
+ queryFn: () => client.listFeedback({
986
+ filters: {
987
+ traceId,
988
+ spanId
989
+ },
990
+ pagination: {
991
+ page: pageNumber,
992
+ perPage: 10
993
+ }
994
+ }),
995
+ refetchInterval: getFeedbackRefetchInterval,
996
+ gcTime: 0,
997
+ staleTime: 0,
998
+ ...queryOptions
999
+ });
1000
+ };
1001
+ //#endregion
1002
+ //#region src/hooks/traces/use-trace-feedback.tsx
1003
+ /** Loads a page of trace-level feedback and stops polling when storage cannot serve feedback. */
1004
+ /**
1005
+ * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
1006
+ */
1007
+ const useTraceFeedback = ({ traceId = "", page, queryOptions }) => {
1008
+ const client = useMastraClient();
1009
+ const pageNumber = page ?? 0;
1010
+ return useQuery({
1011
+ queryKey: [
1012
+ "trace-feedback",
1013
+ traceId,
1014
+ pageNumber
1015
+ ],
1016
+ queryFn: () => client.listFeedback({
1017
+ filters: { traceId },
1018
+ pagination: {
1019
+ page: pageNumber,
1020
+ perPage: 10
1021
+ }
1022
+ }),
1023
+ select: (data) => {
1024
+ const feedback = data.feedback.filter((item) => !item.spanId);
1025
+ if (!data.pagination) return {
1026
+ ...data,
1027
+ feedback
1028
+ };
1029
+ return {
1030
+ ...data,
1031
+ feedback,
1032
+ pagination: {
1033
+ ...data.pagination,
1034
+ total: feedback.length
1035
+ }
1036
+ };
1037
+ },
1038
+ refetchInterval: getFeedbackRefetchInterval,
1039
+ gcTime: 0,
1040
+ staleTime: 0,
1041
+ ...queryOptions
1042
+ });
1043
+ };
1044
+ //#endregion
1045
+ //#region src/hooks/traces/use-trace-metadata-filter-fields.ts
1046
+ const DISCOVERY_LIMIT = 100;
1047
+ const EMPTY_FIELDS = {
1048
+ canonicalFields: [],
1049
+ observedFields: [],
1050
+ observedFieldsTruncated: false
1051
+ };
1052
+ const TRACE_QUERY_DISCOVERY_UNSUPPORTED = "TRACE_QUERY_DISCOVERY_UNSUPPORTED";
1053
+ const isDiscoveryUnsupportedError = (error) => error instanceof MastraClientError && typeof error.body === "object" && error.body !== null && error.body.code === TRACE_QUERY_DISCOVERY_UNSUPPORTED;
1054
+ const traceQueryFieldsQueryKey = (timeRange) => [
1055
+ "trace-query-fields",
1056
+ timeRange.from,
1057
+ timeRange.to
1058
+ ];
1059
+ /** Lazy FilterBar suggestions resolver backed by the value-discovery endpoint for one
1060
+ * `predicateScope` + `path`. the caller owns debounce/abort; this only fetches. */
1061
+ const createTraceQueryValuesResolver = (client, timeRange, predicateScope, path) => {
1062
+ return async ({ query: search, signal }) => {
1063
+ const { values } = await client.getTraceQueryValues({
1064
+ timeRange,
1065
+ predicateScope,
1066
+ path,
1067
+ search: search.trim() || void 0,
1068
+ limit: DISCOVERY_LIMIT
1069
+ }, { signal });
1070
+ return values.map(({ value }) => ({ value }));
1071
+ };
1072
+ };
1073
+ /**
1074
+ * Discovers the `metadata.*` fields observed on traces in the given time range and returns
1075
+ * them as filter bar fields, each with a lazy `suggestions` resolver that fetches the field's
1076
+ * values when the user opens the value step (the caller owns debounce/abort).
1077
+ *
1078
+ * Resolves to an empty field list when the server or store does not support discovery
1079
+ * (`TRACE_QUERY_DISCOVERY_UNSUPPORTED`) so callers never stay blocked.
1080
+ */
1081
+ const useTraceMetadataFilterFields = ({ timeRange, queryOptions }) => {
1082
+ const client = useMastraClient();
1083
+ const query = useQuery({
1084
+ queryKey: traceQueryFieldsQueryKey(timeRange),
1085
+ queryFn: async ({ signal }) => {
1086
+ try {
1087
+ return await client.getTraceQueryFields({
1088
+ timeRange,
1089
+ predicateScope: "trace",
1090
+ limit: DISCOVERY_LIMIT
1091
+ }, { signal });
1092
+ } catch (error) {
1093
+ if (isDiscoveryUnsupportedError(error)) return EMPTY_FIELDS;
1094
+ throw error;
1095
+ }
1096
+ },
1097
+ retry: false,
1098
+ staleTime: DISCOVERY_STALE_TIME,
1099
+ placeholderData: keepPreviousData,
1100
+ ...queryOptions
1101
+ });
1102
+ const observedFields = query.data?.observedFields;
1103
+ return {
1104
+ fields: useMemo(() => (observedFields ?? []).map((field) => ({
1105
+ path: field.path,
1106
+ suggestions: createTraceQueryValuesResolver(client, timeRange, "trace", field.path)
1107
+ })), [
1108
+ observedFields,
1109
+ client,
1110
+ timeRange
1111
+ ]),
1112
+ isLoading: query.isLoading,
1113
+ error: query.error
1114
+ };
1115
+ };
1116
+ //#endregion
1117
+ //#region src/hooks/traces/use-trace-column-preferences-storage-key.ts
1118
+ /**
1119
+ * Storage key for the trace list column preferences, scoped to the Mastra server the client
1120
+ * talks to so each project keeps its own column layout.
1121
+ */
1122
+ function useTraceColumnPreferencesStorageKey() {
1123
+ const client = useMastraClient();
1124
+ return `mastra:traces:columns:${client.options.baseUrl || (typeof window === "undefined" ? "local" : window.location.origin || "local")}:${client.options.apiPrefix ?? "/api"}`;
1125
+ }
1126
+ //#endregion
1127
+ export { DISCOVERY_STALE_TIME, ROOT_ENTITY_TYPES, TRACES_PER_PAGE, TRACE_QUERY_PER_PAGE, createTraceQueryValuesResolver, getLegacyTraceQueryNextPageParam, getTraceQueryNextPageParam, getTracesNextPageParam, lightSpanToTraceQueryTrace, mergeDeltaIntoPage0, refreshPage0Rows, selectLegacyTraceQueryTraces, selectTraceQueryTraces, selectUniqueTraces, shouldPinLightList, shouldResetAfterIdle, traceQueryFieldsQueryKey, traceSpansQueryOptions, useBranch, useCreateFeedback, useDeleteFeedback, useEntityNames, useEnvironments, useFetchTraceSpans, useServiceNames, useSpanDetail, useSpanFeedback, useTags, useThreadHasOtherTraces, useTraceColumnPreferencesStorageKey, useTraceFeedback, useTraceLightSpans, useTraceMetadataFilterFields, useTraceOrBranchSpans, useTraceQuery, useTraceSpans, useTraceSpansQueries, useTraceUsage, useTraces };
1128
+
1129
+ //# sourceMappingURL=index.js.map