openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
40 lines (39 loc) • 1.85 kB
JavaScript
import { s as emitTrustedDiagnosticEvent, t as areDiagnosticsEnabledForProcess } from "./diagnostic-events-BADdmgZf.mjs";
import { a as isDiagnosticsTimelineEnabled, n as emitDiagnosticsTimelineEvent } from "./diagnostics-timeline-DxQ8TaVy.mjs";
import { f as markDiagnosticRunProgress } from "./diagnostic-run-activity-BlCpLag4.mjs";
//#region src/logging/diagnostic-model-stream-progress.ts
const MODEL_CALL_STREAM_PROGRESS_INTERVAL_MS = 3e4;
/** Canonical progress reason for model output observed on a live backend stream. */
const MODEL_CALL_STREAM_PROGRESS_REASON = "model_call:stream_progress";
function createModelCallStreamProgressReporter({ recordProgress, config } = {}) {
let lastEmittedAtMs;
return (target) => {
if (recordProgress && !recordProgress()) return;
const diagnosticsEnabled = areDiagnosticsEnabledForProcess();
const fields = {
runId: target.runId,
...target.sessionKey ? { sessionKey: target.sessionKey } : {},
...target.sessionId ? { sessionId: target.sessionId } : {},
reason: MODEL_CALL_STREAM_PROGRESS_REASON
};
if (diagnosticsEnabled && !recordProgress) markDiagnosticRunProgress(fields);
const now = Date.now();
if (lastEmittedAtMs !== void 0 && now - lastEmittedAtMs < MODEL_CALL_STREAM_PROGRESS_INTERVAL_MS) return;
const timelineEnabled = target.callId !== void 0 && isDiagnosticsTimelineEnabled({ config });
if (!diagnosticsEnabled && !timelineEnabled) return;
lastEmittedAtMs = now;
if (diagnosticsEnabled) emitTrustedDiagnosticEvent({
type: "run.progress",
...fields
});
if (timelineEnabled) emitDiagnosticsTimelineEvent({
type: "mark",
name: "provider.request.activity",
timestamp: new Date(now).toISOString(),
runId: target.runId,
spanId: target.callId
}, { config });
};
}
//#endregion
export { createModelCallStreamProgressReporter as t };