Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ import { buildDecisionPrompt, buildDirectiveText, consumeFallback, DEFAULT_DECID
import { gcConfigFromEnv, gcSessionFiles } from "./session-gc.js";
import { countImagesInParsedBody, countImagesInRawBody, imageTokensInRawBody, imageTokensInParsedBody, resolveImageBilling, upstreamHost, type ResolvedImageBilling } from "./image-tokens.js";
import { APIG_RESIGN_HEADER, APIG_RESIGN_CREDENTIAL_HEADER, APIG_RESIGN_SCHEME, KNOWN_SIGNATURE_SCHEMES, clearSignedRefusal, decodeApigCredential, inboundSignedScheme, readPendingRefusals, recordSignedRefusal, resignApig, signedRefusal, unresolvedRefusals, type ApigCredential } from "./apig-resign.js";
import { renderUI, handleConfigGet, handleConfigPut, handleSummaryCredentialPut, buildOverview, buildSessionList, buildSessionPage, buildSessionDetail, hiddenEmptyCount } from "./web/index.js";
import { reapOrphanBlocks } from "./orphan-gc.js";
import { conflictScanEnabled, isDesignBenign, scanClientPlugins, sniffScanClient } from "./thirdparty-scan.js";
import { clearConflictEvents, recordConflict, summarizeConflicts } from "./conflict-watch.js";
Expand Down
4 changes: 3 additions & 1 deletion src/server/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { clearUpstreamAlertsForHost, getUpstreamAlerts } from "../upstream-alert
import { formatUpstreamError, getUpstreamConnectionStatus, proxyDispatcher, recordUpstreamConnection, resetProxyCache, resolveProxyDecision } from "../upstream-proxy.js";
import { detectStaleInstall } from "../update.js";
import { PACKAGE_NAME, VERSION, BUILD_COMMIT } from "../version.js";
import { buildOverview, buildSessionDetail, buildSessionList, buildSessionPage, handleConfigGet, handleConfigPut, hiddenEmptyCount, renderUI } from "../web/index.js";
import { buildOverview, buildSessionDetail, buildSessionList, buildSessionPage, handleConfigGet, handleConfigPut, handleSummaryCredentialPut, hiddenEmptyCount, renderUI } from "../web/index.js";
import { buildSessionReportMd, buildSessionReportSvg } from "../web/report.js";
import { queryLogLines } from "../web/logs-query.js";
import { buildDiagnostics } from "../web/diagnostics.js";
Expand Down Expand Up @@ -262,6 +262,8 @@ export async function handleAdminRoute(req: http.IncomingMessage, res: http.Serv
Object.assign(opts.namedProviders, loadNamedProviders());
}, opts.port);
}
// #3443: Web UI Save Key — this route was dropped when the admin surface moved here (#1440 P2 cut 1).
if (req.method === "PUT" && req.url === "/__bili/external-summary/credential") return handleSummaryCredentialPut(req, res);
if (req.method === "POST" && req.url === "/__bili/config/reload") return handleConfigReload(opts, res, log);
// #2102: wipe the diagnostic conflict ledgers (global, or one session via
// ?session=<id>). Loopback + trusted-origin gated like every /__bili/ path.
Expand Down
67 changes: 67 additions & 0 deletions tests/web-routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,73 @@ test("PUT /__bili/config with providers takes effect without a separate reload c
}
});

test("PUT /__bili/external-summary/credential routes to the private store (#3443)", async () => {
_setStoreForTest(new SessionStore({ enabled: false }));
setRegistryForTest({});
const root = path.join(tmpdir(), `bili-summary-cred-${process.pid}-${Date.now()}`);
mkdirSync(root, { recursive: true });
const biliConfig = path.join(root, "billion-context.json");
writeFileSync(biliConfig, JSON.stringify({ providers: { deepseek: { baseUrl: "https://api.deepseek.com", api: "openai", credentialRef: "primary", models: { "deepseek-chat": {} } } }, compress: { externalSummary: { enabled: true, targets: ["deepseek/deepseek-chat"] } } }), "utf8");
const prevConfig = process.env.BILI_CONFIG_FILE;
process.env.BILI_CONFIG_FILE = biliConfig;
const opts: ProxyOptions = {
port: 0,
host: "127.0.0.1",
upstream: "http://127.0.0.1:1",
routes: {},
proxy: "",
proxyMode: "direct",
proxySource: "direct",
modelContextLimit: 400_000,
kernelConfig: defaultConfig(400_000),
compress: { injectTool: true, injectNudge: true },
promptCache: { routing: "auto" },
sessionHeader: "x-acp-session",
log: false,
debug: false,
passthrough: false,
passthroughSource: null,
autoUpdate: false,
autoRestartOnUpdate: false,
updateTag: "latest",
advisoryCheck: false,
releaseNotesCheck: false,
compat: { roles: {} },
streamErrorShape: "protocol",
mitm: { enabled: false, domains: [] },
};
const proxy = await startServer(opts);
if (!proxy.listening) await once(proxy, "listening");
const port = (proxy.address() as { port: number }).port;
const base = `http://127.0.0.1:${port}`;
try {
const put = (body: unknown) => fetch(`${base}/__bili/external-summary/credential`, {
method: "PUT",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
});
const malformed = await put({ name: "primary" });
assert.equal(malformed.status, 400);
assert.match(await malformed.text(), /expected name and key/);
const key = "test-route-never-echoed-key";
const savedRaw = await (await put({ name: "primary", key })).text();
assert.equal(savedRaw.includes(key), false);
assert.deepEqual(JSON.parse(savedRaw), { ok: true, configured: true });
const storePath = `${biliConfig}.summary-credentials.json`;
assert.ok(readFileSync(storePath, "utf8").includes(key), "routed handler wrote the private store file");
const view = await (await fetch(`${base}/__bili/config`)).json() as { externalSummaryCredentials: Record<string, boolean> };
assert.equal(view.externalSummaryCredentials["secret:primary"], true);
const deletedRaw = await (await put({ name: "primary", key: null })).text();
assert.deepEqual(JSON.parse(deletedRaw), { ok: true, configured: false });
const afterDelete = await (await fetch(`${base}/__bili/config`)).json() as { externalSummaryCredentials: Record<string, boolean> };
assert.equal(afterDelete.externalSummaryCredentials["secret:primary"], false);
} finally {
await close(proxy);
if (prevConfig === undefined) delete process.env.BILI_CONFIG_FILE; else process.env.BILI_CONFIG_FILE = prevConfig;
rmrf(root);
}
});

test("parseCompressSettings round-trips prompts overrides (#155 + #157 interplay)", () => {
const withPrompts = {
nudgeGrowthTokens: 4000,
Expand Down
Loading