| 1 | import { app } from "./bridge"; |
| 2 | import type { useT } from "./i18n"; |
| 3 | import type { MCPInstallResult, MCPServerInput } from "./types"; |
| 4 | |
| 5 | export function activeWorkBusyNoticeText(error: unknown, translate: ReturnType<typeof useT>): string | null { |
| 6 | const message = String((error as Error)?.message ?? error ?? "").trim(); |
| 7 | const lower = message.toLowerCase(); |
| 8 | if (!lower.startsWith("active work is still running;") || !lower.includes("before changing ")) return null; |
| 9 | |
| 10 | const detail = /running=(true|false);\s*pending_prompt=(true|false);\s*background_jobs=(\d+)/i.exec(message); |
| 11 | if (detail?.[2] === "true") return translate("caps.switchBusyPrompt"); |
| 12 | if (detail?.[1] === "true") return translate("caps.switchBusyRunning"); |
| 13 | const jobs = Number(detail?.[3] ?? 0); |
| 14 | if (jobs > 0) return translate("caps.switchBusyJobs", { n: jobs }); |
| 15 | return translate("caps.switchBusy"); |
| 16 | } |
| 17 | |
| 18 | export async function installMCPServer(input: MCPServerInput): Promise<MCPInstallResult> { |
| 19 | const result = await app.InstallMCPServer(input); |
| 20 | if (result.state === "issue") throw new Error(result.message); |
| 21 | return result; |
| 22 | } |
| 23 |