-
Notifications
You must be signed in to change notification settings - Fork 49
feat(agents): add Publish action, overview summary; drop "Explain this agent" #2884
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
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
122 changes: 122 additions & 0 deletions
122
...ages/ui/src/features/agent-applications/agent-builder/useAgentBuilderClientTools.test.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,122 @@ | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { renderHook } from "@testing-library/react"; | ||
| import type { ReactNode } from "react"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const mockUpdate = vi.hoisted(() => vi.fn()); | ||
| const mockClient = vi.hoisted(() => ({ updateAgentApplication: mockUpdate })); | ||
| const mockNavigate = vi.hoisted(() => vi.fn()); | ||
| const mockSetPendingSecret = vi.hoisted(() => vi.fn()); | ||
|
|
||
| vi.mock("@tanstack/react-router", () => ({ | ||
| useNavigate: () => mockNavigate, | ||
| })); | ||
| vi.mock("@posthog/ui/features/auth/authClient", () => ({ | ||
| useAuthenticatedClient: () => mockClient, | ||
| })); | ||
| vi.mock("../../auth/store", () => ({ | ||
| useAuthStateValue: (selector: (s: { currentProjectId: number }) => unknown) => | ||
| selector({ currentProjectId: 1 }), | ||
| })); | ||
| vi.mock("./agentBuilderStore", () => ({ | ||
| useAgentBuilderStore: ( | ||
| selector: (s: { | ||
| followMode: boolean; | ||
| setPendingSecret: (...args: unknown[]) => unknown; | ||
| page: { kind: string }; | ||
| }) => unknown, | ||
| ) => | ||
| selector({ | ||
| followMode: true, | ||
| setPendingSecret: mockSetPendingSecret, | ||
| page: { kind: "agent-list" }, | ||
| }), | ||
| })); | ||
|
|
||
| import { useAgentBuilderClientTools } from "./useAgentBuilderClientTools"; | ||
|
|
||
| function wrapper({ children }: { children: ReactNode }) { | ||
| const queryClient = new QueryClient({ | ||
| defaultOptions: { queries: { retry: false } }, | ||
| }); | ||
| return ( | ||
| <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
| ); | ||
| } | ||
|
|
||
| function call(toolId: string, args: Record<string, unknown>) { | ||
| return { call_id: "c1", tool_id: toolId, args }; | ||
| } | ||
|
|
||
| describe("useAgentBuilderClientTools — set_application_description", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("calls updateAgentApplication and returns success on the happy path", async () => { | ||
| mockUpdate.mockResolvedValue({}); | ||
| const { result } = renderHook(() => useAgentBuilderClientTools(), { | ||
| wrapper, | ||
| }); | ||
| const outcome = await result.current( | ||
| call("set_application_description", { | ||
| agent_slug: "support", | ||
| description: " Handles tier-1 support tickets. ", | ||
| }), | ||
| ); | ||
| expect(mockUpdate).toHaveBeenCalledWith("support", { | ||
| description: "Handles tier-1 support tickets.", | ||
| }); | ||
| expect(outcome).toEqual({ result: { success: true } }); | ||
| }); | ||
|
|
||
| it("errors when agent_slug is missing", async () => { | ||
| const { result } = renderHook(() => useAgentBuilderClientTools(), { | ||
| wrapper, | ||
| }); | ||
| const outcome = await result.current( | ||
| call("set_application_description", { description: "ok" }), | ||
| ); | ||
| expect(mockUpdate).not.toHaveBeenCalled(); | ||
| expect(outcome).toEqual({ error: "missing_arg: agent_slug" }); | ||
| }); | ||
|
|
||
| it("errors when description is missing", async () => { | ||
| const { result } = renderHook(() => useAgentBuilderClientTools(), { | ||
| wrapper, | ||
| }); | ||
| const outcome = await result.current( | ||
| call("set_application_description", { agent_slug: "support" }), | ||
| ); | ||
| expect(mockUpdate).not.toHaveBeenCalled(); | ||
| expect(outcome).toEqual({ error: "missing_arg: description" }); | ||
| }); | ||
|
|
||
| it("rejects when the trimmed description exceeds the cap", async () => { | ||
| const { result } = renderHook(() => useAgentBuilderClientTools(), { | ||
| wrapper, | ||
| }); | ||
| const outcome = await result.current( | ||
| call("set_application_description", { | ||
| agent_slug: "support", | ||
| description: "x".repeat(281), | ||
| }), | ||
| ); | ||
| expect(mockUpdate).not.toHaveBeenCalled(); | ||
| expect(outcome).toEqual({ error: "description_too_long: max 280 chars" }); | ||
| }); | ||
|
|
||
| it("reports update_failed when the client throws", async () => { | ||
| mockUpdate.mockRejectedValue(new Error("boom")); | ||
| const { result } = renderHook(() => useAgentBuilderClientTools(), { | ||
| wrapper, | ||
| }); | ||
| const outcome = await result.current( | ||
| call("set_application_description", { | ||
| agent_slug: "support", | ||
| description: "ok", | ||
| }), | ||
| ); | ||
| expect(outcome).toEqual({ error: "update_failed: boom" }); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| import { useAuthenticatedClient } from "@posthog/ui/features/auth/authClient"; | ||
| import { useQueryClient } from "@tanstack/react-query"; | ||
| import { useNavigate } from "@tanstack/react-router"; | ||
| import { useCallback, useRef } from "react"; | ||
| import { useAuthStateValue } from "../../auth/store"; | ||
| import { agentApplicationsKeys } from "../hooks/agentApplicationsKeys"; | ||
| import type { ClientToolHandler } from "../hooks/useAgentChat"; | ||
| import { useAgentBuilderStore } from "./agentBuilderStore"; | ||
|
|
||
| const MAX_DESCRIPTION_CHARS = 280; | ||
|
|
||
| /** | ||
| * The agent builder's UI-driving client tools. The agent calls these to steer the | ||
| * user's screen (`focus_*`, which navigate code's agent routes and report back | ||
|
|
@@ -15,6 +21,9 @@ import { useAgentBuilderStore } from "./agentBuilderStore"; | |
| */ | ||
| export function useAgentBuilderClientTools(): ClientToolHandler { | ||
| const navigate = useNavigate(); | ||
| const client = useAuthenticatedClient(); | ||
| const queryClient = useQueryClient(); | ||
| const projectId = useAuthStateValue((state) => state.currentProjectId); | ||
| const followMode = useAgentBuilderStore((s) => s.followMode); | ||
| const setPendingSecret = useAgentBuilderStore((s) => s.setPendingSecret); | ||
| const page = useAgentBuilderStore((s) => s.page); | ||
|
|
@@ -26,10 +35,43 @@ export function useAgentBuilderClientTools(): ClientToolHandler { | |
| pageRef.current = page; | ||
|
|
||
| return useCallback( | ||
| (data) => { | ||
| async (data) => { | ||
| const args = (data.args ?? {}) as Record<string, unknown>; | ||
| const str = (v: unknown) => (typeof v === "string" ? v : undefined); | ||
|
|
||
| // set_application_description — write the agent's short summary. The | ||
| // overview surfaces this directly; capping the length keeps it scannable | ||
| // and forces the agent to retry shorter on overflow. | ||
| if (data.tool_id === "set_application_description") { | ||
| const agentSlug = str(args.agent_slug); | ||
| const description = str(args.description); | ||
| if (!agentSlug) return { error: "missing_arg: agent_slug" }; | ||
| if (description === undefined) { | ||
| return { error: "missing_arg: description" }; | ||
| } | ||
| const trimmed = description.trim(); | ||
| if (trimmed.length > MAX_DESCRIPTION_CHARS) { | ||
| return { | ||
| error: `description_too_long: max ${MAX_DESCRIPTION_CHARS} chars`, | ||
| }; | ||
| } | ||
| try { | ||
| await client.updateAgentApplication(agentSlug, { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is bizarre - why are we making the agent only able to do this in the console? This should just be soemthing it knows how to do via the mcp surely? |
||
| description: trimmed, | ||
| }); | ||
| } catch (error) { | ||
| const msg = error instanceof Error ? error.message : String(error); | ||
| return { error: `update_failed: ${msg}` }; | ||
| } | ||
| void queryClient.invalidateQueries({ | ||
| queryKey: agentApplicationsKeys.detail(projectId, agentSlug), | ||
| }); | ||
| void queryClient.invalidateQueries({ | ||
| queryKey: agentApplicationsKeys.list(projectId), | ||
| }); | ||
| return { result: { success: true } }; | ||
| } | ||
|
|
||
| // set_secret — interactive punch-out. Park the call (defer) and render a | ||
| // form; the dock PUTs the key and wakes the session on submit. Env keys | ||
| // are revision-scoped, so resolve the target revision from the tool args, | ||
|
|
@@ -150,6 +192,6 @@ export function useAgentBuilderClientTools(): ClientToolHandler { | |
| return { result: { focused: false, reason: "unknown_focus_target" } }; | ||
| } | ||
| }, | ||
| [navigate, setPendingSecret], | ||
| [navigate, setPendingSecret, client, queryClient, projectId], | ||
| ); | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not?