@almadar/server 2.0.8 → 2.1.0

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.
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */
8
- import { MemoryManager } from '@almadar/agent';
8
+ import { MemoryManager } from '@almadar-io/agent';
9
9
  /**
10
10
  * Get or create the MemoryManager singleton
11
11
  */
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/deepagent/memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK/C;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAehD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/deepagent/memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKlD;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAehD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
@@ -1,4 +1,4 @@
1
- import { MemoryManager } from '@almadar/agent';
1
+ import { MemoryManager } from '@almadar-io/agent';
2
2
  import admin from 'firebase-admin';
3
3
 
4
4
  // src/deepagent/memory.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/db.ts","../../src/deepagent/memory.ts"],"names":[],"mappings":";;;;AAoFA,SAAS,MAAA,GAAwB;AAC/B,EAAA,IAAI,KAAA,CAAM,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,MAAM,GAAA,EAAI;AACnB;AAKO,SAAS,YAAA,GAA0C;AACxD,EAAA,OAAO,MAAA,GAAS,SAAA,EAAU;AAC5B;AAgBO,IAAM,EAAA,GAAK,IAAI,KAAA,CAAM,EAAC,EAAgC;AAAA,EAC3D,GAAA,CAAI,OAAA,EAAS,IAAA,EAAM,QAAA,EAAU;AAC3B,IAAA,MAAM,YAAY,YAAA,EAAa;AAC/B,IAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,SAAA,EAAW,MAAM,QAAQ,CAAA;AACnD,IAAA,OAAO,OAAO,KAAA,KAAU,UAAA,GAAa,KAAA,CAAM,IAAA,CAAK,SAAS,CAAA,GAAI,KAAA;AAAA,EAC/D;AACF,CAAC,CAAA;;;AC9GD,IAAI,aAAA,GAAsC,IAAA;AAKnC,SAAS,gBAAA,GAAkC;AAChD,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,aAAA,GAAgB,IAAI,aAAA,CAAc;AAAA,MAChC,EAAA;AAAA,MACA,eAAA,EAAiB,oBAAA;AAAA,MACjB,kBAAA,EAAoB,uBAAA;AAAA,MACpB,qBAAA,EAAuB,0BAAA;AAAA,MACvB,kBAAA,EAAoB,uBAAA;AAAA,MACpB,oBAAA,EAAsB,yBAAA;AAAA,MACtB,kBAAA,EAAoB,uBAAA;AAAA,MACpB,qBAAA,EAAuB,0BAAA;AAAA,MACvB,yBAAA,EAA2B;AAAA,KAC5B,CAAA;AAAA,EACH;AACA,EAAA,OAAO,aAAA;AACT;AAKO,SAAS,kBAAA,GAA2B;AACzC,EAAA,aAAA,GAAgB,IAAA;AAClB","file":"memory.js","sourcesContent":["/**\n * Database Accessors & Initialization\n *\n * This module provides:\n * - `initializeFirebase()` — convenience function to init Firebase from env vars\n * - `getFirestore()`, `getAuth()` — accessors for Firebase services\n * - `db` — lazy Firestore proxy (no eager initialization)\n *\n * The consuming application MUST call `initializeFirebase()` or\n * `admin.initializeApp()` before using any Firebase-dependent features.\n */\n\nimport admin from 'firebase-admin';\n\n/**\n * Initialize Firebase Admin SDK from environment variables.\n *\n * Reads: FIREBASE_PROJECT_ID, FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY,\n * FIREBASE_SERVICE_ACCOUNT_PATH, FIRESTORE_EMULATOR_HOST\n *\n * Safe to call multiple times — returns existing app if already initialized.\n */\nexport function initializeFirebase(): admin.app.App {\n // Already initialized — return existing app\n if (admin.apps.length > 0) {\n return admin.app();\n }\n\n const projectId = process.env.FIREBASE_PROJECT_ID;\n const emulatorHost = process.env.FIRESTORE_EMULATOR_HOST;\n\n // Emulator mode — no credentials needed\n if (emulatorHost) {\n const app = admin.initializeApp({\n projectId: projectId || 'demo-project',\n });\n console.log(`Firebase Admin initialized for emulator: ${emulatorHost}`);\n return app;\n }\n\n // Service account file\n const serviceAccountPath = process.env.FIREBASE_SERVICE_ACCOUNT_PATH;\n if (serviceAccountPath) {\n // Dynamic require for JSON service account file at runtime\n const serviceAccount = require(serviceAccountPath) as Record<string, unknown>;\n return admin.initializeApp({\n credential: admin.credential.cert(serviceAccount),\n projectId,\n });\n }\n\n // Inline credentials\n const clientEmail = process.env.FIREBASE_CLIENT_EMAIL;\n const privateKey = process.env.FIREBASE_PRIVATE_KEY;\n if (projectId && clientEmail && privateKey) {\n return admin.initializeApp({\n credential: admin.credential.cert({\n projectId,\n clientEmail,\n privateKey: privateKey.replace(/\\\\n/g, '\\n'),\n }),\n projectId,\n });\n }\n\n // Application default credentials (Cloud Run, etc.)\n if (projectId) {\n return admin.initializeApp({\n credential: admin.credential.applicationDefault(),\n projectId,\n });\n }\n\n throw new Error(\n '@almadar/server: Cannot initialize Firebase — no credentials found. ' +\n 'Set FIREBASE_PROJECT_ID + FIREBASE_CLIENT_EMAIL + FIREBASE_PRIVATE_KEY, ' +\n 'or FIREBASE_SERVICE_ACCOUNT_PATH, or FIRESTORE_EMULATOR_HOST.'\n );\n}\n\n/**\n * Get the initialized Firebase app.\n * Throws if Firebase Admin SDK has not been initialized.\n */\nfunction getApp(): admin.app.App {\n if (admin.apps.length === 0) {\n throw new Error(\n '@almadar/server: Firebase Admin SDK is not initialized. ' +\n 'Call initializeFirebase() or admin.initializeApp() before using @almadar/server.'\n );\n }\n return admin.app();\n}\n\n/**\n * Get Firestore instance from the pre-initialized Firebase app.\n */\nexport function getFirestore(): admin.firestore.Firestore {\n return getApp().firestore();\n}\n\n/**\n * Get Firebase Auth instance from the pre-initialized Firebase app.\n */\nexport function getAuth(): admin.auth.Auth {\n return getApp().auth();\n}\n\n// Re-export admin for convenience\nexport { admin };\n\n/**\n * Lazy Firestore proxy — resolves on first property access, not at import time.\n * This prevents the \"Firebase not initialized\" error during module loading.\n */\nexport const db = new Proxy({} as admin.firestore.Firestore, {\n get(_target, prop, receiver) {\n const firestore = getFirestore();\n const value = Reflect.get(firestore, prop, receiver);\n return typeof value === 'function' ? value.bind(firestore) : value;\n },\n});\n","/**\n * Memory Manager Singleton\n *\n * Provides Firestore-backed memory management for DeepAgent.\n *\n * @packageDocumentation\n */\n\nimport { MemoryManager } from '@almadar/agent';\nimport { db } from '../lib/db.js';\n\nlet memoryManager: MemoryManager | null = null;\n\n/**\n * Get or create the MemoryManager singleton\n */\nexport function getMemoryManager(): MemoryManager {\n if (!memoryManager) {\n memoryManager = new MemoryManager({\n db,\n usersCollection: 'agent_memory_users',\n projectsCollection: 'agent_memory_projects',\n generationsCollection: 'agent_memory_generations',\n patternsCollection: 'agent_memory_patterns',\n interruptsCollection: 'agent_memory_interrupts',\n feedbackCollection: 'agent_memory_feedback',\n checkpointsCollection: 'agent_memory_checkpoints',\n toolPreferencesCollection: 'agent_memory_tool_preferences',\n });\n }\n return memoryManager;\n}\n\n/**\n * Reset the MemoryManager (useful for testing)\n */\nexport function resetMemoryManager(): void {\n memoryManager = null;\n}\n"]}
1
+ {"version":3,"sources":["../../src/lib/db.ts","../../src/deepagent/memory.ts"],"names":[],"mappings":";;;;AAoFA,SAAS,MAAA,GAAwB;AAC/B,EAAA,IAAI,KAAA,CAAM,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,MAAM,GAAA,EAAI;AACnB;AAKO,SAAS,YAAA,GAA0C;AACxD,EAAA,OAAO,MAAA,GAAS,SAAA,EAAU;AAC5B;AAgBO,IAAM,EAAA,GAAK,IAAI,KAAA,CAAM,EAAC,EAAgC;AAAA,EAC3D,GAAA,CAAI,OAAA,EAAS,IAAA,EAAM,QAAA,EAAU;AAC3B,IAAA,MAAM,YAAY,YAAA,EAAa;AAC/B,IAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,SAAA,EAAW,MAAM,QAAQ,CAAA;AACnD,IAAA,OAAO,OAAO,KAAA,KAAU,UAAA,GAAa,KAAA,CAAM,IAAA,CAAK,SAAS,CAAA,GAAI,KAAA;AAAA,EAC/D;AACF,CAAC,CAAA;;;AC9GD,IAAI,aAAA,GAAsC,IAAA;AAKnC,SAAS,gBAAA,GAAkC;AAChD,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,aAAA,GAAgB,IAAI,aAAA,CAAc;AAAA,MAChC,EAAA;AAAA,MACA,eAAA,EAAiB,oBAAA;AAAA,MACjB,kBAAA,EAAoB,uBAAA;AAAA,MACpB,qBAAA,EAAuB,0BAAA;AAAA,MACvB,kBAAA,EAAoB,uBAAA;AAAA,MACpB,oBAAA,EAAsB,yBAAA;AAAA,MACtB,kBAAA,EAAoB,uBAAA;AAAA,MACpB,qBAAA,EAAuB,0BAAA;AAAA,MACvB,yBAAA,EAA2B;AAAA,KAC5B,CAAA;AAAA,EACH;AACA,EAAA,OAAO,aAAA;AACT;AAKO,SAAS,kBAAA,GAA2B;AACzC,EAAA,aAAA,GAAgB,IAAA;AAClB","file":"memory.js","sourcesContent":["/**\n * Database Accessors & Initialization\n *\n * This module provides:\n * - `initializeFirebase()` — convenience function to init Firebase from env vars\n * - `getFirestore()`, `getAuth()` — accessors for Firebase services\n * - `db` — lazy Firestore proxy (no eager initialization)\n *\n * The consuming application MUST call `initializeFirebase()` or\n * `admin.initializeApp()` before using any Firebase-dependent features.\n */\n\nimport admin from 'firebase-admin';\n\n/**\n * Initialize Firebase Admin SDK from environment variables.\n *\n * Reads: FIREBASE_PROJECT_ID, FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY,\n * FIREBASE_SERVICE_ACCOUNT_PATH, FIRESTORE_EMULATOR_HOST\n *\n * Safe to call multiple times — returns existing app if already initialized.\n */\nexport function initializeFirebase(): admin.app.App {\n // Already initialized — return existing app\n if (admin.apps.length > 0) {\n return admin.app();\n }\n\n const projectId = process.env.FIREBASE_PROJECT_ID;\n const emulatorHost = process.env.FIRESTORE_EMULATOR_HOST;\n\n // Emulator mode — no credentials needed\n if (emulatorHost) {\n const app = admin.initializeApp({\n projectId: projectId || 'demo-project',\n });\n console.log(`Firebase Admin initialized for emulator: ${emulatorHost}`);\n return app;\n }\n\n // Service account file\n const serviceAccountPath = process.env.FIREBASE_SERVICE_ACCOUNT_PATH;\n if (serviceAccountPath) {\n // Dynamic require for JSON service account file at runtime\n const serviceAccount = require(serviceAccountPath) as Record<string, unknown>;\n return admin.initializeApp({\n credential: admin.credential.cert(serviceAccount),\n projectId,\n });\n }\n\n // Inline credentials\n const clientEmail = process.env.FIREBASE_CLIENT_EMAIL;\n const privateKey = process.env.FIREBASE_PRIVATE_KEY;\n if (projectId && clientEmail && privateKey) {\n return admin.initializeApp({\n credential: admin.credential.cert({\n projectId,\n clientEmail,\n privateKey: privateKey.replace(/\\\\n/g, '\\n'),\n }),\n projectId,\n });\n }\n\n // Application default credentials (Cloud Run, etc.)\n if (projectId) {\n return admin.initializeApp({\n credential: admin.credential.applicationDefault(),\n projectId,\n });\n }\n\n throw new Error(\n '@almadar/server: Cannot initialize Firebase — no credentials found. ' +\n 'Set FIREBASE_PROJECT_ID + FIREBASE_CLIENT_EMAIL + FIREBASE_PRIVATE_KEY, ' +\n 'or FIREBASE_SERVICE_ACCOUNT_PATH, or FIRESTORE_EMULATOR_HOST.'\n );\n}\n\n/**\n * Get the initialized Firebase app.\n * Throws if Firebase Admin SDK has not been initialized.\n */\nfunction getApp(): admin.app.App {\n if (admin.apps.length === 0) {\n throw new Error(\n '@almadar/server: Firebase Admin SDK is not initialized. ' +\n 'Call initializeFirebase() or admin.initializeApp() before using @almadar/server.'\n );\n }\n return admin.app();\n}\n\n/**\n * Get Firestore instance from the pre-initialized Firebase app.\n */\nexport function getFirestore(): admin.firestore.Firestore {\n return getApp().firestore();\n}\n\n/**\n * Get Firebase Auth instance from the pre-initialized Firebase app.\n */\nexport function getAuth(): admin.auth.Auth {\n return getApp().auth();\n}\n\n// Re-export admin for convenience\nexport { admin };\n\n/**\n * Lazy Firestore proxy — resolves on first property access, not at import time.\n * This prevents the \"Firebase not initialized\" error during module loading.\n */\nexport const db = new Proxy({} as admin.firestore.Firestore, {\n get(_target, prop, receiver) {\n const firestore = getFirestore();\n const value = Reflect.get(firestore, prop, receiver);\n return typeof value === 'function' ? value.bind(firestore) : value;\n },\n});\n","/**\n * Memory Manager Singleton\n *\n * Provides Firestore-backed memory management for DeepAgent.\n *\n * @packageDocumentation\n */\n\nimport { MemoryManager } from '@almadar-io/agent';\nimport { db } from '../lib/db.js';\n\nlet memoryManager: MemoryManager | null = null;\n\n/**\n * Get or create the MemoryManager singleton\n */\nexport function getMemoryManager(): MemoryManager {\n if (!memoryManager) {\n memoryManager = new MemoryManager({\n db,\n usersCollection: 'agent_memory_users',\n projectsCollection: 'agent_memory_projects',\n generationsCollection: 'agent_memory_generations',\n patternsCollection: 'agent_memory_patterns',\n interruptsCollection: 'agent_memory_interrupts',\n feedbackCollection: 'agent_memory_feedback',\n checkpointsCollection: 'agent_memory_checkpoints',\n toolPreferencesCollection: 'agent_memory_tool_preferences',\n });\n }\n return memoryManager;\n}\n\n/**\n * Reset the MemoryManager (useful for testing)\n */\nexport function resetMemoryManager(): void {\n memoryManager = null;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */
8
- import { SessionManager } from '@almadar/agent';
8
+ import { SessionManager } from '@almadar-io/agent';
9
9
  /**
10
10
  * Get or create the SessionManager singleton
11
11
  */
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/deepagent/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAchD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAclD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/deepagent/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAcnD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAclD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C"}
@@ -1,4 +1,4 @@
1
- import { SessionManager, MemoryManager } from '@almadar/agent';
1
+ import { SessionManager, MemoryManager } from '@almadar-io/agent';
2
2
  import admin from 'firebase-admin';
3
3
 
4
4
  // src/deepagent/session.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/db.ts","../../src/deepagent/memory.ts","../../src/deepagent/session.ts"],"names":[],"mappings":";;;;AAoFA,SAAS,MAAA,GAAwB;AAC/B,EAAA,IAAI,KAAA,CAAM,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,MAAM,GAAA,EAAI;AACnB;AAKO,SAAS,YAAA,GAA0C;AACxD,EAAA,OAAO,MAAA,GAAS,SAAA,EAAU;AAC5B;AAgBO,IAAM,EAAA,GAAK,IAAI,KAAA,CAAM,EAAC,EAAgC;AAAA,EAC3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AA,EACH;AACA,EAAA,OAAO,cAAA;AACT;AAKO,SAAS,mBAAA,GAA4B;AAC1C,EAAA,cAAA,GAAiB,IAAA;AACnB","file":"session.js","sourcesContent":["/**\n * Database Accessors & Initialization\n *\n * This module provides:\n * - `initializeFirebase()` — convenience function to init Firebase from env vars\n * - `getFirestore()`, `getAuth()` — accessors for Firebase services\n * - `db` — lazy Firestore proxy (no eager initialization)\n *\n * The consuming application MUST call `initializeFirebase()` or\n * `admin.initializeApp()` before using any Firebase-dependent features.\n */\n\nimport admin from 'firebase-admin';\n\n/**\n * Initialize Firebase Admin SDK from environment variables.\n *\n * Reads: FIREBASE_PROJECT_ID, FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY,\n * FIREBASE_SERVICE_ACCOUNT_PATH, FIRESTORE_EMULATOR_HOST\n *\n * Safe to call multiple times — returns existing app if already initialized.\n */\nexport function initializeFirebase(): admin.app.App {\n // Already initialized — return existing app\n if (admin.apps.length > 0) {\n return admin.app();\n }\n\n const projectId = process.env.FIREBASE_PROJECT_ID;\n const emulatorHost = process.env.FIRESTORE_EMULATOR_HOST;\n\n // Emulator mode — no credentials needed\n if (emulatorHost) {\n const app = admin.initializeApp({\n projectId: projectId || 'demo-project',\n });\n console.log(`Firebase Admin initialized for emulator: ${emulatorHost}`);\n return app;\n }\n\n // Service account file\n const serviceAccountPath = process.env.FIREBASE_SERVICE_ACCOUNT_PATH;\n if (serviceAccountPath) {\n // Dynamic require for JSON service account file at runtime\n const serviceAccount = require(serviceAccountPath) as Record<string, unknown>;\n return admin.initializeApp({\n credential: admin.credential.cert(serviceAccount),\n projectId,\n });\n }\n\n // Inline credentials\n const clientEmail = process.env.FIREBASE_CLIENT_EMAIL;\n const privateKey = process.env.FIREBASE_PRIVATE_KEY;\n if (projectId && clientEmail && privateKey) {\n return admin.initializeApp({\n credential: admin.credential.cert({\n projectId,\n clientEmail,\n privateKey: privateKey.replace(/\\\\n/g, '\\n'),\n }),\n projectId,\n });\n }\n\n // Application default credentials (Cloud Run, etc.)\n if (projectId) {\n return admin.initializeApp({\n credential: admin.credential.applicationDefault(),\n projectId,\n });\n }\n\n throw new Error(\n '@almadar/server: Cannot initialize Firebase — no credentials found. ' +\n 'Set FIREBASE_PROJECT_ID + FIREBASE_CLIENT_EMAIL + FIREBASE_PRIVATE_KEY, ' +\n 'or FIREBASE_SERVICE_ACCOUNT_PATH, or FIRESTORE_EMULATOR_HOST.'\n );\n}\n\n/**\n * Get the initialized Firebase app.\n * Throws if Firebase Admin SDK has not been initialized.\n */\nfunction getApp(): admin.app.App {\n if (admin.apps.length === 0) {\n throw new Error(\n '@almadar/server: Firebase Admin SDK is not initialized. ' +\n 'Call initializeFirebase() or admin.initializeApp() before using @almadar/server.'\n );\n }\n return admin.app();\n}\n\n/**\n * Get Firestore instance from the pre-initialized Firebase app.\n */\nexport function getFirestore(): admin.firestore.Firestore {\n return getApp().firestore();\n}\n\n/**\n * Get Firebase Auth instance from the pre-initialized Firebase app.\n */\nexport function getAuth(): admin.auth.Auth {\n return getApp().auth();\n}\n\n// Re-export admin for convenience\nexport { admin };\n\n/**\n * Lazy Firestore proxy — resolves on first property access, not at import time.\n * This prevents the \"Firebase not initialized\" error during module loading.\n */\nexport const db = new Proxy({} as admin.firestore.Firestore, {\n get(_target, prop, receiver) {\n const firestore = getFirestore();\n const value = Reflect.get(firestore, prop, receiver);\n return typeof value === 'function' ? value.bind(firestore) : value;\n },\n});\n","/**\n * Memory Manager Singleton\n *\n * Provides Firestore-backed memory management for DeepAgent.\n *\n * @packageDocumentation\n */\n\nimport { MemoryManager } from '@almadar/agent';\nimport { db } from '../lib/db.js';\n\nlet memoryManager: MemoryManager | null = null;\n\n/**\n * Get or create the MemoryManager singleton\n */\nexport function getMemoryManager(): MemoryManager {\n if (!memoryManager) {\n memoryManager = new MemoryManager({\n db,\n usersCollection: 'agent_memory_users',\n projectsCollection: 'agent_memory_projects',\n generationsCollection: 'agent_memory_generations',\n patternsCollection: 'agent_memory_patterns',\n interruptsCollection: 'agent_memory_interrupts',\n feedbackCollection: 'agent_memory_feedback',\n checkpointsCollection: 'agent_memory_checkpoints',\n toolPreferencesCollection: 'agent_memory_tool_preferences',\n });\n }\n return memoryManager;\n}\n\n/**\n * Reset the MemoryManager (useful for testing)\n */\nexport function resetMemoryManager(): void {\n memoryManager = null;\n}\n","/**\n * Session Manager Singleton\n *\n * Provides Firestore-backed session management with full GAP features.\n *\n * @packageDocumentation\n */\n\nimport { SessionManager } from '@almadar/agent';\nimport { db } from '../lib/db.js';\nimport { getMemoryManager } from './memory.js';\nimport type { FirestoreDb } from '@almadar/agent';\n\nlet sessionManager: SessionManager | null = null;\n\n/**\n * Adapter to make Firebase Firestore compatible with @almadar/agent FirestoreDb interface\n */\nfunction createFirestoreAdapter(firestore: typeof db): FirestoreDb {\n return firestore as unknown as FirestoreDb;\n}\n\n/**\n * Get or create the SessionManager singleton\n */\nexport function getSessionManager(): SessionManager {\n if (!sessionManager) {\n sessionManager = new SessionManager({\n mode: 'firestore',\n firestoreDb: createFirestoreAdapter(db),\n memoryManager: getMemoryManager(), // Enable GAP-002D\n compactionConfig: {\n maxTokens: 150000,\n keepRecentMessages: 10,\n strategy: 'last',\n },\n });\n }\n return sessionManager;\n}\n\n/**\n * Reset the SessionManager (useful for testing)\n */\nexport function resetSessionManager(): void {\n sessionManager = null;\n}\n"]}
1
+ {"version":3,"sources":["../../src/lib/db.ts","../../src/deepagent/memory.ts","../../src/deepagent/session.ts"],"names":[],"mappings":";;;;AAoFA,SAAS,MAAA,GAAwB;AAC/B,EAAA,IAAI,KAAA,CAAM,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,MAAM,GAAA,EAAI;AACnB;AAKO,SAAS,YAAA,GAA0C;AACxD,EAAA,OAAO,MAAA,GAAS,SAAA,EAAU;AAC5B;AAgBO,IAAM,EAAA,GAAK,I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pB,QAAA,EAAU;AAAA;AACZ,KACD,CAAA;AAAA,EACH;AACA,EAAA,OAAO,cAAA;AACT;AAKO,SAAS,mBAAA,GAA4B;AAC1C,EAAA,cAAA,GAAiB,IAAA;AACnB","file":"session.js","sourcesContent":["/**\n * Database Accessors & Initialization\n *\n * This module provides:\n * - `initializeFirebase()` — convenience function to init Firebase from env vars\n * - `getFirestore()`, `getAuth()` — accessors for Firebase services\n * - `db` — lazy Firestore proxy (no eager initialization)\n *\n * The consuming application MUST call `initializeFirebase()` or\n * `admin.initializeApp()` before using any Firebase-dependent features.\n */\n\nimport admin from 'firebase-admin';\n\n/**\n * Initialize Firebase Admin SDK from environment variables.\n *\n * Reads: FIREBASE_PROJECT_ID, FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY,\n * FIREBASE_SERVICE_ACCOUNT_PATH, FIRESTORE_EMULATOR_HOST\n *\n * Safe to call multiple times — returns existing app if already initialized.\n */\nexport function initializeFirebase(): admin.app.App {\n // Already initialized — return existing app\n if (admin.apps.length > 0) {\n return admin.app();\n }\n\n const projectId = process.env.FIREBASE_PROJECT_ID;\n const emulatorHost = process.env.FIRESTORE_EMULATOR_HOST;\n\n // Emulator mode — no credentials needed\n if (emulatorHost) {\n const app = admin.initializeApp({\n projectId: projectId || 'demo-project',\n });\n console.log(`Firebase Admin initialized for emulator: ${emulatorHost}`);\n return app;\n }\n\n // Service account file\n const serviceAccountPath = process.env.FIREBASE_SERVICE_ACCOUNT_PATH;\n if (serviceAccountPath) {\n // Dynamic require for JSON service account file at runtime\n const serviceAccount = require(serviceAccountPath) as Record<string, unknown>;\n return admin.initializeApp({\n credential: admin.credential.cert(serviceAccount),\n projectId,\n });\n }\n\n // Inline credentials\n const clientEmail = process.env.FIREBASE_CLIENT_EMAIL;\n const privateKey = process.env.FIREBASE_PRIVATE_KEY;\n if (projectId && clientEmail && privateKey) {\n return admin.initializeApp({\n credential: admin.credential.cert({\n projectId,\n clientEmail,\n privateKey: privateKey.replace(/\\\\n/g, '\\n'),\n }),\n projectId,\n });\n }\n\n // Application default credentials (Cloud Run, etc.)\n if (projectId) {\n return admin.initializeApp({\n credential: admin.credential.applicationDefault(),\n projectId,\n });\n }\n\n throw new Error(\n '@almadar/server: Cannot initialize Firebase — no credentials found. ' +\n 'Set FIREBASE_PROJECT_ID + FIREBASE_CLIENT_EMAIL + FIREBASE_PRIVATE_KEY, ' +\n 'or FIREBASE_SERVICE_ACCOUNT_PATH, or FIRESTORE_EMULATOR_HOST.'\n );\n}\n\n/**\n * Get the initialized Firebase app.\n * Throws if Firebase Admin SDK has not been initialized.\n */\nfunction getApp(): admin.app.App {\n if (admin.apps.length === 0) {\n throw new Error(\n '@almadar/server: Firebase Admin SDK is not initialized. ' +\n 'Call initializeFirebase() or admin.initializeApp() before using @almadar/server.'\n );\n }\n return admin.app();\n}\n\n/**\n * Get Firestore instance from the pre-initialized Firebase app.\n */\nexport function getFirestore(): admin.firestore.Firestore {\n return getApp().firestore();\n}\n\n/**\n * Get Firebase Auth instance from the pre-initialized Firebase app.\n */\nexport function getAuth(): admin.auth.Auth {\n return getApp().auth();\n}\n\n// Re-export admin for convenience\nexport { admin };\n\n/**\n * Lazy Firestore proxy — resolves on first property access, not at import time.\n * This prevents the \"Firebase not initialized\" error during module loading.\n */\nexport const db = new Proxy({} as admin.firestore.Firestore, {\n get(_target, prop, receiver) {\n const firestore = getFirestore();\n const value = Reflect.get(firestore, prop, receiver);\n return typeof value === 'function' ? value.bind(firestore) : value;\n },\n});\n","/**\n * Memory Manager Singleton\n *\n * Provides Firestore-backed memory management for DeepAgent.\n *\n * @packageDocumentation\n */\n\nimport { MemoryManager } from '@almadar-io/agent';\nimport { db } from '../lib/db.js';\n\nlet memoryManager: MemoryManager | null = null;\n\n/**\n * Get or create the MemoryManager singleton\n */\nexport function getMemoryManager(): MemoryManager {\n if (!memoryManager) {\n memoryManager = new MemoryManager({\n db,\n usersCollection: 'agent_memory_users',\n projectsCollection: 'agent_memory_projects',\n generationsCollection: 'agent_memory_generations',\n patternsCollection: 'agent_memory_patterns',\n interruptsCollection: 'agent_memory_interrupts',\n feedbackCollection: 'agent_memory_feedback',\n checkpointsCollection: 'agent_memory_checkpoints',\n toolPreferencesCollection: 'agent_memory_tool_preferences',\n });\n }\n return memoryManager;\n}\n\n/**\n * Reset the MemoryManager (useful for testing)\n */\nexport function resetMemoryManager(): void {\n memoryManager = null;\n}\n","/**\n * Session Manager Singleton\n *\n * Provides Firestore-backed session management with full GAP features.\n *\n * @packageDocumentation\n */\n\nimport { SessionManager } from '@almadar-io/agent';\nimport { db } from '../lib/db.js';\nimport { getMemoryManager } from './memory.js';\nimport type { FirestoreDb } from '@almadar-io/agent';\n\nlet sessionManager: SessionManager | null = null;\n\n/**\n * Adapter to make Firebase Firestore compatible with @almadar/agent FirestoreDb interface\n */\nfunction createFirestoreAdapter(firestore: typeof db): FirestoreDb {\n return firestore as unknown as FirestoreDb;\n}\n\n/**\n * Get or create the SessionManager singleton\n */\nexport function getSessionManager(): SessionManager {\n if (!sessionManager) {\n sessionManager = new SessionManager({\n mode: 'firestore',\n firestoreDb: createFirestoreAdapter(db),\n memoryManager: getMemoryManager(), // Enable GAP-002D\n compactionConfig: {\n maxTokens: 150000,\n keepRecentMessages: 10,\n strategy: 'last',\n },\n });\n }\n return sessionManager;\n}\n\n/**\n * Reset the SessionManager (useful for testing)\n */\nexport function resetSessionManager(): void {\n sessionManager = null;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */
8
- import { type SkillAgentOptions, type SkillAgentResult } from '@almadar/agent';
8
+ import { type SkillAgentOptions, type SkillAgentResult } from '@almadar-io/agent';
9
9
  import { getMemoryManager } from './memory.js';
10
10
  import { getSessionManager } from './session.js';
11
11
  interface ServerSkillAgentOptions extends SkillAgentOptions {
@@ -1 +1 @@
1
- {"version":3,"file":"skill-agent.d.ts","sourceRoot":"","sources":["../../src/deepagent/skill-agent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,UAAU,uBAAwB,SAAQ,iBAAiB;IACzD,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAsD3B;AAGD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"skill-agent.d.ts","sourceRoot":"","sources":["../../src/deepagent/skill-agent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,UAAU,uBAAwB,SAAQ,iBAAiB;IACzD,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAsD3B;AAGD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,4 +1,4 @@
1
- import { MemoryManager, SessionManager, getObservabilityCollector, getMultiUserManager, createWorkflowToolWrapper, createSkillAgent } from '@almadar/agent';
1
+ import { MemoryManager, SessionManager, getObservabilityCollector, getMultiUserManager, createWorkflowToolWrapper, createSkillAgent } from '@almadar-io/agent';
2
2
  import admin from 'firebase-admin';
3
3
 
4
4
  // src/deepagent/skill-agent.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/db.ts","../../src/deepagent/memory.ts","../../src/deepagent/session.ts","../../src/deepagent/skill-agent.ts"],"names":["memoryManager"],"mappings":";;;;AAoFA,SAAS,MAAA,GAAwB;AAC/B,EAAA,IAAI,KAAA,CAAM,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,MAAM,GAAA,EAAI;AACnB;AAKO,SAAS,YAAA,GAA0C;AACxD,EAAA,OAAO,MAAA,GAAS,SAAA,EAAU;AAC5B;AAgBO,IAAM,EAAA,GAAK,IAAI,KAAA,CAAM,EAAC,EAAgC;AAAA,EAC3D,GAAA,CAAI,OAAA,EAAS,IAAA,EAAM,QAAA,EAAU;AAC3B,IAAA,MAAM,YAAY,YAAA,EAAa;AAC/B,IAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,SAAA,EAAW,MAAM,QAAQ,CAAA;AACnD,IAAA,OAAO,OAAO,KAAA,KAAU,UAAA,GAAa,KAAA,CAAM,IAAA,CAAK,SAAS,CAAA,GAAI,KAAA;AAAA,EAC/D;AACF,CAAC,CAAA;;;AC9GD,IAAI,aAAA,GAAsC,IAAA;AAKnC,SAAS,gBAAA,GAAkC;AAChD,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,aAAA,GAAgB,IAAI,aAAA,CAAc;AAAA,MAChC,EAAA;AAAA,MACA,eAAA,EAAiB,oBAAA;AAAA,MACjB,kBAAA,EAAoB,uBAAA;AAAA,MACpB,qBAAA,EAAuB,0BAAA;AAAA,MACvB,kBAAA,EAAoB,uBAAA;AAAA,MACpB,oBAAA,EAAsB,yBAAA;AAAA,MACtB,kBAAA,EAAoB,uBAAA;AAAA,MACpB,qBAA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pE,EAAA,MAAM,sBAAsB,yBAAA,CAA0B;AAAA,IACpD,UAAA,EAAY,CAAA;AAAA,IACZ,eAAA,EAAiB,IAAA;AAAA,IACjB,SAAA,EAAW;AAAA;AAAA,GACZ,CAAA;AAED,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,MAAM,gBAAA,CAAiB;AAAA,MACpC,GAAG,OAAA;AAAA,MACH,aAAA,EAAAA,cAAAA;AAAA;AAAA,MACA,QAAQ,OAAA,CAAQ,MAAA;AAAA;AAAA,MAChB,OAAO,OAAA,CAAQ,KAAA;AAAA,MACf,aAAa,mBAAA,CAAoB;AAAA;AAAA,KAClC,CAAA;AAGD,IAAA,IAAI,OAAO,QAAA,EAAU;AACnB,MAAA,SAAA,CAAU,sBAAA,CAAuB,MAAA,CAAO,QAAA,EAAU,OAAA,CAAQ,MAAM,CAAA;AAAA,IAClE;AAGA,IAAA,aAAA,CAAc,WAAA,CAAY;AAAA,MACxB,IAAA,EAAM,eAAA;AAAA,MACN,WAAW,MAAA,CAAO,QAAA;AAAA,MAClB,QAAQ,OAAA,CAAQ,MAAA;AAAA,MAChB,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,CAAQ,KAAA;AAAM,KACjC,CAAA;AAED,IAAA,OAAO,MAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,aAAA,CAAc,WAAA,CAAY,OAAA,CAAQ,QAAA,IAAY,KAAA,EAAO,KAAc,CAAA;AACnE,IAAA,MAAM,KAAA;AAAA,EACR;AACF","file":"skill-agent.js","sourcesContent":["/**\n * Database Accessors & Initialization\n *\n * This module provides:\n * - `initializeFirebase()` — convenience function to init Firebase from env vars\n * - `getFirestore()`, `getAuth()` — accessors for Firebase services\n * - `db` — lazy Firestore proxy (no eager initialization)\n *\n * The consuming application MUST call `initializeFirebase()` or\n * `admin.initializeApp()` before using any Firebase-dependent features.\n */\n\nimport admin from 'firebase-admin';\n\n/**\n * Initialize Firebase Admin SDK from environment variables.\n *\n * Reads: FIREBASE_PROJECT_ID, FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY,\n * FIREBASE_SERVICE_ACCOUNT_PATH, FIRESTORE_EMULATOR_HOST\n *\n * Safe to call multiple times — returns existing app if already initialized.\n */\nexport function initializeFirebase(): admin.app.App {\n // Already initialized — return existing app\n if (admin.apps.length > 0) {\n return admin.app();\n }\n\n const projectId = process.env.FIREBASE_PROJECT_ID;\n const emulatorHost = process.env.FIRESTORE_EMULATOR_HOST;\n\n // Emulator mode — no credentials needed\n if (emulatorHost) {\n const app = admin.initializeApp({\n projectId: projectId || 'demo-project',\n });\n console.log(`Firebase Admin initialized for emulator: ${emulatorHost}`);\n return app;\n }\n\n // Service account file\n const serviceAccountPath = process.env.FIREBASE_SERVICE_ACCOUNT_PATH;\n if (serviceAccountPath) {\n // Dynamic require for JSON service account file at runtime\n const serviceAccount = require(serviceAccountPath) as Record<string, unknown>;\n return admin.initializeApp({\n credential: admin.credential.cert(serviceAccount),\n projectId,\n });\n }\n\n // Inline credentials\n const clientEmail = process.env.FIREBASE_CLIENT_EMAIL;\n const privateKey = process.env.FIREBASE_PRIVATE_KEY;\n if (projectId && clientEmail && privateKey) {\n return admin.initializeApp({\n credential: admin.credential.cert({\n projectId,\n clientEmail,\n privateKey: privateKey.replace(/\\\\n/g, '\\n'),\n }),\n projectId,\n });\n }\n\n // Application default credentials (Cloud Run, etc.)\n if (projectId) {\n return admin.initializeApp({\n credential: admin.credential.applicationDefault(),\n projectId,\n });\n }\n\n throw new Error(\n '@almadar/server: Cannot initialize Firebase — no credentials found. ' +\n 'Set FIREBASE_PROJECT_ID + FIREBASE_CLIENT_EMAIL + FIREBASE_PRIVATE_KEY, ' +\n 'or FIREBASE_SERVICE_ACCOUNT_PATH, or FIRESTORE_EMULATOR_HOST.'\n );\n}\n\n/**\n * Get the initialized Firebase app.\n * Throws if Firebase Admin SDK has not been initialized.\n */\nfunction getApp(): admin.app.App {\n if (admin.apps.length === 0) {\n throw new Error(\n '@almadar/server: Firebase Admin SDK is not initialized. ' +\n 'Call initializeFirebase() or admin.initializeApp() before using @almadar/server.'\n );\n }\n return admin.app();\n}\n\n/**\n * Get Firestore instance from the pre-initialized Firebase app.\n */\nexport function getFirestore(): admin.firestore.Firestore {\n return getApp().firestore();\n}\n\n/**\n * Get Firebase Auth instance from the pre-initialized Firebase app.\n */\nexport function getAuth(): admin.auth.Auth {\n return getApp().auth();\n}\n\n// Re-export admin for convenience\nexport { admin };\n\n/**\n * Lazy Firestore proxy — resolves on first property access, not at import time.\n * This prevents the \"Firebase not initialized\" error during module loading.\n */\nexport const db = new Proxy({} as admin.firestore.Firestore, {\n get(_target, prop, receiver) {\n const firestore = getFirestore();\n const value = Reflect.get(firestore, prop, receiver);\n return typeof value === 'function' ? value.bind(firestore) : value;\n },\n});\n","/**\n * Memory Manager Singleton\n *\n * Provides Firestore-backed memory management for DeepAgent.\n *\n * @packageDocumentation\n */\n\nimport { MemoryManager } from '@almadar/agent';\nimport { db } from '../lib/db.js';\n\nlet memoryManager: MemoryManager | null = null;\n\n/**\n * Get or create the MemoryManager singleton\n */\nexport function getMemoryManager(): MemoryManager {\n if (!memoryManager) {\n memoryManager = new MemoryManager({\n db,\n usersCollection: 'agent_memory_users',\n projectsCollection: 'agent_memory_projects',\n generationsCollection: 'agent_memory_generations',\n patternsCollection: 'agent_memory_patterns',\n interruptsCollection: 'agent_memory_interrupts',\n feedbackCollection: 'agent_memory_feedback',\n checkpointsCollection: 'agent_memory_checkpoints',\n toolPreferencesCollection: 'agent_memory_tool_preferences',\n });\n }\n return memoryManager;\n}\n\n/**\n * Reset the MemoryManager (useful for testing)\n */\nexport function resetMemoryManager(): void {\n memoryManager = null;\n}\n","/**\n * Session Manager Singleton\n *\n * Provides Firestore-backed session management with full GAP features.\n *\n * @packageDocumentation\n */\n\nimport { SessionManager } from '@almadar/agent';\nimport { db } from '../lib/db.js';\nimport { getMemoryManager } from './memory.js';\nimport type { FirestoreDb } from '@almadar/agent';\n\nlet sessionManager: SessionManager | null = null;\n\n/**\n * Adapter to make Firebase Firestore compatible with @almadar/agent FirestoreDb interface\n */\nfunction createFirestoreAdapter(firestore: typeof db): FirestoreDb {\n return firestore as unknown as FirestoreDb;\n}\n\n/**\n * Get or create the SessionManager singleton\n */\nexport function getSessionManager(): SessionManager {\n if (!sessionManager) {\n sessionManager = new SessionManager({\n mode: 'firestore',\n firestoreDb: createFirestoreAdapter(db),\n memoryManager: getMemoryManager(), // Enable GAP-002D\n compactionConfig: {\n maxTokens: 150000,\n keepRecentMessages: 10,\n strategy: 'last',\n },\n });\n }\n return sessionManager;\n}\n\n/**\n * Reset the SessionManager (useful for testing)\n */\nexport function resetSessionManager(): void {\n sessionManager = null;\n}\n","/**\n * Skill Agent Factory\n *\n * Creates DeepAgent instances with full GAP feature integration.\n *\n * @packageDocumentation\n */\n\nimport {\n createSkillAgent,\n getObservabilityCollector,\n getMultiUserManager,\n createWorkflowToolWrapper,\n type SkillAgentOptions,\n type SkillAgentResult,\n} from '@almadar/agent';\nimport { getMemoryManager } from './memory.js';\nimport { getSessionManager } from './session.js';\n\ninterface ServerSkillAgentOptions extends SkillAgentOptions {\n /** User ID from Firebase Auth */\n userId: string;\n /** App/Project ID for context */\n appId?: string;\n}\n\n/**\n * Create a skill agent with full server-side GAP integration\n */\nexport async function createServerSkillAgent(\n options: ServerSkillAgentOptions,\n): Promise<SkillAgentResult> {\n const memoryManager = getMemoryManager();\n const sessionManager = getSessionManager();\n const observability = getObservabilityCollector();\n const multiUser = getMultiUserManager();\n\n // Check access if resuming existing session\n if (options.threadId) {\n const access = multiUser.canAccessSession(options.threadId, {\n userId: options.userId,\n roles: ['user'],\n });\n if (!access.allowed) {\n throw new Error(`Access denied: ${access.reason}`);\n }\n }\n\n // Start observability\n observability.startSession(options.threadId ?? 'new', options.userId);\n\n // Create workflow tool wrapper for retry/telemetry (always enabled)\n const workflowToolWrapper = createWorkflowToolWrapper({\n maxRetries: 2,\n enableTelemetry: true,\n timeoutMs: 300000, // 5 minutes\n });\n\n try {\n const result = await createSkillAgent({\n ...options,\n memoryManager, // GAP-001: Enable memory\n userId: options.userId, // GAP-002D: Session → Memory sync\n appId: options.appId,\n toolWrapper: workflowToolWrapper.wrap, // Always use workflow wrapper for reliability\n });\n\n // Assign ownership for new sessions\n if (result.threadId) {\n multiUser.assignSessionOwnership(result.threadId, options.userId);\n }\n\n // Record successful creation\n observability.recordEvent({\n type: 'session_start',\n sessionId: result.threadId,\n userId: options.userId,\n payload: { skill: options.skill },\n });\n\n return result;\n } catch (error) {\n observability.recordError(options.threadId ?? 'new', error as Error);\n throw error;\n }\n}\n\n// Re-export for convenience\nexport { getMemoryManager, getSessionManager };\n"]}
1
+ {"version":3,"sources":["../../src/lib/db.ts","../../src/deepagent/memory.ts","../../src/deepagent/session.ts","../../src/deepagent/skill-agent.ts"],"names":["memoryManager"],"mappings":";;;;AAoFA,SAAS,MAAA,GAAwB;AAC/B,EAAA,IAAI,KAAA,CAAM,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACA,EAAA,OAAO,MAAM,GAAA,EAAI;AACnB;AAKO,SAAS,YAAA,GAA0C;AACxD,EAAA,OAAO,MAAA,GAAS,SAAA,EAAU;AAC5B;AAgBO,IAAM,EAAA,GAAK,IAAI,KAAA,CAAM,EAAC,EAAgC;AAAA,EAC3D,GAAA,CAAI,OAAA,EAAS,IAAA,EAAM,QAAA,EAAU;AAC3B,IAAA,MAAM,YAAY,YAAA,EAAa;AAC/B,IAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,SAAA,EAAW,MAAM,QAAQ,CAAA;AACnD,IAAA,OAAO,OAAO,KAAA,KAAU,UAAA,GAAa,KAAA,CAAM,IAAA,CAAK,SAAS,CAAA,GAAI,KAAA;AAAA,EAC/D;AACF,CAAC,CAAA;;;AC9GD,IAAI,aAAA,GAAsC,IAAA;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KAAc,CAAA;AACnE,IAAA,MAAM,KAAA;AAAA,EACR;AACF","file":"skill-agent.js","sourcesContent":["/**\n * Database Accessors & Initialization\n *\n * This module provides:\n * - `initializeFirebase()` — convenience function to init Firebase from env vars\n * - `getFirestore()`, `getAuth()` — accessors for Firebase services\n * - `db` — lazy Firestore proxy (no eager initialization)\n *\n * The consuming application MUST call `initializeFirebase()` or\n * `admin.initializeApp()` before using any Firebase-dependent features.\n */\n\nimport admin from 'firebase-admin';\n\n/**\n * Initialize Firebase Admin SDK from environment variables.\n *\n * Reads: FIREBASE_PROJECT_ID, FIREBASE_CLIENT_EMAIL, FIREBASE_PRIVATE_KEY,\n * FIREBASE_SERVICE_ACCOUNT_PATH, FIRESTORE_EMULATOR_HOST\n *\n * Safe to call multiple times — returns existing app if already initialized.\n */\nexport function initializeFirebase(): admin.app.App {\n // Already initialized — return existing app\n if (admin.apps.length > 0) {\n return admin.app();\n }\n\n const projectId = process.env.FIREBASE_PROJECT_ID;\n const emulatorHost = process.env.FIRESTORE_EMULATOR_HOST;\n\n // Emulator mode — no credentials needed\n if (emulatorHost) {\n const app = admin.initializeApp({\n projectId: projectId || 'demo-project',\n });\n console.log(`Firebase Admin initialized for emulator: ${emulatorHost}`);\n return app;\n }\n\n // Service account file\n const serviceAccountPath = process.env.FIREBASE_SERVICE_ACCOUNT_PATH;\n if (serviceAccountPath) {\n // Dynamic require for JSON service account file at runtime\n const serviceAccount = require(serviceAccountPath) as Record<string, unknown>;\n return admin.initializeApp({\n credential: admin.credential.cert(serviceAccount),\n projectId,\n });\n }\n\n // Inline credentials\n const clientEmail = process.env.FIREBASE_CLIENT_EMAIL;\n const privateKey = process.env.FIREBASE_PRIVATE_KEY;\n if (projectId && clientEmail && privateKey) {\n return admin.initializeApp({\n credential: admin.credential.cert({\n projectId,\n clientEmail,\n privateKey: privateKey.replace(/\\\\n/g, '\\n'),\n }),\n projectId,\n });\n }\n\n // Application default credentials (Cloud Run, etc.)\n if (projectId) {\n return admin.initializeApp({\n credential: admin.credential.applicationDefault(),\n projectId,\n });\n }\n\n throw new Error(\n '@almadar/server: Cannot initialize Firebase — no credentials found. ' +\n 'Set FIREBASE_PROJECT_ID + FIREBASE_CLIENT_EMAIL + FIREBASE_PRIVATE_KEY, ' +\n 'or FIREBASE_SERVICE_ACCOUNT_PATH, or FIRESTORE_EMULATOR_HOST.'\n );\n}\n\n/**\n * Get the initialized Firebase app.\n * Throws if Firebase Admin SDK has not been initialized.\n */\nfunction getApp(): admin.app.App {\n if (admin.apps.length === 0) {\n throw new Error(\n '@almadar/server: Firebase Admin SDK is not initialized. ' +\n 'Call initializeFirebase() or admin.initializeApp() before using @almadar/server.'\n );\n }\n return admin.app();\n}\n\n/**\n * Get Firestore instance from the pre-initialized Firebase app.\n */\nexport function getFirestore(): admin.firestore.Firestore {\n return getApp().firestore();\n}\n\n/**\n * Get Firebase Auth instance from the pre-initialized Firebase app.\n */\nexport function getAuth(): admin.auth.Auth {\n return getApp().auth();\n}\n\n// Re-export admin for convenience\nexport { admin };\n\n/**\n * Lazy Firestore proxy — resolves on first property access, not at import time.\n * This prevents the \"Firebase not initialized\" error during module loading.\n */\nexport const db = new Proxy({} as admin.firestore.Firestore, {\n get(_target, prop, receiver) {\n const firestore = getFirestore();\n const value = Reflect.get(firestore, prop, receiver);\n return typeof value === 'function' ? value.bind(firestore) : value;\n },\n});\n","/**\n * Memory Manager Singleton\n *\n * Provides Firestore-backed memory management for DeepAgent.\n *\n * @packageDocumentation\n */\n\nimport { MemoryManager } from '@almadar-io/agent';\nimport { db } from '../lib/db.js';\n\nlet memoryManager: MemoryManager | null = null;\n\n/**\n * Get or create the MemoryManager singleton\n */\nexport function getMemoryManager(): MemoryManager {\n if (!memoryManager) {\n memoryManager = new MemoryManager({\n db,\n usersCollection: 'agent_memory_users',\n projectsCollection: 'agent_memory_projects',\n generationsCollection: 'agent_memory_generations',\n patternsCollection: 'agent_memory_patterns',\n interruptsCollection: 'agent_memory_interrupts',\n feedbackCollection: 'agent_memory_feedback',\n checkpointsCollection: 'agent_memory_checkpoints',\n toolPreferencesCollection: 'agent_memory_tool_preferences',\n });\n }\n return memoryManager;\n}\n\n/**\n * Reset the MemoryManager (useful for testing)\n */\nexport function resetMemoryManager(): void {\n memoryManager = null;\n}\n","/**\n * Session Manager Singleton\n *\n * Provides Firestore-backed session management with full GAP features.\n *\n * @packageDocumentation\n */\n\nimport { SessionManager } from '@almadar-io/agent';\nimport { db } from '../lib/db.js';\nimport { getMemoryManager } from './memory.js';\nimport type { FirestoreDb } from '@almadar-io/agent';\n\nlet sessionManager: SessionManager | null = null;\n\n/**\n * Adapter to make Firebase Firestore compatible with @almadar/agent FirestoreDb interface\n */\nfunction createFirestoreAdapter(firestore: typeof db): FirestoreDb {\n return firestore as unknown as FirestoreDb;\n}\n\n/**\n * Get or create the SessionManager singleton\n */\nexport function getSessionManager(): SessionManager {\n if (!sessionManager) {\n sessionManager = new SessionManager({\n mode: 'firestore',\n firestoreDb: createFirestoreAdapter(db),\n memoryManager: getMemoryManager(), // Enable GAP-002D\n compactionConfig: {\n maxTokens: 150000,\n keepRecentMessages: 10,\n strategy: 'last',\n },\n });\n }\n return sessionManager;\n}\n\n/**\n * Reset the SessionManager (useful for testing)\n */\nexport function resetSessionManager(): void {\n sessionManager = null;\n}\n","/**\n * Skill Agent Factory\n *\n * Creates DeepAgent instances with full GAP feature integration.\n *\n * @packageDocumentation\n */\n\nimport {\n createSkillAgent,\n getObservabilityCollector,\n getMultiUserManager,\n createWorkflowToolWrapper,\n type SkillAgentOptions,\n type SkillAgentResult,\n} from '@almadar-io/agent';\nimport { getMemoryManager } from './memory.js';\nimport { getSessionManager } from './session.js';\n\ninterface ServerSkillAgentOptions extends SkillAgentOptions {\n /** User ID from Firebase Auth */\n userId: string;\n /** App/Project ID for context */\n appId?: string;\n}\n\n/**\n * Create a skill agent with full server-side GAP integration\n */\nexport async function createServerSkillAgent(\n options: ServerSkillAgentOptions,\n): Promise<SkillAgentResult> {\n const memoryManager = getMemoryManager();\n const sessionManager = getSessionManager();\n const observability = getObservabilityCollector();\n const multiUser = getMultiUserManager();\n\n // Check access if resuming existing session\n if (options.threadId) {\n const access = multiUser.canAccessSession(options.threadId, {\n userId: options.userId,\n roles: ['user'],\n });\n if (!access.allowed) {\n throw new Error(`Access denied: ${access.reason}`);\n }\n }\n\n // Start observability\n observability.startSession(options.threadId ?? 'new', options.userId);\n\n // Create workflow tool wrapper for retry/telemetry (always enabled)\n const workflowToolWrapper = createWorkflowToolWrapper({\n maxRetries: 2,\n enableTelemetry: true,\n timeoutMs: 300000, // 5 minutes\n });\n\n try {\n const result = await createSkillAgent({\n ...options,\n memoryManager, // GAP-001: Enable memory\n userId: options.userId, // GAP-002D: Session → Memory sync\n appId: options.appId,\n toolWrapper: workflowToolWrapper.wrap, // Always use workflow wrapper for reliability\n });\n\n // Assign ownership for new sessions\n if (result.threadId) {\n multiUser.assignSessionOwnership(result.threadId, options.userId);\n }\n\n // Record successful creation\n observability.recordEvent({\n type: 'session_start',\n sessionId: result.threadId,\n userId: options.userId,\n payload: { skill: options.skill },\n });\n\n return result;\n } catch (error) {\n observability.recordError(options.threadId ?? 'new', error as Error);\n throw error;\n }\n}\n\n// Re-export for convenience\nexport { getMemoryManager, getSessionManager };\n"]}