API Reference
classes
Aiclient

@coasys/ad4m / Exports / AIClient

Class: AIClient

Table of contents

Constructors

Properties

Methods

Constructors

constructor

• new AIClient(baseUrl, token?, sharedApiClient?)

Parameters

NameType
baseUrlstring
token?string
sharedApiClient?ApiClient

Defined in

core/src/ai/AIClient.ts:12 (opens in a new tab)

Properties

#apiClient

• Private #apiClient: ApiClient

Defined in

core/src/ai/AIClient.ts:9 (opens in a new tab)


#pendingStreamIds

• Private #pendingStreamIds: Set<string>

Defined in

core/src/ai/AIClient.ts:143 (opens in a new tab)


#transcriptionUnsubscribers

• Private #transcriptionUnsubscribers: Map<string, () => void>

Defined in

core/src/ai/AIClient.ts:10 (opens in a new tab)

Methods

addModel

▸ addModel(model, options?): Promise<string>

Parameters

NameType
modelModelInput
options?CallOptions

Returns

Promise<string>

Defined in

core/src/ai/AIClient.ts:41 (opens in a new tab)


addTask

▸ addTask(name, modelId, systemPrompt, promptExamples, metaData?): Promise<AITask>

Parameters

NameType
namestring
modelIdstring
systemPromptstring
promptExamples{ input: string ; output: string }[]
metaData?string

Returns

Promise<AITask>

Defined in

core/src/ai/AIClient.ts:65 (opens in a new tab)


closeTranscriptionStream

▸ closeTranscriptionStream(streamId): Promise<void>

Parameters

NameType
streamIdstring

Returns

Promise<void>

Defined in

core/src/ai/AIClient.ts:133 (opens in a new tab)


discoverModels

▸ discoverModels(baseUrl, apiKey?, apiType?): Promise<string[]>

Ask a remote endpoint which models it serves, before adding one.

Takes the credentials of a model that does not exist yet — a settings form is being filled in and wants the list to pick from. Rejects when the endpoint is unreachable or the key is refused, which makes this the credential check too: without it a bad key surfaces later as a failed completion carrying an error from a different layer.

apiType defaults to the OpenAI shape, which is what every endpoint that is not Anthropic speaks.

Parameters

NameType
baseUrlstring
apiKey?string
apiType?string

Returns

Promise<string[]>

Defined in

core/src/ai/AIClient.ts:37 (opens in a new tab)


embed

▸ embed(modelId, text, options?): Promise<number[]>

Parameters

NameType
modelIdstring
textstring
options?CallOptions

Returns

Promise<number[]>

Defined in

core/src/ai/AIClient.ts:97 (opens in a new tab)


feedTranscriptionStream

▸ feedTranscriptionStream(streamIds, audio): Promise<void>

Feed an audio utterance to one or more transcription streams. Sends raw binary Float32Array as application/octet-stream. NOTE: This method still uses HTTP fetch because binary audio data cannot be efficiently sent over the JSON-based WebSocket RPC protocol. Transcription results are delivered via the WS event channel.

Rejects if any stream did not take the audio. When only some failed, the message names them and the others were fed, so retry only the failed ids.

Parameters

NameType
streamIdsstring | string[]
audionumber[] | Float32Array

Returns

Promise<void>

Defined in

core/src/ai/AIClient.ts:155 (opens in a new tab)


getDefaultModel

▸ getDefaultModel(modelType): Promise<AIModel>

Parameters

NameType
modelTypeModelType

Returns

Promise<AIModel>

Defined in

core/src/ai/AIClient.ts:57 (opens in a new tab)


getModels

▸ getModels(): Promise<AIModel[]>

Returns

Promise<AIModel[]>

Defined in

core/src/ai/AIClient.ts:21 (opens in a new tab)


modelLoadingStatus

▸ modelLoadingStatus(model): Promise<AIModelLoadingStatus>

Parameters

NameType
modelstring

Returns

Promise<AIModelLoadingStatus>

Defined in

core/src/ai/AIClient.ts:89 (opens in a new tab)


openTranscriptionStream

▸ openTranscriptionStream(modelId, streamCallback, params?): Promise<string>

Parameters

NameType
modelIdstring
streamCallback(text: string) => void
params?Object
params.endThreshold?number
params.endWindow?number
params.startThreshold?number
params.startWindow?number
params.timeBeforeSpeech?number

Returns

Promise<string>

Defined in

core/src/ai/AIClient.ts:111 (opens in a new tab)


prompt

▸ prompt(taskId, prompt, options?): Promise<string>

Parameters

NameType
taskIdstring
promptstring
options?CallOptions

Returns

Promise<string>

Defined in

core/src/ai/AIClient.ts:93 (opens in a new tab)


removeModel

▸ removeModel(modelId): Promise<boolean>

Parameters

NameType
modelIdstring

Returns

Promise<boolean>

Defined in

core/src/ai/AIClient.ts:49 (opens in a new tab)


removeTask

▸ removeTask(taskId): Promise<boolean>

Parameters

NameType
taskIdstring

Returns

Promise<boolean>

Defined in

core/src/ai/AIClient.ts:70 (opens in a new tab)


serializeModelInput

▸ Private serializeModelInput(«destructured»): ModelInput

The executor names the model type type.

Parameters

NameType
«destructured»ModelInput

Returns

ModelInput

Defined in

core/src/ai/AIClient.ts:17 (opens in a new tab)


setDefaultModel

▸ setDefaultModel(modelType, modelId): Promise<boolean>

Parameters

NameType
modelTypeModelType
modelIdstring

Returns

Promise<boolean>

Defined in

core/src/ai/AIClient.ts:53 (opens in a new tab)


tasks

▸ tasks(): Promise<AITask[]>

Returns

Promise<AITask[]>

Defined in

core/src/ai/AIClient.ts:61 (opens in a new tab)


updateModel

▸ updateModel(modelId, model): Promise<boolean>

Parameters

NameType
modelIdstring
modelModelInput

Returns

Promise<boolean>

Defined in

core/src/ai/AIClient.ts:45 (opens in a new tab)


updateTask

▸ updateTask(taskId, task): Promise<AITask>

Parameters

NameType
taskIdstring
taskAITask

Returns

Promise<AITask>

Defined in

core/src/ai/AIClient.ts:74 (opens in a new tab)