MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / handleRun

Function handleRun

packages/react/src/components/tool-run-panel.tsx:206–262  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

204 };
205
206 const handleRun = async () => {
207 if (!addressNoPrefix) return;
208
209 const decoded = decodeArgsJson(argsJson);
210 if (Option.isNone(decoded)) {
211 setArgsError("Invalid JSON — enter a valid JSON object of arguments.");
212 return;
213 }
214 const parsed = decoded.value;
215 setArgsError(null);
216 setRunning(true);
217 setResult(null);
218
219 // Read-only invoke: pass the validated args through as JSON. Empty
220 // `reactivityKeys` — invoking a tool doesn't mutate `tools.list`.
221 // `autoApprove` because the operator clicked Run: that IS the approval, so
222 // an approval-gated tool should run here instead of dead-ending on a pause.
223 const code = `return await tools[${JSON.stringify(addressNoPrefix)}](${JSON.stringify(parsed)});`;
224 const exit = await doExecute({ payload: { code, autoApprove: true }, reactivityKeys: [] });
225 setRunning(false);
226
227 if (Exit.isFailure(exit)) {
228 trackEvent("tool_run_submitted", {
229 integration_slug: integration,
230 tool_name: toolName,
231 args_mode: argsMode,
232 result: "failed",
233 });
234 toast.error("Failed to run tool");
235 return;
236 }
237
238 const value = exit.value;
239 if (value.status === "paused") {
240 trackEvent("tool_run_submitted", {
241 integration_slug: integration,
242 tool_name: toolName,
243 args_mode: argsMode,
244 result: "paused",
245 });
246 setResult({ kind: "paused", text: value.text });
247 return;
248 }
249 trackEvent("tool_run_submitted", {
250 integration_slug: integration,
251 tool_name: toolName,
252 args_mode: argsMode,
253 result: "completed",
254 ...(value.isError ? { is_error: true } : {}),
255 });
256 setResult({
257 kind: "completed",
258 text: value.text,
259 structured: value.structured,
260 isError: value.isError,
261 });
262 };
263

Callers 1

ToolRunPanelFunction · 0.85

Calls 2

trackEventFunction · 0.90
errorMethod · 0.80

Tested by

no test coverage detected