@kwirthmagnify/kwirth-common-ai 0.5.56 → 0.5.58

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
@@ -1,4 +1,4 @@
1
- import { ILlm, ILlmProvider, IAgent, ECapability, EToolEffect, IAiToolInfo, IAiToolsetInfo, IToolsetConfig } from './index';
1
+ import { ILlm, ILlmProvider, IAgent, ECapability, EToolEffect, EToolSensitivity, IAiToolInfo, IAiToolsetInfo, IToolsetConfig } from './index';
2
2
  import type { AppsV1Api, CoreV1Api, NetworkingV1Api } from '@kubernetes/client-node';
3
3
  interface ILogChannel {
4
4
  logInfo?: (msg: string) => void;
@@ -74,10 +74,53 @@ export interface IK8sCapability {
74
74
  appsApi: AppsV1Api;
75
75
  networkApi: NetworkingV1Api;
76
76
  }
77
+ export interface IMetricsPodSample {
78
+ podRef?: {
79
+ name?: string;
80
+ namespace?: string;
81
+ };
82
+ cpu?: {
83
+ usageNanoCores?: number;
84
+ };
85
+ memory?: {
86
+ workingSetBytes?: number;
87
+ };
88
+ }
89
+ export interface IMetricsNodeSample {
90
+ name?: string;
91
+ timestamp?: number;
92
+ summary?: {
93
+ cpu?: {
94
+ usageNanoCores?: number;
95
+ };
96
+ memory?: {
97
+ workingSetBytes?: number;
98
+ };
99
+ network?: {
100
+ rxBytes?: number;
101
+ txBytes?: number;
102
+ };
103
+ pods?: IMetricsPodSample[];
104
+ };
105
+ }
106
+ export interface IMetricsSample {
107
+ /** Segundos entre lecturas. Sin esto, una serie de numeros no dice a que ritmo pasa el tiempo. */
108
+ metricsInterval?: number;
109
+ cluster: {
110
+ vcpus: number;
111
+ memory: number;
112
+ /** Porcentajes, 0-100. */
113
+ cpuUsage: number;
114
+ memoryUsage: number;
115
+ txmbps: number;
116
+ rxmbps: number;
117
+ };
118
+ nodes: IMetricsNodeSample[];
119
+ }
77
120
  /** Metricas del cluster (`ECapability.METRICS`). */
78
121
  export interface IMetricsCapability {
79
- /** Muestras de metricas que el core mantiene en memoria. */
80
- samples: unknown[];
122
+ /** Muestras que el core mantiene en memoria. La mas reciente, al final. */
123
+ samples: IMetricsSample[];
81
124
  }
82
125
  /**
83
126
  * Un elemento del buffer de eventos del core: el tipo de cambio y el objeto tal y como vino de la API.
@@ -119,6 +162,24 @@ export interface IAiTool extends IAiToolInfo {
119
162
  export interface IAiToolset extends Omit<IAiToolsetInfo, 'tools'> {
120
163
  tools: IAiTool[];
121
164
  }
165
+ /**
166
+ * Declara una tool infiriendo el tipo de sus argumentos DESDE su propio `inputSchema`.
167
+ *
168
+ * Sin esto, `execute` recibe `Record<string, unknown>` y cada tool acaba llena de `String(args.namespace)`
169
+ * y castings sueltos: treinta tools asi son treinta sitios donde equivocarse en silencio, y el compilador
170
+ * no puede ayudar. Con esto, el esquema es la unica fuente de verdad y `args` viene tipado.
171
+ *
172
+ * El registro sigue guardando el tipo suelto (`IAiTool`): quien lo invoca no conoce el esquema, y ahi la
173
+ * comprobacion la hace zod en tiempo de ejecucion, como debe ser.
174
+ */
175
+ export declare const defineTool: <S extends z.ZodTypeAny>(definition: {
176
+ name: string;
177
+ description: string;
178
+ effect: EToolEffect;
179
+ sensitivity: EToolSensitivity;
180
+ inputSchema: S;
181
+ execute: (args: z.infer<S>, host: IToolHost) => Promise<unknown>;
182
+ }) => IAiTool;
122
183
  export declare const isBuiltInToolsetId: (id: string) => boolean;
123
184
  /**
124
185
  * Registra un toolset. `builtIn` solo lo usa el core para los suyos: marca el id como reservado.
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.buildAgentTools = exports.resolveTools = exports.resolveToolRef = exports.invokeToolRef = exports.buildToolHost = 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;
36
+ exports.runAgent = exports.selectAgentToolNames = exports.toolInfoList = exports.tools = exports.buildAgentTools = exports.resolveTools = exports.resolveToolRef = exports.invokeToolRef = exports.buildToolHost = exports.listToolsetInfos = exports.listToolsets = exports.getToolset = exports.unregisterToolset = exports.registerToolset = exports.isBuiltInToolsetId = exports.defineTool = 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 index_1 = require("./index");
38
38
  const ai_1 = require("ai");
39
39
  const zod_1 = require("zod");
@@ -388,6 +388,18 @@ const configRefsOfPodSpec = (spec) => {
388
388
  }
389
389
  return refs;
390
390
  };
391
+ /**
392
+ * Declara una tool infiriendo el tipo de sus argumentos DESDE su propio `inputSchema`.
393
+ *
394
+ * Sin esto, `execute` recibe `Record<string, unknown>` y cada tool acaba llena de `String(args.namespace)`
395
+ * y castings sueltos: treinta tools asi son treinta sitios donde equivocarse en silencio, y el compilador
396
+ * no puede ayudar. Con esto, el esquema es la unica fuente de verdad y `args` viene tipado.
397
+ *
398
+ * El registro sigue guardando el tipo suelto (`IAiTool`): quien lo invoca no conoce el esquema, y ahi la
399
+ * comprobacion la hace zod en tiempo de ejecucion, como debe ser.
400
+ */
401
+ const defineTool = (definition) => definition;
402
+ exports.defineTool = defineTool;
391
403
  const toolsetRegistry = new Map();
392
404
  // Los ids de los toolsets built-in del core estan RESERVADOS: un `aitoolset` de un tercero no puede
393
405
  // ocuparlos. Sin esta regla, instalar un toolset ajeno llamado 'k8s-inventory' obligaria a renombrar el
@@ -457,7 +469,7 @@ const buildToolHost = (requires, context) => {
457
469
  };
458
470
  }
459
471
  if (requires.includes(index_1.ECapability.METRICS))
460
- host.metrics = { samples: (_a = context.clusterMetrics) !== null && _a !== void 0 ? _a : [] };
472
+ host.metrics = { samples: ((_a = context.clusterMetrics) !== null && _a !== void 0 ? _a : []) };
461
473
  if (requires.includes(index_1.ECapability.EVENTS))
462
474
  host.events = { recent: ((_b = context.clusterEvents) !== null && _b !== void 0 ? _b : []) };
463
475
  if (requires.includes(index_1.ECapability.REPOS))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwirthmagnify/kwirth-common-ai",
3
- "version": "0.5.56",
3
+ "version": "0.5.58",
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",