@voice-session/web 0.1.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/LICENSE +21 -0
- package/README.md +83 -0
- package/dist/index.cjs +41 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/licenses/APACHE-2.0.txt +202 -0
- package/licenses/NOTICE +7 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Realtime voice session SDK
|
|
2
|
+
|
|
3
|
+
Browser SDK for starting a realtime voice session with an AI assistant.
|
|
4
|
+
|
|
5
|
+
The package talks to **your API host**. Pass `baseUrl` yourself. There is no default host.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i @voice-session/web
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Server
|
|
14
|
+
|
|
15
|
+
Your backend mints a short-lived `client_token` with your API key, then the browser SDK exchanges it. Never put the API key in frontend code.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
curl -X POST "$API_HOST/api/user/realtime/session" \
|
|
19
|
+
-H "Authorization: Bearer $API_KEY" \
|
|
20
|
+
-H "Content-Type: application/json" \
|
|
21
|
+
-d '{"assistant_id":"ASSISTANT_UUID"}'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Response:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"id": "session-uuid",
|
|
29
|
+
"client_token": "opaque-token"
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Tokens expire in 15 minutes. Pass `baseUrl` as the same API host (scheme + host, no trailing path).
|
|
34
|
+
|
|
35
|
+
## Browser
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { RealtimeSession } from "@voice-session/web";
|
|
39
|
+
|
|
40
|
+
const session = new RealtimeSession({
|
|
41
|
+
baseUrl: "https://api.example.com",
|
|
42
|
+
clientToken,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
session.on("agent_state", (state) => {
|
|
46
|
+
console.log(state);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
session.on("transcript", ({ role, text, final }) => {
|
|
50
|
+
if (final) {
|
|
51
|
+
console.log(role, text);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
session.on("error", (error) => {
|
|
56
|
+
console.error(error.message);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await session.start({ microphone: true });
|
|
60
|
+
await session.end();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Events
|
|
64
|
+
|
|
65
|
+
| Event | Payload |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| `transcript` | `{ role: "user" \| "assistant", text: string, final: boolean }` |
|
|
68
|
+
| `agent_state` | `"connecting" \| "listening" \| "thinking" \| "speaking" \| "ended"` |
|
|
69
|
+
| `level` | `number` (0 to 1, remote audio level) |
|
|
70
|
+
| `ended` | none |
|
|
71
|
+
| `error` | `Error` |
|
|
72
|
+
|
|
73
|
+
### Direct credentials
|
|
74
|
+
|
|
75
|
+
If your backend already exchanged the session and you have `{ url, token }`, you can skip the client-token hop:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const session = new RealtimeSession({ url, token });
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT. See `licenses/` for notices covering bundled third-party code.
|