From 822a05aee39d9a4f0e11cf290a5a6843be6d6b74 Mon Sep 17 00:00:00 2001 From: Sma1lboy <541898146chen@gmail.com> Date: Thu, 23 Jan 2025 19:26:31 -0600 Subject: [PATCH] refactor(client): remove unused support proxy type and simplify method checks --- clients/tabby-chat-panel/src/index.ts | 13 ---------- .../tabby-threads/source/targets/target.ts | 26 +++---------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/clients/tabby-chat-panel/src/index.ts b/clients/tabby-chat-panel/src/index.ts index 4f372f6161b7..6f46bc9a6523 100644 --- a/clients/tabby-chat-panel/src/index.ts +++ b/clients/tabby-chat-panel/src/index.ts @@ -352,14 +352,6 @@ export interface ClientApiMethods { readFileContent?: (info: FileRange) => Promise } -type ClientApiMethod = keyof ClientApiMethods - -/** - * Provide a convenient way to check if the client supports a specific method. - */ -type SupportProxy = { - [K in ClientApiMethod]: boolean -} export interface ClientApi extends ClientApiMethods { /** * Checks if the client supports this capability. @@ -367,11 +359,6 @@ export interface ClientApi extends ClientApiMethods { * Note: This method should not be used to ensure compatibility across different chat panel SDK versions. */ hasCapability: (method: keyof ClientApiMethods) => Promise - - /** - * The convenient accessor to check if the client supports a specific method from {@link ClientApiMethods}. - */ - supports: SupportProxy } export function createClient(target: HTMLIFrameElement, api: ClientApiMethods): ServerApi { diff --git a/clients/tabby-threads/source/targets/target.ts b/clients/tabby-threads/source/targets/target.ts index 9073bdce9dfb..a3ffbc278afb 100644 --- a/clients/tabby-threads/source/targets/target.ts +++ b/clients/tabby-threads/source/targets/target.ts @@ -240,9 +240,7 @@ export function createThread< args: MessageMap[Type], transferables?: Transferable[] ) { - if (terminated) { - return; - } + if (terminated) return; target.send([type, args], transferables); } @@ -282,7 +280,7 @@ export function createThread< .catch(() => {}); return; } - // FIXME: don't ignore anything, just for testing now + const isThreadMessageData = Array.isArray(rawData) && typeof rawData[0] === "number" && @@ -510,29 +508,13 @@ export function createThread< { get(_target, property) { if (property === "then") { - console.warn("then not found"); + console.log("target then", property); + console.log("_target", _target); return undefined; } if (property === "requestMethods") { return methods?.requestMethods; } - if (property === "supports") { - return new Proxy( - {}, - { - get(_target, method: string) { - if (!state) return false; - const cache = theirMethodsCache; - console.log("cache for supports", cache); - if (cache !== null && !state.isTerminated()) { - return cache.includes(method); - } - return false; - }, - } - ); - } - if ( theirMethodsCache && !theirMethodsCache.includes(String(property))