@almadar/server 2.1.0 → 2.1.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.
Files changed (103) hide show
  1. package/package.json +1 -1
  2. package/dist/contracts.d.ts +0 -174
  3. package/dist/contracts.d.ts.map +0 -1
  4. package/dist/deepagent/__tests__/memory.test.d.ts +0 -6
  5. package/dist/deepagent/__tests__/memory.test.d.ts.map +0 -1
  6. package/dist/deepagent/__tests__/session.test.d.ts +0 -6
  7. package/dist/deepagent/__tests__/session.test.d.ts.map +0 -1
  8. package/dist/deepagent/__tests__/skill-agent.test.d.ts +0 -6
  9. package/dist/deepagent/__tests__/skill-agent.test.d.ts.map +0 -1
  10. package/dist/deepagent/memory.d.ts +0 -17
  11. package/dist/deepagent/memory.d.ts.map +0 -1
  12. package/dist/deepagent/memory.js +0 -48
  13. package/dist/deepagent/memory.js.map +0 -1
  14. package/dist/deepagent/session.d.ts +0 -17
  15. package/dist/deepagent/session.d.ts.map +0 -1
  16. package/dist/deepagent/session.js +0 -68
  17. package/dist/deepagent/session.js.map +0 -1
  18. package/dist/deepagent/skill-agent.d.ts +0 -22
  19. package/dist/deepagent/skill-agent.d.ts.map +0 -1
  20. package/dist/deepagent/skill-agent.js +0 -114
  21. package/dist/deepagent/skill-agent.js.map +0 -1
  22. package/dist/index.js +0 -2598
  23. package/dist/index.js.map +0 -1
  24. package/dist/lib/db.d.ts +0 -36
  25. package/dist/lib/db.d.ts.map +0 -1
  26. package/dist/lib/debugRouter.d.ts +0 -21
  27. package/dist/lib/debugRouter.d.ts.map +0 -1
  28. package/dist/lib/env.d.ts +0 -16
  29. package/dist/lib/env.d.ts.map +0 -1
  30. package/dist/lib/eventBus.d.ts +0 -44
  31. package/dist/lib/eventBus.d.ts.map +0 -1
  32. package/dist/lib/eventBusTransport.d.ts +0 -143
  33. package/dist/lib/eventBusTransport.d.ts.map +0 -1
  34. package/dist/lib/eventPersistence.d.ts +0 -151
  35. package/dist/lib/eventPersistence.d.ts.map +0 -1
  36. package/dist/lib/index.d.ts +0 -6
  37. package/dist/lib/index.d.ts.map +0 -1
  38. package/dist/lib/index.js +0 -288
  39. package/dist/lib/index.js.map +0 -1
  40. package/dist/lib/logger.d.ts +0 -7
  41. package/dist/lib/logger.d.ts.map +0 -1
  42. package/dist/lib/serviceDiscovery.d.ts +0 -168
  43. package/dist/lib/serviceDiscovery.d.ts.map +0 -1
  44. package/dist/lib/websocket.d.ts +0 -41
  45. package/dist/lib/websocket.d.ts.map +0 -1
  46. package/dist/middleware/__tests__/multi-user.test.d.ts +0 -6
  47. package/dist/middleware/__tests__/multi-user.test.d.ts.map +0 -1
  48. package/dist/middleware/authenticateFirebase.d.ts +0 -4
  49. package/dist/middleware/authenticateFirebase.d.ts.map +0 -1
  50. package/dist/middleware/errorHandler.d.ts +0 -53
  51. package/dist/middleware/errorHandler.d.ts.map +0 -1
  52. package/dist/middleware/index.d.ts +0 -4
  53. package/dist/middleware/index.d.ts.map +0 -1
  54. package/dist/middleware/index.js +0 -284
  55. package/dist/middleware/index.js.map +0 -1
  56. package/dist/middleware/multi-user.d.ts +0 -34
  57. package/dist/middleware/multi-user.d.ts.map +0 -1
  58. package/dist/middleware/multi-user.js +0 -76
  59. package/dist/middleware/multi-user.js.map +0 -1
  60. package/dist/middleware/validation.d.ts +0 -15
  61. package/dist/middleware/validation.d.ts.map +0 -1
  62. package/dist/routes/__tests__/observability.test.d.ts +0 -6
  63. package/dist/routes/__tests__/observability.test.d.ts.map +0 -1
  64. package/dist/routes/observability.d.ts +0 -11
  65. package/dist/routes/observability.d.ts.map +0 -1
  66. package/dist/routes/observability.js +0 -62
  67. package/dist/routes/observability.js.map +0 -1
  68. package/dist/services/DataService.d.ts +0 -70
  69. package/dist/services/DataService.d.ts.map +0 -1
  70. package/dist/services/MockDataService.d.ts +0 -110
  71. package/dist/services/MockDataService.d.ts.map +0 -1
  72. package/dist/services/index.d.ts +0 -8
  73. package/dist/services/index.d.ts.map +0 -1
  74. package/dist/services/index.js +0 -735
  75. package/dist/services/index.js.map +0 -1
  76. package/dist/stores/ChangeSetStore.d.ts +0 -24
  77. package/dist/stores/ChangeSetStore.d.ts.map +0 -1
  78. package/dist/stores/SchemaProtectionService.d.ts +0 -23
  79. package/dist/stores/SchemaProtectionService.d.ts.map +0 -1
  80. package/dist/stores/SchemaStore.d.ts +0 -52
  81. package/dist/stores/SchemaStore.d.ts.map +0 -1
  82. package/dist/stores/SnapshotStore.d.ts +0 -26
  83. package/dist/stores/SnapshotStore.d.ts.map +0 -1
  84. package/dist/stores/ValidationStore.d.ts +0 -19
  85. package/dist/stores/ValidationStore.d.ts.map +0 -1
  86. package/dist/stores/firestoreFormat.d.ts +0 -21
  87. package/dist/stores/firestoreFormat.d.ts.map +0 -1
  88. package/dist/stores/index.d.ts +0 -14
  89. package/dist/stores/index.d.ts.map +0 -1
  90. package/dist/stores/index.js +0 -519
  91. package/dist/stores/index.js.map +0 -1
  92. package/dist/utils/index.d.ts +0 -9
  93. package/dist/utils/index.d.ts.map +0 -1
  94. package/dist/utils/index.js +0 -106
  95. package/dist/utils/index.js.map +0 -1
  96. package/dist/utils/queryFilters.d.ts +0 -87
  97. package/dist/utils/queryFilters.d.ts.map +0 -1
  98. package/dist/websocket/__tests__/state-sync.test.d.ts +0 -6
  99. package/dist/websocket/__tests__/state-sync.test.d.ts.map +0 -1
  100. package/dist/websocket/state-sync.d.ts +0 -39
  101. package/dist/websocket/state-sync.d.ts.map +0 -1
  102. package/dist/websocket/state-sync.js +0 -77
  103. package/dist/websocket/state-sync.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/server",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Shared server infrastructure for Almadar applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,174 +0,0 @@
1
- /**
2
- * Server Service Contracts
3
- *
4
- * Type-safe contract definitions for the three main services
5
- * callable from .orb schemas via `["call-service", ...]`.
6
- *
7
- * Each contract maps action names to their params/result types,
8
- * and the corresponding `ServiceContract<Actions>` type ensures
9
- * the runtime `execute(action, params)` call is fully typed.
10
- *
11
- * @packageDocumentation
12
- */
13
- import type { ServiceContract, ServiceEvents } from '@almadar/core';
14
- /** Actions available on the data service (CRUD over collections). */
15
- export type DataServiceActions = {
16
- list: {
17
- params: {
18
- collection: string;
19
- };
20
- result: {
21
- items: unknown[];
22
- };
23
- };
24
- getById: {
25
- params: {
26
- collection: string;
27
- id: string;
28
- };
29
- result: {
30
- item: unknown | null;
31
- };
32
- };
33
- create: {
34
- params: {
35
- collection: string;
36
- data: Record<string, unknown>;
37
- };
38
- result: {
39
- item: unknown;
40
- };
41
- };
42
- update: {
43
- params: {
44
- collection: string;
45
- id: string;
46
- data: Record<string, unknown>;
47
- };
48
- result: {
49
- item: unknown | null;
50
- };
51
- };
52
- delete: {
53
- params: {
54
- collection: string;
55
- id: string;
56
- };
57
- result: {
58
- deleted: boolean;
59
- };
60
- };
61
- };
62
- /** Typed contract for the data service. */
63
- export type DataServiceContract = ServiceContract<DataServiceActions>;
64
- /** Actions available on the event bus service. */
65
- export type EventBusActions = {
66
- emit: {
67
- params: {
68
- event: string;
69
- payload?: unknown;
70
- };
71
- result: {
72
- delivered: number;
73
- };
74
- };
75
- getListenerCounts: {
76
- params: Record<string, never>;
77
- result: {
78
- counts: Record<string, number>;
79
- };
80
- };
81
- };
82
- /** Typed contract for the event bus service. */
83
- export type EventBusServiceContract = ServiceContract<EventBusActions>;
84
- /** Shape of a discovered service instance. */
85
- interface DiscoveredService {
86
- name: string;
87
- instanceId: string;
88
- host: string;
89
- port: number;
90
- }
91
- /** Actions available on the service discovery service. */
92
- export type ServiceDiscoveryActions = {
93
- register: {
94
- params: {
95
- name: string;
96
- instanceId: string;
97
- host: string;
98
- port: number;
99
- emits: string[];
100
- listens: string[];
101
- };
102
- result: {
103
- registered: boolean;
104
- };
105
- };
106
- findListeners: {
107
- params: {
108
- event: string;
109
- };
110
- result: {
111
- services: DiscoveredService[];
112
- };
113
- };
114
- findEmitters: {
115
- params: {
116
- event: string;
117
- };
118
- result: {
119
- services: DiscoveredService[];
120
- };
121
- };
122
- };
123
- /** Typed contract for the service discovery service. */
124
- export type ServiceDiscoveryContract = ServiceContract<ServiceDiscoveryActions>;
125
- /** Events emitted by entity CRUD operations. */
126
- export type EntityCrudEventMap = {
127
- [K in `${string}_CREATED`]: Record<string, unknown>;
128
- } & {
129
- [K in `${string}_UPDATED`]: Record<string, unknown>;
130
- } & {
131
- [K in `${string}_DELETED`]: Record<string, unknown>;
132
- };
133
- /** Events emitted/consumed by the server infrastructure. */
134
- export type ServerEventMap = {
135
- /** Emitted when a service instance registers with ServiceDiscovery. */
136
- SERVICE_REGISTERED: {
137
- name: string;
138
- instanceId: string;
139
- host: string;
140
- port: number;
141
- };
142
- /** Emitted when a service instance deregisters or expires. */
143
- SERVICE_DEREGISTERED: {
144
- name: string;
145
- instanceId: string;
146
- reason: 'explicit' | 'expired';
147
- };
148
- /** Emitted when a service health check fails. */
149
- SERVICE_HEALTH_FAILED: {
150
- name: string;
151
- instanceId: string;
152
- error: string;
153
- };
154
- /** Emitted when the distributed event bus connects. */
155
- TRANSPORT_CONNECTED: {
156
- instanceId: string;
157
- transport: string;
158
- };
159
- /** Emitted when the distributed event bus disconnects. */
160
- TRANSPORT_DISCONNECTED: {
161
- instanceId: string;
162
- reason: string;
163
- };
164
- };
165
- /** Typed event emitter for server events. */
166
- export type ServerServiceEvents = ServiceEvents<ServerEventMap>;
167
- /** All server service contracts keyed by service name. */
168
- export type ServerServiceContracts = {
169
- data: DataServiceContract;
170
- eventBus: EventBusServiceContract;
171
- serviceDiscovery: ServiceDiscoveryContract;
172
- };
173
- export {};
174
- //# sourceMappingURL=contracts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../src/contracts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;A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AAC7C,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;AAMhE,0DAA0D;AAC1D,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,EAAE,uBAAuB,CAAC;IAClC,gBAAgB,EAAE,wBAAwB,CAAC;CAC5C,CAAC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * @fileoverview Unit tests for MemoryManager integration
3
- * @module @almadar/server/deepagent/memory.test
4
- */
5
- export {};
6
- //# sourceMappingURL=memory.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.test.d.ts","sourceRoot":"","sources":["../../../src/deepagent/__tests__/memory.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -1,6 +0,0 @@
1
- /**
2
- * @fileoverview Unit tests for SessionManager integration
3
- * @module @almadar/server/deepagent/session.test
4
- */
5
- export {};
6
- //# sourceMappingURL=session.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session.test.d.ts","sourceRoot":"","sources":["../../../src/deepagent/__tests__/session.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -1,6 +0,0 @@
1
- /**
2
- * @fileoverview Unit tests for skill agent factory
3
- * @module @almadar/server/deepagent/skill-agent.test
4
- */
5
- export {};
6
- //# sourceMappingURL=skill-agent.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"skill-agent.test.d.ts","sourceRoot":"","sources":["../../../src/deepagent/__tests__/skill-agent.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -1,17 +0,0 @@
1
- /**
2
- * Memory Manager Singleton
3
- *
4
- * Provides Firestore-backed memory management for DeepAgent.
5
- *
6
- * @packageDocumentation
7
- */
8
- import { MemoryManager } from '@almadar-io/agent';
9
- /**
10
- * Get or create the MemoryManager singleton
11
- */
12
- export declare function getMemoryManager(): MemoryManager;
13
- /**
14
- * Reset the MemoryManager (useful for testing)
15
- */
16
- export declare function resetMemoryManager(): void;
17
- //# sourceMappingURL=memory.d.ts.map
@@ -1 +0,0 @@
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,48 +0,0 @@
1
- import { MemoryManager } from '@almadar-io/agent';
2
- import admin from 'firebase-admin';
3
-
4
- // src/deepagent/memory.ts
5
- function getApp() {
6
- if (admin.apps.length === 0) {
7
- throw new Error(
8
- "@almadar/server: Firebase Admin SDK is not initialized. Call initializeFirebase() or admin.initializeApp() before using @almadar/server."
9
- );
10
- }
11
- return admin.app();
12
- }
13
- function getFirestore() {
14
- return getApp().firestore();
15
- }
16
- var db = new Proxy({}, {
17
- get(_target, prop, receiver) {
18
- const firestore = getFirestore();
19
- const value = Reflect.get(firestore, prop, receiver);
20
- return typeof value === "function" ? value.bind(firestore) : value;
21
- }
22
- });
23
-
24
- // src/deepagent/memory.ts
25
- var memoryManager = null;
26
- function getMemoryManager() {
27
- if (!memoryManager) {
28
- memoryManager = new MemoryManager({
29
- db,
30
- usersCollection: "agent_memory_users",
31
- projectsCollection: "agent_memory_projects",
32
- generationsCollection: "agent_memory_generations",
33
- patternsCollection: "agent_memory_patterns",
34
- interruptsCollection: "agent_memory_interrupts",
35
- feedbackCollection: "agent_memory_feedback",
36
- checkpointsCollection: "agent_memory_checkpoints",
37
- toolPreferencesCollection: "agent_memory_tool_preferences"
38
- });
39
- }
40
- return memoryManager;
41
- }
42
- function resetMemoryManager() {
43
- memoryManager = null;
44
- }
45
-
46
- export { getMemoryManager, resetMemoryManager };
47
- //# sourceMappingURL=memory.js.map
48
- //# sourceMappingURL=memory.js.map
@@ -1 +0,0 @@
1
- {"version":3,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AAA;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"]}
@@ -1,17 +0,0 @@
1
- /**
2
- * Session Manager Singleton
3
- *
4
- * Provides Firestore-backed session management with full GAP features.
5
- *
6
- * @packageDocumentation
7
- */
8
- import { SessionManager } from '@almadar-io/agent';
9
- /**
10
- * Get or create the SessionManager singleton
11
- */
12
- export declare function getSessionManager(): SessionManager;
13
- /**
14
- * Reset the SessionManager (useful for testing)
15
- */
16
- export declare function resetSessionManager(): void;
17
- //# sourceMappingURL=session.d.ts.map
@@ -1 +0,0 @@
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,68 +0,0 @@
1
- import { SessionManager, MemoryManager } from '@almadar-io/agent';
2
- import admin from 'firebase-admin';
3
-
4
- // src/deepagent/session.ts
5
- function getApp() {
6
- if (admin.apps.length === 0) {
7
- throw new Error(
8
- "@almadar/server: Firebase Admin SDK is not initialized. Call initializeFirebase() or admin.initializeApp() before using @almadar/server."
9
- );
10
- }
11
- return admin.app();
12
- }
13
- function getFirestore() {
14
- return getApp().firestore();
15
- }
16
- var db = new Proxy({}, {
17
- get(_target, prop, receiver) {
18
- const firestore = getFirestore();
19
- const value = Reflect.get(firestore, prop, receiver);
20
- return typeof value === "function" ? value.bind(firestore) : value;
21
- }
22
- });
23
- var memoryManager = null;
24
- function getMemoryManager() {
25
- if (!memoryManager) {
26
- memoryManager = new MemoryManager({
27
- db,
28
- usersCollection: "agent_memory_users",
29
- projectsCollection: "agent_memory_projects",
30
- generationsCollection: "agent_memory_generations",
31
- patternsCollection: "agent_memory_patterns",
32
- interruptsCollection: "agent_memory_interrupts",
33
- feedbackCollection: "agent_memory_feedback",
34
- checkpointsCollection: "agent_memory_checkpoints",
35
- toolPreferencesCollection: "agent_memory_tool_preferences"
36
- });
37
- }
38
- return memoryManager;
39
- }
40
-
41
- // src/deepagent/session.ts
42
- var sessionManager = null;
43
- function createFirestoreAdapter(firestore) {
44
- return firestore;
45
- }
46
- function getSessionManager() {
47
- if (!sessionManager) {
48
- sessionManager = new SessionManager({
49
- mode: "firestore",
50
- firestoreDb: createFirestoreAdapter(db),
51
- memoryManager: getMemoryManager(),
52
- // Enable GAP-002D
53
- compactionConfig: {
54
- maxTokens: 15e4,
55
- keepRecentMessages: 10,
56
- strategy: "last"
57
- }
58
- });
59
- }
60
- return sessionManager;
61
- }
62
- function resetSessionManager() {
63
- sessionManager = null;
64
- }
65
-
66
- export { getSessionManager, resetSessionManager };
67
- //# sourceMappingURL=session.js.map
68
- //# sourceMappingURL=session.js.map
@@ -1 +0,0 @@
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,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;;;AClBA,IAAI,cAAA,GAAwC,IAAA;AAK5C,SAAS,uBAAuB,SAAA,EAAmC;AACjE,EAAA,OAAO,SAAA;AACT;AAKO,SAAS,iBAAA,GAAoC;AAClD,EAAA,IAAI,CAAC,cAAA,EAAgB;AACnB,IAAA,cAAA,GAAiB,IAAI,cAAA,CAAe;AAAA,MAClC,IAAA,EAAM,WAAA;AAAA,MACN,WAAA,EAAa,uBAAuB,EAAE,CAAA;AAAA,MACtC,eAAe,gBAAA,EAAiB;AAAA;AAAA,MAChC,gBAAA,EAAkB;AAAA,QAChB,SAAA,EAAW,IAAA;AAAA,QACX,kBAAA,EAAoB,EAAA;AAAA,QACpB,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"]}
@@ -1,22 +0,0 @@
1
- /**
2
- * Skill Agent Factory
3
- *
4
- * Creates DeepAgent instances with full GAP feature integration.
5
- *
6
- * @packageDocumentation
7
- */
8
- import { type SkillAgentOptions, type SkillAgentResult } from '@almadar-io/agent';
9
- import { getMemoryManager } from './memory.js';
10
- import { getSessionManager } from './session.js';
11
- interface ServerSkillAgentOptions extends SkillAgentOptions {
12
- /** User ID from Firebase Auth */
13
- userId: string;
14
- /** App/Project ID for context */
15
- appId?: string;
16
- }
17
- /**
18
- * Create a skill agent with full server-side GAP integration
19
- */
20
- export declare function createServerSkillAgent(options: ServerSkillAgentOptions): Promise<SkillAgentResult>;
21
- export { getMemoryManager, getSessionManager };
22
- //# sourceMappingURL=skill-agent.d.ts.map
@@ -1 +0,0 @@
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,114 +0,0 @@
1
- import { MemoryManager, SessionManager, getObservabilityCollector, getMultiUserManager, createWorkflowToolWrapper, createSkillAgent } from '@almadar-io/agent';
2
- import admin from 'firebase-admin';
3
-
4
- // src/deepagent/skill-agent.ts
5
- function getApp() {
6
- if (admin.apps.length === 0) {
7
- throw new Error(
8
- "@almadar/server: Firebase Admin SDK is not initialized. Call initializeFirebase() or admin.initializeApp() before using @almadar/server."
9
- );
10
- }
11
- return admin.app();
12
- }
13
- function getFirestore() {
14
- return getApp().firestore();
15
- }
16
- var db = new Proxy({}, {
17
- get(_target, prop, receiver) {
18
- const firestore = getFirestore();
19
- const value = Reflect.get(firestore, prop, receiver);
20
- return typeof value === "function" ? value.bind(firestore) : value;
21
- }
22
- });
23
-
24
- // src/deepagent/memory.ts
25
- var memoryManager = null;
26
- function getMemoryManager() {
27
- if (!memoryManager) {
28
- memoryManager = new MemoryManager({
29
- db,
30
- usersCollection: "agent_memory_users",
31
- projectsCollection: "agent_memory_projects",
32
- generationsCollection: "agent_memory_generations",
33
- patternsCollection: "agent_memory_patterns",
34
- interruptsCollection: "agent_memory_interrupts",
35
- feedbackCollection: "agent_memory_feedback",
36
- checkpointsCollection: "agent_memory_checkpoints",
37
- toolPreferencesCollection: "agent_memory_tool_preferences"
38
- });
39
- }
40
- return memoryManager;
41
- }
42
- var sessionManager = null;
43
- function createFirestoreAdapter(firestore) {
44
- return firestore;
45
- }
46
- function getSessionManager() {
47
- if (!sessionManager) {
48
- sessionManager = new SessionManager({
49
- mode: "firestore",
50
- firestoreDb: createFirestoreAdapter(db),
51
- memoryManager: getMemoryManager(),
52
- // Enable GAP-002D
53
- compactionConfig: {
54
- maxTokens: 15e4,
55
- keepRecentMessages: 10,
56
- strategy: "last"
57
- }
58
- });
59
- }
60
- return sessionManager;
61
- }
62
-
63
- // src/deepagent/skill-agent.ts
64
- async function createServerSkillAgent(options) {
65
- const memoryManager2 = getMemoryManager();
66
- getSessionManager();
67
- const observability = getObservabilityCollector();
68
- const multiUser = getMultiUserManager();
69
- if (options.threadId) {
70
- const access = multiUser.canAccessSession(options.threadId, {
71
- userId: options.userId,
72
- roles: ["user"]
73
- });
74
- if (!access.allowed) {
75
- throw new Error(`Access denied: ${access.reason}`);
76
- }
77
- }
78
- observability.startSession(options.threadId ?? "new", options.userId);
79
- const workflowToolWrapper = createWorkflowToolWrapper({
80
- maxRetries: 2,
81
- enableTelemetry: true,
82
- timeoutMs: 3e5
83
- // 5 minutes
84
- });
85
- try {
86
- const result = await createSkillAgent({
87
- ...options,
88
- memoryManager: memoryManager2,
89
- // GAP-001: Enable memory
90
- userId: options.userId,
91
- // GAP-002D: Session → Memory sync
92
- appId: options.appId,
93
- toolWrapper: workflowToolWrapper.wrap
94
- // Always use workflow wrapper for reliability
95
- });
96
- if (result.threadId) {
97
- multiUser.assignSessionOwnership(result.threadId, options.userId);
98
- }
99
- observability.recordEvent({
100
- type: "session_start",
101
- sessionId: result.threadId,
102
- userId: options.userId,
103
- payload: { skill: options.skill }
104
- });
105
- return result;
106
- } catch (error) {
107
- observability.recordError(options.threadId ?? "new", error);
108
- throw error;
109
- }
110
- }
111
-
112
- export { createServerSkillAgent, getMemoryManager, getSessionManager };
113
- //# sourceMappingURL=skill-agent.js.map
114
- //# sourceMappingURL=skill-agent.js.map
@@ -1 +0,0 @@
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,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,CAAA;AAGpE,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-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"]}