MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / execute

Method execute

src/core/tools/GenerateImageTool.ts:24–259  ·  view source on GitHub ↗
(params: GenerateImageParams, task: Task, callbacks: ToolCallbacks)

Source from the content-addressed store, hash-verified

22 readonly name = "generate_image" as const
23
24 async execute(params: GenerateImageParams, task: Task, callbacks: ToolCallbacks): Promise<void> {
25 const { prompt, path: relPath, image: inputImagePath } = params
26 const { handleError, pushToolResult, askApproval } = callbacks
27
28 const provider = task.providerRef.deref()
29 const state = await provider?.getState()
30 const isImageGenerationEnabled = experiments.isEnabled(
31 state?.experiments ?? {},
32 EXPERIMENT_IDS.IMAGE_GENERATION,
33 )
34
35 if (!isImageGenerationEnabled) {
36 pushToolResult(
37 formatResponse.toolError(
38 "Image generation is an experimental feature that must be enabled in settings. Please enable 'Image Generation' in the Experimental Settings section.",
39 ),
40 )
41 return
42 }
43
44 if (!prompt) {
45 task.consecutiveMistakeCount++
46 task.recordToolError("generate_image")
47 pushToolResult(await task.sayAndCreateMissingParamError("generate_image", "prompt"))
48 return
49 }
50
51 if (!relPath) {
52 task.consecutiveMistakeCount++
53 task.recordToolError("generate_image")
54 pushToolResult(await task.sayAndCreateMissingParamError("generate_image", "path"))
55 return
56 }
57
58 const accessAllowed = task.rooIgnoreController?.validateAccess(relPath)
59 if (!accessAllowed) {
60 await task.say("rooignore_error", relPath)
61 pushToolResult(formatResponse.rooIgnoreError(relPath))
62 return
63 }
64
65 let inputImageData: string | undefined
66 if (inputImagePath) {
67 const inputImageFullPath = path.resolve(task.cwd, inputImagePath)
68
69 const inputImageExists = await fileExistsAtPath(inputImageFullPath)
70 if (!inputImageExists) {
71 await task.say("error", `Input image not found: ${getReadablePath(task.cwd, inputImagePath)}`)
72 task.didToolFailInCurrentTurn = true
73 pushToolResult(
74 formatResponse.toolError(`Input image not found: ${getReadablePath(task.cwd, inputImagePath)}`),
75 )
76 return
77 }
78
79 const inputImageAccessAllowed = task.rooIgnoreController?.validateAccess(inputImagePath)
80 if (!inputImageAccessAllowed) {
81 await task.say("rooignore_error", inputImagePath)

Callers

nothing calls this directly

Calls 15

generateImageMethod · 0.95
fileExistsAtPathFunction · 0.90
getReadablePathFunction · 0.90
tFunction · 0.90
isPathOutsideWorkspaceFunction · 0.90
pushToolResultFunction · 0.85
askApprovalFunction · 0.85
handleErrorFunction · 0.85
isEnabledMethod · 0.80
recordToolErrorMethod · 0.80

Tested by

no test coverage detected