mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-11 12:17:45 +02:00
[Haik]: refactor: remove global components/tool-ui/shared/ directory and colocate its modules under AgentChat/toolkit — move ToolUI schemas to toolkit/utils/schema, action types to approvalToolkit/utils/types, ActionButtons component to approvalToolkit/components/ActionButtons, actions-config and embedded-actions to OptionList/utils, and getMcpInputSummary and useMcpToolMeta to approvalToolkit/utils; update all imports across approvalToolkit and nativeToolkit
This commit is contained in:
+4
-3
@@ -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[];
|
||||
+1
-1
@@ -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[];
|
||||
+2
-2
@@ -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";
|
||||
|
||||
|
||||
+1
-1
@@ -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),
|
||||
|
||||
+2
-2
@@ -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';
|
||||
|
||||
|
||||
+4
-3
@@ -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";
|
||||
|
||||
|
||||
+4
-5
@@ -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),
|
||||
|
||||
+1
-1
@@ -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),
|
||||
|
||||
@@ -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<ReactNode>().optional(),
|
||||
loading: z.boolean().optional(),
|
||||
disabled: z.boolean().optional(),
|
||||
shortcut: z.string().optional(),
|
||||
});
|
||||
|
||||
export type Action = z.infer<typeof ActionSchema>;
|
||||
|
||||
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(),
|
||||
});
|
||||
+1
-1
@@ -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,
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import {
|
||||
ToolUIIdSchema,
|
||||
ToolUIReceiptSchema,
|
||||
ToolUIRoleSchema,
|
||||
} from "../shared/schema";
|
||||
} from "@/app/pages/AgentChat/toolkit/utils/schema";
|
||||
|
||||
const CodeDiffPropsSchemaBase = z.object({
|
||||
id: ToolUIIdSchema,
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
-36
@@ -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<ReactNode>().optional(),
|
||||
loading: z.boolean().optional(),
|
||||
disabled: z.boolean().optional(),
|
||||
shortcut: z.string().optional(),
|
||||
});
|
||||
|
||||
export type Action = z.infer<typeof ActionSchema>;
|
||||
|
||||
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(),
|
||||
});
|
||||
@@ -1,2 +0,0 @@
|
||||
export { cn } from "@/lib/utils";
|
||||
export { Button } from "@/components/ui/button";
|
||||
Reference in New Issue
Block a user