Skip to content

Enhance DuckGo request handling and VQD hash generation#40

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

Enhance DuckGo request handling and VQD hash generation#40
xiaozhou26 merged 4 commits into
mainfrom
dev

Conversation

@xiaozhou26

Copy link
Copy Markdown
Contributor

This pull request introduces significant updates across the build system, dependency management, Docker configuration, and the core application logic. The main goals are to modernize the build and deployment pipelines, update dependencies, enhance model support and request handling, and improve code maintainability.

Build and CI/CD Modernization:

  • GitHub Actions workflows have been updated for both binary and Docker builds. The workflows now use newer action versions, matrix builds for multiple platforms, improved artifact handling, and automated version/tag management. Docker builds now push multi-architecture images with semantic versioning and commit SHA tags. (.github/workflows/build.yml, .github/workflows/build_docker.yml, .github/workflows/Test.yml) [1] [2] [3]

  • Dockerfile now uses Go 1.25, adds timezone data for better locale support, and aligns with the updated build pipeline. (Dockerfile) [1] [2]

  • Go module dependencies are updated to the latest versions, including a bump to Go 1.25, ensuring improved security, performance, and compatibility. (go.mod)

Application Logic Improvements:

  • Model support enhancements: The API request conversion logic now recognizes additional model name prefixes (e.g., llama-4-scout, mistral-small) and maps them to their corresponding backend models, increasing compatibility with new model variants. (conversion/requests/duckgo/convert.go)

  • Request conversion refactor: The ConvertAPIRequest function is refactored for clarity and robustness, with improved content extraction and durable stream generation using RSA keys and UUIDs. (conversion/requests/duckgo/convert.go)

  • Handler improvements: The DuckDuckGo handler is refactored for better error handling and code reuse. A new /responses endpoint is added for handling response streaming, and utility functions are introduced for request translation and streaming output. (initialize/handlers.go) [1] [2]

Other Notable Changes:

  • Version bump: The application version is updated to 2.1.6. (VERSION)
  • README cleanup: Unused or outdated sections are removed from the documentation. (README.md)
  • Build script update: The build script now uses the correct package name. (build.sh)

Build and Deployment Modernization

  • Updated all GitHub Actions workflows to use the latest action versions, matrix builds for multi-arch binaries, and improved artifact/release management; Docker builds now push with semantic version and SHA tags. (.github/workflows/build.yml, .github/workflows/build_docker.yml, .github/workflows/Test.yml) [1] [2] [3]
  • Dockerfile now uses Go 1.25 and installs tzdata for timezone support. (Dockerfile) [1] [2]
  • Go module (go.mod) dependencies updated to latest stable versions, including Go 1.25. (go.mod)

Core Application Enhancements

  • Added support for new model prefixes (llama-4-scout, mistral-small, etc.) in request conversion, improving compatibility with additional models. (conversion/requests/duckgo/convert.go)
  • Refactored request conversion logic for clarity, robust content extraction, and durable stream generation with RSA keys and UUIDs. (conversion/requests/duckgo/convert.go)
  • Refactored DuckDuckGo handler and added a new /responses endpoint for improved error handling and streaming support. (initialize/handlers.go) [1] [2]

Miscellaneous

  • Bumped application version to 2.1.6. (VERSION)
  • Cleaned up README and corrected build script package name. (README.md, build.sh) [1] [2]

- Updated request.go to include new token handling and API endpoint adjustments.
- Introduced durable stream and metadata structures in typings for improved API request handling.
- Added VQD hash generation logic in a new vqd.go file, including JavaScript execution for hash computation.
- Enhanced error handling and response management in POST conversation logic.
- Updated utility functions for better logging and token counting.
主要变更:
1. 更新项目版本号至2.1.6
2. 重构构建配置,重命名项目为duck2api
3. 新增/v1/responses和/v1/response接口支持自定义对话格式
4. 更新CI/CD配置,优化构建和Docker发布流程
5. 升级Go版本和依赖action版本
6. 移除内置web静态文件服务和相关资源
7. 优化token缓存逻辑和请求重试机制
8. 新增响应式API类型定义和流式输出支持
Copilot AI review requested due to automatic review settings June 7, 2026 15:19
@xiaozhou26 xiaozhou26 merged commit 9844bd2 into main Jun 7, 2026
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 modernizes the build/deployment pipeline and updates the DuckDuckGo integration by introducing VQD hash generation, richer DuckDuckGo request metadata (durable stream/tool flags), and an OpenAI-like /v1/responses endpoint alongside refactors to request conversion/handling.

Changes:

  • Updated CI workflows and Docker build/publish logic, plus Go version/dependency bumps.
  • Reworked DuckDuckGo token initialization and request sending (duck.ai endpoints, VQD hash execution, retry behavior, FE version signals).
  • Added OpenAI Responses-compatible request/response typings and handlers, including SSE-style response events.

Reviewed changes

Copilot reviewed 18 out of 22 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
VERSION Bumps application version to 2.1.6.
util/util.go Updates slog warning to structured logging.
typings/official/response.go Adds Responses API/stream event structs and constructors.
typings/official/request.go Adds Responses API request type and conversion to chat completions.
typings/duckgo/request.go Expands DuckGo request schema (metadata, durable stream, tool flags).
README.md Removes web UI documentation section.
main.go Removes embedded static web serving.
internal/duckgo/vqd.go Adds VQD hash generation by executing provided JS via goja.
internal/duckgo/request.go Refactors DuckGo status/chat calls, headers, FE version signals, retry logic, and response helpers.
initialize/router.go Registers /v1/responses and /v1/response endpoints.
initialize/handlers.go Refactors DuckDuckGo handler and adds Responses API handler + streaming writer.
go.mod Bumps Go version and updates/adds dependencies (incl. goja).
go.sum Updates dependency checksums accordingly.
Dockerfile Switches build image to Go 1.25 and installs tzdata in runtime image.
conversion/requests/duckgo/convert.go Refactors request conversion, adds model mappings and durable stream generation.
build.sh Adjusts output package/binary naming.
.github/workflows/Test.yml Updates actions and uses go-version-file with caching.
.github/workflows/build.yml Reworks release workflow into version/build/release jobs (currently manual trigger only).
.github/workflows/build_docker.yml Updates Docker build/push workflow and tagging scheme.

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

Comment on lines +85 to 108
maxRetries := 3
var response *http.Response
var err error

for i := 0; i <= maxRetries; i++ {
response, err = postConversationOnce(client, request, token)
if err != nil {
return nil, err
}

if response.StatusCode != http.StatusTeapot && response.StatusCode != http.StatusTooManyRequests {
return response, nil
}

response.Body.Close()
resetXVQD()
token, err = InitXVQD(client, proxyUrl)
if err != nil {
return nil, err
}
}

return response, nil
}
Comment on lines +142 to 145
header.Set("origin", "https://duck.ai")
header.Set("referer", "https://duck.ai/")
header.Set("sec-ch-ua", `"Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99"`)
header.Set("sec-ch-ua-mobile", "?0")
Comment on lines 42 to 45
with:
registry: ghcr.io
registry: ghcr
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
Comment on lines 3 to 5
on:
push:
branches:
- main
paths-ignore:
- 'README.md'
workflow_dispatch:

Comment on lines +73 to +77
func newDurableStream() duckgotypes.DurableStream {
key, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return duckgotypes.DurableStream{}
}
Comment thread internal/duckgo/vqd.go
Comment on lines +51 to +63
func executeVQDHashScript(jsCode string) (string, error) {
vm := goja.New()
if err := installVQDHelpers(vm); err != nil {
return "", err
}
if _, err := vm.RunString(vqdBrowserPrelude); err != nil {
return "", fmt.Errorf("initialize vqd browser mock: %w", err)
}

value, err := vm.RunString(jsCode)
if err != nil {
return "", fmt.Errorf("execute vqd hash script: %s", jsErrorString(vm, err, nil))
}
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