mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 16:30:27 +00:00
Introduce a new AbortService to centralize cancellation logic across all async operations, replacing scattered AbortSignal parameters with a unified singleton service. This improves maintainability and provides consistent cancellation behavior throughout the application. Key changes: - Add AbortService for centralized abort signal management with automatic cleanup - Refactor all AI providers (Claude, Gemini, OpenAI) to use AbortService instead of passing AbortSignal parameters - Update streaming operations to use centralized abort handling - Add CancellationIndicator component to show visual feedback during operation cancellation - Rename ChatAreaThought to ThoughtIndicator for better semantic clarity - Add Environment enum for consistent environment detection - Enhance ChatService lifecycle with proper cancellation state management - Remove scattered abort-related UI selectors and error messages in favor of dedicated indicator - Add safeContinue() factory method to ConversationContent for internal continuations - Update all tests to reflect new abort handling architecture This change simplifies the API surface by removing AbortSignal parameters from method signatures while improving the user experience with clearer cancellation feedback.
65 lines
No EOL
2.4 KiB
TypeScript
65 lines
No EOL
2.4 KiB
TypeScript
import { Role } from "Enums/Role";
|
|
import { ApiErrorType } from "Types/ApiError";
|
|
|
|
export class ConversationContent {
|
|
role: Role;
|
|
content: string;
|
|
promptContent: string;
|
|
functionCall: string;
|
|
timestamp: Date;
|
|
isFunctionCall: boolean;
|
|
isFunctionCallResponse: boolean;
|
|
toolId?: string;
|
|
errorType?: ApiErrorType;
|
|
|
|
constructor(role: Role, content: string = "", promptContent: string = "", functionCall: string = "", timestamp: Date = new Date(), isFunctionCall = false, isFunctionCallResponse = false, toolId?: string, errorType?: ApiErrorType) {
|
|
this.role = role;
|
|
this.content = content;
|
|
this.promptContent = promptContent;
|
|
this.functionCall = functionCall;
|
|
this.timestamp = timestamp;
|
|
this.isFunctionCall = isFunctionCall;
|
|
this.isFunctionCallResponse = isFunctionCallResponse;
|
|
this.toolId = toolId;
|
|
this.errorType = errorType;
|
|
}
|
|
|
|
public static isConversationContentData(this: void, data: unknown): data is {
|
|
role: string; content: string; promptContent: string; functionCall: string; timestamp: string, isFunctionCall: boolean, isFunctionCallResponse: boolean, toolId?: string, errorType?: string
|
|
} {
|
|
return (
|
|
data !== null &&
|
|
typeof data === "object" &&
|
|
"role" in data &&
|
|
"content" in data &&
|
|
"promptContent" in data &&
|
|
"functionCall" in data &&
|
|
"timestamp" in data &&
|
|
"isFunctionCall" in data &&
|
|
"isFunctionCallResponse" in data &&
|
|
typeof data.role === "string" &&
|
|
typeof data.content === "string" &&
|
|
typeof data.promptContent === "string" &&
|
|
typeof data.functionCall === "string" &&
|
|
typeof data.timestamp === "string" &&
|
|
typeof data.isFunctionCall === "boolean" &&
|
|
typeof data.isFunctionCallResponse === "boolean" &&
|
|
|
|
// optional conversation data fields
|
|
(!("toolId" in data) || typeof data.toolId === "string") &&
|
|
(!("errorType" in data) || typeof data.errorType === "string")
|
|
);
|
|
}
|
|
|
|
public static safeContinue() {
|
|
return new ConversationContent(
|
|
Role.User,
|
|
"Continue",
|
|
"Continue",
|
|
"",
|
|
new Date(),
|
|
false,
|
|
true // isFunctionCallResponse = true (hides from UI)
|
|
);
|
|
}
|
|
} |