refactor: use typed window.metonaDesktop instead of (window as any)
Replaced all '(window as any).metonaDesktop' with the properly typed 'window.metonaDesktop' across mcp-client.ts, skill-manager.ts, agent-engine.ts, and log-service.ts. The MetonaDesktopAPI type is already declared in types.d.ts, so the 'as any' cast was unnecessary and bypassed type checking.
This commit is contained in:
@@ -170,7 +170,7 @@ function parseToolCallsFromText(content: string): ToolCall[] {
|
||||
|
||||
/** v4.2: 从对话中自动推断用户画像 */
|
||||
async function inferUserProfile(userMsg: string, assistantMsg: string): Promise<void> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.db?.getSetting) return;
|
||||
|
||||
const profile: Record<string, unknown> = await bridge.db.getSetting('user_profile', {}) || {};
|
||||
@@ -365,7 +365,7 @@ export interface AgentCallbacks {
|
||||
/** 保存执行轨迹到 SQLite */
|
||||
async function saveTrace(trace: Omit<TraceEntry, 'id' | 'createdAt'>): Promise<void> {
|
||||
try {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.db) return;
|
||||
const entry = {
|
||||
id: `trace_${generateId()}`,
|
||||
|
||||
@@ -212,7 +212,7 @@ async function exportLog(): Promise<void> {
|
||||
const content = header + lines.join('\n');
|
||||
|
||||
try {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (bridge) {
|
||||
const ts = new Date().toISOString().slice(0, 19).replace(/[T:]/g, '-');
|
||||
const filePath = await bridge.dialog.saveFile({
|
||||
|
||||
@@ -45,7 +45,7 @@ export async function addMCPServer(config: MCPServerConfig): Promise<void> {
|
||||
}
|
||||
|
||||
export async function removeMCPServer(name: string): Promise<void> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (bridge?.mcp) await bridge.mcp.stopServer(name);
|
||||
const servers = await getMCPServers();
|
||||
await saveMCPServers(servers.filter(s => s.name !== name));
|
||||
@@ -71,7 +71,7 @@ export async function getEnabledMCPServers(): Promise<MCPServerConfig[]> {
|
||||
|
||||
/** 启动所有已启用的 MCP 服务器 */
|
||||
export async function startAllMCPServers(): Promise<void> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.mcp) return;
|
||||
|
||||
const configs = await getEnabledMCPServers();
|
||||
@@ -91,13 +91,13 @@ export async function startAllMCPServers(): Promise<void> {
|
||||
|
||||
/** 停止所有 MCP 服务器 */
|
||||
export async function stopAllMCPServers(): Promise<void> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (bridge?.mcp) await bridge.mcp.stopAll();
|
||||
}
|
||||
|
||||
/** 获取 MCP 服务器状态 */
|
||||
export async function getMCPServerStatuses(): Promise<Array<{ name: string; running: boolean; toolCount: number }>> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.mcp) return [];
|
||||
try {
|
||||
return await bridge.mcp.getStatuses();
|
||||
@@ -110,7 +110,7 @@ export async function getMCPServerStatuses(): Promise<Array<{ name: string; runn
|
||||
|
||||
/** 从主进程获取所有 MCP 工具并转换为 ToolDefinition 格式 */
|
||||
export async function getMCPToolDefinitions(): Promise<ToolDefinition[]> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.mcp) return [];
|
||||
|
||||
try {
|
||||
@@ -146,7 +146,7 @@ export async function getMCPToolDefinitions(): Promise<ToolDefinition[]> {
|
||||
|
||||
/** 执行 MCP 工具调用 */
|
||||
export async function executeMCPTool(toolName: string, args: Record<string, unknown>): Promise<ToolResult> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.mcp) {
|
||||
return { success: false, error: 'MCP API 不可用' };
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export async function extractSkillsFromToolRecords(
|
||||
userMessage: string,
|
||||
sessionTitle: string
|
||||
): Promise<number> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.db?.saveSkill) return 0;
|
||||
|
||||
// 只看成功的工具调用
|
||||
@@ -117,7 +117,7 @@ export async function extractSkillsFromToolRecords(
|
||||
* 返回匹配度最高的技能列表
|
||||
*/
|
||||
export async function matchSkills(userMessage: string, limit = 3): Promise<Skill[]> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.db?.getAllSkills) return [];
|
||||
|
||||
try {
|
||||
@@ -284,7 +284,7 @@ export async function listSkills(): Promise<Array<{
|
||||
success_rate: string;
|
||||
chain_preview: string;
|
||||
}>> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.db?.getAllSkills) return [];
|
||||
const allSkills: Skill[] = await bridge.db.getAllSkills();
|
||||
return allSkills.map(skill => {
|
||||
@@ -311,7 +311,7 @@ export async function viewSkill(skillName: string): Promise<{
|
||||
skill?: Skill & { chain: ToolChainStep[]; success_rate: string };
|
||||
error?: string;
|
||||
}> {
|
||||
const bridge = (window as any).metonaDesktop;
|
||||
const bridge = window.metonaDesktop;
|
||||
if (!bridge?.db?.getAllSkills) return { success: false, error: '数据库不可用' };
|
||||
const allSkills: Skill[] = await bridge.db.getAllSkills();
|
||||
const skill = allSkills.find(s =>
|
||||
|
||||
Reference in New Issue
Block a user