@kwirthmagnify/kwirth-common-ai 0.5.10 → 0.5.12

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,24 @@ 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 = async (data, filename) => {
41
+ var _a, _b;
42
+ const json = JSON.stringify(data, null, 2);
43
+ const tauri = window.__TAURI__;
44
+ if (((_a = tauri === null || tauri === void 0 ? void 0 : tauri.dialog) === null || _a === void 0 ? void 0 : _a.save) && ((_b = tauri === null || tauri === void 0 ? void 0 : tauri.fs) === null || _b === void 0 ? void 0 : _b.writeTextFile)) {
45
+ const path = await tauri.dialog.save({ defaultPath: filename, filters: [{ name: 'JSON', extensions: ['json'] }] });
46
+ if (path)
47
+ await tauri.fs.writeTextFile(path, json);
48
+ return;
49
+ }
50
+ const blob = new Blob([json], { type: 'application/json' });
51
+ const url = URL.createObjectURL(blob);
52
+ const a = document.createElement('a');
53
+ a.href = url;
54
+ a.download = filename;
55
+ a.click();
56
+ URL.revokeObjectURL(url);
57
+ };
40
58
  const LlmSelector = ({ llms, value, onChange, label = 'LLM', size = 'small', fullWidth = true }) => {
41
59
  return (react_1.default.createElement(material_1.FormControl, { size: size, fullWidth: fullWidth },
42
60
  react_1.default.createElement(material_1.InputLabel, null, label),
@@ -52,6 +70,7 @@ exports.LlmSelector = LlmSelector;
52
70
  const AiConfigLlm = (props) => {
53
71
  var _a;
54
72
  const [llms, setLlms] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.llms)));
73
+ const importLlmRef = (0, react_1.useRef)(null);
55
74
  const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
56
75
  const [showPassword, setShowPassword] = (0, react_1.useState)(false);
57
76
  const [id, setId] = (0, react_1.useState)('');
@@ -140,6 +159,22 @@ const AiConfigLlm = (props) => {
140
159
  react_1.default.createElement(material_1.Button, { color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
141
160
  react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !id || !model }, selectedIndex !== null ? 'Update' : 'Add'))))),
142
161
  react_1.default.createElement(material_1.DialogActions, null,
162
+ react_1.default.createElement("input", { ref: importLlmRef, type: 'file', accept: '.json', style: { display: 'none' }, onChange: e => {
163
+ var _a;
164
+ const f = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
165
+ if (!f)
166
+ return;
167
+ const reader = new FileReader();
168
+ reader.onload = ev => { try {
169
+ setLlms(JSON.parse(ev.target.result));
170
+ }
171
+ catch (_a) { } };
172
+ reader.readAsText(f);
173
+ e.target.value = '';
174
+ } }),
175
+ 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"),
176
+ 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"),
177
+ react_1.default.createElement(material_1.Box, { flex: 1 }),
143
178
  react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(llms), variant: 'contained' }, "OK"),
144
179
  react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), color: 'inherit' }, "Cancel"))));
145
180
  };
@@ -147,6 +182,7 @@ exports.AiConfigLlm = AiConfigLlm;
147
182
  const AiConfigProvider = (props) => {
148
183
  var _a;
149
184
  const [providers, setProviders] = (0, react_1.useState)(JSON.parse(JSON.stringify(props.providers)));
185
+ const importProvRef = (0, react_1.useRef)(null);
150
186
  const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(null);
151
187
  const [showPassword, setShowPassword] = (0, react_1.useState)(false);
152
188
  const [providerName, setProviderName] = (0, react_1.useState)('');
@@ -204,6 +240,22 @@ const AiConfigProvider = (props) => {
204
240
  react_1.default.createElement(material_1.Button, { variant: 'text', color: 'error', onClick: onRemove, disabled: selectedIndex === null }, "Remove"),
205
241
  react_1.default.createElement(material_1.Button, { variant: 'contained', onClick: onAdd, disabled: !providerName }, selectedIndex !== null ? 'Update' : 'Add'))))),
206
242
  react_1.default.createElement(material_1.DialogActions, { sx: { p: 2 } },
243
+ react_1.default.createElement("input", { ref: importProvRef, type: 'file', accept: '.json', style: { display: 'none' }, onChange: e => {
244
+ var _a;
245
+ const f = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
246
+ if (!f)
247
+ return;
248
+ const reader = new FileReader();
249
+ reader.onload = ev => { try {
250
+ setProviders(JSON.parse(ev.target.result));
251
+ }
252
+ catch (_a) { } };
253
+ reader.readAsText(f);
254
+ e.target.value = '';
255
+ } }),
256
+ 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"),
257
+ 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"),
258
+ react_1.default.createElement(material_1.Box, { flex: 1 }),
207
259
  react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(providers), color: 'primary', variant: 'contained' }, "Save"),
208
260
  react_1.default.createElement(material_1.Button, { onClick: () => props.onClose(undefined), color: 'inherit' }, "Cancel"))));
209
261
  };
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.12",
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"