@magpie-community/opencode-qoder-auth 0.2.77 → 0.2.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/opencode2.mjs +16 -2
  2. package/package.json +1 -1
package/opencode2.mjs CHANGED
@@ -507,6 +507,14 @@ async function setupPlugin(ctx, fn, live) {
507
507
  // the account the list was last read for: a credential.updated that
508
508
  // leaves it as it was reads nothing again
509
509
  let readFor = null
510
+ // the last list each account's own read gave, by the account it was read
511
+ // for: a read that fails (a workspace config answering 503) keeps the
512
+ // list that same account last read rather than the bundled one, which
513
+ // brought back models its workspace hides (plugins#1642). Another
514
+ // account's list is never used, a read that gave an empty list is kept
515
+ // as empty, and the bundled list stands in only for an account whose
516
+ // list was never read.
517
+ const lists = new Map()
510
518
  const stateOf = async () => {
511
519
  const c = await ctx.integration.connection.active(authID).catch(() => undefined)
512
520
  const a = c ? await getAuth(authID) : undefined
@@ -523,7 +531,8 @@ async function setupPlugin(ctx, fn, live) {
523
531
  const s = source.get(authID)
524
532
  const connection = await ctx.integration.connection.active(authID).catch(() => undefined)
525
533
  const a = connection ? await getAuth(authID) : undefined
526
- readFor = connKey(connection) + "\0" + (a ? fingerprint(a) : "")
534
+ const readingFor = connKey(connection) + "\0" + (a ? fingerprint(a) : "")
535
+ readFor = readingFor
527
536
  if (!a || listID !== authID || typeof hooks.provider?.models !== "function") {
528
537
  if (s.connection || s.models) {
529
538
  s.connection = undefined
@@ -544,7 +553,12 @@ async function setupPlugin(ctx, fn, live) {
544
553
  return
545
554
  }
546
555
  s.connection = connection
547
- s.models = got && typeof got === "object" ? Object.entries(got).map(([k, m]) => modelOf(authID, s.prov, k, record(m))) : null
556
+ if (got && typeof got === "object") {
557
+ s.models = Object.entries(got).map(([k, m]) => modelOf(authID, s.prov, k, record(m)))
558
+ lists.delete(readingFor)
559
+ lists.set(readingFor, s.models)
560
+ if (lists.size > 32) lists.delete(lists.keys().next().value)
561
+ } else s.models = lists.get(readingFor) ?? null
548
562
  await ctx.provider.reload()
549
563
  await ctx.model?.reload?.()
550
564
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.77",
3
+ "version": "0.2.78",
4
4
  "description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship, VPC and dedicated domains",
5
5
  "type": "module",
6
6
  "main": "./opencode.mjs",