@wix/legends-platform-sdk 1.16.0 → 1.17.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 +48 -42
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,24 +16,23 @@ The SDK exposes two entry points:
|
|
|
16
16
|
|
|
17
17
|
| Entry point | What's inside |
|
|
18
18
|
|---|---|
|
|
19
|
-
| `@wix/legends-platform-sdk` | Types
|
|
19
|
+
| `@wix/legends-platform-sdk` | Types and server-safe hooks (`useTextChat`, `useConversationEvents`, `useMicrophone`, `useSpeaker`, `useCamera`, etc.) — no LiveKit dependency |
|
|
20
20
|
| `@wix/legends-platform-sdk/livekit/sdk` | Everything above **+** `LegendsPlatform`, `useConversation`, `useScreenShare`, `useParticipantTrack`, `useSpeechActivityDetector`, `useAudioLevel` |
|
|
21
21
|
|
|
22
|
-
Use the main entry when you only need types or
|
|
22
|
+
Use the main entry when you only need types or hooks without a LiveKit room (e.g. server-side code or Jest tests). Use `livekit/sdk` for React components and live conversation hooks.
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
26
|
## Quick Start
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Get a namespace API key from the Legends Platform team, then store it in `.env.local`:
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
VITE_LEGENDS_CHAT_ID=your-chat-id
|
|
31
|
+
LEGENDS_API_KEY=lp_your_raw_api_key
|
|
32
|
+
LEGENDS_CHAT_ID=your-chat-id
|
|
34
33
|
```
|
|
35
34
|
|
|
36
|
-
Wrap your app with `LegendsPlatform`
|
|
35
|
+
Wrap your app with `LegendsPlatform`. External apps use `HEADLESS` as the namespace value:
|
|
37
36
|
|
|
38
37
|
```tsx
|
|
39
38
|
import { LegendsPlatform, useConversation, useMicrophone } from '@wix/legends-platform-sdk/livekit/sdk';
|
|
@@ -61,9 +60,9 @@ function VoiceButton() {
|
|
|
61
60
|
export default function App() {
|
|
62
61
|
return (
|
|
63
62
|
<LegendsPlatform
|
|
64
|
-
chatId=
|
|
65
|
-
namespace=
|
|
66
|
-
apiKey=
|
|
63
|
+
chatId="your-chat-id"
|
|
64
|
+
namespace="HEADLESS"
|
|
65
|
+
apiKey="lp_your_api_key"
|
|
67
66
|
>
|
|
68
67
|
<VoiceButton />
|
|
69
68
|
</LegendsPlatform>
|
|
@@ -81,15 +80,14 @@ The root context provider. Must wrap all SDK hooks and components.
|
|
|
81
80
|
|------|------|-------------|
|
|
82
81
|
| `chatId` | `string` | Required. The chat instance ID |
|
|
83
82
|
| `namespace` | `string` | Required. Your namespace |
|
|
84
|
-
| `apiKey` | `string` | API key
|
|
85
|
-
| `personaChatService` | `IPersonaChatService` | Custom service
|
|
83
|
+
| `apiKey` | `string` | Raw namespace API key — pass `lp_...` as-is, the SDK sends it as `Authorization: Api-Key <token>` |
|
|
84
|
+
| `personaChatService` | `IPersonaChatService` | Custom service for advanced use cases (see below) |
|
|
85
|
+
| `tools` | `ToolsRegistry` | Optional client-side tool handlers |
|
|
86
86
|
| `queryClient` | `QueryClient` | Optional TanStack Query client |
|
|
87
87
|
| `children` | `ReactNode` | Required |
|
|
88
88
|
|
|
89
89
|
Either `apiKey` or `personaChatService` must be provided.
|
|
90
90
|
|
|
91
|
-
Pass the raw namespace key as `apiKey`, for example `lp_...`. The SDK sends it as `Authorization: Api-Key <token>`.
|
|
92
|
-
|
|
93
91
|
---
|
|
94
92
|
|
|
95
93
|
### Hooks
|
|
@@ -139,6 +137,21 @@ const { messages, status, send, fetchNext } = useTextChat();
|
|
|
139
137
|
await send({ message: 'Hello' });
|
|
140
138
|
```
|
|
141
139
|
|
|
140
|
+
#### `useTextChatStream(options)`
|
|
141
|
+
|
|
142
|
+
Streaming counterpart to `useTextChat`. Sends messages over SSE and drips the assistant reply into `streamingText` at a steady rate via `requestAnimationFrame`.
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
const { messages, status, send } = useTextChatStream({
|
|
146
|
+
onError: (err) => console.error(err),
|
|
147
|
+
revealMsPerChar: 16, // ms per character, default 16 (~62 chars/s)
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// messages[n].streamStatus === 'streaming' while the reply is in-flight
|
|
151
|
+
const result = await send({ message: 'Hello' });
|
|
152
|
+
// result: { ok: boolean, producedContent: boolean, aborted: boolean }
|
|
153
|
+
```
|
|
154
|
+
|
|
142
155
|
#### `useConversationStatus()`
|
|
143
156
|
|
|
144
157
|
```tsx
|
|
@@ -155,10 +168,10 @@ const { elapsed, remaining } = useConversationTimer();
|
|
|
155
168
|
|
|
156
169
|
#### `useTools()`
|
|
157
170
|
|
|
158
|
-
|
|
171
|
+
Observe client-side tool calls executed by the SDK. Register tool handlers by passing a `tools` registry to `LegendsPlatform`.
|
|
159
172
|
|
|
160
173
|
```tsx
|
|
161
|
-
import { LegendsPlatform, useTools, type ToolsRegistry } from '@wix/legends-platform-sdk';
|
|
174
|
+
import { LegendsPlatform, useTools, type ToolsRegistry } from '@wix/legends-platform-sdk/livekit/sdk';
|
|
162
175
|
|
|
163
176
|
const tools: ToolsRegistry = {
|
|
164
177
|
get_weather: async ({ city }) => {
|
|
@@ -172,25 +185,14 @@ function ToolLog() {
|
|
|
172
185
|
return <pre>{JSON.stringify(calls, null, 2)}</pre>;
|
|
173
186
|
}
|
|
174
187
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
Streaming counterpart to `useTextChat`. Sends messages over SSE and drips the assistant reply into `streamingText` at a steady rate via `requestAnimationFrame`.
|
|
185
|
-
|
|
186
|
-
```tsx
|
|
187
|
-
const { messages, send } = useTextChatStream({
|
|
188
|
-
streamUrl: '/api/chat/stream',
|
|
189
|
-
onError: (err) => console.error(err),
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// messages[n].streamStatus === 'streaming' while the reply is in-flight
|
|
193
|
-
await send({ message: 'Hello' });
|
|
188
|
+
<LegendsPlatform
|
|
189
|
+
chatId="your-chat-id"
|
|
190
|
+
namespace="HEADLESS"
|
|
191
|
+
apiKey="lp_your_api_key"
|
|
192
|
+
tools={tools}
|
|
193
|
+
>
|
|
194
|
+
<ToolLog />
|
|
195
|
+
</LegendsPlatform>
|
|
194
196
|
```
|
|
195
197
|
|
|
196
198
|
#### `useSpeechActivityDetector(options)`
|
|
@@ -211,21 +213,25 @@ useSpeechActivityDetector({
|
|
|
211
213
|
|
|
212
214
|
## Advanced: Custom Service
|
|
213
215
|
|
|
214
|
-
For advanced
|
|
216
|
+
For advanced integration, inject a custom `IPersonaChatService` instead of `apiKey`. Your implementation owns authentication and must forward valid credentials on every request.
|
|
215
217
|
|
|
216
218
|
```tsx
|
|
217
219
|
import { LegendsPlatform } from '@wix/legends-platform-sdk/livekit/sdk';
|
|
218
220
|
import type { IPersonaChatService } from '@wix/legends-platform-sdk';
|
|
219
221
|
|
|
220
222
|
const myService: IPersonaChatService = {
|
|
221
|
-
async createVoiceConversation(params) { ... },
|
|
222
|
-
async createInteractiveConversation(params) { ... },
|
|
223
|
-
async endInteractiveConversation(params) { ... },
|
|
224
|
-
async sendChatMessage(params) { ... },
|
|
225
|
-
async queryChatMessages(params) { ... },
|
|
223
|
+
async createVoiceConversation(params) { /* ... */ },
|
|
224
|
+
async createInteractiveConversation(params) { /* ... */ },
|
|
225
|
+
async endInteractiveConversation(params) { /* ... */ },
|
|
226
|
+
async sendChatMessage(params) { /* ... */ },
|
|
227
|
+
async queryChatMessages(params) { /* ... */ },
|
|
226
228
|
};
|
|
227
229
|
|
|
228
|
-
<LegendsPlatform
|
|
230
|
+
<LegendsPlatform
|
|
231
|
+
chatId="your-chat-id"
|
|
232
|
+
namespace="your-namespace"
|
|
233
|
+
personaChatService={myService}
|
|
234
|
+
>
|
|
229
235
|
...
|
|
230
236
|
</LegendsPlatform>
|
|
231
237
|
```
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.17.0",
|
|
3
3
|
"name": "@wix/legends-platform-sdk",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"wallaby": {
|
|
104
104
|
"autoDetect": true
|
|
105
105
|
},
|
|
106
|
-
"falconPackageHash": "
|
|
106
|
+
"falconPackageHash": "00f289d892a702bdfe7fe6700d234d05983ad90ae438862ab75a68c9"
|
|
107
107
|
}
|