Files
OmniRoute/scripts/cli/install-opencode-media.mjs
Diego Rodrigues de Sa e Souza 191dce8d53 Release v3.8.53
Release v3.8.53 — 1,189 documented changes from 1,162 cycle commits and 208 contributor rows; full changelog in CHANGELOG.md → [3.8.53].

Merged by explicit owner decision at STOP #1 on head 6cc69650, without --admin (main has no required checks). Gate / CI passed on this head: 8 unit shards, Coverage and Quality Ratchet. Security: 0 npm, 0 CodeQL high, 0 Dependabot high.

Red at merge, accepted by the owner:
- Gate / Quality and Fast Quality Gates: complexity-ratchets and dead-code compare the whole cycle against main (11 dead exports; total complexity fell from 1,921 to 1,873). Cleanup follows in v3.8.54.
- dast-smoke: advisory.
- Release-Green: FAIL on `unit-6 no result` (cancelled at the 30-minute limit, cause not identified). Pack, boot and the other 64 commands passed on 7e640dee; there is no complete run on this head.

SonarQube is off (SONARQUBE_ENABLED=false). ⚠️ base-red inherited: #18791, #17267.
2026-11-06 04:21:00 -03:00

58 lines
2.2 KiB
JavaScript

#!/usr/bin/env node
import { readFile, mkdir, writeFile, rename } from "node:fs/promises";
import { homedir } from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { build } from "esbuild";
const configPath =
process.env.OMNIROUTE_MEDIA_CONFIG ||
path.join(
process.env.XDG_CONFIG_HOME || path.join(homedir(), ".config"),
"opencode",
"opencode.json"
);
const directory = path.join(path.dirname(configPath), "omniroute-media");
const bundle = path.join(directory, "server.mjs");
await mkdir(directory, { recursive: true, mode: 0o700 });
await build({
entryPoints: [fileURLToPath(new URL("./omniroute-media-mcp.mjs", import.meta.url))],
outfile: bundle,
bundle: true,
platform: "node",
format: "esm",
target: "node22",
banner: {
js: 'import { createRequire as __omniCreateRequire } from "node:module"; const require = __omniCreateRequire(import.meta.url);',
},
logLevel: "silent",
});
const original = await readFile(configPath, "utf8");
const config = JSON.parse(original);
if (!config.providers?.omniroute?.settings?.baseURL)
throw new Error("Configure the OmniRoute provider in OpenCode first.");
config.mcp ||= {};
config.mcp.servers ||= {};
const existing = config.mcp.servers.omniroute_media;
if (existing && !existing.command?.includes(bundle))
throw new Error("An unrelated MCP server already uses the name omniroute_media.");
const reference = config.providers.omniroute.settings.apiKey;
config.mcp.servers.omniroute_media = {
type: "local",
command: [process.execPath, bundle],
codemode: false,
timeout: { startup: 15000, catalog: 15000, execution: 180000 },
environment: {
OMNIROUTE_MEDIA_CONFIG: configPath,
...(typeof reference === "string" && /^\{env:[A-Za-z_][A-Za-z0-9_]{0,127}\}$/.test(reference)
? { OMNIROUTE_MEDIA_API_KEY: reference }
: {}),
},
};
const backup = `${configPath}.backup-media-${Date.now()}`;
await writeFile(backup, original, { mode: 0o600, flag: "wx" });
const temporary = `${configPath}.media-next`;
await writeFile(temporary, JSON.stringify(config, null, 2) + "\n", { mode: 0o600 });
await rename(temporary, configPath);
console.log(`Installed omniroute_media in ${configPath}. Run opencode reload.`);