@devness/useai 0.4.8 → 0.4.9
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/dist/index.js +17 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -112,7 +112,7 @@ var VERSION;
|
|
|
112
112
|
var init_version = __esm({
|
|
113
113
|
"../shared/dist/constants/version.js"() {
|
|
114
114
|
"use strict";
|
|
115
|
-
VERSION = "0.4.
|
|
115
|
+
VERSION = "0.4.9";
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
|
|
@@ -3125,9 +3125,14 @@ function sealOrphanedSessions() {
|
|
|
3125
3125
|
console.log(`Sealed ${sealed} orphaned session${sealed === 1 ? "" : "s"}`);
|
|
3126
3126
|
}
|
|
3127
3127
|
}
|
|
3128
|
+
function isSessionAlreadySealed(session2) {
|
|
3129
|
+
const activePath = join7(ACTIVE_DIR, `${session2.sessionId}.jsonl`);
|
|
3130
|
+
return !existsSync9(activePath);
|
|
3131
|
+
}
|
|
3128
3132
|
function autoSealSession(active) {
|
|
3129
3133
|
const { session: session2 } = active;
|
|
3130
3134
|
if (session2.sessionRecordCount === 0) return;
|
|
3135
|
+
if (isSessionAlreadySealed(session2)) return;
|
|
3131
3136
|
const duration = session2.getSessionDuration();
|
|
3132
3137
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3133
3138
|
const endRecord = session2.appendToChain("session_end", {
|
|
@@ -3188,6 +3193,10 @@ function autoSealSession(active) {
|
|
|
3188
3193
|
allSessions.push(seal);
|
|
3189
3194
|
writeJson(SESSIONS_FILE, allSessions);
|
|
3190
3195
|
}
|
|
3196
|
+
function sealSessionData(active) {
|
|
3197
|
+
autoSealSession(active);
|
|
3198
|
+
active.session.reset();
|
|
3199
|
+
}
|
|
3191
3200
|
function resetIdleTimer(sessionId) {
|
|
3192
3201
|
const active = sessions.get(sessionId);
|
|
3193
3202
|
if (!active) return;
|
|
@@ -3293,15 +3302,18 @@ async function startDaemon(port) {
|
|
|
3293
3302
|
return;
|
|
3294
3303
|
}
|
|
3295
3304
|
if (url.pathname === "/api/seal-active" && req.method === "POST") {
|
|
3296
|
-
|
|
3297
|
-
for (const
|
|
3298
|
-
|
|
3305
|
+
let sealed = 0;
|
|
3306
|
+
for (const [, active] of sessions) {
|
|
3307
|
+
if (active.session.sessionRecordCount > 0 && !isSessionAlreadySealed(active.session)) {
|
|
3308
|
+
sealSessionData(active);
|
|
3309
|
+
sealed++;
|
|
3310
|
+
}
|
|
3299
3311
|
}
|
|
3300
3312
|
res.writeHead(200, {
|
|
3301
3313
|
"Content-Type": "application/json",
|
|
3302
3314
|
"Access-Control-Allow-Origin": "*"
|
|
3303
3315
|
});
|
|
3304
|
-
res.end(JSON.stringify({ sealed
|
|
3316
|
+
res.end(JSON.stringify({ sealed }));
|
|
3305
3317
|
return;
|
|
3306
3318
|
}
|
|
3307
3319
|
if ((url.pathname.startsWith("/api/local/") || url.pathname === "/api/seal-active") && req.method === "OPTIONS") {
|