UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

61 lines (60 loc) • 1.9 kB
import { o as logSessionStateChange } from "./diagnostic-runtime-BxwnWXDu.mjs"; import { i as isSessionRunActiveForKey, r as isSessionRunActive } from "./session-controller.queries-D7T8foQX.mjs"; import { i as logMessageQueued, r as logMessageProcessed } from "./diagnostic-C-GjPJGO.mjs"; //#region src/logging/message-lifecycle.ts function createDiagnosticMessageLifecycle(e) { const t = e.startedAtMs ?? Date.now(); const resolveRef = (t) => ({ sessionId: t?.sessionId ?? e.sessionId, sessionKey: t?.sessionKey ?? e.sessionKey }); const canTrackSessionState = (t) => e.enabled && e.trackSessionState && Boolean(t.sessionId || t.sessionKey); return { markProcessing() { const t = resolveRef(); if (!canTrackSessionState(t)) return; logMessageQueued({ sessionId: t.sessionId, sessionKey: t.sessionKey, channel: e.channel, source: e.source }); logSessionStateChange({ sessionId: t.sessionId, sessionKey: t.sessionKey, state: (t.sessionKey ? isSessionRunActiveForKey(t.sessionKey) : t.sessionId && isSessionRunActive(t.sessionId)) ? "processing" : "waiting", reason: e.processingReason }); }, markIdle(e, t) { const n = resolveRef(t); if (!canTrackSessionState(n)) return; logSessionStateChange({ sessionId: n.sessionId, sessionKey: n.sessionKey, state: "idle", reason: e }); }, markProcessed(n, r) { if (!e.enabled) return; const i = resolveRef(r); logMessageProcessed({ channel: e.channel, chatId: e.chatId, messageId: e.messageId, sessionId: i.sessionId, sessionKey: i.sessionKey, agentId: e.agentId, durationMs: r?.durationMs ?? Date.now() - t, outcome: n, reason: r?.reason, error: r?.error, userPrompt: r?.userPrompt ?? e.userPrompt, finalResponse: r?.finalResponse }); } }; } //#endregion export { createDiagnosticMessageLifecycle as t };