New package @magpie-community/opencode-mclaw-auth 0.5.2 (joey-41): China
Mobile Cloud's MClaw agent (ai.yun.139.com) as a provider. A browser
sign-in in a dedicated Chrome profile per sign-in harvests the yun.139.com
ticket and fetches the llm key and the model multipliers by itself; the
models come from the account's own lists; the usage card reads the
aitokens pool and, through the vip SSO chain (toSourceId 001005), the
records' own endTime as the reset; the ticket is renewed headless from the
account's own profile, and a ticket for another phone number is refused.
Every host is China Mobile's own. registry.json and the README table list
it.
Reviewed at 905e2a6b, 7ed7d0aa and 7304ac15 (0.5.2, edcd9549 plus a
merge of main). The last review's two must-fixes are in the code:
magpie's cancel (callback(undefined, { signal }) and authorize's signal
both call harvesting.abort(); startBrowserHarvest records an abort while
Chrome is still starting and closes it once open), and a failed,
cancelled or timed-out sign-in deletes its signin-* profile dir after
releasing the lock. Re-signing an account leaving its old dir behind is
in the package README as a known limit.
Run at 7304ac15 (origin/main 10a61c2e already in it), sandbox HOME:
- mote, Bun 1.4.2: bun test in packages/mclaw 30 pass, 0 fail;
bun scripts/check.mjs mclaw and bun scripts/check.mjs (all) ok.
- WSL Ubuntu 24.04, Bun 1.4.2: whole-repo bun test (see the PR).
- The real startBrowserHarvest with Chrome for Testing on mote, aborted
before Chrome was up and 4s after: both reject "登录已取消", no Chrome
left on the profile, no signin-* dir left.
- Review test: authorize and callback given separate signals, as
magpie's host does, only the callback's aborted: closed and released.
With callback's listener taken out it goes red (5s timeout).
Not tried: a real MClaw sign-in (no account here). The package's own
magpie-style test hands both calls one signal, so it stays green
without callback's listener; that is the only gap seen.
npm: the name is new, so trusted publishing can't create it; magpie
serves it from the dist branch until an owner publishes its first
version.
68 lines
2.4 KiB
JavaScript
68 lines
2.4 KiB
JavaScript
// 浏览器替身:startBrowserHarvest / browserRefreshHarvest 的可控 fake。
|
|
// ticket 就是 fake 收割出的 authorization Cookie 值(与真实流程一致:整段
|
|
// "Basic <base64>" 票,fake.mjs 的 TICKET_A/TICKET_B)。closed/released 记录
|
|
// 收尾是否发生(取消收尾的断言用)。
|
|
export function fakeBrowserModule({ ticket } = {}) {
|
|
const state = {
|
|
harvests: 0,
|
|
refreshes: 0,
|
|
openedProfiles: [],
|
|
refreshProfiles: [],
|
|
closed: 0,
|
|
released: 0,
|
|
aborted: false,
|
|
// 测试用例按需覆盖:harvestError 让收割失败;holdHarvest 让 promise 挂起,
|
|
// 再用 deliverHarvest() 放行(取消收尾的时序测试用)。
|
|
harvestError: undefined,
|
|
refreshCookie: ticket,
|
|
}
|
|
let deliverHarvestNow = undefined
|
|
const module = {
|
|
startBrowserHarvest({ profilePath } = {}) {
|
|
const session = { promise: undefined, abort: async () => {} }
|
|
state.harvests++
|
|
const profile = profilePath ?? 'fake-profile-signin'
|
|
state.openedProfiles.push(profile)
|
|
session.promise = new Promise((resolve, reject) => {
|
|
session.abort = async () => {
|
|
if (state.aborted) return
|
|
state.aborted = true
|
|
state.closed++
|
|
state.released++
|
|
reject(new Error('登录已取消'))
|
|
}
|
|
const deliver = () => {
|
|
if (state.harvestError) {
|
|
state.closed++
|
|
state.released++
|
|
reject(state.harvestError)
|
|
return
|
|
}
|
|
resolve({
|
|
cookie: { value: ticket, expiresMs: 0 },
|
|
profilePath: profile,
|
|
release: async () => { state.released++ },
|
|
close: async () => { state.closed++ },
|
|
})
|
|
}
|
|
if (state.harvestError) queueMicrotask(deliver)
|
|
else deliverHarvestNow = deliver
|
|
})
|
|
session.promise.catch(() => {})
|
|
return session
|
|
},
|
|
deliverHarvest() {
|
|
deliverHarvestNow?.()
|
|
deliverHarvestNow = undefined
|
|
},
|
|
async browserRefreshHarvest({ profilePath } = {}) {
|
|
state.refreshes++
|
|
state.refreshProfiles.push(profilePath)
|
|
if (state.harvestError) throw state.harvestError
|
|
if (!state.refreshCookie) throw new Error('profile 里没有移动云登录态(请先完成浏览器登录)')
|
|
return { cookie: { value: state.refreshCookie, expiresMs: 0 }, profilePath: profilePath ?? 'fake-profile-legacy' }
|
|
},
|
|
}
|
|
return { module, state }
|
|
}
|