import { Type, Static } from "@earendil-works/pi-ai"; import { readConfig, resolveApiKey } from "../config.js"; import { getRun } from "../api.js"; import { formatResultProjection } from "../format.js"; import { renderCollapsibleMarkdown } from "../render.js"; // --------------------------------------------------------------------------- // Parameters schema // --------------------------------------------------------------------------- const RunGetParams = Type.Object({ runId: Type.String({ description: "The ID of the automation run to query" }), }); type RunGetParamsType = Static; // --------------------------------------------------------------------------- // Tool definition // --------------------------------------------------------------------------- export const tinyfish_run_get = { name: "tinyfish_run_get", label: "TinyFish Get Run", description: "Get detailed status and result of a specific TinyFish Agent automation run by its ID.", promptSnippet: "Check the status and retrieve results of a specific automation run by ID", promptGuidelines: [ "Use tinyfish_run_get when you have a run ID (from tinyfish_agent_run) and need to check its result or status.", "Call this after tinyfish_agent_run completes to get the full structured result.", ], parameters: RunGetParams, async execute(_id: string, params: RunGetParamsType) { const config = await readConfig(); const apiKey = resolveApiKey(config); if (!apiKey) { return { content: [ { type: "text" as const, text: "TinyFish API key not configured. Run /tinyfish-login to set it up." }, ], details: {}, }; } const run = await getRun(apiKey, params.runId); let output = [ `## Run ${run.id}`, `Status: ${run.status}`, `Goal: ${run.goal}`, `URL: ${run.url}`, `Created: ${run.created_at ?? "N/A"}`, `Updated: ${run.updated_at ?? "N/A"}`, ].join("\n"); if (run.result) { output += `\n\n## Result\n${formatResultProjection(run.result)}`; } if (run.error) { output += `\n\n## Error\n${run.error}`; } return { content: [{ type: "text" as const, text: output }], details: { runId: run.id, status: run.status }, }; }, renderResult(result, options, theme) { const runId = (result.details?.runId as string | undefined) ?? "unknown"; const status = (result.details?.status as string | undefined) ?? "UNKNOWN"; const summary = `📋 Run ${runId} — ${status}`; return renderCollapsibleMarkdown(result, options, theme, summary); }, };