Skip to content

Enhance dynamic model support and optimize user agent handling#266

Merged
xiaozhou26 merged 4 commits into
mainfrom
dev
Jun 12, 2026
Merged

Enhance dynamic model support and optimize user agent handling#266
xiaozhou26 merged 4 commits into
mainfrom
dev

Conversation

@xiaozhou26

Copy link
Copy Markdown
Collaborator

No description provided.

- 新增util包的RandomUserAgent函数,生成主流桌面浏览器随机UA
- 替换所有硬编码userAgent为defaultUserAgent()调用
- 为客户端状态加入UserAgent字段并初始化随机UA
- 重构prooftoken模块,适配新的随机UA和POW逻辑
Copilot AI review requested due to automatic review settings June 12, 2026 10:43
@xiaozhou26 xiaozhou26 enabled auto-merge (squash) June 12, 2026 10:43
@xiaozhou26 xiaozhou26 disabled auto-merge June 12, 2026 10:43
@xiaozhou26 xiaozhou26 merged commit 6cdb974 into main Jun 12, 2026
1 of 2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates ChatGPT client request handling to support dynamic per-client User-Agent selection, modernizes proof-of-work (PoW) token generation, and improves streaming/TTS parsing and model propagation.

Changes:

  • Added a randomized desktop User-Agent generator and began using it (or a per-client override) across request paths.
  • Reworked Sentinel PoW token generation into a requirements-token builder plus a challenge-based proof-token solver.
  • Improved request/model propagation in handlers and added tests for TTS patch-stream parsing and response conversion.

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
util/useragent.go Adds randomized desktop User-Agent generation helper.
util/useragent_test.go Adds tests to validate UA generation behavior.
internal/prooftoken/prooftoken.go Refactors PoW token generation/solving logic and constants.
internal/chatgpt/request.go Switches many request paths to use dynamic UA, updates PoW calls, improves TTS stream parsing, and model fallback behavior.
internal/chatgpt/request_test.go Updates handler tests and adds TTS patch-stream parsing tests.
internal/chatgpt/files.go Uses the new default UA behavior for upload requests.
internal/chatgpt/client_state.go Adds per-client UserAgent to state and initializes it randomly.
internal/chatgpt/artifact_delivery.go Uses the new default UA behavior for artifact downloads.
initialize/handlers.go Updates TTS handler flow to use client-order conversation posting and state.
conversion/response/chatgpt/convert.go Uses request model consistently; safer text-part extraction.
conversion/response/chatgpt/convert_test.go Adds conversion tests for model propagation and source-marker behavior.
go.mod Removes funcaptcha dependency; adds fake-useragent.
go.sum Removes funcaptcha checksums.
.gitignore Adds .atomcode and CLAUDE.md ignores; normalizes .gocache.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread util/useragent.go
Comment on lines +60 to +83
var (
uaRand *rand.Rand
uaRandOnce sync.Once
)

func initUARand() {
uaRandOnce.Do(func() {
uaRand = rand.New(rand.NewSource(time.Now().UnixNano()))
})
}

// RandomUserAgent 返回一个随机的主流桌面浏览器 User-Agent
func RandomUserAgent() string {
initUARand()
spec := userAgentSpecs[uaRand.Intn(len(userAgentSpecs))]

version := spec.MinVersion
if spec.MaxVersion > spec.MinVersion {
version += uaRand.Intn(spec.MaxVersion - spec.MinVersion + 1)
}

// 部分模板里有两个 %d(如 Edge、Fx),用同一个 version 填充
return fmt.Sprintf(spec.Template, version, version)
}
Comment thread util/useragent_test.go
Comment on lines +11 to +18
ua := RandomUserAgent()
if strings.TrimSpace(ua) == "" {
t.Fatalf("empty UA at iter %d", i)
}
if !strings.HasPrefix(ua, "Mozilla/5.0") {
t.Errorf("UA does not start with Mozilla/5.0: %s", ua)
}
seen[ua] = true
Comment on lines +24 to 28
maxRequirementsIter = 500_000
maxProofIter = 100_000

powFallback = "gAAAAABwQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D"
)
Comment on lines +164 to +177
// Python: h[:diff_len] <= target
// diff_len 是字符数(6),target 是字节(3)。Python bytes cmp 按短的逐字节比较。
// 这里保持等价:取 min(len(target), len(sum)) 字节比较。
n2 := diffLen
if n2 > len(sum) {
n2 = len(sum)
}
cmpLen := n2
if cmpLen > len(target) {
cmpLen = len(target)
}
if bytes.Compare(sum[:cmpLen], target[:cmpLen]) <= 0 {
return string(b64buf), true
}
Comment on lines 23 to 31
@@ -24,6 +26,7 @@ func NewChatClientState() *ChatClientState {
SessionID: uuid.NewString(),
StartTime: time.Now(),
ParentMessageID: "client-created-root",
UserAgent: browser.Random(),
}
}
Comment on lines +2617 to +2621
ua := defaultUserAgent()
if state != nil && state.UserAgent != "" {
ua = state.UserAgent
}
header.Set("user-agent", ua)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants