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

Function handleRun

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

Source from the content-addressed store, hash-verified

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

Callers 1

ToolRunPanelFunction · 0.85

Calls 2

trackEventFunction · 0.90
errorMethod · 0.80

Tested by

no test coverage detected