@magpie-community/opencode-grok-auth 0.1.17 → 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.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/index.mjs +9 -2
  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, and a
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") ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-grok-auth",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "OpenCode provider plugin: Grok (SuperGrok / X Premium+) through the Grok Build CLI's sign-in",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",