Skip to content

Commit

Permalink
refactor(client): remove unused support proxy type and simplify metho…
Browse files Browse the repository at this point in the history
…d checks
  • Loading branch information
Sma1lboy committed Jan 24, 2025
1 parent 8575d95 commit 822a05a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 35 deletions.
13 changes: 0 additions & 13 deletions clients/tabby-chat-panel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,26 +352,13 @@ export interface ClientApiMethods {
readFileContent?: (info: FileRange) => Promise<string | null>
}

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.
* This method is designed to check capability across different clients (IDEs).
* Note: This method should not be used to ensure compatibility across different chat panel SDK versions.
*/
hasCapability: (method: keyof ClientApiMethods) => Promise<boolean>

/**
* 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 {
Expand Down
26 changes: 4 additions & 22 deletions clients/tabby-threads/source/targets/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ export function createThread<
args: MessageMap[Type],
transferables?: Transferable[]
) {
if (terminated) {
return;
}
if (terminated) return;
target.send([type, args], transferables);
}

Expand Down Expand Up @@ -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" &&
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 822a05a

Please sign in to comment.