billion-context 0.1.46-pr.211.24 → 0.1.46-pr.211.26
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/agent/opencode.js +8 -4
- package/dist/agent/opencode.js.map +1 -1
- package/dist/index.js +18 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/agent/opencode.js
CHANGED
|
@@ -4,14 +4,18 @@ const require = __biliCreateRequire(import.meta.url);
|
|
|
4
4
|
// src/agent/opencode.ts
|
|
5
5
|
var proxyBase = process.env.BILLION_CONTEXT_PROXY ?? "";
|
|
6
6
|
async function showText(ctx, sid, text) {
|
|
7
|
-
const
|
|
8
|
-
if (typeof prompt !== "function")
|
|
7
|
+
const session = ctx.client?.session;
|
|
8
|
+
if (!session || typeof session.prompt !== "function") {
|
|
9
|
+
console.error("[bili-opencode] /acp render failed: session.prompt unavailable");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
9
12
|
try {
|
|
10
|
-
await prompt({
|
|
13
|
+
await session.prompt({
|
|
11
14
|
path: { id: sid },
|
|
12
15
|
body: { noReply: true, parts: [{ type: "text", text, ignored: true }] }
|
|
13
16
|
});
|
|
14
|
-
} catch {
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error(`[bili-opencode] /acp render failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
21
|
var server = async (ctx) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/agent/opencode.ts"],"sourcesContent":["// Thin opencode plugin for the billion-context proxy (`bili opencode`).\n//\n// Activates ONLY when BILLION_CONTEXT_PROXY is set (the launcher sets it);\n// otherwise it is a no-op so shipping it inside the package is harmless.\n// Mirrors the pi/omp plugin (src/agent/pi.ts):\n// - registers the /acp command (config hook + command.execute.before)\n// - binds the opencode session id to the proxy session via the\n// pending-register queue (POST /__bili/plugin/register on session.created)\n// - renders the proxy's buildStatusPanel via an ignored chat message\n\ninterface OpencodeCommandConfig {\n template: string;\n description?: string;\n}\n\ninterface OpencodeConfig {\n command?: Record<string, OpencodeCommandConfig>;\n [key: string]: unknown;\n}\n\ninterface OpencodeSessionInfo {\n id?: unknown;\n}\n\ninterface OpencodeEvent {\n type?: string;\n properties?: { info?: OpencodeSessionInfo; [key: string]: unknown };\n}\n\ninterface OpencodeEventInput {\n event?: OpencodeEvent;\n}\n\ninterface OpencodeCommandInput {\n command: string;\n sessionID: string;\n arguments?: string;\n}\n\ninterface OpencodePromptPart {\n type: string;\n text: string;\n ignored?: boolean;\n}\n\ninterface OpencodeClient {\n session?: {\n prompt?: (args: {\n path: { id: string };\n body: { noReply: boolean; parts: OpencodePromptPart[] };\n }) => Promise<unknown>;\n };\n}\n\ninterface OpencodePluginContext {\n client?: OpencodeClient;\n}\n\ninterface OpencodeHooks {\n config?: (input: OpencodeConfig) => Promise<void>;\n event?: (input: OpencodeEventInput) => Promise<void>;\n \"command.execute.before\"?: (input: OpencodeCommandInput, output: { parts: unknown[] }) => Promise<void>;\n}\n\nconst proxyBase = process.env.BILLION_CONTEXT_PROXY ?? \"\";\n\nasync function showText(ctx: OpencodePluginContext, sid: string, text: string): Promise<void> {\n const prompt = ctx.client?.session
|
|
1
|
+
{"version":3,"sources":["../../src/agent/opencode.ts"],"sourcesContent":["// Thin opencode plugin for the billion-context proxy (`bili opencode`).\n//\n// Activates ONLY when BILLION_CONTEXT_PROXY is set (the launcher sets it);\n// otherwise it is a no-op so shipping it inside the package is harmless.\n// Mirrors the pi/omp plugin (src/agent/pi.ts):\n// - registers the /acp command (config hook + command.execute.before)\n// - binds the opencode session id to the proxy session via the\n// pending-register queue (POST /__bili/plugin/register on session.created)\n// - renders the proxy's buildStatusPanel via an ignored chat message\n\ninterface OpencodeCommandConfig {\n template: string;\n description?: string;\n}\n\ninterface OpencodeConfig {\n command?: Record<string, OpencodeCommandConfig>;\n [key: string]: unknown;\n}\n\ninterface OpencodeSessionInfo {\n id?: unknown;\n}\n\ninterface OpencodeEvent {\n type?: string;\n properties?: { info?: OpencodeSessionInfo; [key: string]: unknown };\n}\n\ninterface OpencodeEventInput {\n event?: OpencodeEvent;\n}\n\ninterface OpencodeCommandInput {\n command: string;\n sessionID: string;\n arguments?: string;\n}\n\ninterface OpencodePromptPart {\n type: string;\n text: string;\n ignored?: boolean;\n}\n\ninterface OpencodeClient {\n session?: {\n prompt?: (args: {\n path: { id: string };\n body: { noReply: boolean; parts: OpencodePromptPart[] };\n }) => Promise<unknown>;\n };\n}\n\ninterface OpencodePluginContext {\n client?: OpencodeClient;\n}\n\ninterface OpencodeHooks {\n config?: (input: OpencodeConfig) => Promise<void>;\n event?: (input: OpencodeEventInput) => Promise<void>;\n \"command.execute.before\"?: (input: OpencodeCommandInput, output: { parts: unknown[] }) => Promise<void>;\n}\n\nconst proxyBase = process.env.BILLION_CONTEXT_PROXY ?? \"\";\n\nasync function showText(ctx: OpencodePluginContext, sid: string, text: string): Promise<void> {\n // Direct method call — `const p = ctx.client.session.prompt; p(...)` loses `this` (this._client) and throws.\n const session = ctx.client?.session;\n if (!session || typeof session.prompt !== \"function\") {\n console.error(\"[bili-opencode] /acp render failed: session.prompt unavailable\");\n return;\n }\n try {\n await session.prompt({\n path: { id: sid },\n body: { noReply: true, parts: [{ type: \"text\", text, ignored: true }] },\n });\n } catch (err) {\n console.error(`[bili-opencode] /acp render failed: ${err instanceof Error ? err.message : String(err)}`);\n }\n}\n\nconst server = async (ctx: OpencodePluginContext): Promise<OpencodeHooks> => {\n if (!proxyBase) return {};\n console.log(\"[bili-opencode] plugin active (proxy \" + proxyBase + \")\");\n return {\n config: async (opencodeConfig) => {\n opencodeConfig.command ??= {};\n opencodeConfig.command[\"acp\"] = {\n template: \"\",\n description: \"Show ACP status (billion-context proxy)\",\n };\n },\n \"command.execute.before\": async (input) => {\n if (input.command !== \"acp\") return;\n const sid = input.sessionID;\n let text: string;\n try {\n const res = await fetch(`${proxyBase}/__bili/plugin/status?conversationId=${encodeURIComponent(sid)}&fallback=latest`);\n const status = (await res.json()) as { ok?: boolean; panel?: string; error?: string };\n if (typeof status.panel === \"string\" && status.panel.length > 0) {\n text = status.panel;\n } else if (status.ok === false) {\n text = \"bili: no ACP session yet (send a model request first, then run /acp)\";\n } else {\n text = \"bili: proxy returned no status panel\";\n }\n } catch (err) {\n text = `bili: /acp failed (${err instanceof Error ? err.message : String(err)})`;\n }\n await showText(ctx, sid, text);\n throw new Error(\"__BILI_ACP_HANDLED__\");\n },\n };\n};\n\nexport default server;\n"],"mappings":";;;;AAgEA,IAAM,YAAY,QAAQ,IAAI,yBAAyB;AAEvD,eAAe,SAAS,KAA4B,KAAa,MAA6B;AAEtF,QAAM,UAAU,IAAI,QAAQ;AAC5B,MAAI,CAAC,WAAW,OAAO,QAAQ,WAAW,YAAY;AAClD,YAAQ,MAAM,gEAAgE;AAC9E;AAAA,EACJ;AACA,MAAI;AACA,UAAM,QAAQ,OAAO;AAAA,MACjB,MAAM,EAAE,IAAI,IAAI;AAAA,MAChB,MAAM,EAAE,SAAS,MAAM,OAAO,CAAC,EAAE,MAAM,QAAQ,MAAM,SAAS,KAAK,CAAC,EAAE;AAAA,IAC1E,CAAC;AAAA,EACL,SAAS,KAAK;AACV,YAAQ,MAAM,uCAAuC,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC,EAAE;AAAA,EAC3G;AACR;AAEA,IAAM,SAAS,OAAO,QAAuD;AACzE,MAAI,CAAC,UAAW,QAAO,CAAC;AACxB,UAAQ,IAAI,0CAA0C,YAAY,GAAG;AACrE,SAAO;AAAA,IACH,QAAQ,OAAO,mBAAmB;AAC9B,qBAAe,YAAY,CAAC;AAC5B,qBAAe,QAAQ,KAAK,IAAI;AAAA,QAC5B,UAAU;AAAA,QACV,aAAa;AAAA,MACjB;AAAA,IACJ;AAAA,IACA,0BAA0B,OAAO,UAAU;AACvC,UAAI,MAAM,YAAY,MAAO;AAC7B,YAAM,MAAM,MAAM;AAClB,UAAI;AACJ,UAAI;AACA,cAAM,MAAM,MAAM,MAAM,GAAG,SAAS,wCAAwC,mBAAmB,GAAG,CAAC,kBAAkB;AACrH,cAAM,SAAU,MAAM,IAAI,KAAK;AAC/B,YAAI,OAAO,OAAO,UAAU,YAAY,OAAO,MAAM,SAAS,GAAG;AAC7D,iBAAO,OAAO;AAAA,QAClB,WAAW,OAAO,OAAO,OAAO;AAC5B,iBAAO;AAAA,QACX,OAAO;AACH,iBAAO;AAAA,QACX;AAAA,MACJ,SAAS,KAAK;AACV,eAAO,sBAAsB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAAA,MACjF;AACA,YAAM,SAAS,KAAK,KAAK,IAAI;AAC7B,YAAM,IAAI,MAAM,sBAAsB;AAAA,IAC1C;AAAA,EACJ;AACJ;AAEA,IAAO,mBAAQ;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -52115,7 +52115,7 @@ function resolveOmpHome(env) {
|
|
|
52115
52115
|
const h = os.homedir();
|
|
52116
52116
|
return nonEmpty2(env.PI_CODING_AGENT_DIR) ? env.PI_CODING_AGENT_DIR : path8.join(h, ".omp", "agent");
|
|
52117
52117
|
}
|
|
52118
|
-
function readClaudeSettings(homeDir, cwd) {
|
|
52118
|
+
function readClaudeSettings(homeDir, cwd, env = process.env) {
|
|
52119
52119
|
const files = [
|
|
52120
52120
|
path8.join(homeDir, ".claude", "settings.json"),
|
|
52121
52121
|
path8.join(cwd, ".claude", "settings.json")
|
|
@@ -52123,12 +52123,13 @@ function readClaudeSettings(homeDir, cwd) {
|
|
|
52123
52123
|
let anthropicBaseUrl;
|
|
52124
52124
|
for (const f2 of files) {
|
|
52125
52125
|
const obj = readJsonObject(f2);
|
|
52126
|
-
const
|
|
52127
|
-
if (
|
|
52128
|
-
const v2 =
|
|
52126
|
+
const settingsEnv = obj?.env;
|
|
52127
|
+
if (settingsEnv && typeof settingsEnv === "object" && !Array.isArray(settingsEnv)) {
|
|
52128
|
+
const v2 = settingsEnv.ANTHROPIC_BASE_URL;
|
|
52129
52129
|
if (nonEmpty2(v2)) anthropicBaseUrl = v2;
|
|
52130
52130
|
}
|
|
52131
52131
|
}
|
|
52132
|
+
if (!anthropicBaseUrl && nonEmpty2(env.ANTHROPIC_BASE_URL)) anthropicBaseUrl = env.ANTHROPIC_BASE_URL;
|
|
52132
52133
|
return anthropicBaseUrl ? { anthropicBaseUrl } : {};
|
|
52133
52134
|
}
|
|
52134
52135
|
function parseCodexToml(text) {
|
|
@@ -52295,7 +52296,7 @@ function readZcodeConfig(zcodeHome) {
|
|
|
52295
52296
|
function loadClientConfig(env, cwd) {
|
|
52296
52297
|
const home = os.homedir();
|
|
52297
52298
|
const config = {};
|
|
52298
|
-
config.claude = readClaudeSettings(home, cwd);
|
|
52299
|
+
config.claude = readClaudeSettings(home, cwd, env);
|
|
52299
52300
|
const codexHome = nonEmpty2(env.CODEX_HOME) ? env.CODEX_HOME : path8.join(home, ".codex");
|
|
52300
52301
|
config.codex = readCodexConfig(codexHome);
|
|
52301
52302
|
config.pi = readPiConfig(resolvePiHome(env));
|
|
@@ -58475,9 +58476,16 @@ function discoverRoutes(client, config) {
|
|
|
58475
58476
|
}
|
|
58476
58477
|
};
|
|
58477
58478
|
if (client === "claude") {
|
|
58478
|
-
const
|
|
58479
|
-
|
|
58480
|
-
|
|
58479
|
+
const raw = nonEmpty2(config.claude?.anthropicBaseUrl) ? config.claude.anthropicBaseUrl : "https://api.anthropic.com";
|
|
58480
|
+
const real = unwrapUpstream2(raw);
|
|
58481
|
+
try {
|
|
58482
|
+
const url = new URL(real);
|
|
58483
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && !rewriteKeys.has("ANTHROPIC_BASE_URL")) {
|
|
58484
|
+
rewriteKeys.add("ANTHROPIC_BASE_URL");
|
|
58485
|
+
httpRewrites.push({ key: "ANTHROPIC_BASE_URL", realUpstream: real });
|
|
58486
|
+
}
|
|
58487
|
+
} catch {
|
|
58488
|
+
}
|
|
58481
58489
|
} else if (client === "pi") {
|
|
58482
58490
|
for (const [name, prov] of Object.entries(config.pi?.providers ?? {})) {
|
|
58483
58491
|
classify(prov.baseUrl, name);
|
|
@@ -59283,7 +59291,8 @@ function parseArgs(argv) {
|
|
|
59283
59291
|
const a = argv[i];
|
|
59284
59292
|
if (!client && positional.length === 0 && isLaunchClient(a)) {
|
|
59285
59293
|
client = a;
|
|
59286
|
-
|
|
59294
|
+
const rest = argv.slice(i + 1);
|
|
59295
|
+
clientArgs = rest[0] === "--" ? rest.slice(1) : rest;
|
|
59287
59296
|
break;
|
|
59288
59297
|
}
|
|
59289
59298
|
switch (a) {
|