@velocirouter/pi 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/index.js +17 -4
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -55,8 +55,9 @@ the default model prices remain zero. Per-category cost breakdowns are not
|
|
|
55
55
|
available, and earlier turns recorded with zero cost are not updated.
|
|
56
56
|
|
|
57
57
|
The catalog is fetched when an interactive session starts, after `/login`, and
|
|
58
|
-
from the `/model` picker. `pi -p` and `pi --list-models` read the cached copy
|
|
59
|
-
|
|
58
|
+
from the `/model` picker. `pi -p` and `pi --list-models` read the cached copy;
|
|
59
|
+
when the cache is empty they fetch it once with the stored key or
|
|
60
|
+
`VELOCIROUTER_API_KEY`, so CI needs no interactive start.
|
|
60
61
|
|
|
61
62
|
## Environment variables
|
|
62
63
|
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const API = "openai-completions"
|
|
|
5
5
|
const DEFAULT_BASE_URL = "https://api.velocirouter.site"
|
|
6
6
|
const DEFAULT_CONTEXT_WINDOW = 128_000
|
|
7
7
|
const NO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }
|
|
8
|
+
const COLD_FETCH_TIMEOUT_MS = 10_000
|
|
8
9
|
const THINKING_LEVELS = ["minimal", "low", "medium", "high", "xhigh", "max"]
|
|
9
10
|
|
|
10
11
|
function baseUrl() {
|
|
@@ -69,16 +70,28 @@ function restore(stored) {
|
|
|
69
70
|
}))
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
// pi -p never runs the network phase and pi update --models never loads
|
|
74
|
+
// extensions, so a cold cache is fetched here even when allowNetwork is false.
|
|
75
|
+
function refreshKey({ credential, allowNetwork }, cached) {
|
|
76
|
+
if (allowNetwork) return credential?.key
|
|
77
|
+
if (cached?.length || process.env.PI_OFFLINE !== undefined) return undefined
|
|
78
|
+
return credential?.key || process.env.VELOCIROUTER_API_KEY
|
|
79
|
+
}
|
|
80
|
+
|
|
72
81
|
async function refreshModels({ credential, stored, publish, allowNetwork, signal }) {
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
const cached = restore(stored)
|
|
83
|
+
const key = refreshKey({ credential, allowNetwork }, cached)
|
|
84
|
+
if (!key) {
|
|
85
|
+
return cached
|
|
75
86
|
}
|
|
76
|
-
|
|
87
|
+
// The cache phase runs without a host timeout, so a stalled API would block startup.
|
|
88
|
+
const fetchSignal = allowNetwork ? signal : AbortSignal.any([signal, AbortSignal.timeout(COLD_FETCH_TIMEOUT_MS)].filter(Boolean))
|
|
89
|
+
const payload = await getJson(`${baseUrl()}/models`, key, fetchSignal)
|
|
77
90
|
const rows = Array.isArray(payload?.data) ? payload.data : []
|
|
78
91
|
const models = rows.filter((row) => typeof row?.id === "string" && row.id && isChatModel(row)).map(toModel)
|
|
79
92
|
// An empty catalog would wipe the cache; keep what was there.
|
|
80
93
|
if (!models.length) {
|
|
81
|
-
return
|
|
94
|
+
return cached
|
|
82
95
|
}
|
|
83
96
|
const persisted = models.map((model) => ({ ...model, api: API, provider: PROVIDER, baseUrl: baseUrl() }))
|
|
84
97
|
await publish({ persist: { models: persisted, checkedAt: Date.now() } })
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velocirouter/pi",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Pi coding agent package for VelociRouter — registers the provider and its model catalog.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/byte-twister/ai-router.git",
|
|
11
|
+
"directory": "services/velocirouter-pi"
|
|
12
|
+
},
|
|
8
13
|
"files": [
|
|
9
14
|
"index.js",
|
|
10
15
|
"cost-stream.js",
|