@inkeep/agents-run-api 0.0.0-dev-20250913011433 → 0.0.0-dev-20250913015248
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 +217 -250
- package/dist/index.js +213 -243
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var sdkNode = require('@opentelemetry/sdk-node');
|
|
|
15
15
|
var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
16
16
|
var semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
17
17
|
var resources = require('@opentelemetry/resources');
|
|
18
|
+
var contextAsyncHooks = require('@opentelemetry/context-async-hooks');
|
|
18
19
|
var hono = require('hono');
|
|
19
20
|
var zodOpenapi = require('@hono/zod-openapi');
|
|
20
21
|
var api = require('@opentelemetry/api');
|
|
@@ -23,7 +24,6 @@ var httpException = require('hono/http-exception');
|
|
|
23
24
|
var requestId = require('hono/request-id');
|
|
24
25
|
var honoPino = require('hono-pino');
|
|
25
26
|
var pino = require('pino');
|
|
26
|
-
var async_hooks = require('async_hooks');
|
|
27
27
|
var factory = require('hono/factory');
|
|
28
28
|
var swaggerUi = require('@hono/swagger-ui');
|
|
29
29
|
var streaming = require('hono/streaming');
|
|
@@ -335,6 +335,7 @@ var resource = resources.resourceFromAttributes({
|
|
|
335
335
|
});
|
|
336
336
|
var sdk = new sdkNode.NodeSDK({
|
|
337
337
|
resource,
|
|
338
|
+
contextManager: new contextAsyncHooks.AsyncLocalStorageContextManager(),
|
|
338
339
|
spanProcessors: [new baggageSpanProcessor.BaggageSpanProcessor(baggageSpanProcessor.ALLOW_ALL_BAGGAGE_KEYS), batchProcessor],
|
|
339
340
|
instrumentations: [
|
|
340
341
|
autoInstrumentationsNode.getNodeAutoInstrumentations({
|
|
@@ -361,40 +362,6 @@ var sdk = new sdkNode.NodeSDK({
|
|
|
361
362
|
});
|
|
362
363
|
sdk.start();
|
|
363
364
|
|
|
364
|
-
// src/logger.ts
|
|
365
|
-
init_env();
|
|
366
|
-
var isDevelopment = env.ENVIRONMENT === "development";
|
|
367
|
-
var loggerConfig = {
|
|
368
|
-
level: env.LOG_LEVEL,
|
|
369
|
-
serializers: {
|
|
370
|
-
obj: (value) => ({ ...value })
|
|
371
|
-
},
|
|
372
|
-
redact: ["req.headers.authorization", 'req.headers["x-inkeep-admin-authentication"]'],
|
|
373
|
-
// Only use pino-pretty in development
|
|
374
|
-
...isDevelopment && {
|
|
375
|
-
transport: {
|
|
376
|
-
target: "pino-pretty",
|
|
377
|
-
options: {
|
|
378
|
-
sync: true,
|
|
379
|
-
destination: 1,
|
|
380
|
-
// stdout
|
|
381
|
-
colorize: true,
|
|
382
|
-
translateTime: "SYS:standard"
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
var logger = pino.pino(loggerConfig);
|
|
388
|
-
var asyncLocalStorage = new async_hooks.AsyncLocalStorage();
|
|
389
|
-
function getLogger(name) {
|
|
390
|
-
const store = asyncLocalStorage.getStore();
|
|
391
|
-
const reqId = store?.get("requestId") || void 0;
|
|
392
|
-
if (!reqId) {
|
|
393
|
-
return logger.child({ name });
|
|
394
|
-
}
|
|
395
|
-
return logger.child({ reqId, name });
|
|
396
|
-
}
|
|
397
|
-
|
|
398
365
|
// src/middleware/api-key-auth.ts
|
|
399
366
|
init_dbClient();
|
|
400
367
|
init_env();
|
|
@@ -413,7 +380,7 @@ function createExecutionContext(params) {
|
|
|
413
380
|
}
|
|
414
381
|
|
|
415
382
|
// src/middleware/api-key-auth.ts
|
|
416
|
-
var
|
|
383
|
+
var logger = agentsCore.getLogger("env-key-auth");
|
|
417
384
|
var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
418
385
|
if (c.req.method === "OPTIONS") {
|
|
419
386
|
await next();
|
|
@@ -430,7 +397,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
430
397
|
if (authHeader?.startsWith("Bearer ")) {
|
|
431
398
|
try {
|
|
432
399
|
executionContext = await extractContextFromApiKey(authHeader.substring(7));
|
|
433
|
-
|
|
400
|
+
logger.info({}, "Development/test environment - API key authenticated successfully");
|
|
434
401
|
} catch {
|
|
435
402
|
executionContext = createExecutionContext({
|
|
436
403
|
apiKey: "development",
|
|
@@ -441,7 +408,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
441
408
|
baseUrl,
|
|
442
409
|
agentId
|
|
443
410
|
});
|
|
444
|
-
|
|
411
|
+
logger.info(
|
|
445
412
|
{},
|
|
446
413
|
"Development/test environment - fallback to default context due to invalid API key"
|
|
447
414
|
);
|
|
@@ -456,7 +423,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
456
423
|
baseUrl,
|
|
457
424
|
agentId
|
|
458
425
|
});
|
|
459
|
-
|
|
426
|
+
logger.info(
|
|
460
427
|
{},
|
|
461
428
|
"Development/test environment - no API key provided, using default context"
|
|
462
429
|
);
|
|
@@ -488,13 +455,13 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
488
455
|
agentId
|
|
489
456
|
});
|
|
490
457
|
c.set("executionContext", executionContext);
|
|
491
|
-
|
|
458
|
+
logger.info({}, "Bypass secret authenticated successfully");
|
|
492
459
|
await next();
|
|
493
460
|
return;
|
|
494
461
|
} else if (apiKey) {
|
|
495
462
|
const executionContext = await extractContextFromApiKey(apiKey);
|
|
496
463
|
c.set("executionContext", executionContext);
|
|
497
|
-
|
|
464
|
+
logger.info({}, "API key authenticated successfully");
|
|
498
465
|
await next();
|
|
499
466
|
return;
|
|
500
467
|
} else {
|
|
@@ -511,7 +478,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
511
478
|
try {
|
|
512
479
|
const executionContext = await extractContextFromApiKey(apiKey);
|
|
513
480
|
c.set("executionContext", executionContext);
|
|
514
|
-
|
|
481
|
+
logger.debug(
|
|
515
482
|
{
|
|
516
483
|
tenantId: executionContext.tenantId,
|
|
517
484
|
projectId: executionContext.projectId,
|
|
@@ -524,7 +491,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
524
491
|
if (error instanceof httpException.HTTPException) {
|
|
525
492
|
throw error;
|
|
526
493
|
}
|
|
527
|
-
|
|
494
|
+
logger.error({ error }, "API key authentication error");
|
|
528
495
|
throw new httpException.HTTPException(500, {
|
|
529
496
|
message: "Authentication failed"
|
|
530
497
|
});
|
|
@@ -583,7 +550,7 @@ function setupOpenAPIRoutes(app6) {
|
|
|
583
550
|
|
|
584
551
|
// src/a2a/handlers.ts
|
|
585
552
|
init_dbClient();
|
|
586
|
-
var
|
|
553
|
+
var logger2 = agentsCore.getLogger("a2aHandler");
|
|
587
554
|
async function a2aHandler(c, agent) {
|
|
588
555
|
try {
|
|
589
556
|
const rpcRequest = await c.req.json();
|
|
@@ -685,7 +652,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
685
652
|
messageId: task.id,
|
|
686
653
|
kind: "message"
|
|
687
654
|
});
|
|
688
|
-
|
|
655
|
+
logger2.warn(
|
|
689
656
|
{
|
|
690
657
|
taskId: task.id,
|
|
691
658
|
agentId: agent.agentId,
|
|
@@ -695,7 +662,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
695
662
|
);
|
|
696
663
|
}
|
|
697
664
|
} catch (error) {
|
|
698
|
-
|
|
665
|
+
logger2.error({ error, taskId: task.id }, "Failed to serialize message");
|
|
699
666
|
JSON.stringify({
|
|
700
667
|
error: "Failed to serialize message",
|
|
701
668
|
taskId: task.id,
|
|
@@ -703,7 +670,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
703
670
|
parts: [{ text: "Error in delegation", kind: "text" }]
|
|
704
671
|
});
|
|
705
672
|
}
|
|
706
|
-
|
|
673
|
+
logger2.info(
|
|
707
674
|
{
|
|
708
675
|
originalContextId: params.message.contextId,
|
|
709
676
|
taskContextId: task.context?.conversationId,
|
|
@@ -732,7 +699,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
732
699
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
733
700
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
734
701
|
});
|
|
735
|
-
|
|
702
|
+
logger2.info({ metadata: params.message.metadata }, "message metadata");
|
|
736
703
|
if (params.message.metadata?.fromAgentId || params.message.metadata?.fromExternalAgentId) {
|
|
737
704
|
const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
|
|
738
705
|
try {
|
|
@@ -757,7 +724,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
757
724
|
messageData.toAgentId = agent.agentId;
|
|
758
725
|
}
|
|
759
726
|
await agentsCore.createMessage(dbClient_default)(messageData);
|
|
760
|
-
|
|
727
|
+
logger2.info(
|
|
761
728
|
{
|
|
762
729
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
763
730
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
@@ -769,7 +736,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
769
736
|
"A2A message stored in database"
|
|
770
737
|
);
|
|
771
738
|
} catch (error) {
|
|
772
|
-
|
|
739
|
+
logger2.error(
|
|
773
740
|
{
|
|
774
741
|
error,
|
|
775
742
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
@@ -806,7 +773,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
806
773
|
(part) => part.kind === "data" && part.data && typeof part.data === "object" && part.data.type === "transfer"
|
|
807
774
|
);
|
|
808
775
|
if (transferPart && transferPart.kind === "data" && transferPart.data) {
|
|
809
|
-
|
|
776
|
+
logger2.info({ transferPart }, "transferPart");
|
|
810
777
|
return c.json({
|
|
811
778
|
jsonrpc: "2.0",
|
|
812
779
|
result: {
|
|
@@ -1231,10 +1198,10 @@ function statusUpdateOp(ctx) {
|
|
|
1231
1198
|
ctx
|
|
1232
1199
|
};
|
|
1233
1200
|
}
|
|
1234
|
-
var
|
|
1201
|
+
var logger3 = agentsCore.getLogger("DataComponentSchema");
|
|
1235
1202
|
function jsonSchemaToZod(jsonSchema) {
|
|
1236
1203
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
1237
|
-
|
|
1204
|
+
logger3.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
1238
1205
|
return z5.z.string();
|
|
1239
1206
|
}
|
|
1240
1207
|
switch (jsonSchema.type) {
|
|
@@ -1261,7 +1228,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
1261
1228
|
case "null":
|
|
1262
1229
|
return z5.z.null();
|
|
1263
1230
|
default:
|
|
1264
|
-
|
|
1231
|
+
logger3.warn(
|
|
1265
1232
|
{
|
|
1266
1233
|
unsupportedType: jsonSchema.type,
|
|
1267
1234
|
schema: jsonSchema
|
|
@@ -1273,7 +1240,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
1273
1240
|
}
|
|
1274
1241
|
|
|
1275
1242
|
// src/utils/artifact-component-schema.ts
|
|
1276
|
-
getLogger("ArtifactComponentSchema");
|
|
1243
|
+
agentsCore.getLogger("ArtifactComponentSchema");
|
|
1277
1244
|
var _ArtifactReferenceSchema = class _ArtifactReferenceSchema {
|
|
1278
1245
|
/**
|
|
1279
1246
|
* Get the standard Zod schema for artifact reference components
|
|
@@ -1315,7 +1282,7 @@ __publicField(_ArtifactReferenceSchema, "ARTIFACT_PROPS_SCHEMA", {
|
|
|
1315
1282
|
required: ["artifact_id", "task_id"]
|
|
1316
1283
|
});
|
|
1317
1284
|
var ArtifactReferenceSchema = _ArtifactReferenceSchema;
|
|
1318
|
-
var
|
|
1285
|
+
var logger4 = agentsCore.getLogger("ModelFactory");
|
|
1319
1286
|
var _ModelFactory = class _ModelFactory {
|
|
1320
1287
|
/**
|
|
1321
1288
|
* Create a language model instance from configuration
|
|
@@ -1330,7 +1297,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1330
1297
|
const modelSettings = config2;
|
|
1331
1298
|
const modelString = modelSettings.model.trim();
|
|
1332
1299
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1333
|
-
|
|
1300
|
+
logger4.debug(
|
|
1334
1301
|
{
|
|
1335
1302
|
provider,
|
|
1336
1303
|
model: modelName,
|
|
@@ -1351,7 +1318,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1351
1318
|
);
|
|
1352
1319
|
}
|
|
1353
1320
|
} catch (error) {
|
|
1354
|
-
|
|
1321
|
+
logger4.error(
|
|
1355
1322
|
{
|
|
1356
1323
|
provider,
|
|
1357
1324
|
model: modelName,
|
|
@@ -1374,7 +1341,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1374
1341
|
const [provider, ...modelParts] = modelString.split("/");
|
|
1375
1342
|
const normalizedProvider = provider.toLowerCase();
|
|
1376
1343
|
if (!_ModelFactory.SUPPORTED_PROVIDERS.includes(normalizedProvider)) {
|
|
1377
|
-
|
|
1344
|
+
logger4.warn(
|
|
1378
1345
|
{ provider: normalizedProvider, modelName: modelParts.join("/") },
|
|
1379
1346
|
"Unsupported provider detected, falling back to anthropic"
|
|
1380
1347
|
);
|
|
@@ -1403,14 +1370,14 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1403
1370
|
anthropicConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1404
1371
|
}
|
|
1405
1372
|
if (providerOptions?.gateway) {
|
|
1406
|
-
|
|
1373
|
+
logger4.info(
|
|
1407
1374
|
{ gateway: providerOptions.gateway },
|
|
1408
1375
|
"Setting up AI Gateway for Anthropic model"
|
|
1409
1376
|
);
|
|
1410
1377
|
Object.assign(anthropicConfig, providerOptions.gateway);
|
|
1411
1378
|
}
|
|
1412
1379
|
if (Object.keys(anthropicConfig).length > 0) {
|
|
1413
|
-
|
|
1380
|
+
logger4.info({ config: anthropicConfig }, "Applying custom Anthropic provider configuration");
|
|
1414
1381
|
const provider = anthropic.createAnthropic(anthropicConfig);
|
|
1415
1382
|
return provider(modelName);
|
|
1416
1383
|
}
|
|
@@ -1425,11 +1392,11 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1425
1392
|
openaiConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1426
1393
|
}
|
|
1427
1394
|
if (providerOptions?.gateway) {
|
|
1428
|
-
|
|
1395
|
+
logger4.info({ gateway: providerOptions.gateway }, "Setting up AI Gateway for OpenAI model");
|
|
1429
1396
|
Object.assign(openaiConfig, providerOptions.gateway);
|
|
1430
1397
|
}
|
|
1431
1398
|
if (Object.keys(openaiConfig).length > 0) {
|
|
1432
|
-
|
|
1399
|
+
logger4.info({ config: openaiConfig }, "Applying custom OpenAI provider configuration");
|
|
1433
1400
|
const provider = openai.createOpenAI(openaiConfig);
|
|
1434
1401
|
return provider(modelName);
|
|
1435
1402
|
}
|
|
@@ -1523,7 +1490,7 @@ function unregisterStreamHelper(requestId2) {
|
|
|
1523
1490
|
}
|
|
1524
1491
|
|
|
1525
1492
|
// src/utils/graph-session.ts
|
|
1526
|
-
var
|
|
1493
|
+
var logger5 = agentsCore.getLogger("GraphSession");
|
|
1527
1494
|
var GraphSession = class {
|
|
1528
1495
|
// Track scheduled timeouts for cleanup
|
|
1529
1496
|
constructor(sessionId, messageId, graphId, tenantId, projectId) {
|
|
@@ -1547,7 +1514,7 @@ var GraphSession = class {
|
|
|
1547
1514
|
__publicField(this, "MAX_PENDING_ARTIFACTS", 100);
|
|
1548
1515
|
// Prevent unbounded growth
|
|
1549
1516
|
__publicField(this, "scheduledTimeouts");
|
|
1550
|
-
|
|
1517
|
+
logger5.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
1551
1518
|
}
|
|
1552
1519
|
/**
|
|
1553
1520
|
* Initialize status updates for this session
|
|
@@ -1569,7 +1536,7 @@ var GraphSession = class {
|
|
|
1569
1536
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
1570
1537
|
this.statusUpdateTimer = setInterval(async () => {
|
|
1571
1538
|
if (!this.statusUpdateState || this.isEnded) {
|
|
1572
|
-
|
|
1539
|
+
logger5.debug(
|
|
1573
1540
|
{ sessionId: this.sessionId },
|
|
1574
1541
|
"Timer triggered but session already cleaned up or ended"
|
|
1575
1542
|
);
|
|
@@ -1581,7 +1548,7 @@ var GraphSession = class {
|
|
|
1581
1548
|
}
|
|
1582
1549
|
await this.checkAndSendTimeBasedUpdate();
|
|
1583
1550
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
1584
|
-
|
|
1551
|
+
logger5.info(
|
|
1585
1552
|
{
|
|
1586
1553
|
sessionId: this.sessionId,
|
|
1587
1554
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -1595,7 +1562,7 @@ var GraphSession = class {
|
|
|
1595
1562
|
*/
|
|
1596
1563
|
recordEvent(eventType, agentId, data) {
|
|
1597
1564
|
if (this.isEnded) {
|
|
1598
|
-
|
|
1565
|
+
logger5.debug(
|
|
1599
1566
|
{
|
|
1600
1567
|
sessionId: this.sessionId,
|
|
1601
1568
|
eventType,
|
|
@@ -1615,7 +1582,7 @@ var GraphSession = class {
|
|
|
1615
1582
|
if (eventType === "artifact_saved" && data.pendingGeneration) {
|
|
1616
1583
|
const artifactId = data.artifactId;
|
|
1617
1584
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
1618
|
-
|
|
1585
|
+
logger5.warn(
|
|
1619
1586
|
{
|
|
1620
1587
|
sessionId: this.sessionId,
|
|
1621
1588
|
artifactId,
|
|
@@ -1636,7 +1603,7 @@ var GraphSession = class {
|
|
|
1636
1603
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
1637
1604
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
1638
1605
|
this.pendingArtifacts.delete(artifactId);
|
|
1639
|
-
|
|
1606
|
+
logger5.error(
|
|
1640
1607
|
{
|
|
1641
1608
|
sessionId: this.sessionId,
|
|
1642
1609
|
artifactId,
|
|
@@ -1648,7 +1615,7 @@ var GraphSession = class {
|
|
|
1648
1615
|
"Artifact processing failed after max retries, giving up"
|
|
1649
1616
|
);
|
|
1650
1617
|
} else {
|
|
1651
|
-
|
|
1618
|
+
logger5.warn(
|
|
1652
1619
|
{
|
|
1653
1620
|
sessionId: this.sessionId,
|
|
1654
1621
|
artifactId,
|
|
@@ -1670,14 +1637,14 @@ var GraphSession = class {
|
|
|
1670
1637
|
*/
|
|
1671
1638
|
checkStatusUpdates() {
|
|
1672
1639
|
if (this.isEnded) {
|
|
1673
|
-
|
|
1640
|
+
logger5.debug(
|
|
1674
1641
|
{ sessionId: this.sessionId },
|
|
1675
1642
|
"Session has ended - skipping status update check"
|
|
1676
1643
|
);
|
|
1677
1644
|
return;
|
|
1678
1645
|
}
|
|
1679
1646
|
if (!this.statusUpdateState) {
|
|
1680
|
-
|
|
1647
|
+
logger5.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
1681
1648
|
return;
|
|
1682
1649
|
}
|
|
1683
1650
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -1688,11 +1655,11 @@ var GraphSession = class {
|
|
|
1688
1655
|
*/
|
|
1689
1656
|
async checkAndSendTimeBasedUpdate() {
|
|
1690
1657
|
if (this.isEnded) {
|
|
1691
|
-
|
|
1658
|
+
logger5.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
1692
1659
|
return;
|
|
1693
1660
|
}
|
|
1694
1661
|
if (!this.statusUpdateState) {
|
|
1695
|
-
|
|
1662
|
+
logger5.debug(
|
|
1696
1663
|
{ sessionId: this.sessionId },
|
|
1697
1664
|
"No status updates configured for time-based check"
|
|
1698
1665
|
);
|
|
@@ -1705,7 +1672,7 @@ var GraphSession = class {
|
|
|
1705
1672
|
try {
|
|
1706
1673
|
await this.generateAndSendUpdate();
|
|
1707
1674
|
} catch (error) {
|
|
1708
|
-
|
|
1675
|
+
logger5.error(
|
|
1709
1676
|
{
|
|
1710
1677
|
sessionId: this.sessionId,
|
|
1711
1678
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1798,29 +1765,29 @@ var GraphSession = class {
|
|
|
1798
1765
|
*/
|
|
1799
1766
|
async generateAndSendUpdate() {
|
|
1800
1767
|
if (this.isEnded) {
|
|
1801
|
-
|
|
1768
|
+
logger5.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
1802
1769
|
return;
|
|
1803
1770
|
}
|
|
1804
1771
|
if (this.isTextStreaming) {
|
|
1805
|
-
|
|
1772
|
+
logger5.debug(
|
|
1806
1773
|
{ sessionId: this.sessionId },
|
|
1807
1774
|
"Text is currently streaming - skipping status update"
|
|
1808
1775
|
);
|
|
1809
1776
|
return;
|
|
1810
1777
|
}
|
|
1811
1778
|
if (this.isGeneratingUpdate) {
|
|
1812
|
-
|
|
1779
|
+
logger5.debug(
|
|
1813
1780
|
{ sessionId: this.sessionId },
|
|
1814
1781
|
"Update already in progress - skipping duplicate generation"
|
|
1815
1782
|
);
|
|
1816
1783
|
return;
|
|
1817
1784
|
}
|
|
1818
1785
|
if (!this.statusUpdateState) {
|
|
1819
|
-
|
|
1786
|
+
logger5.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
1820
1787
|
return;
|
|
1821
1788
|
}
|
|
1822
1789
|
if (!this.graphId) {
|
|
1823
|
-
|
|
1790
|
+
logger5.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
1824
1791
|
return;
|
|
1825
1792
|
}
|
|
1826
1793
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -1833,7 +1800,7 @@ var GraphSession = class {
|
|
|
1833
1800
|
try {
|
|
1834
1801
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
1835
1802
|
if (!streamHelper) {
|
|
1836
|
-
|
|
1803
|
+
logger5.warn(
|
|
1837
1804
|
{ sessionId: this.sessionId },
|
|
1838
1805
|
"No stream helper found - cannot send status update"
|
|
1839
1806
|
);
|
|
@@ -1854,7 +1821,7 @@ var GraphSession = class {
|
|
|
1854
1821
|
if (result.operations && result.operations.length > 0) {
|
|
1855
1822
|
for (const op of result.operations) {
|
|
1856
1823
|
if (!op || !op.type || !op.data || Object.keys(op.data).length === 0) {
|
|
1857
|
-
|
|
1824
|
+
logger5.warn(
|
|
1858
1825
|
{
|
|
1859
1826
|
sessionId: this.sessionId,
|
|
1860
1827
|
operation: op
|
|
@@ -1907,7 +1874,7 @@ var GraphSession = class {
|
|
|
1907
1874
|
this.previousSummaries.shift();
|
|
1908
1875
|
}
|
|
1909
1876
|
if (!operation || !operation.type || !operation.ctx) {
|
|
1910
|
-
|
|
1877
|
+
logger5.warn(
|
|
1911
1878
|
{
|
|
1912
1879
|
sessionId: this.sessionId,
|
|
1913
1880
|
operation
|
|
@@ -1922,7 +1889,7 @@ var GraphSession = class {
|
|
|
1922
1889
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
1923
1890
|
}
|
|
1924
1891
|
} catch (error) {
|
|
1925
|
-
|
|
1892
|
+
logger5.error(
|
|
1926
1893
|
{
|
|
1927
1894
|
sessionId: this.sessionId,
|
|
1928
1895
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -1960,7 +1927,7 @@ var GraphSession = class {
|
|
|
1960
1927
|
this.releaseUpdateLock();
|
|
1961
1928
|
}
|
|
1962
1929
|
} catch (error) {
|
|
1963
|
-
|
|
1930
|
+
logger5.error(
|
|
1964
1931
|
{
|
|
1965
1932
|
sessionId: this.sessionId,
|
|
1966
1933
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2037,7 +2004,7 @@ User's Question/Context:
|
|
|
2037
2004
|
${conversationHistory}
|
|
2038
2005
|
` : "";
|
|
2039
2006
|
} catch (error) {
|
|
2040
|
-
|
|
2007
|
+
logger5.warn(
|
|
2041
2008
|
{ sessionId: this.sessionId, error },
|
|
2042
2009
|
"Failed to fetch conversation history for status update"
|
|
2043
2010
|
);
|
|
@@ -2089,7 +2056,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2089
2056
|
return text.trim();
|
|
2090
2057
|
} catch (error) {
|
|
2091
2058
|
agentsCore.setSpanWithError(span, error);
|
|
2092
|
-
|
|
2059
|
+
logger5.error({ error }, "Failed to generate summary, using fallback");
|
|
2093
2060
|
return this.generateFallbackSummary(newEvents, elapsedTime);
|
|
2094
2061
|
} finally {
|
|
2095
2062
|
span.end();
|
|
@@ -2135,7 +2102,7 @@ User's Question/Context:
|
|
|
2135
2102
|
${conversationHistory}
|
|
2136
2103
|
` : "";
|
|
2137
2104
|
} catch (error) {
|
|
2138
|
-
|
|
2105
|
+
logger5.warn(
|
|
2139
2106
|
{ sessionId: this.sessionId, error },
|
|
2140
2107
|
"Failed to fetch conversation history for structured status update"
|
|
2141
2108
|
);
|
|
@@ -2234,7 +2201,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2234
2201
|
return { operations };
|
|
2235
2202
|
} catch (error) {
|
|
2236
2203
|
agentsCore.setSpanWithError(span, error);
|
|
2237
|
-
|
|
2204
|
+
logger5.error({ error }, "Failed to generate structured update, using fallback");
|
|
2238
2205
|
return { operations: [] };
|
|
2239
2206
|
} finally {
|
|
2240
2207
|
span.end();
|
|
@@ -2561,7 +2528,7 @@ Make it specific and relevant.`;
|
|
|
2561
2528
|
taskId: artifactData.taskId,
|
|
2562
2529
|
artifacts: [artifactToSave]
|
|
2563
2530
|
});
|
|
2564
|
-
|
|
2531
|
+
logger5.info(
|
|
2565
2532
|
{
|
|
2566
2533
|
sessionId: this.sessionId,
|
|
2567
2534
|
artifactId: artifactData.artifactId,
|
|
@@ -2578,7 +2545,7 @@ Make it specific and relevant.`;
|
|
|
2578
2545
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
2579
2546
|
} catch (error) {
|
|
2580
2547
|
agentsCore.setSpanWithError(span, error);
|
|
2581
|
-
|
|
2548
|
+
logger5.error(
|
|
2582
2549
|
{
|
|
2583
2550
|
sessionId: this.sessionId,
|
|
2584
2551
|
artifactId: artifactData.artifactId,
|
|
@@ -2614,7 +2581,7 @@ Make it specific and relevant.`;
|
|
|
2614
2581
|
taskId: artifactData.taskId,
|
|
2615
2582
|
artifacts: [fallbackArtifact]
|
|
2616
2583
|
});
|
|
2617
|
-
|
|
2584
|
+
logger5.info(
|
|
2618
2585
|
{
|
|
2619
2586
|
sessionId: this.sessionId,
|
|
2620
2587
|
artifactId: artifactData.artifactId
|
|
@@ -2623,7 +2590,7 @@ Make it specific and relevant.`;
|
|
|
2623
2590
|
);
|
|
2624
2591
|
}
|
|
2625
2592
|
} catch (fallbackError) {
|
|
2626
|
-
|
|
2593
|
+
logger5.error(
|
|
2627
2594
|
{
|
|
2628
2595
|
sessionId: this.sessionId,
|
|
2629
2596
|
artifactId: artifactData.artifactId,
|
|
@@ -2650,7 +2617,7 @@ var GraphSessionManager = class {
|
|
|
2650
2617
|
const sessionId = messageId;
|
|
2651
2618
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId);
|
|
2652
2619
|
this.sessions.set(sessionId, session);
|
|
2653
|
-
|
|
2620
|
+
logger5.info({ sessionId, messageId, graphId, tenantId, projectId }, "GraphSession created");
|
|
2654
2621
|
return sessionId;
|
|
2655
2622
|
}
|
|
2656
2623
|
/**
|
|
@@ -2661,7 +2628,7 @@ var GraphSessionManager = class {
|
|
|
2661
2628
|
if (session) {
|
|
2662
2629
|
session.initializeStatusUpdates(config2, summarizerModel);
|
|
2663
2630
|
} else {
|
|
2664
|
-
|
|
2631
|
+
logger5.error(
|
|
2665
2632
|
{
|
|
2666
2633
|
sessionId,
|
|
2667
2634
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -2682,7 +2649,7 @@ var GraphSessionManager = class {
|
|
|
2682
2649
|
recordEvent(sessionId, eventType, agentId, data) {
|
|
2683
2650
|
const session = this.sessions.get(sessionId);
|
|
2684
2651
|
if (!session) {
|
|
2685
|
-
|
|
2652
|
+
logger5.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
2686
2653
|
return;
|
|
2687
2654
|
}
|
|
2688
2655
|
session.recordEvent(eventType, agentId, data);
|
|
@@ -2693,12 +2660,12 @@ var GraphSessionManager = class {
|
|
|
2693
2660
|
endSession(sessionId) {
|
|
2694
2661
|
const session = this.sessions.get(sessionId);
|
|
2695
2662
|
if (!session) {
|
|
2696
|
-
|
|
2663
|
+
logger5.warn({ sessionId }, "Attempted to end non-existent session");
|
|
2697
2664
|
return [];
|
|
2698
2665
|
}
|
|
2699
2666
|
const events = session.getEvents();
|
|
2700
2667
|
const summary = session.getSummary();
|
|
2701
|
-
|
|
2668
|
+
logger5.info({ sessionId, summary }, "GraphSession ended");
|
|
2702
2669
|
session.cleanup();
|
|
2703
2670
|
this.sessions.delete(sessionId);
|
|
2704
2671
|
return events;
|
|
@@ -2727,7 +2694,7 @@ var graphSessionManager = new GraphSessionManager();
|
|
|
2727
2694
|
|
|
2728
2695
|
// src/utils/artifact-parser.ts
|
|
2729
2696
|
init_dbClient();
|
|
2730
|
-
var
|
|
2697
|
+
var logger6 = agentsCore.getLogger("ArtifactParser");
|
|
2731
2698
|
var _ArtifactParser = class _ArtifactParser {
|
|
2732
2699
|
constructor(tenantId) {
|
|
2733
2700
|
this.tenantId = tenantId;
|
|
@@ -2793,7 +2760,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2793
2760
|
id: taskId
|
|
2794
2761
|
});
|
|
2795
2762
|
if (!task) {
|
|
2796
|
-
|
|
2763
|
+
logger6.warn({ taskId }, "Task not found when fetching artifacts");
|
|
2797
2764
|
continue;
|
|
2798
2765
|
}
|
|
2799
2766
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2805,9 +2772,9 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2805
2772
|
artifacts.set(key, artifact);
|
|
2806
2773
|
}
|
|
2807
2774
|
}
|
|
2808
|
-
|
|
2775
|
+
logger6.debug({ contextId, count: artifacts.size }, "Loaded context artifacts");
|
|
2809
2776
|
} catch (error) {
|
|
2810
|
-
|
|
2777
|
+
logger6.error({ error, contextId }, "Error loading context artifacts");
|
|
2811
2778
|
}
|
|
2812
2779
|
return artifacts;
|
|
2813
2780
|
}
|
|
@@ -2910,7 +2877,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2910
2877
|
id: taskId
|
|
2911
2878
|
});
|
|
2912
2879
|
if (!task) {
|
|
2913
|
-
|
|
2880
|
+
logger6.warn({ taskId }, "Task not found when fetching artifact");
|
|
2914
2881
|
return null;
|
|
2915
2882
|
}
|
|
2916
2883
|
const artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2922,7 +2889,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2922
2889
|
return this.formatArtifactData(artifacts[0], artifactId, taskId);
|
|
2923
2890
|
}
|
|
2924
2891
|
} catch (error) {
|
|
2925
|
-
|
|
2892
|
+
logger6.warn({ artifactId, taskId, error }, "Failed to fetch artifact");
|
|
2926
2893
|
}
|
|
2927
2894
|
return null;
|
|
2928
2895
|
}
|
|
@@ -2962,7 +2929,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_ARTIFACT_REGEX", /<(a(r(t(i(f(a(c(t(:
|
|
|
2962
2929
|
var ArtifactParser = _ArtifactParser;
|
|
2963
2930
|
|
|
2964
2931
|
// src/utils/incremental-stream-parser.ts
|
|
2965
|
-
var
|
|
2932
|
+
var logger7 = agentsCore.getLogger("IncrementalStreamParser");
|
|
2966
2933
|
var IncrementalStreamParser = class {
|
|
2967
2934
|
constructor(streamHelper, tenantId, contextId) {
|
|
2968
2935
|
__publicField(this, "buffer", "");
|
|
@@ -3022,13 +2989,13 @@ var IncrementalStreamParser = class {
|
|
|
3022
2989
|
if (part.type === "tool-call-delta" && part.toolName === targetToolName) {
|
|
3023
2990
|
const delta = part.argsTextDelta || "";
|
|
3024
2991
|
if (jsonBuffer.length + delta.length > MAX_BUFFER_SIZE) {
|
|
3025
|
-
|
|
2992
|
+
logger7.warn("JSON buffer exceeded maximum size, truncating");
|
|
3026
2993
|
jsonBuffer = jsonBuffer.slice(-MAX_BUFFER_SIZE / 2);
|
|
3027
2994
|
}
|
|
3028
2995
|
jsonBuffer += delta;
|
|
3029
2996
|
for (const char of delta) {
|
|
3030
2997
|
if (componentBuffer.length > MAX_BUFFER_SIZE) {
|
|
3031
|
-
|
|
2998
|
+
logger7.warn("Component buffer exceeded maximum size, resetting");
|
|
3032
2999
|
componentBuffer = "";
|
|
3033
3000
|
depth = 0;
|
|
3034
3001
|
continue;
|
|
@@ -3043,7 +3010,7 @@ var IncrementalStreamParser = class {
|
|
|
3043
3010
|
if (componentMatch) {
|
|
3044
3011
|
const MAX_COMPONENT_SIZE = 1024 * 1024;
|
|
3045
3012
|
if (componentMatch[0].length > MAX_COMPONENT_SIZE) {
|
|
3046
|
-
|
|
3013
|
+
logger7.warn(
|
|
3047
3014
|
{
|
|
3048
3015
|
size: componentMatch[0].length,
|
|
3049
3016
|
maxSize: MAX_COMPONENT_SIZE
|
|
@@ -3056,7 +3023,7 @@ var IncrementalStreamParser = class {
|
|
|
3056
3023
|
try {
|
|
3057
3024
|
const component = JSON.parse(componentMatch[0]);
|
|
3058
3025
|
if (typeof component !== "object" || !component.id) {
|
|
3059
|
-
|
|
3026
|
+
logger7.warn("Invalid component structure, skipping");
|
|
3060
3027
|
componentBuffer = "";
|
|
3061
3028
|
continue;
|
|
3062
3029
|
}
|
|
@@ -3069,7 +3036,7 @@ var IncrementalStreamParser = class {
|
|
|
3069
3036
|
componentsStreamed++;
|
|
3070
3037
|
componentBuffer = "";
|
|
3071
3038
|
} catch (e) {
|
|
3072
|
-
|
|
3039
|
+
logger7.debug({ error: e }, "Failed to parse component, continuing to accumulate");
|
|
3073
3040
|
}
|
|
3074
3041
|
}
|
|
3075
3042
|
}
|
|
@@ -3086,7 +3053,7 @@ var IncrementalStreamParser = class {
|
|
|
3086
3053
|
break;
|
|
3087
3054
|
}
|
|
3088
3055
|
}
|
|
3089
|
-
|
|
3056
|
+
logger7.debug({ componentsStreamed }, "Finished streaming components");
|
|
3090
3057
|
}
|
|
3091
3058
|
/**
|
|
3092
3059
|
* Legacy method for backward compatibility - defaults to text processing
|
|
@@ -3230,7 +3197,7 @@ var IncrementalStreamParser = class {
|
|
|
3230
3197
|
};
|
|
3231
3198
|
|
|
3232
3199
|
// src/utils/response-formatter.ts
|
|
3233
|
-
var
|
|
3200
|
+
var logger8 = agentsCore.getLogger("ResponseFormatter");
|
|
3234
3201
|
var ResponseFormatter = class {
|
|
3235
3202
|
constructor(tenantId) {
|
|
3236
3203
|
__publicField(this, "artifactParser");
|
|
@@ -3261,7 +3228,7 @@ var ResponseFormatter = class {
|
|
|
3261
3228
|
return { parts };
|
|
3262
3229
|
} catch (error) {
|
|
3263
3230
|
agentsCore.setSpanWithError(span, error);
|
|
3264
|
-
|
|
3231
|
+
logger8.error({ error, responseObject }, "Error formatting object response");
|
|
3265
3232
|
return {
|
|
3266
3233
|
parts: [{ kind: "data", data: responseObject }]
|
|
3267
3234
|
};
|
|
@@ -3312,7 +3279,7 @@ var ResponseFormatter = class {
|
|
|
3312
3279
|
return { parts };
|
|
3313
3280
|
} catch (error) {
|
|
3314
3281
|
agentsCore.setSpanWithError(span, error);
|
|
3315
|
-
|
|
3282
|
+
logger8.error({ error, responseText }, "Error formatting response");
|
|
3316
3283
|
return { text: responseText };
|
|
3317
3284
|
} finally {
|
|
3318
3285
|
span.end();
|
|
@@ -3357,7 +3324,7 @@ var ResponseFormatter = class {
|
|
|
3357
3324
|
}
|
|
3358
3325
|
}
|
|
3359
3326
|
};
|
|
3360
|
-
var
|
|
3327
|
+
var logger9 = agentsCore.getLogger("ToolSessionManager");
|
|
3361
3328
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
3362
3329
|
// 5 minutes
|
|
3363
3330
|
constructor() {
|
|
@@ -3386,7 +3353,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3386
3353
|
createdAt: Date.now()
|
|
3387
3354
|
};
|
|
3388
3355
|
this.sessions.set(sessionId, session);
|
|
3389
|
-
|
|
3356
|
+
logger9.debug({ sessionId, tenantId, contextId, taskId }, "Created tool session");
|
|
3390
3357
|
return sessionId;
|
|
3391
3358
|
}
|
|
3392
3359
|
/**
|
|
@@ -3395,7 +3362,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3395
3362
|
recordToolResult(sessionId, toolResult) {
|
|
3396
3363
|
const session = this.sessions.get(sessionId);
|
|
3397
3364
|
if (!session) {
|
|
3398
|
-
|
|
3365
|
+
logger9.warn(
|
|
3399
3366
|
{ sessionId, toolCallId: toolResult.toolCallId },
|
|
3400
3367
|
"Tool result recorded for unknown session"
|
|
3401
3368
|
);
|
|
@@ -3409,12 +3376,12 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3409
3376
|
getToolResult(sessionId, toolCallId) {
|
|
3410
3377
|
const session = this.sessions.get(sessionId);
|
|
3411
3378
|
if (!session) {
|
|
3412
|
-
|
|
3379
|
+
logger9.warn({ sessionId, toolCallId }, "Requested tool result for unknown session");
|
|
3413
3380
|
return void 0;
|
|
3414
3381
|
}
|
|
3415
3382
|
const result = session.toolResults.get(toolCallId);
|
|
3416
3383
|
if (!result) {
|
|
3417
|
-
|
|
3384
|
+
logger9.warn(
|
|
3418
3385
|
{
|
|
3419
3386
|
sessionId,
|
|
3420
3387
|
toolCallId,
|
|
@@ -3453,10 +3420,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3453
3420
|
}
|
|
3454
3421
|
for (const sessionId of expiredSessions) {
|
|
3455
3422
|
this.sessions.delete(sessionId);
|
|
3456
|
-
|
|
3423
|
+
logger9.debug({ sessionId }, "Cleaned up expired tool session");
|
|
3457
3424
|
}
|
|
3458
3425
|
if (expiredSessions.length > 0) {
|
|
3459
|
-
|
|
3426
|
+
logger9.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
3460
3427
|
}
|
|
3461
3428
|
}
|
|
3462
3429
|
};
|
|
@@ -3465,7 +3432,7 @@ var ToolSessionManager = _ToolSessionManager;
|
|
|
3465
3432
|
var toolSessionManager = ToolSessionManager.getInstance();
|
|
3466
3433
|
|
|
3467
3434
|
// src/agents/artifactTools.ts
|
|
3468
|
-
var
|
|
3435
|
+
var logger10 = agentsCore.getLogger("artifactTools");
|
|
3469
3436
|
function buildKeyNestingMap(data, prefix = "", map = /* @__PURE__ */ new Map()) {
|
|
3470
3437
|
if (typeof data === "object" && data !== null) {
|
|
3471
3438
|
if (Array.isArray(data)) {
|
|
@@ -3686,7 +3653,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3686
3653
|
execute: async ({ toolCallId, baseSelector, propSelectors, ...rest }, _context) => {
|
|
3687
3654
|
const artifactType = "artifactType" in rest ? rest.artifactType : void 0;
|
|
3688
3655
|
if (!sessionId) {
|
|
3689
|
-
|
|
3656
|
+
logger10.warn({ toolCallId }, "No session ID provided to save_tool_result");
|
|
3690
3657
|
return {
|
|
3691
3658
|
saved: false,
|
|
3692
3659
|
error: `[toolCallId: ${toolCallId}] No session context available`,
|
|
@@ -3696,7 +3663,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3696
3663
|
}
|
|
3697
3664
|
const toolResult = toolSessionManager.getToolResult(sessionId, toolCallId);
|
|
3698
3665
|
if (!toolResult) {
|
|
3699
|
-
|
|
3666
|
+
logger10.warn({ toolCallId, sessionId }, "Tool result not found in session");
|
|
3700
3667
|
return {
|
|
3701
3668
|
saved: false,
|
|
3702
3669
|
error: `[toolCallId: ${toolCallId}] Tool result not found`,
|
|
@@ -3709,7 +3676,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3709
3676
|
const baseData = jmespath__default.default.search(parsedResult, baseSelector);
|
|
3710
3677
|
if (!baseData || Array.isArray(baseData) && baseData.length === 0) {
|
|
3711
3678
|
const debugInfo = analyzeSelectorFailure(parsedResult, baseSelector);
|
|
3712
|
-
|
|
3679
|
+
logger10.warn(
|
|
3713
3680
|
{
|
|
3714
3681
|
baseSelector,
|
|
3715
3682
|
toolCallId,
|
|
@@ -3752,7 +3719,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3752
3719
|
const fallbackValue = item[propName];
|
|
3753
3720
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3754
3721
|
extractedItem[propName] = fallbackValue;
|
|
3755
|
-
|
|
3722
|
+
logger10.info(
|
|
3756
3723
|
{ propName, propSelector, context },
|
|
3757
3724
|
`PropSelector failed, used fallback direct property access`
|
|
3758
3725
|
);
|
|
@@ -3764,7 +3731,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3764
3731
|
const fallbackValue = item[propName];
|
|
3765
3732
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3766
3733
|
extractedItem[propName] = fallbackValue;
|
|
3767
|
-
|
|
3734
|
+
logger10.warn(
|
|
3768
3735
|
{ propName, propSelector, context, error: error.message },
|
|
3769
3736
|
`PropSelector syntax error, used fallback direct property access`
|
|
3770
3737
|
);
|
|
@@ -3877,7 +3844,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3877
3844
|
warnings
|
|
3878
3845
|
};
|
|
3879
3846
|
} catch (error) {
|
|
3880
|
-
|
|
3847
|
+
logger10.error({ error, toolCallId, sessionId }, "Error processing save_tool_result");
|
|
3881
3848
|
return {
|
|
3882
3849
|
saved: false,
|
|
3883
3850
|
error: `[toolCallId: ${toolCallId}] ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
@@ -3889,7 +3856,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3889
3856
|
}
|
|
3890
3857
|
|
|
3891
3858
|
// src/a2a/client.ts
|
|
3892
|
-
var
|
|
3859
|
+
var logger11 = agentsCore.getLogger("a2aClient");
|
|
3893
3860
|
var DEFAULT_BACKOFF = {
|
|
3894
3861
|
initialInterval: 500,
|
|
3895
3862
|
maxInterval: 6e4,
|
|
@@ -3957,7 +3924,7 @@ var A2AClient = class {
|
|
|
3957
3924
|
*/
|
|
3958
3925
|
async _fetchAndCacheAgentCard() {
|
|
3959
3926
|
const agentCardUrl = `${this.agentBaseUrl}/.well-known/agent.json`;
|
|
3960
|
-
getLogger("a2a").info({ agentCardUrl, agentBaseUrl: this.agentBaseUrl }, "agentCardUrl");
|
|
3927
|
+
agentsCore.getLogger("a2a").info({ agentCardUrl, agentBaseUrl: this.agentBaseUrl }, "agentCardUrl");
|
|
3961
3928
|
try {
|
|
3962
3929
|
const response = await fetch(agentCardUrl, {
|
|
3963
3930
|
headers: {
|
|
@@ -4095,7 +4062,7 @@ var A2AClient = class {
|
|
|
4095
4062
|
try {
|
|
4096
4063
|
const res = await fn();
|
|
4097
4064
|
if (attempt > 0) {
|
|
4098
|
-
|
|
4065
|
+
logger11.info(
|
|
4099
4066
|
{
|
|
4100
4067
|
attempts: attempt + 1,
|
|
4101
4068
|
elapsedTime: Date.now() - start
|
|
@@ -4110,7 +4077,7 @@ var A2AClient = class {
|
|
|
4110
4077
|
}
|
|
4111
4078
|
const elapsed = Date.now() - start;
|
|
4112
4079
|
if (elapsed > maxElapsedTime) {
|
|
4113
|
-
|
|
4080
|
+
logger11.warn(
|
|
4114
4081
|
{
|
|
4115
4082
|
attempts: attempt + 1,
|
|
4116
4083
|
elapsedTime: elapsed,
|
|
@@ -4131,7 +4098,7 @@ var A2AClient = class {
|
|
|
4131
4098
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
4132
4099
|
}
|
|
4133
4100
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
4134
|
-
|
|
4101
|
+
logger11.info(
|
|
4135
4102
|
{
|
|
4136
4103
|
attempt: attempt + 1,
|
|
4137
4104
|
delayMs,
|
|
@@ -4216,7 +4183,7 @@ var A2AClient = class {
|
|
|
4216
4183
|
}
|
|
4217
4184
|
const rpcResponse = await httpResponse.json();
|
|
4218
4185
|
if (rpcResponse.id !== requestId2) {
|
|
4219
|
-
|
|
4186
|
+
logger11.warn(
|
|
4220
4187
|
{
|
|
4221
4188
|
method,
|
|
4222
4189
|
expectedId: requestId2,
|
|
@@ -4415,7 +4382,7 @@ var A2AClient = class {
|
|
|
4415
4382
|
try {
|
|
4416
4383
|
while (true) {
|
|
4417
4384
|
const { done, value } = await reader.read();
|
|
4418
|
-
|
|
4385
|
+
logger11.info({ done, value }, "parseA2ASseStream");
|
|
4419
4386
|
if (done) {
|
|
4420
4387
|
if (eventDataBuffer.trim()) {
|
|
4421
4388
|
const result = this._processSseEventData(
|
|
@@ -4504,7 +4471,7 @@ var A2AClient = class {
|
|
|
4504
4471
|
// src/agents/relationTools.ts
|
|
4505
4472
|
init_conversations();
|
|
4506
4473
|
init_dbClient();
|
|
4507
|
-
var
|
|
4474
|
+
var logger12 = agentsCore.getLogger("relationships Tools");
|
|
4508
4475
|
var generateTransferToolDescription = (config2) => {
|
|
4509
4476
|
return `Hand off the conversation to agent ${config2.id}.
|
|
4510
4477
|
|
|
@@ -4542,7 +4509,7 @@ var createTransferToAgentTool = ({
|
|
|
4542
4509
|
"transfer.to_agent_id": transferConfig.id ?? "unknown"
|
|
4543
4510
|
});
|
|
4544
4511
|
}
|
|
4545
|
-
|
|
4512
|
+
logger12.info(
|
|
4546
4513
|
{
|
|
4547
4514
|
transferTo: transferConfig.id ?? "unknown",
|
|
4548
4515
|
fromAgent: callingAgentId
|
|
@@ -4690,7 +4657,7 @@ function createDelegateToAgentTool({
|
|
|
4690
4657
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
4691
4658
|
}
|
|
4692
4659
|
};
|
|
4693
|
-
|
|
4660
|
+
logger12.info({ messageToSend }, "messageToSend");
|
|
4694
4661
|
await agentsCore.createMessage(dbClient_default)({
|
|
4695
4662
|
id: nanoid.nanoid(),
|
|
4696
4663
|
tenantId,
|
|
@@ -4752,7 +4719,7 @@ function createDelegateToAgentTool({
|
|
|
4752
4719
|
}
|
|
4753
4720
|
|
|
4754
4721
|
// src/agents/SystemPromptBuilder.ts
|
|
4755
|
-
var
|
|
4722
|
+
var logger13 = agentsCore.getLogger("SystemPromptBuilder");
|
|
4756
4723
|
var SystemPromptBuilder = class {
|
|
4757
4724
|
constructor(version, versionConfig) {
|
|
4758
4725
|
this.version = version;
|
|
@@ -4768,9 +4735,9 @@ var SystemPromptBuilder = class {
|
|
|
4768
4735
|
this.templates.set(name, content);
|
|
4769
4736
|
}
|
|
4770
4737
|
this.loaded = true;
|
|
4771
|
-
|
|
4738
|
+
logger13.debug(`Loaded ${this.templates.size} templates for version ${this.version}`);
|
|
4772
4739
|
} catch (error) {
|
|
4773
|
-
|
|
4740
|
+
logger13.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
4774
4741
|
throw new Error(`Template loading failed: ${error}`);
|
|
4775
4742
|
}
|
|
4776
4743
|
}
|
|
@@ -5172,7 +5139,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
5172
5139
|
return false;
|
|
5173
5140
|
};
|
|
5174
5141
|
}
|
|
5175
|
-
var
|
|
5142
|
+
var logger14 = agentsCore.getLogger("Agent");
|
|
5176
5143
|
var CONSTANTS = {
|
|
5177
5144
|
MAX_GENERATION_STEPS: 12,
|
|
5178
5145
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -5425,14 +5392,14 @@ var Agent = class {
|
|
|
5425
5392
|
for (const toolSet of tools) {
|
|
5426
5393
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
5427
5394
|
if (!isValidTool(originalTool)) {
|
|
5428
|
-
|
|
5395
|
+
logger14.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
5429
5396
|
continue;
|
|
5430
5397
|
}
|
|
5431
5398
|
const sessionWrappedTool = ai.tool({
|
|
5432
5399
|
description: originalTool.description,
|
|
5433
5400
|
inputSchema: originalTool.inputSchema,
|
|
5434
5401
|
execute: async (args, { toolCallId }) => {
|
|
5435
|
-
|
|
5402
|
+
logger14.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
5436
5403
|
try {
|
|
5437
5404
|
const result = await originalTool.execute(args, { toolCallId });
|
|
5438
5405
|
toolSessionManager.recordToolResult(sessionId, {
|
|
@@ -5444,7 +5411,7 @@ var Agent = class {
|
|
|
5444
5411
|
});
|
|
5445
5412
|
return { result, toolCallId };
|
|
5446
5413
|
} catch (error) {
|
|
5447
|
-
|
|
5414
|
+
logger14.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
5448
5415
|
throw error;
|
|
5449
5416
|
}
|
|
5450
5417
|
}
|
|
@@ -5529,7 +5496,7 @@ var Agent = class {
|
|
|
5529
5496
|
selectedTools
|
|
5530
5497
|
};
|
|
5531
5498
|
}
|
|
5532
|
-
|
|
5499
|
+
logger14.info(
|
|
5533
5500
|
{
|
|
5534
5501
|
toolName: tool4.name,
|
|
5535
5502
|
credentialReferenceId,
|
|
@@ -5569,7 +5536,7 @@ var Agent = class {
|
|
|
5569
5536
|
async getResolvedContext(conversationId, requestContext) {
|
|
5570
5537
|
try {
|
|
5571
5538
|
if (!this.config.contextConfigId) {
|
|
5572
|
-
|
|
5539
|
+
logger14.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
5573
5540
|
return null;
|
|
5574
5541
|
}
|
|
5575
5542
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -5577,7 +5544,7 @@ var Agent = class {
|
|
|
5577
5544
|
id: this.config.contextConfigId
|
|
5578
5545
|
});
|
|
5579
5546
|
if (!contextConfig) {
|
|
5580
|
-
|
|
5547
|
+
logger14.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
5581
5548
|
return null;
|
|
5582
5549
|
}
|
|
5583
5550
|
if (!this.contextResolver) {
|
|
@@ -5594,7 +5561,7 @@ var Agent = class {
|
|
|
5594
5561
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5595
5562
|
$env: process.env
|
|
5596
5563
|
};
|
|
5597
|
-
|
|
5564
|
+
logger14.debug(
|
|
5598
5565
|
{
|
|
5599
5566
|
conversationId,
|
|
5600
5567
|
contextConfigId: contextConfig.id,
|
|
@@ -5608,7 +5575,7 @@ var Agent = class {
|
|
|
5608
5575
|
);
|
|
5609
5576
|
return contextWithBuiltins;
|
|
5610
5577
|
} catch (error) {
|
|
5611
|
-
|
|
5578
|
+
logger14.error(
|
|
5612
5579
|
{
|
|
5613
5580
|
conversationId,
|
|
5614
5581
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5632,7 +5599,7 @@ var Agent = class {
|
|
|
5632
5599
|
});
|
|
5633
5600
|
return graphDefinition?.graphPrompt || void 0;
|
|
5634
5601
|
} catch (error) {
|
|
5635
|
-
|
|
5602
|
+
logger14.warn(
|
|
5636
5603
|
{
|
|
5637
5604
|
graphId: this.config.graphId,
|
|
5638
5605
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5659,7 +5626,7 @@ var Agent = class {
|
|
|
5659
5626
|
}
|
|
5660
5627
|
return !!(graphDefinition.artifactComponents && Object.keys(graphDefinition.artifactComponents).length > 0);
|
|
5661
5628
|
} catch (error) {
|
|
5662
|
-
|
|
5629
|
+
logger14.warn(
|
|
5663
5630
|
{
|
|
5664
5631
|
graphId: this.config.graphId,
|
|
5665
5632
|
tenantId: this.config.tenantId,
|
|
@@ -5719,7 +5686,7 @@ Key requirements:
|
|
|
5719
5686
|
preserveUnresolved: false
|
|
5720
5687
|
});
|
|
5721
5688
|
} catch (error) {
|
|
5722
|
-
|
|
5689
|
+
logger14.error(
|
|
5723
5690
|
{
|
|
5724
5691
|
conversationId,
|
|
5725
5692
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5764,7 +5731,7 @@ Key requirements:
|
|
|
5764
5731
|
preserveUnresolved: false
|
|
5765
5732
|
});
|
|
5766
5733
|
} catch (error) {
|
|
5767
|
-
|
|
5734
|
+
logger14.error(
|
|
5768
5735
|
{
|
|
5769
5736
|
conversationId,
|
|
5770
5737
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5792,7 +5759,7 @@ Key requirements:
|
|
|
5792
5759
|
artifactId: z5.z.string().describe("The unique identifier of the artifact to get.")
|
|
5793
5760
|
}),
|
|
5794
5761
|
execute: async ({ artifactId }) => {
|
|
5795
|
-
|
|
5762
|
+
logger14.info({ artifactId }, "get_artifact executed");
|
|
5796
5763
|
const artifact = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
5797
5764
|
scopes: {
|
|
5798
5765
|
tenantId: this.config.tenantId,
|
|
@@ -5859,7 +5826,7 @@ Key requirements:
|
|
|
5859
5826
|
graphId: this.config.graphId
|
|
5860
5827
|
});
|
|
5861
5828
|
} catch (error) {
|
|
5862
|
-
|
|
5829
|
+
logger14.error(
|
|
5863
5830
|
{ error, graphId: this.config.graphId },
|
|
5864
5831
|
"Failed to check graph artifact components"
|
|
5865
5832
|
);
|
|
@@ -5963,7 +5930,7 @@ Key requirements:
|
|
|
5963
5930
|
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;
|
|
5964
5931
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
5965
5932
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
5966
|
-
|
|
5933
|
+
logger14.warn(
|
|
5967
5934
|
{
|
|
5968
5935
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
5969
5936
|
appliedTimeout: timeoutMs,
|
|
@@ -6005,7 +5972,7 @@ Key requirements:
|
|
|
6005
5972
|
}
|
|
6006
5973
|
);
|
|
6007
5974
|
} catch (error) {
|
|
6008
|
-
|
|
5975
|
+
logger14.debug("Failed to track agent reasoning");
|
|
6009
5976
|
}
|
|
6010
5977
|
}
|
|
6011
5978
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -6088,7 +6055,7 @@ Key requirements:
|
|
|
6088
6055
|
}
|
|
6089
6056
|
);
|
|
6090
6057
|
} catch (error) {
|
|
6091
|
-
|
|
6058
|
+
logger14.debug("Failed to track agent reasoning");
|
|
6092
6059
|
}
|
|
6093
6060
|
}
|
|
6094
6061
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -6133,7 +6100,7 @@ Key requirements:
|
|
|
6133
6100
|
return;
|
|
6134
6101
|
}
|
|
6135
6102
|
if (toolName === "save_artifact_tool" || toolName === "save_tool_result") {
|
|
6136
|
-
|
|
6103
|
+
logger14.info({ result }, "save_artifact_tool or save_tool_result");
|
|
6137
6104
|
if (result.output.artifacts) {
|
|
6138
6105
|
for (const artifact of result.output.artifacts) {
|
|
6139
6106
|
const artifactId = artifact?.artifactId || "N/A";
|
|
@@ -6321,7 +6288,7 @@ function parseEmbeddedJson(data) {
|
|
|
6321
6288
|
}
|
|
6322
6289
|
});
|
|
6323
6290
|
}
|
|
6324
|
-
var
|
|
6291
|
+
var logger15 = agentsCore.getLogger("generateTaskHandler");
|
|
6325
6292
|
var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
6326
6293
|
return async (task) => {
|
|
6327
6294
|
try {
|
|
@@ -6371,7 +6338,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6371
6338
|
agentId: config2.agentId
|
|
6372
6339
|
})
|
|
6373
6340
|
]);
|
|
6374
|
-
|
|
6341
|
+
logger15.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
6375
6342
|
const agentPrompt = "prompt" in config2.agentSchema ? config2.agentSchema.prompt : "";
|
|
6376
6343
|
const models = "models" in config2.agentSchema ? config2.agentSchema.models : void 0;
|
|
6377
6344
|
const stopWhen = "stopWhen" in config2.agentSchema ? config2.agentSchema.stopWhen : void 0;
|
|
@@ -6471,7 +6438,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6471
6438
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
6472
6439
|
if (taskIdMatch) {
|
|
6473
6440
|
contextId = taskIdMatch[1];
|
|
6474
|
-
|
|
6441
|
+
logger15.info(
|
|
6475
6442
|
{
|
|
6476
6443
|
taskId: task.id,
|
|
6477
6444
|
extractedContextId: contextId,
|
|
@@ -6487,7 +6454,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6487
6454
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
6488
6455
|
agent.setDelegationStatus(isDelegation);
|
|
6489
6456
|
if (isDelegation) {
|
|
6490
|
-
|
|
6457
|
+
logger15.info(
|
|
6491
6458
|
{ agentId: config2.agentId, taskId: task.id },
|
|
6492
6459
|
"Delegated agent - streaming disabled"
|
|
6493
6460
|
);
|
|
@@ -6770,7 +6737,7 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
|
6770
6737
|
// src/routes/agents.ts
|
|
6771
6738
|
init_dbClient();
|
|
6772
6739
|
var app = new zodOpenapi.OpenAPIHono();
|
|
6773
|
-
var
|
|
6740
|
+
var logger16 = agentsCore.getLogger("agents");
|
|
6774
6741
|
app.openapi(
|
|
6775
6742
|
zodOpenapi.createRoute({
|
|
6776
6743
|
method: "get",
|
|
@@ -6808,7 +6775,7 @@ app.openapi(
|
|
|
6808
6775
|
tracestate: c.req.header("tracestate"),
|
|
6809
6776
|
baggage: c.req.header("baggage")
|
|
6810
6777
|
};
|
|
6811
|
-
|
|
6778
|
+
logger16.info(
|
|
6812
6779
|
{
|
|
6813
6780
|
otelHeaders,
|
|
6814
6781
|
path: c.req.path,
|
|
@@ -6819,7 +6786,7 @@ app.openapi(
|
|
|
6819
6786
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
6820
6787
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6821
6788
|
if (agentId) {
|
|
6822
|
-
|
|
6789
|
+
logger16.info(
|
|
6823
6790
|
{
|
|
6824
6791
|
message: "getRegisteredAgent (agent-level)",
|
|
6825
6792
|
tenantId,
|
|
@@ -6831,13 +6798,13 @@ app.openapi(
|
|
|
6831
6798
|
);
|
|
6832
6799
|
const credentialStores = c.get("credentialStores");
|
|
6833
6800
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
6834
|
-
|
|
6801
|
+
logger16.info({ agent }, "agent registered: well-known agent.json");
|
|
6835
6802
|
if (!agent) {
|
|
6836
6803
|
return c.json({ error: "Agent not found" }, 404);
|
|
6837
6804
|
}
|
|
6838
6805
|
return c.json(agent.agentCard);
|
|
6839
6806
|
} else {
|
|
6840
|
-
|
|
6807
|
+
logger16.info(
|
|
6841
6808
|
{
|
|
6842
6809
|
message: "getRegisteredGraph (graph-level)",
|
|
6843
6810
|
tenantId,
|
|
@@ -6860,7 +6827,7 @@ app.post("/a2a", async (c) => {
|
|
|
6860
6827
|
tracestate: c.req.header("tracestate"),
|
|
6861
6828
|
baggage: c.req.header("baggage")
|
|
6862
6829
|
};
|
|
6863
|
-
|
|
6830
|
+
logger16.info(
|
|
6864
6831
|
{
|
|
6865
6832
|
otelHeaders,
|
|
6866
6833
|
path: c.req.path,
|
|
@@ -6871,7 +6838,7 @@ app.post("/a2a", async (c) => {
|
|
|
6871
6838
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
6872
6839
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6873
6840
|
if (agentId) {
|
|
6874
|
-
|
|
6841
|
+
logger16.info(
|
|
6875
6842
|
{
|
|
6876
6843
|
message: "a2a (agent-level)",
|
|
6877
6844
|
tenantId,
|
|
@@ -6895,7 +6862,7 @@ app.post("/a2a", async (c) => {
|
|
|
6895
6862
|
}
|
|
6896
6863
|
return a2aHandler(c, agent);
|
|
6897
6864
|
} else {
|
|
6898
|
-
|
|
6865
|
+
logger16.info(
|
|
6899
6866
|
{
|
|
6900
6867
|
message: "a2a (graph-level)",
|
|
6901
6868
|
tenantId,
|
|
@@ -6941,14 +6908,14 @@ init_dbClient();
|
|
|
6941
6908
|
|
|
6942
6909
|
// src/a2a/transfer.ts
|
|
6943
6910
|
init_dbClient();
|
|
6944
|
-
var
|
|
6911
|
+
var logger17 = agentsCore.getLogger("Transfer");
|
|
6945
6912
|
async function executeTransfer({
|
|
6946
6913
|
tenantId,
|
|
6947
6914
|
threadId,
|
|
6948
6915
|
projectId,
|
|
6949
6916
|
targetAgentId
|
|
6950
6917
|
}) {
|
|
6951
|
-
|
|
6918
|
+
logger17.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
6952
6919
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
6953
6920
|
scopes: { tenantId, projectId },
|
|
6954
6921
|
threadId,
|
|
@@ -7492,7 +7459,7 @@ function createMCPStreamHelper() {
|
|
|
7492
7459
|
|
|
7493
7460
|
// src/handlers/executionHandler.ts
|
|
7494
7461
|
init_dbClient();
|
|
7495
|
-
var
|
|
7462
|
+
var logger18 = agentsCore.getLogger("ExecutionHandler");
|
|
7496
7463
|
var ExecutionHandler = class {
|
|
7497
7464
|
constructor() {
|
|
7498
7465
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -7517,7 +7484,7 @@ var ExecutionHandler = class {
|
|
|
7517
7484
|
const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
|
|
7518
7485
|
registerStreamHelper(requestId2, sseHelper);
|
|
7519
7486
|
graphSessionManager.createSession(requestId2, graphId, tenantId, projectId);
|
|
7520
|
-
|
|
7487
|
+
logger18.info({ sessionId: requestId2, graphId }, "Created GraphSession for message execution");
|
|
7521
7488
|
let graphConfig = null;
|
|
7522
7489
|
try {
|
|
7523
7490
|
graphConfig = await agentsCore.getFullGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
|
|
@@ -7529,7 +7496,7 @@ var ExecutionHandler = class {
|
|
|
7529
7496
|
);
|
|
7530
7497
|
}
|
|
7531
7498
|
} catch (error) {
|
|
7532
|
-
|
|
7499
|
+
logger18.error(
|
|
7533
7500
|
{
|
|
7534
7501
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
7535
7502
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -7545,7 +7512,7 @@ var ExecutionHandler = class {
|
|
|
7545
7512
|
try {
|
|
7546
7513
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
7547
7514
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
7548
|
-
|
|
7515
|
+
logger18.info(
|
|
7549
7516
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
7550
7517
|
"Attempting to create or reuse existing task"
|
|
7551
7518
|
);
|
|
@@ -7568,7 +7535,7 @@ var ExecutionHandler = class {
|
|
|
7568
7535
|
agent_id: currentAgentId
|
|
7569
7536
|
}
|
|
7570
7537
|
});
|
|
7571
|
-
|
|
7538
|
+
logger18.info(
|
|
7572
7539
|
{
|
|
7573
7540
|
taskId,
|
|
7574
7541
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -7577,27 +7544,27 @@ var ExecutionHandler = class {
|
|
|
7577
7544
|
);
|
|
7578
7545
|
} catch (error) {
|
|
7579
7546
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
7580
|
-
|
|
7547
|
+
logger18.info(
|
|
7581
7548
|
{ taskId, error: error.message },
|
|
7582
7549
|
"Task already exists, fetching existing task"
|
|
7583
7550
|
);
|
|
7584
7551
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
7585
7552
|
if (existingTask) {
|
|
7586
7553
|
task = existingTask;
|
|
7587
|
-
|
|
7554
|
+
logger18.info(
|
|
7588
7555
|
{ taskId, existingTask },
|
|
7589
7556
|
"Successfully reused existing task from race condition"
|
|
7590
7557
|
);
|
|
7591
7558
|
} else {
|
|
7592
|
-
|
|
7559
|
+
logger18.error({ taskId, error }, "Task constraint failed but task not found");
|
|
7593
7560
|
throw error;
|
|
7594
7561
|
}
|
|
7595
7562
|
} else {
|
|
7596
|
-
|
|
7563
|
+
logger18.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
7597
7564
|
throw error;
|
|
7598
7565
|
}
|
|
7599
7566
|
}
|
|
7600
|
-
|
|
7567
|
+
logger18.debug(
|
|
7601
7568
|
{
|
|
7602
7569
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7603
7570
|
executionType: "create_initial_task",
|
|
@@ -7615,7 +7582,7 @@ var ExecutionHandler = class {
|
|
|
7615
7582
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
7616
7583
|
while (iterations < maxTransfers) {
|
|
7617
7584
|
iterations++;
|
|
7618
|
-
|
|
7585
|
+
logger18.info(
|
|
7619
7586
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
7620
7587
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
7621
7588
|
);
|
|
@@ -7623,10 +7590,10 @@ var ExecutionHandler = class {
|
|
|
7623
7590
|
scopes: { tenantId, projectId },
|
|
7624
7591
|
conversationId
|
|
7625
7592
|
});
|
|
7626
|
-
|
|
7593
|
+
logger18.info({ activeAgent }, "activeAgent");
|
|
7627
7594
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
7628
7595
|
currentAgentId = activeAgent.activeAgentId;
|
|
7629
|
-
|
|
7596
|
+
logger18.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
7630
7597
|
}
|
|
7631
7598
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
7632
7599
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -7667,13 +7634,13 @@ var ExecutionHandler = class {
|
|
|
7667
7634
|
});
|
|
7668
7635
|
if (!messageResponse?.result) {
|
|
7669
7636
|
errorCount++;
|
|
7670
|
-
|
|
7637
|
+
logger18.error(
|
|
7671
7638
|
{ currentAgentId, iterations, errorCount },
|
|
7672
7639
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7673
7640
|
);
|
|
7674
7641
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7675
7642
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7676
|
-
|
|
7643
|
+
logger18.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7677
7644
|
await sseHelper.writeError(errorMessage2);
|
|
7678
7645
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7679
7646
|
if (task) {
|
|
@@ -7699,7 +7666,7 @@ var ExecutionHandler = class {
|
|
|
7699
7666
|
const transferResponse = messageResponse.result;
|
|
7700
7667
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
7701
7668
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
7702
|
-
|
|
7669
|
+
logger18.info({ targetAgentId, transferReason }, "transfer response");
|
|
7703
7670
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
7704
7671
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
7705
7672
|
projectId,
|
|
@@ -7710,7 +7677,7 @@ var ExecutionHandler = class {
|
|
|
7710
7677
|
if (success) {
|
|
7711
7678
|
fromAgentId = currentAgentId;
|
|
7712
7679
|
currentAgentId = newAgentId;
|
|
7713
|
-
|
|
7680
|
+
logger18.info(
|
|
7714
7681
|
{
|
|
7715
7682
|
transferFrom: fromAgentId,
|
|
7716
7683
|
transferTo: currentAgentId,
|
|
@@ -7728,7 +7695,7 @@ var ExecutionHandler = class {
|
|
|
7728
7695
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
7729
7696
|
if (graphSessionData) {
|
|
7730
7697
|
const sessionSummary = graphSessionData.getSummary();
|
|
7731
|
-
|
|
7698
|
+
logger18.info(sessionSummary, "GraphSession data after completion");
|
|
7732
7699
|
}
|
|
7733
7700
|
let textContent = "";
|
|
7734
7701
|
for (const part of responseParts) {
|
|
@@ -7783,32 +7750,32 @@ var ExecutionHandler = class {
|
|
|
7783
7750
|
}
|
|
7784
7751
|
});
|
|
7785
7752
|
const updateTaskEnd = Date.now();
|
|
7786
|
-
|
|
7753
|
+
logger18.info(
|
|
7787
7754
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
7788
7755
|
"Completed updateTask operation"
|
|
7789
7756
|
);
|
|
7790
7757
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
7791
7758
|
await sseHelper.complete();
|
|
7792
|
-
|
|
7759
|
+
logger18.info({}, "Ending GraphSession and cleaning up");
|
|
7793
7760
|
graphSessionManager.endSession(requestId2);
|
|
7794
|
-
|
|
7761
|
+
logger18.info({}, "Cleaning up streamHelper");
|
|
7795
7762
|
unregisterStreamHelper(requestId2);
|
|
7796
7763
|
let response;
|
|
7797
7764
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
7798
7765
|
const captured = sseHelper.getCapturedResponse();
|
|
7799
7766
|
response = captured.text || "No response content";
|
|
7800
7767
|
}
|
|
7801
|
-
|
|
7768
|
+
logger18.info({}, "ExecutionHandler returning success");
|
|
7802
7769
|
return { success: true, iterations, response };
|
|
7803
7770
|
}
|
|
7804
7771
|
errorCount++;
|
|
7805
|
-
|
|
7772
|
+
logger18.warn(
|
|
7806
7773
|
{ iterations, errorCount },
|
|
7807
7774
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7808
7775
|
);
|
|
7809
7776
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7810
7777
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7811
|
-
|
|
7778
|
+
logger18.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7812
7779
|
await sseHelper.writeError(errorMessage2);
|
|
7813
7780
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7814
7781
|
if (task) {
|
|
@@ -7830,7 +7797,7 @@ var ExecutionHandler = class {
|
|
|
7830
7797
|
}
|
|
7831
7798
|
}
|
|
7832
7799
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
7833
|
-
|
|
7800
|
+
logger18.error({ maxTransfers, iterations }, errorMessage);
|
|
7834
7801
|
await sseHelper.writeError(errorMessage);
|
|
7835
7802
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
7836
7803
|
if (task) {
|
|
@@ -7850,7 +7817,7 @@ var ExecutionHandler = class {
|
|
|
7850
7817
|
unregisterStreamHelper(requestId2);
|
|
7851
7818
|
return { success: false, error: errorMessage, iterations };
|
|
7852
7819
|
} catch (error) {
|
|
7853
|
-
|
|
7820
|
+
logger18.error({ error }, "Error in execution handler");
|
|
7854
7821
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
7855
7822
|
await sseHelper.writeError(`Execution error: ${errorMessage}`);
|
|
7856
7823
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
@@ -7876,7 +7843,7 @@ var ExecutionHandler = class {
|
|
|
7876
7843
|
|
|
7877
7844
|
// src/routes/chat.ts
|
|
7878
7845
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
7879
|
-
var
|
|
7846
|
+
var logger19 = agentsCore.getLogger("completionsHandler");
|
|
7880
7847
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
7881
7848
|
method: "post",
|
|
7882
7849
|
path: "/completions",
|
|
@@ -7981,7 +7948,7 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
7981
7948
|
});
|
|
7982
7949
|
app2.use("/completions", agentsCore.contextValidationMiddleware(dbClient_default));
|
|
7983
7950
|
app2.openapi(chatCompletionsRoute, async (c) => {
|
|
7984
|
-
getLogger("chat").info(
|
|
7951
|
+
agentsCore.getLogger("chat").info(
|
|
7985
7952
|
{
|
|
7986
7953
|
path: c.req.path,
|
|
7987
7954
|
method: c.req.method,
|
|
@@ -7994,7 +7961,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7994
7961
|
tracestate: c.req.header("tracestate"),
|
|
7995
7962
|
baggage: c.req.header("baggage")
|
|
7996
7963
|
};
|
|
7997
|
-
|
|
7964
|
+
logger19.info(
|
|
7998
7965
|
{
|
|
7999
7966
|
otelHeaders,
|
|
8000
7967
|
path: c.req.path,
|
|
@@ -8005,7 +7972,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8005
7972
|
try {
|
|
8006
7973
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
8007
7974
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8008
|
-
getLogger("chat").debug(
|
|
7975
|
+
agentsCore.getLogger("chat").debug(
|
|
8009
7976
|
{
|
|
8010
7977
|
tenantId,
|
|
8011
7978
|
graphId
|
|
@@ -8080,7 +8047,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8080
8047
|
dbClient_default,
|
|
8081
8048
|
credentialStores
|
|
8082
8049
|
);
|
|
8083
|
-
|
|
8050
|
+
logger19.info(
|
|
8084
8051
|
{
|
|
8085
8052
|
tenantId,
|
|
8086
8053
|
graphId,
|
|
@@ -8126,7 +8093,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8126
8093
|
return streaming.streamSSE(c, async (stream2) => {
|
|
8127
8094
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
8128
8095
|
await sseHelper.writeRole();
|
|
8129
|
-
|
|
8096
|
+
logger19.info({ agentId }, "Starting execution");
|
|
8130
8097
|
const executionHandler = new ExecutionHandler();
|
|
8131
8098
|
const result = await executionHandler.execute({
|
|
8132
8099
|
executionContext,
|
|
@@ -8136,7 +8103,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8136
8103
|
requestId: requestId2,
|
|
8137
8104
|
sseHelper
|
|
8138
8105
|
});
|
|
8139
|
-
|
|
8106
|
+
logger19.info(
|
|
8140
8107
|
{ result },
|
|
8141
8108
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8142
8109
|
);
|
|
@@ -8172,7 +8139,7 @@ var chat_default = app2;
|
|
|
8172
8139
|
// src/routes/chatDataStream.ts
|
|
8173
8140
|
init_dbClient();
|
|
8174
8141
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
8175
|
-
var
|
|
8142
|
+
var logger20 = agentsCore.getLogger("chatDataStream");
|
|
8176
8143
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
8177
8144
|
method: "post",
|
|
8178
8145
|
path: "/chat",
|
|
@@ -8277,7 +8244,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8277
8244
|
);
|
|
8278
8245
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
8279
8246
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
8280
|
-
|
|
8247
|
+
logger20.info({ userText, lastUserMessage }, "userText");
|
|
8281
8248
|
const messageSpan = api.trace.getActiveSpan();
|
|
8282
8249
|
if (messageSpan) {
|
|
8283
8250
|
messageSpan.setAttributes({
|
|
@@ -8319,7 +8286,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8319
8286
|
await streamHelper.writeError("Unable to process request");
|
|
8320
8287
|
}
|
|
8321
8288
|
} catch (err) {
|
|
8322
|
-
|
|
8289
|
+
logger20.error({ err }, "Streaming error");
|
|
8323
8290
|
await streamHelper.writeError("Internal server error");
|
|
8324
8291
|
} finally {
|
|
8325
8292
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -8340,7 +8307,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8340
8307
|
)
|
|
8341
8308
|
);
|
|
8342
8309
|
} catch (error) {
|
|
8343
|
-
|
|
8310
|
+
logger20.error({ error }, "chatDataStream error");
|
|
8344
8311
|
return c.json({ error: "Failed to process chat completion" }, 500);
|
|
8345
8312
|
}
|
|
8346
8313
|
});
|
|
@@ -8351,7 +8318,7 @@ init_dbClient();
|
|
|
8351
8318
|
function createMCPSchema(schema) {
|
|
8352
8319
|
return schema;
|
|
8353
8320
|
}
|
|
8354
|
-
var
|
|
8321
|
+
var logger21 = agentsCore.getLogger("mcp");
|
|
8355
8322
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
8356
8323
|
constructor() {
|
|
8357
8324
|
__publicField(this, "mockRes");
|
|
@@ -8406,21 +8373,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
8406
8373
|
id: 0
|
|
8407
8374
|
});
|
|
8408
8375
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
8409
|
-
|
|
8376
|
+
logger21.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
8410
8377
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
8411
8378
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
8412
8379
|
try {
|
|
8413
8380
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
8414
|
-
|
|
8381
|
+
logger21.info({ sessionId }, "Successfully spoofed initialization");
|
|
8415
8382
|
} catch (spoofError) {
|
|
8416
|
-
|
|
8383
|
+
logger21.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
8417
8384
|
}
|
|
8418
8385
|
};
|
|
8419
8386
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
8420
8387
|
const sessionId = req.headers["mcp-session-id"];
|
|
8421
|
-
|
|
8388
|
+
logger21.info({ sessionId }, "Received MCP session ID");
|
|
8422
8389
|
if (!sessionId) {
|
|
8423
|
-
|
|
8390
|
+
logger21.info({ body }, "Missing session ID");
|
|
8424
8391
|
res.writeHead(400).end(
|
|
8425
8392
|
JSON.stringify({
|
|
8426
8393
|
jsonrpc: "2.0",
|
|
@@ -8446,7 +8413,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8446
8413
|
scopes: { tenantId, projectId },
|
|
8447
8414
|
conversationId: sessionId
|
|
8448
8415
|
});
|
|
8449
|
-
|
|
8416
|
+
logger21.info(
|
|
8450
8417
|
{
|
|
8451
8418
|
sessionId,
|
|
8452
8419
|
conversationFound: !!conversation,
|
|
@@ -8457,7 +8424,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8457
8424
|
"Conversation lookup result"
|
|
8458
8425
|
);
|
|
8459
8426
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
8460
|
-
|
|
8427
|
+
logger21.info(
|
|
8461
8428
|
{ sessionId, conversationId: conversation?.id },
|
|
8462
8429
|
"MCP session not found or invalid"
|
|
8463
8430
|
);
|
|
@@ -8518,7 +8485,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
8518
8485
|
requestId: requestId2,
|
|
8519
8486
|
sseHelper: mcpStreamHelper
|
|
8520
8487
|
});
|
|
8521
|
-
|
|
8488
|
+
logger21.info(
|
|
8522
8489
|
{ result },
|
|
8523
8490
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8524
8491
|
);
|
|
@@ -8592,7 +8559,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
8592
8559
|
dbClient_default,
|
|
8593
8560
|
credentialStores
|
|
8594
8561
|
);
|
|
8595
|
-
|
|
8562
|
+
logger21.info(
|
|
8596
8563
|
{
|
|
8597
8564
|
tenantId,
|
|
8598
8565
|
graphId,
|
|
@@ -8631,10 +8598,10 @@ var validateRequestParameters = (c) => {
|
|
|
8631
8598
|
try {
|
|
8632
8599
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
8633
8600
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8634
|
-
getLogger("mcp").debug({ tenantId, projectId, graphId }, "Extracted MCP entity parameters");
|
|
8601
|
+
agentsCore.getLogger("mcp").debug({ tenantId, projectId, graphId }, "Extracted MCP entity parameters");
|
|
8635
8602
|
return { valid: true, executionContext };
|
|
8636
8603
|
} catch (error) {
|
|
8637
|
-
getLogger("chat").warn(
|
|
8604
|
+
agentsCore.getLogger("chat").warn(
|
|
8638
8605
|
{ error: error instanceof Error ? error.message : "Unknown error" },
|
|
8639
8606
|
"Failed to get execution context"
|
|
8640
8607
|
);
|
|
@@ -8653,7 +8620,7 @@ var validateRequestParameters = (c) => {
|
|
|
8653
8620
|
};
|
|
8654
8621
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
8655
8622
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8656
|
-
|
|
8623
|
+
logger21.info({ body }, "Received initialization request");
|
|
8657
8624
|
const sessionId = nanoid.nanoid();
|
|
8658
8625
|
const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
8659
8626
|
scopes: { tenantId, projectId },
|
|
@@ -8684,7 +8651,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8684
8651
|
}
|
|
8685
8652
|
}
|
|
8686
8653
|
});
|
|
8687
|
-
|
|
8654
|
+
logger21.info(
|
|
8688
8655
|
{ sessionId, conversationId: conversation.id },
|
|
8689
8656
|
"Created MCP session as conversation"
|
|
8690
8657
|
);
|
|
@@ -8693,9 +8660,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8693
8660
|
});
|
|
8694
8661
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
8695
8662
|
await server.connect(transport);
|
|
8696
|
-
|
|
8663
|
+
logger21.info({ sessionId }, "Server connected for initialization");
|
|
8697
8664
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
8698
|
-
|
|
8665
|
+
logger21.info(
|
|
8699
8666
|
{
|
|
8700
8667
|
sessionId,
|
|
8701
8668
|
bodyMethod: body?.method,
|
|
@@ -8704,7 +8671,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8704
8671
|
"About to handle initialization request"
|
|
8705
8672
|
);
|
|
8706
8673
|
await transport.handleRequest(req, res, body);
|
|
8707
|
-
|
|
8674
|
+
logger21.info({ sessionId }, "Successfully handled initialization request");
|
|
8708
8675
|
return fetchToNode.toFetchResponse(res);
|
|
8709
8676
|
};
|
|
8710
8677
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -8732,8 +8699,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8732
8699
|
sessionId,
|
|
8733
8700
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
8734
8701
|
);
|
|
8735
|
-
|
|
8736
|
-
|
|
8702
|
+
logger21.info({ sessionId }, "Server connected and transport initialized");
|
|
8703
|
+
logger21.info(
|
|
8737
8704
|
{
|
|
8738
8705
|
sessionId,
|
|
8739
8706
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -8747,9 +8714,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8747
8714
|
);
|
|
8748
8715
|
try {
|
|
8749
8716
|
await transport.handleRequest(req, res, body);
|
|
8750
|
-
|
|
8717
|
+
logger21.info({ sessionId }, "Successfully handled MCP request");
|
|
8751
8718
|
} catch (transportError) {
|
|
8752
|
-
|
|
8719
|
+
logger21.error(
|
|
8753
8720
|
{
|
|
8754
8721
|
sessionId,
|
|
8755
8722
|
error: transportError,
|
|
@@ -8800,13 +8767,13 @@ app4.openapi(
|
|
|
8800
8767
|
}
|
|
8801
8768
|
const { executionContext } = paramValidation;
|
|
8802
8769
|
const body = await c.req.json();
|
|
8803
|
-
|
|
8770
|
+
logger21.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
8804
8771
|
const isInitRequest = body.method === "initialize";
|
|
8805
8772
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
8806
8773
|
const validatedContext = c.get("validatedContext") || {};
|
|
8807
8774
|
const credentialStores = c.get("credentialStores");
|
|
8808
|
-
|
|
8809
|
-
|
|
8775
|
+
logger21.info({ validatedContext }, "Validated context");
|
|
8776
|
+
logger21.info({ req }, "request");
|
|
8810
8777
|
if (isInitRequest) {
|
|
8811
8778
|
return await handleInitializationRequest(
|
|
8812
8779
|
body,
|
|
@@ -8828,7 +8795,7 @@ app4.openapi(
|
|
|
8828
8795
|
);
|
|
8829
8796
|
}
|
|
8830
8797
|
} catch (e) {
|
|
8831
|
-
|
|
8798
|
+
logger21.error(
|
|
8832
8799
|
{
|
|
8833
8800
|
error: e instanceof Error ? e.message : e,
|
|
8834
8801
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -8840,7 +8807,7 @@ app4.openapi(
|
|
|
8840
8807
|
}
|
|
8841
8808
|
);
|
|
8842
8809
|
app4.get("/", async (c) => {
|
|
8843
|
-
|
|
8810
|
+
logger21.info({}, "Received GET MCP request");
|
|
8844
8811
|
return c.json(
|
|
8845
8812
|
{
|
|
8846
8813
|
jsonrpc: "2.0",
|
|
@@ -8854,7 +8821,7 @@ app4.get("/", async (c) => {
|
|
|
8854
8821
|
);
|
|
8855
8822
|
});
|
|
8856
8823
|
app4.delete("/", async (c) => {
|
|
8857
|
-
|
|
8824
|
+
logger21.info({}, "Received DELETE MCP request");
|
|
8858
8825
|
return c.json(
|
|
8859
8826
|
{
|
|
8860
8827
|
jsonrpc: "2.0",
|
|
@@ -8867,7 +8834,7 @@ app4.delete("/", async (c) => {
|
|
|
8867
8834
|
var mcp_default = app4;
|
|
8868
8835
|
|
|
8869
8836
|
// src/app.ts
|
|
8870
|
-
var
|
|
8837
|
+
var logger22 = agentsCore.getLogger("agents-run-api");
|
|
8871
8838
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
8872
8839
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
8873
8840
|
app6.use("*", requestId.requestId());
|
|
@@ -8891,7 +8858,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8891
8858
|
});
|
|
8892
8859
|
app6.use(
|
|
8893
8860
|
honoPino.pinoLogger({
|
|
8894
|
-
pino:
|
|
8861
|
+
pino: logger22 || pino.pino({ level: "debug" }),
|
|
8895
8862
|
http: {
|
|
8896
8863
|
onResLevel(c) {
|
|
8897
8864
|
if (c.res.status >= 500) {
|
|
@@ -8935,8 +8902,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8935
8902
|
if (!isExpectedError) {
|
|
8936
8903
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
8937
8904
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
8938
|
-
if (
|
|
8939
|
-
|
|
8905
|
+
if (logger22) {
|
|
8906
|
+
logger22.error(
|
|
8940
8907
|
{
|
|
8941
8908
|
error: err,
|
|
8942
8909
|
message: errorMessage,
|
|
@@ -8948,8 +8915,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8948
8915
|
);
|
|
8949
8916
|
}
|
|
8950
8917
|
} else {
|
|
8951
|
-
if (
|
|
8952
|
-
|
|
8918
|
+
if (logger22) {
|
|
8919
|
+
logger22.error(
|
|
8953
8920
|
{
|
|
8954
8921
|
error: err,
|
|
8955
8922
|
path: c.req.path,
|
|
@@ -8966,8 +8933,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8966
8933
|
const response = err.getResponse();
|
|
8967
8934
|
return response;
|
|
8968
8935
|
} catch (responseError) {
|
|
8969
|
-
if (
|
|
8970
|
-
|
|
8936
|
+
if (logger22) {
|
|
8937
|
+
logger22.error({ error: responseError }, "Error while handling HTTPException response");
|
|
8971
8938
|
}
|
|
8972
8939
|
}
|
|
8973
8940
|
}
|
|
@@ -9001,7 +8968,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
9001
8968
|
app6.use("*", async (c, next) => {
|
|
9002
8969
|
const executionContext = c.get("executionContext");
|
|
9003
8970
|
if (!executionContext) {
|
|
9004
|
-
|
|
8971
|
+
logger22.debug({}, "Empty execution context");
|
|
9005
8972
|
return next();
|
|
9006
8973
|
}
|
|
9007
8974
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -9012,7 +8979,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
9012
8979
|
const body = await cloned.json().catch(() => null);
|
|
9013
8980
|
conversationId = body?.conversationId;
|
|
9014
8981
|
} catch (_) {
|
|
9015
|
-
|
|
8982
|
+
logger22.debug({}, "Conversation ID not found in JSON body");
|
|
9016
8983
|
}
|
|
9017
8984
|
}
|
|
9018
8985
|
const entries = Object.fromEntries(
|
|
@@ -9027,7 +8994,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
9027
8994
|
})
|
|
9028
8995
|
);
|
|
9029
8996
|
if (!Object.keys(entries).length) {
|
|
9030
|
-
|
|
8997
|
+
logger22.debug({}, "Empty entries for baggage");
|
|
9031
8998
|
return next();
|
|
9032
8999
|
}
|
|
9033
9000
|
const bag = Object.entries(entries).reduce(
|