()
| 25 | |
| 26 | // Open the database |
| 27 | export async function openDB(): Promise<IDBDatabase> { |
| 28 | return new Promise((resolve, reject) => { |
| 29 | const request = indexedDB.open(DB_NAME, DB_VERSION); |
| 30 | |
| 31 | request.onerror = () => reject(request.error); |
| 32 | request.onsuccess = () => resolve(request.result); |
| 33 | |
| 34 | // Create the object stores when database is first created |
| 35 | request.onupgradeneeded = () => { |
| 36 | const db = request.result; |
| 37 | |
| 38 | // Store for agent metadata |
| 39 | let agentStore: IDBObjectStore; |
| 40 | if (!db.objectStoreNames.contains(AGENT_STORE)) { |
| 41 | agentStore = db.createObjectStore(AGENT_STORE, { keyPath: 'id' }); |
| 42 | } else { |
| 43 | agentStore = request.transaction!.objectStore(AGENT_STORE); |
| 44 | if (agentStore.indexNames.contains('by_status')) { |
| 45 | agentStore.deleteIndex('by_status'); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Store for agent configurations |
| 50 | if (!db.objectStoreNames.contains(CONFIG_STORE)) { |
| 51 | db.createObjectStore(CONFIG_STORE, { keyPath: 'id' }); |
| 52 | } |
| 53 | |
| 54 | // Store for agent code |
| 55 | if (!db.objectStoreNames.contains(CODE_STORE)) { |
| 56 | db.createObjectStore(CODE_STORE, { keyPath: 'id' }); |
| 57 | } |
| 58 | |
| 59 | // Store for agent memories |
| 60 | if (!db.objectStoreNames.contains(MEMORY_STORE)) { |
| 61 | db.createObjectStore(MEMORY_STORE, { keyPath: 'id' }); |
| 62 | } |
| 63 | |
| 64 | // Store for agent image memories |
| 65 | if (!db.objectStoreNames.contains(IMAGE_MEMORY_STORE)) { |
| 66 | db.createObjectStore(IMAGE_MEMORY_STORE, { keyPath: 'id' }); |
| 67 | } |
| 68 | }; |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | // Create or update an agent |
| 73 | export async function saveAgent( |
no outgoing calls
no test coverage detected