mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-07-13 02:45:45 +08:00
feat: add endpoint to fetch indexed session metadata and implement corresponding service method
This commit is contained in:
@@ -492,6 +492,18 @@ router.get(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns one DB-indexed session metadata row.
|
||||||
|
*/
|
||||||
|
router.get(
|
||||||
|
'/sessions/:sessionId',
|
||||||
|
asyncHandler(async (req: Request, res: Response) => {
|
||||||
|
const sessionId = readPathParam(req.params.sessionId, 'sessionId');
|
||||||
|
const session = llmSessionsService.getIndexedSession(sessionId);
|
||||||
|
res.json(createApiSuccessResponse({ session }));
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers provider disk scans and refreshes the shared sessions table.
|
* Triggers provider disk scans and refreshes the shared sessions table.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -106,6 +106,21 @@ export const llmSessionsService = {
|
|||||||
return allSessions.filter((session) => session.provider === provider);
|
return allSessions.filter((session) => session.provider === provider);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads one indexed session metadata row.
|
||||||
|
*/
|
||||||
|
getIndexedSession(sessionId: string) {
|
||||||
|
const session = sessionsDb.getSessionById(sessionId);
|
||||||
|
if (!session) {
|
||||||
|
throw new AppError(`Session "${sessionId}" was not found.`, {
|
||||||
|
code: 'SESSION_NOT_FOUND',
|
||||||
|
statusCode: 404,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return session;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs all provider indexers and updates `scan_state.last_scanned_at`.
|
* Runs all provider indexers and updates `scan_state.last_scanned_at`.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -131,6 +131,44 @@ test('llmSessionsService.updateSessionCustomName validates existence before upda
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// This test covers fetching one indexed DB session metadata row from getSessionById.
|
||||||
|
test('llmSessionsService.getIndexedSession returns DB session metadata', { concurrency: false }, () => {
|
||||||
|
const restoreGetById = patchMethod(sessionsDb, 'getSessionById', (sessionId: string) => (
|
||||||
|
sessionId === 'known-session'
|
||||||
|
? {
|
||||||
|
session_id: 'known-session',
|
||||||
|
provider: 'claude',
|
||||||
|
workspace_path: '/tmp/workspace',
|
||||||
|
jsonl_path: '/tmp/workspace/session.jsonl',
|
||||||
|
created_at: '2026-04-01T00:00:00.000Z',
|
||||||
|
updated_at: '2026-04-02T00:00:00.000Z',
|
||||||
|
}
|
||||||
|
: null
|
||||||
|
));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const session = llmSessionsService.getIndexedSession('known-session');
|
||||||
|
assert.deepEqual(session, {
|
||||||
|
session_id: 'known-session',
|
||||||
|
provider: 'claude',
|
||||||
|
workspace_path: '/tmp/workspace',
|
||||||
|
jsonl_path: '/tmp/workspace/session.jsonl',
|
||||||
|
created_at: '2026-04-01T00:00:00.000Z',
|
||||||
|
updated_at: '2026-04-02T00:00:00.000Z',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => llmSessionsService.getIndexedSession('missing-session'),
|
||||||
|
(error: unknown) =>
|
||||||
|
error instanceof AppError &&
|
||||||
|
error.code === 'SESSION_NOT_FOUND' &&
|
||||||
|
error.statusCode === 404,
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
restoreGetById();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// This test covers delete behavior using only DB jsonl_path, including invalid id validation.
|
// This test covers delete behavior using only DB jsonl_path, including invalid id validation.
|
||||||
test('llmSessionsService.deleteSessionArtifacts validates ids and deletes disk/db artifacts', { concurrency: false }, async () => {
|
test('llmSessionsService.deleteSessionArtifacts validates ids and deletes disk/db artifacts', { concurrency: false }, async () => {
|
||||||
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'llm-delete-session-'));
|
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'llm-delete-session-'));
|
||||||
|
|||||||
Reference in New Issue
Block a user