Files
metona-ollama-desktop/src/main/tool-handlers-shared.ts
T

31 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Tool Handlers Shared - 共享工具函数和类型
*/
import * as path from 'path';
import { mainWindow } from './main.js';
import { getWorkspaceDir } from './workspace.js';
/** 发送日志到渲染进程日志面板 */
export function sendLog(level: 'info' | 'success' | 'warn' | 'error' | 'debug', message: string, detail?: string): void {
mainWindow?.webContents.send('main:log', { level, message, detail });
}
/** 检测字符串是否为 URLhttp:// 或 https:// */
export function isUrl(str: string): boolean {
if (typeof str !== 'string' || str.length < 8) return false;
const lower = str.toLowerCase().trim();
return lower.startsWith('http://') || lower.startsWith('https://');
}
/** 解析路径:相对路径基于工作空间目录 */
export function resolvePath(inputPath: string): string {
if (path.isAbsolute(inputPath)) return path.resolve(inputPath);
return path.resolve(getWorkspaceDir(), inputPath);
}
export interface ToolResult {
success: boolean;
[key: string]: unknown;
}