@inkeep/agents-run-api 0.1.8 → 0.1.9
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 +265 -305
- package/dist/index.js +261 -296
- package/package.json +12 -13
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { env, __publicField, dbClient_default, getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-HO5J26MO.js';
|
|
2
2
|
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
3
3
|
import { BaggageSpanProcessor, ALLOW_ALL_BAGGAGE_KEYS } from '@opentelemetry/baggage-span-processor';
|
|
4
|
-
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-
|
|
4
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
5
5
|
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
6
|
-
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
7
|
+
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
8
|
+
import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
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';
|
|
9
11
|
import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
|
|
10
12
|
import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
|
|
13
|
+
import { Hono } from 'hono';
|
|
11
14
|
import { cors } from 'hono/cors';
|
|
12
15
|
import { HTTPException } from 'hono/http-exception';
|
|
13
16
|
import { requestId } from 'hono/request-id';
|
|
14
|
-
import { pinoLogger } from 'hono-pino';
|
|
15
|
-
import { pino } from 'pino';
|
|
16
|
-
import { AsyncLocalStorage } from 'async_hooks';
|
|
17
17
|
import { createMiddleware } from 'hono/factory';
|
|
18
18
|
import { swaggerUI } from '@hono/swagger-ui';
|
|
19
19
|
import z4, { z } from 'zod';
|
|
@@ -30,36 +30,18 @@ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/
|
|
|
30
30
|
import { z as z$2 } from 'zod/v3';
|
|
31
31
|
import { toReqRes, toFetchResponse } from 'fetch-to-node';
|
|
32
32
|
|
|
33
|
-
var otlpExporter = new OTLPTraceExporter();
|
|
34
|
-
var FanOutSpanProcessor = class {
|
|
35
|
-
constructor(inner) {
|
|
36
|
-
this.inner = inner;
|
|
37
|
-
}
|
|
38
|
-
onStart(span, parent) {
|
|
39
|
-
this.inner.forEach((p) => p.onStart(span, parent));
|
|
40
|
-
}
|
|
41
|
-
onEnd(span) {
|
|
42
|
-
this.inner.forEach((p) => p.onEnd(span));
|
|
43
|
-
}
|
|
44
|
-
forceFlush() {
|
|
45
|
-
return Promise.all(this.inner.map((p) => p.forceFlush?.())).then(() => {
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
shutdown() {
|
|
49
|
-
return Promise.all(this.inner.map((p) => p.shutdown?.())).then(() => {
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
33
|
var maxExportBatchSize = env.OTEL_MAX_EXPORT_BATCH_SIZE ?? (env.ENVIRONMENT === "development" ? 1 : 512);
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
]
|
|
34
|
+
var otlpExporter = new OTLPTraceExporter();
|
|
35
|
+
var batchProcessor = new BatchSpanProcessor(otlpExporter, {
|
|
36
|
+
maxExportBatchSize
|
|
37
|
+
});
|
|
38
|
+
var resource = resourceFromAttributes({
|
|
39
|
+
[ATTR_SERVICE_NAME]: "inkeep-agents-run-api"
|
|
40
|
+
});
|
|
60
41
|
var sdk = new NodeSDK({
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
resource,
|
|
43
|
+
contextManager: new AsyncLocalStorageContextManager(),
|
|
44
|
+
spanProcessors: [new BaggageSpanProcessor(ALLOW_ALL_BAGGAGE_KEYS), batchProcessor],
|
|
63
45
|
instrumentations: [
|
|
64
46
|
getNodeAutoInstrumentations({
|
|
65
47
|
"@opentelemetry/instrumentation-http": {
|
|
@@ -84,37 +66,6 @@ var sdk = new NodeSDK({
|
|
|
84
66
|
]
|
|
85
67
|
});
|
|
86
68
|
sdk.start();
|
|
87
|
-
var isDevelopment = env.ENVIRONMENT === "development";
|
|
88
|
-
var loggerConfig = {
|
|
89
|
-
level: env.LOG_LEVEL,
|
|
90
|
-
serializers: {
|
|
91
|
-
obj: (value) => ({ ...value })
|
|
92
|
-
},
|
|
93
|
-
redact: ["req.headers.authorization", 'req.headers["x-inkeep-admin-authentication"]'],
|
|
94
|
-
// Only use pino-pretty in development
|
|
95
|
-
...isDevelopment && {
|
|
96
|
-
transport: {
|
|
97
|
-
target: "pino-pretty",
|
|
98
|
-
options: {
|
|
99
|
-
sync: true,
|
|
100
|
-
destination: 1,
|
|
101
|
-
// stdout
|
|
102
|
-
colorize: true,
|
|
103
|
-
translateTime: "SYS:standard"
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var logger = pino(loggerConfig);
|
|
109
|
-
var asyncLocalStorage = new AsyncLocalStorage();
|
|
110
|
-
function getLogger(name) {
|
|
111
|
-
const store = asyncLocalStorage.getStore();
|
|
112
|
-
const reqId = store?.get("requestId") || void 0;
|
|
113
|
-
if (!reqId) {
|
|
114
|
-
return logger.child({ name });
|
|
115
|
-
}
|
|
116
|
-
return logger.child({ reqId, name });
|
|
117
|
-
}
|
|
118
69
|
|
|
119
70
|
// src/types/execution-context.ts
|
|
120
71
|
function createExecutionContext(params) {
|
|
@@ -130,7 +81,7 @@ function createExecutionContext(params) {
|
|
|
130
81
|
}
|
|
131
82
|
|
|
132
83
|
// src/middleware/api-key-auth.ts
|
|
133
|
-
var
|
|
84
|
+
var logger = getLogger("env-key-auth");
|
|
134
85
|
var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
135
86
|
if (c.req.method === "OPTIONS") {
|
|
136
87
|
await next();
|
|
@@ -147,7 +98,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
147
98
|
if (authHeader?.startsWith("Bearer ")) {
|
|
148
99
|
try {
|
|
149
100
|
executionContext = await extractContextFromApiKey(authHeader.substring(7));
|
|
150
|
-
|
|
101
|
+
logger.info({}, "Development/test environment - API key authenticated successfully");
|
|
151
102
|
} catch {
|
|
152
103
|
executionContext = createExecutionContext({
|
|
153
104
|
apiKey: "development",
|
|
@@ -158,7 +109,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
158
109
|
baseUrl,
|
|
159
110
|
agentId
|
|
160
111
|
});
|
|
161
|
-
|
|
112
|
+
logger.info(
|
|
162
113
|
{},
|
|
163
114
|
"Development/test environment - fallback to default context due to invalid API key"
|
|
164
115
|
);
|
|
@@ -173,7 +124,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
173
124
|
baseUrl,
|
|
174
125
|
agentId
|
|
175
126
|
});
|
|
176
|
-
|
|
127
|
+
logger.info(
|
|
177
128
|
{},
|
|
178
129
|
"Development/test environment - no API key provided, using default context"
|
|
179
130
|
);
|
|
@@ -205,13 +156,13 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
205
156
|
agentId
|
|
206
157
|
});
|
|
207
158
|
c.set("executionContext", executionContext);
|
|
208
|
-
|
|
159
|
+
logger.info({}, "Bypass secret authenticated successfully");
|
|
209
160
|
await next();
|
|
210
161
|
return;
|
|
211
162
|
} else if (apiKey) {
|
|
212
163
|
const executionContext = await extractContextFromApiKey(apiKey);
|
|
213
164
|
c.set("executionContext", executionContext);
|
|
214
|
-
|
|
165
|
+
logger.info({}, "API key authenticated successfully");
|
|
215
166
|
await next();
|
|
216
167
|
return;
|
|
217
168
|
} else {
|
|
@@ -228,7 +179,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
228
179
|
try {
|
|
229
180
|
const executionContext = await extractContextFromApiKey(apiKey);
|
|
230
181
|
c.set("executionContext", executionContext);
|
|
231
|
-
|
|
182
|
+
logger.debug(
|
|
232
183
|
{
|
|
233
184
|
tenantId: executionContext.tenantId,
|
|
234
185
|
projectId: executionContext.projectId,
|
|
@@ -241,7 +192,7 @@ var apiKeyAuth = () => createMiddleware(async (c, next) => {
|
|
|
241
192
|
if (error instanceof HTTPException) {
|
|
242
193
|
throw error;
|
|
243
194
|
}
|
|
244
|
-
|
|
195
|
+
logger.error({ error }, "API key authentication error");
|
|
245
196
|
throw new HTTPException(500, {
|
|
246
197
|
message: "Authentication failed"
|
|
247
198
|
});
|
|
@@ -294,10 +245,10 @@ function setupOpenAPIRoutes(app6) {
|
|
|
294
245
|
})
|
|
295
246
|
);
|
|
296
247
|
}
|
|
297
|
-
var
|
|
248
|
+
var logger2 = getLogger("a2aHandler");
|
|
298
249
|
async function a2aHandler(c, agent) {
|
|
299
250
|
try {
|
|
300
|
-
const rpcRequest =
|
|
251
|
+
const rpcRequest = c.get("requestBody");
|
|
301
252
|
if (rpcRequest.jsonrpc !== "2.0") {
|
|
302
253
|
return c.json({
|
|
303
254
|
jsonrpc: "2.0",
|
|
@@ -396,7 +347,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
396
347
|
messageId: task.id,
|
|
397
348
|
kind: "message"
|
|
398
349
|
});
|
|
399
|
-
|
|
350
|
+
logger2.warn(
|
|
400
351
|
{
|
|
401
352
|
taskId: task.id,
|
|
402
353
|
agentId: agent.agentId,
|
|
@@ -406,7 +357,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
406
357
|
);
|
|
407
358
|
}
|
|
408
359
|
} catch (error) {
|
|
409
|
-
|
|
360
|
+
logger2.error({ error, taskId: task.id }, "Failed to serialize message");
|
|
410
361
|
JSON.stringify({
|
|
411
362
|
error: "Failed to serialize message",
|
|
412
363
|
taskId: task.id,
|
|
@@ -414,7 +365,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
414
365
|
parts: [{ text: "Error in delegation", kind: "text" }]
|
|
415
366
|
});
|
|
416
367
|
}
|
|
417
|
-
|
|
368
|
+
logger2.info(
|
|
418
369
|
{
|
|
419
370
|
originalContextId: params.message.contextId,
|
|
420
371
|
taskContextId: task.context?.conversationId,
|
|
@@ -443,7 +394,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
443
394
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
444
395
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
445
396
|
});
|
|
446
|
-
|
|
397
|
+
logger2.info({ metadata: params.message.metadata }, "message metadata");
|
|
447
398
|
if (params.message.metadata?.fromAgentId || params.message.metadata?.fromExternalAgentId) {
|
|
448
399
|
const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
|
|
449
400
|
try {
|
|
@@ -468,7 +419,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
468
419
|
messageData.toAgentId = agent.agentId;
|
|
469
420
|
}
|
|
470
421
|
await createMessage(dbClient_default)(messageData);
|
|
471
|
-
|
|
422
|
+
logger2.info(
|
|
472
423
|
{
|
|
473
424
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
474
425
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
@@ -480,7 +431,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
480
431
|
"A2A message stored in database"
|
|
481
432
|
);
|
|
482
433
|
} catch (error) {
|
|
483
|
-
|
|
434
|
+
logger2.error(
|
|
484
435
|
{
|
|
485
436
|
error,
|
|
486
437
|
fromAgentId: params.message.metadata.fromAgentId,
|
|
@@ -517,7 +468,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
517
468
|
(part) => part.kind === "data" && part.data && typeof part.data === "object" && part.data.type === "transfer"
|
|
518
469
|
);
|
|
519
470
|
if (transferPart && transferPart.kind === "data" && transferPart.data) {
|
|
520
|
-
|
|
471
|
+
logger2.info({ transferPart }, "transferPart");
|
|
521
472
|
return c.json({
|
|
522
473
|
jsonrpc: "2.0",
|
|
523
474
|
result: {
|
|
@@ -935,10 +886,10 @@ function statusUpdateOp(ctx) {
|
|
|
935
886
|
ctx
|
|
936
887
|
};
|
|
937
888
|
}
|
|
938
|
-
var
|
|
889
|
+
var logger3 = getLogger("DataComponentSchema");
|
|
939
890
|
function jsonSchemaToZod(jsonSchema) {
|
|
940
891
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
941
|
-
|
|
892
|
+
logger3.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
942
893
|
return z.string();
|
|
943
894
|
}
|
|
944
895
|
switch (jsonSchema.type) {
|
|
@@ -965,7 +916,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
965
916
|
case "null":
|
|
966
917
|
return z.null();
|
|
967
918
|
default:
|
|
968
|
-
|
|
919
|
+
logger3.warn(
|
|
969
920
|
{
|
|
970
921
|
unsupportedType: jsonSchema.type,
|
|
971
922
|
schema: jsonSchema
|
|
@@ -1019,7 +970,7 @@ __publicField(_ArtifactReferenceSchema, "ARTIFACT_PROPS_SCHEMA", {
|
|
|
1019
970
|
required: ["artifact_id", "task_id"]
|
|
1020
971
|
});
|
|
1021
972
|
var ArtifactReferenceSchema = _ArtifactReferenceSchema;
|
|
1022
|
-
var
|
|
973
|
+
var logger4 = getLogger("ModelFactory");
|
|
1023
974
|
var _ModelFactory = class _ModelFactory {
|
|
1024
975
|
/**
|
|
1025
976
|
* Create a language model instance from configuration
|
|
@@ -1034,7 +985,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1034
985
|
const modelSettings = config;
|
|
1035
986
|
const modelString = modelSettings.model.trim();
|
|
1036
987
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1037
|
-
|
|
988
|
+
logger4.debug(
|
|
1038
989
|
{
|
|
1039
990
|
provider,
|
|
1040
991
|
model: modelName,
|
|
@@ -1055,7 +1006,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1055
1006
|
);
|
|
1056
1007
|
}
|
|
1057
1008
|
} catch (error) {
|
|
1058
|
-
|
|
1009
|
+
logger4.error(
|
|
1059
1010
|
{
|
|
1060
1011
|
provider,
|
|
1061
1012
|
model: modelName,
|
|
@@ -1078,7 +1029,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1078
1029
|
const [provider, ...modelParts] = modelString.split("/");
|
|
1079
1030
|
const normalizedProvider = provider.toLowerCase();
|
|
1080
1031
|
if (!_ModelFactory.SUPPORTED_PROVIDERS.includes(normalizedProvider)) {
|
|
1081
|
-
|
|
1032
|
+
logger4.warn(
|
|
1082
1033
|
{ provider: normalizedProvider, modelName: modelParts.join("/") },
|
|
1083
1034
|
"Unsupported provider detected, falling back to anthropic"
|
|
1084
1035
|
);
|
|
@@ -1107,14 +1058,14 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1107
1058
|
anthropicConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1108
1059
|
}
|
|
1109
1060
|
if (providerOptions?.gateway) {
|
|
1110
|
-
|
|
1061
|
+
logger4.info(
|
|
1111
1062
|
{ gateway: providerOptions.gateway },
|
|
1112
1063
|
"Setting up AI Gateway for Anthropic model"
|
|
1113
1064
|
);
|
|
1114
1065
|
Object.assign(anthropicConfig, providerOptions.gateway);
|
|
1115
1066
|
}
|
|
1116
1067
|
if (Object.keys(anthropicConfig).length > 0) {
|
|
1117
|
-
|
|
1068
|
+
logger4.info({ config: anthropicConfig }, "Applying custom Anthropic provider configuration");
|
|
1118
1069
|
const provider = createAnthropic(anthropicConfig);
|
|
1119
1070
|
return provider(modelName);
|
|
1120
1071
|
}
|
|
@@ -1129,11 +1080,11 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1129
1080
|
openaiConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1130
1081
|
}
|
|
1131
1082
|
if (providerOptions?.gateway) {
|
|
1132
|
-
|
|
1083
|
+
logger4.info({ gateway: providerOptions.gateway }, "Setting up AI Gateway for OpenAI model");
|
|
1133
1084
|
Object.assign(openaiConfig, providerOptions.gateway);
|
|
1134
1085
|
}
|
|
1135
1086
|
if (Object.keys(openaiConfig).length > 0) {
|
|
1136
|
-
|
|
1087
|
+
logger4.info({ config: openaiConfig }, "Applying custom OpenAI provider configuration");
|
|
1137
1088
|
const provider = createOpenAI(openaiConfig);
|
|
1138
1089
|
return provider(modelName);
|
|
1139
1090
|
}
|
|
@@ -1223,7 +1174,7 @@ function unregisterStreamHelper(requestId2) {
|
|
|
1223
1174
|
}
|
|
1224
1175
|
|
|
1225
1176
|
// src/utils/graph-session.ts
|
|
1226
|
-
var
|
|
1177
|
+
var logger5 = getLogger("GraphSession");
|
|
1227
1178
|
var GraphSession = class {
|
|
1228
1179
|
// Track scheduled timeouts for cleanup
|
|
1229
1180
|
constructor(sessionId, messageId, graphId, tenantId, projectId) {
|
|
@@ -1247,7 +1198,7 @@ var GraphSession = class {
|
|
|
1247
1198
|
__publicField(this, "MAX_PENDING_ARTIFACTS", 100);
|
|
1248
1199
|
// Prevent unbounded growth
|
|
1249
1200
|
__publicField(this, "scheduledTimeouts");
|
|
1250
|
-
|
|
1201
|
+
logger5.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
1251
1202
|
}
|
|
1252
1203
|
/**
|
|
1253
1204
|
* Initialize status updates for this session
|
|
@@ -1269,7 +1220,7 @@ var GraphSession = class {
|
|
|
1269
1220
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
1270
1221
|
this.statusUpdateTimer = setInterval(async () => {
|
|
1271
1222
|
if (!this.statusUpdateState || this.isEnded) {
|
|
1272
|
-
|
|
1223
|
+
logger5.debug(
|
|
1273
1224
|
{ sessionId: this.sessionId },
|
|
1274
1225
|
"Timer triggered but session already cleaned up or ended"
|
|
1275
1226
|
);
|
|
@@ -1281,7 +1232,7 @@ var GraphSession = class {
|
|
|
1281
1232
|
}
|
|
1282
1233
|
await this.checkAndSendTimeBasedUpdate();
|
|
1283
1234
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
1284
|
-
|
|
1235
|
+
logger5.info(
|
|
1285
1236
|
{
|
|
1286
1237
|
sessionId: this.sessionId,
|
|
1287
1238
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -1295,7 +1246,7 @@ var GraphSession = class {
|
|
|
1295
1246
|
*/
|
|
1296
1247
|
recordEvent(eventType, agentId, data) {
|
|
1297
1248
|
if (this.isEnded) {
|
|
1298
|
-
|
|
1249
|
+
logger5.debug(
|
|
1299
1250
|
{
|
|
1300
1251
|
sessionId: this.sessionId,
|
|
1301
1252
|
eventType,
|
|
@@ -1315,7 +1266,7 @@ var GraphSession = class {
|
|
|
1315
1266
|
if (eventType === "artifact_saved" && data.pendingGeneration) {
|
|
1316
1267
|
const artifactId = data.artifactId;
|
|
1317
1268
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
1318
|
-
|
|
1269
|
+
logger5.warn(
|
|
1319
1270
|
{
|
|
1320
1271
|
sessionId: this.sessionId,
|
|
1321
1272
|
artifactId,
|
|
@@ -1336,7 +1287,7 @@ var GraphSession = class {
|
|
|
1336
1287
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
1337
1288
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
1338
1289
|
this.pendingArtifacts.delete(artifactId);
|
|
1339
|
-
|
|
1290
|
+
logger5.error(
|
|
1340
1291
|
{
|
|
1341
1292
|
sessionId: this.sessionId,
|
|
1342
1293
|
artifactId,
|
|
@@ -1348,7 +1299,7 @@ var GraphSession = class {
|
|
|
1348
1299
|
"Artifact processing failed after max retries, giving up"
|
|
1349
1300
|
);
|
|
1350
1301
|
} else {
|
|
1351
|
-
|
|
1302
|
+
logger5.warn(
|
|
1352
1303
|
{
|
|
1353
1304
|
sessionId: this.sessionId,
|
|
1354
1305
|
artifactId,
|
|
@@ -1370,14 +1321,14 @@ var GraphSession = class {
|
|
|
1370
1321
|
*/
|
|
1371
1322
|
checkStatusUpdates() {
|
|
1372
1323
|
if (this.isEnded) {
|
|
1373
|
-
|
|
1324
|
+
logger5.debug(
|
|
1374
1325
|
{ sessionId: this.sessionId },
|
|
1375
1326
|
"Session has ended - skipping status update check"
|
|
1376
1327
|
);
|
|
1377
1328
|
return;
|
|
1378
1329
|
}
|
|
1379
1330
|
if (!this.statusUpdateState) {
|
|
1380
|
-
|
|
1331
|
+
logger5.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
1381
1332
|
return;
|
|
1382
1333
|
}
|
|
1383
1334
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -1388,11 +1339,11 @@ var GraphSession = class {
|
|
|
1388
1339
|
*/
|
|
1389
1340
|
async checkAndSendTimeBasedUpdate() {
|
|
1390
1341
|
if (this.isEnded) {
|
|
1391
|
-
|
|
1342
|
+
logger5.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
1392
1343
|
return;
|
|
1393
1344
|
}
|
|
1394
1345
|
if (!this.statusUpdateState) {
|
|
1395
|
-
|
|
1346
|
+
logger5.debug(
|
|
1396
1347
|
{ sessionId: this.sessionId },
|
|
1397
1348
|
"No status updates configured for time-based check"
|
|
1398
1349
|
);
|
|
@@ -1405,7 +1356,7 @@ var GraphSession = class {
|
|
|
1405
1356
|
try {
|
|
1406
1357
|
await this.generateAndSendUpdate();
|
|
1407
1358
|
} catch (error) {
|
|
1408
|
-
|
|
1359
|
+
logger5.error(
|
|
1409
1360
|
{
|
|
1410
1361
|
sessionId: this.sessionId,
|
|
1411
1362
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1498,29 +1449,29 @@ var GraphSession = class {
|
|
|
1498
1449
|
*/
|
|
1499
1450
|
async generateAndSendUpdate() {
|
|
1500
1451
|
if (this.isEnded) {
|
|
1501
|
-
|
|
1452
|
+
logger5.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
1502
1453
|
return;
|
|
1503
1454
|
}
|
|
1504
1455
|
if (this.isTextStreaming) {
|
|
1505
|
-
|
|
1456
|
+
logger5.debug(
|
|
1506
1457
|
{ sessionId: this.sessionId },
|
|
1507
1458
|
"Text is currently streaming - skipping status update"
|
|
1508
1459
|
);
|
|
1509
1460
|
return;
|
|
1510
1461
|
}
|
|
1511
1462
|
if (this.isGeneratingUpdate) {
|
|
1512
|
-
|
|
1463
|
+
logger5.debug(
|
|
1513
1464
|
{ sessionId: this.sessionId },
|
|
1514
1465
|
"Update already in progress - skipping duplicate generation"
|
|
1515
1466
|
);
|
|
1516
1467
|
return;
|
|
1517
1468
|
}
|
|
1518
1469
|
if (!this.statusUpdateState) {
|
|
1519
|
-
|
|
1470
|
+
logger5.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
1520
1471
|
return;
|
|
1521
1472
|
}
|
|
1522
1473
|
if (!this.graphId) {
|
|
1523
|
-
|
|
1474
|
+
logger5.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
1524
1475
|
return;
|
|
1525
1476
|
}
|
|
1526
1477
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -1533,7 +1484,7 @@ var GraphSession = class {
|
|
|
1533
1484
|
try {
|
|
1534
1485
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
1535
1486
|
if (!streamHelper) {
|
|
1536
|
-
|
|
1487
|
+
logger5.warn(
|
|
1537
1488
|
{ sessionId: this.sessionId },
|
|
1538
1489
|
"No stream helper found - cannot send status update"
|
|
1539
1490
|
);
|
|
@@ -1554,7 +1505,7 @@ var GraphSession = class {
|
|
|
1554
1505
|
if (result.operations && result.operations.length > 0) {
|
|
1555
1506
|
for (const op of result.operations) {
|
|
1556
1507
|
if (!op || !op.type || !op.data || Object.keys(op.data).length === 0) {
|
|
1557
|
-
|
|
1508
|
+
logger5.warn(
|
|
1558
1509
|
{
|
|
1559
1510
|
sessionId: this.sessionId,
|
|
1560
1511
|
operation: op
|
|
@@ -1607,7 +1558,7 @@ var GraphSession = class {
|
|
|
1607
1558
|
this.previousSummaries.shift();
|
|
1608
1559
|
}
|
|
1609
1560
|
if (!operation || !operation.type || !operation.ctx) {
|
|
1610
|
-
|
|
1561
|
+
logger5.warn(
|
|
1611
1562
|
{
|
|
1612
1563
|
sessionId: this.sessionId,
|
|
1613
1564
|
operation
|
|
@@ -1622,7 +1573,7 @@ var GraphSession = class {
|
|
|
1622
1573
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
1623
1574
|
}
|
|
1624
1575
|
} catch (error) {
|
|
1625
|
-
|
|
1576
|
+
logger5.error(
|
|
1626
1577
|
{
|
|
1627
1578
|
sessionId: this.sessionId,
|
|
1628
1579
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -1660,7 +1611,7 @@ var GraphSession = class {
|
|
|
1660
1611
|
this.releaseUpdateLock();
|
|
1661
1612
|
}
|
|
1662
1613
|
} catch (error) {
|
|
1663
|
-
|
|
1614
|
+
logger5.error(
|
|
1664
1615
|
{
|
|
1665
1616
|
sessionId: this.sessionId,
|
|
1666
1617
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1737,7 +1688,7 @@ User's Question/Context:
|
|
|
1737
1688
|
${conversationHistory}
|
|
1738
1689
|
` : "";
|
|
1739
1690
|
} catch (error) {
|
|
1740
|
-
|
|
1691
|
+
logger5.warn(
|
|
1741
1692
|
{ sessionId: this.sessionId, error },
|
|
1742
1693
|
"Failed to fetch conversation history for status update"
|
|
1743
1694
|
);
|
|
@@ -1789,7 +1740,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
1789
1740
|
return text.trim();
|
|
1790
1741
|
} catch (error) {
|
|
1791
1742
|
setSpanWithError(span, error);
|
|
1792
|
-
|
|
1743
|
+
logger5.error({ error }, "Failed to generate summary, using fallback");
|
|
1793
1744
|
return this.generateFallbackSummary(newEvents, elapsedTime);
|
|
1794
1745
|
} finally {
|
|
1795
1746
|
span.end();
|
|
@@ -1835,7 +1786,7 @@ User's Question/Context:
|
|
|
1835
1786
|
${conversationHistory}
|
|
1836
1787
|
` : "";
|
|
1837
1788
|
} catch (error) {
|
|
1838
|
-
|
|
1789
|
+
logger5.warn(
|
|
1839
1790
|
{ sessionId: this.sessionId, error },
|
|
1840
1791
|
"Failed to fetch conversation history for structured status update"
|
|
1841
1792
|
);
|
|
@@ -1934,7 +1885,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
1934
1885
|
return { operations };
|
|
1935
1886
|
} catch (error) {
|
|
1936
1887
|
setSpanWithError(span, error);
|
|
1937
|
-
|
|
1888
|
+
logger5.error({ error }, "Failed to generate structured update, using fallback");
|
|
1938
1889
|
return { operations: [] };
|
|
1939
1890
|
} finally {
|
|
1940
1891
|
span.end();
|
|
@@ -2261,7 +2212,7 @@ Make it specific and relevant.`;
|
|
|
2261
2212
|
taskId: artifactData.taskId,
|
|
2262
2213
|
artifacts: [artifactToSave]
|
|
2263
2214
|
});
|
|
2264
|
-
|
|
2215
|
+
logger5.info(
|
|
2265
2216
|
{
|
|
2266
2217
|
sessionId: this.sessionId,
|
|
2267
2218
|
artifactId: artifactData.artifactId,
|
|
@@ -2278,7 +2229,7 @@ Make it specific and relevant.`;
|
|
|
2278
2229
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
2279
2230
|
} catch (error) {
|
|
2280
2231
|
setSpanWithError(span, error);
|
|
2281
|
-
|
|
2232
|
+
logger5.error(
|
|
2282
2233
|
{
|
|
2283
2234
|
sessionId: this.sessionId,
|
|
2284
2235
|
artifactId: artifactData.artifactId,
|
|
@@ -2314,7 +2265,7 @@ Make it specific and relevant.`;
|
|
|
2314
2265
|
taskId: artifactData.taskId,
|
|
2315
2266
|
artifacts: [fallbackArtifact]
|
|
2316
2267
|
});
|
|
2317
|
-
|
|
2268
|
+
logger5.info(
|
|
2318
2269
|
{
|
|
2319
2270
|
sessionId: this.sessionId,
|
|
2320
2271
|
artifactId: artifactData.artifactId
|
|
@@ -2323,7 +2274,7 @@ Make it specific and relevant.`;
|
|
|
2323
2274
|
);
|
|
2324
2275
|
}
|
|
2325
2276
|
} catch (fallbackError) {
|
|
2326
|
-
|
|
2277
|
+
logger5.error(
|
|
2327
2278
|
{
|
|
2328
2279
|
sessionId: this.sessionId,
|
|
2329
2280
|
artifactId: artifactData.artifactId,
|
|
@@ -2350,7 +2301,7 @@ var GraphSessionManager = class {
|
|
|
2350
2301
|
const sessionId = messageId;
|
|
2351
2302
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId);
|
|
2352
2303
|
this.sessions.set(sessionId, session);
|
|
2353
|
-
|
|
2304
|
+
logger5.info({ sessionId, messageId, graphId, tenantId, projectId }, "GraphSession created");
|
|
2354
2305
|
return sessionId;
|
|
2355
2306
|
}
|
|
2356
2307
|
/**
|
|
@@ -2361,7 +2312,7 @@ var GraphSessionManager = class {
|
|
|
2361
2312
|
if (session) {
|
|
2362
2313
|
session.initializeStatusUpdates(config, summarizerModel);
|
|
2363
2314
|
} else {
|
|
2364
|
-
|
|
2315
|
+
logger5.error(
|
|
2365
2316
|
{
|
|
2366
2317
|
sessionId,
|
|
2367
2318
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -2382,7 +2333,7 @@ var GraphSessionManager = class {
|
|
|
2382
2333
|
recordEvent(sessionId, eventType, agentId, data) {
|
|
2383
2334
|
const session = this.sessions.get(sessionId);
|
|
2384
2335
|
if (!session) {
|
|
2385
|
-
|
|
2336
|
+
logger5.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
2386
2337
|
return;
|
|
2387
2338
|
}
|
|
2388
2339
|
session.recordEvent(eventType, agentId, data);
|
|
@@ -2393,12 +2344,12 @@ var GraphSessionManager = class {
|
|
|
2393
2344
|
endSession(sessionId) {
|
|
2394
2345
|
const session = this.sessions.get(sessionId);
|
|
2395
2346
|
if (!session) {
|
|
2396
|
-
|
|
2347
|
+
logger5.warn({ sessionId }, "Attempted to end non-existent session");
|
|
2397
2348
|
return [];
|
|
2398
2349
|
}
|
|
2399
2350
|
const events = session.getEvents();
|
|
2400
2351
|
const summary = session.getSummary();
|
|
2401
|
-
|
|
2352
|
+
logger5.info({ sessionId, summary }, "GraphSession ended");
|
|
2402
2353
|
session.cleanup();
|
|
2403
2354
|
this.sessions.delete(sessionId);
|
|
2404
2355
|
return events;
|
|
@@ -2424,7 +2375,7 @@ var GraphSessionManager = class {
|
|
|
2424
2375
|
}
|
|
2425
2376
|
};
|
|
2426
2377
|
var graphSessionManager = new GraphSessionManager();
|
|
2427
|
-
var
|
|
2378
|
+
var logger6 = getLogger("ArtifactParser");
|
|
2428
2379
|
var _ArtifactParser = class _ArtifactParser {
|
|
2429
2380
|
constructor(tenantId) {
|
|
2430
2381
|
this.tenantId = tenantId;
|
|
@@ -2490,7 +2441,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2490
2441
|
id: taskId
|
|
2491
2442
|
});
|
|
2492
2443
|
if (!task) {
|
|
2493
|
-
|
|
2444
|
+
logger6.warn({ taskId }, "Task not found when fetching artifacts");
|
|
2494
2445
|
continue;
|
|
2495
2446
|
}
|
|
2496
2447
|
const taskArtifacts = await getLedgerArtifacts(dbClient_default)({
|
|
@@ -2502,9 +2453,9 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2502
2453
|
artifacts.set(key, artifact);
|
|
2503
2454
|
}
|
|
2504
2455
|
}
|
|
2505
|
-
|
|
2456
|
+
logger6.debug({ contextId, count: artifacts.size }, "Loaded context artifacts");
|
|
2506
2457
|
} catch (error) {
|
|
2507
|
-
|
|
2458
|
+
logger6.error({ error, contextId }, "Error loading context artifacts");
|
|
2508
2459
|
}
|
|
2509
2460
|
return artifacts;
|
|
2510
2461
|
}
|
|
@@ -2607,7 +2558,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2607
2558
|
id: taskId
|
|
2608
2559
|
});
|
|
2609
2560
|
if (!task) {
|
|
2610
|
-
|
|
2561
|
+
logger6.warn({ taskId }, "Task not found when fetching artifact");
|
|
2611
2562
|
return null;
|
|
2612
2563
|
}
|
|
2613
2564
|
const artifacts = await getLedgerArtifacts(dbClient_default)({
|
|
@@ -2619,7 +2570,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2619
2570
|
return this.formatArtifactData(artifacts[0], artifactId, taskId);
|
|
2620
2571
|
}
|
|
2621
2572
|
} catch (error) {
|
|
2622
|
-
|
|
2573
|
+
logger6.warn({ artifactId, taskId, error }, "Failed to fetch artifact");
|
|
2623
2574
|
}
|
|
2624
2575
|
return null;
|
|
2625
2576
|
}
|
|
@@ -2659,7 +2610,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_ARTIFACT_REGEX", /<(a(r(t(i(f(a(c(t(:
|
|
|
2659
2610
|
var ArtifactParser = _ArtifactParser;
|
|
2660
2611
|
|
|
2661
2612
|
// src/utils/incremental-stream-parser.ts
|
|
2662
|
-
var
|
|
2613
|
+
var logger7 = getLogger("IncrementalStreamParser");
|
|
2663
2614
|
var IncrementalStreamParser = class {
|
|
2664
2615
|
constructor(streamHelper, tenantId, contextId) {
|
|
2665
2616
|
__publicField(this, "buffer", "");
|
|
@@ -2719,13 +2670,13 @@ var IncrementalStreamParser = class {
|
|
|
2719
2670
|
if (part.type === "tool-call-delta" && part.toolName === targetToolName) {
|
|
2720
2671
|
const delta = part.argsTextDelta || "";
|
|
2721
2672
|
if (jsonBuffer.length + delta.length > MAX_BUFFER_SIZE) {
|
|
2722
|
-
|
|
2673
|
+
logger7.warn("JSON buffer exceeded maximum size, truncating");
|
|
2723
2674
|
jsonBuffer = jsonBuffer.slice(-MAX_BUFFER_SIZE / 2);
|
|
2724
2675
|
}
|
|
2725
2676
|
jsonBuffer += delta;
|
|
2726
2677
|
for (const char of delta) {
|
|
2727
2678
|
if (componentBuffer.length > MAX_BUFFER_SIZE) {
|
|
2728
|
-
|
|
2679
|
+
logger7.warn("Component buffer exceeded maximum size, resetting");
|
|
2729
2680
|
componentBuffer = "";
|
|
2730
2681
|
depth = 0;
|
|
2731
2682
|
continue;
|
|
@@ -2740,7 +2691,7 @@ var IncrementalStreamParser = class {
|
|
|
2740
2691
|
if (componentMatch) {
|
|
2741
2692
|
const MAX_COMPONENT_SIZE = 1024 * 1024;
|
|
2742
2693
|
if (componentMatch[0].length > MAX_COMPONENT_SIZE) {
|
|
2743
|
-
|
|
2694
|
+
logger7.warn(
|
|
2744
2695
|
{
|
|
2745
2696
|
size: componentMatch[0].length,
|
|
2746
2697
|
maxSize: MAX_COMPONENT_SIZE
|
|
@@ -2753,7 +2704,7 @@ var IncrementalStreamParser = class {
|
|
|
2753
2704
|
try {
|
|
2754
2705
|
const component = JSON.parse(componentMatch[0]);
|
|
2755
2706
|
if (typeof component !== "object" || !component.id) {
|
|
2756
|
-
|
|
2707
|
+
logger7.warn("Invalid component structure, skipping");
|
|
2757
2708
|
componentBuffer = "";
|
|
2758
2709
|
continue;
|
|
2759
2710
|
}
|
|
@@ -2766,7 +2717,7 @@ var IncrementalStreamParser = class {
|
|
|
2766
2717
|
componentsStreamed++;
|
|
2767
2718
|
componentBuffer = "";
|
|
2768
2719
|
} catch (e) {
|
|
2769
|
-
|
|
2720
|
+
logger7.debug({ error: e }, "Failed to parse component, continuing to accumulate");
|
|
2770
2721
|
}
|
|
2771
2722
|
}
|
|
2772
2723
|
}
|
|
@@ -2783,7 +2734,7 @@ var IncrementalStreamParser = class {
|
|
|
2783
2734
|
break;
|
|
2784
2735
|
}
|
|
2785
2736
|
}
|
|
2786
|
-
|
|
2737
|
+
logger7.debug({ componentsStreamed }, "Finished streaming components");
|
|
2787
2738
|
}
|
|
2788
2739
|
/**
|
|
2789
2740
|
* Legacy method for backward compatibility - defaults to text processing
|
|
@@ -2927,7 +2878,7 @@ var IncrementalStreamParser = class {
|
|
|
2927
2878
|
};
|
|
2928
2879
|
|
|
2929
2880
|
// src/utils/response-formatter.ts
|
|
2930
|
-
var
|
|
2881
|
+
var logger8 = getLogger("ResponseFormatter");
|
|
2931
2882
|
var ResponseFormatter = class {
|
|
2932
2883
|
constructor(tenantId) {
|
|
2933
2884
|
__publicField(this, "artifactParser");
|
|
@@ -2958,7 +2909,7 @@ var ResponseFormatter = class {
|
|
|
2958
2909
|
return { parts };
|
|
2959
2910
|
} catch (error) {
|
|
2960
2911
|
setSpanWithError(span, error);
|
|
2961
|
-
|
|
2912
|
+
logger8.error({ error, responseObject }, "Error formatting object response");
|
|
2962
2913
|
return {
|
|
2963
2914
|
parts: [{ kind: "data", data: responseObject }]
|
|
2964
2915
|
};
|
|
@@ -3009,7 +2960,7 @@ var ResponseFormatter = class {
|
|
|
3009
2960
|
return { parts };
|
|
3010
2961
|
} catch (error) {
|
|
3011
2962
|
setSpanWithError(span, error);
|
|
3012
|
-
|
|
2963
|
+
logger8.error({ error, responseText }, "Error formatting response");
|
|
3013
2964
|
return { text: responseText };
|
|
3014
2965
|
} finally {
|
|
3015
2966
|
span.end();
|
|
@@ -3054,7 +3005,7 @@ var ResponseFormatter = class {
|
|
|
3054
3005
|
}
|
|
3055
3006
|
}
|
|
3056
3007
|
};
|
|
3057
|
-
var
|
|
3008
|
+
var logger9 = getLogger("ToolSessionManager");
|
|
3058
3009
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
3059
3010
|
// 5 minutes
|
|
3060
3011
|
constructor() {
|
|
@@ -3083,7 +3034,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3083
3034
|
createdAt: Date.now()
|
|
3084
3035
|
};
|
|
3085
3036
|
this.sessions.set(sessionId, session);
|
|
3086
|
-
|
|
3037
|
+
logger9.debug({ sessionId, tenantId, contextId, taskId }, "Created tool session");
|
|
3087
3038
|
return sessionId;
|
|
3088
3039
|
}
|
|
3089
3040
|
/**
|
|
@@ -3092,7 +3043,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3092
3043
|
recordToolResult(sessionId, toolResult) {
|
|
3093
3044
|
const session = this.sessions.get(sessionId);
|
|
3094
3045
|
if (!session) {
|
|
3095
|
-
|
|
3046
|
+
logger9.warn(
|
|
3096
3047
|
{ sessionId, toolCallId: toolResult.toolCallId },
|
|
3097
3048
|
"Tool result recorded for unknown session"
|
|
3098
3049
|
);
|
|
@@ -3106,12 +3057,12 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3106
3057
|
getToolResult(sessionId, toolCallId) {
|
|
3107
3058
|
const session = this.sessions.get(sessionId);
|
|
3108
3059
|
if (!session) {
|
|
3109
|
-
|
|
3060
|
+
logger9.warn({ sessionId, toolCallId }, "Requested tool result for unknown session");
|
|
3110
3061
|
return void 0;
|
|
3111
3062
|
}
|
|
3112
3063
|
const result = session.toolResults.get(toolCallId);
|
|
3113
3064
|
if (!result) {
|
|
3114
|
-
|
|
3065
|
+
logger9.warn(
|
|
3115
3066
|
{
|
|
3116
3067
|
sessionId,
|
|
3117
3068
|
toolCallId,
|
|
@@ -3150,10 +3101,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3150
3101
|
}
|
|
3151
3102
|
for (const sessionId of expiredSessions) {
|
|
3152
3103
|
this.sessions.delete(sessionId);
|
|
3153
|
-
|
|
3104
|
+
logger9.debug({ sessionId }, "Cleaned up expired tool session");
|
|
3154
3105
|
}
|
|
3155
3106
|
if (expiredSessions.length > 0) {
|
|
3156
|
-
|
|
3107
|
+
logger9.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
3157
3108
|
}
|
|
3158
3109
|
}
|
|
3159
3110
|
};
|
|
@@ -3162,7 +3113,7 @@ var ToolSessionManager = _ToolSessionManager;
|
|
|
3162
3113
|
var toolSessionManager = ToolSessionManager.getInstance();
|
|
3163
3114
|
|
|
3164
3115
|
// src/agents/artifactTools.ts
|
|
3165
|
-
var
|
|
3116
|
+
var logger10 = getLogger("artifactTools");
|
|
3166
3117
|
function buildKeyNestingMap(data, prefix = "", map = /* @__PURE__ */ new Map()) {
|
|
3167
3118
|
if (typeof data === "object" && data !== null) {
|
|
3168
3119
|
if (Array.isArray(data)) {
|
|
@@ -3383,7 +3334,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3383
3334
|
execute: async ({ toolCallId, baseSelector, propSelectors, ...rest }, _context) => {
|
|
3384
3335
|
const artifactType = "artifactType" in rest ? rest.artifactType : void 0;
|
|
3385
3336
|
if (!sessionId) {
|
|
3386
|
-
|
|
3337
|
+
logger10.warn({ toolCallId }, "No session ID provided to save_tool_result");
|
|
3387
3338
|
return {
|
|
3388
3339
|
saved: false,
|
|
3389
3340
|
error: `[toolCallId: ${toolCallId}] No session context available`,
|
|
@@ -3393,7 +3344,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3393
3344
|
}
|
|
3394
3345
|
const toolResult = toolSessionManager.getToolResult(sessionId, toolCallId);
|
|
3395
3346
|
if (!toolResult) {
|
|
3396
|
-
|
|
3347
|
+
logger10.warn({ toolCallId, sessionId }, "Tool result not found in session");
|
|
3397
3348
|
return {
|
|
3398
3349
|
saved: false,
|
|
3399
3350
|
error: `[toolCallId: ${toolCallId}] Tool result not found`,
|
|
@@ -3406,7 +3357,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3406
3357
|
const baseData = jmespath.search(parsedResult, baseSelector);
|
|
3407
3358
|
if (!baseData || Array.isArray(baseData) && baseData.length === 0) {
|
|
3408
3359
|
const debugInfo = analyzeSelectorFailure(parsedResult, baseSelector);
|
|
3409
|
-
|
|
3360
|
+
logger10.warn(
|
|
3410
3361
|
{
|
|
3411
3362
|
baseSelector,
|
|
3412
3363
|
toolCallId,
|
|
@@ -3449,7 +3400,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3449
3400
|
const fallbackValue = item[propName];
|
|
3450
3401
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3451
3402
|
extractedItem[propName] = fallbackValue;
|
|
3452
|
-
|
|
3403
|
+
logger10.info(
|
|
3453
3404
|
{ propName, propSelector, context },
|
|
3454
3405
|
`PropSelector failed, used fallback direct property access`
|
|
3455
3406
|
);
|
|
@@ -3461,7 +3412,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3461
3412
|
const fallbackValue = item[propName];
|
|
3462
3413
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3463
3414
|
extractedItem[propName] = fallbackValue;
|
|
3464
|
-
|
|
3415
|
+
logger10.warn(
|
|
3465
3416
|
{ propName, propSelector, context, error: error.message },
|
|
3466
3417
|
`PropSelector syntax error, used fallback direct property access`
|
|
3467
3418
|
);
|
|
@@ -3574,7 +3525,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3574
3525
|
warnings
|
|
3575
3526
|
};
|
|
3576
3527
|
} catch (error) {
|
|
3577
|
-
|
|
3528
|
+
logger10.error({ error, toolCallId, sessionId }, "Error processing save_tool_result");
|
|
3578
3529
|
return {
|
|
3579
3530
|
saved: false,
|
|
3580
3531
|
error: `[toolCallId: ${toolCallId}] ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
@@ -3586,7 +3537,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3586
3537
|
}
|
|
3587
3538
|
|
|
3588
3539
|
// src/a2a/client.ts
|
|
3589
|
-
var
|
|
3540
|
+
var logger11 = getLogger("a2aClient");
|
|
3590
3541
|
var DEFAULT_BACKOFF = {
|
|
3591
3542
|
initialInterval: 500,
|
|
3592
3543
|
maxInterval: 6e4,
|
|
@@ -3792,7 +3743,7 @@ var A2AClient = class {
|
|
|
3792
3743
|
try {
|
|
3793
3744
|
const res = await fn();
|
|
3794
3745
|
if (attempt > 0) {
|
|
3795
|
-
|
|
3746
|
+
logger11.info(
|
|
3796
3747
|
{
|
|
3797
3748
|
attempts: attempt + 1,
|
|
3798
3749
|
elapsedTime: Date.now() - start
|
|
@@ -3807,7 +3758,7 @@ var A2AClient = class {
|
|
|
3807
3758
|
}
|
|
3808
3759
|
const elapsed = Date.now() - start;
|
|
3809
3760
|
if (elapsed > maxElapsedTime) {
|
|
3810
|
-
|
|
3761
|
+
logger11.warn(
|
|
3811
3762
|
{
|
|
3812
3763
|
attempts: attempt + 1,
|
|
3813
3764
|
elapsedTime: elapsed,
|
|
@@ -3828,7 +3779,7 @@ var A2AClient = class {
|
|
|
3828
3779
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
3829
3780
|
}
|
|
3830
3781
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
3831
|
-
|
|
3782
|
+
logger11.info(
|
|
3832
3783
|
{
|
|
3833
3784
|
attempt: attempt + 1,
|
|
3834
3785
|
delayMs,
|
|
@@ -3913,7 +3864,7 @@ var A2AClient = class {
|
|
|
3913
3864
|
}
|
|
3914
3865
|
const rpcResponse = await httpResponse.json();
|
|
3915
3866
|
if (rpcResponse.id !== requestId2) {
|
|
3916
|
-
|
|
3867
|
+
logger11.warn(
|
|
3917
3868
|
{
|
|
3918
3869
|
method,
|
|
3919
3870
|
expectedId: requestId2,
|
|
@@ -4112,7 +4063,7 @@ var A2AClient = class {
|
|
|
4112
4063
|
try {
|
|
4113
4064
|
while (true) {
|
|
4114
4065
|
const { done, value } = await reader.read();
|
|
4115
|
-
|
|
4066
|
+
logger11.info({ done, value }, "parseA2ASseStream");
|
|
4116
4067
|
if (done) {
|
|
4117
4068
|
if (eventDataBuffer.trim()) {
|
|
4118
4069
|
const result = this._processSseEventData(
|
|
@@ -4199,7 +4150,7 @@ var A2AClient = class {
|
|
|
4199
4150
|
};
|
|
4200
4151
|
|
|
4201
4152
|
// src/agents/relationTools.ts
|
|
4202
|
-
var
|
|
4153
|
+
var logger12 = getLogger("relationships Tools");
|
|
4203
4154
|
var generateTransferToolDescription = (config) => {
|
|
4204
4155
|
return `Hand off the conversation to agent ${config.id}.
|
|
4205
4156
|
|
|
@@ -4237,7 +4188,7 @@ var createTransferToAgentTool = ({
|
|
|
4237
4188
|
"transfer.to_agent_id": transferConfig.id ?? "unknown"
|
|
4238
4189
|
});
|
|
4239
4190
|
}
|
|
4240
|
-
|
|
4191
|
+
logger12.info(
|
|
4241
4192
|
{
|
|
4242
4193
|
transferTo: transferConfig.id ?? "unknown",
|
|
4243
4194
|
fromAgent: callingAgentId
|
|
@@ -4385,7 +4336,7 @@ function createDelegateToAgentTool({
|
|
|
4385
4336
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
4386
4337
|
}
|
|
4387
4338
|
};
|
|
4388
|
-
|
|
4339
|
+
logger12.info({ messageToSend }, "messageToSend");
|
|
4389
4340
|
await createMessage(dbClient_default)({
|
|
4390
4341
|
id: nanoid(),
|
|
4391
4342
|
tenantId,
|
|
@@ -4447,7 +4398,7 @@ function createDelegateToAgentTool({
|
|
|
4447
4398
|
}
|
|
4448
4399
|
|
|
4449
4400
|
// src/agents/SystemPromptBuilder.ts
|
|
4450
|
-
var
|
|
4401
|
+
var logger13 = getLogger("SystemPromptBuilder");
|
|
4451
4402
|
var SystemPromptBuilder = class {
|
|
4452
4403
|
constructor(version, versionConfig) {
|
|
4453
4404
|
this.version = version;
|
|
@@ -4463,9 +4414,9 @@ var SystemPromptBuilder = class {
|
|
|
4463
4414
|
this.templates.set(name, content);
|
|
4464
4415
|
}
|
|
4465
4416
|
this.loaded = true;
|
|
4466
|
-
|
|
4417
|
+
logger13.debug(`Loaded ${this.templates.size} templates for version ${this.version}`);
|
|
4467
4418
|
} catch (error) {
|
|
4468
|
-
|
|
4419
|
+
logger13.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
4469
4420
|
throw new Error(`Template loading failed: ${error}`);
|
|
4470
4421
|
}
|
|
4471
4422
|
}
|
|
@@ -4867,7 +4818,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
4867
4818
|
return false;
|
|
4868
4819
|
};
|
|
4869
4820
|
}
|
|
4870
|
-
var
|
|
4821
|
+
var logger14 = getLogger("Agent");
|
|
4871
4822
|
var CONSTANTS = {
|
|
4872
4823
|
MAX_GENERATION_STEPS: 12,
|
|
4873
4824
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -5120,14 +5071,14 @@ var Agent = class {
|
|
|
5120
5071
|
for (const toolSet of tools) {
|
|
5121
5072
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
5122
5073
|
if (!isValidTool(originalTool)) {
|
|
5123
|
-
|
|
5074
|
+
logger14.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
5124
5075
|
continue;
|
|
5125
5076
|
}
|
|
5126
5077
|
const sessionWrappedTool = tool({
|
|
5127
5078
|
description: originalTool.description,
|
|
5128
5079
|
inputSchema: originalTool.inputSchema,
|
|
5129
5080
|
execute: async (args, { toolCallId }) => {
|
|
5130
|
-
|
|
5081
|
+
logger14.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
5131
5082
|
try {
|
|
5132
5083
|
const result = await originalTool.execute(args, { toolCallId });
|
|
5133
5084
|
toolSessionManager.recordToolResult(sessionId, {
|
|
@@ -5139,7 +5090,7 @@ var Agent = class {
|
|
|
5139
5090
|
});
|
|
5140
5091
|
return { result, toolCallId };
|
|
5141
5092
|
} catch (error) {
|
|
5142
|
-
|
|
5093
|
+
logger14.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
5143
5094
|
throw error;
|
|
5144
5095
|
}
|
|
5145
5096
|
}
|
|
@@ -5224,7 +5175,7 @@ var Agent = class {
|
|
|
5224
5175
|
selectedTools
|
|
5225
5176
|
};
|
|
5226
5177
|
}
|
|
5227
|
-
|
|
5178
|
+
logger14.info(
|
|
5228
5179
|
{
|
|
5229
5180
|
toolName: tool4.name,
|
|
5230
5181
|
credentialReferenceId,
|
|
@@ -5264,7 +5215,7 @@ var Agent = class {
|
|
|
5264
5215
|
async getResolvedContext(conversationId, requestContext) {
|
|
5265
5216
|
try {
|
|
5266
5217
|
if (!this.config.contextConfigId) {
|
|
5267
|
-
|
|
5218
|
+
logger14.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
5268
5219
|
return null;
|
|
5269
5220
|
}
|
|
5270
5221
|
const contextConfig = await getContextConfigById(dbClient_default)({
|
|
@@ -5272,7 +5223,7 @@ var Agent = class {
|
|
|
5272
5223
|
id: this.config.contextConfigId
|
|
5273
5224
|
});
|
|
5274
5225
|
if (!contextConfig) {
|
|
5275
|
-
|
|
5226
|
+
logger14.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
5276
5227
|
return null;
|
|
5277
5228
|
}
|
|
5278
5229
|
if (!this.contextResolver) {
|
|
@@ -5289,7 +5240,7 @@ var Agent = class {
|
|
|
5289
5240
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5290
5241
|
$env: process.env
|
|
5291
5242
|
};
|
|
5292
|
-
|
|
5243
|
+
logger14.debug(
|
|
5293
5244
|
{
|
|
5294
5245
|
conversationId,
|
|
5295
5246
|
contextConfigId: contextConfig.id,
|
|
@@ -5303,7 +5254,7 @@ var Agent = class {
|
|
|
5303
5254
|
);
|
|
5304
5255
|
return contextWithBuiltins;
|
|
5305
5256
|
} catch (error) {
|
|
5306
|
-
|
|
5257
|
+
logger14.error(
|
|
5307
5258
|
{
|
|
5308
5259
|
conversationId,
|
|
5309
5260
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5327,7 +5278,7 @@ var Agent = class {
|
|
|
5327
5278
|
});
|
|
5328
5279
|
return graphDefinition?.graphPrompt || void 0;
|
|
5329
5280
|
} catch (error) {
|
|
5330
|
-
|
|
5281
|
+
logger14.warn(
|
|
5331
5282
|
{
|
|
5332
5283
|
graphId: this.config.graphId,
|
|
5333
5284
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5354,7 +5305,7 @@ var Agent = class {
|
|
|
5354
5305
|
}
|
|
5355
5306
|
return !!(graphDefinition.artifactComponents && Object.keys(graphDefinition.artifactComponents).length > 0);
|
|
5356
5307
|
} catch (error) {
|
|
5357
|
-
|
|
5308
|
+
logger14.warn(
|
|
5358
5309
|
{
|
|
5359
5310
|
graphId: this.config.graphId,
|
|
5360
5311
|
tenantId: this.config.tenantId,
|
|
@@ -5414,7 +5365,7 @@ Key requirements:
|
|
|
5414
5365
|
preserveUnresolved: false
|
|
5415
5366
|
});
|
|
5416
5367
|
} catch (error) {
|
|
5417
|
-
|
|
5368
|
+
logger14.error(
|
|
5418
5369
|
{
|
|
5419
5370
|
conversationId,
|
|
5420
5371
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5459,7 +5410,7 @@ Key requirements:
|
|
|
5459
5410
|
preserveUnresolved: false
|
|
5460
5411
|
});
|
|
5461
5412
|
} catch (error) {
|
|
5462
|
-
|
|
5413
|
+
logger14.error(
|
|
5463
5414
|
{
|
|
5464
5415
|
conversationId,
|
|
5465
5416
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5487,7 +5438,7 @@ Key requirements:
|
|
|
5487
5438
|
artifactId: z.string().describe("The unique identifier of the artifact to get.")
|
|
5488
5439
|
}),
|
|
5489
5440
|
execute: async ({ artifactId }) => {
|
|
5490
|
-
|
|
5441
|
+
logger14.info({ artifactId }, "get_artifact executed");
|
|
5491
5442
|
const artifact = await getLedgerArtifacts(dbClient_default)({
|
|
5492
5443
|
scopes: {
|
|
5493
5444
|
tenantId: this.config.tenantId,
|
|
@@ -5554,7 +5505,7 @@ Key requirements:
|
|
|
5554
5505
|
graphId: this.config.graphId
|
|
5555
5506
|
});
|
|
5556
5507
|
} catch (error) {
|
|
5557
|
-
|
|
5508
|
+
logger14.error(
|
|
5558
5509
|
{ error, graphId: this.config.graphId },
|
|
5559
5510
|
"Failed to check graph artifact components"
|
|
5560
5511
|
);
|
|
@@ -5658,7 +5609,7 @@ Key requirements:
|
|
|
5658
5609
|
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;
|
|
5659
5610
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
5660
5611
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
5661
|
-
|
|
5612
|
+
logger14.warn(
|
|
5662
5613
|
{
|
|
5663
5614
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
5664
5615
|
appliedTimeout: timeoutMs,
|
|
@@ -5700,7 +5651,7 @@ Key requirements:
|
|
|
5700
5651
|
}
|
|
5701
5652
|
);
|
|
5702
5653
|
} catch (error) {
|
|
5703
|
-
|
|
5654
|
+
logger14.debug("Failed to track agent reasoning");
|
|
5704
5655
|
}
|
|
5705
5656
|
}
|
|
5706
5657
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -5783,7 +5734,7 @@ Key requirements:
|
|
|
5783
5734
|
}
|
|
5784
5735
|
);
|
|
5785
5736
|
} catch (error) {
|
|
5786
|
-
|
|
5737
|
+
logger14.debug("Failed to track agent reasoning");
|
|
5787
5738
|
}
|
|
5788
5739
|
}
|
|
5789
5740
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -5828,7 +5779,7 @@ Key requirements:
|
|
|
5828
5779
|
return;
|
|
5829
5780
|
}
|
|
5830
5781
|
if (toolName === "save_artifact_tool" || toolName === "save_tool_result") {
|
|
5831
|
-
|
|
5782
|
+
logger14.info({ result }, "save_artifact_tool or save_tool_result");
|
|
5832
5783
|
if (result.output.artifacts) {
|
|
5833
5784
|
for (const artifact of result.output.artifacts) {
|
|
5834
5785
|
const artifactId = artifact?.artifactId || "N/A";
|
|
@@ -6013,7 +5964,7 @@ function parseEmbeddedJson(data) {
|
|
|
6013
5964
|
}
|
|
6014
5965
|
});
|
|
6015
5966
|
}
|
|
6016
|
-
var
|
|
5967
|
+
var logger15 = getLogger("generateTaskHandler");
|
|
6017
5968
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
6018
5969
|
return async (task) => {
|
|
6019
5970
|
try {
|
|
@@ -6063,7 +6014,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
6063
6014
|
agentId: config.agentId
|
|
6064
6015
|
})
|
|
6065
6016
|
]);
|
|
6066
|
-
|
|
6017
|
+
logger15.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
6067
6018
|
const agentPrompt = "prompt" in config.agentSchema ? config.agentSchema.prompt : "";
|
|
6068
6019
|
const models = "models" in config.agentSchema ? config.agentSchema.models : void 0;
|
|
6069
6020
|
const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
|
|
@@ -6163,7 +6114,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
6163
6114
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
6164
6115
|
if (taskIdMatch) {
|
|
6165
6116
|
contextId = taskIdMatch[1];
|
|
6166
|
-
|
|
6117
|
+
logger15.info(
|
|
6167
6118
|
{
|
|
6168
6119
|
taskId: task.id,
|
|
6169
6120
|
extractedContextId: contextId,
|
|
@@ -6179,7 +6130,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
6179
6130
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
6180
6131
|
agent.setDelegationStatus(isDelegation);
|
|
6181
6132
|
if (isDelegation) {
|
|
6182
|
-
|
|
6133
|
+
logger15.info(
|
|
6183
6134
|
{ agentId: config.agentId, taskId: task.id },
|
|
6184
6135
|
"Delegated agent - streaming disabled"
|
|
6185
6136
|
);
|
|
@@ -6383,7 +6334,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
6383
6334
|
const agentFrameworkBaseUrl = `${baseUrl}/agents`;
|
|
6384
6335
|
return hydrateGraph({ dbGraph, baseUrl: agentFrameworkBaseUrl, apiKey });
|
|
6385
6336
|
}
|
|
6386
|
-
getLogger
|
|
6337
|
+
getLogger("agents");
|
|
6387
6338
|
async function hydrateAgent({
|
|
6388
6339
|
dbAgent,
|
|
6389
6340
|
graphId,
|
|
@@ -6459,7 +6410,7 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
|
6459
6410
|
|
|
6460
6411
|
// src/routes/agents.ts
|
|
6461
6412
|
var app = new OpenAPIHono();
|
|
6462
|
-
var
|
|
6413
|
+
var logger16 = getLogger("agents");
|
|
6463
6414
|
app.openapi(
|
|
6464
6415
|
createRoute({
|
|
6465
6416
|
method: "get",
|
|
@@ -6497,7 +6448,7 @@ app.openapi(
|
|
|
6497
6448
|
tracestate: c.req.header("tracestate"),
|
|
6498
6449
|
baggage: c.req.header("baggage")
|
|
6499
6450
|
};
|
|
6500
|
-
|
|
6451
|
+
logger16.info(
|
|
6501
6452
|
{
|
|
6502
6453
|
otelHeaders,
|
|
6503
6454
|
path: c.req.path,
|
|
@@ -6508,7 +6459,7 @@ app.openapi(
|
|
|
6508
6459
|
const executionContext = getRequestExecutionContext(c);
|
|
6509
6460
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6510
6461
|
if (agentId) {
|
|
6511
|
-
|
|
6462
|
+
logger16.info(
|
|
6512
6463
|
{
|
|
6513
6464
|
message: "getRegisteredAgent (agent-level)",
|
|
6514
6465
|
tenantId,
|
|
@@ -6520,13 +6471,13 @@ app.openapi(
|
|
|
6520
6471
|
);
|
|
6521
6472
|
const credentialStores = c.get("credentialStores");
|
|
6522
6473
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
6523
|
-
|
|
6474
|
+
logger16.info({ agent }, "agent registered: well-known agent.json");
|
|
6524
6475
|
if (!agent) {
|
|
6525
6476
|
return c.json({ error: "Agent not found" }, 404);
|
|
6526
6477
|
}
|
|
6527
6478
|
return c.json(agent.agentCard);
|
|
6528
6479
|
} else {
|
|
6529
|
-
|
|
6480
|
+
logger16.info(
|
|
6530
6481
|
{
|
|
6531
6482
|
message: "getRegisteredGraph (graph-level)",
|
|
6532
6483
|
tenantId,
|
|
@@ -6549,7 +6500,7 @@ app.post("/a2a", async (c) => {
|
|
|
6549
6500
|
tracestate: c.req.header("tracestate"),
|
|
6550
6501
|
baggage: c.req.header("baggage")
|
|
6551
6502
|
};
|
|
6552
|
-
|
|
6503
|
+
logger16.info(
|
|
6553
6504
|
{
|
|
6554
6505
|
otelHeaders,
|
|
6555
6506
|
path: c.req.path,
|
|
@@ -6560,7 +6511,7 @@ app.post("/a2a", async (c) => {
|
|
|
6560
6511
|
const executionContext = getRequestExecutionContext(c);
|
|
6561
6512
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6562
6513
|
if (agentId) {
|
|
6563
|
-
|
|
6514
|
+
logger16.info(
|
|
6564
6515
|
{
|
|
6565
6516
|
message: "a2a (agent-level)",
|
|
6566
6517
|
tenantId,
|
|
@@ -6584,7 +6535,7 @@ app.post("/a2a", async (c) => {
|
|
|
6584
6535
|
}
|
|
6585
6536
|
return a2aHandler(c, agent);
|
|
6586
6537
|
} else {
|
|
6587
|
-
|
|
6538
|
+
logger16.info(
|
|
6588
6539
|
{
|
|
6589
6540
|
message: "a2a (graph-level)",
|
|
6590
6541
|
tenantId,
|
|
@@ -6624,14 +6575,14 @@ app.post("/a2a", async (c) => {
|
|
|
6624
6575
|
}
|
|
6625
6576
|
});
|
|
6626
6577
|
var agents_default = app;
|
|
6627
|
-
var
|
|
6578
|
+
var logger17 = getLogger("Transfer");
|
|
6628
6579
|
async function executeTransfer({
|
|
6629
6580
|
tenantId,
|
|
6630
6581
|
threadId,
|
|
6631
6582
|
projectId,
|
|
6632
6583
|
targetAgentId
|
|
6633
6584
|
}) {
|
|
6634
|
-
|
|
6585
|
+
logger17.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
6635
6586
|
await setActiveAgentForThread(dbClient_default)({
|
|
6636
6587
|
scopes: { tenantId, projectId },
|
|
6637
6588
|
threadId,
|
|
@@ -7172,7 +7123,7 @@ var MCPStreamHelper = class {
|
|
|
7172
7123
|
function createMCPStreamHelper() {
|
|
7173
7124
|
return new MCPStreamHelper();
|
|
7174
7125
|
}
|
|
7175
|
-
var
|
|
7126
|
+
var logger18 = getLogger("ExecutionHandler");
|
|
7176
7127
|
var ExecutionHandler = class {
|
|
7177
7128
|
constructor() {
|
|
7178
7129
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -7197,7 +7148,7 @@ var ExecutionHandler = class {
|
|
|
7197
7148
|
const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
|
|
7198
7149
|
registerStreamHelper(requestId2, sseHelper);
|
|
7199
7150
|
graphSessionManager.createSession(requestId2, graphId, tenantId, projectId);
|
|
7200
|
-
|
|
7151
|
+
logger18.info({ sessionId: requestId2, graphId }, "Created GraphSession for message execution");
|
|
7201
7152
|
let graphConfig = null;
|
|
7202
7153
|
try {
|
|
7203
7154
|
graphConfig = await getFullGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
|
|
@@ -7209,7 +7160,7 @@ var ExecutionHandler = class {
|
|
|
7209
7160
|
);
|
|
7210
7161
|
}
|
|
7211
7162
|
} catch (error) {
|
|
7212
|
-
|
|
7163
|
+
logger18.error(
|
|
7213
7164
|
{
|
|
7214
7165
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
7215
7166
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -7225,7 +7176,7 @@ var ExecutionHandler = class {
|
|
|
7225
7176
|
try {
|
|
7226
7177
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
7227
7178
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
7228
|
-
|
|
7179
|
+
logger18.info(
|
|
7229
7180
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
7230
7181
|
"Attempting to create or reuse existing task"
|
|
7231
7182
|
);
|
|
@@ -7248,7 +7199,7 @@ var ExecutionHandler = class {
|
|
|
7248
7199
|
agent_id: currentAgentId
|
|
7249
7200
|
}
|
|
7250
7201
|
});
|
|
7251
|
-
|
|
7202
|
+
logger18.info(
|
|
7252
7203
|
{
|
|
7253
7204
|
taskId,
|
|
7254
7205
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -7257,27 +7208,27 @@ var ExecutionHandler = class {
|
|
|
7257
7208
|
);
|
|
7258
7209
|
} catch (error) {
|
|
7259
7210
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
7260
|
-
|
|
7211
|
+
logger18.info(
|
|
7261
7212
|
{ taskId, error: error.message },
|
|
7262
7213
|
"Task already exists, fetching existing task"
|
|
7263
7214
|
);
|
|
7264
7215
|
const existingTask = await getTask(dbClient_default)({ id: taskId });
|
|
7265
7216
|
if (existingTask) {
|
|
7266
7217
|
task = existingTask;
|
|
7267
|
-
|
|
7218
|
+
logger18.info(
|
|
7268
7219
|
{ taskId, existingTask },
|
|
7269
7220
|
"Successfully reused existing task from race condition"
|
|
7270
7221
|
);
|
|
7271
7222
|
} else {
|
|
7272
|
-
|
|
7223
|
+
logger18.error({ taskId, error }, "Task constraint failed but task not found");
|
|
7273
7224
|
throw error;
|
|
7274
7225
|
}
|
|
7275
7226
|
} else {
|
|
7276
|
-
|
|
7227
|
+
logger18.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
7277
7228
|
throw error;
|
|
7278
7229
|
}
|
|
7279
7230
|
}
|
|
7280
|
-
|
|
7231
|
+
logger18.debug(
|
|
7281
7232
|
{
|
|
7282
7233
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7283
7234
|
executionType: "create_initial_task",
|
|
@@ -7295,7 +7246,7 @@ var ExecutionHandler = class {
|
|
|
7295
7246
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
7296
7247
|
while (iterations < maxTransfers) {
|
|
7297
7248
|
iterations++;
|
|
7298
|
-
|
|
7249
|
+
logger18.info(
|
|
7299
7250
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
7300
7251
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
7301
7252
|
);
|
|
@@ -7303,10 +7254,10 @@ var ExecutionHandler = class {
|
|
|
7303
7254
|
scopes: { tenantId, projectId },
|
|
7304
7255
|
conversationId
|
|
7305
7256
|
});
|
|
7306
|
-
|
|
7257
|
+
logger18.info({ activeAgent }, "activeAgent");
|
|
7307
7258
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
7308
7259
|
currentAgentId = activeAgent.activeAgentId;
|
|
7309
|
-
|
|
7260
|
+
logger18.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
7310
7261
|
}
|
|
7311
7262
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
7312
7263
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -7347,13 +7298,13 @@ var ExecutionHandler = class {
|
|
|
7347
7298
|
});
|
|
7348
7299
|
if (!messageResponse?.result) {
|
|
7349
7300
|
errorCount++;
|
|
7350
|
-
|
|
7301
|
+
logger18.error(
|
|
7351
7302
|
{ currentAgentId, iterations, errorCount },
|
|
7352
7303
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7353
7304
|
);
|
|
7354
7305
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7355
7306
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7356
|
-
|
|
7307
|
+
logger18.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7357
7308
|
await sseHelper.writeError(errorMessage2);
|
|
7358
7309
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7359
7310
|
if (task) {
|
|
@@ -7379,7 +7330,7 @@ var ExecutionHandler = class {
|
|
|
7379
7330
|
const transferResponse = messageResponse.result;
|
|
7380
7331
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
7381
7332
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
7382
|
-
|
|
7333
|
+
logger18.info({ targetAgentId, transferReason }, "transfer response");
|
|
7383
7334
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
7384
7335
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
7385
7336
|
projectId,
|
|
@@ -7390,7 +7341,7 @@ var ExecutionHandler = class {
|
|
|
7390
7341
|
if (success) {
|
|
7391
7342
|
fromAgentId = currentAgentId;
|
|
7392
7343
|
currentAgentId = newAgentId;
|
|
7393
|
-
|
|
7344
|
+
logger18.info(
|
|
7394
7345
|
{
|
|
7395
7346
|
transferFrom: fromAgentId,
|
|
7396
7347
|
transferTo: currentAgentId,
|
|
@@ -7408,7 +7359,7 @@ var ExecutionHandler = class {
|
|
|
7408
7359
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
7409
7360
|
if (graphSessionData) {
|
|
7410
7361
|
const sessionSummary = graphSessionData.getSummary();
|
|
7411
|
-
|
|
7362
|
+
logger18.info(sessionSummary, "GraphSession data after completion");
|
|
7412
7363
|
}
|
|
7413
7364
|
let textContent = "";
|
|
7414
7365
|
for (const part of responseParts) {
|
|
@@ -7463,32 +7414,32 @@ var ExecutionHandler = class {
|
|
|
7463
7414
|
}
|
|
7464
7415
|
});
|
|
7465
7416
|
const updateTaskEnd = Date.now();
|
|
7466
|
-
|
|
7417
|
+
logger18.info(
|
|
7467
7418
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
7468
7419
|
"Completed updateTask operation"
|
|
7469
7420
|
);
|
|
7470
7421
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
7471
7422
|
await sseHelper.complete();
|
|
7472
|
-
|
|
7423
|
+
logger18.info({}, "Ending GraphSession and cleaning up");
|
|
7473
7424
|
graphSessionManager.endSession(requestId2);
|
|
7474
|
-
|
|
7425
|
+
logger18.info({}, "Cleaning up streamHelper");
|
|
7475
7426
|
unregisterStreamHelper(requestId2);
|
|
7476
7427
|
let response;
|
|
7477
7428
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
7478
7429
|
const captured = sseHelper.getCapturedResponse();
|
|
7479
7430
|
response = captured.text || "No response content";
|
|
7480
7431
|
}
|
|
7481
|
-
|
|
7432
|
+
logger18.info({}, "ExecutionHandler returning success");
|
|
7482
7433
|
return { success: true, iterations, response };
|
|
7483
7434
|
}
|
|
7484
7435
|
errorCount++;
|
|
7485
|
-
|
|
7436
|
+
logger18.warn(
|
|
7486
7437
|
{ iterations, errorCount },
|
|
7487
7438
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7488
7439
|
);
|
|
7489
7440
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7490
7441
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7491
|
-
|
|
7442
|
+
logger18.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7492
7443
|
await sseHelper.writeError(errorMessage2);
|
|
7493
7444
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7494
7445
|
if (task) {
|
|
@@ -7510,7 +7461,7 @@ var ExecutionHandler = class {
|
|
|
7510
7461
|
}
|
|
7511
7462
|
}
|
|
7512
7463
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
7513
|
-
|
|
7464
|
+
logger18.error({ maxTransfers, iterations }, errorMessage);
|
|
7514
7465
|
await sseHelper.writeError(errorMessage);
|
|
7515
7466
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
7516
7467
|
if (task) {
|
|
@@ -7530,7 +7481,7 @@ var ExecutionHandler = class {
|
|
|
7530
7481
|
unregisterStreamHelper(requestId2);
|
|
7531
7482
|
return { success: false, error: errorMessage, iterations };
|
|
7532
7483
|
} catch (error) {
|
|
7533
|
-
|
|
7484
|
+
logger18.error({ error }, "Error in execution handler");
|
|
7534
7485
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
7535
7486
|
await sseHelper.writeError(`Execution error: ${errorMessage}`);
|
|
7536
7487
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
@@ -7556,7 +7507,7 @@ var ExecutionHandler = class {
|
|
|
7556
7507
|
|
|
7557
7508
|
// src/routes/chat.ts
|
|
7558
7509
|
var app2 = new OpenAPIHono();
|
|
7559
|
-
var
|
|
7510
|
+
var logger19 = getLogger("completionsHandler");
|
|
7560
7511
|
var chatCompletionsRoute = createRoute({
|
|
7561
7512
|
method: "post",
|
|
7562
7513
|
path: "/completions",
|
|
@@ -7674,7 +7625,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7674
7625
|
tracestate: c.req.header("tracestate"),
|
|
7675
7626
|
baggage: c.req.header("baggage")
|
|
7676
7627
|
};
|
|
7677
|
-
|
|
7628
|
+
logger19.info(
|
|
7678
7629
|
{
|
|
7679
7630
|
otelHeaders,
|
|
7680
7631
|
path: c.req.path,
|
|
@@ -7692,7 +7643,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7692
7643
|
},
|
|
7693
7644
|
"Extracted chat parameters from API key context"
|
|
7694
7645
|
);
|
|
7695
|
-
const body = c.
|
|
7646
|
+
const body = c.get("requestBody") || {};
|
|
7696
7647
|
const conversationId = body.conversationId || nanoid();
|
|
7697
7648
|
const fullGraph = await getFullGraph(dbClient_default)({
|
|
7698
7649
|
scopes: { tenantId, projectId },
|
|
@@ -7760,7 +7711,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7760
7711
|
dbClient_default,
|
|
7761
7712
|
credentialStores
|
|
7762
7713
|
);
|
|
7763
|
-
|
|
7714
|
+
logger19.info(
|
|
7764
7715
|
{
|
|
7765
7716
|
tenantId,
|
|
7766
7717
|
graphId,
|
|
@@ -7806,7 +7757,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7806
7757
|
return streamSSE(c, async (stream2) => {
|
|
7807
7758
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
7808
7759
|
await sseHelper.writeRole();
|
|
7809
|
-
|
|
7760
|
+
logger19.info({ agentId }, "Starting execution");
|
|
7810
7761
|
const executionHandler = new ExecutionHandler();
|
|
7811
7762
|
const result = await executionHandler.execute({
|
|
7812
7763
|
executionContext,
|
|
@@ -7816,7 +7767,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7816
7767
|
requestId: requestId2,
|
|
7817
7768
|
sseHelper
|
|
7818
7769
|
});
|
|
7819
|
-
|
|
7770
|
+
logger19.info(
|
|
7820
7771
|
{ result },
|
|
7821
7772
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
7822
7773
|
);
|
|
@@ -7849,7 +7800,7 @@ var getMessageText = (content) => {
|
|
|
7849
7800
|
};
|
|
7850
7801
|
var chat_default = app2;
|
|
7851
7802
|
var app3 = new OpenAPIHono();
|
|
7852
|
-
var
|
|
7803
|
+
var logger20 = getLogger("chatDataStream");
|
|
7853
7804
|
var chatDataStreamRoute = createRoute({
|
|
7854
7805
|
method: "post",
|
|
7855
7806
|
path: "/chat",
|
|
@@ -7902,7 +7853,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
7902
7853
|
try {
|
|
7903
7854
|
const executionContext = getRequestExecutionContext(c);
|
|
7904
7855
|
const { tenantId, projectId, graphId } = executionContext;
|
|
7905
|
-
const body =
|
|
7856
|
+
const body = c.get("requestBody") || {};
|
|
7906
7857
|
const conversationId = body.conversationId || nanoid();
|
|
7907
7858
|
const activeSpan = trace.getActiveSpan();
|
|
7908
7859
|
if (activeSpan) {
|
|
@@ -7954,7 +7905,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
7954
7905
|
);
|
|
7955
7906
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
7956
7907
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
7957
|
-
|
|
7908
|
+
logger20.info({ userText, lastUserMessage }, "userText");
|
|
7958
7909
|
const messageSpan = trace.getActiveSpan();
|
|
7959
7910
|
if (messageSpan) {
|
|
7960
7911
|
messageSpan.setAttributes({
|
|
@@ -7996,7 +7947,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
7996
7947
|
await streamHelper.writeError("Unable to process request");
|
|
7997
7948
|
}
|
|
7998
7949
|
} catch (err) {
|
|
7999
|
-
|
|
7950
|
+
logger20.error({ err }, "Streaming error");
|
|
8000
7951
|
await streamHelper.writeError("Internal server error");
|
|
8001
7952
|
} finally {
|
|
8002
7953
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -8017,7 +7968,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8017
7968
|
)
|
|
8018
7969
|
);
|
|
8019
7970
|
} catch (error) {
|
|
8020
|
-
|
|
7971
|
+
logger20.error({ error }, "chatDataStream error");
|
|
8021
7972
|
return c.json({ error: "Failed to process chat completion" }, 500);
|
|
8022
7973
|
}
|
|
8023
7974
|
});
|
|
@@ -8025,7 +7976,7 @@ var chatDataStream_default = app3;
|
|
|
8025
7976
|
function createMCPSchema(schema) {
|
|
8026
7977
|
return schema;
|
|
8027
7978
|
}
|
|
8028
|
-
var
|
|
7979
|
+
var logger21 = getLogger("mcp");
|
|
8029
7980
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
8030
7981
|
constructor() {
|
|
8031
7982
|
__publicField(this, "mockRes");
|
|
@@ -8080,21 +8031,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
8080
8031
|
id: 0
|
|
8081
8032
|
});
|
|
8082
8033
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
8083
|
-
|
|
8034
|
+
logger21.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
8084
8035
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
8085
8036
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
8086
8037
|
try {
|
|
8087
8038
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
8088
|
-
|
|
8039
|
+
logger21.info({ sessionId }, "Successfully spoofed initialization");
|
|
8089
8040
|
} catch (spoofError) {
|
|
8090
|
-
|
|
8041
|
+
logger21.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
8091
8042
|
}
|
|
8092
8043
|
};
|
|
8093
8044
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
8094
8045
|
const sessionId = req.headers["mcp-session-id"];
|
|
8095
|
-
|
|
8046
|
+
logger21.info({ sessionId }, "Received MCP session ID");
|
|
8096
8047
|
if (!sessionId) {
|
|
8097
|
-
|
|
8048
|
+
logger21.info({ body }, "Missing session ID");
|
|
8098
8049
|
res.writeHead(400).end(
|
|
8099
8050
|
JSON.stringify({
|
|
8100
8051
|
jsonrpc: "2.0",
|
|
@@ -8120,7 +8071,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8120
8071
|
scopes: { tenantId, projectId },
|
|
8121
8072
|
conversationId: sessionId
|
|
8122
8073
|
});
|
|
8123
|
-
|
|
8074
|
+
logger21.info(
|
|
8124
8075
|
{
|
|
8125
8076
|
sessionId,
|
|
8126
8077
|
conversationFound: !!conversation,
|
|
@@ -8131,7 +8082,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8131
8082
|
"Conversation lookup result"
|
|
8132
8083
|
);
|
|
8133
8084
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
8134
|
-
|
|
8085
|
+
logger21.info(
|
|
8135
8086
|
{ sessionId, conversationId: conversation?.id },
|
|
8136
8087
|
"MCP session not found or invalid"
|
|
8137
8088
|
);
|
|
@@ -8192,7 +8143,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
8192
8143
|
requestId: requestId2,
|
|
8193
8144
|
sseHelper: mcpStreamHelper
|
|
8194
8145
|
});
|
|
8195
|
-
|
|
8146
|
+
logger21.info(
|
|
8196
8147
|
{ result },
|
|
8197
8148
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8198
8149
|
);
|
|
@@ -8266,7 +8217,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
8266
8217
|
dbClient_default,
|
|
8267
8218
|
credentialStores
|
|
8268
8219
|
);
|
|
8269
|
-
|
|
8220
|
+
logger21.info(
|
|
8270
8221
|
{
|
|
8271
8222
|
tenantId,
|
|
8272
8223
|
graphId,
|
|
@@ -8327,7 +8278,7 @@ var validateRequestParameters = (c) => {
|
|
|
8327
8278
|
};
|
|
8328
8279
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
8329
8280
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8330
|
-
|
|
8281
|
+
logger21.info({ body }, "Received initialization request");
|
|
8331
8282
|
const sessionId = nanoid();
|
|
8332
8283
|
const agentGraph = await getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
8333
8284
|
scopes: { tenantId, projectId },
|
|
@@ -8358,7 +8309,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8358
8309
|
}
|
|
8359
8310
|
}
|
|
8360
8311
|
});
|
|
8361
|
-
|
|
8312
|
+
logger21.info(
|
|
8362
8313
|
{ sessionId, conversationId: conversation.id },
|
|
8363
8314
|
"Created MCP session as conversation"
|
|
8364
8315
|
);
|
|
@@ -8367,9 +8318,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8367
8318
|
});
|
|
8368
8319
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
8369
8320
|
await server.connect(transport);
|
|
8370
|
-
|
|
8321
|
+
logger21.info({ sessionId }, "Server connected for initialization");
|
|
8371
8322
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
8372
|
-
|
|
8323
|
+
logger21.info(
|
|
8373
8324
|
{
|
|
8374
8325
|
sessionId,
|
|
8375
8326
|
bodyMethod: body?.method,
|
|
@@ -8378,7 +8329,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8378
8329
|
"About to handle initialization request"
|
|
8379
8330
|
);
|
|
8380
8331
|
await transport.handleRequest(req, res, body);
|
|
8381
|
-
|
|
8332
|
+
logger21.info({ sessionId }, "Successfully handled initialization request");
|
|
8382
8333
|
return toFetchResponse(res);
|
|
8383
8334
|
};
|
|
8384
8335
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -8406,8 +8357,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8406
8357
|
sessionId,
|
|
8407
8358
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
8408
8359
|
);
|
|
8409
|
-
|
|
8410
|
-
|
|
8360
|
+
logger21.info({ sessionId }, "Server connected and transport initialized");
|
|
8361
|
+
logger21.info(
|
|
8411
8362
|
{
|
|
8412
8363
|
sessionId,
|
|
8413
8364
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -8421,9 +8372,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8421
8372
|
);
|
|
8422
8373
|
try {
|
|
8423
8374
|
await transport.handleRequest(req, res, body);
|
|
8424
|
-
|
|
8375
|
+
logger21.info({ sessionId }, "Successfully handled MCP request");
|
|
8425
8376
|
} catch (transportError) {
|
|
8426
|
-
|
|
8377
|
+
logger21.error(
|
|
8427
8378
|
{
|
|
8428
8379
|
sessionId,
|
|
8429
8380
|
error: transportError,
|
|
@@ -8473,14 +8424,14 @@ app4.openapi(
|
|
|
8473
8424
|
return paramValidation.response;
|
|
8474
8425
|
}
|
|
8475
8426
|
const { executionContext } = paramValidation;
|
|
8476
|
-
const body =
|
|
8477
|
-
|
|
8427
|
+
const body = c.get("requestBody") || {};
|
|
8428
|
+
logger21.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
8478
8429
|
const isInitRequest = body.method === "initialize";
|
|
8479
8430
|
const { req, res } = toReqRes(c.req.raw);
|
|
8480
8431
|
const validatedContext = c.get("validatedContext") || {};
|
|
8481
8432
|
const credentialStores = c.get("credentialStores");
|
|
8482
|
-
|
|
8483
|
-
|
|
8433
|
+
logger21.info({ validatedContext }, "Validated context");
|
|
8434
|
+
logger21.info({ req }, "request");
|
|
8484
8435
|
if (isInitRequest) {
|
|
8485
8436
|
return await handleInitializationRequest(
|
|
8486
8437
|
body,
|
|
@@ -8502,7 +8453,7 @@ app4.openapi(
|
|
|
8502
8453
|
);
|
|
8503
8454
|
}
|
|
8504
8455
|
} catch (e) {
|
|
8505
|
-
|
|
8456
|
+
logger21.error(
|
|
8506
8457
|
{
|
|
8507
8458
|
error: e instanceof Error ? e.message : e,
|
|
8508
8459
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -8514,7 +8465,7 @@ app4.openapi(
|
|
|
8514
8465
|
}
|
|
8515
8466
|
);
|
|
8516
8467
|
app4.get("/", async (c) => {
|
|
8517
|
-
|
|
8468
|
+
logger21.info({}, "Received GET MCP request");
|
|
8518
8469
|
return c.json(
|
|
8519
8470
|
{
|
|
8520
8471
|
jsonrpc: "2.0",
|
|
@@ -8528,7 +8479,7 @@ app4.get("/", async (c) => {
|
|
|
8528
8479
|
);
|
|
8529
8480
|
});
|
|
8530
8481
|
app4.delete("/", async (c) => {
|
|
8531
|
-
|
|
8482
|
+
logger21.info({}, "Received DELETE MCP request");
|
|
8532
8483
|
return c.json(
|
|
8533
8484
|
{
|
|
8534
8485
|
jsonrpc: "2.0",
|
|
@@ -8541,6 +8492,7 @@ app4.delete("/", async (c) => {
|
|
|
8541
8492
|
var mcp_default = app4;
|
|
8542
8493
|
|
|
8543
8494
|
// src/app.ts
|
|
8495
|
+
var logger22 = getLogger("agents-run-api");
|
|
8544
8496
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
8545
8497
|
const app6 = new OpenAPIHono();
|
|
8546
8498
|
app6.use("*", requestId());
|
|
@@ -8549,6 +8501,17 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8549
8501
|
c.set("credentialStores", credentialStores);
|
|
8550
8502
|
return next();
|
|
8551
8503
|
});
|
|
8504
|
+
app6.use("*", async (c, next) => {
|
|
8505
|
+
if (c.req.header("content-type")?.includes("application/json")) {
|
|
8506
|
+
try {
|
|
8507
|
+
const body = await c.req.json();
|
|
8508
|
+
c.set("requestBody", body);
|
|
8509
|
+
} catch (error) {
|
|
8510
|
+
logger22.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
8511
|
+
}
|
|
8512
|
+
}
|
|
8513
|
+
return next();
|
|
8514
|
+
});
|
|
8552
8515
|
app6.use("*", async (c, next) => {
|
|
8553
8516
|
const reqId = c.get("requestId");
|
|
8554
8517
|
let bag = propagation.getBaggage(context.active());
|
|
@@ -8562,19 +8525,6 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8562
8525
|
}
|
|
8563
8526
|
return next();
|
|
8564
8527
|
});
|
|
8565
|
-
app6.use(
|
|
8566
|
-
pinoLogger({
|
|
8567
|
-
pino: getLogger() || pino({ level: "debug" }),
|
|
8568
|
-
http: {
|
|
8569
|
-
onResLevel(c) {
|
|
8570
|
-
if (c.res.status >= 500) {
|
|
8571
|
-
return "error";
|
|
8572
|
-
}
|
|
8573
|
-
return "info";
|
|
8574
|
-
}
|
|
8575
|
-
}
|
|
8576
|
-
})
|
|
8577
|
-
);
|
|
8578
8528
|
app6.onError(async (err, c) => {
|
|
8579
8529
|
const isExpectedError = err instanceof HTTPException;
|
|
8580
8530
|
const status = isExpectedError ? err.status : 500;
|
|
@@ -8608,9 +8558,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8608
8558
|
if (!isExpectedError) {
|
|
8609
8559
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
8610
8560
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
logger23.error(
|
|
8561
|
+
if (logger22) {
|
|
8562
|
+
logger22.error(
|
|
8614
8563
|
{
|
|
8615
8564
|
error: err,
|
|
8616
8565
|
message: errorMessage,
|
|
@@ -8622,9 +8571,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8622
8571
|
);
|
|
8623
8572
|
}
|
|
8624
8573
|
} else {
|
|
8625
|
-
|
|
8626
|
-
|
|
8627
|
-
logger23.error(
|
|
8574
|
+
if (logger22) {
|
|
8575
|
+
logger22.error(
|
|
8628
8576
|
{
|
|
8629
8577
|
error: err,
|
|
8630
8578
|
path: c.req.path,
|
|
@@ -8641,9 +8589,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8641
8589
|
const response = err.getResponse();
|
|
8642
8590
|
return response;
|
|
8643
8591
|
} catch (responseError) {
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
logger23.error({ error: responseError }, "Error while handling HTTPException response");
|
|
8592
|
+
if (logger22) {
|
|
8593
|
+
logger22.error({ error: responseError }, "Error while handling HTTPException response");
|
|
8647
8594
|
}
|
|
8648
8595
|
}
|
|
8649
8596
|
}
|
|
@@ -8677,15 +8624,16 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8677
8624
|
app6.use("*", async (c, next) => {
|
|
8678
8625
|
const executionContext = c.get("executionContext");
|
|
8679
8626
|
if (!executionContext) {
|
|
8627
|
+
logger22.debug({}, "Empty execution context");
|
|
8680
8628
|
return next();
|
|
8681
8629
|
}
|
|
8682
8630
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8683
8631
|
let conversationId;
|
|
8684
|
-
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
|
|
8632
|
+
const requestBody = c.get("requestBody") || {};
|
|
8633
|
+
if (requestBody) {
|
|
8634
|
+
conversationId = requestBody.conversationId;
|
|
8635
|
+
if (!conversationId) {
|
|
8636
|
+
logger22.debug({ requestBody }, "No conversation ID found in request body");
|
|
8689
8637
|
}
|
|
8690
8638
|
}
|
|
8691
8639
|
const entries = Object.fromEntries(
|
|
@@ -8700,6 +8648,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8700
8648
|
})
|
|
8701
8649
|
);
|
|
8702
8650
|
if (!Object.keys(entries).length) {
|
|
8651
|
+
logger22.debug({}, "Empty entries for baggage");
|
|
8703
8652
|
return next();
|
|
8704
8653
|
}
|
|
8705
8654
|
const bag = Object.entries(entries).reduce(
|
|
@@ -8731,6 +8680,22 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8731
8680
|
app6.route("/v1/mcp", mcp_default);
|
|
8732
8681
|
app6.route("/agents", agents_default);
|
|
8733
8682
|
setupOpenAPIRoutes(app6);
|
|
8683
|
+
app6.use("/tenants/*", async (c, next) => {
|
|
8684
|
+
await next();
|
|
8685
|
+
await batchProcessor.forceFlush();
|
|
8686
|
+
});
|
|
8687
|
+
app6.use("/agents/*", async (c, next) => {
|
|
8688
|
+
await next();
|
|
8689
|
+
await batchProcessor.forceFlush();
|
|
8690
|
+
});
|
|
8691
|
+
app6.use("/v1/*", async (c, next) => {
|
|
8692
|
+
await next();
|
|
8693
|
+
await batchProcessor.forceFlush();
|
|
8694
|
+
});
|
|
8695
|
+
app6.use("/api/*", async (c, next) => {
|
|
8696
|
+
await next();
|
|
8697
|
+
await batchProcessor.forceFlush();
|
|
8698
|
+
});
|
|
8734
8699
|
const baseApp = new Hono();
|
|
8735
8700
|
baseApp.route("/", app6);
|
|
8736
8701
|
return baseApp;
|