@centive/aria-sdk 0.1.0 → 0.1.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 +83 -23
- package/dist/components/AriaWidget.d.ts.map +1 -1
- package/dist/context/AriaProvider.d.ts.map +1 -1
- package/dist/{index-C78Qd1Uk.js → index-6g04Wt4g.js} +862 -804
- package/dist/index-6g04Wt4g.js.map +1 -0
- package/dist/{index-DyttThh2.js → index-CWi95RnT.js} +3 -3
- package/dist/{index-DyttThh2.js.map → index-CWi95RnT.js.map} +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +29 -11
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/index-C78Qd1Uk.js.map +0 -1
package/README.md
CHANGED
|
@@ -61,23 +61,31 @@ import { AriaProvider, AriaAssistant, AriaTriggerButton } from '@centive/aria-sd
|
|
|
61
61
|
import '@centive/aria-sdk/styles.css';
|
|
62
62
|
|
|
63
63
|
function App() {
|
|
64
|
+
// Note: Persona configuration is now handled by the backend
|
|
65
|
+
// The backend determines which persona to display based on user context
|
|
64
66
|
const config = {
|
|
65
67
|
websocketUrl: 'ws://localhost:8000/ws',
|
|
66
|
-
userId: 'user_123', // Required for message accumulation
|
|
68
|
+
userId: 'user_123', // Required for backend persona selection & message accumulation
|
|
67
69
|
theme: 'light', // or 'dark'
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
avatarId: 'your-avatar-id',
|
|
71
|
-
voiceId: 'your-voice-id',
|
|
72
|
-
llmId: 'your-llm-id',
|
|
73
|
-
systemPrompt: 'You are Aria, a helpful AI assistant.',
|
|
74
|
-
},
|
|
70
|
+
|
|
71
|
+
// WebSocket event callbacks
|
|
75
72
|
onWebSocketEvent: (event) => {
|
|
76
73
|
console.log('Incoming WebSocket event:', event);
|
|
77
74
|
},
|
|
78
75
|
onError: (error) => console.error('Error:', error),
|
|
79
76
|
onSessionReady: () => console.log('Session ready!'),
|
|
80
77
|
onConnectionStateChange: (connected) => console.log('Connected:', connected),
|
|
78
|
+
|
|
79
|
+
// Message accumulation callbacks
|
|
80
|
+
onMessageHistoryAck: (messageCount) => {
|
|
81
|
+
console.log(`Message history saved: ${messageCount} messages`);
|
|
82
|
+
},
|
|
83
|
+
onSessionEndAck: (savedCount) => {
|
|
84
|
+
console.log(`Session ended: ${savedCount} messages saved`);
|
|
85
|
+
},
|
|
86
|
+
onSessionEndError: (error, errorType) => {
|
|
87
|
+
console.error(`Session end failed: ${errorType} - ${error}`);
|
|
88
|
+
},
|
|
81
89
|
};
|
|
82
90
|
|
|
83
91
|
return (
|
|
@@ -105,14 +113,20 @@ import '@centive/aria-sdk/styles.css';
|
|
|
105
113
|
### 3. Set Up Backend WebSocket Server
|
|
106
114
|
|
|
107
115
|
The SDK requires a backend WebSocket server that:
|
|
116
|
+
- **Configures AI persona** based on user context (role, permissions, etc.)
|
|
108
117
|
- Handles session token generation via Anam AI API
|
|
109
118
|
- Manages WebSocket connections
|
|
110
119
|
- Accumulates and persists messages
|
|
111
120
|
- Handles trigger events
|
|
112
121
|
|
|
122
|
+
**Important:** Persona configuration (avatar, voice, LLM, system prompt) is now controlled by the backend, not the frontend. This allows for:
|
|
123
|
+
- Security: Frontend cannot manipulate AI behavior
|
|
124
|
+
- Flexibility: Change personas based on user roles, context, or A/B testing
|
|
125
|
+
- Centralization: Manage all persona configurations in one place
|
|
126
|
+
|
|
113
127
|
See the included example servers:
|
|
114
|
-
- `example-ws-server.js` -
|
|
115
|
-
- `example-server.js` -
|
|
128
|
+
- `example-ws-server.js` - WebSocket server with backend persona configuration
|
|
129
|
+
- `example-server.js` - HTTP server for session tokens
|
|
116
130
|
|
|
117
131
|
## 📖 Core Concepts
|
|
118
132
|
|
|
@@ -219,29 +233,53 @@ function MyComponent() {
|
|
|
219
233
|
```typescript
|
|
220
234
|
interface AriaSDKConfig {
|
|
221
235
|
websocketUrl: string; // WebSocket server URL
|
|
222
|
-
|
|
223
|
-
userId?: string; // User ID for message accumulation
|
|
236
|
+
userId?: string; // User ID for backend persona selection & message accumulation
|
|
224
237
|
theme?: 'light' | 'dark'; // Initial theme (default: 'light')
|
|
225
238
|
triggerLabel?: string; // Button label text
|
|
239
|
+
|
|
240
|
+
// Event callbacks
|
|
226
241
|
onError?: (error: Error) => void;
|
|
227
242
|
onSessionReady?: () => void;
|
|
228
243
|
onConnectionStateChange?: (connected: boolean) => void;
|
|
229
244
|
onWebSocketEvent?: (event: any) => void;
|
|
245
|
+
|
|
246
|
+
// Message accumulation callbacks
|
|
247
|
+
onMessageHistoryAck?: (messageCount: number) => void;
|
|
248
|
+
onMessageStreamAck?: () => void;
|
|
249
|
+
onSessionEndAck?: (savedCount: number) => void;
|
|
250
|
+
onSessionEndError?: (error: string, errorType: string) => void;
|
|
230
251
|
}
|
|
231
252
|
```
|
|
232
253
|
|
|
233
|
-
###
|
|
254
|
+
### Backend Persona Configuration
|
|
234
255
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
256
|
+
**Persona configuration is now handled entirely by your backend server.** This provides:
|
|
257
|
+
|
|
258
|
+
- **Security**: Frontend cannot manipulate AI behavior or system prompts
|
|
259
|
+
- **Flexibility**: Dynamically select personas based on user roles, context, subscription tier, or A/B testing
|
|
260
|
+
- **Centralization**: Manage all persona configurations in one secure location
|
|
261
|
+
|
|
262
|
+
Your backend should configure personas when creating Anam sessions:
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
// Backend example: Configure persona based on user context
|
|
266
|
+
const getPersonaConfig = (userId, userRole) => {
|
|
267
|
+
// Your business logic here
|
|
268
|
+
return {
|
|
269
|
+
name: 'Aria - AI Assistant',
|
|
270
|
+
avatarId: 'your-avatar-id',
|
|
271
|
+
voiceId: 'your-voice-id',
|
|
272
|
+
llmId: 'your-llm-id',
|
|
273
|
+
systemPrompt: 'You are Aria, a helpful AI assistant.',
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// Use this config when calling Anam AI API
|
|
278
|
+
const personaConfig = getPersonaConfig(userId, userRole);
|
|
243
279
|
```
|
|
244
280
|
|
|
281
|
+
See `example-ws-server.js` for a complete implementation.
|
|
282
|
+
|
|
245
283
|
## 🌐 WebSocket Events
|
|
246
284
|
|
|
247
285
|
### Automatic Session Trigger (Backend → Frontend)
|
|
@@ -330,10 +368,10 @@ function CustomController() {
|
|
|
330
368
|
### Custom Event Handling
|
|
331
369
|
|
|
332
370
|
```tsx
|
|
371
|
+
// Note: Persona configuration is handled by the backend
|
|
333
372
|
const config = {
|
|
334
373
|
websocketUrl: 'ws://localhost:8000/ws',
|
|
335
|
-
userId: 'user_123',
|
|
336
|
-
personaConfig: { /* ... */ },
|
|
374
|
+
userId: 'user_123', // Backend uses this for persona selection
|
|
337
375
|
|
|
338
376
|
onWebSocketEvent: (event) => {
|
|
339
377
|
if (event.data.eventType === 'incoming_call') {
|
|
@@ -349,6 +387,26 @@ const config = {
|
|
|
349
387
|
onError: (error) => {
|
|
350
388
|
captureError(error);
|
|
351
389
|
},
|
|
390
|
+
|
|
391
|
+
// Message accumulation callbacks
|
|
392
|
+
onMessageHistoryAck: (messageCount) => {
|
|
393
|
+
console.log(`Conversation saved: ${messageCount} messages`);
|
|
394
|
+
updateUI({ messagesSaved: true });
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
onSessionEndAck: (savedCount) => {
|
|
398
|
+
console.log(`Session completed: ${savedCount} messages persisted`);
|
|
399
|
+
showSuccessNotification('Conversation saved successfully');
|
|
400
|
+
},
|
|
401
|
+
|
|
402
|
+
onSessionEndError: (error, errorType) => {
|
|
403
|
+
console.error(`Failed to save: ${errorType}`, error);
|
|
404
|
+
if (errorType === 'CIRCUIT_BREAKER_OPEN') {
|
|
405
|
+
showWarning('Saving temporarily unavailable, will retry automatically');
|
|
406
|
+
} else {
|
|
407
|
+
showError('Failed to save conversation');
|
|
408
|
+
}
|
|
409
|
+
},
|
|
352
410
|
};
|
|
353
411
|
```
|
|
354
412
|
|
|
@@ -404,6 +462,8 @@ function SessionMonitor() {
|
|
|
404
462
|
## 📚 Documentation
|
|
405
463
|
|
|
406
464
|
For more detailed documentation, see:
|
|
465
|
+
- [Type Reference](./TYPE_REFERENCE.md) - Complete TypeScript type reference
|
|
466
|
+
- [WebSocket Events Guide](./WEBSOCKET_EVENTS.md) - Complete WebSocket message specification
|
|
407
467
|
- [WebSocket Guide](./WEBSOCKET_GUIDE.md) - WebSocket integration details
|
|
408
468
|
- [Publishing Guide](./PUBLISHING_GUIDE.md) - npm publishing instructions
|
|
409
469
|
- [Setup Summary](./SETUP_SUMMARY.md) - Complete setup overview
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AriaWidget.d.ts","sourceRoot":"","sources":["../../src/components/AriaWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAQjD,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"AriaWidget.d.ts","sourceRoot":"","sources":["../../src/components/AriaWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAQjD,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA+NhD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AriaProvider.d.ts","sourceRoot":"","sources":["../../src/context/AriaProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"AriaProvider.d.ts","sourceRoot":"","sources":["../../src/context/AriaProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAmBxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAK7C,UAAU,iBAAiB;IACzB,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAgGD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAugBpD,CAAC"}
|