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

@@ -65,10 +65,19 @@ function handleGatewayNotification(notification: { method?: string; params?: Rec
if (phase === 'started' && runId != null && sessionKey != null) {
import('./chat')
.then(({ useChatStore }) => {
useChatStore.getState().handleChatEvent({
const state = useChatStore.getState();
const resolvedSessionKey = String(sessionKey);
const shouldRefreshSessions =
resolvedSessionKey !== state.currentSessionKey
|| !state.sessions.some((session) => session.key === resolvedSessionKey);
if (shouldRefreshSessions) {
void state.loadSessions();
}
state.handleChatEvent({
state: 'started',
runId,
sessionKey,
sessionKey: resolvedSessionKey,
});
})
.catch(() => {});
@@ -78,8 +87,22 @@ function handleGatewayNotification(notification: { method?: string; params?: Rec
import('./chat')
.then(({ useChatStore }) => {
const state = useChatStore.getState();
state.loadHistory(true);
if (state.sending) {
const resolvedSessionKey = sessionKey != null ? String(sessionKey) : null;
const shouldRefreshSessions = resolvedSessionKey != null && (
resolvedSessionKey !== state.currentSessionKey
|| !state.sessions.some((session) => session.key === resolvedSessionKey)
);
if (shouldRefreshSessions) {
void state.loadSessions();
}
const matchesCurrentSession = resolvedSessionKey == null || resolvedSessionKey === state.currentSessionKey;
const matchesActiveRun = runId != null && state.activeRunId != null && String(runId) === state.activeRunId;
if (matchesCurrentSession || matchesActiveRun) {
void state.loadHistory(true);
}
if ((matchesCurrentSession || matchesActiveRun) && state.sending) {
useChatStore.setState({
sending: false,
activeRunId: null,