@mastra/playground-ui 5.0.2-alpha.1 → 5.0.2-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/threads.d.ts +28 -0
- package/dist/domains/agents/agent/agent-traces.d.ts +8 -3
- package/dist/domains/workflows/workflow/workflow-traces.d.ts +8 -3
- package/dist/hooks/index.d.ts +1 -0
- package/dist/index.cjs.js +302 -239
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +295 -241
- package/dist/index.es.js.map +1 -1
- package/dist/lib/number.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './domains/workflows/index';
|
|
|
5
5
|
export * from './domains/resizable-panel';
|
|
6
6
|
export * from './components/dynamic-form/index';
|
|
7
7
|
export * from './components/ui/data-table';
|
|
8
|
+
export * from './components/threads';
|
|
8
9
|
export * from './types';
|
|
9
10
|
export * from './ds/components/Badge/index';
|
|
10
11
|
export * from './ds/components/Button/index';
|
|
@@ -14,3 +15,6 @@ export * from './ds/components/Logo/index';
|
|
|
14
15
|
export * from './ds/components/Table/index';
|
|
15
16
|
export * from './ds/components/Txt/index';
|
|
16
17
|
export * from './ds/icons/index';
|
|
18
|
+
export { useTraces } from './hooks/index';
|
|
19
|
+
export { TraceContext, TraceProvider } from './domains/traces/context/trace-context';
|
|
20
|
+
export { refineTraces } from './domains/traces/utils';
|
package/dist/index.es.js
CHANGED
|
@@ -32,7 +32,7 @@ import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
|
32
32
|
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
33
33
|
import jsonSchemaToZod from 'json-schema-to-zod';
|
|
34
34
|
import { parse } from 'superjson';
|
|
35
|
-
import z$1, { z } from 'zod';
|
|
35
|
+
import z$1, { z, ZodObject } from 'zod';
|
|
36
36
|
import { AutoForm as AutoForm$1, buildZodFieldConfig } from '@autoform/react';
|
|
37
37
|
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
38
38
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
@@ -4850,229 +4850,6 @@ function TraceProvider({ children }) {
|
|
|
4850
4850
|
);
|
|
4851
4851
|
}
|
|
4852
4852
|
|
|
4853
|
-
function usePolling({
|
|
4854
|
-
fetchFn,
|
|
4855
|
-
interval = 3e3,
|
|
4856
|
-
enabled = false,
|
|
4857
|
-
onSuccess,
|
|
4858
|
-
onError,
|
|
4859
|
-
shouldContinue = () => true,
|
|
4860
|
-
restartPolling = false
|
|
4861
|
-
}) {
|
|
4862
|
-
const [isPolling, setIsPolling] = useState(enabled);
|
|
4863
|
-
const [error, setError] = useState(null);
|
|
4864
|
-
const [data, setData] = useState(null);
|
|
4865
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
4866
|
-
const [firstCallLoading, setFirstCallLoading] = useState(false);
|
|
4867
|
-
const timeoutRef = useRef(null);
|
|
4868
|
-
const mountedRef = useRef(true);
|
|
4869
|
-
const [restart, setRestart] = useState(restartPolling);
|
|
4870
|
-
const cleanup = useCallback(() => {
|
|
4871
|
-
console.log("cleanup");
|
|
4872
|
-
if (timeoutRef.current) {
|
|
4873
|
-
clearTimeout(timeoutRef.current);
|
|
4874
|
-
timeoutRef.current = null;
|
|
4875
|
-
}
|
|
4876
|
-
}, []);
|
|
4877
|
-
const stopPolling = useCallback(() => {
|
|
4878
|
-
console.log("stopPolling");
|
|
4879
|
-
setIsPolling(false);
|
|
4880
|
-
cleanup();
|
|
4881
|
-
}, [cleanup]);
|
|
4882
|
-
const startPolling = useCallback(() => {
|
|
4883
|
-
console.log("startPolling");
|
|
4884
|
-
setIsPolling(true);
|
|
4885
|
-
setError(null);
|
|
4886
|
-
}, []);
|
|
4887
|
-
const executePoll = useCallback(
|
|
4888
|
-
async (refetch2 = true) => {
|
|
4889
|
-
if (!mountedRef.current) return;
|
|
4890
|
-
setIsLoading(true);
|
|
4891
|
-
try {
|
|
4892
|
-
const result = await fetchFn();
|
|
4893
|
-
setData(result);
|
|
4894
|
-
setError(null);
|
|
4895
|
-
onSuccess?.(result);
|
|
4896
|
-
if (shouldContinue(result) && refetch2) {
|
|
4897
|
-
timeoutRef.current = setTimeout(executePoll, interval);
|
|
4898
|
-
} else {
|
|
4899
|
-
stopPolling();
|
|
4900
|
-
}
|
|
4901
|
-
} catch (err) {
|
|
4902
|
-
if (!mountedRef.current) return;
|
|
4903
|
-
setError(err);
|
|
4904
|
-
onError?.(err);
|
|
4905
|
-
stopPolling();
|
|
4906
|
-
} finally {
|
|
4907
|
-
if (mountedRef.current) {
|
|
4908
|
-
setFirstCallLoading(false);
|
|
4909
|
-
setIsLoading(false);
|
|
4910
|
-
}
|
|
4911
|
-
}
|
|
4912
|
-
},
|
|
4913
|
-
[fetchFn, interval, onSuccess, onError, shouldContinue, stopPolling]
|
|
4914
|
-
);
|
|
4915
|
-
const refetch = useCallback(
|
|
4916
|
-
(withPolling = false) => {
|
|
4917
|
-
console.log("refetch", { withPolling });
|
|
4918
|
-
if (withPolling) {
|
|
4919
|
-
setIsPolling(true);
|
|
4920
|
-
} else {
|
|
4921
|
-
executePoll(false);
|
|
4922
|
-
}
|
|
4923
|
-
setError(null);
|
|
4924
|
-
},
|
|
4925
|
-
[executePoll]
|
|
4926
|
-
);
|
|
4927
|
-
useEffect(() => {
|
|
4928
|
-
mountedRef.current = true;
|
|
4929
|
-
if (enabled && isPolling) {
|
|
4930
|
-
executePoll(true);
|
|
4931
|
-
}
|
|
4932
|
-
return () => {
|
|
4933
|
-
console.log("cleanup poll");
|
|
4934
|
-
mountedRef.current = false;
|
|
4935
|
-
cleanup();
|
|
4936
|
-
};
|
|
4937
|
-
}, [enabled, isPolling, executePoll, cleanup]);
|
|
4938
|
-
useEffect(() => {
|
|
4939
|
-
setRestart(restartPolling);
|
|
4940
|
-
}, [restartPolling]);
|
|
4941
|
-
useEffect(() => {
|
|
4942
|
-
if (restart && !isPolling) {
|
|
4943
|
-
setIsPolling(true);
|
|
4944
|
-
executePoll();
|
|
4945
|
-
setRestart(false);
|
|
4946
|
-
}
|
|
4947
|
-
}, [restart]);
|
|
4948
|
-
return {
|
|
4949
|
-
isPolling,
|
|
4950
|
-
isLoading,
|
|
4951
|
-
error,
|
|
4952
|
-
data,
|
|
4953
|
-
startPolling,
|
|
4954
|
-
stopPolling,
|
|
4955
|
-
firstCallLoading,
|
|
4956
|
-
refetch
|
|
4957
|
-
};
|
|
4958
|
-
}
|
|
4959
|
-
|
|
4960
|
-
function formatOtelTimestamp(otelTimestamp) {
|
|
4961
|
-
const date = new Date(otelTimestamp / 1e3);
|
|
4962
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
4963
|
-
month: "numeric",
|
|
4964
|
-
day: "numeric",
|
|
4965
|
-
year: "numeric",
|
|
4966
|
-
hour: "numeric",
|
|
4967
|
-
minute: "numeric",
|
|
4968
|
-
second: "numeric",
|
|
4969
|
-
hour12: true
|
|
4970
|
-
}).format(date);
|
|
4971
|
-
}
|
|
4972
|
-
function formatOtelTimestamp2(otelTimestamp) {
|
|
4973
|
-
const date = new Date(otelTimestamp / 1e6);
|
|
4974
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
4975
|
-
month: "numeric",
|
|
4976
|
-
day: "numeric",
|
|
4977
|
-
year: "numeric",
|
|
4978
|
-
hour: "numeric",
|
|
4979
|
-
minute: "numeric",
|
|
4980
|
-
second: "numeric",
|
|
4981
|
-
hour12: true
|
|
4982
|
-
}).format(date);
|
|
4983
|
-
}
|
|
4984
|
-
function transformKey(key) {
|
|
4985
|
-
if (key.includes(".argument.")) {
|
|
4986
|
-
return `Input`;
|
|
4987
|
-
}
|
|
4988
|
-
if (key.includes(".result")) {
|
|
4989
|
-
return "Output";
|
|
4990
|
-
}
|
|
4991
|
-
const newKey = key.split(".").join(" ").split("_").join(" ").replaceAll("ai", "AI");
|
|
4992
|
-
return newKey.substring(0, 1).toUpperCase() + newKey.substring(1);
|
|
4993
|
-
}
|
|
4994
|
-
const refineTraces = (traces, isWorkflow = false) => {
|
|
4995
|
-
const listOfSpanIds = /* @__PURE__ */ new Set();
|
|
4996
|
-
const newName = (name) => {
|
|
4997
|
-
if (name?.startsWith("workflow.") && isWorkflow) {
|
|
4998
|
-
return name?.split(".")?.slice(2)?.join(".");
|
|
4999
|
-
}
|
|
5000
|
-
if (name?.startsWith("agent.") && !isWorkflow) {
|
|
5001
|
-
return name?.split(".")?.slice(1)?.join(".");
|
|
5002
|
-
}
|
|
5003
|
-
return name;
|
|
5004
|
-
};
|
|
5005
|
-
const groupedTraces = traces?.reduce((acc, curr) => {
|
|
5006
|
-
const newCurr = { ...curr, name: newName(curr.name), duration: curr.endTime - curr.startTime };
|
|
5007
|
-
listOfSpanIds.add(curr.id);
|
|
5008
|
-
return { ...acc, [curr.traceId]: [...acc[curr.traceId] || [], newCurr] };
|
|
5009
|
-
}, {});
|
|
5010
|
-
const tracesData = Object.entries(groupedTraces).map(([key, value]) => {
|
|
5011
|
-
const parentSpan = value.find((span) => !span.parentSpanId || !listOfSpanIds.has(span.parentSpanId));
|
|
5012
|
-
const enrichedSpans = value.map((span) => ({
|
|
5013
|
-
...span,
|
|
5014
|
-
parentSpanId: parentSpan?.id === span.id ? null : span?.parentSpanId,
|
|
5015
|
-
relativePercentage: parentSpan ? span.duration / parentSpan.duration : 0
|
|
5016
|
-
}));
|
|
5017
|
-
const failedStatus = value.find((span) => span.status.code !== 0)?.status;
|
|
5018
|
-
return {
|
|
5019
|
-
traceId: key,
|
|
5020
|
-
serviceName: parentSpan?.name || key,
|
|
5021
|
-
duration: parentSpan?.duration || value.reduce((acc, curr) => acc + curr.duration, 0),
|
|
5022
|
-
status: failedStatus || parentSpan?.status || value[0].status,
|
|
5023
|
-
started: value[0].startTime,
|
|
5024
|
-
trace: enrichedSpans
|
|
5025
|
-
};
|
|
5026
|
-
});
|
|
5027
|
-
return tracesData;
|
|
5028
|
-
};
|
|
5029
|
-
|
|
5030
|
-
const useTraces = (componentName, baseUrl, isWorkflow = false) => {
|
|
5031
|
-
const [traces, setTraces] = useState([]);
|
|
5032
|
-
const { setTraces: setTraceContextTraces } = useContext(TraceContext);
|
|
5033
|
-
const client = useMemo(() => createMastraClient(baseUrl), [baseUrl]);
|
|
5034
|
-
const fetchFn = useCallback(async () => {
|
|
5035
|
-
try {
|
|
5036
|
-
const res = await client.getTelemetry({
|
|
5037
|
-
attribute: {
|
|
5038
|
-
componentName
|
|
5039
|
-
}
|
|
5040
|
-
});
|
|
5041
|
-
if (!res.traces) {
|
|
5042
|
-
throw new Error("Error fetching traces");
|
|
5043
|
-
}
|
|
5044
|
-
const refinedTraces = refineTraces(res?.traces || [], isWorkflow);
|
|
5045
|
-
return refinedTraces;
|
|
5046
|
-
} catch (error2) {
|
|
5047
|
-
throw error2;
|
|
5048
|
-
}
|
|
5049
|
-
}, [client, componentName, isWorkflow]);
|
|
5050
|
-
const onSuccess = useCallback(
|
|
5051
|
-
(newTraces) => {
|
|
5052
|
-
if (newTraces.length > 0) {
|
|
5053
|
-
setTraces(() => newTraces);
|
|
5054
|
-
setTraceContextTraces(() => newTraces);
|
|
5055
|
-
}
|
|
5056
|
-
},
|
|
5057
|
-
[setTraceContextTraces]
|
|
5058
|
-
);
|
|
5059
|
-
const onError = useCallback((error2) => {
|
|
5060
|
-
toast.error(error2.message);
|
|
5061
|
-
}, []);
|
|
5062
|
-
const shouldContinue = useCallback(() => {
|
|
5063
|
-
return true;
|
|
5064
|
-
}, []);
|
|
5065
|
-
const { firstCallLoading, error } = usePolling({
|
|
5066
|
-
fetchFn,
|
|
5067
|
-
interval: 3e3,
|
|
5068
|
-
onSuccess,
|
|
5069
|
-
onError,
|
|
5070
|
-
shouldContinue,
|
|
5071
|
-
enabled: true
|
|
5072
|
-
});
|
|
5073
|
-
return { traces, firstCallLoading, error };
|
|
5074
|
-
};
|
|
5075
|
-
|
|
5076
4853
|
const rowSize = {
|
|
5077
4854
|
default: "[&>tbody>tr]:h-table-row",
|
|
5078
4855
|
small: "[&>tbody>tr]:h-table-row-small"
|
|
@@ -5194,6 +4971,10 @@ const useOpenTrace = () => {
|
|
|
5194
4971
|
return { openTrace };
|
|
5195
4972
|
};
|
|
5196
4973
|
|
|
4974
|
+
const toSigFigs = (num, sigFigs) => {
|
|
4975
|
+
return Number(num.toPrecision(sigFigs));
|
|
4976
|
+
};
|
|
4977
|
+
|
|
5197
4978
|
const TracesTableSkeleton = ({ colsCount }) => {
|
|
5198
4979
|
return /* @__PURE__ */ jsx(Tbody, { children: /* @__PURE__ */ jsx(Row, { children: Array.from({ length: colsCount }).map((_, index) => /* @__PURE__ */ jsx(Cell, { children: /* @__PURE__ */ jsx(Skeleton, { className: "w-1/2" }) }, index)) }) });
|
|
5199
4980
|
};
|
|
@@ -5212,7 +4993,7 @@ const TraceRow = ({ trace, index, isActive }) => {
|
|
|
5212
4993
|
trace.traceId.substring(0, 7),
|
|
5213
4994
|
"..."
|
|
5214
4995
|
] }),
|
|
5215
|
-
/* @__PURE__ */ jsx(UnitCell, { unit: "ms", children:
|
|
4996
|
+
/* @__PURE__ */ jsx(UnitCell, { unit: "ms", children: toSigFigs(trace.duration / 1e3, 3) }),
|
|
5216
4997
|
/* @__PURE__ */ jsx(Cell, { children: /* @__PURE__ */ jsx("button", { onClick: () => openTrace(trace.trace, index), children: /* @__PURE__ */ jsx(Badge$1, { icon: /* @__PURE__ */ jsx(TraceIcon, {}), children: trace.trace.length }) }) }),
|
|
5217
4998
|
/* @__PURE__ */ jsx(Cell, { children: hasFailure ? /* @__PURE__ */ jsx(Badge$1, { variant: "error", icon: /* @__PURE__ */ jsx(X, {}), children: "Failed" }) : /* @__PURE__ */ jsx(Badge$1, { icon: /* @__PURE__ */ jsx(Check, {}), variant: "success", children: "Success" }) })
|
|
5218
4999
|
] });
|
|
@@ -5349,11 +5130,12 @@ const variantClasses = {
|
|
|
5349
5130
|
};
|
|
5350
5131
|
const Time = ({ durationMs, tokenCount, variant, progressPercent }) => {
|
|
5351
5132
|
const variantClass = variant ? variantClasses[variant] : "bg-accent3";
|
|
5133
|
+
const percent = Math.min(100, progressPercent);
|
|
5352
5134
|
return /* @__PURE__ */ jsxs("div", { className: "w-[80px] xl:w-[166px] shrink-0", children: [
|
|
5353
|
-
/* @__PURE__ */ jsx("div", { className: "bg-surface4 relative h-[6px] w-full rounded-full p-px overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: clsx("absolute h-1 rounded-full", variantClass), style: { width: `${
|
|
5135
|
+
/* @__PURE__ */ jsx("div", { className: "bg-surface4 relative h-[6px] w-full rounded-full p-px overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: clsx("absolute h-1 rounded-full", variantClass), style: { width: `${percent}%` } }) }),
|
|
5354
5136
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 pt-0.5", children: [
|
|
5355
5137
|
/* @__PURE__ */ jsxs(Txt, { variant: "ui-sm", className: "text-icon2 font-medium", children: [
|
|
5356
|
-
|
|
5138
|
+
toSigFigs(durationMs, 3),
|
|
5357
5139
|
"ms"
|
|
5358
5140
|
] }),
|
|
5359
5141
|
tokenCount && /* @__PURE__ */ jsxs(Txt, { variant: "ui-sm", className: "text-icon2 font-medium", children: [
|
|
@@ -5588,6 +5370,76 @@ const SyntaxHighlighter = ({ data }) => {
|
|
|
5588
5370
|
return /* @__PURE__ */ jsx("div", { className: "rounded-md bg-[#1a1a1a] p-1 font-mono", children: /* @__PURE__ */ jsx(CodeMirror, { value: formattedCode, theme, extensions: [jsonLanguage] }) });
|
|
5589
5371
|
};
|
|
5590
5372
|
|
|
5373
|
+
function formatOtelTimestamp(otelTimestamp) {
|
|
5374
|
+
const date = new Date(otelTimestamp / 1e3);
|
|
5375
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
5376
|
+
month: "numeric",
|
|
5377
|
+
day: "numeric",
|
|
5378
|
+
year: "numeric",
|
|
5379
|
+
hour: "numeric",
|
|
5380
|
+
minute: "numeric",
|
|
5381
|
+
second: "numeric",
|
|
5382
|
+
hour12: true
|
|
5383
|
+
}).format(date);
|
|
5384
|
+
}
|
|
5385
|
+
function formatOtelTimestamp2(otelTimestamp) {
|
|
5386
|
+
const date = new Date(otelTimestamp / 1e6);
|
|
5387
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
5388
|
+
month: "numeric",
|
|
5389
|
+
day: "numeric",
|
|
5390
|
+
year: "numeric",
|
|
5391
|
+
hour: "numeric",
|
|
5392
|
+
minute: "numeric",
|
|
5393
|
+
second: "numeric",
|
|
5394
|
+
hour12: true
|
|
5395
|
+
}).format(date);
|
|
5396
|
+
}
|
|
5397
|
+
function transformKey(key) {
|
|
5398
|
+
if (key.includes(".argument.")) {
|
|
5399
|
+
return `Input`;
|
|
5400
|
+
}
|
|
5401
|
+
if (key.includes(".result")) {
|
|
5402
|
+
return "Output";
|
|
5403
|
+
}
|
|
5404
|
+
const newKey = key.split(".").join(" ").split("_").join(" ").replaceAll("ai", "AI");
|
|
5405
|
+
return newKey.substring(0, 1).toUpperCase() + newKey.substring(1);
|
|
5406
|
+
}
|
|
5407
|
+
const refineTraces = (traces, isWorkflow = false) => {
|
|
5408
|
+
const listOfSpanIds = /* @__PURE__ */ new Set();
|
|
5409
|
+
const newName = (name) => {
|
|
5410
|
+
if (name?.startsWith("workflow.") && isWorkflow) {
|
|
5411
|
+
return name?.split(".")?.slice(2)?.join(".");
|
|
5412
|
+
}
|
|
5413
|
+
if (name?.startsWith("agent.") && !isWorkflow) {
|
|
5414
|
+
return name?.split(".")?.slice(1)?.join(".");
|
|
5415
|
+
}
|
|
5416
|
+
return name;
|
|
5417
|
+
};
|
|
5418
|
+
const groupedTraces = traces?.reduce((acc, curr) => {
|
|
5419
|
+
const newCurr = { ...curr, name: newName(curr.name), duration: curr.endTime - curr.startTime };
|
|
5420
|
+
listOfSpanIds.add(curr.id);
|
|
5421
|
+
return { ...acc, [curr.traceId]: [...acc[curr.traceId] || [], newCurr] };
|
|
5422
|
+
}, {});
|
|
5423
|
+
const tracesData = Object.entries(groupedTraces).map(([key, value]) => {
|
|
5424
|
+
const parentSpan = value.find((span) => !span.parentSpanId || !listOfSpanIds.has(span.parentSpanId));
|
|
5425
|
+
const enrichedSpans = value.map((span) => ({
|
|
5426
|
+
...span,
|
|
5427
|
+
parentSpanId: parentSpan?.id === span.id ? null : span?.parentSpanId,
|
|
5428
|
+
relativePercentage: parentSpan ? span.duration / parentSpan.duration : 0
|
|
5429
|
+
}));
|
|
5430
|
+
const failedStatus = value.find((span) => span.status.code !== 0)?.status;
|
|
5431
|
+
return {
|
|
5432
|
+
traceId: key,
|
|
5433
|
+
serviceName: parentSpan?.name || key,
|
|
5434
|
+
duration: parentSpan?.duration || value.reduce((acc, curr) => acc + curr.duration, 0),
|
|
5435
|
+
status: failedStatus || parentSpan?.status || value[0].status,
|
|
5436
|
+
started: value[0].startTime,
|
|
5437
|
+
trace: enrichedSpans
|
|
5438
|
+
};
|
|
5439
|
+
});
|
|
5440
|
+
return tracesData;
|
|
5441
|
+
};
|
|
5442
|
+
|
|
5591
5443
|
function SpanDetail() {
|
|
5592
5444
|
const { span, setSpan, trace, setIsOpen } = useContext(TraceContext);
|
|
5593
5445
|
if (!span || !trace) return null;
|
|
@@ -5623,11 +5475,11 @@ function SpanDetail() {
|
|
|
5623
5475
|
span.name
|
|
5624
5476
|
] }),
|
|
5625
5477
|
/* @__PURE__ */ jsx("div", { className: "flex flex-row gap-2 items-center", children: span.status.code === 0 ? /* @__PURE__ */ jsxs(Badge$1, { icon: /* @__PURE__ */ jsx(LatencyIcon, {}), variant: "success", children: [
|
|
5626
|
-
|
|
5478
|
+
toSigFigs(span.duration / 1e3, 3),
|
|
5627
5479
|
"ms"
|
|
5628
5480
|
] }) : /* @__PURE__ */ jsxs(Badge$1, { variant: "error", icon: /* @__PURE__ */ jsx(X, {}), children: [
|
|
5629
5481
|
"Failed in ",
|
|
5630
|
-
|
|
5482
|
+
toSigFigs(span.duration / 1e3, 3),
|
|
5631
5483
|
"ms"
|
|
5632
5484
|
] }) }),
|
|
5633
5485
|
/* @__PURE__ */ jsx("hr", { className: "border-border1 border-sm my-5" }),
|
|
@@ -5713,15 +5565,14 @@ const TracesSidebar = ({ onResize }) => {
|
|
|
5713
5565
|
);
|
|
5714
5566
|
};
|
|
5715
5567
|
|
|
5716
|
-
function AgentTraces({
|
|
5717
|
-
return /* @__PURE__ */ jsx(
|
|
5568
|
+
function AgentTraces({ className, traces, isLoading, error }) {
|
|
5569
|
+
return /* @__PURE__ */ jsx(AgentTracesInner, { className, traces, isLoading, error });
|
|
5718
5570
|
}
|
|
5719
|
-
function AgentTracesInner({
|
|
5571
|
+
function AgentTracesInner({ className, traces, isLoading, error }) {
|
|
5720
5572
|
const [sidebarWidth, setSidebarWidth] = useState(100);
|
|
5721
|
-
const { traces, firstCallLoading, error } = useTraces(agentName, baseUrl);
|
|
5722
5573
|
const { isOpen: open } = useContext(TraceContext);
|
|
5723
5574
|
return /* @__PURE__ */ jsxs("div", { className: clsx("h-full relative overflow-hidden flex", className), children: [
|
|
5724
|
-
/* @__PURE__ */ jsx("div", { className: "h-full overflow-y-scroll w-full", children: /* @__PURE__ */ jsx(TracesTable, { traces, isLoading
|
|
5575
|
+
/* @__PURE__ */ jsx("div", { className: "h-full overflow-y-scroll w-full", children: /* @__PURE__ */ jsx(TracesTable, { traces, isLoading, error }) }),
|
|
5725
5576
|
open && /* @__PURE__ */ jsx(TracesSidebar, { width: sidebarWidth, onResize: setSidebarWidth })
|
|
5726
5577
|
] });
|
|
5727
5578
|
}
|
|
@@ -6173,15 +6024,14 @@ const NetworkChat = ({ agentId, memory }) => {
|
|
|
6173
6024
|
return /* @__PURE__ */ jsx(MastraNetworkRuntimeProvider, { agentId, memory, modelSettings, children: /* @__PURE__ */ jsx("div", { className: "h-full pb-4", children: /* @__PURE__ */ jsx(Thread, { ToolFallback }) }) });
|
|
6174
6025
|
};
|
|
6175
6026
|
|
|
6176
|
-
function WorkflowTraces({
|
|
6177
|
-
return /* @__PURE__ */ jsx(
|
|
6027
|
+
function WorkflowTraces({ traces, isLoading, error }) {
|
|
6028
|
+
return /* @__PURE__ */ jsx(WorkflowTracesInner, { traces, isLoading, error });
|
|
6178
6029
|
}
|
|
6179
|
-
function WorkflowTracesInner({
|
|
6030
|
+
function WorkflowTracesInner({ traces, isLoading, error }) {
|
|
6180
6031
|
const [sidebarWidth, setSidebarWidth] = useState(100);
|
|
6181
|
-
const { traces, error, firstCallLoading } = useTraces(workflowName, baseUrl, true);
|
|
6182
6032
|
const { isOpen: open } = useContext(TraceContext);
|
|
6183
6033
|
return /* @__PURE__ */ jsxs("main", { className: "h-full relative overflow-hidden flex", children: [
|
|
6184
|
-
/* @__PURE__ */ jsx("div", { className: "h-full overflow-y-scroll w-full", children: /* @__PURE__ */ jsx(TracesTable, { traces, isLoading
|
|
6034
|
+
/* @__PURE__ */ jsx("div", { className: "h-full overflow-y-scroll w-full", children: /* @__PURE__ */ jsx(TracesTable, { traces, isLoading, error }) }),
|
|
6185
6035
|
open && /* @__PURE__ */ jsx(TracesSidebar, { width: sidebarWidth, onResize: setSidebarWidth })
|
|
6186
6036
|
] });
|
|
6187
6037
|
}
|
|
@@ -8208,6 +8058,12 @@ class CustomZodProvider extends ZodProvider {
|
|
|
8208
8058
|
}
|
|
8209
8059
|
}
|
|
8210
8060
|
|
|
8061
|
+
function isEmptyZodObject(schema) {
|
|
8062
|
+
if (schema instanceof ZodObject) {
|
|
8063
|
+
return Object.keys(schema.shape).length === 0;
|
|
8064
|
+
}
|
|
8065
|
+
return false;
|
|
8066
|
+
}
|
|
8211
8067
|
function DynamicForm({
|
|
8212
8068
|
schema,
|
|
8213
8069
|
onSubmit,
|
|
@@ -8220,6 +8076,9 @@ function DynamicForm({
|
|
|
8220
8076
|
return null;
|
|
8221
8077
|
}
|
|
8222
8078
|
const normalizedSchema = (schema2) => {
|
|
8079
|
+
if (isEmptyZodObject(schema2)) {
|
|
8080
|
+
return z$1.object({});
|
|
8081
|
+
}
|
|
8223
8082
|
return z$1.object({
|
|
8224
8083
|
"": schema2
|
|
8225
8084
|
});
|
|
@@ -8228,7 +8087,7 @@ function DynamicForm({
|
|
|
8228
8087
|
const formProps = {
|
|
8229
8088
|
schema: schemaProvider,
|
|
8230
8089
|
onSubmit: async (values) => {
|
|
8231
|
-
await onSubmit(values[""]);
|
|
8090
|
+
await onSubmit(values?.[""] || {});
|
|
8232
8091
|
},
|
|
8233
8092
|
defaultValues: defaultValues ? { "": defaultValues } : void 0,
|
|
8234
8093
|
formProps: {
|
|
@@ -8835,6 +8694,47 @@ const DataTable = ({
|
|
|
8835
8694
|
] });
|
|
8836
8695
|
};
|
|
8837
8696
|
|
|
8697
|
+
const Threads = ({ children }) => {
|
|
8698
|
+
return /* @__PURE__ */ jsx("nav", { className: "bg-surface2 border-r-sm border-border1 min-h-full overflow-hidden", children });
|
|
8699
|
+
};
|
|
8700
|
+
const ThreadLink = ({ children, as: Component = "a", href, className, prefetch, to }) => {
|
|
8701
|
+
return /* @__PURE__ */ jsx(
|
|
8702
|
+
Component,
|
|
8703
|
+
{
|
|
8704
|
+
href,
|
|
8705
|
+
prefetch,
|
|
8706
|
+
to,
|
|
8707
|
+
className: clsx("text-ui-sm flex h-full w-full flex-col justify-center font-medium", className),
|
|
8708
|
+
children
|
|
8709
|
+
}
|
|
8710
|
+
);
|
|
8711
|
+
};
|
|
8712
|
+
const ThreadList = ({ children }) => {
|
|
8713
|
+
return /* @__PURE__ */ jsx("ol", { children });
|
|
8714
|
+
};
|
|
8715
|
+
const ThreadItem = ({ children, isActive }) => {
|
|
8716
|
+
return /* @__PURE__ */ jsx(
|
|
8717
|
+
"li",
|
|
8718
|
+
{
|
|
8719
|
+
className: clsx(
|
|
8720
|
+
"border-b-sm border-border1 hover:bg-surface3 group flex h-[54px] items-center justify-between gap-2 px-5 py-2",
|
|
8721
|
+
isActive && "bg-surface4"
|
|
8722
|
+
),
|
|
8723
|
+
children
|
|
8724
|
+
}
|
|
8725
|
+
);
|
|
8726
|
+
};
|
|
8727
|
+
const ThreadDeleteButton = ({ onClick }) => {
|
|
8728
|
+
return /* @__PURE__ */ jsx(
|
|
8729
|
+
Button,
|
|
8730
|
+
{
|
|
8731
|
+
className: "shrink-0 border-none bg-transparent opacity-0 transition-all group-focus-within:opacity-100 group-hover:opacity-100",
|
|
8732
|
+
onClick,
|
|
8733
|
+
children: /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx(X, { "aria-label": "delete thread", className: "text-icon3" }) })
|
|
8734
|
+
}
|
|
8735
|
+
);
|
|
8736
|
+
};
|
|
8737
|
+
|
|
8838
8738
|
const Breadcrumb = ({ children, label }) => {
|
|
8839
8739
|
return /* @__PURE__ */ jsx("nav", { "aria-label": label, children: /* @__PURE__ */ jsx("ol", { className: "gap-sm flex items-center", children }) });
|
|
8840
8740
|
};
|
|
@@ -8910,5 +8810,159 @@ const DarkLogo = (props) => /* @__PURE__ */ jsxs("svg", { width: "100", height:
|
|
|
8910
8810
|
)
|
|
8911
8811
|
] });
|
|
8912
8812
|
|
|
8913
|
-
|
|
8813
|
+
function usePolling({
|
|
8814
|
+
fetchFn,
|
|
8815
|
+
interval = 3e3,
|
|
8816
|
+
enabled = false,
|
|
8817
|
+
onSuccess,
|
|
8818
|
+
onError,
|
|
8819
|
+
shouldContinue = () => true,
|
|
8820
|
+
restartPolling = false
|
|
8821
|
+
}) {
|
|
8822
|
+
const [isPolling, setIsPolling] = useState(enabled);
|
|
8823
|
+
const [error, setError] = useState(null);
|
|
8824
|
+
const [data, setData] = useState(null);
|
|
8825
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
8826
|
+
const [firstCallLoading, setFirstCallLoading] = useState(false);
|
|
8827
|
+
const timeoutRef = useRef(null);
|
|
8828
|
+
const mountedRef = useRef(true);
|
|
8829
|
+
const [restart, setRestart] = useState(restartPolling);
|
|
8830
|
+
const cleanup = useCallback(() => {
|
|
8831
|
+
console.log("cleanup");
|
|
8832
|
+
if (timeoutRef.current) {
|
|
8833
|
+
clearTimeout(timeoutRef.current);
|
|
8834
|
+
timeoutRef.current = null;
|
|
8835
|
+
}
|
|
8836
|
+
}, []);
|
|
8837
|
+
const stopPolling = useCallback(() => {
|
|
8838
|
+
console.log("stopPolling");
|
|
8839
|
+
setIsPolling(false);
|
|
8840
|
+
cleanup();
|
|
8841
|
+
}, [cleanup]);
|
|
8842
|
+
const startPolling = useCallback(() => {
|
|
8843
|
+
console.log("startPolling");
|
|
8844
|
+
setIsPolling(true);
|
|
8845
|
+
setError(null);
|
|
8846
|
+
}, []);
|
|
8847
|
+
const executePoll = useCallback(
|
|
8848
|
+
async (refetch2 = true) => {
|
|
8849
|
+
if (!mountedRef.current) return;
|
|
8850
|
+
setIsLoading(true);
|
|
8851
|
+
try {
|
|
8852
|
+
const result = await fetchFn();
|
|
8853
|
+
setData(result);
|
|
8854
|
+
setError(null);
|
|
8855
|
+
onSuccess?.(result);
|
|
8856
|
+
if (shouldContinue(result) && refetch2) {
|
|
8857
|
+
timeoutRef.current = setTimeout(executePoll, interval);
|
|
8858
|
+
} else {
|
|
8859
|
+
stopPolling();
|
|
8860
|
+
}
|
|
8861
|
+
} catch (err) {
|
|
8862
|
+
if (!mountedRef.current) return;
|
|
8863
|
+
setError(err);
|
|
8864
|
+
onError?.(err);
|
|
8865
|
+
stopPolling();
|
|
8866
|
+
} finally {
|
|
8867
|
+
if (mountedRef.current) {
|
|
8868
|
+
setFirstCallLoading(false);
|
|
8869
|
+
setIsLoading(false);
|
|
8870
|
+
}
|
|
8871
|
+
}
|
|
8872
|
+
},
|
|
8873
|
+
[fetchFn, interval, onSuccess, onError, shouldContinue, stopPolling]
|
|
8874
|
+
);
|
|
8875
|
+
const refetch = useCallback(
|
|
8876
|
+
(withPolling = false) => {
|
|
8877
|
+
console.log("refetch", { withPolling });
|
|
8878
|
+
if (withPolling) {
|
|
8879
|
+
setIsPolling(true);
|
|
8880
|
+
} else {
|
|
8881
|
+
executePoll(false);
|
|
8882
|
+
}
|
|
8883
|
+
setError(null);
|
|
8884
|
+
},
|
|
8885
|
+
[executePoll]
|
|
8886
|
+
);
|
|
8887
|
+
useEffect(() => {
|
|
8888
|
+
mountedRef.current = true;
|
|
8889
|
+
if (enabled && isPolling) {
|
|
8890
|
+
executePoll(true);
|
|
8891
|
+
}
|
|
8892
|
+
return () => {
|
|
8893
|
+
console.log("cleanup poll");
|
|
8894
|
+
mountedRef.current = false;
|
|
8895
|
+
cleanup();
|
|
8896
|
+
};
|
|
8897
|
+
}, [enabled, isPolling, executePoll, cleanup]);
|
|
8898
|
+
useEffect(() => {
|
|
8899
|
+
setRestart(restartPolling);
|
|
8900
|
+
}, [restartPolling]);
|
|
8901
|
+
useEffect(() => {
|
|
8902
|
+
if (restart && !isPolling) {
|
|
8903
|
+
setIsPolling(true);
|
|
8904
|
+
executePoll();
|
|
8905
|
+
setRestart(false);
|
|
8906
|
+
}
|
|
8907
|
+
}, [restart]);
|
|
8908
|
+
return {
|
|
8909
|
+
isPolling,
|
|
8910
|
+
isLoading,
|
|
8911
|
+
error,
|
|
8912
|
+
data,
|
|
8913
|
+
startPolling,
|
|
8914
|
+
stopPolling,
|
|
8915
|
+
firstCallLoading,
|
|
8916
|
+
refetch
|
|
8917
|
+
};
|
|
8918
|
+
}
|
|
8919
|
+
|
|
8920
|
+
const useTraces = (componentName, baseUrl, isWorkflow = false) => {
|
|
8921
|
+
const [traces, setTraces] = useState([]);
|
|
8922
|
+
const { setTraces: setTraceContextTraces } = useContext(TraceContext);
|
|
8923
|
+
const client = useMemo(() => createMastraClient(baseUrl), [baseUrl]);
|
|
8924
|
+
const fetchFn = useCallback(async () => {
|
|
8925
|
+
try {
|
|
8926
|
+
const res = await client.getTelemetry({
|
|
8927
|
+
attribute: {
|
|
8928
|
+
componentName
|
|
8929
|
+
}
|
|
8930
|
+
});
|
|
8931
|
+
if (!res.traces) {
|
|
8932
|
+
throw new Error("Error fetching traces");
|
|
8933
|
+
}
|
|
8934
|
+
const refinedTraces = refineTraces(res?.traces || [], isWorkflow);
|
|
8935
|
+
return refinedTraces;
|
|
8936
|
+
} catch (error2) {
|
|
8937
|
+
throw error2;
|
|
8938
|
+
}
|
|
8939
|
+
}, [client, componentName, isWorkflow]);
|
|
8940
|
+
const onSuccess = useCallback(
|
|
8941
|
+
(newTraces) => {
|
|
8942
|
+
if (newTraces.length > 0) {
|
|
8943
|
+
setTraces(() => newTraces);
|
|
8944
|
+
setTraceContextTraces(() => newTraces);
|
|
8945
|
+
}
|
|
8946
|
+
},
|
|
8947
|
+
[setTraceContextTraces]
|
|
8948
|
+
);
|
|
8949
|
+
const onError = useCallback((error2) => {
|
|
8950
|
+
console.log(`error, onError`, error2);
|
|
8951
|
+
toast.error(error2.message);
|
|
8952
|
+
}, []);
|
|
8953
|
+
const shouldContinue = useCallback(() => {
|
|
8954
|
+
return true;
|
|
8955
|
+
}, []);
|
|
8956
|
+
const { firstCallLoading, error } = usePolling({
|
|
8957
|
+
fetchFn,
|
|
8958
|
+
interval: 3e3,
|
|
8959
|
+
onSuccess,
|
|
8960
|
+
onError,
|
|
8961
|
+
shouldContinue,
|
|
8962
|
+
enabled: true
|
|
8963
|
+
});
|
|
8964
|
+
return { traces, firstCallLoading, error };
|
|
8965
|
+
};
|
|
8966
|
+
|
|
8967
|
+
export { AgentChat, AgentCoinIcon, AgentContext, AgentEvals, AgentIcon, AgentProvider, AgentTraces, AiIcon, ApiIcon, Badge$1 as Badge, BranchIcon, Breadcrumb, Button, Cell, CheckIcon, ChevronIcon, CommitIcon, CrossIcon, Crumb, DarkLogo, DataTable, DateTimeCell, DbIcon, DebugIcon, DeploymentIcon, DividerIcon, DocsIcon, DynamicForm, EntryCell, EnvIcon, EvaluatorCoinIcon, FiltersIcon, GithubCoinIcon, GithubIcon, GoogleIcon, Header, HeaderAction, HeaderGroup, HeaderTitle, HomeIcon, Icon, InfoIcon, JudgeIcon, LatencyIcon, LogsIcon, MastraResizablePanel, MemoryIcon, NetworkChat, NetworkContext, NetworkProvider, OpenAIIcon, PromptIcon, RepoIcon, Row, ScoreIcon, SettingsIcon, SlashIcon, Table, Tbody, Th, Thead, ThreadDeleteButton, ThreadItem, ThreadLink, ThreadList, Threads, ToolsIcon, TraceContext, TraceIcon, TraceProvider, TsIcon, Txt, TxtCell, UnitCell, VNextWorkflowGraph, VNextWorkflowTrigger, VariablesIcon, WorkflowCoinIcon, WorkflowGraph, WorkflowIcon, WorkflowRunContext, WorkflowRunProvider, WorkflowTraces, WorkflowTrigger, refineTraces, useTraces };
|
|
8914
8968
|
//# sourceMappingURL=index.es.js.map
|