feat(agent): unify MCP tools and adopt Responses delivery

Move project and host queries into native MCP with host-owned OAuth/context,
while retaining memory, skills, actions and publication plugins. Add nearby-model
queries and explicit chat/task/learning model defaults.

Adopt Responses HTTP/SSE and native steer/queue inbox delivery, preserving scoped
session ownership, pending input edits and investigation communication.

Disable local-provider discovery: Server /health allowed native vLLM to probe
/v1/models on port 8000. A native before/after regression prevents recurrence.

Validation: 170 focused Bun tests; service/plugin typechecks; native discovery,
provider-discovery and input-inbox smoke checks; no paid model inference.
This commit is contained in:
2026-10-19 18:46:58 +08:00
parent f5c3cde2c2
commit 6a49d2209e
164 changed files with 12286 additions and 2368 deletions
@@ -1,28 +1,17 @@
import { afterEach, describe, expect, it } from "bun:test";
import { ExternalInformationClient, geocodeInput, webSearchInput } from "../../src/product/external-information-client.js";
import { ExternalInformationClient, geocodeInput } from "../../src/product/external-information-client.js";
import { bindSessionCredential, credentialRefreshCoordinator, refreshSessionCredential, releaseSessionCredential } from "../../src/product/credential-refresh.js";
const originalFetch = globalThis.fetch;
const session = "external-information-test";
afterEach(() => { globalThis.fetch = originalFetch; releaseSessionCredential(session); });
describe("typed external information", () => {
it("uses the fixed Server endpoint and trusted project, translating freshness", async () => {
bindSessionCredential(session, { authorization: "Bearer TEST", projectId: "trusted" });
globalThis.fetch = (async (url: Parameters<typeof fetch>[0], init?: RequestInit) => {
expect(String(url)).toBe("http://server.test/api/v1/web-searches");
expect(new Headers(init?.headers).get("Authorization")).toBe("Bearer TEST");
expect(new Headers(init?.headers).get("X-Project-Id")).toBe("trusted");
expect(JSON.parse(String(init?.body))).toEqual({ query: "供水政策", freshness: "oneWeek", summary: true, count: 10, include: ["gov.cn"] });
return Response.json({ data: { webPages: { value: [{ url: "https://gov.cn/example", name: "example" }] } } });
}) as unknown as typeof fetch;
const result = await new ExternalInformationClient("http://server.test").webSearch(session, webSearchInput.parse({ query: "供水政策", freshness: "one_week", include: ["gov.cn"] }));
expect(result).toHaveProperty("data.webPages.value");
});
it("normalizes valid Tianditu coordinates for zoom_to_map and rejects fabricated coordinates", async () => {
bindSessionCredential(session, { authorization: "Bearer TEST", projectId: "trusted" });
globalThis.fetch = (async (url: Parameters<typeof fetch>[0], init?: RequestInit) => {
expect(new URL(String(url)).pathname).toBe("/api/v1/geocoding-requests");
expect(new Headers(init?.headers).get("Authorization")).toBe("Bearer TEST");
expect(new Headers(init?.headers).get("X-Project-Id")).toBe("trusted");
expect(JSON.parse(String(init?.body))).toEqual({ keyword: "北京市人民政府" });
return Response.json({ status: "0", location: { lon: "116.4", lat: "39.9", level: 1 } });
}) as unknown as typeof fetch;
@@ -52,11 +41,9 @@ describe("typed external information", () => {
} finally { unsubscribe(); }
});
it("rejects scope, URL overrides, empty queries and invalid counts before dispatch", async () => {
expect(webSearchInput.safeParse({ query: "test", url: "http://untrusted" }).success).toBeFalse();
expect(webSearchInput.safeParse({ query: "test", project_id: "other" }).success).toBeFalse();
expect(webSearchInput.safeParse({ query: "test", count: 51 }).success).toBeFalse();
expect(webSearchInput.safeParse({ query: "test", include: ["https://example.com/path"] }).success).toBeFalse();
it("rejects scope, URL overrides and empty keywords before dispatch", async () => {
expect(geocodeInput.safeParse({ keyword: "北京", url: "http://untrusted" }).success).toBeFalse();
expect(geocodeInput.safeParse({ keyword: "北京", project_id: "other" }).success).toBeFalse();
expect(geocodeInput.safeParse({ keyword: " " }).success).toBeFalse();
await expect(new ExternalInformationClient().geocode(session, { keyword: "北京" })).rejects.toMatchObject({ status: 401 });
});