#!/usr/bin/env node const fs = require("node:fs"); const os = require("node:os"); const path = require("node:path"); async function main() { const prompt = process.argv.slice(2).join(" ").trim(); if (!prompt) { console.error("Usage: deepseek-code-openclaw "); process.exit(1); } const cfgPath = path.join(os.homedir(), ".openclaw", "openclaw.json"); const raw = fs.readFileSync(cfgPath, "utf8"); const cfg = JSON.parse(raw); const apiKey = cfg?.models?.providers?.["custom-api-deepseek-com"]?.apiKey; if (!apiKey) { console.error("DeepSeek API key not found in ~/.openclaw/openclaw.json"); process.exit(1); } const response = await fetch("https://api.deepseek.com/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${apiKey}` }, body: JSON.stringify({ model: "deepseek-chat", messages: [ { role: "system", content: "You are a concise coding assistant. Answer directly in plain text." }, { role: "user", content: prompt } ], stream: false }) }); if (!response.ok) { const body = await response.text(); console.error(`DeepSeek API error ${response.status}: ${body}`); process.exit(1); } const data = await response.json(); const text = data?.choices?.[0]?.message?.content?.trim(); if (!text) { console.error("DeepSeek API returned no message content"); process.exit(1); } process.stdout.write(text.endsWith("\n") ? text : `${text}\n`); } main().catch((error) => { console.error(error instanceof Error ? error.message : String(error)); process.exit(1); });