@magpie-community/opencode-grok-auth 0.1.16 → 0.1.18
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 +2 -0
- package/index.mjs +24 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,6 +87,8 @@ leaves these out:
|
|
|
87
87
|
- tools of types it doesn't take (a freeform `apply_patch`, namespaces)
|
|
88
88
|
- `external_web_access` on web search
|
|
89
89
|
- a `tool_choice` naming a dropped type
|
|
90
|
+
- a `tool_choice` with no tools beside it (magpie sends `"none"` so when a
|
|
91
|
+
client turned tools off)
|
|
90
92
|
- a reasoning item's `"content": null`
|
|
91
93
|
|
|
92
94
|
Plain Codex collaboration items (`agent_message`) reach Grok as user
|
package/index.mjs
CHANGED
|
@@ -314,14 +314,17 @@ const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v)
|
|
|
314
314
|
|
|
315
315
|
// rewrite leaves out what Grok's backend doesn't take: tools of other
|
|
316
316
|
// types (a freeform apply_patch, a namespace of sub-agent tools), a web
|
|
317
|
-
// search's external_web_access, a tool_choice naming a dropped type
|
|
317
|
+
// search's external_web_access, a tool_choice naming a dropped type or
|
|
318
|
+
// with no tools beside it (magpie sends "none" so when a client turned
|
|
319
|
+
// tools off, yetone/magpie#3110; Grok refuses it: "A tool_choice was set on
|
|
320
|
+
// the request but no tools were specified"), and a
|
|
318
321
|
// reasoning item's "content": null, beside which it can't read the
|
|
319
322
|
// encrypted reasoning. A function's parameters with a union at the root
|
|
320
323
|
// (Codex desktop's codex_app automation_update) are folded to an object,
|
|
321
324
|
// which Grok turns away otherwise: "tool parameter root must be an object
|
|
322
325
|
// type" (magpie#1271).
|
|
323
326
|
function rewrite(body) {
|
|
324
|
-
if (typeof body !== "string" || (!body.includes('"tools"') && !body.includes('"reasoning"') && !body.includes('"agent_message"'))) return body
|
|
327
|
+
if (typeof body !== "string" || (!body.includes('"tools"') && !body.includes('"tool_choice"') && !body.includes('"reasoning"') && !body.includes('"agent_message"'))) return body
|
|
325
328
|
let m
|
|
326
329
|
try {
|
|
327
330
|
m = JSON.parse(body)
|
|
@@ -356,6 +359,10 @@ function rewrite(body) {
|
|
|
356
359
|
dirty = true
|
|
357
360
|
}
|
|
358
361
|
}
|
|
362
|
+
if (Object.hasOwn(m, "tool_choice") && !(Array.isArray(m.tools) && m.tools.length)) {
|
|
363
|
+
delete m.tool_choice
|
|
364
|
+
dirty = true
|
|
365
|
+
}
|
|
359
366
|
if (Array.isArray(m.input)) {
|
|
360
367
|
m.input = m.input.map((it) => {
|
|
361
368
|
if (!isObj(it) || it.type !== "agent_message" || Object.hasOwn(it, "encrypted_content") ||
|
|
@@ -462,12 +469,24 @@ function modelOf(id) {
|
|
|
462
469
|
|
|
463
470
|
// ---- sign-in ------------------------------------------------------------------
|
|
464
471
|
|
|
472
|
+
// opensPage is whether `grok login --device-auth` opens its page in the
|
|
473
|
+
// browser itself, which it does wherever it can: on macOS (NSWorkspace) and
|
|
474
|
+
// Windows (ShellExecute) always, with nothing to turn it off; on Linux and
|
|
475
|
+
// the BSDs through $BROWSER, else xdg-open where a display is. There it is
|
|
476
|
+
// given a $BROWSER that opens nothing, and the one who asked (magpie, which
|
|
477
|
+
// knows where the user's browser is) opens it; here the sign-in says the
|
|
478
|
+
// page is open already, so it isn't opened a second time (andyfmyth on X:
|
|
479
|
+
// "每次都会弹两次验证").
|
|
480
|
+
const opensPage = () => process.platform === "darwin" || process.platform === "win32"
|
|
481
|
+
|
|
465
482
|
// login runs `grok login --device-auth` in home and hands on the first link
|
|
466
483
|
// it prints; done is settled when the command is.
|
|
467
484
|
function login(exe, home) {
|
|
485
|
+
const env = envFor(home)
|
|
486
|
+
if (!opensPage()) env.BROWSER = "true"
|
|
468
487
|
const child = spawn(exe, ["login", "--device-auth"], {
|
|
469
488
|
cwd: homedir(),
|
|
470
|
-
env
|
|
489
|
+
env,
|
|
471
490
|
stdio: ["ignore", "pipe", "pipe"],
|
|
472
491
|
})
|
|
473
492
|
const tail = []
|
|
@@ -533,6 +552,8 @@ async function signIn() {
|
|
|
533
552
|
}
|
|
534
553
|
return {
|
|
535
554
|
url,
|
|
555
|
+
// not OpenCode's: the page is open already, by Grok Build itself
|
|
556
|
+
opened: opensPage(),
|
|
536
557
|
instructions: "Approve the sign-in on the page; Grok Build finishes it.",
|
|
537
558
|
method: "auto",
|
|
538
559
|
callback: async () => {
|
package/package.json
CHANGED