import { normalizeChatType } from "../channels/chat-type.js"; import type { SessionChatType, SessionEntry } from "../config/sessions.js"; import type { OpenClawConfig } from "../config/types.openclaw.js"; import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalLowercaseString,
} from "../shared/string-coerce.js"; import { deriveSessionChatType } from "./session-chat-type.js";
export type SessionSendPolicyDecision = "allow" | "deny";
export function normalizeSendPolicy(raw?: string | null): SessionSendPolicyDecision | undefined { const value = normalizeOptionalLowercaseString(raw); if (value === "allow") { return"allow";
} if (value === "deny") { return"deny";
} return undefined;
}
function normalizeMatchValue(raw?: string | null) { const value = normalizeOptionalLowercaseString(raw); return value ? value : undefined;
}
function stripAgentSessionKeyPrefix(key?: string): string | undefined { if (!key) { return undefined;
} const parts = key.split(":").filter(Boolean); // Canonical agent session keys: agent:<agentId>:<sessionKey...> if (parts.length >= 3 && parts[0] === "agent") { return parts.slice(2).join(":");
} return key;
}
function deriveChannelFromKey(key?: string) { const normalizedKey = stripAgentSessionKeyPrefix(key); if (!normalizedKey) { return undefined;
} const parts = normalizedKey.split(":").filter(Boolean); if (parts.length >= 3 && (parts[1] === "group" || parts[1] === "channel")) { return normalizeMatchValue(parts[0]);
} return undefined;
}
function deriveChatTypeFromKey(key?: string): SessionChatType | undefined { const normalizedKey = normalizeOptionalLowercaseString(stripAgentSessionKeyPrefix(key)); if (!normalizedKey) { return undefined;
} const tokens = new Set(normalizedKey.split(":").filter(Boolean)); if (tokens.has("group")) { return"group";
} if (tokens.has("channel")) { return"channel";
} if (tokens.has("direct") || tokens.has("dm")) { return"direct";
} const derived = deriveSessionChatType(normalizedKey); if (derived !== "unknown") { return derived;
} return undefined;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.