File size: 2,312 Bytes
5c2a829
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Narrow agent-scope helpers for control-plane and migration paths.

import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
import {
  AgentSelectionRequiredError,
  tryResolveAmbientOwnerAgentId,
} from "../agents/agent-scope-config.js";
import {
  resolveSessionAgentIdStrict,
  resolveSessionAgentIdsStrict,
} from "../agents/agent-scope.js";
import { resolvePersistedSessionStoreOwnerForKey } from "../config/sessions/session-store-owner.js";

export {
  listAgentIds,
  resolveAgentConfig,
  resolveAgentDir,
  resolveDefaultAgentId,
  tryResolveDefaultAgentId,
} from "../agents/agent-scope.js";

export { resolveSessionAgentIdStrict, resolveSessionAgentIdsStrict };

type SessionAgentResolutionParams = Parameters<typeof resolveSessionAgentIdsStrict>[0];

/**
 * @deprecated Use `resolveSessionAgentIdsStrict` with an explicit or prepared
 * owner. Retained through 2026-11-29 for plugins shipped before strict
 * multi-agent ownership was introduced.
 */
function resolveSessionAgentIdsCompatibility(params: SessionAgentResolutionParams): {
  defaultAgentId: string;
  sessionAgentId: string;
} {
  try {
    return resolveSessionAgentIdsStrict(params);
  } catch (error) {
    const requestedAgentId =
      normalizeOptionalString(params.agentId) ?? normalizeOptionalString(params.fallbackAgentId);
    const config = params.config ?? {};
    if (
      !(error instanceof AgentSelectionRequiredError) ||
      requestedAgentId ||
      resolvePersistedSessionStoreOwnerForKey(config, params.sessionKey).kind !== "none"
    ) {
      throw error;
    }
    const ambientAgentId = tryResolveAmbientOwnerAgentId(config);
    if (!ambientAgentId) {
      throw error;
    }
    return resolveSessionAgentIdsStrict({ ...params, fallbackAgentId: ambientAgentId });
  }
}

/**
 * @deprecated Use `resolveSessionAgentIdStrict` with an explicit or prepared
 * owner. Retained through 2026-11-29 for plugins shipped before strict
 * multi-agent ownership was introduced.
 */
function resolveSessionAgentIdCompatibility(params: SessionAgentResolutionParams): string {
  return resolveSessionAgentIdsCompatibility(params).sessionAgentId;
}

export {
  resolveSessionAgentIdCompatibility as resolveSessionAgentId,
  resolveSessionAgentIdsCompatibility as resolveSessionAgentIds,
};