@personaai/react 0.5.4 → 0.7.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/README.md +34 -9
- package/dist/index.cjs +473 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -2
- package/dist/index.d.ts +67 -2
- package/dist/index.js +471 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -275,6 +275,51 @@ 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
|
+
interface UseVoiceResult {
|
|
305
|
+
state: PersonaVoiceState;
|
|
306
|
+
isMuted: boolean;
|
|
307
|
+
/** Committed lines, oldest first. */
|
|
308
|
+
transcript: PersonaVoiceTranscriptLine[];
|
|
309
|
+
/** The current speaker's in-progress (not yet final) line, or `null`. */
|
|
310
|
+
partial: PersonaVoiceTranscriptLine | null;
|
|
311
|
+
toolCalls: PersonaVoiceToolCall[];
|
|
312
|
+
error: Error | null;
|
|
313
|
+
/** Set once the session ends — see {@link PersonaVoiceEndReason}. */
|
|
314
|
+
endReason: PersonaVoiceEndReason | null;
|
|
315
|
+
/** Mints a ticket via the host backend, then opens the call. Resets all state above. */
|
|
316
|
+
start: () => Promise<void>;
|
|
317
|
+
/** Ends the call and tears down the mic/speaker audio graph. Safe to call at any time. */
|
|
318
|
+
stop: () => void;
|
|
319
|
+
mute: (muted: boolean) => void;
|
|
320
|
+
/** Sends a typed message mid-call instead of speaking — the agent may reply in either voice or text. */
|
|
321
|
+
sendText: (text: string) => void;
|
|
322
|
+
}
|
|
278
323
|
|
|
279
324
|
interface PersonaContextValue {
|
|
280
325
|
baseUrl: string;
|
|
@@ -354,9 +399,29 @@ declare function useThreads(autoFetch?: boolean): {
|
|
|
354
399
|
isArchived?: boolean;
|
|
355
400
|
}) => Promise<PersonaThread>;
|
|
356
401
|
renameThread: (threadId: string, title: string) => Promise<PersonaThread>;
|
|
402
|
+
resetThread: (threadId: string) => Promise<PersonaThread>;
|
|
357
403
|
getThread: (threadId: string) => Promise<PersonaThread>;
|
|
358
404
|
};
|
|
359
405
|
|
|
406
|
+
/**
|
|
407
|
+
* Drives a real-time voice call with an Agent (powered by Gemini Live).
|
|
408
|
+
*
|
|
409
|
+
* Ticket minting goes through YOUR OWN backend (`POST /voice/sessions` on
|
|
410
|
+
* whichever `@personaai/runtime`-based adapter you've mounted) via
|
|
411
|
+
* `fetchWithAuth` — same as every other hook in this package. The actual
|
|
412
|
+
* call does NOT: once a ticket comes back, this hook opens a WebSocket
|
|
413
|
+
* DIRECTLY to Persona (`ticket.wsUrl`), bypassing your backend entirely for
|
|
414
|
+
* the live audio. This is deliberate — see the package README's Voice
|
|
415
|
+
* section for why (short version: a multi-minute relay would not survive
|
|
416
|
+
* on a serverless deployment the way `POST /chat`'s bounded SSE relay
|
|
417
|
+
* does), and it means your backend never has to become a WebSocket relay.
|
|
418
|
+
*
|
|
419
|
+
* Requires a browser with `AudioWorklet` support (all current evergreen
|
|
420
|
+
* browsers). The processor code itself needs no `/public` file of your
|
|
421
|
+
* own — it's embedded and loaded via a Blob URL (see `voiceWorklets.ts`).
|
|
422
|
+
*/
|
|
423
|
+
declare function useVoice(options?: UseVoiceOptions): UseVoiceResult;
|
|
424
|
+
|
|
360
425
|
declare function useFiles(autoFetch?: boolean): {
|
|
361
426
|
files: PersonaFileItem[];
|
|
362
427
|
isLoading: boolean;
|
|
@@ -501,6 +566,6 @@ declare function supportsStreamingFetch(): boolean;
|
|
|
501
566
|
*/
|
|
502
567
|
declare function openSSEStream(opts: OpenSSEOptions): Promise<SSEStream>;
|
|
503
568
|
|
|
504
|
-
declare const VERSION = "0.
|
|
569
|
+
declare const VERSION = "0.7.0";
|
|
505
570
|
|
|
506
|
-
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 };
|
|
571
|
+
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,51 @@ 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
|
+
interface UseVoiceResult {
|
|
305
|
+
state: PersonaVoiceState;
|
|
306
|
+
isMuted: boolean;
|
|
307
|
+
/** Committed lines, oldest first. */
|
|
308
|
+
transcript: PersonaVoiceTranscriptLine[];
|
|
309
|
+
/** The current speaker's in-progress (not yet final) line, or `null`. */
|
|
310
|
+
partial: PersonaVoiceTranscriptLine | null;
|
|
311
|
+
toolCalls: PersonaVoiceToolCall[];
|
|
312
|
+
error: Error | null;
|
|
313
|
+
/** Set once the session ends — see {@link PersonaVoiceEndReason}. */
|
|
314
|
+
endReason: PersonaVoiceEndReason | null;
|
|
315
|
+
/** Mints a ticket via the host backend, then opens the call. Resets all state above. */
|
|
316
|
+
start: () => Promise<void>;
|
|
317
|
+
/** Ends the call and tears down the mic/speaker audio graph. Safe to call at any time. */
|
|
318
|
+
stop: () => void;
|
|
319
|
+
mute: (muted: boolean) => void;
|
|
320
|
+
/** Sends a typed message mid-call instead of speaking — the agent may reply in either voice or text. */
|
|
321
|
+
sendText: (text: string) => void;
|
|
322
|
+
}
|
|
278
323
|
|
|
279
324
|
interface PersonaContextValue {
|
|
280
325
|
baseUrl: string;
|
|
@@ -354,9 +399,29 @@ declare function useThreads(autoFetch?: boolean): {
|
|
|
354
399
|
isArchived?: boolean;
|
|
355
400
|
}) => Promise<PersonaThread>;
|
|
356
401
|
renameThread: (threadId: string, title: string) => Promise<PersonaThread>;
|
|
402
|
+
resetThread: (threadId: string) => Promise<PersonaThread>;
|
|
357
403
|
getThread: (threadId: string) => Promise<PersonaThread>;
|
|
358
404
|
};
|
|
359
405
|
|
|
406
|
+
/**
|
|
407
|
+
* Drives a real-time voice call with an Agent (powered by Gemini Live).
|
|
408
|
+
*
|
|
409
|
+
* Ticket minting goes through YOUR OWN backend (`POST /voice/sessions` on
|
|
410
|
+
* whichever `@personaai/runtime`-based adapter you've mounted) via
|
|
411
|
+
* `fetchWithAuth` — same as every other hook in this package. The actual
|
|
412
|
+
* call does NOT: once a ticket comes back, this hook opens a WebSocket
|
|
413
|
+
* DIRECTLY to Persona (`ticket.wsUrl`), bypassing your backend entirely for
|
|
414
|
+
* the live audio. This is deliberate — see the package README's Voice
|
|
415
|
+
* section for why (short version: a multi-minute relay would not survive
|
|
416
|
+
* on a serverless deployment the way `POST /chat`'s bounded SSE relay
|
|
417
|
+
* does), and it means your backend never has to become a WebSocket relay.
|
|
418
|
+
*
|
|
419
|
+
* Requires a browser with `AudioWorklet` support (all current evergreen
|
|
420
|
+
* browsers). The processor code itself needs no `/public` file of your
|
|
421
|
+
* own — it's embedded and loaded via a Blob URL (see `voiceWorklets.ts`).
|
|
422
|
+
*/
|
|
423
|
+
declare function useVoice(options?: UseVoiceOptions): UseVoiceResult;
|
|
424
|
+
|
|
360
425
|
declare function useFiles(autoFetch?: boolean): {
|
|
361
426
|
files: PersonaFileItem[];
|
|
362
427
|
isLoading: boolean;
|
|
@@ -501,6 +566,6 @@ declare function supportsStreamingFetch(): boolean;
|
|
|
501
566
|
*/
|
|
502
567
|
declare function openSSEStream(opts: OpenSSEOptions): Promise<SSEStream>;
|
|
503
568
|
|
|
504
|
-
declare const VERSION = "0.
|
|
569
|
+
declare const VERSION = "0.7.0";
|
|
505
570
|
|
|
506
|
-
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 };
|
|
571
|
+
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 };
|