@mastra/playground-ui 71.0.0-alpha.4 → 71.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EmptyStateArt.css +195 -780
- package/dist/domains/agent-avatar/agent-avatar-upload.cjs.js +3 -3
- package/dist/domains/agent-avatar/agent-avatar-upload.cjs.js.map +1 -1
- package/dist/domains/agent-avatar/agent-avatar-upload.es.js +3 -3
- package/dist/domains/agent-avatar/agent-avatar-upload.es.js.map +1 -1
- package/dist/domains/agents/chat/agent-chat.cjs.js +2 -1
- package/dist/domains/agents/chat/agent-chat.cjs.js.map +1 -1
- package/dist/domains/agents/chat/agent-chat.es.js +2 -1
- package/dist/domains/agents/chat/agent-chat.es.js.map +1 -1
- package/dist/domains/agents/chat/thread.cjs.js +7 -3
- package/dist/domains/agents/chat/thread.cjs.js.map +1 -1
- package/dist/domains/agents/chat/thread.es.js +7 -3
- package/dist/domains/agents/chat/thread.es.js.map +1 -1
- package/dist/domains/chat/messages/gen-ui/gen-ui-interface.cjs.js +15 -8
- package/dist/domains/chat/messages/gen-ui/gen-ui-interface.cjs.js.map +1 -1
- package/dist/domains/chat/messages/gen-ui/gen-ui-interface.es.js +16 -9
- package/dist/domains/chat/messages/gen-ui/gen-ui-interface.es.js.map +1 -1
- package/dist/src/domains/agents/chat/agent-chat.d.ts +3 -1
- package/dist/src/domains/agents/chat/thread.d.ts +1 -0
- package/dist/style.css +10 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread.es.js","names":["_Fragment","ChatComposerAttachments"],"sources":["../../../../src/domains/agents/chat/thread.tsx"],"sourcesContent":["import type { MastraDBMessage } from '@mastra/core/agent/message-list';\nimport type { MessageFactoryPart } from '@mastra/react/ui';\nimport type { ComponentProps } from 'react';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { AttachFileMenu } from './attachments/attach-file-menu';\nimport { ComposerAttachments as ChatComposerAttachments } from './attachments/attachment';\nimport { ComposerAttachmentsProvider, useComposerAttachments } from './attachments/composer-attachments';\nimport { ComposerFileDrop } from './attachments/composer-file-drop';\nimport { BracketOverlay } from './bracket-overlay';\nimport { FallbackThreadInputProvider, useAgentChatFeatures, useResolvedThreadInput } from './features';\nimport type { AgentChatSlots } from './features';\nimport { SuggestedPromptList } from './suggested-prompt-list';\nimport { TaskPanel } from './task-panel';\nimport { useComposerAutofocus } from './use-composer-autofocus';\nimport { startViewTransition } from './view-transition';\nimport { SaveFullConversationAction } from '@/domains/chat';\nimport { useChatMessages, useChatRunning, useChatSend } from '@/domains/chat/context/chat-context';\nimport { MessageRow } from '@/domains/chat/messages/message-row';\nimport {\n ChatAnnotationsProvider,\n ComposerAnnotations,\n formatAnnotatedMessage,\n TranscriptAnnotations,\n useChatAnnotations,\n} from '@/ds/components/ai/annotations';\n\nimport type { ChatAnnotation } from '@/ds/components/ai/annotations';\nimport { ArrivalScope } from '@/ds/components/Arrival';\nimport { Avatar } from '@/ds/components/Avatar';\nimport { Button } from '@/ds/components/Button';\nimport { ChatShell } from '@/ds/components/ChatShell';\nimport {\n Composer,\n ComposerActions,\n ComposerActionsDetail,\n ComposerActionsEnd,\n ComposerActionsStart,\n ComposerBox,\n ComposerInput,\n ComposerRing,\n} from '@/ds/components/Composer';\nimport { MessageScrollerItem } from '@/ds/components/MessageScroller';\nimport { PendingIndicator } from '@/ds/components/PendingIndicator';\nimport { buildThreadRailTurns, getClientMessageKey, groupTurns, ThreadRail } from '@/ds/components/ThreadRail';\nimport type { ThreadRailTurn } from '@/ds/components/ThreadRail';\nimport { Txt } from '@/ds/components/Txt';\nimport { IconArrowUp } from '@/ds/icons/central/IconArrowUp';\nimport { quietTextHover } from '@/ds/primitives/typography';\n\nconst EMPTY_SUGGESTED_PROMPTS: string[] = [];\n\n/**\n * Detects whether the last assistant message has a part that is actively\n * streaming output. Completed tool calls are excluded so the pending indicator\n * stays visible during quiet moments (e.g. server-side retries).\n */\nconst hasStreamingPart = (message: MastraDBMessage | undefined) => {\n if (!message) return false;\n const parts: MessageFactoryPart[] = message.content.parts;\n return parts.some(part => {\n if (part.type === 'reasoning' || part.type === 'text') {\n return 'state' in part && part.state === 'streaming';\n }\n if (part.type === 'tool-invocation') {\n return 'toolInvocation' in part && part.toolInvocation.state !== 'result';\n }\n if (part.type === 'dynamic-tool' || part.type.startsWith('tool-')) {\n const state = 'state' in part ? part.state : undefined;\n return state !== 'output-available' && state !== 'output-error';\n }\n return false;\n });\n};\n\nconst ThreadRailLayer = ({ turns }: { turns: ThreadRailTurn[] }) => {\n if (turns.length === 0) return null;\n\n return (\n // Shown once the viewport fits the 48rem column plus a rail-safe gutter on each side.\n <div\n data-testid=\"thread-rail-layer\"\n className=\"pointer-events-none absolute inset-y-0 left-4 z-20 hidden @min-[58rem]:block\"\n >\n <ThreadRail turns={turns} className=\"pointer-events-auto sticky top-1/2 -translate-y-1/2\" />\n </div>\n );\n};\n\nexport interface ThreadProps {\n mcpAppTools?: ComponentProps<typeof MessageRow>['mcpAppTools'];\n agentName?: string;\n agentId?: string;\n threadId?: string;\n suggestedPrompts?: string[];\n hasModelList?: boolean;\n hideModelSwitcher?: boolean;\n /** Extra run-scoped controls (request context, tracing options) rendered in the composer action row */\n runOptionsSlot?: React.ReactNode;\n /**\n * Called when a voice call connects. On a brand-new chat the agent page passes its\n * thread-list refresh here so the page navigates from /new to the real thread URL.\n */\n refreshThreadList?: () => Promise<void> | void;\n /**\n * True while the thread history is being fetched for the first time. The skeleton\n * only replaces the welcome screen; live messages that arrive earlier take precedence.\n */\n isHistoryLoading?: boolean;\n onLoadPrevious?: () => void | Promise<void>;\n isLoadingPrevious?: boolean;\n}\n\nconst ThreadContent = ({\n agentName,\n agentId,\n threadId,\n suggestedPrompts,\n hasModelList,\n hideModelSwitcher,\n runOptionsSlot,\n refreshThreadList,\n isHistoryLoading,\n onLoadPrevious,\n isLoadingPrevious,\n mcpAppTools,\n}: ThreadProps) => {\n const messagesContainerRef = useRef<HTMLDivElement>(null);\n const features = useAgentChatFeatures();\n const { draft, updateDraft } = useResolvedThreadInput();\n const LoadingSkeleton = features.slots?.LoadingSkeleton;\n\n const messages = useChatMessages();\n const { isRunning } = useChatRunning();\n const readAloud = features.readAloud;\n const browser = features.browser;\n const showThumbnailInChat = Boolean(\n browser?.hasSession && (browser.viewMode === 'collapsed' || browser.viewMode === 'expanded'),\n );\n\n const isEmpty = messages.length === 0;\n const lastMessage = messages[messages.length - 1];\n const showPending = isRunning && (lastMessage?.role !== 'assistant' || !hasStreamingPart(lastMessage));\n const threadRailTurns = useMemo(() => buildThreadRailTurns(messages), [messages]);\n const threadRailAnchorIds = useMemo(() => new Set(threadRailTurns.map(turn => turn.messageId)), [threadRailTurns]);\n // Keyed by the opening message's client key: `data-user-message` reconciliation\n // swaps `message.id` to the server signal id, and a changing key would remount\n // the whole turn.\n const turnGroups = groupTurns(messages, {\n key: getClientMessageKey,\n opensTurn: message => threadRailAnchorIds.has(message.id),\n });\n\n // Before the first message the dock is unpinned and centered so the greeting,\n // composer and prompts read as one landing. The composer keeps its tree position\n // in both modes so the first send doesn't remount it (focus and attachments stay).\n const showLanding = isEmpty && !isHistoryLoading;\n // The layout follows `showLanding` one commit late so leaving the landing can be\n // wrapped in a view transition: the named composer then glides to the dock\n // instead of snapping. Only the exit caused by a send is animated (the chat is\n // running then); a history load resolving on refresh or thread switch also flips\n // `showLanding` false and must snap, or the composer visibly slides on every load.\n const [landingShown, setLandingShown] = useState(showLanding);\n useEffect(() => {\n if (landingShown === showLanding) return;\n if (showLanding || !isRunning) {\n setLandingShown(showLanding);\n return;\n }\n startViewTransition(() => setLandingShown(false));\n }, [showLanding, landingShown, isRunning]);\n\n return (\n <ComposerAttachmentsProvider\n controlled={\n draft && updateDraft\n ? {\n value: draft.attachments,\n onChange: value =>\n updateDraft(previous => ({\n ...previous,\n attachments: typeof value === 'function' ? value(previous.attachments) : value,\n })),\n }\n : undefined\n }\n >\n <ChatShell\n className=\"h-full\"\n scroller={{\n autoScroll: true,\n defaultScrollPosition: 'last-anchor',\n onReachStart: onLoadPrevious,\n preserveScrollOnPrepend: Boolean(onLoadPrevious),\n }}\n data-testid=\"thread-wrapper\"\n >\n <ChatShell.Stage>\n <ChatShell.Viewport style={{ overflowAnchor: 'none' }}>\n <ThreadRailLayer turns={threadRailTurns} />\n <ChatShell.Content className={landingShown ? 'flex-none' : undefined}>\n {isLoadingPrevious && (\n <ChatShell.Column\n data-testid=\"thread-history-older-skeleton\"\n aria-busy=\"true\"\n aria-label=\"Loading older messages\"\n className=\"py-3\"\n >\n {LoadingSkeleton ? <LoadingSkeleton /> : null}\n </ChatShell.Column>\n )}\n {isEmpty && isHistoryLoading ? (\n <ChatShell.Column data-testid=\"thread-history-skeleton\" aria-busy=\"true\" className=\"flex-1 py-4\">\n {LoadingSkeleton ? <LoadingSkeleton /> : null}\n </ChatShell.Column>\n ) : landingShown ? null : (\n <ChatShell.Transcript\n ref={messagesContainerRef}\n data-testid=\"thread-message-column\"\n className=\"flex-1 gap-4 py-4\"\n >\n <BracketOverlay containerRef={messagesContainerRef} />\n <TranscriptAnnotations />\n {/* Everything already here when the reader arrived is theirs; what lands after fades in. */}\n <ArrivalScope>\n {turnGroups.map((group, index) => {\n const isLiveTurn = index === turnGroups.length - 1;\n // The first turn opens at the top already; room under it would only add empty scroll.\n const holdsRoom = isLiveTurn && isRunning && group.opensTurn && index > 0;\n return (\n <ChatShell.Turn\n key={group.key}\n opensTurn={group.opensTurn}\n holdsRoom={holdsRoom}\n className=\"gap-4\"\n >\n {group.entries.map(message => (\n <MessageScrollerItem\n key={getClientMessageKey(message)}\n messageId={message.id}\n scrollAnchor={threadRailAnchorIds.has(message.id)}\n >\n <MessageRow\n message={message}\n hasModelList={hasModelList}\n isSpeaking={readAloud?.isSpeaking ?? false}\n onReadAloud={readAloud?.readAloud}\n onStopSpeaking={readAloud?.stop}\n mcpAppTools={mcpAppTools ?? features.mcpAppTools}\n />\n </MessageScrollerItem>\n ))}\n {isLiveTurn && showPending && (\n <PendingIndicator className=\"animate-in delay-300 duration-200 fade-in-0 fill-mode-backwards\" />\n )}\n </ChatShell.Turn>\n );\n })}\n </ArrivalScope>\n {!isRunning && <SaveFullConversationAction />}\n </ChatShell.Transcript>\n )}\n </ChatShell.Content>\n <ChatShell.Dock\n data-testid={landingShown ? 'thread-landing' : undefined}\n className={\n landingShown\n ? 'static flex flex-1 flex-col justify-end pt-12 pb-[max(--spacing(12),30dvh)] before:hidden'\n : undefined\n }\n >\n {landingShown ? null : <ChatShell.ScrollButton busy={isRunning} />}\n <ChatShell.Column className={landingShown ? 'gap-6 px-1 md:px-1' : 'gap-2 px-1 md:px-1'}>\n {landingShown ? (\n <>\n <ThreadWelcome agentName={agentName} />\n {agentId ? features.slots?.channelsCard?.(agentId) : null}\n </>\n ) : (\n <>\n {showThumbnailInChat && agentId && threadId ? features.slots?.browserThumbnail?.(agentName) : null}\n <TaskPanel />\n </>\n )}\n <div className={landingShown ? 'starter-prompt' : undefined}>\n <AgentComposer\n agentId={agentId}\n threadId={threadId}\n hasModelList={hasModelList}\n hideModelSwitcher={hideModelSwitcher}\n runOptionsSlot={runOptionsSlot}\n refreshThreadList={refreshThreadList}\n />\n </div>\n {landingShown ? <SuggestedPromptList prompts={suggestedPrompts ?? EMPTY_SUGGESTED_PROMPTS} /> : null}\n </ChatShell.Column>\n </ChatShell.Dock>\n </ChatShell.Viewport>\n </ChatShell.Stage>\n </ChatShell>\n </ComposerAttachmentsProvider>\n );\n};\n\nexport const Thread = (props: ThreadProps) => (\n <ChatAnnotationsProvider>\n <FallbackThreadInputProvider>\n <ThreadContent {...props} />\n </FallbackThreadInputProvider>\n </ChatAnnotationsProvider>\n);\n\nconst ThreadWelcome = ({ agentName }: { agentName?: string }) => {\n return (\n <div data-testid=\"thread-welcome\" className=\"flex w-full flex-col items-center gap-4\">\n <div className=\"starter-heading\">\n <Avatar name={agentName || 'Agent'} size=\"lg\" />\n </div>\n <Txt\n as=\"h1\"\n variant=\"display\"\n tone=\"muted\"\n className=\"starter-heading mx-auto max-w-2xl text-center font-normal text-balance\"\n >\n What can <span className=\"font-medium text-foreground\">{agentName || 'this agent'}</span> do for you today?\n </Txt>\n </div>\n );\n};\n\ninterface AgentComposerProps {\n agentId?: string;\n threadId?: string;\n hasModelList?: boolean;\n hideModelSwitcher?: boolean;\n runOptionsSlot?: React.ReactNode;\n refreshThreadList?: () => Promise<void> | void;\n}\n\nconst AgentComposer = ({ agentId, threadId, hasModelList, hideModelSwitcher, runOptionsSlot }: AgentComposerProps) => {\n const { threadInput: text, setThreadInput, updateDraft, draftStatus } = useResolvedThreadInput();\n const features = useAgentChatFeatures();\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const { annotations, takeAnnotations, restoreAnnotations } = useChatAnnotations();\n const preparing = useRef(false);\n const lifetime = useRef(0);\n useEffect(\n () => () => {\n lifetime.current++;\n },\n [],\n );\n const [submitError, setSubmitError] = useState<string>();\n const send = useChatSend();\n const { attachments, toCoreUserMessages, clear, restore, isAddingAttachments } = useComposerAttachments();\n const { isRunning, canSendWhileStreaming, cancelRun } = useChatRunning();\n const [sendPulseKey, setSendPulseKey] = useState(0);\n const canExecuteAgent = features.canExecute !== false;\n const inputDisabled = !canExecuteAgent || Boolean(draftStatus?.restoring);\n useComposerAutofocus(textareaRef, { threadId, disabled: inputDisabled });\n\n const isEmpty = text.trim().length === 0 && attachments.length === 0 && annotations.length === 0;\n const sendBlocked = isRunning && !canSendWhileStreaming;\n const showModelSwitcher = Boolean(agentId && !hasModelList && !hideModelSwitcher);\n const shownError = submitError || draftStatus?.error;\n\n const submit = async () => {\n if (\n isEmpty ||\n sendBlocked ||\n !canExecuteAgent ||\n draftStatus?.restoring ||\n isAddingAttachments ||\n preparing.current\n )\n return;\n preparing.current = true;\n const currentLifetime = lifetime.current;\n const submittedAttachments = attachments;\n const submittedIds = new Set(submittedAttachments.map(attachment => attachment.id));\n // A message the server can't have stored goes back in the composer, before anything typed since.\n const withSubmittedText = (typed: string) => [text, typed].filter(Boolean).join('\\n\\n');\n const restoreSubmission = (sentAnnotations: readonly ChatAnnotation[]) => {\n if (lifetime.current !== currentLifetime) return;\n restoreAnnotations(sentAnnotations);\n if (updateDraft)\n updateDraft(previous => ({\n text: withSubmittedText(previous.text),\n attachments: [...submittedAttachments, ...previous.attachments],\n }));\n else {\n setThreadInput(withSubmittedText);\n restore(submittedAttachments);\n }\n setSubmitError('Your message could not be sent. Your draft has been restored.');\n };\n setSubmitError(undefined);\n try {\n const coreUserMessages = attachments.length > 0 ? await toCoreUserMessages() : undefined;\n if (lifetime.current !== currentLifetime) return;\n // Clear only the submitted snapshot; edits made during file conversion belong to the next draft.\n if (updateDraft)\n updateDraft(previous => ({\n text: previous.text === text ? '' : previous.text,\n attachments: previous.attachments.filter(attachment => !submittedIds.has(attachment.id)),\n }));\n else {\n setThreadInput('');\n clear();\n }\n const sentAnnotations = takeAnnotations();\n setSendPulseKey(k => k + 1);\n const message = formatAnnotatedMessage(text, sentAnnotations);\n void Promise.resolve(send({ message, attachments: coreUserMessages })).then(delivered => {\n if (delivered === false) restoreSubmission(sentAnnotations);\n });\n } catch {\n if (lifetime.current === currentLifetime)\n setSubmitError('Attachments could not be prepared. Your draft has been kept.');\n } finally {\n preparing.current = false;\n }\n };\n\n return (\n // Named so the chat/settings view transition can slide the composer toward\n // the bottom edge independently of the root crossfade.\n <div className=\"relative\" style={{ viewTransitionName: 'agent-chat-composer' }}>\n {features.slots?.voiceCallPanel}\n {shownError && (\n <Txt variant=\"caption\" role=\"alert\">\n {shownError}\n </Txt>\n )}\n {draftStatus?.restoring && (\n <Txt variant=\"caption\" role=\"status\" className=\"sr-only\">\n Restoring draft…\n </Txt>\n )}\n <ComposerFileDrop disabled={!canExecuteAgent || draftStatus?.restoring}>\n <Composer\n className=\"relative\"\n onSubmit={event => {\n event.preventDefault();\n void submit();\n }}\n >\n <ComposerRing busy={isRunning}>\n <ComposerBox sendingPulseKey={sendPulseKey}>\n <ComposerAnnotations />\n <ChatComposerAttachments />\n <ComposerInput\n ref={textareaRef}\n value={text}\n placeholder={canExecuteAgent ? 'Enter your message' : \"You don't have permission to execute agents\"}\n onChange={event => {\n setThreadInput(event.target.value);\n }}\n onKeyDown={event => {\n // Ignore Enter while an IME composition is active (e.g. committing a\n // CJK/pinyin candidate). `isComposing` is the browser-owned flag; the\n // `keyCode === 229` fallback covers browsers that fire keydown without it.\n if (event.nativeEvent.isComposing || event.keyCode === 229) return;\n if (event.key === 'Enter' && !event.shiftKey) {\n if (sendBlocked) return;\n event.preventDefault();\n event.stopPropagation();\n void submit();\n }\n }}\n disabled={inputDisabled}\n />\n {showModelSwitcher && features.slots?.modelWarning}\n <ComposerActions>\n <ComposerActionRow\n canExecute={canExecuteAgent}\n agentId={agentId}\n runOptionsSlot={runOptionsSlot}\n showModelSwitcher={showModelSwitcher}\n isEmpty={isEmpty}\n isRunning={isRunning}\n canSendWhileStreaming={canSendWhileStreaming}\n onCancel={() => void cancelRun()}\n onSetText={value => {\n setThreadInput(value);\n }}\n speechInput={features.slots?.speechInput}\n modelSwitcher={features.slots?.modelSwitcher}\n modelSettings={features.slots?.modelSettings}\n voiceCallButton={features.slots?.voiceCallButton}\n />\n </ComposerActions>\n </ComposerBox>\n </ComposerRing>\n </Composer>\n </ComposerFileDrop>\n </div>\n );\n};\n\ninterface ComposerActionRowProps {\n canExecute?: boolean;\n agentId?: string;\n showModelSwitcher?: boolean;\n runOptionsSlot?: React.ReactNode;\n isEmpty: boolean;\n isRunning: boolean;\n canSendWhileStreaming: boolean;\n onCancel: () => void;\n onSetText: (text: string) => void;\n speechInput?: AgentChatSlots['speechInput'];\n modelSwitcher?: React.ReactNode;\n modelSettings?: AgentChatSlots['modelSettings'];\n voiceCallButton?: React.ReactNode;\n}\n\nconst ComposerActionRow = ({\n canExecute = true,\n agentId,\n showModelSwitcher,\n runOptionsSlot,\n isEmpty,\n isRunning,\n canSendWhileStreaming,\n onCancel,\n onSetText,\n speechInput,\n modelSwitcher,\n modelSettings,\n voiceCallButton,\n}: ComposerActionRowProps) => {\n return (\n <>\n <ComposerActionsStart>\n {canExecute && <AttachFileMenu />}\n <ComposerActionsDetail>{runOptionsSlot}</ComposerActionsDetail>\n </ComposerActionsStart>\n <ComposerActionsEnd>\n {showModelSwitcher && agentId && (\n <>\n {modelSwitcher}\n <ComposerActionsDetail>{modelSettings?.(agentId)}</ComposerActionsDetail>\n </>\n )}\n {canExecute && speechInput?.({ agentId, onTranscript: onSetText })}\n {canExecute && agentId && <ComposerActionsDetail>{voiceCallButton}</ComposerActionsDetail>}\n <ComposerSendButton\n canExecute={canExecute}\n isEmpty={isEmpty}\n isRunning={isRunning}\n canSendWhileStreaming={canSendWhileStreaming}\n onCancel={onCancel}\n />\n </ComposerActionsEnd>\n </>\n );\n};\n\ninterface ComposerSendButtonProps {\n canExecute?: boolean;\n isEmpty: boolean;\n isRunning: boolean;\n canSendWhileStreaming: boolean;\n onCancel: () => void;\n}\n\nconst ComposerSendButton = ({\n canExecute = true,\n isEmpty,\n isRunning,\n canSendWhileStreaming,\n onCancel,\n}: ComposerSendButtonProps) => {\n const { isAddingAttachments } = useComposerAttachments();\n const draftCanSteerRun = canSendWhileStreaming && !isEmpty;\n if (isRunning && !draftCanSteerRun) {\n return (\n <Button\n variant=\"primary\"\n size=\"icon-md\"\n type=\"button\"\n tooltip=\"Cancel\"\n onClick={event => {\n // Send turns into Cancel under the pointer: a double-click on Send must not cancel.\n if (event.detail > 1) return;\n onCancel();\n }}\n >\n <CircleStopIcon />\n </Button>\n );\n }\n\n return (\n <Button\n type=\"submit\"\n variant=\"primary\"\n size=\"icon-md\"\n tooltip={canExecute ? 'Send' : 'No permission to execute'}\n disabled={!canExecute || isEmpty || isAddingAttachments}\n >\n <IconArrowUp />\n </Button>\n );\n};\n\nconst CircleStopIcon = () => {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className={quietTextHover}\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <rect width=\"6\" height=\"6\" x=\"9\" y=\"9\" rx=\"1\" />\n </svg>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAM,0BAAoC,CAAC;;;;;;AAO3C,IAAM,oBAAoB,YAAyC;CACjE,IAAI,CAAC,SAAS,OAAO;CAErB,OADoC,QAAQ,QAAQ,MACvC,MAAK,SAAQ;EACxB,IAAI,KAAK,SAAS,eAAe,KAAK,SAAS,QAC7C,OAAO,WAAW,QAAQ,KAAK,UAAU;EAE3C,IAAI,KAAK,SAAS,mBAChB,OAAO,oBAAoB,QAAQ,KAAK,eAAe,UAAU;EAEnE,IAAI,KAAK,SAAS,kBAAkB,KAAK,KAAK,WAAW,OAAO,GAAG;GACjE,MAAM,QAAQ,WAAW,OAAO,KAAK,QAAQ,KAAA;GAC7C,OAAO,UAAU,sBAAsB,UAAU;EACnD;EACA,OAAO;CACT,CAAC;AACH;AAEA,IAAM,mBAAmB,EAAE,YAAyC;CAClE,IAAI,MAAM,WAAW,GAAG,OAAO;CAE/B,OAEE,oBAAC,OAAD;EACE,eAAY;EACZ,WAAU;EAEV,UAAA,oBAAC,YAAD;GAAmB;GAAO,WAAU;EAAuD,CAAA;CACxF,CAAA;AAET;AA0BA,IAAM,iBAAiB,EACrB,WACA,SACA,UACA,kBACA,cACA,mBACA,gBACA,mBACA,kBACA,gBACA,mBACA,kBACiB;CACjB,MAAM,uBAAuB,OAAuB,IAAI;CACxD,MAAM,WAAW,qBAAqB;CACtC,MAAM,EAAE,OAAO,gBAAgB,uBAAuB;CACtD,MAAM,kBAAkB,SAAS,OAAO;CAExC,MAAM,WAAW,gBAAgB;CACjC,MAAM,EAAE,cAAc,eAAe;CACrC,MAAM,YAAY,SAAS;CAC3B,MAAM,UAAU,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
1
|
+
{"version":3,"file":"thread.es.js","names":["_Fragment","ChatComposerAttachments"],"sources":["../../../../src/domains/agents/chat/thread.tsx"],"sourcesContent":["import type { MastraDBMessage } from '@mastra/core/agent/message-list';\nimport type { MessageFactoryPart } from '@mastra/react/ui';\nimport type { ComponentProps } from 'react';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { AttachFileMenu } from './attachments/attach-file-menu';\nimport { ComposerAttachments as ChatComposerAttachments } from './attachments/attachment';\nimport { ComposerAttachmentsProvider, useComposerAttachments } from './attachments/composer-attachments';\nimport { ComposerFileDrop } from './attachments/composer-file-drop';\nimport { BracketOverlay } from './bracket-overlay';\nimport { FallbackThreadInputProvider, useAgentChatFeatures, useResolvedThreadInput } from './features';\nimport type { AgentChatSlots } from './features';\nimport { SuggestedPromptList } from './suggested-prompt-list';\nimport { TaskPanel } from './task-panel';\nimport { useComposerAutofocus } from './use-composer-autofocus';\nimport { startViewTransition } from './view-transition';\nimport { SaveFullConversationAction } from '@/domains/chat';\nimport { useChatMessages, useChatRunning, useChatSend } from '@/domains/chat/context/chat-context';\nimport { MessageRow } from '@/domains/chat/messages/message-row';\nimport {\n ChatAnnotationsProvider,\n ComposerAnnotations,\n formatAnnotatedMessage,\n TranscriptAnnotations,\n useChatAnnotations,\n} from '@/ds/components/ai/annotations';\n\nimport type { ChatAnnotation } from '@/ds/components/ai/annotations';\nimport { ArrivalScope } from '@/ds/components/Arrival';\nimport { Avatar } from '@/ds/components/Avatar';\nimport { Button } from '@/ds/components/Button';\nimport { ChatShell } from '@/ds/components/ChatShell';\nimport {\n Composer,\n ComposerActions,\n ComposerActionsDetail,\n ComposerActionsEnd,\n ComposerActionsStart,\n ComposerBox,\n ComposerInput,\n ComposerRing,\n} from '@/ds/components/Composer';\nimport { MessageScrollerItem } from '@/ds/components/MessageScroller';\nimport { PendingIndicator } from '@/ds/components/PendingIndicator';\nimport { buildThreadRailTurns, getClientMessageKey, groupTurns, ThreadRail } from '@/ds/components/ThreadRail';\nimport type { ThreadRailTurn } from '@/ds/components/ThreadRail';\nimport { Txt } from '@/ds/components/Txt';\nimport { IconArrowUp } from '@/ds/icons/central/IconArrowUp';\nimport { quietTextHover } from '@/ds/primitives/typography';\n\nconst EMPTY_SUGGESTED_PROMPTS: string[] = [];\n\n/**\n * Detects whether the last assistant message has a part that is actively\n * streaming output. Completed tool calls are excluded so the pending indicator\n * stays visible during quiet moments (e.g. server-side retries).\n */\nconst hasStreamingPart = (message: MastraDBMessage | undefined) => {\n if (!message) return false;\n const parts: MessageFactoryPart[] = message.content.parts;\n return parts.some(part => {\n if (part.type === 'reasoning' || part.type === 'text') {\n return 'state' in part && part.state === 'streaming';\n }\n if (part.type === 'tool-invocation') {\n return 'toolInvocation' in part && part.toolInvocation.state !== 'result';\n }\n if (part.type === 'dynamic-tool' || part.type.startsWith('tool-')) {\n const state = 'state' in part ? part.state : undefined;\n return state !== 'output-available' && state !== 'output-error';\n }\n return false;\n });\n};\n\nconst ThreadRailLayer = ({ turns }: { turns: ThreadRailTurn[] }) => {\n if (turns.length === 0) return null;\n\n return (\n // Shown once the viewport fits the 48rem column plus a rail-safe gutter on each side.\n <div\n data-testid=\"thread-rail-layer\"\n className=\"pointer-events-none absolute inset-y-0 left-4 z-20 hidden @min-[58rem]:block\"\n >\n <ThreadRail turns={turns} className=\"pointer-events-auto sticky top-1/2 -translate-y-1/2\" />\n </div>\n );\n};\n\nexport interface ThreadProps {\n mcpAppTools?: ComponentProps<typeof MessageRow>['mcpAppTools'];\n agentName?: string;\n agentAvatarUrl?: string;\n agentId?: string;\n threadId?: string;\n suggestedPrompts?: string[];\n hasModelList?: boolean;\n hideModelSwitcher?: boolean;\n /** Extra run-scoped controls (request context, tracing options) rendered in the composer action row */\n runOptionsSlot?: React.ReactNode;\n /**\n * Called when a voice call connects. On a brand-new chat the agent page passes its\n * thread-list refresh here so the page navigates from /new to the real thread URL.\n */\n refreshThreadList?: () => Promise<void> | void;\n /**\n * True while the thread history is being fetched for the first time. The skeleton\n * only replaces the welcome screen; live messages that arrive earlier take precedence.\n */\n isHistoryLoading?: boolean;\n onLoadPrevious?: () => void | Promise<void>;\n isLoadingPrevious?: boolean;\n}\n\nconst ThreadContent = ({\n agentName,\n agentAvatarUrl,\n agentId,\n threadId,\n suggestedPrompts,\n hasModelList,\n hideModelSwitcher,\n runOptionsSlot,\n refreshThreadList,\n isHistoryLoading,\n onLoadPrevious,\n isLoadingPrevious,\n mcpAppTools,\n}: ThreadProps) => {\n const messagesContainerRef = useRef<HTMLDivElement>(null);\n const features = useAgentChatFeatures();\n const { draft, updateDraft } = useResolvedThreadInput();\n const LoadingSkeleton = features.slots?.LoadingSkeleton;\n\n const messages = useChatMessages();\n const { isRunning } = useChatRunning();\n const readAloud = features.readAloud;\n const browser = features.browser;\n const showThumbnailInChat = Boolean(\n browser?.hasSession && (browser.viewMode === 'collapsed' || browser.viewMode === 'expanded'),\n );\n\n const isEmpty = messages.length === 0;\n const lastMessage = messages[messages.length - 1];\n const showPending = isRunning && (lastMessage?.role !== 'assistant' || !hasStreamingPart(lastMessage));\n const threadRailTurns = useMemo(() => buildThreadRailTurns(messages), [messages]);\n const threadRailAnchorIds = useMemo(() => new Set(threadRailTurns.map(turn => turn.messageId)), [threadRailTurns]);\n // Keyed by the opening message's client key: `data-user-message` reconciliation\n // swaps `message.id` to the server signal id, and a changing key would remount\n // the whole turn.\n const turnGroups = groupTurns(messages, {\n key: getClientMessageKey,\n opensTurn: message => threadRailAnchorIds.has(message.id),\n });\n\n // Before the first message the dock is unpinned and centered so the greeting,\n // composer and prompts read as one landing. The composer keeps its tree position\n // in both modes so the first send doesn't remount it (focus and attachments stay).\n const showLanding = isEmpty && !isHistoryLoading;\n // The layout follows `showLanding` one commit late so leaving the landing can be\n // wrapped in a view transition: the named composer then glides to the dock\n // instead of snapping. Only the exit caused by a send is animated (the chat is\n // running then); a history load resolving on refresh or thread switch also flips\n // `showLanding` false and must snap, or the composer visibly slides on every load.\n const [landingShown, setLandingShown] = useState(showLanding);\n useEffect(() => {\n if (landingShown === showLanding) return;\n if (showLanding || !isRunning) {\n setLandingShown(showLanding);\n return;\n }\n startViewTransition(() => setLandingShown(false));\n }, [showLanding, landingShown, isRunning]);\n\n return (\n <ComposerAttachmentsProvider\n controlled={\n draft && updateDraft\n ? {\n value: draft.attachments,\n onChange: value =>\n updateDraft(previous => ({\n ...previous,\n attachments: typeof value === 'function' ? value(previous.attachments) : value,\n })),\n }\n : undefined\n }\n >\n <ChatShell\n className=\"h-full\"\n scroller={{\n autoScroll: true,\n defaultScrollPosition: 'last-anchor',\n onReachStart: onLoadPrevious,\n preserveScrollOnPrepend: Boolean(onLoadPrevious),\n }}\n data-testid=\"thread-wrapper\"\n >\n <ChatShell.Stage>\n <ChatShell.Viewport style={{ overflowAnchor: 'none' }}>\n <ThreadRailLayer turns={threadRailTurns} />\n <ChatShell.Content className={landingShown ? 'flex-none' : undefined}>\n {isLoadingPrevious && (\n <ChatShell.Column\n data-testid=\"thread-history-older-skeleton\"\n aria-busy=\"true\"\n aria-label=\"Loading older messages\"\n className=\"py-3\"\n >\n {LoadingSkeleton ? <LoadingSkeleton /> : null}\n </ChatShell.Column>\n )}\n {isEmpty && isHistoryLoading ? (\n <ChatShell.Column data-testid=\"thread-history-skeleton\" aria-busy=\"true\" className=\"flex-1 py-4\">\n {LoadingSkeleton ? <LoadingSkeleton /> : null}\n </ChatShell.Column>\n ) : landingShown ? null : (\n <ChatShell.Transcript\n ref={messagesContainerRef}\n data-testid=\"thread-message-column\"\n className=\"flex-1 gap-4 py-4\"\n >\n <BracketOverlay containerRef={messagesContainerRef} />\n <TranscriptAnnotations />\n {/* Everything already here when the reader arrived is theirs; what lands after fades in. */}\n <ArrivalScope>\n {turnGroups.map((group, index) => {\n const isLiveTurn = index === turnGroups.length - 1;\n // The first turn opens at the top already; room under it would only add empty scroll.\n const holdsRoom = isLiveTurn && isRunning && group.opensTurn && index > 0;\n return (\n <ChatShell.Turn\n key={group.key}\n opensTurn={group.opensTurn}\n holdsRoom={holdsRoom}\n className=\"gap-4\"\n >\n {group.entries.map(message => (\n <MessageScrollerItem\n key={getClientMessageKey(message)}\n messageId={message.id}\n scrollAnchor={threadRailAnchorIds.has(message.id)}\n >\n <MessageRow\n message={message}\n hasModelList={hasModelList}\n isSpeaking={readAloud?.isSpeaking ?? false}\n onReadAloud={readAloud?.readAloud}\n onStopSpeaking={readAloud?.stop}\n mcpAppTools={mcpAppTools ?? features.mcpAppTools}\n />\n </MessageScrollerItem>\n ))}\n {isLiveTurn && showPending && (\n <PendingIndicator className=\"animate-in delay-300 duration-200 fade-in-0 fill-mode-backwards\" />\n )}\n </ChatShell.Turn>\n );\n })}\n </ArrivalScope>\n {!isRunning && <SaveFullConversationAction />}\n </ChatShell.Transcript>\n )}\n </ChatShell.Content>\n <ChatShell.Dock\n data-testid={landingShown ? 'thread-landing' : undefined}\n className={\n landingShown\n ? 'static flex flex-1 flex-col justify-end pt-12 pb-[max(--spacing(12),30dvh)] before:hidden'\n : undefined\n }\n >\n {landingShown ? null : <ChatShell.ScrollButton busy={isRunning} />}\n <ChatShell.Column className={landingShown ? 'gap-6 px-1 md:px-1' : 'gap-2 px-1 md:px-1'}>\n {landingShown ? (\n <>\n <ThreadWelcome agentName={agentName} avatarUrl={agentAvatarUrl} />\n {agentId ? features.slots?.channelsCard?.(agentId) : null}\n </>\n ) : (\n <>\n {showThumbnailInChat && agentId && threadId ? features.slots?.browserThumbnail?.(agentName) : null}\n <TaskPanel />\n </>\n )}\n <div className={landingShown ? 'starter-prompt' : undefined}>\n <AgentComposer\n agentId={agentId}\n threadId={threadId}\n hasModelList={hasModelList}\n hideModelSwitcher={hideModelSwitcher}\n runOptionsSlot={runOptionsSlot}\n refreshThreadList={refreshThreadList}\n />\n </div>\n {landingShown ? <SuggestedPromptList prompts={suggestedPrompts ?? EMPTY_SUGGESTED_PROMPTS} /> : null}\n </ChatShell.Column>\n </ChatShell.Dock>\n </ChatShell.Viewport>\n </ChatShell.Stage>\n </ChatShell>\n </ComposerAttachmentsProvider>\n );\n};\n\nexport const Thread = (props: ThreadProps) => (\n <ChatAnnotationsProvider>\n <FallbackThreadInputProvider>\n <ThreadContent {...props} />\n </FallbackThreadInputProvider>\n </ChatAnnotationsProvider>\n);\n\nconst ThreadWelcome = ({ agentName, avatarUrl }: { agentName?: string; avatarUrl?: string }) => {\n return (\n <div data-testid=\"thread-welcome\" className=\"flex w-full flex-col items-center gap-4\">\n <div className=\"starter-heading\">\n <Avatar src={avatarUrl} name={agentName || 'Agent'} size=\"lg\" />\n </div>\n <Txt\n as=\"h1\"\n variant=\"display\"\n tone=\"muted\"\n className=\"starter-heading mx-auto max-w-2xl text-center font-normal text-balance\"\n >\n What can <span className=\"font-medium text-foreground\">{agentName || 'this agent'}</span> do for you today?\n </Txt>\n </div>\n );\n};\n\ninterface AgentComposerProps {\n agentId?: string;\n threadId?: string;\n hasModelList?: boolean;\n hideModelSwitcher?: boolean;\n runOptionsSlot?: React.ReactNode;\n refreshThreadList?: () => Promise<void> | void;\n}\n\nconst AgentComposer = ({ agentId, threadId, hasModelList, hideModelSwitcher, runOptionsSlot }: AgentComposerProps) => {\n const { threadInput: text, setThreadInput, updateDraft, draftStatus } = useResolvedThreadInput();\n const features = useAgentChatFeatures();\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const { annotations, takeAnnotations, restoreAnnotations } = useChatAnnotations();\n const preparing = useRef(false);\n const lifetime = useRef(0);\n useEffect(\n () => () => {\n lifetime.current++;\n },\n [],\n );\n const [submitError, setSubmitError] = useState<string>();\n const send = useChatSend();\n const { attachments, toCoreUserMessages, clear, restore, isAddingAttachments } = useComposerAttachments();\n const { isRunning, canSendWhileStreaming, cancelRun } = useChatRunning();\n const [sendPulseKey, setSendPulseKey] = useState(0);\n const canExecuteAgent = features.canExecute !== false;\n const inputDisabled = !canExecuteAgent || Boolean(draftStatus?.restoring);\n useComposerAutofocus(textareaRef, { threadId, disabled: inputDisabled });\n\n const isEmpty = text.trim().length === 0 && attachments.length === 0 && annotations.length === 0;\n const sendBlocked = isRunning && !canSendWhileStreaming;\n const showModelSwitcher = Boolean(agentId && !hasModelList && !hideModelSwitcher);\n const shownError = submitError || draftStatus?.error;\n\n const submit = async () => {\n if (\n isEmpty ||\n sendBlocked ||\n !canExecuteAgent ||\n draftStatus?.restoring ||\n isAddingAttachments ||\n preparing.current\n )\n return;\n preparing.current = true;\n const currentLifetime = lifetime.current;\n const submittedAttachments = attachments;\n const submittedIds = new Set(submittedAttachments.map(attachment => attachment.id));\n // A message the server can't have stored goes back in the composer, before anything typed since.\n const withSubmittedText = (typed: string) => [text, typed].filter(Boolean).join('\\n\\n');\n const restoreSubmission = (sentAnnotations: readonly ChatAnnotation[]) => {\n if (lifetime.current !== currentLifetime) return;\n restoreAnnotations(sentAnnotations);\n if (updateDraft)\n updateDraft(previous => ({\n text: withSubmittedText(previous.text),\n attachments: [...submittedAttachments, ...previous.attachments],\n }));\n else {\n setThreadInput(withSubmittedText);\n restore(submittedAttachments);\n }\n setSubmitError('Your message could not be sent. Your draft has been restored.');\n };\n setSubmitError(undefined);\n try {\n const coreUserMessages = attachments.length > 0 ? await toCoreUserMessages() : undefined;\n if (lifetime.current !== currentLifetime) return;\n // Clear only the submitted snapshot; edits made during file conversion belong to the next draft.\n if (updateDraft)\n updateDraft(previous => ({\n text: previous.text === text ? '' : previous.text,\n attachments: previous.attachments.filter(attachment => !submittedIds.has(attachment.id)),\n }));\n else {\n setThreadInput('');\n clear();\n }\n const sentAnnotations = takeAnnotations();\n setSendPulseKey(k => k + 1);\n const message = formatAnnotatedMessage(text, sentAnnotations);\n void Promise.resolve(send({ message, attachments: coreUserMessages })).then(delivered => {\n if (delivered === false) restoreSubmission(sentAnnotations);\n });\n } catch {\n if (lifetime.current === currentLifetime)\n setSubmitError('Attachments could not be prepared. Your draft has been kept.');\n } finally {\n preparing.current = false;\n }\n };\n\n return (\n // Named so the chat/settings view transition can slide the composer toward\n // the bottom edge independently of the root crossfade.\n <div className=\"relative\" style={{ viewTransitionName: 'agent-chat-composer' }}>\n {features.slots?.voiceCallPanel}\n {shownError && (\n <Txt variant=\"caption\" role=\"alert\">\n {shownError}\n </Txt>\n )}\n {draftStatus?.restoring && (\n <Txt variant=\"caption\" role=\"status\" className=\"sr-only\">\n Restoring draft…\n </Txt>\n )}\n <ComposerFileDrop disabled={!canExecuteAgent || draftStatus?.restoring}>\n <Composer\n className=\"relative\"\n onSubmit={event => {\n event.preventDefault();\n void submit();\n }}\n >\n <ComposerRing busy={isRunning}>\n <ComposerBox sendingPulseKey={sendPulseKey}>\n <ComposerAnnotations />\n <ChatComposerAttachments />\n <ComposerInput\n ref={textareaRef}\n value={text}\n placeholder={canExecuteAgent ? 'Enter your message' : \"You don't have permission to execute agents\"}\n onChange={event => {\n setThreadInput(event.target.value);\n }}\n onKeyDown={event => {\n // Ignore Enter while an IME composition is active (e.g. committing a\n // CJK/pinyin candidate). `isComposing` is the browser-owned flag; the\n // `keyCode === 229` fallback covers browsers that fire keydown without it.\n if (event.nativeEvent.isComposing || event.keyCode === 229) return;\n if (event.key === 'Enter' && !event.shiftKey) {\n if (sendBlocked) return;\n event.preventDefault();\n event.stopPropagation();\n void submit();\n }\n }}\n disabled={inputDisabled}\n />\n {showModelSwitcher && features.slots?.modelWarning}\n <ComposerActions>\n <ComposerActionRow\n canExecute={canExecuteAgent}\n agentId={agentId}\n runOptionsSlot={runOptionsSlot}\n showModelSwitcher={showModelSwitcher}\n isEmpty={isEmpty}\n isRunning={isRunning}\n canSendWhileStreaming={canSendWhileStreaming}\n onCancel={() => void cancelRun()}\n onSetText={value => {\n setThreadInput(value);\n }}\n speechInput={features.slots?.speechInput}\n modelSwitcher={features.slots?.modelSwitcher}\n modelSettings={features.slots?.modelSettings}\n voiceCallButton={features.slots?.voiceCallButton}\n />\n </ComposerActions>\n </ComposerBox>\n </ComposerRing>\n </Composer>\n </ComposerFileDrop>\n </div>\n );\n};\n\ninterface ComposerActionRowProps {\n canExecute?: boolean;\n agentId?: string;\n showModelSwitcher?: boolean;\n runOptionsSlot?: React.ReactNode;\n isEmpty: boolean;\n isRunning: boolean;\n canSendWhileStreaming: boolean;\n onCancel: () => void;\n onSetText: (text: string) => void;\n speechInput?: AgentChatSlots['speechInput'];\n modelSwitcher?: React.ReactNode;\n modelSettings?: AgentChatSlots['modelSettings'];\n voiceCallButton?: React.ReactNode;\n}\n\nconst ComposerActionRow = ({\n canExecute = true,\n agentId,\n showModelSwitcher,\n runOptionsSlot,\n isEmpty,\n isRunning,\n canSendWhileStreaming,\n onCancel,\n onSetText,\n speechInput,\n modelSwitcher,\n modelSettings,\n voiceCallButton,\n}: ComposerActionRowProps) => {\n return (\n <>\n <ComposerActionsStart>\n {canExecute && <AttachFileMenu />}\n <ComposerActionsDetail>{runOptionsSlot}</ComposerActionsDetail>\n </ComposerActionsStart>\n <ComposerActionsEnd>\n {showModelSwitcher && agentId && (\n <>\n {modelSwitcher}\n <ComposerActionsDetail>{modelSettings?.(agentId)}</ComposerActionsDetail>\n </>\n )}\n {canExecute && speechInput?.({ agentId, onTranscript: onSetText })}\n {canExecute && agentId && <ComposerActionsDetail>{voiceCallButton}</ComposerActionsDetail>}\n <ComposerSendButton\n canExecute={canExecute}\n isEmpty={isEmpty}\n isRunning={isRunning}\n canSendWhileStreaming={canSendWhileStreaming}\n onCancel={onCancel}\n />\n </ComposerActionsEnd>\n </>\n );\n};\n\ninterface ComposerSendButtonProps {\n canExecute?: boolean;\n isEmpty: boolean;\n isRunning: boolean;\n canSendWhileStreaming: boolean;\n onCancel: () => void;\n}\n\nconst ComposerSendButton = ({\n canExecute = true,\n isEmpty,\n isRunning,\n canSendWhileStreaming,\n onCancel,\n}: ComposerSendButtonProps) => {\n const { isAddingAttachments } = useComposerAttachments();\n const draftCanSteerRun = canSendWhileStreaming && !isEmpty;\n if (isRunning && !draftCanSteerRun) {\n return (\n <Button\n variant=\"primary\"\n size=\"icon-md\"\n type=\"button\"\n tooltip=\"Cancel\"\n onClick={event => {\n // Send turns into Cancel under the pointer: a double-click on Send must not cancel.\n if (event.detail > 1) return;\n onCancel();\n }}\n >\n <CircleStopIcon />\n </Button>\n );\n }\n\n return (\n <Button\n type=\"submit\"\n variant=\"primary\"\n size=\"icon-md\"\n tooltip={canExecute ? 'Send' : 'No permission to execute'}\n disabled={!canExecute || isEmpty || isAddingAttachments}\n >\n <IconArrowUp />\n </Button>\n );\n};\n\nconst CircleStopIcon = () => {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className={quietTextHover}\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <rect width=\"6\" height=\"6\" x=\"9\" y=\"9\" rx=\"1\" />\n </svg>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAM,0BAAoC,CAAC;;;;;;AAO3C,IAAM,oBAAoB,YAAyC;CACjE,IAAI,CAAC,SAAS,OAAO;CAErB,OADoC,QAAQ,QAAQ,MACvC,MAAK,SAAQ;EACxB,IAAI,KAAK,SAAS,eAAe,KAAK,SAAS,QAC7C,OAAO,WAAW,QAAQ,KAAK,UAAU;EAE3C,IAAI,KAAK,SAAS,mBAChB,OAAO,oBAAoB,QAAQ,KAAK,eAAe,UAAU;EAEnE,IAAI,KAAK,SAAS,kBAAkB,KAAK,KAAK,WAAW,OAAO,GAAG;GACjE,MAAM,QAAQ,WAAW,OAAO,KAAK,QAAQ,KAAA;GAC7C,OAAO,UAAU,sBAAsB,UAAU;EACnD;EACA,OAAO;CACT,CAAC;AACH;AAEA,IAAM,mBAAmB,EAAE,YAAyC;CAClE,IAAI,MAAM,WAAW,GAAG,OAAO;CAE/B,OAEE,oBAAC,OAAD;EACE,eAAY;EACZ,WAAU;EAEV,UAAA,oBAAC,YAAD;GAAmB;GAAO,WAA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,UAAA,oBAAC,aAAD,CAAc,CAAA;CACR,CAAA;AAEZ;AAEA,IAAM,uBAAuB;CAC3B,OACE,qBAAC,OAAD;EACE,OAAM;EACN,OAAM;EACN,QAAO;EACP,SAAQ;EACR,MAAK;EACL,QAAO;EACP,aAAY;EACZ,eAAc;EACd,gBAAe;EACf,WAAW;EAVb,UAAA,CAYE,oBAAC,UAAD;GAAQ,IAAG;GAAK,IAAG;GAAK,GAAE;EAAM,CAAA,GAChC,oBAAC,QAAD;GAAM,OAAM;GAAI,QAAO;GAAI,GAAE;GAAI,GAAE;GAAI,IAAG;EAAK,CAAA,CAC5C;;AAET"}
|
|
@@ -22,14 +22,17 @@ var readOnlyRegistry = studioRegistry().registry;
|
|
|
22
22
|
* interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.
|
|
23
23
|
*/
|
|
24
24
|
function GenUiInterface({ parts, onSend, disabled = false }) {
|
|
25
|
+
const [wentLive, setWentLive] = (0, react.useState)(false);
|
|
26
|
+
if (onSend && !disabled && !wentLive) setWentLive(true);
|
|
25
27
|
const spec = (0, _json_render_react.buildSpecFromParts)(structuredClone(parts));
|
|
26
28
|
if (!spec) return null;
|
|
27
29
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
28
30
|
"data-slot": "gen-ui-interface",
|
|
29
31
|
className: "@container min-w-0",
|
|
30
|
-
children: onSend && !disabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LiveInterface, {
|
|
32
|
+
children: onSend && (wentLive || !disabled) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LiveInterface, {
|
|
31
33
|
spec,
|
|
32
|
-
onSend
|
|
34
|
+
onSend,
|
|
35
|
+
disabled
|
|
33
36
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ReadOnlyInterface, { spec })
|
|
34
37
|
});
|
|
35
38
|
}
|
|
@@ -44,14 +47,18 @@ function ReadOnlyInterface({ spec }) {
|
|
|
44
47
|
});
|
|
45
48
|
}
|
|
46
49
|
/**
|
|
47
|
-
* Mounts once the interface can act, so its state starts from the complete spec
|
|
48
|
-
* the action handlers it mounts with
|
|
49
|
-
*
|
|
50
|
+
* Mounts once the interface can act, so its state starts from the complete spec, and keeps that state
|
|
51
|
+
* from then on. json-render keeps the action handlers it mounts with, so they send through a ref to
|
|
52
|
+
* the latest `onSend`.
|
|
50
53
|
*/
|
|
51
|
-
function LiveInterface({ spec, onSend }) {
|
|
54
|
+
function LiveInterface({ spec, onSend, disabled }) {
|
|
55
|
+
const onSendRef = (0, react.useRef)(onSend);
|
|
56
|
+
(0, react.useEffect)(() => {
|
|
57
|
+
onSendRef.current = onSend;
|
|
58
|
+
}, [onSend]);
|
|
52
59
|
const [live] = (0, react.useState)(() => {
|
|
53
60
|
const store = (0, _json_render_core.createStateStore)(spec.state ?? {});
|
|
54
|
-
const { registry, handlers } = studioRegistry(
|
|
61
|
+
const { registry, handlers } = studioRegistry((message, state) => onSendRef.current(message, state));
|
|
55
62
|
return {
|
|
56
63
|
store,
|
|
57
64
|
registry,
|
|
@@ -59,7 +66,7 @@ function LiveInterface({ spec, onSend }) {
|
|
|
59
66
|
};
|
|
60
67
|
});
|
|
61
68
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_domains_chat_messages_gen_ui_interactive_context.GenUiInteractiveContext.Provider, {
|
|
62
|
-
value:
|
|
69
|
+
value: !disabled,
|
|
63
70
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_json_render_react.JSONUIProvider, {
|
|
64
71
|
registry: live.registry,
|
|
65
72
|
store: live.store,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gen-ui-interface.cjs.js","names":["defineRegistry","studioCatalog","studioComponents","buildSpecFromParts","JSONUIProvider","Renderer","
|
|
1
|
+
{"version":3,"file":"gen-ui-interface.cjs.js","names":["defineRegistry","studioCatalog","studioComponents","useState","buildSpecFromParts","JSONUIProvider","Renderer","useRef","createStateStore","GenUiInteractiveContext"],"sources":["../../../../../src/domains/chat/messages/gen-ui/gen-ui-interface.tsx"],"sourcesContent":["import { createStateStore } from '@json-render/core';\nimport type { Spec } from '@json-render/core';\nimport { JSONUIProvider, Renderer, buildSpecFromParts, defineRegistry } from '@json-render/react';\nimport type { DataPart } from '@json-render/react';\nimport { studioCatalog } from '@mastra/json-render/studio';\nimport { useEffect, useRef, useState } from 'react';\nimport { GenUiInteractiveContext } from './interactive-context';\nimport { studioComponents } from './studio-components';\n\nexport const SPEC_PART_TYPE = 'data-spec';\n\n/** Sends `message` as the user's next turn, with the interface's current state. */\nexport type GenUiSend = (message: string, state: Record<string, unknown>) => void;\n\nexport interface GenUiInterfaceProps {\n /** The reply's `data-spec` parts, in order. */\n parts: DataPart[];\n /** Omit to render the interface read-only. */\n onSend?: GenUiSend;\n /** Disables the interface's controls, e.g. while the chat is replying. */\n disabled?: boolean;\n}\n\nfunction studioRegistry(onSend?: GenUiSend) {\n return defineRegistry(studioCatalog, {\n components: studioComponents,\n actions: {\n sendMessage: async (params, _setState, state) => {\n if (params?.message) onSend?.(params.message, state);\n },\n },\n });\n}\n\nconst readOnlyRegistry = studioRegistry().registry;\n\n/**\n * Renders the interface an agent composed in its reply with `studioCatalog`. Once it can act, the\n * interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.\n */\nexport function GenUiInterface({ parts, onSend, disabled = false }: GenUiInterfaceProps) {\n // Once live, stays live: disabling it while the chat replies must not reset what the user entered.\n const [wentLive, setWentLive] = useState(false);\n if (onSend && !disabled && !wentLive) setWentLive(true);\n\n // buildSpecFromParts mutates nested objects of the parts it reads.\n const spec = buildSpecFromParts(structuredClone(parts));\n if (!spec) return null;\n\n return (\n <div data-slot=\"gen-ui-interface\" className=\"@container min-w-0\">\n {onSend && (wentLive || !disabled) ? (\n <LiveInterface spec={spec} onSend={onSend} disabled={disabled} />\n ) : (\n <ReadOnlyInterface spec={spec} />\n )}\n </div>\n );\n}\n\nfunction ReadOnlyInterface({ spec }: { spec: Spec }) {\n // Uncontrolled: the provider follows the state a streaming spec declares as it arrives.\n return (\n <JSONUIProvider registry={readOnlyRegistry} initialState={spec.state}>\n <Renderer spec={spec} registry={readOnlyRegistry} />\n </JSONUIProvider>\n );\n}\n\n/**\n * Mounts once the interface can act, so its state starts from the complete spec, and keeps that state\n * from then on. json-render keeps the action handlers it mounts with, so they send through a ref to\n * the latest `onSend`.\n */\nfunction LiveInterface({ spec, onSend, disabled }: { spec: Spec; onSend: GenUiSend; disabled: boolean }) {\n const onSendRef = useRef(onSend);\n useEffect(() => {\n onSendRef.current = onSend;\n }, [onSend]);\n\n const [live] = useState(() => {\n const store = createStateStore(spec.state ?? {});\n const { registry, handlers } = studioRegistry((message, state) => onSendRef.current(message, state));\n return { store, registry, handlers: handlers(() => undefined, store.getSnapshot) };\n });\n\n return (\n <GenUiInteractiveContext.Provider value={!disabled}>\n <JSONUIProvider registry={live.registry} store={live.store} handlers={live.handlers}>\n <Renderer spec={spec} registry={live.registry} />\n </JSONUIProvider>\n </GenUiInteractiveContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;AASA,IAAa,iBAAiB;AAc9B,SAAS,eAAe,QAAoB;CAC1C,QAAA,GAAOA,mBAAAA,eAAAA,CAAeC,2BAAAA,eAAe;EACnC,YAAYC,uDAAAA;EACZ,SAAS,EACP,aAAa,OAAO,QAAQ,WAAW,UAAU;GAC/C,IAAI,QAAQ,SAAS,SAAS,OAAO,SAAS,KAAK;EACrD,EACF;CACF,CAAC;AACH;AAEA,IAAM,mBAAmB,eAAe,CAAC,CAAC;;;;;AAM1C,SAAgB,eAAe,EAAE,OAAO,QAAQ,WAAW,SAA8B;CAEvF,MAAM,CAAC,UAAU,gBAAA,GAAeC,MAAAA,SAAAA,CAAS,KAAK;CAC9C,IAAI,UAAU,CAAC,YAAY,CAAC,UAAU,YAAY,IAAI;CAGtD,MAAM,QAAA,GAAOC,mBAAAA,mBAAAA,CAAmB,gBAAgB,KAAK,CAAC;CACtD,IAAI,CAAC,MAAM,O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CAACC,mBAAAA,UAAD;IAAgB;IAAM,UAAU,KAAK;GAAW,CAAA;EAClC,CAAA;CACgB,CAAA;AAEtC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GenUiInteractiveContext } from "./interactive-context.es.js";
|
|
2
2
|
import { studioComponents } from "./studio-components.es.js";
|
|
3
|
-
import { useState } from "react";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { studioCatalog } from "@mastra/json-render/studio";
|
|
6
6
|
import { createStateStore } from "@json-render/core";
|
|
@@ -21,14 +21,17 @@ var readOnlyRegistry = studioRegistry().registry;
|
|
|
21
21
|
* interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.
|
|
22
22
|
*/
|
|
23
23
|
function GenUiInterface({ parts, onSend, disabled = false }) {
|
|
24
|
+
const [wentLive, setWentLive] = useState(false);
|
|
25
|
+
if (onSend && !disabled && !wentLive) setWentLive(true);
|
|
24
26
|
const spec = buildSpecFromParts(structuredClone(parts));
|
|
25
27
|
if (!spec) return null;
|
|
26
28
|
return /* @__PURE__ */ jsx("div", {
|
|
27
29
|
"data-slot": "gen-ui-interface",
|
|
28
30
|
className: "@container min-w-0",
|
|
29
|
-
children: onSend && !disabled ? /* @__PURE__ */ jsx(LiveInterface, {
|
|
31
|
+
children: onSend && (wentLive || !disabled) ? /* @__PURE__ */ jsx(LiveInterface, {
|
|
30
32
|
spec,
|
|
31
|
-
onSend
|
|
33
|
+
onSend,
|
|
34
|
+
disabled
|
|
32
35
|
}) : /* @__PURE__ */ jsx(ReadOnlyInterface, { spec })
|
|
33
36
|
});
|
|
34
37
|
}
|
|
@@ -43,14 +46,18 @@ function ReadOnlyInterface({ spec }) {
|
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
48
|
/**
|
|
46
|
-
* Mounts once the interface can act, so its state starts from the complete spec
|
|
47
|
-
* the action handlers it mounts with
|
|
48
|
-
*
|
|
49
|
+
* Mounts once the interface can act, so its state starts from the complete spec, and keeps that state
|
|
50
|
+
* from then on. json-render keeps the action handlers it mounts with, so they send through a ref to
|
|
51
|
+
* the latest `onSend`.
|
|
49
52
|
*/
|
|
50
|
-
function LiveInterface({ spec, onSend }) {
|
|
53
|
+
function LiveInterface({ spec, onSend, disabled }) {
|
|
54
|
+
const onSendRef = useRef(onSend);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
onSendRef.current = onSend;
|
|
57
|
+
}, [onSend]);
|
|
51
58
|
const [live] = useState(() => {
|
|
52
59
|
const store = createStateStore(spec.state ?? {});
|
|
53
|
-
const { registry, handlers } = studioRegistry(
|
|
60
|
+
const { registry, handlers } = studioRegistry((message, state) => onSendRef.current(message, state));
|
|
54
61
|
return {
|
|
55
62
|
store,
|
|
56
63
|
registry,
|
|
@@ -58,7 +65,7 @@ function LiveInterface({ spec, onSend }) {
|
|
|
58
65
|
};
|
|
59
66
|
});
|
|
60
67
|
return /* @__PURE__ */ jsx(GenUiInteractiveContext.Provider, {
|
|
61
|
-
value:
|
|
68
|
+
value: !disabled,
|
|
62
69
|
children: /* @__PURE__ */ jsx(JSONUIProvider, {
|
|
63
70
|
registry: live.registry,
|
|
64
71
|
store: live.store,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gen-ui-interface.es.js","names":[],"sources":["../../../../../src/domains/chat/messages/gen-ui/gen-ui-interface.tsx"],"sourcesContent":["import { createStateStore } from '@json-render/core';\nimport type { Spec } from '@json-render/core';\nimport { JSONUIProvider, Renderer, buildSpecFromParts, defineRegistry } from '@json-render/react';\nimport type { DataPart } from '@json-render/react';\nimport { studioCatalog } from '@mastra/json-render/studio';\nimport { useState } from 'react';\nimport { GenUiInteractiveContext } from './interactive-context';\nimport { studioComponents } from './studio-components';\n\nexport const SPEC_PART_TYPE = 'data-spec';\n\n/** Sends `message` as the user's next turn, with the interface's current state. */\nexport type GenUiSend = (message: string, state: Record<string, unknown>) => void;\n\nexport interface GenUiInterfaceProps {\n /** The reply's `data-spec` parts, in order. */\n parts: DataPart[];\n /** Omit to render the interface read-only. */\n onSend?: GenUiSend;\n /** Disables the interface's controls, e.g. while the chat is replying. */\n disabled?: boolean;\n}\n\nfunction studioRegistry(onSend?: GenUiSend) {\n return defineRegistry(studioCatalog, {\n components: studioComponents,\n actions: {\n sendMessage: async (params, _setState, state) => {\n if (params?.message) onSend?.(params.message, state);\n },\n },\n });\n}\n\nconst readOnlyRegistry = studioRegistry().registry;\n\n/**\n * Renders the interface an agent composed in its reply with `studioCatalog`. Once it can act, the\n * interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.\n */\nexport function GenUiInterface({ parts, onSend, disabled = false }: GenUiInterfaceProps) {\n // buildSpecFromParts mutates nested objects of the parts it reads.\n const spec = buildSpecFromParts(structuredClone(parts));\n if (!spec) return null;\n\n return (\n <div data-slot=\"gen-ui-interface\" className=\"@container min-w-0\">\n {onSend && !disabled ? <LiveInterface spec={spec} onSend={onSend}
|
|
1
|
+
{"version":3,"file":"gen-ui-interface.es.js","names":[],"sources":["../../../../../src/domains/chat/messages/gen-ui/gen-ui-interface.tsx"],"sourcesContent":["import { createStateStore } from '@json-render/core';\nimport type { Spec } from '@json-render/core';\nimport { JSONUIProvider, Renderer, buildSpecFromParts, defineRegistry } from '@json-render/react';\nimport type { DataPart } from '@json-render/react';\nimport { studioCatalog } from '@mastra/json-render/studio';\nimport { useEffect, useRef, useState } from 'react';\nimport { GenUiInteractiveContext } from './interactive-context';\nimport { studioComponents } from './studio-components';\n\nexport const SPEC_PART_TYPE = 'data-spec';\n\n/** Sends `message` as the user's next turn, with the interface's current state. */\nexport type GenUiSend = (message: string, state: Record<string, unknown>) => void;\n\nexport interface GenUiInterfaceProps {\n /** The reply's `data-spec` parts, in order. */\n parts: DataPart[];\n /** Omit to render the interface read-only. */\n onSend?: GenUiSend;\n /** Disables the interface's controls, e.g. while the chat is replying. */\n disabled?: boolean;\n}\n\nfunction studioRegistry(onSend?: GenUiSend) {\n return defineRegistry(studioCatalog, {\n components: studioComponents,\n actions: {\n sendMessage: async (params, _setState, state) => {\n if (params?.message) onSend?.(params.message, state);\n },\n },\n });\n}\n\nconst readOnlyRegistry = studioRegistry().registry;\n\n/**\n * Renders the interface an agent composed in its reply with `studioCatalog`. Once it can act, the\n * interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.\n */\nexport function GenUiInterface({ parts, onSend, disabled = false }: GenUiInterfaceProps) {\n // Once live, stays live: disabling it while the chat replies must not reset what the user entered.\n const [wentLive, setWentLive] = useState(false);\n if (onSend && !disabled && !wentLive) setWentLive(true);\n\n // buildSpecFromParts mutates nested objects of the parts it reads.\n const spec = buildSpecFromParts(structuredClone(parts));\n if (!spec) return null;\n\n return (\n <div data-slot=\"gen-ui-interface\" className=\"@container min-w-0\">\n {onSend && (wentLive || !disabled) ? (\n <LiveInterface spec={spec} onSend={onSend} disabled={disabled} />\n ) : (\n <ReadOnlyInterface spec={spec} />\n )}\n </div>\n );\n}\n\nfunction ReadOnlyInterface({ spec }: { spec: Spec }) {\n // Uncontrolled: the provider follows the state a streaming spec declares as it arrives.\n return (\n <JSONUIProvider registry={readOnlyRegistry} initialState={spec.state}>\n <Renderer spec={spec} registry={readOnlyRegistry} />\n </JSONUIProvider>\n );\n}\n\n/**\n * Mounts once the interface can act, so its state starts from the complete spec, and keeps that state\n * from then on. json-render keeps the action handlers it mounts with, so they send through a ref to\n * the latest `onSend`.\n */\nfunction LiveInterface({ spec, onSend, disabled }: { spec: Spec; onSend: GenUiSend; disabled: boolean }) {\n const onSendRef = useRef(onSend);\n useEffect(() => {\n onSendRef.current = onSend;\n }, [onSend]);\n\n const [live] = useState(() => {\n const store = createStateStore(spec.state ?? {});\n const { registry, handlers } = studioRegistry((message, state) => onSendRef.current(message, state));\n return { store, registry, handlers: handlers(() => undefined, store.getSnapshot) };\n });\n\n return (\n <GenUiInteractiveContext.Provider value={!disabled}>\n <JSONUIProvider registry={live.registry} store={live.store} handlers={live.handlers}>\n <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K,CAAC;EACnG,OAAO;GAAE;GAAO;GAAU,UAAU,eAAe,KAAA,GAAW,MAAM,WAAW;EAAE;CACnF,CAAC;CAED,OACE,oBAAC,wBAAwB,UAAzB;EAAkC,OAAO,CAAC;EACxC,UAAA,oBAAC,gBAAD;GAAgB,UAAU,KAAK;GAAU,OAAO,KAAK;GAAO,UAAU,KAAK;GACzE,UAAA,oBAAC,UAAD;IAAgB;IAAM,UAAU,KAAK;GAAW,CAAA;EAClC,CAAA;CACgB,CAAA;AAEtC"}
|
|
@@ -5,6 +5,8 @@ export type AgentChatProps = Omit<ChatProps, 'initialMessages'> & {
|
|
|
5
5
|
memory?: boolean;
|
|
6
6
|
messageId?: string;
|
|
7
7
|
suggestedPrompts?: string[];
|
|
8
|
+
/** Image shown on the empty-thread welcome; falls back to the agent initial. */
|
|
9
|
+
agentAvatarUrl?: string;
|
|
8
10
|
isNewThread?: boolean;
|
|
9
11
|
hideModelSwitcher?: boolean;
|
|
10
12
|
runOptionsSlot?: ReactNode;
|
|
@@ -15,4 +17,4 @@ export type AgentChatProps = Omit<ChatProps, 'initialMessages'> & {
|
|
|
15
17
|
children: ReactNode;
|
|
16
18
|
}>;
|
|
17
19
|
};
|
|
18
|
-
export declare function AgentChat({ memory, messageId, suggestedPrompts, isNewThread, hideModelSwitcher, runOptionsSlot, RuntimeFeatures, ComposerFeatures, ...chat }: AgentChatProps): import("react").JSX.Element;
|
|
20
|
+
export declare function AgentChat({ memory, messageId, suggestedPrompts, agentAvatarUrl, isNewThread, hideModelSwitcher, runOptionsSlot, RuntimeFeatures, ComposerFeatures, ...chat }: AgentChatProps): import("react").JSX.Element;
|
|
@@ -3,6 +3,7 @@ import { MessageRow } from '../../chat/messages/message-row';
|
|
|
3
3
|
export interface ThreadProps {
|
|
4
4
|
mcpAppTools?: ComponentProps<typeof MessageRow>['mcpAppTools'];
|
|
5
5
|
agentName?: string;
|
|
6
|
+
agentAvatarUrl?: string;
|
|
6
7
|
agentId?: string;
|
|
7
8
|
threadId?: string;
|
|
8
9
|
suggestedPrompts?: string[];
|
package/dist/style.css
CHANGED
|
@@ -6007,6 +6007,16 @@
|
|
|
6007
6007
|
}
|
|
6008
6008
|
}
|
|
6009
6009
|
|
|
6010
|
+
.bg-muted\/80 {
|
|
6011
|
+
background-color: var(--muted);
|
|
6012
|
+
}
|
|
6013
|
+
|
|
6014
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
6015
|
+
.bg-muted\/80 {
|
|
6016
|
+
background-color: color-mix(in oklab, var(--muted) 80%, transparent);
|
|
6017
|
+
}
|
|
6018
|
+
}
|
|
6019
|
+
|
|
6010
6020
|
.bg-placeholder {
|
|
6011
6021
|
background-color: var(--placeholder);
|
|
6012
6022
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/playground-ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "71.0.0-alpha.
|
|
4
|
+
"version": "71.0.0-alpha.6",
|
|
5
5
|
"description": "Mastra Playground components",
|
|
6
6
|
"sideEffects": [
|
|
7
7
|
"**/*.css"
|
|
@@ -230,9 +230,9 @@
|
|
|
230
230
|
"react": ">=19.0.0",
|
|
231
231
|
"react-dom": ">=19.0.0",
|
|
232
232
|
"tailwindcss": "^4.0.0",
|
|
233
|
-
"@mastra/ai-sdk": "^1.12.0",
|
|
234
233
|
"@mastra/client-js": "^1.61.2-alpha.4",
|
|
235
|
-
"@mastra/react": "1.16.0-alpha.4"
|
|
234
|
+
"@mastra/react": "1.16.0-alpha.4",
|
|
235
|
+
"@mastra/ai-sdk": "^1.12.0"
|
|
236
236
|
},
|
|
237
237
|
"devDependencies": {
|
|
238
238
|
"@modelcontextprotocol/client": "2.4.0",
|
|
@@ -278,14 +278,14 @@
|
|
|
278
278
|
"vite": "^8.3.5",
|
|
279
279
|
"vite-plugin-lib-inject-css": "^2.2.2",
|
|
280
280
|
"vitest": "5.1.0",
|
|
281
|
+
"@internal/ai-sdk-v5": "0.0.98",
|
|
281
282
|
"@internal/lint": "0.0.151",
|
|
282
283
|
"@mastra/ai-sdk": "1.12.0",
|
|
283
284
|
"@mastra/client-js": "^1.61.2-alpha.4",
|
|
284
285
|
"@mastra/core": "1.86.0-alpha.4",
|
|
285
286
|
"@mastra/memory": "1.41.3-alpha.0",
|
|
286
287
|
"@mastra/react": "1.16.0-alpha.4",
|
|
287
|
-
"@mastra/schema-compat": "1.4.0"
|
|
288
|
-
"@internal/ai-sdk-v5": "0.0.98"
|
|
288
|
+
"@mastra/schema-compat": "1.4.0"
|
|
289
289
|
},
|
|
290
290
|
"homepage": "https://mastra.ai",
|
|
291
291
|
"repository": {
|