@shogo-ai/voice 1.9.13 → 2.4.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/README.md +89 -0
- package/dist/{chunk-S3S2RNO6.js → chunk-BI6SL35K.js} +1 -184
- package/dist/chunk-CLF25CZC.js +987 -0
- package/dist/chunk-KMSL5PWK.js +540 -0
- package/dist/chunk-ME3SIZZU.js +581 -0
- package/dist/chunk-TQOBJMEK.js +17 -0
- package/dist/{chunk-T3T4EBWY.js → chunk-UH75UVM2.js} +6 -2
- package/dist/chunk-UW7VQ3S6.js +148 -0
- package/dist/chunk-XE4LLC7Z.js +1067 -0
- package/dist/chunk-ZAW6F3YT.js +172 -0
- package/dist/index.cjs +735 -25
- package/dist/index.d.cts +373 -3
- package/dist/index.d.ts +373 -3
- package/dist/index.js +59 -3
- package/dist/live/client.cjs +173 -0
- package/dist/live/client.d.cts +132 -0
- package/dist/live/client.d.ts +132 -0
- package/dist/live/client.js +9 -0
- package/dist/native/index.d.cts +5 -2
- package/dist/native/index.d.ts +5 -2
- package/dist/native/index.js +15 -11
- package/dist/{organicParticlesShaders-DIva0vBO.d.ts → organicParticlesShaders-seZq7jYX.d.cts} +1 -421
- package/dist/{organicParticlesShaders-DIva0vBO.d.cts → organicParticlesShaders-seZq7jYX.d.ts} +1 -421
- package/dist/particlesConfig-0YbdPOdY.d.cts +223 -0
- package/dist/particlesConfig-0YbdPOdY.d.ts +223 -0
- package/dist/react/conversation.cjs +789 -0
- package/dist/react/conversation.d.cts +134 -0
- package/dist/react/conversation.d.ts +134 -0
- package/dist/react/conversation.js +13 -0
- package/dist/react/index.cjs +374 -36
- package/dist/react/index.d.cts +10 -141
- package/dist/react/index.d.ts +10 -141
- package/dist/react/index.js +23 -770
- package/dist/react/visuals.cjs +1048 -0
- package/dist/react/visuals.d.cts +70 -0
- package/dist/react/visuals.d.ts +70 -0
- package/dist/react/visuals.js +10 -0
- package/dist/route/agent.cjs +1038 -85
- package/dist/route/agent.js +3 -3
- package/dist/route/audio-tags.cjs +1038 -85
- package/dist/route/audio-tags.js +3 -3
- package/dist/route/index.cjs +1042 -85
- package/dist/route/index.d.cts +19 -3
- package/dist/route/index.d.ts +19 -3
- package/dist/route/index.js +3 -3
- package/dist/route/music.cjs +1038 -85
- package/dist/route/music.js +3 -3
- package/dist/route/op.cjs +2118 -0
- package/dist/route/op.d.cts +43 -0
- package/dist/route/op.d.ts +43 -0
- package/dist/route/op.js +27 -0
- package/dist/route/signed-url.cjs +1038 -85
- package/dist/route/signed-url.js +3 -3
- package/dist/route/tts-preview.cjs +1038 -85
- package/dist/route/tts-preview.d.cts +6 -4
- package/dist/route/tts-preview.d.ts +6 -4
- package/dist/route/tts-preview.js +3 -3
- package/dist/server.cjs +1038 -85
- package/dist/server.d.cts +40 -8
- package/dist/server.d.ts +40 -8
- package/dist/server.js +2 -2
- package/dist/types-Bfhu-aQH.d.cts +199 -0
- package/dist/types-Bfhu-aQH.d.ts +199 -0
- package/dist/{types-W9y6eMj3.d.ts → types-CadjTXNH.d.cts} +193 -12
- package/dist/{types-W9y6eMj3.d.cts → types-CadjTXNH.d.ts} +193 -12
- package/package.json +21 -1
- package/dist/chunk-B4JC3DK2.js +0 -529
- package/dist/chunk-O362EJQR.js +0 -524
package/dist/server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as node_http from 'node:http';
|
|
2
|
-
import {
|
|
2
|
+
import { V as VoiceUser, E as ElevenLabsClient, C as CompanionStore, a as VoiceMemoryStore } from './types-CadjTXNH.cjs';
|
|
3
3
|
|
|
4
4
|
type GetVoiceUser = (req: Request) => Promise<VoiceUser | null> | VoiceUser | null;
|
|
5
5
|
/**
|
|
@@ -11,15 +11,33 @@ type GetVoiceUser = (req: Request) => Promise<VoiceUser | null> | VoiceUser | nu
|
|
|
11
11
|
* Auto-detection looks for:
|
|
12
12
|
* - `process.env.RUNTIME_AUTH_SECRET` (pod-injected runtime token)
|
|
13
13
|
* - `process.env.PROJECT_ID` (pod-injected project scope)
|
|
14
|
-
* - `process.env.SHOGO_API_URL` (
|
|
14
|
+
* - `process.env.SHOGO_API_URL` (falls back to `SHOGO_CLOUD_URL`)
|
|
15
|
+
*
|
|
16
|
+
* The API host is resolved per request, not at construction, so a pod
|
|
17
|
+
* that sets the token without a host still gets every local-only
|
|
18
|
+
* handler (body validation, 405s, the static audio-tags catalog) and
|
|
19
|
+
* only the call that actually leaves the process refuses to guess.
|
|
15
20
|
*/
|
|
16
21
|
interface VoiceProxyOptions {
|
|
17
22
|
runtimeToken: string;
|
|
18
23
|
projectId: string;
|
|
24
|
+
/**
|
|
25
|
+
* Base URL of the Shogo API. Empty string when the proxy was derived
|
|
26
|
+
* from env: the host is then re-read from `SHOGO_API_URL` /
|
|
27
|
+
* `SHOGO_CLOUD_URL` on each proxied call.
|
|
28
|
+
*/
|
|
19
29
|
apiUrl: string;
|
|
20
30
|
/** Custom fetch impl (forwarded to the proxy fetches). */
|
|
21
31
|
fetch?: typeof fetch;
|
|
22
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* How the handlers should reach ElevenLabs:
|
|
35
|
+
* - `'byo'` — always use the supplied `apiKey`, even inside a pod
|
|
36
|
+
* - `'proxy'` — always go through the Shogo API with the runtime token
|
|
37
|
+
* - `'auto'` — (default) an explicit `apiKey` wins, otherwise use the
|
|
38
|
+
* ambient pod runtime token when present
|
|
39
|
+
*/
|
|
40
|
+
type VoiceHandlerMode = 'proxy' | 'byo' | 'auto';
|
|
23
41
|
interface VoiceHandlersConfig {
|
|
24
42
|
/**
|
|
25
43
|
* 11Labs API key. Required in BYO-EL mode; ignored / optional when
|
|
@@ -28,16 +46,23 @@ interface VoiceHandlersConfig {
|
|
|
28
46
|
apiKey?: string;
|
|
29
47
|
/**
|
|
30
48
|
* Resolve the authenticated user from a request, or `null` for
|
|
31
|
-
* unauthenticated. Required
|
|
32
|
-
*
|
|
33
|
-
*
|
|
49
|
+
* unauthenticated. Required for the user-scoped handlers (`signedUrl`,
|
|
50
|
+
* `agent.*`); optional for `tts` / `music`, which are project-scoped and
|
|
51
|
+
* work without a user context.
|
|
34
52
|
*/
|
|
35
53
|
getUser?: GetVoiceUser;
|
|
36
54
|
/**
|
|
37
|
-
* Consumer-owned persistence layer for Companion records. Required
|
|
38
|
-
*
|
|
55
|
+
* Consumer-owned persistence layer for Companion records. Required for
|
|
56
|
+
* the user-scoped handlers (`signedUrl`, `agent.*`); unused by `tts` /
|
|
57
|
+
* `music` and by proxy mode.
|
|
39
58
|
*/
|
|
40
59
|
companionStore?: CompanionStore;
|
|
60
|
+
/**
|
|
61
|
+
* Force a transport: `'byo'` always uses `apiKey`, `'proxy'` always uses
|
|
62
|
+
* the runtime token, `'auto'` (default) prefers an explicit `apiKey` and
|
|
63
|
+
* falls back to the ambient pod runtime token.
|
|
64
|
+
*/
|
|
65
|
+
mode?: VoiceHandlerMode;
|
|
41
66
|
/** Optional memory store — when present, `signedUrl` preloads context bullets. */
|
|
42
67
|
memoryStore?: (userId: string) => VoiceMemoryStore;
|
|
43
68
|
/**
|
|
@@ -81,6 +106,13 @@ interface VoiceHandlers {
|
|
|
81
106
|
};
|
|
82
107
|
/** `GET /voice/audio-tags` — static catalog + defaults (no auth required). */
|
|
83
108
|
audioTags: (req: Request) => Promise<Response>;
|
|
109
|
+
/**
|
|
110
|
+
* Any op in the {@link VOICE_OPS} registry — `handlers.op(req, 'speech-to-speech')`.
|
|
111
|
+
* `opId` may be omitted when the request URL carries it (last path segment,
|
|
112
|
+
* e.g. `/api/voice/op/speech-to-speech`). Adding a registry row makes it
|
|
113
|
+
* callable here with no other change.
|
|
114
|
+
*/
|
|
115
|
+
op: (req: Request, opId?: string) => Promise<Response>;
|
|
84
116
|
/**
|
|
85
117
|
* The underlying ElevenLabsClient, exposed for consumers who need to build
|
|
86
118
|
* additional endpoints (e.g. an agent-driven God Mode settings editor).
|
|
@@ -91,4 +123,4 @@ declare function createVoiceHandlers(config: VoiceHandlersConfig): VoiceHandlers
|
|
|
91
123
|
/** Wrap a handler for Node `http.createServer` style callbacks. */
|
|
92
124
|
declare function toNodeListener(handler: (req: Request) => Promise<Response>): (req: node_http.IncomingMessage, res: node_http.ServerResponse) => void;
|
|
93
125
|
|
|
94
|
-
export { type GetVoiceUser, type VoiceHandlers, type VoiceHandlersConfig, type VoiceProxyOptions, createVoiceHandlers, toNodeListener };
|
|
126
|
+
export { type GetVoiceUser, type VoiceHandlerMode, type VoiceHandlers, type VoiceHandlersConfig, type VoiceProxyOptions, createVoiceHandlers, toNodeListener };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as node_http from 'node:http';
|
|
2
|
-
import {
|
|
2
|
+
import { V as VoiceUser, E as ElevenLabsClient, C as CompanionStore, a as VoiceMemoryStore } from './types-CadjTXNH.js';
|
|
3
3
|
|
|
4
4
|
type GetVoiceUser = (req: Request) => Promise<VoiceUser | null> | VoiceUser | null;
|
|
5
5
|
/**
|
|
@@ -11,15 +11,33 @@ type GetVoiceUser = (req: Request) => Promise<VoiceUser | null> | VoiceUser | nu
|
|
|
11
11
|
* Auto-detection looks for:
|
|
12
12
|
* - `process.env.RUNTIME_AUTH_SECRET` (pod-injected runtime token)
|
|
13
13
|
* - `process.env.PROJECT_ID` (pod-injected project scope)
|
|
14
|
-
* - `process.env.SHOGO_API_URL` (
|
|
14
|
+
* - `process.env.SHOGO_API_URL` (falls back to `SHOGO_CLOUD_URL`)
|
|
15
|
+
*
|
|
16
|
+
* The API host is resolved per request, not at construction, so a pod
|
|
17
|
+
* that sets the token without a host still gets every local-only
|
|
18
|
+
* handler (body validation, 405s, the static audio-tags catalog) and
|
|
19
|
+
* only the call that actually leaves the process refuses to guess.
|
|
15
20
|
*/
|
|
16
21
|
interface VoiceProxyOptions {
|
|
17
22
|
runtimeToken: string;
|
|
18
23
|
projectId: string;
|
|
24
|
+
/**
|
|
25
|
+
* Base URL of the Shogo API. Empty string when the proxy was derived
|
|
26
|
+
* from env: the host is then re-read from `SHOGO_API_URL` /
|
|
27
|
+
* `SHOGO_CLOUD_URL` on each proxied call.
|
|
28
|
+
*/
|
|
19
29
|
apiUrl: string;
|
|
20
30
|
/** Custom fetch impl (forwarded to the proxy fetches). */
|
|
21
31
|
fetch?: typeof fetch;
|
|
22
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* How the handlers should reach ElevenLabs:
|
|
35
|
+
* - `'byo'` — always use the supplied `apiKey`, even inside a pod
|
|
36
|
+
* - `'proxy'` — always go through the Shogo API with the runtime token
|
|
37
|
+
* - `'auto'` — (default) an explicit `apiKey` wins, otherwise use the
|
|
38
|
+
* ambient pod runtime token when present
|
|
39
|
+
*/
|
|
40
|
+
type VoiceHandlerMode = 'proxy' | 'byo' | 'auto';
|
|
23
41
|
interface VoiceHandlersConfig {
|
|
24
42
|
/**
|
|
25
43
|
* 11Labs API key. Required in BYO-EL mode; ignored / optional when
|
|
@@ -28,16 +46,23 @@ interface VoiceHandlersConfig {
|
|
|
28
46
|
apiKey?: string;
|
|
29
47
|
/**
|
|
30
48
|
* Resolve the authenticated user from a request, or `null` for
|
|
31
|
-
* unauthenticated. Required
|
|
32
|
-
*
|
|
33
|
-
*
|
|
49
|
+
* unauthenticated. Required for the user-scoped handlers (`signedUrl`,
|
|
50
|
+
* `agent.*`); optional for `tts` / `music`, which are project-scoped and
|
|
51
|
+
* work without a user context.
|
|
34
52
|
*/
|
|
35
53
|
getUser?: GetVoiceUser;
|
|
36
54
|
/**
|
|
37
|
-
* Consumer-owned persistence layer for Companion records. Required
|
|
38
|
-
*
|
|
55
|
+
* Consumer-owned persistence layer for Companion records. Required for
|
|
56
|
+
* the user-scoped handlers (`signedUrl`, `agent.*`); unused by `tts` /
|
|
57
|
+
* `music` and by proxy mode.
|
|
39
58
|
*/
|
|
40
59
|
companionStore?: CompanionStore;
|
|
60
|
+
/**
|
|
61
|
+
* Force a transport: `'byo'` always uses `apiKey`, `'proxy'` always uses
|
|
62
|
+
* the runtime token, `'auto'` (default) prefers an explicit `apiKey` and
|
|
63
|
+
* falls back to the ambient pod runtime token.
|
|
64
|
+
*/
|
|
65
|
+
mode?: VoiceHandlerMode;
|
|
41
66
|
/** Optional memory store — when present, `signedUrl` preloads context bullets. */
|
|
42
67
|
memoryStore?: (userId: string) => VoiceMemoryStore;
|
|
43
68
|
/**
|
|
@@ -81,6 +106,13 @@ interface VoiceHandlers {
|
|
|
81
106
|
};
|
|
82
107
|
/** `GET /voice/audio-tags` — static catalog + defaults (no auth required). */
|
|
83
108
|
audioTags: (req: Request) => Promise<Response>;
|
|
109
|
+
/**
|
|
110
|
+
* Any op in the {@link VOICE_OPS} registry — `handlers.op(req, 'speech-to-speech')`.
|
|
111
|
+
* `opId` may be omitted when the request URL carries it (last path segment,
|
|
112
|
+
* e.g. `/api/voice/op/speech-to-speech`). Adding a registry row makes it
|
|
113
|
+
* callable here with no other change.
|
|
114
|
+
*/
|
|
115
|
+
op: (req: Request, opId?: string) => Promise<Response>;
|
|
84
116
|
/**
|
|
85
117
|
* The underlying ElevenLabsClient, exposed for consumers who need to build
|
|
86
118
|
* additional endpoints (e.g. an agent-driven God Mode settings editor).
|
|
@@ -91,4 +123,4 @@ declare function createVoiceHandlers(config: VoiceHandlersConfig): VoiceHandlers
|
|
|
91
123
|
/** Wrap a handler for Node `http.createServer` style callbacks. */
|
|
92
124
|
declare function toNodeListener(handler: (req: Request) => Promise<Response>): (req: node_http.IncomingMessage, res: node_http.ServerResponse) => void;
|
|
93
125
|
|
|
94
|
-
export { type GetVoiceUser, type VoiceHandlers, type VoiceHandlersConfig, type VoiceProxyOptions, createVoiceHandlers, toNodeListener };
|
|
126
|
+
export { type GetVoiceUser, type VoiceHandlerMode, type VoiceHandlers, type VoiceHandlersConfig, type VoiceProxyOptions, createVoiceHandlers, toNodeListener };
|
package/dist/server.js
CHANGED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared option / result types for `useVoiceConversation` across
|
|
3
|
+
* platforms. The web hook ([packages/sdk/src/voice/react]) and the
|
|
4
|
+
* native hook ([packages/sdk/src/voice/native]) both export their own
|
|
5
|
+
* `UseVoiceConversationOptions` / `UseVoiceConversationResult`
|
|
6
|
+
* types — typically by re-exporting `BaseVoiceConversationOptions` /
|
|
7
|
+
* `BaseVoiceConversationResult` from this module — so consumers can
|
|
8
|
+
* import them from whichever subpath they're using.
|
|
9
|
+
*/
|
|
10
|
+
interface BaseVoiceConversationOptions {
|
|
11
|
+
/** Name of the companion the user is talking to (passed as a dynamic variable). */
|
|
12
|
+
characterName: string;
|
|
13
|
+
/** Server path that mints an 11Labs signed URL for this user. Default: `/api/voice/signed-url`. */
|
|
14
|
+
signedUrlPath?: string;
|
|
15
|
+
/** Server path the built-in `add_memory` tool POSTs to. Default: `/api/memory/add`. */
|
|
16
|
+
memoryAddPath?: string;
|
|
17
|
+
/** Server path used to auto-inject memory context. Default: `/api/memory/retrieve`. */
|
|
18
|
+
memoryRetrievePath?: string;
|
|
19
|
+
/** Server path the transcript is POSTed to when the session ends. Default: `/api/memory/ingest`. */
|
|
20
|
+
transcriptIngestPath?: string;
|
|
21
|
+
/** Disable the built-in memory context auto-injection. Default: `true` (enabled). */
|
|
22
|
+
autoInjectMemory?: boolean;
|
|
23
|
+
/** Disable the built-in `add_memory` client tool. Default: `true` (enabled). */
|
|
24
|
+
includeMemoryTool?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Additional client tools merged onto `add_memory`. Tools defined here with
|
|
27
|
+
* the name `add_memory` override the built-in implementation.
|
|
28
|
+
*/
|
|
29
|
+
clientTools?: Record<string, (params: Record<string, unknown>) => Promise<string> | string>;
|
|
30
|
+
/**
|
|
31
|
+
* Called once per session with the accumulated transcript when the session
|
|
32
|
+
* disconnects. Defaults to POST `transcriptIngestPath`; set this to suppress
|
|
33
|
+
* or replace that behaviour.
|
|
34
|
+
*/
|
|
35
|
+
onTranscript?: (transcript: string) => void | Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Credentials mode for built-in fetch calls.
|
|
38
|
+
*
|
|
39
|
+
* - Defaults to `same-origin` in the legacy cookie path.
|
|
40
|
+
* - Defaults to `omit` when `shogoApiKey` is provided (bearer auth is
|
|
41
|
+
* self-contained and you don't want browsers to attach unrelated
|
|
42
|
+
* third-party cookies cross-origin).
|
|
43
|
+
* - Explicit values always win — pass `'include'` to carry both a cookie
|
|
44
|
+
* and the bearer in a hybrid same-origin app.
|
|
45
|
+
*/
|
|
46
|
+
fetchCredentials?: RequestCredentials;
|
|
47
|
+
/**
|
|
48
|
+
* Shogo API key (`shogo_sk_*`) used to authenticate voice routes. When
|
|
49
|
+
* provided, the hook attaches `Authorization: Bearer <key>` to the
|
|
50
|
+
* signed-URL fetch and memory fetches, and appends `?projectId=` to
|
|
51
|
+
* the signed-URL path. Either `shogoApiKey` or a session cookie must
|
|
52
|
+
* be resolvable by the server — both may be passed; the server's
|
|
53
|
+
* `apiKeyOrSession` middleware picks bearer first.
|
|
54
|
+
*/
|
|
55
|
+
shogoApiKey?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Project id (Shogo's `projectId`). Required alongside `shogoApiKey`
|
|
58
|
+
* for Mode B voice. The server uses it to look up / provision the
|
|
59
|
+
* project's ElevenLabs agent and resolve the workspace.
|
|
60
|
+
*/
|
|
61
|
+
projectId?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Optional named agent to talk to. Forwarded as `?agentName=` on
|
|
64
|
+
* the signed-URL fetch and resolved server-side to a project-scoped
|
|
65
|
+
* `ProjectAgent` row (created via `shogo deploy`). When omitted,
|
|
66
|
+
* the server resolves the project's `default` agent.
|
|
67
|
+
*
|
|
68
|
+
* The same `agentName` reaches the same persona via
|
|
69
|
+
* `useChatConversation({ agentName })` — voice and chat are two
|
|
70
|
+
* transports for one agent record.
|
|
71
|
+
*/
|
|
72
|
+
agentName?: string;
|
|
73
|
+
/** Called on connection errors. */
|
|
74
|
+
onError?: (error: unknown) => void;
|
|
75
|
+
/** Called on each message (user or agent) for debugging / custom UI. */
|
|
76
|
+
onMessage?: (message: {
|
|
77
|
+
source: string;
|
|
78
|
+
message: string;
|
|
79
|
+
}) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Stable conversation id used to correlate this voice session with
|
|
82
|
+
* a sibling text thread (see `BaseChatConversationOptions.conversationId`).
|
|
83
|
+
*
|
|
84
|
+
* When set, forwarded to ElevenLabs as a `conversation_id` dynamic
|
|
85
|
+
* variable so the agent's prompt can reference it (`{{conversation_id}}`),
|
|
86
|
+
* and surfaced on `BaseVoiceConversationResult.conversationId` so a
|
|
87
|
+
* single bridge component can read the same value from either hook.
|
|
88
|
+
*
|
|
89
|
+
* Independent of the convai-side conversation id — see
|
|
90
|
+
* `BaseVoiceConversationResult.convaiConversationId` for that. The
|
|
91
|
+
* caller-supplied value wins on `result.conversationId` so consumers
|
|
92
|
+
* who keep their own thread store don't have to special-case the
|
|
93
|
+
* default. Optional; when omitted, `result.conversationId` mirrors
|
|
94
|
+
* the convai conversation id once the session connects.
|
|
95
|
+
*/
|
|
96
|
+
conversationId?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Extra dynamic variables forwarded to ElevenLabs at session start.
|
|
99
|
+
* Merged on top of the SDK's built-in variables — `character_name`,
|
|
100
|
+
* `user_context`, and `conversation_id` (when supplied) always win
|
|
101
|
+
* on collision so consumers can't accidentally override them.
|
|
102
|
+
*
|
|
103
|
+
* Typical use: surface per-user fields from the consumer's own
|
|
104
|
+
* `Companion` row (display name, relationship stage, custom greeting
|
|
105
|
+
* tokens) so the agent's prompt can reference them via
|
|
106
|
+
* `{{var_name}}`. Variables also need to be declared in the agent's
|
|
107
|
+
* `dynamic_variable_placeholders` (set at deploy time) for EL to
|
|
108
|
+
* pick up the value.
|
|
109
|
+
*
|
|
110
|
+
* Non-string values are coerced via `String(...)` before being
|
|
111
|
+
* forwarded; `null` / `undefined` values are silently dropped.
|
|
112
|
+
*/
|
|
113
|
+
dynamicVariables?: Record<string, unknown> | null;
|
|
114
|
+
}
|
|
115
|
+
interface BaseVoiceConversationResult {
|
|
116
|
+
/**
|
|
117
|
+
* Begin a new session. Requests microphone permission and fetches a
|
|
118
|
+
* signed URL.
|
|
119
|
+
*
|
|
120
|
+
* `suppressFirstMessage` mirrors the option on `restart()` — when
|
|
121
|
+
* `true`, the new session is opened with `overrides.agent.firstMessage = ''`
|
|
122
|
+
* so the agent skips its opening greeting. Useful when the consumer
|
|
123
|
+
* is programmatically reconnecting (e.g. to deliver a one-shot spoken
|
|
124
|
+
* summary) and does not want to hear the configured intro.
|
|
125
|
+
*/
|
|
126
|
+
start: (options?: {
|
|
127
|
+
suppressFirstMessage?: boolean;
|
|
128
|
+
}) => Promise<void>;
|
|
129
|
+
/** End the current session (if any). */
|
|
130
|
+
end: () => void;
|
|
131
|
+
/**
|
|
132
|
+
* Tear down the active session and immediately reconnect. Primarily
|
|
133
|
+
* used as a programmatic barge-in: ElevenLabs doesn't expose a public
|
|
134
|
+
* `interrupt()` on `useConversation`, so stopping the agent mid-
|
|
135
|
+
* utterance requires a fast disconnect + reconnect. When
|
|
136
|
+
* `suppressFirstMessage` is `true` (the default), the new session is
|
|
137
|
+
* started with `overrides.agent.firstMessage = ''` so the agent does
|
|
138
|
+
* not replay its intro. The accumulated transcript is preserved
|
|
139
|
+
* across the reconnect gap.
|
|
140
|
+
*/
|
|
141
|
+
restart: (options?: {
|
|
142
|
+
suppressFirstMessage?: boolean;
|
|
143
|
+
}) => Promise<void>;
|
|
144
|
+
/** `'disconnected' | 'connecting' | 'connected'`. */
|
|
145
|
+
status: 'disconnected' | 'connecting' | 'connected';
|
|
146
|
+
/** Whether the agent is currently speaking. */
|
|
147
|
+
isSpeaking: boolean;
|
|
148
|
+
/** Whether the agent is currently listening. */
|
|
149
|
+
isListening: boolean;
|
|
150
|
+
/** Whether the microphone is currently muted (input audio is gated off). */
|
|
151
|
+
isMuted: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Toggle the microphone mute state without tearing down the session.
|
|
154
|
+
* Wraps `@elevenlabs/react` (or `@elevenlabs/react-native`)'s
|
|
155
|
+
* `setMuted`, which in turn calls `conversation.setMicMuted()`.
|
|
156
|
+
* Muting does not end the WebSocket or release the underlying media
|
|
157
|
+
* stream; it simply stops input audio from being forwarded to the
|
|
158
|
+
* server.
|
|
159
|
+
*/
|
|
160
|
+
setMuted: (isMuted: boolean) => void;
|
|
161
|
+
/** For consumers who want to drive their own visualisation / lipsync. */
|
|
162
|
+
getOutputByteFrequencyData: () => Uint8Array | null;
|
|
163
|
+
/** Imperatively send a contextual update (e.g. "user navigated to X"). */
|
|
164
|
+
sendContextualUpdate: (text: string) => void;
|
|
165
|
+
/**
|
|
166
|
+
* Imperatively inject a user-role message, forcing the agent to take
|
|
167
|
+
* its next turn immediately (rather than waiting for the human to
|
|
168
|
+
* speak). Useful for out-of-band prompts like "please summarise what
|
|
169
|
+
* just happened". The injected text is *not* spoken aloud — the agent
|
|
170
|
+
* treats it as if the user said it.
|
|
171
|
+
*/
|
|
172
|
+
sendUserMessage: (text: string) => void;
|
|
173
|
+
/**
|
|
174
|
+
* Low-level signal that the user is active (typing, clicking) so the
|
|
175
|
+
* agent doesn't try to fill silence. Used as a fallback nudge when we
|
|
176
|
+
* want to keep the session "warm" without forcing a full turn.
|
|
177
|
+
*/
|
|
178
|
+
sendUserActivity: () => void;
|
|
179
|
+
/**
|
|
180
|
+
* Stable conversation id for cross-transport correlation. Returns the
|
|
181
|
+
* caller-supplied `BaseVoiceConversationOptions.conversationId` when
|
|
182
|
+
* one was provided; otherwise mirrors the convai conversation id once
|
|
183
|
+
* the session connects (and is `null` while disconnected).
|
|
184
|
+
*
|
|
185
|
+
* Pass this same value to `useChatConversation({ conversationId })`
|
|
186
|
+
* to stitch a text thread onto the same logical conversation.
|
|
187
|
+
*/
|
|
188
|
+
conversationId: string | null;
|
|
189
|
+
/**
|
|
190
|
+
* The convai-side conversation id reported by ElevenLabs on connect.
|
|
191
|
+
* Always reflects the underlying transport id (or `null` while
|
|
192
|
+
* disconnected) regardless of whether the consumer supplied an id.
|
|
193
|
+
* Useful for log correlation against ElevenLabs dashboards even
|
|
194
|
+
* when the consumer is using their own ids on `conversationId`.
|
|
195
|
+
*/
|
|
196
|
+
convaiConversationId: string | null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export type { BaseVoiceConversationOptions as B, BaseVoiceConversationResult as a };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared option / result types for `useVoiceConversation` across
|
|
3
|
+
* platforms. The web hook ([packages/sdk/src/voice/react]) and the
|
|
4
|
+
* native hook ([packages/sdk/src/voice/native]) both export their own
|
|
5
|
+
* `UseVoiceConversationOptions` / `UseVoiceConversationResult`
|
|
6
|
+
* types — typically by re-exporting `BaseVoiceConversationOptions` /
|
|
7
|
+
* `BaseVoiceConversationResult` from this module — so consumers can
|
|
8
|
+
* import them from whichever subpath they're using.
|
|
9
|
+
*/
|
|
10
|
+
interface BaseVoiceConversationOptions {
|
|
11
|
+
/** Name of the companion the user is talking to (passed as a dynamic variable). */
|
|
12
|
+
characterName: string;
|
|
13
|
+
/** Server path that mints an 11Labs signed URL for this user. Default: `/api/voice/signed-url`. */
|
|
14
|
+
signedUrlPath?: string;
|
|
15
|
+
/** Server path the built-in `add_memory` tool POSTs to. Default: `/api/memory/add`. */
|
|
16
|
+
memoryAddPath?: string;
|
|
17
|
+
/** Server path used to auto-inject memory context. Default: `/api/memory/retrieve`. */
|
|
18
|
+
memoryRetrievePath?: string;
|
|
19
|
+
/** Server path the transcript is POSTed to when the session ends. Default: `/api/memory/ingest`. */
|
|
20
|
+
transcriptIngestPath?: string;
|
|
21
|
+
/** Disable the built-in memory context auto-injection. Default: `true` (enabled). */
|
|
22
|
+
autoInjectMemory?: boolean;
|
|
23
|
+
/** Disable the built-in `add_memory` client tool. Default: `true` (enabled). */
|
|
24
|
+
includeMemoryTool?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Additional client tools merged onto `add_memory`. Tools defined here with
|
|
27
|
+
* the name `add_memory` override the built-in implementation.
|
|
28
|
+
*/
|
|
29
|
+
clientTools?: Record<string, (params: Record<string, unknown>) => Promise<string> | string>;
|
|
30
|
+
/**
|
|
31
|
+
* Called once per session with the accumulated transcript when the session
|
|
32
|
+
* disconnects. Defaults to POST `transcriptIngestPath`; set this to suppress
|
|
33
|
+
* or replace that behaviour.
|
|
34
|
+
*/
|
|
35
|
+
onTranscript?: (transcript: string) => void | Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Credentials mode for built-in fetch calls.
|
|
38
|
+
*
|
|
39
|
+
* - Defaults to `same-origin` in the legacy cookie path.
|
|
40
|
+
* - Defaults to `omit` when `shogoApiKey` is provided (bearer auth is
|
|
41
|
+
* self-contained and you don't want browsers to attach unrelated
|
|
42
|
+
* third-party cookies cross-origin).
|
|
43
|
+
* - Explicit values always win — pass `'include'` to carry both a cookie
|
|
44
|
+
* and the bearer in a hybrid same-origin app.
|
|
45
|
+
*/
|
|
46
|
+
fetchCredentials?: RequestCredentials;
|
|
47
|
+
/**
|
|
48
|
+
* Shogo API key (`shogo_sk_*`) used to authenticate voice routes. When
|
|
49
|
+
* provided, the hook attaches `Authorization: Bearer <key>` to the
|
|
50
|
+
* signed-URL fetch and memory fetches, and appends `?projectId=` to
|
|
51
|
+
* the signed-URL path. Either `shogoApiKey` or a session cookie must
|
|
52
|
+
* be resolvable by the server — both may be passed; the server's
|
|
53
|
+
* `apiKeyOrSession` middleware picks bearer first.
|
|
54
|
+
*/
|
|
55
|
+
shogoApiKey?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Project id (Shogo's `projectId`). Required alongside `shogoApiKey`
|
|
58
|
+
* for Mode B voice. The server uses it to look up / provision the
|
|
59
|
+
* project's ElevenLabs agent and resolve the workspace.
|
|
60
|
+
*/
|
|
61
|
+
projectId?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Optional named agent to talk to. Forwarded as `?agentName=` on
|
|
64
|
+
* the signed-URL fetch and resolved server-side to a project-scoped
|
|
65
|
+
* `ProjectAgent` row (created via `shogo deploy`). When omitted,
|
|
66
|
+
* the server resolves the project's `default` agent.
|
|
67
|
+
*
|
|
68
|
+
* The same `agentName` reaches the same persona via
|
|
69
|
+
* `useChatConversation({ agentName })` — voice and chat are two
|
|
70
|
+
* transports for one agent record.
|
|
71
|
+
*/
|
|
72
|
+
agentName?: string;
|
|
73
|
+
/** Called on connection errors. */
|
|
74
|
+
onError?: (error: unknown) => void;
|
|
75
|
+
/** Called on each message (user or agent) for debugging / custom UI. */
|
|
76
|
+
onMessage?: (message: {
|
|
77
|
+
source: string;
|
|
78
|
+
message: string;
|
|
79
|
+
}) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Stable conversation id used to correlate this voice session with
|
|
82
|
+
* a sibling text thread (see `BaseChatConversationOptions.conversationId`).
|
|
83
|
+
*
|
|
84
|
+
* When set, forwarded to ElevenLabs as a `conversation_id` dynamic
|
|
85
|
+
* variable so the agent's prompt can reference it (`{{conversation_id}}`),
|
|
86
|
+
* and surfaced on `BaseVoiceConversationResult.conversationId` so a
|
|
87
|
+
* single bridge component can read the same value from either hook.
|
|
88
|
+
*
|
|
89
|
+
* Independent of the convai-side conversation id — see
|
|
90
|
+
* `BaseVoiceConversationResult.convaiConversationId` for that. The
|
|
91
|
+
* caller-supplied value wins on `result.conversationId` so consumers
|
|
92
|
+
* who keep their own thread store don't have to special-case the
|
|
93
|
+
* default. Optional; when omitted, `result.conversationId` mirrors
|
|
94
|
+
* the convai conversation id once the session connects.
|
|
95
|
+
*/
|
|
96
|
+
conversationId?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Extra dynamic variables forwarded to ElevenLabs at session start.
|
|
99
|
+
* Merged on top of the SDK's built-in variables — `character_name`,
|
|
100
|
+
* `user_context`, and `conversation_id` (when supplied) always win
|
|
101
|
+
* on collision so consumers can't accidentally override them.
|
|
102
|
+
*
|
|
103
|
+
* Typical use: surface per-user fields from the consumer's own
|
|
104
|
+
* `Companion` row (display name, relationship stage, custom greeting
|
|
105
|
+
* tokens) so the agent's prompt can reference them via
|
|
106
|
+
* `{{var_name}}`. Variables also need to be declared in the agent's
|
|
107
|
+
* `dynamic_variable_placeholders` (set at deploy time) for EL to
|
|
108
|
+
* pick up the value.
|
|
109
|
+
*
|
|
110
|
+
* Non-string values are coerced via `String(...)` before being
|
|
111
|
+
* forwarded; `null` / `undefined` values are silently dropped.
|
|
112
|
+
*/
|
|
113
|
+
dynamicVariables?: Record<string, unknown> | null;
|
|
114
|
+
}
|
|
115
|
+
interface BaseVoiceConversationResult {
|
|
116
|
+
/**
|
|
117
|
+
* Begin a new session. Requests microphone permission and fetches a
|
|
118
|
+
* signed URL.
|
|
119
|
+
*
|
|
120
|
+
* `suppressFirstMessage` mirrors the option on `restart()` — when
|
|
121
|
+
* `true`, the new session is opened with `overrides.agent.firstMessage = ''`
|
|
122
|
+
* so the agent skips its opening greeting. Useful when the consumer
|
|
123
|
+
* is programmatically reconnecting (e.g. to deliver a one-shot spoken
|
|
124
|
+
* summary) and does not want to hear the configured intro.
|
|
125
|
+
*/
|
|
126
|
+
start: (options?: {
|
|
127
|
+
suppressFirstMessage?: boolean;
|
|
128
|
+
}) => Promise<void>;
|
|
129
|
+
/** End the current session (if any). */
|
|
130
|
+
end: () => void;
|
|
131
|
+
/**
|
|
132
|
+
* Tear down the active session and immediately reconnect. Primarily
|
|
133
|
+
* used as a programmatic barge-in: ElevenLabs doesn't expose a public
|
|
134
|
+
* `interrupt()` on `useConversation`, so stopping the agent mid-
|
|
135
|
+
* utterance requires a fast disconnect + reconnect. When
|
|
136
|
+
* `suppressFirstMessage` is `true` (the default), the new session is
|
|
137
|
+
* started with `overrides.agent.firstMessage = ''` so the agent does
|
|
138
|
+
* not replay its intro. The accumulated transcript is preserved
|
|
139
|
+
* across the reconnect gap.
|
|
140
|
+
*/
|
|
141
|
+
restart: (options?: {
|
|
142
|
+
suppressFirstMessage?: boolean;
|
|
143
|
+
}) => Promise<void>;
|
|
144
|
+
/** `'disconnected' | 'connecting' | 'connected'`. */
|
|
145
|
+
status: 'disconnected' | 'connecting' | 'connected';
|
|
146
|
+
/** Whether the agent is currently speaking. */
|
|
147
|
+
isSpeaking: boolean;
|
|
148
|
+
/** Whether the agent is currently listening. */
|
|
149
|
+
isListening: boolean;
|
|
150
|
+
/** Whether the microphone is currently muted (input audio is gated off). */
|
|
151
|
+
isMuted: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Toggle the microphone mute state without tearing down the session.
|
|
154
|
+
* Wraps `@elevenlabs/react` (or `@elevenlabs/react-native`)'s
|
|
155
|
+
* `setMuted`, which in turn calls `conversation.setMicMuted()`.
|
|
156
|
+
* Muting does not end the WebSocket or release the underlying media
|
|
157
|
+
* stream; it simply stops input audio from being forwarded to the
|
|
158
|
+
* server.
|
|
159
|
+
*/
|
|
160
|
+
setMuted: (isMuted: boolean) => void;
|
|
161
|
+
/** For consumers who want to drive their own visualisation / lipsync. */
|
|
162
|
+
getOutputByteFrequencyData: () => Uint8Array | null;
|
|
163
|
+
/** Imperatively send a contextual update (e.g. "user navigated to X"). */
|
|
164
|
+
sendContextualUpdate: (text: string) => void;
|
|
165
|
+
/**
|
|
166
|
+
* Imperatively inject a user-role message, forcing the agent to take
|
|
167
|
+
* its next turn immediately (rather than waiting for the human to
|
|
168
|
+
* speak). Useful for out-of-band prompts like "please summarise what
|
|
169
|
+
* just happened". The injected text is *not* spoken aloud — the agent
|
|
170
|
+
* treats it as if the user said it.
|
|
171
|
+
*/
|
|
172
|
+
sendUserMessage: (text: string) => void;
|
|
173
|
+
/**
|
|
174
|
+
* Low-level signal that the user is active (typing, clicking) so the
|
|
175
|
+
* agent doesn't try to fill silence. Used as a fallback nudge when we
|
|
176
|
+
* want to keep the session "warm" without forcing a full turn.
|
|
177
|
+
*/
|
|
178
|
+
sendUserActivity: () => void;
|
|
179
|
+
/**
|
|
180
|
+
* Stable conversation id for cross-transport correlation. Returns the
|
|
181
|
+
* caller-supplied `BaseVoiceConversationOptions.conversationId` when
|
|
182
|
+
* one was provided; otherwise mirrors the convai conversation id once
|
|
183
|
+
* the session connects (and is `null` while disconnected).
|
|
184
|
+
*
|
|
185
|
+
* Pass this same value to `useChatConversation({ conversationId })`
|
|
186
|
+
* to stitch a text thread onto the same logical conversation.
|
|
187
|
+
*/
|
|
188
|
+
conversationId: string | null;
|
|
189
|
+
/**
|
|
190
|
+
* The convai-side conversation id reported by ElevenLabs on connect.
|
|
191
|
+
* Always reflects the underlying transport id (or `null` while
|
|
192
|
+
* disconnected) regardless of whether the consumer supplied an id.
|
|
193
|
+
* Useful for log correlation against ElevenLabs dashboards even
|
|
194
|
+
* when the consumer is using their own ids on `conversationId`.
|
|
195
|
+
*/
|
|
196
|
+
convaiConversationId: string | null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export type { BaseVoiceConversationOptions as B, BaseVoiceConversationResult as a };
|