@inkeep/agents-run-api 0.0.0-dev-20250911195722 → 0.0.0-dev-20250911212652
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/{chunk-JIWNRFDU.js → chunk-2MQ324HB.js} +6 -3
- package/dist/{conversations-YTJWHN67.js → conversations-WZLXOMZH.js} +1 -1
- package/dist/index.cjs +278 -382
- package/dist/index.js +278 -303
- package/package.json +2 -2
- package/dist/chunk-3COYP2VE.js +0 -70
- package/dist/chunk-PKBMQBKP.js +0 -5
- package/dist/instrumentation-KKYHA3A3.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var autoInstrumentationsNode = require('@opentelemetry/auto-instrumentations-node');
|
|
6
|
-
var baggageSpanProcessor = require('@opentelemetry/baggage-span-processor');
|
|
7
|
-
var exporterTraceOtlpProto = require('@opentelemetry/exporter-trace-otlp-proto');
|
|
8
|
-
var sdkNode = require('@opentelemetry/sdk-node');
|
|
9
|
-
var sdkTraceNode = require('@opentelemetry/sdk-trace-node');
|
|
10
5
|
var fs = require('fs');
|
|
11
6
|
var path = require('path');
|
|
12
7
|
var dotenv = require('dotenv');
|
|
13
8
|
var z5 = require('zod');
|
|
14
9
|
var agentsCore = require('@inkeep/agents-core');
|
|
15
10
|
var nanoid = require('nanoid');
|
|
11
|
+
var autoInstrumentationsNode = require('@opentelemetry/auto-instrumentations-node');
|
|
12
|
+
var baggageSpanProcessor = require('@opentelemetry/baggage-span-processor');
|
|
13
|
+
var exporterTraceOtlpProto = require('@opentelemetry/exporter-trace-otlp-proto');
|
|
14
|
+
var sdkNode = require('@opentelemetry/sdk-node');
|
|
15
|
+
var sdkTraceNode = require('@opentelemetry/sdk-trace-node');
|
|
16
16
|
var hono = require('hono');
|
|
17
17
|
var zodOpenapi = require('@hono/zod-openapi');
|
|
18
18
|
var api = require('@opentelemetry/api');
|
|
@@ -78,79 +78,6 @@ var __export = (target, all) => {
|
|
|
78
78
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
79
79
|
};
|
|
80
80
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
81
|
-
|
|
82
|
-
// src/instrumentation.ts
|
|
83
|
-
var instrumentation_exports = {};
|
|
84
|
-
__export(instrumentation_exports, {
|
|
85
|
-
sdk: () => sdk,
|
|
86
|
-
spanProcessor: () => spanProcessor
|
|
87
|
-
});
|
|
88
|
-
var otlpUrl, otlpExporter, FanOutSpanProcessor, spanProcessor, sdk;
|
|
89
|
-
var init_instrumentation = __esm({
|
|
90
|
-
"src/instrumentation.ts"() {
|
|
91
|
-
otlpUrl = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:14318/v1/traces";
|
|
92
|
-
otlpExporter = new exporterTraceOtlpProto.OTLPTraceExporter({ url: otlpUrl });
|
|
93
|
-
FanOutSpanProcessor = class {
|
|
94
|
-
constructor(inner) {
|
|
95
|
-
this.inner = inner;
|
|
96
|
-
}
|
|
97
|
-
onStart(span, parent) {
|
|
98
|
-
this.inner.forEach((p) => p.onStart(span, parent));
|
|
99
|
-
}
|
|
100
|
-
onEnd(span) {
|
|
101
|
-
this.inner.forEach((p) => p.onEnd(span));
|
|
102
|
-
}
|
|
103
|
-
forceFlush() {
|
|
104
|
-
return Promise.all(this.inner.map((p) => p.forceFlush?.())).then(() => {
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
shutdown() {
|
|
108
|
-
return Promise.all(this.inner.map((p) => p.shutdown?.())).then(() => {
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
spanProcessor = new FanOutSpanProcessor([
|
|
113
|
-
new baggageSpanProcessor.BaggageSpanProcessor(baggageSpanProcessor.ALLOW_ALL_BAGGAGE_KEYS),
|
|
114
|
-
new sdkTraceNode.BatchSpanProcessor(otlpExporter, {
|
|
115
|
-
maxExportBatchSize: 1,
|
|
116
|
-
// Send immediately (vs 512)
|
|
117
|
-
scheduledDelayMillis: 100,
|
|
118
|
-
// 100ms delay (vs 5000ms)
|
|
119
|
-
exportTimeoutMillis: 5e3,
|
|
120
|
-
// 5s timeout (vs 30s)
|
|
121
|
-
maxQueueSize: 512
|
|
122
|
-
// Smaller queue
|
|
123
|
-
})
|
|
124
|
-
]);
|
|
125
|
-
sdk = new sdkNode.NodeSDK({
|
|
126
|
-
serviceName: "inkeep-chat",
|
|
127
|
-
spanProcessor,
|
|
128
|
-
instrumentations: [
|
|
129
|
-
autoInstrumentationsNode.getNodeAutoInstrumentations({
|
|
130
|
-
"@opentelemetry/instrumentation-http": {
|
|
131
|
-
enabled: true,
|
|
132
|
-
requestHook: (span, request) => {
|
|
133
|
-
const url = request?.url ?? request?.path;
|
|
134
|
-
if (!url) return;
|
|
135
|
-
const u = new URL(url, "http://localhost");
|
|
136
|
-
span.updateName(`${request?.method || "UNKNOWN"} ${u.pathname}`);
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
"@opentelemetry/instrumentation-undici": {
|
|
140
|
-
requestHook: (span) => {
|
|
141
|
-
const method = span.attributes?.["http.request.method"];
|
|
142
|
-
const host = span.attributes?.["server.address"];
|
|
143
|
-
const path2 = span.attributes?.["url.path"];
|
|
144
|
-
if (method && path2)
|
|
145
|
-
span.updateName(host ? `${method} ${host}${path2}` : `${method} ${path2}`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
]
|
|
150
|
-
});
|
|
151
|
-
sdk.start();
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
81
|
var environmentSchema, criticalEnv, loadEnvFile, envSchema, parseEnv, env;
|
|
155
82
|
var init_env = __esm({
|
|
156
83
|
"src/env.ts"() {
|
|
@@ -183,7 +110,8 @@ var init_env = __esm({
|
|
|
183
110
|
OPENAI_API_KEY: z5.z.string().optional(),
|
|
184
111
|
ANTHROPIC_API_KEY: z5.z.string(),
|
|
185
112
|
INKEEP_AGENTS_RUN_BYPASS_SECRET: z5.z.string().optional(),
|
|
186
|
-
|
|
113
|
+
OTEL_MAX_EXPORT_BATCH_SIZE: z5.z.coerce.number().optional(),
|
|
114
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: z5.z.string().optional().default("http://localhost:14318/v1/traces")
|
|
187
115
|
});
|
|
188
116
|
parseEnv = () => {
|
|
189
117
|
try {
|
|
@@ -401,8 +329,63 @@ var init_conversations = __esm({
|
|
|
401
329
|
}
|
|
402
330
|
});
|
|
403
331
|
|
|
404
|
-
// src/
|
|
405
|
-
|
|
332
|
+
// src/instrumentation.ts
|
|
333
|
+
init_env();
|
|
334
|
+
var otlpUrl = env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
335
|
+
var otlpExporter = new exporterTraceOtlpProto.OTLPTraceExporter({ url: otlpUrl });
|
|
336
|
+
var FanOutSpanProcessor = class {
|
|
337
|
+
constructor(inner) {
|
|
338
|
+
this.inner = inner;
|
|
339
|
+
}
|
|
340
|
+
onStart(span, parent) {
|
|
341
|
+
this.inner.forEach((p) => p.onStart(span, parent));
|
|
342
|
+
}
|
|
343
|
+
onEnd(span) {
|
|
344
|
+
this.inner.forEach((p) => p.onEnd(span));
|
|
345
|
+
}
|
|
346
|
+
forceFlush() {
|
|
347
|
+
return Promise.all(this.inner.map((p) => p.forceFlush?.())).then(() => {
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
shutdown() {
|
|
351
|
+
return Promise.all(this.inner.map((p) => p.shutdown?.())).then(() => {
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
var maxExportBatchSize = env.OTEL_MAX_EXPORT_BATCH_SIZE ?? (env.ENVIRONMENT === "development" ? 1 : 512);
|
|
356
|
+
var spanProcessor = new FanOutSpanProcessor([
|
|
357
|
+
new baggageSpanProcessor.BaggageSpanProcessor(baggageSpanProcessor.ALLOW_ALL_BAGGAGE_KEYS),
|
|
358
|
+
new sdkTraceNode.BatchSpanProcessor(otlpExporter, {
|
|
359
|
+
maxExportBatchSize
|
|
360
|
+
})
|
|
361
|
+
]);
|
|
362
|
+
var sdk = new sdkNode.NodeSDK({
|
|
363
|
+
serviceName: "inkeep-agents-run-api",
|
|
364
|
+
spanProcessor,
|
|
365
|
+
instrumentations: [
|
|
366
|
+
autoInstrumentationsNode.getNodeAutoInstrumentations({
|
|
367
|
+
"@opentelemetry/instrumentation-http": {
|
|
368
|
+
enabled: true,
|
|
369
|
+
requestHook: (span, request) => {
|
|
370
|
+
const url = request?.url ?? request?.path;
|
|
371
|
+
if (!url) return;
|
|
372
|
+
const u = new URL(url, "http://localhost");
|
|
373
|
+
span.updateName(`${request?.method || "UNKNOWN"} ${u.pathname}`);
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
"@opentelemetry/instrumentation-undici": {
|
|
377
|
+
requestHook: (span) => {
|
|
378
|
+
const method = span.attributes?.["http.request.method"];
|
|
379
|
+
const host = span.attributes?.["server.address"];
|
|
380
|
+
const path2 = span.attributes?.["url.path"];
|
|
381
|
+
if (method && path2)
|
|
382
|
+
span.updateName(host ? `${method} ${host}${path2}` : `${method} ${path2}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
})
|
|
386
|
+
]
|
|
387
|
+
});
|
|
388
|
+
sdk.start();
|
|
406
389
|
|
|
407
390
|
// src/logger.ts
|
|
408
391
|
init_env();
|
|
@@ -1235,81 +1218,10 @@ init_dbClient();
|
|
|
1235
1218
|
init_conversations();
|
|
1236
1219
|
init_dbClient();
|
|
1237
1220
|
|
|
1238
|
-
//
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
var
|
|
1242
|
-
var BASE = "inkeep-chat";
|
|
1243
|
-
var SERVICE_NAME = "inkeep-chat";
|
|
1244
|
-
var SERVICE_VERSION = "1.0.0";
|
|
1245
|
-
var createSpanName = (suffix) => `${BASE}.${suffix}`;
|
|
1246
|
-
var createNoOpSpan = () => ({
|
|
1247
|
-
setAttributes: () => ({}),
|
|
1248
|
-
recordException: () => ({}),
|
|
1249
|
-
setStatus: () => ({}),
|
|
1250
|
-
addEvent: () => ({}),
|
|
1251
|
-
end: () => {
|
|
1252
|
-
},
|
|
1253
|
-
isRecording: () => false,
|
|
1254
|
-
setAttribute: () => ({}),
|
|
1255
|
-
updateName: () => ({}),
|
|
1256
|
-
spanContext: () => ({
|
|
1257
|
-
traceId: "00000000000000000000000000000000",
|
|
1258
|
-
spanId: "0000000000000000",
|
|
1259
|
-
traceFlags: 0
|
|
1260
|
-
}),
|
|
1261
|
-
addLink: () => ({}),
|
|
1262
|
-
addLinks: () => ({})
|
|
1263
|
-
});
|
|
1264
|
-
var noopTracer = {
|
|
1265
|
-
startActiveSpan(_name, arg1, arg2, arg3) {
|
|
1266
|
-
const fn = typeof arg1 === "function" ? arg1 : typeof arg2 === "function" ? arg2 : arg3;
|
|
1267
|
-
if (!fn) throw new Error("No callback function provided");
|
|
1268
|
-
return fn(createNoOpSpan());
|
|
1269
|
-
},
|
|
1270
|
-
startSpan(_name, _options) {
|
|
1271
|
-
return createNoOpSpan();
|
|
1272
|
-
}
|
|
1273
|
-
};
|
|
1274
|
-
var globalTracerInstance = null;
|
|
1275
|
-
function handleSpanError(span, error, logger24, logMessage) {
|
|
1276
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1277
|
-
span.recordException(error);
|
|
1278
|
-
span.setStatus({
|
|
1279
|
-
code: api.SpanStatusCode.ERROR,
|
|
1280
|
-
message: errorMessage
|
|
1281
|
-
});
|
|
1282
|
-
}
|
|
1283
|
-
function getGlobalTracer() {
|
|
1284
|
-
if (!globalTracerInstance) {
|
|
1285
|
-
try {
|
|
1286
|
-
globalTracerInstance = api.trace.getTracer(SERVICE_NAME, SERVICE_VERSION);
|
|
1287
|
-
} catch (_error) {
|
|
1288
|
-
logger4.debug("OpenTelemetry tracer not available, using no-op tracer");
|
|
1289
|
-
globalTracerInstance = noopTracer;
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
return globalTracerInstance;
|
|
1293
|
-
}
|
|
1294
|
-
async function forceFlushTracer() {
|
|
1295
|
-
const isOtelTracesForceFlushEnabled = env.OTEL_TRACES_FORCE_FLUSH_ENABLED;
|
|
1296
|
-
const isForceFlushEnvironment = env.ENVIRONMENT && FORCE_FLUSH_ENVIRONMENTS.includes(env.ENVIRONMENT);
|
|
1297
|
-
const shouldForceFlush = isOtelTracesForceFlushEnabled === true || isOtelTracesForceFlushEnabled == null && isForceFlushEnvironment;
|
|
1298
|
-
if (!shouldForceFlush) {
|
|
1299
|
-
return;
|
|
1300
|
-
}
|
|
1301
|
-
try {
|
|
1302
|
-
const { spanProcessor: spanProcessor2 } = await Promise.resolve().then(() => (init_instrumentation(), instrumentation_exports));
|
|
1303
|
-
if (spanProcessor2 && typeof spanProcessor2.forceFlush === "function") {
|
|
1304
|
-
await spanProcessor2.forceFlush();
|
|
1305
|
-
logger4.debug("Span processor force flush completed");
|
|
1306
|
-
} else {
|
|
1307
|
-
logger4.debug("Span processor does not support force flush or is not available");
|
|
1308
|
-
}
|
|
1309
|
-
} catch (error) {
|
|
1310
|
-
logger4.warn({ error }, "Failed to force flush tracer");
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1221
|
+
// package.json
|
|
1222
|
+
var package_default = {
|
|
1223
|
+
version: "0.1.3"};
|
|
1224
|
+
var tracer = agentsCore.getTracer("agents-run-api", package_default.version);
|
|
1313
1225
|
function agentInitializingOp(sessionId, graphId) {
|
|
1314
1226
|
return {
|
|
1315
1227
|
type: "agent_initializing",
|
|
@@ -1346,10 +1258,10 @@ function statusUpdateOp(ctx) {
|
|
|
1346
1258
|
ctx
|
|
1347
1259
|
};
|
|
1348
1260
|
}
|
|
1349
|
-
var
|
|
1261
|
+
var logger4 = getLogger("DataComponentSchema");
|
|
1350
1262
|
function jsonSchemaToZod(jsonSchema) {
|
|
1351
1263
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
1352
|
-
|
|
1264
|
+
logger4.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
1353
1265
|
return z5.z.string();
|
|
1354
1266
|
}
|
|
1355
1267
|
switch (jsonSchema.type) {
|
|
@@ -1376,7 +1288,7 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
1376
1288
|
case "null":
|
|
1377
1289
|
return z5.z.null();
|
|
1378
1290
|
default:
|
|
1379
|
-
|
|
1291
|
+
logger4.warn(
|
|
1380
1292
|
{
|
|
1381
1293
|
unsupportedType: jsonSchema.type,
|
|
1382
1294
|
schema: jsonSchema
|
|
@@ -1430,7 +1342,7 @@ __publicField(_ArtifactReferenceSchema, "ARTIFACT_PROPS_SCHEMA", {
|
|
|
1430
1342
|
required: ["artifact_id", "task_id"]
|
|
1431
1343
|
});
|
|
1432
1344
|
var ArtifactReferenceSchema = _ArtifactReferenceSchema;
|
|
1433
|
-
var
|
|
1345
|
+
var logger5 = getLogger("ModelFactory");
|
|
1434
1346
|
var _ModelFactory = class _ModelFactory {
|
|
1435
1347
|
/**
|
|
1436
1348
|
* Create a language model instance from configuration
|
|
@@ -1443,7 +1355,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1443
1355
|
const modelSettings = config2;
|
|
1444
1356
|
const modelString = modelSettings.model.trim();
|
|
1445
1357
|
const { provider, modelName } = _ModelFactory.parseModelString(modelString);
|
|
1446
|
-
|
|
1358
|
+
logger5.debug(
|
|
1447
1359
|
{
|
|
1448
1360
|
provider,
|
|
1449
1361
|
model: modelName,
|
|
@@ -1462,7 +1374,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1462
1374
|
throw new Error(`Unsupported provider: ${provider}. Supported providers are: ${_ModelFactory.SUPPORTED_PROVIDERS.join(", ")}`);
|
|
1463
1375
|
}
|
|
1464
1376
|
} catch (error) {
|
|
1465
|
-
|
|
1377
|
+
logger5.error(
|
|
1466
1378
|
{
|
|
1467
1379
|
provider,
|
|
1468
1380
|
model: modelName,
|
|
@@ -1483,7 +1395,7 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1483
1395
|
const [provider, ...modelParts] = modelString.split("/");
|
|
1484
1396
|
const normalizedProvider = provider.toLowerCase();
|
|
1485
1397
|
if (!_ModelFactory.SUPPORTED_PROVIDERS.includes(normalizedProvider)) {
|
|
1486
|
-
|
|
1398
|
+
logger5.warn(
|
|
1487
1399
|
{ provider: normalizedProvider, modelName: modelParts.join("/") },
|
|
1488
1400
|
"Unsupported provider detected, falling back to anthropic"
|
|
1489
1401
|
);
|
|
@@ -1512,14 +1424,14 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1512
1424
|
anthropicConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1513
1425
|
}
|
|
1514
1426
|
if (providerOptions?.gateway) {
|
|
1515
|
-
|
|
1427
|
+
logger5.info(
|
|
1516
1428
|
{ gateway: providerOptions.gateway },
|
|
1517
1429
|
"Setting up AI Gateway for Anthropic model"
|
|
1518
1430
|
);
|
|
1519
1431
|
Object.assign(anthropicConfig, providerOptions.gateway);
|
|
1520
1432
|
}
|
|
1521
1433
|
if (Object.keys(anthropicConfig).length > 0) {
|
|
1522
|
-
|
|
1434
|
+
logger5.info({ config: anthropicConfig }, "Applying custom Anthropic provider configuration");
|
|
1523
1435
|
const provider = anthropic.createAnthropic(anthropicConfig);
|
|
1524
1436
|
return provider(modelName);
|
|
1525
1437
|
}
|
|
@@ -1534,11 +1446,11 @@ var _ModelFactory = class _ModelFactory {
|
|
|
1534
1446
|
openaiConfig.baseURL = providerOptions.baseUrl || providerOptions.baseURL;
|
|
1535
1447
|
}
|
|
1536
1448
|
if (providerOptions?.gateway) {
|
|
1537
|
-
|
|
1449
|
+
logger5.info({ gateway: providerOptions.gateway }, "Setting up AI Gateway for OpenAI model");
|
|
1538
1450
|
Object.assign(openaiConfig, providerOptions.gateway);
|
|
1539
1451
|
}
|
|
1540
1452
|
if (Object.keys(openaiConfig).length > 0) {
|
|
1541
|
-
|
|
1453
|
+
logger5.info({ config: openaiConfig }, "Applying custom OpenAI provider configuration");
|
|
1542
1454
|
const provider = openai.createOpenAI(openaiConfig);
|
|
1543
1455
|
return provider(modelName);
|
|
1544
1456
|
}
|
|
@@ -1631,8 +1543,7 @@ function unregisterStreamHelper(requestId2) {
|
|
|
1631
1543
|
}
|
|
1632
1544
|
|
|
1633
1545
|
// src/utils/graph-session.ts
|
|
1634
|
-
var
|
|
1635
|
-
var tracer = getGlobalTracer();
|
|
1546
|
+
var logger6 = getLogger("GraphSession");
|
|
1636
1547
|
var GraphSession = class {
|
|
1637
1548
|
// Track scheduled timeouts for cleanup
|
|
1638
1549
|
constructor(sessionId, messageId, graphId, tenantId, projectId) {
|
|
@@ -1656,7 +1567,7 @@ var GraphSession = class {
|
|
|
1656
1567
|
__publicField(this, "MAX_PENDING_ARTIFACTS", 100);
|
|
1657
1568
|
// Prevent unbounded growth
|
|
1658
1569
|
__publicField(this, "scheduledTimeouts");
|
|
1659
|
-
|
|
1570
|
+
logger6.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
1660
1571
|
}
|
|
1661
1572
|
/**
|
|
1662
1573
|
* Initialize status updates for this session
|
|
@@ -1678,7 +1589,7 @@ var GraphSession = class {
|
|
|
1678
1589
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
1679
1590
|
this.statusUpdateTimer = setInterval(async () => {
|
|
1680
1591
|
if (!this.statusUpdateState || this.isEnded) {
|
|
1681
|
-
|
|
1592
|
+
logger6.debug(
|
|
1682
1593
|
{ sessionId: this.sessionId },
|
|
1683
1594
|
"Timer triggered but session already cleaned up or ended"
|
|
1684
1595
|
);
|
|
@@ -1690,7 +1601,7 @@ var GraphSession = class {
|
|
|
1690
1601
|
}
|
|
1691
1602
|
await this.checkAndSendTimeBasedUpdate();
|
|
1692
1603
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
1693
|
-
|
|
1604
|
+
logger6.info(
|
|
1694
1605
|
{
|
|
1695
1606
|
sessionId: this.sessionId,
|
|
1696
1607
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -1704,7 +1615,7 @@ var GraphSession = class {
|
|
|
1704
1615
|
*/
|
|
1705
1616
|
recordEvent(eventType, agentId, data) {
|
|
1706
1617
|
if (this.isEnded) {
|
|
1707
|
-
|
|
1618
|
+
logger6.debug(
|
|
1708
1619
|
{
|
|
1709
1620
|
sessionId: this.sessionId,
|
|
1710
1621
|
eventType,
|
|
@@ -1724,7 +1635,7 @@ var GraphSession = class {
|
|
|
1724
1635
|
if (eventType === "artifact_saved" && data.pendingGeneration) {
|
|
1725
1636
|
const artifactId = data.artifactId;
|
|
1726
1637
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
1727
|
-
|
|
1638
|
+
logger6.warn({
|
|
1728
1639
|
sessionId: this.sessionId,
|
|
1729
1640
|
artifactId,
|
|
1730
1641
|
pendingCount: this.pendingArtifacts.size,
|
|
@@ -1742,7 +1653,7 @@ var GraphSession = class {
|
|
|
1742
1653
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
1743
1654
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
1744
1655
|
this.pendingArtifacts.delete(artifactId);
|
|
1745
|
-
|
|
1656
|
+
logger6.error({
|
|
1746
1657
|
sessionId: this.sessionId,
|
|
1747
1658
|
artifactId,
|
|
1748
1659
|
errorCount,
|
|
@@ -1751,7 +1662,7 @@ var GraphSession = class {
|
|
|
1751
1662
|
stack: error instanceof Error ? error.stack : void 0
|
|
1752
1663
|
}, "Artifact processing failed after max retries, giving up");
|
|
1753
1664
|
} else {
|
|
1754
|
-
|
|
1665
|
+
logger6.warn({
|
|
1755
1666
|
sessionId: this.sessionId,
|
|
1756
1667
|
artifactId,
|
|
1757
1668
|
errorCount,
|
|
@@ -1770,14 +1681,14 @@ var GraphSession = class {
|
|
|
1770
1681
|
*/
|
|
1771
1682
|
checkStatusUpdates() {
|
|
1772
1683
|
if (this.isEnded) {
|
|
1773
|
-
|
|
1684
|
+
logger6.debug(
|
|
1774
1685
|
{ sessionId: this.sessionId },
|
|
1775
1686
|
"Session has ended - skipping status update check"
|
|
1776
1687
|
);
|
|
1777
1688
|
return;
|
|
1778
1689
|
}
|
|
1779
1690
|
if (!this.statusUpdateState) {
|
|
1780
|
-
|
|
1691
|
+
logger6.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
1781
1692
|
return;
|
|
1782
1693
|
}
|
|
1783
1694
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -1788,11 +1699,11 @@ var GraphSession = class {
|
|
|
1788
1699
|
*/
|
|
1789
1700
|
async checkAndSendTimeBasedUpdate() {
|
|
1790
1701
|
if (this.isEnded) {
|
|
1791
|
-
|
|
1702
|
+
logger6.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
1792
1703
|
return;
|
|
1793
1704
|
}
|
|
1794
1705
|
if (!this.statusUpdateState) {
|
|
1795
|
-
|
|
1706
|
+
logger6.debug(
|
|
1796
1707
|
{ sessionId: this.sessionId },
|
|
1797
1708
|
"No status updates configured for time-based check"
|
|
1798
1709
|
);
|
|
@@ -1805,7 +1716,7 @@ var GraphSession = class {
|
|
|
1805
1716
|
try {
|
|
1806
1717
|
await this.generateAndSendUpdate();
|
|
1807
1718
|
} catch (error) {
|
|
1808
|
-
|
|
1719
|
+
logger6.error(
|
|
1809
1720
|
{
|
|
1810
1721
|
sessionId: this.sessionId,
|
|
1811
1722
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1898,29 +1809,29 @@ var GraphSession = class {
|
|
|
1898
1809
|
*/
|
|
1899
1810
|
async generateAndSendUpdate() {
|
|
1900
1811
|
if (this.isEnded) {
|
|
1901
|
-
|
|
1812
|
+
logger6.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
1902
1813
|
return;
|
|
1903
1814
|
}
|
|
1904
1815
|
if (this.isTextStreaming) {
|
|
1905
|
-
|
|
1816
|
+
logger6.debug(
|
|
1906
1817
|
{ sessionId: this.sessionId },
|
|
1907
1818
|
"Text is currently streaming - skipping status update"
|
|
1908
1819
|
);
|
|
1909
1820
|
return;
|
|
1910
1821
|
}
|
|
1911
1822
|
if (this.isGeneratingUpdate) {
|
|
1912
|
-
|
|
1823
|
+
logger6.debug(
|
|
1913
1824
|
{ sessionId: this.sessionId },
|
|
1914
1825
|
"Update already in progress - skipping duplicate generation"
|
|
1915
1826
|
);
|
|
1916
1827
|
return;
|
|
1917
1828
|
}
|
|
1918
1829
|
if (!this.statusUpdateState) {
|
|
1919
|
-
|
|
1830
|
+
logger6.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
1920
1831
|
return;
|
|
1921
1832
|
}
|
|
1922
1833
|
if (!this.graphId) {
|
|
1923
|
-
|
|
1834
|
+
logger6.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
1924
1835
|
return;
|
|
1925
1836
|
}
|
|
1926
1837
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -1933,7 +1844,7 @@ var GraphSession = class {
|
|
|
1933
1844
|
try {
|
|
1934
1845
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
1935
1846
|
if (!streamHelper) {
|
|
1936
|
-
|
|
1847
|
+
logger6.warn(
|
|
1937
1848
|
{ sessionId: this.sessionId },
|
|
1938
1849
|
"No stream helper found - cannot send status update"
|
|
1939
1850
|
);
|
|
@@ -1954,7 +1865,7 @@ var GraphSession = class {
|
|
|
1954
1865
|
if (result.operations && result.operations.length > 0) {
|
|
1955
1866
|
for (const op of result.operations) {
|
|
1956
1867
|
if (!op || !op.type || !op.data || Object.keys(op.data).length === 0) {
|
|
1957
|
-
|
|
1868
|
+
logger6.warn(
|
|
1958
1869
|
{
|
|
1959
1870
|
sessionId: this.sessionId,
|
|
1960
1871
|
operation: op
|
|
@@ -2007,7 +1918,7 @@ var GraphSession = class {
|
|
|
2007
1918
|
this.previousSummaries.shift();
|
|
2008
1919
|
}
|
|
2009
1920
|
if (!operation || !operation.type || !operation.ctx) {
|
|
2010
|
-
|
|
1921
|
+
logger6.warn(
|
|
2011
1922
|
{
|
|
2012
1923
|
sessionId: this.sessionId,
|
|
2013
1924
|
operation
|
|
@@ -2022,7 +1933,7 @@ var GraphSession = class {
|
|
|
2022
1933
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
2023
1934
|
}
|
|
2024
1935
|
} catch (error) {
|
|
2025
|
-
|
|
1936
|
+
logger6.error(
|
|
2026
1937
|
{
|
|
2027
1938
|
sessionId: this.sessionId,
|
|
2028
1939
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -2060,7 +1971,7 @@ var GraphSession = class {
|
|
|
2060
1971
|
this.releaseUpdateLock();
|
|
2061
1972
|
}
|
|
2062
1973
|
} catch (error) {
|
|
2063
|
-
|
|
1974
|
+
logger6.error(
|
|
2064
1975
|
{
|
|
2065
1976
|
sessionId: this.sessionId,
|
|
2066
1977
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2105,7 +2016,7 @@ var GraphSession = class {
|
|
|
2105
2016
|
*/
|
|
2106
2017
|
async generateProgressSummary(newEvents, elapsedTime, summarizerModel, previousSummaries = []) {
|
|
2107
2018
|
return tracer.startActiveSpan(
|
|
2108
|
-
|
|
2019
|
+
"graph_session.generate_progress_summary",
|
|
2109
2020
|
{
|
|
2110
2021
|
attributes: {
|
|
2111
2022
|
"graph_session.id": this.sessionId,
|
|
@@ -2137,7 +2048,7 @@ User's Question/Context:
|
|
|
2137
2048
|
${conversationHistory}
|
|
2138
2049
|
` : "";
|
|
2139
2050
|
} catch (error) {
|
|
2140
|
-
|
|
2051
|
+
logger6.warn(
|
|
2141
2052
|
{ sessionId: this.sessionId, error },
|
|
2142
2053
|
"Failed to fetch conversation history for status update"
|
|
2143
2054
|
);
|
|
@@ -2186,8 +2097,8 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2186
2097
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
2187
2098
|
return text.trim();
|
|
2188
2099
|
} catch (error) {
|
|
2189
|
-
|
|
2190
|
-
|
|
2100
|
+
agentsCore.setSpanWithError(span, error);
|
|
2101
|
+
logger6.error({ error }, "Failed to generate summary, using fallback");
|
|
2191
2102
|
return this.generateFallbackSummary(newEvents, elapsedTime);
|
|
2192
2103
|
} finally {
|
|
2193
2104
|
span.end();
|
|
@@ -2200,7 +2111,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2200
2111
|
*/
|
|
2201
2112
|
async generateStructuredStatusUpdate(newEvents, elapsedTime, statusComponents, summarizerModel, previousSummaries = []) {
|
|
2202
2113
|
return tracer.startActiveSpan(
|
|
2203
|
-
|
|
2114
|
+
"graph_session.generate_structured_update",
|
|
2204
2115
|
{
|
|
2205
2116
|
attributes: {
|
|
2206
2117
|
"graph_session.id": this.sessionId,
|
|
@@ -2233,7 +2144,7 @@ User's Question/Context:
|
|
|
2233
2144
|
${conversationHistory}
|
|
2234
2145
|
` : "";
|
|
2235
2146
|
} catch (error) {
|
|
2236
|
-
|
|
2147
|
+
logger6.warn(
|
|
2237
2148
|
{ sessionId: this.sessionId, error },
|
|
2238
2149
|
"Failed to fetch conversation history for structured status update"
|
|
2239
2150
|
);
|
|
@@ -2329,8 +2240,8 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2329
2240
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
2330
2241
|
return { operations };
|
|
2331
2242
|
} catch (error) {
|
|
2332
|
-
|
|
2333
|
-
|
|
2243
|
+
agentsCore.setSpanWithError(span, error);
|
|
2244
|
+
logger6.error({ error }, "Failed to generate structured update, using fallback");
|
|
2334
2245
|
return { operations: [] };
|
|
2335
2246
|
} finally {
|
|
2336
2247
|
span.end();
|
|
@@ -2515,7 +2426,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2515
2426
|
*/
|
|
2516
2427
|
async processArtifact(artifactData) {
|
|
2517
2428
|
return tracer.startActiveSpan(
|
|
2518
|
-
|
|
2429
|
+
"graph_session.process_artifact",
|
|
2519
2430
|
{
|
|
2520
2431
|
attributes: {
|
|
2521
2432
|
"graph_session.id": this.sessionId,
|
|
@@ -2588,7 +2499,7 @@ Make it specific and relevant.`;
|
|
|
2588
2499
|
description: z5.z.string().max(150).describe("Brief description of the artifact's relevance to the user's question")
|
|
2589
2500
|
});
|
|
2590
2501
|
const { object: result } = await tracer.startActiveSpan(
|
|
2591
|
-
|
|
2502
|
+
"graph_session.generate_artifact_metadata",
|
|
2592
2503
|
{
|
|
2593
2504
|
attributes: {
|
|
2594
2505
|
"llm.model": this.statusUpdateState?.summarizerModel?.model,
|
|
@@ -2621,7 +2532,7 @@ Make it specific and relevant.`;
|
|
|
2621
2532
|
generationSpan.setStatus({ code: api.SpanStatusCode.OK });
|
|
2622
2533
|
return result2;
|
|
2623
2534
|
} catch (error) {
|
|
2624
|
-
|
|
2535
|
+
agentsCore.setSpanWithError(generationSpan, error);
|
|
2625
2536
|
throw error;
|
|
2626
2537
|
} finally {
|
|
2627
2538
|
generationSpan.end();
|
|
@@ -2655,7 +2566,7 @@ Make it specific and relevant.`;
|
|
|
2655
2566
|
taskId: artifactData.taskId,
|
|
2656
2567
|
artifacts: [artifactToSave]
|
|
2657
2568
|
});
|
|
2658
|
-
|
|
2569
|
+
logger6.info(
|
|
2659
2570
|
{
|
|
2660
2571
|
sessionId: this.sessionId,
|
|
2661
2572
|
artifactId: artifactData.artifactId,
|
|
@@ -2671,8 +2582,8 @@ Make it specific and relevant.`;
|
|
|
2671
2582
|
});
|
|
2672
2583
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
2673
2584
|
} catch (error) {
|
|
2674
|
-
|
|
2675
|
-
|
|
2585
|
+
agentsCore.setSpanWithError(span, error);
|
|
2586
|
+
logger6.error(
|
|
2676
2587
|
{
|
|
2677
2588
|
sessionId: this.sessionId,
|
|
2678
2589
|
artifactId: artifactData.artifactId,
|
|
@@ -2708,7 +2619,7 @@ Make it specific and relevant.`;
|
|
|
2708
2619
|
taskId: artifactData.taskId,
|
|
2709
2620
|
artifacts: [fallbackArtifact]
|
|
2710
2621
|
});
|
|
2711
|
-
|
|
2622
|
+
logger6.info(
|
|
2712
2623
|
{
|
|
2713
2624
|
sessionId: this.sessionId,
|
|
2714
2625
|
artifactId: artifactData.artifactId
|
|
@@ -2717,7 +2628,7 @@ Make it specific and relevant.`;
|
|
|
2717
2628
|
);
|
|
2718
2629
|
}
|
|
2719
2630
|
} catch (fallbackError) {
|
|
2720
|
-
|
|
2631
|
+
logger6.error(
|
|
2721
2632
|
{
|
|
2722
2633
|
sessionId: this.sessionId,
|
|
2723
2634
|
artifactId: artifactData.artifactId,
|
|
@@ -2744,7 +2655,7 @@ var GraphSessionManager = class {
|
|
|
2744
2655
|
const sessionId = messageId;
|
|
2745
2656
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId);
|
|
2746
2657
|
this.sessions.set(sessionId, session);
|
|
2747
|
-
|
|
2658
|
+
logger6.info({ sessionId, messageId, graphId, tenantId, projectId }, "GraphSession created");
|
|
2748
2659
|
return sessionId;
|
|
2749
2660
|
}
|
|
2750
2661
|
/**
|
|
@@ -2755,7 +2666,7 @@ var GraphSessionManager = class {
|
|
|
2755
2666
|
if (session) {
|
|
2756
2667
|
session.initializeStatusUpdates(config2, summarizerModel);
|
|
2757
2668
|
} else {
|
|
2758
|
-
|
|
2669
|
+
logger6.error(
|
|
2759
2670
|
{
|
|
2760
2671
|
sessionId,
|
|
2761
2672
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -2776,7 +2687,7 @@ var GraphSessionManager = class {
|
|
|
2776
2687
|
recordEvent(sessionId, eventType, agentId, data) {
|
|
2777
2688
|
const session = this.sessions.get(sessionId);
|
|
2778
2689
|
if (!session) {
|
|
2779
|
-
|
|
2690
|
+
logger6.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
2780
2691
|
return;
|
|
2781
2692
|
}
|
|
2782
2693
|
session.recordEvent(eventType, agentId, data);
|
|
@@ -2787,12 +2698,12 @@ var GraphSessionManager = class {
|
|
|
2787
2698
|
endSession(sessionId) {
|
|
2788
2699
|
const session = this.sessions.get(sessionId);
|
|
2789
2700
|
if (!session) {
|
|
2790
|
-
|
|
2701
|
+
logger6.warn({ sessionId }, "Attempted to end non-existent session");
|
|
2791
2702
|
return [];
|
|
2792
2703
|
}
|
|
2793
2704
|
const events = session.getEvents();
|
|
2794
2705
|
const summary = session.getSummary();
|
|
2795
|
-
|
|
2706
|
+
logger6.info({ sessionId, summary }, "GraphSession ended");
|
|
2796
2707
|
session.cleanup();
|
|
2797
2708
|
this.sessions.delete(sessionId);
|
|
2798
2709
|
return events;
|
|
@@ -2821,7 +2732,7 @@ var graphSessionManager = new GraphSessionManager();
|
|
|
2821
2732
|
|
|
2822
2733
|
// src/utils/artifact-parser.ts
|
|
2823
2734
|
init_dbClient();
|
|
2824
|
-
var
|
|
2735
|
+
var logger7 = getLogger("ArtifactParser");
|
|
2825
2736
|
var _ArtifactParser = class _ArtifactParser {
|
|
2826
2737
|
constructor(tenantId) {
|
|
2827
2738
|
this.tenantId = tenantId;
|
|
@@ -2885,7 +2796,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2885
2796
|
id: taskId
|
|
2886
2797
|
});
|
|
2887
2798
|
if (!task) {
|
|
2888
|
-
|
|
2799
|
+
logger7.warn({ taskId }, "Task not found when fetching artifacts");
|
|
2889
2800
|
continue;
|
|
2890
2801
|
}
|
|
2891
2802
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -2897,9 +2808,9 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2897
2808
|
artifacts.set(key, artifact);
|
|
2898
2809
|
}
|
|
2899
2810
|
}
|
|
2900
|
-
|
|
2811
|
+
logger7.debug({ contextId, count: artifacts.size }, "Loaded context artifacts");
|
|
2901
2812
|
} catch (error) {
|
|
2902
|
-
|
|
2813
|
+
logger7.error({ error, contextId }, "Error loading context artifacts");
|
|
2903
2814
|
}
|
|
2904
2815
|
return artifacts;
|
|
2905
2816
|
}
|
|
@@ -3002,7 +2913,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
3002
2913
|
id: taskId
|
|
3003
2914
|
});
|
|
3004
2915
|
if (!task) {
|
|
3005
|
-
|
|
2916
|
+
logger7.warn({ taskId }, "Task not found when fetching artifact");
|
|
3006
2917
|
return null;
|
|
3007
2918
|
}
|
|
3008
2919
|
const artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -3014,7 +2925,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
3014
2925
|
return this.formatArtifactData(artifacts[0], artifactId, taskId);
|
|
3015
2926
|
}
|
|
3016
2927
|
} catch (error) {
|
|
3017
|
-
|
|
2928
|
+
logger7.warn({ artifactId, taskId, error }, "Failed to fetch artifact");
|
|
3018
2929
|
}
|
|
3019
2930
|
return null;
|
|
3020
2931
|
}
|
|
@@ -3054,7 +2965,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_ARTIFACT_REGEX", /<(a(r(t(i(f(a(c(t(:
|
|
|
3054
2965
|
var ArtifactParser = _ArtifactParser;
|
|
3055
2966
|
|
|
3056
2967
|
// src/utils/incremental-stream-parser.ts
|
|
3057
|
-
var
|
|
2968
|
+
var logger8 = getLogger("IncrementalStreamParser");
|
|
3058
2969
|
var IncrementalStreamParser = class {
|
|
3059
2970
|
constructor(streamHelper, tenantId, contextId) {
|
|
3060
2971
|
__publicField(this, "buffer", "");
|
|
@@ -3114,13 +3025,13 @@ var IncrementalStreamParser = class {
|
|
|
3114
3025
|
if (part.type === "tool-call-delta" && part.toolName === targetToolName) {
|
|
3115
3026
|
const delta = part.argsTextDelta || "";
|
|
3116
3027
|
if (jsonBuffer.length + delta.length > MAX_BUFFER_SIZE) {
|
|
3117
|
-
|
|
3028
|
+
logger8.warn("JSON buffer exceeded maximum size, truncating");
|
|
3118
3029
|
jsonBuffer = jsonBuffer.slice(-MAX_BUFFER_SIZE / 2);
|
|
3119
3030
|
}
|
|
3120
3031
|
jsonBuffer += delta;
|
|
3121
3032
|
for (const char of delta) {
|
|
3122
3033
|
if (componentBuffer.length > MAX_BUFFER_SIZE) {
|
|
3123
|
-
|
|
3034
|
+
logger8.warn("Component buffer exceeded maximum size, resetting");
|
|
3124
3035
|
componentBuffer = "";
|
|
3125
3036
|
depth = 0;
|
|
3126
3037
|
continue;
|
|
@@ -3135,7 +3046,7 @@ var IncrementalStreamParser = class {
|
|
|
3135
3046
|
if (componentMatch) {
|
|
3136
3047
|
const MAX_COMPONENT_SIZE = 1024 * 1024;
|
|
3137
3048
|
if (componentMatch[0].length > MAX_COMPONENT_SIZE) {
|
|
3138
|
-
|
|
3049
|
+
logger8.warn(
|
|
3139
3050
|
{
|
|
3140
3051
|
size: componentMatch[0].length,
|
|
3141
3052
|
maxSize: MAX_COMPONENT_SIZE
|
|
@@ -3148,7 +3059,7 @@ var IncrementalStreamParser = class {
|
|
|
3148
3059
|
try {
|
|
3149
3060
|
const component = JSON.parse(componentMatch[0]);
|
|
3150
3061
|
if (typeof component !== "object" || !component.id) {
|
|
3151
|
-
|
|
3062
|
+
logger8.warn("Invalid component structure, skipping");
|
|
3152
3063
|
componentBuffer = "";
|
|
3153
3064
|
continue;
|
|
3154
3065
|
}
|
|
@@ -3161,7 +3072,7 @@ var IncrementalStreamParser = class {
|
|
|
3161
3072
|
componentsStreamed++;
|
|
3162
3073
|
componentBuffer = "";
|
|
3163
3074
|
} catch (e) {
|
|
3164
|
-
|
|
3075
|
+
logger8.debug({ error: e }, "Failed to parse component, continuing to accumulate");
|
|
3165
3076
|
}
|
|
3166
3077
|
}
|
|
3167
3078
|
}
|
|
@@ -3178,7 +3089,7 @@ var IncrementalStreamParser = class {
|
|
|
3178
3089
|
break;
|
|
3179
3090
|
}
|
|
3180
3091
|
}
|
|
3181
|
-
|
|
3092
|
+
logger8.debug({ componentsStreamed }, "Finished streaming components");
|
|
3182
3093
|
}
|
|
3183
3094
|
/**
|
|
3184
3095
|
* Legacy method for backward compatibility - defaults to text processing
|
|
@@ -3320,12 +3231,9 @@ var IncrementalStreamParser = class {
|
|
|
3320
3231
|
}
|
|
3321
3232
|
}
|
|
3322
3233
|
};
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
const tracerProvider = api.trace.getTracerProvider();
|
|
3327
|
-
return tracerProvider.getTracer(RESPONSE_FORMATTER_SERVICE, SERVICE_VERSION);
|
|
3328
|
-
}
|
|
3234
|
+
|
|
3235
|
+
// src/utils/response-formatter.ts
|
|
3236
|
+
var logger9 = getLogger("ResponseFormatter");
|
|
3329
3237
|
var ResponseFormatter = class {
|
|
3330
3238
|
constructor(tenantId) {
|
|
3331
3239
|
__publicField(this, "artifactParser");
|
|
@@ -3335,8 +3243,7 @@ var ResponseFormatter = class {
|
|
|
3335
3243
|
* Process structured object response and replace artifact markers with actual artifacts
|
|
3336
3244
|
*/
|
|
3337
3245
|
async formatObjectResponse(responseObject, contextId) {
|
|
3338
|
-
|
|
3339
|
-
return tracer3.startActiveSpan("response.formatObject", async (span) => {
|
|
3246
|
+
return tracer.startActiveSpan("response.format_object_response", async (span) => {
|
|
3340
3247
|
try {
|
|
3341
3248
|
const artifactMap = await this.artifactParser.getContextArtifacts(contextId);
|
|
3342
3249
|
span.setAttributes({
|
|
@@ -3356,8 +3263,8 @@ var ResponseFormatter = class {
|
|
|
3356
3263
|
});
|
|
3357
3264
|
return { parts };
|
|
3358
3265
|
} catch (error) {
|
|
3359
|
-
|
|
3360
|
-
|
|
3266
|
+
agentsCore.setSpanWithError(span, error);
|
|
3267
|
+
logger9.error({ error, responseObject }, "Error formatting object response");
|
|
3361
3268
|
return {
|
|
3362
3269
|
parts: [{ kind: "data", data: responseObject }]
|
|
3363
3270
|
};
|
|
@@ -3370,8 +3277,7 @@ var ResponseFormatter = class {
|
|
|
3370
3277
|
* Process agent response and convert artifact markers to data parts
|
|
3371
3278
|
*/
|
|
3372
3279
|
async formatResponse(responseText, contextId) {
|
|
3373
|
-
|
|
3374
|
-
return tracer3.startActiveSpan("response.format", async (span) => {
|
|
3280
|
+
return tracer.startActiveSpan("response.format_response", async (span) => {
|
|
3375
3281
|
try {
|
|
3376
3282
|
span.setAttributes({
|
|
3377
3283
|
"response.hasArtifactMarkers": this.artifactParser.hasArtifactMarkers(responseText),
|
|
@@ -3408,9 +3314,8 @@ var ResponseFormatter = class {
|
|
|
3408
3314
|
});
|
|
3409
3315
|
return { parts };
|
|
3410
3316
|
} catch (error) {
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
logger10.error({ error, responseText }, "Error formatting response");
|
|
3317
|
+
agentsCore.setSpanWithError(span, error);
|
|
3318
|
+
logger9.error({ error, responseText }, "Error formatting response");
|
|
3414
3319
|
return { text: responseText };
|
|
3415
3320
|
} finally {
|
|
3416
3321
|
span.end();
|
|
@@ -3455,7 +3360,7 @@ var ResponseFormatter = class {
|
|
|
3455
3360
|
}
|
|
3456
3361
|
}
|
|
3457
3362
|
};
|
|
3458
|
-
var
|
|
3363
|
+
var logger10 = getLogger("ToolSessionManager");
|
|
3459
3364
|
var _ToolSessionManager = class _ToolSessionManager {
|
|
3460
3365
|
// 5 minutes
|
|
3461
3366
|
constructor() {
|
|
@@ -3484,7 +3389,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3484
3389
|
createdAt: Date.now()
|
|
3485
3390
|
};
|
|
3486
3391
|
this.sessions.set(sessionId, session);
|
|
3487
|
-
|
|
3392
|
+
logger10.debug({ sessionId, tenantId, contextId, taskId }, "Created tool session");
|
|
3488
3393
|
return sessionId;
|
|
3489
3394
|
}
|
|
3490
3395
|
/**
|
|
@@ -3493,7 +3398,7 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3493
3398
|
recordToolResult(sessionId, toolResult) {
|
|
3494
3399
|
const session = this.sessions.get(sessionId);
|
|
3495
3400
|
if (!session) {
|
|
3496
|
-
|
|
3401
|
+
logger10.warn(
|
|
3497
3402
|
{ sessionId, toolCallId: toolResult.toolCallId },
|
|
3498
3403
|
"Tool result recorded for unknown session"
|
|
3499
3404
|
);
|
|
@@ -3507,12 +3412,12 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3507
3412
|
getToolResult(sessionId, toolCallId) {
|
|
3508
3413
|
const session = this.sessions.get(sessionId);
|
|
3509
3414
|
if (!session) {
|
|
3510
|
-
|
|
3415
|
+
logger10.warn({ sessionId, toolCallId }, "Requested tool result for unknown session");
|
|
3511
3416
|
return void 0;
|
|
3512
3417
|
}
|
|
3513
3418
|
const result = session.toolResults.get(toolCallId);
|
|
3514
3419
|
if (!result) {
|
|
3515
|
-
|
|
3420
|
+
logger10.warn(
|
|
3516
3421
|
{
|
|
3517
3422
|
sessionId,
|
|
3518
3423
|
toolCallId,
|
|
@@ -3551,10 +3456,10 @@ var _ToolSessionManager = class _ToolSessionManager {
|
|
|
3551
3456
|
}
|
|
3552
3457
|
for (const sessionId of expiredSessions) {
|
|
3553
3458
|
this.sessions.delete(sessionId);
|
|
3554
|
-
|
|
3459
|
+
logger10.debug({ sessionId }, "Cleaned up expired tool session");
|
|
3555
3460
|
}
|
|
3556
3461
|
if (expiredSessions.length > 0) {
|
|
3557
|
-
|
|
3462
|
+
logger10.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
3558
3463
|
}
|
|
3559
3464
|
}
|
|
3560
3465
|
};
|
|
@@ -3563,7 +3468,7 @@ var ToolSessionManager = _ToolSessionManager;
|
|
|
3563
3468
|
var toolSessionManager = ToolSessionManager.getInstance();
|
|
3564
3469
|
|
|
3565
3470
|
// src/agents/artifactTools.ts
|
|
3566
|
-
var
|
|
3471
|
+
var logger11 = getLogger("artifactTools");
|
|
3567
3472
|
function buildKeyNestingMap(data, prefix = "", map = /* @__PURE__ */ new Map()) {
|
|
3568
3473
|
if (typeof data === "object" && data !== null) {
|
|
3569
3474
|
if (Array.isArray(data)) {
|
|
@@ -3784,7 +3689,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3784
3689
|
execute: async ({ toolCallId, baseSelector, propSelectors, ...rest }, _context) => {
|
|
3785
3690
|
const artifactType = "artifactType" in rest ? rest.artifactType : void 0;
|
|
3786
3691
|
if (!sessionId) {
|
|
3787
|
-
|
|
3692
|
+
logger11.warn({ toolCallId }, "No session ID provided to save_tool_result");
|
|
3788
3693
|
return {
|
|
3789
3694
|
saved: false,
|
|
3790
3695
|
error: `[toolCallId: ${toolCallId}] No session context available`,
|
|
@@ -3794,7 +3699,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3794
3699
|
}
|
|
3795
3700
|
const toolResult = toolSessionManager.getToolResult(sessionId, toolCallId);
|
|
3796
3701
|
if (!toolResult) {
|
|
3797
|
-
|
|
3702
|
+
logger11.warn({ toolCallId, sessionId }, "Tool result not found in session");
|
|
3798
3703
|
return {
|
|
3799
3704
|
saved: false,
|
|
3800
3705
|
error: `[toolCallId: ${toolCallId}] Tool result not found`,
|
|
@@ -3807,7 +3712,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3807
3712
|
const baseData = jmespath__default.default.search(parsedResult, baseSelector);
|
|
3808
3713
|
if (!baseData || Array.isArray(baseData) && baseData.length === 0) {
|
|
3809
3714
|
const debugInfo = analyzeSelectorFailure(parsedResult, baseSelector);
|
|
3810
|
-
|
|
3715
|
+
logger11.warn(
|
|
3811
3716
|
{
|
|
3812
3717
|
baseSelector,
|
|
3813
3718
|
toolCallId,
|
|
@@ -3850,7 +3755,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3850
3755
|
const fallbackValue = item[propName];
|
|
3851
3756
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3852
3757
|
extractedItem[propName] = fallbackValue;
|
|
3853
|
-
|
|
3758
|
+
logger11.info(
|
|
3854
3759
|
{ propName, propSelector, context },
|
|
3855
3760
|
`PropSelector failed, used fallback direct property access`
|
|
3856
3761
|
);
|
|
@@ -3862,7 +3767,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3862
3767
|
const fallbackValue = item[propName];
|
|
3863
3768
|
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
3864
3769
|
extractedItem[propName] = fallbackValue;
|
|
3865
|
-
|
|
3770
|
+
logger11.warn(
|
|
3866
3771
|
{ propName, propSelector, context, error: error.message },
|
|
3867
3772
|
`PropSelector syntax error, used fallback direct property access`
|
|
3868
3773
|
);
|
|
@@ -3975,7 +3880,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3975
3880
|
warnings
|
|
3976
3881
|
};
|
|
3977
3882
|
} catch (error) {
|
|
3978
|
-
|
|
3883
|
+
logger11.error({ error, toolCallId, sessionId }, "Error processing save_tool_result");
|
|
3979
3884
|
return {
|
|
3980
3885
|
saved: false,
|
|
3981
3886
|
error: `[toolCallId: ${toolCallId}] ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
@@ -3987,7 +3892,7 @@ Remember: Each time you call this tool, you create a separate data component. Ca
|
|
|
3987
3892
|
}
|
|
3988
3893
|
|
|
3989
3894
|
// src/a2a/client.ts
|
|
3990
|
-
var
|
|
3895
|
+
var logger12 = getLogger("a2aClient");
|
|
3991
3896
|
var DEFAULT_BACKOFF = {
|
|
3992
3897
|
initialInterval: 500,
|
|
3993
3898
|
maxInterval: 6e4,
|
|
@@ -4193,7 +4098,7 @@ var A2AClient = class {
|
|
|
4193
4098
|
try {
|
|
4194
4099
|
const res = await fn();
|
|
4195
4100
|
if (attempt > 0) {
|
|
4196
|
-
|
|
4101
|
+
logger12.info(
|
|
4197
4102
|
{
|
|
4198
4103
|
attempts: attempt + 1,
|
|
4199
4104
|
elapsedTime: Date.now() - start
|
|
@@ -4208,7 +4113,7 @@ var A2AClient = class {
|
|
|
4208
4113
|
}
|
|
4209
4114
|
const elapsed = Date.now() - start;
|
|
4210
4115
|
if (elapsed > maxElapsedTime) {
|
|
4211
|
-
|
|
4116
|
+
logger12.warn(
|
|
4212
4117
|
{
|
|
4213
4118
|
attempts: attempt + 1,
|
|
4214
4119
|
elapsedTime: elapsed,
|
|
@@ -4229,7 +4134,7 @@ var A2AClient = class {
|
|
|
4229
4134
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
4230
4135
|
}
|
|
4231
4136
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
4232
|
-
|
|
4137
|
+
logger12.info(
|
|
4233
4138
|
{
|
|
4234
4139
|
attempt: attempt + 1,
|
|
4235
4140
|
delayMs,
|
|
@@ -4314,7 +4219,7 @@ var A2AClient = class {
|
|
|
4314
4219
|
}
|
|
4315
4220
|
const rpcResponse = await httpResponse.json();
|
|
4316
4221
|
if (rpcResponse.id !== requestId2) {
|
|
4317
|
-
|
|
4222
|
+
logger12.warn(
|
|
4318
4223
|
{
|
|
4319
4224
|
method,
|
|
4320
4225
|
expectedId: requestId2,
|
|
@@ -4513,7 +4418,7 @@ var A2AClient = class {
|
|
|
4513
4418
|
try {
|
|
4514
4419
|
while (true) {
|
|
4515
4420
|
const { done, value } = await reader.read();
|
|
4516
|
-
|
|
4421
|
+
logger12.info({ done, value }, "parseA2ASseStream");
|
|
4517
4422
|
if (done) {
|
|
4518
4423
|
if (eventDataBuffer.trim()) {
|
|
4519
4424
|
const result = this._processSseEventData(
|
|
@@ -4602,7 +4507,7 @@ var A2AClient = class {
|
|
|
4602
4507
|
// src/agents/relationTools.ts
|
|
4603
4508
|
init_conversations();
|
|
4604
4509
|
init_dbClient();
|
|
4605
|
-
var
|
|
4510
|
+
var logger13 = getLogger("relationships Tools");
|
|
4606
4511
|
var generateTransferToolDescription = (config2) => {
|
|
4607
4512
|
return `Hand off the conversation to agent ${config2.id}.
|
|
4608
4513
|
|
|
@@ -4640,7 +4545,7 @@ var createTransferToAgentTool = ({
|
|
|
4640
4545
|
"transfer.to_agent_id": transferConfig.id ?? "unknown"
|
|
4641
4546
|
});
|
|
4642
4547
|
}
|
|
4643
|
-
|
|
4548
|
+
logger13.info(
|
|
4644
4549
|
{
|
|
4645
4550
|
transferTo: transferConfig.id ?? "unknown",
|
|
4646
4551
|
fromAgent: callingAgentId
|
|
@@ -4788,7 +4693,7 @@ function createDelegateToAgentTool({
|
|
|
4788
4693
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
4789
4694
|
}
|
|
4790
4695
|
};
|
|
4791
|
-
|
|
4696
|
+
logger13.info({ messageToSend }, "messageToSend");
|
|
4792
4697
|
await agentsCore.createMessage(dbClient_default)({
|
|
4793
4698
|
id: nanoid.nanoid(),
|
|
4794
4699
|
tenantId,
|
|
@@ -4848,7 +4753,7 @@ function createDelegateToAgentTool({
|
|
|
4848
4753
|
}
|
|
4849
4754
|
});
|
|
4850
4755
|
}
|
|
4851
|
-
var
|
|
4756
|
+
var logger14 = getLogger("SystemPromptBuilder");
|
|
4852
4757
|
var SystemPromptBuilder = class {
|
|
4853
4758
|
constructor(version, versionConfig) {
|
|
4854
4759
|
this.version = version;
|
|
@@ -4872,9 +4777,9 @@ var SystemPromptBuilder = class {
|
|
|
4872
4777
|
this.templates.set(name, content);
|
|
4873
4778
|
}
|
|
4874
4779
|
this.loaded = true;
|
|
4875
|
-
|
|
4780
|
+
logger14.debug(`Loaded ${this.templates.size} templates for version ${this.version}`);
|
|
4876
4781
|
} catch (error) {
|
|
4877
|
-
|
|
4782
|
+
logger14.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
4878
4783
|
throw new Error(`Template loading failed: ${error}`);
|
|
4879
4784
|
}
|
|
4880
4785
|
}
|
|
@@ -5210,8 +5115,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
5210
5115
|
return false;
|
|
5211
5116
|
};
|
|
5212
5117
|
}
|
|
5213
|
-
var
|
|
5214
|
-
var tracer2 = getGlobalTracer();
|
|
5118
|
+
var logger15 = getLogger("Agent");
|
|
5215
5119
|
var CONSTANTS = {
|
|
5216
5120
|
MAX_GENERATION_STEPS: 12,
|
|
5217
5121
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -5464,14 +5368,14 @@ var Agent = class {
|
|
|
5464
5368
|
for (const toolSet of tools) {
|
|
5465
5369
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
5466
5370
|
if (!isValidTool(originalTool)) {
|
|
5467
|
-
|
|
5371
|
+
logger15.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
5468
5372
|
continue;
|
|
5469
5373
|
}
|
|
5470
5374
|
const sessionWrappedTool = ai.tool({
|
|
5471
5375
|
description: originalTool.description,
|
|
5472
5376
|
inputSchema: originalTool.inputSchema,
|
|
5473
5377
|
execute: async (args, { toolCallId }) => {
|
|
5474
|
-
|
|
5378
|
+
logger15.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
5475
5379
|
try {
|
|
5476
5380
|
const result = await originalTool.execute(args, { toolCallId });
|
|
5477
5381
|
toolSessionManager.recordToolResult(sessionId, {
|
|
@@ -5483,7 +5387,7 @@ var Agent = class {
|
|
|
5483
5387
|
});
|
|
5484
5388
|
return { result, toolCallId };
|
|
5485
5389
|
} catch (error) {
|
|
5486
|
-
|
|
5390
|
+
logger15.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
5487
5391
|
throw error;
|
|
5488
5392
|
}
|
|
5489
5393
|
}
|
|
@@ -5568,7 +5472,7 @@ var Agent = class {
|
|
|
5568
5472
|
selectedTools
|
|
5569
5473
|
};
|
|
5570
5474
|
}
|
|
5571
|
-
|
|
5475
|
+
logger15.info(
|
|
5572
5476
|
{
|
|
5573
5477
|
toolName: tool4.name,
|
|
5574
5478
|
credentialReferenceId,
|
|
@@ -5608,7 +5512,7 @@ var Agent = class {
|
|
|
5608
5512
|
async getResolvedContext(conversationId, requestContext) {
|
|
5609
5513
|
try {
|
|
5610
5514
|
if (!this.config.contextConfigId) {
|
|
5611
|
-
|
|
5515
|
+
logger15.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
5612
5516
|
return null;
|
|
5613
5517
|
}
|
|
5614
5518
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -5616,7 +5520,7 @@ var Agent = class {
|
|
|
5616
5520
|
id: this.config.contextConfigId
|
|
5617
5521
|
});
|
|
5618
5522
|
if (!contextConfig) {
|
|
5619
|
-
|
|
5523
|
+
logger15.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
5620
5524
|
return null;
|
|
5621
5525
|
}
|
|
5622
5526
|
if (!this.contextResolver) {
|
|
@@ -5633,7 +5537,7 @@ var Agent = class {
|
|
|
5633
5537
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5634
5538
|
$env: process.env
|
|
5635
5539
|
};
|
|
5636
|
-
|
|
5540
|
+
logger15.debug(
|
|
5637
5541
|
{
|
|
5638
5542
|
conversationId,
|
|
5639
5543
|
contextConfigId: contextConfig.id,
|
|
@@ -5647,7 +5551,7 @@ var Agent = class {
|
|
|
5647
5551
|
);
|
|
5648
5552
|
return contextWithBuiltins;
|
|
5649
5553
|
} catch (error) {
|
|
5650
|
-
|
|
5554
|
+
logger15.error(
|
|
5651
5555
|
{
|
|
5652
5556
|
conversationId,
|
|
5653
5557
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5671,7 +5575,7 @@ var Agent = class {
|
|
|
5671
5575
|
});
|
|
5672
5576
|
return graphDefinition?.graphPrompt || void 0;
|
|
5673
5577
|
} catch (error) {
|
|
5674
|
-
|
|
5578
|
+
logger15.warn(
|
|
5675
5579
|
{
|
|
5676
5580
|
graphId: this.config.graphId,
|
|
5677
5581
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5698,7 +5602,7 @@ var Agent = class {
|
|
|
5698
5602
|
}
|
|
5699
5603
|
return !!(graphDefinition.artifactComponents && Object.keys(graphDefinition.artifactComponents).length > 0);
|
|
5700
5604
|
} catch (error) {
|
|
5701
|
-
|
|
5605
|
+
logger15.warn(
|
|
5702
5606
|
{
|
|
5703
5607
|
graphId: this.config.graphId,
|
|
5704
5608
|
tenantId: this.config.tenantId,
|
|
@@ -5758,7 +5662,7 @@ Key requirements:
|
|
|
5758
5662
|
preserveUnresolved: false
|
|
5759
5663
|
});
|
|
5760
5664
|
} catch (error) {
|
|
5761
|
-
|
|
5665
|
+
logger15.error(
|
|
5762
5666
|
{
|
|
5763
5667
|
conversationId,
|
|
5764
5668
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5803,7 +5707,7 @@ Key requirements:
|
|
|
5803
5707
|
preserveUnresolved: false
|
|
5804
5708
|
});
|
|
5805
5709
|
} catch (error) {
|
|
5806
|
-
|
|
5710
|
+
logger15.error(
|
|
5807
5711
|
{
|
|
5808
5712
|
conversationId,
|
|
5809
5713
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -5831,7 +5735,7 @@ Key requirements:
|
|
|
5831
5735
|
artifactId: z5.z.string().describe("The unique identifier of the artifact to get.")
|
|
5832
5736
|
}),
|
|
5833
5737
|
execute: async ({ artifactId }) => {
|
|
5834
|
-
|
|
5738
|
+
logger15.info({ artifactId }, "get_artifact executed");
|
|
5835
5739
|
const artifact = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
5836
5740
|
scopes: {
|
|
5837
5741
|
tenantId: this.config.tenantId,
|
|
@@ -5898,7 +5802,7 @@ Key requirements:
|
|
|
5898
5802
|
graphId: this.config.graphId
|
|
5899
5803
|
});
|
|
5900
5804
|
} catch (error) {
|
|
5901
|
-
|
|
5805
|
+
logger15.error(
|
|
5902
5806
|
{ error, graphId: this.config.graphId },
|
|
5903
5807
|
"Failed to check graph artifact components"
|
|
5904
5808
|
);
|
|
@@ -5906,7 +5810,7 @@ Key requirements:
|
|
|
5906
5810
|
}
|
|
5907
5811
|
}
|
|
5908
5812
|
async generate(userMessage, runtimeContext) {
|
|
5909
|
-
return
|
|
5813
|
+
return tracer.startActiveSpan("agent.generate", async (span) => {
|
|
5910
5814
|
const contextId = runtimeContext?.contextId || "default";
|
|
5911
5815
|
const taskId = runtimeContext?.metadata?.taskId || "unknown";
|
|
5912
5816
|
const sessionId = toolSessionManager.createSession(
|
|
@@ -5930,8 +5834,8 @@ Key requirements:
|
|
|
5930
5834
|
functionTools,
|
|
5931
5835
|
relationTools,
|
|
5932
5836
|
defaultTools
|
|
5933
|
-
] = await
|
|
5934
|
-
|
|
5837
|
+
] = await tracer.startActiveSpan(
|
|
5838
|
+
"agent.load_tools",
|
|
5935
5839
|
{
|
|
5936
5840
|
attributes: {
|
|
5937
5841
|
"agent.name": this.config.name,
|
|
@@ -5953,11 +5857,10 @@ Key requirements:
|
|
|
5953
5857
|
childSpan.setStatus({ code: api.SpanStatusCode.OK });
|
|
5954
5858
|
return result;
|
|
5955
5859
|
} catch (err) {
|
|
5956
|
-
|
|
5860
|
+
agentsCore.setSpanWithError(childSpan, err);
|
|
5957
5861
|
throw err;
|
|
5958
5862
|
} finally {
|
|
5959
5863
|
childSpan.end();
|
|
5960
|
-
await forceFlushTracer();
|
|
5961
5864
|
}
|
|
5962
5865
|
}
|
|
5963
5866
|
);
|
|
@@ -6003,7 +5906,7 @@ Key requirements:
|
|
|
6003
5906
|
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;
|
|
6004
5907
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
6005
5908
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
6006
|
-
|
|
5909
|
+
logger15.warn(
|
|
6007
5910
|
{
|
|
6008
5911
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
6009
5912
|
appliedTimeout: timeoutMs,
|
|
@@ -6045,7 +5948,7 @@ Key requirements:
|
|
|
6045
5948
|
}
|
|
6046
5949
|
);
|
|
6047
5950
|
} catch (error) {
|
|
6048
|
-
|
|
5951
|
+
logger15.debug("Failed to track agent reasoning");
|
|
6049
5952
|
}
|
|
6050
5953
|
}
|
|
6051
5954
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -6128,7 +6031,7 @@ Key requirements:
|
|
|
6128
6031
|
}
|
|
6129
6032
|
);
|
|
6130
6033
|
} catch (error) {
|
|
6131
|
-
|
|
6034
|
+
logger15.debug("Failed to track agent reasoning");
|
|
6132
6035
|
}
|
|
6133
6036
|
}
|
|
6134
6037
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -6173,7 +6076,7 @@ Key requirements:
|
|
|
6173
6076
|
return;
|
|
6174
6077
|
}
|
|
6175
6078
|
if (toolName === "save_artifact_tool" || toolName === "save_tool_result") {
|
|
6176
|
-
|
|
6079
|
+
logger15.info({ result }, "save_artifact_tool or save_tool_result");
|
|
6177
6080
|
if (result.output.artifacts) {
|
|
6178
6081
|
for (const artifact of result.output.artifacts) {
|
|
6179
6082
|
const artifactId = artifact?.artifactId || "N/A";
|
|
@@ -6279,7 +6182,6 @@ ${output}`;
|
|
|
6279
6182
|
}
|
|
6280
6183
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
6281
6184
|
span.end();
|
|
6282
|
-
await forceFlushTracer();
|
|
6283
6185
|
let formattedContent = response.formattedContent || null;
|
|
6284
6186
|
if (!formattedContent) {
|
|
6285
6187
|
if (response.object) {
|
|
@@ -6309,14 +6211,8 @@ ${output}`;
|
|
|
6309
6211
|
return formattedResponse;
|
|
6310
6212
|
} catch (error) {
|
|
6311
6213
|
toolSessionManager.endSession(sessionId);
|
|
6312
|
-
|
|
6313
|
-
span.setStatus({
|
|
6314
|
-
code: api.SpanStatusCode.ERROR,
|
|
6315
|
-
message: error.message
|
|
6316
|
-
});
|
|
6214
|
+
agentsCore.setSpanWithError(span, error);
|
|
6317
6215
|
span.end();
|
|
6318
|
-
await forceFlushTracer();
|
|
6319
|
-
getLogger("Agent").error(error, "Agent generate error");
|
|
6320
6216
|
throw error;
|
|
6321
6217
|
}
|
|
6322
6218
|
});
|
|
@@ -6334,7 +6230,7 @@ function parseEmbeddedJson(data) {
|
|
|
6334
6230
|
}
|
|
6335
6231
|
});
|
|
6336
6232
|
}
|
|
6337
|
-
var
|
|
6233
|
+
var logger16 = getLogger("generateTaskHandler");
|
|
6338
6234
|
var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
6339
6235
|
return async (task) => {
|
|
6340
6236
|
try {
|
|
@@ -6384,7 +6280,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6384
6280
|
agentId: config2.agentId
|
|
6385
6281
|
})
|
|
6386
6282
|
]);
|
|
6387
|
-
|
|
6283
|
+
logger16.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
6388
6284
|
const agentPrompt = "prompt" in config2.agentSchema ? config2.agentSchema.prompt : "";
|
|
6389
6285
|
const models = "models" in config2.agentSchema ? config2.agentSchema.models : void 0;
|
|
6390
6286
|
const stopWhen = "stopWhen" in config2.agentSchema ? config2.agentSchema.stopWhen : void 0;
|
|
@@ -6484,7 +6380,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6484
6380
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
6485
6381
|
if (taskIdMatch) {
|
|
6486
6382
|
contextId = taskIdMatch[1];
|
|
6487
|
-
|
|
6383
|
+
logger16.info(
|
|
6488
6384
|
{
|
|
6489
6385
|
taskId: task.id,
|
|
6490
6386
|
extractedContextId: contextId,
|
|
@@ -6500,7 +6396,7 @@ var createTaskHandler = (config2, credentialStoreRegistry) => {
|
|
|
6500
6396
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
6501
6397
|
agent.setDelegationStatus(isDelegation);
|
|
6502
6398
|
if (isDelegation) {
|
|
6503
|
-
|
|
6399
|
+
logger16.info(
|
|
6504
6400
|
{ agentId: config2.agentId, taskId: task.id },
|
|
6505
6401
|
"Delegated agent - streaming disabled"
|
|
6506
6402
|
);
|
|
@@ -6783,7 +6679,7 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
|
6783
6679
|
// src/routes/agents.ts
|
|
6784
6680
|
init_dbClient();
|
|
6785
6681
|
var app = new zodOpenapi.OpenAPIHono();
|
|
6786
|
-
var
|
|
6682
|
+
var logger17 = getLogger("agents");
|
|
6787
6683
|
app.openapi(
|
|
6788
6684
|
zodOpenapi.createRoute({
|
|
6789
6685
|
method: "get",
|
|
@@ -6821,7 +6717,7 @@ app.openapi(
|
|
|
6821
6717
|
tracestate: c.req.header("tracestate"),
|
|
6822
6718
|
baggage: c.req.header("baggage")
|
|
6823
6719
|
};
|
|
6824
|
-
|
|
6720
|
+
logger17.info(
|
|
6825
6721
|
{
|
|
6826
6722
|
otelHeaders,
|
|
6827
6723
|
path: c.req.path,
|
|
@@ -6832,7 +6728,7 @@ app.openapi(
|
|
|
6832
6728
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
6833
6729
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6834
6730
|
if (agentId) {
|
|
6835
|
-
|
|
6731
|
+
logger17.info(
|
|
6836
6732
|
{
|
|
6837
6733
|
message: "getRegisteredAgent (agent-level)",
|
|
6838
6734
|
tenantId,
|
|
@@ -6844,13 +6740,13 @@ app.openapi(
|
|
|
6844
6740
|
);
|
|
6845
6741
|
const credentialStores = c.get("credentialStores");
|
|
6846
6742
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
6847
|
-
|
|
6743
|
+
logger17.info({ agent }, "agent registered: well-known agent.json");
|
|
6848
6744
|
if (!agent) {
|
|
6849
6745
|
return c.json({ error: "Agent not found" }, 404);
|
|
6850
6746
|
}
|
|
6851
6747
|
return c.json(agent.agentCard);
|
|
6852
6748
|
} else {
|
|
6853
|
-
|
|
6749
|
+
logger17.info(
|
|
6854
6750
|
{
|
|
6855
6751
|
message: "getRegisteredGraph (graph-level)",
|
|
6856
6752
|
tenantId,
|
|
@@ -6873,7 +6769,7 @@ app.post("/a2a", async (c) => {
|
|
|
6873
6769
|
tracestate: c.req.header("tracestate"),
|
|
6874
6770
|
baggage: c.req.header("baggage")
|
|
6875
6771
|
};
|
|
6876
|
-
|
|
6772
|
+
logger17.info(
|
|
6877
6773
|
{
|
|
6878
6774
|
otelHeaders,
|
|
6879
6775
|
path: c.req.path,
|
|
@@ -6884,7 +6780,7 @@ app.post("/a2a", async (c) => {
|
|
|
6884
6780
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
6885
6781
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
6886
6782
|
if (agentId) {
|
|
6887
|
-
|
|
6783
|
+
logger17.info(
|
|
6888
6784
|
{
|
|
6889
6785
|
message: "a2a (agent-level)",
|
|
6890
6786
|
tenantId,
|
|
@@ -6908,7 +6804,7 @@ app.post("/a2a", async (c) => {
|
|
|
6908
6804
|
}
|
|
6909
6805
|
return a2aHandler(c, agent);
|
|
6910
6806
|
} else {
|
|
6911
|
-
|
|
6807
|
+
logger17.info(
|
|
6912
6808
|
{
|
|
6913
6809
|
message: "a2a (graph-level)",
|
|
6914
6810
|
tenantId,
|
|
@@ -6954,14 +6850,14 @@ init_dbClient();
|
|
|
6954
6850
|
|
|
6955
6851
|
// src/a2a/transfer.ts
|
|
6956
6852
|
init_dbClient();
|
|
6957
|
-
var
|
|
6853
|
+
var logger18 = getLogger("Transfer");
|
|
6958
6854
|
async function executeTransfer({
|
|
6959
6855
|
tenantId,
|
|
6960
6856
|
threadId,
|
|
6961
6857
|
projectId,
|
|
6962
6858
|
targetAgentId
|
|
6963
6859
|
}) {
|
|
6964
|
-
|
|
6860
|
+
logger18.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
6965
6861
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
6966
6862
|
scopes: { tenantId, projectId },
|
|
6967
6863
|
threadId,
|
|
@@ -7503,7 +7399,7 @@ function createMCPStreamHelper() {
|
|
|
7503
7399
|
|
|
7504
7400
|
// src/handlers/executionHandler.ts
|
|
7505
7401
|
init_dbClient();
|
|
7506
|
-
var
|
|
7402
|
+
var logger19 = getLogger("ExecutionHandler");
|
|
7507
7403
|
var ExecutionHandler = class {
|
|
7508
7404
|
constructor() {
|
|
7509
7405
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -7528,7 +7424,7 @@ var ExecutionHandler = class {
|
|
|
7528
7424
|
const { tenantId, projectId, graphId, apiKey, baseUrl } = executionContext;
|
|
7529
7425
|
registerStreamHelper(requestId2, sseHelper);
|
|
7530
7426
|
graphSessionManager.createSession(requestId2, graphId, tenantId, projectId);
|
|
7531
|
-
|
|
7427
|
+
logger19.info({ sessionId: requestId2, graphId }, "Created GraphSession for message execution");
|
|
7532
7428
|
let graphConfig = null;
|
|
7533
7429
|
try {
|
|
7534
7430
|
graphConfig = await agentsCore.getFullGraph(dbClient_default)({ scopes: { tenantId, projectId }, graphId });
|
|
@@ -7540,7 +7436,7 @@ var ExecutionHandler = class {
|
|
|
7540
7436
|
);
|
|
7541
7437
|
}
|
|
7542
7438
|
} catch (error) {
|
|
7543
|
-
|
|
7439
|
+
logger19.error(
|
|
7544
7440
|
{
|
|
7545
7441
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
7546
7442
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -7556,7 +7452,7 @@ var ExecutionHandler = class {
|
|
|
7556
7452
|
try {
|
|
7557
7453
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
7558
7454
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
7559
|
-
|
|
7455
|
+
logger19.info(
|
|
7560
7456
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
7561
7457
|
"Attempting to create or reuse existing task"
|
|
7562
7458
|
);
|
|
@@ -7579,7 +7475,7 @@ var ExecutionHandler = class {
|
|
|
7579
7475
|
agent_id: currentAgentId
|
|
7580
7476
|
}
|
|
7581
7477
|
});
|
|
7582
|
-
|
|
7478
|
+
logger19.info(
|
|
7583
7479
|
{
|
|
7584
7480
|
taskId,
|
|
7585
7481
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -7588,21 +7484,21 @@ var ExecutionHandler = class {
|
|
|
7588
7484
|
);
|
|
7589
7485
|
} catch (error) {
|
|
7590
7486
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
7591
|
-
|
|
7487
|
+
logger19.info({ taskId, error: error.message }, "Task already exists, fetching existing task");
|
|
7592
7488
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
7593
7489
|
if (existingTask) {
|
|
7594
7490
|
task = existingTask;
|
|
7595
|
-
|
|
7491
|
+
logger19.info({ taskId, existingTask }, "Successfully reused existing task from race condition");
|
|
7596
7492
|
} else {
|
|
7597
|
-
|
|
7493
|
+
logger19.error({ taskId, error }, "Task constraint failed but task not found");
|
|
7598
7494
|
throw error;
|
|
7599
7495
|
}
|
|
7600
7496
|
} else {
|
|
7601
|
-
|
|
7497
|
+
logger19.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
7602
7498
|
throw error;
|
|
7603
7499
|
}
|
|
7604
7500
|
}
|
|
7605
|
-
|
|
7501
|
+
logger19.debug(
|
|
7606
7502
|
{
|
|
7607
7503
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7608
7504
|
executionType: "create_initial_task",
|
|
@@ -7620,7 +7516,7 @@ var ExecutionHandler = class {
|
|
|
7620
7516
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
7621
7517
|
while (iterations < maxTransfers) {
|
|
7622
7518
|
iterations++;
|
|
7623
|
-
|
|
7519
|
+
logger19.info(
|
|
7624
7520
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
7625
7521
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
7626
7522
|
);
|
|
@@ -7628,10 +7524,10 @@ var ExecutionHandler = class {
|
|
|
7628
7524
|
scopes: { tenantId, projectId },
|
|
7629
7525
|
conversationId
|
|
7630
7526
|
});
|
|
7631
|
-
|
|
7527
|
+
logger19.info({ activeAgent }, "activeAgent");
|
|
7632
7528
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
7633
7529
|
currentAgentId = activeAgent.activeAgentId;
|
|
7634
|
-
|
|
7530
|
+
logger19.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
7635
7531
|
}
|
|
7636
7532
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
7637
7533
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -7672,13 +7568,13 @@ var ExecutionHandler = class {
|
|
|
7672
7568
|
});
|
|
7673
7569
|
if (!messageResponse?.result) {
|
|
7674
7570
|
errorCount++;
|
|
7675
|
-
|
|
7571
|
+
logger19.error(
|
|
7676
7572
|
{ currentAgentId, iterations, errorCount },
|
|
7677
7573
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7678
7574
|
);
|
|
7679
7575
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7680
7576
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7681
|
-
|
|
7577
|
+
logger19.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7682
7578
|
await sseHelper.writeError(errorMessage2);
|
|
7683
7579
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7684
7580
|
if (task) {
|
|
@@ -7704,7 +7600,7 @@ var ExecutionHandler = class {
|
|
|
7704
7600
|
const transferResponse = messageResponse.result;
|
|
7705
7601
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
7706
7602
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
7707
|
-
|
|
7603
|
+
logger19.info({ targetAgentId, transferReason }, "transfer response");
|
|
7708
7604
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
7709
7605
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
7710
7606
|
projectId,
|
|
@@ -7715,7 +7611,7 @@ var ExecutionHandler = class {
|
|
|
7715
7611
|
if (success) {
|
|
7716
7612
|
fromAgentId = currentAgentId;
|
|
7717
7613
|
currentAgentId = newAgentId;
|
|
7718
|
-
|
|
7614
|
+
logger19.info(
|
|
7719
7615
|
{
|
|
7720
7616
|
transferFrom: fromAgentId,
|
|
7721
7617
|
transferTo: currentAgentId,
|
|
@@ -7733,7 +7629,7 @@ var ExecutionHandler = class {
|
|
|
7733
7629
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
7734
7630
|
if (graphSessionData) {
|
|
7735
7631
|
const sessionSummary = graphSessionData.getSummary();
|
|
7736
|
-
|
|
7632
|
+
logger19.info(sessionSummary, "GraphSession data after completion");
|
|
7737
7633
|
}
|
|
7738
7634
|
let textContent = "";
|
|
7739
7635
|
for (const part of responseParts) {
|
|
@@ -7788,32 +7684,32 @@ var ExecutionHandler = class {
|
|
|
7788
7684
|
}
|
|
7789
7685
|
});
|
|
7790
7686
|
const updateTaskEnd = Date.now();
|
|
7791
|
-
|
|
7687
|
+
logger19.info(
|
|
7792
7688
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
7793
7689
|
"Completed updateTask operation"
|
|
7794
7690
|
);
|
|
7795
7691
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
7796
7692
|
await sseHelper.complete();
|
|
7797
|
-
|
|
7693
|
+
logger19.info("Ending GraphSession and cleaning up");
|
|
7798
7694
|
graphSessionManager.endSession(requestId2);
|
|
7799
|
-
|
|
7695
|
+
logger19.info("Cleaning up streamHelper");
|
|
7800
7696
|
unregisterStreamHelper(requestId2);
|
|
7801
7697
|
let response;
|
|
7802
7698
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
7803
7699
|
const captured = sseHelper.getCapturedResponse();
|
|
7804
7700
|
response = captured.text || "No response content";
|
|
7805
7701
|
}
|
|
7806
|
-
|
|
7702
|
+
logger19.info("ExecutionHandler returning success");
|
|
7807
7703
|
return { success: true, iterations, response };
|
|
7808
7704
|
}
|
|
7809
7705
|
errorCount++;
|
|
7810
|
-
|
|
7706
|
+
logger19.warn(
|
|
7811
7707
|
{ iterations, errorCount },
|
|
7812
7708
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
7813
7709
|
);
|
|
7814
7710
|
if (errorCount >= this.MAX_ERRORS) {
|
|
7815
7711
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
7816
|
-
|
|
7712
|
+
logger19.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
7817
7713
|
await sseHelper.writeError(errorMessage2);
|
|
7818
7714
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
7819
7715
|
if (task) {
|
|
@@ -7835,7 +7731,7 @@ var ExecutionHandler = class {
|
|
|
7835
7731
|
}
|
|
7836
7732
|
}
|
|
7837
7733
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
7838
|
-
|
|
7734
|
+
logger19.error({ maxTransfers, iterations }, errorMessage);
|
|
7839
7735
|
await sseHelper.writeError(errorMessage);
|
|
7840
7736
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
7841
7737
|
if (task) {
|
|
@@ -7855,7 +7751,7 @@ var ExecutionHandler = class {
|
|
|
7855
7751
|
unregisterStreamHelper(requestId2);
|
|
7856
7752
|
return { success: false, error: errorMessage, iterations };
|
|
7857
7753
|
} catch (error) {
|
|
7858
|
-
|
|
7754
|
+
logger19.error({ error }, "Error in execution handler");
|
|
7859
7755
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
7860
7756
|
await sseHelper.writeError(`Execution error: ${errorMessage}`);
|
|
7861
7757
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
@@ -7881,7 +7777,7 @@ var ExecutionHandler = class {
|
|
|
7881
7777
|
|
|
7882
7778
|
// src/routes/chat.ts
|
|
7883
7779
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
7884
|
-
var
|
|
7780
|
+
var logger20 = getLogger("completionsHandler");
|
|
7885
7781
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
7886
7782
|
method: "post",
|
|
7887
7783
|
path: "/completions",
|
|
@@ -7999,7 +7895,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
7999
7895
|
tracestate: c.req.header("tracestate"),
|
|
8000
7896
|
baggage: c.req.header("baggage")
|
|
8001
7897
|
};
|
|
8002
|
-
|
|
7898
|
+
logger20.info(
|
|
8003
7899
|
{
|
|
8004
7900
|
otelHeaders,
|
|
8005
7901
|
path: c.req.path,
|
|
@@ -8085,7 +7981,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8085
7981
|
dbClient_default,
|
|
8086
7982
|
credentialStores
|
|
8087
7983
|
);
|
|
8088
|
-
|
|
7984
|
+
logger20.info(
|
|
8089
7985
|
{
|
|
8090
7986
|
tenantId,
|
|
8091
7987
|
graphId,
|
|
@@ -8131,7 +8027,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8131
8027
|
return streaming.streamSSE(c, async (stream2) => {
|
|
8132
8028
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
8133
8029
|
await sseHelper.writeRole();
|
|
8134
|
-
|
|
8030
|
+
logger20.info({ agentId }, "Starting execution");
|
|
8135
8031
|
const executionHandler = new ExecutionHandler();
|
|
8136
8032
|
const result = await executionHandler.execute({
|
|
8137
8033
|
executionContext,
|
|
@@ -8141,7 +8037,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
8141
8037
|
requestId: requestId2,
|
|
8142
8038
|
sseHelper
|
|
8143
8039
|
});
|
|
8144
|
-
|
|
8040
|
+
logger20.info(
|
|
8145
8041
|
{ result },
|
|
8146
8042
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8147
8043
|
);
|
|
@@ -8177,7 +8073,7 @@ var chat_default = app2;
|
|
|
8177
8073
|
// src/routes/chatDataStream.ts
|
|
8178
8074
|
init_dbClient();
|
|
8179
8075
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
8180
|
-
var
|
|
8076
|
+
var logger21 = getLogger("chatDataStream");
|
|
8181
8077
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
8182
8078
|
method: "post",
|
|
8183
8079
|
path: "/chat",
|
|
@@ -8282,7 +8178,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8282
8178
|
);
|
|
8283
8179
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
8284
8180
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
8285
|
-
|
|
8181
|
+
logger21.info({ userText, lastUserMessage }, "userText");
|
|
8286
8182
|
const messageSpan = api.trace.getActiveSpan();
|
|
8287
8183
|
if (messageSpan) {
|
|
8288
8184
|
messageSpan.setAttributes({
|
|
@@ -8324,7 +8220,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8324
8220
|
await streamHelper.writeError("Unable to process request");
|
|
8325
8221
|
}
|
|
8326
8222
|
} catch (err) {
|
|
8327
|
-
|
|
8223
|
+
logger21.error({ err }, "Streaming error");
|
|
8328
8224
|
await streamHelper.writeError("Internal server error");
|
|
8329
8225
|
} finally {
|
|
8330
8226
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -8345,7 +8241,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
8345
8241
|
)
|
|
8346
8242
|
);
|
|
8347
8243
|
} catch (error) {
|
|
8348
|
-
|
|
8244
|
+
logger21.error({ error }, "chatDataStream error");
|
|
8349
8245
|
return c.json({ error: "Failed to process chat completion" }, 500);
|
|
8350
8246
|
}
|
|
8351
8247
|
});
|
|
@@ -8356,7 +8252,7 @@ init_dbClient();
|
|
|
8356
8252
|
function createMCPSchema(schema) {
|
|
8357
8253
|
return schema;
|
|
8358
8254
|
}
|
|
8359
|
-
var
|
|
8255
|
+
var logger22 = getLogger("mcp");
|
|
8360
8256
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
8361
8257
|
constructor() {
|
|
8362
8258
|
__publicField(this, "mockRes");
|
|
@@ -8411,21 +8307,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
8411
8307
|
id: 0
|
|
8412
8308
|
});
|
|
8413
8309
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
8414
|
-
|
|
8310
|
+
logger22.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
8415
8311
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
8416
8312
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
8417
8313
|
try {
|
|
8418
8314
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
8419
|
-
|
|
8315
|
+
logger22.info({ sessionId }, "Successfully spoofed initialization");
|
|
8420
8316
|
} catch (spoofError) {
|
|
8421
|
-
|
|
8317
|
+
logger22.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
8422
8318
|
}
|
|
8423
8319
|
};
|
|
8424
8320
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
8425
8321
|
const sessionId = req.headers["mcp-session-id"];
|
|
8426
|
-
|
|
8322
|
+
logger22.info({ sessionId }, "Received MCP session ID");
|
|
8427
8323
|
if (!sessionId) {
|
|
8428
|
-
|
|
8324
|
+
logger22.info({ body }, "Missing session ID");
|
|
8429
8325
|
res.writeHead(400).end(
|
|
8430
8326
|
JSON.stringify({
|
|
8431
8327
|
jsonrpc: "2.0",
|
|
@@ -8451,7 +8347,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8451
8347
|
scopes: { tenantId, projectId },
|
|
8452
8348
|
conversationId: sessionId
|
|
8453
8349
|
});
|
|
8454
|
-
|
|
8350
|
+
logger22.info(
|
|
8455
8351
|
{
|
|
8456
8352
|
sessionId,
|
|
8457
8353
|
conversationFound: !!conversation,
|
|
@@ -8462,7 +8358,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
8462
8358
|
"Conversation lookup result"
|
|
8463
8359
|
);
|
|
8464
8360
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
8465
|
-
|
|
8361
|
+
logger22.info(
|
|
8466
8362
|
{ sessionId, conversationId: conversation?.id },
|
|
8467
8363
|
"MCP session not found or invalid"
|
|
8468
8364
|
);
|
|
@@ -8523,7 +8419,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
8523
8419
|
requestId: requestId2,
|
|
8524
8420
|
sseHelper: mcpStreamHelper
|
|
8525
8421
|
});
|
|
8526
|
-
|
|
8422
|
+
logger22.info(
|
|
8527
8423
|
{ result },
|
|
8528
8424
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
8529
8425
|
);
|
|
@@ -8597,7 +8493,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
8597
8493
|
dbClient_default,
|
|
8598
8494
|
credentialStores
|
|
8599
8495
|
);
|
|
8600
|
-
|
|
8496
|
+
logger22.info(
|
|
8601
8497
|
{
|
|
8602
8498
|
tenantId,
|
|
8603
8499
|
graphId,
|
|
@@ -8658,7 +8554,7 @@ var validateRequestParameters = (c) => {
|
|
|
8658
8554
|
};
|
|
8659
8555
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
8660
8556
|
const { tenantId, projectId, graphId } = executionContext;
|
|
8661
|
-
|
|
8557
|
+
logger22.info({ body }, "Received initialization request");
|
|
8662
8558
|
const sessionId = nanoid.nanoid();
|
|
8663
8559
|
const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
8664
8560
|
scopes: { tenantId, projectId },
|
|
@@ -8689,7 +8585,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8689
8585
|
}
|
|
8690
8586
|
}
|
|
8691
8587
|
});
|
|
8692
|
-
|
|
8588
|
+
logger22.info(
|
|
8693
8589
|
{ sessionId, conversationId: conversation.id },
|
|
8694
8590
|
"Created MCP session as conversation"
|
|
8695
8591
|
);
|
|
@@ -8698,9 +8594,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8698
8594
|
});
|
|
8699
8595
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
8700
8596
|
await server.connect(transport);
|
|
8701
|
-
|
|
8597
|
+
logger22.info({ sessionId }, "Server connected for initialization");
|
|
8702
8598
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
8703
|
-
|
|
8599
|
+
logger22.info(
|
|
8704
8600
|
{
|
|
8705
8601
|
sessionId,
|
|
8706
8602
|
bodyMethod: body?.method,
|
|
@@ -8709,7 +8605,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
8709
8605
|
"About to handle initialization request"
|
|
8710
8606
|
);
|
|
8711
8607
|
await transport.handleRequest(req, res, body);
|
|
8712
|
-
|
|
8608
|
+
logger22.info({ sessionId }, "Successfully handled initialization request");
|
|
8713
8609
|
return fetchToNode.toFetchResponse(res);
|
|
8714
8610
|
};
|
|
8715
8611
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -8737,8 +8633,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8737
8633
|
sessionId,
|
|
8738
8634
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
8739
8635
|
);
|
|
8740
|
-
|
|
8741
|
-
|
|
8636
|
+
logger22.info({ sessionId }, "Server connected and transport initialized");
|
|
8637
|
+
logger22.info(
|
|
8742
8638
|
{
|
|
8743
8639
|
sessionId,
|
|
8744
8640
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -8752,9 +8648,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
8752
8648
|
);
|
|
8753
8649
|
try {
|
|
8754
8650
|
await transport.handleRequest(req, res, body);
|
|
8755
|
-
|
|
8651
|
+
logger22.info({ sessionId }, "Successfully handled MCP request");
|
|
8756
8652
|
} catch (transportError) {
|
|
8757
|
-
|
|
8653
|
+
logger22.error(
|
|
8758
8654
|
{
|
|
8759
8655
|
sessionId,
|
|
8760
8656
|
error: transportError,
|
|
@@ -8805,13 +8701,13 @@ app4.openapi(
|
|
|
8805
8701
|
}
|
|
8806
8702
|
const { executionContext } = paramValidation;
|
|
8807
8703
|
const body = await c.req.json();
|
|
8808
|
-
|
|
8704
|
+
logger22.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
8809
8705
|
const isInitRequest = body.method === "initialize";
|
|
8810
8706
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
8811
8707
|
const validatedContext = c.get("validatedContext") || {};
|
|
8812
8708
|
const credentialStores = c.get("credentialStores");
|
|
8813
|
-
|
|
8814
|
-
|
|
8709
|
+
logger22.info({ validatedContext }, "Validated context");
|
|
8710
|
+
logger22.info({ req }, "request");
|
|
8815
8711
|
if (isInitRequest) {
|
|
8816
8712
|
return await handleInitializationRequest(
|
|
8817
8713
|
body,
|
|
@@ -8833,7 +8729,7 @@ app4.openapi(
|
|
|
8833
8729
|
);
|
|
8834
8730
|
}
|
|
8835
8731
|
} catch (e) {
|
|
8836
|
-
|
|
8732
|
+
logger22.error(
|
|
8837
8733
|
{
|
|
8838
8734
|
error: e instanceof Error ? e.message : e,
|
|
8839
8735
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -8845,7 +8741,7 @@ app4.openapi(
|
|
|
8845
8741
|
}
|
|
8846
8742
|
);
|
|
8847
8743
|
app4.get("/", async (c) => {
|
|
8848
|
-
|
|
8744
|
+
logger22.info("Received GET MCP request");
|
|
8849
8745
|
return c.json(
|
|
8850
8746
|
{
|
|
8851
8747
|
jsonrpc: "2.0",
|
|
@@ -8859,7 +8755,7 @@ app4.get("/", async (c) => {
|
|
|
8859
8755
|
);
|
|
8860
8756
|
});
|
|
8861
8757
|
app4.delete("/", async (c) => {
|
|
8862
|
-
|
|
8758
|
+
logger22.info("Received DELETE MCP request");
|
|
8863
8759
|
return c.json(
|
|
8864
8760
|
{
|
|
8865
8761
|
jsonrpc: "2.0",
|
|
@@ -8939,9 +8835,9 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8939
8835
|
if (!isExpectedError) {
|
|
8940
8836
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
8941
8837
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
8942
|
-
const
|
|
8943
|
-
if (
|
|
8944
|
-
|
|
8838
|
+
const logger23 = getLogger();
|
|
8839
|
+
if (logger23) {
|
|
8840
|
+
logger23.error(
|
|
8945
8841
|
{
|
|
8946
8842
|
error: err,
|
|
8947
8843
|
message: errorMessage,
|
|
@@ -8953,9 +8849,9 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8953
8849
|
);
|
|
8954
8850
|
}
|
|
8955
8851
|
} else {
|
|
8956
|
-
const
|
|
8957
|
-
if (
|
|
8958
|
-
|
|
8852
|
+
const logger23 = getLogger();
|
|
8853
|
+
if (logger23) {
|
|
8854
|
+
logger23.error(
|
|
8959
8855
|
{
|
|
8960
8856
|
error: err,
|
|
8961
8857
|
path: c.req.path,
|
|
@@ -8972,9 +8868,9 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
8972
8868
|
const response = err.getResponse();
|
|
8973
8869
|
return response;
|
|
8974
8870
|
} catch (responseError) {
|
|
8975
|
-
const
|
|
8976
|
-
if (
|
|
8977
|
-
|
|
8871
|
+
const logger23 = getLogger();
|
|
8872
|
+
if (logger23) {
|
|
8873
|
+
logger23.error({ error: responseError }, "Error while handling HTTPException response");
|
|
8978
8874
|
}
|
|
8979
8875
|
}
|
|
8980
8876
|
}
|