AIInteraction
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
currentReply : AIReply | undefinedmodule:ai/aicore/model/aiinteraction~AIInteraction#currentReplyThe current reply being returned by the AI endpoint and handled by
AIInteraction. This property is set when the interaction is started and becomesundefinedwhen the interaction is stopped. It changes as data for new replies are received from the AI endpoint.id : stringreadonlymodule:ai/aicore/model/aiinteraction~AIInteraction#idThe unique ID of the interaction.
replies : Array<AIReply>module:ai/aicore/model/aiinteraction~AIInteraction#repliesThe replies created for this interaction.
Methods
constructor( __namedParameters )module:ai/aicore/model/aiinteraction~AIInteraction#constructorParameters
__namedParameters : AIInteractionOptions
createReply( options = { [options.areActionsDisabled], [options.content], [options.documentContextContent], [options.editor], [options.id], options.interactionId, [options.isDone], options.type } ) → AIReplymodule:ai/aicore/model/aiinteraction~AIInteraction#createReplyCreates 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 ] : stringoptions.interactionId : string[ options.isDone ] : booleanoptions.type : AIReplyType
Returns
AIReply
delegate( events ) → EmitterMixinDelegateChaininheritedmodule:ai/aicore/model/aiinteraction~AIInteraction#delegateDelegates selected events to another
Emitter. For instance:emitterA.delegate( 'eventX' ).to( emitterB ); emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );Copy codethen
eventXis delegated (fired by)emitterBandemitterCalong withdata:emitterA.fire( 'eventX', data );Copy codeand
eventYis delegated (fired by)emitterCalong withdata:emitterA.fire( 'eventY', data );Copy codeParameters
events : Array<string>Event names that will be delegated to another emitter.
Returns
destroy() → voidmodule:ai/aicore/model/aiinteraction~AIInteraction#destroyDestroys the interaction. It marks the last reply as done and aborts the current request to the AI endpoint.
Returns
void
fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]inheritedmodule:ai/aicore/model/aiinteraction~AIInteraction#fireFires an event, executing all callbacks registered for it.
The first parameter passed to callbacks is an
EventInfoobject, followed by the optionalargsprovided in thefire()method call.Type parameters
Parameters
eventOrInfo : GetNameOrEventInfo<TEvent>The name of the event or
EventInfoobject 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 theevt.return's property (the event info is the first param of every callback).
getReply( id ) → AIReply | undefinedmodule:ai/aicore/model/aiinteraction~AIInteraction#getReplyGets a reply by its ID.
Parameters
id : string
Returns
AIReply | undefined
listenTo( emitter, event, callback, [ options ] ) → voidinheritedmodule:ai/aicore/model/aiinteraction~AIInteraction#listenTo:BASE_EMITTERRegisters 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 codeAn event callback can stop the event and set the return value of the
firemethod.Type parameters
Parameters
emitter : EmitterThe 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
off( event, callback ) → voidinheritedmodule:ai/aicore/model/aiinteraction~AIInteraction#offStops executing the callback on the given event. Shorthand for
this.stopListening( this, event, callback ).Parameters
event : stringThe name of the event.
callback : FunctionThe function to stop being called.
Returns
void
on( event, callback, [ options ] ) → voidinheritedmodule:ai/aicore/model/aiinteraction~AIInteraction#onRegisters 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
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
once( event, callback, [ options ] ) → voidinheritedmodule:ai/aicore/model/aiinteraction~AIInteraction#onceRegisters a callback function to be executed on the next time the event is fired only. This is similar to calling
onfollowed byoffin the callback.Type parameters
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
start() → Promise<void>module:ai/aicore/model/aiinteraction~AIInteraction#startStarts 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,
AIInteractionhandle 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
stopmethod.Returns
Promise<void>
stop() → voidmodule:ai/aicore/model/aiinteraction~AIInteraction#stopStops the interaction. It marks the last reply as done and aborts the current request to the AI endpoint.
Returns
void
stopDelegating( [ event ], [ emitter ] ) → voidinheritedmodule:ai/aicore/model/aiinteraction~AIInteraction#stopDelegatingStops 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 ] : stringThe 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 ofeventto all emitters.
Returns
void
stopListening( [ emitter ], [ event ], [ callback ] ) → voidinheritedmodule:ai/aicore/model/aiinteraction~AIInteraction#stopListening:BASE_STOPStops 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 ] : EmitterThe 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 fromemitter.[ callback ] : Function(Requires the
event) The function to be removed from the call list for the givenevent.
Returns
void
Events
interactionDestroyed( eventInfo, interaction )module:ai/aicore/model/aiinteraction~AIInteraction#event:interactionDestroyedAn event emitted by
AIInteractionwhen it is destroyed.Parameters
eventInfo : EventInfoAn object containing information about the fired event.
interaction : TInteraction
interactionFinished( eventInfo, interaction )module:ai/aicore/model/aiinteraction~AIInteraction#event:interactionFinishedAn event emitted by
AIInteractionwhen an interaction ran out of content to process or crashed during processing.Parameters
eventInfo : EventInfoAn object containing information about the fired event.
interaction : TInteraction
interactionStarted( eventInfo, interaction )module:ai/aicore/model/aiinteraction~AIInteraction#event:interactionStartedAn event emitted by
AIInteractionwhen started, which means that the request to the AI endpoint has been sent.Parameters
eventInfo : EventInfoAn object containing information about the fired event.
interaction : TInteraction
interactionStopped( eventInfo, interaction )module:ai/aicore/model/aiinteraction~AIInteraction#event:interactionStoppedAn event emitted by
AIInteractionwhen a user stopped the current interaction.Parameters
eventInfo : EventInfoAn object containing information about the fired event.
interaction : TInteraction
replyCreated( eventInfo, reply )module:ai/aicore/model/aiinteraction~AIInteraction#event:replyCreatedAn event emitted by an
AIInteractionwhen an AI reply is added to the interaction (usually because received from the AI endpoint).Parameters
eventInfo : EventInfoAn object containing information about the fired event.
reply : AIReply