NEWCKEditor AI on your premises: Hook your LLM and register MCP tools. Webinar coming soon!
Sign up (with export icon)

AIInteraction

Api-class iconclass

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 replies and fires various events that may be handled to update the UI accordingly.

This is an abstract class.

Properties

  • Chevron-right icon

    currentReply : AIReply | undefined

    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 stopped. It changes as data for new replies are received from the AI endpoint.

  • Chevron-right icon

    id : string
    readonly

    The unique ID of the interaction.

  • Chevron-right icon

    replies : Array<AIReply>

    The replies created for this interaction.

Methods

  • Chevron-right icon

    constructor( __namedParameters )

    Parameters

    __namedParameters : AIInteractionOptions
  • Chevron-right icon

    createReply( options = { [options.areActionsDisabled], [options.content], [options.documentContextContent], [options.editor], [options.id], options.interactionId, [options.isDone], options.type } ) → AIReply

    Creates a reply and adds it to the interaction.

    Parameters

    options : object
    Properties
    [ options.areActionsDisabled ] : boolean
    [ options.content ] : string
    [ options.documentContextContent ] : string
    [ options.editor ] : Editor
    [ options.id ] : string
    options.interactionId : string
    [ options.isDone ] : boolean
    options.type : AIReplyType

    Returns

    AIReply
  • Chevron-right icon

    delegate( events ) → EmitterMixinDelegateChain
    inherited

    Delegates selected events to another Emitter. For instance:

    emitterA.delegate( 'eventX' ).to( emitterB );
    emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
    
    Copy code

    then eventX is delegated (fired by) emitterB and emitterC along with data:

    emitterA.fire( 'eventX', data );
    
    Copy code

    and eventY is delegated (fired by) emitterC along with data:

    emitterA.fire( 'eventY', data );
    
    Copy code

    Parameters

    events : Array<string>

    Event names that will be delegated to another emitter.

    Returns

    EmitterMixinDelegateChain
  • Chevron-right icon

    destroy() → void

    Destroys the interaction. It marks the last reply as done and aborts the current request to the AI endpoint.

    Returns

    void
  • Chevron-right icon

    fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]
    inherited

    Fires an event, executing all callbacks registered for it.

    The first parameter passed to callbacks is an EventInfo object, followed by the optional args provided in the fire() method call.

    Type parameters

    TEvent : extends BaseEvent

    The type describing the event. See BaseEvent.

    Parameters

    eventOrInfo : GetNameOrEventInfo<TEvent>

    The name of the event or EventInfo object if event is delegated.

    args : TEvent[ 'args' ]

    Additional arguments to be passed to the callbacks.

    Returns

    GetEventInfo<TEvent>[ 'return' ]

    By default the method returns undefined. However, the return value can be changed by listeners through modification of the evt.return's property (the event info is the first param of every callback).

  • Chevron-right icon

    getReply( id ) → AIReply | undefined

    Gets a reply by its ID.

    Parameters

    id : string

    Returns

    AIReply | undefined
  • Chevron-right icon

    listenTo( emitter, event, callback, [ options ] ) → void
    inherited

    Registers a callback function to be executed when an event is fired in a specific (emitter) object.

    Events can be grouped in namespaces using :. When namespaced event is fired, it additionally fires all callbacks for that namespace.

    // myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
    myEmitter.on( 'myGroup', genericCallback );
    myEmitter.on( 'myGroup:myEvent', specificCallback );
    
    // genericCallback is fired.
    myEmitter.fire( 'myGroup' );
    // both genericCallback and specificCallback are fired.
    myEmitter.fire( 'myGroup:myEvent' );
    // genericCallback is fired even though there are no callbacks for "foo".
    myEmitter.fire( 'myGroup:foo' );
    
    Copy code

    An event callback can stop the event and set the return value of the fire method.

    Type parameters

    TEvent : extends BaseEvent

    The type describing the event. See BaseEvent.

    Parameters

    emitter : Emitter

    The object that fires the event.

    event : TEvent[ 'name' ]

    The name of the event.

    callback : GetCallback<TEvent>

    The function to be called on event.

    [ options ] : GetCallbackOptions<TEvent>

    Additional options.

    Returns

    void
  • Chevron-right icon

    off( event, callback ) → void
    inherited

    Stops executing the callback on the given event. Shorthand for this.stopListening( this, event, callback ).

    Parameters

    event : string

    The name of the event.

    callback : Function

    The function to stop being called.

    Returns

    void
  • Chevron-right icon

    on( event, callback, [ options ] ) → void
    inherited

    Registers a callback function to be executed when an event is fired.

    Shorthand for this.listenTo( this, event, callback, options ) (it makes the emitter listen on itself).

    Type parameters

    TEvent : extends BaseEvent

    The type descibing the event. See BaseEvent.

    Parameters

    event : TEvent[ 'name' ]

    The name of the event.

    callback : GetCallback<TEvent>

    The function to be called on event.

    [ options ] : GetCallbackOptions<TEvent>

    Additional options.

    Returns

    void
  • Chevron-right icon

    once( event, callback, [ options ] ) → void
    inherited

    Registers a callback function to be executed on the next time the event is fired only. This is similar to calling on followed by off in the callback.

    Type parameters

    TEvent : extends BaseEvent

    The type descibing the event. See BaseEvent.

    Parameters

    event : TEvent[ 'name' ]

    The name of the event.

    callback : GetCallback<TEvent>

    The function to be called on event.

    [ options ] : GetCallbackOptions<TEvent>

    Additional options.

    Returns

    void
  • Chevron-right icon

    start() → Promise<void>

    Starts the interaction. It sends the user message to the AI endpoint and starts listening for replies.

    As the data is received from the AI endpoint, AIInteraction handle these data chunks and fires various events. These events can be further handled in order to update the UI accordingly.

    Interaction can be stopped by calling the stop method.

    Returns

    Promise<void>
  • Chevron-right icon

    stop() → void

    Stops the interaction. It marks the last reply as done and aborts the current request to the AI endpoint.

    Returns

    void
  • Chevron-right icon

    stopDelegating( [ event ], [ emitter ] ) → void
    inherited

    Stops delegating events. It can be used at different levels:

    • To stop delegating all events.
    • To stop delegating a specific event to all emitters.
    • To stop delegating a specific event to a specific emitter.

    Parameters

    [ event ] : string

    The name of the event to stop delegating. If omitted, stops it all delegations.

    [ emitter ] : Emitter

    (requires event) The object to stop delegating a particular event to. If omitted, stops delegation of event to all emitters.

    Returns

    void
  • Chevron-right icon

    stopListening( [ emitter ], [ event ], [ callback ] ) → void
    inherited

    Stops listening for events. It can be used at different levels:

    • To stop listening to a specific callback.
    • To stop listening to a specific event.
    • To stop listening to all events fired by a specific object.
    • To stop listening to all events fired by all objects.

    Parameters

    [ emitter ] : Emitter

    The object to stop listening to. If omitted, stops it for all objects.

    [ event ] : string

    (Requires the emitter) The name of the event to stop listening to. If omitted, stops it for all events from emitter.

    [ callback ] : Function

    (Requires the event) The function to be removed from the call list for the given event.

    Returns

    void

Events

  • Chevron-right icon

    interactionDestroyed( eventInfo, interaction )

    An event emitted by AIInteraction when it is destroyed.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    interaction : TInteraction
  • Chevron-right icon

    interactionFinished( eventInfo, interaction )

    An event emitted by AIInteraction when an interaction ran out of content to process or crashed during processing.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    interaction : TInteraction
  • Chevron-right icon

    interactionStarted( eventInfo, interaction )

    An event emitted by AIInteraction when started, which means that the request to the AI endpoint has been sent.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    interaction : TInteraction
  • Chevron-right icon

    interactionStopped( eventInfo, interaction )

    An event emitted by AIInteraction when a user stopped the current interaction.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    interaction : TInteraction
  • Chevron-right icon

    replyCreated( eventInfo, reply )

    An event emitted by an AIInteraction when an AI reply is added to the interaction (usually because received from the AI endpoint).

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    reply : AIReply