@aliou/pi-neuralwatt 0.17.0 → 0.18.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 CHANGED
@@ -41,20 +41,20 @@ pi -e ./extensions/provider/index.ts
41
41
 
42
42
  ## Usage
43
43
 
44
- Once installed, select `neuralwatt` as your provider and choose from available models:
44
+ Once installed, select `neuralwatt` as your provider and pick a model:
45
45
 
46
46
  ```
47
- /model neuralwatt meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8
47
+ /model neuralwatt kimi-k3
48
48
  ```
49
49
 
50
50
  ### API surface
51
51
 
52
- Neuralwatt serves every model on two APIs. Pick one via `/neuralwatt:settings` → **API** (or set `provider.api` in the extension config):
52
+ Neuralwatt serves every model on two APIs. Pick one in `/neuralwatt:settings` → **API** (or set `provider.api` in the extension config):
53
53
 
54
- - `openai-completions` (default) — the OpenAI-compatible `chat/completions` endpoint;
55
- - `anthropic-messages` — the Anthropic-compatible `POST /v1/messages` endpoint (vLLM-backed), which streams native tool use and thinking blocks.
54
+ - `openai-completions` (default): the OpenAI-compatible `chat/completions` endpoint.
55
+ - `anthropic-messages`: the Anthropic-compatible `POST /v1/messages` endpoint, which streams native tool use and thinking blocks.
56
56
 
57
- The setting swaps the whole provider (same model ids on both sides) and applies on `/reload`. Usage/cost accounting and quota tracking work on both surfaces: per-request quota headers only exist on chat-completions responses, while `/v1/messages` streams carry the same data as `: energy` / `: cost` SSE comments.
57
+ Both use the same model ids. The setting applies on `/reload`. Cost, energy, and quota tracking work on both.
58
58
 
59
59
  ### Quota Command
60
60
 
@@ -65,87 +65,48 @@ Check your API usage at a glance:
65
65
  ```
66
66
 
67
67
  The quota command shows three tabs:
68
- - **Subscription** (when subscribed) — plan details, energy quota with progress bar, billing period
69
- - **Credits** — credit balance with progress bar, accounting method
70
- - **Usage & Key** — monthly usage (cost, requests, tokens, energy), API key info, key allowance, rate limits
68
+ - **Subscription** (when subscribed): plan details, energy quota with progress bar, billing period
69
+ - **Credits**: credit balance with progress bar, accounting method
70
+ - **Usage & Key**: monthly usage (cost, requests, tokens, energy), API key info, key allowance, rate limits
71
71
 
72
72
  https://github.com/user-attachments/assets/a8994940-c467-4744-a0f2-833cb63923ff
73
73
 
74
74
  ### Quota Warnings
75
75
 
76
- When enabled, the extension notifies you when credits or energy are running low. When you have an active subscription, only energy warnings fire (credits are on-demand top-up only). Warnings use escalation on severity transitions and have a cooldown for `warning` level.
77
-
78
- ### Sub-bar Integration
79
-
80
- When a Neuralwatt model is active, the footer status bar shows live quota usage (credits and energy). The status updates after each response and on session start.
76
+ When enabled, the extension notifies you when credits or energy are running low. With an active subscription, only energy warnings fire (credits are on-demand top-up only).
81
77
 
82
78
  ## Settings
83
79
 
84
80
  Configure features with `/neuralwatt:settings`:
85
81
 
86
82
  - **API** — Choose between `openai-completions` (default) and `anthropic-messages`; applies on `/reload`
83
+ - **API base URL** — Send requests to a different base URL, such as a gateway; empty uses the Neuralwatt API
87
84
  - **Quota command** — Show/hide `/neuralwatt:quota`
88
85
  - **Quota warnings** — Enable/disable low quota notifications
89
- - **Sub-bar integration** — Show/hide usage in status bar
90
86
 
91
87
  The provider itself cannot be disabled — it is always loaded.
92
88
 
93
- Configuration uses nested per-feature sections. Existing flat config files are migrated automatically, with a backup written next to the migrated config.
94
-
95
- ### Model Refresh
96
-
97
- Neuralwatt registers its public models without network access. Opening `/model` refreshes the catalog from the API in the background (authenticated when an API key is configured). `pi update --models` forces an immediate refresh.
98
-
99
- Pi stores the complete effective Neuralwatt catalog in `~/.pi/agent/models-store.json` for offline startup. Current hardcoded public definitions remain authoritative when cached models are restored.
89
+ ## Model list
100
90
 
101
- ## Adding or Updating Models
102
-
103
- Public models are hardcoded in `extensions/provider/models/public-models.ts` and validated against the live API. To update:
104
-
105
- 1. Run `pnpm test` — it fetches `/v1/models` and compares against hardcoded definitions
106
- 2. Fix any discrepancies (missing models, changed context windows)
107
- 3. Re-run `pnpm test` to confirm
91
+ The extension ships a built-in model list, so it works offline on first start. Pi refreshes the catalog from the Neuralwatt API in the background (authenticated when an API key is configured, so key-scoped models appear too) and caches it in `~/.pi/agent/models-store.json`. `pi update --models` forces a refresh.
108
92
 
109
93
  ## Development
110
94
 
111
- ### Setup
112
-
113
95
  ```bash
114
96
  git clone https://github.com/aliou/pi-neuralwatt.git
115
97
  cd pi-neuralwatt
116
-
117
- # Install dependencies (sets up pre-commit hooks)
118
- pnpm install && pnpm prepare
119
- ```
120
-
121
- Pre-commit hooks run on every commit:
122
- - TypeScript type checking
123
- - Biome linting
124
- - Biome formatting with auto-fix
125
-
126
- ### Commands
127
-
128
- ```bash
129
- # Type check
98
+ pnpm install
130
99
  pnpm run typecheck
131
-
132
- # Lint
133
100
  pnpm run lint
134
-
135
- # Format
136
- pnpm run format
137
-
138
- # Test
139
101
  pnpm run test
102
+ pnpm run check:models # compare the built-in model list with the live API
140
103
  ```
141
104
 
142
- ## Release
143
-
144
- This repository uses [Changesets](https://github.com/changesets/changesets) for versioning.
105
+ The pre-commit hook runs typecheck, lint, the lockfile check, and the changeset check. Releases use [Changesets](https://github.com/changesets/changesets).
145
106
 
146
107
  ## Requirements
147
108
 
148
- - Pi coding agent v0.80.8+
109
+ - Pi coding agent 1.4 or later
149
110
  - Neuralwatt API key (configured in `~/.pi/agent/auth.json` or via `NEURALWATT_API_KEY`)
150
111
 
151
112
  ## Links
@@ -12,10 +12,14 @@ function missingAuthMessage(): string {
12
12
  return `Neuralwatt quota requires an API key. Add credentials to ${authPath} or set the NEURALWATT_API_KEY environment variable.`;
13
13
  }
14
14
 
15
- export function registerQuotasCommand(pi: ExtensionAPI): void {
15
+ export function registerQuotasCommand(
16
+ pi: ExtensionAPI,
17
+ isEnabled: () => boolean,
18
+ ): void {
16
19
  pi.registerCommand("neuralwatt:quota", {
17
20
  description: "Display Neuralwatt API usage and quota",
18
21
  handler: async (_args, ctx) => {
22
+ if (!isEnabled()) return;
19
23
  const apiKey = await getNeuralwattApiKey(ctx.modelRegistry);
20
24
  if (!apiKey) {
21
25
  ctx.ui.notify(missingAuthMessage(), "warning");
@@ -1,19 +1,29 @@
1
+ import { bindProjectConfig } from "@aliou/pi-utils-settings";
1
2
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
3
  import { configLoader } from "../../src/config";
3
4
  import {
5
+ NEURALWATT_CONFIG_UPDATED_EVENT,
4
6
  NEURALWATT_EXTENSIONS_REGISTER_EVENT,
5
7
  NEURALWATT_EXTENSIONS_REQUEST_EVENT,
8
+ type NeuralwattConfigUpdatedPayload,
6
9
  } from "../../src/events";
7
10
  import { registerQuotasCommand } from "./command";
8
11
 
9
12
  export default async function (pi: ExtensionAPI) {
10
13
  await configLoader.load();
14
+ bindProjectConfig(pi, configLoader);
11
15
 
12
- const config = configLoader.getConfig();
16
+ let enabled = configLoader.getConfig().quotaCommand.enabled;
17
+ registerQuotasCommand(pi, () => enabled);
13
18
 
14
- if (config.quotaCommand.enabled) {
15
- registerQuotasCommand(pi);
16
- }
19
+ pi.on("session_start", () => {
20
+ enabled = configLoader.getConfig().quotaCommand.enabled;
21
+ });
22
+
23
+ pi.events.on(NEURALWATT_CONFIG_UPDATED_EVENT, (data: unknown) => {
24
+ enabled = (data as NeuralwattConfigUpdatedPayload).config.quotaCommand
25
+ .enabled;
26
+ });
17
27
 
18
28
  pi.events.on(NEURALWATT_EXTENSIONS_REQUEST_EVENT, () => {
19
29
  pi.events.emit(NEURALWATT_EXTENSIONS_REGISTER_EVENT, {
@@ -142,16 +142,6 @@ export function registerNeuralwattSettings(
142
142
  ),
143
143
  loaded.has("quotaWarnings"),
144
144
  ),
145
- featureRow(
146
- "subBarIntegration",
147
- "Sub-bar integration",
148
- "Toggle integration with the status bar and sub-core",
149
- featureValue(
150
- tabConfig?.subBarIntegration,
151
- resolved.subBarIntegration.enabled,
152
- ),
153
- loaded.has("subBarIntegration"),
154
- ),
155
145
  ],
156
146
  },
157
147
  ];
@@ -187,11 +177,6 @@ export function registerNeuralwattSettings(
187
177
  ...config,
188
178
  quotaWarnings: { ...config.quotaWarnings, enabled },
189
179
  };
190
- case "subBarIntegration":
191
- return {
192
- ...config,
193
- subBarIntegration: { ...config.subBarIntegration, enabled },
194
- };
195
180
  default:
196
181
  return null;
197
182
  }
@@ -1,3 +1,4 @@
1
+ import { bindProjectConfig } from "@aliou/pi-utils-settings";
1
2
  import { getApiProvider } from "@earendil-works/pi-ai/compat";
2
3
  import type {
3
4
  ExtensionAPI,
@@ -88,6 +89,7 @@ function registerNeuralwattProvider(
88
89
 
89
90
  export default async function (pi: ExtensionAPI) {
90
91
  await configLoader.load();
92
+ bindProjectConfig(pi, configLoader);
91
93
 
92
94
  let latestQuotas: NeuralwattQuotas | undefined;
93
95
 
@@ -109,12 +111,14 @@ export default async function (pi: ExtensionAPI) {
109
111
  // text with actionable details from Neuralwatt's response headers.
110
112
  let pendingRateLimitInfo: NeuralwattRateLimitInfo | undefined;
111
113
 
112
- registerNeuralwattProvider(pi, {
114
+ const streamCallbacks: NeuralwattStreamCallbacks = {
113
115
  onSseQuota: handleSseQuota,
114
116
  onRateLimit: (info) => {
115
117
  pendingRateLimitInfo = info;
116
118
  },
117
- });
119
+ };
120
+ let registeredApi = configLoader.getConfig().provider.api;
121
+ registerNeuralwattProvider(pi, streamCallbacks);
118
122
 
119
123
  const loadedFeatures = new Set<NeuralwattFeatureId>();
120
124
 
@@ -233,6 +237,11 @@ export default async function (pi: ExtensionAPI) {
233
237
  });
234
238
 
235
239
  pi.on("session_start", async (_event, ctx) => {
240
+ const api = configLoader.getConfig().provider.api;
241
+ if (api !== registeredApi) {
242
+ registerNeuralwattProvider(pi, streamCallbacks);
243
+ registeredApi = api;
244
+ }
236
245
  currentModelRegistry = ctx.modelRegistry;
237
246
  pendingRateLimitInfo = undefined;
238
247
  const messages = [...new Set(configLoader.drainMessages())];
@@ -16,23 +16,6 @@ import {
16
16
  // unsupported levels through the aliases. See `models.test.ts` for the drift
17
17
  // check against the live catalog.
18
18
 
19
- // DeepSeek V4 Flash: efforts max/high/none, not mandatory.
20
- // https://api-docs.deepseek.com/guides/thinking_mode/
21
- const DEEPSEEK_V4_FLASH: NeuralwattModelFamily = {
22
- cost: { input: 0.14, output: 0.28, cacheRead: 0.028 },
23
- vision: false,
24
- reasoningMetadata: {
25
- supported_efforts: ["max", "high", "none"],
26
- mandatory: false,
27
- effort_aliases: {
28
- xhigh: "max",
29
- medium: "high",
30
- low: "high",
31
- minimal: "high",
32
- },
33
- },
34
- };
35
-
36
19
  // DeepSeek. V4.1 Flash is vision-capable, unlike V4 Flash, and admits
37
20
  // reasoning levels up to `xhigh`. Not mandatory (off defaults).
38
21
  const DEEPSEEK_V4_1_FLASH: NeuralwattModelFamily = {
@@ -105,17 +88,6 @@ const KIMI_K3: NeuralwattModelFamily = {
105
88
  },
106
89
  };
107
90
 
108
- // MoonshotAI. K2.7 Code has mandatory reasoning with no selectable efforts
109
- // (`supported_efforts: []`), so `buildThinkingLevelMap` nulls out every level.
110
- const KIMI_K2_7_CODE: NeuralwattModelFamily = {
111
- cost: { input: 0.95, output: 4.0, cacheRead: 0.095 },
112
- vision: true,
113
- reasoningMetadata: {
114
- supported_efforts: [],
115
- mandatory: true,
116
- },
117
- };
118
-
119
91
  // Xiaomi. MiMo-V2.6-Pro only has two reasoning behaviors: `high` (default)
120
92
  // and `none`; the API aliases every other effort onto those, with `minimal`
121
93
  // landing on `none`.
@@ -203,33 +175,6 @@ const QWEN_3_8_27B: NeuralwattModelFamily = {
203
175
  };
204
176
 
205
177
  const FAMILIES: [NeuralwattModelFamily, NeuralwattVariantSpec[]][] = [
206
- [
207
- DEEPSEEK_V4_FLASH,
208
- [
209
- {
210
- id: "deepseek-v4-flash",
211
- name: "DeepSeek V4 Flash",
212
- contextWindow: 1048560,
213
- maxOutputTokens: 393216,
214
- reasoning: true,
215
- },
216
- {
217
- id: "deepseek-v4-flash-flex",
218
- name: "DeepSeek V4 Flash (flex)",
219
- contextWindow: 1048560,
220
- maxOutputTokens: 393216,
221
- reasoning: true,
222
- costMultiplier: 0.65,
223
- },
224
- {
225
- id: "deepseek-v4-flash-speed",
226
- name: "DeepSeek V4 Flash (Speed)",
227
- contextWindow: 1048560,
228
- maxOutputTokens: 393216,
229
- reasoning: true,
230
- },
231
- ],
232
- ],
233
178
  [
234
179
  DEEPSEEK_V4_1_FLASH,
235
180
  [
@@ -336,35 +281,6 @@ const FAMILIES: [NeuralwattModelFamily, NeuralwattVariantSpec[]][] = [
336
281
  },
337
282
  ],
338
283
  ],
339
- [
340
- KIMI_K2_7_CODE,
341
- [
342
- {
343
- id: "kimi-k2.7-code",
344
- name: "Kimi K2.7 Code",
345
- contextWindow: 262128,
346
- maxOutputTokens: null,
347
- reasoning: true,
348
- },
349
- {
350
- // K2.7 Code cannot disable thinking; the -fast variant caps the
351
- // reasoning budget (~64 tokens) rather than turning it off.
352
- id: "kimi-k2.7-code-fast",
353
- name: "Kimi K2.7 Code Fast",
354
- contextWindow: 262128,
355
- maxOutputTokens: null,
356
- reasoning: true,
357
- },
358
- {
359
- id: "kimi-k2.7-code-flex",
360
- name: "Kimi K2.7 Code (flex)",
361
- contextWindow: 262128,
362
- maxOutputTokens: null,
363
- reasoning: true,
364
- costMultiplier: 0.65,
365
- },
366
- ],
367
- ],
368
284
  [
369
285
  MIMO_V2_6_PRO,
370
286
  [
@@ -1,3 +1,4 @@
1
+ import { bindProjectConfig } from "@aliou/pi-utils-settings";
1
2
  import type {
2
3
  ExtensionAPI,
3
4
  ExtensionContext,
@@ -15,6 +16,7 @@ import { checkQuotas, clearAlertState } from "./notifier";
15
16
 
16
17
  export default async function (pi: ExtensionAPI) {
17
18
  await configLoader.load();
19
+ bindProjectConfig(pi, configLoader);
18
20
 
19
21
  let enabled = configLoader.getConfig().quotaWarnings.enabled;
20
22
  let currentProvider: string | undefined;
@@ -46,6 +48,7 @@ export default async function (pi: ExtensionAPI) {
46
48
  }
47
49
 
48
50
  pi.on("session_start", async (_event, ctx) => {
51
+ enabled = configLoader.getConfig().quotaWarnings.enabled;
49
52
  unsubscribeQuotas?.();
50
53
  currentProvider = ctx.model?.provider;
51
54
  unsubscribeQuotas = pi.events.on(NEURALWATT_QUOTAS_UPDATED_EVENT, (data) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aliou/pi-neuralwatt",
3
- "version": "0.17.0",
3
+ "version": "0.18.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "private": false,
@@ -17,8 +17,7 @@
17
17
  "extensions": [
18
18
  "./extensions/provider/index.ts",
19
19
  "./extensions/command-quotas/index.ts",
20
- "./extensions/quota-warnings/index.ts",
21
- "./extensions/sub-bar-integration/index.ts"
20
+ "./extensions/quota-warnings/index.ts"
22
21
  ],
23
22
  "video": "https://assets.aliou.me/github/aliou/pi-neuralwatt/demo.mp4"
24
23
  },
@@ -34,21 +33,21 @@
34
33
  "!extensions/**/*.test.ts"
35
34
  ],
36
35
  "dependencies": {
37
- "@aliou/pi-utils-settings": "^0.19.1",
36
+ "@aliou/pi-utils-settings": "^0.24.0",
38
37
  "@aliou/pi-utils-ui": "^0.5.0"
39
38
  },
40
39
  "peerDependencies": {
41
40
  "@earendil-works/pi-ai": ">=1.0.0",
42
- "@earendil-works/pi-coding-agent": ">=1.0.0",
41
+ "@earendil-works/pi-coding-agent": ">=1.4.0",
43
42
  "@earendil-works/pi-tui": "*"
44
43
  },
45
44
  "devDependencies": {
46
45
  "@aliou/biome-plugins": "^0.11.0",
47
46
  "@biomejs/biome": "^2.4.15",
48
47
  "@changesets/cli": "^2.27.11",
49
- "@earendil-works/pi-ai": "1.1.0",
50
- "@earendil-works/pi-coding-agent": "1.1.0",
51
- "@earendil-works/pi-tui": "1.1.0",
48
+ "@earendil-works/pi-ai": "1.4.0",
49
+ "@earendil-works/pi-coding-agent": "1.4.0",
50
+ "@earendil-works/pi-tui": "1.4.0",
52
51
  "@types/node": "^25.0.10",
53
52
  "husky": "^9.1.7",
54
53
  "ts-json-schema-generator": "^2.4.0",
@@ -57,12 +56,6 @@
57
56
  "typescript": "^5.9.3",
58
57
  "vitest": "^4.0.18"
59
58
  },
60
- "pnpm": {
61
- "overrides": {
62
- "@earendil-works/pi-ai": "$@earendil-works/pi-coding-agent",
63
- "@earendil-works/pi-tui": "$@earendil-works/pi-coding-agent"
64
- }
65
- },
66
59
  "scripts": {
67
60
  "typecheck": "tsc --noEmit",
68
61
  "lint": "biome check",
@@ -71,15 +64,15 @@
71
64
  "test:watch": "vitest",
72
65
  "check:models": "tsx scripts/check-models.ts",
73
66
  "check:changesets": "tsx scripts/check-changesets.ts",
74
- "gen:schema": "pi-settings-schema -p src/config/types.ts -t NeuralwattConfig -o schema.json --version 0.12.0",
75
- "check:schema": "pi-settings-schema -p src/config/types.ts -t NeuralwattConfig -o schema.json --version 0.12.0 --check",
67
+ "gen:schema": "pi-settings-schema -p src/config/types.ts -t NeuralwattConfig -o schema.json",
68
+ "check:schema": "pi-settings-schema -p src/config/types.ts -t NeuralwattConfig -o schema.json --check",
76
69
  "check:lockfile": "pnpm install --frozen-lockfile --ignore-scripts",
77
70
  "prepare": "[ -d .git ] && husky || true",
78
71
  "changeset": "changeset",
79
72
  "version": "changeset version",
80
73
  "release": "pnpm changeset publish"
81
74
  },
82
- "packageManager": "pnpm@10.26.1",
75
+ "packageManager": "pnpm@11.27.0",
83
76
  "peerDependenciesMeta": {
84
77
  "@earendil-works/pi-ai": {
85
78
  "optional": true
package/schema.json CHANGED
@@ -16,10 +16,6 @@
16
16
  "$ref": "#/definitions/NeuralwattQuotaWarningsConfig",
17
17
  "description": "Quota warning feature."
18
18
  },
19
- "subBarIntegration": {
20
- "$ref": "#/definitions/NeuralwattSubBarIntegrationConfig",
21
- "description": "Sub-bar/status-bar integration feature."
22
- },
23
19
  "provider": {
24
20
  "$ref": "#/definitions/NeuralwattProviderConfig",
25
21
  "description": "Provider behavior (API surface)."
@@ -35,7 +31,7 @@
35
31
  "pattern": "^\\d{1,15}(\\.\\d{1,15})?(\\.\\d{1,15})?$"
36
32
  }
37
33
  ],
38
- "description": "Config schema version, stamped by migrations. Current version: 0.12.0."
34
+ "description": "Config schema version, stamped by migrations."
39
35
  }
40
36
  },
41
37
  "additionalProperties": false
@@ -60,16 +56,6 @@
60
56
  },
61
57
  "additionalProperties": false
62
58
  },
63
- "NeuralwattSubBarIntegrationConfig": {
64
- "type": "object",
65
- "properties": {
66
- "enabled": {
67
- "type": "boolean",
68
- "description": "Show usage in the sub-bar / status bar."
69
- }
70
- },
71
- "additionalProperties": false
72
- },
73
59
  "NeuralwattProviderConfig": {
74
60
  "type": "object",
75
61
  "properties": {
@@ -9,9 +9,6 @@ export const DEFAULT_CONFIG: ResolvedNeuralwattConfig = {
9
9
  quotaWarnings: {
10
10
  enabled: true,
11
11
  },
12
- subBarIntegration: {
13
- enabled: true,
14
- },
15
12
  provider: {
16
13
  api: "openai-completions",
17
14
  apiBaseUrl: NEURALWATT_API_BASE_URL,
@@ -26,11 +26,6 @@ function normalizeResolvedConfig(
26
26
  enabled:
27
27
  config.quotaWarnings?.enabled ?? DEFAULT_CONFIG.quotaWarnings.enabled,
28
28
  },
29
- subBarIntegration: {
30
- enabled:
31
- config.subBarIntegration?.enabled ??
32
- DEFAULT_CONFIG.subBarIntegration.enabled,
33
- },
34
29
  provider: {
35
30
  api: resolveApi(config.provider?.api),
36
31
  apiBaseUrl: resolveApiBaseUrl(config.provider?.apiBaseUrl),
@@ -0,0 +1,31 @@
1
+ import type { Migration } from "@aliou/pi-utils-settings";
2
+
3
+ export const SUB_BAR_GIST_URL =
4
+ "https://gist.github.com/aliou/9939544f3c5a4f917b0a8e5c0497cdb2";
5
+
6
+ interface PreRemovalNeuralwattConfig {
7
+ $schema?: string;
8
+ quotaCommand?: { enabled?: boolean };
9
+ quotaWarnings?: { enabled?: boolean };
10
+ subBarIntegration?: { enabled?: boolean };
11
+ provider?: {
12
+ api?: string;
13
+ apiBaseUrl?: string;
14
+ includeLegacyModelIds?: boolean;
15
+ includeEarlyAccessModels?: boolean;
16
+ };
17
+ }
18
+
19
+ export const removeSubBarIntegrationMigration: Migration<PreRemovalNeuralwattConfig> =
20
+ {
21
+ name: "remove-sub-bar-integration",
22
+ version: "0.18.0",
23
+ shouldRun: (config) => config.subBarIntegration !== undefined,
24
+ message: `[neuralwatt] The built-in sub-bar integration was removed. Test with \`pi -e ${SUB_BAR_GIST_URL}\` and install with \`pi install ${SUB_BAR_GIST_URL}\`. The standalone extension won't be kept up to date.`,
25
+ run: (config) => {
26
+ if (config.subBarIntegration === undefined) return config;
27
+
28
+ const { subBarIntegration: _removed, ...rest } = config;
29
+ return rest;
30
+ },
31
+ };
@@ -1,19 +1,18 @@
1
1
  import type { Migration } from "@aliou/pi-utils-settings";
2
- import type { NeuralwattConfig } from "../types";
3
2
 
4
3
  export {
5
4
  backupConfig,
6
5
  flatToNestedConfigMigration,
7
6
  } from "./02-flat-to-nested-config";
8
7
  export { renameHiddenToEarlyAccessMigration } from "./03-rename-hidden-to-early-access";
8
+ export { removeSubBarIntegrationMigration } from "./04-remove-sub-bar-integration";
9
9
 
10
10
  import { flatToNestedConfigMigration } from "./02-flat-to-nested-config";
11
11
  import { renameHiddenToEarlyAccessMigration } from "./03-rename-hidden-to-early-access";
12
+ import { removeSubBarIntegrationMigration } from "./04-remove-sub-bar-integration";
12
13
 
13
- // Each migration is typed against its own historical input shape. The loader
14
- // applies them in sequence on the raw config record, so they are cast to the
15
- // current config type for the array.
16
14
  export const migrations = [
17
15
  flatToNestedConfigMigration,
18
16
  renameHiddenToEarlyAccessMigration,
19
- ] as unknown as Migration<NeuralwattConfig>[];
17
+ removeSubBarIntegrationMigration,
18
+ ] as Migration<object>[];
@@ -8,11 +8,6 @@ export interface NeuralwattQuotaWarningsConfig {
8
8
  enabled?: boolean;
9
9
  }
10
10
 
11
- export interface NeuralwattSubBarIntegrationConfig {
12
- /** Show usage in the sub-bar / status bar. */
13
- enabled?: boolean;
14
- }
15
-
16
11
  /**
17
12
  * Neuralwatt serves every chat model twice: on an OpenAI-compatible
18
13
  * `chat/completions` endpoint and on a vLLM-backed Anthropic-compatible
@@ -43,9 +38,6 @@ export interface NeuralwattConfig {
43
38
  /** Quota warning feature. */
44
39
  quotaWarnings?: NeuralwattQuotaWarningsConfig;
45
40
 
46
- /** Sub-bar/status-bar integration feature. */
47
- subBarIntegration?: NeuralwattSubBarIntegrationConfig;
48
-
49
41
  /** Provider behavior (API surface). */
50
42
  provider?: NeuralwattProviderConfig;
51
43
  }
@@ -57,9 +49,6 @@ export interface ResolvedNeuralwattConfig {
57
49
  quotaWarnings: {
58
50
  enabled: boolean;
59
51
  };
60
- subBarIntegration: {
61
- enabled: boolean;
62
- };
63
52
  provider: {
64
53
  api: NeuralwattApi;
65
54
  apiBaseUrl: string;
package/src/events.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  import type { ResolvedNeuralwattConfig } from "./config";
2
2
  import type { NeuralwattQuotas } from "./types/quota-api";
3
3
 
4
- export type NeuralwattFeatureId =
5
- | "quotaCommand"
6
- | "quotaWarnings"
7
- | "subBarIntegration";
4
+ export type NeuralwattFeatureId = "quotaCommand" | "quotaWarnings";
8
5
 
9
6
  export const NEURALWATT_EXTENSIONS_REQUEST_EVENT =
10
7
  "neuralwatt:extensions:request" as const;
@@ -1,131 +0,0 @@
1
- import type {
2
- ExtensionAPI,
3
- ExtensionContext,
4
- Theme,
5
- } from "@earendil-works/pi-coding-agent";
6
- import { configLoader } from "../../src/config";
7
- import {
8
- NEURALWATT_CONFIG_UPDATED_EVENT,
9
- NEURALWATT_EXTENSIONS_REGISTER_EVENT,
10
- NEURALWATT_EXTENSIONS_REQUEST_EVENT,
11
- NEURALWATT_QUOTAS_REQUEST_EVENT,
12
- NEURALWATT_QUOTAS_UPDATED_EVENT,
13
- type NeuralwattConfigUpdatedPayload,
14
- type NeuralwattQuotasUpdatedPayload,
15
- } from "../../src/events";
16
- import type { NeuralwattQuotas } from "../../src/types/quota-api";
17
- import {
18
- percentCreditsRemaining,
19
- percentEnergyRemaining,
20
- } from "../../src/utils/quota-bar";
21
- import { formatKwh, formatUsd } from "../../src/utils/quota-format";
22
- import { toUsageSnapshot } from "./snapshot";
23
-
24
- function formatStatus(quotas: NeuralwattQuotas, theme: Theme): string {
25
- const parts: string[] = [];
26
-
27
- const creditsRemaining = percentCreditsRemaining(quotas);
28
- const creditsColor =
29
- creditsRemaining > 50
30
- ? "success"
31
- : creditsRemaining > 20
32
- ? "warning"
33
- : "error";
34
- parts.push(
35
- `${theme.fg("dim", "credits:")} ${theme.fg(creditsColor, formatUsd(quotas.balance.credits_remaining_usd))}`,
36
- );
37
-
38
- if (quotas.subscription) {
39
- const energyRemaining = percentEnergyRemaining(quotas.subscription);
40
- const energyColor =
41
- energyRemaining > 50
42
- ? "success"
43
- : energyRemaining > 20
44
- ? "warning"
45
- : "error";
46
- parts.push(
47
- `${theme.fg("dim", "energy:")} ${theme.fg(energyColor, formatKwh(quotas.subscription.kwh_remaining))}`,
48
- );
49
- }
50
-
51
- return parts.join(" ");
52
- }
53
-
54
- export default async function (pi: ExtensionAPI) {
55
- await configLoader.load();
56
-
57
- let enabled = configLoader.getConfig().subBarIntegration.enabled;
58
- let subCoreReady = false;
59
- let currentProvider: string | undefined;
60
- let unsubscribeQuotas: (() => void) | undefined;
61
-
62
- // Listen for config changes at runtime
63
- pi.events.on(NEURALWATT_CONFIG_UPDATED_EVENT, (data: unknown) => {
64
- enabled = (data as NeuralwattConfigUpdatedPayload).config.subBarIntegration
65
- .enabled;
66
- });
67
-
68
- function isActive(): boolean {
69
- return currentProvider === "neuralwatt";
70
- }
71
-
72
- function emitUsage(quotas: NeuralwattQuotas): void {
73
- pi.events.emit("sub-core:update-current", {
74
- state: {
75
- provider: "neuralwatt",
76
- usage: toUsageSnapshot(quotas),
77
- },
78
- });
79
- }
80
-
81
- function requestQuotas(): void {
82
- pi.events.emit(NEURALWATT_QUOTAS_REQUEST_EVENT, undefined);
83
- }
84
-
85
- // The quota handler runs on the shared event bus, so it must only touch a
86
- // session ctx captured by a live session-scoped subscription: pi
87
- // invalidates session-bound ctx after session replacement (newSession/
88
- // fork/switchSession/reload), and dereferencing a stale ctx throws. We
89
- // subscribe in session_start (capturing the fresh ctx in the closure) and
90
- // unsubscribe in session_shutdown, before the ctx can go stale.
91
- function handleQuotas(ctx: ExtensionContext, data: unknown): void {
92
- if (!isActive() || !subCoreReady || !enabled) return;
93
- if (!data || typeof data !== "object") return;
94
- const { quotas } = data as NeuralwattQuotasUpdatedPayload;
95
- emitUsage(quotas);
96
-
97
- ctx.ui.setStatus("neuralwatt-usage", formatStatus(quotas, ctx.ui.theme));
98
- }
99
-
100
- pi.events.on("sub-core:ready", () => {
101
- subCoreReady = true;
102
- });
103
-
104
- pi.on("session_start", async (_event, ctx) => {
105
- unsubscribeQuotas?.();
106
- currentProvider = ctx.model?.provider;
107
- unsubscribeQuotas = pi.events.on(NEURALWATT_QUOTAS_UPDATED_EVENT, (data) =>
108
- handleQuotas(ctx, data),
109
- );
110
- });
111
-
112
- pi.on("model_select", async (_event, ctx) => {
113
- currentProvider = ctx.model?.provider;
114
-
115
- if (subCoreReady && isActive() && enabled) {
116
- requestQuotas();
117
- }
118
- });
119
-
120
- pi.on("session_shutdown", () => {
121
- unsubscribeQuotas?.();
122
- unsubscribeQuotas = undefined;
123
- currentProvider = undefined;
124
- });
125
-
126
- pi.events.on(NEURALWATT_EXTENSIONS_REQUEST_EVENT, () => {
127
- pi.events.emit(NEURALWATT_EXTENSIONS_REGISTER_EVENT, {
128
- feature: "subBarIntegration",
129
- });
130
- });
131
- }
@@ -1,47 +0,0 @@
1
- import type { NeuralwattQuotas } from "../../src/types/quota-api";
2
- import {
3
- percentCreditsRemaining,
4
- percentEnergyRemaining,
5
- } from "../../src/utils/quota-bar";
6
- import { formatKwh } from "../../src/utils/quota-format";
7
-
8
- interface RateWindow {
9
- label: string;
10
- usedPercent: number;
11
- resetDescription?: string;
12
- }
13
-
14
- export interface UsageSnapshot {
15
- provider: string;
16
- displayName: string;
17
- windows: RateWindow[];
18
- lastSuccessAt?: number;
19
- }
20
-
21
- export function toUsageSnapshot(quotas: NeuralwattQuotas): UsageSnapshot {
22
- const windows: RateWindow[] = [];
23
-
24
- const creditsRemaining = percentCreditsRemaining(quotas);
25
- const creditsUsed = 100 - creditsRemaining;
26
- windows.push({
27
- label: "Credits",
28
- usedPercent: Math.max(0, Math.min(100, creditsUsed)),
29
- });
30
-
31
- if (quotas.subscription) {
32
- const energyRemaining = percentEnergyRemaining(quotas.subscription);
33
- const energyUsed = 100 - energyRemaining;
34
- windows.push({
35
- label: "Energy",
36
- usedPercent: Math.max(0, Math.min(100, energyUsed)),
37
- resetDescription: `${formatKwh(quotas.subscription.kwh_remaining)} left`,
38
- });
39
- }
40
-
41
- return {
42
- provider: "neuralwatt",
43
- displayName: "Neuralwatt",
44
- windows,
45
- lastSuccessAt: Date.now(),
46
- };
47
- }