feat(agent): search_documents tool — the model can grep the indexed documents for an exact string
This commit is contained in:
+27
-18
@@ -55,20 +55,22 @@
|
||||
* "New chat" (#new-chat-btn — bound by the shared header module,
|
||||
* phase 34 task 02) clears the key + the list back to the empty state.
|
||||
*
|
||||
* Agent tool calls (phase 37, PLAN §4 extension): a grounded turn may
|
||||
* call the two server-side document tools (list_documents /
|
||||
* read_document, budgeted server-side). Each call streams a `tool` SSE
|
||||
* frame, and the UI shows the "calling tool" state IN ADDITION to
|
||||
* "thinking": the UI state itself stays "thinking" (the button stays
|
||||
* the enabled "Stop" control — phase 48 — never stale, PLAN §7.4) while
|
||||
* the STATUS LABELS change — the #send-status + typing-indicator labels
|
||||
* say what Brain is doing ("…is listing documents" /
|
||||
* "…is reading source/path" — the name prefix resolves from
|
||||
* window.BOR_BRAND at call time, phase 39) — the button no longer
|
||||
* relabels to "Calling tool…" (phase 48, owner-locked: it stays "Stop"
|
||||
* for the whole turn) — and a visible `.tool-call` line (own icon +
|
||||
* accent color, distinct from the brand-ink Thinking block) is appended
|
||||
* above the answer, one per call, in order.
|
||||
* Agent tool calls (phase 37, PLAN §4 extension; phase 68 added
|
||||
* search_documents): a grounded turn may call the three server-side
|
||||
* document tools (list_documents / read_document / search_documents,
|
||||
* bounded only by the round cap — phases 45/68). Each call streams a
|
||||
* `tool` SSE frame, and the UI shows the "calling tool" state IN
|
||||
* ADDITION to "thinking": the UI state itself stays "thinking" (the
|
||||
* button stays the enabled "Stop" control — phase 48 — never stale,
|
||||
* PLAN §7.4) while the STATUS LABELS change — the #send-status +
|
||||
* typing-indicator labels say what Brain is doing ("…is listing
|
||||
* documents" / "…is reading source/path" / "…is searching for
|
||||
* pattern" — the name prefix resolves from window.BOR_BRAND at call
|
||||
* time, phase 39) — the button no longer relabels to "Calling tool…"
|
||||
* (phase 48, owner-locked: it stays "Stop" for the whole turn) — and a
|
||||
* visible `.tool-call` line (own icon + accent color, distinct from
|
||||
* the brand-ink Thinking block) is appended above the answer, one per
|
||||
* call, in order.
|
||||
* Append-only like thinking: frames are tolerated in any interleaving
|
||||
* (a frame after the first delta just appends — the agent loop never
|
||||
* emits one, but it must not crash). The turn record persists an
|
||||
@@ -808,9 +810,9 @@ function closeThinkingBlock(wrap) {
|
||||
* interleaving with thinking frames, even after the first delta (the
|
||||
* agent loop never emits one, but a late frame must not crash) — just
|
||||
* append another line, in order. The SAME helper re-renders the
|
||||
* persisted lines on restore (phase 14 convention): the path argument
|
||||
* goes through textContent, so nothing HTML-shaped can come from
|
||||
* storage. Lines are not interactive (no focus targets). */
|
||||
* persisted lines on restore (phase 14 convention): the path/pattern
|
||||
* argument goes through textContent, so nothing HTML-shaped can come
|
||||
* from storage. Lines are not interactive (no focus targets). */
|
||||
function appendToolLine(wrap, name, argument) {
|
||||
const body = wrap?.querySelector?.(".msg-body");
|
||||
if (!body) return;
|
||||
@@ -832,6 +834,11 @@ function appendToolLine(wrap, name, argument) {
|
||||
const code = document.createElement("code");
|
||||
code.textContent = argument; // the path is data, never markup
|
||||
line.appendChild(code);
|
||||
} else if (name === "search_documents" && argument) {
|
||||
line.textContent = "🔎 Searching for ";
|
||||
const code = document.createElement("code");
|
||||
code.textContent = argument; // the pattern is data, never markup
|
||||
line.appendChild(code);
|
||||
} else {
|
||||
line.textContent = "🔎 Listing documents";
|
||||
}
|
||||
@@ -1936,7 +1943,9 @@ async function runTurn(text, { reask = false } = {}) {
|
||||
const toolStatus =
|
||||
name === "read_document" && argument
|
||||
? `${brand()} is reading ${argument}`
|
||||
: `${brand()} is listing documents`;
|
||||
: name === "search_documents" && argument
|
||||
? `${brand()} is searching for ${argument}`
|
||||
: `${brand()} is listing documents`;
|
||||
if (uiState === UI_STATE.thinking) {
|
||||
sendStatus.textContent = toolStatus;
|
||||
document
|
||||
|
||||
Reference in New Issue
Block a user