@inkeep/agents-run-api 0.14.1 → 0.14.3
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-5RGAMXUL.js → chunk-USFUAR3Y.js} +14 -3
- package/dist/index.cjs +244 -221
- package/dist/index.js +10 -1
- package/dist/instrumentation.cjs +15 -1
- package/dist/instrumentation.d.cts +2 -2
- package/dist/instrumentation.d.ts +2 -2
- package/dist/instrumentation.js +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -343,8 +343,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
343
343
|
});
|
|
344
344
|
referenceArtifacts.push(...artifacts);
|
|
345
345
|
}
|
|
346
|
-
const
|
|
347
|
-
|
|
346
|
+
const logger26 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
347
|
+
logger26.debug(
|
|
348
348
|
{
|
|
349
349
|
conversationId,
|
|
350
350
|
visibleMessages: visibleMessages.length,
|
|
@@ -356,8 +356,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
356
356
|
);
|
|
357
357
|
return referenceArtifacts;
|
|
358
358
|
} catch (error) {
|
|
359
|
-
const
|
|
360
|
-
|
|
359
|
+
const logger26 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
360
|
+
logger26.error(
|
|
361
361
|
{
|
|
362
362
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
363
363
|
conversationId
|
|
@@ -395,8 +395,22 @@ var init_json_postprocessor = __esm({
|
|
|
395
395
|
|
|
396
396
|
// src/index.ts
|
|
397
397
|
init_env();
|
|
398
|
+
|
|
399
|
+
// src/instrumentation.ts
|
|
400
|
+
init_logger();
|
|
398
401
|
var otlpExporter = new exporterTraceOtlpHttp.OTLPTraceExporter();
|
|
399
|
-
var
|
|
402
|
+
var logger = agentsCore.getLogger("instrumentation");
|
|
403
|
+
function createSafeBatchProcessor() {
|
|
404
|
+
try {
|
|
405
|
+
return new sdkTraceBase.BatchSpanProcessor(otlpExporter, {
|
|
406
|
+
scheduledDelayMillis: 1e3
|
|
407
|
+
});
|
|
408
|
+
} catch (error) {
|
|
409
|
+
logger.warn({ error }, "Failed to create batch processor");
|
|
410
|
+
return new sdkTraceBase.NoopSpanProcessor();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
var defaultBatchProcessor = createSafeBatchProcessor();
|
|
400
414
|
var defaultResource = resources.resourceFromAttributes({
|
|
401
415
|
[semanticConventions.ATTR_SERVICE_NAME]: "inkeep-agents-run-api"
|
|
402
416
|
});
|
|
@@ -460,7 +474,7 @@ function createExecutionContext(params) {
|
|
|
460
474
|
}
|
|
461
475
|
|
|
462
476
|
// src/middleware/api-key-auth.ts
|
|
463
|
-
var
|
|
477
|
+
var logger2 = agentsCore.getLogger("env-key-auth");
|
|
464
478
|
var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
465
479
|
if (c.req.method === "OPTIONS") {
|
|
466
480
|
await next();
|
|
@@ -478,7 +492,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
478
492
|
try {
|
|
479
493
|
executionContext = await extractContextFromApiKey(authHeader.substring(7), baseUrl);
|
|
480
494
|
executionContext.agentId = agentId;
|
|
481
|
-
|
|
495
|
+
logger2.info({}, "Development/test environment - API key authenticated successfully");
|
|
482
496
|
} catch {
|
|
483
497
|
executionContext = createExecutionContext({
|
|
484
498
|
apiKey: "development",
|
|
@@ -489,7 +503,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
489
503
|
baseUrl,
|
|
490
504
|
agentId
|
|
491
505
|
});
|
|
492
|
-
|
|
506
|
+
logger2.info(
|
|
493
507
|
{},
|
|
494
508
|
"Development/test environment - fallback to default context due to invalid API key"
|
|
495
509
|
);
|
|
@@ -504,7 +518,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
504
518
|
baseUrl,
|
|
505
519
|
agentId
|
|
506
520
|
});
|
|
507
|
-
|
|
521
|
+
logger2.info(
|
|
508
522
|
{},
|
|
509
523
|
"Development/test environment - no API key provided, using default context"
|
|
510
524
|
);
|
|
@@ -536,14 +550,14 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
536
550
|
agentId
|
|
537
551
|
});
|
|
538
552
|
c.set("executionContext", executionContext);
|
|
539
|
-
|
|
553
|
+
logger2.info({}, "Bypass secret authenticated successfully");
|
|
540
554
|
await next();
|
|
541
555
|
return;
|
|
542
556
|
} else if (apiKey) {
|
|
543
557
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
544
558
|
executionContext.agentId = agentId;
|
|
545
559
|
c.set("executionContext", executionContext);
|
|
546
|
-
|
|
560
|
+
logger2.info({}, "API key authenticated successfully");
|
|
547
561
|
await next();
|
|
548
562
|
return;
|
|
549
563
|
} else {
|
|
@@ -561,7 +575,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
561
575
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
562
576
|
executionContext.agentId = agentId;
|
|
563
577
|
c.set("executionContext", executionContext);
|
|
564
|
-
|
|
578
|
+
logger2.debug(
|
|
565
579
|
{
|
|
566
580
|
tenantId: executionContext.tenantId,
|
|
567
581
|
projectId: executionContext.projectId,
|
|
@@ -575,7 +589,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
575
589
|
if (error instanceof httpException.HTTPException) {
|
|
576
590
|
throw error;
|
|
577
591
|
}
|
|
578
|
-
|
|
592
|
+
logger2.error({ error }, "API key authentication error");
|
|
579
593
|
throw new httpException.HTTPException(500, {
|
|
580
594
|
message: "Authentication failed"
|
|
581
595
|
});
|
|
@@ -636,7 +650,7 @@ function setupOpenAPIRoutes(app6) {
|
|
|
636
650
|
// src/a2a/handlers.ts
|
|
637
651
|
init_dbClient();
|
|
638
652
|
init_logger();
|
|
639
|
-
var
|
|
653
|
+
var logger3 = agentsCore.getLogger("a2aHandler");
|
|
640
654
|
async function a2aHandler(c, agent) {
|
|
641
655
|
try {
|
|
642
656
|
const rpcRequest = c.get("requestBody");
|
|
@@ -738,7 +752,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
738
752
|
messageId: task.id,
|
|
739
753
|
kind: "message"
|
|
740
754
|
});
|
|
741
|
-
|
|
755
|
+
logger3.warn(
|
|
742
756
|
{
|
|
743
757
|
taskId: task.id,
|
|
744
758
|
agentId: agent.agentId,
|
|
@@ -748,7 +762,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
748
762
|
);
|
|
749
763
|
}
|
|
750
764
|
} catch (error) {
|
|
751
|
-
|
|
765
|
+
logger3.error({ error, taskId: task.id }, "Failed to serialize message");
|
|
752
766
|
JSON.stringify({
|
|
753
767
|
error: "Failed to serialize message",
|
|
754
768
|
taskId: task.id,
|
|
@@ -756,7 +770,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
756
770
|
parts: [{ text: "Error in delegation", kind: "text" }]
|
|
757
771
|
});
|
|
758
772
|
}
|
|
759
|
-
|
|
773
|
+
logger3.info(
|
|
760
774
|
{
|
|
761
775
|
originalContextId: params.message.contextId,
|
|
762
776
|
taskContextId: task.context?.conversationId,
|
|
@@ -786,7 +800,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
786
800
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
787
801
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
788
802
|
});
|
|
789
|
-
|
|
803
|
+
logger3.info({ metadata: params.message.metadata }, "message metadata");
|
|
790
804
|
if (params.message.metadata?.fromAgentId || params.message.metadata?.fromExternalAgentId) {
|
|
791
805
|
const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
|
|
792
806
|
try {
|
|
@@ -811,7 +825,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
811
825
|
messageData.toAgentId = agent.agentId;
|
|
812
826
|
}
|
|
813
827
|
await agentsCore.createMessage(dbClient_default)(messageData);
|
|
814
|
-
|
|
828
|
+
logger3.info(
|
|
815
829
|
{
|
|
816
830
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
817
831
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
@@ -823,7 +837,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
823
837
|
"A2A message stored in database"
|
|
824
838
|
);
|
|
825
839
|
} catch (error) {
|
|
826
|
-
|
|
840
|
+
logger3.error(
|
|
827
841
|
{
|
|
828
842
|
error,
|
|
829
843
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
@@ -860,7 +874,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
860
874
|
(part) => part.kind === "data" && part.data && typeof part.data === "object" && part.data.type === "transfer"
|
|
861
875
|
);
|
|
862
876
|
if (transferPart && transferPart.kind === "data" && transferPart.data) {
|
|
863
|
-
|
|
877
|
+
logger3.info({ transferPart }, "transferPart");
|
|
864
878
|
return c.json({
|
|
865
879
|
jsonrpc: "2.0",
|
|
866
880
|
result: {
|
|
@@ -1411,7 +1425,7 @@ init_logger();
|
|
|
1411
1425
|
|
|
1412
1426
|
// src/agents/ModelFactory.ts
|
|
1413
1427
|
init_logger();
|
|
1414
|
-
var
|
|
1428
|
+
var logger5 = agentsCore.getLogger("ModelFactory");
|
|
1415
1429
|
var _ModelFactory = class _ModelFactory {
|
|
1416
1430
|
/**
|
|
1417
1431
|
* Create a provider instance with custom configuration
|
|
@@ -1473,7 +1487,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1473
1487
|
}
|
|
1474
1488
|
const modelString = modelSettings.model.trim();
|
|
1475
1489
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1476
|
-
|
|
1490
|
+
logger5.debug(
|
|
1477
1491
|
{
|
|
1478
1492
|
provider,
|
|
1479
1493
|
model: modelName,
|
|
@@ -1484,7 +1498,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1484
1498
|
);
|
|
1485
1499
|
const providerConfig = _ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
1486
1500
|
if (Object.keys(providerConfig).length > 0) {
|
|
1487
|
-
|
|
1501
|
+
logger5.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
1488
1502
|
const customProvider = _ModelFactory.createProvider(provider, providerConfig);
|
|
1489
1503
|
return customProvider.languageModel(modelName);
|
|
1490
1504
|
}
|
|
@@ -1603,7 +1617,7 @@ var ModelFactory = _ModelFactory;
|
|
|
1603
1617
|
|
|
1604
1618
|
// src/agents/ToolSessionManager.ts
|
|
1605
1619
|
init_logger();
|
|
1606
|
-
var
|
|
1620
|
+
var logger6 = agentsCore.getLogger("ToolSessionManager");
|
|
1607
1621
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
1608
1622
|
// 5 minutes
|
|
1609
1623
|
constructor() {
|
|
@@ -1638,7 +1652,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1638
1652
|
createdAt: Date.now()
|
|
1639
1653
|
};
|
|
1640
1654
|
this.sessions.set(sessionId, session);
|
|
1641
|
-
|
|
1655
|
+
logger6.debug(
|
|
1642
1656
|
{
|
|
1643
1657
|
sessionId,
|
|
1644
1658
|
tenantId,
|
|
@@ -1656,10 +1670,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1656
1670
|
*/
|
|
1657
1671
|
ensureGraphSession(sessionId, tenantId, projectId, contextId, taskId) {
|
|
1658
1672
|
if (this.sessions.has(sessionId)) {
|
|
1659
|
-
|
|
1673
|
+
logger6.debug({ sessionId }, "Graph session already exists, reusing");
|
|
1660
1674
|
return sessionId;
|
|
1661
1675
|
}
|
|
1662
|
-
|
|
1676
|
+
logger6.debug(
|
|
1663
1677
|
{ sessionId, tenantId, contextId, taskId },
|
|
1664
1678
|
"Creating new graph-scoped tool session"
|
|
1665
1679
|
);
|
|
@@ -1671,7 +1685,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1671
1685
|
recordToolResult(sessionId, toolResult) {
|
|
1672
1686
|
const session = this.sessions.get(sessionId);
|
|
1673
1687
|
if (!session) {
|
|
1674
|
-
|
|
1688
|
+
logger6.warn(
|
|
1675
1689
|
{
|
|
1676
1690
|
sessionId,
|
|
1677
1691
|
toolCallId: toolResult.toolCallId,
|
|
@@ -1683,7 +1697,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1683
1697
|
return;
|
|
1684
1698
|
}
|
|
1685
1699
|
session.toolResults.set(toolResult.toolCallId, toolResult);
|
|
1686
|
-
|
|
1700
|
+
logger6.debug(
|
|
1687
1701
|
{
|
|
1688
1702
|
sessionId,
|
|
1689
1703
|
toolCallId: toolResult.toolCallId,
|
|
@@ -1698,7 +1712,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1698
1712
|
getToolResult(sessionId, toolCallId) {
|
|
1699
1713
|
const session = this.sessions.get(sessionId);
|
|
1700
1714
|
if (!session) {
|
|
1701
|
-
|
|
1715
|
+
logger6.warn(
|
|
1702
1716
|
{
|
|
1703
1717
|
sessionId,
|
|
1704
1718
|
toolCallId,
|
|
@@ -1711,7 +1725,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1711
1725
|
}
|
|
1712
1726
|
const result = session.toolResults.get(toolCallId);
|
|
1713
1727
|
if (!result) {
|
|
1714
|
-
|
|
1728
|
+
logger6.warn(
|
|
1715
1729
|
{
|
|
1716
1730
|
sessionId,
|
|
1717
1731
|
toolCallId,
|
|
@@ -1721,7 +1735,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1721
1735
|
"Tool result not found"
|
|
1722
1736
|
);
|
|
1723
1737
|
} else {
|
|
1724
|
-
|
|
1738
|
+
logger6.debug(
|
|
1725
1739
|
{
|
|
1726
1740
|
sessionId,
|
|
1727
1741
|
toolCallId,
|
|
@@ -1760,10 +1774,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
1760
1774
|
}
|
|
1761
1775
|
for (const sessionId of expiredSessions) {
|
|
1762
1776
|
this.sessions.delete(sessionId);
|
|
1763
|
-
|
|
1777
|
+
logger6.debug({ sessionId }, "Cleaned up expired tool session");
|
|
1764
1778
|
}
|
|
1765
1779
|
if (expiredSessions.length > 0) {
|
|
1766
|
-
|
|
1780
|
+
logger6.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
1767
1781
|
}
|
|
1768
1782
|
}
|
|
1769
1783
|
};
|
|
@@ -1807,7 +1821,7 @@ var tracer = agentsCore.getTracer("agents-run-api");
|
|
|
1807
1821
|
init_logger();
|
|
1808
1822
|
init_dbClient();
|
|
1809
1823
|
init_logger();
|
|
1810
|
-
var
|
|
1824
|
+
var logger7 = agentsCore.getLogger("ArtifactService");
|
|
1811
1825
|
var _ArtifactService = class _ArtifactService {
|
|
1812
1826
|
constructor(context) {
|
|
1813
1827
|
this.context = context;
|
|
@@ -1833,7 +1847,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1833
1847
|
id: taskId
|
|
1834
1848
|
});
|
|
1835
1849
|
if (!task) {
|
|
1836
|
-
|
|
1850
|
+
logger7.warn({ taskId }, "Task not found when fetching artifacts");
|
|
1837
1851
|
continue;
|
|
1838
1852
|
}
|
|
1839
1853
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -1851,7 +1865,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1851
1865
|
}
|
|
1852
1866
|
}
|
|
1853
1867
|
} catch (error) {
|
|
1854
|
-
|
|
1868
|
+
logger7.error({ error, contextId }, "Error loading context artifacts");
|
|
1855
1869
|
}
|
|
1856
1870
|
return artifacts;
|
|
1857
1871
|
}
|
|
@@ -1860,12 +1874,12 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1860
1874
|
*/
|
|
1861
1875
|
async createArtifact(request, agentId) {
|
|
1862
1876
|
if (!this.context.sessionId) {
|
|
1863
|
-
|
|
1877
|
+
logger7.warn({ request }, "No session ID available for artifact creation");
|
|
1864
1878
|
return null;
|
|
1865
1879
|
}
|
|
1866
1880
|
const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
|
|
1867
1881
|
if (!toolResult) {
|
|
1868
|
-
|
|
1882
|
+
logger7.warn(
|
|
1869
1883
|
{ request, sessionId: this.context.sessionId },
|
|
1870
1884
|
"Tool result not found for artifact"
|
|
1871
1885
|
);
|
|
@@ -1881,7 +1895,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1881
1895
|
selectedData = selectedData.length > 0 ? selectedData[0] : {};
|
|
1882
1896
|
}
|
|
1883
1897
|
if (!selectedData) {
|
|
1884
|
-
|
|
1898
|
+
logger7.warn(
|
|
1885
1899
|
{
|
|
1886
1900
|
request,
|
|
1887
1901
|
baseSelector: request.baseSelector
|
|
@@ -1918,7 +1932,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1918
1932
|
);
|
|
1919
1933
|
return artifactData;
|
|
1920
1934
|
} catch (error) {
|
|
1921
|
-
|
|
1935
|
+
logger7.error({ error, request }, "Failed to create artifact");
|
|
1922
1936
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1923
1937
|
throw new Error(`Artifact creation failed for ${request.artifactId}: ${errorMessage}`);
|
|
1924
1938
|
}
|
|
@@ -1947,7 +1961,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1947
1961
|
}
|
|
1948
1962
|
try {
|
|
1949
1963
|
if (!this.context.projectId || !this.context.taskId) {
|
|
1950
|
-
|
|
1964
|
+
logger7.warn(
|
|
1951
1965
|
{ artifactId, toolCallId },
|
|
1952
1966
|
"No projectId or taskId available for artifact lookup"
|
|
1953
1967
|
);
|
|
@@ -1962,7 +1976,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1962
1976
|
return this.formatArtifactData(artifacts[0], artifactId, toolCallId);
|
|
1963
1977
|
}
|
|
1964
1978
|
} catch (error) {
|
|
1965
|
-
|
|
1979
|
+
logger7.warn(
|
|
1966
1980
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
1967
1981
|
"Failed to fetch artifact"
|
|
1968
1982
|
);
|
|
@@ -2015,7 +2029,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2015
2029
|
}
|
|
2016
2030
|
);
|
|
2017
2031
|
} else {
|
|
2018
|
-
|
|
2032
|
+
logger7.warn({
|
|
2019
2033
|
artifactId: request.artifactId,
|
|
2020
2034
|
hasStreamRequestId: !!this.context.streamRequestId,
|
|
2021
2035
|
hasAgentId: !!effectiveAgentId,
|
|
@@ -2100,7 +2114,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2100
2114
|
artifact: artifactToSave
|
|
2101
2115
|
});
|
|
2102
2116
|
if (!result.created && result.existing) {
|
|
2103
|
-
|
|
2117
|
+
logger7.debug(
|
|
2104
2118
|
{
|
|
2105
2119
|
artifactId: artifact.artifactId,
|
|
2106
2120
|
taskId: this.context.taskId
|
|
@@ -2153,7 +2167,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2153
2167
|
extracted[propName] = this.cleanEscapedContent(rawValue);
|
|
2154
2168
|
}
|
|
2155
2169
|
} catch (error) {
|
|
2156
|
-
|
|
2170
|
+
logger7.warn(
|
|
2157
2171
|
{ propName, selector, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2158
2172
|
"Failed to extract property"
|
|
2159
2173
|
);
|
|
@@ -2183,7 +2197,7 @@ __publicField(_ArtifactService, "selectorCache", /* @__PURE__ */ new Map());
|
|
|
2183
2197
|
var ArtifactService = _ArtifactService;
|
|
2184
2198
|
|
|
2185
2199
|
// src/services/ArtifactParser.ts
|
|
2186
|
-
var
|
|
2200
|
+
var logger8 = agentsCore.getLogger("ArtifactParser");
|
|
2187
2201
|
var _ArtifactParser = class _ArtifactParser {
|
|
2188
2202
|
constructor(tenantId, options) {
|
|
2189
2203
|
__publicField(this, "artifactService");
|
|
@@ -2267,7 +2281,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2267
2281
|
attrs[key] = value;
|
|
2268
2282
|
}
|
|
2269
2283
|
if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
|
|
2270
|
-
|
|
2284
|
+
logger8.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
|
|
2271
2285
|
return null;
|
|
2272
2286
|
}
|
|
2273
2287
|
return {
|
|
@@ -2328,7 +2342,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2328
2342
|
} else if (annotation.raw) {
|
|
2329
2343
|
failedAnnotations.push(`Failed to create artifact "${annotation.artifactId}": Missing or invalid data`);
|
|
2330
2344
|
processedText = processedText.replace(annotation.raw, "");
|
|
2331
|
-
|
|
2345
|
+
logger8.warn({ annotation, artifactData }, "Removed failed artifact:create annotation from output");
|
|
2332
2346
|
}
|
|
2333
2347
|
} catch (error) {
|
|
2334
2348
|
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
@@ -2336,11 +2350,11 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2336
2350
|
if (annotation.raw) {
|
|
2337
2351
|
processedText = processedText.replace(annotation.raw, "");
|
|
2338
2352
|
}
|
|
2339
|
-
|
|
2353
|
+
logger8.error({ annotation, error }, "Failed to extract artifact from create annotation");
|
|
2340
2354
|
}
|
|
2341
2355
|
}
|
|
2342
2356
|
if (failedAnnotations.length > 0) {
|
|
2343
|
-
|
|
2357
|
+
logger8.warn({
|
|
2344
2358
|
failedCount: failedAnnotations.length,
|
|
2345
2359
|
failures: failedAnnotations
|
|
2346
2360
|
}, "Some artifact creation attempts failed");
|
|
@@ -2497,7 +2511,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^
|
|
|
2497
2511
|
var ArtifactParser = _ArtifactParser;
|
|
2498
2512
|
|
|
2499
2513
|
// src/services/GraphSession.ts
|
|
2500
|
-
var
|
|
2514
|
+
var logger9 = agentsCore.getLogger("GraphSession");
|
|
2501
2515
|
var GraphSession = class {
|
|
2502
2516
|
// Session-scoped ArtifactParser instance
|
|
2503
2517
|
constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
|
|
@@ -2528,7 +2542,7 @@ var GraphSession = class {
|
|
|
2528
2542
|
__publicField(this, "artifactService");
|
|
2529
2543
|
// Session-scoped ArtifactService instance
|
|
2530
2544
|
__publicField(this, "artifactParser");
|
|
2531
|
-
|
|
2545
|
+
logger9.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
2532
2546
|
if (tenantId && projectId) {
|
|
2533
2547
|
toolSessionManager.createSessionWithId(
|
|
2534
2548
|
sessionId,
|
|
@@ -2576,7 +2590,7 @@ var GraphSession = class {
|
|
|
2576
2590
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
2577
2591
|
this.statusUpdateTimer = setInterval(async () => {
|
|
2578
2592
|
if (!this.statusUpdateState || this.isEnded) {
|
|
2579
|
-
|
|
2593
|
+
logger9.debug(
|
|
2580
2594
|
{ sessionId: this.sessionId },
|
|
2581
2595
|
"Timer triggered but session already cleaned up or ended"
|
|
2582
2596
|
);
|
|
@@ -2588,7 +2602,7 @@ var GraphSession = class {
|
|
|
2588
2602
|
}
|
|
2589
2603
|
await this.checkAndSendTimeBasedUpdate();
|
|
2590
2604
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
2591
|
-
|
|
2605
|
+
logger9.info(
|
|
2592
2606
|
{
|
|
2593
2607
|
sessionId: this.sessionId,
|
|
2594
2608
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -2602,7 +2616,7 @@ var GraphSession = class {
|
|
|
2602
2616
|
*/
|
|
2603
2617
|
recordEvent(eventType, agentId, data) {
|
|
2604
2618
|
if (this.isEnded) {
|
|
2605
|
-
|
|
2619
|
+
logger9.debug(
|
|
2606
2620
|
{
|
|
2607
2621
|
sessionId: this.sessionId,
|
|
2608
2622
|
eventType,
|
|
@@ -2622,7 +2636,7 @@ var GraphSession = class {
|
|
|
2622
2636
|
if (eventType === "artifact_saved" && data.pendingGeneration) {
|
|
2623
2637
|
const artifactId = data.artifactId;
|
|
2624
2638
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
2625
|
-
|
|
2639
|
+
logger9.warn(
|
|
2626
2640
|
{
|
|
2627
2641
|
sessionId: this.sessionId,
|
|
2628
2642
|
artifactId,
|
|
@@ -2644,7 +2658,7 @@ var GraphSession = class {
|
|
|
2644
2658
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
2645
2659
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
2646
2660
|
this.pendingArtifacts.delete(artifactId);
|
|
2647
|
-
|
|
2661
|
+
logger9.error(
|
|
2648
2662
|
{
|
|
2649
2663
|
sessionId: this.sessionId,
|
|
2650
2664
|
artifactId,
|
|
@@ -2656,7 +2670,7 @@ var GraphSession = class {
|
|
|
2656
2670
|
"Artifact processing failed after max retries, giving up"
|
|
2657
2671
|
);
|
|
2658
2672
|
} else {
|
|
2659
|
-
|
|
2673
|
+
logger9.warn(
|
|
2660
2674
|
{
|
|
2661
2675
|
sessionId: this.sessionId,
|
|
2662
2676
|
artifactId,
|
|
@@ -2678,14 +2692,14 @@ var GraphSession = class {
|
|
|
2678
2692
|
*/
|
|
2679
2693
|
checkStatusUpdates() {
|
|
2680
2694
|
if (this.isEnded) {
|
|
2681
|
-
|
|
2695
|
+
logger9.debug(
|
|
2682
2696
|
{ sessionId: this.sessionId },
|
|
2683
2697
|
"Session has ended - skipping status update check"
|
|
2684
2698
|
);
|
|
2685
2699
|
return;
|
|
2686
2700
|
}
|
|
2687
2701
|
if (!this.statusUpdateState) {
|
|
2688
|
-
|
|
2702
|
+
logger9.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
2689
2703
|
return;
|
|
2690
2704
|
}
|
|
2691
2705
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -2696,11 +2710,11 @@ var GraphSession = class {
|
|
|
2696
2710
|
*/
|
|
2697
2711
|
async checkAndSendTimeBasedUpdate() {
|
|
2698
2712
|
if (this.isEnded) {
|
|
2699
|
-
|
|
2713
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
2700
2714
|
return;
|
|
2701
2715
|
}
|
|
2702
2716
|
if (!this.statusUpdateState) {
|
|
2703
|
-
|
|
2717
|
+
logger9.debug(
|
|
2704
2718
|
{ sessionId: this.sessionId },
|
|
2705
2719
|
"No status updates configured for time-based check"
|
|
2706
2720
|
);
|
|
@@ -2713,7 +2727,7 @@ var GraphSession = class {
|
|
|
2713
2727
|
try {
|
|
2714
2728
|
await this.generateAndSendUpdate();
|
|
2715
2729
|
} catch (error) {
|
|
2716
|
-
|
|
2730
|
+
logger9.error(
|
|
2717
2731
|
{
|
|
2718
2732
|
sessionId: this.sessionId,
|
|
2719
2733
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2816,29 +2830,29 @@ var GraphSession = class {
|
|
|
2816
2830
|
*/
|
|
2817
2831
|
async generateAndSendUpdate() {
|
|
2818
2832
|
if (this.isEnded) {
|
|
2819
|
-
|
|
2833
|
+
logger9.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
2820
2834
|
return;
|
|
2821
2835
|
}
|
|
2822
2836
|
if (this.isTextStreaming) {
|
|
2823
|
-
|
|
2837
|
+
logger9.debug(
|
|
2824
2838
|
{ sessionId: this.sessionId },
|
|
2825
2839
|
"Text is currently streaming - skipping status update"
|
|
2826
2840
|
);
|
|
2827
2841
|
return;
|
|
2828
2842
|
}
|
|
2829
2843
|
if (this.isGeneratingUpdate) {
|
|
2830
|
-
|
|
2844
|
+
logger9.debug(
|
|
2831
2845
|
{ sessionId: this.sessionId },
|
|
2832
2846
|
"Update already in progress - skipping duplicate generation"
|
|
2833
2847
|
);
|
|
2834
2848
|
return;
|
|
2835
2849
|
}
|
|
2836
2850
|
if (!this.statusUpdateState) {
|
|
2837
|
-
|
|
2851
|
+
logger9.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
2838
2852
|
return;
|
|
2839
2853
|
}
|
|
2840
2854
|
if (!this.graphId) {
|
|
2841
|
-
|
|
2855
|
+
logger9.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
2842
2856
|
return;
|
|
2843
2857
|
}
|
|
2844
2858
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -2850,7 +2864,7 @@ var GraphSession = class {
|
|
|
2850
2864
|
try {
|
|
2851
2865
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
2852
2866
|
if (!streamHelper) {
|
|
2853
|
-
|
|
2867
|
+
logger9.warn(
|
|
2854
2868
|
{ sessionId: this.sessionId },
|
|
2855
2869
|
"No stream helper found - cannot send status update"
|
|
2856
2870
|
);
|
|
@@ -2870,7 +2884,7 @@ var GraphSession = class {
|
|
|
2870
2884
|
if (result.summaries && result.summaries.length > 0) {
|
|
2871
2885
|
for (const summary of result.summaries) {
|
|
2872
2886
|
if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
|
|
2873
|
-
|
|
2887
|
+
logger9.warn(
|
|
2874
2888
|
{
|
|
2875
2889
|
sessionId: this.sessionId,
|
|
2876
2890
|
summary
|
|
@@ -2907,7 +2921,7 @@ var GraphSession = class {
|
|
|
2907
2921
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
2908
2922
|
}
|
|
2909
2923
|
} catch (error) {
|
|
2910
|
-
|
|
2924
|
+
logger9.error(
|
|
2911
2925
|
{
|
|
2912
2926
|
sessionId: this.sessionId,
|
|
2913
2927
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -2945,7 +2959,7 @@ var GraphSession = class {
|
|
|
2945
2959
|
this.releaseUpdateLock();
|
|
2946
2960
|
}
|
|
2947
2961
|
} catch (error) {
|
|
2948
|
-
|
|
2962
|
+
logger9.error(
|
|
2949
2963
|
{
|
|
2950
2964
|
sessionId: this.sessionId,
|
|
2951
2965
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3023,7 +3037,7 @@ User's Question/Context:
|
|
|
3023
3037
|
${conversationHistory}
|
|
3024
3038
|
` : "";
|
|
3025
3039
|
} catch (error) {
|
|
3026
|
-
|
|
3040
|
+
logger9.warn(
|
|
3027
3041
|
{ sessionId: this.sessionId, error },
|
|
3028
3042
|
"Failed to fetch conversation history for structured status update"
|
|
3029
3043
|
);
|
|
@@ -3157,10 +3171,11 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3157
3171
|
return { summaries };
|
|
3158
3172
|
} catch (error) {
|
|
3159
3173
|
agentsCore.setSpanWithError(span, error);
|
|
3160
|
-
|
|
3174
|
+
logger9.error({ error }, "Failed to generate structured update, using fallback");
|
|
3161
3175
|
return { summaries: [] };
|
|
3162
3176
|
} finally {
|
|
3163
3177
|
span.end();
|
|
3178
|
+
await defaultBatchProcessor.forceFlush();
|
|
3164
3179
|
}
|
|
3165
3180
|
}
|
|
3166
3181
|
);
|
|
@@ -3371,7 +3386,7 @@ Make it specific and relevant.`;
|
|
|
3371
3386
|
});
|
|
3372
3387
|
if (agentData && "models" in agentData && agentData.models?.base?.model) {
|
|
3373
3388
|
modelToUse = agentData.models.base;
|
|
3374
|
-
|
|
3389
|
+
logger9.info(
|
|
3375
3390
|
{
|
|
3376
3391
|
sessionId: this.sessionId,
|
|
3377
3392
|
artifactId: artifactData.artifactId,
|
|
@@ -3382,7 +3397,7 @@ Make it specific and relevant.`;
|
|
|
3382
3397
|
);
|
|
3383
3398
|
}
|
|
3384
3399
|
} catch (error) {
|
|
3385
|
-
|
|
3400
|
+
logger9.warn(
|
|
3386
3401
|
{
|
|
3387
3402
|
sessionId: this.sessionId,
|
|
3388
3403
|
artifactId: artifactData.artifactId,
|
|
@@ -3394,7 +3409,7 @@ Make it specific and relevant.`;
|
|
|
3394
3409
|
}
|
|
3395
3410
|
}
|
|
3396
3411
|
if (!modelToUse?.model?.trim()) {
|
|
3397
|
-
|
|
3412
|
+
logger9.warn(
|
|
3398
3413
|
{
|
|
3399
3414
|
sessionId: this.sessionId,
|
|
3400
3415
|
artifactId: artifactData.artifactId
|
|
@@ -3468,7 +3483,7 @@ Make it specific and relevant.`;
|
|
|
3468
3483
|
return result2;
|
|
3469
3484
|
} catch (error) {
|
|
3470
3485
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
3471
|
-
|
|
3486
|
+
logger9.warn(
|
|
3472
3487
|
{
|
|
3473
3488
|
sessionId: this.sessionId,
|
|
3474
3489
|
artifactId: artifactData.artifactId,
|
|
@@ -3517,7 +3532,7 @@ Make it specific and relevant.`;
|
|
|
3517
3532
|
});
|
|
3518
3533
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
3519
3534
|
} catch (saveError) {
|
|
3520
|
-
|
|
3535
|
+
logger9.error(
|
|
3521
3536
|
{
|
|
3522
3537
|
sessionId: this.sessionId,
|
|
3523
3538
|
artifactId: artifactData.artifactId,
|
|
@@ -3545,7 +3560,7 @@ Make it specific and relevant.`;
|
|
|
3545
3560
|
fullProps: artifactData.fullProps || {},
|
|
3546
3561
|
metadata: artifactData.metadata || {}
|
|
3547
3562
|
});
|
|
3548
|
-
|
|
3563
|
+
logger9.info(
|
|
3549
3564
|
{
|
|
3550
3565
|
sessionId: this.sessionId,
|
|
3551
3566
|
artifactId: artifactData.artifactId
|
|
@@ -3556,7 +3571,7 @@ Make it specific and relevant.`;
|
|
|
3556
3571
|
} catch (fallbackError) {
|
|
3557
3572
|
const isDuplicateError = fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"));
|
|
3558
3573
|
if (isDuplicateError) ; else {
|
|
3559
|
-
|
|
3574
|
+
logger9.error(
|
|
3560
3575
|
{
|
|
3561
3576
|
sessionId: this.sessionId,
|
|
3562
3577
|
artifactId: artifactData.artifactId,
|
|
@@ -3569,7 +3584,7 @@ Make it specific and relevant.`;
|
|
|
3569
3584
|
}
|
|
3570
3585
|
} catch (error) {
|
|
3571
3586
|
agentsCore.setSpanWithError(span, error);
|
|
3572
|
-
|
|
3587
|
+
logger9.error(
|
|
3573
3588
|
{
|
|
3574
3589
|
sessionId: this.sessionId,
|
|
3575
3590
|
artifactId: artifactData.artifactId,
|
|
@@ -3579,6 +3594,7 @@ Make it specific and relevant.`;
|
|
|
3579
3594
|
);
|
|
3580
3595
|
} finally {
|
|
3581
3596
|
span.end();
|
|
3597
|
+
await defaultBatchProcessor.forceFlush();
|
|
3582
3598
|
}
|
|
3583
3599
|
}
|
|
3584
3600
|
);
|
|
@@ -3588,7 +3604,7 @@ Make it specific and relevant.`;
|
|
|
3588
3604
|
*/
|
|
3589
3605
|
setArtifactCache(key, artifact) {
|
|
3590
3606
|
this.artifactCache.set(key, artifact);
|
|
3591
|
-
|
|
3607
|
+
logger9.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
|
|
3592
3608
|
}
|
|
3593
3609
|
/**
|
|
3594
3610
|
* Get session-scoped ArtifactService instance
|
|
@@ -3607,7 +3623,7 @@ Make it specific and relevant.`;
|
|
|
3607
3623
|
*/
|
|
3608
3624
|
getArtifactCache(key) {
|
|
3609
3625
|
const artifact = this.artifactCache.get(key);
|
|
3610
|
-
|
|
3626
|
+
logger9.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
|
|
3611
3627
|
return artifact || null;
|
|
3612
3628
|
}
|
|
3613
3629
|
};
|
|
@@ -3622,7 +3638,7 @@ var GraphSessionManager = class {
|
|
|
3622
3638
|
const sessionId = messageId;
|
|
3623
3639
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
|
|
3624
3640
|
this.sessions.set(sessionId, session);
|
|
3625
|
-
|
|
3641
|
+
logger9.info(
|
|
3626
3642
|
{ sessionId, messageId, graphId, tenantId, projectId, contextId },
|
|
3627
3643
|
"GraphSession created"
|
|
3628
3644
|
);
|
|
@@ -3636,7 +3652,7 @@ var GraphSessionManager = class {
|
|
|
3636
3652
|
if (session) {
|
|
3637
3653
|
session.initializeStatusUpdates(config, summarizerModel);
|
|
3638
3654
|
} else {
|
|
3639
|
-
|
|
3655
|
+
logger9.error(
|
|
3640
3656
|
{
|
|
3641
3657
|
sessionId,
|
|
3642
3658
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -3657,7 +3673,7 @@ var GraphSessionManager = class {
|
|
|
3657
3673
|
recordEvent(sessionId, eventType, agentId, data) {
|
|
3658
3674
|
const session = this.sessions.get(sessionId);
|
|
3659
3675
|
if (!session) {
|
|
3660
|
-
|
|
3676
|
+
logger9.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
3661
3677
|
return;
|
|
3662
3678
|
}
|
|
3663
3679
|
session.recordEvent(eventType, agentId, data);
|
|
@@ -3668,12 +3684,12 @@ var GraphSessionManager = class {
|
|
|
3668
3684
|
endSession(sessionId) {
|
|
3669
3685
|
const session = this.sessions.get(sessionId);
|
|
3670
3686
|
if (!session) {
|
|
3671
|
-
|
|
3687
|
+
logger9.warn({ sessionId }, "Attempted to end non-existent session");
|
|
3672
3688
|
return [];
|
|
3673
3689
|
}
|
|
3674
3690
|
const events = session.getEvents();
|
|
3675
3691
|
const summary = session.getSummary();
|
|
3676
|
-
|
|
3692
|
+
logger9.info({ sessionId, summary }, "GraphSession ended");
|
|
3677
3693
|
session.cleanup();
|
|
3678
3694
|
this.sessions.delete(sessionId);
|
|
3679
3695
|
return events;
|
|
@@ -3732,7 +3748,7 @@ var graphSessionManager = new GraphSessionManager();
|
|
|
3732
3748
|
|
|
3733
3749
|
// src/services/IncrementalStreamParser.ts
|
|
3734
3750
|
init_logger();
|
|
3735
|
-
var
|
|
3751
|
+
var logger10 = agentsCore.getLogger("IncrementalStreamParser");
|
|
3736
3752
|
var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
3737
3753
|
// Max number of collected parts to prevent unbounded growth
|
|
3738
3754
|
constructor(streamHelper, tenantId, contextId, artifactParserOptions) {
|
|
@@ -3773,7 +3789,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3773
3789
|
async initializeArtifactMap() {
|
|
3774
3790
|
try {
|
|
3775
3791
|
this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
|
|
3776
|
-
|
|
3792
|
+
logger10.debug(
|
|
3777
3793
|
{
|
|
3778
3794
|
contextId: this.contextId,
|
|
3779
3795
|
artifactMapSize: this.artifactMap.size
|
|
@@ -3781,7 +3797,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3781
3797
|
"Initialized artifact map for streaming"
|
|
3782
3798
|
);
|
|
3783
3799
|
} catch (error) {
|
|
3784
|
-
|
|
3800
|
+
logger10.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
|
|
3785
3801
|
this.artifactMap = /* @__PURE__ */ new Map();
|
|
3786
3802
|
}
|
|
3787
3803
|
}
|
|
@@ -4090,7 +4106,7 @@ var IncrementalStreamParser = _IncrementalStreamParser;
|
|
|
4090
4106
|
|
|
4091
4107
|
// src/services/ResponseFormatter.ts
|
|
4092
4108
|
init_logger();
|
|
4093
|
-
var
|
|
4109
|
+
var logger11 = agentsCore.getLogger("ResponseFormatter");
|
|
4094
4110
|
var ResponseFormatter = class {
|
|
4095
4111
|
constructor(tenantId, artifactParserOptions) {
|
|
4096
4112
|
__publicField(this, "artifactParser");
|
|
@@ -4130,12 +4146,13 @@ var ResponseFormatter = class {
|
|
|
4130
4146
|
return { parts };
|
|
4131
4147
|
} catch (error) {
|
|
4132
4148
|
agentsCore.setSpanWithError(span, error);
|
|
4133
|
-
|
|
4149
|
+
logger11.error({ error, responseObject }, "Error formatting object response");
|
|
4134
4150
|
return {
|
|
4135
4151
|
parts: [{ kind: "data", data: responseObject }]
|
|
4136
4152
|
};
|
|
4137
4153
|
} finally {
|
|
4138
4154
|
span.end();
|
|
4155
|
+
await defaultBatchProcessor.forceFlush();
|
|
4139
4156
|
}
|
|
4140
4157
|
});
|
|
4141
4158
|
}
|
|
@@ -4182,10 +4199,11 @@ var ResponseFormatter = class {
|
|
|
4182
4199
|
return { parts };
|
|
4183
4200
|
} catch (error) {
|
|
4184
4201
|
agentsCore.setSpanWithError(span, error);
|
|
4185
|
-
|
|
4202
|
+
logger11.error({ error, responseText }, "Error formatting response");
|
|
4186
4203
|
return { text: responseText };
|
|
4187
4204
|
} finally {
|
|
4188
4205
|
span.end();
|
|
4206
|
+
await defaultBatchProcessor.forceFlush();
|
|
4189
4207
|
}
|
|
4190
4208
|
});
|
|
4191
4209
|
}
|
|
@@ -4264,10 +4282,10 @@ init_logger();
|
|
|
4264
4282
|
|
|
4265
4283
|
// src/utils/data-component-schema.ts
|
|
4266
4284
|
init_logger();
|
|
4267
|
-
var
|
|
4285
|
+
var logger12 = agentsCore.getLogger("DataComponentSchema");
|
|
4268
4286
|
function jsonSchemaToZod(jsonSchema) {
|
|
4269
4287
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
4270
|
-
|
|
4288
|
+
logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
4271
4289
|
return z5.z.string();
|
|
4272
4290
|
}
|
|
4273
4291
|
switch (jsonSchema.type) {
|
|
@@ -4294,7 +4312,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
4294
4312
|
case "null":
|
|
4295
4313
|
return z5.z.null();
|
|
4296
4314
|
default:
|
|
4297
|
-
|
|
4315
|
+
logger12.warn(
|
|
4298
4316
|
{
|
|
4299
4317
|
unsupportedType: jsonSchema.type,
|
|
4300
4318
|
schema: jsonSchema
|
|
@@ -4665,7 +4683,7 @@ function parseEmbeddedJson(data) {
|
|
|
4665
4683
|
|
|
4666
4684
|
// src/a2a/client.ts
|
|
4667
4685
|
init_logger();
|
|
4668
|
-
var
|
|
4686
|
+
var logger13 = agentsCore.getLogger("a2aClient");
|
|
4669
4687
|
var DEFAULT_BACKOFF = {
|
|
4670
4688
|
initialInterval: 500,
|
|
4671
4689
|
maxInterval: 6e4,
|
|
@@ -4871,7 +4889,7 @@ var A2AClient = class {
|
|
|
4871
4889
|
try {
|
|
4872
4890
|
const res = await fn();
|
|
4873
4891
|
if (attempt > 0) {
|
|
4874
|
-
|
|
4892
|
+
logger13.info(
|
|
4875
4893
|
{
|
|
4876
4894
|
attempts: attempt + 1,
|
|
4877
4895
|
elapsedTime: Date.now() - start
|
|
@@ -4886,7 +4904,7 @@ var A2AClient = class {
|
|
|
4886
4904
|
}
|
|
4887
4905
|
const elapsed = Date.now() - start;
|
|
4888
4906
|
if (elapsed > maxElapsedTime) {
|
|
4889
|
-
|
|
4907
|
+
logger13.warn(
|
|
4890
4908
|
{
|
|
4891
4909
|
attempts: attempt + 1,
|
|
4892
4910
|
elapsedTime: elapsed,
|
|
@@ -4907,7 +4925,7 @@ var A2AClient = class {
|
|
|
4907
4925
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
4908
4926
|
}
|
|
4909
4927
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
4910
|
-
|
|
4928
|
+
logger13.info(
|
|
4911
4929
|
{
|
|
4912
4930
|
attempt: attempt + 1,
|
|
4913
4931
|
delayMs,
|
|
@@ -4992,7 +5010,7 @@ var A2AClient = class {
|
|
|
4992
5010
|
}
|
|
4993
5011
|
const rpcResponse = await httpResponse.json();
|
|
4994
5012
|
if (rpcResponse.id !== requestId2) {
|
|
4995
|
-
|
|
5013
|
+
logger13.warn(
|
|
4996
5014
|
{
|
|
4997
5015
|
method,
|
|
4998
5016
|
expectedId: requestId2,
|
|
@@ -5191,7 +5209,7 @@ var A2AClient = class {
|
|
|
5191
5209
|
try {
|
|
5192
5210
|
while (true) {
|
|
5193
5211
|
const { done, value } = await reader.read();
|
|
5194
|
-
|
|
5212
|
+
logger13.info({ done, value }, "parseA2ASseStream");
|
|
5195
5213
|
if (done) {
|
|
5196
5214
|
if (eventDataBuffer.trim()) {
|
|
5197
5215
|
const result = this._processSseEventData(
|
|
@@ -5281,7 +5299,7 @@ var A2AClient = class {
|
|
|
5281
5299
|
init_conversations();
|
|
5282
5300
|
init_dbClient();
|
|
5283
5301
|
init_logger();
|
|
5284
|
-
var
|
|
5302
|
+
var logger14 = agentsCore.getLogger("relationships Tools");
|
|
5285
5303
|
var generateTransferToolDescription = (config) => {
|
|
5286
5304
|
return `Hand off the conversation to agent ${config.id}.
|
|
5287
5305
|
|
|
@@ -5319,7 +5337,7 @@ var createTransferToAgentTool = ({
|
|
|
5319
5337
|
"transfer.to_agent_id": transferConfig.id ?? "unknown"
|
|
5320
5338
|
});
|
|
5321
5339
|
}
|
|
5322
|
-
|
|
5340
|
+
logger14.info(
|
|
5323
5341
|
{
|
|
5324
5342
|
transferTo: transferConfig.id ?? "unknown",
|
|
5325
5343
|
fromAgent: callingAgentId
|
|
@@ -5468,7 +5486,7 @@ function createDelegateToAgentTool({
|
|
|
5468
5486
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
5469
5487
|
}
|
|
5470
5488
|
};
|
|
5471
|
-
|
|
5489
|
+
logger14.info({ messageToSend }, "messageToSend");
|
|
5472
5490
|
await agentsCore.createMessage(dbClient_default)({
|
|
5473
5491
|
id: nanoid.nanoid(),
|
|
5474
5492
|
tenantId,
|
|
@@ -5531,7 +5549,7 @@ function createDelegateToAgentTool({
|
|
|
5531
5549
|
|
|
5532
5550
|
// src/agents/SystemPromptBuilder.ts
|
|
5533
5551
|
init_logger();
|
|
5534
|
-
var
|
|
5552
|
+
var logger15 = agentsCore.getLogger("SystemPromptBuilder");
|
|
5535
5553
|
var SystemPromptBuilder = class {
|
|
5536
5554
|
constructor(version, versionConfig) {
|
|
5537
5555
|
this.version = version;
|
|
@@ -5547,12 +5565,12 @@ var SystemPromptBuilder = class {
|
|
|
5547
5565
|
this.templates.set(name, content);
|
|
5548
5566
|
}
|
|
5549
5567
|
this.loaded = true;
|
|
5550
|
-
|
|
5568
|
+
logger15.debug(
|
|
5551
5569
|
{ templateCount: this.templates.size, version: this.version },
|
|
5552
5570
|
`Loaded ${this.templates.size} templates for version ${this.version}`
|
|
5553
5571
|
);
|
|
5554
5572
|
} catch (error) {
|
|
5555
|
-
|
|
5573
|
+
logger15.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
5556
5574
|
throw new Error(`Template loading failed: ${error}`);
|
|
5557
5575
|
}
|
|
5558
5576
|
}
|
|
@@ -6598,7 +6616,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
6598
6616
|
return false;
|
|
6599
6617
|
};
|
|
6600
6618
|
}
|
|
6601
|
-
var
|
|
6619
|
+
var logger17 = agentsCore.getLogger("Agent");
|
|
6602
6620
|
var CONSTANTS = {
|
|
6603
6621
|
MAX_GENERATION_STEPS: 12,
|
|
6604
6622
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -6897,14 +6915,14 @@ var Agent = class {
|
|
|
6897
6915
|
for (const toolSet of tools) {
|
|
6898
6916
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
6899
6917
|
if (!isValidTool(originalTool)) {
|
|
6900
|
-
|
|
6918
|
+
logger17.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
6901
6919
|
continue;
|
|
6902
6920
|
}
|
|
6903
6921
|
const sessionWrappedTool = ai.tool({
|
|
6904
6922
|
description: originalTool.description,
|
|
6905
6923
|
inputSchema: originalTool.inputSchema,
|
|
6906
6924
|
execute: async (args, { toolCallId }) => {
|
|
6907
|
-
|
|
6925
|
+
logger17.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
6908
6926
|
try {
|
|
6909
6927
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
6910
6928
|
const parsedResult = parseEmbeddedJson(rawResult);
|
|
@@ -6918,7 +6936,7 @@ var Agent = class {
|
|
|
6918
6936
|
});
|
|
6919
6937
|
return { result: enhancedResult, toolCallId };
|
|
6920
6938
|
} catch (error) {
|
|
6921
|
-
|
|
6939
|
+
logger17.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
6922
6940
|
throw error;
|
|
6923
6941
|
}
|
|
6924
6942
|
}
|
|
@@ -7012,7 +7030,7 @@ var Agent = class {
|
|
|
7012
7030
|
headers: agentToolRelationHeaders
|
|
7013
7031
|
};
|
|
7014
7032
|
}
|
|
7015
|
-
|
|
7033
|
+
logger17.info(
|
|
7016
7034
|
{
|
|
7017
7035
|
toolName: tool3.name,
|
|
7018
7036
|
credentialReferenceId,
|
|
@@ -7052,7 +7070,7 @@ var Agent = class {
|
|
|
7052
7070
|
async getResolvedContext(conversationId, requestContext) {
|
|
7053
7071
|
try {
|
|
7054
7072
|
if (!this.config.contextConfigId) {
|
|
7055
|
-
|
|
7073
|
+
logger17.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
7056
7074
|
return null;
|
|
7057
7075
|
}
|
|
7058
7076
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -7060,7 +7078,7 @@ var Agent = class {
|
|
|
7060
7078
|
id: this.config.contextConfigId
|
|
7061
7079
|
});
|
|
7062
7080
|
if (!contextConfig) {
|
|
7063
|
-
|
|
7081
|
+
logger17.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
7064
7082
|
return null;
|
|
7065
7083
|
}
|
|
7066
7084
|
if (!this.contextResolver) {
|
|
@@ -7072,12 +7090,13 @@ var Agent = class {
|
|
|
7072
7090
|
requestContext: requestContext || {},
|
|
7073
7091
|
tenantId: this.config.tenantId
|
|
7074
7092
|
});
|
|
7093
|
+
await defaultBatchProcessor.forceFlush();
|
|
7075
7094
|
const contextWithBuiltins = {
|
|
7076
7095
|
...result.resolvedContext,
|
|
7077
7096
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7078
7097
|
$env: process.env
|
|
7079
7098
|
};
|
|
7080
|
-
|
|
7099
|
+
logger17.debug(
|
|
7081
7100
|
{
|
|
7082
7101
|
conversationId,
|
|
7083
7102
|
contextConfigId: contextConfig.id,
|
|
@@ -7091,7 +7110,7 @@ var Agent = class {
|
|
|
7091
7110
|
);
|
|
7092
7111
|
return contextWithBuiltins;
|
|
7093
7112
|
} catch (error) {
|
|
7094
|
-
|
|
7113
|
+
logger17.error(
|
|
7095
7114
|
{
|
|
7096
7115
|
conversationId,
|
|
7097
7116
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7115,7 +7134,7 @@ var Agent = class {
|
|
|
7115
7134
|
});
|
|
7116
7135
|
return graphDefinition?.graphPrompt || void 0;
|
|
7117
7136
|
} catch (error) {
|
|
7118
|
-
|
|
7137
|
+
logger17.warn(
|
|
7119
7138
|
{
|
|
7120
7139
|
graphId: this.config.graphId,
|
|
7121
7140
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7144,7 +7163,7 @@ var Agent = class {
|
|
|
7144
7163
|
(agent) => "artifactComponents" in agent && agent.artifactComponents && agent.artifactComponents.length > 0
|
|
7145
7164
|
);
|
|
7146
7165
|
} catch (error) {
|
|
7147
|
-
|
|
7166
|
+
logger17.warn(
|
|
7148
7167
|
{
|
|
7149
7168
|
graphId: this.config.graphId,
|
|
7150
7169
|
tenantId: this.config.tenantId,
|
|
@@ -7173,7 +7192,7 @@ var Agent = class {
|
|
|
7173
7192
|
preserveUnresolved: false
|
|
7174
7193
|
});
|
|
7175
7194
|
} catch (error) {
|
|
7176
|
-
|
|
7195
|
+
logger17.error(
|
|
7177
7196
|
{
|
|
7178
7197
|
conversationId,
|
|
7179
7198
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7220,7 +7239,7 @@ var Agent = class {
|
|
|
7220
7239
|
preserveUnresolved: false
|
|
7221
7240
|
});
|
|
7222
7241
|
} catch (error) {
|
|
7223
|
-
|
|
7242
|
+
logger17.error(
|
|
7224
7243
|
{
|
|
7225
7244
|
conversationId,
|
|
7226
7245
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7259,7 +7278,7 @@ var Agent = class {
|
|
|
7259
7278
|
preserveUnresolved: false
|
|
7260
7279
|
});
|
|
7261
7280
|
} catch (error) {
|
|
7262
|
-
|
|
7281
|
+
logger17.error(
|
|
7263
7282
|
{
|
|
7264
7283
|
conversationId,
|
|
7265
7284
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7291,7 +7310,7 @@ var Agent = class {
|
|
|
7291
7310
|
artifactId: z5.z.string().describe("The unique identifier of the artifact to get.")
|
|
7292
7311
|
}),
|
|
7293
7312
|
execute: async ({ artifactId }) => {
|
|
7294
|
-
|
|
7313
|
+
logger17.info({ artifactId }, "get_artifact executed");
|
|
7295
7314
|
const artifact = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
7296
7315
|
scopes: {
|
|
7297
7316
|
tenantId: this.config.tenantId,
|
|
@@ -7541,7 +7560,7 @@ var Agent = class {
|
|
|
7541
7560
|
};
|
|
7542
7561
|
return enhanced;
|
|
7543
7562
|
} catch (error) {
|
|
7544
|
-
|
|
7563
|
+
logger17.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
7545
7564
|
return result;
|
|
7546
7565
|
}
|
|
7547
7566
|
}
|
|
@@ -7556,7 +7575,7 @@ var Agent = class {
|
|
|
7556
7575
|
}
|
|
7557
7576
|
});
|
|
7558
7577
|
} catch (error) {
|
|
7559
|
-
|
|
7578
|
+
logger17.error(
|
|
7560
7579
|
{ error, graphId: this.config.graphId },
|
|
7561
7580
|
"Failed to check graph artifact components"
|
|
7562
7581
|
);
|
|
@@ -7610,6 +7629,7 @@ var Agent = class {
|
|
|
7610
7629
|
throw err;
|
|
7611
7630
|
} finally {
|
|
7612
7631
|
childSpan.end();
|
|
7632
|
+
await defaultBatchProcessor.forceFlush();
|
|
7613
7633
|
}
|
|
7614
7634
|
}
|
|
7615
7635
|
);
|
|
@@ -7656,7 +7676,7 @@ var Agent = class {
|
|
|
7656
7676
|
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;
|
|
7657
7677
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
7658
7678
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
7659
|
-
|
|
7679
|
+
logger17.warn(
|
|
7660
7680
|
{
|
|
7661
7681
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
7662
7682
|
appliedTimeout: timeoutMs,
|
|
@@ -7698,7 +7718,7 @@ var Agent = class {
|
|
|
7698
7718
|
}
|
|
7699
7719
|
);
|
|
7700
7720
|
} catch (error) {
|
|
7701
|
-
|
|
7721
|
+
logger17.debug({ error }, "Failed to track agent reasoning");
|
|
7702
7722
|
}
|
|
7703
7723
|
}
|
|
7704
7724
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -7795,7 +7815,7 @@ var Agent = class {
|
|
|
7795
7815
|
}
|
|
7796
7816
|
);
|
|
7797
7817
|
} catch (error) {
|
|
7798
|
-
|
|
7818
|
+
logger17.debug({ error }, "Failed to track agent reasoning");
|
|
7799
7819
|
}
|
|
7800
7820
|
}
|
|
7801
7821
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8040,6 +8060,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8040
8060
|
}
|
|
8041
8061
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
8042
8062
|
span.end();
|
|
8063
|
+
await defaultBatchProcessor.forceFlush();
|
|
8043
8064
|
let formattedContent = response.formattedContent || null;
|
|
8044
8065
|
if (!formattedContent) {
|
|
8045
8066
|
const session = toolSessionManager.getSession(sessionId);
|
|
@@ -8086,7 +8107,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8086
8107
|
};
|
|
8087
8108
|
|
|
8088
8109
|
// src/agents/generateTaskHandler.ts
|
|
8089
|
-
var
|
|
8110
|
+
var logger18 = agentsCore.getLogger("generateTaskHandler");
|
|
8090
8111
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
8091
8112
|
return async (task) => {
|
|
8092
8113
|
try {
|
|
@@ -8139,7 +8160,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8139
8160
|
}
|
|
8140
8161
|
})
|
|
8141
8162
|
]);
|
|
8142
|
-
|
|
8163
|
+
logger18.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
8143
8164
|
const enhancedInternalRelations = await Promise.all(
|
|
8144
8165
|
internalRelations.map(async (relation) => {
|
|
8145
8166
|
try {
|
|
@@ -8168,7 +8189,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8168
8189
|
return { ...relation, description: enhancedDescription };
|
|
8169
8190
|
}
|
|
8170
8191
|
} catch (error) {
|
|
8171
|
-
|
|
8192
|
+
logger18.warn({ agentId: relation.id, error }, "Failed to enhance agent description");
|
|
8172
8193
|
}
|
|
8173
8194
|
return relation;
|
|
8174
8195
|
})
|
|
@@ -8268,7 +8289,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8268
8289
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
8269
8290
|
if (taskIdMatch) {
|
|
8270
8291
|
contextId = taskIdMatch[1];
|
|
8271
|
-
|
|
8292
|
+
logger18.info(
|
|
8272
8293
|
{
|
|
8273
8294
|
taskId: task.id,
|
|
8274
8295
|
extractedContextId: contextId,
|
|
@@ -8284,7 +8305,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8284
8305
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
8285
8306
|
agent.setDelegationStatus(isDelegation);
|
|
8286
8307
|
if (isDelegation) {
|
|
8287
|
-
|
|
8308
|
+
logger18.info(
|
|
8288
8309
|
{ agentId: config.agentId, taskId: task.id },
|
|
8289
8310
|
"Delegated agent - streaming disabled"
|
|
8290
8311
|
);
|
|
@@ -8509,7 +8530,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
8509
8530
|
init_dbClient();
|
|
8510
8531
|
init_logger();
|
|
8511
8532
|
var app = new zodOpenapi.OpenAPIHono();
|
|
8512
|
-
var
|
|
8533
|
+
var logger19 = agentsCore.getLogger("agents");
|
|
8513
8534
|
app.openapi(
|
|
8514
8535
|
zodOpenapi.createRoute({
|
|
8515
8536
|
method: "get",
|
|
@@ -8547,7 +8568,7 @@ app.openapi(
|
|
|
8547
8568
|
tracestate: c.req.header("tracestate"),
|
|
8548
8569
|
baggage: c.req.header("baggage")
|
|
8549
8570
|
};
|
|
8550
|
-
|
|
8571
|
+
logger19.info(
|
|
8551
8572
|
{
|
|
8552
8573
|
otelHeaders,
|
|
8553
8574
|
path: c.req.path,
|
|
@@ -8559,7 +8580,7 @@ app.openapi(
|
|
|
8559
8580
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
8560
8581
|
console.dir("executionContext", executionContext);
|
|
8561
8582
|
if (agentId) {
|
|
8562
|
-
|
|
8583
|
+
logger19.info(
|
|
8563
8584
|
{
|
|
8564
8585
|
message: "getRegisteredAgent (agent-level)",
|
|
8565
8586
|
tenantId,
|
|
@@ -8571,7 +8592,7 @@ app.openapi(
|
|
|
8571
8592
|
);
|
|
8572
8593
|
const credentialStores = c.get("credentialStores");
|
|
8573
8594
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
8574
|
-
|
|
8595
|
+
logger19.info({ agent }, "agent registered: well-known agent.json");
|
|
8575
8596
|
if (!agent) {
|
|
8576
8597
|
throw agentsCore.createApiError({
|
|
8577
8598
|
code: "not_found",
|
|
@@ -8580,7 +8601,7 @@ app.openapi(
|
|
|
8580
8601
|
}
|
|
8581
8602
|
return c.json(agent.agentCard);
|
|
8582
8603
|
} else {
|
|
8583
|
-
|
|
8604
|
+
logger19.info(
|
|
8584
8605
|
{
|
|
8585
8606
|
message: "getRegisteredGraph (graph-level)",
|
|
8586
8607
|
tenantId,
|
|
@@ -8606,7 +8627,7 @@ app.post("/a2a", async (c) => {
|
|
|
8606
8627
|
tracestate: c.req.header("tracestate"),
|
|
8607
8628
|
baggage: c.req.header("baggage")
|
|
8608
8629
|
};
|
|
8609
|
-
|
|
8630
|
+
logger19.info(
|
|
8610
8631
|
{
|
|
8611
8632
|
otelHeaders,
|
|
8612
8633
|
path: c.req.path,
|
|
@@ -8617,7 +8638,7 @@ app.post("/a2a", async (c) => {
|
|
|
8617
8638
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
8618
8639
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
8619
8640
|
if (agentId) {
|
|
8620
|
-
|
|
8641
|
+
logger19.info(
|
|
8621
8642
|
{
|
|
8622
8643
|
message: "a2a (agent-level)",
|
|
8623
8644
|
tenantId,
|
|
@@ -8641,7 +8662,7 @@ app.post("/a2a", async (c) => {
|
|
|
8641
8662
|
}
|
|
8642
8663
|
return a2aHandler(c, agent);
|
|
8643
8664
|
} else {
|
|
8644
|
-
|
|
8665
|
+
logger19.info(
|
|
8645
8666
|
{
|
|
8646
8667
|
message: "a2a (graph-level)",
|
|
8647
8668
|
tenantId,
|
|
@@ -8697,14 +8718,14 @@ init_dbClient();
|
|
|
8697
8718
|
// src/a2a/transfer.ts
|
|
8698
8719
|
init_dbClient();
|
|
8699
8720
|
init_logger();
|
|
8700
|
-
var
|
|
8721
|
+
var logger20 = agentsCore.getLogger("Transfer");
|
|
8701
8722
|
async function executeTransfer({
|
|
8702
8723
|
tenantId,
|
|
8703
8724
|
threadId,
|
|
8704
8725
|
projectId,
|
|
8705
8726
|
targetAgentId
|
|
8706
8727
|
}) {
|
|
8707
|
-
|
|
8728
|
+
logger20.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
8708
8729
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
8709
8730
|
scopes: { tenantId, projectId },
|
|
8710
8731
|
threadId,
|
|
@@ -9290,7 +9311,7 @@ function createMCPStreamHelper() {
|
|
|
9290
9311
|
}
|
|
9291
9312
|
|
|
9292
9313
|
// src/handlers/executionHandler.ts
|
|
9293
|
-
var
|
|
9314
|
+
var logger21 = agentsCore.getLogger("ExecutionHandler");
|
|
9294
9315
|
var ExecutionHandler = class {
|
|
9295
9316
|
constructor() {
|
|
9296
9317
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -9315,7 +9336,7 @@ var ExecutionHandler = class {
|
|
|
9315
9336
|
const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
|
|
9316
9337
|
registerStreamHelper(requestId2, sseHelper);
|
|
9317
9338
|
graphSessionManager.createSession(requestId2, graphId, tenantId, projectId, conversationId);
|
|
9318
|
-
|
|
9339
|
+
logger21.info(
|
|
9319
9340
|
{ sessionId: requestId2, graphId, conversationId },
|
|
9320
9341
|
"Created GraphSession for message execution"
|
|
9321
9342
|
);
|
|
@@ -9330,7 +9351,7 @@ var ExecutionHandler = class {
|
|
|
9330
9351
|
);
|
|
9331
9352
|
}
|
|
9332
9353
|
} catch (error) {
|
|
9333
|
-
|
|
9354
|
+
logger21.error(
|
|
9334
9355
|
{
|
|
9335
9356
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
9336
9357
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -9346,7 +9367,7 @@ var ExecutionHandler = class {
|
|
|
9346
9367
|
try {
|
|
9347
9368
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
9348
9369
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
9349
|
-
|
|
9370
|
+
logger21.info(
|
|
9350
9371
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
9351
9372
|
"Attempting to create or reuse existing task"
|
|
9352
9373
|
);
|
|
@@ -9370,7 +9391,7 @@ var ExecutionHandler = class {
|
|
|
9370
9391
|
agent_id: currentAgentId
|
|
9371
9392
|
}
|
|
9372
9393
|
});
|
|
9373
|
-
|
|
9394
|
+
logger21.info(
|
|
9374
9395
|
{
|
|
9375
9396
|
taskId,
|
|
9376
9397
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -9379,27 +9400,27 @@ var ExecutionHandler = class {
|
|
|
9379
9400
|
);
|
|
9380
9401
|
} catch (error) {
|
|
9381
9402
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
9382
|
-
|
|
9403
|
+
logger21.info(
|
|
9383
9404
|
{ taskId, error: error.message },
|
|
9384
9405
|
"Task already exists, fetching existing task"
|
|
9385
9406
|
);
|
|
9386
9407
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
9387
9408
|
if (existingTask) {
|
|
9388
9409
|
task = existingTask;
|
|
9389
|
-
|
|
9410
|
+
logger21.info(
|
|
9390
9411
|
{ taskId, existingTask },
|
|
9391
9412
|
"Successfully reused existing task from race condition"
|
|
9392
9413
|
);
|
|
9393
9414
|
} else {
|
|
9394
|
-
|
|
9415
|
+
logger21.error({ taskId, error }, "Task constraint failed but task not found");
|
|
9395
9416
|
throw error;
|
|
9396
9417
|
}
|
|
9397
9418
|
} else {
|
|
9398
|
-
|
|
9419
|
+
logger21.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
9399
9420
|
throw error;
|
|
9400
9421
|
}
|
|
9401
9422
|
}
|
|
9402
|
-
|
|
9423
|
+
logger21.debug(
|
|
9403
9424
|
{
|
|
9404
9425
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9405
9426
|
executionType: "create_initial_task",
|
|
@@ -9417,7 +9438,7 @@ var ExecutionHandler = class {
|
|
|
9417
9438
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
9418
9439
|
while (iterations < maxTransfers) {
|
|
9419
9440
|
iterations++;
|
|
9420
|
-
|
|
9441
|
+
logger21.info(
|
|
9421
9442
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
9422
9443
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
9423
9444
|
);
|
|
@@ -9425,10 +9446,10 @@ var ExecutionHandler = class {
|
|
|
9425
9446
|
scopes: { tenantId, projectId },
|
|
9426
9447
|
conversationId
|
|
9427
9448
|
});
|
|
9428
|
-
|
|
9449
|
+
logger21.info({ activeAgent }, "activeAgent");
|
|
9429
9450
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
9430
9451
|
currentAgentId = activeAgent.activeAgentId;
|
|
9431
|
-
|
|
9452
|
+
logger21.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
9432
9453
|
}
|
|
9433
9454
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
9434
9455
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -9469,13 +9490,13 @@ var ExecutionHandler = class {
|
|
|
9469
9490
|
});
|
|
9470
9491
|
if (!messageResponse?.result) {
|
|
9471
9492
|
errorCount++;
|
|
9472
|
-
|
|
9493
|
+
logger21.error(
|
|
9473
9494
|
{ currentAgentId, iterations, errorCount },
|
|
9474
9495
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
9475
9496
|
);
|
|
9476
9497
|
if (errorCount >= this.MAX_ERRORS) {
|
|
9477
9498
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
9478
|
-
|
|
9499
|
+
logger21.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
9479
9500
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
9480
9501
|
if (task) {
|
|
9481
9502
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -9500,7 +9521,7 @@ var ExecutionHandler = class {
|
|
|
9500
9521
|
const transferResponse = messageResponse.result;
|
|
9501
9522
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
9502
9523
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
9503
|
-
|
|
9524
|
+
logger21.info({ targetAgentId, transferReason }, "transfer response");
|
|
9504
9525
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
9505
9526
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
9506
9527
|
projectId,
|
|
@@ -9511,7 +9532,7 @@ var ExecutionHandler = class {
|
|
|
9511
9532
|
if (success) {
|
|
9512
9533
|
fromAgentId = currentAgentId;
|
|
9513
9534
|
currentAgentId = newAgentId;
|
|
9514
|
-
|
|
9535
|
+
logger21.info(
|
|
9515
9536
|
{
|
|
9516
9537
|
transferFrom: fromAgentId,
|
|
9517
9538
|
transferTo: currentAgentId,
|
|
@@ -9529,7 +9550,7 @@ var ExecutionHandler = class {
|
|
|
9529
9550
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
9530
9551
|
if (graphSessionData) {
|
|
9531
9552
|
const sessionSummary = graphSessionData.getSummary();
|
|
9532
|
-
|
|
9553
|
+
logger21.info(sessionSummary, "GraphSession data after completion");
|
|
9533
9554
|
}
|
|
9534
9555
|
let textContent = "";
|
|
9535
9556
|
for (const part of responseParts) {
|
|
@@ -9583,39 +9604,40 @@ var ExecutionHandler = class {
|
|
|
9583
9604
|
}
|
|
9584
9605
|
});
|
|
9585
9606
|
const updateTaskEnd = Date.now();
|
|
9586
|
-
|
|
9607
|
+
logger21.info(
|
|
9587
9608
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
9588
9609
|
"Completed updateTask operation"
|
|
9589
9610
|
);
|
|
9590
9611
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
9591
9612
|
await sseHelper.complete();
|
|
9592
|
-
|
|
9613
|
+
logger21.info({}, "Ending GraphSession and cleaning up");
|
|
9593
9614
|
graphSessionManager.endSession(requestId2);
|
|
9594
|
-
|
|
9615
|
+
logger21.info({}, "Cleaning up streamHelper");
|
|
9595
9616
|
unregisterStreamHelper(requestId2);
|
|
9596
9617
|
let response;
|
|
9597
9618
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
9598
9619
|
const captured = sseHelper.getCapturedResponse();
|
|
9599
9620
|
response = captured.text || "No response content";
|
|
9600
9621
|
}
|
|
9601
|
-
|
|
9622
|
+
logger21.info({}, "ExecutionHandler returning success");
|
|
9602
9623
|
return { success: true, iterations, response };
|
|
9603
9624
|
} catch (error) {
|
|
9604
9625
|
agentsCore.setSpanWithError(span, error);
|
|
9605
9626
|
throw error;
|
|
9606
9627
|
} finally {
|
|
9607
9628
|
span.end();
|
|
9629
|
+
await defaultBatchProcessor.forceFlush();
|
|
9608
9630
|
}
|
|
9609
9631
|
});
|
|
9610
9632
|
}
|
|
9611
9633
|
errorCount++;
|
|
9612
|
-
|
|
9634
|
+
logger21.warn(
|
|
9613
9635
|
{ iterations, errorCount },
|
|
9614
9636
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
9615
9637
|
);
|
|
9616
9638
|
if (errorCount >= this.MAX_ERRORS) {
|
|
9617
9639
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
9618
|
-
|
|
9640
|
+
logger21.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
9619
9641
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
9620
9642
|
if (task) {
|
|
9621
9643
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -9636,7 +9658,7 @@ var ExecutionHandler = class {
|
|
|
9636
9658
|
}
|
|
9637
9659
|
}
|
|
9638
9660
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
9639
|
-
|
|
9661
|
+
logger21.error({ maxTransfers, iterations }, errorMessage);
|
|
9640
9662
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
9641
9663
|
if (task) {
|
|
9642
9664
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -9655,7 +9677,7 @@ var ExecutionHandler = class {
|
|
|
9655
9677
|
unregisterStreamHelper(requestId2);
|
|
9656
9678
|
return { success: false, error: errorMessage, iterations };
|
|
9657
9679
|
} catch (error) {
|
|
9658
|
-
|
|
9680
|
+
logger21.error({ error }, "Error in execution handler");
|
|
9659
9681
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
9660
9682
|
await sseHelper.writeOperation(
|
|
9661
9683
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -9683,7 +9705,7 @@ var ExecutionHandler = class {
|
|
|
9683
9705
|
// src/routes/chat.ts
|
|
9684
9706
|
init_logger();
|
|
9685
9707
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
9686
|
-
var
|
|
9708
|
+
var logger22 = agentsCore.getLogger("completionsHandler");
|
|
9687
9709
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
9688
9710
|
method: "post",
|
|
9689
9711
|
path: "/completions",
|
|
@@ -9801,7 +9823,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9801
9823
|
tracestate: c.req.header("tracestate"),
|
|
9802
9824
|
baggage: c.req.header("baggage")
|
|
9803
9825
|
};
|
|
9804
|
-
|
|
9826
|
+
logger22.info(
|
|
9805
9827
|
{
|
|
9806
9828
|
otelHeaders,
|
|
9807
9829
|
path: c.req.path,
|
|
@@ -9894,7 +9916,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9894
9916
|
dbClient: dbClient_default,
|
|
9895
9917
|
credentialStores
|
|
9896
9918
|
});
|
|
9897
|
-
|
|
9919
|
+
logger22.info(
|
|
9898
9920
|
{
|
|
9899
9921
|
tenantId,
|
|
9900
9922
|
projectId,
|
|
@@ -9942,7 +9964,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9942
9964
|
try {
|
|
9943
9965
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
9944
9966
|
await sseHelper.writeRole();
|
|
9945
|
-
|
|
9967
|
+
logger22.info({ agentId }, "Starting execution");
|
|
9946
9968
|
const executionHandler = new ExecutionHandler();
|
|
9947
9969
|
const result = await executionHandler.execute({
|
|
9948
9970
|
executionContext,
|
|
@@ -9952,7 +9974,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9952
9974
|
requestId: requestId2,
|
|
9953
9975
|
sseHelper
|
|
9954
9976
|
});
|
|
9955
|
-
|
|
9977
|
+
logger22.info(
|
|
9956
9978
|
{ result },
|
|
9957
9979
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
9958
9980
|
);
|
|
@@ -9966,7 +9988,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9966
9988
|
}
|
|
9967
9989
|
await sseHelper.complete();
|
|
9968
9990
|
} catch (error) {
|
|
9969
|
-
|
|
9991
|
+
logger22.error(
|
|
9970
9992
|
{
|
|
9971
9993
|
error: error instanceof Error ? error.message : error,
|
|
9972
9994
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -9983,12 +10005,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9983
10005
|
);
|
|
9984
10006
|
await sseHelper.complete();
|
|
9985
10007
|
} catch (streamError) {
|
|
9986
|
-
|
|
10008
|
+
logger22.error({ streamError }, "Failed to write error to stream");
|
|
9987
10009
|
}
|
|
9988
10010
|
}
|
|
9989
10011
|
});
|
|
9990
10012
|
} catch (error) {
|
|
9991
|
-
|
|
10013
|
+
logger22.error(
|
|
9992
10014
|
{
|
|
9993
10015
|
error: error instanceof Error ? error.message : error,
|
|
9994
10016
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10016,7 +10038,7 @@ var chat_default = app2;
|
|
|
10016
10038
|
init_dbClient();
|
|
10017
10039
|
init_logger();
|
|
10018
10040
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
10019
|
-
var
|
|
10041
|
+
var logger23 = agentsCore.getLogger("chatDataStream");
|
|
10020
10042
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
10021
10043
|
method: "post",
|
|
10022
10044
|
path: "/chat",
|
|
@@ -10131,9 +10153,10 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10131
10153
|
dbClient: dbClient_default,
|
|
10132
10154
|
credentialStores
|
|
10133
10155
|
});
|
|
10156
|
+
await defaultBatchProcessor.forceFlush();
|
|
10134
10157
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
10135
10158
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
10136
|
-
|
|
10159
|
+
logger23.info({ userText, lastUserMessage }, "userText");
|
|
10137
10160
|
const messageSpan = api.trace.getActiveSpan();
|
|
10138
10161
|
if (messageSpan) {
|
|
10139
10162
|
messageSpan.setAttributes({
|
|
@@ -10175,7 +10198,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10175
10198
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
10176
10199
|
}
|
|
10177
10200
|
} catch (err) {
|
|
10178
|
-
|
|
10201
|
+
logger23.error({ err }, "Streaming error");
|
|
10179
10202
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
10180
10203
|
} finally {
|
|
10181
10204
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -10196,7 +10219,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10196
10219
|
)
|
|
10197
10220
|
);
|
|
10198
10221
|
} catch (error) {
|
|
10199
|
-
|
|
10222
|
+
logger23.error({ error }, "chatDataStream error");
|
|
10200
10223
|
throw agentsCore.createApiError({
|
|
10201
10224
|
code: "internal_server_error",
|
|
10202
10225
|
message: "Failed to process chat completion"
|
|
@@ -10211,7 +10234,7 @@ init_logger();
|
|
|
10211
10234
|
function createMCPSchema(schema) {
|
|
10212
10235
|
return schema;
|
|
10213
10236
|
}
|
|
10214
|
-
var
|
|
10237
|
+
var logger24 = agentsCore.getLogger("mcp");
|
|
10215
10238
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
10216
10239
|
constructor() {
|
|
10217
10240
|
__publicField(this, "mockRes");
|
|
@@ -10266,21 +10289,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
10266
10289
|
id: 0
|
|
10267
10290
|
});
|
|
10268
10291
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
10269
|
-
|
|
10292
|
+
logger24.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
10270
10293
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
10271
10294
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
10272
10295
|
try {
|
|
10273
10296
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
10274
|
-
|
|
10297
|
+
logger24.info({ sessionId }, "Successfully spoofed initialization");
|
|
10275
10298
|
} catch (spoofError) {
|
|
10276
|
-
|
|
10299
|
+
logger24.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
10277
10300
|
}
|
|
10278
10301
|
};
|
|
10279
10302
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
10280
10303
|
const sessionId = req.headers["mcp-session-id"];
|
|
10281
|
-
|
|
10304
|
+
logger24.info({ sessionId }, "Received MCP session ID");
|
|
10282
10305
|
if (!sessionId) {
|
|
10283
|
-
|
|
10306
|
+
logger24.info({ body }, "Missing session ID");
|
|
10284
10307
|
res.writeHead(400).end(
|
|
10285
10308
|
JSON.stringify({
|
|
10286
10309
|
jsonrpc: "2.0",
|
|
@@ -10306,7 +10329,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10306
10329
|
scopes: { tenantId, projectId },
|
|
10307
10330
|
conversationId: sessionId
|
|
10308
10331
|
});
|
|
10309
|
-
|
|
10332
|
+
logger24.info(
|
|
10310
10333
|
{
|
|
10311
10334
|
sessionId,
|
|
10312
10335
|
conversationFound: !!conversation,
|
|
@@ -10317,7 +10340,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10317
10340
|
"Conversation lookup result"
|
|
10318
10341
|
);
|
|
10319
10342
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
10320
|
-
|
|
10343
|
+
logger24.info(
|
|
10321
10344
|
{ sessionId, conversationId: conversation?.id },
|
|
10322
10345
|
"MCP session not found or invalid"
|
|
10323
10346
|
);
|
|
@@ -10378,7 +10401,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
10378
10401
|
requestId: requestId2,
|
|
10379
10402
|
sseHelper: mcpStreamHelper
|
|
10380
10403
|
});
|
|
10381
|
-
|
|
10404
|
+
logger24.info(
|
|
10382
10405
|
{ result },
|
|
10383
10406
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10384
10407
|
);
|
|
@@ -10462,7 +10485,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
10462
10485
|
dbClient: dbClient_default,
|
|
10463
10486
|
credentialStores
|
|
10464
10487
|
});
|
|
10465
|
-
|
|
10488
|
+
logger24.info(
|
|
10466
10489
|
{
|
|
10467
10490
|
tenantId,
|
|
10468
10491
|
projectId,
|
|
@@ -10524,7 +10547,7 @@ var validateRequestParameters = (c) => {
|
|
|
10524
10547
|
};
|
|
10525
10548
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
10526
10549
|
const { tenantId, projectId, graphId } = executionContext;
|
|
10527
|
-
|
|
10550
|
+
logger24.info({ body }, "Received initialization request");
|
|
10528
10551
|
const sessionId = nanoid.nanoid();
|
|
10529
10552
|
const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
10530
10553
|
scopes: { tenantId, projectId, graphId }
|
|
@@ -10564,7 +10587,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10564
10587
|
}
|
|
10565
10588
|
}
|
|
10566
10589
|
});
|
|
10567
|
-
|
|
10590
|
+
logger24.info(
|
|
10568
10591
|
{ sessionId, conversationId: conversation.id },
|
|
10569
10592
|
"Created MCP session as conversation"
|
|
10570
10593
|
);
|
|
@@ -10573,9 +10596,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10573
10596
|
});
|
|
10574
10597
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
10575
10598
|
await server.connect(transport);
|
|
10576
|
-
|
|
10599
|
+
logger24.info({ sessionId }, "Server connected for initialization");
|
|
10577
10600
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
10578
|
-
|
|
10601
|
+
logger24.info(
|
|
10579
10602
|
{
|
|
10580
10603
|
sessionId,
|
|
10581
10604
|
bodyMethod: body?.method,
|
|
@@ -10584,7 +10607,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10584
10607
|
"About to handle initialization request"
|
|
10585
10608
|
);
|
|
10586
10609
|
await transport.handleRequest(req, res, body);
|
|
10587
|
-
|
|
10610
|
+
logger24.info({ sessionId }, "Successfully handled initialization request");
|
|
10588
10611
|
return fetchToNode.toFetchResponse(res);
|
|
10589
10612
|
};
|
|
10590
10613
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -10612,8 +10635,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
10612
10635
|
sessionId,
|
|
10613
10636
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
10614
10637
|
);
|
|
10615
|
-
|
|
10616
|
-
|
|
10638
|
+
logger24.info({ sessionId }, "Server connected and transport initialized");
|
|
10639
|
+
logger24.info(
|
|
10617
10640
|
{
|
|
10618
10641
|
sessionId,
|
|
10619
10642
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -10627,9 +10650,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
10627
10650
|
);
|
|
10628
10651
|
try {
|
|
10629
10652
|
await transport.handleRequest(req, res, body);
|
|
10630
|
-
|
|
10653
|
+
logger24.info({ sessionId }, "Successfully handled MCP request");
|
|
10631
10654
|
} catch (transportError) {
|
|
10632
|
-
|
|
10655
|
+
logger24.error(
|
|
10633
10656
|
{
|
|
10634
10657
|
sessionId,
|
|
10635
10658
|
error: transportError,
|
|
@@ -10680,13 +10703,13 @@ app4.openapi(
|
|
|
10680
10703
|
}
|
|
10681
10704
|
const { executionContext } = paramValidation;
|
|
10682
10705
|
const body = c.get("requestBody") || {};
|
|
10683
|
-
|
|
10706
|
+
logger24.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
10684
10707
|
const isInitRequest = body.method === "initialize";
|
|
10685
10708
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
10686
10709
|
const validatedContext = c.get("validatedContext") || {};
|
|
10687
10710
|
const credentialStores = c.get("credentialStores");
|
|
10688
|
-
|
|
10689
|
-
|
|
10711
|
+
logger24.info({ validatedContext }, "Validated context");
|
|
10712
|
+
logger24.info({ req }, "request");
|
|
10690
10713
|
if (isInitRequest) {
|
|
10691
10714
|
return await handleInitializationRequest(
|
|
10692
10715
|
body,
|
|
@@ -10708,7 +10731,7 @@ app4.openapi(
|
|
|
10708
10731
|
);
|
|
10709
10732
|
}
|
|
10710
10733
|
} catch (e) {
|
|
10711
|
-
|
|
10734
|
+
logger24.error(
|
|
10712
10735
|
{
|
|
10713
10736
|
error: e instanceof Error ? e.message : e,
|
|
10714
10737
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -10720,7 +10743,7 @@ app4.openapi(
|
|
|
10720
10743
|
}
|
|
10721
10744
|
);
|
|
10722
10745
|
app4.get("/", async (c) => {
|
|
10723
|
-
|
|
10746
|
+
logger24.info({}, "Received GET MCP request");
|
|
10724
10747
|
return c.json(
|
|
10725
10748
|
{
|
|
10726
10749
|
jsonrpc: "2.0",
|
|
@@ -10734,7 +10757,7 @@ app4.get("/", async (c) => {
|
|
|
10734
10757
|
);
|
|
10735
10758
|
});
|
|
10736
10759
|
app4.delete("/", async (c) => {
|
|
10737
|
-
|
|
10760
|
+
logger24.info({}, "Received DELETE MCP request");
|
|
10738
10761
|
return c.json(
|
|
10739
10762
|
{
|
|
10740
10763
|
jsonrpc: "2.0",
|
|
@@ -10747,7 +10770,7 @@ app4.delete("/", async (c) => {
|
|
|
10747
10770
|
var mcp_default = app4;
|
|
10748
10771
|
|
|
10749
10772
|
// src/app.ts
|
|
10750
|
-
var
|
|
10773
|
+
var logger25 = agentsCore.getLogger("agents-run-api");
|
|
10751
10774
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
10752
10775
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
10753
10776
|
app6.use("*", otel.otel());
|
|
@@ -10763,7 +10786,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10763
10786
|
const body = await c.req.json();
|
|
10764
10787
|
c.set("requestBody", body);
|
|
10765
10788
|
} catch (error) {
|
|
10766
|
-
|
|
10789
|
+
logger25.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
10767
10790
|
}
|
|
10768
10791
|
}
|
|
10769
10792
|
return next();
|
|
@@ -10814,8 +10837,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10814
10837
|
if (!isExpectedError) {
|
|
10815
10838
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
10816
10839
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
10817
|
-
if (
|
|
10818
|
-
|
|
10840
|
+
if (logger25) {
|
|
10841
|
+
logger25.error(
|
|
10819
10842
|
{
|
|
10820
10843
|
error: err,
|
|
10821
10844
|
message: errorMessage,
|
|
@@ -10827,8 +10850,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10827
10850
|
);
|
|
10828
10851
|
}
|
|
10829
10852
|
} else {
|
|
10830
|
-
if (
|
|
10831
|
-
|
|
10853
|
+
if (logger25) {
|
|
10854
|
+
logger25.error(
|
|
10832
10855
|
{
|
|
10833
10856
|
error: err,
|
|
10834
10857
|
path: c.req.path,
|
|
@@ -10845,8 +10868,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10845
10868
|
const response = err.getResponse();
|
|
10846
10869
|
return response;
|
|
10847
10870
|
} catch (responseError) {
|
|
10848
|
-
if (
|
|
10849
|
-
|
|
10871
|
+
if (logger25) {
|
|
10872
|
+
logger25.error({ error: responseError }, "Error while handling HTTPException response");
|
|
10850
10873
|
}
|
|
10851
10874
|
}
|
|
10852
10875
|
}
|
|
@@ -10880,7 +10903,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10880
10903
|
app6.use("*", async (c, next) => {
|
|
10881
10904
|
const executionContext = c.get("executionContext");
|
|
10882
10905
|
if (!executionContext) {
|
|
10883
|
-
|
|
10906
|
+
logger25.debug({}, "Empty execution context");
|
|
10884
10907
|
return next();
|
|
10885
10908
|
}
|
|
10886
10909
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -10889,7 +10912,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10889
10912
|
if (requestBody) {
|
|
10890
10913
|
conversationId = requestBody.conversationId;
|
|
10891
10914
|
if (!conversationId) {
|
|
10892
|
-
|
|
10915
|
+
logger25.debug({ requestBody }, "No conversation ID found in request body");
|
|
10893
10916
|
}
|
|
10894
10917
|
}
|
|
10895
10918
|
const entries = Object.fromEntries(
|
|
@@ -10904,7 +10927,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10904
10927
|
})
|
|
10905
10928
|
);
|
|
10906
10929
|
if (!Object.keys(entries).length) {
|
|
10907
|
-
|
|
10930
|
+
logger25.debug({}, "Empty entries for baggage");
|
|
10908
10931
|
return next();
|
|
10909
10932
|
}
|
|
10910
10933
|
const bag = Object.entries(entries).reduce(
|