@kwirthmagnify/kwirth-common-ai 0.5.10 → 0.5.11

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 CHANGED
@@ -4,6 +4,6 @@ import { LanguageModel } from 'ai';
4
4
  import { z } from 'zod';
5
5
  export declare const buildModel: (llm: ILlm, providers: ILlmProvider[]) => LanguageModel | null;
6
6
  export declare const loadModels: (providers: ILlmProvider[], log: IBackChannelObject) => Promise<void>;
7
- export { generateText, Output, stepCountIs } from 'ai';
7
+ export { generateText, Output, stepCountIs, tool } from 'ai';
8
8
  export { z } from 'zod';
9
9
  export declare const zodFromExample: (example: Record<string, unknown>) => z.ZodObject<Record<string, z.ZodTypeAny>>;
package/dist/back.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zodFromExample = exports.z = exports.stepCountIs = exports.Output = exports.generateText = exports.loadModels = exports.buildModel = void 0;
3
+ exports.zodFromExample = exports.z = exports.tool = exports.stepCountIs = exports.Output = exports.generateText = exports.loadModels = exports.buildModel = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const openai_1 = require("@ai-sdk/openai");
6
6
  const groq_1 = require("@ai-sdk/groq");
@@ -124,6 +124,7 @@ var ai_1 = require("ai");
124
124
  Object.defineProperty(exports, "generateText", { enumerable: true, get: function () { return ai_1.generateText; } });
125
125
  Object.defineProperty(exports, "Output", { enumerable: true, get: function () { return ai_1.Output; } });
126
126
  Object.defineProperty(exports, "stepCountIs", { enumerable: true, get: function () { return ai_1.stepCountIs; } });
127
+ Object.defineProperty(exports, "tool", { enumerable: true, get: function () { return ai_1.tool; } });
127
128
  var zod_2 = require("zod");
128
129
  Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_2.z; } });
129
130
  const zodFromExample = (example) => {
package/dist/front.js CHANGED
@@ -37,6 +37,15 @@ exports.AiConfigProvider = exports.AiConfigLlm = exports.LlmSelector = void 0;
37
37
  const react_1 = __importStar(require("react"));
38
38
  const material_1 = require("@mui/material");
39
39
  const icons_material_1 = require("@mui/icons-material");
40
+ const downloadJson = (data, filename) => {
41
+ const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
42
+ const url = URL.createObjectURL(blob);
43
+ const a = document.createElement('a');
44
+ a.href = url;
45
+ a.download = filename;
46
+ a.click();
47
+ URL.revokeObjectURL(url);
48
+ };
40
49
  const LlmSelector = ({ llms, value, onChange, label = 'LLM', size = 'small', fullWidth = true }) => {
41
50
  return (react_1.default.createElement(material_1.FormControl, { size: size, fullWidth: fullWidth },
42
51
  react_1.default.createElement(material_1.InputLabel, null, label),
@@ -52,6 +61,7 @@ exports.LlmSelector = LlmSelector;
52
61
  const AiConfigLlm = (props) => {
53
62
  var _a;
54
63
  const [llms, setLlms] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.llms)));
64
+ const importLlmRef = (0, react_1.useRef)(null);
55
65
  const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
56
66
  const [showPassword, setShowPassword] = (0, react_1.useState)(false);
57
67
  const [id, setId] = (0, react_1.useState)('');
@@ -140,6 +150,22 @@ const AiConfigLlm = (props) => {
140
150
  react_1.default.createElement(material_1.Button, { color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
141
151
  react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !id || !model }, selectedIndex !== null ? 'Update' : 'Add'))))),
142
152
  react_1.default.createElement(material_1.DialogActions, null,
153
+ react_1.default.createElement("input", { ref: importLlmRef, type: 'file', accept: '.json', style: { display: 'none' }, onChange: e => {
154
+ var _a;
155
+ const f = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
156
+ if (!f)
157
+ return;
158
+ const reader = new FileReader();
159
+ reader.onload = ev => { try {
160
+ setLlms(JSON.parse(ev.target.result));
161
+ }
162
+ catch (_a) { } };
163
+ reader.readAsText(f);
164
+ e.target.value = '';
165
+ } }),
166
+ react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(icons_material_1.FileUpload, { fontSize: 'small' }), onClick: () => { var _a; return (_a = importLlmRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }, "Import"),
167
+ react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(icons_material_1.FileDownload, { fontSize: 'small' }), onClick: () => downloadJson(llms, 'kwirth-llms.json') }, "Export"),
168
+ react_1.default.createElement(material_1.Box, { flex: 1 }),
143
169
  react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(llms), variant: 'contained' }, "OK"),
144
170
  react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), color: 'inherit' }, "Cancel"))));
145
171
  };
@@ -147,6 +173,7 @@ exports.AiConfigLlm = AiConfigLlm;
147
173
  const AiConfigProvider = (props) => {
148
174
  var _a;
149
175
  const [providers, setProviders] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.providers)));
176
+ const importProvRef = (0, react_1.useRef)(null);
150
177
  const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
151
178
  const [showPassword, setShowPassword] = (0, react_1.useState)(false);
152
179
  const [providerName, setProviderName] = (0, react_1.useState)('');
@@ -204,6 +231,22 @@ const AiConfigProvider = (props) => {
204
231
  react_1.default.createElement(material_1.Button, { variant: 'text', color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
205
232
  react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !providerName }, selectedIndex !== null ? 'Update' : 'Add'))))),
206
233
  react_1.default.createElement(material_1.DialogActions, { sx: { p: 2 } },
234
+ react_1.default.createElement("input", { ref: importProvRef, type: 'file', accept: '.json', style: { display: 'none' }, onChange: e => {
235
+ var _a;
236
+ const f = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
237
+ if (!f)
238
+ return;
239
+ const reader = new FileReader();
240
+ reader.onload = ev => { try {
241
+ setProviders(JSON.parse(ev.target.result));
242
+ }
243
+ catch (_a) { } };
244
+ reader.readAsText(f);
245
+ e.target.value = '';
246
+ } }),
247
+ react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(icons_material_1.FileUpload, { fontSize: 'small' }), onClick: () => { var _a; return (_a = importProvRef.current) === null || _a === void 0 ? void 0 : _a.click(); } }, "Import"),
248
+ react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(icons_material_1.FileDownload, { fontSize: 'small' }), onClick: () => downloadJson(providers.map(p => ({ name: p.name, key: p.key })), 'kwirth-providers.json') }, "Export"),
249
+ react_1.default.createElement(material_1.Box, { flex: 1 }),
207
250
  react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(providers), color: 'primary', variant: 'contained' }, "Save"),
208
251
  react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), color: 'inherit' }, "Cancel"))));
209
252
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwirthmagnify/kwirth-common-ai",
3
- "version": "0.5.10",
3
+ "version": "0.5.11",
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"