File size: 1,278 Bytes
f778c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { resolveAgentDir } from "../../agents/agent-scope.js";
import { assertAuthProfileStoreAgentOwner } from "../../agents/auth-profiles/sqlite.js";
import { getRuntimeConfigSourceSnapshot } from "../../config/config.js";
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import { getActiveSecretsRuntimeConfigSnapshot } from "../../secrets/runtime-state.js";

/**
 * Prepare the selected agent's account-owned SecretRefs for one standalone local
 * capability run. Every agent-scoped local runner calls this before provider auth.
 */
export async function prepareLocalCapabilityAccountSecrets(params: {
  cfg: OpenClawConfig;
  agentId: string;
}): Promise<void> {
  const agentDir = resolveAgentDir(params.cfg, params.agentId);
  assertAuthProfileStoreAgentOwner(agentDir, params.agentId);
  if (getActiveSecretsRuntimeConfigSnapshot()) {
    return;
  }

  const secretsRuntime = await import("../../secrets/runtime.js");
  const snapshot = await secretsRuntime.prepareSecretsRuntimeSnapshot({
    config: getRuntimeConfigSourceSnapshot() ?? params.cfg,
    assignmentConfig: params.cfg,
    agentDirs: [agentDir],
    includeConfigRefs: false,
    allowUnavailableSecretOwners: true,
  });
  secretsRuntime.activateSecretsRuntimeSnapshot(snapshot);
}