@inkeep/agents-run-api 0.0.0-dev-20250915190940 → 0.0.0-dev-20250915202938
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/index.cjs +364 -293
- package/dist/index.js +363 -292
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1159,6 +1159,128 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
1159
1159
|
});
|
|
1160
1160
|
}
|
|
1161
1161
|
}
|
|
1162
|
+
init_dbClient();
|
|
1163
|
+
agentsCore.getLogger("agents");
|
|
1164
|
+
function createAgentCard({
|
|
1165
|
+
dbAgent,
|
|
1166
|
+
baseUrl
|
|
1167
|
+
}) {
|
|
1168
|
+
const description = dbAgent.description || "AI Agent";
|
|
1169
|
+
return {
|
|
1170
|
+
name: dbAgent.name,
|
|
1171
|
+
description,
|
|
1172
|
+
url: baseUrl ? `${baseUrl}/a2a` : "",
|
|
1173
|
+
version: "1.0.0",
|
|
1174
|
+
capabilities: {
|
|
1175
|
+
streaming: true,
|
|
1176
|
+
// Enable streaming for A2A compliance
|
|
1177
|
+
pushNotifications: false,
|
|
1178
|
+
stateTransitionHistory: false
|
|
1179
|
+
},
|
|
1180
|
+
defaultInputModes: ["text", "text/plain"],
|
|
1181
|
+
defaultOutputModes: ["text", "text/plain"],
|
|
1182
|
+
skills: [],
|
|
1183
|
+
// Add provider info if available
|
|
1184
|
+
...baseUrl && {
|
|
1185
|
+
provider: {
|
|
1186
|
+
organization: "Inkeep",
|
|
1187
|
+
url: baseUrl
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
function generateDescriptionWithTransfers(baseDescription, internalRelations, externalRelations) {
|
|
1193
|
+
const transfers = [
|
|
1194
|
+
...internalRelations.filter((rel) => rel.relationType === "transfer"),
|
|
1195
|
+
...externalRelations.filter((rel) => rel.relationType === "transfer")
|
|
1196
|
+
];
|
|
1197
|
+
const delegates = [
|
|
1198
|
+
...internalRelations.filter((rel) => rel.relationType === "delegate"),
|
|
1199
|
+
...externalRelations.filter((rel) => rel.relationType === "delegate")
|
|
1200
|
+
];
|
|
1201
|
+
if (transfers.length === 0 && delegates.length === 0) {
|
|
1202
|
+
return baseDescription;
|
|
1203
|
+
}
|
|
1204
|
+
let enhancedDescription = baseDescription;
|
|
1205
|
+
if (transfers.length > 0) {
|
|
1206
|
+
const transferList = transfers.map((rel) => {
|
|
1207
|
+
const name = rel.externalAgent?.name || rel.name;
|
|
1208
|
+
const desc = rel.externalAgent?.description || rel.description || "";
|
|
1209
|
+
return `- ${name}: ${desc}`;
|
|
1210
|
+
}).join("\n");
|
|
1211
|
+
enhancedDescription += `
|
|
1212
|
+
|
|
1213
|
+
Can transfer to:
|
|
1214
|
+
${transferList}`;
|
|
1215
|
+
}
|
|
1216
|
+
if (delegates.length > 0) {
|
|
1217
|
+
const delegateList = delegates.map((rel) => {
|
|
1218
|
+
const name = rel.externalAgent?.name || rel.name;
|
|
1219
|
+
const desc = rel.externalAgent?.description || rel.description || "";
|
|
1220
|
+
return `- ${name}: ${desc}`;
|
|
1221
|
+
}).join("\n");
|
|
1222
|
+
enhancedDescription += `
|
|
1223
|
+
|
|
1224
|
+
Can delegate to:
|
|
1225
|
+
${delegateList}`;
|
|
1226
|
+
}
|
|
1227
|
+
return enhancedDescription;
|
|
1228
|
+
}
|
|
1229
|
+
async function hydrateAgent({
|
|
1230
|
+
dbAgent,
|
|
1231
|
+
graphId,
|
|
1232
|
+
baseUrl,
|
|
1233
|
+
apiKey,
|
|
1234
|
+
credentialStoreRegistry
|
|
1235
|
+
}) {
|
|
1236
|
+
try {
|
|
1237
|
+
const taskHandlerConfig = await createTaskHandlerConfig({
|
|
1238
|
+
tenantId: dbAgent.tenantId,
|
|
1239
|
+
projectId: dbAgent.projectId,
|
|
1240
|
+
graphId,
|
|
1241
|
+
agentId: dbAgent.id,
|
|
1242
|
+
baseUrl,
|
|
1243
|
+
apiKey
|
|
1244
|
+
});
|
|
1245
|
+
const taskHandler = createTaskHandler(taskHandlerConfig, credentialStoreRegistry);
|
|
1246
|
+
const agentCard = createAgentCard({
|
|
1247
|
+
dbAgent,
|
|
1248
|
+
baseUrl
|
|
1249
|
+
});
|
|
1250
|
+
return {
|
|
1251
|
+
agentId: dbAgent.id,
|
|
1252
|
+
tenantId: dbAgent.tenantId,
|
|
1253
|
+
projectId: dbAgent.projectId,
|
|
1254
|
+
graphId,
|
|
1255
|
+
agentCard,
|
|
1256
|
+
taskHandler
|
|
1257
|
+
};
|
|
1258
|
+
} catch (error) {
|
|
1259
|
+
console.error(`\u274C Failed to hydrate agent ${dbAgent.id}:`, error);
|
|
1260
|
+
throw error;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
1264
|
+
const { tenantId, projectId, graphId, agentId, baseUrl, apiKey } = executionContext;
|
|
1265
|
+
if (!agentId) {
|
|
1266
|
+
throw new Error("Agent ID is required");
|
|
1267
|
+
}
|
|
1268
|
+
const dbAgent = await agentsCore.getAgentById(dbClient_default)({
|
|
1269
|
+
scopes: { tenantId, projectId },
|
|
1270
|
+
agentId
|
|
1271
|
+
});
|
|
1272
|
+
if (!dbAgent) {
|
|
1273
|
+
return null;
|
|
1274
|
+
}
|
|
1275
|
+
const agentFrameworkBaseUrl = `${baseUrl}/agents`;
|
|
1276
|
+
return hydrateAgent({
|
|
1277
|
+
dbAgent,
|
|
1278
|
+
graphId,
|
|
1279
|
+
baseUrl: agentFrameworkBaseUrl,
|
|
1280
|
+
credentialStoreRegistry,
|
|
1281
|
+
apiKey
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1162
1284
|
|
|
1163
1285
|
// src/agents/generateTaskHandler.ts
|
|
1164
1286
|
init_dbClient();
|
|
@@ -1202,10 +1324,10 @@ function statusUpdateOp(ctx) {
|
|
|
1202
1324
|
ctx
|
|
1203
1325
|
};
|
|
1204
1326
|
}
|
|
1205
|
-
var
|
|
1327
|
+
var logger4 = agentsCore.getLogger("DataComponentSchema");
|
|
1206
1328
|
function jsonSchemaToZod(jsonSchema) {
|
|
1207
1329
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
1208
|
-
|
|
1330
|
+
logger4.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
1209
1331
|
return z5.z.string();
|
|
1210
1332
|
}
|
|
1211
1333
|
switch (jsonSchema.type) {
|
|
@@ -1232,7 +1354,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
1232
1354
|
case "null":
|
|
1233
1355
|
return z5.z.null();
|
|
1234
1356
|
default:
|
|
1235
|
-
|
|
1357
|
+
logger4.warn(
|
|
1236
1358
|
{
|
|
1237
1359
|
unsupportedType: jsonSchema.type,
|
|
1238
1360
|
schema: jsonSchema
|
|
@@ -1286,7 +1408,7 @@ __publicField(_ArtifactReferenceSchema, "ARTIFACT_PROPS_SCHEMA", {
|
|
|
1286
1408
|
required: ["artifact_id", "task_id"]
|
|
1287
1409
|
});
|
|
1288
1410
|
var ArtifactReferenceSchema = _ArtifactReferenceSchema;
|
|
1289
|
-
var
|
|
1411
|
+
var logger5 = agentsCore.getLogger("ModelFactory");
|
|
1290
1412
|
var _ModelFactory = class _ModelFactory {
|
|
1291
1413
|
/**
|
|
1292
1414
|
* Create a language model instance from configuration
|
|
@@ -1301,7 +1423,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1301
1423
|
const modelSettings = config2;
|
|
1302
1424
|
const modelString = modelSettings.model.trim();
|
|
1303
1425
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1304
|
-
|
|
1426
|
+
logger5.debug(
|
|
1305
1427
|
{
|
|
1306
1428
|
provider,
|
|
1307
1429
|
model: modelName,
|
|
@@ -1322,7 +1444,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1322
1444
|
);
|
|
1323
1445
|
}
|
|
1324
1446
|
} catch (error) {
|
|
1325
|
-
|
|
1447
|
+
logger5.error(
|
|
1326
1448
|
{
|
|
1327
1449
|
provider,
|
|
1328
1450
|
model: modelName,
|
|
@@ -1345,7 +1467,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1345
1467
|
const [provider, ...modelParts] = modelString.split("/");
|
|
1346
1468
|
const normalizedProvider = provider.toLowerCase();
|
|
1347
1469
|
if (!_ModelFactory.SUPPORTED_PROVIDERS.includes(normalizedProvider)) {
|
|
1348
|
-
|
|
1470
|
+
logger5.warn(
|
|
1349
1471
|
{ provider: normalizedProvider, modelName: modelParts.join("/") },
|
|
1350
1472
|
"Unsupported provider detected, falling back to anthropic"
|
|
1351
1473
|
);
|
|
@@ -1374,14 +1496,14 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1374
1496
|
anthropicConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1375
1497
|
}
|
|
1376
1498
|
if (providerOptions?.gateway) {
|
|
1377
|
-
|
|
1499
|
+
logger5.info(
|
|
1378
1500
|
{ gateway: providerOptions.gateway },
|
|
1379
1501
|
"Setting up AI Gateway for Anthropic model"
|
|
1380
1502
|
);
|
|
1381
1503
|
Object.assign(anthropicConfig, providerOptions.gateway);
|
|
1382
1504
|
}
|
|
1383
1505
|
if (Object.keys(anthropicConfig).length > 0) {
|
|
1384
|
-
|
|
1506
|
+
logger5.info({ config: anthropicConfig }, "Applying custom Anthropic provider configuration");
|
|
1385
1507
|
const provider = anthropic.createAnthropic(anthropicConfig);
|
|
1386
1508
|
return provider(modelName);
|
|
1387
1509
|
}
|
|
@@ -1396,11 +1518,11 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1396
1518
|
openaiConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1397
1519
|
}
|
|
1398
1520
|
if (providerOptions?.gateway) {
|
|
1399
|
-
|
|
1521
|
+
logger5.info({ gateway: providerOptions.gateway }, "Setting up AI Gateway for OpenAI model");
|
|
1400
1522
|
Object.assign(openaiConfig, providerOptions.gateway);
|
|
1401
1523
|
}
|
|
1402
1524
|
if (Object.keys(openaiConfig).length > 0) {
|
|
1403
|
-
|
|
1525
|
+
logger5.info({ config: openaiConfig }, "Applying custom OpenAI provider configuration");
|
|
1404
1526
|
const provider = openai.createOpenAI(openaiConfig);
|
|
1405
1527
|
return provider(modelName);
|
|
1406
1528
|
}
|
|
@@ -1494,7 +1616,7 @@ function unregisterStreamHelper(requestId2) {
|
|
|
1494
1616
|
}
|
|
1495
1617
|
|
|
1496
1618
|
// src/utils/graph-session.ts
|
|
1497
|
-
var
|
|
1619
|
+
var logger6 = agentsCore.getLogger("GraphSession");
|
|
1498
1620
|
var GraphSession = class {
|
|
1499
1621
|
// Track scheduled timeouts for cleanup
|
|
1500
1622
|
constructor(sessionId, messageId, graphId, tenantId, projectId) {
|
|
@@ -1518,7 +1640,7 @@ var GraphSession = class {
|
|
|
1518
1640
|
__publicField(this, "MAX_PENDING_ARTIFACTS", 100);
|
|
1519
1641
|
// Prevent unbounded growth
|
|
1520
1642
|
__publicField(this, "scheduledTimeouts");
|
|
1521
|
-
|
|
1643
|
+
logger6.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
1522
1644
|
}
|
|
1523
1645
|
/**
|
|
1524
1646
|
* Initialize status updates for this session
|
|
@@ -1532,15 +1654,15 @@ var GraphSession = class {
|
|
|
1532
1654
|
summarizerModel,
|
|
1533
1655
|
baseModel,
|
|
1534
1656
|
config: {
|
|
1535
|
-
numEvents: config2.numEvents ||
|
|
1536
|
-
timeInSeconds: config2.timeInSeconds ||
|
|
1657
|
+
numEvents: config2.numEvents || 1,
|
|
1658
|
+
timeInSeconds: config2.timeInSeconds || 2,
|
|
1537
1659
|
...config2
|
|
1538
1660
|
}
|
|
1539
1661
|
};
|
|
1540
1662
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
1541
1663
|
this.statusUpdateTimer = setInterval(async () => {
|
|
1542
1664
|
if (!this.statusUpdateState || this.isEnded) {
|
|
1543
|
-
|
|
1665
|
+
logger6.debug(
|
|
1544
1666
|
{ sessionId: this.sessionId },
|
|
1545
1667
|
"Timer triggered but session already cleaned up or ended"
|
|
1546
1668
|
);
|
|
@@ -1552,7 +1674,7 @@ var GraphSession = class {
|
|
|
1552
1674
|
}
|
|
1553
1675
|
await this.checkAndSendTimeBasedUpdate();
|
|
1554
1676
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
1555
|
-
|
|
1677
|
+
logger6.info(
|
|
1556
1678
|
{
|
|
1557
1679
|
sessionId: this.sessionId,
|
|
1558
1680
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -1566,7 +1688,7 @@ var GraphSession = class {
|
|
|
1566
1688
|
*/
|
|
1567
1689
|
recordEvent(eventType, agentId, data) {
|
|
1568
1690
|
if (this.isEnded) {
|
|
1569
|
-
|
|
1691
|
+
logger6.debug(
|
|
1570
1692
|
{
|
|
1571
1693
|
sessionId: this.sessionId,
|
|
1572
1694
|
eventType,
|
|
@@ -1586,7 +1708,7 @@ var GraphSession = class {
|
|
|
1586
1708
|
if (eventType === "artifact_saved" && data.pendingGeneration) {
|
|
1587
1709
|
const artifactId = data.artifactId;
|
|
1588
1710
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
1589
|
-
|
|
1711
|
+
logger6.warn(
|
|
1590
1712
|
{
|
|
1591
1713
|
sessionId: this.sessionId,
|
|
1592
1714
|
artifactId,
|
|
@@ -1607,7 +1729,7 @@ var GraphSession = class {
|
|
|
1607
1729
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
1608
1730
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
1609
1731
|
this.pendingArtifacts.delete(artifactId);
|
|
1610
|
-
|
|
1732
|
+
logger6.error(
|
|
1611
1733
|
{
|
|
1612
1734
|
sessionId: this.sessionId,
|
|
1613
1735
|
artifactId,
|
|
@@ -1619,7 +1741,7 @@ var GraphSession = class {
|
|
|
1619
1741
|
"Artifact processing failed after max retries, giving up"
|
|
1620
1742
|
);
|
|
1621
1743
|
} else {
|
|
1622
|
-
|
|
1744
|
+
logger6.warn(
|
|
1623
1745
|
{
|
|
1624
1746
|
sessionId: this.sessionId,
|
|
1625
1747
|
artifactId,
|
|
@@ -1641,14 +1763,14 @@ var GraphSession = class {
|
|
|
1641
1763
|
*/
|
|
1642
1764
|
checkStatusUpdates() {
|
|
1643
1765
|
if (this.isEnded) {
|
|
1644
|
-
|
|
1766
|
+
logger6.debug(
|
|
1645
1767
|
{ sessionId: this.sessionId },
|
|
1646
1768
|
"Session has ended - skipping status update check"
|
|
1647
1769
|
);
|
|
1648
1770
|
return;
|
|
1649
1771
|
}
|
|
1650
1772
|
if (!this.statusUpdateState) {
|
|
1651
|
-
|
|
1773
|
+
logger6.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
1652
1774
|
return;
|
|
1653
1775
|
}
|
|
1654
1776
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -1659,11 +1781,11 @@ var GraphSession = class {
|
|
|
1659
1781
|
*/
|
|
1660
1782
|
async checkAndSendTimeBasedUpdate() {
|
|
1661
1783
|
if (this.isEnded) {
|
|
1662
|
-
|
|
1784
|
+
logger6.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
1663
1785
|
return;
|
|
1664
1786
|
}
|
|
1665
1787
|
if (!this.statusUpdateState) {
|
|
1666
|
-
|
|
1788
|
+
logger6.debug(
|
|
1667
1789
|
{ sessionId: this.sessionId },
|
|
1668
1790
|
"No status updates configured for time-based check"
|
|
1669
1791
|
);
|
|
@@ -1676,7 +1798,7 @@ var GraphSession = class {
|
|
|
1676
1798
|
try {
|
|
1677
1799
|
await this.generateAndSendUpdate();
|
|
1678
1800
|
} catch (error) {
|
|
1679
|
-
|
|
1801
|
+
logger6.error(
|
|
1680
1802
|
{
|
|
1681
1803
|
sessionId: this.sessionId,
|
|
1682
1804
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1769,29 +1891,29 @@ var GraphSession = class {
|
|
|
1769
1891
|
*/
|
|
1770
1892
|
async generateAndSendUpdate() {
|
|
1771
1893
|
if (this.isEnded) {
|
|
1772
|
-
|
|
1894
|
+
logger6.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
1773
1895
|
return;
|
|
1774
1896
|
}
|
|
1775
1897
|
if (this.isTextStreaming) {
|
|
1776
|
-
|
|
1898
|
+
logger6.debug(
|
|
1777
1899
|
{ sessionId: this.sessionId },
|
|
1778
1900
|
"Text is currently streaming - skipping status update"
|
|
1779
1901
|
);
|
|
1780
1902
|
return;
|
|
1781
1903
|
}
|
|
1782
1904
|
if (this.isGeneratingUpdate) {
|
|
1783
|
-
|
|
1905
|
+
logger6.debug(
|
|
1784
1906
|
{ sessionId: this.sessionId },
|
|
1785
1907
|
"Update already in progress - skipping duplicate generation"
|
|
1786
1908
|
);
|
|
1787
1909
|
return;
|
|
1788
1910
|
}
|
|
1789
1911
|
if (!this.statusUpdateState) {
|
|
1790
|
-
|
|
1912
|
+
logger6.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
1791
1913
|
return;
|
|
1792
1914
|
}
|
|
1793
1915
|
if (!this.graphId) {
|
|
1794
|
-
|
|
1916
|
+
logger6.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
1795
1917
|
return;
|
|
1796
1918
|
}
|
|
1797
1919
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -1804,7 +1926,7 @@ var GraphSession = class {
|
|
|
1804
1926
|
try {
|
|
1805
1927
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
1806
1928
|
if (!streamHelper) {
|
|
1807
|
-
|
|
1929
|
+
logger6.warn(
|
|
1808
1930
|
{ sessionId: this.sessionId },
|
|
1809
1931
|
"No stream helper found - cannot send status update"
|
|
1810
1932
|
);
|
|
@@ -1825,7 +1947,7 @@ var GraphSession = class {
|
|
|
1825
1947
|
if (result.operations && result.operations.length > 0) {
|
|
1826
1948
|
for (const op of result.operations) {
|
|
1827
1949
|
if (!op || !op.type || !op.data || Object.keys(op.data).length === 0) {
|
|
1828
|
-
|
|
1950
|
+
logger6.warn(
|
|
1829
1951
|
{
|
|
1830
1952
|
sessionId: this.sessionId,
|
|
1831
1953
|
operation: op
|
|
@@ -1878,7 +2000,7 @@ var GraphSession = class {
|
|
|
1878
2000
|
this.previousSummaries.shift();
|
|
1879
2001
|
}
|
|
1880
2002
|
if (!operation || !operation.type || !operation.ctx) {
|
|
1881
|
-
|
|
2003
|
+
logger6.warn(
|
|
1882
2004
|
{
|
|
1883
2005
|
sessionId: this.sessionId,
|
|
1884
2006
|
operation
|
|
@@ -1893,7 +2015,7 @@ var GraphSession = class {
|
|
|
1893
2015
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
1894
2016
|
}
|
|
1895
2017
|
} catch (error) {
|
|
1896
|
-
|
|
2018
|
+
logger6.error(
|
|
1897
2019
|
{
|
|
1898
2020
|
sessionId: this.sessionId,
|
|
1899
2021
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -1931,7 +2053,7 @@ var GraphSession = class {
|
|
|
1931
2053
|
this.releaseUpdateLock();
|
|
1932
2054
|
}
|
|
1933
2055
|
} catch (error) {
|
|
1934
|
-
|
|
2056
|
+
logger6.error(
|
|
1935
2057
|
{
|
|
1936
2058
|
sessionId: this.sessionId,
|
|
1937
2059
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2008,7 +2130,7 @@ User's Question/Context:
|
|
|
2008
2130
|
${conversationHistory}
|
|
2009
2131
|
` : "";
|
|
2010
2132
|
} catch (error) {
|
|
2011
|
-
|
|
2133
|
+
logger6.warn(
|
|
2012
2134
|
{ sessionId: this.sessionId, error },
|
|
2013
2135
|
"Failed to fetch conversation history for status update"
|
|
2014
2136
|
);
|
|
@@ -2060,7 +2182,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2060
2182
|
return text.trim();
|
|
2061
2183
|
} catch (error) {
|
|
2062
2184
|
agentsCore.setSpanWithError(span, error);
|
|
2063
|
-
|
|
2185
|
+
logger6.error({ error }, "Failed to generate summary, using fallback");
|
|
2064
2186
|
return this.generateFallbackSummary(newEvents, elapsedTime);
|
|
2065
2187
|
} finally {
|
|
2066
2188
|
span.end();
|
|
@@ -2106,7 +2228,7 @@ User's Question/Context:
|
|
|
2106
2228
|
${conversationHistory}
|
|
2107
2229
|
` : "";
|
|
2108
2230
|
} catch (error) {
|
|
2109
|
-
|
|
2231
|
+
logger6.warn(
|
|
2110
2232
|
{ sessionId: this.sessionId, error },
|
|
2111
2233
|
"Failed to fetch conversation history for structured status update"
|
|
2112
2234
|
);
|
|
@@ -2149,9 +2271,11 @@ Rules:
|
|
|
2149
2271
|
- Labels MUST contain the ACTUAL information discovered ("Found X", "Learned Y", "Discovered Z requires A")
|
|
2150
2272
|
- DO NOT use action words like "Searching", "Processing", "Analyzing" - state what was FOUND
|
|
2151
2273
|
- Include specific details, numbers, requirements, or insights discovered
|
|
2152
|
-
- You are ONE AI
|
|
2153
|
-
-
|
|
2154
|
-
-
|
|
2274
|
+
- You are ONE unified AI system - NEVER mention agents, transfers, delegations, or routing
|
|
2275
|
+
- CRITICAL: NEVER use the words "transfer", "delegation", "agent", "routing", or any internal system terminology in labels
|
|
2276
|
+
- Present all operations as seamless actions by a single system
|
|
2277
|
+
- Anonymize all internal operations so that the information appears descriptive and USER FRIENDLY. HIDE ALL INTERNAL OPERATIONS!
|
|
2278
|
+
- Bad examples: "Transferring to search agent", "Delegating task", "Routing request", "Processing request", or not using the no_relevant_updates
|
|
2155
2279
|
- Good examples: "Slack bot needs admin privileges", "Found 3-step OAuth flow required", "Channel limit is 500 per workspace", or use the no_relevant_updates component if nothing new to report.
|
|
2156
2280
|
|
|
2157
2281
|
REMEMBER YOU CAN ONLY USE 'no_relevant_updates' ALONE! IT CANNOT BE CONCATENATED WITH OTHER STATUS UPDATES!
|
|
@@ -2205,7 +2329,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2205
2329
|
return { operations };
|
|
2206
2330
|
} catch (error) {
|
|
2207
2331
|
agentsCore.setSpanWithError(span, error);
|
|
2208
|
-
|
|
2332
|
+
logger6.error({ error }, "Failed to generate structured update, using fallback");
|
|
2209
2333
|
return { operations: [] };
|
|
2210
2334
|
} finally {
|
|
2211
2335
|
span.end();
|
|
@@ -2312,8 +2436,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2312
2436
|
case "transfer": {
|
|
2313
2437
|
const data = event.data;
|
|
2314
2438
|
activities.push(
|
|
2315
|
-
`\u{1F504} **
|
|
2316
|
-
${data.reason ? `Reason: ${data.reason}` : "Control transfer"}
|
|
2439
|
+
`\u{1F504} **Continuing**: ${data.reason || "Processing request"}
|
|
2317
2440
|
${data.context ? `Context: ${JSON.stringify(data.context, null, 2)}` : ""}`
|
|
2318
2441
|
);
|
|
2319
2442
|
break;
|
|
@@ -2321,8 +2444,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2321
2444
|
case "delegation_sent": {
|
|
2322
2445
|
const data = event.data;
|
|
2323
2446
|
activities.push(
|
|
2324
|
-
`\u{1F4E4} **
|
|
2325
|
-
Task: ${data.taskDescription}
|
|
2447
|
+
`\u{1F4E4} **Processing**: ${data.taskDescription}
|
|
2326
2448
|
${data.context ? `Context: ${JSON.stringify(data.context, null, 2)}` : ""}`
|
|
2327
2449
|
);
|
|
2328
2450
|
break;
|
|
@@ -2330,7 +2452,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2330
2452
|
case "delegation_returned": {
|
|
2331
2453
|
const data = event.data;
|
|
2332
2454
|
activities.push(
|
|
2333
|
-
`\u{1F4E5} **
|
|
2455
|
+
`\u{1F4E5} **Completed subtask**
|
|
2334
2456
|
Result: ${JSON.stringify(data.result, null, 2)}`
|
|
2335
2457
|
);
|
|
2336
2458
|
break;
|
|
@@ -2349,16 +2471,16 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2349
2471
|
case "agent_reasoning": {
|
|
2350
2472
|
const data = event.data;
|
|
2351
2473
|
activities.push(
|
|
2352
|
-
`\u2699\uFE0F **
|
|
2353
|
-
|
|
2474
|
+
`\u2699\uFE0F **Analyzing request**
|
|
2475
|
+
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
2354
2476
|
);
|
|
2355
2477
|
break;
|
|
2356
2478
|
}
|
|
2357
2479
|
case "agent_generate": {
|
|
2358
2480
|
const data = event.data;
|
|
2359
2481
|
activities.push(
|
|
2360
|
-
`\u2699\uFE0F **
|
|
2361
|
-
|
|
2482
|
+
`\u2699\uFE0F **Preparing response**
|
|
2483
|
+
Details: ${JSON.stringify(data.parts, null, 2)}`
|
|
2362
2484
|
);
|
|
2363
2485
|
break;
|
|
2364
2486
|
}
|
|
@@ -2532,7 +2654,7 @@ Make it specific and relevant.`;
|
|
|
2532
2654
|
taskId: artifactData.taskId,
|
|
2533
2655
|
artifacts: [artifactToSave]
|
|
2534
2656
|
});
|
|
2535
|
-
|
|
2657
|
+
logger6.info(
|
|
2536
2658
|
{
|
|
2537
2659
|
sessionId: this.sessionId,
|
|
2538
2660
|
artifactId: artifactData.artifactId,
|
|
@@ -2549,7 +2671,7 @@ Make it specific and relevant.`;
|
|
|
2549
2671
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
2550
2672
|
} catch (error) {
|
|
2551
2673
|
agentsCore.setSpanWithError(span, error);
|
|
2552
|
-
|
|
2674
|
+
logger6.error(
|
|
2553
2675
|
{
|
|
2554
2676
|
sessionId: this.sessionId,
|
|
2555
2677
|
artifactId: artifactData.artifactId,
|
|
@@ -2585,7 +2707,7 @@ Make it specific and relevant.`;
|
|
|
2585
2707
|
taskId: artifactData.taskId,
|
|
2586
2708
|
artifacts: [fallbackArtifact]
|
|
2587
2709
|
});
|
|
2588
|
-
|
|
2710
|
+
logger6.info(
|
|
2589
2711
|
{
|
|
2590
2712
|
sessionId: this.sessionId,
|
|
2591
2713
|
artifactId: artifactData.artifactId
|
|
@@ -2594,7 +2716,7 @@ Make it specific and relevant.`;
|
|
|
2594
2716
|
);
|
|
2595
2717
|
}
|
|
2596
2718
|
} catch (fallbackError) {
|
|
2597
|
-
|
|
2719
|
+
logger6.error(
|
|
2598
2720
|
{
|
|
2599
2721
|
sessionId: this.sessionId,
|
|
2600
2722
|
artifactId: artifactData.artifactId,
|
|
@@ -2621,7 +2743,7 @@ var GraphSessionManager = class {
|
|
|
2621
2743
|
const sessionId = messageId;
|
|
2622
2744
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId);
|
|
2623
2745
|
this.sessions.set(sessionId, session);
|
|
2624
|
-
|
|
2746
|
+
logger6.info({ sessionId, messageId, graphId, tenantId, projectId }, "GraphSession created");
|
|
2625
2747
|
return sessionId;
|
|
2626
2748
|
}
|
|
2627
2749
|
/**
|
|
@@ -2632,7 +2754,7 @@ var GraphSessionManager = class {
|
|
|
2632
2754
|
if (session) {
|
|
2633
2755
|
session.initializeStatusUpdates(config2, summarizerModel);
|
|
2634
2756
|
} else {
|
|
2635
|
-
|
|
2757
|
+
logger6.error(
|
|
2636
2758
|
{
|
|
2637
2759
|
sessionId,
|
|
2638
2760
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -2653,7 +2775,7 @@ var GraphSessionManager = class {
|
|
|
2653
2775
|
recordEvent(sessionId, eventType, agentId, data) {
|
|
2654
2776
|
const session = this.sessions.get(sessionId);
|
|
2655
2777
|
if (!session) {
|
|
2656
|
-
|
|
2778
|
+
logger6.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
2657
2779
|
return;
|
|
2658
2780
|
}
|
|
2659
2781
|
session.recordEvent(eventType, agentId, data);
|
|
@@ -2664,12 +2786,12 @@ var GraphSessionManager = class {
|
|
|
2664
2786
|
endSession(sessionId) {
|
|
2665
2787
|
const session = this.sessions.get(sessionId);
|
|
2666
2788
|
if (!session) {
|
|
2667
|
-
|
|
2789
|
+
logger6.warn({ sessionId }, "Attempted to end non-existent session");
|
|
2668
2790
|
return [];
|
|
2669
2791
|
}
|
|
2670
2792
|
const events = session.getEvents();
|
|
2671
2793
|
const summary = session.getSummary();
|
|
2672
|
-
|
|
2794
|
+
logger6.info({ sessionId, summary }, "GraphSession ended");
|
|
2673
2795
|
session.cleanup();
|
|
2674
2796
|
this.sessions.delete(sessionId);
|
|
2675
2797
|
return events;
|
|
@@ -2698,7 +2820,7 @@ var graphSessionManager = new GraphSessionManager();
|
|
|
2698
2820
|
|
|
2699
2821
|
// src/utils/artifact-parser.ts
|
|
2700
2822
|
init_dbClient();
|
|
2701
|
-
var
|
|
2823
|
+
var logger7 = agentsCore.getLogger("ArtifactParser");
|
|
2702
2824
|
var _ArtifactParser = class _ArtifactParser {
|
|
2703
2825
|
constructor(tenantId) {
|
|
2704
2826
|
this.tenantId = tenantId;
|
|
@@ -2714,9 +2836,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2714
2836
|
* More robust detection that handles streaming fragments
|
|
2715
2837
|
*/
|
|
2716
2838
|
hasIncompleteArtifact(text) {
|
|
2717
|
-
return
|
|
2718
|
-
text
|
|
2719
|
-
) || /^.*<artifact:ref(?:[^>]*)$/.test(text) || // Incomplete artifact:ref at end
|
|
2839
|
+
return /<(a(r(t(i(f(a(c(t(:?(r(e(f)?)?)?)?)?)?)?)?)?)?)?)?$/.test(text) || /<artifact:ref[^>]+$/.test(text) || // Incomplete artifact ref at end
|
|
2720
2840
|
this.findSafeTextBoundary(text) < text.length;
|
|
2721
2841
|
}
|
|
2722
2842
|
/**
|
|
@@ -2725,10 +2845,10 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2725
2845
|
*/
|
|
2726
2846
|
findSafeTextBoundary(text) {
|
|
2727
2847
|
const endPatterns = [
|
|
2728
|
-
|
|
2848
|
+
/<artifact:ref(?![^>]*\/>).*$/,
|
|
2729
2849
|
// artifact:ref that doesn't end with />
|
|
2730
|
-
|
|
2731
|
-
//
|
|
2850
|
+
/<(a(r(t(i(f(a(c(t(:?(r(e(f)?)?)?)?)?)?)?)?)?)?)?)?$/
|
|
2851
|
+
// Any partial artifact pattern at end
|
|
2732
2852
|
];
|
|
2733
2853
|
for (const pattern of endPatterns) {
|
|
2734
2854
|
const match = text.match(pattern);
|
|
@@ -2764,7 +2884,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2764
2884
|
id: taskId
|
|
2765
2885
|
});
|
|
2766
2886
|
if (!task) {
|
|
2767
|
-
|
|
2887
|
+
logger7.warn({ taskId }, "Task not found when fetching artifacts");
|
|
2768
2888
|
continue;
|
|
2769
2889
|
}
|
|
2770
2890
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2776,9 +2896,9 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2776
2896
|
artifacts.set(key, artifact);
|
|
2777
2897
|
}
|
|
2778
2898
|
}
|
|
2779
|
-
|
|
2899
|
+
logger7.debug({ contextId, count: artifacts.size }, "Loaded context artifacts");
|
|
2780
2900
|
} catch (error) {
|
|
2781
|
-
|
|
2901
|
+
logger7.error({ error, contextId }, "Error loading context artifacts");
|
|
2782
2902
|
}
|
|
2783
2903
|
return artifacts;
|
|
2784
2904
|
}
|
|
@@ -2881,7 +3001,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2881
3001
|
id: taskId
|
|
2882
3002
|
});
|
|
2883
3003
|
if (!task) {
|
|
2884
|
-
|
|
3004
|
+
logger7.warn({ taskId }, "Task not found when fetching artifact");
|
|
2885
3005
|
return null;
|
|
2886
3006
|
}
|
|
2887
3007
|
const artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2893,7 +3013,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2893
3013
|
return this.formatArtifactData(artifacts[0], artifactId, taskId);
|
|
2894
3014
|
}
|
|
2895
3015
|
} catch (error) {
|
|
2896
|
-
|
|
3016
|
+
logger7.warn({ artifactId, taskId, error }, "Failed to fetch artifact");
|
|
2897
3017
|
}
|
|
2898
3018
|
return null;
|
|
2899
3019
|
}
|
|
@@ -2929,11 +3049,11 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2929
3049
|
__publicField(_ArtifactParser, "ARTIFACT_REGEX", /<artifact:ref\s+id="([^"]*?)"\s+task="([^"]*?)"\s*\/>/gs);
|
|
2930
3050
|
__publicField(_ArtifactParser, "ARTIFACT_CHECK_REGEX", /<artifact:ref\s+(?=.*id="[^"]+")(?=.*task="[^"]+")[^>]*\/>/);
|
|
2931
3051
|
// Regex for catching any partial artifact pattern (< + any prefix of "artifact:ref")
|
|
2932
|
-
__publicField(_ArtifactParser, "INCOMPLETE_ARTIFACT_REGEX", /<(a(r(t(i(f(a(c(t(
|
|
3052
|
+
__publicField(_ArtifactParser, "INCOMPLETE_ARTIFACT_REGEX", /<(a(r(t(i(f(a(c(t(:?(r(e(f)?)?)?)?)?)?)?)?)?)?)?)?$/g);
|
|
2933
3053
|
var ArtifactParser = _ArtifactParser;
|
|
2934
3054
|
|
|
2935
3055
|
// src/utils/incremental-stream-parser.ts
|
|
2936
|
-
var
|
|
3056
|
+
var logger8 = agentsCore.getLogger("IncrementalStreamParser");
|
|
2937
3057
|
var IncrementalStreamParser = class {
|
|
2938
3058
|
constructor(streamHelper, tenantId, contextId) {
|
|
2939
3059
|
__publicField(this, "buffer", "");
|
|
@@ -2993,13 +3113,13 @@ var IncrementalStreamParser = class {
|
|
|
2993
3113
|
if (part.type === "tool-call-delta" && part.toolName === targetToolName) {
|
|
2994
3114
|
const delta = part.argsTextDelta || "";
|
|
2995
3115
|
if (jsonBuffer.length + delta.length > MAX_BUFFER_SIZE) {
|
|
2996
|
-
|
|
3116
|
+
logger8.warn({ bufferSize: jsonBuffer.length + delta.length, maxSize: MAX_BUFFER_SIZE }, "JSON buffer exceeded maximum size, truncating");
|
|
2997
3117
|
jsonBuffer = jsonBuffer.slice(-MAX_BUFFER_SIZE / 2);
|
|
2998
3118
|
}
|
|
2999
3119
|
jsonBuffer += delta;
|
|
3000
3120
|
for (const char of delta) {
|
|
3001
3121
|
if (componentBuffer.length > MAX_BUFFER_SIZE) {
|
|
3002
|
-
|
|
3122
|
+
logger8.warn({ bufferSize: componentBuffer.length, maxSize: MAX_BUFFER_SIZE }, "Component buffer exceeded maximum size, resetting");
|
|
3003
3123
|
componentBuffer = "";
|
|
3004
3124
|
depth = 0;
|
|
3005
3125
|
continue;
|
|
@@ -3014,7 +3134,7 @@ var IncrementalStreamParser = class {
|
|
|
3014
3134
|
if (componentMatch) {
|
|
3015
3135
|
const MAX_COMPONENT_SIZE = 1024 * 1024;
|
|
3016
3136
|
if (componentMatch[0].length > MAX_COMPONENT_SIZE) {
|
|
3017
|
-
|
|
3137
|
+
logger8.warn(
|
|
3018
3138
|
{
|
|
3019
3139
|
size: componentMatch[0].length,
|
|
3020
3140
|
maxSize: MAX_COMPONENT_SIZE
|
|
@@ -3027,7 +3147,7 @@ var IncrementalStreamParser = class {
|
|
|
3027
3147
|
try {
|
|
3028
3148
|
const component = JSON.parse(componentMatch[0]);
|
|
3029
3149
|
if (typeof component !== "object" || !component.id) {
|
|
3030
|
-
|
|
3150
|
+
logger8.warn({ component }, "Invalid component structure, skipping");
|
|
3031
3151
|
componentBuffer = "";
|
|
3032
3152
|
continue;
|
|
3033
3153
|
}
|
|
@@ -3040,7 +3160,7 @@ var IncrementalStreamParser = class {
|
|
|
3040
3160
|
componentsStreamed++;
|
|
3041
3161
|
componentBuffer = "";
|
|
3042
3162
|
} catch (e) {
|
|
3043
|
-
|
|
3163
|
+
logger8.debug({ error: e }, "Failed to parse component, continuing to accumulate");
|
|
3044
3164
|
}
|
|
3045
3165
|
}
|
|
3046
3166
|
}
|
|
@@ -3057,7 +3177,7 @@ var IncrementalStreamParser = class {
|
|
|
3057
3177
|
break;
|
|
3058
3178
|
}
|
|
3059
3179
|
}
|
|
3060
|
-
|
|
3180
|
+
logger8.debug({ componentsStreamed }, "Finished streaming components");
|
|
3061
3181
|
}
|
|
3062
3182
|
/**
|
|
3063
3183
|
* Legacy method for backward compatibility - defaults to text processing
|
|
@@ -3201,7 +3321,7 @@ var IncrementalStreamParser = class {
|
|
|
3201
3321
|
};
|
|
3202
3322
|
|
|
3203
3323
|
// src/utils/response-formatter.ts
|
|
3204
|
-
var
|
|
3324
|
+
var logger9 = agentsCore.getLogger("ResponseFormatter");
|
|
3205
3325
|
var ResponseFormatter = class {
|
|
3206
3326
|
constructor(tenantId) {
|
|
3207
3327
|
__publicField(this, "artifactParser");
|
|
@@ -3232,7 +3352,7 @@ var ResponseFormatter = class {
|
|
|
3232
3352
|
return { parts };
|
|
3233
3353
|
} catch (error) {
|
|
3234
3354
|
agentsCore.setSpanWithError(span, error);
|
|
3235
|
-
|
|
3355
|
+
logger9.error({ error, responseObject }, "Error formatting object response");
|
|
3236
3356
|
return {
|
|
3237
3357
|
parts: [{ kind: "data", data: responseObject }]
|
|
3238
3358
|
};
|
|
@@ -3283,7 +3403,7 @@ var ResponseFormatter = class {
|
|
|
3283
3403
|
return { parts };
|
|
3284
3404
|
} catch (error) {
|
|
3285
3405
|
agentsCore.setSpanWithError(span, error);
|
|
3286
|
-
|
|
3406
|
+
logger9.error({ error, responseText }, "Error formatting response");
|
|
3287
3407
|
return { text: responseText };
|
|
3288
3408
|
} finally {
|
|
3289
3409
|
span.end();
|
|
@@ -3328,7 +3448,7 @@ var ResponseFormatter = class {
|
|
|
3328
3448
|
}
|
|
3329
3449
|
}
|
|
3330
3450
|
};
|
|
3331
|
-
var
|
|
3451
|
+
var logger10 = agentsCore.getLogger("ToolSessionManager");
|
|
3332
3452
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
3333
3453
|
// 5 minutes
|
|
3334
3454
|
constructor() {
|
|
@@ -3357,7 +3477,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3357
3477
|
createdAt: Date.now()
|
|
3358
3478
|
};
|
|
3359
3479
|
this.sessions.set(sessionId, session);
|
|
3360
|
-
|
|
3480
|
+
logger10.debug({ sessionId, tenantId, contextId, taskId }, "Created tool session");
|
|
3361
3481
|
return sessionId;
|
|
3362
3482
|
}
|
|
3363
3483
|
/**
|
|
@@ -3366,7 +3486,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3366
3486
|
recordToolResult(sessionId, toolResult) {
|
|
3367
3487
|
const session = this.sessions.get(sessionId);
|
|
3368
3488
|
if (!session) {
|
|
3369
|
-
|
|
3489
|
+
logger10.warn(
|
|
3370
3490
|
{ sessionId, toolCallId: toolResult.toolCallId },
|
|
3371
3491
|
"Tool result recorded for unknown session"
|
|
3372
3492
|
);
|
|
@@ -3380,12 +3500,12 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3380
3500
|
getToolResult(sessionId, toolCallId) {
|
|
3381
3501
|
const session = this.sessions.get(sessionId);
|
|
3382
3502
|
if (!session) {
|
|
3383
|
-
|
|
3503
|
+
logger10.warn({ sessionId, toolCallId }, "Requested tool result for unknown session");
|
|
3384
3504
|
return void 0;
|
|
3385
3505
|
}
|
|
3386
3506
|
const result = session.toolResults.get(toolCallId);
|
|
3387
3507
|
if (!result) {
|
|
3388
|
-
|
|
3508
|
+
logger10.warn(
|
|
3389
3509
|
{
|
|
3390
3510
|
sessionId,
|
|
3391
3511
|
toolCallId,
|
|
@@ -3424,10 +3544,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3424
3544
|
}
|
|
3425
3545
|
for (const sessionId of expiredSessions) {
|
|
3426
3546
|
this.sessions.delete(sessionId);
|
|
3427
|
-
|
|
3547
|
+
logger10.debug({ sessionId }, "Cleaned up expired tool session");
|
|
3428
3548
|
}
|
|
3429
3549
|
if (expiredSessions.length > 0) {
|
|
3430
|
-
|
|
3550
|
+
logger10.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
3431
3551
|
}
|
|
3432
3552
|
}
|
|
3433
3553
|
};
|
|
@@ -3436,7 +3556,7 @@ var ToolSessionManager = _ToolSessionManager;
|
|
|
3436
3556
|
var toolSessionManager = ToolSessionManager.getInstance();
|
|
3437
3557
|
|
|
3438
3558
|
// src/agents/artifactTools.ts
|
|
3439
|
-
var
|
|
3559
|
+
var logger11 = agentsCore.getLogger("artifactTools");
|
|
3440
3560
|
function buildKeyNestingMap(data, prefix = "", map = /* @__PURE__ */ new Map()) {
|
|
3441
3561
|
if (typeof data === "object" && data !== null) {
|
|
3442
3562
|
if (Array.isArray(data)) {
|
|
@@ -3657,7 +3777,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3657
3777
|
execute: async ({ toolCallId, baseSelector, propSelectors, ...rest }, _context) => {
|
|
3658
3778
|
const artifactType = "artifactType" in rest ? rest.artifactType : void 0;
|
|
3659
3779
|
if (!sessionId) {
|
|
3660
|
-
|
|
3780
|
+
logger11.warn({ toolCallId }, "No session ID provided to save_tool_result");
|
|
3661
3781
|
return {
|
|
3662
3782
|
saved: false,
|
|
3663
3783
|
error: `[toolCallId: ${toolCallId}] No session context available`,
|
|
@@ -3667,7 +3787,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3667
3787
|
}
|
|
3668
3788
|
const toolResult = toolSessionManager.getToolResult(sessionId, toolCallId);
|
|
3669
3789
|
if (!toolResult) {
|
|
3670
|
-
|
|
3790
|
+
logger11.warn({ toolCallId, sessionId }, "Tool result not found in session");
|
|
3671
3791
|
return {
|
|
3672
3792
|
saved: false,
|
|
3673
3793
|
error: `[toolCallId: ${toolCallId}] Tool result not found`,
|
|
@@ -3680,7 +3800,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3680
3800
|
const baseData = jmespath__default.default.search(parsedResult, baseSelector);
|
|
3681
3801
|
if (!baseData || Array.isArray(baseData) && baseData.length === 0) {
|
|
3682
3802
|
const debugInfo = analyzeSelectorFailure(parsedResult, baseSelector);
|
|
3683
|
-
|
|
3803
|
+
logger11.warn(
|
|
3684
3804
|
{
|
|
3685
3805
|
baseSelector,
|
|
3686
3806
|
toolCallId,
|
|
@@ -3723,7 +3843,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3723
3843
|
const fallbackValue = item[propName];
|
|
3724
3844
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3725
3845
|
extractedItem[propName] = fallbackValue;
|
|
3726
|
-
|
|
3846
|
+
logger11.info(
|
|
3727
3847
|
{ propName, propSelector, context },
|
|
3728
3848
|
`PropSelector failed, used fallback direct property access`
|
|
3729
3849
|
);
|
|
@@ -3735,7 +3855,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3735
3855
|
const fallbackValue = item[propName];
|
|
3736
3856
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3737
3857
|
extractedItem[propName] = fallbackValue;
|
|
3738
|
-
|
|
3858
|
+
logger11.warn(
|
|
3739
3859
|
{ propName, propSelector, context, error: error.message },
|
|
3740
3860
|
`PropSelector syntax error, used fallback direct property access`
|
|
3741
3861
|
);
|
|
@@ -3848,7 +3968,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3848
3968
|
warnings
|
|
3849
3969
|
};
|
|
3850
3970
|
} catch (error) {
|
|
3851
|
-
|
|
3971
|
+
logger11.error({ error, toolCallId, sessionId }, "Error processing save_tool_result");
|
|
3852
3972
|
return {
|
|
3853
3973
|
saved: false,
|
|
3854
3974
|
error: `[toolCallId: ${toolCallId}] ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
@@ -3860,7 +3980,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3860
3980
|
}
|
|
3861
3981
|
|
|
3862
3982
|
// src/a2a/client.ts
|
|
3863
|
-
var
|
|
3983
|
+
var logger12 = agentsCore.getLogger("a2aClient");
|
|
3864
3984
|
var DEFAULT_BACKOFF = {
|
|
3865
3985
|
initialInterval: 500,
|
|
3866
3986
|
maxInterval: 6e4,
|
|
@@ -4066,7 +4186,7 @@ var A2AClient = class {
|
|
|
4066
4186
|
try {
|
|
4067
4187
|
const res = await fn();
|
|
4068
4188
|
if (attempt > 0) {
|
|
4069
|
-
|
|
4189
|
+
logger12.info(
|
|
4070
4190
|
{
|
|
4071
4191
|
attempts: attempt + 1,
|
|
4072
4192
|
elapsedTime: Date.now() - start
|
|
@@ -4081,7 +4201,7 @@ var A2AClient = class {
|
|
|
4081
4201
|
}
|
|
4082
4202
|
const elapsed = Date.now() - start;
|
|
4083
4203
|
if (elapsed > maxElapsedTime) {
|
|
4084
|
-
|
|
4204
|
+
logger12.warn(
|
|
4085
4205
|
{
|
|
4086
4206
|
attempts: attempt + 1,
|
|
4087
4207
|
elapsedTime: elapsed,
|
|
@@ -4102,7 +4222,7 @@ var A2AClient = class {
|
|
|
4102
4222
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
4103
4223
|
}
|
|
4104
4224
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
4105
|
-
|
|
4225
|
+
logger12.info(
|
|
4106
4226
|
{
|
|
4107
4227
|
attempt: attempt + 1,
|
|
4108
4228
|
delayMs,
|
|
@@ -4187,7 +4307,7 @@ var A2AClient = class {
|
|
|
4187
4307
|
}
|
|
4188
4308
|
const rpcResponse = await httpResponse.json();
|
|
4189
4309
|
if (rpcResponse.id !== requestId2) {
|
|
4190
|
-
|
|
4310
|
+
logger12.warn(
|
|
4191
4311
|
{
|
|
4192
4312
|
method,
|
|
4193
4313
|
expectedId: requestId2,
|
|
@@ -4386,7 +4506,7 @@ var A2AClient = class {
|
|
|
4386
4506
|
try {
|
|
4387
4507
|
while (true) {
|
|
4388
4508
|
const { done, value } = await reader.read();
|
|
4389
|
-
|
|
4509
|
+
logger12.info({ done, value }, "parseA2ASseStream");
|
|
4390
4510
|
if (done) {
|
|
4391
4511
|
if (eventDataBuffer.trim()) {
|
|
4392
4512
|
const result = this._processSseEventData(
|
|
@@ -4475,7 +4595,7 @@ var A2AClient = class {
|
|
|
4475
4595
|
// src/agents/relationTools.ts
|
|
4476
4596
|
init_conversations();
|
|
4477
4597
|
init_dbClient();
|
|
4478
|
-
var
|
|
4598
|
+
var logger13 = agentsCore.getLogger("relationships Tools");
|
|
4479
4599
|
var generateTransferToolDescription = (config2) => {
|
|
4480
4600
|
return `Hand off the conversation to agent ${config2.id}.
|
|
4481
4601
|
|
|
@@ -4513,7 +4633,7 @@ var createTransferToAgentTool = ({
|
|
|
4513
4633
|
"transfer.to_agent_id": transferConfig.id ?? "unknown"
|
|
4514
4634
|
});
|
|
4515
4635
|
}
|
|
4516
|
-
|
|
4636
|
+
logger13.info(
|
|
4517
4637
|
{
|
|
4518
4638
|
transferTo: transferConfig.id ?? "unknown",
|
|
4519
4639
|
fromAgent: callingAgentId
|
|
@@ -4661,7 +4781,7 @@ function createDelegateToAgentTool({
|
|
|
4661
4781
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
4662
4782
|
}
|
|
4663
4783
|
};
|
|
4664
|
-
|
|
4784
|
+
logger13.info({ messageToSend }, "messageToSend");
|
|
4665
4785
|
await agentsCore.createMessage(dbClient_default)({
|
|
4666
4786
|
id: nanoid.nanoid(),
|
|
4667
4787
|
tenantId,
|
|
@@ -4723,7 +4843,7 @@ function createDelegateToAgentTool({
|
|
|
4723
4843
|
}
|
|
4724
4844
|
|
|
4725
4845
|
// src/agents/SystemPromptBuilder.ts
|
|
4726
|
-
var
|
|
4846
|
+
var logger14 = agentsCore.getLogger("SystemPromptBuilder");
|
|
4727
4847
|
var SystemPromptBuilder = class {
|
|
4728
4848
|
constructor(version, versionConfig) {
|
|
4729
4849
|
this.version = version;
|
|
@@ -4739,9 +4859,9 @@ var SystemPromptBuilder = class {
|
|
|
4739
4859
|
this.templates.set(name, content);
|
|
4740
4860
|
}
|
|
4741
4861
|
this.loaded = true;
|
|
4742
|
-
|
|
4862
|
+
logger14.debug({ templateCount: this.templates.size, version: this.version }, `Loaded ${this.templates.size} templates for version ${this.version}`);
|
|
4743
4863
|
} catch (error) {
|
|
4744
|
-
|
|
4864
|
+
logger14.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
4745
4865
|
throw new Error(`Template loading failed: ${error}`);
|
|
4746
4866
|
}
|
|
4747
4867
|
}
|
|
@@ -5143,7 +5263,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
5143
5263
|
return false;
|
|
5144
5264
|
};
|
|
5145
5265
|
}
|
|
5146
|
-
var
|
|
5266
|
+
var logger15 = agentsCore.getLogger("Agent");
|
|
5147
5267
|
var CONSTANTS = {
|
|
5148
5268
|
MAX_GENERATION_STEPS: 12,
|
|
5149
5269
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -5396,14 +5516,14 @@ var Agent = class {
|
|
|
5396
5516
|
for (const toolSet of tools) {
|
|
5397
5517
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
5398
5518
|
if (!isValidTool(originalTool)) {
|
|
5399
|
-
|
|
5519
|
+
logger15.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
5400
5520
|
continue;
|
|
5401
5521
|
}
|
|
5402
5522
|
const sessionWrappedTool = ai.tool({
|
|
5403
5523
|
description: originalTool.description,
|
|
5404
5524
|
inputSchema: originalTool.inputSchema,
|
|
5405
5525
|
execute: async (args, { toolCallId }) => {
|
|
5406
|
-
|
|
5526
|
+
logger15.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
5407
5527
|
try {
|
|
5408
5528
|
const result = await originalTool.execute(args, { toolCallId });
|
|
5409
5529
|
toolSessionManager.recordToolResult(sessionId, {
|
|
@@ -5415,7 +5535,7 @@ var Agent = class {
|
|
|
5415
5535
|
});
|
|
5416
5536
|
return { result, toolCallId };
|
|
5417
5537
|
} catch (error) {
|
|
5418
|
-
|
|
5538
|
+
logger15.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
5419
5539
|
throw error;
|
|
5420
5540
|
}
|
|
5421
5541
|
}
|
|
@@ -5500,7 +5620,7 @@ var Agent = class {
|
|
|
5500
5620
|
selectedTools
|
|
5501
5621
|
};
|
|
5502
5622
|
}
|
|
5503
|
-
|
|
5623
|
+
logger15.info(
|
|
5504
5624
|
{
|
|
5505
5625
|
toolName: tool4.name,
|
|
5506
5626
|
credentialReferenceId,
|
|
@@ -5540,7 +5660,7 @@ var Agent = class {
|
|
|
5540
5660
|
async getResolvedContext(conversationId, requestContext) {
|
|
5541
5661
|
try {
|
|
5542
5662
|
if (!this.config.contextConfigId) {
|
|
5543
|
-
|
|
5663
|
+
logger15.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
5544
5664
|
return null;
|
|
5545
5665
|
}
|
|
5546
5666
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -5548,7 +5668,7 @@ var Agent = class {
|
|
|
5548
5668
|
id: this.config.contextConfigId
|
|
5549
5669
|
});
|
|
5550
5670
|
if (!contextConfig) {
|
|
5551
|
-
|
|
5671
|
+
logger15.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
5552
5672
|
return null;
|
|
5553
5673
|
}
|
|
5554
5674
|
if (!this.contextResolver) {
|
|
@@ -5565,7 +5685,7 @@ var Agent = class {
|
|
|
5565
5685
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5566
5686
|
$env: process.env
|
|
5567
5687
|
};
|
|
5568
|
-
|
|
5688
|
+
logger15.debug(
|
|
5569
5689
|
{
|
|
5570
5690
|
conversationId,
|
|
5571
5691
|
contextConfigId: contextConfig.id,
|
|
@@ -5579,7 +5699,7 @@ var Agent = class {
|
|
|
5579
5699
|
);
|
|
5580
5700
|
return contextWithBuiltins;
|
|
5581
5701
|
} catch (error) {
|
|
5582
|
-
|
|
5702
|
+
logger15.error(
|
|
5583
5703
|
{
|
|
5584
5704
|
conversationId,
|
|
5585
5705
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5603,7 +5723,7 @@ var Agent = class {
|
|
|
5603
5723
|
});
|
|
5604
5724
|
return graphDefinition?.graphPrompt || void 0;
|
|
5605
5725
|
} catch (error) {
|
|
5606
|
-
|
|
5726
|
+
logger15.warn(
|
|
5607
5727
|
{
|
|
5608
5728
|
graphId: this.config.graphId,
|
|
5609
5729
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5630,7 +5750,7 @@ var Agent = class {
|
|
|
5630
5750
|
}
|
|
5631
5751
|
return !!(graphDefinition.artifactComponents && Object.keys(graphDefinition.artifactComponents).length > 0);
|
|
5632
5752
|
} catch (error) {
|
|
5633
|
-
|
|
5753
|
+
logger15.warn(
|
|
5634
5754
|
{
|
|
5635
5755
|
graphId: this.config.graphId,
|
|
5636
5756
|
tenantId: this.config.tenantId,
|
|
@@ -5690,7 +5810,7 @@ Key requirements:
|
|
|
5690
5810
|
preserveUnresolved: false
|
|
5691
5811
|
});
|
|
5692
5812
|
} catch (error) {
|
|
5693
|
-
|
|
5813
|
+
logger15.error(
|
|
5694
5814
|
{
|
|
5695
5815
|
conversationId,
|
|
5696
5816
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5735,7 +5855,7 @@ Key requirements:
|
|
|
5735
5855
|
preserveUnresolved: false
|
|
5736
5856
|
});
|
|
5737
5857
|
} catch (error) {
|
|
5738
|
-
|
|
5858
|
+
logger15.error(
|
|
5739
5859
|
{
|
|
5740
5860
|
conversationId,
|
|
5741
5861
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5763,7 +5883,7 @@ Key requirements:
|
|
|
5763
5883
|
artifactId: z5.z.string().describe("The unique identifier of the artifact to get.")
|
|
5764
5884
|
}),
|
|
5765
5885
|
execute: async ({ artifactId }) => {
|
|
5766
|
-
|
|
5886
|
+
logger15.info({ artifactId }, "get_artifact executed");
|
|
5767
5887
|
const artifact = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
5768
5888
|
scopes: {
|
|
5769
5889
|
tenantId: this.config.tenantId,
|
|
@@ -5830,7 +5950,7 @@ Key requirements:
|
|
|
5830
5950
|
graphId: this.config.graphId
|
|
5831
5951
|
});
|
|
5832
5952
|
} catch (error) {
|
|
5833
|
-
|
|
5953
|
+
logger15.error(
|
|
5834
5954
|
{ error, graphId: this.config.graphId },
|
|
5835
5955
|
"Failed to check graph artifact components"
|
|
5836
5956
|
);
|
|
@@ -5934,7 +6054,7 @@ Key requirements:
|
|
|
5934
6054
|
const configuredTimeout = modelSettings.maxDuration ? Math.min(modelSettings.maxDuration * 1e3, MAX_ALLOWED_TIMEOUT_MS) : shouldStreamPhase1 ? CONSTANTS.PHASE_1_TIMEOUT_MS : CONSTANTS.NON_STREAMING_PHASE_1_TIMEOUT_MS;
|
|
5935
6055
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
5936
6056
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
5937
|
-
|
|
6057
|
+
logger15.warn(
|
|
5938
6058
|
{
|
|
5939
6059
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
5940
6060
|
appliedTimeout: timeoutMs,
|
|
@@ -5976,7 +6096,7 @@ Key requirements:
|
|
|
5976
6096
|
}
|
|
5977
6097
|
);
|
|
5978
6098
|
} catch (error) {
|
|
5979
|
-
|
|
6099
|
+
logger15.debug({ error }, "Failed to track agent reasoning");
|
|
5980
6100
|
}
|
|
5981
6101
|
}
|
|
5982
6102
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -6059,7 +6179,7 @@ Key requirements:
|
|
|
6059
6179
|
}
|
|
6060
6180
|
);
|
|
6061
6181
|
} catch (error) {
|
|
6062
|
-
|
|
6182
|
+
logger15.debug({ error }, "Failed to track agent reasoning");
|
|
6063
6183
|
}
|
|
6064
6184
|
}
|
|
6065
6185
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -6104,7 +6224,7 @@ Key requirements:
|
|
|
6104
6224
|
return;
|
|
6105
6225
|
}
|
|
6106
6226
|
if (toolName === "save_artifact_tool" || toolName === "save_tool_result") {
|
|
6107
|
-
|
|
6227
|
+
logger15.info({ result }, "save_artifact_tool or save_tool_result");
|
|
6108
6228
|
if (result.output.artifacts) {
|
|
6109
6229
|
for (const artifact of result.output.artifacts) {
|
|
6110
6230
|
const artifactId = artifact?.artifactId || "N/A";
|
|
@@ -6292,7 +6412,7 @@ function parseEmbeddedJson(data) {
|
|
|
6292
6412
|
}
|
|
6293
6413
|
});
|
|
6294
6414
|
}
|
|
6295
|
-
var
|
|
6415
|
+
var logger16 = agentsCore.getLogger("generateTaskHandler");
|
|
6296
6416
|
var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
6297
6417
|
return async (task) => {
|
|
6298
6418
|
try {
|
|
@@ -6342,7 +6462,33 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6342
6462
|
agentId: config2.agentId
|
|
6343
6463
|
})
|
|
6344
6464
|
]);
|
|
6345
|
-
|
|
6465
|
+
logger16.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
6466
|
+
const enhancedInternalRelations = await Promise.all(
|
|
6467
|
+
internalRelations.map(async (relation) => {
|
|
6468
|
+
try {
|
|
6469
|
+
const relatedAgent = await agentsCore.getAgentById(dbClient_default)({
|
|
6470
|
+
scopes: { tenantId: config2.tenantId, projectId: config2.projectId },
|
|
6471
|
+
agentId: relation.id
|
|
6472
|
+
});
|
|
6473
|
+
if (relatedAgent) {
|
|
6474
|
+
const relatedAgentRelations = await agentsCore.getRelatedAgentsForGraph(dbClient_default)({
|
|
6475
|
+
scopes: { tenantId: config2.tenantId, projectId: config2.projectId },
|
|
6476
|
+
graphId: config2.graphId,
|
|
6477
|
+
agentId: relation.id
|
|
6478
|
+
});
|
|
6479
|
+
const enhancedDescription = generateDescriptionWithTransfers(
|
|
6480
|
+
relation.description || "",
|
|
6481
|
+
relatedAgentRelations.internalRelations,
|
|
6482
|
+
relatedAgentRelations.externalRelations
|
|
6483
|
+
);
|
|
6484
|
+
return { ...relation, description: enhancedDescription };
|
|
6485
|
+
}
|
|
6486
|
+
} catch (error) {
|
|
6487
|
+
logger16.warn({ agentId: relation.id, error }, "Failed to enhance agent description");
|
|
6488
|
+
}
|
|
6489
|
+
return relation;
|
|
6490
|
+
})
|
|
6491
|
+
);
|
|
6346
6492
|
const agentPrompt = "prompt" in config2.agentSchema ? config2.agentSchema.prompt : "";
|
|
6347
6493
|
const models = "models" in config2.agentSchema ? config2.agentSchema.models : void 0;
|
|
6348
6494
|
const stopWhen = "stopWhen" in config2.agentSchema ? config2.agentSchema.stopWhen : void 0;
|
|
@@ -6359,7 +6505,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6359
6505
|
agentPrompt,
|
|
6360
6506
|
models: models || void 0,
|
|
6361
6507
|
stopWhen: stopWhen || void 0,
|
|
6362
|
-
agentRelations:
|
|
6508
|
+
agentRelations: enhancedInternalRelations.map((relation) => ({
|
|
6363
6509
|
id: relation.id,
|
|
6364
6510
|
tenantId: config2.tenantId,
|
|
6365
6511
|
projectId: config2.projectId,
|
|
@@ -6373,7 +6519,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6373
6519
|
agentRelations: [],
|
|
6374
6520
|
transferRelations: []
|
|
6375
6521
|
})),
|
|
6376
|
-
transferRelations:
|
|
6522
|
+
transferRelations: enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map((relation) => ({
|
|
6377
6523
|
baseUrl: config2.baseUrl,
|
|
6378
6524
|
apiKey: config2.apiKey,
|
|
6379
6525
|
id: relation.id,
|
|
@@ -6389,7 +6535,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6389
6535
|
})),
|
|
6390
6536
|
delegateRelations: [
|
|
6391
6537
|
// Internal delegate relations
|
|
6392
|
-
...
|
|
6538
|
+
...enhancedInternalRelations.filter((relation) => relation.relationType === "delegate").map((relation) => ({
|
|
6393
6539
|
type: "internal",
|
|
6394
6540
|
config: {
|
|
6395
6541
|
id: relation.id,
|
|
@@ -6442,7 +6588,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6442
6588
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
6443
6589
|
if (taskIdMatch) {
|
|
6444
6590
|
contextId = taskIdMatch[1];
|
|
6445
|
-
|
|
6591
|
+
logger16.info(
|
|
6446
6592
|
{
|
|
6447
6593
|
taskId: task.id,
|
|
6448
6594
|
extractedContextId: contextId,
|
|
@@ -6458,7 +6604,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6458
6604
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
6459
6605
|
agent.setDelegationStatus(isDelegation);
|
|
6460
6606
|
if (isDelegation) {
|
|
6461
|
-
|
|
6607
|
+
logger16.info(
|
|
6462
6608
|
{ agentId: config2.agentId, taskId: task.id },
|
|
6463
6609
|
"Delegated agent - streaming disabled"
|
|
6464
6610
|
);
|
|
@@ -6664,86 +6810,11 @@ async function getRegisteredGraph(executionContext) {
|
|
|
6664
6810
|
const agentFrameworkBaseUrl = `${baseUrl}/agents`;
|
|
6665
6811
|
return hydrateGraph({ dbGraph, baseUrl: agentFrameworkBaseUrl, apiKey });
|
|
6666
6812
|
}
|
|
6667
|
-
init_dbClient();
|
|
6668
|
-
agentsCore.getLogger("agents");
|
|
6669
|
-
async function hydrateAgent({
|
|
6670
|
-
dbAgent,
|
|
6671
|
-
graphId,
|
|
6672
|
-
baseUrl,
|
|
6673
|
-
apiKey,
|
|
6674
|
-
credentialStoreRegistry
|
|
6675
|
-
}) {
|
|
6676
|
-
try {
|
|
6677
|
-
const taskHandlerConfig = await createTaskHandlerConfig({
|
|
6678
|
-
tenantId: dbAgent.tenantId,
|
|
6679
|
-
projectId: dbAgent.projectId,
|
|
6680
|
-
graphId,
|
|
6681
|
-
agentId: dbAgent.id,
|
|
6682
|
-
baseUrl,
|
|
6683
|
-
apiKey
|
|
6684
|
-
});
|
|
6685
|
-
const taskHandler = createTaskHandler(taskHandlerConfig, credentialStoreRegistry);
|
|
6686
|
-
const agentCard = {
|
|
6687
|
-
name: dbAgent.name,
|
|
6688
|
-
description: dbAgent.description || "AI Agent",
|
|
6689
|
-
url: baseUrl ? `${baseUrl}/a2a` : "",
|
|
6690
|
-
version: "1.0.0",
|
|
6691
|
-
capabilities: {
|
|
6692
|
-
streaming: true,
|
|
6693
|
-
// Enable streaming for A2A compliance
|
|
6694
|
-
pushNotifications: false,
|
|
6695
|
-
stateTransitionHistory: false
|
|
6696
|
-
},
|
|
6697
|
-
defaultInputModes: ["text", "text/plain"],
|
|
6698
|
-
defaultOutputModes: ["text", "text/plain"],
|
|
6699
|
-
skills: [],
|
|
6700
|
-
// Add provider info if available
|
|
6701
|
-
...baseUrl && {
|
|
6702
|
-
provider: {
|
|
6703
|
-
organization: "Inkeep",
|
|
6704
|
-
url: baseUrl
|
|
6705
|
-
}
|
|
6706
|
-
}
|
|
6707
|
-
};
|
|
6708
|
-
return {
|
|
6709
|
-
agentId: dbAgent.id,
|
|
6710
|
-
tenantId: dbAgent.tenantId,
|
|
6711
|
-
projectId: dbAgent.projectId,
|
|
6712
|
-
graphId,
|
|
6713
|
-
agentCard,
|
|
6714
|
-
taskHandler
|
|
6715
|
-
};
|
|
6716
|
-
} catch (error) {
|
|
6717
|
-
console.error(`\u274C Failed to hydrate agent ${dbAgent.id}:`, error);
|
|
6718
|
-
throw error;
|
|
6719
|
-
}
|
|
6720
|
-
}
|
|
6721
|
-
async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
6722
|
-
const { tenantId, projectId, graphId, agentId, baseUrl, apiKey } = executionContext;
|
|
6723
|
-
if (!agentId) {
|
|
6724
|
-
throw new Error("Agent ID is required");
|
|
6725
|
-
}
|
|
6726
|
-
const dbAgent = await agentsCore.getAgentById(dbClient_default)({
|
|
6727
|
-
scopes: { tenantId, projectId },
|
|
6728
|
-
agentId
|
|
6729
|
-
});
|
|
6730
|
-
if (!dbAgent) {
|
|
6731
|
-
return null;
|
|
6732
|
-
}
|
|
6733
|
-
const agentFrameworkBaseUrl = `${baseUrl}/agents`;
|
|
6734
|
-
return hydrateAgent({
|
|
6735
|
-
dbAgent,
|
|
6736
|
-
graphId,
|
|
6737
|
-
baseUrl: agentFrameworkBaseUrl,
|
|
6738
|
-
credentialStoreRegistry,
|
|
6739
|
-
apiKey
|
|
6740
|
-
});
|
|
6741
|
-
}
|
|
6742
6813
|
|
|
6743
6814
|
// src/routes/agents.ts
|
|
6744
6815
|
init_dbClient();
|
|
6745
6816
|
var app = new zodOpenapi.OpenAPIHono();
|
|
6746
|
-
var
|
|
6817
|
+
var logger17 = agentsCore.getLogger("agents");
|
|
6747
6818
|
app.openapi(
|
|
6748
6819
|
zodOpenapi.createRoute({
|
|
6749
6820
|
method: "get",
|
|
@@ -6781,7 +6852,7 @@ app.openapi(
|
|
|
6781
6852
|
tracestate: c.req.header("tracestate"),
|
|
6782
6853
|
baggage: c.req.header("baggage")
|
|
6783
6854
|
};
|
|
6784
|
-
|
|
6855
|
+
logger17.info(
|
|
6785
6856
|
{
|
|
6786
6857
|
otelHeaders,
|
|
6787
6858
|
path: c.req.path,
|
|
@@ -6792,7 +6863,7 @@ app.openapi(
|
|
|
6792
6863
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
6793
6864
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6794
6865
|
if (agentId) {
|
|
6795
|
-
|
|
6866
|
+
logger17.info(
|
|
6796
6867
|
{
|
|
6797
6868
|
message: "getRegisteredAgent (agent-level)",
|
|
6798
6869
|
tenantId,
|
|
@@ -6804,13 +6875,13 @@ app.openapi(
|
|
|
6804
6875
|
);
|
|
6805
6876
|
const credentialStores = c.get("credentialStores");
|
|
6806
6877
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
6807
|
-
|
|
6878
|
+
logger17.info({ agent }, "agent registered: well-known agent.json");
|
|
6808
6879
|
if (!agent) {
|
|
6809
6880
|
return c.json({ error: "Agent not found" }, 404);
|
|
6810
6881
|
}
|
|
6811
6882
|
return c.json(agent.agentCard);
|
|
6812
6883
|
} else {
|
|
6813
|
-
|
|
6884
|
+
logger17.info(
|
|
6814
6885
|
{
|
|
6815
6886
|
message: "getRegisteredGraph (graph-level)",
|
|
6816
6887
|
tenantId,
|
|
@@ -6833,7 +6904,7 @@ app.post("/a2a", async (c) => {
|
|
|
6833
6904
|
tracestate: c.req.header("tracestate"),
|
|
6834
6905
|
baggage: c.req.header("baggage")
|
|
6835
6906
|
};
|
|
6836
|
-
|
|
6907
|
+
logger17.info(
|
|
6837
6908
|
{
|
|
6838
6909
|
otelHeaders,
|
|
6839
6910
|
path: c.req.path,
|
|
@@ -6844,7 +6915,7 @@ app.post("/a2a", async (c) => {
|
|
|
6844
6915
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
6845
6916
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6846
6917
|
if (agentId) {
|
|
6847
|
-
|
|
6918
|
+
logger17.info(
|
|
6848
6919
|
{
|
|
6849
6920
|
message: "a2a (agent-level)",
|
|
6850
6921
|
tenantId,
|
|
@@ -6868,7 +6939,7 @@ app.post("/a2a", async (c) => {
|
|
|
6868
6939
|
}
|
|
6869
6940
|
return a2aHandler(c, agent);
|
|
6870
6941
|
} else {
|
|
6871
|
-
|
|
6942
|
+
logger17.info(
|
|
6872
6943
|
{
|
|
6873
6944
|
message: "a2a (graph-level)",
|
|
6874
6945
|
tenantId,
|
|
@@ -6914,14 +6985,14 @@ init_dbClient();
|
|
|
6914
6985
|
|
|
6915
6986
|
// src/a2a/transfer.ts
|
|
6916
6987
|
init_dbClient();
|
|
6917
|
-
var
|
|
6988
|
+
var logger18 = agentsCore.getLogger("Transfer");
|
|
6918
6989
|
async function executeTransfer({
|
|
6919
6990
|
tenantId,
|
|
6920
6991
|
threadId,
|
|
6921
6992
|
projectId,
|
|
6922
6993
|
targetAgentId
|
|
6923
6994
|
}) {
|
|
6924
|
-
|
|
6995
|
+
logger18.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
6925
6996
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
6926
6997
|
scopes: { tenantId, projectId },
|
|
6927
6998
|
threadId,
|
|
@@ -7116,7 +7187,7 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
7116
7187
|
__publicField(this, "queuedOperations", []);
|
|
7117
7188
|
// Timing tracking for text sequences (text-end to text-start gap)
|
|
7118
7189
|
__publicField(this, "lastTextEndTimestamp", 0);
|
|
7119
|
-
__publicField(this, "TEXT_GAP_THRESHOLD",
|
|
7190
|
+
__publicField(this, "TEXT_GAP_THRESHOLD", 50);
|
|
7120
7191
|
// milliseconds - if gap between text sequences is less than this, queue operations
|
|
7121
7192
|
// Connection management and forced cleanup
|
|
7122
7193
|
__publicField(this, "connectionDropTimer");
|
|
@@ -7465,7 +7536,7 @@ function createMCPStreamHelper() {
|
|
|
7465
7536
|
|
|
7466
7537
|
// src/handlers/executionHandler.ts
|
|
7467
7538
|
init_dbClient();
|
|
7468
|
-
var
|
|
7539
|
+
var logger19 = agentsCore.getLogger("ExecutionHandler");
|
|
7469
7540
|
var ExecutionHandler = class {
|
|
7470
7541
|
constructor() {
|
|
7471
7542
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -7490,7 +7561,7 @@ var ExecutionHandler = class {
|
|
|
7490
7561
|
const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
|
|
7491
7562
|
registerStreamHelper(requestId2, sseHelper);
|
|
7492
7563
|
graphSessionManager.createSession(requestId2, graphId, tenantId, projectId);
|
|
7493
|
-
|
|
7564
|
+
logger19.info({ sessionId: requestId2, graphId }, "Created GraphSession for message execution");
|
|
7494
7565
|
let graphConfig = null;
|
|
7495
7566
|
try {
|
|
7496
7567
|
graphConfig = await agentsCore.getFullGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
|
|
@@ -7502,7 +7573,7 @@ var ExecutionHandler = class {
|
|
|
7502
7573
|
);
|
|
7503
7574
|
}
|
|
7504
7575
|
} catch (error) {
|
|
7505
|
-
|
|
7576
|
+
logger19.error(
|
|
7506
7577
|
{
|
|
7507
7578
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
7508
7579
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -7518,7 +7589,7 @@ var ExecutionHandler = class {
|
|
|
7518
7589
|
try {
|
|
7519
7590
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
7520
7591
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
7521
|
-
|
|
7592
|
+
logger19.info(
|
|
7522
7593
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
7523
7594
|
"Attempting to create or reuse existing task"
|
|
7524
7595
|
);
|
|
@@ -7541,7 +7612,7 @@ var ExecutionHandler = class {
|
|
|
7541
7612
|
agent_id: currentAgentId
|
|
7542
7613
|
}
|
|
7543
7614
|
});
|
|
7544
|
-
|
|
7615
|
+
logger19.info(
|
|
7545
7616
|
{
|
|
7546
7617
|
taskId,
|
|
7547
7618
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -7550,27 +7621,27 @@ var ExecutionHandler = class {
|
|
|
7550
7621
|
);
|
|
7551
7622
|
} catch (error) {
|
|
7552
7623
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
7553
|
-
|
|
7624
|
+
logger19.info(
|
|
7554
7625
|
{ taskId, error: error.message },
|
|
7555
7626
|
"Task already exists, fetching existing task"
|
|
7556
7627
|
);
|
|
7557
7628
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
7558
7629
|
if (existingTask) {
|
|
7559
7630
|
task = existingTask;
|
|
7560
|
-
|
|
7631
|
+
logger19.info(
|
|
7561
7632
|
{ taskId, existingTask },
|
|
7562
7633
|
"Successfully reused existing task from race condition"
|
|
7563
7634
|
);
|
|
7564
7635
|
} else {
|
|
7565
|
-
|
|
7636
|
+
logger19.error({ taskId, error }, "Task constraint failed but task not found");
|
|
7566
7637
|
throw error;
|
|
7567
7638
|
}
|
|
7568
7639
|
} else {
|
|
7569
|
-
|
|
7640
|
+
logger19.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
7570
7641
|
throw error;
|
|
7571
7642
|
}
|
|
7572
7643
|
}
|
|
7573
|
-
|
|
7644
|
+
logger19.debug(
|
|
7574
7645
|
{
|
|
7575
7646
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7576
7647
|
executionType: "create_initial_task",
|
|
@@ -7588,7 +7659,7 @@ var ExecutionHandler = class {
|
|
|
7588
7659
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
7589
7660
|
while (iterations < maxTransfers) {
|
|
7590
7661
|
iterations++;
|
|
7591
|
-
|
|
7662
|
+
logger19.info(
|
|
7592
7663
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
7593
7664
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
7594
7665
|
);
|
|
@@ -7596,10 +7667,10 @@ var ExecutionHandler = class {
|
|
|
7596
7667
|
scopes: { tenantId, projectId },
|
|
7597
7668
|
conversationId
|
|
7598
7669
|
});
|
|
7599
|
-
|
|
7670
|
+
logger19.info({ activeAgent }, "activeAgent");
|
|
7600
7671
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
7601
7672
|
currentAgentId = activeAgent.activeAgentId;
|
|
7602
|
-
|
|
7673
|
+
logger19.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
7603
7674
|
}
|
|
7604
7675
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
7605
7676
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -7640,13 +7711,13 @@ var ExecutionHandler = class {
|
|
|
7640
7711
|
});
|
|
7641
7712
|
if (!messageResponse?.result) {
|
|
7642
7713
|
errorCount++;
|
|
7643
|
-
|
|
7714
|
+
logger19.error(
|
|
7644
7715
|
{ currentAgentId, iterations, errorCount },
|
|
7645
7716
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7646
7717
|
);
|
|
7647
7718
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7648
7719
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7649
|
-
|
|
7720
|
+
logger19.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7650
7721
|
await sseHelper.writeError(errorMessage2);
|
|
7651
7722
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7652
7723
|
if (task) {
|
|
@@ -7672,7 +7743,7 @@ var ExecutionHandler = class {
|
|
|
7672
7743
|
const transferResponse = messageResponse.result;
|
|
7673
7744
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
7674
7745
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
7675
|
-
|
|
7746
|
+
logger19.info({ targetAgentId, transferReason }, "transfer response");
|
|
7676
7747
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
7677
7748
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
7678
7749
|
projectId,
|
|
@@ -7683,7 +7754,7 @@ var ExecutionHandler = class {
|
|
|
7683
7754
|
if (success) {
|
|
7684
7755
|
fromAgentId = currentAgentId;
|
|
7685
7756
|
currentAgentId = newAgentId;
|
|
7686
|
-
|
|
7757
|
+
logger19.info(
|
|
7687
7758
|
{
|
|
7688
7759
|
transferFrom: fromAgentId,
|
|
7689
7760
|
transferTo: currentAgentId,
|
|
@@ -7701,7 +7772,7 @@ var ExecutionHandler = class {
|
|
|
7701
7772
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
7702
7773
|
if (graphSessionData) {
|
|
7703
7774
|
const sessionSummary = graphSessionData.getSummary();
|
|
7704
|
-
|
|
7775
|
+
logger19.info(sessionSummary, "GraphSession data after completion");
|
|
7705
7776
|
}
|
|
7706
7777
|
let textContent = "";
|
|
7707
7778
|
for (const part of responseParts) {
|
|
@@ -7755,22 +7826,22 @@ var ExecutionHandler = class {
|
|
|
7755
7826
|
}
|
|
7756
7827
|
});
|
|
7757
7828
|
const updateTaskEnd = Date.now();
|
|
7758
|
-
|
|
7829
|
+
logger19.info(
|
|
7759
7830
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
7760
7831
|
"Completed updateTask operation"
|
|
7761
7832
|
);
|
|
7762
7833
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
7763
7834
|
await sseHelper.complete();
|
|
7764
|
-
|
|
7835
|
+
logger19.info({}, "Ending GraphSession and cleaning up");
|
|
7765
7836
|
graphSessionManager.endSession(requestId2);
|
|
7766
|
-
|
|
7837
|
+
logger19.info({}, "Cleaning up streamHelper");
|
|
7767
7838
|
unregisterStreamHelper(requestId2);
|
|
7768
7839
|
let response;
|
|
7769
7840
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
7770
7841
|
const captured = sseHelper.getCapturedResponse();
|
|
7771
7842
|
response = captured.text || "No response content";
|
|
7772
7843
|
}
|
|
7773
|
-
|
|
7844
|
+
logger19.info({}, "ExecutionHandler returning success");
|
|
7774
7845
|
return { success: true, iterations, response };
|
|
7775
7846
|
} catch (error) {
|
|
7776
7847
|
agentsCore.setSpanWithError(span, error);
|
|
@@ -7781,13 +7852,13 @@ var ExecutionHandler = class {
|
|
|
7781
7852
|
});
|
|
7782
7853
|
}
|
|
7783
7854
|
errorCount++;
|
|
7784
|
-
|
|
7855
|
+
logger19.warn(
|
|
7785
7856
|
{ iterations, errorCount },
|
|
7786
7857
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7787
7858
|
);
|
|
7788
7859
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7789
7860
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7790
|
-
|
|
7861
|
+
logger19.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7791
7862
|
await sseHelper.writeError(errorMessage2);
|
|
7792
7863
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7793
7864
|
if (task) {
|
|
@@ -7809,7 +7880,7 @@ var ExecutionHandler = class {
|
|
|
7809
7880
|
}
|
|
7810
7881
|
}
|
|
7811
7882
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
7812
|
-
|
|
7883
|
+
logger19.error({ maxTransfers, iterations }, errorMessage);
|
|
7813
7884
|
await sseHelper.writeError(errorMessage);
|
|
7814
7885
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
7815
7886
|
if (task) {
|
|
@@ -7829,7 +7900,7 @@ var ExecutionHandler = class {
|
|
|
7829
7900
|
unregisterStreamHelper(requestId2);
|
|
7830
7901
|
return { success: false, error: errorMessage, iterations };
|
|
7831
7902
|
} catch (error) {
|
|
7832
|
-
|
|
7903
|
+
logger19.error({ error }, "Error in execution handler");
|
|
7833
7904
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
7834
7905
|
await sseHelper.writeError(`Execution error: ${errorMessage}`);
|
|
7835
7906
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
@@ -7855,7 +7926,7 @@ var ExecutionHandler = class {
|
|
|
7855
7926
|
|
|
7856
7927
|
// src/routes/chat.ts
|
|
7857
7928
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
7858
|
-
var
|
|
7929
|
+
var logger20 = agentsCore.getLogger("completionsHandler");
|
|
7859
7930
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
7860
7931
|
method: "post",
|
|
7861
7932
|
path: "/completions",
|
|
@@ -7973,7 +8044,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7973
8044
|
tracestate: c.req.header("tracestate"),
|
|
7974
8045
|
baggage: c.req.header("baggage")
|
|
7975
8046
|
};
|
|
7976
|
-
|
|
8047
|
+
logger20.info(
|
|
7977
8048
|
{
|
|
7978
8049
|
otelHeaders,
|
|
7979
8050
|
path: c.req.path,
|
|
@@ -8059,7 +8130,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8059
8130
|
dbClient_default,
|
|
8060
8131
|
credentialStores
|
|
8061
8132
|
);
|
|
8062
|
-
|
|
8133
|
+
logger20.info(
|
|
8063
8134
|
{
|
|
8064
8135
|
tenantId,
|
|
8065
8136
|
graphId,
|
|
@@ -8105,7 +8176,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8105
8176
|
return streaming.streamSSE(c, async (stream2) => {
|
|
8106
8177
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
8107
8178
|
await sseHelper.writeRole();
|
|
8108
|
-
|
|
8179
|
+
logger20.info({ agentId }, "Starting execution");
|
|
8109
8180
|
const executionHandler = new ExecutionHandler();
|
|
8110
8181
|
const result = await executionHandler.execute({
|
|
8111
8182
|
executionContext,
|
|
@@ -8115,7 +8186,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8115
8186
|
requestId: requestId2,
|
|
8116
8187
|
sseHelper
|
|
8117
8188
|
});
|
|
8118
|
-
|
|
8189
|
+
logger20.info(
|
|
8119
8190
|
{ result },
|
|
8120
8191
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8121
8192
|
);
|
|
@@ -8151,7 +8222,7 @@ var chat_default = app2;
|
|
|
8151
8222
|
// src/routes/chatDataStream.ts
|
|
8152
8223
|
init_dbClient();
|
|
8153
8224
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
8154
|
-
var
|
|
8225
|
+
var logger21 = agentsCore.getLogger("chatDataStream");
|
|
8155
8226
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
8156
8227
|
method: "post",
|
|
8157
8228
|
path: "/chat",
|
|
@@ -8256,7 +8327,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8256
8327
|
);
|
|
8257
8328
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
8258
8329
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
8259
|
-
|
|
8330
|
+
logger21.info({ userText, lastUserMessage }, "userText");
|
|
8260
8331
|
const messageSpan = api.trace.getActiveSpan();
|
|
8261
8332
|
if (messageSpan) {
|
|
8262
8333
|
messageSpan.setAttributes({
|
|
@@ -8298,7 +8369,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8298
8369
|
await streamHelper.writeError("Unable to process request");
|
|
8299
8370
|
}
|
|
8300
8371
|
} catch (err) {
|
|
8301
|
-
|
|
8372
|
+
logger21.error({ err }, "Streaming error");
|
|
8302
8373
|
await streamHelper.writeError("Internal server error");
|
|
8303
8374
|
} finally {
|
|
8304
8375
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -8319,7 +8390,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8319
8390
|
)
|
|
8320
8391
|
);
|
|
8321
8392
|
} catch (error) {
|
|
8322
|
-
|
|
8393
|
+
logger21.error({ error }, "chatDataStream error");
|
|
8323
8394
|
return c.json({ error: "Failed to process chat completion" }, 500);
|
|
8324
8395
|
}
|
|
8325
8396
|
});
|
|
@@ -8330,7 +8401,7 @@ init_dbClient();
|
|
|
8330
8401
|
function createMCPSchema(schema) {
|
|
8331
8402
|
return schema;
|
|
8332
8403
|
}
|
|
8333
|
-
var
|
|
8404
|
+
var logger22 = agentsCore.getLogger("mcp");
|
|
8334
8405
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
8335
8406
|
constructor() {
|
|
8336
8407
|
__publicField(this, "mockRes");
|
|
@@ -8385,21 +8456,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
8385
8456
|
id: 0
|
|
8386
8457
|
});
|
|
8387
8458
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
8388
|
-
|
|
8459
|
+
logger22.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
8389
8460
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
8390
8461
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
8391
8462
|
try {
|
|
8392
8463
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
8393
|
-
|
|
8464
|
+
logger22.info({ sessionId }, "Successfully spoofed initialization");
|
|
8394
8465
|
} catch (spoofError) {
|
|
8395
|
-
|
|
8466
|
+
logger22.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
8396
8467
|
}
|
|
8397
8468
|
};
|
|
8398
8469
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
8399
8470
|
const sessionId = req.headers["mcp-session-id"];
|
|
8400
|
-
|
|
8471
|
+
logger22.info({ sessionId }, "Received MCP session ID");
|
|
8401
8472
|
if (!sessionId) {
|
|
8402
|
-
|
|
8473
|
+
logger22.info({ body }, "Missing session ID");
|
|
8403
8474
|
res.writeHead(400).end(
|
|
8404
8475
|
JSON.stringify({
|
|
8405
8476
|
jsonrpc: "2.0",
|
|
@@ -8425,7 +8496,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8425
8496
|
scopes: { tenantId, projectId },
|
|
8426
8497
|
conversationId: sessionId
|
|
8427
8498
|
});
|
|
8428
|
-
|
|
8499
|
+
logger22.info(
|
|
8429
8500
|
{
|
|
8430
8501
|
sessionId,
|
|
8431
8502
|
conversationFound: !!conversation,
|
|
@@ -8436,7 +8507,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8436
8507
|
"Conversation lookup result"
|
|
8437
8508
|
);
|
|
8438
8509
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
8439
|
-
|
|
8510
|
+
logger22.info(
|
|
8440
8511
|
{ sessionId, conversationId: conversation?.id },
|
|
8441
8512
|
"MCP session not found or invalid"
|
|
8442
8513
|
);
|
|
@@ -8497,7 +8568,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
8497
8568
|
requestId: requestId2,
|
|
8498
8569
|
sseHelper: mcpStreamHelper
|
|
8499
8570
|
});
|
|
8500
|
-
|
|
8571
|
+
logger22.info(
|
|
8501
8572
|
{ result },
|
|
8502
8573
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8503
8574
|
);
|
|
@@ -8571,7 +8642,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
8571
8642
|
dbClient_default,
|
|
8572
8643
|
credentialStores
|
|
8573
8644
|
);
|
|
8574
|
-
|
|
8645
|
+
logger22.info(
|
|
8575
8646
|
{
|
|
8576
8647
|
tenantId,
|
|
8577
8648
|
graphId,
|
|
@@ -8632,7 +8703,7 @@ var validateRequestParameters = (c) => {
|
|
|
8632
8703
|
};
|
|
8633
8704
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
8634
8705
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8635
|
-
|
|
8706
|
+
logger22.info({ body }, "Received initialization request");
|
|
8636
8707
|
const sessionId = nanoid.nanoid();
|
|
8637
8708
|
const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
8638
8709
|
scopes: { tenantId, projectId },
|
|
@@ -8663,7 +8734,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8663
8734
|
}
|
|
8664
8735
|
}
|
|
8665
8736
|
});
|
|
8666
|
-
|
|
8737
|
+
logger22.info(
|
|
8667
8738
|
{ sessionId, conversationId: conversation.id },
|
|
8668
8739
|
"Created MCP session as conversation"
|
|
8669
8740
|
);
|
|
@@ -8672,9 +8743,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8672
8743
|
});
|
|
8673
8744
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
8674
8745
|
await server.connect(transport);
|
|
8675
|
-
|
|
8746
|
+
logger22.info({ sessionId }, "Server connected for initialization");
|
|
8676
8747
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
8677
|
-
|
|
8748
|
+
logger22.info(
|
|
8678
8749
|
{
|
|
8679
8750
|
sessionId,
|
|
8680
8751
|
bodyMethod: body?.method,
|
|
@@ -8683,7 +8754,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8683
8754
|
"About to handle initialization request"
|
|
8684
8755
|
);
|
|
8685
8756
|
await transport.handleRequest(req, res, body);
|
|
8686
|
-
|
|
8757
|
+
logger22.info({ sessionId }, "Successfully handled initialization request");
|
|
8687
8758
|
return fetchToNode.toFetchResponse(res);
|
|
8688
8759
|
};
|
|
8689
8760
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -8711,8 +8782,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8711
8782
|
sessionId,
|
|
8712
8783
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
8713
8784
|
);
|
|
8714
|
-
|
|
8715
|
-
|
|
8785
|
+
logger22.info({ sessionId }, "Server connected and transport initialized");
|
|
8786
|
+
logger22.info(
|
|
8716
8787
|
{
|
|
8717
8788
|
sessionId,
|
|
8718
8789
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -8726,9 +8797,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8726
8797
|
);
|
|
8727
8798
|
try {
|
|
8728
8799
|
await transport.handleRequest(req, res, body);
|
|
8729
|
-
|
|
8800
|
+
logger22.info({ sessionId }, "Successfully handled MCP request");
|
|
8730
8801
|
} catch (transportError) {
|
|
8731
|
-
|
|
8802
|
+
logger22.error(
|
|
8732
8803
|
{
|
|
8733
8804
|
sessionId,
|
|
8734
8805
|
error: transportError,
|
|
@@ -8779,13 +8850,13 @@ app4.openapi(
|
|
|
8779
8850
|
}
|
|
8780
8851
|
const { executionContext } = paramValidation;
|
|
8781
8852
|
const body = c.get("requestBody") || {};
|
|
8782
|
-
|
|
8853
|
+
logger22.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
8783
8854
|
const isInitRequest = body.method === "initialize";
|
|
8784
8855
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
8785
8856
|
const validatedContext = c.get("validatedContext") || {};
|
|
8786
8857
|
const credentialStores = c.get("credentialStores");
|
|
8787
|
-
|
|
8788
|
-
|
|
8858
|
+
logger22.info({ validatedContext }, "Validated context");
|
|
8859
|
+
logger22.info({ req }, "request");
|
|
8789
8860
|
if (isInitRequest) {
|
|
8790
8861
|
return await handleInitializationRequest(
|
|
8791
8862
|
body,
|
|
@@ -8807,7 +8878,7 @@ app4.openapi(
|
|
|
8807
8878
|
);
|
|
8808
8879
|
}
|
|
8809
8880
|
} catch (e) {
|
|
8810
|
-
|
|
8881
|
+
logger22.error(
|
|
8811
8882
|
{
|
|
8812
8883
|
error: e instanceof Error ? e.message : e,
|
|
8813
8884
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -8819,7 +8890,7 @@ app4.openapi(
|
|
|
8819
8890
|
}
|
|
8820
8891
|
);
|
|
8821
8892
|
app4.get("/", async (c) => {
|
|
8822
|
-
|
|
8893
|
+
logger22.info({}, "Received GET MCP request");
|
|
8823
8894
|
return c.json(
|
|
8824
8895
|
{
|
|
8825
8896
|
jsonrpc: "2.0",
|
|
@@ -8833,7 +8904,7 @@ app4.get("/", async (c) => {
|
|
|
8833
8904
|
);
|
|
8834
8905
|
});
|
|
8835
8906
|
app4.delete("/", async (c) => {
|
|
8836
|
-
|
|
8907
|
+
logger22.info({}, "Received DELETE MCP request");
|
|
8837
8908
|
return c.json(
|
|
8838
8909
|
{
|
|
8839
8910
|
jsonrpc: "2.0",
|
|
@@ -8844,7 +8915,7 @@ app4.delete("/", async (c) => {
|
|
|
8844
8915
|
);
|
|
8845
8916
|
});
|
|
8846
8917
|
var mcp_default = app4;
|
|
8847
|
-
var
|
|
8918
|
+
var logger23 = agentsCore.getLogger("agents-run-api");
|
|
8848
8919
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
8849
8920
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
8850
8921
|
app6.use("*", otel.otel());
|
|
@@ -8860,7 +8931,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8860
8931
|
const body = await c.req.json();
|
|
8861
8932
|
c.set("requestBody", body);
|
|
8862
8933
|
} catch (error) {
|
|
8863
|
-
|
|
8934
|
+
logger23.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
8864
8935
|
}
|
|
8865
8936
|
}
|
|
8866
8937
|
return next();
|
|
@@ -8911,8 +8982,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8911
8982
|
if (!isExpectedError) {
|
|
8912
8983
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
8913
8984
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
8914
|
-
if (
|
|
8915
|
-
|
|
8985
|
+
if (logger23) {
|
|
8986
|
+
logger23.error(
|
|
8916
8987
|
{
|
|
8917
8988
|
error: err,
|
|
8918
8989
|
message: errorMessage,
|
|
@@ -8924,8 +8995,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8924
8995
|
);
|
|
8925
8996
|
}
|
|
8926
8997
|
} else {
|
|
8927
|
-
if (
|
|
8928
|
-
|
|
8998
|
+
if (logger23) {
|
|
8999
|
+
logger23.error(
|
|
8929
9000
|
{
|
|
8930
9001
|
error: err,
|
|
8931
9002
|
path: c.req.path,
|
|
@@ -8942,8 +9013,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8942
9013
|
const response = err.getResponse();
|
|
8943
9014
|
return response;
|
|
8944
9015
|
} catch (responseError) {
|
|
8945
|
-
if (
|
|
8946
|
-
|
|
9016
|
+
if (logger23) {
|
|
9017
|
+
logger23.error({ error: responseError }, "Error while handling HTTPException response");
|
|
8947
9018
|
}
|
|
8948
9019
|
}
|
|
8949
9020
|
}
|
|
@@ -8977,7 +9048,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8977
9048
|
app6.use("*", async (c, next) => {
|
|
8978
9049
|
const executionContext = c.get("executionContext");
|
|
8979
9050
|
if (!executionContext) {
|
|
8980
|
-
|
|
9051
|
+
logger23.debug({}, "Empty execution context");
|
|
8981
9052
|
return next();
|
|
8982
9053
|
}
|
|
8983
9054
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -8986,7 +9057,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8986
9057
|
if (requestBody) {
|
|
8987
9058
|
conversationId = requestBody.conversationId;
|
|
8988
9059
|
if (!conversationId) {
|
|
8989
|
-
|
|
9060
|
+
logger23.debug({ requestBody }, "No conversation ID found in request body");
|
|
8990
9061
|
}
|
|
8991
9062
|
}
|
|
8992
9063
|
const entries = Object.fromEntries(
|
|
@@ -9001,7 +9072,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
9001
9072
|
})
|
|
9002
9073
|
);
|
|
9003
9074
|
if (!Object.keys(entries).length) {
|
|
9004
|
-
|
|
9075
|
+
logger23.debug({}, "Empty entries for baggage");
|
|
9005
9076
|
return next();
|
|
9006
9077
|
}
|
|
9007
9078
|
const bag = Object.entries(entries).reduce(
|