openCanvas

This commit is contained in:
董宏凯 committed 2026-05-15 23:27:34 +08:00
1 parent 050b1ad78e
commit 1be600155b
18 files changed
+754 -101

No files matched your search

@@ -8,15 +8,18 @@ import {
import type { CanvasArtifact } from "../types/artifact";
import type { CanvasMessage } from "../types/thread";
import type { StreamingArtifactPartial } from "../api/runs";
export interface CanvasGraphContextValue {
messages: CanvasMessage[];
artifact: CanvasArtifact | null;
streamingArtifact: StreamingArtifactPartial | null;
isStreaming: boolean;
setMessages: (messages: CanvasMessage[]) => void;
/** Upsert a message by id — concatenates string content for streaming deltas. */
appendMessage: (msg: CanvasMessage) => void;
setArtifact: (artifact: CanvasArtifact | null) => void;
setStreamingArtifact: (partial: StreamingArtifactPartial | null) => void;
setIsStreaming: (v: boolean) => void;
}
@@ -25,6 +28,8 @@ const CanvasGraphContext = createContext<CanvasGraphContextValue | null>(null);
export function CanvasGraphProvider({ children }: { children: ReactNode }) {
const [messages, setMessages] = useState<CanvasMessage[]>([]);
const [artifact, setArtifact] = useState<CanvasArtifact | null>(null);
const [streamingArtifact, setStreamingArtifact] =
useState<StreamingArtifactPartial | null>(null);
const [isStreaming, setIsStreaming] = useState(false);
const appendMessage = useCallback((msg: CanvasMessage) => {
@@ -50,10 +55,12 @@ export function CanvasGraphProvider({ children }: { children: ReactNode }) {
value={{
messages,
artifact,
streamingArtifact,
isStreaming,
setMessages,
appendMessage,
setArtifact,
setStreamingArtifact,
setIsStreaming,
}}
>