/*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ import type { IDictionary, IJodit, IViewBased } from "jodit/esm/types/index"; import type { IAIArtifact } from "./artifacts"; import type { IAIAssistantrRequseter } from "./requests"; import type { IAIAssistantStorage } from "./storage"; import type { IToolDefinition, IToolPermission } from "./tools"; import type { AIAssistantAPIMode, AIAssistantDisplayMode, AIAssistantStorageType, AIAssistantTheme, MessageRole, ToolPermissionScope } from "./types"; /** * Configuration for the Jodit AI Adapter provider. * Works with Jodit AI Adapter (https://github.com/jodit/jodit-ai-adapter). * You can deploy it on your own server, or use the managed cloud service at cloud.xdsoft.net. */ export interface IJoditAIAdapterConfig { /** URL of the Jodit AI Adapter instance (e.g., 'https://cloud.xdsoft.net' or your own deployment) */ url: string; /** API key for authentication */ apiKey: string; /** Backend AI provider to use */ provider?: 'openai' | 'deepseek' | string; /** Enable SSE streaming (default: true) */ stream?: boolean; } /** * Provider configuration map for type-safe provider options */ export interface IAIProviderConfigMap { 'jodit-ai-adapter': IJoditAIAdapterConfig; [name: string]: Record; } /** * Factory function that creates partial AI Assistant options from provider config */ export interface IAIProviderFactory = Record> { (config: C): Partial; } /** * Dialog settings configuration */ export interface IDialogSettingsConfig { /** * Available AI models * Can be array of {title, value} objects or array of strings */ models?: Array<{ title: string; value: string; }> | string[]; /** * Temperature range configuration */ temperature?: { /** Minimum temperature value */ min: number; /** Maximum temperature value */ max: number; /** Step for range input */ step?: number; }; } /** * Configuration options for AI Assistant Pro plugin */ export interface IAIAssistantProOptions { /** * Display mode for the AI Assistant interface * @default 'right' */ displayMode: AIAssistantDisplayMode; /** * Width of panel in pixels (for left/right modes) * @default 400 */ panelWidth: number; /** * Height of panel in pixels (for left/right modes) * @default 600 */ panelHeight: number; /** * Height of flight panel in pixels (for flight mode) * @default 250 */ flightPanelHeight: number; /** * Whether dialog should be full-size (for dialog mode) * @default false */ dialogFullSize: boolean; /** * Whether panel/dialog is resizable * @default true */ resizable: boolean; /** * API communication mode * - 'full': Send entire conversation with each request * - 'incremental': Send only new message with parent ID * @default 'incremental' */ apiMode: AIAssistantAPIMode; /** * Callback function to handle AI API requests * Must be provided by the user */ apiRequest: IAIAssistantrRequseter | null; /** * Maximum number of retry attempts for failed requests * @default 3 */ maxRetries: number; /** * Request timeout in milliseconds * @default 300_000 - 5 minutes */ requestTimeout: number; /** * Base delay for exponential backoff in milliseconds * @default 1000 */ retryDelay: number; /** * Maximum recursion depth for tool call follow-up requests * Prevents infinite loops when tools trigger follow-up requests * @default 1000 */ maxRecursionToolCallDepth: number; /** * Array of enabled built-in tool names * Empty array disables all built-in tools * @default ['insertHTML', 'readDocument', 'readBlock', 'replaceInDocument', 'replaceInBlock', 'getSelection'] */ enabledTools: string[]; /** * Custom tool definitions to add * @default [] */ customTools: IToolDefinition[]; /** * Pre-configured tool permissions * @default {} */ toolPermissions: IDictionary; /** * Tool names that don't require user confirmation * @default ['readDocument', 'readBlock', 'getSelection', 'insertHTML'] */ autoApproveTools: string[]; /** * Tool names that are always denied * @default [] */ alwaysDenyTools: string[]; /** * Default permission scope when user approves * @default 'conversation' */ defaultPermissionScope: ToolPermissionScope; /** * Storage type or custom implementation * @default 'indexedDB' */ storage: AIAssistantStorageType | IAIAssistantStorage; /** * Maximum number of conversations to keep * Oldest will be removed when exceeded * @default 50 */ maxConversations: number; /** * Storage key prefix for localStorage * @default 'jodit-ai-assistant-pro' */ storageKey: string; /** * Show conversation list sidebar * @default true */ showConversationList: boolean; /** * Enable markdown rendering in messages * @default true */ enableMarkdown: boolean; /** * Enable code syntax highlighting * @default true */ enableCodeHighlight: boolean; /** * Maximum height for a single message in pixels * @default 400 */ maxMessageHeight: number; /** * Placeholder text for input field * @default 'Ask AI assistant...' */ placeholderText: string; /** * Keyboard shortcut to send message * @default 'Ctrl+Enter' */ sendShortcut: string; /** * Show timestamps on messages * @default true */ showTimestamps: boolean; /** * Custom formatter for message timestamps * @param timestamp - Unix timestamp in milliseconds * @returns Formatted timestamp string * @default Uses locale time string */ formatTimestamp: (timestamp: number, i18n: IViewBased['i18n']) => string; /** * Custom formatter for message content * @param content - Raw message content * @param role - Message role (user, assistant, etc) * @returns Formatted HTML string * @default Uses marked library for markdown rendering */ formatMessageContent: (content: string, role: MessageRole, i18n: IViewBased['i18n']) => string; /** * Show avatar icons for user/AI * @default true */ showAvatars: boolean; /** * Show typing indicator when AI is responding * @default true */ showTypingIndicator: boolean; /** * Include current selection as context by default when opening * @default true */ includeSelectionByDefault: boolean; /** * Maximum number of context ranges to keep * @default 5 */ maxContextRanges: number; /** * Show context preview chips * @default true */ showContextPreview: boolean; /** * Send message on Enter key * If true: Enter sends, Shift+Enter adds new line * If false: Shift+Enter sends, Enter adds new line * @default true */ sendOnEnter: boolean; /** * Instructions for AI assistant (not saved in conversation, sent with every request) * @default undefined */ instructions?: string; /** * Include editor metadata in system prompt * (language, plugins, etc.) * @default false */ includeEditorMetadata: boolean; /** * Automatically open assistant when hotkey is pressed * @default true */ autoOpen: boolean; /** * Remember last conversation on page reload * @default true */ rememberLastConversation: boolean; /** * Auto-focus input when panel opens * @default true */ autoFocusInput: boolean; /** * Close panel after inserting generated content * @default false */ closeAfterInsert: boolean; /** * Enable sound notifications * @default false */ enableSoundNotifications: boolean; /** * Log debug information to console * @default false */ debug: boolean; /** * Execute quick commands in silent mode (without opening AI panel) * When true, command executes silently and replaces selection * When false, opens AI panel with the command prompt * @default false */ quickCommandsSilentMode: boolean; /** * Display mode to use when opening AI panel for quick commands * (only used when quickCommandsSilentMode is false) * @default 'bottom' */ quickCommandsDisplayMode: AIAssistantDisplayMode; /** * Show "Copy message" button in message actions menu * @default true */ showCopyMessageAction: boolean; /** * Show "Restart from here" button in message actions menu (user messages only) * Removes all messages after this one and resends the message * @default true */ showRestartMessageAction: boolean; /** * Show "Edit message" button in message actions menu (user messages only) * Opens the message in input field for editing and resubmission * @default true */ showEditMessageAction: boolean; /** * Show "Delete message" button in message actions menu * Deletes only this message from conversation * @default true */ showDeleteMessageAction: boolean; /** * Dialog-specific settings configuration (model, temperature) * @default {} */ dialogSettings: IDialogSettingsConfig; /** * Default model for new conversations * @default undefined */ defaultModel?: string; /** * Default temperature for new conversations * @default undefined */ defaultTemperature?: number; /** * Allow users to edit dialog-specific settings (model, temperature) * @default false */ allowEditDialogSettings: boolean; /** * Allow users to change display mode via settings * @default true */ allowEditDisplayMode: boolean; /** * Allow users to change panel width via settings * @default true */ allowEditPanelWidth: boolean; /** * Whether assistant should be opened on initialization * @default false */ initiallyOpened: boolean; /** * Allow closing the assistant (only for non-dialog modes) * If false, close button will be hidden * @default true */ allowClose: boolean; /** * Persist open state in localStorage * When true, remembers if user opened/closed assistant * Overrides initiallyOpened if state exists * @default true */ persistOpenState: boolean; /** * Theme mode for the assistant * - 'dark': Force dark theme * - 'light': Force light theme * - 'parent': Inherit from parent Jodit editor theme * @default 'parent' */ theme: AIAssistantTheme; /** * Allow users to change theme via settings UI * @default true */ allowEditTheme: boolean; /** * Enable AI text autocomplete. * Requires `textAutocompleteApiRequest` to be set. * @default false */ textAutocompleteEnabled: boolean; /** * Callback for AI autocomplete API requests. * If not set, text autocomplete is disabled regardless of `textAutocompleteEnabled`. * @default null */ textAutocompleteApiRequest: ((query: string, maxSuggestions: number, signal: AbortSignal) => Promise) | null; /** * Minimum number of characters before triggering AI autocomplete * @default 3 */ textAutocompleteMinQueryLength: number; /** * Maximum number of suggestions to show * @default 3 */ textAutocompleteMaxSuggestions: number; /** * Debounce delay in milliseconds for AI requests * @default 500 */ textAutocompleteDebounceMs: number; /** * TTL for autocomplete cache entries in milliseconds. * Repeated identical queries within this window return cached results. * Set to 0 to disable caching. * @default 30000 */ textAutocompleteCacheTTL: number; /** * Maximum number of entries in the autocomplete cache. * When exceeded, the oldest entry is evicted. * @default 50 */ textAutocompleteCacheMaxSize: number; /** * Allow uploading base64 artifact (images, audio) to server */ uploadBase64Artifact: ((artifact: T, jodit: IJodit) => Promise>) | null; /** * Get pre-configured AI Assistant options for a registered provider * * @param name - Provider name (e.g., 'jodit-ai-adapter') * @param config - Provider-specific configuration * @returns Partial options to spread into aiAssistantPro config * * @example * ```typescript * const providerOptions = Jodit.defaultOptions.aiAssistantPro * .getAIProviderOptions('jodit-ai-adapter', { * url: 'https://cloud.xdsoft.net', * apiKey: 'your-api-key', * }); * * Jodit.make('#editor', { * aiAssistantPro: { * ...providerOptions, * } * }); * ``` */ getAIProviderOptions(name: K, config: IAIProviderConfigMap[K]): Partial; /** * Register a custom AI provider factory * * @param name - Unique provider name * @param factory - Factory function that creates partial options from config */ registerAIProvider(name: K, factory: IAIProviderFactory): void; }