Conversation
- Add RequestType enum (CHAT, COUNT_TOKENS) - Define GuardConfig, GuardPipeline, GuardStep interfaces and adapters - Implement GuardPipelineBuilder to assemble dynamic guard chains - Provide presets: CHAT_PIPELINE and COUNT_TOKENS_PIPELINE - Wire proxy-handler to use pipeline and skip concurrency for count_tokens - Add ProxySession.isCountTokensRequest() helper
Feat/guard pipeline
修复供应商类型标签的 i18n 命名空间错误,将 "providers.types" 更正为 "settings.providers.types"。 受影响的组件: - provider-type-filter.tsx - provider-rich-list-item.tsx - provider-list-item.legacy.tsx 此修复解决了 Claude、Codex、Gemini CLI 等供应商类型标签无法正确读取翻译字符串的问题。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
代码审查总结✅ 架构优化亮点这个 PR 引入了 Guard Pipeline 系统,将原本硬编码的请求检查流程重构为可配置的管道模式,这是一次优秀的架构改进。主要优点:
📋 代码质量评估优点:
代码细节分析: 1. Guard Pipeline 实现(
|
| async run(session: ProxySession): Promise<Response | null> { | ||
| for (const step of steps) { | ||
| const res = await step.execute(session); | ||
| if (res) return res; // early exit |
Contributor
There was a problem hiding this comment.
建议: 添加错误边界处理和日志追踪,提升可调试性:
async run(session: ProxySession): Promise<Response | null> {
logger.debug('[GuardPipeline] Starting pipeline', {
steps: steps.map(s => s.name)
});
for (const step of steps) {
try {
logger.debug(`[GuardPipeline] Executing step: ${step.name}`);
const res = await step.execute(session);
if (res) {
logger.debug(`[GuardPipeline] Early exit at step: ${step.name}`);
return res;
}
} catch (error) {
logger.error(`[GuardPipeline] Step ${step.name} failed`, error);
throw error; // 保持现有行为,或根据策略决定是否继续
}
}
logger.debug('[GuardPipeline] Pipeline completed successfully');
return null;
}这样可以在日志中清晰地追踪每个步骤的执行情况。
|
|
||
| // 9. 增加并发计数(在所有检查通过后,请求开始前) | ||
| if (session.sessionId) { | ||
| // 9. 增加并发计数(在所有检查通过后,请求开始前)- 跳过 count_tokens |
Contributor
There was a problem hiding this comment.
建议: 更新注释编号或改为描述性注释,因为 pipeline 已经包含了步骤 1-8:
// 在所有检查通过后,请求开始前增加并发计数(跳过 count_tokens)
if (session.sessionId && !session.isCountTokensRequest()) {
await SessionTracker.incrementConcurrentCount(session.sessionId);
}这样更符合重构后的代码结构。
| */ | ||
| isCountTokensRequest(): boolean { | ||
| const endpoint = this.getEndpoint(); | ||
| return endpoint === "/v1/messages/count_tokens"; |
Contributor
There was a problem hiding this comment.
建议: 将端点路径提取为常量,避免魔法字符串:
// 在文件顶部定义
export const CLAUDE_ENDPOINTS = {
COUNT_TOKENS: '/v1/messages/count_tokens',
MESSAGES: '/v1/messages',
} as const;
// 在方法中使用
isCountTokensRequest(): boolean {
const endpoint = this.getEndpoint();
return endpoint === CLAUDE_ENDPOINTS.COUNT_TOKENS;
}这样更易于维护和修改。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.