Skip to content

Commit

Permalink
fix: useContentPartText backwards compat type (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Oct 1, 2024
1 parent b80d30f commit 55942d8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-terms-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

fix: useContentPartText backwards compat type
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 13 additions & 10 deletions packages/react/src/types/AssistantTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,19 @@ 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
};

export type ThreadAssistantMessage = MessageCommonProps & {
role: "assistant";
content: ThreadAssistantContentPart[];
status: MessageStatus;
attachments?: undefined;
/**
* @deprecated Use `metadata.roundtrips` instead.
*/
Expand All @@ -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) */

Expand Down

0 comments on commit 55942d8

Please sign in to comment.