Skip to content

Commit 1e2954c

Browse files
MikotoZeroclaude
andcommitted
refactor(http): use ResolvedContext for token resolution
主要改进: - HttpClient 使用 ResolvedContext.resolveToken() - 移除重复的 token 解析逻辑 - 统一使用 ResolvedContext 的方法 - 代码从 13 行简化为 3 行 实现: - 在 request() 中动态创建 ResolvedContext - 调用 ctx.resolveToken() 获取 token - 复用 ResolvedContext 的完整逻辑 优点: - ✅ 消除代码重复 - ✅ 逻辑集中在 ResolvedContext - ✅ 易于维护 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 470b642 commit 1e2954c

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

src/core/network/httpClient.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class HttpClient {
105105
private context?: import('../types/index.js').RequestContext;
106106

107107
/**
108-
* @param context - RequestContext (for token resolution and user identification)
108+
* @param context - RequestContext (包含 token 或用于 token 解析)
109109
*/
110110
constructor(context?: import('../types/index.js').RequestContext) {
111111
this.context = context;
@@ -178,19 +178,10 @@ export class HttpClient {
178178
}
179179
}
180180

181-
// ✅ 动态解析 token(从 context 或文件加载)
182-
let effectiveMacToken: MacToken | null = null;
183-
184-
if (this.context?.macToken?.kid && this.context?.macToken?.mac_key) {
185-
effectiveMacToken = this.context.macToken;
186-
} else if (EnvConfig.transport === 'stdio' && this.context) {
187-
// stdio 模式从用户隔离文件加载
188-
const userId = this.context.userId || 'local';
189-
const projectId = this.context.projectId;
190-
const { loadTokenFromFile, getTokenPath } = await import('../auth/tokenStorage.js');
191-
const tokenPath = getTokenPath(userId, projectId);
192-
effectiveMacToken = loadTokenFromFile(tokenPath);
193-
}
181+
// ✅ 使用 ResolvedContext 解析 token
182+
const { ResolvedContext } = await import('../types/context.js');
183+
const ctx = new ResolvedContext({}, this.context || {});
184+
const effectiveMacToken = ctx.resolveToken();
194185

195186

196187
// Generate MAC Authorization header

0 commit comments

Comments
 (0)