jodit-pro
Version:
PRO Version of Jodit Editor
66 lines (65 loc) • 2.49 kB
TypeScript
import type { IDictionary } from "jodit/esm/types/index";
import type { IConversationOptions } from "./conversations";
import type { AIStreamEvent, IAIMessage, IAIResponse } from "./messages";
import type { IToolDefinition } from "./tools";
import type { AIAssistantAPIMode } from "./types";
/**
* Selection context to include in AI request
*/
export interface ISelectionContext {
/** HTML content of the selection */
readonly html: string;
/** Optional block index if selection is within a specific block */
readonly blockIndex?: number;
/** Serialized range information for restoration */
readonly rangeInfo?: {
readonly startContainer: string;
readonly startOffset: number;
readonly endContainer: string;
readonly endOffset: number;
};
}
/**
* Request context sent to AI API
*/
export interface IAIRequestContext {
/** API mode being used */
readonly mode: AIAssistantAPIMode;
/** Conversation identifier */
readonly conversationId: string;
/** Full conversation history (for 'full' mode) or messages since last successful response (for 'incremental' mode) */
readonly messages?: Readonly<IAIMessage[]>;
/** Parent message ID - ID of last successful assistant response (for 'incremental' mode) */
readonly parentMessageId?: string;
/** Available tools the AI can use */
readonly tools: Readonly<IToolDefinition[]>;
/** Current selection contexts */
readonly selectionContexts?: Readonly<ISelectionContext[]>;
/** Conversation-specific settings (model, temperature) */
readonly conversationOptions?: IConversationOptions;
/** Instructions for AI assistant (not saved in conversation) */
readonly instructions?: string;
/** Additional metadata */
readonly metadata?: IDictionary;
}
export type IAIAssistantResult = {
/** Final response from AI API */
readonly mode: 'final';
readonly response: IAIResponse;
} | {
/** Streaming response from AI API */
readonly mode: 'stream';
readonly stream: AsyncGenerator<AIStreamEvent>;
};
/**
* Callback function for AI API integration
*/
export interface IAIAssistantrRequseter {
/**
* Send request to AI API
* @param request - Request context with conversation and tools
* @param signal - AbortSignal for request cancellation
* @returns Promise resolving to AI response
*/
(request: IAIRequestContext, signal: AbortSignal): Promise<IAIAssistantResult>;
}