agy-cli 0.1.32: the first model list after warming has agy's Claude and GPT models (#1064)
On a signed-in agy, `agy models` takes about 4.4s and `agy acp`'s
session/new about 3s. provider.models() needed three calls before
claude-opus-5-5, claude-sonnet-5-5 and gpt-oss-120b showed up, and
OpenCode 2.x calls it once.
What changed:
- packages/agy-cli/index.mjs:
- The offered-model probe now starts in listAgyModels' .then, as soon as
a non-empty list arrives and a caller asked for probeOffered. It no
longer waits for the next models() call. A hung or failed `agy models`
still never spawns the probe.
- probeSignedIn reuses the `agy models` stdout it already has. The same
parser (parseAgyModels, split out of listAgyModels) fills
cachedModelCatalog, and the probe starts. Sign-in waits for the probe
for at most 3s.
- The offer (acpOfferedModels, acpOfferedKey, offeredProbeAt and any
in-flight probe) is forgotten when agyPath changes and after a new
sign-in finishes. A generation counter drops the answer of a probe
that started before the reset.
- provider.warming() returns a promise while a list or probe is still
running, and null when nothing is.
- scripts/opencode2.mjs, copied byte for byte to every
packages/*/opencode2.mjs: after the first background refresh, the
adapter awaits hooks.provider.warming() once, for at most 60s, and then
refreshes once more. It does not loop. Plugins without warming() behave
as before.
- Not done: the issue's on-disk catalog cache (point 3), skipped as asked.
Known gap: agy-cli has no `config` hook, so under OpenCode 2.x the adapter
lists no provider for it. refresh() returns before it calls
provider.models(), so the follow-up refresh can't add agy's models on 2.x
until agy-cli gets a config hook.
Tests: test/testkit.mjs's fake agy takes a sessionNewDelayMs. The new
tests in test/catalog.mjs set 1.5s on both `agy models` and session/new
and wait for state through warming(), with no fixed sleeps:
- On a slow cold start, the first models() after warming lists Claude and
GPT, from one probe spawn.
- authorize() on a signed-in agy fills the catalog, and the next models()
runs no second `agy models`.
- The sign-in wait is bounded: with a 6s session/new, sign-in returns in
about 4.5s.
- Changing agyPath probes again.
The hang test now awaits warming() before it counts acp spawns.
scripts/opencode2.test.mjs: the warming list is read a second time when
warming ends, and only once when nothing is warming.
Run on Linux (a separate test Mac was over its load limit):
- packages/agy-cli bun test: 17 pass, 0 fail.
- bun scripts/check.mjs agy-cli: ok.
- bun scripts/check.mjs (all packages): ok.
- Root bun test in a temp HOME: 8530 pass, 19 skip, 0 fail.
Broken by hand on Linux, each red, then restored green:
- No probe in the .then: the slow cold-start test.
- probeSignedIn drops the list: the authorize and bounded-wait tests.
- agyPath change keeps the old offer: the agyPath test.
- Unbounded sign-in wait: the bounded-wait test (7514ms).
- Probe also on a failed listing: the hang test.
- origin/main's index.mjs with the new tests: all four #1064 tests.
- Adapter reads the list once: the warming adapter test, and the
copy-identity check.
Not tried: a real agy (no Google sign-in, no network). The reset after
login.finish has no unit test of its own.
Reported-by: hiee3
This commit is contained in:
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
+102
-28
@@ -222,8 +222,13 @@ async function listAgyModels(agyPath) {
|
||||
const { err, stdout, code, timedOut } = await execOnce(agyPath, ["models"], { timeoutMs: 15_000, unrefTimer: true })
|
||||
// null, not FALLBACK_MODELS: a failed listing must not overwrite a dynamic catalog.
|
||||
if (err || timedOut || code !== 0) return null
|
||||
return parseAgyModels(stdout)
|
||||
}
|
||||
|
||||
// parseAgyModels reads `agy models` output: one "<id> <name>" per line.
|
||||
function parseAgyModels(stdout) {
|
||||
const out = []
|
||||
for (const raw of stdout.split("\n")) {
|
||||
for (const raw of String(stdout ?? "").split("\n")) {
|
||||
const line = raw.trim()
|
||||
if (!line) continue
|
||||
const match = /^(\S+)\s+(.+)$/.exec(line)
|
||||
@@ -238,12 +243,25 @@ async function listAgyModels(agyPath) {
|
||||
|
||||
// probeSignedIn is whether agy lists the signed-in account's models: an
|
||||
// exit code alone can't say so, so a listing without one model in it is
|
||||
// not signed in either.
|
||||
// not signed in either. The listing it read is the catalog's, and what agy
|
||||
// acp offers is asked at once (#1064): `agy models` and the session each
|
||||
// take seconds on a real agy, and the host lists models right after.
|
||||
const OFFERED_SIGNIN_WAIT_MS = 3_000
|
||||
|
||||
async function probeSignedIn(agy) {
|
||||
const probe = await execOnce(agy, ["models"], { timeoutMs: 15_000 })
|
||||
const listed = !probe.err && !probe.timedOut && probe.code === 0 &&
|
||||
probe.stdout.split("\n").some(line => /^\S+\s+\S/.test(line.trim()))
|
||||
if (listed) return { ok: true }
|
||||
if (listed) {
|
||||
const list = parseAgyModels(probe.stdout)
|
||||
if (list) {
|
||||
useAgyPath(agy)
|
||||
storeListedCatalog(agy, list, Date.now())
|
||||
wantOfferedProbe = true
|
||||
await briefly(probeOfferedOnce(agy), OFFERED_SIGNIN_WAIT_MS)
|
||||
}
|
||||
return { ok: true }
|
||||
}
|
||||
const why = probe.timedOut
|
||||
? "`agy models` timed out after 15s"
|
||||
: `\`agy models\` says: ${(probe.stderr || probe.stdout || "").trim().split(/\r?\n/).filter(Boolean).at(-1) || probe.err?.message || `exit ${probe.code}`}`
|
||||
@@ -256,6 +274,9 @@ const MODEL_CATALOG_FAST_WAIT_MS = 500
|
||||
const MODEL_CATALOG_RETRY_MS = 5_000
|
||||
let modelCatalogRefreshPromise = null
|
||||
let cachedModelCatalog = fallbackModelCatalog()
|
||||
// A caller lists models (provider.models), so a listing that lands asks agy
|
||||
// acp what it offers right away, not on the next models() call (#1064).
|
||||
let wantOfferedProbe = false
|
||||
|
||||
// `agy models` lists every model of the account, while agy's ACP server offers
|
||||
// a client only some of them. A session's model option (and its
|
||||
@@ -306,6 +327,29 @@ const OFFERED_PROBE_TIMEOUT_MS = 30_000
|
||||
const OFFERED_PROBE_RETRY_MS = 60_000
|
||||
let offeredProbePromise = null
|
||||
let offeredProbeAt = null
|
||||
// Bumped when what was learnt about an agy no longer holds (another
|
||||
// executable, a new sign-in): a probe still running for the old one is
|
||||
// not believed.
|
||||
let offeredGen = 0
|
||||
|
||||
function forgetOffered() {
|
||||
acpOfferedModels = null
|
||||
acpOfferedKey = ""
|
||||
offeredProbePromise = null
|
||||
offeredProbeAt = null
|
||||
offeredGen++
|
||||
}
|
||||
|
||||
// briefly waits for a promise at most ms, and never throws.
|
||||
async function briefly(promise, ms) {
|
||||
if (!promise) return
|
||||
let timer
|
||||
try {
|
||||
await Promise.race([promise.catch(() => {}), new Promise((resolve) => { timer = setTimeout(resolve, ms) })])
|
||||
} finally {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}
|
||||
|
||||
function killQuietly(child) {
|
||||
try { child.stdin?.end() } catch {}
|
||||
@@ -318,6 +362,7 @@ function killQuietly(child) {
|
||||
}
|
||||
|
||||
async function probeOfferedModels(agyPath) {
|
||||
const gen = offeredGen
|
||||
let workspace = null
|
||||
let child = null
|
||||
let conn = null
|
||||
@@ -346,7 +391,7 @@ async function probeOfferedModels(agyPath) {
|
||||
})
|
||||
if (agyTooOld(init?.agentInfo?.version ?? null)) return
|
||||
const session = await conn.request("session/new", { cwd: workspace, mcpServers: [] })
|
||||
noteOfferedModels(session?.configOptions, session?.models)
|
||||
if (gen === offeredGen) noteOfferedModels(session?.configOptions, session?.models)
|
||||
const caps = init?.agentCapabilities ?? {}
|
||||
if (session?.sessionId && (caps.sessionCapabilities?.close ?? caps.session_capabilities?.close)) {
|
||||
await conn.request("session/close", { sessionId: session.sessionId }).catch(() => {})
|
||||
@@ -367,8 +412,11 @@ function probeOfferedOnce(agyPath) {
|
||||
const now = Date.now()
|
||||
if (offeredProbeAt !== null && now - offeredProbeAt < OFFERED_PROBE_RETRY_MS) return null
|
||||
offeredProbeAt = now
|
||||
offeredProbePromise = probeOfferedModels(agyPath).finally(() => { offeredProbePromise = null })
|
||||
return offeredProbePromise
|
||||
const probe = probeOfferedModels(agyPath).finally(() => {
|
||||
if (offeredProbePromise === probe) offeredProbePromise = null
|
||||
})
|
||||
offeredProbePromise = probe
|
||||
return probe
|
||||
}
|
||||
|
||||
function catalogOf(entry) {
|
||||
@@ -445,17 +493,49 @@ function fallbackModelCatalog(agyPath = null) {
|
||||
return { agyPath, list: FALLBACK_MODELS, catalog: null, offeredKey: null, isFallback: true, fetchedAt: 0, lastAttemptAt: null }
|
||||
}
|
||||
|
||||
// useAgyPath starts over when the executable changes: an old executable's
|
||||
// dynamic additions and offer must not route to, or list for, a new one.
|
||||
function useAgyPath(agyPath) {
|
||||
if (cachedModelCatalog.agyPath === agyPath) return
|
||||
// The first agy this process finds is not a change of one.
|
||||
if (cachedModelCatalog.agyPath !== null) forgetOffered()
|
||||
cachedModelCatalog = fallbackModelCatalog(agyPath)
|
||||
modelCatalogRefreshPromise = null
|
||||
}
|
||||
|
||||
function storeListedCatalog(agyPath, list, lastAttemptAt) {
|
||||
cachedModelCatalog = {
|
||||
agyPath,
|
||||
list,
|
||||
catalog: null,
|
||||
offeredKey: null,
|
||||
isFallback: false,
|
||||
fetchedAt: Date.now(),
|
||||
lastAttemptAt,
|
||||
}
|
||||
}
|
||||
|
||||
// catalogWarming is the background work that can still change what models()
|
||||
// lists (the listing, then the session probe it starts), or null when there
|
||||
// is none. Hosts that read the list once (OpenCode 2.x's adapter) read it
|
||||
// again when this ends.
|
||||
function catalogWarming() {
|
||||
if (!modelCatalogRefreshPromise && !offeredProbePromise) return null
|
||||
return (async () => {
|
||||
if (modelCatalogRefreshPromise) await modelCatalogRefreshPromise.catch(() => {})
|
||||
if (offeredProbePromise) await offeredProbePromise.catch(() => {})
|
||||
return true
|
||||
})()
|
||||
}
|
||||
|
||||
// Magpie gives models() about two seconds, while `agy models` can take longer.
|
||||
// Serve the last catalog (static until the first success), refresh it in the
|
||||
// background at most once at a time, and wait for that refresh only briefly.
|
||||
// probeOffered: the caller is listing models (provider.models), not routing a
|
||||
// request that is about to open a session of its own.
|
||||
async function loadModelCatalog(agyPath, { probeOffered = false } = {}) {
|
||||
if (cachedModelCatalog.agyPath !== agyPath) {
|
||||
// An old executable's dynamic additions must not route to a new one.
|
||||
cachedModelCatalog = fallbackModelCatalog(agyPath)
|
||||
modelCatalogRefreshPromise = null
|
||||
}
|
||||
useAgyPath(agyPath)
|
||||
if (probeOffered) wantOfferedProbe = true
|
||||
const current = cachedModelCatalog
|
||||
if (!agyPath) return catalogOf(current)
|
||||
const now = Date.now()
|
||||
@@ -469,15 +549,10 @@ async function loadModelCatalog(agyPath, { probeOffered = false } = {}) {
|
||||
current.lastAttemptAt = now
|
||||
const refresh = listAgyModels(agyPath).then((list) => {
|
||||
if (list?.length && cachedModelCatalog === current) {
|
||||
cachedModelCatalog = {
|
||||
agyPath,
|
||||
list,
|
||||
catalog: null,
|
||||
offeredKey: null,
|
||||
isFallback: false,
|
||||
fetchedAt: Date.now(),
|
||||
lastAttemptAt: current.lastAttemptAt,
|
||||
}
|
||||
storeListedCatalog(agyPath, list, current.lastAttemptAt)
|
||||
// `agy models` answered, so agy is signed in: ask what agy acp
|
||||
// offers now, while the host still waits for its first list.
|
||||
if (wantOfferedProbe) probeOfferedOnce(agyPath)
|
||||
}
|
||||
}).catch(() => {
|
||||
// Keep the last successful catalog, including dynamic-only models.
|
||||
@@ -500,14 +575,7 @@ async function loadModelCatalog(agyPath, { probeOffered = false } = {}) {
|
||||
// `agy models` answered, so agy is signed in: learn what its ACP server
|
||||
// offers this client, waiting for it as briefly as for the listing.
|
||||
const probe = probeOffered && !cachedModelCatalog.isFallback ? probeOfferedOnce(agyPath) : null
|
||||
if (probe) {
|
||||
let timer
|
||||
try {
|
||||
await Promise.race([probe, new Promise((resolve) => { timer = setTimeout(resolve, MODEL_CATALOG_FAST_WAIT_MS) })])
|
||||
} finally {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}
|
||||
if (probe) await briefly(probe, MODEL_CATALOG_FAST_WAIT_MS)
|
||||
return catalogOf(cachedModelCatalog)
|
||||
}
|
||||
|
||||
@@ -5257,6 +5325,9 @@ export const AntigravityBridgePlugin = async () => {
|
||||
callback: async (code, opts = {}) => {
|
||||
const done = await login.finish(code, { signal: opts.signal })
|
||||
if (done.error) return { type: "failed", error: done.error }
|
||||
// A new account: what agy offered the last one, or refused
|
||||
// before the sign-in, is asked again.
|
||||
forgetOffered()
|
||||
const probe = await probeSignedIn(agy)
|
||||
if (!probe.ok) return { type: "failed", error: `agy signed in, but ${probe.why}` }
|
||||
return { type: "success", key: "agy" }
|
||||
@@ -5480,6 +5551,9 @@ export const AntigravityBridgePlugin = async () => {
|
||||
provider: {
|
||||
id: PROVIDER_ID,
|
||||
npm: NPM_ANTHROPIC,
|
||||
// Not an OpenCode hook: the adapter in opencode2.mjs reads the list
|
||||
// once more when this background work ends.
|
||||
warming: () => catalogWarming(),
|
||||
models: async () => {
|
||||
const agy = findAgy()
|
||||
// Never force a refresh here: Magpie times models() out after about two seconds.
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-agy-cli-auth",
|
||||
"version": "0.1.31",
|
||||
"version": "0.1.32",
|
||||
"description": "Magpie/OpenCode model provider that connects your local agy CLI through the Agent Client Protocol (agy acp), so Antigravity subscription models run through the real CLI",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
@@ -72,6 +72,11 @@ test("首次 agy models 卡死时 750ms 内返回非空静态目录", async () =
|
||||
assert.equal(kit.timers.refed().length, 0, "agy models 卡死期间不应有挂住 Node 退出的模块定时器")
|
||||
await kit.finishChildren()
|
||||
assert.equal(kit.timers.refed().length, 0, "子进程结束后不应残留挂住退出的定时器")
|
||||
// 探测一起就在 warming() 里:等它跑完再数,不靠固定时长。
|
||||
const warming = kit.plugin.provider.warming?.()
|
||||
if (warming) await warming
|
||||
await settle(kit)
|
||||
assert.equal(kit.acpSpawns.length, 0, "agy models 没答出来时不应起探测会话")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -154,6 +159,90 @@ test("会话后来开放的型号变了,目录随之更新", async () => {
|
||||
})
|
||||
})
|
||||
|
||||
// #1064(hiee3):真实登录的 agy 上 `agy models` 约 4.4s、agy acp 开会话约 3s,都远过 500ms 的快速等待。
|
||||
// 这里各模拟 1.5s:第一次 models() 只能给静态目录,但列表一到就该起探测,
|
||||
// 后台跑完后的第一次 models() 就要有 Claude 和 GPT-OSS,不该要第三次。
|
||||
const SLOW_MS = 1_500
|
||||
const OFFERED_CLAUDE = [
|
||||
["gemini-4-argon-high", "Gemini 4 Argon (High)"], ["gemini-4-argon-low", "Gemini 4 Argon (Low)"],
|
||||
["claude-opus-5-5-high", "Claude Opus 5.5 (High)"], ["claude-opus-5-5-low", "Claude Opus 5.5 (Low)"],
|
||||
["claude-sonnet-5-5-high", "Claude Sonnet 5.5 (High)"], ["claude-sonnet-5-5-low", "Claude Sonnet 5.5 (Low)"],
|
||||
["gpt-oss-120b-medium", "GPT-OSS 120B (Medium)"],
|
||||
]
|
||||
const SLOW_AGY = { modelsBehavior: { stdout: modelsOutput(BASE_MODEL_ROWS), delayMs: SLOW_MS }, sessionNewDelayMs: SLOW_MS, offeredModels: OFFERED_CLAUDE }
|
||||
|
||||
// 等后台的列表与探测都结束:等状态(没有在跑的假子进程,且插件说没有在热身),不等固定时长。
|
||||
async function warmed(kit) {
|
||||
const warming = kit.plugin.provider.warming?.()
|
||||
if (warming) await warming
|
||||
for (let i = 0; i < 1000 && kit.children.size; i++) await sleep(10)
|
||||
await settle(kit)
|
||||
}
|
||||
|
||||
function assertClaudeListed(models, label) {
|
||||
for (const id of ["claude-opus-5-5", "claude-sonnet-5-5", "gpt-oss-120b"]) assert.ok(models[id], `${label}:没有 ${id},只有 ${ids(models).join(", ")}`)
|
||||
}
|
||||
|
||||
test("#1064 慢 agy:第一次 models() 给静态目录,后台热身后的第一次就列出 Claude 和 GPT-OSS", async () => {
|
||||
await withKit(SLOW_AGY, async (kit) => {
|
||||
const { value: first, ms } = await timed(() => kit.models())
|
||||
assert.ok(ms < FAST_BUDGET_MS, `首次目录耗时 ${Math.round(ms)}ms`)
|
||||
assertFallbackPresent(first)
|
||||
await warmed(kit)
|
||||
assert.equal(kit.acpSpawns.length, 1, "列表一到就该起一次探测会话")
|
||||
const { value: after, ms: warmMs } = await timed(() => kit.models())
|
||||
assert.ok(warmMs < 100, `热身后的目录耗时 ${Math.round(warmMs)}ms`)
|
||||
assertClaudeListed(after, "热身后的第一次 models()")
|
||||
assert.equal(kit.modelsSpawns.length, 1)
|
||||
assert.equal(kit.acpSpawns.length, 1)
|
||||
assert.equal(kit.plugin.provider.warming(), null, "热身完了不该还说在热身")
|
||||
})
|
||||
})
|
||||
|
||||
test("#1064 慢 agy:已登录时 authorize 读到的列表和探测就是目录,紧接着的 models() 不再是静态目录", async () => {
|
||||
await withKit(SLOW_AGY, async (kit) => {
|
||||
const { value: started, ms } = await timed(() => kit.plugin.auth.methods[0].authorize())
|
||||
assert.equal(started.method, "auto")
|
||||
assert.ok(ms < SLOW_MS * 2 + 3_000, `登录检查耗时 ${Math.round(ms)}ms`)
|
||||
assert.equal((await started.callback()).type, "success")
|
||||
const { value: listed, ms: listMs } = await timed(() => kit.models())
|
||||
assert.ok(listMs < 100, `登录后的目录耗时 ${Math.round(listMs)}ms`)
|
||||
assertClaudeListed(listed, "登录后的第一次 models()")
|
||||
assert.equal(kit.modelsSpawns.length, 1, "登录检查读过的列表不该再读一遍")
|
||||
assert.equal(kit.acpSpawns.length, 1)
|
||||
})
|
||||
})
|
||||
|
||||
test("#1064 登录检查不为探测等太久:会话一直不答时最多多等几秒", async () => {
|
||||
await withKit({ ...SLOW_AGY, sessionNewDelayMs: 6_000 }, async (kit) => {
|
||||
const { value: started, ms } = await timed(() => kit.plugin.auth.methods[0].authorize())
|
||||
assert.equal(started.method, "auto")
|
||||
assert.ok(ms < SLOW_MS + 3_000 + 1_000, `登录检查等了 ${Math.round(ms)}ms`)
|
||||
assert.ok(ms >= SLOW_MS + 2_500, `登录检查没等探测(${Math.round(ms)}ms)`)
|
||||
const models = await kit.models()
|
||||
assert.ok(models["gemini-4-argon"])
|
||||
assert.equal(models["claude-opus-5-5"], undefined, "探测没答前不该列出 Claude")
|
||||
})
|
||||
})
|
||||
|
||||
test("#1064 agyPath 变了,旧 agy 开放的型号不再列出,新 agy 重新探测", async () => {
|
||||
await withKit({ modelsBehavior: DYNAMIC_OK, offeredModels: OFFERED_CLAUDE }, async (kit) => {
|
||||
await kit.models()
|
||||
await warmed(kit)
|
||||
assertClaudeListed(await kit.models(), "agy-a")
|
||||
kit.env.AGY_PATH = kit.makeFakeAgy("agy-b")
|
||||
kit.offeredModels = [["gemini-4-argon-high", "Gemini 4 Argon (High)"], ["gemini-4-argon-low", "Gemini 4 Argon (Low)"]]
|
||||
const switched = await kit.models()
|
||||
assert.deepEqual(ids(switched).filter(id => /^(?:claude|gpt)-/.test(id)), [], "换了 agy 还在列旧 agy 开放的型号")
|
||||
await warmed(kit)
|
||||
assert.equal(kit.acpSpawns.length, 2, "新 agy 应重新探测")
|
||||
assert.equal(kit.acpSpawns.at(-1).file, kit.env.AGY_PATH)
|
||||
const after = await kit.models()
|
||||
assert.equal(after["claude-opus-5-5"], undefined)
|
||||
assert.ok(after["gemini-4-argon"])
|
||||
})
|
||||
})
|
||||
|
||||
test("握手报出的 agy 版本低于 1.4.12 时拒绝会话并说明原因", async () => {
|
||||
await withKit({ agentVersion: "1.4.11" }, async (kit) => {
|
||||
kit.defaultPrompt = async (agent) => {
|
||||
|
||||
@@ -264,7 +264,9 @@ class FakeAgy {
|
||||
const models = { currentModelId: this.kit.initialAgyModel }
|
||||
// What agy offers this client in the session; unset, the session names none.
|
||||
if (this.kit.offeredModels) models.availableModels = this.kit.offeredModels.map(([modelId, name]) => ({ modelId, name }))
|
||||
this.respond(id, { sessionId: this.sessionId, models })
|
||||
// A real signed-in agy takes ~3s to open a session (#1064).
|
||||
if (this.kit.sessionNewDelayMs) setTimeout(() => this.respond(id, { sessionId: this.sessionId, models }), this.kit.sessionNewDelayMs)
|
||||
else this.respond(id, { sessionId: this.sessionId, models })
|
||||
} else if (method === "session/set_model") {
|
||||
this.kit.setModels.push(params.modelId)
|
||||
this.respond(id, {})
|
||||
@@ -424,6 +426,7 @@ export async function createBridgeKit(options = {}) {
|
||||
initialAgyModel: options.initialAgyModel ?? "gemini-3.8-flash-low",
|
||||
offeredModels: options.offeredModels ?? null,
|
||||
sessionNewError: options.sessionNewError ?? null,
|
||||
sessionNewDelayMs: options.sessionNewDelayMs ?? 0,
|
||||
sessionResume: options.sessionResume ?? false,
|
||||
agentVersion: options.agentVersion ?? "1.5.0",
|
||||
setModels: [],
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
+25
-1
@@ -575,7 +575,31 @@ async function setupPlugin(ctx, fn, live) {
|
||||
}
|
||||
} catch {}
|
||||
})()
|
||||
void refresh()
|
||||
// A plugin still reading its list in the background when the first read
|
||||
// returned (agy-cli: `agy models` and a session probe take seconds, and
|
||||
// the first read gets its static list) says so through
|
||||
// provider.warming(): the list is read once more when that ends, once,
|
||||
// and no later than a minute on.
|
||||
const warmed = async () => {
|
||||
let w
|
||||
try {
|
||||
w = typeof hooks.provider?.warming === "function" ? hooks.provider.warming() : null
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!w || typeof w.then !== "function") return
|
||||
let timer
|
||||
await Promise.race([
|
||||
Promise.resolve(w).catch(() => {}),
|
||||
new Promise((r) => {
|
||||
timer = setTimeout(r, 60_000)
|
||||
timer.unref?.()
|
||||
}),
|
||||
])
|
||||
clearTimeout(timer)
|
||||
if (live.on) await refresh()
|
||||
}
|
||||
void refresh().then(warmed, () => {})
|
||||
}
|
||||
|
||||
export async function setup(ctx, mod = v1) {
|
||||
|
||||
@@ -271,3 +271,63 @@ test("a 1.x code sign-in is a 2.x code sign-in", async () => {
|
||||
const again = await f.methods[0].authorize({})
|
||||
await expect(again.callback("bad")).rejects.toThrow()
|
||||
})
|
||||
|
||||
// a plugin whose first list is its static one while it reads the real one
|
||||
// in the background (agy-cli, plugins#1064): 2.x reads provider.models once
|
||||
// at startup, so the adapter reads it once more when provider.warming()
|
||||
// ends, and only once
|
||||
function slow(state) {
|
||||
return {
|
||||
SlowPlugin: async () => ({
|
||||
auth: { provider: "slow", methods: [{ type: "api", label: "Slow key" }] },
|
||||
config: async (cfg) => {
|
||||
cfg.provider.slow = { npm: "@ai-sdk/openai-compatible", name: "Slow", models: { m1: { name: "M1" } } }
|
||||
},
|
||||
provider: {
|
||||
id: "slow",
|
||||
warming: () => state.warming(),
|
||||
models: async () => {
|
||||
state.reads++
|
||||
return state.ready ? { full: { name: "Full" } } : { stub: { name: "Stub" } }
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
test("a list still warming when 2.x first reads it is read once more when it ends (plugins#1064)", async () => {
|
||||
const { setup } = await import(join(packages, "agy-cli", "opencode2.mjs"))
|
||||
let release
|
||||
const state = { reads: 0, ready: false, warmings: 0 }
|
||||
state.warming = () => {
|
||||
state.warmings++
|
||||
return state.ready ? null : new Promise((r) => (release = r))
|
||||
}
|
||||
const f = fakeContext()
|
||||
f.conns.set("slow", { connection: { type: "credential", id: "cred_1" }, value: { type: "key", key: "sk" } })
|
||||
const stop = await setup(f.ctx, slow(state))
|
||||
await until(() => f.reloads.model === 1 && !!release)
|
||||
expect(f.providers()[0].models.map((m) => m.name)).toEqual(["Stub"])
|
||||
expect(state.reads).toBe(1)
|
||||
state.ready = true
|
||||
release(true)
|
||||
await until(() => f.reloads.model === 2)
|
||||
expect(f.providers()[0].models.map((m) => m.name)).toEqual(["Full"])
|
||||
// once: the second read doesn't ask again, so nothing loops
|
||||
await new Promise((r) => setTimeout(r, 20))
|
||||
expect(state.reads).toBe(2)
|
||||
expect(state.warmings).toBe(1)
|
||||
stop()
|
||||
})
|
||||
|
||||
test("a plugin with nothing warming is read once at startup", async () => {
|
||||
const { setup } = await import(join(packages, "agy-cli", "opencode2.mjs"))
|
||||
const state = { reads: 0, ready: true, warming: () => null }
|
||||
const f = fakeContext()
|
||||
f.conns.set("slow", { connection: { type: "credential", id: "cred_1" }, value: { type: "key", key: "sk" } })
|
||||
const stop = await setup(f.ctx, slow(state))
|
||||
await until(() => f.reloads.model === 1)
|
||||
await new Promise((r) => setTimeout(r, 20))
|
||||
expect(state.reads).toBe(1)
|
||||
stop()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user