@inkeep/agents-run-api 0.14.2 → 0.14.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-F46V23RK.js → chunk-5GUNCN5X.js} +2 -2
- package/dist/chunk-7IMXW4RD.js +26 -0
- package/dist/{chunk-TWVQBIUL.js → chunk-NZHNG4A3.js} +6 -27
- package/dist/{chunk-Z76LOSTO.js → chunk-XO4RG36I.js} +24 -6
- package/dist/{conversations-AP5WZGWA.js → conversations-6HJ4FX5F.js} +1 -1
- package/dist/dbClient-UQHVUUUY.js +1 -0
- package/dist/index.cjs +300 -239
- package/dist/index.js +58 -19
- package/dist/instrumentation.cjs +57 -3
- package/dist/instrumentation.d.cts +4 -3
- package/dist/instrumentation.d.ts +4 -3
- package/dist/instrumentation.js +1 -1
- package/package.json +2 -2
- package/dist/dbClient-GGR4KMBD.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -71,7 +71,9 @@ var init_env = __esm({
|
|
|
71
71
|
NANGO_SECRET_KEY: z5.z.string().optional(),
|
|
72
72
|
OPENAI_API_KEY: z5.z.string().optional(),
|
|
73
73
|
ANTHROPIC_API_KEY: z5.z.string(),
|
|
74
|
-
INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z5.z.string().optional()
|
|
74
|
+
INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z5.z.string().optional(),
|
|
75
|
+
OTEL_BSP_SCHEDULE_DELAY: z5.z.coerce.number().optional().default(500),
|
|
76
|
+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: z5.z.coerce.number().optional().default(64)
|
|
75
77
|
});
|
|
76
78
|
parseEnv = () => {
|
|
77
79
|
try {
|
|
@@ -343,8 +345,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
343
345
|
});
|
|
344
346
|
referenceArtifacts.push(...artifacts);
|
|
345
347
|
}
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
+
const logger26 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
349
|
+
logger26.debug(
|
|
348
350
|
{
|
|
349
351
|
conversationId,
|
|
350
352
|
visibleMessages: visibleMessages.length,
|
|
@@ -356,8 +358,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
356
358
|
);
|
|
357
359
|
return referenceArtifacts;
|
|
358
360
|
} catch (error) {
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
+
const logger26 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
362
|
+
logger26.error(
|
|
361
363
|
{
|
|
362
364
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
363
365
|
conversationId
|
|
@@ -395,10 +397,24 @@ var init_json_postprocessor = __esm({
|
|
|
395
397
|
|
|
396
398
|
// src/index.ts
|
|
397
399
|
init_env();
|
|
400
|
+
|
|
401
|
+
// src/instrumentation.ts
|
|
402
|
+
init_env();
|
|
403
|
+
init_logger();
|
|
398
404
|
var otlpExporter = new exporterTraceOtlpHttp.OTLPTraceExporter();
|
|
399
|
-
var
|
|
400
|
-
|
|
401
|
-
|
|
405
|
+
var logger = agentsCore.getLogger("instrumentation");
|
|
406
|
+
function createSafeBatchProcessor() {
|
|
407
|
+
try {
|
|
408
|
+
return new sdkTraceBase.BatchSpanProcessor(otlpExporter, {
|
|
409
|
+
scheduledDelayMillis: env.OTEL_BSP_SCHEDULE_DELAY,
|
|
410
|
+
maxExportBatchSize: env.OTEL_BSP_MAX_EXPORT_BATCH_SIZE
|
|
411
|
+
});
|
|
412
|
+
} catch (error) {
|
|
413
|
+
logger.warn({ error }, "Failed to create batch processor");
|
|
414
|
+
return new sdkTraceBase.NoopSpanProcessor();
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
var defaultBatchProcessor = createSafeBatchProcessor();
|
|
402
418
|
var defaultResource = resources.resourceFromAttributes({
|
|
403
419
|
[semanticConventions.ATTR_SERVICE_NAME]: "inkeep-agents-run-api"
|
|
404
420
|
});
|
|
@@ -439,6 +455,13 @@ new sdkNode.NodeSDK({
|
|
|
439
455
|
spanProcessors: defaultSpanProcessors,
|
|
440
456
|
instrumentations: defaultInstrumentations
|
|
441
457
|
});
|
|
458
|
+
async function flushBatchProcessor() {
|
|
459
|
+
try {
|
|
460
|
+
await defaultBatchProcessor.forceFlush();
|
|
461
|
+
} catch (error) {
|
|
462
|
+
logger.warn({ error }, "Failed to flush batch processor");
|
|
463
|
+
}
|
|
464
|
+
}
|
|
442
465
|
|
|
443
466
|
// src/app.ts
|
|
444
467
|
init_logger();
|
|
@@ -462,7 +485,7 @@ function createExecutionContext(params) {
|
|
|
462
485
|
}
|
|
463
486
|
|
|
464
487
|
// src/middleware/api-key-auth.ts
|
|
465
|
-
var
|
|
488
|
+
var logger2 = agentsCore.getLogger("env-key-auth");
|
|
466
489
|
var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
467
490
|
if (c.req.method === "OPTIONS") {
|
|
468
491
|
await next();
|
|
@@ -480,7 +503,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
480
503
|
try {
|
|
481
504
|
executionContext = await extractContextFromApiKey(authHeader.substring(7), baseUrl);
|
|
482
505
|
executionContext.agentId = agentId;
|
|
483
|
-
|
|
506
|
+
logger2.info({}, "Development/test environment - API key authenticated successfully");
|
|
484
507
|
} catch {
|
|
485
508
|
executionContext = createExecutionContext({
|
|
486
509
|
apiKey: "development",
|
|
@@ -491,7 +514,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
491
514
|
baseUrl,
|
|
492
515
|
agentId
|
|
493
516
|
});
|
|
494
|
-
|
|
517
|
+
logger2.info(
|
|
495
518
|
{},
|
|
496
519
|
"Development/test environment - fallback to default context due to invalid API key"
|
|
497
520
|
);
|
|
@@ -506,7 +529,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
506
529
|
baseUrl,
|
|
507
530
|
agentId
|
|
508
531
|
});
|
|
509
|
-
|
|
532
|
+
logger2.info(
|
|
510
533
|
{},
|
|
511
534
|
"Development/test environment - no API key provided, using default context"
|
|
512
535
|
);
|
|
@@ -538,14 +561,14 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
538
561
|
agentId
|
|
539
562
|
});
|
|
540
563
|
c.set("executionContext", executionContext);
|
|
541
|
-
|
|
564
|
+
logger2.info({}, "Bypass secret authenticated successfully");
|
|
542
565
|
await next();
|
|
543
566
|
return;
|
|
544
567
|
} else if (apiKey) {
|
|
545
568
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
546
569
|
executionContext.agentId = agentId;
|
|
547
570
|
c.set("executionContext", executionContext);
|
|
548
|
-
|
|
571
|
+
logger2.info({}, "API key authenticated successfully");
|
|
549
572
|
await next();
|
|
550
573
|
return;
|
|
551
574
|
} else {
|
|
@@ -563,7 +586,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
563
586
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
564
587
|
executionContext.agentId = agentId;
|
|
565
588
|
c.set("executionContext", executionContext);
|
|
566
|
-
|
|
589
|
+
logger2.debug(
|
|
567
590
|
{
|
|
568
591
|
tenantId: executionContext.tenantId,
|
|
569
592
|
projectId: executionContext.projectId,
|
|
@@ -577,7 +600,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
577
600
|
if (error instanceof httpException.HTTPException) {
|
|
578
601
|
throw error;
|
|
579
602
|
}
|
|
580
|
-
|
|
603
|
+
logger2.error({ error }, "API key authentication error");
|
|
581
604
|
throw new httpException.HTTPException(500, {
|
|
582
605
|
message: "Authentication failed"
|
|
583
606
|
});
|
|
@@ -638,7 +661,7 @@ function setupOpenAPIRoutes(app6) {
|
|
|
638
661
|
// src/a2a/handlers.ts
|
|
639
662
|
init_dbClient();
|
|
640
663
|
init_logger();
|
|
641
|
-
var
|
|
664
|
+
var logger3 = agentsCore.getLogger("a2aHandler");
|
|
642
665
|
async function a2aHandler(c, agent) {
|
|
643
666
|
try {
|
|
644
667
|
const rpcRequest = c.get("requestBody");
|
|
@@ -740,7 +763,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
740
763
|
messageId: task.id,
|
|
741
764
|
kind: "message"
|
|
742
765
|
});
|
|
743
|
-
|
|
766
|
+
logger3.warn(
|
|
744
767
|
{
|
|
745
768
|
taskId: task.id,
|
|
746
769
|
agentId: agent.agentId,
|
|
@@ -750,7 +773,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
750
773
|
);
|
|
751
774
|
}
|
|
752
775
|
} catch (error) {
|
|
753
|
-
|
|
776
|
+
logger3.error({ error, taskId: task.id }, "Failed to serialize message");
|
|
754
777
|
JSON.stringify({
|
|
755
778
|
error: "Failed to serialize message",
|
|
756
779
|
taskId: task.id,
|
|
@@ -758,7 +781,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
758
781
|
parts: [{ text: "Error in delegation", kind: "text" }]
|
|
759
782
|
});
|
|
760
783
|
}
|
|
761
|
-
|
|
784
|
+
logger3.info(
|
|
762
785
|
{
|
|
763
786
|
originalContextId: params.message.contextId,
|
|
764
787
|
taskContextId: task.context?.conversationId,
|
|
@@ -788,7 +811,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
788
811
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
789
812
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
790
813
|
});
|
|
791
|
-
|
|
814
|
+
logger3.info({ metadata: params.message.metadata }, "message metadata");
|
|
792
815
|
if (params.message.metadata?.fromAgentId || params.message.metadata?.fromExternalAgentId) {
|
|
793
816
|
const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
|
|
794
817
|
try {
|
|
@@ -813,7 +836,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
813
836
|
messageData.toAgentId = agent.agentId;
|
|
814
837
|
}
|
|
815
838
|
await agentsCore.createMessage(dbClient_default)(messageData);
|
|
816
|
-
|
|
839
|
+
logger3.info(
|
|
817
840
|
{
|
|
818
841
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
819
842
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
@@ -825,7 +848,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
825
848
|
"A2A message stored in database"
|
|
826
849
|
);
|
|
827
850
|
} catch (error) {
|
|
828
|
-
|
|
851
|
+
logger3.error(
|
|
829
852
|
{
|
|
830
853
|
error,
|
|
831
854
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
@@ -862,7 +885,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
862
885
|
(part) => part.kind === "data" && part.data && typeof part.data === "object" && part.data.type === "transfer"
|
|
863
886
|
);
|
|
864
887
|
if (transferPart && transferPart.kind === "data" && transferPart.data) {
|
|
865
|
-
|
|
888
|
+
logger3.info({ transferPart }, "transferPart");
|
|
866
889
|
return c.json({
|
|
867
890
|
jsonrpc: "2.0",
|
|
868
891
|
result: {
|
|
@@ -1413,7 +1436,7 @@ init_logger();
|
|
|
1413
1436
|
|
|
1414
1437
|
// src/agents/ModelFactory.ts
|
|
1415
1438
|
init_logger();
|
|
1416
|
-
var
|
|
1439
|
+
var logger5 = agentsCore.getLogger("ModelFactory");
|
|
1417
1440
|
var _ModelFactory = class _ModelFactory {
|
|
1418
1441
|
/**
|
|
1419
1442
|
* Create a provider instance with custom configuration
|
|
@@ -1475,7 +1498,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1475
1498
|
}
|
|
1476
1499
|
const modelString = modelSettings.model.trim();
|
|
1477
1500
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1478
|
-
|
|
1501
|
+
logger5.debug(
|
|
1479
1502
|
{
|
|
1480
1503
|
provider,
|
|
1481
1504
|
model: modelName,
|
|
@@ -1486,7 +1509,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1486
1509
|
);
|
|
1487
1510
|
const providerConfig = _ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
1488
1511
|
if (Object.keys(providerConfig).length > 0) {
|
|
1489
|
-
|
|
1512
|
+
logger5.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
1490
1513
|
const customProvider = _ModelFactory.createProvider(provider, providerConfig);
|
|
1491
1514
|
return customProvider.languageModel(modelName);
|
|
1492
1515
|
}
|
|
@@ -1605,7 +1628,7 @@ var ModelFactory = _ModelFactory;
|
|
|
1605
1628
|
|
|
1606
1629
|
// src/agents/ToolSessionManager.ts
|
|
1607
1630
|
init_logger();
|
|
1608
|
-
var
|
|
1631
|
+
var logger6 = agentsCore.getLogger("ToolSessionManager");
|
|
1609
1632
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
1610
1633
|
// 5 minutes
|
|
1611
1634
|
constructor() {
|
|
@@ -1640,7 +1663,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1640
1663
|
createdAt: Date.now()
|
|
1641
1664
|
};
|
|
1642
1665
|
this.sessions.set(sessionId, session);
|
|
1643
|
-
|
|
1666
|
+
logger6.debug(
|
|
1644
1667
|
{
|
|
1645
1668
|
sessionId,
|
|
1646
1669
|
tenantId,
|
|
@@ -1658,10 +1681,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1658
1681
|
*/
|
|
1659
1682
|
ensureGraphSession(sessionId, tenantId, projectId, contextId, taskId) {
|
|
1660
1683
|
if (this.sessions.has(sessionId)) {
|
|
1661
|
-
|
|
1684
|
+
logger6.debug({ sessionId }, "Graph session already exists, reusing");
|
|
1662
1685
|
return sessionId;
|
|
1663
1686
|
}
|
|
1664
|
-
|
|
1687
|
+
logger6.debug(
|
|
1665
1688
|
{ sessionId, tenantId, contextId, taskId },
|
|
1666
1689
|
"Creating new graph-scoped tool session"
|
|
1667
1690
|
);
|
|
@@ -1673,7 +1696,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1673
1696
|
recordToolResult(sessionId, toolResult) {
|
|
1674
1697
|
const session = this.sessions.get(sessionId);
|
|
1675
1698
|
if (!session) {
|
|
1676
|
-
|
|
1699
|
+
logger6.warn(
|
|
1677
1700
|
{
|
|
1678
1701
|
sessionId,
|
|
1679
1702
|
toolCallId: toolResult.toolCallId,
|
|
@@ -1685,7 +1708,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1685
1708
|
return;
|
|
1686
1709
|
}
|
|
1687
1710
|
session.toolResults.set(toolResult.toolCallId, toolResult);
|
|
1688
|
-
|
|
1711
|
+
logger6.debug(
|
|
1689
1712
|
{
|
|
1690
1713
|
sessionId,
|
|
1691
1714
|
toolCallId: toolResult.toolCallId,
|
|
@@ -1700,7 +1723,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1700
1723
|
getToolResult(sessionId, toolCallId) {
|
|
1701
1724
|
const session = this.sessions.get(sessionId);
|
|
1702
1725
|
if (!session) {
|
|
1703
|
-
|
|
1726
|
+
logger6.warn(
|
|
1704
1727
|
{
|
|
1705
1728
|
sessionId,
|
|
1706
1729
|
toolCallId,
|
|
@@ -1713,7 +1736,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1713
1736
|
}
|
|
1714
1737
|
const result = session.toolResults.get(toolCallId);
|
|
1715
1738
|
if (!result) {
|
|
1716
|
-
|
|
1739
|
+
logger6.warn(
|
|
1717
1740
|
{
|
|
1718
1741
|
sessionId,
|
|
1719
1742
|
toolCallId,
|
|
@@ -1723,7 +1746,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1723
1746
|
"Tool result not found"
|
|
1724
1747
|
);
|
|
1725
1748
|
} else {
|
|
1726
|
-
|
|
1749
|
+
logger6.debug(
|
|
1727
1750
|
{
|
|
1728
1751
|
sessionId,
|
|
1729
1752
|
toolCallId,
|
|
@@ -1762,10 +1785,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1762
1785
|
}
|
|
1763
1786
|
for (const sessionId of expiredSessions) {
|
|
1764
1787
|
this.sessions.delete(sessionId);
|
|
1765
|
-
|
|
1788
|
+
logger6.debug({ sessionId }, "Cleaned up expired tool session");
|
|
1766
1789
|
}
|
|
1767
1790
|
if (expiredSessions.length > 0) {
|
|
1768
|
-
|
|
1791
|
+
logger6.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
1769
1792
|
}
|
|
1770
1793
|
}
|
|
1771
1794
|
};
|
|
@@ -1809,7 +1832,7 @@ var tracer = agentsCore.getTracer("agents-run-api");
|
|
|
1809
1832
|
init_logger();
|
|
1810
1833
|
init_dbClient();
|
|
1811
1834
|
init_logger();
|
|
1812
|
-
var
|
|
1835
|
+
var logger7 = agentsCore.getLogger("ArtifactService");
|
|
1813
1836
|
var _ArtifactService = class _ArtifactService {
|
|
1814
1837
|
constructor(context) {
|
|
1815
1838
|
this.context = context;
|
|
@@ -1835,7 +1858,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1835
1858
|
id: taskId
|
|
1836
1859
|
});
|
|
1837
1860
|
if (!task) {
|
|
1838
|
-
|
|
1861
|
+
logger7.warn({ taskId }, "Task not found when fetching artifacts");
|
|
1839
1862
|
continue;
|
|
1840
1863
|
}
|
|
1841
1864
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -1853,7 +1876,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1853
1876
|
}
|
|
1854
1877
|
}
|
|
1855
1878
|
} catch (error) {
|
|
1856
|
-
|
|
1879
|
+
logger7.error({ error, contextId }, "Error loading context artifacts");
|
|
1857
1880
|
}
|
|
1858
1881
|
return artifacts;
|
|
1859
1882
|
}
|
|
@@ -1862,12 +1885,12 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1862
1885
|
*/
|
|
1863
1886
|
async createArtifact(request, agentId) {
|
|
1864
1887
|
if (!this.context.sessionId) {
|
|
1865
|
-
|
|
1888
|
+
logger7.warn({ request }, "No session ID available for artifact creation");
|
|
1866
1889
|
return null;
|
|
1867
1890
|
}
|
|
1868
1891
|
const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
|
|
1869
1892
|
if (!toolResult) {
|
|
1870
|
-
|
|
1893
|
+
logger7.warn(
|
|
1871
1894
|
{ request, sessionId: this.context.sessionId },
|
|
1872
1895
|
"Tool result not found for artifact"
|
|
1873
1896
|
);
|
|
@@ -1883,7 +1906,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1883
1906
|
selectedData = selectedData.length > 0 ? selectedData[0] : {};
|
|
1884
1907
|
}
|
|
1885
1908
|
if (!selectedData) {
|
|
1886
|
-
|
|
1909
|
+
logger7.warn(
|
|
1887
1910
|
{
|
|
1888
1911
|
request,
|
|
1889
1912
|
baseSelector: request.baseSelector
|
|
@@ -1920,7 +1943,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1920
1943
|
);
|
|
1921
1944
|
return artifactData;
|
|
1922
1945
|
} catch (error) {
|
|
1923
|
-
|
|
1946
|
+
logger7.error({ error, request }, "Failed to create artifact");
|
|
1924
1947
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1925
1948
|
throw new Error(`Artifact creation failed for ${request.artifactId}: ${errorMessage}`);
|
|
1926
1949
|
}
|
|
@@ -1949,7 +1972,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1949
1972
|
}
|
|
1950
1973
|
try {
|
|
1951
1974
|
if (!this.context.projectId || !this.context.taskId) {
|
|
1952
|
-
|
|
1975
|
+
logger7.warn(
|
|
1953
1976
|
{ artifactId, toolCallId },
|
|
1954
1977
|
"No projectId or taskId available for artifact lookup"
|
|
1955
1978
|
);
|
|
@@ -1964,7 +1987,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1964
1987
|
return this.formatArtifactData(artifacts[0], artifactId, toolCallId);
|
|
1965
1988
|
}
|
|
1966
1989
|
} catch (error) {
|
|
1967
|
-
|
|
1990
|
+
logger7.warn(
|
|
1968
1991
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
1969
1992
|
"Failed to fetch artifact"
|
|
1970
1993
|
);
|
|
@@ -2017,7 +2040,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2017
2040
|
}
|
|
2018
2041
|
);
|
|
2019
2042
|
} else {
|
|
2020
|
-
|
|
2043
|
+
logger7.warn({
|
|
2021
2044
|
artifactId: request.artifactId,
|
|
2022
2045
|
hasStreamRequestId: !!this.context.streamRequestId,
|
|
2023
2046
|
hasAgentId: !!effectiveAgentId,
|
|
@@ -2102,7 +2125,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2102
2125
|
artifact: artifactToSave
|
|
2103
2126
|
});
|
|
2104
2127
|
if (!result.created && result.existing) {
|
|
2105
|
-
|
|
2128
|
+
logger7.debug(
|
|
2106
2129
|
{
|
|
2107
2130
|
artifactId: artifact.artifactId,
|
|
2108
2131
|
taskId: this.context.taskId
|
|
@@ -2155,7 +2178,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2155
2178
|
extracted[propName] = this.cleanEscapedContent(rawValue);
|
|
2156
2179
|
}
|
|
2157
2180
|
} catch (error) {
|
|
2158
|
-
|
|
2181
|
+
logger7.warn(
|
|
2159
2182
|
{ propName, selector, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2160
2183
|
"Failed to extract property"
|
|
2161
2184
|
);
|
|
@@ -2185,7 +2208,7 @@ __publicField(_ArtifactService, "selectorCache", /* @__PURE__ */ new Map());
|
|
|
2185
2208
|
var ArtifactService = _ArtifactService;
|
|
2186
2209
|
|
|
2187
2210
|
// src/services/ArtifactParser.ts
|
|
2188
|
-
var
|
|
2211
|
+
var logger8 = agentsCore.getLogger("ArtifactParser");
|
|
2189
2212
|
var _ArtifactParser = class _ArtifactParser {
|
|
2190
2213
|
constructor(tenantId, options) {
|
|
2191
2214
|
__publicField(this, "artifactService");
|
|
@@ -2269,7 +2292,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2269
2292
|
attrs[key] = value;
|
|
2270
2293
|
}
|
|
2271
2294
|
if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
|
|
2272
|
-
|
|
2295
|
+
logger8.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
|
|
2273
2296
|
return null;
|
|
2274
2297
|
}
|
|
2275
2298
|
return {
|
|
@@ -2330,7 +2353,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2330
2353
|
} else if (annotation.raw) {
|
|
2331
2354
|
failedAnnotations.push(`Failed to create artifact "${annotation.artifactId}": Missing or invalid data`);
|
|
2332
2355
|
processedText = processedText.replace(annotation.raw, "");
|
|
2333
|
-
|
|
2356
|
+
logger8.warn({ annotation, artifactData }, "Removed failed artifact:create annotation from output");
|
|
2334
2357
|
}
|
|
2335
2358
|
} catch (error) {
|
|
2336
2359
|
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
@@ -2338,11 +2361,11 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2338
2361
|
if (annotation.raw) {
|
|
2339
2362
|
processedText = processedText.replace(annotation.raw, "");
|
|
2340
2363
|
}
|
|
2341
|
-
|
|
2364
|
+
logger8.error({ annotation, error }, "Failed to extract artifact from create annotation");
|
|
2342
2365
|
}
|
|
2343
2366
|
}
|
|
2344
2367
|
if (failedAnnotations.length > 0) {
|
|
2345
|
-
|
|
2368
|
+
logger8.warn({
|
|
2346
2369
|
failedCount: failedAnnotations.length,
|
|
2347
2370
|
failures: failedAnnotations
|
|
2348
2371
|
}, "Some artifact creation attempts failed");
|
|
@@ -2499,7 +2522,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^
|
|
|
2499
2522
|
var ArtifactParser = _ArtifactParser;
|
|
2500
2523
|
|
|
2501
2524
|
// src/services/GraphSession.ts
|
|
2502
|
-
var
|
|
2525
|
+
var logger9 = agentsCore.getLogger("GraphSession");
|
|
2503
2526
|
var GraphSession = class {
|
|
2504
2527
|
// Session-scoped ArtifactParser instance
|
|
2505
2528
|
constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
|
|
@@ -2530,7 +2553,7 @@ var GraphSession = class {
|
|
|
2530
2553
|
__publicField(this, "artifactService");
|
|
2531
2554
|
// Session-scoped ArtifactService instance
|
|
2532
2555
|
__publicField(this, "artifactParser");
|
|
2533
|
-
|
|
2556
|
+
logger9.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
2534
2557
|
if (tenantId && projectId) {
|
|
2535
2558
|
toolSessionManager.createSessionWithId(
|
|
2536
2559
|
sessionId,
|
|
@@ -2578,7 +2601,7 @@ var GraphSession = class {
|
|
|
2578
2601
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
2579
2602
|
this.statusUpdateTimer = setInterval(async () => {
|
|
2580
2603
|
if (!this.statusUpdateState || this.isEnded) {
|
|
2581
|
-
|
|
2604
|
+
logger9.debug(
|
|
2582
2605
|
{ sessionId: this.sessionId },
|
|
2583
2606
|
"Timer triggered but session already cleaned up or ended"
|
|
2584
2607
|
);
|
|
@@ -2590,7 +2613,7 @@ var GraphSession = class {
|
|
|
2590
2613
|
}
|
|
2591
2614
|
await this.checkAndSendTimeBasedUpdate();
|
|
2592
2615
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
2593
|
-
|
|
2616
|
+
logger9.info(
|
|
2594
2617
|
{
|
|
2595
2618
|
sessionId: this.sessionId,
|
|
2596
2619
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -2604,7 +2627,7 @@ var GraphSession = class {
|
|
|
2604
2627
|
*/
|
|
2605
2628
|
recordEvent(eventType, agentId, data) {
|
|
2606
2629
|
if (this.isEnded) {
|
|
2607
|
-
|
|
2630
|
+
logger9.debug(
|
|
2608
2631
|
{
|
|
2609
2632
|
sessionId: this.sessionId,
|
|
2610
2633
|
eventType,
|
|
@@ -2624,7 +2647,7 @@ var GraphSession = class {
|
|
|
2624
2647
|
if (eventType === "artifact_saved" && data.pendingGeneration) {
|
|
2625
2648
|
const artifactId = data.artifactId;
|
|
2626
2649
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
2627
|
-
|
|
2650
|
+
logger9.warn(
|
|
2628
2651
|
{
|
|
2629
2652
|
sessionId: this.sessionId,
|
|
2630
2653
|
artifactId,
|
|
@@ -2646,7 +2669,7 @@ var GraphSession = class {
|
|
|
2646
2669
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
2647
2670
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
2648
2671
|
this.pendingArtifacts.delete(artifactId);
|
|
2649
|
-
|
|
2672
|
+
logger9.error(
|
|
2650
2673
|
{
|
|
2651
2674
|
sessionId: this.sessionId,
|
|
2652
2675
|
artifactId,
|
|
@@ -2658,7 +2681,7 @@ var GraphSession = class {
|
|
|
2658
2681
|
"Artifact processing failed after max retries, giving up"
|
|
2659
2682
|
);
|
|
2660
2683
|
} else {
|
|
2661
|
-
|
|
2684
|
+
logger9.warn(
|
|
2662
2685
|
{
|
|
2663
2686
|
sessionId: this.sessionId,
|
|
2664
2687
|
artifactId,
|
|
@@ -2680,14 +2703,14 @@ var GraphSession = class {
|
|
|
2680
2703
|
*/
|
|
2681
2704
|
checkStatusUpdates() {
|
|
2682
2705
|
if (this.isEnded) {
|
|
2683
|
-
|
|
2706
|
+
logger9.debug(
|
|
2684
2707
|
{ sessionId: this.sessionId },
|
|
2685
2708
|
"Session has ended - skipping status update check"
|
|
2686
2709
|
);
|
|
2687
2710
|
return;
|
|
2688
2711
|
}
|
|
2689
2712
|
if (!this.statusUpdateState) {
|
|
2690
|
-
|
|
2713
|
+
logger9.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
2691
2714
|
return;
|
|
2692
2715
|
}
|
|
2693
2716
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -2698,11 +2721,11 @@ var GraphSession = class {
|
|
|
2698
2721
|
*/
|
|
2699
2722
|
async checkAndSendTimeBasedUpdate() {
|
|
2700
2723
|
if (this.isEnded) {
|
|
2701
|
-
|
|
2724
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
2702
2725
|
return;
|
|
2703
2726
|
}
|
|
2704
2727
|
if (!this.statusUpdateState) {
|
|
2705
|
-
|
|
2728
|
+
logger9.debug(
|
|
2706
2729
|
{ sessionId: this.sessionId },
|
|
2707
2730
|
"No status updates configured for time-based check"
|
|
2708
2731
|
);
|
|
@@ -2715,7 +2738,7 @@ var GraphSession = class {
|
|
|
2715
2738
|
try {
|
|
2716
2739
|
await this.generateAndSendUpdate();
|
|
2717
2740
|
} catch (error) {
|
|
2718
|
-
|
|
2741
|
+
logger9.error(
|
|
2719
2742
|
{
|
|
2720
2743
|
sessionId: this.sessionId,
|
|
2721
2744
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2818,29 +2841,29 @@ var GraphSession = class {
|
|
|
2818
2841
|
*/
|
|
2819
2842
|
async generateAndSendUpdate() {
|
|
2820
2843
|
if (this.isEnded) {
|
|
2821
|
-
|
|
2844
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
2822
2845
|
return;
|
|
2823
2846
|
}
|
|
2824
2847
|
if (this.isTextStreaming) {
|
|
2825
|
-
|
|
2848
|
+
logger9.debug(
|
|
2826
2849
|
{ sessionId: this.sessionId },
|
|
2827
2850
|
"Text is currently streaming - skipping status update"
|
|
2828
2851
|
);
|
|
2829
2852
|
return;
|
|
2830
2853
|
}
|
|
2831
2854
|
if (this.isGeneratingUpdate) {
|
|
2832
|
-
|
|
2855
|
+
logger9.debug(
|
|
2833
2856
|
{ sessionId: this.sessionId },
|
|
2834
2857
|
"Update already in progress - skipping duplicate generation"
|
|
2835
2858
|
);
|
|
2836
2859
|
return;
|
|
2837
2860
|
}
|
|
2838
2861
|
if (!this.statusUpdateState) {
|
|
2839
|
-
|
|
2862
|
+
logger9.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
2840
2863
|
return;
|
|
2841
2864
|
}
|
|
2842
2865
|
if (!this.graphId) {
|
|
2843
|
-
|
|
2866
|
+
logger9.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
2844
2867
|
return;
|
|
2845
2868
|
}
|
|
2846
2869
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -2852,7 +2875,7 @@ var GraphSession = class {
|
|
|
2852
2875
|
try {
|
|
2853
2876
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
2854
2877
|
if (!streamHelper) {
|
|
2855
|
-
|
|
2878
|
+
logger9.warn(
|
|
2856
2879
|
{ sessionId: this.sessionId },
|
|
2857
2880
|
"No stream helper found - cannot send status update"
|
|
2858
2881
|
);
|
|
@@ -2872,7 +2895,7 @@ var GraphSession = class {
|
|
|
2872
2895
|
if (result.summaries && result.summaries.length > 0) {
|
|
2873
2896
|
for (const summary of result.summaries) {
|
|
2874
2897
|
if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
|
|
2875
|
-
|
|
2898
|
+
logger9.warn(
|
|
2876
2899
|
{
|
|
2877
2900
|
sessionId: this.sessionId,
|
|
2878
2901
|
summary
|
|
@@ -2909,7 +2932,7 @@ var GraphSession = class {
|
|
|
2909
2932
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
2910
2933
|
}
|
|
2911
2934
|
} catch (error) {
|
|
2912
|
-
|
|
2935
|
+
logger9.error(
|
|
2913
2936
|
{
|
|
2914
2937
|
sessionId: this.sessionId,
|
|
2915
2938
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -2947,7 +2970,7 @@ var GraphSession = class {
|
|
|
2947
2970
|
this.releaseUpdateLock();
|
|
2948
2971
|
}
|
|
2949
2972
|
} catch (error) {
|
|
2950
|
-
|
|
2973
|
+
logger9.error(
|
|
2951
2974
|
{
|
|
2952
2975
|
sessionId: this.sessionId,
|
|
2953
2976
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3025,7 +3048,7 @@ User's Question/Context:
|
|
|
3025
3048
|
${conversationHistory}
|
|
3026
3049
|
` : "";
|
|
3027
3050
|
} catch (error) {
|
|
3028
|
-
|
|
3051
|
+
logger9.warn(
|
|
3029
3052
|
{ sessionId: this.sessionId, error },
|
|
3030
3053
|
"Failed to fetch conversation history for structured status update"
|
|
3031
3054
|
);
|
|
@@ -3159,11 +3182,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3159
3182
|
return { summaries };
|
|
3160
3183
|
} catch (error) {
|
|
3161
3184
|
agentsCore.setSpanWithError(span, error);
|
|
3162
|
-
|
|
3185
|
+
logger9.error({ error }, "Failed to generate structured update, using fallback");
|
|
3163
3186
|
return { summaries: [] };
|
|
3164
3187
|
} finally {
|
|
3165
3188
|
span.end();
|
|
3166
|
-
await defaultBatchProcessor.forceFlush();
|
|
3167
3189
|
}
|
|
3168
3190
|
}
|
|
3169
3191
|
);
|
|
@@ -3374,7 +3396,7 @@ Make it specific and relevant.`;
|
|
|
3374
3396
|
});
|
|
3375
3397
|
if (agentData && "models" in agentData && agentData.models?.base?.model) {
|
|
3376
3398
|
modelToUse = agentData.models.base;
|
|
3377
|
-
|
|
3399
|
+
logger9.info(
|
|
3378
3400
|
{
|
|
3379
3401
|
sessionId: this.sessionId,
|
|
3380
3402
|
artifactId: artifactData.artifactId,
|
|
@@ -3385,7 +3407,7 @@ Make it specific and relevant.`;
|
|
|
3385
3407
|
);
|
|
3386
3408
|
}
|
|
3387
3409
|
} catch (error) {
|
|
3388
|
-
|
|
3410
|
+
logger9.warn(
|
|
3389
3411
|
{
|
|
3390
3412
|
sessionId: this.sessionId,
|
|
3391
3413
|
artifactId: artifactData.artifactId,
|
|
@@ -3397,7 +3419,7 @@ Make it specific and relevant.`;
|
|
|
3397
3419
|
}
|
|
3398
3420
|
}
|
|
3399
3421
|
if (!modelToUse?.model?.trim()) {
|
|
3400
|
-
|
|
3422
|
+
logger9.warn(
|
|
3401
3423
|
{
|
|
3402
3424
|
sessionId: this.sessionId,
|
|
3403
3425
|
artifactId: artifactData.artifactId
|
|
@@ -3471,7 +3493,7 @@ Make it specific and relevant.`;
|
|
|
3471
3493
|
return result2;
|
|
3472
3494
|
} catch (error) {
|
|
3473
3495
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
3474
|
-
|
|
3496
|
+
logger9.warn(
|
|
3475
3497
|
{
|
|
3476
3498
|
sessionId: this.sessionId,
|
|
3477
3499
|
artifactId: artifactData.artifactId,
|
|
@@ -3520,7 +3542,7 @@ Make it specific and relevant.`;
|
|
|
3520
3542
|
});
|
|
3521
3543
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
3522
3544
|
} catch (saveError) {
|
|
3523
|
-
|
|
3545
|
+
logger9.error(
|
|
3524
3546
|
{
|
|
3525
3547
|
sessionId: this.sessionId,
|
|
3526
3548
|
artifactId: artifactData.artifactId,
|
|
@@ -3548,7 +3570,7 @@ Make it specific and relevant.`;
|
|
|
3548
3570
|
fullProps: artifactData.fullProps || {},
|
|
3549
3571
|
metadata: artifactData.metadata || {}
|
|
3550
3572
|
});
|
|
3551
|
-
|
|
3573
|
+
logger9.info(
|
|
3552
3574
|
{
|
|
3553
3575
|
sessionId: this.sessionId,
|
|
3554
3576
|
artifactId: artifactData.artifactId
|
|
@@ -3559,7 +3581,7 @@ Make it specific and relevant.`;
|
|
|
3559
3581
|
} catch (fallbackError) {
|
|
3560
3582
|
const isDuplicateError = fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"));
|
|
3561
3583
|
if (isDuplicateError) ; else {
|
|
3562
|
-
|
|
3584
|
+
logger9.error(
|
|
3563
3585
|
{
|
|
3564
3586
|
sessionId: this.sessionId,
|
|
3565
3587
|
artifactId: artifactData.artifactId,
|
|
@@ -3572,7 +3594,7 @@ Make it specific and relevant.`;
|
|
|
3572
3594
|
}
|
|
3573
3595
|
} catch (error) {
|
|
3574
3596
|
agentsCore.setSpanWithError(span, error);
|
|
3575
|
-
|
|
3597
|
+
logger9.error(
|
|
3576
3598
|
{
|
|
3577
3599
|
sessionId: this.sessionId,
|
|
3578
3600
|
artifactId: artifactData.artifactId,
|
|
@@ -3582,7 +3604,6 @@ Make it specific and relevant.`;
|
|
|
3582
3604
|
);
|
|
3583
3605
|
} finally {
|
|
3584
3606
|
span.end();
|
|
3585
|
-
await defaultBatchProcessor.forceFlush();
|
|
3586
3607
|
}
|
|
3587
3608
|
}
|
|
3588
3609
|
);
|
|
@@ -3592,7 +3613,7 @@ Make it specific and relevant.`;
|
|
|
3592
3613
|
*/
|
|
3593
3614
|
setArtifactCache(key, artifact) {
|
|
3594
3615
|
this.artifactCache.set(key, artifact);
|
|
3595
|
-
|
|
3616
|
+
logger9.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
|
|
3596
3617
|
}
|
|
3597
3618
|
/**
|
|
3598
3619
|
* Get session-scoped ArtifactService instance
|
|
@@ -3611,7 +3632,7 @@ Make it specific and relevant.`;
|
|
|
3611
3632
|
*/
|
|
3612
3633
|
getArtifactCache(key) {
|
|
3613
3634
|
const artifact = this.artifactCache.get(key);
|
|
3614
|
-
|
|
3635
|
+
logger9.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
|
|
3615
3636
|
return artifact || null;
|
|
3616
3637
|
}
|
|
3617
3638
|
};
|
|
@@ -3626,7 +3647,7 @@ var GraphSessionManager = class {
|
|
|
3626
3647
|
const sessionId = messageId;
|
|
3627
3648
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
|
|
3628
3649
|
this.sessions.set(sessionId, session);
|
|
3629
|
-
|
|
3650
|
+
logger9.info(
|
|
3630
3651
|
{ sessionId, messageId, graphId, tenantId, projectId, contextId },
|
|
3631
3652
|
"GraphSession created"
|
|
3632
3653
|
);
|
|
@@ -3640,7 +3661,7 @@ var GraphSessionManager = class {
|
|
|
3640
3661
|
if (session) {
|
|
3641
3662
|
session.initializeStatusUpdates(config, summarizerModel);
|
|
3642
3663
|
} else {
|
|
3643
|
-
|
|
3664
|
+
logger9.error(
|
|
3644
3665
|
{
|
|
3645
3666
|
sessionId,
|
|
3646
3667
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -3661,7 +3682,7 @@ var GraphSessionManager = class {
|
|
|
3661
3682
|
recordEvent(sessionId, eventType, agentId, data) {
|
|
3662
3683
|
const session = this.sessions.get(sessionId);
|
|
3663
3684
|
if (!session) {
|
|
3664
|
-
|
|
3685
|
+
logger9.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
3665
3686
|
return;
|
|
3666
3687
|
}
|
|
3667
3688
|
session.recordEvent(eventType, agentId, data);
|
|
@@ -3672,12 +3693,12 @@ var GraphSessionManager = class {
|
|
|
3672
3693
|
endSession(sessionId) {
|
|
3673
3694
|
const session = this.sessions.get(sessionId);
|
|
3674
3695
|
if (!session) {
|
|
3675
|
-
|
|
3696
|
+
logger9.warn({ sessionId }, "Attempted to end non-existent session");
|
|
3676
3697
|
return [];
|
|
3677
3698
|
}
|
|
3678
3699
|
const events = session.getEvents();
|
|
3679
3700
|
const summary = session.getSummary();
|
|
3680
|
-
|
|
3701
|
+
logger9.info({ sessionId, summary }, "GraphSession ended");
|
|
3681
3702
|
session.cleanup();
|
|
3682
3703
|
this.sessions.delete(sessionId);
|
|
3683
3704
|
return events;
|
|
@@ -3736,7 +3757,7 @@ var graphSessionManager = new GraphSessionManager();
|
|
|
3736
3757
|
|
|
3737
3758
|
// src/services/IncrementalStreamParser.ts
|
|
3738
3759
|
init_logger();
|
|
3739
|
-
var
|
|
3760
|
+
var logger10 = agentsCore.getLogger("IncrementalStreamParser");
|
|
3740
3761
|
var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
3741
3762
|
// Max number of collected parts to prevent unbounded growth
|
|
3742
3763
|
constructor(streamHelper, tenantId, contextId, artifactParserOptions) {
|
|
@@ -3777,7 +3798,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3777
3798
|
async initializeArtifactMap() {
|
|
3778
3799
|
try {
|
|
3779
3800
|
this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
|
|
3780
|
-
|
|
3801
|
+
logger10.debug(
|
|
3781
3802
|
{
|
|
3782
3803
|
contextId: this.contextId,
|
|
3783
3804
|
artifactMapSize: this.artifactMap.size
|
|
@@ -3785,7 +3806,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3785
3806
|
"Initialized artifact map for streaming"
|
|
3786
3807
|
);
|
|
3787
3808
|
} catch (error) {
|
|
3788
|
-
|
|
3809
|
+
logger10.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
|
|
3789
3810
|
this.artifactMap = /* @__PURE__ */ new Map();
|
|
3790
3811
|
}
|
|
3791
3812
|
}
|
|
@@ -4094,7 +4115,7 @@ var IncrementalStreamParser = _IncrementalStreamParser;
|
|
|
4094
4115
|
|
|
4095
4116
|
// src/services/ResponseFormatter.ts
|
|
4096
4117
|
init_logger();
|
|
4097
|
-
var
|
|
4118
|
+
var logger11 = agentsCore.getLogger("ResponseFormatter");
|
|
4098
4119
|
var ResponseFormatter = class {
|
|
4099
4120
|
constructor(tenantId, artifactParserOptions) {
|
|
4100
4121
|
__publicField(this, "artifactParser");
|
|
@@ -4134,13 +4155,12 @@ var ResponseFormatter = class {
|
|
|
4134
4155
|
return { parts };
|
|
4135
4156
|
} catch (error) {
|
|
4136
4157
|
agentsCore.setSpanWithError(span, error);
|
|
4137
|
-
|
|
4158
|
+
logger11.error({ error, responseObject }, "Error formatting object response");
|
|
4138
4159
|
return {
|
|
4139
4160
|
parts: [{ kind: "data", data: responseObject }]
|
|
4140
4161
|
};
|
|
4141
4162
|
} finally {
|
|
4142
4163
|
span.end();
|
|
4143
|
-
await defaultBatchProcessor.forceFlush();
|
|
4144
4164
|
}
|
|
4145
4165
|
});
|
|
4146
4166
|
}
|
|
@@ -4187,11 +4207,10 @@ var ResponseFormatter = class {
|
|
|
4187
4207
|
return { parts };
|
|
4188
4208
|
} catch (error) {
|
|
4189
4209
|
agentsCore.setSpanWithError(span, error);
|
|
4190
|
-
|
|
4210
|
+
logger11.error({ error, responseText }, "Error formatting response");
|
|
4191
4211
|
return { text: responseText };
|
|
4192
4212
|
} finally {
|
|
4193
4213
|
span.end();
|
|
4194
|
-
await defaultBatchProcessor.forceFlush();
|
|
4195
4214
|
}
|
|
4196
4215
|
});
|
|
4197
4216
|
}
|
|
@@ -4270,10 +4289,10 @@ init_logger();
|
|
|
4270
4289
|
|
|
4271
4290
|
// src/utils/data-component-schema.ts
|
|
4272
4291
|
init_logger();
|
|
4273
|
-
var
|
|
4292
|
+
var logger12 = agentsCore.getLogger("DataComponentSchema");
|
|
4274
4293
|
function jsonSchemaToZod(jsonSchema) {
|
|
4275
4294
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
4276
|
-
|
|
4295
|
+
logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
4277
4296
|
return z5.z.string();
|
|
4278
4297
|
}
|
|
4279
4298
|
switch (jsonSchema.type) {
|
|
@@ -4300,7 +4319,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
4300
4319
|
case "null":
|
|
4301
4320
|
return z5.z.null();
|
|
4302
4321
|
default:
|
|
4303
|
-
|
|
4322
|
+
logger12.warn(
|
|
4304
4323
|
{
|
|
4305
4324
|
unsupportedType: jsonSchema.type,
|
|
4306
4325
|
schema: jsonSchema
|
|
@@ -4671,7 +4690,7 @@ function parseEmbeddedJson(data) {
|
|
|
4671
4690
|
|
|
4672
4691
|
// src/a2a/client.ts
|
|
4673
4692
|
init_logger();
|
|
4674
|
-
var
|
|
4693
|
+
var logger13 = agentsCore.getLogger("a2aClient");
|
|
4675
4694
|
var DEFAULT_BACKOFF = {
|
|
4676
4695
|
initialInterval: 500,
|
|
4677
4696
|
maxInterval: 6e4,
|
|
@@ -4877,7 +4896,7 @@ var A2AClient = class {
|
|
|
4877
4896
|
try {
|
|
4878
4897
|
const res = await fn();
|
|
4879
4898
|
if (attempt > 0) {
|
|
4880
|
-
|
|
4899
|
+
logger13.info(
|
|
4881
4900
|
{
|
|
4882
4901
|
attempts: attempt + 1,
|
|
4883
4902
|
elapsedTime: Date.now() - start
|
|
@@ -4892,7 +4911,7 @@ var A2AClient = class {
|
|
|
4892
4911
|
}
|
|
4893
4912
|
const elapsed = Date.now() - start;
|
|
4894
4913
|
if (elapsed > maxElapsedTime) {
|
|
4895
|
-
|
|
4914
|
+
logger13.warn(
|
|
4896
4915
|
{
|
|
4897
4916
|
attempts: attempt + 1,
|
|
4898
4917
|
elapsedTime: elapsed,
|
|
@@ -4913,7 +4932,7 @@ var A2AClient = class {
|
|
|
4913
4932
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
4914
4933
|
}
|
|
4915
4934
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
4916
|
-
|
|
4935
|
+
logger13.info(
|
|
4917
4936
|
{
|
|
4918
4937
|
attempt: attempt + 1,
|
|
4919
4938
|
delayMs,
|
|
@@ -4998,7 +5017,7 @@ var A2AClient = class {
|
|
|
4998
5017
|
}
|
|
4999
5018
|
const rpcResponse = await httpResponse.json();
|
|
5000
5019
|
if (rpcResponse.id !== requestId2) {
|
|
5001
|
-
|
|
5020
|
+
logger13.warn(
|
|
5002
5021
|
{
|
|
5003
5022
|
method,
|
|
5004
5023
|
expectedId: requestId2,
|
|
@@ -5197,7 +5216,7 @@ var A2AClient = class {
|
|
|
5197
5216
|
try {
|
|
5198
5217
|
while (true) {
|
|
5199
5218
|
const { done, value } = await reader.read();
|
|
5200
|
-
|
|
5219
|
+
logger13.info({ done, value }, "parseA2ASseStream");
|
|
5201
5220
|
if (done) {
|
|
5202
5221
|
if (eventDataBuffer.trim()) {
|
|
5203
5222
|
const result = this._processSseEventData(
|
|
@@ -5287,7 +5306,7 @@ var A2AClient = class {
|
|
|
5287
5306
|
init_conversations();
|
|
5288
5307
|
init_dbClient();
|
|
5289
5308
|
init_logger();
|
|
5290
|
-
var
|
|
5309
|
+
var logger14 = agentsCore.getLogger("relationships Tools");
|
|
5291
5310
|
var generateTransferToolDescription = (config) => {
|
|
5292
5311
|
return `Hand off the conversation to agent ${config.id}.
|
|
5293
5312
|
|
|
@@ -5325,7 +5344,7 @@ var createTransferToAgentTool = ({
|
|
|
5325
5344
|
"transfer.to_agent_id": transferConfig.id ?? "unknown"
|
|
5326
5345
|
});
|
|
5327
5346
|
}
|
|
5328
|
-
|
|
5347
|
+
logger14.info(
|
|
5329
5348
|
{
|
|
5330
5349
|
transferTo: transferConfig.id ?? "unknown",
|
|
5331
5350
|
fromAgent: callingAgentId
|
|
@@ -5474,7 +5493,7 @@ function createDelegateToAgentTool({
|
|
|
5474
5493
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
5475
5494
|
}
|
|
5476
5495
|
};
|
|
5477
|
-
|
|
5496
|
+
logger14.info({ messageToSend }, "messageToSend");
|
|
5478
5497
|
await agentsCore.createMessage(dbClient_default)({
|
|
5479
5498
|
id: nanoid.nanoid(),
|
|
5480
5499
|
tenantId,
|
|
@@ -5537,7 +5556,7 @@ function createDelegateToAgentTool({
|
|
|
5537
5556
|
|
|
5538
5557
|
// src/agents/SystemPromptBuilder.ts
|
|
5539
5558
|
init_logger();
|
|
5540
|
-
var
|
|
5559
|
+
var logger15 = agentsCore.getLogger("SystemPromptBuilder");
|
|
5541
5560
|
var SystemPromptBuilder = class {
|
|
5542
5561
|
constructor(version, versionConfig) {
|
|
5543
5562
|
this.version = version;
|
|
@@ -5553,12 +5572,12 @@ var SystemPromptBuilder = class {
|
|
|
5553
5572
|
this.templates.set(name, content);
|
|
5554
5573
|
}
|
|
5555
5574
|
this.loaded = true;
|
|
5556
|
-
|
|
5575
|
+
logger15.debug(
|
|
5557
5576
|
{ templateCount: this.templates.size, version: this.version },
|
|
5558
5577
|
`Loaded ${this.templates.size} templates for version ${this.version}`
|
|
5559
5578
|
);
|
|
5560
5579
|
} catch (error) {
|
|
5561
|
-
|
|
5580
|
+
logger15.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
5562
5581
|
throw new Error(`Template loading failed: ${error}`);
|
|
5563
5582
|
}
|
|
5564
5583
|
}
|
|
@@ -6604,7 +6623,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
6604
6623
|
return false;
|
|
6605
6624
|
};
|
|
6606
6625
|
}
|
|
6607
|
-
var
|
|
6626
|
+
var logger17 = agentsCore.getLogger("Agent");
|
|
6608
6627
|
var CONSTANTS = {
|
|
6609
6628
|
MAX_GENERATION_STEPS: 12,
|
|
6610
6629
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -6637,6 +6656,8 @@ var Agent = class {
|
|
|
6637
6656
|
__publicField(this, "isDelegatedAgent", false);
|
|
6638
6657
|
__publicField(this, "contextResolver");
|
|
6639
6658
|
__publicField(this, "credentialStoreRegistry");
|
|
6659
|
+
__publicField(this, "mcpClientCache", /* @__PURE__ */ new Map());
|
|
6660
|
+
__publicField(this, "mcpConnectionLocks", /* @__PURE__ */ new Map());
|
|
6640
6661
|
this.artifactComponents = config.artifactComponents || [];
|
|
6641
6662
|
let processedDataComponents = config.dataComponents || [];
|
|
6642
6663
|
if (processedDataComponents.length > 0) {
|
|
@@ -6903,14 +6924,14 @@ var Agent = class {
|
|
|
6903
6924
|
for (const toolSet of tools) {
|
|
6904
6925
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
6905
6926
|
if (!isValidTool(originalTool)) {
|
|
6906
|
-
|
|
6927
|
+
logger17.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
6907
6928
|
continue;
|
|
6908
6929
|
}
|
|
6909
6930
|
const sessionWrappedTool = ai.tool({
|
|
6910
6931
|
description: originalTool.description,
|
|
6911
6932
|
inputSchema: originalTool.inputSchema,
|
|
6912
6933
|
execute: async (args, { toolCallId }) => {
|
|
6913
|
-
|
|
6934
|
+
logger17.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
6914
6935
|
try {
|
|
6915
6936
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
6916
6937
|
const parsedResult = parseEmbeddedJson(rawResult);
|
|
@@ -6924,7 +6945,7 @@ var Agent = class {
|
|
|
6924
6945
|
});
|
|
6925
6946
|
return { result: enhancedResult, toolCallId };
|
|
6926
6947
|
} catch (error) {
|
|
6927
|
-
|
|
6948
|
+
logger17.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
6928
6949
|
throw error;
|
|
6929
6950
|
}
|
|
6930
6951
|
}
|
|
@@ -6959,6 +6980,7 @@ var Agent = class {
|
|
|
6959
6980
|
};
|
|
6960
6981
|
}
|
|
6961
6982
|
async getMcpTool(tool3) {
|
|
6983
|
+
const cacheKey = `${this.config.tenantId}-${this.config.projectId}-${tool3.id}-${tool3.credentialReferenceId || "no-cred"}`;
|
|
6962
6984
|
const credentialReferenceId = tool3.credentialReferenceId;
|
|
6963
6985
|
const toolsForAgent = await agentsCore.getToolsForAgent(dbClient_default)({
|
|
6964
6986
|
scopes: {
|
|
@@ -7018,7 +7040,7 @@ var Agent = class {
|
|
|
7018
7040
|
headers: agentToolRelationHeaders
|
|
7019
7041
|
};
|
|
7020
7042
|
}
|
|
7021
|
-
|
|
7043
|
+
logger17.info(
|
|
7022
7044
|
{
|
|
7023
7045
|
toolName: tool3.name,
|
|
7024
7046
|
credentialReferenceId,
|
|
@@ -7027,12 +7049,56 @@ var Agent = class {
|
|
|
7027
7049
|
},
|
|
7028
7050
|
"Built MCP server config with credentials"
|
|
7029
7051
|
);
|
|
7052
|
+
let client = this.mcpClientCache.get(cacheKey);
|
|
7053
|
+
if (client && !client.isConnected()) {
|
|
7054
|
+
this.mcpClientCache.delete(cacheKey);
|
|
7055
|
+
client = void 0;
|
|
7056
|
+
}
|
|
7057
|
+
if (!client) {
|
|
7058
|
+
let connectionPromise = this.mcpConnectionLocks.get(cacheKey);
|
|
7059
|
+
if (!connectionPromise) {
|
|
7060
|
+
connectionPromise = this.createMcpConnection(tool3, serverConfig);
|
|
7061
|
+
this.mcpConnectionLocks.set(cacheKey, connectionPromise);
|
|
7062
|
+
}
|
|
7063
|
+
try {
|
|
7064
|
+
client = await connectionPromise;
|
|
7065
|
+
this.mcpClientCache.set(cacheKey, client);
|
|
7066
|
+
} catch (error) {
|
|
7067
|
+
this.mcpConnectionLocks.delete(cacheKey);
|
|
7068
|
+
logger17.error(
|
|
7069
|
+
{
|
|
7070
|
+
toolName: tool3.name,
|
|
7071
|
+
agentId: this.config.id,
|
|
7072
|
+
cacheKey,
|
|
7073
|
+
error: error instanceof Error ? error.message : String(error)
|
|
7074
|
+
},
|
|
7075
|
+
"MCP connection failed"
|
|
7076
|
+
);
|
|
7077
|
+
throw error;
|
|
7078
|
+
}
|
|
7079
|
+
}
|
|
7080
|
+
const tools = await client.tools();
|
|
7081
|
+
return tools;
|
|
7082
|
+
}
|
|
7083
|
+
async createMcpConnection(tool3, serverConfig) {
|
|
7030
7084
|
const client = new agentsCore.McpClient({
|
|
7031
7085
|
name: tool3.name,
|
|
7032
7086
|
server: serverConfig
|
|
7033
7087
|
});
|
|
7034
|
-
|
|
7035
|
-
|
|
7088
|
+
try {
|
|
7089
|
+
await client.connect();
|
|
7090
|
+
return client;
|
|
7091
|
+
} catch (error) {
|
|
7092
|
+
logger17.error(
|
|
7093
|
+
{
|
|
7094
|
+
toolName: tool3.name,
|
|
7095
|
+
agentId: this.config.id,
|
|
7096
|
+
error: error instanceof Error ? error.message : String(error)
|
|
7097
|
+
},
|
|
7098
|
+
"Agent failed to connect to MCP server"
|
|
7099
|
+
);
|
|
7100
|
+
throw error;
|
|
7101
|
+
}
|
|
7036
7102
|
}
|
|
7037
7103
|
getFunctionTools(streamRequestId) {
|
|
7038
7104
|
if (!this.config.functionTools) return {};
|
|
@@ -7058,7 +7124,7 @@ var Agent = class {
|
|
|
7058
7124
|
async getResolvedContext(conversationId, requestContext) {
|
|
7059
7125
|
try {
|
|
7060
7126
|
if (!this.config.contextConfigId) {
|
|
7061
|
-
|
|
7127
|
+
logger17.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
7062
7128
|
return null;
|
|
7063
7129
|
}
|
|
7064
7130
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -7066,7 +7132,7 @@ var Agent = class {
|
|
|
7066
7132
|
id: this.config.contextConfigId
|
|
7067
7133
|
});
|
|
7068
7134
|
if (!contextConfig) {
|
|
7069
|
-
|
|
7135
|
+
logger17.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
7070
7136
|
return null;
|
|
7071
7137
|
}
|
|
7072
7138
|
if (!this.contextResolver) {
|
|
@@ -7078,13 +7144,12 @@ var Agent = class {
|
|
|
7078
7144
|
requestContext: requestContext || {},
|
|
7079
7145
|
tenantId: this.config.tenantId
|
|
7080
7146
|
});
|
|
7081
|
-
await defaultBatchProcessor.forceFlush();
|
|
7082
7147
|
const contextWithBuiltins = {
|
|
7083
7148
|
...result.resolvedContext,
|
|
7084
7149
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7085
7150
|
$env: process.env
|
|
7086
7151
|
};
|
|
7087
|
-
|
|
7152
|
+
logger17.debug(
|
|
7088
7153
|
{
|
|
7089
7154
|
conversationId,
|
|
7090
7155
|
contextConfigId: contextConfig.id,
|
|
@@ -7098,7 +7163,7 @@ var Agent = class {
|
|
|
7098
7163
|
);
|
|
7099
7164
|
return contextWithBuiltins;
|
|
7100
7165
|
} catch (error) {
|
|
7101
|
-
|
|
7166
|
+
logger17.error(
|
|
7102
7167
|
{
|
|
7103
7168
|
conversationId,
|
|
7104
7169
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7122,7 +7187,7 @@ var Agent = class {
|
|
|
7122
7187
|
});
|
|
7123
7188
|
return graphDefinition?.graphPrompt || void 0;
|
|
7124
7189
|
} catch (error) {
|
|
7125
|
-
|
|
7190
|
+
logger17.warn(
|
|
7126
7191
|
{
|
|
7127
7192
|
graphId: this.config.graphId,
|
|
7128
7193
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7151,7 +7216,7 @@ var Agent = class {
|
|
|
7151
7216
|
(agent) => "artifactComponents" in agent && agent.artifactComponents && agent.artifactComponents.length > 0
|
|
7152
7217
|
);
|
|
7153
7218
|
} catch (error) {
|
|
7154
|
-
|
|
7219
|
+
logger17.warn(
|
|
7155
7220
|
{
|
|
7156
7221
|
graphId: this.config.graphId,
|
|
7157
7222
|
tenantId: this.config.tenantId,
|
|
@@ -7180,7 +7245,7 @@ var Agent = class {
|
|
|
7180
7245
|
preserveUnresolved: false
|
|
7181
7246
|
});
|
|
7182
7247
|
} catch (error) {
|
|
7183
|
-
|
|
7248
|
+
logger17.error(
|
|
7184
7249
|
{
|
|
7185
7250
|
conversationId,
|
|
7186
7251
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7227,7 +7292,7 @@ var Agent = class {
|
|
|
7227
7292
|
preserveUnresolved: false
|
|
7228
7293
|
});
|
|
7229
7294
|
} catch (error) {
|
|
7230
|
-
|
|
7295
|
+
logger17.error(
|
|
7231
7296
|
{
|
|
7232
7297
|
conversationId,
|
|
7233
7298
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7266,7 +7331,7 @@ var Agent = class {
|
|
|
7266
7331
|
preserveUnresolved: false
|
|
7267
7332
|
});
|
|
7268
7333
|
} catch (error) {
|
|
7269
|
-
|
|
7334
|
+
logger17.error(
|
|
7270
7335
|
{
|
|
7271
7336
|
conversationId,
|
|
7272
7337
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7298,7 +7363,7 @@ var Agent = class {
|
|
|
7298
7363
|
artifactId: z5.z.string().describe("The unique identifier of the artifact to get.")
|
|
7299
7364
|
}),
|
|
7300
7365
|
execute: async ({ artifactId }) => {
|
|
7301
|
-
|
|
7366
|
+
logger17.info({ artifactId }, "get_artifact executed");
|
|
7302
7367
|
const artifact = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
7303
7368
|
scopes: {
|
|
7304
7369
|
tenantId: this.config.tenantId,
|
|
@@ -7548,7 +7613,7 @@ var Agent = class {
|
|
|
7548
7613
|
};
|
|
7549
7614
|
return enhanced;
|
|
7550
7615
|
} catch (error) {
|
|
7551
|
-
|
|
7616
|
+
logger17.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
7552
7617
|
return result;
|
|
7553
7618
|
}
|
|
7554
7619
|
}
|
|
@@ -7563,7 +7628,7 @@ var Agent = class {
|
|
|
7563
7628
|
}
|
|
7564
7629
|
});
|
|
7565
7630
|
} catch (error) {
|
|
7566
|
-
|
|
7631
|
+
logger17.error(
|
|
7567
7632
|
{ error, graphId: this.config.graphId },
|
|
7568
7633
|
"Failed to check graph artifact components"
|
|
7569
7634
|
);
|
|
@@ -7617,7 +7682,6 @@ var Agent = class {
|
|
|
7617
7682
|
throw err;
|
|
7618
7683
|
} finally {
|
|
7619
7684
|
childSpan.end();
|
|
7620
|
-
await defaultBatchProcessor.forceFlush();
|
|
7621
7685
|
}
|
|
7622
7686
|
}
|
|
7623
7687
|
);
|
|
@@ -7664,7 +7728,7 @@ var Agent = class {
|
|
|
7664
7728
|
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;
|
|
7665
7729
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
7666
7730
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
7667
|
-
|
|
7731
|
+
logger17.warn(
|
|
7668
7732
|
{
|
|
7669
7733
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
7670
7734
|
appliedTimeout: timeoutMs,
|
|
@@ -7706,7 +7770,7 @@ var Agent = class {
|
|
|
7706
7770
|
}
|
|
7707
7771
|
);
|
|
7708
7772
|
} catch (error) {
|
|
7709
|
-
|
|
7773
|
+
logger17.debug({ error }, "Failed to track agent reasoning");
|
|
7710
7774
|
}
|
|
7711
7775
|
}
|
|
7712
7776
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -7803,7 +7867,7 @@ var Agent = class {
|
|
|
7803
7867
|
}
|
|
7804
7868
|
);
|
|
7805
7869
|
} catch (error) {
|
|
7806
|
-
|
|
7870
|
+
logger17.debug({ error }, "Failed to track agent reasoning");
|
|
7807
7871
|
}
|
|
7808
7872
|
}
|
|
7809
7873
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8048,7 +8112,6 @@ ${output}${structureHintsFormatted}`;
|
|
|
8048
8112
|
}
|
|
8049
8113
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
8050
8114
|
span.end();
|
|
8051
|
-
await defaultBatchProcessor.forceFlush();
|
|
8052
8115
|
let formattedContent = response.formattedContent || null;
|
|
8053
8116
|
if (!formattedContent) {
|
|
8054
8117
|
const session = toolSessionManager.getSession(sessionId);
|
|
@@ -8095,7 +8158,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8095
8158
|
};
|
|
8096
8159
|
|
|
8097
8160
|
// src/agents/generateTaskHandler.ts
|
|
8098
|
-
var
|
|
8161
|
+
var logger18 = agentsCore.getLogger("generateTaskHandler");
|
|
8099
8162
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
8100
8163
|
return async (task) => {
|
|
8101
8164
|
try {
|
|
@@ -8148,7 +8211,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8148
8211
|
}
|
|
8149
8212
|
})
|
|
8150
8213
|
]);
|
|
8151
|
-
|
|
8214
|
+
logger18.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
8152
8215
|
const enhancedInternalRelations = await Promise.all(
|
|
8153
8216
|
internalRelations.map(async (relation) => {
|
|
8154
8217
|
try {
|
|
@@ -8177,7 +8240,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8177
8240
|
return { ...relation, description: enhancedDescription };
|
|
8178
8241
|
}
|
|
8179
8242
|
} catch (error) {
|
|
8180
|
-
|
|
8243
|
+
logger18.warn({ agentId: relation.id, error }, "Failed to enhance agent description");
|
|
8181
8244
|
}
|
|
8182
8245
|
return relation;
|
|
8183
8246
|
})
|
|
@@ -8277,7 +8340,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8277
8340
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
8278
8341
|
if (taskIdMatch) {
|
|
8279
8342
|
contextId = taskIdMatch[1];
|
|
8280
|
-
|
|
8343
|
+
logger18.info(
|
|
8281
8344
|
{
|
|
8282
8345
|
taskId: task.id,
|
|
8283
8346
|
extractedContextId: contextId,
|
|
@@ -8293,7 +8356,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8293
8356
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
8294
8357
|
agent.setDelegationStatus(isDelegation);
|
|
8295
8358
|
if (isDelegation) {
|
|
8296
|
-
|
|
8359
|
+
logger18.info(
|
|
8297
8360
|
{ agentId: config.agentId, taskId: task.id },
|
|
8298
8361
|
"Delegated agent - streaming disabled"
|
|
8299
8362
|
);
|
|
@@ -8518,7 +8581,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
8518
8581
|
init_dbClient();
|
|
8519
8582
|
init_logger();
|
|
8520
8583
|
var app = new zodOpenapi.OpenAPIHono();
|
|
8521
|
-
var
|
|
8584
|
+
var logger19 = agentsCore.getLogger("agents");
|
|
8522
8585
|
app.openapi(
|
|
8523
8586
|
zodOpenapi.createRoute({
|
|
8524
8587
|
method: "get",
|
|
@@ -8556,7 +8619,7 @@ app.openapi(
|
|
|
8556
8619
|
tracestate: c.req.header("tracestate"),
|
|
8557
8620
|
baggage: c.req.header("baggage")
|
|
8558
8621
|
};
|
|
8559
|
-
|
|
8622
|
+
logger19.info(
|
|
8560
8623
|
{
|
|
8561
8624
|
otelHeaders,
|
|
8562
8625
|
path: c.req.path,
|
|
@@ -8568,7 +8631,7 @@ app.openapi(
|
|
|
8568
8631
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
8569
8632
|
console.dir("executionContext", executionContext);
|
|
8570
8633
|
if (agentId) {
|
|
8571
|
-
|
|
8634
|
+
logger19.info(
|
|
8572
8635
|
{
|
|
8573
8636
|
message: "getRegisteredAgent (agent-level)",
|
|
8574
8637
|
tenantId,
|
|
@@ -8580,7 +8643,7 @@ app.openapi(
|
|
|
8580
8643
|
);
|
|
8581
8644
|
const credentialStores = c.get("credentialStores");
|
|
8582
8645
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
8583
|
-
|
|
8646
|
+
logger19.info({ agent }, "agent registered: well-known agent.json");
|
|
8584
8647
|
if (!agent) {
|
|
8585
8648
|
throw agentsCore.createApiError({
|
|
8586
8649
|
code: "not_found",
|
|
@@ -8589,7 +8652,7 @@ app.openapi(
|
|
|
8589
8652
|
}
|
|
8590
8653
|
return c.json(agent.agentCard);
|
|
8591
8654
|
} else {
|
|
8592
|
-
|
|
8655
|
+
logger19.info(
|
|
8593
8656
|
{
|
|
8594
8657
|
message: "getRegisteredGraph (graph-level)",
|
|
8595
8658
|
tenantId,
|
|
@@ -8615,7 +8678,7 @@ app.post("/a2a", async (c) => {
|
|
|
8615
8678
|
tracestate: c.req.header("tracestate"),
|
|
8616
8679
|
baggage: c.req.header("baggage")
|
|
8617
8680
|
};
|
|
8618
|
-
|
|
8681
|
+
logger19.info(
|
|
8619
8682
|
{
|
|
8620
8683
|
otelHeaders,
|
|
8621
8684
|
path: c.req.path,
|
|
@@ -8626,7 +8689,7 @@ app.post("/a2a", async (c) => {
|
|
|
8626
8689
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
8627
8690
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
8628
8691
|
if (agentId) {
|
|
8629
|
-
|
|
8692
|
+
logger19.info(
|
|
8630
8693
|
{
|
|
8631
8694
|
message: "a2a (agent-level)",
|
|
8632
8695
|
tenantId,
|
|
@@ -8650,7 +8713,7 @@ app.post("/a2a", async (c) => {
|
|
|
8650
8713
|
}
|
|
8651
8714
|
return a2aHandler(c, agent);
|
|
8652
8715
|
} else {
|
|
8653
|
-
|
|
8716
|
+
logger19.info(
|
|
8654
8717
|
{
|
|
8655
8718
|
message: "a2a (graph-level)",
|
|
8656
8719
|
tenantId,
|
|
@@ -8706,14 +8769,14 @@ init_dbClient();
|
|
|
8706
8769
|
// src/a2a/transfer.ts
|
|
8707
8770
|
init_dbClient();
|
|
8708
8771
|
init_logger();
|
|
8709
|
-
var
|
|
8772
|
+
var logger20 = agentsCore.getLogger("Transfer");
|
|
8710
8773
|
async function executeTransfer({
|
|
8711
8774
|
tenantId,
|
|
8712
8775
|
threadId,
|
|
8713
8776
|
projectId,
|
|
8714
8777
|
targetAgentId
|
|
8715
8778
|
}) {
|
|
8716
|
-
|
|
8779
|
+
logger20.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
8717
8780
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
8718
8781
|
scopes: { tenantId, projectId },
|
|
8719
8782
|
threadId,
|
|
@@ -9299,7 +9362,7 @@ function createMCPStreamHelper() {
|
|
|
9299
9362
|
}
|
|
9300
9363
|
|
|
9301
9364
|
// src/handlers/executionHandler.ts
|
|
9302
|
-
var
|
|
9365
|
+
var logger21 = agentsCore.getLogger("ExecutionHandler");
|
|
9303
9366
|
var ExecutionHandler = class {
|
|
9304
9367
|
constructor() {
|
|
9305
9368
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -9324,7 +9387,7 @@ var ExecutionHandler = class {
|
|
|
9324
9387
|
const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
|
|
9325
9388
|
registerStreamHelper(requestId2, sseHelper);
|
|
9326
9389
|
graphSessionManager.createSession(requestId2, graphId, tenantId, projectId, conversationId);
|
|
9327
|
-
|
|
9390
|
+
logger21.info(
|
|
9328
9391
|
{ sessionId: requestId2, graphId, conversationId },
|
|
9329
9392
|
"Created GraphSession for message execution"
|
|
9330
9393
|
);
|
|
@@ -9339,7 +9402,7 @@ var ExecutionHandler = class {
|
|
|
9339
9402
|
);
|
|
9340
9403
|
}
|
|
9341
9404
|
} catch (error) {
|
|
9342
|
-
|
|
9405
|
+
logger21.error(
|
|
9343
9406
|
{
|
|
9344
9407
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
9345
9408
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -9355,7 +9418,7 @@ var ExecutionHandler = class {
|
|
|
9355
9418
|
try {
|
|
9356
9419
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
9357
9420
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
9358
|
-
|
|
9421
|
+
logger21.info(
|
|
9359
9422
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
9360
9423
|
"Attempting to create or reuse existing task"
|
|
9361
9424
|
);
|
|
@@ -9379,7 +9442,7 @@ var ExecutionHandler = class {
|
|
|
9379
9442
|
agent_id: currentAgentId
|
|
9380
9443
|
}
|
|
9381
9444
|
});
|
|
9382
|
-
|
|
9445
|
+
logger21.info(
|
|
9383
9446
|
{
|
|
9384
9447
|
taskId,
|
|
9385
9448
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -9388,27 +9451,27 @@ var ExecutionHandler = class {
|
|
|
9388
9451
|
);
|
|
9389
9452
|
} catch (error) {
|
|
9390
9453
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
9391
|
-
|
|
9454
|
+
logger21.info(
|
|
9392
9455
|
{ taskId, error: error.message },
|
|
9393
9456
|
"Task already exists, fetching existing task"
|
|
9394
9457
|
);
|
|
9395
9458
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
9396
9459
|
if (existingTask) {
|
|
9397
9460
|
task = existingTask;
|
|
9398
|
-
|
|
9461
|
+
logger21.info(
|
|
9399
9462
|
{ taskId, existingTask },
|
|
9400
9463
|
"Successfully reused existing task from race condition"
|
|
9401
9464
|
);
|
|
9402
9465
|
} else {
|
|
9403
|
-
|
|
9466
|
+
logger21.error({ taskId, error }, "Task constraint failed but task not found");
|
|
9404
9467
|
throw error;
|
|
9405
9468
|
}
|
|
9406
9469
|
} else {
|
|
9407
|
-
|
|
9470
|
+
logger21.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
9408
9471
|
throw error;
|
|
9409
9472
|
}
|
|
9410
9473
|
}
|
|
9411
|
-
|
|
9474
|
+
logger21.debug(
|
|
9412
9475
|
{
|
|
9413
9476
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9414
9477
|
executionType: "create_initial_task",
|
|
@@ -9426,7 +9489,7 @@ var ExecutionHandler = class {
|
|
|
9426
9489
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
9427
9490
|
while (iterations < maxTransfers) {
|
|
9428
9491
|
iterations++;
|
|
9429
|
-
|
|
9492
|
+
logger21.info(
|
|
9430
9493
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
9431
9494
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
9432
9495
|
);
|
|
@@ -9434,10 +9497,10 @@ var ExecutionHandler = class {
|
|
|
9434
9497
|
scopes: { tenantId, projectId },
|
|
9435
9498
|
conversationId
|
|
9436
9499
|
});
|
|
9437
|
-
|
|
9500
|
+
logger21.info({ activeAgent }, "activeAgent");
|
|
9438
9501
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
9439
9502
|
currentAgentId = activeAgent.activeAgentId;
|
|
9440
|
-
|
|
9503
|
+
logger21.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
9441
9504
|
}
|
|
9442
9505
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
9443
9506
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -9478,13 +9541,13 @@ var ExecutionHandler = class {
|
|
|
9478
9541
|
});
|
|
9479
9542
|
if (!messageResponse?.result) {
|
|
9480
9543
|
errorCount++;
|
|
9481
|
-
|
|
9544
|
+
logger21.error(
|
|
9482
9545
|
{ currentAgentId, iterations, errorCount },
|
|
9483
9546
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
9484
9547
|
);
|
|
9485
9548
|
if (errorCount >= this.MAX_ERRORS) {
|
|
9486
9549
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
9487
|
-
|
|
9550
|
+
logger21.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
9488
9551
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
9489
9552
|
if (task) {
|
|
9490
9553
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -9509,7 +9572,7 @@ var ExecutionHandler = class {
|
|
|
9509
9572
|
const transferResponse = messageResponse.result;
|
|
9510
9573
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
9511
9574
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
9512
|
-
|
|
9575
|
+
logger21.info({ targetAgentId, transferReason }, "transfer response");
|
|
9513
9576
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
9514
9577
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
9515
9578
|
projectId,
|
|
@@ -9520,7 +9583,7 @@ var ExecutionHandler = class {
|
|
|
9520
9583
|
if (success) {
|
|
9521
9584
|
fromAgentId = currentAgentId;
|
|
9522
9585
|
currentAgentId = newAgentId;
|
|
9523
|
-
|
|
9586
|
+
logger21.info(
|
|
9524
9587
|
{
|
|
9525
9588
|
transferFrom: fromAgentId,
|
|
9526
9589
|
transferTo: currentAgentId,
|
|
@@ -9538,7 +9601,7 @@ var ExecutionHandler = class {
|
|
|
9538
9601
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
9539
9602
|
if (graphSessionData) {
|
|
9540
9603
|
const sessionSummary = graphSessionData.getSummary();
|
|
9541
|
-
|
|
9604
|
+
logger21.info(sessionSummary, "GraphSession data after completion");
|
|
9542
9605
|
}
|
|
9543
9606
|
let textContent = "";
|
|
9544
9607
|
for (const part of responseParts) {
|
|
@@ -9592,40 +9655,39 @@ var ExecutionHandler = class {
|
|
|
9592
9655
|
}
|
|
9593
9656
|
});
|
|
9594
9657
|
const updateTaskEnd = Date.now();
|
|
9595
|
-
|
|
9658
|
+
logger21.info(
|
|
9596
9659
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
9597
9660
|
"Completed updateTask operation"
|
|
9598
9661
|
);
|
|
9599
9662
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
9600
9663
|
await sseHelper.complete();
|
|
9601
|
-
|
|
9664
|
+
logger21.info({}, "Ending GraphSession and cleaning up");
|
|
9602
9665
|
graphSessionManager.endSession(requestId2);
|
|
9603
|
-
|
|
9666
|
+
logger21.info({}, "Cleaning up streamHelper");
|
|
9604
9667
|
unregisterStreamHelper(requestId2);
|
|
9605
9668
|
let response;
|
|
9606
9669
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
9607
9670
|
const captured = sseHelper.getCapturedResponse();
|
|
9608
9671
|
response = captured.text || "No response content";
|
|
9609
9672
|
}
|
|
9610
|
-
|
|
9673
|
+
logger21.info({}, "ExecutionHandler returning success");
|
|
9611
9674
|
return { success: true, iterations, response };
|
|
9612
9675
|
} catch (error) {
|
|
9613
9676
|
agentsCore.setSpanWithError(span, error);
|
|
9614
9677
|
throw error;
|
|
9615
9678
|
} finally {
|
|
9616
9679
|
span.end();
|
|
9617
|
-
await defaultBatchProcessor.forceFlush();
|
|
9618
9680
|
}
|
|
9619
9681
|
});
|
|
9620
9682
|
}
|
|
9621
9683
|
errorCount++;
|
|
9622
|
-
|
|
9684
|
+
logger21.warn(
|
|
9623
9685
|
{ iterations, errorCount },
|
|
9624
9686
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
9625
9687
|
);
|
|
9626
9688
|
if (errorCount >= this.MAX_ERRORS) {
|
|
9627
9689
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
9628
|
-
|
|
9690
|
+
logger21.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
9629
9691
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
9630
9692
|
if (task) {
|
|
9631
9693
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -9646,7 +9708,7 @@ var ExecutionHandler = class {
|
|
|
9646
9708
|
}
|
|
9647
9709
|
}
|
|
9648
9710
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
9649
|
-
|
|
9711
|
+
logger21.error({ maxTransfers, iterations }, errorMessage);
|
|
9650
9712
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
9651
9713
|
if (task) {
|
|
9652
9714
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -9665,7 +9727,7 @@ var ExecutionHandler = class {
|
|
|
9665
9727
|
unregisterStreamHelper(requestId2);
|
|
9666
9728
|
return { success: false, error: errorMessage, iterations };
|
|
9667
9729
|
} catch (error) {
|
|
9668
|
-
|
|
9730
|
+
logger21.error({ error }, "Error in execution handler");
|
|
9669
9731
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
9670
9732
|
await sseHelper.writeOperation(
|
|
9671
9733
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -9693,7 +9755,7 @@ var ExecutionHandler = class {
|
|
|
9693
9755
|
// src/routes/chat.ts
|
|
9694
9756
|
init_logger();
|
|
9695
9757
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
9696
|
-
var
|
|
9758
|
+
var logger22 = agentsCore.getLogger("completionsHandler");
|
|
9697
9759
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
9698
9760
|
method: "post",
|
|
9699
9761
|
path: "/completions",
|
|
@@ -9811,7 +9873,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9811
9873
|
tracestate: c.req.header("tracestate"),
|
|
9812
9874
|
baggage: c.req.header("baggage")
|
|
9813
9875
|
};
|
|
9814
|
-
|
|
9876
|
+
logger22.info(
|
|
9815
9877
|
{
|
|
9816
9878
|
otelHeaders,
|
|
9817
9879
|
path: c.req.path,
|
|
@@ -9904,7 +9966,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9904
9966
|
dbClient: dbClient_default,
|
|
9905
9967
|
credentialStores
|
|
9906
9968
|
});
|
|
9907
|
-
|
|
9969
|
+
logger22.info(
|
|
9908
9970
|
{
|
|
9909
9971
|
tenantId,
|
|
9910
9972
|
projectId,
|
|
@@ -9952,7 +10014,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9952
10014
|
try {
|
|
9953
10015
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
9954
10016
|
await sseHelper.writeRole();
|
|
9955
|
-
|
|
10017
|
+
logger22.info({ agentId }, "Starting execution");
|
|
9956
10018
|
const executionHandler = new ExecutionHandler();
|
|
9957
10019
|
const result = await executionHandler.execute({
|
|
9958
10020
|
executionContext,
|
|
@@ -9962,7 +10024,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9962
10024
|
requestId: requestId2,
|
|
9963
10025
|
sseHelper
|
|
9964
10026
|
});
|
|
9965
|
-
|
|
10027
|
+
logger22.info(
|
|
9966
10028
|
{ result },
|
|
9967
10029
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
9968
10030
|
);
|
|
@@ -9976,7 +10038,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9976
10038
|
}
|
|
9977
10039
|
await sseHelper.complete();
|
|
9978
10040
|
} catch (error) {
|
|
9979
|
-
|
|
10041
|
+
logger22.error(
|
|
9980
10042
|
{
|
|
9981
10043
|
error: error instanceof Error ? error.message : error,
|
|
9982
10044
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -9993,12 +10055,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9993
10055
|
);
|
|
9994
10056
|
await sseHelper.complete();
|
|
9995
10057
|
} catch (streamError) {
|
|
9996
|
-
|
|
10058
|
+
logger22.error({ streamError }, "Failed to write error to stream");
|
|
9997
10059
|
}
|
|
9998
10060
|
}
|
|
9999
10061
|
});
|
|
10000
10062
|
} catch (error) {
|
|
10001
|
-
|
|
10063
|
+
logger22.error(
|
|
10002
10064
|
{
|
|
10003
10065
|
error: error instanceof Error ? error.message : error,
|
|
10004
10066
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10026,7 +10088,7 @@ var chat_default = app2;
|
|
|
10026
10088
|
init_dbClient();
|
|
10027
10089
|
init_logger();
|
|
10028
10090
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
10029
|
-
var
|
|
10091
|
+
var logger23 = agentsCore.getLogger("chatDataStream");
|
|
10030
10092
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
10031
10093
|
method: "post",
|
|
10032
10094
|
path: "/chat",
|
|
@@ -10141,10 +10203,9 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10141
10203
|
dbClient: dbClient_default,
|
|
10142
10204
|
credentialStores
|
|
10143
10205
|
});
|
|
10144
|
-
await defaultBatchProcessor.forceFlush();
|
|
10145
10206
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
10146
10207
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
10147
|
-
|
|
10208
|
+
logger23.info({ userText, lastUserMessage }, "userText");
|
|
10148
10209
|
const messageSpan = api.trace.getActiveSpan();
|
|
10149
10210
|
if (messageSpan) {
|
|
10150
10211
|
messageSpan.setAttributes({
|
|
@@ -10186,7 +10247,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10186
10247
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
10187
10248
|
}
|
|
10188
10249
|
} catch (err) {
|
|
10189
|
-
|
|
10250
|
+
logger23.error({ err }, "Streaming error");
|
|
10190
10251
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
10191
10252
|
} finally {
|
|
10192
10253
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -10207,7 +10268,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10207
10268
|
)
|
|
10208
10269
|
);
|
|
10209
10270
|
} catch (error) {
|
|
10210
|
-
|
|
10271
|
+
logger23.error({ error }, "chatDataStream error");
|
|
10211
10272
|
throw agentsCore.createApiError({
|
|
10212
10273
|
code: "internal_server_error",
|
|
10213
10274
|
message: "Failed to process chat completion"
|
|
@@ -10222,7 +10283,7 @@ init_logger();
|
|
|
10222
10283
|
function createMCPSchema(schema) {
|
|
10223
10284
|
return schema;
|
|
10224
10285
|
}
|
|
10225
|
-
var
|
|
10286
|
+
var logger24 = agentsCore.getLogger("mcp");
|
|
10226
10287
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
10227
10288
|
constructor() {
|
|
10228
10289
|
__publicField(this, "mockRes");
|
|
@@ -10277,21 +10338,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
10277
10338
|
id: 0
|
|
10278
10339
|
});
|
|
10279
10340
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
10280
|
-
|
|
10341
|
+
logger24.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
10281
10342
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
10282
10343
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
10283
10344
|
try {
|
|
10284
10345
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
10285
|
-
|
|
10346
|
+
logger24.info({ sessionId }, "Successfully spoofed initialization");
|
|
10286
10347
|
} catch (spoofError) {
|
|
10287
|
-
|
|
10348
|
+
logger24.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
10288
10349
|
}
|
|
10289
10350
|
};
|
|
10290
10351
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
10291
10352
|
const sessionId = req.headers["mcp-session-id"];
|
|
10292
|
-
|
|
10353
|
+
logger24.info({ sessionId }, "Received MCP session ID");
|
|
10293
10354
|
if (!sessionId) {
|
|
10294
|
-
|
|
10355
|
+
logger24.info({ body }, "Missing session ID");
|
|
10295
10356
|
res.writeHead(400).end(
|
|
10296
10357
|
JSON.stringify({
|
|
10297
10358
|
jsonrpc: "2.0",
|
|
@@ -10317,7 +10378,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10317
10378
|
scopes: { tenantId, projectId },
|
|
10318
10379
|
conversationId: sessionId
|
|
10319
10380
|
});
|
|
10320
|
-
|
|
10381
|
+
logger24.info(
|
|
10321
10382
|
{
|
|
10322
10383
|
sessionId,
|
|
10323
10384
|
conversationFound: !!conversation,
|
|
@@ -10328,7 +10389,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10328
10389
|
"Conversation lookup result"
|
|
10329
10390
|
);
|
|
10330
10391
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
10331
|
-
|
|
10392
|
+
logger24.info(
|
|
10332
10393
|
{ sessionId, conversationId: conversation?.id },
|
|
10333
10394
|
"MCP session not found or invalid"
|
|
10334
10395
|
);
|
|
@@ -10389,7 +10450,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
10389
10450
|
requestId: requestId2,
|
|
10390
10451
|
sseHelper: mcpStreamHelper
|
|
10391
10452
|
});
|
|
10392
|
-
|
|
10453
|
+
logger24.info(
|
|
10393
10454
|
{ result },
|
|
10394
10455
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10395
10456
|
);
|
|
@@ -10473,7 +10534,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
10473
10534
|
dbClient: dbClient_default,
|
|
10474
10535
|
credentialStores
|
|
10475
10536
|
});
|
|
10476
|
-
|
|
10537
|
+
logger24.info(
|
|
10477
10538
|
{
|
|
10478
10539
|
tenantId,
|
|
10479
10540
|
projectId,
|
|
@@ -10535,7 +10596,7 @@ var validateRequestParameters = (c) => {
|
|
|
10535
10596
|
};
|
|
10536
10597
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
10537
10598
|
const { tenantId, projectId, graphId } = executionContext;
|
|
10538
|
-
|
|
10599
|
+
logger24.info({ body }, "Received initialization request");
|
|
10539
10600
|
const sessionId = nanoid.nanoid();
|
|
10540
10601
|
const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
10541
10602
|
scopes: { tenantId, projectId, graphId }
|
|
@@ -10575,7 +10636,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10575
10636
|
}
|
|
10576
10637
|
}
|
|
10577
10638
|
});
|
|
10578
|
-
|
|
10639
|
+
logger24.info(
|
|
10579
10640
|
{ sessionId, conversationId: conversation.id },
|
|
10580
10641
|
"Created MCP session as conversation"
|
|
10581
10642
|
);
|
|
@@ -10584,9 +10645,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10584
10645
|
});
|
|
10585
10646
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
10586
10647
|
await server.connect(transport);
|
|
10587
|
-
|
|
10648
|
+
logger24.info({ sessionId }, "Server connected for initialization");
|
|
10588
10649
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
10589
|
-
|
|
10650
|
+
logger24.info(
|
|
10590
10651
|
{
|
|
10591
10652
|
sessionId,
|
|
10592
10653
|
bodyMethod: body?.method,
|
|
@@ -10595,7 +10656,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10595
10656
|
"About to handle initialization request"
|
|
10596
10657
|
);
|
|
10597
10658
|
await transport.handleRequest(req, res, body);
|
|
10598
|
-
|
|
10659
|
+
logger24.info({ sessionId }, "Successfully handled initialization request");
|
|
10599
10660
|
return fetchToNode.toFetchResponse(res);
|
|
10600
10661
|
};
|
|
10601
10662
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -10623,8 +10684,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
10623
10684
|
sessionId,
|
|
10624
10685
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
10625
10686
|
);
|
|
10626
|
-
|
|
10627
|
-
|
|
10687
|
+
logger24.info({ sessionId }, "Server connected and transport initialized");
|
|
10688
|
+
logger24.info(
|
|
10628
10689
|
{
|
|
10629
10690
|
sessionId,
|
|
10630
10691
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -10638,9 +10699,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
10638
10699
|
);
|
|
10639
10700
|
try {
|
|
10640
10701
|
await transport.handleRequest(req, res, body);
|
|
10641
|
-
|
|
10702
|
+
logger24.info({ sessionId }, "Successfully handled MCP request");
|
|
10642
10703
|
} catch (transportError) {
|
|
10643
|
-
|
|
10704
|
+
logger24.error(
|
|
10644
10705
|
{
|
|
10645
10706
|
sessionId,
|
|
10646
10707
|
error: transportError,
|
|
@@ -10691,13 +10752,13 @@ app4.openapi(
|
|
|
10691
10752
|
}
|
|
10692
10753
|
const { executionContext } = paramValidation;
|
|
10693
10754
|
const body = c.get("requestBody") || {};
|
|
10694
|
-
|
|
10755
|
+
logger24.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
10695
10756
|
const isInitRequest = body.method === "initialize";
|
|
10696
10757
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
10697
10758
|
const validatedContext = c.get("validatedContext") || {};
|
|
10698
10759
|
const credentialStores = c.get("credentialStores");
|
|
10699
|
-
|
|
10700
|
-
|
|
10760
|
+
logger24.info({ validatedContext }, "Validated context");
|
|
10761
|
+
logger24.info({ req }, "request");
|
|
10701
10762
|
if (isInitRequest) {
|
|
10702
10763
|
return await handleInitializationRequest(
|
|
10703
10764
|
body,
|
|
@@ -10719,7 +10780,7 @@ app4.openapi(
|
|
|
10719
10780
|
);
|
|
10720
10781
|
}
|
|
10721
10782
|
} catch (e) {
|
|
10722
|
-
|
|
10783
|
+
logger24.error(
|
|
10723
10784
|
{
|
|
10724
10785
|
error: e instanceof Error ? e.message : e,
|
|
10725
10786
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -10731,7 +10792,7 @@ app4.openapi(
|
|
|
10731
10792
|
}
|
|
10732
10793
|
);
|
|
10733
10794
|
app4.get("/", async (c) => {
|
|
10734
|
-
|
|
10795
|
+
logger24.info({}, "Received GET MCP request");
|
|
10735
10796
|
return c.json(
|
|
10736
10797
|
{
|
|
10737
10798
|
jsonrpc: "2.0",
|
|
@@ -10745,7 +10806,7 @@ app4.get("/", async (c) => {
|
|
|
10745
10806
|
);
|
|
10746
10807
|
});
|
|
10747
10808
|
app4.delete("/", async (c) => {
|
|
10748
|
-
|
|
10809
|
+
logger24.info({}, "Received DELETE MCP request");
|
|
10749
10810
|
return c.json(
|
|
10750
10811
|
{
|
|
10751
10812
|
jsonrpc: "2.0",
|
|
@@ -10758,7 +10819,7 @@ app4.delete("/", async (c) => {
|
|
|
10758
10819
|
var mcp_default = app4;
|
|
10759
10820
|
|
|
10760
10821
|
// src/app.ts
|
|
10761
|
-
var
|
|
10822
|
+
var logger25 = agentsCore.getLogger("agents-run-api");
|
|
10762
10823
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
10763
10824
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
10764
10825
|
app6.use("*", otel.otel());
|
|
@@ -10774,7 +10835,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10774
10835
|
const body = await c.req.json();
|
|
10775
10836
|
c.set("requestBody", body);
|
|
10776
10837
|
} catch (error) {
|
|
10777
|
-
|
|
10838
|
+
logger25.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
10778
10839
|
}
|
|
10779
10840
|
}
|
|
10780
10841
|
return next();
|
|
@@ -10825,8 +10886,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10825
10886
|
if (!isExpectedError) {
|
|
10826
10887
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
10827
10888
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
10828
|
-
if (
|
|
10829
|
-
|
|
10889
|
+
if (logger25) {
|
|
10890
|
+
logger25.error(
|
|
10830
10891
|
{
|
|
10831
10892
|
error: err,
|
|
10832
10893
|
message: errorMessage,
|
|
@@ -10838,8 +10899,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10838
10899
|
);
|
|
10839
10900
|
}
|
|
10840
10901
|
} else {
|
|
10841
|
-
if (
|
|
10842
|
-
|
|
10902
|
+
if (logger25) {
|
|
10903
|
+
logger25.error(
|
|
10843
10904
|
{
|
|
10844
10905
|
error: err,
|
|
10845
10906
|
path: c.req.path,
|
|
@@ -10856,8 +10917,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10856
10917
|
const response = err.getResponse();
|
|
10857
10918
|
return response;
|
|
10858
10919
|
} catch (responseError) {
|
|
10859
|
-
if (
|
|
10860
|
-
|
|
10920
|
+
if (logger25) {
|
|
10921
|
+
logger25.error({ error: responseError }, "Error while handling HTTPException response");
|
|
10861
10922
|
}
|
|
10862
10923
|
}
|
|
10863
10924
|
}
|
|
@@ -10891,7 +10952,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10891
10952
|
app6.use("*", async (c, next) => {
|
|
10892
10953
|
const executionContext = c.get("executionContext");
|
|
10893
10954
|
if (!executionContext) {
|
|
10894
|
-
|
|
10955
|
+
logger25.debug({}, "Empty execution context");
|
|
10895
10956
|
return next();
|
|
10896
10957
|
}
|
|
10897
10958
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -10900,7 +10961,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10900
10961
|
if (requestBody) {
|
|
10901
10962
|
conversationId = requestBody.conversationId;
|
|
10902
10963
|
if (!conversationId) {
|
|
10903
|
-
|
|
10964
|
+
logger25.debug({ requestBody }, "No conversation ID found in request body");
|
|
10904
10965
|
}
|
|
10905
10966
|
}
|
|
10906
10967
|
const entries = Object.fromEntries(
|
|
@@ -10915,7 +10976,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10915
10976
|
})
|
|
10916
10977
|
);
|
|
10917
10978
|
if (!Object.keys(entries).length) {
|
|
10918
|
-
|
|
10979
|
+
logger25.debug({}, "Empty entries for baggage");
|
|
10919
10980
|
return next();
|
|
10920
10981
|
}
|
|
10921
10982
|
const bag = Object.entries(entries).reduce(
|
|
@@ -10949,19 +11010,19 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10949
11010
|
setupOpenAPIRoutes(app6);
|
|
10950
11011
|
app6.use("/tenants/*", async (_c, next) => {
|
|
10951
11012
|
await next();
|
|
10952
|
-
await
|
|
11013
|
+
await flushBatchProcessor();
|
|
10953
11014
|
});
|
|
10954
11015
|
app6.use("/agents/*", async (_c, next) => {
|
|
10955
11016
|
await next();
|
|
10956
|
-
await
|
|
11017
|
+
await flushBatchProcessor();
|
|
10957
11018
|
});
|
|
10958
11019
|
app6.use("/v1/*", async (_c, next) => {
|
|
10959
11020
|
await next();
|
|
10960
|
-
await
|
|
11021
|
+
await flushBatchProcessor();
|
|
10961
11022
|
});
|
|
10962
11023
|
app6.use("/api/*", async (_c, next) => {
|
|
10963
11024
|
await next();
|
|
10964
|
-
await
|
|
11025
|
+
await flushBatchProcessor();
|
|
10965
11026
|
});
|
|
10966
11027
|
const baseApp = new hono.Hono();
|
|
10967
11028
|
baseApp.route("/", app6);
|