From 015b663cbfb2c7dfabe25344a306c2e192907afc Mon Sep 17 00:00:00 2001 From: haikdc Date: Sat, 18 Apr 2026 17:06:07 -0700 Subject: [PATCH] =?UTF-8?q?[Haik]:=20refactor:=20remove=20global=20compone?= =?UTF-8?q?nts/tool-ui/shared/=20directory=20and=20colocate=20its=20module?= =?UTF-8?q?s=20under=20AgentChat/toolkit=20=E2=80=94=20move=20ToolUI=20sch?= =?UTF-8?q?emas=20to=20toolkit/utils/schema,=20action=20types=20to=20appro?= =?UTF-8?q?valToolkit/utils/types,=20ActionButtons=20component=20to=20appr?= =?UTF-8?q?ovalToolkit/components/ActionButtons,=20actions-config=20and=20?= =?UTF-8?q?embedded-actions=20to=20OptionList/utils,=20and=20getMcpInputSu?= =?UTF-8?q?mmary=20and=20useMcpToolMeta=20to=20approvalToolkit/utils;=20up?= =?UTF-8?q?date=20all=20imports=20across=20approvalToolkit=20and=20nativeT?= =?UTF-8?q?oolkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ActionButtons/ActionButtons.tsx} | 7 ++-- .../ActionButtons/useActionButtons.tsx} | 2 +- .../ApprovalCard/ApprovalCard.tsx | 4 +- .../ToolApproval/ApprovalCard/schema.ts | 2 +- .../components/ToolApproval/ToolApproval.tsx | 4 +- .../ToolQuestion/OptionList/OptionList.tsx | 7 ++-- .../ToolQuestion/OptionList/schema.ts | 9 ++--- .../OptionList/utils}/actions-config.ts | 0 .../OptionList/utils}/embedded-actions.ts | 0 .../ToolQuestion/QuestionFlow/schema.ts | 2 +- .../getMcpInputSummary.ts | 0 .../toolkit/approvalToolkit/utils/types.ts | 37 +++++++++++++++++++ .../{components => utils}/useMcpToolMeta.tsx | 0 .../components/CodeBlock/schema.ts | 2 +- .../components/CodeDiff/schema.ts | 2 +- .../components/Terminal/schema.ts | 2 +- .../pages/AgentChat/toolkit/utils}/schema.ts | 36 ------------------ .../components/tool-ui/shared/_adapter.tsx | 2 - 18 files changed, 59 insertions(+), 59 deletions(-) rename frontend/src/{components/tool-ui/shared/action-buttons.tsx => app/pages/AgentChat/toolkit/approvalToolkit/components/ActionButtons/ActionButtons.tsx} (94%) rename frontend/src/{components/tool-ui/shared/use-action-buttons.tsx => app/pages/AgentChat/toolkit/approvalToolkit/components/ActionButtons/useActionButtons.tsx} (97%) rename frontend/src/{components/tool-ui/shared => app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/utils}/actions-config.ts (100%) rename frontend/src/{components/tool-ui/shared => app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/utils}/embedded-actions.ts (100%) rename frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/{components => utils}/getMcpInputSummary.ts (100%) create mode 100644 frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/utils/types.ts rename frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/{components => utils}/useMcpToolMeta.tsx (100%) rename frontend/src/{components/tool-ui/shared => app/pages/AgentChat/toolkit/utils}/schema.ts (56%) delete mode 100644 frontend/src/components/tool-ui/shared/_adapter.tsx diff --git a/frontend/src/components/tool-ui/shared/action-buttons.tsx b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ActionButtons/ActionButtons.tsx similarity index 94% rename from frontend/src/components/tool-ui/shared/action-buttons.tsx rename to frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ActionButtons/ActionButtons.tsx index 3fa17579..f9a99083 100644 --- a/frontend/src/components/tool-ui/shared/action-buttons.tsx +++ b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ActionButtons/ActionButtons.tsx @@ -1,8 +1,9 @@ "use client"; -import type { Action } from "./schema"; -import { cn, Button } from "./_adapter"; -import { useActionButtons } from "./use-action-buttons"; +import type { Action } from "../../utils/types"; +import { useActionButtons } from "./useActionButtons"; +import { cn } from "@/lib/utils"; +import { Button } from "@/components/ui/button"; interface ActionButtonsProps { actions: Action[]; diff --git a/frontend/src/components/tool-ui/shared/use-action-buttons.tsx b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ActionButtons/useActionButtons.tsx similarity index 97% rename from frontend/src/components/tool-ui/shared/use-action-buttons.tsx rename to frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ActionButtons/useActionButtons.tsx index 468ed3e4..96bab940 100644 --- a/frontend/src/components/tool-ui/shared/use-action-buttons.tsx +++ b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ActionButtons/useActionButtons.tsx @@ -1,7 +1,7 @@ "use client"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import type { Action } from "./schema"; +import type { Action } from "@/app/pages/AgentChat/toolkit/approvalToolkit/utils/types"; type UseActionButtonsOptions = { actions: Action[]; diff --git a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ApprovalCard/ApprovalCard.tsx b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ApprovalCard/ApprovalCard.tsx index f0ea1ed9..c856f337 100644 --- a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ApprovalCard/ApprovalCard.tsx +++ b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ApprovalCard/ApprovalCard.tsx @@ -3,8 +3,8 @@ import * as React from "react"; import { cn, Separator } from "./_adapter"; import type { ApprovalCardProps, ApprovalDecision } from "./schema"; -import { ActionButtons } from "../shared/action-buttons"; -import { type Action } from "../shared/schema"; +import { ActionButtons } from "../../ActionButtons/ActionButtons"; +import { type Action } from "../../../utils/types"; import { icons, Check, X } from "lucide-react"; diff --git a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ApprovalCard/schema.ts b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ApprovalCard/schema.ts index 1645911c..4e5f3914 100644 --- a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ApprovalCard/schema.ts +++ b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ApprovalCard/schema.ts @@ -1,5 +1,5 @@ import { z } from "zod"; -import { ToolUIIdSchema, ToolUIRoleSchema } from "../shared/schema"; +import { ToolUIIdSchema, ToolUIRoleSchema } from "@/app/pages/AgentChat/toolkit/utils/schema"; const MetadataItemSchema = z.object({ key: z.string().min(1), diff --git a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ToolApproval.tsx b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ToolApproval.tsx index b7e43576..fa1382b4 100644 --- a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ToolApproval.tsx +++ b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolApproval/ToolApproval.tsx @@ -1,11 +1,11 @@ import React, { useMemo } from 'react'; import { ApprovalCard } from './ApprovalCard/ApprovalCard'; import type { ApprovalRequest } from '@/shared/state/agentsSlice'; -import { useMcpToolMeta } from '../useMcpToolMeta'; +import { useMcpToolMeta } from '../../utils/useMcpToolMeta'; import { parseMcpToolName, } from '../../utils'; -import { getMcpInputSummary } from '../getMcpInputSummary'; +import { getMcpInputSummary } from '../../utils/getMcpInputSummary'; // TODO: what is this even supposed to try and import/use ??? import type { MetadataItem } from '@/components/tool-ui/ApprovalCard/schema'; diff --git a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/OptionList.tsx b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/OptionList.tsx index c266eaa9..864efe61 100644 --- a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/OptionList.tsx +++ b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/OptionList.tsx @@ -18,9 +18,10 @@ import { normalizeSelectionForOptions, parseSelectionToIdSet, } from "./selection"; -import { ActionButtons } from "@/components/tool-ui/shared/action-buttons"; -import { normalizeActionsConfig } from "@/components/tool-ui/shared/actions-config"; -import type { Action } from "@/components/tool-ui/shared/schema"; +import { ActionButtons } from "../../ActionButtons"; +import { normalizeActionsConfig } from "./utils/actions-config"; +import type { Action } from "../../../utils/types"; + import { cn, Button, Separator } from "./_adapter"; import { Check } from "lucide-react"; diff --git a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/schema.ts b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/schema.ts index cc65675f..c039b8ab 100644 --- a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/schema.ts +++ b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/schema.ts @@ -1,14 +1,13 @@ import { z } from "zod"; import type { ReactNode } from "react"; -import type { ActionsProp } from "@/components/tool-ui/shared/actions-config"; -import type { EmbeddedActionsProps } from "@/components/tool-ui/shared/embedded-actions"; +import type { ActionsProp } from "./utils/actions-config"; +import type { EmbeddedActionsProps } from "./utils/embedded-actions"; import { - ActionSchema, - SerializableActionsConfigSchema, ToolUIIdSchema, ToolUIReceiptSchema, ToolUIRoleSchema, -} from "@/components/tool-ui/shared/schema"; +} from "@/app/pages/AgentChat/toolkit/utils/schema"; +import type { ActionSchema, SerializableActionsConfigSchema } from "../../../utils/types"; export const OptionListOptionSchema = z.object({ id: z.string().min(1), diff --git a/frontend/src/components/tool-ui/shared/actions-config.ts b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/utils/actions-config.ts similarity index 100% rename from frontend/src/components/tool-ui/shared/actions-config.ts rename to frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/utils/actions-config.ts diff --git a/frontend/src/components/tool-ui/shared/embedded-actions.ts b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/utils/embedded-actions.ts similarity index 100% rename from frontend/src/components/tool-ui/shared/embedded-actions.ts rename to frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/OptionList/utils/embedded-actions.ts diff --git a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/QuestionFlow/schema.ts b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/QuestionFlow/schema.ts index 49a32b16..6d752e5d 100644 --- a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/QuestionFlow/schema.ts +++ b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/ToolQuestion/QuestionFlow/schema.ts @@ -1,6 +1,6 @@ import { z } from "zod"; import type { ReactNode } from "react"; -import { ToolUIIdSchema, ToolUIRoleSchema } from "@/components/tool-ui/shared/schema"; +import { ToolUIIdSchema, ToolUIRoleSchema } from "@/app/pages/AgentChat/toolkit/utils/schema"; export const QuestionFlowOptionSchema = z.object({ id: z.string().min(1), diff --git a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/getMcpInputSummary.ts b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/utils/getMcpInputSummary.ts similarity index 100% rename from frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/getMcpInputSummary.ts rename to frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/utils/getMcpInputSummary.ts diff --git a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/utils/types.ts b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/utils/types.ts new file mode 100644 index 00000000..f81985c2 --- /dev/null +++ b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/utils/types.ts @@ -0,0 +1,37 @@ +import { z } from "zod"; +import type { ReactNode } from "react"; + +export const ActionSchema = z.object({ + id: z.string().min(1), + label: z.string().min(1), + /** + * Canonical narration the assistant can use after this action is taken. + * + * Example: "I exported the table as CSV." / "I opened the link in a new tab." + */ + sentence: z.string().optional(), + confirmLabel: z.string().optional(), + variant: z + .enum(["default", "destructive", "secondary", "ghost", "outline"]) + .optional(), + icon: z.custom().optional(), + loading: z.boolean().optional(), + disabled: z.boolean().optional(), + shortcut: z.string().optional(), +}); + +export type Action = z.infer; + +const SerializableActionSchema = ActionSchema.omit({ icon: true }); + +export interface ActionsConfig { + items: Action[]; + align?: "left" | "center" | "right"; + confirmTimeout?: number; +} + +export const SerializableActionsConfigSchema = z.object({ + items: z.array(SerializableActionSchema).min(1), + align: z.enum(["left", "center", "right"]).optional(), + confirmTimeout: z.number().positive().optional(), +}); \ No newline at end of file diff --git a/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/useMcpToolMeta.tsx b/frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/utils/useMcpToolMeta.tsx similarity index 100% rename from frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/components/useMcpToolMeta.tsx rename to frontend/src/app/pages/AgentChat/toolkit/approvalToolkit/utils/useMcpToolMeta.tsx diff --git a/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/CodeBlock/schema.ts b/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/CodeBlock/schema.ts index c41bfb27..fe66a04a 100644 --- a/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/CodeBlock/schema.ts +++ b/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/CodeBlock/schema.ts @@ -3,7 +3,7 @@ import { ToolUIIdSchema, ToolUIReceiptSchema, ToolUIRoleSchema, -} from "../shared/schema"; +} from "@/app/pages/AgentChat/toolkit/utils/schema"; export const CodeBlockPropsSchema = z.object({ id: ToolUIIdSchema, diff --git a/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/CodeDiff/schema.ts b/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/CodeDiff/schema.ts index 176a1f9c..7dd79475 100644 --- a/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/CodeDiff/schema.ts +++ b/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/CodeDiff/schema.ts @@ -3,7 +3,7 @@ import { ToolUIIdSchema, ToolUIReceiptSchema, ToolUIRoleSchema, -} from "../shared/schema"; +} from "@/app/pages/AgentChat/toolkit/utils/schema"; const CodeDiffPropsSchemaBase = z.object({ id: ToolUIIdSchema, diff --git a/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/Terminal/schema.ts b/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/Terminal/schema.ts index 6167b791..62df2391 100644 --- a/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/Terminal/schema.ts +++ b/frontend/src/app/pages/AgentChat/toolkit/nativeToolkit/components/Terminal/schema.ts @@ -3,7 +3,7 @@ import { ToolUIIdSchema, ToolUIReceiptSchema, ToolUIRoleSchema, -} from "../shared/schema"; +} from "@/app/pages/AgentChat/toolkit/utils/schema"; export const TerminalPropsSchema = z.object({ id: ToolUIIdSchema, diff --git a/frontend/src/components/tool-ui/shared/schema.ts b/frontend/src/app/pages/AgentChat/toolkit/utils/schema.ts similarity index 56% rename from frontend/src/components/tool-ui/shared/schema.ts rename to frontend/src/app/pages/AgentChat/toolkit/utils/schema.ts index 0de45f53..eef78b8a 100644 --- a/frontend/src/components/tool-ui/shared/schema.ts +++ b/frontend/src/app/pages/AgentChat/toolkit/utils/schema.ts @@ -1,5 +1,4 @@ import { z } from "zod"; -import type { ReactNode } from "react"; /** * Tool UI conventions: @@ -51,38 +50,3 @@ export const ToolUIReceiptSchema = z.object({ identifiers: z.record(z.string(), z.string()).optional(), at: z.string().datetime(), }); - -export const ActionSchema = z.object({ - id: z.string().min(1), - label: z.string().min(1), - /** - * Canonical narration the assistant can use after this action is taken. - * - * Example: "I exported the table as CSV." / "I opened the link in a new tab." - */ - sentence: z.string().optional(), - confirmLabel: z.string().optional(), - variant: z - .enum(["default", "destructive", "secondary", "ghost", "outline"]) - .optional(), - icon: z.custom().optional(), - loading: z.boolean().optional(), - disabled: z.boolean().optional(), - shortcut: z.string().optional(), -}); - -export type Action = z.infer; - -const SerializableActionSchema = ActionSchema.omit({ icon: true }); - -export interface ActionsConfig { - items: Action[]; - align?: "left" | "center" | "right"; - confirmTimeout?: number; -} - -export const SerializableActionsConfigSchema = z.object({ - items: z.array(SerializableActionSchema).min(1), - align: z.enum(["left", "center", "right"]).optional(), - confirmTimeout: z.number().positive().optional(), -}); \ No newline at end of file diff --git a/frontend/src/components/tool-ui/shared/_adapter.tsx b/frontend/src/components/tool-ui/shared/_adapter.tsx deleted file mode 100644 index ef8ffcbd..00000000 --- a/frontend/src/components/tool-ui/shared/_adapter.tsx +++ /dev/null @@ -1,2 +0,0 @@ -export { cn } from "@/lib/utils"; -export { Button } from "@/components/ui/button";