Update tool definitions to use isLibrary

This commit is contained in:
akhisud3195 2025-04-15 16:38:50 +04:00 committed by Ramnique Singh
parent 3d4702c83e
commit dbd836d5e6
6 changed files with 35 additions and 52 deletions

View file

@ -49,8 +49,6 @@ export async function fetchMcpTools(projectId: string): Promise<z.infer<typeof W
const tool: z.infer<typeof WorkflowTool> = { const tool: z.infer<typeof WorkflowTool> = {
name: mcpTool.name, name: mcpTool.name,
description: mcpTool.description ?? "", description: mcpTool.description ?? "",
type: 'library',
implementation: 'default',
parameters: { parameters: {
type: "object", type: "object",
properties: props ?? {}, properties: props ?? {},

View file

@ -55,12 +55,11 @@ You are an helpful customer support assistant
{ {
"name": "web_search", "name": "web_search",
"description": "Fetch information from the web based on chat context", "description": "Fetch information from the web based on chat context",
"type": "library",
"parameters": { "parameters": {
"type": "object", "type": "object",
"properties": {}, "properties": {},
}, },
"implementation": "default", "isLibrary": true
} }
], ],
} }

View file

@ -36,15 +36,7 @@ export const WorkflowPrompt = z.object({
export const WorkflowTool = z.object({ export const WorkflowTool = z.object({
name: z.string(), name: z.string(),
description: z.string(), description: z.string(),
type: z.union([ mockTool: z.boolean().default(false).optional(),
z.literal('library'),
z.literal('custom'),
]).default('custom'),
implementation: z.union([
z.literal('mock'),
z.literal('default'),
z.literal('api')
]).default('mock'),
autoSubmitMockedResponse: z.boolean().default(false).optional(), autoSubmitMockedResponse: z.boolean().default(false).optional(),
mockInstructions: z.string().optional(), mockInstructions: z.string().optional(),
parameters: z.object({ parameters: z.object({
@ -56,6 +48,7 @@ export const WorkflowTool = z.object({
required: z.array(z.string()).optional(), required: z.array(z.string()).optional(),
}), }),
isMcp: z.boolean().default(false).optional(), isMcp: z.boolean().default(false).optional(),
isLibrary: z.boolean().default(false).optional(),
mcpServerName: z.string().optional(), mcpServerName: z.string().optional(),
}); });
export const Workflow = z.object({ export const Workflow = z.object({

View file

@ -2,7 +2,7 @@
import { WorkflowTool } from "../../../lib/types/workflow_types"; import { WorkflowTool } from "../../../lib/types/workflow_types";
import { Checkbox, Select, SelectItem, RadioGroup, Radio } from "@heroui/react"; import { Checkbox, Select, SelectItem, RadioGroup, Radio } from "@heroui/react";
import { z } from "zod"; import { z } from "zod";
import { ImportIcon, XIcon, PlusIcon } from "lucide-react"; import { ImportIcon, XIcon, PlusIcon, FolderIcon } from "lucide-react";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { Textarea } from "@/components/ui/textarea"; import { Textarea } from "@/components/ui/textarea";
import { Panel } from "@/components/common/panel-common"; import { Panel } from "@/components/common/panel-common";
@ -161,7 +161,7 @@ export function ToolConfig({
handleClose: () => void handleClose: () => void
}) { }) {
const [selectedParams, setSelectedParams] = useState(new Set([])); const [selectedParams, setSelectedParams] = useState(new Set([]));
const isReadOnly = tool.isMcp; const isReadOnly = tool.isMcp || tool.isLibrary;
const [nameError, setNameError] = useState<string | null>(null); const [nameError, setNameError] = useState<string | null>(null);
function handleParamRename(oldName: string, newName: string) { function handleParamRename(oldName: string, newName: string) {
@ -245,6 +245,12 @@ export function ToolConfig({
<span className="text-xs">MCP: {tool.mcpServerName}</span> <span className="text-xs">MCP: {tool.mcpServerName}</span>
</div> </div>
)} )}
{tool.isLibrary && (
<div className="flex items-center gap-2 text-sm bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded-full text-gray-700 dark:text-gray-300">
<FolderIcon className="w-4 h-4 text-blue-700 dark:text-blue-400" />
<span className="text-xs">Library Tool</span>
</div>
)}
</div> </div>
<Button <Button
variant="secondary" variant="secondary"
@ -259,7 +265,7 @@ export function ToolConfig({
} }
> >
<div className="flex flex-col gap-6 p-4"> <div className="flex flex-col gap-6 p-4">
{!isReadOnly && tool.type !== 'library' && ( {!isReadOnly && (
<div className="space-y-4"> <div className="space-y-4">
<div className="space-y-2"> <div className="space-y-2">
<label className={sectionHeaderStyles}> <label className={sectionHeaderStyles}>
@ -310,7 +316,7 @@ export function ToolConfig({
description: e.target.value description: e.target.value
})} })}
placeholder="Describe what this tool does..." placeholder="Describe what this tool does..."
disabled={isReadOnly || tool.type === 'library'} disabled={isReadOnly}
className={textareaStyles} className={textareaStyles}
autoResize autoResize
/> />
@ -324,13 +330,12 @@ export function ToolConfig({
</label> </label>
<RadioGroup <RadioGroup
defaultValue={tool.implementation} defaultValue="mock"
value={tool.implementation} value={tool.mockTool ? "mock" : "api"}
onValueChange={(value) => handleUpdate({ onValueChange={(value) => handleUpdate({
...tool, ...tool,
implementation: value as "mock" | "default" | "api", mockTool: value === "mock",
autoSubmitMockedResponse: value === "mock" ? true : undefined, autoSubmitMockedResponse: value === "mock" ? true : undefined
mockInstructions: value === "mock" ? tool.mockInstructions : undefined
})} })}
orientation="horizontal" orientation="horizontal"
classNames={{ classNames={{
@ -347,32 +352,20 @@ export function ToolConfig({
> >
Mock tool responses Mock tool responses
</Radio> </Radio>
{tool.type === "library" ? ( <Radio
<Radio value="api"
value="default" classNames={{
classNames={{ base: "p-0 data-[selected=true]:bg-indigo-50 dark:data-[selected=true]:bg-indigo-900/50 rounded-lg transition-colors",
base: "p-0 data-[selected=true]:bg-indigo-50 dark:data-[selected=true]:bg-indigo-900/50 rounded-lg transition-colors", label: "text-base font-normal text-gray-900 dark:text-gray-100 px-3 py-1"
label: "text-base font-normal text-gray-900 dark:text-gray-100 px-3 py-1" }}
}} >
> Connect tool to your API
Use default implementation </Radio>
</Radio>
) : (
<Radio
value="api"
classNames={{
base: "p-0 data-[selected=true]:bg-indigo-50 dark:data-[selected=true]:bg-indigo-900/50 rounded-lg transition-colors",
label: "text-base font-normal text-gray-900 dark:text-gray-100 px-3 py-1"
}}
>
Connect tool to your API
</Radio>
)}
</RadioGroup> </RadioGroup>
</div> </div>
)} )}
{tool.implementation === "mock" && ( {tool.mockTool && (
<div className={`space-y-4 ${dividerStyles} pt-6`}> <div className={`space-y-4 ${dividerStyles} pt-6`}>
<div className="space-y-4"> <div className="space-y-4">
<label className={sectionHeaderStyles}> <label className={sectionHeaderStyles}>
@ -424,12 +417,12 @@ export function ToolConfig({
handleUpdate={handleParamUpdate} handleUpdate={handleParamUpdate}
handleDelete={handleParamDelete} handleDelete={handleParamDelete}
handleRename={handleParamRename} handleRename={handleParamRename}
readOnly={isReadOnly || tool.type === 'library'} readOnly={isReadOnly}
/> />
))} ))}
</div> </div>
{!isReadOnly && tool.type !== 'library' && ( {!isReadOnly && (
<div className="pl-3"> <div className="pl-3">
<Button <Button
variant="primary" variant="primary"
@ -447,8 +440,6 @@ export function ToolConfig({
handleUpdate({ handleUpdate({
...tool, ...tool,
type: 'custom',
implementation: 'mock',
parameters: { parameters: {
type: 'object', type: 'object',
properties: newProperties, properties: newProperties,

View file

@ -237,8 +237,11 @@ export function EntityList({
variant="secondary" variant="secondary"
size="sm" size="sm"
onClick={() => onAddTool({ onClick={() => onAddTool({
type: 'custom', mockTool: true,
implementation: 'mock' parameters: {
type: 'object',
properties: {}
}
})} })}
className={`group ${buttonClasses}`} className={`group ${buttonClasses}`}
showHoverContent={true} showHoverContent={true}

View file

@ -295,8 +295,7 @@ function reducer(state: State, action: Action): State {
type: 'object', type: 'object',
properties: {}, properties: {},
}, },
type: 'custom', mockTool: true,
implementation: 'mock',
autoSubmitMockedResponse: true, autoSubmitMockedResponse: true,
...action.tool ...action.tool
}); });