Skip to content

Main - #87

Open
98654561111 wants to merge 4 commits into
Sophomoresty:mainfrom
98654561111:main
Open

Main#87
98654561111 wants to merge 4 commits into
Sophomoresty:mainfrom
98654561111:main

Conversation

@98654561111

Copy link
Copy Markdown

No description provided.

Arena Agent and others added 4 commits August 24, 2026 04:40
…chip frames

The response parser picked the longest text found anywhere in the
StreamGenerate response (single-file: the last text). A Gemini Web
response also contains thought summaries, alternative drafts and
follow-up/image frames; when the real answer was short (e.g. replying
to '??'), a longer unrelated frame won and the API returned content
that had nothing to do with the user's question.

- Frame-aware parser: only the primary candidate of the main answer
  frame (the one carrying conversation/response ids) is used; answer
  segments are joined instead of returning the longest fragment;
  longest joined candidate kept as protocol-drift fallback
- Streaming: same strict frame selection; no more splicing unrelated
  texts (t[len(prev):] without prefix check) and no more spurious
  'content changed' retries; freezes on mid-stream rewrites; rescans
  buffered response as fallback; retries only when nothing was emitted
- _reqid: process-wide browser-like incrementing counter (+100000 per
  call) instead of timestamp; concurrent requests (cronjob + chat) no
  longer send identical request ids; fresh id on every retry attempt
- Applied to both the package (gemini_web2api/gemini.py) and the
  single-file build (gemini_web2api.py)
- Add tests/test_response_parsing.py with simulated multi-frame wire
  payloads covering all failure modes (36 tests total, all pass)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
The Cloudflare Worker port had the same three bugs fixed in the Python
version:

- extractResponseText used 'last non-empty text anywhere' -- a thought
  summary / follow-up chip frame appearing after the answer won and the
  API returned content unrelated to the question
- streaming emitted t.slice(prevText.length) with only a length check,
  splicing unrelated frames into the output
- _reqid came from a timestamp, so concurrent requests sent identical ids

Port the fixes: frame-aware parser (main answer frame only, joined
segments, fallback tiers), strict streaming with freeze-on-rewrite and
end-of-stream fallback rescan, process-wide incrementing _reqid.
Adds tests/worker_parsing.test.js (Node, 12 checks).

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Cloudflare's 'Connect Git repository' flow runs 'npx wrangler deploy'
as the build command, which failed because the repo had no wrangler
config. Add wrangler.toml pointing main at cloudflare/worker.js
(validated with 'npx wrangler@latest deploy --dry-run', 48.58 KiB
bundle, no errors) and document the flow plus the Access/non-prod-build
toggles in cloudflare/README.MD.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
fix: 只回传主答案框架(修复答非所问)+ Cloudflare 部署支持
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.

1 participant