@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
|
@@ -1,229 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { t as useInView } from "../../use-in-view-C9sYPGRm.js";
|
|
3
|
-
import { t as useCombineByIds } from "../../combine-by-ids-CcaZKGT9.js";
|
|
4
|
-
import { t as getOrCreate } from "../../map-CDv4fbu4.js";
|
|
5
|
-
import { useEffect } from "react";
|
|
6
|
-
import { useInfiniteQuery, useQueries, useQuery } from "@tanstack/react-query";
|
|
7
|
-
//#region src/hooks/experiments/use-experiment-item-usage.ts
|
|
8
|
-
const INPUT_TOKEN_METRIC = "mastra_model_total_input_tokens";
|
|
9
|
-
const OUTPUT_TOKEN_METRIC = "mastra_model_total_output_tokens";
|
|
10
|
-
const POLL_INTERVAL_MS = 2e3;
|
|
11
|
-
const createAccumulator = () => ({
|
|
12
|
-
estimatedCost: 0,
|
|
13
|
-
costUnits: /* @__PURE__ */ new Set(),
|
|
14
|
-
hasUnknownCostUnit: false
|
|
15
|
-
});
|
|
16
|
-
function accumulate(accumulator, tokenField, group) {
|
|
17
|
-
accumulator[tokenField] = (accumulator[tokenField] ?? 0) + group.value;
|
|
18
|
-
if (group.estimatedCost == null) return;
|
|
19
|
-
accumulator.estimatedCost += group.estimatedCost;
|
|
20
|
-
if (group.costUnit) accumulator.costUnits.add(group.costUnit.toLowerCase());
|
|
21
|
-
else accumulator.hasUnknownCostUnit = true;
|
|
22
|
-
}
|
|
23
|
-
function toUsage(accumulator) {
|
|
24
|
-
const isPriced = !accumulator.hasUnknownCostUnit && accumulator.costUnits.size === 1;
|
|
25
|
-
return {
|
|
26
|
-
inputTokens: accumulator.inputTokens,
|
|
27
|
-
outputTokens: accumulator.outputTokens,
|
|
28
|
-
estimatedCost: isPriced ? accumulator.estimatedCost : void 0,
|
|
29
|
-
costUnit: isPriced ? [...accumulator.costUnits][0] : void 0
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/** Builds the experiment totals and the per-trace usage in a single pass over the groups. */
|
|
33
|
-
function toExperimentUsage(response) {
|
|
34
|
-
const summary = createAccumulator();
|
|
35
|
-
const accumulators = /* @__PURE__ */ new Map();
|
|
36
|
-
for (const group of response.groups) {
|
|
37
|
-
const metricName = group.dimensions.name;
|
|
38
|
-
if (metricName !== INPUT_TOKEN_METRIC && metricName !== OUTPUT_TOKEN_METRIC) continue;
|
|
39
|
-
const tokenField = metricName === INPUT_TOKEN_METRIC ? "inputTokens" : "outputTokens";
|
|
40
|
-
accumulate(summary, tokenField, group);
|
|
41
|
-
const traceId = group.dimensions.traceId;
|
|
42
|
-
if (traceId) accumulate(getOrCreate(accumulators, traceId, createAccumulator), tokenField, group);
|
|
43
|
-
}
|
|
44
|
-
const traces = {};
|
|
45
|
-
for (const [traceId, accumulator] of accumulators) traces[traceId] = toUsage(accumulator);
|
|
46
|
-
return {
|
|
47
|
-
summary: toUsage(summary),
|
|
48
|
-
traces
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/** How many breakdowns to fetch after completion while the exporter may still be flushing metrics. */
|
|
52
|
-
const MAX_EMPTY_ATTEMPTS = 5;
|
|
53
|
-
const isEmptyUsage = (usage) => !usage || Object.keys(usage.traces).length === 0 && usage.summary.inputTokens === void 0 && usage.summary.outputTokens === void 0;
|
|
54
|
-
/**
|
|
55
|
-
* Token and cost usage of several experiments, keyed by experiment id: each entry holds the
|
|
56
|
-
* experiment totals (`summary`) and every item's usage keyed by trace id (`traces`).
|
|
57
|
-
* Sends one metric breakdown request per experiment, filtered by its id rather than by trace ids,
|
|
58
|
-
* so it does not wait for the experiment results. Usage is only fetched once an experiment has
|
|
59
|
-
* finished; while the breakdown is still empty (metrics flushing), it retries every 2 seconds up to
|
|
60
|
-
* 5 attempts. No request is made when the observability store cannot serve metrics.
|
|
61
|
-
*/
|
|
62
|
-
const useExperimentsItemUsage = ({ experiments, supportsMetrics }) => {
|
|
63
|
-
const client = useMastraClient();
|
|
64
|
-
const combine = useCombineByIds(experiments.map((experiment) => experiment.id));
|
|
65
|
-
return useQueries({
|
|
66
|
-
queries: experiments.map(({ id, status }) => {
|
|
67
|
-
const finished = status !== "running" && status !== "pending";
|
|
68
|
-
return {
|
|
69
|
-
queryKey: [
|
|
70
|
-
"experiment-item-usage",
|
|
71
|
-
id,
|
|
72
|
-
finished
|
|
73
|
-
],
|
|
74
|
-
queryFn: async () => toExperimentUsage(await client.getMetricBreakdown({
|
|
75
|
-
name: [INPUT_TOKEN_METRIC, OUTPUT_TOKEN_METRIC],
|
|
76
|
-
aggregation: "sum",
|
|
77
|
-
groupBy: ["traceId", "name"],
|
|
78
|
-
filters: { experimentId: id }
|
|
79
|
-
})),
|
|
80
|
-
enabled: supportsMetrics && finished,
|
|
81
|
-
refetchInterval: (query) => isEmptyUsage(query.state.data) && query.state.dataUpdateCount < MAX_EMPTY_ATTEMPTS ? POLL_INTERVAL_MS : false
|
|
82
|
-
};
|
|
83
|
-
}),
|
|
84
|
-
combine
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/hooks/experiments/use-experiment-metrics.ts
|
|
89
|
-
/**
|
|
90
|
-
* Experiment-scoped metrics (tokens, cost, avg agent latency).
|
|
91
|
-
* Filters only by experimentId — no time window, since the experiment already bounds the row set.
|
|
92
|
-
* Polls every 2 seconds while the experiment is running or pending.
|
|
93
|
-
*
|
|
94
|
-
* Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
|
|
95
|
-
*/
|
|
96
|
-
const useExperimentMetrics = ({ experimentId, experimentStatus, supportsMetrics, queryOptions }) => {
|
|
97
|
-
const client = useMastraClient();
|
|
98
|
-
const isEnabled = Boolean(experimentId) && supportsMetrics;
|
|
99
|
-
const query = useQuery({
|
|
100
|
-
queryKey: ["experiment-metrics", experimentId],
|
|
101
|
-
refetchInterval: experimentStatus === "running" || experimentStatus === "pending" ? 2e3 : false,
|
|
102
|
-
queryFn: async () => {
|
|
103
|
-
if (!experimentId) throw new Error("experimentId is required");
|
|
104
|
-
const filters = { experimentId };
|
|
105
|
-
const [tokens, avgDuration, runs] = await Promise.all([
|
|
106
|
-
client.getMetricAggregate({
|
|
107
|
-
name: ["mastra_model_total_input_tokens", "mastra_model_total_output_tokens"],
|
|
108
|
-
aggregation: "sum",
|
|
109
|
-
filters
|
|
110
|
-
}),
|
|
111
|
-
client.getMetricAggregate({
|
|
112
|
-
name: ["mastra_agent_duration_ms"],
|
|
113
|
-
aggregation: "avg",
|
|
114
|
-
filters
|
|
115
|
-
}),
|
|
116
|
-
client.getMetricAggregate({
|
|
117
|
-
name: ["mastra_agent_duration_ms"],
|
|
118
|
-
aggregation: "count",
|
|
119
|
-
filters
|
|
120
|
-
})
|
|
121
|
-
]);
|
|
122
|
-
return {
|
|
123
|
-
totalTokens: tokens.value ?? null,
|
|
124
|
-
estimatedCost: tokens.estimatedCost ?? null,
|
|
125
|
-
costUnit: tokens.costUnit ?? null,
|
|
126
|
-
avgAgentDurationMs: avgDuration.value ?? null,
|
|
127
|
-
agentRuns: runs.value ?? null
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
...queryOptions
|
|
131
|
-
});
|
|
132
|
-
return {
|
|
133
|
-
data: query.data,
|
|
134
|
-
isLoading: query.isLoading,
|
|
135
|
-
isEnabled
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/hooks/experiments/use-experiment-trace.ts
|
|
140
|
-
/**
|
|
141
|
-
* Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.
|
|
142
|
-
*/
|
|
143
|
-
const useExperimentTrace = ({ traceId, queryOptions }) => {
|
|
144
|
-
const client = useMastraClient();
|
|
145
|
-
return useQuery({
|
|
146
|
-
queryKey: ["experiment-trace-light", traceId],
|
|
147
|
-
queryFn: async () => {
|
|
148
|
-
if (!traceId) throw new Error("Trace ID is required");
|
|
149
|
-
return client.getTraceLight(traceId);
|
|
150
|
-
},
|
|
151
|
-
...queryOptions
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/hooks/experiments/use-experiments-for-dataset-filter.ts
|
|
156
|
-
/** Explicit page size: server defaults are 20 (global) / 10 (per dataset), which is too small for the list. */
|
|
157
|
-
const EXPERIMENTS_PAGE_SIZE = 100;
|
|
158
|
-
function useExperimentsForDatasetFilter({ datasetId, target, queryOptions }) {
|
|
159
|
-
const client = useMastraClient();
|
|
160
|
-
const params = { perPage: 100 };
|
|
161
|
-
if (target?.targetType) params.targetType = target.targetType;
|
|
162
|
-
if (target?.targetId) params.targetId = target.targetId;
|
|
163
|
-
return useQuery({
|
|
164
|
-
queryKey: datasetId ? [
|
|
165
|
-
"dataset-experiments",
|
|
166
|
-
datasetId,
|
|
167
|
-
params
|
|
168
|
-
] : ["experiments", params],
|
|
169
|
-
queryFn: () => datasetId ? client.listDatasetExperiments(datasetId, params) : client.listExperiments(params),
|
|
170
|
-
...queryOptions
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/hooks/experiments/use-infinite-experiments.ts
|
|
175
|
-
const EXPERIMENTS_PER_PAGE = 100;
|
|
176
|
-
function useInfiniteExperiments({ datasetId, target, orderBy, queryOptions }) {
|
|
177
|
-
const client = useMastraClient();
|
|
178
|
-
const { inView: isEndOfListInView, setRef: setEndOfListElement } = useInView();
|
|
179
|
-
const targetType = target?.targetType || void 0;
|
|
180
|
-
const targetId = target?.targetId || void 0;
|
|
181
|
-
const query = useInfiniteQuery({
|
|
182
|
-
queryKey: datasetId ? [
|
|
183
|
-
"dataset-experiments",
|
|
184
|
-
datasetId,
|
|
185
|
-
"infinite",
|
|
186
|
-
{
|
|
187
|
-
targetType,
|
|
188
|
-
targetId,
|
|
189
|
-
orderBy
|
|
190
|
-
}
|
|
191
|
-
] : [
|
|
192
|
-
"experiments",
|
|
193
|
-
"infinite",
|
|
194
|
-
{
|
|
195
|
-
targetType,
|
|
196
|
-
targetId,
|
|
197
|
-
orderBy
|
|
198
|
-
}
|
|
199
|
-
],
|
|
200
|
-
queryFn: ({ pageParam }) => {
|
|
201
|
-
const params = {
|
|
202
|
-
page: pageParam,
|
|
203
|
-
perPage: 100
|
|
204
|
-
};
|
|
205
|
-
if (targetType) params.targetType = targetType;
|
|
206
|
-
if (targetId) params.targetId = targetId;
|
|
207
|
-
if (orderBy) params.orderBy = orderBy;
|
|
208
|
-
return datasetId ? client.listDatasetExperiments(datasetId, params) : client.listExperiments(params);
|
|
209
|
-
},
|
|
210
|
-
initialPageParam: 0,
|
|
211
|
-
getNextPageParam: (lastPage, _, lastPageParam) => {
|
|
212
|
-
if (!lastPage?.experiments?.length || !lastPage.pagination?.hasMore) return;
|
|
213
|
-
return lastPageParam + 1;
|
|
214
|
-
},
|
|
215
|
-
select: (data) => data.pages.flatMap((page) => page?.experiments ?? []),
|
|
216
|
-
...queryOptions
|
|
217
|
-
});
|
|
218
|
-
useEffect(() => {
|
|
219
|
-
if (isEndOfListInView && query.hasNextPage && !query.isFetchingNextPage) query.fetchNextPage();
|
|
220
|
-
}, [isEndOfListInView, query]);
|
|
221
|
-
return {
|
|
222
|
-
...query,
|
|
223
|
-
setEndOfListElement
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
//#endregion
|
|
227
|
-
export { EXPERIMENTS_PAGE_SIZE, EXPERIMENTS_PER_PAGE, useExperimentMetrics, useExperimentTrace, useExperimentsForDatasetFilter, useExperimentsItemUsage, useInfiniteExperiments };
|
|
228
|
-
|
|
229
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { i as EXPERIMENTS_PAGE_SIZE, t as EXPERIMENTS_PER_PAGE, s as useExperimentMetrics, o as useExperimentTrace, a as useExperimentsForDatasetFilter, c as useExperimentsItemUsage, r as useExperimentsListMetrics, n as useInfiniteExperiments } from "../../experiments-B7vRMK5T.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { GetMetricBreakdownResponse } from '@mastra/core/storage';
|
|
2
|
+
export declare const INPUT_TOKEN_METRIC = "mastra_model_total_input_tokens";
|
|
3
|
+
export declare const OUTPUT_TOKEN_METRIC = "mastra_model_total_output_tokens";
|
|
4
|
+
export interface ExperimentItemUsage {
|
|
5
|
+
inputTokens?: number;
|
|
6
|
+
outputTokens?: number;
|
|
7
|
+
/** Undefined when no group is priced or when groups use different cost units. */
|
|
8
|
+
estimatedCost?: number;
|
|
9
|
+
costUnit?: string;
|
|
10
|
+
}
|
|
11
|
+
export type UsageAccumulator = {
|
|
12
|
+
inputTokens?: number;
|
|
13
|
+
outputTokens?: number;
|
|
14
|
+
estimatedCost: number;
|
|
15
|
+
costUnits: Set<string>;
|
|
16
|
+
hasUnknownCostUnit: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare const createAccumulator: () => UsageAccumulator;
|
|
19
|
+
type BreakdownGroup = GetMetricBreakdownResponse['groups'][number];
|
|
20
|
+
/** The token field a breakdown group feeds, or undefined when the group is not a token metric. */
|
|
21
|
+
export declare function tokenFieldOf(group: BreakdownGroup): 'inputTokens' | 'outputTokens' | undefined;
|
|
22
|
+
export declare function accumulate(accumulator: UsageAccumulator, tokenField: 'inputTokens' | 'outputTokens', group: BreakdownGroup): void;
|
|
23
|
+
export declare function toUsage(accumulator: UsageAccumulator): ExperimentItemUsage;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=usage-accumulator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-accumulator.d.ts","sourceRoot":"","sources":["../../../src/hooks/experiments/usage-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAEvE,eAAO,MAAM,kBAAkB,oCAAoC,CAAC;AACpE,eAAO,MAAM,mBAAmB,qCAAqC,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACvB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAO,gBAInC,CAAC;AAEH,KAAK,cAAc,GAAG,0BAA0B,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE,kGAAkG;AAClG,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,aAAa,GAAG,cAAc,GAAG,SAAS,CAK9F;AAED,wBAAgB,UAAU,CACxB,WAAW,EAAE,gBAAgB,EAC7B,UAAU,EAAE,aAAa,GAAG,cAAc,EAC1C,KAAK,EAAE,cAAc,QAWtB;AAED,wBAAgB,OAAO,CAAC,WAAW,EAAE,gBAAgB,GAAG,mBAAmB,CAS1E"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import type { ExperimentRef } from '../datasets/use-dataset-experiments.js';
|
|
2
2
|
import type { ExperimentQueriesResult } from '../shared/combine-by-ids.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
outputTokens?: number;
|
|
6
|
-
/** Undefined when no group is priced or when groups use different cost units. */
|
|
7
|
-
estimatedCost?: number;
|
|
8
|
-
costUnit?: string;
|
|
9
|
-
}
|
|
3
|
+
import type { ExperimentItemUsage } from './usage-accumulator.js';
|
|
4
|
+
export type { ExperimentItemUsage } from './usage-accumulator.js';
|
|
10
5
|
/** Usage of one experiment: its totals, and each item's usage keyed by the trace id of its run. */
|
|
11
6
|
export interface ExperimentUsage {
|
|
12
7
|
/** Totals across every item. The cost sums priced groups only. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-experiment-item-usage.d.ts","sourceRoot":"","sources":["../../../src/hooks/experiments/use-experiment-item-usage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"use-experiment-item-usage.d.ts","sourceRoot":"","sources":["../../../src/hooks/experiments/use-experiment-item-usage.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAUxE,OAAO,KAAK,EAAE,mBAAmB,EAAoB,MAAM,qBAAqB,CAAC;AAEjF,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAI/D,mGAAmG;AACnG,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,OAAO,EAAE,mBAAmB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;CAC7C;AAiCD;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,sCAGjC;IACD,WAAW,EAAE,aAAa,EAAE,CAAC;IAC7B,eAAe,EAAE,OAAO,CAAC;CAC1B,KAAG,uBAAuB,CAAC,eAAe,CAyB1C,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { ExperimentRef } from '../datasets/use-dataset-experiments.js';
|
|
3
|
+
import type { ExperimentItemUsage } from './usage-accumulator.js';
|
|
4
|
+
/** Totals of one experiment: token usage, its estimated cost, and the average agent run duration. */
|
|
5
|
+
export interface ExperimentListMetrics extends ExperimentItemUsage {
|
|
6
|
+
avgDurationMs?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Token usage, estimated cost and average agent duration of many experiments, keyed by experiment id.
|
|
10
|
+
* Sends two metric breakdowns per 500 experiments (tokens grouped by experiment and metric name,
|
|
11
|
+
* durations grouped by experiment) instead of one request per experiment.
|
|
12
|
+
* Experiments without any metric are absent from the map. Polls while an experiment is running
|
|
13
|
+
* or pending. No request is made when the observability store cannot serve metrics.
|
|
14
|
+
*/
|
|
15
|
+
export declare const useExperimentsListMetrics: ({ experiments, supportsMetrics, }: {
|
|
16
|
+
experiments: ExperimentRef[];
|
|
17
|
+
supportsMetrics: boolean;
|
|
18
|
+
}) => UseQueryResult<Map<string, ExperimentListMetrics>, Error>;
|
|
19
|
+
//# sourceMappingURL=use-experiments-list-metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-experiments-list-metrics.d.ts","sourceRoot":"","sources":["../../../src/hooks/experiments/use-experiments-list-metrics.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAUzE,OAAO,KAAK,EAAE,mBAAmB,EAAoB,MAAM,qBAAqB,CAAC;AAOjF,qGAAqG;AACrG,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AA4CD;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,sCAGnC;IACD,WAAW,EAAE,aAAa,EAAE,CAAC;IAC7B,eAAe,EAAE,OAAO,CAAC;CAC1B,KAAG,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,EAAE,KAAK,CAwC3D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMastraClient"],"sources":["../../../src/hooks/feedback/use-feedback.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport type FeedbackReviewStatus = 'needs-review' | 'reviewed';\n\ntype UpdateFeedbackReviewStatusVariables = { feedbackId: string; reviewStatus: FeedbackReviewStatus };\ntype UpdateFeedbackReviewStatusResponse = Awaited<ReturnType<MastraClient['updateFeedbackReviewStatus']>>;\n\nexport function useUpdateFeedbackReviewStatus({\n queryOptions,\n}: {\n queryOptions?: MastraMutationOptions<UpdateFeedbackReviewStatusResponse, UpdateFeedbackReviewStatusVariables>;\n} = {}) {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ feedbackId, reviewStatus }: UpdateFeedbackReviewStatusVariables) =>\n client.updateFeedbackReviewStatus({ feedbackId, reviewStatus }),\n onSuccess: () =>\n Promise.all([\n queryClient.invalidateQueries({ queryKey: ['trace-feedback'] }),\n queryClient.invalidateQueries({ queryKey: ['span-feedback'] }),\n ]),\n ...queryOptions,\n });\n}\n"],"mappings":";;;;;AAUA,SAAgB,8BAA8B,EAC5C,iBAGE,CAAC,GAAG;CACN,MAAM,SAASA,8BAAAA,gBAAgB;CAC/B,MAAM,eAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMastraClient","useQueryClient","useMutation"],"sources":["../../../src/hooks/feedback/use-feedback.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\nexport type FeedbackReviewStatus = 'needs-review' | 'reviewed';\n\ntype UpdateFeedbackReviewStatusVariables = { feedbackId: string; reviewStatus: FeedbackReviewStatus };\ntype UpdateFeedbackReviewStatusResponse = Awaited<ReturnType<MastraClient['updateFeedbackReviewStatus']>>;\n\nexport function useUpdateFeedbackReviewStatus({\n queryOptions,\n}: {\n queryOptions?: MastraMutationOptions<UpdateFeedbackReviewStatusResponse, UpdateFeedbackReviewStatusVariables>;\n} = {}) {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ feedbackId, reviewStatus }: UpdateFeedbackReviewStatusVariables) =>\n client.updateFeedbackReviewStatus({ feedbackId, reviewStatus }),\n onSuccess: () =>\n Promise.all([\n queryClient.invalidateQueries({ queryKey: ['trace-feedback'] }),\n queryClient.invalidateQueries({ queryKey: ['span-feedback'] }),\n ]),\n ...queryOptions,\n });\n}\n"],"mappings":";;;;;AAUA,SAAgB,8BAA8B,EAC5C,iBAGE,CAAC,GAAG;CACN,MAAM,SAASA,8BAAAA,gBAAgB;CAC/B,MAAM,eAAA,GAAcC,sBAAAA,eAAAA,CAAe;CAEnC,QAAA,GAAOC,sBAAAA,YAAAA,CAAY;EACjB,aAAa,EAAE,YAAY,mBACzB,OAAO,2BAA2B;GAAE;GAAY;EAAa,CAAC;EAChE,iBACE,QAAQ,IAAI,CACV,YAAY,kBAAkB,EAAE,UAAU,CAAC,gBAAgB,EAAE,CAAC,GAC9D,YAAY,kBAAkB,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,CAC/D,CAAC;EACH,GAAG;CACL,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMastraClient"],"sources":["../../../src/hooks/llm/use-llm-providers.ts"],"sourcesContent":["import type { ListAgentsModelProvidersResponse } 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\nexport const useLLMProviders = <TData = ListAgentsModelProvidersResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ListAgentsModelProvidersResponse, TData> } = {}): UseQueryResult<\n TData,\n Error\n> => {\n const client = useMastraClient();\n\n return useQuery<ListAgentsModelProvidersResponse, Error, TData>({\n queryKey: ['llm-providers'],\n queryFn: async () => client.listAgentsModelProviders(),\n retry: false,\n ...queryOptions,\n });\n};\n"],"mappings":";;;;AAMA,MAAa,mBAA6D,EACxE,iBACkF,CAAC,MAGhF;CACH,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMastraClient","useQuery"],"sources":["../../../src/hooks/llm/use-llm-providers.ts"],"sourcesContent":["import type { ListAgentsModelProvidersResponse } 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\nexport const useLLMProviders = <TData = ListAgentsModelProvidersResponse>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<ListAgentsModelProvidersResponse, TData> } = {}): UseQueryResult<\n TData,\n Error\n> => {\n const client = useMastraClient();\n\n return useQuery<ListAgentsModelProvidersResponse, Error, TData>({\n queryKey: ['llm-providers'],\n queryFn: async () => client.listAgentsModelProviders(),\n retry: false,\n ...queryOptions,\n });\n};\n"],"mappings":";;;;AAMA,MAAa,mBAA6D,EACxE,iBACkF,CAAC,MAGhF;CACH,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAyD;EAC9D,UAAU,CAAC,eAAe;EAC1B,SAAS,YAAY,OAAO,yBAAyB;EACrD,OAAO;EACP,GAAG;CACL,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["isUnsupportedObservabilityOperationError","isObservabilityUnavailableError","useMastraClient","useInView"],"sources":["../../../src/hooks/logs/use-logs.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useInfiniteQuery } from '@tanstack/react-query';\nimport { useEffect } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isObservabilityUnavailableError, isUnsupportedObservabilityOperationError } from '../query/query-utils';\nimport type { MastraInfiniteQueryOptions } from '../shared/query-options';\n\nimport { useInView } from '../shared/use-in-view';\nimport type { LogRecord } from './types';\n\ntype ListLogsArgs = NonNullable<Parameters<MastraClient['listLogsVNext']>[0]>;\ntype ListLogsResponse = Awaited<ReturnType<MastraClient['listLogsVNext']>>;\n\ninterface UseLogsReturn {\n data: LogRecord[] | undefined;\n hasNextPage: boolean;\n isFetchingNextPage: boolean;\n fetchNextPage: () => void;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n setEndOfListElement: (node: HTMLDivElement | null) => void;\n}\n\nconst LOGS_PER_PAGE = 20;\nconst LOGS_REFETCH_INTERVAL_MS = 10000;\n\nexport type LogsOrderBy = NonNullable<ListLogsArgs['orderBy']>;\n\nconst DEFAULT_LOGS_ORDER_BY: LogsOrderBy = { field: 'timestamp', direction: 'DESC' };\n\nexport interface LogsFilters {\n filters?: ListLogsArgs['filters'];\n orderBy?: LogsOrderBy;\n /** TanStack overrides spread last. The hook returns the selected log list, so `select` must keep that shape. */\n queryOptions?: MastraInfiniteQueryOptions<\n ListLogsResponse,\n ReturnType<typeof selectLogs>,\n readonly unknown[],\n number\n >;\n}\n\nfunction getNextPageParam(lastPage: ListLogsResponse | undefined, _allPages: unknown, lastPageParam: number) {\n if (lastPage?.pagination?.hasMore) {\n return lastPageParam + 1;\n }\n return undefined;\n}\n\n/** Deduplicates logs across loaded pages. Offset-based pagination duplicates rows at the page\n * boundary whenever new logs are inserted between sequential `fetchNextPage` calls — without\n * this filter the duplicates produce duplicate React keys and chaotic virtualizer offsets.\n * Falls back to the full serialized record when `logId` is absent so logs that happen to\n * share `(timestamp, message, data)` but differ in other fields aren't collapsed. */\nfunction selectLogs(data: { pages: ListLogsResponse[] }) {\n const seen = new Set<string>();\n const result = [];\n for (const page of data.pages) {\n for (const log of page.logs ?? []) {\n const key = log.logId ?? JSON.stringify(log);\n if (seen.has(key)) continue;\n seen.add(key);\n result.push(log);\n }\n }\n return result;\n}\n\nexport function getLogsRefetchInterval(query: { state: { error: unknown } }) {\n if (\n isUnsupportedObservabilityOperationError(query.state.error, 'logs') ||\n isObservabilityUnavailableError(query.state.error)\n ) {\n return false;\n }\n return LOGS_REFETCH_INTERVAL_MS;\n}\n\nexport const useLogs: (props?: LogsFilters) => UseLogsReturn = ({\n filters,\n orderBy = DEFAULT_LOGS_ORDER_BY,\n queryOptions,\n}: LogsFilters = {}) => {\n const client = useMastraClient();\n const { inView: isEndOfListInView, setRef: setEndOfListElement } = useInView();\n\n const query = useInfiniteQuery<ListLogsResponse, Error, ReturnType<typeof selectLogs>, readonly unknown[], number>({\n queryKey: ['logs', filters, orderBy],\n queryFn: ({ pageParam }) =>\n client.listLogsVNext({\n pagination: { page: pageParam, perPage: LOGS_PER_PAGE },\n filters,\n orderBy,\n }),\n initialPageParam: 0,\n getNextPageParam,\n select: selectLogs,\n retry: false,\n refetchInterval: getLogsRefetchInterval,\n ...queryOptions,\n });\n\n const { hasNextPage, isFetchingNextPage, fetchNextPage, data, isLoading, isError, error } = query;\n\n useEffect(() => {\n if (isEndOfListInView && hasNextPage && !isFetchingNextPage) {\n void fetchNextPage();\n }\n }, [isEndOfListInView, hasNextPage, isFetchingNextPage, fetchNextPage]);\n\n return { data, hasNextPage, isFetchingNextPage, fetchNextPage, isLoading, isError, error, setEndOfListElement };\n};\n"],"mappings":";;;;;;;AAwBA,MAAM,gBAAgB;AACtB,MAAM,2BAA2B;AAIjC,MAAM,wBAAqC;CAAE,OAAO;CAAa,WAAW;AAAO;AAcnF,SAAS,iBAAiB,UAAwC,WAAoB,eAAuB;CAC3G,IAAI,UAAU,YAAY,SACxB,OAAO,gBAAgB;AAG3B;;;;;;AAOA,SAAS,WAAW,MAAqC;CACvD,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,QAAQ,KAAK,OACtB,KAAK,MAAM,OAAO,KAAK,QAAQ,CAAC,GAAG;EACjC,MAAM,MAAM,IAAI,SAAS,KAAK,UAAU,GAAG;EAC3C,IAAI,KAAK,IAAI,GAAG,GAAG;EACnB,KAAK,IAAI,GAAG;EACZ,OAAO,KAAK,GAAG;CACjB;CAEF,OAAO;AACT;AAEA,SAAgB,uBAAuB,OAAsC;CAC3E,IACEA,oBAAAA,yCAAyC,MAAM,MAAM,OAAO,MAAM,KAClEC,oBAAAA,gCAAgC,MAAM,MAAM,KAAK,GAEjD,OAAO;CAET,OAAO;AACT;AAEA,MAAa,WAAmD,EAC9D,SACA,UAAU,uBACV,iBACe,CAAC,MAAM;CACtB,MAAM,SAASC,8BAAAA,gBAAgB;CAC/B,MAAM,EAAE,QAAQ,mBAAmB,QAAQ,wBAAwBC,oBAAAA,UAAU;CAkB7E,MAAM,EAAE,aAAa,oBAAoB,eAAe,MAAM,WAAW,SAAS,WAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isUnsupportedObservabilityOperationError","isObservabilityUnavailableError","useMastraClient","useInView","useInfiniteQuery"],"sources":["../../../src/hooks/logs/use-logs.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useInfiniteQuery } from '@tanstack/react-query';\nimport { useEffect } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport { isObservabilityUnavailableError, isUnsupportedObservabilityOperationError } from '../query/query-utils';\nimport type { MastraInfiniteQueryOptions } from '../shared/query-options';\n\nimport { useInView } from '../shared/use-in-view';\nimport type { LogRecord } from './types';\n\ntype ListLogsArgs = NonNullable<Parameters<MastraClient['listLogsVNext']>[0]>;\ntype ListLogsResponse = Awaited<ReturnType<MastraClient['listLogsVNext']>>;\n\ninterface UseLogsReturn {\n data: LogRecord[] | undefined;\n hasNextPage: boolean;\n isFetchingNextPage: boolean;\n fetchNextPage: () => void;\n isLoading: boolean;\n isError: boolean;\n error: Error | null;\n setEndOfListElement: (node: HTMLDivElement | null) => void;\n}\n\nconst LOGS_PER_PAGE = 20;\nconst LOGS_REFETCH_INTERVAL_MS = 10000;\n\nexport type LogsOrderBy = NonNullable<ListLogsArgs['orderBy']>;\n\nconst DEFAULT_LOGS_ORDER_BY: LogsOrderBy = { field: 'timestamp', direction: 'DESC' };\n\nexport interface LogsFilters {\n filters?: ListLogsArgs['filters'];\n orderBy?: LogsOrderBy;\n /** TanStack overrides spread last. The hook returns the selected log list, so `select` must keep that shape. */\n queryOptions?: MastraInfiniteQueryOptions<\n ListLogsResponse,\n ReturnType<typeof selectLogs>,\n readonly unknown[],\n number\n >;\n}\n\nfunction getNextPageParam(lastPage: ListLogsResponse | undefined, _allPages: unknown, lastPageParam: number) {\n if (lastPage?.pagination?.hasMore) {\n return lastPageParam + 1;\n }\n return undefined;\n}\n\n/** Deduplicates logs across loaded pages. Offset-based pagination duplicates rows at the page\n * boundary whenever new logs are inserted between sequential `fetchNextPage` calls — without\n * this filter the duplicates produce duplicate React keys and chaotic virtualizer offsets.\n * Falls back to the full serialized record when `logId` is absent so logs that happen to\n * share `(timestamp, message, data)` but differ in other fields aren't collapsed. */\nfunction selectLogs(data: { pages: ListLogsResponse[] }) {\n const seen = new Set<string>();\n const result = [];\n for (const page of data.pages) {\n for (const log of page.logs ?? []) {\n const key = log.logId ?? JSON.stringify(log);\n if (seen.has(key)) continue;\n seen.add(key);\n result.push(log);\n }\n }\n return result;\n}\n\nexport function getLogsRefetchInterval(query: { state: { error: unknown } }) {\n if (\n isUnsupportedObservabilityOperationError(query.state.error, 'logs') ||\n isObservabilityUnavailableError(query.state.error)\n ) {\n return false;\n }\n return LOGS_REFETCH_INTERVAL_MS;\n}\n\nexport const useLogs: (props?: LogsFilters) => UseLogsReturn = ({\n filters,\n orderBy = DEFAULT_LOGS_ORDER_BY,\n queryOptions,\n}: LogsFilters = {}) => {\n const client = useMastraClient();\n const { inView: isEndOfListInView, setRef: setEndOfListElement } = useInView();\n\n const query = useInfiniteQuery<ListLogsResponse, Error, ReturnType<typeof selectLogs>, readonly unknown[], number>({\n queryKey: ['logs', filters, orderBy],\n queryFn: ({ pageParam }) =>\n client.listLogsVNext({\n pagination: { page: pageParam, perPage: LOGS_PER_PAGE },\n filters,\n orderBy,\n }),\n initialPageParam: 0,\n getNextPageParam,\n select: selectLogs,\n retry: false,\n refetchInterval: getLogsRefetchInterval,\n ...queryOptions,\n });\n\n const { hasNextPage, isFetchingNextPage, fetchNextPage, data, isLoading, isError, error } = query;\n\n useEffect(() => {\n if (isEndOfListInView && hasNextPage && !isFetchingNextPage) {\n void fetchNextPage();\n }\n }, [isEndOfListInView, hasNextPage, isFetchingNextPage, fetchNextPage]);\n\n return { data, hasNextPage, isFetchingNextPage, fetchNextPage, isLoading, isError, error, setEndOfListElement };\n};\n"],"mappings":";;;;;;;AAwBA,MAAM,gBAAgB;AACtB,MAAM,2BAA2B;AAIjC,MAAM,wBAAqC;CAAE,OAAO;CAAa,WAAW;AAAO;AAcnF,SAAS,iBAAiB,UAAwC,WAAoB,eAAuB;CAC3G,IAAI,UAAU,YAAY,SACxB,OAAO,gBAAgB;AAG3B;;;;;;AAOA,SAAS,WAAW,MAAqC;CACvD,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,QAAQ,KAAK,OACtB,KAAK,MAAM,OAAO,KAAK,QAAQ,CAAC,GAAG;EACjC,MAAM,MAAM,IAAI,SAAS,KAAK,UAAU,GAAG;EAC3C,IAAI,KAAK,IAAI,GAAG,GAAG;EACnB,KAAK,IAAI,GAAG;EACZ,OAAO,KAAK,GAAG;CACjB;CAEF,OAAO;AACT;AAEA,SAAgB,uBAAuB,OAAsC;CAC3E,IACEA,oBAAAA,yCAAyC,MAAM,MAAM,OAAO,MAAM,KAClEC,oBAAAA,gCAAgC,MAAM,MAAM,KAAK,GAEjD,OAAO;CAET,OAAO;AACT;AAEA,MAAa,WAAmD,EAC9D,SACA,UAAU,uBACV,iBACe,CAAC,MAAM;CACtB,MAAM,SAASC,8BAAAA,gBAAgB;CAC/B,MAAM,EAAE,QAAQ,mBAAmB,QAAQ,wBAAwBC,oBAAAA,UAAU;CAkB7E,MAAM,EAAE,aAAa,oBAAoB,eAAe,MAAM,WAAW,SAAS,WAAA,GAhBpEC,sBAAAA,iBAAAA,CAAqG;EACjH,UAAU;GAAC;GAAQ;GAAS;EAAO;EACnC,UAAU,EAAE,gBACV,OAAO,cAAc;GACnB,YAAY;IAAE,MAAM;IAAW,SAAS;GAAc;GACtD;GACA;EACF,CAAC;EACH,kBAAkB;EAClB;EACA,QAAQ;EACR,OAAO;EACP,iBAAiB;EACjB,GAAG;CACL,CAEgG;CAEhG,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,IAAI,qBAAqB,eAAe,CAAC,oBACvC,cAAmB;CAEvB,GAAG;EAAC;EAAmB;EAAa;EAAoB;CAAa,CAAC;CAEtE,OAAO;EAAE;EAAM;EAAa;EAAoB;EAAe;EAAW;EAAS;EAAO;CAAoB;AAChH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMastraClient","useMastraClient","useMastraClient","useMastraClient","useMastraClient","useMastraClient","useMastraClient"],"sources":["../../../src/hooks/mcps/use-mcp-app-html.ts","../../../src/hooks/mcps/use-mcp-app-tools.ts","../../../src/hooks/mcps/use-mcp-server-tool.ts","../../../src/hooks/mcps/use-mcp-server-tools.ts","../../../src/hooks/mcps/use-mcp-server-tools-by-id.ts","../../../src/hooks/mcps/use-mcp-servers.ts","../../../src/hooks/mcps/use-try-connect-mcp.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useQuery } from '@tanstack/react-query';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\n/** The app HTML, or `null` when the resource has no text. */\ntype McpAppHtml = string | null;\n\nexport type ReadMcpServerResourceResponse = Awaited<ReturnType<MastraClient['readMcpServerResource']>>;\n\n/**\n * The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.\n * Skips the fetch when the tool has no app resource.\n */\nexport const useMcpAppHtml = <TData = McpAppHtml>({\n serverId,\n appResourceUri,\n queryOptions,\n}: {\n serverId: string;\n appResourceUri?: string;\n queryOptions?: MastraQueryOptions<McpAppHtml, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-resource', serverId, appResourceUri],\n queryFn: async () => {\n if (!appResourceUri) return null;\n const response = await client.readMcpServerResource(serverId, appResourceUri);\n return response.contents[0]?.text ?? null;\n },\n enabled: appResourceUri !== undefined,\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';\n\nexport interface McpAppToolInfo {\n serverId: string;\n toolId: string;\n toolName: string;\n resourceUri: string;\n}\n\n/**\n * Builds a map of tool names → MCP App info for tools across all registered\n * MCP servers that have `_meta.ui.resourceUri` (i.e., tools with interactive\n * MCP App UIs).\n *\n * For each app tool, entries are created under both the original tool name\n * and the namespaced name (`${serverId}_${toolName}`) so that agent tools\n * sourced via `MCPClient.listTools()` (which namespaces) can be resolved.\n */\nexport function useMcpAppTools<TData = Record<string, McpAppToolInfo>>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<Record<string, McpAppToolInfo>, TData> } = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-tools'],\n queryFn: async () => {\n const map: Record<string, McpAppToolInfo> = {};\n\n const { servers } = await client.getMcpServers();\n if (!servers?.length) return map;\n\n const results = await Promise.allSettled(\n servers.map(async server => {\n const { tools } = await client.getMcpServerTools(server.id);\n return { serverId: server.id, tools };\n }),\n );\n\n for (const result of results) {\n if (result.status !== 'fulfilled') continue;\n const { serverId, tools } = result.value;\n for (const tool of tools) {\n const meta = tool._meta as { ui?: { resourceUri?: string } } | undefined;\n const resourceUri = meta?.ui?.resourceUri;\n if (resourceUri) {\n const toolId = tool.name;\n const info: McpAppToolInfo = { serverId, toolId, toolName: tool.name, resourceUri };\n map[toolId] = info;\n if (tool.name !== toolId) {\n map[tool.name] = info;\n }\n // Also map the namespaced name used by MCPClient.listTools()\n map[`${serverId}_${tool.name}`] = info;\n }\n }\n }\n\n return map;\n },\n staleTime: 60_000,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolDetails = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['details']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerTool = <TData = MCPServerToolDetails>({\n serverId,\n toolId,\n requestContext,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MCPServerToolDetails, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-server-tool', serverId, toolId],\n queryFn: () => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.details(requestContext);\n },\n ...queryOptions,\n });\n};\n\nexport type ExecuteMCPToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['execute']>>;\ntype ExecuteMCPToolVariables = { data: any; requestContext?: Record<string, any> };\n\nexport const useExecuteMCPTool = ({\n serverId,\n toolId,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n queryOptions?: MastraMutationOptions<ExecuteMCPToolResponse, ExecuteMCPToolVariables>;\n}): UseMutationResult<ExecuteMCPToolResponse, Error, ExecuteMCPToolVariables> => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: ({ data, requestContext }: ExecuteMCPToolVariables) => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.execute({ data, requestContext: requestContext as RequestContext });\n },\n ...queryOptions,\n });\n};\n","import type { McpToolInfo as SdkMcpToolInfo } from '@mastra/client-js';\nimport type { ServerInfo } from '@mastra/core/mcp';\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\nexport const useMCPServerTools = <TData = Record<string, SdkMcpToolInfo>>({\n selectedServer,\n queryOptions,\n}: {\n selectedServer: ServerInfo;\n queryOptions?: MastraQueryOptions<Record<string, SdkMcpToolInfo>, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', selectedServer?.id],\n queryFn: async () => {\n const response = await client.getMcpServerTools(selectedServer?.id);\n const fetchedToolsArray: SdkMcpToolInfo[] = response.tools;\n const transformedTools: Record<string, SdkMcpToolInfo> = {};\n fetchedToolsArray.forEach((sdkToolInfo: SdkMcpToolInfo) => {\n transformedTools[sdkToolInfo.name] = sdkToolInfo;\n });\n\n return transformedTools;\n },\n retry: false,\n refetchOnWindowFocus: false,\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';\n\ntype MCPServerToolsById = Record<string, Awaited<ReturnType<MastraClient['getMcpServerTools']>>['tools'][number]>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerToolsById = <TData = MCPServerToolsById>({\n serverId,\n queryOptions,\n}: {\n serverId: string | null;\n queryOptions?: MastraQueryOptions<MCPServerToolsById, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', serverId],\n queryFn: async (): Promise<MCPServerToolsById> => {\n const response = await client.getMcpServerTools(serverId!);\n return Object.fromEntries(response.tools.map(tool => [tool.name, tool]));\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { McpServerListResponse } 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\nexport const useMCPServers = <TData = McpServerListResponse['servers']>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<McpServerListResponse['servers'], TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-servers'],\n queryFn: async () => {\n const mcpServers: McpServerListResponse['servers'] = (await client.getMcpServers(requestContext)).servers;\n return mcpServers;\n },\n ...queryOptions,\n });\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n}\n\nexport interface TryConnectResult {\n tools: McpTool[];\n}\n\nasync function parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get('content-type') ?? '';\n\n if (contentType.includes('text/event-stream')) {\n const text = await response.text();\n const lines = text.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('data:')) {\n const data = line.slice('data:'.length).trim();\n if (data) {\n return JSON.parse(data);\n }\n }\n }\n\n throw new Error('No data found in SSE response');\n }\n\n return response.json();\n}\n\nasync function connectAndListTools(url: string, clientHeaders?: Record<string, string>): Promise<TryConnectResult> {\n const baseHeaders: Record<string, string> = {\n ...clientHeaders,\n 'Content-Type': 'application/json',\n Accept: 'application/json, text/event-stream',\n };\n\n // Step 1: Initialize\n const initResponse = await fetch(url, {\n method: 'POST',\n headers: baseHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: {\n protocolVersion: '2025-03-26',\n capabilities: {},\n clientInfo: { name: 'mastra-playground', version: '1.0.0' },\n },\n }),\n });\n\n if (!initResponse.ok) {\n throw new Error(`Initialize failed: ${initResponse.status} ${initResponse.statusText}`);\n }\n\n const sessionId = initResponse.headers.get('Mcp-Session-Id');\n await parseResponse(initResponse);\n\n const sessionHeaders: Record<string, string> = {\n ...baseHeaders,\n };\n if (sessionId) {\n sessionHeaders['Mcp-Session-Id'] = sessionId;\n }\n\n // Step 2: Send initialized notification\n await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n method: 'notifications/initialized',\n }),\n });\n\n // Step 3: List tools\n const toolsResponse = await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 2,\n method: 'tools/list',\n }),\n });\n\n if (!toolsResponse.ok) {\n throw new Error(`tools/list failed: ${toolsResponse.status} ${toolsResponse.statusText}`);\n }\n\n const toolsResult = (await parseResponse(toolsResponse)) as { result?: { tools?: McpTool[] } };\n\n return {\n tools: toolsResult.result?.tools ?? [],\n };\n}\n\nexport const useTryConnectMcp = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<TryConnectResult, string> } = {}) => {\n const client = useMastraClient();\n const clientHeaders = (client.options?.headers as Record<string, string>) ?? {};\n\n return useMutation({\n mutationFn: (url: string) => connectAndListTools(url, clientHeaders),\n ...queryOptions,\n });\n};\n\nexport type TryConnectMcpMutation = ReturnType<typeof useTryConnectMcp>;\n"],"mappings":";;;;;;;;AAeA,MAAa,iBAAqC,EAChD,UACA,gBACA,mBAKkC;CAClC,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAA,sBAAA,SAAA,CAAgB;EACd,UAAU;GAAC;GAAoB;GAAU;EAAc;EACvD,SAAS,YAAY;GACnB,IAAI,CAAC,gBAAgB,OAAO;GAE5B,QAAO,MADgB,OAAO,sBAAsB,UAAU,cAAc,EAAA,CA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GD,MAAM,gBAAgB,MAAM,MAAM,KAAK;EACrC,QAAQ;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,IAAI;GACJ,QAAQ;EACV,CAAC;CACH,CAAC;CAED,IAAI,CAAC,cAAc,IACjB,MAAM,IAAI,MAAM,sBAAsB,cAAc,OAAO,GAAG,cAAc,YAAY;CAK1F,OAAO,EACL,QAAO,MAHkB,cAAc,aAAa,EAAA,CAGjC,QAAQ,SAAS,CAAC,EACvC;AACF;AAEA,MAAa,oBAAoB,EAC/B,iBACsE,CAAC,MAAM;CAE7E,MAAM,gBADSC,8BAAAA,gBACa,CAAC,CAAC,SAAS,WAAsC,CAAC;CAE9E,QAAA,GAAA,sBAAA,YAAA,CAAmB;EACjB,aAAa,QAAgB,oBAAoB,KAAK,aAAa;EACnE,GAAG;CACL,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMastraClient","useQuery","useMastraClient","useQuery","useMastraClient","useQuery","useMutation","useMastraClient","useQuery","useMastraClient","useQuery","useMastraClient","useQuery","useMastraClient","useMutation"],"sources":["../../../src/hooks/mcps/use-mcp-app-html.ts","../../../src/hooks/mcps/use-mcp-app-tools.ts","../../../src/hooks/mcps/use-mcp-server-tool.ts","../../../src/hooks/mcps/use-mcp-server-tools.ts","../../../src/hooks/mcps/use-mcp-server-tools-by-id.ts","../../../src/hooks/mcps/use-mcp-servers.ts","../../../src/hooks/mcps/use-try-connect-mcp.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport { useQuery } from '@tanstack/react-query';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\n/** The app HTML, or `null` when the resource has no text. */\ntype McpAppHtml = string | null;\n\nexport type ReadMcpServerResourceResponse = Awaited<ReturnType<MastraClient['readMcpServerResource']>>;\n\n/**\n * The HTML of an MCP tool's `ui://` app resource (from the tool's `_meta`), for rendering the tool's own UI.\n * Skips the fetch when the tool has no app resource.\n */\nexport const useMcpAppHtml = <TData = McpAppHtml>({\n serverId,\n appResourceUri,\n queryOptions,\n}: {\n serverId: string;\n appResourceUri?: string;\n queryOptions?: MastraQueryOptions<McpAppHtml, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-resource', serverId, appResourceUri],\n queryFn: async () => {\n if (!appResourceUri) return null;\n const response = await client.readMcpServerResource(serverId, appResourceUri);\n return response.contents[0]?.text ?? null;\n },\n enabled: appResourceUri !== undefined,\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';\n\nexport interface McpAppToolInfo {\n serverId: string;\n toolId: string;\n toolName: string;\n resourceUri: string;\n}\n\n/**\n * Builds a map of tool names → MCP App info for tools across all registered\n * MCP servers that have `_meta.ui.resourceUri` (i.e., tools with interactive\n * MCP App UIs).\n *\n * For each app tool, entries are created under both the original tool name\n * and the namespaced name (`${serverId}_${toolName}`) so that agent tools\n * sourced via `MCPClient.listTools()` (which namespaces) can be resolved.\n */\nexport function useMcpAppTools<TData = Record<string, McpAppToolInfo>>({\n queryOptions,\n}: { queryOptions?: MastraQueryOptions<Record<string, McpAppToolInfo>, TData> } = {}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-app-tools'],\n queryFn: async () => {\n const map: Record<string, McpAppToolInfo> = {};\n\n const { servers } = await client.getMcpServers();\n if (!servers?.length) return map;\n\n const results = await Promise.allSettled(\n servers.map(async server => {\n const { tools } = await client.getMcpServerTools(server.id);\n return { serverId: server.id, tools };\n }),\n );\n\n for (const result of results) {\n if (result.status !== 'fulfilled') continue;\n const { serverId, tools } = result.value;\n for (const tool of tools) {\n const meta = tool._meta as { ui?: { resourceUri?: string } } | undefined;\n const resourceUri = meta?.ui?.resourceUri;\n if (resourceUri) {\n const toolId = tool.name;\n const info: McpAppToolInfo = { serverId, toolId, toolName: tool.name, resourceUri };\n map[toolId] = info;\n if (tool.name !== toolId) {\n map[tool.name] = info;\n }\n // Also map the namespaced name used by MCPClient.listTools()\n map[`${serverId}_${tool.name}`] = info;\n }\n }\n }\n\n return map;\n },\n staleTime: 60_000,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\ntype MCPServerToolDetails = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['details']>>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerTool = <TData = MCPServerToolDetails>({\n serverId,\n toolId,\n requestContext,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MCPServerToolDetails, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-server-tool', serverId, toolId],\n queryFn: () => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.details(requestContext);\n },\n ...queryOptions,\n });\n};\n\nexport type ExecuteMCPToolResponse = Awaited<ReturnType<ReturnType<MastraClient['getMcpServerTool']>['execute']>>;\ntype ExecuteMCPToolVariables = { data: any; requestContext?: Record<string, any> };\n\nexport const useExecuteMCPTool = ({\n serverId,\n toolId,\n queryOptions,\n}: {\n serverId: string;\n toolId: string;\n queryOptions?: MastraMutationOptions<ExecuteMCPToolResponse, ExecuteMCPToolVariables>;\n}): UseMutationResult<ExecuteMCPToolResponse, Error, ExecuteMCPToolVariables> => {\n const client = useMastraClient();\n\n return useMutation({\n mutationFn: ({ data, requestContext }: ExecuteMCPToolVariables) => {\n const instance = client.getMcpServerTool(serverId, toolId);\n return instance.execute({ data, requestContext: requestContext as RequestContext });\n },\n ...queryOptions,\n });\n};\n","import type { McpToolInfo as SdkMcpToolInfo } from '@mastra/client-js';\nimport type { ServerInfo } from '@mastra/core/mcp';\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\nexport const useMCPServerTools = <TData = Record<string, SdkMcpToolInfo>>({\n selectedServer,\n queryOptions,\n}: {\n selectedServer: ServerInfo;\n queryOptions?: MastraQueryOptions<Record<string, SdkMcpToolInfo>, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', selectedServer?.id],\n queryFn: async () => {\n const response = await client.getMcpServerTools(selectedServer?.id);\n const fetchedToolsArray: SdkMcpToolInfo[] = response.tools;\n const transformedTools: Record<string, SdkMcpToolInfo> = {};\n fetchedToolsArray.forEach((sdkToolInfo: SdkMcpToolInfo) => {\n transformedTools[sdkToolInfo.name] = sdkToolInfo;\n });\n\n return transformedTools;\n },\n retry: false,\n refetchOnWindowFocus: false,\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';\n\ntype MCPServerToolsById = Record<string, Awaited<ReturnType<MastraClient['getMcpServerTools']>>['tools'][number]>;\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMCPServerToolsById = <TData = MCPServerToolsById>({\n serverId,\n queryOptions,\n}: {\n serverId: string | null;\n queryOptions?: MastraQueryOptions<MCPServerToolsById, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcpserver-tools', serverId],\n queryFn: async (): Promise<MCPServerToolsById> => {\n const response = await client.getMcpServerTools(serverId!);\n return Object.fromEntries(response.tools.map(tool => [tool.name, tool]));\n },\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n","import type { McpServerListResponse } 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\nexport const useMCPServers = <TData = McpServerListResponse['servers']>({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<McpServerListResponse['servers'], TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['mcp-servers'],\n queryFn: async () => {\n const mcpServers: McpServerListResponse['servers'] = (await client.getMcpServers(requestContext)).servers;\n return mcpServers;\n },\n ...queryOptions,\n });\n};\n","import { useMutation } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions } from '../shared/query-options';\n\ninterface McpTool {\n name: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n}\n\nexport interface TryConnectResult {\n tools: McpTool[];\n}\n\nasync function parseResponse(response: Response): Promise<unknown> {\n const contentType = response.headers.get('content-type') ?? '';\n\n if (contentType.includes('text/event-stream')) {\n const text = await response.text();\n const lines = text.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('data:')) {\n const data = line.slice('data:'.length).trim();\n if (data) {\n return JSON.parse(data);\n }\n }\n }\n\n throw new Error('No data found in SSE response');\n }\n\n return response.json();\n}\n\nasync function connectAndListTools(url: string, clientHeaders?: Record<string, string>): Promise<TryConnectResult> {\n const baseHeaders: Record<string, string> = {\n ...clientHeaders,\n 'Content-Type': 'application/json',\n Accept: 'application/json, text/event-stream',\n };\n\n // Step 1: Initialize\n const initResponse = await fetch(url, {\n method: 'POST',\n headers: baseHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'initialize',\n params: {\n protocolVersion: '2025-03-26',\n capabilities: {},\n clientInfo: { name: 'mastra-playground', version: '1.0.0' },\n },\n }),\n });\n\n if (!initResponse.ok) {\n throw new Error(`Initialize failed: ${initResponse.status} ${initResponse.statusText}`);\n }\n\n const sessionId = initResponse.headers.get('Mcp-Session-Id');\n await parseResponse(initResponse);\n\n const sessionHeaders: Record<string, string> = {\n ...baseHeaders,\n };\n if (sessionId) {\n sessionHeaders['Mcp-Session-Id'] = sessionId;\n }\n\n // Step 2: Send initialized notification\n await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n method: 'notifications/initialized',\n }),\n });\n\n // Step 3: List tools\n const toolsResponse = await fetch(url, {\n method: 'POST',\n headers: sessionHeaders,\n credentials: 'include',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 2,\n method: 'tools/list',\n }),\n });\n\n if (!toolsResponse.ok) {\n throw new Error(`tools/list failed: ${toolsResponse.status} ${toolsResponse.statusText}`);\n }\n\n const toolsResult = (await parseResponse(toolsResponse)) as { result?: { tools?: McpTool[] } };\n\n return {\n tools: toolsResult.result?.tools ?? [],\n };\n}\n\nexport const useTryConnectMcp = ({\n queryOptions,\n}: { queryOptions?: MastraMutationOptions<TryConnectResult, string> } = {}) => {\n const client = useMastraClient();\n const clientHeaders = (client.options?.headers as Record<string, string>) ?? {};\n\n return useMutation({\n mutationFn: (url: string) => connectAndListTools(url, clientHeaders),\n ...queryOptions,\n });\n};\n\nexport type TryConnectMcpMutation = ReturnType<typeof useTryConnectMcp>;\n"],"mappings":";;;;;;;;AAeA,MAAa,iBAAqC,EAChD,UACA,gBACA,mBAKkC;CAClC,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,S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G,YACL;CACA,IAAI,WACF,eAAe,oBAAoB;CAIrC,MAAM,MAAM,KAAK;EACf,QAAQ;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,QAAQ;EACV,CAAC;CACH,CAAC;CAGD,MAAM,gBAAgB,MAAM,MAAM,KAAK;EACrC,QAAQ;EACR,SAAS;EACT,aAAa;EACb,MAAM,KAAK,UAAU;GACnB,SAAS;GACT,IAAI;GACJ,QAAQ;EACV,CAAC;CACH,CAAC;CAED,IAAI,CAAC,cAAc,IACjB,MAAM,IAAI,MAAM,sBAAsB,cAAc,OAAO,GAAG,cAAc,YAAY;CAK1F,OAAO,EACL,QAAO,MAHkB,cAAc,aAAa,EAAA,CAGjC,QAAQ,SAAS,CAAC,EACvC;AACF;AAEA,MAAa,oBAAoB,EAC/B,iBACsE,CAAC,MAAM;CAE7E,MAAM,gBADSC,8BAAAA,gBACa,CAAC,CAAC,SAAS,WAAsC,CAAC;CAE9E,QAAA,GAAOC,sBAAAA,YAAAA,CAAY;EACjB,aAAa,QAAgB,oBAAoB,KAAK,aAAa;EACnE,GAAG;CACL,CAAC;AACH"}
|
|
@@ -72,8 +72,8 @@ const useMemory = ({ agentId, requestContext, queryOptions } = {}) => {
|
|
|
72
72
|
requestContext
|
|
73
73
|
],
|
|
74
74
|
queryFn: () => agentId ? client.getMemoryStatus(agentId, requestContext) : null,
|
|
75
|
-
staleTime:
|
|
76
|
-
gcTime:
|
|
75
|
+
staleTime: 3e5,
|
|
76
|
+
gcTime: 6e5,
|
|
77
77
|
retry: false,
|
|
78
78
|
...queryOptions
|
|
79
79
|
});
|
|
@@ -94,8 +94,8 @@ const useMemoryConfig = ({ agentId, requestContext, queryOptions } = {}) => {
|
|
|
94
94
|
agentId,
|
|
95
95
|
requestContext
|
|
96
96
|
}) : null,
|
|
97
|
-
staleTime:
|
|
98
|
-
gcTime:
|
|
97
|
+
staleTime: 3e5,
|
|
98
|
+
gcTime: 6e5,
|
|
99
99
|
retry: false,
|
|
100
100
|
refetchOnWindowFocus: false,
|
|
101
101
|
...queryOptions
|
|
@@ -118,8 +118,8 @@ const useThread = ({ threadId, agentId, requestContext, queryOptions }) => {
|
|
|
118
118
|
threadId,
|
|
119
119
|
agentId
|
|
120
120
|
}).get({ requestContext }),
|
|
121
|
-
staleTime:
|
|
122
|
-
gcTime:
|
|
121
|
+
staleTime: 3e5,
|
|
122
|
+
gcTime: 6e5,
|
|
123
123
|
retry: false,
|
|
124
124
|
refetchOnWindowFocus: false,
|
|
125
125
|
...queryOptions
|
|
@@ -261,8 +261,8 @@ const useObservationalMemoryWithHistory = ({ agentId, resourceId, threadId, isAc
|
|
|
261
261
|
requestContext
|
|
262
262
|
});
|
|
263
263
|
},
|
|
264
|
-
staleTime: isActive ? 1e3 :
|
|
265
|
-
gcTime:
|
|
264
|
+
staleTime: isActive ? 1e3 : 3e4,
|
|
265
|
+
gcTime: 3e5,
|
|
266
266
|
retry: false,
|
|
267
267
|
refetchOnWindowFocus: false,
|
|
268
268
|
refetchInterval: isActive ? 2e3 : false,
|
|
@@ -292,8 +292,8 @@ const useMemoryWithOMStatus = ({ agentId, resourceId, threadId, pollWhenActive =
|
|
|
292
292
|
resourceId,
|
|
293
293
|
threadId
|
|
294
294
|
}) : null,
|
|
295
|
-
staleTime: isActive && pollWhenActive ? 1e3 :
|
|
296
|
-
gcTime:
|
|
295
|
+
staleTime: isActive && pollWhenActive ? 1e3 : 3e4,
|
|
296
|
+
gcTime: 3e5,
|
|
297
297
|
retry: false,
|
|
298
298
|
refetchOnWindowFocus: false,
|
|
299
299
|
refetchInterval: isActive && pollWhenActive ? 2e3 : false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMastraClient","skipToken","useMastraClient","skipToken","useMastraClient","skipToken","useMastraClient"],"sources":["../../../src/hooks/memory/use-memory-thread-messages.ts","../../../src/hooks/memory/use-observational-memory.ts","../../../src/hooks/memory/use-memory-status.ts","../../../src/hooks/memory/use-memory.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryThreadMessagesQueryKey = (threadId: string | undefined, page?: number) =>\n ['memory', 'thread', threadId, 'messages', page ?? 0] as const;\n\ntype MemoryThreadMessagesResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['listMessages']>>;\n\nexport function useMemoryThreadMessages<TData = MemoryThreadMessagesResponse>({\n threadId,\n page = 0,\n perPage = 100,\n queryOptions,\n}: {\n threadId: string | undefined;\n page?: number;\n perPage?: number;\n queryOptions?: MastraQueryOptions<MemoryThreadMessagesResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryThreadMessagesQueryKey(threadId, page),\n queryFn: threadId ? () => client.getMemoryThread({ threadId }).listMessages({ page, perPage }) : skipToken,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const observationalMemoryQueryKey = (agentId: string | undefined, threadId: string | undefined) =>\n ['memory', 'observational-memory', agentId, threadId] as const;\n\ntype ObservationalMemoryResponse = Awaited<ReturnType<MastraClient['getObservationalMemory']>>;\n\nexport function useObservationalMemory<TData = ObservationalMemoryResponse>({\n agentId,\n threadId,\n resourceId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId: string | undefined;\n resourceId?: string;\n queryOptions?: MastraQueryOptions<ObservationalMemoryResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: observationalMemoryQueryKey(agentId, threadId),\n queryFn:\n agentId && threadId\n ? () =>\n client.getObservationalMemory({\n agentId,\n threadId,\n resourceId,\n })\n : skipToken,\n // The record is read by several surfaces at once (collapsed memory bar, OM\n // section, detail panel). A short stale window lets a newly mounted consumer\n // reuse the cached record instead of refiring the request; freshness still\n // comes from the explicit refetch on stream finish/observation signals.\n staleTime: 5_000,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryStatusQueryKey = (agentId: string | undefined, threadId?: string) =>\n ['memory', 'status', agentId, threadId] as const;\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>>;\n\nexport function useMemoryStatus<TData = MemoryStatusResponse>({\n agentId,\n threadId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId?: string;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryStatusQueryKey(agentId, threadId),\n queryFn: agentId\n ? () =>\n client.getMemoryStatus(agentId, undefined, {\n threadId,\n })\n : skipToken,\n ...queryOptions,\n });\n}\n","import type { GetObservationalMemoryResponse, GetMemoryStatusResponse, MastraClient } from '@mastra/client-js';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useState, useEffect } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport interface MemorySearchParams {\n lastMessages?: number | false;\n}\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>> | null;\ntype MemoryConfigResponse = Awaited<ReturnType<MastraClient['getMemoryConfig']>> | null;\ntype ThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['get']>>;\ntype ThreadsResponse = Awaited<ReturnType<MastraClient['listMemoryThreads']>>['threads'] | null;\ntype UpdateThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['update']>>;\ntype CloneThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['clone']>>;\ntype SearchMemoryResponse = Awaited<ReturnType<MastraClient['searchMemory']>>;\ntype ThreadVariables = { threadId: string; agentId: string };\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemory = <TData = MemoryStatusResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryStatus(agentId, requestContext) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryConfig = <TData = MemoryConfigResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryConfigResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'config', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryConfig({ agentId, requestContext }) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThread = <TData = ThreadResponse>({\n threadId,\n agentId,\n requestContext,\n queryOptions,\n}: {\n threadId?: string;\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'thread', threadId, agentId, requestContext],\n queryFn: () => client.getMemoryThread({ threadId: threadId!, agentId }).get({ requestContext }),\n staleTime: 5 * 60 * 1000,\n gcTime: 10 * 60 * 1000,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThreads = <TData = ThreadsResponse>({\n resourceId,\n agentId,\n isMemoryEnabled,\n requestContext,\n queryOptions,\n}: {\n resourceId: string;\n agentId: string;\n isMemoryEnabled: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'threads', resourceId, agentId, requestContext],\n queryFn: async () => {\n if (!isMemoryEnabled) return null;\n const result = await client.listMemoryThreads({ resourceId, agentId, requestContext });\n return result.threads;\n },\n staleTime: 0,\n gcTime: 0,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\nexport type DeleteThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['delete']>>;\n\nexport const useDeleteThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<DeleteThreadResponse, ThreadVariables>;\n} = {}): UseMutationResult<DeleteThreadResponse, Error, ThreadVariables> => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId }: { threadId: string; agentId: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.delete({ requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\nexport const useUpdateThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<UpdateThreadResponse, ThreadVariables & { title: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId, title }: { threadId: string; agentId: string; title: string }) =>\n client.getMemoryThread({ threadId, agentId }).update({ title, agentId, requestContext }),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads'] });\n void queryClient.invalidateQueries({ queryKey: ['memory', 'thread'] });\n },\n ...queryOptions,\n });\n};\n\nexport const useMemorySearch = ({\n agentId,\n resourceId,\n threadId,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId: string;\n threadId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<\n SearchMemoryResponse,\n { searchQuery: string; memoryConfig?: MemorySearchParams }\n >;\n}) => {\n const client = useMastraClient();\n return useMutation({\n mutationFn: async ({ searchQuery, memoryConfig }: { searchQuery: string; memoryConfig?: MemorySearchParams }) => {\n return client.searchMemory({ agentId, resourceId, threadId, searchQuery, memoryConfig, requestContext });\n },\n ...queryOptions,\n });\n};\n\nexport const useCloneThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<CloneThreadResponse, ThreadVariables & { title?: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ threadId, agentId, title }: { threadId: string; agentId: string; title?: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.clone({ title, requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to fetch Observational Memory data for an agent\n * Returns the current OM record and history for a given resource/thread\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useObservationalMemoryWithHistory = <TData = GetObservationalMemoryResponse | null>({\n agentId,\n resourceId,\n threadId,\n isActive = false,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId?: string;\n threadId?: string;\n isActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetObservationalMemoryResponse | null, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observational-memory', agentId, resourceId, threadId, requestContext],\n queryFn: async (): Promise<GetObservationalMemoryResponse | null> => {\n if (!resourceId && !threadId) return null;\n return client.getObservationalMemory({\n agentId,\n resourceId,\n threadId,\n requestContext,\n });\n },\n staleTime: isActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n};\n\n/**\n * Hook to get OM-aware memory status\n * Extends useMemory with OM-specific status information\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryWithOMStatus = ({\n agentId,\n resourceId,\n threadId,\n pollWhenActive = true,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n resourceId?: string;\n threadId?: string;\n pollWhenActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetMemoryStatusResponse | null>;\n}) => {\n const client = useMastraClient();\n const [isActive, setIsActive] = useState(false);\n\n const query = useQuery<GetMemoryStatusResponse | null>({\n queryKey: ['memory-status', agentId, resourceId, threadId, requestContext],\n queryFn: () =>\n agentId\n ? client.getMemoryStatus(agentId, requestContext, {\n resourceId,\n threadId,\n })\n : null,\n staleTime: isActive && pollWhenActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive && pollWhenActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n\n // Update isActive state when data changes\n const isObserving = query.data?.observationalMemory?.isObserving;\n const isReflecting = query.data?.observationalMemory?.isReflecting;\n\n useEffect(() => {\n const newIsActive = isObserving || isReflecting || false;\n setIsActive(newIsActive);\n }, [isObserving, isReflecting]);\n\n return query;\n};\n"],"mappings":";;;;;AAMA,MAAa,gCAAgC,UAA8B,SACzE;CAAC;CAAU;CAAU;CAAU;CAAY,QAAQ;AAAC;AAItD,SAAgB,wBAA8D,EAC5E,UACA,OAAO,GACP,UAAU,KACV,gBAM+B;CAC/B,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAA,sBAAA,SAAA,CAAgB;EACd,UAAU,6BAA6B,UAAU,IAAI;EACrD,SAAS,iBAAiB,OAAO,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa;GAAE;GAAM;EAAQ,CAAC,IAAIC,sBAAAA;EACjG,GAAG;CACL,CAAC;AACH;;;ACvBA,MAAa,+BAA+B,SAA6B,aACvE;CAAC;CAAU;CAAwB;CAAS;AAAQ;AAItD,SAAgB,uBAA4D,EAC1E,SACA,UACA,YACA,gBAM+B;CAC/B,MAAM,SAASC,8BAAAA,gBAAgB;CAE/B,QAAA,GAAA,sBAAA,SAAA,CAAgB;EACd,UAAU,4BAA4B,SAAS,QAAQ;EACvD,SACE,WAAW,iBAEL,OAAO,uBAAuB;GAC5B;GACA;GACA;EACF,CAAC,IACHC,sBAAAA;EAKN,WAAW;EACX,GAAG;CACL,CAAC;AACH;;;ACpCA,MAAa,wBAAwB,SAA6B,aAChE;CAAC;CAAU;C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W,MAAO,KAAK;EAClC,QAAQ,MAAS;EACjB,OAAO;EACP,sBAAsB;EACtB,iBAAiB,WAAW,MAAO;EACnC,kBAAiB,iBAAgB;EACjC,GAAG;CACL,CAAC;AACH;;;;;;;;AASA,MAAa,yBAAyB,EACpC,SACA,YACA,UACA,iBAAiB,MACjB,gBACA,mBAQI;CACJ,MAAM,SAASA,8BAAAA,gBAAgB;CAC/B,MAAM,CAAC,UAAU,gBAAA,GAAA,MAAA,SAAA,CAAwB,KAAK;CAE9C,MAAM,SAAA,GAAA,sBAAA,SAAA,CAAiD;EACrD,UAAU;GAAC;GAAiB;GAAS;GAAY;GAAU;EAAc;EACzE,eACE,UACI,OAAO,gBAAgB,SAAS,gBAAgB;GAC9C;GACA;EACF,CAAC,IACD;EACN,WAAW,YAAY,iBAAiB,MAAO,KAAK;EACpD,QAAQ,MAAS;EACjB,OAAO;EACP,sBAAsB;EACtB,iBAAiB,YAAY,iBAAiB,MAAO;EACrD,kBAAiB,iBAAgB;EACjC,GAAG;CACL,CAAC;CAGD,MAAM,cAAc,MAAM,MAAM,qBAAqB;CACrD,MAAM,eAAe,MAAM,MAAM,qBAAqB;CAEtD,CAAA,GAAA,MAAA,UAAA,OAAgB;EAEd,YADoB,eAAe,gBAAgB,KAC5B;CACzB,GAAG,CAAC,aAAa,YAAY,CAAC;CAE9B,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMastraClient","useQuery","skipToken","useMastraClient","useQuery","skipToken","useMastraClient","useQuery","skipToken","useMastraClient","useQuery","useQueryClient","useMutation","useState"],"sources":["../../../src/hooks/memory/use-memory-thread-messages.ts","../../../src/hooks/memory/use-observational-memory.ts","../../../src/hooks/memory/use-memory-status.ts","../../../src/hooks/memory/use-memory.ts"],"sourcesContent":["import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryThreadMessagesQueryKey = (threadId: string | undefined, page?: number) =>\n ['memory', 'thread', threadId, 'messages', page ?? 0] as const;\n\ntype MemoryThreadMessagesResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['listMessages']>>;\n\nexport function useMemoryThreadMessages<TData = MemoryThreadMessagesResponse>({\n threadId,\n page = 0,\n perPage = 100,\n queryOptions,\n}: {\n threadId: string | undefined;\n page?: number;\n perPage?: number;\n queryOptions?: MastraQueryOptions<MemoryThreadMessagesResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryThreadMessagesQueryKey(threadId, page),\n queryFn: threadId ? () => client.getMemoryThread({ threadId }).listMessages({ page, perPage }) : skipToken,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const observationalMemoryQueryKey = (agentId: string | undefined, threadId: string | undefined) =>\n ['memory', 'observational-memory', agentId, threadId] as const;\n\ntype ObservationalMemoryResponse = Awaited<ReturnType<MastraClient['getObservationalMemory']>>;\n\nexport function useObservationalMemory<TData = ObservationalMemoryResponse>({\n agentId,\n threadId,\n resourceId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId: string | undefined;\n resourceId?: string;\n queryOptions?: MastraQueryOptions<ObservationalMemoryResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: observationalMemoryQueryKey(agentId, threadId),\n queryFn:\n agentId && threadId\n ? () =>\n client.getObservationalMemory({\n agentId,\n threadId,\n resourceId,\n })\n : skipToken,\n // The record is read by several surfaces at once (collapsed memory bar, OM\n // section, detail panel). A short stale window lets a newly mounted consumer\n // reuse the cached record instead of refiring the request; freshness still\n // comes from the explicit refetch on stream finish/observation signals.\n staleTime: 5_000,\n ...queryOptions,\n });\n}\n","import type { MastraClient } from '@mastra/client-js';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { skipToken, useQuery } from '@tanstack/react-query';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraQueryOptions } from '../shared/query-options';\n\nexport const memoryStatusQueryKey = (agentId: string | undefined, threadId?: string) =>\n ['memory', 'status', agentId, threadId] as const;\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>>;\n\nexport function useMemoryStatus<TData = MemoryStatusResponse>({\n agentId,\n threadId,\n queryOptions,\n}: {\n agentId: string | undefined;\n threadId?: string;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n}): UseQueryResult<TData, Error> {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: memoryStatusQueryKey(agentId, threadId),\n queryFn: agentId\n ? () =>\n client.getMemoryStatus(agentId, undefined, {\n threadId,\n })\n : skipToken,\n ...queryOptions,\n });\n}\n","import type { GetObservationalMemoryResponse, GetMemoryStatusResponse, MastraClient } from '@mastra/client-js';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';\nimport { useState, useEffect } from 'react';\nimport { useMastraClient } from '../../mastra-client-context';\nimport type { MastraMutationOptions, MastraQueryOptions } from '../shared/query-options';\n\nexport interface MemorySearchParams {\n lastMessages?: number | false;\n}\n\ntype MemoryStatusResponse = Awaited<ReturnType<MastraClient['getMemoryStatus']>> | null;\ntype MemoryConfigResponse = Awaited<ReturnType<MastraClient['getMemoryConfig']>> | null;\ntype ThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['get']>>;\ntype ThreadsResponse = Awaited<ReturnType<MastraClient['listMemoryThreads']>>['threads'] | null;\ntype UpdateThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['update']>>;\ntype CloneThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['clone']>>;\ntype SearchMemoryResponse = Awaited<ReturnType<MastraClient['searchMemory']>>;\ntype ThreadVariables = { threadId: string; agentId: string };\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemory = <TData = MemoryStatusResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryStatusResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryStatus(agentId, requestContext) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryConfig = <TData = MemoryConfigResponse>({\n agentId,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<MemoryConfigResponse, TData>;\n} = {}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'config', agentId, requestContext],\n queryFn: () => (agentId ? client.getMemoryConfig({ agentId, requestContext }) : null),\n staleTime: 5 * 60 * 1000, // 5 minutes\n gcTime: 10 * 60 * 1000, // 10 minutes\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThread = <TData = ThreadResponse>({\n threadId,\n agentId,\n requestContext,\n queryOptions,\n}: {\n threadId?: string;\n agentId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'thread', threadId, agentId, requestContext],\n queryFn: () => client.getMemoryThread({ threadId: threadId!, agentId }).get({ requestContext }),\n staleTime: 5 * 60 * 1000,\n gcTime: 10 * 60 * 1000,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\n/**\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useThreads = <TData = ThreadsResponse>({\n resourceId,\n agentId,\n isMemoryEnabled,\n requestContext,\n queryOptions,\n}: {\n resourceId: string;\n agentId: string;\n isMemoryEnabled: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<ThreadsResponse, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['memory', 'threads', resourceId, agentId, requestContext],\n queryFn: async () => {\n if (!isMemoryEnabled) return null;\n const result = await client.listMemoryThreads({ resourceId, agentId, requestContext });\n return result.threads;\n },\n staleTime: 0,\n gcTime: 0,\n retry: false,\n refetchOnWindowFocus: false,\n ...queryOptions,\n });\n};\n\nexport type DeleteThreadResponse = Awaited<ReturnType<ReturnType<MastraClient['getMemoryThread']>['delete']>>;\n\nexport const useDeleteThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<DeleteThreadResponse, ThreadVariables>;\n} = {}): UseMutationResult<DeleteThreadResponse, Error, ThreadVariables> => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId }: { threadId: string; agentId: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.delete({ requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\nexport const useUpdateThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<UpdateThreadResponse, ThreadVariables & { title: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: ({ threadId, agentId, title }: { threadId: string; agentId: string; title: string }) =>\n client.getMemoryThread({ threadId, agentId }).update({ title, agentId, requestContext }),\n onSuccess: () => {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads'] });\n void queryClient.invalidateQueries({ queryKey: ['memory', 'thread'] });\n },\n ...queryOptions,\n });\n};\n\nexport const useMemorySearch = ({\n agentId,\n resourceId,\n threadId,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId: string;\n threadId?: string;\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<\n SearchMemoryResponse,\n { searchQuery: string; memoryConfig?: MemorySearchParams }\n >;\n}) => {\n const client = useMastraClient();\n return useMutation({\n mutationFn: async ({ searchQuery, memoryConfig }: { searchQuery: string; memoryConfig?: MemorySearchParams }) => {\n return client.searchMemory({ agentId, resourceId, threadId, searchQuery, memoryConfig, requestContext });\n },\n ...queryOptions,\n });\n};\n\nexport const useCloneThread = ({\n requestContext,\n queryOptions,\n}: {\n requestContext?: Record<string, any>;\n queryOptions?: MastraMutationOptions<CloneThreadResponse, ThreadVariables & { title?: string }>;\n} = {}) => {\n const client = useMastraClient();\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ threadId, agentId, title }: { threadId: string; agentId: string; title?: string }) => {\n const thread = client.getMemoryThread({ threadId, agentId });\n return thread.clone({ title, requestContext });\n },\n onSuccess: (_, variables) => {\n const { agentId } = variables;\n if (agentId) {\n void queryClient.invalidateQueries({ queryKey: ['memory', 'threads', agentId, agentId] });\n }\n },\n ...queryOptions,\n });\n};\n\n/**\n * Hook to fetch Observational Memory data for an agent\n * Returns the current OM record and history for a given resource/thread\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useObservationalMemoryWithHistory = <TData = GetObservationalMemoryResponse | null>({\n agentId,\n resourceId,\n threadId,\n isActive = false,\n requestContext,\n queryOptions,\n}: {\n agentId: string;\n resourceId?: string;\n threadId?: string;\n isActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetObservationalMemoryResponse | null, TData>;\n}): UseQueryResult<TData, Error> => {\n const client = useMastraClient();\n\n return useQuery({\n queryKey: ['observational-memory', agentId, resourceId, threadId, requestContext],\n queryFn: async (): Promise<GetObservationalMemoryResponse | null> => {\n if (!resourceId && !threadId) return null;\n return client.getObservationalMemory({\n agentId,\n resourceId,\n threadId,\n requestContext,\n });\n },\n staleTime: isActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n};\n\n/**\n * Hook to get OM-aware memory status\n * Extends useMemory with OM-specific status information\n * Polls more frequently when observing/reflecting is in progress\n *\n * Does not guard on empty ids; pass `queryOptions: { enabled }` to skip the fetch.\n */\nexport const useMemoryWithOMStatus = ({\n agentId,\n resourceId,\n threadId,\n pollWhenActive = true,\n requestContext,\n queryOptions,\n}: {\n agentId?: string;\n resourceId?: string;\n threadId?: string;\n pollWhenActive?: boolean;\n requestContext?: Record<string, any>;\n queryOptions?: MastraQueryOptions<GetMemoryStatusResponse | null>;\n}) => {\n const client = useMastraClient();\n const [isActive, setIsActive] = useState(false);\n\n const query = useQuery<GetMemoryStatusResponse | null>({\n queryKey: ['memory-status', agentId, resourceId, threadId, requestContext],\n queryFn: () =>\n agentId\n ? client.getMemoryStatus(agentId, requestContext, {\n resourceId,\n threadId,\n })\n : null,\n staleTime: isActive && pollWhenActive ? 1000 : 30 * 1000, // 1 second when active, 30 seconds otherwise\n gcTime: 5 * 60 * 1000, // 5 minutes\n retry: false,\n refetchOnWindowFocus: false,\n refetchInterval: isActive && pollWhenActive ? 2000 : false, // Poll every 2 seconds when active\n placeholderData: previousData => previousData, // Keep previous data during refetch to prevent skeleton flash\n ...queryOptions,\n });\n\n // Update isActive state when data changes\n const isObserving = query.data?.observationalMemory?.isObserving;\n const isReflecting = query.data?.observationalMemory?.isReflecting;\n\n useEffect(() => {\n const newIsActive = isObserving || isReflecting || false;\n setIsActive(newIsActive);\n }, [isObserving, isReflecting]);\n\n return query;\n};\n"],"mappings":";;;;;AAMA,MAAa,gCAAgC,UAA8B,SACzE;CAAC;CAAU;CAAU;CAAU;CAAY,QAAQ;AAAC;AAItD,SAAgB,wBAA8D,EAC5E,UACA,OAAO,GACP,UAAU,KACV,gBAM+B;CAC/B,MAAM,SAASA,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd,UAAU,6BAA6B,UAAU,IAAI;EACrD,SAAS,iBAAiB,OAAO,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC,aAAa;GAAE;GAAM;EAAQ,CAAC,IAAIC,sBAAAA;EACjG,GAAG;CACL,CAAC;AACH;;;ACvBA,MAAa,+BAA+B,SAA6B,aACvE;CAAC;CAAU;CAAwB;CAAS;AAAQ;AAItD,SAAgB,uBAA4D,EAC1E,SACA,UACA,YACA,gBAM+B;CAC/B,MAAM,SAASC,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd,UAAU,4BAA4B,SAAS,QAAQ;EACvD,SACE,WAAW,iBAEL,OAAO,uBAAuB;GAC5B;GACA;GACA;EACF,CAAC,IACHC,sBAAAA;EAKN,WAAW;EACX,GAAG;CACL,CAAC;AACH;;;ACpCA,MAAa,wBAAwB,SAA6B,aAChE;CAAC;CAAU;CAAU;CAAS;AAAQ;AAIxC,SAAgB,gBAA8C,EAC5D,SACA,UACA,gBAK+B;CAC/B,MAAM,SAASC,8BAAAA,gBAAgB;CAE/B,QAAA,GAAOC,sBAAAA,SAAAA,CAAS;EACd,UAA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