billion-context 0.1.46-pr.211.21 → 0.1.46-pr.211.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -52217,6 +52217,41 @@ function readOmpConfig(ompHome) {
52217
52217
  }
52218
52218
  return parseOmpYaml(text);
52219
52219
  }
52220
+ function resolveOpencodeConfigFile(env) {
52221
+ if (nonEmpty2(env.OPENCODE_CONFIG)) return env.OPENCODE_CONFIG;
52222
+ const xdg2 = nonEmpty2(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path8.join(os.homedir(), ".config");
52223
+ return path8.join(xdg2, "opencode", "opencode.json");
52224
+ }
52225
+ function readOpencodeConfig(file) {
52226
+ let text;
52227
+ try {
52228
+ text = fs4.readFileSync(file, "utf8");
52229
+ } catch {
52230
+ return { providers: {} };
52231
+ }
52232
+ let parsed;
52233
+ try {
52234
+ parsed = JSON.parse(text);
52235
+ } catch {
52236
+ return { providers: {} };
52237
+ }
52238
+ const providers = {};
52239
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
52240
+ const root = parsed;
52241
+ const provRoot = root.provider;
52242
+ if (provRoot && typeof provRoot === "object" && !Array.isArray(provRoot)) {
52243
+ for (const [name, value] of Object.entries(provRoot)) {
52244
+ if (!value || typeof value !== "object" || Array.isArray(value)) continue;
52245
+ const opts = value.options;
52246
+ if (opts && typeof opts === "object" && !Array.isArray(opts)) {
52247
+ const baseURL = opts.baseURL;
52248
+ if (typeof baseURL === "string") providers[name] = { baseURL };
52249
+ }
52250
+ }
52251
+ }
52252
+ }
52253
+ return { providers };
52254
+ }
52220
52255
  function parseZcodeConfig(obj) {
52221
52256
  const result = { providers: {} };
52222
52257
  if (!obj || typeof obj !== "object" || Array.isArray(obj)) return result;
@@ -52259,6 +52294,7 @@ function loadClientConfig(env, cwd) {
52259
52294
  const zcodeHome = nonEmpty2(env.ZCODE_DATA_BASE_DIR) ? env.ZCODE_DATA_BASE_DIR : path8.join(home, ".zcode");
52260
52295
  config.zcode = readZcodeConfig(zcodeHome);
52261
52296
  config.omp = readOmpConfig(resolveOmpHome(env));
52297
+ config.opencode = readOpencodeConfig(resolveOpencodeConfigFile(env));
52262
52298
  return config;
52263
52299
  }
52264
52300
 
@@ -58438,6 +58474,10 @@ function discoverRoutes(client, config) {
58438
58474
  for (const [name, prov] of Object.entries(config.omp?.providers ?? {})) {
58439
58475
  classify(prov.baseUrl, name);
58440
58476
  }
58477
+ } else if (client === "opencode") {
58478
+ for (const [name, prov] of Object.entries(config.opencode?.providers ?? {})) {
58479
+ classify(prov.baseURL, name);
58480
+ }
58441
58481
  } else {
58442
58482
  for (const [name, prov] of Object.entries(config.codex?.providers ?? {})) {
58443
58483
  classify(prov.baseUrl, `model_providers.${name}.base_url`);
@@ -58616,6 +58656,43 @@ function prepareOmpHttpRewrite(ompHome, origin, httpRewrites, httpsRewrites) {
58616
58656
  fs10.writeFileSync(path13.join(tmp, "models.yml"), lines.join("\n"));
58617
58657
  return tmp;
58618
58658
  }
58659
+ function prepareOpencodeHttpRewrite(configFile2, origin, httpRewrites, httpsRewrites) {
58660
+ if (httpRewrites.length === 0 && httpsRewrites.length === 0) return void 0;
58661
+ let txt;
58662
+ try {
58663
+ txt = fs10.readFileSync(configFile2, "utf8");
58664
+ } catch {
58665
+ return void 0;
58666
+ }
58667
+ let parsed;
58668
+ try {
58669
+ parsed = JSON.parse(txt);
58670
+ } catch {
58671
+ return void 0;
58672
+ }
58673
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return void 0;
58674
+ const root = parsed;
58675
+ const provRoot = root.provider;
58676
+ if (provRoot && typeof provRoot === "object" && !Array.isArray(provRoot)) {
58677
+ const providers = provRoot;
58678
+ const rewrite = (rewrites, wrap) => {
58679
+ for (const r of rewrites) {
58680
+ const prov = providers[r.key];
58681
+ if (!prov || typeof prov !== "object" || Array.isArray(prov)) continue;
58682
+ const p2 = prov;
58683
+ if (!p2.options || typeof p2.options !== "object") continue;
58684
+ const existing = typeof p2.options.baseURL === "string" ? p2.options.baseURL : r.realUpstream;
58685
+ p2.options.baseURL = wrap ? wrapUpstream(origin, unwrapUpstream2(existing)) : r.realUpstream;
58686
+ }
58687
+ };
58688
+ rewrite(httpRewrites, true);
58689
+ rewrite(httpsRewrites, false);
58690
+ }
58691
+ const tmp = fs10.mkdtempSync(path13.join(os5.tmpdir(), "bili-opencode-"));
58692
+ const tmpFile = path13.join(tmp, "opencode.json");
58693
+ fs10.writeFileSync(tmpFile, JSON.stringify(root));
58694
+ return tmpFile;
58695
+ }
58619
58696
  function dedupeInOrder(list) {
58620
58697
  const seen = /* @__PURE__ */ new Set();
58621
58698
  const out = [];
@@ -58820,6 +58897,7 @@ async function runLaunch(params, deps = {}) {
58820
58897
  let clientArgs = params.clientArgs;
58821
58898
  let piTmpHome;
58822
58899
  let ompTmpHome;
58900
+ let opencodeTmpFile;
58823
58901
  const tmpFiles = [];
58824
58902
  const directUrl = launcherDirectUrl(process.env);
58825
58903
  if (directUrl) {
@@ -58848,6 +58926,8 @@ async function runLaunch(params, deps = {}) {
58848
58926
  if (ompTmpHome) env.PI_CODING_AGENT_DIR = ompTmpHome;
58849
58927
  } else if (base === "opencode") {
58850
58928
  env = { ...process.env, HTTPS_PROXY: origin, NODE_EXTRA_CA_CERTS: ca, BILLION_CONTEXT_PROXY: origin };
58929
+ opencodeTmpFile = prepareOpencodeHttpRewrite(resolveOpencodeConfigFile(process.env), origin, routes.httpRewrites, routes.httpsRewrites);
58930
+ if (opencodeTmpFile) env.OPENCODE_CONFIG = opencodeTmpFile;
58851
58931
  } else if (base === "codex") {
58852
58932
  const codexConversationId = injectMcp ? randomUUID2() : void 0;
58853
58933
  if (directUrl) {
@@ -58892,6 +58972,12 @@ async function runLaunch(params, deps = {}) {
58892
58972
  } catch {
58893
58973
  }
58894
58974
  }
58975
+ if (opencodeTmpFile) {
58976
+ try {
58977
+ fs10.rmSync(path13.dirname(opencodeTmpFile), { recursive: true, force: true });
58978
+ } catch {
58979
+ }
58980
+ }
58895
58981
  for (const f2 of tmpFiles) {
58896
58982
  try {
58897
58983
  fs10.rmSync(f2, { force: true });