/** * @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/toolkit/proposedchange * @publicApi */ import { type ModelRange } from "@ckeditor/ckeditor5-engine"; import { type AIOperationSource } from "../aicore/utils/markoperationsasai.js"; /** * Represents a single change document change. */ export interface DocumentChange { /** * The name of the editor root the change applies to. */ rootName: string; /** * What the change covers, represented as a range inside the captured snapshot. The range covers the existing elements which were * either removed or modified. * * Note, that the range is placed inside the snapshot represented as a model document fragment, not in the actual model document. One * snapshot model fragment is shared between all document changes in a given set. * * Collapsed for a change that only adds content. */ beforeRange: ModelRange; /** * What the covered content becomes, represented as a range inside the processed data. The range covers existing elements which were * modified or new elements. * * In other words, the document change says that `beforeRange` content becomes `afterRange` content. * * Note, that the range is placed inside the processed data represented as a model document fragment, not in the actual model document. * One processed data model fragment is shared between all document changes in a given set. * * Collapsed for a change that only removes content. */ afterRange: ModelRange; /** * The document {@link module:engine/model/document~ModelDocument#version version} for which the change is proposed. */ version: number; /** * The editing session ID during which the change was captured. */ sessionId: string; /** * The ID of the document the change was captured from. */ channelId: string; /** * Which AI feature produced the change or not set if the change did not come from AI. * * See {@link module:ai/toolkit/documentcompare~DocumentCompareComputeChangesOptions#aiSource}. */ aiSource?: AIOperationSource; } /** * Holds information whether the user has interacted with the proposed document change: * * * `'pending'` - waiting for the user's decision. * * `'accepted'` - applied to the document (directly or as a tracked suggestion). * * `'rejected'` - dismissed by the user. * * Whether the document can still have the change applied is a separate question, see {@link ~ProposedChange#outdatedState}. */ export type ProposedChangeState = "pending" | "accepted" | "rejected"; /** * Holds a reason why the proposed change cannot be applied to the current state of the document. * * * `'content-removed'` - the related content or parent root were removed from the document. * * `'editor-removed'` - the target editor (identified through `channelId`) is not available. * * `'session-changed'` - the change was captured for document during a previous editing session. */ export type ProposedChangeOutdatedState = "content-removed" | "editor-removed" | "session-changed"; /** * Holds a reason why the proposed change yields nothing (no preview to show, and nothing an apply would do): * * * `'diff-empty'` - the change's two sides were compared, and nothing differs. * * `'diff-failed'` - comparing the two sides threw, the proposed change cannot be further handled. */ export type ProposedChangeEmptyReason = "diff-empty" | "diff-failed"; /** * Represents a single, reviewable proposed document change. Holds both the information about the change and its current status. */ export interface ProposedChange extends DocumentChange { /** * The change's position in the {@link module:ai/toolkit/proposedchangescollection~ProposedChangesCollection set}. * * Assigned when the set of changes is built, does not change later on. */ index: number; /** * Holds information whether the user has interacted with the proposed document change. */ state: ProposedChangeState; /** * If set, holds a reason why the proposed change cannot be applied to the current state of the document. * * If not set, the change is not outdated and can be applied to the document. */ outdatedState?: ProposedChangeOutdatedState; /** * If set, holds a reason why the proposed change yields nothing (no preview to show, and nothing an apply would do). */ emptyReason?: ProposedChangeEmptyReason; /** * If `true`, the change relates to content that is current in read-only mode and thus the change cannot be applied. */ isReadOnly?: boolean; }