@assistant-ui/react 0.7.50 → 0.7.51

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.
@@ -1 +1 @@
1
- {"version":3,"file":"MessageContent.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageContent.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAcnE,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,4BAA4B,EAC5B,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,uCAAuC,CAAC;AAI/C,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,KAAK,GAAG;QAClB,UAAU,CAAC,EACP;YACE,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,cAAc,CAAC,EAAE,kCAAkC,GAAG,SAAS,CAAC;YAChE,EAAE,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAC;YACxC,KAAK,CAAC,EACF;gBACE,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,SAAS,CAAC,GACxD,SAAS,CAAC;gBACd,QAAQ,CAAC,EAAE,aAAa,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;aAChE,GACD;gBACE,QAAQ,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAC;aACnD,GACD,SAAS,CAAC;SACf,GACD,SAAS,CAAC;KACf,CAAC;CACH;AAyID,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,uBAAuB,CAAC,KAAK,CAYrE,CAAC"}
1
+ {"version":3,"file":"MessageContent.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageContent.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAenE,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,4BAA4B,EAC5B,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,uCAAuC,CAAC;AAI/C,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,KAAK,GAAG;QAClB,UAAU,CAAC,EACP;YACE,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,cAAc,CAAC,EAAE,kCAAkC,GAAG,SAAS,CAAC;YAChE,EAAE,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAC;YACxC,KAAK,CAAC,EACF;gBACE,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,SAAS,CAAC,GACxD,SAAS,CAAC;gBACd,QAAQ,CAAC,EAAE,aAAa,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;aAChE,GACD;gBACE,QAAQ,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAC;aACnD,GACD,SAAS,CAAC;SACf,GACD,SAAS,CAAC;KACf,CAAC;CACH;AAyJD,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,uBAAuB,CAAC,KAAK,CAYrE,CAAC"}
@@ -107,12 +107,21 @@ var MessageContentPart = (0, import_react.memo)(
107
107
  var COMPLETE_STATUS = Object.freeze({
108
108
  type: "complete"
109
109
  });
110
+ var EmptyContentFallback = ({ status, component: Component }) => {
111
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.TextContentPartProvider, { text: "", isRunning: status.type === "running", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { type: "text", text: "", status }) });
112
+ };
110
113
  var EmptyContentImpl = ({
111
114
  components
112
115
  }) => {
113
116
  const status = (0, import_MessageContext.useMessage)((s) => s.status) ?? COMPLETE_STATUS;
114
- const Component = components?.Empty ?? components?.Text ?? defaultComponents.Text;
115
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { type: "text", text: "", status });
117
+ if (components?.Empty) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(components.Empty, { status });
118
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
119
+ EmptyContentFallback,
120
+ {
121
+ status,
122
+ component: components?.Text ?? defaultComponents.Text
123
+ }
124
+ );
116
125
  };
117
126
  var EmptyContent = (0, import_react.memo)(
118
127
  EmptyContentImpl,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/message/MessageContent.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ComponentType, type FC, memo, useMemo } from \"react\";\nimport {\n useContentPart,\n useContentPartRuntime,\n useToolUIs,\n} from \"../../context\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { ContentPartRuntimeProvider } from \"../../context/providers/ContentPartRuntimeProvider\";\nimport { ContentPartPrimitiveText } from \"../contentPart/ContentPartText\";\nimport { ContentPartPrimitiveImage } from \"../contentPart/ContentPartImage\";\nimport { ContentPartPrimitiveDisplay } from \"../contentPart/ContentPartDisplay\";\nimport type {\n Unstable_AudioContentPartComponent,\n EmptyContentPartComponent,\n ImageContentPartComponent,\n TextContentPartComponent,\n ToolCallContentPartComponent,\n ToolCallContentPartProps,\n UIContentPartComponent,\n FileContentPartComponent,\n} from \"../../types/ContentPartComponentTypes\";\nimport { ContentPartPrimitiveInProgress } from \"../contentPart/ContentPartInProgress\";\nimport { ContentPartStatus } from \"../../types/AssistantTypes\";\n\nexport namespace MessagePrimitiveContent {\n export type Props = {\n components?:\n | {\n Empty?: EmptyContentPartComponent | undefined;\n Text?: TextContentPartComponent | undefined;\n Image?: ImageContentPartComponent | undefined;\n File?: FileContentPartComponent | undefined;\n Unstable_Audio?: Unstable_AudioContentPartComponent | undefined;\n UI?: UIContentPartComponent | undefined;\n tools?:\n | {\n by_name?:\n | Record<string, ToolCallContentPartComponent | undefined>\n | undefined;\n Fallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | {\n Override: ComponentType<ToolCallContentPartProps>;\n }\n | undefined;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallContentPartComponent | undefined;\n} & ToolCallContentPartProps) => {\n const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? Fallback;\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <ContentPartPrimitiveText />\n <ContentPartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </ContentPartPrimitiveInProgress>\n </p>\n ),\n Image: () => <ContentPartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n UI: () => <ContentPartPrimitiveDisplay />,\n} satisfies MessagePrimitiveContent.Props[\"components\"];\n\ntype MessageContentPartComponentProps = {\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartComponent: FC<MessageContentPartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Image = defaultComponents.Image,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n UI = defaultComponents.UI,\n tools = {},\n } = {},\n}) => {\n const contentPartRuntime = useContentPartRuntime();\n\n const part = useContentPart();\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = (result: any) => contentPartRuntime.addToolResult(result);\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return <ToolUIDisplay {...part} Fallback={Tool} addResult={addResult} />;\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 \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n case \"ui\":\n return <UI {...part} />;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n};\n\ntype MessageContentPartProps = {\n partIndex: number;\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartImpl: FC<MessageContentPartProps> = ({\n partIndex,\n components,\n}) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getContentPartByIndex(partIndex),\n [messageRuntime, partIndex],\n );\n\n return (\n <ContentPartRuntimeProvider runtime={runtime}>\n <MessageContentPartComponent components={components} />\n </ContentPartRuntimeProvider>\n );\n};\n\nconst MessageContentPart = memo(\n MessageContentPartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\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?.UI === next.components?.UI &&\n prev.components?.tools === next.components?.tools,\n);\n\nconst COMPLETE_STATUS: ContentPartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyContentImpl: FC<MessageContentPartComponentProps> = ({\n components,\n}) => {\n const status =\n useMessage((s) => s.status as ContentPartStatus) ?? COMPLETE_STATUS;\n\n const Component =\n components?.Empty ?? components?.Text ?? defaultComponents.Text;\n return <Component type=\"text\" text=\"\" status={status} />;\n};\n\nconst EmptyContent = memo(\n EmptyContentImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\nexport const MessagePrimitiveContent: FC<MessagePrimitiveContent.Props> = ({\n components,\n}) => {\n const contentLength = useMessage((s) => s.content.length);\n\n if (contentLength === 0) {\n return <EmptyContent components={components} />;\n }\n\n return Array.from({ length: contentLength }, (_, index) => (\n <MessageContentPart key={index} partIndex={index} components={components} />\n ));\n};\n\nMessagePrimitiveContent.displayName = \"MessagePrimitive.Content\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA2D;AAC3D,qBAIO;AACP,4BAGO;AACP,wCAA2C;AAC3C,6BAAyC;AACzC,8BAA0C;AAC1C,gCAA4C;AAW5C,mCAA+C;AAqCtC;AART,IAAM,gBAAgB,CAAC;AAAA,EACrB;AAAA,EACA,GAAG;AACL,MAEiC;AAC/B,QAAM,aAAS,2BAAW,CAAC,MAAM,EAAE,UAAU,MAAM,QAAQ,CAAC,KAAK;AACjE,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,4CAAC,UAAQ,GAAG,OAAO;AAC5B;AAEA,IAAM,oBAAoB;AAAA,EACxB,MAAM,MACJ,6CAAC,OAAE,OAAO,EAAE,YAAY,WAAW,GACjC;AAAA,gDAAC,mDAAyB;AAAA,IAC1B,4CAAC,+DACC,sDAAC,UAAK,OAAO,EAAE,YAAY,SAAS,GAAI,qBAAU,GACpD;AAAA,KACF;AAAA,EAEF,OAAO,MAAM,4CAAC,qDAA0B;AAAA,EACxC,MAAM,MAAM;AAAA,EACZ,gBAAgB,MAAM;AAAA,EACtB,IAAI,MAAM,4CAAC,yDAA4B;AACzC;AAMA,IAAM,8BAAoE,CAAC;AAAA,EACzE,YAAY;AAAA,IACV,OAAO,kBAAkB;AAAA,IACzB,QAAQ,kBAAkB;AAAA,IAC1B,OAAO,kBAAkB;AAAA,IACzB,gBAAgB,QAAQ,kBAAkB;AAAA,IAC1C,KAAK,kBAAkB;AAAA,IACvB,QAAQ,CAAC;AAAA,EACX,IAAI,C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AK,YAAY,SAC5C,KAAK,YAAY,SAAS,KAAK,YAAY,QAC3C,KAAK,YAAY,mBAAmB,KAAK,YAAY,kBACrD,KAAK,YAAY,OAAO,KAAK,YAAY,MACzC,KAAK,YAAY,UAAU,KAAK,YAAY;AAChD;AAEA,IAAM,kBAAqC,OAAO,OAAO;AAAA,EACvD,MAAM;AACR,CAAC;AAED,IAAM,mBAAyD,CAAC;AAAA,EAC9D;AACF,MAAM;AACJ,QAAM,aACJ,kCAAW,CAAC,MAAM,EAAE,MAA2B,KAAK;AAEtD,QAAM,YACJ,YAAY,SAAS,YAAY,QAAQ,kBAAkB;AAC7D,SAAO,4CAAC,aAAU,MAAK,QAAO,MAAK,IAAG,QAAgB;AACxD;AAEA,IAAM,mBAAe;AAAA,EACnB;AAAA,EACA,CAAC,MAAM,SACL,KAAK,YAAY,UAAU,KAAK,YAAY,SAC5C,KAAK,YAAY,SAAS,KAAK,YAAY;AAC/C;AAEO,IAAM,0BAA6D,CAAC;AAAA,EACzE;AACF,MAAM;AACJ,QAAM,oBAAgB,kCAAW,CAAC,MAAM,EAAE,QAAQ,MAAM;AAExD,MAAI,kBAAkB,GAAG;AACvB,WAAO,4CAAC,gBAAa,YAAwB;AAAA,EAC/C;AAEA,SAAO,MAAM,KAAK,EAAE,QAAQ,cAAc,GAAG,CAAC,GAAG,UAC/C,4CAAC,sBAA+B,WAAW,OAAO,cAAzB,KAAiD,CAC3E;AACH;AAEA,wBAAwB,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/message/MessageContent.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ComponentType, type FC, memo, useMemo } from \"react\";\nimport {\n TextContentPartProvider,\n useContentPart,\n useContentPartRuntime,\n useToolUIs,\n} from \"../../context\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { ContentPartRuntimeProvider } from \"../../context/providers/ContentPartRuntimeProvider\";\nimport { ContentPartPrimitiveText } from \"../contentPart/ContentPartText\";\nimport { ContentPartPrimitiveImage } from \"../contentPart/ContentPartImage\";\nimport { ContentPartPrimitiveDisplay } from \"../contentPart/ContentPartDisplay\";\nimport type {\n Unstable_AudioContentPartComponent,\n EmptyContentPartComponent,\n ImageContentPartComponent,\n TextContentPartComponent,\n ToolCallContentPartComponent,\n ToolCallContentPartProps,\n UIContentPartComponent,\n FileContentPartComponent,\n} from \"../../types/ContentPartComponentTypes\";\nimport { ContentPartPrimitiveInProgress } from \"../contentPart/ContentPartInProgress\";\nimport { ContentPartStatus } from \"../../types/AssistantTypes\";\n\nexport namespace MessagePrimitiveContent {\n export type Props = {\n components?:\n | {\n Empty?: EmptyContentPartComponent | undefined;\n Text?: TextContentPartComponent | undefined;\n Image?: ImageContentPartComponent | undefined;\n File?: FileContentPartComponent | undefined;\n Unstable_Audio?: Unstable_AudioContentPartComponent | undefined;\n UI?: UIContentPartComponent | undefined;\n tools?:\n | {\n by_name?:\n | Record<string, ToolCallContentPartComponent | undefined>\n | undefined;\n Fallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | {\n Override: ComponentType<ToolCallContentPartProps>;\n }\n | undefined;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallContentPartComponent | undefined;\n} & ToolCallContentPartProps) => {\n const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? Fallback;\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <ContentPartPrimitiveText />\n <ContentPartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </ContentPartPrimitiveInProgress>\n </p>\n ),\n Image: () => <ContentPartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n UI: () => <ContentPartPrimitiveDisplay />,\n} satisfies MessagePrimitiveContent.Props[\"components\"];\n\ntype MessageContentPartComponentProps = {\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartComponent: FC<MessageContentPartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Image = defaultComponents.Image,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n UI = defaultComponents.UI,\n tools = {},\n } = {},\n}) => {\n const contentPartRuntime = useContentPartRuntime();\n\n const part = useContentPart();\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = (result: any) => contentPartRuntime.addToolResult(result);\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return <ToolUIDisplay {...part} Fallback={Tool} addResult={addResult} />;\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 \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n case \"ui\":\n return <UI {...part} />;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n};\n\ntype MessageContentPartProps = {\n partIndex: number;\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartImpl: FC<MessageContentPartProps> = ({\n partIndex,\n components,\n}) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getContentPartByIndex(partIndex),\n [messageRuntime, partIndex],\n );\n\n return (\n <ContentPartRuntimeProvider runtime={runtime}>\n <MessageContentPartComponent components={components} />\n </ContentPartRuntimeProvider>\n );\n};\n\nconst MessageContentPart = memo(\n MessageContentPartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\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?.UI === next.components?.UI &&\n prev.components?.tools === next.components?.tools,\n);\n\nconst COMPLETE_STATUS: ContentPartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyContentFallback: FC<{\n status: ContentPartStatus;\n component: TextContentPartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextContentPartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextContentPartProvider>\n );\n};\n\nconst EmptyContentImpl: FC<MessageContentPartComponentProps> = ({\n components,\n}) => {\n const status =\n useMessage((s) => s.status as ContentPartStatus) ?? COMPLETE_STATUS;\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyContentFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyContent = memo(\n EmptyContentImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\nexport const MessagePrimitiveContent: FC<MessagePrimitiveContent.Props> = ({\n components,\n}) => {\n const contentLength = useMessage((s) => s.content.length);\n\n if (contentLength === 0) {\n return <EmptyContent components={components} />;\n }\n\n return Array.from({ length: contentLength }, (_, index) => (\n <MessageContentPart key={index} partIndex={index} components={components} />\n ));\n};\n\nMessagePrimitiveContent.displayName = \"MessagePrimitive.Content\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA2D;AAC3D,qBAKO;AACP,4BAGO;AACP,wCAA2C;AAC3C,6BAAyC;AACzC,8BAA0C;AAC1C,gCAA4C;AAW5C,mCAA+C;AAqCtC;AART,IAAM,gBAAgB,CAAC;AAAA,EACrB;AAAA,EACA,GAAG;AACL,MAEiC;AAC/B,QAAM,aAAS,2BAAW,CAAC,MAAM,EAAE,UAAU,MAAM,QAAQ,CAAC,KAAK;AACjE,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,4CAAC,UAAQ,GAAG,OAAO;AAC5B;AAEA,IAAM,oBAAoB;AAAA,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IAAM,mBAAe;AAAA,EACnB;AAAA,EACA,CAAC,MAAM,SACL,KAAK,YAAY,UAAU,KAAK,YAAY,SAC5C,KAAK,YAAY,SAAS,KAAK,YAAY;AAC/C;AAEO,IAAM,0BAA6D,CAAC;AAAA,EACzE;AACF,MAAM;AACJ,QAAM,oBAAgB,kCAAW,CAAC,MAAM,EAAE,QAAQ,MAAM;AAExD,MAAI,kBAAkB,GAAG;AACvB,WAAO,4CAAC,gBAAa,YAAwB;AAAA,EAC/C;AAEA,SAAO,MAAM,KAAK,EAAE,QAAQ,cAAc,GAAG,CAAC,GAAG,UAC/C,4CAAC,sBAA+B,WAAW,OAAO,cAAzB,KAAiD,CAC3E;AACH;AAEA,wBAAwB,cAAc;","names":[]}
@@ -3,6 +3,7 @@
3
3
  // src/primitives/message/MessageContent.tsx
4
4
  import { memo, useMemo } from "react";
5
5
  import {
6
+ TextContentPartProvider,
6
7
  useContentPart,
7
8
  useContentPartRuntime,
8
9
  useToolUIs
@@ -91,12 +92,21 @@ var MessageContentPart = memo(
91
92
  var COMPLETE_STATUS = Object.freeze({
92
93
  type: "complete"
93
94
  });
95
+ var EmptyContentFallback = ({ status, component: Component }) => {
96
+ return /* @__PURE__ */ jsx(TextContentPartProvider, { text: "", isRunning: status.type === "running", children: /* @__PURE__ */ jsx(Component, { type: "text", text: "", status }) });
97
+ };
94
98
  var EmptyContentImpl = ({
95
99
  components
96
100
  }) => {
97
101
  const status = useMessage((s) => s.status) ?? COMPLETE_STATUS;
98
- const Component = components?.Empty ?? components?.Text ?? defaultComponents.Text;
99
- return /* @__PURE__ */ jsx(Component, { type: "text", text: "", status });
102
+ if (components?.Empty) return /* @__PURE__ */ jsx(components.Empty, { status });
103
+ return /* @__PURE__ */ jsx(
104
+ EmptyContentFallback,
105
+ {
106
+ status,
107
+ component: components?.Text ?? defaultComponents.Text
108
+ }
109
+ );
100
110
  };
101
111
  var EmptyContent = memo(
102
112
  EmptyContentImpl,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/message/MessageContent.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ComponentType, type FC, memo, useMemo } from \"react\";\nimport {\n useContentPart,\n useContentPartRuntime,\n useToolUIs,\n} from \"../../context\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { ContentPartRuntimeProvider } from \"../../context/providers/ContentPartRuntimeProvider\";\nimport { ContentPartPrimitiveText } from \"../contentPart/ContentPartText\";\nimport { ContentPartPrimitiveImage } from \"../contentPart/ContentPartImage\";\nimport { ContentPartPrimitiveDisplay } from \"../contentPart/ContentPartDisplay\";\nimport type {\n Unstable_AudioContentPartComponent,\n EmptyContentPartComponent,\n ImageContentPartComponent,\n TextContentPartComponent,\n ToolCallContentPartComponent,\n ToolCallContentPartProps,\n UIContentPartComponent,\n FileContentPartComponent,\n} from \"../../types/ContentPartComponentTypes\";\nimport { ContentPartPrimitiveInProgress } from \"../contentPart/ContentPartInProgress\";\nimport { ContentPartStatus } from \"../../types/AssistantTypes\";\n\nexport namespace MessagePrimitiveContent {\n export type Props = {\n components?:\n | {\n Empty?: EmptyContentPartComponent | undefined;\n Text?: TextContentPartComponent | undefined;\n Image?: ImageContentPartComponent | undefined;\n File?: FileContentPartComponent | undefined;\n Unstable_Audio?: Unstable_AudioContentPartComponent | undefined;\n UI?: UIContentPartComponent | undefined;\n tools?:\n | {\n by_name?:\n | Record<string, ToolCallContentPartComponent | undefined>\n | undefined;\n Fallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | {\n Override: ComponentType<ToolCallContentPartProps>;\n }\n | undefined;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallContentPartComponent | undefined;\n} & ToolCallContentPartProps) => {\n const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? Fallback;\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <ContentPartPrimitiveText />\n <ContentPartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </ContentPartPrimitiveInProgress>\n </p>\n ),\n Image: () => <ContentPartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n UI: () => <ContentPartPrimitiveDisplay />,\n} satisfies MessagePrimitiveContent.Props[\"components\"];\n\ntype MessageContentPartComponentProps = {\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartComponent: FC<MessageContentPartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Image = defaultComponents.Image,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n UI = defaultComponents.UI,\n tools = {},\n } = {},\n}) => {\n const contentPartRuntime = useContentPartRuntime();\n\n const part = useContentPart();\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = (result: any) => contentPartRuntime.addToolResult(result);\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return <ToolUIDisplay {...part} Fallback={Tool} addResult={addResult} />;\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 \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n case \"ui\":\n return <UI {...part} />;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n};\n\ntype MessageContentPartProps = {\n partIndex: number;\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartImpl: FC<MessageContentPartProps> = ({\n partIndex,\n components,\n}) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getContentPartByIndex(partIndex),\n [messageRuntime, partIndex],\n );\n\n return (\n <ContentPartRuntimeProvider runtime={runtime}>\n <MessageContentPartComponent components={components} />\n </ContentPartRuntimeProvider>\n );\n};\n\nconst MessageContentPart = memo(\n MessageContentPartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\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?.UI === next.components?.UI &&\n prev.components?.tools === next.components?.tools,\n);\n\nconst COMPLETE_STATUS: ContentPartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyContentImpl: FC<MessageContentPartComponentProps> = ({\n components,\n}) => {\n const status =\n useMessage((s) => s.status as ContentPartStatus) ?? COMPLETE_STATUS;\n\n const Component =\n components?.Empty ?? components?.Text ?? defaultComponents.Text;\n return <Component type=\"text\" text=\"\" status={status} />;\n};\n\nconst EmptyContent = memo(\n EmptyContentImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\nexport const MessagePrimitiveContent: FC<MessagePrimitiveContent.Props> = ({\n components,\n}) => {\n const contentLength = useMessage((s) => s.content.length);\n\n if (contentLength === 0) {\n return <EmptyContent components={components} />;\n }\n\n return Array.from({ length: contentLength }, (_, index) => (\n <MessageContentPart key={index} partIndex={index} components={components} />\n ));\n};\n\nMessagePrimitiveContent.displayName = \"MessagePrimitive.Content\";\n"],"mappings":";;;AAEA,SAAsC,MAAM,eAAe;AAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAC1C,SAAS,mCAAmC;AAW5C,SAAS,sCAAsC;AAqCtC,cAKL,YALK;AART,IAAM,gBAAgB,CAAC;AAAA,EACrB;AAAA,EACA,GAAG;AACL,MAEiC;AAC/B,QAAM,SAAS,WAA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AY,SAC5C,KAAK,YAAY,SAAS,KAAK,YAAY;AAC/C;AAEO,IAAM,0BAA6D,CAAC;AAAA,EACzE;AACF,MAAM;AACJ,QAAM,gBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,MAAM;AAExD,MAAI,kBAAkB,GAAG;AACvB,WAAO,oBAAC,gBAAa,YAAwB;AAAA,EAC/C;AAEA,SAAO,MAAM,KAAK,EAAE,QAAQ,cAAc,GAAG,CAAC,GAAG,UAC/C,oBAAC,sBAA+B,WAAW,OAAO,cAAzB,KAAiD,CAC3E;AACH;AAEA,wBAAwB,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/message/MessageContent.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ComponentType, type FC, memo, useMemo } from \"react\";\nimport {\n TextContentPartProvider,\n useContentPart,\n useContentPartRuntime,\n useToolUIs,\n} from \"../../context\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { ContentPartRuntimeProvider } from \"../../context/providers/ContentPartRuntimeProvider\";\nimport { ContentPartPrimitiveText } from \"../contentPart/ContentPartText\";\nimport { ContentPartPrimitiveImage } from \"../contentPart/ContentPartImage\";\nimport { ContentPartPrimitiveDisplay } from \"../contentPart/ContentPartDisplay\";\nimport type {\n Unstable_AudioContentPartComponent,\n EmptyContentPartComponent,\n ImageContentPartComponent,\n TextContentPartComponent,\n ToolCallContentPartComponent,\n ToolCallContentPartProps,\n UIContentPartComponent,\n FileContentPartComponent,\n} from \"../../types/ContentPartComponentTypes\";\nimport { ContentPartPrimitiveInProgress } from \"../contentPart/ContentPartInProgress\";\nimport { ContentPartStatus } from \"../../types/AssistantTypes\";\n\nexport namespace MessagePrimitiveContent {\n export type Props = {\n components?:\n | {\n Empty?: EmptyContentPartComponent | undefined;\n Text?: TextContentPartComponent | undefined;\n Image?: ImageContentPartComponent | undefined;\n File?: FileContentPartComponent | undefined;\n Unstable_Audio?: Unstable_AudioContentPartComponent | undefined;\n UI?: UIContentPartComponent | undefined;\n tools?:\n | {\n by_name?:\n | Record<string, ToolCallContentPartComponent | undefined>\n | undefined;\n Fallback?: ComponentType<ToolCallContentPartProps> | undefined;\n }\n | {\n Override: ComponentType<ToolCallContentPartProps>;\n }\n | undefined;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallContentPartComponent | undefined;\n} & ToolCallContentPartProps) => {\n const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? Fallback;\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <ContentPartPrimitiveText />\n <ContentPartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </ContentPartPrimitiveInProgress>\n </p>\n ),\n Image: () => <ContentPartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n UI: () => <ContentPartPrimitiveDisplay />,\n} satisfies MessagePrimitiveContent.Props[\"components\"];\n\ntype MessageContentPartComponentProps = {\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartComponent: FC<MessageContentPartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Image = defaultComponents.Image,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n UI = defaultComponents.UI,\n tools = {},\n } = {},\n}) => {\n const contentPartRuntime = useContentPartRuntime();\n\n const part = useContentPart();\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = (result: any) => contentPartRuntime.addToolResult(result);\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return <ToolUIDisplay {...part} Fallback={Tool} addResult={addResult} />;\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 \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n case \"ui\":\n return <UI {...part} />;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown content part type: ${unhandledType}`);\n }\n};\n\ntype MessageContentPartProps = {\n partIndex: number;\n components: MessagePrimitiveContent.Props[\"components\"];\n};\n\nconst MessageContentPartImpl: FC<MessageContentPartProps> = ({\n partIndex,\n components,\n}) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getContentPartByIndex(partIndex),\n [messageRuntime, partIndex],\n );\n\n return (\n <ContentPartRuntimeProvider runtime={runtime}>\n <MessageContentPartComponent components={components} />\n </ContentPartRuntimeProvider>\n );\n};\n\nconst MessageContentPart = memo(\n MessageContentPartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\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?.UI === next.components?.UI &&\n prev.components?.tools === next.components?.tools,\n);\n\nconst COMPLETE_STATUS: ContentPartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyContentFallback: FC<{\n status: ContentPartStatus;\n component: TextContentPartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextContentPartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextContentPartProvider>\n );\n};\n\nconst EmptyContentImpl: FC<MessageContentPartComponentProps> = ({\n components,\n}) => {\n const status =\n useMessage((s) => s.status as ContentPartStatus) ?? COMPLETE_STATUS;\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyContentFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyContent = memo(\n EmptyContentImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\nexport const MessagePrimitiveContent: FC<MessagePrimitiveContent.Props> = ({\n components,\n}) => {\n const contentLength = useMessage((s) => s.content.length);\n\n if (contentLength === 0) {\n return <EmptyContent components={components} />;\n }\n\n return Array.from({ length: contentLength }, (_, index) => (\n <MessageContentPart key={index} partIndex={index} components={components} />\n ));\n};\n\nMessagePrimitiveContent.displayName = \"MessagePrimitive.Content\";\n"],"mappings":";;;AAEA,SAAsC,MAAM,eAAe;AAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAC1C,SAAS,mCAAmC;AAW5C,SAAS,sCAAsC;AAqCtC,cAKL,YALK;AART,IAAM,gBAAgB,CAAC;AAAA,EACrB;AAAA,EACA,GAAG;AACL,MAEiC;AAC/B,QAAM,SAAS,WAAW,CAAC,MAAM,EAAE,UAAU,MAAM,QAAQ,CAAC,KAAK;AACjE,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,oBAAC,UAAQ,GAAG,OAAO;AAC5B;AAEA,IAAM,oBAAoB;AAAA,EACxB,MAAM,MACJ,qBAAC,OAAE,OAAO,EAAE,YAAY,WAAW,GACjC;AAAA,wBAAC,4BAAyB;AAAA,IAC1B,oBAAC,kCACC,8BAAC,UAAK,OAAO,EAAE,YAAY,SAAS,GAAI,qBAAU,GACpD;AAAA,KACF;AAAA,EAEF,OAAO,MAAM,oBAAC,6BAA0B;AAAA,EACxC,MAAM,MAAM;AAAA,EACZ,gBAAgB,MAAM;AAAA,EACtB,IAAI,MAAM,oBAAC,+BAA4B;AACzC;AAMA,IAAM,8BAAoE,CAAC;AAAA,EACzE,YAAY;AAAA,IACV,OAAO,kBAAkB;AAAA,IACzB,QAAQ,kBAAkB;AAAA,IAC1B,OAAO,kBAAkB;AAAA,IACzB,gBAAgB,QAAQ,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GED
@@ -29,7 +29,7 @@
29
29
  "conversational-ui",
30
30
  "conversational-ai"
31
31
  ],
32
- "version": "0.7.50",
32
+ "version": "0.7.51",
33
33
  "license": "MIT",
34
34
  "exports": {
35
35
  ".": {
@@ -117,9 +117,9 @@
117
117
  "tailwindcss": "^3.4.17",
118
118
  "tailwindcss-animate": "^1.0.7",
119
119
  "tsx": "^4.19.2",
120
+ "@assistant-ui/tsbuildutils": "^0.0.1",
120
121
  "@assistant-ui/tailwindcss-transformer": "0.1.0",
121
- "@assistant-ui/tsconfig": "0.0.0",
122
- "@assistant-ui/tsbuildutils": "^0.0.1"
122
+ "@assistant-ui/tsconfig": "0.0.0"
123
123
  },
124
124
  "publishConfig": {
125
125
  "access": "public",
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { type ComponentType, type FC, memo, useMemo } from "react";
4
4
  import {
5
+ TextContentPartProvider,
5
6
  useContentPart,
6
7
  useContentPartRuntime,
7
8
  useToolUIs,
@@ -170,15 +171,31 @@ const COMPLETE_STATUS: ContentPartStatus = Object.freeze({
170
171
  type: "complete",
171
172
  });
172
173
 
174
+ const EmptyContentFallback: FC<{
175
+ status: ContentPartStatus;
176
+ component: TextContentPartComponent;
177
+ }> = ({ status, component: Component }) => {
178
+ return (
179
+ <TextContentPartProvider text="" isRunning={status.type === "running"}>
180
+ <Component type="text" text="" status={status} />
181
+ </TextContentPartProvider>
182
+ );
183
+ };
184
+
173
185
  const EmptyContentImpl: FC<MessageContentPartComponentProps> = ({
174
186
  components,
175
187
  }) => {
176
188
  const status =
177
189
  useMessage((s) => s.status as ContentPartStatus) ?? COMPLETE_STATUS;
178
190
 
179
- const Component =
180
- components?.Empty ?? components?.Text ?? defaultComponents.Text;
181
- return <Component type="text" text="" status={status} />;
191
+ if (components?.Empty) return <components.Empty status={status} />;
192
+
193
+ return (
194
+ <EmptyContentFallback
195
+ status={status}
196
+ component={components?.Text ?? defaultComponents.Text}
197
+ />
198
+ );
182
199
  };
183
200
 
184
201
  const EmptyContent = memo(