Enhance DuckGo request handling and VQD hash generation#40
Merged
Conversation
- 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类型定义和流式输出支持
There was a problem hiding this comment.
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 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)) | ||
| } |
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.
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
ConvertAPIRequestfunction 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
/responsesendpoint 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:
2.1.6. (VERSION)Build and Deployment Modernization
tzdatafor timezone support. (Dockerfile) [1] [2]go.mod) dependencies updated to latest stable versions, including Go 1.25. (go.mod)Core Application Enhancements
llama-4-scout,mistral-small, etc.) in request conversion, improving compatibility with additional models. (conversion/requests/duckgo/convert.go)/responsesendpoint for improved error handling and streaming support. (initialize/handlers.go) [1] [2]Miscellaneous
2.1.6. (VERSION)