mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 11:55:12 +00:00
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import type { createSubsystemLogger } from "../logging/subsystem.js";
|
|
|
|
type SubsystemLogger = ReturnType<typeof createSubsystemLogger>;
|
|
|
|
type ModelTransportDebugEnv = NodeJS.ProcessEnv;
|
|
|
|
export type ModelPayloadDebugMode = "off" | "summary" | "tools" | "full-redacted";
|
|
export type ModelSseDebugMode = "off" | "events" | "peek";
|
|
|
|
function normalizeEnv(value: unknown): string {
|
|
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
}
|
|
|
|
function isTruthyEnv(value: unknown): boolean {
|
|
const normalized = normalizeEnv(value);
|
|
return (
|
|
normalized.length > 0 &&
|
|
normalized !== "0" &&
|
|
normalized !== "false" &&
|
|
normalized !== "off" &&
|
|
normalized !== "no"
|
|
);
|
|
}
|
|
|
|
export function resolveModelPayloadDebugMode(
|
|
env: ModelTransportDebugEnv = process.env,
|
|
): ModelPayloadDebugMode {
|
|
const normalized = normalizeEnv(env.OPENCLAW_DEBUG_MODEL_PAYLOAD);
|
|
if (normalized === "tools" || normalized === "full-redacted") {
|
|
return normalized;
|
|
}
|
|
if (normalized === "summary") {
|
|
return "summary";
|
|
}
|
|
return "off";
|
|
}
|
|
|
|
export function resolveModelSseDebugMode(
|
|
env: ModelTransportDebugEnv = process.env,
|
|
): ModelSseDebugMode {
|
|
const normalized = normalizeEnv(env.OPENCLAW_DEBUG_SSE);
|
|
if (normalized === "peek") {
|
|
return "peek";
|
|
}
|
|
if (normalized === "events" || isTruthyEnv(normalized)) {
|
|
return "events";
|
|
}
|
|
return "off";
|
|
}
|
|
|
|
export function isModelTransportDebugEnabled(env: ModelTransportDebugEnv = process.env): boolean {
|
|
return (
|
|
isTruthyEnv(env.OPENCLAW_DEBUG_MODEL_TRANSPORT) ||
|
|
resolveModelPayloadDebugMode(env) !== "off" ||
|
|
resolveModelSseDebugMode(env) !== "off" ||
|
|
isTruthyEnv(env.OPENCLAW_DEBUG_CODE_MODE)
|
|
);
|
|
}
|
|
|
|
export function isCodeModeDebugEnabled(env: ModelTransportDebugEnv = process.env): boolean {
|
|
return isTruthyEnv(env.OPENCLAW_DEBUG_CODE_MODE) || isModelTransportDebugEnabled(env);
|
|
}
|
|
|
|
export function emitModelTransportDebug(log: SubsystemLogger, message: string): void {
|
|
if (isModelTransportDebugEnabled()) {
|
|
log.info(message);
|
|
return;
|
|
}
|
|
log.debug(message);
|
|
}
|