@craftedxp/voice-js 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -221,6 +221,61 @@ interface RoomSession {
221
221
  }
222
222
  declare const joinRoom: (opts: JoinRoomOptions) => Promise<RoomSession>;
223
223
 
224
+ /**
225
+ * Browser-friendly text-channel chat session. Mint a `ct_` token with
226
+ * `channel: 'text'` on your backend, then call `startTextSession({...})`
227
+ * to open the SSE stream.
228
+ *
229
+ * Each `.send(text)` is a fresh POST; SSE-per-turn means the connection
230
+ * closes when each turn ends. Conversation state lives server-side on the
231
+ * underlying CallRecord.
232
+ */
233
+ type ChatEvent = {
234
+ type: 'chat.started';
235
+ chatId: string;
236
+ callId: string;
237
+ } | {
238
+ type: 'token';
239
+ text: string;
240
+ } | {
241
+ type: 'tool.call';
242
+ name: string;
243
+ args: unknown;
244
+ } | {
245
+ type: 'tool.result';
246
+ name: string;
247
+ ok?: boolean;
248
+ [key: string]: unknown;
249
+ } | {
250
+ type: 'turn.end';
251
+ finishReason: 'stop' | 'aborted' | 'length' | 'tool_error';
252
+ committedText?: string;
253
+ } | {
254
+ type: 'error';
255
+ code: string;
256
+ message: string;
257
+ };
258
+ interface StartTextSessionOpts {
259
+ baseUrl: string;
260
+ token: string;
261
+ agentId: string;
262
+ /** Optional inline first user message; otherwise the agent's greeting opens the stream. */
263
+ text?: string;
264
+ /** Override the global fetch (useful for tests; defaults to globalThis.fetch). */
265
+ fetch?: typeof fetch;
266
+ }
267
+ interface TextSession {
268
+ id: string;
269
+ callId: string;
270
+ /** Async iterable for the opening turn — greeting tokens / first reply if text was inlined. */
271
+ greeting: AsyncIterable<ChatEvent>;
272
+ /** Send a user message; returns an async iterable for the agent's reply. */
273
+ send(text: string): Promise<AsyncIterable<ChatEvent>>;
274
+ /** End the session — DELETE /v1/calls/:callId. */
275
+ end(): Promise<void>;
276
+ }
277
+ declare function startTextSession(opts: StartTextSessionOpts): Promise<TextSession>;
278
+
224
279
  interface FetchTokenArgs {
225
280
  /** The agent the SDK is about to call. */
226
281
  agentId: string;
@@ -380,6 +435,15 @@ interface VoiceClientFactory {
380
435
  * implement this — livekit-client is a browser-only WebRTC client.
381
436
  */
382
437
  joinRoom?: (options: Omit<JoinRoomOptions, 'apiBase'>) => Promise<RoomSession>;
438
+ /**
439
+ * Open a text-channel chat session (no microphone / audio required).
440
+ * Mint a `ct_` token with `channel: 'text'` server-side, then call
441
+ * this to connect. Returns a `TextSession` with:
442
+ * - `.greeting` — async iterable for the opening turn
443
+ * - `.send(text)` — send a user message; returns an async iterable for the reply
444
+ * - `.end()` — close the session (DELETE /v1/calls/:callId)
445
+ */
446
+ startTextSession?: (opts: Omit<StartTextSessionOpts, 'baseUrl' | 'fetch'>) => Promise<TextSession>;
383
447
  }
384
448
 
385
449
  type OnChunk = (pcm: ArrayBuffer) => void;
@@ -511,4 +575,4 @@ declare const parseIncomingCall: (raw: unknown) => IncomingCallPayload;
511
575
  */
512
576
  declare function configureVoiceClient(config: VoiceClientConfig): VoiceClientFactory;
513
577
 
514
- export { type Call, type CallEndEvent, type CallEndReason, type CallError, type CallErrorCode, type CallState, type CaptureController, type CaptureOptions, type ClientTool, type ClientToolMap, type FetchToken, type FetchTokenArgs, type FetchTokenResult, type IncomingCallPayload, type JoinRoomOptions, type OnAgentSpeakingChange, type OnChunk, type OnError, type OnVolume$1 as OnVolume, type PlaybackController, type PlaybackOptions, type ProtocolCallbacks, type ProtocolState, type RWSEvent, type RWSOptions, type ReconnectingWebSocket, type RoomEventName, type RoomEventPayloads, type RoomParticipantInfo, type RoomSession, type ServerMessage, type StartCallOptions, type SystemMessage, type TranscriptEntry, type TranscriptMessage, type VoiceClientConfig, type VoiceClientFactory, type VolumeEvent, type WebSocketFactory, type WebSocketLike, buildWsUrl, configureVoiceClient, createAudioCapture, createAudioPlayback, createProtocolState, createReconnectingWebSocket, handleServerMessage, joinRoom, parseIncomingCall };
578
+ export { type Call, type CallEndEvent, type CallEndReason, type CallError, type CallErrorCode, type CallState, type CaptureController, type CaptureOptions, type ChatEvent, type ClientTool, type ClientToolMap, type FetchToken, type FetchTokenArgs, type FetchTokenResult, type IncomingCallPayload, type JoinRoomOptions, type OnAgentSpeakingChange, type OnChunk, type OnError, type OnVolume$1 as OnVolume, type PlaybackController, type PlaybackOptions, type ProtocolCallbacks, type ProtocolState, type RWSEvent, type RWSOptions, type ReconnectingWebSocket, type RoomEventName, type RoomEventPayloads, type RoomParticipantInfo, type RoomSession, type ServerMessage, type StartCallOptions, type StartTextSessionOpts, type SystemMessage, type TextSession, type TranscriptEntry, type TranscriptMessage, type VoiceClientConfig, type VoiceClientFactory, type VolumeEvent, type WebSocketFactory, type WebSocketLike, buildWsUrl, configureVoiceClient, createAudioCapture, createAudioPlayback, createProtocolState, createReconnectingWebSocket, handleServerMessage, joinRoom, parseIncomingCall, startTextSession };