@aliou/pi-neuralwatt 0.20.0 → 0.21.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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # @aliou/pi-extension-template
2
2
 
3
+ ## 0.21.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ebddddb: Add `/neuralwatt:flex` to toggle between standard and flex model variants, including models routed through a virtual model.
8
+
9
+ ### Patch Changes
10
+
11
+ - ed3cf03: Seed System One classifier models in the offline fallback table and verify them in the model drift check, sharing the provider's served-model filter.
12
+
3
13
  ## 0.20.0
4
14
 
5
15
  ### Minor Changes
@@ -718,6 +718,20 @@ const NEURALWATT_MODELS = [
718
718
  costMultiplier: .65
719
719
  }]]
720
720
  ].flatMap(([family, variants]) => buildNeuralwattFamily(family, variants));
721
+ const NEURALWATT_CLASSIFIERS = [{
722
+ type: "classifier",
723
+ api: NEURALWATT_SYSTEM_ONE_API,
724
+ id: "mammoth-1",
725
+ name: "mammoth-1",
726
+ input: ["text"],
727
+ cost: {
728
+ input: .18,
729
+ output: 0,
730
+ cacheRead: .018,
731
+ cacheWrite: 0
732
+ },
733
+ contextWindow: 32753
734
+ }];
721
735
  // src/models/catalog.ts
722
736
  function isNeuralwattClassifierModel(model) {
723
737
  return model.type === "classifier";
@@ -785,15 +799,20 @@ function apiModelToProviderModel(model) {
785
799
  }
786
800
  return result;
787
801
  }
802
+ const SERVED_TASKS = [
803
+ "chat",
804
+ "completions",
805
+ "decision"
806
+ ];
807
+ function isServedApiModel(model) {
808
+ const meta = model.metadata;
809
+ return !!meta && !meta.deprecated && !meta.pricing.pricing_tbd && (!meta.capabilities.task || SERVED_TASKS.includes(meta.capabilities.task));
810
+ }
788
811
  function buildNeuralwattProviderModels() {
789
- return NEURALWATT_MODELS.map((model) => ({ ...model }));
812
+ return [...NEURALWATT_MODELS.map((model) => ({ ...model })), ...NEURALWATT_CLASSIFIERS.map((model) => ({ ...model }))];
790
813
  }
791
814
  function buildNeuralwattProviderModelsFromApi(apiModels) {
792
- return apiModels.filter((m) => m.metadata && !m.metadata.deprecated && !m.metadata.pricing.pricing_tbd && !(m.metadata.capabilities.task && ![
793
- "chat",
794
- "completions",
795
- "decision"
796
- ].includes(m.metadata.capabilities.task))).map((m) => m.metadata?.capabilities.task === "decision" ? apiModelToClassifierModel(m) : apiModelToProviderModel(m));
815
+ return apiModels.filter(isServedApiModel).map((m) => m.metadata?.capabilities.task === "decision" ? apiModelToClassifierModel(m) : apiModelToProviderModel(m));
797
816
  }
798
817
  function buildNeuralwattProviderModelsFromStore(storedModels) {
799
818
  return storedModels.map((model) => ({ ...model }));
@@ -0,0 +1,35 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { toggleFlexMode } from "./flex-mode";
3
+
4
+ export function registerFlexModeCommand(pi: ExtensionAPI): void {
5
+ pi.registerCommand("neuralwatt:flex", {
6
+ description: "Toggle the Neuralwatt flex variant of the current model",
7
+ handler: async (_args, ctx) => {
8
+ const result = await toggleFlexMode(pi, ctx);
9
+ switch (result.status) {
10
+ case "toggled":
11
+ ctx.ui.notify(
12
+ `Neuralwatt: flex mode ${result.enabled ? "enabled" : "disabled"}`,
13
+ "info",
14
+ );
15
+ return;
16
+ case "requires-neuralwatt":
17
+ ctx.ui.notify(
18
+ result.virtual
19
+ ? "Neuralwatt: flex mode is unavailable until the virtual model routes to a Neuralwatt model"
20
+ : "Neuralwatt: flex mode requires a Neuralwatt model",
21
+ "error",
22
+ );
23
+ return;
24
+ case "missing-variant":
25
+ ctx.ui.notify(
26
+ `Neuralwatt: ${result.variant} variant is unavailable for ${result.modelName}`,
27
+ "error",
28
+ );
29
+ return;
30
+ case "switch-failed":
31
+ ctx.ui.notify("Neuralwatt: could not switch models", "error");
32
+ }
33
+ },
34
+ });
35
+ }
@@ -0,0 +1,84 @@
1
+ import type { Api, AssistantMessage, Model } from "@earendil-works/pi-ai";
2
+ import type {
3
+ ExtensionAPI,
4
+ ExtensionContext,
5
+ SessionEntry,
6
+ } from "@earendil-works/pi-coding-agent";
7
+
8
+ const FLEX_MODEL_SUFFIX = "-flex";
9
+
10
+ export type FlexModeResult =
11
+ | { status: "toggled"; enabled: boolean }
12
+ | { status: "requires-neuralwatt"; virtual: boolean }
13
+ | {
14
+ status: "missing-variant";
15
+ modelName: string;
16
+ variant: "standard" | "flex";
17
+ }
18
+ | { status: "switch-failed" };
19
+
20
+ function isVirtualModel(model: { api: string } | undefined): boolean {
21
+ return model?.api === "pi-virtual";
22
+ }
23
+
24
+ function isFlexModelId(modelId: string): boolean {
25
+ return modelId.endsWith(FLEX_MODEL_SUFFIX);
26
+ }
27
+
28
+ function flexVariantId(modelId: string): string {
29
+ return isFlexModelId(modelId)
30
+ ? modelId.slice(0, -FLEX_MODEL_SUFFIX.length)
31
+ : `${modelId}${FLEX_MODEL_SUFFIX}`;
32
+ }
33
+
34
+ function latestResponse(
35
+ branch: readonly SessionEntry[],
36
+ ): AssistantMessage | undefined {
37
+ for (let i = branch.length - 1; i >= 0; i--) {
38
+ const entry = branch[i];
39
+ if (entry.type !== "message") continue;
40
+ const message = entry.message;
41
+ if (message.role !== "assistant") continue;
42
+ if (message.stopReason === "error" || message.stopReason === "aborted")
43
+ continue;
44
+ return message;
45
+ }
46
+ return undefined;
47
+ }
48
+
49
+ function resolveModel(ctx: ExtensionContext): Model<Api> | undefined {
50
+ const selected = ctx.model;
51
+ if (selected && !isVirtualModel(selected)) {
52
+ return selected.provider === "neuralwatt" ? selected : undefined;
53
+ }
54
+ const routed = latestResponse(ctx.sessionManager.getBranch());
55
+ return routed?.provider === "neuralwatt"
56
+ ? ctx.modelRegistry.find("neuralwatt", routed.model)
57
+ : undefined;
58
+ }
59
+
60
+ export async function toggleFlexMode(
61
+ pi: ExtensionAPI,
62
+ ctx: ExtensionContext,
63
+ ): Promise<FlexModeResult> {
64
+ const model = resolveModel(ctx);
65
+ if (!model) {
66
+ return {
67
+ status: "requires-neuralwatt",
68
+ virtual: isVirtualModel(ctx.model),
69
+ };
70
+ }
71
+
72
+ const target = ctx.modelRegistry.find("neuralwatt", flexVariantId(model.id));
73
+ if (!target) {
74
+ return {
75
+ status: "missing-variant",
76
+ modelName: model.name,
77
+ variant: isFlexModelId(model.id) ? "standard" : "flex",
78
+ };
79
+ }
80
+
81
+ const switched = await pi.setModel(target);
82
+ if (!switched) return { status: "switch-failed" };
83
+ return { status: "toggled", enabled: isFlexModelId(target.id) };
84
+ }
@@ -0,0 +1,11 @@
1
+ import { bindProjectConfig } from "@aliou/pi-utils-settings";
2
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
+ import { configLoader } from "../_shared/config";
4
+ import { registerFlexModeCommand } from "./command";
5
+
6
+ export default async function (pi: ExtensionAPI) {
7
+ await configLoader.load();
8
+ bindProjectConfig(pi, configLoader);
9
+
10
+ registerFlexModeCommand(pi);
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aliou/pi-neuralwatt",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "private": false,
@@ -23,6 +23,7 @@
23
23
  "pi": {
24
24
  "extensions": [
25
25
  "./extensions/provider/index.ts",
26
+ "./extensions/flex-mode/index.ts",
26
27
  "./extensions/command-quotas/index.ts",
27
28
  "./extensions/quota-warnings/index.ts"
28
29
  ],
@@ -8,7 +8,7 @@ import {
8
8
  resolveMaxTokens,
9
9
  type ThinkingLevelMap,
10
10
  } from "./build";
11
- import { NEURALWATT_MODELS } from "./public-models";
11
+ import { NEURALWATT_CLASSIFIERS, NEURALWATT_MODELS } from "./public-models";
12
12
 
13
13
  export type NeuralwattChatModel = NeuralwattCompiledModel;
14
14
 
@@ -125,26 +125,35 @@ function apiModelToProviderModel(
125
125
  return result;
126
126
  }
127
127
 
128
+ const SERVED_TASKS = ["chat", "completions", "decision"] as const;
129
+
130
+ export function isServedApiModel(
131
+ model: NeuralwattApiModel,
132
+ ): model is NeuralwattApiModel & {
133
+ metadata: NonNullable<NeuralwattApiModel["metadata"]>;
134
+ } {
135
+ const meta = model.metadata;
136
+ return (
137
+ !!meta &&
138
+ !meta.deprecated &&
139
+ !meta.pricing.pricing_tbd &&
140
+ (!meta.capabilities.task ||
141
+ (SERVED_TASKS as readonly string[]).includes(meta.capabilities.task))
142
+ );
143
+ }
144
+
128
145
  export function buildNeuralwattProviderModels(): NeuralwattModel[] {
129
- return NEURALWATT_MODELS.map((model) => ({ ...model }));
146
+ return [
147
+ ...NEURALWATT_MODELS.map((model) => ({ ...model })),
148
+ ...NEURALWATT_CLASSIFIERS.map((model) => ({ ...model })),
149
+ ];
130
150
  }
131
151
 
132
152
  export function buildNeuralwattProviderModelsFromApi(
133
153
  apiModels: readonly NeuralwattApiModel[],
134
154
  ): NeuralwattModel[] {
135
155
  const models = apiModels
136
- .filter(
137
- (m) =>
138
- m.metadata &&
139
- !m.metadata.deprecated &&
140
- !m.metadata.pricing.pricing_tbd &&
141
- !(
142
- m.metadata.capabilities.task &&
143
- !["chat", "completions", "decision"].includes(
144
- m.metadata.capabilities.task,
145
- )
146
- ),
147
- )
156
+ .filter(isServedApiModel)
148
157
  .map((m) =>
149
158
  m.metadata?.capabilities.task === "decision"
150
159
  ? apiModelToClassifierModel(m)
@@ -2,9 +2,10 @@ export {
2
2
  buildNeuralwattProviderModels,
3
3
  buildNeuralwattProviderModelsFromApi,
4
4
  buildNeuralwattProviderModelsFromStore,
5
+ isServedApiModel,
5
6
  type NeuralwattModel,
6
7
  } from "./catalog";
7
- export { NEURALWATT_MODELS } from "./public-models";
8
+ export { NEURALWATT_CLASSIFIERS, NEURALWATT_MODELS } from "./public-models";
8
9
  export {
9
10
  createNeuralwattRefreshModels,
10
11
  type FetchNeuralwattApiModels,
@@ -1,5 +1,7 @@
1
1
  import {
2
2
  buildNeuralwattFamily,
3
+ NEURALWATT_SYSTEM_ONE_API,
4
+ type NeuralwattClassifierModel,
3
5
  type NeuralwattModelFamily,
4
6
  type NeuralwattVariantSpec,
5
7
  type ProviderChatModelConfig,
@@ -412,3 +414,17 @@ const FAMILIES: [NeuralwattModelFamily, NeuralwattVariantSpec[]][] = [
412
414
  export const NEURALWATT_MODELS: ProviderChatModelConfig[] = FAMILIES.flatMap(
413
415
  ([family, variants]) => buildNeuralwattFamily(family, variants),
414
416
  );
417
+
418
+ // System One classifier models (`metadata.capabilities.task === "decision"`).
419
+ // Served on POST /v1/systemone; no reasoning, compat, or output tokens.
420
+ export const NEURALWATT_CLASSIFIERS: NeuralwattClassifierModel[] = [
421
+ {
422
+ type: "classifier",
423
+ api: NEURALWATT_SYSTEM_ONE_API,
424
+ id: "mammoth-1",
425
+ name: "mammoth-1",
426
+ input: ["text"],
427
+ cost: { input: 0.18, output: 0, cacheRead: 0.018, cacheWrite: 0 },
428
+ contextWindow: 32753,
429
+ },
430
+ ];