@kwirthmagnify/kwirth-common-ai 0.5.6
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 +7 -0
- package/dist/back.js +129 -0
- package/dist/front.d.ts +24 -0
- package/dist/front.js +200 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +6 -0
- package/package.json +45 -0
package/dist/back.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IBackChannelObject } from '@kwirthmagnify/kwirth-common';
|
|
2
|
+
import { ILlm, ILlmProvider } from './index';
|
|
3
|
+
import { LanguageModel } from 'ai';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare const buildModel: (llm: ILlm, providers: ILlmProvider[]) => LanguageModel | null;
|
|
6
|
+
export declare const loadModels: (providers: ILlmProvider[], log: IBackChannelObject) => Promise<void>;
|
|
7
|
+
export declare const zodFromExample: (example: Record<string, unknown>) => z.ZodObject<Record<string, z.ZodTypeAny>>;
|
package/dist/back.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zodFromExample = exports.loadModels = exports.buildModel = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const openai_1 = require("@ai-sdk/openai");
|
|
6
|
+
const groq_1 = require("@ai-sdk/groq");
|
|
7
|
+
const mistral_1 = require("@ai-sdk/mistral");
|
|
8
|
+
const google_1 = require("@ai-sdk/google");
|
|
9
|
+
const deepseek_1 = require("@ai-sdk/deepseek");
|
|
10
|
+
const ai_sdk_provider_1 = require("@openrouter/ai-sdk-provider");
|
|
11
|
+
const buildModel = (llm, providers) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const key = llm.useProviderKey ? (_a = providers.find(p => p.name === llm.provider)) === null || _a === void 0 ? void 0 : _a.key : llm.key;
|
|
14
|
+
if (!key) {
|
|
15
|
+
console.log('Could not find a key');
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
switch (llm.provider) {
|
|
19
|
+
case 'openai': return (0, openai_1.createOpenAI)({ apiKey: key })(llm.model);
|
|
20
|
+
case 'groq': return (0, groq_1.createGroq)({ apiKey: key })(llm.model);
|
|
21
|
+
case 'mistral': return (0, mistral_1.createMistral)({ apiKey: key })(llm.model);
|
|
22
|
+
case 'google': return (0, google_1.createGoogleGenerativeAI)({ apiKey: key })(llm.model);
|
|
23
|
+
case 'deepseek': return (0, deepseek_1.createDeepSeek)({ apiKey: key })(llm.model);
|
|
24
|
+
case 'openrouter': return (0, ai_sdk_provider_1.createOpenRouter)({ apiKey: key })(llm.model);
|
|
25
|
+
default:
|
|
26
|
+
console.log('Invalid provider', llm.provider);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.buildModel = buildModel;
|
|
31
|
+
const loadModels = async (providers, log) => {
|
|
32
|
+
var _a, _b, _c, _d;
|
|
33
|
+
(_a = log.logInfo) === null || _a === void 0 ? void 0 : _a.call(log, 'Loading AI models...');
|
|
34
|
+
for (const provider of providers) {
|
|
35
|
+
try {
|
|
36
|
+
switch (provider.name) {
|
|
37
|
+
case 'deepseek': {
|
|
38
|
+
const resp = await fetch('https://api.deepseek.com/models', { headers: { Authorization: 'Bearer ' + provider.key } });
|
|
39
|
+
const data = await resp.json();
|
|
40
|
+
provider.models = data.data.filter((m) => m.object === 'model').map((m) => ({
|
|
41
|
+
id: m.id, name: m.id, description: m.description, type: 'text'
|
|
42
|
+
}));
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case 'google': {
|
|
46
|
+
const resp = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${provider.key}`);
|
|
47
|
+
const data = await resp.json();
|
|
48
|
+
provider.models = data.models.map((m) => ({
|
|
49
|
+
id: m.name.startsWith('models/') ? m.name.substring(7) : m.name,
|
|
50
|
+
name: m.displayName,
|
|
51
|
+
description: m.description,
|
|
52
|
+
type: 'text'
|
|
53
|
+
}));
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'groq': {
|
|
57
|
+
const resp = await fetch('https://api.groq.com/openai/v1/models', { headers: { Authorization: 'Bearer ' + provider.key } });
|
|
58
|
+
const data = await resp.json();
|
|
59
|
+
provider.models = data.data.filter((m) => m.object === 'model' && m.active).map((m) => ({
|
|
60
|
+
id: m.id, name: m.id, description: m.description, type: 'text'
|
|
61
|
+
}));
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'openai': {
|
|
65
|
+
const resp = await fetch('https://api.openai.com/v1/models', { headers: { Authorization: 'Bearer ' + provider.key } });
|
|
66
|
+
const data = await resp.json();
|
|
67
|
+
provider.models = data.data.filter((m) => m.object === 'model').map((m) => ({
|
|
68
|
+
id: m.id, name: m.id, description: m.description, type: 'text'
|
|
69
|
+
}));
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'openrouter': {
|
|
73
|
+
const resp = await fetch('https://openrouter.ai/api/v1/models', { headers: { Authorization: 'Bearer ' + provider.key } });
|
|
74
|
+
const data = await resp.json();
|
|
75
|
+
provider.models = data.data.map((m) => ({
|
|
76
|
+
id: m.id, name: m.name, description: m.description, type: 'text'
|
|
77
|
+
}));
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case 'mistral': {
|
|
81
|
+
const resp = await fetch('https://api.mistral.ai/v1/models', { headers: { Authorization: 'Bearer ' + provider.key } });
|
|
82
|
+
const data = await resp.json();
|
|
83
|
+
provider.models = data.data.filter((m) => m.object === 'model').map((m) => {
|
|
84
|
+
var _a;
|
|
85
|
+
return ({
|
|
86
|
+
id: m.id, name: m.id, description: m.description,
|
|
87
|
+
type: ((_a = m.capabilities) === null || _a === void 0 ? void 0 : _a.completion_chat) === true ? 'text' : 'other'
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case 'kwirth':
|
|
93
|
+
provider.models = [
|
|
94
|
+
{ id: 'alberto-1-flash-gordon-lite', name: 'Alberto model quick response', description: 'Albert #1 model', type: 'text' },
|
|
95
|
+
{ id: 'alberto-1.5-python-forever', name: 'Alberto model legacy frameworks', description: 'Albert Pythoneer', type: 'text' }
|
|
96
|
+
];
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
(_b = log.logWarning) === null || _b === void 0 ? void 0 : _b.call(log, `Provider '${provider.name}' is not implemented, will not be available.`);
|
|
100
|
+
}
|
|
101
|
+
(_c = log.logInfo) === null || _c === void 0 ? void 0 : _c.call(log, `Provider '${provider.name}' loaded ${provider.models.length} models`);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
(_d = log.logError) === null || _d === void 0 ? void 0 : _d.call(log, `Error loading models from provider '${provider.name}': ${err}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
exports.loadModels = loadModels;
|
|
109
|
+
const inferZod = (value) => {
|
|
110
|
+
if (Array.isArray(value))
|
|
111
|
+
return value.length > 0 ? zod_1.z.array(inferZod(value[0])) : zod_1.z.array(zod_1.z.unknown());
|
|
112
|
+
if (typeof value === 'string')
|
|
113
|
+
return zod_1.z.string();
|
|
114
|
+
if (typeof value === 'number')
|
|
115
|
+
return zod_1.z.number();
|
|
116
|
+
if (typeof value === 'boolean')
|
|
117
|
+
return zod_1.z.boolean();
|
|
118
|
+
if (value !== null && typeof value === 'object')
|
|
119
|
+
return (0, exports.zodFromExample)(value);
|
|
120
|
+
return zod_1.z.unknown();
|
|
121
|
+
};
|
|
122
|
+
const zodFromExample = (example) => {
|
|
123
|
+
const shape = {};
|
|
124
|
+
for (const [key, value] of Object.entries(example)) {
|
|
125
|
+
shape[key] = inferZod(value);
|
|
126
|
+
}
|
|
127
|
+
return zod_1.z.object(shape);
|
|
128
|
+
};
|
|
129
|
+
exports.zodFromExample = zodFromExample;
|
package/dist/front.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ILlm, ILlmProvider } from './index';
|
|
3
|
+
interface ILlmSelectorProps {
|
|
4
|
+
llms: ILlm[];
|
|
5
|
+
value: string;
|
|
6
|
+
onChange: (id: string) => void;
|
|
7
|
+
label?: string;
|
|
8
|
+
size?: 'small' | 'medium';
|
|
9
|
+
fullWidth?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const LlmSelector: React.FC<ILlmSelectorProps>;
|
|
12
|
+
interface IAiConfigLlmProps {
|
|
13
|
+
onClose: (llms: ILlm[] | undefined) => void;
|
|
14
|
+
providers: ILlmProvider[];
|
|
15
|
+
llms: ILlm[];
|
|
16
|
+
}
|
|
17
|
+
declare const AiConfigLlm: React.FC<IAiConfigLlmProps>;
|
|
18
|
+
interface IAiConfigProviderProps {
|
|
19
|
+
providersAvailable: string[];
|
|
20
|
+
providers: ILlmProvider[];
|
|
21
|
+
onClose: (providers: ILlmProvider[] | undefined) => void;
|
|
22
|
+
}
|
|
23
|
+
declare const AiConfigProvider: React.FC<IAiConfigProviderProps>;
|
|
24
|
+
export { LlmSelector, AiConfigLlm, AiConfigProvider };
|
package/dist/front.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.AiConfigProvider = exports.AiConfigLlm = exports.LlmSelector = void 0;
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const material_1 = require("@mui/material");
|
|
39
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
40
|
+
const LlmSelector = ({ llms, value, onChange, label = 'LLM', size = 'small', fullWidth = true }) => {
|
|
41
|
+
return (react_1.default.createElement(material_1.FormControl, { size: size, fullWidth: fullWidth },
|
|
42
|
+
react_1.default.createElement(material_1.InputLabel, null, label),
|
|
43
|
+
react_1.default.createElement(material_1.Select, { label: label, value: value, onChange: e => onChange(e.target.value) }, llms.map(llm => (react_1.default.createElement(material_1.MenuItem, { key: llm.id, value: llm.id },
|
|
44
|
+
llm.id,
|
|
45
|
+
" (",
|
|
46
|
+
llm.provider,
|
|
47
|
+
"/",
|
|
48
|
+
llm.model,
|
|
49
|
+
")"))))));
|
|
50
|
+
};
|
|
51
|
+
exports.LlmSelector = LlmSelector;
|
|
52
|
+
const AiConfigLlm = (props) => {
|
|
53
|
+
var _a;
|
|
54
|
+
const [llms, setLlms] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.llms)));
|
|
55
|
+
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
|
|
56
|
+
const [showPassword, setShowPassword] = (0, react_1.useState)(false);
|
|
57
|
+
const [id, setId] = (0, react_1.useState)('');
|
|
58
|
+
const [provider, setProvider] = (0, react_1.useState)('');
|
|
59
|
+
const [model, setModel] = (0, react_1.useState)('');
|
|
60
|
+
const [temperature, setTemperature] = (0, react_1.useState)(0);
|
|
61
|
+
const [useProviderKey, setUseProviderKey] = (0, react_1.useState)(true);
|
|
62
|
+
const [key, setKey] = (0, react_1.useState)('');
|
|
63
|
+
const onLlmSelected = (index) => {
|
|
64
|
+
const l = llms[index];
|
|
65
|
+
if (l) {
|
|
66
|
+
setId(l.id);
|
|
67
|
+
setProvider(l.provider);
|
|
68
|
+
setModel(l.model);
|
|
69
|
+
setTemperature(l.temperature);
|
|
70
|
+
setUseProviderKey(l.useProviderKey);
|
|
71
|
+
setKey(l.key);
|
|
72
|
+
setSelectedIndex(index);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const onNew = () => {
|
|
76
|
+
setSelectedIndex(null);
|
|
77
|
+
setId('');
|
|
78
|
+
setProvider('');
|
|
79
|
+
setModel('');
|
|
80
|
+
setTemperature(0);
|
|
81
|
+
setUseProviderKey(false);
|
|
82
|
+
setKey('');
|
|
83
|
+
};
|
|
84
|
+
const onAdd = () => {
|
|
85
|
+
const llm = { id, provider, model, temperature, useProviderKey, key };
|
|
86
|
+
const updated = [...llms];
|
|
87
|
+
if (selectedIndex !== null)
|
|
88
|
+
updated[selectedIndex] = llm;
|
|
89
|
+
else
|
|
90
|
+
updated.push(llm);
|
|
91
|
+
setLlms(updated);
|
|
92
|
+
onNew();
|
|
93
|
+
};
|
|
94
|
+
const onRemove = () => {
|
|
95
|
+
if (selectedIndex === null)
|
|
96
|
+
return;
|
|
97
|
+
setLlms(llms.filter((_, i) => i !== selectedIndex));
|
|
98
|
+
onNew();
|
|
99
|
+
};
|
|
100
|
+
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: '80vw', maxWidth: '800px', height: '55vh' } } },
|
|
101
|
+
react_1.default.createElement(material_1.DialogTitle, null, "AI \u2014 LLM config"),
|
|
102
|
+
react_1.default.createElement(material_1.DialogContent, { style: { display: 'flex', height: '100%' } },
|
|
103
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', flexDirection: 'column', boxSizing: 'border-box', maxWidth: '40%' } },
|
|
104
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: 1, overflowY: 'auto', overflowX: 'hidden' } },
|
|
105
|
+
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) },
|
|
106
|
+
react_1.default.createElement(material_1.Stack, { direction: 'column' },
|
|
107
|
+
react_1.default.createElement(material_1.Typography, { sx: { fontWeight: selectedIndex === index ? 'bold' : 'normal' } }, llm.id),
|
|
108
|
+
react_1.default.createElement(material_1.Typography, { color: 'darkgray', fontSize: 12 }, llm.provider)))))))),
|
|
109
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', alignItems: 'start', padding: '16px' } },
|
|
110
|
+
react_1.default.createElement(material_1.Stack, { spacing: 2, style: { width: '100%' } },
|
|
111
|
+
react_1.default.createElement(material_1.Stack, { direction: 'column', spacing: 1 },
|
|
112
|
+
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 }),
|
|
113
|
+
react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
|
|
114
|
+
react_1.default.createElement(material_1.InputLabel, null, "Provider"),
|
|
115
|
+
react_1.default.createElement(material_1.Select, { value: provider, onChange: e => { setProvider(e.target.value); setModel(''); }, variant: 'standard', fullWidth: true }, props.providers.map(p => (react_1.default.createElement(material_1.MenuItem, { key: p.name, value: p.name, disabled: p.models.length === 0 }, p.name))))),
|
|
116
|
+
react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
|
|
117
|
+
react_1.default.createElement(material_1.InputLabel, null, "Model"),
|
|
118
|
+
react_1.default.createElement(material_1.Select, { value: model, onChange: e => setModel(e.target.value), variant: 'standard', fullWidth: true, displayEmpty: true }, (_a = props.providers.find(p => p.name === provider)) === null || _a === void 0 ? void 0 : _a.models.map((m, i) => (react_1.default.createElement(material_1.MenuItem, { key: i, value: m.id }, m.name))))),
|
|
119
|
+
react_1.default.createElement(material_1.TextField, { value: temperature, onChange: e => setTemperature(+e.target.value), label: 'Model temperature', variant: 'standard', type: 'number', fullWidth: true }),
|
|
120
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', alignItems: 'center' },
|
|
121
|
+
react_1.default.createElement(material_1.Typography, { flex: 1 }, "Use provider API Key (or enter a specific one)"),
|
|
122
|
+
react_1.default.createElement(material_1.Checkbox, { checked: useProviderKey, onChange: e => setUseProviderKey(e.target.checked) })),
|
|
123
|
+
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: {
|
|
124
|
+
endAdornment: (react_1.default.createElement(material_1.InputAdornment, { position: 'end' },
|
|
125
|
+
react_1.default.createElement(material_1.IconButton, { onClick: () => setShowPassword(!showPassword), edge: 'end' }, showPassword ? react_1.default.createElement(icons_material_1.VisibilityOff, null) : react_1.default.createElement(icons_material_1.Visibility, null))))
|
|
126
|
+
} })),
|
|
127
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
|
|
128
|
+
react_1.default.createElement(material_1.Button, { variant: 'outlined', size: 'small', onClick: onNew }, "New"),
|
|
129
|
+
react_1.default.createElement(material_1.Typography, { flex: 1 }),
|
|
130
|
+
react_1.default.createElement(material_1.Button, { color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
|
|
131
|
+
react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !id || !model }, selectedIndex !== null ? 'Update' : 'Add'))))),
|
|
132
|
+
react_1.default.createElement(material_1.DialogActions, null,
|
|
133
|
+
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(llms), variant: 'contained' }, "OK"),
|
|
134
|
+
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), color: 'inherit' }, "Cancel"))));
|
|
135
|
+
};
|
|
136
|
+
exports.AiConfigLlm = AiConfigLlm;
|
|
137
|
+
const AiConfigProvider = (props) => {
|
|
138
|
+
var _a;
|
|
139
|
+
const [providers, setProviders] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.providers)));
|
|
140
|
+
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
|
|
141
|
+
const [showPassword, setShowPassword] = (0, react_1.useState)(false);
|
|
142
|
+
const [providerName, setProviderName] = (0, react_1.useState)('');
|
|
143
|
+
const [providerKey, setProviderKey] = (0, react_1.useState)((_a = props.providersAvailable[0]) !== null && _a !== void 0 ? _a : '');
|
|
144
|
+
const onProviderSelected = (p, index) => {
|
|
145
|
+
setProviderName(p.name);
|
|
146
|
+
setProviderKey(p.key);
|
|
147
|
+
setSelectedIndex(index);
|
|
148
|
+
};
|
|
149
|
+
const onNew = () => { setSelectedIndex(null); setProviderName(''); setProviderKey(''); };
|
|
150
|
+
const onAdd = () => {
|
|
151
|
+
if (!providerName.trim())
|
|
152
|
+
return;
|
|
153
|
+
const updated = [...providers];
|
|
154
|
+
if (selectedIndex !== null)
|
|
155
|
+
updated[selectedIndex] = Object.assign(Object.assign({}, updated[selectedIndex]), { name: providerName, key: providerKey });
|
|
156
|
+
else
|
|
157
|
+
updated.push({ name: providerName, key: providerKey, models: [] });
|
|
158
|
+
setProviders(updated);
|
|
159
|
+
onNew();
|
|
160
|
+
};
|
|
161
|
+
const onRemove = () => {
|
|
162
|
+
if (selectedIndex === null)
|
|
163
|
+
return;
|
|
164
|
+
setProviders(providers.filter((_, i) => i !== selectedIndex));
|
|
165
|
+
onNew();
|
|
166
|
+
};
|
|
167
|
+
return (react_1.default.createElement(material_1.Dialog, { open: true, onClose: () => props.onClose(undefined), PaperProps: { sx: { width: '80vw', maxWidth: '900px', height: '45vh' } } },
|
|
168
|
+
react_1.default.createElement(material_1.DialogTitle, null, "AI \u2014 Provider config"),
|
|
169
|
+
react_1.default.createElement(material_1.DialogContent, { style: { display: 'flex', height: '100%' } },
|
|
170
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', flexDirection: 'column', boxSizing: 'border-box', maxWidth: '30%' } },
|
|
171
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: 1, overflowY: 'auto' } },
|
|
172
|
+
react_1.default.createElement(material_1.List, { sx: { mr: 1 } }, providers.map((p, index) => {
|
|
173
|
+
var _a;
|
|
174
|
+
return (react_1.default.createElement(material_1.ListItemButton, { key: index, selected: selectedIndex === index, onClick: () => onProviderSelected(p, index) },
|
|
175
|
+
react_1.default.createElement(material_1.Stack, { direction: 'column' },
|
|
176
|
+
react_1.default.createElement(material_1.Typography, { sx: { fontWeight: selectedIndex === index ? 'bold' : 'normal' } }, p.name),
|
|
177
|
+
react_1.default.createElement(material_1.Typography, { color: 'darkgray', fontSize: 11 },
|
|
178
|
+
((_a = p.models) === null || _a === void 0 ? void 0 : _a.length) || 0,
|
|
179
|
+
" models loaded"))));
|
|
180
|
+
})))),
|
|
181
|
+
react_1.default.createElement(material_1.Box, { sx: { flex: 1, display: 'flex', alignItems: 'start', padding: '24px' } },
|
|
182
|
+
react_1.default.createElement(material_1.Stack, { spacing: 3, style: { width: '100%' } },
|
|
183
|
+
react_1.default.createElement(material_1.FormControl, { variant: 'standard', sx: { width: '100%' } },
|
|
184
|
+
react_1.default.createElement(material_1.InputLabel, null, "Provider"),
|
|
185
|
+
react_1.default.createElement(material_1.Select, { value: providerName, onChange: e => setProviderName(e.target.value), variant: 'standard', fullWidth: true }, props.providersAvailable.map(name => (react_1.default.createElement(material_1.MenuItem, { key: name, value: name }, name))))),
|
|
186
|
+
react_1.default.createElement(material_1.TextField, { label: 'API Key / Token', type: showPassword ? 'text' : 'password', variant: 'standard', fullWidth: true, value: providerKey, onChange: e => setProviderKey(e.target.value), helperText: 'This key can be afterwards linked to specific uses.', InputProps: {
|
|
187
|
+
endAdornment: (react_1.default.createElement(material_1.InputAdornment, { position: 'end' },
|
|
188
|
+
react_1.default.createElement(material_1.IconButton, { onClick: () => setShowPassword(!showPassword), edge: 'end' }, showPassword ? react_1.default.createElement(icons_material_1.VisibilityOff, null) : react_1.default.createElement(icons_material_1.Visibility, null))))
|
|
189
|
+
} }),
|
|
190
|
+
react_1.default.createElement(material_1.Box, { sx: { flexGrow: 1 } }),
|
|
191
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 1 },
|
|
192
|
+
react_1.default.createElement(material_1.Button, { variant: 'outlined', onClick: onNew }, "New"),
|
|
193
|
+
react_1.default.createElement(material_1.Typography, { flex: 1 }),
|
|
194
|
+
react_1.default.createElement(material_1.Button, { variant: 'text', color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
|
|
195
|
+
react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !providerName }, selectedIndex !== null ? 'Update' : 'Add'))))),
|
|
196
|
+
react_1.default.createElement(material_1.DialogActions, { sx: { p: 2 } },
|
|
197
|
+
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(providers), color: 'primary', variant: 'contained' }, "Save"),
|
|
198
|
+
react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), color: 'inherit' }, "Cancel"))));
|
|
199
|
+
};
|
|
200
|
+
exports.AiConfigProvider = AiConfigProvider;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const STORAGE_KEY_PROVIDERS = "kwirth-ai-providers";
|
|
2
|
+
export declare const STORAGE_KEY_LLMS = "kwirth-ai-llms";
|
|
3
|
+
export declare const PROVIDERS_AVAILABLE: string[];
|
|
4
|
+
export interface ILlmModel {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
type: 'text' | 'image' | 'video' | 'other';
|
|
9
|
+
}
|
|
10
|
+
export interface ILlmProvider {
|
|
11
|
+
name: string;
|
|
12
|
+
key: string;
|
|
13
|
+
models: ILlmModel[];
|
|
14
|
+
}
|
|
15
|
+
export interface ILlm {
|
|
16
|
+
id: string;
|
|
17
|
+
provider: string;
|
|
18
|
+
model: string;
|
|
19
|
+
temperature: number;
|
|
20
|
+
useProviderKey: boolean;
|
|
21
|
+
key: string;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROVIDERS_AVAILABLE = exports.STORAGE_KEY_LLMS = exports.STORAGE_KEY_PROVIDERS = void 0;
|
|
4
|
+
exports.STORAGE_KEY_PROVIDERS = 'kwirth-ai-providers';
|
|
5
|
+
exports.STORAGE_KEY_LLMS = 'kwirth-ai-llms';
|
|
6
|
+
exports.PROVIDERS_AVAILABLE = ['google', 'openai', 'openrouter', 'mistral', 'groq', 'deepseek'];
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kwirthmagnify/kwirth-common-ai",
|
|
3
|
+
"version": "0.5.6",
|
|
4
|
+
"description": "Shared AI/LLM types and utilities for Kwirth AI plugins",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "del .\\dist\\* /s /q 2>nul & tsc"
|
|
7
|
+
},
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"module": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./dist/index.js",
|
|
16
|
+
"./back": "./dist/back.js",
|
|
17
|
+
"./front": "./dist/front.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"author": "Julio Fernandez",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@ai-sdk/deepseek": "^2.0.29",
|
|
26
|
+
"@ai-sdk/google": "^3.0.64",
|
|
27
|
+
"@ai-sdk/groq": "^3.0.35",
|
|
28
|
+
"@ai-sdk/mistral": "^3.0.30",
|
|
29
|
+
"@ai-sdk/openai": "^3.0.53",
|
|
30
|
+
"@openrouter/ai-sdk-provider": "^2.8.0",
|
|
31
|
+
"ai": "^6.0.174",
|
|
32
|
+
"zod": "^4.3.6"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@kwirthmagnify/kwirth-common": "^0.5.1",
|
|
39
|
+
"@mui/icons-material": "7.1.2",
|
|
40
|
+
"@mui/material": "7.1.2",
|
|
41
|
+
"@types/react": "^18.3.0",
|
|
42
|
+
"react": "^18.3.0",
|
|
43
|
+
"typescript": "^5.4.0"
|
|
44
|
+
}
|
|
45
|
+
}
|