@assistant-ui/react 0.11.47 → 0.11.48
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/types/Thread.d.ts +4 -0
- package/dist/client/types/Thread.d.ts.map +1 -1
- package/dist/context/react/index.d.ts +1 -1
- package/dist/context/react/index.d.ts.map +1 -1
- package/dist/context/react/index.js.map +1 -1
- package/dist/context/stores/ThreadViewport.js +1 -1
- package/dist/context/stores/ThreadViewport.js.map +1 -1
- package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ThreadRuntimeClient.js +1 -0
- package/dist/legacy-runtime/client/ThreadRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/runtime/subscribable/SKIP_UPDATE.js +1 -1
- package/dist/legacy-runtime/runtime/subscribable/SKIP_UPDATE.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/getExternalStoreMessage.js +2 -2
- package/dist/legacy-runtime/runtime-cores/external-store/getExternalStoreMessage.js.map +1 -1
- package/dist/model-context/registry/ModelContextRegistry.js +3 -3
- package/dist/model-context/registry/ModelContextRegistry.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.d.ts +17 -0
- package/dist/primitives/actionBar/ActionBarExportMarkdown.d.ts.map +1 -0
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js +54 -0
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -0
- package/dist/primitives/actionBar/index.d.ts +1 -0
- package/dist/primitives/actionBar/index.d.ts.map +1 -1
- package/dist/primitives/actionBar/index.js +2 -0
- package/dist/primitives/actionBar/index.js.map +1 -1
- package/dist/primitives/assistant/AssistantIf.d.ts +12 -0
- package/dist/primitives/assistant/AssistantIf.d.ts.map +1 -0
- package/dist/primitives/assistant/AssistantIf.js +16 -0
- package/dist/primitives/assistant/AssistantIf.js.map +1 -0
- package/dist/primitives/composer/ComposerIf.d.ts +3 -0
- package/dist/primitives/composer/ComposerIf.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerIf.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +1 -0
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/message/MessageIf.d.ts +3 -0
- package/dist/primitives/message/MessageIf.d.ts.map +1 -1
- package/dist/primitives/message/MessageIf.js.map +1 -1
- package/dist/primitives/message/MessageParts.js +2 -2
- package/dist/primitives/message/MessageParts.js.map +1 -1
- package/dist/primitives/thread/ThreadIf.d.ts +3 -0
- package/dist/primitives/thread/ThreadIf.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadIf.js +2 -3
- package/dist/primitives/thread/ThreadIf.js.map +1 -1
- package/dist/tests/setup.js +44 -42
- package/dist/tests/setup.js.map +1 -1
- package/package.json +7 -7
- package/src/client/types/Thread.ts +5 -0
- package/src/context/react/index.ts +1 -0
- package/src/legacy-runtime/client/ThreadRuntimeClient.ts +1 -0
- package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +70 -0
- package/src/primitives/actionBar/index.ts +1 -0
- package/src/primitives/assistant/AssistantIf.tsx +25 -0
- package/src/primitives/composer/ComposerIf.tsx +3 -0
- package/src/primitives/composer/ComposerInput.tsx +3 -0
- package/src/primitives/index.ts +2 -0
- package/src/primitives/message/MessageIf.tsx +3 -0
- package/src/primitives/message/MessageParts.tsx +2 -2
- package/src/primitives/thread/ThreadIf.tsx +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n ClipboardEvent,\n type KeyboardEvent,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n} from \"react-textarea-autosize\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useAssistantState, useAssistantApi } from \"../../context\";\n\nexport namespace ComposerPrimitiveInput {\n export type Element = HTMLTextAreaElement;\n export type Props = TextareaAutosizeProps & {\n /**\n * Whether to render as a child component using Slot.\n * When true, the component will merge its props with its child.\n */\n asChild?: boolean | undefined;\n /**\n * Whether to submit the message when Enter is pressed (without Shift).\n * @default true\n */\n submitOnEnter?: boolean | undefined;\n /**\n * Whether to cancel message composition when Escape is pressed.\n * @default true\n */\n cancelOnEscape?: boolean | undefined;\n /**\n * Whether to automatically focus the input when a new run starts.\n * @default true\n */\n unstable_focusOnRunStart?: boolean | undefined;\n /**\n * Whether to automatically focus the input when scrolling to bottom.\n * @default true\n */\n unstable_focusOnScrollToBottom?: boolean | undefined;\n /**\n * Whether to automatically focus the input when switching threads.\n * @default true\n */\n unstable_focusOnThreadSwitched?: boolean | undefined;\n /**\n * Whether to automatically add pasted files as attachments.\n * @default true\n */\n addAttachmentOnPaste?: boolean | undefined;\n };\n}\n\n/**\n * A text input component for composing messages.\n *\n * This component provides a rich text input experience with automatic resizing,\n * keyboard shortcuts, file paste support, and intelligent focus management.\n * It integrates with the composer context to manage message state and submission.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitOnEnter={true}\n * addAttachmentOnPaste={true}\n * />\n * ```\n */\nexport const ComposerPrimitiveInput = forwardRef<\n ComposerPrimitiveInput.Element,\n ComposerPrimitiveInput.Props\n>(\n (\n {\n autoFocus = false,\n asChild,\n disabled: disabledProp,\n onChange,\n onKeyDown,\n onPaste,\n submitOnEnter = true,\n cancelOnEscape = true,\n unstable_focusOnRunStart = true,\n unstable_focusOnScrollToBottom = true,\n unstable_focusOnThreadSwitched = true,\n addAttachmentOnPaste = true,\n ...rest\n },\n forwardedRef,\n ) => {\n const api = useAssistantApi();\n\n const value = useAssistantState(({ composer }) => {\n if (!composer.isEditing) return \"\";\n return composer.text;\n });\n\n const Component = asChild ? Slot : TextareaAutosize;\n\n const isDisabled =\n useAssistantState(({ thread }) => thread.isDisabled) || disabledProp;\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n\n useEscapeKeydown((e) => {\n if (!cancelOnEscape) return;\n\n const composer = api.composer();\n if (composer.getState().canCancel) {\n composer.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (isDisabled || !submitOnEnter) return;\n\n // ignore IME composition events\n if (e.nativeEvent.isComposing) return;\n\n if (e.key === \"Enter\" && e.shiftKey === false) {\n const isRunning = api.thread().getState().isRunning;\n\n if (!isRunning) {\n e.preventDefault();\n\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const handlePaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {\n if (!addAttachmentOnPaste) return;\n const threadCapabilities = api.thread().getState().capabilities;\n const files = Array.from(e.clipboardData?.files || []);\n\n if (threadCapabilities.attachments && files.length > 0) {\n try {\n e.preventDefault();\n await Promise.all(\n files.map((file) => api.composer().addAttachment(file)),\n );\n } catch (error) {\n console.error(\"Error adding attachment:\", error);\n }\n }\n };\n\n const autoFocusEnabled = autoFocus && !isDisabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(textarea.value.length, textarea.value.length);\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (\n api.composer().getState().type === \"thread\" &&\n unstable_focusOnScrollToBottom\n ) {\n focus();\n }\n });\n\n useEffect(() => {\n if (\n api.composer().getState().type !== \"thread\" ||\n !unstable_focusOnRunStart\n )\n return undefined;\n\n return api.on(\"thread.run-start\", focus);\n }, [unstable_focusOnRunStart, focus, api]);\n\n useEffect(() => {\n if (\n api.composer().getState().type !== \"thread\" ||\n !unstable_focusOnThreadSwitched\n )\n return undefined;\n\n return api.on(\"thread-list-item.switched-to\", focus);\n }, [unstable_focusOnThreadSwitched, focus, api]);\n\n return (\n <Component\n name=\"input\"\n value={value}\n {...rest}\n ref={ref as React.ForwardedRef<HTMLTextAreaElement>}\n disabled={isDisabled}\n onChange={composeEventHandlers(onChange, (e) => {\n if (!api.composer().getState().isEditing) return;\n api.composer().setText(e.target.value);\n api.flushSync();\n })}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyPress)}\n onPaste={composeEventHandlers(onPaste, handlePaste)}\n />\n );\n },\n);\n\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n"],"mappings":";;;AAEA,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAChC,SAAS,YAAY;AACrB;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,sBAEA;AACP,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,mBAAmB,uBAAuB;
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/composer/ComposerInput.tsx"],"sourcesContent":["\"use client\";\n\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n ClipboardEvent,\n type KeyboardEvent,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\nimport TextareaAutosize, {\n type TextareaAutosizeProps,\n} from \"react-textarea-autosize\";\nimport { useEscapeKeydown } from \"@radix-ui/react-use-escape-keydown\";\nimport { useOnScrollToBottom } from \"../../utils/hooks/useOnScrollToBottom\";\nimport { useAssistantState, useAssistantApi } from \"../../context\";\n\nexport namespace ComposerPrimitiveInput {\n export type Element = HTMLTextAreaElement;\n export type Props = TextareaAutosizeProps & {\n /**\n * Whether to render as a child component using Slot.\n * When true, the component will merge its props with its child.\n */\n asChild?: boolean | undefined;\n /**\n * Whether to submit the message when Enter is pressed (without Shift).\n * @default true\n */\n submitOnEnter?: boolean | undefined;\n /**\n * Whether to cancel message composition when Escape is pressed.\n * @default true\n */\n cancelOnEscape?: boolean | undefined;\n /**\n * Whether to automatically focus the input when a new run starts.\n * @default true\n */\n unstable_focusOnRunStart?: boolean | undefined;\n /**\n * Whether to automatically focus the input when scrolling to bottom.\n * @default true\n */\n unstable_focusOnScrollToBottom?: boolean | undefined;\n /**\n * Whether to automatically focus the input when switching threads.\n * @default true\n */\n unstable_focusOnThreadSwitched?: boolean | undefined;\n /**\n * Whether to automatically add pasted files as attachments.\n * @default true\n */\n addAttachmentOnPaste?: boolean | undefined;\n };\n}\n\n/**\n * A text input component for composing messages.\n *\n * This component provides a rich text input experience with automatic resizing,\n * keyboard shortcuts, file paste support, and intelligent focus management.\n * It integrates with the composer context to manage message state and submission.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.Input\n * placeholder=\"Type your message...\"\n * submitOnEnter={true}\n * addAttachmentOnPaste={true}\n * />\n * ```\n */\nexport const ComposerPrimitiveInput = forwardRef<\n ComposerPrimitiveInput.Element,\n ComposerPrimitiveInput.Props\n>(\n (\n {\n autoFocus = false,\n asChild,\n disabled: disabledProp,\n onChange,\n onKeyDown,\n onPaste,\n submitOnEnter = true,\n cancelOnEscape = true,\n unstable_focusOnRunStart = true,\n unstable_focusOnScrollToBottom = true,\n unstable_focusOnThreadSwitched = true,\n addAttachmentOnPaste = true,\n ...rest\n },\n forwardedRef,\n ) => {\n const api = useAssistantApi();\n\n const value = useAssistantState(({ composer }) => {\n if (!composer.isEditing) return \"\";\n return composer.text;\n });\n\n const Component = asChild ? Slot : TextareaAutosize;\n\n const isDisabled =\n useAssistantState(({ thread }) => thread.isDisabled) || disabledProp;\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const ref = useComposedRefs(forwardedRef, textareaRef);\n\n useEscapeKeydown((e) => {\n if (!cancelOnEscape) return;\n\n // Only handle ESC if it originated from within this input\n if (!textareaRef.current?.contains(e.target as Node)) return;\n\n const composer = api.composer();\n if (composer.getState().canCancel) {\n composer.cancel();\n e.preventDefault();\n }\n });\n\n const handleKeyPress = (e: KeyboardEvent) => {\n if (isDisabled || !submitOnEnter) return;\n\n // ignore IME composition events\n if (e.nativeEvent.isComposing) return;\n\n if (e.key === \"Enter\" && e.shiftKey === false) {\n const isRunning = api.thread().getState().isRunning;\n\n if (!isRunning) {\n e.preventDefault();\n\n textareaRef.current?.closest(\"form\")?.requestSubmit();\n }\n }\n };\n\n const handlePaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {\n if (!addAttachmentOnPaste) return;\n const threadCapabilities = api.thread().getState().capabilities;\n const files = Array.from(e.clipboardData?.files || []);\n\n if (threadCapabilities.attachments && files.length > 0) {\n try {\n e.preventDefault();\n await Promise.all(\n files.map((file) => api.composer().addAttachment(file)),\n );\n } catch (error) {\n console.error(\"Error adding attachment:\", error);\n }\n }\n };\n\n const autoFocusEnabled = autoFocus && !isDisabled;\n const focus = useCallback(() => {\n const textarea = textareaRef.current;\n if (!textarea || !autoFocusEnabled) return;\n\n textarea.focus({ preventScroll: true });\n textarea.setSelectionRange(textarea.value.length, textarea.value.length);\n }, [autoFocusEnabled]);\n\n useEffect(() => focus(), [focus]);\n\n useOnScrollToBottom(() => {\n if (\n api.composer().getState().type === \"thread\" &&\n unstable_focusOnScrollToBottom\n ) {\n focus();\n }\n });\n\n useEffect(() => {\n if (\n api.composer().getState().type !== \"thread\" ||\n !unstable_focusOnRunStart\n )\n return undefined;\n\n return api.on(\"thread.run-start\", focus);\n }, [unstable_focusOnRunStart, focus, api]);\n\n useEffect(() => {\n if (\n api.composer().getState().type !== \"thread\" ||\n !unstable_focusOnThreadSwitched\n )\n return undefined;\n\n return api.on(\"thread-list-item.switched-to\", focus);\n }, [unstable_focusOnThreadSwitched, focus, api]);\n\n return (\n <Component\n name=\"input\"\n value={value}\n {...rest}\n ref={ref as React.ForwardedRef<HTMLTextAreaElement>}\n disabled={isDisabled}\n onChange={composeEventHandlers(onChange, (e) => {\n if (!api.composer().getState().isEditing) return;\n api.composer().setText(e.target.value);\n api.flushSync();\n })}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyPress)}\n onPaste={composeEventHandlers(onPaste, handlePaste)}\n />\n );\n },\n);\n\nComposerPrimitiveInput.displayName = \"ComposerPrimitive.Input\";\n"],"mappings":";;;AAEA,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAChC,SAAS,YAAY;AACrB;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,sBAEA;AACP,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,mBAAmB,uBAAuB;AAuL7C;AA5HC,IAAM,yBAAyB;AAAA,EAIpC,CACE;AAAA,IACE,YAAY;AAAA,IACZ;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,IACjB,2BAA2B;AAAA,IAC3B,iCAAiC;AAAA,IACjC,iCAAiC;AAAA,IACjC,uBAAuB;AAAA,IACvB,GAAG;AAAA,EACL,GACA,iBACG;AACH,UAAM,MAAM,gBAAgB;AAE5B,UAAM,QAAQ,kBAAkB,CAAC,EAAE,SAAS,MAAM;AAChD,UAAI,CAAC,SAAS,UAAW,QAAO;AAChC,aAAO,SAAS;AAAA,IAClB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./thread";
|
|
10
10
|
export * as ThreadListPrimitive from "./threadList";
|
|
11
11
|
export * as ThreadListItemPrimitive from "./threadListItem";
|
|
12
|
+
export { AssistantIf } from "./assistant/AssistantIf";
|
|
12
13
|
export { useMessagePartText } from "./messagePart/useMessagePartText";
|
|
13
14
|
export { useMessagePartReasoning } from "./messagePart/useMessagePartReasoning";
|
|
14
15
|
export { useMessagePartSource } from "./messagePart/useMessagePartSource";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/primitives/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,uBAAuB,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,mBAAmB,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,qBAAqB,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,iBAAiB,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,oBAAoB,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,cAAc,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,gBAAgB,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,eAAe,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,mBAAmB,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,uBAAuB,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/primitives/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,uBAAuB,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,mBAAmB,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,qBAAqB,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,iBAAiB,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,oBAAoB,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,cAAc,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,gBAAgB,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,eAAe,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,mBAAmB,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,uBAAuB,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/primitives/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import * as MessagePrimitive from "./message/index.js";
|
|
|
10
10
|
import * as ThreadPrimitive from "./thread/index.js";
|
|
11
11
|
import * as ThreadListPrimitive from "./threadList/index.js";
|
|
12
12
|
import * as ThreadListItemPrimitive from "./threadListItem/index.js";
|
|
13
|
+
import { AssistantIf } from "./assistant/AssistantIf.js";
|
|
13
14
|
import { useMessagePartText } from "./messagePart/useMessagePartText.js";
|
|
14
15
|
import { useMessagePartReasoning } from "./messagePart/useMessagePartReasoning.js";
|
|
15
16
|
import { useMessagePartSource } from "./messagePart/useMessagePartSource.js";
|
|
@@ -20,6 +21,7 @@ import { useThreadViewportAutoScroll } from "./thread/useThreadViewportAutoScrol
|
|
|
20
21
|
import { useScrollLock } from "./reasoning/index.js";
|
|
21
22
|
export {
|
|
22
23
|
ActionBarPrimitive,
|
|
24
|
+
AssistantIf,
|
|
23
25
|
AssistantModalPrimitive,
|
|
24
26
|
AttachmentPrimitive,
|
|
25
27
|
BranchPickerPrimitive,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/primitives/index.ts"],"sourcesContent":["export * as ActionBarPrimitive from \"./actionBar\";\nexport * as AssistantModalPrimitive from \"./assistantModal\";\nexport * as AttachmentPrimitive from \"./attachment\";\nexport * as BranchPickerPrimitive from \"./branchPicker\";\nexport * as ComposerPrimitive from \"./composer\";\nexport * as MessagePartPrimitive from \"./messagePart\";\nexport * as ErrorPrimitive from \"./error\";\nexport * as MessagePrimitive from \"./message\";\nexport * as ThreadPrimitive from \"./thread\";\nexport * as ThreadListPrimitive from \"./threadList\";\nexport * as ThreadListItemPrimitive from \"./threadListItem\";\n\nexport { useMessagePartText } from \"./messagePart/useMessagePartText\";\nexport { useMessagePartReasoning } from \"./messagePart/useMessagePartReasoning\";\nexport { useMessagePartSource } from \"./messagePart/useMessagePartSource\";\nexport { useMessagePartFile } from \"./messagePart/useMessagePartFile\";\nexport { useMessagePartImage } from \"./messagePart/useMessagePartImage\";\nexport { useMessagePartData } from \"./messagePart/useMessagePartData\";\nexport { useThreadViewportAutoScroll } from \"./thread/useThreadViewportAutoScroll\";\nexport { useScrollLock } from \"./reasoning\";\n"],"mappings":";AAAA,YAAY,wBAAwB;AACpC,YAAY,6BAA6B;AACzC,YAAY,yBAAyB;AACrC,YAAY,2BAA2B;AACvC,YAAY,uBAAuB;AACnC,YAAY,0BAA0B;AACtC,YAAY,oBAAoB;AAChC,YAAY,sBAAsB;AAClC,YAAY,qBAAqB;AACjC,YAAY,yBAAyB;AACrC,YAAY,6BAA6B;AAEzC,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AAC5C,SAAS,qBAAqB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/primitives/index.ts"],"sourcesContent":["export * as ActionBarPrimitive from \"./actionBar\";\nexport * as AssistantModalPrimitive from \"./assistantModal\";\nexport * as AttachmentPrimitive from \"./attachment\";\nexport * as BranchPickerPrimitive from \"./branchPicker\";\nexport * as ComposerPrimitive from \"./composer\";\nexport * as MessagePartPrimitive from \"./messagePart\";\nexport * as ErrorPrimitive from \"./error\";\nexport * as MessagePrimitive from \"./message\";\nexport * as ThreadPrimitive from \"./thread\";\nexport * as ThreadListPrimitive from \"./threadList\";\nexport * as ThreadListItemPrimitive from \"./threadListItem\";\n\nexport { AssistantIf } from \"./assistant/AssistantIf\";\n\nexport { useMessagePartText } from \"./messagePart/useMessagePartText\";\nexport { useMessagePartReasoning } from \"./messagePart/useMessagePartReasoning\";\nexport { useMessagePartSource } from \"./messagePart/useMessagePartSource\";\nexport { useMessagePartFile } from \"./messagePart/useMessagePartFile\";\nexport { useMessagePartImage } from \"./messagePart/useMessagePartImage\";\nexport { useMessagePartData } from \"./messagePart/useMessagePartData\";\nexport { useThreadViewportAutoScroll } from \"./thread/useThreadViewportAutoScroll\";\nexport { useScrollLock } from \"./reasoning\";\n"],"mappings":";AAAA,YAAY,wBAAwB;AACpC,YAAY,6BAA6B;AACzC,YAAY,yBAAyB;AACrC,YAAY,2BAA2B;AACvC,YAAY,uBAAuB;AACnC,YAAY,0BAA0B;AACtC,YAAY,oBAAoB;AAChC,YAAY,sBAAsB;AAClC,YAAY,qBAAqB;AACjC,YAAY,yBAAyB;AACrC,YAAY,6BAA6B;AAEzC,SAAS,mBAAmB;AAE5B,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AAC5C,SAAS,qBAAqB;","names":[]}
|
|
@@ -17,6 +17,9 @@ type UseMessageIfProps = RequireAtLeastOne<MessageIfFilters>;
|
|
|
17
17
|
export declare namespace MessagePrimitiveIf {
|
|
18
18
|
type Props = PropsWithChildren<UseMessageIfProps>;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use `<AssistantIf condition={({ message }) => ...} />` instead.
|
|
22
|
+
*/
|
|
20
23
|
export declare const MessagePrimitiveIf: FC<MessagePrimitiveIf.Props>;
|
|
21
24
|
export {};
|
|
22
25
|
//# sourceMappingURL=MessageIf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageIf.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageIf.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,WAAW,EAAE,OAAO,GAAG,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GAAG,SAAS,CAAC;CAC/D,CAAC;AACF,KAAK,iBAAiB,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;AAwD7D,yBAAiB,kBAAkB,CAAC;IAClC,KAAY,KAAK,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;CAC1D;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAM3D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/message/MessageIf.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useAssistantState } from \"../../context\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype MessageIfFilters = {\n user: boolean | undefined;\n assistant: boolean | undefined;\n system: boolean | undefined;\n hasBranches: boolean | undefined;\n copied: boolean | undefined;\n lastOrHover: boolean | undefined;\n last: boolean | undefined;\n speaking: boolean | undefined;\n hasAttachments: boolean | undefined;\n hasContent: boolean | undefined;\n submittedFeedback: \"positive\" | \"negative\" | null | undefined;\n};\ntype UseMessageIfProps = RequireAtLeastOne<MessageIfFilters>;\n\nconst useMessageIf = (props: UseMessageIfProps) => {\n return useAssistantState(({ message }) => {\n const {\n role,\n attachments,\n parts,\n branchCount,\n isLast,\n speech,\n isCopied,\n isHovering,\n } = message;\n\n if (props.hasBranches === true && branchCount < 2) return false;\n\n if (props.user && role !== \"user\") return false;\n if (props.assistant && role !== \"assistant\") return false;\n if (props.system && role !== \"system\") return false;\n\n if (props.lastOrHover === true && !isHovering && !isLast) return false;\n if (props.last !== undefined && props.last !== isLast) return false;\n\n if (props.copied === true && !isCopied) return false;\n if (props.copied === false && isCopied) return false;\n\n if (props.speaking === true && speech == null) return false;\n if (props.speaking === false && speech != null) return false;\n\n if (\n props.hasAttachments === true &&\n (role !== \"user\" || !attachments?.length)\n )\n return false;\n if (\n props.hasAttachments === false &&\n role === \"user\" &&\n !!attachments?.length\n )\n return false;\n\n if (props.hasContent === true && parts.length === 0) return false;\n if (props.hasContent === false && parts.length > 0) return false;\n\n if (\n props.submittedFeedback !== undefined &&\n (message.metadata.submittedFeedback?.type ?? null) !==\n props.submittedFeedback\n )\n return false;\n\n return true;\n });\n};\n\nexport namespace MessagePrimitiveIf {\n export type Props = PropsWithChildren<UseMessageIfProps>;\n}\n\nexport const MessagePrimitiveIf: FC<MessagePrimitiveIf.Props> = ({\n children,\n ...query\n}) => {\n const result = useMessageIf(query);\n return result ? children : null;\n};\n\nMessagePrimitiveIf.displayName = \"MessagePrimitive.If\";\n"],"mappings":";;;AAGA,SAAS,yBAAyB;AAkBlC,IAAM,eAAe,CAAC,UAA6B;AACjD,SAAO,kBAAkB,CAAC,EAAE,QAAQ,MAAM;AACxC,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAEJ,QAAI,MAAM,gBAAgB,QAAQ,cAAc,EAAG,QAAO;AAE1D,QAAI,MAAM,QAAQ,SAAS,OAAQ,QAAO;AAC1C,QAAI,MAAM,aAAa,SAAS,YAAa,QAAO;AACpD,QAAI,MAAM,UAAU,SAAS,SAAU,QAAO;AAE9C,QAAI,MAAM,gBAAgB,QAAQ,CAAC,cAAc,CAAC,OAAQ,QAAO;AACjE,QAAI,MAAM,SAAS,UAAa,MAAM,SAAS,OAAQ,QAAO;AAE9D,QAAI,MAAM,WAAW,QAAQ,CAAC,SAAU,QAAO;AAC/C,QAAI,MAAM,WAAW,SAAS,SAAU,QAAO;AAE/C,QAAI,MAAM,aAAa,QAAQ,UAAU,KAAM,QAAO;AACtD,QAAI,MAAM,aAAa,SAAS,UAAU,KAAM,QAAO;AAEvD,QACE,MAAM,mBAAmB,SACxB,SAAS,UAAU,CAAC,aAAa;AAElC,aAAO;AACT,QACE,MAAM,mBAAmB,SACzB,SAAS,UACT,CAAC,CAAC,aAAa;AAEf,aAAO;AAET,QAAI,MAAM,eAAe,QAAQ,MAAM,WAAW,EAAG,QAAO;AAC5D,QAAI,MAAM,eAAe,SAAS,MAAM,SAAS,EAAG,QAAO;AAE3D,QACE,MAAM,sBAAsB,WAC3B,QAAQ,SAAS,mBAAmB,QAAQ,UAC3C,MAAM;AAER,aAAO;AAET,WAAO;AAAA,EACT,CAAC;AACH;
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/message/MessageIf.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useAssistantState } from \"../../context\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype MessageIfFilters = {\n user: boolean | undefined;\n assistant: boolean | undefined;\n system: boolean | undefined;\n hasBranches: boolean | undefined;\n copied: boolean | undefined;\n lastOrHover: boolean | undefined;\n last: boolean | undefined;\n speaking: boolean | undefined;\n hasAttachments: boolean | undefined;\n hasContent: boolean | undefined;\n submittedFeedback: \"positive\" | \"negative\" | null | undefined;\n};\ntype UseMessageIfProps = RequireAtLeastOne<MessageIfFilters>;\n\nconst useMessageIf = (props: UseMessageIfProps) => {\n return useAssistantState(({ message }) => {\n const {\n role,\n attachments,\n parts,\n branchCount,\n isLast,\n speech,\n isCopied,\n isHovering,\n } = message;\n\n if (props.hasBranches === true && branchCount < 2) return false;\n\n if (props.user && role !== \"user\") return false;\n if (props.assistant && role !== \"assistant\") return false;\n if (props.system && role !== \"system\") return false;\n\n if (props.lastOrHover === true && !isHovering && !isLast) return false;\n if (props.last !== undefined && props.last !== isLast) return false;\n\n if (props.copied === true && !isCopied) return false;\n if (props.copied === false && isCopied) return false;\n\n if (props.speaking === true && speech == null) return false;\n if (props.speaking === false && speech != null) return false;\n\n if (\n props.hasAttachments === true &&\n (role !== \"user\" || !attachments?.length)\n )\n return false;\n if (\n props.hasAttachments === false &&\n role === \"user\" &&\n !!attachments?.length\n )\n return false;\n\n if (props.hasContent === true && parts.length === 0) return false;\n if (props.hasContent === false && parts.length > 0) return false;\n\n if (\n props.submittedFeedback !== undefined &&\n (message.metadata.submittedFeedback?.type ?? null) !==\n props.submittedFeedback\n )\n return false;\n\n return true;\n });\n};\n\nexport namespace MessagePrimitiveIf {\n export type Props = PropsWithChildren<UseMessageIfProps>;\n}\n\n/**\n * @deprecated Use `<AssistantIf condition={({ message }) => ...} />` instead.\n */\nexport const MessagePrimitiveIf: FC<MessagePrimitiveIf.Props> = ({\n children,\n ...query\n}) => {\n const result = useMessageIf(query);\n return result ? children : null;\n};\n\nMessagePrimitiveIf.displayName = \"MessagePrimitive.If\";\n"],"mappings":";;;AAGA,SAAS,yBAAyB;AAkBlC,IAAM,eAAe,CAAC,UAA6B;AACjD,SAAO,kBAAkB,CAAC,EAAE,QAAQ,MAAM;AACxC,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAEJ,QAAI,MAAM,gBAAgB,QAAQ,cAAc,EAAG,QAAO;AAE1D,QAAI,MAAM,QAAQ,SAAS,OAAQ,QAAO;AAC1C,QAAI,MAAM,aAAa,SAAS,YAAa,QAAO;AACpD,QAAI,MAAM,UAAU,SAAS,SAAU,QAAO;AAE9C,QAAI,MAAM,gBAAgB,QAAQ,CAAC,cAAc,CAAC,OAAQ,QAAO;AACjE,QAAI,MAAM,SAAS,UAAa,MAAM,SAAS,OAAQ,QAAO;AAE9D,QAAI,MAAM,WAAW,QAAQ,CAAC,SAAU,QAAO;AAC/C,QAAI,MAAM,WAAW,SAAS,SAAU,QAAO;AAE/C,QAAI,MAAM,aAAa,QAAQ,UAAU,KAAM,QAAO;AACtD,QAAI,MAAM,aAAa,SAAS,UAAU,KAAM,QAAO;AAEvD,QACE,MAAM,mBAAmB,SACxB,SAAS,UAAU,CAAC,aAAa;AAElC,aAAO;AACT,QACE,MAAM,mBAAmB,SACzB,SAAS,UACT,CAAC,CAAC,aAAa;AAEf,aAAO;AAET,QAAI,MAAM,eAAe,QAAQ,MAAM,WAAW,EAAG,QAAO;AAC5D,QAAI,MAAM,eAAe,SAAS,MAAM,SAAS,EAAG,QAAO;AAE3D,QACE,MAAM,sBAAsB,WAC3B,QAAQ,SAAS,mBAAmB,QAAQ,UAC3C,MAAM;AAER,aAAO;AAET,WAAO;AAAA,EACT,CAAC;AACH;AASO,IAAM,qBAAmD,CAAC;AAAA,EAC/D;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,SAAS,aAAa,KAAK;AACjC,SAAO,SAAS,WAAW;AAC7B;AAEA,mBAAmB,cAAc;","names":[]}
|
|
@@ -207,7 +207,7 @@ var MessagePrimitiveParts = ({
|
|
|
207
207
|
range.index
|
|
208
208
|
);
|
|
209
209
|
} else if (range.type === "toolGroup") {
|
|
210
|
-
const ToolGroupComponent = components
|
|
210
|
+
const ToolGroupComponent = components?.ToolGroup ?? defaultComponents.ToolGroup;
|
|
211
211
|
return /* @__PURE__ */ jsx(
|
|
212
212
|
ToolGroupComponent,
|
|
213
213
|
{
|
|
@@ -228,7 +228,7 @@ var MessagePrimitiveParts = ({
|
|
|
228
228
|
`tool-${range.startIndex}`
|
|
229
229
|
);
|
|
230
230
|
} else {
|
|
231
|
-
const ReasoningGroupComponent = components
|
|
231
|
+
const ReasoningGroupComponent = components?.ReasoningGroup ?? defaultComponents.ReasoningGroup;
|
|
232
232
|
return /* @__PURE__ */ jsx(
|
|
233
233
|
ReasoningGroupComponent,
|
|
234
234
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/message/MessageParts.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type FC,\n memo,\n PropsWithChildren,\n useMemo,\n} from \"react\";\nimport {\n useAssistantState,\n useAssistantApi,\n PartByIndexProvider,\n TextMessagePartProvider,\n} from \"../../context\";\nimport { MessagePartPrimitiveText } from \"../messagePart/MessagePartText\";\nimport { MessagePartPrimitiveImage } from \"../messagePart/MessagePartImage\";\nimport type {\n Unstable_AudioMessagePartComponent,\n EmptyMessagePartComponent,\n TextMessagePartComponent,\n ImageMessagePartComponent,\n SourceMessagePartComponent,\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n FileMessagePartComponent,\n ReasoningMessagePartComponent,\n ReasoningGroupComponent,\n} from \"../../types/MessagePartComponentTypes\";\nimport { MessagePartPrimitiveInProgress } from \"../messagePart/MessagePartInProgress\";\nimport { MessagePartStatus } from \"../../types/AssistantTypes\";\nimport { useShallow } from \"zustand/shallow\";\n\ntype MessagePartRange =\n | { type: \"single\"; index: number }\n | { type: \"toolGroup\"; startIndex: number; endIndex: number }\n | { type: \"reasoningGroup\"; startIndex: number; endIndex: number };\n\n/**\n * Creates a group state manager for a specific part type.\n * Returns functions to start, end, and finalize groups.\n */\nconst createGroupState = <T extends \"toolGroup\" | \"reasoningGroup\">(\n groupType: T,\n) => {\n let start = -1;\n\n return {\n startGroup: (index: number) => {\n if (start === -1) {\n start = index;\n }\n },\n endGroup: (endIndex: number, ranges: MessagePartRange[]) => {\n if (start !== -1) {\n ranges.push({\n type: groupType,\n startIndex: start,\n endIndex,\n } as MessagePartRange);\n start = -1;\n }\n },\n finalize: (endIndex: number, ranges: MessagePartRange[]) => {\n if (start !== -1) {\n ranges.push({\n type: groupType,\n startIndex: start,\n endIndex,\n } as MessagePartRange);\n }\n },\n };\n};\n\n/**\n * Groups consecutive tool-call and reasoning message parts into ranges.\n * Always groups tool calls and reasoning parts, even if there's only one.\n */\nconst groupMessageParts = (\n messageTypes: readonly string[],\n): MessagePartRange[] => {\n const ranges: MessagePartRange[] = [];\n const toolGroup = createGroupState(\"toolGroup\");\n const reasoningGroup = createGroupState(\"reasoningGroup\");\n\n for (let i = 0; i < messageTypes.length; i++) {\n const type = messageTypes[i];\n\n if (type === \"tool-call\") {\n reasoningGroup.endGroup(i - 1, ranges);\n toolGroup.startGroup(i);\n } else if (type === \"reasoning\") {\n toolGroup.endGroup(i - 1, ranges);\n reasoningGroup.startGroup(i);\n } else {\n toolGroup.endGroup(i - 1, ranges);\n reasoningGroup.endGroup(i - 1, ranges);\n ranges.push({ type: \"single\", index: i });\n }\n }\n\n toolGroup.finalize(messageTypes.length - 1, ranges);\n reasoningGroup.finalize(messageTypes.length - 1, ranges);\n\n return ranges;\n};\n\nconst useMessagePartsGroups = (): MessagePartRange[] => {\n const messageTypes = useAssistantState(\n useShallow((s) => s.message.parts.map((c: any) => c.type)),\n );\n\n return useMemo(() => {\n if (messageTypes.length === 0) {\n return [];\n }\n return groupMessageParts(messageTypes);\n }, [messageTypes]);\n};\n\nexport namespace MessagePrimitiveParts {\n export type Props = {\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 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 consecutive tool calls.\n *\n * When provided, this component will automatically wrap consecutive tool-call\n * message parts, allowing you to create collapsible sections, custom styling,\n * or other grouped presentations for multiple tool calls.\n *\n * The component receives:\n * - `startIndex`: The index of the first tool call in the group\n * - `endIndex`: The index of the last tool call in the group\n * - `children`: The rendered tool call components\n *\n * @example\n * ```tsx\n * // Collapsible tool group\n * ToolGroup: ({ startIndex, endIndex, children }) => (\n * <details className=\"tool-group\">\n * <summary>\n * {endIndex - startIndex + 1} tool calls\n * </summary>\n * <div className=\"tool-group-content\">\n * {children}\n * </div>\n * </details>\n * )\n * ```\n *\n * @example\n * ```tsx\n * // Custom styled tool group with header\n * ToolGroup: ({ startIndex, endIndex, children }) => (\n * <div className=\"border rounded-lg p-4 my-2\">\n * <div className=\"text-sm text-gray-600 mb-2\">\n * Tool execution #{startIndex + 1}-{endIndex + 1}\n * </div>\n * <div className=\"space-y-2\">\n * {children}\n * </div>\n * </div>\n * )\n * ```\n *\n * @param startIndex - Index of the first tool call in the group\n * @param endIndex - Index of the last tool call in the group\n * @param children - Rendered tool call components to display within the group\n *\n * @deprecated This feature is still experimental and subject to change.\n */\n ToolGroup?: ComponentType<\n PropsWithChildren<{ startIndex: number; endIndex: number }>\n >;\n\n /**\n * Component for rendering grouped reasoning parts.\n *\n * When provided, this component will automatically wrap reasoning message parts\n * (one or more consecutive) in a group container. Each reasoning part inside\n * renders its own text independently - no text merging occurs.\n *\n * The component receives:\n * - `startIndex`: The index of the first reasoning part in the group\n * - `endIndex`: The index of the last reasoning part in the group\n * - `children`: The rendered Reasoning components (one per part)\n *\n * @example\n * ```tsx\n * // Collapsible reasoning group\n * ReasoningGroup: ({ children }) => (\n * <details className=\"reasoning-group\">\n * <summary>Reasoning</summary>\n * <div className=\"reasoning-content\">\n * {children}\n * </div>\n * </details>\n * )\n * ```\n *\n * @param startIndex - Index of the first reasoning part in the group\n * @param endIndex - Index of the last reasoning part in the group\n * @param children - Rendered reasoning part components\n */\n ReasoningGroup?: ReasoningGroupComponent;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallMessagePartComponent | undefined;\n} & ToolCallMessagePartProps) => {\n const Render = useAssistantState(({ tools }) => {\n const Render = 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 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 ToolGroup: ({ children }) => children,\n ReasoningGroup: ({ children }) => children,\n} satisfies MessagePrimitiveParts.Props[\"components\"];\n\ntype MessagePartComponentProps = {\n components: MessagePrimitiveParts.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 } = {},\n}) => {\n const api = useAssistantApi();\n const part = useAssistantState(({ part }) => part);\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = api.part().addToolResult;\n const resume = api.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 return null;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown message part type: ${unhandledType}`);\n }\n};\n\nexport namespace MessagePrimitivePartByIndex {\n export type Props = {\n index: number;\n components: MessagePrimitiveParts.Props[\"components\"];\n };\n}\n\n/**\n * Renders a single message part at the specified index.\n *\n * This component provides direct access to render a specific message part\n * within the current message context, using the provided component configuration.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.PartByIndex\n * index={0}\n * components={{\n * Text: MyTextComponent,\n * Image: MyImageComponent\n * }}\n * />\n * ```\n */\nexport const MessagePrimitivePartByIndex: FC<MessagePrimitivePartByIndex.Props> =\n memo(\n ({ index, components }) => {\n return (\n <PartByIndexProvider index={index}>\n <MessagePartComponent components={components} />\n </PartByIndexProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\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?.ToolGroup === next.components?.ToolGroup &&\n prev.components?.ReasoningGroup === next.components?.ReasoningGroup,\n );\n\nMessagePrimitivePartByIndex.displayName = \"MessagePrimitive.PartByIndex\";\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 = useAssistantState(\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 with support for multiple content types.\n *\n * This component automatically handles different types of message content including\n * text, images, files, tool calls, and more. It provides a flexible component\n * system for customizing how each content type is rendered.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.Parts\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * tools: {\n * by_name: {\n * calculator: CalculatorTool,\n * weather: WeatherTool,\n * },\n * Fallback: DefaultToolComponent\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveParts: FC<MessagePrimitiveParts.Props> = ({\n components,\n}) => {\n const contentLength = useAssistantState(\n ({ message }) => message.parts.length,\n );\n const messageRanges = useMessagePartsGroups();\n\n const partsElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyParts components={components} />;\n }\n\n return messageRanges.map((range) => {\n if (range.type === \"single\") {\n return (\n <MessagePrimitivePartByIndex\n key={range.index}\n index={range.index}\n components={components}\n />\n );\n } else if (range.type === \"toolGroup\") {\n const ToolGroupComponent =\n components!.ToolGroup ?? defaultComponents.ToolGroup;\n return (\n <ToolGroupComponent\n key={`tool-${range.startIndex}`}\n startIndex={range.startIndex}\n endIndex={range.endIndex}\n >\n {Array.from(\n { length: range.endIndex - range.startIndex + 1 },\n (_, i) => (\n <MessagePrimitivePartByIndex\n key={i}\n index={range.startIndex + i}\n components={components}\n />\n ),\n )}\n </ToolGroupComponent>\n );\n } else {\n // reasoningGroup\n const ReasoningGroupComponent =\n components!.ReasoningGroup ?? defaultComponents.ReasoningGroup;\n return (\n <ReasoningGroupComponent\n key={`reasoning-${range.startIndex}`}\n startIndex={range.startIndex}\n endIndex={range.endIndex}\n >\n {Array.from(\n { length: range.endIndex - range.startIndex + 1 },\n (_, i) => (\n <MessagePrimitivePartByIndex\n key={i}\n index={range.startIndex + i}\n components={components}\n />\n ),\n )}\n </ReasoningGroupComponent>\n );\n }\n });\n }, [messageRanges, components, contentLength]);\n\n return <>{partsElements}</>;\n};\n\nMessagePrimitiveParts.displayName = \"MessagePrimitive.Parts\";\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAa1C,SAAS,sCAAsC;AAE/C,SAAS,kBAAkB;AAqOlB,SAyQA,UAzQA,KAKL,YALK;AA1NT,IAAM,mBAAmB,CACvB,cACG;AACH,MAAI,QAAQ;AAEZ,SAAO;AAAA,IACL,YAAY,CAAC,UAAkB;AAC7B,UAAI,UAAU,IAAI;AAChB,gBAAQ;AAAA,MACV;AAAA,IACF;AAAA,IACA,UAAU,CAAC,UAAkB,WAA+B;AAC1D,UAAI,UAAU,IAAI;AAChB,eAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,YAAY;AAAA,UACZ;AAAA,QACF,CAAqB;AACrB,gBAAQ;AAAA,MACV;AAAA,IACF;AAAA,IACA,UAAU,CAAC,UAAkB,WAA+B;AAC1D,UAAI,UAAU,IAAI;AAChB,eAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,YAAY;AAAA,UACZ;AAAA,QACF,CAAqB;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;AAMA,IAAM,oBAAoB,CACxB,iBACuB;AACvB,QAAM,SAA6B,CAAC;AACpC,QAAM,YAAY,iBAAiB,WAAW;AAC9C,QAAM,iBAAiB,iBAAiB,gBAAgB;AAExD,WAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,UAAM,OAAO,aAAa,CAAC;AAE3B,QAAI,SAAS,aAAa;AACxB,qBAAe,SAAS,IAAI,GAAG,MAAM;AACrC,gBAAU,WAAW,CAA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AAA,YAEf,gBAAM;AAAA,cACL,EAAE,QAAQ,MAAM,WAAW,MAAM,aAAa,EAAE;AAAA,cAChD,CAAC,GAAG,MACF;AAAA,gBAAC;AAAA;AAAA,kBAEC,OAAO,MAAM,aAAa;AAAA,kBAC1B;AAAA;AAAA,gBAFK;AAAA,cAGP;AAAA,YAEJ;AAAA;AAAA,UAbK,aAAa,MAAM,UAAU;AAAA,QAcpC;AAAA,MAEJ;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,YAAY,aAAa,CAAC;AAE7C,SAAO,gCAAG,yBAAc;AAC1B;AAEA,sBAAsB,cAAc;","names":["Render","part"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/message/MessageParts.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type FC,\n memo,\n PropsWithChildren,\n useMemo,\n} from \"react\";\nimport {\n useAssistantState,\n useAssistantApi,\n PartByIndexProvider,\n TextMessagePartProvider,\n} from \"../../context\";\nimport { MessagePartPrimitiveText } from \"../messagePart/MessagePartText\";\nimport { MessagePartPrimitiveImage } from \"../messagePart/MessagePartImage\";\nimport type {\n Unstable_AudioMessagePartComponent,\n EmptyMessagePartComponent,\n TextMessagePartComponent,\n ImageMessagePartComponent,\n SourceMessagePartComponent,\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n FileMessagePartComponent,\n ReasoningMessagePartComponent,\n ReasoningGroupComponent,\n} from \"../../types/MessagePartComponentTypes\";\nimport { MessagePartPrimitiveInProgress } from \"../messagePart/MessagePartInProgress\";\nimport { MessagePartStatus } from \"../../types/AssistantTypes\";\nimport { useShallow } from \"zustand/shallow\";\n\ntype MessagePartRange =\n | { type: \"single\"; index: number }\n | { type: \"toolGroup\"; startIndex: number; endIndex: number }\n | { type: \"reasoningGroup\"; startIndex: number; endIndex: number };\n\n/**\n * Creates a group state manager for a specific part type.\n * Returns functions to start, end, and finalize groups.\n */\nconst createGroupState = <T extends \"toolGroup\" | \"reasoningGroup\">(\n groupType: T,\n) => {\n let start = -1;\n\n return {\n startGroup: (index: number) => {\n if (start === -1) {\n start = index;\n }\n },\n endGroup: (endIndex: number, ranges: MessagePartRange[]) => {\n if (start !== -1) {\n ranges.push({\n type: groupType,\n startIndex: start,\n endIndex,\n } as MessagePartRange);\n start = -1;\n }\n },\n finalize: (endIndex: number, ranges: MessagePartRange[]) => {\n if (start !== -1) {\n ranges.push({\n type: groupType,\n startIndex: start,\n endIndex,\n } as MessagePartRange);\n }\n },\n };\n};\n\n/**\n * Groups consecutive tool-call and reasoning message parts into ranges.\n * Always groups tool calls and reasoning parts, even if there's only one.\n */\nconst groupMessageParts = (\n messageTypes: readonly string[],\n): MessagePartRange[] => {\n const ranges: MessagePartRange[] = [];\n const toolGroup = createGroupState(\"toolGroup\");\n const reasoningGroup = createGroupState(\"reasoningGroup\");\n\n for (let i = 0; i < messageTypes.length; i++) {\n const type = messageTypes[i];\n\n if (type === \"tool-call\") {\n reasoningGroup.endGroup(i - 1, ranges);\n toolGroup.startGroup(i);\n } else if (type === \"reasoning\") {\n toolGroup.endGroup(i - 1, ranges);\n reasoningGroup.startGroup(i);\n } else {\n toolGroup.endGroup(i - 1, ranges);\n reasoningGroup.endGroup(i - 1, ranges);\n ranges.push({ type: \"single\", index: i });\n }\n }\n\n toolGroup.finalize(messageTypes.length - 1, ranges);\n reasoningGroup.finalize(messageTypes.length - 1, ranges);\n\n return ranges;\n};\n\nconst useMessagePartsGroups = (): MessagePartRange[] => {\n const messageTypes = useAssistantState(\n useShallow((s) => s.message.parts.map((c: any) => c.type)),\n );\n\n return useMemo(() => {\n if (messageTypes.length === 0) {\n return [];\n }\n return groupMessageParts(messageTypes);\n }, [messageTypes]);\n};\n\nexport namespace MessagePrimitiveParts {\n export type Props = {\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 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 consecutive tool calls.\n *\n * When provided, this component will automatically wrap consecutive tool-call\n * message parts, allowing you to create collapsible sections, custom styling,\n * or other grouped presentations for multiple tool calls.\n *\n * The component receives:\n * - `startIndex`: The index of the first tool call in the group\n * - `endIndex`: The index of the last tool call in the group\n * - `children`: The rendered tool call components\n *\n * @example\n * ```tsx\n * // Collapsible tool group\n * ToolGroup: ({ startIndex, endIndex, children }) => (\n * <details className=\"tool-group\">\n * <summary>\n * {endIndex - startIndex + 1} tool calls\n * </summary>\n * <div className=\"tool-group-content\">\n * {children}\n * </div>\n * </details>\n * )\n * ```\n *\n * @example\n * ```tsx\n * // Custom styled tool group with header\n * ToolGroup: ({ startIndex, endIndex, children }) => (\n * <div className=\"border rounded-lg p-4 my-2\">\n * <div className=\"text-sm text-gray-600 mb-2\">\n * Tool execution #{startIndex + 1}-{endIndex + 1}\n * </div>\n * <div className=\"space-y-2\">\n * {children}\n * </div>\n * </div>\n * )\n * ```\n *\n * @param startIndex - Index of the first tool call in the group\n * @param endIndex - Index of the last tool call in the group\n * @param children - Rendered tool call components to display within the group\n *\n * @deprecated This feature is still experimental and subject to change.\n */\n ToolGroup?: ComponentType<\n PropsWithChildren<{ startIndex: number; endIndex: number }>\n >;\n\n /**\n * Component for rendering grouped reasoning parts.\n *\n * When provided, this component will automatically wrap reasoning message parts\n * (one or more consecutive) in a group container. Each reasoning part inside\n * renders its own text independently - no text merging occurs.\n *\n * The component receives:\n * - `startIndex`: The index of the first reasoning part in the group\n * - `endIndex`: The index of the last reasoning part in the group\n * - `children`: The rendered Reasoning components (one per part)\n *\n * @example\n * ```tsx\n * // Collapsible reasoning group\n * ReasoningGroup: ({ children }) => (\n * <details className=\"reasoning-group\">\n * <summary>Reasoning</summary>\n * <div className=\"reasoning-content\">\n * {children}\n * </div>\n * </details>\n * )\n * ```\n *\n * @param startIndex - Index of the first reasoning part in the group\n * @param endIndex - Index of the last reasoning part in the group\n * @param children - Rendered reasoning part components\n */\n ReasoningGroup?: ReasoningGroupComponent;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallMessagePartComponent | undefined;\n} & ToolCallMessagePartProps) => {\n const Render = useAssistantState(({ tools }) => {\n const Render = 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 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 ToolGroup: ({ children }) => children,\n ReasoningGroup: ({ children }) => children,\n} satisfies MessagePrimitiveParts.Props[\"components\"];\n\ntype MessagePartComponentProps = {\n components: MessagePrimitiveParts.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 } = {},\n}) => {\n const api = useAssistantApi();\n const part = useAssistantState(({ part }) => part);\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = api.part().addToolResult;\n const resume = api.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 return null;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown message part type: ${unhandledType}`);\n }\n};\n\nexport namespace MessagePrimitivePartByIndex {\n export type Props = {\n index: number;\n components: MessagePrimitiveParts.Props[\"components\"];\n };\n}\n\n/**\n * Renders a single message part at the specified index.\n *\n * This component provides direct access to render a specific message part\n * within the current message context, using the provided component configuration.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.PartByIndex\n * index={0}\n * components={{\n * Text: MyTextComponent,\n * Image: MyImageComponent\n * }}\n * />\n * ```\n */\nexport const MessagePrimitivePartByIndex: FC<MessagePrimitivePartByIndex.Props> =\n memo(\n ({ index, components }) => {\n return (\n <PartByIndexProvider index={index}>\n <MessagePartComponent components={components} />\n </PartByIndexProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\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?.ToolGroup === next.components?.ToolGroup &&\n prev.components?.ReasoningGroup === next.components?.ReasoningGroup,\n );\n\nMessagePrimitivePartByIndex.displayName = \"MessagePrimitive.PartByIndex\";\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 = useAssistantState(\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 with support for multiple content types.\n *\n * This component automatically handles different types of message content including\n * text, images, files, tool calls, and more. It provides a flexible component\n * system for customizing how each content type is rendered.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.Parts\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * tools: {\n * by_name: {\n * calculator: CalculatorTool,\n * weather: WeatherTool,\n * },\n * Fallback: DefaultToolComponent\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveParts: FC<MessagePrimitiveParts.Props> = ({\n components,\n}) => {\n const contentLength = useAssistantState(\n ({ message }) => message.parts.length,\n );\n const messageRanges = useMessagePartsGroups();\n\n const partsElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyParts components={components} />;\n }\n\n return messageRanges.map((range) => {\n if (range.type === \"single\") {\n return (\n <MessagePrimitivePartByIndex\n key={range.index}\n index={range.index}\n components={components}\n />\n );\n } else if (range.type === \"toolGroup\") {\n const ToolGroupComponent =\n components?.ToolGroup ?? defaultComponents.ToolGroup;\n return (\n <ToolGroupComponent\n key={`tool-${range.startIndex}`}\n startIndex={range.startIndex}\n endIndex={range.endIndex}\n >\n {Array.from(\n { length: range.endIndex - range.startIndex + 1 },\n (_, i) => (\n <MessagePrimitivePartByIndex\n key={i}\n index={range.startIndex + i}\n components={components}\n />\n ),\n )}\n </ToolGroupComponent>\n );\n } else {\n // reasoningGroup\n const ReasoningGroupComponent =\n components?.ReasoningGroup ?? defaultComponents.ReasoningGroup;\n return (\n <ReasoningGroupComponent\n key={`reasoning-${range.startIndex}`}\n startIndex={range.startIndex}\n endIndex={range.endIndex}\n >\n {Array.from(\n { length: range.endIndex - range.startIndex + 1 },\n (_, i) => (\n <MessagePrimitivePartByIndex\n key={i}\n index={range.startIndex + i}\n components={components}\n />\n ),\n )}\n </ReasoningGroupComponent>\n );\n }\n });\n }, [messageRanges, components, contentLength]);\n\n return <>{partsElements}</>;\n};\n\nMessagePrimitiveParts.displayName = \"MessagePrimitive.Parts\";\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAa1C,SAAS,sCAAsC;AAE/C,SAAS,kBAAkB;AAqOlB,SAyQA,UAzQA,KAKL,YALK;AA1NT,IAAM,mBAAmB,CACvB,cACG;AACH,MAAI,QAAQ;AAEZ,SAAO;AAAA,IACL,YAAY,CAAC,UAAkB;AAC7B,UAAI,UAAU,IAAI;AAChB,gBAAQ;AAAA,MACV;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SAAS,UAAU;AAC3B,eACE;AAAA,UAAC;AAAA;AAAA,YAEC,OAAO,MAAM;AAAA,YACb;AAAA;AAAA,UAFK,MAAM;AAAA,QAGb;AAAA,MAEJ,WAAW,MAAM,SAAS,aAAa;AACrC,cAAM,qBACJ,YAAY,aAAa,kBAAkB;AAC7C,eACE;AAAA,UAAC;AAAA;AAAA,YAEC,YAAY,MAAM;AAAA,YAClB,UAAU,MAAM;AAAA,YAEf,gBAAM;AAAA,cACL,EAAE,QAAQ,MAAM,WAAW,MAAM,aAAa,EAAE;AAAA,cAChD,CAAC,GAAG,MACF;AAAA,gBAAC;AAAA;AAAA,kBAEC,OAAO,MAAM,aAAa;AAAA,kBAC1B;AAAA;AAAA,gBAFK;AAAA,cAGP;AAAA,YAEJ;AAAA;AAAA,UAbK,QAAQ,MAAM,UAAU;AAAA,QAc/B;AAAA,MAEJ,OAAO;AAEL,cAAM,0BACJ,YAAY,kBAAkB,kBAAkB;AAClD,eACE;AAAA,UAAC;AAAA;AAAA,YAEC,YAAY,MAAM;AAAA,YAClB,UAAU,MAAM;AAAA,YAEf,gBAAM;AAAA,cACL,EAAE,QAAQ,MAAM,WAAW,MAAM,aAAa,EAAE;AAAA,cAChD,CAAC,GAAG,MACF;AAAA,gBAAC;AAAA;AAAA,kBAEC,OAAO,MAAM,aAAa;AAAA,kBAC1B;AAAA;AAAA,gBAFK;AAAA,cAGP;AAAA,YAEJ;AAAA;AAAA,UAbK,aAAa,MAAM,UAAU;AAAA,QAcpC;AAAA,MAEJ;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,YAAY,aAAa,CAAC;AAE7C,SAAO,gCAAG,yBAAc;AAC1B;AAEA,sBAAsB,cAAc;","names":["Render","part"]}
|
|
@@ -9,6 +9,9 @@ type UseThreadIfProps = RequireAtLeastOne<ThreadIfFilters>;
|
|
|
9
9
|
export declare namespace ThreadPrimitiveIf {
|
|
10
10
|
type Props = PropsWithChildren<UseThreadIfProps>;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use `<AssistantIf condition={({ thread }) => ...} />` instead.
|
|
14
|
+
*/
|
|
12
15
|
export declare const ThreadPrimitiveIf: FC<ThreadPrimitiveIf.Props>;
|
|
13
16
|
export {};
|
|
14
17
|
//# sourceMappingURL=ThreadIf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThreadIf.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/ThreadIf.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF,KAAK,gBAAgB,GAAG,iBAAiB,CAAC,eAAe,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ThreadIf.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/ThreadIf.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF,KAAK,gBAAgB,GAAG,iBAAiB,CAAC,eAAe,CAAC,CAAC;AAgB3D,yBAAiB,iBAAiB,CAAC;IACjC,KAAY,KAAK,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;CACzD;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAMzD,CAAC"}
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
import { useAssistantState } from "../../context/index.js";
|
|
5
5
|
var useThreadIf = (props) => {
|
|
6
6
|
return useAssistantState(({ thread }) => {
|
|
7
|
-
|
|
8
|
-
if (props.empty ===
|
|
9
|
-
if (props.empty === false && isEmpty) return false;
|
|
7
|
+
if (props.empty === true && !thread.isEmpty) return false;
|
|
8
|
+
if (props.empty === false && thread.isEmpty) return false;
|
|
10
9
|
if (props.running === true && !thread.isRunning) return false;
|
|
11
10
|
if (props.running === false && thread.isRunning) return false;
|
|
12
11
|
if (props.disabled === true && !thread.isDisabled) return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/thread/ThreadIf.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useAssistantState } from \"../../context\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype ThreadIfFilters = {\n empty: boolean | undefined;\n running: boolean | undefined;\n disabled: boolean | undefined;\n};\n\ntype UseThreadIfProps = RequireAtLeastOne<ThreadIfFilters>;\n\nconst useThreadIf = (props: UseThreadIfProps) => {\n return useAssistantState(({ thread }) => {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/thread/ThreadIf.tsx"],"sourcesContent":["\"use client\";\n\nimport type { FC, PropsWithChildren } from \"react\";\nimport { useAssistantState } from \"../../context\";\nimport type { RequireAtLeastOne } from \"../../utils/RequireAtLeastOne\";\n\ntype ThreadIfFilters = {\n empty: boolean | undefined;\n running: boolean | undefined;\n disabled: boolean | undefined;\n};\n\ntype UseThreadIfProps = RequireAtLeastOne<ThreadIfFilters>;\n\nconst useThreadIf = (props: UseThreadIfProps) => {\n return useAssistantState(({ thread }) => {\n if (props.empty === true && !thread.isEmpty) return false;\n if (props.empty === false && thread.isEmpty) return false;\n\n if (props.running === true && !thread.isRunning) return false;\n if (props.running === false && thread.isRunning) return false;\n if (props.disabled === true && !thread.isDisabled) return false;\n if (props.disabled === false && thread.isDisabled) return false;\n\n return true;\n });\n};\n\nexport namespace ThreadPrimitiveIf {\n export type Props = PropsWithChildren<UseThreadIfProps>;\n}\n\n/**\n * @deprecated Use `<AssistantIf condition={({ thread }) => ...} />` instead.\n */\nexport const ThreadPrimitiveIf: FC<ThreadPrimitiveIf.Props> = ({\n children,\n ...query\n}) => {\n const result = useThreadIf(query);\n return result ? children : null;\n};\n\nThreadPrimitiveIf.displayName = \"ThreadPrimitive.If\";\n"],"mappings":";;;AAGA,SAAS,yBAAyB;AAWlC,IAAM,cAAc,CAAC,UAA4B;AAC/C,SAAO,kBAAkB,CAAC,EAAE,OAAO,MAAM;AACvC,QAAI,MAAM,UAAU,QAAQ,CAAC,OAAO,QAAS,QAAO;AACpD,QAAI,MAAM,UAAU,SAAS,OAAO,QAAS,QAAO;AAEpD,QAAI,MAAM,YAAY,QAAQ,CAAC,OAAO,UAAW,QAAO;AACxD,QAAI,MAAM,YAAY,SAAS,OAAO,UAAW,QAAO;AACxD,QAAI,MAAM,aAAa,QAAQ,CAAC,OAAO,WAAY,QAAO;AAC1D,QAAI,MAAM,aAAa,SAAS,OAAO,WAAY,QAAO;AAE1D,WAAO;AAAA,EACT,CAAC;AACH;AASO,IAAM,oBAAiD,CAAC;AAAA,EAC7D;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,SAAS,YAAY,KAAK;AAChC,SAAO,SAAS,WAAW;AAC7B;AAEA,kBAAkB,cAAc;","names":[]}
|
package/dist/tests/setup.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
// ../../node_modules/.pnpm/vitest@4.0.
|
|
1
|
+
// ../../node_modules/.pnpm/vitest@4.0.15_@opentelemetry+api@1.9.0_@types+node@24.10.1_@vitest+ui@4.0.15_jiti@2.6.1_1316c7438d8db3eab2efa08f08502397/node_modules/vitest/dist/chunks/vi.2VT5v0um.js
|
|
2
2
|
import { chai, equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from "@vitest/expect.js";
|
|
3
3
|
import { getCurrentTest } from "@vitest/runner.js";
|
|
4
|
-
import { getNames, getTestName } from "@vitest/runner/utils.js";
|
|
5
4
|
|
|
6
|
-
// ../../node_modules/.pnpm/vitest@4.0.
|
|
5
|
+
// ../../node_modules/.pnpm/vitest@4.0.15_@opentelemetry+api@1.9.0_@types+node@24.10.1_@vitest+ui@4.0.15_jiti@2.6.1_1316c7438d8db3eab2efa08f08502397/node_modules/vitest/dist/chunks/utils.DvEY5TfP.js
|
|
7
6
|
import { getSafeTimers } from "@vitest/utils/timers.js";
|
|
8
7
|
var NAME_WORKER_STATE = "__vitest_worker__";
|
|
9
8
|
function getWorkerState() {
|
|
@@ -44,8 +43,9 @@ async function waitForImportsToResolve() {
|
|
|
44
43
|
await waitForImportsToResolve();
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
// ../../node_modules/.pnpm/vitest@4.0.
|
|
48
|
-
import { getSafeTimers as getSafeTimers2 } from "@vitest/utils/timers.js";
|
|
46
|
+
// ../../node_modules/.pnpm/vitest@4.0.15_@opentelemetry+api@1.9.0_@types+node@24.10.1_@vitest+ui@4.0.15_jiti@2.6.1_1316c7438d8db3eab2efa08f08502397/node_modules/vitest/dist/chunks/vi.2VT5v0um.js
|
|
47
|
+
import { getSafeTimers as getSafeTimers2, delay } from "@vitest/utils/timers.js";
|
|
48
|
+
import { getNames } from "@vitest/runner/utils.js";
|
|
49
49
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from "@vitest/snapshot.js";
|
|
50
50
|
import "@vitest/utils/error.js";
|
|
51
51
|
import { assertTypes, createSimpleStackTrace } from "@vitest/utils/helpers.js";
|
|
@@ -53,10 +53,10 @@ import { fn, spyOn, restoreAllMocks, resetAllMocks, clearAllMocks, isMockFunctio
|
|
|
53
53
|
import "@vitest/utils/offset.js";
|
|
54
54
|
import { parseSingleStack } from "@vitest/utils/source-map.js";
|
|
55
55
|
|
|
56
|
-
// ../../node_modules/.pnpm/vitest@4.0.
|
|
56
|
+
// ../../node_modules/.pnpm/vitest@4.0.15_@opentelemetry+api@1.9.0_@types+node@24.10.1_@vitest+ui@4.0.15_jiti@2.6.1_1316c7438d8db3eab2efa08f08502397/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js
|
|
57
57
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
58
58
|
|
|
59
|
-
// ../../node_modules/.pnpm/vitest@4.0.
|
|
59
|
+
// ../../node_modules/.pnpm/vitest@4.0.15_@opentelemetry+api@1.9.0_@types+node@24.10.1_@vitest+ui@4.0.15_jiti@2.6.1_1316c7438d8db3eab2efa08f08502397/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js
|
|
60
60
|
var RealDate = Date;
|
|
61
61
|
var now = null;
|
|
62
62
|
var MockDate = class _MockDate extends RealDate {
|
|
@@ -104,7 +104,7 @@ function resetDate() {
|
|
|
104
104
|
globalThis.Date = RealDate;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
// ../../node_modules/.pnpm/vitest@4.0.
|
|
107
|
+
// ../../node_modules/.pnpm/vitest@4.0.15_@opentelemetry+api@1.9.0_@types+node@24.10.1_@vitest+ui@4.0.15_jiti@2.6.1_1316c7438d8db3eab2efa08f08502397/node_modules/vitest/dist/chunks/vi.2VT5v0um.js
|
|
108
108
|
var unsupported = [
|
|
109
109
|
"matchSnapshot",
|
|
110
110
|
"toMatchSnapshot",
|
|
@@ -117,6 +117,10 @@ var unsupported = [
|
|
|
117
117
|
"toThrow",
|
|
118
118
|
"toThrowError"
|
|
119
119
|
];
|
|
120
|
+
function throwWithCause(error, source) {
|
|
121
|
+
if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
|
|
122
|
+
throw copyStackTrace$1(error, source);
|
|
123
|
+
}
|
|
120
124
|
function createExpectPoll(expect) {
|
|
121
125
|
return function poll(fn2, options = {}) {
|
|
122
126
|
const defaults = getWorkerState().config.expect?.poll ?? {};
|
|
@@ -132,35 +136,33 @@ function createExpectPoll(expect) {
|
|
|
132
136
|
if (typeof key === "string" && unsupported.includes(key)) throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
|
|
133
137
|
return function(...args) {
|
|
134
138
|
const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
|
|
135
|
-
const promise =
|
|
136
|
-
let intervalId;
|
|
137
|
-
let timeoutId;
|
|
138
|
-
let lastError;
|
|
139
|
+
const promise = async () => {
|
|
139
140
|
const { setTimeout, clearTimeout } = getSafeTimers2();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
chai.util.flag(assertion, "object", obj);
|
|
145
|
-
resolve(await assertionFunction.call(assertion, ...args));
|
|
146
|
-
clearTimeout(intervalId);
|
|
147
|
-
clearTimeout(timeoutId);
|
|
148
|
-
} catch (err) {
|
|
149
|
-
lastError = err;
|
|
150
|
-
if (!chai.util.flag(assertion, "_isLastPollAttempt")) intervalId = setTimeout(check, interval);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
timeoutId = setTimeout(() => {
|
|
154
|
-
clearTimeout(intervalId);
|
|
155
|
-
chai.util.flag(assertion, "_isLastPollAttempt", true);
|
|
156
|
-
const rejectWithCause = (error) => {
|
|
157
|
-
if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
|
|
158
|
-
reject(copyStackTrace$1(error, STACK_TRACE_ERROR));
|
|
159
|
-
};
|
|
160
|
-
check().then(() => rejectWithCause(lastError)).catch((e) => rejectWithCause(e));
|
|
141
|
+
let executionPhase = "fn";
|
|
142
|
+
let hasTimedOut = false;
|
|
143
|
+
const timerId = setTimeout(() => {
|
|
144
|
+
hasTimedOut = true;
|
|
161
145
|
}, timeout);
|
|
162
|
-
|
|
163
|
-
|
|
146
|
+
chai.util.flag(assertion, "_name", key);
|
|
147
|
+
try {
|
|
148
|
+
while (true) {
|
|
149
|
+
const isLastAttempt = hasTimedOut;
|
|
150
|
+
if (isLastAttempt) chai.util.flag(assertion, "_isLastPollAttempt", true);
|
|
151
|
+
try {
|
|
152
|
+
executionPhase = "fn";
|
|
153
|
+
const obj = await fn2();
|
|
154
|
+
chai.util.flag(assertion, "object", obj);
|
|
155
|
+
executionPhase = "assertion";
|
|
156
|
+
return await assertionFunction.call(assertion, ...args);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
if (isLastAttempt || executionPhase === "assertion" && chai.util.flag(assertion, "_poll.assert_once")) throwWithCause(err, STACK_TRACE_ERROR);
|
|
159
|
+
await delay(interval, setTimeout);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} finally {
|
|
163
|
+
clearTimeout(timerId);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
164
166
|
let awaited = false;
|
|
165
167
|
test2.onFinished ??= [];
|
|
166
168
|
test2.onFinished.push(() => {
|
|
@@ -397,7 +399,7 @@ function createExpect(test2) {
|
|
|
397
399
|
get testPath() {
|
|
398
400
|
return getWorkerState().filepath;
|
|
399
401
|
},
|
|
400
|
-
currentTestName: test2 ?
|
|
402
|
+
currentTestName: test2 ? test2.fullTestName ?? "" : globalState.currentTestName
|
|
401
403
|
}, expect);
|
|
402
404
|
expect.assert = chai.assert;
|
|
403
405
|
expect.extend = (matchers) => chai.expect.extend(expect, matchers);
|
|
@@ -2056,7 +2058,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
2056
2058
|
methodName: "setTimeout",
|
|
2057
2059
|
original: timersPromisesModule.setTimeout
|
|
2058
2060
|
});
|
|
2059
|
-
timersPromisesModule.setTimeout = (
|
|
2061
|
+
timersPromisesModule.setTimeout = (delay2, value, options = {}) => new Promise((resolve, reject) => {
|
|
2060
2062
|
const abort = () => {
|
|
2061
2063
|
options.signal.removeEventListener(
|
|
2062
2064
|
"abort",
|
|
@@ -2075,7 +2077,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
2075
2077
|
clock.abortListenerMap.delete(abort);
|
|
2076
2078
|
}
|
|
2077
2079
|
resolve(value);
|
|
2078
|
-
},
|
|
2080
|
+
}, delay2);
|
|
2079
2081
|
if (options.signal) {
|
|
2080
2082
|
if (options.signal.aborted) {
|
|
2081
2083
|
abort();
|
|
@@ -2136,7 +2138,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
2136
2138
|
methodName: "setInterval",
|
|
2137
2139
|
original: timersPromisesModule.setInterval
|
|
2138
2140
|
});
|
|
2139
|
-
timersPromisesModule.setInterval = (
|
|
2141
|
+
timersPromisesModule.setInterval = (delay2, value, options = {}) => ({
|
|
2140
2142
|
[Symbol.asyncIterator]: () => {
|
|
2141
2143
|
const createResolvable = () => {
|
|
2142
2144
|
let resolve, reject;
|
|
@@ -2159,7 +2161,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
|
|
|
2159
2161
|
} else {
|
|
2160
2162
|
nextAvailable++;
|
|
2161
2163
|
}
|
|
2162
|
-
},
|
|
2164
|
+
}, delay2);
|
|
2163
2165
|
const abort = () => {
|
|
2164
2166
|
options.signal.removeEventListener(
|
|
2165
2167
|
"abort",
|
|
@@ -2696,12 +2698,12 @@ function getImporter(name) {
|
|
|
2696
2698
|
}) + 1])?.file || "";
|
|
2697
2699
|
}
|
|
2698
2700
|
|
|
2699
|
-
// ../../node_modules/.pnpm/vitest@4.0.
|
|
2701
|
+
// ../../node_modules/.pnpm/vitest@4.0.15_@opentelemetry+api@1.9.0_@types+node@24.10.1_@vitest+ui@4.0.15_jiti@2.6.1_1316c7438d8db3eab2efa08f08502397/node_modules/vitest/dist/index.js
|
|
2700
2702
|
import { expectTypeOf } from "expect-type.js";
|
|
2701
2703
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, recordArtifact, suite, test } from "@vitest/runner.js";
|
|
2702
2704
|
import { chai as chai2 } from "@vitest/expect.js";
|
|
2703
|
-
import "@vitest/runner/utils.js";
|
|
2704
2705
|
import "@vitest/utils/timers.js";
|
|
2706
|
+
import "@vitest/runner/utils.js";
|
|
2705
2707
|
import "@vitest/snapshot.js";
|
|
2706
2708
|
import "@vitest/utils/error.js";
|
|
2707
2709
|
import "@vitest/utils/helpers.js";
|