@affectively/aeon 1.0.0 → 1.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.
- package/README.md +10 -0
- package/dist/compression/index.cjs +580 -0
- package/dist/compression/index.cjs.map +1 -0
- package/dist/compression/index.d.cts +189 -0
- package/dist/compression/index.d.ts +189 -0
- package/dist/compression/index.js +573 -0
- package/dist/compression/index.js.map +1 -0
- package/dist/crypto/index.cjs +100 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.cts +407 -0
- package/dist/crypto/index.d.ts +407 -0
- package/dist/crypto/index.js +96 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/distributed/index.cjs +420 -23
- package/dist/distributed/index.cjs.map +1 -1
- package/dist/distributed/index.d.cts +901 -2
- package/dist/distributed/index.d.ts +901 -2
- package/dist/distributed/index.js +420 -23
- package/dist/distributed/index.js.map +1 -1
- package/dist/index.cjs +1071 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -811
- package/dist/index.d.ts +11 -811
- package/dist/index.js +1070 -56
- package/dist/index.js.map +1 -1
- package/dist/offline/index.cjs +419 -0
- package/dist/offline/index.cjs.map +1 -0
- package/dist/offline/index.d.cts +148 -0
- package/dist/offline/index.d.ts +148 -0
- package/dist/offline/index.js +415 -0
- package/dist/offline/index.js.map +1 -0
- package/dist/optimization/index.cjs +797 -0
- package/dist/optimization/index.cjs.map +1 -0
- package/dist/optimization/index.d.cts +347 -0
- package/dist/optimization/index.d.ts +347 -0
- package/dist/optimization/index.js +787 -0
- package/dist/optimization/index.js.map +1 -0
- package/dist/persistence/index.cjs +145 -0
- package/dist/persistence/index.cjs.map +1 -0
- package/dist/persistence/index.d.cts +63 -0
- package/dist/persistence/index.d.ts +63 -0
- package/dist/persistence/index.js +142 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/presence/index.cjs +338 -0
- package/dist/presence/index.cjs.map +1 -0
- package/dist/presence/index.d.cts +168 -0
- package/dist/presence/index.d.ts +168 -0
- package/dist/presence/index.js +334 -0
- package/dist/presence/index.js.map +1 -0
- package/dist/types-CMxO7QF0.d.cts +33 -0
- package/dist/types-CMxO7QF0.d.ts +33 -0
- package/dist/versioning/index.cjs +296 -14
- package/dist/versioning/index.cjs.map +1 -1
- package/dist/versioning/index.d.cts +66 -1
- package/dist/versioning/index.d.ts +66 -1
- package/dist/versioning/index.js +296 -14
- package/dist/versioning/index.js.map +1 -1
- package/package.json +51 -1
- package/dist/index-C_4CMV5c.d.cts +0 -1207
- package/dist/index-C_4CMV5c.d.ts +0 -1207
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Agent Presence Manager (Phase 14)
|
|
5
|
+
*
|
|
6
|
+
* Tracks real-time presence of all agents in a session.
|
|
7
|
+
* Provides status updates, cursor tracking, and activity monitoring.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
interface AgentPresence {
|
|
11
|
+
agentId: string;
|
|
12
|
+
name: string;
|
|
13
|
+
role: 'user' | 'assistant' | 'monitor' | 'admin';
|
|
14
|
+
status: 'online' | 'away' | 'offline' | 'reconnecting';
|
|
15
|
+
joinedAt: string;
|
|
16
|
+
lastSeen: string;
|
|
17
|
+
cursorPosition?: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
path: string;
|
|
21
|
+
};
|
|
22
|
+
activeSection?: string;
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
interface PresenceUpdate {
|
|
26
|
+
agentId: string;
|
|
27
|
+
changes: Partial<AgentPresence>;
|
|
28
|
+
timestamp: string;
|
|
29
|
+
}
|
|
30
|
+
interface PresenceEvents {
|
|
31
|
+
presence_updated: (data: {
|
|
32
|
+
agentId: string;
|
|
33
|
+
presence: AgentPresence;
|
|
34
|
+
}) => void;
|
|
35
|
+
agent_joined: (data: {
|
|
36
|
+
agentId: string;
|
|
37
|
+
presence: AgentPresence;
|
|
38
|
+
}) => void;
|
|
39
|
+
agent_left: (data: {
|
|
40
|
+
agentId: string;
|
|
41
|
+
presence: AgentPresence;
|
|
42
|
+
}) => void;
|
|
43
|
+
cursor_updated: (data: {
|
|
44
|
+
agentId: string;
|
|
45
|
+
cursorPosition: {
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
path: string;
|
|
49
|
+
};
|
|
50
|
+
}) => void;
|
|
51
|
+
section_updated: (data: {
|
|
52
|
+
agentId: string;
|
|
53
|
+
activeSection: string;
|
|
54
|
+
}) => void;
|
|
55
|
+
status_updated: (data: {
|
|
56
|
+
agentId: string;
|
|
57
|
+
status: AgentPresence['status'];
|
|
58
|
+
}) => void;
|
|
59
|
+
}
|
|
60
|
+
declare class AgentPresenceManager extends EventEmitter<PresenceEvents> {
|
|
61
|
+
private presences;
|
|
62
|
+
private sessionId;
|
|
63
|
+
private heartbeatInterval;
|
|
64
|
+
private heartbeatTimeout;
|
|
65
|
+
private inactivityThreshold;
|
|
66
|
+
constructor(sessionId: string);
|
|
67
|
+
/**
|
|
68
|
+
* Add or update agent presence
|
|
69
|
+
*/
|
|
70
|
+
updatePresence(agentId: string, presence: Omit<AgentPresence, 'joinedAt' | 'lastSeen'>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Agent joined
|
|
73
|
+
*/
|
|
74
|
+
agentJoined(agentId: string, name: string, role?: AgentPresence['role'], metadata?: Record<string, unknown>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Agent left
|
|
77
|
+
*/
|
|
78
|
+
agentLeft(agentId: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* Update cursor position
|
|
81
|
+
*/
|
|
82
|
+
updateCursor(agentId: string, x: number, y: number, path: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* Update active section
|
|
85
|
+
*/
|
|
86
|
+
updateActiveSection(agentId: string, section: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Update status
|
|
89
|
+
*/
|
|
90
|
+
updateStatus(agentId: string, status: AgentPresence['status']): void;
|
|
91
|
+
/**
|
|
92
|
+
* Heartbeat from agent (keeps them online)
|
|
93
|
+
*/
|
|
94
|
+
heartbeat(agentId: string): void;
|
|
95
|
+
/**
|
|
96
|
+
* Get presence for agent
|
|
97
|
+
*/
|
|
98
|
+
getPresence(agentId: string): AgentPresence | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Get all online agents
|
|
101
|
+
*/
|
|
102
|
+
getOnlineAgents(): AgentPresence[];
|
|
103
|
+
/**
|
|
104
|
+
* Get all agents
|
|
105
|
+
*/
|
|
106
|
+
getAllAgents(): AgentPresence[];
|
|
107
|
+
/**
|
|
108
|
+
* Get all presences
|
|
109
|
+
*/
|
|
110
|
+
getAllPresences(): AgentPresence[];
|
|
111
|
+
/**
|
|
112
|
+
* Get agent count
|
|
113
|
+
*/
|
|
114
|
+
getAgentCount(): Record<AgentPresence['status'], number>;
|
|
115
|
+
/**
|
|
116
|
+
* Get statistics
|
|
117
|
+
*/
|
|
118
|
+
getStats(): {
|
|
119
|
+
totalAgents: number;
|
|
120
|
+
onlineAgents: number;
|
|
121
|
+
offlineAgents: number;
|
|
122
|
+
awayAgents: number;
|
|
123
|
+
reconnectingAgents: number;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Clear expired presences
|
|
127
|
+
*/
|
|
128
|
+
clearExpiredPresences(maxAgeMs: number): void;
|
|
129
|
+
/**
|
|
130
|
+
* Get agents by role
|
|
131
|
+
*/
|
|
132
|
+
getByRole(role: AgentPresence['role']): AgentPresence[];
|
|
133
|
+
/**
|
|
134
|
+
* Get agents in active section
|
|
135
|
+
*/
|
|
136
|
+
getInSection(section: string): AgentPresence[];
|
|
137
|
+
/**
|
|
138
|
+
* Get presence timeline
|
|
139
|
+
*/
|
|
140
|
+
getPresenceStats(): {
|
|
141
|
+
total: number;
|
|
142
|
+
online: number;
|
|
143
|
+
away: number;
|
|
144
|
+
offline: number;
|
|
145
|
+
reconnecting: number;
|
|
146
|
+
byRole: Record<string, number>;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Start heartbeat check (mark inactive agents as away)
|
|
150
|
+
*/
|
|
151
|
+
private startHeartbeatCheck;
|
|
152
|
+
/**
|
|
153
|
+
* Stop heartbeat monitoring
|
|
154
|
+
*/
|
|
155
|
+
stopHeartbeatMonitoring(): void;
|
|
156
|
+
/**
|
|
157
|
+
* Clear all presences
|
|
158
|
+
*/
|
|
159
|
+
clear(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Destroy the manager
|
|
162
|
+
*/
|
|
163
|
+
destroy(): void;
|
|
164
|
+
}
|
|
165
|
+
declare function getAgentPresenceManager(sessionId: string): AgentPresenceManager;
|
|
166
|
+
declare function clearAgentPresenceManager(sessionId: string): void;
|
|
167
|
+
|
|
168
|
+
export { type AgentPresence, AgentPresenceManager, type PresenceEvents, type PresenceUpdate, clearAgentPresenceManager, getAgentPresenceManager };
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
|
|
3
|
+
// src/presence/AgentPresenceManager.ts
|
|
4
|
+
|
|
5
|
+
// src/utils/logger.ts
|
|
6
|
+
var consoleLogger = {
|
|
7
|
+
debug: (...args) => {
|
|
8
|
+
console.debug("[AEON:DEBUG]", ...args);
|
|
9
|
+
},
|
|
10
|
+
info: (...args) => {
|
|
11
|
+
console.info("[AEON:INFO]", ...args);
|
|
12
|
+
},
|
|
13
|
+
warn: (...args) => {
|
|
14
|
+
console.warn("[AEON:WARN]", ...args);
|
|
15
|
+
},
|
|
16
|
+
error: (...args) => {
|
|
17
|
+
console.error("[AEON:ERROR]", ...args);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var currentLogger = consoleLogger;
|
|
21
|
+
function getLogger() {
|
|
22
|
+
return currentLogger;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/presence/AgentPresenceManager.ts
|
|
26
|
+
var logger = getLogger();
|
|
27
|
+
var AgentPresenceManager = class extends EventEmitter {
|
|
28
|
+
presences = /* @__PURE__ */ new Map();
|
|
29
|
+
sessionId;
|
|
30
|
+
heartbeatInterval = null;
|
|
31
|
+
heartbeatTimeout = 3e4;
|
|
32
|
+
inactivityThreshold = 6e4;
|
|
33
|
+
constructor(sessionId) {
|
|
34
|
+
super();
|
|
35
|
+
this.sessionId = sessionId;
|
|
36
|
+
this.startHeartbeatCheck();
|
|
37
|
+
logger.debug("[AgentPresenceManager] Initialized", { sessionId });
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Add or update agent presence
|
|
41
|
+
*/
|
|
42
|
+
updatePresence(agentId, presence) {
|
|
43
|
+
const existing = this.presences.get(agentId);
|
|
44
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
45
|
+
const updated = {
|
|
46
|
+
...existing,
|
|
47
|
+
...presence,
|
|
48
|
+
agentId,
|
|
49
|
+
joinedAt: existing?.joinedAt ?? now,
|
|
50
|
+
lastSeen: now
|
|
51
|
+
};
|
|
52
|
+
this.presences.set(agentId, updated);
|
|
53
|
+
this.emit("presence_updated", {
|
|
54
|
+
agentId,
|
|
55
|
+
presence: updated
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Agent joined
|
|
60
|
+
*/
|
|
61
|
+
agentJoined(agentId, name, role = "user", metadata) {
|
|
62
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
63
|
+
const presence = {
|
|
64
|
+
agentId,
|
|
65
|
+
name,
|
|
66
|
+
role,
|
|
67
|
+
status: "online",
|
|
68
|
+
joinedAt: now,
|
|
69
|
+
lastSeen: now,
|
|
70
|
+
metadata
|
|
71
|
+
};
|
|
72
|
+
this.presences.set(agentId, presence);
|
|
73
|
+
this.emit("agent_joined", { agentId, presence });
|
|
74
|
+
logger.debug("[AgentPresenceManager] Agent joined", {
|
|
75
|
+
agentId,
|
|
76
|
+
name,
|
|
77
|
+
role
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Agent left
|
|
82
|
+
*/
|
|
83
|
+
agentLeft(agentId) {
|
|
84
|
+
const presence = this.presences.get(agentId);
|
|
85
|
+
if (presence) {
|
|
86
|
+
presence.status = "offline";
|
|
87
|
+
presence.lastSeen = (/* @__PURE__ */ new Date()).toISOString();
|
|
88
|
+
this.presences.set(agentId, presence);
|
|
89
|
+
this.emit("agent_left", { agentId, presence });
|
|
90
|
+
logger.debug("[AgentPresenceManager] Agent left", { agentId });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Update cursor position
|
|
95
|
+
*/
|
|
96
|
+
updateCursor(agentId, x, y, path) {
|
|
97
|
+
const presence = this.presences.get(agentId);
|
|
98
|
+
if (presence) {
|
|
99
|
+
presence.cursorPosition = { x, y, path };
|
|
100
|
+
presence.lastSeen = (/* @__PURE__ */ new Date()).toISOString();
|
|
101
|
+
this.presences.set(agentId, presence);
|
|
102
|
+
this.emit("cursor_updated", {
|
|
103
|
+
agentId,
|
|
104
|
+
cursorPosition: presence.cursorPosition
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Update active section
|
|
110
|
+
*/
|
|
111
|
+
updateActiveSection(agentId, section) {
|
|
112
|
+
const presence = this.presences.get(agentId);
|
|
113
|
+
if (presence) {
|
|
114
|
+
presence.activeSection = section;
|
|
115
|
+
presence.lastSeen = (/* @__PURE__ */ new Date()).toISOString();
|
|
116
|
+
this.presences.set(agentId, presence);
|
|
117
|
+
this.emit("section_updated", {
|
|
118
|
+
agentId,
|
|
119
|
+
activeSection: section
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Update status
|
|
125
|
+
*/
|
|
126
|
+
updateStatus(agentId, status) {
|
|
127
|
+
const presence = this.presences.get(agentId);
|
|
128
|
+
if (presence) {
|
|
129
|
+
presence.status = status;
|
|
130
|
+
presence.lastSeen = (/* @__PURE__ */ new Date()).toISOString();
|
|
131
|
+
this.presences.set(agentId, presence);
|
|
132
|
+
this.emit("status_updated", { agentId, status });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Heartbeat from agent (keeps them online)
|
|
137
|
+
*/
|
|
138
|
+
heartbeat(agentId) {
|
|
139
|
+
const presence = this.presences.get(agentId);
|
|
140
|
+
if (presence) {
|
|
141
|
+
if (presence.status === "reconnecting") {
|
|
142
|
+
presence.status = "online";
|
|
143
|
+
this.emit("status_updated", { agentId, status: "online" });
|
|
144
|
+
}
|
|
145
|
+
presence.lastSeen = (/* @__PURE__ */ new Date()).toISOString();
|
|
146
|
+
this.presences.set(agentId, presence);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get presence for agent
|
|
151
|
+
*/
|
|
152
|
+
getPresence(agentId) {
|
|
153
|
+
return this.presences.get(agentId);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get all online agents
|
|
157
|
+
*/
|
|
158
|
+
getOnlineAgents() {
|
|
159
|
+
return Array.from(this.presences.values()).filter(
|
|
160
|
+
(p) => p.status === "online"
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get all agents
|
|
165
|
+
*/
|
|
166
|
+
getAllAgents() {
|
|
167
|
+
return Array.from(this.presences.values());
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Get all presences
|
|
171
|
+
*/
|
|
172
|
+
getAllPresences() {
|
|
173
|
+
return Array.from(this.presences.values());
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get agent count
|
|
177
|
+
*/
|
|
178
|
+
getAgentCount() {
|
|
179
|
+
const counts = {
|
|
180
|
+
online: 0,
|
|
181
|
+
away: 0,
|
|
182
|
+
offline: 0,
|
|
183
|
+
reconnecting: 0
|
|
184
|
+
};
|
|
185
|
+
this.presences.forEach((p) => {
|
|
186
|
+
counts[p.status]++;
|
|
187
|
+
});
|
|
188
|
+
return counts;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get statistics
|
|
192
|
+
*/
|
|
193
|
+
getStats() {
|
|
194
|
+
return {
|
|
195
|
+
totalAgents: this.presences.size,
|
|
196
|
+
onlineAgents: Array.from(this.presences.values()).filter(
|
|
197
|
+
(p) => p.status === "online"
|
|
198
|
+
).length,
|
|
199
|
+
offlineAgents: Array.from(this.presences.values()).filter(
|
|
200
|
+
(p) => p.status === "offline"
|
|
201
|
+
).length,
|
|
202
|
+
awayAgents: Array.from(this.presences.values()).filter(
|
|
203
|
+
(p) => p.status === "away"
|
|
204
|
+
).length,
|
|
205
|
+
reconnectingAgents: Array.from(this.presences.values()).filter(
|
|
206
|
+
(p) => p.status === "reconnecting"
|
|
207
|
+
).length
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Clear expired presences
|
|
212
|
+
*/
|
|
213
|
+
clearExpiredPresences(maxAgeMs) {
|
|
214
|
+
const now = Date.now();
|
|
215
|
+
const toRemove = [];
|
|
216
|
+
this.presences.forEach((presence, agentId) => {
|
|
217
|
+
const lastSeenTime = new Date(presence.lastSeen).getTime();
|
|
218
|
+
const ageMs = now - lastSeenTime;
|
|
219
|
+
if (ageMs > maxAgeMs && presence.status === "offline") {
|
|
220
|
+
toRemove.push(agentId);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
toRemove.forEach((agentId) => {
|
|
224
|
+
this.presences.delete(agentId);
|
|
225
|
+
});
|
|
226
|
+
if (toRemove.length > 0) {
|
|
227
|
+
logger.debug("[AgentPresenceManager] Cleared expired presences", {
|
|
228
|
+
count: toRemove.length
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Get agents by role
|
|
234
|
+
*/
|
|
235
|
+
getByRole(role) {
|
|
236
|
+
return Array.from(this.presences.values()).filter((p) => p.role === role);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get agents in active section
|
|
240
|
+
*/
|
|
241
|
+
getInSection(section) {
|
|
242
|
+
return Array.from(this.presences.values()).filter(
|
|
243
|
+
(p) => p.activeSection === section && p.status === "online"
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Get presence timeline
|
|
248
|
+
*/
|
|
249
|
+
getPresenceStats() {
|
|
250
|
+
const stats = {
|
|
251
|
+
total: this.presences.size,
|
|
252
|
+
online: 0,
|
|
253
|
+
away: 0,
|
|
254
|
+
offline: 0,
|
|
255
|
+
reconnecting: 0,
|
|
256
|
+
byRole: {}
|
|
257
|
+
};
|
|
258
|
+
this.presences.forEach((p) => {
|
|
259
|
+
stats[p.status]++;
|
|
260
|
+
stats.byRole[p.role] = (stats.byRole[p.role] ?? 0) + 1;
|
|
261
|
+
});
|
|
262
|
+
return stats;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Start heartbeat check (mark inactive agents as away)
|
|
266
|
+
*/
|
|
267
|
+
startHeartbeatCheck() {
|
|
268
|
+
this.heartbeatInterval = setInterval(() => {
|
|
269
|
+
const now = Date.now();
|
|
270
|
+
this.presences.forEach((presence) => {
|
|
271
|
+
const lastSeenTime = new Date(presence.lastSeen).getTime();
|
|
272
|
+
const timeSinceLastSeen = now - lastSeenTime;
|
|
273
|
+
if (timeSinceLastSeen > this.inactivityThreshold && presence.status === "online") {
|
|
274
|
+
presence.status = "away";
|
|
275
|
+
this.emit("status_updated", {
|
|
276
|
+
agentId: presence.agentId,
|
|
277
|
+
status: "away"
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
if (timeSinceLastSeen > this.heartbeatTimeout && presence.status !== "offline") {
|
|
281
|
+
presence.status = "reconnecting";
|
|
282
|
+
this.emit("status_updated", {
|
|
283
|
+
agentId: presence.agentId,
|
|
284
|
+
status: "reconnecting"
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}, 1e4);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Stop heartbeat monitoring
|
|
292
|
+
*/
|
|
293
|
+
stopHeartbeatMonitoring() {
|
|
294
|
+
if (this.heartbeatInterval) {
|
|
295
|
+
clearInterval(this.heartbeatInterval);
|
|
296
|
+
this.heartbeatInterval = null;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Clear all presences
|
|
301
|
+
*/
|
|
302
|
+
clear() {
|
|
303
|
+
this.presences.clear();
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Destroy the manager
|
|
307
|
+
*/
|
|
308
|
+
destroy() {
|
|
309
|
+
this.stopHeartbeatMonitoring();
|
|
310
|
+
this.presences.clear();
|
|
311
|
+
this.removeAllListeners();
|
|
312
|
+
logger.debug("[AgentPresenceManager] Destroyed", {
|
|
313
|
+
sessionId: this.sessionId
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
var instances = /* @__PURE__ */ new Map();
|
|
318
|
+
function getAgentPresenceManager(sessionId) {
|
|
319
|
+
if (!instances.has(sessionId)) {
|
|
320
|
+
instances.set(sessionId, new AgentPresenceManager(sessionId));
|
|
321
|
+
}
|
|
322
|
+
return instances.get(sessionId);
|
|
323
|
+
}
|
|
324
|
+
function clearAgentPresenceManager(sessionId) {
|
|
325
|
+
const instance = instances.get(sessionId);
|
|
326
|
+
if (instance) {
|
|
327
|
+
instance.destroy();
|
|
328
|
+
instances.delete(sessionId);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export { AgentPresenceManager, clearAgentPresenceManager, getAgentPresenceManager };
|
|
333
|
+
//# sourceMappingURL=index.js.map
|
|
334
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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AA,GAAgB;AACd,IAAA,IAAA,CAAK,uBAAA,EAAwB;AAC7B,IAAA,IAAA,CAAK,UAAU,KAAA,EAAM;AACrB,IAAA,IAAA,CAAK,kBAAA,EAAmB;AACxB,IAAA,MAAA,CAAO,MAAM,kCAAA,EAAoC;AAAA,MAC/C,WAAW,IAAA,CAAK;AAAA,KACjB,CAAA;AAAA,EACH;AACF;AAMA,IAAM,SAAA,uBAAgB,GAAA,EAAkC;AAEjD,SAAS,wBACd,SAAA,EACsB;AACtB,EAAA,IAAI,CAAC,SAAA,CAAU,GAAA,CAAI,SAAS,CAAA,EAAG;AAC7B,IAAA,SAAA,CAAU,GAAA,CAAI,SAAA,EAAW,IAAI,oBAAA,CAAqB,SAAS,CAAC,CAAA;AAAA,EAC9D;AACA,EAAA,OAAO,SAAA,CAAU,IAAI,SAAS,CAAA;AAChC;AAEO,SAAS,0BAA0B,SAAA,EAAyB;AACjE,EAAA,MAAM,QAAA,GAAW,SAAA,CAAU,GAAA,CAAI,SAAS,CAAA;AACxC,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,QAAA,CAAS,OAAA,EAAQ;AACjB,IAAA,SAAA,CAAU,OAAO,SAAS,CAAA;AAAA,EAC5B;AACF","file":"index.js","sourcesContent":["/**\n * Aeon Logger Interface\n *\n * Provides a pluggable logging interface that can be configured\n * by consumers to integrate with their preferred logging solution.\n */\n\n/**\n * Logger interface that consumers can implement\n */\nexport interface Logger {\n debug: (...args: unknown[]) => void;\n info: (...args: unknown[]) => void;\n warn: (...args: unknown[]) => void;\n error: (...args: unknown[]) => void;\n}\n\n/**\n * Default console logger implementation\n */\nconst consoleLogger: Logger = {\n debug: (...args: unknown[]) => {\n // eslint-disable-next-line no-console\n console.debug('[AEON:DEBUG]', ...args);\n },\n info: (...args: unknown[]) => {\n // eslint-disable-next-line no-console\n console.info('[AEON:INFO]', ...args);\n },\n warn: (...args: unknown[]) => {\n // eslint-disable-next-line no-console\n console.warn('[AEON:WARN]', ...args);\n },\n error: (...args: unknown[]) => {\n // eslint-disable-next-line no-console\n console.error('[AEON:ERROR]', ...args);\n },\n};\n\n/**\n * No-op logger for production or when logging is disabled\n */\nconst noopLogger: Logger = {\n debug: () => {},\n info: () => {},\n warn: () => {},\n error: () => {},\n};\n\n/**\n * Current logger instance\n */\nlet currentLogger: Logger = consoleLogger;\n\n/**\n * Get the current logger instance\n */\nexport function getLogger(): Logger {\n return currentLogger;\n}\n\n/**\n * Set a custom logger implementation\n */\nexport function setLogger(logger: Logger): void {\n currentLogger = logger;\n}\n\n/**\n * Reset to the default console logger\n */\nexport function resetLogger(): void {\n currentLogger = consoleLogger;\n}\n\n/**\n * Disable all logging\n */\nexport function disableLogging(): void {\n currentLogger = noopLogger;\n}\n\n/**\n * Create a namespaced logger\n */\nexport function createNamespacedLogger(namespace: string): Logger {\n const logger = getLogger();\n return {\n debug: (...args: unknown[]) => logger.debug(`[${namespace}]`, ...args),\n info: (...args: unknown[]) => logger.info(`[${namespace}]`, ...args),\n warn: (...args: unknown[]) => logger.warn(`[${namespace}]`, ...args),\n error: (...args: unknown[]) => logger.error(`[${namespace}]`, ...args),\n };\n}\n\n// Export default logger for convenience\nexport const logger: Logger = {\n debug: (...args: unknown[]) => getLogger().debug(...args),\n info: (...args: unknown[]) => getLogger().info(...args),\n warn: (...args: unknown[]) => getLogger().warn(...args),\n error: (...args: unknown[]) => getLogger().error(...args),\n};\n","/**\n * Agent Presence Manager (Phase 14)\n *\n * Tracks real-time presence of all agents in a session.\n * Provides status updates, cursor tracking, and activity monitoring.\n */\n\nimport { EventEmitter } from 'eventemitter3';\nimport { getLogger } from '../utils/logger';\n\nconst logger = getLogger();\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface AgentPresence {\n agentId: string;\n name: string;\n role: 'user' | 'assistant' | 'monitor' | 'admin';\n status: 'online' | 'away' | 'offline' | 'reconnecting';\n joinedAt: string;\n lastSeen: string;\n cursorPosition?: { x: number; y: number; path: string };\n activeSection?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface PresenceUpdate {\n agentId: string;\n changes: Partial<AgentPresence>;\n timestamp: string;\n}\n\nexport interface PresenceEvents {\n presence_updated: (data: {\n agentId: string;\n presence: AgentPresence;\n }) => void;\n agent_joined: (data: { agentId: string; presence: AgentPresence }) => void;\n agent_left: (data: { agentId: string; presence: AgentPresence }) => void;\n cursor_updated: (data: {\n agentId: string;\n cursorPosition: { x: number; y: number; path: string };\n }) => void;\n section_updated: (data: { agentId: string; activeSection: string }) => void;\n status_updated: (data: {\n agentId: string;\n status: AgentPresence['status'];\n }) => void;\n}\n\n// ============================================================================\n// Agent Presence Manager\n// ============================================================================\n\nexport class AgentPresenceManager extends EventEmitter<PresenceEvents> {\n private presences: Map<string, AgentPresence> = new Map();\n private sessionId: string;\n private heartbeatInterval: ReturnType<typeof setInterval> | null = null;\n private heartbeatTimeout = 30000;\n private inactivityThreshold = 60000;\n\n constructor(sessionId: string) {\n super();\n this.sessionId = sessionId;\n this.startHeartbeatCheck();\n logger.debug('[AgentPresenceManager] Initialized', { sessionId });\n }\n\n /**\n * Add or update agent presence\n */\n updatePresence(\n agentId: string,\n presence: Omit<AgentPresence, 'joinedAt' | 'lastSeen'>,\n ): void {\n const existing = this.presences.get(agentId);\n const now = new Date().toISOString();\n\n const updated: AgentPresence = {\n ...existing,\n ...presence,\n agentId,\n joinedAt: existing?.joinedAt ?? now,\n lastSeen: now,\n };\n\n this.presences.set(agentId, updated);\n\n this.emit('presence_updated', {\n agentId,\n presence: updated,\n });\n }\n\n /**\n * Agent joined\n */\n agentJoined(\n agentId: string,\n name: string,\n role: AgentPresence['role'] = 'user',\n metadata?: Record<string, unknown>,\n ): void {\n const now = new Date().toISOString();\n\n const presence: AgentPresence = {\n agentId,\n name,\n role,\n status: 'online',\n joinedAt: now,\n lastSeen: now,\n metadata,\n };\n\n this.presences.set(agentId, presence);\n this.emit('agent_joined', { agentId, presence });\n\n logger.debug('[AgentPresenceManager] Agent joined', {\n agentId,\n name,\n role,\n });\n }\n\n /**\n * Agent left\n */\n agentLeft(agentId: string): void {\n const presence = this.presences.get(agentId);\n\n if (presence) {\n presence.status = 'offline';\n presence.lastSeen = new Date().toISOString();\n\n this.presences.set(agentId, presence);\n this.emit('agent_left', { agentId, presence });\n\n logger.debug('[AgentPresenceManager] Agent left', { agentId });\n }\n }\n\n /**\n * Update cursor position\n */\n updateCursor(agentId: string, x: number, y: number, path: string): void {\n const presence = this.presences.get(agentId);\n\n if (presence) {\n presence.cursorPosition = { x, y, path };\n presence.lastSeen = new Date().toISOString();\n\n this.presences.set(agentId, presence);\n this.emit('cursor_updated', {\n agentId,\n cursorPosition: presence.cursorPosition,\n });\n }\n }\n\n /**\n * Update active section\n */\n updateActiveSection(agentId: string, section: string): void {\n const presence = this.presences.get(agentId);\n\n if (presence) {\n presence.activeSection = section;\n presence.lastSeen = new Date().toISOString();\n\n this.presences.set(agentId, presence);\n this.emit('section_updated', {\n agentId,\n activeSection: section,\n });\n }\n }\n\n /**\n * Update status\n */\n updateStatus(agentId: string, status: AgentPresence['status']): void {\n const presence = this.presences.get(agentId);\n\n if (presence) {\n presence.status = status;\n presence.lastSeen = new Date().toISOString();\n\n this.presences.set(agentId, presence);\n this.emit('status_updated', { agentId, status });\n }\n }\n\n /**\n * Heartbeat from agent (keeps them online)\n */\n heartbeat(agentId: string): void {\n const presence = this.presences.get(agentId);\n\n if (presence) {\n if (presence.status === 'reconnecting') {\n presence.status = 'online';\n this.emit('status_updated', { agentId, status: 'online' });\n }\n\n presence.lastSeen = new Date().toISOString();\n this.presences.set(agentId, presence);\n }\n }\n\n /**\n * Get presence for agent\n */\n getPresence(agentId: string): AgentPresence | undefined {\n return this.presences.get(agentId);\n }\n\n /**\n * Get all online agents\n */\n getOnlineAgents(): AgentPresence[] {\n return Array.from(this.presences.values()).filter(\n (p) => p.status === 'online',\n );\n }\n\n /**\n * Get all agents\n */\n getAllAgents(): AgentPresence[] {\n return Array.from(this.presences.values());\n }\n\n /**\n * Get all presences\n */\n getAllPresences(): AgentPresence[] {\n return Array.from(this.presences.values());\n }\n\n /**\n * Get agent count\n */\n getAgentCount(): Record<AgentPresence['status'], number> {\n const counts = {\n online: 0,\n away: 0,\n offline: 0,\n reconnecting: 0,\n };\n\n this.presences.forEach((p) => {\n counts[p.status]++;\n });\n\n return counts;\n }\n\n /**\n * Get statistics\n */\n getStats() {\n return {\n totalAgents: this.presences.size,\n onlineAgents: Array.from(this.presences.values()).filter(\n (p) => p.status === 'online',\n ).length,\n offlineAgents: Array.from(this.presences.values()).filter(\n (p) => p.status === 'offline',\n ).length,\n awayAgents: Array.from(this.presences.values()).filter(\n (p) => p.status === 'away',\n ).length,\n reconnectingAgents: Array.from(this.presences.values()).filter(\n (p) => p.status === 'reconnecting',\n ).length,\n };\n }\n\n /**\n * Clear expired presences\n */\n clearExpiredPresences(maxAgeMs: number): void {\n const now = Date.now();\n const toRemove: string[] = [];\n\n this.presences.forEach((presence, agentId) => {\n const lastSeenTime = new Date(presence.lastSeen).getTime();\n const ageMs = now - lastSeenTime;\n\n if (ageMs > maxAgeMs && presence.status === 'offline') {\n toRemove.push(agentId);\n }\n });\n\n toRemove.forEach((agentId) => {\n this.presences.delete(agentId);\n });\n\n if (toRemove.length > 0) {\n logger.debug('[AgentPresenceManager] Cleared expired presences', {\n count: toRemove.length,\n });\n }\n }\n\n /**\n * Get agents by role\n */\n getByRole(role: AgentPresence['role']): AgentPresence[] {\n return Array.from(this.presences.values()).filter((p) => p.role === role);\n }\n\n /**\n * Get agents in active section\n */\n getInSection(section: string): AgentPresence[] {\n return Array.from(this.presences.values()).filter(\n (p) => p.activeSection === section && p.status === 'online',\n );\n }\n\n /**\n * Get presence timeline\n */\n getPresenceStats() {\n const stats = {\n total: this.presences.size,\n online: 0,\n away: 0,\n offline: 0,\n reconnecting: 0,\n byRole: {} as Record<string, number>,\n };\n\n this.presences.forEach((p) => {\n stats[p.status]++;\n stats.byRole[p.role] = (stats.byRole[p.role] ?? 0) + 1;\n });\n\n return stats;\n }\n\n /**\n * Start heartbeat check (mark inactive agents as away)\n */\n private startHeartbeatCheck(): void {\n this.heartbeatInterval = setInterval(() => {\n const now = Date.now();\n\n this.presences.forEach((presence) => {\n const lastSeenTime = new Date(presence.lastSeen).getTime();\n const timeSinceLastSeen = now - lastSeenTime;\n\n if (\n timeSinceLastSeen > this.inactivityThreshold &&\n presence.status === 'online'\n ) {\n presence.status = 'away';\n this.emit('status_updated', {\n agentId: presence.agentId,\n status: 'away',\n });\n }\n\n if (\n timeSinceLastSeen > this.heartbeatTimeout &&\n presence.status !== 'offline'\n ) {\n presence.status = 'reconnecting';\n this.emit('status_updated', {\n agentId: presence.agentId,\n status: 'reconnecting',\n });\n }\n });\n }, 10000);\n }\n\n /**\n * Stop heartbeat monitoring\n */\n stopHeartbeatMonitoring(): void {\n if (this.heartbeatInterval) {\n clearInterval(this.heartbeatInterval);\n this.heartbeatInterval = null;\n }\n }\n\n /**\n * Clear all presences\n */\n clear(): void {\n this.presences.clear();\n }\n\n /**\n * Destroy the manager\n */\n destroy(): void {\n this.stopHeartbeatMonitoring();\n this.presences.clear();\n this.removeAllListeners();\n logger.debug('[AgentPresenceManager] Destroyed', {\n sessionId: this.sessionId,\n });\n }\n}\n\n// ============================================================================\n// Singleton Instance Map\n// ============================================================================\n\nconst instances = new Map<string, AgentPresenceManager>();\n\nexport function getAgentPresenceManager(\n sessionId: string,\n): AgentPresenceManager {\n if (!instances.has(sessionId)) {\n instances.set(sessionId, new AgentPresenceManager(sessionId));\n }\n return instances.get(sessionId)!;\n}\n\nexport function clearAgentPresenceManager(sessionId: string): void {\n const instance = instances.get(sessionId);\n if (instance) {\n instance.destroy();\n instances.delete(sessionId);\n }\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistence types for Aeon durable state.
|
|
3
|
+
*
|
|
4
|
+
* The adapter interface is intentionally minimal so consumers can map it to
|
|
5
|
+
* local storage, WASM-backed stores, D1/R2 synchronization layers, or custom
|
|
6
|
+
* encrypted stores without extra dependencies.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Minimal storage adapter interface.
|
|
10
|
+
*/
|
|
11
|
+
interface StorageAdapter {
|
|
12
|
+
getItem(key: string): Promise<string | null> | string | null;
|
|
13
|
+
setItem(key: string, value: string): Promise<void> | void;
|
|
14
|
+
removeItem(key: string): Promise<void> | void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Versioned envelope for persisted payloads.
|
|
18
|
+
*/
|
|
19
|
+
interface PersistedEnvelope<T> {
|
|
20
|
+
version: 1;
|
|
21
|
+
updatedAt: number;
|
|
22
|
+
data: T;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Serialization hook for custom privacy/security implementations.
|
|
26
|
+
*/
|
|
27
|
+
type PersistenceSerializer<T> = (value: PersistedEnvelope<T>) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Deserialization hook for custom privacy/security implementations.
|
|
30
|
+
*/
|
|
31
|
+
type PersistenceDeserializer<T> = (raw: string) => PersistedEnvelope<T>;
|
|
32
|
+
|
|
33
|
+
export type { PersistedEnvelope as P, StorageAdapter as S, PersistenceDeserializer as a, PersistenceSerializer as b };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistence types for Aeon durable state.
|
|
3
|
+
*
|
|
4
|
+
* The adapter interface is intentionally minimal so consumers can map it to
|
|
5
|
+
* local storage, WASM-backed stores, D1/R2 synchronization layers, or custom
|
|
6
|
+
* encrypted stores without extra dependencies.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Minimal storage adapter interface.
|
|
10
|
+
*/
|
|
11
|
+
interface StorageAdapter {
|
|
12
|
+
getItem(key: string): Promise<string | null> | string | null;
|
|
13
|
+
setItem(key: string, value: string): Promise<void> | void;
|
|
14
|
+
removeItem(key: string): Promise<void> | void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Versioned envelope for persisted payloads.
|
|
18
|
+
*/
|
|
19
|
+
interface PersistedEnvelope<T> {
|
|
20
|
+
version: 1;
|
|
21
|
+
updatedAt: number;
|
|
22
|
+
data: T;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Serialization hook for custom privacy/security implementations.
|
|
26
|
+
*/
|
|
27
|
+
type PersistenceSerializer<T> = (value: PersistedEnvelope<T>) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Deserialization hook for custom privacy/security implementations.
|
|
30
|
+
*/
|
|
31
|
+
type PersistenceDeserializer<T> = (raw: string) => PersistedEnvelope<T>;
|
|
32
|
+
|
|
33
|
+
export type { PersistedEnvelope as P, StorageAdapter as S, PersistenceDeserializer as a, PersistenceSerializer as b };
|