Files
openclaw/src/agents/session-agent-binding.ts
Josh Lehman 9119492f15 fix: preserve plugin LLM command auth (#85936)
Merged via squash.

Prepared head SHA: e61c724708
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
2026-05-26 22:41:52 -04:00

43 lines
1.3 KiB
TypeScript

import type { OpenClawConfig } from "../config/types.openclaw.js";
import {
parseAgentSessionKey,
normalizeAgentId,
normalizeMainKey,
} from "../routing/session-key.js";
import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalString,
} from "../shared/string-coerce.js";
import { resolveDefaultAgentId } from "./agent-scope.js";
/**
* Resolve the trusted active agent bound to a host-owned session reference.
*/
export function resolveBoundAgentIdForSession(params: {
config?: OpenClawConfig;
sessionKey?: string;
agentId?: string;
}): string | undefined {
const explicitAgentId = normalizeOptionalString(params.agentId);
if (explicitAgentId) {
return normalizeAgentId(explicitAgentId);
}
const normalizedSessionKey = normalizeOptionalString(params.sessionKey);
if (!normalizedSessionKey) {
return undefined;
}
const parsed = parseAgentSessionKey(normalizedSessionKey);
if (parsed?.agentId) {
return normalizeAgentId(parsed.agentId);
}
const loweredSessionKey = normalizeLowercaseStringOrEmpty(normalizedSessionKey);
const mainKey = normalizeMainKey(params.config?.session?.mainKey);
if (loweredSessionKey === "main" || loweredSessionKey === mainKey) {
return resolveDefaultAgentId(params.config ?? {});
}
return undefined;
}