From 7574d049ffb7792b005b5e73b1b8b5fcad952dfe Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Mon, 24 Nov 2025 22:40:47 +0800 Subject: [PATCH] feat(frontend): extend deeplink API for multi-resource support Update the frontend deeplink API to support importing multiple resource types with proper TypeScript typing. Changes: - Add ResourceType union type: "provider" | "prompt" | "mcp" | "skill" - Convert DeepLinkImportRequest fields to optional (matching backend) - Add resource-specific field types (prompt, mcp, skill) - Add ImportResult discriminated union for type-safe results - Add McpImportResult interface for batch import results - Update importFromDeeplink to use unified command Type safety improvements: - ImportResult discriminated union ensures proper type narrowing - Each result type has its own specific return data structure - Frontend can pattern match on result.type for correct handling Breaking change: - importFromDeeplink now returns ImportResult instead of string - Callers must handle all resource types appropriately --- src/lib/api/deeplink.ts | 71 ++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/src/lib/api/deeplink.ts b/src/lib/api/deeplink.ts index c85341ccb..e13f8cf4c 100644 --- a/src/lib/api/deeplink.ts +++ b/src/lib/api/deeplink.ts @@ -1,25 +1,66 @@ import { invoke } from "@tauri-apps/api/core"; +export type ResourceType = "provider" | "prompt" | "mcp" | "skill"; + export interface DeepLinkImportRequest { version: string; - resource: string; - app: "claude" | "codex" | "gemini"; - name: string; - homepage: string; - endpoint: string; - apiKey: string; + resource: ResourceType; + + // Common fields + app?: "claude" | "codex" | "gemini"; + name?: string; + enabled?: boolean; + + // Provider fields + homepage?: string; + endpoint?: string; + apiKey?: string; + icon?: string; model?: string; notes?: string; - // Claude 专用模型字段 (v3.7.1+) haikuModel?: string; sonnetModel?: string; opusModel?: string; - // 配置文件导入字段 (v3.8+) - config?: string; // Base64 编码的配置内容 - configFormat?: string; // json/toml - configUrl?: string; // 远程配置 URL + + // Prompt fields + content?: string; + description?: string; + + // MCP fields + apps?: string; // "claude,codex,gemini" + + // Skill fields + repo?: string; + directory?: string; + branch?: string; + skillsPath?: string; + + // Config file fields + config?: string; + configFormat?: string; + configUrl?: string; } +export interface McpImportResult { + importedCount: number; + importedIds: string[]; + failed: Array<{ + id: string; + error: string; + }>; +} + +export type ImportResult = + | { type: "provider"; id: string } + | { type: "prompt"; id: string } + | { + type: "mcp"; + importedCount: number; + importedIds: string[]; + failed: Array<{ id: string; error: string }>; + } + | { type: "skill"; key: string }; + export const deeplinkApi = { /** * Parse a deep link URL @@ -43,13 +84,13 @@ export const deeplinkApi = { }, /** - * Import a provider from a deep link request + * Import a resource from a deep link request (unified handler) * @param request The deep link import request - * @returns The ID of the imported provider + * @returns Import result based on resource type */ importFromDeeplink: async ( request: DeepLinkImportRequest, - ): Promise => { - return invoke("import_from_deeplink", { request }); + ): Promise => { + return invoke("import_from_deeplink_unified", { request }); }, };