@aliou/pi-neuralwatt 0.18.0 → 0.19.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/CHANGELOG.md +624 -0
- package/README.md +40 -51
- package/dist/provider/index.d.ts +28 -0
- package/dist/provider/index.js +1142 -0
- package/extensions/_shared/config/index.ts +1 -0
- package/{src → extensions/_shared}/config/loader.ts +11 -25
- package/{src → extensions/_shared}/config/migration/02-flat-to-nested-config.ts +1 -1
- package/extensions/command-quotas/command.ts +12 -3
- package/extensions/command-quotas/components/quota-tabs.ts +1 -1
- package/extensions/command-quotas/components/quotas-display.ts +2 -1
- package/extensions/command-quotas/index.ts +15 -5
- package/extensions/provider/commands/settings/api-base-url-editor.ts +2 -6
- package/extensions/provider/commands/settings/index.ts +31 -5
- package/extensions/provider/index.ts +50 -33
- package/extensions/provider/quota-store.ts +2 -1
- package/extensions/quota-warnings/index.ts +4 -1
- package/extensions/shared/truncate.ts +292 -0
- package/package.json +27 -17
- package/schema.json +14 -0
- package/{extensions/provider → src}/api/anthropic-messages.ts +22 -8
- package/{extensions/provider → src}/api/openai-completions.ts +38 -7
- package/{extensions/provider → src}/api/system-one.ts +5 -3
- package/src/config/index.ts +1 -2
- package/src/config/resolve.ts +25 -0
- package/src/config/types.ts +11 -0
- package/{extensions/provider → src}/constants.ts +1 -0
- package/src/lib/neuralwatt-api.ts +15 -7
- package/{extensions/provider → src}/models/build.ts +10 -10
- package/{extensions/provider → src}/models/catalog.ts +1 -1
- package/{extensions/provider → src}/models/public-models.ts +0 -44
- package/{extensions/provider → src}/models/refresh.ts +16 -9
- package/{extensions/provider → src}/provider.ts +81 -46
- package/{extensions/provider → src}/sse-quotas.ts +5 -4
- package/{extensions/provider → src}/stream-simple.ts +3 -3
- /package/{src → extensions/_shared}/config/migration/03-rename-hidden-to-early-access.ts +0 -0
- /package/{src → extensions/_shared}/config/migration/04-remove-sub-bar-integration.ts +0 -0
- /package/{src → extensions/_shared}/config/migration/index.ts +0 -0
- /package/{extensions/provider → src}/api/types.ts +0 -0
- /package/{extensions/provider → src}/models/index.ts +0 -0
- /package/{extensions/provider → src}/rate-limit-error.ts +0 -0
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
|
|
44
|
+
Once installed, select `neuralwatt` as your provider and pick a model:
|
|
45
45
|
|
|
46
46
|
```
|
|
47
|
-
/model neuralwatt
|
|
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
|
|
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)
|
|
55
|
-
- `anthropic-messages
|
|
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
|
-
|
|
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,82 +65,71 @@ Check your API usage at a glance:
|
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
The quota command shows three tabs:
|
|
68
|
-
- **Subscription** (when subscribed)
|
|
69
|
-
- **Credits
|
|
70
|
-
- **Usage & Key
|
|
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.
|
|
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).
|
|
77
|
+
|
|
78
|
+
## Library use
|
|
79
|
+
|
|
80
|
+
Use `@aliou/pi-neuralwatt/provider` outside the coding agent:
|
|
81
|
+
|
|
82
|
+
Install the library with its runtime peers, `@earendil-works/pi-ai` and `typebox`.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { InMemoryModelsStore } from "@earendil-works/pi-ai";
|
|
86
|
+
import { createModels } from "@earendil-works/pi-ai/models";
|
|
87
|
+
import createNeuralwattProvider from "@aliou/pi-neuralwatt/provider";
|
|
88
|
+
|
|
89
|
+
const models = createModels({ modelsStore: new InMemoryModelsStore() });
|
|
90
|
+
models.setProvider(
|
|
91
|
+
createNeuralwattProvider({
|
|
92
|
+
baseUrl: "https://gateway.example.com/v1",
|
|
93
|
+
provenance: { referer: "https://my-app.example" },
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
await models.refresh();
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
All options are optional. Without credentials, the provider lists and refreshes the public catalog. `NEURALWATT_API_KEY` or a stored credential enables keyed models. The `X-NW-Conversation-ID` header comes from each request's `sessionId`. Set `provenance: { enabled: false }` to stop adding the `Referer` and conversation ID headers to inference requests.
|
|
77
100
|
|
|
78
101
|
## Settings
|
|
79
102
|
|
|
80
103
|
Configure features with `/neuralwatt:settings`:
|
|
81
104
|
|
|
82
105
|
- **API** — Choose between `openai-completions` (default) and `anthropic-messages`; applies on `/reload`
|
|
106
|
+
- **API base URL** — Send requests to a different base URL, such as a gateway; empty uses the Neuralwatt API
|
|
83
107
|
- **Quota command** — Show/hide `/neuralwatt:quota`
|
|
84
108
|
- **Quota warnings** — Enable/disable low quota notifications
|
|
85
109
|
|
|
86
110
|
The provider itself cannot be disabled — it is always loaded.
|
|
87
111
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
### Model Refresh
|
|
91
|
-
|
|
92
|
-
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.
|
|
93
|
-
|
|
94
|
-
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.
|
|
95
|
-
|
|
96
|
-
## Adding or Updating Models
|
|
97
|
-
|
|
98
|
-
Public models are hardcoded in `extensions/provider/models/public-models.ts` and validated against the live API. To update:
|
|
112
|
+
## Model list
|
|
99
113
|
|
|
100
|
-
|
|
101
|
-
2. Fix any discrepancies (missing models, changed context windows)
|
|
102
|
-
3. Re-run `pnpm test` to confirm
|
|
114
|
+
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.
|
|
103
115
|
|
|
104
116
|
## Development
|
|
105
117
|
|
|
106
|
-
### Setup
|
|
107
|
-
|
|
108
118
|
```bash
|
|
109
119
|
git clone https://github.com/aliou/pi-neuralwatt.git
|
|
110
120
|
cd pi-neuralwatt
|
|
111
|
-
|
|
112
|
-
# Install dependencies (sets up pre-commit hooks)
|
|
113
|
-
pnpm install && pnpm prepare
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Pre-commit hooks run on every commit:
|
|
117
|
-
- TypeScript type checking
|
|
118
|
-
- Biome linting
|
|
119
|
-
- Biome formatting with auto-fix
|
|
120
|
-
|
|
121
|
-
### Commands
|
|
122
|
-
|
|
123
|
-
```bash
|
|
124
|
-
# Type check
|
|
121
|
+
pnpm install
|
|
125
122
|
pnpm run typecheck
|
|
126
|
-
|
|
127
|
-
# Lint
|
|
128
123
|
pnpm run lint
|
|
129
|
-
|
|
130
|
-
# Format
|
|
131
|
-
pnpm run format
|
|
132
|
-
|
|
133
|
-
# Test
|
|
134
124
|
pnpm run test
|
|
125
|
+
pnpm run check:models # compare the built-in model list with the live API
|
|
135
126
|
```
|
|
136
127
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
This repository uses [Changesets](https://github.com/changesets/changesets) for versioning.
|
|
128
|
+
The pre-commit hook runs typecheck, lint, the lockfile check, and the changeset check. Releases use [Changesets](https://github.com/changesets/changesets).
|
|
140
129
|
|
|
141
130
|
## Requirements
|
|
142
131
|
|
|
143
|
-
- Pi coding agent
|
|
132
|
+
- Pi coding agent 1.4 or later
|
|
144
133
|
- Neuralwatt API key (configured in `~/.pi/agent/auth.json` or via `NEURALWATT_API_KEY`)
|
|
145
134
|
|
|
146
135
|
## Links
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AssistantMessageEventStream, Model, Provider, ProviderHeaders, ProviderStreams, SimpleStreamOptions, TranscriptContext } from "@earendil-works/pi-ai";
|
|
2
|
+
/**
|
|
3
|
+
* Neuralwatt serves every chat model twice: on an OpenAI-compatible
|
|
4
|
+
* `chat/completions` endpoint and on a vLLM-backed Anthropic-compatible
|
|
5
|
+
* `POST /v1/messages` endpoint. Exactly one serves the provider at a time.
|
|
6
|
+
*/
|
|
7
|
+
type NeuralwattApi = "openai-completions" | "anthropic-messages";
|
|
8
|
+
type AnyStreamSimple = (model: Model<string>, context: TranscriptContext, options?: SimpleStreamOptions) => AssistantMessageEventStream;
|
|
9
|
+
export declare const DEFAULT_ATTRIBUTION_URL = "https://pi.dev";
|
|
10
|
+
export declare const CONVERSATION_ID_HEADER = "X-NW-Conversation-ID";
|
|
11
|
+
interface ProvenanceOptions {
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
referer?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function provenanceRequestHeaders(options: ProvenanceOptions | undefined): ProviderHeaders | undefined;
|
|
16
|
+
export declare function withProvenanceHeaders(streams: ProviderStreams, headers: ProviderHeaders | undefined): ProviderStreams;
|
|
17
|
+
export declare const NEURALWATT_PROVIDER_ID = "neuralwatt";
|
|
18
|
+
export declare const NEURALWATT_BASE_URL = "https://api.neuralwatt.com/v1";
|
|
19
|
+
export declare const NEURALWATT_API_KEY_ENV = "NEURALWATT_API_KEY";
|
|
20
|
+
export interface NeuralwattProviderOptions {
|
|
21
|
+
api?: NeuralwattApi;
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
provenance?: ProvenanceOptions;
|
|
24
|
+
openAiStreamSimple?: AnyStreamSimple;
|
|
25
|
+
messagesStreamSimple?: AnyStreamSimple;
|
|
26
|
+
}
|
|
27
|
+
export default function createNeuralwattProvider(options?: NeuralwattProviderOptions): Provider<"openai-completions" | "anthropic-messages">;
|
|
28
|
+
export type { ProvenanceOptions };
|