@kwirthmagnify/kwirth-common-ai 0.5.75 → 0.5.77
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 +29 -1
- package/dist/back.d.ts +2 -1
- package/dist/back.js +40 -5
- package/dist/front.js +127 -105
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
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
|
-
|
|
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,4 +1,4 @@
|
|
|
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;
|
|
@@ -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<{
|
package/dist/back.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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.streamText = 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.
|
|
@@ -113,18 +113,53 @@ const keyFingerprint = (key) => (0, crypto_1.createHash)('sha256').update(key).d
|
|
|
113
113
|
*/
|
|
114
114
|
const usageSubjectForKey = (key) => keyFingerprint(key);
|
|
115
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; };
|
|
116
152
|
/*
|
|
117
153
|
Records what a model was built from, so generateText can count against it. Called by buildModel; a
|
|
118
154
|
model built any other way simply has no origin and is not counted — never silently miscounted.
|
|
119
155
|
*/
|
|
120
156
|
const rememberOrigin = (model, llm, prov, key) => {
|
|
121
|
-
var _a, _b;
|
|
122
157
|
if (model && typeof model === 'object') {
|
|
123
158
|
modelOrigin.set(model, {
|
|
124
159
|
subject: keyFingerprint(key),
|
|
125
|
-
limits:
|
|
126
|
-
inputCostPerMillion: (
|
|
127
|
-
outputCostPerMillion: (
|
|
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)
|
|
128
163
|
});
|
|
129
164
|
}
|
|
130
165
|
return model;
|
package/dist/front.js
CHANGED
|
@@ -49,27 +49,51 @@ const material_1 = require("@mui/material");
|
|
|
49
49
|
That is why the "no deep imports" rule is only for PLUGINS — there it breaks @emotion, which loads a
|
|
50
50
|
copy of its own — and common-front and common-ai are the documented exception.
|
|
51
51
|
*/
|
|
52
|
-
const Download_1 = __importDefault(require("@mui/icons-material/Download"));
|
|
53
|
-
const Upload_1 = __importDefault(require("@mui/icons-material/Upload"));
|
|
54
52
|
const Visibility_1 = __importDefault(require("@mui/icons-material/Visibility"));
|
|
55
53
|
const VisibilityOff_1 = __importDefault(require("@mui/icons-material/VisibilityOff"));
|
|
56
|
-
const downloadJson = async (data, filename) => {
|
|
57
|
-
var _a;
|
|
58
|
-
const json = JSON.stringify(data, null, 2);
|
|
59
|
-
const tauri = window.__TAURI__;
|
|
60
|
-
if ((_a = tauri === null || tauri === void 0 ? void 0 : tauri.core) === null || _a === void 0 ? void 0 : _a.invoke) {
|
|
61
|
-
await tauri.core.invoke('save_file_dialog', { filename, content: json });
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const blob = new Blob([json], { type: 'application/json' });
|
|
65
|
-
const url = URL.createObjectURL(blob);
|
|
66
|
-
const a = document.createElement('a');
|
|
67
|
-
a.href = url;
|
|
68
|
-
a.download = filename;
|
|
69
|
-
a.click();
|
|
70
|
-
URL.revokeObjectURL(url);
|
|
71
|
-
};
|
|
72
54
|
const index_1 = require("./index");
|
|
55
|
+
/*
|
|
56
|
+
🔴 These dialogs HAVE NO Import/Export of their own, and that is deliberate — do not add them back.
|
|
57
|
+
|
|
58
|
+
Both lists travel in the core's configuration bundle, under `core/sharedAi` ('AI providers and
|
|
59
|
+
models'), which is reached from ☰ → Kwirth export / Kwirth import. It writes to the very same
|
|
60
|
+
configmap and secret these dialogs do, so a second door onto the same store could only diverge from
|
|
61
|
+
it — and it had: the local export emitted a hand-written subset of the provider, so the prices and
|
|
62
|
+
the limits added on 2026-10-26 were silently dropped, and the local import replaced the whole list
|
|
63
|
+
from an unvalidated file, with a `catch {}` that said nothing when the file was not one.
|
|
64
|
+
|
|
65
|
+
The bundle also honours the 'Include credentials' tick (see `redactSharedAi` in the core), which a
|
|
66
|
+
plain download of the list in clear could not.
|
|
67
|
+
*/
|
|
68
|
+
/*
|
|
69
|
+
The height of the content of BOTH config dialogs, and the one number that keeps them still.
|
|
70
|
+
|
|
71
|
+
The rule, and it is not negotiable the next time a field is added: THE CONTENT IS FIXED AND THE DIALOG
|
|
72
|
+
ADAPTS TO IT. One size for the two dialogs, because they are the same form seen twice and nothing is
|
|
73
|
+
more obviously broken than the two resizing against each other when the user switches between them.
|
|
74
|
+
|
|
75
|
+
Sized for the tallest state either form reaches (the limits editor: four units × two windows). Anything
|
|
76
|
+
taller scrolls inside its column — it does NOT grow the box.
|
|
77
|
+
*/
|
|
78
|
+
/*
|
|
79
|
+
🔴 THE CONTENT HAS A FIXED SIZE AND THE DIALOG ADAPTS TO IT. Never the reverse.
|
|
80
|
+
|
|
81
|
+
'Fixed' does NOT mean a magic number of pixels: that is how the gap between the form and the buttons
|
|
82
|
+
appeared —a panel taller than what was inside it— and how a dialog ends up half empty. It means the
|
|
83
|
+
content cannot CHANGE size: every field is always on screen (disabled when it does not apply, never
|
|
84
|
+
removed), captions are a single fixed line, and the columns are COL_WIDTH wide.
|
|
85
|
+
|
|
86
|
+
With nothing left that can grow or vanish, the form measures the same always, the list stretches to
|
|
87
|
+
whatever the form measures, and the dialog is simply as big as the two of them.
|
|
88
|
+
*/
|
|
89
|
+
/*
|
|
90
|
+
And the WIDTH of each of the two form columns, for the same reason. Fixed too, because 'adapts to the
|
|
91
|
+
content' cuts both ways: columns that stretch with the window are not a fixed content either, and a
|
|
92
|
+
percentage width is what once truncated the 'Temperature' label to 'Tempe…'.
|
|
93
|
+
|
|
94
|
+
These two plus the 220px list are the whole content, so the Paper can simply be as wide as they are.
|
|
95
|
+
*/
|
|
96
|
+
const COL_WIDTH = 340;
|
|
73
97
|
/* The four units in the order an admin thinks about them: what it costs, how often, how much it moved. */
|
|
74
98
|
const USAGE_ROWS = [
|
|
75
99
|
{ unit: index_1.EUsageUnit.COST, label: 'Cost (€/$)', of: a => a.cost },
|
|
@@ -126,16 +150,19 @@ const UsageLimitsEditor = (props) => {
|
|
|
126
150
|
react_1.default.createElement("b", null, "in memory"),
|
|
127
151
|
" (no SQL): they reset on every restart, and so do these limits."),
|
|
128
152
|
USAGE_ROWS.map(({ unit, label, of }) => {
|
|
129
|
-
var _a, _b, _c
|
|
153
|
+
var _a, _b, _c;
|
|
130
154
|
const w = (_a = limits[unit]) !== null && _a !== void 0 ? _a : { enabled: false };
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
/*
|
|
156
|
+
🔴 El gasto YA NO va bajo cada campo. Iba en el helperText de su ventana, y aparecía
|
|
157
|
+
sólo cuando había consumo — así que el diálogo CAMBIABA DE TAMAÑO al seleccionar un
|
|
158
|
+
modelo: ocho helpers que aparecen de golpe son ocho líneas más de alto, y el contenido
|
|
159
|
+
salta bajo el cursor. Un diálogo que se mueve mientras lo lees cuesta más que el dato
|
|
160
|
+
que daba, y el dato está en el panel de consumo.
|
|
161
|
+
*/
|
|
135
162
|
return (react_1.default.createElement(material_1.Stack, { key: unit, direction: 'row', spacing: 1, alignItems: 'flex-start' },
|
|
136
163
|
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'
|
|
138
|
-
react_1.default.createElement(material_1.TextField, { value: (
|
|
164
|
+
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' }),
|
|
165
|
+
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
166
|
})));
|
|
140
167
|
};
|
|
141
168
|
const LlmSelector = ({ llms, value, onChange, label = 'LLM', size = 'small', fullWidth = true }) => {
|
|
@@ -153,7 +180,6 @@ exports.LlmSelector = LlmSelector;
|
|
|
153
180
|
const AiConfigLlm = (props) => {
|
|
154
181
|
var _a, _b, _c;
|
|
155
182
|
const [llms, setLlms] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.llms)));
|
|
156
|
-
const importLlmRef = (0, react_1.useRef)(null);
|
|
157
183
|
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
|
|
158
184
|
const [showPassword, setShowPassword] = (0, react_1.useState)(false);
|
|
159
185
|
const [id, setId] = (0, react_1.useState)('');
|
|
@@ -163,8 +189,11 @@ const AiConfigLlm = (props) => {
|
|
|
163
189
|
const [useProviderKey, setUseProviderKey] = (0, react_1.useState)(true);
|
|
164
190
|
const [key, setKey] = (0, react_1.useState)('');
|
|
165
191
|
const [limits, setLimits] = (0, react_1.useState)({});
|
|
166
|
-
|
|
167
|
-
|
|
192
|
+
// Empty, not zero, and that is the whole point: empty means 'the provider's price', while 0 is a
|
|
193
|
+
// stated price — a free or self-hosted model. Defaulting these to 0 made every model declare that it
|
|
194
|
+
// was free, and no provider default could ever be reached.
|
|
195
|
+
const [inputCostPerMillion, setInputCostPerMillion] = (0, react_1.useState)('');
|
|
196
|
+
const [outputCostPerMillion, setOutputCostPerMillion] = (0, react_1.useState)('');
|
|
168
197
|
// Re-syncs state when the models arrive asynchronously (same race fix as AiConfigProvider): on open,
|
|
169
198
|
// the parent mounts the dialog with props.llms empty and requests them over WS; without this, the list
|
|
170
199
|
// stayed empty until the dialog was closed and reopened.
|
|
@@ -172,6 +201,14 @@ const AiConfigLlm = (props) => {
|
|
|
172
201
|
setLlms(JSON.parse(JSON.stringify(props.llms)));
|
|
173
202
|
setSelectedIndex(null);
|
|
174
203
|
}, [props.llms]);
|
|
204
|
+
/* What the selected provider charges, as the placeholder of an empty price field: the fallback is
|
|
205
|
+
only useful if the admin can SEE what they are inheriting before leaving the field blank. Nothing
|
|
206
|
+
declared on the provider, and the fallback is 0, so the placeholder says so instead of staying
|
|
207
|
+
empty — an empty cost box is exactly what made this look like 'free'. */
|
|
208
|
+
const providerCost = (providerName, field) => {
|
|
209
|
+
const p = props.providers.find(p => p.name === providerName);
|
|
210
|
+
return (p === null || p === void 0 ? void 0 : p[field]) !== undefined ? `${p[field]} (provider)` : '0 (provider)';
|
|
211
|
+
};
|
|
175
212
|
const onLlmSelected = (index) => {
|
|
176
213
|
var _a, _b, _c;
|
|
177
214
|
const l = llms[index];
|
|
@@ -182,8 +219,8 @@ const AiConfigLlm = (props) => {
|
|
|
182
219
|
setTemperature(l.temperature);
|
|
183
220
|
setUseProviderKey(l.useProviderKey);
|
|
184
221
|
setKey(l.key);
|
|
185
|
-
setInputCostPerMillion((_a = l.inputCostPerMillion) !== null && _a !== void 0 ? _a :
|
|
186
|
-
setOutputCostPerMillion((_b = l.outputCostPerMillion) !== null && _b !== void 0 ? _b :
|
|
222
|
+
setInputCostPerMillion((_a = l.inputCostPerMillion) !== null && _a !== void 0 ? _a : '');
|
|
223
|
+
setOutputCostPerMillion((_b = l.outputCostPerMillion) !== null && _b !== void 0 ? _b : '');
|
|
187
224
|
setLimits((_c = l.limits) !== null && _c !== void 0 ? _c : {});
|
|
188
225
|
setSelectedIndex(index);
|
|
189
226
|
}
|
|
@@ -196,14 +233,16 @@ const AiConfigLlm = (props) => {
|
|
|
196
233
|
setTemperature(0);
|
|
197
234
|
setUseProviderKey(false);
|
|
198
235
|
setKey('');
|
|
199
|
-
setInputCostPerMillion(
|
|
200
|
-
setOutputCostPerMillion(
|
|
236
|
+
setInputCostPerMillion('');
|
|
237
|
+
setOutputCostPerMillion('');
|
|
201
238
|
setLimits({});
|
|
202
239
|
};
|
|
203
240
|
const onAdd = () => {
|
|
204
|
-
//
|
|
205
|
-
// provider's
|
|
206
|
-
|
|
241
|
+
// Prices and limits travel ALWAYS, borrowed key or not, and a field left empty is left out so the
|
|
242
|
+
// back end falls back to the provider's. Writing a 0 for an empty price would persist 'free', and
|
|
243
|
+
// dropping the limits on a borrowed key cost the admin the only way of cutting one model short
|
|
244
|
+
// before the shared budget ran out.
|
|
245
|
+
const llm = Object.assign(Object.assign(Object.assign({ id, provider, model, temperature, useProviderKey, key }, (inputCostPerMillion === '' ? {} : { inputCostPerMillion })), (outputCostPerMillion === '' ? {} : { outputCostPerMillion })), { limits });
|
|
207
246
|
const updated = [...llms];
|
|
208
247
|
if (selectedIndex !== null)
|
|
209
248
|
updated[selectedIndex] = llm;
|
|
@@ -223,19 +262,19 @@ const AiConfigLlm = (props) => {
|
|
|
223
262
|
Add/Update button below the fold on a short screen: the form grew, the dialog did not, and the
|
|
224
263
|
control that applies the form to the list scrolled out of sight.
|
|
225
264
|
*/
|
|
226
|
-
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: '
|
|
265
|
+
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: 'auto', maxWidth: 'none', height: 'auto' } } },
|
|
227
266
|
react_1.default.createElement(material_1.DialogTitle, { sx: { pb: 1 } }, "AI \u2014 LLM config"),
|
|
228
267
|
react_1.default.createElement(material_1.DialogContent, { style: { display: 'flex' } },
|
|
229
|
-
react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px',
|
|
230
|
-
react_1.default.createElement(material_1.Box, { sx: {
|
|
268
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px', boxSizing: 'border-box', position: 'relative' } },
|
|
269
|
+
react_1.default.createElement(material_1.Box, { sx: { position: 'absolute', inset: 0, overflowY: 'auto', overflowX: 'hidden' } },
|
|
231
270
|
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
271
|
react_1.default.createElement(material_1.Stack, { direction: 'column' },
|
|
233
272
|
react_1.default.createElement(material_1.Typography, { sx: { fontWeight: selectedIndex === index ? 'bold' : 'normal' } }, llm.id),
|
|
234
273
|
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',
|
|
274
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', flexDirection: 'column', padding: '16px', minWidth: 0 } },
|
|
236
275
|
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: '
|
|
238
|
-
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex:
|
|
276
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 3, alignItems: 'stretch', sx: { flexWrap: 'wrap', height: '100%' } },
|
|
277
|
+
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
|
|
239
278
|
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
279
|
react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
|
|
241
280
|
react_1.default.createElement(material_1.InputLabel, null, "Provider"),
|
|
@@ -248,43 +287,27 @@ const AiConfigLlm = (props) => {
|
|
|
248
287
|
react_1.default.createElement(material_1.InputLabel, null, "Model"),
|
|
249
288
|
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
289
|
: (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.
|
|
252
|
-
|
|
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:
|
|
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:
|
|
290
|
+
react_1.default.createElement(material_1.TextField, { value: temperature, onChange: e => setTemperature(+e.target.value), label: 'Temperature', variant: 'standard', type: 'number', fullWidth: true }),
|
|
291
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { flexWrap: 'nowrap' } },
|
|
292
|
+
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 } }),
|
|
293
|
+
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
294
|
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
|
|
295
|
+
react_1.default.createElement(material_1.Typography, { flex: 1 }, "Use provider API Key"),
|
|
257
296
|
react_1.default.createElement(material_1.Checkbox, { checked: useProviderKey, onChange: e => setUseProviderKey(e.target.checked) })),
|
|
258
297
|
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
298
|
endAdornment: (react_1.default.createElement(material_1.InputAdornment, { position: 'end' },
|
|
260
299
|
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
300
|
} })),
|
|
262
|
-
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex:
|
|
301
|
+
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
|
|
263
302
|
react_1.default.createElement(material_1.Typography, { variant: 'subtitle2' }, "Usage limits"),
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
react_1.default.createElement(material_1.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !id || !model }, selectedIndex !== null ? 'Update' : 'Add'))))),
|
|
303
|
+
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 }),
|
|
304
|
+
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.")))),
|
|
305
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { pt: 2 } },
|
|
306
|
+
react_1.default.createElement(material_1.Button, { variant: 'outlined', size: 'small', onClick: onNew }, "New"),
|
|
307
|
+
react_1.default.createElement(material_1.Typography, { flex: 1 }),
|
|
308
|
+
react_1.default.createElement(material_1.Button, { color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
|
|
309
|
+
react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !id || !model }, selectedIndex !== null ? 'Update' : 'Add')))),
|
|
272
310
|
react_1.default.createElement(material_1.DialogActions, null,
|
|
273
|
-
react_1.default.createElement("input", { ref: importLlmRef, type: 'file', accept: '.json', style: { display: 'none' }, onChange: e => {
|
|
274
|
-
var _a;
|
|
275
|
-
const f = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
276
|
-
if (!f)
|
|
277
|
-
return;
|
|
278
|
-
const reader = new FileReader();
|
|
279
|
-
reader.onload = ev => { try {
|
|
280
|
-
setLlms(JSON.parse(ev.target.result));
|
|
281
|
-
}
|
|
282
|
-
catch (_a) { } };
|
|
283
|
-
reader.readAsText(f);
|
|
284
|
-
e.target.value = '';
|
|
285
|
-
} }),
|
|
286
|
-
react_1.default.createElement(material_1.Button, { variant: 'outlined', startIcon: react_1.default.createElement(Upload_1.default, { fontSize: 'small' }), onClick: () => { var _a; return (_a = importLlmRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }, "Import"),
|
|
287
|
-
react_1.default.createElement(material_1.Button, { variant: 'outlined', startIcon: react_1.default.createElement(Download_1.default, { fontSize: 'small' }), onClick: () => downloadJson(llms, 'kwirth-llms.json') }, "Export"),
|
|
288
311
|
react_1.default.createElement(material_1.Box, { flex: 1 }),
|
|
289
312
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(llms), variant: 'contained' }, "OK"),
|
|
290
313
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), variant: 'outlined' }, "Cancel"))));
|
|
@@ -293,7 +316,6 @@ exports.AiConfigLlm = AiConfigLlm;
|
|
|
293
316
|
const AiConfigProvider = (props) => {
|
|
294
317
|
var _a, _b;
|
|
295
318
|
const [providers, setProviders] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.providers)));
|
|
296
|
-
const importProvRef = (0, react_1.useRef)(null);
|
|
297
319
|
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
|
|
298
320
|
const [showPassword, setShowPassword] = (0, react_1.useState)(false);
|
|
299
321
|
const [loadingModels, setLoadingModels] = (0, react_1.useState)(false);
|
|
@@ -307,16 +329,22 @@ const AiConfigProvider = (props) => {
|
|
|
307
329
|
const [providerKey, setProviderKey] = (0, react_1.useState)('');
|
|
308
330
|
const [providerEndpoint, setProviderEndpoint] = (0, react_1.useState)('');
|
|
309
331
|
const [providerLimits, setProviderLimits] = (0, react_1.useState)({});
|
|
332
|
+
/* The DEFAULT price of this provider's models, which each model may override. Here so that adding a
|
|
333
|
+
model does not mean looking the provider's rate up again — not because the key has a price. */
|
|
334
|
+
const [providerInputCost, setProviderInputCost] = (0, react_1.useState)('');
|
|
335
|
+
const [providerOutputCost, setProviderOutputCost] = (0, react_1.useState)('');
|
|
310
336
|
const [pendingModels, setPendingModels] = (0, react_1.useState)([]); // solo para mostrar count en el botón
|
|
311
337
|
const onProviderSelected = (p, index) => {
|
|
312
|
-
var _a, _b, _c, _d, _e;
|
|
338
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
313
339
|
setProviderName(p.name);
|
|
314
340
|
setProviderType((_a = p.type) !== null && _a !== void 0 ? _a : p.name);
|
|
315
341
|
setProviderKey(p.key);
|
|
316
342
|
setProviderEndpoint((_b = p.endpoint) !== null && _b !== void 0 ? _b : '');
|
|
317
343
|
setProviderLimits((_c = p.limits) !== null && _c !== void 0 ? _c : {});
|
|
318
|
-
|
|
319
|
-
|
|
344
|
+
setProviderInputCost((_d = p.inputCostPerMillion) !== null && _d !== void 0 ? _d : '');
|
|
345
|
+
setProviderOutputCost((_e = p.outputCostPerMillion) !== null && _e !== void 0 ? _e : '');
|
|
346
|
+
loadedModelsRef.current = (_f = p.models) !== null && _f !== void 0 ? _f : [];
|
|
347
|
+
setPendingModels((_g = p.models) !== null && _g !== void 0 ? _g : []);
|
|
320
348
|
setSelectedIndex(index);
|
|
321
349
|
};
|
|
322
350
|
const onNew = () => {
|
|
@@ -327,6 +355,8 @@ const AiConfigProvider = (props) => {
|
|
|
327
355
|
setProviderKey('');
|
|
328
356
|
setProviderEndpoint('');
|
|
329
357
|
setProviderLimits({});
|
|
358
|
+
setProviderInputCost('');
|
|
359
|
+
setProviderOutputCost('');
|
|
330
360
|
loadedModelsRef.current = [];
|
|
331
361
|
setPendingModels([]);
|
|
332
362
|
};
|
|
@@ -335,11 +365,13 @@ const AiConfigProvider = (props) => {
|
|
|
335
365
|
return;
|
|
336
366
|
const endpoint = providerType === 'openai-compat' ? providerEndpoint : undefined;
|
|
337
367
|
const models = loadedModelsRef.current;
|
|
368
|
+
// An empty price is left OUT, never written as 0: a model inheriting it would be counted free.
|
|
369
|
+
const costs = Object.assign(Object.assign({}, (providerInputCost === '' ? { inputCostPerMillion: undefined } : { inputCostPerMillion: providerInputCost })), (providerOutputCost === '' ? { outputCostPerMillion: undefined } : { outputCostPerMillion: providerOutputCost }));
|
|
338
370
|
const updated = [...providers];
|
|
339
371
|
if (selectedIndex !== null)
|
|
340
|
-
updated[selectedIndex] = Object.assign(Object.assign({}, updated[selectedIndex]), { name: providerName, type: providerType, key: providerKey, models, endpoint, limits: providerLimits });
|
|
372
|
+
updated[selectedIndex] = Object.assign(Object.assign(Object.assign({}, updated[selectedIndex]), { name: providerName, type: providerType, key: providerKey, models, endpoint, limits: providerLimits }), costs);
|
|
341
373
|
else
|
|
342
|
-
updated.push({ name: providerName, type: providerType, key: providerKey, models, endpoint, limits: providerLimits });
|
|
374
|
+
updated.push(Object.assign({ name: providerName, type: providerType, key: providerKey, models, endpoint, limits: providerLimits }, costs));
|
|
343
375
|
setProviders(updated);
|
|
344
376
|
onNew();
|
|
345
377
|
};
|
|
@@ -368,11 +400,11 @@ const AiConfigProvider = (props) => {
|
|
|
368
400
|
setLoadingModels(false);
|
|
369
401
|
}
|
|
370
402
|
};
|
|
371
|
-
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: '
|
|
403
|
+
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: 'auto', maxWidth: 'none', height: 'auto' } } },
|
|
372
404
|
react_1.default.createElement(material_1.DialogTitle, { sx: { pb: 1 } }, "AI \u2014 Provider config"),
|
|
373
405
|
react_1.default.createElement(material_1.DialogContent, { style: { display: 'flex' } },
|
|
374
|
-
react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px',
|
|
375
|
-
react_1.default.createElement(material_1.Box, { sx: {
|
|
406
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: '0 0 220px', boxSizing: 'border-box', position: 'relative' } },
|
|
407
|
+
react_1.default.createElement(material_1.Box, { sx: { position: 'absolute', inset: 0, overflowY: 'auto' } },
|
|
376
408
|
react_1.default.createElement(material_1.List, { sx: { mr: 1 } }, providers.map((p, index) => {
|
|
377
409
|
var _a;
|
|
378
410
|
return (react_1.default.createElement(material_1.ListItemButton, { key: index, selected: selectedIndex === index, onClick: () => onProviderSelected(p, index) },
|
|
@@ -382,10 +414,10 @@ const AiConfigProvider = (props) => {
|
|
|
382
414
|
((_a = p.models) === null || _a === void 0 ? void 0 : _a.length) || 0,
|
|
383
415
|
" models loaded"))));
|
|
384
416
|
})))),
|
|
385
|
-
react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex',
|
|
417
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', flexDirection: 'column', padding: '16px', minWidth: 0 } },
|
|
386
418
|
react_1.default.createElement(material_1.Stack, { spacing: 2, style: { width: '100%' } },
|
|
387
419
|
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:
|
|
420
|
+
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
|
|
389
421
|
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
422
|
react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
|
|
391
423
|
react_1.default.createElement(material_1.InputLabel, null, "Type"),
|
|
@@ -395,32 +427,22 @@ const AiConfigProvider = (props) => {
|
|
|
395
427
|
endAdornment: (react_1.default.createElement(material_1.InputAdornment, { position: 'end' },
|
|
396
428
|
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
429
|
} }),
|
|
398
|
-
|
|
399
|
-
|
|
430
|
+
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' }),
|
|
431
|
+
react_1.default.createElement(material_1.Typography, { variant: 'subtitle2', sx: { pt: 1 } }, "Default model costs"),
|
|
432
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, sx: { flexWrap: 'wrap' } },
|
|
433
|
+
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 } }),
|
|
434
|
+
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 } })),
|
|
435
|
+
react_1.default.createElement(material_1.Typography, { variant: 'caption', color: 'text.secondary' }, "Used by models that declare no cost of their own.")),
|
|
436
|
+
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1, sx: { flex: `0 0 ${COL_WIDTH}px`, width: COL_WIDTH } },
|
|
400
437
|
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
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
438
|
+
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 })))),
|
|
439
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1, alignItems: 'center', sx: { pt: 2 } },
|
|
440
|
+
react_1.default.createElement(material_1.Button, { variant: 'outlined', onClick: onNew }, "New"),
|
|
441
|
+
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})` : ''}`)),
|
|
442
|
+
react_1.default.createElement(material_1.Typography, { flex: 1 }),
|
|
443
|
+
react_1.default.createElement(material_1.Button, { variant: 'text', color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
|
|
444
|
+
react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !providerName.trim() || !providerType }, selectedIndex !== null ? 'Update' : 'Add')))),
|
|
408
445
|
react_1.default.createElement(material_1.DialogActions, { sx: { p: 2 } },
|
|
409
|
-
react_1.default.createElement("input", { ref: importProvRef, type: 'file', accept: '.json', style: { display: 'none' }, onChange: e => {
|
|
410
|
-
var _a;
|
|
411
|
-
const f = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
412
|
-
if (!f)
|
|
413
|
-
return;
|
|
414
|
-
const reader = new FileReader();
|
|
415
|
-
reader.onload = ev => { try {
|
|
416
|
-
setProviders(JSON.parse(ev.target.result));
|
|
417
|
-
}
|
|
418
|
-
catch (_a) { } };
|
|
419
|
-
reader.readAsText(f);
|
|
420
|
-
e.target.value = '';
|
|
421
|
-
} }),
|
|
422
|
-
react_1.default.createElement(material_1.Button, { variant: 'outlined', startIcon: react_1.default.createElement(Upload_1.default, { fontSize: 'small' }), onClick: () => { var _a; return (_a = importProvRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }, "Import"),
|
|
423
|
-
react_1.default.createElement(material_1.Button, { variant: 'outlined', startIcon: react_1.default.createElement(Download_1.default, { fontSize: 'small' }), onClick: () => downloadJson(providers.map(p => { var _a; return (Object.assign({ name: p.name, type: (_a = p.type) !== null && _a !== void 0 ? _a : p.name, key: p.key }, (p.endpoint ? { endpoint: p.endpoint } : {}))); }), 'kwirth-providers.json') }, "Export"),
|
|
424
446
|
react_1.default.createElement(material_1.Box, { flex: 1 }),
|
|
425
447
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(providers), variant: 'contained' }, "Save"),
|
|
426
448
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), variant: 'outlined' }, "Cancel"))));
|
package/dist/index.d.ts
CHANGED