@aliou/pi-neuralwatt 0.14.2 → 0.15.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/extensions/provider/commands/settings/index.ts +0 -73
- package/extensions/provider/index.ts +13 -35
- package/extensions/provider/models/catalog.ts +148 -0
- package/extensions/provider/models/index.ts +10 -37
- package/extensions/provider/models/refresh.ts +65 -183
- package/extensions/provider/provider.ts +19 -26
- package/package.json +1 -1
- package/schema.json +0 -22
- package/src/config/defaults.ts +0 -5
- package/src/config/loader.ts +0 -11
- package/src/config/migration/01-disable-legacy-model-ids-by-default.ts +15 -28
- package/src/config/migration/02-flat-to-nested-config.ts +35 -71
- package/src/config/migration/03-rename-hidden-to-early-access.ts +33 -38
- package/src/config/migration/04-enable-aliases-for-legacy-users.ts +16 -25
- package/src/config/migration/index.ts +5 -2
- package/src/config/types.ts +0 -19
- package/src/lib/neuralwatt-api.ts +7 -7
- package/extensions/provider/models/aliases.ts +0 -35
- package/extensions/provider/models/early-access.ts +0 -158
- package/extensions/provider/models/legacy.ts +0 -47
|
@@ -5,12 +5,15 @@ import type {
|
|
|
5
5
|
ProviderStreamOptions,
|
|
6
6
|
} from "@earendil-works/pi-ai";
|
|
7
7
|
import { stream, streamSimple } from "@earendil-works/pi-ai/compat";
|
|
8
|
-
import type {
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import type { NeuralwattModel } from "./models/catalog";
|
|
9
|
+
import {
|
|
10
|
+
buildNeuralwattProviderModelsFromApi,
|
|
11
|
+
buildNeuralwattProviderModelsFromStore,
|
|
12
|
+
} from "./models/catalog";
|
|
13
|
+
import {
|
|
14
|
+
createNeuralwattRefreshModels,
|
|
15
|
+
type FetchNeuralwattApiModels,
|
|
12
16
|
} from "./models/refresh";
|
|
13
|
-
import { refreshNeuralwattModels } from "./models/refresh";
|
|
14
17
|
import type { AnyStreamSimple } from "./stream-simple";
|
|
15
18
|
|
|
16
19
|
export const NEURALWATT_PROVIDER_ID = "neuralwatt";
|
|
@@ -24,9 +27,7 @@ const NEURALWATT_REQUEST_HEADERS = {
|
|
|
24
27
|
|
|
25
28
|
const API = "openai-completions" as const;
|
|
26
29
|
|
|
27
|
-
function toProviderModels(
|
|
28
|
-
models: readonly ProviderModelConfig[],
|
|
29
|
-
): Model<Api>[] {
|
|
30
|
+
function toProviderModels(models: NeuralwattModel[]): Model<Api>[] {
|
|
30
31
|
return models.map((model) => ({
|
|
31
32
|
...model,
|
|
32
33
|
api: model.api ?? API,
|
|
@@ -37,11 +38,17 @@ function toProviderModels(
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export function createNeuralwattProvider(
|
|
40
|
-
staticModels:
|
|
41
|
-
|
|
41
|
+
staticModels: NeuralwattModel[],
|
|
42
|
+
fetchApiModels: FetchNeuralwattApiModels,
|
|
42
43
|
streamSimpleOverride?: AnyStreamSimple,
|
|
43
44
|
): Provider {
|
|
44
45
|
let liveModels = toProviderModels(staticModels);
|
|
46
|
+
const refreshCatalog = createNeuralwattRefreshModels(
|
|
47
|
+
staticModels,
|
|
48
|
+
fetchApiModels,
|
|
49
|
+
buildNeuralwattProviderModelsFromApi,
|
|
50
|
+
buildNeuralwattProviderModelsFromStore,
|
|
51
|
+
);
|
|
45
52
|
|
|
46
53
|
return {
|
|
47
54
|
id: NEURALWATT_PROVIDER_ID,
|
|
@@ -65,8 +72,6 @@ export function createNeuralwattProvider(
|
|
|
65
72
|
if (await ctx.env(NEURALWATT_API_KEY_ENV)) {
|
|
66
73
|
return { type: "api_key", source: NEURALWATT_API_KEY_ENV };
|
|
67
74
|
}
|
|
68
|
-
// Anonymous availability: requests resolve with an empty key, and
|
|
69
|
-
// in aperture proxy mode the gateway owns auth.
|
|
70
75
|
return { type: "api_key", source: "anonymous" };
|
|
71
76
|
},
|
|
72
77
|
resolve: async ({ ctx, credential, signal }) => {
|
|
@@ -83,28 +88,16 @@ export function createNeuralwattProvider(
|
|
|
83
88
|
if (envKey) {
|
|
84
89
|
return { auth: { apiKey: envKey }, source: NEURALWATT_API_KEY_ENV };
|
|
85
90
|
}
|
|
86
|
-
// Resolve never fails: without a key the catalog is the hardcoded
|
|
87
|
-
// one and early-access discovery is skipped (anonymous playground
|
|
88
|
-
// traffic authenticates at stream time).
|
|
89
91
|
return { auth: { apiKey: "" }, source: "anonymous" };
|
|
90
92
|
},
|
|
91
93
|
},
|
|
92
94
|
},
|
|
93
95
|
getModels: () => liveModels,
|
|
94
96
|
refreshModels: async (context) => {
|
|
95
|
-
const
|
|
96
|
-
context,
|
|
97
|
-
refreshOptions(),
|
|
98
|
-
);
|
|
99
|
-
// Fresh or offline store: the refresh intentionally skipped the
|
|
100
|
-
// network; adopt the persisted catalog anyway so getModels reflects it
|
|
101
|
-
// (statics otherwise).
|
|
102
|
-
const next = refreshed ?? context.stored?.models;
|
|
103
|
-
if (!next || next.length === 0) return;
|
|
104
|
-
const adopted = toProviderModels(next as StoredProviderModels);
|
|
97
|
+
const models = await refreshCatalog(context);
|
|
105
98
|
await context.publish({
|
|
106
99
|
update: () => {
|
|
107
|
-
liveModels =
|
|
100
|
+
liveModels = toProviderModels(models);
|
|
108
101
|
},
|
|
109
102
|
});
|
|
110
103
|
},
|
package/package.json
CHANGED
package/schema.json
CHANGED
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
"$schema": {
|
|
9
9
|
"type": "string"
|
|
10
10
|
},
|
|
11
|
-
"provider": {
|
|
12
|
-
"$ref": "#/definitions/NeuralwattProviderConfig",
|
|
13
|
-
"description": "Provider/model behavior."
|
|
14
|
-
},
|
|
15
11
|
"quotaCommand": {
|
|
16
12
|
"$ref": "#/definitions/NeuralwattQuotaCommandConfig",
|
|
17
13
|
"description": "Quota command feature."
|
|
@@ -40,24 +36,6 @@
|
|
|
40
36
|
},
|
|
41
37
|
"additionalProperties": false
|
|
42
38
|
},
|
|
43
|
-
"NeuralwattProviderConfig": {
|
|
44
|
-
"type": "object",
|
|
45
|
-
"properties": {
|
|
46
|
-
"includeLegacyModelIds": {
|
|
47
|
-
"type": "boolean",
|
|
48
|
-
"description": "Include legacy Neuralwatt model IDs in the model picker."
|
|
49
|
-
},
|
|
50
|
-
"includeAliasedModelIds": {
|
|
51
|
-
"type": "boolean",
|
|
52
|
-
"description": "Include alternate creator-scoped Neuralwatt model IDs in the model picker."
|
|
53
|
-
},
|
|
54
|
-
"includeEarlyAccessModels": {
|
|
55
|
-
"type": "boolean",
|
|
56
|
-
"description": "Include early-access Neuralwatt models discovered via the authenticated API."
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
"additionalProperties": false
|
|
60
|
-
},
|
|
61
39
|
"NeuralwattQuotaCommandConfig": {
|
|
62
40
|
"type": "object",
|
|
63
41
|
"properties": {
|
package/src/config/defaults.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { ResolvedNeuralwattConfig } from "./types";
|
|
2
2
|
|
|
3
3
|
export const DEFAULT_CONFIG: ResolvedNeuralwattConfig = {
|
|
4
|
-
provider: {
|
|
5
|
-
includeLegacyModelIds: false,
|
|
6
|
-
includeAliasedModelIds: false,
|
|
7
|
-
includeEarlyAccessModels: false,
|
|
8
|
-
},
|
|
9
4
|
quotaCommand: {
|
|
10
5
|
enabled: true,
|
|
11
6
|
},
|
package/src/config/loader.ts
CHANGED
|
@@ -14,17 +14,6 @@ function normalizeResolvedConfig(
|
|
|
14
14
|
const config = resolved as Partial<ResolvedNeuralwattConfig>;
|
|
15
15
|
|
|
16
16
|
return {
|
|
17
|
-
provider: {
|
|
18
|
-
includeLegacyModelIds:
|
|
19
|
-
config.provider?.includeLegacyModelIds ??
|
|
20
|
-
DEFAULT_CONFIG.provider.includeLegacyModelIds,
|
|
21
|
-
includeAliasedModelIds:
|
|
22
|
-
config.provider?.includeAliasedModelIds ??
|
|
23
|
-
DEFAULT_CONFIG.provider.includeAliasedModelIds,
|
|
24
|
-
includeEarlyAccessModels:
|
|
25
|
-
config.provider?.includeEarlyAccessModels ??
|
|
26
|
-
DEFAULT_CONFIG.provider.includeEarlyAccessModels,
|
|
27
|
-
},
|
|
28
17
|
quotaCommand: {
|
|
29
18
|
enabled:
|
|
30
19
|
config.quotaCommand?.enabled ?? DEFAULT_CONFIG.quotaCommand.enabled,
|
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
import type { Migration } from "@aliou/pi-utils-settings";
|
|
2
|
-
import type { NeuralwattConfig } from "../types";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
("provider" in config && config.provider) ||
|
|
13
|
-
(config.quotaCommand && typeof config.quotaCommand === "object") ||
|
|
14
|
-
(config.quotaWarnings && typeof config.quotaWarnings === "object") ||
|
|
15
|
-
(config.subBarIntegration &&
|
|
16
|
-
typeof config.subBarIntegration === "object"),
|
|
17
|
-
);
|
|
3
|
+
/** Flat config shape before the 0.8.x nested migration. */
|
|
4
|
+
interface FlatNeuralwattConfig {
|
|
5
|
+
$schema?: string;
|
|
6
|
+
quotaCommand?: boolean;
|
|
7
|
+
quotaWarnings?: boolean;
|
|
8
|
+
subBarIntegration?: boolean;
|
|
9
|
+
includeLegacyModelIds?: boolean;
|
|
10
|
+
includeHiddenModels?: boolean;
|
|
18
11
|
}
|
|
19
12
|
|
|
20
13
|
function isPreviousConfigWithoutLegacyDefault(
|
|
21
|
-
config:
|
|
14
|
+
config: FlatNeuralwattConfig,
|
|
22
15
|
): boolean {
|
|
23
|
-
return
|
|
24
|
-
!hasNestedConfig(config) &&
|
|
25
|
-
!hasOwn(config as MutableConfigRecord, "includeLegacyModelIds")
|
|
26
|
-
);
|
|
16
|
+
return config.includeLegacyModelIds === undefined;
|
|
27
17
|
}
|
|
28
18
|
|
|
29
|
-
export const disableLegacyModelIdsByDefaultMigration: Migration<
|
|
19
|
+
export const disableLegacyModelIdsByDefaultMigration: Migration<FlatNeuralwattConfig> =
|
|
30
20
|
{
|
|
31
21
|
name: "disable-legacy-model-ids-by-default",
|
|
32
22
|
version: "0.8.0",
|
|
33
23
|
shouldRun: isPreviousConfigWithoutLegacyDefault,
|
|
34
24
|
message:
|
|
35
25
|
"[neuralwatt] legacy model IDs (ids including the provider and the quantization) are disabled by default. You can enable them with /neuralwatt:settings.",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
...config,
|
|
41
|
-
includeLegacyModelIds: false,
|
|
42
|
-
}) as unknown as NeuralwattConfig,
|
|
26
|
+
run: (config) => ({
|
|
27
|
+
...config,
|
|
28
|
+
includeLegacyModelIds: false,
|
|
29
|
+
}),
|
|
43
30
|
};
|
|
@@ -3,22 +3,14 @@ import { copyFile } from "node:fs/promises";
|
|
|
3
3
|
import { basename, dirname, join } from "node:path";
|
|
4
4
|
import type { Migration } from "@aliou/pi-utils-settings";
|
|
5
5
|
import packageJson from "../../../package.json";
|
|
6
|
-
import type { NeuralwattConfig } from "../types";
|
|
7
6
|
|
|
8
7
|
/** The original flat config, replaced by per-feature sections. */
|
|
9
8
|
interface FlatNeuralwattConfig {
|
|
10
|
-
|
|
9
|
+
$schema?: string;
|
|
11
10
|
quotaCommand?: boolean;
|
|
12
|
-
|
|
13
|
-
/** Show quota warnings when credits or energy are low. */
|
|
14
11
|
quotaWarnings?: boolean;
|
|
15
|
-
|
|
16
|
-
/** Show usage in the sub-bar / status bar. */
|
|
17
12
|
subBarIntegration?: boolean;
|
|
18
|
-
|
|
19
|
-
/** Include legacy Neuralwatt model IDs in the model picker. */
|
|
20
13
|
includeLegacyModelIds?: boolean;
|
|
21
|
-
|
|
22
14
|
/** Renamed to `provider.includeEarlyAccessModels` by migration 03. */
|
|
23
15
|
includeHiddenModels?: boolean;
|
|
24
16
|
}
|
|
@@ -50,7 +42,7 @@ function isObject(value: unknown): value is Record<string, unknown> {
|
|
|
50
42
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
51
43
|
}
|
|
52
44
|
|
|
53
|
-
function isPreviousConfig(config:
|
|
45
|
+
function isPreviousConfig(config: FlatNeuralwattConfig): boolean {
|
|
54
46
|
const record = config as MutableConfigRecord;
|
|
55
47
|
return FLAT_CONFIG_KEYS.some((key) => typeof record[key] === "boolean");
|
|
56
48
|
}
|
|
@@ -78,7 +70,7 @@ export async function backupConfig(filePath: string): Promise<void> {
|
|
|
78
70
|
}
|
|
79
71
|
}
|
|
80
72
|
|
|
81
|
-
export const flatToNestedConfigMigration: Migration<
|
|
73
|
+
export const flatToNestedConfigMigration: Migration<FlatNeuralwattConfig> = {
|
|
82
74
|
name: "flat-to-nested-config",
|
|
83
75
|
version: "0.8.1",
|
|
84
76
|
shouldRun: isPreviousConfig,
|
|
@@ -86,82 +78,54 @@ export const flatToNestedConfigMigration: Migration<NeuralwattConfig> = {
|
|
|
86
78
|
run: async (config, filePath) => {
|
|
87
79
|
await backupConfig(filePath);
|
|
88
80
|
|
|
89
|
-
const nestedConfig = config;
|
|
90
81
|
const record = config as unknown as MutableConfigRecord;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
82
|
+
|
|
83
|
+
// Preserve existing nested values from a partially-migrated config.
|
|
84
|
+
const existingProvider = isObject(record.provider)
|
|
85
|
+
? { ...record.provider }
|
|
86
|
+
: {};
|
|
87
|
+
const existingQuotaCommand = isObject(record.quotaCommand)
|
|
88
|
+
? { ...record.quotaCommand }
|
|
89
|
+
: {};
|
|
90
|
+
const existingQuotaWarnings = isObject(record.quotaWarnings)
|
|
91
|
+
? { ...record.quotaWarnings }
|
|
92
|
+
: {};
|
|
93
|
+
const existingSubBarIntegration = isObject(record.subBarIntegration)
|
|
94
|
+
? { ...record.subBarIntegration }
|
|
95
|
+
: {};
|
|
96
|
+
|
|
97
|
+
const nested = {
|
|
98
|
+
provider: existingProvider as Record<string, unknown>,
|
|
99
|
+
quotaCommand: existingQuotaCommand as Record<string, unknown>,
|
|
100
|
+
quotaWarnings: existingQuotaWarnings as Record<string, unknown>,
|
|
101
|
+
subBarIntegration: existingSubBarIntegration as Record<string, unknown>,
|
|
104
102
|
};
|
|
105
103
|
|
|
106
104
|
const includeLegacyModelIds = booleanValue(record, "includeLegacyModelIds");
|
|
107
|
-
if (
|
|
108
|
-
nested.provider
|
|
109
|
-
includeLegacyModelIds !== undefined
|
|
110
|
-
) {
|
|
111
|
-
nested.provider = {
|
|
112
|
-
...nested.provider,
|
|
113
|
-
includeLegacyModelIds,
|
|
114
|
-
};
|
|
105
|
+
if (includeLegacyModelIds !== undefined) {
|
|
106
|
+
nested.provider = { ...nested.provider, includeLegacyModelIds };
|
|
115
107
|
}
|
|
116
108
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"includeHiddenModels",
|
|
121
|
-
);
|
|
122
|
-
if (
|
|
123
|
-
nested.provider?.includeEarlyAccessModels === undefined &&
|
|
124
|
-
includeEarlyAccessModels !== undefined
|
|
125
|
-
) {
|
|
126
|
-
nested.provider = {
|
|
127
|
-
...nested.provider,
|
|
128
|
-
includeEarlyAccessModels,
|
|
129
|
-
};
|
|
109
|
+
const includeHiddenModels = booleanValue(record, "includeHiddenModels");
|
|
110
|
+
if (includeHiddenModels !== undefined) {
|
|
111
|
+
nested.provider = { ...nested.provider, includeHiddenModels };
|
|
130
112
|
}
|
|
131
113
|
|
|
132
114
|
const quotaCommand = booleanValue(record, "quotaCommand");
|
|
133
|
-
if (
|
|
134
|
-
nested.quotaCommand
|
|
135
|
-
quotaCommand !== undefined
|
|
136
|
-
) {
|
|
137
|
-
nested.quotaCommand = {
|
|
138
|
-
...nested.quotaCommand,
|
|
139
|
-
enabled: quotaCommand,
|
|
140
|
-
};
|
|
115
|
+
if (quotaCommand !== undefined) {
|
|
116
|
+
nested.quotaCommand = { enabled: quotaCommand };
|
|
141
117
|
}
|
|
142
118
|
|
|
143
119
|
const quotaWarnings = booleanValue(record, "quotaWarnings");
|
|
144
|
-
if (
|
|
145
|
-
nested.quotaWarnings
|
|
146
|
-
quotaWarnings !== undefined
|
|
147
|
-
) {
|
|
148
|
-
nested.quotaWarnings = {
|
|
149
|
-
...nested.quotaWarnings,
|
|
150
|
-
enabled: quotaWarnings,
|
|
151
|
-
};
|
|
120
|
+
if (quotaWarnings !== undefined) {
|
|
121
|
+
nested.quotaWarnings = { enabled: quotaWarnings };
|
|
152
122
|
}
|
|
153
123
|
|
|
154
124
|
const subBarIntegration = booleanValue(record, "subBarIntegration");
|
|
155
|
-
if (
|
|
156
|
-
nested.subBarIntegration
|
|
157
|
-
subBarIntegration !== undefined
|
|
158
|
-
) {
|
|
159
|
-
nested.subBarIntegration = {
|
|
160
|
-
...nested.subBarIntegration,
|
|
161
|
-
enabled: subBarIntegration,
|
|
162
|
-
};
|
|
125
|
+
if (subBarIntegration !== undefined) {
|
|
126
|
+
nested.subBarIntegration = { enabled: subBarIntegration };
|
|
163
127
|
}
|
|
164
128
|
|
|
165
|
-
return nested;
|
|
129
|
+
return nested as unknown as FlatNeuralwattConfig;
|
|
166
130
|
},
|
|
167
131
|
};
|
|
@@ -1,48 +1,43 @@
|
|
|
1
1
|
import type { Migration } from "@aliou/pi-utils-settings";
|
|
2
|
-
import type { NeuralwattConfig } from "../types";
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const { provider } = config;
|
|
17
|
-
return provider && typeof provider === "object"
|
|
18
|
-
? (provider as PreviousProviderConfig)
|
|
19
|
-
: undefined;
|
|
3
|
+
/** Nested config shape with `includeHiddenModels` (pre-0.10.6). */
|
|
4
|
+
interface PreRenameNeuralwattConfig {
|
|
5
|
+
$schema?: string;
|
|
6
|
+
provider?: {
|
|
7
|
+
includeLegacyModelIds?: boolean;
|
|
8
|
+
includeEarlyAccessModels?: boolean;
|
|
9
|
+
/** Renamed to `includeEarlyAccessModels`. */
|
|
10
|
+
includeHiddenModels?: boolean;
|
|
11
|
+
};
|
|
12
|
+
quotaCommand?: { enabled?: boolean };
|
|
13
|
+
quotaWarnings?: { enabled?: boolean };
|
|
14
|
+
subBarIntegration?: { enabled?: boolean };
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
/**
|
|
23
18
|
* `provider.includeHiddenModels` was renamed to `provider.includeEarlyAccessModels`.
|
|
24
19
|
* The models were never hidden, only released to authorized accounts first.
|
|
25
20
|
*/
|
|
26
|
-
export const renameHiddenToEarlyAccessMigration: Migration<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
export const renameHiddenToEarlyAccessMigration: Migration<PreRenameNeuralwattConfig> =
|
|
22
|
+
{
|
|
23
|
+
name: "rename-hidden-models-to-early-access",
|
|
24
|
+
version: "0.10.6",
|
|
25
|
+
shouldRun: (config) => config.provider?.includeHiddenModels !== undefined,
|
|
26
|
+
message:
|
|
27
|
+
"[neuralwatt] `provider.includeHiddenModels` is now `provider.includeEarlyAccessModels`.",
|
|
28
|
+
run: (config) => {
|
|
29
|
+
const provider = config.provider;
|
|
30
|
+
if (!provider) return config;
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
const { includeHiddenModels, ...rest } = provider;
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
34
|
+
return {
|
|
35
|
+
...config,
|
|
36
|
+
provider: {
|
|
37
|
+
...rest,
|
|
38
|
+
includeEarlyAccessModels:
|
|
39
|
+
rest.includeEarlyAccessModels ?? includeHiddenModels,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -1,42 +1,33 @@
|
|
|
1
1
|
import type { Migration } from "@aliou/pi-utils-settings";
|
|
2
|
-
import type { NeuralwattConfig } from "../types";
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const { provider } = config;
|
|
16
|
-
return provider && typeof provider === "object"
|
|
17
|
-
? (provider as PreviousProviderConfig)
|
|
18
|
-
: undefined;
|
|
3
|
+
/** Nested config shape before aliases were split out (pre-0.11.0). */
|
|
4
|
+
interface PreAliasNeuralwattConfig {
|
|
5
|
+
$schema?: string;
|
|
6
|
+
provider?: {
|
|
7
|
+
includeLegacyModelIds?: boolean;
|
|
8
|
+
includeAliasedModelIds?: boolean;
|
|
9
|
+
includeEarlyAccessModels?: boolean;
|
|
10
|
+
};
|
|
11
|
+
quotaCommand?: { enabled?: boolean };
|
|
12
|
+
quotaWarnings?: { enabled?: boolean };
|
|
13
|
+
subBarIntegration?: { enabled?: boolean };
|
|
19
14
|
}
|
|
20
15
|
|
|
21
16
|
/**
|
|
22
17
|
* Creator-scoped active model IDs were split out of the legacy model ID setting.
|
|
23
18
|
* Preserve behavior for users who had explicitly enabled legacy model IDs.
|
|
24
19
|
*/
|
|
25
|
-
export const enableAliasesForLegacyUsersMigration: Migration<
|
|
20
|
+
export const enableAliasesForLegacyUsersMigration: Migration<PreAliasNeuralwattConfig> =
|
|
26
21
|
{
|
|
27
22
|
name: "enable-alias-model-ids-for-legacy-users",
|
|
28
23
|
version: "0.11.0",
|
|
29
|
-
shouldRun: (config) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
provider?.includeLegacyModelIds === true &&
|
|
33
|
-
provider.includeAliasedModelIds === undefined
|
|
34
|
-
);
|
|
35
|
-
},
|
|
24
|
+
shouldRun: (config) =>
|
|
25
|
+
config.provider?.includeLegacyModelIds === true &&
|
|
26
|
+
config.provider?.includeAliasedModelIds === undefined,
|
|
36
27
|
message:
|
|
37
28
|
"[neuralwatt] active model aliases now use `provider.includeAliasedModelIds`; it was enabled because legacy model IDs were enabled.",
|
|
38
29
|
run: (config) => {
|
|
39
|
-
const provider =
|
|
30
|
+
const provider = config.provider;
|
|
40
31
|
if (!provider) return config;
|
|
41
32
|
|
|
42
33
|
return {
|
|
@@ -14,9 +14,12 @@ import { flatToNestedConfigMigration } from "./02-flat-to-nested-config";
|
|
|
14
14
|
import { renameHiddenToEarlyAccessMigration } from "./03-rename-hidden-to-early-access";
|
|
15
15
|
import { enableAliasesForLegacyUsersMigration } from "./04-enable-aliases-for-legacy-users";
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// Each migration is typed against its own historical input shape. The loader
|
|
18
|
+
// applies them in sequence on the raw config record, so they are cast to the
|
|
19
|
+
// current config type for the array.
|
|
20
|
+
export const migrations = [
|
|
18
21
|
disableLegacyModelIdsByDefaultMigration,
|
|
19
22
|
flatToNestedConfigMigration,
|
|
20
23
|
renameHiddenToEarlyAccessMigration,
|
|
21
24
|
enableAliasesForLegacyUsersMigration,
|
|
22
|
-
];
|
|
25
|
+
] as unknown as Migration<NeuralwattConfig>[];
|
package/src/config/types.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
export interface NeuralwattProviderConfig {
|
|
2
|
-
/** Include legacy Neuralwatt model IDs in the model picker. */
|
|
3
|
-
includeLegacyModelIds?: boolean;
|
|
4
|
-
|
|
5
|
-
/** Include alternate creator-scoped Neuralwatt model IDs in the model picker. */
|
|
6
|
-
includeAliasedModelIds?: boolean;
|
|
7
|
-
|
|
8
|
-
/** Include early-access Neuralwatt models discovered via the authenticated API. */
|
|
9
|
-
includeEarlyAccessModels?: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
1
|
export interface NeuralwattQuotaCommandConfig {
|
|
13
2
|
/** Show the quota command (/neuralwatt:quota). */
|
|
14
3
|
enabled?: boolean;
|
|
@@ -28,9 +17,6 @@ export interface NeuralwattConfig {
|
|
|
28
17
|
/** $schema URL for editor autocomplete. */
|
|
29
18
|
$schema?: string;
|
|
30
19
|
|
|
31
|
-
/** Provider/model behavior. */
|
|
32
|
-
provider?: NeuralwattProviderConfig;
|
|
33
|
-
|
|
34
20
|
/** Quota command feature. */
|
|
35
21
|
quotaCommand?: NeuralwattQuotaCommandConfig;
|
|
36
22
|
|
|
@@ -42,11 +28,6 @@ export interface NeuralwattConfig {
|
|
|
42
28
|
}
|
|
43
29
|
|
|
44
30
|
export interface ResolvedNeuralwattConfig {
|
|
45
|
-
provider: {
|
|
46
|
-
includeLegacyModelIds: boolean;
|
|
47
|
-
includeAliasedModelIds: boolean;
|
|
48
|
-
includeEarlyAccessModels: boolean;
|
|
49
|
-
};
|
|
50
31
|
quotaCommand: {
|
|
51
32
|
enabled: boolean;
|
|
52
33
|
};
|
|
@@ -8,6 +8,10 @@ import type { QuotasResult } from "../types/quota-result";
|
|
|
8
8
|
const BASE_URL = "https://api.neuralwatt.com/v1";
|
|
9
9
|
const FETCH_TIMEOUT_MS = 15_000;
|
|
10
10
|
|
|
11
|
+
function authHeaders(apiKey: string | undefined): Record<string, string> {
|
|
12
|
+
return apiKey && apiKey !== "-" ? { Authorization: `Bearer ${apiKey}` } : {};
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
function isTimeoutReason(reason: unknown): boolean {
|
|
12
16
|
return (
|
|
13
17
|
(reason instanceof DOMException && reason.name === "TimeoutError") ||
|
|
@@ -23,12 +27,12 @@ function combineSignals(signal?: AbortSignal): AbortSignal {
|
|
|
23
27
|
|
|
24
28
|
async function neuralwattFetch(
|
|
25
29
|
path: string,
|
|
26
|
-
apiKey: string,
|
|
30
|
+
apiKey: string | undefined,
|
|
27
31
|
signal?: AbortSignal,
|
|
28
32
|
headers?: Record<string, string>,
|
|
29
33
|
): Promise<Response> {
|
|
30
34
|
return fetch(`${BASE_URL}${path}`, {
|
|
31
|
-
headers: {
|
|
35
|
+
headers: { ...authHeaders(apiKey), ...headers },
|
|
32
36
|
signal: combineSignals(signal),
|
|
33
37
|
});
|
|
34
38
|
}
|
|
@@ -38,13 +42,9 @@ export type NeuralwattModelsResult =
|
|
|
38
42
|
| { success: false };
|
|
39
43
|
|
|
40
44
|
export async function fetchNeuralwattModels(
|
|
41
|
-
apiKey: string,
|
|
45
|
+
apiKey: string | undefined,
|
|
42
46
|
signal?: AbortSignal,
|
|
43
47
|
): Promise<NeuralwattModelsResult> {
|
|
44
|
-
if (!apiKey) {
|
|
45
|
-
return { success: false };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
48
|
const combined = combineSignals(signal);
|
|
49
49
|
|
|
50
50
|
try {
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { NEURALWATT_MODELS } from "./public-models";
|
|
3
|
-
|
|
4
|
-
// Alternate creator-scoped model IDs that Neuralwatt accepts for active models.
|
|
5
|
-
// These are only included when `includeAliasedModelIds` is enabled.
|
|
6
|
-
export const ALIAS_MODEL_MAP = {
|
|
7
|
-
"deepseek-ai/DeepSeek-V4-Flash": "deepseek-v4-flash",
|
|
8
|
-
"zai-org/GLM-5.2-FP8": "glm-5.2",
|
|
9
|
-
"moonshotai/Kimi-K2.7-Code": "kimi-k2.7-code",
|
|
10
|
-
"moonshotai/Kimi-K3": "kimi-k3",
|
|
11
|
-
"Qwen/Qwen3.6-35B-A3B": "qwen3.6-35b",
|
|
12
|
-
"nvidia/Gemma-4-31B-IT-NVFP4": "gemma-4-31b",
|
|
13
|
-
} as const;
|
|
14
|
-
|
|
15
|
-
export const ALIAS_NEURALWATT_MODEL_IDS = new Set<string>(
|
|
16
|
-
Object.keys(ALIAS_MODEL_MAP),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
export function buildAliasNeuralwattModels(
|
|
20
|
-
canonicalModels: ProviderModelConfig[] = NEURALWATT_MODELS,
|
|
21
|
-
): ProviderModelConfig[] {
|
|
22
|
-
return Object.entries(ALIAS_MODEL_MAP).flatMap(([aliasId, canonicalId]) => {
|
|
23
|
-
const canonical = canonicalModels.find((model) => model.id === canonicalId);
|
|
24
|
-
|
|
25
|
-
if (!canonical) return [];
|
|
26
|
-
|
|
27
|
-
return [
|
|
28
|
-
{
|
|
29
|
-
...canonical,
|
|
30
|
-
id: aliasId,
|
|
31
|
-
name: `${canonical.name} (alias ID)`,
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
});
|
|
35
|
-
}
|