@mastra/playground-ui 5.0.2-alpha.0 → 5.0.2-alpha.3
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/assistant-ui/thread.d.ts +5 -1
- 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 +271 -244
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +269 -246
- 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
|
@@ -14,3 +14,6 @@ export * from './ds/components/Logo/index';
|
|
|
14
14
|
export * from './ds/components/Table/index';
|
|
15
15
|
export * from './ds/components/Txt/index';
|
|
16
16
|
export * from './ds/icons/index';
|
|
17
|
+
export { useTraces } from './hooks/index';
|
|
18
|
+
export { TraceContext, TraceProvider } from './domains/traces/context/trace-context';
|
|
19
|
+
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';
|
|
@@ -3916,7 +3916,7 @@ const useAutoscroll = (ref, { enabled = true }) => {
|
|
|
3916
3916
|
}, [enabled, ref]);
|
|
3917
3917
|
};
|
|
3918
3918
|
|
|
3919
|
-
const Thread = ({ ToolFallback }) => {
|
|
3919
|
+
const Thread = ({ ToolFallback, agentName }) => {
|
|
3920
3920
|
const areaRef = useRef(null);
|
|
3921
3921
|
useAutoscroll(areaRef, { enabled: true });
|
|
3922
3922
|
const WrappedAssistantMessage = (props) => {
|
|
@@ -3925,7 +3925,7 @@ const Thread = ({ ToolFallback }) => {
|
|
|
3925
3925
|
return /* @__PURE__ */ jsxs(ThreadPrimitive.Root, { className: "max-w-[568px] w-full mx-auto h-[calc(100%-100px)] px-4", children: [
|
|
3926
3926
|
/* @__PURE__ */ jsxs(ThreadPrimitive.Viewport, { className: "py-10 overflow-y-auto scroll-smooth h-full", ref: areaRef, autoScroll: false, children: [
|
|
3927
3927
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
3928
|
-
/* @__PURE__ */ jsx(ThreadWelcome, {}),
|
|
3928
|
+
/* @__PURE__ */ jsx(ThreadWelcome, { agentName }),
|
|
3929
3929
|
/* @__PURE__ */ jsx(
|
|
3930
3930
|
ThreadPrimitive.Messages,
|
|
3931
3931
|
{
|
|
@@ -3942,9 +3942,19 @@ const Thread = ({ ToolFallback }) => {
|
|
|
3942
3942
|
/* @__PURE__ */ jsx(Composer, {})
|
|
3943
3943
|
] });
|
|
3944
3944
|
};
|
|
3945
|
-
const ThreadWelcome = () => {
|
|
3945
|
+
const ThreadWelcome = ({ agentName }) => {
|
|
3946
|
+
const safeAgentName = agentName ?? "";
|
|
3947
|
+
const words = safeAgentName.split(" ") ?? [];
|
|
3948
|
+
let initials = "A";
|
|
3949
|
+
if (words.length === 2) {
|
|
3950
|
+
initials = `${words[0][0]}${words[1][0]}`;
|
|
3951
|
+
} else if (safeAgentName.length > 0) {
|
|
3952
|
+
initials = `${safeAgentName[0]}`;
|
|
3953
|
+
} else {
|
|
3954
|
+
initials = "A";
|
|
3955
|
+
}
|
|
3946
3956
|
return /* @__PURE__ */ jsx(ThreadPrimitive.Empty, { children: /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-grow flex-col items-center justify-center", children: [
|
|
3947
|
-
/* @__PURE__ */ jsx(Avatar, { children: /* @__PURE__ */ jsx(AvatarFallback, { children:
|
|
3957
|
+
/* @__PURE__ */ jsx(Avatar, { children: /* @__PURE__ */ jsx(AvatarFallback, { children: initials }) }),
|
|
3948
3958
|
/* @__PURE__ */ jsx("p", { className: "mt-4 font-medium", children: "How can I help you today?" })
|
|
3949
3959
|
] }) });
|
|
3950
3960
|
};
|
|
@@ -4335,7 +4345,7 @@ const AgentChat = ({
|
|
|
4335
4345
|
refreshThreadList,
|
|
4336
4346
|
modelSettings,
|
|
4337
4347
|
chatWithGenerate,
|
|
4338
|
-
children: /* @__PURE__ */ jsx("div", { className: "h-full pb-4", children: /* @__PURE__ */ jsx(Thread, {}) })
|
|
4348
|
+
children: /* @__PURE__ */ jsx("div", { className: "h-full pb-4", children: /* @__PURE__ */ jsx(Thread, { agentName: agentName ?? "" }) })
|
|
4339
4349
|
}
|
|
4340
4350
|
);
|
|
4341
4351
|
};
|
|
@@ -4840,229 +4850,6 @@ function TraceProvider({ children }) {
|
|
|
4840
4850
|
);
|
|
4841
4851
|
}
|
|
4842
4852
|
|
|
4843
|
-
function usePolling({
|
|
4844
|
-
fetchFn,
|
|
4845
|
-
interval = 3e3,
|
|
4846
|
-
enabled = false,
|
|
4847
|
-
onSuccess,
|
|
4848
|
-
onError,
|
|
4849
|
-
shouldContinue = () => true,
|
|
4850
|
-
restartPolling = false
|
|
4851
|
-
}) {
|
|
4852
|
-
const [isPolling, setIsPolling] = useState(enabled);
|
|
4853
|
-
const [error, setError] = useState(null);
|
|
4854
|
-
const [data, setData] = useState(null);
|
|
4855
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
4856
|
-
const [firstCallLoading, setFirstCallLoading] = useState(false);
|
|
4857
|
-
const timeoutRef = useRef(null);
|
|
4858
|
-
const mountedRef = useRef(true);
|
|
4859
|
-
const [restart, setRestart] = useState(restartPolling);
|
|
4860
|
-
const cleanup = useCallback(() => {
|
|
4861
|
-
console.log("cleanup");
|
|
4862
|
-
if (timeoutRef.current) {
|
|
4863
|
-
clearTimeout(timeoutRef.current);
|
|
4864
|
-
timeoutRef.current = null;
|
|
4865
|
-
}
|
|
4866
|
-
}, []);
|
|
4867
|
-
const stopPolling = useCallback(() => {
|
|
4868
|
-
console.log("stopPolling");
|
|
4869
|
-
setIsPolling(false);
|
|
4870
|
-
cleanup();
|
|
4871
|
-
}, [cleanup]);
|
|
4872
|
-
const startPolling = useCallback(() => {
|
|
4873
|
-
console.log("startPolling");
|
|
4874
|
-
setIsPolling(true);
|
|
4875
|
-
setError(null);
|
|
4876
|
-
}, []);
|
|
4877
|
-
const executePoll = useCallback(
|
|
4878
|
-
async (refetch2 = true) => {
|
|
4879
|
-
if (!mountedRef.current) return;
|
|
4880
|
-
setIsLoading(true);
|
|
4881
|
-
try {
|
|
4882
|
-
const result = await fetchFn();
|
|
4883
|
-
setData(result);
|
|
4884
|
-
setError(null);
|
|
4885
|
-
onSuccess?.(result);
|
|
4886
|
-
if (shouldContinue(result) && refetch2) {
|
|
4887
|
-
timeoutRef.current = setTimeout(executePoll, interval);
|
|
4888
|
-
} else {
|
|
4889
|
-
stopPolling();
|
|
4890
|
-
}
|
|
4891
|
-
} catch (err) {
|
|
4892
|
-
if (!mountedRef.current) return;
|
|
4893
|
-
setError(err);
|
|
4894
|
-
onError?.(err);
|
|
4895
|
-
stopPolling();
|
|
4896
|
-
} finally {
|
|
4897
|
-
if (mountedRef.current) {
|
|
4898
|
-
setFirstCallLoading(false);
|
|
4899
|
-
setIsLoading(false);
|
|
4900
|
-
}
|
|
4901
|
-
}
|
|
4902
|
-
},
|
|
4903
|
-
[fetchFn, interval, onSuccess, onError, shouldContinue, stopPolling]
|
|
4904
|
-
);
|
|
4905
|
-
const refetch = useCallback(
|
|
4906
|
-
(withPolling = false) => {
|
|
4907
|
-
console.log("refetch", { withPolling });
|
|
4908
|
-
if (withPolling) {
|
|
4909
|
-
setIsPolling(true);
|
|
4910
|
-
} else {
|
|
4911
|
-
executePoll(false);
|
|
4912
|
-
}
|
|
4913
|
-
setError(null);
|
|
4914
|
-
},
|
|
4915
|
-
[executePoll]
|
|
4916
|
-
);
|
|
4917
|
-
useEffect(() => {
|
|
4918
|
-
mountedRef.current = true;
|
|
4919
|
-
if (enabled && isPolling) {
|
|
4920
|
-
executePoll(true);
|
|
4921
|
-
}
|
|
4922
|
-
return () => {
|
|
4923
|
-
console.log("cleanup poll");
|
|
4924
|
-
mountedRef.current = false;
|
|
4925
|
-
cleanup();
|
|
4926
|
-
};
|
|
4927
|
-
}, [enabled, isPolling, executePoll, cleanup]);
|
|
4928
|
-
useEffect(() => {
|
|
4929
|
-
setRestart(restartPolling);
|
|
4930
|
-
}, [restartPolling]);
|
|
4931
|
-
useEffect(() => {
|
|
4932
|
-
if (restart && !isPolling) {
|
|
4933
|
-
setIsPolling(true);
|
|
4934
|
-
executePoll();
|
|
4935
|
-
setRestart(false);
|
|
4936
|
-
}
|
|
4937
|
-
}, [restart]);
|
|
4938
|
-
return {
|
|
4939
|
-
isPolling,
|
|
4940
|
-
isLoading,
|
|
4941
|
-
error,
|
|
4942
|
-
data,
|
|
4943
|
-
startPolling,
|
|
4944
|
-
stopPolling,
|
|
4945
|
-
firstCallLoading,
|
|
4946
|
-
refetch
|
|
4947
|
-
};
|
|
4948
|
-
}
|
|
4949
|
-
|
|
4950
|
-
function formatOtelTimestamp(otelTimestamp) {
|
|
4951
|
-
const date = new Date(otelTimestamp / 1e3);
|
|
4952
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
4953
|
-
month: "numeric",
|
|
4954
|
-
day: "numeric",
|
|
4955
|
-
year: "numeric",
|
|
4956
|
-
hour: "numeric",
|
|
4957
|
-
minute: "numeric",
|
|
4958
|
-
second: "numeric",
|
|
4959
|
-
hour12: true
|
|
4960
|
-
}).format(date);
|
|
4961
|
-
}
|
|
4962
|
-
function formatOtelTimestamp2(otelTimestamp) {
|
|
4963
|
-
const date = new Date(otelTimestamp / 1e6);
|
|
4964
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
4965
|
-
month: "numeric",
|
|
4966
|
-
day: "numeric",
|
|
4967
|
-
year: "numeric",
|
|
4968
|
-
hour: "numeric",
|
|
4969
|
-
minute: "numeric",
|
|
4970
|
-
second: "numeric",
|
|
4971
|
-
hour12: true
|
|
4972
|
-
}).format(date);
|
|
4973
|
-
}
|
|
4974
|
-
function transformKey(key) {
|
|
4975
|
-
if (key.includes(".argument.")) {
|
|
4976
|
-
return `Input`;
|
|
4977
|
-
}
|
|
4978
|
-
if (key.includes(".result")) {
|
|
4979
|
-
return "Output";
|
|
4980
|
-
}
|
|
4981
|
-
const newKey = key.split(".").join(" ").split("_").join(" ").replaceAll("ai", "AI");
|
|
4982
|
-
return newKey.substring(0, 1).toUpperCase() + newKey.substring(1);
|
|
4983
|
-
}
|
|
4984
|
-
const refineTraces = (traces, isWorkflow = false) => {
|
|
4985
|
-
const listOfSpanIds = /* @__PURE__ */ new Set();
|
|
4986
|
-
const newName = (name) => {
|
|
4987
|
-
if (name?.startsWith("workflow.") && isWorkflow) {
|
|
4988
|
-
return name?.split(".")?.slice(2)?.join(".");
|
|
4989
|
-
}
|
|
4990
|
-
if (name?.startsWith("agent.") && !isWorkflow) {
|
|
4991
|
-
return name?.split(".")?.slice(1)?.join(".");
|
|
4992
|
-
}
|
|
4993
|
-
return name;
|
|
4994
|
-
};
|
|
4995
|
-
const groupedTraces = traces?.reduce((acc, curr) => {
|
|
4996
|
-
const newCurr = { ...curr, name: newName(curr.name), duration: curr.endTime - curr.startTime };
|
|
4997
|
-
listOfSpanIds.add(curr.id);
|
|
4998
|
-
return { ...acc, [curr.traceId]: [...acc[curr.traceId] || [], newCurr] };
|
|
4999
|
-
}, {});
|
|
5000
|
-
const tracesData = Object.entries(groupedTraces).map(([key, value]) => {
|
|
5001
|
-
const parentSpan = value.find((span) => !span.parentSpanId || !listOfSpanIds.has(span.parentSpanId));
|
|
5002
|
-
const enrichedSpans = value.map((span) => ({
|
|
5003
|
-
...span,
|
|
5004
|
-
parentSpanId: parentSpan?.id === span.id ? null : span?.parentSpanId,
|
|
5005
|
-
relativePercentage: parentSpan ? span.duration / parentSpan.duration : 0
|
|
5006
|
-
}));
|
|
5007
|
-
const failedStatus = value.find((span) => span.status.code !== 0)?.status;
|
|
5008
|
-
return {
|
|
5009
|
-
traceId: key,
|
|
5010
|
-
serviceName: parentSpan?.name || key,
|
|
5011
|
-
duration: parentSpan?.duration || value.reduce((acc, curr) => acc + curr.duration, 0),
|
|
5012
|
-
status: failedStatus || parentSpan?.status || value[0].status,
|
|
5013
|
-
started: value[0].startTime,
|
|
5014
|
-
trace: enrichedSpans
|
|
5015
|
-
};
|
|
5016
|
-
});
|
|
5017
|
-
return tracesData;
|
|
5018
|
-
};
|
|
5019
|
-
|
|
5020
|
-
const useTraces = (componentName, baseUrl, isWorkflow = false) => {
|
|
5021
|
-
const [traces, setTraces] = useState([]);
|
|
5022
|
-
const { setTraces: setTraceContextTraces } = useContext(TraceContext);
|
|
5023
|
-
const client = useMemo(() => createMastraClient(baseUrl), [baseUrl]);
|
|
5024
|
-
const fetchFn = useCallback(async () => {
|
|
5025
|
-
try {
|
|
5026
|
-
const res = await client.getTelemetry({
|
|
5027
|
-
attribute: {
|
|
5028
|
-
componentName
|
|
5029
|
-
}
|
|
5030
|
-
});
|
|
5031
|
-
if (!res.traces) {
|
|
5032
|
-
throw new Error("Error fetching traces");
|
|
5033
|
-
}
|
|
5034
|
-
const refinedTraces = refineTraces(res?.traces || [], isWorkflow);
|
|
5035
|
-
return refinedTraces;
|
|
5036
|
-
} catch (error2) {
|
|
5037
|
-
throw error2;
|
|
5038
|
-
}
|
|
5039
|
-
}, [client, componentName, isWorkflow]);
|
|
5040
|
-
const onSuccess = useCallback(
|
|
5041
|
-
(newTraces) => {
|
|
5042
|
-
if (newTraces.length > 0) {
|
|
5043
|
-
setTraces(() => newTraces);
|
|
5044
|
-
setTraceContextTraces(() => newTraces);
|
|
5045
|
-
}
|
|
5046
|
-
},
|
|
5047
|
-
[setTraceContextTraces]
|
|
5048
|
-
);
|
|
5049
|
-
const onError = useCallback((error2) => {
|
|
5050
|
-
toast.error(error2.message);
|
|
5051
|
-
}, []);
|
|
5052
|
-
const shouldContinue = useCallback(() => {
|
|
5053
|
-
return true;
|
|
5054
|
-
}, []);
|
|
5055
|
-
const { firstCallLoading, error } = usePolling({
|
|
5056
|
-
fetchFn,
|
|
5057
|
-
interval: 3e3,
|
|
5058
|
-
onSuccess,
|
|
5059
|
-
onError,
|
|
5060
|
-
shouldContinue,
|
|
5061
|
-
enabled: true
|
|
5062
|
-
});
|
|
5063
|
-
return { traces, firstCallLoading, error };
|
|
5064
|
-
};
|
|
5065
|
-
|
|
5066
4853
|
const rowSize = {
|
|
5067
4854
|
default: "[&>tbody>tr]:h-table-row",
|
|
5068
4855
|
small: "[&>tbody>tr]:h-table-row-small"
|
|
@@ -5184,6 +4971,10 @@ const useOpenTrace = () => {
|
|
|
5184
4971
|
return { openTrace };
|
|
5185
4972
|
};
|
|
5186
4973
|
|
|
4974
|
+
const toSigFigs = (num, sigFigs) => {
|
|
4975
|
+
return Number(num.toPrecision(sigFigs));
|
|
4976
|
+
};
|
|
4977
|
+
|
|
5187
4978
|
const TracesTableSkeleton = ({ colsCount }) => {
|
|
5188
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)) }) });
|
|
5189
4980
|
};
|
|
@@ -5202,7 +4993,7 @@ const TraceRow = ({ trace, index, isActive }) => {
|
|
|
5202
4993
|
trace.traceId.substring(0, 7),
|
|
5203
4994
|
"..."
|
|
5204
4995
|
] }),
|
|
5205
|
-
/* @__PURE__ */ jsx(UnitCell, { unit: "ms", children:
|
|
4996
|
+
/* @__PURE__ */ jsx(UnitCell, { unit: "ms", children: toSigFigs(trace.duration / 1e3, 3) }),
|
|
5206
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 }) }) }),
|
|
5207
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" }) })
|
|
5208
4999
|
] });
|
|
@@ -5339,11 +5130,12 @@ const variantClasses = {
|
|
|
5339
5130
|
};
|
|
5340
5131
|
const Time = ({ durationMs, tokenCount, variant, progressPercent }) => {
|
|
5341
5132
|
const variantClass = variant ? variantClasses[variant] : "bg-accent3";
|
|
5133
|
+
const percent = Math.min(100, progressPercent);
|
|
5342
5134
|
return /* @__PURE__ */ jsxs("div", { className: "w-[80px] xl:w-[166px] shrink-0", children: [
|
|
5343
|
-
/* @__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}%` } }) }),
|
|
5344
5136
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 pt-0.5", children: [
|
|
5345
5137
|
/* @__PURE__ */ jsxs(Txt, { variant: "ui-sm", className: "text-icon2 font-medium", children: [
|
|
5346
|
-
|
|
5138
|
+
toSigFigs(durationMs, 3),
|
|
5347
5139
|
"ms"
|
|
5348
5140
|
] }),
|
|
5349
5141
|
tokenCount && /* @__PURE__ */ jsxs(Txt, { variant: "ui-sm", className: "text-icon2 font-medium", children: [
|
|
@@ -5578,6 +5370,76 @@ const SyntaxHighlighter = ({ data }) => {
|
|
|
5578
5370
|
return /* @__PURE__ */ jsx("div", { className: "rounded-md bg-[#1a1a1a] p-1 font-mono", children: /* @__PURE__ */ jsx(CodeMirror, { value: formattedCode, theme, extensions: [jsonLanguage] }) });
|
|
5579
5371
|
};
|
|
5580
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
|
+
|
|
5581
5443
|
function SpanDetail() {
|
|
5582
5444
|
const { span, setSpan, trace, setIsOpen } = useContext(TraceContext);
|
|
5583
5445
|
if (!span || !trace) return null;
|
|
@@ -5613,11 +5475,11 @@ function SpanDetail() {
|
|
|
5613
5475
|
span.name
|
|
5614
5476
|
] }),
|
|
5615
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: [
|
|
5616
|
-
|
|
5478
|
+
toSigFigs(span.duration / 1e3, 3),
|
|
5617
5479
|
"ms"
|
|
5618
5480
|
] }) : /* @__PURE__ */ jsxs(Badge$1, { variant: "error", icon: /* @__PURE__ */ jsx(X, {}), children: [
|
|
5619
5481
|
"Failed in ",
|
|
5620
|
-
|
|
5482
|
+
toSigFigs(span.duration / 1e3, 3),
|
|
5621
5483
|
"ms"
|
|
5622
5484
|
] }) }),
|
|
5623
5485
|
/* @__PURE__ */ jsx("hr", { className: "border-border1 border-sm my-5" }),
|
|
@@ -5703,15 +5565,14 @@ const TracesSidebar = ({ onResize }) => {
|
|
|
5703
5565
|
);
|
|
5704
5566
|
};
|
|
5705
5567
|
|
|
5706
|
-
function AgentTraces({
|
|
5707
|
-
return /* @__PURE__ */ jsx(
|
|
5568
|
+
function AgentTraces({ className, traces, isLoading, error }) {
|
|
5569
|
+
return /* @__PURE__ */ jsx(AgentTracesInner, { className, traces, isLoading, error });
|
|
5708
5570
|
}
|
|
5709
|
-
function AgentTracesInner({
|
|
5571
|
+
function AgentTracesInner({ className, traces, isLoading, error }) {
|
|
5710
5572
|
const [sidebarWidth, setSidebarWidth] = useState(100);
|
|
5711
|
-
const { traces, firstCallLoading, error } = useTraces(agentName, baseUrl);
|
|
5712
5573
|
const { isOpen: open } = useContext(TraceContext);
|
|
5713
5574
|
return /* @__PURE__ */ jsxs("div", { className: clsx("h-full relative overflow-hidden flex", className), children: [
|
|
5714
|
-
/* @__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 }) }),
|
|
5715
5576
|
open && /* @__PURE__ */ jsx(TracesSidebar, { width: sidebarWidth, onResize: setSidebarWidth })
|
|
5716
5577
|
] });
|
|
5717
5578
|
}
|
|
@@ -6163,15 +6024,14 @@ const NetworkChat = ({ agentId, memory }) => {
|
|
|
6163
6024
|
return /* @__PURE__ */ jsx(MastraNetworkRuntimeProvider, { agentId, memory, modelSettings, children: /* @__PURE__ */ jsx("div", { className: "h-full pb-4", children: /* @__PURE__ */ jsx(Thread, { ToolFallback }) }) });
|
|
6164
6025
|
};
|
|
6165
6026
|
|
|
6166
|
-
function WorkflowTraces({
|
|
6167
|
-
return /* @__PURE__ */ jsx(
|
|
6027
|
+
function WorkflowTraces({ traces, isLoading, error }) {
|
|
6028
|
+
return /* @__PURE__ */ jsx(WorkflowTracesInner, { traces, isLoading, error });
|
|
6168
6029
|
}
|
|
6169
|
-
function WorkflowTracesInner({
|
|
6030
|
+
function WorkflowTracesInner({ traces, isLoading, error }) {
|
|
6170
6031
|
const [sidebarWidth, setSidebarWidth] = useState(100);
|
|
6171
|
-
const { traces, error, firstCallLoading } = useTraces(workflowName, baseUrl, true);
|
|
6172
6032
|
const { isOpen: open } = useContext(TraceContext);
|
|
6173
6033
|
return /* @__PURE__ */ jsxs("main", { className: "h-full relative overflow-hidden flex", children: [
|
|
6174
|
-
/* @__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 }) }),
|
|
6175
6035
|
open && /* @__PURE__ */ jsx(TracesSidebar, { width: sidebarWidth, onResize: setSidebarWidth })
|
|
6176
6036
|
] });
|
|
6177
6037
|
}
|
|
@@ -8198,6 +8058,12 @@ class CustomZodProvider extends ZodProvider {
|
|
|
8198
8058
|
}
|
|
8199
8059
|
}
|
|
8200
8060
|
|
|
8061
|
+
function isEmptyZodObject(schema) {
|
|
8062
|
+
if (schema instanceof ZodObject) {
|
|
8063
|
+
return Object.keys(schema.shape).length === 0;
|
|
8064
|
+
}
|
|
8065
|
+
return false;
|
|
8066
|
+
}
|
|
8201
8067
|
function DynamicForm({
|
|
8202
8068
|
schema,
|
|
8203
8069
|
onSubmit,
|
|
@@ -8210,6 +8076,9 @@ function DynamicForm({
|
|
|
8210
8076
|
return null;
|
|
8211
8077
|
}
|
|
8212
8078
|
const normalizedSchema = (schema2) => {
|
|
8079
|
+
if (isEmptyZodObject(schema2)) {
|
|
8080
|
+
return z$1.object({});
|
|
8081
|
+
}
|
|
8213
8082
|
return z$1.object({
|
|
8214
8083
|
"": schema2
|
|
8215
8084
|
});
|
|
@@ -8218,7 +8087,7 @@ function DynamicForm({
|
|
|
8218
8087
|
const formProps = {
|
|
8219
8088
|
schema: schemaProvider,
|
|
8220
8089
|
onSubmit: async (values) => {
|
|
8221
|
-
await onSubmit(values[""]);
|
|
8090
|
+
await onSubmit(values?.[""] || {});
|
|
8222
8091
|
},
|
|
8223
8092
|
defaultValues: defaultValues ? { "": defaultValues } : void 0,
|
|
8224
8093
|
formProps: {
|
|
@@ -8900,5 +8769,159 @@ const DarkLogo = (props) => /* @__PURE__ */ jsxs("svg", { width: "100", height:
|
|
|
8900
8769
|
)
|
|
8901
8770
|
] });
|
|
8902
8771
|
|
|
8903
|
-
|
|
8772
|
+
function usePolling({
|
|
8773
|
+
fetchFn,
|
|
8774
|
+
interval = 3e3,
|
|
8775
|
+
enabled = false,
|
|
8776
|
+
onSuccess,
|
|
8777
|
+
onError,
|
|
8778
|
+
shouldContinue = () => true,
|
|
8779
|
+
restartPolling = false
|
|
8780
|
+
}) {
|
|
8781
|
+
const [isPolling, setIsPolling] = useState(enabled);
|
|
8782
|
+
const [error, setError] = useState(null);
|
|
8783
|
+
const [data, setData] = useState(null);
|
|
8784
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
8785
|
+
const [firstCallLoading, setFirstCallLoading] = useState(false);
|
|
8786
|
+
const timeoutRef = useRef(null);
|
|
8787
|
+
const mountedRef = useRef(true);
|
|
8788
|
+
const [restart, setRestart] = useState(restartPolling);
|
|
8789
|
+
const cleanup = useCallback(() => {
|
|
8790
|
+
console.log("cleanup");
|
|
8791
|
+
if (timeoutRef.current) {
|
|
8792
|
+
clearTimeout(timeoutRef.current);
|
|
8793
|
+
timeoutRef.current = null;
|
|
8794
|
+
}
|
|
8795
|
+
}, []);
|
|
8796
|
+
const stopPolling = useCallback(() => {
|
|
8797
|
+
console.log("stopPolling");
|
|
8798
|
+
setIsPolling(false);
|
|
8799
|
+
cleanup();
|
|
8800
|
+
}, [cleanup]);
|
|
8801
|
+
const startPolling = useCallback(() => {
|
|
8802
|
+
console.log("startPolling");
|
|
8803
|
+
setIsPolling(true);
|
|
8804
|
+
setError(null);
|
|
8805
|
+
}, []);
|
|
8806
|
+
const executePoll = useCallback(
|
|
8807
|
+
async (refetch2 = true) => {
|
|
8808
|
+
if (!mountedRef.current) return;
|
|
8809
|
+
setIsLoading(true);
|
|
8810
|
+
try {
|
|
8811
|
+
const result = await fetchFn();
|
|
8812
|
+
setData(result);
|
|
8813
|
+
setError(null);
|
|
8814
|
+
onSuccess?.(result);
|
|
8815
|
+
if (shouldContinue(result) && refetch2) {
|
|
8816
|
+
timeoutRef.current = setTimeout(executePoll, interval);
|
|
8817
|
+
} else {
|
|
8818
|
+
stopPolling();
|
|
8819
|
+
}
|
|
8820
|
+
} catch (err) {
|
|
8821
|
+
if (!mountedRef.current) return;
|
|
8822
|
+
setError(err);
|
|
8823
|
+
onError?.(err);
|
|
8824
|
+
stopPolling();
|
|
8825
|
+
} finally {
|
|
8826
|
+
if (mountedRef.current) {
|
|
8827
|
+
setFirstCallLoading(false);
|
|
8828
|
+
setIsLoading(false);
|
|
8829
|
+
}
|
|
8830
|
+
}
|
|
8831
|
+
},
|
|
8832
|
+
[fetchFn, interval, onSuccess, onError, shouldContinue, stopPolling]
|
|
8833
|
+
);
|
|
8834
|
+
const refetch = useCallback(
|
|
8835
|
+
(withPolling = false) => {
|
|
8836
|
+
console.log("refetch", { withPolling });
|
|
8837
|
+
if (withPolling) {
|
|
8838
|
+
setIsPolling(true);
|
|
8839
|
+
} else {
|
|
8840
|
+
executePoll(false);
|
|
8841
|
+
}
|
|
8842
|
+
setError(null);
|
|
8843
|
+
},
|
|
8844
|
+
[executePoll]
|
|
8845
|
+
);
|
|
8846
|
+
useEffect(() => {
|
|
8847
|
+
mountedRef.current = true;
|
|
8848
|
+
if (enabled && isPolling) {
|
|
8849
|
+
executePoll(true);
|
|
8850
|
+
}
|
|
8851
|
+
return () => {
|
|
8852
|
+
console.log("cleanup poll");
|
|
8853
|
+
mountedRef.current = false;
|
|
8854
|
+
cleanup();
|
|
8855
|
+
};
|
|
8856
|
+
}, [enabled, isPolling, executePoll, cleanup]);
|
|
8857
|
+
useEffect(() => {
|
|
8858
|
+
setRestart(restartPolling);
|
|
8859
|
+
}, [restartPolling]);
|
|
8860
|
+
useEffect(() => {
|
|
8861
|
+
if (restart && !isPolling) {
|
|
8862
|
+
setIsPolling(true);
|
|
8863
|
+
executePoll();
|
|
8864
|
+
setRestart(false);
|
|
8865
|
+
}
|
|
8866
|
+
}, [restart]);
|
|
8867
|
+
return {
|
|
8868
|
+
isPolling,
|
|
8869
|
+
isLoading,
|
|
8870
|
+
error,
|
|
8871
|
+
data,
|
|
8872
|
+
startPolling,
|
|
8873
|
+
stopPolling,
|
|
8874
|
+
firstCallLoading,
|
|
8875
|
+
refetch
|
|
8876
|
+
};
|
|
8877
|
+
}
|
|
8878
|
+
|
|
8879
|
+
const useTraces = (componentName, baseUrl, isWorkflow = false) => {
|
|
8880
|
+
const [traces, setTraces] = useState([]);
|
|
8881
|
+
const { setTraces: setTraceContextTraces } = useContext(TraceContext);
|
|
8882
|
+
const client = useMemo(() => createMastraClient(baseUrl), [baseUrl]);
|
|
8883
|
+
const fetchFn = useCallback(async () => {
|
|
8884
|
+
try {
|
|
8885
|
+
const res = await client.getTelemetry({
|
|
8886
|
+
attribute: {
|
|
8887
|
+
componentName
|
|
8888
|
+
}
|
|
8889
|
+
});
|
|
8890
|
+
if (!res.traces) {
|
|
8891
|
+
throw new Error("Error fetching traces");
|
|
8892
|
+
}
|
|
8893
|
+
const refinedTraces = refineTraces(res?.traces || [], isWorkflow);
|
|
8894
|
+
return refinedTraces;
|
|
8895
|
+
} catch (error2) {
|
|
8896
|
+
throw error2;
|
|
8897
|
+
}
|
|
8898
|
+
}, [client, componentName, isWorkflow]);
|
|
8899
|
+
const onSuccess = useCallback(
|
|
8900
|
+
(newTraces) => {
|
|
8901
|
+
if (newTraces.length > 0) {
|
|
8902
|
+
setTraces(() => newTraces);
|
|
8903
|
+
setTraceContextTraces(() => newTraces);
|
|
8904
|
+
}
|
|
8905
|
+
},
|
|
8906
|
+
[setTraceContextTraces]
|
|
8907
|
+
);
|
|
8908
|
+
const onError = useCallback((error2) => {
|
|
8909
|
+
console.log(`error, onError`, error2);
|
|
8910
|
+
toast.error(error2.message);
|
|
8911
|
+
}, []);
|
|
8912
|
+
const shouldContinue = useCallback(() => {
|
|
8913
|
+
return true;
|
|
8914
|
+
}, []);
|
|
8915
|
+
const { firstCallLoading, error } = usePolling({
|
|
8916
|
+
fetchFn,
|
|
8917
|
+
interval: 3e3,
|
|
8918
|
+
onSuccess,
|
|
8919
|
+
onError,
|
|
8920
|
+
shouldContinue,
|
|
8921
|
+
enabled: true
|
|
8922
|
+
});
|
|
8923
|
+
return { traces, firstCallLoading, error };
|
|
8924
|
+
};
|
|
8925
|
+
|
|
8926
|
+
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, ToolsIcon, TraceContext, TraceIcon, TraceProvider, TsIcon, Txt, TxtCell, UnitCell, VNextWorkflowGraph, VNextWorkflowTrigger, VariablesIcon, WorkflowCoinIcon, WorkflowGraph, WorkflowIcon, WorkflowRunContext, WorkflowRunProvider, WorkflowTraces, WorkflowTrigger, refineTraces, useTraces };
|
|
8904
8927
|
//# sourceMappingURL=index.es.js.map
|