@simfinity/constellation-react 0.0.1 → 0.0.2
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 +31 -51
- package/dist/index.cjs +0 -2
- package/dist/index.d.cts +25 -124
- package/dist/index.d.ts +25 -124
- package/dist/index.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @simfinity/constellation-
|
|
1
|
+
# @simfinity/constellation-react
|
|
2
2
|
|
|
3
3
|
React bindings for Simfinity Constellation Client — persistent real-time LLM chat rooms (text + audio).
|
|
4
4
|
|
|
@@ -20,14 +20,9 @@ It provides context + hooks for lifecycle management.
|
|
|
20
20
|
|
|
21
21
|
## Installation
|
|
22
22
|
```bash
|
|
23
|
-
npm install @simfinity/constellation-
|
|
23
|
+
npm install @simfinity/constellation-react
|
|
24
24
|
# or
|
|
25
|
-
yarn add @simfinity/constellation-
|
|
26
|
-
|
|
27
|
-
# Dependency:
|
|
28
|
-
npm install @simfinity/constellation-client
|
|
29
|
-
# or
|
|
30
|
-
yarn add @simfinity/constellation-client
|
|
25
|
+
yarn add @simfinity/constellation-react
|
|
31
26
|
```
|
|
32
27
|
|
|
33
28
|
## Architecture
|
|
@@ -51,20 +46,13 @@ endSession() → REST call
|
|
|
51
46
|
|
|
52
47
|
```Typescript
|
|
53
48
|
import React, { useEffect } from "react";
|
|
54
|
-
import WebClient from "@simfinity/constellation-client";
|
|
55
49
|
import {
|
|
56
50
|
ConstellationProvider,
|
|
57
|
-
|
|
58
|
-
} from "@simfinity/constellation-
|
|
59
|
-
|
|
60
|
-
const client = new WebClient({
|
|
61
|
-
sessionEndpoint: "https://your-api",
|
|
62
|
-
streamingEndpoint: "wss://your-stream",
|
|
63
|
-
key: "YOUR_SECRET_KEY",
|
|
64
|
-
});
|
|
51
|
+
useConstellationSession
|
|
52
|
+
} from "@simfinity/constellation-react";
|
|
65
53
|
|
|
66
54
|
function Chat() {
|
|
67
|
-
const
|
|
55
|
+
const constellationSession = useConstellationSession();
|
|
68
56
|
|
|
69
57
|
useEffect(() => {
|
|
70
58
|
async function init() {
|
|
@@ -77,22 +65,21 @@ function Chat() {
|
|
|
77
65
|
}
|
|
78
66
|
}
|
|
79
67
|
|
|
80
|
-
await
|
|
81
|
-
|
|
82
|
-
await client.joinSession(false, {
|
|
68
|
+
await constellationSession.startSession(params);
|
|
69
|
+
await constellationSession.joinSession(false, {
|
|
83
70
|
onStreamClosed: console.log,
|
|
84
71
|
onTranscriptResponse: (msg) => {
|
|
85
72
|
console.log("Model:", msg);
|
|
86
73
|
}
|
|
87
|
-
|
|
74
|
+
});
|
|
88
75
|
|
|
89
|
-
|
|
76
|
+
constellationSession.sendText("Hello!");
|
|
90
77
|
}
|
|
91
78
|
|
|
92
79
|
init();
|
|
93
80
|
|
|
94
81
|
return () => {
|
|
95
|
-
|
|
82
|
+
constellationSession.endSession();
|
|
96
83
|
};
|
|
97
84
|
}, []);
|
|
98
85
|
|
|
@@ -101,7 +88,11 @@ function Chat() {
|
|
|
101
88
|
|
|
102
89
|
export default function App() {
|
|
103
90
|
return (
|
|
104
|
-
<ConstellationProvider
|
|
91
|
+
<ConstellationProvider config={{
|
|
92
|
+
sessionEndpoint: "https://your-api",
|
|
93
|
+
streamingEndpoint: "wss://your-stream",
|
|
94
|
+
key: "YOUR_SECRET_KEY"
|
|
95
|
+
}}>
|
|
105
96
|
<Chat />
|
|
106
97
|
</ConstellationProvider>
|
|
107
98
|
);
|
|
@@ -117,53 +108,45 @@ To enable audio:
|
|
|
117
108
|
const params: SessionStartParameters = {
|
|
118
109
|
llmProvider: "openai",
|
|
119
110
|
voiceEnabled: true,
|
|
111
|
+
interruptions: true,
|
|
120
112
|
voiceName: "alloy",
|
|
121
113
|
behaviour: {
|
|
122
114
|
temperature: 0.9,
|
|
123
115
|
instructions: "Just have a nice and casual conversation.",
|
|
124
116
|
}
|
|
125
117
|
}
|
|
126
|
-
await startSession(params);
|
|
127
118
|
|
|
119
|
+
await constellationSession.startSession(params);
|
|
128
120
|
// Join a stream subscribing to audio events
|
|
129
|
-
await joinSession(true, {
|
|
121
|
+
await constellationSession.joinSession(true, {
|
|
130
122
|
onStreamClosed: console.log,
|
|
131
|
-
onAudioResponseStart: () => console.log("Speaking..."),
|
|
132
|
-
onAudioResponseChunk: (chunk) => audioPlayer.enqueue(chunk),
|
|
133
|
-
onAudioResponseEnd: () => console.log("Done")
|
|
134
123
|
});
|
|
124
|
+
|
|
125
|
+
// Use built-in audio capture and playback device
|
|
126
|
+
await constellationSession.audioDevice().in.start();
|
|
127
|
+
constellationSession.audioDevice().in.setMuted(true);
|
|
135
128
|
```
|
|
136
129
|
|
|
137
130
|
Audio requirements:
|
|
138
131
|
|
|
139
132
|
### Input:
|
|
140
|
-
* Format: PCM,
|
|
133
|
+
* Format: PCM, 24k Hertz
|
|
141
134
|
* Encoding: Base64
|
|
142
135
|
* Transcription: handled server-side
|
|
143
136
|
|
|
144
|
-
Send audio:
|
|
145
|
-
|
|
146
|
-
```Typescript
|
|
147
|
-
sendAudioChunk(base64PcmChunk);
|
|
148
|
-
commitAudio();
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
commitAudio() is MANDATORY: server-side VAD (voice activation detection) is not provided.
|
|
152
|
-
|
|
153
|
-
⚠️ Client should always implement audio-input noise detection and explicit commits:
|
|
154
|
-
* Current constellation version does not provide it server-side
|
|
155
|
-
* Avoids continuously streaming audio data which reduces network and token consumption
|
|
156
|
-
* Allows to provide a more responsive experience as VAD introduces a constant delay and is potentially less stable
|
|
157
|
-
|
|
158
137
|
### Output:
|
|
159
138
|
Audio responses are:
|
|
160
139
|
* Format: PCM, 24k Hertz
|
|
161
140
|
* Encoding: Base64
|
|
162
141
|
|
|
142
|
+
Sending audio:
|
|
143
|
+
|
|
144
|
+
Handled internally by the constellationSession package.
|
|
145
|
+
|
|
163
146
|
|
|
164
147
|
## Text and Transcript
|
|
165
148
|
|
|
166
|
-
Text is always enabled in a session. However, the client must provide the appropriate handlers to receive events:
|
|
149
|
+
Text is always enabled in a session. However, the client application must provide the appropriate handlers to receive events:
|
|
167
150
|
```Typescript
|
|
168
151
|
interface EventHandlers {
|
|
169
152
|
// ...
|
|
@@ -177,15 +160,14 @@ interface EventHandlers {
|
|
|
177
160
|
// Pseudo-code:
|
|
178
161
|
|
|
179
162
|
// Text:
|
|
180
|
-
|
|
163
|
+
constellationSession.sendText("Hello");
|
|
181
164
|
|
|
182
165
|
// Triggers:
|
|
183
166
|
// 1) onTranscriptInput(transcript) -> transcript is "Hello"
|
|
184
167
|
// 2) onTranscriptResponse(transcript) -> transcript is the response from the LLM
|
|
185
168
|
|
|
186
169
|
// Audio:
|
|
187
|
-
|
|
188
|
-
constellationClient.commitAudio();
|
|
170
|
+
// ... Internally, constellationSession does 'send audio data + commit audio message' ...
|
|
189
171
|
|
|
190
172
|
// Triggers:
|
|
191
173
|
// 1) onTranscriptInput(transcript) -> transcript is "Hello"
|
|
@@ -226,8 +208,6 @@ joinSession() requires at least:
|
|
|
226
208
|
Optional handlers:
|
|
227
209
|
|
|
228
210
|
* onSessionConfigured: acknowledgment of configureSession call
|
|
229
|
-
* onAudioResponseChunk: audio data chunk of a model audio response
|
|
230
|
-
* onAudioResponseEnd: model has finished streaming an audio response
|
|
231
211
|
* onResponseEnd: model has finished generating and streaming a response
|
|
232
212
|
* onTranscriptInput: the echo of a user text input or transcript of a user audio input
|
|
233
213
|
* onTranscriptInputPart: the echo of a user text input or a piece of transcript of a user audio input
|
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
AudioCaptureConfig: () => AudioCaptureConfig,
|
|
34
33
|
ConstellationProvider: () => ConstellationProvider,
|
|
35
34
|
useAudioCaptureState: () => useAudioCaptureState,
|
|
36
35
|
useAudioPlaybackState: () => useAudioPlaybackState,
|
|
@@ -911,7 +910,6 @@ function useAudioCaptureState(selector) {
|
|
|
911
910
|
}
|
|
912
911
|
// Annotate the CommonJS export names for ESM import in node:
|
|
913
912
|
0 && (module.exports = {
|
|
914
|
-
AudioCaptureConfig,
|
|
915
913
|
ConstellationProvider,
|
|
916
914
|
useAudioCaptureState,
|
|
917
915
|
useAudioPlaybackState,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { WebClientConfig, SessionStartParameters, SessionStats,
|
|
3
|
+
import { WebClientConfig, EventHandlers, SessionStartParameters, SessionStats, SessionConfig } from '@simfinity/constellation-client';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* State machine
|
|
@@ -9,77 +9,6 @@ type AudioPlaybackState = {
|
|
|
9
9
|
playing: boolean;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Audio capturing settings.
|
|
14
|
-
* Includes a basic Voice-Activation-Detection implementation with minimum energy threshold
|
|
15
|
-
* and silence tracking to detect end-of-speech.
|
|
16
|
-
* Default values are provided and should be adequate in most typical setups.
|
|
17
|
-
*/
|
|
18
|
-
declare class AudioCaptureConfig {
|
|
19
|
-
readonly sampleRate = 24000;
|
|
20
|
-
/**
|
|
21
|
-
* Minimum amount of energy for a noise to be considered as actual input and be recorded.
|
|
22
|
-
* - Below it, audio data is silently discarded
|
|
23
|
-
* - Above it, onAudioChunk events containing the audio stream will be fired
|
|
24
|
-
*
|
|
25
|
-
* @remarks
|
|
26
|
-
* This is the main parameter for noise-cancelling
|
|
27
|
-
*/
|
|
28
|
-
silenceThreshold: number;
|
|
29
|
-
/**
|
|
30
|
-
* Once an input was detected, this is the duration of silence required before
|
|
31
|
-
* detecting the end-of-speech and triggering the onSilenceCommit event.
|
|
32
|
-
*
|
|
33
|
-
* IMPORTANT:
|
|
34
|
-
* Internally, duration is computed on audio chunks count, not system clock.
|
|
35
|
-
* A chunk is usually 8ms, therefore to see the effect of a silence duration change, it must be
|
|
36
|
-
* such that the number of chunks count changes e.g. going from 800ms to 810ms increases
|
|
37
|
-
* the chunk count by one.
|
|
38
|
-
*
|
|
39
|
-
* @remarks
|
|
40
|
-
* This is the main voice-activation-detection parameter.
|
|
41
|
-
*/
|
|
42
|
-
silenceDurationMs: number;
|
|
43
|
-
/**
|
|
44
|
-
* Minimum input duration: below it, an input will not trigger an onSilenceCommit event.
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* This is an important interruption parameter: it prevents very short inputs from
|
|
48
|
-
* interrupting an ongoing audio response.
|
|
49
|
-
*/
|
|
50
|
-
minSpeechDurationMs: number;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Client callback functions for the different audio events, provided at start time.
|
|
54
|
-
*/
|
|
55
|
-
type CaptureStartParams = {
|
|
56
|
-
/**
|
|
57
|
-
* Fired when a valid audio chunk containing sound was captured:
|
|
58
|
-
* This event only occurs when confirmed input voice was detected.
|
|
59
|
-
*
|
|
60
|
-
* @param base64Chunk
|
|
61
|
-
*/
|
|
62
|
-
onAudioChunk: (base64Chunk: string) => void;
|
|
63
|
-
/**
|
|
64
|
-
* Fired after a silence period, following a confirmed input and marks the end of the input.
|
|
65
|
-
* This event necessarily occurs after at least one onAudioChunk (most likely many).
|
|
66
|
-
*/
|
|
67
|
-
onSilenceCommit?: () => void;
|
|
68
|
-
/**
|
|
69
|
-
* Fired very early in the voice detection process. This event marks the beginning
|
|
70
|
-
* of an internal process to assess whether the sound captured should convert to an actual input.
|
|
71
|
-
*/
|
|
72
|
-
onSpeechConsidered?: () => void;
|
|
73
|
-
/**
|
|
74
|
-
* Fired when speech is confirmed: marks the end of the process started when onSpeechConsidered was fired.
|
|
75
|
-
* The captured input has finally been determined to be real voice input.
|
|
76
|
-
* Upon receiving this event, it is not yet known what the input is or how long it will be, but there is
|
|
77
|
-
* a guarantee that an input audio message will be produced:
|
|
78
|
-
* - onAudioChunk events can be expected next
|
|
79
|
-
* - When working with conversational-interruptions, this is typically the right moment to trigger them
|
|
80
|
-
*/
|
|
81
|
-
onSpeechConfirmed?: () => void;
|
|
82
|
-
};
|
|
83
12
|
/**
|
|
84
13
|
* State machine
|
|
85
14
|
*/
|
|
@@ -96,26 +25,22 @@ type AudioCaptureState = {
|
|
|
96
25
|
* functions to its descendant components.
|
|
97
26
|
*
|
|
98
27
|
* A ConstellationProvider MUST wrap any component that calls:
|
|
99
|
-
* - useConstellationClient()
|
|
100
28
|
* - useConstellationSession()
|
|
101
29
|
*
|
|
102
|
-
* @param
|
|
30
|
+
* @param config the configuration for underlying WebClient instance from "@simfinity/constellation-client".
|
|
103
31
|
* @param children The DOM descendant components
|
|
104
32
|
*
|
|
105
33
|
* @example
|
|
106
34
|
* ```tsx
|
|
107
|
-
* import
|
|
108
|
-
* import { ConstellationProvider } from "@simfinity/constellation-ui";
|
|
109
|
-
*
|
|
110
|
-
* const client = new WebClient({
|
|
111
|
-
* sessionEndpoint: "https://your-api-endpoint",
|
|
112
|
-
* streamingEndpoint: "wss://your-stream-endpoint",
|
|
113
|
-
* key: "YOUR_SECRET_KEY",
|
|
114
|
-
* });
|
|
35
|
+
* import { ConstellationProvider } from "@simfinity/constellation-react";
|
|
115
36
|
*
|
|
116
37
|
* function App() {
|
|
117
38
|
* return (
|
|
118
|
-
* <ConstellationProvider
|
|
39
|
+
* <ConstellationProvider config={{
|
|
40
|
+
* sessionEndpoint: "https://your-api-endpoint",
|
|
41
|
+
* streamingEndpoint: "wss://your-stream-endpoint",
|
|
42
|
+
* key: "YOUR_SECRET_KEY",
|
|
43
|
+
* }}>
|
|
119
44
|
* <Chat />
|
|
120
45
|
* </ConstellationProvider>
|
|
121
46
|
* );
|
|
@@ -124,7 +49,7 @@ type AudioCaptureState = {
|
|
|
124
49
|
*
|
|
125
50
|
* @remarks
|
|
126
51
|
* This provider does NOT automatically start or join sessions.
|
|
127
|
-
* The lifecycle must be controlled explicitly via
|
|
52
|
+
* The lifecycle must be controlled explicitly via useConstellationSession().
|
|
128
53
|
*/
|
|
129
54
|
declare function ConstellationProvider({ config, children, }: {
|
|
130
55
|
config: WebClientConfig;
|
|
@@ -132,8 +57,8 @@ declare function ConstellationProvider({ config, children, }: {
|
|
|
132
57
|
}): react_jsx_runtime.JSX.Element;
|
|
133
58
|
|
|
134
59
|
/**
|
|
135
|
-
* An instance of constellation
|
|
136
|
-
* If a constellation session is already started & in context, this
|
|
60
|
+
* An instance of constellation session.
|
|
61
|
+
* If a constellation session is already started & in context, this instance
|
|
137
62
|
* can resume interacting with it:
|
|
138
63
|
* Either stop it & start a new session, or keep it alive and re-join it.
|
|
139
64
|
*/
|
|
@@ -160,7 +85,7 @@ interface AudioDevice {
|
|
|
160
85
|
* Hook exposing all lifecycle control functions required to
|
|
161
86
|
* interact with a Constellation session.
|
|
162
87
|
*
|
|
163
|
-
* Internally uses
|
|
88
|
+
* Internally uses a unique constellation client instance maintained in context by the ConstellationProvider.
|
|
164
89
|
*
|
|
165
90
|
* IMPORTANT SESSION ORDER:
|
|
166
91
|
*
|
|
@@ -180,10 +105,13 @@ interface AudioDevice {
|
|
|
180
105
|
* → May not be supported by some LLMs
|
|
181
106
|
* → Can be provided initially in the startSession parameters
|
|
182
107
|
*
|
|
183
|
-
* 4) sendText(...)
|
|
184
|
-
* → Input-sending
|
|
108
|
+
* 4) sendText(...)
|
|
109
|
+
* → Input-sending method for text
|
|
185
110
|
*
|
|
186
|
-
* 5)
|
|
111
|
+
* 5) await audioDevice().in.start()
|
|
112
|
+
* → Start capture sound in an audio session
|
|
113
|
+
*
|
|
114
|
+
* 6) endSession()
|
|
187
115
|
* → Closes the persistent server-side session
|
|
188
116
|
* → For a clean implementation the client should close the stream first
|
|
189
117
|
*
|
|
@@ -192,38 +120,11 @@ interface AudioDevice {
|
|
|
192
120
|
*
|
|
193
121
|
* @throws Error if used outside ConstellationProvider.
|
|
194
122
|
*
|
|
195
|
-
* @returns a
|
|
196
|
-
*
|
|
197
|
-
* startSession
|
|
198
|
-
* - Creates a new persistent session on the server.
|
|
199
|
-
* - Must be called before joinSession().
|
|
200
|
-
*
|
|
201
|
-
* joinSession
|
|
202
|
-
* - Opens the WebSocket stream.
|
|
203
|
-
* - Handlers are required to receive model responses.
|
|
204
|
-
*
|
|
205
|
-
* configureSession
|
|
206
|
-
* - Updates temperature, instructions, max tokens.
|
|
207
|
-
* - Does NOT trigger a response.
|
|
208
|
-
* - The instructions are the "system prompt" giving context to the model
|
|
209
|
-
*
|
|
210
|
-
* sendText
|
|
211
|
-
* - Sends a user text message.
|
|
212
|
-
* - Triggers model response.
|
|
213
|
-
*
|
|
214
|
-
* sendAudioChunk
|
|
215
|
-
* - Sends base64 PCM16 16k Hertz, audio chunk.
|
|
216
|
-
* - Accumulates until commitAudio() or silence detection.
|
|
217
|
-
*
|
|
218
|
-
* commitAudio
|
|
219
|
-
* - Forces model to process accumulated audio and generate a response.
|
|
220
|
-
*
|
|
221
|
-
* endSession
|
|
222
|
-
* - Closes session and frees server resources.
|
|
123
|
+
* @returns a ConstellationSession instance providing lifecycle control methods:
|
|
223
124
|
*
|
|
224
125
|
* @example
|
|
225
126
|
* ```tsx
|
|
226
|
-
* const
|
|
127
|
+
* const constellationSession = useConstellationSession();
|
|
227
128
|
* const params: SessionStartParameters = {
|
|
228
129
|
* llmProvider: "openai",
|
|
229
130
|
* voiceEnabled: false,
|
|
@@ -233,13 +134,13 @@ interface AudioDevice {
|
|
|
233
134
|
* instructions: "Just have a nice and casual conversation.",
|
|
234
135
|
* }
|
|
235
136
|
* }
|
|
236
|
-
* await
|
|
237
|
-
* await
|
|
137
|
+
* await constellationSession.startSession(params);
|
|
138
|
+
* await constellationSession.joinSession(false, {
|
|
238
139
|
* onStreamClosed: () => console.log,
|
|
239
140
|
* onTranscriptResponse: (text) => console.log(text),
|
|
240
141
|
* });
|
|
241
|
-
*
|
|
242
|
-
*
|
|
142
|
+
* constellationSession.sendText("Hello world");
|
|
143
|
+
* constellationSession.endSession();
|
|
243
144
|
* ```
|
|
244
145
|
*/
|
|
245
146
|
declare function useConstellationSession(): ConstellationSession;
|
|
@@ -258,4 +159,4 @@ declare function useAudioPlaybackState<T>(selector: (state: AudioPlaybackState)
|
|
|
258
159
|
*/
|
|
259
160
|
declare function useAudioCaptureState<T>(selector: (state: AudioCaptureState) => T): T;
|
|
260
161
|
|
|
261
|
-
export {
|
|
162
|
+
export { type AudioCaptureState, type AudioDevice, type AudioPlaybackState, type ConstellationEventHandlers, ConstellationProvider, type ConstellationSession, useAudioCaptureState, useAudioPlaybackState, useConstellationSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { WebClientConfig, SessionStartParameters, SessionStats,
|
|
3
|
+
import { WebClientConfig, EventHandlers, SessionStartParameters, SessionStats, SessionConfig } from '@simfinity/constellation-client';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* State machine
|
|
@@ -9,77 +9,6 @@ type AudioPlaybackState = {
|
|
|
9
9
|
playing: boolean;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Audio capturing settings.
|
|
14
|
-
* Includes a basic Voice-Activation-Detection implementation with minimum energy threshold
|
|
15
|
-
* and silence tracking to detect end-of-speech.
|
|
16
|
-
* Default values are provided and should be adequate in most typical setups.
|
|
17
|
-
*/
|
|
18
|
-
declare class AudioCaptureConfig {
|
|
19
|
-
readonly sampleRate = 24000;
|
|
20
|
-
/**
|
|
21
|
-
* Minimum amount of energy for a noise to be considered as actual input and be recorded.
|
|
22
|
-
* - Below it, audio data is silently discarded
|
|
23
|
-
* - Above it, onAudioChunk events containing the audio stream will be fired
|
|
24
|
-
*
|
|
25
|
-
* @remarks
|
|
26
|
-
* This is the main parameter for noise-cancelling
|
|
27
|
-
*/
|
|
28
|
-
silenceThreshold: number;
|
|
29
|
-
/**
|
|
30
|
-
* Once an input was detected, this is the duration of silence required before
|
|
31
|
-
* detecting the end-of-speech and triggering the onSilenceCommit event.
|
|
32
|
-
*
|
|
33
|
-
* IMPORTANT:
|
|
34
|
-
* Internally, duration is computed on audio chunks count, not system clock.
|
|
35
|
-
* A chunk is usually 8ms, therefore to see the effect of a silence duration change, it must be
|
|
36
|
-
* such that the number of chunks count changes e.g. going from 800ms to 810ms increases
|
|
37
|
-
* the chunk count by one.
|
|
38
|
-
*
|
|
39
|
-
* @remarks
|
|
40
|
-
* This is the main voice-activation-detection parameter.
|
|
41
|
-
*/
|
|
42
|
-
silenceDurationMs: number;
|
|
43
|
-
/**
|
|
44
|
-
* Minimum input duration: below it, an input will not trigger an onSilenceCommit event.
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* This is an important interruption parameter: it prevents very short inputs from
|
|
48
|
-
* interrupting an ongoing audio response.
|
|
49
|
-
*/
|
|
50
|
-
minSpeechDurationMs: number;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Client callback functions for the different audio events, provided at start time.
|
|
54
|
-
*/
|
|
55
|
-
type CaptureStartParams = {
|
|
56
|
-
/**
|
|
57
|
-
* Fired when a valid audio chunk containing sound was captured:
|
|
58
|
-
* This event only occurs when confirmed input voice was detected.
|
|
59
|
-
*
|
|
60
|
-
* @param base64Chunk
|
|
61
|
-
*/
|
|
62
|
-
onAudioChunk: (base64Chunk: string) => void;
|
|
63
|
-
/**
|
|
64
|
-
* Fired after a silence period, following a confirmed input and marks the end of the input.
|
|
65
|
-
* This event necessarily occurs after at least one onAudioChunk (most likely many).
|
|
66
|
-
*/
|
|
67
|
-
onSilenceCommit?: () => void;
|
|
68
|
-
/**
|
|
69
|
-
* Fired very early in the voice detection process. This event marks the beginning
|
|
70
|
-
* of an internal process to assess whether the sound captured should convert to an actual input.
|
|
71
|
-
*/
|
|
72
|
-
onSpeechConsidered?: () => void;
|
|
73
|
-
/**
|
|
74
|
-
* Fired when speech is confirmed: marks the end of the process started when onSpeechConsidered was fired.
|
|
75
|
-
* The captured input has finally been determined to be real voice input.
|
|
76
|
-
* Upon receiving this event, it is not yet known what the input is or how long it will be, but there is
|
|
77
|
-
* a guarantee that an input audio message will be produced:
|
|
78
|
-
* - onAudioChunk events can be expected next
|
|
79
|
-
* - When working with conversational-interruptions, this is typically the right moment to trigger them
|
|
80
|
-
*/
|
|
81
|
-
onSpeechConfirmed?: () => void;
|
|
82
|
-
};
|
|
83
12
|
/**
|
|
84
13
|
* State machine
|
|
85
14
|
*/
|
|
@@ -96,26 +25,22 @@ type AudioCaptureState = {
|
|
|
96
25
|
* functions to its descendant components.
|
|
97
26
|
*
|
|
98
27
|
* A ConstellationProvider MUST wrap any component that calls:
|
|
99
|
-
* - useConstellationClient()
|
|
100
28
|
* - useConstellationSession()
|
|
101
29
|
*
|
|
102
|
-
* @param
|
|
30
|
+
* @param config the configuration for underlying WebClient instance from "@simfinity/constellation-client".
|
|
103
31
|
* @param children The DOM descendant components
|
|
104
32
|
*
|
|
105
33
|
* @example
|
|
106
34
|
* ```tsx
|
|
107
|
-
* import
|
|
108
|
-
* import { ConstellationProvider } from "@simfinity/constellation-ui";
|
|
109
|
-
*
|
|
110
|
-
* const client = new WebClient({
|
|
111
|
-
* sessionEndpoint: "https://your-api-endpoint",
|
|
112
|
-
* streamingEndpoint: "wss://your-stream-endpoint",
|
|
113
|
-
* key: "YOUR_SECRET_KEY",
|
|
114
|
-
* });
|
|
35
|
+
* import { ConstellationProvider } from "@simfinity/constellation-react";
|
|
115
36
|
*
|
|
116
37
|
* function App() {
|
|
117
38
|
* return (
|
|
118
|
-
* <ConstellationProvider
|
|
39
|
+
* <ConstellationProvider config={{
|
|
40
|
+
* sessionEndpoint: "https://your-api-endpoint",
|
|
41
|
+
* streamingEndpoint: "wss://your-stream-endpoint",
|
|
42
|
+
* key: "YOUR_SECRET_KEY",
|
|
43
|
+
* }}>
|
|
119
44
|
* <Chat />
|
|
120
45
|
* </ConstellationProvider>
|
|
121
46
|
* );
|
|
@@ -124,7 +49,7 @@ type AudioCaptureState = {
|
|
|
124
49
|
*
|
|
125
50
|
* @remarks
|
|
126
51
|
* This provider does NOT automatically start or join sessions.
|
|
127
|
-
* The lifecycle must be controlled explicitly via
|
|
52
|
+
* The lifecycle must be controlled explicitly via useConstellationSession().
|
|
128
53
|
*/
|
|
129
54
|
declare function ConstellationProvider({ config, children, }: {
|
|
130
55
|
config: WebClientConfig;
|
|
@@ -132,8 +57,8 @@ declare function ConstellationProvider({ config, children, }: {
|
|
|
132
57
|
}): react_jsx_runtime.JSX.Element;
|
|
133
58
|
|
|
134
59
|
/**
|
|
135
|
-
* An instance of constellation
|
|
136
|
-
* If a constellation session is already started & in context, this
|
|
60
|
+
* An instance of constellation session.
|
|
61
|
+
* If a constellation session is already started & in context, this instance
|
|
137
62
|
* can resume interacting with it:
|
|
138
63
|
* Either stop it & start a new session, or keep it alive and re-join it.
|
|
139
64
|
*/
|
|
@@ -160,7 +85,7 @@ interface AudioDevice {
|
|
|
160
85
|
* Hook exposing all lifecycle control functions required to
|
|
161
86
|
* interact with a Constellation session.
|
|
162
87
|
*
|
|
163
|
-
* Internally uses
|
|
88
|
+
* Internally uses a unique constellation client instance maintained in context by the ConstellationProvider.
|
|
164
89
|
*
|
|
165
90
|
* IMPORTANT SESSION ORDER:
|
|
166
91
|
*
|
|
@@ -180,10 +105,13 @@ interface AudioDevice {
|
|
|
180
105
|
* → May not be supported by some LLMs
|
|
181
106
|
* → Can be provided initially in the startSession parameters
|
|
182
107
|
*
|
|
183
|
-
* 4) sendText(...)
|
|
184
|
-
* → Input-sending
|
|
108
|
+
* 4) sendText(...)
|
|
109
|
+
* → Input-sending method for text
|
|
185
110
|
*
|
|
186
|
-
* 5)
|
|
111
|
+
* 5) await audioDevice().in.start()
|
|
112
|
+
* → Start capture sound in an audio session
|
|
113
|
+
*
|
|
114
|
+
* 6) endSession()
|
|
187
115
|
* → Closes the persistent server-side session
|
|
188
116
|
* → For a clean implementation the client should close the stream first
|
|
189
117
|
*
|
|
@@ -192,38 +120,11 @@ interface AudioDevice {
|
|
|
192
120
|
*
|
|
193
121
|
* @throws Error if used outside ConstellationProvider.
|
|
194
122
|
*
|
|
195
|
-
* @returns a
|
|
196
|
-
*
|
|
197
|
-
* startSession
|
|
198
|
-
* - Creates a new persistent session on the server.
|
|
199
|
-
* - Must be called before joinSession().
|
|
200
|
-
*
|
|
201
|
-
* joinSession
|
|
202
|
-
* - Opens the WebSocket stream.
|
|
203
|
-
* - Handlers are required to receive model responses.
|
|
204
|
-
*
|
|
205
|
-
* configureSession
|
|
206
|
-
* - Updates temperature, instructions, max tokens.
|
|
207
|
-
* - Does NOT trigger a response.
|
|
208
|
-
* - The instructions are the "system prompt" giving context to the model
|
|
209
|
-
*
|
|
210
|
-
* sendText
|
|
211
|
-
* - Sends a user text message.
|
|
212
|
-
* - Triggers model response.
|
|
213
|
-
*
|
|
214
|
-
* sendAudioChunk
|
|
215
|
-
* - Sends base64 PCM16 16k Hertz, audio chunk.
|
|
216
|
-
* - Accumulates until commitAudio() or silence detection.
|
|
217
|
-
*
|
|
218
|
-
* commitAudio
|
|
219
|
-
* - Forces model to process accumulated audio and generate a response.
|
|
220
|
-
*
|
|
221
|
-
* endSession
|
|
222
|
-
* - Closes session and frees server resources.
|
|
123
|
+
* @returns a ConstellationSession instance providing lifecycle control methods:
|
|
223
124
|
*
|
|
224
125
|
* @example
|
|
225
126
|
* ```tsx
|
|
226
|
-
* const
|
|
127
|
+
* const constellationSession = useConstellationSession();
|
|
227
128
|
* const params: SessionStartParameters = {
|
|
228
129
|
* llmProvider: "openai",
|
|
229
130
|
* voiceEnabled: false,
|
|
@@ -233,13 +134,13 @@ interface AudioDevice {
|
|
|
233
134
|
* instructions: "Just have a nice and casual conversation.",
|
|
234
135
|
* }
|
|
235
136
|
* }
|
|
236
|
-
* await
|
|
237
|
-
* await
|
|
137
|
+
* await constellationSession.startSession(params);
|
|
138
|
+
* await constellationSession.joinSession(false, {
|
|
238
139
|
* onStreamClosed: () => console.log,
|
|
239
140
|
* onTranscriptResponse: (text) => console.log(text),
|
|
240
141
|
* });
|
|
241
|
-
*
|
|
242
|
-
*
|
|
142
|
+
* constellationSession.sendText("Hello world");
|
|
143
|
+
* constellationSession.endSession();
|
|
243
144
|
* ```
|
|
244
145
|
*/
|
|
245
146
|
declare function useConstellationSession(): ConstellationSession;
|
|
@@ -258,4 +159,4 @@ declare function useAudioPlaybackState<T>(selector: (state: AudioPlaybackState)
|
|
|
258
159
|
*/
|
|
259
160
|
declare function useAudioCaptureState<T>(selector: (state: AudioCaptureState) => T): T;
|
|
260
161
|
|
|
261
|
-
export {
|
|
162
|
+
export { type AudioCaptureState, type AudioDevice, type AudioPlaybackState, type ConstellationEventHandlers, ConstellationProvider, type ConstellationSession, useAudioCaptureState, useAudioPlaybackState, useConstellationSession };
|
package/dist/index.js
CHANGED