logancyang_obsidian-copilot/src/tools/toolManager.ts
Zero Liu 500bc347a0
chore(eslint): enable no-unsafe-member-access; fix 124 violations (#2438)
Enables @typescript-eslint/no-unsafe-member-access globally. Tests and 41
heavy source files (>5 violations each) are exempted via per-file overrides
with current violation counts annotated for follow-up PRs. Fixes 124
violations across 51 source files using narrow type assertions, instanceof
Error guards, and proper structural types instead of blanket any casts.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 22:35:38 -07:00

38 lines
1 KiB
TypeScript

import { logWarn } from "@/logger";
export const getToolDescription = (tool: string): string => {
switch (tool) {
case "@vault":
return "Search through your vault for relevant information";
case "@websearch":
return "Search the web for information";
case "@composer":
return "Edit existing notes or create new notes.";
case "@memory":
return "Save information to user memory";
default:
return "";
}
};
export class ToolManager {
/**
* Call a tool with the given arguments.
* Throws on error so caller can handle with proper context (args, tool name).
*/
static async callTool(tool: any, args: any): Promise<any> {
if (!tool) {
throw new Error("Tool is undefined");
}
const typedTool = tool as { call: (args: unknown) => Promise<unknown>; name: string };
const result = await typedTool.call(args);
if (result === undefined || result === null) {
logWarn(`[ToolCall] Tool "${typedTool.name}" returned null/undefined`);
return null;
}
return result;
}
}