Talk to wren nodes from the chat's Control tab, opened from Home

This commit is contained in:
2026-10-05 20:59:11 +02:00
parent 14d3208a5d
commit afe0c94a24
11 changed files with 417 additions and 42 deletions
+10 -4
View File
@@ -1,16 +1,20 @@
import { useSyncExternalStore } from "react"
/** What the panel is talking to: the assistant, or a wren node in a flow. */
export type ChatTab = "build" | "control"
/**
* Whether the assistant is open, and whether another panel is open beside it.
* Whether the assistant is open, on which tab, and whether another panel is
* open beside it.
*
* Module state rather than context because the chat is mounted once in the
* sidebar and toggled from there, while the editor's own panels report in
* from a different tree: the two only have to agree on who takes which half
* of the lane.
*/
type State = { open: boolean; panels: number }
type State = { open: boolean; tab: ChatTab; panels: number }
let state: State = { open: false, panels: 0 }
let state: State = { open: false, tab: "build", panels: 0 }
const listeners = new Set<() => void>()
function set(next: Partial<State>) {
@@ -19,7 +23,9 @@ function set(next: Partial<State>) {
}
export const chatStore = {
open: () => set({ open: true }),
/** Open it, on a given tab or on whichever was last shown. */
open: (tab?: ChatTab) => set(tab ? { open: true, tab } : { open: true }),
show: (tab: ChatTab) => set({ tab }),
close: () => set({ open: false }),
toggle: () => set({ open: !state.open }),
/** A floating panel is open; returns how to say it closed again. */