@personaai/react 0.6.0 → 0.7.1

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/index.d.cts CHANGED
@@ -275,6 +275,59 @@ interface SendMessageOverride {
275
275
  /** Answers/approves a paused interrupt from a previous turn instead of starting a fresh one. */
276
276
  resume?: PersonaResumeValue;
277
277
  }
278
+ /**
279
+ * `useVoice`'s call state, driven by `voice_activity` events from the
280
+ * server (never guessed client-side). `'idle'` before `start()` and again
281
+ * after a clean `stop()`; `'ended'` after the server itself closed the
282
+ * session (see {@link PersonaVoiceEndReason}).
283
+ */
284
+ type PersonaVoiceState = "idle" | "connecting" | "listening" | "thinking" | "speaking" | "error" | "ended";
285
+ /** A committed transcript line. See `partial` on {@link UseVoiceResult} for the in-progress one. */
286
+ interface PersonaVoiceTranscriptLine {
287
+ id: string;
288
+ speaker: "user" | "agent";
289
+ text: string;
290
+ }
291
+ interface PersonaVoiceToolCall {
292
+ id: string;
293
+ name?: string;
294
+ status: "running" | "done" | "error";
295
+ /** Tool output (success) or error message — whichever applies. */
296
+ summary?: string;
297
+ }
298
+ /** Why a voice session ended — the terminal `voice_session_ended` event's `reason`. */
299
+ type PersonaVoiceEndReason = "client_closed" | "agent_ended" | "max_duration" | "idle" | "upstream_error" | "upstream_goaway";
300
+ interface UseVoiceOptions {
301
+ /** Falls back to `PersonaProvider`'s `defaultAgentId` if omitted. */
302
+ agentId?: string;
303
+ /**
304
+ * Resume an existing conversation over voice instead of starting fresh.
305
+ * `start()` mints the session with this thread id (same value `useChat`'s
306
+ * `threadId` uses), so voice turns are persisted back into that thread's
307
+ * history — a later text message on the same thread sees them. Omit (or
308
+ * leave undefined) to start a fresh conversation.
309
+ */
310
+ threadId?: string;
311
+ }
312
+ interface UseVoiceResult {
313
+ state: PersonaVoiceState;
314
+ isMuted: boolean;
315
+ /** Committed lines, oldest first. */
316
+ transcript: PersonaVoiceTranscriptLine[];
317
+ /** The current speaker's in-progress (not yet final) line, or `null`. */
318
+ partial: PersonaVoiceTranscriptLine | null;
319
+ toolCalls: PersonaVoiceToolCall[];
320
+ error: Error | null;
321
+ /** Set once the session ends — see {@link PersonaVoiceEndReason}. */
322
+ endReason: PersonaVoiceEndReason | null;
323
+ /** Mints a ticket via the host backend, then opens the call. Resets all state above. */
324
+ start: () => Promise<void>;
325
+ /** Ends the call and tears down the mic/speaker audio graph. Safe to call at any time. */
326
+ stop: () => void;
327
+ mute: (muted: boolean) => void;
328
+ /** Sends a typed message mid-call instead of speaking — the agent may reply in either voice or text. */
329
+ sendText: (text: string) => void;
330
+ }
278
331
 
279
332
  interface PersonaContextValue {
280
333
  baseUrl: string;
@@ -358,6 +411,25 @@ declare function useThreads(autoFetch?: boolean): {
358
411
  getThread: (threadId: string) => Promise<PersonaThread>;
359
412
  };
360
413
 
414
+ /**
415
+ * Drives a real-time voice call with an Agent (powered by Gemini Live).
416
+ *
417
+ * Ticket minting goes through YOUR OWN backend (`POST /voice/sessions` on
418
+ * whichever `@personaai/runtime`-based adapter you've mounted) via
419
+ * `fetchWithAuth` — same as every other hook in this package. The actual
420
+ * call does NOT: once a ticket comes back, this hook opens a WebSocket
421
+ * DIRECTLY to Persona (`ticket.wsUrl`), bypassing your backend entirely for
422
+ * the live audio. This is deliberate — see the package README's Voice
423
+ * section for why (short version: a multi-minute relay would not survive
424
+ * on a serverless deployment the way `POST /chat`'s bounded SSE relay
425
+ * does), and it means your backend never has to become a WebSocket relay.
426
+ *
427
+ * Requires a browser with `AudioWorklet` support (all current evergreen
428
+ * browsers). The processor code itself needs no `/public` file of your
429
+ * own — it's embedded and loaded via a Blob URL (see `voiceWorklets.ts`).
430
+ */
431
+ declare function useVoice(options?: UseVoiceOptions): UseVoiceResult;
432
+
361
433
  declare function useFiles(autoFetch?: boolean): {
362
434
  files: PersonaFileItem[];
363
435
  isLoading: boolean;
@@ -502,6 +574,6 @@ declare function supportsStreamingFetch(): boolean;
502
574
  */
503
575
  declare function openSSEStream(opts: OpenSSEOptions): Promise<SSEStream>;
504
576
 
505
- declare const VERSION = "0.6.0";
577
+ declare const VERSION = "0.7.0";
506
578
 
507
- export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcpConnections, useMemory, usePersonaContext, useThreads };
579
+ export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaVoiceEndReason, type PersonaVoiceState, type PersonaVoiceToolCall, type PersonaVoiceTranscriptLine, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, type UseVoiceOptions, type UseVoiceResult, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcpConnections, useMemory, usePersonaContext, useThreads, useVoice };
package/dist/index.d.ts CHANGED
@@ -275,6 +275,59 @@ interface SendMessageOverride {
275
275
  /** Answers/approves a paused interrupt from a previous turn instead of starting a fresh one. */
276
276
  resume?: PersonaResumeValue;
277
277
  }
278
+ /**
279
+ * `useVoice`'s call state, driven by `voice_activity` events from the
280
+ * server (never guessed client-side). `'idle'` before `start()` and again
281
+ * after a clean `stop()`; `'ended'` after the server itself closed the
282
+ * session (see {@link PersonaVoiceEndReason}).
283
+ */
284
+ type PersonaVoiceState = "idle" | "connecting" | "listening" | "thinking" | "speaking" | "error" | "ended";
285
+ /** A committed transcript line. See `partial` on {@link UseVoiceResult} for the in-progress one. */
286
+ interface PersonaVoiceTranscriptLine {
287
+ id: string;
288
+ speaker: "user" | "agent";
289
+ text: string;
290
+ }
291
+ interface PersonaVoiceToolCall {
292
+ id: string;
293
+ name?: string;
294
+ status: "running" | "done" | "error";
295
+ /** Tool output (success) or error message — whichever applies. */
296
+ summary?: string;
297
+ }
298
+ /** Why a voice session ended — the terminal `voice_session_ended` event's `reason`. */
299
+ type PersonaVoiceEndReason = "client_closed" | "agent_ended" | "max_duration" | "idle" | "upstream_error" | "upstream_goaway";
300
+ interface UseVoiceOptions {
301
+ /** Falls back to `PersonaProvider`'s `defaultAgentId` if omitted. */
302
+ agentId?: string;
303
+ /**
304
+ * Resume an existing conversation over voice instead of starting fresh.
305
+ * `start()` mints the session with this thread id (same value `useChat`'s
306
+ * `threadId` uses), so voice turns are persisted back into that thread's
307
+ * history — a later text message on the same thread sees them. Omit (or
308
+ * leave undefined) to start a fresh conversation.
309
+ */
310
+ threadId?: string;
311
+ }
312
+ interface UseVoiceResult {
313
+ state: PersonaVoiceState;
314
+ isMuted: boolean;
315
+ /** Committed lines, oldest first. */
316
+ transcript: PersonaVoiceTranscriptLine[];
317
+ /** The current speaker's in-progress (not yet final) line, or `null`. */
318
+ partial: PersonaVoiceTranscriptLine | null;
319
+ toolCalls: PersonaVoiceToolCall[];
320
+ error: Error | null;
321
+ /** Set once the session ends — see {@link PersonaVoiceEndReason}. */
322
+ endReason: PersonaVoiceEndReason | null;
323
+ /** Mints a ticket via the host backend, then opens the call. Resets all state above. */
324
+ start: () => Promise<void>;
325
+ /** Ends the call and tears down the mic/speaker audio graph. Safe to call at any time. */
326
+ stop: () => void;
327
+ mute: (muted: boolean) => void;
328
+ /** Sends a typed message mid-call instead of speaking — the agent may reply in either voice or text. */
329
+ sendText: (text: string) => void;
330
+ }
278
331
 
279
332
  interface PersonaContextValue {
280
333
  baseUrl: string;
@@ -358,6 +411,25 @@ declare function useThreads(autoFetch?: boolean): {
358
411
  getThread: (threadId: string) => Promise<PersonaThread>;
359
412
  };
360
413
 
414
+ /**
415
+ * Drives a real-time voice call with an Agent (powered by Gemini Live).
416
+ *
417
+ * Ticket minting goes through YOUR OWN backend (`POST /voice/sessions` on
418
+ * whichever `@personaai/runtime`-based adapter you've mounted) via
419
+ * `fetchWithAuth` — same as every other hook in this package. The actual
420
+ * call does NOT: once a ticket comes back, this hook opens a WebSocket
421
+ * DIRECTLY to Persona (`ticket.wsUrl`), bypassing your backend entirely for
422
+ * the live audio. This is deliberate — see the package README's Voice
423
+ * section for why (short version: a multi-minute relay would not survive
424
+ * on a serverless deployment the way `POST /chat`'s bounded SSE relay
425
+ * does), and it means your backend never has to become a WebSocket relay.
426
+ *
427
+ * Requires a browser with `AudioWorklet` support (all current evergreen
428
+ * browsers). The processor code itself needs no `/public` file of your
429
+ * own — it's embedded and loaded via a Blob URL (see `voiceWorklets.ts`).
430
+ */
431
+ declare function useVoice(options?: UseVoiceOptions): UseVoiceResult;
432
+
361
433
  declare function useFiles(autoFetch?: boolean): {
362
434
  files: PersonaFileItem[];
363
435
  isLoading: boolean;
@@ -502,6 +574,6 @@ declare function supportsStreamingFetch(): boolean;
502
574
  */
503
575
  declare function openSSEStream(opts: OpenSSEOptions): Promise<SSEStream>;
504
576
 
505
- declare const VERSION = "0.6.0";
577
+ declare const VERSION = "0.7.0";
506
578
 
507
- export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcpConnections, useMemory, usePersonaContext, useThreads };
579
+ export { type OpenSSEOptions, type PersonaAgentSummary, type PersonaClarificationQuestion, type PersonaFileItem, type PersonaHealthInfo, type PersonaHitlActionRequest, type PersonaInterrupt, type PersonaMcpConnection, type PersonaMemoryAgentGroup, type PersonaMemoryFile, type PersonaMemoryList, type PersonaMessage, type PersonaPresentedFile, PersonaProvider, type PersonaProviderProps, type PersonaResumeValue, type PersonaRole, type PersonaStreamingEvent, type PersonaSubagentActivityEntry, type PersonaThread, type PersonaTodo, type PersonaToolCall, type PersonaVoiceEndReason, type PersonaVoiceState, type PersonaVoiceToolCall, type PersonaVoiceTranscriptLine, type PersonaWorkspaceFile, type SSEReader, type SSEStream, type SendMessageOverride, type UseChatOptions, type UseMcpConnectionsOptions, type UseVoiceOptions, type UseVoiceResult, VERSION, openSSEStream, supportsStreamingFetch, useAgents, useChat, useConnection, useFiles, useMcpConnections, useMemory, usePersonaContext, useThreads, useVoice };