Repository navigation
feat(desktop): open chat subagents in stacked right panes #5830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...spaceId/hooks/usePaneRegistry/components/ChatPane/hooks/useAutoOpenSubagentPanes/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { useAutoOpenSubagentPanes } from "./useAutoOpenSubagentPanes"; |
92 changes: 92 additions & 0 deletions
92
...neRegistry/components/ChatPane/hooks/useAutoOpenSubagentPanes/useAutoOpenSubagentPanes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import type { WorkspaceStore } from "@superset/panes"; | ||
| import { useEffect, useRef } from "react"; | ||
| import type { StoreApi } from "zustand/vanilla"; | ||
| import type { PaneViewerData } from "../../../../../../types"; | ||
| import { | ||
| findSubagentPaneLocation, | ||
| openSubagentPane, | ||
| } from "../../../../../../utils/openSubagentPane"; | ||
| import type { UseChatDisplayReturn } from "../useWorkspaceChatDisplay"; | ||
|
|
||
| type ChatActiveSubagents = NonNullable<UseChatDisplayReturn["activeSubagents"]>; | ||
|
|
||
| function asRecord(value: unknown): Record<string, unknown> | null { | ||
| if (typeof value !== "object" || value === null || Array.isArray(value)) { | ||
| return null; | ||
| } | ||
| return value as Record<string, unknown>; | ||
| } | ||
|
|
||
| function asString(value: unknown): string | undefined { | ||
| if (typeof value !== "string") return undefined; | ||
| const trimmed = value.trim(); | ||
| return trimmed.length > 0 ? trimmed : undefined; | ||
| } | ||
|
|
||
| function listSubagentEntries( | ||
| activeSubagents: ChatActiveSubagents | undefined | null, | ||
| ): Array<{ | ||
| toolCallId: string; | ||
| task?: string; | ||
| agentType?: string; | ||
| }> { | ||
| if (!activeSubagents || typeof activeSubagents.entries !== "function") { | ||
| return []; | ||
| } | ||
|
|
||
| const entries: Array<{ | ||
| toolCallId: string; | ||
| task?: string; | ||
| agentType?: string; | ||
| }> = []; | ||
| for (const [toolCallId, subagent] of activeSubagents.entries()) { | ||
| if (typeof toolCallId !== "string" || toolCallId.length === 0) continue; | ||
| const record = asRecord(subagent); | ||
| entries.push({ | ||
| toolCallId, | ||
| task: asString(record?.task), | ||
| agentType: asString(record?.agentType) ?? asString(record?.displayName), | ||
| }); | ||
| } | ||
| return entries; | ||
| } | ||
|
|
||
| export function useAutoOpenSubagentPanes({ | ||
| store, | ||
| tabId, | ||
| parentPaneId, | ||
| sessionId, | ||
| activeSubagents, | ||
| }: { | ||
| store: StoreApi<WorkspaceStore<PaneViewerData>> | null; | ||
| tabId: string | null; | ||
| parentPaneId: string | null; | ||
| sessionId: string | null; | ||
| activeSubagents: ChatActiveSubagents | undefined | null; | ||
| }) { | ||
| const openedToolCallIdsRef = useRef(new Set<string>()); | ||
|
|
||
| useEffect(() => { | ||
| openedToolCallIdsRef.current.clear(); | ||
| }, [sessionId, parentPaneId]); | ||
|
|
||
| useEffect(() => { | ||
| if (!store || !tabId || !parentPaneId || !sessionId) return; | ||
|
|
||
| const state = store.getState(); | ||
| for (const entry of listSubagentEntries(activeSubagents)) { | ||
| if (openedToolCallIdsRef.current.has(entry.toolCallId)) continue; | ||
| openedToolCallIdsRef.current.add(entry.toolCallId); | ||
| if (findSubagentPaneLocation(state, entry.toolCallId)) continue; | ||
|
|
||
| openSubagentPane(store, { | ||
| tabId, | ||
| parentPaneId, | ||
| parentSessionId: sessionId, | ||
| toolCallId: entry.toolCallId, | ||
| task: entry.task, | ||
| agentType: entry.agentType, | ||
| }); | ||
| } | ||
| }, [activeSubagents, parentPaneId, sessionId, store, tabId]); | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
.../v2-workspace/$workspaceId/hooks/usePaneRegistry/components/SubagentPane/SubagentPane.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import type { RendererContext } from "@superset/panes"; | ||
| import { useMemo } from "react"; | ||
| import type { PaneViewerData, SubagentPaneData } from "../../../../types"; | ||
| import { SubagentExecutionMessage } from "../ChatPane/components/WorkspaceChatInterface/components/ChatMessageList/components/SubagentExecutionMessage"; | ||
| import { useChatDisplay } from "../ChatPane/hooks/useWorkspaceChatDisplay"; | ||
| import { resolveSubagentEntries } from "./utils/resolveSubagentEntries"; | ||
|
|
||
| interface SubagentPaneProps { | ||
| context: RendererContext<PaneViewerData>; | ||
| workspaceId: string; | ||
| } | ||
|
|
||
| export function SubagentPane({ context, workspaceId }: SubagentPaneProps) { | ||
| const data = context.pane.data as SubagentPaneData; | ||
| const chat = useChatDisplay({ | ||
| sessionId: data.parentSessionId, | ||
| workspaceId, | ||
| enabled: Boolean(data.parentSessionId), | ||
| }); | ||
|
|
||
| const entries = useMemo( | ||
| () => | ||
| resolveSubagentEntries({ | ||
| toolCallId: data.toolCallId, | ||
| activeSubagents: chat.activeSubagents, | ||
| messages: chat.messages ?? [], | ||
| fallback: { | ||
| task: data.task, | ||
| agentType: data.agentType, | ||
| }, | ||
| }), | ||
| [ | ||
| chat.activeSubagents, | ||
| chat.messages, | ||
| data.agentType, | ||
| data.task, | ||
| data.toolCallId, | ||
| ], | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-background"> | ||
| <div className="min-h-0 flex-1 overflow-y-auto p-3 select-text"> | ||
| {entries.length > 0 ? ( | ||
| <SubagentExecutionMessage subagents={entries} inline /> | ||
| ) : ( | ||
| <div className="flex h-full items-center justify-center px-4 text-center text-sm text-muted-foreground"> | ||
| Waiting for subagent activity… | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
55 changes: 55 additions & 0 deletions
55
...sePaneRegistry/components/SubagentPane/components/SubagentPaneTitle/SubagentPaneTitle.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import type { RendererContext } from "@superset/panes"; | ||
| import { cn } from "@superset/ui/utils"; | ||
| import { useMemo } from "react"; | ||
| import type { PaneViewerData, SubagentPaneData } from "../../../../../../types"; | ||
| import { useChatDisplay } from "../../../ChatPane/hooks/useWorkspaceChatDisplay"; | ||
| import { resolveSubagentTitle } from "../../utils/resolveSubagentEntries"; | ||
|
|
||
| interface SubagentPaneTitleProps { | ||
| context: RendererContext<PaneViewerData>; | ||
| workspaceId: string; | ||
| } | ||
|
|
||
| export function SubagentPaneTitle({ | ||
| context, | ||
| workspaceId, | ||
| }: SubagentPaneTitleProps) { | ||
| const data = context.pane.data as SubagentPaneData; | ||
| const chat = useChatDisplay({ | ||
| sessionId: data.parentSessionId, | ||
| workspaceId, | ||
| enabled: Boolean(data.parentSessionId), | ||
| }); | ||
|
|
||
| const title = useMemo( | ||
| () => | ||
| resolveSubagentTitle({ | ||
| toolCallId: data.toolCallId, | ||
| activeSubagents: chat.activeSubagents, | ||
| messages: chat.messages ?? [], | ||
| fallback: { | ||
| task: data.task, | ||
| agentType: data.agentType, | ||
| }, | ||
| }), | ||
| [ | ||
| chat.activeSubagents, | ||
| chat.messages, | ||
| data.agentType, | ||
| data.task, | ||
| data.toolCallId, | ||
| ], | ||
| ); | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn( | ||
| "flex min-w-0 items-center gap-1.5 text-xs transition-colors duration-150", | ||
| context.isActive ? "text-foreground" : "text-muted-foreground", | ||
| )} | ||
| title={data.task ?? title} | ||
| > | ||
| <span className="min-w-0 truncate">{title}</span> | ||
| </div> | ||
| ); | ||
| } |
1 change: 1 addition & 0 deletions
1
...aceId/hooks/usePaneRegistry/components/SubagentPane/components/SubagentPaneTitle/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { SubagentPaneTitle } from "./SubagentPaneTitle"; |
1 change: 1 addition & 0 deletions
1
...ashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/SubagentPane/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { SubagentPane } from "./SubagentPane"; |
4 changes: 4 additions & 0 deletions
4
...aceId/hooks/usePaneRegistry/components/SubagentPane/utils/resolveSubagentEntries/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export { | ||
| resolveSubagentEntries, | ||
| resolveSubagentTitle, | ||
| } from "./resolveSubagentEntries"; |
77 changes: 77 additions & 0 deletions
77
...istry/components/SubagentPane/utils/resolveSubagentEntries/resolveSubagentEntries.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
| import { resolveSubagentEntries } from "./resolveSubagentEntries"; | ||
|
|
||
| describe("resolveSubagentEntries", () => { | ||
| it("prefers live activeSubagents state", () => { | ||
| const activeSubagents = new Map([ | ||
| [ | ||
| "tool-1", | ||
| { | ||
| agentType: "explore", | ||
| task: "Find files", | ||
| textDelta: "Searching…", | ||
| toolCalls: [{ name: "bash", isError: false }], | ||
| status: "running" as const, | ||
| }, | ||
| ], | ||
| ]); | ||
|
|
||
| const entries = resolveSubagentEntries({ | ||
| toolCallId: "tool-1", | ||
| activeSubagents, | ||
| messages: [], | ||
| fallback: { task: "fallback" }, | ||
| }); | ||
|
|
||
| expect(entries).toHaveLength(1); | ||
| expect(entries[0]?.[0]).toBe("tool-1"); | ||
| expect((entries[0]?.[1] as { task: string }).task).toBe("Find files"); | ||
| }); | ||
|
|
||
| it("falls back to message history when subagent left the live map", () => { | ||
| const entries = resolveSubagentEntries({ | ||
| toolCallId: "tool-2", | ||
| activeSubagents: new Map(), | ||
| messages: [ | ||
| { | ||
| id: "msg-1", | ||
| role: "assistant", | ||
| content: [ | ||
| { | ||
| type: "tool_call", | ||
| id: "tool-2", | ||
| name: "subagent", | ||
| args: { task: "Summarize", agentType: "explore" }, | ||
| }, | ||
| { | ||
| type: "tool_result", | ||
| id: "tool-2", | ||
| result: "All done", | ||
| isError: false, | ||
| }, | ||
| ], | ||
| createdAt: new Date(), | ||
| }, | ||
| ] as never, | ||
| fallback: {}, | ||
| }); | ||
|
|
||
| expect(entries).toHaveLength(1); | ||
| expect((entries[0]?.[1] as { status: string }).status).toBe("completed"); | ||
| expect((entries[0]?.[1] as { result?: string }).result).toBe("All done"); | ||
| }); | ||
|
|
||
| it("uses fallback when nothing is known yet", () => { | ||
| const entries = resolveSubagentEntries({ | ||
| toolCallId: "tool-3", | ||
| activeSubagents: undefined, | ||
| messages: [], | ||
| fallback: { task: "Bootstrapping", agentType: "execute" }, | ||
| }); | ||
|
|
||
| expect(entries).toHaveLength(1); | ||
| expect((entries[0]?.[1] as { agentType: string }).agentType).toBe( | ||
| "execute", | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.