@cc-monitoring/proxy-core 0.1.3-alpha.6 → 0.1.3-alpha.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/server/ui-route.js
CHANGED
|
@@ -8,7 +8,7 @@ import { loadConfig, saveConfig } from '../config/index.js';
|
|
|
8
8
|
import { getProcessStatus, startProcess, stopProcess, reloadProcess } from '../utils/pm2.js';
|
|
9
9
|
import { getCallerDirname } from '../utils/esm-dirname.js';
|
|
10
10
|
import { getConfigPath, getDisplayPath } from '../utils/paths.js';
|
|
11
|
-
import { loadRequestDB, listRequestDB } from '../utils/request-writer.js';
|
|
11
|
+
import { loadRequestDB, listRequestDB, sessionIdExists } from '../utils/request-writer.js';
|
|
12
12
|
import { statusHistory } from '../utils/status-history.js';
|
|
13
13
|
import { addDataClient, removeDataClient } from './data-push.js';
|
|
14
14
|
import { getVersionInfo } from '../utils/version.js';
|
|
@@ -253,9 +253,12 @@ export async function setupUiRoutes(fastify) {
|
|
|
253
253
|
if (!sessionId) {
|
|
254
254
|
sendSSE('session', newSessionId);
|
|
255
255
|
}
|
|
256
|
+
// 判断:如果 sessionId 存在于数据库,用 -r;否则用 --session-id
|
|
256
257
|
const spawnArgs = sessionId
|
|
257
|
-
?
|
|
258
|
-
|
|
258
|
+
? (sessionIdExists(sessionId)
|
|
259
|
+
? ['-r', sessionId, '-p', prompt]
|
|
260
|
+
: ['--session-id', sessionId, '-p', prompt])
|
|
261
|
+
: ['-p', prompt];
|
|
259
262
|
const child = spawn('claude', spawnArgs, {
|
|
260
263
|
env: { ...process.env }
|
|
261
264
|
});
|
|
@@ -300,9 +303,12 @@ export async function setupUiRoutes(fastify) {
|
|
|
300
303
|
else {
|
|
301
304
|
// Non-streaming mode: buffer all output
|
|
302
305
|
const newSessionId = sessionId ?? randomUUID();
|
|
306
|
+
// 判断:如果 sessionId 存在于数据库,用 -r;否则用 --session-id
|
|
303
307
|
const spawnArgs = sessionId
|
|
304
|
-
?
|
|
305
|
-
|
|
308
|
+
? (sessionIdExists(sessionId)
|
|
309
|
+
? ['-r', sessionId, '-p', prompt]
|
|
310
|
+
: ['--session-id', sessionId, '-p', prompt])
|
|
311
|
+
: ['-p', prompt];
|
|
306
312
|
const child = spawn('claude', spawnArgs, {
|
|
307
313
|
env: { ...process.env }
|
|
308
314
|
});
|
|
@@ -117,3 +117,11 @@ export async function cleanOldRequestsDB(daysToKeep = 7) {
|
|
|
117
117
|
const cutoff = new Date(Date.now() - daysToKeep * 86400000).toISOString();
|
|
118
118
|
db.prepare(`DELETE FROM requests WHERE timestamp < ?`).run(cutoff);
|
|
119
119
|
}
|
|
120
|
+
// Check if a sessionId exists in the database
|
|
121
|
+
export function sessionIdExists(sessionId) {
|
|
122
|
+
const db = initDatabase();
|
|
123
|
+
const row = db.prepare(`
|
|
124
|
+
SELECT 1 FROM requests WHERE session_id = ? LIMIT 1
|
|
125
|
+
`).get(sessionId);
|
|
126
|
+
return !!row;
|
|
127
|
+
}
|