From 55942d8aef8913a6ef949d2548904f6fc79ff670 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Tue, 1 Oct 2024 11:41:53 -0700 Subject: [PATCH] fix: useContentPartText backwards compat type (#937) --- .changeset/fair-terms-jam.md | 5 ++++ .../contentPart/useContentPartDisplay.tsx | 2 +- .../contentPart/useContentPartImage.tsx | 3 ++- .../contentPart/useContentPartText.tsx | 2 +- packages/react/src/types/AssistantTypes.ts | 23 +++++++++++-------- 5 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 .changeset/fair-terms-jam.md diff --git a/.changeset/fair-terms-jam.md b/.changeset/fair-terms-jam.md new file mode 100644 index 000000000..2d10b4393 --- /dev/null +++ b/.changeset/fair-terms-jam.md @@ -0,0 +1,5 @@ +--- +"@assistant-ui/react": patch +--- + +fix: useContentPartText backwards compat type diff --git a/packages/react/src/primitive-hooks/contentPart/useContentPartDisplay.tsx b/packages/react/src/primitive-hooks/contentPart/useContentPartDisplay.tsx index c7cd8a69c..7ff2acd8f 100644 --- a/packages/react/src/primitive-hooks/contentPart/useContentPartDisplay.tsx +++ b/packages/react/src/primitive-hooks/contentPart/useContentPartDisplay.tsx @@ -9,7 +9,7 @@ export const useContentPartDisplay = () => { "This component can only be used inside ui content parts.", ); - return c as ContentPartState & UIContentPart; + return c as ContentPartState & UIContentPart & { part: UIContentPart }; }); return display; diff --git a/packages/react/src/primitive-hooks/contentPart/useContentPartImage.tsx b/packages/react/src/primitive-hooks/contentPart/useContentPartImage.tsx index c6816539c..775382de7 100644 --- a/packages/react/src/primitive-hooks/contentPart/useContentPartImage.tsx +++ b/packages/react/src/primitive-hooks/contentPart/useContentPartImage.tsx @@ -9,7 +9,8 @@ export const useContentPartImage = () => { "ContentPartImage can only be used inside image content parts.", ); - return c as ContentPartState & ImageContentPart; + return c as ContentPartState & + ImageContentPart & { part: ImageContentPart }; }); return image; diff --git a/packages/react/src/primitive-hooks/contentPart/useContentPartText.tsx b/packages/react/src/primitive-hooks/contentPart/useContentPartText.tsx index 16c2a07af..5631c5c24 100644 --- a/packages/react/src/primitive-hooks/contentPart/useContentPartText.tsx +++ b/packages/react/src/primitive-hooks/contentPart/useContentPartText.tsx @@ -9,7 +9,7 @@ export const useContentPartText = () => { "ContentPartText can only be used inside text content parts.", ); - return c as ContentPartState & TextContentPart; + return c as ContentPartState & TextContentPart & { part: TextContentPart }; }); return text; diff --git a/packages/react/src/types/AssistantTypes.ts b/packages/react/src/types/AssistantTypes.ts index 21eca41f4..8046ac511 100644 --- a/packages/react/src/types/AssistantTypes.ts +++ b/packages/react/src/types/AssistantTypes.ts @@ -108,17 +108,12 @@ export type MessageStatus = export type ThreadSystemMessage = MessageCommonProps & { role: "system"; content: [TextContentPart]; - status?: undefined; - attachments?: undefined; - metadata?: undefined; }; export type ThreadUserMessage = MessageCommonProps & { role: "user"; content: ThreadUserContentPart[]; attachments: readonly CompleteAttachment[]; - status?: undefined; - metadata?: undefined; // TODO metadata }; @@ -126,7 +121,6 @@ export type ThreadAssistantMessage = MessageCommonProps & { role: "assistant"; content: ThreadAssistantContentPart[]; status: MessageStatus; - attachments?: undefined; /** * @deprecated Use `metadata.roundtrips` instead. */ @@ -143,10 +137,19 @@ export type AppendMessage = CoreMessage & { attachments?: readonly CompleteAttachment[] | undefined; }; -export type ThreadMessage = - | ThreadSystemMessage - | ThreadUserMessage - | ThreadAssistantMessage; +type BaseThreadMessage = { + role: "user" | "system" | "assistant"; + content: + | ThreadUserMessage["content"] + | ThreadSystemMessage["content"] + | ThreadAssistantMessage["content"]; + status?: ThreadAssistantMessage["status"]; + metadata?: ThreadAssistantMessage["metadata"]; + attachments?: ThreadUserMessage["attachments"]; +}; + +export type ThreadMessage = BaseThreadMessage & + (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage); /** Core Message Types (without UI content parts) */