Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(jev): say "out of credit" instead of stalling, and ship a self-test (#158)

Deeffbc4b0d7de0
diff --git a/store/agents/jev-blocks/toolchain/jev.mjs b/store/agents/jev-blocks/toolchain/jev.mjs
index 0552989b9..d42c43c0b 100644
--- a/store/agents/jev-blocks/toolchain/jev.mjs
+++ b/store/agents/jev-blocks/toolchain/jev.mjs
@@ -343,8 +343,12 @@ export async function connectKey(value, { probe = true } = {}) {
return { ok: true, provider: cred.provider, stored: true, probed: true }
} catch (e) {
const msg = String(e?.message ?? e)
- if (/\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg)) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
- return { ok: true, provider: cred.provider, stored: true, probed: false, warning: `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
+ // A refused key is not worth keeping. A good key on an account with no credit left is: the
+ // person only has to top it up, and throwing the key away would make that harder.
+ const refused = e?.status === 401 || e?.status === 403 ||
+ (!e?.status && /\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg))
+ if (refused) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
+ return { ok: true, provider: cred.provider, stored: true, probed: false, warning: e?.provider ? msg : `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
}
}
@@ -379,10 +383,25 @@ async function liveEvaluate(body, cred) {
return data?.result?.answers ? data.result : data
}
const detail = await res.text().catch(() => '')
- lastErr = new JevError(`Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // A person reading the pane needs to know what to do, not what the server's JSON looked like.
+ const plain = {
+ 401: 'That Jev key was refused. Paste a working one in the pane\'s "Jev · live mind" panel.',
+ 402: 'The account behind that Jev key is out of credit. Top it up with your provider and press Go again.',
+ 403: 'That Jev key is not allowed to use this model.',
+ 429: 'Your Jev provider is rate limiting these calls. Wait a moment and try again.',
+ 529: 'Jev is overloaded right now. Try again in a moment.',
+ }[res.status]
+ lastErr = new JevError(plain ? `${plain} (HTTP ${res.status})` : `Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // The caller shows this one to a person as-is: it already says what to do, so nothing should
+ // bury it under "nothing could be worked out".
+ lastErr.provider = Boolean(plain)
+ lastErr.status = res.status
if (res.status !== 429 && res.status !== 529 && res.status < 500) throw lastErr // 401/422: retrying cannot help
} catch (e) {
- if (e instanceof JevError && !/ (429|529|5\d\d):/.test(e.message)) throw e
+ // Which ones are worth trying again is a fact about the status, not about how the message
+ // happens to read: the messages above are written for a person and no longer carry the code.
+ const worthRetrying = e.status === 429 || e.status === 529 || e.status >= 500
+ if (e instanceof JevError && !worthRetrying) throw e
lastErr = e instanceof JevError ? e : new JevError(`Jev API unreachable: ${e?.message ?? e}`)
}
}
diff --git a/store/agents/jev-browser/AGENTS.md b/store/agents/jev-browser/AGENTS.md
index d94dc3f38..020b6a189 100644
--- a/store/agents/jev-browser/AGENTS.md
+++ b/store/agents/jev-browser/AGENTS.md
@@ -193,7 +193,11 @@ about a minute). Never ask them to paste a key into the chat.
- Never propose opening a browser yourself, changing ports, or running a second server. The pane
owns the browser, and Start, Stop and the address bar are the person's buttons, not yours. The
one browser you may open is a read-only look with `openChrome` (below), which touches nothing.
-- Chrome must be on the machine. `toolchain/doctor.sh` says whether it is.
+- Chrome must be on the machine. When they say the pane is stuck, did nothing, or never opened a
+ browser, run `bash toolchain/doctor.sh` before theorising: it walks the whole chain — Chrome, a
+ page, the reader, one Jev call — and prints `ok` or `FAIL` for each, and the first `FAIL` is the
+ thing to fix. Tell them that line, not a guess. The usual three are an account out of credit, a
+ browser window left open on this harness's profile, and a site that refuses automated browsers.
## Definition of done
diff --git a/store/agents/jev-browser/README.md b/store/agents/jev-browser/README.md
index 6e1e5bf04..b20b44ff8 100644
--- a/store/agents/jev-browser/README.md
+++ b/store/agents/jev-browser/README.md
@@ -129,6 +129,26 @@ about being a stand-in, but its rows are not worth acting on. Paste an OpenRoute
into the **Jev · live mind** panel in the pane. It is saved on your machine in
`~/.config/typesafe/credentials` and checked with one tiny call.
+## When the pane does nothing
+
+One command runs the whole chain — Chrome, a page, the reader, one Jev call — and prints `ok` or
+`FAIL` for each link, so you find out which one broke instead of guessing:
+
+```
+bash toolchain/doctor.sh the built-in site, about five seconds
+bash toolchain/doctor.sh https://… that site instead
+bash toolchain/doctor.sh --show a visible window, the way the pane runs it
+```
+
+The three that actually happen:
+
+- **out of credit.** Every call comes back 402 and nothing can be answered. Top the account up
+ with your provider. The pane says so in as many words now.
+- **a browser left open.** Chrome will not open a second window on this harness's profile; it
+ hands the request to the open one and quits. Close that window and press Go again.
+- **the site says no.** Some sites serve a challenge page to any automated browser. It is named in
+ the pane rather than collected from. Try another site.
+
## Which sites let it read
Checked on 2026-09-20, one page each, with the headless browser the tests use.
@@ -169,6 +189,7 @@ jev-browser/
chrome.mjs drives a real Chrome over the DevTools protocol, and holds every refusal
jev.mjs the Jev client (TypeSafe, Cloudflare or OpenRouter, or the stand-in)
check.mjs validates browse.json
+ selftest.mjs runs the whole chain and says which link broke
viewer.sh setup.sh doctor.sh init-workspace.sh
viewer/
viewer.mjs the server: the job, the browser, the run, results.csv, the verdict
diff --git a/store/agents/jev-browser/test/viewer.test.mjs b/store/agents/jev-browser/test/viewer.test.mjs
index 3fa659b64..f750d5256 100644
--- a/store/agents/jev-browser/test/viewer.test.mjs
+++ b/store/agents/jev-browser/test/viewer.test.mjs
@@ -495,3 +495,34 @@ test('a browser left open on the profile is reported, and does not take the view
assert.ok(r.ok !== false || r.error)
} finally { await v.close(); delete process.env.JEV_OFFLINE }
})
+
+test("a key with no credit left is said plainly, not as a blob of the provider's JSON", async () => {
+ // This is the one that had the pane stuck at "reading the page": the account behind the key had
+ // run dry, every call came back 402, and the pane said
+ // `No columns could be worked out: Jev API 402: {"error":{"message":"Insufficient credits…`.
+ const { createServer } = await import('node:http')
+ const { evaluate, jev } = await import('../toolchain/jev.mjs')
+ const seen = []
+ const server = createServer((req, res) => {
+ seen.push(req.url)
+ res.writeHead(402, { 'content-type': 'application/json' })
+ res.end('{"error":{"message":"Insufficient credits. Add more using https://openrouter.ai/settings/credits","code":402}}')
+ })
+ await new Promise((r) => server.listen(0, '127.0.0.1', r))
+ const before = process.env.TYPESAFE_API_URL
+ process.env.TYPESAFE_API_URL = `http://127.0.0.1:${server.address().port}/v1/systemone`
+ try {
+ const err = await evaluate({ state: { page: 'a page' }, questions: { q: jev.noul('is it?') }, key: 'not-a-real-key' })
+ .then(() => null, (e) => e)
+ assert.ok(err, 'the call fails')
+ assert.match(err.message, /out of credit/, err.message)
+ assert.ok(!err.message.includes('{'), `no JSON in front of a person: ${err.message}`)
+ assert.equal(err.provider, true, 'flagged, so the pane repeats it as it is')
+ assert.equal(err.status, 402)
+ assert.equal(seen.length, 1, 'no point retrying a dry account')
+ } finally {
+ if (before === undefined) delete process.env.TYPESAFE_API_URL
+ else process.env.TYPESAFE_API_URL = before
+ server.close()
+ }
+})
diff --git a/store/agents/jev-browser/toolchain/doctor.sh b/store/agents/jev-browser/toolchain/doctor.sh
index a88fc0c65..8df9b3560 100755
--- a/store/agents/jev-browser/toolchain/doctor.sh
+++ b/store/agents/jev-browser/toolchain/doctor.sh
@@ -1,12 +1,10 @@
#!/usr/bin/env bash
-# Doctor: what this harness needs to drive a real browser.
+# Doctor: run the whole chain — Chrome, a page, the reader, one Jev call — and say which link broke.
+# Pass a web address to try that site instead of the built-in one, or --show for a visible window.
set -euo pipefail
if ! command -v node >/dev/null 2>&1; then echo "fail node is required (Node 22+)"; exit 1; fi
if ! node -e "process.exit(Number(process.versions.node.split('.')[0]) >= 22 ? 0 : 1)" 2>/dev/null; then
echo "fail node >= 22 required for the built-in WebSocket (found $(node -v))"; exit 1
fi
-echo "ok node $(node -v)"
cd "$(dirname "$0")/.."
-node -e "import('./toolchain/chrome.mjs').then((m) => { const p = m.findChrome(); console.log(p ? 'ok Google Chrome: ' + p : 'fail Google Chrome was not found. Install it, or set CHROME_PATH to where it is.'); process.exit(p ? 0 : 1) })"
-node -e "import('./toolchain/jev.mjs').then((m) => console.log('ok Jev: ' + m.describeCredentials())).catch((e) => console.log('warn Jev client did not load: ' + e.message))"
-echo "done"
+exec node toolchain/selftest.mjs "$@"
diff --git a/store/agents/jev-browser/toolchain/jev.mjs b/store/agents/jev-browser/toolchain/jev.mjs
index 0552989b9..d42c43c0b 100644
--- a/store/agents/jev-browser/toolchain/jev.mjs
+++ b/store/agents/jev-browser/toolchain/jev.mjs
@@ -343,8 +343,12 @@ export async function connectKey(value, { probe = true } = {}) {
return { ok: true, provider: cred.provider, stored: true, probed: true }
} catch (e) {
const msg = String(e?.message ?? e)
- if (/\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg)) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
- return { ok: true, provider: cred.provider, stored: true, probed: false, warning: `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
+ // A refused key is not worth keeping. A good key on an account with no credit left is: the
+ // person only has to top it up, and throwing the key away would make that harder.
+ const refused = e?.status === 401 || e?.status === 403 ||
+ (!e?.status && /\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg))
+ if (refused) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
+ return { ok: true, provider: cred.provider, stored: true, probed: false, warning: e?.provider ? msg : `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
}
}
@@ -379,10 +383,25 @@ async function liveEvaluate(body, cred) {
return data?.result?.answers ? data.result : data
}
const detail = await res.text().catch(() => '')
- lastErr = new JevError(`Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // A person reading the pane needs to know what to do, not what the server's JSON looked like.
+ const plain = {
+ 401: 'That Jev key was refused. Paste a working one in the pane\'s "Jev · live mind" panel.',
+ 402: 'The account behind that Jev key is out of credit. Top it up with your provider and press Go again.',
+ 403: 'That Jev key is not allowed to use this model.',
+ 429: 'Your Jev provider is rate limiting these calls. Wait a moment and try again.',
+ 529: 'Jev is overloaded right now. Try again in a moment.',
+ }[res.status]
+ lastErr = new JevError(plain ? `${plain} (HTTP ${res.status})` : `Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // The caller shows this one to a person as-is: it already says what to do, so nothing should
+ // bury it under "nothing could be worked out".
+ lastErr.provider = Boolean(plain)
+ lastErr.status = res.status
if (res.status !== 429 && res.status !== 529 && res.status < 500) throw lastErr // 401/422: retrying cannot help
} catch (e) {
- if (e instanceof JevError && !/ (429|529|5\d\d):/.test(e.message)) throw e
+ // Which ones are worth trying again is a fact about the status, not about how the message
+ // happens to read: the messages above are written for a person and no longer carry the code.
+ const worthRetrying = e.status === 429 || e.status === 529 || e.status >= 500
+ if (e instanceof JevError && !worthRetrying) throw e
lastErr = e instanceof JevError ? e : new JevError(`Jev API unreachable: ${e?.message ?? e}`)
}
}
diff --git a/store/agents/jev-browser/toolchain/selftest.mjs b/store/agents/jev-browser/toolchain/selftest.mjs
new file mode 100755
index 000000000..620dc1178
--- /dev/null
+++ b/store/agents/jev-browser/toolchain/selftest.mjs
@@ -0,0 +1,76 @@
+#!/usr/bin/env node
+// selftest.mjs — run the whole chain and say which link in it broke.
+//
+// node toolchain/selftest.mjs the practice site, no key needed
+// node toolchain/selftest.mjs <url> that site instead
+// node toolchain/selftest.mjs --show a visible window, like the pane uses
+//
+// Every step prints ok or fail with the reason, so a person can paste the output and be told what
+// to do rather than "nothing happened".
+import { findChrome, openChrome } from './chrome.mjs'
+import { describeCredentials, resolveCredentials, evaluate, jev } from './jev.mjs'
+import { readPage, wallReason } from '../viewer/page.mjs'
+import { startDemoSite } from '../viewer/demosite.mjs'
+import { mkdtempSync, existsSync, readdirSync } from 'node:fs'
+import { tmpdir, homedir } from 'node:os'
+import { join } from 'node:path'
+
+const args = process.argv.slice(2)
+const show = args.includes('--show')
+const url = args.find((a) => !a.startsWith('--'))
+let failed = 0
+const ok = (what, detail = '') => console.log(`ok ${what}${detail ? ' — ' + detail : ''}`)
+const bad = (what, detail) => { failed++; console.log(`FAIL ${what}\n ${detail}`) }
+
+console.log(`node ${process.version}`)
+const chromePath = findChrome()
+if (!chromePath) bad('Google Chrome', 'not found. Install Chrome, or set CHROME_PATH to where it is.')
+else ok('Google Chrome', chromePath)
+
+// A window left open on the harness's own profile is the usual reason nothing happens.
+const workspace = process.env.HARNESS_WORKSPACE || process.cwd()
+const profileDir = join(workspace, '.harness', 'chrome-profile')
+if (existsSync(join(profileDir, 'SingletonLock'))) {
+ console.log(`warn a browser may still be open on this harness's profile (${profileDir}).`)
+ console.log(` If the next step fails, close that window and run this again.`)
+}
+
+const cred = resolveCredentials()
+if (cred) ok('Jev key', describeCredentials())
+else console.log(`warn no Jev key: an offline stand-in will answer. Paste a key in the pane's "Jev · live mind" panel.`)
+
+if (!chromePath) { console.log(`\n${failed} step failed.`); process.exit(1) }
+
+const site = url ? null : await startDemoSite()
+const target = url ?? site.url
+let chrome = null
+try {
+ try {
+ chrome = await openChrome({ profileDir: show ? profileDir : mkdtempSync(join(tmpdir(), 'jev-selftest-')), show, allowedHosts: [new URL(target).hostname] })
+ ok(`opened a ${show ? 'visible' : 'headless'} browser`, `debugging on port ${chrome.port}`)
+ } catch (e) { bad('opening the browser', e.message); throw e }
+
+ try {
+ const went = await chrome.go(target)
+ ok('opened the page', went.url)
+ } catch (e) { bad(`opening ${target}`, e.message); throw e }
+
+ const page = await readPage(chrome)
+ const wall = wallReason(page)
+ if (wall) bad('reading the page', `${wall}. This site refuses an automated browser; try another.`)
+ else ok('read the page', `${page.links.length} links, ${page.blocks.length} pieces of text`)
+
+ try {
+ const t0 = Date.now()
+ const res = await evaluate({ state: { text: page.title || 'a web page' }, questions: { q: jev.noul('Is this text the title of a web page?') } })
+ ok(`asked Jev`, `${res.client}, ${Date.now() - t0} ms, answer ${Number(res.answers.q.noul).toFixed(2)}`)
+ } catch (e) { bad('asking Jev', e.message) }
+} catch { /* already reported */ } finally {
+ await chrome?.close()
+ await site?.close()
+}
+
+const files = existsSync(workspace) ? readdirSync(workspace).filter((f) => !f.startsWith('.')) : []
+console.log(`\nworkspace ${workspace}${files.length ? ` (${files.join(', ')})` : ' (empty)'}`)
+console.log(failed ? `${failed} step failed — the first FAIL above is the one to fix.` : 'Everything works. If the pane still does nothing, say so and paste this output.')
+process.exit(failed ? 1 : 0)
diff --git a/store/agents/jev-browser/viewer/viewer.mjs b/store/agents/jev-browser/viewer/viewer.mjs
index a8364505d..417ded2dc 100644
--- a/store/agents/jev-browser/viewer/viewer.mjs
+++ b/store/agents/jev-browser/viewer/viewer.mjs
@@ -197,15 +197,17 @@ export async function startBrowserViewer({ workspace, port = 0, show = null } =
if (found.url !== job.start) { job = { ...job, start: found.url }; counters.pages = found.steps }
got = await proposeJob({ chrome, ask, start: found.url, page: found.page, want: job.want, search: job.search, onEvent: watch })
}
- } catch (e) { got = { columns: [], error: String(e.message ?? e) } }
+ } catch (e) { got = { columns: [], error: String(e.message ?? e), provider: e?.provider === true } }
proposing = false
if (got.walled) { lastRun = { walled: got.walled, errors: [] }; say(got.walled, 'bad'); phase = 'done'; finishedAt = Date.now(); push(); saveVerdict(); return { ok: false, error: got.walled } }
if (!got.columns.length) {
phase = 'idle'; finishedAt = Date.now()
const why = got.error || got.none || 'nothing on that page looked like a value worth a column'
- say(`No columns could be worked out: ${why}`, 'bad')
+ // A key that is refused or out of credit is not a "the page was no good" problem, and
+ // saying so sends the person off reading the page instead of fixing the key.
+ say(got.provider ? why : `No columns could be worked out: ${why}`, 'bad')
push(); saveVerdict()
- return { ok: false, error: `${why}. Write the columns yourself, one per line.` }
+ return { ok: false, error: got.provider ? why : `${why}. Write the columns yourself, one per line.` }
}
const saidItem = String(watcher.get()?.item ?? '').trim()
// Write back the page it walked to, not the address that was typed: otherwise the job resets
diff --git a/store/agents/jev-compactor/toolchain/jev.mjs b/store/agents/jev-compactor/toolchain/jev.mjs
index 0552989b9..d42c43c0b 100644
--- a/store/agents/jev-compactor/toolchain/jev.mjs
+++ b/store/agents/jev-compactor/toolchain/jev.mjs
@@ -343,8 +343,12 @@ export async function connectKey(value, { probe = true } = {}) {
return { ok: true, provider: cred.provider, stored: true, probed: true }
} catch (e) {
const msg = String(e?.message ?? e)
- if (/\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg)) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
- return { ok: true, provider: cred.provider, stored: true, probed: false, warning: `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
+ // A refused key is not worth keeping. A good key on an account with no credit left is: the
+ // person only has to top it up, and throwing the key away would make that harder.
+ const refused = e?.status === 401 || e?.status === 403 ||
+ (!e?.status && /\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg))
+ if (refused) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
+ return { ok: true, provider: cred.provider, stored: true, probed: false, warning: e?.provider ? msg : `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
}
}
@@ -379,10 +383,25 @@ async function liveEvaluate(body, cred) {
return data?.result?.answers ? data.result : data
}
const detail = await res.text().catch(() => '')
- lastErr = new JevError(`Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // A person reading the pane needs to know what to do, not what the server's JSON looked like.
+ const plain = {
+ 401: 'That Jev key was refused. Paste a working one in the pane\'s "Jev · live mind" panel.',
+ 402: 'The account behind that Jev key is out of credit. Top it up with your provider and press Go again.',
+ 403: 'That Jev key is not allowed to use this model.',
+ 429: 'Your Jev provider is rate limiting these calls. Wait a moment and try again.',
+ 529: 'Jev is overloaded right now. Try again in a moment.',
+ }[res.status]
+ lastErr = new JevError(plain ? `${plain} (HTTP ${res.status})` : `Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // The caller shows this one to a person as-is: it already says what to do, so nothing should
+ // bury it under "nothing could be worked out".
+ lastErr.provider = Boolean(plain)
+ lastErr.status = res.status
if (res.status !== 429 && res.status !== 529 && res.status < 500) throw lastErr // 401/422: retrying cannot help
} catch (e) {
- if (e instanceof JevError && !/ (429|529|5\d\d):/.test(e.message)) throw e
+ // Which ones are worth trying again is a fact about the status, not about how the message
+ // happens to read: the messages above are written for a person and no longer carry the code.
+ const worthRetrying = e.status === 429 || e.status === 529 || e.status >= 500
+ if (e instanceof JevError && !worthRetrying) throw e
lastErr = e instanceof JevError ? e : new JevError(`Jev API unreachable: ${e?.message ?? e}`)
}
}
diff --git a/store/agents/jev-firehose/toolchain/jev.mjs b/store/agents/jev-firehose/toolchain/jev.mjs
index 0552989b9..d42c43c0b 100644
--- a/store/agents/jev-firehose/toolchain/jev.mjs
+++ b/store/agents/jev-firehose/toolchain/jev.mjs
@@ -343,8 +343,12 @@ export async function connectKey(value, { probe = true } = {}) {
return { ok: true, provider: cred.provider, stored: true, probed: true }
} catch (e) {
const msg = String(e?.message ?? e)
- if (/\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg)) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
- return { ok: true, provider: cred.provider, stored: true, probed: false, warning: `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
+ // A refused key is not worth keeping. A good key on an account with no credit left is: the
+ // person only has to top it up, and throwing the key away would make that harder.
+ const refused = e?.status === 401 || e?.status === 403 ||
+ (!e?.status && /\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg))
+ if (refused) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
+ return { ok: true, provider: cred.provider, stored: true, probed: false, warning: e?.provider ? msg : `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
}
}
@@ -379,10 +383,25 @@ async function liveEvaluate(body, cred) {
return data?.result?.answers ? data.result : data
}
const detail = await res.text().catch(() => '')
- lastErr = new JevError(`Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // A person reading the pane needs to know what to do, not what the server's JSON looked like.
+ const plain = {
+ 401: 'That Jev key was refused. Paste a working one in the pane\'s "Jev · live mind" panel.',
+ 402: 'The account behind that Jev key is out of credit. Top it up with your provider and press Go again.',
+ 403: 'That Jev key is not allowed to use this model.',
+ 429: 'Your Jev provider is rate limiting these calls. Wait a moment and try again.',
+ 529: 'Jev is overloaded right now. Try again in a moment.',
+ }[res.status]
+ lastErr = new JevError(plain ? `${plain} (HTTP ${res.status})` : `Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // The caller shows this one to a person as-is: it already says what to do, so nothing should
+ // bury it under "nothing could be worked out".
+ lastErr.provider = Boolean(plain)
+ lastErr.status = res.status
if (res.status !== 429 && res.status !== 529 && res.status < 500) throw lastErr // 401/422: retrying cannot help
} catch (e) {
- if (e instanceof JevError && !/ (429|529|5\d\d):/.test(e.message)) throw e
+ // Which ones are worth trying again is a fact about the status, not about how the message
+ // happens to read: the messages above are written for a person and no longer carry the code.
+ const worthRetrying = e.status === 429 || e.status === 529 || e.status >= 500
+ if (e instanceof JevError && !worthRetrying) throw e
lastErr = e instanceof JevError ? e : new JevError(`Jev API unreachable: ${e?.message ?? e}`)
}
}
diff --git a/store/agents/jev-fps/toolchain/jev.mjs b/store/agents/jev-fps/toolchain/jev.mjs
index 0552989b9..d42c43c0b 100644
--- a/store/agents/jev-fps/toolchain/jev.mjs
+++ b/store/agents/jev-fps/toolchain/jev.mjs
@@ -343,8 +343,12 @@ export async function connectKey(value, { probe = true } = {}) {
return { ok: true, provider: cred.provider, stored: true, probed: true }
} catch (e) {
const msg = String(e?.message ?? e)
- if (/\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg)) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
- return { ok: true, provider: cred.provider, stored: true, probed: false, warning: `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
+ // A refused key is not worth keeping. A good key on an account with no credit left is: the
+ // person only has to top it up, and throwing the key away would make that harder.
+ const refused = e?.status === 401 || e?.status === 403 ||
+ (!e?.status && /\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg))
+ if (refused) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
+ return { ok: true, provider: cred.provider, stored: true, probed: false, warning: e?.provider ? msg : `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
}
}
@@ -379,10 +383,25 @@ async function liveEvaluate(body, cred) {
return data?.result?.answers ? data.result : data
}
const detail = await res.text().catch(() => '')
- lastErr = new JevError(`Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // A person reading the pane needs to know what to do, not what the server's JSON looked like.
+ const plain = {
+ 401: 'That Jev key was refused. Paste a working one in the pane\'s "Jev · live mind" panel.',
+ 402: 'The account behind that Jev key is out of credit. Top it up with your provider and press Go again.',
+ 403: 'That Jev key is not allowed to use this model.',
+ 429: 'Your Jev provider is rate limiting these calls. Wait a moment and try again.',
+ 529: 'Jev is overloaded right now. Try again in a moment.',
+ }[res.status]
+ lastErr = new JevError(plain ? `${plain} (HTTP ${res.status})` : `Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // The caller shows this one to a person as-is: it already says what to do, so nothing should
+ // bury it under "nothing could be worked out".
+ lastErr.provider = Boolean(plain)
+ lastErr.status = res.status
if (res.status !== 429 && res.status !== 529 && res.status < 500) throw lastErr // 401/422: retrying cannot help
} catch (e) {
- if (e instanceof JevError && !/ (429|529|5\d\d):/.test(e.message)) throw e
+ // Which ones are worth trying again is a fact about the status, not about how the message
+ // happens to read: the messages above are written for a person and no longer carry the code.
+ const worthRetrying = e.status === 429 || e.status === 529 || e.status >= 500
+ if (e instanceof JevError && !worthRetrying) throw e
lastErr = e instanceof JevError ? e : new JevError(`Jev API unreachable: ${e?.message ?? e}`)
}
}
diff --git a/store/agents/jev-sheets/toolchain/jev.mjs b/store/agents/jev-sheets/toolchain/jev.mjs
index 0552989b9..d42c43c0b 100644
--- a/store/agents/jev-sheets/toolchain/jev.mjs
+++ b/store/agents/jev-sheets/toolchain/jev.mjs
@@ -343,8 +343,12 @@ export async function connectKey(value, { probe = true } = {}) {
return { ok: true, provider: cred.provider, stored: true, probed: true }
} catch (e) {
const msg = String(e?.message ?? e)
- if (/\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg)) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
- return { ok: true, provider: cred.provider, stored: true, probed: false, warning: `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
+ // A refused key is not worth keeping. A good key on an account with no credit left is: the
+ // person only has to top it up, and throwing the key away would make that harder.
+ const refused = e?.status === 401 || e?.status === 403 ||
+ (!e?.status && /\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg))
+ if (refused) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
+ return { ok: true, provider: cred.provider, stored: true, probed: false, warning: e?.provider ? msg : `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
}
}
@@ -379,10 +383,25 @@ async function liveEvaluate(body, cred) {
return data?.result?.answers ? data.result : data
}
const detail = await res.text().catch(() => '')
- lastErr = new JevError(`Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // A person reading the pane needs to know what to do, not what the server's JSON looked like.
+ const plain = {
+ 401: 'That Jev key was refused. Paste a working one in the pane\'s "Jev · live mind" panel.',
+ 402: 'The account behind that Jev key is out of credit. Top it up with your provider and press Go again.',
+ 403: 'That Jev key is not allowed to use this model.',
+ 429: 'Your Jev provider is rate limiting these calls. Wait a moment and try again.',
+ 529: 'Jev is overloaded right now. Try again in a moment.',
+ }[res.status]
+ lastErr = new JevError(plain ? `${plain} (HTTP ${res.status})` : `Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // The caller shows this one to a person as-is: it already says what to do, so nothing should
+ // bury it under "nothing could be worked out".
+ lastErr.provider = Boolean(plain)
+ lastErr.status = res.status
if (res.status !== 429 && res.status !== 529 && res.status < 500) throw lastErr // 401/422: retrying cannot help
} catch (e) {
- if (e instanceof JevError && !/ (429|529|5\d\d):/.test(e.message)) throw e
+ // Which ones are worth trying again is a fact about the status, not about how the message
+ // happens to read: the messages above are written for a person and no longer carry the code.
+ const worthRetrying = e.status === 429 || e.status === 529 || e.status >= 500
+ if (e instanceof JevError && !worthRetrying) throw e
lastErr = e instanceof JevError ? e : new JevError(`Jev API unreachable: ${e?.message ?? e}`)
}
}
diff --git a/store/tools/jev-kit/jev.mjs b/store/tools/jev-kit/jev.mjs
index 0552989b9..d42c43c0b 100644
--- a/store/tools/jev-kit/jev.mjs
+++ b/store/tools/jev-kit/jev.mjs
@@ -343,8 +343,12 @@ export async function connectKey(value, { probe = true } = {}) {
return { ok: true, provider: cred.provider, stored: true, probed: true }
} catch (e) {
const msg = String(e?.message ?? e)
- if (/\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg)) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
- return { ok: true, provider: cred.provider, stored: true, probed: false, warning: `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
+ // A refused key is not worth keeping. A good key on an account with no credit left is: the
+ // person only has to top it up, and throwing the key away would make that harder.
+ const refused = e?.status === 401 || e?.status === 403 ||
+ (!e?.status && /\b(401|403)\b|unauthor|invalid.*key|forbidden/i.test(msg))
+ if (refused) { removeCredential(name); return { ok: false, error: 'The service refused that key. Nothing was saved.' } }
+ return { ok: true, provider: cred.provider, stored: true, probed: false, warning: e?.provider ? msg : `The key is saved, but the test call failed: ${msg.slice(0, 160)}` }
}
}
@@ -379,10 +383,25 @@ async function liveEvaluate(body, cred) {
return data?.result?.answers ? data.result : data
}
const detail = await res.text().catch(() => '')
- lastErr = new JevError(`Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // A person reading the pane needs to know what to do, not what the server's JSON looked like.
+ const plain = {
+ 401: 'That Jev key was refused. Paste a working one in the pane\'s "Jev · live mind" panel.',
+ 402: 'The account behind that Jev key is out of credit. Top it up with your provider and press Go again.',
+ 403: 'That Jev key is not allowed to use this model.',
+ 429: 'Your Jev provider is rate limiting these calls. Wait a moment and try again.',
+ 529: 'Jev is overloaded right now. Try again in a moment.',
+ }[res.status]
+ lastErr = new JevError(plain ? `${plain} (HTTP ${res.status})` : `Jev API ${res.status}: ${detail.slice(0, 200)}`)
+ // The caller shows this one to a person as-is: it already says what to do, so nothing should
+ // bury it under "nothing could be worked out".
+ lastErr.provider = Boolean(plain)
+ lastErr.status = res.status
if (res.status !== 429 && res.status !== 529 && res.status < 500) throw lastErr // 401/422: retrying cannot help
} catch (e) {
- if (e instanceof JevError && !/ (429|529|5\d\d):/.test(e.message)) throw e
+ // Which ones are worth trying again is a fact about the status, not about how the message
+ // happens to read: the messages above are written for a person and no longer carry the code.
+ const worthRetrying = e.status === 429 || e.status === 529 || e.status >= 500
+ if (e instanceof JevError && !worthRetrying) throw e
lastErr = e instanceof JevError ? e : new JevError(`Jev API unreachable: ${e?.message ?? e}`)
}
}