jodit-pro
Version:
PRO Version of Jodit Editor
373 lines (372 loc) • 10.5 kB
TypeScript
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";
/**
* 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<IToolPermission>;
/**
* 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;
/**
* Allow uploading base64 artifact (images, audio) to server
*/
uploadBase64Artifact: (<T extends IAIArtifact>(artifact: T, jodit: IJodit) => Promise<T | IAIArtifact<{
kind: 'url';
url: string;
}>>) | null;
}