(workspaceId: string, key: string)
| 199 | } |
| 200 | |
| 201 | private async fetchMemory(workspaceId: string, key: string): Promise<Message[]> { |
| 202 | const result = await db |
| 203 | .select({ data: memory.data }) |
| 204 | .from(memory) |
| 205 | .where(and(eq(memory.workspaceId, workspaceId), eq(memory.key, key))) |
| 206 | .limit(1) |
| 207 | |
| 208 | if (result.length === 0) return [] |
| 209 | |
| 210 | const data = result[0].data |
| 211 | if (!Array.isArray(data)) return [] |
| 212 | |
| 213 | return data |
| 214 | .filter( |
| 215 | (msg): msg is Message => |
| 216 | msg && |
| 217 | typeof msg === 'object' && |
| 218 | 'role' in msg && |
| 219 | 'content' in msg && |
| 220 | ['system', 'user', 'assistant'].includes(msg.role) && |
| 221 | typeof msg.content === 'string' |
| 222 | ) |
| 223 | .map((msg) => this.sanitizeMessageForStorage(msg)) |
| 224 | } |
| 225 | |
| 226 | private async seedMemoryRecord( |
| 227 | workspaceId: string, |
no test coverage detected