Wave A: pi-native tool layer — delete LhTool/toPiTool, TypeBox everywhere, terminate on questions
- src/agent/lh-tool.ts deleted: the zod-wrapped LhTool + toPiTool bridge (z.toJSONSchema per call, clientQuestion flag, hand-rolled result mapping) is gone. Tools are pi-agent-core native AgentTools now. - New src/agent/tool-execute.ts owns what the wrapper added: the abort guard (runWithAbortGuard: run signal + 30s per-call timeout + 250ms grace, 'Operation aborted' / timeout wording preserved), ToolInputError (the retryable '- problem at path' format), result mapping (string verbatim / object JSON / image parts, details rides the record's tool part output), and questionResult() — placeholder + terminate:true (owner Option A: belt of terminate + slim makeQuestionStopper with the clean-question rule; maxTurns deleted from the teaching turn entirely per owner). - All 11 tool files + tools.ts registries converted to TypeBox parameters (typebox@1.3.7, pinned to pi-agent-core's copy). zod refinements (quizInputProblems, askOptionProblems, live-nodeId) moved from schemas into execute — the model sees the same retryable error shape. - question-core + contracts/probe TypeBox-authored (single source shared with the UI); tool-parts parse seam runs the boundary's full chain (Convert → Check → Clean → refinement), fixing the live-smoke lockout: pi's boundary Value.Converts correctAnswer: 17 → '17' but the record keeps raw args, so a parse without Convert rejected a posed quiz (invisible pending question, turn ended). Pinned with the real smoke emission shape. - Subagents converted: demo-builder/researcher AgentTool-native, visual-maker/pdf-reader declaration-only pi-ai Tools with local execute fns, extraction submit schemas re-authored in TypeBox (owner option 2: zod defaults → Type.Optional + fill at the submit seam). - Accepted delta, flagged: TypeBox-native schemas skip pi's JSON-Schema primitive coercion fast path... (boundary still Value.Converts), and prober-quiz unknown keys ride through (Value.Clean strips at display). - Tests: 988 passing (was 967 at the recon baseline); tool-abort and read-tool rewritten against the native seams; question-core/question- tools/tool-parts/demos/web-search/graph-tools/plan-tree/probe-done/ tool-toggles converted to Value.Check/execute pins. Live smoke (PORT=3004, real model): native ls turn streams end-to-end; a real quiz pose (first attempt missing correctAnswer → tool-input-error → model retry → posed) terminates the turn cleanly and persists pending.
This commit is contained in:
+13
-13
@@ -31,9 +31,9 @@ function stubProvider(hits: SearchHit[] = [{ title: "t", url: "https://e.com/",
|
||||
describe("web_search on the injected port (web.ts)", () => {
|
||||
it("null provider → the honest unavailability string, never a crash", async () => {
|
||||
const { web_search } = createWebTools(() => null);
|
||||
const out = await web_search.execute!({ query: "anything" }, { toolCallId: "c1" });
|
||||
assert.match(String(out), /not available: no search engine is configured/);
|
||||
assert.match(String(out), /Tavily or Brave/);
|
||||
const out = await web_search!.execute!("c1", { query: "anything" });
|
||||
assert.match(String(out.details), /not available: no search engine is configured/);
|
||||
assert.match(String(out.details), /Tavily or Brave/);
|
||||
});
|
||||
|
||||
it("a live provider returns its hits (count defaults to 5)", async () => {
|
||||
@@ -46,9 +46,9 @@ describe("web_search on the injected port (web.ts)", () => {
|
||||
},
|
||||
};
|
||||
const { web_search } = createWebTools(() => provider);
|
||||
const out = await web_search.execute!({ query: "sigma.js latest version" }, { toolCallId: "c1" });
|
||||
const out = await web_search!.execute!("c1", { query: "sigma.js latest version" });
|
||||
assert.deepEqual(seen, [{ query: "sigma.js latest version", count: 5 }]);
|
||||
assert.deepEqual(out, [{ title: "sigma.js", url: "https://www.sigmajs.org/", snippet: "v3 released" }]);
|
||||
assert.deepEqual(out.details, [{ title: "sigma.js", url: "https://www.sigmajs.org/", snippet: "v3 released" }]);
|
||||
});
|
||||
|
||||
it("provider errors surface as error strings, never thrown", async () => {
|
||||
@@ -59,26 +59,26 @@ describe("web_search on the injected port (web.ts)", () => {
|
||||
},
|
||||
};
|
||||
const { web_search } = createWebTools(() => provider);
|
||||
const out = await web_search.execute!({ query: "q" }, { toolCallId: "c1" });
|
||||
assert.match(String(out), /web_search failed: Brave search API 429: rate limited/);
|
||||
const out = await web_search!.execute!("c1", { query: "q" });
|
||||
assert.match(String(out.details), /web_search failed: Brave search API 429: rate limited/);
|
||||
});
|
||||
|
||||
it("the resolution is FRESH per call — a key appearing mid-session takes effect", async () => {
|
||||
let provider: SearchProvider | null = null;
|
||||
const { web_search } = createWebTools(() => provider);
|
||||
const first = await web_search.execute!({ query: "q" }, { toolCallId: "c1" });
|
||||
assert.match(String(first), /not available/);
|
||||
const first = await web_search!.execute!("c1", { query: "q" });
|
||||
assert.match(String(first.details), /not available/);
|
||||
provider = stubProvider();
|
||||
const second = await web_search.execute!({ query: "q" }, { toolCallId: "c2" });
|
||||
assert.ok(Array.isArray(second), "the live provider answered on the very next call");
|
||||
const second = await web_search!.execute!("c2", { query: "q" });
|
||||
assert.ok(Array.isArray(second.details), "the live provider answered on the very next call");
|
||||
});
|
||||
|
||||
it("web_fetch needs no search engine — it stays independent", async () => {
|
||||
const { web_fetch } = createWebTools(() => null);
|
||||
assert.ok(web_fetch, "web_fetch present with no provider");
|
||||
// (Full fetch behavior is out of scope here — no network in tests.)
|
||||
const out = await web_fetch.execute!({ url: "not a url" }, { toolCallId: "c1" });
|
||||
assert.match(String(out), /web_fetch failed: invalid URL/);
|
||||
const out = await web_fetch!.execute!("c1", { url: "not a url" });
|
||||
assert.match(String(out.details), /web_fetch failed: invalid URL/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user