mirror of
https://github.com/Hmbown/DeepSeek-TUI.git
synced 2026-09-02 22:36:19 +08:00
CodeWhale had two hand-rolled device-code pollers with nothing shared
between them (crates/cli/src/cloud.rs poll_device, crates/tui/src/
xai_oauth.rs poll_device_token + device_poll_backoff). The xAI one
decided whether to keep polling by substring-matching its own error
strings, which is why slow_down handling was stringly typed.
Port pi's pollOAuthDeviceCodeFlow to Rust as codewhale_config::
device_code::DeviceCodePoll, generic over the poll result and free of
I/O: the caller supplies poll and sleep. It carries pi's accumulated
fixes, which CodeWhale did not all have:
- RFC 8628 3.2 default of 5s when the server omits interval
- slow_down that PREFERS a server-supplied interval over the
client-tracked one, because a purely client-tracked interval polls
early forever under WSL/VM clock drift; RFC 8628 3.5's +5s step is
the fallback
- a deadline from expires_in that is never slept past, including
after backoff
- a distinct timeout message once any slow_down was seen
Also ports pi's validateVerificationUri as
validate_browser_verification_uri: the URI comes off the wire and is
handed to a browser opener, so it must not be able to launch file:,
javascript:, or a custom app scheme. pi requires https; this allows
http on a loopback host as well, matching the loopback allowance
crates/cli/src/cloud.rs already makes for a self-hosted test API.
The primitive never holds, formats, or logs token material: T is
opaque to the module and no Debug/Display derive touches it.
Ported from pi (MIT, Copyright (c) 2025 Mario Zechner),
packages/ai/src/auth/oauth/device-code.ts and .../xai.ts; notice
carried in THIRD_PARTY_NOTICES.md and at the top of the new module.
Implemented with agent assistance.
Signed-off-by: Hunter Bown <hmbown@gmail.com>
1.6 KiB
1.6 KiB
Third-party notices
Source vendored or ported into this repository, beyond the crates resolved by
Cargo (whose licences are enforced by deny.toml).
pi (pi-mono) — MIT
crates/config/src/device_code.rs is a Rust port of pi's OAuth device-code
polling loop and verification-URI check:
packages/ai/src/auth/oauth/device-code.ts(pollOAuthDeviceCodeFlow, the RFC 8628 polling behaviours)packages/ai/src/auth/oauth/xai.ts(validateVerificationUri)
Upstream: https://github.com/badlogic/pi-mono
MIT License
Copyright (c) 2025 Mario Zechner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.