feat(cron): implement cron session management and logging features, including session key parsing and fallback message handling (#429)
This commit is contained in:
37
src/stores/chat/cron-session-utils.ts
Normal file
37
src/stores/chat/cron-session-utils.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export interface CronSessionKeyParts {
|
||||
agentId: string;
|
||||
jobId: string;
|
||||
runSessionId?: string;
|
||||
}
|
||||
|
||||
export function parseCronSessionKey(sessionKey: string): CronSessionKeyParts | null {
|
||||
if (!sessionKey.startsWith('agent:')) return null;
|
||||
const parts = sessionKey.split(':');
|
||||
if (parts.length < 4 || parts[2] !== 'cron') return null;
|
||||
|
||||
const agentId = parts[1] || 'main';
|
||||
const jobId = parts[3];
|
||||
if (!jobId) return null;
|
||||
|
||||
if (parts.length === 4) {
|
||||
return { agentId, jobId };
|
||||
}
|
||||
|
||||
if (parts.length === 6 && parts[4] === 'run' && parts[5]) {
|
||||
return { agentId, jobId, runSessionId: parts[5] };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isCronSessionKey(sessionKey: string): boolean {
|
||||
return parseCronSessionKey(sessionKey) != null;
|
||||
}
|
||||
|
||||
export function buildCronSessionHistoryPath(sessionKey: string, limit = 200): string {
|
||||
const params = new URLSearchParams({ sessionKey });
|
||||
if (Number.isFinite(limit) && limit > 0) {
|
||||
params.set('limit', String(Math.floor(limit)));
|
||||
}
|
||||
return `/api/cron/session-history?${params.toString()}`;
|
||||
}
|
||||
Reference in New Issue
Block a user