MCPcopy Create free account
hub / github.com/diegosouzapw/OmniRoute / runSetupOpencodeCommand

Function runSetupOpencodeCommand

bin/cli/commands/setup-opencode.mjs:73–110  ·  view source on GitHub ↗
(opts = {})

Source from the content-addressed store, hash-verified

71}
72
73export async function runSetupOpencodeCommand(opts = {}) {
74 const { baseUrl, apiKey } = resolveOpencodeTarget(opts);
75 const dryRun = Boolean(opts.dryRun ?? opts["dry-run"]);
76 const only = opts.only ? opts.only.split(",").map((s) => s.trim()).filter(Boolean) : null;
77
78 printHeading("OmniRoute → OpenCode provider (openai-compatible)");
79 printInfo(`Connecting to ${baseUrl} …`);
80
81 // Deferred import: opencode.ts is TypeScript; tsx is registered by
82 // bin/omniroute.mjs before any command runs, so importing here is safe.
83 let raw;
84 try {
85 const { generateOpencodeConfig } = await import(
86 "../../../src/lib/cli-helper/config-generator/opencode.ts"
87 );
88 raw = await generateOpencodeConfig({ baseUrl, apiKey, model: opts.model, providerId: "omniroute" });
89 } catch (err) {
90 printError(`Failed to generate opencode.json: ${err?.message || err}`);
91 printInfo("Make sure OmniRoute is running and --remote/--api-key are correct.");
92 return 1;
93 }
94
95 const { json, modelCount } = postProcessOpencodeConfig(raw, { only });
96 const configDir = join(os.homedir(), ".config", "opencode");
97 const configPath = join(configDir, "opencode.json");
98
99 if (dryRun) {
100 console.log(json.length > 4000 ? json.slice(0, 4000) + "\n… (truncated)" : json);
101 printInfo(`[dry-run] ${modelCount} model(s) under provider 'omniroute' → ${configPath}`);
102 return 0;
103 }
104
105 if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
106 writeFileSync(configPath, json, "utf8");
107 printSuccess(`opencode.json updated at ${configPath} (${modelCount} models under 'omniroute')`);
108 printInfo('Use it: opencode -m omniroute/<model> "..." (export OMNIROUTE_API_KEY first)');
109 return 0;
110}
111
112export function registerSetupOpencode(program) {
113 program

Callers 1

registerSetupOpencodeFunction · 0.85

Calls 7

printHeadingFunction · 0.90
printInfoFunction · 0.90
printErrorFunction · 0.90
printSuccessFunction · 0.90
resolveOpencodeTargetFunction · 0.85
generateOpencodeConfigFunction · 0.85

Tested by

no test coverage detected