zcode 0.1.40: two accounts take requests at once, the others in reserve
01huadalang on Discord (#feedback): three ZCode accounts used at once from one address got the address refused with a 405; two were served. They asked for the first account to be used until it runs out, then the next. The plugin now declares maxAccounts 2, on the auth hook and as magpie.maxAccounts in package.json, beside maxConcurrency. magpie (the release after this, its provider setting Accounts at once) sends requests to the first two accounts of the user's list only and holds the others in reserve; one that runs out or fails rests and the first in reserve takes its place. The user's own value on the provider wins, 0 for every account. A magpie that doesn't read the field uses every account, as before. README: "Two accounts at once". Run on mote: HOME=$(mktemp -d) bun test in packages/zcode (183 pass, 0 fail) and bun scripts/check.mjs (exit 0). Broken by hand: package.json's maxAccounts set to 3 turns "two accounts at once are declared, the same number twice" red. Not tried: real ZCode accounts (none used, per the task), and whether two at once is always under ZCode's limit; that is the reporter's finding, and the user can lower it to 1.
This commit is contained in:
@@ -196,6 +196,19 @@ number written into the plugin would hold a Max account to a Lite one's
|
||||
with no way to raise it. A user who knows their plan's cap sets it on the
|
||||
account or the provider in magpie, and magpie's queue follows that.
|
||||
|
||||
## Two accounts at once
|
||||
|
||||
Three ZCode accounts used at once from one address can get the address
|
||||
refused with a 405, where two are served (01huadalang on Discord). So the
|
||||
plugin declares `maxAccounts` two, on the auth hook and as
|
||||
`magpie.maxAccounts` in its `package.json`: magpie sends requests to the
|
||||
first two accounts of the user's list only, and holds the others in
|
||||
reserve. One that runs out or fails rests, and the first in reserve takes
|
||||
its place until it is back. A user changes the number on the provider in
|
||||
magpie (Advanced → Accounts at once, or `magpie provider at-once zcode
|
||||
<n>`), 0 for every account at once. A magpie older than the one that
|
||||
reads it uses every account, as before.
|
||||
|
||||
## The usage card
|
||||
|
||||
An account with both plans shows both allowances: the coding plan's
|
||||
|
||||
@@ -10,7 +10,7 @@ import { homedir, tmpdir } from "node:os"
|
||||
import { readFileSync, realpathSync } from "node:fs"
|
||||
import { ZCodeAuthPlugin, _internal } from "./index.mjs"
|
||||
|
||||
const { busy, spentUp, BUSY_WAITS, DEFAULT_CONCURRENCY } = _internal
|
||||
const { busy, spentUp, BUSY_WAITS, DEFAULT_CONCURRENCY, DEFAULT_ACCOUNTS } = _internal
|
||||
const WAITS = [...BUSY_WAITS]
|
||||
|
||||
let server
|
||||
@@ -181,3 +181,14 @@ test("the account's cap is declared, and declared as the same number twice", asy
|
||||
expect(hooks.auth.maxConcurrency).toBe(DEFAULT_CONCURRENCY)
|
||||
expect(pkg.magpie.maxConcurrency).toBe(DEFAULT_CONCURRENCY)
|
||||
})
|
||||
|
||||
test("two accounts at once are declared, the same number twice", async () => {
|
||||
// 01huadalang on Discord: three ZCode accounts used at once from one
|
||||
// address got it refused with a 405, two didn't. magpie keeps the first
|
||||
// two of the user's list taking requests and the others in reserve
|
||||
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"))
|
||||
const hooks = await ZCodeAuthPlugin({ client: { auth: { set: async () => {} } } })
|
||||
expect(DEFAULT_ACCOUNTS).toBe(2)
|
||||
expect(hooks.auth.maxAccounts).toBe(DEFAULT_ACCOUNTS)
|
||||
expect(pkg.magpie.maxAccounts).toBe(DEFAULT_ACCOUNTS)
|
||||
})
|
||||
|
||||
@@ -1746,6 +1746,13 @@ function kept(res, text) {
|
||||
// (https://docs.z.ai/devpack/usage-policy), so a number written here would
|
||||
// hold a Max account to a Lite one's, with no way for the user to raise it.
|
||||
const DEFAULT_CONCURRENCY = 3
|
||||
// DEFAULT_ACCOUNTS is how many of a user's ZCode accounts magpie sends
|
||||
// requests to at the same time (maxAccounts, on the auth hook and in
|
||||
// package.json): the first in the user's list, the next taking over once
|
||||
// one runs out or fails. 01huadalang on Discord: three accounts used at
|
||||
// once from one address got the address refused with a 405, two didn't. A
|
||||
// user sets their own on the provider (Accounts at once), 0 for no limit.
|
||||
const DEFAULT_ACCOUNTS = 2
|
||||
const BUSY_CODES = new Set(["3008", "3009"])
|
||||
// BUSY_WAITS are the waits between asks, longest last: about ten seconds of
|
||||
// them. Past that the account is saturated rather than busy, and magpie's
|
||||
@@ -2294,6 +2301,9 @@ export async function ZCodeAuthPlugin({ client }, options = {}) {
|
||||
// own cap follows its tier (Max > Pro > Lite) and the time of day, and
|
||||
// a user who knows theirs can raise this on the account
|
||||
maxConcurrency: DEFAULT_CONCURRENCY,
|
||||
// how many accounts take requests at once, the others in reserve
|
||||
// (DEFAULT_ACCOUNTS); a magpie that doesn't read it uses them all
|
||||
maxAccounts: DEFAULT_ACCOUNTS,
|
||||
async loader(getAuth, provider) {
|
||||
const s0 = stateOf(await getAuth())
|
||||
if (!s0) return {}
|
||||
@@ -2650,4 +2660,4 @@ export async function ZCodeAuthPlugin({ client }, options = {}) {
|
||||
// config sets what zcodeConfig has read, for tests: null is ZCode's config
|
||||
// out of reach, undefined forgets it
|
||||
const config = (cfg) => (cfgCache = cfg === undefined ? null : { cfg, at: Date.now() })
|
||||
export const _internal = { config, entry, limitWindows, termOf, startUsage, routes, blocked, plansOf, giftOf, dualUsage, claimHint, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY }
|
||||
export const _internal = { config, entry, limitWindows, termOf, startUsage, routes, blocked, plansOf, giftOf, dualUsage, claimHint, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY, DEFAULT_ACCOUNTS }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-zcode-auth",
|
||||
"version": "0.1.39",
|
||||
"version": "0.1.40",
|
||||
"description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan, and claims its gift plans daily",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
@@ -14,6 +14,7 @@
|
||||
"directory": "packages/zcode"
|
||||
},
|
||||
"magpie": {
|
||||
"maxConcurrency": 3
|
||||
"maxConcurrency": 3,
|
||||
"maxAccounts": 2
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user