@kernel.chat/kbot 3.71.0 → 3.72.0

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/serve.d.ts CHANGED
@@ -2,6 +2,9 @@ interface ServeOptions {
2
2
  port: number;
3
3
  token?: string;
4
4
  computerUse?: boolean;
5
+ https?: boolean;
6
+ cert?: string;
7
+ key?: string;
5
8
  }
6
9
  export declare function startServe(options: ServeOptions): Promise<void>;
7
10
  export {};
package/dist/serve.js CHANGED
@@ -1,9 +1,11 @@
1
- // kbot Serve — HTTP server that exposes all tools over REST
1
+ // kbot Serve — HTTP/HTTPS server that exposes all tools over REST
2
2
  //
3
3
  // Usage:
4
4
  // kbot serve # Start on default port 7437
5
5
  // kbot serve --port 3000 # Custom port
6
6
  // kbot serve --token mysecret # Require auth token
7
+ // kbot serve --https # HTTPS with auto-generated self-signed cert
8
+ // kbot serve --cert x.pem --key x.key # HTTPS with custom cert
7
9
  //
8
10
  // Endpoints:
9
11
  // GET /health — Health check
@@ -13,6 +15,7 @@
13
15
  // POST /stream — SSE streaming agent execution
14
16
  // GET /metrics — Tool execution metrics
15
17
  import { createServer } from 'node:http';
18
+ import { createServer as createHttpsServer } from 'node:https';
16
19
  import { createRequire } from 'node:module';
17
20
  import { registerAllTools, getAllTools, executeTool, getToolDefinitionsForApi, getToolMetrics } from './tools/index.js';
18
21
  import { extractMcpAppFromText, renderMcpApp, listAppCapableTools } from './mcp-apps.js';
@@ -22,6 +25,10 @@ import { runAgent } from './agent.js';
22
25
  import { destroySession } from './memory.js';
23
26
  import { randomUUID } from 'node:crypto';
24
27
  import { mountA2ARoutes } from './a2a.js';
28
+ import { execSync } from 'node:child_process';
29
+ import { existsSync, readFileSync, mkdirSync } from 'node:fs';
30
+ import { join } from 'node:path';
31
+ import { homedir } from 'node:os';
25
32
  const __require = createRequire(import.meta.url);
26
33
  const VERSION = __require('../package.json').version;
27
34
  function cors(res) {
@@ -42,13 +49,42 @@ function readBody(req) {
42
49
  req.on('error', reject);
43
50
  });
44
51
  }
52
+ /** Generate or load a self-signed TLS certificate for localhost */
53
+ function ensureSelfSignedCert() {
54
+ const certDir = join(homedir(), '.kbot', 'certs');
55
+ const certPath = join(certDir, 'localhost.crt');
56
+ const keyPath = join(certDir, 'localhost.key');
57
+ if (existsSync(certPath) && existsSync(keyPath)) {
58
+ return { cert: readFileSync(certPath, 'utf-8'), key: readFileSync(keyPath, 'utf-8') };
59
+ }
60
+ mkdirSync(certDir, { recursive: true });
61
+ printInfo('Generating self-signed TLS certificate for localhost...');
62
+ execSync(`openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 ` +
63
+ `-nodes -days 365 -subj "/CN=localhost" ` +
64
+ `-addext "subjectAltName=DNS:localhost,IP:127.0.0.1" ` +
65
+ `-keyout "${keyPath}" -out "${certPath}"`, { stdio: 'pipe' });
66
+ printSuccess('Certificate generated at ~/.kbot/certs/');
67
+ return { cert: readFileSync(certPath, 'utf-8'), key: readFileSync(keyPath, 'utf-8') };
68
+ }
45
69
  export async function startServe(options) {
46
70
  // Register all tools before starting
47
71
  printInfo('Registering tools...');
48
72
  await registerAllTools({ computerUse: options.computerUse });
49
73
  const tools = getAllTools();
50
74
  printSuccess(`${tools.length} tools registered`);
51
- const server = createServer(async (req, res) => {
75
+ // Determine TLS config
76
+ const useTls = !!(options.https || options.cert || options.key);
77
+ let tlsOpts;
78
+ if (useTls) {
79
+ if (options.cert && options.key) {
80
+ tlsOpts = { cert: readFileSync(options.cert, 'utf-8'), key: readFileSync(options.key, 'utf-8') };
81
+ }
82
+ else {
83
+ tlsOpts = ensureSelfSignedCert();
84
+ }
85
+ }
86
+ const protocol = useTls ? 'https' : 'http';
87
+ const handler = async (req, res) => {
52
88
  // CORS preflight
53
89
  if (req.method === 'OPTIONS') {
54
90
  cors(res);
@@ -66,7 +102,7 @@ export async function startServe(options) {
66
102
  return;
67
103
  }
68
104
  }
69
- const url = new URL(req.url || '/', `http://localhost:${options.port}`);
105
+ const url = new URL(req.url || '/', `${protocol}://localhost:${options.port}`);
70
106
  const path = url.pathname;
71
107
  try {
72
108
  // GET /health
@@ -218,15 +254,23 @@ export async function startServe(options) {
218
254
  catch (err) {
219
255
  json(res, 500, { error: err instanceof Error ? err.message : 'Internal error' });
220
256
  }
221
- });
257
+ };
258
+ const server = useTls
259
+ ? createHttpsServer(tlsOpts, handler)
260
+ : createServer(handler);
222
261
  // Mount A2A protocol routes (Agent Card + task endpoints)
262
+ // Cast needed: https.Server and http.Server share the same request event API
223
263
  mountA2ARoutes(server, {
224
264
  port: options.port,
225
- endpointUrl: `http://localhost:${options.port}`,
265
+ endpointUrl: `${protocol}://localhost:${options.port}`,
226
266
  token: options.token,
227
267
  });
268
+ const baseUrl = `${protocol}://localhost:${options.port}`;
228
269
  server.listen(options.port, () => {
229
- printSuccess(`kbot serve running on http://localhost:${options.port}`);
270
+ printSuccess(`kbot serve running on ${baseUrl}`);
271
+ if (useTls) {
272
+ printInfo(' TLS: self-signed cert (browsers will warn — safe for local connectors)');
273
+ }
230
274
  printInfo(` GET /health — Health check`);
231
275
  printInfo(` GET /tools — List ${tools.length} tools`);
232
276
  printInfo(` POST /execute — Execute a tool`);
@@ -243,7 +287,7 @@ export async function startServe(options) {
243
287
  }
244
288
  printInfo('');
245
289
  printInfo('Connect from kernel.chat:');
246
- printInfo(` connectKbot('http://localhost:${options.port}')`);
290
+ printInfo(` connectKbot('${baseUrl}')`);
247
291
  });
248
292
  // Graceful shutdown
249
293
  const shutdown = () => {
@@ -311,6 +311,8 @@ 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: './mobile-automation.js', registerFn: 'registerMobileAutomationTools' },
315
+ { path: './iphone.js', registerFn: 'registerIPhoneTools' },
314
316
  ];
315
317
  /** Track whether lazy tools have been registered */
316
318
  let lazyToolsRegistered = false;
@@ -0,0 +1,2 @@
1
+ export declare function registerIPhoneTools(): void;
2
+ //# sourceMappingURL=iphone.d.ts.map