mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 07:13:39 +00:00
Merged via squash.
Prepared head SHA: e61c724708
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
43 lines
1.3 KiB
TypeScript
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;
|
|
}
|