Skip to content

oracular / episodeClosed

Function: episodeClosed() ​

ts
function episodeClosed(prev, next): boolean;

Defined in: observe.ts:156

Whether an episode closed between two states: prev had an open episode and next either has none or has a different one. Useful after observe or endEpisode to react to a session ending, for example to persist, or to read the misses it produced as next.intents[x].episodes.misses - prev.intents[x].episodes.misses (0 for an intent with attribution set, whose verdict waits).

Parameters ​

ParameterTypeDescription
prevEngineStateThe state before the operation.
nextEngineStateThe state after it.

Returns ​

boolean

True when prev.episode.startedAt is not null and differs from next.episode.startedAt.

Throws ​

TypeError when either argument is not an engine state.

Example ​

ts
const next = observe(state, event);
if (episodeClosed(state, next)) persist(next);

Released under the MIT License.