this repo has no description
at main 26 lines 972 B view raw
1import { createAnthropic } from "@ai-sdk/anthropic"; 2import { streamText } from "ai"; 3 4const anthropic = createAnthropic({ 5 apiKey: process.env.NLCMD_API_KEY || process.env.ANTHROPIC_API_KEY, 6 ...(process.env.NLCMD_BASE_URL && { baseURL: process.env.NLCMD_BASE_URL }), 7}); 8 9const input = await Bun.stdin.text(); 10 11const { textStream } = streamText({ 12 model: anthropic("claude-haiku-4-5-20251001"), 13 system: "Convert natural language to a shell command. Output ONLY the command itself - no explanations, no markdown, no alternatives, no questions. Make reasonable assumptions. One line only.", 14 prompt: input.trim(), 15 onError({ error }: { error: any }) { 16 const msg = error.statusCode === 401 ? "Invalid API key" 17 : error.message?.includes("API key") ? "Missing API key" 18 : error.message || "Unknown error"; 19 console.log(`# Error: ${msg}`); 20 process.exit(1); 21 }, 22}); 23 24for await (const chunk of textStream) { 25 await Bun.write(Bun.stdout, chunk); 26}