Fix https://github.com/sunnoy/openclaw-plugin-wecom/issues/49#52
Fix https://github.com/sunnoy/openclaw-plugin-wecom/issues/49#52roamerxv wants to merge 4 commits intosunnoy:mainfrom
Conversation
|
感谢 PR!环境变量替换这个需求很实用,不过当前实现有几个问题需要修改: 1. 替换结果未使用(Bug)const corpId = resolveEnvVars(agent?.corpId);
const corpSecret = resolveEnvVars(agent?.corpSecret);
const agentId = resolveEnvVars(agent?.agentId);
// ❌ 下面判断和返回还是用的原始 agent.xxx,替换后的值被丢弃了
if (!agent?.corpId || !agent?.corpSecret || !agent?.agentId) return null;
return { corpId: agent.corpId, corpSecret: agent.corpSecret, agentId: agent.agentId };应该改为: if (!corpId || !corpSecret || !agentId) return null;
return { corpId, corpSecret, agentId };2. 覆盖面不够当前只处理了 3. 建议:在配置加载层统一处理更好的做法是在配置加载时对整个 config 对象做一次递归的环境变量替换,而不是在 function deepResolveEnvVars(obj) {
if (typeof obj === "string") {
return obj.replace(/\$\{([^}]+)\}/g, (m, k) => process.env[k] || m);
}
if (Array.isArray(obj)) return obj.map(deepResolveEnvVars);
if (obj && typeof obj === "object") {
const result = {};
for (const [k, v] of Object.entries(obj)) result[k] = deepResolveEnvVars(v);
return result;
}
return obj;
}可以在 另外注意 |
|
好的。我也只是粗略过了一下。没有全局考虑。等待你们发布最新版本来 涵盖 openclaw 的 secret 的官方做法
Hui Liu ***@***.***> 于2026年3月2日周一 16:56写道:
… *sunnoy* left a comment (sunnoy/openclaw-plugin-wecom#52)
<#52 (comment)>
感谢 PR!环境变量替换这个需求很实用,不过当前实现有几个问题需要修改:
1. 替换结果未使用(Bug)
const corpId = resolveEnvVars(agent?.corpId);const corpSecret = resolveEnvVars(agent?.corpSecret);const agentId = resolveEnvVars(agent?.agentId);
// ❌ 下面判断和返回还是用的原始 agent.xxx,替换后的值被丢弃了if (!agent?.corpId || !agent?.corpSecret || !agent?.agentId) return null;return { corpId: agent.corpId, corpSecret: agent.corpSecret, agentId: agent.agentId };
应该改为:
if (!corpId || !corpSecret || !agentId) return null;return { corpId, corpSecret, agentId };
2. 覆盖面不够
当前只处理了 agent.corpId / corpSecret / agentId 三个字段。实际上 token、encodingAesKey、
agent.token、agent.encodingAesKey 等字段也可能需要环境变量。在单个函数里逐字段替换不够通用。
3. 建议:在配置加载层统一处理
更好的做法是在配置加载时对整个 config 对象做一次递归的环境变量替换,而不是在 resolveAgentConfig() 里打补丁。例如:
function deepResolveEnvVars(obj) {
if (typeof obj === "string") {
return obj.replace(/\$\{([^}]+)\}/g, (m, k) => process.env[k] || m);
}
if (Array.isArray(obj)) return obj.map(deepResolveEnvVars);
if (obj && typeof obj === "object") {
const result = {};
for (const [k, v] of Object.entries(obj)) result[k] = deepResolveEnvVars(v);
return result;
}
return obj;}
可以在 setOpenclawConfig(config) 时统一调用一次,这样所有字段都支持 ${VAR} 语法,后续也不用逐个函数修改。
------------------------------
另外注意 main 分支的 state.js 已经重构过(resolveAgentConfig 现在走 accounts.js
的多账号解析层),当前 PR 的 diff 会有冲突,需要 rebase 后在 accounts.js 的 buildAccount() 或
setOpenclawConfig() 中统一做环境变量替换。
—
Reply to this email directly, view it on GitHub
<#52 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAM7S6OIKO4AYMOMZWTUTKD4OVEEHAVCNFSM6AAAAACWDMWGJKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSOBTGAYTSMRQG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
感谢提交这个修复方向。不过这条 PR 目前我建议先不要直接合,主要是它已经明显落后于当前主干结构了。 现在的 另外,从改动内容看,这条 PR 的核心目标是支持配置里的
如果后面基于最新主干重开一个更小、更聚焦的 PR,这个能力我觉得是可以继续评估的。 |
|
感谢 PR!不过这个方案有几个问题不太适合合并:
建议:如果需要在 config 中使用环境变量,可以直接在 关闭此 PR。 |
|
Closing — related issue #49 is already closed and env var resolution belongs in the OpenClaw core, not the plugin layer. |
ix #49