All files / bridge chatMode.ts

100% Statements 38/38
100% Branches 14/14
100% Functions 3/3
100% Lines 38/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x         1x 7x 3x 3x 4x 4x         1x 5x 1x 1x 5x 1x 1x 3x 3x         1x 5x 1x 1x 4x 4x  
import type { McpTool } from "../mcp/client";
import type { AgentTool } from "../agent/types";
 
/**
 * UI chat mode from the webview (Plain = só texto, Agent = tools completos, Ask = só leitura/pesquisa).
 */
export type ChatUiMode = "plain" | "agent" | "ask";
 
const ASK_ALLOWED_TOOL_NAMES = new Set<string>([
  "ExploreAgent",
  "Read",
  "readFile",
  "Grep",
  "Glob",
  "globFiles",
  "listDir",
  "searchCode",
  "webFetch",
  "WebSearch",
  "TodoWrite",
  "ListSkills",
  "ReadSkill",
  "EnterPlanMode",
  "ExitPlanMode",
]);
 
/**
 * Narrows unknown bridge payloads to ChatUiMode; default agent.
 */
export function parseChatUiMode(value: unknown): ChatUiMode {
  if (value === "plain" || value === "agent" || value === "ask") {
    return value;
  }
  return "agent";
}
 
/**
 * Native tools exposed to the model for the selected UI mode.
 */
export function selectToolsForChatMode(mode: ChatUiMode, allTools: AgentTool[]): AgentTool[] {
  if (mode === "plain") {
    return [];
  }
  if (mode === "agent") {
    return allTools;
  }
  return allTools.filter((tool) => ASK_ALLOWED_TOOL_NAMES.has(tool.name));
}
 
/**
 * MCP tools: only full agent mode loads MCP (Ask/Plain avoid side effects e custo).
 */
export function mcpToolsForChatMode(mode: ChatUiMode, list: McpTool[]): McpTool[] {
  if (mode === "agent") {
    return list;
  }
  return [];
}