API Reference

Gami

Main SDK singleton

You should NOT instanciate this class.

Instead use the window gami:init event.

let gami = null;
window.addEventListener("gami:init", (evt) => {
    gami = evt.detail.Gami();
});

Every interaction with the Gami API uses this singleton as entry point

Kind: global class


gami.connect(host) ⇒ Promise.<void>

Connects to the WebSocket server

Kind: instance method of Gami

ParamTypeDescription
hoststring

The WebSocket host URL, reserved for future use, must be NULL

Example

await gami.connect();

gami.disconnect() ⇒ Promise.<void>

Disconnects from the WebSocket server

Kind: instance method of Gami


gami.use_portal(portal_id_or_opts, [token]) ⇒ Promise.<void>

Set the current portal

Kind: instance method of Gami

ParamTypeDescription
portal_id_or_optsstring | integer | Object

The ID of the portal, or an object with portal_id and token properties

[token]string

The embed token, required when first argument is a portal ID

Example

await gami.use_portal(12, "secret-embed-token");
await gami.use_portal({
    portal_id: 12,
    token: "secret-embed-token",
});

gami.create_thread() ⇒ Promise.<{thread_id: string, token: string}>

Creates a new thread in the current portal

Kind: instance method of Gami
Returns: Promise.<{thread_id: string, token: string}> - Object containing thread information thread_id and token
Throws:

  • Error If thread creation fails

Example

const thread_info = await gami.create_thread();

gami.resume_thread() ⇒ Promise.<{thread_id: string, token: string}>

Resume an existing thread in the current portal

Kind: instance method of Gami
Returns: Promise.<{thread_id: string, token: string}> - Thread information
Throws:

  • Error If thread resume fails

Example

const thread_info = await gami.resume_thread(thread_id);

gami.start_recording() ⇒ Promise.<void>

Starts audio recording

This method handles browser permissions for microphone access.

Kind: instance method of Gami
Throws:

  • Error If recording mime type is not supported or thread is not set

Example

await gami.start_recording();

gami.pause_recording() ⇒ Promise.<void>

Pause recording

Kind: instance method of Gami


gami.toggle_recording() ⇒ Promise.<void>

Toggle recording

Kind: instance method of Gami


gami.resume_recording() ⇒ Promise.<void>

Resume recording

Kind: instance method of Gami


gami.append_delta(verb, path, value) ⇒ Promise.<void>

Append a structured delta to the thread structured data.

For example, if the thread data is {"a": "b", "c": "d"}, calling append_delta("set", "c", "e") will update it to {"a": "b", "c": "e"}.

Kind: instance method of Gami

ParamTypeDescription
verbstring

The action verb: set overrides the data at path, insert inserts an item in a list, delete removes an item from a list (value must be null).

pathstring

Dot-separated path (e.g. a.b.c). Use numbers for array indices: a.2.b.

valuestring

Any value that can be passed to JSON.stringify.


gami.extract()

Trigger an extraction.

If an extraction is running, this does nothing. This is an async function that waits on extraction completion.

Kind: instance method of Gami


gami.set_auto_extract(val)

Control auto extraction.

Default to false.

Kind: instance method of Gami

ParamTypeDescription
valboolean

Enable or disable auto extraction


gami.set_live_waveform_enabled(val)

Control live waveform generation.

If set to enabled, a live_waveform event will be generated. Default to false.

Kind: instance method of Gami

ParamTypeDescription
valboolean

Enable or disable live waveform generation


gami.set_extraction_context(ctx)

Set extraction context passed to the extraction engine.

The context is a list of key-value pairs passed as-is to the extraction engine. It must be string keys and string values.

For example, {user: "Jon doe"} will allow the extraction to reference the context user.

Kind: instance method of Gami

ParamTypeDescription
ctxObject

Key-value pairs to pass as context to the extraction


gami.is_recording() ⇒ boolean

Is recording

Kind: instance method of Gami
Returns: boolean - True if recording, false otherwise


gami.is_extracting() ⇒ boolean

Is extracting

Kind: instance method of Gami
Returns: boolean - True if extracting, false otherwise


gami.get_state(key) ⇒ any

Get current state

Kind: instance method of Gami
Returns: any - Current state value, can be undefined if state is not set yet.

ParamTypeDescription
keystring

State key name


gami.get_model() ⇒ Promise.<Object>

Get the model associated with the current thread's portal

Kind: instance method of Gami
Returns: Promise.<Object> - Model data including id, name, output_language and schema
Throws:

  • Error If no portal is active

Example

const { name, schema } = await gami.get_model();
console.log(name, schema);

gami.get_portal() ⇒ Promise.<{data: {id: number, name: string, collection: string, description: string, language: string}}>

Get the current portal data

Kind: instance method of Gami
Returns: Promise.<{data: {id: number, name: string, collection: string, description: string, language: string}}> - Portal data including id, name, collection, description, and language (ASR/STT language; the user must speak this language)
Throws:

  • Error If no portal is active

Example

const { data: portal } = await gami.get_portal();
console.log(portal.name, portal.language);

gami.on(evt, cb) ⇒ Symbol

Add event handler

Kind: instance method of Gami
Returns: Symbol - Unique reference to the handler

ParamTypeDescription
evtstring

Event name

cbfunction

Callback function to execute when event is emitted

Example

const ref = gami.on("update", (data) => console.log(data));

gami.off(ref) ⇒ void

Remove event handler

Kind: instance method of Gami

ParamTypeDescription
refSymbol

Reference returned from on() method

Example

gami.off(ref);