Skip to content

Commit

Permalink
fix(runtimes/external-store): invalidate cache when isRunning changes…
Browse files Browse the repository at this point in the history
… during autoStatus (#584)
  • Loading branch information
Yonom authored Jul 26, 2024
1 parent 461bf80 commit 0418c73
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-balloons-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

fix(runtimes/external-store): invalidate cache when isRunning changes during autoStatus
5 changes: 0 additions & 5 deletions packages/react/src/runtimes/external-store/auto-status.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { MessageStatus } from "../../types";

const AUTO_STATUS_RUNNING = Object.freeze({ type: "running" });
const AUTO_STATUS_COMPLETE = Object.freeze({
type: "complete",
reason: "unknown",
});

export const isAutoStatus = (status: MessageStatus) =>
status === AUTO_STATUS_RUNNING || status === AUTO_STATUS_COMPLETE;

export const getAutoStatus = (isLast: boolean, isRunning: boolean) =>
isLast && isRunning ? AUTO_STATUS_RUNNING : AUTO_STATUS_COMPLETE;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "./ThreadMessageConverter";
import { ThreadMessage } from "../../types";
import { symbolInnerMessage } from "./getExternalStoreMessage";
import { getAutoStatus, isAutoStatus } from "./auto-status";
import { getAutoStatus } from "./auto-status";
import { fromThreadMessageLike } from "./ThreadMessageLike";

type UpdateDataCallback = (
Expand All @@ -32,16 +32,9 @@ export const useExternalStoreSync = <T extends WeakKey>(
adapterRef.current.isRunning ?? false,
);

if (
cache &&
(cache.role !== "assistant" ||
!isAutoStatus(cache.status) ||
cache.status.type === autoStatus.type)
)
if (cache && (cache.role !== "assistant" || cache.status === autoStatus))
return cache;

if (cache) return cache;

const newMessage = fromThreadMessageLike(
converter(m, idx),
idx.toString(),
Expand Down

0 comments on commit 0418c73

Please sign in to comment.