🐛 fix(amp-code): 修复 AMP Code 缓存 #85
Merged
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.
概述
本 PR 为 AMP Code 透明代理实现了 Claude API 会话标识自动生成功能,当请求缺少
metadata.user_id时自动注入,确保会话上下文的连续性。功能亮点
🔑 会话标识自动生成
user_{64位hex}_account__session_{uuid}metadata.user_id缺失或为空时生成🔐 安全增强
SHA256(API_Key + User-Agent)生成 64 位 hexSHA256(messages[:3])→ UUID 格式(支持复用)UUID v4随机生成(避免碰撞)📋 字段顺序保持
metadata字段model→system→messages→tools→metadata→max_tokens→thinking→stream数据流设计
技术实现
后端(Rust)
新增依赖
新增函数(
services/proxy/headers/amp_processor.rs)generate_user_hash()generate_session_uuid()inject_metadata_with_order()修改逻辑
ApiType::Claude分支:在调用ClaudeHeadersProcessor前检查并注入metadata.user_id生成示例
测试情况
代码质量检查
功能测试
风险评估
低风险 ✅
需注意⚠️
Breaking Changes: 无
依赖变更: 新增
uuid = { version = "1", features = ["v4"] }