The Grok plugin's sign-in said only "grok login gave no link to open". The plugin host has magpie's proxy only as MAGPIE_*_PROXY, so the `grok login` the plugin runs went out with none, where the built-in's had it (netproxy.Env); where x.ai is reached only through a proxy, it failed. host.js's spawn wrapper now gives a started program HTTPS_PROXY and HTTP_PROXY (the account's own proxy, none for direct, else magpie's) when the plugin set none. grok 1.0.46, unable to reach x.ai, prints "Error: error sending request for url (https://auth.x.ai/oauth2/device/code): …", whose URL the built-in's runCLISignIn took for the page to open; a line saying error gives no link, and a login with none ends with the CLI's last line. The plugin does the same from 0.1.8, which the grok mover now asks for. plugin_cliproxy_test.go and TestCLISignInSaysWhyNoLink fail before this. Checked with grok 1.0.46 itself through the plugin host and the published plugin's code, given a proxy that refuses: the CLI goes through it and the error names what it said.
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
// A plugin that signs in with a CLI of the vendor's, as the Grok plugin
|
|
// runs `grok login`: the link it hands on says the proxy the CLI was
|
|
// given, started with the host's environment and with a copy of it.
|
|
import { spawn } from "node:child_process"
|
|
|
|
function proxyOf(env) {
|
|
return new Promise((resolve) => {
|
|
const child = spawn(process.execPath, ["-e", "process.stdout.write(process.env.HTTPS_PROXY || 'none')"], {
|
|
env,
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
})
|
|
let out = ""
|
|
child.stdout.on("data", (b) => (out += b))
|
|
child.on("close", () => resolve(out))
|
|
})
|
|
}
|
|
|
|
export const CLIProxyPlugin = async () => ({
|
|
auth: {
|
|
provider: "cliproxy",
|
|
methods: [
|
|
{
|
|
type: "oauth",
|
|
label: "CLI",
|
|
authorize: async () => {
|
|
const inherited = await proxyOf(undefined)
|
|
const copied = await proxyOf({ ...process.env })
|
|
return {
|
|
url: `https://cliproxy.invalid/?inherited=${encodeURIComponent(inherited)}&copied=${encodeURIComponent(copied)}`,
|
|
instructions: "",
|
|
method: "code",
|
|
callback: async () => ({ type: "failed" }),
|
|
}
|
|
},
|
|
},
|
|
],
|
|
},
|
|
})
|