mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-26 21:39:43 +02:00
feat: sync thread artifacts to panel state
This commit is contained in:
parent
64c3db60bd
commit
87224b0239
1 changed files with 22 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
import type { ThreadMessageLike } from "@assistant-ui/react";
|
||||
import { useSetAtom } from "jotai";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { collectArtifacts } from "../lib/collect-artifacts";
|
||||
import { chatArtifactsAtom } from "../state/artifacts-panel.atom";
|
||||
|
||||
/**
|
||||
* Keep `chatArtifactsAtom` in sync with the active thread's messages so the
|
||||
* right-panel sidebar (rendered in the layout shell, outside the chat runtime)
|
||||
* can read the deliverable list. Clears on unmount and on thread switch (a new
|
||||
* `messages` array recomputes to the new thread's artifacts).
|
||||
*/
|
||||
export function useSyncChatArtifacts(messages: readonly ThreadMessageLike[]): void {
|
||||
const setArtifacts = useSetAtom(chatArtifactsAtom);
|
||||
const artifacts = useMemo(() => collectArtifacts(messages), [messages]);
|
||||
|
||||
useEffect(() => {
|
||||
setArtifacts(artifacts);
|
||||
}, [artifacts, setArtifacts]);
|
||||
|
||||
useEffect(() => () => setArtifacts([]), [setArtifacts]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue