File size: 1,269 Bytes
e249c6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import {
  classifySessionKeyShape,
  isUnscopedSessionKeySentinel,
  scopeLegacySessionKeyToAgent,
} from "../../routing/session-key.js";
import { resolveSessionAgentIds } from "../agent-scope.js";

export function resolveExplicitAgentCommandSessionKey(params: {
  rawExplicitSessionKey?: string;
  agentIdOverride?: string;
  shouldScopeDefaultAgentKey?: boolean;
  cfg: OpenClawConfig;
}): string | undefined {
  // Storage sentinels keep their logical key; resolveSession validates the separate owner.
  if (isUnscopedSessionKeySentinel(params.rawExplicitSessionKey)) {
    return params.rawExplicitSessionKey;
  }
  const unscopedOwnerAgentId =
    classifySessionKeyShape(params.rawExplicitSessionKey) === "legacy_or_alias" &&
    (params.agentIdOverride || params.shouldScopeDefaultAgentKey)
      ? resolveSessionAgentIds({
          config: params.cfg,
          agentId: params.agentIdOverride,
          sessionKey: params.rawExplicitSessionKey,
        }).sessionAgentId
      : undefined;
  return scopeLegacySessionKeyToAgent({
    agentId: unscopedOwnerAgentId ?? params.agentIdOverride,
    sessionKey: params.rawExplicitSessionKey,
    mainKey: params.cfg.session?.mainKey,
  });
}