Files
plugins/packages/mclaw/nonet.mjs
T
Joey Shao 367e879cab mclaw 0.5.2: China Mobile Cloud's MClaw agent (ai.yun.139.com), with a browser sign-in (#746)
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.
2026-11-06 10:35:49 +08:00

11 lines
680 B
JavaScript

// 每个测试文件最先 import 它:测试跑不到真网络。fetch 只放行本机(127.0.0.1/
// localhost/[::1]),其余一律抛错——哪个测试忘了装 fake,请求就发不出去,
// 凭证(Basic 票、llm key、vip Cookie)不可能漏到 yun.139.com / mcloud.139.com。
const local = (u) => /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\])(:\d+)?(\/|$|\?)/.test(u)
const realFetch = globalThis.fetch
globalThis.fetch = async (input, init) => {
const u = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url
if (!local(u)) throw new Error('a test asked ' + u + ' with no fake in place')
return realFetch(input, init)
}