Skip to main content

CommandHistory

aac-voice-api


Defined in: CommandHistory.ts:49

CommandHistory keeps track of a chronological log of commands.

When to use CommandHistory vs Logger:

  • Use CommandHistory for:

    • Lightweight command-only tracking
    • UI features like command history popup (showHistoryPopup())
    • Simple execution tracking without full context
    • End-user facing features that need quick command lookups
    • Backward compatibility with existing UI components
  • Use Logger (see Logging.ts) for:

    • Comprehensive session analytics with full transcription text
    • Detailed synonym resolution tracking (library vs API sources)
    • Confidence scores and error messages
    • Multi-speaker support and speaker identification
    • JSON export for data analysis and debugging
    • Research and development purposes

This class allows you to:

  • Add new commands to the history (if logging is enabled).
  • Retrieve all commands or a slice of commands.
  • Query the total number of commands logged.
  • Enable or disable logging.
  • Clear the entire history.

Commands are stored in memory in the order they were added. Slices and retrievals return copies of the array to prevent external mutation. There is no built-in limit on how many commands are stored.

Methods​

add()​

add(command): void;

Defined in: CommandHistory.ts:99

Adds a new command to the Command History Log if Logging has been turned on

Parameters​

ParameterTypeDescription

command

CommandLogEntry

Adds a new command entry to the array

Returns​

void


clear()​

clear(): void;

Defined in: CommandHistory.ts:146

Clears all history

Returns​

void


getAll()​

getAll(): CommandLogEntry[];

Defined in: CommandHistory.ts:110

Returns all logged Commands

Returns​

CommandLogEntry[]

returns a copy of the history that is immutable


getSize()​

getSize(): number;

Defined in: CommandHistory.ts:119

Returns a number of commands that have been logged

Returns​

number

The number of commands that have been logged


getSlice()​

getSlice(start, end?): CommandLogEntry[];

Defined in: CommandHistory.ts:134

Returns a portion of the command history as a new array.

Parameters​

ParameterTypeDescription

start

number

Starting position of commands you want to have returned

end?

number

Ending position of the commands you want to have returned

Returns​

CommandLogEntry[]

If the starting slice is larger then the end it will return an empty array otherwise it returns a list of the commands from the starting index to the ending index


isEnabled()​

isEnabled(): boolean;

Defined in: CommandHistory.ts:89

Returns whether logging is currently enabled.

Returns​

boolean

True if logging is enabled, false otherwise


toggle()​

toggle(enable): void;

Defined in: CommandHistory.ts:80

Parameters​

ParameterTypeDescription

enable

boolean

Turn logging on/off.

Returns​

void


getInstance()​

static getInstance(): CommandHistory;

Defined in: CommandHistory.ts:67

Returns the singleton instance of CommandHistory.

Returns​

CommandHistory

The single shared instance.