@kwirthmagnify/kwirth-common-ai 0.5.51 → 0.5.53
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 +138 -5
- package/dist/back.js +258 -53
- package/dist/index.d.ts +43 -0
- package/dist/index.js +51 -1
- package/package.json +2 -2
package/dist/back.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ILlm, ILlmProvider, IAgent } from './index';
|
|
1
|
+
import { ILlm, ILlmProvider, IAgent, EToolEffect, IAiToolInfo, IAiToolsetInfo } from './index';
|
|
2
2
|
interface ILogChannel {
|
|
3
3
|
logInfo?: (msg: string) => void;
|
|
4
4
|
logWarning?: (msg: string) => void;
|
|
@@ -46,16 +46,40 @@ export interface IToolContext {
|
|
|
46
46
|
sourceRepos?: ISourceRepoCred[];
|
|
47
47
|
trace: (toolName: string, args: Record<string, unknown>) => void;
|
|
48
48
|
}
|
|
49
|
-
export
|
|
50
|
-
READ = "read",
|
|
51
|
-
WRITE = "write"
|
|
52
|
-
}
|
|
49
|
+
export { EToolEffect } from './index';
|
|
53
50
|
export interface IToolInfo {
|
|
54
51
|
name: string;
|
|
55
52
|
description: string;
|
|
56
53
|
effect: EToolEffect;
|
|
57
54
|
}
|
|
58
55
|
export declare const runWithToolContext: <T>(context: IToolContext, fn: () => Promise<T>) => Promise<T>;
|
|
56
|
+
/** Una tool ejecutable: lo que viaja al front (IAiToolInfo) mas lo que hace falta para invocarla. */
|
|
57
|
+
export interface IAiTool extends IAiToolInfo {
|
|
58
|
+
inputSchema: z.ZodTypeAny;
|
|
59
|
+
execute: (args: Record<string, unknown>) => Promise<unknown>;
|
|
60
|
+
}
|
|
61
|
+
/** Un toolset ejecutable: su ficha (IAiToolsetInfo) con las tools de verdad dentro. */
|
|
62
|
+
export interface IAiToolset extends Omit<IAiToolsetInfo, 'tools'> {
|
|
63
|
+
tools: IAiTool[];
|
|
64
|
+
}
|
|
65
|
+
export declare const isBuiltInToolsetId: (id: string) => boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Registra un toolset. `builtIn` solo lo usa el core para los suyos: marca el id como reservado.
|
|
68
|
+
* Lanza si el id ya esta ocupado — registrar dos veces el mismo id es un error de empaquetado, no algo
|
|
69
|
+
* que deba resolverse en silencio pisando al primero.
|
|
70
|
+
*/
|
|
71
|
+
export declare const registerToolset: (toolset: IAiToolset, builtIn?: boolean) => void;
|
|
72
|
+
/** Retira un toolset del registro (desinstalacion). Los built-in no se retiran. */
|
|
73
|
+
export declare const unregisterToolset: (id: string) => boolean;
|
|
74
|
+
export declare const getToolset: (id: string) => IAiToolset | undefined;
|
|
75
|
+
export declare const listToolsets: () => IAiToolset[];
|
|
76
|
+
/** Lo que se le manda al front: las fichas, sin inputSchema ni execute. */
|
|
77
|
+
export declare const listToolsetInfos: () => IAiToolsetInfo[];
|
|
78
|
+
/** Resuelve una referencia cualificada '<toolset>/<tool>' contra el registro. */
|
|
79
|
+
export declare const resolveToolRef: (ref: string) => {
|
|
80
|
+
toolset: IAiToolset;
|
|
81
|
+
tool: IAiTool;
|
|
82
|
+
} | undefined;
|
|
59
83
|
export declare const tools: {
|
|
60
84
|
readonly list_namespaces: import("ai").Tool<Record<string, never>, {
|
|
61
85
|
namespaces: any;
|
|
@@ -103,6 +127,10 @@ export declare const tools: {
|
|
|
103
127
|
namespace: string;
|
|
104
128
|
}, {
|
|
105
129
|
namespace: string;
|
|
130
|
+
status: any;
|
|
131
|
+
labels: any;
|
|
132
|
+
resourceQuotas: any;
|
|
133
|
+
limitRanges: any;
|
|
106
134
|
pods: any;
|
|
107
135
|
deployments: any;
|
|
108
136
|
services: any;
|
|
@@ -111,11 +139,111 @@ export declare const tools: {
|
|
|
111
139
|
} | {
|
|
112
140
|
error: any;
|
|
113
141
|
namespace?: undefined;
|
|
142
|
+
status?: undefined;
|
|
143
|
+
labels?: undefined;
|
|
144
|
+
resourceQuotas?: undefined;
|
|
145
|
+
limitRanges?: undefined;
|
|
114
146
|
pods?: undefined;
|
|
115
147
|
deployments?: undefined;
|
|
116
148
|
services?: undefined;
|
|
117
149
|
configMaps?: undefined;
|
|
118
150
|
}>;
|
|
151
|
+
readonly get_namespace_yaml: import("ai").Tool<{
|
|
152
|
+
name: string;
|
|
153
|
+
}, any>;
|
|
154
|
+
readonly describe_service: import("ai").Tool<{
|
|
155
|
+
namespace: string;
|
|
156
|
+
name: string;
|
|
157
|
+
}, {
|
|
158
|
+
name: string;
|
|
159
|
+
namespace: string;
|
|
160
|
+
type: any;
|
|
161
|
+
clusterIP: any;
|
|
162
|
+
externalIPs: any;
|
|
163
|
+
loadBalancer: any;
|
|
164
|
+
sessionAffinity: any;
|
|
165
|
+
selector: any;
|
|
166
|
+
ports: any;
|
|
167
|
+
endpoints: any;
|
|
168
|
+
endpointCount: any;
|
|
169
|
+
error?: undefined;
|
|
170
|
+
} | {
|
|
171
|
+
error: any;
|
|
172
|
+
name?: undefined;
|
|
173
|
+
namespace?: undefined;
|
|
174
|
+
type?: undefined;
|
|
175
|
+
clusterIP?: undefined;
|
|
176
|
+
externalIPs?: undefined;
|
|
177
|
+
loadBalancer?: undefined;
|
|
178
|
+
sessionAffinity?: undefined;
|
|
179
|
+
selector?: undefined;
|
|
180
|
+
ports?: undefined;
|
|
181
|
+
endpoints?: undefined;
|
|
182
|
+
endpointCount?: undefined;
|
|
183
|
+
}>;
|
|
184
|
+
readonly describe_ingress: import("ai").Tool<{
|
|
185
|
+
namespace: string;
|
|
186
|
+
name: string;
|
|
187
|
+
}, {
|
|
188
|
+
name: string;
|
|
189
|
+
namespace: string;
|
|
190
|
+
ingressClass: any;
|
|
191
|
+
defaultBackend: string | undefined;
|
|
192
|
+
rules: any;
|
|
193
|
+
tls: any;
|
|
194
|
+
loadBalancer: any;
|
|
195
|
+
error?: undefined;
|
|
196
|
+
} | {
|
|
197
|
+
error: any;
|
|
198
|
+
name?: undefined;
|
|
199
|
+
namespace?: undefined;
|
|
200
|
+
ingressClass?: undefined;
|
|
201
|
+
defaultBackend?: undefined;
|
|
202
|
+
rules?: undefined;
|
|
203
|
+
tls?: undefined;
|
|
204
|
+
loadBalancer?: undefined;
|
|
205
|
+
}>;
|
|
206
|
+
readonly describe_controller: import("ai").Tool<{
|
|
207
|
+
namespace: string;
|
|
208
|
+
kind: "Deployment" | "StatefulSet" | "DaemonSet" | "ReplicaSet";
|
|
209
|
+
name: string;
|
|
210
|
+
}, {
|
|
211
|
+
kind: "Deployment" | "StatefulSet" | "DaemonSet" | "ReplicaSet";
|
|
212
|
+
name: string;
|
|
213
|
+
namespace: string;
|
|
214
|
+
replicas: {
|
|
215
|
+
desired: any;
|
|
216
|
+
current: any;
|
|
217
|
+
ready: any;
|
|
218
|
+
available: any;
|
|
219
|
+
updated: any;
|
|
220
|
+
} | {
|
|
221
|
+
desired: any;
|
|
222
|
+
ready: any;
|
|
223
|
+
available: any;
|
|
224
|
+
updated: any;
|
|
225
|
+
current?: undefined;
|
|
226
|
+
};
|
|
227
|
+
strategy: any;
|
|
228
|
+
conditions: any;
|
|
229
|
+
selector: any;
|
|
230
|
+
template: {
|
|
231
|
+
containers: any;
|
|
232
|
+
initContainers: any;
|
|
233
|
+
serviceAccount: any;
|
|
234
|
+
};
|
|
235
|
+
error?: undefined;
|
|
236
|
+
} | {
|
|
237
|
+
error: any;
|
|
238
|
+
kind?: undefined;
|
|
239
|
+
name?: undefined;
|
|
240
|
+
namespace?: undefined;
|
|
241
|
+
replicas?: undefined;
|
|
242
|
+
strategy?: undefined;
|
|
243
|
+
conditions?: undefined;
|
|
244
|
+
selector?: undefined;
|
|
245
|
+
template?: undefined;
|
|
246
|
+
}>;
|
|
119
247
|
readonly get_service_yaml: import("ai").Tool<{
|
|
120
248
|
namespace: string;
|
|
121
249
|
name: string;
|
|
@@ -460,6 +588,11 @@ export declare const tools: {
|
|
|
460
588
|
namespace: string;
|
|
461
589
|
name: string;
|
|
462
590
|
}, any>;
|
|
591
|
+
readonly get_controller_yaml: import("ai").Tool<{
|
|
592
|
+
namespace: string;
|
|
593
|
+
kind: "Deployment" | "StatefulSet" | "DaemonSet" | "ReplicaSet";
|
|
594
|
+
name: string;
|
|
595
|
+
}, any>;
|
|
463
596
|
readonly get_rollout_history: import("ai").Tool<{
|
|
464
597
|
namespace: string;
|
|
465
598
|
name: string;
|
package/dist/back.js
CHANGED
|
@@ -33,7 +33,8 @@ 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.generateVision = exports.buildModel = void 0;
|
|
36
|
+
exports.runAgent = exports.selectAgentToolNames = exports.toolInfoList = exports.tools = exports.resolveToolRef = exports.listToolsetInfos = exports.listToolsets = exports.getToolset = exports.unregisterToolset = exports.registerToolset = exports.isBuiltInToolsetId = 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
|
+
const index_1 = require("./index");
|
|
37
38
|
const ai_1 = require("ai");
|
|
38
39
|
const zod_1 = require("zod");
|
|
39
40
|
const async_hooks_1 = require("async_hooks");
|
|
@@ -303,13 +304,11 @@ const fetchSourceFile = async (cred, projectPath, ref, path) => {
|
|
|
303
304
|
throw new Error(`GitLab ${resp.status} for ${projectPath}/${cleanPath}@${ref}`);
|
|
304
305
|
return await resp.text();
|
|
305
306
|
};
|
|
306
|
-
//
|
|
307
|
-
//
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
EToolEffect["WRITE"] = "write";
|
|
312
|
-
})(EToolEffect || (exports.EToolEffect = EToolEffect = {}));
|
|
307
|
+
// EToolEffect vive ahora en el contrato isomorfo (./index): el front tambien tiene que saber que hace una
|
|
308
|
+
// tool para poder marcarla en el selector, y hasta ahora no le llegaba. Se re-exporta para no romper a
|
|
309
|
+
// quien lo importe desde aqui.
|
|
310
|
+
var index_2 = require("./index");
|
|
311
|
+
Object.defineProperty(exports, "EToolEffect", { enumerable: true, get: function () { return index_2.EToolEffect; } });
|
|
313
312
|
const toolContextStorage = new async_hooks_1.AsyncLocalStorage();
|
|
314
313
|
const runWithToolContext = (context, fn) => toolContextStorage.run(context, fn);
|
|
315
314
|
exports.runWithToolContext = runWithToolContext;
|
|
@@ -389,6 +388,59 @@ const configRefsOfPodSpec = (spec) => {
|
|
|
389
388
|
}
|
|
390
389
|
return refs;
|
|
391
390
|
};
|
|
391
|
+
const toolsetRegistry = new Map();
|
|
392
|
+
// Los ids de los toolsets built-in del core estan RESERVADOS: un `aitoolset` de un tercero no puede
|
|
393
|
+
// ocuparlos. Sin esta regla, instalar un toolset ajeno llamado 'k8s-inventory' obligaria a renombrar el
|
|
394
|
+
// built-in, y con el se romperia todo techo y todo agente que lo tuviera configurado.
|
|
395
|
+
const builtInToolsetIds = new Set();
|
|
396
|
+
const isBuiltInToolsetId = (id) => builtInToolsetIds.has(id);
|
|
397
|
+
exports.isBuiltInToolsetId = isBuiltInToolsetId;
|
|
398
|
+
/**
|
|
399
|
+
* Registra un toolset. `builtIn` solo lo usa el core para los suyos: marca el id como reservado.
|
|
400
|
+
* Lanza si el id ya esta ocupado — registrar dos veces el mismo id es un error de empaquetado, no algo
|
|
401
|
+
* que deba resolverse en silencio pisando al primero.
|
|
402
|
+
*/
|
|
403
|
+
const registerToolset = (toolset, builtIn = false) => {
|
|
404
|
+
// El id reservado se comprueba ANTES que el duplicado, y el orden importa: un built-in siempre esta
|
|
405
|
+
// registrado, asi que chocar con uno da SIEMPRE duplicado tambien. Al reves, quien instala un toolset
|
|
406
|
+
// ajeno leeria 'already registered' —que suena a que lo instalo dos veces— en vez de enterarse de que
|
|
407
|
+
// ese id es del core y no lo puede ocupar.
|
|
408
|
+
if (!builtIn && builtInToolsetIds.has(toolset.id))
|
|
409
|
+
throw new Error(`[common-ai] toolset id '${toolset.id}' is reserved by a built-in toolset`);
|
|
410
|
+
if (toolsetRegistry.has(toolset.id))
|
|
411
|
+
throw new Error(`[common-ai] toolset '${toolset.id}' already registered`);
|
|
412
|
+
toolsetRegistry.set(toolset.id, toolset);
|
|
413
|
+
if (builtIn)
|
|
414
|
+
builtInToolsetIds.add(toolset.id);
|
|
415
|
+
};
|
|
416
|
+
exports.registerToolset = registerToolset;
|
|
417
|
+
/** Retira un toolset del registro (desinstalacion). Los built-in no se retiran. */
|
|
418
|
+
const unregisterToolset = (id) => builtInToolsetIds.has(id) ? false : toolsetRegistry.delete(id);
|
|
419
|
+
exports.unregisterToolset = unregisterToolset;
|
|
420
|
+
const getToolset = (id) => toolsetRegistry.get(id);
|
|
421
|
+
exports.getToolset = getToolset;
|
|
422
|
+
const listToolsets = () => [...toolsetRegistry.values()];
|
|
423
|
+
exports.listToolsets = listToolsets;
|
|
424
|
+
/** Lo que se le manda al front: las fichas, sin inputSchema ni execute. */
|
|
425
|
+
const listToolsetInfos = () => (0, exports.listToolsets)().map(t => ({
|
|
426
|
+
id: t.id,
|
|
427
|
+
version: t.version,
|
|
428
|
+
displayName: t.displayName,
|
|
429
|
+
description: t.description,
|
|
430
|
+
requires: t.requires,
|
|
431
|
+
tools: t.tools.map(x => ({ name: x.name, description: x.description, effect: x.effect, sensitivity: x.sensitivity }))
|
|
432
|
+
}));
|
|
433
|
+
exports.listToolsetInfos = listToolsetInfos;
|
|
434
|
+
/** Resuelve una referencia cualificada '<toolset>/<tool>' contra el registro. */
|
|
435
|
+
const resolveToolRef = (ref) => {
|
|
436
|
+
const parsed = (0, index_1.parseToolRef)(ref);
|
|
437
|
+
if (!parsed)
|
|
438
|
+
return undefined;
|
|
439
|
+
const toolset = toolsetRegistry.get(parsed.toolsetId);
|
|
440
|
+
const tool = toolset === null || toolset === void 0 ? void 0 : toolset.tools.find(t => t.name === parsed.toolName);
|
|
441
|
+
return toolset && tool ? { toolset, tool } : undefined;
|
|
442
|
+
};
|
|
443
|
+
exports.resolveToolRef = resolveToolRef;
|
|
392
444
|
exports.tools = {
|
|
393
445
|
// ── CLUSTER CONFIG ───────────────────────────────────────────────────────
|
|
394
446
|
list_namespaces: (0, ai_1.tool)({
|
|
@@ -401,11 +453,12 @@ exports.tools = {
|
|
|
401
453
|
const resp = await ctx().clusterInfo.coreApi.listNamespace();
|
|
402
454
|
return {
|
|
403
455
|
namespaces: resp.items.map((ns) => {
|
|
404
|
-
var _a, _b, _c, _d;
|
|
456
|
+
var _a, _b, _c, _d, _e;
|
|
405
457
|
return ({
|
|
406
458
|
name: (_a = ns.metadata) === null || _a === void 0 ? void 0 : _a.name,
|
|
407
|
-
|
|
408
|
-
|
|
459
|
+
uid: (_b = ns.metadata) === null || _b === void 0 ? void 0 : _b.uid,
|
|
460
|
+
status: (_c = ns.status) === null || _c === void 0 ? void 0 : _c.phase,
|
|
461
|
+
labels: (_e = (_d = ns.metadata) === null || _d === void 0 ? void 0 : _d.labels) !== null && _e !== void 0 ? _e : {}
|
|
409
462
|
});
|
|
410
463
|
})
|
|
411
464
|
};
|
|
@@ -465,27 +518,152 @@ exports.tools = {
|
|
|
465
518
|
}
|
|
466
519
|
}),
|
|
467
520
|
get_space_data: (0, ai_1.tool)({
|
|
468
|
-
description: '
|
|
521
|
+
description: 'Describes a Kubernetes namespace (equivalent to kubectl describe namespace + a rollup): its status and labels, ResourceQuota usage (used vs hard) and LimitRange defaults, plus the resources in it — pods (with restart count), deployments, services and configmap names.',
|
|
469
522
|
inputSchema: zod_1.z.object({ namespace: zod_1.z.string().describe('Name of the namespace to retrieve data for') }),
|
|
470
523
|
execute: async ({ namespace }) => {
|
|
471
|
-
var _a;
|
|
524
|
+
var _a, _b, _c, _d;
|
|
472
525
|
ctx().trace('get_space_data', { namespace });
|
|
473
526
|
try {
|
|
474
527
|
const c = ctx().clusterInfo;
|
|
475
|
-
|
|
528
|
+
// ns/quota/limits are best-effort: a missing RBAC for them must not hide the core namespace rollup.
|
|
529
|
+
const [ns, p, d, s, cm, rq, lr] = await Promise.all([
|
|
530
|
+
c.coreApi.readNamespace({ name: namespace }).catch(() => null),
|
|
531
|
+
c.coreApi.listNamespacedPod({ namespace }),
|
|
532
|
+
c.appsApi.listNamespacedDeployment({ namespace }),
|
|
533
|
+
c.coreApi.listNamespacedService({ namespace }),
|
|
534
|
+
c.coreApi.listNamespacedConfigMap({ namespace }),
|
|
535
|
+
c.coreApi.listNamespacedResourceQuota({ namespace }).catch(() => ({ items: [] })),
|
|
536
|
+
c.coreApi.listNamespacedLimitRange({ namespace }).catch(() => ({ items: [] }))
|
|
537
|
+
]);
|
|
476
538
|
return {
|
|
477
539
|
namespace,
|
|
540
|
+
status: (_a = ns === null || ns === void 0 ? void 0 : ns.status) === null || _a === void 0 ? void 0 : _a.phase,
|
|
541
|
+
labels: (_c = (_b = ns === null || ns === void 0 ? void 0 : ns.metadata) === null || _b === void 0 ? void 0 : _b.labels) !== null && _c !== void 0 ? _c : {},
|
|
542
|
+
resourceQuotas: rq.items.map((q) => { var _a, _b, _c, _d, _e, _f, _g; return ({ name: (_a = q.metadata) === null || _a === void 0 ? void 0 : _a.name, hard: (_e = (_c = (_b = q.status) === null || _b === void 0 ? void 0 : _b.hard) !== null && _c !== void 0 ? _c : (_d = q.spec) === null || _d === void 0 ? void 0 : _d.hard) !== null && _e !== void 0 ? _e : {}, used: (_g = (_f = q.status) === null || _f === void 0 ? void 0 : _f.used) !== null && _g !== void 0 ? _g : {} }); }),
|
|
543
|
+
limitRanges: lr.items.map((l) => { var _a, _b, _c; return ({ name: (_a = l.metadata) === null || _a === void 0 ? void 0 : _a.name, limits: (_c = (_b = l.spec) === null || _b === void 0 ? void 0 : _b.limits) !== null && _c !== void 0 ? _c : [] }); }),
|
|
478
544
|
pods: p.items.map((x) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j; return ({ name: (_a = x.metadata) === null || _a === void 0 ? void 0 : _a.name, phase: (_b = x.status) === null || _b === void 0 ? void 0 : _b.phase, nodeName: (_c = x.spec) === null || _c === void 0 ? void 0 : _c.nodeName, ready: ((_f = (_e = (_d = x.status) === null || _d === void 0 ? void 0 : _d.conditions) === null || _e === void 0 ? void 0 : _e.find((c) => c.type === 'Ready')) === null || _f === void 0 ? void 0 : _f.status) === 'True', restartCount: (_j = (_h = (_g = x.status) === null || _g === void 0 ? void 0 : _g.containerStatuses) === null || _h === void 0 ? void 0 : _h.reduce((sum, cs) => sum + cs.restartCount, 0)) !== null && _j !== void 0 ? _j : 0 }); }),
|
|
479
545
|
deployments: d.items.map((x) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j; return ({ name: (_a = x.metadata) === null || _a === void 0 ? void 0 : _a.name, replicas: (_b = x.spec) === null || _b === void 0 ? void 0 : _b.replicas, readyReplicas: (_d = (_c = x.status) === null || _c === void 0 ? void 0 : _c.readyReplicas) !== null && _d !== void 0 ? _d : 0, image: (_j = (_h = (_g = (_f = (_e = x.spec) === null || _e === void 0 ? void 0 : _e.template) === null || _f === void 0 ? void 0 : _f.spec) === null || _g === void 0 ? void 0 : _g.containers) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.image }); }),
|
|
480
546
|
services: s.items.map((x) => { var _a, _b, _c; return ({ name: (_a = x.metadata) === null || _a === void 0 ? void 0 : _a.name, type: (_b = x.spec) === null || _b === void 0 ? void 0 : _b.type, clusterIP: (_c = x.spec) === null || _c === void 0 ? void 0 : _c.clusterIP }); }),
|
|
481
547
|
configMaps: cm.items.map((x) => { var _a; return (_a = x.metadata) === null || _a === void 0 ? void 0 : _a.name; })
|
|
482
548
|
};
|
|
483
549
|
}
|
|
550
|
+
catch (err) {
|
|
551
|
+
return { error: (_d = err.message) !== null && _d !== void 0 ? _d : String(err) };
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}),
|
|
555
|
+
get_namespace_yaml: (0, ai_1.tool)({
|
|
556
|
+
description: 'Returns the full Kubernetes Namespace manifest (equivalent to kubectl get namespace -o yaml): complete metadata (uid, labels, annotations, creationTimestamp), spec (finalizers) and status. Use when you need a specific field the namespace summary doesn\'t include (e.g. its uid).',
|
|
557
|
+
inputSchema: zod_1.z.object({ name: zod_1.z.string().describe('Name of the namespace') }),
|
|
558
|
+
execute: async ({ name }) => {
|
|
559
|
+
var _a;
|
|
560
|
+
ctx().trace('get_namespace_yaml', { name });
|
|
561
|
+
try {
|
|
562
|
+
return await ctx().clusterInfo.coreApi.readNamespace({ name });
|
|
563
|
+
}
|
|
484
564
|
catch (err) {
|
|
485
565
|
return { error: (_a = err.message) !== null && _a !== void 0 ? _a : String(err) };
|
|
486
566
|
}
|
|
487
567
|
}
|
|
488
568
|
}),
|
|
569
|
+
describe_service: (0, ai_1.tool)({
|
|
570
|
+
description: 'Diagnostic summary of a Service (equivalent to kubectl describe service): type, clusterIP, ports, selector, sessionAffinity, external/loadBalancer, AND its live Endpoints — the pod IPs currently backing it (ready vs not-ready). Best tool to see WHY traffic isn\'t reaching pods (empty/not-ready endpoints = selector mismatch or unready pods).',
|
|
571
|
+
inputSchema: zod_1.z.object({
|
|
572
|
+
namespace: zod_1.z.string().describe('Namespace of the service'),
|
|
573
|
+
name: zod_1.z.string().describe('Name of the service')
|
|
574
|
+
}),
|
|
575
|
+
execute: async ({ namespace, name }) => {
|
|
576
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _l, _m, _o, _p, _q, _r;
|
|
577
|
+
ctx().trace('describe_service', { namespace, name });
|
|
578
|
+
try {
|
|
579
|
+
const c = ctx().clusterInfo;
|
|
580
|
+
const svc = await c.coreApi.readNamespacedService({ name, namespace });
|
|
581
|
+
const ep = await c.coreApi.readNamespacedEndpoints({ name, namespace }).catch(() => null);
|
|
582
|
+
const endpoints = ((_a = ep === null || ep === void 0 ? void 0 : ep.subsets) !== null && _a !== void 0 ? _a : []).flatMap((ss) => {
|
|
583
|
+
var _a, _b;
|
|
584
|
+
return [
|
|
585
|
+
...((_a = ss.addresses) !== null && _a !== void 0 ? _a : []).map((a) => { var _a; return ({ ip: a.ip, ready: true, targetRef: a.targetRef ? `${a.targetRef.kind}/${a.targetRef.name}` : undefined, ports: ((_a = ss.ports) !== null && _a !== void 0 ? _a : []).map((p) => p.port) }); }),
|
|
586
|
+
...((_b = ss.notReadyAddresses) !== null && _b !== void 0 ? _b : []).map((a) => { var _a; return ({ ip: a.ip, ready: false, targetRef: a.targetRef ? `${a.targetRef.kind}/${a.targetRef.name}` : undefined, ports: ((_a = ss.ports) !== null && _a !== void 0 ? _a : []).map((p) => p.port) }); })
|
|
587
|
+
];
|
|
588
|
+
});
|
|
589
|
+
return {
|
|
590
|
+
name, namespace,
|
|
591
|
+
type: (_b = svc.spec) === null || _b === void 0 ? void 0 : _b.type, clusterIP: (_c = svc.spec) === null || _c === void 0 ? void 0 : _c.clusterIP, externalIPs: (_e = (_d = svc.spec) === null || _d === void 0 ? void 0 : _d.externalIPs) !== null && _e !== void 0 ? _e : [],
|
|
592
|
+
loadBalancer: (_h = (_g = (_f = svc.status) === null || _f === void 0 ? void 0 : _f.loadBalancer) === null || _g === void 0 ? void 0 : _g.ingress) !== null && _h !== void 0 ? _h : [], sessionAffinity: (_j = svc.spec) === null || _j === void 0 ? void 0 : _j.sessionAffinity,
|
|
593
|
+
selector: (_m = (_l = svc.spec) === null || _l === void 0 ? void 0 : _l.selector) !== null && _m !== void 0 ? _m : {},
|
|
594
|
+
ports: (_q = (_p = (_o = svc.spec) === null || _o === void 0 ? void 0 : _o.ports) === null || _p === void 0 ? void 0 : _p.map((p) => ({ name: p.name, port: p.port, targetPort: p.targetPort, nodePort: p.nodePort, protocol: p.protocol }))) !== null && _q !== void 0 ? _q : [],
|
|
595
|
+
endpoints, // the pods actually behind the service right now (empty = nothing serving)
|
|
596
|
+
endpointCount: endpoints.length
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
catch (err) {
|
|
600
|
+
return { error: (_r = err.message) !== null && _r !== void 0 ? _r : String(err) };
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}),
|
|
604
|
+
describe_ingress: (0, ai_1.tool)({
|
|
605
|
+
description: 'Diagnostic summary of an Ingress (equivalent to kubectl describe ingress): ingressClass, the routing rules (host → path → backend service:port), the default backend, TLS (hosts + secret), and the load-balancer address assigned by the controller. Use to see how external traffic is routed to services.',
|
|
606
|
+
inputSchema: zod_1.z.object({
|
|
607
|
+
namespace: zod_1.z.string().describe('Namespace of the ingress'),
|
|
608
|
+
name: zod_1.z.string().describe('Name of the ingress')
|
|
609
|
+
}),
|
|
610
|
+
execute: async ({ namespace, name }) => {
|
|
611
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _l;
|
|
612
|
+
ctx().trace('describe_ingress', { namespace, name });
|
|
613
|
+
try {
|
|
614
|
+
const ing = await ctx().clusterInfo.networkApi.readNamespacedIngress({ name, namespace });
|
|
615
|
+
const backend = (b) => { var _a, _b, _c; return (b === null || b === void 0 ? void 0 : b.service) ? `${b.service.name}:${(_b = (_a = b.service.port) === null || _a === void 0 ? void 0 : _a.number) !== null && _b !== void 0 ? _b : (_c = b.service.port) === null || _c === void 0 ? void 0 : _c.name}` : ((b === null || b === void 0 ? void 0 : b.resource) ? `${b.resource.kind}/${b.resource.name}` : undefined); };
|
|
616
|
+
return {
|
|
617
|
+
name, namespace,
|
|
618
|
+
ingressClass: (_a = ing.spec) === null || _a === void 0 ? void 0 : _a.ingressClassName,
|
|
619
|
+
defaultBackend: backend((_b = ing.spec) === null || _b === void 0 ? void 0 : _b.defaultBackend),
|
|
620
|
+
rules: ((_d = (_c = ing.spec) === null || _c === void 0 ? void 0 : _c.rules) !== null && _d !== void 0 ? _d : []).flatMap((r) => { var _a, _b; return ((_b = (_a = r.http) === null || _a === void 0 ? void 0 : _a.paths) !== null && _b !== void 0 ? _b : []).map((p) => ({ host: r.host, path: p.path, pathType: p.pathType, backend: backend(p.backend) })); }),
|
|
621
|
+
tls: ((_f = (_e = ing.spec) === null || _e === void 0 ? void 0 : _e.tls) !== null && _f !== void 0 ? _f : []).map((t) => ({ hosts: t.hosts, secretName: t.secretName })),
|
|
622
|
+
loadBalancer: (_j = (_h = (_g = ing.status) === null || _g === void 0 ? void 0 : _g.loadBalancer) === null || _h === void 0 ? void 0 : _h.ingress) !== null && _j !== void 0 ? _j : []
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
catch (err) {
|
|
626
|
+
return { error: (_l = err.message) !== null && _l !== void 0 ? _l : String(err) };
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}),
|
|
630
|
+
describe_controller: (0, ai_1.tool)({
|
|
631
|
+
description: 'Diagnostic summary of a workload controller (equivalent to kubectl describe deployment/statefulset/daemonset/replicaset): replica counts (desired/ready/available/updated), rollout strategy, conditions (Available/Progressing + reason — why it is not fully rolled out), selector, and its pod template (image, resources, probes). Parametrised by kind, so one call covers any controller type.',
|
|
632
|
+
inputSchema: zod_1.z.object({
|
|
633
|
+
namespace: zod_1.z.string().describe('Namespace of the controller'),
|
|
634
|
+
kind: zod_1.z.enum(['Deployment', 'StatefulSet', 'DaemonSet', 'ReplicaSet']).describe('Controller kind'),
|
|
635
|
+
name: zod_1.z.string().describe('Name of the controller')
|
|
636
|
+
}),
|
|
637
|
+
execute: async ({ namespace, kind, name }) => {
|
|
638
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _l, _m, _o, _p, _q, _r, _s;
|
|
639
|
+
ctx().trace('describe_controller', { namespace, kind, name });
|
|
640
|
+
try {
|
|
641
|
+
const a = ctx().clusterInfo.appsApi;
|
|
642
|
+
const obj = kind === 'StatefulSet' ? await a.readNamespacedStatefulSet({ name, namespace })
|
|
643
|
+
: kind === 'DaemonSet' ? await a.readNamespacedDaemonSet({ name, namespace })
|
|
644
|
+
: kind === 'ReplicaSet' ? await a.readNamespacedReplicaSet({ name, namespace })
|
|
645
|
+
: await a.readNamespacedDeployment({ name, namespace });
|
|
646
|
+
const spec = (_a = obj.spec) !== null && _a !== void 0 ? _a : {}, status = (_b = obj.status) !== null && _b !== void 0 ? _b : {};
|
|
647
|
+
const tpl = (_d = (_c = spec.template) === null || _c === void 0 ? void 0 : _c.spec) !== null && _d !== void 0 ? _d : {};
|
|
648
|
+
const container = (ct) => ({ name: ct.name, image: ct.image, resources: ct.resources, livenessProbe: !!ct.livenessProbe, readinessProbe: !!ct.readinessProbe });
|
|
649
|
+
// DaemonSet reports scheduling counts; the others report replica counts.
|
|
650
|
+
const replicas = kind === 'DaemonSet'
|
|
651
|
+
? { desired: status.desiredNumberScheduled, current: status.currentNumberScheduled, ready: status.numberReady, available: status.numberAvailable, updated: status.updatedNumberScheduled }
|
|
652
|
+
: { desired: spec.replicas, ready: (_e = status.readyReplicas) !== null && _e !== void 0 ? _e : 0, available: (_f = status.availableReplicas) !== null && _f !== void 0 ? _f : 0, updated: (_g = status.updatedReplicas) !== null && _g !== void 0 ? _g : 0 };
|
|
653
|
+
return {
|
|
654
|
+
kind, name, namespace,
|
|
655
|
+
replicas,
|
|
656
|
+
strategy: (_j = (_h = spec.strategy) === null || _h === void 0 ? void 0 : _h.type) !== null && _j !== void 0 ? _j : (_l = spec.updateStrategy) === null || _l === void 0 ? void 0 : _l.type,
|
|
657
|
+
conditions: ((_m = status.conditions) !== null && _m !== void 0 ? _m : []).map((c) => ({ type: c.type, status: c.status, reason: c.reason, message: c.message })),
|
|
658
|
+
selector: (_p = (_o = spec.selector) === null || _o === void 0 ? void 0 : _o.matchLabels) !== null && _p !== void 0 ? _p : {},
|
|
659
|
+
template: { containers: ((_q = tpl.containers) !== null && _q !== void 0 ? _q : []).map(container), initContainers: ((_r = tpl.initContainers) !== null && _r !== void 0 ? _r : []).map(container), serviceAccount: tpl.serviceAccountName }
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
catch (err) {
|
|
663
|
+
return { error: (_s = err.message) !== null && _s !== void 0 ? _s : String(err) };
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}),
|
|
489
667
|
get_service_yaml: (0, ai_1.tool)({
|
|
490
668
|
description: 'Returns the full Kubernetes Service manifest (equivalent to kubectl get service -o yaml) for a given namespace and service name.',
|
|
491
669
|
inputSchema: zod_1.z.object({
|
|
@@ -1070,6 +1248,28 @@ exports.tools = {
|
|
|
1070
1248
|
}
|
|
1071
1249
|
}
|
|
1072
1250
|
}),
|
|
1251
|
+
get_controller_yaml: (0, ai_1.tool)({
|
|
1252
|
+
description: 'Returns the full manifest of a workload controller (equivalent to kubectl get <kind> -o yaml), for ANY kind — Deployment, StatefulSet, DaemonSet or ReplicaSet. Complete metadata (uid, labels, annotations), spec (pod template, strategy) and status. Use when you need a specific field the describe summary doesn\'t include.',
|
|
1253
|
+
inputSchema: zod_1.z.object({
|
|
1254
|
+
namespace: zod_1.z.string().describe('Namespace of the controller'),
|
|
1255
|
+
kind: zod_1.z.enum(['Deployment', 'StatefulSet', 'DaemonSet', 'ReplicaSet']).describe('Controller kind'),
|
|
1256
|
+
name: zod_1.z.string().describe('Name of the controller')
|
|
1257
|
+
}),
|
|
1258
|
+
execute: async ({ namespace, kind, name }) => {
|
|
1259
|
+
var _a;
|
|
1260
|
+
ctx().trace('get_controller_yaml', { namespace, kind, name });
|
|
1261
|
+
try {
|
|
1262
|
+
const a = ctx().clusterInfo.appsApi;
|
|
1263
|
+
return kind === 'StatefulSet' ? await a.readNamespacedStatefulSet({ name, namespace })
|
|
1264
|
+
: kind === 'DaemonSet' ? await a.readNamespacedDaemonSet({ name, namespace })
|
|
1265
|
+
: kind === 'ReplicaSet' ? await a.readNamespacedReplicaSet({ name, namespace })
|
|
1266
|
+
: await a.readNamespacedDeployment({ name, namespace });
|
|
1267
|
+
}
|
|
1268
|
+
catch (err) {
|
|
1269
|
+
return { error: (_a = err.message) !== null && _a !== void 0 ? _a : String(err) };
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
}),
|
|
1073
1273
|
get_rollout_history: (0, ai_1.tool)({
|
|
1074
1274
|
description: 'Returns the rollout history (revisions) of a Deployment via its ReplicaSets: per revision the image(s), replicas and pod-template summary (env with inline VALUES and their configMap/secret source, resources, command). Use to see WHAT CHANGED recently — a new image tag, a changed inline env value, a resource/command change — that may have broken the pods. Compare the newest revision against the previous one. NOTE: a change to a ConfigMap/Secret VALUE does NOT create a revision — use get_workload_config_refs for that.',
|
|
1075
1275
|
inputSchema: zod_1.z.object({
|
|
@@ -1214,49 +1414,54 @@ exports.tools = {
|
|
|
1214
1414
|
}),
|
|
1215
1415
|
};
|
|
1216
1416
|
exports.toolInfoList = [
|
|
1217
|
-
{ name: 'list_namespaces', effect: EToolEffect.READ, description: 'Lists all namespaces in the cluster with their status and labels.' },
|
|
1218
|
-
{ name: 'get_node_data', effect: EToolEffect.READ, description: 'Returns configuration info about all Kubernetes nodes (name, IP). Configuration only — not workload or usage data.' },
|
|
1219
|
-
{ name: 'get_cluster_data', effect: EToolEffect.READ, description: 'Returns general cluster info: name, flavour (AKS/EKS/GKE/k3s/k3d), total vCPUs, total memory, node count and readiness status.' },
|
|
1220
|
-
{ name: 'get_workload_data', effect: EToolEffect.READ, description: 'Returns all workloads in the cluster: deployments, statefulsets, daemonsets, pods and services. Optionally filter by namespace.' },
|
|
1221
|
-
{ name: 'get_space_data', effect: EToolEffect.READ, description: '
|
|
1222
|
-
{ name: '
|
|
1223
|
-
{ name: '
|
|
1224
|
-
{ name: '
|
|
1225
|
-
{ name: '
|
|
1226
|
-
{ name: '
|
|
1227
|
-
{ name: '
|
|
1228
|
-
{ name: '
|
|
1229
|
-
{ name: '
|
|
1230
|
-
{ name: '
|
|
1231
|
-
{ name: '
|
|
1232
|
-
{ name: '
|
|
1233
|
-
{ name: '
|
|
1234
|
-
{ name: '
|
|
1235
|
-
{ name: '
|
|
1236
|
-
{ name: '
|
|
1237
|
-
{ name: '
|
|
1238
|
-
{ name: '
|
|
1239
|
-
{ name: '
|
|
1240
|
-
{ name: '
|
|
1241
|
-
{ name: '
|
|
1242
|
-
{ name: '
|
|
1243
|
-
{ name: '
|
|
1244
|
-
{ name: '
|
|
1245
|
-
{ name: '
|
|
1246
|
-
{ name: '
|
|
1247
|
-
{ name: '
|
|
1248
|
-
{ name: '
|
|
1249
|
-
{ name: '
|
|
1250
|
-
{ name: '
|
|
1251
|
-
{ name: '
|
|
1252
|
-
{ name: '
|
|
1253
|
-
{ name: '
|
|
1254
|
-
{ name: '
|
|
1417
|
+
{ name: 'list_namespaces', effect: index_1.EToolEffect.READ, description: 'Lists all namespaces in the cluster with their status and labels.' },
|
|
1418
|
+
{ name: 'get_node_data', effect: index_1.EToolEffect.READ, description: 'Returns configuration info about all Kubernetes nodes (name, IP). Configuration only — not workload or usage data.' },
|
|
1419
|
+
{ name: 'get_cluster_data', effect: index_1.EToolEffect.READ, description: 'Returns general cluster info: name, flavour (AKS/EKS/GKE/k3s/k3d), total vCPUs, total memory, node count and readiness status.' },
|
|
1420
|
+
{ name: 'get_workload_data', effect: index_1.EToolEffect.READ, description: 'Returns all workloads in the cluster: deployments, statefulsets, daemonsets, pods and services. Optionally filter by namespace.' },
|
|
1421
|
+
{ name: 'get_space_data', effect: index_1.EToolEffect.READ, description: 'Describes a namespace (kubectl describe namespace + rollup): status/labels, ResourceQuota (used vs hard), LimitRange, plus its pods (restart count), deployments, services and configmaps.' },
|
|
1422
|
+
{ name: 'get_namespace_yaml', effect: index_1.EToolEffect.READ, description: 'Full Namespace manifest (kubectl get namespace -o yaml): complete metadata (uid, labels, annotations, creationTimestamp), spec and status — for any field the summary omits (e.g. its uid).' },
|
|
1423
|
+
{ name: 'get_service_yaml', effect: index_1.EToolEffect.READ, description: 'Returns the full Kubernetes Service manifest (equivalent to kubectl get service -o yaml) for a given namespace and service name.' },
|
|
1424
|
+
{ name: 'describe_service', effect: index_1.EToolEffect.READ, description: 'Diagnostic summary of a Service (kubectl describe service): type/clusterIP/ports/selector + its live Endpoints (the pod IPs backing it, ready vs not) — see why traffic isn\'t reaching pods.' },
|
|
1425
|
+
{ name: 'list_services', effect: index_1.EToolEffect.READ, description: 'Lists all Services in the cluster with full details (type, clusterIP, ports, selector). Optionally filter by namespace.' },
|
|
1426
|
+
{ name: 'list_ingresses', effect: index_1.EToolEffect.READ, description: 'Lists all Ingresses in the cluster (hosts, paths, TLS, backend services). Optionally filter by namespace.' },
|
|
1427
|
+
{ name: 'get_ingress_yaml', effect: index_1.EToolEffect.READ, description: 'Returns the full Kubernetes Ingress manifest (equivalent to kubectl get ingress -o yaml) for a given namespace and ingress name.' },
|
|
1428
|
+
{ name: 'describe_ingress', effect: index_1.EToolEffect.READ, description: 'Diagnostic summary of an Ingress (kubectl describe ingress): ingressClass, rules (host → path → backend service:port), default backend, TLS, and the load-balancer address.' },
|
|
1429
|
+
{ name: 'get_cluster_usage', effect: index_1.EToolEffect.READ, description: 'Returns current overall cluster resource usage: CPU%, memory%, network Mbps, total vCPUs and total memory GB.' },
|
|
1430
|
+
{ name: 'get_node_usage', effect: index_1.EToolEffect.READ, description: 'Returns current CPU and memory usage for one node or all nodes from the latest metrics reading.' },
|
|
1431
|
+
{ name: 'get_deployment_usage', effect: index_1.EToolEffect.READ, description: 'Returns current aggregated CPU and memory usage for all pods belonging to a specific deployment.' },
|
|
1432
|
+
{ name: 'get_prev_cluster_usage', effect: index_1.EToolEffect.READ, description: 'Returns historical overall cluster usage over the last N metrics readings (CPU%, memory%, network Mbps).' },
|
|
1433
|
+
{ name: 'get_prev_node_usage', effect: index_1.EToolEffect.READ, description: 'Returns historical CPU and memory usage for one or all nodes over the last N metrics readings.' },
|
|
1434
|
+
{ name: 'get_prev_deployment_usage', effect: index_1.EToolEffect.READ, description: 'Returns historical aggregated CPU and memory usage for a deployment over the last N metrics readings.' },
|
|
1435
|
+
{ name: 'get_prev_space_data', effect: index_1.EToolEffect.READ, description: 'Returns historical aggregated CPU and memory usage for all pods in a namespace over the last N metrics readings.' },
|
|
1436
|
+
{ name: 'add_node', effect: index_1.EToolEffect.WRITE, description: 'Adds a new agent node to the cluster. For k3d uses `k3d node create`. Cloud providers not yet implemented.' },
|
|
1437
|
+
{ name: 'remove_node', effect: index_1.EToolEffect.WRITE, description: 'Removes a node from the cluster (cordon + delete). For k3d uses `k3d node delete`. Cloud providers not yet implemented.' },
|
|
1438
|
+
{ name: 'stop_node', effect: index_1.EToolEffect.WRITE, description: 'Stops a running cluster node: cordons it then stops the container. For k3d uses `k3d node stop`.' },
|
|
1439
|
+
{ name: 'start_node', effect: index_1.EToolEffect.WRITE, description: 'Starts a previously stopped cluster node and uncordons it. For k3d uses `k3d node start`.' },
|
|
1440
|
+
{ name: 'add_replica', effect: index_1.EToolEffect.WRITE, description: 'Scales up a deployment by adding one replica.' },
|
|
1441
|
+
{ name: 'remove_replica', effect: index_1.EToolEffect.WRITE, description: 'Scales down a deployment by removing one replica. Minimum of 1 replica is enforced.' },
|
|
1442
|
+
{ name: 'restart_deployment', effect: index_1.EToolEffect.WRITE, description: 'Rollout-restarts a deployment (recreates its pods gracefully via the restartedAt annotation, respecting the rolling update) — restart a workload without changing its spec.' },
|
|
1443
|
+
{ name: 'delete_pod', effect: index_1.EToolEffect.WRITE, description: 'Deletes a single pod; its controller recreates it. Surgical restart of one stuck pod (no rolling update — prefer restart_deployment for a whole workload).' },
|
|
1444
|
+
{ name: 'times_two', effect: index_1.EToolEffect.READ, description: 'Multiplies a number by two.' },
|
|
1445
|
+
{ name: 'father_of', effect: index_1.EToolEffect.READ, description: 'Returns the name of the father of a person.' },
|
|
1446
|
+
{ name: 'get_certificate_info', effect: index_1.EToolEffect.READ, description: 'Connects to a hostname via HTTPS and returns TLS certificate details: subject, issuer, validity dates, SANs, fingerprint and whether it is currently valid.' },
|
|
1447
|
+
{ name: 'get_cluster_events', effect: index_1.EToolEffect.READ, description: 'Returns recent buffered Kubernetes events for this cluster (warnings + object lifecycle changes); filter by warnings only or namespace.' },
|
|
1448
|
+
{ name: 'get_object_events', effect: index_1.EToolEffect.READ, description: 'Returns recent events for a specific Kubernetes object (namespace + name), including related kube Events.' },
|
|
1449
|
+
{ name: 'get_pod_logs', effect: index_1.EToolEffect.READ, description: 'Returns container logs for a pod (kubectl logs); previous:true reads the crashed instance logs — the root cause of a CrashLoopBackOff.' },
|
|
1450
|
+
{ name: 'describe_pod', effect: index_1.EToolEffect.READ, description: 'Diagnostic summary of a pod (kubectl describe pod): per-container waiting/terminated reason + exitCode (OOMKilled/CrashLoop…), restart count, probes.' },
|
|
1451
|
+
{ name: 'get_pod_yaml', effect: index_1.EToolEffect.READ, description: 'Full Pod manifest (kubectl get pod -o yaml): spec (env, volumes, resources, probes) and status.' },
|
|
1452
|
+
{ name: 'get_deployment_yaml', effect: index_1.EToolEffect.READ, description: 'Full Deployment manifest (kubectl get deployment -o yaml): pod template (image, env, resources, probes) and strategy.' },
|
|
1453
|
+
{ name: 'describe_controller', effect: index_1.EToolEffect.READ, description: 'Diagnostic summary of a workload controller (kubectl describe deployment/statefulset/daemonset/replicaset): replica counts (desired/ready/available/updated), strategy, conditions (why not rolled out), selector, pod template. Parametrised by kind.' },
|
|
1454
|
+
{ name: 'get_controller_yaml', effect: index_1.EToolEffect.READ, description: 'Full manifest of any workload controller (kubectl get <kind> -o yaml): Deployment/StatefulSet/DaemonSet/ReplicaSet — complete metadata (uid, annotations), spec and status. Parametrised by kind, for any field the describe omits.' },
|
|
1455
|
+
{ name: 'get_rollout_history', effect: index_1.EToolEffect.READ, description: 'Rollout revisions of a Deployment (via ReplicaSets): image + template per revision (env with inline values + configMap/secret source), to see what changed (new image/env/resource) that may have broken the pods.' },
|
|
1456
|
+
{ name: 'get_configmap', effect: index_1.EToolEffect.READ, description: 'A ConfigMap\'s data (key→value) + lastModified. A ConfigMap value change does NOT create a rollout revision, so check it for a crash with no deployment change.' },
|
|
1457
|
+
{ name: 'get_secret', effect: index_1.EToolEffect.READ, description: 'A Secret\'s keys + type + lastModified (VALUES REDACTED). Check whether a consumed Secret changed recently (no rollout revision is created by a value change).' },
|
|
1458
|
+
{ name: 'get_workload_config_refs', effect: index_1.EToolEffect.READ, description: 'The ConfigMaps/Secrets a Deployment consumes (envFrom/valueFrom/volumes) with each one\'s lastModified — find a config source that changed WITHOUT a rollout and broke the pods.' },
|
|
1459
|
+
{ name: 'get_source_file', effect: index_1.EToolEffect.READ, description: 'Fetches a file from a Git repo (GitHub/GitLab) at a ref — inspect the source behind a crash by following the stack trace to the offending file:line.' },
|
|
1255
1460
|
];
|
|
1256
1461
|
// Resolves the tool names an agent may use: autoTools = full catalog, otherwise its own list
|
|
1257
1462
|
// (intersected with the catalog); readOnly filters out WRITE-effect tools. Pure (no LLM) → unit-testable.
|
|
1258
1463
|
const selectAgentToolNames = (agent) => {
|
|
1259
|
-
const writeNames = new Set(exports.toolInfoList.filter(t => t.effect === EToolEffect.WRITE).map(t => t.name));
|
|
1464
|
+
const writeNames = new Set(exports.toolInfoList.filter(t => t.effect === index_1.EToolEffect.WRITE).map(t => t.name));
|
|
1260
1465
|
const catalogNames = exports.toolInfoList.map(t => t.name);
|
|
1261
1466
|
const wanted = agent.autoTools ? catalogNames : agent.tools.filter(n => catalogNames.includes(n));
|
|
1262
1467
|
return wanted.filter(n => !(agent.readOnly && writeNames.has(n)));
|
package/dist/index.d.ts
CHANGED
|
@@ -38,3 +38,46 @@ export interface IAgent {
|
|
|
38
38
|
steps: number;
|
|
39
39
|
readOnly: boolean;
|
|
40
40
|
}
|
|
41
|
+
/** Que le hace una tool al mundo. */
|
|
42
|
+
export declare enum EToolEffect {
|
|
43
|
+
READ = "read",
|
|
44
|
+
WRITE = "write"
|
|
45
|
+
}
|
|
46
|
+
export declare enum EToolSensitivity {
|
|
47
|
+
PUBLIC = "public",// inventario, formas, nombres
|
|
48
|
+
INTERNAL = "internal",// configuracion, eventos, logs
|
|
49
|
+
SECRET = "secret"
|
|
50
|
+
}
|
|
51
|
+
export declare enum ECapability {
|
|
52
|
+
K8S = "k8s",// acceso al cluster
|
|
53
|
+
METRICS = "metrics",// metricas, actuales e historicas
|
|
54
|
+
EVENTS = "events",// buffer de eventos del cluster
|
|
55
|
+
REPOS = "repos"
|
|
56
|
+
}
|
|
57
|
+
/** Separador de una referencia cualificada a una tool: '<toolset>/<tool>'. */
|
|
58
|
+
export declare const TOOL_REF_SEPARATOR = "/";
|
|
59
|
+
export declare const toolRef: (toolsetId: string, toolName: string) => string;
|
|
60
|
+
export declare const parseToolRef: (ref: string) => {
|
|
61
|
+
toolsetId: string;
|
|
62
|
+
toolName: string;
|
|
63
|
+
} | undefined;
|
|
64
|
+
/** Una tool, sin lo necesario para ejecutarla. Es lo que viaja al front. */
|
|
65
|
+
export interface IAiToolInfo {
|
|
66
|
+
name: string;
|
|
67
|
+
description: string;
|
|
68
|
+
effect: EToolEffect;
|
|
69
|
+
sensitivity: EToolSensitivity;
|
|
70
|
+
}
|
|
71
|
+
/** Un toolset, sin lo necesario para ejecutar sus tools. Es lo que viaja al front. */
|
|
72
|
+
export interface IAiToolsetInfo {
|
|
73
|
+
id: string;
|
|
74
|
+
version: string;
|
|
75
|
+
displayName: string;
|
|
76
|
+
description: string;
|
|
77
|
+
requires: ECapability[];
|
|
78
|
+
tools: IAiToolInfo[];
|
|
79
|
+
}
|
|
80
|
+
export interface IToolsetConfig {
|
|
81
|
+
activeToolsets: string[];
|
|
82
|
+
disabledTools: string[];
|
|
83
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STORAGE_KEY_AGENTS = exports.PROVIDERS_AVAILABLE = exports.STORAGE_KEY_LLMS = exports.STORAGE_KEY_PROVIDERS = void 0;
|
|
3
|
+
exports.parseToolRef = exports.toolRef = exports.TOOL_REF_SEPARATOR = exports.ECapability = exports.EToolSensitivity = exports.EToolEffect = exports.STORAGE_KEY_AGENTS = exports.PROVIDERS_AVAILABLE = exports.STORAGE_KEY_LLMS = exports.STORAGE_KEY_PROVIDERS = void 0;
|
|
4
4
|
exports.STORAGE_KEY_PROVIDERS = 'kwirth-ai-providers';
|
|
5
5
|
exports.STORAGE_KEY_LLMS = 'kwirth-ai-llms';
|
|
6
6
|
exports.PROVIDERS_AVAILABLE = ['google', 'openai', 'openrouter', 'mistral', 'groq', 'deepseek', 'anthropic', 'openai-compat'];
|
|
7
7
|
exports.STORAGE_KEY_AGENTS = 'kwirth-ai-agents';
|
|
8
|
+
// ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
9
|
+
// Contrato de toolsets de IA (plan: plans/ai-tools/PLAN.md, S1)
|
|
10
|
+
//
|
|
11
|
+
// La unidad es el TOOLSET, no la tool: ninguna tool es alcanzable fuera de uno. Para gestionar una tool
|
|
12
|
+
// sola se empaqueta un toolset con una sola tool, y asi no existe el concepto de 'tool suelta' ni en el
|
|
13
|
+
// modelo, ni en la configuracion, ni en la UI.
|
|
14
|
+
//
|
|
15
|
+
// Lo de aqui es ISOMORFICO: lo que hace falta para DECIDIR sobre una tool (mostrarla, agruparla,
|
|
16
|
+
// autorizarla, configurarla). Lo que hace falta para EJECUTARLA —inputSchema y execute— vive en back.ts,
|
|
17
|
+
// porque el front ni lo necesita ni debe cargarlo.
|
|
18
|
+
// ─────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
19
|
+
/** Que le hace una tool al mundo. */
|
|
20
|
+
var EToolEffect;
|
|
21
|
+
(function (EToolEffect) {
|
|
22
|
+
EToolEffect["READ"] = "read";
|
|
23
|
+
EToolEffect["WRITE"] = "write";
|
|
24
|
+
})(EToolEffect || (exports.EToolEffect = EToolEffect = {}));
|
|
25
|
+
// Que EXPONE una tool, que no es lo mismo que que le hace al mundo. El caso que obliga a separarlo es
|
|
26
|
+
// get_secret: lee Secrets de Kubernetes, o sea que es READ y es lo mas peligroso del catalogo. Con una
|
|
27
|
+
// sola dimension no hay forma de denegarla sin denegar tambien 'listar namespaces'.
|
|
28
|
+
var EToolSensitivity;
|
|
29
|
+
(function (EToolSensitivity) {
|
|
30
|
+
EToolSensitivity["PUBLIC"] = "public";
|
|
31
|
+
EToolSensitivity["INTERNAL"] = "internal";
|
|
32
|
+
EToolSensitivity["SECRET"] = "secret"; // credenciales y material sensible
|
|
33
|
+
})(EToolSensitivity || (exports.EToolSensitivity = EToolSensitivity = {}));
|
|
34
|
+
// Lo que un toolset necesita del host para funcionar. El host provisiona SOLO lo declarado, que es lo que
|
|
35
|
+
// evita el cajon de sastre de hoy (siete campos que recibe todo el mundo por si acaso, con 'sourceRepos'
|
|
36
|
+
// existiendo para una sola de las 43 tools).
|
|
37
|
+
var ECapability;
|
|
38
|
+
(function (ECapability) {
|
|
39
|
+
ECapability["K8S"] = "k8s";
|
|
40
|
+
ECapability["METRICS"] = "metrics";
|
|
41
|
+
ECapability["EVENTS"] = "events";
|
|
42
|
+
ECapability["REPOS"] = "repos"; // credenciales de repositorios fuente
|
|
43
|
+
})(ECapability || (exports.ECapability = ECapability = {}));
|
|
44
|
+
/** Separador de una referencia cualificada a una tool: '<toolset>/<tool>'. */
|
|
45
|
+
exports.TOOL_REF_SEPARATOR = '/';
|
|
46
|
+
// ⚠️ Una tool se referencia SIEMPRE cualificada por su toolset ('k8s-inventory/list_namespaces'), nunca
|
|
47
|
+
// por su nombre a secas. Es lo que se persiste en la configuracion de agentes y techos, asi que no puede
|
|
48
|
+
// volverse ambiguo el dia que dos toolsets de terceros traigan los dos un 'get_pod_logs'.
|
|
49
|
+
const toolRef = (toolsetId, toolName) => `${toolsetId}${exports.TOOL_REF_SEPARATOR}${toolName}`;
|
|
50
|
+
exports.toolRef = toolRef;
|
|
51
|
+
const parseToolRef = (ref) => {
|
|
52
|
+
const i = ref.indexOf(exports.TOOL_REF_SEPARATOR);
|
|
53
|
+
if (i <= 0 || i === ref.length - 1)
|
|
54
|
+
return undefined;
|
|
55
|
+
return { toolsetId: ref.slice(0, i), toolName: ref.slice(i + 1) };
|
|
56
|
+
};
|
|
57
|
+
exports.parseToolRef = parseToolRef;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kwirthmagnify/kwirth-common-ai",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.53",
|
|
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",
|
|
7
|
-
"test": "node --test tests
|
|
7
|
+
"test": "node --test tests/*.test.mjs"
|
|
8
8
|
},
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|