phonic
Version:
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FPhonic-Co%2Fphonic-node) [ • 3.56 kB
text/typescript
import * as core from "../../../../core/index.mjs";
import type * as Phonic from "../../../index.mjs";
export declare namespace ConversationsSocket {
interface Args {
socket: core.ReconnectingWebSocket;
}
type Response = Phonic.ReadyToStartConversationPayload | Phonic.ConversationCreatedPayload | Phonic.InputTextPayload | Phonic.InputCancelledPayload | Phonic.AudioChunkResponsePayload | Phonic.UserStartedSpeakingPayload | Phonic.UserFinishedSpeakingPayload | Phonic.AssistantStartedSpeakingPayload | Phonic.AssistantFinishedSpeakingPayload | Phonic.DtmfPayload | Phonic.ToolCallPayload | Phonic.ToolCallOutputProcessedPayload | Phonic.ToolCallInterruptedPayload | Phonic.AssistantChoseNotToRespondPayload | Phonic.AssistantEndedConversationPayload | Phonic.ErrorPayload | Phonic.WarningPayload;
type EventHandlers = {
open?: () => void;
message?: (message: Response) => void;
close?: (event: core.CloseEvent) => void;
error?: (error: Error) => void;
};
}
export declare class ConversationsSocket {
readonly socket: core.ReconnectingWebSocket;
protected readonly eventHandlers: ConversationsSocket.EventHandlers;
private handleOpen;
private handleMessage;
private handleClose;
private handleError;
constructor(args: ConversationsSocket.Args);
/** The current state of the connection; this is one of the readyState constants. */
get readyState(): core.ReconnectingWebSocket.ReadyState;
/**
* @param event - The event to attach to.
* @param callback - The callback to run when the event is triggered.
* Usage:
* ```typescript
* this.on('open', () => {
* console.log('The websocket is open');
* });
* ```
*/
on<T extends keyof ConversationsSocket.EventHandlers>(event: T, callback: ConversationsSocket.EventHandlers[T]): void;
sendConfig(message: Phonic.ConfigPayload): void;
sendAudioChunk(message: Phonic.AudioChunkPayload): void;
sendUpdateSystemPrompt(message: Phonic.UpdateSystemPromptPayload): void;
sendAddSystemMessage(message: Phonic.AddSystemMessagePayload): void;
sendUpdateToolsSubset(message: Phonic.UpdateToolsSubsetPayload): void;
sendSetExternalId(message: Phonic.SetExternalIdPayload): void;
sendToolCallOutput(message: Phonic.ToolCallOutputPayload): void;
sendUnmute(message: Phonic.UnmutePayload): void;
sendMute(message: Phonic.MutePayload): void;
sendGenerateReply(message: Phonic.GenerateReplyPayload): void;
sendSay(message: Phonic.SayPayload): void;
sendReset(message: Phonic.ResetPayload): void;
/** Connect to the websocket and register event handlers. */
connect(): ConversationsSocket;
/** Close the websocket and unregister event handlers. */
close(): void;
/** Returns a promise that resolves when the websocket is open. */
waitForOpen(): Promise<core.ReconnectingWebSocket>;
/** Asserts that the websocket is open. */
private assertSocketIsOpen;
/** Send a binary payload to the websocket. */
protected sendBinary(payload: ArrayBuffer | Blob | ArrayBufferView): void;
/** Send a JSON payload to the websocket. */
protected sendJson(payload: Phonic.ConfigPayload | Phonic.AudioChunkPayload | Phonic.UpdateSystemPromptPayload | Phonic.AddSystemMessagePayload | Phonic.UpdateToolsSubsetPayload | Phonic.SetExternalIdPayload | Phonic.ToolCallOutputPayload | Phonic.UnmutePayload | Phonic.MutePayload | Phonic.GenerateReplyPayload | Phonic.SayPayload | Phonic.ResetPayload): void;
}