@inkeep/agents-run-api 0.1.8 → 0.1.10
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 +267 -307
- package/dist/index.js +263 -298
- package/package.json +12 -13
package/dist/index.cjs
CHANGED
|
@@ -10,18 +10,18 @@ var agentsCore = require('@inkeep/agents-core');
|
|
|
10
10
|
var nanoid = require('nanoid');
|
|
11
11
|
var autoInstrumentationsNode = require('@opentelemetry/auto-instrumentations-node');
|
|
12
12
|
var baggageSpanProcessor = require('@opentelemetry/baggage-span-processor');
|
|
13
|
-
var
|
|
13
|
+
var exporterTraceOtlpHttp = require('@opentelemetry/exporter-trace-otlp-http');
|
|
14
14
|
var sdkNode = require('@opentelemetry/sdk-node');
|
|
15
|
-
var
|
|
16
|
-
var
|
|
15
|
+
var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
16
|
+
var semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
17
|
+
var resources = require('@opentelemetry/resources');
|
|
18
|
+
var contextAsyncHooks = require('@opentelemetry/context-async-hooks');
|
|
17
19
|
var zodOpenapi = require('@hono/zod-openapi');
|
|
18
20
|
var api = require('@opentelemetry/api');
|
|
21
|
+
var hono = require('hono');
|
|
19
22
|
var cors = require('hono/cors');
|
|
20
23
|
var httpException = require('hono/http-exception');
|
|
21
24
|
var requestId = require('hono/request-id');
|
|
22
|
-
var honoPino = require('hono-pino');
|
|
23
|
-
var pino = require('pino');
|
|
24
|
-
var async_hooks = require('async_hooks');
|
|
25
25
|
var factory = require('hono/factory');
|
|
26
26
|
var swaggerUi = require('@hono/swagger-ui');
|
|
27
27
|
var streaming = require('hono/streaming');
|
|
@@ -323,36 +323,18 @@ var init_conversations = __esm({
|
|
|
323
323
|
|
|
324
324
|
// src/instrumentation.ts
|
|
325
325
|
init_env();
|
|
326
|
-
var otlpExporter = new exporterTraceOtlpProto.OTLPTraceExporter();
|
|
327
|
-
var FanOutSpanProcessor = class {
|
|
328
|
-
constructor(inner) {
|
|
329
|
-
this.inner = inner;
|
|
330
|
-
}
|
|
331
|
-
onStart(span, parent) {
|
|
332
|
-
this.inner.forEach((p) => p.onStart(span, parent));
|
|
333
|
-
}
|
|
334
|
-
onEnd(span) {
|
|
335
|
-
this.inner.forEach((p) => p.onEnd(span));
|
|
336
|
-
}
|
|
337
|
-
forceFlush() {
|
|
338
|
-
return Promise.all(this.inner.map((p) => p.forceFlush?.())).then(() => {
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
shutdown() {
|
|
342
|
-
return Promise.all(this.inner.map((p) => p.shutdown?.())).then(() => {
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
326
|
var maxExportBatchSize = env.OTEL_MAX_EXPORT_BATCH_SIZE ?? (env.ENVIRONMENT === "development" ? 1 : 512);
|
|
347
|
-
var
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
]
|
|
327
|
+
var otlpExporter = new exporterTraceOtlpHttp.OTLPTraceExporter();
|
|
328
|
+
var batchProcessor = new sdkTraceBase.BatchSpanProcessor(otlpExporter, {
|
|
329
|
+
maxExportBatchSize
|
|
330
|
+
});
|
|
331
|
+
var resource = resources.resourceFromAttributes({
|
|
332
|
+
[semanticConventions.ATTR_SERVICE_NAME]: "inkeep-agents-run-api"
|
|
333
|
+
});
|
|
353
334
|
var sdk = new sdkNode.NodeSDK({
|
|
354
|
-
|
|
355
|
-
|
|
335
|
+
resource,
|
|
336
|
+
contextManager: new contextAsyncHooks.AsyncLocalStorageContextManager(),
|
|
337
|
+
spanProcessors: [new baggageSpanProcessor.BaggageSpanProcessor(baggageSpanProcessor.ALLOW_ALL_BAGGAGE_KEYS), batchProcessor],
|
|
356
338
|
instrumentations: [
|
|
357
339
|
autoInstrumentationsNode.getNodeAutoInstrumentations({
|
|
358
340
|
"@opentelemetry/instrumentation-http": {
|
|
@@ -377,42 +359,6 @@ var sdk = new sdkNode.NodeSDK({
|
|
|
377
359
|
]
|
|
378
360
|
});
|
|
379
361
|
sdk.start();
|
|
380
|
-
|
|
381
|
-
// src/logger.ts
|
|
382
|
-
init_env();
|
|
383
|
-
var isDevelopment = env.ENVIRONMENT === "development";
|
|
384
|
-
var loggerConfig = {
|
|
385
|
-
level: env.LOG_LEVEL,
|
|
386
|
-
serializers: {
|
|
387
|
-
obj: (value) => ({ ...value })
|
|
388
|
-
},
|
|
389
|
-
redact: ["req.headers.authorization", 'req.headers["x-inkeep-admin-authentication"]'],
|
|
390
|
-
// Only use pino-pretty in development
|
|
391
|
-
...isDevelopment && {
|
|
392
|
-
transport: {
|
|
393
|
-
target: "pino-pretty",
|
|
394
|
-
options: {
|
|
395
|
-
sync: true,
|
|
396
|
-
destination: 1,
|
|
397
|
-
// stdout
|
|
398
|
-
colorize: true,
|
|
399
|
-
translateTime: "SYS:standard"
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
var logger = pino.pino(loggerConfig);
|
|
405
|
-
var asyncLocalStorage = new async_hooks.AsyncLocalStorage();
|
|
406
|
-
function getLogger(name) {
|
|
407
|
-
const store = asyncLocalStorage.getStore();
|
|
408
|
-
const reqId = store?.get("requestId") || void 0;
|
|
409
|
-
if (!reqId) {
|
|
410
|
-
return logger.child({ name });
|
|
411
|
-
}
|
|
412
|
-
return logger.child({ reqId, name });
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// src/middleware/api-key-auth.ts
|
|
416
362
|
init_dbClient();
|
|
417
363
|
init_env();
|
|
418
364
|
|
|
@@ -430,7 +376,7 @@ function createExecutionContext(params) {
|
|
|
430
376
|
}
|
|
431
377
|
|
|
432
378
|
// src/middleware/api-key-auth.ts
|
|
433
|
-
var
|
|
379
|
+
var logger = agentsCore.getLogger("env-key-auth");
|
|
434
380
|
var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
435
381
|
if (c.req.method === "OPTIONS") {
|
|
436
382
|
await next();
|
|
@@ -447,7 +393,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
447
393
|
if (authHeader?.startsWith("Bearer ")) {
|
|
448
394
|
try {
|
|
449
395
|
executionContext = await extractContextFromApiKey(authHeader.substring(7));
|
|
450
|
-
|
|
396
|
+
logger.info({}, "Development/test environment - API key authenticated successfully");
|
|
451
397
|
} catch {
|
|
452
398
|
executionContext = createExecutionContext({
|
|
453
399
|
apiKey: "development",
|
|
@@ -458,7 +404,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
458
404
|
baseUrl,
|
|
459
405
|
agentId
|
|
460
406
|
});
|
|
461
|
-
|
|
407
|
+
logger.info(
|
|
462
408
|
{},
|
|
463
409
|
"Development/test environment - fallback to default context due to invalid API key"
|
|
464
410
|
);
|
|
@@ -473,7 +419,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
473
419
|
baseUrl,
|
|
474
420
|
agentId
|
|
475
421
|
});
|
|
476
|
-
|
|
422
|
+
logger.info(
|
|
477
423
|
{},
|
|
478
424
|
"Development/test environment - no API key provided, using default context"
|
|
479
425
|
);
|
|
@@ -505,13 +451,13 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
505
451
|
agentId
|
|
506
452
|
});
|
|
507
453
|
c.set("executionContext", executionContext);
|
|
508
|
-
|
|
454
|
+
logger.info({}, "Bypass secret authenticated successfully");
|
|
509
455
|
await next();
|
|
510
456
|
return;
|
|
511
457
|
} else if (apiKey) {
|
|
512
458
|
const executionContext = await extractContextFromApiKey(apiKey);
|
|
513
459
|
c.set("executionContext", executionContext);
|
|
514
|
-
|
|
460
|
+
logger.info({}, "API key authenticated successfully");
|
|
515
461
|
await next();
|
|
516
462
|
return;
|
|
517
463
|
} else {
|
|
@@ -528,7 +474,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
528
474
|
try {
|
|
529
475
|
const executionContext = await extractContextFromApiKey(apiKey);
|
|
530
476
|
c.set("executionContext", executionContext);
|
|
531
|
-
|
|
477
|
+
logger.debug(
|
|
532
478
|
{
|
|
533
479
|
tenantId: executionContext.tenantId,
|
|
534
480
|
projectId: executionContext.projectId,
|
|
@@ -541,7 +487,7 @@ var apiKeyAuth = () => factory.createMiddleware(async (c, next) => {
|
|
|
541
487
|
if (error instanceof httpException.HTTPException) {
|
|
542
488
|
throw error;
|
|
543
489
|
}
|
|
544
|
-
|
|
490
|
+
logger.error({ error }, "API key authentication error");
|
|
545
491
|
throw new httpException.HTTPException(500, {
|
|
546
492
|
message: "Authentication failed"
|
|
547
493
|
});
|
|
@@ -600,10 +546,10 @@ function setupOpenAPIRoutes(app6) {
|
|
|
600
546
|
|
|
601
547
|
// src/a2a/handlers.ts
|
|
602
548
|
init_dbClient();
|
|
603
|
-
var
|
|
549
|
+
var logger2 = agentsCore.getLogger("a2aHandler");
|
|
604
550
|
async function a2aHandler(c, agent) {
|
|
605
551
|
try {
|
|
606
|
-
const rpcRequest =
|
|
552
|
+
const rpcRequest = c.get("requestBody");
|
|
607
553
|
if (rpcRequest.jsonrpc !== "2.0") {
|
|
608
554
|
return c.json({
|
|
609
555
|
jsonrpc: "2.0",
|
|
@@ -702,7 +648,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
702
648
|
messageId: task.id,
|
|
703
649
|
kind: "message"
|
|
704
650
|
});
|
|
705
|
-
|
|
651
|
+
logger2.warn(
|
|
706
652
|
{
|
|
707
653
|
taskId: task.id,
|
|
708
654
|
agentId: agent.agentId,
|
|
@@ -712,7 +658,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
712
658
|
);
|
|
713
659
|
}
|
|
714
660
|
} catch (error) {
|
|
715
|
-
|
|
661
|
+
logger2.error({ error, taskId: task.id }, "Failed to serialize message");
|
|
716
662
|
JSON.stringify({
|
|
717
663
|
error: "Failed to serialize message",
|
|
718
664
|
taskId: task.id,
|
|
@@ -720,7 +666,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
720
666
|
parts: [{ text: "Error in delegation", kind: "text" }]
|
|
721
667
|
});
|
|
722
668
|
}
|
|
723
|
-
|
|
669
|
+
logger2.info(
|
|
724
670
|
{
|
|
725
671
|
originalContextId: params.message.contextId,
|
|
726
672
|
taskContextId: task.context?.conversationId,
|
|
@@ -749,7 +695,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
749
695
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
750
696
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
751
697
|
});
|
|
752
|
-
|
|
698
|
+
logger2.info({ metadata: params.message.metadata }, "message metadata");
|
|
753
699
|
if (params.message.metadata?.fromAgentId || params.message.metadata?.fromExternalAgentId) {
|
|
754
700
|
const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
|
|
755
701
|
try {
|
|
@@ -774,7 +720,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
774
720
|
messageData.toAgentId = agent.agentId;
|
|
775
721
|
}
|
|
776
722
|
await agentsCore.createMessage(dbClient_default)(messageData);
|
|
777
|
-
|
|
723
|
+
logger2.info(
|
|
778
724
|
{
|
|
779
725
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
780
726
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
@@ -786,7 +732,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
786
732
|
"A2A message stored in database"
|
|
787
733
|
);
|
|
788
734
|
} catch (error) {
|
|
789
|
-
|
|
735
|
+
logger2.error(
|
|
790
736
|
{
|
|
791
737
|
error,
|
|
792
738
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
@@ -823,7 +769,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
823
769
|
(part) => part.kind === "data" && part.data && typeof part.data === "object" && part.data.type === "transfer"
|
|
824
770
|
);
|
|
825
771
|
if (transferPart && transferPart.kind === "data" && transferPart.data) {
|
|
826
|
-
|
|
772
|
+
logger2.info({ transferPart }, "transferPart");
|
|
827
773
|
return c.json({
|
|
828
774
|
jsonrpc: "2.0",
|
|
829
775
|
result: {
|
|
@@ -1248,10 +1194,10 @@ function statusUpdateOp(ctx) {
|
|
|
1248
1194
|
ctx
|
|
1249
1195
|
};
|
|
1250
1196
|
}
|
|
1251
|
-
var
|
|
1197
|
+
var logger3 = agentsCore.getLogger("DataComponentSchema");
|
|
1252
1198
|
function jsonSchemaToZod(jsonSchema) {
|
|
1253
1199
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
1254
|
-
|
|
1200
|
+
logger3.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
1255
1201
|
return z5.z.string();
|
|
1256
1202
|
}
|
|
1257
1203
|
switch (jsonSchema.type) {
|
|
@@ -1278,7 +1224,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
1278
1224
|
case "null":
|
|
1279
1225
|
return z5.z.null();
|
|
1280
1226
|
default:
|
|
1281
|
-
|
|
1227
|
+
logger3.warn(
|
|
1282
1228
|
{
|
|
1283
1229
|
unsupportedType: jsonSchema.type,
|
|
1284
1230
|
schema: jsonSchema
|
|
@@ -1290,7 +1236,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
1290
1236
|
}
|
|
1291
1237
|
|
|
1292
1238
|
// src/utils/artifact-component-schema.ts
|
|
1293
|
-
getLogger("ArtifactComponentSchema");
|
|
1239
|
+
agentsCore.getLogger("ArtifactComponentSchema");
|
|
1294
1240
|
var _ArtifactReferenceSchema = class _ArtifactReferenceSchema {
|
|
1295
1241
|
/**
|
|
1296
1242
|
* Get the standard Zod schema for artifact reference components
|
|
@@ -1332,7 +1278,7 @@ __publicField(_ArtifactReferenceSchema, "ARTIFACT_PROPS_SCHEMA", {
|
|
|
1332
1278
|
required: ["artifact_id", "task_id"]
|
|
1333
1279
|
});
|
|
1334
1280
|
var ArtifactReferenceSchema = _ArtifactReferenceSchema;
|
|
1335
|
-
var
|
|
1281
|
+
var logger4 = agentsCore.getLogger("ModelFactory");
|
|
1336
1282
|
var _ModelFactory = class _ModelFactory {
|
|
1337
1283
|
/**
|
|
1338
1284
|
* Create a language model instance from configuration
|
|
@@ -1347,7 +1293,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1347
1293
|
const modelSettings = config2;
|
|
1348
1294
|
const modelString = modelSettings.model.trim();
|
|
1349
1295
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1350
|
-
|
|
1296
|
+
logger4.debug(
|
|
1351
1297
|
{
|
|
1352
1298
|
provider,
|
|
1353
1299
|
model: modelName,
|
|
@@ -1368,7 +1314,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1368
1314
|
);
|
|
1369
1315
|
}
|
|
1370
1316
|
} catch (error) {
|
|
1371
|
-
|
|
1317
|
+
logger4.error(
|
|
1372
1318
|
{
|
|
1373
1319
|
provider,
|
|
1374
1320
|
model: modelName,
|
|
@@ -1391,7 +1337,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1391
1337
|
const [provider, ...modelParts] = modelString.split("/");
|
|
1392
1338
|
const normalizedProvider = provider.toLowerCase();
|
|
1393
1339
|
if (!_ModelFactory.SUPPORTED_PROVIDERS.includes(normalizedProvider)) {
|
|
1394
|
-
|
|
1340
|
+
logger4.warn(
|
|
1395
1341
|
{ provider: normalizedProvider, modelName: modelParts.join("/") },
|
|
1396
1342
|
"Unsupported provider detected, falling back to anthropic"
|
|
1397
1343
|
);
|
|
@@ -1420,14 +1366,14 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1420
1366
|
anthropicConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1421
1367
|
}
|
|
1422
1368
|
if (providerOptions?.gateway) {
|
|
1423
|
-
|
|
1369
|
+
logger4.info(
|
|
1424
1370
|
{ gateway: providerOptions.gateway },
|
|
1425
1371
|
"Setting up AI Gateway for Anthropic model"
|
|
1426
1372
|
);
|
|
1427
1373
|
Object.assign(anthropicConfig, providerOptions.gateway);
|
|
1428
1374
|
}
|
|
1429
1375
|
if (Object.keys(anthropicConfig).length > 0) {
|
|
1430
|
-
|
|
1376
|
+
logger4.info({ config: anthropicConfig }, "Applying custom Anthropic provider configuration");
|
|
1431
1377
|
const provider = anthropic.createAnthropic(anthropicConfig);
|
|
1432
1378
|
return provider(modelName);
|
|
1433
1379
|
}
|
|
@@ -1442,11 +1388,11 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1442
1388
|
openaiConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1443
1389
|
}
|
|
1444
1390
|
if (providerOptions?.gateway) {
|
|
1445
|
-
|
|
1391
|
+
logger4.info({ gateway: providerOptions.gateway }, "Setting up AI Gateway for OpenAI model");
|
|
1446
1392
|
Object.assign(openaiConfig, providerOptions.gateway);
|
|
1447
1393
|
}
|
|
1448
1394
|
if (Object.keys(openaiConfig).length > 0) {
|
|
1449
|
-
|
|
1395
|
+
logger4.info({ config: openaiConfig }, "Applying custom OpenAI provider configuration");
|
|
1450
1396
|
const provider = openai.createOpenAI(openaiConfig);
|
|
1451
1397
|
return provider(modelName);
|
|
1452
1398
|
}
|
|
@@ -1540,7 +1486,7 @@ function unregisterStreamHelper(requestId2) {
|
|
|
1540
1486
|
}
|
|
1541
1487
|
|
|
1542
1488
|
// src/utils/graph-session.ts
|
|
1543
|
-
var
|
|
1489
|
+
var logger5 = agentsCore.getLogger("GraphSession");
|
|
1544
1490
|
var GraphSession = class {
|
|
1545
1491
|
// Track scheduled timeouts for cleanup
|
|
1546
1492
|
constructor(sessionId, messageId, graphId, tenantId, projectId) {
|
|
@@ -1564,7 +1510,7 @@ var GraphSession = class {
|
|
|
1564
1510
|
__publicField(this, "MAX_PENDING_ARTIFACTS", 100);
|
|
1565
1511
|
// Prevent unbounded growth
|
|
1566
1512
|
__publicField(this, "scheduledTimeouts");
|
|
1567
|
-
|
|
1513
|
+
logger5.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
1568
1514
|
}
|
|
1569
1515
|
/**
|
|
1570
1516
|
* Initialize status updates for this session
|
|
@@ -1586,7 +1532,7 @@ var GraphSession = class {
|
|
|
1586
1532
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
1587
1533
|
this.statusUpdateTimer = setInterval(async () => {
|
|
1588
1534
|
if (!this.statusUpdateState || this.isEnded) {
|
|
1589
|
-
|
|
1535
|
+
logger5.debug(
|
|
1590
1536
|
{ sessionId: this.sessionId },
|
|
1591
1537
|
"Timer triggered but session already cleaned up or ended"
|
|
1592
1538
|
);
|
|
@@ -1598,7 +1544,7 @@ var GraphSession = class {
|
|
|
1598
1544
|
}
|
|
1599
1545
|
await this.checkAndSendTimeBasedUpdate();
|
|
1600
1546
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
1601
|
-
|
|
1547
|
+
logger5.info(
|
|
1602
1548
|
{
|
|
1603
1549
|
sessionId: this.sessionId,
|
|
1604
1550
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -1612,7 +1558,7 @@ var GraphSession = class {
|
|
|
1612
1558
|
*/
|
|
1613
1559
|
recordEvent(eventType, agentId, data) {
|
|
1614
1560
|
if (this.isEnded) {
|
|
1615
|
-
|
|
1561
|
+
logger5.debug(
|
|
1616
1562
|
{
|
|
1617
1563
|
sessionId: this.sessionId,
|
|
1618
1564
|
eventType,
|
|
@@ -1632,7 +1578,7 @@ var GraphSession = class {
|
|
|
1632
1578
|
if (eventType === "artifact_saved" && data.pendingGeneration) {
|
|
1633
1579
|
const artifactId = data.artifactId;
|
|
1634
1580
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
1635
|
-
|
|
1581
|
+
logger5.warn(
|
|
1636
1582
|
{
|
|
1637
1583
|
sessionId: this.sessionId,
|
|
1638
1584
|
artifactId,
|
|
@@ -1653,7 +1599,7 @@ var GraphSession = class {
|
|
|
1653
1599
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
1654
1600
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
1655
1601
|
this.pendingArtifacts.delete(artifactId);
|
|
1656
|
-
|
|
1602
|
+
logger5.error(
|
|
1657
1603
|
{
|
|
1658
1604
|
sessionId: this.sessionId,
|
|
1659
1605
|
artifactId,
|
|
@@ -1665,7 +1611,7 @@ var GraphSession = class {
|
|
|
1665
1611
|
"Artifact processing failed after max retries, giving up"
|
|
1666
1612
|
);
|
|
1667
1613
|
} else {
|
|
1668
|
-
|
|
1614
|
+
logger5.warn(
|
|
1669
1615
|
{
|
|
1670
1616
|
sessionId: this.sessionId,
|
|
1671
1617
|
artifactId,
|
|
@@ -1687,14 +1633,14 @@ var GraphSession = class {
|
|
|
1687
1633
|
*/
|
|
1688
1634
|
checkStatusUpdates() {
|
|
1689
1635
|
if (this.isEnded) {
|
|
1690
|
-
|
|
1636
|
+
logger5.debug(
|
|
1691
1637
|
{ sessionId: this.sessionId },
|
|
1692
1638
|
"Session has ended - skipping status update check"
|
|
1693
1639
|
);
|
|
1694
1640
|
return;
|
|
1695
1641
|
}
|
|
1696
1642
|
if (!this.statusUpdateState) {
|
|
1697
|
-
|
|
1643
|
+
logger5.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
1698
1644
|
return;
|
|
1699
1645
|
}
|
|
1700
1646
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -1705,11 +1651,11 @@ var GraphSession = class {
|
|
|
1705
1651
|
*/
|
|
1706
1652
|
async checkAndSendTimeBasedUpdate() {
|
|
1707
1653
|
if (this.isEnded) {
|
|
1708
|
-
|
|
1654
|
+
logger5.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
1709
1655
|
return;
|
|
1710
1656
|
}
|
|
1711
1657
|
if (!this.statusUpdateState) {
|
|
1712
|
-
|
|
1658
|
+
logger5.debug(
|
|
1713
1659
|
{ sessionId: this.sessionId },
|
|
1714
1660
|
"No status updates configured for time-based check"
|
|
1715
1661
|
);
|
|
@@ -1722,7 +1668,7 @@ var GraphSession = class {
|
|
|
1722
1668
|
try {
|
|
1723
1669
|
await this.generateAndSendUpdate();
|
|
1724
1670
|
} catch (error) {
|
|
1725
|
-
|
|
1671
|
+
logger5.error(
|
|
1726
1672
|
{
|
|
1727
1673
|
sessionId: this.sessionId,
|
|
1728
1674
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1815,29 +1761,29 @@ var GraphSession = class {
|
|
|
1815
1761
|
*/
|
|
1816
1762
|
async generateAndSendUpdate() {
|
|
1817
1763
|
if (this.isEnded) {
|
|
1818
|
-
|
|
1764
|
+
logger5.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
1819
1765
|
return;
|
|
1820
1766
|
}
|
|
1821
1767
|
if (this.isTextStreaming) {
|
|
1822
|
-
|
|
1768
|
+
logger5.debug(
|
|
1823
1769
|
{ sessionId: this.sessionId },
|
|
1824
1770
|
"Text is currently streaming - skipping status update"
|
|
1825
1771
|
);
|
|
1826
1772
|
return;
|
|
1827
1773
|
}
|
|
1828
1774
|
if (this.isGeneratingUpdate) {
|
|
1829
|
-
|
|
1775
|
+
logger5.debug(
|
|
1830
1776
|
{ sessionId: this.sessionId },
|
|
1831
1777
|
"Update already in progress - skipping duplicate generation"
|
|
1832
1778
|
);
|
|
1833
1779
|
return;
|
|
1834
1780
|
}
|
|
1835
1781
|
if (!this.statusUpdateState) {
|
|
1836
|
-
|
|
1782
|
+
logger5.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
1837
1783
|
return;
|
|
1838
1784
|
}
|
|
1839
1785
|
if (!this.graphId) {
|
|
1840
|
-
|
|
1786
|
+
logger5.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
1841
1787
|
return;
|
|
1842
1788
|
}
|
|
1843
1789
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -1850,7 +1796,7 @@ var GraphSession = class {
|
|
|
1850
1796
|
try {
|
|
1851
1797
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
1852
1798
|
if (!streamHelper) {
|
|
1853
|
-
|
|
1799
|
+
logger5.warn(
|
|
1854
1800
|
{ sessionId: this.sessionId },
|
|
1855
1801
|
"No stream helper found - cannot send status update"
|
|
1856
1802
|
);
|
|
@@ -1871,7 +1817,7 @@ var GraphSession = class {
|
|
|
1871
1817
|
if (result.operations && result.operations.length > 0) {
|
|
1872
1818
|
for (const op of result.operations) {
|
|
1873
1819
|
if (!op || !op.type || !op.data || Object.keys(op.data).length === 0) {
|
|
1874
|
-
|
|
1820
|
+
logger5.warn(
|
|
1875
1821
|
{
|
|
1876
1822
|
sessionId: this.sessionId,
|
|
1877
1823
|
operation: op
|
|
@@ -1924,7 +1870,7 @@ var GraphSession = class {
|
|
|
1924
1870
|
this.previousSummaries.shift();
|
|
1925
1871
|
}
|
|
1926
1872
|
if (!operation || !operation.type || !operation.ctx) {
|
|
1927
|
-
|
|
1873
|
+
logger5.warn(
|
|
1928
1874
|
{
|
|
1929
1875
|
sessionId: this.sessionId,
|
|
1930
1876
|
operation
|
|
@@ -1939,7 +1885,7 @@ var GraphSession = class {
|
|
|
1939
1885
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
1940
1886
|
}
|
|
1941
1887
|
} catch (error) {
|
|
1942
|
-
|
|
1888
|
+
logger5.error(
|
|
1943
1889
|
{
|
|
1944
1890
|
sessionId: this.sessionId,
|
|
1945
1891
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -1977,7 +1923,7 @@ var GraphSession = class {
|
|
|
1977
1923
|
this.releaseUpdateLock();
|
|
1978
1924
|
}
|
|
1979
1925
|
} catch (error) {
|
|
1980
|
-
|
|
1926
|
+
logger5.error(
|
|
1981
1927
|
{
|
|
1982
1928
|
sessionId: this.sessionId,
|
|
1983
1929
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2054,7 +2000,7 @@ User's Question/Context:
|
|
|
2054
2000
|
${conversationHistory}
|
|
2055
2001
|
` : "";
|
|
2056
2002
|
} catch (error) {
|
|
2057
|
-
|
|
2003
|
+
logger5.warn(
|
|
2058
2004
|
{ sessionId: this.sessionId, error },
|
|
2059
2005
|
"Failed to fetch conversation history for status update"
|
|
2060
2006
|
);
|
|
@@ -2106,7 +2052,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2106
2052
|
return text.trim();
|
|
2107
2053
|
} catch (error) {
|
|
2108
2054
|
agentsCore.setSpanWithError(span, error);
|
|
2109
|
-
|
|
2055
|
+
logger5.error({ error }, "Failed to generate summary, using fallback");
|
|
2110
2056
|
return this.generateFallbackSummary(newEvents, elapsedTime);
|
|
2111
2057
|
} finally {
|
|
2112
2058
|
span.end();
|
|
@@ -2152,7 +2098,7 @@ User's Question/Context:
|
|
|
2152
2098
|
${conversationHistory}
|
|
2153
2099
|
` : "";
|
|
2154
2100
|
} catch (error) {
|
|
2155
|
-
|
|
2101
|
+
logger5.warn(
|
|
2156
2102
|
{ sessionId: this.sessionId, error },
|
|
2157
2103
|
"Failed to fetch conversation history for structured status update"
|
|
2158
2104
|
);
|
|
@@ -2251,7 +2197,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2251
2197
|
return { operations };
|
|
2252
2198
|
} catch (error) {
|
|
2253
2199
|
agentsCore.setSpanWithError(span, error);
|
|
2254
|
-
|
|
2200
|
+
logger5.error({ error }, "Failed to generate structured update, using fallback");
|
|
2255
2201
|
return { operations: [] };
|
|
2256
2202
|
} finally {
|
|
2257
2203
|
span.end();
|
|
@@ -2578,7 +2524,7 @@ Make it specific and relevant.`;
|
|
|
2578
2524
|
taskId: artifactData.taskId,
|
|
2579
2525
|
artifacts: [artifactToSave]
|
|
2580
2526
|
});
|
|
2581
|
-
|
|
2527
|
+
logger5.info(
|
|
2582
2528
|
{
|
|
2583
2529
|
sessionId: this.sessionId,
|
|
2584
2530
|
artifactId: artifactData.artifactId,
|
|
@@ -2595,7 +2541,7 @@ Make it specific and relevant.`;
|
|
|
2595
2541
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
2596
2542
|
} catch (error) {
|
|
2597
2543
|
agentsCore.setSpanWithError(span, error);
|
|
2598
|
-
|
|
2544
|
+
logger5.error(
|
|
2599
2545
|
{
|
|
2600
2546
|
sessionId: this.sessionId,
|
|
2601
2547
|
artifactId: artifactData.artifactId,
|
|
@@ -2631,7 +2577,7 @@ Make it specific and relevant.`;
|
|
|
2631
2577
|
taskId: artifactData.taskId,
|
|
2632
2578
|
artifacts: [fallbackArtifact]
|
|
2633
2579
|
});
|
|
2634
|
-
|
|
2580
|
+
logger5.info(
|
|
2635
2581
|
{
|
|
2636
2582
|
sessionId: this.sessionId,
|
|
2637
2583
|
artifactId: artifactData.artifactId
|
|
@@ -2640,7 +2586,7 @@ Make it specific and relevant.`;
|
|
|
2640
2586
|
);
|
|
2641
2587
|
}
|
|
2642
2588
|
} catch (fallbackError) {
|
|
2643
|
-
|
|
2589
|
+
logger5.error(
|
|
2644
2590
|
{
|
|
2645
2591
|
sessionId: this.sessionId,
|
|
2646
2592
|
artifactId: artifactData.artifactId,
|
|
@@ -2667,7 +2613,7 @@ var GraphSessionManager = class {
|
|
|
2667
2613
|
const sessionId = messageId;
|
|
2668
2614
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId);
|
|
2669
2615
|
this.sessions.set(sessionId, session);
|
|
2670
|
-
|
|
2616
|
+
logger5.info({ sessionId, messageId, graphId, tenantId, projectId }, "GraphSession created");
|
|
2671
2617
|
return sessionId;
|
|
2672
2618
|
}
|
|
2673
2619
|
/**
|
|
@@ -2678,7 +2624,7 @@ var GraphSessionManager = class {
|
|
|
2678
2624
|
if (session) {
|
|
2679
2625
|
session.initializeStatusUpdates(config2, summarizerModel);
|
|
2680
2626
|
} else {
|
|
2681
|
-
|
|
2627
|
+
logger5.error(
|
|
2682
2628
|
{
|
|
2683
2629
|
sessionId,
|
|
2684
2630
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -2699,7 +2645,7 @@ var GraphSessionManager = class {
|
|
|
2699
2645
|
recordEvent(sessionId, eventType, agentId, data) {
|
|
2700
2646
|
const session = this.sessions.get(sessionId);
|
|
2701
2647
|
if (!session) {
|
|
2702
|
-
|
|
2648
|
+
logger5.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
2703
2649
|
return;
|
|
2704
2650
|
}
|
|
2705
2651
|
session.recordEvent(eventType, agentId, data);
|
|
@@ -2710,12 +2656,12 @@ var GraphSessionManager = class {
|
|
|
2710
2656
|
endSession(sessionId) {
|
|
2711
2657
|
const session = this.sessions.get(sessionId);
|
|
2712
2658
|
if (!session) {
|
|
2713
|
-
|
|
2659
|
+
logger5.warn({ sessionId }, "Attempted to end non-existent session");
|
|
2714
2660
|
return [];
|
|
2715
2661
|
}
|
|
2716
2662
|
const events = session.getEvents();
|
|
2717
2663
|
const summary = session.getSummary();
|
|
2718
|
-
|
|
2664
|
+
logger5.info({ sessionId, summary }, "GraphSession ended");
|
|
2719
2665
|
session.cleanup();
|
|
2720
2666
|
this.sessions.delete(sessionId);
|
|
2721
2667
|
return events;
|
|
@@ -2744,7 +2690,7 @@ var graphSessionManager = new GraphSessionManager();
|
|
|
2744
2690
|
|
|
2745
2691
|
// src/utils/artifact-parser.ts
|
|
2746
2692
|
init_dbClient();
|
|
2747
|
-
var
|
|
2693
|
+
var logger6 = agentsCore.getLogger("ArtifactParser");
|
|
2748
2694
|
var _ArtifactParser = class _ArtifactParser {
|
|
2749
2695
|
constructor(tenantId) {
|
|
2750
2696
|
this.tenantId = tenantId;
|
|
@@ -2810,7 +2756,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2810
2756
|
id: taskId
|
|
2811
2757
|
});
|
|
2812
2758
|
if (!task) {
|
|
2813
|
-
|
|
2759
|
+
logger6.warn({ taskId }, "Task not found when fetching artifacts");
|
|
2814
2760
|
continue;
|
|
2815
2761
|
}
|
|
2816
2762
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2822,9 +2768,9 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2822
2768
|
artifacts.set(key, artifact);
|
|
2823
2769
|
}
|
|
2824
2770
|
}
|
|
2825
|
-
|
|
2771
|
+
logger6.debug({ contextId, count: artifacts.size }, "Loaded context artifacts");
|
|
2826
2772
|
} catch (error) {
|
|
2827
|
-
|
|
2773
|
+
logger6.error({ error, contextId }, "Error loading context artifacts");
|
|
2828
2774
|
}
|
|
2829
2775
|
return artifacts;
|
|
2830
2776
|
}
|
|
@@ -2927,7 +2873,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2927
2873
|
id: taskId
|
|
2928
2874
|
});
|
|
2929
2875
|
if (!task) {
|
|
2930
|
-
|
|
2876
|
+
logger6.warn({ taskId }, "Task not found when fetching artifact");
|
|
2931
2877
|
return null;
|
|
2932
2878
|
}
|
|
2933
2879
|
const artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2939,7 +2885,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2939
2885
|
return this.formatArtifactData(artifacts[0], artifactId, taskId);
|
|
2940
2886
|
}
|
|
2941
2887
|
} catch (error) {
|
|
2942
|
-
|
|
2888
|
+
logger6.warn({ artifactId, taskId, error }, "Failed to fetch artifact");
|
|
2943
2889
|
}
|
|
2944
2890
|
return null;
|
|
2945
2891
|
}
|
|
@@ -2979,7 +2925,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_ARTIFACT_REGEX", /<(a(r(t(i(f(a(c(t(:
|
|
|
2979
2925
|
var ArtifactParser = _ArtifactParser;
|
|
2980
2926
|
|
|
2981
2927
|
// src/utils/incremental-stream-parser.ts
|
|
2982
|
-
var
|
|
2928
|
+
var logger7 = agentsCore.getLogger("IncrementalStreamParser");
|
|
2983
2929
|
var IncrementalStreamParser = class {
|
|
2984
2930
|
constructor(streamHelper, tenantId, contextId) {
|
|
2985
2931
|
__publicField(this, "buffer", "");
|
|
@@ -3039,13 +2985,13 @@ var IncrementalStreamParser = class {
|
|
|
3039
2985
|
if (part.type === "tool-call-delta" && part.toolName === targetToolName) {
|
|
3040
2986
|
const delta = part.argsTextDelta || "";
|
|
3041
2987
|
if (jsonBuffer.length + delta.length > MAX_BUFFER_SIZE) {
|
|
3042
|
-
|
|
2988
|
+
logger7.warn("JSON buffer exceeded maximum size, truncating");
|
|
3043
2989
|
jsonBuffer = jsonBuffer.slice(-MAX_BUFFER_SIZE / 2);
|
|
3044
2990
|
}
|
|
3045
2991
|
jsonBuffer += delta;
|
|
3046
2992
|
for (const char of delta) {
|
|
3047
2993
|
if (componentBuffer.length > MAX_BUFFER_SIZE) {
|
|
3048
|
-
|
|
2994
|
+
logger7.warn("Component buffer exceeded maximum size, resetting");
|
|
3049
2995
|
componentBuffer = "";
|
|
3050
2996
|
depth = 0;
|
|
3051
2997
|
continue;
|
|
@@ -3060,7 +3006,7 @@ var IncrementalStreamParser = class {
|
|
|
3060
3006
|
if (componentMatch) {
|
|
3061
3007
|
const MAX_COMPONENT_SIZE = 1024 * 1024;
|
|
3062
3008
|
if (componentMatch[0].length > MAX_COMPONENT_SIZE) {
|
|
3063
|
-
|
|
3009
|
+
logger7.warn(
|
|
3064
3010
|
{
|
|
3065
3011
|
size: componentMatch[0].length,
|
|
3066
3012
|
maxSize: MAX_COMPONENT_SIZE
|
|
@@ -3073,7 +3019,7 @@ var IncrementalStreamParser = class {
|
|
|
3073
3019
|
try {
|
|
3074
3020
|
const component = JSON.parse(componentMatch[0]);
|
|
3075
3021
|
if (typeof component !== "object" || !component.id) {
|
|
3076
|
-
|
|
3022
|
+
logger7.warn("Invalid component structure, skipping");
|
|
3077
3023
|
componentBuffer = "";
|
|
3078
3024
|
continue;
|
|
3079
3025
|
}
|
|
@@ -3086,7 +3032,7 @@ var IncrementalStreamParser = class {
|
|
|
3086
3032
|
componentsStreamed++;
|
|
3087
3033
|
componentBuffer = "";
|
|
3088
3034
|
} catch (e) {
|
|
3089
|
-
|
|
3035
|
+
logger7.debug({ error: e }, "Failed to parse component, continuing to accumulate");
|
|
3090
3036
|
}
|
|
3091
3037
|
}
|
|
3092
3038
|
}
|
|
@@ -3103,7 +3049,7 @@ var IncrementalStreamParser = class {
|
|
|
3103
3049
|
break;
|
|
3104
3050
|
}
|
|
3105
3051
|
}
|
|
3106
|
-
|
|
3052
|
+
logger7.debug({ componentsStreamed }, "Finished streaming components");
|
|
3107
3053
|
}
|
|
3108
3054
|
/**
|
|
3109
3055
|
* Legacy method for backward compatibility - defaults to text processing
|
|
@@ -3247,7 +3193,7 @@ var IncrementalStreamParser = class {
|
|
|
3247
3193
|
};
|
|
3248
3194
|
|
|
3249
3195
|
// src/utils/response-formatter.ts
|
|
3250
|
-
var
|
|
3196
|
+
var logger8 = agentsCore.getLogger("ResponseFormatter");
|
|
3251
3197
|
var ResponseFormatter = class {
|
|
3252
3198
|
constructor(tenantId) {
|
|
3253
3199
|
__publicField(this, "artifactParser");
|
|
@@ -3278,7 +3224,7 @@ var ResponseFormatter = class {
|
|
|
3278
3224
|
return { parts };
|
|
3279
3225
|
} catch (error) {
|
|
3280
3226
|
agentsCore.setSpanWithError(span, error);
|
|
3281
|
-
|
|
3227
|
+
logger8.error({ error, responseObject }, "Error formatting object response");
|
|
3282
3228
|
return {
|
|
3283
3229
|
parts: [{ kind: "data", data: responseObject }]
|
|
3284
3230
|
};
|
|
@@ -3329,7 +3275,7 @@ var ResponseFormatter = class {
|
|
|
3329
3275
|
return { parts };
|
|
3330
3276
|
} catch (error) {
|
|
3331
3277
|
agentsCore.setSpanWithError(span, error);
|
|
3332
|
-
|
|
3278
|
+
logger8.error({ error, responseText }, "Error formatting response");
|
|
3333
3279
|
return { text: responseText };
|
|
3334
3280
|
} finally {
|
|
3335
3281
|
span.end();
|
|
@@ -3374,7 +3320,7 @@ var ResponseFormatter = class {
|
|
|
3374
3320
|
}
|
|
3375
3321
|
}
|
|
3376
3322
|
};
|
|
3377
|
-
var
|
|
3323
|
+
var logger9 = agentsCore.getLogger("ToolSessionManager");
|
|
3378
3324
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
3379
3325
|
// 5 minutes
|
|
3380
3326
|
constructor() {
|
|
@@ -3403,7 +3349,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3403
3349
|
createdAt: Date.now()
|
|
3404
3350
|
};
|
|
3405
3351
|
this.sessions.set(sessionId, session);
|
|
3406
|
-
|
|
3352
|
+
logger9.debug({ sessionId, tenantId, contextId, taskId }, "Created tool session");
|
|
3407
3353
|
return sessionId;
|
|
3408
3354
|
}
|
|
3409
3355
|
/**
|
|
@@ -3412,7 +3358,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3412
3358
|
recordToolResult(sessionId, toolResult) {
|
|
3413
3359
|
const session = this.sessions.get(sessionId);
|
|
3414
3360
|
if (!session) {
|
|
3415
|
-
|
|
3361
|
+
logger9.warn(
|
|
3416
3362
|
{ sessionId, toolCallId: toolResult.toolCallId },
|
|
3417
3363
|
"Tool result recorded for unknown session"
|
|
3418
3364
|
);
|
|
@@ -3426,12 +3372,12 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3426
3372
|
getToolResult(sessionId, toolCallId) {
|
|
3427
3373
|
const session = this.sessions.get(sessionId);
|
|
3428
3374
|
if (!session) {
|
|
3429
|
-
|
|
3375
|
+
logger9.warn({ sessionId, toolCallId }, "Requested tool result for unknown session");
|
|
3430
3376
|
return void 0;
|
|
3431
3377
|
}
|
|
3432
3378
|
const result = session.toolResults.get(toolCallId);
|
|
3433
3379
|
if (!result) {
|
|
3434
|
-
|
|
3380
|
+
logger9.warn(
|
|
3435
3381
|
{
|
|
3436
3382
|
sessionId,
|
|
3437
3383
|
toolCallId,
|
|
@@ -3470,10 +3416,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3470
3416
|
}
|
|
3471
3417
|
for (const sessionId of expiredSessions) {
|
|
3472
3418
|
this.sessions.delete(sessionId);
|
|
3473
|
-
|
|
3419
|
+
logger9.debug({ sessionId }, "Cleaned up expired tool session");
|
|
3474
3420
|
}
|
|
3475
3421
|
if (expiredSessions.length > 0) {
|
|
3476
|
-
|
|
3422
|
+
logger9.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
3477
3423
|
}
|
|
3478
3424
|
}
|
|
3479
3425
|
};
|
|
@@ -3482,7 +3428,7 @@ var ToolSessionManager = _ToolSessionManager;
|
|
|
3482
3428
|
var toolSessionManager = ToolSessionManager.getInstance();
|
|
3483
3429
|
|
|
3484
3430
|
// src/agents/artifactTools.ts
|
|
3485
|
-
var
|
|
3431
|
+
var logger10 = agentsCore.getLogger("artifactTools");
|
|
3486
3432
|
function buildKeyNestingMap(data, prefix = "", map = /* @__PURE__ */ new Map()) {
|
|
3487
3433
|
if (typeof data === "object" && data !== null) {
|
|
3488
3434
|
if (Array.isArray(data)) {
|
|
@@ -3703,7 +3649,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3703
3649
|
execute: async ({ toolCallId, baseSelector, propSelectors, ...rest }, _context) => {
|
|
3704
3650
|
const artifactType = "artifactType" in rest ? rest.artifactType : void 0;
|
|
3705
3651
|
if (!sessionId) {
|
|
3706
|
-
|
|
3652
|
+
logger10.warn({ toolCallId }, "No session ID provided to save_tool_result");
|
|
3707
3653
|
return {
|
|
3708
3654
|
saved: false,
|
|
3709
3655
|
error: `[toolCallId: ${toolCallId}] No session context available`,
|
|
@@ -3713,7 +3659,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3713
3659
|
}
|
|
3714
3660
|
const toolResult = toolSessionManager.getToolResult(sessionId, toolCallId);
|
|
3715
3661
|
if (!toolResult) {
|
|
3716
|
-
|
|
3662
|
+
logger10.warn({ toolCallId, sessionId }, "Tool result not found in session");
|
|
3717
3663
|
return {
|
|
3718
3664
|
saved: false,
|
|
3719
3665
|
error: `[toolCallId: ${toolCallId}] Tool result not found`,
|
|
@@ -3726,7 +3672,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3726
3672
|
const baseData = jmespath__default.default.search(parsedResult, baseSelector);
|
|
3727
3673
|
if (!baseData || Array.isArray(baseData) && baseData.length === 0) {
|
|
3728
3674
|
const debugInfo = analyzeSelectorFailure(parsedResult, baseSelector);
|
|
3729
|
-
|
|
3675
|
+
logger10.warn(
|
|
3730
3676
|
{
|
|
3731
3677
|
baseSelector,
|
|
3732
3678
|
toolCallId,
|
|
@@ -3769,7 +3715,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3769
3715
|
const fallbackValue = item[propName];
|
|
3770
3716
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3771
3717
|
extractedItem[propName] = fallbackValue;
|
|
3772
|
-
|
|
3718
|
+
logger10.info(
|
|
3773
3719
|
{ propName, propSelector, context },
|
|
3774
3720
|
`PropSelector failed, used fallback direct property access`
|
|
3775
3721
|
);
|
|
@@ -3781,7 +3727,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3781
3727
|
const fallbackValue = item[propName];
|
|
3782
3728
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3783
3729
|
extractedItem[propName] = fallbackValue;
|
|
3784
|
-
|
|
3730
|
+
logger10.warn(
|
|
3785
3731
|
{ propName, propSelector, context, error: error.message },
|
|
3786
3732
|
`PropSelector syntax error, used fallback direct property access`
|
|
3787
3733
|
);
|
|
@@ -3894,7 +3840,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3894
3840
|
warnings
|
|
3895
3841
|
};
|
|
3896
3842
|
} catch (error) {
|
|
3897
|
-
|
|
3843
|
+
logger10.error({ error, toolCallId, sessionId }, "Error processing save_tool_result");
|
|
3898
3844
|
return {
|
|
3899
3845
|
saved: false,
|
|
3900
3846
|
error: `[toolCallId: ${toolCallId}] ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
@@ -3906,7 +3852,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3906
3852
|
}
|
|
3907
3853
|
|
|
3908
3854
|
// src/a2a/client.ts
|
|
3909
|
-
var
|
|
3855
|
+
var logger11 = agentsCore.getLogger("a2aClient");
|
|
3910
3856
|
var DEFAULT_BACKOFF = {
|
|
3911
3857
|
initialInterval: 500,
|
|
3912
3858
|
maxInterval: 6e4,
|
|
@@ -3974,7 +3920,7 @@ var A2AClient = class {
|
|
|
3974
3920
|
*/
|
|
3975
3921
|
async _fetchAndCacheAgentCard() {
|
|
3976
3922
|
const agentCardUrl = `${this.agentBaseUrl}/.well-known/agent.json`;
|
|
3977
|
-
getLogger("a2a").info({ agentCardUrl, agentBaseUrl: this.agentBaseUrl }, "agentCardUrl");
|
|
3923
|
+
agentsCore.getLogger("a2a").info({ agentCardUrl, agentBaseUrl: this.agentBaseUrl }, "agentCardUrl");
|
|
3978
3924
|
try {
|
|
3979
3925
|
const response = await fetch(agentCardUrl, {
|
|
3980
3926
|
headers: {
|
|
@@ -4112,7 +4058,7 @@ var A2AClient = class {
|
|
|
4112
4058
|
try {
|
|
4113
4059
|
const res = await fn();
|
|
4114
4060
|
if (attempt > 0) {
|
|
4115
|
-
|
|
4061
|
+
logger11.info(
|
|
4116
4062
|
{
|
|
4117
4063
|
attempts: attempt + 1,
|
|
4118
4064
|
elapsedTime: Date.now() - start
|
|
@@ -4127,7 +4073,7 @@ var A2AClient = class {
|
|
|
4127
4073
|
}
|
|
4128
4074
|
const elapsed = Date.now() - start;
|
|
4129
4075
|
if (elapsed > maxElapsedTime) {
|
|
4130
|
-
|
|
4076
|
+
logger11.warn(
|
|
4131
4077
|
{
|
|
4132
4078
|
attempts: attempt + 1,
|
|
4133
4079
|
elapsedTime: elapsed,
|
|
@@ -4148,7 +4094,7 @@ var A2AClient = class {
|
|
|
4148
4094
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
4149
4095
|
}
|
|
4150
4096
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
4151
|
-
|
|
4097
|
+
logger11.info(
|
|
4152
4098
|
{
|
|
4153
4099
|
attempt: attempt + 1,
|
|
4154
4100
|
delayMs,
|
|
@@ -4233,7 +4179,7 @@ var A2AClient = class {
|
|
|
4233
4179
|
}
|
|
4234
4180
|
const rpcResponse = await httpResponse.json();
|
|
4235
4181
|
if (rpcResponse.id !== requestId2) {
|
|
4236
|
-
|
|
4182
|
+
logger11.warn(
|
|
4237
4183
|
{
|
|
4238
4184
|
method,
|
|
4239
4185
|
expectedId: requestId2,
|
|
@@ -4432,7 +4378,7 @@ var A2AClient = class {
|
|
|
4432
4378
|
try {
|
|
4433
4379
|
while (true) {
|
|
4434
4380
|
const { done, value } = await reader.read();
|
|
4435
|
-
|
|
4381
|
+
logger11.info({ done, value }, "parseA2ASseStream");
|
|
4436
4382
|
if (done) {
|
|
4437
4383
|
if (eventDataBuffer.trim()) {
|
|
4438
4384
|
const result = this._processSseEventData(
|
|
@@ -4521,7 +4467,7 @@ var A2AClient = class {
|
|
|
4521
4467
|
// src/agents/relationTools.ts
|
|
4522
4468
|
init_conversations();
|
|
4523
4469
|
init_dbClient();
|
|
4524
|
-
var
|
|
4470
|
+
var logger12 = agentsCore.getLogger("relationships Tools");
|
|
4525
4471
|
var generateTransferToolDescription = (config2) => {
|
|
4526
4472
|
return `Hand off the conversation to agent ${config2.id}.
|
|
4527
4473
|
|
|
@@ -4559,7 +4505,7 @@ var createTransferToAgentTool = ({
|
|
|
4559
4505
|
"transfer.to_agent_id": transferConfig.id ?? "unknown"
|
|
4560
4506
|
});
|
|
4561
4507
|
}
|
|
4562
|
-
|
|
4508
|
+
logger12.info(
|
|
4563
4509
|
{
|
|
4564
4510
|
transferTo: transferConfig.id ?? "unknown",
|
|
4565
4511
|
fromAgent: callingAgentId
|
|
@@ -4707,7 +4653,7 @@ function createDelegateToAgentTool({
|
|
|
4707
4653
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
4708
4654
|
}
|
|
4709
4655
|
};
|
|
4710
|
-
|
|
4656
|
+
logger12.info({ messageToSend }, "messageToSend");
|
|
4711
4657
|
await agentsCore.createMessage(dbClient_default)({
|
|
4712
4658
|
id: nanoid.nanoid(),
|
|
4713
4659
|
tenantId,
|
|
@@ -4769,7 +4715,7 @@ function createDelegateToAgentTool({
|
|
|
4769
4715
|
}
|
|
4770
4716
|
|
|
4771
4717
|
// src/agents/SystemPromptBuilder.ts
|
|
4772
|
-
var
|
|
4718
|
+
var logger13 = agentsCore.getLogger("SystemPromptBuilder");
|
|
4773
4719
|
var SystemPromptBuilder = class {
|
|
4774
4720
|
constructor(version, versionConfig) {
|
|
4775
4721
|
this.version = version;
|
|
@@ -4785,9 +4731,9 @@ var SystemPromptBuilder = class {
|
|
|
4785
4731
|
this.templates.set(name, content);
|
|
4786
4732
|
}
|
|
4787
4733
|
this.loaded = true;
|
|
4788
|
-
|
|
4734
|
+
logger13.debug(`Loaded ${this.templates.size} templates for version ${this.version}`);
|
|
4789
4735
|
} catch (error) {
|
|
4790
|
-
|
|
4736
|
+
logger13.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
4791
4737
|
throw new Error(`Template loading failed: ${error}`);
|
|
4792
4738
|
}
|
|
4793
4739
|
}
|
|
@@ -5189,7 +5135,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
5189
5135
|
return false;
|
|
5190
5136
|
};
|
|
5191
5137
|
}
|
|
5192
|
-
var
|
|
5138
|
+
var logger14 = agentsCore.getLogger("Agent");
|
|
5193
5139
|
var CONSTANTS = {
|
|
5194
5140
|
MAX_GENERATION_STEPS: 12,
|
|
5195
5141
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -5442,14 +5388,14 @@ var Agent = class {
|
|
|
5442
5388
|
for (const toolSet of tools) {
|
|
5443
5389
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
5444
5390
|
if (!isValidTool(originalTool)) {
|
|
5445
|
-
|
|
5391
|
+
logger14.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
5446
5392
|
continue;
|
|
5447
5393
|
}
|
|
5448
5394
|
const sessionWrappedTool = ai.tool({
|
|
5449
5395
|
description: originalTool.description,
|
|
5450
5396
|
inputSchema: originalTool.inputSchema,
|
|
5451
5397
|
execute: async (args, { toolCallId }) => {
|
|
5452
|
-
|
|
5398
|
+
logger14.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
5453
5399
|
try {
|
|
5454
5400
|
const result = await originalTool.execute(args, { toolCallId });
|
|
5455
5401
|
toolSessionManager.recordToolResult(sessionId, {
|
|
@@ -5461,7 +5407,7 @@ var Agent = class {
|
|
|
5461
5407
|
});
|
|
5462
5408
|
return { result, toolCallId };
|
|
5463
5409
|
} catch (error) {
|
|
5464
|
-
|
|
5410
|
+
logger14.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
5465
5411
|
throw error;
|
|
5466
5412
|
}
|
|
5467
5413
|
}
|
|
@@ -5546,7 +5492,7 @@ var Agent = class {
|
|
|
5546
5492
|
selectedTools
|
|
5547
5493
|
};
|
|
5548
5494
|
}
|
|
5549
|
-
|
|
5495
|
+
logger14.info(
|
|
5550
5496
|
{
|
|
5551
5497
|
toolName: tool4.name,
|
|
5552
5498
|
credentialReferenceId,
|
|
@@ -5586,7 +5532,7 @@ var Agent = class {
|
|
|
5586
5532
|
async getResolvedContext(conversationId, requestContext) {
|
|
5587
5533
|
try {
|
|
5588
5534
|
if (!this.config.contextConfigId) {
|
|
5589
|
-
|
|
5535
|
+
logger14.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
5590
5536
|
return null;
|
|
5591
5537
|
}
|
|
5592
5538
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -5594,7 +5540,7 @@ var Agent = class {
|
|
|
5594
5540
|
id: this.config.contextConfigId
|
|
5595
5541
|
});
|
|
5596
5542
|
if (!contextConfig) {
|
|
5597
|
-
|
|
5543
|
+
logger14.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
5598
5544
|
return null;
|
|
5599
5545
|
}
|
|
5600
5546
|
if (!this.contextResolver) {
|
|
@@ -5611,7 +5557,7 @@ var Agent = class {
|
|
|
5611
5557
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5612
5558
|
$env: process.env
|
|
5613
5559
|
};
|
|
5614
|
-
|
|
5560
|
+
logger14.debug(
|
|
5615
5561
|
{
|
|
5616
5562
|
conversationId,
|
|
5617
5563
|
contextConfigId: contextConfig.id,
|
|
@@ -5625,7 +5571,7 @@ var Agent = class {
|
|
|
5625
5571
|
);
|
|
5626
5572
|
return contextWithBuiltins;
|
|
5627
5573
|
} catch (error) {
|
|
5628
|
-
|
|
5574
|
+
logger14.error(
|
|
5629
5575
|
{
|
|
5630
5576
|
conversationId,
|
|
5631
5577
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5649,7 +5595,7 @@ var Agent = class {
|
|
|
5649
5595
|
});
|
|
5650
5596
|
return graphDefinition?.graphPrompt || void 0;
|
|
5651
5597
|
} catch (error) {
|
|
5652
|
-
|
|
5598
|
+
logger14.warn(
|
|
5653
5599
|
{
|
|
5654
5600
|
graphId: this.config.graphId,
|
|
5655
5601
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5676,7 +5622,7 @@ var Agent = class {
|
|
|
5676
5622
|
}
|
|
5677
5623
|
return !!(graphDefinition.artifactComponents && Object.keys(graphDefinition.artifactComponents).length > 0);
|
|
5678
5624
|
} catch (error) {
|
|
5679
|
-
|
|
5625
|
+
logger14.warn(
|
|
5680
5626
|
{
|
|
5681
5627
|
graphId: this.config.graphId,
|
|
5682
5628
|
tenantId: this.config.tenantId,
|
|
@@ -5736,7 +5682,7 @@ Key requirements:
|
|
|
5736
5682
|
preserveUnresolved: false
|
|
5737
5683
|
});
|
|
5738
5684
|
} catch (error) {
|
|
5739
|
-
|
|
5685
|
+
logger14.error(
|
|
5740
5686
|
{
|
|
5741
5687
|
conversationId,
|
|
5742
5688
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5781,7 +5727,7 @@ Key requirements:
|
|
|
5781
5727
|
preserveUnresolved: false
|
|
5782
5728
|
});
|
|
5783
5729
|
} catch (error) {
|
|
5784
|
-
|
|
5730
|
+
logger14.error(
|
|
5785
5731
|
{
|
|
5786
5732
|
conversationId,
|
|
5787
5733
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5809,7 +5755,7 @@ Key requirements:
|
|
|
5809
5755
|
artifactId: z5.z.string().describe("The unique identifier of the artifact to get.")
|
|
5810
5756
|
}),
|
|
5811
5757
|
execute: async ({ artifactId }) => {
|
|
5812
|
-
|
|
5758
|
+
logger14.info({ artifactId }, "get_artifact executed");
|
|
5813
5759
|
const artifact = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
5814
5760
|
scopes: {
|
|
5815
5761
|
tenantId: this.config.tenantId,
|
|
@@ -5876,7 +5822,7 @@ Key requirements:
|
|
|
5876
5822
|
graphId: this.config.graphId
|
|
5877
5823
|
});
|
|
5878
5824
|
} catch (error) {
|
|
5879
|
-
|
|
5825
|
+
logger14.error(
|
|
5880
5826
|
{ error, graphId: this.config.graphId },
|
|
5881
5827
|
"Failed to check graph artifact components"
|
|
5882
5828
|
);
|
|
@@ -5980,7 +5926,7 @@ Key requirements:
|
|
|
5980
5926
|
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;
|
|
5981
5927
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
5982
5928
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
5983
|
-
|
|
5929
|
+
logger14.warn(
|
|
5984
5930
|
{
|
|
5985
5931
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
5986
5932
|
appliedTimeout: timeoutMs,
|
|
@@ -6022,7 +5968,7 @@ Key requirements:
|
|
|
6022
5968
|
}
|
|
6023
5969
|
);
|
|
6024
5970
|
} catch (error) {
|
|
6025
|
-
|
|
5971
|
+
logger14.debug("Failed to track agent reasoning");
|
|
6026
5972
|
}
|
|
6027
5973
|
}
|
|
6028
5974
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -6105,7 +6051,7 @@ Key requirements:
|
|
|
6105
6051
|
}
|
|
6106
6052
|
);
|
|
6107
6053
|
} catch (error) {
|
|
6108
|
-
|
|
6054
|
+
logger14.debug("Failed to track agent reasoning");
|
|
6109
6055
|
}
|
|
6110
6056
|
}
|
|
6111
6057
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -6150,7 +6096,7 @@ Key requirements:
|
|
|
6150
6096
|
return;
|
|
6151
6097
|
}
|
|
6152
6098
|
if (toolName === "save_artifact_tool" || toolName === "save_tool_result") {
|
|
6153
|
-
|
|
6099
|
+
logger14.info({ result }, "save_artifact_tool or save_tool_result");
|
|
6154
6100
|
if (result.output.artifacts) {
|
|
6155
6101
|
for (const artifact of result.output.artifacts) {
|
|
6156
6102
|
const artifactId = artifact?.artifactId || "N/A";
|
|
@@ -6338,7 +6284,7 @@ function parseEmbeddedJson(data) {
|
|
|
6338
6284
|
}
|
|
6339
6285
|
});
|
|
6340
6286
|
}
|
|
6341
|
-
var
|
|
6287
|
+
var logger15 = agentsCore.getLogger("generateTaskHandler");
|
|
6342
6288
|
var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
6343
6289
|
return async (task) => {
|
|
6344
6290
|
try {
|
|
@@ -6388,7 +6334,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6388
6334
|
agentId: config2.agentId
|
|
6389
6335
|
})
|
|
6390
6336
|
]);
|
|
6391
|
-
|
|
6337
|
+
logger15.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
6392
6338
|
const agentPrompt = "prompt" in config2.agentSchema ? config2.agentSchema.prompt : "";
|
|
6393
6339
|
const models = "models" in config2.agentSchema ? config2.agentSchema.models : void 0;
|
|
6394
6340
|
const stopWhen = "stopWhen" in config2.agentSchema ? config2.agentSchema.stopWhen : void 0;
|
|
@@ -6488,7 +6434,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6488
6434
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
6489
6435
|
if (taskIdMatch) {
|
|
6490
6436
|
contextId = taskIdMatch[1];
|
|
6491
|
-
|
|
6437
|
+
logger15.info(
|
|
6492
6438
|
{
|
|
6493
6439
|
taskId: task.id,
|
|
6494
6440
|
extractedContextId: contextId,
|
|
@@ -6504,7 +6450,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6504
6450
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
6505
6451
|
agent.setDelegationStatus(isDelegation);
|
|
6506
6452
|
if (isDelegation) {
|
|
6507
|
-
|
|
6453
|
+
logger15.info(
|
|
6508
6454
|
{ agentId: config2.agentId, taskId: task.id },
|
|
6509
6455
|
"Delegated agent - streaming disabled"
|
|
6510
6456
|
);
|
|
@@ -6787,7 +6733,7 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
|
6787
6733
|
// src/routes/agents.ts
|
|
6788
6734
|
init_dbClient();
|
|
6789
6735
|
var app = new zodOpenapi.OpenAPIHono();
|
|
6790
|
-
var
|
|
6736
|
+
var logger16 = agentsCore.getLogger("agents");
|
|
6791
6737
|
app.openapi(
|
|
6792
6738
|
zodOpenapi.createRoute({
|
|
6793
6739
|
method: "get",
|
|
@@ -6825,7 +6771,7 @@ app.openapi(
|
|
|
6825
6771
|
tracestate: c.req.header("tracestate"),
|
|
6826
6772
|
baggage: c.req.header("baggage")
|
|
6827
6773
|
};
|
|
6828
|
-
|
|
6774
|
+
logger16.info(
|
|
6829
6775
|
{
|
|
6830
6776
|
otelHeaders,
|
|
6831
6777
|
path: c.req.path,
|
|
@@ -6836,7 +6782,7 @@ app.openapi(
|
|
|
6836
6782
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
6837
6783
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6838
6784
|
if (agentId) {
|
|
6839
|
-
|
|
6785
|
+
logger16.info(
|
|
6840
6786
|
{
|
|
6841
6787
|
message: "getRegisteredAgent (agent-level)",
|
|
6842
6788
|
tenantId,
|
|
@@ -6848,13 +6794,13 @@ app.openapi(
|
|
|
6848
6794
|
);
|
|
6849
6795
|
const credentialStores = c.get("credentialStores");
|
|
6850
6796
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
6851
|
-
|
|
6797
|
+
logger16.info({ agent }, "agent registered: well-known agent.json");
|
|
6852
6798
|
if (!agent) {
|
|
6853
6799
|
return c.json({ error: "Agent not found" }, 404);
|
|
6854
6800
|
}
|
|
6855
6801
|
return c.json(agent.agentCard);
|
|
6856
6802
|
} else {
|
|
6857
|
-
|
|
6803
|
+
logger16.info(
|
|
6858
6804
|
{
|
|
6859
6805
|
message: "getRegisteredGraph (graph-level)",
|
|
6860
6806
|
tenantId,
|
|
@@ -6877,7 +6823,7 @@ app.post("/a2a", async (c) => {
|
|
|
6877
6823
|
tracestate: c.req.header("tracestate"),
|
|
6878
6824
|
baggage: c.req.header("baggage")
|
|
6879
6825
|
};
|
|
6880
|
-
|
|
6826
|
+
logger16.info(
|
|
6881
6827
|
{
|
|
6882
6828
|
otelHeaders,
|
|
6883
6829
|
path: c.req.path,
|
|
@@ -6888,7 +6834,7 @@ app.post("/a2a", async (c) => {
|
|
|
6888
6834
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
6889
6835
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6890
6836
|
if (agentId) {
|
|
6891
|
-
|
|
6837
|
+
logger16.info(
|
|
6892
6838
|
{
|
|
6893
6839
|
message: "a2a (agent-level)",
|
|
6894
6840
|
tenantId,
|
|
@@ -6912,7 +6858,7 @@ app.post("/a2a", async (c) => {
|
|
|
6912
6858
|
}
|
|
6913
6859
|
return a2aHandler(c, agent);
|
|
6914
6860
|
} else {
|
|
6915
|
-
|
|
6861
|
+
logger16.info(
|
|
6916
6862
|
{
|
|
6917
6863
|
message: "a2a (graph-level)",
|
|
6918
6864
|
tenantId,
|
|
@@ -6958,14 +6904,14 @@ init_dbClient();
|
|
|
6958
6904
|
|
|
6959
6905
|
// src/a2a/transfer.ts
|
|
6960
6906
|
init_dbClient();
|
|
6961
|
-
var
|
|
6907
|
+
var logger17 = agentsCore.getLogger("Transfer");
|
|
6962
6908
|
async function executeTransfer({
|
|
6963
6909
|
tenantId,
|
|
6964
6910
|
threadId,
|
|
6965
6911
|
projectId,
|
|
6966
6912
|
targetAgentId
|
|
6967
6913
|
}) {
|
|
6968
|
-
|
|
6914
|
+
logger17.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
6969
6915
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
6970
6916
|
scopes: { tenantId, projectId },
|
|
6971
6917
|
threadId,
|
|
@@ -7509,7 +7455,7 @@ function createMCPStreamHelper() {
|
|
|
7509
7455
|
|
|
7510
7456
|
// src/handlers/executionHandler.ts
|
|
7511
7457
|
init_dbClient();
|
|
7512
|
-
var
|
|
7458
|
+
var logger18 = agentsCore.getLogger("ExecutionHandler");
|
|
7513
7459
|
var ExecutionHandler = class {
|
|
7514
7460
|
constructor() {
|
|
7515
7461
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -7534,7 +7480,7 @@ var ExecutionHandler = class {
|
|
|
7534
7480
|
const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
|
|
7535
7481
|
registerStreamHelper(requestId2, sseHelper);
|
|
7536
7482
|
graphSessionManager.createSession(requestId2, graphId, tenantId, projectId);
|
|
7537
|
-
|
|
7483
|
+
logger18.info({ sessionId: requestId2, graphId }, "Created GraphSession for message execution");
|
|
7538
7484
|
let graphConfig = null;
|
|
7539
7485
|
try {
|
|
7540
7486
|
graphConfig = await agentsCore.getFullGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
|
|
@@ -7546,7 +7492,7 @@ var ExecutionHandler = class {
|
|
|
7546
7492
|
);
|
|
7547
7493
|
}
|
|
7548
7494
|
} catch (error) {
|
|
7549
|
-
|
|
7495
|
+
logger18.error(
|
|
7550
7496
|
{
|
|
7551
7497
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
7552
7498
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -7562,7 +7508,7 @@ var ExecutionHandler = class {
|
|
|
7562
7508
|
try {
|
|
7563
7509
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
7564
7510
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
7565
|
-
|
|
7511
|
+
logger18.info(
|
|
7566
7512
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
7567
7513
|
"Attempting to create or reuse existing task"
|
|
7568
7514
|
);
|
|
@@ -7585,7 +7531,7 @@ var ExecutionHandler = class {
|
|
|
7585
7531
|
agent_id: currentAgentId
|
|
7586
7532
|
}
|
|
7587
7533
|
});
|
|
7588
|
-
|
|
7534
|
+
logger18.info(
|
|
7589
7535
|
{
|
|
7590
7536
|
taskId,
|
|
7591
7537
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -7594,27 +7540,27 @@ var ExecutionHandler = class {
|
|
|
7594
7540
|
);
|
|
7595
7541
|
} catch (error) {
|
|
7596
7542
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
7597
|
-
|
|
7543
|
+
logger18.info(
|
|
7598
7544
|
{ taskId, error: error.message },
|
|
7599
7545
|
"Task already exists, fetching existing task"
|
|
7600
7546
|
);
|
|
7601
7547
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
7602
7548
|
if (existingTask) {
|
|
7603
7549
|
task = existingTask;
|
|
7604
|
-
|
|
7550
|
+
logger18.info(
|
|
7605
7551
|
{ taskId, existingTask },
|
|
7606
7552
|
"Successfully reused existing task from race condition"
|
|
7607
7553
|
);
|
|
7608
7554
|
} else {
|
|
7609
|
-
|
|
7555
|
+
logger18.error({ taskId, error }, "Task constraint failed but task not found");
|
|
7610
7556
|
throw error;
|
|
7611
7557
|
}
|
|
7612
7558
|
} else {
|
|
7613
|
-
|
|
7559
|
+
logger18.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
7614
7560
|
throw error;
|
|
7615
7561
|
}
|
|
7616
7562
|
}
|
|
7617
|
-
|
|
7563
|
+
logger18.debug(
|
|
7618
7564
|
{
|
|
7619
7565
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7620
7566
|
executionType: "create_initial_task",
|
|
@@ -7632,7 +7578,7 @@ var ExecutionHandler = class {
|
|
|
7632
7578
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
7633
7579
|
while (iterations < maxTransfers) {
|
|
7634
7580
|
iterations++;
|
|
7635
|
-
|
|
7581
|
+
logger18.info(
|
|
7636
7582
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
7637
7583
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
7638
7584
|
);
|
|
@@ -7640,10 +7586,10 @@ var ExecutionHandler = class {
|
|
|
7640
7586
|
scopes: { tenantId, projectId },
|
|
7641
7587
|
conversationId
|
|
7642
7588
|
});
|
|
7643
|
-
|
|
7589
|
+
logger18.info({ activeAgent }, "activeAgent");
|
|
7644
7590
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
7645
7591
|
currentAgentId = activeAgent.activeAgentId;
|
|
7646
|
-
|
|
7592
|
+
logger18.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
7647
7593
|
}
|
|
7648
7594
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
7649
7595
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -7684,13 +7630,13 @@ var ExecutionHandler = class {
|
|
|
7684
7630
|
});
|
|
7685
7631
|
if (!messageResponse?.result) {
|
|
7686
7632
|
errorCount++;
|
|
7687
|
-
|
|
7633
|
+
logger18.error(
|
|
7688
7634
|
{ currentAgentId, iterations, errorCount },
|
|
7689
7635
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7690
7636
|
);
|
|
7691
7637
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7692
7638
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7693
|
-
|
|
7639
|
+
logger18.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7694
7640
|
await sseHelper.writeError(errorMessage2);
|
|
7695
7641
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7696
7642
|
if (task) {
|
|
@@ -7716,7 +7662,7 @@ var ExecutionHandler = class {
|
|
|
7716
7662
|
const transferResponse = messageResponse.result;
|
|
7717
7663
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
7718
7664
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
7719
|
-
|
|
7665
|
+
logger18.info({ targetAgentId, transferReason }, "transfer response");
|
|
7720
7666
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
7721
7667
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
7722
7668
|
projectId,
|
|
@@ -7727,7 +7673,7 @@ var ExecutionHandler = class {
|
|
|
7727
7673
|
if (success) {
|
|
7728
7674
|
fromAgentId = currentAgentId;
|
|
7729
7675
|
currentAgentId = newAgentId;
|
|
7730
|
-
|
|
7676
|
+
logger18.info(
|
|
7731
7677
|
{
|
|
7732
7678
|
transferFrom: fromAgentId,
|
|
7733
7679
|
transferTo: currentAgentId,
|
|
@@ -7745,7 +7691,7 @@ var ExecutionHandler = class {
|
|
|
7745
7691
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
7746
7692
|
if (graphSessionData) {
|
|
7747
7693
|
const sessionSummary = graphSessionData.getSummary();
|
|
7748
|
-
|
|
7694
|
+
logger18.info(sessionSummary, "GraphSession data after completion");
|
|
7749
7695
|
}
|
|
7750
7696
|
let textContent = "";
|
|
7751
7697
|
for (const part of responseParts) {
|
|
@@ -7800,32 +7746,32 @@ var ExecutionHandler = class {
|
|
|
7800
7746
|
}
|
|
7801
7747
|
});
|
|
7802
7748
|
const updateTaskEnd = Date.now();
|
|
7803
|
-
|
|
7749
|
+
logger18.info(
|
|
7804
7750
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
7805
7751
|
"Completed updateTask operation"
|
|
7806
7752
|
);
|
|
7807
7753
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
7808
7754
|
await sseHelper.complete();
|
|
7809
|
-
|
|
7755
|
+
logger18.info({}, "Ending GraphSession and cleaning up");
|
|
7810
7756
|
graphSessionManager.endSession(requestId2);
|
|
7811
|
-
|
|
7757
|
+
logger18.info({}, "Cleaning up streamHelper");
|
|
7812
7758
|
unregisterStreamHelper(requestId2);
|
|
7813
7759
|
let response;
|
|
7814
7760
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
7815
7761
|
const captured = sseHelper.getCapturedResponse();
|
|
7816
7762
|
response = captured.text || "No response content";
|
|
7817
7763
|
}
|
|
7818
|
-
|
|
7764
|
+
logger18.info({}, "ExecutionHandler returning success");
|
|
7819
7765
|
return { success: true, iterations, response };
|
|
7820
7766
|
}
|
|
7821
7767
|
errorCount++;
|
|
7822
|
-
|
|
7768
|
+
logger18.warn(
|
|
7823
7769
|
{ iterations, errorCount },
|
|
7824
7770
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7825
7771
|
);
|
|
7826
7772
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7827
7773
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7828
|
-
|
|
7774
|
+
logger18.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7829
7775
|
await sseHelper.writeError(errorMessage2);
|
|
7830
7776
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7831
7777
|
if (task) {
|
|
@@ -7847,7 +7793,7 @@ var ExecutionHandler = class {
|
|
|
7847
7793
|
}
|
|
7848
7794
|
}
|
|
7849
7795
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
7850
|
-
|
|
7796
|
+
logger18.error({ maxTransfers, iterations }, errorMessage);
|
|
7851
7797
|
await sseHelper.writeError(errorMessage);
|
|
7852
7798
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
7853
7799
|
if (task) {
|
|
@@ -7867,7 +7813,7 @@ var ExecutionHandler = class {
|
|
|
7867
7813
|
unregisterStreamHelper(requestId2);
|
|
7868
7814
|
return { success: false, error: errorMessage, iterations };
|
|
7869
7815
|
} catch (error) {
|
|
7870
|
-
|
|
7816
|
+
logger18.error({ error }, "Error in execution handler");
|
|
7871
7817
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
7872
7818
|
await sseHelper.writeError(`Execution error: ${errorMessage}`);
|
|
7873
7819
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
@@ -7893,7 +7839,7 @@ var ExecutionHandler = class {
|
|
|
7893
7839
|
|
|
7894
7840
|
// src/routes/chat.ts
|
|
7895
7841
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
7896
|
-
var
|
|
7842
|
+
var logger19 = agentsCore.getLogger("completionsHandler");
|
|
7897
7843
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
7898
7844
|
method: "post",
|
|
7899
7845
|
path: "/completions",
|
|
@@ -7998,7 +7944,7 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
7998
7944
|
});
|
|
7999
7945
|
app2.use("/completions", agentsCore.contextValidationMiddleware(dbClient_default));
|
|
8000
7946
|
app2.openapi(chatCompletionsRoute, async (c) => {
|
|
8001
|
-
getLogger("chat").info(
|
|
7947
|
+
agentsCore.getLogger("chat").info(
|
|
8002
7948
|
{
|
|
8003
7949
|
path: c.req.path,
|
|
8004
7950
|
method: c.req.method,
|
|
@@ -8011,7 +7957,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8011
7957
|
tracestate: c.req.header("tracestate"),
|
|
8012
7958
|
baggage: c.req.header("baggage")
|
|
8013
7959
|
};
|
|
8014
|
-
|
|
7960
|
+
logger19.info(
|
|
8015
7961
|
{
|
|
8016
7962
|
otelHeaders,
|
|
8017
7963
|
path: c.req.path,
|
|
@@ -8022,14 +7968,14 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8022
7968
|
try {
|
|
8023
7969
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
8024
7970
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8025
|
-
getLogger("chat").debug(
|
|
7971
|
+
agentsCore.getLogger("chat").debug(
|
|
8026
7972
|
{
|
|
8027
7973
|
tenantId,
|
|
8028
7974
|
graphId
|
|
8029
7975
|
},
|
|
8030
7976
|
"Extracted chat parameters from API key context"
|
|
8031
7977
|
);
|
|
8032
|
-
const body = c.
|
|
7978
|
+
const body = c.get("requestBody") || {};
|
|
8033
7979
|
const conversationId = body.conversationId || nanoid.nanoid();
|
|
8034
7980
|
const fullGraph = await agentsCore.getFullGraph(dbClient_default)({
|
|
8035
7981
|
scopes: { tenantId, projectId },
|
|
@@ -8097,7 +8043,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8097
8043
|
dbClient_default,
|
|
8098
8044
|
credentialStores
|
|
8099
8045
|
);
|
|
8100
|
-
|
|
8046
|
+
logger19.info(
|
|
8101
8047
|
{
|
|
8102
8048
|
tenantId,
|
|
8103
8049
|
graphId,
|
|
@@ -8143,7 +8089,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8143
8089
|
return streaming.streamSSE(c, async (stream2) => {
|
|
8144
8090
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
8145
8091
|
await sseHelper.writeRole();
|
|
8146
|
-
|
|
8092
|
+
logger19.info({ agentId }, "Starting execution");
|
|
8147
8093
|
const executionHandler = new ExecutionHandler();
|
|
8148
8094
|
const result = await executionHandler.execute({
|
|
8149
8095
|
executionContext,
|
|
@@ -8153,7 +8099,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8153
8099
|
requestId: requestId2,
|
|
8154
8100
|
sseHelper
|
|
8155
8101
|
});
|
|
8156
|
-
|
|
8102
|
+
logger19.info(
|
|
8157
8103
|
{ result },
|
|
8158
8104
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8159
8105
|
);
|
|
@@ -8189,7 +8135,7 @@ var chat_default = app2;
|
|
|
8189
8135
|
// src/routes/chatDataStream.ts
|
|
8190
8136
|
init_dbClient();
|
|
8191
8137
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
8192
|
-
var
|
|
8138
|
+
var logger20 = agentsCore.getLogger("chatDataStream");
|
|
8193
8139
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
8194
8140
|
method: "post",
|
|
8195
8141
|
path: "/chat",
|
|
@@ -8242,7 +8188,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8242
8188
|
try {
|
|
8243
8189
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
8244
8190
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8245
|
-
const body =
|
|
8191
|
+
const body = c.get("requestBody") || {};
|
|
8246
8192
|
const conversationId = body.conversationId || nanoid.nanoid();
|
|
8247
8193
|
const activeSpan = api.trace.getActiveSpan();
|
|
8248
8194
|
if (activeSpan) {
|
|
@@ -8294,7 +8240,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8294
8240
|
);
|
|
8295
8241
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
8296
8242
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
8297
|
-
|
|
8243
|
+
logger20.info({ userText, lastUserMessage }, "userText");
|
|
8298
8244
|
const messageSpan = api.trace.getActiveSpan();
|
|
8299
8245
|
if (messageSpan) {
|
|
8300
8246
|
messageSpan.setAttributes({
|
|
@@ -8336,7 +8282,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8336
8282
|
await streamHelper.writeError("Unable to process request");
|
|
8337
8283
|
}
|
|
8338
8284
|
} catch (err) {
|
|
8339
|
-
|
|
8285
|
+
logger20.error({ err }, "Streaming error");
|
|
8340
8286
|
await streamHelper.writeError("Internal server error");
|
|
8341
8287
|
} finally {
|
|
8342
8288
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -8357,7 +8303,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8357
8303
|
)
|
|
8358
8304
|
);
|
|
8359
8305
|
} catch (error) {
|
|
8360
|
-
|
|
8306
|
+
logger20.error({ error }, "chatDataStream error");
|
|
8361
8307
|
return c.json({ error: "Failed to process chat completion" }, 500);
|
|
8362
8308
|
}
|
|
8363
8309
|
});
|
|
@@ -8368,7 +8314,7 @@ init_dbClient();
|
|
|
8368
8314
|
function createMCPSchema(schema) {
|
|
8369
8315
|
return schema;
|
|
8370
8316
|
}
|
|
8371
|
-
var
|
|
8317
|
+
var logger21 = agentsCore.getLogger("mcp");
|
|
8372
8318
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
8373
8319
|
constructor() {
|
|
8374
8320
|
__publicField(this, "mockRes");
|
|
@@ -8423,21 +8369,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
8423
8369
|
id: 0
|
|
8424
8370
|
});
|
|
8425
8371
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
8426
|
-
|
|
8372
|
+
logger21.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
8427
8373
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
8428
8374
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
8429
8375
|
try {
|
|
8430
8376
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
8431
|
-
|
|
8377
|
+
logger21.info({ sessionId }, "Successfully spoofed initialization");
|
|
8432
8378
|
} catch (spoofError) {
|
|
8433
|
-
|
|
8379
|
+
logger21.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
8434
8380
|
}
|
|
8435
8381
|
};
|
|
8436
8382
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
8437
8383
|
const sessionId = req.headers["mcp-session-id"];
|
|
8438
|
-
|
|
8384
|
+
logger21.info({ sessionId }, "Received MCP session ID");
|
|
8439
8385
|
if (!sessionId) {
|
|
8440
|
-
|
|
8386
|
+
logger21.info({ body }, "Missing session ID");
|
|
8441
8387
|
res.writeHead(400).end(
|
|
8442
8388
|
JSON.stringify({
|
|
8443
8389
|
jsonrpc: "2.0",
|
|
@@ -8463,7 +8409,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8463
8409
|
scopes: { tenantId, projectId },
|
|
8464
8410
|
conversationId: sessionId
|
|
8465
8411
|
});
|
|
8466
|
-
|
|
8412
|
+
logger21.info(
|
|
8467
8413
|
{
|
|
8468
8414
|
sessionId,
|
|
8469
8415
|
conversationFound: !!conversation,
|
|
@@ -8474,7 +8420,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8474
8420
|
"Conversation lookup result"
|
|
8475
8421
|
);
|
|
8476
8422
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
8477
|
-
|
|
8423
|
+
logger21.info(
|
|
8478
8424
|
{ sessionId, conversationId: conversation?.id },
|
|
8479
8425
|
"MCP session not found or invalid"
|
|
8480
8426
|
);
|
|
@@ -8535,7 +8481,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
8535
8481
|
requestId: requestId2,
|
|
8536
8482
|
sseHelper: mcpStreamHelper
|
|
8537
8483
|
});
|
|
8538
|
-
|
|
8484
|
+
logger21.info(
|
|
8539
8485
|
{ result },
|
|
8540
8486
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8541
8487
|
);
|
|
@@ -8609,7 +8555,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
8609
8555
|
dbClient_default,
|
|
8610
8556
|
credentialStores
|
|
8611
8557
|
);
|
|
8612
|
-
|
|
8558
|
+
logger21.info(
|
|
8613
8559
|
{
|
|
8614
8560
|
tenantId,
|
|
8615
8561
|
graphId,
|
|
@@ -8648,10 +8594,10 @@ var validateRequestParameters = (c) => {
|
|
|
8648
8594
|
try {
|
|
8649
8595
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
8650
8596
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8651
|
-
getLogger("mcp").debug({ tenantId, projectId, graphId }, "Extracted MCP entity parameters");
|
|
8597
|
+
agentsCore.getLogger("mcp").debug({ tenantId, projectId, graphId }, "Extracted MCP entity parameters");
|
|
8652
8598
|
return { valid: true, executionContext };
|
|
8653
8599
|
} catch (error) {
|
|
8654
|
-
getLogger("chat").warn(
|
|
8600
|
+
agentsCore.getLogger("chat").warn(
|
|
8655
8601
|
{ error: error instanceof Error ? error.message : "Unknown error" },
|
|
8656
8602
|
"Failed to get execution context"
|
|
8657
8603
|
);
|
|
@@ -8670,7 +8616,7 @@ var validateRequestParameters = (c) => {
|
|
|
8670
8616
|
};
|
|
8671
8617
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
8672
8618
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8673
|
-
|
|
8619
|
+
logger21.info({ body }, "Received initialization request");
|
|
8674
8620
|
const sessionId = nanoid.nanoid();
|
|
8675
8621
|
const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
8676
8622
|
scopes: { tenantId, projectId },
|
|
@@ -8701,7 +8647,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8701
8647
|
}
|
|
8702
8648
|
}
|
|
8703
8649
|
});
|
|
8704
|
-
|
|
8650
|
+
logger21.info(
|
|
8705
8651
|
{ sessionId, conversationId: conversation.id },
|
|
8706
8652
|
"Created MCP session as conversation"
|
|
8707
8653
|
);
|
|
@@ -8710,9 +8656,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8710
8656
|
});
|
|
8711
8657
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
8712
8658
|
await server.connect(transport);
|
|
8713
|
-
|
|
8659
|
+
logger21.info({ sessionId }, "Server connected for initialization");
|
|
8714
8660
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
8715
|
-
|
|
8661
|
+
logger21.info(
|
|
8716
8662
|
{
|
|
8717
8663
|
sessionId,
|
|
8718
8664
|
bodyMethod: body?.method,
|
|
@@ -8721,7 +8667,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8721
8667
|
"About to handle initialization request"
|
|
8722
8668
|
);
|
|
8723
8669
|
await transport.handleRequest(req, res, body);
|
|
8724
|
-
|
|
8670
|
+
logger21.info({ sessionId }, "Successfully handled initialization request");
|
|
8725
8671
|
return fetchToNode.toFetchResponse(res);
|
|
8726
8672
|
};
|
|
8727
8673
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -8749,8 +8695,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8749
8695
|
sessionId,
|
|
8750
8696
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
8751
8697
|
);
|
|
8752
|
-
|
|
8753
|
-
|
|
8698
|
+
logger21.info({ sessionId }, "Server connected and transport initialized");
|
|
8699
|
+
logger21.info(
|
|
8754
8700
|
{
|
|
8755
8701
|
sessionId,
|
|
8756
8702
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -8764,9 +8710,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8764
8710
|
);
|
|
8765
8711
|
try {
|
|
8766
8712
|
await transport.handleRequest(req, res, body);
|
|
8767
|
-
|
|
8713
|
+
logger21.info({ sessionId }, "Successfully handled MCP request");
|
|
8768
8714
|
} catch (transportError) {
|
|
8769
|
-
|
|
8715
|
+
logger21.error(
|
|
8770
8716
|
{
|
|
8771
8717
|
sessionId,
|
|
8772
8718
|
error: transportError,
|
|
@@ -8816,14 +8762,14 @@ app4.openapi(
|
|
|
8816
8762
|
return paramValidation.response;
|
|
8817
8763
|
}
|
|
8818
8764
|
const { executionContext } = paramValidation;
|
|
8819
|
-
const body =
|
|
8820
|
-
|
|
8765
|
+
const body = c.get("requestBody") || {};
|
|
8766
|
+
logger21.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
8821
8767
|
const isInitRequest = body.method === "initialize";
|
|
8822
8768
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
8823
8769
|
const validatedContext = c.get("validatedContext") || {};
|
|
8824
8770
|
const credentialStores = c.get("credentialStores");
|
|
8825
|
-
|
|
8826
|
-
|
|
8771
|
+
logger21.info({ validatedContext }, "Validated context");
|
|
8772
|
+
logger21.info({ req }, "request");
|
|
8827
8773
|
if (isInitRequest) {
|
|
8828
8774
|
return await handleInitializationRequest(
|
|
8829
8775
|
body,
|
|
@@ -8845,7 +8791,7 @@ app4.openapi(
|
|
|
8845
8791
|
);
|
|
8846
8792
|
}
|
|
8847
8793
|
} catch (e) {
|
|
8848
|
-
|
|
8794
|
+
logger21.error(
|
|
8849
8795
|
{
|
|
8850
8796
|
error: e instanceof Error ? e.message : e,
|
|
8851
8797
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -8857,7 +8803,7 @@ app4.openapi(
|
|
|
8857
8803
|
}
|
|
8858
8804
|
);
|
|
8859
8805
|
app4.get("/", async (c) => {
|
|
8860
|
-
|
|
8806
|
+
logger21.info({}, "Received GET MCP request");
|
|
8861
8807
|
return c.json(
|
|
8862
8808
|
{
|
|
8863
8809
|
jsonrpc: "2.0",
|
|
@@ -8871,7 +8817,7 @@ app4.get("/", async (c) => {
|
|
|
8871
8817
|
);
|
|
8872
8818
|
});
|
|
8873
8819
|
app4.delete("/", async (c) => {
|
|
8874
|
-
|
|
8820
|
+
logger21.info({}, "Received DELETE MCP request");
|
|
8875
8821
|
return c.json(
|
|
8876
8822
|
{
|
|
8877
8823
|
jsonrpc: "2.0",
|
|
@@ -8884,6 +8830,7 @@ app4.delete("/", async (c) => {
|
|
|
8884
8830
|
var mcp_default = app4;
|
|
8885
8831
|
|
|
8886
8832
|
// src/app.ts
|
|
8833
|
+
var logger22 = agentsCore.getLogger("agents-run-api");
|
|
8887
8834
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
8888
8835
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
8889
8836
|
app6.use("*", requestId.requestId());
|
|
@@ -8892,6 +8839,17 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8892
8839
|
c.set("credentialStores", credentialStores);
|
|
8893
8840
|
return next();
|
|
8894
8841
|
});
|
|
8842
|
+
app6.use("*", async (c, next) => {
|
|
8843
|
+
if (c.req.header("content-type")?.includes("application/json")) {
|
|
8844
|
+
try {
|
|
8845
|
+
const body = await c.req.json();
|
|
8846
|
+
c.set("requestBody", body);
|
|
8847
|
+
} catch (error) {
|
|
8848
|
+
logger22.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
8849
|
+
}
|
|
8850
|
+
}
|
|
8851
|
+
return next();
|
|
8852
|
+
});
|
|
8895
8853
|
app6.use("*", async (c, next) => {
|
|
8896
8854
|
const reqId = c.get("requestId");
|
|
8897
8855
|
let bag = api.propagation.getBaggage(api.context.active());
|
|
@@ -8901,23 +8859,10 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8901
8859
|
if (bag && typeof bag.setEntry === "function") {
|
|
8902
8860
|
bag = bag.setEntry("request.id", { value: String(reqId ?? "unknown") });
|
|
8903
8861
|
const ctxWithBag = api.propagation.setBaggage(api.context.active(), bag);
|
|
8904
|
-
return api.context.with(ctxWithBag, () => next());
|
|
8862
|
+
return await api.context.with(ctxWithBag, async () => await next());
|
|
8905
8863
|
}
|
|
8906
8864
|
return next();
|
|
8907
8865
|
});
|
|
8908
|
-
app6.use(
|
|
8909
|
-
honoPino.pinoLogger({
|
|
8910
|
-
pino: getLogger() || pino.pino({ level: "debug" }),
|
|
8911
|
-
http: {
|
|
8912
|
-
onResLevel(c) {
|
|
8913
|
-
if (c.res.status >= 500) {
|
|
8914
|
-
return "error";
|
|
8915
|
-
}
|
|
8916
|
-
return "info";
|
|
8917
|
-
}
|
|
8918
|
-
}
|
|
8919
|
-
})
|
|
8920
|
-
);
|
|
8921
8866
|
app6.onError(async (err, c) => {
|
|
8922
8867
|
const isExpectedError = err instanceof httpException.HTTPException;
|
|
8923
8868
|
const status = isExpectedError ? err.status : 500;
|
|
@@ -8951,9 +8896,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8951
8896
|
if (!isExpectedError) {
|
|
8952
8897
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
8953
8898
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
logger23.error(
|
|
8899
|
+
if (logger22) {
|
|
8900
|
+
logger22.error(
|
|
8957
8901
|
{
|
|
8958
8902
|
error: err,
|
|
8959
8903
|
message: errorMessage,
|
|
@@ -8965,9 +8909,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8965
8909
|
);
|
|
8966
8910
|
}
|
|
8967
8911
|
} else {
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
logger23.error(
|
|
8912
|
+
if (logger22) {
|
|
8913
|
+
logger22.error(
|
|
8971
8914
|
{
|
|
8972
8915
|
error: err,
|
|
8973
8916
|
path: c.req.path,
|
|
@@ -8984,9 +8927,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8984
8927
|
const response = err.getResponse();
|
|
8985
8928
|
return response;
|
|
8986
8929
|
} catch (responseError) {
|
|
8987
|
-
|
|
8988
|
-
|
|
8989
|
-
logger23.error({ error: responseError }, "Error while handling HTTPException response");
|
|
8930
|
+
if (logger22) {
|
|
8931
|
+
logger22.error({ error: responseError }, "Error while handling HTTPException response");
|
|
8990
8932
|
}
|
|
8991
8933
|
}
|
|
8992
8934
|
}
|
|
@@ -9020,15 +8962,16 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
9020
8962
|
app6.use("*", async (c, next) => {
|
|
9021
8963
|
const executionContext = c.get("executionContext");
|
|
9022
8964
|
if (!executionContext) {
|
|
8965
|
+
logger22.debug({}, "Empty execution context");
|
|
9023
8966
|
return next();
|
|
9024
8967
|
}
|
|
9025
8968
|
const { tenantId, projectId, graphId } = executionContext;
|
|
9026
8969
|
let conversationId;
|
|
9027
|
-
|
|
9028
|
-
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
8970
|
+
const requestBody = c.get("requestBody") || {};
|
|
8971
|
+
if (requestBody) {
|
|
8972
|
+
conversationId = requestBody.conversationId;
|
|
8973
|
+
if (!conversationId) {
|
|
8974
|
+
logger22.debug({ requestBody }, "No conversation ID found in request body");
|
|
9032
8975
|
}
|
|
9033
8976
|
}
|
|
9034
8977
|
const entries = Object.fromEntries(
|
|
@@ -9043,6 +8986,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
9043
8986
|
})
|
|
9044
8987
|
);
|
|
9045
8988
|
if (!Object.keys(entries).length) {
|
|
8989
|
+
logger22.debug({}, "Empty entries for baggage");
|
|
9046
8990
|
return next();
|
|
9047
8991
|
}
|
|
9048
8992
|
const bag = Object.entries(entries).reduce(
|
|
@@ -9050,7 +8994,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
9050
8994
|
api.propagation.getBaggage(api.context.active()) ?? api.propagation.createBaggage()
|
|
9051
8995
|
);
|
|
9052
8996
|
const ctxWithBag = api.propagation.setBaggage(api.context.active(), bag);
|
|
9053
|
-
return api.context.with(ctxWithBag, () => next());
|
|
8997
|
+
return await api.context.with(ctxWithBag, async () => await next());
|
|
9054
8998
|
});
|
|
9055
8999
|
app6.openapi(
|
|
9056
9000
|
zodOpenapi.createRoute({
|
|
@@ -9074,6 +9018,22 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
9074
9018
|
app6.route("/v1/mcp", mcp_default);
|
|
9075
9019
|
app6.route("/agents", agents_default);
|
|
9076
9020
|
setupOpenAPIRoutes(app6);
|
|
9021
|
+
app6.use("/tenants/*", async (c, next) => {
|
|
9022
|
+
await next();
|
|
9023
|
+
await batchProcessor.forceFlush();
|
|
9024
|
+
});
|
|
9025
|
+
app6.use("/agents/*", async (c, next) => {
|
|
9026
|
+
await next();
|
|
9027
|
+
await batchProcessor.forceFlush();
|
|
9028
|
+
});
|
|
9029
|
+
app6.use("/v1/*", async (c, next) => {
|
|
9030
|
+
await next();
|
|
9031
|
+
await batchProcessor.forceFlush();
|
|
9032
|
+
});
|
|
9033
|
+
app6.use("/api/*", async (c, next) => {
|
|
9034
|
+
await next();
|
|
9035
|
+
await batchProcessor.forceFlush();
|
|
9036
|
+
});
|
|
9077
9037
|
const baseApp = new hono.Hono();
|
|
9078
9038
|
baseApp.route("/", app6);
|
|
9079
9039
|
return baseApp;
|