@zds-ai/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +497 -0
- package/dist/agent/grok-agent.d.ts +250 -0
- package/dist/agent/grok-agent.js +2480 -0
- package/dist/agent/grok-agent.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.js +136 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.js +239 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/grok/client.d.ts +55 -0
- package/dist/grok/client.js +276 -0
- package/dist/grok/client.js.map +1 -0
- package/dist/grok/tools.d.ts +8 -0
- package/dist/grok/tools.js +878 -0
- package/dist/grok/tools.js.map +1 -0
- package/dist/hooks/use-enhanced-input.d.ts +38 -0
- package/dist/hooks/use-enhanced-input.js +228 -0
- package/dist/hooks/use-enhanced-input.js.map +1 -0
- package/dist/hooks/use-input-handler.d.ts +36 -0
- package/dist/hooks/use-input-handler.js +1099 -0
- package/dist/hooks/use-input-handler.js.map +1 -0
- package/dist/hooks/use-input-history.d.ts +9 -0
- package/dist/hooks/use-input-history.js +61 -0
- package/dist/hooks/use-input-history.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +869 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +41 -0
- package/dist/mcp/client.js +224 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/config.d.ts +13 -0
- package/dist/mcp/config.js +56 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/transports.d.ts +53 -0
- package/dist/mcp/transports.js +256 -0
- package/dist/mcp/transports.js.map +1 -0
- package/dist/tools/character-tool.d.ts +27 -0
- package/dist/tools/character-tool.js +194 -0
- package/dist/tools/character-tool.js.map +1 -0
- package/dist/tools/clear-cache-tool.d.ts +14 -0
- package/dist/tools/clear-cache-tool.js +82 -0
- package/dist/tools/clear-cache-tool.js.map +1 -0
- package/dist/tools/confirmation-tool.d.ts +16 -0
- package/dist/tools/confirmation-tool.js +72 -0
- package/dist/tools/confirmation-tool.js.map +1 -0
- package/dist/tools/env-tool.d.ts +17 -0
- package/dist/tools/env-tool.js +89 -0
- package/dist/tools/env-tool.js.map +1 -0
- package/dist/tools/file-conversion-tool.d.ts +16 -0
- package/dist/tools/file-conversion-tool.js +181 -0
- package/dist/tools/file-conversion-tool.js.map +1 -0
- package/dist/tools/image-tool.d.ts +22 -0
- package/dist/tools/image-tool.js +268 -0
- package/dist/tools/image-tool.js.map +1 -0
- package/dist/tools/index.d.ts +14 -0
- package/dist/tools/index.js +15 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internet-tool.d.ts +11 -0
- package/dist/tools/internet-tool.js +108 -0
- package/dist/tools/internet-tool.js.map +1 -0
- package/dist/tools/introspect-tool.d.ts +11 -0
- package/dist/tools/introspect-tool.js +243 -0
- package/dist/tools/introspect-tool.js.map +1 -0
- package/dist/tools/morph-editor.d.ts +38 -0
- package/dist/tools/morph-editor.js +318 -0
- package/dist/tools/morph-editor.js.map +1 -0
- package/dist/tools/restart-tool.d.ts +7 -0
- package/dist/tools/restart-tool.js +24 -0
- package/dist/tools/restart-tool.js.map +1 -0
- package/dist/tools/search.d.ts +71 -0
- package/dist/tools/search.js +340 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/task-tool.d.ts +19 -0
- package/dist/tools/task-tool.js +115 -0
- package/dist/tools/task-tool.js.map +1 -0
- package/dist/tools/text-editor.d.ts +35 -0
- package/dist/tools/text-editor.js +669 -0
- package/dist/tools/text-editor.js.map +1 -0
- package/dist/tools/tool-discovery.d.ts +20 -0
- package/dist/tools/tool-discovery.js +45 -0
- package/dist/tools/tool-discovery.js.map +1 -0
- package/dist/tools/zsh.d.ts +13 -0
- package/dist/tools/zsh.js +168 -0
- package/dist/tools/zsh.js.map +1 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/app.d.ts +7 -0
- package/dist/ui/app.js +99 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/components/active-task-status.d.ts +7 -0
- package/dist/ui/components/active-task-status.js +37 -0
- package/dist/ui/components/active-task-status.js.map +1 -0
- package/dist/ui/components/api-key-input.d.ts +7 -0
- package/dist/ui/components/api-key-input.js +80 -0
- package/dist/ui/components/api-key-input.js.map +1 -0
- package/dist/ui/components/backend-status.d.ts +7 -0
- package/dist/ui/components/backend-status.js +85 -0
- package/dist/ui/components/backend-status.js.map +1 -0
- package/dist/ui/components/chat-history.d.ts +8 -0
- package/dist/ui/components/chat-history.js +187 -0
- package/dist/ui/components/chat-history.js.map +1 -0
- package/dist/ui/components/chat-input.d.ts +9 -0
- package/dist/ui/components/chat-input.js +63 -0
- package/dist/ui/components/chat-input.js.map +1 -0
- package/dist/ui/components/chat-interface.d.ts +9 -0
- package/dist/ui/components/chat-interface.js +389 -0
- package/dist/ui/components/chat-interface.js.map +1 -0
- package/dist/ui/components/command-suggestions.d.ts +17 -0
- package/dist/ui/components/command-suggestions.js +22 -0
- package/dist/ui/components/command-suggestions.js.map +1 -0
- package/dist/ui/components/confirmation-dialog.d.ts +11 -0
- package/dist/ui/components/confirmation-dialog.js +105 -0
- package/dist/ui/components/confirmation-dialog.js.map +1 -0
- package/dist/ui/components/context-status.d.ts +7 -0
- package/dist/ui/components/context-status.js +36 -0
- package/dist/ui/components/context-status.js.map +1 -0
- package/dist/ui/components/diff-renderer.d.ts +13 -0
- package/dist/ui/components/diff-renderer.js +206 -0
- package/dist/ui/components/diff-renderer.js.map +1 -0
- package/dist/ui/components/loading-spinner.d.ts +8 -0
- package/dist/ui/components/loading-spinner.js +64 -0
- package/dist/ui/components/loading-spinner.js.map +1 -0
- package/dist/ui/components/mcp-status.d.ts +5 -0
- package/dist/ui/components/mcp-status.js +57 -0
- package/dist/ui/components/mcp-status.js.map +1 -0
- package/dist/ui/components/model-selection.d.ts +12 -0
- package/dist/ui/components/model-selection.js +17 -0
- package/dist/ui/components/model-selection.js.map +1 -0
- package/dist/ui/components/mood-status.d.ts +7 -0
- package/dist/ui/components/mood-status.js +34 -0
- package/dist/ui/components/mood-status.js.map +1 -0
- package/dist/ui/components/persona-status.d.ts +7 -0
- package/dist/ui/components/persona-status.js +34 -0
- package/dist/ui/components/persona-status.js.map +1 -0
- package/dist/ui/shared/max-sized-box.d.ts +8 -0
- package/dist/ui/shared/max-sized-box.js +6 -0
- package/dist/ui/shared/max-sized-box.js.map +1 -0
- package/dist/ui/utils/code-colorizer.d.ts +2 -0
- package/dist/ui/utils/code-colorizer.js +7 -0
- package/dist/ui/utils/code-colorizer.js.map +1 -0
- package/dist/ui/utils/colors.d.ts +14 -0
- package/dist/ui/utils/colors.js +15 -0
- package/dist/ui/utils/colors.js.map +1 -0
- package/dist/ui/utils/markdown-renderer.d.ts +4 -0
- package/dist/ui/utils/markdown-renderer.js +40 -0
- package/dist/ui/utils/markdown-renderer.js.map +1 -0
- package/dist/utils/auth-helper.d.ts +63 -0
- package/dist/utils/auth-helper.js +129 -0
- package/dist/utils/auth-helper.js.map +1 -0
- package/dist/utils/chat-history-manager-sqlite.d.ts +92 -0
- package/dist/utils/chat-history-manager-sqlite.js +334 -0
- package/dist/utils/chat-history-manager-sqlite.js.map +1 -0
- package/dist/utils/chat-history-manager.d.ts +87 -0
- package/dist/utils/chat-history-manager.js +273 -0
- package/dist/utils/chat-history-manager.js.map +1 -0
- package/dist/utils/chat-history-manager.json-backup.d.ts +69 -0
- package/dist/utils/chat-history-manager.json-backup.js +215 -0
- package/dist/utils/chat-history-manager.json-backup.js.map +1 -0
- package/dist/utils/confirmation-service.d.ts +46 -0
- package/dist/utils/confirmation-service.js +165 -0
- package/dist/utils/confirmation-service.js.map +1 -0
- package/dist/utils/custom-instructions.d.ts +1 -0
- package/dist/utils/custom-instructions.js +30 -0
- package/dist/utils/custom-instructions.js.map +1 -0
- package/dist/utils/database-connection.d.ts +27 -0
- package/dist/utils/database-connection.js +81 -0
- package/dist/utils/database-connection.js.map +1 -0
- package/dist/utils/database-schema.d.ts +17 -0
- package/dist/utils/database-schema.js +93 -0
- package/dist/utils/database-schema.js.map +1 -0
- package/dist/utils/error-logger.d.ts +13 -0
- package/dist/utils/error-logger.js +56 -0
- package/dist/utils/error-logger.js.map +1 -0
- package/dist/utils/hook-executor.d.ts +59 -0
- package/dist/utils/hook-executor.js +351 -0
- package/dist/utils/hook-executor.js.map +1 -0
- package/dist/utils/model-config.d.ts +28 -0
- package/dist/utils/model-config.js +42 -0
- package/dist/utils/model-config.js.map +1 -0
- package/dist/utils/path-utils.d.ts +4 -0
- package/dist/utils/path-utils.js +12 -0
- package/dist/utils/path-utils.js.map +1 -0
- package/dist/utils/settings-manager.d.ts +169 -0
- package/dist/utils/settings-manager.js +403 -0
- package/dist/utils/settings-manager.js.map +1 -0
- package/dist/utils/settings.d.ts +1 -0
- package/dist/utils/settings.js +4 -0
- package/dist/utils/settings.js.map +1 -0
- package/dist/utils/slash-commands.d.ts +25 -0
- package/dist/utils/slash-commands.js +454 -0
- package/dist/utils/slash-commands.js.map +1 -0
- package/dist/utils/startup-hook.d.ts +13 -0
- package/dist/utils/startup-hook.js +44 -0
- package/dist/utils/startup-hook.js.map +1 -0
- package/dist/utils/text-utils.d.ts +80 -0
- package/dist/utils/text-utils.js +182 -0
- package/dist/utils/text-utils.js.map +1 -0
- package/dist/utils/token-counter.d.ts +33 -0
- package/dist/utils/token-counter.js +78 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { exec } from "child_process";
|
|
2
|
+
import { promisify } from "util";
|
|
3
|
+
import { getHandledToolNames } from "./tool-discovery.js";
|
|
4
|
+
const execAsync = promisify(exec);
|
|
5
|
+
export class ImageTool {
|
|
6
|
+
agent; // Reference to the GrokAgent
|
|
7
|
+
setAgent(agent) {
|
|
8
|
+
this.agent = agent;
|
|
9
|
+
}
|
|
10
|
+
getHandledToolNames() {
|
|
11
|
+
return getHandledToolNames(this);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generate an image using AI image generation.
|
|
15
|
+
* Uses generate_image_asl.sh script with Stable Diffusion.
|
|
16
|
+
*/
|
|
17
|
+
async generateImage(prompt, negativePrompt, width, height, model, sampler, configScale, numSteps, nsfw, name, move, seed) {
|
|
18
|
+
try {
|
|
19
|
+
if (!prompt) {
|
|
20
|
+
return {
|
|
21
|
+
success: false,
|
|
22
|
+
error: "Prompt is required",
|
|
23
|
+
output: "Prompt is required"
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (!this.agent) {
|
|
27
|
+
return {
|
|
28
|
+
success: false,
|
|
29
|
+
error: "Agent not available",
|
|
30
|
+
output: "Agent not available"
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// Get the agent's home directory and create Images path
|
|
34
|
+
const agentHome = process.env.ZDS_AI_AGENT_HOME_DIR;
|
|
35
|
+
if (!agentHome) {
|
|
36
|
+
return {
|
|
37
|
+
success: false,
|
|
38
|
+
error: "Agent home directory not found",
|
|
39
|
+
output: "Agent home directory not found"
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const imagesDir = `${agentHome}/Images`;
|
|
43
|
+
// Ensure Images directory exists
|
|
44
|
+
try {
|
|
45
|
+
await execAsync(`mkdir -p "${imagesDir}"`);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
error: `Failed to create Images directory: ${error}`,
|
|
51
|
+
output: `Failed to create Images directory: ${error}`
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Set defaults
|
|
55
|
+
const defaultNegativePrompt = "score_6, score_5, score_4, (worst quality:1.2), (low quality:1.2), (normal quality:1.2), lowres, bad anatomy, bad hands, signature, watermarks, ugly, imperfect eyes, skewed eyes, unnatural face, unnatural body, error, extra limb, missing limbs";
|
|
56
|
+
const finalModel = model || "cyberrealisticPony_v130";
|
|
57
|
+
const finalWidth = Math.floor(width || 480);
|
|
58
|
+
const finalHeight = Math.floor(height || 720);
|
|
59
|
+
const finalSampler = sampler || "DPM++ 2M Karras";
|
|
60
|
+
const finalConfigScale = configScale || 5.0;
|
|
61
|
+
const finalNumSteps = Math.floor(numSteps || 30);
|
|
62
|
+
const finalNsfw = nsfw !== undefined ? nsfw : false;
|
|
63
|
+
const finalMove = move !== undefined ? move : false;
|
|
64
|
+
const finalNegativePrompt = negativePrompt || defaultNegativePrompt;
|
|
65
|
+
// Handle NSFW flag: when nsfw=true, allow NSFW content (prepend to prompt)
|
|
66
|
+
// when nsfw=false (default), avoid NSFW content (prepend to negative prompt)
|
|
67
|
+
const finalPrompt = finalNsfw ? `NSFW, ${prompt}` : prompt;
|
|
68
|
+
// If nsfw is on, strip out any "NSFW" from negative prompt (case-insensitive)
|
|
69
|
+
let finalNegativePromptWithNsfw;
|
|
70
|
+
if (finalNsfw) {
|
|
71
|
+
// Remove all "NSFW" variants - keep replacing until none left
|
|
72
|
+
finalNegativePromptWithNsfw = finalNegativePrompt;
|
|
73
|
+
let prev = '';
|
|
74
|
+
while (prev !== finalNegativePromptWithNsfw) {
|
|
75
|
+
prev = finalNegativePromptWithNsfw;
|
|
76
|
+
finalNegativePromptWithNsfw = finalNegativePromptWithNsfw
|
|
77
|
+
.replace(/NSFW,?\s*/gi, '') // Remove NSFW with optional comma and spaces
|
|
78
|
+
.replace(/,\s*,/g, ',') // Clean up double commas
|
|
79
|
+
.replace(/^\s*,\s*/, '') // Remove leading comma
|
|
80
|
+
.trim();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// nsfw is off, prepend "NSFW, " to block NSFW content
|
|
85
|
+
finalNegativePromptWithNsfw = `NSFW, ${finalNegativePrompt}`;
|
|
86
|
+
}
|
|
87
|
+
// Escape prompts for shell
|
|
88
|
+
const escapedPrompt = finalPrompt.replace(/'/g, "'\\''");
|
|
89
|
+
const escapedNegativePrompt = finalNegativePromptWithNsfw.replace(/'/g, "'\\''");
|
|
90
|
+
// Build command using generate_image_asl.sh
|
|
91
|
+
let command = `generate_image_asl.sh '${escapedPrompt}' '${escapedNegativePrompt}'`;
|
|
92
|
+
if (finalMove) {
|
|
93
|
+
command += ' --move';
|
|
94
|
+
}
|
|
95
|
+
command += ` --width ${finalWidth} --height ${finalHeight} --cfg-scale ${finalConfigScale} --steps ${finalNumSteps} --sampler '${finalSampler}' --model '${finalModel}'`;
|
|
96
|
+
if (seed !== undefined) {
|
|
97
|
+
command += ` --seed ${Math.floor(seed)}`;
|
|
98
|
+
}
|
|
99
|
+
if (name) {
|
|
100
|
+
const escapedName = name.replace(/'/g, "'\\''");
|
|
101
|
+
command += ` --name '${escapedName}'`;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
105
|
+
timeout: 300000 // 5 minute timeout
|
|
106
|
+
});
|
|
107
|
+
// Parse output to find the generated file path
|
|
108
|
+
// The script must output the absolute path to the generated image
|
|
109
|
+
const lines = stdout.trim().split('\n');
|
|
110
|
+
const lastLine = lines[lines.length - 1];
|
|
111
|
+
// Verify we got an absolute path
|
|
112
|
+
if (!lastLine.startsWith('/')) {
|
|
113
|
+
return {
|
|
114
|
+
success: false,
|
|
115
|
+
error: `Image generation script did not return a valid file path. Output: ${stdout}`,
|
|
116
|
+
output: `Image generation failed - no file path returned.\n\nScript output:\n${stdout}`
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const filepath = lastLine;
|
|
120
|
+
// Get file size if file exists
|
|
121
|
+
let fileSize = "unknown";
|
|
122
|
+
try {
|
|
123
|
+
const { stdout: sizeOutput } = await execAsync(`ls -lh "${filepath}" 2>/dev/null | awk '{print $5}'`);
|
|
124
|
+
fileSize = sizeOutput.trim() || "unknown";
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
fileSize = "unknown";
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
output: `Image generated successfully\nPrompt: ${prompt}\nModel: ${finalModel}\nSize: ${finalWidth}x${finalHeight}\nSteps: ${finalNumSteps}\nGuidance: ${finalConfigScale}\nPath: ${filepath}\nFile Size: ${fileSize}`,
|
|
132
|
+
displayOutput: `Generated image (${finalWidth}x${finalHeight})`
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
return {
|
|
137
|
+
success: false,
|
|
138
|
+
error: `Image generation failed: ${error.message}`,
|
|
139
|
+
output: `Image generation failed: ${error.message}`
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
return {
|
|
145
|
+
success: false,
|
|
146
|
+
error: error instanceof Error ? error.message : "Unknown error generating image",
|
|
147
|
+
output: error instanceof Error ? error.message : "Unknown error generating image"
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Caption an image using AI image captioning.
|
|
153
|
+
* Uses joycaption script.
|
|
154
|
+
*/
|
|
155
|
+
async captionImage(filename, prompt) {
|
|
156
|
+
try {
|
|
157
|
+
if (!filename) {
|
|
158
|
+
return {
|
|
159
|
+
success: false,
|
|
160
|
+
error: "Filename is required",
|
|
161
|
+
output: "Filename is required"
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
// Build command using joycaption
|
|
165
|
+
let command = `joycaption '${filename.replace(/'/g, "'\\''")}'`;
|
|
166
|
+
if (prompt) {
|
|
167
|
+
command += ` --prompt "${prompt.replace(/"/g, '\\"')}"`;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
171
|
+
timeout: 90000, // 90 second timeout
|
|
172
|
+
shell: '/bin/zsh'
|
|
173
|
+
});
|
|
174
|
+
// If there's stderr output, include it but still return success if we got stdout
|
|
175
|
+
if (stderr && !stdout) {
|
|
176
|
+
return {
|
|
177
|
+
success: false,
|
|
178
|
+
error: `Image captioning failed: ${stderr}`,
|
|
179
|
+
output: stderr
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const caption = stdout.trim();
|
|
183
|
+
return {
|
|
184
|
+
success: true,
|
|
185
|
+
output: caption,
|
|
186
|
+
displayOutput: `Caption: ${caption}`
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
// Extract error details
|
|
191
|
+
const errorMessage = error.message || "Unknown error";
|
|
192
|
+
const stderr = error.stderr || "";
|
|
193
|
+
const stdout = error.stdout || "";
|
|
194
|
+
return {
|
|
195
|
+
success: false,
|
|
196
|
+
error: `Image captioning failed (code ${error.code || 'unknown'}): ${errorMessage}${stderr ? '\nstderr: ' + stderr : ''}${stdout ? '\nstdout: ' + stdout : ''}`,
|
|
197
|
+
output: `Error code: ${error.code || 'unknown'}\n${errorMessage}${stderr ? '\nstderr: ' + stderr : ''}${stdout ? '\nstdout: ' + stdout : ''}`
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
return {
|
|
203
|
+
success: false,
|
|
204
|
+
error: error instanceof Error ? error.message : "Unknown error captioning image",
|
|
205
|
+
output: error instanceof Error ? error.message : "Unknown error captioning image"
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Extract PNG metadata (generation settings) from a PNG file.
|
|
211
|
+
* Uses exiftool to read embedded generation parameters.
|
|
212
|
+
*/
|
|
213
|
+
async pngInfo(filename) {
|
|
214
|
+
try {
|
|
215
|
+
if (!filename) {
|
|
216
|
+
return {
|
|
217
|
+
success: false,
|
|
218
|
+
error: "Filename is required",
|
|
219
|
+
output: "Filename is required"
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const escapedFilename = filename.replace(/'/g, "'\\''");
|
|
223
|
+
const command = `exiftool -Parameters '${escapedFilename}'`;
|
|
224
|
+
try {
|
|
225
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
226
|
+
timeout: 10000 // 10 second timeout
|
|
227
|
+
});
|
|
228
|
+
if (stderr && !stdout) {
|
|
229
|
+
return {
|
|
230
|
+
success: false,
|
|
231
|
+
error: `Failed to read PNG metadata: ${stderr}`,
|
|
232
|
+
output: stderr
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
const metadata = stdout.trim();
|
|
236
|
+
if (!metadata) {
|
|
237
|
+
return {
|
|
238
|
+
success: false,
|
|
239
|
+
error: "No generation parameters found in file",
|
|
240
|
+
output: "No generation parameters found in file"
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
success: true,
|
|
245
|
+
output: metadata,
|
|
246
|
+
displayOutput: "PNG generation parameters extracted"
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
const errorMessage = error.message || "Unknown error";
|
|
251
|
+
const stderr = error.stderr || "";
|
|
252
|
+
return {
|
|
253
|
+
success: false,
|
|
254
|
+
error: `Failed to read PNG metadata: ${errorMessage}${stderr ? '\n' + stderr : ''}`,
|
|
255
|
+
output: `Failed to read PNG metadata: ${errorMessage}${stderr ? '\n' + stderr : ''}`
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
return {
|
|
261
|
+
success: false,
|
|
262
|
+
error: error instanceof Error ? error.message : "Unknown error reading PNG metadata",
|
|
263
|
+
output: error instanceof Error ? error.message : "Unknown error reading PNG metadata"
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=image-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-tool.js","sourceRoot":"","sources":["../../src/tools/image-tool.ts"],"names":[],"mappings":"AAAA,OAAO,E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AAC,EAAE,EAAE;oBACnF,MAAM,EAAE,gCAAgC,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;iBACrF,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,oCAAoC;gBACpF,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,oCAAoC;aACtF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { ZshTool } from "./zsh.js";
|
|
2
|
+
export { TextEditorTool } from "./text-editor.js";
|
|
3
|
+
export { MorphEditorTool } from "./morph-editor.js";
|
|
4
|
+
export { ConfirmationTool } from "./confirmation-tool.js";
|
|
5
|
+
export { SearchTool } from "./search.js";
|
|
6
|
+
export { EnvTool } from "./env-tool.js";
|
|
7
|
+
export { IntrospectTool } from "./introspect-tool.js";
|
|
8
|
+
export { ClearCacheTool } from "./clear-cache-tool.js";
|
|
9
|
+
export { CharacterTool } from "./character-tool.js";
|
|
10
|
+
export { TaskTool } from "./task-tool.js";
|
|
11
|
+
export { InternetTool } from "./internet-tool.js";
|
|
12
|
+
export { ImageTool } from "./image-tool.js";
|
|
13
|
+
export { FileConversionTool } from "./file-conversion-tool.js";
|
|
14
|
+
export { RestartTool } from "./restart-tool.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { ZshTool } from "./zsh.js";
|
|
2
|
+
export { TextEditorTool } from "./text-editor.js";
|
|
3
|
+
export { MorphEditorTool } from "./morph-editor.js";
|
|
4
|
+
export { ConfirmationTool } from "./confirmation-tool.js";
|
|
5
|
+
export { SearchTool } from "./search.js";
|
|
6
|
+
export { EnvTool } from "./env-tool.js";
|
|
7
|
+
export { IntrospectTool } from "./introspect-tool.js";
|
|
8
|
+
export { ClearCacheTool } from "./clear-cache-tool.js";
|
|
9
|
+
export { CharacterTool } from "./character-tool.js";
|
|
10
|
+
export { TaskTool } from "./task-tool.js";
|
|
11
|
+
export { InternetTool } from "./internet-tool.js";
|
|
12
|
+
export { ImageTool } from "./image-tool.js";
|
|
13
|
+
export { FileConversionTool } from "./file-conversion-tool.js";
|
|
14
|
+
export { RestartTool } from "./restart-tool.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ToolResult } from "../types/index.js";
|
|
2
|
+
import { ToolDiscovery } from "./tool-discovery.js";
|
|
3
|
+
export declare class InternetTool implements ToolDiscovery {
|
|
4
|
+
private agent;
|
|
5
|
+
setAgent(agent: any): void;
|
|
6
|
+
getHandledToolNames(): string[];
|
|
7
|
+
/**
|
|
8
|
+
* Download a file < 10MB from the Internet.
|
|
9
|
+
*/
|
|
10
|
+
downloadFile(url: string): Promise<ToolResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { exec } from "child_process";
|
|
2
|
+
import { promisify } from "util";
|
|
3
|
+
const execAsync = promisify(exec);
|
|
4
|
+
export class InternetTool {
|
|
5
|
+
agent; // Reference to the GrokAgent
|
|
6
|
+
setAgent(agent) {
|
|
7
|
+
this.agent = agent;
|
|
8
|
+
}
|
|
9
|
+
getHandledToolNames() {
|
|
10
|
+
return ["downloadFile"];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Download a file < 10MB from the Internet.
|
|
14
|
+
*/
|
|
15
|
+
async downloadFile(url) {
|
|
16
|
+
try {
|
|
17
|
+
if (!this.agent) {
|
|
18
|
+
return {
|
|
19
|
+
success: false,
|
|
20
|
+
error: "Agent not available",
|
|
21
|
+
output: "Agent not available"
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// Get the agent's home directory and create Downloads path
|
|
25
|
+
const agentHome = process.env.ZDS_AI_AGENT_HOME_DIR;
|
|
26
|
+
if (!agentHome) {
|
|
27
|
+
return {
|
|
28
|
+
success: false,
|
|
29
|
+
error: "Agent home directory not found",
|
|
30
|
+
output: "Agent home directory not found"
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const downloadsDir = `${agentHome}/Downloads`;
|
|
34
|
+
// Ensure Downloads directory exists
|
|
35
|
+
try {
|
|
36
|
+
await execAsync(`mkdir -p "${downloadsDir}"`);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
error: `Failed to create Downloads directory: ${error}`,
|
|
42
|
+
output: `Failed to create Downloads directory: ${error}`
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// Check file size first using curl -I (HEAD request)
|
|
46
|
+
let contentLength;
|
|
47
|
+
try {
|
|
48
|
+
const { stdout } = await execAsync(`curl -sI "${url}" | grep -i "content-length" | awk '{print $2}' | tr -d '\r'`);
|
|
49
|
+
contentLength = parseInt(stdout.trim() || "0");
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: `Failed to check file size: ${error}`,
|
|
55
|
+
output: `Failed to check file size: ${error}`
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const maxSize = 10 * 1024 * 1024; // 10MB
|
|
59
|
+
if (contentLength > maxSize) {
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
error: `File too large: ${contentLength} bytes (max: ${maxSize} bytes)`,
|
|
63
|
+
output: `File too large: ${contentLength} bytes (max: ${maxSize} bytes)`
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// Extract filename from URL
|
|
67
|
+
const filename = url.split('/').pop()?.split('?')[0] || 'downloaded_file';
|
|
68
|
+
const filepath = `${downloadsDir}/${filename}`;
|
|
69
|
+
// Download the file
|
|
70
|
+
try {
|
|
71
|
+
await execAsync(`curl -L -o "${filepath}" "${url}"`);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
success: false,
|
|
76
|
+
error: `Download failed: ${error}`,
|
|
77
|
+
output: `Download failed: ${error}`
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Get MIME info using file command
|
|
81
|
+
let fileInfo;
|
|
82
|
+
try {
|
|
83
|
+
const { stdout } = await execAsync(`file "${filepath}"`);
|
|
84
|
+
fileInfo = stdout.trim() || "Unknown file type";
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: `Failed to get file info: ${error}`,
|
|
90
|
+
output: `Download completed but failed to get file info: ${error}`
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
success: true,
|
|
95
|
+
output: `File downloaded successfully\nPath: ${filepath}\nSize: ${contentLength} bytes\nInfo: ${fileInfo}`,
|
|
96
|
+
displayOutput: `Downloaded ${filename} (${contentLength} bytes)`
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
error: error instanceof Error ? error.message : "Unknown error downloading file",
|
|
103
|
+
output: error instanceof Error ? error.message : "Unknown error downloading file"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=internet-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internet-tool.js","sourceRoot":"","sources":["../../src/tools/internet-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAIjC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC,MAAM,OAAO,YAAY;IACf,KAAK,CAAM,CAAC,6BAA6B;IAEjD,QAAQ,CAAC,KAAU;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,mBAAmB;QACjB,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,GAAW;QAC5B,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;gBAChB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,qBAAqB;oBAC5B,MAAM,EAAE,qBAAqB;iBAC9B,CAAC;YACJ,C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CAAC,CAAC,gCAAgC;gBAChF,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,gCAAgC;aAClF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ToolResult } from "../types/index.js";
|
|
2
|
+
import { ToolDiscovery } from "./tool-discovery.js";
|
|
3
|
+
export declare class IntrospectTool implements ToolDiscovery {
|
|
4
|
+
private agent;
|
|
5
|
+
setAgent(agent: any): void;
|
|
6
|
+
/**
|
|
7
|
+
* Introspect available tools and system information
|
|
8
|
+
*/
|
|
9
|
+
introspect(target: string): Promise<ToolResult>;
|
|
10
|
+
getHandledToolNames(): string[];
|
|
11
|
+
}
|