@ckeditor/ckeditor5-ai
Version:
AI features for CKEditor 5.
206 lines (205 loc) • 7.81 kB
TypeScript
/**
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/
/**
* @module ai/aicore/model/aiinteraction
* @publicApi
*/
import { type Locale } from '@ckeditor/ckeditor5-utils';
import { type AIConnector } from '../aiconnector.js';
import { AIReply } from './aireply.js';
declare const AIInteraction_base: {
new (): import("@ckeditor/ckeditor5-utils").Emitter;
prototype: import("@ckeditor/ckeditor5-utils").Emitter;
};
/**
* An interaction is a single request to the AI endpoint. It is created when a user message is sent and finishes when the
* all responses are received (interaction is finished) or interaction is stopped (by an error or directly by the user).
*
* An interaction hosts a collection of {@link #replies} and fires various events that may be handled to update the UI accordingly.
*
* @experimental **Experimental:** This is a production-ready API but may change in minor releases
* without the standard deprecation policy. Check the changelog for migration guidance.
*/
export declare abstract class AIInteraction extends /* #__PURE__ */ AIInteraction_base {
/**
* The unique ID of the interaction.
*/
readonly id: string;
/**
* The replies created for this interaction.
*/
replies: Array<AIReply>;
/**
* The current reply being returned by the AI endpoint and handled by `AIInteraction`. This property is set when the interaction
* is started and becomes `undefined` when the interaction is {@link #stop stopped}. It changes as data for new replies are received
* from the AI endpoint.
*/
currentReply?: AIReply;
constructor({ connector, locale }: AIInteractionOptions);
/**
* Stops the interaction. It marks the last reply as done and aborts the current request to the AI endpoint.
*
* @experimental **Experimental:** This is a production-ready API but may change in minor releases
* without the standard deprecation policy. Check the changelog for migration guidance.
*/
stop(): void;
/**
* Gets a reply by its ID.
*
* @experimental **Experimental:** This is a production-ready API but may change in minor releases
* without the standard deprecation policy. Check the changelog for migration guidance.
*/
getReply(id: string): AIReply | undefined;
/**
* Destroys the interaction. It marks the last reply as done and aborts the current request to the AI endpoint.
*
* @experimental **Experimental:** This is a production-ready API but may change in minor releases
* without the standard deprecation policy. Check the changelog for migration guidance.
*/
destroy(): void;
/**
* Creates a reply and adds it to the interaction.
*
* @experimental **Experimental:** This is a production-ready API but may change in minor releases
* without the standard deprecation policy. Check the changelog for migration guidance.
*/
createReply(options: ConstructorParameters<typeof AIReply>[0]): AIReply;
}
export type AIInteractionOptions = {
connector: AIConnector;
/**
* Locale used to translate user-facing strings produced internally by replies (e.g. the placeholder shown in place of
* removed content while change groups are computed).
*/
locale?: Locale;
};
export type AIToolData = {
/**
* Name of the AI tool which returned the data.
*/
toolName: string;
/**
* Data type.
*
* * `'result'` – if the AI tool returned final results of its execution.
* * `'notification'` – if the AI tool returned a notification (e.g., progress update).
*/
type: 'result' | 'notification';
/**
* Data returned by the tool.
*
* Content depends on the AI tool implementation.
*/
data?: Record<string, any>;
/**
* Additional parameters returned by the tool.
*
* Content depends on the AI tool implementation.
*
* Available only if `type` is `'result'`.
*/
attributes?: Record<string, any>;
};
/**
* 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];
};
/**
* An event emitted by an {@link module:ai/aicore/model/aiinteraction~AIInteraction} when
* data from an AI tool is received.
*/
export type AIToolDataReceivedEvent<TInteraction extends AIInteraction = AIInteraction> = {
name: 'toolDataReceived';
args: [
toolData: AIToolData,
interaction: TInteraction
];
};
export {};