@kwirthmagnify/kwirth-common-ai 0.5.24 → 0.5.25

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
@@ -12,6 +12,7 @@ export interface IToolContext {
12
12
  nodes: Map<string, any>;
13
13
  clusterInfo: any;
14
14
  clusterMetrics: any[];
15
+ clusterEvents?: any[];
15
16
  trace: (toolName: string, args: Record<string, unknown>) => void;
16
17
  }
17
18
  export declare enum EToolEffect {
@@ -318,6 +319,21 @@ export declare const tools: {
318
319
  hostname: string;
319
320
  port?: number | undefined;
320
321
  }, unknown>;
322
+ readonly get_cluster_events: import("ai").Tool<{
323
+ warningsOnly?: boolean | undefined;
324
+ namespace?: string | undefined;
325
+ limit?: number | undefined;
326
+ }, {
327
+ count: number;
328
+ events: Record<string, unknown>[];
329
+ }>;
330
+ readonly get_object_events: import("ai").Tool<{
331
+ namespace: string;
332
+ name: string;
333
+ }, {
334
+ count: number;
335
+ events: Record<string, unknown>[];
336
+ }>;
321
337
  };
322
338
  export declare const toolInfoList: IToolInfo[];
323
339
  export interface IAgentRunResult {
package/dist/back.js CHANGED
@@ -207,6 +207,29 @@ function mapToJson(data) {
207
207
  }
208
208
  return data;
209
209
  }
210
+ // Compact, LLM-friendly view of one buffered event ({type, obj}): a CoreV1Event (kind='Event') or an
211
+ // object lifecycle change.
212
+ const summarizeClusterEvent = (e) => {
213
+ var _a, _b, _c, _d;
214
+ const o = (_a = e === null || e === void 0 ? void 0 : e.obj) !== null && _a !== void 0 ? _a : {};
215
+ if (o.kind === 'Event') {
216
+ return {
217
+ kind: 'Event',
218
+ eventType: o.type, // Normal | Warning
219
+ reason: o.reason,
220
+ message: o.message,
221
+ involved: o.involvedObject ? { kind: o.involvedObject.kind, name: o.involvedObject.name, namespace: o.involvedObject.namespace } : undefined,
222
+ count: o.count,
223
+ lastTimestamp: (_b = o.lastTimestamp) !== null && _b !== void 0 ? _b : o.eventTime
224
+ };
225
+ }
226
+ return {
227
+ changeType: e === null || e === void 0 ? void 0 : e.type, // ADDED | MODIFIED
228
+ kind: o.kind,
229
+ name: (_c = o.metadata) === null || _c === void 0 ? void 0 : _c.name,
230
+ namespace: (_d = o.metadata) === null || _d === void 0 ? void 0 : _d.namespace
231
+ };
232
+ };
210
233
  exports.tools = {
211
234
  // ── CLUSTER CONFIG ───────────────────────────────────────────────────────
212
235
  list_namespaces: (0, ai_1.tool)({
@@ -694,6 +717,44 @@ exports.tools = {
694
717
  });
695
718
  }
696
719
  }),
720
+ // ── EVENTS (from the cluster events buffer in ctx().clusterEvents) ──────────
721
+ get_cluster_events: (0, ai_1.tool)({
722
+ description: 'Returns recent Kubernetes events buffered for this cluster: kube Events (warnings like crashloops/OOM/failed scheduling) and object lifecycle changes. Optionally filter to warnings only or by namespace.',
723
+ inputSchema: zod_1.z.object({
724
+ warningsOnly: zod_1.z.boolean().optional().describe('Only Warning-type kube Events'),
725
+ namespace: zod_1.z.string().optional().describe('Filter by namespace'),
726
+ limit: zod_1.z.number().optional().describe('Max events to return (default 50)')
727
+ }),
728
+ execute: async ({ warningsOnly, namespace, limit = 50 }) => {
729
+ var _a;
730
+ ctx().trace('get_cluster_events', { warningsOnly: !!warningsOnly, namespace: namespace !== null && namespace !== void 0 ? namespace : '*', limit });
731
+ let evs = (_a = ctx().clusterEvents) !== null && _a !== void 0 ? _a : [];
732
+ if (warningsOnly)
733
+ evs = evs.filter(e => { var _a; return ((_a = e === null || e === void 0 ? void 0 : e.obj) === null || _a === void 0 ? void 0 : _a.kind) === 'Event' && e.obj.type === 'Warning'; });
734
+ if (namespace)
735
+ evs = evs.filter(e => { var _a, _b, _c, _d, _e; return ((_c = (_b = (_a = e === null || e === void 0 ? void 0 : e.obj) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.namespace) !== null && _c !== void 0 ? _c : (_e = (_d = e === null || e === void 0 ? void 0 : e.obj) === null || _d === void 0 ? void 0 : _d.involvedObject) === null || _e === void 0 ? void 0 : _e.namespace) === namespace; });
736
+ return { count: evs.length, events: evs.slice(-limit).map(summarizeClusterEvent) };
737
+ }
738
+ }),
739
+ get_object_events: (0, ai_1.tool)({
740
+ description: 'Returns recent events for a specific Kubernetes object (by namespace and name): its lifecycle changes and related kube Events (via involvedObject).',
741
+ inputSchema: zod_1.z.object({
742
+ namespace: zod_1.z.string().describe('Namespace of the object'),
743
+ name: zod_1.z.string().describe('Name of the object')
744
+ }),
745
+ execute: async ({ namespace, name }) => {
746
+ var _a;
747
+ ctx().trace('get_object_events', { namespace, name });
748
+ const evs = ((_a = ctx().clusterEvents) !== null && _a !== void 0 ? _a : []).filter(e => {
749
+ var _a, _b, _c, _d, _e;
750
+ const o = (_a = e === null || e === void 0 ? void 0 : e.obj) !== null && _a !== void 0 ? _a : {};
751
+ const isObj = ((_b = o.metadata) === null || _b === void 0 ? void 0 : _b.namespace) === namespace && ((_c = o.metadata) === null || _c === void 0 ? void 0 : _c.name) === name;
752
+ const isInvolved = ((_d = o.involvedObject) === null || _d === void 0 ? void 0 : _d.namespace) === namespace && ((_e = o.involvedObject) === null || _e === void 0 ? void 0 : _e.name) === name;
753
+ return isObj || isInvolved;
754
+ });
755
+ return { count: evs.length, events: evs.map(summarizeClusterEvent) };
756
+ }
757
+ }),
697
758
  };
698
759
  exports.toolInfoList = [
699
760
  { name: 'list_namespaces', effect: EToolEffect.READ, description: 'Lists all namespaces in the cluster with their status and labels.' },
@@ -721,6 +782,8 @@ exports.toolInfoList = [
721
782
  { name: 'times_two', effect: EToolEffect.READ, description: 'Multiplies a number by two.' },
722
783
  { name: 'father_of', effect: EToolEffect.READ, description: 'Returns the name of the father of a person.' },
723
784
  { name: 'get_certificate_info', effect: 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.' },
785
+ { name: 'get_cluster_events', effect: EToolEffect.READ, description: 'Returns recent buffered Kubernetes events for this cluster (warnings + object lifecycle changes); filter by warnings only or namespace.' },
786
+ { name: 'get_object_events', effect: EToolEffect.READ, description: 'Returns recent events for a specific Kubernetes object (namespace + name), including related kube Events.' },
724
787
  ];
725
788
  // Resolves the tool names an agent may use: autoTools = full catalog, otherwise its own list
726
789
  // (intersected with the catalog); readOnly filters out WRITE-effect tools. Pure (no LLM) → unit-testable.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwirthmagnify/kwirth-common-ai",
3
- "version": "0.5.24",
3
+ "version": "0.5.25",
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",