@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.
- package/dist/browser.d.mts +65 -1
- package/dist/browser.d.ts +467 -502
- package/dist/browser.js +921 -836
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +93 -1
- package/dist/browser.mjs.map +1 -1
- package/dist/embed.iife.js +67 -23358
- package/dist/node.d.mts +63 -0
- package/dist/node.d.ts +462 -483
- package/dist/node.js +453 -467
- package/dist/node.js.map +1 -1
- package/dist/node.mjs.map +1 -1
- package/package.json +2 -1
package/dist/node.d.mts
CHANGED
|
@@ -220,6 +220,60 @@ interface RoomSession {
|
|
|
220
220
|
leave(): Promise<void>;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Browser-friendly text-channel chat session. Mint a `ct_` token with
|
|
225
|
+
* `channel: 'text'` on your backend, then call `startTextSession({...})`
|
|
226
|
+
* to open the SSE stream.
|
|
227
|
+
*
|
|
228
|
+
* Each `.send(text)` is a fresh POST; SSE-per-turn means the connection
|
|
229
|
+
* closes when each turn ends. Conversation state lives server-side on the
|
|
230
|
+
* underlying CallRecord.
|
|
231
|
+
*/
|
|
232
|
+
type ChatEvent = {
|
|
233
|
+
type: 'chat.started';
|
|
234
|
+
chatId: string;
|
|
235
|
+
callId: string;
|
|
236
|
+
} | {
|
|
237
|
+
type: 'token';
|
|
238
|
+
text: string;
|
|
239
|
+
} | {
|
|
240
|
+
type: 'tool.call';
|
|
241
|
+
name: string;
|
|
242
|
+
args: unknown;
|
|
243
|
+
} | {
|
|
244
|
+
type: 'tool.result';
|
|
245
|
+
name: string;
|
|
246
|
+
ok?: boolean;
|
|
247
|
+
[key: string]: unknown;
|
|
248
|
+
} | {
|
|
249
|
+
type: 'turn.end';
|
|
250
|
+
finishReason: 'stop' | 'aborted' | 'length' | 'tool_error';
|
|
251
|
+
committedText?: string;
|
|
252
|
+
} | {
|
|
253
|
+
type: 'error';
|
|
254
|
+
code: string;
|
|
255
|
+
message: string;
|
|
256
|
+
};
|
|
257
|
+
interface StartTextSessionOpts {
|
|
258
|
+
baseUrl: string;
|
|
259
|
+
token: string;
|
|
260
|
+
agentId: string;
|
|
261
|
+
/** Optional inline first user message; otherwise the agent's greeting opens the stream. */
|
|
262
|
+
text?: string;
|
|
263
|
+
/** Override the global fetch (useful for tests; defaults to globalThis.fetch). */
|
|
264
|
+
fetch?: typeof fetch;
|
|
265
|
+
}
|
|
266
|
+
interface TextSession {
|
|
267
|
+
id: string;
|
|
268
|
+
callId: string;
|
|
269
|
+
/** Async iterable for the opening turn — greeting tokens / first reply if text was inlined. */
|
|
270
|
+
greeting: AsyncIterable<ChatEvent>;
|
|
271
|
+
/** Send a user message; returns an async iterable for the agent's reply. */
|
|
272
|
+
send(text: string): Promise<AsyncIterable<ChatEvent>>;
|
|
273
|
+
/** End the session — DELETE /v1/calls/:callId. */
|
|
274
|
+
end(): Promise<void>;
|
|
275
|
+
}
|
|
276
|
+
|
|
223
277
|
interface FetchTokenArgs {
|
|
224
278
|
/** The agent the SDK is about to call. */
|
|
225
279
|
agentId: string;
|
|
@@ -379,6 +433,15 @@ interface VoiceClientFactory {
|
|
|
379
433
|
* implement this — livekit-client is a browser-only WebRTC client.
|
|
380
434
|
*/
|
|
381
435
|
joinRoom?: (options: Omit<JoinRoomOptions, 'apiBase'>) => Promise<RoomSession>;
|
|
436
|
+
/**
|
|
437
|
+
* Open a text-channel chat session (no microphone / audio required).
|
|
438
|
+
* Mint a `ct_` token with `channel: 'text'` server-side, then call
|
|
439
|
+
* this to connect. Returns a `TextSession` with:
|
|
440
|
+
* - `.greeting` — async iterable for the opening turn
|
|
441
|
+
* - `.send(text)` — send a user message; returns an async iterable for the reply
|
|
442
|
+
* - `.end()` — close the session (DELETE /v1/calls/:callId)
|
|
443
|
+
*/
|
|
444
|
+
startTextSession?: (opts: Omit<StartTextSessionOpts, 'baseUrl' | 'fetch'>) => Promise<TextSession>;
|
|
382
445
|
}
|
|
383
446
|
|
|
384
447
|
type RWSEvent = {
|