@inkeep/agents-run-api 0.17.0 → 0.18.1
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 → LocalSandboxExecutor-2UQ32ZZH.js} +130 -12
- package/dist/{chunk-5GUNCN5X.js → chunk-DQQRVSJS.js} +10 -8
- package/dist/{conversations-6HJ4FX5F.js → conversations-JSORLLWS.js} +1 -1
- package/dist/index.cjs +812 -590
- package/dist/index.js +655 -553
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -198,8 +198,8 @@ async function saveA2AMessageResponse(response, params) {
|
|
|
198
198
|
},
|
|
199
199
|
visibility: params.visibility,
|
|
200
200
|
messageType: params.messageType,
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
fromSubAgentId: params.fromSubAgentId,
|
|
202
|
+
toSubAgentId: params.toSubAgentId,
|
|
203
203
|
fromExternalAgentId: params.fromExternalAgentId,
|
|
204
204
|
toExternalAgentId: params.toExternalAgentId,
|
|
205
205
|
a2aTaskId: params.a2aTaskId,
|
|
@@ -220,23 +220,23 @@ async function getScopedHistory({
|
|
|
220
220
|
conversationId,
|
|
221
221
|
options
|
|
222
222
|
});
|
|
223
|
-
if (!filters || !filters.
|
|
223
|
+
if (!filters || !filters.subAgentId && !filters.taskId) {
|
|
224
224
|
return messages;
|
|
225
225
|
}
|
|
226
226
|
const relevantMessages = messages.filter((msg) => {
|
|
227
227
|
if (msg.role === "user") return true;
|
|
228
228
|
let matchesAgent = true;
|
|
229
229
|
let matchesTask = true;
|
|
230
|
-
if (filters.
|
|
231
|
-
matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toAgentId === filters.
|
|
230
|
+
if (filters.subAgentId) {
|
|
231
|
+
matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toAgentId === filters.subAgentId || msg.fromAgentId === filters.subAgentId;
|
|
232
232
|
}
|
|
233
233
|
if (filters.taskId) {
|
|
234
234
|
matchesTask = msg.taskId === filters.taskId || msg.a2aTaskId === filters.taskId;
|
|
235
235
|
}
|
|
236
|
-
if (filters.
|
|
236
|
+
if (filters.subAgentId && filters.taskId) {
|
|
237
237
|
return matchesAgent && matchesTask;
|
|
238
238
|
}
|
|
239
|
-
if (filters.
|
|
239
|
+
if (filters.subAgentId) {
|
|
240
240
|
return matchesAgent;
|
|
241
241
|
}
|
|
242
242
|
if (filters.taskId) {
|
|
@@ -337,7 +337,9 @@ async function getConversationScopedArtifacts(params) {
|
|
|
337
337
|
if (visibleMessages.length === 0) {
|
|
338
338
|
return [];
|
|
339
339
|
}
|
|
340
|
-
const visibleMessageIds = visibleMessages.filter(
|
|
340
|
+
const visibleMessageIds = visibleMessages.filter(
|
|
341
|
+
(msg) => !(msg.messageType === "system" && msg.content?.text?.includes("Previous conversation history truncated"))
|
|
342
|
+
).map((msg) => msg.id);
|
|
341
343
|
if (visibleMessageIds.length === 0) {
|
|
342
344
|
return [];
|
|
343
345
|
}
|
|
@@ -352,8 +354,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
352
354
|
});
|
|
353
355
|
referenceArtifacts.push(...artifacts);
|
|
354
356
|
}
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
+
const logger27 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
358
|
+
logger27.debug(
|
|
357
359
|
{
|
|
358
360
|
conversationId,
|
|
359
361
|
visibleMessages: visibleMessages.length,
|
|
@@ -365,8 +367,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
365
367
|
);
|
|
366
368
|
return referenceArtifacts;
|
|
367
369
|
} catch (error) {
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
+
const logger27 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
371
|
+
logger27.error(
|
|
370
372
|
{
|
|
371
373
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
372
374
|
conversationId
|
|
@@ -387,10 +389,62 @@ var LocalSandboxExecutor_exports = {};
|
|
|
387
389
|
__export(LocalSandboxExecutor_exports, {
|
|
388
390
|
LocalSandboxExecutor: () => LocalSandboxExecutor
|
|
389
391
|
});
|
|
390
|
-
var
|
|
392
|
+
var logger17, ExecutionSemaphore, _LocalSandboxExecutor, LocalSandboxExecutor;
|
|
391
393
|
var init_LocalSandboxExecutor = __esm({
|
|
392
394
|
"src/tools/LocalSandboxExecutor.ts"() {
|
|
393
|
-
|
|
395
|
+
logger17 = agentsCore.getLogger("local-sandbox-executor");
|
|
396
|
+
ExecutionSemaphore = class {
|
|
397
|
+
constructor(permits, maxWaitTimeMs = 3e4) {
|
|
398
|
+
__publicField(this, "permits");
|
|
399
|
+
__publicField(this, "waitQueue", []);
|
|
400
|
+
__publicField(this, "maxWaitTime");
|
|
401
|
+
this.permits = Math.max(1, permits);
|
|
402
|
+
this.maxWaitTime = maxWaitTimeMs;
|
|
403
|
+
}
|
|
404
|
+
async acquire(fn) {
|
|
405
|
+
await new Promise((resolve, reject) => {
|
|
406
|
+
if (this.permits > 0) {
|
|
407
|
+
this.permits--;
|
|
408
|
+
resolve();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const timeoutId = setTimeout(() => {
|
|
412
|
+
const index = this.waitQueue.findIndex((item) => item.resolve === resolve);
|
|
413
|
+
if (index !== -1) {
|
|
414
|
+
this.waitQueue.splice(index, 1);
|
|
415
|
+
reject(
|
|
416
|
+
new Error(
|
|
417
|
+
`Function execution queue timeout after ${this.maxWaitTime}ms. Too many concurrent executions.`
|
|
418
|
+
)
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
}, this.maxWaitTime);
|
|
422
|
+
this.waitQueue.push({
|
|
423
|
+
resolve: () => {
|
|
424
|
+
clearTimeout(timeoutId);
|
|
425
|
+
this.permits--;
|
|
426
|
+
resolve();
|
|
427
|
+
},
|
|
428
|
+
reject
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
try {
|
|
432
|
+
return await fn();
|
|
433
|
+
} finally {
|
|
434
|
+
this.permits++;
|
|
435
|
+
const next = this.waitQueue.shift();
|
|
436
|
+
if (next) {
|
|
437
|
+
next.resolve();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
getAvailablePermits() {
|
|
442
|
+
return this.permits;
|
|
443
|
+
}
|
|
444
|
+
getQueueLength() {
|
|
445
|
+
return this.waitQueue.length;
|
|
446
|
+
}
|
|
447
|
+
};
|
|
394
448
|
_LocalSandboxExecutor = class _LocalSandboxExecutor {
|
|
395
449
|
constructor() {
|
|
396
450
|
__publicField(this, "tempDir");
|
|
@@ -398,6 +452,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
398
452
|
__publicField(this, "POOL_TTL", 5 * 60 * 1e3);
|
|
399
453
|
// 5 minutes
|
|
400
454
|
__publicField(this, "MAX_USE_COUNT", 50);
|
|
455
|
+
__publicField(this, "executionSemaphores", /* @__PURE__ */ new Map());
|
|
401
456
|
this.tempDir = path.join(os.tmpdir(), "inkeep-sandboxes");
|
|
402
457
|
this.ensureTempDir();
|
|
403
458
|
this.startPoolCleanup();
|
|
@@ -408,6 +463,34 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
408
463
|
}
|
|
409
464
|
return _LocalSandboxExecutor.instance;
|
|
410
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* Get or create a semaphore for the specified vCPU limit
|
|
468
|
+
*/
|
|
469
|
+
getSemaphore(vcpus) {
|
|
470
|
+
const effectiveVcpus = Math.max(1, vcpus || 1);
|
|
471
|
+
if (!this.executionSemaphores.has(effectiveVcpus)) {
|
|
472
|
+
logger17.debug({ vcpus: effectiveVcpus }, "Creating new execution semaphore");
|
|
473
|
+
this.executionSemaphores.set(effectiveVcpus, new ExecutionSemaphore(effectiveVcpus));
|
|
474
|
+
}
|
|
475
|
+
const semaphore = this.executionSemaphores.get(effectiveVcpus);
|
|
476
|
+
if (!semaphore) {
|
|
477
|
+
throw new Error(`Failed to create semaphore for ${effectiveVcpus} vCPUs`);
|
|
478
|
+
}
|
|
479
|
+
return semaphore;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Get execution statistics for monitoring and debugging
|
|
483
|
+
*/
|
|
484
|
+
getExecutionStats() {
|
|
485
|
+
const stats = {};
|
|
486
|
+
for (const [vcpus, semaphore] of this.executionSemaphores.entries()) {
|
|
487
|
+
stats[`vcpu_${vcpus}`] = {
|
|
488
|
+
availablePermits: semaphore.getAvailablePermits(),
|
|
489
|
+
queueLength: semaphore.getQueueLength()
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
return stats;
|
|
493
|
+
}
|
|
411
494
|
ensureTempDir() {
|
|
412
495
|
try {
|
|
413
496
|
fs.mkdirSync(this.tempDir, { recursive: true });
|
|
@@ -426,7 +509,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
426
509
|
if (now - sandbox.lastUsed < this.POOL_TTL && sandbox.useCount < this.MAX_USE_COUNT) {
|
|
427
510
|
sandbox.lastUsed = now;
|
|
428
511
|
sandbox.useCount++;
|
|
429
|
-
|
|
512
|
+
logger17.debug(
|
|
430
513
|
{
|
|
431
514
|
poolKey,
|
|
432
515
|
useCount: sandbox.useCount,
|
|
@@ -454,14 +537,14 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
454
537
|
useCount: 1,
|
|
455
538
|
dependencies
|
|
456
539
|
};
|
|
457
|
-
|
|
540
|
+
logger17.debug({ poolKey, sandboxDir }, "Added sandbox to pool");
|
|
458
541
|
}
|
|
459
542
|
cleanupSandbox(sandboxDir) {
|
|
460
543
|
try {
|
|
461
544
|
fs.rmSync(sandboxDir, { recursive: true, force: true });
|
|
462
|
-
|
|
545
|
+
logger17.debug({ sandboxDir }, "Cleaned up sandbox");
|
|
463
546
|
} catch (error) {
|
|
464
|
-
|
|
547
|
+
logger17.warn({ sandboxDir, error }, "Failed to clean up sandbox");
|
|
465
548
|
}
|
|
466
549
|
}
|
|
467
550
|
startPoolCleanup() {
|
|
@@ -478,11 +561,11 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
478
561
|
delete this.sandboxPool[key];
|
|
479
562
|
});
|
|
480
563
|
if (keysToDelete.length > 0) {
|
|
481
|
-
|
|
564
|
+
logger17.debug({ cleanedCount: keysToDelete.length }, "Cleaned up expired sandboxes");
|
|
482
565
|
}
|
|
483
566
|
}, 6e4);
|
|
484
567
|
}
|
|
485
|
-
detectModuleType(executeCode) {
|
|
568
|
+
detectModuleType(executeCode, configuredRuntime) {
|
|
486
569
|
const esmPatterns = [
|
|
487
570
|
/import\s+.*\s+from\s+['"]/g,
|
|
488
571
|
// import ... from '...'
|
|
@@ -503,8 +586,11 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
503
586
|
];
|
|
504
587
|
const hasEsmSyntax = esmPatterns.some((pattern) => pattern.test(executeCode));
|
|
505
588
|
const hasCjsSyntax = cjsPatterns.some((pattern) => pattern.test(executeCode));
|
|
589
|
+
if (configuredRuntime === "typescript") {
|
|
590
|
+
return hasCjsSyntax ? "cjs" : "esm";
|
|
591
|
+
}
|
|
506
592
|
if (hasEsmSyntax && hasCjsSyntax) {
|
|
507
|
-
|
|
593
|
+
logger17.warn(
|
|
508
594
|
{ executeCode: `${executeCode.substring(0, 100)}...` },
|
|
509
595
|
"Both ESM and CommonJS syntax detected, defaulting to ESM"
|
|
510
596
|
);
|
|
@@ -519,13 +605,32 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
519
605
|
return "cjs";
|
|
520
606
|
}
|
|
521
607
|
async executeFunctionTool(toolId, args, config) {
|
|
608
|
+
const vcpus = config.sandboxConfig?.vcpus || 1;
|
|
609
|
+
const semaphore = this.getSemaphore(vcpus);
|
|
610
|
+
logger17.debug(
|
|
611
|
+
{
|
|
612
|
+
toolId,
|
|
613
|
+
vcpus,
|
|
614
|
+
availablePermits: semaphore.getAvailablePermits(),
|
|
615
|
+
queueLength: semaphore.getQueueLength(),
|
|
616
|
+
sandboxConfig: config.sandboxConfig,
|
|
617
|
+
poolSize: Object.keys(this.sandboxPool).length
|
|
618
|
+
},
|
|
619
|
+
"Acquiring execution slot for function tool"
|
|
620
|
+
);
|
|
621
|
+
return semaphore.acquire(async () => {
|
|
622
|
+
return this.executeInSandbox_Internal(toolId, args, config);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
async executeInSandbox_Internal(toolId, args, config) {
|
|
522
626
|
const dependencies = config.dependencies || {};
|
|
523
627
|
const dependencyHash = this.generateDependencyHash(dependencies);
|
|
524
|
-
|
|
628
|
+
logger17.debug(
|
|
525
629
|
{
|
|
526
630
|
toolId,
|
|
527
631
|
dependencies,
|
|
528
632
|
dependencyHash,
|
|
633
|
+
sandboxConfig: config.sandboxConfig,
|
|
529
634
|
poolSize: Object.keys(this.sandboxPool).length
|
|
530
635
|
},
|
|
531
636
|
"Executing function tool"
|
|
@@ -536,7 +641,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
536
641
|
sandboxDir = path.join(this.tempDir, `sandbox-${dependencyHash}-${Date.now()}`);
|
|
537
642
|
fs.mkdirSync(sandboxDir, { recursive: true });
|
|
538
643
|
isNewSandbox = true;
|
|
539
|
-
|
|
644
|
+
logger17.debug(
|
|
540
645
|
{
|
|
541
646
|
toolId,
|
|
542
647
|
dependencyHash,
|
|
@@ -545,7 +650,7 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
545
650
|
},
|
|
546
651
|
"Creating new sandbox"
|
|
547
652
|
);
|
|
548
|
-
const moduleType = this.detectModuleType(config.executeCode);
|
|
653
|
+
const moduleType = this.detectModuleType(config.executeCode, config.sandboxConfig?.runtime);
|
|
549
654
|
const packageJson = {
|
|
550
655
|
name: `function-tool-${toolId}`,
|
|
551
656
|
version: "1.0.0",
|
|
@@ -562,14 +667,15 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
562
667
|
this.addToPool(dependencyHash, sandboxDir, dependencies);
|
|
563
668
|
}
|
|
564
669
|
try {
|
|
565
|
-
const moduleType = this.detectModuleType(config.executeCode);
|
|
670
|
+
const moduleType = this.detectModuleType(config.executeCode, config.sandboxConfig?.runtime);
|
|
566
671
|
const executionCode = this.wrapFunctionCode(config.executeCode, args);
|
|
567
672
|
const fileExtension = moduleType === "esm" ? "mjs" : "js";
|
|
568
673
|
fs.writeFileSync(path.join(sandboxDir, `index.${fileExtension}`), executionCode, "utf8");
|
|
569
674
|
const result = await this.executeInSandbox(
|
|
570
675
|
sandboxDir,
|
|
571
676
|
config.sandboxConfig?.timeout || 3e4,
|
|
572
|
-
moduleType
|
|
677
|
+
moduleType,
|
|
678
|
+
config.sandboxConfig
|
|
573
679
|
);
|
|
574
680
|
return result;
|
|
575
681
|
} catch (error) {
|
|
@@ -595,20 +701,20 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
595
701
|
});
|
|
596
702
|
npm.on("close", (code) => {
|
|
597
703
|
if (code === 0) {
|
|
598
|
-
|
|
704
|
+
logger17.debug({ sandboxDir }, "Dependencies installed successfully");
|
|
599
705
|
resolve();
|
|
600
706
|
} else {
|
|
601
|
-
|
|
707
|
+
logger17.error({ sandboxDir, code, stderr }, "Failed to install dependencies");
|
|
602
708
|
reject(new Error(`npm install failed with code ${code}: ${stderr}`));
|
|
603
709
|
}
|
|
604
710
|
});
|
|
605
711
|
npm.on("error", (err) => {
|
|
606
|
-
|
|
712
|
+
logger17.error({ sandboxDir, error: err }, "Failed to spawn npm install");
|
|
607
713
|
reject(err);
|
|
608
714
|
});
|
|
609
715
|
});
|
|
610
716
|
}
|
|
611
|
-
async executeInSandbox(sandboxDir, timeout, moduleType) {
|
|
717
|
+
async executeInSandbox(sandboxDir, timeout, moduleType, _sandboxConfig) {
|
|
612
718
|
return new Promise((resolve, reject) => {
|
|
613
719
|
const fileExtension = moduleType === "esm" ? "mjs" : "js";
|
|
614
720
|
const spawnOptions = {
|
|
@@ -644,14 +750,15 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
644
750
|
stderr += dataStr;
|
|
645
751
|
});
|
|
646
752
|
const timeoutId = setTimeout(() => {
|
|
647
|
-
|
|
753
|
+
logger17.warn({ sandboxDir, timeout }, "Function execution timed out, killing process");
|
|
648
754
|
node.kill("SIGTERM");
|
|
755
|
+
const forceKillTimeout = Math.min(Math.max(timeout / 10, 2e3), 5e3);
|
|
649
756
|
setTimeout(() => {
|
|
650
757
|
try {
|
|
651
758
|
node.kill("SIGKILL");
|
|
652
759
|
} catch {
|
|
653
760
|
}
|
|
654
|
-
},
|
|
761
|
+
}, forceKillTimeout);
|
|
655
762
|
reject(new Error(`Function execution timed out after ${timeout}ms`));
|
|
656
763
|
}, timeout);
|
|
657
764
|
node.on("close", (code, signal) => {
|
|
@@ -665,18 +772,18 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
665
772
|
reject(new Error(result.error || "Function execution failed"));
|
|
666
773
|
}
|
|
667
774
|
} catch (parseError) {
|
|
668
|
-
|
|
775
|
+
logger17.error({ stdout, stderr, parseError }, "Failed to parse function result");
|
|
669
776
|
reject(new Error(`Invalid function result: ${stdout}`));
|
|
670
777
|
}
|
|
671
778
|
} else {
|
|
672
779
|
const errorMsg = signal ? `Function execution killed by signal ${signal}: ${stderr}` : `Function execution failed with code ${code}: ${stderr}`;
|
|
673
|
-
|
|
780
|
+
logger17.error({ code, signal, stderr }, "Function execution failed");
|
|
674
781
|
reject(new Error(errorMsg));
|
|
675
782
|
}
|
|
676
783
|
});
|
|
677
784
|
node.on("error", (error) => {
|
|
678
785
|
clearTimeout(timeoutId);
|
|
679
|
-
|
|
786
|
+
logger17.error({ sandboxDir, error }, "Failed to spawn node process");
|
|
680
787
|
reject(error);
|
|
681
788
|
});
|
|
682
789
|
});
|
|
@@ -687,13 +794,26 @@ var init_LocalSandboxExecutor = __esm({
|
|
|
687
794
|
const execute = ${executeCode};
|
|
688
795
|
const args = ${JSON.stringify(args)};
|
|
689
796
|
|
|
690
|
-
|
|
691
|
-
|
|
797
|
+
try {
|
|
798
|
+
const result = execute(args);
|
|
799
|
+
|
|
800
|
+
// Handle both sync and async functions
|
|
801
|
+
if (result && typeof result.then === 'function') {
|
|
802
|
+
// Async function - result is a Promise
|
|
803
|
+
result
|
|
804
|
+
.then(result => {
|
|
805
|
+
console.log(JSON.stringify({ success: true, result }));
|
|
806
|
+
})
|
|
807
|
+
.catch(error => {
|
|
808
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
809
|
+
});
|
|
810
|
+
} else {
|
|
811
|
+
// Sync function - result is immediate
|
|
692
812
|
console.log(JSON.stringify({ success: true, result }));
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
813
|
+
}
|
|
814
|
+
} catch (error) {
|
|
815
|
+
console.log(JSON.stringify({ success: false, error: error.message }));
|
|
816
|
+
}
|
|
697
817
|
`;
|
|
698
818
|
}
|
|
699
819
|
};
|
|
@@ -807,7 +927,7 @@ function createExecutionContext(params) {
|
|
|
807
927
|
graphId: params.graphId,
|
|
808
928
|
baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
|
|
809
929
|
apiKeyId: params.apiKeyId,
|
|
810
|
-
|
|
930
|
+
subAgentId: params.subAgentId
|
|
811
931
|
};
|
|
812
932
|
}
|
|
813
933
|
|
|
@@ -822,7 +942,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
822
942
|
const tenantId = c.req.header("x-inkeep-tenant-id");
|
|
823
943
|
const projectId = c.req.header("x-inkeep-project-id");
|
|
824
944
|
const graphId = c.req.header("x-inkeep-graph-id");
|
|
825
|
-
const
|
|
945
|
+
const subAgentId = c.req.header("x-inkeep-agent-id");
|
|
826
946
|
const proto = c.req.header("x-forwarded-proto")?.split(",")[0].trim();
|
|
827
947
|
const fwdHost = c.req.header("x-forwarded-host")?.split(",")[0].trim();
|
|
828
948
|
const host = fwdHost ?? c.req.header("host");
|
|
@@ -833,7 +953,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
833
953
|
if (authHeader?.startsWith("Bearer ")) {
|
|
834
954
|
try {
|
|
835
955
|
executionContext = await extractContextFromApiKey(authHeader.substring(7), baseUrl);
|
|
836
|
-
executionContext.
|
|
956
|
+
executionContext.subAgentId = subAgentId;
|
|
837
957
|
logger2.info({}, "Development/test environment - API key authenticated successfully");
|
|
838
958
|
} catch {
|
|
839
959
|
executionContext = createExecutionContext({
|
|
@@ -843,7 +963,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
843
963
|
graphId: graphId || "test-graph",
|
|
844
964
|
apiKeyId: "test-key",
|
|
845
965
|
baseUrl,
|
|
846
|
-
|
|
966
|
+
subAgentId
|
|
847
967
|
});
|
|
848
968
|
logger2.info(
|
|
849
969
|
{},
|
|
@@ -858,7 +978,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
858
978
|
graphId: graphId || "test-graph",
|
|
859
979
|
apiKeyId: "test-key",
|
|
860
980
|
baseUrl,
|
|
861
|
-
|
|
981
|
+
subAgentId
|
|
862
982
|
});
|
|
863
983
|
logger2.info(
|
|
864
984
|
{},
|
|
@@ -889,7 +1009,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
889
1009
|
graphId,
|
|
890
1010
|
apiKeyId: "bypass",
|
|
891
1011
|
baseUrl,
|
|
892
|
-
|
|
1012
|
+
subAgentId
|
|
893
1013
|
});
|
|
894
1014
|
c.set("executionContext", executionContext);
|
|
895
1015
|
logger2.info({}, "Bypass secret authenticated successfully");
|
|
@@ -897,7 +1017,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
897
1017
|
return;
|
|
898
1018
|
} else if (apiKey) {
|
|
899
1019
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
900
|
-
executionContext.
|
|
1020
|
+
executionContext.subAgentId = subAgentId;
|
|
901
1021
|
c.set("executionContext", executionContext);
|
|
902
1022
|
logger2.info({}, "API key authenticated successfully");
|
|
903
1023
|
await next();
|
|
@@ -915,14 +1035,14 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
915
1035
|
}
|
|
916
1036
|
try {
|
|
917
1037
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
918
|
-
executionContext.
|
|
1038
|
+
executionContext.subAgentId = subAgentId;
|
|
919
1039
|
c.set("executionContext", executionContext);
|
|
920
1040
|
logger2.debug(
|
|
921
1041
|
{
|
|
922
1042
|
tenantId: executionContext.tenantId,
|
|
923
1043
|
projectId: executionContext.projectId,
|
|
924
1044
|
graphId: executionContext.graphId,
|
|
925
|
-
|
|
1045
|
+
subAgentId: executionContext.subAgentId
|
|
926
1046
|
},
|
|
927
1047
|
"API key authenticated successfully"
|
|
928
1048
|
);
|
|
@@ -1097,7 +1217,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1097
1217
|
logger3.warn(
|
|
1098
1218
|
{
|
|
1099
1219
|
taskId: task.id,
|
|
1100
|
-
|
|
1220
|
+
subAgentId: agent.subAgentId,
|
|
1101
1221
|
originalMessage: params.message
|
|
1102
1222
|
},
|
|
1103
1223
|
"Created fallback message content for empty delegation message"
|
|
@@ -1118,7 +1238,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1118
1238
|
taskContextId: task.context?.conversationId,
|
|
1119
1239
|
metadataContextId: params.message.metadata?.conversationId,
|
|
1120
1240
|
finalContextId: effectiveContextId,
|
|
1121
|
-
|
|
1241
|
+
subAgentId: agent.subAgentId
|
|
1122
1242
|
},
|
|
1123
1243
|
"A2A contextId resolution for delegation"
|
|
1124
1244
|
);
|
|
@@ -1134,11 +1254,11 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1134
1254
|
message_id: params.message.messageId || "",
|
|
1135
1255
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1136
1256
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1137
|
-
agent_id: agent.
|
|
1257
|
+
agent_id: agent.subAgentId,
|
|
1138
1258
|
graph_id: graphId || "",
|
|
1139
1259
|
stream_request_id: params.message.metadata?.stream_request_id
|
|
1140
1260
|
},
|
|
1141
|
-
|
|
1261
|
+
subAgentId: agent.subAgentId,
|
|
1142
1262
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1143
1263
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1144
1264
|
});
|
|
@@ -1161,17 +1281,17 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1161
1281
|
};
|
|
1162
1282
|
if (params.message.metadata?.fromAgentId) {
|
|
1163
1283
|
messageData.fromAgentId = params.message.metadata.fromAgentId;
|
|
1164
|
-
messageData.toAgentId = agent.
|
|
1284
|
+
messageData.toAgentId = agent.subAgentId;
|
|
1165
1285
|
} else if (params.message.metadata?.fromExternalAgentId) {
|
|
1166
1286
|
messageData.fromExternalAgentId = params.message.metadata.fromExternalAgentId;
|
|
1167
|
-
messageData.toAgentId = agent.
|
|
1287
|
+
messageData.toAgentId = agent.subAgentId;
|
|
1168
1288
|
}
|
|
1169
1289
|
await agentsCore.createMessage(dbClient_default)(messageData);
|
|
1170
1290
|
logger3.info(
|
|
1171
1291
|
{
|
|
1172
1292
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
1173
1293
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
1174
|
-
toAgentId: agent.
|
|
1294
|
+
toAgentId: agent.subAgentId,
|
|
1175
1295
|
conversationId: effectiveContextId,
|
|
1176
1296
|
messageType: "a2a-request",
|
|
1177
1297
|
taskId: task.id
|
|
@@ -1184,7 +1304,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1184
1304
|
error,
|
|
1185
1305
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
1186
1306
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
1187
|
-
toAgentId: agent.
|
|
1307
|
+
toAgentId: agent.subAgentId,
|
|
1188
1308
|
conversationId: effectiveContextId
|
|
1189
1309
|
},
|
|
1190
1310
|
"Failed to store A2A message in database"
|
|
@@ -1201,7 +1321,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1201
1321
|
message_id: params.message.messageId || "",
|
|
1202
1322
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1203
1323
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1204
|
-
agent_id: agent.
|
|
1324
|
+
agent_id: agent.subAgentId,
|
|
1205
1325
|
graph_id: graphId || ""
|
|
1206
1326
|
}
|
|
1207
1327
|
}
|
|
@@ -1235,7 +1355,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1235
1355
|
kind: "data",
|
|
1236
1356
|
data: {
|
|
1237
1357
|
type: "transfer",
|
|
1238
|
-
|
|
1358
|
+
targetSubAgentId: transferPart.data.target
|
|
1239
1359
|
}
|
|
1240
1360
|
},
|
|
1241
1361
|
{
|
|
@@ -1535,7 +1655,7 @@ async function handleGetCapabilities(c, agent, request) {
|
|
|
1535
1655
|
async function handleGetStatus(c, agent, request) {
|
|
1536
1656
|
return c.json({
|
|
1537
1657
|
jsonrpc: "2.0",
|
|
1538
|
-
result: { status: "ready",
|
|
1658
|
+
result: { status: "ready", subAgentId: agent.subAgentId },
|
|
1539
1659
|
id: request.id
|
|
1540
1660
|
});
|
|
1541
1661
|
}
|
|
@@ -1599,7 +1719,6 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
1599
1719
|
}
|
|
1600
1720
|
}
|
|
1601
1721
|
init_dbClient();
|
|
1602
|
-
agentsCore.getLogger("agents");
|
|
1603
1722
|
function createAgentCard({
|
|
1604
1723
|
dbAgent,
|
|
1605
1724
|
baseUrl
|
|
@@ -1677,7 +1796,7 @@ async function hydrateAgent({
|
|
|
1677
1796
|
tenantId: dbAgent.tenantId,
|
|
1678
1797
|
projectId: dbAgent.projectId,
|
|
1679
1798
|
graphId,
|
|
1680
|
-
|
|
1799
|
+
subAgentId: dbAgent.id,
|
|
1681
1800
|
baseUrl,
|
|
1682
1801
|
apiKey
|
|
1683
1802
|
});
|
|
@@ -1687,7 +1806,7 @@ async function hydrateAgent({
|
|
|
1687
1806
|
baseUrl
|
|
1688
1807
|
});
|
|
1689
1808
|
return {
|
|
1690
|
-
|
|
1809
|
+
subAgentId: dbAgent.id,
|
|
1691
1810
|
tenantId: dbAgent.tenantId,
|
|
1692
1811
|
projectId: dbAgent.projectId,
|
|
1693
1812
|
graphId,
|
|
@@ -1700,13 +1819,13 @@ async function hydrateAgent({
|
|
|
1700
1819
|
}
|
|
1701
1820
|
}
|
|
1702
1821
|
async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
1703
|
-
const { tenantId, projectId, graphId,
|
|
1704
|
-
if (!
|
|
1822
|
+
const { tenantId, projectId, graphId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
1823
|
+
if (!subAgentId) {
|
|
1705
1824
|
throw new Error("Agent ID is required");
|
|
1706
1825
|
}
|
|
1707
|
-
const dbAgent = await agentsCore.
|
|
1826
|
+
const dbAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
1708
1827
|
scopes: { tenantId, projectId, graphId },
|
|
1709
|
-
|
|
1828
|
+
subAgentId
|
|
1710
1829
|
});
|
|
1711
1830
|
if (!dbAgent) {
|
|
1712
1831
|
return null;
|
|
@@ -1727,7 +1846,7 @@ init_logger();
|
|
|
1727
1846
|
|
|
1728
1847
|
// src/agents/ModelFactory.ts
|
|
1729
1848
|
init_logger();
|
|
1730
|
-
var
|
|
1849
|
+
var logger4 = agentsCore.getLogger("ModelFactory");
|
|
1731
1850
|
var _ModelFactory = class _ModelFactory {
|
|
1732
1851
|
/**
|
|
1733
1852
|
* Create a provider instance with custom configuration
|
|
@@ -1789,7 +1908,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1789
1908
|
}
|
|
1790
1909
|
const modelString = modelSettings.model.trim();
|
|
1791
1910
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1792
|
-
|
|
1911
|
+
logger4.debug(
|
|
1793
1912
|
{
|
|
1794
1913
|
provider,
|
|
1795
1914
|
model: modelName,
|
|
@@ -1800,7 +1919,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1800
1919
|
);
|
|
1801
1920
|
const providerConfig = _ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
1802
1921
|
if (Object.keys(providerConfig).length > 0) {
|
|
1803
|
-
|
|
1922
|
+
logger4.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
1804
1923
|
const customProvider = _ModelFactory.createProvider(provider, providerConfig);
|
|
1805
1924
|
return customProvider.languageModel(modelName);
|
|
1806
1925
|
}
|
|
@@ -1919,7 +2038,7 @@ var ModelFactory = _ModelFactory;
|
|
|
1919
2038
|
|
|
1920
2039
|
// src/agents/ToolSessionManager.ts
|
|
1921
2040
|
init_logger();
|
|
1922
|
-
var
|
|
2041
|
+
var logger5 = agentsCore.getLogger("ToolSessionManager");
|
|
1923
2042
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
1924
2043
|
// 5 minutes
|
|
1925
2044
|
constructor() {
|
|
@@ -1954,7 +2073,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1954
2073
|
createdAt: Date.now()
|
|
1955
2074
|
};
|
|
1956
2075
|
this.sessions.set(sessionId, session);
|
|
1957
|
-
|
|
2076
|
+
logger5.debug(
|
|
1958
2077
|
{
|
|
1959
2078
|
sessionId,
|
|
1960
2079
|
tenantId,
|
|
@@ -1972,10 +2091,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1972
2091
|
*/
|
|
1973
2092
|
ensureGraphSession(sessionId, tenantId, projectId, contextId, taskId) {
|
|
1974
2093
|
if (this.sessions.has(sessionId)) {
|
|
1975
|
-
|
|
2094
|
+
logger5.debug({ sessionId }, "Graph session already exists, reusing");
|
|
1976
2095
|
return sessionId;
|
|
1977
2096
|
}
|
|
1978
|
-
|
|
2097
|
+
logger5.debug(
|
|
1979
2098
|
{ sessionId, tenantId, contextId, taskId },
|
|
1980
2099
|
"Creating new graph-scoped tool session"
|
|
1981
2100
|
);
|
|
@@ -1987,7 +2106,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1987
2106
|
recordToolResult(sessionId, toolResult) {
|
|
1988
2107
|
const session = this.sessions.get(sessionId);
|
|
1989
2108
|
if (!session) {
|
|
1990
|
-
|
|
2109
|
+
logger5.warn(
|
|
1991
2110
|
{
|
|
1992
2111
|
sessionId,
|
|
1993
2112
|
toolCallId: toolResult.toolCallId,
|
|
@@ -1999,7 +2118,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1999
2118
|
return;
|
|
2000
2119
|
}
|
|
2001
2120
|
session.toolResults.set(toolResult.toolCallId, toolResult);
|
|
2002
|
-
|
|
2121
|
+
logger5.debug(
|
|
2003
2122
|
{
|
|
2004
2123
|
sessionId,
|
|
2005
2124
|
toolCallId: toolResult.toolCallId,
|
|
@@ -2014,7 +2133,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2014
2133
|
getToolResult(sessionId, toolCallId) {
|
|
2015
2134
|
const session = this.sessions.get(sessionId);
|
|
2016
2135
|
if (!session) {
|
|
2017
|
-
|
|
2136
|
+
logger5.warn(
|
|
2018
2137
|
{
|
|
2019
2138
|
sessionId,
|
|
2020
2139
|
toolCallId,
|
|
@@ -2027,7 +2146,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2027
2146
|
}
|
|
2028
2147
|
const result = session.toolResults.get(toolCallId);
|
|
2029
2148
|
if (!result) {
|
|
2030
|
-
|
|
2149
|
+
logger5.warn(
|
|
2031
2150
|
{
|
|
2032
2151
|
sessionId,
|
|
2033
2152
|
toolCallId,
|
|
@@ -2037,7 +2156,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2037
2156
|
"Tool result not found"
|
|
2038
2157
|
);
|
|
2039
2158
|
} else {
|
|
2040
|
-
|
|
2159
|
+
logger5.debug(
|
|
2041
2160
|
{
|
|
2042
2161
|
sessionId,
|
|
2043
2162
|
toolCallId,
|
|
@@ -2076,10 +2195,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
2076
2195
|
}
|
|
2077
2196
|
for (const sessionId of expiredSessions) {
|
|
2078
2197
|
this.sessions.delete(sessionId);
|
|
2079
|
-
|
|
2198
|
+
logger5.debug({ sessionId }, "Cleaned up expired tool session");
|
|
2080
2199
|
}
|
|
2081
2200
|
if (expiredSessions.length > 0) {
|
|
2082
|
-
|
|
2201
|
+
logger5.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
2083
2202
|
}
|
|
2084
2203
|
}
|
|
2085
2204
|
};
|
|
@@ -2162,7 +2281,7 @@ function extractFullFields(schema) {
|
|
|
2162
2281
|
}
|
|
2163
2282
|
|
|
2164
2283
|
// src/services/ArtifactService.ts
|
|
2165
|
-
var
|
|
2284
|
+
var logger7 = agentsCore.getLogger("ArtifactService");
|
|
2166
2285
|
var _ArtifactService = class _ArtifactService {
|
|
2167
2286
|
constructor(context) {
|
|
2168
2287
|
this.context = context;
|
|
@@ -2194,7 +2313,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2194
2313
|
id: taskId
|
|
2195
2314
|
});
|
|
2196
2315
|
if (!task) {
|
|
2197
|
-
|
|
2316
|
+
logger7.warn({ taskId }, "Task not found when fetching artifacts");
|
|
2198
2317
|
continue;
|
|
2199
2318
|
}
|
|
2200
2319
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2212,21 +2331,21 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2212
2331
|
}
|
|
2213
2332
|
}
|
|
2214
2333
|
} catch (error) {
|
|
2215
|
-
|
|
2334
|
+
logger7.error({ error, contextId }, "Error loading context artifacts");
|
|
2216
2335
|
}
|
|
2217
2336
|
return artifacts;
|
|
2218
2337
|
}
|
|
2219
2338
|
/**
|
|
2220
2339
|
* Create artifact from tool result and request data
|
|
2221
2340
|
*/
|
|
2222
|
-
async createArtifact(request,
|
|
2341
|
+
async createArtifact(request, subAgentId) {
|
|
2223
2342
|
if (!this.context.sessionId) {
|
|
2224
|
-
|
|
2343
|
+
logger7.warn({ request }, "No session ID available for artifact creation");
|
|
2225
2344
|
return null;
|
|
2226
2345
|
}
|
|
2227
2346
|
const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
|
|
2228
2347
|
if (!toolResult) {
|
|
2229
|
-
|
|
2348
|
+
logger7.warn(
|
|
2230
2349
|
{ request, sessionId: this.context.sessionId },
|
|
2231
2350
|
"Tool result not found for artifact"
|
|
2232
2351
|
);
|
|
@@ -2242,7 +2361,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2242
2361
|
selectedData = selectedData.length > 0 ? selectedData[0] : {};
|
|
2243
2362
|
}
|
|
2244
2363
|
if (!selectedData) {
|
|
2245
|
-
|
|
2364
|
+
logger7.warn(
|
|
2246
2365
|
{
|
|
2247
2366
|
request,
|
|
2248
2367
|
baseSelector: request.baseSelector
|
|
@@ -2287,7 +2406,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2287
2406
|
type: request.type,
|
|
2288
2407
|
data: cleanedSummaryData
|
|
2289
2408
|
};
|
|
2290
|
-
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData,
|
|
2409
|
+
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId);
|
|
2291
2410
|
await this.cacheArtifact(
|
|
2292
2411
|
request.artifactId,
|
|
2293
2412
|
request.toolCallId,
|
|
@@ -2296,7 +2415,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2296
2415
|
);
|
|
2297
2416
|
return artifactData;
|
|
2298
2417
|
} catch (error) {
|
|
2299
|
-
|
|
2418
|
+
logger7.error({ error, request }, "Failed to create artifact");
|
|
2300
2419
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
2301
2420
|
throw new Error(`Artifact creation failed for ${request.artifactId}: ${errorMessage}`);
|
|
2302
2421
|
}
|
|
@@ -2325,7 +2444,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2325
2444
|
}
|
|
2326
2445
|
try {
|
|
2327
2446
|
if (!this.context.projectId || !this.context.taskId) {
|
|
2328
|
-
|
|
2447
|
+
logger7.warn(
|
|
2329
2448
|
{ artifactId, toolCallId },
|
|
2330
2449
|
"No projectId or taskId available for artifact lookup"
|
|
2331
2450
|
);
|
|
@@ -2340,7 +2459,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2340
2459
|
return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
|
|
2341
2460
|
}
|
|
2342
2461
|
} catch (error) {
|
|
2343
|
-
|
|
2462
|
+
logger7.warn(
|
|
2344
2463
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
2345
2464
|
"Failed to fetch artifact"
|
|
2346
2465
|
);
|
|
@@ -2371,7 +2490,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2371
2490
|
}
|
|
2372
2491
|
try {
|
|
2373
2492
|
if (!this.context.projectId || !this.context.taskId) {
|
|
2374
|
-
|
|
2493
|
+
logger7.warn(
|
|
2375
2494
|
{ artifactId, toolCallId },
|
|
2376
2495
|
"No projectId or taskId available for artifact lookup"
|
|
2377
2496
|
);
|
|
@@ -2386,7 +2505,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2386
2505
|
return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
|
|
2387
2506
|
}
|
|
2388
2507
|
} catch (error) {
|
|
2389
|
-
|
|
2508
|
+
logger7.warn(
|
|
2390
2509
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
2391
2510
|
"Failed to fetch artifact"
|
|
2392
2511
|
);
|
|
@@ -2422,8 +2541,8 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2422
2541
|
/**
|
|
2423
2542
|
* Persist artifact to database via graph session
|
|
2424
2543
|
*/
|
|
2425
|
-
async persistArtifact(request, summaryData, fullData,
|
|
2426
|
-
const effectiveAgentId =
|
|
2544
|
+
async persistArtifact(request, summaryData, fullData, subAgentId) {
|
|
2545
|
+
const effectiveAgentId = subAgentId || this.context.subAgentId;
|
|
2427
2546
|
if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
|
|
2428
2547
|
await graphSessionManager.recordEvent(
|
|
2429
2548
|
this.context.streamRequestId,
|
|
@@ -2436,7 +2555,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2436
2555
|
artifactType: request.type,
|
|
2437
2556
|
summaryData,
|
|
2438
2557
|
data: fullData,
|
|
2439
|
-
|
|
2558
|
+
subAgentId: effectiveAgentId,
|
|
2440
2559
|
metadata: {
|
|
2441
2560
|
toolCallId: request.toolCallId,
|
|
2442
2561
|
baseSelector: request.baseSelector,
|
|
@@ -2451,14 +2570,14 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2451
2570
|
}
|
|
2452
2571
|
);
|
|
2453
2572
|
} else {
|
|
2454
|
-
|
|
2573
|
+
logger7.warn(
|
|
2455
2574
|
{
|
|
2456
2575
|
artifactId: request.artifactId,
|
|
2457
2576
|
hasStreamRequestId: !!this.context.streamRequestId,
|
|
2458
2577
|
hasAgentId: !!effectiveAgentId,
|
|
2459
2578
|
hasTaskId: !!this.context.taskId,
|
|
2460
|
-
passedAgentId:
|
|
2461
|
-
contextAgentId: this.context.
|
|
2579
|
+
passedAgentId: subAgentId,
|
|
2580
|
+
contextAgentId: this.context.subAgentId
|
|
2462
2581
|
},
|
|
2463
2582
|
"Skipping artifact_saved event - missing required context"
|
|
2464
2583
|
);
|
|
@@ -2526,7 +2645,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2526
2645
|
summaryData = this.filterBySchema(artifact.data, previewSchema);
|
|
2527
2646
|
fullData = this.filterBySchema(artifact.data, fullSchema);
|
|
2528
2647
|
} catch (error) {
|
|
2529
|
-
|
|
2648
|
+
logger7.warn(
|
|
2530
2649
|
{
|
|
2531
2650
|
artifactType: artifact.type,
|
|
2532
2651
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2564,7 +2683,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2564
2683
|
artifact: artifactToSave
|
|
2565
2684
|
});
|
|
2566
2685
|
if (!result.created && result.existing) {
|
|
2567
|
-
|
|
2686
|
+
logger7.debug(
|
|
2568
2687
|
{
|
|
2569
2688
|
artifactId: artifact.artifactId,
|
|
2570
2689
|
taskId: this.context.taskId
|
|
@@ -2617,7 +2736,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2617
2736
|
extracted[propName] = this.cleanEscapedContent(rawValue);
|
|
2618
2737
|
}
|
|
2619
2738
|
} catch (error) {
|
|
2620
|
-
|
|
2739
|
+
logger7.warn(
|
|
2621
2740
|
{ propName, selector, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2622
2741
|
"Failed to extract property"
|
|
2623
2742
|
);
|
|
@@ -2649,7 +2768,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2649
2768
|
extracted[fieldName] = this.cleanEscapedContent(rawValue);
|
|
2650
2769
|
}
|
|
2651
2770
|
} catch (error) {
|
|
2652
|
-
|
|
2771
|
+
logger7.warn(
|
|
2653
2772
|
{ fieldName, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2654
2773
|
"Failed to extract schema field"
|
|
2655
2774
|
);
|
|
@@ -2680,7 +2799,7 @@ __publicField(_ArtifactService, "selectorCache", /* @__PURE__ */ new Map());
|
|
|
2680
2799
|
var ArtifactService = _ArtifactService;
|
|
2681
2800
|
|
|
2682
2801
|
// src/services/ArtifactParser.ts
|
|
2683
|
-
var
|
|
2802
|
+
var logger8 = agentsCore.getLogger("ArtifactParser");
|
|
2684
2803
|
var _ArtifactParser = class _ArtifactParser {
|
|
2685
2804
|
constructor(tenantId, options) {
|
|
2686
2805
|
__publicField(this, "artifactService");
|
|
@@ -2768,7 +2887,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2768
2887
|
attrs[key] = value;
|
|
2769
2888
|
}
|
|
2770
2889
|
if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
|
|
2771
|
-
|
|
2890
|
+
logger8.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
|
|
2772
2891
|
return null;
|
|
2773
2892
|
}
|
|
2774
2893
|
return {
|
|
@@ -2799,7 +2918,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2799
2918
|
/**
|
|
2800
2919
|
* Extract artifact data from a create annotation - delegates to service
|
|
2801
2920
|
*/
|
|
2802
|
-
async extractFromCreateAnnotation(annotation,
|
|
2921
|
+
async extractFromCreateAnnotation(annotation, subAgentId) {
|
|
2803
2922
|
const request = {
|
|
2804
2923
|
artifactId: annotation.artifactId,
|
|
2805
2924
|
toolCallId: annotation.toolCallId,
|
|
@@ -2807,21 +2926,21 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2807
2926
|
baseSelector: annotation.baseSelector,
|
|
2808
2927
|
detailsSelector: annotation.detailsSelector
|
|
2809
2928
|
};
|
|
2810
|
-
return this.artifactService.createArtifact(request,
|
|
2929
|
+
return this.artifactService.createArtifact(request, subAgentId);
|
|
2811
2930
|
}
|
|
2812
2931
|
/**
|
|
2813
2932
|
* Parse text with artifact markers into parts array
|
|
2814
2933
|
* Handles both artifact:ref and artifact:create tags
|
|
2815
2934
|
* Can work with or without pre-fetched artifact map
|
|
2816
2935
|
*/
|
|
2817
|
-
async parseText(text, artifactMap,
|
|
2936
|
+
async parseText(text, artifactMap, subAgentId) {
|
|
2818
2937
|
let processedText = text;
|
|
2819
2938
|
const createAnnotations = this.parseCreateAnnotations(text);
|
|
2820
2939
|
const createdArtifactData = /* @__PURE__ */ new Map();
|
|
2821
2940
|
const failedAnnotations = [];
|
|
2822
2941
|
for (const annotation of createAnnotations) {
|
|
2823
2942
|
try {
|
|
2824
|
-
const artifactData = await this.extractFromCreateAnnotation(annotation,
|
|
2943
|
+
const artifactData = await this.extractFromCreateAnnotation(annotation, subAgentId);
|
|
2825
2944
|
if (artifactData && annotation.raw) {
|
|
2826
2945
|
createdArtifactData.set(annotation.raw, artifactData);
|
|
2827
2946
|
} else if (annotation.raw) {
|
|
@@ -2829,7 +2948,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2829
2948
|
`Failed to create artifact "${annotation.artifactId}": Missing or invalid data`
|
|
2830
2949
|
);
|
|
2831
2950
|
processedText = processedText.replace(annotation.raw, "");
|
|
2832
|
-
|
|
2951
|
+
logger8.warn(
|
|
2833
2952
|
{ annotation, artifactData },
|
|
2834
2953
|
"Removed failed artifact:create annotation from output"
|
|
2835
2954
|
);
|
|
@@ -2840,11 +2959,11 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2840
2959
|
if (annotation.raw) {
|
|
2841
2960
|
processedText = processedText.replace(annotation.raw, "");
|
|
2842
2961
|
}
|
|
2843
|
-
|
|
2962
|
+
logger8.error({ annotation, error }, "Failed to extract artifact from create annotation");
|
|
2844
2963
|
}
|
|
2845
2964
|
}
|
|
2846
2965
|
if (failedAnnotations.length > 0) {
|
|
2847
|
-
|
|
2966
|
+
logger8.warn(
|
|
2848
2967
|
{
|
|
2849
2968
|
failedCount: failedAnnotations.length,
|
|
2850
2969
|
failures: failedAnnotations
|
|
@@ -2908,7 +3027,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2908
3027
|
/**
|
|
2909
3028
|
* Process object/dataComponents for artifact components
|
|
2910
3029
|
*/
|
|
2911
|
-
async parseObject(obj, artifactMap,
|
|
3030
|
+
async parseObject(obj, artifactMap, subAgentId) {
|
|
2912
3031
|
if (obj?.dataComponents && Array.isArray(obj.dataComponents)) {
|
|
2913
3032
|
const parts = [];
|
|
2914
3033
|
for (const component of obj.dataComponents) {
|
|
@@ -2932,7 +3051,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2932
3051
|
});
|
|
2933
3052
|
}
|
|
2934
3053
|
} else if (this.isArtifactCreateComponent(component)) {
|
|
2935
|
-
const createData = await this.extractFromArtifactCreateComponent(component,
|
|
3054
|
+
const createData = await this.extractFromArtifactCreateComponent(component, subAgentId);
|
|
2936
3055
|
if (createData) {
|
|
2937
3056
|
parts.push({
|
|
2938
3057
|
kind: "data",
|
|
@@ -2973,7 +3092,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2973
3092
|
] : [];
|
|
2974
3093
|
}
|
|
2975
3094
|
if (this.isArtifactCreateComponent(obj)) {
|
|
2976
|
-
const createData = await this.extractFromArtifactCreateComponent(obj,
|
|
3095
|
+
const createData = await this.extractFromArtifactCreateComponent(obj, subAgentId);
|
|
2977
3096
|
return createData ? [
|
|
2978
3097
|
{
|
|
2979
3098
|
kind: "data",
|
|
@@ -3005,7 +3124,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
3005
3124
|
/**
|
|
3006
3125
|
* Extract artifact from ArtifactCreate component
|
|
3007
3126
|
*/
|
|
3008
|
-
async extractFromArtifactCreateComponent(component,
|
|
3127
|
+
async extractFromArtifactCreateComponent(component, subAgentId) {
|
|
3009
3128
|
const props = component.props;
|
|
3010
3129
|
if (!props) {
|
|
3011
3130
|
return null;
|
|
@@ -3017,7 +3136,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
3017
3136
|
baseSelector: props.base_selector,
|
|
3018
3137
|
detailsSelector: props.details_selector || {}
|
|
3019
3138
|
};
|
|
3020
|
-
return await this.extractFromCreateAnnotation(annotation,
|
|
3139
|
+
return await this.extractFromCreateAnnotation(annotation, subAgentId);
|
|
3021
3140
|
}
|
|
3022
3141
|
/**
|
|
3023
3142
|
* Get artifact data - delegates to service
|
|
@@ -3057,7 +3176,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^
|
|
|
3057
3176
|
var ArtifactParser = _ArtifactParser;
|
|
3058
3177
|
|
|
3059
3178
|
// src/services/GraphSession.ts
|
|
3060
|
-
var
|
|
3179
|
+
var logger9 = agentsCore.getLogger("GraphSession");
|
|
3061
3180
|
var GraphSession = class {
|
|
3062
3181
|
// Whether to send data operations
|
|
3063
3182
|
constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
|
|
@@ -3090,7 +3209,7 @@ var GraphSession = class {
|
|
|
3090
3209
|
__publicField(this, "artifactParser");
|
|
3091
3210
|
// Session-scoped ArtifactParser instance
|
|
3092
3211
|
__publicField(this, "isEmitOperations", false);
|
|
3093
|
-
|
|
3212
|
+
logger9.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
3094
3213
|
if (tenantId && projectId) {
|
|
3095
3214
|
toolSessionManager.createSessionWithId(
|
|
3096
3215
|
sessionId,
|
|
@@ -3104,7 +3223,6 @@ var GraphSession = class {
|
|
|
3104
3223
|
tenantId,
|
|
3105
3224
|
projectId,
|
|
3106
3225
|
sessionId,
|
|
3107
|
-
// Same ID as ToolSession
|
|
3108
3226
|
contextId,
|
|
3109
3227
|
taskId: `task_${contextId}-${messageId}`,
|
|
3110
3228
|
streamRequestId: sessionId
|
|
@@ -3125,7 +3243,7 @@ var GraphSession = class {
|
|
|
3125
3243
|
*/
|
|
3126
3244
|
enableEmitOperations() {
|
|
3127
3245
|
this.isEmitOperations = true;
|
|
3128
|
-
|
|
3246
|
+
logger9.info(
|
|
3129
3247
|
{ sessionId: this.sessionId },
|
|
3130
3248
|
"\u{1F50D} DEBUG: Emit operations enabled for GraphSession"
|
|
3131
3249
|
);
|
|
@@ -3142,14 +3260,14 @@ var GraphSession = class {
|
|
|
3142
3260
|
label: this.generateEventLabel(event),
|
|
3143
3261
|
details: {
|
|
3144
3262
|
timestamp: event.timestamp,
|
|
3145
|
-
|
|
3263
|
+
subAgentId: event.subAgentId,
|
|
3146
3264
|
data: event.data
|
|
3147
3265
|
}
|
|
3148
3266
|
};
|
|
3149
3267
|
await streamHelper.writeOperation(formattedOperation);
|
|
3150
3268
|
}
|
|
3151
3269
|
} catch (error) {
|
|
3152
|
-
|
|
3270
|
+
logger9.error(
|
|
3153
3271
|
{
|
|
3154
3272
|
sessionId: this.sessionId,
|
|
3155
3273
|
eventType: event.eventType,
|
|
@@ -3165,29 +3283,19 @@ var GraphSession = class {
|
|
|
3165
3283
|
generateEventLabel(event) {
|
|
3166
3284
|
switch (event.eventType) {
|
|
3167
3285
|
case "agent_generate":
|
|
3168
|
-
return `Agent ${event.
|
|
3286
|
+
return `Agent ${event.subAgentId} generating response`;
|
|
3169
3287
|
case "agent_reasoning":
|
|
3170
|
-
return `Agent ${event.
|
|
3171
|
-
case "tool_execution":
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
case "
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
case "
|
|
3180
|
-
|
|
3181
|
-
return `Task delegated: ${delegationData.fromAgent} \u2192 ${delegationData.targetAgent}`;
|
|
3182
|
-
}
|
|
3183
|
-
case "delegation_returned": {
|
|
3184
|
-
const returnData = event.data;
|
|
3185
|
-
return `Task completed: ${returnData.targetAgent} \u2192 ${returnData.fromAgent}`;
|
|
3186
|
-
}
|
|
3187
|
-
case "artifact_saved": {
|
|
3188
|
-
const artifactData = event.data;
|
|
3189
|
-
return `Artifact saved: ${artifactData.artifactType || "unknown type"}`;
|
|
3190
|
-
}
|
|
3288
|
+
return `Agent ${event.subAgentId} reasoning through request`;
|
|
3289
|
+
case "tool_execution":
|
|
3290
|
+
return `Tool execution: ${event.data.toolName || "unknown"}`;
|
|
3291
|
+
case "transfer":
|
|
3292
|
+
return `Agent transfer: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
|
|
3293
|
+
case "delegation_sent":
|
|
3294
|
+
return `Task delegated: ${event.data.fromSubAgent} \u2192 ${event.data.targetSubAgent}`;
|
|
3295
|
+
case "delegation_returned":
|
|
3296
|
+
return `Task completed: ${event.data.targetSubAgent} \u2192 ${event.data.fromSubAgent}`;
|
|
3297
|
+
case "artifact_saved":
|
|
3298
|
+
return `Artifact saved: ${event.data.artifactType || "unknown type"}`;
|
|
3191
3299
|
default:
|
|
3192
3300
|
return `${event.eventType} event`;
|
|
3193
3301
|
}
|
|
@@ -3212,7 +3320,7 @@ var GraphSession = class {
|
|
|
3212
3320
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
3213
3321
|
this.statusUpdateTimer = setInterval(async () => {
|
|
3214
3322
|
if (!this.statusUpdateState || this.isEnded) {
|
|
3215
|
-
|
|
3323
|
+
logger9.debug(
|
|
3216
3324
|
{ sessionId: this.sessionId },
|
|
3217
3325
|
"Timer triggered but session already cleaned up or ended"
|
|
3218
3326
|
);
|
|
@@ -3224,7 +3332,7 @@ var GraphSession = class {
|
|
|
3224
3332
|
}
|
|
3225
3333
|
await this.checkAndSendTimeBasedUpdate();
|
|
3226
3334
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
3227
|
-
|
|
3335
|
+
logger9.info(
|
|
3228
3336
|
{
|
|
3229
3337
|
sessionId: this.sessionId,
|
|
3230
3338
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -3235,22 +3343,24 @@ var GraphSession = class {
|
|
|
3235
3343
|
}
|
|
3236
3344
|
/**
|
|
3237
3345
|
* Record an event in the session and trigger status updates if configured
|
|
3346
|
+
* Generic type parameter T ensures eventType and data are correctly paired
|
|
3238
3347
|
*/
|
|
3239
|
-
recordEvent(eventType,
|
|
3348
|
+
recordEvent(eventType, subAgentId, data) {
|
|
3240
3349
|
if (this.isEmitOperations) {
|
|
3241
|
-
|
|
3350
|
+
const dataOpEvent = {
|
|
3242
3351
|
timestamp: Date.now(),
|
|
3243
3352
|
eventType,
|
|
3244
|
-
|
|
3353
|
+
subAgentId,
|
|
3245
3354
|
data
|
|
3246
|
-
}
|
|
3355
|
+
};
|
|
3356
|
+
this.sendDataOperation(dataOpEvent);
|
|
3247
3357
|
}
|
|
3248
3358
|
if (this.isEnded) {
|
|
3249
|
-
|
|
3359
|
+
logger9.debug(
|
|
3250
3360
|
{
|
|
3251
3361
|
sessionId: this.sessionId,
|
|
3252
3362
|
eventType,
|
|
3253
|
-
|
|
3363
|
+
subAgentId
|
|
3254
3364
|
},
|
|
3255
3365
|
"Event received after session ended - ignoring"
|
|
3256
3366
|
);
|
|
@@ -3259,59 +3369,62 @@ var GraphSession = class {
|
|
|
3259
3369
|
const event = {
|
|
3260
3370
|
timestamp: Date.now(),
|
|
3261
3371
|
eventType,
|
|
3262
|
-
|
|
3372
|
+
subAgentId,
|
|
3263
3373
|
data
|
|
3264
3374
|
};
|
|
3265
3375
|
this.events.push(event);
|
|
3266
|
-
if (eventType === "artifact_saved"
|
|
3267
|
-
const
|
|
3268
|
-
if (
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
this.
|
|
3286
|
-
}).catch((error) => {
|
|
3287
|
-
const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
|
|
3288
|
-
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
3289
|
-
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
3376
|
+
if (eventType === "artifact_saved") {
|
|
3377
|
+
const artifactData = data;
|
|
3378
|
+
if (artifactData.pendingGeneration) {
|
|
3379
|
+
const artifactId = artifactData.artifactId;
|
|
3380
|
+
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
3381
|
+
logger9.warn(
|
|
3382
|
+
{
|
|
3383
|
+
sessionId: this.sessionId,
|
|
3384
|
+
artifactId,
|
|
3385
|
+
pendingCount: this.pendingArtifacts.size,
|
|
3386
|
+
maxAllowed: this.MAX_PENDING_ARTIFACTS
|
|
3387
|
+
},
|
|
3388
|
+
"Too many pending artifacts, skipping processing"
|
|
3389
|
+
);
|
|
3390
|
+
return;
|
|
3391
|
+
}
|
|
3392
|
+
this.pendingArtifacts.add(artifactId);
|
|
3393
|
+
setImmediate(() => {
|
|
3394
|
+
const artifactDataWithAgent = { ...artifactData, subAgentId };
|
|
3395
|
+
this.processArtifact(artifactDataWithAgent).then(() => {
|
|
3290
3396
|
this.pendingArtifacts.delete(artifactId);
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3397
|
+
this.artifactProcessingErrors.delete(artifactId);
|
|
3398
|
+
}).catch((error) => {
|
|
3399
|
+
const errorCount = (this.artifactProcessingErrors.get(artifactId) || 0) + 1;
|
|
3400
|
+
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
3401
|
+
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
3402
|
+
this.pendingArtifacts.delete(artifactId);
|
|
3403
|
+
logger9.error(
|
|
3404
|
+
{
|
|
3405
|
+
sessionId: this.sessionId,
|
|
3406
|
+
artifactId,
|
|
3407
|
+
errorCount,
|
|
3408
|
+
maxRetries: this.MAX_ARTIFACT_RETRIES,
|
|
3409
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
3410
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
3411
|
+
},
|
|
3412
|
+
"Artifact processing failed after max retries, giving up"
|
|
3413
|
+
);
|
|
3414
|
+
} else {
|
|
3415
|
+
logger9.warn(
|
|
3416
|
+
{
|
|
3417
|
+
sessionId: this.sessionId,
|
|
3418
|
+
artifactId,
|
|
3419
|
+
errorCount,
|
|
3420
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
3421
|
+
},
|
|
3422
|
+
"Artifact processing failed, may retry"
|
|
3423
|
+
);
|
|
3424
|
+
}
|
|
3425
|
+
});
|
|
3313
3426
|
});
|
|
3314
|
-
}
|
|
3427
|
+
}
|
|
3315
3428
|
}
|
|
3316
3429
|
if (!this.isEnded) {
|
|
3317
3430
|
this.checkStatusUpdates();
|
|
@@ -3322,14 +3435,14 @@ var GraphSession = class {
|
|
|
3322
3435
|
*/
|
|
3323
3436
|
checkStatusUpdates() {
|
|
3324
3437
|
if (this.isEnded) {
|
|
3325
|
-
|
|
3438
|
+
logger9.debug(
|
|
3326
3439
|
{ sessionId: this.sessionId },
|
|
3327
3440
|
"Session has ended - skipping status update check"
|
|
3328
3441
|
);
|
|
3329
3442
|
return;
|
|
3330
3443
|
}
|
|
3331
3444
|
if (!this.statusUpdateState) {
|
|
3332
|
-
|
|
3445
|
+
logger9.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
3333
3446
|
return;
|
|
3334
3447
|
}
|
|
3335
3448
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -3340,11 +3453,11 @@ var GraphSession = class {
|
|
|
3340
3453
|
*/
|
|
3341
3454
|
async checkAndSendTimeBasedUpdate() {
|
|
3342
3455
|
if (this.isEnded) {
|
|
3343
|
-
|
|
3456
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
3344
3457
|
return;
|
|
3345
3458
|
}
|
|
3346
3459
|
if (!this.statusUpdateState) {
|
|
3347
|
-
|
|
3460
|
+
logger9.debug(
|
|
3348
3461
|
{ sessionId: this.sessionId },
|
|
3349
3462
|
"No status updates configured for time-based check"
|
|
3350
3463
|
);
|
|
@@ -3357,7 +3470,7 @@ var GraphSession = class {
|
|
|
3357
3470
|
try {
|
|
3358
3471
|
await this.generateAndSendUpdate();
|
|
3359
3472
|
} catch (error) {
|
|
3360
|
-
|
|
3473
|
+
logger9.error(
|
|
3361
3474
|
{
|
|
3362
3475
|
sessionId: this.sessionId,
|
|
3363
3476
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3381,8 +3494,8 @@ var GraphSession = class {
|
|
|
3381
3494
|
/**
|
|
3382
3495
|
* Get events filtered by agent
|
|
3383
3496
|
*/
|
|
3384
|
-
getEventsByAgent(
|
|
3385
|
-
return this.events.filter((event) => event.
|
|
3497
|
+
getEventsByAgent(subAgentId) {
|
|
3498
|
+
return this.events.filter((event) => event.subAgentId === subAgentId);
|
|
3386
3499
|
}
|
|
3387
3500
|
/**
|
|
3388
3501
|
* Get summary of session activity
|
|
@@ -3397,7 +3510,7 @@ var GraphSession = class {
|
|
|
3397
3510
|
);
|
|
3398
3511
|
const agentCounts = this.events.reduce(
|
|
3399
3512
|
(counts, event) => {
|
|
3400
|
-
counts[event.
|
|
3513
|
+
counts[event.subAgentId] = (counts[event.subAgentId] || 0) + 1;
|
|
3401
3514
|
return counts;
|
|
3402
3515
|
},
|
|
3403
3516
|
{}
|
|
@@ -3460,29 +3573,29 @@ var GraphSession = class {
|
|
|
3460
3573
|
*/
|
|
3461
3574
|
async generateAndSendUpdate() {
|
|
3462
3575
|
if (this.isEnded) {
|
|
3463
|
-
|
|
3576
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
3464
3577
|
return;
|
|
3465
3578
|
}
|
|
3466
3579
|
if (this.isTextStreaming) {
|
|
3467
|
-
|
|
3580
|
+
logger9.debug(
|
|
3468
3581
|
{ sessionId: this.sessionId },
|
|
3469
3582
|
"Text is currently streaming - skipping status update"
|
|
3470
3583
|
);
|
|
3471
3584
|
return;
|
|
3472
3585
|
}
|
|
3473
3586
|
if (this.isGeneratingUpdate) {
|
|
3474
|
-
|
|
3587
|
+
logger9.debug(
|
|
3475
3588
|
{ sessionId: this.sessionId },
|
|
3476
3589
|
"Update already in progress - skipping duplicate generation"
|
|
3477
3590
|
);
|
|
3478
3591
|
return;
|
|
3479
3592
|
}
|
|
3480
3593
|
if (!this.statusUpdateState) {
|
|
3481
|
-
|
|
3594
|
+
logger9.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
3482
3595
|
return;
|
|
3483
3596
|
}
|
|
3484
3597
|
if (!this.graphId) {
|
|
3485
|
-
|
|
3598
|
+
logger9.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
3486
3599
|
return;
|
|
3487
3600
|
}
|
|
3488
3601
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -3494,7 +3607,7 @@ var GraphSession = class {
|
|
|
3494
3607
|
try {
|
|
3495
3608
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
3496
3609
|
if (!streamHelper) {
|
|
3497
|
-
|
|
3610
|
+
logger9.warn(
|
|
3498
3611
|
{ sessionId: this.sessionId },
|
|
3499
3612
|
"No stream helper found - cannot send status update"
|
|
3500
3613
|
);
|
|
@@ -3514,7 +3627,7 @@ var GraphSession = class {
|
|
|
3514
3627
|
if (result.summaries && result.summaries.length > 0) {
|
|
3515
3628
|
for (const summary of result.summaries) {
|
|
3516
3629
|
if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
|
|
3517
|
-
|
|
3630
|
+
logger9.warn(
|
|
3518
3631
|
{
|
|
3519
3632
|
sessionId: this.sessionId,
|
|
3520
3633
|
summary
|
|
@@ -3551,7 +3664,7 @@ var GraphSession = class {
|
|
|
3551
3664
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
3552
3665
|
}
|
|
3553
3666
|
} catch (error) {
|
|
3554
|
-
|
|
3667
|
+
logger9.error(
|
|
3555
3668
|
{
|
|
3556
3669
|
sessionId: this.sessionId,
|
|
3557
3670
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -3589,7 +3702,7 @@ var GraphSession = class {
|
|
|
3589
3702
|
this.releaseUpdateLock();
|
|
3590
3703
|
}
|
|
3591
3704
|
} catch (error) {
|
|
3592
|
-
|
|
3705
|
+
logger9.error(
|
|
3593
3706
|
{
|
|
3594
3707
|
sessionId: this.sessionId,
|
|
3595
3708
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3667,7 +3780,7 @@ User's Question/Context:
|
|
|
3667
3780
|
${conversationHistory}
|
|
3668
3781
|
` : "";
|
|
3669
3782
|
} catch (error) {
|
|
3670
|
-
|
|
3783
|
+
logger9.warn(
|
|
3671
3784
|
{ sessionId: this.sessionId, error },
|
|
3672
3785
|
"Failed to fetch conversation history for structured status update"
|
|
3673
3786
|
);
|
|
@@ -3801,7 +3914,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3801
3914
|
return { summaries };
|
|
3802
3915
|
} catch (error) {
|
|
3803
3916
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
3804
|
-
|
|
3917
|
+
logger9.error({ error }, "Failed to generate structured update, using fallback");
|
|
3805
3918
|
return { summaries: [] };
|
|
3806
3919
|
} finally {
|
|
3807
3920
|
span.end();
|
|
@@ -3827,7 +3940,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3827
3940
|
*/
|
|
3828
3941
|
buildZodSchemaFromJson(jsonSchema) {
|
|
3829
3942
|
const properties = {};
|
|
3830
|
-
properties
|
|
3943
|
+
properties.label = z6.z.string().describe(
|
|
3831
3944
|
'A short 3-5 word phrase, that is a descriptive label for the update component. This Label must be EXTREMELY unique to represent the UNIQUE update we are providing. The SPECIFIC finding, result, or insight discovered (e.g., "Slack bot needs workspace admin role", "Found ingestion requires 3 steps", "Channel history limited to 10k messages"). State the ACTUAL information found, not that you searched. What did you LEARN or DISCOVER? What specific detail is now known? CRITICAL: Only use facts explicitly found in the activities - NEVER invent names, people, organizations, or details that are not present in the actual tool results.'
|
|
3832
3945
|
);
|
|
3833
3946
|
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
@@ -3896,11 +4009,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3896
4009
|
for (const event of events) {
|
|
3897
4010
|
switch (event.eventType) {
|
|
3898
4011
|
case "tool_execution": {
|
|
3899
|
-
const
|
|
3900
|
-
const resultStr = JSON.stringify(data.result);
|
|
4012
|
+
const resultStr = JSON.stringify(event.data.result);
|
|
3901
4013
|
activities.push(
|
|
3902
|
-
`\u{1F527} **${data.toolName}** ${data.duration ? `(${data.duration}ms)` : ""}
|
|
3903
|
-
\u{1F4E5} Input: ${JSON.stringify(data.args)}
|
|
4014
|
+
`\u{1F527} **${event.data.toolName}** ${event.data.duration ? `(${event.data.duration}ms)` : ""}
|
|
4015
|
+
\u{1F4E5} Input: ${JSON.stringify(event.data.args)}
|
|
3904
4016
|
\u{1F4E4} Output: ${resultStr}`
|
|
3905
4017
|
);
|
|
3906
4018
|
break;
|
|
@@ -3912,23 +4024,24 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3912
4024
|
case "artifact_saved":
|
|
3913
4025
|
break;
|
|
3914
4026
|
case "agent_reasoning": {
|
|
3915
|
-
const data = event.data;
|
|
3916
4027
|
activities.push(
|
|
3917
4028
|
`\u2699\uFE0F **Analyzing request**
|
|
3918
|
-
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
4029
|
+
Details: ${JSON.stringify(event.data.parts, null, 2)}`
|
|
3919
4030
|
);
|
|
3920
4031
|
break;
|
|
3921
4032
|
}
|
|
3922
4033
|
case "agent_generate": {
|
|
3923
|
-
const data = event.data;
|
|
3924
4034
|
activities.push(
|
|
3925
4035
|
`\u2699\uFE0F **Preparing response**
|
|
3926
|
-
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
4036
|
+
Details: ${JSON.stringify(event.data.parts, null, 2)}`
|
|
3927
4037
|
);
|
|
3928
4038
|
break;
|
|
3929
4039
|
}
|
|
3930
4040
|
default: {
|
|
3931
|
-
|
|
4041
|
+
const safeEvent = event;
|
|
4042
|
+
activities.push(
|
|
4043
|
+
`\u{1F4CB} **${safeEvent.eventType}**: ${JSON.stringify(safeEvent.data, null, 2)}`
|
|
4044
|
+
);
|
|
3932
4045
|
break;
|
|
3933
4046
|
}
|
|
3934
4047
|
}
|
|
@@ -3946,7 +4059,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3946
4059
|
"graph_session.id": this.sessionId,
|
|
3947
4060
|
"artifact.id": artifactData.artifactId,
|
|
3948
4061
|
"artifact.type": artifactData.artifactType || "unknown",
|
|
3949
|
-
"artifact.agent_id": artifactData.
|
|
4062
|
+
"artifact.agent_id": artifactData.subAgentId || "unknown",
|
|
3950
4063
|
"artifact.tool_call_id": artifactData.metadata?.toolCallId || "unknown",
|
|
3951
4064
|
"artifact.data": JSON.stringify(artifactData.data, null, 2),
|
|
3952
4065
|
"tenant.id": artifactData.tenantId || "unknown",
|
|
@@ -4005,34 +4118,34 @@ Make it specific and relevant.`;
|
|
|
4005
4118
|
let modelToUse = this.statusUpdateState?.summarizerModel;
|
|
4006
4119
|
if (!modelToUse?.model?.trim()) {
|
|
4007
4120
|
if (!this.statusUpdateState?.baseModel?.model?.trim()) {
|
|
4008
|
-
if (artifactData.
|
|
4121
|
+
if (artifactData.subAgentId && artifactData.tenantId && artifactData.projectId) {
|
|
4009
4122
|
try {
|
|
4010
|
-
const agentData = await agentsCore.
|
|
4123
|
+
const agentData = await agentsCore.getSubAgentById(dbClient_default)({
|
|
4011
4124
|
scopes: {
|
|
4012
4125
|
tenantId: artifactData.tenantId,
|
|
4013
4126
|
projectId: artifactData.projectId,
|
|
4014
4127
|
graphId: this.graphId || ""
|
|
4015
4128
|
},
|
|
4016
|
-
|
|
4129
|
+
subAgentId: artifactData.subAgentId
|
|
4017
4130
|
});
|
|
4018
4131
|
if (agentData && "models" in agentData && agentData.models?.base?.model) {
|
|
4019
4132
|
modelToUse = agentData.models.base;
|
|
4020
|
-
|
|
4133
|
+
logger9.info(
|
|
4021
4134
|
{
|
|
4022
4135
|
sessionId: this.sessionId,
|
|
4023
4136
|
artifactId: artifactData.artifactId,
|
|
4024
|
-
|
|
4137
|
+
subAgentId: artifactData.subAgentId,
|
|
4025
4138
|
model: modelToUse.model
|
|
4026
4139
|
},
|
|
4027
4140
|
"Using agent model configuration for artifact name generation"
|
|
4028
4141
|
);
|
|
4029
4142
|
}
|
|
4030
4143
|
} catch (error) {
|
|
4031
|
-
|
|
4144
|
+
logger9.warn(
|
|
4032
4145
|
{
|
|
4033
4146
|
sessionId: this.sessionId,
|
|
4034
4147
|
artifactId: artifactData.artifactId,
|
|
4035
|
-
|
|
4148
|
+
subAgentId: artifactData.subAgentId,
|
|
4036
4149
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
4037
4150
|
},
|
|
4038
4151
|
"Failed to get agent model configuration"
|
|
@@ -4040,7 +4153,7 @@ Make it specific and relevant.`;
|
|
|
4040
4153
|
}
|
|
4041
4154
|
}
|
|
4042
4155
|
if (!modelToUse?.model?.trim()) {
|
|
4043
|
-
|
|
4156
|
+
logger9.warn(
|
|
4044
4157
|
{
|
|
4045
4158
|
sessionId: this.sessionId,
|
|
4046
4159
|
artifactId: artifactData.artifactId
|
|
@@ -4122,7 +4235,7 @@ Make it specific and relevant.`;
|
|
|
4122
4235
|
return result2;
|
|
4123
4236
|
} catch (error) {
|
|
4124
4237
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
4125
|
-
|
|
4238
|
+
logger9.warn(
|
|
4126
4239
|
{
|
|
4127
4240
|
sessionId: this.sessionId,
|
|
4128
4241
|
artifactId: artifactData.artifactId,
|
|
@@ -4174,7 +4287,7 @@ Make it specific and relevant.`;
|
|
|
4174
4287
|
});
|
|
4175
4288
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
4176
4289
|
} catch (saveError) {
|
|
4177
|
-
|
|
4290
|
+
logger9.error(
|
|
4178
4291
|
{
|
|
4179
4292
|
sessionId: this.sessionId,
|
|
4180
4293
|
artifactId: artifactData.artifactId,
|
|
@@ -4202,7 +4315,7 @@ Make it specific and relevant.`;
|
|
|
4202
4315
|
metadata: artifactData.metadata || {},
|
|
4203
4316
|
toolCallId: artifactData.toolCallId
|
|
4204
4317
|
});
|
|
4205
|
-
|
|
4318
|
+
logger9.info(
|
|
4206
4319
|
{
|
|
4207
4320
|
sessionId: this.sessionId,
|
|
4208
4321
|
artifactId: artifactData.artifactId
|
|
@@ -4213,7 +4326,7 @@ Make it specific and relevant.`;
|
|
|
4213
4326
|
} catch (fallbackError) {
|
|
4214
4327
|
const isDuplicateError = fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"));
|
|
4215
4328
|
if (isDuplicateError) ; else {
|
|
4216
|
-
|
|
4329
|
+
logger9.error(
|
|
4217
4330
|
{
|
|
4218
4331
|
sessionId: this.sessionId,
|
|
4219
4332
|
artifactId: artifactData.artifactId,
|
|
@@ -4226,7 +4339,7 @@ Make it specific and relevant.`;
|
|
|
4226
4339
|
}
|
|
4227
4340
|
} catch (error) {
|
|
4228
4341
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4229
|
-
|
|
4342
|
+
logger9.error(
|
|
4230
4343
|
{
|
|
4231
4344
|
sessionId: this.sessionId,
|
|
4232
4345
|
artifactId: artifactData.artifactId,
|
|
@@ -4245,7 +4358,7 @@ Make it specific and relevant.`;
|
|
|
4245
4358
|
*/
|
|
4246
4359
|
setArtifactCache(key, artifact) {
|
|
4247
4360
|
this.artifactCache.set(key, artifact);
|
|
4248
|
-
|
|
4361
|
+
logger9.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
|
|
4249
4362
|
}
|
|
4250
4363
|
/**
|
|
4251
4364
|
* Get session-scoped ArtifactService instance
|
|
@@ -4264,7 +4377,7 @@ Make it specific and relevant.`;
|
|
|
4264
4377
|
*/
|
|
4265
4378
|
getArtifactCache(key) {
|
|
4266
4379
|
const artifact = this.artifactCache.get(key);
|
|
4267
|
-
|
|
4380
|
+
logger9.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
|
|
4268
4381
|
return artifact || null;
|
|
4269
4382
|
}
|
|
4270
4383
|
/**
|
|
@@ -4287,7 +4400,7 @@ var GraphSessionManager = class {
|
|
|
4287
4400
|
const sessionId = messageId;
|
|
4288
4401
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
|
|
4289
4402
|
this.sessions.set(sessionId, session);
|
|
4290
|
-
|
|
4403
|
+
logger9.info(
|
|
4291
4404
|
{ sessionId, messageId, graphId, tenantId, projectId, contextId },
|
|
4292
4405
|
"GraphSession created"
|
|
4293
4406
|
);
|
|
@@ -4301,7 +4414,7 @@ var GraphSessionManager = class {
|
|
|
4301
4414
|
if (session) {
|
|
4302
4415
|
session.initializeStatusUpdates(config, summarizerModel);
|
|
4303
4416
|
} else {
|
|
4304
|
-
|
|
4417
|
+
logger9.error(
|
|
4305
4418
|
{
|
|
4306
4419
|
sessionId,
|
|
4307
4420
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -4318,7 +4431,7 @@ var GraphSessionManager = class {
|
|
|
4318
4431
|
if (session) {
|
|
4319
4432
|
session.enableEmitOperations();
|
|
4320
4433
|
} else {
|
|
4321
|
-
|
|
4434
|
+
logger9.error(
|
|
4322
4435
|
{
|
|
4323
4436
|
sessionId,
|
|
4324
4437
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -4335,14 +4448,15 @@ var GraphSessionManager = class {
|
|
|
4335
4448
|
}
|
|
4336
4449
|
/**
|
|
4337
4450
|
* Record an event in a session
|
|
4451
|
+
* Generic type parameter T ensures eventType and data are correctly paired
|
|
4338
4452
|
*/
|
|
4339
|
-
recordEvent(sessionId, eventType,
|
|
4453
|
+
recordEvent(sessionId, eventType, subAgentId, data) {
|
|
4340
4454
|
const session = this.sessions.get(sessionId);
|
|
4341
4455
|
if (!session) {
|
|
4342
|
-
|
|
4456
|
+
logger9.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
4343
4457
|
return;
|
|
4344
4458
|
}
|
|
4345
|
-
session.recordEvent(eventType,
|
|
4459
|
+
session.recordEvent(eventType, subAgentId, data);
|
|
4346
4460
|
}
|
|
4347
4461
|
/**
|
|
4348
4462
|
* End a session and return the final event data
|
|
@@ -4350,12 +4464,12 @@ var GraphSessionManager = class {
|
|
|
4350
4464
|
endSession(sessionId) {
|
|
4351
4465
|
const session = this.sessions.get(sessionId);
|
|
4352
4466
|
if (!session) {
|
|
4353
|
-
|
|
4467
|
+
logger9.warn({ sessionId }, "Attempted to end non-existent session");
|
|
4354
4468
|
return [];
|
|
4355
4469
|
}
|
|
4356
4470
|
const events = session.getEvents();
|
|
4357
4471
|
const summary = session.getSummary();
|
|
4358
|
-
|
|
4472
|
+
logger9.info({ sessionId, summary }, "GraphSession ended");
|
|
4359
4473
|
session.cleanup();
|
|
4360
4474
|
this.sessions.delete(sessionId);
|
|
4361
4475
|
return events;
|
|
@@ -4463,7 +4577,7 @@ init_logger();
|
|
|
4463
4577
|
|
|
4464
4578
|
// src/services/IncrementalStreamParser.ts
|
|
4465
4579
|
init_logger();
|
|
4466
|
-
var
|
|
4580
|
+
var logger10 = agentsCore.getLogger("IncrementalStreamParser");
|
|
4467
4581
|
var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
4468
4582
|
// Max number of collected parts to prevent unbounded growth
|
|
4469
4583
|
constructor(streamHelper, tenantId, contextId, artifactParserOptions) {
|
|
@@ -4479,10 +4593,11 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4479
4593
|
__publicField(this, "lastStreamedComponents", /* @__PURE__ */ new Map());
|
|
4480
4594
|
__publicField(this, "componentSnapshots", /* @__PURE__ */ new Map());
|
|
4481
4595
|
__publicField(this, "artifactMap");
|
|
4482
|
-
__publicField(this, "
|
|
4596
|
+
__publicField(this, "subAgentId");
|
|
4597
|
+
__publicField(this, "allStreamedContent", []);
|
|
4483
4598
|
this.streamHelper = streamHelper;
|
|
4484
4599
|
this.contextId = contextId;
|
|
4485
|
-
this.
|
|
4600
|
+
this.subAgentId = artifactParserOptions?.subAgentId;
|
|
4486
4601
|
if (artifactParserOptions?.streamRequestId) {
|
|
4487
4602
|
const sessionParser = graphSessionManager.getArtifactParser(
|
|
4488
4603
|
artifactParserOptions.streamRequestId
|
|
@@ -4515,7 +4630,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4515
4630
|
async initializeArtifactMap() {
|
|
4516
4631
|
try {
|
|
4517
4632
|
this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
|
|
4518
|
-
|
|
4633
|
+
logger10.debug(
|
|
4519
4634
|
{
|
|
4520
4635
|
contextId: this.contextId,
|
|
4521
4636
|
artifactMapSize: this.artifactMap.size
|
|
@@ -4523,7 +4638,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4523
4638
|
"Initialized artifact map for streaming"
|
|
4524
4639
|
);
|
|
4525
4640
|
} catch (error) {
|
|
4526
|
-
|
|
4641
|
+
logger10.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
|
|
4527
4642
|
this.artifactMap = /* @__PURE__ */ new Map();
|
|
4528
4643
|
}
|
|
4529
4644
|
}
|
|
@@ -4598,10 +4713,12 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4598
4713
|
this.hasStartedRole = true;
|
|
4599
4714
|
}
|
|
4600
4715
|
await this.streamHelper.streamText(newText, 50);
|
|
4601
|
-
|
|
4716
|
+
const textPart = {
|
|
4602
4717
|
kind: "text",
|
|
4603
4718
|
text: newText
|
|
4604
|
-
}
|
|
4719
|
+
};
|
|
4720
|
+
this.collectedParts.push(textPart);
|
|
4721
|
+
this.allStreamedContent.push(textPart);
|
|
4605
4722
|
}
|
|
4606
4723
|
continue;
|
|
4607
4724
|
}
|
|
@@ -4625,7 +4742,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4625
4742
|
dataComponents: [component]
|
|
4626
4743
|
},
|
|
4627
4744
|
this.artifactMap,
|
|
4628
|
-
this.
|
|
4745
|
+
this.subAgentId
|
|
4629
4746
|
);
|
|
4630
4747
|
if (!Array.isArray(parts)) {
|
|
4631
4748
|
console.warn("parseObject returned non-array:", parts);
|
|
@@ -4701,7 +4818,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4701
4818
|
dataComponents: [component]
|
|
4702
4819
|
},
|
|
4703
4820
|
this.artifactMap,
|
|
4704
|
-
this.
|
|
4821
|
+
this.subAgentId
|
|
4705
4822
|
);
|
|
4706
4823
|
for (const part of parts) {
|
|
4707
4824
|
await this.streamPart(part);
|
|
@@ -4727,10 +4844,12 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4727
4844
|
if (this.pendingTextBuffer) {
|
|
4728
4845
|
const cleanedText = this.pendingTextBuffer.replace(/<\/?artifact:ref(?:\s[^>]*)?>\/?>/g, "").replace(/<\/?artifact(?:\s[^>]*)?>\/?>/g, "").replace(/<\/artifact:ref>/g, "").replace(/<\/(?:\w+:)?artifact>/g, "");
|
|
4729
4846
|
if (cleanedText) {
|
|
4730
|
-
|
|
4847
|
+
const textPart = {
|
|
4731
4848
|
kind: "text",
|
|
4732
4849
|
text: cleanedText
|
|
4733
|
-
}
|
|
4850
|
+
};
|
|
4851
|
+
this.collectedParts.push(textPart);
|
|
4852
|
+
this.allStreamedContent.push(textPart);
|
|
4734
4853
|
await this.streamHelper.streamText(cleanedText, 50);
|
|
4735
4854
|
}
|
|
4736
4855
|
this.pendingTextBuffer = "";
|
|
@@ -4745,6 +4864,12 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4745
4864
|
getCollectedParts() {
|
|
4746
4865
|
return [...this.collectedParts];
|
|
4747
4866
|
}
|
|
4867
|
+
/**
|
|
4868
|
+
* Get all streamed content that was actually sent to the user
|
|
4869
|
+
*/
|
|
4870
|
+
getAllStreamedContent() {
|
|
4871
|
+
return [...this.allStreamedContent];
|
|
4872
|
+
}
|
|
4748
4873
|
/**
|
|
4749
4874
|
* Parse buffer for complete artifacts and text parts (for text streaming)
|
|
4750
4875
|
*/
|
|
@@ -4755,7 +4880,11 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4755
4880
|
const safeEnd = this.artifactParser.findSafeTextBoundary(workingBuffer);
|
|
4756
4881
|
if (safeEnd > 0) {
|
|
4757
4882
|
const safeText = workingBuffer.slice(0, safeEnd);
|
|
4758
|
-
const parts2 = await this.artifactParser.parseText(
|
|
4883
|
+
const parts2 = await this.artifactParser.parseText(
|
|
4884
|
+
safeText,
|
|
4885
|
+
this.artifactMap,
|
|
4886
|
+
this.subAgentId
|
|
4887
|
+
);
|
|
4759
4888
|
completeParts.push(...parts2);
|
|
4760
4889
|
return {
|
|
4761
4890
|
completeParts,
|
|
@@ -4770,7 +4899,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4770
4899
|
const parts = await this.artifactParser.parseText(
|
|
4771
4900
|
workingBuffer,
|
|
4772
4901
|
this.artifactMap,
|
|
4773
|
-
this.
|
|
4902
|
+
this.subAgentId
|
|
4774
4903
|
);
|
|
4775
4904
|
if (parts.length > 0 && parts[parts.length - 1].kind === "text") {
|
|
4776
4905
|
const lastPart = parts[parts.length - 1];
|
|
@@ -4800,10 +4929,15 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4800
4929
|
*/
|
|
4801
4930
|
async streamPart(part) {
|
|
4802
4931
|
this.collectedParts.push({ ...part });
|
|
4932
|
+
this.allStreamedContent.push({ ...part });
|
|
4803
4933
|
if (this.collectedParts.length > _IncrementalStreamParser.MAX_COLLECTED_PARTS) {
|
|
4804
4934
|
const excess = this.collectedParts.length - _IncrementalStreamParser.MAX_COLLECTED_PARTS;
|
|
4805
4935
|
this.collectedParts.splice(0, excess);
|
|
4806
4936
|
}
|
|
4937
|
+
if (this.allStreamedContent.length > _IncrementalStreamParser.MAX_COLLECTED_PARTS) {
|
|
4938
|
+
const excess = this.allStreamedContent.length - _IncrementalStreamParser.MAX_COLLECTED_PARTS;
|
|
4939
|
+
this.allStreamedContent.splice(0, excess);
|
|
4940
|
+
}
|
|
4807
4941
|
if (!this.hasStartedRole) {
|
|
4808
4942
|
await this.streamHelper.writeRole("assistant");
|
|
4809
4943
|
this.hasStartedRole = true;
|
|
@@ -4844,12 +4978,12 @@ var IncrementalStreamParser = _IncrementalStreamParser;
|
|
|
4844
4978
|
|
|
4845
4979
|
// src/services/ResponseFormatter.ts
|
|
4846
4980
|
init_logger();
|
|
4847
|
-
var
|
|
4981
|
+
var logger11 = agentsCore.getLogger("ResponseFormatter");
|
|
4848
4982
|
var ResponseFormatter = class {
|
|
4849
4983
|
constructor(tenantId, artifactParserOptions) {
|
|
4850
4984
|
__publicField(this, "artifactParser");
|
|
4851
|
-
__publicField(this, "
|
|
4852
|
-
this.
|
|
4985
|
+
__publicField(this, "subAgentId");
|
|
4986
|
+
this.subAgentId = artifactParserOptions?.subAgentId;
|
|
4853
4987
|
if (artifactParserOptions?.streamRequestId) {
|
|
4854
4988
|
const sessionParser = graphSessionManager.getArtifactParser(
|
|
4855
4989
|
artifactParserOptions.streamRequestId
|
|
@@ -4888,7 +5022,7 @@ var ResponseFormatter = class {
|
|
|
4888
5022
|
const parts = await this.artifactParser.parseObject(
|
|
4889
5023
|
responseObject,
|
|
4890
5024
|
artifactMap,
|
|
4891
|
-
this.
|
|
5025
|
+
this.subAgentId
|
|
4892
5026
|
);
|
|
4893
5027
|
const uniqueArtifacts = this.countUniqueArtifacts(parts);
|
|
4894
5028
|
span.setAttributes({
|
|
@@ -4903,7 +5037,7 @@ var ResponseFormatter = class {
|
|
|
4903
5037
|
return { parts };
|
|
4904
5038
|
} catch (error) {
|
|
4905
5039
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4906
|
-
|
|
5040
|
+
logger11.error({ error, responseObject }, "Error formatting object response");
|
|
4907
5041
|
return {
|
|
4908
5042
|
parts: [{ kind: "data", data: responseObject }]
|
|
4909
5043
|
};
|
|
@@ -4935,7 +5069,11 @@ var ResponseFormatter = class {
|
|
|
4935
5069
|
"response.type": "text",
|
|
4936
5070
|
"response.availableArtifacts": artifactMap.size
|
|
4937
5071
|
});
|
|
4938
|
-
const parts = await this.artifactParser.parseText(
|
|
5072
|
+
const parts = await this.artifactParser.parseText(
|
|
5073
|
+
responseText,
|
|
5074
|
+
artifactMap,
|
|
5075
|
+
this.subAgentId
|
|
5076
|
+
);
|
|
4939
5077
|
if (parts.length === 1 && parts[0].kind === "text") {
|
|
4940
5078
|
return { text: parts[0].text };
|
|
4941
5079
|
}
|
|
@@ -4955,7 +5093,7 @@ var ResponseFormatter = class {
|
|
|
4955
5093
|
return { parts };
|
|
4956
5094
|
} catch (error) {
|
|
4957
5095
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4958
|
-
|
|
5096
|
+
logger11.error({ error, responseText }, "Error formatting response");
|
|
4959
5097
|
return { text: responseText };
|
|
4960
5098
|
} finally {
|
|
4961
5099
|
span.end();
|
|
@@ -5009,20 +5147,20 @@ function agentInitializingOp(sessionId, graphId) {
|
|
|
5009
5147
|
}
|
|
5010
5148
|
};
|
|
5011
5149
|
}
|
|
5012
|
-
function completionOp(
|
|
5150
|
+
function completionOp(subAgentId, iterations) {
|
|
5013
5151
|
return {
|
|
5014
5152
|
type: "completion",
|
|
5015
5153
|
details: {
|
|
5016
|
-
agent:
|
|
5154
|
+
agent: subAgentId,
|
|
5017
5155
|
iteration: iterations
|
|
5018
5156
|
}
|
|
5019
5157
|
};
|
|
5020
5158
|
}
|
|
5021
|
-
function errorOp(message,
|
|
5159
|
+
function errorOp(message, subAgentId, severity = "error", code) {
|
|
5022
5160
|
return {
|
|
5023
5161
|
type: "error",
|
|
5024
5162
|
message,
|
|
5025
|
-
agent:
|
|
5163
|
+
agent: subAgentId,
|
|
5026
5164
|
severity,
|
|
5027
5165
|
code,
|
|
5028
5166
|
timestamp: Date.now()
|
|
@@ -5037,10 +5175,10 @@ init_logger();
|
|
|
5037
5175
|
|
|
5038
5176
|
// src/utils/data-component-schema.ts
|
|
5039
5177
|
init_logger();
|
|
5040
|
-
var
|
|
5178
|
+
var logger12 = agentsCore.getLogger("DataComponentSchema");
|
|
5041
5179
|
function jsonSchemaToZod(jsonSchema) {
|
|
5042
5180
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
5043
|
-
|
|
5181
|
+
logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
5044
5182
|
return z6.z.string();
|
|
5045
5183
|
}
|
|
5046
5184
|
switch (jsonSchema.type) {
|
|
@@ -5067,7 +5205,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
5067
5205
|
case "null":
|
|
5068
5206
|
return z6.z.null();
|
|
5069
5207
|
default:
|
|
5070
|
-
|
|
5208
|
+
logger12.warn(
|
|
5071
5209
|
{
|
|
5072
5210
|
unsupportedType: jsonSchema.type,
|
|
5073
5211
|
schema: jsonSchema
|
|
@@ -5434,7 +5572,7 @@ function parseEmbeddedJson(data) {
|
|
|
5434
5572
|
|
|
5435
5573
|
// src/a2a/client.ts
|
|
5436
5574
|
init_logger();
|
|
5437
|
-
var
|
|
5575
|
+
var logger13 = agentsCore.getLogger("a2aClient");
|
|
5438
5576
|
var DEFAULT_BACKOFF = {
|
|
5439
5577
|
initialInterval: 500,
|
|
5440
5578
|
maxInterval: 6e4,
|
|
@@ -5640,7 +5778,7 @@ var A2AClient = class {
|
|
|
5640
5778
|
try {
|
|
5641
5779
|
const res = await fn();
|
|
5642
5780
|
if (attempt > 0) {
|
|
5643
|
-
|
|
5781
|
+
logger13.info(
|
|
5644
5782
|
{
|
|
5645
5783
|
attempts: attempt + 1,
|
|
5646
5784
|
elapsedTime: Date.now() - start
|
|
@@ -5655,7 +5793,7 @@ var A2AClient = class {
|
|
|
5655
5793
|
}
|
|
5656
5794
|
const elapsed = Date.now() - start;
|
|
5657
5795
|
if (elapsed > maxElapsedTime) {
|
|
5658
|
-
|
|
5796
|
+
logger13.warn(
|
|
5659
5797
|
{
|
|
5660
5798
|
attempts: attempt + 1,
|
|
5661
5799
|
elapsedTime: elapsed,
|
|
@@ -5676,7 +5814,7 @@ var A2AClient = class {
|
|
|
5676
5814
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
5677
5815
|
}
|
|
5678
5816
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
5679
|
-
|
|
5817
|
+
logger13.info(
|
|
5680
5818
|
{
|
|
5681
5819
|
attempt: attempt + 1,
|
|
5682
5820
|
delayMs,
|
|
@@ -5761,7 +5899,7 @@ var A2AClient = class {
|
|
|
5761
5899
|
}
|
|
5762
5900
|
const rpcResponse = await httpResponse.json();
|
|
5763
5901
|
if (rpcResponse.id !== requestId2) {
|
|
5764
|
-
|
|
5902
|
+
logger13.warn(
|
|
5765
5903
|
{
|
|
5766
5904
|
method,
|
|
5767
5905
|
expectedId: requestId2,
|
|
@@ -5960,7 +6098,7 @@ var A2AClient = class {
|
|
|
5960
6098
|
try {
|
|
5961
6099
|
while (true) {
|
|
5962
6100
|
const { done, value } = await reader.read();
|
|
5963
|
-
|
|
6101
|
+
logger13.info({ done, value }, "parseA2ASseStream");
|
|
5964
6102
|
if (done) {
|
|
5965
6103
|
if (eventDataBuffer.trim()) {
|
|
5966
6104
|
const result = this._processSseEventData(
|
|
@@ -6050,7 +6188,7 @@ var A2AClient = class {
|
|
|
6050
6188
|
init_conversations();
|
|
6051
6189
|
init_dbClient();
|
|
6052
6190
|
init_logger();
|
|
6053
|
-
var
|
|
6191
|
+
var logger14 = agentsCore.getLogger("relationships Tools");
|
|
6054
6192
|
var generateTransferToolDescription = (config) => {
|
|
6055
6193
|
return `Hand off the conversation to agent ${config.id}.
|
|
6056
6194
|
|
|
@@ -6074,7 +6212,7 @@ Delegate a specific task to agent ${config.id} when it seems like the agent can
|
|
|
6074
6212
|
var createTransferToAgentTool = ({
|
|
6075
6213
|
transferConfig,
|
|
6076
6214
|
callingAgentId,
|
|
6077
|
-
|
|
6215
|
+
subAgent,
|
|
6078
6216
|
streamRequestId
|
|
6079
6217
|
}) => {
|
|
6080
6218
|
return ai.tool({
|
|
@@ -6084,11 +6222,11 @@ var createTransferToAgentTool = ({
|
|
|
6084
6222
|
const activeSpan = api.trace.getActiveSpan();
|
|
6085
6223
|
if (activeSpan) {
|
|
6086
6224
|
activeSpan.setAttributes({
|
|
6087
|
-
|
|
6088
|
-
|
|
6225
|
+
[agentsCore.SPAN_KEYS.TRANSFER_FROM_SUB_AGENT_ID]: callingAgentId,
|
|
6226
|
+
[agentsCore.SPAN_KEYS.TRANSFER_TO_SUB_AGENT_ID]: transferConfig.id ?? "unknown"
|
|
6089
6227
|
});
|
|
6090
6228
|
}
|
|
6091
|
-
|
|
6229
|
+
logger14.info(
|
|
6092
6230
|
{
|
|
6093
6231
|
transferTo: transferConfig.id ?? "unknown",
|
|
6094
6232
|
fromAgent: callingAgentId
|
|
@@ -6097,8 +6235,8 @@ var createTransferToAgentTool = ({
|
|
|
6097
6235
|
);
|
|
6098
6236
|
if (streamRequestId) {
|
|
6099
6237
|
graphSessionManager.recordEvent(streamRequestId, "transfer", callingAgentId, {
|
|
6100
|
-
|
|
6101
|
-
|
|
6238
|
+
fromSubAgent: callingAgentId,
|
|
6239
|
+
targetSubAgent: transferConfig.id ?? "unknown",
|
|
6102
6240
|
reason: `Transfer to ${transferConfig.name || transferConfig.id}`
|
|
6103
6241
|
});
|
|
6104
6242
|
}
|
|
@@ -6120,7 +6258,7 @@ function createDelegateToAgentTool({
|
|
|
6120
6258
|
contextId,
|
|
6121
6259
|
metadata,
|
|
6122
6260
|
sessionId,
|
|
6123
|
-
|
|
6261
|
+
subAgent,
|
|
6124
6262
|
credentialStoreRegistry
|
|
6125
6263
|
}) {
|
|
6126
6264
|
return ai.tool({
|
|
@@ -6131,9 +6269,9 @@ function createDelegateToAgentTool({
|
|
|
6131
6269
|
const activeSpan = api.trace.getActiveSpan();
|
|
6132
6270
|
if (activeSpan) {
|
|
6133
6271
|
activeSpan.setAttributes({
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6272
|
+
[agentsCore.SPAN_KEYS.DELEGATION_FROM_SUB_AGENT_ID]: callingAgentId,
|
|
6273
|
+
[agentsCore.SPAN_KEYS.DELEGATION_TO_SUB_AGENT_ID]: delegateConfig.config.id ?? "unknown",
|
|
6274
|
+
[agentsCore.SPAN_KEYS.DELEGATION_ID]: delegationId
|
|
6137
6275
|
});
|
|
6138
6276
|
}
|
|
6139
6277
|
if (metadata.streamRequestId) {
|
|
@@ -6143,8 +6281,8 @@ function createDelegateToAgentTool({
|
|
|
6143
6281
|
callingAgentId,
|
|
6144
6282
|
{
|
|
6145
6283
|
delegationId,
|
|
6146
|
-
|
|
6147
|
-
|
|
6284
|
+
fromSubAgent: callingAgentId,
|
|
6285
|
+
targetSubAgent: delegateConfig.config.id,
|
|
6148
6286
|
taskDescription: input.message
|
|
6149
6287
|
}
|
|
6150
6288
|
);
|
|
@@ -6158,7 +6296,7 @@ function createDelegateToAgentTool({
|
|
|
6158
6296
|
projectId,
|
|
6159
6297
|
graphId
|
|
6160
6298
|
},
|
|
6161
|
-
|
|
6299
|
+
subAgentId: delegateConfig.config.id
|
|
6162
6300
|
});
|
|
6163
6301
|
if (externalAgent && (externalAgent.credentialReferenceId || externalAgent.headers) && credentialStoreRegistry) {
|
|
6164
6302
|
const contextResolver = new agentsCore.ContextResolver(
|
|
@@ -6237,7 +6375,7 @@ function createDelegateToAgentTool({
|
|
|
6237
6375
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
6238
6376
|
}
|
|
6239
6377
|
};
|
|
6240
|
-
|
|
6378
|
+
logger14.info({ messageToSend }, "messageToSend");
|
|
6241
6379
|
await agentsCore.createMessage(dbClient_default)({
|
|
6242
6380
|
id: nanoid.nanoid(),
|
|
6243
6381
|
tenantId,
|
|
@@ -6249,7 +6387,7 @@ function createDelegateToAgentTool({
|
|
|
6249
6387
|
},
|
|
6250
6388
|
visibility: isInternal ? "internal" : "external",
|
|
6251
6389
|
messageType: "a2a-request",
|
|
6252
|
-
|
|
6390
|
+
fromSubAgentId: callingAgentId,
|
|
6253
6391
|
...isInternal ? { toAgentId: delegateConfig.config.id } : { toExternalAgentId: delegateConfig.config.id }
|
|
6254
6392
|
});
|
|
6255
6393
|
const response = await a2aClient.sendMessage({
|
|
@@ -6264,8 +6402,8 @@ function createDelegateToAgentTool({
|
|
|
6264
6402
|
conversationId: contextId,
|
|
6265
6403
|
messageType: "a2a-response",
|
|
6266
6404
|
visibility: isInternal ? "internal" : "external",
|
|
6267
|
-
|
|
6268
|
-
...isInternal ? {
|
|
6405
|
+
toSubAgentId: callingAgentId,
|
|
6406
|
+
...isInternal ? { fromSubAgentId: delegateConfig.config.id } : { fromExternalAgentId: delegateConfig.config.id }
|
|
6269
6407
|
});
|
|
6270
6408
|
if (sessionId && context?.toolCallId) {
|
|
6271
6409
|
const toolResult = {
|
|
@@ -6284,8 +6422,8 @@ function createDelegateToAgentTool({
|
|
|
6284
6422
|
callingAgentId,
|
|
6285
6423
|
{
|
|
6286
6424
|
delegationId,
|
|
6287
|
-
|
|
6288
|
-
|
|
6425
|
+
fromSubAgent: delegateConfig.config.id,
|
|
6426
|
+
targetSubAgent: callingAgentId,
|
|
6289
6427
|
result: response.result
|
|
6290
6428
|
}
|
|
6291
6429
|
);
|
|
@@ -6300,7 +6438,7 @@ function createDelegateToAgentTool({
|
|
|
6300
6438
|
|
|
6301
6439
|
// src/agents/SystemPromptBuilder.ts
|
|
6302
6440
|
init_logger();
|
|
6303
|
-
var
|
|
6441
|
+
var logger15 = agentsCore.getLogger("SystemPromptBuilder");
|
|
6304
6442
|
var SystemPromptBuilder = class {
|
|
6305
6443
|
constructor(version, versionConfig) {
|
|
6306
6444
|
this.version = version;
|
|
@@ -6316,12 +6454,12 @@ var SystemPromptBuilder = class {
|
|
|
6316
6454
|
this.templates.set(name, content);
|
|
6317
6455
|
}
|
|
6318
6456
|
this.loaded = true;
|
|
6319
|
-
|
|
6457
|
+
logger15.debug(
|
|
6320
6458
|
{ templateCount: this.templates.size, version: this.version },
|
|
6321
6459
|
`Loaded ${this.templates.size} templates for version ${this.version}`
|
|
6322
6460
|
);
|
|
6323
6461
|
} catch (error) {
|
|
6324
|
-
|
|
6462
|
+
logger15.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
6325
6463
|
throw new Error(`Template loading failed: ${error}`);
|
|
6326
6464
|
}
|
|
6327
6465
|
}
|
|
@@ -7382,7 +7520,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
7382
7520
|
return false;
|
|
7383
7521
|
};
|
|
7384
7522
|
}
|
|
7385
|
-
var
|
|
7523
|
+
var logger18 = agentsCore.getLogger("Agent");
|
|
7386
7524
|
var CONSTANTS = {
|
|
7387
7525
|
MAX_GENERATION_STEPS: 12,
|
|
7388
7526
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -7612,7 +7750,7 @@ var Agent = class {
|
|
|
7612
7750
|
}
|
|
7613
7751
|
getRelationTools(runtimeContext, sessionId) {
|
|
7614
7752
|
const { transferRelations = [], delegateRelations = [] } = this.config;
|
|
7615
|
-
const createToolName = (prefix,
|
|
7753
|
+
const createToolName = (prefix, subAgentId) => `${prefix}_to_${subAgentId.toLowerCase().replace(/\s+/g, "_")}`;
|
|
7616
7754
|
return Object.fromEntries([
|
|
7617
7755
|
...transferRelations.map((agentConfig) => {
|
|
7618
7756
|
const toolName = createToolName("transfer", agentConfig.id);
|
|
@@ -7623,7 +7761,7 @@ var Agent = class {
|
|
|
7623
7761
|
createTransferToAgentTool({
|
|
7624
7762
|
transferConfig: agentConfig,
|
|
7625
7763
|
callingAgentId: this.config.id,
|
|
7626
|
-
|
|
7764
|
+
subAgent: this,
|
|
7627
7765
|
streamRequestId: runtimeContext?.metadata?.streamRequestId
|
|
7628
7766
|
}),
|
|
7629
7767
|
runtimeContext?.metadata?.streamRequestId,
|
|
@@ -7652,7 +7790,7 @@ var Agent = class {
|
|
|
7652
7790
|
apiKey: runtimeContext?.metadata?.apiKey
|
|
7653
7791
|
},
|
|
7654
7792
|
sessionId,
|
|
7655
|
-
|
|
7793
|
+
subAgent: this,
|
|
7656
7794
|
credentialStoreRegistry: this.credentialStoreRegistry
|
|
7657
7795
|
}),
|
|
7658
7796
|
runtimeContext?.metadata?.streamRequestId,
|
|
@@ -7686,14 +7824,14 @@ var Agent = class {
|
|
|
7686
7824
|
for (const toolSet of tools) {
|
|
7687
7825
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
7688
7826
|
if (!isValidTool(originalTool)) {
|
|
7689
|
-
|
|
7827
|
+
logger18.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
7690
7828
|
continue;
|
|
7691
7829
|
}
|
|
7692
7830
|
const sessionWrappedTool = ai.tool({
|
|
7693
7831
|
description: originalTool.description,
|
|
7694
7832
|
inputSchema: originalTool.inputSchema,
|
|
7695
7833
|
execute: async (args, { toolCallId }) => {
|
|
7696
|
-
|
|
7834
|
+
logger18.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
7697
7835
|
try {
|
|
7698
7836
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
7699
7837
|
const parsedResult = parseEmbeddedJson(rawResult);
|
|
@@ -7707,7 +7845,7 @@ var Agent = class {
|
|
|
7707
7845
|
});
|
|
7708
7846
|
return { result: enhancedResult, toolCallId };
|
|
7709
7847
|
} catch (error) {
|
|
7710
|
-
|
|
7848
|
+
logger18.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
7711
7849
|
throw error;
|
|
7712
7850
|
}
|
|
7713
7851
|
}
|
|
@@ -7752,7 +7890,7 @@ var Agent = class {
|
|
|
7752
7890
|
tenantId: this.config.tenantId,
|
|
7753
7891
|
projectId: this.config.projectId,
|
|
7754
7892
|
graphId: this.config.graphId,
|
|
7755
|
-
|
|
7893
|
+
subAgentId: this.config.id
|
|
7756
7894
|
}
|
|
7757
7895
|
});
|
|
7758
7896
|
const agentToolRelationHeaders = toolsForAgent.data.find((t) => t.toolId === tool3.id)?.headers || void 0;
|
|
@@ -7808,7 +7946,7 @@ var Agent = class {
|
|
|
7808
7946
|
headers: agentToolRelationHeaders
|
|
7809
7947
|
};
|
|
7810
7948
|
}
|
|
7811
|
-
|
|
7949
|
+
logger18.info(
|
|
7812
7950
|
{
|
|
7813
7951
|
toolName: tool3.name,
|
|
7814
7952
|
credentialReferenceId,
|
|
@@ -7833,10 +7971,10 @@ var Agent = class {
|
|
|
7833
7971
|
this.mcpClientCache.set(cacheKey, client);
|
|
7834
7972
|
} catch (error) {
|
|
7835
7973
|
this.mcpConnectionLocks.delete(cacheKey);
|
|
7836
|
-
|
|
7974
|
+
logger18.error(
|
|
7837
7975
|
{
|
|
7838
7976
|
toolName: tool3.name,
|
|
7839
|
-
|
|
7977
|
+
subAgentId: this.config.id,
|
|
7840
7978
|
cacheKey,
|
|
7841
7979
|
error: error instanceof Error ? error.message : String(error)
|
|
7842
7980
|
},
|
|
@@ -7846,6 +7984,45 @@ var Agent = class {
|
|
|
7846
7984
|
}
|
|
7847
7985
|
}
|
|
7848
7986
|
const tools = await client.tools();
|
|
7987
|
+
if (!tools || Object.keys(tools).length === 0) {
|
|
7988
|
+
const streamRequestId = this.getStreamRequestId();
|
|
7989
|
+
if (streamRequestId) {
|
|
7990
|
+
tracer.startActiveSpan(
|
|
7991
|
+
"ai.toolCall",
|
|
7992
|
+
{
|
|
7993
|
+
attributes: {
|
|
7994
|
+
"ai.toolCall.name": tool3.name,
|
|
7995
|
+
"ai.toolCall.args": JSON.stringify({ operation: "mcp_tool_discovery" }),
|
|
7996
|
+
"ai.toolCall.result": JSON.stringify({
|
|
7997
|
+
status: "no_tools_available",
|
|
7998
|
+
message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
|
|
7999
|
+
serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown",
|
|
8000
|
+
originalToolName: tool3.name
|
|
8001
|
+
}),
|
|
8002
|
+
"ai.toolType": "mcp",
|
|
8003
|
+
"ai.agentName": this.config.name || "unknown",
|
|
8004
|
+
"conversation.id": this.conversationId || "unknown",
|
|
8005
|
+
"graph.id": this.config.graphId || "unknown",
|
|
8006
|
+
"tenant.id": this.config.tenantId || "unknown",
|
|
8007
|
+
"project.id": this.config.projectId || "unknown"
|
|
8008
|
+
}
|
|
8009
|
+
},
|
|
8010
|
+
(span) => {
|
|
8011
|
+
agentsCore.setSpanWithError(span, new Error(`0 effective tools available for ${tool3.name}`));
|
|
8012
|
+
graphSessionManager.recordEvent(streamRequestId, "tool_execution", this.config.id, {
|
|
8013
|
+
toolName: tool3.name,
|
|
8014
|
+
args: { operation: "mcp_tool_discovery" },
|
|
8015
|
+
result: {
|
|
8016
|
+
status: "no_tools_available",
|
|
8017
|
+
message: `MCP server has 0 effective tools. Double check the selected tools in your graph and the active tools in the MCP server configuration.`,
|
|
8018
|
+
serverUrl: tool3.config.type === "mcp" ? tool3.config.mcp.server.url : "unknown"
|
|
8019
|
+
}
|
|
8020
|
+
});
|
|
8021
|
+
span.end();
|
|
8022
|
+
}
|
|
8023
|
+
);
|
|
8024
|
+
}
|
|
8025
|
+
}
|
|
7849
8026
|
return tools;
|
|
7850
8027
|
}
|
|
7851
8028
|
async createMcpConnection(tool3, serverConfig) {
|
|
@@ -7857,99 +8034,120 @@ var Agent = class {
|
|
|
7857
8034
|
await client.connect();
|
|
7858
8035
|
return client;
|
|
7859
8036
|
} catch (error) {
|
|
7860
|
-
|
|
8037
|
+
logger18.error(
|
|
7861
8038
|
{
|
|
7862
8039
|
toolName: tool3.name,
|
|
7863
|
-
|
|
8040
|
+
subAgentId: this.config.id,
|
|
7864
8041
|
error: error instanceof Error ? error.message : String(error)
|
|
7865
8042
|
},
|
|
7866
8043
|
"Agent failed to connect to MCP server"
|
|
7867
8044
|
);
|
|
8045
|
+
if (error instanceof Error) {
|
|
8046
|
+
if (error?.cause && JSON.stringify(error.cause).includes("ECONNREFUSED")) {
|
|
8047
|
+
const errorMessage = "Connection refused. Please check if the MCP server is running.";
|
|
8048
|
+
throw new Error(errorMessage);
|
|
8049
|
+
} else if (error.message.includes("404")) {
|
|
8050
|
+
const errorMessage = "Error accessing endpoint (HTTP 404)";
|
|
8051
|
+
throw new Error(errorMessage);
|
|
8052
|
+
} else {
|
|
8053
|
+
throw new Error(`MCP server connection failed: ${error.message}`);
|
|
8054
|
+
}
|
|
8055
|
+
}
|
|
7868
8056
|
throw error;
|
|
7869
8057
|
}
|
|
7870
8058
|
}
|
|
7871
8059
|
async getFunctionTools(sessionId, streamRequestId) {
|
|
7872
8060
|
const functionTools = {};
|
|
7873
8061
|
try {
|
|
7874
|
-
const
|
|
8062
|
+
const functionToolsForAgent = await agentsCore.getFunctionToolsForSubAgent(dbClient_default)({
|
|
7875
8063
|
scopes: {
|
|
7876
|
-
tenantId: this.config.tenantId
|
|
7877
|
-
projectId: this.config.projectId
|
|
7878
|
-
graphId: this.config.graphId
|
|
7879
|
-
|
|
7880
|
-
|
|
8064
|
+
tenantId: this.config.tenantId,
|
|
8065
|
+
projectId: this.config.projectId,
|
|
8066
|
+
graphId: this.config.graphId
|
|
8067
|
+
},
|
|
8068
|
+
subAgentId: this.config.id
|
|
7881
8069
|
});
|
|
7882
|
-
const
|
|
7883
|
-
|
|
7884
|
-
if (functionToolDefs.length === 0) {
|
|
8070
|
+
const functionToolsData = functionToolsForAgent.data || [];
|
|
8071
|
+
if (functionToolsData.length === 0) {
|
|
7885
8072
|
return functionTools;
|
|
7886
8073
|
}
|
|
7887
8074
|
const { LocalSandboxExecutor: LocalSandboxExecutor2 } = await Promise.resolve().then(() => (init_LocalSandboxExecutor(), LocalSandboxExecutor_exports));
|
|
7888
8075
|
const sandboxExecutor = LocalSandboxExecutor2.getInstance();
|
|
7889
|
-
for (const
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
8076
|
+
for (const functionToolDef of functionToolsData) {
|
|
8077
|
+
const functionId = functionToolDef.functionId;
|
|
8078
|
+
if (!functionId) {
|
|
8079
|
+
logger18.warn(
|
|
8080
|
+
{ functionToolId: functionToolDef.id },
|
|
8081
|
+
"Function tool missing functionId reference"
|
|
8082
|
+
);
|
|
8083
|
+
continue;
|
|
8084
|
+
}
|
|
8085
|
+
const functionData = await agentsCore.getFunction(dbClient_default)({
|
|
8086
|
+
functionId,
|
|
8087
|
+
scopes: {
|
|
8088
|
+
tenantId: this.config.tenantId || "default",
|
|
8089
|
+
projectId: this.config.projectId || "default"
|
|
7895
8090
|
}
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
|
|
7906
|
-
|
|
8091
|
+
});
|
|
8092
|
+
if (!functionData) {
|
|
8093
|
+
logger18.warn(
|
|
8094
|
+
{ functionId, functionToolId: functionToolDef.id },
|
|
8095
|
+
"Function not found in functions table"
|
|
8096
|
+
);
|
|
8097
|
+
continue;
|
|
8098
|
+
}
|
|
8099
|
+
const zodSchema = jsonSchemaToZod(functionData.inputSchema);
|
|
8100
|
+
const aiTool = ai.tool({
|
|
8101
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
8102
|
+
inputSchema: zodSchema,
|
|
8103
|
+
execute: async (args, { toolCallId }) => {
|
|
8104
|
+
logger18.debug(
|
|
8105
|
+
{ toolName: functionToolDef.name, toolCallId, args },
|
|
8106
|
+
"Function Tool Called"
|
|
7907
8107
|
);
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
8108
|
+
try {
|
|
8109
|
+
const project = await agentsCore.getProject(dbClient_default)({
|
|
8110
|
+
scopes: { tenantId: this.config.tenantId, projectId: this.config.projectId }
|
|
8111
|
+
});
|
|
8112
|
+
const defaultSandboxConfig = {
|
|
8113
|
+
provider: "local",
|
|
8114
|
+
runtime: "node22",
|
|
8115
|
+
timeout: 3e4,
|
|
8116
|
+
vcpus: 1
|
|
8117
|
+
};
|
|
8118
|
+
const result = await sandboxExecutor.executeFunctionTool(functionToolDef.id, args, {
|
|
8119
|
+
description: functionToolDef.description || functionToolDef.name,
|
|
8120
|
+
inputSchema: functionData.inputSchema || {},
|
|
8121
|
+
executeCode: functionData.executeCode,
|
|
8122
|
+
dependencies: functionData.dependencies || {},
|
|
8123
|
+
sandboxConfig: project?.sandboxConfig || defaultSandboxConfig
|
|
8124
|
+
});
|
|
8125
|
+
toolSessionManager.recordToolResult(sessionId || "", {
|
|
8126
|
+
toolCallId,
|
|
8127
|
+
toolName: functionToolDef.name,
|
|
8128
|
+
args,
|
|
8129
|
+
result,
|
|
8130
|
+
timestamp: Date.now()
|
|
8131
|
+
});
|
|
8132
|
+
return { result, toolCallId };
|
|
8133
|
+
} catch (error) {
|
|
8134
|
+
logger18.error(
|
|
8135
|
+
{ toolName: functionToolDef.name, toolCallId, error },
|
|
8136
|
+
"Function tool execution failed"
|
|
7918
8137
|
);
|
|
7919
|
-
|
|
7920
|
-
const result = await sandboxExecutor.executeFunctionTool(toolDef.tool.id, args, {
|
|
7921
|
-
description: toolDef.tool.description || toolDef.tool.name,
|
|
7922
|
-
inputSchema: functionData.inputSchema || {},
|
|
7923
|
-
executeCode: functionData.executeCode,
|
|
7924
|
-
dependencies: functionData.dependencies || {}
|
|
7925
|
-
});
|
|
7926
|
-
toolSessionManager.recordToolResult(sessionId || "", {
|
|
7927
|
-
toolCallId,
|
|
7928
|
-
toolName: toolDef.tool.name,
|
|
7929
|
-
args,
|
|
7930
|
-
result,
|
|
7931
|
-
timestamp: Date.now()
|
|
7932
|
-
});
|
|
7933
|
-
return { result, toolCallId };
|
|
7934
|
-
} catch (error) {
|
|
7935
|
-
logger19.error(
|
|
7936
|
-
{ toolName: toolDef.tool.name, toolCallId, error },
|
|
7937
|
-
"Function tool execution failed"
|
|
7938
|
-
);
|
|
7939
|
-
throw error;
|
|
7940
|
-
}
|
|
8138
|
+
throw error;
|
|
7941
8139
|
}
|
|
7942
|
-
}
|
|
7943
|
-
|
|
7944
|
-
|
|
7945
|
-
|
|
7946
|
-
|
|
7947
|
-
|
|
7948
|
-
|
|
7949
|
-
|
|
8140
|
+
}
|
|
8141
|
+
});
|
|
8142
|
+
functionTools[functionToolDef.name] = this.wrapToolWithStreaming(
|
|
8143
|
+
functionToolDef.name,
|
|
8144
|
+
aiTool,
|
|
8145
|
+
streamRequestId || "",
|
|
8146
|
+
"tool"
|
|
8147
|
+
);
|
|
7950
8148
|
}
|
|
7951
8149
|
} catch (error) {
|
|
7952
|
-
|
|
8150
|
+
logger18.error({ error }, "Failed to load function tools from database");
|
|
7953
8151
|
}
|
|
7954
8152
|
return functionTools;
|
|
7955
8153
|
}
|
|
@@ -7959,7 +8157,7 @@ var Agent = class {
|
|
|
7959
8157
|
async getResolvedContext(conversationId, headers) {
|
|
7960
8158
|
try {
|
|
7961
8159
|
if (!this.config.contextConfigId) {
|
|
7962
|
-
|
|
8160
|
+
logger18.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
7963
8161
|
return null;
|
|
7964
8162
|
}
|
|
7965
8163
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -7971,7 +8169,7 @@ var Agent = class {
|
|
|
7971
8169
|
id: this.config.contextConfigId
|
|
7972
8170
|
});
|
|
7973
8171
|
if (!contextConfig) {
|
|
7974
|
-
|
|
8172
|
+
logger18.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
7975
8173
|
return null;
|
|
7976
8174
|
}
|
|
7977
8175
|
if (!this.contextResolver) {
|
|
@@ -7988,7 +8186,7 @@ var Agent = class {
|
|
|
7988
8186
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7989
8187
|
$env: process.env
|
|
7990
8188
|
};
|
|
7991
|
-
|
|
8189
|
+
logger18.debug(
|
|
7992
8190
|
{
|
|
7993
8191
|
conversationId,
|
|
7994
8192
|
contextConfigId: contextConfig.id,
|
|
@@ -8002,7 +8200,7 @@ var Agent = class {
|
|
|
8002
8200
|
);
|
|
8003
8201
|
return contextWithBuiltins;
|
|
8004
8202
|
} catch (error) {
|
|
8005
|
-
|
|
8203
|
+
logger18.error(
|
|
8006
8204
|
{
|
|
8007
8205
|
conversationId,
|
|
8008
8206
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8026,7 +8224,7 @@ var Agent = class {
|
|
|
8026
8224
|
});
|
|
8027
8225
|
return graphDefinition?.graphPrompt || void 0;
|
|
8028
8226
|
} catch (error) {
|
|
8029
|
-
|
|
8227
|
+
logger18.warn(
|
|
8030
8228
|
{
|
|
8031
8229
|
graphId: this.config.graphId,
|
|
8032
8230
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8051,11 +8249,11 @@ var Agent = class {
|
|
|
8051
8249
|
if (!graphDefinition) {
|
|
8052
8250
|
return false;
|
|
8053
8251
|
}
|
|
8054
|
-
return Object.values(graphDefinition.
|
|
8055
|
-
(
|
|
8252
|
+
return Object.values(graphDefinition.subAgents).some(
|
|
8253
|
+
(subAgent) => "artifactComponents" in subAgent && subAgent.artifactComponents && subAgent.artifactComponents.length > 0
|
|
8056
8254
|
);
|
|
8057
8255
|
} catch (error) {
|
|
8058
|
-
|
|
8256
|
+
logger18.warn(
|
|
8059
8257
|
{
|
|
8060
8258
|
graphId: this.config.graphId,
|
|
8061
8259
|
tenantId: this.config.tenantId,
|
|
@@ -8084,7 +8282,7 @@ var Agent = class {
|
|
|
8084
8282
|
preserveUnresolved: false
|
|
8085
8283
|
});
|
|
8086
8284
|
} catch (error) {
|
|
8087
|
-
|
|
8285
|
+
logger18.error(
|
|
8088
8286
|
{
|
|
8089
8287
|
conversationId,
|
|
8090
8288
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8131,7 +8329,7 @@ var Agent = class {
|
|
|
8131
8329
|
preserveUnresolved: false
|
|
8132
8330
|
});
|
|
8133
8331
|
} catch (error) {
|
|
8134
|
-
|
|
8332
|
+
logger18.error(
|
|
8135
8333
|
{
|
|
8136
8334
|
conversationId,
|
|
8137
8335
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8146,7 +8344,7 @@ var Agent = class {
|
|
|
8146
8344
|
const functionTools = await this.getFunctionTools(streamRequestId || "");
|
|
8147
8345
|
const relationTools = this.getRelationTools(runtimeContext);
|
|
8148
8346
|
const allTools = { ...mcpTools, ...functionTools, ...relationTools };
|
|
8149
|
-
|
|
8347
|
+
logger18.info(
|
|
8150
8348
|
{
|
|
8151
8349
|
mcpTools: Object.keys(mcpTools),
|
|
8152
8350
|
functionTools: Object.keys(functionTools),
|
|
@@ -8185,7 +8383,7 @@ var Agent = class {
|
|
|
8185
8383
|
preserveUnresolved: false
|
|
8186
8384
|
});
|
|
8187
8385
|
} catch (error) {
|
|
8188
|
-
|
|
8386
|
+
logger18.error(
|
|
8189
8387
|
{
|
|
8190
8388
|
conversationId,
|
|
8191
8389
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8218,7 +8416,7 @@ var Agent = class {
|
|
|
8218
8416
|
toolCallId: z6.z.string().describe("The tool call ID associated with this artifact.")
|
|
8219
8417
|
}),
|
|
8220
8418
|
execute: async ({ artifactId, toolCallId }) => {
|
|
8221
|
-
|
|
8419
|
+
logger18.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
8222
8420
|
const streamRequestId = this.getStreamRequestId();
|
|
8223
8421
|
const artifactService = graphSessionManager.getArtifactService(streamRequestId);
|
|
8224
8422
|
if (!artifactService) {
|
|
@@ -8252,7 +8450,7 @@ var Agent = class {
|
|
|
8252
8450
|
});
|
|
8253
8451
|
}
|
|
8254
8452
|
// Provide a default tool set that is always available to the agent.
|
|
8255
|
-
async getDefaultTools(
|
|
8453
|
+
async getDefaultTools(streamRequestId) {
|
|
8256
8454
|
const defaultTools = {};
|
|
8257
8455
|
if (await this.graphHasArtifactComponents()) {
|
|
8258
8456
|
defaultTools.get_reference_artifact = this.getArtifactTools();
|
|
@@ -8478,7 +8676,7 @@ var Agent = class {
|
|
|
8478
8676
|
};
|
|
8479
8677
|
return enhanced;
|
|
8480
8678
|
} catch (error) {
|
|
8481
|
-
|
|
8679
|
+
logger18.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
8482
8680
|
return result;
|
|
8483
8681
|
}
|
|
8484
8682
|
}
|
|
@@ -8493,7 +8691,7 @@ var Agent = class {
|
|
|
8493
8691
|
}
|
|
8494
8692
|
});
|
|
8495
8693
|
} catch (error) {
|
|
8496
|
-
|
|
8694
|
+
logger18.error(
|
|
8497
8695
|
{ error, graphId: this.config.graphId },
|
|
8498
8696
|
"Failed to check graph artifact components"
|
|
8499
8697
|
);
|
|
@@ -8538,7 +8736,7 @@ var Agent = class {
|
|
|
8538
8736
|
// Thinking prompt without data components
|
|
8539
8737
|
this.getFunctionTools(sessionId, streamRequestId),
|
|
8540
8738
|
Promise.resolve(this.getRelationTools(runtimeContext, sessionId)),
|
|
8541
|
-
this.getDefaultTools(
|
|
8739
|
+
this.getDefaultTools(streamRequestId)
|
|
8542
8740
|
]);
|
|
8543
8741
|
childSpan.setStatus({ code: api.SpanStatusCode.OK });
|
|
8544
8742
|
return result;
|
|
@@ -8578,7 +8776,7 @@ var Agent = class {
|
|
|
8578
8776
|
currentMessage: userMessage,
|
|
8579
8777
|
options: historyConfig,
|
|
8580
8778
|
filters: {
|
|
8581
|
-
|
|
8779
|
+
subAgentId: this.config.id,
|
|
8582
8780
|
taskId
|
|
8583
8781
|
}
|
|
8584
8782
|
});
|
|
@@ -8594,7 +8792,7 @@ var Agent = class {
|
|
|
8594
8792
|
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;
|
|
8595
8793
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
8596
8794
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
8597
|
-
|
|
8795
|
+
logger18.warn(
|
|
8598
8796
|
{
|
|
8599
8797
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
8600
8798
|
appliedTimeout: timeoutMs,
|
|
@@ -8636,7 +8834,7 @@ var Agent = class {
|
|
|
8636
8834
|
}
|
|
8637
8835
|
);
|
|
8638
8836
|
} catch (error) {
|
|
8639
|
-
|
|
8837
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
8640
8838
|
}
|
|
8641
8839
|
}
|
|
8642
8840
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8663,7 +8861,7 @@ var Agent = class {
|
|
|
8663
8861
|
projectId: session?.projectId,
|
|
8664
8862
|
artifactComponents: this.artifactComponents,
|
|
8665
8863
|
streamRequestId: this.getStreamRequestId(),
|
|
8666
|
-
|
|
8864
|
+
subAgentId: this.config.id
|
|
8667
8865
|
};
|
|
8668
8866
|
const parser = new IncrementalStreamParser(
|
|
8669
8867
|
streamHelper,
|
|
@@ -8708,6 +8906,16 @@ var Agent = class {
|
|
|
8708
8906
|
}))
|
|
8709
8907
|
};
|
|
8710
8908
|
}
|
|
8909
|
+
const streamedContent = parser.getAllStreamedContent();
|
|
8910
|
+
if (streamedContent.length > 0) {
|
|
8911
|
+
response.streamedContent = {
|
|
8912
|
+
parts: streamedContent.map((part) => ({
|
|
8913
|
+
kind: part.kind,
|
|
8914
|
+
...part.kind === "text" && { text: part.text },
|
|
8915
|
+
...part.kind === "data" && { data: part.data }
|
|
8916
|
+
}))
|
|
8917
|
+
};
|
|
8918
|
+
}
|
|
8711
8919
|
} else {
|
|
8712
8920
|
let genConfig;
|
|
8713
8921
|
if (hasStructuredOutput) {
|
|
@@ -8740,7 +8948,7 @@ var Agent = class {
|
|
|
8740
8948
|
}
|
|
8741
8949
|
);
|
|
8742
8950
|
} catch (error) {
|
|
8743
|
-
|
|
8951
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
8744
8952
|
}
|
|
8745
8953
|
}
|
|
8746
8954
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8912,7 +9120,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8912
9120
|
projectId: session?.projectId,
|
|
8913
9121
|
artifactComponents: this.artifactComponents,
|
|
8914
9122
|
streamRequestId: this.getStreamRequestId(),
|
|
8915
|
-
|
|
9123
|
+
subAgentId: this.config.id
|
|
8916
9124
|
};
|
|
8917
9125
|
const parser = new IncrementalStreamParser(
|
|
8918
9126
|
streamHelper,
|
|
@@ -8995,7 +9203,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8995
9203
|
contextId,
|
|
8996
9204
|
artifactComponents: this.artifactComponents,
|
|
8997
9205
|
streamRequestId: this.getStreamRequestId(),
|
|
8998
|
-
|
|
9206
|
+
subAgentId: this.config.id
|
|
8999
9207
|
});
|
|
9000
9208
|
if (response.object) {
|
|
9001
9209
|
formattedContent = await responseFormatter.formatObjectResponse(
|
|
@@ -9032,7 +9240,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
9032
9240
|
};
|
|
9033
9241
|
|
|
9034
9242
|
// src/agents/generateTaskHandler.ts
|
|
9035
|
-
var
|
|
9243
|
+
var logger19 = agentsCore.getLogger("generateTaskHandler");
|
|
9036
9244
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
9037
9245
|
return async (task) => {
|
|
9038
9246
|
try {
|
|
@@ -9058,14 +9266,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9058
9266
|
projectId: config.projectId,
|
|
9059
9267
|
graphId: config.graphId
|
|
9060
9268
|
},
|
|
9061
|
-
|
|
9269
|
+
subAgentId: config.subAgentId
|
|
9062
9270
|
}),
|
|
9063
9271
|
agentsCore.getToolsForAgent(dbClient_default)({
|
|
9064
9272
|
scopes: {
|
|
9065
9273
|
tenantId: config.tenantId,
|
|
9066
9274
|
projectId: config.projectId,
|
|
9067
9275
|
graphId: config.graphId,
|
|
9068
|
-
|
|
9276
|
+
subAgentId: config.subAgentId
|
|
9069
9277
|
}
|
|
9070
9278
|
}),
|
|
9071
9279
|
agentsCore.getDataComponentsForAgent(dbClient_default)({
|
|
@@ -9073,7 +9281,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9073
9281
|
tenantId: config.tenantId,
|
|
9074
9282
|
projectId: config.projectId,
|
|
9075
9283
|
graphId: config.graphId,
|
|
9076
|
-
|
|
9284
|
+
subAgentId: config.subAgentId
|
|
9077
9285
|
}
|
|
9078
9286
|
}),
|
|
9079
9287
|
agentsCore.getArtifactComponentsForAgent(dbClient_default)({
|
|
@@ -9081,21 +9289,21 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9081
9289
|
tenantId: config.tenantId,
|
|
9082
9290
|
projectId: config.projectId,
|
|
9083
9291
|
graphId: config.graphId,
|
|
9084
|
-
|
|
9292
|
+
subAgentId: config.subAgentId
|
|
9085
9293
|
}
|
|
9086
9294
|
})
|
|
9087
9295
|
]);
|
|
9088
|
-
|
|
9296
|
+
logger19.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
9089
9297
|
const enhancedInternalRelations = await Promise.all(
|
|
9090
9298
|
internalRelations.map(async (relation) => {
|
|
9091
9299
|
try {
|
|
9092
|
-
const relatedAgent = await agentsCore.
|
|
9300
|
+
const relatedAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
9093
9301
|
scopes: {
|
|
9094
9302
|
tenantId: config.tenantId,
|
|
9095
9303
|
projectId: config.projectId,
|
|
9096
9304
|
graphId: config.graphId
|
|
9097
9305
|
},
|
|
9098
|
-
|
|
9306
|
+
subAgentId: relation.id
|
|
9099
9307
|
});
|
|
9100
9308
|
if (relatedAgent) {
|
|
9101
9309
|
const relatedAgentRelations = await agentsCore.getRelatedAgentsForGraph(dbClient_default)({
|
|
@@ -9104,7 +9312,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9104
9312
|
projectId: config.projectId,
|
|
9105
9313
|
graphId: config.graphId
|
|
9106
9314
|
},
|
|
9107
|
-
|
|
9315
|
+
subAgentId: relation.id
|
|
9108
9316
|
});
|
|
9109
9317
|
const enhancedDescription = generateDescriptionWithTransfers(
|
|
9110
9318
|
relation.description || "",
|
|
@@ -9114,7 +9322,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9114
9322
|
return { ...relation, description: enhancedDescription };
|
|
9115
9323
|
}
|
|
9116
9324
|
} catch (error) {
|
|
9117
|
-
|
|
9325
|
+
logger19.warn({ subAgentId: relation.id, error }, "Failed to enhance agent description");
|
|
9118
9326
|
}
|
|
9119
9327
|
return relation;
|
|
9120
9328
|
})
|
|
@@ -9129,7 +9337,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9129
9337
|
) ?? [];
|
|
9130
9338
|
const agent = new Agent(
|
|
9131
9339
|
{
|
|
9132
|
-
id: config.
|
|
9340
|
+
id: config.subAgentId,
|
|
9133
9341
|
tenantId: config.tenantId,
|
|
9134
9342
|
projectId: config.projectId,
|
|
9135
9343
|
graphId: config.graphId,
|
|
@@ -9140,7 +9348,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9140
9348
|
agentPrompt,
|
|
9141
9349
|
models: models || void 0,
|
|
9142
9350
|
stopWhen: stopWhen || void 0,
|
|
9143
|
-
|
|
9351
|
+
subAgentRelations: enhancedInternalRelations.map((relation) => ({
|
|
9144
9352
|
id: relation.id,
|
|
9145
9353
|
tenantId: config.tenantId,
|
|
9146
9354
|
projectId: config.projectId,
|
|
@@ -9151,7 +9359,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9151
9359
|
description: relation.description,
|
|
9152
9360
|
agentPrompt: "",
|
|
9153
9361
|
delegateRelations: [],
|
|
9154
|
-
|
|
9362
|
+
subAgentRelations: [],
|
|
9155
9363
|
transferRelations: []
|
|
9156
9364
|
})),
|
|
9157
9365
|
transferRelations: enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map((relation) => ({
|
|
@@ -9165,7 +9373,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9165
9373
|
description: relation.description,
|
|
9166
9374
|
agentPrompt: "",
|
|
9167
9375
|
delegateRelations: [],
|
|
9168
|
-
|
|
9376
|
+
subAgentRelations: [],
|
|
9169
9377
|
transferRelations: []
|
|
9170
9378
|
})),
|
|
9171
9379
|
delegateRelations: [
|
|
@@ -9183,7 +9391,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9183
9391
|
description: relation.description,
|
|
9184
9392
|
agentPrompt: "",
|
|
9185
9393
|
delegateRelations: [],
|
|
9186
|
-
|
|
9394
|
+
subAgentRelations: [],
|
|
9187
9395
|
transferRelations: []
|
|
9188
9396
|
}
|
|
9189
9397
|
})),
|
|
@@ -9218,11 +9426,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9218
9426
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
9219
9427
|
if (taskIdMatch) {
|
|
9220
9428
|
contextId = taskIdMatch[1];
|
|
9221
|
-
|
|
9429
|
+
logger19.info(
|
|
9222
9430
|
{
|
|
9223
9431
|
taskId: task.id,
|
|
9224
9432
|
extractedContextId: contextId,
|
|
9225
|
-
|
|
9433
|
+
subAgentId: config.subAgentId
|
|
9226
9434
|
},
|
|
9227
9435
|
"Extracted contextId from task ID for delegation"
|
|
9228
9436
|
);
|
|
@@ -9234,8 +9442,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9234
9442
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
9235
9443
|
agent.setDelegationStatus(isDelegation);
|
|
9236
9444
|
if (isDelegation) {
|
|
9237
|
-
|
|
9238
|
-
{
|
|
9445
|
+
logger19.info(
|
|
9446
|
+
{ subAgentId: config.subAgentId, taskId: task.id },
|
|
9239
9447
|
"Delegated agent - streaming disabled"
|
|
9240
9448
|
);
|
|
9241
9449
|
if (streamRequestId && config.tenantId && config.projectId) {
|
|
@@ -9332,13 +9540,13 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9332
9540
|
};
|
|
9333
9541
|
};
|
|
9334
9542
|
var createTaskHandlerConfig = async (params) => {
|
|
9335
|
-
const agent = await agentsCore.
|
|
9543
|
+
const agent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
9336
9544
|
scopes: {
|
|
9337
9545
|
tenantId: params.tenantId,
|
|
9338
9546
|
projectId: params.projectId,
|
|
9339
9547
|
graphId: params.graphId
|
|
9340
9548
|
},
|
|
9341
|
-
|
|
9549
|
+
subAgentId: params.subAgentId
|
|
9342
9550
|
});
|
|
9343
9551
|
const agentGraph = await agentsCore.getAgentGraphById(dbClient_default)({
|
|
9344
9552
|
scopes: {
|
|
@@ -9348,7 +9556,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
9348
9556
|
}
|
|
9349
9557
|
});
|
|
9350
9558
|
if (!agent) {
|
|
9351
|
-
throw new Error(`Agent not found: ${params.
|
|
9559
|
+
throw new Error(`Agent not found: ${params.subAgentId}`);
|
|
9352
9560
|
}
|
|
9353
9561
|
const effectiveModels = await resolveModelConfig(params.graphId, agent);
|
|
9354
9562
|
const effectiveConversationHistoryConfig = agent.conversationHistoryConfig || { mode: "full" };
|
|
@@ -9356,7 +9564,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
9356
9564
|
tenantId: params.tenantId,
|
|
9357
9565
|
projectId: params.projectId,
|
|
9358
9566
|
graphId: params.graphId,
|
|
9359
|
-
|
|
9567
|
+
subAgentId: params.subAgentId,
|
|
9360
9568
|
agentSchema: {
|
|
9361
9569
|
id: agent.id,
|
|
9362
9570
|
name: agent.name,
|
|
@@ -9385,25 +9593,27 @@ async function hydrateGraph({
|
|
|
9385
9593
|
apiKey
|
|
9386
9594
|
}) {
|
|
9387
9595
|
try {
|
|
9388
|
-
if (!dbGraph.
|
|
9596
|
+
if (!dbGraph.defaultSubAgentId) {
|
|
9389
9597
|
throw new Error(`Graph ${dbGraph.id} does not have a default agent configured`);
|
|
9390
9598
|
}
|
|
9391
|
-
const
|
|
9599
|
+
const defaultSubAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
9392
9600
|
scopes: {
|
|
9393
9601
|
tenantId: dbGraph.tenantId,
|
|
9394
9602
|
projectId: dbGraph.projectId,
|
|
9395
9603
|
graphId: dbGraph.id
|
|
9396
9604
|
},
|
|
9397
|
-
|
|
9605
|
+
subAgentId: dbGraph.defaultSubAgentId
|
|
9398
9606
|
});
|
|
9399
|
-
if (!
|
|
9400
|
-
throw new Error(
|
|
9607
|
+
if (!defaultSubAgent) {
|
|
9608
|
+
throw new Error(
|
|
9609
|
+
`Default agent ${dbGraph.defaultSubAgentId} not found for graph ${dbGraph.id}`
|
|
9610
|
+
);
|
|
9401
9611
|
}
|
|
9402
9612
|
const taskHandlerConfig = await createTaskHandlerConfig({
|
|
9403
9613
|
tenantId: dbGraph.tenantId,
|
|
9404
9614
|
projectId: dbGraph.projectId,
|
|
9405
9615
|
graphId: dbGraph.id,
|
|
9406
|
-
|
|
9616
|
+
subAgentId: dbGraph.defaultSubAgentId,
|
|
9407
9617
|
baseUrl,
|
|
9408
9618
|
apiKey
|
|
9409
9619
|
});
|
|
@@ -9432,7 +9642,7 @@ async function hydrateGraph({
|
|
|
9432
9642
|
}
|
|
9433
9643
|
};
|
|
9434
9644
|
return {
|
|
9435
|
-
|
|
9645
|
+
subAgentId: dbGraph.id,
|
|
9436
9646
|
// Use graph ID as agent ID for A2A purposes
|
|
9437
9647
|
tenantId: dbGraph.tenantId,
|
|
9438
9648
|
projectId: dbGraph.projectId,
|
|
@@ -9459,7 +9669,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
9459
9669
|
init_dbClient();
|
|
9460
9670
|
init_logger();
|
|
9461
9671
|
var app = new zodOpenapi.OpenAPIHono();
|
|
9462
|
-
var
|
|
9672
|
+
var logger20 = agentsCore.getLogger("agents");
|
|
9463
9673
|
app.openapi(
|
|
9464
9674
|
zodOpenapi.createRoute({
|
|
9465
9675
|
method: "get",
|
|
@@ -9497,7 +9707,7 @@ app.openapi(
|
|
|
9497
9707
|
tracestate: c.req.header("tracestate"),
|
|
9498
9708
|
baggage: c.req.header("baggage")
|
|
9499
9709
|
};
|
|
9500
|
-
|
|
9710
|
+
logger20.info(
|
|
9501
9711
|
{
|
|
9502
9712
|
otelHeaders,
|
|
9503
9713
|
path: c.req.path,
|
|
@@ -9506,22 +9716,22 @@ app.openapi(
|
|
|
9506
9716
|
"OpenTelemetry headers: well-known agent.json"
|
|
9507
9717
|
);
|
|
9508
9718
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
9509
|
-
const { tenantId, projectId, graphId,
|
|
9719
|
+
const { tenantId, projectId, graphId, subAgentId } = executionContext;
|
|
9510
9720
|
console.dir("executionContext", executionContext);
|
|
9511
|
-
if (
|
|
9512
|
-
|
|
9721
|
+
if (subAgentId) {
|
|
9722
|
+
logger20.info(
|
|
9513
9723
|
{
|
|
9514
9724
|
message: "getRegisteredAgent (agent-level)",
|
|
9515
9725
|
tenantId,
|
|
9516
9726
|
projectId,
|
|
9517
9727
|
graphId,
|
|
9518
|
-
|
|
9728
|
+
subAgentId
|
|
9519
9729
|
},
|
|
9520
9730
|
"agent-level well-known agent.json"
|
|
9521
9731
|
);
|
|
9522
9732
|
const credentialStores = c.get("credentialStores");
|
|
9523
9733
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
9524
|
-
|
|
9734
|
+
logger20.info({ agent }, "agent registered: well-known agent.json");
|
|
9525
9735
|
if (!agent) {
|
|
9526
9736
|
throw agentsCore.createApiError({
|
|
9527
9737
|
code: "not_found",
|
|
@@ -9530,7 +9740,7 @@ app.openapi(
|
|
|
9530
9740
|
}
|
|
9531
9741
|
return c.json(agent.agentCard);
|
|
9532
9742
|
} else {
|
|
9533
|
-
|
|
9743
|
+
logger20.info(
|
|
9534
9744
|
{
|
|
9535
9745
|
message: "getRegisteredGraph (graph-level)",
|
|
9536
9746
|
tenantId,
|
|
@@ -9556,7 +9766,7 @@ app.post("/a2a", async (c) => {
|
|
|
9556
9766
|
tracestate: c.req.header("tracestate"),
|
|
9557
9767
|
baggage: c.req.header("baggage")
|
|
9558
9768
|
};
|
|
9559
|
-
|
|
9769
|
+
logger20.info(
|
|
9560
9770
|
{
|
|
9561
9771
|
otelHeaders,
|
|
9562
9772
|
path: c.req.path,
|
|
@@ -9565,15 +9775,15 @@ app.post("/a2a", async (c) => {
|
|
|
9565
9775
|
"OpenTelemetry headers: a2a"
|
|
9566
9776
|
);
|
|
9567
9777
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
9568
|
-
const { tenantId, projectId, graphId,
|
|
9569
|
-
if (
|
|
9570
|
-
|
|
9778
|
+
const { tenantId, projectId, graphId, subAgentId } = executionContext;
|
|
9779
|
+
if (subAgentId) {
|
|
9780
|
+
logger20.info(
|
|
9571
9781
|
{
|
|
9572
9782
|
message: "a2a (agent-level)",
|
|
9573
9783
|
tenantId,
|
|
9574
9784
|
projectId,
|
|
9575
9785
|
graphId,
|
|
9576
|
-
|
|
9786
|
+
subAgentId
|
|
9577
9787
|
},
|
|
9578
9788
|
"agent-level a2a endpoint"
|
|
9579
9789
|
);
|
|
@@ -9591,7 +9801,7 @@ app.post("/a2a", async (c) => {
|
|
|
9591
9801
|
}
|
|
9592
9802
|
return a2aHandler(c, agent);
|
|
9593
9803
|
} else {
|
|
9594
|
-
|
|
9804
|
+
logger20.info(
|
|
9595
9805
|
{
|
|
9596
9806
|
message: "a2a (graph-level)",
|
|
9597
9807
|
tenantId,
|
|
@@ -9600,7 +9810,7 @@ app.post("/a2a", async (c) => {
|
|
|
9600
9810
|
},
|
|
9601
9811
|
"graph-level a2a endpoint"
|
|
9602
9812
|
);
|
|
9603
|
-
const graph = await agentsCore.
|
|
9813
|
+
const graph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
9604
9814
|
scopes: { tenantId, projectId, graphId }
|
|
9605
9815
|
});
|
|
9606
9816
|
if (!graph) {
|
|
@@ -9613,7 +9823,7 @@ app.post("/a2a", async (c) => {
|
|
|
9613
9823
|
404
|
|
9614
9824
|
);
|
|
9615
9825
|
}
|
|
9616
|
-
if (!graph.
|
|
9826
|
+
if (!graph.defaultSubAgentId) {
|
|
9617
9827
|
return c.json(
|
|
9618
9828
|
{
|
|
9619
9829
|
jsonrpc: "2.0",
|
|
@@ -9623,10 +9833,10 @@ app.post("/a2a", async (c) => {
|
|
|
9623
9833
|
400
|
|
9624
9834
|
);
|
|
9625
9835
|
}
|
|
9626
|
-
executionContext.
|
|
9836
|
+
executionContext.subAgentId = graph.defaultSubAgentId;
|
|
9627
9837
|
const credentialStores = c.get("credentialStores");
|
|
9628
|
-
const
|
|
9629
|
-
if (!
|
|
9838
|
+
const defaultSubAgent = await getRegisteredAgent(executionContext, credentialStores);
|
|
9839
|
+
if (!defaultSubAgent) {
|
|
9630
9840
|
return c.json(
|
|
9631
9841
|
{
|
|
9632
9842
|
jsonrpc: "2.0",
|
|
@@ -9636,7 +9846,7 @@ app.post("/a2a", async (c) => {
|
|
|
9636
9846
|
404
|
|
9637
9847
|
);
|
|
9638
9848
|
}
|
|
9639
|
-
return a2aHandler(c,
|
|
9849
|
+
return a2aHandler(c, defaultSubAgent);
|
|
9640
9850
|
}
|
|
9641
9851
|
});
|
|
9642
9852
|
var agents_default = app;
|
|
@@ -9647,20 +9857,20 @@ init_dbClient();
|
|
|
9647
9857
|
// src/a2a/transfer.ts
|
|
9648
9858
|
init_dbClient();
|
|
9649
9859
|
init_logger();
|
|
9650
|
-
var
|
|
9860
|
+
var logger21 = agentsCore.getLogger("Transfer");
|
|
9651
9861
|
async function executeTransfer({
|
|
9652
9862
|
tenantId,
|
|
9653
9863
|
threadId,
|
|
9654
9864
|
projectId,
|
|
9655
|
-
|
|
9865
|
+
targetSubAgentId
|
|
9656
9866
|
}) {
|
|
9657
|
-
|
|
9867
|
+
logger21.info({ targetAgent: targetSubAgentId }, "Executing transfer to agent");
|
|
9658
9868
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
9659
9869
|
scopes: { tenantId, projectId },
|
|
9660
9870
|
threadId,
|
|
9661
|
-
|
|
9871
|
+
subAgentId: targetSubAgentId
|
|
9662
9872
|
});
|
|
9663
|
-
return { success: true,
|
|
9873
|
+
return { success: true, targetSubAgentId };
|
|
9664
9874
|
}
|
|
9665
9875
|
function isTransferResponse(result) {
|
|
9666
9876
|
return result?.artifacts.some(
|
|
@@ -10240,7 +10450,7 @@ function createMCPStreamHelper() {
|
|
|
10240
10450
|
}
|
|
10241
10451
|
|
|
10242
10452
|
// src/handlers/executionHandler.ts
|
|
10243
|
-
var
|
|
10453
|
+
var logger22 = agentsCore.getLogger("ExecutionHandler");
|
|
10244
10454
|
var ExecutionHandler = class {
|
|
10245
10455
|
constructor() {
|
|
10246
10456
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -10276,7 +10486,7 @@ var ExecutionHandler = class {
|
|
|
10276
10486
|
if (emitOperations) {
|
|
10277
10487
|
graphSessionManager.enableEmitOperations(requestId2);
|
|
10278
10488
|
}
|
|
10279
|
-
|
|
10489
|
+
logger22.info(
|
|
10280
10490
|
{ sessionId: requestId2, graphId, conversationId, emitOperations },
|
|
10281
10491
|
"Created GraphSession for message execution"
|
|
10282
10492
|
);
|
|
@@ -10291,7 +10501,7 @@ var ExecutionHandler = class {
|
|
|
10291
10501
|
);
|
|
10292
10502
|
}
|
|
10293
10503
|
} catch (error) {
|
|
10294
|
-
|
|
10504
|
+
logger22.error(
|
|
10295
10505
|
{
|
|
10296
10506
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
10297
10507
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10307,7 +10517,7 @@ var ExecutionHandler = class {
|
|
|
10307
10517
|
try {
|
|
10308
10518
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
10309
10519
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
10310
|
-
|
|
10520
|
+
logger22.info(
|
|
10311
10521
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
10312
10522
|
"Attempting to create or reuse existing task"
|
|
10313
10523
|
);
|
|
@@ -10317,7 +10527,7 @@ var ExecutionHandler = class {
|
|
|
10317
10527
|
tenantId,
|
|
10318
10528
|
projectId,
|
|
10319
10529
|
graphId,
|
|
10320
|
-
|
|
10530
|
+
subAgentId: currentAgentId,
|
|
10321
10531
|
contextId: conversationId,
|
|
10322
10532
|
status: "pending",
|
|
10323
10533
|
metadata: {
|
|
@@ -10331,7 +10541,7 @@ var ExecutionHandler = class {
|
|
|
10331
10541
|
agent_id: currentAgentId
|
|
10332
10542
|
}
|
|
10333
10543
|
});
|
|
10334
|
-
|
|
10544
|
+
logger22.info(
|
|
10335
10545
|
{
|
|
10336
10546
|
taskId,
|
|
10337
10547
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -10340,27 +10550,27 @@ var ExecutionHandler = class {
|
|
|
10340
10550
|
);
|
|
10341
10551
|
} catch (error) {
|
|
10342
10552
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
10343
|
-
|
|
10553
|
+
logger22.info(
|
|
10344
10554
|
{ taskId, error: error.message },
|
|
10345
10555
|
"Task already exists, fetching existing task"
|
|
10346
10556
|
);
|
|
10347
10557
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
10348
10558
|
if (existingTask) {
|
|
10349
10559
|
task = existingTask;
|
|
10350
|
-
|
|
10560
|
+
logger22.info(
|
|
10351
10561
|
{ taskId, existingTask },
|
|
10352
10562
|
"Successfully reused existing task from race condition"
|
|
10353
10563
|
);
|
|
10354
10564
|
} else {
|
|
10355
|
-
|
|
10565
|
+
logger22.error({ taskId, error }, "Task constraint failed but task not found");
|
|
10356
10566
|
throw error;
|
|
10357
10567
|
}
|
|
10358
10568
|
} else {
|
|
10359
|
-
|
|
10569
|
+
logger22.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
10360
10570
|
throw error;
|
|
10361
10571
|
}
|
|
10362
10572
|
}
|
|
10363
|
-
|
|
10573
|
+
logger22.debug(
|
|
10364
10574
|
{
|
|
10365
10575
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10366
10576
|
executionType: "create_initial_task",
|
|
@@ -10378,7 +10588,7 @@ var ExecutionHandler = class {
|
|
|
10378
10588
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
10379
10589
|
while (iterations < maxTransfers) {
|
|
10380
10590
|
iterations++;
|
|
10381
|
-
|
|
10591
|
+
logger22.info(
|
|
10382
10592
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
10383
10593
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
10384
10594
|
);
|
|
@@ -10386,10 +10596,10 @@ var ExecutionHandler = class {
|
|
|
10386
10596
|
scopes: { tenantId, projectId },
|
|
10387
10597
|
conversationId
|
|
10388
10598
|
});
|
|
10389
|
-
|
|
10390
|
-
if (activeAgent && activeAgent.
|
|
10391
|
-
currentAgentId = activeAgent.
|
|
10392
|
-
|
|
10599
|
+
logger22.info({ activeAgent }, "activeAgent");
|
|
10600
|
+
if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
|
|
10601
|
+
currentAgentId = activeAgent.activeSubAgentId;
|
|
10602
|
+
logger22.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
10393
10603
|
}
|
|
10394
10604
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
10395
10605
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -10430,13 +10640,13 @@ var ExecutionHandler = class {
|
|
|
10430
10640
|
});
|
|
10431
10641
|
if (!messageResponse?.result) {
|
|
10432
10642
|
errorCount++;
|
|
10433
|
-
|
|
10643
|
+
logger22.error(
|
|
10434
10644
|
{ currentAgentId, iterations, errorCount },
|
|
10435
10645
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10436
10646
|
);
|
|
10437
10647
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10438
10648
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10439
|
-
|
|
10649
|
+
logger22.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10440
10650
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10441
10651
|
if (task) {
|
|
10442
10652
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10459,20 +10669,20 @@ var ExecutionHandler = class {
|
|
|
10459
10669
|
}
|
|
10460
10670
|
if (isTransferResponse(messageResponse.result)) {
|
|
10461
10671
|
const transferResponse = messageResponse.result;
|
|
10462
|
-
const
|
|
10672
|
+
const targetSubAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetSubAgentId;
|
|
10463
10673
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
10464
|
-
|
|
10674
|
+
logger22.info({ targetSubAgentId, transferReason }, "transfer response");
|
|
10465
10675
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
10466
|
-
const { success,
|
|
10676
|
+
const { success, targetSubAgentId: newAgentId } = await executeTransfer({
|
|
10467
10677
|
projectId,
|
|
10468
10678
|
tenantId,
|
|
10469
10679
|
threadId: conversationId,
|
|
10470
|
-
|
|
10680
|
+
targetSubAgentId
|
|
10471
10681
|
});
|
|
10472
10682
|
if (success) {
|
|
10473
10683
|
fromAgentId = currentAgentId;
|
|
10474
10684
|
currentAgentId = newAgentId;
|
|
10475
|
-
|
|
10685
|
+
logger22.info(
|
|
10476
10686
|
{
|
|
10477
10687
|
transferFrom: fromAgentId,
|
|
10478
10688
|
transferTo: currentAgentId,
|
|
@@ -10483,14 +10693,27 @@ var ExecutionHandler = class {
|
|
|
10483
10693
|
}
|
|
10484
10694
|
continue;
|
|
10485
10695
|
}
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10696
|
+
let responseParts = [];
|
|
10697
|
+
if (messageResponse.result.streamedContent?.parts) {
|
|
10698
|
+
responseParts = messageResponse.result.streamedContent.parts;
|
|
10699
|
+
logger22.info(
|
|
10700
|
+
{ partsCount: responseParts.length },
|
|
10701
|
+
"Using streamed content for conversation history"
|
|
10702
|
+
);
|
|
10703
|
+
} else {
|
|
10704
|
+
responseParts = messageResponse.result.artifacts?.flatMap(
|
|
10705
|
+
(artifact) => artifact.parts || []
|
|
10706
|
+
) || [];
|
|
10707
|
+
logger22.info(
|
|
10708
|
+
{ partsCount: responseParts.length },
|
|
10709
|
+
"Using artifacts for conversation history (fallback)"
|
|
10710
|
+
);
|
|
10711
|
+
}
|
|
10489
10712
|
if (responseParts && responseParts.length > 0) {
|
|
10490
10713
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
10491
10714
|
if (graphSessionData) {
|
|
10492
10715
|
const sessionSummary = graphSessionData.getSummary();
|
|
10493
|
-
|
|
10716
|
+
logger22.info(sessionSummary, "GraphSession data after completion");
|
|
10494
10717
|
}
|
|
10495
10718
|
let textContent = "";
|
|
10496
10719
|
for (const part of responseParts) {
|
|
@@ -10522,8 +10745,7 @@ var ExecutionHandler = class {
|
|
|
10522
10745
|
},
|
|
10523
10746
|
visibility: "user-facing",
|
|
10524
10747
|
messageType: "chat",
|
|
10525
|
-
|
|
10526
|
-
fromAgentId: currentAgentId,
|
|
10748
|
+
fromSubAgentId: currentAgentId,
|
|
10527
10749
|
taskId: task.id
|
|
10528
10750
|
});
|
|
10529
10751
|
const updateTaskStart = Date.now();
|
|
@@ -10544,22 +10766,22 @@ var ExecutionHandler = class {
|
|
|
10544
10766
|
}
|
|
10545
10767
|
});
|
|
10546
10768
|
const updateTaskEnd = Date.now();
|
|
10547
|
-
|
|
10769
|
+
logger22.info(
|
|
10548
10770
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
10549
10771
|
"Completed updateTask operation"
|
|
10550
10772
|
);
|
|
10551
10773
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
10552
10774
|
await sseHelper.complete();
|
|
10553
|
-
|
|
10775
|
+
logger22.info({}, "Ending GraphSession and cleaning up");
|
|
10554
10776
|
graphSessionManager.endSession(requestId2);
|
|
10555
|
-
|
|
10777
|
+
logger22.info({}, "Cleaning up streamHelper");
|
|
10556
10778
|
unregisterStreamHelper(requestId2);
|
|
10557
10779
|
let response;
|
|
10558
10780
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
10559
10781
|
const captured = sseHelper.getCapturedResponse();
|
|
10560
10782
|
response = captured.text || "No response content";
|
|
10561
10783
|
}
|
|
10562
|
-
|
|
10784
|
+
logger22.info({}, "ExecutionHandler returning success");
|
|
10563
10785
|
return { success: true, iterations, response };
|
|
10564
10786
|
} catch (error) {
|
|
10565
10787
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -10570,13 +10792,13 @@ var ExecutionHandler = class {
|
|
|
10570
10792
|
});
|
|
10571
10793
|
}
|
|
10572
10794
|
errorCount++;
|
|
10573
|
-
|
|
10795
|
+
logger22.warn(
|
|
10574
10796
|
{ iterations, errorCount },
|
|
10575
10797
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10576
10798
|
);
|
|
10577
10799
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10578
10800
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10579
|
-
|
|
10801
|
+
logger22.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10580
10802
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10581
10803
|
if (task) {
|
|
10582
10804
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10597,7 +10819,7 @@ var ExecutionHandler = class {
|
|
|
10597
10819
|
}
|
|
10598
10820
|
}
|
|
10599
10821
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
10600
|
-
|
|
10822
|
+
logger22.error({ maxTransfers, iterations }, errorMessage);
|
|
10601
10823
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
10602
10824
|
if (task) {
|
|
10603
10825
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -10616,7 +10838,7 @@ var ExecutionHandler = class {
|
|
|
10616
10838
|
unregisterStreamHelper(requestId2);
|
|
10617
10839
|
return { success: false, error: errorMessage, iterations };
|
|
10618
10840
|
} catch (error) {
|
|
10619
|
-
|
|
10841
|
+
logger22.error({ error }, "Error in execution handler");
|
|
10620
10842
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
10621
10843
|
await sseHelper.writeOperation(
|
|
10622
10844
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -10644,7 +10866,7 @@ var ExecutionHandler = class {
|
|
|
10644
10866
|
// src/routes/chat.ts
|
|
10645
10867
|
init_logger();
|
|
10646
10868
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
10647
|
-
var
|
|
10869
|
+
var logger23 = agentsCore.getLogger("completionsHandler");
|
|
10648
10870
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
10649
10871
|
method: "post",
|
|
10650
10872
|
path: "/completions",
|
|
@@ -10762,7 +10984,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10762
10984
|
tracestate: c.req.header("tracestate"),
|
|
10763
10985
|
baggage: c.req.header("baggage")
|
|
10764
10986
|
};
|
|
10765
|
-
|
|
10987
|
+
logger23.info(
|
|
10766
10988
|
{
|
|
10767
10989
|
otelHeaders,
|
|
10768
10990
|
path: c.req.path,
|
|
@@ -10786,20 +11008,20 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10786
11008
|
scopes: { tenantId, projectId, graphId }
|
|
10787
11009
|
});
|
|
10788
11010
|
let agentGraph;
|
|
10789
|
-
let
|
|
11011
|
+
let defaultSubAgentId;
|
|
10790
11012
|
if (fullGraph) {
|
|
10791
11013
|
agentGraph = {
|
|
10792
11014
|
id: fullGraph.id,
|
|
10793
11015
|
name: fullGraph.name,
|
|
10794
11016
|
tenantId,
|
|
10795
11017
|
projectId,
|
|
10796
|
-
|
|
11018
|
+
defaultSubAgentId: fullGraph.defaultSubAgentId
|
|
10797
11019
|
};
|
|
10798
|
-
const agentKeys = Object.keys(fullGraph.
|
|
11020
|
+
const agentKeys = Object.keys(fullGraph.subAgents || {});
|
|
10799
11021
|
const firstAgentId = agentKeys.length > 0 ? agentKeys[0] : "";
|
|
10800
|
-
|
|
11022
|
+
defaultSubAgentId = fullGraph.defaultSubAgentId || firstAgentId;
|
|
10801
11023
|
} else {
|
|
10802
|
-
agentGraph = await agentsCore.
|
|
11024
|
+
agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
10803
11025
|
scopes: { tenantId, projectId, graphId }
|
|
10804
11026
|
});
|
|
10805
11027
|
if (!agentGraph) {
|
|
@@ -10808,9 +11030,9 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10808
11030
|
message: "Agent graph not found"
|
|
10809
11031
|
});
|
|
10810
11032
|
}
|
|
10811
|
-
|
|
11033
|
+
defaultSubAgentId = agentGraph.defaultSubAgentId || "";
|
|
10812
11034
|
}
|
|
10813
|
-
if (!
|
|
11035
|
+
if (!defaultSubAgentId) {
|
|
10814
11036
|
throw agentsCore.createApiError({
|
|
10815
11037
|
code: "not_found",
|
|
10816
11038
|
message: "No default agent found in graph"
|
|
@@ -10820,7 +11042,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10820
11042
|
tenantId,
|
|
10821
11043
|
projectId,
|
|
10822
11044
|
id: conversationId,
|
|
10823
|
-
|
|
11045
|
+
activeSubAgentId: defaultSubAgentId
|
|
10824
11046
|
});
|
|
10825
11047
|
const activeAgent = await agentsCore.getActiveAgentForConversation(dbClient_default)({
|
|
10826
11048
|
scopes: { tenantId, projectId },
|
|
@@ -10830,13 +11052,13 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10830
11052
|
agentsCore.setActiveAgentForConversation(dbClient_default)({
|
|
10831
11053
|
scopes: { tenantId, projectId },
|
|
10832
11054
|
conversationId,
|
|
10833
|
-
|
|
11055
|
+
subAgentId: defaultSubAgentId
|
|
10834
11056
|
});
|
|
10835
11057
|
}
|
|
10836
|
-
const
|
|
10837
|
-
const agentInfo = await agentsCore.
|
|
11058
|
+
const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
|
|
11059
|
+
const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
|
|
10838
11060
|
scopes: { tenantId, projectId, graphId },
|
|
10839
|
-
|
|
11061
|
+
subAgentId
|
|
10840
11062
|
});
|
|
10841
11063
|
if (!agentInfo) {
|
|
10842
11064
|
throw agentsCore.createApiError({
|
|
@@ -10855,14 +11077,14 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10855
11077
|
dbClient: dbClient_default,
|
|
10856
11078
|
credentialStores
|
|
10857
11079
|
});
|
|
10858
|
-
|
|
11080
|
+
logger23.info(
|
|
10859
11081
|
{
|
|
10860
11082
|
tenantId,
|
|
10861
11083
|
projectId,
|
|
10862
11084
|
graphId,
|
|
10863
11085
|
conversationId,
|
|
10864
|
-
|
|
10865
|
-
|
|
11086
|
+
defaultSubAgentId,
|
|
11087
|
+
activeSubAgentId: activeAgent?.activeSubAgentId || "none",
|
|
10866
11088
|
hasContextConfig: !!agentGraph.contextConfigId,
|
|
10867
11089
|
hasHeaders: !!body.headers,
|
|
10868
11090
|
hasValidatedContext: !!validatedContext,
|
|
@@ -10903,7 +11125,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10903
11125
|
try {
|
|
10904
11126
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
10905
11127
|
await sseHelper.writeRole();
|
|
10906
|
-
|
|
11128
|
+
logger23.info({ subAgentId }, "Starting execution");
|
|
10907
11129
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
10908
11130
|
const emitOperations = emitOperationsHeader === "true";
|
|
10909
11131
|
const executionHandler = new ExecutionHandler();
|
|
@@ -10911,12 +11133,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10911
11133
|
executionContext,
|
|
10912
11134
|
conversationId,
|
|
10913
11135
|
userMessage,
|
|
10914
|
-
initialAgentId:
|
|
11136
|
+
initialAgentId: subAgentId,
|
|
10915
11137
|
requestId: requestId2,
|
|
10916
11138
|
sseHelper,
|
|
10917
11139
|
emitOperations
|
|
10918
11140
|
});
|
|
10919
|
-
|
|
11141
|
+
logger23.info(
|
|
10920
11142
|
{ result },
|
|
10921
11143
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10922
11144
|
);
|
|
@@ -10930,7 +11152,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10930
11152
|
}
|
|
10931
11153
|
await sseHelper.complete();
|
|
10932
11154
|
} catch (error) {
|
|
10933
|
-
|
|
11155
|
+
logger23.error(
|
|
10934
11156
|
{
|
|
10935
11157
|
error: error instanceof Error ? error.message : error,
|
|
10936
11158
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10947,12 +11169,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10947
11169
|
);
|
|
10948
11170
|
await sseHelper.complete();
|
|
10949
11171
|
} catch (streamError) {
|
|
10950
|
-
|
|
11172
|
+
logger23.error({ streamError }, "Failed to write error to stream");
|
|
10951
11173
|
}
|
|
10952
11174
|
}
|
|
10953
11175
|
});
|
|
10954
11176
|
} catch (error) {
|
|
10955
|
-
|
|
11177
|
+
logger23.error(
|
|
10956
11178
|
{
|
|
10957
11179
|
error: error instanceof Error ? error.message : error,
|
|
10958
11180
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10980,7 +11202,7 @@ var chat_default = app2;
|
|
|
10980
11202
|
init_dbClient();
|
|
10981
11203
|
init_logger();
|
|
10982
11204
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
10983
|
-
var
|
|
11205
|
+
var logger24 = agentsCore.getLogger("chatDataStream");
|
|
10984
11206
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
10985
11207
|
method: "post",
|
|
10986
11208
|
path: "/chat",
|
|
@@ -11045,7 +11267,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11045
11267
|
"project.id": projectId
|
|
11046
11268
|
});
|
|
11047
11269
|
}
|
|
11048
|
-
const agentGraph = await agentsCore.
|
|
11270
|
+
const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
11049
11271
|
scopes: { tenantId, projectId, graphId }
|
|
11050
11272
|
});
|
|
11051
11273
|
if (!agentGraph) {
|
|
@@ -11054,9 +11276,9 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11054
11276
|
message: "Agent graph not found"
|
|
11055
11277
|
});
|
|
11056
11278
|
}
|
|
11057
|
-
const
|
|
11279
|
+
const defaultSubAgentId = agentGraph.defaultSubAgentId;
|
|
11058
11280
|
const graphName = agentGraph.name;
|
|
11059
|
-
if (!
|
|
11281
|
+
if (!defaultSubAgentId) {
|
|
11060
11282
|
throw agentsCore.createApiError({
|
|
11061
11283
|
code: "bad_request",
|
|
11062
11284
|
message: "Graph does not have a default agent configured"
|
|
@@ -11070,13 +11292,13 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11070
11292
|
agentsCore.setActiveAgentForConversation(dbClient_default)({
|
|
11071
11293
|
scopes: { tenantId, projectId },
|
|
11072
11294
|
conversationId,
|
|
11073
|
-
|
|
11295
|
+
subAgentId: defaultSubAgentId
|
|
11074
11296
|
});
|
|
11075
11297
|
}
|
|
11076
|
-
const
|
|
11077
|
-
const agentInfo = await agentsCore.
|
|
11298
|
+
const subAgentId = activeAgent?.activeSubAgentId || defaultSubAgentId;
|
|
11299
|
+
const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
|
|
11078
11300
|
scopes: { tenantId, projectId, graphId },
|
|
11079
|
-
|
|
11301
|
+
subAgentId
|
|
11080
11302
|
});
|
|
11081
11303
|
if (!agentInfo) {
|
|
11082
11304
|
throw agentsCore.createApiError({
|
|
@@ -11097,7 +11319,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11097
11319
|
});
|
|
11098
11320
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
11099
11321
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
11100
|
-
|
|
11322
|
+
logger24.info({ userText, lastUserMessage }, "userText");
|
|
11101
11323
|
const messageSpan = api.trace.getActiveSpan();
|
|
11102
11324
|
if (messageSpan) {
|
|
11103
11325
|
messageSpan.setAttributes({
|
|
@@ -11133,7 +11355,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11133
11355
|
executionContext,
|
|
11134
11356
|
conversationId,
|
|
11135
11357
|
userMessage: userText,
|
|
11136
|
-
initialAgentId:
|
|
11358
|
+
initialAgentId: subAgentId,
|
|
11137
11359
|
requestId: `chatds-${Date.now()}`,
|
|
11138
11360
|
sseHelper: streamHelper,
|
|
11139
11361
|
emitOperations
|
|
@@ -11142,7 +11364,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11142
11364
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
11143
11365
|
}
|
|
11144
11366
|
} catch (err) {
|
|
11145
|
-
|
|
11367
|
+
logger24.error({ err }, "Streaming error");
|
|
11146
11368
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
11147
11369
|
} finally {
|
|
11148
11370
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -11163,7 +11385,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11163
11385
|
)
|
|
11164
11386
|
);
|
|
11165
11387
|
} catch (error) {
|
|
11166
|
-
|
|
11388
|
+
logger24.error({ error }, "chatDataStream error");
|
|
11167
11389
|
throw agentsCore.createApiError({
|
|
11168
11390
|
code: "internal_server_error",
|
|
11169
11391
|
message: "Failed to process chat completion"
|
|
@@ -11178,7 +11400,7 @@ init_logger();
|
|
|
11178
11400
|
function createMCPSchema(schema) {
|
|
11179
11401
|
return schema;
|
|
11180
11402
|
}
|
|
11181
|
-
var
|
|
11403
|
+
var logger25 = agentsCore.getLogger("mcp");
|
|
11182
11404
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
11183
11405
|
constructor() {
|
|
11184
11406
|
__publicField(this, "mockRes");
|
|
@@ -11233,21 +11455,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
11233
11455
|
id: 0
|
|
11234
11456
|
});
|
|
11235
11457
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
11236
|
-
|
|
11458
|
+
logger25.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
11237
11459
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
11238
11460
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
11239
11461
|
try {
|
|
11240
11462
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
11241
|
-
|
|
11463
|
+
logger25.info({ sessionId }, "Successfully spoofed initialization");
|
|
11242
11464
|
} catch (spoofError) {
|
|
11243
|
-
|
|
11465
|
+
logger25.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
11244
11466
|
}
|
|
11245
11467
|
};
|
|
11246
11468
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
11247
11469
|
const sessionId = req.headers["mcp-session-id"];
|
|
11248
|
-
|
|
11470
|
+
logger25.info({ sessionId }, "Received MCP session ID");
|
|
11249
11471
|
if (!sessionId) {
|
|
11250
|
-
|
|
11472
|
+
logger25.info({ body }, "Missing session ID");
|
|
11251
11473
|
res.writeHead(400).end(
|
|
11252
11474
|
JSON.stringify({
|
|
11253
11475
|
jsonrpc: "2.0",
|
|
@@ -11273,7 +11495,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
11273
11495
|
scopes: { tenantId, projectId },
|
|
11274
11496
|
conversationId: sessionId
|
|
11275
11497
|
});
|
|
11276
|
-
|
|
11498
|
+
logger25.info(
|
|
11277
11499
|
{
|
|
11278
11500
|
sessionId,
|
|
11279
11501
|
conversationFound: !!conversation,
|
|
@@ -11284,7 +11506,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
11284
11506
|
"Conversation lookup result"
|
|
11285
11507
|
);
|
|
11286
11508
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
11287
|
-
|
|
11509
|
+
logger25.info(
|
|
11288
11510
|
{ sessionId, conversationId: conversation?.id },
|
|
11289
11511
|
"MCP session not found or invalid"
|
|
11290
11512
|
);
|
|
@@ -11333,7 +11555,7 @@ var processUserMessage = async (tenantId, projectId, conversationId, query) => {
|
|
|
11333
11555
|
messageType: "chat"
|
|
11334
11556
|
});
|
|
11335
11557
|
};
|
|
11336
|
-
var executeAgentQuery = async (executionContext, conversationId, query,
|
|
11558
|
+
var executeAgentQuery = async (executionContext, conversationId, query, defaultSubAgentId) => {
|
|
11337
11559
|
const requestId2 = `mcp-${Date.now()}`;
|
|
11338
11560
|
const mcpStreamHelper = createMCPStreamHelper();
|
|
11339
11561
|
const executionHandler = new ExecutionHandler();
|
|
@@ -11341,11 +11563,11 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
11341
11563
|
executionContext,
|
|
11342
11564
|
conversationId,
|
|
11343
11565
|
userMessage: query,
|
|
11344
|
-
initialAgentId:
|
|
11566
|
+
initialAgentId: defaultSubAgentId,
|
|
11345
11567
|
requestId: requestId2,
|
|
11346
11568
|
sseHelper: mcpStreamHelper
|
|
11347
11569
|
});
|
|
11348
|
-
|
|
11570
|
+
logger25.info(
|
|
11349
11571
|
{ result },
|
|
11350
11572
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
11351
11573
|
);
|
|
@@ -11372,7 +11594,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
11372
11594
|
var getServer = async (headers, executionContext, conversationId, credentialStores) => {
|
|
11373
11595
|
const { tenantId, projectId, graphId } = executionContext;
|
|
11374
11596
|
setupTracing(conversationId, tenantId, graphId);
|
|
11375
|
-
const agentGraph = await agentsCore.
|
|
11597
|
+
const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
11376
11598
|
scopes: { tenantId, projectId, graphId }
|
|
11377
11599
|
});
|
|
11378
11600
|
if (!agentGraph) {
|
|
@@ -11393,7 +11615,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11393
11615
|
},
|
|
11394
11616
|
async ({ query }) => {
|
|
11395
11617
|
try {
|
|
11396
|
-
if (!agentGraph.
|
|
11618
|
+
if (!agentGraph.defaultSubAgentId) {
|
|
11397
11619
|
return {
|
|
11398
11620
|
content: [
|
|
11399
11621
|
{
|
|
@@ -11404,10 +11626,10 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11404
11626
|
isError: true
|
|
11405
11627
|
};
|
|
11406
11628
|
}
|
|
11407
|
-
const
|
|
11408
|
-
const agentInfo = await agentsCore.
|
|
11629
|
+
const defaultSubAgentId = agentGraph.defaultSubAgentId;
|
|
11630
|
+
const agentInfo = await agentsCore.getSubAgentById(dbClient_default)({
|
|
11409
11631
|
scopes: { tenantId, projectId, graphId },
|
|
11410
|
-
|
|
11632
|
+
subAgentId: defaultSubAgentId
|
|
11411
11633
|
});
|
|
11412
11634
|
if (!agentInfo) {
|
|
11413
11635
|
return {
|
|
@@ -11429,7 +11651,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11429
11651
|
dbClient: dbClient_default,
|
|
11430
11652
|
credentialStores
|
|
11431
11653
|
});
|
|
11432
|
-
|
|
11654
|
+
logger25.info(
|
|
11433
11655
|
{
|
|
11434
11656
|
tenantId,
|
|
11435
11657
|
projectId,
|
|
@@ -11442,7 +11664,7 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
11442
11664
|
"parameters"
|
|
11443
11665
|
);
|
|
11444
11666
|
await processUserMessage(tenantId, projectId, conversationId, query);
|
|
11445
|
-
return executeAgentQuery(executionContext, conversationId, query,
|
|
11667
|
+
return executeAgentQuery(executionContext, conversationId, query, defaultSubAgentId);
|
|
11446
11668
|
} catch (error) {
|
|
11447
11669
|
return {
|
|
11448
11670
|
content: [
|
|
@@ -11491,9 +11713,9 @@ var validateRequestParameters = (c) => {
|
|
|
11491
11713
|
};
|
|
11492
11714
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
11493
11715
|
const { tenantId, projectId, graphId } = executionContext;
|
|
11494
|
-
|
|
11716
|
+
logger25.info({ body }, "Received initialization request");
|
|
11495
11717
|
const sessionId = agentsCore.getConversationId();
|
|
11496
|
-
const agentGraph = await agentsCore.
|
|
11718
|
+
const agentGraph = await agentsCore.getAgentGraphWithDefaultSubAgent(dbClient_default)({
|
|
11497
11719
|
scopes: { tenantId, projectId, graphId }
|
|
11498
11720
|
});
|
|
11499
11721
|
if (!agentGraph) {
|
|
@@ -11506,7 +11728,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11506
11728
|
{ status: 404 }
|
|
11507
11729
|
);
|
|
11508
11730
|
}
|
|
11509
|
-
if (!agentGraph.
|
|
11731
|
+
if (!agentGraph.defaultSubAgentId) {
|
|
11510
11732
|
return c.json(
|
|
11511
11733
|
{
|
|
11512
11734
|
jsonrpc: "2.0",
|
|
@@ -11520,7 +11742,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11520
11742
|
id: sessionId,
|
|
11521
11743
|
tenantId,
|
|
11522
11744
|
projectId,
|
|
11523
|
-
|
|
11745
|
+
activeSubAgentId: agentGraph.defaultSubAgentId,
|
|
11524
11746
|
metadata: {
|
|
11525
11747
|
sessionData: {
|
|
11526
11748
|
graphId,
|
|
@@ -11531,7 +11753,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11531
11753
|
}
|
|
11532
11754
|
}
|
|
11533
11755
|
});
|
|
11534
|
-
|
|
11756
|
+
logger25.info(
|
|
11535
11757
|
{ sessionId, conversationId: conversation.id },
|
|
11536
11758
|
"Created MCP session as conversation"
|
|
11537
11759
|
);
|
|
@@ -11540,9 +11762,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11540
11762
|
});
|
|
11541
11763
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
11542
11764
|
await server.connect(transport);
|
|
11543
|
-
|
|
11765
|
+
logger25.info({ sessionId }, "Server connected for initialization");
|
|
11544
11766
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
11545
|
-
|
|
11767
|
+
logger25.info(
|
|
11546
11768
|
{
|
|
11547
11769
|
sessionId,
|
|
11548
11770
|
bodyMethod: body?.method,
|
|
@@ -11551,7 +11773,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11551
11773
|
"About to handle initialization request"
|
|
11552
11774
|
);
|
|
11553
11775
|
await transport.handleRequest(req, res, body);
|
|
11554
|
-
|
|
11776
|
+
logger25.info({ sessionId }, "Successfully handled initialization request");
|
|
11555
11777
|
return fetchToNode.toFetchResponse(res);
|
|
11556
11778
|
};
|
|
11557
11779
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -11579,8 +11801,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11579
11801
|
sessionId,
|
|
11580
11802
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
11581
11803
|
);
|
|
11582
|
-
|
|
11583
|
-
|
|
11804
|
+
logger25.info({ sessionId }, "Server connected and transport initialized");
|
|
11805
|
+
logger25.info(
|
|
11584
11806
|
{
|
|
11585
11807
|
sessionId,
|
|
11586
11808
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -11594,9 +11816,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11594
11816
|
);
|
|
11595
11817
|
try {
|
|
11596
11818
|
await transport.handleRequest(req, res, body);
|
|
11597
|
-
|
|
11819
|
+
logger25.info({ sessionId }, "Successfully handled MCP request");
|
|
11598
11820
|
} catch (transportError) {
|
|
11599
|
-
|
|
11821
|
+
logger25.error(
|
|
11600
11822
|
{
|
|
11601
11823
|
sessionId,
|
|
11602
11824
|
error: transportError,
|
|
@@ -11647,13 +11869,13 @@ app4.openapi(
|
|
|
11647
11869
|
}
|
|
11648
11870
|
const { executionContext } = paramValidation;
|
|
11649
11871
|
const body = c.get("requestBody") || {};
|
|
11650
|
-
|
|
11872
|
+
logger25.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
11651
11873
|
const isInitRequest = body.method === "initialize";
|
|
11652
11874
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
11653
11875
|
const validatedContext = c.get("validatedContext") || {};
|
|
11654
11876
|
const credentialStores = c.get("credentialStores");
|
|
11655
|
-
|
|
11656
|
-
|
|
11877
|
+
logger25.info({ validatedContext }, "Validated context");
|
|
11878
|
+
logger25.info({ req }, "request");
|
|
11657
11879
|
if (isInitRequest) {
|
|
11658
11880
|
return await handleInitializationRequest(
|
|
11659
11881
|
body,
|
|
@@ -11675,7 +11897,7 @@ app4.openapi(
|
|
|
11675
11897
|
);
|
|
11676
11898
|
}
|
|
11677
11899
|
} catch (e) {
|
|
11678
|
-
|
|
11900
|
+
logger25.error(
|
|
11679
11901
|
{
|
|
11680
11902
|
error: e instanceof Error ? e.message : e,
|
|
11681
11903
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -11687,7 +11909,7 @@ app4.openapi(
|
|
|
11687
11909
|
}
|
|
11688
11910
|
);
|
|
11689
11911
|
app4.get("/", async (c) => {
|
|
11690
|
-
|
|
11912
|
+
logger25.info({}, "Received GET MCP request");
|
|
11691
11913
|
return c.json(
|
|
11692
11914
|
{
|
|
11693
11915
|
jsonrpc: "2.0",
|
|
@@ -11701,7 +11923,7 @@ app4.get("/", async (c) => {
|
|
|
11701
11923
|
);
|
|
11702
11924
|
});
|
|
11703
11925
|
app4.delete("/", async (c) => {
|
|
11704
|
-
|
|
11926
|
+
logger25.info({}, "Received DELETE MCP request");
|
|
11705
11927
|
return c.json(
|
|
11706
11928
|
{
|
|
11707
11929
|
jsonrpc: "2.0",
|
|
@@ -11714,7 +11936,7 @@ app4.delete("/", async (c) => {
|
|
|
11714
11936
|
var mcp_default = app4;
|
|
11715
11937
|
|
|
11716
11938
|
// src/app.ts
|
|
11717
|
-
var
|
|
11939
|
+
var logger26 = agentsCore.getLogger("agents-run-api");
|
|
11718
11940
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
11719
11941
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
11720
11942
|
app6.use("*", otel.otel());
|
|
@@ -11730,7 +11952,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11730
11952
|
const body = await c.req.json();
|
|
11731
11953
|
c.set("requestBody", body);
|
|
11732
11954
|
} catch (error) {
|
|
11733
|
-
|
|
11955
|
+
logger26.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
11734
11956
|
}
|
|
11735
11957
|
}
|
|
11736
11958
|
return next();
|
|
@@ -11781,8 +12003,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11781
12003
|
if (!isExpectedError) {
|
|
11782
12004
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
11783
12005
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
11784
|
-
if (
|
|
11785
|
-
|
|
12006
|
+
if (logger26) {
|
|
12007
|
+
logger26.error(
|
|
11786
12008
|
{
|
|
11787
12009
|
error: err,
|
|
11788
12010
|
message: errorMessage,
|
|
@@ -11794,8 +12016,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11794
12016
|
);
|
|
11795
12017
|
}
|
|
11796
12018
|
} else {
|
|
11797
|
-
if (
|
|
11798
|
-
|
|
12019
|
+
if (logger26) {
|
|
12020
|
+
logger26.error(
|
|
11799
12021
|
{
|
|
11800
12022
|
error: err,
|
|
11801
12023
|
path: c.req.path,
|
|
@@ -11812,8 +12034,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11812
12034
|
const response = err.getResponse();
|
|
11813
12035
|
return response;
|
|
11814
12036
|
} catch (responseError) {
|
|
11815
|
-
if (
|
|
11816
|
-
|
|
12037
|
+
if (logger26) {
|
|
12038
|
+
logger26.error({ error: responseError }, "Error while handling HTTPException response");
|
|
11817
12039
|
}
|
|
11818
12040
|
}
|
|
11819
12041
|
}
|
|
@@ -11847,7 +12069,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11847
12069
|
app6.use("*", async (c, next) => {
|
|
11848
12070
|
const executionContext = c.get("executionContext");
|
|
11849
12071
|
if (!executionContext) {
|
|
11850
|
-
|
|
12072
|
+
logger26.debug({}, "Empty execution context");
|
|
11851
12073
|
return next();
|
|
11852
12074
|
}
|
|
11853
12075
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -11856,7 +12078,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11856
12078
|
if (requestBody) {
|
|
11857
12079
|
conversationId = requestBody.conversationId;
|
|
11858
12080
|
if (!conversationId) {
|
|
11859
|
-
|
|
12081
|
+
logger26.debug({ requestBody }, "No conversation ID found in request body");
|
|
11860
12082
|
}
|
|
11861
12083
|
}
|
|
11862
12084
|
const entries = Object.fromEntries(
|
|
@@ -11871,7 +12093,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11871
12093
|
})
|
|
11872
12094
|
);
|
|
11873
12095
|
if (!Object.keys(entries).length) {
|
|
11874
|
-
|
|
12096
|
+
logger26.debug({}, "Empty entries for baggage");
|
|
11875
12097
|
return next();
|
|
11876
12098
|
}
|
|
11877
12099
|
const bag = Object.entries(entries).reduce(
|