@voice-session/web 0.1.0 → 0.2.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 +6 -17
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -7
- package/dist/index.d.ts +2 -7
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Browser SDK for starting a realtime voice session with an AI assistant.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Mint `{ url, token }` on **your server**. Pass those values into the SDK. Never put the API key in frontend code.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -12,8 +12,6 @@ npm i @voice-session/web
|
|
|
12
12
|
|
|
13
13
|
## Server
|
|
14
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
15
|
```bash
|
|
18
16
|
curl -X POST "$API_HOST/api/user/realtime/session" \
|
|
19
17
|
-H "Authorization: Bearer $API_KEY" \
|
|
@@ -26,21 +24,20 @@ Response:
|
|
|
26
24
|
```json
|
|
27
25
|
{
|
|
28
26
|
"id": "session-uuid",
|
|
29
|
-
"
|
|
27
|
+
"url": "wss://example.invalid",
|
|
28
|
+
"token": "short-lived-token",
|
|
29
|
+
"expires_in": 900
|
|
30
30
|
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
Tokens expire in 15 minutes.
|
|
33
|
+
Tokens expire in 15 minutes. Start the browser session before they expire.
|
|
34
34
|
|
|
35
35
|
## Browser
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
38
|
import { RealtimeSession } from "@voice-session/web";
|
|
39
39
|
|
|
40
|
-
const session = new RealtimeSession({
|
|
41
|
-
baseUrl: "https://api.example.com",
|
|
42
|
-
clientToken,
|
|
43
|
-
});
|
|
40
|
+
const session = new RealtimeSession({ url, token });
|
|
44
41
|
|
|
45
42
|
session.on("agent_state", (state) => {
|
|
46
43
|
console.log(state);
|
|
@@ -70,14 +67,6 @@ await session.end();
|
|
|
70
67
|
| `ended` | none |
|
|
71
68
|
| `error` | `Error` |
|
|
72
69
|
|
|
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
70
|
## License
|
|
82
71
|
|
|
83
72
|
MIT. See `licenses/` for notices covering bundled third-party code.
|