Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ee327cf
fix(assistant): let the assistant's tools be imported first
claude Oct 16, 2026
defb487
feat(chat): each answer records what produced it
claude Oct 17, 2026
983d046
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Oct 17, 2026
acf97d7
test(notes): keep the daily notes test from failing on 2026-10-17
claude Oct 17, 2026
db85b14
Merge origin/main into claude/project-thread-r960xc-c1-record
claude Oct 17, 2026
275692b
Merge remote-tracking branch 'origin/main' into port-c1
claude Oct 17, 2026
33a2c19
feat(chat): choose tools, a tool-call limit and a scope per answer
claude Oct 17, 2026
448565d
Merge remote-tracking branch 'origin/claude/project-thread-r960xc-c1-…
claude Oct 17, 2026
957c3f1
docs(chat): choosing tools, namespaces and a limit; regenerate the cl…
claude Oct 17, 2026
8759a60
feat(chat): a choice made as a conversation starts is the latest choice
claude Oct 17, 2026
73d10e7
fix(chat): setting the server up keeps every tool, whatever the lates…
claude Oct 17, 2026
554668b
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Oct 17, 2026
a22d140
Merge origin/main into claude/project-thread-r960xc-c4-tools
claude Oct 17, 2026
3f0b9de
test(entities): wait for the typed search before counting merge options
claude Oct 17, 2026
33e40f0
Merge origin/main into claude/project-thread-r960xc-c4-tools
claude Oct 17, 2026
dde1384
Merge origin/main into claude/project-thread-r960xc-c4-tools
claude Oct 17, 2026
e6b5cfa
test(settings): the AI section's server values include ai.max_tool_calls
claude Oct 17, 2026
cdf1f0c
Merge origin/main into claude/project-thread-r960xc-c4-tools
claude Oct 17, 2026
a9e21e5
fix(chat): find_resources belongs to the archive's tools
claude Oct 17, 2026
daa8aaa
Merge origin/main into claude/project-thread-r960xc-c4-tools
claude Oct 17, 2026
98b7a8b
docs(chat): a new built-in tool joins a tool group
claude Oct 17, 2026
e8073d6
feat(chat): a Tools chip to pick tools and a limit, and all namespace…
claude Oct 17, 2026
181c5d7
Merge remote-tracking branch 'origin/main' into port-c4
claude Oct 17, 2026
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version
assistant → Most tool calls a question may ask for, 50 by default) and narrow one answer to its own namespaces
(`scope`). `GET /api/v1/chats/tools` lists the groups a person has, what each tool does (reads, asks first, sends data
out) and why a group is missing. An admin's switches still win, and new conversations start with the person's last
choice. The web app's Tools chip is in progress
choice. In the web app, a Tools chip beside the scope picks them, and "All my namespaces" tops the scope's list
([Choosing tools, namespaces and a limit](docs/assistant.md#choosing-tools-namespaces-and-a-limit)).
- **Names get their real types, not Term.** The built-in extractor now tells people, places, organisations, events,
works and dates apart without a model: by a title or role before a name, a given name, the word a name ends or
Expand Down
5 changes: 4 additions & 1 deletion docs/assistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ tools it may use, how many tool calls it may make, and which namespaces it reads
- **Web and MCP tools reach beyond your namespaces.** The namespaces picked narrow the archive's tools only. A web
search, an MCP server or the browser reads and sends wherever it reaches.

In the web app, a Tools chip beside the composer's scope picks these (in progress).
In the web app, the **Tools** chip beside the composer's scope picks these for the conversation (Enter or a tap opens
it): Auto, a switch for each group (marked "needs approval" or "sends data out"; one you don't have says why, with a
link to its setting for admins) and a limit on tool calls per answer. A conversation not started yet opens on your
latest choice. "All my namespaces" at the top of the scope's namespaces goes back to everything in one tap.

Refine later: tool choice in chat rooms and voice mode, a default choice per namespace, and the model suggesting the
tools a question needs.
Expand Down
149 changes: 149 additions & 0 deletions nextjs-frontend/__tests__/chat-tools-picker.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
import "@testing-library/jest-dom";

import type { ChatTools } from "@/app/openapi-client/types.gen";
import { ScopeBar } from "@/components/chat/composer";
import { choiceLabel, settingLink, ToolsChip, type ToolChoice } from "@/components/chat/tools-picker";

jest.mock("@/app/openapi-client", () => ({ Chats: { chatTools: jest.fn() }, Collections: {} }));
jest.mock("next-auth/react", () => ({ useSession: () => ({ data: { accessToken: "t" } }) }));
jest.mock("@/lib/hooks/session", () => ({
useArchive: () => ({
namespaces: [
{ name: "pods", recordings: 3, minutes: 40 },
{ name: "calls", recordings: 2, minutes: 10 },
],
}),
}));
jest.mock("@/components/import/pending", () => ({ chooseFiles: jest.fn(() => Promise.resolve([])) }));

beforeAll(() => {
// Radix's popper measures what it places
global.ResizeObserver = class {
observe() {}
unobserve() {}
disconnect() {}
} as unknown as typeof ResizeObserver;
});

const group = (name: string, label: string, more: Partial<ChatTools["groups"][number]> = {}) => ({
name,
label,
tools: [{ name: `${name}_tool`, effect: "read" as const, out: false, available: more.available ?? true }],
asks: false,
out: false,
available: true,
why: null,
setting: null,
...more,
});

const CATALOG: ChatTools = {
groups: [
group("archive", "Archive"),
group("notes", "Notes", { asks: true }),
group("browser", "Your browser", {
out: true,
available: false,
why: "switched off by an admin",
setting: "ai.browser",
}),
group("server", "Server", { available: false, why: "for admins" }),
],
max_tool_calls: 12,
remembered: { tools: null, max_tool_calls: null },
namespaces_note:
"Web and MCP tools reach beyond your namespaces: the namespaces you pick narrow the archive's tools only.",
};

function chip(value: ToolChoice, admin = false) {
const onChange = jest.fn();
render(<ToolsChip value={value} onChange={onChange} catalog={CATALOG} admin={admin} />);
const button = screen.getByRole("button", { name: /Choose the tools for this conversation/ });
return { onChange, button };
}

describe("the Tools chip", () => {
it("is a button, so Enter opens it, and says what is picked", () => {
const { button } = chip({ tools: null, max_tool_calls: null });
expect(button.tagName).toBe("BUTTON");
expect(button).toHaveTextContent("Tools: Auto");
expect(choiceLabel({ tools: [], max_tool_calls: null })).toBe("Tools: no tools");
expect(choiceLabel({ tools: ["archive", "notes"], max_tool_calls: 5 })).toBe("Tools: 2 picked · 5 calls");
});

it("opens on Auto, with every group you have on and the others saying why", () => {
const { button } = chip({ tools: null, max_tool_calls: null });
fireEvent.click(button);
const dialog = screen.getByRole("dialog");
expect(within(dialog).getByRole("switch", { name: /Auto/ })).toBeChecked();
expect(within(dialog).getByRole("switch", { name: "Archive" })).toBeChecked();
expect(within(dialog).getByRole("switch", { name: "Server" })).toBeDisabled();
expect(within(dialog).getByText("For admins.")).toBeInTheDocument();
expect(within(dialog).getByText("needs approval")).toBeInTheDocument();
expect(within(dialog).getByText("sends data out")).toBeInTheDocument();
expect(within(dialog).getByText(/Web and MCP tools reach beyond your namespaces/)).toBeInTheDocument();
// only admins are sent to the setting
expect(within(dialog).queryByRole("link", { name: "Open settings" })).not.toBeInTheDocument();
});

it("links an admin to the setting that switches a group back on", () => {
fireEvent.click(chip({ tools: null, max_tool_calls: null }, true).button);
expect(screen.getByRole("link", { name: "Open settings" })).toHaveAttribute("href", settingLink("ai.browser"));
expect(settingLink("ai.browser")).toBe("/settings/ai?field=ai.browser");
});

it("turning a group off leaves Auto with the rest of what you have", () => {
const { button, onChange } = chip({ tools: null, max_tool_calls: null });
fireEvent.click(button);
fireEvent.click(screen.getByRole("switch", { name: "Notes" }));
expect(onChange).toHaveBeenCalledWith({ tools: ["archive"], max_tool_calls: null });
});

it("picks groups, keeps single tools, and goes back to Auto", () => {
const { button, onChange } = chip({ tools: ["archive", "find_entities"], max_tool_calls: null });
fireEvent.click(button);
expect(screen.getByRole("switch", { name: "Notes" })).not.toBeChecked();
expect(screen.getByText("Also picked: find_entities")).toBeInTheDocument();
fireEvent.click(screen.getByRole("switch", { name: "Notes" }));
expect(onChange).toHaveBeenLastCalledWith({ tools: ["archive", "find_entities", "notes"], max_tool_calls: null });
fireEvent.click(screen.getByRole("switch", { name: /Auto/ }));
expect(onChange).toHaveBeenLastCalledWith({ tools: null, max_tool_calls: null });
});

it("limits the tool calls, from 1 to the server's most", () => {
let r = chip({ tools: null, max_tool_calls: null });
fireEvent.click(r.button);
fireEvent.click(screen.getByRole("switch", { name: "Limit tool calls per answer" }));
expect(r.onChange).toHaveBeenCalledWith({ tools: null, max_tool_calls: 10 });
cleanup();

r = chip({ tools: null, max_tool_calls: 12 });
fireEvent.click(r.button);
expect(screen.getByRole("button", { name: "More tool calls" })).toBeDisabled();
fireEvent.click(screen.getByRole("button", { name: "Fewer tool calls" }));
expect(r.onChange).toHaveBeenLastCalledWith({ tools: null, max_tool_calls: 11 });
fireEvent.change(screen.getByRole("spinbutton", { name: "Tool calls per answer" }), { target: { value: "40" } });
expect(r.onChange).toHaveBeenCalledTimes(1); // past the most: not sent
fireEvent.change(screen.getByRole("spinbutton", { name: "Tool calls per answer" }), { target: { value: "3" } });
expect(r.onChange).toHaveBeenLastCalledWith({ tools: null, max_tool_calls: 3 });
});
});

describe("the scope's namespaces", () => {
it("go back to all of them in one tap", () => {
const onChange = jest.fn();
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
render(
<QueryClientProvider client={qc}>
<ScopeBar scope={{ namespaces: ["pods"] }} onChange={onChange} model={null} tools={null} />
</QueryClientProvider>,
);
fireEvent.click(screen.getByRole("button", { name: "Scope" }));
const all = screen.getByRole("checkbox", { name: "All my namespaces" });
expect(all).not.toBeChecked();
fireEvent.click(all);
expect(onChange).toHaveBeenCalledWith({ namespaces: undefined });
});
});
47 changes: 44 additions & 3 deletions nextjs-frontend/components/chat/chat-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { EmptyChat } from "@/components/chat/empty";
import { NamespaceOffer, spokenPick } from "@/components/chat/namespace-offer";
import { fromApiScope, scopeFromParams, toApiScope, type Scope } from "@/components/chat/scope";
import { CitationSheet, SourcesPanel, SourcesSheet } from "@/components/chat/sources";
import { ToolsChip, useToolCatalog, type ToolChoice } from "@/components/chat/tools-picker";
import {
applyEvent,
newTurn,
Expand Down Expand Up @@ -103,6 +104,7 @@ export function ChatApp() {
const linkScope = useMemo(() => scopeFromParams(new URLSearchParams(search.toString())), [search]);
const [draftScope, setDraftScope] = useState<Scope>(() => linkScope);
const [draftModel, setDraftModel] = useState<string | null>(null); // for the conversation that isn't started yet
const [draftTools, setDraftTools] = useState<ToolChoice | null>(null); // and its tools, when picked before it starts
const [draft, setDraft] = useState(() => search.get("q") ?? "");
const [composing, setComposing] = useState(() =>
Boolean(
Expand Down Expand Up @@ -320,11 +322,18 @@ export function ChatApp() {
const created = await data(
Chats.createChat({
client,
body: kind === "setup" ? { kind } : { scope: toApiScope(draftScope), model: draftModel ?? undefined },
body:
kind === "setup"
? { kind }
: { scope: toApiScope(draftScope), model: draftModel ?? undefined, ...(draftTools ?? {}) },
}),
);
cid = created.id;
qc.invalidateQueries({ queryKey: ["chats"] });
if (draftTools) {
setDraftTools(null); // it's the latest choice now: the next new conversation starts with it
void qc.invalidateQueries({ queryKey: ["chat-tools"] });
}
setComposing(false);
router.replace(`/chat/${cid}`);
} catch (e) {
Expand All @@ -339,7 +348,7 @@ export function ChatApp() {
}
return run(cid, question, model, attached, edit);
},
[activeId, client, draftScope, draftModel, qc, router, run, toast],
[activeId, client, draftScope, draftModel, draftTools, qc, router, run, toast],
);

// What you send while an answer is being written waits its turn, so you never have to wait to type.
Expand Down Expand Up @@ -599,6 +608,28 @@ export function ChatApp() {
}
};
const noProvider = llm.known && !llm.configured;

// what the answers may use: the conversation's choice, else the one picked before it started, else your latest
const usesTools = llm.known && llm.configured && llm.tools;
const toolCatalog = useToolCatalog(activeId, usesTools);
const toolChoice: ToolChoice =
activeId != null
? { tools: chat.data?.tools ?? null, max_tool_calls: chat.data?.max_tool_calls ?? null }
: (draftTools ?? {
tools: toolCatalog.data?.remembered.tools ?? null,
max_tool_calls: toolCatalog.data?.remembered.max_tool_calls ?? null,
});
const pickTools = async (v: ToolChoice) => {
if (activeId == null) return setDraftTools(v);
try {
await data(Chats.updateChat({ client, path: { cid: activeId }, body: v }));
await qc.invalidateQueries({ queryKey: ["chat", activeId] });
void qc.invalidateQueries({ queryKey: ["chats"] });
void qc.invalidateQueries({ queryKey: ["chat-tools"] });
} catch (e) {
toast({ title: "Couldn’t change the tools", body: e instanceof Error ? e.message : undefined, tone: "red" });
}
};
const showThread = activeId != null || liveHere != null;
// setting the server up doesn't look in the archive: no sources column to fill
const setupChat = activeId != null && chat.data?.kind === "setup";
Expand Down Expand Up @@ -851,6 +882,16 @@ export function ChatApp() {
models={llm.models}
onModel={(m) => void pickModel(m)}
openTick={scopeOpenTick}
toolsChip={
usesTools && !setupChat ? (
<ToolsChip
value={toolChoice}
onChange={(v) => void pickTools(v)}
catalog={toolCatalog.data}
admin={admin}
/>
) : undefined
}
/>
{queue.length > 0 && (
<ul className="flex flex-col gap-1" aria-label="Waiting to send">
Expand Down Expand Up @@ -920,7 +961,7 @@ export function ChatApp() {
function ScopeBarWithOpen({ openTick, ...props }: Parameters<typeof ScopeBar>[0] & { openTick: number }) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (openTick) ref.current?.querySelector<HTMLButtonElement>("button[aria-haspopup='dialog']")?.click();
if (openTick) ref.current?.querySelector<HTMLButtonElement>("button[data-scope-open]")?.click();
}, [openTick]);
return (
<div ref={ref}>
Expand Down
19 changes: 17 additions & 2 deletions nextjs-frontend/components/chat/composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ function ScopePicker({
<div className="max-h-[300px] overflow-y-auto">
{section === "namespaces" && (
<ul className="m-0 flex list-none flex-col gap-2 p-0">
<li className="flex items-center gap-2 border-b border-border pb-2">
<Checkbox
checked={!scope.namespaces?.length}
onCheckedChange={() => onChange({ ...scope, namespaces: undefined })}
label={<span className="font-semibold">All my namespaces</span>}
/>
<span className="ml-auto text-[12px] text-fg-muted">{namespaceSize(namespaces)}</span>
</li>
{namespaces.map((n) => (
<li key={n.name} className="flex items-center gap-2">
<Checkbox
Expand All @@ -161,7 +169,8 @@ function ScopePicker({
</li>
))}
<li className="pt-1 text-[12px] text-fg-muted">
None ticked means all your namespaces. Scope never goes beyond what you can read.
Scope never goes beyond what you can read. It narrows the archive’s tools: web and MCP tools reach beyond
your namespaces.
</li>
</ul>
)}
Expand Down Expand Up @@ -298,14 +307,16 @@ function useCollectionNames(enabled: boolean): Map<number, string> {
return useMemo(() => new Map((cols.data ?? []).map((c) => [c.id, c.name])), [cols.data]);
}

/** Scope chips (each shows its size), "+ Scope", and which model answers (a menu, when there's a choice). */
/** Scope chips (each shows its size), "+ Scope", the Tools chip, and which model answers (a menu, when there's a
* choice). */
export function ScopeBar({
scope,
onChange,
model,
tools,
models = [],
onModel,
toolsChip,
className,
}: {
scope: Scope;
Expand All @@ -315,6 +326,8 @@ export function ScopeBar({
/** The models people may pick (GET /chats/capabilities). */
models?: string[];
onModel?: (m: string) => void;
/** What the answers may use (the Tools chip), after the scope. */
toolsChip?: ReactNode;
className?: string;
}) {
const { namespaces } = useArchive();
Expand Down Expand Up @@ -379,6 +392,7 @@ export function ScopeBar({
<PopoverTrigger asChild>
<button
type="button"
data-scope-open
className="inline-flex h-7 items-center gap-1 rounded-pill border border-dashed border-border px-2.5 text-[12px] font-semibold text-fg-secondary hover:border-fg-muted hover:text-fg"
>
<Plus className="size-3" aria-hidden /> Scope
Expand All @@ -388,6 +402,7 @@ export function ScopeBar({
<ScopePicker scope={scope} onChange={onChange} onClose={() => setOpen(false)} />
</PopoverContent>
</Popover>
{toolsChip}
<span className="flex-1" />
{model &&
(models.length > 1 && onModel ? (
Expand Down
Loading
Loading