@aliou/pi-neuralwatt 0.7.6 → 0.8.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 +4 -2
- package/{src/extensions → extensions}/command-quotas/command.ts +2 -2
- package/extensions/command-quotas/components/progress-bar.ts +38 -0
- package/{src/extensions → extensions}/command-quotas/components/quota-tabs.ts +4 -4
- package/{src/extensions → extensions}/command-quotas/components/quotas-display.ts +1 -1
- package/{src/extensions → extensions}/command-quotas/index.ts +3 -3
- package/extensions/provider/commands/settings/index.ts +246 -0
- package/{src/extensions → extensions}/provider/index.ts +28 -20
- package/{src/extensions → extensions}/provider/models/hidden.ts +3 -3
- package/{src/extensions → extensions}/provider/quota-store.ts +4 -4
- package/{src/extensions → extensions}/provider/sse-quotas.ts +1 -1
- package/{src/extensions → extensions}/quota-warnings/index.ts +6 -7
- package/{src/extensions → extensions}/quota-warnings/notifier.ts +2 -2
- package/{src/extensions → extensions}/sub-bar-integration/index.ts +9 -10
- package/{src/extensions → extensions}/sub-bar-integration/snapshot.ts +3 -3
- package/package.json +20 -14
- package/schema.json +50 -6
- package/src/config/defaults.ts +17 -0
- package/src/config/index.ts +9 -0
- package/src/config/loader.ts +74 -0
- package/src/config/migration/01-disable-legacy-model-ids-by-default.ts +44 -0
- package/src/config/migration/02-flat-to-nested-config.ts +149 -0
- package/src/config/migration/index.ts +16 -0
- package/src/config/types.ts +77 -0
- package/src/{types/quota-events.ts → events.ts} +25 -13
- package/src/lib/neuralwatt-api.ts +1 -1
- package/src/types/quota-result.ts +12 -0
- package/src/utils/quota-bar.ts +0 -38
- package/src/config.ts +0 -210
- /package/{src/lib/env.ts → extensions/_shared/auth.ts} +0 -0
- /package/{src/extensions → extensions}/provider/context-overflow.ts +0 -0
- /package/{src/extensions → extensions}/provider/models/cache.ts +0 -0
- /package/{src/extensions → extensions}/provider/models/index.ts +0 -0
- /package/{src/extensions → extensions}/provider/models/legacy.ts +0 -0
- /package/{src/extensions → extensions}/provider/models/public-models.ts +0 -0
- /package/{src/extensions → extensions}/provider/rate-limit-error.ts +0 -0
- /package/{src/extensions → extensions}/provider/stream-simple.ts +0 -0
package/src/config.ts
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConfigLoader,
|
|
3
|
-
registerSettingsCommand,
|
|
4
|
-
type SettingsSection,
|
|
5
|
-
} from "@aliou/pi-utils-settings";
|
|
6
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import type { SettingItem } from "@earendil-works/pi-tui";
|
|
8
|
-
|
|
9
|
-
export type NeuralwattFeatureId =
|
|
10
|
-
| "quotaCommand"
|
|
11
|
-
| "quotaWarnings"
|
|
12
|
-
| "subBarIntegration";
|
|
13
|
-
|
|
14
|
-
export const NEURALWATT_EXTENSIONS_REQUEST_EVENT =
|
|
15
|
-
"neuralwatt:extensions:request" as const;
|
|
16
|
-
|
|
17
|
-
export const NEURALWATT_EXTENSIONS_REGISTER_EVENT =
|
|
18
|
-
"neuralwatt:extensions:register" as const;
|
|
19
|
-
|
|
20
|
-
export interface NeuralwattExtensionsRegisterPayload {
|
|
21
|
-
feature: NeuralwattFeatureId;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface NeuralwattConfig {
|
|
25
|
-
/** Show the quota command (/neuralwatt:quota). */
|
|
26
|
-
quotaCommand?: boolean;
|
|
27
|
-
/** Show quota warnings when credits or energy are low. */
|
|
28
|
-
quotaWarnings?: boolean;
|
|
29
|
-
/** Show usage in the sub-bar / status bar. */
|
|
30
|
-
subBarIntegration?: boolean;
|
|
31
|
-
/** Include legacy Neuralwatt model IDs in the model picker. */
|
|
32
|
-
includeLegacyModelIds?: boolean;
|
|
33
|
-
/** Include hidden Neuralwatt models discovered via the authenticated API. */
|
|
34
|
-
includeHiddenModels?: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface ResolvedNeuralwattConfig {
|
|
38
|
-
quotaCommand: boolean;
|
|
39
|
-
quotaWarnings: boolean;
|
|
40
|
-
subBarIntegration: boolean;
|
|
41
|
-
includeLegacyModelIds: boolean;
|
|
42
|
-
includeHiddenModels: boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const DEFAULTS: ResolvedNeuralwattConfig = {
|
|
46
|
-
quotaCommand: true,
|
|
47
|
-
quotaWarnings: true,
|
|
48
|
-
subBarIntegration: true,
|
|
49
|
-
includeLegacyModelIds: false,
|
|
50
|
-
includeHiddenModels: false,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const configLoader = new ConfigLoader<
|
|
54
|
-
NeuralwattConfig,
|
|
55
|
-
ResolvedNeuralwattConfig
|
|
56
|
-
>("neuralwatt", DEFAULTS, {
|
|
57
|
-
migrations: [
|
|
58
|
-
{
|
|
59
|
-
name: "disable-legacy-model-ids-by-default",
|
|
60
|
-
shouldRun: (config) => config.includeLegacyModelIds === undefined,
|
|
61
|
-
message:
|
|
62
|
-
"[neuralwatt] legacy model IDs (ids including the provider and the quantization) are disabled by default. You can enable them with /neuralwatt:settings.",
|
|
63
|
-
run: (config) => ({ ...config, includeLegacyModelIds: false }),
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
export const NEURALWATT_CONFIG_UPDATED_EVENT =
|
|
69
|
-
"neuralwatt:config:updated" as const;
|
|
70
|
-
|
|
71
|
-
export interface NeuralwattConfigUpdatedPayload {
|
|
72
|
-
config: ResolvedNeuralwattConfig;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function emitConfigUpdated(pi: ExtensionAPI): void {
|
|
76
|
-
pi.events.emit(NEURALWATT_CONFIG_UPDATED_EVENT, {
|
|
77
|
-
config: configLoader.getConfig(),
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface RegisterNeuralwattSettingsOptions {
|
|
82
|
-
getLoadedFeatures: () => Set<NeuralwattFeatureId>;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function featureRow(
|
|
86
|
-
id: NeuralwattFeatureId,
|
|
87
|
-
label: string,
|
|
88
|
-
description: string,
|
|
89
|
-
configValue: boolean,
|
|
90
|
-
isLoaded: boolean,
|
|
91
|
-
): SettingItem {
|
|
92
|
-
if (isLoaded) {
|
|
93
|
-
return {
|
|
94
|
-
id,
|
|
95
|
-
label,
|
|
96
|
-
description,
|
|
97
|
-
currentValue: configValue ? "enabled" : "disabled",
|
|
98
|
-
values: ["enabled", "disabled"],
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
id,
|
|
103
|
-
label,
|
|
104
|
-
description: `${description} (Not loaded by Pi)`,
|
|
105
|
-
currentValue: "unavailable",
|
|
106
|
-
values: [],
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function registerNeuralwattSettings(
|
|
111
|
-
pi: ExtensionAPI,
|
|
112
|
-
options: RegisterNeuralwattSettingsOptions,
|
|
113
|
-
): void {
|
|
114
|
-
const { getLoadedFeatures } = options;
|
|
115
|
-
|
|
116
|
-
registerSettingsCommand<NeuralwattConfig, ResolvedNeuralwattConfig>(pi, {
|
|
117
|
-
commandName: "neuralwatt:settings",
|
|
118
|
-
title: "Neuralwatt Settings",
|
|
119
|
-
configStore: configLoader,
|
|
120
|
-
buildSections: (tabConfig, resolved): SettingsSection[] => {
|
|
121
|
-
const loaded = getLoadedFeatures();
|
|
122
|
-
return [
|
|
123
|
-
{
|
|
124
|
-
label: "Features",
|
|
125
|
-
items: [
|
|
126
|
-
featureRow(
|
|
127
|
-
"quotaCommand",
|
|
128
|
-
"Quota command",
|
|
129
|
-
"Toggle the /neuralwatt:quota command, showing your API usage at a glance",
|
|
130
|
-
tabConfig?.quotaCommand ?? resolved.quotaCommand,
|
|
131
|
-
loaded.has("quotaCommand"),
|
|
132
|
-
),
|
|
133
|
-
featureRow(
|
|
134
|
-
"quotaWarnings",
|
|
135
|
-
"Quota warnings",
|
|
136
|
-
"Toggle notifications when credits or energy are running low",
|
|
137
|
-
tabConfig?.quotaWarnings ?? resolved.quotaWarnings,
|
|
138
|
-
loaded.has("quotaWarnings"),
|
|
139
|
-
),
|
|
140
|
-
featureRow(
|
|
141
|
-
"subBarIntegration",
|
|
142
|
-
"Sub-bar integration",
|
|
143
|
-
"Toggle integration with the status bar and sub-core",
|
|
144
|
-
tabConfig?.subBarIntegration ?? resolved.subBarIntegration,
|
|
145
|
-
loaded.has("subBarIntegration"),
|
|
146
|
-
),
|
|
147
|
-
],
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
label: "Other settings",
|
|
151
|
-
items: [
|
|
152
|
-
{
|
|
153
|
-
id: "includeLegacyModelIds",
|
|
154
|
-
label: "Legacy model IDs",
|
|
155
|
-
description:
|
|
156
|
-
"Include deprecated Neuralwatt model IDs as aliases in the model picker",
|
|
157
|
-
currentValue:
|
|
158
|
-
(tabConfig?.includeLegacyModelIds ??
|
|
159
|
-
resolved.includeLegacyModelIds)
|
|
160
|
-
? "include"
|
|
161
|
-
: "ignore",
|
|
162
|
-
values: ["include", "ignore"],
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
id: "includeHiddenModels",
|
|
166
|
-
label: "Hidden models",
|
|
167
|
-
description:
|
|
168
|
-
"Include Neuralwatt models that are accessible via API key but not advertised in the public model list",
|
|
169
|
-
currentValue:
|
|
170
|
-
(tabConfig?.includeHiddenModels ?? resolved.includeHiddenModels)
|
|
171
|
-
? "include"
|
|
172
|
-
: "ignore",
|
|
173
|
-
values: ["include", "ignore"],
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
},
|
|
177
|
-
];
|
|
178
|
-
},
|
|
179
|
-
onSettingChange: (id, newValue, config) => {
|
|
180
|
-
// Non-feature toggles are handled first so they are not blocked by the
|
|
181
|
-
// loaded-features guard (they are managed directly by the provider).
|
|
182
|
-
if (id === "includeLegacyModelIds") {
|
|
183
|
-
return { ...config, includeLegacyModelIds: newValue === "include" };
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (id === "includeHiddenModels") {
|
|
187
|
-
return { ...config, includeHiddenModels: newValue === "include" };
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (!getLoadedFeatures().has(id as NeuralwattFeatureId)) {
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const enabled = newValue === "enabled";
|
|
195
|
-
switch (id) {
|
|
196
|
-
case "quotaCommand":
|
|
197
|
-
return { ...config, quotaCommand: enabled };
|
|
198
|
-
case "quotaWarnings":
|
|
199
|
-
return { ...config, quotaWarnings: enabled };
|
|
200
|
-
case "subBarIntegration":
|
|
201
|
-
return { ...config, subBarIntegration: enabled };
|
|
202
|
-
default:
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
onSave: async () => {
|
|
207
|
-
emitConfigUpdated(pi);
|
|
208
|
-
},
|
|
209
|
-
});
|
|
210
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|