@kwirthmagnify/kwirth-common-ai 0.5.79 → 0.5.80
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 +12 -1
- package/dist/back.js +18 -14
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -1
- package/package.json +6 -5
package/dist/back.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ILlm, ILlmProvider, ECapability, EToolEffect, EToolSensitivity, EUsagePeriod, EUsageUnit, IAiToolInfo, IAiToolsetInfo, IToolsetConfig, IToolsetGrant, IUsageAmounts, IUsageLimits } from './index';
|
|
2
2
|
import type { AppsV1Api, CoreV1Api, CustomObjectsApi, NetworkingV1Api } from '@kubernetes/client-node';
|
|
3
|
+
import type { IProviderHandle } from '@kwirthmagnify/kwirth-common-back';
|
|
3
4
|
interface ILogChannel {
|
|
4
5
|
logInfo?: (msg: string) => void;
|
|
5
6
|
logWarning?: (msg: string) => void;
|
|
@@ -93,6 +94,7 @@ export interface IToolContext {
|
|
|
93
94
|
clusterEvents?: any[];
|
|
94
95
|
sourceRepos?: ISourceRepoCred[];
|
|
95
96
|
trace: (toolName: string, args: Record<string, unknown>) => void;
|
|
97
|
+
consumer?: object;
|
|
96
98
|
}
|
|
97
99
|
export { EToolEffect } from './index';
|
|
98
100
|
export declare const runWithToolContext: <T>(context: IToolContext, fn: () => Promise<T>) => Promise<T>;
|
|
@@ -189,6 +191,14 @@ export interface IEventsCapability {
|
|
|
189
191
|
export interface IReposCapability {
|
|
190
192
|
creds: ISourceRepoCred[];
|
|
191
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* The providers a toolset declared (`ECapability.PROVIDERS` + its `providers` list), and ONLY those: reads
|
|
196
|
+
* (getData) and operations (getOperations / runOperation), through the core's handle, so the core knows who
|
|
197
|
+
* reads and logs who operates. Undefined: the toolset did not declare that provider, or it is not installed here.
|
|
198
|
+
*/
|
|
199
|
+
export interface IProvidersCapability {
|
|
200
|
+
get(providerId: string): IProviderHandle | undefined;
|
|
201
|
+
}
|
|
192
202
|
/**
|
|
193
203
|
* What a tool receives when it runs. Only the capabilities its toolset declared come filled in:
|
|
194
204
|
* a `requires: []` receives nothing but `trace`.
|
|
@@ -200,6 +210,7 @@ export interface IToolHost {
|
|
|
200
210
|
metrics?: IMetricsCapability;
|
|
201
211
|
events?: IEventsCapability;
|
|
202
212
|
repos?: IReposCapability;
|
|
213
|
+
providers?: IProvidersCapability;
|
|
203
214
|
}
|
|
204
215
|
/** An executable tool: what travels to the front end (IAiToolInfo) plus what it takes to invoke it. */
|
|
205
216
|
export interface IAiTool extends IAiToolInfo {
|
|
@@ -263,7 +274,7 @@ export declare const listToolsetInfos: () => IAiToolsetInfo[];
|
|
|
263
274
|
* if every site assembled its own object, one of them being too generous would be enough for the
|
|
264
275
|
* declaration to stop meaning anything.
|
|
265
276
|
*/
|
|
266
|
-
export declare const buildToolHost: (requires: ECapability[], context: IToolContext) => IToolHost;
|
|
277
|
+
export declare const buildToolHost: (requires: ECapability[], context: IToolContext, providers?: string[]) => IToolHost;
|
|
267
278
|
/**
|
|
268
279
|
* Invokes a tool by its qualified reference. A single invocation path for built-in and installed alike,
|
|
269
280
|
* with the host built according to the `requires` of ITS toolset.
|
package/dist/back.js
CHANGED
|
@@ -803,14 +803,7 @@ exports.getToolset = getToolset;
|
|
|
803
803
|
const listToolsets = () => [...toolsetRegistry.values()];
|
|
804
804
|
exports.listToolsets = listToolsets;
|
|
805
805
|
/** What is sent to the front end: the descriptors, without inputSchema or execute. */
|
|
806
|
-
const listToolsetInfos = () => (0, exports.listToolsets)().map(t => ({
|
|
807
|
-
id: t.id,
|
|
808
|
-
version: t.version,
|
|
809
|
-
displayName: t.displayName,
|
|
810
|
-
description: t.description,
|
|
811
|
-
requires: t.requires,
|
|
812
|
-
tools: t.tools.map(x => ({ name: x.name, description: x.description, effect: x.effect, sensitivity: x.sensitivity }))
|
|
813
|
-
}));
|
|
806
|
+
const listToolsetInfos = () => (0, exports.listToolsets)().map(t => (Object.assign(Object.assign({ id: t.id, version: t.version, displayName: t.displayName, description: t.description, requires: t.requires }, (t.providers ? { providers: t.providers } : {})), { tools: t.tools.map(x => ({ name: x.name, description: x.description, effect: x.effect, sensitivity: x.sensitivity })) })));
|
|
814
807
|
exports.listToolsetInfos = listToolsetInfos;
|
|
815
808
|
/**
|
|
816
809
|
* Builds a toolset's host from the core context, provisioning ONLY what was declared.
|
|
@@ -819,7 +812,7 @@ exports.listToolsetInfos = listToolsetInfos;
|
|
|
819
812
|
* if every site assembled its own object, one of them being too generous would be enough for the
|
|
820
813
|
* declaration to stop meaning anything.
|
|
821
814
|
*/
|
|
822
|
-
const buildToolHost = (requires, context) => {
|
|
815
|
+
const buildToolHost = (requires, context, providers) => {
|
|
823
816
|
var _a, _b, _c;
|
|
824
817
|
const host = { trace: context.trace };
|
|
825
818
|
const ci = context.clusterInfo;
|
|
@@ -844,6 +837,17 @@ const buildToolHost = (requires, context) => {
|
|
|
844
837
|
host.events = { recent: ((_b = context.clusterEvents) !== null && _b !== void 0 ? _b : []) };
|
|
845
838
|
if (requires.includes(index_1.ECapability.REPOS))
|
|
846
839
|
host.repos = { creds: (_c = context.sourceRepos) !== null && _c !== void 0 ? _c : [] };
|
|
840
|
+
/*
|
|
841
|
+
The providers: only the ones the toolset NAMED, asked for on behalf of the extension the tools run for
|
|
842
|
+
(context.consumer), so the core's registry and its log of operations attribute them. No consumer, or a
|
|
843
|
+
host without getProvider, lends nothing: a tool then says the provider is not available.
|
|
844
|
+
*/
|
|
845
|
+
if (requires.includes(index_1.ECapability.PROVIDERS) && context.consumer && typeof (ci === null || ci === void 0 ? void 0 : ci.getProvider) === 'function') {
|
|
846
|
+
const declared = new Set(providers !== null && providers !== void 0 ? providers : []);
|
|
847
|
+
host.providers = {
|
|
848
|
+
get: (providerId) => declared.has(providerId) ? ci.getProvider(providerId, context.consumer) : undefined
|
|
849
|
+
};
|
|
850
|
+
}
|
|
847
851
|
return host;
|
|
848
852
|
};
|
|
849
853
|
exports.buildToolHost = buildToolHost;
|
|
@@ -858,7 +862,7 @@ const invokeToolRef = async (ref, args, context) => {
|
|
|
858
862
|
const resolved = (0, exports.resolveToolRef)(ref);
|
|
859
863
|
if (!resolved)
|
|
860
864
|
throw new Error(`[common-ai] unknown tool '${ref}'`);
|
|
861
|
-
return resolved.tool.execute(args, (0, exports.buildToolHost)(resolved.toolset.requires, context));
|
|
865
|
+
return resolved.tool.execute(args, (0, exports.buildToolHost)(resolved.toolset.requires, context, resolved.toolset.providers));
|
|
862
866
|
};
|
|
863
867
|
exports.invokeToolRef = invokeToolRef;
|
|
864
868
|
/** Resolves a qualified reference '<toolset>/<tool>' against the registry. */
|
|
@@ -948,7 +952,7 @@ requesterId) => {
|
|
|
948
952
|
description: e.tool.description,
|
|
949
953
|
inputSchema: e.tool.inputSchema,
|
|
950
954
|
execute: async (rawArgs) => {
|
|
951
|
-
var _a, _b, _c, _d, _e;
|
|
955
|
+
var _a, _b, _c, _d, _e, _f;
|
|
952
956
|
const args = (rawArgs !== null && rawArgs !== void 0 ? rawArgs : {});
|
|
953
957
|
const invocation = invocationOf(args);
|
|
954
958
|
const started = Date.now();
|
|
@@ -960,18 +964,18 @@ requesterId) => {
|
|
|
960
964
|
(_a = hooks.observe) === null || _a === void 0 ? void 0 : _a.call(hooks, invocation, { ok: false, error: denial.error, ms: Date.now() - started, denied: true });
|
|
961
965
|
return denial;
|
|
962
966
|
}
|
|
963
|
-
const host = (0, exports.buildToolHost)((_c = (_b = (0, exports.getToolset)(e.toolsetId)) === null || _b === void 0 ? void 0 : _b.requires) !== null && _c !== void 0 ? _c : [], context);
|
|
967
|
+
const host = (0, exports.buildToolHost)((_c = (_b = (0, exports.getToolset)(e.toolsetId)) === null || _b === void 0 ? void 0 : _b.requires) !== null && _c !== void 0 ? _c : [], context, (_d = (0, exports.getToolset)(e.toolsetId)) === null || _d === void 0 ? void 0 : _d.providers);
|
|
964
968
|
try {
|
|
965
969
|
// runWithToolContext also wraps the tools written against the OLD contract (the ones
|
|
966
970
|
// that read ctx()). That is what lets the 43 be migrated package by package in S3,
|
|
967
971
|
// instead of having to rewrite them all before this path can be used at all.
|
|
968
972
|
const result = await (0, exports.runWithToolContext)(context, () => e.tool.execute(args, host));
|
|
969
|
-
(
|
|
973
|
+
(_e = hooks.observe) === null || _e === void 0 ? void 0 : _e.call(hooks, invocation, { ok: true, result, ms: Date.now() - started });
|
|
970
974
|
return result;
|
|
971
975
|
}
|
|
972
976
|
catch (err) {
|
|
973
977
|
const message = err instanceof Error ? err.message : String(err);
|
|
974
|
-
(
|
|
978
|
+
(_f = hooks.observe) === null || _f === void 0 ? void 0 : _f.call(hooks, invocation, { ok: false, error: message, ms: Date.now() - started });
|
|
975
979
|
return { error: message };
|
|
976
980
|
}
|
|
977
981
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -87,7 +87,8 @@ export declare enum ECapability {
|
|
|
87
87
|
K8S = "k8s",// cluster access
|
|
88
88
|
METRICS = "metrics",// metrics, current and historical
|
|
89
89
|
EVENTS = "events",// cluster event buffer
|
|
90
|
-
REPOS = "repos"
|
|
90
|
+
REPOS = "repos",// source repository credentials
|
|
91
|
+
PROVIDERS = "providers"
|
|
91
92
|
}
|
|
92
93
|
/** Separator of a qualified reference to a tool: '<toolset>/<tool>'. */
|
|
93
94
|
export declare const TOOL_REF_SEPARATOR = "/";
|
|
@@ -110,6 +111,8 @@ export interface IAiToolsetInfo {
|
|
|
110
111
|
displayName: string;
|
|
111
112
|
description: string;
|
|
112
113
|
requires: ECapability[];
|
|
114
|
+
/** With ECapability.PROVIDERS: the ids of the providers it needs (e.g. ['aws']). The host lends ONLY these. */
|
|
115
|
+
providers?: string[];
|
|
113
116
|
tools: IAiToolInfo[];
|
|
114
117
|
}
|
|
115
118
|
export interface IToolsetGrant {
|
package/dist/index.js
CHANGED
|
@@ -54,7 +54,8 @@ var ECapability;
|
|
|
54
54
|
ECapability["K8S"] = "k8s";
|
|
55
55
|
ECapability["METRICS"] = "metrics";
|
|
56
56
|
ECapability["EVENTS"] = "events";
|
|
57
|
-
ECapability["REPOS"] = "repos";
|
|
57
|
+
ECapability["REPOS"] = "repos";
|
|
58
|
+
ECapability["PROVIDERS"] = "providers"; // handles of the providers the toolset names in `providers` (reads and operations)
|
|
58
59
|
})(ECapability || (exports.ECapability = ECapability = {}));
|
|
59
60
|
/** Separator of a qualified reference to a tool: '<toolset>/<tool>'. */
|
|
60
61
|
exports.TOOL_REF_SEPARATOR = '/';
|
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.80",
|
|
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",
|
|
@@ -56,17 +56,18 @@
|
|
|
56
56
|
"zod": "^4.3.6"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
59
|
+
"@kubernetes/client-node": ">=1.0.0",
|
|
60
|
+
"react": ">=18.0.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
+
"@kubernetes/client-node": "^1.4.0",
|
|
63
64
|
"@kwirthmagnify/kwirth-common": "^0.5.76",
|
|
65
|
+
"@kwirthmagnify/kwirth-common-back": "^0.6.11",
|
|
64
66
|
"@mui/icons-material": "9.5.0",
|
|
65
67
|
"@mui/material": "9.5.0",
|
|
66
68
|
"@types/node": "^25.9.1",
|
|
67
69
|
"@types/react": "^18.3.0",
|
|
68
|
-
"typescript": "^5.4.0"
|
|
69
|
-
"@kubernetes/client-node": "^1.4.0"
|
|
70
|
+
"typescript": "^5.4.0"
|
|
70
71
|
},
|
|
71
72
|
"peerDependenciesMeta": {
|
|
72
73
|
"@kubernetes/client-node": {
|