@inkeep/agents-run-api 0.26.2 → 0.28.0
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 +520 -212
- package/dist/index.js +517 -211
- 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
|
},
|
|
@@ -2800,9 +2889,11 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2800
2889
|
const component = this.context.artifactComponents?.find((ac) => ac.name === request.type);
|
|
2801
2890
|
let summaryData = {};
|
|
2802
2891
|
let fullData = {};
|
|
2892
|
+
let previewSchema = null;
|
|
2893
|
+
let fullSchema = null;
|
|
2803
2894
|
if (component?.props) {
|
|
2804
|
-
|
|
2805
|
-
|
|
2895
|
+
previewSchema = extractPreviewFields(component.props);
|
|
2896
|
+
fullSchema = extractFullFields(component.props);
|
|
2806
2897
|
summaryData = this.extractPropsFromSchema(
|
|
2807
2898
|
selectedData,
|
|
2808
2899
|
previewSchema,
|
|
@@ -2825,6 +2916,15 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2825
2916
|
}
|
|
2826
2917
|
const cleanedSummaryData = this.cleanEscapedContent(summaryData);
|
|
2827
2918
|
const cleanedFullData = this.cleanEscapedContent(fullData);
|
|
2919
|
+
const schemaValidation = this.validateExtractedData(
|
|
2920
|
+
request.artifactId,
|
|
2921
|
+
request.type,
|
|
2922
|
+
cleanedSummaryData,
|
|
2923
|
+
cleanedFullData,
|
|
2924
|
+
previewSchema,
|
|
2925
|
+
fullSchema,
|
|
2926
|
+
component?.props
|
|
2927
|
+
);
|
|
2828
2928
|
const artifactData = {
|
|
2829
2929
|
artifactId: request.artifactId,
|
|
2830
2930
|
toolCallId: request.toolCallId,
|
|
@@ -2833,7 +2933,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2833
2933
|
type: request.type,
|
|
2834
2934
|
data: cleanedSummaryData
|
|
2835
2935
|
};
|
|
2836
|
-
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId);
|
|
2936
|
+
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId, schemaValidation);
|
|
2837
2937
|
await this.cacheArtifact(
|
|
2838
2938
|
request.artifactId,
|
|
2839
2939
|
request.toolCallId,
|
|
@@ -2943,32 +3043,183 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2943
3043
|
* Format raw artifact to standardized summary data format
|
|
2944
3044
|
*/
|
|
2945
3045
|
formatArtifactSummaryData(artifact, artifactId, toolCallId) {
|
|
3046
|
+
let data = artifact.parts?.[0]?.data?.summary;
|
|
3047
|
+
let dataSource = "parts[0].data.summary";
|
|
3048
|
+
if (!data || typeof data === "object" && Object.keys(data).length === 0) {
|
|
3049
|
+
data = artifact.parts?.[0]?.data;
|
|
3050
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
3051
|
+
dataSource = "parts[0].data (fallback)";
|
|
3052
|
+
logger7.debug(
|
|
3053
|
+
{ artifactId, toolCallId, dataSource },
|
|
3054
|
+
"Using fallback data source for artifact summary"
|
|
3055
|
+
);
|
|
3056
|
+
} else {
|
|
3057
|
+
data = artifact.data;
|
|
3058
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
3059
|
+
dataSource = "artifact.data (fallback)";
|
|
3060
|
+
logger7.debug(
|
|
3061
|
+
{ artifactId, toolCallId, dataSource },
|
|
3062
|
+
"Using fallback data source for artifact summary"
|
|
3063
|
+
);
|
|
3064
|
+
} else {
|
|
3065
|
+
data = {};
|
|
3066
|
+
dataSource = "empty (no data found)";
|
|
3067
|
+
logger7.warn(
|
|
3068
|
+
{
|
|
3069
|
+
artifactId,
|
|
3070
|
+
toolCallId,
|
|
3071
|
+
artifactStructure: {
|
|
3072
|
+
hasParts: !!artifact.parts,
|
|
3073
|
+
partsLength: artifact.parts?.length,
|
|
3074
|
+
hasPartsData: !!artifact.parts?.[0]?.data,
|
|
3075
|
+
hasPartsSummary: !!artifact.parts?.[0]?.data?.summary,
|
|
3076
|
+
hasArtifactData: !!artifact.data,
|
|
3077
|
+
artifactKeys: Object.keys(artifact || {})
|
|
3078
|
+
}
|
|
3079
|
+
},
|
|
3080
|
+
"No valid data found for artifact summary - using empty object"
|
|
3081
|
+
);
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
2946
3085
|
return {
|
|
2947
3086
|
artifactId,
|
|
2948
3087
|
toolCallId,
|
|
2949
3088
|
name: artifact.name || "Processing...",
|
|
2950
3089
|
description: artifact.description || "Name and description being generated...",
|
|
2951
3090
|
type: artifact.metadata?.artifactType || artifact.artifactType,
|
|
2952
|
-
data
|
|
3091
|
+
data
|
|
2953
3092
|
};
|
|
2954
3093
|
}
|
|
2955
3094
|
/**
|
|
2956
3095
|
* Format raw artifact to standardized full data format
|
|
2957
3096
|
*/
|
|
2958
3097
|
formatArtifactFullData(artifact, artifactId, toolCallId) {
|
|
3098
|
+
let data = artifact.parts?.[0]?.data?.full;
|
|
3099
|
+
let dataSource = "parts[0].data.full";
|
|
3100
|
+
if (!data || typeof data === "object" && Object.keys(data).length === 0) {
|
|
3101
|
+
data = artifact.parts?.[0]?.data;
|
|
3102
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
3103
|
+
dataSource = "parts[0].data (fallback)";
|
|
3104
|
+
logger7.debug(
|
|
3105
|
+
{ artifactId, toolCallId, dataSource },
|
|
3106
|
+
"Using fallback data source for artifact full data"
|
|
3107
|
+
);
|
|
3108
|
+
} else {
|
|
3109
|
+
data = artifact.data;
|
|
3110
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
3111
|
+
dataSource = "artifact.data (fallback)";
|
|
3112
|
+
logger7.debug(
|
|
3113
|
+
{ artifactId, toolCallId, dataSource },
|
|
3114
|
+
"Using fallback data source for artifact full data"
|
|
3115
|
+
);
|
|
3116
|
+
} else {
|
|
3117
|
+
data = {};
|
|
3118
|
+
dataSource = "empty (no data found)";
|
|
3119
|
+
logger7.warn(
|
|
3120
|
+
{
|
|
3121
|
+
artifactId,
|
|
3122
|
+
toolCallId,
|
|
3123
|
+
artifactStructure: {
|
|
3124
|
+
hasParts: !!artifact.parts,
|
|
3125
|
+
partsLength: artifact.parts?.length,
|
|
3126
|
+
hasPartsData: !!artifact.parts?.[0]?.data,
|
|
3127
|
+
hasPartsFull: !!artifact.parts?.[0]?.data?.full,
|
|
3128
|
+
hasArtifactData: !!artifact.data,
|
|
3129
|
+
artifactKeys: Object.keys(artifact || {})
|
|
3130
|
+
}
|
|
3131
|
+
},
|
|
3132
|
+
"No valid data found for artifact full data - using empty object"
|
|
3133
|
+
);
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
2959
3137
|
return {
|
|
2960
3138
|
artifactId,
|
|
2961
3139
|
toolCallId,
|
|
2962
3140
|
name: artifact.name || "Processing...",
|
|
2963
3141
|
description: artifact.description || "Name and description being generated...",
|
|
2964
3142
|
type: artifact.metadata?.artifactType || artifact.artifactType,
|
|
2965
|
-
data
|
|
3143
|
+
data
|
|
3144
|
+
};
|
|
3145
|
+
}
|
|
3146
|
+
/**
|
|
3147
|
+
* Validate extracted data against the schemas used for extraction
|
|
3148
|
+
*/
|
|
3149
|
+
validateExtractedData(artifactId, artifactType, summaryData, fullData, previewSchema, fullSchema, originalProps) {
|
|
3150
|
+
const validateAgainstSchema = (data, schema) => {
|
|
3151
|
+
const actualFields = Object.keys(data || {});
|
|
3152
|
+
const expectedFields = schema?.properties ? Object.keys(schema.properties) : [];
|
|
3153
|
+
const missingFields = expectedFields.filter((field) => !(field in (data || {})));
|
|
3154
|
+
const extraFields = actualFields.filter((field) => !expectedFields.includes(field));
|
|
3155
|
+
const requiredFields = schema?.required || [];
|
|
3156
|
+
const missingRequired = requiredFields.filter((field) => !(field in (data || {})));
|
|
3157
|
+
return {
|
|
3158
|
+
hasExpectedFields: missingFields.length === 0,
|
|
3159
|
+
missingFields,
|
|
3160
|
+
extraFields,
|
|
3161
|
+
expectedFields,
|
|
3162
|
+
actualFields,
|
|
3163
|
+
hasRequiredFields: missingRequired.length === 0,
|
|
3164
|
+
missingRequired
|
|
3165
|
+
};
|
|
3166
|
+
};
|
|
3167
|
+
const summaryValidation = validateAgainstSchema(summaryData, previewSchema);
|
|
3168
|
+
const fullValidation = validateAgainstSchema(fullData, fullSchema);
|
|
3169
|
+
if (!summaryValidation.hasRequiredFields) {
|
|
3170
|
+
const error = new Error(
|
|
3171
|
+
`Cannot save artifact: Missing required fields [${summaryValidation.missingRequired.join(", ")}] for '${artifactType}' schema. Required: [${summaryValidation.missingRequired.join(", ")}]. Found: [${summaryValidation.actualFields.join(", ")}]. Consider using a different artifact component type that matches your data structure.`
|
|
3172
|
+
);
|
|
3173
|
+
logger7.error(
|
|
3174
|
+
{
|
|
3175
|
+
artifactId,
|
|
3176
|
+
artifactType,
|
|
3177
|
+
requiredFields: summaryValidation.missingRequired,
|
|
3178
|
+
actualFields: summaryValidation.actualFields,
|
|
3179
|
+
schemaExpected: previewSchema?.properties ? Object.keys(previewSchema.properties) : []
|
|
3180
|
+
},
|
|
3181
|
+
"Blocking artifact save due to missing required fields"
|
|
3182
|
+
);
|
|
3183
|
+
throw error;
|
|
3184
|
+
}
|
|
3185
|
+
if (!summaryValidation.hasExpectedFields || summaryValidation.extraFields.length > 0) {
|
|
3186
|
+
logger7.warn(
|
|
3187
|
+
{
|
|
3188
|
+
artifactId,
|
|
3189
|
+
artifactType,
|
|
3190
|
+
dataType: "summary",
|
|
3191
|
+
expectedFields: summaryValidation.expectedFields,
|
|
3192
|
+
actualFields: summaryValidation.actualFields,
|
|
3193
|
+
missingFields: summaryValidation.missingFields,
|
|
3194
|
+
extraFields: summaryValidation.extraFields
|
|
3195
|
+
},
|
|
3196
|
+
"Summary data structure does not match preview schema"
|
|
3197
|
+
);
|
|
3198
|
+
}
|
|
3199
|
+
if (!fullValidation.hasExpectedFields || fullValidation.extraFields.length > 0) {
|
|
3200
|
+
logger7.warn(
|
|
3201
|
+
{
|
|
3202
|
+
artifactId,
|
|
3203
|
+
artifactType,
|
|
3204
|
+
dataType: "full",
|
|
3205
|
+
expectedFields: fullValidation.expectedFields,
|
|
3206
|
+
actualFields: fullValidation.actualFields,
|
|
3207
|
+
missingFields: fullValidation.missingFields,
|
|
3208
|
+
extraFields: fullValidation.extraFields
|
|
3209
|
+
},
|
|
3210
|
+
"Full data structure does not match full schema"
|
|
3211
|
+
);
|
|
3212
|
+
}
|
|
3213
|
+
return {
|
|
3214
|
+
summary: summaryValidation,
|
|
3215
|
+
full: fullValidation,
|
|
3216
|
+
schemaFound: !!originalProps
|
|
2966
3217
|
};
|
|
2967
3218
|
}
|
|
2968
3219
|
/**
|
|
2969
3220
|
* Persist artifact to database vian agent session
|
|
2970
3221
|
*/
|
|
2971
|
-
async persistArtifact(request, summaryData, fullData, subAgentId) {
|
|
3222
|
+
async persistArtifact(request, summaryData, fullData, subAgentId, schemaValidation) {
|
|
2972
3223
|
const effectiveAgentId = subAgentId || this.context.subAgentId;
|
|
2973
3224
|
if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
|
|
2974
3225
|
await agentSessionManager.recordEvent(
|
|
@@ -2990,6 +3241,11 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2990
3241
|
sessionId: this.context.sessionId,
|
|
2991
3242
|
artifactType: request.type
|
|
2992
3243
|
},
|
|
3244
|
+
schemaValidation: schemaValidation || {
|
|
3245
|
+
summary: { hasExpectedFields: true, missingFields: [], extraFields: [], expectedFields: [], actualFields: [], hasRequiredFields: true, missingRequired: [] },
|
|
3246
|
+
full: { hasExpectedFields: true, missingFields: [], extraFields: [], expectedFields: [], actualFields: [], hasRequiredFields: true, missingRequired: [] },
|
|
3247
|
+
schemaFound: false
|
|
3248
|
+
},
|
|
2993
3249
|
tenantId: this.context.tenantId,
|
|
2994
3250
|
projectId: this.context.projectId,
|
|
2995
3251
|
contextId: this.context.contextId,
|
|
@@ -4484,7 +4740,29 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
4484
4740
|
has_context_id: !!artifactData.contextId,
|
|
4485
4741
|
has_metadata: !!artifactData.metadata,
|
|
4486
4742
|
tool_call_id: artifactData.metadata?.toolCallId || "missing",
|
|
4487
|
-
pending_generation: !!artifactData.pendingGeneration
|
|
4743
|
+
pending_generation: !!artifactData.pendingGeneration,
|
|
4744
|
+
// Schema validation attributes
|
|
4745
|
+
"schema_validation.schema_found": artifactData.schemaValidation?.schemaFound || false,
|
|
4746
|
+
"schema_validation.summary.has_expected_fields": artifactData.schemaValidation?.summary?.hasExpectedFields || true,
|
|
4747
|
+
"schema_validation.summary.missing_fields_count": artifactData.schemaValidation?.summary?.missingFields?.length || 0,
|
|
4748
|
+
"schema_validation.summary.extra_fields_count": artifactData.schemaValidation?.summary?.extraFields?.length || 0,
|
|
4749
|
+
"schema_validation.summary.expected_fields": JSON.stringify(artifactData.schemaValidation?.summary?.expectedFields || []),
|
|
4750
|
+
"schema_validation.summary.actual_fields": JSON.stringify(artifactData.schemaValidation?.summary?.actualFields || []),
|
|
4751
|
+
"schema_validation.summary.missing_fields": JSON.stringify(artifactData.schemaValidation?.summary?.missingFields || []),
|
|
4752
|
+
"schema_validation.summary.extra_fields": JSON.stringify(artifactData.schemaValidation?.summary?.extraFields || []),
|
|
4753
|
+
"schema_validation.summary.has_required_fields": artifactData.schemaValidation?.summary?.hasRequiredFields || true,
|
|
4754
|
+
"schema_validation.summary.missing_required_count": artifactData.schemaValidation?.summary?.missingRequired?.length || 0,
|
|
4755
|
+
"schema_validation.summary.missing_required": JSON.stringify(artifactData.schemaValidation?.summary?.missingRequired || []),
|
|
4756
|
+
"schema_validation.full.has_expected_fields": artifactData.schemaValidation?.full?.hasExpectedFields || true,
|
|
4757
|
+
"schema_validation.full.missing_fields_count": artifactData.schemaValidation?.full?.missingFields?.length || 0,
|
|
4758
|
+
"schema_validation.full.extra_fields_count": artifactData.schemaValidation?.full?.extraFields?.length || 0,
|
|
4759
|
+
"schema_validation.full.expected_fields": JSON.stringify(artifactData.schemaValidation?.full?.expectedFields || []),
|
|
4760
|
+
"schema_validation.full.actual_fields": JSON.stringify(artifactData.schemaValidation?.full?.actualFields || []),
|
|
4761
|
+
"schema_validation.full.missing_fields": JSON.stringify(artifactData.schemaValidation?.full?.missingFields || []),
|
|
4762
|
+
"schema_validation.full.extra_fields": JSON.stringify(artifactData.schemaValidation?.full?.extraFields || []),
|
|
4763
|
+
"schema_validation.full.has_required_fields": artifactData.schemaValidation?.full?.hasRequiredFields || true,
|
|
4764
|
+
"schema_validation.full.missing_required_count": artifactData.schemaValidation?.full?.missingRequired?.length || 0,
|
|
4765
|
+
"schema_validation.full.missing_required": JSON.stringify(artifactData.schemaValidation?.full?.missingRequired || [])
|
|
4488
4766
|
}
|
|
4489
4767
|
},
|
|
4490
4768
|
async (span) => {
|
|
@@ -6715,8 +6993,10 @@ function createDelegateToAgentTool({
|
|
|
6715
6993
|
);
|
|
6716
6994
|
}
|
|
6717
6995
|
const isInternal = delegateConfig.type === "internal";
|
|
6996
|
+
const isExternal = delegateConfig.type === "external";
|
|
6997
|
+
const isTeam = delegateConfig.type === "team";
|
|
6718
6998
|
let resolvedHeaders = {};
|
|
6719
|
-
if (
|
|
6999
|
+
if (isExternal) {
|
|
6720
7000
|
if ((delegateConfig.config.credentialReferenceId || delegateConfig.config.headers) && credentialStoreRegistry) {
|
|
6721
7001
|
const contextResolver = new agentsCore.ContextResolver(
|
|
6722
7002
|
tenantId,
|
|
@@ -6754,6 +7034,23 @@ function createDelegateToAgentTool({
|
|
|
6754
7034
|
headers: delegateConfig.config.headers || void 0
|
|
6755
7035
|
});
|
|
6756
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
|
+
})}`;
|
|
6757
7054
|
} else {
|
|
6758
7055
|
resolvedHeaders = {
|
|
6759
7056
|
Authorization: `Bearer ${metadata.apiKey}`,
|
|
@@ -8616,7 +8913,7 @@ var Agent = class {
|
|
|
8616
8913
|
/**
|
|
8617
8914
|
* Get resolved context using ContextResolver - will return cached data or fetch fresh data as needed
|
|
8618
8915
|
*/
|
|
8619
|
-
async getResolvedContext(conversationId,
|
|
8916
|
+
async getResolvedContext(conversationId, headers2) {
|
|
8620
8917
|
try {
|
|
8621
8918
|
if (!this.config.contextConfigId) {
|
|
8622
8919
|
logger19.debug({ agentId: this.config.agentId }, "No context config found for agent");
|
|
@@ -8640,7 +8937,7 @@ var Agent = class {
|
|
|
8640
8937
|
const result = await this.contextResolver.resolve(contextConfig, {
|
|
8641
8938
|
triggerEvent: "invocation",
|
|
8642
8939
|
conversationId,
|
|
8643
|
-
headers:
|
|
8940
|
+
headers: headers2 || {},
|
|
8644
8941
|
tenantId: this.config.tenantId
|
|
8645
8942
|
});
|
|
8646
8943
|
const contextWithBuiltins = {
|
|
@@ -9742,6 +10039,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9742
10039
|
const [
|
|
9743
10040
|
internalRelations,
|
|
9744
10041
|
externalRelations,
|
|
10042
|
+
teamRelations,
|
|
9745
10043
|
toolsForAgent,
|
|
9746
10044
|
dataComponents,
|
|
9747
10045
|
artifactComponents
|
|
@@ -9762,6 +10060,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9762
10060
|
subAgentId: config.subAgentId
|
|
9763
10061
|
}
|
|
9764
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
|
+
}),
|
|
9765
10071
|
agentsCore.getToolsForAgent(dbClient_default)({
|
|
9766
10072
|
scopes: {
|
|
9767
10073
|
tenantId: config.tenantId,
|
|
@@ -9910,6 +10216,17 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9910
10216
|
relationId: relation.id,
|
|
9911
10217
|
relationType: "delegate"
|
|
9912
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
|
+
}
|
|
9913
10230
|
}))
|
|
9914
10231
|
],
|
|
9915
10232
|
tools: toolsForAgentResult,
|
|
@@ -10131,7 +10448,9 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
10131
10448
|
};
|
|
10132
10449
|
|
|
10133
10450
|
// src/data/agents.ts
|
|
10451
|
+
init_logger();
|
|
10134
10452
|
init_dbClient();
|
|
10453
|
+
var logger21 = agentsCore.getLogger("agents");
|
|
10135
10454
|
function createAgentCard({
|
|
10136
10455
|
dbAgent,
|
|
10137
10456
|
baseUrl
|
|
@@ -10233,13 +10552,26 @@ async function hydrateAgent({
|
|
|
10233
10552
|
async function getRegisteredAgent(params) {
|
|
10234
10553
|
const { executionContext, credentialStoreRegistry, sandboxConfig } = params;
|
|
10235
10554
|
const { tenantId, projectId, agentId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
10555
|
+
let dbAgent;
|
|
10236
10556
|
if (!subAgentId) {
|
|
10237
|
-
|
|
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;
|
|
10238
10574
|
}
|
|
10239
|
-
const dbAgent = await agentsCore.getSubAgentById(dbClient_default)({
|
|
10240
|
-
scopes: { tenantId, projectId, agentId },
|
|
10241
|
-
subAgentId
|
|
10242
|
-
});
|
|
10243
10575
|
if (!dbAgent) {
|
|
10244
10576
|
return null;
|
|
10245
10577
|
}
|
|
@@ -10258,7 +10590,7 @@ async function getRegisteredAgent(params) {
|
|
|
10258
10590
|
init_dbClient();
|
|
10259
10591
|
init_logger();
|
|
10260
10592
|
var app = new zodOpenapi.OpenAPIHono();
|
|
10261
|
-
var
|
|
10593
|
+
var logger22 = agentsCore.getLogger("agents");
|
|
10262
10594
|
app.openapi(
|
|
10263
10595
|
zodOpenapi.createRoute({
|
|
10264
10596
|
method: "get",
|
|
@@ -10296,7 +10628,7 @@ app.openapi(
|
|
|
10296
10628
|
tracestate: c.req.header("tracestate"),
|
|
10297
10629
|
baggage: c.req.header("baggage")
|
|
10298
10630
|
};
|
|
10299
|
-
|
|
10631
|
+
logger22.info(
|
|
10300
10632
|
{
|
|
10301
10633
|
otelHeaders,
|
|
10302
10634
|
path: c.req.path,
|
|
@@ -10306,56 +10638,32 @@ app.openapi(
|
|
|
10306
10638
|
);
|
|
10307
10639
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
10308
10640
|
const { tenantId, projectId, agentId, subAgentId } = executionContext;
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
message: "Agent not found"
|
|
10333
|
-
});
|
|
10334
|
-
}
|
|
10335
|
-
return c.json(agent.agentCard);
|
|
10336
|
-
} else {
|
|
10337
|
-
logger21.info(
|
|
10338
|
-
{
|
|
10339
|
-
message: "getRegisteredAgent (agent-level)",
|
|
10340
|
-
tenantId,
|
|
10341
|
-
projectId,
|
|
10342
|
-
agentId
|
|
10343
|
-
},
|
|
10344
|
-
"agent-level well-known agent.json"
|
|
10345
|
-
);
|
|
10346
|
-
const sandboxConfig = c.get("sandboxConfig");
|
|
10347
|
-
const agent = await getRegisteredAgent({
|
|
10348
|
-
executionContext,
|
|
10349
|
-
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"
|
|
10350
10664
|
});
|
|
10351
|
-
if (!agent) {
|
|
10352
|
-
throw agentsCore.createApiError({
|
|
10353
|
-
code: "not_found",
|
|
10354
|
-
message: "Agent not found"
|
|
10355
|
-
});
|
|
10356
|
-
}
|
|
10357
|
-
return c.json(agent.agentCard);
|
|
10358
10665
|
}
|
|
10666
|
+
return c.json(agent.agentCard);
|
|
10359
10667
|
}
|
|
10360
10668
|
);
|
|
10361
10669
|
app.post("/a2a", async (c) => {
|
|
@@ -10364,7 +10672,7 @@ app.post("/a2a", async (c) => {
|
|
|
10364
10672
|
tracestate: c.req.header("tracestate"),
|
|
10365
10673
|
baggage: c.req.header("baggage")
|
|
10366
10674
|
};
|
|
10367
|
-
|
|
10675
|
+
logger22.info(
|
|
10368
10676
|
{
|
|
10369
10677
|
otelHeaders,
|
|
10370
10678
|
path: c.req.path,
|
|
@@ -10375,7 +10683,7 @@ app.post("/a2a", async (c) => {
|
|
|
10375
10683
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
10376
10684
|
const { tenantId, projectId, agentId, subAgentId } = executionContext;
|
|
10377
10685
|
if (subAgentId) {
|
|
10378
|
-
|
|
10686
|
+
logger22.info(
|
|
10379
10687
|
{
|
|
10380
10688
|
message: "a2a (agent-level)",
|
|
10381
10689
|
tenantId,
|
|
@@ -10404,7 +10712,7 @@ app.post("/a2a", async (c) => {
|
|
|
10404
10712
|
}
|
|
10405
10713
|
return a2aHandler(c, agent);
|
|
10406
10714
|
} else {
|
|
10407
|
-
|
|
10715
|
+
logger22.info(
|
|
10408
10716
|
{
|
|
10409
10717
|
message: "a2a (agent-level)",
|
|
10410
10718
|
tenantId,
|
|
@@ -10514,14 +10822,14 @@ function extractTransferData(task) {
|
|
|
10514
10822
|
}
|
|
10515
10823
|
|
|
10516
10824
|
// src/a2a/transfer.ts
|
|
10517
|
-
var
|
|
10825
|
+
var logger23 = agentsCore.getLogger("Transfer");
|
|
10518
10826
|
async function executeTransfer({
|
|
10519
10827
|
tenantId,
|
|
10520
10828
|
threadId,
|
|
10521
10829
|
projectId,
|
|
10522
10830
|
targetSubAgentId
|
|
10523
10831
|
}) {
|
|
10524
|
-
|
|
10832
|
+
logger23.info(
|
|
10525
10833
|
{
|
|
10526
10834
|
targetAgent: targetSubAgentId,
|
|
10527
10835
|
threadId,
|
|
@@ -10536,12 +10844,12 @@ async function executeTransfer({
|
|
|
10536
10844
|
threadId,
|
|
10537
10845
|
subAgentId: targetSubAgentId
|
|
10538
10846
|
});
|
|
10539
|
-
|
|
10847
|
+
logger23.info(
|
|
10540
10848
|
{ targetAgent: targetSubAgentId, threadId },
|
|
10541
10849
|
"Successfully updated active_sub_agent_id in database"
|
|
10542
10850
|
);
|
|
10543
10851
|
} catch (error) {
|
|
10544
|
-
|
|
10852
|
+
logger23.error(
|
|
10545
10853
|
{ error, targetAgent: targetSubAgentId, threadId },
|
|
10546
10854
|
"Failed to update active_sub_agent_id"
|
|
10547
10855
|
);
|
|
@@ -11116,7 +11424,7 @@ function createMCPStreamHelper() {
|
|
|
11116
11424
|
}
|
|
11117
11425
|
|
|
11118
11426
|
// src/handlers/executionHandler.ts
|
|
11119
|
-
var
|
|
11427
|
+
var logger24 = agentsCore.getLogger("ExecutionHandler");
|
|
11120
11428
|
var ExecutionHandler = class {
|
|
11121
11429
|
constructor() {
|
|
11122
11430
|
__publicField(this, "MAX_ERRORS", 3);
|
|
@@ -11151,7 +11459,7 @@ var ExecutionHandler = class {
|
|
|
11151
11459
|
if (emitOperations) {
|
|
11152
11460
|
agentSessionManager.enableEmitOperations(requestId2);
|
|
11153
11461
|
}
|
|
11154
|
-
|
|
11462
|
+
logger24.info(
|
|
11155
11463
|
{ sessionId: requestId2, agentId, conversationId, emitOperations },
|
|
11156
11464
|
"Created AgentSession for message execution"
|
|
11157
11465
|
);
|
|
@@ -11168,7 +11476,7 @@ var ExecutionHandler = class {
|
|
|
11168
11476
|
);
|
|
11169
11477
|
}
|
|
11170
11478
|
} catch (error) {
|
|
11171
|
-
|
|
11479
|
+
logger24.error(
|
|
11172
11480
|
{
|
|
11173
11481
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
11174
11482
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -11184,7 +11492,7 @@ var ExecutionHandler = class {
|
|
|
11184
11492
|
try {
|
|
11185
11493
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, agentId));
|
|
11186
11494
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
11187
|
-
|
|
11495
|
+
logger24.info(
|
|
11188
11496
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
11189
11497
|
"Attempting to create or reuse existing task"
|
|
11190
11498
|
);
|
|
@@ -11208,7 +11516,7 @@ var ExecutionHandler = class {
|
|
|
11208
11516
|
sub_agent_id: currentAgentId
|
|
11209
11517
|
}
|
|
11210
11518
|
});
|
|
11211
|
-
|
|
11519
|
+
logger24.info(
|
|
11212
11520
|
{
|
|
11213
11521
|
taskId,
|
|
11214
11522
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -11217,27 +11525,27 @@ var ExecutionHandler = class {
|
|
|
11217
11525
|
);
|
|
11218
11526
|
} catch (error) {
|
|
11219
11527
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
11220
|
-
|
|
11528
|
+
logger24.info(
|
|
11221
11529
|
{ taskId, error: error.message },
|
|
11222
11530
|
"Task already exists, fetching existing task"
|
|
11223
11531
|
);
|
|
11224
11532
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
11225
11533
|
if (existingTask) {
|
|
11226
11534
|
task = existingTask;
|
|
11227
|
-
|
|
11535
|
+
logger24.info(
|
|
11228
11536
|
{ taskId, existingTask },
|
|
11229
11537
|
"Successfully reused existing task from race condition"
|
|
11230
11538
|
);
|
|
11231
11539
|
} else {
|
|
11232
|
-
|
|
11540
|
+
logger24.error({ taskId, error }, "Task constraint failed but task not found");
|
|
11233
11541
|
throw error;
|
|
11234
11542
|
}
|
|
11235
11543
|
} else {
|
|
11236
|
-
|
|
11544
|
+
logger24.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
11237
11545
|
throw error;
|
|
11238
11546
|
}
|
|
11239
11547
|
}
|
|
11240
|
-
|
|
11548
|
+
logger24.debug(
|
|
11241
11549
|
{
|
|
11242
11550
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
11243
11551
|
executionType: "create_initial_task",
|
|
@@ -11256,7 +11564,7 @@ var ExecutionHandler = class {
|
|
|
11256
11564
|
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? 10;
|
|
11257
11565
|
while (iterations < maxTransfers) {
|
|
11258
11566
|
iterations++;
|
|
11259
|
-
|
|
11567
|
+
logger24.info(
|
|
11260
11568
|
{ iterations, currentAgentId, agentId, conversationId, fromSubAgentId },
|
|
11261
11569
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromSubAgentId || "none"}`
|
|
11262
11570
|
);
|
|
@@ -11264,10 +11572,10 @@ var ExecutionHandler = class {
|
|
|
11264
11572
|
scopes: { tenantId, projectId },
|
|
11265
11573
|
conversationId
|
|
11266
11574
|
});
|
|
11267
|
-
|
|
11575
|
+
logger24.info({ activeAgent }, "activeAgent");
|
|
11268
11576
|
if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
|
|
11269
11577
|
currentAgentId = activeAgent.activeSubAgentId;
|
|
11270
|
-
|
|
11578
|
+
logger24.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
11271
11579
|
}
|
|
11272
11580
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
11273
11581
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -11308,13 +11616,13 @@ var ExecutionHandler = class {
|
|
|
11308
11616
|
});
|
|
11309
11617
|
if (!messageResponse?.result) {
|
|
11310
11618
|
errorCount++;
|
|
11311
|
-
|
|
11619
|
+
logger24.error(
|
|
11312
11620
|
{ currentAgentId, iterations, errorCount },
|
|
11313
11621
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
11314
11622
|
);
|
|
11315
11623
|
if (errorCount >= this.MAX_ERRORS) {
|
|
11316
11624
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
11317
|
-
|
|
11625
|
+
logger24.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
11318
11626
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
11319
11627
|
if (task) {
|
|
11320
11628
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -11338,7 +11646,7 @@ var ExecutionHandler = class {
|
|
|
11338
11646
|
if (isTransferTask(messageResponse.result)) {
|
|
11339
11647
|
const transferData = extractTransferData(messageResponse.result);
|
|
11340
11648
|
if (!transferData) {
|
|
11341
|
-
|
|
11649
|
+
logger24.error(
|
|
11342
11650
|
{ result: messageResponse.result },
|
|
11343
11651
|
"Transfer detected but no transfer data found"
|
|
11344
11652
|
);
|
|
@@ -11347,7 +11655,7 @@ var ExecutionHandler = class {
|
|
|
11347
11655
|
const { targetSubAgentId, fromSubAgentId: transferFromAgent } = transferData;
|
|
11348
11656
|
const firstArtifact = messageResponse.result.artifacts[0];
|
|
11349
11657
|
const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
|
|
11350
|
-
|
|
11658
|
+
logger24.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
|
|
11351
11659
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
11352
11660
|
const { success, targetSubAgentId: newAgentId } = await executeTransfer({
|
|
11353
11661
|
projectId,
|
|
@@ -11358,7 +11666,7 @@ var ExecutionHandler = class {
|
|
|
11358
11666
|
if (success) {
|
|
11359
11667
|
fromSubAgentId = currentAgentId;
|
|
11360
11668
|
currentAgentId = newAgentId;
|
|
11361
|
-
|
|
11669
|
+
logger24.info(
|
|
11362
11670
|
{
|
|
11363
11671
|
transferFrom: fromSubAgentId,
|
|
11364
11672
|
transferTo: currentAgentId,
|
|
@@ -11372,7 +11680,7 @@ var ExecutionHandler = class {
|
|
|
11372
11680
|
let responseParts = [];
|
|
11373
11681
|
if (messageResponse.result.streamedContent?.parts) {
|
|
11374
11682
|
responseParts = messageResponse.result.streamedContent.parts;
|
|
11375
|
-
|
|
11683
|
+
logger24.info(
|
|
11376
11684
|
{ partsCount: responseParts.length },
|
|
11377
11685
|
"Using streamed content for conversation history"
|
|
11378
11686
|
);
|
|
@@ -11380,7 +11688,7 @@ var ExecutionHandler = class {
|
|
|
11380
11688
|
responseParts = messageResponse.result.artifacts?.flatMap(
|
|
11381
11689
|
(artifact) => artifact.parts || []
|
|
11382
11690
|
) || [];
|
|
11383
|
-
|
|
11691
|
+
logger24.info(
|
|
11384
11692
|
{ partsCount: responseParts.length },
|
|
11385
11693
|
"Using artifacts for conversation history (fallback)"
|
|
11386
11694
|
);
|
|
@@ -11389,7 +11697,7 @@ var ExecutionHandler = class {
|
|
|
11389
11697
|
const agentSessionData = agentSessionManager.getSession(requestId2);
|
|
11390
11698
|
if (agentSessionData) {
|
|
11391
11699
|
const sessionSummary = agentSessionData.getSummary();
|
|
11392
|
-
|
|
11700
|
+
logger24.info(sessionSummary, "AgentSession data after completion");
|
|
11393
11701
|
}
|
|
11394
11702
|
let textContent = "";
|
|
11395
11703
|
for (const part of responseParts) {
|
|
@@ -11442,22 +11750,22 @@ var ExecutionHandler = class {
|
|
|
11442
11750
|
}
|
|
11443
11751
|
});
|
|
11444
11752
|
const updateTaskEnd = Date.now();
|
|
11445
|
-
|
|
11753
|
+
logger24.info(
|
|
11446
11754
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
11447
11755
|
"Completed updateTask operation"
|
|
11448
11756
|
);
|
|
11449
11757
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
11450
11758
|
await sseHelper.complete();
|
|
11451
|
-
|
|
11759
|
+
logger24.info({}, "Ending AgentSession and cleaning up");
|
|
11452
11760
|
agentSessionManager.endSession(requestId2);
|
|
11453
|
-
|
|
11761
|
+
logger24.info({}, "Cleaning up streamHelper");
|
|
11454
11762
|
unregisterStreamHelper(requestId2);
|
|
11455
11763
|
let response;
|
|
11456
11764
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
11457
11765
|
const captured = sseHelper.getCapturedResponse();
|
|
11458
11766
|
response = captured.text || "No response content";
|
|
11459
11767
|
}
|
|
11460
|
-
|
|
11768
|
+
logger24.info({}, "ExecutionHandler returning success");
|
|
11461
11769
|
return { success: true, iterations, response };
|
|
11462
11770
|
} catch (error) {
|
|
11463
11771
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -11468,13 +11776,13 @@ var ExecutionHandler = class {
|
|
|
11468
11776
|
});
|
|
11469
11777
|
}
|
|
11470
11778
|
errorCount++;
|
|
11471
|
-
|
|
11779
|
+
logger24.warn(
|
|
11472
11780
|
{ iterations, errorCount },
|
|
11473
11781
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
11474
11782
|
);
|
|
11475
11783
|
if (errorCount >= this.MAX_ERRORS) {
|
|
11476
11784
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
11477
|
-
|
|
11785
|
+
logger24.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
11478
11786
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
11479
11787
|
if (task) {
|
|
11480
11788
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -11495,7 +11803,7 @@ var ExecutionHandler = class {
|
|
|
11495
11803
|
}
|
|
11496
11804
|
}
|
|
11497
11805
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
11498
|
-
|
|
11806
|
+
logger24.error({ maxTransfers, iterations }, errorMessage);
|
|
11499
11807
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
11500
11808
|
if (task) {
|
|
11501
11809
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -11514,7 +11822,7 @@ var ExecutionHandler = class {
|
|
|
11514
11822
|
unregisterStreamHelper(requestId2);
|
|
11515
11823
|
return { success: false, error: errorMessage, iterations };
|
|
11516
11824
|
} catch (error) {
|
|
11517
|
-
|
|
11825
|
+
logger24.error({ error }, "Error in execution handler");
|
|
11518
11826
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
11519
11827
|
await sseHelper.writeOperation(
|
|
11520
11828
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -11542,7 +11850,7 @@ var ExecutionHandler = class {
|
|
|
11542
11850
|
// src/routes/chat.ts
|
|
11543
11851
|
init_logger();
|
|
11544
11852
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
11545
|
-
var
|
|
11853
|
+
var logger25 = agentsCore.getLogger("completionsHandler");
|
|
11546
11854
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
11547
11855
|
method: "post",
|
|
11548
11856
|
path: "/completions",
|
|
@@ -11660,7 +11968,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11660
11968
|
tracestate: c.req.header("tracestate"),
|
|
11661
11969
|
baggage: c.req.header("baggage")
|
|
11662
11970
|
};
|
|
11663
|
-
|
|
11971
|
+
logger25.info(
|
|
11664
11972
|
{
|
|
11665
11973
|
otelHeaders,
|
|
11666
11974
|
path: c.req.path,
|
|
@@ -11769,7 +12077,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11769
12077
|
dbClient: dbClient_default,
|
|
11770
12078
|
credentialStores
|
|
11771
12079
|
});
|
|
11772
|
-
|
|
12080
|
+
logger25.info(
|
|
11773
12081
|
{
|
|
11774
12082
|
tenantId,
|
|
11775
12083
|
projectId,
|
|
@@ -11817,7 +12125,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11817
12125
|
try {
|
|
11818
12126
|
const sseHelper = createSSEStreamHelper(stream3, requestId2, timestamp);
|
|
11819
12127
|
await sseHelper.writeRole();
|
|
11820
|
-
|
|
12128
|
+
logger25.info({ subAgentId }, "Starting execution");
|
|
11821
12129
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
11822
12130
|
const emitOperations = emitOperationsHeader === "true";
|
|
11823
12131
|
const executionHandler = new ExecutionHandler();
|
|
@@ -11830,7 +12138,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11830
12138
|
sseHelper,
|
|
11831
12139
|
emitOperations
|
|
11832
12140
|
});
|
|
11833
|
-
|
|
12141
|
+
logger25.info(
|
|
11834
12142
|
{ result },
|
|
11835
12143
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
11836
12144
|
);
|
|
@@ -11844,7 +12152,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11844
12152
|
}
|
|
11845
12153
|
await sseHelper.complete();
|
|
11846
12154
|
} catch (error) {
|
|
11847
|
-
|
|
12155
|
+
logger25.error(
|
|
11848
12156
|
{
|
|
11849
12157
|
error: error instanceof Error ? error.message : error,
|
|
11850
12158
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -11861,13 +12169,13 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11861
12169
|
);
|
|
11862
12170
|
await sseHelper.complete();
|
|
11863
12171
|
} catch (streamError) {
|
|
11864
|
-
|
|
12172
|
+
logger25.error({ streamError }, "Failed to write error to stream");
|
|
11865
12173
|
}
|
|
11866
12174
|
}
|
|
11867
12175
|
});
|
|
11868
12176
|
});
|
|
11869
12177
|
} catch (error) {
|
|
11870
|
-
|
|
12178
|
+
logger25.error(
|
|
11871
12179
|
{
|
|
11872
12180
|
error: error instanceof Error ? error.message : error,
|
|
11873
12181
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -11895,7 +12203,7 @@ var chat_default = app2;
|
|
|
11895
12203
|
init_dbClient();
|
|
11896
12204
|
init_logger();
|
|
11897
12205
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
11898
|
-
var
|
|
12206
|
+
var logger26 = agentsCore.getLogger("chatDataStream");
|
|
11899
12207
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
11900
12208
|
method: "post",
|
|
11901
12209
|
path: "/chat",
|
|
@@ -12019,7 +12327,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
12019
12327
|
});
|
|
12020
12328
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
12021
12329
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
12022
|
-
|
|
12330
|
+
logger26.info({ userText, lastUserMessage }, "userText");
|
|
12023
12331
|
const messageSpan = api.trace.getActiveSpan();
|
|
12024
12332
|
if (messageSpan) {
|
|
12025
12333
|
messageSpan.setAttributes({
|
|
@@ -12064,7 +12372,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
12064
12372
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
12065
12373
|
}
|
|
12066
12374
|
} catch (err) {
|
|
12067
|
-
|
|
12375
|
+
logger26.error({ err }, "Streaming error");
|
|
12068
12376
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
12069
12377
|
} finally {
|
|
12070
12378
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -12086,7 +12394,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
12086
12394
|
);
|
|
12087
12395
|
});
|
|
12088
12396
|
} catch (error) {
|
|
12089
|
-
|
|
12397
|
+
logger26.error({ error }, "chatDataStream error");
|
|
12090
12398
|
throw agentsCore.createApiError({
|
|
12091
12399
|
code: "internal_server_error",
|
|
12092
12400
|
message: "Failed to process chat completion"
|
|
@@ -12096,14 +12404,14 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
12096
12404
|
var chatDataStream_default = app3;
|
|
12097
12405
|
init_dbClient();
|
|
12098
12406
|
init_logger();
|
|
12099
|
-
var
|
|
12407
|
+
var logger27 = agentsCore.getLogger("dataComponentPreview");
|
|
12100
12408
|
var app4 = new zodOpenapi.OpenAPIHono();
|
|
12101
12409
|
var generatePreviewRoute = zodOpenapi.createRoute({
|
|
12102
12410
|
method: "post",
|
|
12103
|
-
path: "/:tenantId/projects/:projectId/data-components/:id/generate-
|
|
12411
|
+
path: "/:tenantId/projects/:projectId/data-components/:id/generate-render",
|
|
12104
12412
|
tags: ["Data Component Preview"],
|
|
12105
|
-
summary: "Generate Component
|
|
12106
|
-
description: "Generate a React/Tailwind component
|
|
12413
|
+
summary: "Generate Component Render",
|
|
12414
|
+
description: "Generate a React/Tailwind component render using AI based on the data component schema",
|
|
12107
12415
|
request: {
|
|
12108
12416
|
params: z6.z.object({
|
|
12109
12417
|
tenantId: z6.z.string(),
|
|
@@ -12142,7 +12450,7 @@ app4.openapi(generatePreviewRoute, async (c) => {
|
|
|
12142
12450
|
const { tenantId, projectId, id } = c.req.valid("param");
|
|
12143
12451
|
const body = c.req.valid("json");
|
|
12144
12452
|
const { instructions, existingCode } = body;
|
|
12145
|
-
|
|
12453
|
+
logger27.info(
|
|
12146
12454
|
{
|
|
12147
12455
|
tenantId,
|
|
12148
12456
|
projectId,
|
|
@@ -12174,38 +12482,38 @@ app4.openapi(generatePreviewRoute, async (c) => {
|
|
|
12174
12482
|
const prompt = buildGenerationPrompt(dataComponent, instructions, existingCode);
|
|
12175
12483
|
try {
|
|
12176
12484
|
const modelConfig = ModelFactory.prepareGenerationConfig(project.models.base);
|
|
12177
|
-
const
|
|
12178
|
-
|
|
12179
|
-
|
|
12485
|
+
const renderSchema = z6.z.object({
|
|
12486
|
+
component: z6.z.string().describe("The React component code"),
|
|
12487
|
+
mockData: z6.z.any().describe("Sample data matching the props schema")
|
|
12180
12488
|
});
|
|
12181
12489
|
const result = ai.streamObject({
|
|
12182
12490
|
...modelConfig,
|
|
12183
12491
|
prompt,
|
|
12184
|
-
schema:
|
|
12492
|
+
schema: renderSchema,
|
|
12185
12493
|
temperature: 0.7
|
|
12186
12494
|
});
|
|
12187
12495
|
c.header("Content-Type", "text/plain; charset=utf-8");
|
|
12188
12496
|
c.header("Cache-Control", "no-cache");
|
|
12189
12497
|
c.header("Connection", "keep-alive");
|
|
12190
|
-
const existingData = existingCode && dataComponent.
|
|
12498
|
+
const existingData = existingCode && dataComponent.render && typeof dataComponent.render === "object" && "mockData" in dataComponent.render ? dataComponent.render.mockData : null;
|
|
12191
12499
|
return streaming.stream(c, async (stream3) => {
|
|
12192
12500
|
try {
|
|
12193
12501
|
for await (const partialObject of result.partialObjectStream) {
|
|
12194
|
-
const outputObject = instructions && existingData ? { ...partialObject,
|
|
12502
|
+
const outputObject = instructions && existingData ? { ...partialObject, mockData: existingData } : partialObject;
|
|
12195
12503
|
await stream3.write(JSON.stringify(outputObject) + "\n");
|
|
12196
12504
|
}
|
|
12197
12505
|
} catch (error) {
|
|
12198
|
-
|
|
12506
|
+
logger27.error(
|
|
12199
12507
|
{ error, tenantId, projectId, dataComponentId: id },
|
|
12200
12508
|
"Error streaming preview generation"
|
|
12201
12509
|
);
|
|
12202
12510
|
await stream3.write(
|
|
12203
|
-
JSON.stringify({
|
|
12511
|
+
JSON.stringify({ component: "// Error generating component preview", mockData: {} }) + "\n"
|
|
12204
12512
|
);
|
|
12205
12513
|
}
|
|
12206
12514
|
});
|
|
12207
12515
|
} catch (error) {
|
|
12208
|
-
|
|
12516
|
+
logger27.error(
|
|
12209
12517
|
{ error, tenantId, projectId, dataComponentId: id },
|
|
12210
12518
|
"Error generating component preview"
|
|
12211
12519
|
);
|
|
@@ -12248,13 +12556,13 @@ REQUIREMENTS:
|
|
|
12248
12556
|
|
|
12249
12557
|
OUTPUT FORMAT:
|
|
12250
12558
|
You need to generate only one thing:
|
|
12251
|
-
1. "
|
|
12559
|
+
1. "component": The modified React component code as a string
|
|
12252
12560
|
|
|
12253
|
-
Return ONLY the
|
|
12561
|
+
Return ONLY the component field, the mockData field will be reused from the existing render.
|
|
12254
12562
|
|
|
12255
12563
|
EXAMPLE OUTPUT:
|
|
12256
12564
|
{
|
|
12257
|
-
"
|
|
12565
|
+
"component": "import { Mail, User } from 'lucide-react';\\n\\nfunction ${componentName}(props) {\\n // Modified component code here\\n}"
|
|
12258
12566
|
}
|
|
12259
12567
|
|
|
12260
12568
|
Focus on making the requested changes while maintaining the component's quality and design principles.`;
|
|
@@ -12308,13 +12616,13 @@ AVAILABLE SEMANTIC COLOR CLASSES:
|
|
|
12308
12616
|
|
|
12309
12617
|
OUTPUT FORMAT:
|
|
12310
12618
|
You need to generate two things:
|
|
12311
|
-
1. "
|
|
12312
|
-
2. "
|
|
12619
|
+
1. "component": The complete React component code as a string
|
|
12620
|
+
2. "mockData": Realistic sample data that matches the props schema (as a JSON object)
|
|
12313
12621
|
|
|
12314
12622
|
EXAMPLE OUTPUT (for a user profile schema with name, email, role):
|
|
12315
12623
|
{
|
|
12316
|
-
"
|
|
12317
|
-
"
|
|
12624
|
+
"component": "import { Mail, User } from 'lucide-react';\\n\\nfunction ${componentName}(props) {\\n return (\\n <div className=\\"p-4 rounded-lg border border-border bg-card\\">\\n <div className=\\"flex items-center gap-2.5 mb-2\\">\\n <User className=\\"size-4 text-muted-foreground\\" />\\n <span className=\\"text-base font-medium text-foreground\\">{props.name}</span>\\n </div>\\n <div className=\\"flex items-center gap-2 text-sm text-muted-foreground\\">\\n <Mail className=\\"size-4\\" />\\n <span>{props.email}</span>\\n </div>\\n <div className=\\"text-xs text-muted-foreground mt-2\\">Role: {props.role}</div>\\n </div>\\n );\\n}",
|
|
12625
|
+
"mockData": {
|
|
12318
12626
|
"name": "Sarah Chen",
|
|
12319
12627
|
"email": "sarah.chen@example.com",
|
|
12320
12628
|
"role": "Product Manager"
|
|
@@ -12342,7 +12650,7 @@ init_logger();
|
|
|
12342
12650
|
function createMCPSchema(schema) {
|
|
12343
12651
|
return schema;
|
|
12344
12652
|
}
|
|
12345
|
-
var
|
|
12653
|
+
var logger28 = agentsCore.getLogger("mcp");
|
|
12346
12654
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
12347
12655
|
constructor() {
|
|
12348
12656
|
__publicField(this, "mockRes");
|
|
@@ -12397,21 +12705,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
12397
12705
|
id: 0
|
|
12398
12706
|
});
|
|
12399
12707
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
12400
|
-
|
|
12708
|
+
logger28.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
12401
12709
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
12402
12710
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
12403
12711
|
try {
|
|
12404
12712
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
12405
|
-
|
|
12713
|
+
logger28.info({ sessionId }, "Successfully spoofed initialization");
|
|
12406
12714
|
} catch (spoofError) {
|
|
12407
|
-
|
|
12715
|
+
logger28.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
12408
12716
|
}
|
|
12409
12717
|
};
|
|
12410
12718
|
var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
12411
12719
|
const sessionId = req.headers["mcp-session-id"];
|
|
12412
|
-
|
|
12720
|
+
logger28.info({ sessionId }, "Received MCP session ID");
|
|
12413
12721
|
if (!sessionId) {
|
|
12414
|
-
|
|
12722
|
+
logger28.info({ body }, "Missing session ID");
|
|
12415
12723
|
res.writeHead(400).end(
|
|
12416
12724
|
JSON.stringify({
|
|
12417
12725
|
jsonrpc: "2.0",
|
|
@@ -12437,7 +12745,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
|
12437
12745
|
scopes: { tenantId, projectId },
|
|
12438
12746
|
conversationId: sessionId
|
|
12439
12747
|
});
|
|
12440
|
-
|
|
12748
|
+
logger28.info(
|
|
12441
12749
|
{
|
|
12442
12750
|
sessionId,
|
|
12443
12751
|
conversationFound: !!conversation,
|
|
@@ -12448,7 +12756,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
|
12448
12756
|
"Conversation lookup result"
|
|
12449
12757
|
);
|
|
12450
12758
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.agentId !== agentId) {
|
|
12451
|
-
|
|
12759
|
+
logger28.info(
|
|
12452
12760
|
{ sessionId, conversationId: conversation?.id },
|
|
12453
12761
|
"MCP session not found or invalid"
|
|
12454
12762
|
);
|
|
@@ -12509,7 +12817,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
|
|
|
12509
12817
|
requestId: requestId2,
|
|
12510
12818
|
sseHelper: mcpStreamHelper
|
|
12511
12819
|
});
|
|
12512
|
-
|
|
12820
|
+
logger28.info(
|
|
12513
12821
|
{ result },
|
|
12514
12822
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
12515
12823
|
);
|
|
@@ -12533,7 +12841,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
|
|
|
12533
12841
|
]
|
|
12534
12842
|
};
|
|
12535
12843
|
};
|
|
12536
|
-
var getServer = async (
|
|
12844
|
+
var getServer = async (headers2, executionContext, conversationId, credentialStores) => {
|
|
12537
12845
|
const { tenantId, projectId, agentId } = executionContext;
|
|
12538
12846
|
setupTracing(conversationId, tenantId, agentId);
|
|
12539
12847
|
const agent = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
|
|
@@ -12589,18 +12897,18 @@ var getServer = async (headers, executionContext, conversationId, credentialStor
|
|
|
12589
12897
|
projectId,
|
|
12590
12898
|
agentId,
|
|
12591
12899
|
conversationId,
|
|
12592
|
-
headers,
|
|
12900
|
+
headers: headers2,
|
|
12593
12901
|
dbClient: dbClient_default,
|
|
12594
12902
|
credentialStores
|
|
12595
12903
|
});
|
|
12596
|
-
|
|
12904
|
+
logger28.info(
|
|
12597
12905
|
{
|
|
12598
12906
|
tenantId,
|
|
12599
12907
|
projectId,
|
|
12600
12908
|
agentId,
|
|
12601
12909
|
conversationId,
|
|
12602
12910
|
hasContextConfig: !!agent.contextConfigId,
|
|
12603
|
-
hasHeaders: !!
|
|
12911
|
+
hasHeaders: !!headers2,
|
|
12604
12912
|
hasValidatedContext: !!resolvedContext
|
|
12605
12913
|
},
|
|
12606
12914
|
"parameters"
|
|
@@ -12655,7 +12963,7 @@ var validateRequestParameters = (c) => {
|
|
|
12655
12963
|
};
|
|
12656
12964
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
12657
12965
|
const { tenantId, projectId, agentId } = executionContext;
|
|
12658
|
-
|
|
12966
|
+
logger28.info({ body }, "Received initialization request");
|
|
12659
12967
|
const sessionId = agentsCore.getConversationId();
|
|
12660
12968
|
const activeSpan = api.trace.getActiveSpan();
|
|
12661
12969
|
if (activeSpan) {
|
|
@@ -12711,7 +13019,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
12711
13019
|
}
|
|
12712
13020
|
}
|
|
12713
13021
|
});
|
|
12714
|
-
|
|
13022
|
+
logger28.info(
|
|
12715
13023
|
{ sessionId, conversationId: conversation.id },
|
|
12716
13024
|
"Created MCP session as conversation"
|
|
12717
13025
|
);
|
|
@@ -12720,9 +13028,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
12720
13028
|
});
|
|
12721
13029
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
12722
13030
|
await server.connect(transport);
|
|
12723
|
-
|
|
13031
|
+
logger28.info({ sessionId }, "Server connected for initialization");
|
|
12724
13032
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
12725
|
-
|
|
13033
|
+
logger28.info(
|
|
12726
13034
|
{
|
|
12727
13035
|
sessionId,
|
|
12728
13036
|
bodyMethod: body?.method,
|
|
@@ -12731,7 +13039,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
12731
13039
|
"About to handle initialization request"
|
|
12732
13040
|
);
|
|
12733
13041
|
await transport.handleRequest(req, res, body);
|
|
12734
|
-
|
|
13042
|
+
logger28.info({ sessionId }, "Successfully handled initialization request");
|
|
12735
13043
|
return fetchToNode.toFetchResponse(res);
|
|
12736
13044
|
});
|
|
12737
13045
|
};
|
|
@@ -12758,8 +13066,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
12758
13066
|
sessionId,
|
|
12759
13067
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
12760
13068
|
);
|
|
12761
|
-
|
|
12762
|
-
|
|
13069
|
+
logger28.info({ sessionId }, "Server connected and transport initialized");
|
|
13070
|
+
logger28.info(
|
|
12763
13071
|
{
|
|
12764
13072
|
sessionId,
|
|
12765
13073
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -12773,9 +13081,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
12773
13081
|
);
|
|
12774
13082
|
try {
|
|
12775
13083
|
await transport.handleRequest(req, res, body);
|
|
12776
|
-
|
|
13084
|
+
logger28.info({ sessionId }, "Successfully handled MCP request");
|
|
12777
13085
|
} catch (transportError) {
|
|
12778
|
-
|
|
13086
|
+
logger28.error(
|
|
12779
13087
|
{
|
|
12780
13088
|
sessionId,
|
|
12781
13089
|
error: transportError,
|
|
@@ -12826,13 +13134,13 @@ app5.openapi(
|
|
|
12826
13134
|
}
|
|
12827
13135
|
const { executionContext } = paramValidation;
|
|
12828
13136
|
const body = c.get("requestBody") || {};
|
|
12829
|
-
|
|
13137
|
+
logger28.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
12830
13138
|
const isInitRequest = body.method === "initialize";
|
|
12831
13139
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
12832
13140
|
const validatedContext = c.get("validatedContext") || {};
|
|
12833
13141
|
const credentialStores = c.get("credentialStores");
|
|
12834
|
-
|
|
12835
|
-
|
|
13142
|
+
logger28.info({ validatedContext }, "Validated context");
|
|
13143
|
+
logger28.info({ req }, "request");
|
|
12836
13144
|
if (isInitRequest) {
|
|
12837
13145
|
return await handleInitializationRequest(
|
|
12838
13146
|
body,
|
|
@@ -12854,7 +13162,7 @@ app5.openapi(
|
|
|
12854
13162
|
);
|
|
12855
13163
|
}
|
|
12856
13164
|
} catch (e) {
|
|
12857
|
-
|
|
13165
|
+
logger28.error(
|
|
12858
13166
|
{
|
|
12859
13167
|
error: e instanceof Error ? e.message : e,
|
|
12860
13168
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -12866,7 +13174,7 @@ app5.openapi(
|
|
|
12866
13174
|
}
|
|
12867
13175
|
);
|
|
12868
13176
|
app5.get("/", async (c) => {
|
|
12869
|
-
|
|
13177
|
+
logger28.info({}, "Received GET MCP request");
|
|
12870
13178
|
return c.json(
|
|
12871
13179
|
{
|
|
12872
13180
|
jsonrpc: "2.0",
|
|
@@ -12880,7 +13188,7 @@ app5.get("/", async (c) => {
|
|
|
12880
13188
|
);
|
|
12881
13189
|
});
|
|
12882
13190
|
app5.delete("/", async (c) => {
|
|
12883
|
-
|
|
13191
|
+
logger28.info({}, "Received DELETE MCP request");
|
|
12884
13192
|
return c.json(
|
|
12885
13193
|
{
|
|
12886
13194
|
jsonrpc: "2.0",
|
|
@@ -12893,7 +13201,7 @@ app5.delete("/", async (c) => {
|
|
|
12893
13201
|
var mcp_default = app5;
|
|
12894
13202
|
|
|
12895
13203
|
// src/app.ts
|
|
12896
|
-
var
|
|
13204
|
+
var logger29 = agentsCore.getLogger("agents-run-api");
|
|
12897
13205
|
function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
12898
13206
|
const app7 = new zodOpenapi.OpenAPIHono();
|
|
12899
13207
|
app7.use("*", otel.otel());
|
|
@@ -12912,7 +13220,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12912
13220
|
const body = await c.req.json();
|
|
12913
13221
|
c.set("requestBody", body);
|
|
12914
13222
|
} catch (error) {
|
|
12915
|
-
|
|
13223
|
+
logger29.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
12916
13224
|
}
|
|
12917
13225
|
}
|
|
12918
13226
|
return next();
|
|
@@ -12963,8 +13271,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12963
13271
|
if (!isExpectedError) {
|
|
12964
13272
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
12965
13273
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
12966
|
-
if (
|
|
12967
|
-
|
|
13274
|
+
if (logger29) {
|
|
13275
|
+
logger29.error(
|
|
12968
13276
|
{
|
|
12969
13277
|
error: err,
|
|
12970
13278
|
message: errorMessage,
|
|
@@ -12976,8 +13284,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12976
13284
|
);
|
|
12977
13285
|
}
|
|
12978
13286
|
} else {
|
|
12979
|
-
if (
|
|
12980
|
-
|
|
13287
|
+
if (logger29) {
|
|
13288
|
+
logger29.error(
|
|
12981
13289
|
{
|
|
12982
13290
|
error: err,
|
|
12983
13291
|
path: c.req.path,
|
|
@@ -12994,8 +13302,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12994
13302
|
const response = err.getResponse();
|
|
12995
13303
|
return response;
|
|
12996
13304
|
} catch (responseError) {
|
|
12997
|
-
if (
|
|
12998
|
-
|
|
13305
|
+
if (logger29) {
|
|
13306
|
+
logger29.error({ error: responseError }, "Error while handling HTTPException response");
|
|
12999
13307
|
}
|
|
13000
13308
|
}
|
|
13001
13309
|
}
|
|
@@ -13029,7 +13337,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13029
13337
|
app7.use("*", async (c, next) => {
|
|
13030
13338
|
const executionContext = c.get("executionContext");
|
|
13031
13339
|
if (!executionContext) {
|
|
13032
|
-
|
|
13340
|
+
logger29.debug({}, "Empty execution context");
|
|
13033
13341
|
return next();
|
|
13034
13342
|
}
|
|
13035
13343
|
const { tenantId, projectId, agentId } = executionContext;
|
|
@@ -13038,7 +13346,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13038
13346
|
if (requestBody) {
|
|
13039
13347
|
conversationId = requestBody.conversationId;
|
|
13040
13348
|
if (!conversationId) {
|
|
13041
|
-
|
|
13349
|
+
logger29.debug({ requestBody }, "No conversation ID found in request body");
|
|
13042
13350
|
}
|
|
13043
13351
|
}
|
|
13044
13352
|
const entries = Object.fromEntries(
|
|
@@ -13053,7 +13361,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
13053
13361
|
})
|
|
13054
13362
|
);
|
|
13055
13363
|
if (!Object.keys(entries).length) {
|
|
13056
|
-
|
|
13364
|
+
logger29.debug({}, "Empty entries for baggage");
|
|
13057
13365
|
return next();
|
|
13058
13366
|
}
|
|
13059
13367
|
const bag = Object.entries(entries).reduce(
|