refactor: improve type safety in file service and error handling

- Change listFiles() to synchronous method returning cached IDs
- Add type predicate to ApiError.isApiError() for better type narrowing
- Remove redundant ApiError union type in retry error handling
This commit is contained in:
Andrew Beal 2025-12-19 12:36:28 +00:00
parent 3e013f6c9f
commit e4f56e3877
3 changed files with 4 additions and 4 deletions

View file

@ -35,7 +35,7 @@ export abstract class BaseAIFileService implements IAIFileService {
this.fileIDs = await this.listFilesFromAPI();
}
public async listFiles(): Promise<string[]> {
public listFiles(): string[] {
return [...this.fileIDs];
}
@ -78,7 +78,7 @@ export abstract class BaseAIFileService implements IAIFileService {
// Retries operation on retryable errors (500, 502, 503, 504) with exponential backoff
protected async withRetry<T>(operationName: string, operation: () => Promise<T>): Promise<T> {
let lastError: ApiError | unknown;
let lastError: unknown;
for (let attempt = 1; attempt <= BaseAIFileService.MAX_RETRIES; attempt++) {
try {

View file

@ -2,7 +2,7 @@ import type { Attachment } from "Conversations/Attachment";
export interface IAIFileService {
refreshCache(): Promise<void>;
listFiles(): Promise<string[]>;
listFiles(): string[];
uploadFile(attachment: Attachment): Promise<string>;
deleteFile(attachment: Attachment): Promise<void>;
}

View file

@ -23,7 +23,7 @@ export class ApiError extends Error {
this.name = "ApiError";
}
static isApiError(error: unknown): boolean {
static isApiError(error: unknown): error is ApiError {
return error instanceof ApiError;
}