@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.js
CHANGED
|
@@ -6,7 +6,8 @@ import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
|
6
6
|
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
7
7
|
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
8
8
|
import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
9
|
-
import {
|
|
9
|
+
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
|
|
10
|
+
import { getLogger, getTracer, HeadersScopeSchema, getRequestExecutionContext, getAgentGraphWithDefaultAgent, contextValidationMiddleware, getFullGraph, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getAgentById, handleContextResolution, createMessage, commonGetErrorResponses, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, getAgentGraph, createTask, updateTask, updateConversation, handleApiError, setSpanWithError, TaskState, setActiveAgentForThread, getConversation, getRelatedAgentsForGraph, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, validateAndGetApiKey, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getContextConfigById, getFullGraphDefinition, TemplateEngine, graphHasArtifactComponents, MCPTransportType, getExternalAgent } from '@inkeep/agents-core';
|
|
10
11
|
import { Hono } from 'hono';
|
|
11
12
|
import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
|
|
12
13
|
import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
|
|
@@ -15,7 +16,6 @@ import { HTTPException } from 'hono/http-exception';
|
|
|
15
16
|
import { requestId } from 'hono/request-id';
|
|
16
17
|
import { pinoLogger } from 'hono-pino';
|
|
17
18
|
import { pino } from 'pino';
|
|
18
|
-
import { AsyncLocalStorage } from 'async_hooks';
|
|
19
19
|
import { createMiddleware } from 'hono/factory';
|
|
20
20
|
import { swaggerUI } from '@hono/swagger-ui';
|
|
21
21
|
import z4, { z } from 'zod';
|
|
@@ -42,6 +42,7 @@ var resource = resourceFromAttributes({
|
|
|
42
42
|
});
|
|
43
43
|
var sdk = new NodeSDK({
|
|
44
44
|
resource,
|
|
45
|
+
contextManager: new AsyncLocalStorageContextManager(),
|
|
45
46
|
spanProcessors: [new BaggageSpanProcessor(ALLOW_ALL_BAGGAGE_KEYS), batchProcessor],
|
|
46
47
|
instrumentations: [
|
|
47
48
|
getNodeAutoInstrumentations({
|
|
@@ -67,37 +68,6 @@ var sdk = new NodeSDK({
|
|
|
67
68
|
]
|
|
68
69
|
});
|
|
69
70
|
sdk.start();
|
|
70
|
-
var isDevelopment = env.ENVIRONMENT === "development";
|
|
71
|
-
var loggerConfig = {
|
|
72
|
-
level: env.LOG_LEVEL,
|
|
73
|
-
serializers: {
|
|
74
|
-
obj: (value) => ({ ...value })
|
|
75
|
-
},
|
|
76
|
-
redact: ["req.headers.authorization", 'req.headers["x-inkeep-admin-authentication"]'],
|
|
77
|
-
// Only use pino-pretty in development
|
|
78
|
-
...isDevelopment && {
|
|
79
|
-
transport: {
|
|
80
|
-
target: "pino-pretty",
|
|
81
|
-
options: {
|
|
82
|
-
sync: true,
|
|
83
|
-
destination: 1,
|
|
84
|
-
// stdout
|
|
85
|
-
colorize: true,
|
|
86
|
-
translateTime: "SYS:standard"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
var logger = pino(loggerConfig);
|
|
92
|
-
var asyncLocalStorage = new AsyncLocalStorage();
|
|
93
|
-
function getLogger(name) {
|
|
94
|
-
const store = asyncLocalStorage.getStore();
|
|
95
|
-
const reqId = store?.get("requestId") || void 0;
|
|
96
|
-
if (!reqId) {
|
|
97
|
-
return logger.child({ name });
|
|
98
|
-
}
|
|
99
|
-
return logger.child({ reqId, name });
|
|
100
|
-
}
|
|
101
71
|
|
|
102
72
|
// src/types/execution-context.ts
|
|
103
73
|
function createExecutionContext(params) {
|
|
@@ -113,7 +83,7 @@ function createExecutionContext(params) {
|
|
|
113
83
|
}
|
|
114
84
|
|
|
115
85
|
// src/middleware/api-key-auth.ts
|
|
116
|
-
var
|
|
86
|
+
var logger = getLogger("env-key-auth");
|
|
117
87
|
var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
118
88
|
if (c.req.method === "OPTIONS") {
|
|
119
89
|
await next();
|
|
@@ -130,7 +100,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
130
100
|
if (authHeader?.startsWith("Bearer ")) {
|
|
131
101
|
try {
|
|
132
102
|
executionContext = await extractContextFromApiKey(authHeader.substring(7));
|
|
133
|
-
|
|
103
|
+
logger.info({}, "Development/test environment - API key authenticated successfully");
|
|
134
104
|
} catch {
|
|
135
105
|
executionContext = createExecutionContext({
|
|
136
106
|
apiKey: "development",
|
|
@@ -141,7 +111,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
141
111
|
baseUrl,
|
|
142
112
|
agentId
|
|
143
113
|
});
|
|
144
|
-
|
|
114
|
+
logger.info(
|
|
145
115
|
{},
|
|
146
116
|
"Development/test environment - fallback to default context due to invalid API key"
|
|
147
117
|
);
|
|
@@ -156,7 +126,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
156
126
|
baseUrl,
|
|
157
127
|
agentId
|
|
158
128
|
});
|
|
159
|
-
|
|
129
|
+
logger.info(
|
|
160
130
|
{},
|
|
161
131
|
"Development/test environment - no API key provided, using default context"
|
|
162
132
|
);
|
|
@@ -188,13 +158,13 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
188
158
|
agentId
|
|
189
159
|
});
|
|
190
160
|
c.set("executionContext", executionContext);
|
|
191
|
-
|
|
161
|
+
logger.info({}, "Bypass secret authenticated successfully");
|
|
192
162
|
await next();
|
|
193
163
|
return;
|
|
194
164
|
} else if (apiKey) {
|
|
195
165
|
const executionContext = await extractContextFromApiKey(apiKey);
|
|
196
166
|
c.set("executionContext", executionContext);
|
|
197
|
-
|
|
167
|
+
logger.info({}, "API key authenticated successfully");
|
|
198
168
|
await next();
|
|
199
169
|
return;
|
|
200
170
|
} else {
|
|
@@ -211,7 +181,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
211
181
|
try {
|
|
212
182
|
const executionContext = await extractContextFromApiKey(apiKey);
|
|
213
183
|
c.set("executionContext", executionContext);
|
|
214
|
-
|
|
184
|
+
logger.debug(
|
|
215
185
|
{
|
|
216
186
|
tenantId: executionContext.tenantId,
|
|
217
187
|
projectId: executionContext.projectId,
|
|
@@ -224,7 +194,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
224
194
|
if (error instanceof HTTPException) {
|
|
225
195
|
throw error;
|
|
226
196
|
}
|
|
227
|
-
|
|
197
|
+
logger.error({ error }, "API key authentication error");
|
|
228
198
|
throw new HTTPException(500, {
|
|
229
199
|
message: "Authentication failed"
|
|
230
200
|
});
|
|
@@ -277,7 +247,7 @@ function setupOpenAPIRoutes(app6) {
|
|
|
277
247
|
})
|
|
278
248
|
);
|
|
279
249
|
}
|
|
280
|
-
var
|
|
250
|
+
var logger2 = getLogger("a2aHandler");
|
|
281
251
|
async function a2aHandler(c, agent) {
|
|
282
252
|
try {
|
|
283
253
|
const rpcRequest = await c.req.json();
|
|
@@ -379,7 +349,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
379
349
|
messageId: task.id,
|
|
380
350
|
kind: "message"
|
|
381
351
|
});
|
|
382
|
-
|
|
352
|
+
logger2.warn(
|
|
383
353
|
{
|
|
384
354
|
taskId: task.id,
|
|
385
355
|
agentId: agent.agentId,
|
|
@@ -389,7 +359,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
389
359
|
);
|
|
390
360
|
}
|
|
391
361
|
} catch (error) {
|
|
392
|
-
|
|
362
|
+
logger2.error({ error, taskId: task.id }, "Failed to serialize message");
|
|
393
363
|
JSON.stringify({
|
|
394
364
|
error: "Failed to serialize message",
|
|
395
365
|
taskId: task.id,
|
|
@@ -397,7 +367,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
397
367
|
parts: [{ text: "Error in delegation", kind: "text" }]
|
|
398
368
|
});
|
|
399
369
|
}
|
|
400
|
-
|
|
370
|
+
logger2.info(
|
|
401
371
|
{
|
|
402
372
|
originalContextId: params.message.contextId,
|
|
403
373
|
taskContextId: task.context?.conversationId,
|
|
@@ -426,7 +396,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
426
396
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
427
397
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
428
398
|
});
|
|
429
|
-
|
|
399
|
+
logger2.info({ metadata: params.message.metadata }, "message metadata");
|
|
430
400
|
if (params.message.metadata?.fromAgentId || params.message.metadata?.fromExternalAgentId) {
|
|
431
401
|
const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
|
|
432
402
|
try {
|
|
@@ -451,7 +421,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
451
421
|
messageData.toAgentId = agent.agentId;
|
|
452
422
|
}
|
|
453
423
|
await createMessage(dbClient_default)(messageData);
|
|
454
|
-
|
|
424
|
+
logger2.info(
|
|
455
425
|
{
|
|
456
426
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
457
427
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
@@ -463,7 +433,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
463
433
|
"A2A message stored in database"
|
|
464
434
|
);
|
|
465
435
|
} catch (error) {
|
|
466
|
-
|
|
436
|
+
logger2.error(
|
|
467
437
|
{
|
|
468
438
|
error,
|
|
469
439
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
@@ -500,7 +470,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
500
470
|
(part) => part.kind === "data" && part.data && typeof part.data === "object" && part.data.type === "transfer"
|
|
501
471
|
);
|
|
502
472
|
if (transferPart && transferPart.kind === "data" && transferPart.data) {
|
|
503
|
-
|
|
473
|
+
logger2.info({ transferPart }, "transferPart");
|
|
504
474
|
return c.json({
|
|
505
475
|
jsonrpc: "2.0",
|
|
506
476
|
result: {
|
|
@@ -918,10 +888,10 @@ function statusUpdateOp(ctx) {
|
|
|
918
888
|
ctx
|
|
919
889
|
};
|
|
920
890
|
}
|
|
921
|
-
var
|
|
891
|
+
var logger3 = getLogger("DataComponentSchema");
|
|
922
892
|
function jsonSchemaToZod(jsonSchema) {
|
|
923
893
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
924
|
-
|
|
894
|
+
logger3.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
925
895
|
return z.string();
|
|
926
896
|
}
|
|
927
897
|
switch (jsonSchema.type) {
|
|
@@ -948,7 +918,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
948
918
|
case "null":
|
|
949
919
|
return z.null();
|
|
950
920
|
default:
|
|
951
|
-
|
|
921
|
+
logger3.warn(
|
|
952
922
|
{
|
|
953
923
|
unsupportedType: jsonSchema.type,
|
|
954
924
|
schema: jsonSchema
|
|
@@ -1002,7 +972,7 @@ __publicField(_ArtifactReferenceSchema, "ARTIFACT_PROPS_SCHEMA", {
|
|
|
1002
972
|
required: ["artifact_id", "task_id"]
|
|
1003
973
|
});
|
|
1004
974
|
var ArtifactReferenceSchema = _ArtifactReferenceSchema;
|
|
1005
|
-
var
|
|
975
|
+
var logger4 = getLogger("ModelFactory");
|
|
1006
976
|
var _ModelFactory = class _ModelFactory {
|
|
1007
977
|
/**
|
|
1008
978
|
* Create a language model instance from configuration
|
|
@@ -1017,7 +987,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1017
987
|
const modelSettings = config;
|
|
1018
988
|
const modelString = modelSettings.model.trim();
|
|
1019
989
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1020
|
-
|
|
990
|
+
logger4.debug(
|
|
1021
991
|
{
|
|
1022
992
|
provider,
|
|
1023
993
|
model: modelName,
|
|
@@ -1038,7 +1008,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1038
1008
|
);
|
|
1039
1009
|
}
|
|
1040
1010
|
} catch (error) {
|
|
1041
|
-
|
|
1011
|
+
logger4.error(
|
|
1042
1012
|
{
|
|
1043
1013
|
provider,
|
|
1044
1014
|
model: modelName,
|
|
@@ -1061,7 +1031,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1061
1031
|
const [provider, ...modelParts] = modelString.split("/");
|
|
1062
1032
|
const normalizedProvider = provider.toLowerCase();
|
|
1063
1033
|
if (!_ModelFactory.SUPPORTED_PROVIDERS.includes(normalizedProvider)) {
|
|
1064
|
-
|
|
1034
|
+
logger4.warn(
|
|
1065
1035
|
{ provider: normalizedProvider, modelName: modelParts.join("/") },
|
|
1066
1036
|
"Unsupported provider detected, falling back to anthropic"
|
|
1067
1037
|
);
|
|
@@ -1090,14 +1060,14 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1090
1060
|
anthropicConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1091
1061
|
}
|
|
1092
1062
|
if (providerOptions?.gateway) {
|
|
1093
|
-
|
|
1063
|
+
logger4.info(
|
|
1094
1064
|
{ gateway: providerOptions.gateway },
|
|
1095
1065
|
"Setting up AI Gateway for Anthropic model"
|
|
1096
1066
|
);
|
|
1097
1067
|
Object.assign(anthropicConfig, providerOptions.gateway);
|
|
1098
1068
|
}
|
|
1099
1069
|
if (Object.keys(anthropicConfig).length > 0) {
|
|
1100
|
-
|
|
1070
|
+
logger4.info({ config: anthropicConfig }, "Applying custom Anthropic provider configuration");
|
|
1101
1071
|
const provider = createAnthropic(anthropicConfig);
|
|
1102
1072
|
return provider(modelName);
|
|
1103
1073
|
}
|
|
@@ -1112,11 +1082,11 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1112
1082
|
openaiConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1113
1083
|
}
|
|
1114
1084
|
if (providerOptions?.gateway) {
|
|
1115
|
-
|
|
1085
|
+
logger4.info({ gateway: providerOptions.gateway }, "Setting up AI Gateway for OpenAI model");
|
|
1116
1086
|
Object.assign(openaiConfig, providerOptions.gateway);
|
|
1117
1087
|
}
|
|
1118
1088
|
if (Object.keys(openaiConfig).length > 0) {
|
|
1119
|
-
|
|
1089
|
+
logger4.info({ config: openaiConfig }, "Applying custom OpenAI provider configuration");
|
|
1120
1090
|
const provider = createOpenAI(openaiConfig);
|
|
1121
1091
|
return provider(modelName);
|
|
1122
1092
|
}
|
|
@@ -1206,7 +1176,7 @@ function unregisterStreamHelper(requestId2) {
|
|
|
1206
1176
|
}
|
|
1207
1177
|
|
|
1208
1178
|
// src/utils/graph-session.ts
|
|
1209
|
-
var
|
|
1179
|
+
var logger5 = getLogger("GraphSession");
|
|
1210
1180
|
var GraphSession = class {
|
|
1211
1181
|
// Track scheduled timeouts for cleanup
|
|
1212
1182
|
constructor(sessionId, messageId, graphId, tenantId, projectId) {
|
|
@@ -1230,7 +1200,7 @@ var GraphSession = class {
|
|
|
1230
1200
|
__publicField(this, "MAX_PENDING_ARTIFACTS", 100);
|
|
1231
1201
|
// Prevent unbounded growth
|
|
1232
1202
|
__publicField(this, "scheduledTimeouts");
|
|
1233
|
-
|
|
1203
|
+
logger5.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
1234
1204
|
}
|
|
1235
1205
|
/**
|
|
1236
1206
|
* Initialize status updates for this session
|
|
@@ -1252,7 +1222,7 @@ var GraphSession = class {
|
|
|
1252
1222
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
1253
1223
|
this.statusUpdateTimer = setInterval(async () => {
|
|
1254
1224
|
if (!this.statusUpdateState || this.isEnded) {
|
|
1255
|
-
|
|
1225
|
+
logger5.debug(
|
|
1256
1226
|
{ sessionId: this.sessionId },
|
|
1257
1227
|
"Timer triggered but session already cleaned up or ended"
|
|
1258
1228
|
);
|
|
@@ -1264,7 +1234,7 @@ var GraphSession = class {
|
|
|
1264
1234
|
}
|
|
1265
1235
|
await this.checkAndSendTimeBasedUpdate();
|
|
1266
1236
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
1267
|
-
|
|
1237
|
+
logger5.info(
|
|
1268
1238
|
{
|
|
1269
1239
|
sessionId: this.sessionId,
|
|
1270
1240
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -1278,7 +1248,7 @@ var GraphSession = class {
|
|
|
1278
1248
|
*/
|
|
1279
1249
|
recordEvent(eventType, agentId, data) {
|
|
1280
1250
|
if (this.isEnded) {
|
|
1281
|
-
|
|
1251
|
+
logger5.debug(
|
|
1282
1252
|
{
|
|
1283
1253
|
sessionId: this.sessionId,
|
|
1284
1254
|
eventType,
|
|
@@ -1298,7 +1268,7 @@ var GraphSession = class {
|
|
|
1298
1268
|
if (eventType === "artifact_saved" && data.pendingGeneration) {
|
|
1299
1269
|
const artifactId = data.artifactId;
|
|
1300
1270
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
1301
|
-
|
|
1271
|
+
logger5.warn(
|
|
1302
1272
|
{
|
|
1303
1273
|
sessionId: this.sessionId,
|
|
1304
1274
|
artifactId,
|
|
@@ -1319,7 +1289,7 @@ var GraphSession = class {
|
|
|
1319
1289
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
1320
1290
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
1321
1291
|
this.pendingArtifacts.delete(artifactId);
|
|
1322
|
-
|
|
1292
|
+
logger5.error(
|
|
1323
1293
|
{
|
|
1324
1294
|
sessionId: this.sessionId,
|
|
1325
1295
|
artifactId,
|
|
@@ -1331,7 +1301,7 @@ var GraphSession = class {
|
|
|
1331
1301
|
"Artifact processing failed after max retries, giving up"
|
|
1332
1302
|
);
|
|
1333
1303
|
} else {
|
|
1334
|
-
|
|
1304
|
+
logger5.warn(
|
|
1335
1305
|
{
|
|
1336
1306
|
sessionId: this.sessionId,
|
|
1337
1307
|
artifactId,
|
|
@@ -1353,14 +1323,14 @@ var GraphSession = class {
|
|
|
1353
1323
|
*/
|
|
1354
1324
|
checkStatusUpdates() {
|
|
1355
1325
|
if (this.isEnded) {
|
|
1356
|
-
|
|
1326
|
+
logger5.debug(
|
|
1357
1327
|
{ sessionId: this.sessionId },
|
|
1358
1328
|
"Session has ended - skipping status update check"
|
|
1359
1329
|
);
|
|
1360
1330
|
return;
|
|
1361
1331
|
}
|
|
1362
1332
|
if (!this.statusUpdateState) {
|
|
1363
|
-
|
|
1333
|
+
logger5.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
1364
1334
|
return;
|
|
1365
1335
|
}
|
|
1366
1336
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -1371,11 +1341,11 @@ var GraphSession = class {
|
|
|
1371
1341
|
*/
|
|
1372
1342
|
async checkAndSendTimeBasedUpdate() {
|
|
1373
1343
|
if (this.isEnded) {
|
|
1374
|
-
|
|
1344
|
+
logger5.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
1375
1345
|
return;
|
|
1376
1346
|
}
|
|
1377
1347
|
if (!this.statusUpdateState) {
|
|
1378
|
-
|
|
1348
|
+
logger5.debug(
|
|
1379
1349
|
{ sessionId: this.sessionId },
|
|
1380
1350
|
"No status updates configured for time-based check"
|
|
1381
1351
|
);
|
|
@@ -1388,7 +1358,7 @@ var GraphSession = class {
|
|
|
1388
1358
|
try {
|
|
1389
1359
|
await this.generateAndSendUpdate();
|
|
1390
1360
|
} catch (error) {
|
|
1391
|
-
|
|
1361
|
+
logger5.error(
|
|
1392
1362
|
{
|
|
1393
1363
|
sessionId: this.sessionId,
|
|
1394
1364
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1481,29 +1451,29 @@ var GraphSession = class {
|
|
|
1481
1451
|
*/
|
|
1482
1452
|
async generateAndSendUpdate() {
|
|
1483
1453
|
if (this.isEnded) {
|
|
1484
|
-
|
|
1454
|
+
logger5.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
1485
1455
|
return;
|
|
1486
1456
|
}
|
|
1487
1457
|
if (this.isTextStreaming) {
|
|
1488
|
-
|
|
1458
|
+
logger5.debug(
|
|
1489
1459
|
{ sessionId: this.sessionId },
|
|
1490
1460
|
"Text is currently streaming - skipping status update"
|
|
1491
1461
|
);
|
|
1492
1462
|
return;
|
|
1493
1463
|
}
|
|
1494
1464
|
if (this.isGeneratingUpdate) {
|
|
1495
|
-
|
|
1465
|
+
logger5.debug(
|
|
1496
1466
|
{ sessionId: this.sessionId },
|
|
1497
1467
|
"Update already in progress - skipping duplicate generation"
|
|
1498
1468
|
);
|
|
1499
1469
|
return;
|
|
1500
1470
|
}
|
|
1501
1471
|
if (!this.statusUpdateState) {
|
|
1502
|
-
|
|
1472
|
+
logger5.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
1503
1473
|
return;
|
|
1504
1474
|
}
|
|
1505
1475
|
if (!this.graphId) {
|
|
1506
|
-
|
|
1476
|
+
logger5.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
1507
1477
|
return;
|
|
1508
1478
|
}
|
|
1509
1479
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -1516,7 +1486,7 @@ var GraphSession = class {
|
|
|
1516
1486
|
try {
|
|
1517
1487
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
1518
1488
|
if (!streamHelper) {
|
|
1519
|
-
|
|
1489
|
+
logger5.warn(
|
|
1520
1490
|
{ sessionId: this.sessionId },
|
|
1521
1491
|
"No stream helper found - cannot send status update"
|
|
1522
1492
|
);
|
|
@@ -1537,7 +1507,7 @@ var GraphSession = class {
|
|
|
1537
1507
|
if (result.operations && result.operations.length > 0) {
|
|
1538
1508
|
for (const op of result.operations) {
|
|
1539
1509
|
if (!op || !op.type || !op.data || Object.keys(op.data).length === 0) {
|
|
1540
|
-
|
|
1510
|
+
logger5.warn(
|
|
1541
1511
|
{
|
|
1542
1512
|
sessionId: this.sessionId,
|
|
1543
1513
|
operation: op
|
|
@@ -1590,7 +1560,7 @@ var GraphSession = class {
|
|
|
1590
1560
|
this.previousSummaries.shift();
|
|
1591
1561
|
}
|
|
1592
1562
|
if (!operation || !operation.type || !operation.ctx) {
|
|
1593
|
-
|
|
1563
|
+
logger5.warn(
|
|
1594
1564
|
{
|
|
1595
1565
|
sessionId: this.sessionId,
|
|
1596
1566
|
operation
|
|
@@ -1605,7 +1575,7 @@ var GraphSession = class {
|
|
|
1605
1575
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
1606
1576
|
}
|
|
1607
1577
|
} catch (error) {
|
|
1608
|
-
|
|
1578
|
+
logger5.error(
|
|
1609
1579
|
{
|
|
1610
1580
|
sessionId: this.sessionId,
|
|
1611
1581
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -1643,7 +1613,7 @@ var GraphSession = class {
|
|
|
1643
1613
|
this.releaseUpdateLock();
|
|
1644
1614
|
}
|
|
1645
1615
|
} catch (error) {
|
|
1646
|
-
|
|
1616
|
+
logger5.error(
|
|
1647
1617
|
{
|
|
1648
1618
|
sessionId: this.sessionId,
|
|
1649
1619
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1720,7 +1690,7 @@ User's Question/Context:
|
|
|
1720
1690
|
${conversationHistory}
|
|
1721
1691
|
` : "";
|
|
1722
1692
|
} catch (error) {
|
|
1723
|
-
|
|
1693
|
+
logger5.warn(
|
|
1724
1694
|
{ sessionId: this.sessionId, error },
|
|
1725
1695
|
"Failed to fetch conversation history for status update"
|
|
1726
1696
|
);
|
|
@@ -1772,7 +1742,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
1772
1742
|
return text.trim();
|
|
1773
1743
|
} catch (error) {
|
|
1774
1744
|
setSpanWithError(span, error);
|
|
1775
|
-
|
|
1745
|
+
logger5.error({ error }, "Failed to generate summary, using fallback");
|
|
1776
1746
|
return this.generateFallbackSummary(newEvents, elapsedTime);
|
|
1777
1747
|
} finally {
|
|
1778
1748
|
span.end();
|
|
@@ -1818,7 +1788,7 @@ User's Question/Context:
|
|
|
1818
1788
|
${conversationHistory}
|
|
1819
1789
|
` : "";
|
|
1820
1790
|
} catch (error) {
|
|
1821
|
-
|
|
1791
|
+
logger5.warn(
|
|
1822
1792
|
{ sessionId: this.sessionId, error },
|
|
1823
1793
|
"Failed to fetch conversation history for structured status update"
|
|
1824
1794
|
);
|
|
@@ -1917,7 +1887,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
1917
1887
|
return { operations };
|
|
1918
1888
|
} catch (error) {
|
|
1919
1889
|
setSpanWithError(span, error);
|
|
1920
|
-
|
|
1890
|
+
logger5.error({ error }, "Failed to generate structured update, using fallback");
|
|
1921
1891
|
return { operations: [] };
|
|
1922
1892
|
} finally {
|
|
1923
1893
|
span.end();
|
|
@@ -2244,7 +2214,7 @@ Make it specific and relevant.`;
|
|
|
2244
2214
|
taskId: artifactData.taskId,
|
|
2245
2215
|
artifacts: [artifactToSave]
|
|
2246
2216
|
});
|
|
2247
|
-
|
|
2217
|
+
logger5.info(
|
|
2248
2218
|
{
|
|
2249
2219
|
sessionId: this.sessionId,
|
|
2250
2220
|
artifactId: artifactData.artifactId,
|
|
@@ -2261,7 +2231,7 @@ Make it specific and relevant.`;
|
|
|
2261
2231
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
2262
2232
|
} catch (error) {
|
|
2263
2233
|
setSpanWithError(span, error);
|
|
2264
|
-
|
|
2234
|
+
logger5.error(
|
|
2265
2235
|
{
|
|
2266
2236
|
sessionId: this.sessionId,
|
|
2267
2237
|
artifactId: artifactData.artifactId,
|
|
@@ -2297,7 +2267,7 @@ Make it specific and relevant.`;
|
|
|
2297
2267
|
taskId: artifactData.taskId,
|
|
2298
2268
|
artifacts: [fallbackArtifact]
|
|
2299
2269
|
});
|
|
2300
|
-
|
|
2270
|
+
logger5.info(
|
|
2301
2271
|
{
|
|
2302
2272
|
sessionId: this.sessionId,
|
|
2303
2273
|
artifactId: artifactData.artifactId
|
|
@@ -2306,7 +2276,7 @@ Make it specific and relevant.`;
|
|
|
2306
2276
|
);
|
|
2307
2277
|
}
|
|
2308
2278
|
} catch (fallbackError) {
|
|
2309
|
-
|
|
2279
|
+
logger5.error(
|
|
2310
2280
|
{
|
|
2311
2281
|
sessionId: this.sessionId,
|
|
2312
2282
|
artifactId: artifactData.artifactId,
|
|
@@ -2333,7 +2303,7 @@ var GraphSessionManager = class {
|
|
|
2333
2303
|
const sessionId = messageId;
|
|
2334
2304
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId);
|
|
2335
2305
|
this.sessions.set(sessionId, session);
|
|
2336
|
-
|
|
2306
|
+
logger5.info({ sessionId, messageId, graphId, tenantId, projectId }, "GraphSession created");
|
|
2337
2307
|
return sessionId;
|
|
2338
2308
|
}
|
|
2339
2309
|
/**
|
|
@@ -2344,7 +2314,7 @@ var GraphSessionManager = class {
|
|
|
2344
2314
|
if (session) {
|
|
2345
2315
|
session.initializeStatusUpdates(config, summarizerModel);
|
|
2346
2316
|
} else {
|
|
2347
|
-
|
|
2317
|
+
logger5.error(
|
|
2348
2318
|
{
|
|
2349
2319
|
sessionId,
|
|
2350
2320
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -2365,7 +2335,7 @@ var GraphSessionManager = class {
|
|
|
2365
2335
|
recordEvent(sessionId, eventType, agentId, data) {
|
|
2366
2336
|
const session = this.sessions.get(sessionId);
|
|
2367
2337
|
if (!session) {
|
|
2368
|
-
|
|
2338
|
+
logger5.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
2369
2339
|
return;
|
|
2370
2340
|
}
|
|
2371
2341
|
session.recordEvent(eventType, agentId, data);
|
|
@@ -2376,12 +2346,12 @@ var GraphSessionManager = class {
|
|
|
2376
2346
|
endSession(sessionId) {
|
|
2377
2347
|
const session = this.sessions.get(sessionId);
|
|
2378
2348
|
if (!session) {
|
|
2379
|
-
|
|
2349
|
+
logger5.warn({ sessionId }, "Attempted to end non-existent session");
|
|
2380
2350
|
return [];
|
|
2381
2351
|
}
|
|
2382
2352
|
const events = session.getEvents();
|
|
2383
2353
|
const summary = session.getSummary();
|
|
2384
|
-
|
|
2354
|
+
logger5.info({ sessionId, summary }, "GraphSession ended");
|
|
2385
2355
|
session.cleanup();
|
|
2386
2356
|
this.sessions.delete(sessionId);
|
|
2387
2357
|
return events;
|
|
@@ -2407,7 +2377,7 @@ var GraphSessionManager = class {
|
|
|
2407
2377
|
}
|
|
2408
2378
|
};
|
|
2409
2379
|
var graphSessionManager = new GraphSessionManager();
|
|
2410
|
-
var
|
|
2380
|
+
var logger6 = getLogger("ArtifactParser");
|
|
2411
2381
|
var _ArtifactParser = class _ArtifactParser {
|
|
2412
2382
|
constructor(tenantId) {
|
|
2413
2383
|
this.tenantId = tenantId;
|
|
@@ -2473,7 +2443,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2473
2443
|
id: taskId
|
|
2474
2444
|
});
|
|
2475
2445
|
if (!task) {
|
|
2476
|
-
|
|
2446
|
+
logger6.warn({ taskId }, "Task not found when fetching artifacts");
|
|
2477
2447
|
continue;
|
|
2478
2448
|
}
|
|
2479
2449
|
const taskArtifacts = await getLedgerArtifacts(dbClient_default)({
|
|
@@ -2485,9 +2455,9 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2485
2455
|
artifacts.set(key, artifact);
|
|
2486
2456
|
}
|
|
2487
2457
|
}
|
|
2488
|
-
|
|
2458
|
+
logger6.debug({ contextId, count: artifacts.size }, "Loaded context artifacts");
|
|
2489
2459
|
} catch (error) {
|
|
2490
|
-
|
|
2460
|
+
logger6.error({ error, contextId }, "Error loading context artifacts");
|
|
2491
2461
|
}
|
|
2492
2462
|
return artifacts;
|
|
2493
2463
|
}
|
|
@@ -2590,7 +2560,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2590
2560
|
id: taskId
|
|
2591
2561
|
});
|
|
2592
2562
|
if (!task) {
|
|
2593
|
-
|
|
2563
|
+
logger6.warn({ taskId }, "Task not found when fetching artifact");
|
|
2594
2564
|
return null;
|
|
2595
2565
|
}
|
|
2596
2566
|
const artifacts = await getLedgerArtifacts(dbClient_default)({
|
|
@@ -2602,7 +2572,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2602
2572
|
return this.formatArtifactData(artifacts[0], artifactId, taskId);
|
|
2603
2573
|
}
|
|
2604
2574
|
} catch (error) {
|
|
2605
|
-
|
|
2575
|
+
logger6.warn({ artifactId, taskId, error }, "Failed to fetch artifact");
|
|
2606
2576
|
}
|
|
2607
2577
|
return null;
|
|
2608
2578
|
}
|
|
@@ -2642,7 +2612,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_ARTIFACT_REGEX", /<(a(r(t(i(f(a(c(t(:
|
|
|
2642
2612
|
var ArtifactParser = _ArtifactParser;
|
|
2643
2613
|
|
|
2644
2614
|
// src/utils/incremental-stream-parser.ts
|
|
2645
|
-
var
|
|
2615
|
+
var logger7 = getLogger("IncrementalStreamParser");
|
|
2646
2616
|
var IncrementalStreamParser = class {
|
|
2647
2617
|
constructor(streamHelper, tenantId, contextId) {
|
|
2648
2618
|
__publicField(this, "buffer", "");
|
|
@@ -2702,13 +2672,13 @@ var IncrementalStreamParser = class {
|
|
|
2702
2672
|
if (part.type === "tool-call-delta" && part.toolName === targetToolName) {
|
|
2703
2673
|
const delta = part.argsTextDelta || "";
|
|
2704
2674
|
if (jsonBuffer.length + delta.length > MAX_BUFFER_SIZE) {
|
|
2705
|
-
|
|
2675
|
+
logger7.warn("JSON buffer exceeded maximum size, truncating");
|
|
2706
2676
|
jsonBuffer = jsonBuffer.slice(-MAX_BUFFER_SIZE / 2);
|
|
2707
2677
|
}
|
|
2708
2678
|
jsonBuffer += delta;
|
|
2709
2679
|
for (const char of delta) {
|
|
2710
2680
|
if (componentBuffer.length > MAX_BUFFER_SIZE) {
|
|
2711
|
-
|
|
2681
|
+
logger7.warn("Component buffer exceeded maximum size, resetting");
|
|
2712
2682
|
componentBuffer = "";
|
|
2713
2683
|
depth = 0;
|
|
2714
2684
|
continue;
|
|
@@ -2723,7 +2693,7 @@ var IncrementalStreamParser = class {
|
|
|
2723
2693
|
if (componentMatch) {
|
|
2724
2694
|
const MAX_COMPONENT_SIZE = 1024 * 1024;
|
|
2725
2695
|
if (componentMatch[0].length > MAX_COMPONENT_SIZE) {
|
|
2726
|
-
|
|
2696
|
+
logger7.warn(
|
|
2727
2697
|
{
|
|
2728
2698
|
size: componentMatch[0].length,
|
|
2729
2699
|
maxSize: MAX_COMPONENT_SIZE
|
|
@@ -2736,7 +2706,7 @@ var IncrementalStreamParser = class {
|
|
|
2736
2706
|
try {
|
|
2737
2707
|
const component = JSON.parse(componentMatch[0]);
|
|
2738
2708
|
if (typeof component !== "object" || !component.id) {
|
|
2739
|
-
|
|
2709
|
+
logger7.warn("Invalid component structure, skipping");
|
|
2740
2710
|
componentBuffer = "";
|
|
2741
2711
|
continue;
|
|
2742
2712
|
}
|
|
@@ -2749,7 +2719,7 @@ var IncrementalStreamParser = class {
|
|
|
2749
2719
|
componentsStreamed++;
|
|
2750
2720
|
componentBuffer = "";
|
|
2751
2721
|
} catch (e) {
|
|
2752
|
-
|
|
2722
|
+
logger7.debug({ error: e }, "Failed to parse component, continuing to accumulate");
|
|
2753
2723
|
}
|
|
2754
2724
|
}
|
|
2755
2725
|
}
|
|
@@ -2766,7 +2736,7 @@ var IncrementalStreamParser = class {
|
|
|
2766
2736
|
break;
|
|
2767
2737
|
}
|
|
2768
2738
|
}
|
|
2769
|
-
|
|
2739
|
+
logger7.debug({ componentsStreamed }, "Finished streaming components");
|
|
2770
2740
|
}
|
|
2771
2741
|
/**
|
|
2772
2742
|
* Legacy method for backward compatibility - defaults to text processing
|
|
@@ -2910,7 +2880,7 @@ var IncrementalStreamParser = class {
|
|
|
2910
2880
|
};
|
|
2911
2881
|
|
|
2912
2882
|
// src/utils/response-formatter.ts
|
|
2913
|
-
var
|
|
2883
|
+
var logger8 = getLogger("ResponseFormatter");
|
|
2914
2884
|
var ResponseFormatter = class {
|
|
2915
2885
|
constructor(tenantId) {
|
|
2916
2886
|
__publicField(this, "artifactParser");
|
|
@@ -2941,7 +2911,7 @@ var ResponseFormatter = class {
|
|
|
2941
2911
|
return { parts };
|
|
2942
2912
|
} catch (error) {
|
|
2943
2913
|
setSpanWithError(span, error);
|
|
2944
|
-
|
|
2914
|
+
logger8.error({ error, responseObject }, "Error formatting object response");
|
|
2945
2915
|
return {
|
|
2946
2916
|
parts: [{ kind: "data", data: responseObject }]
|
|
2947
2917
|
};
|
|
@@ -2992,7 +2962,7 @@ var ResponseFormatter = class {
|
|
|
2992
2962
|
return { parts };
|
|
2993
2963
|
} catch (error) {
|
|
2994
2964
|
setSpanWithError(span, error);
|
|
2995
|
-
|
|
2965
|
+
logger8.error({ error, responseText }, "Error formatting response");
|
|
2996
2966
|
return { text: responseText };
|
|
2997
2967
|
} finally {
|
|
2998
2968
|
span.end();
|
|
@@ -3037,7 +3007,7 @@ var ResponseFormatter = class {
|
|
|
3037
3007
|
}
|
|
3038
3008
|
}
|
|
3039
3009
|
};
|
|
3040
|
-
var
|
|
3010
|
+
var logger9 = getLogger("ToolSessionManager");
|
|
3041
3011
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
3042
3012
|
// 5 minutes
|
|
3043
3013
|
constructor() {
|
|
@@ -3066,7 +3036,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3066
3036
|
createdAt: Date.now()
|
|
3067
3037
|
};
|
|
3068
3038
|
this.sessions.set(sessionId, session);
|
|
3069
|
-
|
|
3039
|
+
logger9.debug({ sessionId, tenantId, contextId, taskId }, "Created tool session");
|
|
3070
3040
|
return sessionId;
|
|
3071
3041
|
}
|
|
3072
3042
|
/**
|
|
@@ -3075,7 +3045,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3075
3045
|
recordToolResult(sessionId, toolResult) {
|
|
3076
3046
|
const session = this.sessions.get(sessionId);
|
|
3077
3047
|
if (!session) {
|
|
3078
|
-
|
|
3048
|
+
logger9.warn(
|
|
3079
3049
|
{ sessionId, toolCallId: toolResult.toolCallId },
|
|
3080
3050
|
"Tool result recorded for unknown session"
|
|
3081
3051
|
);
|
|
@@ -3089,12 +3059,12 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3089
3059
|
getToolResult(sessionId, toolCallId) {
|
|
3090
3060
|
const session = this.sessions.get(sessionId);
|
|
3091
3061
|
if (!session) {
|
|
3092
|
-
|
|
3062
|
+
logger9.warn({ sessionId, toolCallId }, "Requested tool result for unknown session");
|
|
3093
3063
|
return void 0;
|
|
3094
3064
|
}
|
|
3095
3065
|
const result = session.toolResults.get(toolCallId);
|
|
3096
3066
|
if (!result) {
|
|
3097
|
-
|
|
3067
|
+
logger9.warn(
|
|
3098
3068
|
{
|
|
3099
3069
|
sessionId,
|
|
3100
3070
|
toolCallId,
|
|
@@ -3133,10 +3103,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3133
3103
|
}
|
|
3134
3104
|
for (const sessionId of expiredSessions) {
|
|
3135
3105
|
this.sessions.delete(sessionId);
|
|
3136
|
-
|
|
3106
|
+
logger9.debug({ sessionId }, "Cleaned up expired tool session");
|
|
3137
3107
|
}
|
|
3138
3108
|
if (expiredSessions.length > 0) {
|
|
3139
|
-
|
|
3109
|
+
logger9.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
3140
3110
|
}
|
|
3141
3111
|
}
|
|
3142
3112
|
};
|
|
@@ -3145,7 +3115,7 @@ var ToolSessionManager = _ToolSessionManager;
|
|
|
3145
3115
|
var toolSessionManager = ToolSessionManager.getInstance();
|
|
3146
3116
|
|
|
3147
3117
|
// src/agents/artifactTools.ts
|
|
3148
|
-
var
|
|
3118
|
+
var logger10 = getLogger("artifactTools");
|
|
3149
3119
|
function buildKeyNestingMap(data, prefix = "", map = /* @__PURE__ */ new Map()) {
|
|
3150
3120
|
if (typeof data === "object" && data !== null) {
|
|
3151
3121
|
if (Array.isArray(data)) {
|
|
@@ -3366,7 +3336,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3366
3336
|
execute: async ({ toolCallId, baseSelector, propSelectors, ...rest }, _context) => {
|
|
3367
3337
|
const artifactType = "artifactType" in rest ? rest.artifactType : void 0;
|
|
3368
3338
|
if (!sessionId) {
|
|
3369
|
-
|
|
3339
|
+
logger10.warn({ toolCallId }, "No session ID provided to save_tool_result");
|
|
3370
3340
|
return {
|
|
3371
3341
|
saved: false,
|
|
3372
3342
|
error: `[toolCallId: ${toolCallId}] No session context available`,
|
|
@@ -3376,7 +3346,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3376
3346
|
}
|
|
3377
3347
|
const toolResult = toolSessionManager.getToolResult(sessionId, toolCallId);
|
|
3378
3348
|
if (!toolResult) {
|
|
3379
|
-
|
|
3349
|
+
logger10.warn({ toolCallId, sessionId }, "Tool result not found in session");
|
|
3380
3350
|
return {
|
|
3381
3351
|
saved: false,
|
|
3382
3352
|
error: `[toolCallId: ${toolCallId}] Tool result not found`,
|
|
@@ -3389,7 +3359,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3389
3359
|
const baseData = jmespath.search(parsedResult, baseSelector);
|
|
3390
3360
|
if (!baseData || Array.isArray(baseData) && baseData.length === 0) {
|
|
3391
3361
|
const debugInfo = analyzeSelectorFailure(parsedResult, baseSelector);
|
|
3392
|
-
|
|
3362
|
+
logger10.warn(
|
|
3393
3363
|
{
|
|
3394
3364
|
baseSelector,
|
|
3395
3365
|
toolCallId,
|
|
@@ -3432,7 +3402,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3432
3402
|
const fallbackValue = item[propName];
|
|
3433
3403
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3434
3404
|
extractedItem[propName] = fallbackValue;
|
|
3435
|
-
|
|
3405
|
+
logger10.info(
|
|
3436
3406
|
{ propName, propSelector, context },
|
|
3437
3407
|
`PropSelector failed, used fallback direct property access`
|
|
3438
3408
|
);
|
|
@@ -3444,7 +3414,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3444
3414
|
const fallbackValue = item[propName];
|
|
3445
3415
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3446
3416
|
extractedItem[propName] = fallbackValue;
|
|
3447
|
-
|
|
3417
|
+
logger10.warn(
|
|
3448
3418
|
{ propName, propSelector, context, error: error.message },
|
|
3449
3419
|
`PropSelector syntax error, used fallback direct property access`
|
|
3450
3420
|
);
|
|
@@ -3557,7 +3527,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3557
3527
|
warnings
|
|
3558
3528
|
};
|
|
3559
3529
|
} catch (error) {
|
|
3560
|
-
|
|
3530
|
+
logger10.error({ error, toolCallId, sessionId }, "Error processing save_tool_result");
|
|
3561
3531
|
return {
|
|
3562
3532
|
saved: false,
|
|
3563
3533
|
error: `[toolCallId: ${toolCallId}] ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
@@ -3569,7 +3539,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3569
3539
|
}
|
|
3570
3540
|
|
|
3571
3541
|
// src/a2a/client.ts
|
|
3572
|
-
var
|
|
3542
|
+
var logger11 = getLogger("a2aClient");
|
|
3573
3543
|
var DEFAULT_BACKOFF = {
|
|
3574
3544
|
initialInterval: 500,
|
|
3575
3545
|
maxInterval: 6e4,
|
|
@@ -3775,7 +3745,7 @@ var A2AClient = class {
|
|
|
3775
3745
|
try {
|
|
3776
3746
|
const res = await fn();
|
|
3777
3747
|
if (attempt > 0) {
|
|
3778
|
-
|
|
3748
|
+
logger11.info(
|
|
3779
3749
|
{
|
|
3780
3750
|
attempts: attempt + 1,
|
|
3781
3751
|
elapsedTime: Date.now() - start
|
|
@@ -3790,7 +3760,7 @@ var A2AClient = class {
|
|
|
3790
3760
|
}
|
|
3791
3761
|
const elapsed = Date.now() - start;
|
|
3792
3762
|
if (elapsed > maxElapsedTime) {
|
|
3793
|
-
|
|
3763
|
+
logger11.warn(
|
|
3794
3764
|
{
|
|
3795
3765
|
attempts: attempt + 1,
|
|
3796
3766
|
elapsedTime: elapsed,
|
|
@@ -3811,7 +3781,7 @@ var A2AClient = class {
|
|
|
3811
3781
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
3812
3782
|
}
|
|
3813
3783
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
3814
|
-
|
|
3784
|
+
logger11.info(
|
|
3815
3785
|
{
|
|
3816
3786
|
attempt: attempt + 1,
|
|
3817
3787
|
delayMs,
|
|
@@ -3896,7 +3866,7 @@ var A2AClient = class {
|
|
|
3896
3866
|
}
|
|
3897
3867
|
const rpcResponse = await httpResponse.json();
|
|
3898
3868
|
if (rpcResponse.id !== requestId2) {
|
|
3899
|
-
|
|
3869
|
+
logger11.warn(
|
|
3900
3870
|
{
|
|
3901
3871
|
method,
|
|
3902
3872
|
expectedId: requestId2,
|
|
@@ -4095,7 +4065,7 @@ var A2AClient = class {
|
|
|
4095
4065
|
try {
|
|
4096
4066
|
while (true) {
|
|
4097
4067
|
const { done, value } = await reader.read();
|
|
4098
|
-
|
|
4068
|
+
logger11.info({ done, value }, "parseA2ASseStream");
|
|
4099
4069
|
if (done) {
|
|
4100
4070
|
if (eventDataBuffer.trim()) {
|
|
4101
4071
|
const result = this._processSseEventData(
|
|
@@ -4182,7 +4152,7 @@ var A2AClient = class {
|
|
|
4182
4152
|
};
|
|
4183
4153
|
|
|
4184
4154
|
// src/agents/relationTools.ts
|
|
4185
|
-
var
|
|
4155
|
+
var logger12 = getLogger("relationships Tools");
|
|
4186
4156
|
var generateTransferToolDescription = (config) => {
|
|
4187
4157
|
return `Hand off the conversation to agent ${config.id}.
|
|
4188
4158
|
|
|
@@ -4220,7 +4190,7 @@ var createTransferToAgentTool = ({
|
|
|
4220
4190
|
"transfer.to_agent_id": transferConfig.id ?? "unknown"
|
|
4221
4191
|
});
|
|
4222
4192
|
}
|
|
4223
|
-
|
|
4193
|
+
logger12.info(
|
|
4224
4194
|
{
|
|
4225
4195
|
transferTo: transferConfig.id ?? "unknown",
|
|
4226
4196
|
fromAgent: callingAgentId
|
|
@@ -4368,7 +4338,7 @@ function createDelegateToAgentTool({
|
|
|
4368
4338
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
4369
4339
|
}
|
|
4370
4340
|
};
|
|
4371
|
-
|
|
4341
|
+
logger12.info({ messageToSend }, "messageToSend");
|
|
4372
4342
|
await createMessage(dbClient_default)({
|
|
4373
4343
|
id: nanoid(),
|
|
4374
4344
|
tenantId,
|
|
@@ -4430,7 +4400,7 @@ function createDelegateToAgentTool({
|
|
|
4430
4400
|
}
|
|
4431
4401
|
|
|
4432
4402
|
// src/agents/SystemPromptBuilder.ts
|
|
4433
|
-
var
|
|
4403
|
+
var logger13 = getLogger("SystemPromptBuilder");
|
|
4434
4404
|
var SystemPromptBuilder = class {
|
|
4435
4405
|
constructor(version, versionConfig) {
|
|
4436
4406
|
this.version = version;
|
|
@@ -4446,9 +4416,9 @@ var SystemPromptBuilder = class {
|
|
|
4446
4416
|
this.templates.set(name, content);
|
|
4447
4417
|
}
|
|
4448
4418
|
this.loaded = true;
|
|
4449
|
-
|
|
4419
|
+
logger13.debug(`Loaded ${this.templates.size} templates for version ${this.version}`);
|
|
4450
4420
|
} catch (error) {
|
|
4451
|
-
|
|
4421
|
+
logger13.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
4452
4422
|
throw new Error(`Template loading failed: ${error}`);
|
|
4453
4423
|
}
|
|
4454
4424
|
}
|
|
@@ -4850,7 +4820,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
4850
4820
|
return false;
|
|
4851
4821
|
};
|
|
4852
4822
|
}
|
|
4853
|
-
var
|
|
4823
|
+
var logger14 = getLogger("Agent");
|
|
4854
4824
|
var CONSTANTS = {
|
|
4855
4825
|
MAX_GENERATION_STEPS: 12,
|
|
4856
4826
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -5103,14 +5073,14 @@ var Agent = class {
|
|
|
5103
5073
|
for (const toolSet of tools) {
|
|
5104
5074
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
5105
5075
|
if (!isValidTool(originalTool)) {
|
|
5106
|
-
|
|
5076
|
+
logger14.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
5107
5077
|
continue;
|
|
5108
5078
|
}
|
|
5109
5079
|
const sessionWrappedTool = tool({
|
|
5110
5080
|
description: originalTool.description,
|
|
5111
5081
|
inputSchema: originalTool.inputSchema,
|
|
5112
5082
|
execute: async (args, { toolCallId }) => {
|
|
5113
|
-
|
|
5083
|
+
logger14.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
5114
5084
|
try {
|
|
5115
5085
|
const result = await originalTool.execute(args, { toolCallId });
|
|
5116
5086
|
toolSessionManager.recordToolResult(sessionId, {
|
|
@@ -5122,7 +5092,7 @@ var Agent = class {
|
|
|
5122
5092
|
});
|
|
5123
5093
|
return { result, toolCallId };
|
|
5124
5094
|
} catch (error) {
|
|
5125
|
-
|
|
5095
|
+
logger14.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
5126
5096
|
throw error;
|
|
5127
5097
|
}
|
|
5128
5098
|
}
|
|
@@ -5207,7 +5177,7 @@ var Agent = class {
|
|
|
5207
5177
|
selectedTools
|
|
5208
5178
|
};
|
|
5209
5179
|
}
|
|
5210
|
-
|
|
5180
|
+
logger14.info(
|
|
5211
5181
|
{
|
|
5212
5182
|
toolName: tool4.name,
|
|
5213
5183
|
credentialReferenceId,
|
|
@@ -5247,7 +5217,7 @@ var Agent = class {
|
|
|
5247
5217
|
async getResolvedContext(conversationId, requestContext) {
|
|
5248
5218
|
try {
|
|
5249
5219
|
if (!this.config.contextConfigId) {
|
|
5250
|
-
|
|
5220
|
+
logger14.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
5251
5221
|
return null;
|
|
5252
5222
|
}
|
|
5253
5223
|
const contextConfig = await getContextConfigById(dbClient_default)({
|
|
@@ -5255,7 +5225,7 @@ var Agent = class {
|
|
|
5255
5225
|
id: this.config.contextConfigId
|
|
5256
5226
|
});
|
|
5257
5227
|
if (!contextConfig) {
|
|
5258
|
-
|
|
5228
|
+
logger14.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
5259
5229
|
return null;
|
|
5260
5230
|
}
|
|
5261
5231
|
if (!this.contextResolver) {
|
|
@@ -5272,7 +5242,7 @@ var Agent = class {
|
|
|
5272
5242
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5273
5243
|
$env: process.env
|
|
5274
5244
|
};
|
|
5275
|
-
|
|
5245
|
+
logger14.debug(
|
|
5276
5246
|
{
|
|
5277
5247
|
conversationId,
|
|
5278
5248
|
contextConfigId: contextConfig.id,
|
|
@@ -5286,7 +5256,7 @@ var Agent = class {
|
|
|
5286
5256
|
);
|
|
5287
5257
|
return contextWithBuiltins;
|
|
5288
5258
|
} catch (error) {
|
|
5289
|
-
|
|
5259
|
+
logger14.error(
|
|
5290
5260
|
{
|
|
5291
5261
|
conversationId,
|
|
5292
5262
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5310,7 +5280,7 @@ var Agent = class {
|
|
|
5310
5280
|
});
|
|
5311
5281
|
return graphDefinition?.graphPrompt || void 0;
|
|
5312
5282
|
} catch (error) {
|
|
5313
|
-
|
|
5283
|
+
logger14.warn(
|
|
5314
5284
|
{
|
|
5315
5285
|
graphId: this.config.graphId,
|
|
5316
5286
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5337,7 +5307,7 @@ var Agent = class {
|
|
|
5337
5307
|
}
|
|
5338
5308
|
return !!(graphDefinition.artifactComponents && Object.keys(graphDefinition.artifactComponents).length > 0);
|
|
5339
5309
|
} catch (error) {
|
|
5340
|
-
|
|
5310
|
+
logger14.warn(
|
|
5341
5311
|
{
|
|
5342
5312
|
graphId: this.config.graphId,
|
|
5343
5313
|
tenantId: this.config.tenantId,
|
|
@@ -5397,7 +5367,7 @@ Key requirements:
|
|
|
5397
5367
|
preserveUnresolved: false
|
|
5398
5368
|
});
|
|
5399
5369
|
} catch (error) {
|
|
5400
|
-
|
|
5370
|
+
logger14.error(
|
|
5401
5371
|
{
|
|
5402
5372
|
conversationId,
|
|
5403
5373
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5442,7 +5412,7 @@ Key requirements:
|
|
|
5442
5412
|
preserveUnresolved: false
|
|
5443
5413
|
});
|
|
5444
5414
|
} catch (error) {
|
|
5445
|
-
|
|
5415
|
+
logger14.error(
|
|
5446
5416
|
{
|
|
5447
5417
|
conversationId,
|
|
5448
5418
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5470,7 +5440,7 @@ Key requirements:
|
|
|
5470
5440
|
artifactId: z.string().describe("The unique identifier of the artifact to get.")
|
|
5471
5441
|
}),
|
|
5472
5442
|
execute: async ({ artifactId }) => {
|
|
5473
|
-
|
|
5443
|
+
logger14.info({ artifactId }, "get_artifact executed");
|
|
5474
5444
|
const artifact = await getLedgerArtifacts(dbClient_default)({
|
|
5475
5445
|
scopes: {
|
|
5476
5446
|
tenantId: this.config.tenantId,
|
|
@@ -5537,7 +5507,7 @@ Key requirements:
|
|
|
5537
5507
|
graphId: this.config.graphId
|
|
5538
5508
|
});
|
|
5539
5509
|
} catch (error) {
|
|
5540
|
-
|
|
5510
|
+
logger14.error(
|
|
5541
5511
|
{ error, graphId: this.config.graphId },
|
|
5542
5512
|
"Failed to check graph artifact components"
|
|
5543
5513
|
);
|
|
@@ -5641,7 +5611,7 @@ Key requirements:
|
|
|
5641
5611
|
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;
|
|
5642
5612
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
5643
5613
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
5644
|
-
|
|
5614
|
+
logger14.warn(
|
|
5645
5615
|
{
|
|
5646
5616
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
5647
5617
|
appliedTimeout: timeoutMs,
|
|
@@ -5683,7 +5653,7 @@ Key requirements:
|
|
|
5683
5653
|
}
|
|
5684
5654
|
);
|
|
5685
5655
|
} catch (error) {
|
|
5686
|
-
|
|
5656
|
+
logger14.debug("Failed to track agent reasoning");
|
|
5687
5657
|
}
|
|
5688
5658
|
}
|
|
5689
5659
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -5766,7 +5736,7 @@ Key requirements:
|
|
|
5766
5736
|
}
|
|
5767
5737
|
);
|
|
5768
5738
|
} catch (error) {
|
|
5769
|
-
|
|
5739
|
+
logger14.debug("Failed to track agent reasoning");
|
|
5770
5740
|
}
|
|
5771
5741
|
}
|
|
5772
5742
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -5811,7 +5781,7 @@ Key requirements:
|
|
|
5811
5781
|
return;
|
|
5812
5782
|
}
|
|
5813
5783
|
if (toolName === "save_artifact_tool" || toolName === "save_tool_result") {
|
|
5814
|
-
|
|
5784
|
+
logger14.info({ result }, "save_artifact_tool or save_tool_result");
|
|
5815
5785
|
if (result.output.artifacts) {
|
|
5816
5786
|
for (const artifact of result.output.artifacts) {
|
|
5817
5787
|
const artifactId = artifact?.artifactId || "N/A";
|
|
@@ -5996,7 +5966,7 @@ function parseEmbeddedJson(data) {
|
|
|
5996
5966
|
}
|
|
5997
5967
|
});
|
|
5998
5968
|
}
|
|
5999
|
-
var
|
|
5969
|
+
var logger15 = getLogger("generateTaskHandler");
|
|
6000
5970
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
6001
5971
|
return async (task) => {
|
|
6002
5972
|
try {
|
|
@@ -6046,7 +6016,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
6046
6016
|
agentId: config.agentId
|
|
6047
6017
|
})
|
|
6048
6018
|
]);
|
|
6049
|
-
|
|
6019
|
+
logger15.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
6050
6020
|
const agentPrompt = "prompt" in config.agentSchema ? config.agentSchema.prompt : "";
|
|
6051
6021
|
const models = "models" in config.agentSchema ? config.agentSchema.models : void 0;
|
|
6052
6022
|
const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
|
|
@@ -6146,7 +6116,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
6146
6116
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
6147
6117
|
if (taskIdMatch) {
|
|
6148
6118
|
contextId = taskIdMatch[1];
|
|
6149
|
-
|
|
6119
|
+
logger15.info(
|
|
6150
6120
|
{
|
|
6151
6121
|
taskId: task.id,
|
|
6152
6122
|
extractedContextId: contextId,
|
|
@@ -6162,7 +6132,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
6162
6132
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
6163
6133
|
agent.setDelegationStatus(isDelegation);
|
|
6164
6134
|
if (isDelegation) {
|
|
6165
|
-
|
|
6135
|
+
logger15.info(
|
|
6166
6136
|
{ agentId: config.agentId, taskId: task.id },
|
|
6167
6137
|
"Delegated agent - streaming disabled"
|
|
6168
6138
|
);
|
|
@@ -6366,7 +6336,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
6366
6336
|
const agentFrameworkBaseUrl = `${baseUrl}/agents`;
|
|
6367
6337
|
return hydrateGraph({ dbGraph, baseUrl: agentFrameworkBaseUrl, apiKey });
|
|
6368
6338
|
}
|
|
6369
|
-
getLogger
|
|
6339
|
+
getLogger("agents");
|
|
6370
6340
|
async function hydrateAgent({
|
|
6371
6341
|
dbAgent,
|
|
6372
6342
|
graphId,
|
|
@@ -6442,7 +6412,7 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
|
6442
6412
|
|
|
6443
6413
|
// src/routes/agents.ts
|
|
6444
6414
|
var app = new OpenAPIHono();
|
|
6445
|
-
var
|
|
6415
|
+
var logger16 = getLogger("agents");
|
|
6446
6416
|
app.openapi(
|
|
6447
6417
|
createRoute({
|
|
6448
6418
|
method: "get",
|
|
@@ -6480,7 +6450,7 @@ app.openapi(
|
|
|
6480
6450
|
tracestate: c.req.header("tracestate"),
|
|
6481
6451
|
baggage: c.req.header("baggage")
|
|
6482
6452
|
};
|
|
6483
|
-
|
|
6453
|
+
logger16.info(
|
|
6484
6454
|
{
|
|
6485
6455
|
otelHeaders,
|
|
6486
6456
|
path: c.req.path,
|
|
@@ -6491,7 +6461,7 @@ app.openapi(
|
|
|
6491
6461
|
const executionContext = getRequestExecutionContext(c);
|
|
6492
6462
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6493
6463
|
if (agentId) {
|
|
6494
|
-
|
|
6464
|
+
logger16.info(
|
|
6495
6465
|
{
|
|
6496
6466
|
message: "getRegisteredAgent (agent-level)",
|
|
6497
6467
|
tenantId,
|
|
@@ -6503,13 +6473,13 @@ app.openapi(
|
|
|
6503
6473
|
);
|
|
6504
6474
|
const credentialStores = c.get("credentialStores");
|
|
6505
6475
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
6506
|
-
|
|
6476
|
+
logger16.info({ agent }, "agent registered: well-known agent.json");
|
|
6507
6477
|
if (!agent) {
|
|
6508
6478
|
return c.json({ error: "Agent not found" }, 404);
|
|
6509
6479
|
}
|
|
6510
6480
|
return c.json(agent.agentCard);
|
|
6511
6481
|
} else {
|
|
6512
|
-
|
|
6482
|
+
logger16.info(
|
|
6513
6483
|
{
|
|
6514
6484
|
message: "getRegisteredGraph (graph-level)",
|
|
6515
6485
|
tenantId,
|
|
@@ -6532,7 +6502,7 @@ app.post("/a2a", async (c) => {
|
|
|
6532
6502
|
tracestate: c.req.header("tracestate"),
|
|
6533
6503
|
baggage: c.req.header("baggage")
|
|
6534
6504
|
};
|
|
6535
|
-
|
|
6505
|
+
logger16.info(
|
|
6536
6506
|
{
|
|
6537
6507
|
otelHeaders,
|
|
6538
6508
|
path: c.req.path,
|
|
@@ -6543,7 +6513,7 @@ app.post("/a2a", async (c) => {
|
|
|
6543
6513
|
const executionContext = getRequestExecutionContext(c);
|
|
6544
6514
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6545
6515
|
if (agentId) {
|
|
6546
|
-
|
|
6516
|
+
logger16.info(
|
|
6547
6517
|
{
|
|
6548
6518
|
message: "a2a (agent-level)",
|
|
6549
6519
|
tenantId,
|
|
@@ -6567,7 +6537,7 @@ app.post("/a2a", async (c) => {
|
|
|
6567
6537
|
}
|
|
6568
6538
|
return a2aHandler(c, agent);
|
|
6569
6539
|
} else {
|
|
6570
|
-
|
|
6540
|
+
logger16.info(
|
|
6571
6541
|
{
|
|
6572
6542
|
message: "a2a (graph-level)",
|
|
6573
6543
|
tenantId,
|
|
@@ -6607,14 +6577,14 @@ app.post("/a2a", async (c) => {
|
|
|
6607
6577
|
}
|
|
6608
6578
|
});
|
|
6609
6579
|
var agents_default = app;
|
|
6610
|
-
var
|
|
6580
|
+
var logger17 = getLogger("Transfer");
|
|
6611
6581
|
async function executeTransfer({
|
|
6612
6582
|
tenantId,
|
|
6613
6583
|
threadId,
|
|
6614
6584
|
projectId,
|
|
6615
6585
|
targetAgentId
|
|
6616
6586
|
}) {
|
|
6617
|
-
|
|
6587
|
+
logger17.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
6618
6588
|
await setActiveAgentForThread(dbClient_default)({
|
|
6619
6589
|
scopes: { tenantId, projectId },
|
|
6620
6590
|
threadId,
|
|
@@ -7155,7 +7125,7 @@ var MCPStreamHelper = class {
|
|
|
7155
7125
|
function createMCPStreamHelper() {
|
|
7156
7126
|
return new MCPStreamHelper();
|
|
7157
7127
|
}
|
|
7158
|
-
var
|
|
7128
|
+
var logger18 = getLogger("ExecutionHandler");
|
|
7159
7129
|
var ExecutionHandler = class {
|
|
7160
7130
|
constructor() {
|
|
7161
7131
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -7180,7 +7150,7 @@ var ExecutionHandler = class {
|
|
|
7180
7150
|
const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
|
|
7181
7151
|
registerStreamHelper(requestId2, sseHelper);
|
|
7182
7152
|
graphSessionManager.createSession(requestId2, graphId, tenantId, projectId);
|
|
7183
|
-
|
|
7153
|
+
logger18.info({ sessionId: requestId2, graphId }, "Created GraphSession for message execution");
|
|
7184
7154
|
let graphConfig = null;
|
|
7185
7155
|
try {
|
|
7186
7156
|
graphConfig = await getFullGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
|
|
@@ -7192,7 +7162,7 @@ var ExecutionHandler = class {
|
|
|
7192
7162
|
);
|
|
7193
7163
|
}
|
|
7194
7164
|
} catch (error) {
|
|
7195
|
-
|
|
7165
|
+
logger18.error(
|
|
7196
7166
|
{
|
|
7197
7167
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
7198
7168
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -7208,7 +7178,7 @@ var ExecutionHandler = class {
|
|
|
7208
7178
|
try {
|
|
7209
7179
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
7210
7180
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
7211
|
-
|
|
7181
|
+
logger18.info(
|
|
7212
7182
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
7213
7183
|
"Attempting to create or reuse existing task"
|
|
7214
7184
|
);
|
|
@@ -7231,7 +7201,7 @@ var ExecutionHandler = class {
|
|
|
7231
7201
|
agent_id: currentAgentId
|
|
7232
7202
|
}
|
|
7233
7203
|
});
|
|
7234
|
-
|
|
7204
|
+
logger18.info(
|
|
7235
7205
|
{
|
|
7236
7206
|
taskId,
|
|
7237
7207
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -7240,27 +7210,27 @@ var ExecutionHandler = class {
|
|
|
7240
7210
|
);
|
|
7241
7211
|
} catch (error) {
|
|
7242
7212
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
7243
|
-
|
|
7213
|
+
logger18.info(
|
|
7244
7214
|
{ taskId, error: error.message },
|
|
7245
7215
|
"Task already exists, fetching existing task"
|
|
7246
7216
|
);
|
|
7247
7217
|
const existingTask = await getTask(dbClient_default)({ id: taskId });
|
|
7248
7218
|
if (existingTask) {
|
|
7249
7219
|
task = existingTask;
|
|
7250
|
-
|
|
7220
|
+
logger18.info(
|
|
7251
7221
|
{ taskId, existingTask },
|
|
7252
7222
|
"Successfully reused existing task from race condition"
|
|
7253
7223
|
);
|
|
7254
7224
|
} else {
|
|
7255
|
-
|
|
7225
|
+
logger18.error({ taskId, error }, "Task constraint failed but task not found");
|
|
7256
7226
|
throw error;
|
|
7257
7227
|
}
|
|
7258
7228
|
} else {
|
|
7259
|
-
|
|
7229
|
+
logger18.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
7260
7230
|
throw error;
|
|
7261
7231
|
}
|
|
7262
7232
|
}
|
|
7263
|
-
|
|
7233
|
+
logger18.debug(
|
|
7264
7234
|
{
|
|
7265
7235
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7266
7236
|
executionType: "create_initial_task",
|
|
@@ -7278,7 +7248,7 @@ var ExecutionHandler = class {
|
|
|
7278
7248
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
7279
7249
|
while (iterations < maxTransfers) {
|
|
7280
7250
|
iterations++;
|
|
7281
|
-
|
|
7251
|
+
logger18.info(
|
|
7282
7252
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
7283
7253
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
7284
7254
|
);
|
|
@@ -7286,10 +7256,10 @@ var ExecutionHandler = class {
|
|
|
7286
7256
|
scopes: { tenantId, projectId },
|
|
7287
7257
|
conversationId
|
|
7288
7258
|
});
|
|
7289
|
-
|
|
7259
|
+
logger18.info({ activeAgent }, "activeAgent");
|
|
7290
7260
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
7291
7261
|
currentAgentId = activeAgent.activeAgentId;
|
|
7292
|
-
|
|
7262
|
+
logger18.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
7293
7263
|
}
|
|
7294
7264
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
7295
7265
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -7330,13 +7300,13 @@ var ExecutionHandler = class {
|
|
|
7330
7300
|
});
|
|
7331
7301
|
if (!messageResponse?.result) {
|
|
7332
7302
|
errorCount++;
|
|
7333
|
-
|
|
7303
|
+
logger18.error(
|
|
7334
7304
|
{ currentAgentId, iterations, errorCount },
|
|
7335
7305
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7336
7306
|
);
|
|
7337
7307
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7338
7308
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7339
|
-
|
|
7309
|
+
logger18.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7340
7310
|
await sseHelper.writeError(errorMessage2);
|
|
7341
7311
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7342
7312
|
if (task) {
|
|
@@ -7362,7 +7332,7 @@ var ExecutionHandler = class {
|
|
|
7362
7332
|
const transferResponse = messageResponse.result;
|
|
7363
7333
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
7364
7334
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
7365
|
-
|
|
7335
|
+
logger18.info({ targetAgentId, transferReason }, "transfer response");
|
|
7366
7336
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
7367
7337
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
7368
7338
|
projectId,
|
|
@@ -7373,7 +7343,7 @@ var ExecutionHandler = class {
|
|
|
7373
7343
|
if (success) {
|
|
7374
7344
|
fromAgentId = currentAgentId;
|
|
7375
7345
|
currentAgentId = newAgentId;
|
|
7376
|
-
|
|
7346
|
+
logger18.info(
|
|
7377
7347
|
{
|
|
7378
7348
|
transferFrom: fromAgentId,
|
|
7379
7349
|
transferTo: currentAgentId,
|
|
@@ -7391,7 +7361,7 @@ var ExecutionHandler = class {
|
|
|
7391
7361
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
7392
7362
|
if (graphSessionData) {
|
|
7393
7363
|
const sessionSummary = graphSessionData.getSummary();
|
|
7394
|
-
|
|
7364
|
+
logger18.info(sessionSummary, "GraphSession data after completion");
|
|
7395
7365
|
}
|
|
7396
7366
|
let textContent = "";
|
|
7397
7367
|
for (const part of responseParts) {
|
|
@@ -7446,32 +7416,32 @@ var ExecutionHandler = class {
|
|
|
7446
7416
|
}
|
|
7447
7417
|
});
|
|
7448
7418
|
const updateTaskEnd = Date.now();
|
|
7449
|
-
|
|
7419
|
+
logger18.info(
|
|
7450
7420
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
7451
7421
|
"Completed updateTask operation"
|
|
7452
7422
|
);
|
|
7453
7423
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
7454
7424
|
await sseHelper.complete();
|
|
7455
|
-
|
|
7425
|
+
logger18.info({}, "Ending GraphSession and cleaning up");
|
|
7456
7426
|
graphSessionManager.endSession(requestId2);
|
|
7457
|
-
|
|
7427
|
+
logger18.info({}, "Cleaning up streamHelper");
|
|
7458
7428
|
unregisterStreamHelper(requestId2);
|
|
7459
7429
|
let response;
|
|
7460
7430
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
7461
7431
|
const captured = sseHelper.getCapturedResponse();
|
|
7462
7432
|
response = captured.text || "No response content";
|
|
7463
7433
|
}
|
|
7464
|
-
|
|
7434
|
+
logger18.info({}, "ExecutionHandler returning success");
|
|
7465
7435
|
return { success: true, iterations, response };
|
|
7466
7436
|
}
|
|
7467
7437
|
errorCount++;
|
|
7468
|
-
|
|
7438
|
+
logger18.warn(
|
|
7469
7439
|
{ iterations, errorCount },
|
|
7470
7440
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7471
7441
|
);
|
|
7472
7442
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7473
7443
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7474
|
-
|
|
7444
|
+
logger18.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7475
7445
|
await sseHelper.writeError(errorMessage2);
|
|
7476
7446
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7477
7447
|
if (task) {
|
|
@@ -7493,7 +7463,7 @@ var ExecutionHandler = class {
|
|
|
7493
7463
|
}
|
|
7494
7464
|
}
|
|
7495
7465
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
7496
|
-
|
|
7466
|
+
logger18.error({ maxTransfers, iterations }, errorMessage);
|
|
7497
7467
|
await sseHelper.writeError(errorMessage);
|
|
7498
7468
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
7499
7469
|
if (task) {
|
|
@@ -7513,7 +7483,7 @@ var ExecutionHandler = class {
|
|
|
7513
7483
|
unregisterStreamHelper(requestId2);
|
|
7514
7484
|
return { success: false, error: errorMessage, iterations };
|
|
7515
7485
|
} catch (error) {
|
|
7516
|
-
|
|
7486
|
+
logger18.error({ error }, "Error in execution handler");
|
|
7517
7487
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
7518
7488
|
await sseHelper.writeError(`Execution error: ${errorMessage}`);
|
|
7519
7489
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
@@ -7539,7 +7509,7 @@ var ExecutionHandler = class {
|
|
|
7539
7509
|
|
|
7540
7510
|
// src/routes/chat.ts
|
|
7541
7511
|
var app2 = new OpenAPIHono();
|
|
7542
|
-
var
|
|
7512
|
+
var logger19 = getLogger("completionsHandler");
|
|
7543
7513
|
var chatCompletionsRoute = createRoute({
|
|
7544
7514
|
method: "post",
|
|
7545
7515
|
path: "/completions",
|
|
@@ -7657,7 +7627,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7657
7627
|
tracestate: c.req.header("tracestate"),
|
|
7658
7628
|
baggage: c.req.header("baggage")
|
|
7659
7629
|
};
|
|
7660
|
-
|
|
7630
|
+
logger19.info(
|
|
7661
7631
|
{
|
|
7662
7632
|
otelHeaders,
|
|
7663
7633
|
path: c.req.path,
|
|
@@ -7743,7 +7713,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7743
7713
|
dbClient_default,
|
|
7744
7714
|
credentialStores
|
|
7745
7715
|
);
|
|
7746
|
-
|
|
7716
|
+
logger19.info(
|
|
7747
7717
|
{
|
|
7748
7718
|
tenantId,
|
|
7749
7719
|
graphId,
|
|
@@ -7789,7 +7759,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7789
7759
|
return streamSSE(c, async (stream2) => {
|
|
7790
7760
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
7791
7761
|
await sseHelper.writeRole();
|
|
7792
|
-
|
|
7762
|
+
logger19.info({ agentId }, "Starting execution");
|
|
7793
7763
|
const executionHandler = new ExecutionHandler();
|
|
7794
7764
|
const result = await executionHandler.execute({
|
|
7795
7765
|
executionContext,
|
|
@@ -7799,7 +7769,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7799
7769
|
requestId: requestId2,
|
|
7800
7770
|
sseHelper
|
|
7801
7771
|
});
|
|
7802
|
-
|
|
7772
|
+
logger19.info(
|
|
7803
7773
|
{ result },
|
|
7804
7774
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
7805
7775
|
);
|
|
@@ -7832,7 +7802,7 @@ var getMessageText = (content) => {
|
|
|
7832
7802
|
};
|
|
7833
7803
|
var chat_default = app2;
|
|
7834
7804
|
var app3 = new OpenAPIHono();
|
|
7835
|
-
var
|
|
7805
|
+
var logger20 = getLogger("chatDataStream");
|
|
7836
7806
|
var chatDataStreamRoute = createRoute({
|
|
7837
7807
|
method: "post",
|
|
7838
7808
|
path: "/chat",
|
|
@@ -7937,7 +7907,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
7937
7907
|
);
|
|
7938
7908
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
7939
7909
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
7940
|
-
|
|
7910
|
+
logger20.info({ userText, lastUserMessage }, "userText");
|
|
7941
7911
|
const messageSpan = trace.getActiveSpan();
|
|
7942
7912
|
if (messageSpan) {
|
|
7943
7913
|
messageSpan.setAttributes({
|
|
@@ -7979,7 +7949,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
7979
7949
|
await streamHelper.writeError("Unable to process request");
|
|
7980
7950
|
}
|
|
7981
7951
|
} catch (err) {
|
|
7982
|
-
|
|
7952
|
+
logger20.error({ err }, "Streaming error");
|
|
7983
7953
|
await streamHelper.writeError("Internal server error");
|
|
7984
7954
|
} finally {
|
|
7985
7955
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -8000,7 +7970,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8000
7970
|
)
|
|
8001
7971
|
);
|
|
8002
7972
|
} catch (error) {
|
|
8003
|
-
|
|
7973
|
+
logger20.error({ error }, "chatDataStream error");
|
|
8004
7974
|
return c.json({ error: "Failed to process chat completion" }, 500);
|
|
8005
7975
|
}
|
|
8006
7976
|
});
|
|
@@ -8008,7 +7978,7 @@ var chatDataStream_default = app3;
|
|
|
8008
7978
|
function createMCPSchema(schema) {
|
|
8009
7979
|
return schema;
|
|
8010
7980
|
}
|
|
8011
|
-
var
|
|
7981
|
+
var logger21 = getLogger("mcp");
|
|
8012
7982
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
8013
7983
|
constructor() {
|
|
8014
7984
|
__publicField(this, "mockRes");
|
|
@@ -8063,21 +8033,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
8063
8033
|
id: 0
|
|
8064
8034
|
});
|
|
8065
8035
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
8066
|
-
|
|
8036
|
+
logger21.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
8067
8037
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
8068
8038
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
8069
8039
|
try {
|
|
8070
8040
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
8071
|
-
|
|
8041
|
+
logger21.info({ sessionId }, "Successfully spoofed initialization");
|
|
8072
8042
|
} catch (spoofError) {
|
|
8073
|
-
|
|
8043
|
+
logger21.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
8074
8044
|
}
|
|
8075
8045
|
};
|
|
8076
8046
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
8077
8047
|
const sessionId = req.headers["mcp-session-id"];
|
|
8078
|
-
|
|
8048
|
+
logger21.info({ sessionId }, "Received MCP session ID");
|
|
8079
8049
|
if (!sessionId) {
|
|
8080
|
-
|
|
8050
|
+
logger21.info({ body }, "Missing session ID");
|
|
8081
8051
|
res.writeHead(400).end(
|
|
8082
8052
|
JSON.stringify({
|
|
8083
8053
|
jsonrpc: "2.0",
|
|
@@ -8103,7 +8073,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8103
8073
|
scopes: { tenantId, projectId },
|
|
8104
8074
|
conversationId: sessionId
|
|
8105
8075
|
});
|
|
8106
|
-
|
|
8076
|
+
logger21.info(
|
|
8107
8077
|
{
|
|
8108
8078
|
sessionId,
|
|
8109
8079
|
conversationFound: !!conversation,
|
|
@@ -8114,7 +8084,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8114
8084
|
"Conversation lookup result"
|
|
8115
8085
|
);
|
|
8116
8086
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
8117
|
-
|
|
8087
|
+
logger21.info(
|
|
8118
8088
|
{ sessionId, conversationId: conversation?.id },
|
|
8119
8089
|
"MCP session not found or invalid"
|
|
8120
8090
|
);
|
|
@@ -8175,7 +8145,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
8175
8145
|
requestId: requestId2,
|
|
8176
8146
|
sseHelper: mcpStreamHelper
|
|
8177
8147
|
});
|
|
8178
|
-
|
|
8148
|
+
logger21.info(
|
|
8179
8149
|
{ result },
|
|
8180
8150
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8181
8151
|
);
|
|
@@ -8249,7 +8219,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
8249
8219
|
dbClient_default,
|
|
8250
8220
|
credentialStores
|
|
8251
8221
|
);
|
|
8252
|
-
|
|
8222
|
+
logger21.info(
|
|
8253
8223
|
{
|
|
8254
8224
|
tenantId,
|
|
8255
8225
|
graphId,
|
|
@@ -8310,7 +8280,7 @@ var validateRequestParameters = (c) => {
|
|
|
8310
8280
|
};
|
|
8311
8281
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
8312
8282
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8313
|
-
|
|
8283
|
+
logger21.info({ body }, "Received initialization request");
|
|
8314
8284
|
const sessionId = nanoid();
|
|
8315
8285
|
const agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
8316
8286
|
scopes: { tenantId, projectId },
|
|
@@ -8341,7 +8311,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8341
8311
|
}
|
|
8342
8312
|
}
|
|
8343
8313
|
});
|
|
8344
|
-
|
|
8314
|
+
logger21.info(
|
|
8345
8315
|
{ sessionId, conversationId: conversation.id },
|
|
8346
8316
|
"Created MCP session as conversation"
|
|
8347
8317
|
);
|
|
@@ -8350,9 +8320,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8350
8320
|
});
|
|
8351
8321
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
8352
8322
|
await server.connect(transport);
|
|
8353
|
-
|
|
8323
|
+
logger21.info({ sessionId }, "Server connected for initialization");
|
|
8354
8324
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
8355
|
-
|
|
8325
|
+
logger21.info(
|
|
8356
8326
|
{
|
|
8357
8327
|
sessionId,
|
|
8358
8328
|
bodyMethod: body?.method,
|
|
@@ -8361,7 +8331,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8361
8331
|
"About to handle initialization request"
|
|
8362
8332
|
);
|
|
8363
8333
|
await transport.handleRequest(req, res, body);
|
|
8364
|
-
|
|
8334
|
+
logger21.info({ sessionId }, "Successfully handled initialization request");
|
|
8365
8335
|
return toFetchResponse(res);
|
|
8366
8336
|
};
|
|
8367
8337
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -8389,8 +8359,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8389
8359
|
sessionId,
|
|
8390
8360
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
8391
8361
|
);
|
|
8392
|
-
|
|
8393
|
-
|
|
8362
|
+
logger21.info({ sessionId }, "Server connected and transport initialized");
|
|
8363
|
+
logger21.info(
|
|
8394
8364
|
{
|
|
8395
8365
|
sessionId,
|
|
8396
8366
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -8404,9 +8374,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8404
8374
|
);
|
|
8405
8375
|
try {
|
|
8406
8376
|
await transport.handleRequest(req, res, body);
|
|
8407
|
-
|
|
8377
|
+
logger21.info({ sessionId }, "Successfully handled MCP request");
|
|
8408
8378
|
} catch (transportError) {
|
|
8409
|
-
|
|
8379
|
+
logger21.error(
|
|
8410
8380
|
{
|
|
8411
8381
|
sessionId,
|
|
8412
8382
|
error: transportError,
|
|
@@ -8457,13 +8427,13 @@ app4.openapi(
|
|
|
8457
8427
|
}
|
|
8458
8428
|
const { executionContext } = paramValidation;
|
|
8459
8429
|
const body = await c.req.json();
|
|
8460
|
-
|
|
8430
|
+
logger21.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
8461
8431
|
const isInitRequest = body.method === "initialize";
|
|
8462
8432
|
const { req, res } = toReqRes(c.req.raw);
|
|
8463
8433
|
const validatedContext = c.get("validatedContext") || {};
|
|
8464
8434
|
const credentialStores = c.get("credentialStores");
|
|
8465
|
-
|
|
8466
|
-
|
|
8435
|
+
logger21.info({ validatedContext }, "Validated context");
|
|
8436
|
+
logger21.info({ req }, "request");
|
|
8467
8437
|
if (isInitRequest) {
|
|
8468
8438
|
return await handleInitializationRequest(
|
|
8469
8439
|
body,
|
|
@@ -8485,7 +8455,7 @@ app4.openapi(
|
|
|
8485
8455
|
);
|
|
8486
8456
|
}
|
|
8487
8457
|
} catch (e) {
|
|
8488
|
-
|
|
8458
|
+
logger21.error(
|
|
8489
8459
|
{
|
|
8490
8460
|
error: e instanceof Error ? e.message : e,
|
|
8491
8461
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -8497,7 +8467,7 @@ app4.openapi(
|
|
|
8497
8467
|
}
|
|
8498
8468
|
);
|
|
8499
8469
|
app4.get("/", async (c) => {
|
|
8500
|
-
|
|
8470
|
+
logger21.info({}, "Received GET MCP request");
|
|
8501
8471
|
return c.json(
|
|
8502
8472
|
{
|
|
8503
8473
|
jsonrpc: "2.0",
|
|
@@ -8511,7 +8481,7 @@ app4.get("/", async (c) => {
|
|
|
8511
8481
|
);
|
|
8512
8482
|
});
|
|
8513
8483
|
app4.delete("/", async (c) => {
|
|
8514
|
-
|
|
8484
|
+
logger21.info({}, "Received DELETE MCP request");
|
|
8515
8485
|
return c.json(
|
|
8516
8486
|
{
|
|
8517
8487
|
jsonrpc: "2.0",
|
|
@@ -8524,7 +8494,7 @@ app4.delete("/", async (c) => {
|
|
|
8524
8494
|
var mcp_default = app4;
|
|
8525
8495
|
|
|
8526
8496
|
// src/app.ts
|
|
8527
|
-
var
|
|
8497
|
+
var logger22 = getLogger("agents-run-api");
|
|
8528
8498
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
8529
8499
|
const app6 = new OpenAPIHono();
|
|
8530
8500
|
app6.use("*", requestId());
|
|
@@ -8548,7 +8518,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8548
8518
|
});
|
|
8549
8519
|
app6.use(
|
|
8550
8520
|
pinoLogger({
|
|
8551
|
-
pino:
|
|
8521
|
+
pino: logger22 || pino({ level: "debug" }),
|
|
8552
8522
|
http: {
|
|
8553
8523
|
onResLevel(c) {
|
|
8554
8524
|
if (c.res.status >= 500) {
|
|
@@ -8592,8 +8562,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8592
8562
|
if (!isExpectedError) {
|
|
8593
8563
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
8594
8564
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
8595
|
-
if (
|
|
8596
|
-
|
|
8565
|
+
if (logger22) {
|
|
8566
|
+
logger22.error(
|
|
8597
8567
|
{
|
|
8598
8568
|
error: err,
|
|
8599
8569
|
message: errorMessage,
|
|
@@ -8605,8 +8575,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8605
8575
|
);
|
|
8606
8576
|
}
|
|
8607
8577
|
} else {
|
|
8608
|
-
if (
|
|
8609
|
-
|
|
8578
|
+
if (logger22) {
|
|
8579
|
+
logger22.error(
|
|
8610
8580
|
{
|
|
8611
8581
|
error: err,
|
|
8612
8582
|
path: c.req.path,
|
|
@@ -8623,8 +8593,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8623
8593
|
const response = err.getResponse();
|
|
8624
8594
|
return response;
|
|
8625
8595
|
} catch (responseError) {
|
|
8626
|
-
if (
|
|
8627
|
-
|
|
8596
|
+
if (logger22) {
|
|
8597
|
+
logger22.error({ error: responseError }, "Error while handling HTTPException response");
|
|
8628
8598
|
}
|
|
8629
8599
|
}
|
|
8630
8600
|
}
|
|
@@ -8658,7 +8628,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8658
8628
|
app6.use("*", async (c, next) => {
|
|
8659
8629
|
const executionContext = c.get("executionContext");
|
|
8660
8630
|
if (!executionContext) {
|
|
8661
|
-
|
|
8631
|
+
logger22.debug({}, "Empty execution context");
|
|
8662
8632
|
return next();
|
|
8663
8633
|
}
|
|
8664
8634
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -8669,7 +8639,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8669
8639
|
const body = await cloned.json().catch(() => null);
|
|
8670
8640
|
conversationId = body?.conversationId;
|
|
8671
8641
|
} catch (_) {
|
|
8672
|
-
|
|
8642
|
+
logger22.debug({}, "Conversation ID not found in JSON body");
|
|
8673
8643
|
}
|
|
8674
8644
|
}
|
|
8675
8645
|
const entries = Object.fromEntries(
|
|
@@ -8684,7 +8654,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8684
8654
|
})
|
|
8685
8655
|
);
|
|
8686
8656
|
if (!Object.keys(entries).length) {
|
|
8687
|
-
|
|
8657
|
+
logger22.debug({}, "Empty entries for baggage");
|
|
8688
8658
|
return next();
|
|
8689
8659
|
}
|
|
8690
8660
|
const bag = Object.entries(entries).reduce(
|