@kraken-ai/platform 0.0.1 → 0.0.2
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/{chunk-HGJSK6MW.js → chunk-PPT6GGYL.js} +99 -2
- package/dist/chunk-PPT6GGYL.js.map +1 -0
- package/dist/cli.js +47 -19
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +3 -449
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -369
- package/dist/index.d.ts +14 -369
- package/dist/index.js +92 -611
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +498 -6
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +19 -2
- package/dist/server.d.ts +19 -2
- package/dist/server.js +451 -2
- package/dist/server.js.map +1 -1
- package/dist/types-CkknNKNr.d.cts +451 -0
- package/dist/types-CkknNKNr.d.ts +451 -0
- package/package.json +12 -12
- package/dist/chunk-HGJSK6MW.js.map +0 -1
- package/dist/connector-CumEDPfS.d.cts +0 -103
- package/dist/connector-CumEDPfS.d.ts +0 -103
package/dist/server.cjs
CHANGED
|
@@ -30,6 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/server.ts
|
|
31
31
|
var server_exports = {};
|
|
32
32
|
__export(server_exports, {
|
|
33
|
+
MockToolSet: () => MockToolSet,
|
|
34
|
+
runDev: () => runDev,
|
|
33
35
|
startConnectorServer: () => startConnectorServer
|
|
34
36
|
});
|
|
35
37
|
module.exports = __toCommonJS(server_exports);
|
|
@@ -104,7 +106,7 @@ var withTimeout = (promise, ms) => Promise.race([
|
|
|
104
106
|
(_, reject) => setTimeout(() => reject(new Error(`Handler timed out after ${ms}ms`)), ms)
|
|
105
107
|
)
|
|
106
108
|
]);
|
|
107
|
-
var readBody = (req, maxSize) => new Promise((
|
|
109
|
+
var readBody = (req, maxSize) => new Promise((resolve2, reject) => {
|
|
108
110
|
const chunks = [];
|
|
109
111
|
let size = 0;
|
|
110
112
|
req.on("data", (chunk) => {
|
|
@@ -116,7 +118,7 @@ var readBody = (req, maxSize) => new Promise((resolve, reject) => {
|
|
|
116
118
|
}
|
|
117
119
|
chunks.push(chunk);
|
|
118
120
|
});
|
|
119
|
-
req.on("end", () =>
|
|
121
|
+
req.on("end", () => resolve2(Buffer.concat(chunks).toString()));
|
|
120
122
|
req.on("error", reject);
|
|
121
123
|
});
|
|
122
124
|
var buildPromptArgsSchema = (def) => {
|
|
@@ -291,8 +293,8 @@ var startConnectorServer = async (connector, options) => {
|
|
|
291
293
|
res.end("Not found");
|
|
292
294
|
});
|
|
293
295
|
await mcpServer.connect(transport);
|
|
294
|
-
await new Promise((
|
|
295
|
-
httpServer.listen(port, host, () =>
|
|
296
|
+
await new Promise((resolve2) => {
|
|
297
|
+
httpServer.listen(port, host, () => resolve2());
|
|
296
298
|
});
|
|
297
299
|
const addr = httpServer.address();
|
|
298
300
|
if (!addr || typeof addr === "string") {
|
|
@@ -302,14 +304,504 @@ var startConnectorServer = async (connector, options) => {
|
|
|
302
304
|
port: addr.port,
|
|
303
305
|
close: async () => {
|
|
304
306
|
await mcpServer.close();
|
|
305
|
-
await new Promise((
|
|
306
|
-
httpServer.close((err) => err ? reject(err) :
|
|
307
|
+
await new Promise((resolve2, reject) => {
|
|
308
|
+
httpServer.close((err) => err ? reject(err) : resolve2());
|
|
307
309
|
});
|
|
308
310
|
}
|
|
309
311
|
};
|
|
310
312
|
};
|
|
313
|
+
|
|
314
|
+
// src/dev.ts
|
|
315
|
+
var import_node_fs = require("fs");
|
|
316
|
+
var import_node_readline = require("readline");
|
|
317
|
+
var import_kraken_ai2 = require("kraken-ai");
|
|
318
|
+
|
|
319
|
+
// src/agents/define-actions.ts
|
|
320
|
+
var z3 = __toESM(require("zod"), 1);
|
|
321
|
+
|
|
322
|
+
// src/agents/types/action.ts
|
|
323
|
+
var z2 = __toESM(require("zod"), 1);
|
|
324
|
+
var actionVariantConfigSchema = z2.object({
|
|
325
|
+
schema: z2.record(z2.string(), z2.unknown()),
|
|
326
|
+
webhook: z2.string().url().optional(),
|
|
327
|
+
hasHandler: z2.boolean()
|
|
328
|
+
});
|
|
329
|
+
var actionsConfigSchema = z2.object({
|
|
330
|
+
variants: z2.record(z2.string(), actionVariantConfigSchema)
|
|
331
|
+
}).strict();
|
|
332
|
+
|
|
333
|
+
// src/agents/define-actions.ts
|
|
334
|
+
var buildActionOutputSchema = (actions) => {
|
|
335
|
+
const entries = Object.entries(actions.zodSchemas);
|
|
336
|
+
if (entries.length === 0) {
|
|
337
|
+
throw new Error("Cannot build output schema from empty action definitions");
|
|
338
|
+
}
|
|
339
|
+
const variants = entries.map(
|
|
340
|
+
([name, schema]) => z3.object({ action: z3.literal(name) }).extend(schema.shape)
|
|
341
|
+
);
|
|
342
|
+
const [first, ...rest] = variants;
|
|
343
|
+
if (!first) {
|
|
344
|
+
throw new Error("Cannot build output schema from empty action definitions");
|
|
345
|
+
}
|
|
346
|
+
return z3.discriminatedUnion("action", [first, ...rest]);
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// src/cli/log.ts
|
|
350
|
+
var supportsColor = !("NO_COLOR" in process.env) && process.env.FORCE_COLOR !== "0" && (process.stderr.isTTY ?? false);
|
|
351
|
+
var code = (open, close) => {
|
|
352
|
+
const openStr = `\x1B[${open}m`;
|
|
353
|
+
const closeStr = `\x1B[${close}m`;
|
|
354
|
+
return (s) => supportsColor ? `${openStr}${s}${closeStr}` : s;
|
|
355
|
+
};
|
|
356
|
+
var bold = code(1, 22);
|
|
357
|
+
var dim = code(2, 22);
|
|
358
|
+
var red = code(31, 39);
|
|
359
|
+
var yellow = code(33, 39);
|
|
360
|
+
var green = code(32, 39);
|
|
361
|
+
var cyan = code(36, 39);
|
|
362
|
+
|
|
363
|
+
// src/dev-actions.ts
|
|
364
|
+
var buildActionInstructions = (zodSchemas) => {
|
|
365
|
+
const entries = Object.entries(zodSchemas);
|
|
366
|
+
if (entries.length === 0) return "";
|
|
367
|
+
const variants = entries.map(([name, schema]) => {
|
|
368
|
+
const fields = Object.keys(schema.shape).join(", ");
|
|
369
|
+
return ` - "${name}": { ${fields} }`;
|
|
370
|
+
});
|
|
371
|
+
return [
|
|
372
|
+
'You MUST respond with a JSON object containing an "action" field set to one of the following action names, plus the fields for that action:',
|
|
373
|
+
"",
|
|
374
|
+
...variants,
|
|
375
|
+
"",
|
|
376
|
+
'Example: { "action": "<name>", ...fields }'
|
|
377
|
+
].join("\n");
|
|
378
|
+
};
|
|
379
|
+
var dispatchDevAction = async (output, zodSchemas, handlers, webhooks) => {
|
|
380
|
+
if (output == null || typeof output !== "object" || !("action" in output)) {
|
|
381
|
+
throw new Error('Action output must contain an "action" field');
|
|
382
|
+
}
|
|
383
|
+
const { action: actionName, ...rest } = output;
|
|
384
|
+
if (typeof actionName !== "string") {
|
|
385
|
+
throw new Error('Action output "action" field must be a string');
|
|
386
|
+
}
|
|
387
|
+
const schema = zodSchemas[actionName];
|
|
388
|
+
if (!schema) {
|
|
389
|
+
throw new Error(
|
|
390
|
+
`Unknown action "${actionName}". Expected one of: ${Object.keys(zodSchemas).join(", ")}`
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
const parsed = schema.parse(rest);
|
|
394
|
+
const payload = parsed;
|
|
395
|
+
let handlerCalled = false;
|
|
396
|
+
const handler = handlers?.[actionName];
|
|
397
|
+
if (handler) {
|
|
398
|
+
await handler(payload);
|
|
399
|
+
handlerCalled = true;
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
actionName,
|
|
403
|
+
payload,
|
|
404
|
+
handlerCalled,
|
|
405
|
+
webhookUrl: webhooks[actionName]
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// src/dev-connectors.ts
|
|
410
|
+
var import_node_path = require("path");
|
|
411
|
+
var import_kraken_ai = require("kraken-ai");
|
|
412
|
+
|
|
413
|
+
// src/cli/validate.ts
|
|
414
|
+
var ENTITY_NAME_REGEX = /^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$/;
|
|
415
|
+
var isValidEntityName = (name) => name.length === 1 ? /^[a-z0-9]$/.test(name) : ENTITY_NAME_REGEX.test(name);
|
|
416
|
+
|
|
417
|
+
// src/dev-connectors.ts
|
|
418
|
+
var isPlatformConnector = (v) => v != null && typeof v === "object" && v.__type === "PlatformConnector";
|
|
419
|
+
var importConnector = async (name, projectRoot) => {
|
|
420
|
+
const basePath = (0, import_node_path.resolve)(projectRoot, "connectors", name, "index");
|
|
421
|
+
for (const ext of [".ts", ".js"]) {
|
|
422
|
+
try {
|
|
423
|
+
const mod = await import(`${basePath}${ext}`);
|
|
424
|
+
const connector = mod.default;
|
|
425
|
+
if (!isPlatformConnector(connector)) {
|
|
426
|
+
console.warn(`[connector:${name}] Default export is not a PlatformConnector \u2014 skipping`);
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
return connector;
|
|
430
|
+
} catch (err) {
|
|
431
|
+
if (ext === ".ts") continue;
|
|
432
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
433
|
+
console.warn(`[connector:${name}] Failed to import \u2014 skipping. Error: ${message}`);
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return null;
|
|
438
|
+
};
|
|
439
|
+
var createToolsFromConnector = (connector) => {
|
|
440
|
+
const tools = connector.tools ?? {};
|
|
441
|
+
return Object.entries(tools).map(
|
|
442
|
+
([name, def]) => (0, import_kraken_ai.tool)({
|
|
443
|
+
name,
|
|
444
|
+
description: def.description,
|
|
445
|
+
parameters: def.input,
|
|
446
|
+
execute: async (args) => {
|
|
447
|
+
try {
|
|
448
|
+
const result = await Promise.resolve(def.handler(args));
|
|
449
|
+
return wrapToolResult(result);
|
|
450
|
+
} catch (error) {
|
|
451
|
+
return wrapToolError(error);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
})
|
|
455
|
+
);
|
|
456
|
+
};
|
|
457
|
+
var buildConnectorTools = (connectors) => {
|
|
458
|
+
const toolOwners = /* @__PURE__ */ new Map();
|
|
459
|
+
for (const { name, connector } of connectors) {
|
|
460
|
+
for (const toolName of Object.keys(connector.tools ?? {})) {
|
|
461
|
+
const existing = toolOwners.get(toolName);
|
|
462
|
+
if (existing) {
|
|
463
|
+
throw new Error(
|
|
464
|
+
`Tool name collision: "${toolName}" is defined by both connectors "${existing}" and "${name}". Rename one of the tools or use a unique prefix.`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
toolOwners.set(toolName, name);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const resourceOwners = /* @__PURE__ */ new Map();
|
|
471
|
+
for (const { name, connector } of connectors) {
|
|
472
|
+
for (const resourceName of Object.keys(connector.resources ?? {})) {
|
|
473
|
+
const existing = resourceOwners.get(resourceName);
|
|
474
|
+
if (existing) {
|
|
475
|
+
throw new Error(
|
|
476
|
+
`Resource name collision: "${resourceName}" is defined by both connectors "${existing}" and "${name}". Rename one of the resources or use a unique prefix.`
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
resourceOwners.set(resourceName, name);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const promptOwners = /* @__PURE__ */ new Map();
|
|
483
|
+
for (const { name, connector } of connectors) {
|
|
484
|
+
for (const promptName of Object.keys(connector.prompts ?? {})) {
|
|
485
|
+
const existing = promptOwners.get(promptName);
|
|
486
|
+
if (existing) {
|
|
487
|
+
throw new Error(
|
|
488
|
+
`Prompt name collision: "${promptName}" is defined by both connectors "${existing}" and "${name}". Rename one of the prompts or use a unique prefix.`
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
promptOwners.set(promptName, name);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
const allTools = [];
|
|
495
|
+
const allResources = [];
|
|
496
|
+
const allPrompts = [];
|
|
497
|
+
const allInstructions = [];
|
|
498
|
+
for (const { name, connector } of connectors) {
|
|
499
|
+
const tools = createToolsFromConnector(connector);
|
|
500
|
+
allTools.push(...tools);
|
|
501
|
+
for (const [resName, resDef] of Object.entries(connector.resources ?? {})) {
|
|
502
|
+
allResources.push({
|
|
503
|
+
name: resName,
|
|
504
|
+
uri: resDef.uri,
|
|
505
|
+
description: resDef.description,
|
|
506
|
+
mimeType: resDef.mimeType,
|
|
507
|
+
read: (ctx) => resDef.read(ctx)
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
for (const [promptName, promptDef] of Object.entries(connector.prompts ?? {})) {
|
|
511
|
+
allPrompts.push({
|
|
512
|
+
name: promptName,
|
|
513
|
+
description: promptDef.description,
|
|
514
|
+
arguments: promptDef.arguments,
|
|
515
|
+
get: (args, ctx) => promptDef.get(args, ctx)
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
const toolCount = Object.keys(connector.tools ?? {}).length;
|
|
519
|
+
const resourceCount = Object.keys(connector.resources ?? {}).length;
|
|
520
|
+
const promptCount = Object.keys(connector.prompts ?? {}).length;
|
|
521
|
+
const parts = [
|
|
522
|
+
`${toolCount} tool${toolCount !== 1 ? "s" : ""}`,
|
|
523
|
+
`${resourceCount} resource${resourceCount !== 1 ? "s" : ""}`,
|
|
524
|
+
`${promptCount} prompt${promptCount !== 1 ? "s" : ""}`
|
|
525
|
+
];
|
|
526
|
+
console.log(` Connector: ${name} (${parts.join(", ")})`);
|
|
527
|
+
if (connector.instructions) {
|
|
528
|
+
allInstructions.push(connector.instructions);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
tools: allTools,
|
|
533
|
+
resources: allResources,
|
|
534
|
+
prompts: allPrompts,
|
|
535
|
+
instructions: allInstructions
|
|
536
|
+
};
|
|
537
|
+
};
|
|
538
|
+
var loadConnectorTools = async (connectorNames, projectRoot) => {
|
|
539
|
+
if (connectorNames.length === 0) {
|
|
540
|
+
return { tools: [], resources: [], prompts: [], instructions: [] };
|
|
541
|
+
}
|
|
542
|
+
const root = projectRoot ?? process.cwd();
|
|
543
|
+
const connectors = [];
|
|
544
|
+
for (const name of connectorNames) {
|
|
545
|
+
if (!isValidEntityName(name)) {
|
|
546
|
+
console.warn(
|
|
547
|
+
`[connector] Invalid connector name "${name}" \u2014 must match ${ENTITY_NAME_REGEX}. Skipping.`
|
|
548
|
+
);
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
const connector = await importConnector(name, root);
|
|
552
|
+
if (connector) {
|
|
553
|
+
connectors.push({ name, connector });
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return buildConnectorTools(connectors);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// src/dev.ts
|
|
560
|
+
var loadDotenv = () => {
|
|
561
|
+
try {
|
|
562
|
+
const content = (0, import_node_fs.readFileSync)(".env", "utf-8");
|
|
563
|
+
for (const line of content.split("\n")) {
|
|
564
|
+
const trimmed = line.trim();
|
|
565
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
566
|
+
const eqIdx = trimmed.indexOf("=");
|
|
567
|
+
if (eqIdx === -1) continue;
|
|
568
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
569
|
+
const value = trimmed.slice(eqIdx + 1).trim();
|
|
570
|
+
if (!process.env[key]) {
|
|
571
|
+
process.env[key] = value;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
} catch {
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
var FRONTMATTER_RE = /^---\n[\s\S]*?\n---\n([\s\S]*)$/;
|
|
578
|
+
var resolveSkillContent = (refs) => refs.map((ref) => {
|
|
579
|
+
try {
|
|
580
|
+
return (0, import_node_fs.readFileSync)(`skills/${ref}`, "utf-8");
|
|
581
|
+
} catch {
|
|
582
|
+
return ref;
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
var buildInstructions = (base, skillContent) => {
|
|
586
|
+
if (skillContent.length === 0) return base;
|
|
587
|
+
const bodies = skillContent.map((s) => {
|
|
588
|
+
const m = FRONTMATTER_RE.exec(s);
|
|
589
|
+
return m?.[1]?.trim() ?? s;
|
|
590
|
+
});
|
|
591
|
+
return `${base}
|
|
592
|
+
|
|
593
|
+
${bodies.join("\n\n")}`;
|
|
594
|
+
};
|
|
595
|
+
var buildDevAgent = async (pa) => {
|
|
596
|
+
const {
|
|
597
|
+
name,
|
|
598
|
+
model,
|
|
599
|
+
instructions,
|
|
600
|
+
skills,
|
|
601
|
+
temperature,
|
|
602
|
+
thinkingLevel,
|
|
603
|
+
maxOutputTokens,
|
|
604
|
+
logLevel
|
|
605
|
+
} = pa.config.agent;
|
|
606
|
+
const connectorNames = pa.config.connectors ?? [];
|
|
607
|
+
const { tools: connectorTools, instructions: connectorInstructions } = await loadConnectorTools(connectorNames);
|
|
608
|
+
const skillContent = resolveSkillContent(skills ?? []);
|
|
609
|
+
let fullInstructions = buildInstructions(instructions, skillContent);
|
|
610
|
+
if (connectorInstructions.length > 0) {
|
|
611
|
+
fullInstructions = `${fullInstructions}
|
|
612
|
+
|
|
613
|
+
${connectorInstructions.join("\n\n")}`;
|
|
614
|
+
}
|
|
615
|
+
let outputSchema;
|
|
616
|
+
if (pa.actionZodSchemas && Object.keys(pa.actionZodSchemas).length > 0) {
|
|
617
|
+
const actionInstructions = buildActionInstructions(pa.actionZodSchemas);
|
|
618
|
+
if (actionInstructions) {
|
|
619
|
+
fullInstructions = `${fullInstructions}
|
|
620
|
+
|
|
621
|
+
${actionInstructions}`;
|
|
622
|
+
}
|
|
623
|
+
outputSchema = buildActionOutputSchema({
|
|
624
|
+
__type: "PlatformActions",
|
|
625
|
+
config: pa.config.actions ?? { variants: {} },
|
|
626
|
+
zodSchemas: pa.actionZodSchemas,
|
|
627
|
+
handlers: pa.actionHandlers ?? {}
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
let team;
|
|
631
|
+
if (pa.teamAgents && pa.teamAgents.length > 0) {
|
|
632
|
+
team = await Promise.all(pa.teamAgents.map(buildDevAgent));
|
|
633
|
+
}
|
|
634
|
+
return new import_kraken_ai2.Agent({
|
|
635
|
+
name,
|
|
636
|
+
model,
|
|
637
|
+
instructions: fullInstructions,
|
|
638
|
+
tools: connectorTools.length > 0 ? connectorTools : void 0,
|
|
639
|
+
outputSchema,
|
|
640
|
+
team,
|
|
641
|
+
temperature,
|
|
642
|
+
thinkingLevel,
|
|
643
|
+
maxOutputTokens,
|
|
644
|
+
logLevel
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
var runDev = async (agent) => {
|
|
648
|
+
loadDotenv();
|
|
649
|
+
const hasActions = agent.actionZodSchemas && Object.keys(agent.actionZodSchemas).length > 0;
|
|
650
|
+
const sdkAgent = await buildDevAgent(agent);
|
|
651
|
+
const { name, model } = agent.config.agent;
|
|
652
|
+
const connectorNames = agent.config.connectors ?? [];
|
|
653
|
+
try {
|
|
654
|
+
await sdkAgent.preflight();
|
|
655
|
+
} catch (err) {
|
|
656
|
+
console.error(`
|
|
657
|
+
${err instanceof Error ? err.message : String(err)}
|
|
658
|
+
`);
|
|
659
|
+
process.exit(1);
|
|
660
|
+
}
|
|
661
|
+
console.log(`
|
|
662
|
+
Agent: ${name}`);
|
|
663
|
+
console.log(` Model: ${model}`);
|
|
664
|
+
if (connectorNames.length > 0) {
|
|
665
|
+
console.log(` Connectors: ${connectorNames.join(", ")}`);
|
|
666
|
+
}
|
|
667
|
+
if (agent.teamAgents && agent.teamAgents.length > 0) {
|
|
668
|
+
console.log(` Team: ${agent.teamAgents.map((a) => a.config.agent.name).join(", ")}`);
|
|
669
|
+
}
|
|
670
|
+
if (hasActions && agent.actionZodSchemas) {
|
|
671
|
+
console.log(` Actions: ${Object.keys(agent.actionZodSchemas).join(", ")}`);
|
|
672
|
+
}
|
|
673
|
+
console.log(`
|
|
674
|
+
Type a message to start. Ctrl+C to exit.
|
|
675
|
+
`);
|
|
676
|
+
const rl = (0, import_node_readline.createInterface)({ input: process.stdin, output: process.stdout });
|
|
677
|
+
const messages = [];
|
|
678
|
+
const cleanup = () => {
|
|
679
|
+
rl.close();
|
|
680
|
+
process.exit(0);
|
|
681
|
+
};
|
|
682
|
+
process.on("SIGINT", cleanup);
|
|
683
|
+
process.on("SIGTERM", cleanup);
|
|
684
|
+
const ask = () => {
|
|
685
|
+
rl.question("You: ", (input) => {
|
|
686
|
+
if (!input.trim()) {
|
|
687
|
+
ask();
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
messages.push({ role: "user", content: input });
|
|
691
|
+
void (async () => {
|
|
692
|
+
try {
|
|
693
|
+
const result = await sdkAgent.run(messages, {
|
|
694
|
+
onEvent: (event) => {
|
|
695
|
+
if (event.type === "thought") {
|
|
696
|
+
console.log(
|
|
697
|
+
` [thinking] ${event.text.slice(0, 120)}${event.text.length > 120 ? "\u2026" : ""}`
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
if (event.type === "tool_call" && event.status === "success") {
|
|
701
|
+
console.log(` [tool] ${event.toolName}`);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
if (result.status === "complete") {
|
|
706
|
+
const output = typeof result.output === "string" ? result.output : JSON.stringify(result.output, null, 2);
|
|
707
|
+
if (hasActions && agent.actionZodSchemas && result.output != null && typeof result.output === "object" && "action" in result.output) {
|
|
708
|
+
const webhooks = {};
|
|
709
|
+
if (agent.config.actions?.variants) {
|
|
710
|
+
for (const [k, v] of Object.entries(agent.config.actions.variants)) {
|
|
711
|
+
webhooks[k] = v.webhook;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
try {
|
|
715
|
+
const dispatched = await dispatchDevAction(
|
|
716
|
+
result.output,
|
|
717
|
+
agent.actionZodSchemas,
|
|
718
|
+
agent.actionHandlers,
|
|
719
|
+
webhooks
|
|
720
|
+
);
|
|
721
|
+
console.log(`
|
|
722
|
+
${cyan("Action:")} ${green(dispatched.actionName)}`);
|
|
723
|
+
console.log(` ${dim("Payload:")} ${JSON.stringify(dispatched.payload, null, 2)}`);
|
|
724
|
+
if (dispatched.handlerCalled) {
|
|
725
|
+
console.log(` ${dim("Handler:")} ${green("called")}`);
|
|
726
|
+
}
|
|
727
|
+
if (dispatched.webhookUrl) {
|
|
728
|
+
console.log(
|
|
729
|
+
` ${dim("Webhook:")} ${yellow(dispatched.webhookUrl)} ${dim("(skipped in dev)")}`
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
console.log();
|
|
733
|
+
} catch (err) {
|
|
734
|
+
console.error(
|
|
735
|
+
`
|
|
736
|
+
Action dispatch error: ${err instanceof Error ? err.message : String(err)}
|
|
737
|
+
`
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
} else {
|
|
741
|
+
console.log(`
|
|
742
|
+
Agent: ${output}
|
|
743
|
+
`);
|
|
744
|
+
}
|
|
745
|
+
messages.push({ role: "assistant", content: output });
|
|
746
|
+
} else if (result.status === "interrupted") {
|
|
747
|
+
console.log(`
|
|
748
|
+
[Interrupted: ${result.interrupt.toolName} requires approval]
|
|
749
|
+
`);
|
|
750
|
+
}
|
|
751
|
+
} catch (err) {
|
|
752
|
+
console.error(`
|
|
753
|
+
Error: ${err instanceof Error ? err.message : String(err)}
|
|
754
|
+
`);
|
|
755
|
+
}
|
|
756
|
+
ask();
|
|
757
|
+
})();
|
|
758
|
+
});
|
|
759
|
+
};
|
|
760
|
+
ask();
|
|
761
|
+
return new Promise(() => {
|
|
762
|
+
});
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
// src/mock-tool-set.ts
|
|
766
|
+
var MockToolSet = class _MockToolSet {
|
|
767
|
+
defs;
|
|
768
|
+
overrides;
|
|
769
|
+
toolNames;
|
|
770
|
+
constructor(tools, overrides = {}) {
|
|
771
|
+
this.defs = tools;
|
|
772
|
+
this.overrides = overrides;
|
|
773
|
+
this.toolNames = new Set(tools.map((t) => t.name));
|
|
774
|
+
}
|
|
775
|
+
static fromConnectors(connectors, opts) {
|
|
776
|
+
const include = opts?.include;
|
|
777
|
+
const filtered = include ? connectors.filter((c) => include.includes(c.id)) : connectors;
|
|
778
|
+
const tools = filtered.flatMap(
|
|
779
|
+
(c) => c.tools.map((t) => ({
|
|
780
|
+
name: t.name,
|
|
781
|
+
description: t.description,
|
|
782
|
+
parameters: t.parameters
|
|
783
|
+
}))
|
|
784
|
+
);
|
|
785
|
+
return new _MockToolSet(tools, opts?.overrides);
|
|
786
|
+
}
|
|
787
|
+
definitions() {
|
|
788
|
+
return this.defs;
|
|
789
|
+
}
|
|
790
|
+
async call(name, params) {
|
|
791
|
+
if (!this.toolNames.has(name)) {
|
|
792
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
793
|
+
}
|
|
794
|
+
const override = this.overrides[name];
|
|
795
|
+
if (override) {
|
|
796
|
+
return override(params);
|
|
797
|
+
}
|
|
798
|
+
return {};
|
|
799
|
+
}
|
|
800
|
+
};
|
|
311
801
|
// Annotate the CommonJS export names for ESM import in node:
|
|
312
802
|
0 && (module.exports = {
|
|
803
|
+
MockToolSet,
|
|
804
|
+
runDev,
|
|
313
805
|
startConnectorServer
|
|
314
806
|
});
|
|
315
807
|
//# sourceMappingURL=server.cjs.map
|