@inkeep/agents-run-api 0.0.0-dev-20251022171155 → 0.0.0-dev-20251022211302
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-TVLDBLRZ.js → chunk-DWEFKQTA.js} +1 -1
- package/dist/{chunk-XLUE6U2L.js → chunk-IMJLQGAX.js} +2 -2
- package/dist/{chunk-IBMWBEXH.js → chunk-TRNLEUK2.js} +1 -1
- package/dist/{chunk-LHCIBW34.js → chunk-Z4TYO3W3.js} +1 -0
- package/dist/{conversations-H2TSLD3U.js → conversations-V6DNH5MW.js} +1 -1
- package/dist/dbClient-PLEBWGM4.js +1 -0
- package/dist/index.cjs +307 -188
- package/dist/index.js +304 -187
- package/dist/instrumentation.cjs +1 -0
- package/dist/instrumentation.js +1 -1
- package/package.json +2 -2
- package/dist/dbClient-CSP4YJOO.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -82,6 +82,7 @@ var init_env = __esm({
|
|
|
82
82
|
OPENAI_API_KEY: z6.z.string().optional(),
|
|
83
83
|
GOOGLE_GENERATIVE_AI_API_KEY: z6.z.string().optional(),
|
|
84
84
|
INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z6.z.string().optional(),
|
|
85
|
+
INKEEP_AGENTS_JWT_SIGNING_SECRET: z6.z.string().optional(),
|
|
85
86
|
OTEL_BSP_SCHEDULE_DELAY: z6.z.coerce.number().optional().default(500),
|
|
86
87
|
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: z6.z.coerce.number().optional().default(64)
|
|
87
88
|
});
|
|
@@ -357,8 +358,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
357
358
|
});
|
|
358
359
|
referenceArtifacts.push(...artifacts);
|
|
359
360
|
}
|
|
360
|
-
const
|
|
361
|
-
|
|
361
|
+
const logger30 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
362
|
+
logger30.debug(
|
|
362
363
|
{
|
|
363
364
|
conversationId,
|
|
364
365
|
visibleMessages: visibleMessages.length,
|
|
@@ -370,8 +371,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
370
371
|
);
|
|
371
372
|
return referenceArtifacts;
|
|
372
373
|
} catch (error) {
|
|
373
|
-
const
|
|
374
|
-
|
|
374
|
+
const logger30 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
375
|
+
logger30.error(
|
|
375
376
|
{
|
|
376
377
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
377
378
|
conversationId
|
|
@@ -412,14 +413,14 @@ const execute = ${executeCode}
|
|
|
412
413
|
})();
|
|
413
414
|
`;
|
|
414
415
|
}
|
|
415
|
-
function parseExecutionResult(stdout, functionId,
|
|
416
|
+
function parseExecutionResult(stdout, functionId, logger30) {
|
|
416
417
|
try {
|
|
417
418
|
const outputLines = stdout.split("\n").filter((line) => line.trim());
|
|
418
419
|
const resultLine = outputLines[outputLines.length - 1];
|
|
419
420
|
return JSON.parse(resultLine);
|
|
420
421
|
} catch (parseError) {
|
|
421
|
-
if (
|
|
422
|
-
|
|
422
|
+
if (logger30) {
|
|
423
|
+
logger30.warn(
|
|
423
424
|
{
|
|
424
425
|
functionId,
|
|
425
426
|
stdout,
|
|
@@ -1459,7 +1460,8 @@ function createExecutionContext(params) {
|
|
|
1459
1460
|
agentId: params.agentId,
|
|
1460
1461
|
baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
|
|
1461
1462
|
apiKeyId: params.apiKeyId,
|
|
1462
|
-
subAgentId: params.subAgentId
|
|
1463
|
+
subAgentId: params.subAgentId,
|
|
1464
|
+
metadata: params.metadata || {}
|
|
1463
1465
|
};
|
|
1464
1466
|
}
|
|
1465
1467
|
|
|
@@ -1481,28 +1483,36 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
1481
1483
|
const reqUrl = new URL(c.req.url);
|
|
1482
1484
|
const baseUrl = proto && host ? `${proto}://${host}` : host ? `${reqUrl.protocol}//${host}` : `${reqUrl.origin}`;
|
|
1483
1485
|
if (process.env.ENVIRONMENT === "development" || process.env.ENVIRONMENT === "test") {
|
|
1486
|
+
logger2.info({}, "development environment");
|
|
1484
1487
|
let executionContext;
|
|
1485
1488
|
if (authHeader?.startsWith("Bearer ")) {
|
|
1489
|
+
const apiKey2 = authHeader.substring(7);
|
|
1486
1490
|
try {
|
|
1487
|
-
executionContext = await extractContextFromApiKey(
|
|
1491
|
+
executionContext = await extractContextFromApiKey(apiKey2, baseUrl);
|
|
1488
1492
|
if (subAgentId) {
|
|
1489
1493
|
executionContext.subAgentId = subAgentId;
|
|
1490
1494
|
}
|
|
1491
|
-
|
|
1495
|
+
c.set("executionContext", executionContext);
|
|
1492
1496
|
} catch {
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1497
|
+
try {
|
|
1498
|
+
executionContext = await extractContextFromTeamAgentToken(apiKey2, baseUrl, subAgentId);
|
|
1499
|
+
c.set("executionContext", executionContext);
|
|
1500
|
+
} catch {
|
|
1501
|
+
executionContext = createExecutionContext({
|
|
1502
|
+
apiKey: "development",
|
|
1503
|
+
tenantId: tenantId || "test-tenant",
|
|
1504
|
+
projectId: projectId || "test-project",
|
|
1505
|
+
agentId: agentId || "test-agent",
|
|
1506
|
+
apiKeyId: "test-key",
|
|
1507
|
+
baseUrl,
|
|
1508
|
+
subAgentId
|
|
1509
|
+
});
|
|
1510
|
+
c.set("executionContext", executionContext);
|
|
1511
|
+
logger2.info(
|
|
1512
|
+
{},
|
|
1513
|
+
"Development/test environment - fallback to default context due to invalid API key"
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1506
1516
|
}
|
|
1507
1517
|
} else {
|
|
1508
1518
|
executionContext = createExecutionContext({
|
|
@@ -1514,12 +1524,12 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
1514
1524
|
baseUrl,
|
|
1515
1525
|
subAgentId
|
|
1516
1526
|
});
|
|
1527
|
+
c.set("executionContext", executionContext);
|
|
1517
1528
|
logger2.info(
|
|
1518
1529
|
{},
|
|
1519
1530
|
"Development/test environment - no API key provided, using default context"
|
|
1520
1531
|
);
|
|
1521
1532
|
}
|
|
1522
|
-
c.set("executionContext", executionContext);
|
|
1523
1533
|
await next();
|
|
1524
1534
|
return;
|
|
1525
1535
|
}
|
|
@@ -1550,12 +1560,21 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
1550
1560
|
await next();
|
|
1551
1561
|
return;
|
|
1552
1562
|
} else if (apiKey) {
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1563
|
+
try {
|
|
1564
|
+
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
1565
|
+
if (subAgentId) {
|
|
1566
|
+
executionContext.subAgentId = subAgentId;
|
|
1567
|
+
}
|
|
1568
|
+
c.set("executionContext", executionContext);
|
|
1569
|
+
logger2.info({}, "API key authenticated successfully");
|
|
1570
|
+
} catch {
|
|
1571
|
+
const executionContext = await extractContextFromTeamAgentToken(
|
|
1572
|
+
apiKey,
|
|
1573
|
+
baseUrl,
|
|
1574
|
+
subAgentId
|
|
1575
|
+
);
|
|
1576
|
+
c.set("executionContext", executionContext);
|
|
1556
1577
|
}
|
|
1557
|
-
c.set("executionContext", executionContext);
|
|
1558
|
-
logger2.info({}, "API key authenticated successfully");
|
|
1559
1578
|
await next();
|
|
1560
1579
|
return;
|
|
1561
1580
|
} else {
|
|
@@ -1585,14 +1604,24 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
1585
1604
|
"API key authenticated successfully"
|
|
1586
1605
|
);
|
|
1587
1606
|
await next();
|
|
1588
|
-
} catch
|
|
1589
|
-
|
|
1590
|
-
|
|
1607
|
+
} catch {
|
|
1608
|
+
try {
|
|
1609
|
+
const executionContext = await extractContextFromTeamAgentToken(
|
|
1610
|
+
apiKey,
|
|
1611
|
+
baseUrl,
|
|
1612
|
+
subAgentId
|
|
1613
|
+
);
|
|
1614
|
+
c.set("executionContext", executionContext);
|
|
1615
|
+
await next();
|
|
1616
|
+
} catch (error) {
|
|
1617
|
+
if (error instanceof httpException.HTTPException) {
|
|
1618
|
+
throw error;
|
|
1619
|
+
}
|
|
1620
|
+
logger2.error({ error }, "API key authentication error");
|
|
1621
|
+
throw new httpException.HTTPException(500, {
|
|
1622
|
+
message: "Authentication failed"
|
|
1623
|
+
});
|
|
1591
1624
|
}
|
|
1592
|
-
logger2.error({ error }, "API key authentication error");
|
|
1593
|
-
throw new httpException.HTTPException(500, {
|
|
1594
|
-
message: "Authentication failed"
|
|
1595
|
-
});
|
|
1596
1625
|
}
|
|
1597
1626
|
});
|
|
1598
1627
|
var extractContextFromApiKey = async (apiKey, baseUrl) => {
|
|
@@ -1614,8 +1643,15 @@ var extractContextFromApiKey = async (apiKey, baseUrl) => {
|
|
|
1614
1643
|
message: "Invalid or expired API key"
|
|
1615
1644
|
});
|
|
1616
1645
|
}
|
|
1617
|
-
logger2.
|
|
1618
|
-
|
|
1646
|
+
logger2.debug(
|
|
1647
|
+
{
|
|
1648
|
+
tenantId: apiKeyRecord.tenantId,
|
|
1649
|
+
projectId: apiKeyRecord.projectId,
|
|
1650
|
+
agentId: apiKeyRecord.agentId,
|
|
1651
|
+
subAgentId: agent.defaultSubAgentId || void 0
|
|
1652
|
+
},
|
|
1653
|
+
"API key authenticated successfully"
|
|
1654
|
+
);
|
|
1619
1655
|
return createExecutionContext({
|
|
1620
1656
|
apiKey,
|
|
1621
1657
|
tenantId: apiKeyRecord.tenantId,
|
|
@@ -1626,6 +1662,53 @@ var extractContextFromApiKey = async (apiKey, baseUrl) => {
|
|
|
1626
1662
|
subAgentId: agent.defaultSubAgentId || void 0
|
|
1627
1663
|
});
|
|
1628
1664
|
};
|
|
1665
|
+
var extractContextFromTeamAgentToken = async (token, baseUrl, expectedSubAgentId) => {
|
|
1666
|
+
const result = await agentsCore.verifyServiceToken(token);
|
|
1667
|
+
if (!result.valid || !result.payload) {
|
|
1668
|
+
logger2.warn({ error: result.error }, "Invalid team agent JWT token");
|
|
1669
|
+
throw new httpException.HTTPException(401, {
|
|
1670
|
+
message: `Invalid team agent token: ${result.error || "Unknown error"}`
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
const payload = result.payload;
|
|
1674
|
+
if (expectedSubAgentId && !agentsCore.validateTargetAgent(payload, expectedSubAgentId)) {
|
|
1675
|
+
logger2.error(
|
|
1676
|
+
{
|
|
1677
|
+
tokenTargetAgentId: payload.aud,
|
|
1678
|
+
expectedSubAgentId,
|
|
1679
|
+
originAgentId: payload.sub
|
|
1680
|
+
},
|
|
1681
|
+
"Team agent token target mismatch"
|
|
1682
|
+
);
|
|
1683
|
+
throw new httpException.HTTPException(403, {
|
|
1684
|
+
message: "Token not valid for the requested agent"
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
logger2.info(
|
|
1688
|
+
{
|
|
1689
|
+
originAgentId: payload.sub,
|
|
1690
|
+
targetAgentId: payload.aud,
|
|
1691
|
+
tenantId: payload.tenantId,
|
|
1692
|
+
projectId: payload.projectId
|
|
1693
|
+
},
|
|
1694
|
+
"Team agent JWT token authenticated successfully"
|
|
1695
|
+
);
|
|
1696
|
+
return createExecutionContext({
|
|
1697
|
+
apiKey: "team-agent-jwt",
|
|
1698
|
+
// Not an actual API key
|
|
1699
|
+
tenantId: payload.tenantId,
|
|
1700
|
+
projectId: payload.projectId,
|
|
1701
|
+
agentId: payload.aud,
|
|
1702
|
+
// Target agent ID
|
|
1703
|
+
apiKeyId: "team-agent-token",
|
|
1704
|
+
baseUrl,
|
|
1705
|
+
subAgentId: void 0,
|
|
1706
|
+
metadata: {
|
|
1707
|
+
teamDelegation: true,
|
|
1708
|
+
originAgentId: payload.sub
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
};
|
|
1629
1712
|
|
|
1630
1713
|
// src/openapi.ts
|
|
1631
1714
|
init_env();
|
|
@@ -1813,7 +1896,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1813
1896
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1814
1897
|
});
|
|
1815
1898
|
logger3.info({ metadata: params.message.metadata }, "message metadata");
|
|
1816
|
-
if (params.message.metadata?.fromSubAgentId || params.message.metadata?.fromExternalAgentId) {
|
|
1899
|
+
if (params.message.metadata?.fromSubAgentId || params.message.metadata?.fromExternalAgentId || params.message.metadata?.fromTeamAgentId) {
|
|
1817
1900
|
const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
|
|
1818
1901
|
try {
|
|
1819
1902
|
const messageData = {
|
|
@@ -1835,13 +1918,18 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1835
1918
|
} else if (params.message.metadata?.fromExternalAgentId) {
|
|
1836
1919
|
messageData.fromExternalAgentId = params.message.metadata.fromExternalAgentId;
|
|
1837
1920
|
messageData.toSubAgentId = agent.subAgentId;
|
|
1921
|
+
} else if (params.message.metadata?.fromTeamAgentId) {
|
|
1922
|
+
messageData.fromTeamAgentId = params.message.metadata.fromTeamAgentId;
|
|
1923
|
+
messageData.toTeamAgentId = agent.subAgentId;
|
|
1838
1924
|
}
|
|
1839
1925
|
await agentsCore.createMessage(dbClient_default)(messageData);
|
|
1840
1926
|
logger3.info(
|
|
1841
1927
|
{
|
|
1842
1928
|
fromSubAgentId: params.message.metadata.fromSubAgentId,
|
|
1843
1929
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
1930
|
+
fromTeamAgentId: params.message.metadata.fromTeamAgentId,
|
|
1844
1931
|
toSubAgentId: agent.subAgentId,
|
|
1932
|
+
toTeamAgentId: params.message.metadata.fromTeamAgentId ? agent.subAgentId : void 0,
|
|
1845
1933
|
conversationId: effectiveContextId,
|
|
1846
1934
|
messageType: "a2a-request",
|
|
1847
1935
|
taskId: task.id
|
|
@@ -1854,6 +1942,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
1854
1942
|
error,
|
|
1855
1943
|
fromSubAgentId: params.message.metadata.fromSubAgentId,
|
|
1856
1944
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
1945
|
+
fromTeamAgentId: params.message.metadata.fromTeamAgentId,
|
|
1857
1946
|
toSubAgentId: agent.subAgentId,
|
|
1858
1947
|
conversationId: effectiveContextId
|
|
1859
1948
|
},
|
|
@@ -6904,8 +6993,10 @@ function createDelegateToAgentTool({
|
|
|
6904
6993
|
);
|
|
6905
6994
|
}
|
|
6906
6995
|
const isInternal = delegateConfig.type === "internal";
|
|
6996
|
+
const isExternal = delegateConfig.type === "external";
|
|
6997
|
+
const isTeam = delegateConfig.type === "team";
|
|
6907
6998
|
let resolvedHeaders = {};
|
|
6908
|
-
if (
|
|
6999
|
+
if (isExternal) {
|
|
6909
7000
|
if ((delegateConfig.config.credentialReferenceId || delegateConfig.config.headers) && credentialStoreRegistry) {
|
|
6910
7001
|
const contextResolver = new agentsCore.ContextResolver(
|
|
6911
7002
|
tenantId,
|
|
@@ -6943,6 +7034,23 @@ function createDelegateToAgentTool({
|
|
|
6943
7034
|
headers: delegateConfig.config.headers || void 0
|
|
6944
7035
|
});
|
|
6945
7036
|
}
|
|
7037
|
+
} else if (isTeam) {
|
|
7038
|
+
const contextResolver = new agentsCore.ContextResolver(
|
|
7039
|
+
tenantId,
|
|
7040
|
+
projectId,
|
|
7041
|
+
dbClient_default,
|
|
7042
|
+
credentialStoreRegistry
|
|
7043
|
+
);
|
|
7044
|
+
const context2 = await contextResolver.resolveHeaders(metadata.conversationId, contextId);
|
|
7045
|
+
for (const [key, value] of Object.entries(agentsCore.headers)) {
|
|
7046
|
+
resolvedHeaders[key] = agentsCore.TemplateEngine.render(value, context2, { strict: true });
|
|
7047
|
+
}
|
|
7048
|
+
resolvedHeaders.Authorization = `Bearer ${await agentsCore.generateServiceToken({
|
|
7049
|
+
tenantId,
|
|
7050
|
+
projectId,
|
|
7051
|
+
originAgentId: agentId,
|
|
7052
|
+
targetAgentId: delegateConfig.config.id
|
|
7053
|
+
})}`;
|
|
6946
7054
|
} else {
|
|
6947
7055
|
resolvedHeaders = {
|
|
6948
7056
|
Authorization: `Bearer ${metadata.apiKey}`,
|
|
@@ -8805,7 +8913,7 @@ var Agent = class {
|
|
|
8805
8913
|
/**
|
|
8806
8914
|
* Get resolved context using ContextResolver - will return cached data or fetch fresh data as needed
|
|
8807
8915
|
*/
|
|
8808
|
-
async getResolvedContext(conversationId,
|
|
8916
|
+
async getResolvedContext(conversationId, headers2) {
|
|
8809
8917
|
try {
|
|
8810
8918
|
if (!this.config.contextConfigId) {
|
|
8811
8919
|
logger19.debug({ agentId: this.config.agentId }, "No context config found for agent");
|
|
@@ -8829,7 +8937,7 @@ var Agent = class {
|
|
|
8829
8937
|
const result = await this.contextResolver.resolve(contextConfig, {
|
|
8830
8938
|
triggerEvent: "invocation",
|
|
8831
8939
|
conversationId,
|
|
8832
|
-
headers:
|
|
8940
|
+
headers: headers2 || {},
|
|
8833
8941
|
tenantId: this.config.tenantId
|
|
8834
8942
|
});
|
|
8835
8943
|
const contextWithBuiltins = {
|
|
@@ -9931,6 +10039,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9931
10039
|
const [
|
|
9932
10040
|
internalRelations,
|
|
9933
10041
|
externalRelations,
|
|
10042
|
+
teamRelations,
|
|
9934
10043
|
toolsForAgent,
|
|
9935
10044
|
dataComponents,
|
|
9936
10045
|
artifactComponents
|
|
@@ -9951,6 +10060,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9951
10060
|
subAgentId: config.subAgentId
|
|
9952
10061
|
}
|
|
9953
10062
|
}),
|
|
10063
|
+
agentsCore.getTeamAgentsForSubAgent(dbClient_default)({
|
|
10064
|
+
scopes: {
|
|
10065
|
+
tenantId: config.tenantId,
|
|
10066
|
+
projectId: config.projectId,
|
|
10067
|
+
agentId: config.agentId,
|
|
10068
|
+
subAgentId: config.subAgentId
|
|
10069
|
+
}
|
|
10070
|
+
}),
|
|
9954
10071
|
agentsCore.getToolsForAgent(dbClient_default)({
|
|
9955
10072
|
scopes: {
|
|
9956
10073
|
tenantId: config.tenantId,
|
|
@@ -10099,6 +10216,17 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10099
10216
|
relationId: relation.id,
|
|
10100
10217
|
relationType: "delegate"
|
|
10101
10218
|
}
|
|
10219
|
+
})),
|
|
10220
|
+
...teamRelations.data.map((relation) => ({
|
|
10221
|
+
type: "team",
|
|
10222
|
+
config: {
|
|
10223
|
+
id: relation.targetAgent.id,
|
|
10224
|
+
name: relation.targetAgent.name,
|
|
10225
|
+
description: relation.targetAgent.description || "",
|
|
10226
|
+
baseUrl: config.baseUrl,
|
|
10227
|
+
headers: relation.headers,
|
|
10228
|
+
relationId: relation.id
|
|
10229
|
+
}
|
|
10102
10230
|
}))
|
|
10103
10231
|
],
|
|
10104
10232
|
tools: toolsForAgentResult,
|
|
@@ -10320,7 +10448,9 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
10320
10448
|
};
|
|
10321
10449
|
|
|
10322
10450
|
// src/data/agents.ts
|
|
10451
|
+
init_logger();
|
|
10323
10452
|
init_dbClient();
|
|
10453
|
+
var logger21 = agentsCore.getLogger("agents");
|
|
10324
10454
|
function createAgentCard({
|
|
10325
10455
|
dbAgent,
|
|
10326
10456
|
baseUrl
|
|
@@ -10422,13 +10552,26 @@ async function hydrateAgent({
|
|
|
10422
10552
|
async function getRegisteredAgent(params) {
|
|
10423
10553
|
const { executionContext, credentialStoreRegistry, sandboxConfig } = params;
|
|
10424
10554
|
const { tenantId, projectId, agentId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
10555
|
+
let dbAgent;
|
|
10425
10556
|
if (!subAgentId) {
|
|
10426
|
-
|
|
10557
|
+
const agent = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
|
|
10558
|
+
scopes: { tenantId, projectId, agentId }
|
|
10559
|
+
});
|
|
10560
|
+
logger21.info({ agent }, "agent with default sub agent");
|
|
10561
|
+
if (!agent || !agent.defaultSubAgent) {
|
|
10562
|
+
return null;
|
|
10563
|
+
}
|
|
10564
|
+
dbAgent = agent.defaultSubAgent;
|
|
10565
|
+
} else {
|
|
10566
|
+
const response = await agentsCore.getSubAgentById(dbClient_default)({
|
|
10567
|
+
scopes: { tenantId, projectId, agentId },
|
|
10568
|
+
subAgentId
|
|
10569
|
+
});
|
|
10570
|
+
if (!response) {
|
|
10571
|
+
return null;
|
|
10572
|
+
}
|
|
10573
|
+
dbAgent = response;
|
|
10427
10574
|
}
|
|
10428
|
-
const dbAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
10429
|
-
scopes: { tenantId, projectId, agentId },
|
|
10430
|
-
subAgentId
|
|
10431
|
-
});
|
|
10432
10575
|
if (!dbAgent) {
|
|
10433
10576
|
return null;
|
|
10434
10577
|
}
|
|
@@ -10447,7 +10590,7 @@ async function getRegisteredAgent(params) {
|
|
|
10447
10590
|
init_dbClient();
|
|
10448
10591
|
init_logger();
|
|
10449
10592
|
var app = new zodOpenapi.OpenAPIHono();
|
|
10450
|
-
var
|
|
10593
|
+
var logger22 = agentsCore.getLogger("agents");
|
|
10451
10594
|
app.openapi(
|
|
10452
10595
|
zodOpenapi.createRoute({
|
|
10453
10596
|
method: "get",
|
|
@@ -10485,7 +10628,7 @@ app.openapi(
|
|
|
10485
10628
|
tracestate: c.req.header("tracestate"),
|
|
10486
10629
|
baggage: c.req.header("baggage")
|
|
10487
10630
|
};
|
|
10488
|
-
|
|
10631
|
+
logger22.info(
|
|
10489
10632
|
{
|
|
10490
10633
|
otelHeaders,
|
|
10491
10634
|
path: c.req.path,
|
|
@@ -10495,56 +10638,32 @@ app.openapi(
|
|
|
10495
10638
|
);
|
|
10496
10639
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
10497
10640
|
const { tenantId, projectId, agentId, subAgentId } = executionContext;
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
10501
|
-
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
|
|
10511
|
-
|
|
10512
|
-
|
|
10513
|
-
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
message: "Agent not found"
|
|
10522
|
-
});
|
|
10523
|
-
}
|
|
10524
|
-
return c.json(agent.agentCard);
|
|
10525
|
-
} else {
|
|
10526
|
-
logger21.info(
|
|
10527
|
-
{
|
|
10528
|
-
message: "getRegisteredAgent (agent-level)",
|
|
10529
|
-
tenantId,
|
|
10530
|
-
projectId,
|
|
10531
|
-
agentId
|
|
10532
|
-
},
|
|
10533
|
-
"agent-level well-known agent.json"
|
|
10534
|
-
);
|
|
10535
|
-
const sandboxConfig = c.get("sandboxConfig");
|
|
10536
|
-
const agent = await getRegisteredAgent({
|
|
10537
|
-
executionContext,
|
|
10538
|
-
sandboxConfig
|
|
10641
|
+
logger22.info({ executionContext }, "executionContext");
|
|
10642
|
+
logger22.info(
|
|
10643
|
+
{
|
|
10644
|
+
message: "getRegisteredAgent (agent-level)",
|
|
10645
|
+
tenantId,
|
|
10646
|
+
projectId,
|
|
10647
|
+
agentId,
|
|
10648
|
+
subAgentId
|
|
10649
|
+
},
|
|
10650
|
+
"agent-level well-known agent.json"
|
|
10651
|
+
);
|
|
10652
|
+
const credentialStores = c.get("credentialStores");
|
|
10653
|
+
const sandboxConfig = c.get("sandboxConfig");
|
|
10654
|
+
const agent = await getRegisteredAgent({
|
|
10655
|
+
executionContext,
|
|
10656
|
+
credentialStoreRegistry: credentialStores,
|
|
10657
|
+
sandboxConfig
|
|
10658
|
+
});
|
|
10659
|
+
logger22.info({ agent }, "agent registered: well-known agent.json");
|
|
10660
|
+
if (!agent) {
|
|
10661
|
+
throw agentsCore.createApiError({
|
|
10662
|
+
code: "not_found",
|
|
10663
|
+
message: "Agent not found"
|
|
10539
10664
|
});
|
|
10540
|
-
if (!agent) {
|
|
10541
|
-
throw agentsCore.createApiError({
|
|
10542
|
-
code: "not_found",
|
|
10543
|
-
message: "Agent not found"
|
|
10544
|
-
});
|
|
10545
|
-
}
|
|
10546
|
-
return c.json(agent.agentCard);
|
|
10547
10665
|
}
|
|
10666
|
+
return c.json(agent.agentCard);
|
|
10548
10667
|
}
|
|
10549
10668
|
);
|
|
10550
10669
|
app.post("/a2a", async (c) => {
|
|
@@ -10553,7 +10672,7 @@ app.post("/a2a", async (c) => {
|
|
|
10553
10672
|
tracestate: c.req.header("tracestate"),
|
|
10554
10673
|
baggage: c.req.header("baggage")
|
|
10555
10674
|
};
|
|
10556
|
-
|
|
10675
|
+
logger22.info(
|
|
10557
10676
|
{
|
|
10558
10677
|
otelHeaders,
|
|
10559
10678
|
path: c.req.path,
|
|
@@ -10564,7 +10683,7 @@ app.post("/a2a", async (c) => {
|
|
|
10564
10683
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
10565
10684
|
const { tenantId, projectId, agentId, subAgentId } = executionContext;
|
|
10566
10685
|
if (subAgentId) {
|
|
10567
|
-
|
|
10686
|
+
logger22.info(
|
|
10568
10687
|
{
|
|
10569
10688
|
message: "a2a (agent-level)",
|
|
10570
10689
|
tenantId,
|
|
@@ -10593,7 +10712,7 @@ app.post("/a2a", async (c) => {
|
|
|
10593
10712
|
}
|
|
10594
10713
|
return a2aHandler(c, agent);
|
|
10595
10714
|
} else {
|
|
10596
|
-
|
|
10715
|
+
logger22.info(
|
|
10597
10716
|
{
|
|
10598
10717
|
message: "a2a (agent-level)",
|
|
10599
10718
|
tenantId,
|
|
@@ -10703,14 +10822,14 @@ function extractTransferData(task) {
|
|
|
10703
10822
|
}
|
|
10704
10823
|
|
|
10705
10824
|
// src/a2a/transfer.ts
|
|
10706
|
-
var
|
|
10825
|
+
var logger23 = agentsCore.getLogger("Transfer");
|
|
10707
10826
|
async function executeTransfer({
|
|
10708
10827
|
tenantId,
|
|
10709
10828
|
threadId,
|
|
10710
10829
|
projectId,
|
|
10711
10830
|
targetSubAgentId
|
|
10712
10831
|
}) {
|
|
10713
|
-
|
|
10832
|
+
logger23.info(
|
|
10714
10833
|
{
|
|
10715
10834
|
targetAgent: targetSubAgentId,
|
|
10716
10835
|
threadId,
|
|
@@ -10725,12 +10844,12 @@ async function executeTransfer({
|
|
|
10725
10844
|
threadId,
|
|
10726
10845
|
subAgentId: targetSubAgentId
|
|
10727
10846
|
});
|
|
10728
|
-
|
|
10847
|
+
logger23.info(
|
|
10729
10848
|
{ targetAgent: targetSubAgentId, threadId },
|
|
10730
10849
|
"Successfully updated active_sub_agent_id in database"
|
|
10731
10850
|
);
|
|
10732
10851
|
} catch (error) {
|
|
10733
|
-
|
|
10852
|
+
logger23.error(
|
|
10734
10853
|
{ error, targetAgent: targetSubAgentId, threadId },
|
|
10735
10854
|
"Failed to update active_sub_agent_id"
|
|
10736
10855
|
);
|
|
@@ -11305,7 +11424,7 @@ function createMCPStreamHelper() {
|
|
|
11305
11424
|
}
|
|
11306
11425
|
|
|
11307
11426
|
// src/handlers/executionHandler.ts
|
|
11308
|
-
var
|
|
11427
|
+
var logger24 = agentsCore.getLogger("ExecutionHandler");
|
|
11309
11428
|
var ExecutionHandler = class {
|
|
11310
11429
|
constructor() {
|
|
11311
11430
|
__publicField(this, "MAX_ERRORS", 3);
|
|
@@ -11340,7 +11459,7 @@ var ExecutionHandler = class {
|
|
|
11340
11459
|
if (emitOperations) {
|
|
11341
11460
|
agentSessionManager.enableEmitOperations(requestId2);
|
|
11342
11461
|
}
|
|
11343
|
-
|
|
11462
|
+
logger24.info(
|
|
11344
11463
|
{ sessionId: requestId2, agentId, conversationId, emitOperations },
|
|
11345
11464
|
"Created AgentSession for message execution"
|
|
11346
11465
|
);
|
|
@@ -11357,7 +11476,7 @@ var ExecutionHandler = class {
|
|
|
11357
11476
|
);
|
|
11358
11477
|
}
|
|
11359
11478
|
} catch (error) {
|
|
11360
|
-
|
|
11479
|
+
logger24.error(
|
|
11361
11480
|
{
|
|
11362
11481
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
11363
11482
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -11373,7 +11492,7 @@ var ExecutionHandler = class {
|
|
|
11373
11492
|
try {
|
|
11374
11493
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, agentId));
|
|
11375
11494
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
11376
|
-
|
|
11495
|
+
logger24.info(
|
|
11377
11496
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
11378
11497
|
"Attempting to create or reuse existing task"
|
|
11379
11498
|
);
|
|
@@ -11397,7 +11516,7 @@ var ExecutionHandler = class {
|
|
|
11397
11516
|
sub_agent_id: currentAgentId
|
|
11398
11517
|
}
|
|
11399
11518
|
});
|
|
11400
|
-
|
|
11519
|
+
logger24.info(
|
|
11401
11520
|
{
|
|
11402
11521
|
taskId,
|
|
11403
11522
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -11406,27 +11525,27 @@ var ExecutionHandler = class {
|
|
|
11406
11525
|
);
|
|
11407
11526
|
} catch (error) {
|
|
11408
11527
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
11409
|
-
|
|
11528
|
+
logger24.info(
|
|
11410
11529
|
{ taskId, error: error.message },
|
|
11411
11530
|
"Task already exists, fetching existing task"
|
|
11412
11531
|
);
|
|
11413
11532
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
11414
11533
|
if (existingTask) {
|
|
11415
11534
|
task = existingTask;
|
|
11416
|
-
|
|
11535
|
+
logger24.info(
|
|
11417
11536
|
{ taskId, existingTask },
|
|
11418
11537
|
"Successfully reused existing task from race condition"
|
|
11419
11538
|
);
|
|
11420
11539
|
} else {
|
|
11421
|
-
|
|
11540
|
+
logger24.error({ taskId, error }, "Task constraint failed but task not found");
|
|
11422
11541
|
throw error;
|
|
11423
11542
|
}
|
|
11424
11543
|
} else {
|
|
11425
|
-
|
|
11544
|
+
logger24.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
11426
11545
|
throw error;
|
|
11427
11546
|
}
|
|
11428
11547
|
}
|
|
11429
|
-
|
|
11548
|
+
logger24.debug(
|
|
11430
11549
|
{
|
|
11431
11550
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
11432
11551
|
executionType: "create_initial_task",
|
|
@@ -11445,7 +11564,7 @@ var ExecutionHandler = class {
|
|
|
11445
11564
|
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? 10;
|
|
11446
11565
|
while (iterations < maxTransfers) {
|
|
11447
11566
|
iterations++;
|
|
11448
|
-
|
|
11567
|
+
logger24.info(
|
|
11449
11568
|
{ iterations, currentAgentId, agentId, conversationId, fromSubAgentId },
|
|
11450
11569
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromSubAgentId || "none"}`
|
|
11451
11570
|
);
|
|
@@ -11453,10 +11572,10 @@ var ExecutionHandler = class {
|
|
|
11453
11572
|
scopes: { tenantId, projectId },
|
|
11454
11573
|
conversationId
|
|
11455
11574
|
});
|
|
11456
|
-
|
|
11575
|
+
logger24.info({ activeAgent }, "activeAgent");
|
|
11457
11576
|
if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
|
|
11458
11577
|
currentAgentId = activeAgent.activeSubAgentId;
|
|
11459
|
-
|
|
11578
|
+
logger24.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
11460
11579
|
}
|
|
11461
11580
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
11462
11581
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -11497,13 +11616,13 @@ var ExecutionHandler = class {
|
|
|
11497
11616
|
});
|
|
11498
11617
|
if (!messageResponse?.result) {
|
|
11499
11618
|
errorCount++;
|
|
11500
|
-
|
|
11619
|
+
logger24.error(
|
|
11501
11620
|
{ currentAgentId, iterations, errorCount },
|
|
11502
11621
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
11503
11622
|
);
|
|
11504
11623
|
if (errorCount >= this.MAX_ERRORS) {
|
|
11505
11624
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
11506
|
-
|
|
11625
|
+
logger24.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
11507
11626
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
11508
11627
|
if (task) {
|
|
11509
11628
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -11527,7 +11646,7 @@ var ExecutionHandler = class {
|
|
|
11527
11646
|
if (isTransferTask(messageResponse.result)) {
|
|
11528
11647
|
const transferData = extractTransferData(messageResponse.result);
|
|
11529
11648
|
if (!transferData) {
|
|
11530
|
-
|
|
11649
|
+
logger24.error(
|
|
11531
11650
|
{ result: messageResponse.result },
|
|
11532
11651
|
"Transfer detected but no transfer data found"
|
|
11533
11652
|
);
|
|
@@ -11536,7 +11655,7 @@ var ExecutionHandler = class {
|
|
|
11536
11655
|
const { targetSubAgentId, fromSubAgentId: transferFromAgent } = transferData;
|
|
11537
11656
|
const firstArtifact = messageResponse.result.artifacts[0];
|
|
11538
11657
|
const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
|
|
11539
|
-
|
|
11658
|
+
logger24.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
|
|
11540
11659
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
11541
11660
|
const { success, targetSubAgentId: newAgentId } = await executeTransfer({
|
|
11542
11661
|
projectId,
|
|
@@ -11547,7 +11666,7 @@ var ExecutionHandler = class {
|
|
|
11547
11666
|
if (success) {
|
|
11548
11667
|
fromSubAgentId = currentAgentId;
|
|
11549
11668
|
currentAgentId = newAgentId;
|
|
11550
|
-
|
|
11669
|
+
logger24.info(
|
|
11551
11670
|
{
|
|
11552
11671
|
transferFrom: fromSubAgentId,
|
|
11553
11672
|
transferTo: currentAgentId,
|
|
@@ -11561,7 +11680,7 @@ var ExecutionHandler = class {
|
|
|
11561
11680
|
let responseParts = [];
|
|
11562
11681
|
if (messageResponse.result.streamedContent?.parts) {
|
|
11563
11682
|
responseParts = messageResponse.result.streamedContent.parts;
|
|
11564
|
-
|
|
11683
|
+
logger24.info(
|
|
11565
11684
|
{ partsCount: responseParts.length },
|
|
11566
11685
|
"Using streamed content for conversation history"
|
|
11567
11686
|
);
|
|
@@ -11569,7 +11688,7 @@ var ExecutionHandler = class {
|
|
|
11569
11688
|
responseParts = messageResponse.result.artifacts?.flatMap(
|
|
11570
11689
|
(artifact) => artifact.parts || []
|
|
11571
11690
|
) || [];
|
|
11572
|
-
|
|
11691
|
+
logger24.info(
|
|
11573
11692
|
{ partsCount: responseParts.length },
|
|
11574
11693
|
"Using artifacts for conversation history (fallback)"
|
|
11575
11694
|
);
|
|
@@ -11578,7 +11697,7 @@ var ExecutionHandler = class {
|
|
|
11578
11697
|
const agentSessionData = agentSessionManager.getSession(requestId2);
|
|
11579
11698
|
if (agentSessionData) {
|
|
11580
11699
|
const sessionSummary = agentSessionData.getSummary();
|
|
11581
|
-
|
|
11700
|
+
logger24.info(sessionSummary, "AgentSession data after completion");
|
|
11582
11701
|
}
|
|
11583
11702
|
let textContent = "";
|
|
11584
11703
|
for (const part of responseParts) {
|
|
@@ -11631,22 +11750,22 @@ var ExecutionHandler = class {
|
|
|
11631
11750
|
}
|
|
11632
11751
|
});
|
|
11633
11752
|
const updateTaskEnd = Date.now();
|
|
11634
|
-
|
|
11753
|
+
logger24.info(
|
|
11635
11754
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
11636
11755
|
"Completed updateTask operation"
|
|
11637
11756
|
);
|
|
11638
11757
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
11639
11758
|
await sseHelper.complete();
|
|
11640
|
-
|
|
11759
|
+
logger24.info({}, "Ending AgentSession and cleaning up");
|
|
11641
11760
|
agentSessionManager.endSession(requestId2);
|
|
11642
|
-
|
|
11761
|
+
logger24.info({}, "Cleaning up streamHelper");
|
|
11643
11762
|
unregisterStreamHelper(requestId2);
|
|
11644
11763
|
let response;
|
|
11645
11764
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
11646
11765
|
const captured = sseHelper.getCapturedResponse();
|
|
11647
11766
|
response = captured.text || "No response content";
|
|
11648
11767
|
}
|
|
11649
|
-
|
|
11768
|
+
logger24.info({}, "ExecutionHandler returning success");
|
|
11650
11769
|
return { success: true, iterations, response };
|
|
11651
11770
|
} catch (error) {
|
|
11652
11771
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -11657,13 +11776,13 @@ var ExecutionHandler = class {
|
|
|
11657
11776
|
});
|
|
11658
11777
|
}
|
|
11659
11778
|
errorCount++;
|
|
11660
|
-
|
|
11779
|
+
logger24.warn(
|
|
11661
11780
|
{ iterations, errorCount },
|
|
11662
11781
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
11663
11782
|
);
|
|
11664
11783
|
if (errorCount >= this.MAX_ERRORS) {
|
|
11665
11784
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
11666
|
-
|
|
11785
|
+
logger24.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
11667
11786
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
11668
11787
|
if (task) {
|
|
11669
11788
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -11684,7 +11803,7 @@ var ExecutionHandler = class {
|
|
|
11684
11803
|
}
|
|
11685
11804
|
}
|
|
11686
11805
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
11687
|
-
|
|
11806
|
+
logger24.error({ maxTransfers, iterations }, errorMessage);
|
|
11688
11807
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
11689
11808
|
if (task) {
|
|
11690
11809
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -11703,7 +11822,7 @@ var ExecutionHandler = class {
|
|
|
11703
11822
|
unregisterStreamHelper(requestId2);
|
|
11704
11823
|
return { success: false, error: errorMessage, iterations };
|
|
11705
11824
|
} catch (error) {
|
|
11706
|
-
|
|
11825
|
+
logger24.error({ error }, "Error in execution handler");
|
|
11707
11826
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
11708
11827
|
await sseHelper.writeOperation(
|
|
11709
11828
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -11731,7 +11850,7 @@ var ExecutionHandler = class {
|
|
|
11731
11850
|
// src/routes/chat.ts
|
|
11732
11851
|
init_logger();
|
|
11733
11852
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
11734
|
-
var
|
|
11853
|
+
var logger25 = agentsCore.getLogger("completionsHandler");
|
|
11735
11854
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
11736
11855
|
method: "post",
|
|
11737
11856
|
path: "/completions",
|
|
@@ -11849,7 +11968,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11849
11968
|
tracestate: c.req.header("tracestate"),
|
|
11850
11969
|
baggage: c.req.header("baggage")
|
|
11851
11970
|
};
|
|
11852
|
-
|
|
11971
|
+
logger25.info(
|
|
11853
11972
|
{
|
|
11854
11973
|
otelHeaders,
|
|
11855
11974
|
path: c.req.path,
|
|
@@ -11958,7 +12077,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11958
12077
|
dbClient: dbClient_default,
|
|
11959
12078
|
credentialStores
|
|
11960
12079
|
});
|
|
11961
|
-
|
|
12080
|
+
logger25.info(
|
|
11962
12081
|
{
|
|
11963
12082
|
tenantId,
|
|
11964
12083
|
projectId,
|
|
@@ -12006,7 +12125,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
12006
12125
|
try {
|
|
12007
12126
|
const sseHelper = createSSEStreamHelper(stream3, requestId2, timestamp);
|
|
12008
12127
|
await sseHelper.writeRole();
|
|
12009
|
-
|
|
12128
|
+
logger25.info({ subAgentId }, "Starting execution");
|
|
12010
12129
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
12011
12130
|
const emitOperations = emitOperationsHeader === "true";
|
|
12012
12131
|
const executionHandler = new ExecutionHandler();
|
|
@@ -12019,7 +12138,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
12019
12138
|
sseHelper,
|
|
12020
12139
|
emitOperations
|
|
12021
12140
|
});
|
|
12022
|
-
|
|
12141
|
+
logger25.info(
|
|
12023
12142
|
{ result },
|
|
12024
12143
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
12025
12144
|
);
|
|
@@ -12033,7 +12152,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
12033
12152
|
}
|
|
12034
12153
|
await sseHelper.complete();
|
|
12035
12154
|
} catch (error) {
|
|
12036
|
-
|
|
12155
|
+
logger25.error(
|
|
12037
12156
|
{
|
|
12038
12157
|
error: error instanceof Error ? error.message : error,
|
|
12039
12158
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -12050,13 +12169,13 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
12050
12169
|
);
|
|
12051
12170
|
await sseHelper.complete();
|
|
12052
12171
|
} catch (streamError) {
|
|
12053
|
-
|
|
12172
|
+
logger25.error({ streamError }, "Failed to write error to stream");
|
|
12054
12173
|
}
|
|
12055
12174
|
}
|
|
12056
12175
|
});
|
|
12057
12176
|
});
|
|
12058
12177
|
} catch (error) {
|
|
12059
|
-
|
|
12178
|
+
logger25.error(
|
|
12060
12179
|
{
|
|
12061
12180
|
error: error instanceof Error ? error.message : error,
|
|
12062
12181
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -12084,7 +12203,7 @@ var chat_default = app2;
|
|
|
12084
12203
|
init_dbClient();
|
|
12085
12204
|
init_logger();
|
|
12086
12205
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
12087
|
-
var
|
|
12206
|
+
var logger26 = agentsCore.getLogger("chatDataStream");
|
|
12088
12207
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
12089
12208
|
method: "post",
|
|
12090
12209
|
path: "/chat",
|
|
@@ -12208,7 +12327,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
12208
12327
|
});
|
|
12209
12328
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
12210
12329
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
12211
|
-
|
|
12330
|
+
logger26.info({ userText, lastUserMessage }, "userText");
|
|
12212
12331
|
const messageSpan = api.trace.getActiveSpan();
|
|
12213
12332
|
if (messageSpan) {
|
|
12214
12333
|
messageSpan.setAttributes({
|
|
@@ -12253,7 +12372,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
12253
12372
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
12254
12373
|
}
|
|
12255
12374
|
} catch (err) {
|
|
12256
|
-
|
|
12375
|
+
logger26.error({ err }, "Streaming error");
|
|
12257
12376
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
12258
12377
|
} finally {
|
|
12259
12378
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -12275,7 +12394,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
12275
12394
|
);
|
|
12276
12395
|
});
|
|
12277
12396
|
} catch (error) {
|
|
12278
|
-
|
|
12397
|
+
logger26.error({ error }, "chatDataStream error");
|
|
12279
12398
|
throw agentsCore.createApiError({
|
|
12280
12399
|
code: "internal_server_error",
|
|
12281
12400
|
message: "Failed to process chat completion"
|
|
@@ -12285,7 +12404,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
12285
12404
|
var chatDataStream_default = app3;
|
|
12286
12405
|
init_dbClient();
|
|
12287
12406
|
init_logger();
|
|
12288
|
-
var
|
|
12407
|
+
var logger27 = agentsCore.getLogger("dataComponentPreview");
|
|
12289
12408
|
var app4 = new zodOpenapi.OpenAPIHono();
|
|
12290
12409
|
var generatePreviewRoute = zodOpenapi.createRoute({
|
|
12291
12410
|
method: "post",
|
|
@@ -12331,7 +12450,7 @@ app4.openapi(generatePreviewRoute, async (c) => {
|
|
|
12331
12450
|
const { tenantId, projectId, id } = c.req.valid("param");
|
|
12332
12451
|
const body = c.req.valid("json");
|
|
12333
12452
|
const { instructions, existingCode } = body;
|
|
12334
|
-
|
|
12453
|
+
logger27.info(
|
|
12335
12454
|
{
|
|
12336
12455
|
tenantId,
|
|
12337
12456
|
projectId,
|
|
@@ -12384,7 +12503,7 @@ app4.openapi(generatePreviewRoute, async (c) => {
|
|
|
12384
12503
|
await stream3.write(JSON.stringify(outputObject) + "\n");
|
|
12385
12504
|
}
|
|
12386
12505
|
} catch (error) {
|
|
12387
|
-
|
|
12506
|
+
logger27.error(
|
|
12388
12507
|
{ error, tenantId, projectId, dataComponentId: id },
|
|
12389
12508
|
"Error streaming preview generation"
|
|
12390
12509
|
);
|
|
@@ -12394,7 +12513,7 @@ app4.openapi(generatePreviewRoute, async (c) => {
|
|
|
12394
12513
|
}
|
|
12395
12514
|
});
|
|
12396
12515
|
} catch (error) {
|
|
12397
|
-
|
|
12516
|
+
logger27.error(
|
|
12398
12517
|
{ error, tenantId, projectId, dataComponentId: id },
|
|
12399
12518
|
"Error generating component preview"
|
|
12400
12519
|
);
|
|
@@ -12531,7 +12650,7 @@ init_logger();
|
|
|
12531
12650
|
function createMCPSchema(schema) {
|
|
12532
12651
|
return schema;
|
|
12533
12652
|
}
|
|
12534
|
-
var
|
|
12653
|
+
var logger28 = agentsCore.getLogger("mcp");
|
|
12535
12654
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
12536
12655
|
constructor() {
|
|
12537
12656
|
__publicField(this, "mockRes");
|
|
@@ -12586,21 +12705,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
12586
12705
|
id: 0
|
|
12587
12706
|
});
|
|
12588
12707
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
12589
|
-
|
|
12708
|
+
logger28.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
12590
12709
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
12591
12710
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
12592
12711
|
try {
|
|
12593
12712
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
12594
|
-
|
|
12713
|
+
logger28.info({ sessionId }, "Successfully spoofed initialization");
|
|
12595
12714
|
} catch (spoofError) {
|
|
12596
|
-
|
|
12715
|
+
logger28.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
12597
12716
|
}
|
|
12598
12717
|
};
|
|
12599
12718
|
var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
12600
12719
|
const sessionId = req.headers["mcp-session-id"];
|
|
12601
|
-
|
|
12720
|
+
logger28.info({ sessionId }, "Received MCP session ID");
|
|
12602
12721
|
if (!sessionId) {
|
|
12603
|
-
|
|
12722
|
+
logger28.info({ body }, "Missing session ID");
|
|
12604
12723
|
res.writeHead(400).end(
|
|
12605
12724
|
JSON.stringify({
|
|
12606
12725
|
jsonrpc: "2.0",
|
|
@@ -12626,7 +12745,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
|
12626
12745
|
scopes: { tenantId, projectId },
|
|
12627
12746
|
conversationId: sessionId
|
|
12628
12747
|
});
|
|
12629
|
-
|
|
12748
|
+
logger28.info(
|
|
12630
12749
|
{
|
|
12631
12750
|
sessionId,
|
|
12632
12751
|
conversationFound: !!conversation,
|
|
@@ -12637,7 +12756,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
|
12637
12756
|
"Conversation lookup result"
|
|
12638
12757
|
);
|
|
12639
12758
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.agentId !== agentId) {
|
|
12640
|
-
|
|
12759
|
+
logger28.info(
|
|
12641
12760
|
{ sessionId, conversationId: conversation?.id },
|
|
12642
12761
|
"MCP session not found or invalid"
|
|
12643
12762
|
);
|
|
@@ -12698,7 +12817,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
|
|
|
12698
12817
|
requestId: requestId2,
|
|
12699
12818
|
sseHelper: mcpStreamHelper
|
|
12700
12819
|
});
|
|
12701
|
-
|
|
12820
|
+
logger28.info(
|
|
12702
12821
|
{ result },
|
|
12703
12822
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
12704
12823
|
);
|
|
@@ -12722,7 +12841,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
|
|
|
12722
12841
|
]
|
|
12723
12842
|
};
|
|
12724
12843
|
};
|
|
12725
|
-
var getServer = async (
|
|
12844
|
+
var getServer = async (headers2, executionContext, conversationId, credentialStores) => {
|
|
12726
12845
|
const { tenantId, projectId, agentId } = executionContext;
|
|
12727
12846
|
setupTracing(conversationId, tenantId, agentId);
|
|
12728
12847
|
const agent = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
|
|
@@ -12778,18 +12897,18 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
12778
12897
|
projectId,
|
|
12779
12898
|
agentId,
|
|
12780
12899
|
conversationId,
|
|
12781
|
-
headers,
|
|
12900
|
+
headers: headers2,
|
|
12782
12901
|
dbClient: dbClient_default,
|
|
12783
12902
|
credentialStores
|
|
12784
12903
|
});
|
|
12785
|
-
|
|
12904
|
+
logger28.info(
|
|
12786
12905
|
{
|
|
12787
12906
|
tenantId,
|
|
12788
12907
|
projectId,
|
|
12789
12908
|
agentId,
|
|
12790
12909
|
conversationId,
|
|
12791
12910
|
hasContextConfig: !!agent.contextConfigId,
|
|
12792
|
-
hasHeaders: !!
|
|
12911
|
+
hasHeaders: !!headers2,
|
|
12793
12912
|
hasValidatedContext: !!resolvedContext
|
|
12794
12913
|
},
|
|
12795
12914
|
"parameters"
|
|
@@ -12844,7 +12963,7 @@ var validateRequestParameters = (c) => {
|
|
|
12844
12963
|
};
|
|
12845
12964
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
12846
12965
|
const { tenantId, projectId, agentId } = executionContext;
|
|
12847
|
-
|
|
12966
|
+
logger28.info({ body }, "Received initialization request");
|
|
12848
12967
|
const sessionId = agentsCore.getConversationId();
|
|
12849
12968
|
const activeSpan = api.trace.getActiveSpan();
|
|
12850
12969
|
if (activeSpan) {
|
|
@@ -12900,7 +13019,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
12900
13019
|
}
|
|
12901
13020
|
}
|
|
12902
13021
|
});
|
|
12903
|
-
|
|
13022
|
+
logger28.info(
|
|
12904
13023
|
{ sessionId, conversationId: conversation.id },
|
|
12905
13024
|
"Created MCP session as conversation"
|
|
12906
13025
|
);
|
|
@@ -12909,9 +13028,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
12909
13028
|
});
|
|
12910
13029
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
12911
13030
|
await server.connect(transport);
|
|
12912
|
-
|
|
13031
|
+
logger28.info({ sessionId }, "Server connected for initialization");
|
|
12913
13032
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
12914
|
-
|
|
13033
|
+
logger28.info(
|
|
12915
13034
|
{
|
|
12916
13035
|
sessionId,
|
|
12917
13036
|
bodyMethod: body?.method,
|
|
@@ -12920,7 +13039,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
12920
13039
|
"About to handle initialization request"
|
|
12921
13040
|
);
|
|
12922
13041
|
await transport.handleRequest(req, res, body);
|
|
12923
|
-
|
|
13042
|
+
logger28.info({ sessionId }, "Successfully handled initialization request");
|
|
12924
13043
|
return fetchToNode.toFetchResponse(res);
|
|
12925
13044
|
});
|
|
12926
13045
|
};
|
|
@@ -12947,8 +13066,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
12947
13066
|
sessionId,
|
|
12948
13067
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
12949
13068
|
);
|
|
12950
|
-
|
|
12951
|
-
|
|
13069
|
+
logger28.info({ sessionId }, "Server connected and transport initialized");
|
|
13070
|
+
logger28.info(
|
|
12952
13071
|
{
|
|
12953
13072
|
sessionId,
|
|
12954
13073
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -12962,9 +13081,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
12962
13081
|
);
|
|
12963
13082
|
try {
|
|
12964
13083
|
await transport.handleRequest(req, res, body);
|
|
12965
|
-
|
|
13084
|
+
logger28.info({ sessionId }, "Successfully handled MCP request");
|
|
12966
13085
|
} catch (transportError) {
|
|
12967
|
-
|
|
13086
|
+
logger28.error(
|
|
12968
13087
|
{
|
|
12969
13088
|
sessionId,
|
|
12970
13089
|
error: transportError,
|
|
@@ -13015,13 +13134,13 @@ app5.openapi(
|
|
|
13015
13134
|
}
|
|
13016
13135
|
const { executionContext } = paramValidation;
|
|
13017
13136
|
const body = c.get("requestBody") || {};
|
|
13018
|
-
|
|
13137
|
+
logger28.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
13019
13138
|
const isInitRequest = body.method === "initialize";
|
|
13020
13139
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
13021
13140
|
const validatedContext = c.get("validatedContext") || {};
|
|
13022
13141
|
const credentialStores = c.get("credentialStores");
|
|
13023
|
-
|
|
13024
|
-
|
|
13142
|
+
logger28.info({ validatedContext }, "Validated context");
|
|
13143
|
+
logger28.info({ req }, "request");
|
|
13025
13144
|
if (isInitRequest) {
|
|
13026
13145
|
return await handleInitializationRequest(
|
|
13027
13146
|
body,
|
|
@@ -13043,7 +13162,7 @@ app5.openapi(
|
|
|
13043
13162
|
);
|
|
13044
13163
|
}
|
|
13045
13164
|
} catch (e) {
|
|
13046
|
-
|
|
13165
|
+
logger28.error(
|
|
13047
13166
|
{
|
|
13048
13167
|
error: e instanceof Error ? e.message : e,
|
|
13049
13168
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -13055,7 +13174,7 @@ app5.openapi(
|
|
|
13055
13174
|
}
|
|
13056
13175
|
);
|
|
13057
13176
|
app5.get("/", async (c) => {
|
|
13058
|
-
|
|
13177
|
+
logger28.info({}, "Received GET MCP request");
|
|
13059
13178
|
return c.json(
|
|
13060
13179
|
{
|
|
13061
13180
|
jsonrpc: "2.0",
|
|
@@ -13069,7 +13188,7 @@ app5.get("/", async (c) => {
|
|
|
13069
13188
|
);
|
|
13070
13189
|
});
|
|
13071
13190
|
app5.delete("/", async (c) => {
|
|
13072
|
-
|
|
13191
|
+
logger28.info({}, "Received DELETE MCP request");
|
|
13073
13192
|
return c.json(
|
|
13074
13193
|
{
|
|
13075
13194
|
jsonrpc: "2.0",
|
|
@@ -13082,7 +13201,7 @@ app5.delete("/", async (c) => {
|
|
|
13082
13201
|
var mcp_default = app5;
|
|
13083
13202
|
|
|
13084
13203
|
// src/app.ts
|
|
13085
|
-
var
|
|
13204
|
+
var logger29 = agentsCore.getLogger("agents-run-api");
|
|
13086
13205
|
function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
13087
13206
|
const app7 = new zodOpenapi.OpenAPIHono();
|
|
13088
13207
|
app7.use("*", otel.otel());
|
|
@@ -13101,7 +13220,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13101
13220
|
const body = await c.req.json();
|
|
13102
13221
|
c.set("requestBody", body);
|
|
13103
13222
|
} catch (error) {
|
|
13104
|
-
|
|
13223
|
+
logger29.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
13105
13224
|
}
|
|
13106
13225
|
}
|
|
13107
13226
|
return next();
|
|
@@ -13152,8 +13271,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13152
13271
|
if (!isExpectedError) {
|
|
13153
13272
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
13154
13273
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
13155
|
-
if (
|
|
13156
|
-
|
|
13274
|
+
if (logger29) {
|
|
13275
|
+
logger29.error(
|
|
13157
13276
|
{
|
|
13158
13277
|
error: err,
|
|
13159
13278
|
message: errorMessage,
|
|
@@ -13165,8 +13284,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13165
13284
|
);
|
|
13166
13285
|
}
|
|
13167
13286
|
} else {
|
|
13168
|
-
if (
|
|
13169
|
-
|
|
13287
|
+
if (logger29) {
|
|
13288
|
+
logger29.error(
|
|
13170
13289
|
{
|
|
13171
13290
|
error: err,
|
|
13172
13291
|
path: c.req.path,
|
|
@@ -13183,8 +13302,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13183
13302
|
const response = err.getResponse();
|
|
13184
13303
|
return response;
|
|
13185
13304
|
} catch (responseError) {
|
|
13186
|
-
if (
|
|
13187
|
-
|
|
13305
|
+
if (logger29) {
|
|
13306
|
+
logger29.error({ error: responseError }, "Error while handling HTTPException response");
|
|
13188
13307
|
}
|
|
13189
13308
|
}
|
|
13190
13309
|
}
|
|
@@ -13218,7 +13337,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13218
13337
|
app7.use("*", async (c, next) => {
|
|
13219
13338
|
const executionContext = c.get("executionContext");
|
|
13220
13339
|
if (!executionContext) {
|
|
13221
|
-
|
|
13340
|
+
logger29.debug({}, "Empty execution context");
|
|
13222
13341
|
return next();
|
|
13223
13342
|
}
|
|
13224
13343
|
const { tenantId, projectId, agentId } = executionContext;
|
|
@@ -13227,7 +13346,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13227
13346
|
if (requestBody) {
|
|
13228
13347
|
conversationId = requestBody.conversationId;
|
|
13229
13348
|
if (!conversationId) {
|
|
13230
|
-
|
|
13349
|
+
logger29.debug({ requestBody }, "No conversation ID found in request body");
|
|
13231
13350
|
}
|
|
13232
13351
|
}
|
|
13233
13352
|
const entries = Object.fromEntries(
|
|
@@ -13242,7 +13361,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13242
13361
|
})
|
|
13243
13362
|
);
|
|
13244
13363
|
if (!Object.keys(entries).length) {
|
|
13245
|
-
|
|
13364
|
+
logger29.debug({}, "Empty entries for baggage");
|
|
13246
13365
|
return next();
|
|
13247
13366
|
}
|
|
13248
13367
|
const bag = Object.entries(entries).reduce(
|