@mastra/playground-ui 6.7.1 → 6.7.2-alpha.1
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/CHANGELOG.md +26 -0
- package/dist/index.cjs.js +2758 -996
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +2754 -1004
- package/dist/index.es.js.map +1 -1
- package/dist/src/components/ui/autoform/components/CustomArrayField.d.ts +6 -0
- package/dist/src/components/ui/autoform/components/CustomAutoFormField.d.ts +6 -0
- package/dist/src/components/ui/autoform/components/CustomObjectField.d.ts +6 -0
- package/dist/src/components/ui/autoform/components/DiscriminatedUnionField.d.ts +2 -0
- package/dist/src/components/ui/autoform/components/UnionField.d.ts +2 -0
- package/dist/src/components/ui/autoform/utils.d.ts +1 -0
- package/dist/src/components/ui/autoform/zodProvider/default-values.d.ts +3 -0
- package/dist/src/components/ui/autoform/zodProvider/index.d.ts +1 -0
- package/dist/src/components/ui/code-mirror-block.d.ts +2 -0
- package/dist/src/components/ui/copy-button.d.ts +4 -1
- package/dist/src/components/ui/elements/main-sidebar/main-sidebar-nav-link.d.ts +1 -0
- package/dist/src/domains/agents/components/AgentToolPanel.d.ts +5 -0
- package/dist/src/domains/agents/components/agent-information/agent-information.d.ts +5 -0
- package/dist/src/domains/agents/components/agent-information/agent-instructions-enhancer.d.ts +5 -0
- package/dist/src/domains/agents/components/agent-information/agent-memory-config.d.ts +5 -0
- package/dist/src/domains/agents/components/agent-information/agent-memory.d.ts +6 -0
- package/dist/src/domains/agents/components/agent-information/agent-working-memory.d.ts +5 -0
- package/dist/src/domains/agents/components/agent-information/code-display.d.ts +10 -0
- package/dist/src/domains/agents/components/agent-information/current-instructions.d.ts +15 -0
- package/dist/src/domains/agents/components/agent-information/version-actions.d.ts +8 -0
- package/dist/src/domains/agents/components/agent-information/version-history-dialog.d.ts +9 -0
- package/dist/src/domains/agents/components/agent-information/version-history.d.ts +10 -0
- package/dist/src/domains/agents/components/agent-information/version-item.d.ts +14 -0
- package/dist/src/domains/agents/hooks/use-prompt-enhancer.d.ts +19 -0
- package/dist/src/domains/agents/hooks/use-prompt-versions.d.ts +12 -0
- package/dist/src/domains/agents/index.d.ts +2 -0
- package/dist/src/domains/mcps/components/MCPDetail.d.ts +12 -0
- package/dist/src/domains/mcps/components/MCPToolPanel.d.ts +5 -0
- package/dist/src/domains/mcps/hooks/index.d.ts +3 -0
- package/dist/src/domains/mcps/hooks/use-mcp-server-tool.d.ts +2 -0
- package/dist/src/domains/mcps/hooks/use-mcp-servers.d.ts +1 -0
- package/dist/src/domains/mcps/index.d.ts +3 -1
- package/dist/src/domains/tools/components/ToolExecutor.d.ts +14 -0
- package/dist/src/domains/tools/components/ToolIcon.d.ts +5 -0
- package/dist/src/domains/tools/components/ToolInformation.d.ts +7 -0
- package/dist/src/domains/tools/components/ToolPanel.d.ts +4 -0
- package/dist/src/domains/tools/components/index.d.ts +4 -0
- package/dist/src/domains/tools/hooks/index.d.ts +1 -0
- package/dist/src/domains/tools/hooks/use-all-tools.d.ts +2 -0
- package/dist/src/domains/tools/index.d.ts +1 -0
- package/dist/src/lib/framework.d.ts +2 -1
- package/package.json +6 -6
package/dist/index.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { useMessagePart, useMessage, MessagePrimitive, ActionBarPrimitive, useAttachment, AttachmentPrimitive, useComposerRuntime, ComposerPrimitive, useComposer, ThreadPrimitive, CompositeAttachmentAdapter, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, WebSpeechSynthesisAdapter, useExternalStoreRuntime, AssistantRuntimeProvider } from '@assistant-ui/react';
|
|
3
|
-
import { CheckIcon as CheckIcon$1, CopyIcon, AlertCircle, TriangleAlert,
|
|
3
|
+
import { CheckIcon as CheckIcon$1, CopyIcon, AlertCircle, TriangleAlert, ChevronUpIcon, X, Share2, Check, Braces, Loader2, Network, ChevronDown, PauseIcon, HourglassIcon, CircleDashed, Footprints, CircleCheck, CircleX, Minus, Plus, Maximize, Workflow, AlertCircleIcon, ChevronDownIcon, CirclePause, CalendarIcon, Brackets, PlusIcon, TrashIcon, Circle, StopCircle, SearchIcon, BrainIcon, AudioLinesIcon, StopCircleIcon, FileText, CircleXIcon, Link, CloudUpload, Mic, ArrowUp, Copy, Search, RefreshCcwIcon, ChevronRight, SortAsc, SortDesc, SaveIcon, RefreshCw, ExternalLink, InfoIcon as InfoIcon$1, TriangleAlertIcon, ChevronRightIcon, ArrowLeftIcon, ArrowRightIcon, ChevronsRightIcon, AlignLeftIcon, AlignJustifyIcon, ArrowUpIcon, ArrowDownIcon, CircleAlertIcon, XIcon, PanelRightIcon, GaugeIcon, EyeIcon, ChevronsLeftRightEllipsisIcon, CalculatorIcon, HashIcon, FileInputIcon, FileOutputIcon, ReceiptText, Info, RotateCcw, GripVertical, AlertTriangleIcon, FileClock, Loader, Wand2, Play, Trash2, NetworkIcon, WorkflowIcon as WorkflowIcon$1, PackageIcon, GitBranchIcon, PackageOpenIcon, OctagonXIcon, FrownIcon, ChevronUp, ChevronsLeftRight, TimerIcon, ChevronsLeftRightIcon, ChevronFirstIcon, ChevronLastIcon, ArrowRightToLineIcon, CoinsIcon, BracesIcon, CircleGaugeIcon, PanelTopIcon, ListTreeIcon, PanelLeftIcon, CircleSlash, Clock as Clock$1 } from 'lucide-react';
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import React__default, { forwardRef, memo, useState, useEffect, useRef, useCallback, useMemo, createContext, useContext, Fragment as Fragment$1, useId } from 'react';
|
|
5
|
+
import React__default, { forwardRef, memo, useState, useEffect, useRef, useCallback, useMemo, createContext, useContext, Fragment as Fragment$1, useId, Suspense } from 'react';
|
|
6
6
|
import { Slot } from '@radix-ui/react-slot';
|
|
7
7
|
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
8
8
|
import { TooltipProvider as TooltipProvider$1 } from '@radix-ui/react-tooltip';
|
|
@@ -24,18 +24,17 @@ import Dagre from '@dagrejs/dagre';
|
|
|
24
24
|
import { Highlight, themes } from 'prism-react-renderer';
|
|
25
25
|
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
|
|
26
26
|
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
27
|
-
import { I as IconColors } from './colors-Br49332d.js';
|
|
28
27
|
import prettier from 'prettier';
|
|
29
28
|
import prettierPluginBabel from 'prettier/plugins/babel';
|
|
30
29
|
import prettierPluginEstree from 'prettier/plugins/estree';
|
|
31
30
|
import * as SliderPrimitive from '@radix-ui/react-slider';
|
|
32
31
|
import jsonSchemaToZod from 'json-schema-to-zod';
|
|
33
32
|
import { parse } from 'superjson';
|
|
34
|
-
import z$
|
|
35
|
-
import { CodeBlock } from 'react-code-block';
|
|
33
|
+
import z$3, { z, ZodObject, ZodIntersection } from 'zod';
|
|
34
|
+
import { CodeBlock as CodeBlock$1 } from 'react-code-block';
|
|
36
35
|
import { create } from 'zustand';
|
|
37
36
|
import { persist } from 'zustand/middleware';
|
|
38
|
-
import { AutoForm as AutoForm$1, buildZodFieldConfig } from '@autoform/react';
|
|
37
|
+
import { useAutoForm, getPathInObject, AutoForm as AutoForm$1, buildZodFieldConfig } from '@autoform/react';
|
|
39
38
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
40
39
|
import { format, isValid, formatDistanceToNow, formatDate, isToday } from 'date-fns';
|
|
41
40
|
import { useDebouncedCallback } from 'use-debounce';
|
|
@@ -43,15 +42,19 @@ import { DayPicker } from 'react-day-picker';
|
|
|
43
42
|
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
44
43
|
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
45
44
|
import { v4 } from '@lukeed/uuid';
|
|
45
|
+
import { useFormContext, useFieldArray } from 'react-hook-form';
|
|
46
|
+
import { getLabel } from '@autoform/core';
|
|
46
47
|
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
47
|
-
import { ZodProvider, getFieldConfigInZodStack
|
|
48
|
+
import { ZodProvider, getFieldConfigInZodStack } from '@autoform/zod/v4';
|
|
48
49
|
import { z as z$1 } from 'zod/v3';
|
|
50
|
+
import z$2 from 'zod/v4';
|
|
49
51
|
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
|
50
52
|
import { useMastraClient, mapWorkflowStreamChunkToWatchResult, resolveToChildMessages, useChat, toAssistantUIMessage } from '@mastra/react';
|
|
51
53
|
import { useQuery, useMutation, useQueryClient, QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
52
54
|
import './index.css';export * from '@tanstack/react-query';
|
|
53
55
|
import { useReactTable, getCoreRowModel, flexRender } from '@tanstack/react-table';
|
|
54
56
|
import { RuntimeContext as RuntimeContext$1 } from '@mastra/core/runtime-context';
|
|
57
|
+
import { I as IconColors } from './colors-Br49332d.js';
|
|
55
58
|
import Markdown from 'react-markdown';
|
|
56
59
|
import { useShallow } from 'zustand/shallow';
|
|
57
60
|
import { RuntimeContext as RuntimeContext$2 } from '@mastra/core/di';
|
|
@@ -4312,25 +4315,20 @@ function useCopyToClipboard({ text, copyMessage = "Copied to clipboard!" }) {
|
|
|
4312
4315
|
return { isCopied, handleCopy };
|
|
4313
4316
|
}
|
|
4314
4317
|
|
|
4315
|
-
function CopyButton({
|
|
4316
|
-
|
|
4318
|
+
function CopyButton({
|
|
4319
|
+
content,
|
|
4320
|
+
copyMessage,
|
|
4321
|
+
tooltip = "Copy to clipboard",
|
|
4322
|
+
iconSize = "default"
|
|
4323
|
+
}) {
|
|
4324
|
+
const { handleCopy } = useCopyToClipboard({
|
|
4317
4325
|
text: content,
|
|
4318
4326
|
copyMessage
|
|
4319
4327
|
});
|
|
4320
|
-
return /* @__PURE__ */ jsxs(
|
|
4321
|
-
|
|
4322
|
-
{
|
|
4323
|
-
|
|
4324
|
-
size: "icon",
|
|
4325
|
-
className: cn("relative h-6 w-6", className),
|
|
4326
|
-
"aria-label": "Copy to clipboard",
|
|
4327
|
-
onClick: handleCopy,
|
|
4328
|
-
children: [
|
|
4329
|
-
/* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsx(Check, { className: cn("h-4 w-4 transition-transform ease-in-out", isCopied ? "scale-100" : "scale-0") }) }),
|
|
4330
|
-
/* @__PURE__ */ jsx(Copy, { className: cn("h-4 w-4 transition-transform ease-in-out", isCopied ? "scale-0" : "scale-100") })
|
|
4331
|
-
]
|
|
4332
|
-
}
|
|
4333
|
-
);
|
|
4328
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
4329
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx("button", { onClick: handleCopy, type: "button", children: /* @__PURE__ */ jsx(Icon, { className: "transition-colors hover:bg-surface4 rounded-lg text-icon3 hover:text-icon6", size: iconSize, children: /* @__PURE__ */ jsx(CopyIcon, {}) }) }) }),
|
|
4330
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: tooltip })
|
|
4331
|
+
] });
|
|
4334
4332
|
}
|
|
4335
4333
|
|
|
4336
4334
|
const useCodemirrorTheme$2 = () => {
|
|
@@ -4361,6 +4359,19 @@ const SyntaxHighlighter$2 = ({
|
|
|
4361
4359
|
/* @__PURE__ */ jsx(CodeMirror, { value: formattedCode, theme, extensions: [jsonLanguage] })
|
|
4362
4360
|
] });
|
|
4363
4361
|
};
|
|
4362
|
+
async function highlight(code, language) {
|
|
4363
|
+
const { codeToTokens, bundledLanguages } = await import('shiki');
|
|
4364
|
+
if (!(language in bundledLanguages)) return null;
|
|
4365
|
+
const { tokens } = await codeToTokens(code, {
|
|
4366
|
+
lang: language,
|
|
4367
|
+
defaultColor: false,
|
|
4368
|
+
themes: {
|
|
4369
|
+
light: "github-light",
|
|
4370
|
+
dark: "github-dark"
|
|
4371
|
+
}
|
|
4372
|
+
});
|
|
4373
|
+
return tokens;
|
|
4374
|
+
}
|
|
4364
4375
|
|
|
4365
4376
|
const variantClasses$2 = {
|
|
4366
4377
|
default: "text-icon3",
|
|
@@ -5253,7 +5264,7 @@ const useCodemirrorTheme$1 = () => {
|
|
|
5253
5264
|
fontSize: "0.8rem",
|
|
5254
5265
|
lineHighlight: "transparent",
|
|
5255
5266
|
gutterBackground: "transparent",
|
|
5256
|
-
gutterForeground:
|
|
5267
|
+
gutterForeground: "#939393",
|
|
5257
5268
|
background: "transparent"
|
|
5258
5269
|
},
|
|
5259
5270
|
styles: [{ tag: [tags.className, tags.propertyName] }]
|
|
@@ -6117,15 +6128,15 @@ function CodeBlockDemo({
|
|
|
6117
6128
|
filename,
|
|
6118
6129
|
className
|
|
6119
6130
|
}) {
|
|
6120
|
-
return /* @__PURE__ */ jsxs(CodeBlock, { code, language, theme: themes.oneDark, children: [
|
|
6131
|
+
return /* @__PURE__ */ jsxs(CodeBlock$1, { code, language, theme: themes.oneDark, children: [
|
|
6121
6132
|
filename ? /* @__PURE__ */ jsx("div", { className: "absolute w-full px-6 py-2 pl-4 text-sm rounded bg-mastra-bg-2 text-mastra-el-6/50", children: filename }) : null,
|
|
6122
6133
|
/* @__PURE__ */ jsx(
|
|
6123
|
-
CodeBlock.Code,
|
|
6134
|
+
CodeBlock$1.Code,
|
|
6124
6135
|
{
|
|
6125
6136
|
className: cn("bg-transparent h-full p-6 rounded-xl whitespace-pre-wrap", filename ? "pt-10" : "", className),
|
|
6126
6137
|
children: /* @__PURE__ */ jsx("div", { className: "table-row", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center", children: [
|
|
6127
|
-
/* @__PURE__ */ jsx(CodeBlock.LineNumber, { className: "table-cell pr-4 text-sm text-right select-none text-gray-500/50" }),
|
|
6128
|
-
/* @__PURE__ */ jsx(CodeBlock.LineContent, { className: "flex", children: /* @__PURE__ */ jsx(CodeBlock.Token, { className: "font-mono text-sm mastra-token" }) })
|
|
6138
|
+
/* @__PURE__ */ jsx(CodeBlock$1.LineNumber, { className: "table-cell pr-4 text-sm text-right select-none text-gray-500/50" }),
|
|
6139
|
+
/* @__PURE__ */ jsx(CodeBlock$1.LineContent, { className: "flex", children: /* @__PURE__ */ jsx(CodeBlock$1.Token, { className: "font-mono text-sm mastra-token" }) })
|
|
6129
6140
|
] }) })
|
|
6130
6141
|
}
|
|
6131
6142
|
)
|
|
@@ -6834,6 +6845,145 @@ const RecordField = ({ inputProps, field, error, id }) => {
|
|
|
6834
6845
|
] });
|
|
6835
6846
|
};
|
|
6836
6847
|
|
|
6848
|
+
const CustomObjectField = ({ field, path }) => {
|
|
6849
|
+
const { uiComponents } = useAutoForm();
|
|
6850
|
+
return /* @__PURE__ */ jsx(uiComponents.ObjectWrapper, { label: getLabel(field), field, children: Object.entries(field.schema).map(([_key, subField]) => /* @__PURE__ */ jsx(
|
|
6851
|
+
CustomAutoFormField,
|
|
6852
|
+
{
|
|
6853
|
+
field: subField,
|
|
6854
|
+
path: [...path, subField.key]
|
|
6855
|
+
},
|
|
6856
|
+
`${path.join(".")}.${subField.key}`
|
|
6857
|
+
)) });
|
|
6858
|
+
};
|
|
6859
|
+
|
|
6860
|
+
const CustomArrayField = ({ field, path }) => {
|
|
6861
|
+
const { uiComponents } = useAutoForm();
|
|
6862
|
+
const { control } = useFormContext();
|
|
6863
|
+
const { fields, append, remove } = useFieldArray({
|
|
6864
|
+
control,
|
|
6865
|
+
name: path.join(".")
|
|
6866
|
+
});
|
|
6867
|
+
const subFieldType = field.schema?.[0]?.type;
|
|
6868
|
+
let defaultValue;
|
|
6869
|
+
if (subFieldType === "object") {
|
|
6870
|
+
defaultValue = {};
|
|
6871
|
+
} else if (subFieldType === "array") {
|
|
6872
|
+
defaultValue = [];
|
|
6873
|
+
} else {
|
|
6874
|
+
defaultValue = null;
|
|
6875
|
+
}
|
|
6876
|
+
return /* @__PURE__ */ jsx(uiComponents.ArrayWrapper, { label: getLabel(field), field, onAddItem: () => append(defaultValue), children: fields.map((item, index) => /* @__PURE__ */ jsx(uiComponents.ArrayElementWrapper, { onRemove: () => remove(index), index, children: /* @__PURE__ */ jsx(CustomAutoFormField, { field: field.schema[0], path: [...path, index.toString()] }) }, item.id)) });
|
|
6877
|
+
};
|
|
6878
|
+
|
|
6879
|
+
const CustomAutoFormField = ({ field, path }) => {
|
|
6880
|
+
const { formComponents, uiComponents } = useAutoForm();
|
|
6881
|
+
const {
|
|
6882
|
+
register,
|
|
6883
|
+
formState: { errors },
|
|
6884
|
+
getValues
|
|
6885
|
+
} = useFormContext();
|
|
6886
|
+
const fullPath = path.join(".");
|
|
6887
|
+
const error = getPathInObject(errors, path)?.message;
|
|
6888
|
+
const value = getValues(fullPath);
|
|
6889
|
+
const FieldWrapper = field.fieldConfig?.fieldWrapper || uiComponents.FieldWrapper;
|
|
6890
|
+
let FieldComponent = () => /* @__PURE__ */ jsx(
|
|
6891
|
+
uiComponents.ErrorMessage,
|
|
6892
|
+
{
|
|
6893
|
+
error: `[AutoForm Configuration Error] No component found for type "${field.type}" nor a fallback`
|
|
6894
|
+
}
|
|
6895
|
+
);
|
|
6896
|
+
if (field.type === "array") {
|
|
6897
|
+
FieldComponent = CustomArrayField;
|
|
6898
|
+
} else if (field.type === "object") {
|
|
6899
|
+
FieldComponent = CustomObjectField;
|
|
6900
|
+
} else if (field.type in formComponents) {
|
|
6901
|
+
FieldComponent = formComponents[field.type];
|
|
6902
|
+
} else if ("fallback" in formComponents) {
|
|
6903
|
+
FieldComponent = formComponents.fallback;
|
|
6904
|
+
}
|
|
6905
|
+
return /* @__PURE__ */ jsx(FieldWrapper, { label: getLabel(field), error, id: fullPath, field, children: /* @__PURE__ */ jsx(
|
|
6906
|
+
FieldComponent,
|
|
6907
|
+
{
|
|
6908
|
+
label: getLabel(field),
|
|
6909
|
+
field,
|
|
6910
|
+
value,
|
|
6911
|
+
error,
|
|
6912
|
+
id: fullPath,
|
|
6913
|
+
path,
|
|
6914
|
+
inputProps: {
|
|
6915
|
+
required: field.required,
|
|
6916
|
+
error,
|
|
6917
|
+
key: `${fullPath}-input`,
|
|
6918
|
+
...field.fieldConfig?.inputProps,
|
|
6919
|
+
...register(fullPath)
|
|
6920
|
+
}
|
|
6921
|
+
},
|
|
6922
|
+
fullPath
|
|
6923
|
+
) });
|
|
6924
|
+
};
|
|
6925
|
+
|
|
6926
|
+
const UnionField = ({ field, inputProps }) => {
|
|
6927
|
+
const path = inputProps.name?.split(".") ?? [];
|
|
6928
|
+
return field.schema?.map((schema, index) => {
|
|
6929
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
6930
|
+
/* @__PURE__ */ jsx(CustomAutoFormField, { field: schema, path }, path.join(".")),
|
|
6931
|
+
index < (field.schema?.length ?? 0) - 1 && /* @__PURE__ */ jsx(Txt, { variant: "ui-xs", className: "text-center", children: "OR" })
|
|
6932
|
+
] }, schema.key);
|
|
6933
|
+
});
|
|
6934
|
+
};
|
|
6935
|
+
|
|
6936
|
+
const DiscriminatedUnionField = ({ field, path }) => {
|
|
6937
|
+
const { watch } = useFormContext();
|
|
6938
|
+
const fullPath = path.join(".");
|
|
6939
|
+
const value = watch(fullPath);
|
|
6940
|
+
const allSchemas = field.schema?.flatMap((schema) => schema.schema || []) || [];
|
|
6941
|
+
const literalSchemas = allSchemas?.filter((schema) => schema.fieldConfig?.customData?.isLiteral) || [];
|
|
6942
|
+
const firstLiteralSchema = literalSchemas[0];
|
|
6943
|
+
const literalSchemaField = literalSchemas?.reduce(
|
|
6944
|
+
(acc, schema) => {
|
|
6945
|
+
const optionValues = (schema.fieldConfig?.customData?.literalValues ?? []).map(
|
|
6946
|
+
(value2) => [value2, value2]
|
|
6947
|
+
);
|
|
6948
|
+
acc.options?.push(...optionValues);
|
|
6949
|
+
return acc;
|
|
6950
|
+
},
|
|
6951
|
+
{
|
|
6952
|
+
key: firstLiteralSchema.key,
|
|
6953
|
+
required: firstLiteralSchema.required,
|
|
6954
|
+
type: "select",
|
|
6955
|
+
default: firstLiteralSchema.default,
|
|
6956
|
+
description: firstLiteralSchema.description,
|
|
6957
|
+
options: [],
|
|
6958
|
+
fieldConfig: firstLiteralSchema.fieldConfig
|
|
6959
|
+
}
|
|
6960
|
+
);
|
|
6961
|
+
const otherFieldSchemas = field.schema?.reduce(
|
|
6962
|
+
(acc, schema) => {
|
|
6963
|
+
const literalSchema = schema.schema?.find((schema2) => schema2.fieldConfig?.customData?.isLiteral);
|
|
6964
|
+
const literalSchemaValue = literalSchema?.fieldConfig?.customData?.literalValues?.[0];
|
|
6965
|
+
const otherSchemas = schema.schema?.filter((schema2) => schema2.key !== literalSchema?.key) ?? [];
|
|
6966
|
+
if (literalSchemaValue) {
|
|
6967
|
+
acc[literalSchemaValue] = otherSchemas;
|
|
6968
|
+
}
|
|
6969
|
+
return acc;
|
|
6970
|
+
},
|
|
6971
|
+
{}
|
|
6972
|
+
);
|
|
6973
|
+
const literalFieldValue = value?.[literalSchemaField.key];
|
|
6974
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
6975
|
+
/* @__PURE__ */ jsx(
|
|
6976
|
+
CustomAutoFormField,
|
|
6977
|
+
{
|
|
6978
|
+
field: literalSchemaField,
|
|
6979
|
+
path: [...path, literalSchemaField.key]
|
|
6980
|
+
},
|
|
6981
|
+
`${fullPath}.${literalSchemaField.key}`
|
|
6982
|
+
),
|
|
6983
|
+
literalFieldValue && otherFieldSchemas?.[literalFieldValue] && otherFieldSchemas[literalFieldValue].map((schema) => /* @__PURE__ */ jsx(CustomAutoFormField, { field: schema, path: [...path, schema.key] }, `${fullPath}.${schema.key}`))
|
|
6984
|
+
] }, field.key);
|
|
6985
|
+
};
|
|
6986
|
+
|
|
6837
6987
|
const ShadcnUIComponents = {
|
|
6838
6988
|
Form,
|
|
6839
6989
|
FieldWrapper,
|
|
@@ -6861,6 +7011,8 @@ function AutoForm({
|
|
|
6861
7011
|
date: (props2) => /* @__PURE__ */ jsx(DateField, { ...props2, inputProps: { ...props2.inputProps, readOnly } }),
|
|
6862
7012
|
select: (props2) => /* @__PURE__ */ jsx(SelectField$1, { ...props2, inputProps: { ...props2.inputProps, readOnly } }),
|
|
6863
7013
|
record: (props2) => /* @__PURE__ */ jsx(RecordField, { ...props2, inputProps: { ...props2.inputProps, readOnly } }),
|
|
7014
|
+
union: (props2) => /* @__PURE__ */ jsx(UnionField, { ...props2, inputProps: { ...props2.inputProps, readOnly } }),
|
|
7015
|
+
"discriminated-union": (props2) => /* @__PURE__ */ jsx(DiscriminatedUnionField, { ...props2, inputProps: { ...props2.inputProps, readOnly } }),
|
|
6864
7016
|
...formComponents
|
|
6865
7017
|
}
|
|
6866
7018
|
}
|
|
@@ -6868,6 +7020,39 @@ function AutoForm({
|
|
|
6868
7020
|
}
|
|
6869
7021
|
|
|
6870
7022
|
buildZodFieldConfig();
|
|
7023
|
+
function removeEmptyValues(values) {
|
|
7024
|
+
const result = {};
|
|
7025
|
+
for (const key in values) {
|
|
7026
|
+
const value = values[key];
|
|
7027
|
+
if ([null, void 0, "", [], {}].includes(value)) {
|
|
7028
|
+
continue;
|
|
7029
|
+
}
|
|
7030
|
+
if (Array.isArray(value)) {
|
|
7031
|
+
const newArray = value.map((item) => {
|
|
7032
|
+
if (typeof item === "object") {
|
|
7033
|
+
const cleanedItem = removeEmptyValues(item);
|
|
7034
|
+
if (Object.keys(cleanedItem).length > 0) {
|
|
7035
|
+
return cleanedItem;
|
|
7036
|
+
}
|
|
7037
|
+
return null;
|
|
7038
|
+
}
|
|
7039
|
+
return item;
|
|
7040
|
+
});
|
|
7041
|
+
const filteredArray = newArray.filter((item) => item !== null);
|
|
7042
|
+
if (filteredArray.length > 0) {
|
|
7043
|
+
result[key] = filteredArray;
|
|
7044
|
+
}
|
|
7045
|
+
} else if (typeof value === "object") {
|
|
7046
|
+
const cleanedValue = removeEmptyValues(value);
|
|
7047
|
+
if (Object.keys(cleanedValue).length > 0) {
|
|
7048
|
+
result[key] = cleanedValue;
|
|
7049
|
+
}
|
|
7050
|
+
} else {
|
|
7051
|
+
result[key] = value;
|
|
7052
|
+
}
|
|
7053
|
+
}
|
|
7054
|
+
return result;
|
|
7055
|
+
}
|
|
6871
7056
|
|
|
6872
7057
|
const labelVariants = cva("text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70");
|
|
6873
7058
|
const Label = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(LabelPrimitive.Root, { ref, className: clsx(labelVariants(), className), ...props }));
|
|
@@ -6894,9 +7079,50 @@ function inferFieldType(schema, fieldConfig) {
|
|
|
6894
7079
|
if (schema instanceof z$1.ZodNativeEnum) return "select";
|
|
6895
7080
|
if (schema instanceof z.ZodArray) return "array";
|
|
6896
7081
|
if (schema instanceof z.ZodRecord) return "record";
|
|
7082
|
+
if (schema instanceof z.ZodUnion) {
|
|
7083
|
+
const options = schema._zod.def.options;
|
|
7084
|
+
const hasLiteral = options.every((option) => {
|
|
7085
|
+
if ("shape" in option._zod.def) {
|
|
7086
|
+
return Object.values(option._zod.def.shape).some(
|
|
7087
|
+
(value) => value instanceof z.ZodLiteral
|
|
7088
|
+
);
|
|
7089
|
+
}
|
|
7090
|
+
return false;
|
|
7091
|
+
});
|
|
7092
|
+
if (hasLiteral) {
|
|
7093
|
+
return "discriminated-union";
|
|
7094
|
+
}
|
|
7095
|
+
return "union";
|
|
7096
|
+
}
|
|
6897
7097
|
return "string";
|
|
6898
7098
|
}
|
|
6899
7099
|
|
|
7100
|
+
function getDefaultValueInZodStack(schema) {
|
|
7101
|
+
if (schema instanceof z$2.core.$ZodDefault) {
|
|
7102
|
+
return schema._zod.def.defaultValue;
|
|
7103
|
+
} else if ("innerType" in schema._zod.def) {
|
|
7104
|
+
return getDefaultValueInZodStack(schema._zod.def.innerType);
|
|
7105
|
+
} else if ("shape" in schema._zod.def) {
|
|
7106
|
+
return getDefaultValues(schema);
|
|
7107
|
+
} else if ("left" in schema._zod.def && "right" in schema._zod.def) {
|
|
7108
|
+
const left = getDefaultValues(schema._zod.def.left);
|
|
7109
|
+
const right = getDefaultValues(schema._zod.def.right);
|
|
7110
|
+
return { ...left, ...right };
|
|
7111
|
+
}
|
|
7112
|
+
return void 0;
|
|
7113
|
+
}
|
|
7114
|
+
function getDefaultValues(schema) {
|
|
7115
|
+
const shape = schema._zod.def.shape;
|
|
7116
|
+
const defaultValues = {};
|
|
7117
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
7118
|
+
const defaultValue = getDefaultValueInZodStack(field);
|
|
7119
|
+
if (defaultValue !== void 0) {
|
|
7120
|
+
defaultValues[key] = defaultValue;
|
|
7121
|
+
}
|
|
7122
|
+
}
|
|
7123
|
+
return defaultValues;
|
|
7124
|
+
}
|
|
7125
|
+
|
|
6900
7126
|
function parseField(key, schema) {
|
|
6901
7127
|
const baseSchema = getBaseSchema(schema);
|
|
6902
7128
|
const fieldConfig = getFieldConfigInZodStack(schema);
|
|
@@ -6915,11 +7141,16 @@ function parseField(key, schema) {
|
|
|
6915
7141
|
if (baseSchema instanceof z$1.ZodObject || baseSchema instanceof z.ZodObject) {
|
|
6916
7142
|
subSchema = Object.entries(baseSchema.shape).map(([key2, field]) => parseField(key2, field));
|
|
6917
7143
|
}
|
|
7144
|
+
if (baseSchema instanceof z$1.ZodUnion || baseSchema instanceof z.ZodUnion) {
|
|
7145
|
+
subSchema = Object.entries(baseSchema.def.options).map(([key2, field]) => {
|
|
7146
|
+
return parseField(key2, field);
|
|
7147
|
+
});
|
|
7148
|
+
}
|
|
6918
7149
|
if (baseSchema instanceof z$1.ZodIntersection || baseSchema instanceof z.ZodIntersection) {
|
|
6919
|
-
const subSchemaLeft = Object.entries(baseSchema.
|
|
7150
|
+
const subSchemaLeft = Object.entries(baseSchema.def.left.shape).map(
|
|
6920
7151
|
([key2, field]) => parseField(key2, field)
|
|
6921
7152
|
);
|
|
6922
|
-
const subSchemaRight = Object.entries(baseSchema.
|
|
7153
|
+
const subSchemaRight = Object.entries(baseSchema.def.right.shape).map(
|
|
6923
7154
|
([key2, field]) => parseField(key2, field)
|
|
6924
7155
|
);
|
|
6925
7156
|
subSchema = [...subSchemaLeft, ...subSchemaRight];
|
|
@@ -6927,13 +7158,21 @@ function parseField(key, schema) {
|
|
|
6927
7158
|
if (baseSchema instanceof z$1.ZodArray || baseSchema instanceof z.ZodArray) {
|
|
6928
7159
|
subSchema = [parseField("0", baseSchema._zod.def.element)];
|
|
6929
7160
|
}
|
|
7161
|
+
const isLiteral = baseSchema instanceof z.ZodLiteral;
|
|
7162
|
+
const literalValues = isLiteral ? baseSchema._zod.def.values : void 0;
|
|
6930
7163
|
return {
|
|
6931
7164
|
key,
|
|
6932
7165
|
type,
|
|
6933
7166
|
required: !schema.optional(),
|
|
6934
7167
|
default: defaultValue,
|
|
6935
7168
|
description: baseSchema.description,
|
|
6936
|
-
fieldConfig
|
|
7169
|
+
fieldConfig: isLiteral || Object.keys(fieldConfig ?? {})?.length > 0 ? {
|
|
7170
|
+
...fieldConfig,
|
|
7171
|
+
customData: {
|
|
7172
|
+
...fieldConfig?.customData ?? {},
|
|
7173
|
+
...isLiteral ? { isLiteral, literalValues } : {}
|
|
7174
|
+
}
|
|
7175
|
+
} : void 0,
|
|
6937
7176
|
options: optionValues,
|
|
6938
7177
|
schema: subSchema
|
|
6939
7178
|
};
|
|
@@ -6958,8 +7197,12 @@ class CustomZodProvider extends ZodProvider {
|
|
|
6958
7197
|
super(schema);
|
|
6959
7198
|
this._schema = schema;
|
|
6960
7199
|
}
|
|
7200
|
+
getDefaultValues() {
|
|
7201
|
+
return getDefaultValues(this._schema);
|
|
7202
|
+
}
|
|
6961
7203
|
validateSchema(values) {
|
|
6962
|
-
const
|
|
7204
|
+
const cleanedValues = removeEmptyValues(values);
|
|
7205
|
+
const result = super.validateSchema(cleanedValues);
|
|
6963
7206
|
return result;
|
|
6964
7207
|
}
|
|
6965
7208
|
parseSchema() {
|
|
@@ -6992,10 +7235,10 @@ function DynamicForm({
|
|
|
6992
7235
|
}
|
|
6993
7236
|
const normalizedSchema = (schema2) => {
|
|
6994
7237
|
if (isEmptyZodObject(schema2)) {
|
|
6995
|
-
return z$
|
|
7238
|
+
return z$3.object({});
|
|
6996
7239
|
}
|
|
6997
7240
|
if (isNotZodObject) {
|
|
6998
|
-
return z$
|
|
7241
|
+
return z$3.object({
|
|
6999
7242
|
"": schema2
|
|
7000
7243
|
});
|
|
7001
7244
|
}
|
|
@@ -7668,6 +7911,7 @@ const LinkComponentContext = createContext({
|
|
|
7668
7911
|
scorerLink: () => "",
|
|
7669
7912
|
toolLink: () => "",
|
|
7670
7913
|
mcpServerLink: () => "",
|
|
7914
|
+
mcpServerToolLink: () => "",
|
|
7671
7915
|
workflowRunLink: () => ""
|
|
7672
7916
|
}
|
|
7673
7917
|
});
|
|
@@ -13199,7 +13443,7 @@ function MainSidebarNavLink({
|
|
|
13199
13443
|
className
|
|
13200
13444
|
}) {
|
|
13201
13445
|
const { Link } = useLinkComponent();
|
|
13202
|
-
const
|
|
13446
|
+
const isCollapsed = state === "collapsed";
|
|
13203
13447
|
const isFeatured = link?.variant === "featured";
|
|
13204
13448
|
const linkParams = link?.url?.startsWith("http") ? { target: "_blank", rel: "noreferrer" } : {};
|
|
13205
13449
|
return /* @__PURE__ */ jsx(
|
|
@@ -13213,22 +13457,31 @@ function MainSidebarNavLink({
|
|
|
13213
13457
|
{
|
|
13214
13458
|
"[&>a]:text-icon5 [&>a]:bg-surface3": isActive,
|
|
13215
13459
|
"[&_svg]:text-icon5": isActive,
|
|
13216
|
-
"[&>a]:justify-start ":
|
|
13217
|
-
"[&_svg]:text-icon3":
|
|
13460
|
+
"[&>a]:justify-start ": !isCollapsed,
|
|
13461
|
+
"[&_svg]:text-icon3": isCollapsed,
|
|
13218
13462
|
"[&>a]:rounded-md [&>a]:my-[0.5rem] [&>a]:bg-accent1/75 [&>a:hover]:bg-accent1/85 [&>a]:text-black [&>a:hover]:text-black": isFeatured,
|
|
13219
|
-
"[&_svg]:text-black/75": isFeatured
|
|
13463
|
+
"[&_svg]:text-black/75 [&>a:hover_svg]:text-black": isFeatured
|
|
13220
13464
|
},
|
|
13221
13465
|
className
|
|
13222
13466
|
),
|
|
13223
|
-
children: link ? /* @__PURE__ */
|
|
13224
|
-
|
|
13225
|
-
|
|
13226
|
-
/* @__PURE__ */ jsx(
|
|
13227
|
-
|
|
13228
|
-
|
|
13467
|
+
children: link ? /* @__PURE__ */ jsx(Fragment, { children: isCollapsed || link.tooltipMsg ? /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
13468
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Link, { href: link.url, ...linkParams, children: [
|
|
13469
|
+
link.icon && link.icon,
|
|
13470
|
+
isCollapsed ? /* @__PURE__ */ jsx(VisuallyHidden$1, { children: link.name }) : link.name,
|
|
13471
|
+
" ",
|
|
13472
|
+
children
|
|
13473
|
+
] }) }),
|
|
13474
|
+
/* @__PURE__ */ jsx(TooltipContent, { side: "right", align: "center", className: "bg-border1 text-icon6 ml-[1rem]", children: link.tooltipMsg ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
13475
|
+
isCollapsed && `${link.name} | `,
|
|
13476
|
+
" ",
|
|
13477
|
+
link.tooltipMsg
|
|
13478
|
+
] }) : link.name })
|
|
13479
|
+
] }) : /* @__PURE__ */ jsxs(Link, { href: link.url, ...linkParams, children: [
|
|
13480
|
+
link.icon && link.icon,
|
|
13481
|
+
isCollapsed ? /* @__PURE__ */ jsx(VisuallyHidden$1, { children: link.name }) : link.name,
|
|
13229
13482
|
" ",
|
|
13230
13483
|
children
|
|
13231
|
-
] }) : children
|
|
13484
|
+
] }) }) : children
|
|
13232
13485
|
}
|
|
13233
13486
|
);
|
|
13234
13487
|
}
|
|
@@ -14844,495 +15097,2127 @@ const useExecuteAgentTool = () => {
|
|
|
14844
15097
|
});
|
|
14845
15098
|
};
|
|
14846
15099
|
|
|
14847
|
-
const
|
|
14848
|
-
|
|
14849
|
-
|
|
15100
|
+
const ToolIconMap = {
|
|
15101
|
+
agent: AgentIcon,
|
|
15102
|
+
workflow: WorkflowIcon,
|
|
15103
|
+
tool: ToolsIcon
|
|
15104
|
+
};
|
|
15105
|
+
|
|
15106
|
+
const ToolInformation = ({ toolDescription, toolId, toolType }) => {
|
|
15107
|
+
const ToolIconComponent = ToolIconMap[toolType || "tool"];
|
|
15108
|
+
return /* @__PURE__ */ jsx("div", { className: "p-5 border-b-sm border-border1", children: /* @__PURE__ */ jsxs("div", { className: "text-icon6 flex gap-2", children: [
|
|
15109
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Icon, { size: "lg", className: "bg-surface4 rounded-md p-1", children: /* @__PURE__ */ jsx(ToolIconComponent, {}) }) }),
|
|
15110
|
+
/* @__PURE__ */ jsx("div", { className: "flex gap-4 justify-between w-full min-w-0", children: /* @__PURE__ */ jsxs("div", { children: [
|
|
15111
|
+
/* @__PURE__ */ jsx(Txt, { variant: "header-md", as: "h2", className: "font-medium truncate", children: toolId }),
|
|
15112
|
+
/* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon3", children: toolDescription })
|
|
15113
|
+
] }) })
|
|
15114
|
+
] }) });
|
|
15115
|
+
};
|
|
15116
|
+
|
|
15117
|
+
const ToolExecutor = ({
|
|
15118
|
+
isExecutingTool,
|
|
15119
|
+
zodInputSchema,
|
|
15120
|
+
handleExecuteTool,
|
|
15121
|
+
executionResult: result,
|
|
15122
|
+
errorString,
|
|
15123
|
+
toolDescription,
|
|
15124
|
+
toolId,
|
|
15125
|
+
toolType
|
|
15126
|
+
}) => {
|
|
15127
|
+
const theme = useCodemirrorTheme$1();
|
|
15128
|
+
const code = JSON.stringify(result ?? {}, null, 2);
|
|
15129
|
+
return /* @__PURE__ */ jsxs(MainContentContent, { hasLeftServiceColumn: true, className: "relative", children: [
|
|
15130
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-surface2 border-r-sm border-border1 w-[20rem]", children: [
|
|
15131
|
+
/* @__PURE__ */ jsx(ToolInformation, { toolDescription, toolId, toolType }),
|
|
15132
|
+
/* @__PURE__ */ jsx("div", { className: "p-5 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
15133
|
+
DynamicForm,
|
|
15134
|
+
{
|
|
15135
|
+
isSubmitLoading: isExecutingTool,
|
|
15136
|
+
schema: zodInputSchema,
|
|
15137
|
+
onSubmit: (data) => {
|
|
15138
|
+
handleExecuteTool(data);
|
|
15139
|
+
},
|
|
15140
|
+
className: "h-auto pb-7"
|
|
15141
|
+
}
|
|
15142
|
+
) })
|
|
15143
|
+
] }),
|
|
15144
|
+
/* @__PURE__ */ jsx("div", { className: "absolute top-4 right-4 z-10", children: /* @__PURE__ */ jsx(CopyButton, { content: code, tooltip: "Copy JSON result to clipboard" }) }),
|
|
15145
|
+
/* @__PURE__ */ jsx("div", { className: "p-5 h-full relative overflow-x-auto overflow-y-auto", children: /* @__PURE__ */ jsx(CodeMirror, { value: errorString || code, editable: true, theme, extensions: [jsonLanguage] }) })
|
|
15146
|
+
] });
|
|
15147
|
+
};
|
|
15148
|
+
|
|
15149
|
+
const AgentToolPanel = ({ toolId, agentId }) => {
|
|
15150
|
+
const { data: agent, isLoading: isAgentLoading } = useAgent(agentId);
|
|
15151
|
+
const tool = Object.values(agent?.tools ?? {}).find((tool2) => tool2.id === toolId);
|
|
15152
|
+
const { mutateAsync: executeTool, isPending: isExecutingTool, data: result } = useExecuteAgentTool();
|
|
15153
|
+
const { runtimeContext: playgroundRuntimeContext } = usePlaygroundStore();
|
|
15154
|
+
const handleExecuteTool = async (data) => {
|
|
15155
|
+
if (!tool) return;
|
|
15156
|
+
await executeTool({
|
|
15157
|
+
agentId,
|
|
15158
|
+
toolId: tool.id,
|
|
15159
|
+
input: data,
|
|
15160
|
+
playgroundRuntimeContext
|
|
15161
|
+
});
|
|
15162
|
+
};
|
|
15163
|
+
const zodInputSchema = tool?.inputSchema ? resolveSerializedZodOutput(jsonSchemaToZod(parse(tool?.inputSchema))) : z.object({});
|
|
15164
|
+
if (isAgentLoading) return null;
|
|
15165
|
+
if (!tool)
|
|
15166
|
+
return /* @__PURE__ */ jsx("div", { className: "py-12 text-center px-6", children: /* @__PURE__ */ jsx(Txt, { variant: "header-md", className: "text-icon3", children: "Tool not found" }) });
|
|
14850
15167
|
return /* @__PURE__ */ jsx(
|
|
14851
|
-
|
|
15168
|
+
ToolExecutor,
|
|
14852
15169
|
{
|
|
14853
|
-
|
|
14854
|
-
|
|
15170
|
+
executionResult: result,
|
|
15171
|
+
isExecutingTool,
|
|
15172
|
+
zodInputSchema,
|
|
15173
|
+
handleExecuteTool,
|
|
15174
|
+
toolDescription: tool.description,
|
|
15175
|
+
toolId: tool.id
|
|
14855
15176
|
}
|
|
14856
15177
|
);
|
|
14857
15178
|
};
|
|
14858
|
-
const columns$1 = [
|
|
14859
|
-
{
|
|
14860
|
-
header: "Name",
|
|
14861
|
-
accessorKey: "name",
|
|
14862
|
-
cell: NameCell$1
|
|
14863
|
-
},
|
|
14864
|
-
{
|
|
14865
|
-
header: "Attached entities",
|
|
14866
|
-
accessorKey: "attachedEntities",
|
|
14867
|
-
cell: ({ row }) => {
|
|
14868
|
-
const tool = row.original;
|
|
14869
|
-
const agentsCount = tool.agents.length;
|
|
14870
|
-
return /* @__PURE__ */ jsx(Cell, { children: /* @__PURE__ */ jsxs(Badge$1, { variant: "default", icon: /* @__PURE__ */ jsx(AgentIcon, { className: "text-accent1" }), children: [
|
|
14871
|
-
agentsCount,
|
|
14872
|
-
" agent",
|
|
14873
|
-
agentsCount > 1 ? "s" : ""
|
|
14874
|
-
] }) });
|
|
14875
|
-
}
|
|
14876
|
-
}
|
|
14877
|
-
];
|
|
14878
15179
|
|
|
14879
|
-
const
|
|
14880
|
-
const
|
|
14881
|
-
|
|
14882
|
-
|
|
14883
|
-
|
|
14884
|
-
|
|
14885
|
-
|
|
14886
|
-
|
|
14887
|
-
|
|
14888
|
-
|
|
14889
|
-
|
|
14890
|
-
|
|
14891
|
-
|
|
14892
|
-
|
|
15180
|
+
const useMemory = (agentId) => {
|
|
15181
|
+
const client = useMastraClient();
|
|
15182
|
+
return useQuery({
|
|
15183
|
+
queryKey: ["memory", agentId],
|
|
15184
|
+
queryFn: () => agentId ? client.getMemoryStatus(agentId) : null,
|
|
15185
|
+
enabled: Boolean(agentId),
|
|
15186
|
+
staleTime: 5 * 60 * 1e3,
|
|
15187
|
+
// 5 minutes
|
|
15188
|
+
gcTime: 10 * 60 * 1e3,
|
|
15189
|
+
// 10 minutes
|
|
15190
|
+
retry: false
|
|
15191
|
+
});
|
|
15192
|
+
};
|
|
15193
|
+
const useMemoryConfig = (agentId) => {
|
|
15194
|
+
const client = useMastraClient();
|
|
15195
|
+
return useQuery({
|
|
15196
|
+
queryKey: ["memory", "config", agentId],
|
|
15197
|
+
queryFn: () => agentId ? client.getMemoryConfig({ agentId }) : null,
|
|
15198
|
+
enabled: Boolean(agentId),
|
|
15199
|
+
staleTime: 5 * 60 * 1e3,
|
|
15200
|
+
// 5 minutes
|
|
15201
|
+
gcTime: 10 * 60 * 1e3,
|
|
15202
|
+
// 10 minutes
|
|
15203
|
+
retry: false,
|
|
15204
|
+
refetchOnWindowFocus: false
|
|
15205
|
+
});
|
|
15206
|
+
};
|
|
15207
|
+
const useThreads = ({
|
|
15208
|
+
resourceId,
|
|
15209
|
+
agentId,
|
|
15210
|
+
isMemoryEnabled
|
|
15211
|
+
}) => {
|
|
15212
|
+
const client = useMastraClient();
|
|
15213
|
+
return useQuery({
|
|
15214
|
+
queryKey: ["memory", "threads", resourceId, agentId],
|
|
15215
|
+
queryFn: () => isMemoryEnabled ? client.getMemoryThreads({ resourceId, agentId }) : null,
|
|
15216
|
+
enabled: Boolean(isMemoryEnabled),
|
|
15217
|
+
staleTime: 0,
|
|
15218
|
+
gcTime: 0,
|
|
15219
|
+
retry: false,
|
|
15220
|
+
refetchOnWindowFocus: false
|
|
15221
|
+
});
|
|
15222
|
+
};
|
|
15223
|
+
const useDeleteThread = () => {
|
|
15224
|
+
const client = useMastraClient();
|
|
15225
|
+
const queryClient = useQueryClient();
|
|
15226
|
+
return useMutation({
|
|
15227
|
+
mutationFn: ({ threadId, agentId, networkId }) => client.deleteThread(threadId, { agentId, networkId }),
|
|
15228
|
+
onSuccess: (_, variables) => {
|
|
15229
|
+
const { agentId, networkId } = variables;
|
|
15230
|
+
if (agentId) {
|
|
15231
|
+
queryClient.invalidateQueries({ queryKey: ["memory", "threads", agentId, agentId] });
|
|
14893
15232
|
}
|
|
14894
|
-
|
|
14895
|
-
|
|
14896
|
-
|
|
14897
|
-
|
|
14898
|
-
|
|
14899
|
-
|
|
14900
|
-
|
|
14901
|
-
agents: []
|
|
14902
|
-
});
|
|
15233
|
+
if (networkId) {
|
|
15234
|
+
queryClient.invalidateQueries({ queryKey: ["network", "threads", networkId, networkId] });
|
|
15235
|
+
}
|
|
15236
|
+
toast.success("Chat deleted successfully");
|
|
15237
|
+
},
|
|
15238
|
+
onError: () => {
|
|
15239
|
+
toast.error("Failed to delete chat");
|
|
14903
15240
|
}
|
|
14904
|
-
}
|
|
14905
|
-
return Array.from(toolsWithAgents.values());
|
|
14906
|
-
};
|
|
14907
|
-
|
|
14908
|
-
function ToolTable({ tools, agents, isLoading }) {
|
|
14909
|
-
const [search, setSearch] = useState("");
|
|
14910
|
-
const { navigate, paths } = useLinkComponent();
|
|
14911
|
-
const toolData = useMemo(() => prepareToolsTable(tools, agents), [tools, agents]);
|
|
14912
|
-
const table = useReactTable({
|
|
14913
|
-
data: toolData,
|
|
14914
|
-
columns: columns$1,
|
|
14915
|
-
getCoreRowModel: getCoreRowModel()
|
|
14916
15241
|
});
|
|
14917
|
-
|
|
14918
|
-
|
|
14919
|
-
|
|
14920
|
-
|
|
14921
|
-
|
|
14922
|
-
|
|
14923
|
-
|
|
14924
|
-
|
|
14925
|
-
|
|
14926
|
-
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
|
|
14930
|
-
|
|
14931
|
-
|
|
14932
|
-
|
|
14933
|
-
|
|
14934
|
-
}
|
|
14935
|
-
|
|
14936
|
-
|
|
14937
|
-
|
|
14938
|
-
|
|
14939
|
-
|
|
14940
|
-
|
|
14941
|
-
|
|
14942
|
-
|
|
14943
|
-
] }, index)) })
|
|
14944
|
-
] });
|
|
14945
|
-
const EmptyToolsTable = () => /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(
|
|
14946
|
-
EmptyState,
|
|
14947
|
-
{
|
|
14948
|
-
iconSlot: /* @__PURE__ */ jsx(ToolCoinIcon, {}),
|
|
14949
|
-
titleSlot: "Configure Tools",
|
|
14950
|
-
descriptionSlot: "Mastra tools are not configured yet. You can find more information in the documentation.",
|
|
14951
|
-
actionSlot: /* @__PURE__ */ jsxs(
|
|
14952
|
-
Button$1,
|
|
14953
|
-
{
|
|
14954
|
-
size: "lg",
|
|
14955
|
-
className: "w-full",
|
|
14956
|
-
variant: "light",
|
|
14957
|
-
as: "a",
|
|
14958
|
-
href: "https://mastra.ai/en/docs/agents/using-tools-and-mcp",
|
|
14959
|
-
target: "_blank",
|
|
14960
|
-
children: [
|
|
14961
|
-
/* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx(ToolsIcon, {}) }),
|
|
14962
|
-
"Docs"
|
|
14963
|
-
]
|
|
14964
|
-
}
|
|
14965
|
-
)
|
|
14966
|
-
}
|
|
14967
|
-
) });
|
|
14968
|
-
|
|
14969
|
-
const useExecuteTool = () => {
|
|
14970
|
-
const client = useMastraClient();
|
|
14971
|
-
return useMutation({
|
|
14972
|
-
mutationFn: async ({
|
|
14973
|
-
toolId,
|
|
14974
|
-
input,
|
|
14975
|
-
runtimeContext: playgroundRuntimeContext
|
|
14976
|
-
}) => {
|
|
14977
|
-
const runtimeContext = new RuntimeContext$2();
|
|
14978
|
-
Object.entries(playgroundRuntimeContext ?? {}).forEach(([key, value]) => {
|
|
14979
|
-
runtimeContext.set(key, value);
|
|
14980
|
-
});
|
|
14981
|
-
try {
|
|
14982
|
-
const tool = client.getTool(toolId);
|
|
14983
|
-
const response = await tool.execute({ data: input, runtimeContext });
|
|
14984
|
-
return response;
|
|
14985
|
-
} catch (error) {
|
|
14986
|
-
toast.error("Error executing dev tool");
|
|
14987
|
-
console.error("Error executing dev tool:", error);
|
|
14988
|
-
throw error;
|
|
15242
|
+
};
|
|
15243
|
+
const useMemorySearch = ({
|
|
15244
|
+
agentId,
|
|
15245
|
+
resourceId,
|
|
15246
|
+
threadId
|
|
15247
|
+
}) => {
|
|
15248
|
+
const searchMemory = async (searchQuery, memoryConfig) => {
|
|
15249
|
+
if (!searchQuery.trim()) {
|
|
15250
|
+
return { results: [], count: 0, query: searchQuery };
|
|
15251
|
+
}
|
|
15252
|
+
const params = new URLSearchParams({
|
|
15253
|
+
searchQuery,
|
|
15254
|
+
resourceId,
|
|
15255
|
+
agentId
|
|
15256
|
+
});
|
|
15257
|
+
if (threadId) {
|
|
15258
|
+
params.append("threadId", threadId);
|
|
15259
|
+
}
|
|
15260
|
+
if (memoryConfig) {
|
|
15261
|
+
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
15262
|
+
}
|
|
15263
|
+
const response = await fetch(`/api/memory/search?${params}`, {
|
|
15264
|
+
method: "GET",
|
|
15265
|
+
headers: {
|
|
15266
|
+
"Content-Type": "application/json",
|
|
15267
|
+
"x-mastra-dev-playground": "true"
|
|
14989
15268
|
}
|
|
15269
|
+
});
|
|
15270
|
+
if (!response.ok) {
|
|
15271
|
+
const errorData = await response.json().catch(() => ({ message: "Unknown error" }));
|
|
15272
|
+
console.error("Search memory error:", errorData);
|
|
15273
|
+
throw new Error(errorData.message || errorData.error || "Failed to search memory");
|
|
14990
15274
|
}
|
|
14991
|
-
|
|
15275
|
+
return response.json();
|
|
15276
|
+
};
|
|
15277
|
+
return { searchMemory };
|
|
14992
15278
|
};
|
|
14993
15279
|
|
|
14994
|
-
function
|
|
14995
|
-
|
|
14996
|
-
|
|
14997
|
-
|
|
14998
|
-
|
|
14999
|
-
|
|
15000
|
-
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
|
|
15004
|
-
|
|
15005
|
-
|
|
15006
|
-
})
|
|
15007
|
-
if (isLoading) {
|
|
15008
|
-
return /* @__PURE__ */ jsxs(
|
|
15009
|
-
"div",
|
|
15010
|
-
{
|
|
15011
|
-
className: cn(
|
|
15012
|
-
"h-[6.5rem] flex items-center gap-[2rem]",
|
|
15013
|
-
"[&>div]:bg-surface3 [&>div]:w-[12rem] [&>div]:h-[2rem] [&>div]:animate-pulse",
|
|
15014
|
-
className
|
|
15015
|
-
),
|
|
15016
|
-
children: [
|
|
15017
|
-
/* @__PURE__ */ jsx("div", {}),
|
|
15018
|
-
" ",
|
|
15019
|
-
/* @__PURE__ */ jsx("div", {}),
|
|
15020
|
-
" ",
|
|
15021
|
-
/* @__PURE__ */ jsx("div", {})
|
|
15022
|
-
]
|
|
15023
|
-
}
|
|
15024
|
-
);
|
|
15280
|
+
function MarkdownRenderer({ children }) {
|
|
15281
|
+
const processedText = children.replace(/\\n/g, "\n");
|
|
15282
|
+
return /* @__PURE__ */ jsx(Markdown, { remarkPlugins: [remarkGfm], components: COMPONENTS, className: "space-y-3", children: processedText });
|
|
15283
|
+
}
|
|
15284
|
+
const HighlightedPre = React__default.memo(({ children, language, ...props }) => {
|
|
15285
|
+
const [tokens, setTokens] = useState([]);
|
|
15286
|
+
useEffect(() => {
|
|
15287
|
+
highlight(children, language).then((tokens2) => {
|
|
15288
|
+
if (tokens2) setTokens(tokens2);
|
|
15289
|
+
});
|
|
15290
|
+
}, [children, language]);
|
|
15291
|
+
if (!tokens.length) {
|
|
15292
|
+
return /* @__PURE__ */ jsx("pre", { ...props, children });
|
|
15025
15293
|
}
|
|
15026
|
-
return /* @__PURE__ */
|
|
15027
|
-
/* @__PURE__ */ jsx(
|
|
15028
|
-
|
|
15029
|
-
|
|
15030
|
-
|
|
15031
|
-
|
|
15032
|
-
|
|
15033
|
-
|
|
15034
|
-
|
|
15035
|
-
|
|
15036
|
-
|
|
15294
|
+
return /* @__PURE__ */ jsx("pre", { ...props, children: /* @__PURE__ */ jsx("code", { children: tokens.map((line, lineIndex) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
15295
|
+
/* @__PURE__ */ jsx("span", { children: line.map((token, tokenIndex) => {
|
|
15296
|
+
const style = typeof token.htmlStyle === "string" ? void 0 : token.htmlStyle;
|
|
15297
|
+
return /* @__PURE__ */ jsx(
|
|
15298
|
+
"span",
|
|
15299
|
+
{
|
|
15300
|
+
className: "text-shiki-light bg-shiki-light-bg dark:text-shiki-dark dark:bg-shiki-dark-bg",
|
|
15301
|
+
style,
|
|
15302
|
+
children: token.content
|
|
15303
|
+
},
|
|
15304
|
+
tokenIndex
|
|
15305
|
+
);
|
|
15306
|
+
}) }, lineIndex),
|
|
15307
|
+
lineIndex !== tokens.length - 1 && "\n"
|
|
15308
|
+
] })) }) });
|
|
15309
|
+
});
|
|
15310
|
+
HighlightedPre.displayName = "HighlightedCode";
|
|
15311
|
+
const CodeBlock = ({ children, className, language, ...restProps }) => {
|
|
15312
|
+
const code = typeof children === "string" ? children : childrenTakeAllStringContents(children);
|
|
15313
|
+
const preClass = cn(
|
|
15314
|
+
"overflow-x-scroll rounded-md border bg-background/50 p-4 font-mono text-sm [scrollbar-width:none]",
|
|
15315
|
+
className
|
|
15316
|
+
);
|
|
15317
|
+
return /* @__PURE__ */ jsxs("div", { className: "group/code relative mb-4", children: [
|
|
15037
15318
|
/* @__PURE__ */ jsx(
|
|
15038
|
-
|
|
15319
|
+
Suspense,
|
|
15039
15320
|
{
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
onValueChange: onProviderChange,
|
|
15043
|
-
options: providerOptions
|
|
15321
|
+
fallback: /* @__PURE__ */ jsx("pre", { className: preClass, ...restProps, children }),
|
|
15322
|
+
children: /* @__PURE__ */ jsx(HighlightedPre, { language, className: preClass, children: code })
|
|
15044
15323
|
}
|
|
15045
15324
|
),
|
|
15046
|
-
|
|
15047
|
-
"Reset ",
|
|
15048
|
-
/* @__PURE__ */ jsx(XIcon, {})
|
|
15049
|
-
] })
|
|
15325
|
+
/* @__PURE__ */ jsx("div", { className: "invisible absolute right-2 top-2 flex space-x-1 rounded-lg p-1 opacity-0 transition-all duration-200 group-hover/code:visible group-hover/code:opacity-100", children: /* @__PURE__ */ jsx(CopyButton, { content: code, copyMessage: "Copied code to clipboard" }) })
|
|
15050
15326
|
] });
|
|
15327
|
+
};
|
|
15328
|
+
function childrenTakeAllStringContents(element) {
|
|
15329
|
+
if (typeof element === "string") {
|
|
15330
|
+
return element;
|
|
15331
|
+
}
|
|
15332
|
+
if (element?.props?.children) {
|
|
15333
|
+
let children = element.props.children;
|
|
15334
|
+
if (Array.isArray(children)) {
|
|
15335
|
+
return children.map((child) => childrenTakeAllStringContents(child)).join("");
|
|
15336
|
+
} else {
|
|
15337
|
+
return childrenTakeAllStringContents(children);
|
|
15338
|
+
}
|
|
15339
|
+
}
|
|
15340
|
+
return "";
|
|
15051
15341
|
}
|
|
15052
|
-
|
|
15053
|
-
|
|
15054
|
-
|
|
15055
|
-
}
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
|
|
15342
|
+
const COMPONENTS = {
|
|
15343
|
+
h1: ({ children, ...props }) => /* @__PURE__ */ jsx("h1", { className: "text-2xl font-semibold", ...props, children }),
|
|
15344
|
+
h2: ({ children, ...props }) => /* @__PURE__ */ jsx("h2", { className: "font-semibold text-xl", ...props, children }),
|
|
15345
|
+
h3: ({ children, ...props }) => /* @__PURE__ */ jsx("h3", { className: "font-semibold text-lg", ...props, children }),
|
|
15346
|
+
h4: ({ children, ...props }) => /* @__PURE__ */ jsx("h4", { className: "font-semibold text-base", ...props, children }),
|
|
15347
|
+
h5: ({ children, ...props }) => /* @__PURE__ */ jsx("h5", { className: "font-medium", ...props, children }),
|
|
15348
|
+
strong: ({ children, ...props }) => /* @__PURE__ */ jsx("strong", { className: "font-semibold", ...props, children }),
|
|
15349
|
+
a: ({ children, ...props }) => /* @__PURE__ */ jsx("a", { className: "underline underline-offset-2", ...props, children }),
|
|
15350
|
+
blockquote: ({ children, ...props }) => /* @__PURE__ */ jsx("blockquote", { className: "border-l-2 border-primary pl-4", ...props, children }),
|
|
15351
|
+
code: ({ children, className, ...rest }) => {
|
|
15352
|
+
const match = /language-(\w+)/.exec(className || "");
|
|
15353
|
+
return match ? /* @__PURE__ */ jsx(CodeBlock, { className, language: match[1], ...rest, children }) : /* @__PURE__ */ jsx(
|
|
15354
|
+
"code",
|
|
15355
|
+
{
|
|
15356
|
+
className: cn(
|
|
15357
|
+
"font-mono [:not(pre)>&]:rounded-md [:not(pre)>&]:bg-background/50 [:not(pre)>&]:px-1 [:not(pre)>&]:py-0.5"
|
|
15358
|
+
),
|
|
15359
|
+
...rest,
|
|
15360
|
+
children
|
|
15361
|
+
}
|
|
15362
|
+
);
|
|
15363
|
+
},
|
|
15364
|
+
pre: ({ children }) => children,
|
|
15365
|
+
ol: ({ children, ...props }) => /* @__PURE__ */ jsx("ol", { className: "list-decimal space-y-2 pl-6", ...props, children }),
|
|
15366
|
+
ul: ({ children, ...props }) => /* @__PURE__ */ jsx("ul", { className: "list-disc space-y-2 pl-6", ...props, children }),
|
|
15367
|
+
li: ({ children, ...props }) => /* @__PURE__ */ jsx("li", { className: "my-1.5", ...props, children }),
|
|
15368
|
+
table: ({ children, ...props }) => /* @__PURE__ */ jsx("table", { className: "w-full border-collapse overflow-y-auto rounded-md border border-foreground/20", ...props, children }),
|
|
15369
|
+
th: ({ children, ...props }) => /* @__PURE__ */ jsx(
|
|
15370
|
+
"th",
|
|
15059
15371
|
{
|
|
15060
|
-
className:
|
|
15061
|
-
|
|
15062
|
-
className
|
|
15063
|
-
),
|
|
15372
|
+
className: "border border-foreground/20 px-4 py-2 text-left font-bold [&[align=center]]:text-center [&[align=right]]:text-right",
|
|
15373
|
+
...props,
|
|
15064
15374
|
children
|
|
15065
15375
|
}
|
|
15066
|
-
)
|
|
15376
|
+
),
|
|
15377
|
+
td: ({ children, ...props }) => /* @__PURE__ */ jsx(
|
|
15378
|
+
"td",
|
|
15379
|
+
{
|
|
15380
|
+
className: "border border-foreground/20 px-4 py-2 text-left [&[align=center]]:text-center [&[align=right]]:text-right",
|
|
15381
|
+
...props,
|
|
15382
|
+
children
|
|
15383
|
+
}
|
|
15384
|
+
),
|
|
15385
|
+
tr: ({ children, ...props }) => /* @__PURE__ */ jsx("tr", { className: "m-0 border-t p-0 even:bg-muted", ...props, children }),
|
|
15386
|
+
p: ({ children, ...props }) => /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap leading-relaxed", ...props, children }),
|
|
15387
|
+
hr: ({ ...props }) => /* @__PURE__ */ jsx("hr", { className: "border-foreground/20", ...props })
|
|
15388
|
+
};
|
|
15389
|
+
|
|
15390
|
+
function CodeDisplay({
|
|
15391
|
+
content,
|
|
15392
|
+
height = "150px",
|
|
15393
|
+
isCopied = false,
|
|
15394
|
+
isDraft = false,
|
|
15395
|
+
onCopy,
|
|
15396
|
+
className = ""
|
|
15397
|
+
}) {
|
|
15398
|
+
return /* @__PURE__ */ jsx("div", { className: `rounded-md border ${className}`, style: { height }, children: /* @__PURE__ */ jsx(ScrollArea, { className: "h-full", children: /* @__PURE__ */ jsxs("div", { className: "p-2 cursor-pointer hover:bg-mastra-bg-3/50 transition-colors group relative", onClick: onCopy, children: [
|
|
15399
|
+
/* @__PURE__ */ jsx("pre", { className: "text-[10px] whitespace-pre-wrap font-mono", children: content }),
|
|
15400
|
+
isDraft && /* @__PURE__ */ jsx("div", { className: "mt-1.5", children: /* @__PURE__ */ jsx("span", { className: "text-[10px] px-1.5 py-0.5 rounded-full bg-yellow-500/20 text-yellow-500", children: "Draft - Save changes to apply" }) }),
|
|
15401
|
+
isCopied && /* @__PURE__ */ jsx("span", { className: "absolute top-2 right-2 text-[10px] px-1.5 py-0.5 rounded-full bg-green-500/20 text-green-500", children: "Copied!" }),
|
|
15402
|
+
onCopy && /* @__PURE__ */ jsx("span", { className: "absolute top-2 right-2 text-[10px] px-1.5 py-0.5 rounded-full bg-mastra-bg-3 text-mastra-el-4 opacity-0 group-hover:opacity-100 transition-opacity", children: "Click to copy" })
|
|
15403
|
+
] }) }) });
|
|
15067
15404
|
}
|
|
15068
15405
|
|
|
15069
|
-
|
|
15070
|
-
const
|
|
15406
|
+
const AgentWorkingMemory = ({ agentId }) => {
|
|
15407
|
+
const { threadExists, workingMemoryData, workingMemorySource, isLoading, isUpdating, updateWorkingMemory } = useWorkingMemory();
|
|
15408
|
+
const { data } = useMemoryConfig(agentId);
|
|
15409
|
+
const config = data?.config;
|
|
15410
|
+
const isWorkingMemoryEnabled = Boolean(config?.workingMemory?.enabled);
|
|
15411
|
+
const { isCopied, handleCopy } = useCopyToClipboard({
|
|
15412
|
+
text: workingMemoryData ?? "",
|
|
15413
|
+
copyMessage: "Working memory copied!"
|
|
15414
|
+
});
|
|
15415
|
+
const [editValue, setEditValue] = useState(workingMemoryData ?? "");
|
|
15416
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
15417
|
+
React__default.useEffect(() => {
|
|
15418
|
+
setEditValue(workingMemoryData ?? "");
|
|
15419
|
+
}, [workingMemoryData]);
|
|
15071
15420
|
if (isLoading) {
|
|
15072
|
-
return /* @__PURE__ */ jsx(
|
|
15421
|
+
return /* @__PURE__ */ jsx(Skeleton, { className: "h-32 w-full" });
|
|
15073
15422
|
}
|
|
15074
|
-
return /* @__PURE__ */
|
|
15075
|
-
|
|
15076
|
-
|
|
15077
|
-
|
|
15078
|
-
|
|
15079
|
-
|
|
15080
|
-
|
|
15423
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 p-4", children: [
|
|
15424
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
15425
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mb-2", children: [
|
|
15426
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-medium text-icon5", children: "Working Memory" }),
|
|
15427
|
+
isWorkingMemoryEnabled && workingMemorySource && /* @__PURE__ */ jsx(
|
|
15428
|
+
"span",
|
|
15429
|
+
{
|
|
15430
|
+
className: cn(
|
|
15431
|
+
"text-xs font-medium px-2 py-0.5 rounded",
|
|
15432
|
+
workingMemorySource === "resource" ? "bg-purple-500/20 text-purple-400" : "bg-blue-500/20 text-blue-400"
|
|
15433
|
+
),
|
|
15434
|
+
title: workingMemorySource === "resource" ? "Shared across all threads for this agent" : "Specific to this conversation thread",
|
|
15435
|
+
children: workingMemorySource
|
|
15436
|
+
}
|
|
15437
|
+
)
|
|
15438
|
+
] }),
|
|
15439
|
+
isWorkingMemoryEnabled && !threadExists && /* @__PURE__ */ jsx("p", { className: "text-xs text-icon3", children: "Send a message to the agent to enable working memory." })
|
|
15440
|
+
] }),
|
|
15441
|
+
isWorkingMemoryEnabled ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
15442
|
+
!isEditing ? /* @__PURE__ */ jsx(Fragment, { children: workingMemoryData ? /* @__PURE__ */ jsx(Fragment, { children: workingMemoryData.trim().startsWith("{") ? /* @__PURE__ */ jsx(
|
|
15443
|
+
CodeDisplay,
|
|
15444
|
+
{
|
|
15445
|
+
content: workingMemoryData || "",
|
|
15446
|
+
isCopied,
|
|
15447
|
+
onCopy: handleCopy,
|
|
15448
|
+
className: "bg-surface3 text-sm font-mono min-h-[150px] border border-border1 rounded-lg"
|
|
15449
|
+
}
|
|
15450
|
+
) : /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("div", { className: "bg-surface3 border border-border1 rounded-lg", style: { height: "300px" }, children: /* @__PURE__ */ jsx(ScrollArea, { className: "h-full", children: /* @__PURE__ */ jsxs(
|
|
15451
|
+
"div",
|
|
15452
|
+
{
|
|
15453
|
+
className: "p-3 cursor-pointer hover:bg-surface4/20 transition-colors relative group text-[10px]",
|
|
15454
|
+
onClick: handleCopy,
|
|
15455
|
+
children: [
|
|
15456
|
+
/* @__PURE__ */ jsx(MarkdownRenderer, { children: workingMemoryData }),
|
|
15457
|
+
isCopied && /* @__PURE__ */ jsx("span", { className: "absolute top-2 right-2 text-[10px] px-1.5 py-0.5 rounded-full bg-green-500/20 text-green-500", children: "Copied!" }),
|
|
15458
|
+
/* @__PURE__ */ jsx("span", { className: "absolute top-2 right-2 text-[10px] px-1.5 py-0.5 rounded-full bg-surface3 text-icon4 opacity-0 group-hover:opacity-100 transition-opacity", children: "Click to copy" })
|
|
15459
|
+
]
|
|
15460
|
+
}
|
|
15461
|
+
) }) }) }) }) : /* @__PURE__ */ jsx("div", { className: "text-sm text-icon3 font-mono", children: 'No working memory content yet. Click "Edit Working Memory" to add content.' }) }) : /* @__PURE__ */ jsx(
|
|
15462
|
+
"textarea",
|
|
15463
|
+
{
|
|
15464
|
+
className: "w-full min-h-[150px] p-3 border border-border1 rounded-lg bg-surface3 font-mono text-sm text-icon5 resize-none",
|
|
15465
|
+
value: editValue,
|
|
15466
|
+
onChange: (e) => setEditValue(e.target.value),
|
|
15467
|
+
disabled: isUpdating,
|
|
15468
|
+
placeholder: "Enter working memory content..."
|
|
15469
|
+
}
|
|
15470
|
+
),
|
|
15471
|
+
/* @__PURE__ */ jsx("div", { className: "flex gap-2", children: !isEditing ? /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
15472
|
+
Button$2,
|
|
15473
|
+
{
|
|
15474
|
+
variant: "secondary",
|
|
15475
|
+
size: "sm",
|
|
15476
|
+
onClick: () => setIsEditing(true),
|
|
15477
|
+
disabled: !threadExists || isUpdating,
|
|
15478
|
+
className: "text-xs",
|
|
15479
|
+
children: "Edit Working Memory"
|
|
15480
|
+
}
|
|
15481
|
+
) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
15482
|
+
/* @__PURE__ */ jsx(
|
|
15483
|
+
Button$2,
|
|
15484
|
+
{
|
|
15485
|
+
variant: "default",
|
|
15486
|
+
size: "sm",
|
|
15487
|
+
onClick: async () => {
|
|
15488
|
+
try {
|
|
15489
|
+
await updateWorkingMemory(editValue);
|
|
15490
|
+
setIsEditing(false);
|
|
15491
|
+
} catch (error) {
|
|
15492
|
+
console.error("Failed to update working memory:", error);
|
|
15493
|
+
toast.error("Failed to update working memory");
|
|
15494
|
+
}
|
|
15495
|
+
},
|
|
15496
|
+
disabled: isUpdating,
|
|
15497
|
+
className: "text-xs",
|
|
15498
|
+
children: isUpdating ? /* @__PURE__ */ jsx(RefreshCcwIcon, { className: "w-3 h-3 animate-spin" }) : "Save Changes"
|
|
15499
|
+
}
|
|
15081
15500
|
),
|
|
15082
|
-
children: [
|
|
15083
|
-
/* @__PURE__ */ jsxs(
|
|
15084
|
-
LinkComponent,
|
|
15085
|
-
{
|
|
15086
|
-
to: `/templates/${template.slug}`,
|
|
15087
|
-
className: cn("grid [&:hover_p]:text-icon5", {
|
|
15088
|
-
"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]": template.imageURL
|
|
15089
|
-
}),
|
|
15090
|
-
children: [
|
|
15091
|
-
template.imageURL && /* @__PURE__ */ jsx("div", { className: cn("overflow-hidden"), children: /* @__PURE__ */ jsx(
|
|
15092
|
-
"div",
|
|
15093
|
-
{
|
|
15094
|
-
className: "w-full h-full bg-cover thumb transition-scale duration-150",
|
|
15095
|
-
style: {
|
|
15096
|
-
backgroundImage: `url(${template.imageURL})`
|
|
15097
|
-
}
|
|
15098
|
-
}
|
|
15099
|
-
) }),
|
|
15100
|
-
/* @__PURE__ */ jsxs(
|
|
15101
|
-
"div",
|
|
15102
|
-
{
|
|
15103
|
-
className: cn(
|
|
15104
|
-
"grid py-[.75rem] px-[1.5rem] w-full gap-[0.1rem]",
|
|
15105
|
-
"[&_svg]:w-[1em] [&_svg]:h-[1em] [&_svg]:text-icon3"
|
|
15106
|
-
),
|
|
15107
|
-
children: [
|
|
15108
|
-
/* @__PURE__ */ jsx("h2", { className: "text-[1rem] text-icon5", children: template.title }),
|
|
15109
|
-
/* @__PURE__ */ jsx("p", { className: "text-[0.875rem] text-icon4 transition-colors duration-500", children: template.description }),
|
|
15110
|
-
/* @__PURE__ */ jsxs("div", { className: "hidden 2xl:flex text-icon3 text-[0.875rem] flex-wrap items-center gap-[1rem] mt-[0.75rem]", children: [
|
|
15111
|
-
hasMetaInfo && /* @__PURE__ */ jsxs(
|
|
15112
|
-
"ul",
|
|
15113
|
-
{
|
|
15114
|
-
className: cn(
|
|
15115
|
-
"flex gap-[1rem] text-[0.875rem] text-icon3 m-0 p-0 list-none",
|
|
15116
|
-
"[&>li]:flex [&>li]:items-center [&>li]:gap-[0.1rem] text-icon4"
|
|
15117
|
-
),
|
|
15118
|
-
children: [
|
|
15119
|
-
template?.agents && template.agents.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
15120
|
-
/* @__PURE__ */ jsx(AgentIcon, {}),
|
|
15121
|
-
" ",
|
|
15122
|
-
template.agents.length
|
|
15123
|
-
] }),
|
|
15124
|
-
template?.tools && template.tools.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
15125
|
-
/* @__PURE__ */ jsx(ToolsIcon, {}),
|
|
15126
|
-
" ",
|
|
15127
|
-
template.tools.length
|
|
15128
|
-
] }),
|
|
15129
|
-
template?.networks && template.networks.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
15130
|
-
/* @__PURE__ */ jsx(NetworkIcon, {}),
|
|
15131
|
-
" ",
|
|
15132
|
-
template.networks.length
|
|
15133
|
-
] }),
|
|
15134
|
-
template?.workflows && template.workflows.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
15135
|
-
/* @__PURE__ */ jsx(WorkflowIcon$1, {}),
|
|
15136
|
-
" ",
|
|
15137
|
-
template.workflows.length
|
|
15138
|
-
] }),
|
|
15139
|
-
template?.mcp && template.mcp.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
15140
|
-
/* @__PURE__ */ jsx(McpServerIcon, {}),
|
|
15141
|
-
" ",
|
|
15142
|
-
template.mcp.length
|
|
15143
|
-
] })
|
|
15144
|
-
]
|
|
15145
|
-
}
|
|
15146
|
-
),
|
|
15147
|
-
hasMetaInfo && template.supportedProviders && /* @__PURE__ */ jsx("small", { children: "|" }),
|
|
15148
|
-
/* @__PURE__ */ jsx("div", { className: "flex items-center text-icon3 gap-[1rem]", children: template.supportedProviders.map((provider) => /* @__PURE__ */ jsx("span", { className: "", children: provider }, provider)) })
|
|
15149
|
-
] })
|
|
15150
|
-
]
|
|
15151
|
-
}
|
|
15152
|
-
)
|
|
15153
|
-
]
|
|
15154
|
-
}
|
|
15155
|
-
),
|
|
15156
|
-
/* @__PURE__ */ jsx(
|
|
15157
|
-
"a",
|
|
15158
|
-
{
|
|
15159
|
-
href: template.githubUrl,
|
|
15160
|
-
className: cn("group items-center gap-[0.5rem] text-[0.875rem] ml-auto pr-[1rem] hidden", "lg:flex"),
|
|
15161
|
-
target: "_blank",
|
|
15162
|
-
rel: "noopener noreferrer",
|
|
15163
|
-
children: /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-[0.5rem] px-[0.5rem] py-[0.25rem] rounded bg-surface1 group-hover:bg-surface2 text-icon3 transition-colors group-hover:text-icon5 ", children: [
|
|
15164
|
-
/* @__PURE__ */ jsx(GithubIcon, {}),
|
|
15165
|
-
" ",
|
|
15166
|
-
getRepoName(template.githubUrl)
|
|
15167
|
-
] })
|
|
15168
|
-
}
|
|
15169
|
-
)
|
|
15170
|
-
]
|
|
15171
|
-
},
|
|
15172
|
-
template.slug
|
|
15173
|
-
);
|
|
15174
|
-
}) });
|
|
15175
|
-
}
|
|
15176
|
-
|
|
15177
|
-
function TemplateInfo({
|
|
15178
|
-
title,
|
|
15179
|
-
description,
|
|
15180
|
-
imageURL,
|
|
15181
|
-
githubUrl,
|
|
15182
|
-
isLoading,
|
|
15183
|
-
infoData,
|
|
15184
|
-
templateSlug
|
|
15185
|
-
}) {
|
|
15186
|
-
const branchName = templateSlug ? `feat/install-template-${templateSlug}` : "feat/install-template-[slug]";
|
|
15187
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
15188
|
-
/* @__PURE__ */ jsx("div", { className: cn("grid mt-[2rem] items-center"), children: /* @__PURE__ */ jsxs(
|
|
15189
|
-
"div",
|
|
15190
|
-
{
|
|
15191
|
-
className: cn(
|
|
15192
|
-
"text-[1.5rem] flex items-center gap-[0.75rem]",
|
|
15193
|
-
"[&>svg]:w-[1.2em] [&>svg]:h-[1.2em] [&>svg]:opacity-50",
|
|
15194
|
-
{
|
|
15195
|
-
"[&>svg]:opacity-20": isLoading
|
|
15196
|
-
}
|
|
15197
|
-
),
|
|
15198
|
-
children: [
|
|
15199
|
-
/* @__PURE__ */ jsx(PackageIcon, {}),
|
|
15200
|
-
/* @__PURE__ */ jsx(
|
|
15201
|
-
"h2",
|
|
15202
|
-
{
|
|
15203
|
-
className: cn({
|
|
15204
|
-
"bg-surface4 flex rounded-lg min-w-[50%]": isLoading
|
|
15205
|
-
}),
|
|
15206
|
-
children: isLoading ? /* @__PURE__ */ jsx(Fragment, { children: " " }) : title
|
|
15207
|
-
}
|
|
15208
|
-
)
|
|
15209
|
-
]
|
|
15210
|
-
}
|
|
15211
|
-
) }),
|
|
15212
|
-
/* @__PURE__ */ jsxs("div", { className: "grid lg:grid-cols-[1fr_1fr] gap-x-[6rem] ", children: [
|
|
15213
|
-
/* @__PURE__ */ jsxs("div", { className: "grid", children: [
|
|
15214
15501
|
/* @__PURE__ */ jsx(
|
|
15215
|
-
|
|
15216
|
-
{
|
|
15217
|
-
className: cn("mb-[1rem] text-[0.875rem] text-icon4 mt-[.5rem] leading-[1.75]", {
|
|
15218
|
-
"bg-surface4 rounded-lg ": isLoading
|
|
15219
|
-
}),
|
|
15220
|
-
children: isLoading ? /* @__PURE__ */ jsx(Fragment, { children: " " }) : description
|
|
15221
|
-
}
|
|
15222
|
-
),
|
|
15223
|
-
!isLoading && templateSlug && /* @__PURE__ */ jsxs(
|
|
15224
|
-
"div",
|
|
15225
|
-
{
|
|
15226
|
-
className: cn(
|
|
15227
|
-
"bg-surface2 border border-surface4 rounded-lg p-[1rem] mb-[1rem]",
|
|
15228
|
-
"flex items-start gap-[0.75rem]"
|
|
15229
|
-
),
|
|
15230
|
-
children: [
|
|
15231
|
-
/* @__PURE__ */ jsx("div", { className: "flex-shrink-0 mt-[0.125rem]", children: /* @__PURE__ */ jsx(InfoIcon$1, { className: "w-[1.1em] h-[1.1em] text-blue-500" }) }),
|
|
15232
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-[0.5rem]", children: [
|
|
15233
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[0.5rem]", children: [
|
|
15234
|
-
/* @__PURE__ */ jsx(GitBranchIcon, { className: "w-[1em] h-[1em] text-icon4" }),
|
|
15235
|
-
/* @__PURE__ */ jsx("span", { className: "text-[0.875rem] font-medium text-icon5", children: "A new Git branch will be created" })
|
|
15236
|
-
] }),
|
|
15237
|
-
/* @__PURE__ */ jsxs("div", { className: "text-[0.8125rem] text-icon4 space-y-[0.25rem]", children: [
|
|
15238
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
15239
|
-
/* @__PURE__ */ jsx("span", { className: "font-medium", children: "Branch name:" }),
|
|
15240
|
-
" ",
|
|
15241
|
-
/* @__PURE__ */ jsx("code", { className: "bg-surface3 px-[0.375rem] py-[0.125rem] rounded text-[0.75rem] font-mono", children: branchName })
|
|
15242
|
-
] }),
|
|
15243
|
-
/* @__PURE__ */ jsx("div", { children: "This ensures safe installation with easy rollback if needed. Your main branch remains unchanged." })
|
|
15244
|
-
] })
|
|
15245
|
-
] })
|
|
15246
|
-
]
|
|
15247
|
-
}
|
|
15248
|
-
),
|
|
15249
|
-
githubUrl && /* @__PURE__ */ jsxs(
|
|
15250
|
-
"a",
|
|
15502
|
+
Button$2,
|
|
15251
15503
|
{
|
|
15252
|
-
|
|
15253
|
-
|
|
15254
|
-
|
|
15255
|
-
|
|
15256
|
-
|
|
15257
|
-
|
|
15258
|
-
|
|
15259
|
-
|
|
15504
|
+
variant: "secondary",
|
|
15505
|
+
size: "sm",
|
|
15506
|
+
onClick: () => {
|
|
15507
|
+
setEditValue(workingMemoryData ?? "");
|
|
15508
|
+
setIsEditing(false);
|
|
15509
|
+
},
|
|
15510
|
+
disabled: isUpdating,
|
|
15511
|
+
className: "text-xs",
|
|
15512
|
+
children: "Cancel"
|
|
15260
15513
|
}
|
|
15261
15514
|
)
|
|
15262
|
-
] })
|
|
15263
|
-
|
|
15515
|
+
] }) })
|
|
15516
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "bg-surface3 border border-border1 rounded-lg p-4", children: [
|
|
15517
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-icon3 mb-3", children: "Working memory is not enabled for this agent. Enable it to maintain context across conversations." }),
|
|
15518
|
+
/* @__PURE__ */ jsxs(
|
|
15519
|
+
"a",
|
|
15520
|
+
{
|
|
15521
|
+
href: "https://mastra.ai/en/docs/memory/working-memory",
|
|
15522
|
+
target: "_blank",
|
|
15523
|
+
rel: "noopener noreferrer",
|
|
15524
|
+
className: "inline-flex items-center gap-2 text-sm text-blue-400 hover:text-blue-300 transition-colors",
|
|
15525
|
+
children: [
|
|
15526
|
+
"Learn about working memory",
|
|
15527
|
+
/* @__PURE__ */ jsx(ExternalLink, { className: "w-3 h-3" })
|
|
15528
|
+
]
|
|
15529
|
+
}
|
|
15530
|
+
)
|
|
15264
15531
|
] })
|
|
15265
15532
|
] });
|
|
15266
|
-
}
|
|
15533
|
+
};
|
|
15267
15534
|
|
|
15268
|
-
|
|
15269
|
-
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
|
|
15273
|
-
|
|
15274
|
-
|
|
15275
|
-
|
|
15276
|
-
isLoadingEnvVars,
|
|
15277
|
-
defaultModelProvider,
|
|
15278
|
-
defaultModelId,
|
|
15279
|
-
onModelUpdate
|
|
15280
|
-
}) {
|
|
15281
|
-
return /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsxs("div", { className: "max-w-[40rem] my-[1rem] p-[1rem] lg:p-[2rem] mx-auto gap-[2rem] grid", children: [
|
|
15282
|
-
/* @__PURE__ */ jsxs(
|
|
15283
|
-
"h2",
|
|
15535
|
+
const AgentMemoryConfig = ({ agentId }) => {
|
|
15536
|
+
const { data, isLoading } = useMemoryConfig(agentId);
|
|
15537
|
+
const [expandedSections, setExpandedSections] = useState(/* @__PURE__ */ new Set(["General", "Semantic Recall"]));
|
|
15538
|
+
const config = data?.config;
|
|
15539
|
+
const configSections = useMemo(() => {
|
|
15540
|
+
if (!config) return [];
|
|
15541
|
+
const memoryEnabled = !!config;
|
|
15542
|
+
const sections = [
|
|
15284
15543
|
{
|
|
15285
|
-
|
|
15286
|
-
|
|
15287
|
-
"
|
|
15288
|
-
|
|
15289
|
-
|
|
15290
|
-
|
|
15291
|
-
|
|
15544
|
+
title: "General",
|
|
15545
|
+
items: [
|
|
15546
|
+
{ label: "Memory Enabled", value: memoryEnabled, badge: memoryEnabled ? "success" : void 0 },
|
|
15547
|
+
{ label: "Last Messages", value: config.lastMessages || 0 },
|
|
15548
|
+
{
|
|
15549
|
+
label: "Auto-generate Titles",
|
|
15550
|
+
value: !!config.threads?.generateTitle,
|
|
15551
|
+
badge: config.threads?.generateTitle ? "info" : void 0
|
|
15552
|
+
}
|
|
15292
15553
|
]
|
|
15293
15554
|
}
|
|
15294
|
-
|
|
15295
|
-
|
|
15296
|
-
|
|
15297
|
-
{
|
|
15298
|
-
|
|
15299
|
-
|
|
15300
|
-
|
|
15301
|
-
|
|
15302
|
-
|
|
15303
|
-
|
|
15304
|
-
|
|
15305
|
-
|
|
15306
|
-
|
|
15307
|
-
|
|
15308
|
-
|
|
15555
|
+
];
|
|
15556
|
+
if (config.semanticRecall) {
|
|
15557
|
+
const enabled = Boolean(config.semanticRecall);
|
|
15558
|
+
const semanticRecall = typeof config.semanticRecall === "object" ? config.semanticRecall : {};
|
|
15559
|
+
sections.push({
|
|
15560
|
+
title: "Semantic Recall",
|
|
15561
|
+
items: [
|
|
15562
|
+
{ label: "Enabled", value: enabled, badge: enabled ? "success" : void 0 },
|
|
15563
|
+
...enabled ? [
|
|
15564
|
+
{ label: "Scope", value: semanticRecall.scope || "thread" },
|
|
15565
|
+
{ label: "Top K Results", value: semanticRecall.topK || 5 },
|
|
15566
|
+
{
|
|
15567
|
+
label: "Message Range",
|
|
15568
|
+
value: typeof semanticRecall.messageRange === "object" ? `${semanticRecall.messageRange.before || 0} before, ${semanticRecall.messageRange.after || 0} after` : `${semanticRecall.messageRange || 20} messages`
|
|
15569
|
+
}
|
|
15570
|
+
] : []
|
|
15571
|
+
]
|
|
15572
|
+
});
|
|
15573
|
+
}
|
|
15574
|
+
if (config.workingMemory) {
|
|
15575
|
+
sections.push({
|
|
15576
|
+
title: "Working Memory",
|
|
15577
|
+
items: [
|
|
15578
|
+
{
|
|
15579
|
+
label: "Enabled",
|
|
15580
|
+
value: config.workingMemory.enabled,
|
|
15581
|
+
badge: config.workingMemory.enabled ? "success" : void 0
|
|
15582
|
+
},
|
|
15583
|
+
...config.workingMemory.enabled ? [
|
|
15584
|
+
{ label: "Scope", value: config.workingMemory.scope || "thread" },
|
|
15585
|
+
{ label: "Template", value: config.workingMemory.template || "default" }
|
|
15586
|
+
] : []
|
|
15587
|
+
]
|
|
15588
|
+
});
|
|
15589
|
+
}
|
|
15590
|
+
return sections;
|
|
15591
|
+
}, [config]);
|
|
15592
|
+
const toggleSection = (title) => {
|
|
15593
|
+
const newExpanded = new Set(expandedSections);
|
|
15594
|
+
if (newExpanded.has(title)) {
|
|
15595
|
+
newExpanded.delete(title);
|
|
15596
|
+
} else {
|
|
15597
|
+
newExpanded.add(title);
|
|
15598
|
+
}
|
|
15599
|
+
setExpandedSections(newExpanded);
|
|
15600
|
+
};
|
|
15601
|
+
const renderValue = (value, badge) => {
|
|
15602
|
+
if (typeof value === "boolean") {
|
|
15603
|
+
return /* @__PURE__ */ jsx(
|
|
15604
|
+
"span",
|
|
15309
15605
|
{
|
|
15310
15606
|
className: cn(
|
|
15311
|
-
"
|
|
15312
|
-
"
|
|
15313
|
-
"animate-in fade-in duration-300"
|
|
15607
|
+
"text-xs font-medium px-2 py-0.5 rounded",
|
|
15608
|
+
value ? badge === "info" ? "bg-blue-500/20 text-blue-400" : "bg-green-500/20 text-green-400" : "bg-red-500/20 text-red-400"
|
|
15314
15609
|
),
|
|
15610
|
+
children: value ? "Yes" : "No"
|
|
15611
|
+
}
|
|
15612
|
+
);
|
|
15613
|
+
}
|
|
15614
|
+
if (badge) {
|
|
15615
|
+
const badgeColors = {
|
|
15616
|
+
success: "bg-green-500/20 text-green-400",
|
|
15617
|
+
info: "bg-blue-500/20 text-blue-400",
|
|
15618
|
+
warning: "bg-yellow-500/20 text-yellow-400"
|
|
15619
|
+
};
|
|
15620
|
+
return /* @__PURE__ */ jsx("span", { className: cn("text-xs font-medium px-2 py-0.5 rounded", badgeColors[badge]), children: value });
|
|
15621
|
+
}
|
|
15622
|
+
return /* @__PURE__ */ jsx("span", { className: "text-xs text-icon3", children: value });
|
|
15623
|
+
};
|
|
15624
|
+
if (isLoading) {
|
|
15625
|
+
return /* @__PURE__ */ jsx("div", { className: "p-4", children: /* @__PURE__ */ jsx(Skeleton, { className: "h-32 w-full" }) });
|
|
15626
|
+
}
|
|
15627
|
+
if (!config || configSections.length === 0) {
|
|
15628
|
+
return /* @__PURE__ */ jsxs("div", { className: "p-4", children: [
|
|
15629
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-medium text-icon5 mb-3", children: "Memory Configuration" }),
|
|
15630
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-icon3", children: "No memory configuration available" })
|
|
15631
|
+
] });
|
|
15632
|
+
}
|
|
15633
|
+
return /* @__PURE__ */ jsxs("div", { className: "p-4", children: [
|
|
15634
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-medium text-icon5 mb-3", children: "Memory Configuration" }),
|
|
15635
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-2", children: configSections.map((section) => /* @__PURE__ */ jsxs("div", { className: "border border-border1 rounded-lg bg-surface3", children: [
|
|
15636
|
+
/* @__PURE__ */ jsxs(
|
|
15637
|
+
"button",
|
|
15638
|
+
{
|
|
15639
|
+
onClick: () => toggleSection(section.title),
|
|
15640
|
+
className: "w-full px-3 py-2 flex items-center justify-between hover:bg-surface4 transition-colors rounded-t-lg",
|
|
15315
15641
|
children: [
|
|
15316
|
-
/* @__PURE__ */ jsx(
|
|
15317
|
-
"
|
|
15642
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-icon5", children: section.title }),
|
|
15643
|
+
expandedSections.has(section.title) ? /* @__PURE__ */ jsx(ChevronDown, { className: "w-3 h-3 text-icon3" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "w-3 h-3 text-icon3" })
|
|
15318
15644
|
]
|
|
15319
15645
|
}
|
|
15320
|
-
)
|
|
15321
|
-
|
|
15322
|
-
|
|
15323
|
-
|
|
15324
|
-
|
|
15325
|
-
|
|
15326
|
-
|
|
15327
|
-
|
|
15328
|
-
|
|
15329
|
-
|
|
15330
|
-
|
|
15331
|
-
|
|
15332
|
-
|
|
15333
|
-
|
|
15334
|
-
|
|
15335
|
-
|
|
15646
|
+
),
|
|
15647
|
+
expandedSections.has(section.title) && /* @__PURE__ */ jsx("div", { className: "px-3 pb-2 space-y-1", children: section.items.map((item) => /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between py-1", children: [
|
|
15648
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-icon3", children: item.label }),
|
|
15649
|
+
renderValue(item.value || "", item.badge)
|
|
15650
|
+
] }, `${section.title}-${item.label}`)) })
|
|
15651
|
+
] }, section.title)) })
|
|
15652
|
+
] });
|
|
15653
|
+
};
|
|
15654
|
+
|
|
15655
|
+
const formatRelativeTime = (date) => {
|
|
15656
|
+
const now = /* @__PURE__ */ new Date();
|
|
15657
|
+
const seconds = Math.floor((now.getTime() - date.getTime()) / 1e3);
|
|
15658
|
+
if (seconds < 60) return "just now";
|
|
15659
|
+
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`;
|
|
15660
|
+
if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`;
|
|
15661
|
+
if (seconds < 604800) return `${Math.floor(seconds / 86400)}d ago`;
|
|
15662
|
+
return date.toLocaleDateString();
|
|
15663
|
+
};
|
|
15664
|
+
const MemorySearch = ({
|
|
15665
|
+
searchMemory,
|
|
15666
|
+
onResultClick,
|
|
15667
|
+
className,
|
|
15668
|
+
currentThreadId,
|
|
15669
|
+
chatInputValue
|
|
15670
|
+
}) => {
|
|
15671
|
+
const [query, setQuery] = useState("");
|
|
15672
|
+
const [results, setResults] = useState([]);
|
|
15673
|
+
const [isSearching, setIsSearching] = useState(false);
|
|
15674
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
15675
|
+
const [error, setError] = useState(null);
|
|
15676
|
+
const searchTimeoutRef = useRef(void 0);
|
|
15677
|
+
const dropdownRef = useRef(null);
|
|
15678
|
+
const prevThreadIdRef = useRef(currentThreadId);
|
|
15679
|
+
const lastSearchTimeRef = useRef(0);
|
|
15680
|
+
const pendingSearchRef = useRef(null);
|
|
15681
|
+
const handleSearch = useCallback(
|
|
15682
|
+
async (searchQuery) => {
|
|
15683
|
+
if (!searchQuery.trim()) {
|
|
15684
|
+
setError(null);
|
|
15685
|
+
return;
|
|
15686
|
+
}
|
|
15687
|
+
setIsSearching(true);
|
|
15688
|
+
setError(null);
|
|
15689
|
+
try {
|
|
15690
|
+
const response = await searchMemory(searchQuery);
|
|
15691
|
+
setResults(response.results);
|
|
15692
|
+
setIsOpen((prev) => prev || response.results.length > 0);
|
|
15693
|
+
} catch (err) {
|
|
15694
|
+
setError("Failed to search memory");
|
|
15695
|
+
console.error("Memory search error:", err);
|
|
15696
|
+
} finally {
|
|
15697
|
+
setIsSearching(false);
|
|
15698
|
+
}
|
|
15699
|
+
},
|
|
15700
|
+
[searchMemory]
|
|
15701
|
+
);
|
|
15702
|
+
const handleInputChange = useCallback(
|
|
15703
|
+
(e) => {
|
|
15704
|
+
const value = e.target.value;
|
|
15705
|
+
setQuery(value);
|
|
15706
|
+
if (searchTimeoutRef.current) {
|
|
15707
|
+
clearTimeout(searchTimeoutRef.current);
|
|
15708
|
+
}
|
|
15709
|
+
if (value.trim()) {
|
|
15710
|
+
const now = Date.now();
|
|
15711
|
+
const timeSinceLastSearch = now - lastSearchTimeRef.current;
|
|
15712
|
+
if (timeSinceLastSearch >= 500) {
|
|
15713
|
+
setIsSearching(true);
|
|
15714
|
+
handleSearch(value);
|
|
15715
|
+
lastSearchTimeRef.current = now;
|
|
15716
|
+
} else {
|
|
15717
|
+
setIsSearching(true);
|
|
15718
|
+
pendingSearchRef.current = value;
|
|
15719
|
+
const remainingTime = 500 - timeSinceLastSearch;
|
|
15720
|
+
searchTimeoutRef.current = setTimeout(() => {
|
|
15721
|
+
if (pendingSearchRef.current) {
|
|
15722
|
+
handleSearch(pendingSearchRef.current);
|
|
15723
|
+
lastSearchTimeRef.current = Date.now();
|
|
15724
|
+
pendingSearchRef.current = null;
|
|
15725
|
+
}
|
|
15726
|
+
}, remainingTime);
|
|
15727
|
+
}
|
|
15728
|
+
} else {
|
|
15729
|
+
setResults([]);
|
|
15730
|
+
setIsOpen(false);
|
|
15731
|
+
setIsSearching(false);
|
|
15732
|
+
pendingSearchRef.current = null;
|
|
15733
|
+
}
|
|
15734
|
+
},
|
|
15735
|
+
[handleSearch]
|
|
15736
|
+
);
|
|
15737
|
+
const handleKeyDown = useCallback(
|
|
15738
|
+
(e) => {
|
|
15739
|
+
if (e.key === "Enter") {
|
|
15740
|
+
e.preventDefault();
|
|
15741
|
+
if (searchTimeoutRef.current) {
|
|
15742
|
+
clearTimeout(searchTimeoutRef.current);
|
|
15743
|
+
}
|
|
15744
|
+
handleSearch(query);
|
|
15745
|
+
}
|
|
15746
|
+
},
|
|
15747
|
+
[query, handleSearch]
|
|
15748
|
+
);
|
|
15749
|
+
useEffect(() => {
|
|
15750
|
+
return () => {
|
|
15751
|
+
if (searchTimeoutRef.current) {
|
|
15752
|
+
clearTimeout(searchTimeoutRef.current);
|
|
15753
|
+
}
|
|
15754
|
+
};
|
|
15755
|
+
}, []);
|
|
15756
|
+
useEffect(() => {
|
|
15757
|
+
const handleClickOutside = (event) => {
|
|
15758
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
15759
|
+
setIsOpen(false);
|
|
15760
|
+
}
|
|
15761
|
+
};
|
|
15762
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
15763
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
15764
|
+
}, []);
|
|
15765
|
+
useEffect(() => {
|
|
15766
|
+
if (prevThreadIdRef.current !== currentThreadId && query.trim()) {
|
|
15767
|
+
handleSearch(query);
|
|
15768
|
+
}
|
|
15769
|
+
prevThreadIdRef.current = currentThreadId;
|
|
15770
|
+
}, [currentThreadId, query, handleSearch]);
|
|
15771
|
+
useEffect(() => {
|
|
15772
|
+
if (chatInputValue !== void 0 && chatInputValue !== query) {
|
|
15773
|
+
setQuery(chatInputValue);
|
|
15774
|
+
if (searchTimeoutRef.current) {
|
|
15775
|
+
clearTimeout(searchTimeoutRef.current);
|
|
15776
|
+
}
|
|
15777
|
+
if (chatInputValue.trim()) {
|
|
15778
|
+
const now = Date.now();
|
|
15779
|
+
const timeSinceLastSearch = now - lastSearchTimeRef.current;
|
|
15780
|
+
if (timeSinceLastSearch >= 500) {
|
|
15781
|
+
setIsSearching(true);
|
|
15782
|
+
handleSearch(chatInputValue);
|
|
15783
|
+
lastSearchTimeRef.current = now;
|
|
15784
|
+
} else {
|
|
15785
|
+
setIsSearching(true);
|
|
15786
|
+
pendingSearchRef.current = chatInputValue;
|
|
15787
|
+
const remainingTime = 500 - timeSinceLastSearch;
|
|
15788
|
+
searchTimeoutRef.current = setTimeout(() => {
|
|
15789
|
+
if (pendingSearchRef.current) {
|
|
15790
|
+
handleSearch(pendingSearchRef.current);
|
|
15791
|
+
lastSearchTimeRef.current = Date.now();
|
|
15792
|
+
pendingSearchRef.current = null;
|
|
15793
|
+
}
|
|
15794
|
+
}, remainingTime);
|
|
15795
|
+
}
|
|
15796
|
+
} else {
|
|
15797
|
+
setResults([]);
|
|
15798
|
+
setIsOpen(false);
|
|
15799
|
+
setIsSearching(false);
|
|
15800
|
+
pendingSearchRef.current = null;
|
|
15801
|
+
}
|
|
15802
|
+
}
|
|
15803
|
+
return () => {
|
|
15804
|
+
if (searchTimeoutRef.current) {
|
|
15805
|
+
clearTimeout(searchTimeoutRef.current);
|
|
15806
|
+
}
|
|
15807
|
+
};
|
|
15808
|
+
}, [chatInputValue]);
|
|
15809
|
+
const handleResultClick = (messageId, threadId) => {
|
|
15810
|
+
onResultClick?.(messageId, threadId);
|
|
15811
|
+
};
|
|
15812
|
+
const clearSearch = () => {
|
|
15813
|
+
setQuery("");
|
|
15814
|
+
setResults([]);
|
|
15815
|
+
setIsOpen(false);
|
|
15816
|
+
setError(null);
|
|
15817
|
+
if (searchTimeoutRef.current) {
|
|
15818
|
+
clearTimeout(searchTimeoutRef.current);
|
|
15819
|
+
}
|
|
15820
|
+
};
|
|
15821
|
+
const truncateContent = (content, maxLength = 100) => {
|
|
15822
|
+
if (content.length <= maxLength) return content;
|
|
15823
|
+
return content.substring(0, maxLength) + "...";
|
|
15824
|
+
};
|
|
15825
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col h-full", className), ref: dropdownRef, children: [
|
|
15826
|
+
/* @__PURE__ */ jsxs("div", { className: "relative shrink-0", children: [
|
|
15827
|
+
/* @__PURE__ */ jsx(Search, { className: "absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-icon3" }),
|
|
15828
|
+
/* @__PURE__ */ jsx(
|
|
15829
|
+
Input,
|
|
15830
|
+
{
|
|
15831
|
+
type: "text",
|
|
15832
|
+
value: query,
|
|
15833
|
+
onChange: handleInputChange,
|
|
15834
|
+
onKeyDown: handleKeyDown,
|
|
15835
|
+
placeholder: "Search memory...",
|
|
15836
|
+
className: "pl-10 pr-10 bg-surface3 border-border1"
|
|
15837
|
+
}
|
|
15838
|
+
),
|
|
15839
|
+
query && /* @__PURE__ */ jsx(
|
|
15840
|
+
Button$2,
|
|
15841
|
+
{
|
|
15842
|
+
onClick: clearSearch,
|
|
15843
|
+
variant: "ghost",
|
|
15844
|
+
size: "sm",
|
|
15845
|
+
className: "absolute right-1 top-1/2 transform -translate-y-1/2 h-6 w-6 p-0",
|
|
15846
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
15847
|
+
}
|
|
15848
|
+
)
|
|
15849
|
+
] }),
|
|
15850
|
+
(isOpen || query && (isSearching || results.length === 0)) && /* @__PURE__ */ jsx("div", { className: "mt-2 flex-1 bg-surface3 border border-border1 rounded-lg shadow-lg overflow-y-auto", children: error ? /* @__PURE__ */ jsx("div", { className: "p-4 text-center", children: /* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-red-500", children: error }) }) : isSearching && results.length === 0 ? /* @__PURE__ */ jsx("div", { className: "p-4 text-center", children: /* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon3", children: "Searching..." }) }) : results.length === 0 ? /* @__PURE__ */ jsx("div", { className: "p-4 text-center", children: /* @__PURE__ */ jsxs(Txt, { variant: "ui-sm", className: "text-icon3", children: [
|
|
15851
|
+
'No results found for "',
|
|
15852
|
+
query,
|
|
15853
|
+
'"'
|
|
15854
|
+
] }) }) : /* @__PURE__ */ jsx("div", { className: "py-2", children: results.map((result) => /* @__PURE__ */ jsx(
|
|
15855
|
+
"button",
|
|
15856
|
+
{
|
|
15857
|
+
onClick: () => handleResultClick(result.id, result.threadId),
|
|
15858
|
+
className: cn(
|
|
15859
|
+
"w-full px-4 py-3 hover:bg-surface4 transition-colors duration-150 text-left border-b border-border1 last:border-b-0",
|
|
15860
|
+
result.threadId !== currentThreadId && "border-l-2 border-l-blue-400"
|
|
15861
|
+
),
|
|
15862
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
15863
|
+
result.context?.before && result.context.before.length > 0 && /* @__PURE__ */ jsx("div", { className: "opacity-50 text-xs space-y-1", children: result.context.before.map((msg, idx) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
|
|
15864
|
+
/* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
|
|
15865
|
+
msg.role,
|
|
15866
|
+
":"
|
|
15867
|
+
] }),
|
|
15868
|
+
/* @__PURE__ */ jsx("span", { className: "text-icon3", children: truncateContent(msg.content, 50) })
|
|
15869
|
+
] }, idx)) }),
|
|
15870
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-start justify-between gap-2", children: /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
15871
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mb-1", children: [
|
|
15872
|
+
/* @__PURE__ */ jsx(
|
|
15873
|
+
"span",
|
|
15874
|
+
{
|
|
15875
|
+
className: cn(
|
|
15876
|
+
"text-xs font-medium px-2 py-0.5 rounded",
|
|
15877
|
+
result.role === "user" ? "bg-blue-500/20 text-blue-400" : "bg-green-500/20 text-green-400"
|
|
15878
|
+
),
|
|
15879
|
+
children: result.role
|
|
15880
|
+
}
|
|
15881
|
+
),
|
|
15882
|
+
/* @__PURE__ */ jsx(Txt, { variant: "ui-xs", className: "text-icon3", children: formatRelativeTime(new Date(result.createdAt)) }),
|
|
15883
|
+
result.threadTitle && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
15884
|
+
/* @__PURE__ */ jsxs(
|
|
15885
|
+
Txt,
|
|
15886
|
+
{
|
|
15887
|
+
variant: "ui-xs",
|
|
15888
|
+
className: cn(
|
|
15889
|
+
"truncate max-w-[150px]",
|
|
15890
|
+
result.threadId !== currentThreadId ? "text-blue-400 font-medium" : "text-icon3"
|
|
15891
|
+
),
|
|
15892
|
+
title: result.threadTitle,
|
|
15893
|
+
children: [
|
|
15894
|
+
"• ",
|
|
15895
|
+
result.threadTitle
|
|
15896
|
+
]
|
|
15897
|
+
}
|
|
15898
|
+
),
|
|
15899
|
+
result.threadId !== currentThreadId && /* @__PURE__ */ jsx(ExternalLink, { className: "w-3 h-3 text-blue-400" })
|
|
15900
|
+
] })
|
|
15901
|
+
] }),
|
|
15902
|
+
/* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon5 break-words", children: truncateContent(result.content) })
|
|
15903
|
+
] }) }),
|
|
15904
|
+
result.context?.after && result.context.after.length > 0 && /* @__PURE__ */ jsx("div", { className: "opacity-50 text-xs space-y-1", children: result.context.after.map((msg, idx) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
|
|
15905
|
+
/* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
|
|
15906
|
+
msg.role,
|
|
15907
|
+
":"
|
|
15908
|
+
] }),
|
|
15909
|
+
/* @__PURE__ */ jsx("span", { className: "text-icon3", children: truncateContent(msg.content, 50) })
|
|
15910
|
+
] }, idx)) })
|
|
15911
|
+
] })
|
|
15912
|
+
},
|
|
15913
|
+
result.id
|
|
15914
|
+
)) }) })
|
|
15915
|
+
] });
|
|
15916
|
+
};
|
|
15917
|
+
|
|
15918
|
+
function AgentMemory({ agentId, threadId }) {
|
|
15919
|
+
const { threadInput: chatInputValue } = useThreadInput();
|
|
15920
|
+
const { paths, navigate } = useLinkComponent();
|
|
15921
|
+
const [searchScope, setSearchScope] = useState(null);
|
|
15922
|
+
const { data } = useMemoryConfig(agentId);
|
|
15923
|
+
const config = data?.config;
|
|
15924
|
+
const isSemanticRecallEnabled = Boolean(config?.semanticRecall);
|
|
15925
|
+
const { searchMemory } = useMemorySearch({
|
|
15926
|
+
agentId: agentId || "",
|
|
15927
|
+
resourceId: agentId || "",
|
|
15928
|
+
// In playground, agentId is the resourceId
|
|
15929
|
+
threadId
|
|
15930
|
+
});
|
|
15931
|
+
const searchSemanticRecall = useCallback(
|
|
15932
|
+
async (query) => {
|
|
15933
|
+
const result = await searchMemory(query, { lastMessages: 0 });
|
|
15934
|
+
if (result.searchScope) {
|
|
15935
|
+
setSearchScope(result.searchScope);
|
|
15936
|
+
}
|
|
15937
|
+
return result;
|
|
15938
|
+
},
|
|
15939
|
+
[searchMemory]
|
|
15940
|
+
);
|
|
15941
|
+
const handleResultClick = useCallback(
|
|
15942
|
+
(messageId, resultThreadId) => {
|
|
15943
|
+
if (resultThreadId && resultThreadId !== threadId) {
|
|
15944
|
+
navigate(paths.agentThreadLink(agentId, resultThreadId, messageId));
|
|
15945
|
+
} else {
|
|
15946
|
+
const messageElement = document.querySelector(`[data-message-id="${messageId}"]`);
|
|
15947
|
+
if (messageElement) {
|
|
15948
|
+
messageElement.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
15949
|
+
messageElement.classList.add("bg-surface4");
|
|
15950
|
+
setTimeout(() => {
|
|
15951
|
+
messageElement.classList.remove("bg-surface4");
|
|
15952
|
+
}, 2e3);
|
|
15953
|
+
}
|
|
15954
|
+
}
|
|
15955
|
+
},
|
|
15956
|
+
[agentId, threadId, navigate]
|
|
15957
|
+
);
|
|
15958
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col h-full", children: [
|
|
15959
|
+
/* @__PURE__ */ jsxs("div", { className: "p-4 border-b border-border1", children: [
|
|
15960
|
+
/* @__PURE__ */ jsx("div", { className: "mb-2", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mb-2", children: [
|
|
15961
|
+
/* @__PURE__ */ jsx("h3", { className: "text-sm font-medium text-icon5", children: "Semantic Recall" }),
|
|
15962
|
+
searchScope && /* @__PURE__ */ jsx(
|
|
15963
|
+
"span",
|
|
15964
|
+
{
|
|
15965
|
+
className: cn(
|
|
15966
|
+
"text-xs font-medium px-2 py-0.5 rounded",
|
|
15967
|
+
searchScope === "resource" ? "bg-purple-500/20 text-purple-400" : "bg-blue-500/20 text-blue-400"
|
|
15968
|
+
),
|
|
15969
|
+
title: searchScope === "resource" ? "Searching across all threads" : "Searching within current thread only",
|
|
15970
|
+
children: searchScope
|
|
15971
|
+
}
|
|
15972
|
+
)
|
|
15973
|
+
] }) }),
|
|
15974
|
+
isSemanticRecallEnabled ? /* @__PURE__ */ jsx(
|
|
15975
|
+
MemorySearch,
|
|
15976
|
+
{
|
|
15977
|
+
searchMemory: searchSemanticRecall,
|
|
15978
|
+
onResultClick: handleResultClick,
|
|
15979
|
+
currentThreadId: threadId,
|
|
15980
|
+
className: "w-full",
|
|
15981
|
+
chatInputValue
|
|
15982
|
+
}
|
|
15983
|
+
) : /* @__PURE__ */ jsxs("div", { className: "bg-surface3 border border-border1 rounded-lg p-4", children: [
|
|
15984
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-icon3 mb-3", children: "Semantic recall is not enabled for this agent. Enable it to search through conversation history." }),
|
|
15985
|
+
/* @__PURE__ */ jsxs(
|
|
15986
|
+
"a",
|
|
15987
|
+
{
|
|
15988
|
+
href: "https://mastra.ai/en/docs/memory/semantic-recall",
|
|
15989
|
+
target: "_blank",
|
|
15990
|
+
rel: "noopener noreferrer",
|
|
15991
|
+
className: "inline-flex items-center gap-2 text-sm text-blue-400 hover:text-blue-300 transition-colors",
|
|
15992
|
+
children: [
|
|
15993
|
+
"Learn about semantic recall",
|
|
15994
|
+
/* @__PURE__ */ jsx(ExternalLink, { className: "w-3 h-3" })
|
|
15995
|
+
]
|
|
15996
|
+
}
|
|
15997
|
+
)
|
|
15998
|
+
] })
|
|
15999
|
+
] }),
|
|
16000
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-y-auto", children: [
|
|
16001
|
+
/* @__PURE__ */ jsx(AgentWorkingMemory, { agentId }),
|
|
16002
|
+
/* @__PURE__ */ jsx("div", { className: "border-t border-border1", children: /* @__PURE__ */ jsx(AgentMemoryConfig, { agentId }) })
|
|
16003
|
+
] })
|
|
16004
|
+
] });
|
|
16005
|
+
}
|
|
16006
|
+
|
|
16007
|
+
function CurrentInstructions({
|
|
16008
|
+
instructions,
|
|
16009
|
+
enhancedPrompt,
|
|
16010
|
+
isEnhancing,
|
|
16011
|
+
userComment,
|
|
16012
|
+
onEnhance,
|
|
16013
|
+
onCancel,
|
|
16014
|
+
onSave,
|
|
16015
|
+
onCommentChange,
|
|
16016
|
+
onShowHistory
|
|
16017
|
+
}) {
|
|
16018
|
+
const currentContent = enhancedPrompt || extractPrompt(instructions);
|
|
16019
|
+
const { isCopied, handleCopy } = useCopyToClipboard({ text: currentContent || "" });
|
|
16020
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
16021
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-4 pb-2", children: enhancedPrompt ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
|
|
16022
|
+
/* @__PURE__ */ jsx("button", { onClick: onCancel, children: /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
16023
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Icon, { className: "hover:bg-surface2 rounded-lg", children: /* @__PURE__ */ jsx(X, { className: "text-accent2" }) }) }),
|
|
16024
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: "Discard prompt suggestions" })
|
|
16025
|
+
] }) }),
|
|
16026
|
+
/* @__PURE__ */ jsx("button", { onClick: onSave, disabled: !enhancedPrompt, children: /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
16027
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Icon, { className: "hover:bg-surface2 rounded-lg", children: /* @__PURE__ */ jsx(CheckIcon$1, { className: "text-accent1" }) }) }),
|
|
16028
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: "Save prompt suggestions" })
|
|
16029
|
+
] }) })
|
|
16030
|
+
] }) : /* @__PURE__ */ jsx("button", { onClick: onShowHistory, children: /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
16031
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Icon, { className: "hover:bg-surface2 rounded-lg text-icon3 hover:text-icon6", children: /* @__PURE__ */ jsx(FileClock, {}) }) }),
|
|
16032
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: "Version history" })
|
|
16033
|
+
] }) }) }),
|
|
16034
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("div", { className: clsx("p-[1px] rounded-lg overflow-hidden relative"), children: [
|
|
16035
|
+
/* @__PURE__ */ jsx(
|
|
16036
|
+
"div",
|
|
16037
|
+
{
|
|
16038
|
+
className: clsx(
|
|
16039
|
+
"absolute inset-0 bg-surface4 transition-all",
|
|
16040
|
+
enhancedPrompt && "bg-gradient-to-br from-accent1 to-accent3"
|
|
16041
|
+
)
|
|
16042
|
+
}
|
|
16043
|
+
),
|
|
16044
|
+
/* @__PURE__ */ jsxs("div", { className: "relative z-10 bg-surface4 rounded-lg", children: [
|
|
16045
|
+
/* @__PURE__ */ jsx(
|
|
16046
|
+
CodeDisplay,
|
|
16047
|
+
{
|
|
16048
|
+
content: currentContent || "",
|
|
16049
|
+
isCopied,
|
|
16050
|
+
isDraft: !!enhancedPrompt,
|
|
16051
|
+
onCopy: () => currentContent && handleCopy(),
|
|
16052
|
+
className: "border-none bg-surface4 text-ui-sm p-2 !h-[260px]"
|
|
16053
|
+
}
|
|
16054
|
+
),
|
|
16055
|
+
/* @__PURE__ */ jsx("div", { className: "px-3 py-3", children: /* @__PURE__ */ jsxs("div", { className: "flex justify-between rounded-lg border border-border1 bg-surface5 shadow-lg disabled:bg-surface3 text-icon6 w-full py-2 px-3 gap-3 relative z-10", children: [
|
|
16056
|
+
/* @__PURE__ */ jsx(
|
|
16057
|
+
"textarea",
|
|
16058
|
+
{
|
|
16059
|
+
value: userComment,
|
|
16060
|
+
onChange: (e) => onCommentChange(e.target.value),
|
|
16061
|
+
placeholder: "Add your comments or requirements for enhancing your agent's prompt...",
|
|
16062
|
+
className: "resize-none text-ui-sm w-full placeholder:text-icon3 bg-transparent block disabled:text-icon3",
|
|
16063
|
+
disabled: Boolean(isEnhancing || enhancedPrompt)
|
|
16064
|
+
}
|
|
16065
|
+
),
|
|
16066
|
+
/* @__PURE__ */ jsx("button", { onClick: onEnhance, disabled: isEnhancing || !instructions || Boolean(enhancedPrompt), children: /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
16067
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Icon, { className: "text-icon3 hover:text-icon6 disabled:hover:text-icon3", children: isEnhancing ? /* @__PURE__ */ jsx(Loader, { className: "animate-spin" }) : /* @__PURE__ */ jsx(Wand2, {}) }) }),
|
|
16068
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: isEnhancing ? "Enhancing..." : "Enhance prompt" })
|
|
16069
|
+
] }) })
|
|
16070
|
+
] }) })
|
|
16071
|
+
] })
|
|
16072
|
+
] }) })
|
|
16073
|
+
] });
|
|
16074
|
+
}
|
|
16075
|
+
|
|
16076
|
+
function usePromptEnhancer({
|
|
16077
|
+
agentId,
|
|
16078
|
+
instructions,
|
|
16079
|
+
versions,
|
|
16080
|
+
onVersionCreate,
|
|
16081
|
+
onVersionUpdate
|
|
16082
|
+
}) {
|
|
16083
|
+
const [enhancedPrompt, setEnhancedPrompt] = useState("");
|
|
16084
|
+
const [explanation, setExplanation] = useState("");
|
|
16085
|
+
const [isEnhancing, setIsEnhancing] = useState(false);
|
|
16086
|
+
const [userComment, setUserComment] = useState("");
|
|
16087
|
+
const enhancePrompt = async () => {
|
|
16088
|
+
if (!instructions) return;
|
|
16089
|
+
setIsEnhancing(true);
|
|
16090
|
+
try {
|
|
16091
|
+
const response = await fetch(`/api/agents/${agentId}/instructions/enhance`, {
|
|
16092
|
+
method: "POST",
|
|
16093
|
+
headers: {
|
|
16094
|
+
"Content-Type": "application/json",
|
|
16095
|
+
"x-mastra-dev-playground": "true"
|
|
16096
|
+
},
|
|
16097
|
+
body: JSON.stringify({
|
|
16098
|
+
instructions,
|
|
16099
|
+
comment: userComment
|
|
16100
|
+
})
|
|
16101
|
+
});
|
|
16102
|
+
if (!response.ok) {
|
|
16103
|
+
throw new Error("Failed to enhance prompt");
|
|
16104
|
+
}
|
|
16105
|
+
const data = await response.json();
|
|
16106
|
+
setEnhancedPrompt(data.new_prompt);
|
|
16107
|
+
setExplanation(data.explanation);
|
|
16108
|
+
setUserComment("");
|
|
16109
|
+
} catch (error) {
|
|
16110
|
+
console.error("Failed to enhance prompt:", error);
|
|
16111
|
+
} finally {
|
|
16112
|
+
setIsEnhancing(false);
|
|
16113
|
+
}
|
|
16114
|
+
};
|
|
16115
|
+
const clearEnhancement = () => {
|
|
16116
|
+
setEnhancedPrompt("");
|
|
16117
|
+
setExplanation("");
|
|
16118
|
+
};
|
|
16119
|
+
const applyChanges = () => {
|
|
16120
|
+
if (!enhancedPrompt) return;
|
|
16121
|
+
const draftIndex = versions.findIndex((v) => v.status === "draft");
|
|
16122
|
+
if (draftIndex !== -1) {
|
|
16123
|
+
onVersionUpdate(draftIndex, {
|
|
16124
|
+
content: enhancedPrompt,
|
|
16125
|
+
analysis: explanation,
|
|
16126
|
+
status: "published",
|
|
16127
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
16128
|
+
});
|
|
16129
|
+
} else {
|
|
16130
|
+
const newVersion = {
|
|
16131
|
+
content: enhancedPrompt,
|
|
16132
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
16133
|
+
analysis: explanation,
|
|
16134
|
+
status: "published"
|
|
16135
|
+
};
|
|
16136
|
+
onVersionCreate(newVersion);
|
|
16137
|
+
}
|
|
16138
|
+
clearEnhancement();
|
|
16139
|
+
};
|
|
16140
|
+
return {
|
|
16141
|
+
enhancedPrompt,
|
|
16142
|
+
explanation,
|
|
16143
|
+
isEnhancing,
|
|
16144
|
+
userComment,
|
|
16145
|
+
enhancePrompt,
|
|
16146
|
+
setUserComment,
|
|
16147
|
+
clearEnhancement,
|
|
16148
|
+
applyChanges
|
|
16149
|
+
};
|
|
16150
|
+
}
|
|
16151
|
+
|
|
16152
|
+
function usePromptVersions(agentId, instructions) {
|
|
16153
|
+
const [versions, setVersions] = useState([]);
|
|
16154
|
+
const [copiedVersions, setCopiedVersions] = useState({});
|
|
16155
|
+
const [isUpdating, setIsUpdating] = useState(false);
|
|
16156
|
+
const [versionToDelete, setVersionToDelete] = useState(null);
|
|
16157
|
+
const client = useMastraClient();
|
|
16158
|
+
const { runtimeContext } = usePlaygroundStore();
|
|
16159
|
+
const fetchEvalResults = async () => {
|
|
16160
|
+
try {
|
|
16161
|
+
const response = await client.getAgent(agentId).liveEvals(runtimeContext);
|
|
16162
|
+
return response?.evals;
|
|
16163
|
+
} catch (error) {
|
|
16164
|
+
console.error("Failed to fetch eval results:", error);
|
|
16165
|
+
return [];
|
|
16166
|
+
}
|
|
16167
|
+
};
|
|
16168
|
+
useEffect(() => {
|
|
16169
|
+
const loadVersions = async () => {
|
|
16170
|
+
const evals = await fetchEvalResults();
|
|
16171
|
+
const storedVersions = localStorage.getItem(`agent-${agentId}-versions`);
|
|
16172
|
+
if (storedVersions) {
|
|
16173
|
+
const parsedVersions = JSON.parse(storedVersions);
|
|
16174
|
+
const originalVersion = parsedVersions.find((v) => v.status === "original");
|
|
16175
|
+
if (instructions && originalVersion && originalVersion.content !== instructions) {
|
|
16176
|
+
const originalEvals = evals?.filter((m) => m.meta.instructions === instructions);
|
|
16177
|
+
const newVersions = [
|
|
16178
|
+
{
|
|
16179
|
+
content: instructions,
|
|
16180
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
16181
|
+
analysis: "Original instructions",
|
|
16182
|
+
status: "original",
|
|
16183
|
+
evals: originalEvals
|
|
16184
|
+
}
|
|
16185
|
+
];
|
|
16186
|
+
newVersions[0].evals = evals;
|
|
16187
|
+
setVersions(newVersions);
|
|
16188
|
+
localStorage.setItem(`agent-${agentId}-versions`, JSON.stringify(newVersions));
|
|
16189
|
+
} else {
|
|
16190
|
+
const updatedVersions = await Promise.all(
|
|
16191
|
+
parsedVersions.map(async (v) => {
|
|
16192
|
+
const originalEvals = evals?.filter((m) => m.meta.instructions === v.content);
|
|
16193
|
+
const version = {
|
|
16194
|
+
...v,
|
|
16195
|
+
timestamp: new Date(v.timestamp),
|
|
16196
|
+
status: v.content === instructions ? "active" : v.status === "active" ? "published" : v.status
|
|
16197
|
+
};
|
|
16198
|
+
return { ...version, evals: originalEvals };
|
|
16199
|
+
})
|
|
16200
|
+
);
|
|
16201
|
+
setVersions(updatedVersions);
|
|
16202
|
+
}
|
|
16203
|
+
} else if (instructions) {
|
|
16204
|
+
const initialVersions = [
|
|
16205
|
+
{
|
|
16206
|
+
content: instructions,
|
|
16207
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
16208
|
+
analysis: "Original instructions",
|
|
16209
|
+
status: "original",
|
|
16210
|
+
evals: []
|
|
16211
|
+
}
|
|
16212
|
+
];
|
|
16213
|
+
const originalEvals = evals?.filter((m) => m.meta.instructions === instructions);
|
|
16214
|
+
initialVersions[0].evals = originalEvals;
|
|
16215
|
+
setVersions(initialVersions);
|
|
16216
|
+
localStorage.setItem(`agent-${agentId}-versions`, JSON.stringify(initialVersions));
|
|
16217
|
+
}
|
|
16218
|
+
};
|
|
16219
|
+
loadVersions();
|
|
16220
|
+
}, [instructions, agentId]);
|
|
16221
|
+
useEffect(() => {
|
|
16222
|
+
if (versions.length > 0) {
|
|
16223
|
+
localStorage.setItem(`agent-${agentId}-versions`, JSON.stringify(versions));
|
|
16224
|
+
}
|
|
16225
|
+
}, [versions, agentId]);
|
|
16226
|
+
const copyToClipboard = async (text, versionIndex) => {
|
|
16227
|
+
setCopiedVersions((prev) => ({ ...prev, [versionIndex]: true }));
|
|
16228
|
+
const timer = setTimeout(() => {
|
|
16229
|
+
setCopiedVersions((prev) => ({ ...prev, [versionIndex]: false }));
|
|
16230
|
+
}, 1e3);
|
|
16231
|
+
return () => clearTimeout(timer);
|
|
16232
|
+
};
|
|
16233
|
+
const setVersionActive = async (version, index) => {
|
|
16234
|
+
setIsUpdating(true);
|
|
16235
|
+
try {
|
|
16236
|
+
const response = await fetch(`/api/agents/${agentId}/instructions`, {
|
|
16237
|
+
method: "POST",
|
|
16238
|
+
headers: {
|
|
16239
|
+
"Content-Type": "application/json",
|
|
16240
|
+
"x-mastra-dev-playground": "true"
|
|
16241
|
+
},
|
|
16242
|
+
body: JSON.stringify({
|
|
16243
|
+
instructions: version.content
|
|
16244
|
+
})
|
|
16245
|
+
});
|
|
16246
|
+
if (!response.ok) {
|
|
16247
|
+
throw new Error("Failed to update instructions");
|
|
16248
|
+
}
|
|
16249
|
+
setVersions(
|
|
16250
|
+
(prev) => prev.map((v, i) => ({
|
|
16251
|
+
...v,
|
|
16252
|
+
status: i === index ? "active" : v.status === "active" ? "published" : v.status
|
|
16253
|
+
}))
|
|
16254
|
+
);
|
|
16255
|
+
} catch (error) {
|
|
16256
|
+
console.error("Failed to set version as active:", error);
|
|
16257
|
+
} finally {
|
|
16258
|
+
setIsUpdating(false);
|
|
16259
|
+
}
|
|
16260
|
+
};
|
|
16261
|
+
const deleteVersion = (index) => {
|
|
16262
|
+
setVersions((prev) => prev.filter((_, i) => i !== index));
|
|
16263
|
+
setVersionToDelete(null);
|
|
16264
|
+
};
|
|
16265
|
+
const updateVersion = async (index, updates) => {
|
|
16266
|
+
const updatedVersion = {
|
|
16267
|
+
...versions[index],
|
|
16268
|
+
...updates
|
|
16269
|
+
};
|
|
16270
|
+
setVersions((prev) => prev.map((version, i) => i === index ? updatedVersion : version));
|
|
16271
|
+
};
|
|
16272
|
+
return {
|
|
16273
|
+
versions,
|
|
16274
|
+
copiedVersions,
|
|
16275
|
+
isUpdating,
|
|
16276
|
+
versionToDelete,
|
|
16277
|
+
setVersions,
|
|
16278
|
+
setVersionToDelete,
|
|
16279
|
+
copyToClipboard,
|
|
16280
|
+
setVersionActive,
|
|
16281
|
+
deleteVersion,
|
|
16282
|
+
updateVersion
|
|
16283
|
+
};
|
|
16284
|
+
}
|
|
16285
|
+
|
|
16286
|
+
function VersionActions({ version, index, isUpdating, onSetActive, onDelete }) {
|
|
16287
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-1", children: [
|
|
16288
|
+
version.status !== "active" && version.status !== "draft" && /* @__PURE__ */ jsx(
|
|
16289
|
+
Button$2,
|
|
16290
|
+
{
|
|
16291
|
+
variant: "ghost",
|
|
16292
|
+
size: "sm",
|
|
16293
|
+
className: "h-6 px-2 hover:bg-mastra-bg-3 relative group",
|
|
16294
|
+
onClick: (e) => {
|
|
16295
|
+
e.stopPropagation();
|
|
16296
|
+
onSetActive(version, index);
|
|
16297
|
+
},
|
|
16298
|
+
disabled: isUpdating,
|
|
16299
|
+
children: /* @__PURE__ */ jsx(Play, { className: "h-3 w-3" })
|
|
16300
|
+
}
|
|
16301
|
+
),
|
|
16302
|
+
index !== 0 && version.status !== "active" && /* @__PURE__ */ jsx(
|
|
16303
|
+
Button$2,
|
|
16304
|
+
{
|
|
16305
|
+
variant: "ghost",
|
|
16306
|
+
size: "sm",
|
|
16307
|
+
className: "h-6 px-2 hover:bg-mastra-bg-3 relative group",
|
|
16308
|
+
onClick: (e) => {
|
|
16309
|
+
e.stopPropagation();
|
|
16310
|
+
onDelete(index);
|
|
16311
|
+
},
|
|
16312
|
+
children: /* @__PURE__ */ jsx(Trash2, { className: "h-3 w-3 text-red-400 hover:text-red-500" })
|
|
16313
|
+
}
|
|
16314
|
+
)
|
|
16315
|
+
] });
|
|
16316
|
+
}
|
|
16317
|
+
|
|
16318
|
+
function VersionItem({
|
|
16319
|
+
version,
|
|
16320
|
+
index,
|
|
16321
|
+
isExpanded,
|
|
16322
|
+
isUpdating,
|
|
16323
|
+
onToggleExpand,
|
|
16324
|
+
onToggleAnalysis,
|
|
16325
|
+
onSetActive,
|
|
16326
|
+
onDelete
|
|
16327
|
+
}) {
|
|
16328
|
+
const [showEvals, setShowEvals] = useState(false);
|
|
16329
|
+
const [showInstructions, setShowInstructions] = useState(true);
|
|
16330
|
+
const [showAnalysis, setShowAnalysis] = useState(false);
|
|
16331
|
+
const { handleCopy, isCopied } = useCopyToClipboard({
|
|
16332
|
+
text: version.content
|
|
16333
|
+
});
|
|
16334
|
+
const formatText = (text) => {
|
|
16335
|
+
return text.replace(/\\n/g, "\n");
|
|
16336
|
+
};
|
|
16337
|
+
return /* @__PURE__ */ jsxs(
|
|
16338
|
+
"div",
|
|
16339
|
+
{
|
|
16340
|
+
className: `rounded-md border ${isExpanded ? "border-mastra-purple/30" : "border-mastra-bg-3"} bg-mastra-bg-2`,
|
|
16341
|
+
children: [
|
|
16342
|
+
/* @__PURE__ */ jsxs(
|
|
16343
|
+
"div",
|
|
16344
|
+
{
|
|
16345
|
+
className: "p-2 flex items-center justify-between cursor-pointer hover:bg-mastra-bg-3/50",
|
|
16346
|
+
onClick: onToggleExpand,
|
|
16347
|
+
children: [
|
|
16348
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-2", children: [
|
|
16349
|
+
/* @__PURE__ */ jsx(
|
|
16350
|
+
ChevronRight,
|
|
16351
|
+
{
|
|
16352
|
+
className: `h-3 w-3 transition-transform ${isExpanded ? "rotate-90 text-mastra-purple" : ""}`
|
|
16353
|
+
}
|
|
16354
|
+
),
|
|
16355
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
16356
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-2", children: [
|
|
16357
|
+
/* @__PURE__ */ jsxs("p", { className: "text-xs font-medium text-mastra-el-4", children: [
|
|
16358
|
+
"Version ",
|
|
16359
|
+
index + 1
|
|
16360
|
+
] }),
|
|
16361
|
+
version.status === "active" && /* @__PURE__ */ jsx("span", { className: "text-[10px] px-1.5 py-0.5 rounded-full bg-green-500/20 text-green-500", children: "Active" }),
|
|
16362
|
+
version.status === "original" && /* @__PURE__ */ jsx("span", { className: "text-[10px] px-1.5 py-0.5 rounded-full bg-blue-500/20 text-blue-500", children: "Original" }),
|
|
16363
|
+
version.status === "draft" && /* @__PURE__ */ jsx("span", { className: "text-[10px] px-1.5 py-0.5 rounded-full bg-yellow-500/20 text-yellow-500", children: "Draft" })
|
|
16364
|
+
] }),
|
|
16365
|
+
/* @__PURE__ */ jsx("p", { className: "text-[10px] text-mastra-el-3", children: version.timestamp.toLocaleString() })
|
|
16366
|
+
] })
|
|
16367
|
+
] }),
|
|
16368
|
+
/* @__PURE__ */ jsx(
|
|
16369
|
+
VersionActions,
|
|
16370
|
+
{
|
|
16371
|
+
version,
|
|
16372
|
+
index,
|
|
16373
|
+
isUpdating,
|
|
16374
|
+
onSetActive,
|
|
16375
|
+
onDelete
|
|
16376
|
+
}
|
|
16377
|
+
)
|
|
16378
|
+
]
|
|
16379
|
+
}
|
|
16380
|
+
),
|
|
16381
|
+
isExpanded && /* @__PURE__ */ jsx(ScrollArea, { className: "h-[250px]", children: /* @__PURE__ */ jsxs("div", { className: "px-2 pb-2 space-y-2", children: [
|
|
16382
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
16383
|
+
/* @__PURE__ */ jsxs(
|
|
16384
|
+
"div",
|
|
16385
|
+
{
|
|
16386
|
+
className: "flex items-center space-x-1 cursor-pointer hover:bg-mastra-bg-3/50 p-1 rounded-md mb-2",
|
|
16387
|
+
onClick: (e) => {
|
|
16388
|
+
e.stopPropagation();
|
|
16389
|
+
setShowInstructions(!showInstructions);
|
|
16390
|
+
},
|
|
16391
|
+
children: [
|
|
16392
|
+
/* @__PURE__ */ jsx(ChevronRight, { className: `h-3 w-3 transition-transform ${showInstructions ? "rotate-90" : ""}` }),
|
|
16393
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-mastra-el-4", children: "Instructions" })
|
|
16394
|
+
]
|
|
16395
|
+
}
|
|
16396
|
+
),
|
|
16397
|
+
showInstructions && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-mastra-bg-3", children: /* @__PURE__ */ jsx("div", { className: "mt-2", children: /* @__PURE__ */ jsx(CodeDisplay, { content: formatText(version.content), isCopied, onCopy: handleCopy }) }) })
|
|
16398
|
+
] }),
|
|
16399
|
+
version.analysis && /* @__PURE__ */ jsxs("div", { children: [
|
|
16400
|
+
/* @__PURE__ */ jsxs(
|
|
16401
|
+
"div",
|
|
16402
|
+
{
|
|
16403
|
+
className: "flex items-center space-x-1 cursor-pointer hover:bg-mastra-bg-3/50 p-1 rounded-md mb-2",
|
|
16404
|
+
onClick: (e) => {
|
|
16405
|
+
e.stopPropagation();
|
|
16406
|
+
setShowAnalysis(!showAnalysis);
|
|
16407
|
+
},
|
|
16408
|
+
children: [
|
|
16409
|
+
/* @__PURE__ */ jsx(ChevronRight, { className: `h-3 w-3 transition-transform ${showAnalysis ? "rotate-90" : ""}` }),
|
|
16410
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-mastra-el-4", children: "Analysis" })
|
|
16411
|
+
]
|
|
16412
|
+
}
|
|
16413
|
+
),
|
|
16414
|
+
showAnalysis && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-mastra-bg-3", children: /* @__PURE__ */ jsx("div", { className: "p-2", children: /* @__PURE__ */ jsx("pre", { className: "text-[10px] text-mastra-el-4 whitespace-pre-wrap font-mono", children: formatText(version.analysis || "") }) }) })
|
|
16415
|
+
] }),
|
|
16416
|
+
version.evals && version.evals.length > 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
16417
|
+
/* @__PURE__ */ jsxs(
|
|
16418
|
+
"div",
|
|
16419
|
+
{
|
|
16420
|
+
className: "flex items-center space-x-1 cursor-pointer hover:bg-mastra-bg-3/50 p-1 rounded-md",
|
|
16421
|
+
onClick: (e) => {
|
|
16422
|
+
e.stopPropagation();
|
|
16423
|
+
setShowEvals(!showEvals);
|
|
16424
|
+
},
|
|
16425
|
+
children: [
|
|
16426
|
+
/* @__PURE__ */ jsx(ChevronRight, { className: `h-3 w-3 transition-transform ${showEvals ? "rotate-90" : ""}` }),
|
|
16427
|
+
/* @__PURE__ */ jsxs("p", { className: "text-xs font-medium text-mastra-el-4", children: [
|
|
16428
|
+
"Evaluations (",
|
|
16429
|
+
version.evals.length,
|
|
16430
|
+
")"
|
|
16431
|
+
] })
|
|
16432
|
+
]
|
|
16433
|
+
}
|
|
16434
|
+
),
|
|
16435
|
+
showEvals && /* @__PURE__ */ jsx("div", { className: "pl-4", children: /* @__PURE__ */ jsx("div", { className: "space-y-1 pr-4", children: version.evals.map((metric, evalIndex) => /* @__PURE__ */ jsxs("div", { className: "rounded-md border border-mastra-bg-3 p-1.5 text-[10px]", children: [
|
|
16436
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-2", children: [
|
|
16437
|
+
/* @__PURE__ */ jsx(
|
|
16438
|
+
"span",
|
|
16439
|
+
{
|
|
16440
|
+
className: `px-1.5 py-0.5 rounded-full min-w-[32px] text-center ${metric.result.score >= 0.7 ? "bg-green-500/20 text-green-500" : metric.result.score >= 0.4 ? "bg-yellow-500/20 text-yellow-500" : "bg-red-500/20 text-red-500"}`,
|
|
16441
|
+
children: metric.result.score.toFixed(2)
|
|
16442
|
+
}
|
|
16443
|
+
),
|
|
16444
|
+
/* @__PURE__ */ jsx("span", { className: "text-mastra-el-3 text-[9px]", children: new Date(metric.createdAt).toLocaleTimeString() })
|
|
16445
|
+
] }) }),
|
|
16446
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-1 space-y-1", children: [
|
|
16447
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-1.5", children: [
|
|
16448
|
+
/* @__PURE__ */ jsx("span", { className: "text-mastra-el-3 shrink-0", children: "→" }),
|
|
16449
|
+
/* @__PURE__ */ jsx("span", { className: "text-mastra-el-4", children: metric.input })
|
|
16450
|
+
] }),
|
|
16451
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-1.5", children: [
|
|
16452
|
+
/* @__PURE__ */ jsx("span", { className: "text-mastra-el-3 shrink-0", children: "←" }),
|
|
16453
|
+
/* @__PURE__ */ jsx("span", { className: "text-mastra-el-4", children: metric.output })
|
|
16454
|
+
] }),
|
|
16455
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-1.5 text-[9px] text-mastra-el-3", children: [
|
|
16456
|
+
/* @__PURE__ */ jsx("span", { className: "shrink-0", children: "⚬" }),
|
|
16457
|
+
/* @__PURE__ */ jsx("span", { children: metric.result.info.reason })
|
|
16458
|
+
] })
|
|
16459
|
+
] })
|
|
16460
|
+
] }, evalIndex)) }) })
|
|
16461
|
+
] })
|
|
16462
|
+
] }) })
|
|
16463
|
+
]
|
|
16464
|
+
}
|
|
16465
|
+
);
|
|
16466
|
+
}
|
|
16467
|
+
|
|
16468
|
+
function VersionHistory({
|
|
16469
|
+
versions,
|
|
16470
|
+
isUpdating,
|
|
16471
|
+
copiedVersions,
|
|
16472
|
+
onCopy,
|
|
16473
|
+
onSetActive,
|
|
16474
|
+
onDelete
|
|
16475
|
+
}) {
|
|
16476
|
+
const [expandedVersion, setExpandedVersion] = useState(null);
|
|
16477
|
+
const [expandedAnalysis, setExpandedAnalysis] = useState(null);
|
|
16478
|
+
return /* @__PURE__ */ jsx(ScrollArea, { className: "flex-1", children: /* @__PURE__ */ jsx("div", { className: "space-y-2 pr-4", children: versions.map((version, index) => /* @__PURE__ */ jsx(
|
|
16479
|
+
VersionItem,
|
|
16480
|
+
{
|
|
16481
|
+
version,
|
|
16482
|
+
index,
|
|
16483
|
+
isExpanded: expandedVersion === index,
|
|
16484
|
+
isUpdating,
|
|
16485
|
+
copiedVersions,
|
|
16486
|
+
onToggleExpand: () => {
|
|
16487
|
+
if (expandedVersion === index) {
|
|
16488
|
+
return setExpandedVersion(null);
|
|
16489
|
+
}
|
|
16490
|
+
setExpandedVersion(index);
|
|
16491
|
+
},
|
|
16492
|
+
onToggleAnalysis: () => {
|
|
16493
|
+
if (expandedAnalysis === index) {
|
|
16494
|
+
return setExpandedAnalysis(null);
|
|
16495
|
+
}
|
|
16496
|
+
setExpandedAnalysis(index);
|
|
16497
|
+
},
|
|
16498
|
+
onCopy,
|
|
16499
|
+
onSetActive,
|
|
16500
|
+
onDelete
|
|
16501
|
+
},
|
|
16502
|
+
index
|
|
16503
|
+
)) }) });
|
|
16504
|
+
}
|
|
16505
|
+
|
|
16506
|
+
const VersionHistoryDialog = ({
|
|
16507
|
+
open,
|
|
16508
|
+
onOpenChange,
|
|
16509
|
+
onDelete,
|
|
16510
|
+
onSetActive,
|
|
16511
|
+
versions,
|
|
16512
|
+
isUpdating
|
|
16513
|
+
}) => {
|
|
16514
|
+
return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { className: "bg-surface4", children: [
|
|
16515
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
16516
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: "Version History" }),
|
|
16517
|
+
/* @__PURE__ */ jsx(DialogDescription, { children: "View the history of changes to the agent's instructions." })
|
|
16518
|
+
] }),
|
|
16519
|
+
/* @__PURE__ */ jsx(
|
|
16520
|
+
VersionHistory,
|
|
16521
|
+
{
|
|
16522
|
+
versions,
|
|
16523
|
+
isUpdating,
|
|
16524
|
+
copiedVersions: {},
|
|
16525
|
+
onCopy: async (content, key) => {
|
|
16526
|
+
await navigator.clipboard.writeText(content);
|
|
16527
|
+
},
|
|
16528
|
+
onSetActive,
|
|
16529
|
+
onDelete
|
|
16530
|
+
}
|
|
16531
|
+
)
|
|
16532
|
+
] }) });
|
|
16533
|
+
};
|
|
16534
|
+
|
|
16535
|
+
function AgentPromptEnhancer({ agentId }) {
|
|
16536
|
+
const { data: agent } = useAgent(agentId);
|
|
16537
|
+
const [showVersionHistoryDialog, setShowVersionHistoryDialog] = useState(false);
|
|
16538
|
+
const formattedInstructions = extractPrompt(agent?.instructions || "");
|
|
16539
|
+
const {
|
|
16540
|
+
versions,
|
|
16541
|
+
isUpdating,
|
|
16542
|
+
versionToDelete,
|
|
16543
|
+
setVersions,
|
|
16544
|
+
setVersionToDelete,
|
|
16545
|
+
deleteVersion,
|
|
16546
|
+
updateVersion,
|
|
16547
|
+
setVersionActive
|
|
16548
|
+
} = usePromptVersions(agentId, formattedInstructions);
|
|
16549
|
+
const { enhancedPrompt, isEnhancing, userComment, enhancePrompt, setUserComment, clearEnhancement, applyChanges } = usePromptEnhancer({
|
|
16550
|
+
agentId,
|
|
16551
|
+
instructions: formattedInstructions,
|
|
16552
|
+
versions,
|
|
16553
|
+
onVersionCreate: (newVersion) => {
|
|
16554
|
+
setVersions((prev) => [...prev, newVersion]);
|
|
16555
|
+
},
|
|
16556
|
+
onVersionUpdate: updateVersion
|
|
16557
|
+
});
|
|
16558
|
+
if (!agent) return null;
|
|
16559
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
16560
|
+
/* @__PURE__ */ jsx(
|
|
16561
|
+
CurrentInstructions,
|
|
16562
|
+
{
|
|
16563
|
+
instructions: agent.instructions,
|
|
16564
|
+
enhancedPrompt,
|
|
16565
|
+
isEnhancing,
|
|
16566
|
+
userComment,
|
|
16567
|
+
onEnhance: enhancePrompt,
|
|
16568
|
+
onCancel: clearEnhancement,
|
|
16569
|
+
onSave: applyChanges,
|
|
16570
|
+
onCommentChange: setUserComment,
|
|
16571
|
+
agentId,
|
|
16572
|
+
onShowHistory: () => setShowVersionHistoryDialog(true)
|
|
16573
|
+
}
|
|
16574
|
+
),
|
|
16575
|
+
/* @__PURE__ */ jsx(
|
|
16576
|
+
VersionHistoryDialog,
|
|
16577
|
+
{
|
|
16578
|
+
versions,
|
|
16579
|
+
isUpdating,
|
|
16580
|
+
onSetActive: setVersionActive,
|
|
16581
|
+
onDelete: setVersionToDelete,
|
|
16582
|
+
open: showVersionHistoryDialog,
|
|
16583
|
+
onOpenChange: setShowVersionHistoryDialog
|
|
16584
|
+
}
|
|
16585
|
+
),
|
|
16586
|
+
/* @__PURE__ */ jsx(AlertDialog, { open: versionToDelete !== null, onOpenChange: () => setVersionToDelete(null), children: /* @__PURE__ */ jsxs(AlertDialog.Content, { children: [
|
|
16587
|
+
/* @__PURE__ */ jsxs(AlertDialog.Header, { children: [
|
|
16588
|
+
/* @__PURE__ */ jsxs(AlertDialog.Title, { children: [
|
|
16589
|
+
"Delete Version ",
|
|
16590
|
+
versionToDelete !== null ? versionToDelete + 1 : ""
|
|
16591
|
+
] }),
|
|
16592
|
+
/* @__PURE__ */ jsx(AlertDialog.Description, { children: "Are you sure you want to delete this version? This action cannot be undone." })
|
|
16593
|
+
] }),
|
|
16594
|
+
/* @__PURE__ */ jsxs(AlertDialog.Footer, { children: [
|
|
16595
|
+
/* @__PURE__ */ jsx(AlertDialog.Cancel, { children: "Cancel" }),
|
|
16596
|
+
/* @__PURE__ */ jsx(
|
|
16597
|
+
AlertDialog.Action,
|
|
16598
|
+
{
|
|
16599
|
+
className: "bg-red-500 hover:bg-red-600",
|
|
16600
|
+
onClick: () => {
|
|
16601
|
+
if (versionToDelete !== null) {
|
|
16602
|
+
deleteVersion(versionToDelete);
|
|
16603
|
+
}
|
|
16604
|
+
},
|
|
16605
|
+
children: "Delete"
|
|
16606
|
+
}
|
|
16607
|
+
)
|
|
16608
|
+
] })
|
|
16609
|
+
] }) })
|
|
16610
|
+
] });
|
|
16611
|
+
}
|
|
16612
|
+
|
|
16613
|
+
function AgentInformation({ agentId, threadId }) {
|
|
16614
|
+
const { data: agent, isLoading } = useAgent(agentId);
|
|
16615
|
+
const { data: modelProviders } = useModelProviders();
|
|
16616
|
+
const { mutateAsync: updateModel } = useUpdateAgentModel(agentId);
|
|
16617
|
+
const { mutate: reorderModelList } = useReorderModelList(agentId);
|
|
16618
|
+
const { mutateAsync: updateModelInModelList } = useUpdateModelInModelList(agentId);
|
|
16619
|
+
const { data: memory, isLoading: isMemoryLoading } = useMemory(agentId);
|
|
16620
|
+
const { settings, setSettings } = useAgentSettings();
|
|
16621
|
+
const STORAGE_KEY = "agent-info-selected-tab";
|
|
16622
|
+
const [selectedTab, setSelectedTab] = useState(() => {
|
|
16623
|
+
return sessionStorage.getItem(STORAGE_KEY) || "overview";
|
|
16624
|
+
});
|
|
16625
|
+
const handleTabChange = (value) => {
|
|
16626
|
+
setSelectedTab(value);
|
|
16627
|
+
sessionStorage.setItem(STORAGE_KEY, value);
|
|
16628
|
+
};
|
|
16629
|
+
useEffect(() => {
|
|
16630
|
+
if (agent?.modelId?.includes("gpt-5")) {
|
|
16631
|
+
setSettings({
|
|
16632
|
+
...settings || {},
|
|
16633
|
+
modelSettings: {
|
|
16634
|
+
...settings?.modelSettings || {},
|
|
16635
|
+
temperature: 1
|
|
16636
|
+
}
|
|
16637
|
+
});
|
|
16638
|
+
}
|
|
16639
|
+
}, [agent]);
|
|
16640
|
+
useEffect(() => {
|
|
16641
|
+
if (!isMemoryLoading && !memory?.result && selectedTab === "memory") {
|
|
16642
|
+
handleTabChange("overview");
|
|
16643
|
+
}
|
|
16644
|
+
}, [isMemoryLoading, memory?.result, selectedTab]);
|
|
16645
|
+
return /* @__PURE__ */ jsxs("div", { className: "grid grid-rows-[auto_1fr] h-full items-start overflow-y-auto border-l-sm border-border1", children: [
|
|
16646
|
+
/* @__PURE__ */ jsx(AgentEntityHeader, { agentId, isLoading: isMemoryLoading, agentName: agent?.name || "" }),
|
|
16647
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden border-t-sm border-border1 flex flex-col", children: /* @__PURE__ */ jsxs(PlaygroundTabs, { defaultTab: "overview", value: selectedTab, onValueChange: handleTabChange, children: [
|
|
16648
|
+
/* @__PURE__ */ jsxs(TabList$1, { children: [
|
|
16649
|
+
/* @__PURE__ */ jsx(Tab$1, { value: "overview", children: "Overview" }),
|
|
16650
|
+
/* @__PURE__ */ jsx(Tab$1, { value: "model-settings", children: "Model Settings" }),
|
|
16651
|
+
memory?.result && /* @__PURE__ */ jsx(Tab$1, { value: "memory", children: "Memory" })
|
|
16652
|
+
] }),
|
|
16653
|
+
/* @__PURE__ */ jsxs(TabContent$1, { value: "overview", children: [
|
|
16654
|
+
isLoading && /* @__PURE__ */ jsx(Skeleton, { className: "h-full" }),
|
|
16655
|
+
agent && /* @__PURE__ */ jsx(
|
|
16656
|
+
AgentMetadata,
|
|
16657
|
+
{
|
|
16658
|
+
agentId,
|
|
16659
|
+
agent,
|
|
16660
|
+
updateModel,
|
|
16661
|
+
updateModelInModelList,
|
|
16662
|
+
reorderModelList,
|
|
16663
|
+
modelProviders: modelProviders || [],
|
|
16664
|
+
hasMemoryEnabled: Boolean(memory?.result),
|
|
16665
|
+
promptSlot: /* @__PURE__ */ jsx(AgentPromptEnhancer, { agentId }),
|
|
16666
|
+
modelVersion: agent.modelVersion
|
|
16667
|
+
}
|
|
16668
|
+
)
|
|
16669
|
+
] }),
|
|
16670
|
+
/* @__PURE__ */ jsxs(TabContent$1, { value: "model-settings", children: [
|
|
16671
|
+
isLoading && /* @__PURE__ */ jsx(Skeleton, { className: "h-full" }),
|
|
16672
|
+
agent && /* @__PURE__ */ jsx(
|
|
16673
|
+
AgentSettings,
|
|
16674
|
+
{
|
|
16675
|
+
modelVersion: agent.modelVersion,
|
|
16676
|
+
hasMemory: Boolean(memory?.result),
|
|
16677
|
+
hasSubAgents: Boolean(Object.keys(agent.agents || {}).length > 0)
|
|
16678
|
+
}
|
|
16679
|
+
)
|
|
16680
|
+
] }),
|
|
16681
|
+
/* @__PURE__ */ jsx(TabContent$1, { value: "memory", children: isLoading ? /* @__PURE__ */ jsx(Skeleton, { className: "h-full" }) : /* @__PURE__ */ jsx(AgentMemory, { agentId, threadId }) })
|
|
16682
|
+
] }) })
|
|
16683
|
+
] });
|
|
16684
|
+
}
|
|
16685
|
+
|
|
16686
|
+
const NameCell$1 = ({ row }) => {
|
|
16687
|
+
const { Link, paths } = useLinkComponent();
|
|
16688
|
+
const tool = row.original;
|
|
16689
|
+
return /* @__PURE__ */ jsx(
|
|
16690
|
+
EntryCell,
|
|
16691
|
+
{
|
|
16692
|
+
name: /* @__PURE__ */ jsx(Link, { className: "w-full space-y-0", href: paths.toolLink(tool.id), children: tool.id }),
|
|
16693
|
+
description: tool.description
|
|
16694
|
+
}
|
|
16695
|
+
);
|
|
16696
|
+
};
|
|
16697
|
+
const columns$1 = [
|
|
16698
|
+
{
|
|
16699
|
+
header: "Name",
|
|
16700
|
+
accessorKey: "name",
|
|
16701
|
+
cell: NameCell$1
|
|
16702
|
+
},
|
|
16703
|
+
{
|
|
16704
|
+
header: "Attached entities",
|
|
16705
|
+
accessorKey: "attachedEntities",
|
|
16706
|
+
cell: ({ row }) => {
|
|
16707
|
+
const tool = row.original;
|
|
16708
|
+
const agentsCount = tool.agents.length;
|
|
16709
|
+
return /* @__PURE__ */ jsx(Cell, { children: /* @__PURE__ */ jsxs(Badge$1, { variant: "default", icon: /* @__PURE__ */ jsx(AgentIcon, { className: "text-accent1" }), children: [
|
|
16710
|
+
agentsCount,
|
|
16711
|
+
" agent",
|
|
16712
|
+
agentsCount > 1 ? "s" : ""
|
|
16713
|
+
] }) });
|
|
16714
|
+
}
|
|
16715
|
+
}
|
|
16716
|
+
];
|
|
16717
|
+
|
|
16718
|
+
const prepareToolsTable = (tools, agents) => {
|
|
16719
|
+
const toolsWithAgents = /* @__PURE__ */ new Map();
|
|
16720
|
+
const agentsKeys = Object.keys(agents);
|
|
16721
|
+
for (const k of agentsKeys) {
|
|
16722
|
+
const agent = agents[k];
|
|
16723
|
+
const agentToolsDict = agent.tools;
|
|
16724
|
+
const agentToolsKeys = Object.keys(agentToolsDict);
|
|
16725
|
+
for (const key of agentToolsKeys) {
|
|
16726
|
+
const tool = agentToolsDict[key];
|
|
16727
|
+
if (!toolsWithAgents.has(tool.id)) {
|
|
16728
|
+
toolsWithAgents.set(tool.id, {
|
|
16729
|
+
...tool,
|
|
16730
|
+
agents: []
|
|
16731
|
+
});
|
|
16732
|
+
}
|
|
16733
|
+
toolsWithAgents.get(tool.id).agents.push({ ...agent, id: k });
|
|
16734
|
+
}
|
|
16735
|
+
}
|
|
16736
|
+
for (const [_, tool] of Object.entries(tools)) {
|
|
16737
|
+
if (!toolsWithAgents.has(tool.id)) {
|
|
16738
|
+
toolsWithAgents.set(tool.id, {
|
|
16739
|
+
...tool,
|
|
16740
|
+
agents: []
|
|
16741
|
+
});
|
|
16742
|
+
}
|
|
16743
|
+
}
|
|
16744
|
+
return Array.from(toolsWithAgents.values());
|
|
16745
|
+
};
|
|
16746
|
+
|
|
16747
|
+
function ToolTable({ tools, agents, isLoading }) {
|
|
16748
|
+
const [search, setSearch] = useState("");
|
|
16749
|
+
const { navigate, paths } = useLinkComponent();
|
|
16750
|
+
const toolData = useMemo(() => prepareToolsTable(tools, agents), [tools, agents]);
|
|
16751
|
+
const table = useReactTable({
|
|
16752
|
+
data: toolData,
|
|
16753
|
+
columns: columns$1,
|
|
16754
|
+
getCoreRowModel: getCoreRowModel()
|
|
16755
|
+
});
|
|
16756
|
+
const ths = table.getHeaderGroups()[0];
|
|
16757
|
+
const rows = table.getRowModel().rows.concat();
|
|
16758
|
+
if (rows.length === 0 && !isLoading) {
|
|
16759
|
+
return /* @__PURE__ */ jsx(EmptyToolsTable, {});
|
|
16760
|
+
}
|
|
16761
|
+
const filteredRows = rows.filter((row) => row.original.id.toLowerCase().includes(search.toLowerCase()));
|
|
16762
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
16763
|
+
/* @__PURE__ */ jsx(SearchbarWrapper, { children: /* @__PURE__ */ jsx(Searchbar, { onSearch: setSearch, label: "Search tools", placeholder: "Search tools" }) }),
|
|
16764
|
+
isLoading ? /* @__PURE__ */ jsx(ToolTableSkeleton, {}) : /* @__PURE__ */ jsx(ScrollableContainer, { children: /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs(Table$1, { children: [
|
|
16765
|
+
/* @__PURE__ */ jsx(Thead, { className: "sticky top-0", children: ths.headers.map((header) => /* @__PURE__ */ jsx(Th, { style: { width: header.column.getSize() ?? "auto" }, children: flexRender(header.column.columnDef.header, header.getContext()) }, header.id)) }),
|
|
16766
|
+
/* @__PURE__ */ jsx(Tbody, { children: filteredRows.map((row) => {
|
|
16767
|
+
const firstAgent = row.original.agents[0];
|
|
16768
|
+
const link = firstAgent ? paths.agentToolLink(firstAgent.id, row.original.id) : paths.toolLink(row.original.id);
|
|
16769
|
+
return /* @__PURE__ */ jsx(Row, { onClick: () => navigate(link), children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(React__default.Fragment, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id)) }, row.id);
|
|
16770
|
+
}) })
|
|
16771
|
+
] }) }) })
|
|
16772
|
+
] });
|
|
16773
|
+
}
|
|
16774
|
+
const ToolTableSkeleton = () => /* @__PURE__ */ jsxs(Table$1, { children: [
|
|
16775
|
+
/* @__PURE__ */ jsxs(Thead, { children: [
|
|
16776
|
+
/* @__PURE__ */ jsx(Th, { children: "Name" }),
|
|
16777
|
+
/* @__PURE__ */ jsx(Th, { children: "Used by" })
|
|
16778
|
+
] }),
|
|
16779
|
+
/* @__PURE__ */ jsx(Tbody, { children: Array.from({ length: 3 }).map((_, index) => /* @__PURE__ */ jsxs(Row, { children: [
|
|
16780
|
+
/* @__PURE__ */ jsx(Cell, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-1/2" }) }),
|
|
16781
|
+
/* @__PURE__ */ jsx(Cell, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-1/2" }) })
|
|
16782
|
+
] }, index)) })
|
|
16783
|
+
] });
|
|
16784
|
+
const EmptyToolsTable = () => /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsx(
|
|
16785
|
+
EmptyState,
|
|
16786
|
+
{
|
|
16787
|
+
iconSlot: /* @__PURE__ */ jsx(ToolCoinIcon, {}),
|
|
16788
|
+
titleSlot: "Configure Tools",
|
|
16789
|
+
descriptionSlot: "Mastra tools are not configured yet. You can find more information in the documentation.",
|
|
16790
|
+
actionSlot: /* @__PURE__ */ jsxs(
|
|
16791
|
+
Button$1,
|
|
16792
|
+
{
|
|
16793
|
+
size: "lg",
|
|
16794
|
+
className: "w-full",
|
|
16795
|
+
variant: "light",
|
|
16796
|
+
as: "a",
|
|
16797
|
+
href: "https://mastra.ai/en/docs/agents/using-tools-and-mcp",
|
|
16798
|
+
target: "_blank",
|
|
16799
|
+
children: [
|
|
16800
|
+
/* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx(ToolsIcon, {}) }),
|
|
16801
|
+
"Docs"
|
|
16802
|
+
]
|
|
16803
|
+
}
|
|
16804
|
+
)
|
|
16805
|
+
}
|
|
16806
|
+
) });
|
|
16807
|
+
|
|
16808
|
+
const useExecuteTool = () => {
|
|
16809
|
+
const client = useMastraClient();
|
|
16810
|
+
return useMutation({
|
|
16811
|
+
mutationFn: async ({
|
|
16812
|
+
toolId,
|
|
16813
|
+
input,
|
|
16814
|
+
runtimeContext: playgroundRuntimeContext
|
|
16815
|
+
}) => {
|
|
16816
|
+
const runtimeContext = new RuntimeContext$2();
|
|
16817
|
+
Object.entries(playgroundRuntimeContext ?? {}).forEach(([key, value]) => {
|
|
16818
|
+
runtimeContext.set(key, value);
|
|
16819
|
+
});
|
|
16820
|
+
try {
|
|
16821
|
+
const tool = client.getTool(toolId);
|
|
16822
|
+
const response = await tool.execute({ data: input, runtimeContext });
|
|
16823
|
+
return response;
|
|
16824
|
+
} catch (error) {
|
|
16825
|
+
toast.error("Error executing dev tool");
|
|
16826
|
+
console.error("Error executing dev tool:", error);
|
|
16827
|
+
throw error;
|
|
16828
|
+
}
|
|
16829
|
+
}
|
|
16830
|
+
});
|
|
16831
|
+
};
|
|
16832
|
+
|
|
16833
|
+
const useTools = () => {
|
|
16834
|
+
const { runtimeContext } = usePlaygroundStore();
|
|
16835
|
+
const client = useMastraClient();
|
|
16836
|
+
return useQuery({
|
|
16837
|
+
queryKey: ["tools"],
|
|
16838
|
+
queryFn: () => client.getTools(runtimeContext)
|
|
16839
|
+
});
|
|
16840
|
+
};
|
|
16841
|
+
const useTool = (toolId) => {
|
|
16842
|
+
const client = useMastraClient();
|
|
16843
|
+
const { runtimeContext } = usePlaygroundStore();
|
|
16844
|
+
return useQuery({
|
|
16845
|
+
queryKey: ["tool", toolId],
|
|
16846
|
+
queryFn: () => client.getTool(toolId).details(runtimeContext)
|
|
16847
|
+
});
|
|
16848
|
+
};
|
|
16849
|
+
|
|
16850
|
+
const ToolPanel = ({ toolId }) => {
|
|
16851
|
+
const { data: tool, isLoading } = useTool(toolId);
|
|
16852
|
+
const { mutateAsync: executeTool, isPending: isExecuting, data: result } = useExecuteTool();
|
|
16853
|
+
const { runtimeContext: playgroundRuntimeContext } = usePlaygroundStore();
|
|
16854
|
+
const handleExecuteTool = async (data) => {
|
|
16855
|
+
if (!tool) return;
|
|
16856
|
+
return executeTool({
|
|
16857
|
+
toolId: tool.id,
|
|
16858
|
+
input: data,
|
|
16859
|
+
runtimeContext: playgroundRuntimeContext
|
|
16860
|
+
});
|
|
16861
|
+
};
|
|
16862
|
+
const zodInputSchema = tool?.inputSchema ? resolveSerializedZodOutput(jsonSchemaToZod(parse(tool?.inputSchema))) : z.object({});
|
|
16863
|
+
if (isLoading) return null;
|
|
16864
|
+
if (!tool)
|
|
16865
|
+
return /* @__PURE__ */ jsx("div", { className: "py-12 text-center px-6", children: /* @__PURE__ */ jsx(Txt, { variant: "header-md", className: "text-icon3", children: "Tool not found" }) });
|
|
16866
|
+
return /* @__PURE__ */ jsx(
|
|
16867
|
+
ToolExecutor,
|
|
16868
|
+
{
|
|
16869
|
+
executionResult: result,
|
|
16870
|
+
isExecutingTool: isExecuting,
|
|
16871
|
+
zodInputSchema,
|
|
16872
|
+
handleExecuteTool,
|
|
16873
|
+
toolDescription: tool.description,
|
|
16874
|
+
toolId: tool.id
|
|
16875
|
+
}
|
|
16876
|
+
);
|
|
16877
|
+
};
|
|
16878
|
+
|
|
16879
|
+
function TemplatesTools({
|
|
16880
|
+
tagOptions,
|
|
16881
|
+
selectedTag,
|
|
16882
|
+
providerOptions,
|
|
16883
|
+
selectedProvider,
|
|
16884
|
+
onTagChange,
|
|
16885
|
+
onProviderChange,
|
|
16886
|
+
searchTerm,
|
|
16887
|
+
onSearchChange,
|
|
16888
|
+
onReset,
|
|
16889
|
+
className,
|
|
16890
|
+
isLoading
|
|
16891
|
+
}) {
|
|
16892
|
+
if (isLoading) {
|
|
16893
|
+
return /* @__PURE__ */ jsxs(
|
|
16894
|
+
"div",
|
|
16895
|
+
{
|
|
16896
|
+
className: cn(
|
|
16897
|
+
"h-[6.5rem] flex items-center gap-[2rem]",
|
|
16898
|
+
"[&>div]:bg-surface3 [&>div]:w-[12rem] [&>div]:h-[2rem] [&>div]:animate-pulse",
|
|
16899
|
+
className
|
|
16900
|
+
),
|
|
16901
|
+
children: [
|
|
16902
|
+
/* @__PURE__ */ jsx("div", {}),
|
|
16903
|
+
" ",
|
|
16904
|
+
/* @__PURE__ */ jsx("div", {}),
|
|
16905
|
+
" ",
|
|
16906
|
+
/* @__PURE__ */ jsx("div", {})
|
|
16907
|
+
]
|
|
16908
|
+
}
|
|
16909
|
+
);
|
|
16910
|
+
}
|
|
16911
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex flex-wrap mx-auto sticky top-0 gap-[2rem] bg-surface2 py-[2rem]", className), children: [
|
|
16912
|
+
/* @__PURE__ */ jsx(
|
|
16913
|
+
SearchField,
|
|
16914
|
+
{
|
|
16915
|
+
label: "Search templates",
|
|
16916
|
+
value: searchTerm,
|
|
16917
|
+
onChange: (e) => onSearchChange?.(e.target.value),
|
|
16918
|
+
placeholder: "Search Template"
|
|
16919
|
+
}
|
|
16920
|
+
),
|
|
16921
|
+
/* @__PURE__ */ jsx(SelectField, { label: "Filter by tag", value: selectedTag, onValueChange: onTagChange, options: tagOptions }),
|
|
16922
|
+
/* @__PURE__ */ jsx(
|
|
16923
|
+
SelectField,
|
|
16924
|
+
{
|
|
16925
|
+
label: "Filter by provider",
|
|
16926
|
+
value: selectedProvider,
|
|
16927
|
+
onValueChange: onProviderChange,
|
|
16928
|
+
options: providerOptions
|
|
16929
|
+
}
|
|
16930
|
+
),
|
|
16931
|
+
onReset && /* @__PURE__ */ jsxs(Button, { onClick: onReset, children: [
|
|
16932
|
+
"Reset ",
|
|
16933
|
+
/* @__PURE__ */ jsx(XIcon, {})
|
|
16934
|
+
] })
|
|
16935
|
+
] });
|
|
16936
|
+
}
|
|
16937
|
+
|
|
16938
|
+
function getRepoName(githubUrl) {
|
|
16939
|
+
return githubUrl.replace(/\/$/, "").split("/").pop();
|
|
16940
|
+
}
|
|
16941
|
+
function Container({ children, className }) {
|
|
16942
|
+
return /* @__PURE__ */ jsx(
|
|
16943
|
+
"div",
|
|
16944
|
+
{
|
|
16945
|
+
className: cn(
|
|
16946
|
+
"border border-border1 rounded-lg mt-[3rem] py-[2rem] lg:min-h-[25rem] transition-height px-[1rem] lg:px-[3rem]",
|
|
16947
|
+
className
|
|
16948
|
+
),
|
|
16949
|
+
children
|
|
16950
|
+
}
|
|
16951
|
+
);
|
|
16952
|
+
}
|
|
16953
|
+
|
|
16954
|
+
function TemplatesList({ templates, linkComponent, className, isLoading }) {
|
|
16955
|
+
const LinkComponent = linkComponent || "a";
|
|
16956
|
+
if (isLoading) {
|
|
16957
|
+
return /* @__PURE__ */ jsx("div", { className: cn("grid gap-y-[1rem]", className), children: Array.from({ length: 5 }).map((_, index) => /* @__PURE__ */ jsx("div", { className: "h-[4rem] bg-surface3 animate-pulse rounded-lg" }, index)) });
|
|
16958
|
+
}
|
|
16959
|
+
return /* @__PURE__ */ jsx("div", { className: cn("grid gap-y-[1rem]", className), children: templates.map((template) => {
|
|
16960
|
+
const hasMetaInfo = template?.agents || template?.tools || template?.networks || template?.workflows || template?.mcp;
|
|
16961
|
+
return /* @__PURE__ */ jsxs(
|
|
16962
|
+
"article",
|
|
16963
|
+
{
|
|
16964
|
+
className: cn(
|
|
16965
|
+
"border border-border1 rounded-lg overflow-hidden w-full grid grid-cols-[1fr_auto] bg-surface3 transition-colors hover:bg-surface4"
|
|
16966
|
+
),
|
|
16967
|
+
children: [
|
|
16968
|
+
/* @__PURE__ */ jsxs(
|
|
16969
|
+
LinkComponent,
|
|
16970
|
+
{
|
|
16971
|
+
to: `/templates/${template.slug}`,
|
|
16972
|
+
className: cn("grid [&:hover_p]:text-icon5", {
|
|
16973
|
+
"grid-cols-[8rem_1fr] lg:grid-cols-[12rem_1fr]": template.imageURL
|
|
16974
|
+
}),
|
|
16975
|
+
children: [
|
|
16976
|
+
template.imageURL && /* @__PURE__ */ jsx("div", { className: cn("overflow-hidden"), children: /* @__PURE__ */ jsx(
|
|
16977
|
+
"div",
|
|
16978
|
+
{
|
|
16979
|
+
className: "w-full h-full bg-cover thumb transition-scale duration-150",
|
|
16980
|
+
style: {
|
|
16981
|
+
backgroundImage: `url(${template.imageURL})`
|
|
16982
|
+
}
|
|
16983
|
+
}
|
|
16984
|
+
) }),
|
|
16985
|
+
/* @__PURE__ */ jsxs(
|
|
16986
|
+
"div",
|
|
16987
|
+
{
|
|
16988
|
+
className: cn(
|
|
16989
|
+
"grid py-[.75rem] px-[1.5rem] w-full gap-[0.1rem]",
|
|
16990
|
+
"[&_svg]:w-[1em] [&_svg]:h-[1em] [&_svg]:text-icon3"
|
|
16991
|
+
),
|
|
16992
|
+
children: [
|
|
16993
|
+
/* @__PURE__ */ jsx("h2", { className: "text-[1rem] text-icon5", children: template.title }),
|
|
16994
|
+
/* @__PURE__ */ jsx("p", { className: "text-[0.875rem] text-icon4 transition-colors duration-500", children: template.description }),
|
|
16995
|
+
/* @__PURE__ */ jsxs("div", { className: "hidden 2xl:flex text-icon3 text-[0.875rem] flex-wrap items-center gap-[1rem] mt-[0.75rem]", children: [
|
|
16996
|
+
hasMetaInfo && /* @__PURE__ */ jsxs(
|
|
16997
|
+
"ul",
|
|
16998
|
+
{
|
|
16999
|
+
className: cn(
|
|
17000
|
+
"flex gap-[1rem] text-[0.875rem] text-icon3 m-0 p-0 list-none",
|
|
17001
|
+
"[&>li]:flex [&>li]:items-center [&>li]:gap-[0.1rem] text-icon4"
|
|
17002
|
+
),
|
|
17003
|
+
children: [
|
|
17004
|
+
template?.agents && template.agents.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
17005
|
+
/* @__PURE__ */ jsx(AgentIcon, {}),
|
|
17006
|
+
" ",
|
|
17007
|
+
template.agents.length
|
|
17008
|
+
] }),
|
|
17009
|
+
template?.tools && template.tools.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
17010
|
+
/* @__PURE__ */ jsx(ToolsIcon, {}),
|
|
17011
|
+
" ",
|
|
17012
|
+
template.tools.length
|
|
17013
|
+
] }),
|
|
17014
|
+
template?.networks && template.networks.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
17015
|
+
/* @__PURE__ */ jsx(NetworkIcon, {}),
|
|
17016
|
+
" ",
|
|
17017
|
+
template.networks.length
|
|
17018
|
+
] }),
|
|
17019
|
+
template?.workflows && template.workflows.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
17020
|
+
/* @__PURE__ */ jsx(WorkflowIcon$1, {}),
|
|
17021
|
+
" ",
|
|
17022
|
+
template.workflows.length
|
|
17023
|
+
] }),
|
|
17024
|
+
template?.mcp && template.mcp.length > 0 && /* @__PURE__ */ jsxs("li", { children: [
|
|
17025
|
+
/* @__PURE__ */ jsx(McpServerIcon, {}),
|
|
17026
|
+
" ",
|
|
17027
|
+
template.mcp.length
|
|
17028
|
+
] })
|
|
17029
|
+
]
|
|
17030
|
+
}
|
|
17031
|
+
),
|
|
17032
|
+
hasMetaInfo && template.supportedProviders && /* @__PURE__ */ jsx("small", { children: "|" }),
|
|
17033
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center text-icon3 gap-[1rem]", children: template.supportedProviders.map((provider) => /* @__PURE__ */ jsx("span", { className: "", children: provider }, provider)) })
|
|
17034
|
+
] })
|
|
17035
|
+
]
|
|
17036
|
+
}
|
|
17037
|
+
)
|
|
17038
|
+
]
|
|
17039
|
+
}
|
|
17040
|
+
),
|
|
17041
|
+
/* @__PURE__ */ jsx(
|
|
17042
|
+
"a",
|
|
17043
|
+
{
|
|
17044
|
+
href: template.githubUrl,
|
|
17045
|
+
className: cn("group items-center gap-[0.5rem] text-[0.875rem] ml-auto pr-[1rem] hidden", "lg:flex"),
|
|
17046
|
+
target: "_blank",
|
|
17047
|
+
rel: "noopener noreferrer",
|
|
17048
|
+
children: /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-[0.5rem] px-[0.5rem] py-[0.25rem] rounded bg-surface1 group-hover:bg-surface2 text-icon3 transition-colors group-hover:text-icon5 ", children: [
|
|
17049
|
+
/* @__PURE__ */ jsx(GithubIcon, {}),
|
|
17050
|
+
" ",
|
|
17051
|
+
getRepoName(template.githubUrl)
|
|
17052
|
+
] })
|
|
17053
|
+
}
|
|
17054
|
+
)
|
|
17055
|
+
]
|
|
17056
|
+
},
|
|
17057
|
+
template.slug
|
|
17058
|
+
);
|
|
17059
|
+
}) });
|
|
17060
|
+
}
|
|
17061
|
+
|
|
17062
|
+
function TemplateInfo({
|
|
17063
|
+
title,
|
|
17064
|
+
description,
|
|
17065
|
+
imageURL,
|
|
17066
|
+
githubUrl,
|
|
17067
|
+
isLoading,
|
|
17068
|
+
infoData,
|
|
17069
|
+
templateSlug
|
|
17070
|
+
}) {
|
|
17071
|
+
const branchName = templateSlug ? `feat/install-template-${templateSlug}` : "feat/install-template-[slug]";
|
|
17072
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17073
|
+
/* @__PURE__ */ jsx("div", { className: cn("grid mt-[2rem] items-center"), children: /* @__PURE__ */ jsxs(
|
|
17074
|
+
"div",
|
|
17075
|
+
{
|
|
17076
|
+
className: cn(
|
|
17077
|
+
"text-[1.5rem] flex items-center gap-[0.75rem]",
|
|
17078
|
+
"[&>svg]:w-[1.2em] [&>svg]:h-[1.2em] [&>svg]:opacity-50",
|
|
17079
|
+
{
|
|
17080
|
+
"[&>svg]:opacity-20": isLoading
|
|
17081
|
+
}
|
|
17082
|
+
),
|
|
17083
|
+
children: [
|
|
17084
|
+
/* @__PURE__ */ jsx(PackageIcon, {}),
|
|
17085
|
+
/* @__PURE__ */ jsx(
|
|
17086
|
+
"h2",
|
|
17087
|
+
{
|
|
17088
|
+
className: cn({
|
|
17089
|
+
"bg-surface4 flex rounded-lg min-w-[50%]": isLoading
|
|
17090
|
+
}),
|
|
17091
|
+
children: isLoading ? /* @__PURE__ */ jsx(Fragment, { children: " " }) : title
|
|
17092
|
+
}
|
|
17093
|
+
)
|
|
17094
|
+
]
|
|
17095
|
+
}
|
|
17096
|
+
) }),
|
|
17097
|
+
/* @__PURE__ */ jsxs("div", { className: "grid lg:grid-cols-[1fr_1fr] gap-x-[6rem] ", children: [
|
|
17098
|
+
/* @__PURE__ */ jsxs("div", { className: "grid", children: [
|
|
17099
|
+
/* @__PURE__ */ jsx(
|
|
17100
|
+
"p",
|
|
17101
|
+
{
|
|
17102
|
+
className: cn("mb-[1rem] text-[0.875rem] text-icon4 mt-[.5rem] leading-[1.75]", {
|
|
17103
|
+
"bg-surface4 rounded-lg ": isLoading
|
|
17104
|
+
}),
|
|
17105
|
+
children: isLoading ? /* @__PURE__ */ jsx(Fragment, { children: " " }) : description
|
|
17106
|
+
}
|
|
17107
|
+
),
|
|
17108
|
+
!isLoading && templateSlug && /* @__PURE__ */ jsxs(
|
|
17109
|
+
"div",
|
|
17110
|
+
{
|
|
17111
|
+
className: cn(
|
|
17112
|
+
"bg-surface2 border border-surface4 rounded-lg p-[1rem] mb-[1rem]",
|
|
17113
|
+
"flex items-start gap-[0.75rem]"
|
|
17114
|
+
),
|
|
17115
|
+
children: [
|
|
17116
|
+
/* @__PURE__ */ jsx("div", { className: "flex-shrink-0 mt-[0.125rem]", children: /* @__PURE__ */ jsx(InfoIcon$1, { className: "w-[1.1em] h-[1.1em] text-blue-500" }) }),
|
|
17117
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-[0.5rem]", children: [
|
|
17118
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[0.5rem]", children: [
|
|
17119
|
+
/* @__PURE__ */ jsx(GitBranchIcon, { className: "w-[1em] h-[1em] text-icon4" }),
|
|
17120
|
+
/* @__PURE__ */ jsx("span", { className: "text-[0.875rem] font-medium text-icon5", children: "A new Git branch will be created" })
|
|
17121
|
+
] }),
|
|
17122
|
+
/* @__PURE__ */ jsxs("div", { className: "text-[0.8125rem] text-icon4 space-y-[0.25rem]", children: [
|
|
17123
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
17124
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: "Branch name:" }),
|
|
17125
|
+
" ",
|
|
17126
|
+
/* @__PURE__ */ jsx("code", { className: "bg-surface3 px-[0.375rem] py-[0.125rem] rounded text-[0.75rem] font-mono", children: branchName })
|
|
17127
|
+
] }),
|
|
17128
|
+
/* @__PURE__ */ jsx("div", { children: "This ensures safe installation with easy rollback if needed. Your main branch remains unchanged." })
|
|
17129
|
+
] })
|
|
17130
|
+
] })
|
|
17131
|
+
]
|
|
17132
|
+
}
|
|
17133
|
+
),
|
|
17134
|
+
githubUrl && /* @__PURE__ */ jsxs(
|
|
17135
|
+
"a",
|
|
17136
|
+
{
|
|
17137
|
+
href: githubUrl,
|
|
17138
|
+
target: "_blank",
|
|
17139
|
+
rel: "noopener noreferrer",
|
|
17140
|
+
className: "flex items-center gap-[.5rem] mt-auto text-icon3 text-[0.875rem] hover:text-icon5",
|
|
17141
|
+
children: [
|
|
17142
|
+
/* @__PURE__ */ jsx(GithubIcon, {}),
|
|
17143
|
+
githubUrl?.split("/")?.pop()
|
|
17144
|
+
]
|
|
17145
|
+
}
|
|
17146
|
+
)
|
|
17147
|
+
] }),
|
|
17148
|
+
infoData && /* @__PURE__ */ jsx(KeyValueList, { data: infoData, LinkComponent: Link, labelsAreHidden: true, isLoading })
|
|
17149
|
+
] })
|
|
17150
|
+
] });
|
|
17151
|
+
}
|
|
17152
|
+
|
|
17153
|
+
function TemplateForm({
|
|
17154
|
+
providerOptions,
|
|
17155
|
+
selectedProvider,
|
|
17156
|
+
onProviderChange,
|
|
17157
|
+
variables,
|
|
17158
|
+
errors,
|
|
17159
|
+
handleInstallTemplate,
|
|
17160
|
+
handleVariableChange,
|
|
17161
|
+
isLoadingEnvVars,
|
|
17162
|
+
defaultModelProvider,
|
|
17163
|
+
defaultModelId,
|
|
17164
|
+
onModelUpdate
|
|
17165
|
+
}) {
|
|
17166
|
+
return /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsxs("div", { className: "max-w-[40rem] my-[1rem] p-[1rem] lg:p-[2rem] mx-auto gap-[2rem] grid", children: [
|
|
17167
|
+
/* @__PURE__ */ jsxs(
|
|
17168
|
+
"h2",
|
|
17169
|
+
{
|
|
17170
|
+
className: cn(
|
|
17171
|
+
"text-icon4 text-[1.125rem] font-semibold flex items-center gap-[0.5rem]",
|
|
17172
|
+
"[&>svg]:w-[1.2em] [&_svg]:h-[1.2em] [&_svg]:opacity-70 "
|
|
17173
|
+
),
|
|
17174
|
+
children: [
|
|
17175
|
+
"Install Template ",
|
|
17176
|
+
/* @__PURE__ */ jsx(PackageOpenIcon, {})
|
|
17177
|
+
]
|
|
17178
|
+
}
|
|
17179
|
+
),
|
|
17180
|
+
/* @__PURE__ */ jsx(
|
|
17181
|
+
SelectField,
|
|
17182
|
+
{
|
|
17183
|
+
options: providerOptions,
|
|
17184
|
+
label: "Template AI Model Provider",
|
|
17185
|
+
onValueChange: onProviderChange,
|
|
17186
|
+
value: selectedProvider,
|
|
17187
|
+
placeholder: "Select"
|
|
17188
|
+
}
|
|
17189
|
+
),
|
|
17190
|
+
selectedProvider && Object.entries(variables || {}).length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17191
|
+
/* @__PURE__ */ jsx("h3", { className: "text-icon3 text-[0.875rem]", children: "Set required Environmental Variables" }),
|
|
17192
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-[1fr_1fr] gap-[1rem] items-start", children: isLoadingEnvVars ? /* @__PURE__ */ jsxs(
|
|
17193
|
+
"div",
|
|
17194
|
+
{
|
|
17195
|
+
className: cn(
|
|
17196
|
+
"flex items-center justify-center col-span-2 text-icon3 text-[0.75rem] gap-[1rem]",
|
|
17197
|
+
"[&_svg]:opacity-50 [&_svg]:w-[1.1em] [&_svg]:h-[1.1em]",
|
|
17198
|
+
"animate-in fade-in duration-300"
|
|
17199
|
+
),
|
|
17200
|
+
children: [
|
|
17201
|
+
/* @__PURE__ */ jsx(Spinner, {}),
|
|
17202
|
+
" Loading variables..."
|
|
17203
|
+
]
|
|
17204
|
+
}
|
|
17205
|
+
) : Object.entries(variables).map(([key, value]) => /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
17206
|
+
/* @__PURE__ */ jsx(
|
|
17207
|
+
InputField,
|
|
17208
|
+
{
|
|
17209
|
+
name: `env-${key}`,
|
|
17210
|
+
labelIsHidden: true,
|
|
17211
|
+
label: "Key",
|
|
17212
|
+
value: key,
|
|
17213
|
+
disabled: true,
|
|
17214
|
+
className: "w-full"
|
|
17215
|
+
}
|
|
17216
|
+
),
|
|
17217
|
+
/* @__PURE__ */ jsx(
|
|
17218
|
+
InputField,
|
|
17219
|
+
{
|
|
17220
|
+
name: key,
|
|
15336
17221
|
labelIsHidden: true,
|
|
15337
17222
|
label: "Value",
|
|
15338
17223
|
value,
|
|
@@ -17824,535 +19709,172 @@ const DarkLogo = (props) => /* @__PURE__ */ jsxs("svg", { width: "100", height:
|
|
|
17824
19709
|
d: "M59.2351 43.2352L43.194 59.2763L40.958 57.0403L56.9991 40.9992L59.2351 43.2352Z",
|
|
17825
19710
|
fill: "currentColor"
|
|
17826
19711
|
}
|
|
17827
|
-
),
|
|
17828
|
-
/* @__PURE__ */ jsx(
|
|
17829
|
-
"path",
|
|
17830
|
-
{
|
|
17831
|
-
fillRule: "evenodd",
|
|
17832
|
-
clipRule: "evenodd",
|
|
17833
|
-
d: "M43.1969 40.9992L59.2379 57.0403L57.002 59.2763L40.9609 43.2352L43.1969 40.9992Z",
|
|
17834
|
-
fill: "currentColor"
|
|
17835
|
-
}
|
|
17836
|
-
),
|
|
17837
|
-
/* @__PURE__ */ jsx(
|
|
17838
|
-
"path",
|
|
17839
|
-
{
|
|
17840
|
-
fillRule: "evenodd",
|
|
17841
|
-
clipRule: "evenodd",
|
|
17842
|
-
d: "M23.7151 33.0924C17.0466 37.565 13.1629 43.573 13.1629 49.9999C13.1629 56.4269 17.0466 62.4349 23.7151 66.9075C30.3734 71.3733 39.662 74.1867 50.0004 74.1867C60.3388 74.1867 69.6274 71.3733 76.2857 66.9075C82.9541 62.4349 86.8378 56.4269 86.8378 49.9999C86.8378 43.573 82.9541 37.565 76.2857 33.0924C69.6274 28.6266 60.3388 25.8132 50.0004 25.8132C39.662 25.8132 30.3734 28.6266 23.7151 33.0924ZM21.9537 30.4662C29.2002 25.6059 39.1209 22.651 50.0004 22.651C60.8799 22.651 70.8006 25.6059 78.0471 30.4662C85.2834 35.3197 90 42.1957 90 49.9999C90 57.8042 85.2834 64.6802 78.0471 69.5337C70.8006 74.394 60.8799 77.3489 50.0004 77.3489C39.1209 77.3489 29.2002 74.394 21.9537 69.5337C14.7174 64.6802 10.0008 57.8042 10.0008 49.9999C10.0008 42.1957 14.7174 35.3197 21.9537 30.4662Z",
|
|
17843
|
-
fill: "currentColor"
|
|
17844
|
-
}
|
|
17845
|
-
)
|
|
17846
|
-
] });
|
|
17847
|
-
|
|
17848
|
-
const Entity = ({ children, className, onClick }) => {
|
|
17849
|
-
return /* @__PURE__ */ jsx(
|
|
17850
|
-
"div",
|
|
17851
|
-
{
|
|
17852
|
-
tabIndex: onClick ? 0 : void 0,
|
|
17853
|
-
onKeyDown: (e) => {
|
|
17854
|
-
if (!onClick) return;
|
|
17855
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
17856
|
-
e.preventDefault();
|
|
17857
|
-
onClick?.();
|
|
17858
|
-
}
|
|
17859
|
-
},
|
|
17860
|
-
className: clsx(
|
|
17861
|
-
"flex gap-3 group/entity bg-surface3 rounded-lg border-sm border-border1 py-3 px-4",
|
|
17862
|
-
onClick && "cursor-pointer hover:bg-surface4 transition-all",
|
|
17863
|
-
className
|
|
17864
|
-
),
|
|
17865
|
-
onClick,
|
|
17866
|
-
children
|
|
17867
|
-
}
|
|
17868
|
-
);
|
|
17869
|
-
};
|
|
17870
|
-
const EntityIcon = ({ children, className }) => {
|
|
17871
|
-
return /* @__PURE__ */ jsx(Icon, { size: "lg", className: clsx("text-icon3 mt-1", className), children });
|
|
17872
|
-
};
|
|
17873
|
-
const EntityName = ({ children, className }) => {
|
|
17874
|
-
return /* @__PURE__ */ jsx(Txt, { as: "p", variant: "ui-lg", className: clsx("text-icon6 font-medium", className), children });
|
|
17875
|
-
};
|
|
17876
|
-
const EntityDescription = ({ children, className }) => {
|
|
17877
|
-
return /* @__PURE__ */ jsx(Txt, { as: "p", variant: "ui-sm", className: clsx("text-icon3", className), children });
|
|
17878
|
-
};
|
|
17879
|
-
const EntityContent = ({ children, className }) => {
|
|
17880
|
-
return /* @__PURE__ */ jsx("div", { className, children });
|
|
17881
|
-
};
|
|
17882
|
-
|
|
17883
|
-
function usePolling({
|
|
17884
|
-
fetchFn,
|
|
17885
|
-
interval = 3e3,
|
|
17886
|
-
enabled = false,
|
|
17887
|
-
onSuccess,
|
|
17888
|
-
onError,
|
|
17889
|
-
shouldContinue = () => true,
|
|
17890
|
-
restartPolling = false
|
|
17891
|
-
}) {
|
|
17892
|
-
const [isPolling, setIsPolling] = useState(enabled);
|
|
17893
|
-
const [error, setError] = useState(null);
|
|
17894
|
-
const [data, setData] = useState(null);
|
|
17895
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
17896
|
-
const [firstCallLoading, setFirstCallLoading] = useState(false);
|
|
17897
|
-
const timeoutRef = useRef(null);
|
|
17898
|
-
const mountedRef = useRef(true);
|
|
17899
|
-
const [restart, setRestart] = useState(restartPolling);
|
|
17900
|
-
const cleanup = useCallback(() => {
|
|
17901
|
-
console.log("cleanup");
|
|
17902
|
-
if (timeoutRef.current) {
|
|
17903
|
-
clearTimeout(timeoutRef.current);
|
|
17904
|
-
timeoutRef.current = null;
|
|
17905
|
-
}
|
|
17906
|
-
}, []);
|
|
17907
|
-
const stopPolling = useCallback(() => {
|
|
17908
|
-
console.log("stopPolling");
|
|
17909
|
-
setIsPolling(false);
|
|
17910
|
-
cleanup();
|
|
17911
|
-
}, [cleanup]);
|
|
17912
|
-
const startPolling = useCallback(() => {
|
|
17913
|
-
console.log("startPolling");
|
|
17914
|
-
setIsPolling(true);
|
|
17915
|
-
setError(null);
|
|
17916
|
-
}, []);
|
|
17917
|
-
const executePoll = useCallback(
|
|
17918
|
-
async (refetch2 = true) => {
|
|
17919
|
-
if (!mountedRef.current) return;
|
|
17920
|
-
setIsLoading(true);
|
|
17921
|
-
try {
|
|
17922
|
-
const result = await fetchFn();
|
|
17923
|
-
setData(result);
|
|
17924
|
-
setError(null);
|
|
17925
|
-
onSuccess?.(result);
|
|
17926
|
-
if (shouldContinue(result) && refetch2) {
|
|
17927
|
-
timeoutRef.current = setTimeout(executePoll, interval);
|
|
17928
|
-
} else {
|
|
17929
|
-
stopPolling();
|
|
17930
|
-
}
|
|
17931
|
-
} catch (err) {
|
|
17932
|
-
if (!mountedRef.current) return;
|
|
17933
|
-
setError(err);
|
|
17934
|
-
onError?.(err);
|
|
17935
|
-
stopPolling();
|
|
17936
|
-
} finally {
|
|
17937
|
-
if (mountedRef.current) {
|
|
17938
|
-
setFirstCallLoading(false);
|
|
17939
|
-
setIsLoading(false);
|
|
17940
|
-
}
|
|
17941
|
-
}
|
|
17942
|
-
},
|
|
17943
|
-
[fetchFn, interval, onSuccess, onError, shouldContinue, stopPolling]
|
|
17944
|
-
);
|
|
17945
|
-
const refetch = useCallback(
|
|
17946
|
-
(withPolling = false) => {
|
|
17947
|
-
console.log("refetch", { withPolling });
|
|
17948
|
-
if (withPolling) {
|
|
17949
|
-
setIsPolling(true);
|
|
17950
|
-
} else {
|
|
17951
|
-
executePoll(false);
|
|
17952
|
-
}
|
|
17953
|
-
setError(null);
|
|
17954
|
-
},
|
|
17955
|
-
[executePoll]
|
|
17956
|
-
);
|
|
17957
|
-
useEffect(() => {
|
|
17958
|
-
mountedRef.current = true;
|
|
17959
|
-
if (enabled && isPolling) {
|
|
17960
|
-
executePoll(true);
|
|
17961
|
-
}
|
|
17962
|
-
return () => {
|
|
17963
|
-
console.log("cleanup poll");
|
|
17964
|
-
mountedRef.current = false;
|
|
17965
|
-
cleanup();
|
|
17966
|
-
};
|
|
17967
|
-
}, [enabled, isPolling, executePoll, cleanup]);
|
|
17968
|
-
useEffect(() => {
|
|
17969
|
-
setRestart(restartPolling);
|
|
17970
|
-
}, [restartPolling]);
|
|
17971
|
-
useEffect(() => {
|
|
17972
|
-
if (restart && !isPolling) {
|
|
17973
|
-
setIsPolling(true);
|
|
17974
|
-
executePoll();
|
|
17975
|
-
setRestart(false);
|
|
17976
|
-
}
|
|
17977
|
-
}, [restart]);
|
|
17978
|
-
return {
|
|
17979
|
-
isPolling,
|
|
17980
|
-
isLoading,
|
|
17981
|
-
error,
|
|
17982
|
-
data,
|
|
17983
|
-
startPolling,
|
|
17984
|
-
stopPolling,
|
|
17985
|
-
firstCallLoading,
|
|
17986
|
-
refetch
|
|
17987
|
-
};
|
|
17988
|
-
}
|
|
17989
|
-
|
|
17990
|
-
const PlaygroundQueryClient = ({ children }) => {
|
|
17991
|
-
const queryClient = new QueryClient();
|
|
17992
|
-
return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children });
|
|
17993
|
-
};
|
|
17994
|
-
|
|
17995
|
-
const useMemory = (agentId) => {
|
|
17996
|
-
const client = useMastraClient();
|
|
17997
|
-
return useQuery({
|
|
17998
|
-
queryKey: ["memory", agentId],
|
|
17999
|
-
queryFn: () => agentId ? client.getMemoryStatus(agentId) : null,
|
|
18000
|
-
enabled: Boolean(agentId),
|
|
18001
|
-
staleTime: 5 * 60 * 1e3,
|
|
18002
|
-
// 5 minutes
|
|
18003
|
-
gcTime: 10 * 60 * 1e3,
|
|
18004
|
-
// 10 minutes
|
|
18005
|
-
retry: false
|
|
18006
|
-
});
|
|
18007
|
-
};
|
|
18008
|
-
const useMemoryConfig = (agentId) => {
|
|
18009
|
-
const client = useMastraClient();
|
|
18010
|
-
return useQuery({
|
|
18011
|
-
queryKey: ["memory", "config", agentId],
|
|
18012
|
-
queryFn: () => agentId ? client.getMemoryConfig({ agentId }) : null,
|
|
18013
|
-
enabled: Boolean(agentId),
|
|
18014
|
-
staleTime: 5 * 60 * 1e3,
|
|
18015
|
-
// 5 minutes
|
|
18016
|
-
gcTime: 10 * 60 * 1e3,
|
|
18017
|
-
// 10 minutes
|
|
18018
|
-
retry: false,
|
|
18019
|
-
refetchOnWindowFocus: false
|
|
18020
|
-
});
|
|
18021
|
-
};
|
|
18022
|
-
const useThreads = ({
|
|
18023
|
-
resourceId,
|
|
18024
|
-
agentId,
|
|
18025
|
-
isMemoryEnabled
|
|
18026
|
-
}) => {
|
|
18027
|
-
const client = useMastraClient();
|
|
18028
|
-
return useQuery({
|
|
18029
|
-
queryKey: ["memory", "threads", resourceId, agentId],
|
|
18030
|
-
queryFn: () => isMemoryEnabled ? client.getMemoryThreads({ resourceId, agentId }) : null,
|
|
18031
|
-
enabled: Boolean(isMemoryEnabled),
|
|
18032
|
-
staleTime: 0,
|
|
18033
|
-
gcTime: 0,
|
|
18034
|
-
retry: false,
|
|
18035
|
-
refetchOnWindowFocus: false
|
|
18036
|
-
});
|
|
18037
|
-
};
|
|
18038
|
-
const useDeleteThread = () => {
|
|
18039
|
-
const client = useMastraClient();
|
|
18040
|
-
const queryClient = useQueryClient();
|
|
18041
|
-
return useMutation({
|
|
18042
|
-
mutationFn: ({ threadId, agentId, networkId }) => client.deleteThread(threadId, { agentId, networkId }),
|
|
18043
|
-
onSuccess: (_, variables) => {
|
|
18044
|
-
const { agentId, networkId } = variables;
|
|
18045
|
-
if (agentId) {
|
|
18046
|
-
queryClient.invalidateQueries({ queryKey: ["memory", "threads", agentId, agentId] });
|
|
18047
|
-
}
|
|
18048
|
-
if (networkId) {
|
|
18049
|
-
queryClient.invalidateQueries({ queryKey: ["network", "threads", networkId, networkId] });
|
|
18050
|
-
}
|
|
18051
|
-
toast.success("Chat deleted successfully");
|
|
18052
|
-
},
|
|
18053
|
-
onError: () => {
|
|
18054
|
-
toast.error("Failed to delete chat");
|
|
18055
|
-
}
|
|
18056
|
-
});
|
|
18057
|
-
};
|
|
18058
|
-
const useMemorySearch = ({
|
|
18059
|
-
agentId,
|
|
18060
|
-
resourceId,
|
|
18061
|
-
threadId
|
|
18062
|
-
}) => {
|
|
18063
|
-
const searchMemory = async (searchQuery, memoryConfig) => {
|
|
18064
|
-
if (!searchQuery.trim()) {
|
|
18065
|
-
return { results: [], count: 0, query: searchQuery };
|
|
18066
|
-
}
|
|
18067
|
-
const params = new URLSearchParams({
|
|
18068
|
-
searchQuery,
|
|
18069
|
-
resourceId,
|
|
18070
|
-
agentId
|
|
18071
|
-
});
|
|
18072
|
-
if (threadId) {
|
|
18073
|
-
params.append("threadId", threadId);
|
|
18074
|
-
}
|
|
18075
|
-
if (memoryConfig) {
|
|
18076
|
-
params.append("memoryConfig", JSON.stringify(memoryConfig));
|
|
19712
|
+
),
|
|
19713
|
+
/* @__PURE__ */ jsx(
|
|
19714
|
+
"path",
|
|
19715
|
+
{
|
|
19716
|
+
fillRule: "evenodd",
|
|
19717
|
+
clipRule: "evenodd",
|
|
19718
|
+
d: "M43.1969 40.9992L59.2379 57.0403L57.002 59.2763L40.9609 43.2352L43.1969 40.9992Z",
|
|
19719
|
+
fill: "currentColor"
|
|
18077
19720
|
}
|
|
18078
|
-
|
|
18079
|
-
|
|
18080
|
-
|
|
18081
|
-
|
|
18082
|
-
|
|
18083
|
-
|
|
18084
|
-
|
|
18085
|
-
|
|
18086
|
-
const errorData = await response.json().catch(() => ({ message: "Unknown error" }));
|
|
18087
|
-
console.error("Search memory error:", errorData);
|
|
18088
|
-
throw new Error(errorData.message || errorData.error || "Failed to search memory");
|
|
19721
|
+
),
|
|
19722
|
+
/* @__PURE__ */ jsx(
|
|
19723
|
+
"path",
|
|
19724
|
+
{
|
|
19725
|
+
fillRule: "evenodd",
|
|
19726
|
+
clipRule: "evenodd",
|
|
19727
|
+
d: "M23.7151 33.0924C17.0466 37.565 13.1629 43.573 13.1629 49.9999C13.1629 56.4269 17.0466 62.4349 23.7151 66.9075C30.3734 71.3733 39.662 74.1867 50.0004 74.1867C60.3388 74.1867 69.6274 71.3733 76.2857 66.9075C82.9541 62.4349 86.8378 56.4269 86.8378 49.9999C86.8378 43.573 82.9541 37.565 76.2857 33.0924C69.6274 28.6266 60.3388 25.8132 50.0004 25.8132C39.662 25.8132 30.3734 28.6266 23.7151 33.0924ZM21.9537 30.4662C29.2002 25.6059 39.1209 22.651 50.0004 22.651C60.8799 22.651 70.8006 25.6059 78.0471 30.4662C85.2834 35.3197 90 42.1957 90 49.9999C90 57.8042 85.2834 64.6802 78.0471 69.5337C70.8006 74.394 60.8799 77.3489 50.0004 77.3489C39.1209 77.3489 29.2002 74.394 21.9537 69.5337C14.7174 64.6802 10.0008 57.8042 10.0008 49.9999C10.0008 42.1957 14.7174 35.3197 21.9537 30.4662Z",
|
|
19728
|
+
fill: "currentColor"
|
|
18089
19729
|
}
|
|
18090
|
-
|
|
18091
|
-
|
|
18092
|
-
return { searchMemory };
|
|
18093
|
-
};
|
|
19730
|
+
)
|
|
19731
|
+
] });
|
|
18094
19732
|
|
|
18095
|
-
const
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
|
|
18099
|
-
|
|
18100
|
-
|
|
18101
|
-
|
|
18102
|
-
|
|
18103
|
-
|
|
18104
|
-
|
|
18105
|
-
searchMemory,
|
|
18106
|
-
onResultClick,
|
|
18107
|
-
className,
|
|
18108
|
-
currentThreadId,
|
|
18109
|
-
chatInputValue
|
|
18110
|
-
}) => {
|
|
18111
|
-
const [query, setQuery] = useState("");
|
|
18112
|
-
const [results, setResults] = useState([]);
|
|
18113
|
-
const [isSearching, setIsSearching] = useState(false);
|
|
18114
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
18115
|
-
const [error, setError] = useState(null);
|
|
18116
|
-
const searchTimeoutRef = useRef(void 0);
|
|
18117
|
-
const dropdownRef = useRef(null);
|
|
18118
|
-
const prevThreadIdRef = useRef(currentThreadId);
|
|
18119
|
-
const lastSearchTimeRef = useRef(0);
|
|
18120
|
-
const pendingSearchRef = useRef(null);
|
|
18121
|
-
const handleSearch = useCallback(
|
|
18122
|
-
async (searchQuery) => {
|
|
18123
|
-
if (!searchQuery.trim()) {
|
|
18124
|
-
setError(null);
|
|
18125
|
-
return;
|
|
18126
|
-
}
|
|
18127
|
-
setIsSearching(true);
|
|
18128
|
-
setError(null);
|
|
18129
|
-
try {
|
|
18130
|
-
const response = await searchMemory(searchQuery);
|
|
18131
|
-
setResults(response.results);
|
|
18132
|
-
setIsOpen((prev) => prev || response.results.length > 0);
|
|
18133
|
-
} catch (err) {
|
|
18134
|
-
setError("Failed to search memory");
|
|
18135
|
-
console.error("Memory search error:", err);
|
|
18136
|
-
} finally {
|
|
18137
|
-
setIsSearching(false);
|
|
18138
|
-
}
|
|
18139
|
-
},
|
|
18140
|
-
[searchMemory]
|
|
18141
|
-
);
|
|
18142
|
-
const handleInputChange = useCallback(
|
|
18143
|
-
(e) => {
|
|
18144
|
-
const value = e.target.value;
|
|
18145
|
-
setQuery(value);
|
|
18146
|
-
if (searchTimeoutRef.current) {
|
|
18147
|
-
clearTimeout(searchTimeoutRef.current);
|
|
18148
|
-
}
|
|
18149
|
-
if (value.trim()) {
|
|
18150
|
-
const now = Date.now();
|
|
18151
|
-
const timeSinceLastSearch = now - lastSearchTimeRef.current;
|
|
18152
|
-
if (timeSinceLastSearch >= 500) {
|
|
18153
|
-
setIsSearching(true);
|
|
18154
|
-
handleSearch(value);
|
|
18155
|
-
lastSearchTimeRef.current = now;
|
|
18156
|
-
} else {
|
|
18157
|
-
setIsSearching(true);
|
|
18158
|
-
pendingSearchRef.current = value;
|
|
18159
|
-
const remainingTime = 500 - timeSinceLastSearch;
|
|
18160
|
-
searchTimeoutRef.current = setTimeout(() => {
|
|
18161
|
-
if (pendingSearchRef.current) {
|
|
18162
|
-
handleSearch(pendingSearchRef.current);
|
|
18163
|
-
lastSearchTimeRef.current = Date.now();
|
|
18164
|
-
pendingSearchRef.current = null;
|
|
18165
|
-
}
|
|
18166
|
-
}, remainingTime);
|
|
18167
|
-
}
|
|
18168
|
-
} else {
|
|
18169
|
-
setResults([]);
|
|
18170
|
-
setIsOpen(false);
|
|
18171
|
-
setIsSearching(false);
|
|
18172
|
-
pendingSearchRef.current = null;
|
|
18173
|
-
}
|
|
18174
|
-
},
|
|
18175
|
-
[handleSearch]
|
|
18176
|
-
);
|
|
18177
|
-
const handleKeyDown = useCallback(
|
|
18178
|
-
(e) => {
|
|
18179
|
-
if (e.key === "Enter") {
|
|
18180
|
-
e.preventDefault();
|
|
18181
|
-
if (searchTimeoutRef.current) {
|
|
18182
|
-
clearTimeout(searchTimeoutRef.current);
|
|
19733
|
+
const Entity = ({ children, className, onClick }) => {
|
|
19734
|
+
return /* @__PURE__ */ jsx(
|
|
19735
|
+
"div",
|
|
19736
|
+
{
|
|
19737
|
+
tabIndex: onClick ? 0 : void 0,
|
|
19738
|
+
onKeyDown: (e) => {
|
|
19739
|
+
if (!onClick) return;
|
|
19740
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
19741
|
+
e.preventDefault();
|
|
19742
|
+
onClick?.();
|
|
18183
19743
|
}
|
|
18184
|
-
|
|
18185
|
-
|
|
18186
|
-
|
|
18187
|
-
|
|
19744
|
+
},
|
|
19745
|
+
className: clsx(
|
|
19746
|
+
"flex gap-3 group/entity bg-surface3 rounded-lg border-sm border-border1 py-3 px-4",
|
|
19747
|
+
onClick && "cursor-pointer hover:bg-surface4 transition-all",
|
|
19748
|
+
className
|
|
19749
|
+
),
|
|
19750
|
+
onClick,
|
|
19751
|
+
children
|
|
19752
|
+
}
|
|
18188
19753
|
);
|
|
18189
|
-
|
|
18190
|
-
|
|
18191
|
-
|
|
18192
|
-
|
|
18193
|
-
|
|
18194
|
-
|
|
19754
|
+
};
|
|
19755
|
+
const EntityIcon = ({ children, className }) => {
|
|
19756
|
+
return /* @__PURE__ */ jsx(Icon, { size: "lg", className: clsx("text-icon3 mt-1", className), children });
|
|
19757
|
+
};
|
|
19758
|
+
const EntityName = ({ children, className }) => {
|
|
19759
|
+
return /* @__PURE__ */ jsx(Txt, { as: "p", variant: "ui-lg", className: clsx("text-icon6 font-medium", className), children });
|
|
19760
|
+
};
|
|
19761
|
+
const EntityDescription = ({ children, className }) => {
|
|
19762
|
+
return /* @__PURE__ */ jsx(Txt, { as: "p", variant: "ui-sm", className: clsx("text-icon3", className), children });
|
|
19763
|
+
};
|
|
19764
|
+
const EntityContent = ({ children, className }) => {
|
|
19765
|
+
return /* @__PURE__ */ jsx("div", { className, children });
|
|
19766
|
+
};
|
|
19767
|
+
|
|
19768
|
+
function usePolling({
|
|
19769
|
+
fetchFn,
|
|
19770
|
+
interval = 3e3,
|
|
19771
|
+
enabled = false,
|
|
19772
|
+
onSuccess,
|
|
19773
|
+
onError,
|
|
19774
|
+
shouldContinue = () => true,
|
|
19775
|
+
restartPolling = false
|
|
19776
|
+
}) {
|
|
19777
|
+
const [isPolling, setIsPolling] = useState(enabled);
|
|
19778
|
+
const [error, setError] = useState(null);
|
|
19779
|
+
const [data, setData] = useState(null);
|
|
19780
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
19781
|
+
const [firstCallLoading, setFirstCallLoading] = useState(false);
|
|
19782
|
+
const timeoutRef = useRef(null);
|
|
19783
|
+
const mountedRef = useRef(true);
|
|
19784
|
+
const [restart, setRestart] = useState(restartPolling);
|
|
19785
|
+
const cleanup = useCallback(() => {
|
|
19786
|
+
console.log("cleanup");
|
|
19787
|
+
if (timeoutRef.current) {
|
|
19788
|
+
clearTimeout(timeoutRef.current);
|
|
19789
|
+
timeoutRef.current = null;
|
|
19790
|
+
}
|
|
18195
19791
|
}, []);
|
|
18196
|
-
|
|
18197
|
-
|
|
18198
|
-
|
|
18199
|
-
|
|
18200
|
-
|
|
18201
|
-
|
|
18202
|
-
|
|
18203
|
-
|
|
19792
|
+
const stopPolling = useCallback(() => {
|
|
19793
|
+
console.log("stopPolling");
|
|
19794
|
+
setIsPolling(false);
|
|
19795
|
+
cleanup();
|
|
19796
|
+
}, [cleanup]);
|
|
19797
|
+
const startPolling = useCallback(() => {
|
|
19798
|
+
console.log("startPolling");
|
|
19799
|
+
setIsPolling(true);
|
|
19800
|
+
setError(null);
|
|
18204
19801
|
}, []);
|
|
18205
|
-
|
|
18206
|
-
|
|
18207
|
-
|
|
18208
|
-
|
|
18209
|
-
|
|
18210
|
-
|
|
18211
|
-
|
|
18212
|
-
|
|
18213
|
-
|
|
18214
|
-
|
|
18215
|
-
|
|
18216
|
-
}
|
|
18217
|
-
if (chatInputValue.trim()) {
|
|
18218
|
-
const now = Date.now();
|
|
18219
|
-
const timeSinceLastSearch = now - lastSearchTimeRef.current;
|
|
18220
|
-
if (timeSinceLastSearch >= 500) {
|
|
18221
|
-
setIsSearching(true);
|
|
18222
|
-
handleSearch(chatInputValue);
|
|
18223
|
-
lastSearchTimeRef.current = now;
|
|
19802
|
+
const executePoll = useCallback(
|
|
19803
|
+
async (refetch2 = true) => {
|
|
19804
|
+
if (!mountedRef.current) return;
|
|
19805
|
+
setIsLoading(true);
|
|
19806
|
+
try {
|
|
19807
|
+
const result = await fetchFn();
|
|
19808
|
+
setData(result);
|
|
19809
|
+
setError(null);
|
|
19810
|
+
onSuccess?.(result);
|
|
19811
|
+
if (shouldContinue(result) && refetch2) {
|
|
19812
|
+
timeoutRef.current = setTimeout(executePoll, interval);
|
|
18224
19813
|
} else {
|
|
18225
|
-
|
|
18226
|
-
|
|
18227
|
-
|
|
18228
|
-
|
|
18229
|
-
|
|
18230
|
-
|
|
18231
|
-
|
|
18232
|
-
|
|
18233
|
-
|
|
18234
|
-
|
|
19814
|
+
stopPolling();
|
|
19815
|
+
}
|
|
19816
|
+
} catch (err) {
|
|
19817
|
+
if (!mountedRef.current) return;
|
|
19818
|
+
setError(err);
|
|
19819
|
+
onError?.(err);
|
|
19820
|
+
stopPolling();
|
|
19821
|
+
} finally {
|
|
19822
|
+
if (mountedRef.current) {
|
|
19823
|
+
setFirstCallLoading(false);
|
|
19824
|
+
setIsLoading(false);
|
|
18235
19825
|
}
|
|
19826
|
+
}
|
|
19827
|
+
},
|
|
19828
|
+
[fetchFn, interval, onSuccess, onError, shouldContinue, stopPolling]
|
|
19829
|
+
);
|
|
19830
|
+
const refetch = useCallback(
|
|
19831
|
+
(withPolling = false) => {
|
|
19832
|
+
console.log("refetch", { withPolling });
|
|
19833
|
+
if (withPolling) {
|
|
19834
|
+
setIsPolling(true);
|
|
18236
19835
|
} else {
|
|
18237
|
-
|
|
18238
|
-
setIsOpen(false);
|
|
18239
|
-
setIsSearching(false);
|
|
18240
|
-
pendingSearchRef.current = null;
|
|
19836
|
+
executePoll(false);
|
|
18241
19837
|
}
|
|
19838
|
+
setError(null);
|
|
19839
|
+
},
|
|
19840
|
+
[executePoll]
|
|
19841
|
+
);
|
|
19842
|
+
useEffect(() => {
|
|
19843
|
+
mountedRef.current = true;
|
|
19844
|
+
if (enabled && isPolling) {
|
|
19845
|
+
executePoll(true);
|
|
18242
19846
|
}
|
|
18243
19847
|
return () => {
|
|
18244
|
-
|
|
18245
|
-
|
|
18246
|
-
|
|
19848
|
+
console.log("cleanup poll");
|
|
19849
|
+
mountedRef.current = false;
|
|
19850
|
+
cleanup();
|
|
18247
19851
|
};
|
|
18248
|
-
}, [
|
|
18249
|
-
|
|
18250
|
-
|
|
18251
|
-
};
|
|
18252
|
-
|
|
18253
|
-
|
|
18254
|
-
|
|
18255
|
-
|
|
18256
|
-
|
|
18257
|
-
if (searchTimeoutRef.current) {
|
|
18258
|
-
clearTimeout(searchTimeoutRef.current);
|
|
19852
|
+
}, [enabled, isPolling, executePoll, cleanup]);
|
|
19853
|
+
useEffect(() => {
|
|
19854
|
+
setRestart(restartPolling);
|
|
19855
|
+
}, [restartPolling]);
|
|
19856
|
+
useEffect(() => {
|
|
19857
|
+
if (restart && !isPolling) {
|
|
19858
|
+
setIsPolling(true);
|
|
19859
|
+
executePoll();
|
|
19860
|
+
setRestart(false);
|
|
18259
19861
|
}
|
|
19862
|
+
}, [restart]);
|
|
19863
|
+
return {
|
|
19864
|
+
isPolling,
|
|
19865
|
+
isLoading,
|
|
19866
|
+
error,
|
|
19867
|
+
data,
|
|
19868
|
+
startPolling,
|
|
19869
|
+
stopPolling,
|
|
19870
|
+
firstCallLoading,
|
|
19871
|
+
refetch
|
|
18260
19872
|
};
|
|
18261
|
-
|
|
18262
|
-
|
|
18263
|
-
|
|
18264
|
-
|
|
18265
|
-
return /* @__PURE__ */
|
|
18266
|
-
/* @__PURE__ */ jsxs("div", { className: "relative shrink-0", children: [
|
|
18267
|
-
/* @__PURE__ */ jsx(Search, { className: "absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-icon3" }),
|
|
18268
|
-
/* @__PURE__ */ jsx(
|
|
18269
|
-
Input,
|
|
18270
|
-
{
|
|
18271
|
-
type: "text",
|
|
18272
|
-
value: query,
|
|
18273
|
-
onChange: handleInputChange,
|
|
18274
|
-
onKeyDown: handleKeyDown,
|
|
18275
|
-
placeholder: "Search memory...",
|
|
18276
|
-
className: "pl-10 pr-10 bg-surface3 border-border1"
|
|
18277
|
-
}
|
|
18278
|
-
),
|
|
18279
|
-
query && /* @__PURE__ */ jsx(
|
|
18280
|
-
Button$2,
|
|
18281
|
-
{
|
|
18282
|
-
onClick: clearSearch,
|
|
18283
|
-
variant: "ghost",
|
|
18284
|
-
size: "sm",
|
|
18285
|
-
className: "absolute right-1 top-1/2 transform -translate-y-1/2 h-6 w-6 p-0",
|
|
18286
|
-
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
18287
|
-
}
|
|
18288
|
-
)
|
|
18289
|
-
] }),
|
|
18290
|
-
(isOpen || query && (isSearching || results.length === 0)) && /* @__PURE__ */ jsx("div", { className: "mt-2 flex-1 bg-surface3 border border-border1 rounded-lg shadow-lg overflow-y-auto", children: error ? /* @__PURE__ */ jsx("div", { className: "p-4 text-center", children: /* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-red-500", children: error }) }) : isSearching && results.length === 0 ? /* @__PURE__ */ jsx("div", { className: "p-4 text-center", children: /* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon3", children: "Searching..." }) }) : results.length === 0 ? /* @__PURE__ */ jsx("div", { className: "p-4 text-center", children: /* @__PURE__ */ jsxs(Txt, { variant: "ui-sm", className: "text-icon3", children: [
|
|
18291
|
-
'No results found for "',
|
|
18292
|
-
query,
|
|
18293
|
-
'"'
|
|
18294
|
-
] }) }) : /* @__PURE__ */ jsx("div", { className: "py-2", children: results.map((result) => /* @__PURE__ */ jsx(
|
|
18295
|
-
"button",
|
|
18296
|
-
{
|
|
18297
|
-
onClick: () => handleResultClick(result.id, result.threadId),
|
|
18298
|
-
className: cn(
|
|
18299
|
-
"w-full px-4 py-3 hover:bg-surface4 transition-colors duration-150 text-left border-b border-border1 last:border-b-0",
|
|
18300
|
-
result.threadId !== currentThreadId && "border-l-2 border-l-blue-400"
|
|
18301
|
-
),
|
|
18302
|
-
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
18303
|
-
result.context?.before && result.context.before.length > 0 && /* @__PURE__ */ jsx("div", { className: "opacity-50 text-xs space-y-1", children: result.context.before.map((msg, idx) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
|
|
18304
|
-
/* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
|
|
18305
|
-
msg.role,
|
|
18306
|
-
":"
|
|
18307
|
-
] }),
|
|
18308
|
-
/* @__PURE__ */ jsx("span", { className: "text-icon3", children: truncateContent(msg.content, 50) })
|
|
18309
|
-
] }, idx)) }),
|
|
18310
|
-
/* @__PURE__ */ jsx("div", { className: "flex items-start justify-between gap-2", children: /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
|
|
18311
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mb-1", children: [
|
|
18312
|
-
/* @__PURE__ */ jsx(
|
|
18313
|
-
"span",
|
|
18314
|
-
{
|
|
18315
|
-
className: cn(
|
|
18316
|
-
"text-xs font-medium px-2 py-0.5 rounded",
|
|
18317
|
-
result.role === "user" ? "bg-blue-500/20 text-blue-400" : "bg-green-500/20 text-green-400"
|
|
18318
|
-
),
|
|
18319
|
-
children: result.role
|
|
18320
|
-
}
|
|
18321
|
-
),
|
|
18322
|
-
/* @__PURE__ */ jsx(Txt, { variant: "ui-xs", className: "text-icon3", children: formatRelativeTime(new Date(result.createdAt)) }),
|
|
18323
|
-
result.threadTitle && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
18324
|
-
/* @__PURE__ */ jsxs(
|
|
18325
|
-
Txt,
|
|
18326
|
-
{
|
|
18327
|
-
variant: "ui-xs",
|
|
18328
|
-
className: cn(
|
|
18329
|
-
"truncate max-w-[150px]",
|
|
18330
|
-
result.threadId !== currentThreadId ? "text-blue-400 font-medium" : "text-icon3"
|
|
18331
|
-
),
|
|
18332
|
-
title: result.threadTitle,
|
|
18333
|
-
children: [
|
|
18334
|
-
"• ",
|
|
18335
|
-
result.threadTitle
|
|
18336
|
-
]
|
|
18337
|
-
}
|
|
18338
|
-
),
|
|
18339
|
-
result.threadId !== currentThreadId && /* @__PURE__ */ jsx(ExternalLink, { className: "w-3 h-3 text-blue-400" })
|
|
18340
|
-
] })
|
|
18341
|
-
] }),
|
|
18342
|
-
/* @__PURE__ */ jsx(Txt, { variant: "ui-sm", className: "text-icon5 break-words", children: truncateContent(result.content) })
|
|
18343
|
-
] }) }),
|
|
18344
|
-
result.context?.after && result.context.after.length > 0 && /* @__PURE__ */ jsx("div", { className: "opacity-50 text-xs space-y-1", children: result.context.after.map((msg, idx) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
|
|
18345
|
-
/* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
|
|
18346
|
-
msg.role,
|
|
18347
|
-
":"
|
|
18348
|
-
] }),
|
|
18349
|
-
/* @__PURE__ */ jsx("span", { className: "text-icon3", children: truncateContent(msg.content, 50) })
|
|
18350
|
-
] }, idx)) })
|
|
18351
|
-
] })
|
|
18352
|
-
},
|
|
18353
|
-
result.id
|
|
18354
|
-
)) }) })
|
|
18355
|
-
] });
|
|
19873
|
+
}
|
|
19874
|
+
|
|
19875
|
+
const PlaygroundQueryClient = ({ children }) => {
|
|
19876
|
+
const queryClient = new QueryClient();
|
|
19877
|
+
return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children });
|
|
18356
19878
|
};
|
|
18357
19879
|
|
|
18358
19880
|
const errorFallback = "Something went wrong while fetching the data.";
|
|
@@ -18543,6 +20065,234 @@ const EmptyMCPTable = () => /* @__PURE__ */ jsx("div", { className: "flex h-full
|
|
|
18543
20065
|
}
|
|
18544
20066
|
) });
|
|
18545
20067
|
|
|
20068
|
+
const useMCPServers = () => {
|
|
20069
|
+
const client = useMastraClient();
|
|
20070
|
+
const { runtimeContext } = usePlaygroundStore();
|
|
20071
|
+
return useQuery({
|
|
20072
|
+
queryKey: ["mcp-servers"],
|
|
20073
|
+
queryFn: async () => {
|
|
20074
|
+
const mcpServers = (await client.getMcpServers(runtimeContext)).servers;
|
|
20075
|
+
return mcpServers;
|
|
20076
|
+
}
|
|
20077
|
+
});
|
|
20078
|
+
};
|
|
20079
|
+
|
|
20080
|
+
const useMCPServerTool = (serverId, toolId) => {
|
|
20081
|
+
const { runtimeContext } = usePlaygroundStore();
|
|
20082
|
+
const client = useMastraClient();
|
|
20083
|
+
return useQuery({
|
|
20084
|
+
queryKey: ["mcp-server-tool", serverId, toolId],
|
|
20085
|
+
queryFn: () => {
|
|
20086
|
+
const instance = client.getMcpServerTool(serverId, toolId);
|
|
20087
|
+
return instance.details(runtimeContext);
|
|
20088
|
+
}
|
|
20089
|
+
});
|
|
20090
|
+
};
|
|
20091
|
+
const useExecuteMCPTool = (serverId, toolId) => {
|
|
20092
|
+
const { runtimeContext } = usePlaygroundStore();
|
|
20093
|
+
const client = useMastraClient();
|
|
20094
|
+
return useMutation({
|
|
20095
|
+
mutationFn: (data) => {
|
|
20096
|
+
const instance = client.getMcpServerTool(serverId, toolId);
|
|
20097
|
+
return instance.execute({ data, runtimeContext });
|
|
20098
|
+
}
|
|
20099
|
+
});
|
|
20100
|
+
};
|
|
20101
|
+
|
|
20102
|
+
const MCPToolPanel = ({ toolId, serverId }) => {
|
|
20103
|
+
const { data: tool, isLoading } = useMCPServerTool(serverId, toolId);
|
|
20104
|
+
const { mutateAsync: executeTool, isPending: isExecuting, data: result } = useExecuteMCPTool(serverId, toolId);
|
|
20105
|
+
const handleExecuteTool = async (data) => {
|
|
20106
|
+
if (!tool) return;
|
|
20107
|
+
return await executeTool(data);
|
|
20108
|
+
};
|
|
20109
|
+
if (isLoading) return null;
|
|
20110
|
+
if (!tool)
|
|
20111
|
+
return /* @__PURE__ */ jsx("div", { className: "py-12 text-center px-6", children: /* @__PURE__ */ jsx(Txt, { variant: "header-md", className: "text-icon3", children: "Tool not found" }) });
|
|
20112
|
+
let zodInputSchema;
|
|
20113
|
+
try {
|
|
20114
|
+
zodInputSchema = resolveSerializedZodOutput(jsonSchemaToZod(tool.inputSchema));
|
|
20115
|
+
} catch (e) {
|
|
20116
|
+
console.error("Error processing input schema:", e);
|
|
20117
|
+
toast.error("Failed to process tool input schema.");
|
|
20118
|
+
zodInputSchema = z.object({});
|
|
20119
|
+
}
|
|
20120
|
+
return /* @__PURE__ */ jsx(
|
|
20121
|
+
ToolExecutor,
|
|
20122
|
+
{
|
|
20123
|
+
executionResult: result,
|
|
20124
|
+
isExecutingTool: isExecuting,
|
|
20125
|
+
zodInputSchema,
|
|
20126
|
+
handleExecuteTool,
|
|
20127
|
+
toolDescription: tool.description || "",
|
|
20128
|
+
toolId: tool.id
|
|
20129
|
+
}
|
|
20130
|
+
);
|
|
20131
|
+
};
|
|
20132
|
+
|
|
20133
|
+
const CodeMirrorBlock = (props) => {
|
|
20134
|
+
const theme = useCodemirrorTheme$1();
|
|
20135
|
+
return /* @__PURE__ */ jsxs("div", { className: "rounded-lg border-sm border-border1 bg-surface3 p-4 relative", children: [
|
|
20136
|
+
/* @__PURE__ */ jsx("div", { className: "absolute top-4 right-4 z-10", children: /* @__PURE__ */ jsx(CopyButton, { tooltip: "Copy code", content: props.value || "No content" }) }),
|
|
20137
|
+
/* @__PURE__ */ jsx(CodeMirror, { extensions: [json()], theme, ...props })
|
|
20138
|
+
] });
|
|
20139
|
+
};
|
|
20140
|
+
|
|
20141
|
+
const MCPDetail = ({ isLoading, server }) => {
|
|
20142
|
+
const [{ sseUrl, httpStreamUrl }, setUrls] = useState({
|
|
20143
|
+
sseUrl: "",
|
|
20144
|
+
httpStreamUrl: ""
|
|
20145
|
+
});
|
|
20146
|
+
useEffect(() => {
|
|
20147
|
+
if (!server) return;
|
|
20148
|
+
const host = window.MASTRA_SERVER_HOST;
|
|
20149
|
+
const port = window.MASTRA_SERVER_PORT;
|
|
20150
|
+
let baseUrl = null;
|
|
20151
|
+
if (host && port) {
|
|
20152
|
+
baseUrl = `http://${host}:${port}`;
|
|
20153
|
+
}
|
|
20154
|
+
const effectiveBaseUrl = baseUrl || "http://localhost:4111";
|
|
20155
|
+
const sseUrl2 = `${effectiveBaseUrl}/api/mcp/${server.id}/sse`;
|
|
20156
|
+
const httpStreamUrl2 = `${effectiveBaseUrl}/api/mcp/${server.id}/mcp`;
|
|
20157
|
+
setUrls({ sseUrl: sseUrl2, httpStreamUrl: httpStreamUrl2 });
|
|
20158
|
+
}, [server]);
|
|
20159
|
+
if (isLoading) return null;
|
|
20160
|
+
if (!server)
|
|
20161
|
+
return /* @__PURE__ */ jsx(MainContentContent, { children: /* @__PURE__ */ jsx(Txt, { as: "h1", variant: "header-md", className: "text-icon3 font-medium py-20 text-center", children: "Server not found" }) });
|
|
20162
|
+
return /* @__PURE__ */ jsxs(MainContentContent, { isDivided: true, children: [
|
|
20163
|
+
/* @__PURE__ */ jsxs("div", { className: "px-8 py-20 mx-auto max-w-[604px] w-full", children: [
|
|
20164
|
+
/* @__PURE__ */ jsx(Txt, { as: "h1", variant: "header-md", className: "text-icon6 font-medium pb-4", children: server.name }),
|
|
20165
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
20166
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
20167
|
+
/* @__PURE__ */ jsx(
|
|
20168
|
+
Badge$1,
|
|
20169
|
+
{
|
|
20170
|
+
icon: /* @__PURE__ */ jsx("span", { className: "font-mono w-6 text-accent1 text-ui-xs font-medium", children: "SSE" }),
|
|
20171
|
+
className: "!text-icon4",
|
|
20172
|
+
children: sseUrl
|
|
20173
|
+
}
|
|
20174
|
+
),
|
|
20175
|
+
/* @__PURE__ */ jsx(CopyButton, { tooltip: "Copy SSE URL", content: sseUrl, iconSize: "sm" })
|
|
20176
|
+
] }),
|
|
20177
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
20178
|
+
/* @__PURE__ */ jsx(
|
|
20179
|
+
Badge$1,
|
|
20180
|
+
{
|
|
20181
|
+
icon: /* @__PURE__ */ jsx("span", { className: "font-mono w-6 text-accent1 text-ui-xs font-medium", children: "HTTP" }),
|
|
20182
|
+
className: "!text-icon4",
|
|
20183
|
+
children: httpStreamUrl
|
|
20184
|
+
}
|
|
20185
|
+
),
|
|
20186
|
+
/* @__PURE__ */ jsx(CopyButton, { tooltip: "Copy HTTP Stream URL", content: httpStreamUrl, iconSize: "sm" })
|
|
20187
|
+
] })
|
|
20188
|
+
] }),
|
|
20189
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 pt-3 pb-9", children: [
|
|
20190
|
+
/* @__PURE__ */ jsx(Badge$1, { icon: /* @__PURE__ */ jsx(FolderIcon, { className: "text-icon6" }), className: "rounded-r-sm !text-icon4", children: "Version" }),
|
|
20191
|
+
/* @__PURE__ */ jsx(Badge$1, { className: "rounded-l-sm !text-icon4", children: server.version_detail.version })
|
|
20192
|
+
] }),
|
|
20193
|
+
/* @__PURE__ */ jsx(McpSetupTabs, { sseUrl, serverName: server.name })
|
|
20194
|
+
] }),
|
|
20195
|
+
/* @__PURE__ */ jsx("div", { className: "h-full overflow-y-scroll border-l-sm border-border1", children: /* @__PURE__ */ jsx(McpToolList, { server }) })
|
|
20196
|
+
] });
|
|
20197
|
+
};
|
|
20198
|
+
const McpSetupTabs = ({ sseUrl, serverName }) => {
|
|
20199
|
+
const { Link } = useLinkComponent();
|
|
20200
|
+
return /* @__PURE__ */ jsxs(PlaygroundTabs, { defaultTab: "cursor", children: [
|
|
20201
|
+
/* @__PURE__ */ jsxs(TabList$1, { children: [
|
|
20202
|
+
/* @__PURE__ */ jsx(Tab$1, { value: "cursor", children: "Cursor" }),
|
|
20203
|
+
/* @__PURE__ */ jsx(Tab$1, { value: "windsurf", children: "Windsurf" })
|
|
20204
|
+
] }),
|
|
20205
|
+
/* @__PURE__ */ jsxs(TabContent$1, { value: "cursor", children: [
|
|
20206
|
+
/* @__PURE__ */ jsxs(Txt, { className: "text-icon3 pb-4", children: [
|
|
20207
|
+
"Cursor comes with built-in MCP Support.",
|
|
20208
|
+
" ",
|
|
20209
|
+
/* @__PURE__ */ jsx(
|
|
20210
|
+
Link,
|
|
20211
|
+
{
|
|
20212
|
+
href: "https://docs.cursor.com/context/model-context-protocol",
|
|
20213
|
+
target: "_blank",
|
|
20214
|
+
rel: "noopener noreferrer",
|
|
20215
|
+
className: "underline hover:text-icon6",
|
|
20216
|
+
children: "Following the documentation"
|
|
20217
|
+
}
|
|
20218
|
+
),
|
|
20219
|
+
", you can register an MCP server using SSE with the following configuration."
|
|
20220
|
+
] }),
|
|
20221
|
+
/* @__PURE__ */ jsx(
|
|
20222
|
+
CodeMirrorBlock,
|
|
20223
|
+
{
|
|
20224
|
+
editable: false,
|
|
20225
|
+
value: `{
|
|
20226
|
+
"mcpServers": {
|
|
20227
|
+
"${serverName}": {
|
|
20228
|
+
"url": "${sseUrl}"
|
|
20229
|
+
}
|
|
20230
|
+
}
|
|
20231
|
+
}`
|
|
20232
|
+
}
|
|
20233
|
+
)
|
|
20234
|
+
] }),
|
|
20235
|
+
/* @__PURE__ */ jsxs(TabContent$1, { value: "windsurf", children: [
|
|
20236
|
+
/* @__PURE__ */ jsxs(Txt, { className: "text-icon3 pb-4", children: [
|
|
20237
|
+
"Windsurf comes with built-in MCP Support.",
|
|
20238
|
+
" ",
|
|
20239
|
+
/* @__PURE__ */ jsx(
|
|
20240
|
+
Link,
|
|
20241
|
+
{
|
|
20242
|
+
href: "https://docs.windsurf.com/windsurf/cascade/mcp#mcp-config-json",
|
|
20243
|
+
target: "_blank",
|
|
20244
|
+
rel: "noopener noreferrer",
|
|
20245
|
+
className: "underline hover:text-icon6",
|
|
20246
|
+
children: "Following the documentation"
|
|
20247
|
+
}
|
|
20248
|
+
),
|
|
20249
|
+
", you can register an MCP server using SSE with the following configuration."
|
|
20250
|
+
] }),
|
|
20251
|
+
/* @__PURE__ */ jsx(
|
|
20252
|
+
CodeMirrorBlock,
|
|
20253
|
+
{
|
|
20254
|
+
editable: false,
|
|
20255
|
+
value: `{
|
|
20256
|
+
"mcpServers": {
|
|
20257
|
+
"${serverName}": {
|
|
20258
|
+
"command": "npx",
|
|
20259
|
+
"args": ["-y", "mcp-remote", "${sseUrl}"]
|
|
20260
|
+
}
|
|
20261
|
+
}
|
|
20262
|
+
}`
|
|
20263
|
+
}
|
|
20264
|
+
)
|
|
20265
|
+
] })
|
|
20266
|
+
] });
|
|
20267
|
+
};
|
|
20268
|
+
const McpToolList = ({ server }) => {
|
|
20269
|
+
const { data: tools = {}, isLoading } = useMCPServerTools(server);
|
|
20270
|
+
if (isLoading) return null;
|
|
20271
|
+
const toolsKeyArray = Object.keys(tools);
|
|
20272
|
+
return /* @__PURE__ */ jsxs("div", { className: "p-5 overflow-y-scroll", children: [
|
|
20273
|
+
/* @__PURE__ */ jsxs("div", { className: "text-icon6 flex gap-2 items-center", children: [
|
|
20274
|
+
/* @__PURE__ */ jsx(Icon, { size: "lg", className: "bg-surface4 rounded-md p-1", children: /* @__PURE__ */ jsx(McpServerIcon, {}) }),
|
|
20275
|
+
/* @__PURE__ */ jsx(Txt, { variant: "header-md", as: "h2", className: "font-medium", children: "Available Tools" })
|
|
20276
|
+
] }),
|
|
20277
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2 pt-6", children: toolsKeyArray.map((toolId) => {
|
|
20278
|
+
const tool = tools[toolId];
|
|
20279
|
+
return /* @__PURE__ */ jsx(ToolEntry, { tool, serverId: server.id }, toolId);
|
|
20280
|
+
}) })
|
|
20281
|
+
] });
|
|
20282
|
+
};
|
|
20283
|
+
const ToolEntry = ({ tool, serverId }) => {
|
|
20284
|
+
const linkRef = useRef(null);
|
|
20285
|
+
const { Link, paths } = useLinkComponent();
|
|
20286
|
+
const ToolIconComponent = ToolIconMap[tool.toolType || "tool"];
|
|
20287
|
+
return /* @__PURE__ */ jsxs(Entity, { onClick: () => linkRef.current?.click(), children: [
|
|
20288
|
+
/* @__PURE__ */ jsx(EntityIcon, { children: /* @__PURE__ */ jsx(ToolIconComponent, { className: "group-hover/entity:text-[#ECB047]" }) }),
|
|
20289
|
+
/* @__PURE__ */ jsxs(EntityContent, { children: [
|
|
20290
|
+
/* @__PURE__ */ jsx(EntityName, { children: /* @__PURE__ */ jsx(Link, { ref: linkRef, href: paths.mcpServerToolLink(serverId, tool.id), children: tool.id }) }),
|
|
20291
|
+
/* @__PURE__ */ jsx(EntityDescription, { children: tool.description })
|
|
20292
|
+
] })
|
|
20293
|
+
] });
|
|
20294
|
+
};
|
|
20295
|
+
|
|
18546
20296
|
const useEvalsByAgentId = (agentId, type) => {
|
|
18547
20297
|
const { runtimeContext } = usePlaygroundStore();
|
|
18548
20298
|
const client = useMastraClient();
|
|
@@ -18554,5 +20304,5 @@ const useEvalsByAgentId = (agentId, type) => {
|
|
|
18554
20304
|
});
|
|
18555
20305
|
};
|
|
18556
20306
|
|
|
18557
|
-
export { AgentChat, AgentCoinIcon, AgentEntityHeader, AgentEvals, AgentIcon, AgentMetadata, AgentMetadataList, AgentMetadataListEmpty, AgentMetadataListItem, AgentMetadataNetworkList, AgentMetadataPrompt, AgentMetadataScorerList, AgentMetadataSection, AgentMetadataToolList, AgentMetadataWorkflowList, AgentMetadataWrapper, AgentNetworkCoinIcon, AgentSettings, AgentSettingsContext, AgentSettingsProvider, AgentsTable, AiIcon, Alert$1 as Alert, AlertDescription$1 as AlertDescription, AlertDialog, AlertTitle$1 as AlertTitle, ApiIcon, Badge$1 as Badge, BranchIcon, Breadcrumb, Button$1 as Button, ButtonsGroup, Cell, ChatThreads, CheckIcon, ChevronIcon, Collapsible, CollapsibleContent, CollapsibleTrigger, CommitIcon, CrossIcon, Crumb, DarkLogo, DateTimeCell, DateTimePicker, DateTimePickerContent, DbIcon, DebugIcon, DefaultTrigger, DeploymentIcon, DividerIcon, DocsIcon, DynamicForm, EmptyState, Entity, EntityContent, EntityDescription, EntityHeader, EntityIcon, EntityMainHeader, EntityName, Entry, EntryCell, EntryList, EntryListSkeleton, EnvIcon, EvaluatorCoinIcon, FiltersIcon, FolderIcon, FormActions, GithubCoinIcon, GithubIcon, GoogleIcon, Header, HeaderAction, HeaderGroup, HeaderTitle, HomeIcon, Icon, InfoIcon, InputField, JudgeIcon, Kbd, KeyValueList, LatencyIcon, LinkComponentProvider, LogsIcon, MCPTable, MainContentContent, MainContentLayout, MainSidebar, MainSidebarProvider, MastraResizablePanel, McpCoinIcon, McpServerIcon, MemoryIcon, MemorySearch, ModelResetProvider, Notification, OpenAIIcon, PageHeader, PlaygroundQueryClient, PlaygroundTabs, PromptIcon, RadioGroup, RadioGroupField, RadioGroupItem, RepoIcon, Row, RuntimeContext, RuntimeContextWrapper, ScoreDialog, ScoreIcon, ScorersTable, ScoresList, ScoresTools, SearchField, Searchbar, SearchbarWrapper, Section, Sections, SelectField, SettingsIcon, SideDialog, SlashIcon, SliderField, SpanScoreList, SpanScoring, SpanTabs, Tab$1 as Tab, TabContent$1 as TabContent, TabList$1 as TabList, Table$1 as Table, Tbody, TemplateFailure, TemplateForm, TemplateInfo, TemplateInstallation, TemplateSuccess, TemplatesList, TemplatesTools, TextAndIcon, TextareaField, Th, Thead, ThreadDeleteButton, ThreadInputProvider, ThreadItem, ThreadLink, ThreadList, Threads, ToolCoinIcon, ToolFallback, ToolTable, ToolsIcon, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TraceDialog, TraceIcon, TraceTimeline, TraceTimelineLegend, TraceTimelineSpan, TracesList, TracesTools, TracesView, TracesViewSkeleton, TsIcon, Txt, TxtCell, UnitCell, VariablesIcon, WorkflowCoinIcon, WorkflowGraph, WorkflowIcon, WorkflowRunContext, WorkflowRunDetail, WorkflowRunList, WorkflowRunProvider, WorkflowTable, WorkflowTrigger, WorkingMemoryContext, WorkingMemoryProvider, allowedAiSpanAttributes, cleanString, convertWorkflowRunStateToStreamResult, extractPrompt, formatDuration, formatHierarchicalSpans, formatOtelTimestamp, formatOtelTimestamp2, getColumnTemplate, getShortId, getSpanTypeUi, getToNextEntryFn, getToPreviousEntryFn, parseError, providerMapToIcon, scoresListColumns, spanTypePrefixes, traceScoresListColumns, tracesListColumns, transformKey, useAgent, useAgentSettings, useAgents, useCancelWorkflowRun, useCurrentRun, useDeleteThread, useEvalsByAgentId, useExecuteAgentTool, useExecuteTool, useExecuteWorkflow, useInView, useLinkComponent, useMCPServerTools, useMainSidebar, useMemory, useMemoryConfig, useMemorySearch, useModelProviders, useModelReset, usePlaygroundStore, usePolling, useReorderModelList, useScorer, useScorers, useScoresByEntityId, useScoresByScorerId, useSendWorkflowRunEvent, useSpeechRecognition, useStreamWorkflow, useThreadInput, useThreads, useTraceSpanScores, useUpdateAgentModel, useUpdateModelInModelList, useWorkflow, useWorkflowRuns, useWorkflows, useWorkingMemory };
|
|
20307
|
+
export { AgentChat, AgentCoinIcon, AgentEntityHeader, AgentEvals, AgentIcon, AgentInformation, AgentMetadata, AgentMetadataList, AgentMetadataListEmpty, AgentMetadataListItem, AgentMetadataNetworkList, AgentMetadataPrompt, AgentMetadataScorerList, AgentMetadataSection, AgentMetadataToolList, AgentMetadataWorkflowList, AgentMetadataWrapper, AgentNetworkCoinIcon, AgentSettings, AgentSettingsContext, AgentSettingsProvider, AgentToolPanel, AgentsTable, AiIcon, Alert$1 as Alert, AlertDescription$1 as AlertDescription, AlertDialog, AlertTitle$1 as AlertTitle, ApiIcon, Badge$1 as Badge, BranchIcon, Breadcrumb, Button$1 as Button, ButtonsGroup, Cell, ChatThreads, CheckIcon, ChevronIcon, Collapsible, CollapsibleContent, CollapsibleTrigger, CommitIcon, CrossIcon, Crumb, DarkLogo, DateTimeCell, DateTimePicker, DateTimePickerContent, DbIcon, DebugIcon, DefaultTrigger, DeploymentIcon, DividerIcon, DocsIcon, DynamicForm, EmptyState, Entity, EntityContent, EntityDescription, EntityHeader, EntityIcon, EntityMainHeader, EntityName, Entry, EntryCell, EntryList, EntryListSkeleton, EnvIcon, EvaluatorCoinIcon, FiltersIcon, FolderIcon, FormActions, GithubCoinIcon, GithubIcon, GoogleIcon, Header, HeaderAction, HeaderGroup, HeaderTitle, HomeIcon, Icon, InfoIcon, InputField, JudgeIcon, Kbd, KeyValueList, LatencyIcon, LinkComponentProvider, LogsIcon, MCPDetail, MCPTable, MCPToolPanel, MainContentContent, MainContentLayout, MainSidebar, MainSidebarProvider, MastraResizablePanel, McpCoinIcon, McpServerIcon, MemoryIcon, MemorySearch, ModelResetProvider, Notification, OpenAIIcon, PageHeader, PlaygroundQueryClient, PlaygroundTabs, PromptIcon, RadioGroup, RadioGroupField, RadioGroupItem, RepoIcon, Row, RuntimeContext, RuntimeContextWrapper, ScoreDialog, ScoreIcon, ScorersTable, ScoresList, ScoresTools, SearchField, Searchbar, SearchbarWrapper, Section, Sections, SelectField, SettingsIcon, SideDialog, SlashIcon, SliderField, SpanScoreList, SpanScoring, SpanTabs, Tab$1 as Tab, TabContent$1 as TabContent, TabList$1 as TabList, Table$1 as Table, Tbody, TemplateFailure, TemplateForm, TemplateInfo, TemplateInstallation, TemplateSuccess, TemplatesList, TemplatesTools, TextAndIcon, TextareaField, Th, Thead, ThreadDeleteButton, ThreadInputProvider, ThreadItem, ThreadLink, ThreadList, Threads, ToolCoinIcon, ToolFallback, ToolIconMap, ToolInformation, ToolPanel, ToolTable, ToolsIcon, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TraceDialog, TraceIcon, TraceTimeline, TraceTimelineLegend, TraceTimelineSpan, TracesList, TracesTools, TracesView, TracesViewSkeleton, TsIcon, Txt, TxtCell, UnitCell, VariablesIcon, WorkflowCoinIcon, WorkflowGraph, WorkflowIcon, WorkflowRunContext, WorkflowRunDetail, WorkflowRunList, WorkflowRunProvider, WorkflowTable, WorkflowTrigger, WorkingMemoryContext, WorkingMemoryProvider, allowedAiSpanAttributes, cleanString, convertWorkflowRunStateToStreamResult, extractPrompt, formatDuration, formatHierarchicalSpans, formatOtelTimestamp, formatOtelTimestamp2, getColumnTemplate, getShortId, getSpanTypeUi, getToNextEntryFn, getToPreviousEntryFn, parseError, providerMapToIcon, scoresListColumns, spanTypePrefixes, traceScoresListColumns, tracesListColumns, transformKey, useAgent, useAgentSettings, useAgents, useCancelWorkflowRun, useCurrentRun, useDeleteThread, useEvalsByAgentId, useExecuteAgentTool, useExecuteMCPTool, useExecuteTool, useExecuteWorkflow, useInView, useLinkComponent, useMCPServerTool, useMCPServerTools, useMCPServers, useMainSidebar, useMemory, useMemoryConfig, useMemorySearch, useModelProviders, useModelReset, usePlaygroundStore, usePolling, useReorderModelList, useScorer, useScorers, useScoresByEntityId, useScoresByScorerId, useSendWorkflowRunEvent, useSpeechRecognition, useStreamWorkflow, useThreadInput, useThreads, useTool, useTools, useTraceSpanScores, useUpdateAgentModel, useUpdateModelInModelList, useWorkflow, useWorkflowRuns, useWorkflows, useWorkingMemory };
|
|
18558
20308
|
//# sourceMappingURL=index.es.js.map
|