@robhowley/pi-openrouter 0.9.0 → 0.9.1
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 +39 -4
- package/extensions/openrouter/__tests__/cache.test.ts +769 -0
- package/extensions/openrouter/__tests__/client.test.ts +333 -15
- package/extensions/openrouter/__tests__/commands.test.ts +816 -0
- package/extensions/openrouter/__tests__/fixtures.ts +140 -1
- package/extensions/openrouter/__tests__/format.test.ts +19 -0
- package/extensions/openrouter/__tests__/hooks.test.ts +276 -0
- package/extensions/openrouter/__tests__/index.test.ts +112 -363
- package/extensions/openrouter/__tests__/local-usage.test.ts +777 -0
- package/extensions/openrouter/__tests__/normalizers.test.ts +288 -0
- package/extensions/openrouter/__tests__/overlay.test.ts +225 -0
- package/extensions/openrouter/__tests__/session-state.test.ts +233 -0
- package/extensions/openrouter/__tests__/session.test.ts +44 -43
- package/extensions/openrouter/account-client.ts +11 -61
- package/extensions/openrouter/cache.ts +203 -91
- package/extensions/openrouter/client.ts +49 -3
- package/extensions/openrouter/commands.ts +555 -0
- package/extensions/openrouter/format.ts +7 -4
- package/extensions/openrouter/hooks.ts +229 -0
- package/extensions/openrouter/index.ts +13 -990
- package/extensions/openrouter/local-usage.ts +145 -22
- package/extensions/openrouter/models/__tests__/cache.test.ts +63 -2
- package/extensions/openrouter/models/__tests__/mapper.test.ts +29 -0
- package/extensions/openrouter/models/__tests__/override-commands.test.ts +668 -0
- package/extensions/openrouter/models/__tests__/sync.test.ts +156 -4
- package/extensions/openrouter/models/cache.ts +27 -2
- package/extensions/openrouter/models/mapper.ts +35 -69
- package/extensions/openrouter/models/override-commands.ts +434 -0
- package/extensions/openrouter/models/skip-hints.ts +19 -0
- package/extensions/openrouter/models/sync.ts +22 -10
- package/extensions/openrouter/models/types.ts +2 -1
- package/extensions/openrouter/normalizers.ts +128 -0
- package/extensions/openrouter/overlay.ts +19 -8
- package/extensions/openrouter/session-state.ts +110 -0
- package/extensions/openrouter/session.ts +16 -0
- package/extensions/openrouter/types.ts +28 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,13 +12,18 @@ pi install npm:@robhowley/pi-openrouter
|
|
|
12
12
|
|
|
13
13
|
Set one of these environment variables:
|
|
14
14
|
|
|
15
|
-
- `OPENROUTER_MANAGEMENT_KEY` (preferred)
|
|
16
|
-
- `OPENROUTER_API_KEY
|
|
15
|
+
- `OPENROUTER_MANAGEMENT_KEY` (preferred) — provides full usage/analytics and can be used for model sync
|
|
16
|
+
- `OPENROUTER_API_KEY` — basic usage data and user-scoped model sync
|
|
17
17
|
|
|
18
18
|
```shell
|
|
19
19
|
export OPENROUTER_MANAGEMENT_KEY=sk-or-...
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
**Key selection:**
|
|
23
|
+
|
|
24
|
+
- Usage/account commands prefer `OPENROUTER_MANAGEMENT_KEY` for full analytics, falling back to `OPENROUTER_API_KEY`
|
|
25
|
+
- Model sync prefers `OPENROUTER_API_KEY` but will attempt `OPENROUTER_MANAGEMENT_KEY` if only that is set
|
|
26
|
+
|
|
22
27
|
## Commands
|
|
23
28
|
|
|
24
29
|
```bash
|
|
@@ -39,7 +44,7 @@ export OPENROUTER_MANAGEMENT_KEY=sk-or-...
|
|
|
39
44
|
|
|
40
45
|
`/openrouter models-sync`
|
|
41
46
|
|
|
42
|
-
The sync uses OpenRouter’s authenticated user model catalog, so Pi can see the models available to your account instead of only the default provider list.
|
|
47
|
+
The sync uses OpenRouter’s authenticated user model catalog, so Pi can see the models available to your account instead of only the default provider list. This intentionally replaces Pi's OpenRouter provider model list with your user-scoped catalog plus OpenRouter's built-in router aliases (`openrouter/auto`, `openrouter/free`, and `openrouter/owl-alpha`). It does not merge in every built-in model unless that model is returned by your OpenRouter account catalog.
|
|
43
48
|
|
|
44
49
|
`/openrouter models-status`
|
|
45
50
|
|
|
@@ -54,6 +59,8 @@ To see why models were skipped:
|
|
|
54
59
|
|
|
55
60
|
`/openrouter models-status --skipped`
|
|
56
61
|
|
|
62
|
+
Skipped output may include a grouped suggestion when Pi can offer a safe next step, such as adding a local `contextWindow` override for incomplete metadata.
|
|
63
|
+
|
|
57
64
|
Skipped models do not make the sync fail; models are skipped when required metadata cannot be safely mapped into Pi’s provider model config. The last successful catalog is cached so Pi can keep using it if a later refresh fails, and the cache persists across sessions. If a session starts with a cached catalog that has not been registered yet, status will show:
|
|
58
65
|
|
|
59
66
|
```text
|
|
@@ -102,6 +109,8 @@ Select a key from the list to inspect its limit, usage, reset cadence, and BYOK
|
|
|
102
109
|
|
|
103
110
|
`pi-openrouter` automatically tags OpenRouter requests with a `session_id` derived from the Pi session ID.
|
|
104
111
|
|
|
112
|
+
Request detection is intentionally broad: the extension checks provider metadata, `openrouter/...` model ids, configured OpenRouter base URLs, Shopify's ZDR provider flag, and request URLs/endpoints so tagging still works across different Pi event shapes.
|
|
113
|
+
|
|
105
114
|
View the OpenRouter session tag with:
|
|
106
115
|
|
|
107
116
|
```bash
|
|
@@ -111,6 +120,20 @@ View the OpenRouter session tag with:
|
|
|
111
120
|
pi:[uuid]
|
|
112
121
|
```
|
|
113
122
|
|
|
123
|
+
## Local usage tracking
|
|
124
|
+
|
|
125
|
+
The extension logs completed OpenRouter turns to local JSONL files in `~/.pi/openrouter/usage/` to provide near-real-time usage data for "Today's spend" in the usage overlay. This supplements the OpenRouter Activity API, which typically has a delay.
|
|
126
|
+
|
|
127
|
+
**Retention:** Local usage files are automatically cleaned up after 90 days.
|
|
128
|
+
|
|
129
|
+
**Debug logging:** By default, file operations are quiet (fail-open). To enable verbose logging for troubleshooting:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
export PI_OPENROUTER_DEBUG_USAGE=1
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
This logs write/read errors, malformed lines, and cleanup operations to the console.
|
|
136
|
+
|
|
114
137
|
## Model field overrides
|
|
115
138
|
|
|
116
139
|
Some OpenRouter models don't have complete metadata in Pi's built-in registry or the OpenRouter model catalog. You can manually configure supported `PiModelConfig` fields using scoped syntax:
|
|
@@ -133,12 +156,16 @@ Some OpenRouter models don't have complete metadata in Pi's built-in registry or
|
|
|
133
156
|
- `maxTokens` → `maxTokens` (number)
|
|
134
157
|
- `reasoning` → `reasoning` (boolean)
|
|
135
158
|
|
|
159
|
+
For CLI `thinking.*` / `thinkingLevelMap.*` assignments, `pi-openrouter` only accepts the conservative documented value set: `off`, `minimal`, `low`, `medium`, `high`, `max`, `xhigh`, or `null`.
|
|
160
|
+
|
|
136
161
|
Use `null` to hide a level from Pi's UI:
|
|
137
162
|
|
|
138
163
|
```bash
|
|
139
164
|
/openrouter model-override-set deepseek/deepseek-v4-pro thinking.off=null
|
|
140
165
|
```
|
|
141
166
|
|
|
167
|
+
If you need an advanced or experimental thinking value outside that CLI set, edit `~/.pi/openrouter/model-overrides.json` directly. The JSON file is the escape hatch; the CLI intentionally stays conservative.
|
|
168
|
+
|
|
142
169
|
List your overrides:
|
|
143
170
|
|
|
144
171
|
```bash
|
|
@@ -153,7 +180,15 @@ Clear overrides:
|
|
|
153
180
|
/openrouter model-override-clear deepseek/deepseek-v4-pro
|
|
154
181
|
```
|
|
155
182
|
|
|
156
|
-
Overrides are stored in `~/.pi/openrouter/model-overrides.json
|
|
183
|
+
Overrides are stored in `~/.pi/openrouter/model-overrides.json`.
|
|
184
|
+
|
|
185
|
+
Precedence is:
|
|
186
|
+
|
|
187
|
+
1. Pi's built-in registry
|
|
188
|
+
2. OpenRouter's user-scoped model catalog
|
|
189
|
+
3. Local overrides from `~/.pi/openrouter/model-overrides.json`
|
|
190
|
+
|
|
191
|
+
That means local overrides win. Run `/openrouter models-sync` after changing overrides to apply them to the registered OpenRouter model list.
|
|
157
192
|
|
|
158
193
|
## License
|
|
159
194
|
|