From 7ed296b769d4c976053a99da6853e32f59044435 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Mon, 9 Sep 2024 10:41:54 -0700 Subject: [PATCH] fix: make AppendMessage attachments field optional for now (#797) --- .changeset/four-cars-deliver.md | 5 +++++ packages/react-ai-sdk/src/ui/utils/toCreateMessage.ts | 2 +- packages/react/src/types/AssistantTypes.ts | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/four-cars-deliver.md diff --git a/.changeset/four-cars-deliver.md b/.changeset/four-cars-deliver.md new file mode 100644 index 000000000..bdef212d2 --- /dev/null +++ b/.changeset/four-cars-deliver.md @@ -0,0 +1,5 @@ +--- +"@assistant-ui/react": patch +--- + +fix: make AppendMessage attachments field optional for now diff --git a/packages/react-ai-sdk/src/ui/utils/toCreateMessage.ts b/packages/react-ai-sdk/src/ui/utils/toCreateMessage.ts index e9be5efbc..1f5714657 100644 --- a/packages/react-ai-sdk/src/ui/utils/toCreateMessage.ts +++ b/packages/react-ai-sdk/src/ui/utils/toCreateMessage.ts @@ -19,7 +19,7 @@ export const toCreateMessage = async ( experimental_attachments: [ ...images, ...(await Promise.all( - message.attachments.map(async (m) => { + (message.attachments ?? []).map(async (m) => { if (m.file == null) throw new Error("Attachment did not contain a file"); return { diff --git a/packages/react/src/types/AssistantTypes.ts b/packages/react/src/types/AssistantTypes.ts index 3167181f0..7b51adc93 100644 --- a/packages/react/src/types/AssistantTypes.ts +++ b/packages/react/src/types/AssistantTypes.ts @@ -133,7 +133,8 @@ export type ThreadAssistantMessage = MessageCommonProps & { export type AppendMessage = CoreMessage & { parentId: string | null; - attachments: readonly MessageAttachment[]; + // TODO make required in the next major version + attachments?: readonly MessageAttachment[]; }; export type ThreadMessage =