Skip to content
Source
Sign inSign up

sideChatPane.ts

31 lines1.4 KB

1import type { OrchestrationV2ThreadShell, ScopedThreadRef } from "@t3tools/contracts";
2​
3import type { ToolCallDiffTarget } from "../diffPanelStore";
4import { useRightPanelStore } from "../rightPanelStore";
5​
6/** Whether an event started in the side chat pane (`data-side-chat-pane`), which the main chat ignores. */
7export function isInSideChatPane(target: EventTarget | null): boolean {
8 return target instanceof Element && target.closest("[data-side-chat-pane]") !== null;
9}
10​
11/**
12 * Opens an embedded side chat's tool diffs in its parent's diff panel and runs its shell commands
13 * in the parent's terminal drawer, since the embedded view hides its own. Other panel actions reach
14 * the parent through `hostRightPanel`; diff selection and the drawer are not panel state.
15 */
16export interface SideChatParentPanel {
17 readonly openToolDiff: (target: ToolCallDiffTarget) => void;
18 readonly runShellCommand: (command: string) => void;
20​
21/** Opens `thread` in its tab when it is a side chat of `parentRef`; false for any other thread. */
22export function openSideChatTab(
23 parentRef: ScopedThreadRef,
24 thread: Pick<OrchestrationV2ThreadShell, "id" | "lineage"> | null,
25): boolean {
26 if (thread?.lineage.sideChat !== true || thread.lineage.parentThreadId !== parentRef.threadId) {
27 return false;
28 }
29 useRightPanelStore.getState().openSideChat(parentRef, thread.id);
30 return true;