Skip to content

Commit

Permalink
fix: do not require content in ChatModelRunResult (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Aug 21, 2024
1 parent 16777c9 commit 53cf707
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-vans-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

fix: do not require content in ChatModelRunResult
12 changes: 6 additions & 6 deletions packages/react/src/runtimes/edge/streams/runResultStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export function runResultStream() {
}

const appendOrUpdateText = (message: ChatModelRunResult, textDelta: string) => {
let contentParts = message.content;
let contentPart = message.content.at(-1);
let contentParts = message.content ?? [];
let contentPart = message.content?.at(-1);
if (contentPart?.type !== "text") {
contentPart = { type: "text", text: textDelta };
} else {
Expand All @@ -98,8 +98,8 @@ const appendOrUpdateToolCall = (
toolName: string,
argsText: string,
) => {
let contentParts = message.content;
let contentPart = message.content.at(-1);
let contentParts = message.content ?? [];
let contentPart = message.content?.at(-1);
if (
contentPart?.type !== "tool-call" ||
contentPart.toolCallId !== toolCallId
Expand Down Expand Up @@ -132,7 +132,7 @@ const appendOrUpdateToolResult = (
result: any,
) => {
let found = false;
const newContentParts = message.content.map((part) => {
const newContentParts = message.content?.map((part) => {
if (part.type !== "tool-call" || part.toolCallId !== toolCallId)
return part;
found = true;
Expand All @@ -154,7 +154,7 @@ const appendOrUpdateToolResult = (

return {
...message,
content: newContentParts,
content: newContentParts!,
};
};

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/runtimes/local/ChatModelAdapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type ChatModelRunUpdate = {
};

export type ChatModelRunResult = {
content: ThreadAssistantContentPart[];
content?: ThreadAssistantContentPart[];
status?: MessageStatus;
metadata?: {
roundtrips?: ThreadRoundtrip[];
Expand Down

0 comments on commit 53cf707

Please sign in to comment.