@kwirthmagnify/kwirth-common-ai 0.5.33 → 0.5.34
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/dist/back.d.ts +6 -2
- package/dist/back.js +50 -6
- package/dist/front.js +15 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +2 -1
package/dist/back.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { IBackChannelObject } from '@kwirthmagnify/kwirth-common';
|
|
2
1
|
import { ILlm, ILlmProvider, IAgent } from './index';
|
|
2
|
+
interface ILogChannel {
|
|
3
|
+
logInfo?: (msg: string) => void;
|
|
4
|
+
logWarning?: (msg: string) => void;
|
|
5
|
+
logError?: (msg: string) => void;
|
|
6
|
+
}
|
|
3
7
|
import { LanguageModel } from 'ai';
|
|
4
8
|
import { z } from 'zod';
|
|
5
9
|
export declare const buildModel: (llm: ILlm, providers: ILlmProvider[]) => LanguageModel | null;
|
|
@@ -23,7 +27,7 @@ export interface IVisionOptions<T> {
|
|
|
23
27
|
mediaType?: string;
|
|
24
28
|
}
|
|
25
29
|
export declare const generateVision: <T>(opts: IVisionOptions<T>) => Promise<IVisionResult<T>>;
|
|
26
|
-
export declare const loadModels: (providers: ILlmProvider[], log:
|
|
30
|
+
export declare const loadModels: (providers: ILlmProvider[], log: ILogChannel) => Promise<void>;
|
|
27
31
|
export { generateText, Output, stepCountIs, tool } from 'ai';
|
|
28
32
|
export { z } from 'zod';
|
|
29
33
|
export declare const zodFromExample: (example: Record<string, unknown>) => z.ZodObject<Record<string, z.ZodTypeAny>>;
|
package/dist/back.js
CHANGED
|
@@ -47,9 +47,10 @@ const mistral_1 = require("@ai-sdk/mistral");
|
|
|
47
47
|
const google_1 = require("@ai-sdk/google");
|
|
48
48
|
const deepseek_1 = require("@ai-sdk/deepseek");
|
|
49
49
|
const ai_sdk_provider_1 = require("@openrouter/ai-sdk-provider");
|
|
50
|
+
const anthropic_1 = require("@ai-sdk/anthropic");
|
|
50
51
|
const buildModel = (llm, providers) => {
|
|
51
|
-
|
|
52
|
-
const key = llm.useProviderKey ?
|
|
52
|
+
const prov = providers.find(p => p.name === llm.provider);
|
|
53
|
+
const key = llm.useProviderKey ? prov === null || prov === void 0 ? void 0 : prov.key : llm.key;
|
|
53
54
|
if (!key) {
|
|
54
55
|
console.log('Could not find a key');
|
|
55
56
|
return null;
|
|
@@ -61,6 +62,8 @@ const buildModel = (llm, providers) => {
|
|
|
61
62
|
case 'google': return (0, google_1.createGoogleGenerativeAI)({ apiKey: key })(llm.model);
|
|
62
63
|
case 'deepseek': return (0, deepseek_1.createDeepSeek)({ apiKey: key })(llm.model);
|
|
63
64
|
case 'openrouter': return (0, ai_sdk_provider_1.createOpenRouter)({ apiKey: key })(llm.model);
|
|
65
|
+
case 'anthropic': return (0, anthropic_1.createAnthropic)({ apiKey: key })(llm.model);
|
|
66
|
+
case 'openai-compat': return (0, openai_1.createOpenAI)({ apiKey: key, baseURL: prov === null || prov === void 0 ? void 0 : prov.endpoint })(llm.model);
|
|
64
67
|
default:
|
|
65
68
|
console.log('Invalid provider', llm.provider);
|
|
66
69
|
return null;
|
|
@@ -88,7 +91,7 @@ const generateVision = async (opts) => {
|
|
|
88
91
|
};
|
|
89
92
|
exports.generateVision = generateVision;
|
|
90
93
|
const loadModels = async (providers, log) => {
|
|
91
|
-
var _a, _b, _c, _d;
|
|
94
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
92
95
|
(_a = log.logInfo) === null || _a === void 0 ? void 0 : _a.call(log, 'Loading AI models...');
|
|
93
96
|
for (const provider of providers) {
|
|
94
97
|
try {
|
|
@@ -104,6 +107,7 @@ const loadModels = async (providers, log) => {
|
|
|
104
107
|
case 'google': {
|
|
105
108
|
const resp = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${provider.key}`);
|
|
106
109
|
const data = await resp.json();
|
|
110
|
+
console.log(data);
|
|
107
111
|
provider.models = data.models.map((m) => ({
|
|
108
112
|
id: m.name.startsWith('models/') ? m.name.substring(7) : m.name,
|
|
109
113
|
name: m.displayName,
|
|
@@ -148,6 +152,46 @@ const loadModels = async (providers, log) => {
|
|
|
148
152
|
});
|
|
149
153
|
break;
|
|
150
154
|
}
|
|
155
|
+
case 'anthropic': {
|
|
156
|
+
const resp = await fetch('https://api.anthropic.com/v1/models', { headers: { 'x-api-key': provider.key, 'anthropic-version': '2023-06-01' } });
|
|
157
|
+
const data = await resp.json();
|
|
158
|
+
provider.models = ((_b = data.data) !== null && _b !== void 0 ? _b : []).map((m) => {
|
|
159
|
+
var _a;
|
|
160
|
+
return ({
|
|
161
|
+
id: m.id, name: (_a = m.display_name) !== null && _a !== void 0 ? _a : m.id, description: '', type: 'text'
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case 'openai-compat': {
|
|
167
|
+
if (!provider.endpoint) {
|
|
168
|
+
(_c = log.logWarning) === null || _c === void 0 ? void 0 : _c.call(log, `Provider 'openai-compat' has no endpoint configured — skipping model load`);
|
|
169
|
+
provider.models = [];
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
const base = provider.endpoint.replace(/\/+$/, '');
|
|
173
|
+
const modelsUrl = base.endsWith('/v1') ? `${base}/models` : `${base}/v1/models`;
|
|
174
|
+
try {
|
|
175
|
+
const resp = await fetch(modelsUrl, { headers: { Authorization: 'Bearer ' + provider.key } });
|
|
176
|
+
if (!resp.ok) {
|
|
177
|
+
(_d = log.logWarning) === null || _d === void 0 ? void 0 : _d.call(log, `Provider 'openai-compat' /models returned ${resp.status} — models list will be empty`);
|
|
178
|
+
provider.models = [];
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
const data = await resp.json();
|
|
182
|
+
provider.models = ((_f = (_e = data.data) !== null && _e !== void 0 ? _e : data.models) !== null && _f !== void 0 ? _f : []).map((m) => {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
return ({
|
|
185
|
+
id: m.id, name: (_a = m.name) !== null && _a !== void 0 ? _a : m.id, description: (_b = m.description) !== null && _b !== void 0 ? _b : '', type: 'text'
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
(_g = log.logWarning) === null || _g === void 0 ? void 0 : _g.call(log, `Provider 'openai-compat' failed to load models: ${err} — models list will be empty`);
|
|
191
|
+
provider.models = [];
|
|
192
|
+
}
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
151
195
|
case 'kwirth':
|
|
152
196
|
provider.models = [
|
|
153
197
|
{ id: 'alberto-1-flash-gordon-lite', name: 'Alberto model quick response', description: 'Albert #1 model', type: 'text' },
|
|
@@ -155,12 +199,12 @@ const loadModels = async (providers, log) => {
|
|
|
155
199
|
];
|
|
156
200
|
break;
|
|
157
201
|
default:
|
|
158
|
-
(
|
|
202
|
+
(_h = log.logWarning) === null || _h === void 0 ? void 0 : _h.call(log, `Provider '${provider.name}' is not implemented, will not be available.`);
|
|
159
203
|
}
|
|
160
|
-
(
|
|
204
|
+
(_j = log.logInfo) === null || _j === void 0 ? void 0 : _j.call(log, `Provider '${provider.name}' loaded ${provider.models.length} models`);
|
|
161
205
|
}
|
|
162
206
|
catch (err) {
|
|
163
|
-
(
|
|
207
|
+
(_k = log.logError) === null || _k === void 0 ? void 0 : _k.call(log, `Error loading models from provider '${provider.name}': ${err}`);
|
|
164
208
|
}
|
|
165
209
|
}
|
|
166
210
|
};
|
package/dist/front.js
CHANGED
|
@@ -72,7 +72,7 @@ const LlmSelector = ({ llms, value, onChange, label = 'LLM', size = 'small', ful
|
|
|
72
72
|
};
|
|
73
73
|
exports.LlmSelector = LlmSelector;
|
|
74
74
|
const AiConfigLlm = (props) => {
|
|
75
|
-
var _a;
|
|
75
|
+
var _a, _b;
|
|
76
76
|
const [llms, setLlms] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.llms)));
|
|
77
77
|
const importLlmRef = (0, react_1.useRef)(null);
|
|
78
78
|
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
|
|
@@ -153,9 +153,11 @@ const AiConfigLlm = (props) => {
|
|
|
153
153
|
var _a;
|
|
154
154
|
return (react_1.default.createElement(material_1.MenuItem, { key: p.name, value: p.name, disabled: !((_a = p.models) === null || _a === void 0 ? void 0 : _a.length) }, p.name));
|
|
155
155
|
}))),
|
|
156
|
-
|
|
157
|
-
react_1.default.createElement(material_1.
|
|
158
|
-
|
|
156
|
+
((_a = props.providers.find(p => p.name === provider)) === null || _a === void 0 ? void 0 : _a.models.length)
|
|
157
|
+
? (react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
|
|
158
|
+
react_1.default.createElement(material_1.InputLabel, null, "Model"),
|
|
159
|
+
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))))))
|
|
160
|
+
: (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 })),
|
|
159
161
|
react_1.default.createElement(material_1.TextField, { value: temperature, onChange: e => setTemperature(+e.target.value), label: 'Model temperature', variant: 'standard', type: 'number', fullWidth: true }),
|
|
160
162
|
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
|
|
161
163
|
react_1.default.createElement(material_1.TextField, { value: inputCostPerMillion, onChange: e => setInputCostPerMillion(e.target.value === '' ? '' : +e.target.value), label: 'Input cost / M tokens (\u20AC/$)', variant: 'standard', type: 'number', fullWidth: true, inputProps: { min: 0, step: 0.01 } }),
|
|
@@ -205,20 +207,24 @@ const AiConfigProvider = (props) => {
|
|
|
205
207
|
}, [props.providers]);
|
|
206
208
|
const [providerName, setProviderName] = (0, react_1.useState)('');
|
|
207
209
|
const [providerKey, setProviderKey] = (0, react_1.useState)((_a = props.providersAvailable[0]) !== null && _a !== void 0 ? _a : '');
|
|
210
|
+
const [providerEndpoint, setProviderEndpoint] = (0, react_1.useState)('');
|
|
208
211
|
const onProviderSelected = (p, index) => {
|
|
212
|
+
var _a;
|
|
209
213
|
setProviderName(p.name);
|
|
210
214
|
setProviderKey(p.key);
|
|
215
|
+
setProviderEndpoint((_a = p.endpoint) !== null && _a !== void 0 ? _a : '');
|
|
211
216
|
setSelectedIndex(index);
|
|
212
217
|
};
|
|
213
|
-
const onNew = () => { setSelectedIndex(null); setProviderName(''); setProviderKey(''); };
|
|
218
|
+
const onNew = () => { setSelectedIndex(null); setProviderName(''); setProviderKey(''); setProviderEndpoint(''); };
|
|
214
219
|
const onAdd = () => {
|
|
215
220
|
if (!providerName.trim())
|
|
216
221
|
return;
|
|
222
|
+
const endpoint = providerName === 'openai-compat' ? providerEndpoint : undefined;
|
|
217
223
|
const updated = [...providers];
|
|
218
224
|
if (selectedIndex !== null)
|
|
219
|
-
updated[selectedIndex] = Object.assign(Object.assign({}, updated[selectedIndex]), { name: providerName, key: providerKey });
|
|
225
|
+
updated[selectedIndex] = Object.assign(Object.assign({}, updated[selectedIndex]), { name: providerName, key: providerKey, endpoint });
|
|
220
226
|
else
|
|
221
|
-
updated.push({ name: providerName, key: providerKey, models: [] });
|
|
227
|
+
updated.push({ name: providerName, key: providerKey, models: [], endpoint });
|
|
222
228
|
setProviders(updated);
|
|
223
229
|
onNew();
|
|
224
230
|
};
|
|
@@ -251,6 +257,7 @@ const AiConfigProvider = (props) => {
|
|
|
251
257
|
endAdornment: (react_1.default.createElement(material_1.InputAdornment, { position: 'end' },
|
|
252
258
|
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))))
|
|
253
259
|
} }),
|
|
260
|
+
providerName === '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)' })),
|
|
254
261
|
react_1.default.createElement(material_1.Box, { sx: { flexGrow: 1 } }),
|
|
255
262
|
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
|
|
256
263
|
react_1.default.createElement(material_1.Button, { variant: 'outlined', onClick: onNew }, "New"),
|
|
@@ -272,7 +279,7 @@ const AiConfigProvider = (props) => {
|
|
|
272
279
|
e.target.value = '';
|
|
273
280
|
} }),
|
|
274
281
|
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileUpload_1.default, { fontSize: 'small' }), onClick: () => { var _a; return (_a = importProvRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }, "Import"),
|
|
275
|
-
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, { fontSize: 'small' }), onClick: () => downloadJson(providers.map(p => ({ name: p.name, key: p.key })), 'kwirth-providers.json') }, "Export"),
|
|
282
|
+
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, { fontSize: 'small' }), onClick: () => downloadJson(providers.map(p => (Object.assign({ name: p.name, key: p.key }, (p.endpoint ? { endpoint: p.endpoint } : {})))), 'kwirth-providers.json') }, "Export"),
|
|
276
283
|
react_1.default.createElement(material_1.Box, { flex: 1 }),
|
|
277
284
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(providers), color: 'primary', variant: 'contained' }, "Save"),
|
|
278
285
|
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), color: 'inherit' }, "Cancel"))));
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.STORAGE_KEY_AGENTS = exports.PROVIDERS_AVAILABLE = exports.STORAGE_KEY_LLMS = exports.STORAGE_KEY_PROVIDERS = void 0;
|
|
4
4
|
exports.STORAGE_KEY_PROVIDERS = 'kwirth-ai-providers';
|
|
5
5
|
exports.STORAGE_KEY_LLMS = 'kwirth-ai-llms';
|
|
6
|
-
exports.PROVIDERS_AVAILABLE = ['google', 'openai', 'openrouter', 'mistral', 'groq', 'deepseek'];
|
|
6
|
+
exports.PROVIDERS_AVAILABLE = ['google', 'openai', 'openrouter', 'mistral', 'groq', 'deepseek', 'anthropic', 'openai-compat'];
|
|
7
7
|
exports.STORAGE_KEY_AGENTS = 'kwirth-ai-agents';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kwirthmagnify/kwirth-common-ai",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.34",
|
|
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",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"author": "Julio Fernandez",
|
|
46
46
|
"license": "ISC",
|
|
47
47
|
"dependencies": {
|
|
48
|
+
"@ai-sdk/anthropic": "^3.0.116",
|
|
48
49
|
"@ai-sdk/deepseek": "^2.0.29",
|
|
49
50
|
"@ai-sdk/google": "^3.0.64",
|
|
50
51
|
"@ai-sdk/groq": "^3.0.35",
|