mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 16:47:27 +00:00
Dead code: remove unused helper modules (#38318)
* Dead code: remove unused provider runtime policy helper * Dead code: remove unused shared env writer * Dead code: remove unused auth store path collector
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
import { resolveRuntimeGroupPolicy } from "./runtime-group-policy.js";
|
||||
import type { GroupPolicy } from "./types.base.js";
|
||||
|
||||
export function resolveProviderRuntimeGroupPolicy(params: {
|
||||
providerConfigPresent: boolean;
|
||||
groupPolicy?: GroupPolicy;
|
||||
defaultGroupPolicy?: GroupPolicy;
|
||||
}): {
|
||||
groupPolicy: GroupPolicy;
|
||||
providerMissingFallbackApplied: boolean;
|
||||
} {
|
||||
return resolveRuntimeGroupPolicy({
|
||||
providerConfigPresent: params.providerConfigPresent,
|
||||
groupPolicy: params.groupPolicy,
|
||||
defaultGroupPolicy: params.defaultGroupPolicy,
|
||||
configuredFallbackPolicy: "open",
|
||||
missingProviderFallbackPolicy: "allowlist",
|
||||
});
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { escapeRegExp, resolveConfigDir } from "../utils.js";
|
||||
|
||||
export function upsertSharedEnvVar(params: {
|
||||
key: string;
|
||||
value: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}): { path: string; updated: boolean; created: boolean } {
|
||||
const env = params.env ?? process.env;
|
||||
const dir = resolveConfigDir(env);
|
||||
const filepath = path.join(dir, ".env");
|
||||
const key = params.key.trim();
|
||||
const value = params.value;
|
||||
|
||||
let raw = "";
|
||||
if (fs.existsSync(filepath)) {
|
||||
raw = fs.readFileSync(filepath, "utf8");
|
||||
}
|
||||
|
||||
const lines = raw.length ? raw.split(/\r?\n/) : [];
|
||||
const matcher = new RegExp(`^(\\s*(?:export\\s+)?)${escapeRegExp(key)}\\s*=`);
|
||||
let updated = false;
|
||||
let replaced = false;
|
||||
|
||||
const nextLines = lines.map((line) => {
|
||||
const match = line.match(matcher);
|
||||
if (!match) {
|
||||
return line;
|
||||
}
|
||||
replaced = true;
|
||||
const prefix = match[1] ?? "";
|
||||
const next = `${prefix}${key}=${value}`;
|
||||
if (next !== line) {
|
||||
updated = true;
|
||||
}
|
||||
return next;
|
||||
});
|
||||
|
||||
if (!replaced) {
|
||||
nextLines.push(`${key}=${value}`);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
||||
}
|
||||
|
||||
const output = `${nextLines.join("\n")}\n`;
|
||||
fs.writeFileSync(filepath, output, "utf8");
|
||||
fs.chmodSync(filepath, 0o600);
|
||||
|
||||
return { path: filepath, updated, created: !raw };
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { listAgentIds, resolveAgentDir } from "../agents/agent-scope.js";
|
||||
import { resolveAuthStorePath } from "../agents/auth-profiles/paths.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
|
||||
export function collectAuthStorePaths(config: OpenClawConfig, stateDir: string): string[] {
|
||||
const paths = new Set<string>();
|
||||
// Scope default auth store discovery to the provided stateDir instead of
|
||||
// ambient process env, so callers do not touch unrelated host-global stores.
|
||||
paths.add(path.join(resolveUserPath(stateDir), "agents", "main", "agent", "auth-profiles.json"));
|
||||
|
||||
const agentsRoot = path.join(resolveUserPath(stateDir), "agents");
|
||||
if (fs.existsSync(agentsRoot)) {
|
||||
for (const entry of fs.readdirSync(agentsRoot, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
paths.add(path.join(agentsRoot, entry.name, "agent", "auth-profiles.json"));
|
||||
}
|
||||
}
|
||||
|
||||
for (const agentId of listAgentIds(config)) {
|
||||
if (agentId === "main") {
|
||||
paths.add(
|
||||
path.join(resolveUserPath(stateDir), "agents", "main", "agent", "auth-profiles.json"),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const agentDir = resolveAgentDir(config, agentId);
|
||||
paths.add(resolveUserPath(resolveAuthStorePath(agentDir)));
|
||||
}
|
||||
|
||||
return [...paths];
|
||||
}
|
||||
Reference in New Issue
Block a user