66 type BaseClientToolMetadata ,
77 ClientToolCallState ,
88} from '@/lib/copilot/tools/client/base-tool'
9- import { useCustomToolsStore } from '@/stores /custom-tools'
9+ import { getCustomTool } from '@/hooks/queries /custom-tools'
1010import { useCopilotStore } from '@/stores/panel/copilot/store'
1111import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
1212
@@ -83,17 +83,15 @@ export class ManageCustomToolClientTool extends BaseClientTool {
8383 getDynamicText : ( params , state ) => {
8484 const operation = params ?. operation as 'add' | 'edit' | 'delete' | 'list' | undefined
8585
86- // Return undefined if no operation yet - use static defaults
8786 if ( ! operation ) return undefined
8887
89- // Get tool name from schema, or look it up from the store by toolId
9088 let toolName = params ?. schema ?. function ?. name
9189 if ( ! toolName && params ?. toolId ) {
9290 try {
93- const tool = useCustomToolsStore . getState ( ) . getTool ( params . toolId )
91+ const tool = getCustomTool ( params . toolId )
9492 toolName = tool ?. schema ?. function ?. name
9593 } catch {
96- // Ignore errors accessing store
94+ // Ignore errors accessing cache
9795 }
9896 }
9997
@@ -168,7 +166,6 @@ export class ManageCustomToolClientTool extends BaseClientTool {
168166 * Add operations execute directly without confirmation.
169167 */
170168 getInterruptDisplays ( ) : BaseClientToolMetadata [ 'interrupt' ] | undefined {
171- // Try currentArgs first, then fall back to store (for when called before execute())
172169 const args = this . currentArgs || this . getArgsFromStore ( )
173170 const operation = args ?. operation
174171 if ( operation === 'edit' || operation === 'delete' ) {
@@ -199,12 +196,9 @@ export class ManageCustomToolClientTool extends BaseClientTool {
199196
200197 async execute ( args ?: ManageCustomToolArgs ) : Promise < void > {
201198 this . currentArgs = args
202- // For add and list operations, execute directly without confirmation
203- // For edit/delete, the copilot store will check hasInterrupt() and wait for confirmation
204199 if ( args ?. operation === 'add' || args ?. operation === 'list' ) {
205200 await this . handleAccept ( args )
206201 }
207- // edit/delete will wait for user confirmation via handleAccept
208202 }
209203
210204 /**
@@ -222,7 +216,6 @@ export class ManageCustomToolClientTool extends BaseClientTool {
222216
223217 const { operation, toolId, schema, code } = args
224218
225- // Get workspace ID from the workflow registry
226219 const { hydration } = useWorkflowRegistry . getState ( )
227220 const workspaceId = hydration . workspaceId
228221 if ( ! workspaceId ) {
@@ -247,7 +240,6 @@ export class ManageCustomToolClientTool extends BaseClientTool {
247240 await this . deleteCustomTool ( { toolId, workspaceId } , logger )
248241 break
249242 case 'list' :
250- // List operation is read-only, just mark as complete
251243 await this . markToolComplete ( 200 , 'Listed custom tools' )
252244 break
253245 default :
@@ -326,13 +318,10 @@ export class ManageCustomToolClientTool extends BaseClientTool {
326318 throw new Error ( 'Tool ID is required for editing a custom tool' )
327319 }
328320
329- // At least one of schema or code must be provided
330321 if ( ! schema && ! code ) {
331322 throw new Error ( 'At least one of schema or code must be provided for editing' )
332323 }
333324
334- // We need to send the full tool data to the API for updates
335- // First, fetch the existing tool to merge with updates
336325 const existingResponse = await fetch ( `${ API_ENDPOINT } ?workspaceId=${ workspaceId } ` )
337326 const existingData = await existingResponse . json ( )
338327
@@ -345,7 +334,6 @@ export class ManageCustomToolClientTool extends BaseClientTool {
345334 throw new Error ( `Tool with ID ${ toolId } not found` )
346335 }
347336
348- // Merge updates with existing tool - use function name as title
349337 const mergedSchema = schema ?? existingTool . schema
350338 const updatedTool = {
351339 id : toolId ,
0 commit comments