Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

frontend tools to be filtered based on chat mode (#7225)

Shahmir Varqhab0e7bd4b2776
diff --git a/frontend/src/components/chat/chat-panel.tsx b/frontend/src/components/chat/chat-panel.tsx
index d7c60e6011..2b2d020f54 100644
--- a/frontend/src/components/chat/chat-panel.tsx
+++ b/frontend/src/components/chat/chat-panel.tsx
@@ -182,7 +182,7 @@ const ChatMessageDisplay: React.FC<ChatMessageProps> = memo(
const content = textParts.map((p) => p.text).join("\n");
return (
- <div className="w-[95%] break-words">
+ <div className="w-[95%] wrap-break-word">
<div className="absolute right-1 top-1 opacity-0 group-hover:opacity-100 transition-opacity">
<CopyClipboardIcon className="h-3 w-3" value={content || ""} />
</div>
@@ -567,9 +567,13 @@ const ChatPanelBody = () => {
options.messages,
);
+ // Call this here to ensure the value is not stale
+ const chatMode = store.get(aiAtom)?.mode || DEFAULT_MODE;
+ const tools = FRONTEND_TOOL_REGISTRY.getToolSchemas(chatMode);
+
return {
body: {
- tools: FRONTEND_TOOL_REGISTRY.getToolSchemas(),
+ tools,
...options,
...completionBody,
},
diff --git a/frontend/src/core/ai/tools/__tests__/registry.test.ts b/frontend/src/core/ai/tools/__tests__/registry.test.ts
index fefbc73d65..5fc3acf514 100644
--- a/frontend/src/core/ai/tools/__tests__/registry.test.ts
+++ b/frontend/src/core/ai/tools/__tests__/registry.test.ts
@@ -63,7 +63,7 @@ describe("FrontendToolRegistry", () => {
it("returns tool schemas with expected shape and memoizes the result", () => {
const registry = new FrontendToolRegistry([new TestFrontendTool()]);
- const schemas1 = registry.getToolSchemas();
+ const schemas1 = registry.getToolSchemas("ask");
expect(Array.isArray(schemas1)).toBe(true);
expect(schemas1.length).toBe(1);
@@ -80,7 +80,11 @@ describe("FrontendToolRegistry", () => {
expect(properties && typeof properties === "object").toBe(true);
expect("name" in (properties ?? {})).toBe(true);
- const schemas2 = registry.getToolSchemas();
+ const schemas2 = registry.getToolSchemas("ask");
expect(schemas2).toBe(schemas1);
+
+ // Should not include tools for other modes
+ const schemas3 = registry.getToolSchemas("agent");
+ expect(schemas3.length).toBe(0);
});
});
diff --git a/frontend/src/core/ai/tools/registry.ts b/frontend/src/core/ai/tools/registry.ts
index 9dcfd981d5..c86e08801f 100644
--- a/frontend/src/core/ai/tools/registry.ts
+++ b/frontend/src/core/ai/tools/registry.ts
@@ -123,8 +123,11 @@ export class FrontendToolRegistry {
}
@Memoize()
- getToolSchemas(): FrontendToolDefinition[] {
- return [...this.tools.values()].map((tool) => ({
+ getToolSchemas(mode: CopilotMode): FrontendToolDefinition[] {
+ const tools = [...this.tools.values()].filter((tool) =>
+ tool.mode.includes(mode),
+ );
+ return tools.map((tool) => ({
name: tool.name,
description: formatToolDescription(tool.description),
parameters: z.toJSONSchema(tool.schema),