@inkeep/agents-sdk 0.6.4 → 0.6.6

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