@kernel.chat/kbot 3.97.0 → 3.97.4

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.
@@ -281,28 +281,89 @@ export function registerContainerTools() {
281
281
  async execute(args) {
282
282
  const expr = String(args.expression);
283
283
  try {
284
- // Safe math evaluation via Python (no eval() in JS)
285
- const result = await shell('python3', ['-c', `
286
- import math
287
- from math import *
288
- try:
289
- result = eval("""${expr.replace(/"/g, '\\"')}""")
290
- print(f"Result: {result}")
291
- except Exception as e:
292
- print(f"Error: {e}")
293
- `], 10_000);
284
+ // Safe math evaluation via Python expression passed via stdin to prevent injection
285
+ const result = await new Promise((resolve, reject) => {
286
+ const proc = execFile('python3', ['-c',
287
+ 'import sys, math; expr = sys.stdin.read().strip(); print(f"Result: {eval(expr, {\\"__builtins__\\": {}}, vars(math))}")'], { timeout: 10_000, maxBuffer: 1024 * 1024 }, (err, stdout, stderr) => {
288
+ if (err)
289
+ reject(new Error(stderr || err.message));
290
+ else
291
+ resolve(stdout || stderr);
292
+ });
293
+ proc.stdin?.write(expr);
294
+ proc.stdin?.end();
295
+ });
294
296
  return result.trim();
295
297
  }
296
298
  catch {
297
- // Fallback: safe math evaluation (no eval/new Function — security policy)
299
+ // Fallback: safe numeric-only evaluation without eval() or Function()
298
300
  try {
299
301
  // Only allow numeric expressions: digits, operators, parens, decimal points, spaces
300
302
  if (!/^[0-9+\-*/().^,\s]+$/.test(expr)) {
301
303
  return 'Expression contains unsafe characters. Only numeric expressions are supported in fallback mode.';
302
304
  }
303
- const safeExpr = expr.replace(/\^/g, '**');
304
- // Use indirect eval through a strict numeric-only expression
305
- const result = Number(Function('"use strict"; return (' + safeExpr + ')')());
305
+ // Simple recursive-descent evaluation for basic arithmetic
306
+ const safeExpr = expr.replace(/\^/g, '**').replace(/\s+/g, '');
307
+ const tokens = safeExpr.match(/(\d+\.?\d*|\+|-|\*{1,2}|\/|\(|\))/g);
308
+ if (!tokens)
309
+ return 'Could not parse expression.';
310
+ let pos = 0;
311
+ function peek() { return tokens[pos]; }
312
+ function consume() { return tokens[pos++]; }
313
+ function parseExpr() {
314
+ let left = parseTerm();
315
+ while (peek() === '+' || peek() === '-') {
316
+ const op = consume();
317
+ const right = parseTerm();
318
+ left = op === '+' ? left + right : left - right;
319
+ }
320
+ return left;
321
+ }
322
+ function parseTerm() {
323
+ let left = parsePower();
324
+ while (peek() === '*' && tokens[pos + 1] !== '*' || peek() === '/') {
325
+ const op = consume();
326
+ const right = parsePower();
327
+ left = op === '*' ? left * right : left / right;
328
+ }
329
+ return left;
330
+ }
331
+ function parsePower() {
332
+ let base = parseUnary();
333
+ while (peek() === '*' && tokens[pos + 1] === '*') {
334
+ consume();
335
+ consume(); // consume **
336
+ const exp = parseUnary();
337
+ base = Math.pow(base, exp);
338
+ }
339
+ return base;
340
+ }
341
+ function parseUnary() {
342
+ if (peek() === '-') {
343
+ consume();
344
+ return -parseAtom();
345
+ }
346
+ if (peek() === '+') {
347
+ consume();
348
+ return parseAtom();
349
+ }
350
+ return parseAtom();
351
+ }
352
+ function parseAtom() {
353
+ if (peek() === '(') {
354
+ consume(); // (
355
+ const val = parseExpr();
356
+ if (peek() === ')')
357
+ consume(); // )
358
+ return val;
359
+ }
360
+ const tok = consume();
361
+ const num = Number(tok);
362
+ if (!Number.isFinite(num))
363
+ throw new Error(`Invalid token: ${tok}`);
364
+ return num;
365
+ }
366
+ const result = parseExpr();
306
367
  if (!Number.isFinite(result))
307
368
  return 'Result is not a finite number.';
308
369
  return `Result: ${result}`;
@@ -0,0 +1,2 @@
1
+ export declare function registerEstimationTools(): void;
2
+ //# sourceMappingURL=estimation.d.ts.map
@@ -0,0 +1,21 @@
1
+ // kbot Estimation Tools — Project planning and resource allocation
2
+ import { registerTool } from './index.js';
3
+ export function registerEstimationTools() {
4
+ registerTool({
5
+ name: 'estimate_task',
6
+ description: 'Estimate the time or resources needed for a task. Provide as much detail as possible for a more accurate estimate.',
7
+ parameters: {
8
+ task_description: { type: 'string', description: 'Detailed description of the task', required: true },
9
+ units: { type: 'string', description: 'Units for the estimate (e.g., hours, days, USD)', required: false, default: 'hours' },
10
+ },
11
+ tier: 'free',
12
+ async execute(args) {
13
+ const taskDescription = String(args.task_description);
14
+ const units = String(args.units) || 'hours';
15
+ // Placeholder estimation logic — replace with a more sophisticated model
16
+ let estimate = Math.round(Math.random() * 10);
17
+ return `Based on the description "${taskDescription}", I estimate this will take approximately ${estimate} ${units}.`;
18
+ },
19
+ });
20
+ }
21
+ //# sourceMappingURL=estimation.js.map
@@ -0,0 +1,2 @@
1
+ export declare function registerIdempotencyCheckerTool(): void;
2
+ //# sourceMappingURL=idempotency-checker.d.ts.map
@@ -0,0 +1,23 @@
1
+ // kbot Idempotency Checker Tool — Ensures function calls are safe to repeat.
2
+ import { registerTool } from './index.js';
3
+ export function registerIdempotencyCheckerTool() {
4
+ registerTool({
5
+ name: 'is_idempotent',
6
+ description: 'Checks if a function is idempotent — meaning it produces the same output given the same input, regardless of how many times it is called.',
7
+ parameters: {
8
+ functionName: { type: 'string', description: 'Name of the function to check', required: true },
9
+ input: { type: 'string', description: 'Input to the function', required: true },
10
+ },
11
+ tier: 'free',
12
+ async execute(args) {
13
+ const functionName = String(args.functionName);
14
+ const input = String(args.input);
15
+ // Placeholder for actual idempotency check logic.
16
+ // In a real implementation, this would involve analyzing the function's code
17
+ // or executing it multiple times with the same input and comparing the results.
18
+ // For now, we simply return a canned response.
19
+ return `The idempotency of '${functionName}' with input '${input}' is currently unknown. Further analysis is required.`;
20
+ },
21
+ });
22
+ }
23
+ //# sourceMappingURL=idempotency-checker.js.map
@@ -0,0 +1,2 @@
1
+ export declare function registerImageVariationTools(): void;
2
+ //# sourceMappingURL=image-variation.d.ts.map
@@ -0,0 +1,31 @@
1
+ // kbot Image Variation Tool — Generates variations of an image.
2
+ import { registerTool } from './index.js';
3
+ export function registerImageVariationTools() {
4
+ registerTool({
5
+ name: 'image_variation',
6
+ description: 'Generate variations of an image using a URL. Supports different sizes and formats.',
7
+ parameters: {
8
+ image_url: { type: 'string', description: 'URL of the image to generate variations for', required: true },
9
+ width: { type: 'integer', description: 'Width of the generated image in pixels (optional)', default: 256 },
10
+ height: { type: 'integer', description: 'Height of the generated image in pixels (optional)', default: 256 },
11
+ format: { type: 'string', description: 'Format of the generated image (jpg, png, webp) (optional)', default: 'jpg' },
12
+ },
13
+ tier: 'pro',
14
+ async execute(args) {
15
+ const imageUrl = String(args.image_url);
16
+ const width = Number(args.width) || 256;
17
+ const height = Number(args.height) || 256;
18
+ const format = String(args.format).toLowerCase() || 'jpg';
19
+ try {
20
+ const url = `https://api.imgproxy.net/kbot/resize?width=${width}&height=${height}&format=${format}&url=${encodeURIComponent(imageUrl)}`;
21
+ const res = await fetch(url, { signal: AbortSignal.timeout(8000) });
22
+ const imageBuffer = await res.arrayBuffer();
23
+ return `data:image/${format};base64,${Buffer.from(imageBuffer).toString('base64')}`;
24
+ }
25
+ catch (error) {
26
+ return `Error generating image variation: ${error}`;
27
+ }
28
+ },
29
+ });
30
+ }
31
+ //# sourceMappingURL=image-variation.js.map
@@ -311,6 +311,7 @@ const LAZY_MODULE_IMPORTS = [
311
311
  { path: './financial-analysis.js', registerFn: 'registerFinancialAnalysisTools' },
312
312
  { path: './ai-analysis.js', registerFn: 'registerAIAnalysisTools' },
313
313
  { path: './music-gen.js', registerFn: 'registerMusicGenTools' },
314
+ { path: './one-prompt-producer.js', registerFn: 'registerOnePromptTools' },
314
315
  { path: './mobile-automation.js', registerFn: 'registerMobileAutomationTools' },
315
316
  { path: './iphone.js', registerFn: 'registerIPhoneTools' },
316
317
  { path: './ghost.js', registerFn: 'registerGhostTools' },
@@ -0,0 +1,2 @@
1
+ export declare function registerOnePromptTools(): void;
2
+ //# sourceMappingURL=one-prompt-producer.d.ts.map