@assistant-ui/react 0.14.8 → 0.14.9
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/client/ExternalThread.d.ts.map +1 -1
- package/dist/client/ExternalThread.js +2 -1
- package/dist/client/ExternalThread.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js +5 -2
- package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
- package/package.json +3 -3
- package/src/client/ExternalThread.ts +1 -0
- package/src/index.ts +1 -0
- package/src/primitives/message/MessagePartsGrouped.tsx +10 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExternalThread.d.ts","names":[],"sources":["../../src/client/ExternalThread.ts"],"mappings":";;;;;KAgCY,qBAAA,GAAwB,aAAa;EAC/C,EAAE;AAAA;AAAA,KAGQ,0BAAA;iCAEV,KAAA,WAAgB,cAAA,IALd;EAOF,OAAA,GAAU,OAAA,EAAS,aAAa,EAAE,IAAA;IAAQ,KAAA;EAAA,YAAV;EAEhC,KAAA,GAAQ,WAAA,mBAJQ;EAMhB,MAAA,GAAS,WAAA,mBAJU;EAMnB,KAAA,GAAQ,MAAA;AAAA;AAAA,KAGE,mBAAA;EACV,QAAA,WAAmB,qBAAA;EACnB,SAAA;EAPA;;;;;AAEgD;EAYhD,cAAA;EAT6B;;;;EAc7B,KAAA,IAAS,OAAA,EAAS,aAAA;EAClB,MAAA,IAAU,OAAA,EAAS,aAAA;EACnB,QAAA,IAAY,QAAA;EACZ,UAAA;EACA,QAAA,eAjBmB;EAmBnB,KAAA,GAAQ,0BAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"ExternalThread.d.ts","names":[],"sources":["../../src/client/ExternalThread.ts"],"mappings":";;;;;KAgCY,qBAAA,GAAwB,aAAa;EAC/C,EAAE;AAAA;AAAA,KAGQ,0BAAA;iCAEV,KAAA,WAAgB,cAAA,IALd;EAOF,OAAA,GAAU,OAAA,EAAS,aAAa,EAAE,IAAA;IAAQ,KAAA;EAAA,YAAV;EAEhC,KAAA,GAAQ,WAAA,mBAJQ;EAMhB,MAAA,GAAS,WAAA,mBAJU;EAMnB,KAAA,GAAQ,MAAA;AAAA;AAAA,KAGE,mBAAA;EACV,QAAA,WAAmB,qBAAA;EACnB,SAAA;EAPA;;;;;AAEgD;EAYhD,cAAA;EAT6B;;;;EAc7B,KAAA,IAAS,OAAA,EAAS,aAAA;EAClB,MAAA,IAAU,OAAA,EAAS,aAAA;EACnB,QAAA,IAAY,QAAA;EACZ,UAAA;EACA,QAAA,eAjBmB;EAmBnB,KAAA,GAAQ,0BAAA;AAAA;AAAA,cAiZG,cAAA,GAAc,KAAA,EAAA,mBAAA,iCAAA,eAAA,CAAA,YAAA,YAAA,mBAAA"}
|
|
@@ -94,7 +94,8 @@ const PartResource = resource(({ part }) => {
|
|
|
94
94
|
return {
|
|
95
95
|
getState: () => state,
|
|
96
96
|
addToolResult: () => {},
|
|
97
|
-
resumeToolCall: () => {}
|
|
97
|
+
resumeToolCall: () => {},
|
|
98
|
+
respondToToolApproval: () => {}
|
|
98
99
|
};
|
|
99
100
|
});
|
|
100
101
|
const AttachmentResource = resource(({ attachment, onRemove }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExternalThread.js","names":[],"sources":["../../src/client/ExternalThread.ts"],"sourcesContent":["import {\n resource,\n tapState,\n tapMemo,\n tapEffect,\n tapEffectEvent,\n} from \"@assistant-ui/tap\";\nimport {\n type ClientElement,\n type ClientOutput,\n tapClientLookup,\n attachTransformScopes,\n tapClientResource,\n Derived,\n} from \"@assistant-ui/store\";\nimport { withKey } from \"@assistant-ui/tap\";\nimport type {\n AppendMessage,\n Attachment,\n CreateAttachment,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ThreadMessage,\n} from \"@assistant-ui/core\";\nimport type { QueueItemState } from \"@assistant-ui/core/store\";\nimport type { ComposerSendOptions } from \"@assistant-ui/core/store\";\nimport { ModelContext, Suggestions } from \"@assistant-ui/core/store\";\nimport { Tools, DataRenderers } from \"@assistant-ui/core/react\";\nimport { SingleThreadList } from \"./SingleThreadList\";\n\nconst EMPTY_QUEUE_ITEMS: readonly QueueItemState[] = [];\n\nexport type ExternalThreadMessage = ThreadMessage & {\n id: string;\n};\n\nexport type ExternalThreadQueueAdapter = {\n /** The current queue items. */\n items: readonly QueueItemState[];\n /** Called when a message is submitted via the composer. Receives the steer preference. */\n enqueue: (message: AppendMessage, opts: { steer: boolean }) => void;\n /** Called to promote an existing queue item (cancel current run, run this immediately). */\n steer: (queueItemId: string) => void;\n /** Called to remove an item from the queue. */\n remove: (queueItemId: string) => void;\n /** Called to clear all pending queue items, with the reason for clearing. */\n clear: (reason: \"edit\" | \"reload\" | \"cancel-run\") => void;\n};\n\nexport type ExternalThreadProps = {\n messages: readonly ExternalThreadMessage[];\n isRunning?: boolean;\n /**\n * Whether sending new messages is currently disabled. When `true`, the\n * thread composer's input remains usable but `send()` is a no-op and\n * `composer.canSend` is `false`. Edit composers (saving message edits)\n * intentionally ignore this flag.\n */\n isSendDisabled?: boolean;\n /**\n * Callback for new messages (non-queue runtimes).\n * @note Unused when `queue` is provided — new messages are routed through `queue.enqueue` instead.\n */\n onNew?: (message: AppendMessage) => void;\n onEdit?: (message: AppendMessage) => void;\n onReload?: (parentId: string | null) => void;\n onStartRun?: () => void;\n onCancel?: () => void;\n /** Queue adapter for runtimes that support message queuing and steering. */\n queue?: ExternalThreadQueueAdapter;\n};\n\ntype MessageClientProps = {\n message: ExternalThreadMessage;\n index: number;\n onEdit?: (message: AppendMessage) => void;\n onReload?: () => void;\n queue?: ExternalThreadQueueAdapter | undefined;\n};\n\n// Message Client - minimal implementation\nconst MessageClient = resource(\n ({\n message,\n index,\n onEdit,\n onReload,\n queue,\n }: MessageClientProps): ClientOutput<\"message\"> => {\n const [isCopied, setIsCopied] = tapState(false);\n const [isHovering, setIsHovering] = tapState(false);\n const [isEditing, setIsEditing] = tapState(false);\n\n const partClients = tapClientLookup(\n () =>\n message.content.map((part, idx) =>\n withKey(idx, PartResource({ part })),\n ),\n [message.content],\n );\n\n const attachmentClients = tapClientLookup(\n () =>\n (message.attachments ?? []).map((attachment) =>\n withKey(\n attachment.id,\n AttachmentResource({\n attachment,\n onRemove: () => {},\n }),\n ),\n ),\n [message.attachments],\n );\n\n const handleBeginEdit = () => {\n setIsEditing(true);\n };\n\n const handleCancelEdit = () => {\n setIsEditing(false);\n };\n\n const handleSendEdit = (msg: AppendMessage) => {\n queue?.clear(\"edit\");\n onEdit?.({\n ...msg,\n parentId: message.id,\n sourceId: message.id,\n });\n setIsEditing(false);\n };\n\n const composerClient = tapClientResource(\n ComposerClientResource({\n type: \"edit\",\n isEditing,\n canCancel: true,\n onCancel: handleCancelEdit,\n onBeginEdit: handleBeginEdit,\n onSend: handleSendEdit,\n message,\n queue,\n }),\n );\n\n const state = tapMemo(() => {\n return {\n ...message,\n attachments: message.attachments ?? [],\n parentId: null,\n isLast: false, // Will be set by thread\n branchNumber: 1,\n branchCount: 1,\n speech: undefined,\n parts: partClients.state,\n isCopied,\n isHovering,\n index,\n composer: composerClient.state,\n };\n }, [\n message,\n isCopied,\n isHovering,\n index,\n composerClient.state,\n partClients.state,\n ]);\n\n return {\n getState: () => state,\n composer: () => composerClient.methods,\n reload: () => {\n onReload?.();\n },\n speak: () => {},\n stopSpeaking: () => {},\n submitFeedback: () => {},\n switchToBranch: () => {},\n getCopyText: () =>\n message.content.map((c) => (\"text\" in c ? c.text : \"\")).join(\"\"),\n part: (selector) => {\n if (\"index\" in selector) {\n return partClients.get(selector);\n }\n const partIndex = state.parts.findIndex(\n (p) => p.type === \"tool-call\" && p.toolCallId === selector.toolCallId,\n );\n return partClients.get({ index: partIndex });\n },\n attachment: (selector) => {\n if (\"id\" in selector) {\n return attachmentClients.get({ key: selector.id });\n }\n return attachmentClients.get(selector);\n },\n setIsCopied,\n setIsHovering,\n };\n },\n);\n\ntype PartResourceProps = {\n part: ThreadAssistantMessagePart | ThreadUserMessagePart;\n};\n\n// Part Client - minimal implementation\nconst PartResource = resource(\n ({ part }: PartResourceProps): ClientOutput<\"part\"> => {\n const state = tapMemo(\n () => ({\n ...part,\n status: { type: \"complete\" as const },\n }),\n [part],\n );\n\n return {\n getState: () => state,\n addToolResult: () => {},\n resumeToolCall: () => {},\n };\n },\n);\n\ntype AttachmentResourceProps = {\n attachment: Attachment;\n onRemove?: () => void;\n};\n\n// Attachment Client - minimal implementation\nconst AttachmentResource = resource(\n ({\n attachment,\n onRemove,\n }: AttachmentResourceProps): ClientOutput<\"attachment\"> => {\n return {\n getState: () => attachment,\n remove: async () => {\n onRemove?.();\n },\n };\n },\n);\n\ntype ComposerClientResourceProps = {\n type: \"thread\" | \"edit\";\n isEditing: boolean;\n canCancel: boolean;\n isSendDisabled?: boolean;\n onCancel: () => void;\n onBeginEdit?: () => void;\n onSend?: (message: AppendMessage) => void;\n message?: ExternalThreadMessage;\n queue?: ExternalThreadQueueAdapter | undefined;\n};\n\nconst QueueItemClient = resource(\n ({\n item,\n onSteer,\n onRemove,\n }: {\n item: QueueItemState;\n onSteer: () => void;\n onRemove: () => void;\n }): ClientOutput<\"queueItem\"> => {\n return {\n getState: () => item,\n steer: onSteer,\n remove: onRemove,\n };\n },\n);\n\n// Composer Client - minimal implementation\nconst ComposerClientResource = resource(\n ({\n type,\n isEditing,\n canCancel,\n isSendDisabled = false,\n onCancel,\n onBeginEdit,\n onSend,\n message,\n queue,\n }: ComposerClientResourceProps): ClientOutput<\"composer\"> => {\n const [text, setText] = tapState(\"\");\n const [role, setRole] = tapState<\"user\" | \"assistant\" | \"system\">(\"user\");\n const [runConfig, setRunConfig] = tapState<Record<string, unknown>>({});\n const [attachments, setAttachments] = tapState<readonly Attachment[]>([]);\n const [quote, setQuote] = tapState<\n { readonly text: string; readonly messageId: string } | undefined\n >(undefined);\n\n // Update composer values when editing begins\n const updateFromMessage = tapEffectEvent(() => {\n if (message) {\n // Extract text from message content (text parts only)\n const textParts = message.content.filter(\n (part) => part.type === \"text\",\n );\n const messageText = textParts\n .map((part) => (\"text\" in part ? part.text : \"\"))\n .join(\"\\n\\n\");\n\n setText(messageText);\n setRole(message.role);\n setAttachments(message.attachments ?? []);\n }\n });\n\n tapEffect(() => {\n if (isEditing) {\n updateFromMessage();\n }\n }, [isEditing]);\n\n const attachmentClients = tapClientLookup(\n () =>\n attachments.map((attachment, idx) =>\n withKey(\n attachment.id,\n AttachmentResource({\n attachment,\n onRemove: () => {\n setAttachments(attachments.filter((_, i) => i !== idx));\n },\n }),\n ),\n ),\n [attachments],\n );\n\n const queueItems = queue?.items ?? EMPTY_QUEUE_ITEMS;\n const queueItemClients = tapClientLookup(\n () =>\n queueItems.map((item) =>\n withKey(\n item.id,\n QueueItemClient({\n item,\n onSteer: () => queue?.steer(item.id),\n onRemove: () => queue?.remove(item.id),\n }),\n ),\n ),\n [queueItems],\n );\n\n const state = tapMemo(() => {\n const isEmpty = !text.trim() && !attachments.length;\n return {\n text,\n role,\n attachments: attachmentClients.state,\n runConfig,\n isEditing,\n canCancel,\n canSend: isEditing && !isEmpty && !isSendDisabled,\n attachmentAccept: \"*\",\n isEmpty,\n type,\n dictation: undefined,\n quote,\n queue: queueItems,\n };\n }, [\n text,\n role,\n attachmentClients.state,\n runConfig,\n isEditing,\n canCancel,\n isSendDisabled,\n type,\n attachments.length,\n quote,\n queueItems,\n ]);\n\n return {\n getState: () => state,\n setText,\n setRole,\n setRunConfig,\n addAttachment: async (fileOrAttachment: File | CreateAttachment) => {\n if (fileOrAttachment instanceof File) {\n const newAttachment: Attachment = {\n id: Math.random().toString(36).substring(7),\n type: \"file\",\n name: fileOrAttachment.name,\n contentType: fileOrAttachment.type,\n file: fileOrAttachment,\n status: { type: \"complete\" },\n content: [],\n };\n setAttachments([...attachments, newAttachment]);\n } else {\n const newAttachment: Attachment = {\n id: fileOrAttachment.id ?? Math.random().toString(36).substring(7),\n type: fileOrAttachment.type ?? \"document\",\n name: fileOrAttachment.name,\n contentType: fileOrAttachment.contentType,\n content: fileOrAttachment.content,\n status: { type: \"complete\" },\n };\n setAttachments([...attachments, newAttachment]);\n }\n },\n clearAttachments: async () => {\n setAttachments([]);\n },\n attachment: (selector) => {\n if (\"id\" in selector) {\n return attachmentClients.get({ key: selector.id });\n }\n return attachmentClients.get(selector);\n },\n reset: async () => {\n setText(\"\");\n setRole(\"user\");\n setRunConfig({});\n setAttachments([]);\n setQuote(undefined);\n },\n send: (opts?: ComposerSendOptions) => {\n if (!state.canSend) return;\n\n const currentQuote = quote;\n const composedMessage: AppendMessage = {\n role,\n content: text ? [{ type: \"text\" as const, text }] : [],\n attachments: attachments as any,\n createdAt: new Date(),\n parentId: null,\n sourceId: null,\n runConfig,\n startRun: opts?.startRun,\n metadata: {\n custom: { ...(currentQuote ? { quote: currentQuote } : {}) },\n },\n };\n if (queue) {\n queue.enqueue(composedMessage, { steer: opts?.steer ?? false });\n } else {\n onSend?.(composedMessage);\n }\n setText(\"\");\n setAttachments([]);\n setQuote(undefined);\n },\n cancel: onCancel,\n beginEdit: () => {\n onBeginEdit?.();\n },\n startDictation: () => {},\n stopDictation: () => {},\n setQuote,\n queueItem: (selector: { index: number }) => {\n return queueItemClients.get(selector);\n },\n };\n },\n);\n\n// External Thread Client\nexport const ExternalThread = resource(\n ({\n messages,\n isRunning = false,\n isSendDisabled = false,\n onNew,\n onEdit,\n onReload,\n onStartRun,\n onCancel,\n queue,\n }: ExternalThreadProps): ClientOutput<\"thread\"> => {\n const handleReload = (messageId: string) => {\n const messageIndex = messages.findIndex((m) => m.id === messageId);\n if (messageIndex === -1) return;\n\n const parentId = messageIndex > 0 ? messages[messageIndex - 1]!.id : null;\n queue?.clear(\"reload\");\n onReload?.(parentId);\n };\n\n const messageClients = tapClientLookup(\n () =>\n messages.map((msg, index) => {\n const props: MessageClientProps = {\n message: msg,\n index,\n onReload: () => handleReload(msg.id),\n queue,\n };\n if (onEdit) props.onEdit = onEdit;\n return withKey(msg.id, MessageClient(props));\n }),\n [messages, onEdit, queue],\n );\n\n const handleCancelRun = () => {\n queue?.clear(\"cancel-run\");\n onCancel?.();\n };\n\n const handleSendNew = (message: AppendMessage) => {\n onNew?.(message);\n };\n\n const composerClient = tapClientResource(\n ComposerClientResource({\n type: \"thread\",\n isEditing: true,\n canCancel: isRunning,\n isSendDisabled,\n onCancel: handleCancelRun,\n onSend: handleSendNew,\n queue,\n }),\n );\n\n const hasQueue = !!queue;\n const state = tapMemo(() => {\n const messageStates = messageClients.state.map((s, idx, arr) => ({\n ...s,\n isLast: idx === arr.length - 1,\n }));\n\n return {\n isEmpty: messages.length === 0,\n isDisabled: false,\n isLoading: false,\n isRunning,\n capabilities: {\n edit: false,\n reload: false,\n cancel: isRunning,\n speech: false,\n attachments: false,\n feedback: false,\n voice: false,\n switchToBranch: false,\n switchBranchDuringRun: false,\n unstable_copy: false,\n dictation: false,\n queue: hasQueue,\n },\n messages: messageStates,\n state: {},\n suggestions: [],\n extras: undefined,\n speech: undefined,\n voice: undefined,\n composer: composerClient.state,\n };\n }, [\n messages,\n isRunning,\n hasQueue,\n messageClients.state,\n composerClient.state,\n ]);\n\n return {\n getState: () => state,\n composer: () => composerClient.methods,\n append: (message) => {\n const appendMessage: AppendMessage =\n typeof message === \"string\"\n ? {\n createdAt: new Date(),\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n metadata: { custom: {} },\n }\n : {\n createdAt: message.createdAt ?? new Date(),\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n metadata: message.metadata ?? { custom: {} },\n runConfig: message.runConfig ?? {},\n startRun: message.startRun,\n };\n if (queue) {\n queue.enqueue(appendMessage, { steer: false });\n } else {\n onNew?.(appendMessage);\n }\n },\n startRun: () => {\n onStartRun?.();\n },\n resumeRun: () => {},\n cancelRun: handleCancelRun,\n getModelContext: () => ({ tools: {}, config: {} }),\n export: () => ({ messages: [] }),\n import: () => {},\n reset: () => {},\n message: (selector) => {\n if (\"id\" in selector) {\n return messageClients.get({ key: selector.id });\n }\n return messageClients.get(selector);\n },\n stopSpeaking: () => {},\n connectVoice: () => {},\n disconnectVoice: () => {},\n getVoiceVolume: () => 0,\n subscribeVoiceVolume: () => () => {},\n muteVoice: () => {},\n unmuteVoice: () => {},\n };\n },\n);\n\nattachTransformScopes(ExternalThread, (scopes, parent) => {\n if (!scopes.threads && parent.threads.source === null) {\n const threadElement = scopes.thread as ClientElement<\"thread\">;\n scopes.threads = SingleThreadList({ thread: threadElement });\n scopes.thread = Derived({\n source: \"threads\",\n query: { type: \"main\" },\n get: (aui) => aui.threads().thread(\"main\"),\n });\n }\n\n if (!scopes.threadListItem && parent.threadListItem.source === null) {\n scopes.threadListItem = Derived({\n source: \"threads\",\n query: { type: \"main\" },\n get: (aui) => aui.threads().item(\"main\"),\n });\n }\n\n scopes.composer ??= Derived({\n source: \"thread\",\n query: {},\n get: (aui) => aui.thread().composer(),\n });\n\n if (!scopes.modelContext && parent.modelContext.source === null) {\n scopes.modelContext = ModelContext();\n }\n if (!scopes.tools && parent.tools.source === null) {\n scopes.tools = Tools({});\n }\n if (!scopes.dataRenderers && parent.dataRenderers.source === null) {\n scopes.dataRenderers = DataRenderers();\n }\n if (!scopes.suggestions && parent.suggestions.source === null) {\n scopes.suggestions = Suggestions();\n }\n});\n"],"mappings":";;;;;;AA8BA,MAAM,oBAA+C,CAAC;AAmDtD,MAAM,gBAAgB,UACnB,EACC,SACA,OACA,QACA,UACA,YACiD;CACjD,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,YAAY,iBAAiB,SAAS,KAAK;CAClD,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAEhD,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AAC;EACrB,oBAAoB,CAAC;EACrB,uBAAuB,CAAC;EACxB,sBAAsB;EACtB,kCAAkC,CAAC;EACnC,iBAAiB,CAAC;EAClB,mBAAmB,CAAC;CACtB;AACF,CACF;AAEA,sBAAsB,iBAAiB,QAAQ,WAAW;CACxD,IAAI,CAAC,OAAO,WAAW,OAAO,QAAQ,WAAW,MAAM;EACrD,MAAM,gBAAgB,OAAO;EAC7B,OAAO,UAAU,iBAAiB,EAAE,QAAQ,cAAc,CAAC;EAC3D,OAAO,SAAS,QAAQ;GACtB,QAAQ;GACR,OAAO,EAAE,MAAM,OAAO;GACtB,MAAM,QAAQ,IAAI,QAAQ,EAAE,OAAO,MAAM;EAC3C,CAAC;CACH;CAEA,IAAI,CAAC,OAAO,kBAAkB,OAAO,eAAe,WAAW,MAC7D,OAAO,iBAAiB,QAAQ;EAC9B,QAAQ;EACR,OAAO,EAAE,MAAM,OAAO;EACtB,MAAM,QAAQ,IAAI,QAAQ,EAAE,KAAK,MAAM;CACzC,CAAC;CAGH,OAAO,aAAa,QAAQ;EAC1B,QAAQ;EACR,OAAO,CAAC;EACR,MAAM,QAAQ,IAAI,OAAO,EAAE,SAAS;CACtC,CAAC;CAED,IAAI,CAAC,OAAO,gBAAgB,OAAO,aAAa,WAAW,MACzD,OAAO,eAAe,aAAa;CAErC,IAAI,CAAC,OAAO,SAAS,OAAO,MAAM,WAAW,MAC3C,OAAO,QAAQ,MAAM,CAAC,CAAC;CAEzB,IAAI,CAAC,OAAO,iBAAiB,OAAO,cAAc,WAAW,MAC3D,OAAO,gBAAgB,cAAc;CAEvC,IAAI,CAAC,OAAO,eAAe,OAAO,YAAY,WAAW,MACvD,OAAO,cAAc,YAAY;AAErC,CAAC"}
|
|
1
|
+
{"version":3,"file":"ExternalThread.js","names":[],"sources":["../../src/client/ExternalThread.ts"],"sourcesContent":["import {\n resource,\n tapState,\n tapMemo,\n tapEffect,\n tapEffectEvent,\n} from \"@assistant-ui/tap\";\nimport {\n type ClientElement,\n type ClientOutput,\n tapClientLookup,\n attachTransformScopes,\n tapClientResource,\n Derived,\n} from \"@assistant-ui/store\";\nimport { withKey } from \"@assistant-ui/tap\";\nimport type {\n AppendMessage,\n Attachment,\n CreateAttachment,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ThreadMessage,\n} from \"@assistant-ui/core\";\nimport type { QueueItemState } from \"@assistant-ui/core/store\";\nimport type { ComposerSendOptions } from \"@assistant-ui/core/store\";\nimport { ModelContext, Suggestions } from \"@assistant-ui/core/store\";\nimport { Tools, DataRenderers } from \"@assistant-ui/core/react\";\nimport { SingleThreadList } from \"./SingleThreadList\";\n\nconst EMPTY_QUEUE_ITEMS: readonly QueueItemState[] = [];\n\nexport type ExternalThreadMessage = ThreadMessage & {\n id: string;\n};\n\nexport type ExternalThreadQueueAdapter = {\n /** The current queue items. */\n items: readonly QueueItemState[];\n /** Called when a message is submitted via the composer. Receives the steer preference. */\n enqueue: (message: AppendMessage, opts: { steer: boolean }) => void;\n /** Called to promote an existing queue item (cancel current run, run this immediately). */\n steer: (queueItemId: string) => void;\n /** Called to remove an item from the queue. */\n remove: (queueItemId: string) => void;\n /** Called to clear all pending queue items, with the reason for clearing. */\n clear: (reason: \"edit\" | \"reload\" | \"cancel-run\") => void;\n};\n\nexport type ExternalThreadProps = {\n messages: readonly ExternalThreadMessage[];\n isRunning?: boolean;\n /**\n * Whether sending new messages is currently disabled. When `true`, the\n * thread composer's input remains usable but `send()` is a no-op and\n * `composer.canSend` is `false`. Edit composers (saving message edits)\n * intentionally ignore this flag.\n */\n isSendDisabled?: boolean;\n /**\n * Callback for new messages (non-queue runtimes).\n * @note Unused when `queue` is provided — new messages are routed through `queue.enqueue` instead.\n */\n onNew?: (message: AppendMessage) => void;\n onEdit?: (message: AppendMessage) => void;\n onReload?: (parentId: string | null) => void;\n onStartRun?: () => void;\n onCancel?: () => void;\n /** Queue adapter for runtimes that support message queuing and steering. */\n queue?: ExternalThreadQueueAdapter;\n};\n\ntype MessageClientProps = {\n message: ExternalThreadMessage;\n index: number;\n onEdit?: (message: AppendMessage) => void;\n onReload?: () => void;\n queue?: ExternalThreadQueueAdapter | undefined;\n};\n\n// Message Client - minimal implementation\nconst MessageClient = resource(\n ({\n message,\n index,\n onEdit,\n onReload,\n queue,\n }: MessageClientProps): ClientOutput<\"message\"> => {\n const [isCopied, setIsCopied] = tapState(false);\n const [isHovering, setIsHovering] = tapState(false);\n const [isEditing, setIsEditing] = tapState(false);\n\n const partClients = tapClientLookup(\n () =>\n message.content.map((part, idx) =>\n withKey(idx, PartResource({ part })),\n ),\n [message.content],\n );\n\n const attachmentClients = tapClientLookup(\n () =>\n (message.attachments ?? []).map((attachment) =>\n withKey(\n attachment.id,\n AttachmentResource({\n attachment,\n onRemove: () => {},\n }),\n ),\n ),\n [message.attachments],\n );\n\n const handleBeginEdit = () => {\n setIsEditing(true);\n };\n\n const handleCancelEdit = () => {\n setIsEditing(false);\n };\n\n const handleSendEdit = (msg: AppendMessage) => {\n queue?.clear(\"edit\");\n onEdit?.({\n ...msg,\n parentId: message.id,\n sourceId: message.id,\n });\n setIsEditing(false);\n };\n\n const composerClient = tapClientResource(\n ComposerClientResource({\n type: \"edit\",\n isEditing,\n canCancel: true,\n onCancel: handleCancelEdit,\n onBeginEdit: handleBeginEdit,\n onSend: handleSendEdit,\n message,\n queue,\n }),\n );\n\n const state = tapMemo(() => {\n return {\n ...message,\n attachments: message.attachments ?? [],\n parentId: null,\n isLast: false, // Will be set by thread\n branchNumber: 1,\n branchCount: 1,\n speech: undefined,\n parts: partClients.state,\n isCopied,\n isHovering,\n index,\n composer: composerClient.state,\n };\n }, [\n message,\n isCopied,\n isHovering,\n index,\n composerClient.state,\n partClients.state,\n ]);\n\n return {\n getState: () => state,\n composer: () => composerClient.methods,\n reload: () => {\n onReload?.();\n },\n speak: () => {},\n stopSpeaking: () => {},\n submitFeedback: () => {},\n switchToBranch: () => {},\n getCopyText: () =>\n message.content.map((c) => (\"text\" in c ? c.text : \"\")).join(\"\"),\n part: (selector) => {\n if (\"index\" in selector) {\n return partClients.get(selector);\n }\n const partIndex = state.parts.findIndex(\n (p) => p.type === \"tool-call\" && p.toolCallId === selector.toolCallId,\n );\n return partClients.get({ index: partIndex });\n },\n attachment: (selector) => {\n if (\"id\" in selector) {\n return attachmentClients.get({ key: selector.id });\n }\n return attachmentClients.get(selector);\n },\n setIsCopied,\n setIsHovering,\n };\n },\n);\n\ntype PartResourceProps = {\n part: ThreadAssistantMessagePart | ThreadUserMessagePart;\n};\n\n// Part Client - minimal implementation\nconst PartResource = resource(\n ({ part }: PartResourceProps): ClientOutput<\"part\"> => {\n const state = tapMemo(\n () => ({\n ...part,\n status: { type: \"complete\" as const },\n }),\n [part],\n );\n\n return {\n getState: () => state,\n addToolResult: () => {},\n resumeToolCall: () => {},\n respondToToolApproval: () => {},\n };\n },\n);\n\ntype AttachmentResourceProps = {\n attachment: Attachment;\n onRemove?: () => void;\n};\n\n// Attachment Client - minimal implementation\nconst AttachmentResource = resource(\n ({\n attachment,\n onRemove,\n }: AttachmentResourceProps): ClientOutput<\"attachment\"> => {\n return {\n getState: () => attachment,\n remove: async () => {\n onRemove?.();\n },\n };\n },\n);\n\ntype ComposerClientResourceProps = {\n type: \"thread\" | \"edit\";\n isEditing: boolean;\n canCancel: boolean;\n isSendDisabled?: boolean;\n onCancel: () => void;\n onBeginEdit?: () => void;\n onSend?: (message: AppendMessage) => void;\n message?: ExternalThreadMessage;\n queue?: ExternalThreadQueueAdapter | undefined;\n};\n\nconst QueueItemClient = resource(\n ({\n item,\n onSteer,\n onRemove,\n }: {\n item: QueueItemState;\n onSteer: () => void;\n onRemove: () => void;\n }): ClientOutput<\"queueItem\"> => {\n return {\n getState: () => item,\n steer: onSteer,\n remove: onRemove,\n };\n },\n);\n\n// Composer Client - minimal implementation\nconst ComposerClientResource = resource(\n ({\n type,\n isEditing,\n canCancel,\n isSendDisabled = false,\n onCancel,\n onBeginEdit,\n onSend,\n message,\n queue,\n }: ComposerClientResourceProps): ClientOutput<\"composer\"> => {\n const [text, setText] = tapState(\"\");\n const [role, setRole] = tapState<\"user\" | \"assistant\" | \"system\">(\"user\");\n const [runConfig, setRunConfig] = tapState<Record<string, unknown>>({});\n const [attachments, setAttachments] = tapState<readonly Attachment[]>([]);\n const [quote, setQuote] = tapState<\n { readonly text: string; readonly messageId: string } | undefined\n >(undefined);\n\n // Update composer values when editing begins\n const updateFromMessage = tapEffectEvent(() => {\n if (message) {\n // Extract text from message content (text parts only)\n const textParts = message.content.filter(\n (part) => part.type === \"text\",\n );\n const messageText = textParts\n .map((part) => (\"text\" in part ? part.text : \"\"))\n .join(\"\\n\\n\");\n\n setText(messageText);\n setRole(message.role);\n setAttachments(message.attachments ?? []);\n }\n });\n\n tapEffect(() => {\n if (isEditing) {\n updateFromMessage();\n }\n }, [isEditing]);\n\n const attachmentClients = tapClientLookup(\n () =>\n attachments.map((attachment, idx) =>\n withKey(\n attachment.id,\n AttachmentResource({\n attachment,\n onRemove: () => {\n setAttachments(attachments.filter((_, i) => i !== idx));\n },\n }),\n ),\n ),\n [attachments],\n );\n\n const queueItems = queue?.items ?? EMPTY_QUEUE_ITEMS;\n const queueItemClients = tapClientLookup(\n () =>\n queueItems.map((item) =>\n withKey(\n item.id,\n QueueItemClient({\n item,\n onSteer: () => queue?.steer(item.id),\n onRemove: () => queue?.remove(item.id),\n }),\n ),\n ),\n [queueItems],\n );\n\n const state = tapMemo(() => {\n const isEmpty = !text.trim() && !attachments.length;\n return {\n text,\n role,\n attachments: attachmentClients.state,\n runConfig,\n isEditing,\n canCancel,\n canSend: isEditing && !isEmpty && !isSendDisabled,\n attachmentAccept: \"*\",\n isEmpty,\n type,\n dictation: undefined,\n quote,\n queue: queueItems,\n };\n }, [\n text,\n role,\n attachmentClients.state,\n runConfig,\n isEditing,\n canCancel,\n isSendDisabled,\n type,\n attachments.length,\n quote,\n queueItems,\n ]);\n\n return {\n getState: () => state,\n setText,\n setRole,\n setRunConfig,\n addAttachment: async (fileOrAttachment: File | CreateAttachment) => {\n if (fileOrAttachment instanceof File) {\n const newAttachment: Attachment = {\n id: Math.random().toString(36).substring(7),\n type: \"file\",\n name: fileOrAttachment.name,\n contentType: fileOrAttachment.type,\n file: fileOrAttachment,\n status: { type: \"complete\" },\n content: [],\n };\n setAttachments([...attachments, newAttachment]);\n } else {\n const newAttachment: Attachment = {\n id: fileOrAttachment.id ?? Math.random().toString(36).substring(7),\n type: fileOrAttachment.type ?? \"document\",\n name: fileOrAttachment.name,\n contentType: fileOrAttachment.contentType,\n content: fileOrAttachment.content,\n status: { type: \"complete\" },\n };\n setAttachments([...attachments, newAttachment]);\n }\n },\n clearAttachments: async () => {\n setAttachments([]);\n },\n attachment: (selector) => {\n if (\"id\" in selector) {\n return attachmentClients.get({ key: selector.id });\n }\n return attachmentClients.get(selector);\n },\n reset: async () => {\n setText(\"\");\n setRole(\"user\");\n setRunConfig({});\n setAttachments([]);\n setQuote(undefined);\n },\n send: (opts?: ComposerSendOptions) => {\n if (!state.canSend) return;\n\n const currentQuote = quote;\n const composedMessage: AppendMessage = {\n role,\n content: text ? [{ type: \"text\" as const, text }] : [],\n attachments: attachments as any,\n createdAt: new Date(),\n parentId: null,\n sourceId: null,\n runConfig,\n startRun: opts?.startRun,\n metadata: {\n custom: { ...(currentQuote ? { quote: currentQuote } : {}) },\n },\n };\n if (queue) {\n queue.enqueue(composedMessage, { steer: opts?.steer ?? false });\n } else {\n onSend?.(composedMessage);\n }\n setText(\"\");\n setAttachments([]);\n setQuote(undefined);\n },\n cancel: onCancel,\n beginEdit: () => {\n onBeginEdit?.();\n },\n startDictation: () => {},\n stopDictation: () => {},\n setQuote,\n queueItem: (selector: { index: number }) => {\n return queueItemClients.get(selector);\n },\n };\n },\n);\n\n// External Thread Client\nexport const ExternalThread = resource(\n ({\n messages,\n isRunning = false,\n isSendDisabled = false,\n onNew,\n onEdit,\n onReload,\n onStartRun,\n onCancel,\n queue,\n }: ExternalThreadProps): ClientOutput<\"thread\"> => {\n const handleReload = (messageId: string) => {\n const messageIndex = messages.findIndex((m) => m.id === messageId);\n if (messageIndex === -1) return;\n\n const parentId = messageIndex > 0 ? messages[messageIndex - 1]!.id : null;\n queue?.clear(\"reload\");\n onReload?.(parentId);\n };\n\n const messageClients = tapClientLookup(\n () =>\n messages.map((msg, index) => {\n const props: MessageClientProps = {\n message: msg,\n index,\n onReload: () => handleReload(msg.id),\n queue,\n };\n if (onEdit) props.onEdit = onEdit;\n return withKey(msg.id, MessageClient(props));\n }),\n [messages, onEdit, queue],\n );\n\n const handleCancelRun = () => {\n queue?.clear(\"cancel-run\");\n onCancel?.();\n };\n\n const handleSendNew = (message: AppendMessage) => {\n onNew?.(message);\n };\n\n const composerClient = tapClientResource(\n ComposerClientResource({\n type: \"thread\",\n isEditing: true,\n canCancel: isRunning,\n isSendDisabled,\n onCancel: handleCancelRun,\n onSend: handleSendNew,\n queue,\n }),\n );\n\n const hasQueue = !!queue;\n const state = tapMemo(() => {\n const messageStates = messageClients.state.map((s, idx, arr) => ({\n ...s,\n isLast: idx === arr.length - 1,\n }));\n\n return {\n isEmpty: messages.length === 0,\n isDisabled: false,\n isLoading: false,\n isRunning,\n capabilities: {\n edit: false,\n reload: false,\n cancel: isRunning,\n speech: false,\n attachments: false,\n feedback: false,\n voice: false,\n switchToBranch: false,\n switchBranchDuringRun: false,\n unstable_copy: false,\n dictation: false,\n queue: hasQueue,\n },\n messages: messageStates,\n state: {},\n suggestions: [],\n extras: undefined,\n speech: undefined,\n voice: undefined,\n composer: composerClient.state,\n };\n }, [\n messages,\n isRunning,\n hasQueue,\n messageClients.state,\n composerClient.state,\n ]);\n\n return {\n getState: () => state,\n composer: () => composerClient.methods,\n append: (message) => {\n const appendMessage: AppendMessage =\n typeof message === \"string\"\n ? {\n createdAt: new Date(),\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n metadata: { custom: {} },\n }\n : {\n createdAt: message.createdAt ?? new Date(),\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n metadata: message.metadata ?? { custom: {} },\n runConfig: message.runConfig ?? {},\n startRun: message.startRun,\n };\n if (queue) {\n queue.enqueue(appendMessage, { steer: false });\n } else {\n onNew?.(appendMessage);\n }\n },\n startRun: () => {\n onStartRun?.();\n },\n resumeRun: () => {},\n cancelRun: handleCancelRun,\n getModelContext: () => ({ tools: {}, config: {} }),\n export: () => ({ messages: [] }),\n import: () => {},\n reset: () => {},\n message: (selector) => {\n if (\"id\" in selector) {\n return messageClients.get({ key: selector.id });\n }\n return messageClients.get(selector);\n },\n stopSpeaking: () => {},\n connectVoice: () => {},\n disconnectVoice: () => {},\n getVoiceVolume: () => 0,\n subscribeVoiceVolume: () => () => {},\n muteVoice: () => {},\n unmuteVoice: () => {},\n };\n },\n);\n\nattachTransformScopes(ExternalThread, (scopes, parent) => {\n if (!scopes.threads && parent.threads.source === null) {\n const threadElement = scopes.thread as ClientElement<\"thread\">;\n scopes.threads = SingleThreadList({ thread: threadElement });\n scopes.thread = Derived({\n source: \"threads\",\n query: { type: \"main\" },\n get: (aui) => aui.threads().thread(\"main\"),\n });\n }\n\n if (!scopes.threadListItem && parent.threadListItem.source === null) {\n scopes.threadListItem = Derived({\n source: \"threads\",\n query: { type: \"main\" },\n get: (aui) => aui.threads().item(\"main\"),\n });\n }\n\n scopes.composer ??= Derived({\n source: \"thread\",\n query: {},\n get: (aui) => aui.thread().composer(),\n });\n\n if (!scopes.modelContext && parent.modelContext.source === null) {\n scopes.modelContext = ModelContext();\n }\n if (!scopes.tools && parent.tools.source === null) {\n scopes.tools = Tools({});\n }\n if (!scopes.dataRenderers && parent.dataRenderers.source === null) {\n scopes.dataRenderers = DataRenderers();\n }\n if (!scopes.suggestions && parent.suggestions.source === null) {\n scopes.suggestions = Suggestions();\n }\n});\n"],"mappings":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c;CAEvC,IAAI,CAAC,OAAO,eAAe,OAAO,YAAY,WAAW,MACvD,OAAO,cAAc,YAAY;AAErC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -74,9 +74,9 @@ import { McpAppRenderer, McpAppRendererOptions } from "./mcp-apps/McpAppRenderer
|
|
|
74
74
|
import { McpAppsRemoteHost } from "./mcp-apps/McpAppsRemoteHost.js";
|
|
75
75
|
import { getMcpAppFromToolPart } from "./mcp-apps/utils.js";
|
|
76
76
|
import { AssistantClient, AssistantEventCallback, AssistantEventName, AssistantEventPayload, AssistantEventScope, AssistantEventSelector, AssistantState, AuiIf, AuiProvider, useAui, useAuiEvent, useAuiState } from "@assistant-ui/store";
|
|
77
|
-
import { AssistantContextConfig, AssistantDataUI, AssistantDataUIProps, AssistantInteractableProps, AssistantTool, AssistantToolProps, AssistantToolUI, AssistantToolUIProps, DataMessagePartComponent, DataMessagePartProps, DataRenderers, EmptyMessagePartComponent, EmptyMessagePartProps, EnrichedPartState, FileMessagePartComponent, FileMessagePartProps, GenerativeUIComponentRegistry, GenerativeUIMessagePartComponent, GenerativeUIMessagePartProps, GenerativeUIRender, GenerativeUIRenderError, GenerativeUIRenderProps, ImageMessagePartComponent, ImageMessagePartProps, Interactables, McpAppResourceOutput, PartState, QuoteMessagePartComponent, QuoteMessagePartProps, ReasoningGroupComponent, ReasoningGroupProps, ReasoningMessagePartComponent, ReasoningMessagePartProps, RuntimeAdapterProvider, RuntimeAdapters, SourceMessagePartComponent, SourceMessagePartProps, TextMessagePartComponent, TextMessagePartProps, ToolArgsStatus, ToolCallMessagePartComponent, ToolCallMessagePartProps, ToolDefinition, Toolkit, Tools, Unstable_AudioMessagePartComponent, Unstable_AudioMessagePartProps, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useInlineRender, useInteractableState, useRuntimeAdapters, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume } from "@assistant-ui/core/react";
|
|
77
|
+
import { AssistantContextConfig, AssistantDataUI, AssistantDataUIProps, AssistantInteractableProps, AssistantTool, AssistantToolProps, AssistantToolUI, AssistantToolUIProps, DataMessagePartComponent, DataMessagePartProps, DataRenderers, EmptyMessagePartComponent, EmptyMessagePartProps, EnrichedPartState, FileMessagePartComponent, FileMessagePartProps, GenerativeUIComponentRegistry, GenerativeUIMessagePartComponent, GenerativeUIMessagePartProps, GenerativeUIRender, GenerativeUIRenderError, GenerativeUIRenderProps, ImageMessagePartComponent, ImageMessagePartProps, Interactables, McpAppResourceOutput, PartState, QuoteMessagePartComponent, QuoteMessagePartProps, ReasoningGroupComponent, ReasoningGroupProps, ReasoningMessagePartComponent, ReasoningMessagePartProps, RuntimeAdapterProvider, RuntimeAdapters, SourceMessagePartComponent, SourceMessagePartProps, TextMessagePartComponent, TextMessagePartProps, ToolArgsStatus, ToolCallMessagePartComponent, ToolCallMessagePartProps, ToolDefinition, Toolkit, Tools, Unstable_AudioMessagePartComponent, Unstable_AudioMessagePartProps, groupPartByType, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useInlineRender, useInteractableState, useRuntimeAdapters, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume } from "@assistant-ui/core/react";
|
|
78
78
|
import { AssistantCloud } from "assistant-cloud";
|
|
79
79
|
import { AddToolResultOptions, AppendMessage, AssistantFrameHost, AssistantFrameProvider, AssistantRuntime, Attachment, AttachmentAdapter, AttachmentRuntime, AttachmentState, AttachmentStatus, ChatModelAdapter, ChatModelRunOptions, ChatModelRunResult, ChatModelRunUpdate, CompleteAttachment, ComposerRuntime, ComposerState, CompositeAttachmentAdapter, CreateAppendMessage, CreateAttachment, CreateResumeRunConfig, CreateStartRunConfig, DataMessagePart, DictationAdapter, DictationState, EditComposerRuntime, EditComposerState, ExportedMessageRepository, ExportedMessageRepositoryItem, ExternalStoreAdapter, ExternalStoreMessageConverter, ExternalStoreThreadData, ExternalStoreThreadListAdapter, FRAME_MESSAGE_CHANNEL, FeedbackAdapter, FileMessagePart, FrameMessage, FrameMessageType, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, GenericThreadHistoryAdapter, ImageMessagePart, InMemoryThreadListAdapter, LanguageModelConfig, LanguageModelV1CallSettings, LocalRuntimeOptionsBase, MessageFormatAdapter, MessageFormatItem, MessageFormatRepository, MessagePartRuntime, MessagePartState, MessagePartStatus, MessageRuntime, MessageState, MessageStatus, MessageStorageEntry, MessageTiming, ModelContext, ModelContextProvider, ModelContextRegistry, ModelContextRegistryInstructionHandle, ModelContextRegistryProviderHandle, ModelContextRegistryToolHandle, PendingAttachment, QuoteInfo, RealtimeVoiceAdapter, ReasoningMessagePart, RemoteThreadListAdapter, SerializedModelContext, SerializedTool, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SourceMessagePart, SourceProviderMetadata, SpeechSynthesisAdapter, SubmitFeedbackOptions, SuggestionAdapter, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadComposerRuntime, ThreadComposerState, ThreadHistoryAdapter, ThreadListItemRuntime, ThreadListItemState, ThreadListItemStatus, ThreadListRuntime, ThreadListState, ThreadMessage, ThreadMessageLike, ThreadRuntime, ThreadState, ThreadSuggestion, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolCallMessagePart, ToolCallMessagePartStatus, ToolModelContentPart, Unstable_AudioMessagePart, Unstable_DirectiveFormatter, Unstable_DirectiveSegment, Unstable_TriggerItem, Unsubscribe, VoiceSessionControls, VoiceSessionHelpers, VoiceSessionState, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createVoiceSession, getExternalStoreMessages, mergeModelContexts, tool, unstable_defaultDirectiveFormatter } from "@assistant-ui/core";
|
|
80
80
|
import { Tool } from "assistant-stream";
|
|
81
81
|
import { ChainOfThoughtClient, ComposerSendOptions, ModelContext as ModelContextClient, QueueItemMethods, QueueItemState, SuggestionConfig, Suggestions } from "@assistant-ui/core/store";
|
|
82
|
-
export { actionBarMore_d_exports as ActionBarMorePrimitive, actionBar_d_exports as ActionBarPrimitive, type AddToolResultOptions, type AppendMessage, type Assistant, type AssistantClient, AssistantCloud, type AssistantContextConfig, type AssistantDataUI, type AssistantDataUIProps, type AssistantEventCallback, type AssistantEventName, type AssistantEventPayload, type AssistantEventScope, type AssistantEventSelector, AssistantFrameHost, AssistantFrameProvider, type AssistantInteractableProps, assistantModal_d_exports as AssistantModalPrimitive, type AssistantRuntime, AssistantRuntimeProvider, type AssistantState, type AssistantTool, type AssistantToolProps, type AssistantToolUI, type AssistantToolUIProps, type AssistantTransportCommand, type AssistantTransportConnectionMetadata, type AssistantTransportProtocol, type Attachment, type AttachmentAdapter, attachment_d_exports as AttachmentPrimitive, type AttachmentRuntime, type AttachmentState, type AttachmentStatus, AuiIf, AuiProvider, branchPicker_d_exports as BranchPickerPrimitive, ChainOfThoughtByIndicesProvider, ChainOfThoughtClient, chainOfThought_d_exports as ChainOfThoughtPrimitive, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, CloudFileAttachmentAdapter, type CompleteAttachment, ComposerAttachmentByIndexProvider, composer_d_exports as ComposerPrimitive, type ComposerRuntime, type ComposerSendOptions, type ComposerState, CompositeAttachmentAdapter, type CreateAppendMessage, type CreateAttachment, type CreateResumeRunConfig, type CreateStartRunConfig, type DataMessagePart, type DataMessagePartComponent, type DataMessagePartProps, DataRenderers, DevToolsHooks, DevToolsProviderApi, type DictationAdapter, type DictationState, type EditComposerRuntime, type EditComposerState, type EmptyMessagePartComponent, type EmptyMessagePartProps, type EnrichedPartState, error_d_exports as ErrorPrimitive, ExportedMessageRepository, type ExportedMessageRepositoryItem, type ExternalStoreAdapter, type ExternalStoreMessageConverter, type ExternalStoreThreadData, type ExternalStoreThreadListAdapter, ExternalThread, type ExternalThreadMessage, type ExternalThreadProps, type ExternalThreadQueueAdapter, FRAME_MESSAGE_CHANNEL, type FeedbackAdapter, type FileMessagePart, type FileMessagePartComponent, type FileMessagePartProps, type FrameMessage, type FrameMessageType, type GenerativeUIComponentRegistry, type GenerativeUIMessagePart, type GenerativeUIMessagePartComponent, type GenerativeUIMessagePartProps, type GenerativeUINode, GenerativeUIRender, GenerativeUIRenderError, type GenerativeUIRenderProps, type GenerativeUISpec, type GenericThreadHistoryAdapter, internal_d_exports as INTERNAL, type ImageMessagePart, type ImageMessagePartComponent, type ImageMessagePartProps, InMemoryThreadList, InMemoryThreadListAdapter, type InMemoryThreadListProps, Interactables, type LanguageModelConfig, type LanguageModelV1CallSettings, type LocalRuntimeOptions, type LocalRuntimeOptionsBase, type McpAppDisplayMode, type McpAppHostContext, type McpAppHostInfo, type McpAppMetadata, McpAppRenderer, type McpAppRendererOptions, type McpAppResource, type McpAppResourceCSP, type McpAppResourceMeta, type McpAppResourceOutput, type McpAppSandboxConfig, type McpAppToolCallParams, type McpAppsHost, McpAppsRemoteHost, type McpAppsRemoteHostOptions, MessageAttachmentByIndexProvider, MessageByIndexProvider, type MessageFormatAdapter, type MessageFormatItem, type MessageFormatRepository, messagePart_d_exports as MessagePartPrimitive, type MessagePartRuntime, type MessagePartState, type MessagePartStatus, message_d_exports as MessagePrimitive, MessageProvider, type MessageRuntime, type MessageState, type MessageStatus, type MessageStorageEntry, type MessageTiming, type ModelContext, ModelContextClient, type ModelContextProvider, ModelContextRegistry, type ModelContextRegistryInstructionHandle, type ModelContextRegistryProviderHandle, type ModelContextRegistryToolHandle, PartByIndexProvider, type PartState, type PendingAttachment, type QueueItemMethods, queueItem_d_exports as QueueItemPrimitive, type QueueItemState, type QuoteInfo, type QuoteMessagePartComponent, type QuoteMessagePartProps, ReadonlyThreadProvider, type RealtimeVoiceAdapter, type ReasoningGroupComponent, type ReasoningGroupProps, type ReasoningMessagePart, type ReasoningMessagePartComponent, type ReasoningMessagePartProps, type RemoteThreadListAdapter, RuntimeAdapterProvider, type RuntimeAdapters, selectionToolbar_d_exports as SelectionToolbarPrimitive, type SendCommandsRequestBody, type SerializedModelContext, type SerializedTool, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SingleThreadList, type SourceMessagePart, type SourceMessagePartComponent, type SourceMessagePartProps, type SourceProviderMetadata, type SpeechSynthesisAdapter, type SubmitFeedbackOptions, type SuggestionAdapter, SuggestionByIndexProvider, type SuggestionConfig, suggestion_d_exports as SuggestionPrimitive, Suggestions, type TextMessagePart, type TextMessagePartComponent, type TextMessagePartProps, TextMessagePartProvider, type ThreadAssistantMessage, type ThreadAssistantMessagePart, type ThreadComposerRuntime, type ThreadComposerState, type ThreadHistoryAdapter, ThreadListItemByIndexProvider, threadListItemMore_d_exports as ThreadListItemMorePrimitive, threadListItem_d_exports as ThreadListItemPrimitive, type ThreadListItemRuntime, ThreadListItemRuntimeProvider, type ThreadListItemState, type ThreadListItemStatus, threadList_d_exports as ThreadListPrimitive, type ThreadListRuntime, type ThreadListState, type ThreadMessage, type ThreadMessageLike, thread_d_exports as ThreadPrimitive, type ThreadRuntime, type ThreadState, type ThreadSuggestion, type ThreadSystemMessage, type ThreadUserMessage, type ThreadUserMessagePart, type ThreadViewportState, type Tool, type ToolArgsStatus, type ToolCallMessagePart, type ToolCallMessagePartComponent, type ToolCallMessagePartMcpMetadata, type ToolCallMessagePartProps, type ToolCallMessagePartStatus, type ToolDefinition, type ToolExecutionStatus, type ToolModelContentPart, type Toolkit, Tools, type Unstable_AudioMessagePart, type Unstable_AudioMessagePartComponent, type Unstable_AudioMessagePartProps, type Unstable_DirectiveFormatter, type Unstable_DirectiveSegment, type Unstable_IconComponent, type Unstable_Mention, type Unstable_MentionCategory, type Unstable_MentionDirective, type Unstable_ModelContextToolsOptions, type RegisteredTrigger as Unstable_RegisteredTrigger, type Unstable_SlashCommand, type Unstable_SlashCommandAction, type TriggerBehavior as Unstable_TriggerBehavior, type Unstable_TriggerItem, type Unstable_UseMentionAdapterOptions, type Unstable_UseSlashCommandAdapterOptions, type Unsubscribe, type VoiceSessionControls, type VoiceSessionHelpers, type VoiceSessionState, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createVoiceSession, getExternalStoreMessages, getMcpAppFromToolPart, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, makeAssistantVisible, mergeModelContexts, tool, convertExternalMessages as unstable_convertExternalMessages, createMessageConverter as unstable_createMessageConverter, unstable_defaultDirectiveFormatter, unstable_useMentionAdapter, unstable_useSlashCommandAdapter, useTriggerPopoverRootContext as unstable_useTriggerPopoverRootContext, useTriggerPopoverRootContextOptional as unstable_useTriggerPopoverRootContextOptional, useTriggerPopoverScopeContext as unstable_useTriggerPopoverScopeContext, useTriggerPopoverScopeContextOptional as unstable_useTriggerPopoverScopeContextOptional, useTriggerPopoverTriggers as unstable_useTriggerPopoverTriggers, useTriggerPopoverTriggersOptional as unstable_useTriggerPopoverTriggersOptional, useAssistantContext, useAssistantDataUI, useAssistantFrameHost, useAssistantInstructions, useAssistantInteractable, useAssistantRuntime, useAssistantTool, useAssistantToolUI, useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState, useAttachment, useAttachmentRuntime, useAui, useAuiEvent, useAuiState, useCloudThreadListAdapter, useCloudThreadListRuntime, useComposer, useComposerRuntime, useEditComposer, useEditComposerAttachment, useEditComposerAttachmentRuntime, useExternalMessageConverter, useExternalStoreRuntime, useInlineRender, useInteractableState, useLocalRuntime, useMessage, useMessageAttachment, useMessageAttachmentRuntime, useMessagePart, useMessagePartData, useMessagePartFile, useMessagePartImage, useMessagePartReasoning, useMessagePartRuntime, useMessagePartSource, useMessagePartText, useMessageQuote, useMessageRuntime, useMessageTiming, useRemoteThreadListRuntime, useRuntimeAdapters, useScrollLock, useThread, useThreadComposer, useThreadComposerAttachment, useThreadComposerAttachmentRuntime, useThreadList, useThreadListItem, useThreadListItemRuntime, useThreadModelContext, useThreadRuntime, useThreadViewport, useThreadViewportAutoScroll, useThreadViewportStore, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume };
|
|
82
|
+
export { actionBarMore_d_exports as ActionBarMorePrimitive, actionBar_d_exports as ActionBarPrimitive, type AddToolResultOptions, type AppendMessage, type Assistant, type AssistantClient, AssistantCloud, type AssistantContextConfig, type AssistantDataUI, type AssistantDataUIProps, type AssistantEventCallback, type AssistantEventName, type AssistantEventPayload, type AssistantEventScope, type AssistantEventSelector, AssistantFrameHost, AssistantFrameProvider, type AssistantInteractableProps, assistantModal_d_exports as AssistantModalPrimitive, type AssistantRuntime, AssistantRuntimeProvider, type AssistantState, type AssistantTool, type AssistantToolProps, type AssistantToolUI, type AssistantToolUIProps, type AssistantTransportCommand, type AssistantTransportConnectionMetadata, type AssistantTransportProtocol, type Attachment, type AttachmentAdapter, attachment_d_exports as AttachmentPrimitive, type AttachmentRuntime, type AttachmentState, type AttachmentStatus, AuiIf, AuiProvider, branchPicker_d_exports as BranchPickerPrimitive, ChainOfThoughtByIndicesProvider, ChainOfThoughtClient, chainOfThought_d_exports as ChainOfThoughtPrimitive, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, CloudFileAttachmentAdapter, type CompleteAttachment, ComposerAttachmentByIndexProvider, composer_d_exports as ComposerPrimitive, type ComposerRuntime, type ComposerSendOptions, type ComposerState, CompositeAttachmentAdapter, type CreateAppendMessage, type CreateAttachment, type CreateResumeRunConfig, type CreateStartRunConfig, type DataMessagePart, type DataMessagePartComponent, type DataMessagePartProps, DataRenderers, DevToolsHooks, DevToolsProviderApi, type DictationAdapter, type DictationState, type EditComposerRuntime, type EditComposerState, type EmptyMessagePartComponent, type EmptyMessagePartProps, type EnrichedPartState, error_d_exports as ErrorPrimitive, ExportedMessageRepository, type ExportedMessageRepositoryItem, type ExternalStoreAdapter, type ExternalStoreMessageConverter, type ExternalStoreThreadData, type ExternalStoreThreadListAdapter, ExternalThread, type ExternalThreadMessage, type ExternalThreadProps, type ExternalThreadQueueAdapter, FRAME_MESSAGE_CHANNEL, type FeedbackAdapter, type FileMessagePart, type FileMessagePartComponent, type FileMessagePartProps, type FrameMessage, type FrameMessageType, type GenerativeUIComponentRegistry, type GenerativeUIMessagePart, type GenerativeUIMessagePartComponent, type GenerativeUIMessagePartProps, type GenerativeUINode, GenerativeUIRender, GenerativeUIRenderError, type GenerativeUIRenderProps, type GenerativeUISpec, type GenericThreadHistoryAdapter, internal_d_exports as INTERNAL, type ImageMessagePart, type ImageMessagePartComponent, type ImageMessagePartProps, InMemoryThreadList, InMemoryThreadListAdapter, type InMemoryThreadListProps, Interactables, type LanguageModelConfig, type LanguageModelV1CallSettings, type LocalRuntimeOptions, type LocalRuntimeOptionsBase, type McpAppDisplayMode, type McpAppHostContext, type McpAppHostInfo, type McpAppMetadata, McpAppRenderer, type McpAppRendererOptions, type McpAppResource, type McpAppResourceCSP, type McpAppResourceMeta, type McpAppResourceOutput, type McpAppSandboxConfig, type McpAppToolCallParams, type McpAppsHost, McpAppsRemoteHost, type McpAppsRemoteHostOptions, MessageAttachmentByIndexProvider, MessageByIndexProvider, type MessageFormatAdapter, type MessageFormatItem, type MessageFormatRepository, messagePart_d_exports as MessagePartPrimitive, type MessagePartRuntime, type MessagePartState, type MessagePartStatus, message_d_exports as MessagePrimitive, MessageProvider, type MessageRuntime, type MessageState, type MessageStatus, type MessageStorageEntry, type MessageTiming, type ModelContext, ModelContextClient, type ModelContextProvider, ModelContextRegistry, type ModelContextRegistryInstructionHandle, type ModelContextRegistryProviderHandle, type ModelContextRegistryToolHandle, PartByIndexProvider, type PartState, type PendingAttachment, type QueueItemMethods, queueItem_d_exports as QueueItemPrimitive, type QueueItemState, type QuoteInfo, type QuoteMessagePartComponent, type QuoteMessagePartProps, ReadonlyThreadProvider, type RealtimeVoiceAdapter, type ReasoningGroupComponent, type ReasoningGroupProps, type ReasoningMessagePart, type ReasoningMessagePartComponent, type ReasoningMessagePartProps, type RemoteThreadListAdapter, RuntimeAdapterProvider, type RuntimeAdapters, selectionToolbar_d_exports as SelectionToolbarPrimitive, type SendCommandsRequestBody, type SerializedModelContext, type SerializedTool, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SingleThreadList, type SourceMessagePart, type SourceMessagePartComponent, type SourceMessagePartProps, type SourceProviderMetadata, type SpeechSynthesisAdapter, type SubmitFeedbackOptions, type SuggestionAdapter, SuggestionByIndexProvider, type SuggestionConfig, suggestion_d_exports as SuggestionPrimitive, Suggestions, type TextMessagePart, type TextMessagePartComponent, type TextMessagePartProps, TextMessagePartProvider, type ThreadAssistantMessage, type ThreadAssistantMessagePart, type ThreadComposerRuntime, type ThreadComposerState, type ThreadHistoryAdapter, ThreadListItemByIndexProvider, threadListItemMore_d_exports as ThreadListItemMorePrimitive, threadListItem_d_exports as ThreadListItemPrimitive, type ThreadListItemRuntime, ThreadListItemRuntimeProvider, type ThreadListItemState, type ThreadListItemStatus, threadList_d_exports as ThreadListPrimitive, type ThreadListRuntime, type ThreadListState, type ThreadMessage, type ThreadMessageLike, thread_d_exports as ThreadPrimitive, type ThreadRuntime, type ThreadState, type ThreadSuggestion, type ThreadSystemMessage, type ThreadUserMessage, type ThreadUserMessagePart, type ThreadViewportState, type Tool, type ToolArgsStatus, type ToolCallMessagePart, type ToolCallMessagePartComponent, type ToolCallMessagePartMcpMetadata, type ToolCallMessagePartProps, type ToolCallMessagePartStatus, type ToolDefinition, type ToolExecutionStatus, type ToolModelContentPart, type Toolkit, Tools, type Unstable_AudioMessagePart, type Unstable_AudioMessagePartComponent, type Unstable_AudioMessagePartProps, type Unstable_DirectiveFormatter, type Unstable_DirectiveSegment, type Unstable_IconComponent, type Unstable_Mention, type Unstable_MentionCategory, type Unstable_MentionDirective, type Unstable_ModelContextToolsOptions, type RegisteredTrigger as Unstable_RegisteredTrigger, type Unstable_SlashCommand, type Unstable_SlashCommandAction, type TriggerBehavior as Unstable_TriggerBehavior, type Unstable_TriggerItem, type Unstable_UseMentionAdapterOptions, type Unstable_UseSlashCommandAdapterOptions, type Unsubscribe, type VoiceSessionControls, type VoiceSessionHelpers, type VoiceSessionState, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createVoiceSession, getExternalStoreMessages, getMcpAppFromToolPart, groupPartByType, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, makeAssistantVisible, mergeModelContexts, tool, convertExternalMessages as unstable_convertExternalMessages, createMessageConverter as unstable_createMessageConverter, unstable_defaultDirectiveFormatter, unstable_useMentionAdapter, unstable_useSlashCommandAdapter, useTriggerPopoverRootContext as unstable_useTriggerPopoverRootContext, useTriggerPopoverRootContextOptional as unstable_useTriggerPopoverRootContextOptional, useTriggerPopoverScopeContext as unstable_useTriggerPopoverScopeContext, useTriggerPopoverScopeContextOptional as unstable_useTriggerPopoverScopeContextOptional, useTriggerPopoverTriggers as unstable_useTriggerPopoverTriggers, useTriggerPopoverTriggersOptional as unstable_useTriggerPopoverTriggersOptional, useAssistantContext, useAssistantDataUI, useAssistantFrameHost, useAssistantInstructions, useAssistantInteractable, useAssistantRuntime, useAssistantTool, useAssistantToolUI, useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState, useAttachment, useAttachmentRuntime, useAui, useAuiEvent, useAuiState, useCloudThreadListAdapter, useCloudThreadListRuntime, useComposer, useComposerRuntime, useEditComposer, useEditComposerAttachment, useEditComposerAttachmentRuntime, useExternalMessageConverter, useExternalStoreRuntime, useInlineRender, useInteractableState, useLocalRuntime, useMessage, useMessageAttachment, useMessageAttachmentRuntime, useMessagePart, useMessagePartData, useMessagePartFile, useMessagePartImage, useMessagePartReasoning, useMessagePartRuntime, useMessagePartSource, useMessagePartText, useMessageQuote, useMessageRuntime, useMessageTiming, useRemoteThreadListRuntime, useRuntimeAdapters, useScrollLock, useThread, useThreadComposer, useThreadComposerAttachment, useThreadComposerAttachmentRuntime, useThreadList, useThreadListItem, useThreadListItemRuntime, useThreadModelContext, useThreadRuntime, useThreadViewport, useThreadViewportAutoScroll, useThreadViewportStore, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume };
|
package/dist/index.js
CHANGED
|
@@ -67,8 +67,8 @@ import { getMcpAppFromToolPart } from "./mcp-apps/utils.js";
|
|
|
67
67
|
import { McpAppRenderer } from "./mcp-apps/McpAppRenderer.js";
|
|
68
68
|
import { McpAppsRemoteHost } from "./mcp-apps/McpAppsRemoteHost.js";
|
|
69
69
|
import { AuiIf, AuiProvider, useAui, useAuiEvent, useAuiState } from "@assistant-ui/store";
|
|
70
|
-
import { DataRenderers, GenerativeUIRender, GenerativeUIRenderError, Interactables, RuntimeAdapterProvider, Tools, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useInlineRender, useInteractableState, useRuntimeAdapters, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume } from "@assistant-ui/core/react";
|
|
70
|
+
import { DataRenderers, GenerativeUIRender, GenerativeUIRenderError, Interactables, RuntimeAdapterProvider, Tools, groupPartByType, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, useAssistantContext, useAssistantDataUI, useAssistantInstructions, useAssistantInteractable, useAssistantTool, useAssistantToolUI, useInlineRender, useInteractableState, useRuntimeAdapters, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume } from "@assistant-ui/core/react";
|
|
71
71
|
import { AssistantCloud } from "assistant-cloud";
|
|
72
72
|
import { AssistantFrameHost, AssistantFrameProvider, CompositeAttachmentAdapter, ExportedMessageRepository, FRAME_MESSAGE_CHANNEL, InMemoryThreadListAdapter, ModelContextRegistry, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createVoiceSession, getExternalStoreMessages, mergeModelContexts, tool, unstable_defaultDirectiveFormatter } from "@assistant-ui/core";
|
|
73
73
|
import { ChainOfThoughtClient, ModelContext as ModelContextClient, Suggestions } from "@assistant-ui/core/store";
|
|
74
|
-
export { actionBarMore_exports as ActionBarMorePrimitive, actionBar_exports as ActionBarPrimitive, AssistantCloud, AssistantFrameHost, AssistantFrameProvider, assistantModal_exports as AssistantModalPrimitive, AssistantRuntimeProvider, attachment_exports as AttachmentPrimitive, AuiIf, AuiProvider, branchPicker_exports as BranchPickerPrimitive, ChainOfThoughtByIndicesProvider, ChainOfThoughtClient, chainOfThought_exports as ChainOfThoughtPrimitive, CloudFileAttachmentAdapter, ComposerAttachmentByIndexProvider, composer_exports as ComposerPrimitive, CompositeAttachmentAdapter, DataRenderers, DevToolsHooks, DevToolsProviderApi, error_exports as ErrorPrimitive, ExportedMessageRepository, ExternalThread, FRAME_MESSAGE_CHANNEL, GenerativeUIRender, GenerativeUIRenderError, internal_exports as INTERNAL, InMemoryThreadList, InMemoryThreadListAdapter, Interactables, McpAppRenderer, McpAppsRemoteHost, MessageAttachmentByIndexProvider, MessageByIndexProvider, messagePart_exports as MessagePartPrimitive, message_exports as MessagePrimitive, MessageProvider, ModelContextClient, ModelContextRegistry, PartByIndexProvider, queueItem_exports as QueueItemPrimitive, ReadonlyThreadProvider, RuntimeAdapterProvider, selectionToolbar_exports as SelectionToolbarPrimitive, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SingleThreadList, SuggestionByIndexProvider, suggestion_exports as SuggestionPrimitive, Suggestions, TextMessagePartProvider, ThreadListItemByIndexProvider, threadListItemMore_exports as ThreadListItemMorePrimitive, threadListItem_exports as ThreadListItemPrimitive, ThreadListItemRuntimeProvider, threadList_exports as ThreadListPrimitive, thread_exports as ThreadPrimitive, Tools, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createVoiceSession, getExternalStoreMessages, getMcpAppFromToolPart, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, makeAssistantVisible, mergeModelContexts, tool, convertExternalMessages as unstable_convertExternalMessages, createMessageConverter as unstable_createMessageConverter, unstable_defaultDirectiveFormatter, unstable_useMentionAdapter, unstable_useSlashCommandAdapter, useTriggerPopoverRootContext as unstable_useTriggerPopoverRootContext, useTriggerPopoverRootContextOptional as unstable_useTriggerPopoverRootContextOptional, useTriggerPopoverScopeContext as unstable_useTriggerPopoverScopeContext, useTriggerPopoverScopeContextOptional as unstable_useTriggerPopoverScopeContextOptional, useTriggerPopoverTriggers as unstable_useTriggerPopoverTriggers, useTriggerPopoverTriggersOptional as unstable_useTriggerPopoverTriggersOptional, useAssistantContext, useAssistantDataUI, useAssistantFrameHost, useAssistantInstructions, useAssistantInteractable, useAssistantRuntime, useAssistantTool, useAssistantToolUI, useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState, useAttachment, useAttachmentRuntime, useAui, useAuiEvent, useAuiState, useCloudThreadListAdapter, useCloudThreadListRuntime, useComposer, useComposerRuntime, useEditComposer, useEditComposerAttachment, useEditComposerAttachmentRuntime, useExternalMessageConverter, useExternalStoreRuntime, useInlineRender, useInteractableState, useLocalRuntime, useMessage, useMessageAttachment, useMessageAttachmentRuntime, useMessagePart, useMessagePartData, useMessagePartFile, useMessagePartImage, useMessagePartReasoning, useMessagePartRuntime, useMessagePartSource, useMessagePartText, useMessageQuote, useMessageRuntime, useMessageTiming, useRemoteThreadListRuntime, useRuntimeAdapters, useScrollLock, useThread, useThreadComposer, useThreadComposerAttachment, useThreadComposerAttachmentRuntime, useThreadList, useThreadListItem, useThreadListItemRuntime, useThreadModelContext, useThreadRuntime, useThreadViewport, useThreadViewportAutoScroll, useThreadViewportStore, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume };
|
|
74
|
+
export { actionBarMore_exports as ActionBarMorePrimitive, actionBar_exports as ActionBarPrimitive, AssistantCloud, AssistantFrameHost, AssistantFrameProvider, assistantModal_exports as AssistantModalPrimitive, AssistantRuntimeProvider, attachment_exports as AttachmentPrimitive, AuiIf, AuiProvider, branchPicker_exports as BranchPickerPrimitive, ChainOfThoughtByIndicesProvider, ChainOfThoughtClient, chainOfThought_exports as ChainOfThoughtPrimitive, CloudFileAttachmentAdapter, ComposerAttachmentByIndexProvider, composer_exports as ComposerPrimitive, CompositeAttachmentAdapter, DataRenderers, DevToolsHooks, DevToolsProviderApi, error_exports as ErrorPrimitive, ExportedMessageRepository, ExternalThread, FRAME_MESSAGE_CHANNEL, GenerativeUIRender, GenerativeUIRenderError, internal_exports as INTERNAL, InMemoryThreadList, InMemoryThreadListAdapter, Interactables, McpAppRenderer, McpAppsRemoteHost, MessageAttachmentByIndexProvider, MessageByIndexProvider, messagePart_exports as MessagePartPrimitive, message_exports as MessagePrimitive, MessageProvider, ModelContextClient, ModelContextRegistry, PartByIndexProvider, queueItem_exports as QueueItemPrimitive, ReadonlyThreadProvider, RuntimeAdapterProvider, selectionToolbar_exports as SelectionToolbarPrimitive, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, SingleThreadList, SuggestionByIndexProvider, suggestion_exports as SuggestionPrimitive, Suggestions, TextMessagePartProvider, ThreadListItemByIndexProvider, threadListItemMore_exports as ThreadListItemMorePrimitive, threadListItem_exports as ThreadListItemPrimitive, ThreadListItemRuntimeProvider, threadList_exports as ThreadListPrimitive, thread_exports as ThreadPrimitive, Tools, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createVoiceSession, getExternalStoreMessages, getMcpAppFromToolPart, groupPartByType, makeAssistantDataUI, makeAssistantTool, makeAssistantToolUI, makeAssistantVisible, mergeModelContexts, tool, convertExternalMessages as unstable_convertExternalMessages, createMessageConverter as unstable_createMessageConverter, unstable_defaultDirectiveFormatter, unstable_useMentionAdapter, unstable_useSlashCommandAdapter, useTriggerPopoverRootContext as unstable_useTriggerPopoverRootContext, useTriggerPopoverRootContextOptional as unstable_useTriggerPopoverRootContextOptional, useTriggerPopoverScopeContext as unstable_useTriggerPopoverScopeContext, useTriggerPopoverScopeContextOptional as unstable_useTriggerPopoverScopeContextOptional, useTriggerPopoverTriggers as unstable_useTriggerPopoverTriggers, useTriggerPopoverTriggersOptional as unstable_useTriggerPopoverTriggersOptional, useAssistantContext, useAssistantDataUI, useAssistantFrameHost, useAssistantInstructions, useAssistantInteractable, useAssistantRuntime, useAssistantTool, useAssistantToolUI, useAssistantTransportRuntime, useAssistantTransportSendCommand, useAssistantTransportState, useAttachment, useAttachmentRuntime, useAui, useAuiEvent, useAuiState, useCloudThreadListAdapter, useCloudThreadListRuntime, useComposer, useComposerRuntime, useEditComposer, useEditComposerAttachment, useEditComposerAttachmentRuntime, useExternalMessageConverter, useExternalStoreRuntime, useInlineRender, useInteractableState, useLocalRuntime, useMessage, useMessageAttachment, useMessageAttachmentRuntime, useMessagePart, useMessagePartData, useMessagePartFile, useMessagePartImage, useMessagePartReasoning, useMessagePartRuntime, useMessagePartSource, useMessagePartText, useMessageQuote, useMessageRuntime, useMessageTiming, useRemoteThreadListRuntime, useRuntimeAdapters, useScrollLock, useThread, useThreadComposer, useThreadComposerAttachment, useThreadComposerAttachmentRuntime, useThreadList, useThreadListItem, useThreadListItemRuntime, useThreadModelContext, useThreadRuntime, useThreadViewport, useThreadViewportAutoScroll, useThreadViewportStore, useToolArgsStatus, useVoiceControls, useVoiceState, useVoiceVolume };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessagePartsGrouped.d.ts","names":[],"sources":["../../../src/primitives/message/MessagePartsGrouped.tsx"],"mappings":";;;;KA8BK,gBAAA;EACH,QAAA;EACA,OAAO;AAAA;AAAA,KAGG,gBAAA,IAAoB,KAAA,qBAA0B,gBAAgB;AAAA,kBAmDzD,qCAAA;EAAA,KACH,KAAA;IApDF;;;;AAA8D;AAmD1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6CI,gBAAA,EAAkB,gBAAA;IAqBL;;;;;;IAbb,UAAA;MAwBY,6CArBN,KAAA,GAAQ,yBAAA,cAyBR;MAvBA,IAAA,GAAO,wBAAA,cA2BG;MAzBV,SAAA,GAAY,6BAAA,cA4BN;MA1BN,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A;MAAA;IAAA;EAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAuOD,qCAAA,EAAuC,EAAE,CACpD,qCAAA,CAAsC,KAAA;;;;;;;cA2C3B,+CAAA,EAAiD,EAAA,CAC5D,IAAA,CAAK,qCAAA,CAAsC,KAAA"}
|
|
@@ -78,17 +78,20 @@ const MessagePartComponent = ({ components: { Text = defaultComponents.Text, Rea
|
|
|
78
78
|
if (type === "tool-call") {
|
|
79
79
|
const addResult = aui.part().addToolResult;
|
|
80
80
|
const resume = aui.part().resumeToolCall;
|
|
81
|
+
const respondToApproval = aui.part().respondToToolApproval;
|
|
81
82
|
if ("Override" in tools) return /* @__PURE__ */ jsx(tools.Override, {
|
|
82
83
|
...part,
|
|
83
84
|
addResult,
|
|
84
|
-
resume
|
|
85
|
+
resume,
|
|
86
|
+
respondToApproval
|
|
85
87
|
});
|
|
86
88
|
const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;
|
|
87
89
|
return /* @__PURE__ */ jsx(ToolUIDisplay, {
|
|
88
90
|
...part,
|
|
89
91
|
Fallback: Tool,
|
|
90
92
|
addResult,
|
|
91
|
-
resume
|
|
93
|
+
resume,
|
|
94
|
+
respondToApproval
|
|
92
95
|
});
|
|
93
96
|
}
|
|
94
97
|
if (part.status?.type === "requires-action") throw new Error("Encountered unexpected requires-action status");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessagePartsGrouped.js","names":[],"sources":["../../../src/primitives/message/MessagePartsGrouped.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type FC,\n memo,\n type PropsWithChildren,\n useMemo,\n} from \"react\";\nimport { useAuiState, useAui } from \"@assistant-ui/store\";\nimport { PartByIndexProvider } from \"../../context/providers/PartByIndexProvider\";\nimport { TextMessagePartProvider } from \"../../context/providers/TextMessagePartProvider\";\nimport { MessagePartPrimitiveText } from \"../messagePart/MessagePartText\";\nimport { MessagePartPrimitiveImage } from \"../messagePart/MessagePartImage\";\nimport type {\n Unstable_AudioMessagePartComponent,\n DataMessagePartComponent,\n DataMessagePartProps,\n EmptyMessagePartComponent,\n TextMessagePartComponent,\n ImageMessagePartComponent,\n SourceMessagePartComponent,\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n FileMessagePartComponent,\n ReasoningMessagePartComponent,\n} from \"@assistant-ui/core/react\";\nimport { MessagePartPrimitiveInProgress } from \"../messagePart/MessagePartInProgress\";\nimport type { MessagePartStatus } from \"@assistant-ui/core\";\n\ntype MessagePartGroup = {\n groupKey: string | undefined;\n indices: number[];\n};\n\nexport type GroupingFunction = (parts: readonly any[]) => MessagePartGroup[];\n\n/**\n * Groups message parts by their parent ID.\n * Parts without a parent ID appear in their chronological position as individual groups.\n * Parts with the same parent ID are grouped together at the position of their first occurrence.\n */\nconst groupMessagePartsByParentId: GroupingFunction = (\n parts: readonly any[],\n): MessagePartGroup[] => {\n // Map maintains insertion order, so groups appear in order of first occurrence\n const groupMap = new Map<string, number[]>();\n\n // Process each part in order\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n const parentId = part?.parentId as string | undefined;\n\n // For parts without parentId, assign a unique group ID to maintain their position\n const groupId = parentId ?? `__ungrouped_${i}`;\n\n // Get or create the indices array for this group\n const indices = groupMap.get(groupId) ?? [];\n indices.push(i);\n groupMap.set(groupId, indices);\n }\n\n // Convert map to array of groups\n const groups: MessagePartGroup[] = [];\n for (const [groupId, indices] of groupMap) {\n // Extract parentId (undefined for ungrouped parts)\n const groupKey = groupId.startsWith(\"__ungrouped_\") ? undefined : groupId;\n groups.push({ groupKey, indices });\n }\n\n return groups;\n};\n\nconst useMessagePartsGrouped = (\n groupingFunction: GroupingFunction,\n): MessagePartGroup[] => {\n const parts = useAuiState((s) => s.message.parts);\n\n return useMemo(() => {\n if (parts.length === 0) {\n return [];\n }\n return groupingFunction(parts);\n }, [parts, groupingFunction]);\n};\n\nexport namespace MessagePrimitiveUnstable_PartsGrouped {\n export type Props = {\n /**\n * Function that takes an array of message parts and returns an array of groups.\n * Each group contains a key (for identification) and an array of indices.\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * groupingFunction={(parts) => {\n * const groups = new Map<string, number[]>();\n * parts.forEach((part, i) => {\n * const key = part.parentId ?? `__ungrouped_${i}`;\n * const indices = groups.get(key) ?? [];\n * indices.push(i);\n * groups.set(key, indices);\n * });\n * return Array.from(groups.entries()).map(([key, indices]) => ({\n * key: key.startsWith(\"__ungrouped_\") ? undefined : key,\n * indices\n * }));\n * }}\n * ```\n *\n * @example\n * ```tsx\n * // Group by tool name\n * import { groupMessagePartsByToolName } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.Unstable_PartsGrouped\n * groupingFunction={groupMessagePartsByToolName}\n * components={{\n * Group: ({ key, indices, children }) => {\n * if (!key) return <>{children}</>;\n * return (\n * <div className=\"tool-group\">\n * <h4>Tool: {key}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\n groupingFunction: GroupingFunction;\n\n /**\n * Component configuration for rendering different types of message content.\n *\n * You can provide custom components for each content type (text, image, file, etc.)\n * and configure tool rendering behavior. If not provided, default components will be used.\n */\n components:\n | {\n /** Component for rendering empty messages */\n Empty?: EmptyMessagePartComponent | undefined;\n /** Component for rendering text content */\n Text?: TextMessagePartComponent | undefined;\n /** Component for rendering reasoning content (typically hidden) */\n Reasoning?: ReasoningMessagePartComponent | undefined;\n /** Component for rendering source content */\n Source?: SourceMessagePartComponent | undefined;\n /** Component for rendering image content */\n Image?: ImageMessagePartComponent | undefined;\n /** Component for rendering file content */\n File?: FileMessagePartComponent | undefined;\n /** Component for rendering audio content (experimental) */\n Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;\n /** Configuration for data part rendering */\n data?:\n | {\n /** Map data event names to specific components */\n by_name?:\n | Record<string, DataMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unmatched data events */\n Fallback?: DataMessagePartComponent | undefined;\n }\n | undefined;\n /** Configuration for tool call rendering */\n tools?:\n | {\n /** Map of tool names to their specific components */\n by_name?:\n | Record<string, ToolCallMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unregistered tools */\n Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;\n }\n | {\n /** Override component that handles all tool calls */\n Override: ComponentType<ToolCallMessagePartProps>;\n }\n | undefined;\n\n /**\n * Component for rendering grouped message parts.\n *\n * When provided, this component will automatically wrap message parts that share\n * the same group key as determined by the groupingFunction.\n *\n * The component receives:\n * - `groupKey`: The group key (or undefined for ungrouped parts)\n * - `indices`: Array of indices for the parts in this group\n * - `children`: The rendered message part components\n *\n * @example\n * ```tsx\n * // Collapsible group\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <details className=\"message-group\">\n * <summary>\n * Group {groupKey} ({indices.length} parts)\n * </summary>\n * <div className=\"group-content\">\n * {children}\n * </div>\n * </details>\n * );\n * }\n * ```\n *\n * @param groupKey - The group key (undefined for ungrouped parts)\n * @param indices - Array of indices for the parts in this group\n * @param children - Rendered message part components to display within the group\n */\n Group?: ComponentType<\n PropsWithChildren<{\n groupKey: string | undefined;\n indices: number[];\n }>\n >;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallMessagePartComponent | undefined;\n} & ToolCallMessagePartProps) => {\n const Render = useAuiState((s) => {\n const Render = s.tools.tools[props.toolName] ?? Fallback;\n if (Array.isArray(Render)) return Render[0] ?? Fallback;\n return Render;\n });\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst DataUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: DataMessagePartComponent | undefined;\n} & DataMessagePartProps) => {\n const Render = useAuiState((s) => {\n const Render = s.dataRenderers.renderers[props.name] ?? Fallback;\n if (Array.isArray(Render)) return Render[0] ?? Fallback;\n return Render;\n });\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <MessagePartPrimitiveText />\n <MessagePartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </MessagePartPrimitiveInProgress>\n </p>\n ),\n Reasoning: () => null,\n Source: () => null,\n Image: () => <MessagePartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n Group: ({ children }) => children,\n} satisfies MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n\ntype MessagePartComponentProps = {\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartComponent: FC<MessagePartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Reasoning = defaultComponents.Reasoning,\n Image = defaultComponents.Image,\n Source = defaultComponents.Source,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n tools = {},\n data,\n } = {},\n}) => {\n const aui = useAui();\n const part = useAuiState((s) => s.part);\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = aui.part().addToolResult;\n const resume = aui.part().resumeToolCall;\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} resume={resume} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return (\n <ToolUIDisplay\n {...part}\n Fallback={Tool}\n addResult={addResult}\n resume={resume}\n />\n );\n }\n\n if (part.status?.type === \"requires-action\")\n throw new Error(\"Encountered unexpected requires-action status\");\n\n switch (type) {\n case \"text\":\n return <Text {...part} />;\n\n case \"reasoning\":\n return <Reasoning {...part} />;\n\n case \"source\":\n return <Source {...part} />;\n\n case \"image\":\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n case \"data\": {\n const Data = data?.by_name?.[part.name] ?? data?.Fallback;\n return <DataUIDisplay {...part} Fallback={Data} />;\n }\n\n default:\n console.warn(`Unknown message part type: ${type}`);\n return null;\n }\n};\n\ntype MessagePartProps = {\n partIndex: number;\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartImpl: FC<MessagePartProps> = ({ partIndex, components }) => {\n return (\n <PartByIndexProvider index={partIndex}>\n <MessagePartComponent components={components} />\n </PartByIndexProvider>\n );\n};\n\nconst MessagePart = memo(\n MessagePartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Reasoning === next.components?.Reasoning &&\n prev.components?.Source === next.components?.Source &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.File === next.components?.File &&\n prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&\n prev.components?.tools === next.components?.tools &&\n prev.components?.data === next.components?.data &&\n prev.components?.Group === next.components?.Group,\n);\n\nconst EmptyPartFallback: FC<{\n status: MessagePartStatus;\n component: TextMessagePartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextMessagePartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextMessagePartProvider>\n );\n};\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyPartsImpl: FC<MessagePartComponentProps> = ({ components }) => {\n const status = useAuiState(\n (s) => (s.message.status ?? COMPLETE_STATUS) as MessagePartStatus,\n );\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyPartFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyParts = memo(\n EmptyPartsImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\n/**\n * Renders the parts of a message grouped by a custom grouping function.\n *\n * This component allows you to group message parts based on any criteria you define.\n * The grouping function receives all message parts and returns an array of groups,\n * where each group has a key and an array of part indices.\n *\n * @deprecated Prefer `<MessagePrimitive.GroupedParts>` for adjacent\n * grouping — it dispatches all rendering through one `switch (part.type)`\n * and supports nested group paths. Keep this primitive only for\n * non-adjacent clustering (e.g., gathering parts with the same parent-id\n * across the message).\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * <MessagePrimitive.Unstable_PartsGrouped\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <div className=\"parent-group border rounded p-4\">\n * <h4>Parent ID: {groupKey}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveUnstable_PartsGrouped: FC<\n MessagePrimitiveUnstable_PartsGrouped.Props\n> = ({ groupingFunction, components }) => {\n const contentLength = useAuiState((s) => s.message.parts.length);\n const messageGroups = useMessagePartsGrouped(groupingFunction);\n\n const partsElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyParts components={components} />;\n }\n\n return messageGroups.map((group, groupIndex) => {\n const GroupComponent = components?.Group ?? defaultComponents.Group;\n\n return (\n <GroupComponent\n key={`group-${groupIndex}-${group.groupKey ?? \"ungrouped\"}`}\n groupKey={group.groupKey}\n indices={group.indices}\n >\n {group.indices.map((partIndex) => (\n <MessagePart\n key={partIndex}\n partIndex={partIndex}\n components={components}\n />\n ))}\n </GroupComponent>\n );\n });\n }, [messageGroups, components, contentLength]);\n\n return <>{partsElements}</>;\n};\n\nMessagePrimitiveUnstable_PartsGrouped.displayName =\n \"MessagePrimitive.Unstable_PartsGrouped\";\n\n/**\n * Renders the parts of a message grouped by their parent ID.\n * This is a convenience wrapper around Unstable_PartsGrouped with parent ID grouping.\n *\n * @deprecated Use MessagePrimitive.Unstable_PartsGrouped instead for more flexibility\n */\nexport const MessagePrimitiveUnstable_PartsGroupedByParentId: FC<\n Omit<MessagePrimitiveUnstable_PartsGrouped.Props, \"groupingFunction\">\n> = ({ components, ...props }) => {\n return (\n <MessagePrimitiveUnstable_PartsGrouped\n {...props}\n components={components}\n groupingFunction={groupMessagePartsByParentId}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+
{"version":3,"file":"MessagePartsGrouped.js","names":[],"sources":["../../../src/primitives/message/MessagePartsGrouped.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type FC,\n memo,\n type PropsWithChildren,\n useMemo,\n} from \"react\";\nimport { useAuiState, useAui } from \"@assistant-ui/store\";\nimport { PartByIndexProvider } from \"../../context/providers/PartByIndexProvider\";\nimport { TextMessagePartProvider } from \"../../context/providers/TextMessagePartProvider\";\nimport { MessagePartPrimitiveText } from \"../messagePart/MessagePartText\";\nimport { MessagePartPrimitiveImage } from \"../messagePart/MessagePartImage\";\nimport type {\n Unstable_AudioMessagePartComponent,\n DataMessagePartComponent,\n DataMessagePartProps,\n EmptyMessagePartComponent,\n TextMessagePartComponent,\n ImageMessagePartComponent,\n SourceMessagePartComponent,\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n FileMessagePartComponent,\n ReasoningMessagePartComponent,\n} from \"@assistant-ui/core/react\";\nimport { MessagePartPrimitiveInProgress } from \"../messagePart/MessagePartInProgress\";\nimport type { MessagePartStatus } from \"@assistant-ui/core\";\n\ntype MessagePartGroup = {\n groupKey: string | undefined;\n indices: number[];\n};\n\nexport type GroupingFunction = (parts: readonly any[]) => MessagePartGroup[];\n\n/**\n * Groups message parts by their parent ID.\n * Parts without a parent ID appear in their chronological position as individual groups.\n * Parts with the same parent ID are grouped together at the position of their first occurrence.\n */\nconst groupMessagePartsByParentId: GroupingFunction = (\n parts: readonly any[],\n): MessagePartGroup[] => {\n // Map maintains insertion order, so groups appear in order of first occurrence\n const groupMap = new Map<string, number[]>();\n\n // Process each part in order\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n const parentId = part?.parentId as string | undefined;\n\n // For parts without parentId, assign a unique group ID to maintain their position\n const groupId = parentId ?? `__ungrouped_${i}`;\n\n // Get or create the indices array for this group\n const indices = groupMap.get(groupId) ?? [];\n indices.push(i);\n groupMap.set(groupId, indices);\n }\n\n // Convert map to array of groups\n const groups: MessagePartGroup[] = [];\n for (const [groupId, indices] of groupMap) {\n // Extract parentId (undefined for ungrouped parts)\n const groupKey = groupId.startsWith(\"__ungrouped_\") ? undefined : groupId;\n groups.push({ groupKey, indices });\n }\n\n return groups;\n};\n\nconst useMessagePartsGrouped = (\n groupingFunction: GroupingFunction,\n): MessagePartGroup[] => {\n const parts = useAuiState((s) => s.message.parts);\n\n return useMemo(() => {\n if (parts.length === 0) {\n return [];\n }\n return groupingFunction(parts);\n }, [parts, groupingFunction]);\n};\n\nexport namespace MessagePrimitiveUnstable_PartsGrouped {\n export type Props = {\n /**\n * Function that takes an array of message parts and returns an array of groups.\n * Each group contains a key (for identification) and an array of indices.\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * groupingFunction={(parts) => {\n * const groups = new Map<string, number[]>();\n * parts.forEach((part, i) => {\n * const key = part.parentId ?? `__ungrouped_${i}`;\n * const indices = groups.get(key) ?? [];\n * indices.push(i);\n * groups.set(key, indices);\n * });\n * return Array.from(groups.entries()).map(([key, indices]) => ({\n * key: key.startsWith(\"__ungrouped_\") ? undefined : key,\n * indices\n * }));\n * }}\n * ```\n *\n * @example\n * ```tsx\n * // Group by tool name\n * import { groupMessagePartsByToolName } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.Unstable_PartsGrouped\n * groupingFunction={groupMessagePartsByToolName}\n * components={{\n * Group: ({ key, indices, children }) => {\n * if (!key) return <>{children}</>;\n * return (\n * <div className=\"tool-group\">\n * <h4>Tool: {key}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\n groupingFunction: GroupingFunction;\n\n /**\n * Component configuration for rendering different types of message content.\n *\n * You can provide custom components for each content type (text, image, file, etc.)\n * and configure tool rendering behavior. If not provided, default components will be used.\n */\n components:\n | {\n /** Component for rendering empty messages */\n Empty?: EmptyMessagePartComponent | undefined;\n /** Component for rendering text content */\n Text?: TextMessagePartComponent | undefined;\n /** Component for rendering reasoning content (typically hidden) */\n Reasoning?: ReasoningMessagePartComponent | undefined;\n /** Component for rendering source content */\n Source?: SourceMessagePartComponent | undefined;\n /** Component for rendering image content */\n Image?: ImageMessagePartComponent | undefined;\n /** Component for rendering file content */\n File?: FileMessagePartComponent | undefined;\n /** Component for rendering audio content (experimental) */\n Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;\n /** Configuration for data part rendering */\n data?:\n | {\n /** Map data event names to specific components */\n by_name?:\n | Record<string, DataMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unmatched data events */\n Fallback?: DataMessagePartComponent | undefined;\n }\n | undefined;\n /** Configuration for tool call rendering */\n tools?:\n | {\n /** Map of tool names to their specific components */\n by_name?:\n | Record<string, ToolCallMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unregistered tools */\n Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;\n }\n | {\n /** Override component that handles all tool calls */\n Override: ComponentType<ToolCallMessagePartProps>;\n }\n | undefined;\n\n /**\n * Component for rendering grouped message parts.\n *\n * When provided, this component will automatically wrap message parts that share\n * the same group key as determined by the groupingFunction.\n *\n * The component receives:\n * - `groupKey`: The group key (or undefined for ungrouped parts)\n * - `indices`: Array of indices for the parts in this group\n * - `children`: The rendered message part components\n *\n * @example\n * ```tsx\n * // Collapsible group\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <details className=\"message-group\">\n * <summary>\n * Group {groupKey} ({indices.length} parts)\n * </summary>\n * <div className=\"group-content\">\n * {children}\n * </div>\n * </details>\n * );\n * }\n * ```\n *\n * @param groupKey - The group key (undefined for ungrouped parts)\n * @param indices - Array of indices for the parts in this group\n * @param children - Rendered message part components to display within the group\n */\n Group?: ComponentType<\n PropsWithChildren<{\n groupKey: string | undefined;\n indices: number[];\n }>\n >;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallMessagePartComponent | undefined;\n} & ToolCallMessagePartProps) => {\n const Render = useAuiState((s) => {\n const Render = s.tools.tools[props.toolName] ?? Fallback;\n if (Array.isArray(Render)) return Render[0] ?? Fallback;\n return Render;\n });\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst DataUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: DataMessagePartComponent | undefined;\n} & DataMessagePartProps) => {\n const Render = useAuiState((s) => {\n const Render = s.dataRenderers.renderers[props.name] ?? Fallback;\n if (Array.isArray(Render)) return Render[0] ?? Fallback;\n return Render;\n });\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <MessagePartPrimitiveText />\n <MessagePartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </MessagePartPrimitiveInProgress>\n </p>\n ),\n Reasoning: () => null,\n Source: () => null,\n Image: () => <MessagePartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n Group: ({ children }) => children,\n} satisfies MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n\ntype MessagePartComponentProps = {\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartComponent: FC<MessagePartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Reasoning = defaultComponents.Reasoning,\n Image = defaultComponents.Image,\n Source = defaultComponents.Source,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n tools = {},\n data,\n } = {},\n}) => {\n const aui = useAui();\n const part = useAuiState((s) => s.part);\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = aui.part().addToolResult;\n const resume = aui.part().resumeToolCall;\n const respondToApproval = aui.part().respondToToolApproval;\n if (\"Override\" in tools)\n return (\n <tools.Override\n {...part}\n addResult={addResult}\n resume={resume}\n respondToApproval={respondToApproval}\n />\n );\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return (\n <ToolUIDisplay\n {...part}\n Fallback={Tool}\n addResult={addResult}\n resume={resume}\n respondToApproval={respondToApproval}\n />\n );\n }\n\n if (part.status?.type === \"requires-action\")\n throw new Error(\"Encountered unexpected requires-action status\");\n\n switch (type) {\n case \"text\":\n return <Text {...part} />;\n\n case \"reasoning\":\n return <Reasoning {...part} />;\n\n case \"source\":\n return <Source {...part} />;\n\n case \"image\":\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n case \"data\": {\n const Data = data?.by_name?.[part.name] ?? data?.Fallback;\n return <DataUIDisplay {...part} Fallback={Data} />;\n }\n\n default:\n console.warn(`Unknown message part type: ${type}`);\n return null;\n }\n};\n\ntype MessagePartProps = {\n partIndex: number;\n components: MessagePrimitiveUnstable_PartsGrouped.Props[\"components\"];\n};\n\nconst MessagePartImpl: FC<MessagePartProps> = ({ partIndex, components }) => {\n return (\n <PartByIndexProvider index={partIndex}>\n <MessagePartComponent components={components} />\n </PartByIndexProvider>\n );\n};\n\nconst MessagePart = memo(\n MessagePartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Reasoning === next.components?.Reasoning &&\n prev.components?.Source === next.components?.Source &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.File === next.components?.File &&\n prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&\n prev.components?.tools === next.components?.tools &&\n prev.components?.data === next.components?.data &&\n prev.components?.Group === next.components?.Group,\n);\n\nconst EmptyPartFallback: FC<{\n status: MessagePartStatus;\n component: TextMessagePartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextMessagePartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextMessagePartProvider>\n );\n};\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyPartsImpl: FC<MessagePartComponentProps> = ({ components }) => {\n const status = useAuiState(\n (s) => (s.message.status ?? COMPLETE_STATUS) as MessagePartStatus,\n );\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyPartFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyParts = memo(\n EmptyPartsImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\n/**\n * Renders the parts of a message grouped by a custom grouping function.\n *\n * This component allows you to group message parts based on any criteria you define.\n * The grouping function receives all message parts and returns an array of groups,\n * where each group has a key and an array of part indices.\n *\n * @deprecated Prefer `<MessagePrimitive.GroupedParts>` for adjacent\n * grouping — it dispatches all rendering through one `switch (part.type)`\n * and supports nested group paths. Keep this primitive only for\n * non-adjacent clustering (e.g., gathering parts with the same parent-id\n * across the message).\n *\n * @example\n * ```tsx\n * // Group by parent ID (default behavior)\n * <MessagePrimitive.Unstable_PartsGrouped\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * Group: ({ groupKey, indices, children }) => {\n * if (!groupKey) return <>{children}</>;\n * return (\n * <div className=\"parent-group border rounded p-4\">\n * <h4>Parent ID: {groupKey}</h4>\n * {children}\n * </div>\n * );\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveUnstable_PartsGrouped: FC<\n MessagePrimitiveUnstable_PartsGrouped.Props\n> = ({ groupingFunction, components }) => {\n const contentLength = useAuiState((s) => s.message.parts.length);\n const messageGroups = useMessagePartsGrouped(groupingFunction);\n\n const partsElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyParts components={components} />;\n }\n\n return messageGroups.map((group, groupIndex) => {\n const GroupComponent = components?.Group ?? defaultComponents.Group;\n\n return (\n <GroupComponent\n key={`group-${groupIndex}-${group.groupKey ?? \"ungrouped\"}`}\n groupKey={group.groupKey}\n indices={group.indices}\n >\n {group.indices.map((partIndex) => (\n <MessagePart\n key={partIndex}\n partIndex={partIndex}\n components={components}\n />\n ))}\n </GroupComponent>\n );\n });\n }, [messageGroups, components, contentLength]);\n\n return <>{partsElements}</>;\n};\n\nMessagePrimitiveUnstable_PartsGrouped.displayName =\n \"MessagePrimitive.Unstable_PartsGrouped\";\n\n/**\n * Renders the parts of a message grouped by their parent ID.\n * This is a convenience wrapper around Unstable_PartsGrouped with parent ID grouping.\n *\n * @deprecated Use MessagePrimitive.Unstable_PartsGrouped instead for more flexibility\n */\nexport const MessagePrimitiveUnstable_PartsGroupedByParentId: FC<\n Omit<MessagePrimitiveUnstable_PartsGrouped.Props, \"groupingFunction\">\n> = ({ components, ...props }) => {\n return (\n <MessagePrimitiveUnstable_PartsGrouped\n {...props}\n components={components}\n groupingFunction={groupMessagePartsByParentId}\n />\n );\n};\n\nMessagePrimitiveUnstable_PartsGroupedByParentId.displayName =\n \"MessagePrimitive.Unstable_PartsGroupedByParentId\";\n"],"mappings":";;;;;;;;;;;;;;;AA0CA,MAAM,+BACJ,UACuB;CAEvB,MAAM,2BAAW,IAAI,IAAsB;CAG3C,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EAKrC,MAAM,UAJO,MAAM,IACI,YAGK,eAAe;EAG3C,MAAM,UAAU,SAAS,IAAI,OAAO,KAAK,CAAC;EAC1C,QAAQ,KAAK,CAAC;EACd,SAAS,IAAI,SAAS,OAAO;CAC/B;CAGA,MAAM,SAA6B,CAAC;CACpC,KAAK,MAAM,CAAC,SAAS,YAAY,UAAU;EAEzC,MAAM,WAAW,QAAQ,WAAW,cAAc,IAAI,KAAA,IAAY;EAClE,OAAO,KAAK;GAAE;GAAU;EAAQ,CAAC;CACnC;CAEA,OAAO;AACT;AAEA,MAAM,0BACJ,qBACuB;CACvB,MAAM,QAAQ,aAAa,MAAM,EAAE,QAAQ,KAAK;CAEhD,OAAO,cAAc;EACnB,IAAI,MAAM,WAAW,GACnB,OAAO,CAAC;EAEV,OAAO,iBAAiB,KAAK;CAC/B,GAAG,CAAC,OAAO,gBAAgB,CAAC;AAC9B;AA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AAK,OAAO,eAAe;GAG9C,OACE,oBAHqB,YAAY,SAAS,kBAAkB,OAG5D;IAEE,UAAU,MAAM;IAChB,SAAS,MAAM;cAEd,MAAM,QAAQ,KAAK,cAClB,oBAAC,aAAD;KAEa;KACC;IACb,GAHM,SAGN,CACF;GACa,GAXT,SAAS,WAAW,GAAG,MAAM,YAAY,aAWhC;EAEpB,CAAC;CACH,GAAG;EAAC;EAAe;EAAY;CAAa,CAEtB,EAAI,CAAA;AAC5B;AAEA,sCAAsC,cACpC;;;;;;;AAQF,MAAa,mDAER,EAAE,YAAY,GAAG,YAAY;CAChC,OACE,oBAAC,uCAAD;EACE,GAAI;EACQ;EACZ,kBAAkB;CACnB,CAAA;AAEL;AAEA,gDAAgD,cAC9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.9",
|
|
4
4
|
"description": "Open-source TypeScript/React library for building production-grade AI chat experiences",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"radix-ui",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
],
|
|
49
49
|
"sideEffects": false,
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@assistant-ui/core": "^0.2.
|
|
51
|
+
"@assistant-ui/core": "^0.2.6",
|
|
52
52
|
"@assistant-ui/store": "^0.2.12",
|
|
53
53
|
"@assistant-ui/tap": "^0.5.12",
|
|
54
54
|
"@radix-ui/primitive": "^1.1.3",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@radix-ui/react-use-callback-ref": "^1.1.1",
|
|
59
59
|
"@radix-ui/react-use-escape-keydown": "^1.1.1",
|
|
60
60
|
"assistant-cloud": "^0.1.29",
|
|
61
|
-
"assistant-stream": "^0.3.
|
|
61
|
+
"assistant-stream": "^0.3.17",
|
|
62
62
|
"nanoid": "^5.1.11",
|
|
63
63
|
"radix-ui": "^1.4.3",
|
|
64
64
|
"react-textarea-autosize": "^8.5.9",
|
package/src/index.ts
CHANGED
|
@@ -254,6 +254,7 @@ export * as ThreadListItemPrimitive from "./primitives/threadListItem";
|
|
|
254
254
|
export * as ThreadListItemMorePrimitive from "./primitives/threadListItemMore";
|
|
255
255
|
export * as SelectionToolbarPrimitive from "./primitives/selectionToolbar";
|
|
256
256
|
|
|
257
|
+
export { groupPartByType } from "@assistant-ui/core/react";
|
|
257
258
|
export { useMessagePartText } from "./primitives/messagePart/useMessagePartText";
|
|
258
259
|
export { useMessagePartReasoning } from "./primitives/messagePart/useMessagePartReasoning";
|
|
259
260
|
export { useMessagePartSource } from "./primitives/messagePart/useMessagePartSource";
|
|
@@ -294,8 +294,16 @@ const MessagePartComponent: FC<MessagePartComponentProps> = ({
|
|
|
294
294
|
if (type === "tool-call") {
|
|
295
295
|
const addResult = aui.part().addToolResult;
|
|
296
296
|
const resume = aui.part().resumeToolCall;
|
|
297
|
+
const respondToApproval = aui.part().respondToToolApproval;
|
|
297
298
|
if ("Override" in tools)
|
|
298
|
-
return
|
|
299
|
+
return (
|
|
300
|
+
<tools.Override
|
|
301
|
+
{...part}
|
|
302
|
+
addResult={addResult}
|
|
303
|
+
resume={resume}
|
|
304
|
+
respondToApproval={respondToApproval}
|
|
305
|
+
/>
|
|
306
|
+
);
|
|
299
307
|
const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;
|
|
300
308
|
return (
|
|
301
309
|
<ToolUIDisplay
|
|
@@ -303,6 +311,7 @@ const MessagePartComponent: FC<MessagePartComponentProps> = ({
|
|
|
303
311
|
Fallback={Tool}
|
|
304
312
|
addResult={addResult}
|
|
305
313
|
resume={resume}
|
|
314
|
+
respondToApproval={respondToApproval}
|
|
306
315
|
/>
|
|
307
316
|
);
|
|
308
317
|
}
|