@convai/web-sdk 1.2.1-beta.1 → 1.2.2-beta.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 +110 -14
- package/dist/core/ConvaiClient.d.ts +33 -1
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +117 -19
- package/dist/core/ConvaiClient.js.map +1 -1
- package/dist/core/MemoryManager.d.ts +179 -0
- package/dist/core/MemoryManager.d.ts.map +1 -0
- package/dist/core/MemoryManager.js +281 -0
- package/dist/core/MemoryManager.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/types.d.ts +306 -5
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +58 -1
- package/dist/core/types.js.map +1 -1
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.js +1 -1
- package/dist/react/components/ConvaiWidget.js.map +1 -1
- package/dist/react/hooks/useCharacterInfo.d.ts +1 -1
- package/dist/react/hooks/useCharacterInfo.d.ts.map +1 -1
- package/dist/react/hooks/useCharacterInfo.js +11 -5
- package/dist/react/hooks/useCharacterInfo.js.map +1 -1
- package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
- package/dist/react/hooks/useConvaiClient.js +4 -1
- package/dist/react/hooks/useConvaiClient.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
- package/dist/vanilla/ConvaiWidget.js +6 -4
- package/dist/vanilla/ConvaiWidget.js.map +1 -1
- package/dist/vanilla/types.d.ts +3 -1
- package/dist/vanilla/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/types/index.d.ts +0 -421
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convai Memory Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages long-term memories for characters using the Convai Memory API.
|
|
5
|
+
* All memory operations are scoped to a (character_id, end_user_id) pair.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const memoryManager = new MemoryManager(apiKey, characterId, endUserId);
|
|
10
|
+
*
|
|
11
|
+
* // Add memories
|
|
12
|
+
* const result = await memoryManager.addMemories([
|
|
13
|
+
* "User prefers outdoor activities",
|
|
14
|
+
* "User is allergic to peanuts"
|
|
15
|
+
* ]);
|
|
16
|
+
*
|
|
17
|
+
* // List memories
|
|
18
|
+
* const memories = await memoryManager.listMemories({ page: 1, pageSize: 50 });
|
|
19
|
+
*
|
|
20
|
+
* // Get a specific memory
|
|
21
|
+
* const memory = await memoryManager.getMemory(memoryId);
|
|
22
|
+
*
|
|
23
|
+
* // Delete a memory
|
|
24
|
+
* await memoryManager.deleteMemory(memoryId);
|
|
25
|
+
*
|
|
26
|
+
* // Delete all memories
|
|
27
|
+
* await memoryManager.deleteAllMemories();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import { MemoryAddResponse, MemoryListResponse, MemoryGetResponse, MemoryDeleteResponse, MemoryDeleteAllResponse } from './types';
|
|
31
|
+
/**
|
|
32
|
+
* MemoryManager class for handling Convai Memory API operations.
|
|
33
|
+
* Provides methods to add, list, get, and delete memories for a character.
|
|
34
|
+
*/
|
|
35
|
+
export declare class MemoryManager {
|
|
36
|
+
private apiKey;
|
|
37
|
+
private authToken;
|
|
38
|
+
private characterId;
|
|
39
|
+
private endUserId;
|
|
40
|
+
private baseUrl;
|
|
41
|
+
/**
|
|
42
|
+
* Create a new MemoryManager instance
|
|
43
|
+
*
|
|
44
|
+
* @param apiKeyOrAuthToken - Convai API key or auth token (required)
|
|
45
|
+
* @param characterId - Character UUID (required)
|
|
46
|
+
* @param endUserId - End user identifier (required)
|
|
47
|
+
* @param baseUrl - Base URL for Convai API (default: https://api.convai.com)
|
|
48
|
+
* @param useAuthToken - If true, treats first parameter as auth token instead of API key (default: false)
|
|
49
|
+
*/
|
|
50
|
+
constructor(apiKeyOrAuthToken: string, characterId: string, endUserId: string, baseUrl?: string, useAuthToken?: boolean);
|
|
51
|
+
/**
|
|
52
|
+
* Make an authenticated request to the Convai Memory API
|
|
53
|
+
*/
|
|
54
|
+
private makeRequest;
|
|
55
|
+
/**
|
|
56
|
+
* Add one or more memory strings
|
|
57
|
+
*
|
|
58
|
+
* @param memories - Array of memory strings to add (required, non-empty)
|
|
59
|
+
* @returns Promise resolving to the add response with memory IDs
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const result = await memoryManager.addMemories([
|
|
64
|
+
* "User prefers outdoor activities",
|
|
65
|
+
* "User is allergic to peanuts"
|
|
66
|
+
* ]);
|
|
67
|
+
*
|
|
68
|
+
* result.memories.forEach(memory => {
|
|
69
|
+
* console.log(`Added memory ${memory.id}: ${memory.memory}`);
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
addMemories(memories: string[]): Promise<MemoryAddResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* List memories with pagination
|
|
76
|
+
*
|
|
77
|
+
* @param options - Pagination options
|
|
78
|
+
* @param options.page - Page number (default: 1, clamped to 1-1000)
|
|
79
|
+
* @param options.pageSize - Number of memories per page (default: 50, clamped to 1-100)
|
|
80
|
+
* @returns Promise resolving to paginated list of memories
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Get first page
|
|
85
|
+
* const firstPage = await memoryManager.listMemories({ page: 1, pageSize: 50 });
|
|
86
|
+
*
|
|
87
|
+
* console.log(`Total memories: ${firstPage.total_count}`);
|
|
88
|
+
* console.log(`Has more: ${firstPage.has_more}`);
|
|
89
|
+
*
|
|
90
|
+
* firstPage.memories.forEach(memory => {
|
|
91
|
+
* console.log(`${memory.id}: ${memory.memory}`);
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* // Get next page if available
|
|
95
|
+
* if (firstPage.has_more) {
|
|
96
|
+
* const nextPage = await memoryManager.listMemories({ page: 2, pageSize: 50 });
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
listMemories(options?: {
|
|
101
|
+
page?: number;
|
|
102
|
+
pageSize?: number;
|
|
103
|
+
}): Promise<MemoryListResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* Fetch a single memory by ID
|
|
106
|
+
*
|
|
107
|
+
* @param memoryId - Memory UUID to fetch
|
|
108
|
+
* @returns Promise resolving to the memory details
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const memory = await memoryManager.getMemory('f4cbdb08-7062-4f3e-8eb2-9f5c80dfe64c');
|
|
113
|
+
*
|
|
114
|
+
* console.log(`Memory: ${memory.memory}`);
|
|
115
|
+
* console.log(`Created: ${memory.created_at}`);
|
|
116
|
+
* console.log(`Updated: ${memory.updated_at}`);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
getMemory(memoryId: string): Promise<MemoryGetResponse>;
|
|
120
|
+
/**
|
|
121
|
+
* Delete a single memory by ID
|
|
122
|
+
*
|
|
123
|
+
* @param memoryId - Memory UUID to delete
|
|
124
|
+
* @returns Promise resolving to the deletion confirmation
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const result = await memoryManager.deleteMemory('f4cbdb08-7062-4f3e-8eb2-9f5c80dfe64c');
|
|
129
|
+
*
|
|
130
|
+
* if (result.deleted) {
|
|
131
|
+
* console.log('Memory deleted successfully');
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
deleteMemory(memoryId: string): Promise<MemoryDeleteResponse>;
|
|
136
|
+
/**
|
|
137
|
+
* Delete all memories for the (character_id, end_user_id) pair
|
|
138
|
+
*
|
|
139
|
+
* This operation is asynchronous on the server side.
|
|
140
|
+
* Check listMemories() after a short delay if confirmation is needed.
|
|
141
|
+
*
|
|
142
|
+
* @returns Promise resolving to the deletion status message
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const result = await memoryManager.deleteAllMemories();
|
|
147
|
+
* console.log(result.message); // "Memory deletion in progress..."
|
|
148
|
+
*
|
|
149
|
+
* // Optional: Wait and verify
|
|
150
|
+
* await new Promise(resolve => setTimeout(resolve, 2000));
|
|
151
|
+
* const remaining = await memoryManager.listMemories();
|
|
152
|
+
* console.log(`Remaining memories: ${remaining.total_count}`);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
deleteAllMemories(): Promise<MemoryDeleteAllResponse>;
|
|
156
|
+
/**
|
|
157
|
+
* Update the end user ID for this memory manager instance
|
|
158
|
+
* Useful when switching users in the same session
|
|
159
|
+
*
|
|
160
|
+
* @param endUserId - New end user identifier
|
|
161
|
+
*/
|
|
162
|
+
setEndUserId(endUserId: string): void;
|
|
163
|
+
/**
|
|
164
|
+
* Get the current end user ID
|
|
165
|
+
*/
|
|
166
|
+
getEndUserId(): string;
|
|
167
|
+
/**
|
|
168
|
+
* Update the character ID for this memory manager instance
|
|
169
|
+
* Useful when switching characters in the same session
|
|
170
|
+
*
|
|
171
|
+
* @param characterId - New character UUID
|
|
172
|
+
*/
|
|
173
|
+
setCharacterId(characterId: string): void;
|
|
174
|
+
/**
|
|
175
|
+
* Get the current character ID
|
|
176
|
+
*/
|
|
177
|
+
getCharacterId(): string;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=MemoryManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryManager.d.ts","sourceRoot":"","sources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;;;;;OAKG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAOzC;;OAEG;IACH,cAAc,IAAI,MAAM;CAGzB"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convai Memory Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages long-term memories for characters using the Convai Memory API.
|
|
5
|
+
* All memory operations are scoped to a (character_id, end_user_id) pair.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const memoryManager = new MemoryManager(apiKey, characterId, endUserId);
|
|
10
|
+
*
|
|
11
|
+
* // Add memories
|
|
12
|
+
* const result = await memoryManager.addMemories([
|
|
13
|
+
* "User prefers outdoor activities",
|
|
14
|
+
* "User is allergic to peanuts"
|
|
15
|
+
* ]);
|
|
16
|
+
*
|
|
17
|
+
* // List memories
|
|
18
|
+
* const memories = await memoryManager.listMemories({ page: 1, pageSize: 50 });
|
|
19
|
+
*
|
|
20
|
+
* // Get a specific memory
|
|
21
|
+
* const memory = await memoryManager.getMemory(memoryId);
|
|
22
|
+
*
|
|
23
|
+
* // Delete a memory
|
|
24
|
+
* await memoryManager.deleteMemory(memoryId);
|
|
25
|
+
*
|
|
26
|
+
* // Delete all memories
|
|
27
|
+
* await memoryManager.deleteAllMemories();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* MemoryManager class for handling Convai Memory API operations.
|
|
32
|
+
* Provides methods to add, list, get, and delete memories for a character.
|
|
33
|
+
*/
|
|
34
|
+
export class MemoryManager {
|
|
35
|
+
/**
|
|
36
|
+
* Create a new MemoryManager instance
|
|
37
|
+
*
|
|
38
|
+
* @param apiKeyOrAuthToken - Convai API key or auth token (required)
|
|
39
|
+
* @param characterId - Character UUID (required)
|
|
40
|
+
* @param endUserId - End user identifier (required)
|
|
41
|
+
* @param baseUrl - Base URL for Convai API (default: https://api.convai.com)
|
|
42
|
+
* @param useAuthToken - If true, treats first parameter as auth token instead of API key (default: false)
|
|
43
|
+
*/
|
|
44
|
+
constructor(apiKeyOrAuthToken, characterId, endUserId, baseUrl = 'https://api.convai.com', useAuthToken = false) {
|
|
45
|
+
if (!apiKeyOrAuthToken) {
|
|
46
|
+
throw new Error('API key or auth token is required');
|
|
47
|
+
}
|
|
48
|
+
if (!characterId) {
|
|
49
|
+
throw new Error('Character ID is required');
|
|
50
|
+
}
|
|
51
|
+
if (!endUserId) {
|
|
52
|
+
throw new Error('End user ID is required');
|
|
53
|
+
}
|
|
54
|
+
// Set either apiKey or authToken based on the flag
|
|
55
|
+
if (useAuthToken) {
|
|
56
|
+
this.apiKey = null;
|
|
57
|
+
this.authToken = apiKeyOrAuthToken;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.apiKey = apiKeyOrAuthToken;
|
|
61
|
+
this.authToken = null;
|
|
62
|
+
}
|
|
63
|
+
this.characterId = characterId;
|
|
64
|
+
this.endUserId = endUserId;
|
|
65
|
+
this.baseUrl = baseUrl.replace(/\/$/, ''); // Remove trailing slash
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Make an authenticated request to the Convai Memory API
|
|
69
|
+
*/
|
|
70
|
+
async makeRequest(endpoint, body) {
|
|
71
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
72
|
+
try {
|
|
73
|
+
const headers = {
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
};
|
|
76
|
+
// Set authentication header based on what's available
|
|
77
|
+
if (this.authToken) {
|
|
78
|
+
headers['API-AUTH-TOKEN'] = this.authToken;
|
|
79
|
+
}
|
|
80
|
+
else if (this.apiKey) {
|
|
81
|
+
headers['CONVAI-API-KEY'] = this.apiKey;
|
|
82
|
+
}
|
|
83
|
+
const response = await fetch(url, {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
headers,
|
|
86
|
+
body: JSON.stringify(body),
|
|
87
|
+
});
|
|
88
|
+
const data = await response.json();
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
const error = data;
|
|
91
|
+
throw new Error(error.ERROR || `HTTP error! status: ${response.status}`);
|
|
92
|
+
}
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error instanceof Error) {
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
throw new Error('Unknown error occurred');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Add one or more memory strings
|
|
104
|
+
*
|
|
105
|
+
* @param memories - Array of memory strings to add (required, non-empty)
|
|
106
|
+
* @returns Promise resolving to the add response with memory IDs
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const result = await memoryManager.addMemories([
|
|
111
|
+
* "User prefers outdoor activities",
|
|
112
|
+
* "User is allergic to peanuts"
|
|
113
|
+
* ]);
|
|
114
|
+
*
|
|
115
|
+
* result.memories.forEach(memory => {
|
|
116
|
+
* console.log(`Added memory ${memory.id}: ${memory.memory}`);
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
async addMemories(memories) {
|
|
121
|
+
if (!memories || memories.length === 0) {
|
|
122
|
+
throw new Error('Memories array is required and must not be empty');
|
|
123
|
+
}
|
|
124
|
+
const request = {
|
|
125
|
+
character_id: this.characterId,
|
|
126
|
+
end_user_id: this.endUserId,
|
|
127
|
+
memories,
|
|
128
|
+
};
|
|
129
|
+
return this.makeRequest('/memory/add', request);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* List memories with pagination
|
|
133
|
+
*
|
|
134
|
+
* @param options - Pagination options
|
|
135
|
+
* @param options.page - Page number (default: 1, clamped to 1-1000)
|
|
136
|
+
* @param options.pageSize - Number of memories per page (default: 50, clamped to 1-100)
|
|
137
|
+
* @returns Promise resolving to paginated list of memories
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* // Get first page
|
|
142
|
+
* const firstPage = await memoryManager.listMemories({ page: 1, pageSize: 50 });
|
|
143
|
+
*
|
|
144
|
+
* console.log(`Total memories: ${firstPage.total_count}`);
|
|
145
|
+
* console.log(`Has more: ${firstPage.has_more}`);
|
|
146
|
+
*
|
|
147
|
+
* firstPage.memories.forEach(memory => {
|
|
148
|
+
* console.log(`${memory.id}: ${memory.memory}`);
|
|
149
|
+
* });
|
|
150
|
+
*
|
|
151
|
+
* // Get next page if available
|
|
152
|
+
* if (firstPage.has_more) {
|
|
153
|
+
* const nextPage = await memoryManager.listMemories({ page: 2, pageSize: 50 });
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
async listMemories(options = {}) {
|
|
158
|
+
const request = {
|
|
159
|
+
character_id: this.characterId,
|
|
160
|
+
end_user_id: this.endUserId,
|
|
161
|
+
page: options.page,
|
|
162
|
+
page_size: options.pageSize,
|
|
163
|
+
};
|
|
164
|
+
return this.makeRequest('/memory/list', request);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Fetch a single memory by ID
|
|
168
|
+
*
|
|
169
|
+
* @param memoryId - Memory UUID to fetch
|
|
170
|
+
* @returns Promise resolving to the memory details
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const memory = await memoryManager.getMemory('f4cbdb08-7062-4f3e-8eb2-9f5c80dfe64c');
|
|
175
|
+
*
|
|
176
|
+
* console.log(`Memory: ${memory.memory}`);
|
|
177
|
+
* console.log(`Created: ${memory.created_at}`);
|
|
178
|
+
* console.log(`Updated: ${memory.updated_at}`);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
async getMemory(memoryId) {
|
|
182
|
+
if (!memoryId) {
|
|
183
|
+
throw new Error('Memory ID is required');
|
|
184
|
+
}
|
|
185
|
+
const request = {
|
|
186
|
+
character_id: this.characterId,
|
|
187
|
+
end_user_id: this.endUserId,
|
|
188
|
+
memory_id: memoryId,
|
|
189
|
+
};
|
|
190
|
+
return this.makeRequest('/memory/get', request);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Delete a single memory by ID
|
|
194
|
+
*
|
|
195
|
+
* @param memoryId - Memory UUID to delete
|
|
196
|
+
* @returns Promise resolving to the deletion confirmation
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const result = await memoryManager.deleteMemory('f4cbdb08-7062-4f3e-8eb2-9f5c80dfe64c');
|
|
201
|
+
*
|
|
202
|
+
* if (result.deleted) {
|
|
203
|
+
* console.log('Memory deleted successfully');
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
async deleteMemory(memoryId) {
|
|
208
|
+
if (!memoryId) {
|
|
209
|
+
throw new Error('Memory ID is required');
|
|
210
|
+
}
|
|
211
|
+
const request = {
|
|
212
|
+
character_id: this.characterId,
|
|
213
|
+
end_user_id: this.endUserId,
|
|
214
|
+
memory_id: memoryId,
|
|
215
|
+
};
|
|
216
|
+
return this.makeRequest('/memory/delete', request);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Delete all memories for the (character_id, end_user_id) pair
|
|
220
|
+
*
|
|
221
|
+
* This operation is asynchronous on the server side.
|
|
222
|
+
* Check listMemories() after a short delay if confirmation is needed.
|
|
223
|
+
*
|
|
224
|
+
* @returns Promise resolving to the deletion status message
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* const result = await memoryManager.deleteAllMemories();
|
|
229
|
+
* console.log(result.message); // "Memory deletion in progress..."
|
|
230
|
+
*
|
|
231
|
+
* // Optional: Wait and verify
|
|
232
|
+
* await new Promise(resolve => setTimeout(resolve, 2000));
|
|
233
|
+
* const remaining = await memoryManager.listMemories();
|
|
234
|
+
* console.log(`Remaining memories: ${remaining.total_count}`);
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
async deleteAllMemories() {
|
|
238
|
+
const request = {
|
|
239
|
+
character_id: this.characterId,
|
|
240
|
+
end_user_id: this.endUserId,
|
|
241
|
+
};
|
|
242
|
+
return this.makeRequest('/memory/delete-all', request);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Update the end user ID for this memory manager instance
|
|
246
|
+
* Useful when switching users in the same session
|
|
247
|
+
*
|
|
248
|
+
* @param endUserId - New end user identifier
|
|
249
|
+
*/
|
|
250
|
+
setEndUserId(endUserId) {
|
|
251
|
+
if (!endUserId) {
|
|
252
|
+
throw new Error('End user ID is required');
|
|
253
|
+
}
|
|
254
|
+
this.endUserId = endUserId;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get the current end user ID
|
|
258
|
+
*/
|
|
259
|
+
getEndUserId() {
|
|
260
|
+
return this.endUserId;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Update the character ID for this memory manager instance
|
|
264
|
+
* Useful when switching characters in the same session
|
|
265
|
+
*
|
|
266
|
+
* @param characterId - New character UUID
|
|
267
|
+
*/
|
|
268
|
+
setCharacterId(characterId) {
|
|
269
|
+
if (!characterId) {
|
|
270
|
+
throw new Error('Character ID is required');
|
|
271
|
+
}
|
|
272
|
+
this.characterId = characterId;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get the current character ID
|
|
276
|
+
*/
|
|
277
|
+
getCharacterId() {
|
|
278
|
+
return this.characterId;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=MemoryManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryManager.js","sourceRoot":"","sources":["../../src/core/MemoryManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAgBH;;;GAGG;AACH,MAAM,OAAO,aAAa;IAOxB;;;;;;;;OAQG;IACH,YACE,iBAAyB,EACzB,WAAmB,EACnB,SAAiB,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CAAC,SAAiB;QAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,cAAc,CAAC,WAAmB;QAChC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export { ConvaiClient } from './ConvaiClient';
|
|
2
2
|
export * from './types';
|
|
3
|
+
export { getDisconnectReasonMessage } from './types';
|
|
3
4
|
export type { ConvaiClient as ConvaiClientType } from './ConvaiClient';
|
|
4
5
|
export { AudioManager } from './AudioManager';
|
|
5
6
|
export { VideoManager } from './VideoManager';
|
|
6
7
|
export { ScreenShareManager } from './ScreenShareManager';
|
|
7
8
|
export { MessageHandler } from './MessageHandler';
|
|
9
|
+
export { MemoryManager } from './MemoryManager';
|
|
8
10
|
export { BlendshapeQueue } from './BlendshapeQueue';
|
|
9
11
|
export type { TurnStats } from './BlendshapeQueue';
|
|
10
12
|
export { EventEmitter } from './EventEmitter';
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,cAAc,SAAS,CAAC;AAGxB,YAAY,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAGrD,YAAY,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
export { ConvaiClient } from './ConvaiClient';
|
|
3
3
|
// Types (including IConvaiClient interface)
|
|
4
4
|
export * from './types';
|
|
5
|
+
// Helper functions
|
|
6
|
+
export { getDisconnectReasonMessage } from './types';
|
|
5
7
|
// Managers (for advanced usage)
|
|
6
8
|
export { AudioManager } from './AudioManager';
|
|
7
9
|
export { VideoManager } from './VideoManager';
|
|
8
10
|
export { ScreenShareManager } from './ScreenShareManager';
|
|
9
11
|
export { MessageHandler } from './MessageHandler';
|
|
12
|
+
export { MemoryManager } from './MemoryManager';
|
|
10
13
|
// Blendshape queue for lipsync
|
|
11
14
|
export { BlendshapeQueue } from './BlendshapeQueue';
|
|
12
15
|
// Event Emitter (for advanced usage)
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,4CAA4C;AAC5C,cAAc,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,4CAA4C;AAC5C,cAAc,SAAS,CAAC;AAExB,mBAAmB;AACnB,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAKrD,gCAAgC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,+BAA+B;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,qCAAqC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|