@mastra/react 1.12.0-alpha.10 → 1.12.0-alpha.12
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.
- package/dist/{accumulator-C8kIc450.js → accumulator-BfvVnXJr.js} +1 -2
- package/dist/{accumulator-C8kIc450.js.map → accumulator-BfvVnXJr.js.map} +1 -1
- package/dist/{accumulator-BQGsraqS.cjs → accumulator-CgLQ_3q3.cjs} +1 -2
- package/dist/{accumulator-BQGsraqS.cjs.map → accumulator-CgLQ_3q3.cjs.map} +1 -1
- package/dist/chat/index.cjs +1 -1
- package/dist/chat/index.js +1 -2
- package/dist/combine-by-ids-D_lp6Dvq.cjs.map +1 -1
- package/dist/experiments-B7vRMK5T.js +306 -0
- package/dist/experiments-B7vRMK5T.js.map +1 -0
- package/dist/experiments-CJw1N3FB.cjs +353 -0
- package/dist/experiments-CJw1N3FB.cjs.map +1 -0
- package/dist/hooks/agents/index.cjs +2 -2
- package/dist/hooks/agents/index.cjs.map +1 -1
- package/dist/hooks/agents/index.js +2 -2
- package/dist/hooks/agents/index.js.map +1 -1
- package/dist/hooks/auth/index.cjs +2 -2
- package/dist/hooks/auth/index.cjs.map +1 -1
- package/dist/hooks/auth/index.js +2 -2
- package/dist/hooks/auth/index.js.map +1 -1
- package/dist/hooks/capabilities/index.cjs +1 -1
- package/dist/hooks/capabilities/index.cjs.map +1 -1
- package/dist/hooks/capabilities/index.js +1 -1
- package/dist/hooks/capabilities/index.js.map +1 -1
- package/dist/hooks/configuration/index.cjs.map +1 -1
- package/dist/hooks/datasets/index.cjs +25 -1
- package/dist/hooks/datasets/index.cjs.map +1 -1
- package/dist/hooks/datasets/index.js +25 -2
- package/dist/hooks/datasets/index.js.map +1 -1
- package/dist/hooks/datasets/use-datasets.d.ts +7 -0
- package/dist/hooks/datasets/use-datasets.d.ts.map +1 -1
- package/dist/hooks/embedders/index.cjs.map +1 -1
- package/dist/hooks/experiments/index.cjs +9 -235
- package/dist/hooks/experiments/index.d.ts +1 -0
- package/dist/hooks/experiments/index.d.ts.map +1 -1
- package/dist/hooks/experiments/index.js +1 -229
- package/dist/hooks/experiments/usage-accumulator.d.ts +25 -0
- package/dist/hooks/experiments/usage-accumulator.d.ts.map +1 -0
- package/dist/hooks/experiments/use-experiment-item-usage.d.ts +2 -7
- package/dist/hooks/experiments/use-experiment-item-usage.d.ts.map +1 -1
- package/dist/hooks/experiments/use-experiments-list-metrics.d.ts +19 -0
- package/dist/hooks/experiments/use-experiments-list-metrics.d.ts.map +1 -0
- package/dist/hooks/feedback/index.cjs.map +1 -1
- package/dist/hooks/llm/index.cjs.map +1 -1
- package/dist/hooks/logs/index.cjs.map +1 -1
- package/dist/hooks/mcps/index.cjs.map +1 -1
- package/dist/hooks/memory/index.cjs +10 -10
- package/dist/hooks/memory/index.cjs.map +1 -1
- package/dist/hooks/memory/index.js +10 -10
- package/dist/hooks/memory/index.js.map +1 -1
- package/dist/hooks/metrics/index.cjs +13 -11
- package/dist/hooks/metrics/index.cjs.map +1 -1
- package/dist/hooks/metrics/index.js +13 -11
- package/dist/hooks/metrics/index.js.map +1 -1
- package/dist/hooks/processors/index.cjs.map +1 -1
- package/dist/hooks/prompt-blocks/index.cjs.map +1 -1
- package/dist/hooks/query/index.cjs.map +1 -1
- package/dist/hooks/review/index.cjs +2 -2
- package/dist/hooks/review/index.cjs.map +1 -1
- package/dist/hooks/review/index.js +1 -1
- package/dist/hooks/schedules/index.cjs.map +1 -1
- package/dist/hooks/scores/index.cjs.map +1 -1
- package/dist/hooks/templates/index.cjs +20 -18
- package/dist/hooks/templates/index.cjs.map +1 -1
- package/dist/hooks/templates/index.js +20 -18
- package/dist/hooks/templates/index.js.map +1 -1
- package/dist/hooks/tool-providers/index.cjs +1 -1
- package/dist/hooks/tool-providers/index.cjs.map +1 -1
- package/dist/hooks/tool-providers/index.js +1 -1
- package/dist/hooks/tool-providers/index.js.map +1 -1
- package/dist/hooks/tools/index.cjs.map +1 -1
- package/dist/hooks/traces/index.cjs +4 -4
- package/dist/hooks/traces/index.cjs.map +1 -1
- package/dist/hooks/traces/index.js +4 -4
- package/dist/hooks/traces/index.js.map +1 -1
- package/dist/hooks/vectors/index.cjs.map +1 -1
- package/dist/hooks/voice/index.cjs.map +1 -1
- package/dist/hooks/workflows/index.cjs +1 -1
- package/dist/hooks/workflows/index.cjs.map +1 -1
- package/dist/hooks/workflows/index.js +1 -1
- package/dist/hooks/workspace/index.cjs +1 -1
- package/dist/hooks/workspace/index.cjs.map +1 -1
- package/dist/hooks/workspace/index.js +1 -1
- package/dist/hooks/workspace/index.js.map +1 -1
- package/dist/{hooks-CIutb3DO.cjs → hooks-B1i-oHae.cjs} +6 -4
- package/dist/hooks-B1i-oHae.cjs.map +1 -0
- package/dist/{hooks-FVbeHlov.js → hooks-CLfMO5cH.js} +6 -4
- package/dist/{hooks-FVbeHlov.js.map → hooks-CLfMO5cH.js.map} +1 -1
- package/dist/{hooks-_YevKidX.cjs → hooks-D8nOYPUd.cjs} +2 -2
- package/dist/hooks-D8nOYPUd.cjs.map +1 -0
- package/dist/{hooks-0L0RNfau.js → hooks-NaZLZreZ.js} +2 -2
- package/dist/{hooks-0L0RNfau.js.map → hooks-NaZLZreZ.js.map} +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/mastra-client-context-DzX3f0RF.cjs.map +1 -1
- package/dist/ui/index.cjs +4 -4
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.js +3 -3
- package/dist/ui/index.js.map +1 -1
- package/dist/use-in-view-B6eJO9Zi.cjs.map +1 -1
- package/dist/voice-BOtUdMi8.cjs.map +1 -1
- package/package.json +3 -3
- package/dist/hooks/experiments/index.cjs.map +0 -1
- package/dist/hooks/experiments/index.js.map +0 -1
- package/dist/hooks-CIutb3DO.cjs.map +0 -1
- package/dist/hooks-_YevKidX.cjs.map +0 -1
|
@@ -3,13 +3,13 @@ import { t as getOrCreate } from "../../map-CDv4fbu4.js";
|
|
|
3
3
|
import { useMemo, useRef } from "react";
|
|
4
4
|
import { useQuery } from "@tanstack/react-query";
|
|
5
5
|
//#region src/hooks/metrics/metrics-query-filters.ts
|
|
6
|
-
const DEFAULT_WINDOW_MS =
|
|
6
|
+
const DEFAULT_WINDOW_MS = 864e5;
|
|
7
7
|
const PRESET_MS = {
|
|
8
8
|
"24h": DEFAULT_WINDOW_MS,
|
|
9
|
-
"3d":
|
|
10
|
-
"7d":
|
|
11
|
-
"14d":
|
|
12
|
-
"30d":
|
|
9
|
+
"3d": 2592e5,
|
|
10
|
+
"7d": 6048e5,
|
|
11
|
+
"14d": 12096e5,
|
|
12
|
+
"30d": 2592e6
|
|
13
13
|
};
|
|
14
14
|
function buildTimestamp(preset, customRange, anchor) {
|
|
15
15
|
if (preset !== "custom") {
|
|
@@ -160,9 +160,9 @@ function formatShortDate(value, { locale, now, timeZone } = {}) {
|
|
|
160
160
|
return getFormatter(calendarDate(date, timeZone).year === calendarDate(reference, timeZone).year ? "dayMonth" : "dayMonthYear", locale, timeZone).format(date);
|
|
161
161
|
}
|
|
162
162
|
const LONG_RELATIVE_UNITS = [
|
|
163
|
-
["year",
|
|
164
|
-
["month",
|
|
165
|
-
["week",
|
|
163
|
+
["year", 31536e3],
|
|
164
|
+
["month", 2592e3],
|
|
165
|
+
["week", 604800],
|
|
166
166
|
["day", 86400],
|
|
167
167
|
["hour", 3600],
|
|
168
168
|
["minute", 60]
|
|
@@ -212,7 +212,7 @@ function formatDate(value, preset, options = {}) {
|
|
|
212
212
|
unit: "h"
|
|
213
213
|
},
|
|
214
214
|
{
|
|
215
|
-
limit:
|
|
215
|
+
limit: 6048e5,
|
|
216
216
|
size: 864e5,
|
|
217
217
|
unit: "d"
|
|
218
218
|
}
|
|
@@ -231,7 +231,7 @@ function formatDate(value, preset, options = {}) {
|
|
|
231
231
|
}
|
|
232
232
|
//#endregion
|
|
233
233
|
//#region src/hooks/metrics/metrics-interval.ts
|
|
234
|
-
const HOURLY_MAX_RANGE_MS =
|
|
234
|
+
const HOURLY_MAX_RANGE_MS = 1728e5;
|
|
235
235
|
/** Hourly buckets up to 48h, daily buckets beyond, so long ranges stay readable. */
|
|
236
236
|
function chooseMetricsInterval({ start, end }) {
|
|
237
237
|
return end.getTime() - start.getTime() <= HOURLY_MAX_RANGE_MS ? "1h" : "1d";
|
|
@@ -582,7 +582,9 @@ function useScoresMetrics(params) {
|
|
|
582
582
|
const series = timeSeriesResults[i]?.series ?? [];
|
|
583
583
|
for (const s of series) for (const point of s.points) {
|
|
584
584
|
const ts = new Date(point.timestamp);
|
|
585
|
-
const
|
|
585
|
+
const hourKey = ts.getHours() * 60 + ts.getMinutes();
|
|
586
|
+
const scorerMap = getOrCreate(hourBuckets, hourKey, () => /* @__PURE__ */ new Map());
|
|
587
|
+
const acc = getOrCreate(scorerMap, scorerId, () => ({
|
|
586
588
|
sum: 0,
|
|
587
589
|
count: 0
|
|
588
590
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["TOP_N"],"sources":["../../../src/hooks/metrics/metrics-query-filters.ts","../../../src/hooks/shared/date-format.ts","../../../src/hooks/metrics/metrics-interval.ts","../../../src/hooks/metrics/use-active-resources-kpi-metrics.tsx","../../../src/hooks/metrics/use-active-threads-kpi-metrics.tsx","../../../src/hooks/metrics/use-agent-runs-kpi-metrics.tsx","../../../src/hooks/metrics/use-latency-metrics.tsx","../../../src/hooks/metrics/use-model-cost-kpi-metrics.tsx","../../../src/hooks/shared/cost.ts","../../../src/hooks/metrics/use-model-usage-cost-metrics.tsx","../../../src/hooks/metrics/use-scores-metrics.tsx","../../../src/hooks/metrics/use-token-usage-by-agent-metrics.tsx","../../../src/hooks/metrics/use-token-usage-timeseries.tsx","../../../src/hooks/metrics/use-top-active-threads-metrics.tsx","../../../src/hooks/metrics/use-top-resources-by-threads-metrics.tsx","../../../src/hooks/metrics/use-total-tokens-kpi-metrics.tsx","../../../src/hooks/metrics/use-trace-volume-metrics.tsx"],"sourcesContent":["import type { EntityType } from '@mastra/core/observability';\nimport { useMemo, useRef } from 'react';\n\nexport type MetricsDatePreset = '24h' | '3d' | '7d' | '14d' | '30d' | 'custom';\n\nexport type MetricsDateRange = { from?: Date; to?: Date };\n\n/** Shape of the dimensional filter object fed into `MetricsFilter` on client\n * calls. Kept compatible with `metricsFilterSchema` in @internal/core — every\n * scalar field maps to a single-string column filter, and `tags` is the only\n * array field (matched via `has()` / equivalent on backends). */\nexport type MetricsDimensionalFilter = {\n rootEntityType?: EntityType;\n entityName?: string;\n tags?: string[];\n serviceName?: string;\n environment?: string;\n provider?: string;\n model?: string;\n threadId?: string;\n resourceId?: string;\n userId?: string;\n organizationId?: string;\n runId?: string;\n sessionId?: string;\n requestId?: string;\n experimentId?: string;\n};\n\nexport interface MetricsQueryFiltersInput {\n datePreset: MetricsDatePreset;\n customRange: MetricsDateRange | undefined;\n dimensionalFilter: MetricsDimensionalFilter;\n /** Stable JSON representation of `dimensionalFilter`, safe for query keys. */\n dimensionalFilterKey: string;\n}\n\ntype Timestamp = { start: Date; end: Date };\n\nexport interface MetricsQueryFilters {\n datePreset: MetricsDatePreset;\n customRange: MetricsDateRange | undefined;\n timestamp: Timestamp;\n filters: MetricsDimensionalFilter & { timestamp: Timestamp };\n dimensionalFilter: MetricsDimensionalFilter;\n filterKey: string;\n}\n\nconst DEFAULT_WINDOW_MS = 24 * 60 * 60 * 1000;\n\nconst PRESET_MS: Record<string, number> = {\n '24h': DEFAULT_WINDOW_MS,\n '3d': 3 * 24 * 60 * 60 * 1000,\n '7d': 7 * 24 * 60 * 60 * 1000,\n '14d': 14 * 24 * 60 * 60 * 1000,\n '30d': 30 * 24 * 60 * 60 * 1000,\n};\n\nfunction buildTimestamp(\n preset: MetricsDatePreset,\n customRange: MetricsDateRange | undefined,\n anchor: number,\n): Timestamp {\n if (preset !== 'custom') {\n const ms = PRESET_MS[preset] ?? DEFAULT_WINDOW_MS;\n return { start: new Date(anchor - ms), end: new Date(anchor) };\n }\n return {\n start: customRange?.from ?? new Date(anchor - DEFAULT_WINDOW_MS),\n end: customRange?.to ?? new Date(anchor),\n };\n}\n\n/**\n * Compose a ready-to-use metrics filter object from a date window and a\n * dimensional filter. Pass the result to the metrics hooks.\n *\n * Stability guarantees (important for react-query):\n * - `timestamp` is frozen at the moment the inputs change and does NOT update\n * on every render. Otherwise each render would mint a new `new Date()` and\n * every metrics query would re-fetch on every keystroke.\n * - `filters` and `filterKey` are referentially stable while inputs are\n * unchanged, so `queryKey` hashing is cheap and caches hit.\n */\nexport function useMetricsQueryFilters({\n datePreset,\n customRange,\n dimensionalFilter,\n dimensionalFilterKey,\n}: MetricsQueryFiltersInput): MetricsQueryFilters {\n // Anchor the \"now\" used for preset windows. We only recompute when the\n // preset or custom range changes — this gives a stable timestamp per query\n // boundary rather than a new Date on every render.\n const anchorRef = useRef<{ key: string; anchor: number } | null>(null);\n const windowKey =\n datePreset === 'custom'\n ? `custom:${customRange?.from?.getTime() ?? ''}:${customRange?.to?.getTime() ?? ''}`\n : `preset:${datePreset}`;\n if (!anchorRef.current || anchorRef.current.key !== windowKey) {\n anchorRef.current = { key: windowKey, anchor: Date.now() };\n }\n const anchor = anchorRef.current.anchor;\n\n const timestamp = useMemo(() => buildTimestamp(datePreset, customRange, anchor), [datePreset, customRange, anchor]);\n\n const filters = useMemo(\n () => ({ timestamp, ...dimensionalFilter }),\n // dimensionalFilterKey is a stringified digest, so this dep set gives a\n // stable ref while content is unchanged.\n [timestamp, dimensionalFilterKey],\n );\n\n // filterKey combines window + dimensions so react-query keys are cheap.\n const filterKey = useMemo(() => `${windowKey}|${dimensionalFilterKey}`, [windowKey, dimensionalFilterKey]);\n\n return { datePreset, customRange, timestamp, filters, dimensionalFilter, filterKey };\n}\n","export type DateInput = Date | string | number | null | undefined;\nexport type DatePreset =\n | 'date'\n | 'date-time'\n | 'date-time-seconds'\n | 'day-time-seconds'\n | 'time'\n | 'time-seconds'\n | 'relative-time'\n | 'relative-long';\n\ntype FormatOptions = { locale?: string; now?: Date | number; timeZone?: string };\n\nexport function toDate(value: DateInput): Date | undefined {\n if (value == null) return undefined;\n const date = value instanceof Date ? value : new Date(value);\n return Number.isNaN(date.getTime()) ? undefined : date;\n}\n\nconst PRESET_OPTIONS = {\n time: { hour: 'numeric', minute: '2-digit' },\n 'time-seconds': { hour: 'numeric', minute: '2-digit', second: '2-digit' },\n 'date-time': { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit' },\n 'date-time-seconds': {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n hour: 'numeric',\n minute: '2-digit',\n second: '2-digit',\n },\n 'day-time-seconds': { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', second: '2-digit' },\n calendar: { year: 'numeric', month: 'numeric', day: 'numeric', calendar: 'gregory', numberingSystem: 'latn' },\n dayMonth: { month: 'short', day: 'numeric' },\n dayMonthYear: { month: 'short', day: 'numeric', year: 'numeric' },\n precise: {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n hour: 'numeric',\n minute: '2-digit',\n second: '2-digit',\n fractionalSecondDigits: 3,\n },\n timePrecise: { hour: 'numeric', minute: '2-digit', second: '2-digit', fractionalSecondDigits: 3 },\n} satisfies Record<string, Intl.DateTimeFormatOptions>;\n\ntype FormatterKey = keyof typeof PRESET_OPTIONS;\n\nconst formatters = new Map<string, Intl.DateTimeFormat>();\n\nfunction getFormatter(key: FormatterKey, locale?: string, timeZone?: string) {\n const cacheKey = `${locale ?? ''}|${timeZone ?? ''}|${key}`;\n let formatter = formatters.get(cacheKey);\n if (!formatter) {\n formatter = new Intl.DateTimeFormat(locale, { ...PRESET_OPTIONS[key], timeZone });\n formatters.set(cacheKey, formatter);\n }\n return formatter;\n}\n\nfunction calendarDate(date: Date, timeZone?: string) {\n const parts = getFormatter('calendar', 'en-US', timeZone).formatToParts(date);\n return {\n year: parts.find(part => part.type === 'year')?.value,\n month: parts.find(part => part.type === 'month')?.value,\n day: parts.find(part => part.type === 'day')?.value,\n };\n}\n\n/** Short absolute date without time: `Sep 24` this year, `Sep 24, 2025` otherwise. */\nexport function formatShortDate(value: DateInput, { locale, now, timeZone }: FormatOptions = {}) {\n const date = toDate(value);\n if (!date) return undefined;\n const reference = new Date(now ?? Date.now());\n const key =\n calendarDate(date, timeZone).year === calendarDate(reference, timeZone).year ? 'dayMonth' : 'dayMonthYear';\n return getFormatter(key, locale, timeZone).format(date);\n}\n\nconst LONG_RELATIVE_UNITS: Array<[Intl.RelativeTimeFormatUnit, number]> = [\n ['year', 365 * 86_400],\n ['month', 30 * 86_400],\n ['week', 7 * 86_400],\n ['day', 86_400],\n ['hour', 3_600],\n ['minute', 60],\n];\n\nconst relativeFormatters = new Map<string, Intl.RelativeTimeFormat>();\n\nfunction getRelativeFormatter(locale?: string) {\n const key = locale ?? '';\n let formatter = relativeFormatters.get(key);\n if (!formatter) {\n formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });\n relativeFormatters.set(key, formatter);\n }\n return formatter;\n}\n\n/**\n * Uses the browser locale unless `locale` is given.\n * - `date`: date only; omits the year when it matches `now` in the requested timezone\n * - `date-time`: date, year and time to minutes, including historical dates\n * - `date-time-seconds`: date, year and time to seconds\n * - `day-time-seconds`: month, day and time to seconds, without the year\n * - `time`: time to minutes, without a date\n * - `time-seconds`: time to seconds, without a date\n * - `relative-time`: short relative label; delegates to `date` at seven days\n */\nexport function formatDate(value: DateInput, preset: DatePreset, options: FormatOptions = {}) {\n const date = toDate(value);\n if (!date) return undefined;\n const { locale, now, timeZone } = options;\n\n if (preset === 'relative-time') {\n const diff = date.getTime() - new Date(now ?? Date.now()).getTime();\n const abs = Math.abs(diff);\n if (abs < 5_000) return 'just now';\n const units = [\n { limit: 60_000, size: 1_000, unit: 's' },\n { limit: 3_600_000, size: 60_000, unit: 'm' },\n { limit: 86_400_000, size: 3_600_000, unit: 'h' },\n { limit: 7 * 86_400_000, size: 86_400_000, unit: 'd' },\n ];\n const match = units.find(({ limit }) => abs < limit);\n if (!match) return formatDate(date, 'date', options);\n const label = `${Math.floor(abs / match.size)}${match.unit}`;\n return diff < 0 ? `${label} ago` : `in ${label}`;\n }\n if (preset === 'relative-long') {\n const seconds = (date.getTime() - new Date(now ?? Date.now()).getTime()) / 1000;\n const [unit, size] = LONG_RELATIVE_UNITS.find(([, size]) => Math.abs(seconds) >= size) ?? ['second', 1];\n return getRelativeFormatter(locale).format(Math.round(seconds / size), unit);\n }\n if (preset === 'date') return formatShortDate(date, options);\n\n return getFormatter(preset, locale, timeZone).format(date);\n}\n\n/** Locale-aware compact date range, e.g. `Sep 2 – 5, 2026`. */\nexport function formatDateRange(start: DateInput, end: DateInput, options: Omit<FormatOptions, 'now'> = {}) {\n const from = toDate(start);\n const to = toDate(end);\n if (!from || !to) return undefined;\n return getFormatter('dayMonthYear', options.locale, options.timeZone)\n .formatRange(from, to)\n .replace(/\\u2009/g, ' ');\n}\n\n/** Date and time down to milliseconds, for trace debugging. `withDate: false` keeps only the time. */\nexport function formatTimestampPrecise(\n value: DateInput,\n { locale, withDate = true }: { locale?: string; withDate?: boolean } = {},\n) {\n const date = toDate(value);\n return date ? getFormatter(withDate ? 'precise' : 'timePrecise', locale).format(date) : undefined;\n}\n","import { formatDate, formatShortDate } from '../shared/date-format';\n\nexport type MetricsInterval = '1h' | '1d';\n\nconst HOURLY_MAX_RANGE_MS = 48 * 60 * 60 * 1000;\n\n/** Hourly buckets up to 48h, daily buckets beyond, so long ranges stay readable. */\nexport function chooseMetricsInterval({ start, end }: { start: Date; end: Date }): MetricsInterval {\n return end.getTime() - start.getTime() <= HOURLY_MAX_RANGE_MS ? '1h' : '1d';\n}\n\nexport function formatMetricsBucketLabel(ts: Date, interval: MetricsInterval): string {\n if (interval === '1h') {\n return formatDate(ts, 'time') ?? '';\n }\n return formatShortDate(ts) ?? '';\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Active Resources — number of distinct resource IDs observed in agent runs.\n * Uses approximate `count_distinct` (HyperLogLog on ClickHouse,\n * `approx_count_distinct` on DuckDB) so the query stays fast even on\n * tens of millions of rows. */\nexport function useActiveResourcesKpiMetrics<TData = Awaited<ReturnType<MastraClient['getMetricAggregate']>>>(\n params: MetricsQueryFilters & {\n queryOptions?: MastraQueryOptions<Awaited<ReturnType<MastraClient['getMetricAggregate']>>, TData>;\n },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'active-resources-kpi', filterKey],\n queryFn: () =>\n client.getMetricAggregate({\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count_distinct',\n distinctColumn: 'resourceId' as never,\n filters,\n comparePeriod: 'previous_period',\n }),\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Active Threads — number of distinct thread IDs observed in agent runs.\n * Uses approximate `count_distinct` (HyperLogLog on ClickHouse,\n * `approx_count_distinct` on DuckDB) so the query stays fast even on\n * tens of millions of rows. */\nexport function useActiveThreadsKpiMetrics<TData = Awaited<ReturnType<MastraClient['getMetricAggregate']>>>(\n params: MetricsQueryFilters & {\n queryOptions?: MastraQueryOptions<Awaited<ReturnType<MastraClient['getMetricAggregate']>>, TData>;\n },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'active-threads-kpi', filterKey],\n queryFn: () =>\n client.getMetricAggregate({\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count_distinct',\n distinctColumn: 'threadId' as never,\n filters,\n comparePeriod: 'previous_period',\n }),\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Total Agent Runs — count of agent duration metric observations */\nexport function useAgentRunsKpiMetrics<TData = Awaited<ReturnType<MastraClient['getMetricAggregate']>>>(\n params: MetricsQueryFilters & {\n queryOptions?: MastraQueryOptions<Awaited<ReturnType<MastraClient['getMetricAggregate']>>, TData>;\n },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'agent-runs-kpi', filterKey],\n queryFn: () =>\n client.getMetricAggregate({\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count',\n filters,\n comparePeriod: 'previous_period',\n }),\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport { chooseMetricsInterval, formatMetricsBucketLabel } from './metrics-interval';\nimport type { MetricsInterval } from './metrics-interval';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface LatencyPoint {\n [key: string]: unknown;\n time: string;\n /** Raw timestamp (ms since epoch) for the bucket this point represents.\n * Used by drilldown clicks to compute a narrow time window. */\n tsMs: number;\n p50: number;\n p95: number;\n}\n\nasync function fetchPercentiles(\n client: ReturnType<typeof useMastraClient>,\n metricName: string,\n filters: Record<string, unknown>,\n interval: MetricsInterval,\n): Promise<LatencyPoint[]> {\n const res = await client.getMetricPercentiles({\n name: metricName,\n percentiles: [0.5, 0.95],\n interval,\n filters,\n });\n\n const p50Series = res.series.find(s => s.percentile === 0.5);\n const p95Series = res.series.find(s => s.percentile === 0.95);\n\n if (!p50Series || !p95Series) return [];\n\n const p95Map = new Map(p95Series.points.map(p => [new Date(p.timestamp).getTime(), p.value]));\n\n return p50Series.points.map(p => {\n const ts = new Date(p.timestamp);\n const tsMs = ts.getTime();\n return {\n time: formatMetricsBucketLabel(ts, interval),\n tsMs,\n p50: Math.round(p.value),\n p95: Math.round(p95Map.get(tsMs) ?? 0),\n };\n });\n}\n\nexport interface LatencyMetricsData {\n agentData: LatencyPoint[];\n workflowData: LatencyPoint[];\n toolData: LatencyPoint[];\n interval: MetricsInterval;\n}\n\nexport function useLatencyMetrics<TData = LatencyMetricsData>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<LatencyMetricsData, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { timestamp, filters, filterKey, queryOptions } = params;\n const interval = chooseMetricsInterval(timestamp);\n\n return useQuery({\n queryKey: ['metrics', 'latency', filterKey, interval],\n queryFn: async (): Promise<LatencyMetricsData> => {\n const [agentData, workflowData, toolData] = await Promise.all([\n fetchPercentiles(client, 'mastra_agent_duration_ms', filters, interval),\n fetchPercentiles(client, 'mastra_workflow_duration_ms', filters, interval),\n fetchPercentiles(client, 'mastra_tool_duration_ms', filters, interval),\n ]);\n return { agentData, workflowData, toolData, interval };\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Total Model Cost — sum of estimatedCost across input and output token metrics */\nexport interface ModelCostKpi {\n cost: number | null;\n costUnit: string | null;\n previousCost: number | null;\n costChangePercent: number | null;\n}\n\nexport function useModelCostKpiMetrics<TData = ModelCostKpi>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ModelCostKpi, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'model-cost-kpi', filterKey],\n queryFn: async (): Promise<ModelCostKpi> => {\n const res = await client.getMetricAggregate({\n name: ['mastra_model_total_input_tokens', 'mastra_model_total_output_tokens'],\n aggregation: 'sum',\n filters,\n comparePeriod: 'previous_period',\n });\n\n return {\n cost: res.estimatedCost ?? null,\n costUnit: res.costUnit ?? null,\n previousCost: res.previousEstimatedCost ?? null,\n costChangePercent: res.costChangePercent ?? null,\n };\n },\n ...queryOptions,\n });\n}\n","export interface CompactNumberFormatOptions {\n currency?: string;\n}\n\nconst compactNumber = new Intl.NumberFormat('en-US', { notation: 'compact', maximumSignificantDigits: 3 });\nconst fullNumber = new Intl.NumberFormat('en-US');\n\nconst currencyCodes = new Set(Intl.supportedValuesOf('currency'));\n\nfunction isCurrency(code: string | undefined): code is string {\n return code !== undefined && currencyCodes.has(code.toUpperCase());\n}\n\nfunction money(currency: string, options: Intl.NumberFormatOptions) {\n return new Intl.NumberFormat('en-US', { style: 'currency', currency, ...options });\n}\n\nexport function formatCompactNumber(value: number, { currency }: CompactNumberFormatOptions = {}): string {\n if (!isCurrency(currency)) return compactNumber.format(value);\n const size = Math.abs(value);\n if (size < 100) return formatFullNumber(value, { currency });\n if (size < 1000) return money(currency, { maximumFractionDigits: 0 }).format(value);\n return money(currency, { notation: 'compact', maximumSignificantDigits: 3 }).format(value);\n}\n\nexport function formatFullNumber(value: number, { currency }: CompactNumberFormatOptions = {}): string {\n if (!isCurrency(currency)) return fullNumber.format(value);\n const formatter = money(currency, {});\n const smallestUnit = 10 ** -(formatter.resolvedOptions().maximumFractionDigits ?? 2);\n if (value !== 0 && Math.abs(value) < smallestUnit) {\n return `${value < 0 ? '-' : ''}<${formatter.format(smallestUnit)}`;\n }\n return formatter.format(value);\n}\n\nexport function formatCost(value: number, unit?: string | null): string {\n const isUsd = !unit || unit.toLowerCase() === 'usd';\n const amount = value > 0 && value < 0.01 ? '<0.01' : value.toFixed(2);\n if (!isUsd) return `${amount} ${unit}`;\n return amount.startsWith('<') ? '<$0.01' : `$${amount}`;\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { formatCompactNumber } from '../shared/cost';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface ModelUsageRow {\n model: string;\n provider?: string;\n input: string;\n output: string;\n cacheRead: string;\n cacheWrite: string;\n cost: number | null;\n costUnit: string | null;\n}\n\nexport function useModelUsageCostMetrics<TData = ModelUsageRow[]>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ModelUsageRow[], TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'model-usage-cost', filterKey],\n queryFn: async (): Promise<ModelUsageRow[]> => {\n const [inputRes, outputRes, cacheReadRes, cacheWriteRes] = await Promise.all(\n (\n [\n 'mastra_model_total_input_tokens',\n 'mastra_model_total_output_tokens',\n 'mastra_model_input_cache_read_tokens',\n 'mastra_model_input_cache_write_tokens',\n ] as const\n ).map(name =>\n client.getMetricBreakdown({\n name: [name],\n groupBy: ['model', 'provider'],\n aggregation: 'sum',\n orderDirection: 'DESC',\n filters,\n }),\n ),\n );\n\n if (!inputRes || !outputRes || !cacheReadRes || !cacheWriteRes) return [];\n\n type ModelEntry = {\n model: string;\n provider: string | undefined;\n input: number;\n output: number;\n cacheRead: number;\n cacheWrite: number;\n cost: number | null;\n costUnit: string | null;\n };\n\n const modelMap = new Map<string, ModelEntry>();\n\n const ensureModel = (dimensions: { model?: string | null; provider?: string | null }): ModelEntry => {\n const model = dimensions.model ?? 'unknown';\n const provider = dimensions.provider ?? undefined;\n return getOrCreate(modelMap, `${model}\\u0000${provider ?? ''}`, () => ({\n model,\n provider,\n input: 0,\n output: 0,\n cacheRead: 0,\n cacheWrite: 0,\n cost: null,\n costUnit: null,\n }));\n };\n\n // total_input/total_output estimatedCost already rolls up cache + other detail\n // costs. The cache breakdowns are kept for their token counts only.\n const addCost = (entry: ModelEntry, group: { estimatedCost?: number | null; costUnit?: string | null }) => {\n if (group.estimatedCost != null) {\n entry.cost = (entry.cost ?? 0) + group.estimatedCost;\n if (group.costUnit) entry.costUnit = group.costUnit;\n }\n };\n\n for (const group of inputRes.groups) {\n const entry = ensureModel(group.dimensions);\n entry.input = group.value;\n addCost(entry, group);\n }\n for (const group of outputRes.groups) {\n const entry = ensureModel(group.dimensions);\n entry.output = group.value;\n addCost(entry, group);\n }\n for (const group of cacheReadRes.groups) {\n const entry = ensureModel(group.dimensions);\n entry.cacheRead = group.value;\n }\n for (const group of cacheWriteRes.groups) {\n const entry = ensureModel(group.dimensions);\n entry.cacheWrite = group.value;\n }\n\n return Array.from(modelMap.values())\n .map(vals => ({\n model: vals.model,\n ...(vals.provider ? { provider: vals.provider } : {}),\n input: formatCompactNumber(vals.input),\n output: formatCompactNumber(vals.output),\n cacheRead: formatCompactNumber(vals.cacheRead),\n cacheWrite: formatCompactNumber(vals.cacheWrite),\n cost: vals.cost,\n costUnit: vals.costUnit,\n }))\n .sort((a, b) => a.model.localeCompare(b.model) || (a.provider ?? '').localeCompare(b.provider ?? ''));\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { formatDate } from '../shared/date-format';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface ScorerSummary {\n scorer: string;\n avg: number;\n min: number;\n max: number;\n count: number;\n}\n\nexport interface ScoresOverTimePoint {\n time: string;\n [scorer: string]: string | number;\n}\n\nexport interface ScoresMetricsData {\n summaryData: ScorerSummary[];\n overTimeData: ScoresOverTimePoint[];\n scorerNames: string[];\n avgScore: number | null;\n}\n\nexport function useScoresMetrics<TData = ScoresMetricsData>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ScoresMetricsData, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { datePreset, customRange, timestamp, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'scores-card', datePreset, customRange],\n queryFn: async (): Promise<ScoresMetricsData> => {\n const filters = {\n timestamp: { start: timestamp.start, end: timestamp.end },\n };\n\n const scorersMap = await client.listScorers();\n const scorerIds = Object.keys(scorersMap ?? {});\n\n if (scorerIds.length === 0) {\n return { summaryData: [], overTimeData: [], scorerNames: [], avgScore: null };\n }\n\n // Fetch summary stats first to determine which scorers have data\n const summaryResults = await Promise.all(\n scorerIds.map(async scorerId => {\n const [avg, min, max, count] = await Promise.all([\n client.getScoreAggregate({ scorerId, aggregation: 'avg', filters }),\n client.getScoreAggregate({ scorerId, aggregation: 'min', filters }),\n client.getScoreAggregate({ scorerId, aggregation: 'max', filters }),\n client.getScoreAggregate({ scorerId, aggregation: 'count', filters }),\n ]);\n return {\n scorer: scorerId,\n avg: avg.value ?? 0,\n min: min.value ?? 0,\n max: max.value ?? 0,\n count: count.value ?? 0,\n };\n }),\n );\n\n const summaryData: ScorerSummary[] = summaryResults.filter(s => s.count > 0);\n const scorerNames = summaryData.map(s => s.scorer);\n\n if (summaryData.length === 0) {\n return { summaryData: [], overTimeData: [], scorerNames: [], avgScore: null };\n }\n\n const totalWeighted = summaryData.reduce((s, d) => s + d.avg * d.count, 0);\n const totalCount = summaryData.reduce((s, d) => s + d.count, 0);\n const avgScore = totalCount ? Math.round((totalWeighted / totalCount) * 100) / 100 : 0;\n\n const interval = '1h';\n\n // Fetch hourly time series from the full period for active scorers\n const timeSeriesResults = await Promise.all(\n scorerNames.map(scorerId =>\n client.getScoreTimeSeries({\n scorerId,\n interval,\n aggregation: 'avg',\n filters,\n }),\n ),\n );\n\n // Collapse all days into a single 24-hour view (00:00–23:00).\n // For each hour-of-day, average the values across all days in the range.\n const hourBuckets = new Map<number, Map<string, { sum: number; count: number }>>();\n\n for (let i = 0; i < scorerNames.length; i++) {\n const scorerId = scorerNames[i];\n const series = timeSeriesResults[i]?.series ?? [];\n for (const s of series) {\n for (const point of s.points) {\n const ts = new Date(point.timestamp);\n const hourKey = ts.getHours() * 60 + ts.getMinutes();\n const scorerMap = getOrCreate(hourBuckets, hourKey, () => new Map());\n const acc = getOrCreate(scorerMap, scorerId, () => ({ sum: 0, count: 0 }));\n\n acc.sum += point.value;\n acc.count += 1;\n }\n }\n }\n\n // Build sorted 24h chart data\n const overTimeData: ScoresOverTimePoint[] = Array.from(hourBuckets.entries())\n .sort(([a], [b]) => a - b)\n .map(([hourKey, scorerMap]) => {\n const point: ScoresOverTimePoint = {\n time: formatDate(new Date(2000, 0, 1, Math.floor(hourKey / 60), hourKey % 60), 'time') ?? '',\n };\n for (const [scorerId, acc] of scorerMap) {\n point[scorerId] = +(acc.sum / acc.count).toFixed(2);\n }\n return point;\n });\n\n return {\n summaryData,\n overTimeData,\n scorerNames,\n avgScore,\n };\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface TokenUsageByAgentRow {\n name: string;\n total: number;\n input: number;\n output: number;\n cost: number | null;\n costUnit: string | null;\n}\n\nexport function useTokenUsageByAgentMetrics<TData = TokenUsageByAgentRow[]>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<TokenUsageByAgentRow[], TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'token-usage-by-agent', filterKey],\n queryFn: async (): Promise<TokenUsageByAgentRow[]> => {\n const breakdownBase = {\n groupBy: ['entityName'],\n aggregation: 'sum' as const,\n orderDirection: 'DESC' as const,\n filters,\n };\n // total_input/total_output estimatedCost already rolls up cache + other detail costs.\n const [inputRes, outputRes] = await Promise.all([\n client.getMetricBreakdown({ ...breakdownBase, name: ['mastra_model_total_input_tokens'] }),\n client.getMetricBreakdown({ ...breakdownBase, name: ['mastra_model_total_output_tokens'] }),\n ]);\n\n type AgentEntry = { input: number; output: number; cost: number | null; costUnit: string | null };\n\n const agentMap = new Map<string, AgentEntry>();\n\n const ensure = (name: string): AgentEntry =>\n getOrCreate(agentMap, name, () => ({ input: 0, output: 0, cost: null, costUnit: null }));\n\n const addCost = (entry: AgentEntry, group: { estimatedCost?: number | null; costUnit?: string | null }) => {\n if (group.estimatedCost != null) {\n entry.cost = (entry.cost ?? 0) + group.estimatedCost;\n if (group.costUnit) entry.costUnit = group.costUnit;\n }\n };\n\n for (const group of inputRes.groups) {\n const name = group.dimensions.entityName ?? 'unknown';\n const entry = ensure(name);\n entry.input = group.value;\n addCost(entry, group);\n }\n for (const group of outputRes.groups) {\n const name = group.dimensions.entityName ?? 'unknown';\n const entry = ensure(name);\n entry.output = group.value;\n addCost(entry, group);\n }\n\n return Array.from(agentMap.entries())\n .map(([name, vals]) => ({\n name,\n input: vals.input,\n output: vals.output,\n total: vals.input + vals.output,\n cost: vals.cost,\n costUnit: vals.costUnit,\n }))\n .sort((a, b) => b.total - a.total);\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport { chooseMetricsInterval, formatMetricsBucketLabel } from './metrics-interval';\nimport type { MetricsInterval } from './metrics-interval';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport type TokenUsageTimeSeriesInterval = MetricsInterval;\n\nexport interface TokenTimelinePoint {\n time: string;\n tsMs: number;\n input: number;\n output: number;\n total: number;\n cost: number | null;\n costUnit: string | null;\n}\n\nexport interface TokenUsageTimeSeriesData {\n data: TokenTimelinePoint[];\n interval: TokenUsageTimeSeriesInterval;\n}\n\ntype TimeSeriesPoint = {\n timestamp: string | Date;\n value: number;\n estimatedCost?: number | null;\n};\n\ntype SeriesWithCost = {\n costUnit?: string | null;\n points: TimeSeriesPoint[];\n};\n\ntype TokenTimelineAccumulator = {\n tsMs: number;\n input: number;\n output: number;\n cost: number | null;\n costUnits: Set<string>;\n hasUnknownCostUnit: boolean;\n};\n\nfunction addSeriesPoints(\n pointMap: Map<number, TokenTimelineAccumulator>,\n series: SeriesWithCost | undefined,\n key: 'input' | 'output',\n) {\n for (const point of series?.points ?? []) {\n const tsMs = new Date(point.timestamp).getTime();\n if (!Number.isFinite(tsMs)) continue;\n\n const existing = pointMap.get(tsMs) ?? {\n tsMs,\n input: 0,\n output: 0,\n cost: null,\n costUnits: new Set<string>(),\n hasUnknownCostUnit: false,\n };\n\n existing[key] += point.value;\n\n if (point.estimatedCost != null) {\n existing.cost = (existing.cost ?? 0) + point.estimatedCost;\n if (series?.costUnit) {\n existing.costUnits.add(series.costUnit);\n } else {\n existing.hasUnknownCostUnit = true;\n }\n }\n\n pointMap.set(tsMs, existing);\n }\n}\n\nfunction toCostUnit(entry: TokenTimelineAccumulator): string | null {\n if (entry.cost == null || entry.hasUnknownCostUnit || entry.costUnits.size !== 1) return null;\n return [...entry.costUnits][0] ?? null;\n}\n\nexport function useTokenUsageTimeSeries<TData = TokenUsageTimeSeriesData>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<TokenUsageTimeSeriesData, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { timestamp, filters, filterKey, queryOptions } = params;\n const interval = chooseMetricsInterval(timestamp);\n\n return useQuery({\n queryKey: ['metrics', 'token-usage-timeseries', filterKey, interval],\n queryFn: async (): Promise<TokenUsageTimeSeriesData> => {\n const [inputRes, outputRes] = await Promise.all([\n client.getMetricTimeSeries({\n name: ['mastra_model_total_input_tokens'],\n interval,\n aggregation: 'sum',\n filters,\n }),\n client.getMetricTimeSeries({\n name: ['mastra_model_total_output_tokens'],\n interval,\n aggregation: 'sum',\n filters,\n }),\n ]);\n\n const pointMap = new Map<number, TokenTimelineAccumulator>();\n addSeriesPoints(pointMap, inputRes.series[0], 'input');\n addSeriesPoints(pointMap, outputRes.series[0], 'output');\n\n const data = Array.from(pointMap.values())\n .sort((a, b) => a.tsMs - b.tsMs)\n .map(point => {\n const ts = new Date(point.tsMs);\n return {\n time: formatMetricsBucketLabel(ts, interval),\n tsMs: point.tsMs,\n input: point.input,\n output: point.output,\n total: point.input + point.output,\n cost: point.cost,\n costUnit: toCostUnit(point),\n };\n });\n\n return { data, interval };\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { useMastraClient } from '../../mastra-client-context';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface ActiveThreadRow {\n threadId: string;\n resourceId: string | null;\n runs: number;\n tokens: number;\n cost: number | null;\n costUnit: string | null;\n}\n\nconst TOP_N = 20;\n\n/** Top Active Threads — the threads with the most agent runs in the selected\n * range. Server-side TopK (`ORDER BY value DESC LIMIT 20`) is required so the\n * query never returns the full thread set when cardinality is in the millions.\n *\n * Tokens + cost are joined in from parallel breakdowns on the same `threadId`\n * grouping so we don't need any new backend aggregation support. */\nexport function useTopActiveThreadsMetrics<TData = ActiveThreadRow[]>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ActiveThreadRow[], TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'top-active-threads', filterKey],\n queryFn: async (): Promise<ActiveThreadRow[]> => {\n const breakdownBase = {\n groupBy: ['threadId', 'resourceId'],\n orderDirection: 'DESC' as const,\n filters,\n };\n\n const [runsRes, inputRes, outputRes] = await Promise.all([\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count',\n limit: TOP_N,\n }),\n // Token breakdowns use the same groupBy and a server-side TopK so the\n // response stays bounded even when the underlying thread set has very\n // high cardinality. Threads that are top-N by runs but not by tokens\n // will display 0 tokens (an acceptable approximation in exchange for\n // a bounded query).\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_model_total_input_tokens'],\n aggregation: 'sum',\n limit: TOP_N,\n }),\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_model_total_output_tokens'],\n aggregation: 'sum',\n limit: TOP_N,\n }),\n ]);\n\n type Entry = { tokens: number; cost: number | null; costUnit: string | null };\n const byThread = new Map<string, Entry>();\n\n const ensure = (threadId: string): Entry =>\n getOrCreate(byThread, threadId, () => ({ tokens: 0, cost: null, costUnit: null }));\n\n const foldTokens = (groups: typeof inputRes.groups) => {\n for (const group of groups) {\n const threadId = group.dimensions.threadId;\n if (!threadId) continue;\n const entry = ensure(threadId as string);\n entry.tokens += group.value;\n if (group.estimatedCost != null) {\n entry.cost = (entry.cost ?? 0) + group.estimatedCost;\n if (group.costUnit) entry.costUnit = group.costUnit;\n }\n }\n };\n foldTokens(inputRes.groups);\n foldTokens(outputRes.groups);\n\n return runsRes.groups\n .filter(group => !!group.dimensions.threadId)\n .map(group => {\n const threadId = group.dimensions.threadId as string;\n const extra = byThread.get(threadId);\n return {\n threadId,\n resourceId: (group.dimensions.resourceId as string | undefined) ?? null,\n runs: group.value,\n tokens: extra?.tokens ?? 0,\n cost: extra?.cost ?? null,\n costUnit: extra?.costUnit ?? null,\n };\n });\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { useMastraClient } from '../../mastra-client-context';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface ResourceThreadsRow {\n resourceId: string;\n threadCount: number;\n tokens: number;\n cost: number | null;\n costUnit: string | null;\n}\n\nconst TOP_N = 20;\n\n/** Top Resources by Thread Count — the resources with the most distinct threads\n * in the selected range. Uses `count_distinct(threadId)` per `resourceId`,\n * with server-side TopK (`ORDER BY value DESC LIMIT 20`).\n *\n * Tokens + cost are joined in from parallel breakdowns on `resourceId` so the\n * table can show cost/usage without a separate backend aggregation. */\nexport function useTopResourcesByThreadsMetrics<TData = ResourceThreadsRow[]>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ResourceThreadsRow[], TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'top-resources-by-threads', filterKey],\n queryFn: async (): Promise<ResourceThreadsRow[]> => {\n const breakdownBase = {\n groupBy: ['resourceId'],\n orderDirection: 'DESC' as const,\n filters,\n };\n\n const [threadsRes, inputRes, outputRes] = await Promise.all([\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count_distinct',\n distinctColumn: 'threadId' as never,\n limit: TOP_N,\n }),\n // Token breakdowns use the same groupBy and a server-side TopK so the\n // response stays bounded even when the underlying resource set has very\n // high cardinality. Resources that are top-N by thread count but not by\n // tokens will display 0 tokens (an acceptable approximation in exchange\n // for a bounded query).\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_model_total_input_tokens'],\n aggregation: 'sum',\n limit: TOP_N,\n }),\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_model_total_output_tokens'],\n aggregation: 'sum',\n limit: TOP_N,\n }),\n ]);\n\n type Entry = { tokens: number; cost: number | null; costUnit: string | null };\n const byResource = new Map<string, Entry>();\n\n const ensure = (resourceId: string): Entry =>\n getOrCreate(byResource, resourceId, () => ({ tokens: 0, cost: null, costUnit: null }));\n\n const foldTokens = (groups: typeof inputRes.groups) => {\n for (const group of groups) {\n const resourceId = group.dimensions.resourceId;\n if (!resourceId) continue;\n const entry = ensure(resourceId as string);\n entry.tokens += group.value;\n if (group.estimatedCost != null) {\n entry.cost = (entry.cost ?? 0) + group.estimatedCost;\n if (group.costUnit) entry.costUnit = group.costUnit;\n }\n }\n };\n foldTokens(inputRes.groups);\n foldTokens(outputRes.groups);\n\n return threadsRes.groups\n .filter(group => !!group.dimensions.resourceId)\n .map(group => {\n const resourceId = group.dimensions.resourceId as string;\n const extra = byResource.get(resourceId);\n return {\n resourceId,\n threadCount: group.value,\n tokens: extra?.tokens ?? 0,\n cost: extra?.cost ?? null,\n costUnit: extra?.costUnit ?? null,\n };\n });\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Total Tokens — sum of all input + output tokens */\nexport interface TotalTokensKpi {\n value: number | null;\n previousValue: number | null;\n changePercent: number | null;\n}\n\nexport function useTotalTokensKpiMetrics<TData = TotalTokensKpi>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<TotalTokensKpi, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'total-tokens-kpi', filterKey],\n queryFn: async (): Promise<TotalTokensKpi> => {\n const [input, output] = await Promise.all([\n client.getMetricAggregate({\n name: ['mastra_model_total_input_tokens'],\n aggregation: 'sum',\n filters,\n comparePeriod: 'previous_period',\n }),\n client.getMetricAggregate({\n name: ['mastra_model_total_output_tokens'],\n aggregation: 'sum',\n filters,\n comparePeriod: 'previous_period',\n }),\n ]);\n\n const hasCurrent = input.value != null || output.value != null;\n const hasPrevious = input.previousValue != null || output.previousValue != null;\n const value = (input.value ?? 0) + (output.value ?? 0);\n const previousValue = (input.previousValue ?? 0) + (output.previousValue ?? 0);\n const changePercent = hasPrevious && previousValue > 0 ? ((value - previousValue) / previousValue) * 100 : null;\n\n return {\n value: hasCurrent ? value : null,\n previousValue: hasPrevious ? previousValue : null,\n changePercent,\n };\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface VolumeRow {\n name: string;\n completed: number;\n errors: number;\n}\n\nasync function fetchVolume(\n client: ReturnType<typeof useMastraClient>,\n metricName: string,\n filters: Record<string, unknown>,\n): Promise<VolumeRow[]> {\n const res = await client.getMetricBreakdown({\n name: [metricName],\n groupBy: ['entityName', 'status'],\n aggregation: 'count',\n orderDirection: 'DESC',\n filters,\n });\n\n const map = new Map<string, { completed: number; errors: number }>();\n\n for (const group of res.groups) {\n const name = group.dimensions.entityName ?? 'unknown';\n const status = group.dimensions.status ?? 'ok';\n const entry = getOrCreate(map, name, () => ({ completed: 0, errors: 0 }));\n\n if (status === 'error') {\n entry.errors += group.value;\n } else {\n entry.completed += group.value;\n }\n }\n\n return Array.from(map.entries())\n .map(([name, vals]) => ({ name, ...vals }))\n .sort((a, b) => b.completed + b.errors - (a.completed + a.errors));\n}\n\nexport interface TraceVolumeData {\n agentData: VolumeRow[];\n workflowData: VolumeRow[];\n toolData: VolumeRow[];\n}\n\nexport function useTraceVolumeMetrics<TData = TraceVolumeData>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<TraceVolumeData, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'trace-volume', filterKey],\n queryFn: async (): Promise<TraceVolumeData> => {\n const [agentData, workflowData, toolData] = await Promise.all([\n fetchVolume(client, 'mastra_agent_duration_ms', filters),\n fetchVolume(client, 'mastra_workflow_duration_ms', filters),\n fetchVolume(client, 'mastra_tool_duration_ms', filters),\n ]);\n return { agentData, workflowData, toolData };\n },\n ...queryOptions,\n });\n}\n"],"mappings":";;;;;AAgDA,MAAM,oBAAoB,OAAU,KAAK;AAEzC,MAAM,YAAoC;CACxC,OAAO;CACP,MAAM,OAAc,KAAK;CACzB,MAAM,QAAc,KAAK;CACzB,OAAO,MAAU,KAAK,KAAK;CAC3B,OAAO,MAAU,KAAK,KAAK;AAC7B;AAEA,SAAS,eACP,QACA,aACA,QACW;CACX,IAAI,WAAW,UAAU;EACvB,MAAM,KAAK,UAAU,WAAW;EAChC,OAAO;GAAE,OAAO,IAAI,KAAK,SAAS,EAAE;GAAG,KAAK,IAAI,KAAK,MAAM;EAAE;CAC/D;CACA,OAAO;EACL,OAAO,aAAa,wBAAQ,IAAI,KAAK,SAAS,iBAAiB;EAC/D,KAAK,aAAa,MAAM,IAAI,KAAK,MAAM;CACzC;AACF;;;;;;;;;;;;AAaA,SAAgB,uBAAuB,EACrC,YACA,aACA,mBACA,wBACgD;CAIhD,MAAM,YAAY,OAA+C,IAAI;CACrE,MAAM,YACJ,eAAe,WACX,UAAU,aAAa,MAAM,QAAQ,KAAK,GAAG,GAAG,aAAa,IAAI,QAAQ,KAAK,OAC9E,UAAU;CAChB,IAAI,CAAC,UAAU,WAAW,UAAU,QAAQ,QAAQ,WAClD,UAAU,UAAU;EAAE,KAAK;EAAW,QAAQ,KAAK,IAAI;CAAE;CAE3D,MAAM,SAAS,UAAU,QAAQ;CAEjC,MAAM,YAAY,cAAc,eAAe,YAAY,aAAa,MAAM,GAAG;EAAC;EAAY;EAAa;CAAM,CAAC;CAYlH,OAAO;EAAE;EAAY;EAAa;EAAW,SAV7B,eACP;GAAE;GAAW,GAAG;EAAkB,IAGzC,CAAC,WAAW,oBAA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A,GAAG;CACL,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["TOP_N"],"sources":["../../../src/hooks/metrics/metrics-query-filters.ts","../../../src/hooks/shared/date-format.ts","../../../src/hooks/metrics/metrics-interval.ts","../../../src/hooks/metrics/use-active-resources-kpi-metrics.tsx","../../../src/hooks/metrics/use-active-threads-kpi-metrics.tsx","../../../src/hooks/metrics/use-agent-runs-kpi-metrics.tsx","../../../src/hooks/metrics/use-latency-metrics.tsx","../../../src/hooks/metrics/use-model-cost-kpi-metrics.tsx","../../../src/hooks/shared/cost.ts","../../../src/hooks/metrics/use-model-usage-cost-metrics.tsx","../../../src/hooks/metrics/use-scores-metrics.tsx","../../../src/hooks/metrics/use-token-usage-by-agent-metrics.tsx","../../../src/hooks/metrics/use-token-usage-timeseries.tsx","../../../src/hooks/metrics/use-top-active-threads-metrics.tsx","../../../src/hooks/metrics/use-top-resources-by-threads-metrics.tsx","../../../src/hooks/metrics/use-total-tokens-kpi-metrics.tsx","../../../src/hooks/metrics/use-trace-volume-metrics.tsx"],"sourcesContent":["import type { EntityType } from '@mastra/core/observability';\nimport { useMemo, useRef } from 'react';\n\nexport type MetricsDatePreset = '24h' | '3d' | '7d' | '14d' | '30d' | 'custom';\n\nexport type MetricsDateRange = { from?: Date; to?: Date };\n\n/** Shape of the dimensional filter object fed into `MetricsFilter` on client\n * calls. Kept compatible with `metricsFilterSchema` in @internal/core — every\n * scalar field maps to a single-string column filter, and `tags` is the only\n * array field (matched via `has()` / equivalent on backends). */\nexport type MetricsDimensionalFilter = {\n rootEntityType?: EntityType;\n entityName?: string;\n tags?: string[];\n serviceName?: string;\n environment?: string;\n provider?: string;\n model?: string;\n threadId?: string;\n resourceId?: string;\n userId?: string;\n organizationId?: string;\n runId?: string;\n sessionId?: string;\n requestId?: string;\n experimentId?: string;\n};\n\nexport interface MetricsQueryFiltersInput {\n datePreset: MetricsDatePreset;\n customRange: MetricsDateRange | undefined;\n dimensionalFilter: MetricsDimensionalFilter;\n /** Stable JSON representation of `dimensionalFilter`, safe for query keys. */\n dimensionalFilterKey: string;\n}\n\ntype Timestamp = { start: Date; end: Date };\n\nexport interface MetricsQueryFilters {\n datePreset: MetricsDatePreset;\n customRange: MetricsDateRange | undefined;\n timestamp: Timestamp;\n filters: MetricsDimensionalFilter & { timestamp: Timestamp };\n dimensionalFilter: MetricsDimensionalFilter;\n filterKey: string;\n}\n\nconst DEFAULT_WINDOW_MS = 24 * 60 * 60 * 1000;\n\nconst PRESET_MS: Record<string, number> = {\n '24h': DEFAULT_WINDOW_MS,\n '3d': 3 * 24 * 60 * 60 * 1000,\n '7d': 7 * 24 * 60 * 60 * 1000,\n '14d': 14 * 24 * 60 * 60 * 1000,\n '30d': 30 * 24 * 60 * 60 * 1000,\n};\n\nfunction buildTimestamp(\n preset: MetricsDatePreset,\n customRange: MetricsDateRange | undefined,\n anchor: number,\n): Timestamp {\n if (preset !== 'custom') {\n const ms = PRESET_MS[preset] ?? DEFAULT_WINDOW_MS;\n return { start: new Date(anchor - ms), end: new Date(anchor) };\n }\n return {\n start: customRange?.from ?? new Date(anchor - DEFAULT_WINDOW_MS),\n end: customRange?.to ?? new Date(anchor),\n };\n}\n\n/**\n * Compose a ready-to-use metrics filter object from a date window and a\n * dimensional filter. Pass the result to the metrics hooks.\n *\n * Stability guarantees (important for react-query):\n * - `timestamp` is frozen at the moment the inputs change and does NOT update\n * on every render. Otherwise each render would mint a new `new Date()` and\n * every metrics query would re-fetch on every keystroke.\n * - `filters` and `filterKey` are referentially stable while inputs are\n * unchanged, so `queryKey` hashing is cheap and caches hit.\n */\nexport function useMetricsQueryFilters({\n datePreset,\n customRange,\n dimensionalFilter,\n dimensionalFilterKey,\n}: MetricsQueryFiltersInput): MetricsQueryFilters {\n // Anchor the \"now\" used for preset windows. We only recompute when the\n // preset or custom range changes — this gives a stable timestamp per query\n // boundary rather than a new Date on every render.\n const anchorRef = useRef<{ key: string; anchor: number } | null>(null);\n const windowKey =\n datePreset === 'custom'\n ? `custom:${customRange?.from?.getTime() ?? ''}:${customRange?.to?.getTime() ?? ''}`\n : `preset:${datePreset}`;\n if (!anchorRef.current || anchorRef.current.key !== windowKey) {\n anchorRef.current = { key: windowKey, anchor: Date.now() };\n }\n const anchor = anchorRef.current.anchor;\n\n const timestamp = useMemo(() => buildTimestamp(datePreset, customRange, anchor), [datePreset, customRange, anchor]);\n\n const filters = useMemo(\n () => ({ timestamp, ...dimensionalFilter }),\n // dimensionalFilterKey is a stringified digest, so this dep set gives a\n // stable ref while content is unchanged.\n [timestamp, dimensionalFilterKey],\n );\n\n // filterKey combines window + dimensions so react-query keys are cheap.\n const filterKey = useMemo(() => `${windowKey}|${dimensionalFilterKey}`, [windowKey, dimensionalFilterKey]);\n\n return { datePreset, customRange, timestamp, filters, dimensionalFilter, filterKey };\n}\n","export type DateInput = Date | string | number | null | undefined;\nexport type DatePreset =\n | 'date'\n | 'date-time'\n | 'date-time-seconds'\n | 'day-time-seconds'\n | 'time'\n | 'time-seconds'\n | 'relative-time'\n | 'relative-long';\n\ntype FormatOptions = { locale?: string; now?: Date | number; timeZone?: string };\n\nexport function toDate(value: DateInput): Date | undefined {\n if (value == null) return undefined;\n const date = value instanceof Date ? value : new Date(value);\n return Number.isNaN(date.getTime()) ? undefined : date;\n}\n\nconst PRESET_OPTIONS = {\n time: { hour: 'numeric', minute: '2-digit' },\n 'time-seconds': { hour: 'numeric', minute: '2-digit', second: '2-digit' },\n 'date-time': { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit' },\n 'date-time-seconds': {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n hour: 'numeric',\n minute: '2-digit',\n second: '2-digit',\n },\n 'day-time-seconds': { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', second: '2-digit' },\n calendar: { year: 'numeric', month: 'numeric', day: 'numeric', calendar: 'gregory', numberingSystem: 'latn' },\n dayMonth: { month: 'short', day: 'numeric' },\n dayMonthYear: { month: 'short', day: 'numeric', year: 'numeric' },\n precise: {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n hour: 'numeric',\n minute: '2-digit',\n second: '2-digit',\n fractionalSecondDigits: 3,\n },\n timePrecise: { hour: 'numeric', minute: '2-digit', second: '2-digit', fractionalSecondDigits: 3 },\n} satisfies Record<string, Intl.DateTimeFormatOptions>;\n\ntype FormatterKey = keyof typeof PRESET_OPTIONS;\n\nconst formatters = new Map<string, Intl.DateTimeFormat>();\n\nfunction getFormatter(key: FormatterKey, locale?: string, timeZone?: string) {\n const cacheKey = `${locale ?? ''}|${timeZone ?? ''}|${key}`;\n let formatter = formatters.get(cacheKey);\n if (!formatter) {\n formatter = new Intl.DateTimeFormat(locale, { ...PRESET_OPTIONS[key], timeZone });\n formatters.set(cacheKey, formatter);\n }\n return formatter;\n}\n\nfunction calendarDate(date: Date, timeZone?: string) {\n const parts = getFormatter('calendar', 'en-US', timeZone).formatToParts(date);\n return {\n year: parts.find(part => part.type === 'year')?.value,\n month: parts.find(part => part.type === 'month')?.value,\n day: parts.find(part => part.type === 'day')?.value,\n };\n}\n\n/** Short absolute date without time: `Sep 24` this year, `Sep 24, 2025` otherwise. */\nexport function formatShortDate(value: DateInput, { locale, now, timeZone }: FormatOptions = {}) {\n const date = toDate(value);\n if (!date) return undefined;\n const reference = new Date(now ?? Date.now());\n const key =\n calendarDate(date, timeZone).year === calendarDate(reference, timeZone).year ? 'dayMonth' : 'dayMonthYear';\n return getFormatter(key, locale, timeZone).format(date);\n}\n\nconst LONG_RELATIVE_UNITS: Array<[Intl.RelativeTimeFormatUnit, number]> = [\n ['year', 365 * 86_400],\n ['month', 30 * 86_400],\n ['week', 7 * 86_400],\n ['day', 86_400],\n ['hour', 3_600],\n ['minute', 60],\n];\n\nconst relativeFormatters = new Map<string, Intl.RelativeTimeFormat>();\n\nfunction getRelativeFormatter(locale?: string) {\n const key = locale ?? '';\n let formatter = relativeFormatters.get(key);\n if (!formatter) {\n formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });\n relativeFormatters.set(key, formatter);\n }\n return formatter;\n}\n\n/**\n * Uses the browser locale unless `locale` is given.\n * - `date`: date only; omits the year when it matches `now` in the requested timezone\n * - `date-time`: date, year and time to minutes, including historical dates\n * - `date-time-seconds`: date, year and time to seconds\n * - `day-time-seconds`: month, day and time to seconds, without the year\n * - `time`: time to minutes, without a date\n * - `time-seconds`: time to seconds, without a date\n * - `relative-time`: short relative label; delegates to `date` at seven days\n */\nexport function formatDate(value: DateInput, preset: DatePreset, options: FormatOptions = {}) {\n const date = toDate(value);\n if (!date) return undefined;\n const { locale, now, timeZone } = options;\n\n if (preset === 'relative-time') {\n const diff = date.getTime() - new Date(now ?? Date.now()).getTime();\n const abs = Math.abs(diff);\n if (abs < 5_000) return 'just now';\n const units = [\n { limit: 60_000, size: 1_000, unit: 's' },\n { limit: 3_600_000, size: 60_000, unit: 'm' },\n { limit: 86_400_000, size: 3_600_000, unit: 'h' },\n { limit: 7 * 86_400_000, size: 86_400_000, unit: 'd' },\n ];\n const match = units.find(({ limit }) => abs < limit);\n if (!match) return formatDate(date, 'date', options);\n const label = `${Math.floor(abs / match.size)}${match.unit}`;\n return diff < 0 ? `${label} ago` : `in ${label}`;\n }\n if (preset === 'relative-long') {\n const seconds = (date.getTime() - new Date(now ?? Date.now()).getTime()) / 1000;\n const [unit, size] = LONG_RELATIVE_UNITS.find(([, size]) => Math.abs(seconds) >= size) ?? ['second', 1];\n return getRelativeFormatter(locale).format(Math.round(seconds / size), unit);\n }\n if (preset === 'date') return formatShortDate(date, options);\n\n return getFormatter(preset, locale, timeZone).format(date);\n}\n\n/** Locale-aware compact date range, e.g. `Sep 2 – 5, 2026`. */\nexport function formatDateRange(start: DateInput, end: DateInput, options: Omit<FormatOptions, 'now'> = {}) {\n const from = toDate(start);\n const to = toDate(end);\n if (!from || !to) return undefined;\n return getFormatter('dayMonthYear', options.locale, options.timeZone)\n .formatRange(from, to)\n .replace(/\\u2009/g, ' ');\n}\n\n/** Date and time down to milliseconds, for trace debugging. `withDate: false` keeps only the time. */\nexport function formatTimestampPrecise(\n value: DateInput,\n { locale, withDate = true }: { locale?: string; withDate?: boolean } = {},\n) {\n const date = toDate(value);\n return date ? getFormatter(withDate ? 'precise' : 'timePrecise', locale).format(date) : undefined;\n}\n","import { formatDate, formatShortDate } from '../shared/date-format';\n\nexport type MetricsInterval = '1h' | '1d';\n\nconst HOURLY_MAX_RANGE_MS = 48 * 60 * 60 * 1000;\n\n/** Hourly buckets up to 48h, daily buckets beyond, so long ranges stay readable. */\nexport function chooseMetricsInterval({ start, end }: { start: Date; end: Date }): MetricsInterval {\n return end.getTime() - start.getTime() <= HOURLY_MAX_RANGE_MS ? '1h' : '1d';\n}\n\nexport function formatMetricsBucketLabel(ts: Date, interval: MetricsInterval): string {\n if (interval === '1h') {\n return formatDate(ts, 'time') ?? '';\n }\n return formatShortDate(ts) ?? '';\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Active Resources — number of distinct resource IDs observed in agent runs.\n * Uses approximate `count_distinct` (HyperLogLog on ClickHouse,\n * `approx_count_distinct` on DuckDB) so the query stays fast even on\n * tens of millions of rows. */\nexport function useActiveResourcesKpiMetrics<TData = Awaited<ReturnType<MastraClient['getMetricAggregate']>>>(\n params: MetricsQueryFilters & {\n queryOptions?: MastraQueryOptions<Awaited<ReturnType<MastraClient['getMetricAggregate']>>, TData>;\n },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'active-resources-kpi', filterKey],\n queryFn: () =>\n client.getMetricAggregate({\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count_distinct',\n distinctColumn: 'resourceId' as never,\n filters,\n comparePeriod: 'previous_period',\n }),\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Active Threads — number of distinct thread IDs observed in agent runs.\n * Uses approximate `count_distinct` (HyperLogLog on ClickHouse,\n * `approx_count_distinct` on DuckDB) so the query stays fast even on\n * tens of millions of rows. */\nexport function useActiveThreadsKpiMetrics<TData = Awaited<ReturnType<MastraClient['getMetricAggregate']>>>(\n params: MetricsQueryFilters & {\n queryOptions?: MastraQueryOptions<Awaited<ReturnType<MastraClient['getMetricAggregate']>>, TData>;\n },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'active-threads-kpi', filterKey],\n queryFn: () =>\n client.getMetricAggregate({\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count_distinct',\n distinctColumn: 'threadId' as never,\n filters,\n comparePeriod: 'previous_period',\n }),\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Total Agent Runs — count of agent duration metric observations */\nexport function useAgentRunsKpiMetrics<TData = Awaited<ReturnType<MastraClient['getMetricAggregate']>>>(\n params: MetricsQueryFilters & {\n queryOptions?: MastraQueryOptions<Awaited<ReturnType<MastraClient['getMetricAggregate']>>, TData>;\n },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'agent-runs-kpi', filterKey],\n queryFn: () =>\n client.getMetricAggregate({\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count',\n filters,\n comparePeriod: 'previous_period',\n }),\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport { chooseMetricsInterval, formatMetricsBucketLabel } from './metrics-interval';\nimport type { MetricsInterval } from './metrics-interval';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface LatencyPoint {\n [key: string]: unknown;\n time: string;\n /** Raw timestamp (ms since epoch) for the bucket this point represents.\n * Used by drilldown clicks to compute a narrow time window. */\n tsMs: number;\n p50: number;\n p95: number;\n}\n\nasync function fetchPercentiles(\n client: ReturnType<typeof useMastraClient>,\n metricName: string,\n filters: Record<string, unknown>,\n interval: MetricsInterval,\n): Promise<LatencyPoint[]> {\n const res = await client.getMetricPercentiles({\n name: metricName,\n percentiles: [0.5, 0.95],\n interval,\n filters,\n });\n\n const p50Series = res.series.find(s => s.percentile === 0.5);\n const p95Series = res.series.find(s => s.percentile === 0.95);\n\n if (!p50Series || !p95Series) return [];\n\n const p95Map = new Map(p95Series.points.map(p => [new Date(p.timestamp).getTime(), p.value]));\n\n return p50Series.points.map(p => {\n const ts = new Date(p.timestamp);\n const tsMs = ts.getTime();\n return {\n time: formatMetricsBucketLabel(ts, interval),\n tsMs,\n p50: Math.round(p.value),\n p95: Math.round(p95Map.get(tsMs) ?? 0),\n };\n });\n}\n\nexport interface LatencyMetricsData {\n agentData: LatencyPoint[];\n workflowData: LatencyPoint[];\n toolData: LatencyPoint[];\n interval: MetricsInterval;\n}\n\nexport function useLatencyMetrics<TData = LatencyMetricsData>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<LatencyMetricsData, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { timestamp, filters, filterKey, queryOptions } = params;\n const interval = chooseMetricsInterval(timestamp);\n\n return useQuery({\n queryKey: ['metrics', 'latency', filterKey, interval],\n queryFn: async (): Promise<LatencyMetricsData> => {\n const [agentData, workflowData, toolData] = await Promise.all([\n fetchPercentiles(client, 'mastra_agent_duration_ms', filters, interval),\n fetchPercentiles(client, 'mastra_workflow_duration_ms', filters, interval),\n fetchPercentiles(client, 'mastra_tool_duration_ms', filters, interval),\n ]);\n return { agentData, workflowData, toolData, interval };\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Total Model Cost — sum of estimatedCost across input and output token metrics */\nexport interface ModelCostKpi {\n cost: number | null;\n costUnit: string | null;\n previousCost: number | null;\n costChangePercent: number | null;\n}\n\nexport function useModelCostKpiMetrics<TData = ModelCostKpi>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ModelCostKpi, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'model-cost-kpi', filterKey],\n queryFn: async (): Promise<ModelCostKpi> => {\n const res = await client.getMetricAggregate({\n name: ['mastra_model_total_input_tokens', 'mastra_model_total_output_tokens'],\n aggregation: 'sum',\n filters,\n comparePeriod: 'previous_period',\n });\n\n return {\n cost: res.estimatedCost ?? null,\n costUnit: res.costUnit ?? null,\n previousCost: res.previousEstimatedCost ?? null,\n costChangePercent: res.costChangePercent ?? null,\n };\n },\n ...queryOptions,\n });\n}\n","export interface CompactNumberFormatOptions {\n currency?: string;\n}\n\nconst compactNumber = new Intl.NumberFormat('en-US', { notation: 'compact', maximumSignificantDigits: 3 });\nconst fullNumber = new Intl.NumberFormat('en-US');\n\nconst currencyCodes = new Set(Intl.supportedValuesOf('currency'));\n\nfunction isCurrency(code: string | undefined): code is string {\n return code !== undefined && currencyCodes.has(code.toUpperCase());\n}\n\nfunction money(currency: string, options: Intl.NumberFormatOptions) {\n return new Intl.NumberFormat('en-US', { style: 'currency', currency, ...options });\n}\n\nexport function formatCompactNumber(value: number, { currency }: CompactNumberFormatOptions = {}): string {\n if (!isCurrency(currency)) return compactNumber.format(value);\n const size = Math.abs(value);\n if (size < 100) return formatFullNumber(value, { currency });\n if (size < 1000) return money(currency, { maximumFractionDigits: 0 }).format(value);\n return money(currency, { notation: 'compact', maximumSignificantDigits: 3 }).format(value);\n}\n\nexport function formatFullNumber(value: number, { currency }: CompactNumberFormatOptions = {}): string {\n if (!isCurrency(currency)) return fullNumber.format(value);\n const formatter = money(currency, {});\n const smallestUnit = 10 ** -(formatter.resolvedOptions().maximumFractionDigits ?? 2);\n if (value !== 0 && Math.abs(value) < smallestUnit) {\n return `${value < 0 ? '-' : ''}<${formatter.format(smallestUnit)}`;\n }\n return formatter.format(value);\n}\n\nexport function formatCost(value: number, unit?: string | null): string {\n const isUsd = !unit || unit.toLowerCase() === 'usd';\n const amount = value > 0 && value < 0.01 ? '<0.01' : value.toFixed(2);\n if (!isUsd) return `${amount} ${unit}`;\n return amount.startsWith('<') ? '<$0.01' : `$${amount}`;\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { formatCompactNumber } from '../shared/cost';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface ModelUsageRow {\n model: string;\n provider?: string;\n input: string;\n output: string;\n cacheRead: string;\n cacheWrite: string;\n cost: number | null;\n costUnit: string | null;\n}\n\nexport function useModelUsageCostMetrics<TData = ModelUsageRow[]>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ModelUsageRow[], TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'model-usage-cost', filterKey],\n queryFn: async (): Promise<ModelUsageRow[]> => {\n const [inputRes, outputRes, cacheReadRes, cacheWriteRes] = await Promise.all(\n (\n [\n 'mastra_model_total_input_tokens',\n 'mastra_model_total_output_tokens',\n 'mastra_model_input_cache_read_tokens',\n 'mastra_model_input_cache_write_tokens',\n ] as const\n ).map(name =>\n client.getMetricBreakdown({\n name: [name],\n groupBy: ['model', 'provider'],\n aggregation: 'sum',\n orderDirection: 'DESC',\n filters,\n }),\n ),\n );\n\n if (!inputRes || !outputRes || !cacheReadRes || !cacheWriteRes) return [];\n\n type ModelEntry = {\n model: string;\n provider: string | undefined;\n input: number;\n output: number;\n cacheRead: number;\n cacheWrite: number;\n cost: number | null;\n costUnit: string | null;\n };\n\n const modelMap = new Map<string, ModelEntry>();\n\n const ensureModel = (dimensions: { model?: string | null; provider?: string | null }): ModelEntry => {\n const model = dimensions.model ?? 'unknown';\n const provider = dimensions.provider ?? undefined;\n return getOrCreate(modelMap, `${model}\\u0000${provider ?? ''}`, () => ({\n model,\n provider,\n input: 0,\n output: 0,\n cacheRead: 0,\n cacheWrite: 0,\n cost: null,\n costUnit: null,\n }));\n };\n\n // total_input/total_output estimatedCost already rolls up cache + other detail\n // costs. The cache breakdowns are kept for their token counts only.\n const addCost = (entry: ModelEntry, group: { estimatedCost?: number | null; costUnit?: string | null }) => {\n if (group.estimatedCost != null) {\n entry.cost = (entry.cost ?? 0) + group.estimatedCost;\n if (group.costUnit) entry.costUnit = group.costUnit;\n }\n };\n\n for (const group of inputRes.groups) {\n const entry = ensureModel(group.dimensions);\n entry.input = group.value;\n addCost(entry, group);\n }\n for (const group of outputRes.groups) {\n const entry = ensureModel(group.dimensions);\n entry.output = group.value;\n addCost(entry, group);\n }\n for (const group of cacheReadRes.groups) {\n const entry = ensureModel(group.dimensions);\n entry.cacheRead = group.value;\n }\n for (const group of cacheWriteRes.groups) {\n const entry = ensureModel(group.dimensions);\n entry.cacheWrite = group.value;\n }\n\n return Array.from(modelMap.values())\n .map(vals => ({\n model: vals.model,\n ...(vals.provider ? { provider: vals.provider } : {}),\n input: formatCompactNumber(vals.input),\n output: formatCompactNumber(vals.output),\n cacheRead: formatCompactNumber(vals.cacheRead),\n cacheWrite: formatCompactNumber(vals.cacheWrite),\n cost: vals.cost,\n costUnit: vals.costUnit,\n }))\n .sort((a, b) => a.model.localeCompare(b.model) || (a.provider ?? '').localeCompare(b.provider ?? ''));\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { formatDate } from '../shared/date-format';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface ScorerSummary {\n scorer: string;\n avg: number;\n min: number;\n max: number;\n count: number;\n}\n\nexport interface ScoresOverTimePoint {\n time: string;\n [scorer: string]: string | number;\n}\n\nexport interface ScoresMetricsData {\n summaryData: ScorerSummary[];\n overTimeData: ScoresOverTimePoint[];\n scorerNames: string[];\n avgScore: number | null;\n}\n\nexport function useScoresMetrics<TData = ScoresMetricsData>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ScoresMetricsData, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { datePreset, customRange, timestamp, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'scores-card', datePreset, customRange],\n queryFn: async (): Promise<ScoresMetricsData> => {\n const filters = {\n timestamp: { start: timestamp.start, end: timestamp.end },\n };\n\n const scorersMap = await client.listScorers();\n const scorerIds = Object.keys(scorersMap ?? {});\n\n if (scorerIds.length === 0) {\n return { summaryData: [], overTimeData: [], scorerNames: [], avgScore: null };\n }\n\n // Fetch summary stats first to determine which scorers have data\n const summaryResults = await Promise.all(\n scorerIds.map(async scorerId => {\n const [avg, min, max, count] = await Promise.all([\n client.getScoreAggregate({ scorerId, aggregation: 'avg', filters }),\n client.getScoreAggregate({ scorerId, aggregation: 'min', filters }),\n client.getScoreAggregate({ scorerId, aggregation: 'max', filters }),\n client.getScoreAggregate({ scorerId, aggregation: 'count', filters }),\n ]);\n return {\n scorer: scorerId,\n avg: avg.value ?? 0,\n min: min.value ?? 0,\n max: max.value ?? 0,\n count: count.value ?? 0,\n };\n }),\n );\n\n const summaryData: ScorerSummary[] = summaryResults.filter(s => s.count > 0);\n const scorerNames = summaryData.map(s => s.scorer);\n\n if (summaryData.length === 0) {\n return { summaryData: [], overTimeData: [], scorerNames: [], avgScore: null };\n }\n\n const totalWeighted = summaryData.reduce((s, d) => s + d.avg * d.count, 0);\n const totalCount = summaryData.reduce((s, d) => s + d.count, 0);\n const avgScore = totalCount ? Math.round((totalWeighted / totalCount) * 100) / 100 : 0;\n\n const interval = '1h';\n\n // Fetch hourly time series from the full period for active scorers\n const timeSeriesResults = await Promise.all(\n scorerNames.map(scorerId =>\n client.getScoreTimeSeries({\n scorerId,\n interval,\n aggregation: 'avg',\n filters,\n }),\n ),\n );\n\n // Collapse all days into a single 24-hour view (00:00–23:00).\n // For each hour-of-day, average the values across all days in the range.\n const hourBuckets = new Map<number, Map<string, { sum: number; count: number }>>();\n\n for (let i = 0; i < scorerNames.length; i++) {\n const scorerId = scorerNames[i];\n const series = timeSeriesResults[i]?.series ?? [];\n for (const s of series) {\n for (const point of s.points) {\n const ts = new Date(point.timestamp);\n const hourKey = ts.getHours() * 60 + ts.getMinutes();\n const scorerMap = getOrCreate(hourBuckets, hourKey, () => new Map());\n const acc = getOrCreate(scorerMap, scorerId, () => ({ sum: 0, count: 0 }));\n\n acc.sum += point.value;\n acc.count += 1;\n }\n }\n }\n\n // Build sorted 24h chart data\n const overTimeData: ScoresOverTimePoint[] = Array.from(hourBuckets.entries())\n .sort(([a], [b]) => a - b)\n .map(([hourKey, scorerMap]) => {\n const point: ScoresOverTimePoint = {\n time: formatDate(new Date(2000, 0, 1, Math.floor(hourKey / 60), hourKey % 60), 'time') ?? '',\n };\n for (const [scorerId, acc] of scorerMap) {\n point[scorerId] = +(acc.sum / acc.count).toFixed(2);\n }\n return point;\n });\n\n return {\n summaryData,\n overTimeData,\n scorerNames,\n avgScore,\n };\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface TokenUsageByAgentRow {\n name: string;\n total: number;\n input: number;\n output: number;\n cost: number | null;\n costUnit: string | null;\n}\n\nexport function useTokenUsageByAgentMetrics<TData = TokenUsageByAgentRow[]>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<TokenUsageByAgentRow[], TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'token-usage-by-agent', filterKey],\n queryFn: async (): Promise<TokenUsageByAgentRow[]> => {\n const breakdownBase = {\n groupBy: ['entityName'],\n aggregation: 'sum' as const,\n orderDirection: 'DESC' as const,\n filters,\n };\n // total_input/total_output estimatedCost already rolls up cache + other detail costs.\n const [inputRes, outputRes] = await Promise.all([\n client.getMetricBreakdown({ ...breakdownBase, name: ['mastra_model_total_input_tokens'] }),\n client.getMetricBreakdown({ ...breakdownBase, name: ['mastra_model_total_output_tokens'] }),\n ]);\n\n type AgentEntry = { input: number; output: number; cost: number | null; costUnit: string | null };\n\n const agentMap = new Map<string, AgentEntry>();\n\n const ensure = (name: string): AgentEntry =>\n getOrCreate(agentMap, name, () => ({ input: 0, output: 0, cost: null, costUnit: null }));\n\n const addCost = (entry: AgentEntry, group: { estimatedCost?: number | null; costUnit?: string | null }) => {\n if (group.estimatedCost != null) {\n entry.cost = (entry.cost ?? 0) + group.estimatedCost;\n if (group.costUnit) entry.costUnit = group.costUnit;\n }\n };\n\n for (const group of inputRes.groups) {\n const name = group.dimensions.entityName ?? 'unknown';\n const entry = ensure(name);\n entry.input = group.value;\n addCost(entry, group);\n }\n for (const group of outputRes.groups) {\n const name = group.dimensions.entityName ?? 'unknown';\n const entry = ensure(name);\n entry.output = group.value;\n addCost(entry, group);\n }\n\n return Array.from(agentMap.entries())\n .map(([name, vals]) => ({\n name,\n input: vals.input,\n output: vals.output,\n total: vals.input + vals.output,\n cost: vals.cost,\n costUnit: vals.costUnit,\n }))\n .sort((a, b) => b.total - a.total);\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport { chooseMetricsInterval, formatMetricsBucketLabel } from './metrics-interval';\nimport type { MetricsInterval } from './metrics-interval';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport type TokenUsageTimeSeriesInterval = MetricsInterval;\n\nexport interface TokenTimelinePoint {\n time: string;\n tsMs: number;\n input: number;\n output: number;\n total: number;\n cost: number | null;\n costUnit: string | null;\n}\n\nexport interface TokenUsageTimeSeriesData {\n data: TokenTimelinePoint[];\n interval: TokenUsageTimeSeriesInterval;\n}\n\ntype TimeSeriesPoint = {\n timestamp: string | Date;\n value: number;\n estimatedCost?: number | null;\n};\n\ntype SeriesWithCost = {\n costUnit?: string | null;\n points: TimeSeriesPoint[];\n};\n\ntype TokenTimelineAccumulator = {\n tsMs: number;\n input: number;\n output: number;\n cost: number | null;\n costUnits: Set<string>;\n hasUnknownCostUnit: boolean;\n};\n\nfunction addSeriesPoints(\n pointMap: Map<number, TokenTimelineAccumulator>,\n series: SeriesWithCost | undefined,\n key: 'input' | 'output',\n) {\n for (const point of series?.points ?? []) {\n const tsMs = new Date(point.timestamp).getTime();\n if (!Number.isFinite(tsMs)) continue;\n\n const existing = pointMap.get(tsMs) ?? {\n tsMs,\n input: 0,\n output: 0,\n cost: null,\n costUnits: new Set<string>(),\n hasUnknownCostUnit: false,\n };\n\n existing[key] += point.value;\n\n if (point.estimatedCost != null) {\n existing.cost = (existing.cost ?? 0) + point.estimatedCost;\n if (series?.costUnit) {\n existing.costUnits.add(series.costUnit);\n } else {\n existing.hasUnknownCostUnit = true;\n }\n }\n\n pointMap.set(tsMs, existing);\n }\n}\n\nfunction toCostUnit(entry: TokenTimelineAccumulator): string | null {\n if (entry.cost == null || entry.hasUnknownCostUnit || entry.costUnits.size !== 1) return null;\n return [...entry.costUnits][0] ?? null;\n}\n\nexport function useTokenUsageTimeSeries<TData = TokenUsageTimeSeriesData>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<TokenUsageTimeSeriesData, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { timestamp, filters, filterKey, queryOptions } = params;\n const interval = chooseMetricsInterval(timestamp);\n\n return useQuery({\n queryKey: ['metrics', 'token-usage-timeseries', filterKey, interval],\n queryFn: async (): Promise<TokenUsageTimeSeriesData> => {\n const [inputRes, outputRes] = await Promise.all([\n client.getMetricTimeSeries({\n name: ['mastra_model_total_input_tokens'],\n interval,\n aggregation: 'sum',\n filters,\n }),\n client.getMetricTimeSeries({\n name: ['mastra_model_total_output_tokens'],\n interval,\n aggregation: 'sum',\n filters,\n }),\n ]);\n\n const pointMap = new Map<number, TokenTimelineAccumulator>();\n addSeriesPoints(pointMap, inputRes.series[0], 'input');\n addSeriesPoints(pointMap, outputRes.series[0], 'output');\n\n const data = Array.from(pointMap.values())\n .sort((a, b) => a.tsMs - b.tsMs)\n .map(point => {\n const ts = new Date(point.tsMs);\n return {\n time: formatMetricsBucketLabel(ts, interval),\n tsMs: point.tsMs,\n input: point.input,\n output: point.output,\n total: point.input + point.output,\n cost: point.cost,\n costUnit: toCostUnit(point),\n };\n });\n\n return { data, interval };\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { useMastraClient } from '../../mastra-client-context';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface ActiveThreadRow {\n threadId: string;\n resourceId: string | null;\n runs: number;\n tokens: number;\n cost: number | null;\n costUnit: string | null;\n}\n\nconst TOP_N = 20;\n\n/** Top Active Threads — the threads with the most agent runs in the selected\n * range. Server-side TopK (`ORDER BY value DESC LIMIT 20`) is required so the\n * query never returns the full thread set when cardinality is in the millions.\n *\n * Tokens + cost are joined in from parallel breakdowns on the same `threadId`\n * grouping so we don't need any new backend aggregation support. */\nexport function useTopActiveThreadsMetrics<TData = ActiveThreadRow[]>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ActiveThreadRow[], TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'top-active-threads', filterKey],\n queryFn: async (): Promise<ActiveThreadRow[]> => {\n const breakdownBase = {\n groupBy: ['threadId', 'resourceId'],\n orderDirection: 'DESC' as const,\n filters,\n };\n\n const [runsRes, inputRes, outputRes] = await Promise.all([\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count',\n limit: TOP_N,\n }),\n // Token breakdowns use the same groupBy and a server-side TopK so the\n // response stays bounded even when the underlying thread set has very\n // high cardinality. Threads that are top-N by runs but not by tokens\n // will display 0 tokens (an acceptable approximation in exchange for\n // a bounded query).\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_model_total_input_tokens'],\n aggregation: 'sum',\n limit: TOP_N,\n }),\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_model_total_output_tokens'],\n aggregation: 'sum',\n limit: TOP_N,\n }),\n ]);\n\n type Entry = { tokens: number; cost: number | null; costUnit: string | null };\n const byThread = new Map<string, Entry>();\n\n const ensure = (threadId: string): Entry =>\n getOrCreate(byThread, threadId, () => ({ tokens: 0, cost: null, costUnit: null }));\n\n const foldTokens = (groups: typeof inputRes.groups) => {\n for (const group of groups) {\n const threadId = group.dimensions.threadId;\n if (!threadId) continue;\n const entry = ensure(threadId as string);\n entry.tokens += group.value;\n if (group.estimatedCost != null) {\n entry.cost = (entry.cost ?? 0) + group.estimatedCost;\n if (group.costUnit) entry.costUnit = group.costUnit;\n }\n }\n };\n foldTokens(inputRes.groups);\n foldTokens(outputRes.groups);\n\n return runsRes.groups\n .filter(group => !!group.dimensions.threadId)\n .map(group => {\n const threadId = group.dimensions.threadId as string;\n const extra = byThread.get(threadId);\n return {\n threadId,\n resourceId: (group.dimensions.resourceId as string | undefined) ?? null,\n runs: group.value,\n tokens: extra?.tokens ?? 0,\n cost: extra?.cost ?? null,\n costUnit: extra?.costUnit ?? null,\n };\n });\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { useMastraClient } from '../../mastra-client-context';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface ResourceThreadsRow {\n resourceId: string;\n threadCount: number;\n tokens: number;\n cost: number | null;\n costUnit: string | null;\n}\n\nconst TOP_N = 20;\n\n/** Top Resources by Thread Count — the resources with the most distinct threads\n * in the selected range. Uses `count_distinct(threadId)` per `resourceId`,\n * with server-side TopK (`ORDER BY value DESC LIMIT 20`).\n *\n * Tokens + cost are joined in from parallel breakdowns on `resourceId` so the\n * table can show cost/usage without a separate backend aggregation. */\nexport function useTopResourcesByThreadsMetrics<TData = ResourceThreadsRow[]>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<ResourceThreadsRow[], TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'top-resources-by-threads', filterKey],\n queryFn: async (): Promise<ResourceThreadsRow[]> => {\n const breakdownBase = {\n groupBy: ['resourceId'],\n orderDirection: 'DESC' as const,\n filters,\n };\n\n const [threadsRes, inputRes, outputRes] = await Promise.all([\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_agent_duration_ms'],\n aggregation: 'count_distinct',\n distinctColumn: 'threadId' as never,\n limit: TOP_N,\n }),\n // Token breakdowns use the same groupBy and a server-side TopK so the\n // response stays bounded even when the underlying resource set has very\n // high cardinality. Resources that are top-N by thread count but not by\n // tokens will display 0 tokens (an acceptable approximation in exchange\n // for a bounded query).\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_model_total_input_tokens'],\n aggregation: 'sum',\n limit: TOP_N,\n }),\n client.getMetricBreakdown({\n ...breakdownBase,\n name: ['mastra_model_total_output_tokens'],\n aggregation: 'sum',\n limit: TOP_N,\n }),\n ]);\n\n type Entry = { tokens: number; cost: number | null; costUnit: string | null };\n const byResource = new Map<string, Entry>();\n\n const ensure = (resourceId: string): Entry =>\n getOrCreate(byResource, resourceId, () => ({ tokens: 0, cost: null, costUnit: null }));\n\n const foldTokens = (groups: typeof inputRes.groups) => {\n for (const group of groups) {\n const resourceId = group.dimensions.resourceId;\n if (!resourceId) continue;\n const entry = ensure(resourceId as string);\n entry.tokens += group.value;\n if (group.estimatedCost != null) {\n entry.cost = (entry.cost ?? 0) + group.estimatedCost;\n if (group.costUnit) entry.costUnit = group.costUnit;\n }\n }\n };\n foldTokens(inputRes.groups);\n foldTokens(outputRes.groups);\n\n return threadsRes.groups\n .filter(group => !!group.dimensions.resourceId)\n .map(group => {\n const resourceId = group.dimensions.resourceId as string;\n const extra = byResource.get(resourceId);\n return {\n resourceId,\n threadCount: group.value,\n tokens: extra?.tokens ?? 0,\n cost: extra?.cost ?? null,\n costUnit: extra?.costUnit ?? null,\n };\n });\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\n/** Total Tokens — sum of all input + output tokens */\nexport interface TotalTokensKpi {\n value: number | null;\n previousValue: number | null;\n changePercent: number | null;\n}\n\nexport function useTotalTokensKpiMetrics<TData = TotalTokensKpi>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<TotalTokensKpi, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'total-tokens-kpi', filterKey],\n queryFn: async (): Promise<TotalTokensKpi> => {\n const [input, output] = await Promise.all([\n client.getMetricAggregate({\n name: ['mastra_model_total_input_tokens'],\n aggregation: 'sum',\n filters,\n comparePeriod: 'previous_period',\n }),\n client.getMetricAggregate({\n name: ['mastra_model_total_output_tokens'],\n aggregation: 'sum',\n filters,\n comparePeriod: 'previous_period',\n }),\n ]);\n\n const hasCurrent = input.value != null || output.value != null;\n const hasPrevious = input.previousValue != null || output.previousValue != null;\n const value = (input.value ?? 0) + (output.value ?? 0);\n const previousValue = (input.previousValue ?? 0) + (output.previousValue ?? 0);\n const changePercent = hasPrevious && previousValue > 0 ? ((value - previousValue) / previousValue) * 100 : null;\n\n return {\n value: hasCurrent ? value : null,\n previousValue: hasPrevious ? previousValue : null,\n changePercent,\n };\n },\n ...queryOptions,\n });\n}\n","import type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { getOrCreate } from '../shared/map';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { MetricsQueryFilters } from './metrics-query-filters';\n\nexport interface VolumeRow {\n name: string;\n completed: number;\n errors: number;\n}\n\nasync function fetchVolume(\n client: ReturnType<typeof useMastraClient>,\n metricName: string,\n filters: Record<string, unknown>,\n): Promise<VolumeRow[]> {\n const res = await client.getMetricBreakdown({\n name: [metricName],\n groupBy: ['entityName', 'status'],\n aggregation: 'count',\n orderDirection: 'DESC',\n filters,\n });\n\n const map = new Map<string, { completed: number; errors: number }>();\n\n for (const group of res.groups) {\n const name = group.dimensions.entityName ?? 'unknown';\n const status = group.dimensions.status ?? 'ok';\n const entry = getOrCreate(map, name, () => ({ completed: 0, errors: 0 }));\n\n if (status === 'error') {\n entry.errors += group.value;\n } else {\n entry.completed += group.value;\n }\n }\n\n return Array.from(map.entries())\n .map(([name, vals]) => ({ name, ...vals }))\n .sort((a, b) => b.completed + b.errors - (a.completed + a.errors));\n}\n\nexport interface TraceVolumeData {\n agentData: VolumeRow[];\n workflowData: VolumeRow[];\n toolData: VolumeRow[];\n}\n\nexport function useTraceVolumeMetrics<TData = TraceVolumeData>(\n params: MetricsQueryFilters & { queryOptions?: MastraQueryOptions<TraceVolumeData, TData> },\n): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n const { filters, filterKey, queryOptions } = params;\n\n return useQuery({\n queryKey: ['metrics', 'trace-volume', filterKey],\n queryFn: async (): Promise<TraceVolumeData> => {\n const [agentData, workflowData, toolData] = await Promise.all([\n fetchVolume(client, 'mastra_agent_duration_ms', filters),\n fetchVolume(client, 'mastra_workflow_duration_ms', filters),\n fetchVolume(client, 'mastra_tool_duration_ms', filters),\n ]);\n return { agentData, workflowData, toolData };\n },\n ...queryOptions,\n });\n}\n"],"mappings":";;;;;AAgDA,MAAM,oBAAoB;AAE1B,MAAM,YAAoC;CACxC,OAAO;CACP,MAAM;CACN,MAAM;CACN,OAAO;CACP,OAAO;AACT;AAEA,SAAS,eACP,QACA,aACA,QACW;CACX,IAAI,WAAW,UAAU;EACvB,MAAM,KAAK,UAAU,WAAW;EAChC,OAAO;GAAE,OAAO,IAAI,KAAK,SAAS,EAAE;GAAG,KAAK,IAAI,KAAK,MAAM;EAAE;CAC/D;CACA,OAAO;EACL,OAAO,aAAa,wBAAQ,IAAI,KAAK,SAAS,iBAAiB;EAC/D,KAAK,aAAa,MAAM,IAAI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AK,IAAI,QAAQ,CAAC,CAAC,CAC7B,KAAK,CAAC,MAAM,WAAW;EAAE;EAAM,GAAG;CAAK,EAAE,CAAC,CAC1C,MAAM,GAAG,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO;AACrE;AAQA,SAAgB,sBACd,QAC8B;CAC9B,MAAM,SAAS,gBAAgB;CAC/B,MAAM,EAAE,SAAS,WAAW,iBAAiB;CAE7C,OAAO,SAAS;EACd,UAAU;GAAC;GAAW;GAAgB;EAAS;EAC/C,SAAS,YAAsC;GAC7C,MAAM,CAAC,WAAW,cAAc,YAAY,MAAM,QAAQ,IAAI;IAC5D,YAAY,QAAQ,4BAA4B,OAAO;IACvD,YAAY,QAAQ,+BAA+B,OAAO;IAC1D,YAAY,QAAQ,2BAA2B,OAAO;GACxD,CAAC;GACD,OAAO;IAAE;IAAW;IAAc;GAAS;EAC7C;EACA,GAAG;CACL,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMastraClient"],"sources":["../../../src/hooks/processors/use-processors.ts"],"sourcesContent":["import type {\n ExecuteProcessorResponse,\n GetProcessorDetailResponse,\n GetProcessorResponse,\n ProcessorConfiguration,\n ProcessorPhase,\n} from '@mastra/client-js';\nimport type { MastraDBMessage } from '@mastra/core/agent/message-list';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery, useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport type {\n GetProcessorDetailResponse as ProcessorDetail,\n GetProcessorResponse as ProcessorInfo,\n MastraDBMessage,\n ProcessorConfiguration,\n ProcessorPhase,\n};\n\nexport interface ExecuteProcessorParams {\n processorId: string;\n phase: ProcessorPhase;\n messages: MastraDBMessage[];\n agentId?: string;\n}\n\nexport type { ExecuteProcessorResponse };\n\nexport const useProcessors = <TData = Record<string, GetProcessorResponse>>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<Record<string, GetProcessorResponse>, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['processors'],\n queryFn: () => client.listProcessors(requestContext),\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useProcessor = <TData = GetProcessorDetailResponse>({\n processorId,\n requestContext,\n queryOptions,\n}: {\n processorId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetProcessorDetailResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['processor', processorId],\n queryFn: () => client.getProcessor(processorId).details(requestContext),\n ...queryOptions,\n });\n};\n\nexport const useExecuteProcessor = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<ExecuteProcessorResponse, ExecuteProcessorParams>;\n} = {}) => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: async ({\n processorId,\n phase,\n messages,\n agentId,\n }: ExecuteProcessorParams): Promise<ExecuteProcessorResponse> => {\n return client.getProcessor(processorId).execute({\n phase,\n messages,\n agentId,\n requestContext,\n });\n },\n ...queryOptions,\n });\n};\n"],"mappings":";;;;AA8BA,MAAa,iBAA+D,EAC1E,gBACA,iBAIE,CAAC,MAAoC;CACvC,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMastraClient","useQuery","useMutation"],"sources":["../../../src/hooks/processors/use-processors.ts"],"sourcesContent":["import type {\n ExecuteProcessorResponse,\n GetProcessorDetailResponse,\n GetProcessorResponse,\n ProcessorConfiguration,\n ProcessorPhase,\n} from '@mastra/client-js';\nimport type { MastraDBMessage } from '@mastra/core/agent/message-list';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery, useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport type {\n GetProcessorDetailResponse as ProcessorDetail,\n GetProcessorResponse as ProcessorInfo,\n MastraDBMessage,\n ProcessorConfiguration,\n ProcessorPhase,\n};\n\nexport interface ExecuteProcessorParams {\n processorId: string;\n phase: ProcessorPhase;\n messages: MastraDBMessage[];\n agentId?: string;\n}\n\nexport type { ExecuteProcessorResponse };\n\nexport const useProcessors = <TData = Record<string, GetProcessorResponse>>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<Record<string, GetProcessorResponse>, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['processors'],\n queryFn: () => client.listProcessors(requestContext),\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useProcessor = <TData = GetProcessorDetailResponse>({\n processorId,\n requestContext,\n queryOptions,\n}: {\n processorId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetProcessorDetailResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['processor', processorId],\n queryFn: () => client.getProcessor(processorId).details(requestContext),\n ...queryOptions,\n });\n};\n\nexport const useExecuteProcessor = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<ExecuteProcessorResponse, ExecuteProcessorParams>;\n} = {}) => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: async ({\n processorId,\n phase,\n messages,\n agentId,\n }: ExecuteProcessorParams): Promise<ExecuteProcessorResponse> => {\n return client.getProcessor(processorId).execute({\n phase,\n messages,\n agentId,\n requestContext,\n });\n },\n ...queryOptions,\n });\n};\n"],"mappings":";;;;AA8BA,MAAa,iBAA+D,EAC1E,gBACA,iBAIE,CAAC,MAAoC;CACvC,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd,UAAU,CAAC,YAAY;EACvB,eAAe,OAAO,eAAe,cAAc;EACnD,GAAG;CACL,CAAC;AACH;;;;AAKA,MAAa,gBAAoD,EAC/D,aACA,gBACA,mBAKkC;CAClC,MAAM,SAASD,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd,UAAU,CAAC,aAAa,WAAW;EACnC,eAAe,OAAO,aAAa,WAAW,CAAC,CAAC,QAAQ,cAAc;EACtE,GAAG;CACL,CAAC;AACH;AAEA,MAAa,uBAAuB,EAClC,gBACA,iBAIE,CAAC,MAAM;CACT,MAAM,SAASD,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOE,sBAAAA,YAAAA,CAAY;EACjB,YAAY,OAAO,EACjB,aACA,OACA,UACA,cAC+D;GAC/D,OAAO,OAAO,aAAa,WAAW,CAAC,CAAC,QAAQ;IAC9C;IACA;IACA;IACA;GACF,CAAC;EACH;EACA,GAAG;CACL,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMastraClient","useMastraClient"],"sources":["../../../src/hooks/prompt-blocks/use-prompt-block-versions.ts","../../../src/hooks/prompt-blocks/use-stored-prompt-blocks.ts"],"sourcesContent":["import type {\n ListPromptBlockVersionsParams,\n CreatePromptBlockVersionParams,\n ListPromptBlockVersionsResponse,\n PromptBlockVersionResponse,\n ActivatePromptBlockVersionResponse,\n DeletePromptBlockVersionResponse,\n} from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport type { ListPromptBlockVersionsParams, CreatePromptBlockVersionParams };\n\n/**\n * Hook to list versions of a stored prompt block\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const usePromptBlockVersions = <TData = ListPromptBlockVersionsResponse>({\n blockId,\n params,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n params?: ListPromptBlockVersionsParams;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ListPromptBlockVersionsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery<ListPromptBlockVersionsResponse, Error, TData>({\n queryKey: ['prompt-block-versions', blockId, params, requestContext],\n queryFn: () => client.getStoredPromptBlock(blockId).listVersions(params, requestContext),\n ...queryOptions,\n });\n};\n\n/**\n * Hook to get a single version of a stored prompt block\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const usePromptBlockVersion = <TData = PromptBlockVersionResponse>({\n blockId,\n versionId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n versionId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<PromptBlockVersionResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery<PromptBlockVersionResponse, Error, TData>({\n queryKey: ['prompt-block-version', blockId, versionId, requestContext],\n queryFn: () => client.getStoredPromptBlock(blockId).getVersion(versionId, requestContext),\n ...queryOptions,\n });\n};\n\n/**\n * Hook to create a new version of a stored prompt block\n */\nexport const useCreatePromptBlockVersion = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<PromptBlockVersionResponse, CreatePromptBlockVersionParams | undefined>;\n}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation<PromptBlockVersionResponse, Error, CreatePromptBlockVersionParams | undefined>({\n mutationFn: (params?: CreatePromptBlockVersionParams) =>\n client.getStoredPromptBlock(blockId).createVersion(params, requestContext),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to activate a specific version of a stored prompt block\n */\nexport const useActivatePromptBlockVersion = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<ActivatePromptBlockVersionResponse, string>;\n}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation<ActivatePromptBlockVersionResponse, Error, string>({\n mutationFn: (versionId: string) => client.getStoredPromptBlock(blockId).activateVersion(versionId, requestContext),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to restore a specific version of a stored prompt block (creates a new version from an old one)\n */\nexport const useRestorePromptBlockVersion = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<PromptBlockVersionResponse, string>;\n}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation<PromptBlockVersionResponse, Error, string>({\n mutationFn: (versionId: string) => client.getStoredPromptBlock(blockId).restoreVersion(versionId, requestContext),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to delete a specific version of a stored prompt block\n */\nexport const useDeletePromptBlockVersion = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<DeletePromptBlockVersionResponse, string>;\n}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation<DeletePromptBlockVersionResponse, Error, string>({\n mutationFn: (versionId: string) => client.getStoredPromptBlock(blockId).deleteVersion(versionId, requestContext),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n },\n ...queryOptions,\n });\n};\n","import type {\n MastraClient,\n ListStoredPromptBlocksParams,\n ListStoredPromptBlocksResponse,\n StoredPromptBlockResponse,\n CreateStoredPromptBlockParams,\n UpdateStoredPromptBlockParams,\n} from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport const useStoredPromptBlocks = <TData = ListStoredPromptBlocksResponse>({\n requestContext,\n queryOptions,\n ...params\n}: ListStoredPromptBlocksParams & {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ListStoredPromptBlocksResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery<ListStoredPromptBlocksResponse, Error, TData>({\n queryKey: ['stored-prompt-blocks', params, requestContext],\n queryFn: () => client.listStoredPromptBlocks(params),\n placeholderData: (previousData: ListStoredPromptBlocksResponse | undefined) => previousData,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useStoredPromptBlock = <TData = StoredPromptBlockResponse | null>({\n blockId,\n status,\n requestContext,\n queryOptions,\n}: {\n blockId?: string;\n status?: 'draft' | 'published';\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<StoredPromptBlockResponse | null, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery<StoredPromptBlockResponse | null, Error, TData>({\n queryKey: ['stored-prompt-block', blockId, status, requestContext],\n queryFn: () => (blockId ? client.getStoredPromptBlock(blockId).details(requestContext, { status }) : null),\n ...queryOptions,\n });\n};\n\ntype DeleteStoredPromptBlockResponse = Awaited<ReturnType<ReturnType<MastraClient['getStoredPromptBlock']>['delete']>>;\n\nexport const useStoredPromptBlockMutations = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: {\n createStoredPromptBlock?: MastraMutationOptions<StoredPromptBlockResponse, CreateStoredPromptBlockParams>;\n updateStoredPromptBlock?: MastraMutationOptions<StoredPromptBlockResponse, UpdateStoredPromptBlockParams>;\n deleteStoredPromptBlock?: MastraMutationOptions<DeleteStoredPromptBlockResponse, void>;\n };\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n const createMutation = useMutation({\n mutationFn: (params: CreateStoredPromptBlockParams) => client.createStoredPromptBlock(params),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-blocks'] });\n },\n ...queryOptions?.createStoredPromptBlock,\n });\n\n const updateMutation = useMutation({\n mutationFn: (params: UpdateStoredPromptBlockParams) => {\n if (!blockId) throw new Error('blockId is required for update');\n return client.getStoredPromptBlock(blockId).update(params, requestContext);\n },\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-blocks'] });\n if (blockId) {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n }\n },\n ...queryOptions?.updateStoredPromptBlock,\n });\n\n const deleteMutation = useMutation({\n mutationFn: () => {\n if (!blockId) throw new Error('blockId is required for delete');\n return client.getStoredPromptBlock(blockId).delete(requestContext);\n },\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-blocks'] });\n if (blockId) {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n }\n },\n ...queryOptions?.deleteStoredPromptBlock,\n });\n\n return {\n createStoredPromptBlock: createMutation,\n updateStoredPromptBlock: updateMutation,\n deleteStoredPromptBlock: deleteMutation,\n };\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C9D,OAAO,OAAO,qBAAqB,OAAO,CAAC,CAAC,OAAO,cAAc;GACnE;GACA,iBAAiB;IACf,YAAiB,kBAAkB,EAAE,UAAU,CAAC,sBAAsB,EAAE,CAAC;IACzE,IAAI,SACF,YAAiB,kBAAkB,EAAE,UAAU,CAAC,uBAAuB,OAAO,EAAE,CAAC;GAErF;GACA,GAAG,cAAc;EACnB,CAKwC;CACxC;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMastraClient","useQuery","useQueryClient","useMutation","useMastraClient","useQuery","useQueryClient","useMutation"],"sources":["../../../src/hooks/prompt-blocks/use-prompt-block-versions.ts","../../../src/hooks/prompt-blocks/use-stored-prompt-blocks.ts"],"sourcesContent":["import type {\n ListPromptBlockVersionsParams,\n CreatePromptBlockVersionParams,\n ListPromptBlockVersionsResponse,\n PromptBlockVersionResponse,\n ActivatePromptBlockVersionResponse,\n DeletePromptBlockVersionResponse,\n} from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport type { ListPromptBlockVersionsParams, CreatePromptBlockVersionParams };\n\n/**\n * Hook to list versions of a stored prompt block\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const usePromptBlockVersions = <TData = ListPromptBlockVersionsResponse>({\n blockId,\n params,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n params?: ListPromptBlockVersionsParams;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ListPromptBlockVersionsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery<ListPromptBlockVersionsResponse, Error, TData>({\n queryKey: ['prompt-block-versions', blockId, params, requestContext],\n queryFn: () => client.getStoredPromptBlock(blockId).listVersions(params, requestContext),\n ...queryOptions,\n });\n};\n\n/**\n * Hook to get a single version of a stored prompt block\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const usePromptBlockVersion = <TData = PromptBlockVersionResponse>({\n blockId,\n versionId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n versionId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<PromptBlockVersionResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery<PromptBlockVersionResponse, Error, TData>({\n queryKey: ['prompt-block-version', blockId, versionId, requestContext],\n queryFn: () => client.getStoredPromptBlock(blockId).getVersion(versionId, requestContext),\n ...queryOptions,\n });\n};\n\n/**\n * Hook to create a new version of a stored prompt block\n */\nexport const useCreatePromptBlockVersion = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<PromptBlockVersionResponse, CreatePromptBlockVersionParams | undefined>;\n}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation<PromptBlockVersionResponse, Error, CreatePromptBlockVersionParams | undefined>({\n mutationFn: (params?: CreatePromptBlockVersionParams) =>\n client.getStoredPromptBlock(blockId).createVersion(params, requestContext),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to activate a specific version of a stored prompt block\n */\nexport const useActivatePromptBlockVersion = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<ActivatePromptBlockVersionResponse, string>;\n}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation<ActivatePromptBlockVersionResponse, Error, string>({\n mutationFn: (versionId: string) => client.getStoredPromptBlock(blockId).activateVersion(versionId, requestContext),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to restore a specific version of a stored prompt block (creates a new version from an old one)\n */\nexport const useRestorePromptBlockVersion = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<PromptBlockVersionResponse, string>;\n}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation<PromptBlockVersionResponse, Error, string>({\n mutationFn: (versionId: string) => client.getStoredPromptBlock(blockId).restoreVersion(versionId, requestContext),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to delete a specific version of a stored prompt block\n */\nexport const useDeletePromptBlockVersion = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<DeletePromptBlockVersionResponse, string>;\n}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation<DeletePromptBlockVersionResponse, Error, string>({\n mutationFn: (versionId: string) => client.getStoredPromptBlock(blockId).deleteVersion(versionId, requestContext),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n },\n ...queryOptions,\n });\n};\n","import type {\n MastraClient,\n ListStoredPromptBlocksParams,\n ListStoredPromptBlocksResponse,\n StoredPromptBlockResponse,\n CreateStoredPromptBlockParams,\n UpdateStoredPromptBlockParams,\n} from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport const useStoredPromptBlocks = <TData = ListStoredPromptBlocksResponse>({\n requestContext,\n queryOptions,\n ...params\n}: ListStoredPromptBlocksParams & {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ListStoredPromptBlocksResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery<ListStoredPromptBlocksResponse, Error, TData>({\n queryKey: ['stored-prompt-blocks', params, requestContext],\n queryFn: () => client.listStoredPromptBlocks(params),\n placeholderData: (previousData: ListStoredPromptBlocksResponse | undefined) => previousData,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useStoredPromptBlock = <TData = StoredPromptBlockResponse | null>({\n blockId,\n status,\n requestContext,\n queryOptions,\n}: {\n blockId?: string;\n status?: 'draft' | 'published';\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<StoredPromptBlockResponse | null, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery<StoredPromptBlockResponse | null, Error, TData>({\n queryKey: ['stored-prompt-block', blockId, status, requestContext],\n queryFn: () => (blockId ? client.getStoredPromptBlock(blockId).details(requestContext, { status }) : null),\n ...queryOptions,\n });\n};\n\ntype DeleteStoredPromptBlockResponse = Awaited<ReturnType<ReturnType<MastraClient['getStoredPromptBlock']>['delete']>>;\n\nexport const useStoredPromptBlockMutations = ({\n blockId,\n requestContext,\n queryOptions,\n}: {\n blockId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: {\n createStoredPromptBlock?: MastraMutationOptions<StoredPromptBlockResponse, CreateStoredPromptBlockParams>;\n updateStoredPromptBlock?: MastraMutationOptions<StoredPromptBlockResponse, UpdateStoredPromptBlockParams>;\n deleteStoredPromptBlock?: MastraMutationOptions<DeleteStoredPromptBlockResponse, void>;\n };\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n const createMutation = useMutation({\n mutationFn: (params: CreateStoredPromptBlockParams) => client.createStoredPromptBlock(params),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-blocks'] });\n },\n ...queryOptions?.createStoredPromptBlock,\n });\n\n const updateMutation = useMutation({\n mutationFn: (params: UpdateStoredPromptBlockParams) => {\n if (!blockId) throw new Error('blockId is required for update');\n return client.getStoredPromptBlock(blockId).update(params, requestContext);\n },\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-blocks'] });\n if (blockId) {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n void queryClient.invalidateQueries({ queryKey: ['prompt-block-versions', blockId] });\n }\n },\n ...queryOptions?.updateStoredPromptBlock,\n });\n\n const deleteMutation = useMutation({\n mutationFn: () => {\n if (!blockId) throw new Error('blockId is required for delete');\n return client.getStoredPromptBlock(blockId).delete(requestContext);\n },\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-blocks'] });\n if (blockId) {\n void queryClient.invalidateQueries({ queryKey: ['stored-prompt-block', blockId] });\n }\n },\n ...queryOptions?.deleteStoredPromptBlock,\n });\n\n return {\n createStoredPromptBlock: createMutation,\n updateStoredPromptBlock: updateMutation,\n deleteStoredPromptBlock: deleteMutation,\n };\n};\n"],"mappings":";;;;;;;;;AAoBA,MAAa,0BAAmE,EAC9E,SACA,QACA,gBACA,mBAMkC;CAClC,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAwD;EAC7D,UAAU;GAAC;GAAyB;GAAS;GAAQ;EAAc;EACnE,eAAe,OAAO,qBAAqB,OAAO,CAAC,CAAC,aAAa,QAAQ,cAAc;EACvF,GAAG;CACL,CAAC;AACH;;;;;;AAOA,MAAa,yBAA6D,EACxE,SACA,WACA,gBACA,mBAMkC;CAClC,MAAM,SAASD,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAmD;EACxD,UAA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AM,SAASD,8BAAAA,gBAAgB;CAC/B,MAAM,eAAA,GAAcE,sBAAAA,eAAAA,CAAe;CAuCnC,OAAO;EACL,0BAAA,GAtCqBC,sBAAAA,YAAAA,CAAY;GACjC,aAAa,WAA0C,OAAO,wBAAwB,MAAM;GAC5F,iBAAiB;IACf,YAAiB,kBAAkB,EAAE,UAAU,CAAC,sBAAsB,EAAE,CAAC;GAC3E;GACA,GAAG,cAAc;EACnB,CAgCwC;EACtC,0BAAA,GA/BqBA,sBAAAA,YAAAA,CAAY;GACjC,aAAa,WAA0C;IACrD,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,gCAAgC;IAC9D,OAAO,OAAO,qBAAqB,OAAO,CAAC,CAAC,OAAO,QAAQ,cAAc;GAC3E;GACA,iBAAiB;IACf,YAAiB,kBAAkB,EAAE,UAAU,CAAC,sBAAsB,EAAE,CAAC;IACzE,IAAI,SAAS;KACX,YAAiB,kBAAkB,EAAE,UAAU,CAAC,uBAAuB,OAAO,EAAE,CAAC;KACjF,YAAiB,kBAAkB,EAAE,UAAU,CAAC,yBAAyB,OAAO,EAAE,CAAC;IACrF;GACF;GACA,GAAG,cAAc;EACnB,CAkBwC;EACtC,0BAAA,GAjBqBA,sBAAAA,YAAAA,CAAY;GACjC,kBAAkB;IAChB,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,gCAAgC;IAC9D,OAAO,OAAO,qBAAqB,OAAO,CAAC,CAAC,OAAO,cAAc;GACnE;GACA,iBAAiB;IACf,YAAiB,kBAAkB,EAAE,UAAU,CAAC,sBAAsB,EAAE,CAAC;IACzE,IAAI,SACF,YAAiB,kBAAkB,EAAE,UAAU,CAAC,uBAAuB,OAAO,EAAE,CAAC;GAErF;GACA,GAAG,cAAc;EACnB,CAKwC;CACxC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["QueryClient","shouldRetryQuery","QueryClientProvider"],"sources":["../../../src/hooks/query/query-client-provider.tsx"],"sourcesContent":["import type { QueryClientConfig } from '@tanstack/react-query';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { shouldRetryQuery } from './query-utils';\n\nexport interface MastraQueryClientProviderProps {\n children: ReactNode;\n options?: QueryClientConfig;\n}\n\nexport const MastraQueryClientProvider = ({ children, options }: MastraQueryClientProviderProps) => {\n const [queryClient] = useState(\n () =>\n new QueryClient({\n ...options,\n defaultOptions: {\n ...options?.defaultOptions,\n queries: {\n retry: shouldRetryQuery,\n ...options?.defaultOptions?.queries,\n },\n },\n }),\n );\n\n return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;\n};\n"],"mappings":";;;;;;AAYA,MAAa,6BAA6B,EAAE,UAAU,cAA8C;CAClG,MAAM,CAAC,gBAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useState","QueryClient","shouldRetryQuery","QueryClientProvider"],"sources":["../../../src/hooks/query/query-client-provider.tsx"],"sourcesContent":["import type { QueryClientConfig } from '@tanstack/react-query';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { useState } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { shouldRetryQuery } from './query-utils';\n\nexport interface MastraQueryClientProviderProps {\n children: ReactNode;\n options?: QueryClientConfig;\n}\n\nexport const MastraQueryClientProvider = ({ children, options }: MastraQueryClientProviderProps) => {\n const [queryClient] = useState(\n () =>\n new QueryClient({\n ...options,\n defaultOptions: {\n ...options?.defaultOptions,\n queries: {\n retry: shouldRetryQuery,\n ...options?.defaultOptions?.queries,\n },\n },\n }),\n );\n\n return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;\n};\n"],"mappings":";;;;;;AAYA,MAAa,6BAA6B,EAAE,UAAU,cAA8C;CAClG,MAAM,CAAC,gBAAA,GAAeA,MAAAA,SAAAA,OAElB,IAAIC,sBAAAA,YAAY;EACd,GAAG;EACH,gBAAgB;GACd,GAAG,SAAS;GACZ,SAAS;IACP,OAAOC,oBAAAA;IACP,GAAG,SAAS,gBAAgB;GAC9B;EACF;CACF,CAAC,CACL;CAEA,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,qBAAD;EAAqB,QAAQ;EAAc;CAA8B,CAAA;AAClF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_mastra_client_context = require("../../mastra-client-context-DzX3f0RF.cjs");
|
|
3
|
-
const
|
|
3
|
+
const require_experiments = require("../../experiments-CJw1N3FB.cjs");
|
|
4
4
|
let _tanstack_react_query = require("@tanstack/react-query");
|
|
5
5
|
//#region src/hooks/review/use-dataset-review-items.ts
|
|
6
6
|
/**
|
|
@@ -10,7 +10,7 @@ let _tanstack_react_query = require("@tanstack/react-query");
|
|
|
10
10
|
const useReviewItemsByStatus = (status, { experimentId, targetType, targetId, experiments: suppliedExperiments, isLoadingExperiments = false, queryOptions }) => {
|
|
11
11
|
const client = require_mastra_client_context.useMastraClient();
|
|
12
12
|
const hasSuppliedExperiments = suppliedExperiments !== void 0;
|
|
13
|
-
const { data: experimentsData, isLoading: isDiscoveringExperiments } =
|
|
13
|
+
const { data: experimentsData, isLoading: isDiscoveringExperiments } = require_experiments.useExperimentsForDatasetFilter({
|
|
14
14
|
datasetId: void 0,
|
|
15
15
|
target: {
|
|
16
16
|
targetType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMastraClient","useExperimentsForDatasetFilter","useMastraClient"],"sources":["../../../src/hooks/review/use-dataset-review-items.ts","../../../src/hooks/review/use-review-summary.ts"],"sourcesContent":["import type { DatasetExperiment } from '@mastra/client-js';\nimport { useQuery } from '@tanstack/react-query';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { useExperimentsForDatasetFilter } from '../experiments';\nimport type { ExperimentTargetFilter } from '../experiments';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { ReviewItem } from './types';\n\ntype ReviewStatus = 'needs-review' | 'complete';\n\nexport interface ReviewItemsOptions extends ExperimentTargetFilter {\n /** When set, only this experiment's results are loaded; otherwise every experiment in the project. */\n experimentId?: string;\n /** Explicit source owned by the caller; an empty list disables discovery too. */\n experiments?: DatasetExperiment[];\n isLoadingExperiments?: boolean;\n /** TanStack overrides spread last into the review-items query. */\n queryOptions?: MastraQueryOptions<ReviewItem[]>;\n}\n\n/**\n * Loads experiment results with the given review status, across the project, scoped to a target,\n * or scoped to one experiment.\n */\nconst useReviewItemsByStatus = (\n status: ReviewStatus,\n {\n experimentId,\n targetType,\n targetId,\n experiments: suppliedExperiments,\n isLoadingExperiments = false,\n queryOptions,\n }: ReviewItemsOptions,\n): UseQueryResult<ReviewItem[], Error> => {\n const client = useMastraClient();\n const hasSuppliedExperiments = suppliedExperiments !== undefined;\n const { data: experimentsData, isLoading: isDiscoveringExperiments } = useExperimentsForDatasetFilter({\n datasetId: undefined,\n target: { targetType, targetId },\n queryOptions: { enabled: !hasSuppliedExperiments },\n });\n const experiments = hasSuppliedExperiments ? suppliedExperiments : experimentsData?.experiments;\n const isLoadingSource = hasSuppliedExperiments ? isLoadingExperiments : isDiscoveringExperiments;\n const scopedExperiments = experimentId ? experiments?.filter(exp => exp.id === experimentId) : experiments;\n\n const query = useQuery({\n queryKey: [\n 'review-items',\n status,\n experimentId ?? 'all',\n hasSuppliedExperiments ? 'supplied' : 'discovered',\n hasSuppliedExperiments ? undefined : targetType || 'all',\n hasSuppliedExperiments ? undefined : targetId || 'all',\n scopedExperiments?.map(e => [e.datasetId, e.id]),\n ],\n queryFn: async () => {\n if (!scopedExperiments || scopedExperiments.length === 0) return [] as ReviewItem[];\n\n const allResults = await Promise.all(\n scopedExperiments.map(async exp => {\n if (!exp.datasetId) return [];\n try {\n const { results } = await client.listDatasetExperimentResults(exp.datasetId, exp.id);\n return results\n .filter(r => r.status === status)\n .map(r => ({\n id: r.id,\n input: r.input,\n output: r.output,\n error: r.error,\n itemId: r.itemId,\n experimentId: r.experimentId,\n datasetId: exp.datasetId ?? undefined,\n traceId: r.traceId ?? undefined,\n scores: r.scores ? Object.fromEntries(r.scores.map(s => [s.scorerId, s.score ?? 0])) : {},\n tags: r.tags ?? [],\n targetType: r.targetType,\n createdAt: r.createdAt,\n startedAt: r.startedAt,\n completedAt: r.completedAt,\n status: r.status,\n groundTruth: r.groundTruth,\n toolMockReport: r.toolMockReport,\n }));\n } catch {\n return [];\n }\n }),\n );\n\n return allResults.flat() as ReviewItem[];\n },\n enabled: Boolean(experiments),\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n\n // The results query is disabled until experiments arrive, so its own `isLoading`\n // is false during that window; surface the upstream load to avoid an empty flash.\n return { ...query, isLoading: query.isLoading || isLoadingSource } as UseQueryResult<ReviewItem[], Error>;\n};\n\n/** Loads persisted review items (status='needs-review'), project-wide, per target or for one experiment. */\nexport const useReviewItems = (options: ReviewItemsOptions = {}) => useReviewItemsByStatus('needs-review', options);\n\n/** Loads completed review items (status='complete'), project-wide, per target or for one experiment. */\nexport const useCompletedItems = (options: ReviewItemsOptions = {}) => useReviewItemsByStatus('complete', options);\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ReviewSummaryResponse = Awaited<ReturnType<MastraClient['getExperimentReviewSummary']>>;\n\nexport function useReviewSummary<TData = ReviewSummaryResponse>({\n queryOptions,\n}: {\n queryOptions?: MastraQueryOptions<ReviewSummaryResponse, TData>;\n} = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['experiment-review-summary'],\n queryFn: () => client.getExperimentReviewSummary(),\n ...queryOptions,\n });\n}\n"],"mappings":";;;;;;;;;AAyBA,MAAM,0BACJ,QACA,EACE,cACA,YACA,UACA,aAAa,qBACb,uBAAuB,OACvB,mBAEsC;CACxC,MAAM,SAASA,8BAAAA,gBAAgB;CAC/B,MAAM,yBAAyB,wBAAwB,KAAA;CACvD,MAAM,EAAE,MAAM,iBAAiB,WAAW,6BAA6BC,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMastraClient","useExperimentsForDatasetFilter","useQuery","useMastraClient","useQuery"],"sources":["../../../src/hooks/review/use-dataset-review-items.ts","../../../src/hooks/review/use-review-summary.ts"],"sourcesContent":["import type { DatasetExperiment } from '@mastra/client-js';\nimport { useQuery } from '@tanstack/react-query';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { useExperimentsForDatasetFilter } from '../experiments';\nimport type { ExperimentTargetFilter } from '../experiments';\nimport type { MastraQueryOptions } from '../shared/query-options';\nimport type { ReviewItem } from './types';\n\ntype ReviewStatus = 'needs-review' | 'complete';\n\nexport interface ReviewItemsOptions extends ExperimentTargetFilter {\n /** When set, only this experiment's results are loaded; otherwise every experiment in the project. */\n experimentId?: string;\n /** Explicit source owned by the caller; an empty list disables discovery too. */\n experiments?: DatasetExperiment[];\n isLoadingExperiments?: boolean;\n /** TanStack overrides spread last into the review-items query. */\n queryOptions?: MastraQueryOptions<ReviewItem[]>;\n}\n\n/**\n * Loads experiment results with the given review status, across the project, scoped to a target,\n * or scoped to one experiment.\n */\nconst useReviewItemsByStatus = (\n status: ReviewStatus,\n {\n experimentId,\n targetType,\n targetId,\n experiments: suppliedExperiments,\n isLoadingExperiments = false,\n queryOptions,\n }: ReviewItemsOptions,\n): UseQueryResult<ReviewItem[], Error> => {\n const client = useMastraClient();\n const hasSuppliedExperiments = suppliedExperiments !== undefined;\n const { data: experimentsData, isLoading: isDiscoveringExperiments } = useExperimentsForDatasetFilter({\n datasetId: undefined,\n target: { targetType, targetId },\n queryOptions: { enabled: !hasSuppliedExperiments },\n });\n const experiments = hasSuppliedExperiments ? suppliedExperiments : experimentsData?.experiments;\n const isLoadingSource = hasSuppliedExperiments ? isLoadingExperiments : isDiscoveringExperiments;\n const scopedExperiments = experimentId ? experiments?.filter(exp => exp.id === experimentId) : experiments;\n\n const query = useQuery({\n queryKey: [\n 'review-items',\n status,\n experimentId ?? 'all',\n hasSuppliedExperiments ? 'supplied' : 'discovered',\n hasSuppliedExperiments ? undefined : targetType || 'all',\n hasSuppliedExperiments ? undefined : targetId || 'all',\n scopedExperiments?.map(e => [e.datasetId, e.id]),\n ],\n queryFn: async () => {\n if (!scopedExperiments || scopedExperiments.length === 0) return [] as ReviewItem[];\n\n const allResults = await Promise.all(\n scopedExperiments.map(async exp => {\n if (!exp.datasetId) return [];\n try {\n const { results } = await client.listDatasetExperimentResults(exp.datasetId, exp.id);\n return results\n .filter(r => r.status === status)\n .map(r => ({\n id: r.id,\n input: r.input,\n output: r.output,\n error: r.error,\n itemId: r.itemId,\n experimentId: r.experimentId,\n datasetId: exp.datasetId ?? undefined,\n traceId: r.traceId ?? undefined,\n scores: r.scores ? Object.fromEntries(r.scores.map(s => [s.scorerId, s.score ?? 0])) : {},\n tags: r.tags ?? [],\n targetType: r.targetType,\n createdAt: r.createdAt,\n startedAt: r.startedAt,\n completedAt: r.completedAt,\n status: r.status,\n groundTruth: r.groundTruth,\n toolMockReport: r.toolMockReport,\n }));\n } catch {\n return [];\n }\n }),\n );\n\n return allResults.flat() as ReviewItem[];\n },\n enabled: Boolean(experiments),\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n\n // The results query is disabled until experiments arrive, so its own `isLoading`\n // is false during that window; surface the upstream load to avoid an empty flash.\n return { ...query, isLoading: query.isLoading || isLoadingSource } as UseQueryResult<ReviewItem[], Error>;\n};\n\n/** Loads persisted review items (status='needs-review'), project-wide, per target or for one experiment. */\nexport const useReviewItems = (options: ReviewItemsOptions = {}) => useReviewItemsByStatus('needs-review', options);\n\n/** Loads completed review items (status='complete'), project-wide, per target or for one experiment. */\nexport const useCompletedItems = (options: ReviewItemsOptions = {}) => useReviewItemsByStatus('complete', options);\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\ntype ReviewSummaryResponse = Awaited<ReturnType<MastraClient['getExperimentReviewSummary']>>;\n\nexport function useReviewSummary<TData = ReviewSummaryResponse>({\n queryOptions,\n}: {\n queryOptions?: MastraQueryOptions<ReviewSummaryResponse, TData>;\n} = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['experiment-review-summary'],\n queryFn: () => client.getExperimentReviewSummary(),\n ...queryOptions,\n });\n}\n"],"mappings":";;;;;;;;;AAyBA,MAAM,0BACJ,QACA,EACE,cACA,YACA,UACA,aAAa,qBACb,uBAAuB,OACvB,mBAEsC;CACxC,MAAM,SAASA,8BAAAA,gBAAgB;CAC/B,MAAM,yBAAyB,wBAAwB,KAAA;CACvD,MAAM,EAAE,MAAM,iBAAiB,WAAW,6BAA6BC,oBAAAA,+BAA+B;EACpG,WAAW,KAAA;EACX,QAAQ;GAAE;GAAY;EAAS;EAC/B,cAAc,EAAE,SAAS,CAAC,uBAAuB;CACnD,CAAC;CACD,MAAM,cAAc,yBAAyB,sBAAsB,iBAAiB;CACpF,MAAM,kBAAkB,yBAAyB,uBAAuB;CACxE,MAAM,oBAAoB,eAAe,aAAa,QAAO,QAAO,IAAI,OAAO,YAAY,IAAI;CAE/F,MAAM,SAAA,GAAQC,sBAAAA,SAAAA,CAAS;EACrB,UAAU;GACR;GACA;GACA,gBAAgB;GAChB,yBAAyB,aAAa;GACtC,yBAAyB,KAAA,IAAY,cAAc;GACnD,yBAAyB,KAAA,IAAY,YAAY;GACjD,mBAAmB,KAAI,MAAK,CAAC,EAAE,WAAW,EAAE,EAAE,CAAC;EACjD;EACA,SAAS,YAAY;GACnB,IAAI,CAAC,qBAAqB,kBAAkB,WAAW,GAAG,OAAO,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G;CACL,CAAC;AACH"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as useMastraClient } from "../../mastra-client-context-Bx_g84YB.js";
|
|
2
|
-
import { useExperimentsForDatasetFilter } from "
|
|
2
|
+
import { a as useExperimentsForDatasetFilter } from "../../experiments-B7vRMK5T.js";
|
|
3
3
|
import { useQuery } from "@tanstack/react-query";
|
|
4
4
|
//#region src/hooks/review/use-dataset-review-items.ts
|
|
5
5
|
/**
|