pi-uva-hva 1.4.0 → 1.5.0
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 +255 -179
- package/index.ts +208 -47
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -7,37 +7,125 @@
|
|
|
7
7
|
> [Factory Droid](../factory-droid/README.md), or
|
|
8
8
|
> [Odysseus](../odysseus/README.md).
|
|
9
9
|
|
|
10
|
+
[](https://www.npmjs.com/package/pi-uva-hva)
|
|
11
|
+
|
|
10
12
|
A [Pi](https://pi.dev) coding-agent provider extension for the University of
|
|
11
13
|
Amsterdam / Amsterdam University of Applied Sciences LiteLLM proxies
|
|
12
|
-
(
|
|
14
|
+
(https://llmproxy.uva.nl/v1, https://llmproxy.hva.nl/v1).
|
|
13
15
|
|
|
14
16
|
Get every UvA/HvA model working in Pi in under a minute, without editing Pi's config
|
|
15
|
-
files. Load the extension, run
|
|
17
|
+
files. Load the extension, run /login, pick your proxy, paste your API key, and
|
|
16
18
|
it auto-discovers all available models so you can select one straight from
|
|
17
|
-
|
|
19
|
+
/model. Your base URL and key are saved, so the next launch just reconnects.
|
|
18
20
|
Reasoning models come pre-tuned (thinking on at medium),
|
|
19
21
|
and tool-heavy agent turns that would otherwise silently come back empty on this
|
|
20
22
|
proxy just work. That's the whole setup; everything below is optional detail.
|
|
21
23
|
|
|
24
|
+
## Quick setup
|
|
25
|
+
|
|
26
|
+
Copy-paste these commands in a terminal. They install Node.js, Pi and the
|
|
27
|
+
[recommended extension set](#pi-harness-setup). If you only want the UvA/HvA
|
|
28
|
+
provider, use the [manual install](#install) instead.
|
|
29
|
+
|
|
30
|
+
### 1. Install Node.js (skip if node --version shows 22.19 or newer)
|
|
31
|
+
|
|
32
|
+
Windows (PowerShell):
|
|
33
|
+
|
|
34
|
+
```powershell
|
|
35
|
+
winget install OpenJS.NodeJS.LTS
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Close and reopen PowerShell afterwards so node and npm are found.
|
|
39
|
+
|
|
40
|
+
Linux / macOS (any distro, no admin rights needed, uses
|
|
41
|
+
[nvm](https://github.com/nvm-sh/nvm)):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
|
45
|
+
. "$HOME/.nvm/nvm.sh"
|
|
46
|
+
nvm install --lts
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. Install Pi
|
|
50
|
+
|
|
51
|
+
Linux / macOS:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
curl -fsSL https://pi.dev/install.sh | sh
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Windows (PowerShell):
|
|
58
|
+
|
|
59
|
+
```powershell
|
|
60
|
+
powershell -c "irm https://pi.dev/install.ps1 | iex"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or install it with npm, the same command on every platform:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install -g --ignore-scripts @earendil-works/pi-coding-agent
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Check it with `pi --version`.
|
|
70
|
+
|
|
71
|
+
> Windows: if PowerShell says "running scripts is disabled on this system", run
|
|
72
|
+
> Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once and try again.
|
|
73
|
+
|
|
74
|
+
### 3. Install the extensions
|
|
75
|
+
|
|
76
|
+
Windows (PowerShell):
|
|
77
|
+
|
|
78
|
+
```powershell
|
|
79
|
+
$pkgs = "pi-uva-hva","@narumitw/pi-plan-mode","pi-ask-user","pi-btw",
|
|
80
|
+
"@dietrichgebert/ponytail","pi-markdown-preview"
|
|
81
|
+
foreach ($p in $pkgs) { pi install "npm:$p" }
|
|
82
|
+
pi list
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Linux / macOS:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
for p in pi-uva-hva @narumitw/pi-plan-mode pi-ask-user pi-btw \
|
|
89
|
+
@dietrichgebert/ponytail pi-markdown-preview
|
|
90
|
+
do pi install "npm:$p"; done
|
|
91
|
+
pi list
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Already-installed packages are fine to re-run. Want only some? Remove them from
|
|
95
|
+
the list; only pi-uva-hva is needed for the university proxy.
|
|
96
|
+
|
|
97
|
+
We also recommend [Matt Pocock's skills](#skills). Optional:
|
|
98
|
+
[MCP servers](#mcp-servers).
|
|
99
|
+
|
|
100
|
+
### 4. Log in and pick a model
|
|
101
|
+
|
|
102
|
+
Start pi, then:
|
|
103
|
+
|
|
104
|
+
1. Run /login, choose UvA / HvA proxy, pick your university and paste
|
|
105
|
+
your own API key (never paste it into a chat or a repo).
|
|
106
|
+
2. Run /model and select a model.
|
|
107
|
+
3. Optional: for a model with a ~1M-token context, see the
|
|
108
|
+
[recommended context window](#recommended-context-window-for-1m-models).
|
|
109
|
+
|
|
110
|
+
This is a package-selection snapshot, not a version-locked environment. New
|
|
111
|
+
installs resolve the published package versions available at installation time.
|
|
112
|
+
Extensions run with your account's permissions; review the packages before
|
|
113
|
+
installing them. Some, such as pi-btw, make additional model calls, so check
|
|
114
|
+
their routing and cost settings before use.
|
|
115
|
+
|
|
22
116
|
## Install
|
|
23
117
|
|
|
24
|
-
|
|
118
|
+
For the provider alone, you need Pi installed and a UvA/HvA proxy API key.
|
|
25
119
|
|
|
26
120
|
### 1. Load the extension
|
|
27
121
|
|
|
28
122
|
Pick one:
|
|
29
123
|
|
|
30
|
-
- From npm
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```jsonc
|
|
34
|
-
{
|
|
35
|
-
"packages": [
|
|
36
|
-
"npm:pi-uva-hva"
|
|
37
|
-
]
|
|
38
|
-
}
|
|
124
|
+
- From npm : run
|
|
125
|
+
```bash
|
|
126
|
+
pi install npm:pi-uva-hva
|
|
39
127
|
```
|
|
40
|
-
- From a local clone: clone the repo and point at the
|
|
128
|
+
- From a local clone: clone the repo and point at the pi/ folder instead:
|
|
41
129
|
```jsonc
|
|
42
130
|
{
|
|
43
131
|
"packages": [
|
|
@@ -45,10 +133,8 @@ Pick one:
|
|
|
45
133
|
]
|
|
46
134
|
}
|
|
47
135
|
```
|
|
48
|
-
- Try it once: `pi -e /path/to/uva-hva-agentic-tools/pi`
|
|
49
|
-
- Auto-load folder: copy `index.ts` to `~/.pi/agent/extensions/`.
|
|
50
136
|
|
|
51
|
-
### 2. Connect with
|
|
137
|
+
### 2. Connect with /login
|
|
52
138
|
|
|
53
139
|
Start Pi and run:
|
|
54
140
|
|
|
@@ -58,103 +144,147 @@ Start Pi and run:
|
|
|
58
144
|
|
|
59
145
|
Choose "UvA / HvA proxy", pick a base URL (UvA / HvA / custom), and paste
|
|
60
146
|
your API key. The extension discovers every model and saves your base URL + key
|
|
61
|
-
to
|
|
62
|
-
|
|
147
|
+
to openai-responses-uva.json in Pi's agent dir (~/.pi/agent unless --agent-dir
|
|
148
|
+
or PI_CODING_AGENT_DIR is set), so the next launch reconnects with nothing
|
|
149
|
+
re-entered. /uva-login runs the same flow.
|
|
150
|
+
|
|
151
|
+
Pi only lists the models that actually work for your key. During login, each
|
|
152
|
+
model gets one tiny test request, so login can take up to two minutes. Models
|
|
153
|
+
that return an error (for example a broken deployment on the proxy) are hidden.
|
|
154
|
+
The result is remembered for a day, then checked again in the background when
|
|
155
|
+
you start Pi. Run /login again to re-check right away.
|
|
63
156
|
|
|
64
|
-
> Prefer env vars? Set
|
|
65
|
-
>
|
|
157
|
+
> Prefer env vars? Set UVA_API_KEY (and optionally UVA_BASE_URL) instead of
|
|
158
|
+
> /login. Both work.
|
|
66
159
|
|
|
67
160
|
### 3. Pick a model
|
|
68
161
|
|
|
69
162
|
```
|
|
70
|
-
/
|
|
163
|
+
/model # select an available discovered model
|
|
71
164
|
```
|
|
72
165
|
|
|
73
166
|
Reasoning models default to thinking ON at medium. You can raise or lower a
|
|
74
|
-
model's default in
|
|
167
|
+
model's default in /configure-models, or set the level per run from the CLI:
|
|
75
168
|
|
|
76
169
|
```bash
|
|
77
|
-
pi --provider uva --model gpt-
|
|
170
|
+
pi --provider uva --model gpt-6.1-sol --thinking high -p "hello"
|
|
78
171
|
```
|
|
79
172
|
|
|
80
173
|
## Configuration
|
|
81
174
|
|
|
82
|
-
|
|
175
|
+
/login is the easy path; everything is also configurable via environment
|
|
83
176
|
variables (all optional):
|
|
84
177
|
|
|
85
178
|
| Variable | Default | Purpose |
|
|
86
179
|
| --- | --- | --- |
|
|
87
|
-
|
|
|
88
|
-
|
|
|
89
|
-
|
|
|
90
|
-
|
|
|
91
|
-
|
|
|
92
|
-
|
|
|
180
|
+
| UVA_API_KEY | - | API key, if you prefer env over /login. A saved /login wins when both exist. |
|
|
181
|
+
| UVA_BASE_URL | https://llmproxy.uva.nl/v1 | Proxy base URL (must end at the /v1 root). |
|
|
182
|
+
| UVA_PROVIDER_ID | uva | Provider id shown in /model and --provider. |
|
|
183
|
+
| UVA_CREDENTIALS_FILE | `<agent dir>/openai-responses-uva.json` | Override the saved-credentials path. |
|
|
184
|
+
| UVA_NO_AUTO_THINKING | - | Set to disable the medium thinking default. |
|
|
185
|
+
| UVA_MODEL_OVERRIDES_FILE | - | Path to a JSON file overriding per-model capabilities (below). |
|
|
93
186
|
|
|
94
187
|
### Per-model overrides
|
|
95
188
|
|
|
96
189
|
Capabilities come from the proxy metadata (with a name-table fallback). To pin a
|
|
97
190
|
value yourself there are two ways.
|
|
98
191
|
|
|
99
|
-
Interactive menu (easiest): run
|
|
192
|
+
Interactive menu (easiest): run /configure-models. Pick a model, then set
|
|
100
193
|
its context window and max output (type the number), toggle reasoning on/off,
|
|
101
194
|
and choose the default thinking level applied when that model is selected. Two
|
|
102
195
|
options at the end, Save & apply changes and Discard & exit. Saved
|
|
103
|
-
overrides are written to
|
|
196
|
+
overrides are written to openai-responses-uva.models.json in Pi's agent dir and
|
|
104
197
|
applied live (and on every future launch).
|
|
105
198
|
|
|
106
|
-
By hand: point
|
|
199
|
+
By hand: point UVA_MODEL_OVERRIDES_FILE at a JSON file (this overrides the
|
|
107
200
|
default path above):
|
|
108
201
|
|
|
109
202
|
```json
|
|
110
203
|
{
|
|
111
|
-
"gpt-
|
|
204
|
+
"gpt-6.1-sol": { "contextWindow": 272000, "maxTokens": 128000, "defaultThinkingLevel": "high" },
|
|
112
205
|
"some-new-model": { "reasoning": false, "input": ["text", "image"], "contextWindow": 200000, "maxTokens": 32000 }
|
|
113
206
|
}
|
|
114
207
|
```
|
|
115
208
|
|
|
116
|
-
The
|
|
117
|
-
one model to
|
|
209
|
+
The defaultThinkingLevel on gpt-6.1-sol above is just an example of pinning
|
|
210
|
+
one model to high; by default every reasoning model starts at medium.
|
|
211
|
+
|
|
212
|
+
Each key is a model id; each value may set any of reasoning,
|
|
213
|
+
defaultThinkingLevel (off/low/medium/high/xhigh/max), input, contextWindow,
|
|
214
|
+
maxTokens, vision, name, cost, thinkingLevelMap.
|
|
215
|
+
|
|
216
|
+
### Recommended context window for 1M models
|
|
217
|
+
|
|
218
|
+
Some models can read about one million tokens at once. We cap them at 272k
|
|
219
|
+
(272,000 tokens) in Pi, for two reasons:
|
|
220
|
+
|
|
221
|
+
1. Lower costs. In agentic work every step resends the whole conversation, so
|
|
222
|
+
a huge context gets expensive fast. A cap makes Pi compact the history
|
|
223
|
+
before it grows unnecessarily large.
|
|
224
|
+
2. Better answers. Once the context gets very full, models noticeably get
|
|
225
|
+
worse: they miss details, forget instructions and make more mistakes (the
|
|
226
|
+
"dumb zone"). Staying under 272k keeps the model in the range where it
|
|
227
|
+
still works well.
|
|
228
|
+
|
|
229
|
+
The model can still handle more; 272k is just the working limit we chose.
|
|
230
|
+
|
|
231
|
+
To set it, run /configure-models in Pi, select your model, set Context window
|
|
232
|
+
to 272000, then choose Save & apply changes. Leave Max output tokens and the
|
|
233
|
+
other settings unchanged. Only do this for 1M models; don't raise smaller
|
|
234
|
+
models to 272k.
|
|
235
|
+
|
|
236
|
+
To configure it by hand, merge the following into
|
|
237
|
+
openai-responses-uva.models.json in Pi's agent dir (or your
|
|
238
|
+
UVA_MODEL_OVERRIDES_FILE), preserving all other models and settings:
|
|
239
|
+
|
|
240
|
+
```json
|
|
241
|
+
{
|
|
242
|
+
"YOUR_DISCOVERED_1M_MODEL_ID": { "contextWindow": 272000 }
|
|
243
|
+
}
|
|
244
|
+
```
|
|
118
245
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
246
|
+
Replace the placeholder with an actual model ID from your proxy. Restart Pi
|
|
247
|
+
after a manual file edit; the interactive menu applies its changes live.
|
|
248
|
+
/configure-models belongs to this provider, not to all Pi providers. For other
|
|
249
|
+
providers, use their documented context override mechanism; Pi also supports
|
|
250
|
+
per-provider modelOverrides in ~/.pi/agent/models.json. A
|
|
251
|
+
contextWindow field in the general settings.json is not the equivalent.
|
|
122
252
|
|
|
123
253
|
## How it works
|
|
124
254
|
|
|
125
255
|
For each turn the custom stream handler:
|
|
126
256
|
|
|
127
|
-
1. Lets Pi's pristine built-in
|
|
257
|
+
1. Lets Pi's pristine built-in openai-responses handler build the exact
|
|
128
258
|
request params (full message + tool conversion, reasoning, caching) via an
|
|
129
|
-
|
|
259
|
+
onPayload hook that captures the params and throws before the network
|
|
130
260
|
call, so nothing extra is billed.
|
|
131
261
|
2. Reissues the request itself and synthesizes Pi's content events
|
|
132
|
-
(
|
|
133
|
-
with the terminal
|
|
262
|
+
(text / thinking / toolCall), reconciling the incremental SSE events
|
|
263
|
+
with the terminal response.output[] by item id so a collapsed tool call is
|
|
134
264
|
never lost. Tool-call ids and signatures are preserved for multi-turn replay.
|
|
135
265
|
|
|
136
266
|
Two dispatch paths keep it reliable:
|
|
137
267
|
|
|
138
|
-
- Non-reasoning turns stream (
|
|
268
|
+
- Non-reasoning turns stream (stream:true): bytes flow, so the nginx
|
|
139
269
|
gateway read-timeout keeps resetting and output is token-by-token.
|
|
140
|
-
- Reasoning turns use background + poll (
|
|
141
|
-
|
|
270
|
+
- Reasoning turns use background + poll (background:true +
|
|
271
|
+
GET /responses/{id}): the model can buffer its whole reasoning phase with
|
|
142
272
|
zero interim bytes without ever tripping a 504, because each request is short.
|
|
143
273
|
A streaming turn that still hits a gateway 5xx before any output falls back to
|
|
144
274
|
this path automatically.
|
|
145
275
|
|
|
146
|
-
Params incompatible with non-OpenAI backends (
|
|
276
|
+
Params incompatible with non-OpenAI backends (prompt_cache_key on
|
|
147
277
|
Bedrock/Vertex) are stripped per-model.
|
|
148
278
|
|
|
149
279
|
### Robust to model changes
|
|
150
280
|
|
|
151
281
|
The UvA/HvA line-up changes often, so nothing about specific models is
|
|
152
282
|
hard-coded. On connect the extension reads the proxy's own
|
|
153
|
-
|
|
283
|
+
/model_group/info and derives each model's context window, max output,
|
|
154
284
|
reasoning/vision support, cost, and backend directly from it, then decides the
|
|
155
|
-
endpoint from the backend (
|
|
156
|
-
open-weight
|
|
157
|
-
endpoint is ever unavailable it falls back to
|
|
285
|
+
endpoint from the backend (azure/bedrock speak the Responses API;
|
|
286
|
+
open-weight openai/vLLM models use chat-completions). If that metadata
|
|
287
|
+
endpoint is ever unavailable it falls back to /v1/models plus a researched
|
|
158
288
|
name table, and if a model is still mis-routed, a Responses turn that 404s is
|
|
159
289
|
self-healed at runtime (retried on chat-completions and remembered). So even
|
|
160
290
|
if every current model is replaced with new ones, discovery, capabilities, and
|
|
@@ -168,151 +298,97 @@ Non-reasoning turns stream normally.
|
|
|
168
298
|
|
|
169
299
|
## Reasoning models
|
|
170
300
|
|
|
171
|
-
Reasoning is enabled per model from the proxy metadata (
|
|
172
|
-
|
|
173
|
-
Responses route (chat-completions rejects
|
|
301
|
+
Reasoning is enabled per model from the proxy metadata (supports_reasoning or a
|
|
302
|
+
reasoning_effort parameter), with the name table as a fallback, but only on the
|
|
303
|
+
Responses route (chat-completions rejects reasoning_effort alongside tools).
|
|
174
304
|
Reasoning models default to thinking ON at medium (disable with
|
|
175
|
-
|
|
176
|
-
default thinking level, per-id via
|
|
177
|
-
|
|
305
|
+
UVA_NO_AUTO_THINKING=1). Override any model's capabilities, including its
|
|
306
|
+
default thinking level, per-id via UVA_MODEL_OVERRIDES_FILE or
|
|
307
|
+
/configure-models.
|
|
178
308
|
|
|
179
309
|
## Compatibility
|
|
180
310
|
|
|
181
|
-
-
|
|
182
|
-
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
## Recommended extensions
|
|
186
|
-
|
|
187
|
-
Pi becomes far more capable with a few extensions. These are the ones I run
|
|
188
|
-
alongside this provider, grouped by what they do, with install commands below.
|
|
189
|
-
|
|
190
|
-
### Context, memory & compaction
|
|
191
|
-
|
|
192
|
-
These three cover the three layers with one tool each, so nothing overlaps:
|
|
311
|
+
- Tested on Pi 1.7.0.
|
|
312
|
+
- The offline tests (`npm test` in pi/) run on Linux and macOS only.
|
|
313
|
+
- Imports only the extension-facing `@earendil-works/pi-ai/compat` entry, so it
|
|
314
|
+
keeps working across Pi updates (it does not patch node_modules).
|
|
193
315
|
|
|
194
|
-
|
|
195
|
-
| --- | --- | --- |
|
|
196
|
-
| [context-mode](https://github.com/mksglu/context-mode) | Tool output | Offloads large tool/command output into a sandbox and a searchable store so it never floods your context window. |
|
|
197
|
-
| [pi-smart-compact](https://github.com/alpertarhan/pi-smart-compact) | History | Verification-oriented conversation compaction: deterministic extract, then synthesize, then verify what survived. |
|
|
198
|
-
| [gentle-engram](https://github.com/Gentleman-Programming/engram) | Memory | Persistent memory shared across sessions, compactions, and MCP agents. |
|
|
199
|
-
|
|
200
|
-
### Planning, workflows & subagents
|
|
316
|
+
## Pi harness setup
|
|
201
317
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
| [pi-code-planner](https://github.com/m62624/pi-code-planner) | Structured planning, TDD, and Git worktrees for local coding agents. |
|
|
206
|
-
| [@gotgenes/pi-subagents](https://github.com/gotgenes/pi-packages/tree/main/packages/pi-subagents) | In-process sub-agent core with a typed API and lifecycle events. |
|
|
207
|
-
| [@quintinshaw/pi-dynamic-workflows](https://github.com/QuintinShaw/pi-dynamic-workflows) | Fan a task across hundreds of subagents with real model routing and cost accounting. |
|
|
208
|
-
| [@juicesharp/rpiv-workflow](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-workflow) | Chain skills into typed multi-stage workflows with audited state. |
|
|
209
|
-
| [@juicesharp/rpiv-todo](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo) | A live todo overlay for the model that survives `/reload` and compaction. |
|
|
318
|
+
This is a description of a recommended setup, not a
|
|
319
|
+
requirement to install everything just to use the university proxy. The
|
|
320
|
+
[quick setup](#quick-setup) contains the install commands.
|
|
210
321
|
|
|
211
|
-
###
|
|
322
|
+
### Packages
|
|
212
323
|
|
|
213
|
-
|
|
|
324
|
+
| Package | description |
|
|
214
325
|
| --- | --- |
|
|
215
|
-
| [pi-
|
|
216
|
-
| [
|
|
326
|
+
| [pi-uva-hva](https://www.npmjs.com/package/pi-uva-hva) | The UvA/HvA provider documented on this page. |
|
|
327
|
+
| [@narumitw/pi-plan-mode](https://www.npmjs.com/package/@narumitw/pi-plan-mode) | Read-only planning before the agent edits anything. |
|
|
328
|
+
| [pi-ask-user](https://www.npmjs.com/package/pi-ask-user) | The agent asks a structured question instead of guessing when a task is unclear. |
|
|
329
|
+
| [pi-btw](https://www.npmjs.com/package/pi-btw) | Ask a side question without interrupting the running task. |
|
|
330
|
+
| [@dietrichgebert/ponytail](https://www.npmjs.com/package/@dietrichgebert/ponytail) | Keeps changes small and readable, so you can understand and explain the code. |
|
|
331
|
+
| [pi-markdown-preview](https://www.npmjs.com/package/pi-markdown-preview) | Render Markdown/LaTeX and export previews. |
|
|
332
|
+
|
|
333
|
+
### Skills
|
|
334
|
+
|
|
335
|
+
Skills are reusable instructions that the agent loads when a task matches. We
|
|
336
|
+
recommend installing all of Matt Pocock's
|
|
337
|
+
[skills](https://github.com/mattpocock/skills). They help with planning, TDD,
|
|
338
|
+
debugging, review, and writing specs and tickets: for example
|
|
339
|
+
grill-with-docs, tdd, diagnosing-bugs, code-review, to-spec and to-tickets.
|
|
340
|
+
Install all of them globally for Pi with the
|
|
341
|
+
[skills CLI](https://www.npmjs.com/package/skills) (same command on every
|
|
342
|
+
platform):
|
|
217
343
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
| --- | --- |
|
|
222
|
-
| [@juicesharp/rpiv-web-tools](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-web-tools) | Web search + fetch for the model with pluggable providers (Brave, Tavily, Exa, …). |
|
|
223
|
-
| [pi-mcp-adapter](https://github.com/nicobailon/pi-mcp-adapter) | Connect any MCP (Model Context Protocol) server to Pi. |
|
|
224
|
-
| [@amaster.ai/pi-computer-use](https://github.com/TGYD-helige/pi) | Desktop automation via `computer_use_*` tools. |
|
|
225
|
-
| [pi-image-paste](https://github.com/tuanhung303/pi-image-paste) | Turns pasted image paths into first-class image attachments. |
|
|
226
|
-
| [@trevonistrevon/pi-loop](https://github.com/trvon/pi-loop) | Cron/event re-wake loops and background process monitoring. |
|
|
227
|
-
| [@juicesharp/rpiv-ask-user-question](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-ask-user-question) | Lets the model ask you a structured, typed questionnaire instead of guessing. |
|
|
228
|
-
| [@juicesharp/rpiv-advisor](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-advisor) | A second opinion the model can request from a stronger reviewer model. |
|
|
229
|
-
| [@juicesharp/rpiv-args](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-args) | `$1` / `$ARGUMENTS` placeholders and shell substitution in skills. |
|
|
230
|
-
| [@juicesharp/rpiv-i18n](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-i18n) | Localization foundation for the `rpiv-*` skills (`/languages`, `--locale`). |
|
|
231
|
-
|
|
232
|
-
### Code quality
|
|
233
|
-
|
|
234
|
-
| Extension | What it does |
|
|
235
|
-
| --- | --- |
|
|
236
|
-
| [pi-simplify](https://github.com/MattDevy/pi-extensions/tree/main/packages/pi-simplify) | Reviews recently changed code for clarity, consistency, and maintainability. |
|
|
237
|
-
| [ponytail](https://github.com/DietrichGebert/ponytail) | Lazy senior dev mode: stops the agent over-engineering and writes the minimum code that works, with `/ponytail` review/audit/debt commands. |
|
|
344
|
+
```bash
|
|
345
|
+
npx skills@latest add mattpocock/skills -g -a pi -s '*' -y
|
|
346
|
+
```
|
|
238
347
|
|
|
239
|
-
|
|
348
|
+
They are saved in ~/.agents/skills, which Pi reads when it starts. Run
|
|
349
|
+
/skill:setup-matt-pocock-skills once in each repo. To update later, run
|
|
350
|
+
npx skills@latest update -g, and run the add command again to pick up new
|
|
351
|
+
skills. Skills run with the agent's permissions, so read them before you use
|
|
352
|
+
them.
|
|
240
353
|
|
|
241
|
-
|
|
242
|
-
`~/.pi/agent/settings.json` on the next launch, with no manual `npm install`.
|
|
354
|
+
### MCP servers
|
|
243
355
|
|
|
244
|
-
|
|
245
|
-
|
|
356
|
+
These are the public MCP servers we use through Pi's built-in MCP support.
|
|
357
|
+
Merge them into the mcpServers of ~/.pi/agent/mcp.json (it applies to all
|
|
358
|
+
projects; create the file if it does not exist). Check them with pi mcp list,
|
|
359
|
+
then restart Pi or run /reload. If you still have pi-mcp-adapter installed,
|
|
360
|
+
remove it: it replaces the built-in support, and Pi then ignores mcp.json.
|
|
246
361
|
|
|
247
|
-
```
|
|
362
|
+
```json
|
|
248
363
|
{
|
|
249
|
-
"
|
|
250
|
-
"
|
|
251
|
-
"
|
|
252
|
-
"
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
"
|
|
256
|
-
"
|
|
257
|
-
"
|
|
258
|
-
"
|
|
259
|
-
|
|
260
|
-
"npm:glm-vision",
|
|
261
|
-
"npm:@juicesharp/rpiv-web-tools",
|
|
262
|
-
"npm:pi-mcp-adapter",
|
|
263
|
-
"npm:@amaster.ai/pi-computer-use",
|
|
264
|
-
"npm:pi-image-paste",
|
|
265
|
-
"npm:@trevonistrevon/pi-loop",
|
|
266
|
-
"npm:@juicesharp/rpiv-ask-user-question",
|
|
267
|
-
"npm:@juicesharp/rpiv-advisor",
|
|
268
|
-
"npm:@juicesharp/rpiv-args",
|
|
269
|
-
"npm:@juicesharp/rpiv-i18n",
|
|
270
|
-
"npm:pi-simplify",
|
|
271
|
-
"npm:opencode-ponytail"
|
|
272
|
-
]
|
|
364
|
+
"mcpServers": {
|
|
365
|
+
"playwright": { "command": "npx", "args": ["-y", "@playwright/mcp@latest", "--headless"] },
|
|
366
|
+
"deepwiki": { "url": "https://mcp.deepwiki.com/mcp" },
|
|
367
|
+
"context7": { "url": "https://mcp.context7.com/mcp" },
|
|
368
|
+
"parallel-search": { "url": "https://search.parallel.ai/mcp", "exposure": "direct" },
|
|
369
|
+
"github": { "url": "https://api.githubcopilot.com/mcp", "headers": { "Authorization": "!echo Bearer $(gh auth token)" } },
|
|
370
|
+
"shadcn": { "command": "npx", "args": ["-y", "shadcn@latest", "mcp"] },
|
|
371
|
+
"ui-layouts": { "command": "npx", "args": ["-y", "@ui-layouts/mcp@latest"] },
|
|
372
|
+
"lazyweb": { "url": "https://www.lazyweb.com/mcp/public" },
|
|
373
|
+
"avalonia-docs": { "url": "https://docs-mcp.avaloniaui.net/mcp" }
|
|
374
|
+
}
|
|
273
375
|
}
|
|
274
376
|
```
|
|
275
377
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
]
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
- Node ≥ 22.5.0, required by `context-mode`. It stores its knowledge base in
|
|
292
|
-
SQLite and relies on Node's built-in `node:sqlite` (older Node falls back to a
|
|
293
|
-
native module that can crash). Check with `node -v`. Its `postinstall`
|
|
294
|
-
auto-wires the Pi hooks and heals the native binding, so no manual setup is
|
|
295
|
-
needed. Just verify afterward with `/context-mode:ctx-doctor` (or
|
|
296
|
-
`npx context-mode doctor`). If an install ever complains about
|
|
297
|
-
`better-sqlite3`, upgrading Node to 22.5+ is the fix. Known quirk: if you also
|
|
298
|
-
have a `~/.claude` folder, context-mode may store its knowledge base there
|
|
299
|
-
instead of under `~/.pi`; harmless, but that is where to look for it.
|
|
300
|
-
|
|
301
|
-
- `gentle-engram` needs the Engram backend. The npm package is only the Pi
|
|
302
|
-
bridge: persistence is handled by a separate `engram` binary that it launches
|
|
303
|
-
as an MCP server. Install Engram from
|
|
304
|
-
[Gentleman-Programming/engram](https://github.com/Gentleman-Programming/engram)
|
|
305
|
-
and make sure `engram` is on your `PATH` (or set `ENGRAM_BIN`); otherwise the
|
|
306
|
-
memory tools load but nothing is saved. Also keep only one engram entry in
|
|
307
|
-
`packages`: `npm:gentle-engram`, not a second pinned copy like
|
|
308
|
-
`npm:gentle-engram@0.1.8`.
|
|
309
|
-
|
|
310
|
-
> Some of these overlap in purpose. `rpiv-todo` gives the model its `todo`
|
|
311
|
-
> tracker; `pi-loop` also ships a native `TaskCreate` fallback that only
|
|
312
|
-
> activates when no dedicated task system is present, so it just sits unused
|
|
313
|
-
> beside `todo` (harmless, not a conflict). Several planning and workflow
|
|
314
|
-
> engines overlap too. Start with the context/memory group, then add planning
|
|
315
|
-
> and tools as you need them rather than enabling all of them at once.
|
|
378
|
+
| Server | description |
|
|
379
|
+
| --- | --- |
|
|
380
|
+
| [playwright](https://github.com/microsoft/playwright-mcp) | Drive a headless browser to test and inspect web pages. |
|
|
381
|
+
| [deepwiki](https://deepwiki.com) | Ask questions about public GitHub repositories. |
|
|
382
|
+
| [context7](https://context7.com) | Up-to-date library and framework documentation. |
|
|
383
|
+
| [parallel-search](https://parallel.ai) | Web search and page fetching for agents. |
|
|
384
|
+
| [github](https://github.com/github/github-mcp-server) | Issues, pull requests and code on GitHub. Needs the [GitHub CLI](https://cli.github.com) logged in (gh auth login); the token is read at connect time, never stored in the file. Checked on Linux; if the command fails on Windows, set GITHUB_TOKEN and use "Bearer ${GITHUB_TOKEN}" instead. |
|
|
385
|
+
| [shadcn](https://ui.shadcn.com/docs/mcp) | Browse and add shadcn/ui components. |
|
|
386
|
+
| [ui-layouts](https://www.ui-layouts.com) | UI layout and component examples. |
|
|
387
|
+
| [lazyweb](https://www.lazyweb.com) | Real-app UI design references. |
|
|
388
|
+
| [avalonia-docs](https://docs.avaloniaui.net) | Avalonia UI documentation (only for Avalonia/.NET projects). |
|
|
389
|
+
|
|
390
|
+
Keep only the ones you need: each one starts a process or connection and adds
|
|
391
|
+
a line to the system prompt.
|
|
316
392
|
|
|
317
393
|
## License
|
|
318
394
|
|
package/index.ts
CHANGED
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
* ----------
|
|
50
50
|
* Run `/login` (choose "UvA / HvA proxy") or `/uva-login`: pick a base URL
|
|
51
51
|
* (UvA / HvA / custom), paste your API key, and every model is auto-discovered.
|
|
52
|
-
* The base URL + key are saved to
|
|
53
|
-
* next launch reconnects with nothing re-entered. Then
|
|
52
|
+
* The base URL + key are saved to openai-responses-uva.json in Pi's agent dir
|
|
53
|
+
* so the next launch reconnects with nothing re-entered. Then use /models.
|
|
54
54
|
*
|
|
55
55
|
* Reasoning models default to thinking ON at medium
|
|
56
56
|
* (set UVA_NO_AUTO_THINKING=1 to disable this; change any model's default in
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
* UVA_CREDENTIALS_FILE Override the saved-credentials path.
|
|
65
65
|
* UVA_NO_AUTO_THINKING Set to disable the medium thinking default.
|
|
66
66
|
*
|
|
67
|
-
* Only imports
|
|
68
|
-
*
|
|
67
|
+
* Only imports "@earendil-works/pi-ai/compat" (the extension-facing surface),
|
|
68
|
+
* so it works under Pi's jiti extension loader.
|
|
69
69
|
*/
|
|
70
70
|
|
|
71
|
-
import type
|
|
72
|
-
import { getApiProvider, createAssistantMessageEventStream, calculateCost } from "@earendil-works/pi-ai";
|
|
71
|
+
import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
72
|
+
import { getApiProvider, createAssistantMessageEventStream, calculateCost } from "@earendil-works/pi-ai/compat";
|
|
73
73
|
|
|
74
74
|
const BASE_API = "openai-responses"; // pristine built-in handler we delegate to
|
|
75
75
|
const CUSTOM_API = "openai-responses-uva"; // our fixed handler is registered under this
|
|
@@ -84,15 +84,15 @@ const PROVIDER_ID = process.env.UVA_PROVIDER_ID || "uva";
|
|
|
84
84
|
// Active connection settings. Seeded from env, overridden by saved credentials
|
|
85
85
|
// (from the /login flow) at startup, and updated live on login.
|
|
86
86
|
let activeBaseUrl = (process.env.UVA_BASE_URL || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
87
|
-
let activeApiKey: string | undefined = process.env.UVA_API_KEY
|
|
87
|
+
let activeApiKey: string | undefined = process.env.UVA_API_KEY;
|
|
88
|
+
let savedApiKey: string | undefined;
|
|
88
89
|
|
|
89
90
|
// Persisted login (base URL + API key) so model discovery works at the next
|
|
90
91
|
// startup with nothing re-entered. Path overridable via UVA_CREDENTIALS_FILE.
|
|
91
92
|
function credsFile(): string {
|
|
92
93
|
if (process.env.UVA_CREDENTIALS_FILE) return process.env.UVA_CREDENTIALS_FILE;
|
|
93
|
-
const os = require("node:os");
|
|
94
94
|
const { join } = require("node:path");
|
|
95
|
-
return join(
|
|
95
|
+
return join(getAgentDir(), "openai-responses-uva.json");
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function loadCreds(): { baseUrl?: string; apiKey?: string } | null {
|
|
@@ -119,10 +119,10 @@ function saveCreds(creds: { baseUrl: string; apiKey: string }): void {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
// Models that are not chat/response models, never register these.
|
|
122
|
-
const DENY = /embedding|whisper|audio|tts|speech|dall|(^|[-_])image|document-ai|ocr|rerank|moderation|guard|stable-diffusion/i;
|
|
122
|
+
const DENY = /embedding|whisper|audio|tts|speech|dall|(^|[-_])image|document-ai|ocr|rerank|moderation|guard|stable-diffusion|batch/i;
|
|
123
123
|
|
|
124
124
|
// Known-good fallback if /v1/models discovery fails.
|
|
125
|
-
const FALLBACK_MODEL_IDS = ["gpt-
|
|
125
|
+
const FALLBACK_MODEL_IDS = ["gpt-6.2-astra", "gpt-6.2-sol", "gpt-6.1-sol", "gpt-6-sol", "gpt-6-luna", "gpt-5.6-sol", "gpt-4.1"];
|
|
126
126
|
|
|
127
127
|
// ---------------------------------------------------------------------------
|
|
128
128
|
// FALLBACK capability table.
|
|
@@ -144,8 +144,10 @@ const FALLBACK_MODEL_IDS = ["gpt-5.6-sol", "gpt-5.6-luna", "gpt-5.5", "gpt-5.1",
|
|
|
144
144
|
type Caps = { ctx: number; out: number; reasoning: boolean; vision: boolean };
|
|
145
145
|
|
|
146
146
|
const CAPS: Array<{ re: RegExp; caps: Caps }> = [
|
|
147
|
+
// OpenAI GPT-6 (astra / sol / luna) and later
|
|
148
|
+
{ re: /^gpt-[6-9]/i, caps: { ctx: 1_050_000, out: 128_000, reasoning: true, vision: true } },
|
|
147
149
|
// OpenAI GPT-5.x
|
|
148
|
-
{ re: /^gpt-5\.6/i, caps: { ctx:
|
|
150
|
+
{ re: /^gpt-5\.6/i, caps: { ctx: 1_050_000, out: 128_000, reasoning: true, vision: true } },
|
|
149
151
|
{ re: /^gpt-5\.[45]/i, caps: { ctx: 1_050_000, out: 128_000, reasoning: true, vision: true } },
|
|
150
152
|
{ re: /^gpt-5\.1/i, caps: { ctx: 400_000, out: 128_000, reasoning: true, vision: true } },
|
|
151
153
|
{ re: /^gpt-5(-|$)/i, caps: { ctx: 400_000, out: 128_000, reasoning: true, vision: true } }, // gpt-5 / -mini / -nano
|
|
@@ -185,13 +187,23 @@ const REASONING_THINKING_MAP = {
|
|
|
185
187
|
max: null,
|
|
186
188
|
} as const;
|
|
187
189
|
|
|
190
|
+
// GPT-5.6 / GPT-6 accept none/low/medium/high/xhigh/max (verified on the HvA
|
|
191
|
+
// proxy; "minimal" is rejected), so expose xhigh + max for them. Pi sends
|
|
192
|
+
// effort "none" for thinking=off; OpenAI docs: GPT-6 Astra rejects "none", so
|
|
193
|
+
// off:null hides "off" for Astra and Pi clamps it up to "low".
|
|
194
|
+
function thinkingMapFor(id: string) {
|
|
195
|
+
if (!/^gpt-(5\.6|[6-9])/i.test(id)) return REASONING_THINKING_MAP;
|
|
196
|
+
const map = { ...REASONING_THINKING_MAP, xhigh: "xhigh", max: "max" };
|
|
197
|
+
return /astra/i.test(id) ? { ...map, off: null } : map;
|
|
198
|
+
}
|
|
199
|
+
|
|
188
200
|
// Endpoint routing. Some models speak the OpenAI Responses API (/v1/responses);
|
|
189
201
|
// open-weight vLLM deployments only speak /v1/chat/completions and 404 on
|
|
190
202
|
// /responses. We derive this from the proxy's own /model_group/info metadata
|
|
191
203
|
// (backend `providers`), fall back to a name regex when metadata is absent, and
|
|
192
204
|
// SELF-HEAL at runtime: a Responses turn that 404s is retried on
|
|
193
205
|
// chat-completions and the id is remembered for the rest of the session.
|
|
194
|
-
const RESPONSES_CAPABLE = /^(gpt-4|gpt-5|o[0-9]|claude|model-router|grok|gemini)/i;
|
|
206
|
+
const RESPONSES_CAPABLE = /^(gpt-4|gpt-[5-9]|o[0-9]|claude|model-router|grok|gemini)/i;
|
|
195
207
|
const RESPONSES_PROVIDERS = /azure|bedrock|vertex|anthropic|openai_responses/i;
|
|
196
208
|
|
|
197
209
|
// The model defs from the most recent registration (for the /configure-models
|
|
@@ -202,9 +214,15 @@ let currentModels: any[] = [];
|
|
|
202
214
|
const modelRoutes = new Map<string, "responses" | "chat">();
|
|
203
215
|
// Runtime self-heal overrides (win over modelRoutes, survive re-registration).
|
|
204
216
|
const routeOverrides = new Map<string, "responses" | "chat">();
|
|
217
|
+
// Ids whose deployment answered 400 to effort "none" this session.
|
|
218
|
+
const noneRejected = new Set<string>();
|
|
205
219
|
|
|
206
220
|
function routeForModel(id: string, providers?: string[]): "responses" | "chat" {
|
|
207
221
|
if (routeOverrides.has(id)) return routeOverrides.get(id)!;
|
|
222
|
+
// GPT-6 always goes to /responses, even if the backend is reported as plain
|
|
223
|
+
// "openai": per OpenAI docs its tool calling only works there. A 404 there
|
|
224
|
+
// still self-heals to chat.
|
|
225
|
+
if (/^gpt-[6-9]/i.test(id)) return "responses";
|
|
208
226
|
if (providers && providers.length) {
|
|
209
227
|
return providers.some((p) => RESPONSES_PROVIDERS.test(p)) ? "responses" : "chat";
|
|
210
228
|
}
|
|
@@ -218,8 +236,8 @@ function currentRoute(id: string): "responses" | "chat" {
|
|
|
218
236
|
function resolveCaps(id: string): Caps {
|
|
219
237
|
for (const { re, caps } of CAPS) if (re.test(id)) return caps;
|
|
220
238
|
// Unknown / future model: infer conservatively.
|
|
221
|
-
const reasoning = /gpt-5|gpt-oss/i.test(id) || /^o[134](-|$)/i.test(id);
|
|
222
|
-
const vision = /gpt-4
|
|
239
|
+
const reasoning = /gpt-[5-9]|gpt-oss/i.test(id) || /^o[134](-|$)/i.test(id);
|
|
240
|
+
const vision = /gpt-[4-9]|claude|gemini|vl|vision|nova/i.test(id);
|
|
223
241
|
return { ctx: reasoning ? 400_000 : 128_000, out: reasoning ? 128_000 : 16_384, reasoning, vision };
|
|
224
242
|
}
|
|
225
243
|
|
|
@@ -252,18 +270,17 @@ function buildModelDef(info: ModelInfo, overrides: Record<string, any>) {
|
|
|
252
270
|
cost,
|
|
253
271
|
contextWindow: ctx,
|
|
254
272
|
maxTokens: out,
|
|
255
|
-
...(reasoning ? { thinkingLevelMap: ov.thinkingLevelMap ||
|
|
273
|
+
...(reasoning ? { thinkingLevelMap: ov.thinkingLevelMap || thinkingMapFor(id) } : {}),
|
|
256
274
|
};
|
|
257
275
|
}
|
|
258
276
|
|
|
259
277
|
// Per-id capability overrides (context window, reasoning, default thinking
|
|
260
278
|
// level, ...) written by the /configure-models menu. Path is
|
|
261
|
-
// UVA_MODEL_OVERRIDES_FILE or
|
|
279
|
+
// UVA_MODEL_OVERRIDES_FILE or <agent dir>/openai-responses-uva.models.json.
|
|
262
280
|
function overridesFile(): string {
|
|
263
281
|
if (process.env.UVA_MODEL_OVERRIDES_FILE) return process.env.UVA_MODEL_OVERRIDES_FILE;
|
|
264
|
-
const os = require("node:os");
|
|
265
282
|
const { join } = require("node:path");
|
|
266
|
-
return join(
|
|
283
|
+
return join(getAgentDir(), "openai-responses-uva.models.json");
|
|
267
284
|
}
|
|
268
285
|
|
|
269
286
|
function loadOverrides(): Record<string, any> {
|
|
@@ -343,19 +360,27 @@ async function fetchModelInfos(apiKey: string | undefined, baseUrl: string): Pro
|
|
|
343
360
|
return infos;
|
|
344
361
|
}
|
|
345
362
|
|
|
346
|
-
// Fallback discovery: /v1/models returns ids only
|
|
347
|
-
|
|
363
|
+
// Fallback discovery: /v1/models. Plain OpenAI returns ids only; LiteLLM also
|
|
364
|
+
// adds mode and token limits, which we keep when present (keys that may not
|
|
365
|
+
// call /model_group/info, e.g. on the HvA proxy, still get real limits).
|
|
366
|
+
async function fetchModelIds(apiKey: string | undefined, baseUrl: string): Promise<ModelInfo[]> {
|
|
348
367
|
const root = baseUrl.replace(/\/+$/, "");
|
|
349
368
|
const res = await fetch(`${root}/models`, {
|
|
350
369
|
headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
|
|
351
370
|
});
|
|
352
371
|
if (!res.ok) throw new Error(`GET ${root}/models -> HTTP ${res.status}`);
|
|
353
372
|
const data: any = await res.json();
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
.filter((
|
|
357
|
-
|
|
358
|
-
|
|
373
|
+
const num = (v: any) => (typeof v === "number" && v > 0 ? v : 0);
|
|
374
|
+
const infos: ModelInfo[] = (Array.isArray(data?.data) ? data.data : [])
|
|
375
|
+
.filter((m: any) => typeof m?.id === "string" && m.id.length > 0)
|
|
376
|
+
.map((m: any) => ({
|
|
377
|
+
id: m.id,
|
|
378
|
+
mode: typeof m.mode === "string" ? m.mode : "",
|
|
379
|
+
ctx: num(m.max_input_tokens),
|
|
380
|
+
out: num(m.max_output_tokens),
|
|
381
|
+
}));
|
|
382
|
+
if (infos.length === 0) throw new Error("no models returned by /v1/models");
|
|
383
|
+
return infos;
|
|
359
384
|
}
|
|
360
385
|
|
|
361
386
|
// Layered discovery: rich metadata first, ids-only fallback. Throws only if
|
|
@@ -369,8 +394,7 @@ async function discoverModels(apiKey: string | undefined, baseUrl: string): Prom
|
|
|
369
394
|
`[openai-responses-uva] /model_group/info unavailable (${err instanceof Error ? err.message : String(err)}); falling back to /v1/models.`,
|
|
370
395
|
);
|
|
371
396
|
}
|
|
372
|
-
|
|
373
|
-
return ids.map((id) => ({ id }));
|
|
397
|
+
return fetchModelIds(apiKey, baseUrl);
|
|
374
398
|
}
|
|
375
399
|
|
|
376
400
|
// ---------------------------------------------------------------------------
|
|
@@ -791,8 +815,14 @@ async function runBackgroundPoll(
|
|
|
791
815
|
}
|
|
792
816
|
throw new Error(`openai-responses-uva: HTTP ${res.status}: ${text.slice(0, 200).replace(/\s+/g, " ")}`);
|
|
793
817
|
}
|
|
818
|
+
// Bedrock ignores background, answers finished and 500s on GET.
|
|
819
|
+
let terminal: any = data?.status === "completed" || data?.status === "incomplete" ? data : null;
|
|
820
|
+
if (data?.status === "failed" || data?.status === "cancelled") {
|
|
821
|
+
const e = data.error;
|
|
822
|
+
throw new Error(`openai-responses-uva: background ${data.status}: ${e?.message || e?.code || "no message"}`);
|
|
823
|
+
}
|
|
794
824
|
const id = data?.id;
|
|
795
|
-
if (!id) throw new Error("openai-responses-uva: background response missing id");
|
|
825
|
+
if (!id && !terminal) throw new Error("openai-responses-uva: background response missing id");
|
|
796
826
|
|
|
797
827
|
state.started = true;
|
|
798
828
|
out.push({ type: "start", partial: output });
|
|
@@ -802,8 +832,7 @@ async function runBackgroundPoll(
|
|
|
802
832
|
const deadline = Date.now() + 15 * 60 * 1000; // 15 min hard cap
|
|
803
833
|
let delay = 1500;
|
|
804
834
|
let getFails = 0;
|
|
805
|
-
|
|
806
|
-
while (true) {
|
|
835
|
+
while (!terminal) {
|
|
807
836
|
if (signal?.aborted) throw new Error("openai-responses-uva: aborted");
|
|
808
837
|
await sleep(delay);
|
|
809
838
|
let g: any;
|
|
@@ -858,7 +887,20 @@ function chatDelegate(model: any, context: any, options: any): any {
|
|
|
858
887
|
error: {
|
|
859
888
|
role: "assistant",
|
|
860
889
|
content: [],
|
|
890
|
+
api: model.api,
|
|
891
|
+
provider: model.provider,
|
|
892
|
+
model: model.id,
|
|
893
|
+
usage: {
|
|
894
|
+
input: 0,
|
|
895
|
+
output: 0,
|
|
896
|
+
cacheRead: 0,
|
|
897
|
+
cacheWrite: 0,
|
|
898
|
+
reasoning: 0,
|
|
899
|
+
totalTokens: 0,
|
|
900
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
901
|
+
},
|
|
861
902
|
stopReason: "error",
|
|
903
|
+
timestamp: Date.now(),
|
|
862
904
|
errorMessage: "openai-responses-uva: openai-completions handler unavailable",
|
|
863
905
|
},
|
|
864
906
|
});
|
|
@@ -916,11 +958,13 @@ function uvaStreamSimple(model: any, context: any, options: any): any {
|
|
|
916
958
|
if (next !== undefined) params = next;
|
|
917
959
|
}
|
|
918
960
|
|
|
919
|
-
const apiKey = options?.apiKey || activeApiKey || process.env.UVA_API_KEY
|
|
961
|
+
const apiKey = options?.apiKey || activeApiKey || process.env.UVA_API_KEY;
|
|
920
962
|
if (!apiKey) throw new Error("openai-responses-uva: no API key (run /login or set UVA_API_KEY)");
|
|
921
963
|
const url = String(model.baseUrl || activeBaseUrl).replace(/\/+$/, "") + "/responses";
|
|
922
964
|
|
|
923
965
|
const state = { started: false };
|
|
966
|
+
const low = { ...params, reasoning: { ...params.reasoning, effort: "low" } };
|
|
967
|
+
if (params?.reasoning?.effort === "none" && noneRejected.has(model.id)) params = low;
|
|
924
968
|
const effort = params?.reasoning?.effort;
|
|
925
969
|
// Reasoning turns buffer server-side (the proxy sends no interim bytes
|
|
926
970
|
// while the model thinks) and can 504 mid-stream. Route them straight to
|
|
@@ -943,6 +987,10 @@ function uvaStreamSimple(model: any, context: any, options: any): any {
|
|
|
943
987
|
// retrying the same doomed stream.
|
|
944
988
|
if (!state.started && gateway && !options?.signal?.aborted) {
|
|
945
989
|
await runBackgroundPoll(url, apiKey, params, out, output, model, options?.signal, options?.onResponse, state);
|
|
990
|
+
} else if (status === 400 && effort === "none" && /'none' is not supported/.test(err?.message)) {
|
|
991
|
+
// Some deployments (gpt-6.1-sol) reject "none"; "low" is the floor.
|
|
992
|
+
noneRejected.add(model.id);
|
|
993
|
+
await runBackgroundPoll(url, apiKey, low, out, output, model, options?.signal, options?.onResponse, state);
|
|
946
994
|
} else {
|
|
947
995
|
throw err;
|
|
948
996
|
}
|
|
@@ -956,10 +1004,11 @@ function uvaStreamSimple(model: any, context: any, options: any): any {
|
|
|
956
1004
|
out.end();
|
|
957
1005
|
} catch (error) {
|
|
958
1006
|
const msg = error instanceof Error ? error.message : String(error);
|
|
959
|
-
// Self-heal: this model isn't on /responses (proxy 404 / "not found"
|
|
1007
|
+
// Self-heal: this model isn't on /responses (proxy 404 / "not found", or
|
|
1008
|
+
// an Azure deployment whose api-version predates the Responses API).
|
|
960
1009
|
// Remember it as chat-only and reissue this turn on chat-completions.
|
|
961
1010
|
const notOnResponses =
|
|
962
|
-
(error as any)?.status === 404 || /HTTP 404|not found|does not exist|no model group|NotFound/i.test(msg);
|
|
1011
|
+
(error as any)?.status === 404 || /HTTP 404|not found|does not exist|no model group|NotFound|Responses API is enabled only/i.test(msg);
|
|
963
1012
|
if (notOnResponses && output.content.length === 0 && !options?.signal?.aborted) {
|
|
964
1013
|
routeOverrides.set(model.id, "chat");
|
|
965
1014
|
try {
|
|
@@ -1004,12 +1053,106 @@ async function buildModels(apiKey: string | undefined, baseUrl: string): Promise
|
|
|
1004
1053
|
.map((info) => buildModelDef(info, overrides));
|
|
1005
1054
|
}
|
|
1006
1055
|
|
|
1056
|
+
// ---------------------------------------------------------------------------
|
|
1057
|
+
// Health check: only list models that actually answer.
|
|
1058
|
+
//
|
|
1059
|
+
// The proxy lists every deployment, including ones that are misconfigured
|
|
1060
|
+
// upstream (e.g. HvA's gpt-5 / gpt-5.5 return 500s on both endpoints). We send
|
|
1061
|
+
// each model one tiny request on the route we would use, retry on chat when
|
|
1062
|
+
// /responses is not enabled for it, and hide models that give a definite error.
|
|
1063
|
+
// Timeouts and 429s keep the model (slow != broken). Results are cached per
|
|
1064
|
+
// base URL for a day; /login always re-checks.
|
|
1065
|
+
// ponytail: one sample per model, so a model that fails intermittently can be
|
|
1066
|
+
// hidden (or shown) until the next check; sample more if that bites.
|
|
1067
|
+
// ---------------------------------------------------------------------------
|
|
1068
|
+
|
|
1069
|
+
const PROBE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
1070
|
+
type ProbeCache = { baseUrl: string; at: number; broken: string[]; chat: string[] };
|
|
1071
|
+
|
|
1072
|
+
function probeFile(): string {
|
|
1073
|
+
return credsFile().replace(/\.json$/, "") + ".health.json";
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
function loadProbe(baseUrl: string): ProbeCache | null {
|
|
1077
|
+
try {
|
|
1078
|
+
const { readFileSync } = require("node:fs");
|
|
1079
|
+
const c = JSON.parse(readFileSync(probeFile(), "utf8"));
|
|
1080
|
+
return c?.baseUrl === baseUrl && Date.now() - c.at < PROBE_TTL_MS ? c : null;
|
|
1081
|
+
} catch {
|
|
1082
|
+
return null;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// "ok" | "chat" (works, but only on chat-completions) | "broken"
|
|
1087
|
+
async function probeOne(apiKey: string, baseUrl: string, id: string): Promise<"ok" | "chat" | "broken"> {
|
|
1088
|
+
const call = async (path: string, body: any): Promise<{ status: number; text: string } | null> => {
|
|
1089
|
+
try {
|
|
1090
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
1091
|
+
method: "POST",
|
|
1092
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
1093
|
+
body: JSON.stringify({ model: id, ...body }),
|
|
1094
|
+
// The proxy gateway answers 504 by ~90s, so this rarely fires.
|
|
1095
|
+
signal: AbortSignal.timeout(100_000),
|
|
1096
|
+
});
|
|
1097
|
+
return { status: res.status, text: await res.text() };
|
|
1098
|
+
} catch {
|
|
1099
|
+
return null; // timeout / network: unknown, keep the model
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
const failed = (r: { status: number } | null) => !!r && r.status >= 400 && r.status !== 429;
|
|
1103
|
+
const chatBody = { messages: [{ role: "user", content: "hi" }], max_tokens: 16 };
|
|
1104
|
+
|
|
1105
|
+
if (currentRoute(id) === "chat") return failed(await call("/chat/completions", chatBody)) ? "broken" : "ok";
|
|
1106
|
+
const r = await call("/responses", { input: "hi", max_output_tokens: 16 });
|
|
1107
|
+
if (!failed(r)) return "ok";
|
|
1108
|
+
if (!/Responses API is enabled only|not found|does not exist|NotFound/i.test(r!.text)) return "broken";
|
|
1109
|
+
return failed(await call("/chat/completions", chatBody)) ? "broken" : "chat";
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
async function probeModels(apiKey: string, baseUrl: string, ids: string[]): Promise<ProbeCache> {
|
|
1113
|
+
const results = await Promise.all(ids.map((id) => probeOne(apiKey, baseUrl, id)));
|
|
1114
|
+
const cache: ProbeCache = {
|
|
1115
|
+
baseUrl,
|
|
1116
|
+
at: Date.now(),
|
|
1117
|
+
broken: ids.filter((_, i) => results[i] === "broken"),
|
|
1118
|
+
chat: ids.filter((_, i) => results[i] === "chat"),
|
|
1119
|
+
};
|
|
1120
|
+
try {
|
|
1121
|
+
const { writeFileSync, mkdirSync } = require("node:fs");
|
|
1122
|
+
const { dirname } = require("node:path");
|
|
1123
|
+
mkdirSync(dirname(probeFile()), { recursive: true });
|
|
1124
|
+
writeFileSync(probeFile(), JSON.stringify(cache, null, 2));
|
|
1125
|
+
} catch {
|
|
1126
|
+
/* cache is best-effort */
|
|
1127
|
+
}
|
|
1128
|
+
return cache;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
// Discover, then drop broken models and pin chat-only ones (from the cache, or a
|
|
1132
|
+
// fresh probe when `probe` is set).
|
|
1133
|
+
async function buildWorkingModels(apiKey: string | undefined, baseUrl: string, probe: boolean): Promise<any[]> {
|
|
1134
|
+
let health = loadProbe(baseUrl);
|
|
1135
|
+
if (health) for (const id of health.chat) routeOverrides.set(id, "chat");
|
|
1136
|
+
let models = await buildModels(apiKey, baseUrl);
|
|
1137
|
+
if (probe && apiKey) {
|
|
1138
|
+
health = await probeModels(apiKey, baseUrl, models.map((m) => m.id));
|
|
1139
|
+
for (const id of health.chat) routeOverrides.set(id, "chat");
|
|
1140
|
+
models = await buildModels(apiKey, baseUrl);
|
|
1141
|
+
}
|
|
1142
|
+
const broken = new Set(health?.broken ?? []);
|
|
1143
|
+
return models.filter((m) => !broken.has(m.id));
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
let registrations = 0;
|
|
1147
|
+
|
|
1007
1148
|
function registerProviderNow(pi: ExtensionAPI, models: any[], baseUrl: string): void {
|
|
1149
|
+
registrations++;
|
|
1008
1150
|
currentModels = models;
|
|
1009
1151
|
pi.registerProvider(PROVIDER_ID, {
|
|
1010
1152
|
name: "UvA / HvA (Responses fix)",
|
|
1011
1153
|
baseUrl: baseUrl.replace(/\/+$/, ""),
|
|
1012
|
-
|
|
1154
|
+
// Pi reads "$" as an env reference and a leading "!" as a shell command.
|
|
1155
|
+
apiKey: savedApiKey ? savedApiKey.replace(/[$!]/g, "$$$&") : "$UVA_API_KEY",
|
|
1013
1156
|
api: CUSTOM_API,
|
|
1014
1157
|
models,
|
|
1015
1158
|
streamSimple: uvaStreamSimple as any,
|
|
@@ -1051,13 +1194,15 @@ function makeOAuth(pi: ExtensionAPI) {
|
|
|
1051
1194
|
const apiKey = key.trim();
|
|
1052
1195
|
|
|
1053
1196
|
callbacks.onProgress?.("Discovering models…");
|
|
1054
|
-
|
|
1055
|
-
callbacks.onProgress?.(
|
|
1197
|
+
await discoverModels(apiKey, baseUrl); // throws on a bad key/url -> login fails
|
|
1198
|
+
callbacks.onProgress?.("Checking which models work (can take up to 2 minutes)\u2026");
|
|
1199
|
+
const models = await buildWorkingModels(apiKey, baseUrl, true);
|
|
1200
|
+
callbacks.onProgress?.(`Connected, ${models.length} working models available.`);
|
|
1056
1201
|
|
|
1057
1202
|
saveCreds({ baseUrl, apiKey });
|
|
1058
|
-
activeApiKey = apiKey;
|
|
1203
|
+
activeApiKey = savedApiKey = apiKey;
|
|
1059
1204
|
activeBaseUrl = baseUrl;
|
|
1060
|
-
registerProviderNow(pi,
|
|
1205
|
+
registerProviderNow(pi, models, baseUrl);
|
|
1061
1206
|
|
|
1062
1207
|
return {
|
|
1063
1208
|
access: apiKey,
|
|
@@ -1139,7 +1284,7 @@ async function configureOneModel(ctx: any, id: string, draft: Record<string, any
|
|
|
1139
1284
|
const v = await ctx.ui.select(`${id} - reasoning (thinking) support`, ["on", "off"]);
|
|
1140
1285
|
if (v) ov.reasoning = v === "on";
|
|
1141
1286
|
} else if (pick.startsWith("Default thinking")) {
|
|
1142
|
-
const v = await ctx.ui.select(`${id} - default thinking level when selected`, ["off", "low", "medium", "high"]);
|
|
1287
|
+
const v = await ctx.ui.select(`${id} - default thinking level when selected`, ["off", "low", "medium", "high", "xhigh", "max"]);
|
|
1143
1288
|
if (v) ov.defaultThinkingLevel = v;
|
|
1144
1289
|
} else if (pick.startsWith("Vision")) {
|
|
1145
1290
|
const v = await ctx.ui.select(`${id} - vision (image input)`, ["on", "off"]);
|
|
@@ -1151,13 +1296,29 @@ async function configureOneModel(ctx: any, id: string, draft: Record<string, any
|
|
|
1151
1296
|
export default async function (pi: ExtensionAPI): Promise<void> {
|
|
1152
1297
|
const creds = loadCreds();
|
|
1153
1298
|
if (creds?.baseUrl) activeBaseUrl = String(creds.baseUrl).replace(/\/+$/, "");
|
|
1154
|
-
if (creds?.apiKey) activeApiKey = creds.apiKey;
|
|
1155
|
-
|
|
1156
|
-
registerProviderNow(pi, await
|
|
1299
|
+
if (typeof creds?.apiKey === "string" && creds.apiKey) activeApiKey = savedApiKey = creds.apiKey;
|
|
1300
|
+
|
|
1301
|
+
registerProviderNow(pi, await buildWorkingModels(activeApiKey, activeBaseUrl, false), activeBaseUrl);
|
|
1302
|
+
|
|
1303
|
+
// No recent health check: run it in the background (interactive only, so
|
|
1304
|
+
// `pi -p` doesn't wait on it), then re-register with the working models.
|
|
1305
|
+
pi.on("session_start", (event: any, ctx: any) => {
|
|
1306
|
+
if (event?.reason !== "startup" || !ctx?.hasUI || !activeApiKey || loadProbe(activeBaseUrl)) return;
|
|
1307
|
+
const baseUrl = activeBaseUrl;
|
|
1308
|
+
const seen = registrations;
|
|
1309
|
+
buildWorkingModels(activeApiKey, baseUrl, true)
|
|
1310
|
+
.then((models) => {
|
|
1311
|
+
// /login or /configure-models may have re-registered meanwhile.
|
|
1312
|
+
if (baseUrl === activeBaseUrl && seen === registrations) registerProviderNow(pi, models, baseUrl);
|
|
1313
|
+
})
|
|
1314
|
+
.catch(() => {});
|
|
1315
|
+
});
|
|
1157
1316
|
|
|
1158
|
-
//
|
|
1159
|
-
|
|
1160
|
-
pi.on("
|
|
1317
|
+
// Only when the user switches model; on startup/restore keep Pi's saved
|
|
1318
|
+
// thinking level (or --thinking) so the chosen effort sticks.
|
|
1319
|
+
pi.on("model_select", (event: any) => {
|
|
1320
|
+
if (event?.source !== "restore") applyThinkingDefault(pi, event?.model);
|
|
1321
|
+
});
|
|
1161
1322
|
|
|
1162
1323
|
// Named convenience command; the same flow is also reachable via `/login`.
|
|
1163
1324
|
pi.registerCommand("uva-login", {
|
|
@@ -1219,7 +1380,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
1219
1380
|
}
|
|
1220
1381
|
try {
|
|
1221
1382
|
saveOverrides(draft);
|
|
1222
|
-
registerProviderNow(pi, await
|
|
1383
|
+
registerProviderNow(pi, await buildWorkingModels(activeApiKey, activeBaseUrl, false), activeBaseUrl);
|
|
1223
1384
|
if (ctx.model) applyThinkingDefault(pi, ctx.model);
|
|
1224
1385
|
ctx.ui.notify(`Saved & applied overrides for ${Object.keys(draft).length} model(s).`, "info");
|
|
1225
1386
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-uva-hva",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Pi coding-agent provider extension for the UvA/HvA LiteLLM proxy. Adds a /login connect flow (pick base URL, paste API key), discovers every model with real capabilities from /model_group/info, routes each to the right endpoint (Responses vs chat-completions) with runtime self-heal, fixes empty output on tool turns, and defeats the gateway 504 on long reasoning turns via a background+poll path.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi",
|
|
@@ -17,10 +17,17 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/
|
|
20
|
+
"url": "https://github.com/uva/UvA-HvA-Agentic-Tools.git",
|
|
21
21
|
"directory": "pi"
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "node --test"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@earendil-works/pi-ai": "*",
|
|
29
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
30
|
+
},
|
|
24
31
|
"files": [
|
|
25
32
|
"index.ts",
|
|
26
33
|
"README.md",
|