@inkeep/agents-run-api 0.0.0-dev-20251008200151 → 0.0.0-dev-20251009000750
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/LocalSandboxExecutor-JI4X2Z3N.js +319 -0
- package/dist/index.cjs +557 -135
- package/dist/index.js +118 -21
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var agentsCore = require('@inkeep/agents-core');
|
|
6
6
|
var z6 = require('zod');
|
|
7
7
|
var nanoid = require('nanoid');
|
|
8
|
+
var child_process = require('child_process');
|
|
9
|
+
var crypto = require('crypto');
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
var os = require('os');
|
|
12
|
+
var path = require('path');
|
|
8
13
|
var otel = require('@hono/otel');
|
|
9
14
|
var zodOpenapi = require('@hono/zod-openapi');
|
|
10
15
|
var api = require('@opentelemetry/api');
|
|
@@ -347,8 +352,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
347
352
|
});
|
|
348
353
|
referenceArtifacts.push(...artifacts);
|
|
349
354
|
}
|
|
350
|
-
const
|
|
351
|
-
|
|
355
|
+
const logger28 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
356
|
+
logger28.debug(
|
|
352
357
|
{
|
|
353
358
|
conversationId,
|
|
354
359
|
visibleMessages: visibleMessages.length,
|
|
@@ -360,8 +365,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
360
365
|
);
|
|
361
366
|
return referenceArtifacts;
|
|
362
367
|
} catch (error) {
|
|
363
|
-
const
|
|
364
|
-
|
|
368
|
+
const logger28 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
369
|
+
logger28.error(
|
|
365
370
|
{
|
|
366
371
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
367
372
|
conversationId
|
|
@@ -377,6 +382,326 @@ var init_conversations = __esm({
|
|
|
377
382
|
}
|
|
378
383
|
});
|
|
379
384
|
|
|
385
|
+
// src/tools/LocalSandboxExecutor.ts
|
|
386
|
+
var LocalSandboxExecutor_exports = {};
|
|
387
|
+
__export(LocalSandboxExecutor_exports, {
|
|
388
|
+
LocalSandboxExecutor: () => LocalSandboxExecutor
|
|
389
|
+
});
|
|
390
|
+
var logger18, _LocalSandboxExecutor, LocalSandboxExecutor;
|
|
391
|
+
var init_LocalSandboxExecutor = __esm({
|
|
392
|
+
"src/tools/LocalSandboxExecutor.ts"() {
|
|
393
|
+
logger18 = agentsCore.getLogger("local-sandbox-executor");
|
|
394
|
+
_LocalSandboxExecutor = class _LocalSandboxExecutor {
|
|
395
|
+
constructor() {
|
|
396
|
+
__publicField(this, "tempDir");
|
|
397
|
+
__publicField(this, "sandboxPool", {});
|
|
398
|
+
__publicField(this, "POOL_TTL", 5 * 60 * 1e3);
|
|
399
|
+
// 5 minutes
|
|
400
|
+
__publicField(this, "MAX_USE_COUNT", 50);
|
|
401
|
+
this.tempDir = path.join(os.tmpdir(), "inkeep-sandboxes");
|
|
402
|
+
this.ensureTempDir();
|
|
403
|
+
this.startPoolCleanup();
|
|
404
|
+
}
|
|
405
|
+
static getInstance() {
|
|
406
|
+
if (!_LocalSandboxExecutor.instance) {
|
|
407
|
+
_LocalSandboxExecutor.instance = new _LocalSandboxExecutor();
|
|
408
|
+
}
|
|
409
|
+
return _LocalSandboxExecutor.instance;
|
|
410
|
+
}
|
|
411
|
+
ensureTempDir() {
|
|
412
|
+
try {
|
|
413
|
+
fs.mkdirSync(this.tempDir, { recursive: true });
|
|
414
|
+
} catch {
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
generateDependencyHash(dependencies) {
|
|
418
|
+
const sortedDeps = Object.keys(dependencies).sort().map((key) => `${key}@${dependencies[key]}`).join(",");
|
|
419
|
+
return crypto.createHash("sha256").update(sortedDeps).digest("hex").substring(0, 16);
|
|
420
|
+
}
|
|
421
|
+
getCachedSandbox(dependencyHash) {
|
|
422
|
+
const poolKey = dependencyHash;
|
|
423
|
+
const sandbox = this.sandboxPool[poolKey];
|
|
424
|
+
if (sandbox && fs.existsSync(sandbox.sandboxDir)) {
|
|
425
|
+
const now = Date.now();
|
|
426
|
+
if (now - sandbox.lastUsed < this.POOL_TTL && sandbox.useCount < this.MAX_USE_COUNT) {
|
|
427
|
+
sandbox.lastUsed = now;
|
|
428
|
+
sandbox.useCount++;
|
|
429
|
+
logger18.debug(
|
|
430
|
+
{
|
|
431
|
+
poolKey,
|
|
432
|
+
useCount: sandbox.useCount,
|
|
433
|
+
sandboxDir: sandbox.sandboxDir,
|
|
434
|
+
lastUsed: new Date(sandbox.lastUsed).toISOString()
|
|
435
|
+
},
|
|
436
|
+
"Reusing cached sandbox"
|
|
437
|
+
);
|
|
438
|
+
return sandbox.sandboxDir;
|
|
439
|
+
} else {
|
|
440
|
+
this.cleanupSandbox(sandbox.sandboxDir);
|
|
441
|
+
delete this.sandboxPool[poolKey];
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
addToPool(dependencyHash, sandboxDir, dependencies) {
|
|
447
|
+
const poolKey = dependencyHash;
|
|
448
|
+
if (this.sandboxPool[poolKey]) {
|
|
449
|
+
this.cleanupSandbox(this.sandboxPool[poolKey].sandboxDir);
|
|
450
|
+
}
|
|
451
|
+
this.sandboxPool[poolKey] = {
|
|
452
|
+
sandboxDir,
|
|
453
|
+
lastUsed: Date.now(),
|
|
454
|
+
useCount: 1,
|
|
455
|
+
dependencies
|
|
456
|
+
};
|
|
457
|
+
logger18.debug({ poolKey, sandboxDir }, "Added sandbox to pool");
|
|
458
|
+
}
|
|
459
|
+
cleanupSandbox(sandboxDir) {
|
|
460
|
+
try {
|
|
461
|
+
fs.rmSync(sandboxDir, { recursive: true, force: true });
|
|
462
|
+
logger18.debug({ sandboxDir }, "Cleaned up sandbox");
|
|
463
|
+
} catch (error) {
|
|
464
|
+
logger18.warn({ sandboxDir, error }, "Failed to clean up sandbox");
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
startPoolCleanup() {
|
|
468
|
+
setInterval(() => {
|
|
469
|
+
const now = Date.now();
|
|
470
|
+
const keysToDelete = [];
|
|
471
|
+
for (const [key, sandbox] of Object.entries(this.sandboxPool)) {
|
|
472
|
+
if (now - sandbox.lastUsed > this.POOL_TTL || sandbox.useCount >= this.MAX_USE_COUNT) {
|
|
473
|
+
this.cleanupSandbox(sandbox.sandboxDir);
|
|
474
|
+
keysToDelete.push(key);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
keysToDelete.forEach((key) => {
|
|
478
|
+
delete this.sandboxPool[key];
|
|
479
|
+
});
|
|
480
|
+
if (keysToDelete.length > 0) {
|
|
481
|
+
logger18.debug({ cleanedCount: keysToDelete.length }, "Cleaned up expired sandboxes");
|
|
482
|
+
}
|
|
483
|
+
}, 6e4);
|
|
484
|
+
}
|
|
485
|
+
detectModuleType(executeCode) {
|
|
486
|
+
const esmPatterns = [
|
|
487
|
+
/import\s+.*\s+from\s+['"]/g,
|
|
488
|
+
// import ... from '...'
|
|
489
|
+
/import\s*\(/g,
|
|
490
|
+
// import(...)
|
|
491
|
+
/export\s+(default|const|let|var|function|class)/g,
|
|
492
|
+
// export statements
|
|
493
|
+
/export\s*\{/g
|
|
494
|
+
// export { ... }
|
|
495
|
+
];
|
|
496
|
+
const cjsPatterns = [
|
|
497
|
+
/require\s*\(/g,
|
|
498
|
+
// require(...)
|
|
499
|
+
/module\.exports/g,
|
|
500
|
+
// module.exports
|
|
501
|
+
/exports\./g
|
|
502
|
+
// exports.something
|
|
503
|
+
];
|
|
504
|
+
const hasEsmSyntax = esmPatterns.some((pattern) => pattern.test(executeCode));
|
|
505
|
+
const hasCjsSyntax = cjsPatterns.some((pattern) => pattern.test(executeCode));
|
|
506
|
+
if (hasEsmSyntax && hasCjsSyntax) {
|
|
507
|
+
logger18.warn(
|
|
508
|
+
{ executeCode: `${executeCode.substring(0, 100)}...` },
|
|
509
|
+
"Both ESM and CommonJS syntax detected, defaulting to ESM"
|
|
510
|
+
);
|
|
511
|
+
return "esm";
|
|
512
|
+
}
|
|
513
|
+
if (hasEsmSyntax) {
|
|
514
|
+
return "esm";
|
|
515
|
+
}
|
|
516
|
+
if (hasCjsSyntax) {
|
|
517
|
+
return "cjs";
|
|
518
|
+
}
|
|
519
|
+
return "cjs";
|
|
520
|
+
}
|
|
521
|
+
async executeFunctionTool(toolId, args, config) {
|
|
522
|
+
const dependencies = config.dependencies || {};
|
|
523
|
+
const dependencyHash = this.generateDependencyHash(dependencies);
|
|
524
|
+
logger18.debug(
|
|
525
|
+
{
|
|
526
|
+
toolId,
|
|
527
|
+
dependencies,
|
|
528
|
+
dependencyHash,
|
|
529
|
+
poolSize: Object.keys(this.sandboxPool).length
|
|
530
|
+
},
|
|
531
|
+
"Executing function tool"
|
|
532
|
+
);
|
|
533
|
+
let sandboxDir = this.getCachedSandbox(dependencyHash);
|
|
534
|
+
let isNewSandbox = false;
|
|
535
|
+
if (!sandboxDir) {
|
|
536
|
+
sandboxDir = path.join(this.tempDir, `sandbox-${dependencyHash}-${Date.now()}`);
|
|
537
|
+
fs.mkdirSync(sandboxDir, { recursive: true });
|
|
538
|
+
isNewSandbox = true;
|
|
539
|
+
logger18.debug(
|
|
540
|
+
{
|
|
541
|
+
toolId,
|
|
542
|
+
dependencyHash,
|
|
543
|
+
sandboxDir,
|
|
544
|
+
dependencies
|
|
545
|
+
},
|
|
546
|
+
"Creating new sandbox"
|
|
547
|
+
);
|
|
548
|
+
const moduleType = this.detectModuleType(config.executeCode);
|
|
549
|
+
const packageJson = {
|
|
550
|
+
name: `function-tool-${toolId}`,
|
|
551
|
+
version: "1.0.0",
|
|
552
|
+
...moduleType === "esm" && { type: "module" },
|
|
553
|
+
dependencies,
|
|
554
|
+
scripts: {
|
|
555
|
+
start: moduleType === "esm" ? "node index.mjs" : "node index.js"
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
fs.writeFileSync(path.join(sandboxDir, "package.json"), JSON.stringify(packageJson, null, 2), "utf8");
|
|
559
|
+
if (Object.keys(dependencies).length > 0) {
|
|
560
|
+
await this.installDependencies(sandboxDir);
|
|
561
|
+
}
|
|
562
|
+
this.addToPool(dependencyHash, sandboxDir, dependencies);
|
|
563
|
+
}
|
|
564
|
+
try {
|
|
565
|
+
const moduleType = this.detectModuleType(config.executeCode);
|
|
566
|
+
const executionCode = this.wrapFunctionCode(config.executeCode, args);
|
|
567
|
+
const fileExtension = moduleType === "esm" ? "mjs" : "js";
|
|
568
|
+
fs.writeFileSync(path.join(sandboxDir, `index.${fileExtension}`), executionCode, "utf8");
|
|
569
|
+
const result = await this.executeInSandbox(
|
|
570
|
+
sandboxDir,
|
|
571
|
+
config.sandboxConfig?.timeout || 3e4,
|
|
572
|
+
moduleType
|
|
573
|
+
);
|
|
574
|
+
return result;
|
|
575
|
+
} catch (error) {
|
|
576
|
+
if (isNewSandbox) {
|
|
577
|
+
this.cleanupSandbox(sandboxDir);
|
|
578
|
+
const poolKey = dependencyHash;
|
|
579
|
+
delete this.sandboxPool[poolKey];
|
|
580
|
+
}
|
|
581
|
+
throw error;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
async installDependencies(sandboxDir) {
|
|
585
|
+
return new Promise((resolve, reject) => {
|
|
586
|
+
const npm = child_process.spawn("npm", ["install"], {
|
|
587
|
+
cwd: sandboxDir,
|
|
588
|
+
stdio: "pipe"
|
|
589
|
+
});
|
|
590
|
+
let stderr = "";
|
|
591
|
+
npm.stdout?.on("data", () => {
|
|
592
|
+
});
|
|
593
|
+
npm.stderr?.on("data", (data) => {
|
|
594
|
+
stderr += data.toString();
|
|
595
|
+
});
|
|
596
|
+
npm.on("close", (code) => {
|
|
597
|
+
if (code === 0) {
|
|
598
|
+
logger18.debug({ sandboxDir }, "Dependencies installed successfully");
|
|
599
|
+
resolve();
|
|
600
|
+
} else {
|
|
601
|
+
logger18.error({ sandboxDir, code, stderr }, "Failed to install dependencies");
|
|
602
|
+
reject(new Error(`npm install failed with code ${code}: ${stderr}`));
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
npm.on("error", (err) => {
|
|
606
|
+
logger18.error({ sandboxDir, error: err }, "Failed to spawn npm install");
|
|
607
|
+
reject(err);
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
async executeInSandbox(sandboxDir, timeout, moduleType) {
|
|
612
|
+
return new Promise((resolve, reject) => {
|
|
613
|
+
const fileExtension = moduleType === "esm" ? "mjs" : "js";
|
|
614
|
+
const spawnOptions = {
|
|
615
|
+
cwd: sandboxDir,
|
|
616
|
+
stdio: "pipe",
|
|
617
|
+
// Security: drop privileges and limit resources
|
|
618
|
+
uid: process.getuid ? process.getuid() : void 0,
|
|
619
|
+
gid: process.getgid ? process.getgid() : void 0
|
|
620
|
+
};
|
|
621
|
+
const node = child_process.spawn("node", [`index.${fileExtension}`], spawnOptions);
|
|
622
|
+
let stdout = "";
|
|
623
|
+
let stderr = "";
|
|
624
|
+
let outputSize = 0;
|
|
625
|
+
const MAX_OUTPUT_SIZE = 1024 * 1024;
|
|
626
|
+
node.stdout?.on("data", (data) => {
|
|
627
|
+
const dataStr = data.toString();
|
|
628
|
+
outputSize += dataStr.length;
|
|
629
|
+
if (outputSize > MAX_OUTPUT_SIZE) {
|
|
630
|
+
node.kill("SIGTERM");
|
|
631
|
+
reject(new Error(`Output size exceeded limit of ${MAX_OUTPUT_SIZE} bytes`));
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
stdout += dataStr;
|
|
635
|
+
});
|
|
636
|
+
node.stderr?.on("data", (data) => {
|
|
637
|
+
const dataStr = data.toString();
|
|
638
|
+
outputSize += dataStr.length;
|
|
639
|
+
if (outputSize > MAX_OUTPUT_SIZE) {
|
|
640
|
+
node.kill("SIGTERM");
|
|
641
|
+
reject(new Error(`Output size exceeded limit of ${MAX_OUTPUT_SIZE} bytes`));
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
stderr += dataStr;
|
|
645
|
+
});
|
|
646
|
+
const timeoutId = setTimeout(() => {
|
|
647
|
+
logger18.warn({ sandboxDir, timeout }, "Function execution timed out, killing process");
|
|
648
|
+
node.kill("SIGTERM");
|
|
649
|
+
setTimeout(() => {
|
|
650
|
+
try {
|
|
651
|
+
node.kill("SIGKILL");
|
|
652
|
+
} catch {
|
|
653
|
+
}
|
|
654
|
+
}, 5e3);
|
|
655
|
+
reject(new Error(`Function execution timed out after ${timeout}ms`));
|
|
656
|
+
}, timeout);
|
|
657
|
+
node.on("close", (code, signal) => {
|
|
658
|
+
clearTimeout(timeoutId);
|
|
659
|
+
if (code === 0) {
|
|
660
|
+
try {
|
|
661
|
+
const result = JSON.parse(stdout);
|
|
662
|
+
if (result.success) {
|
|
663
|
+
resolve(result.result);
|
|
664
|
+
} else {
|
|
665
|
+
reject(new Error(result.error || "Function execution failed"));
|
|
666
|
+
}
|
|
667
|
+
} catch (parseError) {
|
|
668
|
+
logger18.error({ stdout, stderr, parseError }, "Failed to parse function result");
|
|
669
|
+
reject(new Error(`Invalid function result: ${stdout}`));
|
|
670
|
+
}
|
|
671
|
+
} else {
|
|
672
|
+
const errorMsg = signal ? `Function execution killed by signal ${signal}: ${stderr}` : `Function execution failed with code ${code}: ${stderr}`;
|
|
673
|
+
logger18.error({ code, signal, stderr }, "Function execution failed");
|
|
674
|
+
reject(new Error(errorMsg));
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
node.on("error", (error) => {
|
|
678
|
+
clearTimeout(timeoutId);
|
|
679
|
+
logger18.error({ sandboxDir, error }, "Failed to spawn node process");
|
|
680
|
+
reject(error);
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
wrapFunctionCode(executeCode, args) {
|
|
685
|
+
return `
|
|
686
|
+
// Wrapped function execution (ESM)
|
|
687
|
+
const execute = ${executeCode};
|
|
688
|
+
const args = ${JSON.stringify(args)};
|
|
689
|
+
|
|
690
|
+
execute(args)
|
|
691
|
+
.then(result => {
|
|
692
|
+
console.log(JSON.stringify({ success: true, result }));
|
|
693
|
+
})
|
|
694
|
+
.catch(error => {
|
|
695
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
696
|
+
});
|
|
697
|
+
`;
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
__publicField(_LocalSandboxExecutor, "instance", null);
|
|
701
|
+
LocalSandboxExecutor = _LocalSandboxExecutor;
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
|
|
380
705
|
// src/utils/json-postprocessor.ts
|
|
381
706
|
var json_postprocessor_exports = {};
|
|
382
707
|
__export(json_postprocessor_exports, {
|
|
@@ -7053,7 +7378,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
7053
7378
|
return false;
|
|
7054
7379
|
};
|
|
7055
7380
|
}
|
|
7056
|
-
var
|
|
7381
|
+
var logger19 = agentsCore.getLogger("Agent");
|
|
7057
7382
|
var CONSTANTS = {
|
|
7058
7383
|
MAX_GENERATION_STEPS: 12,
|
|
7059
7384
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -7334,7 +7659,10 @@ var Agent = class {
|
|
|
7334
7659
|
]);
|
|
7335
7660
|
}
|
|
7336
7661
|
async getMcpTools(sessionId, streamRequestId) {
|
|
7337
|
-
const
|
|
7662
|
+
const mcpTools = this.config.tools?.filter((tool3) => {
|
|
7663
|
+
return tool3.config?.type === "mcp";
|
|
7664
|
+
}) || [];
|
|
7665
|
+
const tools = await Promise.all(mcpTools.map((tool3) => this.getMcpTool(tool3)) || []) || [];
|
|
7338
7666
|
if (!sessionId) {
|
|
7339
7667
|
const combinedTools = tools.reduce((acc, tool3) => {
|
|
7340
7668
|
return Object.assign(acc, tool3);
|
|
@@ -7354,14 +7682,14 @@ var Agent = class {
|
|
|
7354
7682
|
for (const toolSet of tools) {
|
|
7355
7683
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
7356
7684
|
if (!isValidTool(originalTool)) {
|
|
7357
|
-
|
|
7685
|
+
logger19.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
7358
7686
|
continue;
|
|
7359
7687
|
}
|
|
7360
7688
|
const sessionWrappedTool = ai.tool({
|
|
7361
7689
|
description: originalTool.description,
|
|
7362
7690
|
inputSchema: originalTool.inputSchema,
|
|
7363
7691
|
execute: async (args, { toolCallId }) => {
|
|
7364
|
-
|
|
7692
|
+
logger19.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
7365
7693
|
try {
|
|
7366
7694
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
7367
7695
|
const parsedResult = parseEmbeddedJson(rawResult);
|
|
@@ -7375,7 +7703,7 @@ var Agent = class {
|
|
|
7375
7703
|
});
|
|
7376
7704
|
return { result: enhancedResult, toolCallId };
|
|
7377
7705
|
} catch (error) {
|
|
7378
|
-
|
|
7706
|
+
logger19.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
7379
7707
|
throw error;
|
|
7380
7708
|
}
|
|
7381
7709
|
}
|
|
@@ -7394,6 +7722,9 @@ var Agent = class {
|
|
|
7394
7722
|
* Convert database McpTool to builder MCPToolConfig format
|
|
7395
7723
|
*/
|
|
7396
7724
|
convertToMCPToolConfig(tool3, agentToolRelationHeaders) {
|
|
7725
|
+
if (tool3.config.type !== "mcp") {
|
|
7726
|
+
throw new Error(`Cannot convert non-MCP tool to MCP config: ${tool3.id}`);
|
|
7727
|
+
}
|
|
7397
7728
|
return {
|
|
7398
7729
|
id: tool3.id,
|
|
7399
7730
|
name: tool3.name,
|
|
@@ -7462,6 +7793,9 @@ var Agent = class {
|
|
|
7462
7793
|
selectedTools
|
|
7463
7794
|
);
|
|
7464
7795
|
} else {
|
|
7796
|
+
if (tool3.config.type !== "mcp") {
|
|
7797
|
+
throw new Error(`Cannot build server config for non-MCP tool: ${tool3.id}`);
|
|
7798
|
+
}
|
|
7465
7799
|
serverConfig = {
|
|
7466
7800
|
type: tool3.config.mcp.transport?.type || agentsCore.MCPTransportType.streamableHttp,
|
|
7467
7801
|
url: tool3.config.mcp.server.url,
|
|
@@ -7470,7 +7804,7 @@ var Agent = class {
|
|
|
7470
7804
|
headers: agentToolRelationHeaders
|
|
7471
7805
|
};
|
|
7472
7806
|
}
|
|
7473
|
-
|
|
7807
|
+
logger19.info(
|
|
7474
7808
|
{
|
|
7475
7809
|
toolName: tool3.name,
|
|
7476
7810
|
credentialReferenceId,
|
|
@@ -7495,7 +7829,7 @@ var Agent = class {
|
|
|
7495
7829
|
this.mcpClientCache.set(cacheKey, client);
|
|
7496
7830
|
} catch (error) {
|
|
7497
7831
|
this.mcpConnectionLocks.delete(cacheKey);
|
|
7498
|
-
|
|
7832
|
+
logger19.error(
|
|
7499
7833
|
{
|
|
7500
7834
|
toolName: tool3.name,
|
|
7501
7835
|
agentId: this.config.id,
|
|
@@ -7519,7 +7853,7 @@ var Agent = class {
|
|
|
7519
7853
|
await client.connect();
|
|
7520
7854
|
return client;
|
|
7521
7855
|
} catch (error) {
|
|
7522
|
-
|
|
7856
|
+
logger19.error(
|
|
7523
7857
|
{
|
|
7524
7858
|
toolName: tool3.name,
|
|
7525
7859
|
agentId: this.config.id,
|
|
@@ -7530,21 +7864,88 @@ var Agent = class {
|
|
|
7530
7864
|
throw error;
|
|
7531
7865
|
}
|
|
7532
7866
|
}
|
|
7533
|
-
getFunctionTools(streamRequestId) {
|
|
7534
|
-
if (!this.config.functionTools) return {};
|
|
7867
|
+
async getFunctionTools(sessionId, streamRequestId) {
|
|
7535
7868
|
const functionTools = {};
|
|
7536
|
-
|
|
7537
|
-
const
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7869
|
+
try {
|
|
7870
|
+
const toolsForAgent = await agentsCore.getToolsForAgent(dbClient_default)({
|
|
7871
|
+
scopes: {
|
|
7872
|
+
tenantId: this.config.tenantId || "default",
|
|
7873
|
+
projectId: this.config.projectId || "default",
|
|
7874
|
+
graphId: this.config.graphId,
|
|
7875
|
+
agentId: this.config.id
|
|
7876
|
+
}
|
|
7541
7877
|
});
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
);
|
|
7878
|
+
const toolsData = toolsForAgent.data || [];
|
|
7879
|
+
const functionToolDefs = toolsData.filter((tool3) => tool3.tool.config.type === "function");
|
|
7880
|
+
if (functionToolDefs.length === 0) {
|
|
7881
|
+
return functionTools;
|
|
7882
|
+
}
|
|
7883
|
+
const { LocalSandboxExecutor: LocalSandboxExecutor2 } = await Promise.resolve().then(() => (init_LocalSandboxExecutor(), LocalSandboxExecutor_exports));
|
|
7884
|
+
const sandboxExecutor = LocalSandboxExecutor2.getInstance();
|
|
7885
|
+
for (const toolDef of functionToolDefs) {
|
|
7886
|
+
if (toolDef.tool.config?.type === "function") {
|
|
7887
|
+
const functionId = toolDef.tool.functionId;
|
|
7888
|
+
if (!functionId) {
|
|
7889
|
+
logger19.warn({ toolId: toolDef.tool.id }, "Function tool missing functionId reference");
|
|
7890
|
+
continue;
|
|
7891
|
+
}
|
|
7892
|
+
const functionData = await agentsCore.getFunction(dbClient_default)({
|
|
7893
|
+
functionId,
|
|
7894
|
+
scopes: {
|
|
7895
|
+
tenantId: this.config.tenantId || "default",
|
|
7896
|
+
projectId: this.config.projectId || "default"
|
|
7897
|
+
}
|
|
7898
|
+
});
|
|
7899
|
+
if (!functionData) {
|
|
7900
|
+
logger19.warn(
|
|
7901
|
+
{ functionId, toolId: toolDef.tool.id },
|
|
7902
|
+
"Function not found in functions table"
|
|
7903
|
+
);
|
|
7904
|
+
continue;
|
|
7905
|
+
}
|
|
7906
|
+
const zodSchema = jsonSchemaToZod(functionData.inputSchema);
|
|
7907
|
+
const aiTool = ai.tool({
|
|
7908
|
+
description: toolDef.tool.description || toolDef.tool.name,
|
|
7909
|
+
inputSchema: zodSchema,
|
|
7910
|
+
execute: async (args, { toolCallId }) => {
|
|
7911
|
+
logger19.debug(
|
|
7912
|
+
{ toolName: toolDef.tool.name, toolCallId, args },
|
|
7913
|
+
"Function Tool Called"
|
|
7914
|
+
);
|
|
7915
|
+
try {
|
|
7916
|
+
const result = await sandboxExecutor.executeFunctionTool(toolDef.tool.id, args, {
|
|
7917
|
+
description: toolDef.tool.description || toolDef.tool.name,
|
|
7918
|
+
inputSchema: functionData.inputSchema || {},
|
|
7919
|
+
executeCode: functionData.executeCode,
|
|
7920
|
+
dependencies: functionData.dependencies || {}
|
|
7921
|
+
});
|
|
7922
|
+
toolSessionManager.recordToolResult(sessionId || "", {
|
|
7923
|
+
toolCallId,
|
|
7924
|
+
toolName: toolDef.tool.name,
|
|
7925
|
+
args,
|
|
7926
|
+
result,
|
|
7927
|
+
timestamp: Date.now()
|
|
7928
|
+
});
|
|
7929
|
+
return { result, toolCallId };
|
|
7930
|
+
} catch (error) {
|
|
7931
|
+
logger19.error(
|
|
7932
|
+
{ toolName: toolDef.tool.name, toolCallId, error },
|
|
7933
|
+
"Function tool execution failed"
|
|
7934
|
+
);
|
|
7935
|
+
throw error;
|
|
7936
|
+
}
|
|
7937
|
+
}
|
|
7938
|
+
});
|
|
7939
|
+
functionTools[toolDef.tool.name] = this.wrapToolWithStreaming(
|
|
7940
|
+
toolDef.tool.name,
|
|
7941
|
+
aiTool,
|
|
7942
|
+
streamRequestId || "",
|
|
7943
|
+
"tool"
|
|
7944
|
+
);
|
|
7945
|
+
}
|
|
7946
|
+
}
|
|
7947
|
+
} catch (error) {
|
|
7948
|
+
logger19.error({ error }, "Failed to load function tools from database");
|
|
7548
7949
|
}
|
|
7549
7950
|
return functionTools;
|
|
7550
7951
|
}
|
|
@@ -7554,7 +7955,7 @@ var Agent = class {
|
|
|
7554
7955
|
async getResolvedContext(conversationId, requestContext) {
|
|
7555
7956
|
try {
|
|
7556
7957
|
if (!this.config.contextConfigId) {
|
|
7557
|
-
|
|
7958
|
+
logger19.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
7558
7959
|
return null;
|
|
7559
7960
|
}
|
|
7560
7961
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -7566,7 +7967,7 @@ var Agent = class {
|
|
|
7566
7967
|
id: this.config.contextConfigId
|
|
7567
7968
|
});
|
|
7568
7969
|
if (!contextConfig) {
|
|
7569
|
-
|
|
7970
|
+
logger19.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
7570
7971
|
return null;
|
|
7571
7972
|
}
|
|
7572
7973
|
if (!this.contextResolver) {
|
|
@@ -7583,7 +7984,7 @@ var Agent = class {
|
|
|
7583
7984
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7584
7985
|
$env: process.env
|
|
7585
7986
|
};
|
|
7586
|
-
|
|
7987
|
+
logger19.debug(
|
|
7587
7988
|
{
|
|
7588
7989
|
conversationId,
|
|
7589
7990
|
contextConfigId: contextConfig.id,
|
|
@@ -7597,7 +7998,7 @@ var Agent = class {
|
|
|
7597
7998
|
);
|
|
7598
7999
|
return contextWithBuiltins;
|
|
7599
8000
|
} catch (error) {
|
|
7600
|
-
|
|
8001
|
+
logger19.error(
|
|
7601
8002
|
{
|
|
7602
8003
|
conversationId,
|
|
7603
8004
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7621,7 +8022,7 @@ var Agent = class {
|
|
|
7621
8022
|
});
|
|
7622
8023
|
return graphDefinition?.graphPrompt || void 0;
|
|
7623
8024
|
} catch (error) {
|
|
7624
|
-
|
|
8025
|
+
logger19.warn(
|
|
7625
8026
|
{
|
|
7626
8027
|
graphId: this.config.graphId,
|
|
7627
8028
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7650,7 +8051,7 @@ var Agent = class {
|
|
|
7650
8051
|
(agent) => "artifactComponents" in agent && agent.artifactComponents && agent.artifactComponents.length > 0
|
|
7651
8052
|
);
|
|
7652
8053
|
} catch (error) {
|
|
7653
|
-
|
|
8054
|
+
logger19.warn(
|
|
7654
8055
|
{
|
|
7655
8056
|
graphId: this.config.graphId,
|
|
7656
8057
|
tenantId: this.config.tenantId,
|
|
@@ -7679,7 +8080,7 @@ var Agent = class {
|
|
|
7679
8080
|
preserveUnresolved: false
|
|
7680
8081
|
});
|
|
7681
8082
|
} catch (error) {
|
|
7682
|
-
|
|
8083
|
+
logger19.error(
|
|
7683
8084
|
{
|
|
7684
8085
|
conversationId,
|
|
7685
8086
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7726,7 +8127,7 @@ var Agent = class {
|
|
|
7726
8127
|
preserveUnresolved: false
|
|
7727
8128
|
});
|
|
7728
8129
|
} catch (error) {
|
|
7729
|
-
|
|
8130
|
+
logger19.error(
|
|
7730
8131
|
{
|
|
7731
8132
|
conversationId,
|
|
7732
8133
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7738,9 +8139,24 @@ var Agent = class {
|
|
|
7738
8139
|
}
|
|
7739
8140
|
const streamRequestId = runtimeContext?.metadata?.streamRequestId;
|
|
7740
8141
|
const mcpTools = await this.getMcpTools(void 0, streamRequestId);
|
|
7741
|
-
const functionTools = this.getFunctionTools(streamRequestId);
|
|
8142
|
+
const functionTools = await this.getFunctionTools(streamRequestId || "");
|
|
7742
8143
|
const relationTools = this.getRelationTools(runtimeContext);
|
|
7743
8144
|
const allTools = { ...mcpTools, ...functionTools, ...relationTools };
|
|
8145
|
+
logger19.info(
|
|
8146
|
+
{
|
|
8147
|
+
mcpTools: Object.keys(mcpTools),
|
|
8148
|
+
functionTools: Object.keys(functionTools),
|
|
8149
|
+
relationTools: Object.keys(relationTools),
|
|
8150
|
+
allTools: Object.keys(allTools),
|
|
8151
|
+
functionToolsDetails: Object.entries(functionTools).map(([name, tool3]) => ({
|
|
8152
|
+
name,
|
|
8153
|
+
hasExecute: typeof tool3.execute === "function",
|
|
8154
|
+
hasDescription: !!tool3.description,
|
|
8155
|
+
hasInputSchema: !!tool3.inputSchema
|
|
8156
|
+
}))
|
|
8157
|
+
},
|
|
8158
|
+
"Tools loaded for agent"
|
|
8159
|
+
);
|
|
7744
8160
|
const toolDefinitions = Object.entries(allTools).map(([name, tool3]) => ({
|
|
7745
8161
|
name,
|
|
7746
8162
|
description: tool3.description || "",
|
|
@@ -7765,7 +8181,7 @@ var Agent = class {
|
|
|
7765
8181
|
preserveUnresolved: false
|
|
7766
8182
|
});
|
|
7767
8183
|
} catch (error) {
|
|
7768
|
-
|
|
8184
|
+
logger19.error(
|
|
7769
8185
|
{
|
|
7770
8186
|
conversationId,
|
|
7771
8187
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7798,7 +8214,7 @@ var Agent = class {
|
|
|
7798
8214
|
toolCallId: z6.z.string().describe("The tool call ID associated with this artifact.")
|
|
7799
8215
|
}),
|
|
7800
8216
|
execute: async ({ artifactId, toolCallId }) => {
|
|
7801
|
-
|
|
8217
|
+
logger19.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
7802
8218
|
const streamRequestId = this.getStreamRequestId();
|
|
7803
8219
|
const artifactService = graphSessionManager.getArtifactService(streamRequestId);
|
|
7804
8220
|
if (!artifactService) {
|
|
@@ -7832,7 +8248,7 @@ var Agent = class {
|
|
|
7832
8248
|
});
|
|
7833
8249
|
}
|
|
7834
8250
|
// Provide a default tool set that is always available to the agent.
|
|
7835
|
-
async getDefaultTools(
|
|
8251
|
+
async getDefaultTools(_sessionId, streamRequestId) {
|
|
7836
8252
|
const defaultTools = {};
|
|
7837
8253
|
if (await this.graphHasArtifactComponents()) {
|
|
7838
8254
|
defaultTools.get_reference_artifact = this.getArtifactTools();
|
|
@@ -7920,13 +8336,19 @@ var Agent = class {
|
|
|
7920
8336
|
if (Array.isArray(obj)) {
|
|
7921
8337
|
obj.slice(0, 3).forEach((item) => {
|
|
7922
8338
|
if (item && typeof item === "object") {
|
|
7923
|
-
Object.keys(item).forEach((key) =>
|
|
8339
|
+
Object.keys(item).forEach((key) => {
|
|
8340
|
+
fields.add(key);
|
|
8341
|
+
});
|
|
7924
8342
|
}
|
|
7925
8343
|
});
|
|
7926
8344
|
} else if (obj && typeof obj === "object") {
|
|
7927
|
-
Object.keys(obj).forEach((key) =>
|
|
8345
|
+
Object.keys(obj).forEach((key) => {
|
|
8346
|
+
fields.add(key);
|
|
8347
|
+
});
|
|
7928
8348
|
Object.values(obj).forEach((value) => {
|
|
7929
|
-
findCommonFields(value, depth + 1).forEach((field) =>
|
|
8349
|
+
findCommonFields(value, depth + 1).forEach((field) => {
|
|
8350
|
+
fields.add(field);
|
|
8351
|
+
});
|
|
7930
8352
|
});
|
|
7931
8353
|
}
|
|
7932
8354
|
return fields;
|
|
@@ -8052,7 +8474,7 @@ var Agent = class {
|
|
|
8052
8474
|
};
|
|
8053
8475
|
return enhanced;
|
|
8054
8476
|
} catch (error) {
|
|
8055
|
-
|
|
8477
|
+
logger19.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
8056
8478
|
return result;
|
|
8057
8479
|
}
|
|
8058
8480
|
}
|
|
@@ -8067,7 +8489,7 @@ var Agent = class {
|
|
|
8067
8489
|
}
|
|
8068
8490
|
});
|
|
8069
8491
|
} catch (error) {
|
|
8070
|
-
|
|
8492
|
+
logger19.error(
|
|
8071
8493
|
{ error, graphId: this.config.graphId },
|
|
8072
8494
|
"Failed to check graph artifact components"
|
|
8073
8495
|
);
|
|
@@ -8110,7 +8532,7 @@ var Agent = class {
|
|
|
8110
8532
|
// Normal prompt with data components
|
|
8111
8533
|
this.buildSystemPrompt(runtimeContext, true),
|
|
8112
8534
|
// Thinking prompt without data components
|
|
8113
|
-
|
|
8535
|
+
this.getFunctionTools(sessionId, streamRequestId),
|
|
8114
8536
|
Promise.resolve(this.getRelationTools(runtimeContext, sessionId)),
|
|
8115
8537
|
this.getDefaultTools(sessionId, streamRequestId)
|
|
8116
8538
|
]);
|
|
@@ -8168,7 +8590,7 @@ var Agent = class {
|
|
|
8168
8590
|
const configuredTimeout = modelSettings.maxDuration ? Math.min(modelSettings.maxDuration * 1e3, MAX_ALLOWED_TIMEOUT_MS) : shouldStreamPhase1 ? CONSTANTS.PHASE_1_TIMEOUT_MS : CONSTANTS.NON_STREAMING_PHASE_1_TIMEOUT_MS;
|
|
8169
8591
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
8170
8592
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
8171
|
-
|
|
8593
|
+
logger19.warn(
|
|
8172
8594
|
{
|
|
8173
8595
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
8174
8596
|
appliedTimeout: timeoutMs,
|
|
@@ -8210,7 +8632,7 @@ var Agent = class {
|
|
|
8210
8632
|
}
|
|
8211
8633
|
);
|
|
8212
8634
|
} catch (error) {
|
|
8213
|
-
|
|
8635
|
+
logger19.debug({ error }, "Failed to track agent reasoning");
|
|
8214
8636
|
}
|
|
8215
8637
|
}
|
|
8216
8638
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8314,7 +8736,7 @@ var Agent = class {
|
|
|
8314
8736
|
}
|
|
8315
8737
|
);
|
|
8316
8738
|
} catch (error) {
|
|
8317
|
-
|
|
8739
|
+
logger19.debug({ error }, "Failed to track agent reasoning");
|
|
8318
8740
|
}
|
|
8319
8741
|
}
|
|
8320
8742
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8606,7 +9028,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8606
9028
|
};
|
|
8607
9029
|
|
|
8608
9030
|
// src/agents/generateTaskHandler.ts
|
|
8609
|
-
var
|
|
9031
|
+
var logger20 = agentsCore.getLogger("generateTaskHandler");
|
|
8610
9032
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
8611
9033
|
return async (task) => {
|
|
8612
9034
|
try {
|
|
@@ -8659,7 +9081,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8659
9081
|
}
|
|
8660
9082
|
})
|
|
8661
9083
|
]);
|
|
8662
|
-
|
|
9084
|
+
logger20.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
8663
9085
|
const enhancedInternalRelations = await Promise.all(
|
|
8664
9086
|
internalRelations.map(async (relation) => {
|
|
8665
9087
|
try {
|
|
@@ -8688,7 +9110,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8688
9110
|
return { ...relation, description: enhancedDescription };
|
|
8689
9111
|
}
|
|
8690
9112
|
} catch (error) {
|
|
8691
|
-
|
|
9113
|
+
logger20.warn({ agentId: relation.id, error }, "Failed to enhance agent description");
|
|
8692
9114
|
}
|
|
8693
9115
|
return relation;
|
|
8694
9116
|
})
|
|
@@ -8792,7 +9214,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8792
9214
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
8793
9215
|
if (taskIdMatch) {
|
|
8794
9216
|
contextId = taskIdMatch[1];
|
|
8795
|
-
|
|
9217
|
+
logger20.info(
|
|
8796
9218
|
{
|
|
8797
9219
|
taskId: task.id,
|
|
8798
9220
|
extractedContextId: contextId,
|
|
@@ -8808,7 +9230,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8808
9230
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
8809
9231
|
agent.setDelegationStatus(isDelegation);
|
|
8810
9232
|
if (isDelegation) {
|
|
8811
|
-
|
|
9233
|
+
logger20.info(
|
|
8812
9234
|
{ agentId: config.agentId, taskId: task.id },
|
|
8813
9235
|
"Delegated agent - streaming disabled"
|
|
8814
9236
|
);
|
|
@@ -9033,7 +9455,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
9033
9455
|
init_dbClient();
|
|
9034
9456
|
init_logger();
|
|
9035
9457
|
var app = new zodOpenapi.OpenAPIHono();
|
|
9036
|
-
var
|
|
9458
|
+
var logger21 = agentsCore.getLogger("agents");
|
|
9037
9459
|
app.openapi(
|
|
9038
9460
|
zodOpenapi.createRoute({
|
|
9039
9461
|
method: "get",
|
|
@@ -9071,7 +9493,7 @@ app.openapi(
|
|
|
9071
9493
|
tracestate: c.req.header("tracestate"),
|
|
9072
9494
|
baggage: c.req.header("baggage")
|
|
9073
9495
|
};
|
|
9074
|
-
|
|
9496
|
+
logger21.info(
|
|
9075
9497
|
{
|
|
9076
9498
|
otelHeaders,
|
|
9077
9499
|
path: c.req.path,
|
|
@@ -9083,7 +9505,7 @@ app.openapi(
|
|
|
9083
9505
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
9084
9506
|
console.dir("executionContext", executionContext);
|
|
9085
9507
|
if (agentId) {
|
|
9086
|
-
|
|
9508
|
+
logger21.info(
|
|
9087
9509
|
{
|
|
9088
9510
|
message: "getRegisteredAgent (agent-level)",
|
|
9089
9511
|
tenantId,
|
|
@@ -9095,7 +9517,7 @@ app.openapi(
|
|
|
9095
9517
|
);
|
|
9096
9518
|
const credentialStores = c.get("credentialStores");
|
|
9097
9519
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
9098
|
-
|
|
9520
|
+
logger21.info({ agent }, "agent registered: well-known agent.json");
|
|
9099
9521
|
if (!agent) {
|
|
9100
9522
|
throw agentsCore.createApiError({
|
|
9101
9523
|
code: "not_found",
|
|
@@ -9104,7 +9526,7 @@ app.openapi(
|
|
|
9104
9526
|
}
|
|
9105
9527
|
return c.json(agent.agentCard);
|
|
9106
9528
|
} else {
|
|
9107
|
-
|
|
9529
|
+
logger21.info(
|
|
9108
9530
|
{
|
|
9109
9531
|
message: "getRegisteredGraph (graph-level)",
|
|
9110
9532
|
tenantId,
|
|
@@ -9130,7 +9552,7 @@ app.post("/a2a", async (c) => {
|
|
|
9130
9552
|
tracestate: c.req.header("tracestate"),
|
|
9131
9553
|
baggage: c.req.header("baggage")
|
|
9132
9554
|
};
|
|
9133
|
-
|
|
9555
|
+
logger21.info(
|
|
9134
9556
|
{
|
|
9135
9557
|
otelHeaders,
|
|
9136
9558
|
path: c.req.path,
|
|
@@ -9141,7 +9563,7 @@ app.post("/a2a", async (c) => {
|
|
|
9141
9563
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
9142
9564
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
9143
9565
|
if (agentId) {
|
|
9144
|
-
|
|
9566
|
+
logger21.info(
|
|
9145
9567
|
{
|
|
9146
9568
|
message: "a2a (agent-level)",
|
|
9147
9569
|
tenantId,
|
|
@@ -9165,7 +9587,7 @@ app.post("/a2a", async (c) => {
|
|
|
9165
9587
|
}
|
|
9166
9588
|
return a2aHandler(c, agent);
|
|
9167
9589
|
} else {
|
|
9168
|
-
|
|
9590
|
+
logger21.info(
|
|
9169
9591
|
{
|
|
9170
9592
|
message: "a2a (graph-level)",
|
|
9171
9593
|
tenantId,
|
|
@@ -9221,14 +9643,14 @@ init_dbClient();
|
|
|
9221
9643
|
// src/a2a/transfer.ts
|
|
9222
9644
|
init_dbClient();
|
|
9223
9645
|
init_logger();
|
|
9224
|
-
var
|
|
9646
|
+
var logger22 = agentsCore.getLogger("Transfer");
|
|
9225
9647
|
async function executeTransfer({
|
|
9226
9648
|
tenantId,
|
|
9227
9649
|
threadId,
|
|
9228
9650
|
projectId,
|
|
9229
9651
|
targetAgentId
|
|
9230
9652
|
}) {
|
|
9231
|
-
|
|
9653
|
+
logger22.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
9232
9654
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
9233
9655
|
scopes: { tenantId, projectId },
|
|
9234
9656
|
threadId,
|
|
@@ -9814,7 +10236,7 @@ function createMCPStreamHelper() {
|
|
|
9814
10236
|
}
|
|
9815
10237
|
|
|
9816
10238
|
// src/handlers/executionHandler.ts
|
|
9817
|
-
var
|
|
10239
|
+
var logger23 = agentsCore.getLogger("ExecutionHandler");
|
|
9818
10240
|
var ExecutionHandler = class {
|
|
9819
10241
|
constructor() {
|
|
9820
10242
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -9850,7 +10272,7 @@ var ExecutionHandler = class {
|
|
|
9850
10272
|
if (emitOperations) {
|
|
9851
10273
|
graphSessionManager.enableEmitOperations(requestId2);
|
|
9852
10274
|
}
|
|
9853
|
-
|
|
10275
|
+
logger23.info(
|
|
9854
10276
|
{ sessionId: requestId2, graphId, conversationId, emitOperations },
|
|
9855
10277
|
"Created GraphSession for message execution"
|
|
9856
10278
|
);
|
|
@@ -9865,7 +10287,7 @@ var ExecutionHandler = class {
|
|
|
9865
10287
|
);
|
|
9866
10288
|
}
|
|
9867
10289
|
} catch (error) {
|
|
9868
|
-
|
|
10290
|
+
logger23.error(
|
|
9869
10291
|
{
|
|
9870
10292
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
9871
10293
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -9881,7 +10303,7 @@ var ExecutionHandler = class {
|
|
|
9881
10303
|
try {
|
|
9882
10304
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
9883
10305
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
9884
|
-
|
|
10306
|
+
logger23.info(
|
|
9885
10307
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
9886
10308
|
"Attempting to create or reuse existing task"
|
|
9887
10309
|
);
|
|
@@ -9905,7 +10327,7 @@ var ExecutionHandler = class {
|
|
|
9905
10327
|
agent_id: currentAgentId
|
|
9906
10328
|
}
|
|
9907
10329
|
});
|
|
9908
|
-
|
|
10330
|
+
logger23.info(
|
|
9909
10331
|
{
|
|
9910
10332
|
taskId,
|
|
9911
10333
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -9914,27 +10336,27 @@ var ExecutionHandler = class {
|
|
|
9914
10336
|
);
|
|
9915
10337
|
} catch (error) {
|
|
9916
10338
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
9917
|
-
|
|
10339
|
+
logger23.info(
|
|
9918
10340
|
{ taskId, error: error.message },
|
|
9919
10341
|
"Task already exists, fetching existing task"
|
|
9920
10342
|
);
|
|
9921
10343
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
9922
10344
|
if (existingTask) {
|
|
9923
10345
|
task = existingTask;
|
|
9924
|
-
|
|
10346
|
+
logger23.info(
|
|
9925
10347
|
{ taskId, existingTask },
|
|
9926
10348
|
"Successfully reused existing task from race condition"
|
|
9927
10349
|
);
|
|
9928
10350
|
} else {
|
|
9929
|
-
|
|
10351
|
+
logger23.error({ taskId, error }, "Task constraint failed but task not found");
|
|
9930
10352
|
throw error;
|
|
9931
10353
|
}
|
|
9932
10354
|
} else {
|
|
9933
|
-
|
|
10355
|
+
logger23.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
9934
10356
|
throw error;
|
|
9935
10357
|
}
|
|
9936
10358
|
}
|
|
9937
|
-
|
|
10359
|
+
logger23.debug(
|
|
9938
10360
|
{
|
|
9939
10361
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9940
10362
|
executionType: "create_initial_task",
|
|
@@ -9952,7 +10374,7 @@ var ExecutionHandler = class {
|
|
|
9952
10374
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
9953
10375
|
while (iterations < maxTransfers) {
|
|
9954
10376
|
iterations++;
|
|
9955
|
-
|
|
10377
|
+
logger23.info(
|
|
9956
10378
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
9957
10379
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
9958
10380
|
);
|
|
@@ -9960,10 +10382,10 @@ var ExecutionHandler = class {
|
|
|
9960
10382
|
scopes: { tenantId, projectId },
|
|
9961
10383
|
conversationId
|
|
9962
10384
|
});
|
|
9963
|
-
|
|
10385
|
+
logger23.info({ activeAgent }, "activeAgent");
|
|
9964
10386
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
9965
10387
|
currentAgentId = activeAgent.activeAgentId;
|
|
9966
|
-
|
|
10388
|
+
logger23.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
9967
10389
|
}
|
|
9968
10390
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
9969
10391
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -10004,13 +10426,13 @@ var ExecutionHandler = class {
|
|
|
10004
10426
|
});
|
|
10005
10427
|
if (!messageResponse?.result) {
|
|
10006
10428
|
errorCount++;
|
|
10007
|
-
|
|
10429
|
+
logger23.error(
|
|
10008
10430
|
{ currentAgentId, iterations, errorCount },
|
|
10009
10431
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10010
10432
|
);
|
|
10011
10433
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10012
10434
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10013
|
-
|
|
10435
|
+
logger23.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10014
10436
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10015
10437
|
if (task) {
|
|
10016
10438
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10035,7 +10457,7 @@ var ExecutionHandler = class {
|
|
|
10035
10457
|
const transferResponse = messageResponse.result;
|
|
10036
10458
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
10037
10459
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
10038
|
-
|
|
10460
|
+
logger23.info({ targetAgentId, transferReason }, "transfer response");
|
|
10039
10461
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
10040
10462
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
10041
10463
|
projectId,
|
|
@@ -10046,7 +10468,7 @@ var ExecutionHandler = class {
|
|
|
10046
10468
|
if (success) {
|
|
10047
10469
|
fromAgentId = currentAgentId;
|
|
10048
10470
|
currentAgentId = newAgentId;
|
|
10049
|
-
|
|
10471
|
+
logger23.info(
|
|
10050
10472
|
{
|
|
10051
10473
|
transferFrom: fromAgentId,
|
|
10052
10474
|
transferTo: currentAgentId,
|
|
@@ -10064,7 +10486,7 @@ var ExecutionHandler = class {
|
|
|
10064
10486
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
10065
10487
|
if (graphSessionData) {
|
|
10066
10488
|
const sessionSummary = graphSessionData.getSummary();
|
|
10067
|
-
|
|
10489
|
+
logger23.info(sessionSummary, "GraphSession data after completion");
|
|
10068
10490
|
}
|
|
10069
10491
|
let textContent = "";
|
|
10070
10492
|
for (const part of responseParts) {
|
|
@@ -10118,22 +10540,22 @@ var ExecutionHandler = class {
|
|
|
10118
10540
|
}
|
|
10119
10541
|
});
|
|
10120
10542
|
const updateTaskEnd = Date.now();
|
|
10121
|
-
|
|
10543
|
+
logger23.info(
|
|
10122
10544
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
10123
10545
|
"Completed updateTask operation"
|
|
10124
10546
|
);
|
|
10125
10547
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
10126
10548
|
await sseHelper.complete();
|
|
10127
|
-
|
|
10549
|
+
logger23.info({}, "Ending GraphSession and cleaning up");
|
|
10128
10550
|
graphSessionManager.endSession(requestId2);
|
|
10129
|
-
|
|
10551
|
+
logger23.info({}, "Cleaning up streamHelper");
|
|
10130
10552
|
unregisterStreamHelper(requestId2);
|
|
10131
10553
|
let response;
|
|
10132
10554
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
10133
10555
|
const captured = sseHelper.getCapturedResponse();
|
|
10134
10556
|
response = captured.text || "No response content";
|
|
10135
10557
|
}
|
|
10136
|
-
|
|
10558
|
+
logger23.info({}, "ExecutionHandler returning success");
|
|
10137
10559
|
return { success: true, iterations, response };
|
|
10138
10560
|
} catch (error) {
|
|
10139
10561
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -10144,13 +10566,13 @@ var ExecutionHandler = class {
|
|
|
10144
10566
|
});
|
|
10145
10567
|
}
|
|
10146
10568
|
errorCount++;
|
|
10147
|
-
|
|
10569
|
+
logger23.warn(
|
|
10148
10570
|
{ iterations, errorCount },
|
|
10149
10571
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10150
10572
|
);
|
|
10151
10573
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10152
10574
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10153
|
-
|
|
10575
|
+
logger23.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10154
10576
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10155
10577
|
if (task) {
|
|
10156
10578
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10171,7 +10593,7 @@ var ExecutionHandler = class {
|
|
|
10171
10593
|
}
|
|
10172
10594
|
}
|
|
10173
10595
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
10174
|
-
|
|
10596
|
+
logger23.error({ maxTransfers, iterations }, errorMessage);
|
|
10175
10597
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
10176
10598
|
if (task) {
|
|
10177
10599
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10190,7 +10612,7 @@ var ExecutionHandler = class {
|
|
|
10190
10612
|
unregisterStreamHelper(requestId2);
|
|
10191
10613
|
return { success: false, error: errorMessage, iterations };
|
|
10192
10614
|
} catch (error) {
|
|
10193
|
-
|
|
10615
|
+
logger23.error({ error }, "Error in execution handler");
|
|
10194
10616
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
10195
10617
|
await sseHelper.writeOperation(
|
|
10196
10618
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -10218,7 +10640,7 @@ var ExecutionHandler = class {
|
|
|
10218
10640
|
// src/routes/chat.ts
|
|
10219
10641
|
init_logger();
|
|
10220
10642
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
10221
|
-
var
|
|
10643
|
+
var logger24 = agentsCore.getLogger("completionsHandler");
|
|
10222
10644
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
10223
10645
|
method: "post",
|
|
10224
10646
|
path: "/completions",
|
|
@@ -10336,7 +10758,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10336
10758
|
tracestate: c.req.header("tracestate"),
|
|
10337
10759
|
baggage: c.req.header("baggage")
|
|
10338
10760
|
};
|
|
10339
|
-
|
|
10761
|
+
logger24.info(
|
|
10340
10762
|
{
|
|
10341
10763
|
otelHeaders,
|
|
10342
10764
|
path: c.req.path,
|
|
@@ -10429,7 +10851,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10429
10851
|
dbClient: dbClient_default,
|
|
10430
10852
|
credentialStores
|
|
10431
10853
|
});
|
|
10432
|
-
|
|
10854
|
+
logger24.info(
|
|
10433
10855
|
{
|
|
10434
10856
|
tenantId,
|
|
10435
10857
|
projectId,
|
|
@@ -10477,7 +10899,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10477
10899
|
try {
|
|
10478
10900
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
10479
10901
|
await sseHelper.writeRole();
|
|
10480
|
-
|
|
10902
|
+
logger24.info({ agentId }, "Starting execution");
|
|
10481
10903
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
10482
10904
|
const emitOperations = emitOperationsHeader === "true";
|
|
10483
10905
|
const executionHandler = new ExecutionHandler();
|
|
@@ -10490,7 +10912,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10490
10912
|
sseHelper,
|
|
10491
10913
|
emitOperations
|
|
10492
10914
|
});
|
|
10493
|
-
|
|
10915
|
+
logger24.info(
|
|
10494
10916
|
{ result },
|
|
10495
10917
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10496
10918
|
);
|
|
@@ -10504,7 +10926,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10504
10926
|
}
|
|
10505
10927
|
await sseHelper.complete();
|
|
10506
10928
|
} catch (error) {
|
|
10507
|
-
|
|
10929
|
+
logger24.error(
|
|
10508
10930
|
{
|
|
10509
10931
|
error: error instanceof Error ? error.message : error,
|
|
10510
10932
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10521,12 +10943,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10521
10943
|
);
|
|
10522
10944
|
await sseHelper.complete();
|
|
10523
10945
|
} catch (streamError) {
|
|
10524
|
-
|
|
10946
|
+
logger24.error({ streamError }, "Failed to write error to stream");
|
|
10525
10947
|
}
|
|
10526
10948
|
}
|
|
10527
10949
|
});
|
|
10528
10950
|
} catch (error) {
|
|
10529
|
-
|
|
10951
|
+
logger24.error(
|
|
10530
10952
|
{
|
|
10531
10953
|
error: error instanceof Error ? error.message : error,
|
|
10532
10954
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10554,7 +10976,7 @@ var chat_default = app2;
|
|
|
10554
10976
|
init_dbClient();
|
|
10555
10977
|
init_logger();
|
|
10556
10978
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
10557
|
-
var
|
|
10979
|
+
var logger25 = agentsCore.getLogger("chatDataStream");
|
|
10558
10980
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
10559
10981
|
method: "post",
|
|
10560
10982
|
path: "/chat",
|
|
@@ -10671,7 +11093,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10671
11093
|
});
|
|
10672
11094
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
10673
11095
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
10674
|
-
|
|
11096
|
+
logger25.info({ userText, lastUserMessage }, "userText");
|
|
10675
11097
|
const messageSpan = api.trace.getActiveSpan();
|
|
10676
11098
|
if (messageSpan) {
|
|
10677
11099
|
messageSpan.setAttributes({
|
|
@@ -10716,7 +11138,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10716
11138
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
10717
11139
|
}
|
|
10718
11140
|
} catch (err) {
|
|
10719
|
-
|
|
11141
|
+
logger25.error({ err }, "Streaming error");
|
|
10720
11142
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
10721
11143
|
} finally {
|
|
10722
11144
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -10737,7 +11159,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10737
11159
|
)
|
|
10738
11160
|
);
|
|
10739
11161
|
} catch (error) {
|
|
10740
|
-
|
|
11162
|
+
logger25.error({ error }, "chatDataStream error");
|
|
10741
11163
|
throw agentsCore.createApiError({
|
|
10742
11164
|
code: "internal_server_error",
|
|
10743
11165
|
message: "Failed to process chat completion"
|
|
@@ -10752,7 +11174,7 @@ init_logger();
|
|
|
10752
11174
|
function createMCPSchema(schema) {
|
|
10753
11175
|
return schema;
|
|
10754
11176
|
}
|
|
10755
|
-
var
|
|
11177
|
+
var logger26 = agentsCore.getLogger("mcp");
|
|
10756
11178
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
10757
11179
|
constructor() {
|
|
10758
11180
|
__publicField(this, "mockRes");
|
|
@@ -10807,21 +11229,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
10807
11229
|
id: 0
|
|
10808
11230
|
});
|
|
10809
11231
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
10810
|
-
|
|
11232
|
+
logger26.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
10811
11233
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
10812
11234
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
10813
11235
|
try {
|
|
10814
11236
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
10815
|
-
|
|
11237
|
+
logger26.info({ sessionId }, "Successfully spoofed initialization");
|
|
10816
11238
|
} catch (spoofError) {
|
|
10817
|
-
|
|
11239
|
+
logger26.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
10818
11240
|
}
|
|
10819
11241
|
};
|
|
10820
11242
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
10821
11243
|
const sessionId = req.headers["mcp-session-id"];
|
|
10822
|
-
|
|
11244
|
+
logger26.info({ sessionId }, "Received MCP session ID");
|
|
10823
11245
|
if (!sessionId) {
|
|
10824
|
-
|
|
11246
|
+
logger26.info({ body }, "Missing session ID");
|
|
10825
11247
|
res.writeHead(400).end(
|
|
10826
11248
|
JSON.stringify({
|
|
10827
11249
|
jsonrpc: "2.0",
|
|
@@ -10847,7 +11269,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10847
11269
|
scopes: { tenantId, projectId },
|
|
10848
11270
|
conversationId: sessionId
|
|
10849
11271
|
});
|
|
10850
|
-
|
|
11272
|
+
logger26.info(
|
|
10851
11273
|
{
|
|
10852
11274
|
sessionId,
|
|
10853
11275
|
conversationFound: !!conversation,
|
|
@@ -10858,7 +11280,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10858
11280
|
"Conversation lookup result"
|
|
10859
11281
|
);
|
|
10860
11282
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
10861
|
-
|
|
11283
|
+
logger26.info(
|
|
10862
11284
|
{ sessionId, conversationId: conversation?.id },
|
|
10863
11285
|
"MCP session not found or invalid"
|
|
10864
11286
|
);
|
|
@@ -10919,7 +11341,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
10919
11341
|
requestId: requestId2,
|
|
10920
11342
|
sseHelper: mcpStreamHelper
|
|
10921
11343
|
});
|
|
10922
|
-
|
|
11344
|
+
logger26.info(
|
|
10923
11345
|
{ result },
|
|
10924
11346
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10925
11347
|
);
|
|
@@ -11003,7 +11425,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
11003
11425
|
dbClient: dbClient_default,
|
|
11004
11426
|
credentialStores
|
|
11005
11427
|
});
|
|
11006
|
-
|
|
11428
|
+
logger26.info(
|
|
11007
11429
|
{
|
|
11008
11430
|
tenantId,
|
|
11009
11431
|
projectId,
|
|
@@ -11065,7 +11487,7 @@ var validateRequestParameters = (c) => {
|
|
|
11065
11487
|
};
|
|
11066
11488
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
11067
11489
|
const { tenantId, projectId, graphId } = executionContext;
|
|
11068
|
-
|
|
11490
|
+
logger26.info({ body }, "Received initialization request");
|
|
11069
11491
|
const sessionId = agentsCore.getConversationId();
|
|
11070
11492
|
const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
11071
11493
|
scopes: { tenantId, projectId, graphId }
|
|
@@ -11105,7 +11527,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11105
11527
|
}
|
|
11106
11528
|
}
|
|
11107
11529
|
});
|
|
11108
|
-
|
|
11530
|
+
logger26.info(
|
|
11109
11531
|
{ sessionId, conversationId: conversation.id },
|
|
11110
11532
|
"Created MCP session as conversation"
|
|
11111
11533
|
);
|
|
@@ -11114,9 +11536,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11114
11536
|
});
|
|
11115
11537
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
11116
11538
|
await server.connect(transport);
|
|
11117
|
-
|
|
11539
|
+
logger26.info({ sessionId }, "Server connected for initialization");
|
|
11118
11540
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
11119
|
-
|
|
11541
|
+
logger26.info(
|
|
11120
11542
|
{
|
|
11121
11543
|
sessionId,
|
|
11122
11544
|
bodyMethod: body?.method,
|
|
@@ -11125,7 +11547,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11125
11547
|
"About to handle initialization request"
|
|
11126
11548
|
);
|
|
11127
11549
|
await transport.handleRequest(req, res, body);
|
|
11128
|
-
|
|
11550
|
+
logger26.info({ sessionId }, "Successfully handled initialization request");
|
|
11129
11551
|
return fetchToNode.toFetchResponse(res);
|
|
11130
11552
|
};
|
|
11131
11553
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -11153,8 +11575,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11153
11575
|
sessionId,
|
|
11154
11576
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
11155
11577
|
);
|
|
11156
|
-
|
|
11157
|
-
|
|
11578
|
+
logger26.info({ sessionId }, "Server connected and transport initialized");
|
|
11579
|
+
logger26.info(
|
|
11158
11580
|
{
|
|
11159
11581
|
sessionId,
|
|
11160
11582
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -11168,9 +11590,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11168
11590
|
);
|
|
11169
11591
|
try {
|
|
11170
11592
|
await transport.handleRequest(req, res, body);
|
|
11171
|
-
|
|
11593
|
+
logger26.info({ sessionId }, "Successfully handled MCP request");
|
|
11172
11594
|
} catch (transportError) {
|
|
11173
|
-
|
|
11595
|
+
logger26.error(
|
|
11174
11596
|
{
|
|
11175
11597
|
sessionId,
|
|
11176
11598
|
error: transportError,
|
|
@@ -11221,13 +11643,13 @@ app4.openapi(
|
|
|
11221
11643
|
}
|
|
11222
11644
|
const { executionContext } = paramValidation;
|
|
11223
11645
|
const body = c.get("requestBody") || {};
|
|
11224
|
-
|
|
11646
|
+
logger26.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
11225
11647
|
const isInitRequest = body.method === "initialize";
|
|
11226
11648
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
11227
11649
|
const validatedContext = c.get("validatedContext") || {};
|
|
11228
11650
|
const credentialStores = c.get("credentialStores");
|
|
11229
|
-
|
|
11230
|
-
|
|
11651
|
+
logger26.info({ validatedContext }, "Validated context");
|
|
11652
|
+
logger26.info({ req }, "request");
|
|
11231
11653
|
if (isInitRequest) {
|
|
11232
11654
|
return await handleInitializationRequest(
|
|
11233
11655
|
body,
|
|
@@ -11249,7 +11671,7 @@ app4.openapi(
|
|
|
11249
11671
|
);
|
|
11250
11672
|
}
|
|
11251
11673
|
} catch (e) {
|
|
11252
|
-
|
|
11674
|
+
logger26.error(
|
|
11253
11675
|
{
|
|
11254
11676
|
error: e instanceof Error ? e.message : e,
|
|
11255
11677
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -11261,7 +11683,7 @@ app4.openapi(
|
|
|
11261
11683
|
}
|
|
11262
11684
|
);
|
|
11263
11685
|
app4.get("/", async (c) => {
|
|
11264
|
-
|
|
11686
|
+
logger26.info({}, "Received GET MCP request");
|
|
11265
11687
|
return c.json(
|
|
11266
11688
|
{
|
|
11267
11689
|
jsonrpc: "2.0",
|
|
@@ -11275,7 +11697,7 @@ app4.get("/", async (c) => {
|
|
|
11275
11697
|
);
|
|
11276
11698
|
});
|
|
11277
11699
|
app4.delete("/", async (c) => {
|
|
11278
|
-
|
|
11700
|
+
logger26.info({}, "Received DELETE MCP request");
|
|
11279
11701
|
return c.json(
|
|
11280
11702
|
{
|
|
11281
11703
|
jsonrpc: "2.0",
|
|
@@ -11288,7 +11710,7 @@ app4.delete("/", async (c) => {
|
|
|
11288
11710
|
var mcp_default = app4;
|
|
11289
11711
|
|
|
11290
11712
|
// src/app.ts
|
|
11291
|
-
var
|
|
11713
|
+
var logger27 = agentsCore.getLogger("agents-run-api");
|
|
11292
11714
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
11293
11715
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
11294
11716
|
app6.use("*", otel.otel());
|
|
@@ -11304,7 +11726,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11304
11726
|
const body = await c.req.json();
|
|
11305
11727
|
c.set("requestBody", body);
|
|
11306
11728
|
} catch (error) {
|
|
11307
|
-
|
|
11729
|
+
logger27.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
11308
11730
|
}
|
|
11309
11731
|
}
|
|
11310
11732
|
return next();
|
|
@@ -11355,8 +11777,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11355
11777
|
if (!isExpectedError) {
|
|
11356
11778
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
11357
11779
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
11358
|
-
if (
|
|
11359
|
-
|
|
11780
|
+
if (logger27) {
|
|
11781
|
+
logger27.error(
|
|
11360
11782
|
{
|
|
11361
11783
|
error: err,
|
|
11362
11784
|
message: errorMessage,
|
|
@@ -11368,8 +11790,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11368
11790
|
);
|
|
11369
11791
|
}
|
|
11370
11792
|
} else {
|
|
11371
|
-
if (
|
|
11372
|
-
|
|
11793
|
+
if (logger27) {
|
|
11794
|
+
logger27.error(
|
|
11373
11795
|
{
|
|
11374
11796
|
error: err,
|
|
11375
11797
|
path: c.req.path,
|
|
@@ -11386,8 +11808,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11386
11808
|
const response = err.getResponse();
|
|
11387
11809
|
return response;
|
|
11388
11810
|
} catch (responseError) {
|
|
11389
|
-
if (
|
|
11390
|
-
|
|
11811
|
+
if (logger27) {
|
|
11812
|
+
logger27.error({ error: responseError }, "Error while handling HTTPException response");
|
|
11391
11813
|
}
|
|
11392
11814
|
}
|
|
11393
11815
|
}
|
|
@@ -11421,7 +11843,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11421
11843
|
app6.use("*", async (c, next) => {
|
|
11422
11844
|
const executionContext = c.get("executionContext");
|
|
11423
11845
|
if (!executionContext) {
|
|
11424
|
-
|
|
11846
|
+
logger27.debug({}, "Empty execution context");
|
|
11425
11847
|
return next();
|
|
11426
11848
|
}
|
|
11427
11849
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -11430,7 +11852,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11430
11852
|
if (requestBody) {
|
|
11431
11853
|
conversationId = requestBody.conversationId;
|
|
11432
11854
|
if (!conversationId) {
|
|
11433
|
-
|
|
11855
|
+
logger27.debug({ requestBody }, "No conversation ID found in request body");
|
|
11434
11856
|
}
|
|
11435
11857
|
}
|
|
11436
11858
|
const entries = Object.fromEntries(
|
|
@@ -11445,7 +11867,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11445
11867
|
})
|
|
11446
11868
|
);
|
|
11447
11869
|
if (!Object.keys(entries).length) {
|
|
11448
|
-
|
|
11870
|
+
logger27.debug({}, "Empty entries for baggage");
|
|
11449
11871
|
return next();
|
|
11450
11872
|
}
|
|
11451
11873
|
const bag = Object.entries(entries).reduce(
|