Add runtime provider controls and searchable AI routing
CI / verify (push) Has been cancelled
CI / publish (push) Has been cancelled

Manage provider keys at runtime, route current-information questions through server-side search with safe fallback, and scope OOBE usage claims to grants.
This commit is contained in:
Rocky
2026-08-22 16:33:17 +08:00
parent f8fa93dc48
commit 9fb947aa7d
43 changed files with 2079 additions and 80 deletions
+26
View File
@@ -276,4 +276,30 @@ describe("adminApi", () => {
);
expect(result.totpSecret).toBe("JBSWY3DPEHPK3PXP");
});
it("Provider API Key 替换请求携带 CSRF 且只提交新 Key", async () => {
const fetchMock = vi.fn().mockResolvedValue(
new Response(
JSON.stringify({
providerId: "deepseek",
configured: true,
source: "RUNTIME_OVERRIDE",
updatedAt: "2026-08-22T08:00:00Z",
}),
{ status: 200, headers: { "Content-Type": "application/json" } },
),
);
vi.stubGlobal("fetch", fetchMock);
setCsrfToken("csrf-provider");
await adminApi.updateProviderApiKey("deepseek", { apiKey: "new-provider-key" });
expect(fetchMock.mock.calls[0]?.[0]).toBe(
"/v1/admin/providers/deepseek/api-key",
);
const request = fetchMock.mock.calls[0]?.[1] as RequestInit;
expect(request.method).toBe("PUT");
expect((request.headers as Headers).get("X-CSRF-Token")).toBe("csrf-provider");
expect(request.body).toBe(JSON.stringify({ apiKey: "new-provider-key" }));
});
});