@kwirthmagnify/kwirth-common-ai 0.5.31 → 0.5.33
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 +20 -0
- package/dist/back.js +21 -1
- package/dist/front.js +7 -0
- package/package.json +68 -68
package/dist/back.d.ts
CHANGED
|
@@ -3,6 +3,26 @@ import { ILlm, ILlmProvider, IAgent } from './index';
|
|
|
3
3
|
import { LanguageModel } from 'ai';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
export declare const buildModel: (llm: ILlm, providers: ILlmProvider[]) => LanguageModel | null;
|
|
6
|
+
export interface IVisionResult<T> {
|
|
7
|
+
object: T | null;
|
|
8
|
+
text: string;
|
|
9
|
+
usage?: unknown;
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
type TJsonValue = string | number | boolean | null | TJsonValue[] | {
|
|
13
|
+
[k: string]: TJsonValue;
|
|
14
|
+
};
|
|
15
|
+
export interface IVisionOptions<T> {
|
|
16
|
+
model: LanguageModel;
|
|
17
|
+
image: string;
|
|
18
|
+
prompt: string;
|
|
19
|
+
schema: z.ZodType<T>;
|
|
20
|
+
system?: string;
|
|
21
|
+
temperature?: number;
|
|
22
|
+
providerOptions?: Record<string, Record<string, TJsonValue>>;
|
|
23
|
+
mediaType?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const generateVision: <T>(opts: IVisionOptions<T>) => Promise<IVisionResult<T>>;
|
|
6
26
|
export declare const loadModels: (providers: ILlmProvider[], log: IBackChannelObject) => Promise<void>;
|
|
7
27
|
export { generateText, Output, stepCountIs, tool } from 'ai';
|
|
8
28
|
export { z } from 'zod';
|
package/dist/back.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.runAgent = exports.selectAgentToolNames = exports.toolInfoList = exports.tools = exports.runWithToolContext = exports.EToolEffect = exports.zodFromExample = exports.z = exports.tool = exports.stepCountIs = exports.Output = exports.generateText = exports.loadModels = exports.buildModel = void 0;
|
|
36
|
+
exports.runAgent = exports.selectAgentToolNames = exports.toolInfoList = exports.tools = exports.runWithToolContext = exports.EToolEffect = exports.zodFromExample = exports.z = exports.tool = exports.stepCountIs = exports.Output = exports.generateText = exports.loadModels = exports.generateVision = exports.buildModel = void 0;
|
|
37
37
|
const ai_1 = require("ai");
|
|
38
38
|
const zod_1 = require("zod");
|
|
39
39
|
const async_hooks_1 = require("async_hooks");
|
|
@@ -67,6 +67,26 @@ const buildModel = (llm, providers) => {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
exports.buildModel = buildModel;
|
|
70
|
+
// Llamada MULTIMODAL genérica: manda una imagen + prompt a un LLM y devuelve salida ESTRUCTURADA validada por
|
|
71
|
+
// un schema Zod (patrón Output.object). Reutilizable por toda la plataforma (Iter la usa para extraer un mapa
|
|
72
|
+
// de un diagrama). No lanza: los errores vuelven en `error`.
|
|
73
|
+
const generateVision = async (opts) => {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
try {
|
|
76
|
+
const imagePart = opts.mediaType
|
|
77
|
+
? { type: 'image', image: opts.image, mediaType: opts.mediaType }
|
|
78
|
+
: { type: 'image', image: opts.image };
|
|
79
|
+
const { output, text, usage } = await (0, ai_1.generateText)(Object.assign({ model: opts.model, temperature: (_a = opts.temperature) !== null && _a !== void 0 ? _a : 0, system: opts.system, messages: [{
|
|
80
|
+
role: 'user',
|
|
81
|
+
content: [{ type: 'text', text: opts.prompt }, imagePart],
|
|
82
|
+
}], output: ai_1.Output.object({ schema: opts.schema }) }, (opts.providerOptions ? { providerOptions: opts.providerOptions } : {})));
|
|
83
|
+
return { object: (_b = output) !== null && _b !== void 0 ? _b : null, text: text !== null && text !== void 0 ? text : '', usage };
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
return { object: null, text: '', error: (_c = err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : String(err) };
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
exports.generateVision = generateVision;
|
|
70
90
|
const loadModels = async (providers, log) => {
|
|
71
91
|
var _a, _b, _c, _d;
|
|
72
92
|
(_a = log.logInfo) === null || _a === void 0 ? void 0 : _a.call(log, 'Loading AI models...');
|
package/dist/front.js
CHANGED
|
@@ -85,6 +85,13 @@ const AiConfigLlm = (props) => {
|
|
|
85
85
|
const [key, setKey] = (0, react_1.useState)('');
|
|
86
86
|
const [inputCostPerMillion, setInputCostPerMillion] = (0, react_1.useState)(0);
|
|
87
87
|
const [outputCostPerMillion, setOutputCostPerMillion] = (0, react_1.useState)(0);
|
|
88
|
+
// Re-sincroniza el estado cuando llegan los modelos async (mismo fix de race que AiConfigProvider): al abrir,
|
|
89
|
+
// el padre monta el diálogo con props.llms vacío y los pide por WS; sin esto, la lista quedaba vacía hasta
|
|
90
|
+
// cerrar/reabrir.
|
|
91
|
+
(0, react_1.useEffect)(() => {
|
|
92
|
+
setLlms(JSON.parse(JSON.stringify(props.llms)));
|
|
93
|
+
setSelectedIndex(null);
|
|
94
|
+
}, [props.llms]);
|
|
88
95
|
const onLlmSelected = (index) => {
|
|
89
96
|
var _a, _b;
|
|
90
97
|
const l = llms[index];
|
package/package.json
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@kwirthmagnify/kwirth-common-ai",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "Shared AI/LLM types and utilities for Kwirth AI plugins",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "del .\\dist\\* /s /q 2>nul & tsc",
|
|
7
|
-
"test": "node --test tests/agent.test.mjs"
|
|
8
|
-
},
|
|
9
|
-
"publishConfig": {
|
|
10
|
-
"access": "public"
|
|
11
|
-
},
|
|
12
|
-
"main": "dist/index.js",
|
|
13
|
-
"module": "dist/index.js",
|
|
14
|
-
"types": "dist/index.d.ts",
|
|
15
|
-
"exports": {
|
|
16
|
-
".": {
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"require": "./dist/index.js",
|
|
19
|
-
"default": "./dist/index.js"
|
|
20
|
-
},
|
|
21
|
-
"./back": {
|
|
22
|
-
"types": "./dist/back.d.ts",
|
|
23
|
-
"require": "./dist/back.js",
|
|
24
|
-
"default": "./dist/back.js"
|
|
25
|
-
},
|
|
26
|
-
"./front": {
|
|
27
|
-
"types": "./dist/front.d.ts",
|
|
28
|
-
"require": "./dist/front.js",
|
|
29
|
-
"default": "./dist/front.js"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"typesVersions": {
|
|
33
|
-
"*": {
|
|
34
|
-
"back": [
|
|
35
|
-
"dist/back.d.ts"
|
|
36
|
-
],
|
|
37
|
-
"front": [
|
|
38
|
-
"dist/front.d.ts"
|
|
39
|
-
]
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"files": [
|
|
43
|
-
"dist"
|
|
44
|
-
],
|
|
45
|
-
"author": "Julio Fernandez",
|
|
46
|
-
"license": "ISC",
|
|
47
|
-
"dependencies": {
|
|
48
|
-
"@ai-sdk/deepseek": "^2.0.29",
|
|
49
|
-
"@ai-sdk/google": "^3.0.64",
|
|
50
|
-
"@ai-sdk/groq": "^3.0.35",
|
|
51
|
-
"@ai-sdk/mistral": "^3.0.30",
|
|
52
|
-
"@ai-sdk/openai": "^3.0.53",
|
|
53
|
-
"@openrouter/ai-sdk-provider": "^2.8.0",
|
|
54
|
-
"ai": "^6.0.174",
|
|
55
|
-
"zod": "^4.3.6"
|
|
56
|
-
},
|
|
57
|
-
"peerDependencies": {
|
|
58
|
-
"react": ">=18.0.0"
|
|
59
|
-
},
|
|
60
|
-
"devDependencies": {
|
|
61
|
-
"@kwirthmagnify/kwirth-common": "^0.5.22",
|
|
62
|
-
"@mui/icons-material": "7.1.2",
|
|
63
|
-
"@mui/material": "7.1.2",
|
|
64
|
-
"@types/node": "^25.9.1",
|
|
65
|
-
"@types/react": "^18.3.0",
|
|
66
|
-
"typescript": "^5.4.0"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@kwirthmagnify/kwirth-common-ai",
|
|
3
|
+
"version": "0.5.33",
|
|
4
|
+
"description": "Shared AI/LLM types and utilities for Kwirth AI plugins",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "del .\\dist\\* /s /q 2>nul & tsc",
|
|
7
|
+
"test": "node --test tests/agent.test.mjs"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"module": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"require": "./dist/index.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./back": {
|
|
22
|
+
"types": "./dist/back.d.ts",
|
|
23
|
+
"require": "./dist/back.js",
|
|
24
|
+
"default": "./dist/back.js"
|
|
25
|
+
},
|
|
26
|
+
"./front": {
|
|
27
|
+
"types": "./dist/front.d.ts",
|
|
28
|
+
"require": "./dist/front.js",
|
|
29
|
+
"default": "./dist/front.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"typesVersions": {
|
|
33
|
+
"*": {
|
|
34
|
+
"back": [
|
|
35
|
+
"dist/back.d.ts"
|
|
36
|
+
],
|
|
37
|
+
"front": [
|
|
38
|
+
"dist/front.d.ts"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"author": "Julio Fernandez",
|
|
46
|
+
"license": "ISC",
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@ai-sdk/deepseek": "^2.0.29",
|
|
49
|
+
"@ai-sdk/google": "^3.0.64",
|
|
50
|
+
"@ai-sdk/groq": "^3.0.35",
|
|
51
|
+
"@ai-sdk/mistral": "^3.0.30",
|
|
52
|
+
"@ai-sdk/openai": "^3.0.53",
|
|
53
|
+
"@openrouter/ai-sdk-provider": "^2.8.0",
|
|
54
|
+
"ai": "^6.0.174",
|
|
55
|
+
"zod": "^4.3.6"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"react": ">=18.0.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@kwirthmagnify/kwirth-common": "^0.5.22",
|
|
62
|
+
"@mui/icons-material": "7.1.2",
|
|
63
|
+
"@mui/material": "7.1.2",
|
|
64
|
+
"@types/node": "^25.9.1",
|
|
65
|
+
"@types/react": "^18.3.0",
|
|
66
|
+
"typescript": "^5.4.0"
|
|
67
|
+
}
|
|
68
|
+
}
|