@inkeep/agents-run-api 0.39.3 → 0.39.5
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 +293 -142
- package/dist/index.js +293 -142
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ let ajv = require("ajv");
|
|
|
26
26
|
ajv = require_chunk.__toESM(ajv);
|
|
27
27
|
let crypto = require("crypto");
|
|
28
28
|
let zod = require("zod");
|
|
29
|
+
let llm_info = require("llm-info");
|
|
29
30
|
let __alcyone_labs_modelcontextprotocol_sdk_server_mcp_js = require("@alcyone-labs/modelcontextprotocol-sdk/server/mcp.js");
|
|
30
31
|
let __alcyone_labs_modelcontextprotocol_sdk_server_streamableHttp_js = require("@alcyone-labs/modelcontextprotocol-sdk/server/streamableHttp.js");
|
|
31
32
|
let fetch_to_node = require("fetch-to-node");
|
|
@@ -57,7 +58,7 @@ function createExecutionContext(params) {
|
|
|
57
58
|
|
|
58
59
|
//#endregion
|
|
59
60
|
//#region src/middleware/api-key-auth.ts
|
|
60
|
-
const logger$
|
|
61
|
+
const logger$25 = (0, __inkeep_agents_core.getLogger)("env-key-auth");
|
|
61
62
|
/**
|
|
62
63
|
* Attempts to authenticate using a JWT temporary token
|
|
63
64
|
* Returns execution context if successful, null if token is invalid or not a JWT
|
|
@@ -66,7 +67,7 @@ async function tryAuthenticateWithTempJwt(apiKey, baseUrl, subAgentId) {
|
|
|
66
67
|
if (!apiKey.startsWith("eyJ") || !require_env.env.INKEEP_AGENTS_TEMP_JWT_PUBLIC_KEY) return null;
|
|
67
68
|
try {
|
|
68
69
|
const payload = await (0, __inkeep_agents_core.verifyTempToken)(Buffer.from(require_env.env.INKEEP_AGENTS_TEMP_JWT_PUBLIC_KEY, "base64").toString("utf-8"), apiKey);
|
|
69
|
-
logger$
|
|
70
|
+
logger$25.info({}, "JWT temp token authenticated successfully");
|
|
70
71
|
return createExecutionContext({
|
|
71
72
|
apiKey,
|
|
72
73
|
tenantId: payload.tenantId,
|
|
@@ -78,7 +79,7 @@ async function tryAuthenticateWithTempJwt(apiKey, baseUrl, subAgentId) {
|
|
|
78
79
|
metadata: { initiatedBy: payload.initiatedBy }
|
|
79
80
|
});
|
|
80
81
|
} catch (error) {
|
|
81
|
-
logger$
|
|
82
|
+
logger$25.debug({ error }, "JWT verification failed");
|
|
82
83
|
return null;
|
|
83
84
|
}
|
|
84
85
|
}
|
|
@@ -97,7 +98,7 @@ const apiKeyAuth = () => (0, hono_factory.createMiddleware)(async (c, next) => {
|
|
|
97
98
|
const reqUrl = new URL(c.req.url);
|
|
98
99
|
const baseUrl = proto && host ? `${proto}://${host}` : host ? `${reqUrl.protocol}//${host}` : `${reqUrl.origin}`;
|
|
99
100
|
if (process.env.ENVIRONMENT === "development" || process.env.ENVIRONMENT === "test") {
|
|
100
|
-
logger$
|
|
101
|
+
logger$25.info({}, "development environment");
|
|
101
102
|
let executionContext;
|
|
102
103
|
if (authHeader?.startsWith("Bearer ")) {
|
|
103
104
|
const apiKey$1 = authHeader.substring(7);
|
|
@@ -126,7 +127,7 @@ const apiKeyAuth = () => (0, hono_factory.createMiddleware)(async (c, next) => {
|
|
|
126
127
|
subAgentId
|
|
127
128
|
});
|
|
128
129
|
c.set("executionContext", executionContext);
|
|
129
|
-
logger$
|
|
130
|
+
logger$25.info({}, "Development/test environment - fallback to default context due to invalid API key");
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
} else {
|
|
@@ -140,7 +141,7 @@ const apiKeyAuth = () => (0, hono_factory.createMiddleware)(async (c, next) => {
|
|
|
140
141
|
subAgentId
|
|
141
142
|
});
|
|
142
143
|
c.set("executionContext", executionContext);
|
|
143
|
-
logger$
|
|
144
|
+
logger$25.info({}, "Development/test environment - no API key provided, using default context");
|
|
144
145
|
}
|
|
145
146
|
await next();
|
|
146
147
|
return;
|
|
@@ -166,7 +167,7 @@ const apiKeyAuth = () => (0, hono_factory.createMiddleware)(async (c, next) => {
|
|
|
166
167
|
subAgentId
|
|
167
168
|
});
|
|
168
169
|
c.set("executionContext", executionContext);
|
|
169
|
-
logger$
|
|
170
|
+
logger$25.info({}, "Bypass secret authenticated successfully");
|
|
170
171
|
await next();
|
|
171
172
|
return;
|
|
172
173
|
}
|
|
@@ -175,7 +176,7 @@ const apiKeyAuth = () => (0, hono_factory.createMiddleware)(async (c, next) => {
|
|
|
175
176
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
176
177
|
if (subAgentId) executionContext.subAgentId = subAgentId;
|
|
177
178
|
c.set("executionContext", executionContext);
|
|
178
|
-
logger$
|
|
179
|
+
logger$25.info({}, "API key authenticated successfully");
|
|
179
180
|
} catch {
|
|
180
181
|
const executionContext = await extractContextFromTeamAgentToken(apiKey, baseUrl, subAgentId);
|
|
181
182
|
c.set("executionContext", executionContext);
|
|
@@ -190,7 +191,7 @@ const apiKeyAuth = () => (0, hono_factory.createMiddleware)(async (c, next) => {
|
|
|
190
191
|
const executionContext = await extractContextFromApiKey(apiKey, baseUrl);
|
|
191
192
|
if (subAgentId) executionContext.subAgentId = subAgentId;
|
|
192
193
|
c.set("executionContext", executionContext);
|
|
193
|
-
logger$
|
|
194
|
+
logger$25.debug({
|
|
194
195
|
tenantId: executionContext.tenantId,
|
|
195
196
|
projectId: executionContext.projectId,
|
|
196
197
|
agentId: executionContext.agentId,
|
|
@@ -204,7 +205,7 @@ const apiKeyAuth = () => (0, hono_factory.createMiddleware)(async (c, next) => {
|
|
|
204
205
|
await next();
|
|
205
206
|
} catch (error) {
|
|
206
207
|
if (error instanceof hono_http_exception.HTTPException) throw error;
|
|
207
|
-
logger$
|
|
208
|
+
logger$25.error({ error }, "API key authentication error");
|
|
208
209
|
throw new hono_http_exception.HTTPException(500, { message: "Authentication failed" });
|
|
209
210
|
}
|
|
210
211
|
}
|
|
@@ -218,7 +219,7 @@ const extractContextFromApiKey = async (apiKey, baseUrl) => {
|
|
|
218
219
|
agentId: apiKeyRecord.agentId
|
|
219
220
|
} });
|
|
220
221
|
if (!agent) throw new hono_http_exception.HTTPException(401, { message: "Invalid or expired API key" });
|
|
221
|
-
logger$
|
|
222
|
+
logger$25.debug({
|
|
222
223
|
tenantId: apiKeyRecord.tenantId,
|
|
223
224
|
projectId: apiKeyRecord.projectId,
|
|
224
225
|
agentId: apiKeyRecord.agentId,
|
|
@@ -241,19 +242,19 @@ const extractContextFromApiKey = async (apiKey, baseUrl) => {
|
|
|
241
242
|
const extractContextFromTeamAgentToken = async (token, baseUrl, expectedSubAgentId) => {
|
|
242
243
|
const result = await (0, __inkeep_agents_core.verifyServiceToken)(token);
|
|
243
244
|
if (!result.valid || !result.payload) {
|
|
244
|
-
logger$
|
|
245
|
+
logger$25.warn({ error: result.error }, "Invalid team agent JWT token");
|
|
245
246
|
throw new hono_http_exception.HTTPException(401, { message: `Invalid team agent token: ${result.error || "Unknown error"}` });
|
|
246
247
|
}
|
|
247
248
|
const payload = result.payload;
|
|
248
249
|
if (expectedSubAgentId && !(0, __inkeep_agents_core.validateTargetAgent)(payload, expectedSubAgentId)) {
|
|
249
|
-
logger$
|
|
250
|
+
logger$25.error({
|
|
250
251
|
tokenTargetAgentId: payload.aud,
|
|
251
252
|
expectedSubAgentId,
|
|
252
253
|
originAgentId: payload.sub
|
|
253
254
|
}, "Team agent token target mismatch");
|
|
254
255
|
throw new hono_http_exception.HTTPException(403, { message: "Token not valid for the requested agent" });
|
|
255
256
|
}
|
|
256
|
-
logger$
|
|
257
|
+
logger$25.info({
|
|
257
258
|
originAgentId: payload.sub,
|
|
258
259
|
targetAgentId: payload.aud,
|
|
259
260
|
tenantId: payload.tenantId,
|
|
@@ -326,7 +327,7 @@ function setupOpenAPIRoutes(app$5) {
|
|
|
326
327
|
|
|
327
328
|
//#endregion
|
|
328
329
|
//#region src/a2a/handlers.ts
|
|
329
|
-
const logger$
|
|
330
|
+
const logger$24 = (0, __inkeep_agents_core.getLogger)("a2aHandler");
|
|
330
331
|
async function a2aHandler(c, agent) {
|
|
331
332
|
try {
|
|
332
333
|
const rpcRequest = c.get("requestBody");
|
|
@@ -407,14 +408,14 @@ async function handleMessageSend(c, agent, request) {
|
|
|
407
408
|
messageId: task.id,
|
|
408
409
|
kind: "message"
|
|
409
410
|
});
|
|
410
|
-
logger$
|
|
411
|
+
logger$24.warn({
|
|
411
412
|
taskId: task.id,
|
|
412
413
|
subAgentId: agent.subAgentId,
|
|
413
414
|
originalMessage: params.message
|
|
414
415
|
}, "Created fallback message content for empty delegation message");
|
|
415
416
|
}
|
|
416
417
|
} catch (error) {
|
|
417
|
-
logger$
|
|
418
|
+
logger$24.error({
|
|
418
419
|
error,
|
|
419
420
|
taskId: task.id
|
|
420
421
|
}, "Failed to serialize message");
|
|
@@ -428,7 +429,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
428
429
|
}]
|
|
429
430
|
});
|
|
430
431
|
}
|
|
431
|
-
logger$
|
|
432
|
+
logger$24.info({
|
|
432
433
|
originalContextId: params.message.contextId,
|
|
433
434
|
taskContextId: task.context?.conversationId,
|
|
434
435
|
metadataContextId: params.message.metadata?.conversationId,
|
|
@@ -455,7 +456,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
455
456
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
456
457
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
457
458
|
});
|
|
458
|
-
logger$
|
|
459
|
+
logger$24.info({ metadata: params.message.metadata }, "message metadata");
|
|
459
460
|
if (params.message.metadata?.fromSubAgentId || params.message.metadata?.fromExternalAgentId || params.message.metadata?.fromTeamAgentId) {
|
|
460
461
|
const messageText = params.message.parts.filter((part) => part.kind === "text" && "text" in part && part.text).map((part) => part.text).join(" ");
|
|
461
462
|
try {
|
|
@@ -481,7 +482,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
481
482
|
messageData.toTeamAgentId = agent.subAgentId;
|
|
482
483
|
}
|
|
483
484
|
await (0, __inkeep_agents_core.createMessage)(require_dbClient.dbClient_default)(messageData);
|
|
484
|
-
logger$
|
|
485
|
+
logger$24.info({
|
|
485
486
|
fromSubAgentId: params.message.metadata.fromSubAgentId,
|
|
486
487
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
487
488
|
fromTeamAgentId: params.message.metadata.fromTeamAgentId,
|
|
@@ -492,7 +493,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
492
493
|
taskId: task.id
|
|
493
494
|
}, "A2A message stored in database");
|
|
494
495
|
} catch (error) {
|
|
495
|
-
logger$
|
|
496
|
+
logger$24.error({
|
|
496
497
|
error,
|
|
497
498
|
fromSubAgentId: params.message.metadata.fromSubAgentId,
|
|
498
499
|
fromExternalAgentId: params.message.metadata.fromExternalAgentId,
|
|
@@ -521,7 +522,7 @@ async function handleMessageSend(c, agent, request) {
|
|
|
521
522
|
if (transferArtifact) {
|
|
522
523
|
const transferPart = transferArtifact.parts?.find((part) => part.kind === "data" && part.data && typeof part.data === "object" && part.data.type === "transfer");
|
|
523
524
|
if (transferPart && transferPart.kind === "data" && transferPart.data) {
|
|
524
|
-
logger$
|
|
525
|
+
logger$24.info({ transferPart }, "transferPart");
|
|
525
526
|
return c.json({
|
|
526
527
|
jsonrpc: "2.0",
|
|
527
528
|
result: {
|
|
@@ -879,7 +880,7 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
879
880
|
|
|
880
881
|
//#endregion
|
|
881
882
|
//#region src/agents/ToolSessionManager.ts
|
|
882
|
-
const logger$
|
|
883
|
+
const logger$23 = (0, __inkeep_agents_core.getLogger)("ToolSessionManager");
|
|
883
884
|
/**
|
|
884
885
|
* Manages tool execution state during agent generation sessions.
|
|
885
886
|
* Allows tools to access previous tool call results within the same execution.
|
|
@@ -915,7 +916,7 @@ var ToolSessionManager = class ToolSessionManager {
|
|
|
915
916
|
createdAt: Date.now()
|
|
916
917
|
};
|
|
917
918
|
this.sessions.set(sessionId, session);
|
|
918
|
-
logger$
|
|
919
|
+
logger$23.debug({
|
|
919
920
|
sessionId,
|
|
920
921
|
tenantId,
|
|
921
922
|
contextId,
|
|
@@ -930,10 +931,10 @@ var ToolSessionManager = class ToolSessionManager {
|
|
|
930
931
|
*/
|
|
931
932
|
ensureAgentSession(sessionId, tenantId, projectId, contextId, taskId) {
|
|
932
933
|
if (this.sessions.has(sessionId)) {
|
|
933
|
-
logger$
|
|
934
|
+
logger$23.debug({ sessionId }, "Agent session already exists, reusing");
|
|
934
935
|
return sessionId;
|
|
935
936
|
}
|
|
936
|
-
logger$
|
|
937
|
+
logger$23.debug({
|
|
937
938
|
sessionId,
|
|
938
939
|
tenantId,
|
|
939
940
|
contextId,
|
|
@@ -947,7 +948,7 @@ var ToolSessionManager = class ToolSessionManager {
|
|
|
947
948
|
recordToolResult(sessionId, toolResult) {
|
|
948
949
|
const session = this.sessions.get(sessionId);
|
|
949
950
|
if (!session) {
|
|
950
|
-
logger$
|
|
951
|
+
logger$23.warn({
|
|
951
952
|
sessionId,
|
|
952
953
|
toolCallId: toolResult.toolCallId,
|
|
953
954
|
availableSessionIds: Array.from(this.sessions.keys()),
|
|
@@ -956,7 +957,7 @@ var ToolSessionManager = class ToolSessionManager {
|
|
|
956
957
|
return;
|
|
957
958
|
}
|
|
958
959
|
session.toolResults.set(toolResult.toolCallId, toolResult);
|
|
959
|
-
logger$
|
|
960
|
+
logger$23.debug({
|
|
960
961
|
sessionId,
|
|
961
962
|
toolCallId: toolResult.toolCallId,
|
|
962
963
|
toolName: toolResult.toolName
|
|
@@ -968,7 +969,7 @@ var ToolSessionManager = class ToolSessionManager {
|
|
|
968
969
|
getToolResult(sessionId, toolCallId) {
|
|
969
970
|
const session = this.sessions.get(sessionId);
|
|
970
971
|
if (!session) {
|
|
971
|
-
logger$
|
|
972
|
+
logger$23.warn({
|
|
972
973
|
sessionId,
|
|
973
974
|
toolCallId,
|
|
974
975
|
availableSessionIds: Array.from(this.sessions.keys()),
|
|
@@ -977,13 +978,13 @@ var ToolSessionManager = class ToolSessionManager {
|
|
|
977
978
|
return;
|
|
978
979
|
}
|
|
979
980
|
const result = session.toolResults.get(toolCallId);
|
|
980
|
-
if (!result) logger$
|
|
981
|
+
if (!result) logger$23.warn({
|
|
981
982
|
sessionId,
|
|
982
983
|
toolCallId,
|
|
983
984
|
availableToolResultIds: Array.from(session.toolResults.keys()),
|
|
984
985
|
totalToolResults: session.toolResults.size
|
|
985
986
|
}, "Tool result not found");
|
|
986
|
-
else logger$
|
|
987
|
+
else logger$23.debug({
|
|
987
988
|
sessionId,
|
|
988
989
|
toolCallId,
|
|
989
990
|
toolName: result.toolName
|
|
@@ -1011,9 +1012,9 @@ var ToolSessionManager = class ToolSessionManager {
|
|
|
1011
1012
|
for (const [sessionId, session] of this.sessions.entries()) if (now - session.createdAt > require_execution_limits.SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS) expiredSessions.push(sessionId);
|
|
1012
1013
|
for (const sessionId of expiredSessions) {
|
|
1013
1014
|
this.sessions.delete(sessionId);
|
|
1014
|
-
logger$
|
|
1015
|
+
logger$23.debug({ sessionId }, "Cleaned up expired tool session");
|
|
1015
1016
|
}
|
|
1016
|
-
if (expiredSessions.length > 0) logger$
|
|
1017
|
+
if (expiredSessions.length > 0) logger$23.info({ expiredCount: expiredSessions.length }, "Cleaned up expired tool sessions");
|
|
1017
1018
|
}
|
|
1018
1019
|
};
|
|
1019
1020
|
const toolSessionManager = ToolSessionManager.getInstance();
|
|
@@ -1074,7 +1075,7 @@ const tracer = (0, __inkeep_agents_core.getTracer)("agents-run-api");
|
|
|
1074
1075
|
|
|
1075
1076
|
//#endregion
|
|
1076
1077
|
//#region src/utils/schema-validation.ts
|
|
1077
|
-
const logger$
|
|
1078
|
+
const logger$22 = (0, __inkeep_agents_core.getLogger)("SchemaValidation");
|
|
1078
1079
|
const ajv$1 = new ajv.default({
|
|
1079
1080
|
allErrors: true,
|
|
1080
1081
|
strict: false
|
|
@@ -1116,7 +1117,7 @@ function extractFullFields(schema) {
|
|
|
1116
1117
|
|
|
1117
1118
|
//#endregion
|
|
1118
1119
|
//#region src/services/ArtifactService.ts
|
|
1119
|
-
const logger$
|
|
1120
|
+
const logger$21 = (0, __inkeep_agents_core.getLogger)("ArtifactService");
|
|
1120
1121
|
/**
|
|
1121
1122
|
* Service class responsible for artifact business logic operations
|
|
1122
1123
|
* Handles database persistence, tool result extraction, and artifact management
|
|
@@ -1150,7 +1151,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1150
1151
|
for (const taskId of taskIds) {
|
|
1151
1152
|
const task = await (0, __inkeep_agents_core.getTask)(require_dbClient.dbClient_default)({ id: taskId });
|
|
1152
1153
|
if (!task) {
|
|
1153
|
-
logger$
|
|
1154
|
+
logger$21.warn({ taskId }, "Task not found when fetching artifacts");
|
|
1154
1155
|
continue;
|
|
1155
1156
|
}
|
|
1156
1157
|
const taskArtifacts = await (0, __inkeep_agents_core.getLedgerArtifacts)(require_dbClient.dbClient_default)({
|
|
@@ -1171,7 +1172,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1171
1172
|
}
|
|
1172
1173
|
}
|
|
1173
1174
|
} catch (error) {
|
|
1174
|
-
logger$
|
|
1175
|
+
logger$21.error({
|
|
1175
1176
|
error,
|
|
1176
1177
|
contextId
|
|
1177
1178
|
}, "Error loading context artifacts");
|
|
@@ -1183,12 +1184,12 @@ var ArtifactService = class ArtifactService {
|
|
|
1183
1184
|
*/
|
|
1184
1185
|
async createArtifact(request, subAgentId) {
|
|
1185
1186
|
if (!this.context.sessionId) {
|
|
1186
|
-
logger$
|
|
1187
|
+
logger$21.warn({ request }, "No session ID available for artifact creation");
|
|
1187
1188
|
return null;
|
|
1188
1189
|
}
|
|
1189
1190
|
const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
|
|
1190
1191
|
if (!toolResult) {
|
|
1191
|
-
logger$
|
|
1192
|
+
logger$21.warn({
|
|
1192
1193
|
request,
|
|
1193
1194
|
sessionId: this.context.sessionId
|
|
1194
1195
|
}, "Tool result not found for artifact");
|
|
@@ -1200,7 +1201,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1200
1201
|
let selectedData = jmespath.default.search(toolResultData, sanitizedBaseSelector);
|
|
1201
1202
|
if (Array.isArray(selectedData)) selectedData = selectedData.length > 0 ? selectedData[0] : {};
|
|
1202
1203
|
if (!selectedData) {
|
|
1203
|
-
logger$
|
|
1204
|
+
logger$21.warn({
|
|
1204
1205
|
request,
|
|
1205
1206
|
baseSelector: request.baseSelector
|
|
1206
1207
|
}, "Base selector returned no data - using empty object as fallback");
|
|
@@ -1236,7 +1237,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1236
1237
|
await this.cacheArtifact(request.artifactId, request.toolCallId, artifactData, cleanedFullData);
|
|
1237
1238
|
return artifactData;
|
|
1238
1239
|
} catch (error) {
|
|
1239
|
-
logger$
|
|
1240
|
+
logger$21.error({
|
|
1240
1241
|
error,
|
|
1241
1242
|
request
|
|
1242
1243
|
}, "Failed to create artifact");
|
|
@@ -1263,7 +1264,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1263
1264
|
}
|
|
1264
1265
|
try {
|
|
1265
1266
|
if (!this.context.projectId || !this.context.taskId) {
|
|
1266
|
-
logger$
|
|
1267
|
+
logger$21.warn({
|
|
1267
1268
|
artifactId,
|
|
1268
1269
|
toolCallId
|
|
1269
1270
|
}, "No projectId or taskId available for artifact lookup");
|
|
@@ -1289,7 +1290,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1289
1290
|
});
|
|
1290
1291
|
if (artifacts.length > 0) return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
|
|
1291
1292
|
} catch (error) {
|
|
1292
|
-
logger$
|
|
1293
|
+
logger$21.warn({
|
|
1293
1294
|
artifactId,
|
|
1294
1295
|
toolCallId,
|
|
1295
1296
|
taskId: this.context.taskId,
|
|
@@ -1317,7 +1318,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1317
1318
|
}
|
|
1318
1319
|
try {
|
|
1319
1320
|
if (!this.context.projectId || !this.context.taskId) {
|
|
1320
|
-
logger$
|
|
1321
|
+
logger$21.warn({
|
|
1321
1322
|
artifactId,
|
|
1322
1323
|
toolCallId
|
|
1323
1324
|
}, "No projectId or taskId available for artifact lookup");
|
|
@@ -1343,7 +1344,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1343
1344
|
});
|
|
1344
1345
|
if (artifacts.length > 0) return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
|
|
1345
1346
|
} catch (error) {
|
|
1346
|
-
logger$
|
|
1347
|
+
logger$21.warn({
|
|
1347
1348
|
artifactId,
|
|
1348
1349
|
toolCallId,
|
|
1349
1350
|
taskId: this.context.taskId,
|
|
@@ -1362,7 +1363,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1362
1363
|
data = artifact.parts?.[0]?.data;
|
|
1363
1364
|
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
1364
1365
|
dataSource = "parts[0].data (fallback)";
|
|
1365
|
-
logger$
|
|
1366
|
+
logger$21.debug({
|
|
1366
1367
|
artifactId,
|
|
1367
1368
|
toolCallId,
|
|
1368
1369
|
dataSource
|
|
@@ -1371,7 +1372,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1371
1372
|
data = artifact.data;
|
|
1372
1373
|
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
1373
1374
|
dataSource = "artifact.data (fallback)";
|
|
1374
|
-
logger$
|
|
1375
|
+
logger$21.debug({
|
|
1375
1376
|
artifactId,
|
|
1376
1377
|
toolCallId,
|
|
1377
1378
|
dataSource
|
|
@@ -1379,7 +1380,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1379
1380
|
} else {
|
|
1380
1381
|
data = {};
|
|
1381
1382
|
dataSource = "empty (no data found)";
|
|
1382
|
-
logger$
|
|
1383
|
+
logger$21.warn({
|
|
1383
1384
|
artifactId,
|
|
1384
1385
|
toolCallId,
|
|
1385
1386
|
artifactStructure: {
|
|
@@ -1413,7 +1414,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1413
1414
|
data = artifact.parts?.[0]?.data;
|
|
1414
1415
|
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
1415
1416
|
dataSource = "parts[0].data (fallback)";
|
|
1416
|
-
logger$
|
|
1417
|
+
logger$21.debug({
|
|
1417
1418
|
artifactId,
|
|
1418
1419
|
toolCallId,
|
|
1419
1420
|
dataSource
|
|
@@ -1422,7 +1423,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1422
1423
|
data = artifact.data;
|
|
1423
1424
|
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
1424
1425
|
dataSource = "artifact.data (fallback)";
|
|
1425
|
-
logger$
|
|
1426
|
+
logger$21.debug({
|
|
1426
1427
|
artifactId,
|
|
1427
1428
|
toolCallId,
|
|
1428
1429
|
dataSource
|
|
@@ -1430,7 +1431,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1430
1431
|
} else {
|
|
1431
1432
|
data = {};
|
|
1432
1433
|
dataSource = "empty (no data found)";
|
|
1433
|
-
logger$
|
|
1434
|
+
logger$21.warn({
|
|
1434
1435
|
artifactId,
|
|
1435
1436
|
toolCallId,
|
|
1436
1437
|
artifactStructure: {
|
|
@@ -1478,7 +1479,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1478
1479
|
const fullValidation = validateAgainstSchema(fullData, fullSchema);
|
|
1479
1480
|
if (!summaryValidation.hasRequiredFields) {
|
|
1480
1481
|
`${summaryValidation.missingRequired.join(", ")}${artifactType}${summaryValidation.missingRequired.join(", ")}${summaryValidation.actualFields.join(", ")}`;
|
|
1481
|
-
logger$
|
|
1482
|
+
logger$21.error({
|
|
1482
1483
|
artifactId,
|
|
1483
1484
|
artifactType,
|
|
1484
1485
|
requiredFields: summaryValidation.missingRequired,
|
|
@@ -1491,7 +1492,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1491
1492
|
schemaFound: !!previewSchema
|
|
1492
1493
|
};
|
|
1493
1494
|
}
|
|
1494
|
-
if (!summaryValidation.hasExpectedFields || summaryValidation.extraFields.length > 0) logger$
|
|
1495
|
+
if (!summaryValidation.hasExpectedFields || summaryValidation.extraFields.length > 0) logger$21.warn({
|
|
1495
1496
|
artifactId,
|
|
1496
1497
|
artifactType,
|
|
1497
1498
|
dataType: "summary",
|
|
@@ -1500,7 +1501,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1500
1501
|
missingFields: summaryValidation.missingFields,
|
|
1501
1502
|
extraFields: summaryValidation.extraFields
|
|
1502
1503
|
}, "Summary data structure does not match preview schema");
|
|
1503
|
-
if (!fullValidation.hasExpectedFields || fullValidation.extraFields.length > 0) logger$
|
|
1504
|
+
if (!fullValidation.hasExpectedFields || fullValidation.extraFields.length > 0) logger$21.warn({
|
|
1504
1505
|
artifactId,
|
|
1505
1506
|
artifactType,
|
|
1506
1507
|
dataType: "full",
|
|
@@ -1561,7 +1562,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1561
1562
|
contextId: this.context.contextId,
|
|
1562
1563
|
pendingGeneration: true
|
|
1563
1564
|
});
|
|
1564
|
-
else logger$
|
|
1565
|
+
else logger$21.warn({
|
|
1565
1566
|
artifactId: request.artifactId,
|
|
1566
1567
|
hasStreamRequestId: !!this.context.streamRequestId,
|
|
1567
1568
|
hasAgentId: !!effectiveAgentId,
|
|
@@ -1619,7 +1620,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1619
1620
|
summaryData = this.filterBySchema(artifact.data, previewSchema);
|
|
1620
1621
|
fullData = this.filterBySchema(artifact.data, fullSchema);
|
|
1621
1622
|
} catch (error) {
|
|
1622
|
-
logger$
|
|
1623
|
+
logger$21.warn({
|
|
1623
1624
|
artifactType: artifact.type,
|
|
1624
1625
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
1625
1626
|
}, "Failed to extract preview/full fields from schema, using full data for both");
|
|
@@ -1650,7 +1651,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1650
1651
|
toolCallId: artifact.toolCallId,
|
|
1651
1652
|
artifact: artifactToSave
|
|
1652
1653
|
});
|
|
1653
|
-
if (!result.created && result.existing) logger$
|
|
1654
|
+
if (!result.created && result.existing) logger$21.debug({
|
|
1654
1655
|
artifactId: artifact.artifactId,
|
|
1655
1656
|
taskId: this.context.taskId
|
|
1656
1657
|
}, "Artifact already exists, skipping duplicate creation");
|
|
@@ -1696,7 +1697,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1696
1697
|
} else rawValue = item[fieldName];
|
|
1697
1698
|
if (rawValue !== null && rawValue !== void 0) extracted[fieldName] = this.cleanEscapedContent(rawValue);
|
|
1698
1699
|
} catch (error) {
|
|
1699
|
-
logger$
|
|
1700
|
+
logger$21.warn({
|
|
1700
1701
|
fieldName,
|
|
1701
1702
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
1702
1703
|
}, "Failed to extract schema field");
|
|
@@ -1718,7 +1719,7 @@ var ArtifactService = class ArtifactService {
|
|
|
1718
1719
|
|
|
1719
1720
|
//#endregion
|
|
1720
1721
|
//#region src/services/ArtifactParser.ts
|
|
1721
|
-
const logger$
|
|
1722
|
+
const logger$20 = (0, __inkeep_agents_core.getLogger)("ArtifactParser");
|
|
1722
1723
|
/**
|
|
1723
1724
|
* Artifact parser focused on parsing and text processing responsibilities
|
|
1724
1725
|
* Delegates business logic operations to ArtifactService
|
|
@@ -1811,7 +1812,7 @@ var ArtifactParser = class ArtifactParser {
|
|
|
1811
1812
|
attrs[key] = value;
|
|
1812
1813
|
}
|
|
1813
1814
|
if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
|
|
1814
|
-
logger$
|
|
1815
|
+
logger$20.warn({
|
|
1815
1816
|
attrs,
|
|
1816
1817
|
attrString
|
|
1817
1818
|
}, "Missing required attributes in artifact annotation");
|
|
@@ -1870,7 +1871,7 @@ var ArtifactParser = class ArtifactParser {
|
|
|
1870
1871
|
else if (annotation.raw) {
|
|
1871
1872
|
failedAnnotations.push(`Failed to create artifact "${annotation.artifactId}": Missing or invalid data`);
|
|
1872
1873
|
processedText = processedText.replace(annotation.raw, "");
|
|
1873
|
-
logger$
|
|
1874
|
+
logger$20.warn({
|
|
1874
1875
|
annotation,
|
|
1875
1876
|
artifactData
|
|
1876
1877
|
}, "Removed failed artifact:create annotation from output");
|
|
@@ -1879,12 +1880,12 @@ var ArtifactParser = class ArtifactParser {
|
|
|
1879
1880
|
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
1880
1881
|
failedAnnotations.push(`Failed to create artifact "${annotation.artifactId}": ${errorMsg}`);
|
|
1881
1882
|
if (annotation.raw) processedText = processedText.replace(annotation.raw, "");
|
|
1882
|
-
logger$
|
|
1883
|
+
logger$20.error({
|
|
1883
1884
|
annotation,
|
|
1884
1885
|
error
|
|
1885
1886
|
}, "Failed to extract artifact from create annotation");
|
|
1886
1887
|
}
|
|
1887
|
-
if (failedAnnotations.length > 0) logger$
|
|
1888
|
+
if (failedAnnotations.length > 0) logger$20.warn({
|
|
1888
1889
|
failedCount: failedAnnotations.length,
|
|
1889
1890
|
failures: failedAnnotations
|
|
1890
1891
|
}, "Some artifact creation attempts failed");
|
|
@@ -2052,7 +2053,7 @@ var ArtifactParser = class ArtifactParser {
|
|
|
2052
2053
|
|
|
2053
2054
|
//#endregion
|
|
2054
2055
|
//#region src/services/AgentSession.ts
|
|
2055
|
-
const logger$
|
|
2056
|
+
const logger$19 = (0, __inkeep_agents_core.getLogger)("AgentSession");
|
|
2056
2057
|
/**
|
|
2057
2058
|
* Tracks all agent operations and interactions for a single message
|
|
2058
2059
|
* Now includes intelligent status update functionality
|
|
@@ -2081,7 +2082,7 @@ var AgentSession = class {
|
|
|
2081
2082
|
this.tenantId = tenantId;
|
|
2082
2083
|
this.projectId = projectId;
|
|
2083
2084
|
this.contextId = contextId;
|
|
2084
|
-
logger$
|
|
2085
|
+
logger$19.debug({
|
|
2085
2086
|
sessionId,
|
|
2086
2087
|
messageId,
|
|
2087
2088
|
agentId
|
|
@@ -2111,7 +2112,7 @@ var AgentSession = class {
|
|
|
2111
2112
|
*/
|
|
2112
2113
|
enableEmitOperations() {
|
|
2113
2114
|
this.isEmitOperations = true;
|
|
2114
|
-
logger$
|
|
2115
|
+
logger$19.info({ sessionId: this.sessionId }, "🔍 DEBUG: Emit operations enabled for AgentSession");
|
|
2115
2116
|
}
|
|
2116
2117
|
/**
|
|
2117
2118
|
* Send data operation to stream when emit operations is enabled
|
|
@@ -2132,7 +2133,7 @@ var AgentSession = class {
|
|
|
2132
2133
|
await streamHelper.writeOperation(formattedOperation);
|
|
2133
2134
|
}
|
|
2134
2135
|
} catch (error) {
|
|
2135
|
-
logger$
|
|
2136
|
+
logger$19.error({
|
|
2136
2137
|
sessionId: this.sessionId,
|
|
2137
2138
|
eventType: event.eventType,
|
|
2138
2139
|
error: error instanceof Error ? error.message : error
|
|
@@ -2180,7 +2181,7 @@ var AgentSession = class {
|
|
|
2180
2181
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
2181
2182
|
this.statusUpdateTimer = setInterval(async () => {
|
|
2182
2183
|
if (!this.statusUpdateState || this.isEnded) {
|
|
2183
|
-
logger$
|
|
2184
|
+
logger$19.debug({ sessionId: this.sessionId }, "Timer triggered but session already cleaned up or ended");
|
|
2184
2185
|
if (this.statusUpdateTimer) {
|
|
2185
2186
|
clearInterval(this.statusUpdateTimer);
|
|
2186
2187
|
this.statusUpdateTimer = void 0;
|
|
@@ -2189,7 +2190,7 @@ var AgentSession = class {
|
|
|
2189
2190
|
}
|
|
2190
2191
|
await this.checkAndSendTimeBasedUpdate();
|
|
2191
2192
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
2192
|
-
logger$
|
|
2193
|
+
logger$19.info({
|
|
2193
2194
|
sessionId: this.sessionId,
|
|
2194
2195
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
2195
2196
|
}, "Time-based status update timer started");
|
|
@@ -2210,7 +2211,7 @@ var AgentSession = class {
|
|
|
2210
2211
|
this.sendDataOperation(dataOpEvent);
|
|
2211
2212
|
}
|
|
2212
2213
|
if (this.isEnded) {
|
|
2213
|
-
logger$
|
|
2214
|
+
logger$19.debug({
|
|
2214
2215
|
sessionId: this.sessionId,
|
|
2215
2216
|
eventType,
|
|
2216
2217
|
subAgentId
|
|
@@ -2229,7 +2230,7 @@ var AgentSession = class {
|
|
|
2229
2230
|
if (artifactData.pendingGeneration) {
|
|
2230
2231
|
const artifactId = artifactData.artifactId;
|
|
2231
2232
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
2232
|
-
logger$
|
|
2233
|
+
logger$19.warn({
|
|
2233
2234
|
sessionId: this.sessionId,
|
|
2234
2235
|
artifactId,
|
|
2235
2236
|
pendingCount: this.pendingArtifacts.size,
|
|
@@ -2251,7 +2252,7 @@ var AgentSession = class {
|
|
|
2251
2252
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
2252
2253
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
2253
2254
|
this.pendingArtifacts.delete(artifactId);
|
|
2254
|
-
logger$
|
|
2255
|
+
logger$19.error({
|
|
2255
2256
|
sessionId: this.sessionId,
|
|
2256
2257
|
artifactId,
|
|
2257
2258
|
errorCount,
|
|
@@ -2259,7 +2260,7 @@ var AgentSession = class {
|
|
|
2259
2260
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
2260
2261
|
stack: error instanceof Error ? error.stack : void 0
|
|
2261
2262
|
}, "Artifact processing failed after max retries, giving up");
|
|
2262
|
-
} else logger$
|
|
2263
|
+
} else logger$19.warn({
|
|
2263
2264
|
sessionId: this.sessionId,
|
|
2264
2265
|
artifactId,
|
|
2265
2266
|
errorCount,
|
|
@@ -2276,11 +2277,11 @@ var AgentSession = class {
|
|
|
2276
2277
|
*/
|
|
2277
2278
|
checkStatusUpdates() {
|
|
2278
2279
|
if (this.isEnded) {
|
|
2279
|
-
logger$
|
|
2280
|
+
logger$19.debug({ sessionId: this.sessionId }, "Session has ended - skipping status update check");
|
|
2280
2281
|
return;
|
|
2281
2282
|
}
|
|
2282
2283
|
if (!this.statusUpdateState) {
|
|
2283
|
-
logger$
|
|
2284
|
+
logger$19.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
2284
2285
|
return;
|
|
2285
2286
|
}
|
|
2286
2287
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -2291,18 +2292,18 @@ var AgentSession = class {
|
|
|
2291
2292
|
*/
|
|
2292
2293
|
async checkAndSendTimeBasedUpdate() {
|
|
2293
2294
|
if (this.isEnded) {
|
|
2294
|
-
logger$
|
|
2295
|
+
logger$19.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
2295
2296
|
return;
|
|
2296
2297
|
}
|
|
2297
2298
|
if (!this.statusUpdateState) {
|
|
2298
|
-
logger$
|
|
2299
|
+
logger$19.debug({ sessionId: this.sessionId }, "No status updates configured for time-based check");
|
|
2299
2300
|
return;
|
|
2300
2301
|
}
|
|
2301
2302
|
if (this.events.length - this.statusUpdateState.lastEventCount === 0) return;
|
|
2302
2303
|
try {
|
|
2303
2304
|
await this.generateAndSendUpdate();
|
|
2304
2305
|
} catch (error) {
|
|
2305
|
-
logger$
|
|
2306
|
+
logger$19.error({
|
|
2306
2307
|
sessionId: this.sessionId,
|
|
2307
2308
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
2308
2309
|
}, "Failed to send time-based status update");
|
|
@@ -2376,7 +2377,7 @@ var AgentSession = class {
|
|
|
2376
2377
|
const maxWaitTime = 1e4;
|
|
2377
2378
|
const startTime = Date.now();
|
|
2378
2379
|
while (this.pendingArtifacts.size > 0 && Date.now() - startTime < maxWaitTime) await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2379
|
-
if (this.pendingArtifacts.size > 0) logger$
|
|
2380
|
+
if (this.pendingArtifacts.size > 0) logger$19.warn({
|
|
2380
2381
|
sessionId: this.sessionId,
|
|
2381
2382
|
pendingCount: this.pendingArtifacts.size,
|
|
2382
2383
|
pendingIds: Array.from(this.pendingArtifacts)
|
|
@@ -2400,23 +2401,23 @@ var AgentSession = class {
|
|
|
2400
2401
|
*/
|
|
2401
2402
|
async generateAndSendUpdate() {
|
|
2402
2403
|
if (this.isEnded) {
|
|
2403
|
-
logger$
|
|
2404
|
+
logger$19.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
2404
2405
|
return;
|
|
2405
2406
|
}
|
|
2406
2407
|
if (this.isTextStreaming) {
|
|
2407
|
-
logger$
|
|
2408
|
+
logger$19.debug({ sessionId: this.sessionId }, "Text is currently streaming - skipping status update");
|
|
2408
2409
|
return;
|
|
2409
2410
|
}
|
|
2410
2411
|
if (this.isGeneratingUpdate) {
|
|
2411
|
-
logger$
|
|
2412
|
+
logger$19.debug({ sessionId: this.sessionId }, "Update already in progress - skipping duplicate generation");
|
|
2412
2413
|
return;
|
|
2413
2414
|
}
|
|
2414
2415
|
if (!this.statusUpdateState) {
|
|
2415
|
-
logger$
|
|
2416
|
+
logger$19.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
2416
2417
|
return;
|
|
2417
2418
|
}
|
|
2418
2419
|
if (!this.agentId) {
|
|
2419
|
-
logger$
|
|
2420
|
+
logger$19.warn({ sessionId: this.sessionId }, "No agent ID - cannot generate update");
|
|
2420
2421
|
return;
|
|
2421
2422
|
}
|
|
2422
2423
|
if (this.events.length - this.statusUpdateState.lastEventCount === 0) return;
|
|
@@ -2425,7 +2426,7 @@ var AgentSession = class {
|
|
|
2425
2426
|
try {
|
|
2426
2427
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
2427
2428
|
if (!streamHelper) {
|
|
2428
|
-
logger$
|
|
2429
|
+
logger$19.warn({ sessionId: this.sessionId }, "No stream helper found - cannot send status update");
|
|
2429
2430
|
this.isGeneratingUpdate = false;
|
|
2430
2431
|
return;
|
|
2431
2432
|
}
|
|
@@ -2436,7 +2437,7 @@ var AgentSession = class {
|
|
|
2436
2437
|
if (result.summaries && result.summaries.length > 0) {
|
|
2437
2438
|
for (const summary of result.summaries) {
|
|
2438
2439
|
if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
|
|
2439
|
-
logger$
|
|
2440
|
+
logger$19.warn({
|
|
2440
2441
|
sessionId: this.sessionId,
|
|
2441
2442
|
summary
|
|
2442
2443
|
}, "Skipping empty or invalid structured operation");
|
|
@@ -2466,7 +2467,7 @@ var AgentSession = class {
|
|
|
2466
2467
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
2467
2468
|
}
|
|
2468
2469
|
} catch (error) {
|
|
2469
|
-
logger$
|
|
2470
|
+
logger$19.error({
|
|
2470
2471
|
sessionId: this.sessionId,
|
|
2471
2472
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
2472
2473
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -2492,7 +2493,7 @@ var AgentSession = class {
|
|
|
2492
2493
|
this.releaseUpdateLock();
|
|
2493
2494
|
}
|
|
2494
2495
|
} catch (error) {
|
|
2495
|
-
logger$
|
|
2496
|
+
logger$19.error({
|
|
2496
2497
|
sessionId: this.sessionId,
|
|
2497
2498
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
2498
2499
|
}, "Failed to check status updates during event recording");
|
|
@@ -2549,7 +2550,7 @@ var AgentSession = class {
|
|
|
2549
2550
|
});
|
|
2550
2551
|
conversationContext = conversationHistory.trim() ? `\nUser's Question/Context:\n${conversationHistory}\n` : "";
|
|
2551
2552
|
} catch (error) {
|
|
2552
|
-
logger$
|
|
2553
|
+
logger$19.warn({
|
|
2553
2554
|
sessionId: this.sessionId,
|
|
2554
2555
|
error
|
|
2555
2556
|
}, "Failed to fetch conversation history for structured status update");
|
|
@@ -2631,10 +2632,10 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2631
2632
|
}
|
|
2632
2633
|
});
|
|
2633
2634
|
const result = object;
|
|
2634
|
-
logger$
|
|
2635
|
+
logger$19.info({ result: JSON.stringify(result) }, "DEBUG: Result");
|
|
2635
2636
|
const summaries = [];
|
|
2636
2637
|
for (const [componentId, data] of Object.entries(result)) {
|
|
2637
|
-
logger$
|
|
2638
|
+
logger$19.info({
|
|
2638
2639
|
componentId,
|
|
2639
2640
|
data: JSON.stringify(data)
|
|
2640
2641
|
}, "DEBUG: Component data");
|
|
@@ -2653,7 +2654,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2653
2654
|
return { summaries };
|
|
2654
2655
|
} catch (error) {
|
|
2655
2656
|
(0, __inkeep_agents_core.setSpanWithError)(span, error instanceof Error ? error : new Error(String(error)));
|
|
2656
|
-
logger$
|
|
2657
|
+
logger$19.error({ error }, "Failed to generate structured update, using fallback");
|
|
2657
2658
|
return { summaries: [] };
|
|
2658
2659
|
} finally {
|
|
2659
2660
|
span.end();
|
|
@@ -2826,7 +2827,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
2826
2827
|
taskId: artifactData.taskId
|
|
2827
2828
|
})).map((a) => a.name).filter(Boolean);
|
|
2828
2829
|
} catch (error) {
|
|
2829
|
-
logger$
|
|
2830
|
+
logger$19.warn({
|
|
2830
2831
|
sessionId: this.sessionId,
|
|
2831
2832
|
artifactId: artifactData.artifactId,
|
|
2832
2833
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2877,7 +2878,7 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
2877
2878
|
});
|
|
2878
2879
|
if (agentData && "models" in agentData && agentData.models?.base?.model) {
|
|
2879
2880
|
modelToUse = agentData.models.base;
|
|
2880
|
-
logger$
|
|
2881
|
+
logger$19.info({
|
|
2881
2882
|
sessionId: this.sessionId,
|
|
2882
2883
|
artifactId: artifactData.artifactId,
|
|
2883
2884
|
subAgentId: artifactData.subAgentId,
|
|
@@ -2885,7 +2886,7 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
2885
2886
|
}, "Using agent model configuration for artifact name generation");
|
|
2886
2887
|
}
|
|
2887
2888
|
} catch (error) {
|
|
2888
|
-
logger$
|
|
2889
|
+
logger$19.warn({
|
|
2889
2890
|
sessionId: this.sessionId,
|
|
2890
2891
|
artifactId: artifactData.artifactId,
|
|
2891
2892
|
subAgentId: artifactData.subAgentId,
|
|
@@ -2893,7 +2894,7 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
2893
2894
|
}, "Failed to get agent model configuration");
|
|
2894
2895
|
}
|
|
2895
2896
|
if (!modelToUse?.model?.trim()) {
|
|
2896
|
-
logger$
|
|
2897
|
+
logger$19.warn({
|
|
2897
2898
|
sessionId: this.sessionId,
|
|
2898
2899
|
artifactId: artifactData.artifactId
|
|
2899
2900
|
}, "No model configuration available for artifact name generation, will use fallback names");
|
|
@@ -2956,7 +2957,7 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
2956
2957
|
return result$1;
|
|
2957
2958
|
} catch (error) {
|
|
2958
2959
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2959
|
-
logger$
|
|
2960
|
+
logger$19.warn({
|
|
2960
2961
|
sessionId: this.sessionId,
|
|
2961
2962
|
artifactId: artifactData.artifactId,
|
|
2962
2963
|
attempt,
|
|
@@ -2977,7 +2978,7 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
2977
2978
|
const toolCallSuffix = toolCallId.slice(-8);
|
|
2978
2979
|
const originalName = result.name;
|
|
2979
2980
|
result.name = result.name.length + toolCallSuffix.length + 1 <= 50 ? `${result.name} ${toolCallSuffix}` : `${result.name.substring(0, 50 - toolCallSuffix.length - 1)} ${toolCallSuffix}`;
|
|
2980
|
-
logger$
|
|
2981
|
+
logger$19.info({
|
|
2981
2982
|
sessionId: this.sessionId,
|
|
2982
2983
|
artifactId: artifactData.artifactId,
|
|
2983
2984
|
originalName,
|
|
@@ -3005,7 +3006,7 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
3005
3006
|
});
|
|
3006
3007
|
span.setStatus({ code: __opentelemetry_api.SpanStatusCode.OK });
|
|
3007
3008
|
} catch (saveError) {
|
|
3008
|
-
logger$
|
|
3009
|
+
logger$19.error({
|
|
3009
3010
|
sessionId: this.sessionId,
|
|
3010
3011
|
artifactId: artifactData.artifactId,
|
|
3011
3012
|
error: saveError instanceof Error ? saveError.message : "Unknown error",
|
|
@@ -3035,13 +3036,13 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
3035
3036
|
metadata: artifactData.metadata || {},
|
|
3036
3037
|
toolCallId: artifactData.toolCallId
|
|
3037
3038
|
});
|
|
3038
|
-
logger$
|
|
3039
|
+
logger$19.info({
|
|
3039
3040
|
sessionId: this.sessionId,
|
|
3040
3041
|
artifactId: artifactData.artifactId
|
|
3041
3042
|
}, "Saved artifact with fallback name/description after main save failed");
|
|
3042
3043
|
}
|
|
3043
3044
|
} catch (fallbackError) {
|
|
3044
|
-
if (fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"))) {} else logger$
|
|
3045
|
+
if (fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"))) {} else logger$19.error({
|
|
3045
3046
|
sessionId: this.sessionId,
|
|
3046
3047
|
artifactId: artifactData.artifactId,
|
|
3047
3048
|
error: fallbackError instanceof Error ? fallbackError.message : "Unknown error",
|
|
@@ -3055,7 +3056,7 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
3055
3056
|
}
|
|
3056
3057
|
} catch (error) {
|
|
3057
3058
|
(0, __inkeep_agents_core.setSpanWithError)(span, error instanceof Error ? error : new Error(String(error)));
|
|
3058
|
-
logger$
|
|
3059
|
+
logger$19.error({
|
|
3059
3060
|
sessionId: this.sessionId,
|
|
3060
3061
|
artifactId: artifactData.artifactId,
|
|
3061
3062
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3070,7 +3071,7 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
3070
3071
|
*/
|
|
3071
3072
|
setArtifactCache(key, artifact) {
|
|
3072
3073
|
this.artifactCache.set(key, artifact);
|
|
3073
|
-
logger$
|
|
3074
|
+
logger$19.debug({
|
|
3074
3075
|
sessionId: this.sessionId,
|
|
3075
3076
|
key
|
|
3076
3077
|
}, "Artifact cached in session");
|
|
@@ -3092,7 +3093,7 @@ Make the name extremely specific to what this tool call actually returned, not g
|
|
|
3092
3093
|
*/
|
|
3093
3094
|
getArtifactCache(key) {
|
|
3094
3095
|
const artifact = this.artifactCache.get(key);
|
|
3095
|
-
logger$
|
|
3096
|
+
logger$19.debug({
|
|
3096
3097
|
sessionId: this.sessionId,
|
|
3097
3098
|
key,
|
|
3098
3099
|
found: !!artifact
|
|
@@ -3118,7 +3119,7 @@ var AgentSessionManager = class {
|
|
|
3118
3119
|
const sessionId = messageId;
|
|
3119
3120
|
const session = new AgentSession(sessionId, messageId, agentId, tenantId, projectId, contextId);
|
|
3120
3121
|
this.sessions.set(sessionId, session);
|
|
3121
|
-
logger$
|
|
3122
|
+
logger$19.info({
|
|
3122
3123
|
sessionId,
|
|
3123
3124
|
messageId,
|
|
3124
3125
|
agentId,
|
|
@@ -3134,7 +3135,7 @@ var AgentSessionManager = class {
|
|
|
3134
3135
|
initializeStatusUpdates(sessionId, config, summarizerModel, baseModel) {
|
|
3135
3136
|
const session = this.sessions.get(sessionId);
|
|
3136
3137
|
if (session) session.initializeStatusUpdates(config, summarizerModel, baseModel);
|
|
3137
|
-
else logger$
|
|
3138
|
+
else logger$19.error({
|
|
3138
3139
|
sessionId,
|
|
3139
3140
|
availableSessions: Array.from(this.sessions.keys())
|
|
3140
3141
|
}, "Session not found for status updates initialization");
|
|
@@ -3145,7 +3146,7 @@ var AgentSessionManager = class {
|
|
|
3145
3146
|
enableEmitOperations(sessionId) {
|
|
3146
3147
|
const session = this.sessions.get(sessionId);
|
|
3147
3148
|
if (session) session.enableEmitOperations();
|
|
3148
|
-
else logger$
|
|
3149
|
+
else logger$19.error({
|
|
3149
3150
|
sessionId,
|
|
3150
3151
|
availableSessions: Array.from(this.sessions.keys())
|
|
3151
3152
|
}, "Session not found for emit operations enablement");
|
|
@@ -3163,7 +3164,7 @@ var AgentSessionManager = class {
|
|
|
3163
3164
|
recordEvent(sessionId, eventType, subAgentId, data) {
|
|
3164
3165
|
const session = this.sessions.get(sessionId);
|
|
3165
3166
|
if (!session) {
|
|
3166
|
-
logger$
|
|
3167
|
+
logger$19.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
3167
3168
|
return;
|
|
3168
3169
|
}
|
|
3169
3170
|
session.recordEvent(eventType, subAgentId, data);
|
|
@@ -3174,12 +3175,12 @@ var AgentSessionManager = class {
|
|
|
3174
3175
|
async endSession(sessionId) {
|
|
3175
3176
|
const session = this.sessions.get(sessionId);
|
|
3176
3177
|
if (!session) {
|
|
3177
|
-
logger$
|
|
3178
|
+
logger$19.warn({ sessionId }, "Attempted to end non-existent session");
|
|
3178
3179
|
return [];
|
|
3179
3180
|
}
|
|
3180
3181
|
const events = session.getEvents();
|
|
3181
3182
|
const summary = session.getSummary();
|
|
3182
|
-
logger$
|
|
3183
|
+
logger$19.info({
|
|
3183
3184
|
sessionId,
|
|
3184
3185
|
summary
|
|
3185
3186
|
}, "AgentSession ended");
|
|
@@ -3274,7 +3275,7 @@ async function resolveModelConfig(agentId, subAgent) {
|
|
|
3274
3275
|
|
|
3275
3276
|
//#endregion
|
|
3276
3277
|
//#region src/services/IncrementalStreamParser.ts
|
|
3277
|
-
const logger$
|
|
3278
|
+
const logger$18 = (0, __inkeep_agents_core.getLogger)("IncrementalStreamParser");
|
|
3278
3279
|
/**
|
|
3279
3280
|
* Incremental parser that processes streaming text and formats artifacts/objects as they become complete
|
|
3280
3281
|
* Uses the unified ArtifactParser to eliminate redundancy
|
|
@@ -3325,12 +3326,12 @@ var IncrementalStreamParser = class IncrementalStreamParser {
|
|
|
3325
3326
|
async initializeArtifactMap() {
|
|
3326
3327
|
try {
|
|
3327
3328
|
this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
|
|
3328
|
-
logger$
|
|
3329
|
+
logger$18.debug({
|
|
3329
3330
|
contextId: this.contextId,
|
|
3330
3331
|
artifactMapSize: this.artifactMap.size
|
|
3331
3332
|
}, "Initialized artifact map for streaming");
|
|
3332
3333
|
} catch (error) {
|
|
3333
|
-
logger$
|
|
3334
|
+
logger$18.warn({
|
|
3334
3335
|
error,
|
|
3335
3336
|
contextId: this.contextId
|
|
3336
3337
|
}, "Failed to initialize artifact map");
|
|
@@ -3595,7 +3596,7 @@ var IncrementalStreamParser = class IncrementalStreamParser {
|
|
|
3595
3596
|
|
|
3596
3597
|
//#endregion
|
|
3597
3598
|
//#region src/tools/distill-conversation-tool.ts
|
|
3598
|
-
const logger$
|
|
3599
|
+
const logger$17 = (0, __inkeep_agents_core.getLogger)("distill-conversation-tool");
|
|
3599
3600
|
/**
|
|
3600
3601
|
* Conversation Summary Schema - structured object for maintaining conversation context
|
|
3601
3602
|
*/
|
|
@@ -3643,7 +3644,7 @@ async function distillConversation(params) {
|
|
|
3643
3644
|
} else if (msg.content?.text) parts.push(msg.content.text);
|
|
3644
3645
|
return parts.length > 0 ? `${msg.role || "system"}: ${parts.join("\n")}` : "";
|
|
3645
3646
|
}).filter((line) => line.trim().length > 0).join("\n\n");
|
|
3646
|
-
logger$
|
|
3647
|
+
logger$17.debug({
|
|
3647
3648
|
conversationId,
|
|
3648
3649
|
messageCount: messages.length,
|
|
3649
3650
|
formattedLength: formattedMessages.length,
|
|
@@ -3714,7 +3715,7 @@ Return **only** valid JSON.`,
|
|
|
3714
3715
|
schema: ConversationSummarySchema
|
|
3715
3716
|
});
|
|
3716
3717
|
summary.session_id = conversationId;
|
|
3717
|
-
logger$
|
|
3718
|
+
logger$17.info({
|
|
3718
3719
|
conversationId,
|
|
3719
3720
|
messageCount: messages.length,
|
|
3720
3721
|
artifactsCount: summary.related_artifacts?.length || 0,
|
|
@@ -3722,7 +3723,7 @@ Return **only** valid JSON.`,
|
|
|
3722
3723
|
}, "Successfully distilled conversation");
|
|
3723
3724
|
return summary;
|
|
3724
3725
|
} catch (error) {
|
|
3725
|
-
logger$
|
|
3726
|
+
logger$17.error({
|
|
3726
3727
|
conversationId,
|
|
3727
3728
|
messageCount: messages.length,
|
|
3728
3729
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3745,7 +3746,7 @@ Return **only** valid JSON.`,
|
|
|
3745
3746
|
|
|
3746
3747
|
//#endregion
|
|
3747
3748
|
//#region src/services/MidGenerationCompressor.ts
|
|
3748
|
-
const logger$
|
|
3749
|
+
const logger$16 = (0, __inkeep_agents_core.getLogger)("MidGenerationCompressor");
|
|
3749
3750
|
/**
|
|
3750
3751
|
* Get compression config from environment variables
|
|
3751
3752
|
*/
|
|
@@ -3815,7 +3816,7 @@ var MidGenerationCompressor = class {
|
|
|
3815
3816
|
*/
|
|
3816
3817
|
requestManualCompression(reason) {
|
|
3817
3818
|
this.shouldCompress = true;
|
|
3818
|
-
logger$
|
|
3819
|
+
logger$16.info({
|
|
3819
3820
|
sessionId: this.sessionId,
|
|
3820
3821
|
reason: reason || "Manual request from LLM"
|
|
3821
3822
|
}, "Manual compression requested");
|
|
@@ -3833,7 +3834,7 @@ var MidGenerationCompressor = class {
|
|
|
3833
3834
|
*/
|
|
3834
3835
|
async compress(messages) {
|
|
3835
3836
|
const contextSizeBefore = this.calculateContextSize(messages);
|
|
3836
|
-
logger$
|
|
3837
|
+
logger$16.info({
|
|
3837
3838
|
sessionId: this.sessionId,
|
|
3838
3839
|
messageCount: messages.length,
|
|
3839
3840
|
contextSize: contextSizeBefore
|
|
@@ -3842,7 +3843,7 @@ var MidGenerationCompressor = class {
|
|
|
3842
3843
|
if (Array.isArray(msg.content)) return count + msg.content.filter((block) => block.type === "tool-result").length;
|
|
3843
3844
|
return count;
|
|
3844
3845
|
}, 0);
|
|
3845
|
-
logger$
|
|
3846
|
+
logger$16.debug({ toolResultCount }, "Tool results found for compression");
|
|
3846
3847
|
const toolCallToArtifactMap = await this.saveToolResultsAsArtifacts(messages);
|
|
3847
3848
|
const summary = await this.createConversationSummary(messages, toolCallToArtifactMap);
|
|
3848
3849
|
const contextSizeAfter = this.estimateTokens(JSON.stringify(summary));
|
|
@@ -3859,7 +3860,7 @@ var MidGenerationCompressor = class {
|
|
|
3859
3860
|
});
|
|
3860
3861
|
}
|
|
3861
3862
|
this.shouldCompress = false;
|
|
3862
|
-
logger$
|
|
3863
|
+
logger$16.info({
|
|
3863
3864
|
sessionId: this.sessionId,
|
|
3864
3865
|
artifactsCreated: Object.keys(toolCallToArtifactMap).length,
|
|
3865
3866
|
messageCount: messages.length,
|
|
@@ -3880,7 +3881,7 @@ var MidGenerationCompressor = class {
|
|
|
3880
3881
|
if (!session) throw new Error(`No session found: ${this.sessionId}`);
|
|
3881
3882
|
const toolCallToArtifactMap = {};
|
|
3882
3883
|
const newMessages = messages.slice(this.lastProcessedMessageIndex);
|
|
3883
|
-
logger$
|
|
3884
|
+
logger$16.debug({
|
|
3884
3885
|
totalMessages: messages.length,
|
|
3885
3886
|
newMessages: newMessages.length,
|
|
3886
3887
|
startIndex: this.lastProcessedMessageIndex
|
|
@@ -3888,7 +3889,7 @@ var MidGenerationCompressor = class {
|
|
|
3888
3889
|
for (const message of newMessages) if (Array.isArray(message.content)) {
|
|
3889
3890
|
for (const block of message.content) if (block.type === "tool-result") {
|
|
3890
3891
|
if (block.toolName === "get_reference_artifact" || block.toolName === "thinking_complete") {
|
|
3891
|
-
logger$
|
|
3892
|
+
logger$16.debug({
|
|
3892
3893
|
toolCallId: block.toolCallId,
|
|
3893
3894
|
toolName: block.toolName
|
|
3894
3895
|
}, "Skipping special tool - not creating artifacts");
|
|
@@ -3896,14 +3897,14 @@ var MidGenerationCompressor = class {
|
|
|
3896
3897
|
continue;
|
|
3897
3898
|
}
|
|
3898
3899
|
if (this.processedToolCalls.has(block.toolCallId)) {
|
|
3899
|
-
logger$
|
|
3900
|
+
logger$16.debug({
|
|
3900
3901
|
toolCallId: block.toolCallId,
|
|
3901
3902
|
toolName: block.toolName
|
|
3902
3903
|
}, "Skipping already processed tool call");
|
|
3903
3904
|
continue;
|
|
3904
3905
|
}
|
|
3905
3906
|
const artifactId = `compress_${block.toolName || "tool"}_${block.toolCallId || Date.now()}_${(0, crypto.randomUUID)().slice(0, 8)}`;
|
|
3906
|
-
logger$
|
|
3907
|
+
logger$16.debug({
|
|
3907
3908
|
artifactId,
|
|
3908
3909
|
toolName: block.toolName,
|
|
3909
3910
|
toolCallId: block.toolCallId
|
|
@@ -3918,7 +3919,7 @@ var MidGenerationCompressor = class {
|
|
|
3918
3919
|
compressedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3919
3920
|
};
|
|
3920
3921
|
if (this.isEmpty(toolResultData)) {
|
|
3921
|
-
logger$
|
|
3922
|
+
logger$16.debug({
|
|
3922
3923
|
toolName: block.toolName,
|
|
3923
3924
|
toolCallId: block.toolCallId
|
|
3924
3925
|
}, "Skipping empty tool result");
|
|
@@ -3947,7 +3948,7 @@ var MidGenerationCompressor = class {
|
|
|
3947
3948
|
};
|
|
3948
3949
|
const fullData = artifactData.data;
|
|
3949
3950
|
if (!(fullData && typeof fullData === "object" && Object.keys(fullData).length > 0 && fullData.toolResult && (typeof fullData.toolResult !== "object" || Object.keys(fullData.toolResult).length > 0))) {
|
|
3950
|
-
logger$
|
|
3951
|
+
logger$16.debug({
|
|
3951
3952
|
artifactId,
|
|
3952
3953
|
toolName: block.toolName,
|
|
3953
3954
|
toolCallId: block.toolCallId
|
|
@@ -3960,7 +3961,7 @@ var MidGenerationCompressor = class {
|
|
|
3960
3961
|
}
|
|
3961
3962
|
}
|
|
3962
3963
|
this.lastProcessedMessageIndex = messages.length;
|
|
3963
|
-
logger$
|
|
3964
|
+
logger$16.debug({
|
|
3964
3965
|
totalArtifactsCreated: Object.keys(toolCallToArtifactMap).length,
|
|
3965
3966
|
newMessageIndex: this.lastProcessedMessageIndex
|
|
3966
3967
|
}, "Compression artifact processing completed");
|
|
@@ -3971,7 +3972,7 @@ var MidGenerationCompressor = class {
|
|
|
3971
3972
|
*/
|
|
3972
3973
|
async createConversationSummary(messages, toolCallToArtifactMap) {
|
|
3973
3974
|
const textMessages = this.extractTextMessages(messages, toolCallToArtifactMap);
|
|
3974
|
-
logger$
|
|
3975
|
+
logger$16.debug({
|
|
3975
3976
|
sessionId: this.sessionId,
|
|
3976
3977
|
messageCount: messages.length,
|
|
3977
3978
|
textMessageCount: textMessages.length,
|
|
@@ -3990,7 +3991,7 @@ var MidGenerationCompressor = class {
|
|
|
3990
3991
|
toolCallToArtifactMap
|
|
3991
3992
|
});
|
|
3992
3993
|
this.cumulativeSummary = summary;
|
|
3993
|
-
logger$
|
|
3994
|
+
logger$16.debug({
|
|
3994
3995
|
sessionId: this.sessionId,
|
|
3995
3996
|
summaryGenerated: !!summary,
|
|
3996
3997
|
summaryHighLevel: summary?.high_level,
|
|
@@ -4114,7 +4115,7 @@ var MidGenerationCompressor = class {
|
|
|
4114
4115
|
|
|
4115
4116
|
//#endregion
|
|
4116
4117
|
//#region src/services/PendingToolApprovalManager.ts
|
|
4117
|
-
const logger$
|
|
4118
|
+
const logger$15 = (0, __inkeep_agents_core.getLogger)("PendingToolApprovalManager");
|
|
4118
4119
|
const APPROVAL_CLEANUP_INTERVAL_MS = 120 * 1e3;
|
|
4119
4120
|
const APPROVAL_TIMEOUT_MS = 600 * 1e3;
|
|
4120
4121
|
/**
|
|
@@ -4156,7 +4157,7 @@ var PendingToolApprovalManager = class PendingToolApprovalManager {
|
|
|
4156
4157
|
timeoutId
|
|
4157
4158
|
};
|
|
4158
4159
|
this.pendingApprovals.set(toolCallId, approval);
|
|
4159
|
-
logger$
|
|
4160
|
+
logger$15.info({
|
|
4160
4161
|
toolCallId,
|
|
4161
4162
|
toolName,
|
|
4162
4163
|
conversationId,
|
|
@@ -4170,10 +4171,10 @@ var PendingToolApprovalManager = class PendingToolApprovalManager {
|
|
|
4170
4171
|
approveToolCall(toolCallId) {
|
|
4171
4172
|
const approval = this.pendingApprovals.get(toolCallId);
|
|
4172
4173
|
if (!approval) {
|
|
4173
|
-
logger$
|
|
4174
|
+
logger$15.warn({ toolCallId }, "Tool approval not found or already processed");
|
|
4174
4175
|
return false;
|
|
4175
4176
|
}
|
|
4176
|
-
logger$
|
|
4177
|
+
logger$15.info({
|
|
4177
4178
|
toolCallId,
|
|
4178
4179
|
toolName: approval.toolName,
|
|
4179
4180
|
conversationId: approval.conversationId
|
|
@@ -4189,10 +4190,10 @@ var PendingToolApprovalManager = class PendingToolApprovalManager {
|
|
|
4189
4190
|
denyToolCall(toolCallId, reason) {
|
|
4190
4191
|
const approval = this.pendingApprovals.get(toolCallId);
|
|
4191
4192
|
if (!approval) {
|
|
4192
|
-
logger$
|
|
4193
|
+
logger$15.warn({ toolCallId }, "Tool approval not found or already processed");
|
|
4193
4194
|
return false;
|
|
4194
4195
|
}
|
|
4195
|
-
logger$
|
|
4196
|
+
logger$15.info({
|
|
4196
4197
|
toolCallId,
|
|
4197
4198
|
toolName: approval.toolName,
|
|
4198
4199
|
conversationId: approval.conversationId,
|
|
@@ -4221,7 +4222,7 @@ var PendingToolApprovalManager = class PendingToolApprovalManager {
|
|
|
4221
4222
|
});
|
|
4222
4223
|
cleanedUp++;
|
|
4223
4224
|
}
|
|
4224
|
-
if (cleanedUp > 0) logger$
|
|
4225
|
+
if (cleanedUp > 0) logger$15.info({ cleanedUp }, "Cleaned up expired tool approvals");
|
|
4225
4226
|
}
|
|
4226
4227
|
/**
|
|
4227
4228
|
* Get current status for monitoring
|
|
@@ -4244,7 +4245,7 @@ const pendingToolApprovalManager = PendingToolApprovalManager.getInstance();
|
|
|
4244
4245
|
|
|
4245
4246
|
//#endregion
|
|
4246
4247
|
//#region src/services/ResponseFormatter.ts
|
|
4247
|
-
const logger$
|
|
4248
|
+
const logger$14 = (0, __inkeep_agents_core.getLogger)("ResponseFormatter");
|
|
4248
4249
|
/**
|
|
4249
4250
|
* Response formatter that uses the unified ArtifactParser to convert artifact markers
|
|
4250
4251
|
* into data parts for consistent artifact handling across all agent responses
|
|
@@ -4293,7 +4294,7 @@ var ResponseFormatter = class {
|
|
|
4293
4294
|
return { parts };
|
|
4294
4295
|
} catch (error) {
|
|
4295
4296
|
(0, __inkeep_agents_core.setSpanWithError)(span, error instanceof Error ? error : new Error(String(error)));
|
|
4296
|
-
logger$
|
|
4297
|
+
logger$14.error({
|
|
4297
4298
|
error,
|
|
4298
4299
|
responseObject
|
|
4299
4300
|
}, "Error formatting object response");
|
|
@@ -4346,7 +4347,7 @@ var ResponseFormatter = class {
|
|
|
4346
4347
|
return { parts };
|
|
4347
4348
|
} catch (error) {
|
|
4348
4349
|
(0, __inkeep_agents_core.setSpanWithError)(span, error instanceof Error ? error : new Error(String(error)));
|
|
4349
|
-
logger$
|
|
4350
|
+
logger$14.error({
|
|
4350
4351
|
error,
|
|
4351
4352
|
responseText
|
|
4352
4353
|
}, "Error formatting response");
|
|
@@ -4764,6 +4765,151 @@ var ArtifactCreateSchema = class {
|
|
|
4764
4765
|
}
|
|
4765
4766
|
};
|
|
4766
4767
|
|
|
4768
|
+
//#endregion
|
|
4769
|
+
//#region src/utils/model-context-utils.ts
|
|
4770
|
+
const logger$13 = (0, __inkeep_agents_core.getLogger)("ModelContextUtils");
|
|
4771
|
+
/**
|
|
4772
|
+
* Extract model ID from model settings for llm-info lookup
|
|
4773
|
+
*/
|
|
4774
|
+
function extractModelIdForLlmInfo(modelSettings) {
|
|
4775
|
+
if (!modelSettings?.model) return null;
|
|
4776
|
+
const modelString = modelSettings.model.trim();
|
|
4777
|
+
if (modelString.includes("/")) {
|
|
4778
|
+
const parts = modelString.split("/");
|
|
4779
|
+
return parts[parts.length - 1];
|
|
4780
|
+
}
|
|
4781
|
+
return modelString;
|
|
4782
|
+
}
|
|
4783
|
+
/**
|
|
4784
|
+
* Get context window size for a model using llm-info
|
|
4785
|
+
* Falls back to default values if model not found
|
|
4786
|
+
*/
|
|
4787
|
+
function getModelContextWindow(modelSettings) {
|
|
4788
|
+
const defaultContextWindow = 12e4;
|
|
4789
|
+
if (!modelSettings?.model) {
|
|
4790
|
+
logger$13.debug({}, "No model settings provided, using fallback");
|
|
4791
|
+
return {
|
|
4792
|
+
contextWindow: defaultContextWindow,
|
|
4793
|
+
hasValidContextWindow: false,
|
|
4794
|
+
modelId: "unknown",
|
|
4795
|
+
source: "fallback"
|
|
4796
|
+
};
|
|
4797
|
+
}
|
|
4798
|
+
const modelId = extractModelIdForLlmInfo(modelSettings);
|
|
4799
|
+
if (!modelId) {
|
|
4800
|
+
logger$13.debug({ modelString: modelSettings.model }, "Could not extract model ID for llm-info lookup");
|
|
4801
|
+
return {
|
|
4802
|
+
contextWindow: defaultContextWindow,
|
|
4803
|
+
hasValidContextWindow: false,
|
|
4804
|
+
modelId: modelSettings.model,
|
|
4805
|
+
source: "fallback"
|
|
4806
|
+
};
|
|
4807
|
+
}
|
|
4808
|
+
try {
|
|
4809
|
+
const modelDetails = llm_info.ModelInfoMap[modelId];
|
|
4810
|
+
if (modelDetails && modelDetails.contextWindowTokenLimit && modelDetails.contextWindowTokenLimit > 0) {
|
|
4811
|
+
logger$13.debug({
|
|
4812
|
+
modelId,
|
|
4813
|
+
contextWindow: modelDetails.contextWindowTokenLimit,
|
|
4814
|
+
originalModel: modelSettings.model
|
|
4815
|
+
}, "Found context window from llm-info");
|
|
4816
|
+
return {
|
|
4817
|
+
contextWindow: modelDetails.contextWindowTokenLimit,
|
|
4818
|
+
hasValidContextWindow: true,
|
|
4819
|
+
modelId,
|
|
4820
|
+
source: "llm-info"
|
|
4821
|
+
};
|
|
4822
|
+
} else logger$13.debug({
|
|
4823
|
+
modelId,
|
|
4824
|
+
modelDetails,
|
|
4825
|
+
originalModel: modelSettings.model
|
|
4826
|
+
}, "No valid context window found in llm-info");
|
|
4827
|
+
} catch (error) {
|
|
4828
|
+
logger$13.debug({
|
|
4829
|
+
modelId,
|
|
4830
|
+
error: error instanceof Error ? error.message : String(error),
|
|
4831
|
+
originalModel: modelSettings.model
|
|
4832
|
+
}, "Error getting model details from llm-info");
|
|
4833
|
+
}
|
|
4834
|
+
logger$13.debug({
|
|
4835
|
+
modelId,
|
|
4836
|
+
defaultContextWindow
|
|
4837
|
+
}, "Using fallback context window");
|
|
4838
|
+
return {
|
|
4839
|
+
contextWindow: defaultContextWindow,
|
|
4840
|
+
hasValidContextWindow: false,
|
|
4841
|
+
modelId,
|
|
4842
|
+
source: "fallback"
|
|
4843
|
+
};
|
|
4844
|
+
}
|
|
4845
|
+
/**
|
|
4846
|
+
* Get model-size aware compression parameters
|
|
4847
|
+
* Uses aggressive thresholds for better utilization, especially on large models
|
|
4848
|
+
*/
|
|
4849
|
+
function getCompressionParams(contextWindow) {
|
|
4850
|
+
if (contextWindow < 1e5) return {
|
|
4851
|
+
threshold: .85,
|
|
4852
|
+
bufferPct: .1
|
|
4853
|
+
};
|
|
4854
|
+
else if (contextWindow < 5e5) return {
|
|
4855
|
+
threshold: .9,
|
|
4856
|
+
bufferPct: .07
|
|
4857
|
+
};
|
|
4858
|
+
else return {
|
|
4859
|
+
threshold: .95,
|
|
4860
|
+
bufferPct: .04
|
|
4861
|
+
};
|
|
4862
|
+
}
|
|
4863
|
+
/**
|
|
4864
|
+
* Get compression configuration based on model context window
|
|
4865
|
+
* Uses actual model context window when available, otherwise falls back to environment variables
|
|
4866
|
+
*/
|
|
4867
|
+
function getCompressionConfigForModel(modelSettings) {
|
|
4868
|
+
const modelContextInfo = getModelContextWindow(modelSettings);
|
|
4869
|
+
const envHardLimit = parseInt(process.env.AGENTS_COMPRESSION_HARD_LIMIT || "120000");
|
|
4870
|
+
const envSafetyBuffer = parseInt(process.env.AGENTS_COMPRESSION_SAFETY_BUFFER || "20000");
|
|
4871
|
+
const enabled = process.env.AGENTS_COMPRESSION_ENABLED !== "false";
|
|
4872
|
+
if (modelContextInfo.hasValidContextWindow && modelContextInfo.contextWindow) {
|
|
4873
|
+
const params = getCompressionParams(modelContextInfo.contextWindow);
|
|
4874
|
+
const hardLimit = Math.floor(modelContextInfo.contextWindow * params.threshold);
|
|
4875
|
+
const safetyBuffer = Math.floor(modelContextInfo.contextWindow * params.bufferPct);
|
|
4876
|
+
const triggerPoint = hardLimit - safetyBuffer;
|
|
4877
|
+
const triggerPercentage = (triggerPoint / modelContextInfo.contextWindow * 100).toFixed(1);
|
|
4878
|
+
logger$13.info({
|
|
4879
|
+
modelId: modelContextInfo.modelId,
|
|
4880
|
+
contextWindow: modelContextInfo.contextWindow,
|
|
4881
|
+
hardLimit,
|
|
4882
|
+
safetyBuffer,
|
|
4883
|
+
triggerPoint,
|
|
4884
|
+
triggerPercentage: `${triggerPercentage}%`,
|
|
4885
|
+
threshold: params.threshold,
|
|
4886
|
+
bufferPct: params.bufferPct
|
|
4887
|
+
}, "Using model-size aware compression configuration");
|
|
4888
|
+
return {
|
|
4889
|
+
hardLimit,
|
|
4890
|
+
safetyBuffer,
|
|
4891
|
+
enabled,
|
|
4892
|
+
source: "model-specific",
|
|
4893
|
+
modelContextInfo
|
|
4894
|
+
};
|
|
4895
|
+
} else {
|
|
4896
|
+
const source = process.env.AGENTS_COMPRESSION_HARD_LIMIT ? "environment" : "default";
|
|
4897
|
+
logger$13.debug({
|
|
4898
|
+
modelId: modelContextInfo.modelId,
|
|
4899
|
+
hardLimit: envHardLimit,
|
|
4900
|
+
safetyBuffer: envSafetyBuffer,
|
|
4901
|
+
source
|
|
4902
|
+
}, "Using fallback compression configuration");
|
|
4903
|
+
return {
|
|
4904
|
+
hardLimit: envHardLimit,
|
|
4905
|
+
safetyBuffer: envSafetyBuffer,
|
|
4906
|
+
enabled,
|
|
4907
|
+
source,
|
|
4908
|
+
modelContextInfo
|
|
4909
|
+
};
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
|
|
4767
4913
|
//#endregion
|
|
4768
4914
|
//#region src/a2a/client.ts
|
|
4769
4915
|
const logger$12 = (0, __inkeep_agents_core.getLogger)("a2aClient");
|
|
@@ -7694,7 +7840,12 @@ ${typeof cleanResult === "string" ? cleanResult : JSON.stringify(cleanResult, nu
|
|
|
7694
7840
|
content: userMessage
|
|
7695
7841
|
});
|
|
7696
7842
|
const originalMessageCount = messages.length;
|
|
7697
|
-
const
|
|
7843
|
+
const compressionConfigResult = getCompressionConfigForModel(primaryModelSettings);
|
|
7844
|
+
const compressionConfig = {
|
|
7845
|
+
hardLimit: compressionConfigResult.hardLimit,
|
|
7846
|
+
safetyBuffer: compressionConfigResult.safetyBuffer,
|
|
7847
|
+
enabled: compressionConfigResult.enabled
|
|
7848
|
+
};
|
|
7698
7849
|
const compressor = compressionConfig.enabled ? new MidGenerationCompressor(sessionId, contextId, this.config.tenantId, this.config.projectId, compressionConfig, this.getSummarizerModel(), primaryModelSettings) : null;
|
|
7699
7850
|
this.currentCompressor = compressor;
|
|
7700
7851
|
if (shouldStreamPhase1) {
|