New package @magpie-community/opencode-copilot-auth 0.1.0 (provider id
github-copilot), from kurtleee. It adapts opencode-copilot-auth 0.0.12 (MIT):
GitHub.com and GHE.com device sign-in, Copilot token renewal, request
signing with initiator and vision headers. Client versions match magpie's
native Copilot (vscode/1.140.0, copilot-chat/0.68.0). Host headers are
read as a Headers object, which is how magpie's host.js passes them. When the
sign-in isn't OAuth, the request goes on to plain fetch.
It adds magpie's auth.usage hook. The hook reads GET
api.<host>/copilot_internal/user with the GitHub OAuth token
(redirect: "error", 15s timeout) and turns the reply into windows the way
magpie's built-in Copilot reader does. It reads only the chat, completions
and premium_interactions snapshots. Credits are fractional, and string
counters are accepted. An exhausted unlimited pool counts as 100% used.
Managed seats block when spent, and personal seats with overage are aside.
credits_used is never divided by the entitlement. An unlimited pool's
credits_used goes in the display, aside and with no limit. Data that can't
be read is unknown, and only HTTP 401 expires the sign-in.
Run at head c7fb3abd, merged onto main 6a2ade35 (Bun 1.4.2, sandbox HOME
and TMPDIR, HTTP(S)_PROXY pointed at a closed port):
- packages/copilot bun test: 40 pass, 0 fail. Full repo bun test: 2838
pass, 3 skip, 0 fail. bun scripts/check.mjs: all ok.
- A probe sent fetch to a local Bun server, using magpie's real Copilot
quota bytes (internal/provider/copilot_usage_test.go). Max token billing:
"0.1 / 20,000 credits used". Enterprise pool spent: 100%, blocking. Pro in
overage: 300/300, aside. 401: signIn expired. A GHE sign-in reads
api.<host>. The loader with a host-style Headers object renewed through
v2/token with Bearer <oauth>. The chat request went out with content-type,
accept and the extra header kept. Incoming authorization and x-api-key
were replaced. Vision and X-Initiator were set, and the renewed token was
saved under github-copilot.
- PR CI (approved at c7fb3abd): test and on-npm pass.
Not tried: a real GitHub or Enterprise account. Not changed: the device
flow treats slow_down as a failure. This comes from upstream.
17 lines
596 B
JSON
17 lines
596 B
JSON
{
|
|
"name": "@magpie-community/opencode-copilot-auth",
|
|
"version": "0.1.0",
|
|
"description": "GitHub Copilot on GitHub.com and GitHub Enterprise, with account quota and credit balances for magpie",
|
|
"type": "module",
|
|
"main": "./index.mjs",
|
|
"files": ["index.mjs", "endpoints.mjs", "usage.mjs", "README.md", "LICENSE"],
|
|
"keywords": ["opencode", "opencode-plugin", "github", "copilot", "magpie"],
|
|
"license": "MIT",
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "https://github.com/magpie-community/plugins",
|
|
"directory": "packages/copilot"
|
|
},
|
|
"scripts": { "test": "bun test" }
|
|
}
|