feat(cron): implement cron session management and logging features, including session key parsing and fallback message handling (#429)

This commit is contained in:
Haze
2026-03-12 11:20:56 +08:00
committed by GitHub
Unverified
parent 882da7b904
commit 38391dd093
9 changed files with 836 additions and 220 deletions

View 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()}`;
}