summaryrefslogtreecommitdiffhomepage
path: root/src/features/tabs/tabs.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/tabs/tabs.ts')
-rw-r--r--src/features/tabs/tabs.ts78
1 files changed, 77 insertions, 1 deletions
diff --git a/src/features/tabs/tabs.ts b/src/features/tabs/tabs.ts
index 63cda35..b2dad7d 100644
--- a/src/features/tabs/tabs.ts
+++ b/src/features/tabs/tabs.ts
@@ -1,9 +1,25 @@
+import type { NamedAgentSelectionSnapshot } from "../named-agents";
+
export interface Tab {
readonly conversationId: string;
readonly model: string;
readonly title: string;
/** The workspace this tab belongs to (the workspace's URL slug). */
readonly workspaceId: string;
+ /**
+ * The Named Agent selection snapshot, when this conversation was selected via
+ * a Named Agent (plan §7). Retained so the conversation keeps showing the
+ * friendly label (and its captured raw model) even after the Named Agent is
+ * renamed/removed. Absent for a raw model selection.
+ */
+ readonly snapshot?: NamedAgentSelectionSnapshot;
+ /**
+ * The EFFECTIVE tab group parent (backend `tabGroupParentId`): the
+ * conversation whose subagent group this tab is visually nested under in
+ * the tab grid. Purely presentational — distinct from the lineage
+ * `parentConversationId`. Absent = ungrouped (a top-level tab).
+ */
+ readonly tabGroupParentId?: string;
}
export interface TabsState {
@@ -73,7 +89,36 @@ export function closeTab(state: TabsState, conversationId: string): TabsState {
}
export function setModel(state: TabsState, conversationId: string, model: string): TabsState {
- const tabs = state.tabs.map((t) => (t.conversationId === conversationId ? { ...t, model } : t));
+ // A raw-model selection clears any Named Agent snapshot (a raw selection is
+ // not "via a Named Agent"). Omit the key entirely (`exactOptionalPropertyTypes`).
+ const tabs = state.tabs.map((t) =>
+ t.conversationId !== conversationId ? t : omitSnapshot({ ...t, model }),
+ );
+ return { tabs, activeConversationId: state.activeConversationId };
+}
+
+/** Drop the optional `snapshot` key (used to clear a Named Agent selection). */
+function omitSnapshot(tab: Tab): Tab {
+ if (!("snapshot" in tab)) return tab;
+ const { snapshot: _omit, ...rest } = tab;
+ void _omit;
+ return rest;
+}
+
+/**
+ * Set (or clear) a tab's Named Agent selection snapshot (plan §7). The snapshot's
+ * captured `model` should equal the tab's `model` (the resolved raw model); this
+ * reducer does not rewrite `model` — the caller keeps them in sync. Pass `null`
+ * to clear (a raw model selection).
+ */
+export function setSnapshot(
+ state: TabsState,
+ conversationId: string,
+ snapshot: NamedAgentSelectionSnapshot | null,
+): TabsState {
+ const tabs = state.tabs.map((t) =>
+ t.conversationId === conversationId ? { ...t, ...(snapshot === null ? {} : { snapshot }) } : t,
+ );
return { tabs, activeConversationId: state.activeConversationId };
}
@@ -82,6 +127,37 @@ export function setTitle(state: TabsState, conversationId: string, title: string
return { tabs, activeConversationId: state.activeConversationId };
}
+/**
+ * Set (string) or clear (null) a tab's tab group parent. Omits the key when
+ * cleared (`exactOptionalPropertyTypes`). No-op for an unknown tab.
+ */
+export function setTabGroupParent(
+ state: TabsState,
+ conversationId: string,
+ parentId: string | null,
+): TabsState {
+ const tabs = state.tabs.map((t) => {
+ if (t.conversationId !== conversationId) return t;
+ if (parentId !== null) return { ...t, tabGroupParentId: parentId };
+ if (!("tabGroupParentId" in t)) return t;
+ const { tabGroupParentId: _omit, ...rest } = t;
+ void _omit;
+ return rest;
+ });
+ return { tabs, activeConversationId: state.activeConversationId };
+}
+
+export function setWorkspaceId(
+ state: TabsState,
+ conversationId: string,
+ workspaceId: string,
+): TabsState {
+ const tabs = state.tabs.map((t) =>
+ t.conversationId === conversationId ? { ...t, workspaceId } : t,
+ );
+ return { tabs, activeConversationId: state.activeConversationId };
+}
+
export function activeTab(state: TabsState): Tab | null {
if (state.activeConversationId === null) return null;
return state.tabs.find((t) => t.conversationId === state.activeConversationId) ?? null;