@magpie-community/opencode-grok-auth 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/index.mjs +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,6 +93,9 @@ API (`@ai-sdk/openai`), signed as the CLI signs them:
|
|
|
93
93
|
(`500000` for `@500k`). The plain id sends no such header and stays on
|
|
94
94
|
the default window.
|
|
95
95
|
- `x-grok-conv-id`: the request's `prompt_cache_key`.
|
|
96
|
+
- `x-grok-doom-loop-check: 1024` and `x-grok-exact-repetition-check: 64`
|
|
97
|
+
on a Responses request, as Grok Build sends them: the proxy then stops a
|
|
98
|
+
reply that repeats itself after ~1K tokens instead of letting it run on.
|
|
96
99
|
|
|
97
100
|
The backend turns away some of what a request may carry, so the plugin
|
|
98
101
|
leaves these out:
|
package/index.mjs
CHANGED
|
@@ -19,6 +19,7 @@ const BASE = "https://cli-chat-proxy.grok.com/v1"
|
|
|
19
19
|
const CLIENT_VERSION = "1.0.41"
|
|
20
20
|
const CPA_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828"
|
|
21
21
|
const CPA_SCOPE = `https://auth.x.ai::${CPA_CLIENT_ID}`
|
|
22
|
+
const LOOP_CHECKS = [["x-grok-doom-loop-check", "1024"], ["x-grok-exact-repetition-check", "64"]]
|
|
22
23
|
const REFRESH_MARGIN = 5 * 60 * 1000 // a token this close to its end is renewed before a request
|
|
23
24
|
const LEAD_MS = REFRESH_MARGIN // and this close, magpie renews it ahead of time (auth.refresh)
|
|
24
25
|
const LINK_WAIT = 30 * 1000
|
|
@@ -987,6 +988,15 @@ export const GrokAuthPlugin = async ({ client, magpie }) => {
|
|
|
987
988
|
}
|
|
988
989
|
if (asked.window) headers.set("x-grok-context-window", String(asked.window))
|
|
989
990
|
if (typeof parsed.prompt_cache_key === "string" && parsed.prompt_cache_key) headers.set("x-grok-conv-id", parsed.prompt_cache_key)
|
|
991
|
+
// Grok Build asks the proxy to watch every Responses stream for a
|
|
992
|
+
// model stuck repeating itself: without these the proxy cuts a
|
|
993
|
+
// loop only after ~4K tokens, and a looser one (a fence or a line
|
|
994
|
+
// over and over) runs to max_output_tokens (yetone/magpie#3594).
|
|
995
|
+
// The values are Grok Build 1.0.67's (doom_loop_recovery's
|
|
996
|
+
// max_threshold is the 64).
|
|
997
|
+
if (new URL(req.url).pathname.endsWith("/responses")) {
|
|
998
|
+
for (const [k, v] of LOOP_CHECKS) if (!headers.has(k)) headers.set(k, v)
|
|
999
|
+
}
|
|
990
1000
|
headers.delete("content-length")
|
|
991
1001
|
const send = async (key) => {
|
|
992
1002
|
await sign(headers, key)
|
package/package.json
CHANGED