@inkeep/agents-sdk 0.6.4 → 0.6.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 +310 -465
- package/dist/index.d.cts +66 -59
- package/dist/index.d.ts +66 -59
- package/dist/index.js +310 -465
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -437,6 +437,11 @@ var Tool = class {
|
|
|
437
437
|
}
|
|
438
438
|
};
|
|
439
439
|
|
|
440
|
+
// src/utils/tool-normalization.ts
|
|
441
|
+
function isAgentMcpConfig(value) {
|
|
442
|
+
return value !== null && typeof value === "object" && "server" in value && "selectedTools" in value && Array.isArray(value.selectedTools) && value.server && typeof value.server === "object";
|
|
443
|
+
}
|
|
444
|
+
|
|
440
445
|
// src/agent.ts
|
|
441
446
|
var logger4 = agentsCore.getLogger("agent");
|
|
442
447
|
function resolveGetter(value) {
|
|
@@ -501,14 +506,13 @@ var Agent = class {
|
|
|
501
506
|
if (tool && typeof tool === "object") {
|
|
502
507
|
let id;
|
|
503
508
|
let toolInstance;
|
|
504
|
-
if (
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
toolInstance =
|
|
508
|
-
toolInstance.selectedTools = agentMcpConfig.selectedTools;
|
|
509
|
+
if (isAgentMcpConfig(tool)) {
|
|
510
|
+
id = tool.server.getId();
|
|
511
|
+
toolInstance = tool.server;
|
|
512
|
+
toolInstance.selectedTools = tool.selectedTools;
|
|
509
513
|
} else {
|
|
510
|
-
id = tool.id || tool.getId?.() || tool.name;
|
|
511
514
|
toolInstance = tool;
|
|
515
|
+
id = toolInstance.getId();
|
|
512
516
|
}
|
|
513
517
|
if (id) {
|
|
514
518
|
toolRecord[id] = toolInstance;
|
|
@@ -1054,171 +1058,9 @@ var Agent = class {
|
|
|
1054
1058
|
}
|
|
1055
1059
|
}
|
|
1056
1060
|
};
|
|
1057
|
-
var logger5 = agentsCore.getLogger("
|
|
1058
|
-
var ExternalAgent = class {
|
|
1059
|
-
constructor(config) {
|
|
1060
|
-
__publicField(this, "config");
|
|
1061
|
-
__publicField(this, "type", "external");
|
|
1062
|
-
__publicField(this, "initialized", false);
|
|
1063
|
-
__publicField(this, "tenantId");
|
|
1064
|
-
__publicField(this, "baseURL");
|
|
1065
|
-
this.config = { ...config, type: "external" };
|
|
1066
|
-
this.tenantId = "default";
|
|
1067
|
-
this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
|
|
1068
|
-
logger5.debug(
|
|
1069
|
-
{
|
|
1070
|
-
externalAgentName: this.config.name,
|
|
1071
|
-
baseUrl: this.config.baseUrl,
|
|
1072
|
-
tenantId: this.tenantId
|
|
1073
|
-
},
|
|
1074
|
-
"External Agent constructor initialized"
|
|
1075
|
-
);
|
|
1076
|
-
}
|
|
1077
|
-
/**
|
|
1078
|
-
* Initialize the external agent by upserting it in the database
|
|
1079
|
-
*/
|
|
1080
|
-
async init() {
|
|
1081
|
-
if (this.initialized) return;
|
|
1082
|
-
try {
|
|
1083
|
-
await this.upsertExternalAgent();
|
|
1084
|
-
logger5.info(
|
|
1085
|
-
{
|
|
1086
|
-
externalAgentId: this.getId()
|
|
1087
|
-
},
|
|
1088
|
-
"External agent initialized successfully"
|
|
1089
|
-
);
|
|
1090
|
-
this.initialized = true;
|
|
1091
|
-
} catch (error) {
|
|
1092
|
-
logger5.error(
|
|
1093
|
-
{
|
|
1094
|
-
externalAgentId: this.getId(),
|
|
1095
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
1096
|
-
},
|
|
1097
|
-
"Failed to initialize external agent"
|
|
1098
|
-
);
|
|
1099
|
-
throw error;
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
// Set context (tenantId) from external source (graph, CLI, etc)
|
|
1103
|
-
setContext(tenantId) {
|
|
1104
|
-
this.tenantId = tenantId;
|
|
1105
|
-
}
|
|
1106
|
-
// Compute ID from name using a simple slug transformation
|
|
1107
|
-
getId() {
|
|
1108
|
-
return this.config.id;
|
|
1109
|
-
}
|
|
1110
|
-
// Private method to upsert external agent (create or update)
|
|
1111
|
-
async upsertExternalAgent() {
|
|
1112
|
-
const externalAgentData = {
|
|
1113
|
-
id: this.getId(),
|
|
1114
|
-
name: this.config.name,
|
|
1115
|
-
description: this.config.description,
|
|
1116
|
-
baseUrl: this.config.baseUrl,
|
|
1117
|
-
credentialReferenceId: this.config.credentialReference?.id || void 0,
|
|
1118
|
-
headers: this.config.headers || void 0
|
|
1119
|
-
};
|
|
1120
|
-
const updateResponse = await fetch(
|
|
1121
|
-
`${this.baseURL}/tenants/${this.tenantId}/external-agents/${this.getId()}`,
|
|
1122
|
-
{
|
|
1123
|
-
method: "PUT",
|
|
1124
|
-
headers: {
|
|
1125
|
-
"Content-Type": "application/json"
|
|
1126
|
-
},
|
|
1127
|
-
body: JSON.stringify(externalAgentData)
|
|
1128
|
-
}
|
|
1129
|
-
);
|
|
1130
|
-
if (updateResponse.ok) {
|
|
1131
|
-
logger5.info(
|
|
1132
|
-
{
|
|
1133
|
-
externalAgentId: this.getId()
|
|
1134
|
-
},
|
|
1135
|
-
"External agent updated successfully"
|
|
1136
|
-
);
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
if (updateResponse.status === 404) {
|
|
1140
|
-
logger5.info(
|
|
1141
|
-
{
|
|
1142
|
-
externalAgentId: this.getId()
|
|
1143
|
-
},
|
|
1144
|
-
"External agent not found, creating new external agent"
|
|
1145
|
-
);
|
|
1146
|
-
const createResponse = await fetch(
|
|
1147
|
-
`${this.baseURL}/tenants/${this.tenantId}/external-agents`,
|
|
1148
|
-
{
|
|
1149
|
-
method: "POST",
|
|
1150
|
-
headers: {
|
|
1151
|
-
"Content-Type": "application/json"
|
|
1152
|
-
},
|
|
1153
|
-
body: JSON.stringify(externalAgentData)
|
|
1154
|
-
}
|
|
1155
|
-
);
|
|
1156
|
-
if (!createResponse.ok) {
|
|
1157
|
-
const errorText2 = await createResponse.text().catch(() => "Unknown error");
|
|
1158
|
-
throw new Error(
|
|
1159
|
-
`Failed to create external agent: ${createResponse.status} ${createResponse.statusText} - ${errorText2}`
|
|
1160
|
-
);
|
|
1161
|
-
}
|
|
1162
|
-
logger5.info(
|
|
1163
|
-
{
|
|
1164
|
-
externalAgentId: this.getId()
|
|
1165
|
-
},
|
|
1166
|
-
"External agent created successfully"
|
|
1167
|
-
);
|
|
1168
|
-
return;
|
|
1169
|
-
}
|
|
1170
|
-
const errorText = await updateResponse.text().catch(() => "Unknown error");
|
|
1171
|
-
throw new Error(
|
|
1172
|
-
`Failed to update external agent: ${updateResponse.status} ${updateResponse.statusText} - ${errorText}`
|
|
1173
|
-
);
|
|
1174
|
-
}
|
|
1175
|
-
/**
|
|
1176
|
-
* Get the external agent configuration
|
|
1177
|
-
*/
|
|
1178
|
-
getConfig() {
|
|
1179
|
-
return { ...this.config };
|
|
1180
|
-
}
|
|
1181
|
-
/**
|
|
1182
|
-
* Get the external agent name
|
|
1183
|
-
*/
|
|
1184
|
-
getName() {
|
|
1185
|
-
return this.config.name;
|
|
1186
|
-
}
|
|
1187
|
-
/**
|
|
1188
|
-
* Get the external agent base URL
|
|
1189
|
-
*/
|
|
1190
|
-
getBaseUrl() {
|
|
1191
|
-
return this.config.baseUrl;
|
|
1192
|
-
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Get the tenant ID
|
|
1195
|
-
*/
|
|
1196
|
-
getTenantId() {
|
|
1197
|
-
return this.tenantId;
|
|
1198
|
-
}
|
|
1199
|
-
getDescription() {
|
|
1200
|
-
return this.config.description || "";
|
|
1201
|
-
}
|
|
1202
|
-
getCredentialReferenceId() {
|
|
1203
|
-
return this.config.credentialReference?.id || void 0;
|
|
1204
|
-
}
|
|
1205
|
-
getHeaders() {
|
|
1206
|
-
return this.config.headers;
|
|
1207
|
-
}
|
|
1208
|
-
};
|
|
1209
|
-
function externalAgent(config) {
|
|
1210
|
-
return new ExternalAgent(config);
|
|
1211
|
-
}
|
|
1212
|
-
function externalAgents(configs) {
|
|
1213
|
-
const builders = {};
|
|
1214
|
-
for (const [name, config] of Object.entries(configs)) {
|
|
1215
|
-
builders[name] = externalAgent(config);
|
|
1216
|
-
}
|
|
1217
|
-
return builders;
|
|
1218
|
-
}
|
|
1219
|
-
var logger6 = agentsCore.getLogger("graphFullClient");
|
|
1061
|
+
var logger5 = agentsCore.getLogger("graphFullClient");
|
|
1220
1062
|
async function updateFullGraphViaAPI(tenantId, projectId, apiUrl, graphId, graphData) {
|
|
1221
|
-
|
|
1063
|
+
logger5.info(
|
|
1222
1064
|
{
|
|
1223
1065
|
tenantId,
|
|
1224
1066
|
projectId,
|
|
@@ -1248,7 +1090,7 @@ async function updateFullGraphViaAPI(tenantId, projectId, apiUrl, graphId, graph
|
|
|
1248
1090
|
errorMessage = errorText;
|
|
1249
1091
|
}
|
|
1250
1092
|
}
|
|
1251
|
-
|
|
1093
|
+
logger5.error(
|
|
1252
1094
|
{
|
|
1253
1095
|
status: response.status,
|
|
1254
1096
|
error: errorMessage
|
|
@@ -1258,7 +1100,7 @@ async function updateFullGraphViaAPI(tenantId, projectId, apiUrl, graphId, graph
|
|
|
1258
1100
|
throw new Error(errorMessage);
|
|
1259
1101
|
}
|
|
1260
1102
|
const result = await response.json();
|
|
1261
|
-
|
|
1103
|
+
logger5.info(
|
|
1262
1104
|
{
|
|
1263
1105
|
graphId
|
|
1264
1106
|
},
|
|
@@ -1268,7 +1110,7 @@ async function updateFullGraphViaAPI(tenantId, projectId, apiUrl, graphId, graph
|
|
|
1268
1110
|
}
|
|
1269
1111
|
|
|
1270
1112
|
// src/graph.ts
|
|
1271
|
-
var
|
|
1113
|
+
var logger6 = agentsCore.getLogger("graph");
|
|
1272
1114
|
function resolveGetter2(value) {
|
|
1273
1115
|
if (typeof value === "function") {
|
|
1274
1116
|
return value();
|
|
@@ -1323,7 +1165,7 @@ var AgentGraph = class {
|
|
|
1323
1165
|
if (this.models) {
|
|
1324
1166
|
this.propagateImmediateModelSettings();
|
|
1325
1167
|
}
|
|
1326
|
-
|
|
1168
|
+
logger6.info(
|
|
1327
1169
|
{
|
|
1328
1170
|
graphId: this.graphId,
|
|
1329
1171
|
tenantId: this.tenantId,
|
|
@@ -1356,9 +1198,6 @@ var AgentGraph = class {
|
|
|
1356
1198
|
if ("setContext" in toolInstance && typeof toolInstance.setContext === "function") {
|
|
1357
1199
|
toolInstance.setContext(tenantId, projectId);
|
|
1358
1200
|
}
|
|
1359
|
-
if ("baseURL" in toolInstance && !toolInstance.baseURL) {
|
|
1360
|
-
toolInstance.baseURL = apiUrl;
|
|
1361
|
-
}
|
|
1362
1201
|
}
|
|
1363
1202
|
}
|
|
1364
1203
|
}
|
|
@@ -1366,7 +1205,7 @@ var AgentGraph = class {
|
|
|
1366
1205
|
if (this.contextConfig?.setContext) {
|
|
1367
1206
|
this.contextConfig.setContext(tenantId, projectId);
|
|
1368
1207
|
}
|
|
1369
|
-
|
|
1208
|
+
logger6.info(
|
|
1370
1209
|
{
|
|
1371
1210
|
graphId: this.graphId,
|
|
1372
1211
|
tenantId: this.tenantId,
|
|
@@ -1394,7 +1233,7 @@ var AgentGraph = class {
|
|
|
1394
1233
|
let toolId;
|
|
1395
1234
|
toolId = toolInstance.getId?.() || toolInstance.id;
|
|
1396
1235
|
if ("selectedTools" in toolInstance && toolInstance.selectedTools !== void 0) {
|
|
1397
|
-
|
|
1236
|
+
logger6.info(
|
|
1398
1237
|
{ toolId, selectedTools: toolInstance.selectedTools },
|
|
1399
1238
|
"Selected tools"
|
|
1400
1239
|
);
|
|
@@ -1450,103 +1289,6 @@ var AgentGraph = class {
|
|
|
1450
1289
|
};
|
|
1451
1290
|
}
|
|
1452
1291
|
}
|
|
1453
|
-
const toolsObject = {};
|
|
1454
|
-
for (const agent2 of this.agents) {
|
|
1455
|
-
if (!agent2.getTransfers) {
|
|
1456
|
-
continue;
|
|
1457
|
-
}
|
|
1458
|
-
const internalAgent = agent2;
|
|
1459
|
-
const agentTools = internalAgent.getTools();
|
|
1460
|
-
for (const [toolName, toolInstance] of Object.entries(agentTools)) {
|
|
1461
|
-
if (toolInstance && typeof toolInstance === "object") {
|
|
1462
|
-
let actualTool;
|
|
1463
|
-
let toolId;
|
|
1464
|
-
if ("server" in toolInstance && "selectedTools" in toolInstance) {
|
|
1465
|
-
const mcpConfig = toolInstance;
|
|
1466
|
-
actualTool = mcpConfig.server;
|
|
1467
|
-
toolId = actualTool.getId();
|
|
1468
|
-
} else {
|
|
1469
|
-
actualTool = toolInstance;
|
|
1470
|
-
toolId = actualTool.getId?.() || actualTool.id || toolName;
|
|
1471
|
-
}
|
|
1472
|
-
if (!toolsObject[toolId]) {
|
|
1473
|
-
let toolConfig;
|
|
1474
|
-
if (actualTool.config?.serverUrl) {
|
|
1475
|
-
toolConfig = {
|
|
1476
|
-
type: "mcp",
|
|
1477
|
-
mcp: {
|
|
1478
|
-
server: {
|
|
1479
|
-
url: actualTool.config.serverUrl
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
};
|
|
1483
|
-
} else if (actualTool.config?.type === "mcp") {
|
|
1484
|
-
toolConfig = actualTool.config;
|
|
1485
|
-
} else {
|
|
1486
|
-
toolConfig = {
|
|
1487
|
-
type: "function",
|
|
1488
|
-
parameters: actualTool.parameters || {}
|
|
1489
|
-
};
|
|
1490
|
-
}
|
|
1491
|
-
const toolData = {
|
|
1492
|
-
id: toolId,
|
|
1493
|
-
name: actualTool.config?.name || actualTool.name || toolName,
|
|
1494
|
-
config: toolConfig,
|
|
1495
|
-
status: actualTool.getStatus?.() || actualTool.status || "unknown"
|
|
1496
|
-
};
|
|
1497
|
-
if (actualTool.config?.imageUrl) {
|
|
1498
|
-
toolData.imageUrl = actualTool.config.imageUrl;
|
|
1499
|
-
}
|
|
1500
|
-
if (actualTool.config?.headers) {
|
|
1501
|
-
toolData.headers = actualTool.config.headers;
|
|
1502
|
-
}
|
|
1503
|
-
if (actualTool.capabilities) {
|
|
1504
|
-
toolData.capabilities = actualTool.capabilities;
|
|
1505
|
-
}
|
|
1506
|
-
if (actualTool.lastHealthCheck) {
|
|
1507
|
-
toolData.lastHealthCheck = actualTool.lastHealthCheck;
|
|
1508
|
-
}
|
|
1509
|
-
if (actualTool.availableTools) {
|
|
1510
|
-
toolData.availableTools = actualTool.availableTools;
|
|
1511
|
-
}
|
|
1512
|
-
if (actualTool.lastError) {
|
|
1513
|
-
toolData.lastError = actualTool.lastError;
|
|
1514
|
-
}
|
|
1515
|
-
if (actualTool.lastToolsSync) {
|
|
1516
|
-
toolData.lastToolsSync = actualTool.lastToolsSync;
|
|
1517
|
-
}
|
|
1518
|
-
if (actualTool.getCredentialReferenceId?.()) {
|
|
1519
|
-
toolData.credentialReferenceId = actualTool.getCredentialReferenceId();
|
|
1520
|
-
}
|
|
1521
|
-
toolsObject[toolId] = toolData;
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
for (const agent2 of this.agents) {
|
|
1527
|
-
if (!this.isInternalAgent(agent2)) {
|
|
1528
|
-
continue;
|
|
1529
|
-
}
|
|
1530
|
-
const internalAgent = agent2;
|
|
1531
|
-
const agentDataComponents = internalAgent.getDataComponents();
|
|
1532
|
-
if (agentDataComponents) {
|
|
1533
|
-
for (const dataComponent2 of agentDataComponents) {
|
|
1534
|
-
dataComponent2.id || dataComponent2.name.toLowerCase().replace(/\s+/g, "-");
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
for (const agent2 of this.agents) {
|
|
1539
|
-
if (!this.isInternalAgent(agent2)) {
|
|
1540
|
-
continue;
|
|
1541
|
-
}
|
|
1542
|
-
const internalAgent = agent2;
|
|
1543
|
-
const agentArtifactComponents = internalAgent.getArtifactComponents();
|
|
1544
|
-
if (agentArtifactComponents) {
|
|
1545
|
-
for (const artifactComponent2 of agentArtifactComponents) {
|
|
1546
|
-
artifactComponent2.id || artifactComponent2.name.toLowerCase().replace(/\s+/g, "-");
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
1292
|
return {
|
|
1551
1293
|
id: this.graphId,
|
|
1552
1294
|
name: this.graphName,
|
|
@@ -1565,7 +1307,7 @@ var AgentGraph = class {
|
|
|
1565
1307
|
* Initialize all tools in all agents (especially IPCTools that need MCP server URLs)
|
|
1566
1308
|
*/
|
|
1567
1309
|
async initializeAllTools() {
|
|
1568
|
-
|
|
1310
|
+
logger6.info({ graphId: this.graphId }, "Initializing all tools in graph");
|
|
1569
1311
|
const toolInitPromises = [];
|
|
1570
1312
|
for (const agent2 of this.agents) {
|
|
1571
1313
|
if (!agent2.getTools) {
|
|
@@ -1589,7 +1331,7 @@ var AgentGraph = class {
|
|
|
1589
1331
|
await toolInstance.init();
|
|
1590
1332
|
}
|
|
1591
1333
|
}
|
|
1592
|
-
|
|
1334
|
+
logger6.debug(
|
|
1593
1335
|
{
|
|
1594
1336
|
agentId: agent2.getId(),
|
|
1595
1337
|
toolName,
|
|
@@ -1599,7 +1341,7 @@ var AgentGraph = class {
|
|
|
1599
1341
|
"Tool initialized successfully"
|
|
1600
1342
|
);
|
|
1601
1343
|
} catch (error) {
|
|
1602
|
-
|
|
1344
|
+
logger6.error(
|
|
1603
1345
|
{
|
|
1604
1346
|
agentId: agent2.getId(),
|
|
1605
1347
|
toolName,
|
|
@@ -1616,7 +1358,7 @@ var AgentGraph = class {
|
|
|
1616
1358
|
}
|
|
1617
1359
|
}
|
|
1618
1360
|
await Promise.all(toolInitPromises);
|
|
1619
|
-
|
|
1361
|
+
logger6.info(
|
|
1620
1362
|
{ graphId: this.graphId, toolCount: toolInitPromises.length },
|
|
1621
1363
|
"All tools initialized successfully"
|
|
1622
1364
|
);
|
|
@@ -1626,10 +1368,10 @@ var AgentGraph = class {
|
|
|
1626
1368
|
*/
|
|
1627
1369
|
async init() {
|
|
1628
1370
|
if (this.initialized) {
|
|
1629
|
-
|
|
1371
|
+
logger6.info({ graphId: this.graphId }, "Graph already initialized");
|
|
1630
1372
|
return;
|
|
1631
1373
|
}
|
|
1632
|
-
|
|
1374
|
+
logger6.info(
|
|
1633
1375
|
{
|
|
1634
1376
|
graphId: this.graphId,
|
|
1635
1377
|
agentCount: this.agents.length
|
|
@@ -1640,7 +1382,7 @@ var AgentGraph = class {
|
|
|
1640
1382
|
await this.initializeAllTools();
|
|
1641
1383
|
await this.applyModelInheritance();
|
|
1642
1384
|
const graphDefinition = await this.toFullGraphDefinition();
|
|
1643
|
-
|
|
1385
|
+
logger6.info(
|
|
1644
1386
|
{
|
|
1645
1387
|
graphId: this.graphId,
|
|
1646
1388
|
mode: "api-client",
|
|
@@ -1655,7 +1397,7 @@ var AgentGraph = class {
|
|
|
1655
1397
|
this.graphId,
|
|
1656
1398
|
graphDefinition
|
|
1657
1399
|
);
|
|
1658
|
-
|
|
1400
|
+
logger6.info(
|
|
1659
1401
|
{
|
|
1660
1402
|
graphId: this.graphId,
|
|
1661
1403
|
agentCount: Object.keys(createdGraph.agents || {}).length
|
|
@@ -1664,7 +1406,7 @@ var AgentGraph = class {
|
|
|
1664
1406
|
);
|
|
1665
1407
|
this.initialized = true;
|
|
1666
1408
|
} catch (error) {
|
|
1667
|
-
|
|
1409
|
+
logger6.error(
|
|
1668
1410
|
{
|
|
1669
1411
|
graphId: this.graphId,
|
|
1670
1412
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1680,10 +1422,10 @@ var AgentGraph = class {
|
|
|
1680
1422
|
*/
|
|
1681
1423
|
async initLegacy() {
|
|
1682
1424
|
if (this.initialized) {
|
|
1683
|
-
|
|
1425
|
+
logger6.info({ graphId: this.graphId }, "Graph already initialized");
|
|
1684
1426
|
return;
|
|
1685
1427
|
}
|
|
1686
|
-
|
|
1428
|
+
logger6.info(
|
|
1687
1429
|
{
|
|
1688
1430
|
graphId: this.graphId,
|
|
1689
1431
|
agentCount: this.agents.length
|
|
@@ -1693,7 +1435,7 @@ var AgentGraph = class {
|
|
|
1693
1435
|
try {
|
|
1694
1436
|
if (this.contextConfig) {
|
|
1695
1437
|
await this.contextConfig.init();
|
|
1696
|
-
|
|
1438
|
+
logger6.info(
|
|
1697
1439
|
{
|
|
1698
1440
|
graphId: this.graphId,
|
|
1699
1441
|
contextConfigId: this.contextConfig.getId()
|
|
@@ -1705,7 +1447,7 @@ var AgentGraph = class {
|
|
|
1705
1447
|
try {
|
|
1706
1448
|
agent2.config.graphId = this.graphId;
|
|
1707
1449
|
await agent2.init();
|
|
1708
|
-
|
|
1450
|
+
logger6.debug(
|
|
1709
1451
|
{
|
|
1710
1452
|
agentId: agent2.getId(),
|
|
1711
1453
|
graphId: this.graphId
|
|
@@ -1713,7 +1455,7 @@ var AgentGraph = class {
|
|
|
1713
1455
|
"Agent initialized in graph"
|
|
1714
1456
|
);
|
|
1715
1457
|
} catch (error) {
|
|
1716
|
-
|
|
1458
|
+
logger6.error(
|
|
1717
1459
|
{
|
|
1718
1460
|
agentId: agent2.getId(),
|
|
1719
1461
|
graphId: this.graphId,
|
|
@@ -1730,7 +1472,7 @@ var AgentGraph = class {
|
|
|
1730
1472
|
await this.createAgentRelations();
|
|
1731
1473
|
await this.saveRelations();
|
|
1732
1474
|
this.initialized = true;
|
|
1733
|
-
|
|
1475
|
+
logger6.info(
|
|
1734
1476
|
{
|
|
1735
1477
|
graphId: this.graphId,
|
|
1736
1478
|
agentCount: this.agents.length
|
|
@@ -1738,7 +1480,7 @@ var AgentGraph = class {
|
|
|
1738
1480
|
"Agent graph initialized successfully"
|
|
1739
1481
|
);
|
|
1740
1482
|
} catch (error) {
|
|
1741
|
-
|
|
1483
|
+
logger6.error(
|
|
1742
1484
|
{
|
|
1743
1485
|
graphId: this.graphId,
|
|
1744
1486
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -1756,7 +1498,7 @@ var AgentGraph = class {
|
|
|
1756
1498
|
if (!this.defaultAgent) {
|
|
1757
1499
|
throw new Error("No default agent configured for this graph");
|
|
1758
1500
|
}
|
|
1759
|
-
|
|
1501
|
+
logger6.info(
|
|
1760
1502
|
{
|
|
1761
1503
|
graphId: this.graphId,
|
|
1762
1504
|
defaultAgent: this.defaultAgent.getName(),
|
|
@@ -1775,7 +1517,7 @@ var AgentGraph = class {
|
|
|
1775
1517
|
if (!this.defaultAgent) {
|
|
1776
1518
|
throw new Error("No default agent configured for this graph");
|
|
1777
1519
|
}
|
|
1778
|
-
|
|
1520
|
+
logger6.info(
|
|
1779
1521
|
{
|
|
1780
1522
|
graphId: this.graphId,
|
|
1781
1523
|
defaultAgent: this.defaultAgent.getName(),
|
|
@@ -1814,7 +1556,7 @@ var AgentGraph = class {
|
|
|
1814
1556
|
`Agent '${agentId}' is an external agent and cannot be run directly. External agents are only accessible via delegation.`
|
|
1815
1557
|
);
|
|
1816
1558
|
}
|
|
1817
|
-
|
|
1559
|
+
logger6.info(
|
|
1818
1560
|
{
|
|
1819
1561
|
graphId: this.graphId,
|
|
1820
1562
|
agentId,
|
|
@@ -1849,7 +1591,7 @@ var AgentGraph = class {
|
|
|
1849
1591
|
if (this.models && this.isInternalAgent(agent2)) {
|
|
1850
1592
|
this.propagateModelSettingsToAgent(agent2);
|
|
1851
1593
|
}
|
|
1852
|
-
|
|
1594
|
+
logger6.info(
|
|
1853
1595
|
{
|
|
1854
1596
|
graphId: this.graphId,
|
|
1855
1597
|
agentId: agent2.getId(),
|
|
@@ -1866,7 +1608,7 @@ var AgentGraph = class {
|
|
|
1866
1608
|
if (agentToRemove) {
|
|
1867
1609
|
this.agentMap.delete(agentToRemove.getId());
|
|
1868
1610
|
this.agents = this.agents.filter((agent2) => agent2.getId() !== agentToRemove.getId());
|
|
1869
|
-
|
|
1611
|
+
logger6.info(
|
|
1870
1612
|
{
|
|
1871
1613
|
graphId: this.graphId,
|
|
1872
1614
|
agentId: agentToRemove.getId()
|
|
@@ -1895,7 +1637,7 @@ var AgentGraph = class {
|
|
|
1895
1637
|
setDefaultAgent(agent2) {
|
|
1896
1638
|
this.defaultAgent = agent2;
|
|
1897
1639
|
this.addAgent(agent2);
|
|
1898
|
-
|
|
1640
|
+
logger6.info(
|
|
1899
1641
|
{
|
|
1900
1642
|
graphId: this.graphId,
|
|
1901
1643
|
defaultAgent: agent2.getId()
|
|
@@ -2037,7 +1779,7 @@ var AgentGraph = class {
|
|
|
2037
1779
|
});
|
|
2038
1780
|
return project2?.models;
|
|
2039
1781
|
} catch (error) {
|
|
2040
|
-
|
|
1782
|
+
logger6.warn(
|
|
2041
1783
|
{
|
|
2042
1784
|
tenantId: this.tenantId,
|
|
2043
1785
|
projectId: this.projectId,
|
|
@@ -2058,7 +1800,7 @@ var AgentGraph = class {
|
|
|
2058
1800
|
});
|
|
2059
1801
|
return project2?.stopWhen;
|
|
2060
1802
|
} catch (error) {
|
|
2061
|
-
|
|
1803
|
+
logger6.warn(
|
|
2062
1804
|
{
|
|
2063
1805
|
tenantId: this.tenantId,
|
|
2064
1806
|
projectId: this.projectId,
|
|
@@ -2122,7 +1864,7 @@ var AgentGraph = class {
|
|
|
2122
1864
|
}
|
|
2123
1865
|
}
|
|
2124
1866
|
}
|
|
2125
|
-
|
|
1867
|
+
logger6.debug(
|
|
2126
1868
|
{
|
|
2127
1869
|
graphId: this.graphId,
|
|
2128
1870
|
graphStopWhen: this.stopWhen,
|
|
@@ -2172,7 +1914,7 @@ var AgentGraph = class {
|
|
|
2172
1914
|
async executeWithBackend(input, options) {
|
|
2173
1915
|
const normalizedMessages = this.normalizeMessages(input);
|
|
2174
1916
|
const url = `${this.baseURL}/tenants/${this.tenantId}/graphs/${this.graphId}/v1/chat/completions`;
|
|
2175
|
-
|
|
1917
|
+
logger6.info({ url }, "Executing with backend");
|
|
2176
1918
|
const requestBody = {
|
|
2177
1919
|
model: "gpt-4o-mini",
|
|
2178
1920
|
messages: normalizedMessages.map((msg) => ({
|
|
@@ -2256,7 +1998,7 @@ var AgentGraph = class {
|
|
|
2256
1998
|
}
|
|
2257
1999
|
});
|
|
2258
2000
|
if (getResponse.ok) {
|
|
2259
|
-
|
|
2001
|
+
logger6.info({ graphId: this.graphId }, "Graph already exists in backend");
|
|
2260
2002
|
return;
|
|
2261
2003
|
}
|
|
2262
2004
|
if (getResponse.status !== 404) {
|
|
@@ -2267,7 +2009,7 @@ var AgentGraph = class {
|
|
|
2267
2009
|
throw error;
|
|
2268
2010
|
}
|
|
2269
2011
|
}
|
|
2270
|
-
|
|
2012
|
+
logger6.info({ graphId: this.graphId }, "Creating graph in backend");
|
|
2271
2013
|
const createUrl = `${this.baseURL}/tenants/${this.tenantId}/agent-graphs`;
|
|
2272
2014
|
const createResponse = await fetch(createUrl, {
|
|
2273
2015
|
method: "POST",
|
|
@@ -2287,7 +2029,7 @@ var AgentGraph = class {
|
|
|
2287
2029
|
}
|
|
2288
2030
|
const createData = await createResponse.json();
|
|
2289
2031
|
this.graphId = createData.data.id;
|
|
2290
|
-
|
|
2032
|
+
logger6.info({ graph: createData.data }, "Graph created in backend");
|
|
2291
2033
|
} catch (error) {
|
|
2292
2034
|
throw new Error(
|
|
2293
2035
|
`Failed to save graph to database: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
@@ -2312,7 +2054,7 @@ var AgentGraph = class {
|
|
|
2312
2054
|
if (!updateResponse.ok) {
|
|
2313
2055
|
throw new Error(`HTTP ${updateResponse.status}: ${updateResponse.statusText}`);
|
|
2314
2056
|
}
|
|
2315
|
-
|
|
2057
|
+
logger6.debug(
|
|
2316
2058
|
{
|
|
2317
2059
|
graphId: this.graphId,
|
|
2318
2060
|
defaultAgent: this.defaultAgent.getName()
|
|
@@ -2320,7 +2062,7 @@ var AgentGraph = class {
|
|
|
2320
2062
|
"Graph relationships configured"
|
|
2321
2063
|
);
|
|
2322
2064
|
} catch (error) {
|
|
2323
|
-
|
|
2065
|
+
logger6.error(
|
|
2324
2066
|
{
|
|
2325
2067
|
graphId: this.graphId,
|
|
2326
2068
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2343,7 +2085,7 @@ var AgentGraph = class {
|
|
|
2343
2085
|
}
|
|
2344
2086
|
const delegates = agent2.getDelegates();
|
|
2345
2087
|
for (const delegate of delegates) {
|
|
2346
|
-
if (delegate
|
|
2088
|
+
if (delegate.type === "external") {
|
|
2347
2089
|
allRelationPromises.push(this.createExternalAgentRelation(agent2, delegate, "delegate"));
|
|
2348
2090
|
} else {
|
|
2349
2091
|
allRelationPromises.push(
|
|
@@ -2361,7 +2103,7 @@ var AgentGraph = class {
|
|
|
2361
2103
|
successCount++;
|
|
2362
2104
|
} else {
|
|
2363
2105
|
errors.push(result.reason);
|
|
2364
|
-
|
|
2106
|
+
logger6.error(
|
|
2365
2107
|
{
|
|
2366
2108
|
error: result.reason instanceof Error ? result.reason.message : "Unknown error",
|
|
2367
2109
|
graphId: this.graphId
|
|
@@ -2370,7 +2112,7 @@ var AgentGraph = class {
|
|
|
2370
2112
|
);
|
|
2371
2113
|
}
|
|
2372
2114
|
}
|
|
2373
|
-
|
|
2115
|
+
logger6.info(
|
|
2374
2116
|
{
|
|
2375
2117
|
graphId: this.graphId,
|
|
2376
2118
|
totalRelations: allRelationPromises.length,
|
|
@@ -2385,25 +2127,22 @@ var AgentGraph = class {
|
|
|
2385
2127
|
}
|
|
2386
2128
|
async createInternalAgentRelation(sourceAgent, targetAgent, relationType) {
|
|
2387
2129
|
try {
|
|
2388
|
-
const response = await fetch(
|
|
2389
|
-
|
|
2390
|
-
{
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
})
|
|
2401
|
-
}
|
|
2402
|
-
);
|
|
2130
|
+
const response = await fetch(`${this.baseURL}/tenants/${this.tenantId}/agent-relations`, {
|
|
2131
|
+
method: "POST",
|
|
2132
|
+
headers: {
|
|
2133
|
+
"Content-Type": "application/json"
|
|
2134
|
+
},
|
|
2135
|
+
body: JSON.stringify({
|
|
2136
|
+
graphId: this.graphId,
|
|
2137
|
+
sourceAgentId: sourceAgent.getId(),
|
|
2138
|
+
targetAgentId: targetAgent.getId(),
|
|
2139
|
+
relationType
|
|
2140
|
+
})
|
|
2141
|
+
});
|
|
2403
2142
|
if (!response.ok) {
|
|
2404
2143
|
const errorText = await response.text().catch(() => "Unknown error");
|
|
2405
2144
|
if (response.status === 422 && errorText.includes("already exists")) {
|
|
2406
|
-
|
|
2145
|
+
logger6.info(
|
|
2407
2146
|
{
|
|
2408
2147
|
sourceAgentId: sourceAgent.getId(),
|
|
2409
2148
|
targetAgentId: targetAgent.getId(),
|
|
@@ -2416,7 +2155,7 @@ var AgentGraph = class {
|
|
|
2416
2155
|
}
|
|
2417
2156
|
throw new Error(`Failed to create agent relation: ${response.status} - ${errorText}`);
|
|
2418
2157
|
}
|
|
2419
|
-
|
|
2158
|
+
logger6.info(
|
|
2420
2159
|
{
|
|
2421
2160
|
sourceAgentId: sourceAgent.getId(),
|
|
2422
2161
|
targetAgentId: targetAgent.getId(),
|
|
@@ -2426,7 +2165,7 @@ var AgentGraph = class {
|
|
|
2426
2165
|
`${relationType} relation created successfully`
|
|
2427
2166
|
);
|
|
2428
2167
|
} catch (error) {
|
|
2429
|
-
|
|
2168
|
+
logger6.error(
|
|
2430
2169
|
{
|
|
2431
2170
|
sourceAgentId: sourceAgent.getId(),
|
|
2432
2171
|
targetAgentId: targetAgent.getId(),
|
|
@@ -2441,25 +2180,22 @@ var AgentGraph = class {
|
|
|
2441
2180
|
}
|
|
2442
2181
|
async createExternalAgentRelation(sourceAgent, externalAgent2, relationType) {
|
|
2443
2182
|
try {
|
|
2444
|
-
const response = await fetch(
|
|
2445
|
-
|
|
2446
|
-
{
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
})
|
|
2457
|
-
}
|
|
2458
|
-
);
|
|
2183
|
+
const response = await fetch(`${this.baseURL}/tenants/${this.tenantId}/agent-relations`, {
|
|
2184
|
+
method: "POST",
|
|
2185
|
+
headers: {
|
|
2186
|
+
"Content-Type": "application/json"
|
|
2187
|
+
},
|
|
2188
|
+
body: JSON.stringify({
|
|
2189
|
+
graphId: this.graphId,
|
|
2190
|
+
sourceAgentId: sourceAgent.getId(),
|
|
2191
|
+
externalAgentId: externalAgent2.getId(),
|
|
2192
|
+
relationType
|
|
2193
|
+
})
|
|
2194
|
+
});
|
|
2459
2195
|
if (!response.ok) {
|
|
2460
2196
|
const errorText = await response.text().catch(() => "Unknown error");
|
|
2461
2197
|
if (response.status === 422 && errorText.includes("already exists")) {
|
|
2462
|
-
|
|
2198
|
+
logger6.info(
|
|
2463
2199
|
{
|
|
2464
2200
|
sourceAgentId: sourceAgent.getId(),
|
|
2465
2201
|
externalAgentId: externalAgent2.getId(),
|
|
@@ -2474,7 +2210,7 @@ var AgentGraph = class {
|
|
|
2474
2210
|
`Failed to create external agent relation: ${response.status} - ${errorText}`
|
|
2475
2211
|
);
|
|
2476
2212
|
}
|
|
2477
|
-
|
|
2213
|
+
logger6.info(
|
|
2478
2214
|
{
|
|
2479
2215
|
sourceAgentId: sourceAgent.getId(),
|
|
2480
2216
|
externalAgentId: externalAgent2.getId(),
|
|
@@ -2484,7 +2220,7 @@ var AgentGraph = class {
|
|
|
2484
2220
|
`${relationType} relation created successfully`
|
|
2485
2221
|
);
|
|
2486
2222
|
} catch (error) {
|
|
2487
|
-
|
|
2223
|
+
logger6.error(
|
|
2488
2224
|
{
|
|
2489
2225
|
sourceAgentId: sourceAgent.getId(),
|
|
2490
2226
|
externalAgentId: externalAgent2.getId(),
|
|
@@ -2502,7 +2238,7 @@ var AgentGraph = class {
|
|
|
2502
2238
|
*/
|
|
2503
2239
|
async createExternalAgents() {
|
|
2504
2240
|
const externalAgents2 = this.agents.filter((agent2) => this.isExternalAgent(agent2));
|
|
2505
|
-
|
|
2241
|
+
logger6.info(
|
|
2506
2242
|
{
|
|
2507
2243
|
graphId: this.graphId,
|
|
2508
2244
|
externalAgentCount: externalAgents2.length
|
|
@@ -2512,7 +2248,7 @@ var AgentGraph = class {
|
|
|
2512
2248
|
const initPromises = externalAgents2.map(async (externalAgent2) => {
|
|
2513
2249
|
try {
|
|
2514
2250
|
await externalAgent2.init();
|
|
2515
|
-
|
|
2251
|
+
logger6.debug(
|
|
2516
2252
|
{
|
|
2517
2253
|
externalAgentId: externalAgent2.getId(),
|
|
2518
2254
|
graphId: this.graphId
|
|
@@ -2520,7 +2256,7 @@ var AgentGraph = class {
|
|
|
2520
2256
|
"External agent created in database"
|
|
2521
2257
|
);
|
|
2522
2258
|
} catch (error) {
|
|
2523
|
-
|
|
2259
|
+
logger6.error(
|
|
2524
2260
|
{
|
|
2525
2261
|
externalAgentId: externalAgent2.getId(),
|
|
2526
2262
|
graphId: this.graphId,
|
|
@@ -2533,7 +2269,7 @@ var AgentGraph = class {
|
|
|
2533
2269
|
});
|
|
2534
2270
|
try {
|
|
2535
2271
|
await Promise.all(initPromises);
|
|
2536
|
-
|
|
2272
|
+
logger6.info(
|
|
2537
2273
|
{
|
|
2538
2274
|
graphId: this.graphId,
|
|
2539
2275
|
externalAgentCount: externalAgents2.length
|
|
@@ -2541,7 +2277,7 @@ var AgentGraph = class {
|
|
|
2541
2277
|
"All external agents created successfully"
|
|
2542
2278
|
);
|
|
2543
2279
|
} catch (error) {
|
|
2544
|
-
|
|
2280
|
+
logger6.error(
|
|
2545
2281
|
{
|
|
2546
2282
|
graphId: this.graphId,
|
|
2547
2283
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2552,9 +2288,9 @@ var AgentGraph = class {
|
|
|
2552
2288
|
}
|
|
2553
2289
|
}
|
|
2554
2290
|
};
|
|
2555
|
-
var
|
|
2291
|
+
var logger7 = agentsCore.getLogger("projectFullClient");
|
|
2556
2292
|
async function createFullProjectViaAPI(tenantId, apiUrl, projectData) {
|
|
2557
|
-
|
|
2293
|
+
logger7.info(
|
|
2558
2294
|
{
|
|
2559
2295
|
tenantId,
|
|
2560
2296
|
projectId: projectData.id,
|
|
@@ -2573,7 +2309,7 @@ async function createFullProjectViaAPI(tenantId, apiUrl, projectData) {
|
|
|
2573
2309
|
body: JSON.stringify(projectData)
|
|
2574
2310
|
});
|
|
2575
2311
|
} catch (fetchError) {
|
|
2576
|
-
|
|
2312
|
+
logger7.error({
|
|
2577
2313
|
error: fetchError instanceof Error ? fetchError.message : "Unknown fetch error",
|
|
2578
2314
|
url,
|
|
2579
2315
|
tenantId,
|
|
@@ -2594,7 +2330,7 @@ async function createFullProjectViaAPI(tenantId, apiUrl, projectData) {
|
|
|
2594
2330
|
errorMessage = errorText;
|
|
2595
2331
|
}
|
|
2596
2332
|
}
|
|
2597
|
-
|
|
2333
|
+
logger7.error(
|
|
2598
2334
|
{
|
|
2599
2335
|
status: response.status,
|
|
2600
2336
|
error: errorMessage
|
|
@@ -2604,7 +2340,7 @@ async function createFullProjectViaAPI(tenantId, apiUrl, projectData) {
|
|
|
2604
2340
|
throw new Error(errorMessage);
|
|
2605
2341
|
}
|
|
2606
2342
|
const result = await response.json();
|
|
2607
|
-
|
|
2343
|
+
logger7.info(
|
|
2608
2344
|
{
|
|
2609
2345
|
projectId: projectData.id
|
|
2610
2346
|
},
|
|
@@ -2613,7 +2349,7 @@ async function createFullProjectViaAPI(tenantId, apiUrl, projectData) {
|
|
|
2613
2349
|
return result.data;
|
|
2614
2350
|
}
|
|
2615
2351
|
async function updateFullProjectViaAPI(tenantId, apiUrl, projectId, projectData) {
|
|
2616
|
-
|
|
2352
|
+
logger7.info(
|
|
2617
2353
|
{
|
|
2618
2354
|
tenantId,
|
|
2619
2355
|
projectId,
|
|
@@ -2632,7 +2368,7 @@ async function updateFullProjectViaAPI(tenantId, apiUrl, projectId, projectData)
|
|
|
2632
2368
|
body: JSON.stringify(projectData)
|
|
2633
2369
|
});
|
|
2634
2370
|
} catch (fetchError) {
|
|
2635
|
-
|
|
2371
|
+
logger7.error({
|
|
2636
2372
|
error: fetchError instanceof Error ? fetchError.message : "Unknown fetch error",
|
|
2637
2373
|
url,
|
|
2638
2374
|
tenantId,
|
|
@@ -2653,7 +2389,7 @@ async function updateFullProjectViaAPI(tenantId, apiUrl, projectId, projectData)
|
|
|
2653
2389
|
errorMessage = errorText;
|
|
2654
2390
|
}
|
|
2655
2391
|
}
|
|
2656
|
-
|
|
2392
|
+
logger7.error(
|
|
2657
2393
|
{
|
|
2658
2394
|
status: response.status,
|
|
2659
2395
|
error: errorMessage
|
|
@@ -2663,7 +2399,7 @@ async function updateFullProjectViaAPI(tenantId, apiUrl, projectId, projectData)
|
|
|
2663
2399
|
throw new Error(errorMessage);
|
|
2664
2400
|
}
|
|
2665
2401
|
const result = await response.json();
|
|
2666
|
-
|
|
2402
|
+
logger7.info(
|
|
2667
2403
|
{
|
|
2668
2404
|
projectId
|
|
2669
2405
|
},
|
|
@@ -2672,7 +2408,7 @@ async function updateFullProjectViaAPI(tenantId, apiUrl, projectId, projectData)
|
|
|
2672
2408
|
return result.data;
|
|
2673
2409
|
}
|
|
2674
2410
|
async function getFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
2675
|
-
|
|
2411
|
+
logger7.info(
|
|
2676
2412
|
{
|
|
2677
2413
|
tenantId,
|
|
2678
2414
|
projectId,
|
|
@@ -2689,7 +2425,7 @@ async function getFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
|
2689
2425
|
});
|
|
2690
2426
|
if (!response.ok) {
|
|
2691
2427
|
if (response.status === 404) {
|
|
2692
|
-
|
|
2428
|
+
logger7.info(
|
|
2693
2429
|
{
|
|
2694
2430
|
projectId
|
|
2695
2431
|
},
|
|
@@ -2709,7 +2445,7 @@ async function getFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
|
2709
2445
|
errorMessage = errorText;
|
|
2710
2446
|
}
|
|
2711
2447
|
}
|
|
2712
|
-
|
|
2448
|
+
logger7.error(
|
|
2713
2449
|
{
|
|
2714
2450
|
status: response.status,
|
|
2715
2451
|
error: errorMessage
|
|
@@ -2719,7 +2455,7 @@ async function getFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
|
2719
2455
|
throw new Error(errorMessage);
|
|
2720
2456
|
}
|
|
2721
2457
|
const result = await response.json();
|
|
2722
|
-
|
|
2458
|
+
logger7.info(
|
|
2723
2459
|
{
|
|
2724
2460
|
projectId
|
|
2725
2461
|
},
|
|
@@ -2728,7 +2464,7 @@ async function getFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
|
2728
2464
|
return result.data;
|
|
2729
2465
|
}
|
|
2730
2466
|
async function deleteFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
2731
|
-
|
|
2467
|
+
logger7.info(
|
|
2732
2468
|
{
|
|
2733
2469
|
tenantId,
|
|
2734
2470
|
projectId,
|
|
@@ -2756,7 +2492,7 @@ async function deleteFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
|
2756
2492
|
errorMessage = errorText;
|
|
2757
2493
|
}
|
|
2758
2494
|
}
|
|
2759
|
-
|
|
2495
|
+
logger7.error(
|
|
2760
2496
|
{
|
|
2761
2497
|
status: response.status,
|
|
2762
2498
|
error: errorMessage
|
|
@@ -2765,7 +2501,7 @@ async function deleteFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
|
2765
2501
|
);
|
|
2766
2502
|
throw new Error(errorMessage);
|
|
2767
2503
|
}
|
|
2768
|
-
|
|
2504
|
+
logger7.info(
|
|
2769
2505
|
{
|
|
2770
2506
|
projectId
|
|
2771
2507
|
},
|
|
@@ -2774,7 +2510,7 @@ async function deleteFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
|
2774
2510
|
}
|
|
2775
2511
|
|
|
2776
2512
|
// src/project.ts
|
|
2777
|
-
var
|
|
2513
|
+
var logger8 = agentsCore.getLogger("project");
|
|
2778
2514
|
var Project = class {
|
|
2779
2515
|
constructor(config) {
|
|
2780
2516
|
__publicField(this, "__type", "project");
|
|
@@ -2803,7 +2539,7 @@ var Project = class {
|
|
|
2803
2539
|
graph.setConfig(this.tenantId, this.projectId, this.baseURL);
|
|
2804
2540
|
}
|
|
2805
2541
|
}
|
|
2806
|
-
|
|
2542
|
+
logger8.info(
|
|
2807
2543
|
{
|
|
2808
2544
|
projectId: this.projectId,
|
|
2809
2545
|
tenantId: this.tenantId,
|
|
@@ -2828,7 +2564,7 @@ var Project = class {
|
|
|
2828
2564
|
for (const graph of this.graphs) {
|
|
2829
2565
|
graph.setConfig(tenantId, this.projectId, apiUrl);
|
|
2830
2566
|
}
|
|
2831
|
-
|
|
2567
|
+
logger8.info(
|
|
2832
2568
|
{
|
|
2833
2569
|
projectId: this.projectId,
|
|
2834
2570
|
tenantId: this.tenantId,
|
|
@@ -2844,7 +2580,7 @@ var Project = class {
|
|
|
2844
2580
|
*/
|
|
2845
2581
|
setCredentials(credentials) {
|
|
2846
2582
|
this.credentialReferences = Object.values(credentials);
|
|
2847
|
-
|
|
2583
|
+
logger8.info(
|
|
2848
2584
|
{
|
|
2849
2585
|
projectId: this.projectId,
|
|
2850
2586
|
credentialCount: this.credentialReferences?.length || 0
|
|
@@ -2857,10 +2593,10 @@ var Project = class {
|
|
|
2857
2593
|
*/
|
|
2858
2594
|
async init() {
|
|
2859
2595
|
if (this.initialized) {
|
|
2860
|
-
|
|
2596
|
+
logger8.info({ projectId: this.projectId }, "Project already initialized");
|
|
2861
2597
|
return;
|
|
2862
2598
|
}
|
|
2863
|
-
|
|
2599
|
+
logger8.info(
|
|
2864
2600
|
{
|
|
2865
2601
|
projectId: this.projectId,
|
|
2866
2602
|
tenantId: this.tenantId,
|
|
@@ -2883,7 +2619,7 @@ var Project = class {
|
|
|
2883
2619
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2884
2620
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2885
2621
|
};
|
|
2886
|
-
|
|
2622
|
+
logger8.info(
|
|
2887
2623
|
{
|
|
2888
2624
|
projectId: this.projectId,
|
|
2889
2625
|
mode: "api-client",
|
|
@@ -2892,7 +2628,7 @@ var Project = class {
|
|
|
2892
2628
|
"Creating project metadata first"
|
|
2893
2629
|
);
|
|
2894
2630
|
await updateFullProjectViaAPI(this.tenantId, this.baseURL, this.projectId, projectMetadata);
|
|
2895
|
-
|
|
2631
|
+
logger8.info(
|
|
2896
2632
|
{
|
|
2897
2633
|
projectId: this.projectId
|
|
2898
2634
|
},
|
|
@@ -2901,7 +2637,7 @@ var Project = class {
|
|
|
2901
2637
|
const initPromises = this.graphs.map(async (graph) => {
|
|
2902
2638
|
try {
|
|
2903
2639
|
await graph.init();
|
|
2904
|
-
|
|
2640
|
+
logger8.debug(
|
|
2905
2641
|
{
|
|
2906
2642
|
projectId: this.projectId,
|
|
2907
2643
|
graphId: graph.getId()
|
|
@@ -2909,7 +2645,7 @@ var Project = class {
|
|
|
2909
2645
|
"Graph initialized in project"
|
|
2910
2646
|
);
|
|
2911
2647
|
} catch (error) {
|
|
2912
|
-
|
|
2648
|
+
logger8.error(
|
|
2913
2649
|
{
|
|
2914
2650
|
projectId: this.projectId,
|
|
2915
2651
|
graphId: graph.getId(),
|
|
@@ -2922,7 +2658,7 @@ var Project = class {
|
|
|
2922
2658
|
});
|
|
2923
2659
|
await Promise.all(initPromises);
|
|
2924
2660
|
const projectDefinition = await this.toFullProjectDefinition();
|
|
2925
|
-
|
|
2661
|
+
logger8.info(
|
|
2926
2662
|
{
|
|
2927
2663
|
projectId: this.projectId,
|
|
2928
2664
|
mode: "api-client",
|
|
@@ -2937,7 +2673,7 @@ var Project = class {
|
|
|
2937
2673
|
projectDefinition
|
|
2938
2674
|
);
|
|
2939
2675
|
this.initialized = true;
|
|
2940
|
-
|
|
2676
|
+
logger8.info(
|
|
2941
2677
|
{
|
|
2942
2678
|
projectId: this.projectId,
|
|
2943
2679
|
tenantId: this.tenantId,
|
|
@@ -2946,7 +2682,7 @@ var Project = class {
|
|
|
2946
2682
|
"Project initialized successfully using full project endpoint"
|
|
2947
2683
|
);
|
|
2948
2684
|
} catch (error) {
|
|
2949
|
-
|
|
2685
|
+
logger8.error(
|
|
2950
2686
|
{
|
|
2951
2687
|
projectId: this.projectId,
|
|
2952
2688
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3037,7 +2773,7 @@ var Project = class {
|
|
|
3037
2773
|
this.graphs.push(graph);
|
|
3038
2774
|
this.graphMap.set(graph.getId(), graph);
|
|
3039
2775
|
graph.setConfig(this.tenantId, this.projectId, this.baseURL);
|
|
3040
|
-
|
|
2776
|
+
logger8.info(
|
|
3041
2777
|
{
|
|
3042
2778
|
projectId: this.projectId,
|
|
3043
2779
|
graphId: graph.getId()
|
|
@@ -3053,7 +2789,7 @@ var Project = class {
|
|
|
3053
2789
|
if (graphToRemove) {
|
|
3054
2790
|
this.graphMap.delete(id);
|
|
3055
2791
|
this.graphs = this.graphs.filter((graph) => graph.getId() !== id);
|
|
3056
|
-
|
|
2792
|
+
logger8.info(
|
|
3057
2793
|
{
|
|
3058
2794
|
projectId: this.projectId,
|
|
3059
2795
|
graphId: id
|
|
@@ -3189,94 +2925,41 @@ var Project = class {
|
|
|
3189
2925
|
}
|
|
3190
2926
|
}
|
|
3191
2927
|
}
|
|
3192
|
-
for (const agent2 of graph.
|
|
3193
|
-
if (
|
|
2928
|
+
for (const agent2 of graph.getAgents()) {
|
|
2929
|
+
if (agent2.type === "external") {
|
|
3194
2930
|
continue;
|
|
3195
2931
|
}
|
|
3196
2932
|
const agentTools = agent2.getTools();
|
|
3197
|
-
for (const [
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
if (!toolsObject[toolId]) {
|
|
3210
|
-
let toolConfig;
|
|
3211
|
-
if (actualTool.config?.serverUrl) {
|
|
3212
|
-
toolConfig = {
|
|
3213
|
-
type: "mcp",
|
|
3214
|
-
mcp: {
|
|
3215
|
-
server: {
|
|
3216
|
-
url: actualTool.config.serverUrl
|
|
3217
|
-
}
|
|
3218
|
-
}
|
|
3219
|
-
};
|
|
3220
|
-
} else if (actualTool.config?.type === "mcp") {
|
|
3221
|
-
toolConfig = actualTool.config;
|
|
3222
|
-
} else {
|
|
3223
|
-
toolConfig = {
|
|
3224
|
-
type: "function",
|
|
3225
|
-
parameters: actualTool.parameters || {}
|
|
3226
|
-
};
|
|
3227
|
-
}
|
|
3228
|
-
const toolData = {
|
|
3229
|
-
id: toolId,
|
|
3230
|
-
name: actualTool.config?.name || actualTool.name || toolName,
|
|
3231
|
-
config: toolConfig,
|
|
3232
|
-
status: actualTool.getStatus?.() || actualTool.status || "unknown"
|
|
3233
|
-
};
|
|
3234
|
-
if (actualTool.config?.imageUrl) {
|
|
3235
|
-
toolData.imageUrl = actualTool.config.imageUrl;
|
|
3236
|
-
}
|
|
3237
|
-
if (actualTool.config?.headers) {
|
|
3238
|
-
toolData.headers = actualTool.config.headers;
|
|
3239
|
-
}
|
|
3240
|
-
if (actualTool.capabilities) {
|
|
3241
|
-
toolData.capabilities = actualTool.capabilities;
|
|
3242
|
-
}
|
|
3243
|
-
if (actualTool.lastHealthCheck) {
|
|
3244
|
-
toolData.lastHealthCheck = actualTool.lastHealthCheck;
|
|
3245
|
-
}
|
|
3246
|
-
if (actualTool.availableTools) {
|
|
3247
|
-
toolData.availableTools = actualTool.availableTools;
|
|
3248
|
-
}
|
|
3249
|
-
if (actualTool.lastError) {
|
|
3250
|
-
toolData.lastError = actualTool.lastError;
|
|
3251
|
-
}
|
|
3252
|
-
if (actualTool.lastToolsSync) {
|
|
3253
|
-
toolData.lastToolsSync = actualTool.lastToolsSync;
|
|
3254
|
-
}
|
|
3255
|
-
if (actualTool.getCredentialReferenceId?.()) {
|
|
3256
|
-
const credId = actualTool.getCredentialReferenceId();
|
|
3257
|
-
toolData.credentialReferenceId = credId;
|
|
3258
|
-
if (!credentialUsageMap[credId]) {
|
|
3259
|
-
credentialUsageMap[credId] = [];
|
|
3260
|
-
}
|
|
3261
|
-
credentialUsageMap[credId].push({
|
|
3262
|
-
type: "tool",
|
|
3263
|
-
id: toolId,
|
|
3264
|
-
graphId: graph.getId()
|
|
3265
|
-
});
|
|
3266
|
-
} else if (actualTool.config?.credential?.id) {
|
|
3267
|
-
const credId = actualTool.config.credential.id;
|
|
3268
|
-
toolData.credentialReferenceId = credId;
|
|
3269
|
-
if (!credentialUsageMap[credId]) {
|
|
3270
|
-
credentialUsageMap[credId] = [];
|
|
3271
|
-
}
|
|
3272
|
-
credentialUsageMap[credId].push({
|
|
3273
|
-
type: "tool",
|
|
3274
|
-
id: toolId,
|
|
3275
|
-
graphId: graph.getId()
|
|
3276
|
-
});
|
|
2933
|
+
for (const [, toolInstance] of Object.entries(agentTools)) {
|
|
2934
|
+
const actualTool = toolInstance;
|
|
2935
|
+
const toolId = actualTool.getId();
|
|
2936
|
+
if (!toolsObject[toolId]) {
|
|
2937
|
+
const toolConfig = {
|
|
2938
|
+
type: "mcp",
|
|
2939
|
+
mcp: {
|
|
2940
|
+
server: {
|
|
2941
|
+
url: actualTool.config.serverUrl
|
|
2942
|
+
},
|
|
2943
|
+
transport: actualTool.config.transport,
|
|
2944
|
+
activeTools: actualTool.config.activeTools
|
|
3277
2945
|
}
|
|
3278
|
-
|
|
2946
|
+
};
|
|
2947
|
+
const toolData = {
|
|
2948
|
+
id: toolId,
|
|
2949
|
+
name: actualTool.getName(),
|
|
2950
|
+
config: toolConfig
|
|
2951
|
+
};
|
|
2952
|
+
if (actualTool.config?.imageUrl) {
|
|
2953
|
+
toolData.imageUrl = actualTool.config.imageUrl;
|
|
2954
|
+
}
|
|
2955
|
+
if (actualTool.config?.headers) {
|
|
2956
|
+
toolData.headers = actualTool.config.headers;
|
|
3279
2957
|
}
|
|
2958
|
+
const credentialId = actualTool.getCredentialReferenceId();
|
|
2959
|
+
if (credentialId) {
|
|
2960
|
+
toolData.credentialReferenceId = credentialId;
|
|
2961
|
+
}
|
|
2962
|
+
toolsObject[toolId] = toolData;
|
|
3280
2963
|
}
|
|
3281
2964
|
}
|
|
3282
2965
|
const agentDataComponents = agent2.getDataComponents?.();
|
|
@@ -3498,6 +3181,168 @@ function createEnvironmentSettings(environments) {
|
|
|
3498
3181
|
function registerEnvironmentSettings(config) {
|
|
3499
3182
|
return config;
|
|
3500
3183
|
}
|
|
3184
|
+
var logger9 = agentsCore.getLogger("external-agent-builder");
|
|
3185
|
+
var ExternalAgent = class {
|
|
3186
|
+
constructor(config) {
|
|
3187
|
+
__publicField(this, "config");
|
|
3188
|
+
__publicField(this, "type", "external");
|
|
3189
|
+
__publicField(this, "initialized", false);
|
|
3190
|
+
__publicField(this, "tenantId");
|
|
3191
|
+
__publicField(this, "baseURL");
|
|
3192
|
+
this.config = { ...config, type: "external" };
|
|
3193
|
+
this.tenantId = "default";
|
|
3194
|
+
this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
|
|
3195
|
+
logger9.debug(
|
|
3196
|
+
{
|
|
3197
|
+
externalAgentName: this.config.name,
|
|
3198
|
+
baseUrl: this.config.baseUrl,
|
|
3199
|
+
tenantId: this.tenantId
|
|
3200
|
+
},
|
|
3201
|
+
"External Agent constructor initialized"
|
|
3202
|
+
);
|
|
3203
|
+
}
|
|
3204
|
+
/**
|
|
3205
|
+
* Initialize the external agent by upserting it in the database
|
|
3206
|
+
*/
|
|
3207
|
+
async init() {
|
|
3208
|
+
if (this.initialized) return;
|
|
3209
|
+
try {
|
|
3210
|
+
await this.upsertExternalAgent();
|
|
3211
|
+
logger9.info(
|
|
3212
|
+
{
|
|
3213
|
+
externalAgentId: this.getId()
|
|
3214
|
+
},
|
|
3215
|
+
"External agent initialized successfully"
|
|
3216
|
+
);
|
|
3217
|
+
this.initialized = true;
|
|
3218
|
+
} catch (error) {
|
|
3219
|
+
logger9.error(
|
|
3220
|
+
{
|
|
3221
|
+
externalAgentId: this.getId(),
|
|
3222
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
3223
|
+
},
|
|
3224
|
+
"Failed to initialize external agent"
|
|
3225
|
+
);
|
|
3226
|
+
throw error;
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
// Set context (tenantId) from external source (graph, CLI, etc)
|
|
3230
|
+
setContext(tenantId) {
|
|
3231
|
+
this.tenantId = tenantId;
|
|
3232
|
+
}
|
|
3233
|
+
// Compute ID from name using a simple slug transformation
|
|
3234
|
+
getId() {
|
|
3235
|
+
return this.config.id;
|
|
3236
|
+
}
|
|
3237
|
+
// Private method to upsert external agent (create or update)
|
|
3238
|
+
async upsertExternalAgent() {
|
|
3239
|
+
const externalAgentData = {
|
|
3240
|
+
id: this.getId(),
|
|
3241
|
+
name: this.config.name,
|
|
3242
|
+
description: this.config.description,
|
|
3243
|
+
baseUrl: this.config.baseUrl,
|
|
3244
|
+
credentialReferenceId: this.config.credentialReference?.id || void 0,
|
|
3245
|
+
headers: this.config.headers || void 0
|
|
3246
|
+
};
|
|
3247
|
+
const updateResponse = await fetch(
|
|
3248
|
+
`${this.baseURL}/tenants/${this.tenantId}/external-agents/${this.getId()}`,
|
|
3249
|
+
{
|
|
3250
|
+
method: "PUT",
|
|
3251
|
+
headers: {
|
|
3252
|
+
"Content-Type": "application/json"
|
|
3253
|
+
},
|
|
3254
|
+
body: JSON.stringify(externalAgentData)
|
|
3255
|
+
}
|
|
3256
|
+
);
|
|
3257
|
+
if (updateResponse.ok) {
|
|
3258
|
+
logger9.info(
|
|
3259
|
+
{
|
|
3260
|
+
externalAgentId: this.getId()
|
|
3261
|
+
},
|
|
3262
|
+
"External agent updated successfully"
|
|
3263
|
+
);
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
3266
|
+
if (updateResponse.status === 404) {
|
|
3267
|
+
logger9.info(
|
|
3268
|
+
{
|
|
3269
|
+
externalAgentId: this.getId()
|
|
3270
|
+
},
|
|
3271
|
+
"External agent not found, creating new external agent"
|
|
3272
|
+
);
|
|
3273
|
+
const createResponse = await fetch(
|
|
3274
|
+
`${this.baseURL}/tenants/${this.tenantId}/external-agents`,
|
|
3275
|
+
{
|
|
3276
|
+
method: "POST",
|
|
3277
|
+
headers: {
|
|
3278
|
+
"Content-Type": "application/json"
|
|
3279
|
+
},
|
|
3280
|
+
body: JSON.stringify(externalAgentData)
|
|
3281
|
+
}
|
|
3282
|
+
);
|
|
3283
|
+
if (!createResponse.ok) {
|
|
3284
|
+
const errorText2 = await createResponse.text().catch(() => "Unknown error");
|
|
3285
|
+
throw new Error(
|
|
3286
|
+
`Failed to create external agent: ${createResponse.status} ${createResponse.statusText} - ${errorText2}`
|
|
3287
|
+
);
|
|
3288
|
+
}
|
|
3289
|
+
logger9.info(
|
|
3290
|
+
{
|
|
3291
|
+
externalAgentId: this.getId()
|
|
3292
|
+
},
|
|
3293
|
+
"External agent created successfully"
|
|
3294
|
+
);
|
|
3295
|
+
return;
|
|
3296
|
+
}
|
|
3297
|
+
const errorText = await updateResponse.text().catch(() => "Unknown error");
|
|
3298
|
+
throw new Error(
|
|
3299
|
+
`Failed to update external agent: ${updateResponse.status} ${updateResponse.statusText} - ${errorText}`
|
|
3300
|
+
);
|
|
3301
|
+
}
|
|
3302
|
+
/**
|
|
3303
|
+
* Get the external agent configuration
|
|
3304
|
+
*/
|
|
3305
|
+
getConfig() {
|
|
3306
|
+
return { ...this.config };
|
|
3307
|
+
}
|
|
3308
|
+
/**
|
|
3309
|
+
* Get the external agent name
|
|
3310
|
+
*/
|
|
3311
|
+
getName() {
|
|
3312
|
+
return this.config.name;
|
|
3313
|
+
}
|
|
3314
|
+
/**
|
|
3315
|
+
* Get the external agent base URL
|
|
3316
|
+
*/
|
|
3317
|
+
getBaseUrl() {
|
|
3318
|
+
return this.config.baseUrl;
|
|
3319
|
+
}
|
|
3320
|
+
/**
|
|
3321
|
+
* Get the tenant ID
|
|
3322
|
+
*/
|
|
3323
|
+
getTenantId() {
|
|
3324
|
+
return this.tenantId;
|
|
3325
|
+
}
|
|
3326
|
+
getDescription() {
|
|
3327
|
+
return this.config.description || "";
|
|
3328
|
+
}
|
|
3329
|
+
getCredentialReferenceId() {
|
|
3330
|
+
return this.config.credentialReference?.id || void 0;
|
|
3331
|
+
}
|
|
3332
|
+
getHeaders() {
|
|
3333
|
+
return this.config.headers;
|
|
3334
|
+
}
|
|
3335
|
+
};
|
|
3336
|
+
function externalAgent(config) {
|
|
3337
|
+
return new ExternalAgent(config);
|
|
3338
|
+
}
|
|
3339
|
+
function externalAgents(configs) {
|
|
3340
|
+
const builders = {};
|
|
3341
|
+
for (const [name, config] of Object.entries(configs)) {
|
|
3342
|
+
builders[name] = externalAgent(config);
|
|
3343
|
+
}
|
|
3344
|
+
return builders;
|
|
3345
|
+
}
|
|
3501
3346
|
zod.z.object({
|
|
3502
3347
|
model: zod.z.string().optional(),
|
|
3503
3348
|
providerOptions: zod.z.record(zod.z.string(), zod.z.record(zod.z.string(), zod.z.unknown())).optional()
|