@kwirthmagnify/kwirth-common-ai 0.5.74 → 0.5.76

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
@@ -4,7 +4,35 @@ Shared AI/LLM types and utilities for [Kwirth](https://kwirthmagnify.dev) AI plu
4
4
 
5
5
  ## What is this?
6
6
 
7
- This package contains the TypeScript interfaces and utilities for working with LLM providers and models in Kwirth: `ILlm`, `IProvider`, `IModel`, `buildModel`, `loadModels`, and related types.
7
+ The AI layer every Kwirth plugin shares, so that a plugin wanting to talk to an LLM does not have to
8
+ carry its own provider adapters, its own configuration dialogs, or its own spending controls.
9
+
10
+ It ships in three entry points:
11
+
12
+ - **`@kwirthmagnify/kwirth-common-ai`** — the isomorphic types: `ILlmProvider`, `ILlm`, `ILlmModel`,
13
+ `IAgent`, the AI toolset contract (`IAiToolsetInfo`, `EToolEffect`, `EToolSensitivity`,
14
+ `ECapability`), and the usage-limit model (`IUsageLimits`, `EUsageUnit`, `EUsagePeriod`).
15
+ - **`@kwirthmagnify/kwirth-common-ai/back`** — `buildModel` and the counted `generateText` /
16
+ `streamText`, which enforce the configured ceilings around every call.
17
+ - **`@kwirthmagnify/kwirth-common-ai/front`** — the React dialogs for configuring providers and
18
+ models, plus the LLM and toolset selectors.
19
+
20
+ ## Providers
21
+
22
+ One adapter per supported SDK: Google, OpenAI, OpenRouter, Mistral, Groq, DeepSeek, Anthropic, and
23
+ `openai-compat` for any OpenAI-compatible endpoint (Huawei MaaS, vLLM, LM Studio…).
24
+
25
+ ## Costs and usage limits
26
+
27
+ Each provider declares **default prices per million tokens**, and each model may override them — within
28
+ one provider, and on one key, each model costs a different amount. A model that states no price of its
29
+ own is charged at its provider's.
30
+
31
+ Ceilings can be set on tokens in, tokens out, calls and cost, per day and per month, and apply to
32
+ whichever is reached first. A model with no limits of its own inherits the provider's.
33
+
34
+ ⚠️ Spending is accounted **per API key**: models sharing a key share one budget, because that is what
35
+ the provider bills.
8
36
 
9
37
  ## Installation
10
38
 
package/dist/back.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { ILlm, ILlmProvider, ECapability, EToolEffect, EToolSensitivity, EUsagePeriod, EUsageUnit, IAiToolInfo, IAiToolsetInfo, IToolsetConfig, IUsageAmounts } from './index';
1
+ import { ILlm, ILlmProvider, ECapability, EToolEffect, EToolSensitivity, EUsagePeriod, EUsageUnit, IAiToolInfo, IAiToolsetInfo, IToolsetConfig, IUsageAmounts, IUsageLimits } from './index';
2
2
  import type { AppsV1Api, CoreV1Api, CustomObjectsApi, NetworkingV1Api } from '@kubernetes/client-node';
3
3
  interface ILogChannel {
4
4
  logInfo?: (msg: string) => void;
5
5
  logWarning?: (msg: string) => void;
6
6
  logError?: (msg: string) => void;
7
7
  }
8
- import { LanguageModel, ToolSet, generateText as sdkGenerateText } from 'ai';
8
+ import { LanguageModel, ToolSet, generateText as sdkGenerateText, streamText as sdkStreamText } from 'ai';
9
9
  import { z } from 'zod';
10
10
  export declare const buildModel: (llm: ILlm, providers: ILlmProvider[]) => LanguageModel | null;
11
11
  export declare enum EUsageScope {
@@ -38,6 +38,7 @@ export declare const setAiLogger: (logger: TAiLogger | undefined) => void;
38
38
  export declare const setUsageService: (service: IUsageService | undefined) => void;
39
39
  export declare const getUsageService: () => IUsageService | undefined;
40
40
  export declare const usageSubjectForKey: (key: string) => string;
41
+ export declare const effectiveLimits: (llm: ILlm, prov: ILlmProvider | undefined) => IUsageLimits | undefined;
41
42
  export declare const runWithUsageGuard: (options: {
42
43
  model?: unknown;
43
44
  }, call: () => Promise<{
@@ -73,6 +74,7 @@ export interface IVisionOptions<T> {
73
74
  export declare const generateVision: <T>(opts: IVisionOptions<T>) => Promise<IVisionResult<T>>;
74
75
  export declare const loadModels: (providers: ILlmProvider[], log: ILogChannel) => Promise<void>;
75
76
  export declare const generateText: typeof sdkGenerateText;
77
+ export declare const streamText: typeof sdkStreamText;
76
78
  export { Output, stepCountIs, tool } from 'ai';
77
79
  export type { LanguageModel, ToolSet } from 'ai';
78
80
  export { z } from 'zod';
package/dist/back.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildAgentTools = exports.resolveTools = exports.resolveToolRef = exports.invokeToolRef = exports.buildToolHost = exports.listToolsetInfos = exports.listToolsets = exports.getToolset = exports.unregisterToolset = exports.registerToolset = exports.isToolsetGrantedTo = exports.getToolsetGrants = exports.setToolsetGrants = exports.isBuiltInToolsetId = exports.defineTool = exports.runWithToolContext = exports.EToolEffect = exports.zodFromExample = exports.z = exports.tool = exports.stepCountIs = exports.Output = exports.generateText = exports.loadModels = exports.generateVision = exports.runWithUsageGuard = exports.usageSubjectForKey = exports.getUsageService = exports.setUsageService = exports.setAiLogger = exports.UsageLimitError = exports.EUsageScope = exports.buildModel = void 0;
3
+ exports.buildAgentTools = exports.resolveTools = exports.resolveToolRef = exports.invokeToolRef = exports.buildToolHost = exports.listToolsetInfos = exports.listToolsets = exports.getToolset = exports.unregisterToolset = exports.registerToolset = exports.isToolsetGrantedTo = exports.getToolsetGrants = exports.setToolsetGrants = exports.isBuiltInToolsetId = exports.defineTool = exports.runWithToolContext = exports.EToolEffect = exports.zodFromExample = exports.z = exports.tool = exports.stepCountIs = exports.Output = exports.streamText = exports.generateText = exports.loadModels = exports.generateVision = exports.runWithUsageGuard = exports.effectiveLimits = exports.usageSubjectForKey = exports.getUsageService = exports.setUsageService = exports.setAiLogger = exports.UsageLimitError = exports.EUsageScope = exports.buildModel = void 0;
4
4
  const index_1 = require("./index");
5
5
  // Aliased on purpose: the generateText this module EXPORTS is the wrapped one, and nothing below should
6
6
  // be able to reach the raw SDK call by accident — that is exactly how a call would escape the counters.
7
+ // streamText is aliased for the same reason: what leaves here is the counted one.
7
8
  const ai_1 = require("ai");
8
9
  const zod_1 = require("zod");
9
10
  const async_hooks_1 = require("async_hooks");
@@ -112,18 +113,53 @@ const keyFingerprint = (key) => (0, crypto_1.createHash)('sha256').update(key).d
112
113
  */
113
114
  const usageSubjectForKey = (key) => keyFingerprint(key);
114
115
  exports.usageSubjectForKey = usageSubjectForKey;
116
+ /* The four units as they are keyed inside IUsageLimits. Typed off the interface, so adding a fifth unit
117
+ breaks the build here instead of quietly leaving it out of the checks below. */
118
+ const UNIT_KEYS = ['tokensIn', 'tokensOut', 'calls', 'cost'];
119
+ /*
120
+ Does this set of limits say anything at all? An IUsageLimits that exists but has no window with a
121
+ number is the SAME as not having one, and the difference matters because that is exactly what the
122
+ dialog leaves behind when an admin empties the fields: the object survives, emptied.
123
+
124
+ Without this check an emptied model would stop inheriting the provider's limits —silently going from
125
+ limited to unlimited— which is the opposite of what clearing a field asks for.
126
+ */
127
+ const statesSomething = (limits) => !!limits && UNIT_KEYS.some(k => {
128
+ const w = limits[k];
129
+ return !!w && (w.daily !== undefined || w.monthly !== undefined);
130
+ });
131
+ /*
132
+ Which limits govern a model: ITS OWN if it states any, otherwise the provider's. Model first and the
133
+ provider as a default, and the borrowed key no longer decides — a cheap model and an expensive one on
134
+ the same key are not the same budget.
135
+
136
+ ⚠️ What it does NOT do is split the counter. Spending is counted per KEY (EUsageScope.LLM_KEY), so on
137
+ a borrowed key the ceiling set here is measured against what EVERY model sharing that key spent. It is
138
+ still worth setting —it is the only way to cut a model short before the shared budget runs out— but it
139
+ is not a per-model budget, and the dialog says so where the admin types it.
140
+ */
141
+ const effectiveLimits = (llm, prov) => statesSomething(llm.limits) ? llm.limits : prov === null || prov === void 0 ? void 0 : prov.limits;
142
+ exports.effectiveLimits = effectiveLimits;
143
+ /*
144
+ What a model costs, per million tokens: ITS OWN price if it has one, otherwise the provider's, and 0
145
+ if nobody said. Model first, because within one provider —and on one key— each model costs a different
146
+ amount, which is the whole reason the price could never be a property of the key.
147
+
148
+ `??` and not `||` on purpose: 0 is a stated price —a free or self-hosted model— and must NOT fall
149
+ through to the provider's.
150
+ */
151
+ const priceOf = (own, fallback) => { var _a; return (_a = own !== null && own !== void 0 ? own : fallback) !== null && _a !== void 0 ? _a : 0; };
115
152
  /*
116
153
  Records what a model was built from, so generateText can count against it. Called by buildModel; a
117
154
  model built any other way simply has no origin and is not counted — never silently miscounted.
118
155
  */
119
156
  const rememberOrigin = (model, llm, prov, key) => {
120
- var _a, _b;
121
157
  if (model && typeof model === 'object') {
122
158
  modelOrigin.set(model, {
123
159
  subject: keyFingerprint(key),
124
- limits: llm.useProviderKey ? prov === null || prov === void 0 ? void 0 : prov.limits : llm.limits,
125
- inputCostPerMillion: (_a = llm.inputCostPerMillion) !== null && _a !== void 0 ? _a : 0,
126
- outputCostPerMillion: (_b = llm.outputCostPerMillion) !== null && _b !== void 0 ? _b : 0
160
+ limits: (0, exports.effectiveLimits)(llm, prov),
161
+ inputCostPerMillion: priceOf(llm.inputCostPerMillion, prov === null || prov === void 0 ? void 0 : prov.inputCostPerMillion),
162
+ outputCostPerMillion: priceOf(llm.outputCostPerMillion, prov === null || prov === void 0 ? void 0 : prov.outputCostPerMillion)
127
163
  });
128
164
  }
129
165
  return model;
@@ -177,30 +213,36 @@ const costOf = (origin, tokensIn, tokensOut) => (tokensIn / 1000000) * origin.in
177
213
  offline, and sends something outward on every run. The same seam is what a wrapper around another SDK
178
214
  entry point (streamText) would use.
179
215
  */
180
- const runWithUsageGuard = async (options, call) => {
181
- var _a, _b, _c, _d, _e;
182
- const service = usageService;
183
- const origin = options.model && typeof options.model === 'object' ? modelOrigin.get(options.model) : undefined;
184
- if (!service || !origin)
185
- return await call();
186
- /*
187
- 🔴 The bookkeeping must never be what breaks the feature.
216
+ /*
217
+ 🔴 The bookkeeping must never be what breaks the feature.
188
218
 
189
- Both halves of this used to be plain `await`s on a database, sitting in the critical path of every
190
- AI call. When that database has a bad moment the cost is not a missing counter: it is the whole
191
- call. Measured on 2026-10-14 — `core-ai-usage: Connection Error: Connection ended unexpectedly` one
192
- second in, and then **exactly 120 seconds** until the caller's own timeout gave up. The AI never
193
- got a chance; the two minutes were spent waiting on an accounting read that was never going to
194
- answer, and the user saw a ticket open with no resolution guidance for no reason at all.
219
+ Both halves of this used to be plain `await`s on a database, sitting in the critical path of every
220
+ AI call. When that database has a bad moment the cost is not a missing counter: it is the whole
221
+ call. Measured on 2026-10-14 — `core-ai-usage: Connection Error: Connection ended unexpectedly` one
222
+ second in, and then **exactly 120 seconds** until the caller's own timeout gave up. The AI never
223
+ got a chance; the two minutes were spent waiting on an accounting read that was never going to
224
+ answer, and the user saw a ticket open with no resolution guidance for no reason at all.
195
225
 
196
- So: the read is BOUNDED and FAILS OPEN, and the write does not block the answer.
226
+ So: the read is BOUNDED and FAILS OPEN, and the write does not block the answer.
197
227
 
198
- Failing open is a deliberate trade and it is the uncomfortable one: for the span of a sick usage
199
- database, the ceilings are not enforced. The alternative is worse — an accounting hiccup leaving
200
- every channel in Kwirth without AI. It is said loudly in the log so it cannot pass unnoticed, and
201
- the limits apply again the moment the database answers.
202
- */
203
- const READ_TIMEOUT_MS = 5000;
228
+ Failing open is a deliberate trade and it is the uncomfortable one: for the span of a sick usage
229
+ database, the ceilings are not enforced. The alternative is worse — an accounting hiccup leaving
230
+ every channel in Kwirth without AI. It is said loudly in the log so it cannot pass unnoticed, and
231
+ the limits apply again the moment the database answers.
232
+ */
233
+ const READ_TIMEOUT_MS = 5000;
234
+ /*
235
+ The READ half of the counting: checks the ceilings BEFORE the call. Extracted from runWithUsageGuard
236
+ when streamText needed the same check without the same shape — a stream's caller needs the result
237
+ object immediately, so the guard cannot wrap the whole call (see the streamText wrapper below).
238
+ Bounded and fail-open; throws UsageLimitError when a ceiling is passed.
239
+ */
240
+ const usageGuardCheck = async (options) => {
241
+ var _a;
242
+ const service = usageService;
243
+ const origin = options.model && typeof options.model === 'object' ? modelOrigin.get(options.model) : undefined;
244
+ if (!service || !origin)
245
+ return;
204
246
  let read;
205
247
  const readStarted = Date.now();
206
248
  try {
@@ -229,6 +271,30 @@ const runWithUsageGuard = async (options, call) => {
229
271
  throw new UsageLimitError(exceeded);
230
272
  }
231
273
  }
274
+ };
275
+ /*
276
+ The WRITE half: what a call spent, recorded without blocking the answer. Sin `await`: la respuesta
277
+ ya está. Esperar al apunte solo añade el tiempo de la base a lo que el usuario percibe, y si la base
278
+ está mal, lo añade entero. Lo que se pierde al fallar es un contador; lo que se perdía antes era la
279
+ llamada.
280
+ */
281
+ const usageRecord = (options, result) => {
282
+ var _a, _b, _c, _d;
283
+ const service = usageService;
284
+ const origin = options.model && typeof options.model === 'object' ? modelOrigin.get(options.model) : undefined;
285
+ if (!service || !origin)
286
+ return;
287
+ const tokensIn = (_b = (_a = result.usage) === null || _a === void 0 ? void 0 : _a.inputTokens) !== null && _b !== void 0 ? _b : 0;
288
+ const tokensOut = (_d = (_c = result.usage) === null || _c === void 0 ? void 0 : _c.outputTokens) !== null && _d !== void 0 ? _d : 0;
289
+ void service.add(EUsageScope.LLM_KEY, origin.subject, {
290
+ tokensIn,
291
+ tokensOut,
292
+ calls: 1,
293
+ cost: costOf(origin, tokensIn, tokensOut)
294
+ }).catch(err => logUsage(`AI usage: could not record ${tokensIn + tokensOut} token(s) of a call that DID happen (${err}) — the counters are now short`));
295
+ };
296
+ const runWithUsageGuard = async (options, call) => {
297
+ await usageGuardCheck(options);
232
298
  /* 🔴 En `finally`, no después del `await`. La primera versión medía solo el camino feliz, que es
233
299
  justo el que no hacía falta medir: cuando una llamada se aborta por tiempo —el caso que se estaba
234
300
  investigando— el log no se ejecutaba y seguíamos sin saber si el tiempo era del modelo o de la
@@ -244,19 +310,9 @@ const runWithUsageGuard = async (options, call) => {
244
310
  finally {
245
311
  const callMs = Date.now() - callStarted;
246
312
  if (callMs > 30000 || !ok)
247
- logUsage(`AI usage: the model ${ok ? 'took' : 'FAILED after'} ${Math.round(callMs / 1000)} s (counters read in ${readMs} ms)`);
313
+ logUsage(`AI usage: the model ${ok ? 'took' : 'FAILED after'} ${Math.round(callMs / 1000)} s`);
248
314
  }
249
- const tokensIn = (_c = (_b = result.usage) === null || _b === void 0 ? void 0 : _b.inputTokens) !== null && _c !== void 0 ? _c : 0;
250
- const tokensOut = (_e = (_d = result.usage) === null || _d === void 0 ? void 0 : _d.outputTokens) !== null && _e !== void 0 ? _e : 0;
251
- /* Sin `await`: la respuesta ya está. Esperar al apunte solo añade el tiempo de la base a lo que el
252
- usuario percibe, y si la base está mal, lo añade entero. Lo que se pierde al fallar es un contador;
253
- lo que se perdía antes era la llamada. */
254
- void service.add(EUsageScope.LLM_KEY, origin.subject, {
255
- tokensIn,
256
- tokensOut,
257
- calls: 1,
258
- cost: costOf(origin, tokensIn, tokensOut)
259
- }).catch(err => logUsage(`AI usage: could not record ${tokensIn + tokensOut} token(s) of a call that DID happen (${err}) — the counters are now short`));
315
+ usageRecord(options, result);
260
316
  return result;
261
317
  };
262
318
  exports.runWithUsageGuard = runWithUsageGuard;
@@ -450,6 +506,24 @@ const inferZod = (value) => {
450
506
  restating generateText's generics here and keeping them in step with the SDK by hand.
451
507
  */
452
508
  exports.generateText = ((options) => (0, exports.runWithUsageGuard)(options, () => (0, ai_1.generateText)(options)));
509
+ /*
510
+ 🔴 streamText goes through the same counters as generateText, split in two because of the shape of a
511
+ stream: the ceilings are checked BEFORE the stream starts, and the usage is recorded when the stream
512
+ ends (the SDK reports it with the last chunk). The whole call cannot go through runWithUsageGuard —
513
+ the guard's promise resolves when the call finishes, but the caller needs the result object
514
+ IMMEDIATELY to consume textStream; awaiting the guard would deliver it only after the stream is over.
515
+ A failed stream records nothing, exactly like a failed generateText. First consumer: the vllm channel,
516
+ which re-streams what the model it routed to produces.
517
+ */
518
+ exports.streamText = (async (options) => {
519
+ await usageGuardCheck(options);
520
+ const result = (0, ai_1.streamText)(options);
521
+ // usage is a PromiseLike in the SDK: Promise.resolve gives it the .catch the record path needs.
522
+ void Promise.resolve(result.usage)
523
+ .then(usage => usageRecord(options, { usage }))
524
+ .catch(() => { });
525
+ return result;
526
+ });
453
527
  var ai_2 = require("ai");
454
528
  Object.defineProperty(exports, "Output", { enumerable: true, get: function () { return ai_2.Output; } });
455
529
  Object.defineProperty(exports, "stepCountIs", { enumerable: true, get: function () { return ai_2.stepCountIs; } });
package/dist/front.js CHANGED
@@ -70,6 +70,35 @@ const downloadJson = async (data, filename) => {
70
70
  URL.revokeObjectURL(url);
71
71
  };
72
72
  const index_1 = require("./index");
73
+ /*
74
+ The height of the content of BOTH config dialogs, and the one number that keeps them still.
75
+
76
+ The rule, and it is not negotiable the next time a field is added: THE CONTENT IS FIXED AND THE DIALOG
77
+ ADAPTS TO IT. One size for the two dialogs, because they are the same form seen twice and nothing is
78
+ more obviously broken than the two resizing against each other when the user switches between them.
79
+
80
+ Sized for the tallest state either form reaches (the limits editor: four units × two windows). Anything
81
+ taller scrolls inside its column — it does NOT grow the box.
82
+ */
83
+ /*
84
+ 🔴 THE CONTENT HAS A FIXED SIZE AND THE DIALOG ADAPTS TO IT. Never the reverse.
85
+
86
+ 'Fixed' does NOT mean a magic number of pixels: that is how the gap between the form and the buttons
87
+ appeared —a panel taller than what was inside it— and how a dialog ends up half empty. It means the
88
+ content cannot CHANGE size: every field is always on screen (disabled when it does not apply, never
89
+ removed), captions are a single fixed line, and the columns are COL_WIDTH wide.
90
+
91
+ With nothing left that can grow or vanish, the form measures the same always, the list stretches to
92
+ whatever the form measures, and the dialog is simply as big as the two of them.
93
+ */
94
+ /*
95
+ And the WIDTH of each of the two form columns, for the same reason. Fixed too, because 'adapts to the
96
+ content' cuts both ways: columns that stretch with the window are not a fixed content either, and a
97
+ percentage width is what once truncated the 'Temperature' label to 'Tempe…'.
98
+
99
+ These two plus the 220px list are the whole content, so the Paper can simply be as wide as they are.
100
+ */
101
+ const COL_WIDTH = 340;
73
102
  /* The four units in the order an admin thinks about them: what it costs, how often, how much it moved. */
74
103
  const USAGE_ROWS = [
75
104
  { unit: index_1.EUsageUnit.COST, label: 'Cost (€/$)', of: a => a.cost },
@@ -126,16 +155,19 @@ const UsageLimitsEditor = (props) => {
126
155
  react_1.default.createElement("b", null, "in memory"),
127
156
  " (no SQL): they reset on every restart, and so do these limits."),
128
157
  USAGE_ROWS.map(({ unit, label, of }) => {
129
- var _a, _b, _c, _d, _e;
158
+ var _a, _b, _c;
130
159
  const w = (_a = limits[unit]) !== null && _a !== void 0 ? _a : { enabled: false };
131
- // What has been spent goes in the helper text of its own window: next to the number it is
132
- // measured against, which is the only place it answers anything. It only costs height when
133
- // there IS usage, which is when it earns it.
134
- const spent = (amounts) => amounts ? `${formatSpent(of(amounts))} so far` : undefined;
160
+ /*
161
+ 🔴 El gasto YA NO va bajo cada campo. Iba en el helperText de su ventana, y aparecía
162
+ sólo cuando había consumo — así que el diálogo CAMBIABA DE TAMAÑO al seleccionar un
163
+ modelo: ocho helpers que aparecen de golpe son ocho líneas más de alto, y el contenido
164
+ salta bajo el cursor. Un diálogo que se mueve mientras lo lees cuesta más que el dato
165
+ que daba, y el dato está en el panel de consumo.
166
+ */
135
167
  return (react_1.default.createElement(material_1.Stack, { key: unit, direction: 'row', spacing: 1, alignItems: 'flex-start' },
136
168
  react_1.default.createElement(material_1.FormControlLabel, { sx: { width: '150px', flexShrink: 0, mr: 0, mt: 0.5 }, control: react_1.default.createElement(material_1.Checkbox, { size: 'small', checked: !!w.enabled, disabled: props.disabled, onChange: e => patch(unit, { enabled: e.target.checked }) }), label: react_1.default.createElement(material_1.Typography, { variant: 'body2' }, label) }),
137
- react_1.default.createElement(material_1.TextField, { value: (_b = w.daily) !== null && _b !== void 0 ? _b : '', onChange: e => patch(unit, { daily: numberOrUndefined(e.target.value) }), label: 'Per day', variant: 'standard', type: 'number', fullWidth: true, size: 'small', disabled: props.disabled || !w.enabled, inputProps: { min: 0 }, placeholder: 'no limit', helperText: spent((_c = props.usage) === null || _c === void 0 ? void 0 : _c.daily), FormHelperTextProps: { sx: { mt: 0 } } }),
138
- react_1.default.createElement(material_1.TextField, { value: (_d = w.monthly) !== null && _d !== void 0 ? _d : '', onChange: e => patch(unit, { monthly: numberOrUndefined(e.target.value) }), label: 'Per month', variant: 'standard', type: 'number', fullWidth: true, size: 'small', disabled: props.disabled || !w.enabled, inputProps: { min: 0 }, placeholder: 'no limit', helperText: spent((_e = props.usage) === null || _e === void 0 ? void 0 : _e.monthly), FormHelperTextProps: { sx: { mt: 0 } } })));
169
+ react_1.default.createElement(material_1.TextField, { value: (_b = w.daily) !== null && _b !== void 0 ? _b : '', onChange: e => patch(unit, { daily: numberOrUndefined(e.target.value) }), label: 'Per day', variant: 'standard', type: 'number', fullWidth: true, size: 'small', disabled: props.disabled || !w.enabled, inputProps: { min: 0 }, placeholder: 'no limit' }),
170
+ react_1.default.createElement(material_1.TextField, { value: (_c = w.monthly) !== null && _c !== void 0 ? _c : '', onChange: e => patch(unit, { monthly: numberOrUndefined(e.target.value) }), label: 'Per month', variant: 'standard', type: 'number', fullWidth: true, size: 'small', disabled: props.disabled || !w.enabled, inputProps: { min: 0 }, placeholder: 'no limit' })));
139
171
  })));
140
172
  };
141
173
  const LlmSelector = ({ llms, value, onChange, label = 'LLM', size = 'small', fullWidth = true }) => {
@@ -163,8 +195,11 @@ const AiConfigLlm = (props) => {
163
195
  const [useProviderKey, setUseProviderKey] = (0, react_1.useState)(true);
164
196
  const [key, setKey] = (0, react_1.useState)('');
165
197
  const [limits, setLimits] = (0, react_1.useState)({});
166
- const [inputCostPerMillion, setInputCostPerMillion] = (0, react_1.useState)(0);
167
- const [outputCostPerMillion, setOutputCostPerMillion] = (0, react_1.useState)(0);
198
+ // Empty, not zero, and that is the whole point: empty means 'the provider's price', while 0 is a
199
+ // stated price — a free or self-hosted model. Defaulting these to 0 made every model declare that it
200
+ // was free, and no provider default could ever be reached.
201
+ const [inputCostPerMillion, setInputCostPerMillion] = (0, react_1.useState)('');
202
+ const [outputCostPerMillion, setOutputCostPerMillion] = (0, react_1.useState)('');
168
203
  // Re-syncs state when the models arrive asynchronously (same race fix as AiConfigProvider): on open,
169
204
  // the parent mounts the dialog with props.llms empty and requests them over WS; without this, the list
170
205
  // stayed empty until the dialog was closed and reopened.
@@ -172,6 +207,14 @@ const AiConfigLlm = (props) => {
172
207
  setLlms(JSON.parse(JSON.stringify(props.llms)));
173
208
  setSelectedIndex(null);
174
209
  }, [props.llms]);
210
+ /* What the selected provider charges, as the placeholder of an empty price field: the fallback is
211
+ only useful if the admin can SEE what they are inheriting before leaving the field blank. Nothing
212
+ declared on the provider, and the fallback is 0, so the placeholder says so instead of staying
213
+ empty — an empty cost box is exactly what made this look like 'free'. */
214
+ const providerCost = (providerName, field) => {
215
+ const p = props.providers.find(p => p.name === providerName);
216
+ return (p === null || p === void 0 ? void 0 : p[field]) !== undefined ? `${p[field]} (provider)` : '0 (provider)';
217
+ };
175
218
  const onLlmSelected = (index) => {
176
219
  var _a, _b, _c;
177
220
  const l = llms[index];
@@ -182,8 +225,8 @@ const AiConfigLlm = (props) => {
182
225
  setTemperature(l.temperature);
183
226
  setUseProviderKey(l.useProviderKey);
184
227
  setKey(l.key);
185
- setInputCostPerMillion((_a = l.inputCostPerMillion) !== null && _a !== void 0 ? _a : 0);
186
- setOutputCostPerMillion((_b = l.outputCostPerMillion) !== null && _b !== void 0 ? _b : 0);
228
+ setInputCostPerMillion((_a = l.inputCostPerMillion) !== null && _a !== void 0 ? _a : '');
229
+ setOutputCostPerMillion((_b = l.outputCostPerMillion) !== null && _b !== void 0 ? _b : '');
187
230
  setLimits((_c = l.limits) !== null && _c !== void 0 ? _c : {});
188
231
  setSelectedIndex(index);
189
232
  }
@@ -196,14 +239,16 @@ const AiConfigLlm = (props) => {
196
239
  setTemperature(0);
197
240
  setUseProviderKey(false);
198
241
  setKey('');
199
- setInputCostPerMillion(0);
200
- setOutputCostPerMillion(0);
242
+ setInputCostPerMillion('');
243
+ setOutputCostPerMillion('');
201
244
  setLimits({});
202
245
  };
203
246
  const onAdd = () => {
204
- // Limits only travel with a model that has its OWN key: with a borrowed one the budget is the
205
- // provider's, and keeping a stale copy here would show a ceiling that nothing enforces.
206
- const llm = Object.assign({ id, provider, model, temperature, useProviderKey, key, inputCostPerMillion: inputCostPerMillion === '' ? 0 : inputCostPerMillion, outputCostPerMillion: outputCostPerMillion === '' ? 0 : outputCostPerMillion }, (useProviderKey ? {} : { limits }));
247
+ // Prices and limits travel ALWAYS, borrowed key or not, and a field left empty is left out so the
248
+ // back end falls back to the provider's. Writing a 0 for an empty price would persist 'free', and
249
+ // dropping the limits on a borrowed key cost the admin the only way of cutting one model short
250
+ // before the shared budget ran out.
251
+ const llm = Object.assign(Object.assign(Object.assign({ id, provider, model, temperature, useProviderKey, key }, (inputCostPerMillion === '' ? {} : { inputCostPerMillion })), (outputCostPerMillion === '' ? {} : { outputCostPerMillion })), { limits });
207
252
  const updated = [...llms];
208
253
  if (selectedIndex !== null)
209
254
  updated[selectedIndex] = llm;
@@ -223,19 +268,19 @@ const AiConfigLlm = (props) => {
223
268
  Add/Update button below the fold on a short screen: the form grew, the dialog did not, and the
224
269
  control that applies the form to the list scrolled out of sight.
225
270
  */
226
- return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: '90vw', maxWidth: '1200px', height: 'auto', maxHeight: '90vh' } } },
271
+ return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: 'auto', maxWidth: 'none', height: 'auto' } } },
227
272
  react_1.default.createElement(material_1.DialogTitle, { sx: { pb: 1 } }, "AI \u2014 LLM config"),
228
273
  react_1.default.createElement(material_1.DialogContent, { style: { display: 'flex' } },
229
- react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px', display: 'flex', flexDirection: 'column', boxSizing: 'border-box' } },
230
- react_1.default.createElement(material_1.Box, { sx: { flex: 1, overflowY: 'auto', overflowX: 'hidden', maxHeight: '70vh' } },
274
+ react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px', boxSizing: 'border-box', position: 'relative' } },
275
+ react_1.default.createElement(material_1.Box, { sx: { position: 'absolute', inset: 0, overflowY: 'auto', overflowX: 'hidden' } },
231
276
  react_1.default.createElement(material_1.List, { sx: { flexGrow: 1, mr: 2, width: '100%' } }, llms.map((llm, index) => (react_1.default.createElement(material_1.ListItemButton, { key: index, selected: selectedIndex === index, onClick: () => onLlmSelected(index) },
232
277
  react_1.default.createElement(material_1.Stack, { direction: 'column' },
233
278
  react_1.default.createElement(material_1.Typography, { sx: { fontWeight: selectedIndex === index ? 'bold' : 'normal' } }, llm.id),
234
279
  react_1.default.createElement(material_1.Typography, { color: 'darkgray', fontSize: 12 }, llm.provider)))))))),
235
- react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', alignItems: 'start', padding: '16px', minWidth: 0 } },
280
+ react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', flexDirection: 'column', padding: '16px', minWidth: 0 } },
236
281
  react_1.default.createElement(material_1.Stack, { spacing: 2, style: { width: '100%' } },
237
- react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 3, alignItems: 'flex-start', sx: { flexWrap: 'wrap' } },
238
- react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: 1, minWidth: '260px' } },
282
+ react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 3, alignItems: 'stretch', sx: { flexWrap: 'wrap', height: '100%' } },
283
+ react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
239
284
  react_1.default.createElement(material_1.TextField, { value: id, onChange: e => setId(e.target.value), placeholder: 'Enter LLM id', label: 'LLM ID', variant: 'standard', fullWidth: true }),
240
285
  react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
241
286
  react_1.default.createElement(material_1.InputLabel, null, "Provider"),
@@ -248,27 +293,26 @@ const AiConfigLlm = (props) => {
248
293
  react_1.default.createElement(material_1.InputLabel, null, "Model"),
249
294
  react_1.default.createElement(material_1.Select, { value: model, onChange: e => setModel(e.target.value), variant: 'standard', fullWidth: true, displayEmpty: true }, (_b = props.providers.find(p => p.name === provider)) === null || _b === void 0 ? void 0 : _b.models.map((m, i) => (react_1.default.createElement(material_1.MenuItem, { key: i, value: m.id }, m.name))))))
250
295
  : (react_1.default.createElement(material_1.TextField, { value: model, onChange: e => setModel(e.target.value), label: 'Model ID', placeholder: 'e.g. claude-sonnet-4-5, glm-5.2', variant: 'standard', fullWidth: true })),
251
- react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { flexWrap: 'wrap' } },
252
- react_1.default.createElement(material_1.TextField, { value: temperature, onChange: e => setTemperature(+e.target.value), label: 'Temperature', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: '110px' } }),
253
- react_1.default.createElement(material_1.TextField, { value: inputCostPerMillion, onChange: e => setInputCostPerMillion(e.target.value === '' ? '' : +e.target.value), label: 'Input cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: '110px' }, inputProps: { min: 0, step: 0.01 } }),
254
- react_1.default.createElement(material_1.TextField, { value: outputCostPerMillion, onChange: e => setOutputCostPerMillion(e.target.value === '' ? '' : +e.target.value), label: 'Output cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: '110px' }, inputProps: { min: 0, step: 0.01 } })),
296
+ react_1.default.createElement(material_1.TextField, { value: temperature, onChange: e => setTemperature(+e.target.value), label: 'Temperature', variant: 'standard', type: 'number', fullWidth: true }),
297
+ react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { flexWrap: 'nowrap' } },
298
+ react_1.default.createElement(material_1.TextField, { value: inputCostPerMillion, onChange: e => setInputCostPerMillion(e.target.value === '' ? '' : +e.target.value), label: 'Input cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: 0 }, inputProps: { min: 0, step: 0.01 }, placeholder: providerCost(provider, 'inputCostPerMillion'), InputLabelProps: { shrink: true } }),
299
+ react_1.default.createElement(material_1.TextField, { value: outputCostPerMillion, onChange: e => setOutputCostPerMillion(e.target.value === '' ? '' : +e.target.value), label: 'Output cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: 0 }, inputProps: { min: 0, step: 0.01 }, placeholder: providerCost(provider, 'outputCostPerMillion'), InputLabelProps: { shrink: true } })),
255
300
  react_1.default.createElement(material_1.Stack, { direction: 'row', alignItems: 'center' },
256
- react_1.default.createElement(material_1.Typography, { flex: 1 }, "Use provider API Key (or enter a specific one)"),
301
+ react_1.default.createElement(material_1.Typography, { flex: 1 }, "Use provider API Key"),
257
302
  react_1.default.createElement(material_1.Checkbox, { checked: useProviderKey, onChange: e => setUseProviderKey(e.target.checked) })),
258
303
  react_1.default.createElement(material_1.TextField, { value: key, onChange: e => setKey(e.target.value), disabled: useProviderKey, label: 'API Key', placeholder: 'Enter API Key', variant: 'standard', fullWidth: true, type: showPassword ? 'text' : 'password', InputProps: {
259
304
  endAdornment: (react_1.default.createElement(material_1.InputAdornment, { position: 'end' },
260
305
  react_1.default.createElement(material_1.IconButton, { onClick: () => setShowPassword(!showPassword), edge: 'end' }, showPassword ? react_1.default.createElement(VisibilityOff_1.default, null) : react_1.default.createElement(Visibility_1.default, null))))
261
306
  } })),
262
- react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: 1, minWidth: '260px' } },
307
+ react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
263
308
  react_1.default.createElement(material_1.Typography, { variant: 'subtitle2' }, "Usage limits"),
264
- useProviderKey
265
- ? react_1.default.createElement(material_1.Typography, { variant: 'caption', color: 'text.secondary' }, "Usage limits for this model live on its provider, because it borrows the provider's key \u2014 and that key is what gets billed.")
266
- : react_1.default.createElement(UsageLimitsEditor, { value: limits, onChange: setLimits, subject: `this model's own key`, usage: (_c = props.usage) === null || _c === void 0 ? void 0 : _c[id], durable: props.usageDurable }))),
267
- react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
268
- react_1.default.createElement(material_1.Button, { variant: 'outlined', size: 'small', onClick: onNew }, "New"),
269
- react_1.default.createElement(material_1.Typography, { flex: 1 }),
270
- react_1.default.createElement(material_1.Button, { color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
271
- react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !id || !model }, selectedIndex !== null ? 'Update' : 'Add'))))),
309
+ react_1.default.createElement(UsageLimitsEditor, { value: limits, onChange: setLimits, subject: `the key this model uses`, usage: (_c = props.usage) === null || _c === void 0 ? void 0 : _c[id], durable: props.usageDurable }),
310
+ react_1.default.createElement(material_1.Typography, { variant: 'caption', color: 'text.secondary' }, "Left empty, the provider's limits apply. Spending is counted per API key.")))),
311
+ react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { pt: 2 } },
312
+ react_1.default.createElement(material_1.Button, { variant: 'outlined', size: 'small', onClick: onNew }, "New"),
313
+ react_1.default.createElement(material_1.Typography, { flex: 1 }),
314
+ react_1.default.createElement(material_1.Button, { color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
315
+ react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !id || !model }, selectedIndex !== null ? 'Update' : 'Add')))),
272
316
  react_1.default.createElement(material_1.DialogActions, null,
273
317
  react_1.default.createElement("input", { ref: importLlmRef, type: 'file', accept: '.json', style: { display: 'none' }, onChange: e => {
274
318
  var _a;
@@ -307,16 +351,22 @@ const AiConfigProvider = (props) => {
307
351
  const [providerKey, setProviderKey] = (0, react_1.useState)('');
308
352
  const [providerEndpoint, setProviderEndpoint] = (0, react_1.useState)('');
309
353
  const [providerLimits, setProviderLimits] = (0, react_1.useState)({});
354
+ /* The DEFAULT price of this provider's models, which each model may override. Here so that adding a
355
+ model does not mean looking the provider's rate up again — not because the key has a price. */
356
+ const [providerInputCost, setProviderInputCost] = (0, react_1.useState)('');
357
+ const [providerOutputCost, setProviderOutputCost] = (0, react_1.useState)('');
310
358
  const [pendingModels, setPendingModels] = (0, react_1.useState)([]); // solo para mostrar count en el botón
311
359
  const onProviderSelected = (p, index) => {
312
- var _a, _b, _c, _d, _e;
360
+ var _a, _b, _c, _d, _e, _f, _g;
313
361
  setProviderName(p.name);
314
362
  setProviderType((_a = p.type) !== null && _a !== void 0 ? _a : p.name);
315
363
  setProviderKey(p.key);
316
364
  setProviderEndpoint((_b = p.endpoint) !== null && _b !== void 0 ? _b : '');
317
365
  setProviderLimits((_c = p.limits) !== null && _c !== void 0 ? _c : {});
318
- loadedModelsRef.current = (_d = p.models) !== null && _d !== void 0 ? _d : [];
319
- setPendingModels((_e = p.models) !== null && _e !== void 0 ? _e : []);
366
+ setProviderInputCost((_d = p.inputCostPerMillion) !== null && _d !== void 0 ? _d : '');
367
+ setProviderOutputCost((_e = p.outputCostPerMillion) !== null && _e !== void 0 ? _e : '');
368
+ loadedModelsRef.current = (_f = p.models) !== null && _f !== void 0 ? _f : [];
369
+ setPendingModels((_g = p.models) !== null && _g !== void 0 ? _g : []);
320
370
  setSelectedIndex(index);
321
371
  };
322
372
  const onNew = () => {
@@ -327,6 +377,8 @@ const AiConfigProvider = (props) => {
327
377
  setProviderKey('');
328
378
  setProviderEndpoint('');
329
379
  setProviderLimits({});
380
+ setProviderInputCost('');
381
+ setProviderOutputCost('');
330
382
  loadedModelsRef.current = [];
331
383
  setPendingModels([]);
332
384
  };
@@ -335,11 +387,13 @@ const AiConfigProvider = (props) => {
335
387
  return;
336
388
  const endpoint = providerType === 'openai-compat' ? providerEndpoint : undefined;
337
389
  const models = loadedModelsRef.current;
390
+ // An empty price is left OUT, never written as 0: a model inheriting it would be counted free.
391
+ const costs = Object.assign(Object.assign({}, (providerInputCost === '' ? { inputCostPerMillion: undefined } : { inputCostPerMillion: providerInputCost })), (providerOutputCost === '' ? { outputCostPerMillion: undefined } : { outputCostPerMillion: providerOutputCost }));
338
392
  const updated = [...providers];
339
393
  if (selectedIndex !== null)
340
- updated[selectedIndex] = Object.assign(Object.assign({}, updated[selectedIndex]), { name: providerName, type: providerType, key: providerKey, models, endpoint, limits: providerLimits });
394
+ updated[selectedIndex] = Object.assign(Object.assign(Object.assign({}, updated[selectedIndex]), { name: providerName, type: providerType, key: providerKey, models, endpoint, limits: providerLimits }), costs);
341
395
  else
342
- updated.push({ name: providerName, type: providerType, key: providerKey, models, endpoint, limits: providerLimits });
396
+ updated.push(Object.assign({ name: providerName, type: providerType, key: providerKey, models, endpoint, limits: providerLimits }, costs));
343
397
  setProviders(updated);
344
398
  onNew();
345
399
  };
@@ -368,11 +422,11 @@ const AiConfigProvider = (props) => {
368
422
  setLoadingModels(false);
369
423
  }
370
424
  };
371
- return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: '90vw', maxWidth: '1200px', height: 'auto', maxHeight: '90vh' } } },
425
+ return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: 'auto', maxWidth: 'none', height: 'auto' } } },
372
426
  react_1.default.createElement(material_1.DialogTitle, { sx: { pb: 1 } }, "AI \u2014 Provider config"),
373
427
  react_1.default.createElement(material_1.DialogContent, { style: { display: 'flex' } },
374
- react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px', display: 'flex', flexDirection: 'column', boxSizing: 'border-box' } },
375
- react_1.default.createElement(material_1.Box, { sx: { flex: 1, overflowY: 'auto', maxHeight: '70vh' } },
428
+ react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px', boxSizing: 'border-box', position: 'relative' } },
429
+ react_1.default.createElement(material_1.Box, { sx: { position: 'absolute', inset: 0, overflowY: 'auto' } },
376
430
  react_1.default.createElement(material_1.List, { sx: { mr: 1 } }, providers.map((p, index) => {
377
431
  var _a;
378
432
  return (react_1.default.createElement(material_1.ListItemButton, { key: index, selected: selectedIndex === index, onClick: () => onProviderSelected(p, index) },
@@ -382,10 +436,10 @@ const AiConfigProvider = (props) => {
382
436
  ((_a = p.models) === null || _a === void 0 ? void 0 : _a.length) || 0,
383
437
  " models loaded"))));
384
438
  })))),
385
- react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', alignItems: 'start', padding: '16px', minWidth: 0 } },
439
+ react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', flexDirection: 'column', padding: '16px', minWidth: 0 } },
386
440
  react_1.default.createElement(material_1.Stack, { spacing: 2, style: { width: '100%' } },
387
441
  react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 3, alignItems: 'flex-start', sx: { flexWrap: 'wrap' } },
388
- react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: 1, minWidth: '260px' } },
442
+ react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
389
443
  react_1.default.createElement(material_1.TextField, { label: 'Name', variant: 'standard', fullWidth: true, placeholder: 'e.g. huawei-maas, openai-prod', value: providerName, onChange: e => setProviderName(e.target.value), helperText: 'Unique identifier for this provider instance' }),
390
444
  react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
391
445
  react_1.default.createElement(material_1.InputLabel, null, "Type"),
@@ -395,16 +449,21 @@ const AiConfigProvider = (props) => {
395
449
  endAdornment: (react_1.default.createElement(material_1.InputAdornment, { position: 'end' },
396
450
  react_1.default.createElement(material_1.IconButton, { onClick: () => setShowPassword(!showPassword), edge: 'end' }, showPassword ? react_1.default.createElement(VisibilityOff_1.default, null) : react_1.default.createElement(Visibility_1.default, null))))
397
451
  } }),
398
- providerType === 'openai-compat' && (react_1.default.createElement(material_1.TextField, { label: 'Base URL', variant: 'standard', fullWidth: true, placeholder: 'https://your-maas-host/v1', value: providerEndpoint, onChange: e => setProviderEndpoint(e.target.value), helperText: 'OpenAI-compatible API base URL (e.g. Huawei MaaS, vLLM, LM Studio\u2026)' }))),
399
- react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: 1, minWidth: '260px' } },
452
+ react_1.default.createElement(material_1.TextField, { label: 'Base URL', variant: 'standard', fullWidth: true, placeholder: 'https://your-maas-host/v1', value: providerEndpoint, onChange: e => setProviderEndpoint(e.target.value), disabled: providerType !== 'openai-compat' }),
453
+ react_1.default.createElement(material_1.Typography, { variant: 'subtitle2', sx: { pt: 1 } }, "Default model costs"),
454
+ react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { flexWrap: 'wrap' } },
455
+ react_1.default.createElement(material_1.TextField, { value: providerInputCost, onChange: e => setProviderInputCost(e.target.value === '' ? '' : +e.target.value), label: 'Input cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: '110px' }, inputProps: { min: 0, step: 0.01 } }),
456
+ react_1.default.createElement(material_1.TextField, { value: providerOutputCost, onChange: e => setProviderOutputCost(e.target.value === '' ? '' : +e.target.value), label: 'Output cost /M', variant: 'standard', type: 'number', sx: { flex: 1, minWidth: '110px' }, inputProps: { min: 0, step: 0.01 } })),
457
+ react_1.default.createElement(material_1.Typography, { variant: 'caption', color: 'text.secondary' }, "Used by models that declare no cost of their own.")),
458
+ react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
400
459
  react_1.default.createElement(material_1.Typography, { variant: 'subtitle2' }, "Usage limits"),
401
- react_1.default.createElement(UsageLimitsEditor, { value: providerLimits, onChange: setProviderLimits, subject: `this provider's key`, disabled: !providerName.trim(), usage: (_b = props.usage) === null || _b === void 0 ? void 0 : _b[providerName], durable: props.usageDurable }))),
402
- react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, alignItems: 'center' },
403
- react_1.default.createElement(material_1.Button, { variant: 'outlined', onClick: onNew }, "New"),
404
- props.onLoadModels && (react_1.default.createElement(material_1.Button, { variant: 'outlined', onClick: onLoadModels, disabled: !providerType || !providerKey || loadingModels, startIcon: loadingModels ? react_1.default.createElement(material_1.CircularProgress, { size: 14 }) : undefined }, loadingModels ? 'Loading...' : `Load models${pendingModels.length ? ` (${pendingModels.length})` : ''}`)),
405
- react_1.default.createElement(material_1.Typography, { flex: 1 }),
406
- react_1.default.createElement(material_1.Button, { variant: 'text', color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
407
- react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !providerName.trim() || !providerType }, selectedIndex !== null ? 'Update' : 'Add'))))),
460
+ react_1.default.createElement(UsageLimitsEditor, { value: providerLimits, onChange: setProviderLimits, subject: `this provider's key`, disabled: !providerName.trim(), usage: (_b = props.usage) === null || _b === void 0 ? void 0 : _b[providerName], durable: props.usageDurable })))),
461
+ react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, alignItems: 'center', sx: { pt: 2 } },
462
+ react_1.default.createElement(material_1.Button, { variant: 'outlined', onClick: onNew }, "New"),
463
+ props.onLoadModels && (react_1.default.createElement(material_1.Button, { variant: 'outlined', onClick: onLoadModels, disabled: !providerType || !providerKey || loadingModels, startIcon: loadingModels ? react_1.default.createElement(material_1.CircularProgress, { size: 14 }) : undefined }, loadingModels ? 'Loading...' : `Load models${pendingModels.length ? ` (${pendingModels.length})` : ''}`)),
464
+ react_1.default.createElement(material_1.Typography, { flex: 1 }),
465
+ react_1.default.createElement(material_1.Button, { variant: 'text', color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
466
+ react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !providerName.trim() || !providerType }, selectedIndex !== null ? 'Update' : 'Add')))),
408
467
  react_1.default.createElement(material_1.DialogActions, { sx: { p: 2 } },
409
468
  react_1.default.createElement("input", { ref: importProvRef, type: 'file', accept: '.json', style: { display: 'none' }, onChange: e => {
410
469
  var _a;
package/dist/index.d.ts CHANGED
@@ -45,6 +45,8 @@ export interface ILlmProvider {
45
45
  models: ILlmModel[];
46
46
  endpoint?: string;
47
47
  limits?: IUsageLimits;
48
+ inputCostPerMillion?: number;
49
+ outputCostPerMillion?: number;
48
50
  }
49
51
  export interface ILlm {
50
52
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwirthmagnify/kwirth-common-ai",
3
- "version": "0.5.74",
3
+ "version": "0.5.76",
4
4
  "description": "Shared AI/LLM types and utilities for Kwirth AI plugins",
5
5
  "scripts": {
6
6
  "build": "del .\\dist\\* /s /q 2>nul & tsc",