Repository navigation
fix(site/src/pages/AgentsPage): use the root chat's project for subagent chat skills #30840
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
jaaydenh
wants to merge
5
commits into
chat-project-skills/chatd
from
chat-project-skills/subagent-project
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
26deda5
fix(site/src/pages/AgentsPage): use the root chat's project for subag…
jaaydenh 549a030
fix(site/src/pages/AgentsPage): keep inherited project skills pending…
jaaydenh 7b6c3e3
test(site/src/pages/AgentsPage/components): restore Range geometry st…
jaaydenh 958d217
Merge branch 'chat-project-skills/chatd' into chat-project-skills/sub…
jaaydenh c39c1e0
Merge branch 'chat-project-skills/chatd' into chat-project-skills/sub…
jaaydenh 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { renderHook, waitFor } from "@testing-library/react"; | ||
| import { QueryClientProvider } from "react-query"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| import { API } from "#/api/api"; | ||
| import type { Chat } from "#/api/typesGenerated"; | ||
| import { MockChat } from "#/testHelpers/chatEntities"; | ||
| import { createTestQueryClient } from "#/testHelpers/renderHelpers"; | ||
| import { useChatProjectId } from "./useChatProjectId"; | ||
|
|
||
| const mockRootChat: Chat = { | ||
| ...MockChat, | ||
| id: "root-chat", | ||
| project_id: "project-1", | ||
| }; | ||
| const mockSubagentChat: Chat = { | ||
| ...MockChat, | ||
| id: "subagent-chat", | ||
| parent_chat_id: mockRootChat.id, | ||
| root_chat_id: mockRootChat.id, | ||
| }; | ||
|
|
||
| const renderUseChatProjectId = (chat: Chat, enabled = true) => { | ||
| const queryClient = createTestQueryClient(); | ||
| return renderHook(() => useChatProjectId(chat, enabled), { | ||
| wrapper: ({ children }: React.PropsWithChildren) => ( | ||
| <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
| ), | ||
| }); | ||
| }; | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| describe("useChatProjectId", () => { | ||
| it("resolves no project when the root chat fails to load", async () => { | ||
| vi.spyOn(API.experimental, "getChat").mockRejectedValue(new Error("boom")); | ||
|
|
||
| const { result } = renderUseChatProjectId(mockSubagentChat); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current).toEqual({ | ||
| projectId: undefined, | ||
| isResolved: true, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it("uses the chat's own project without fetching the root chat", () => { | ||
| const getChat = vi.spyOn(API.experimental, "getChat"); | ||
|
|
||
| const { result } = renderUseChatProjectId({ | ||
| ...mockSubagentChat, | ||
| project_id: "project-2", | ||
| }); | ||
|
|
||
| expect(result.current).toEqual({ | ||
| projectId: "project-2", | ||
| isResolved: true, | ||
| }); | ||
| expect(getChat).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("resolves no project while the chat-projects experiment is off", () => { | ||
| const getChat = vi.spyOn(API.experimental, "getChat"); | ||
|
|
||
| const { result } = renderUseChatProjectId(mockSubagentChat, false); | ||
|
|
||
| expect(result.current).toEqual({ projectId: undefined, isResolved: true }); | ||
| expect(getChat).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
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,44 @@ | ||
| import { useQuery } from "react-query"; | ||
| import { chat as chatQuery } from "#/api/queries/chats"; | ||
| import type { Chat } from "#/api/typesGenerated"; | ||
|
|
||
| type ChatProjectId = { | ||
| /** The project whose skills apply to the chat, if any. */ | ||
| projectId: string | undefined; | ||
| /** | ||
| * False while the project is unknown, so callers can avoid treating | ||
| * project skills as absent before the root chat loads. A failed root | ||
| * chat lookup resolves to no project so built-in commands keep working. | ||
| */ | ||
| isResolved: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * Resolves the project a chat belongs to. Subagent chats have no | ||
| * project_id of their own and inherit the root chat's project, matching | ||
| * chatd's project resolution. | ||
| */ | ||
| export const useChatProjectId = ( | ||
| chat: Chat | undefined, | ||
| enabled: boolean, | ||
| ): ChatProjectId => { | ||
| const rootChatId = chat?.root_chat_id; | ||
| const needsRootChat = Boolean( | ||
| enabled && chat && !chat.project_id && rootChatId && rootChatId !== chat.id, | ||
| ); | ||
| const rootChatQuery = useQuery({ | ||
| ...chatQuery(rootChatId ?? ""), | ||
| enabled: needsRootChat, | ||
| }); | ||
|
|
||
| if (!enabled) { | ||
| return { projectId: undefined, isResolved: true }; | ||
| } | ||
| if (!needsRootChat) { | ||
| return { projectId: chat?.project_id, isResolved: true }; | ||
| } | ||
| return { | ||
| projectId: rootChatQuery.data?.project_id, | ||
| isResolved: rootChatQuery.data !== undefined || rootChatQuery.isError, | ||
| }; | ||
| }; |
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.