UNPKG

@ckeditor/ckeditor5-ai

Version:

AI features for CKEditor 5.

176 lines (175 loc) • 6.87 kB
/** * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options */ import { type AIConnectorRequest, type AIConnector } from '../aiconnector.js'; import { AIReply } from './aireply.js'; import { type Editor } from 'ckeditor5/src/core.js'; import { type AIContextItem } from './aicontext.js'; export declare const AI_MODEL_EVENT_NAMES: readonly ["interactionCreated", "interactionStarted", "interactionStopped", "interactionFinished", "interactionDestroyed", "replyCreated", "replyContentUpdated", "replyChangeGroupStateUpdated", "setConversationTitle", "webSearchStarted", "webSearchFinished", "reasoningStarted", "reasoningFinished", "error"]; declare const AIInteraction_base: { new (): import("ckeditor5/src/utils.js").Emitter; prototype: import("ckeditor5/src/utils.js").Emitter; }; /** * An interaction is a single request to the AI endpoint. It is created when a user message is sent and finishes when the * interaction is stopped. * * An interaction hosts a collection of {@link module:ai/aicore/model/aireply~AIReply replies}. * * There's a {@link module:ai/aicore/model/aiinteraction~AIInteraction#currentReply current reply} in the interaction * that is the reply that is currently being processed by the AI. */ export declare abstract class AIInteraction extends /* #__PURE__ */ AIInteraction_base { /** * The unique ID of the interaction. */ readonly id: string; /** * The AI endpoint replies to the user message. */ replies: Array<AIReply>; /** * Message ID returned by the AI endpoint used for rating requests. */ messageId?: string; /** * Action call ID returned by the AI endpoint used for rating requests. */ actionCallId?: string; constructor({ connector, editor }: AIInteractionOptions); /** * Sends the request to the AI endpoint. */ abstract sendRequest(): Promise<AIConnectorRequest>; /** * Gets the document context for further processing (merging, displaying changes, applying changes, etc.). */ abstract getDocumentContext(): AIContextItem | undefined; /** * Starts the interaction. It sends the user message to the AI endpoint and starts listening for replies. * * * It fires the {@link #userMessage event} with the user message. * * It fires {@link #newReply events} during the interaction as new replies are received from the AI endpoint. * * Interaction can be stopped by calling the {@link #stop} method. */ start(): Promise<void>; /** * Stops the interaction. It marks the last reply as done and aborts the current request to the AI endpoint. */ stop(): void; /** * Gets a reply by its ID. */ getReply(id: string): AIReply | undefined; /** * Destroys the interaction. It marks the last reply as done and aborts the current request to the AI endpoint. */ destroy(): void; /** * Creates a reply and adds it to the interaction. */ createReply(options: ConstructorParameters<typeof AIReply>[0]): AIReply; /** * Fires an event to set the conversation title. * * @param title The new title of the conversation. * @param shouldAnimate Whether the title change should be animated. Defaults to `false`. */ setConversationTitle(title: string, shouldAnimate?: boolean): void; } export type AIInteractionOptions = { connector: AIConnector; editor?: Editor; }; /** * An event emitted by {@link module:ai/aicore/model/aiinteraction~AIInteraction} when started, which means that * the request to the AI endpoint has been sent. * * @eventName ~AIInteraction#interactionStarted */ export type AIInteractionStartedEvent<TInteraction extends AIInteraction = AIInteraction> = { name: 'interactionStarted'; args: [interaction: TInteraction]; }; /** * An event emitted by {@link module:ai/aicore/model/aiinteraction~AIInteraction} when a user stopped * the current interaction. * * @eventName ~AIInteraction#interactionStopped */ export type AIInteractionStoppedEvent<TInteraction extends AIInteraction = AIInteraction> = { name: 'interactionStopped'; args: [interaction: TInteraction]; }; /** * An event emitted by {@link module:ai/aicore/model/aiinteraction~AIInteraction} when an interaction * ran out of content to process or crashed during processing. * * @eventName ~AIInteraction#interactionFinished */ export type AIInteractionFinishedEvent<TInteraction extends AIInteraction = AIInteraction> = { name: 'interactionFinished'; args: [interaction: TInteraction]; }; /** * An event emitted by {@link module:ai/aicore/model/aiinteraction~AIInteraction} when it is destroyed. * * @eventName ~AIInteraction#interactionDestroyed */ export type AIInteractionDestroyedEvent<TInteraction extends AIInteraction = AIInteraction> = { name: 'interactionDestroyed'; args: [interaction: TInteraction]; }; /** * An event emitted by an {@link module:ai/aicore/model/aiinteraction~AIInteraction} when an AI reply is added to the * interaction (usually because received from the AI endpoint). * * @eventName ~AIInteraction#replyCreated */ export type AIInteractionReplyCreatedEvent = { name: 'replyCreated'; args: [reply: AIReply]; }; /** * An event emitted by an {@link module:ai/aicore/model/aiinteraction~AIInteraction} when * the title of the conversation needs to be updated. */ export type AISetConversationTitleEvent = { name: 'setConversationTitle'; args: [title: string, shouldAnimate?: boolean]; }; /** * An event emitted by an {@link module:ai/aicore/model/aiinteraction~AIInteraction} when * the web search was performed. */ export type AIWebSearchStartedEvent<TInteraction extends AIInteraction = AIInteraction> = { name: 'webSearchStarted'; args: [interaction: TInteraction]; }; /** * An event emitted by an {@link module:ai/aicore/model/aiinteraction~AIInteraction} when * the web search was performed. */ export type AIWebSearchFinishedEvent<TInteraction extends AIInteraction = AIInteraction> = { name: 'webSearchFinished'; args: [interaction: TInteraction]; }; /** * An event emitted by an {@link module:ai/aicore/model/aiinteraction~AIInteraction} when * the reasoning was performed. */ export type AIReasoningStartedEvent<TInteraction extends AIInteraction = AIInteraction> = { name: 'reasoningStarted'; args: [interaction: TInteraction]; }; /** * An event emitted by an {@link module:ai/aicore/model/aiinteraction~AIInteraction} when * the reasoning was performed. */ export type AIReasoningFinishedEvent<TInteraction extends AIInteraction = AIInteraction> = { name: 'reasoningFinished'; args: [interaction: TInteraction]; }; export {};