repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { v4 as uuidv4 } from "uuid"; |
| #2 | import { HistoryManager } from "./base"; |
| #3 | interface HistoryEntry { |
| #4 | id: string; |
| #5 | memory_id: string; |
| #6 | previous_value: string | null; |
| #7 | new_value: string | null; |
| #8 | action: string; |
| #9 | created_at: string; |
| #10 | updated_at: string | null; |
| #11 | is_deleted: number; |
| #12 | } |
| #13 | |
| #14 | export class MemoryHistoryManager implements HistoryManager { |
| #15 | private memoryStore: Map<string, HistoryEntry> = new Map(); |
| #16 | |
| #17 | async addHistory( |
| #18 | memoryId: string, |
| #19 | previousValue: string | null, |
| #20 | newValue: string | null, |
| #21 | action: string, |
| #22 | createdAt?: string, |
| #23 | updatedAt?: string, |
| #24 | isDeleted: number = 0, |
| #25 | ): Promise<void> { |
| #26 | const historyEntry: HistoryEntry = { |
| #27 | id: uuidv4(), |
| #28 | memory_id: memoryId, |
| #29 | previous_value: previousValue, |
| #30 | new_value: newValue, |
| #31 | action: action, |
| #32 | created_at: createdAt || new Date().toISOString(), |
| #33 | updated_at: updatedAt || null, |
| #34 | is_deleted: isDeleted, |
| #35 | }; |
| #36 | |
| #37 | this.memoryStore.set(historyEntry.id, historyEntry); |
| #38 | } |
| #39 | |
| #40 | async getHistory(memoryId: string): Promise<any[]> { |
| #41 | return Array.from(this.memoryStore.values()) |
| #42 | .filter((entry) => entry.memory_id === memoryId) |
| #43 | .sort( |
| #44 | (a, b) => |
| #45 | new Date(b.created_at).getTime() - new Date(a.created_at).getTime(), |
| #46 | ) |
| #47 | .slice(0, 100); |
| #48 | } |
| #49 | |
| #50 | async reset(): Promise<void> { |
| #51 | this.memoryStore.clear(); |
| #52 | } |
| #53 | |
| #54 | close(): void { |
| #55 | // No need to close anything for in-memory storage |
| #56 | return; |
| #57 | } |
| #58 | } |
| #59 |