@inkeep/agents-sdk 0.3.0 → 0.6.0

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 CHANGED
@@ -6,6 +6,13 @@ var zod = require('zod');
6
6
  var __defProp = Object.defineProperty;
7
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
8
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
+
10
+ // src/utils/generateIdFromName.ts
11
+ function generateIdFromName(name) {
12
+ return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
13
+ }
14
+
15
+ // src/artifact-component.ts
9
16
  var logger = agentsCore.getLogger("artifactComponent");
10
17
  var ArtifactComponent = class {
11
18
  constructor(config) {
@@ -15,16 +22,14 @@ var ArtifactComponent = class {
15
22
  __publicField(this, "projectId");
16
23
  __publicField(this, "initialized", false);
17
24
  __publicField(this, "id");
18
- this.id = agentsCore.generateIdFromName(config.name);
25
+ this.id = config.id || generateIdFromName(config.name);
19
26
  this.config = {
20
27
  ...config,
21
- id: this.id,
22
- tenantId: config.tenantId || "default",
23
- projectId: config.projectId || "default"
28
+ id: this.id
24
29
  };
25
30
  this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
26
- this.tenantId = this.config.tenantId;
27
- this.projectId = this.config.projectId;
31
+ this.tenantId = "default";
32
+ this.projectId = "default";
28
33
  logger.info(
29
34
  {
30
35
  artifactComponentId: this.getId(),
@@ -33,6 +38,11 @@ var ArtifactComponent = class {
33
38
  "ArtifactComponent constructor initialized"
34
39
  );
35
40
  }
41
+ // Set context (tenantId and projectId) from external source (agent, graph, CLI, etc)
42
+ setContext(tenantId, projectId) {
43
+ this.tenantId = tenantId;
44
+ this.projectId = projectId;
45
+ }
36
46
  // Compute ID from name using same slug transformation as agents
37
47
  getId() {
38
48
  return this.id;
@@ -83,7 +93,7 @@ var ArtifactComponent = class {
83
93
  };
84
94
  logger.info({ artifactComponentData }, "artifactComponentData for create/update");
85
95
  const updateResponse = await fetch(
86
- `${this.baseURL}/tenants/${this.tenantId}/artifact-components/${this.getId()}`,
96
+ `${this.baseURL}/tenants/${this.tenantId}/projects/${this.projectId}/artifact-components/${this.getId()}`,
87
97
  {
88
98
  method: "PUT",
89
99
  headers: {
@@ -116,7 +126,7 @@ var ArtifactComponent = class {
116
126
  "ArtifactComponent not found, creating new artifact component"
117
127
  );
118
128
  const createResponse = await fetch(
119
- `${this.baseURL}/tenants/${this.tenantId}/artifact-components`,
129
+ `${this.baseURL}/tenants/${this.tenantId}/projects/${this.projectId}/artifact-components`,
120
130
  {
121
131
  method: "POST",
122
132
  headers: {
@@ -154,16 +164,14 @@ var DataComponent = class {
154
164
  __publicField(this, "projectId");
155
165
  __publicField(this, "initialized", false);
156
166
  __publicField(this, "id");
157
- this.id = agentsCore.generateIdFromName(config.name);
167
+ this.id = config.id || generateIdFromName(config.name);
158
168
  this.config = {
159
169
  ...config,
160
- id: this.id,
161
- tenantId: config.tenantId || "default",
162
- projectId: config.projectId || "default"
170
+ id: this.id
163
171
  };
164
172
  this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
165
- this.tenantId = this.config.tenantId;
166
- this.projectId = this.config.projectId;
173
+ this.tenantId = "default";
174
+ this.projectId = "default";
167
175
  logger2.info(
168
176
  {
169
177
  dataComponentId: this.getId(),
@@ -172,6 +180,11 @@ var DataComponent = class {
172
180
  "DataComponent constructor initialized"
173
181
  );
174
182
  }
183
+ // Set context (tenantId and projectId) from external source (agent, graph, CLI, etc)
184
+ setContext(tenantId, projectId) {
185
+ this.tenantId = tenantId;
186
+ this.projectId = projectId;
187
+ }
175
188
  // Compute ID from name using same slug transformation as agents
176
189
  getId() {
177
190
  return this.id;
@@ -218,7 +231,7 @@ var DataComponent = class {
218
231
  };
219
232
  logger2.info({ dataComponentData }, "dataComponentData for create/update");
220
233
  const updateResponse = await fetch(
221
- `${this.baseURL}/tenants/${this.tenantId}/data-components/${this.getId()}`,
234
+ `${this.baseURL}/tenants/${this.tenantId}/projects/${this.projectId}/data-components/${this.getId()}`,
222
235
  {
223
236
  method: "PUT",
224
237
  headers: {
@@ -251,7 +264,7 @@ var DataComponent = class {
251
264
  "DataComponent not found, creating new data component"
252
265
  );
253
266
  const createResponse = await fetch(
254
- `${this.baseURL}/tenants/${this.tenantId}/data-components`,
267
+ `${this.baseURL}/tenants/${this.tenantId}/projects/${this.projectId}/data-components`,
255
268
  {
256
269
  method: "POST",
257
270
  headers: {
@@ -290,8 +303,8 @@ var Tool = class {
290
303
  __publicField(this, "projectId");
291
304
  this.config = config;
292
305
  this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
293
- this.tenantId = config.tenantId || "default";
294
- this.projectId = config.projectId || "default";
306
+ this.tenantId = "default";
307
+ this.projectId = "default";
295
308
  logger3.info(
296
309
  {
297
310
  Id: this.getId(),
@@ -300,6 +313,11 @@ var Tool = class {
300
313
  "Tool constructor initialized"
301
314
  );
302
315
  }
316
+ // Set context (tenantId and projectId) from external source (agent, graph, CLI, etc)
317
+ setContext(tenantId, projectId) {
318
+ this.tenantId = tenantId;
319
+ this.projectId = projectId;
320
+ }
303
321
  // Compute ID from name using same slug transformation as agents
304
322
  getId() {
305
323
  return this.config.id;
@@ -437,8 +455,8 @@ var Agent = class {
437
455
  __publicField(this, "initialized", false);
438
456
  this.config = { ...config, type: "internal" };
439
457
  this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
440
- this.tenantId = config.tenantId || "default";
441
- this.projectId = config.projectId || "default";
458
+ this.tenantId = "default";
459
+ this.projectId = "default";
442
460
  logger4.info(
443
461
  {
444
462
  tenantId: this.tenantId,
@@ -448,6 +466,11 @@ var Agent = class {
448
466
  "Agent constructor initialized"
449
467
  );
450
468
  }
469
+ // Set context (tenantId and projectId) from external source (graph, CLI, etc)
470
+ setContext(tenantId, projectId) {
471
+ this.tenantId = tenantId;
472
+ this.projectId = projectId;
473
+ }
451
474
  // Return the configured ID
452
475
  getId() {
453
476
  return this.config.id;
@@ -507,10 +530,33 @@ var Agent = class {
507
530
  return typeof this.config.canDelegateTo === "function" ? this.config.canDelegateTo() : [];
508
531
  }
509
532
  getDataComponents() {
510
- return resolveGetter(this.config.dataComponents) || [];
533
+ const components = resolveGetter(this.config.dataComponents) || [];
534
+ return components.map((comp) => {
535
+ if (comp && typeof comp.getId === "function") {
536
+ return {
537
+ id: comp.getId(),
538
+ name: comp.getName(),
539
+ description: comp.getDescription(),
540
+ props: comp.getProps()
541
+ };
542
+ }
543
+ return comp;
544
+ });
511
545
  }
512
546
  getArtifactComponents() {
513
- return resolveGetter(this.config.artifactComponents) || [];
547
+ const components = resolveGetter(this.config.artifactComponents) || [];
548
+ return components.map((comp) => {
549
+ if (comp && typeof comp.getId === "function") {
550
+ return {
551
+ id: comp.getId(),
552
+ name: comp.getName(),
553
+ description: comp.getDescription(),
554
+ summaryProps: comp.getSummaryProps?.() || comp.summaryProps,
555
+ fullProps: comp.getFullProps?.() || comp.fullProps
556
+ };
557
+ }
558
+ return comp;
559
+ });
514
560
  }
515
561
  // adjust
516
562
  addTool(_name, tool) {
@@ -659,7 +705,13 @@ var Agent = class {
659
705
  const components = resolveGetter(this.config.dataComponents);
660
706
  if (components) {
661
707
  for (const dataComponent2 of components) {
662
- await this.createDataComponent(dataComponent2);
708
+ const plainComponent = dataComponent2 && typeof dataComponent2.getId === "function" ? {
709
+ id: dataComponent2.getId(),
710
+ name: dataComponent2.getName(),
711
+ description: dataComponent2.getDescription(),
712
+ props: dataComponent2.getProps()
713
+ } : dataComponent2;
714
+ await this.createDataComponent(plainComponent);
663
715
  }
664
716
  }
665
717
  }
@@ -671,7 +723,14 @@ var Agent = class {
671
723
  const components = resolveGetter(this.config.artifactComponents);
672
724
  if (components) {
673
725
  for (const artifactComponent2 of components) {
674
- await this.createArtifactComponent(artifactComponent2);
726
+ const plainComponent = artifactComponent2 && typeof artifactComponent2.getId === "function" ? {
727
+ id: artifactComponent2.getId(),
728
+ name: artifactComponent2.getName(),
729
+ description: artifactComponent2.getDescription(),
730
+ summaryProps: artifactComponent2.getSummaryProps?.() || artifactComponent2.summaryProps,
731
+ fullProps: artifactComponent2.getFullProps?.() || artifactComponent2.fullProps
732
+ } : artifactComponent2;
733
+ await this.createArtifactComponent(plainComponent);
675
734
  }
676
735
  }
677
736
  }
@@ -680,8 +739,6 @@ var Agent = class {
680
739
  const existingComponents = [];
681
740
  const dbDataComponents = existingComponents.map((component) => ({
682
741
  id: component.id,
683
- tenantId: component.tenantId || this.tenantId,
684
- projectId: component.projectId || this.projectId,
685
742
  name: component.name,
686
743
  description: component.description,
687
744
  props: component.props,
@@ -689,9 +746,24 @@ var Agent = class {
689
746
  updatedAt: component.updatedAt
690
747
  }));
691
748
  const configComponents = resolveGetter(this.config.dataComponents) || [];
692
- const allComponents = [...dbDataComponents, ...configComponents];
749
+ const normalizedConfigComponents = configComponents.map((comp) => {
750
+ if (comp && typeof comp.getId === "function") {
751
+ return {
752
+ id: comp.getId(),
753
+ name: comp.getName(),
754
+ description: comp.getDescription(),
755
+ props: comp.getProps()
756
+ };
757
+ }
758
+ return comp;
759
+ });
760
+ const allComponents = [...dbDataComponents, ...normalizedConfigComponents];
693
761
  const uniqueComponents = allComponents.reduce((acc, component) => {
694
- const existingIndex = acc.findIndex((c) => c.id === component.id);
762
+ const componentId = typeof component.getId === "function" ? component.getId() : component.id;
763
+ const existingIndex = acc.findIndex((c) => {
764
+ const cId = typeof c.getId === "function" ? c.getId() : c.id;
765
+ return cId === componentId;
766
+ });
695
767
  if (existingIndex >= 0) {
696
768
  acc[existingIndex] = component;
697
769
  } else {
@@ -699,7 +771,7 @@ var Agent = class {
699
771
  }
700
772
  return acc;
701
773
  }, []);
702
- this.config.dataComponents = uniqueComponents;
774
+ this.config.dataComponents = () => uniqueComponents;
703
775
  logger4.info(
704
776
  {
705
777
  agentId: this.getId(),
@@ -724,8 +796,6 @@ var Agent = class {
724
796
  const existingComponents = [];
725
797
  const dbArtifactComponents = existingComponents.map((component) => ({
726
798
  id: component.id,
727
- tenantId: component.tenantId || this.tenantId,
728
- projectId: component.projectId || this.projectId,
729
799
  name: component.name,
730
800
  description: component.description,
731
801
  summaryProps: component.summaryProps,
@@ -734,9 +804,25 @@ var Agent = class {
734
804
  updatedAt: component.updatedAt
735
805
  }));
736
806
  const configComponents = resolveGetter(this.config.artifactComponents) || [];
737
- const allComponents = [...dbArtifactComponents, ...configComponents];
807
+ const normalizedConfigComponents = configComponents.map((comp) => {
808
+ if (comp && typeof comp.getId === "function") {
809
+ return {
810
+ id: comp.getId(),
811
+ name: comp.getName(),
812
+ description: comp.getDescription(),
813
+ summaryProps: comp.getSummaryProps?.() || comp.summaryProps,
814
+ fullProps: comp.getFullProps?.() || comp.fullProps
815
+ };
816
+ }
817
+ return comp;
818
+ });
819
+ const allComponents = [...dbArtifactComponents, ...normalizedConfigComponents];
738
820
  const uniqueComponents = allComponents.reduce((acc, component) => {
739
- const existingIndex = acc.findIndex((c) => c.id === component.id);
821
+ const componentId = typeof component.getId === "function" ? component.getId() : component.id;
822
+ const existingIndex = acc.findIndex((c) => {
823
+ const cId = typeof c.getId === "function" ? c.getId() : c.id;
824
+ return cId === componentId;
825
+ });
740
826
  if (existingIndex >= 0) {
741
827
  acc[existingIndex] = component;
742
828
  } else {
@@ -744,7 +830,7 @@ var Agent = class {
744
830
  }
745
831
  return acc;
746
832
  }, []);
747
- this.config.artifactComponents = uniqueComponents;
833
+ this.config.artifactComponents = () => uniqueComponents;
748
834
  logger4.info(
749
835
  {
750
836
  agentId: this.getId(),
@@ -782,20 +868,22 @@ var Agent = class {
782
868
  const mcpConfig = toolConfig;
783
869
  tool = mcpConfig.server;
784
870
  selectedTools = mcpConfig.selectedTools;
871
+ tool.setContext(this.tenantId, this.projectId);
785
872
  await tool.init();
786
873
  } else if (toolConfig instanceof Tool) {
787
874
  tool = toolConfig;
875
+ tool.setContext(this.tenantId, this.projectId);
788
876
  await tool.init();
789
877
  } else {
790
878
  tool = new Tool({
791
879
  id: toolId,
792
- tenantId: this.tenantId,
793
880
  name: toolConfig.name || toolId,
794
881
  description: toolConfig.description || `MCP tool: ${toolId}`,
795
882
  serverUrl: toolConfig.config?.serverUrl || toolConfig.serverUrl || "http://localhost:3000",
796
883
  activeTools: toolConfig.config?.mcp?.activeTools,
797
884
  credential: toolConfig.credential
798
885
  });
886
+ tool.setContext(this.tenantId, this.projectId);
799
887
  await tool.init();
800
888
  }
801
889
  await this.createAgentToolRelation(tool.getId(), selectedTools);
@@ -821,12 +909,12 @@ var Agent = class {
821
909
  async createDataComponent(dataComponent2) {
822
910
  try {
823
911
  const dc = new DataComponent({
824
- tenantId: this.tenantId,
825
- projectId: this.projectId,
912
+ id: dataComponent2.id,
826
913
  name: dataComponent2.name,
827
914
  description: dataComponent2.description,
828
915
  props: dataComponent2.props
829
916
  });
917
+ dc.setContext(this.tenantId, this.projectId);
830
918
  await dc.init();
831
919
  await this.createAgentDataComponentRelation(dc.getId());
832
920
  logger4.info(
@@ -851,13 +939,13 @@ var Agent = class {
851
939
  async createArtifactComponent(artifactComponent2) {
852
940
  try {
853
941
  const ac = new ArtifactComponent({
854
- tenantId: this.tenantId,
855
- projectId: this.projectId,
942
+ id: artifactComponent2.id,
856
943
  name: artifactComponent2.name,
857
944
  description: artifactComponent2.description,
858
945
  summaryProps: artifactComponent2.summaryProps,
859
946
  fullProps: artifactComponent2.fullProps
860
947
  });
948
+ ac.setContext(this.tenantId, this.projectId);
861
949
  await ac.init();
862
950
  await this.createAgentArtifactComponentRelation(ac.getId());
863
951
  logger4.info(
@@ -975,13 +1063,13 @@ var ExternalAgent = class {
975
1063
  __publicField(this, "tenantId");
976
1064
  __publicField(this, "baseURL");
977
1065
  this.config = { ...config, type: "external" };
978
- this.tenantId = config.tenantId || "default";
1066
+ this.tenantId = "default";
979
1067
  this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
980
1068
  logger5.debug(
981
1069
  {
982
1070
  externalAgentName: this.config.name,
983
1071
  baseUrl: this.config.baseUrl,
984
- tenantId: this.config.tenantId
1072
+ tenantId: this.tenantId
985
1073
  },
986
1074
  "External Agent constructor initialized"
987
1075
  );
@@ -1011,6 +1099,10 @@ var ExternalAgent = class {
1011
1099
  throw error;
1012
1100
  }
1013
1101
  }
1102
+ // Set context (tenantId) from external source (graph, CLI, etc)
1103
+ setContext(tenantId) {
1104
+ this.tenantId = tenantId;
1105
+ }
1014
1106
  // Compute ID from name using a simple slug transformation
1015
1107
  getId() {
1016
1108
  return this.config.id;
@@ -1204,7 +1296,7 @@ var AgentGraph = class {
1204
1296
  __publicField(this, "stopWhen");
1205
1297
  __publicField(this, "dbClient");
1206
1298
  this.defaultAgent = config.defaultAgent;
1207
- this.tenantId = config.tenantId || "default";
1299
+ this.tenantId = "default";
1208
1300
  this.projectId = "default";
1209
1301
  this.graphId = config.id;
1210
1302
  this.graphName = config.name || this.graphId;
@@ -1255,14 +1347,14 @@ var AgentGraph = class {
1255
1347
  for (const agent2 of this.agents) {
1256
1348
  if (this.isInternalAgent(agent2)) {
1257
1349
  const internalAgent = agent2;
1258
- if (!internalAgent.config.tenantId) {
1259
- internalAgent.config.tenantId = tenantId;
1350
+ if (internalAgent.setContext) {
1351
+ internalAgent.setContext(tenantId, projectId);
1260
1352
  }
1261
1353
  const tools = internalAgent.getTools();
1262
1354
  for (const [_, toolInstance] of Object.entries(tools)) {
1263
- if (toolInstance && typeof toolInstance === "object" && toolInstance.config) {
1264
- if (!toolInstance.config.tenantId) {
1265
- toolInstance.config.tenantId = tenantId;
1355
+ if (toolInstance && typeof toolInstance === "object") {
1356
+ if ("setContext" in toolInstance && typeof toolInstance.setContext === "function") {
1357
+ toolInstance.setContext(tenantId, projectId);
1266
1358
  }
1267
1359
  if ("baseURL" in toolInstance && !toolInstance.baseURL) {
1268
1360
  toolInstance.baseURL = apiUrl;
@@ -1271,8 +1363,8 @@ var AgentGraph = class {
1271
1363
  }
1272
1364
  }
1273
1365
  }
1274
- if (this.contextConfig && !this.contextConfig.tenantId) {
1275
- this.contextConfig.tenantId = tenantId;
1366
+ if (this.contextConfig?.setContext) {
1367
+ this.contextConfig.setContext(tenantId, projectId);
1276
1368
  }
1277
1369
  logger7.info(
1278
1370
  {
@@ -1327,6 +1419,10 @@ var AgentGraph = class {
1327
1419
  artifactComponents.push(artifactComponentId);
1328
1420
  }
1329
1421
  }
1422
+ const canUse = tools.map((toolId) => ({
1423
+ toolId,
1424
+ toolSelection: selectedToolsMapping[toolId] || null
1425
+ }));
1330
1426
  agentsObject[internalAgent.getId()] = {
1331
1427
  id: internalAgent.getId(),
1332
1428
  name: internalAgent.getName(),
@@ -1335,8 +1431,8 @@ var AgentGraph = class {
1335
1431
  models: internalAgent.config.models,
1336
1432
  canTransferTo: transfers.map((h) => h.getId()),
1337
1433
  canDelegateTo: delegates.map((d) => d.getId()),
1338
- tools,
1339
- selectedTools: Object.keys(selectedToolsMapping).length > 0 ? selectedToolsMapping : void 0,
1434
+ canUse,
1435
+ // Always include for internal agents (required by API)
1340
1436
  dataComponents: dataComponents.length > 0 ? dataComponents : void 0,
1341
1437
  artifactComponents: artifactComponents.length > 0 ? artifactComponents : void 0,
1342
1438
  type: "internal"
@@ -1350,8 +1446,6 @@ var AgentGraph = class {
1350
1446
  baseUrl: externalAgent2.getBaseUrl(),
1351
1447
  credentialReferenceId: externalAgent2.getCredentialReferenceId(),
1352
1448
  headers: externalAgent2.getHeaders(),
1353
- tools: [],
1354
- // External agents don't have tools in this context
1355
1449
  type: "external"
1356
1450
  };
1357
1451
  }
@@ -2345,7 +2439,6 @@ var AgentGraph = class {
2345
2439
  throw error;
2346
2440
  }
2347
2441
  }
2348
- // enableComponentMode removed – feature deprecated
2349
2442
  async createExternalAgentRelation(sourceAgent, externalAgent2, relationType) {
2350
2443
  try {
2351
2444
  const response = await fetch(
@@ -2470,13 +2563,24 @@ async function createFullProjectViaAPI(tenantId, apiUrl, projectData) {
2470
2563
  "Creating full project via API"
2471
2564
  );
2472
2565
  const url = `${apiUrl}/tenants/${tenantId}/project-full`;
2473
- const response = await fetch(url, {
2474
- method: "POST",
2475
- headers: {
2476
- "Content-Type": "application/json"
2477
- },
2478
- body: JSON.stringify(projectData)
2479
- });
2566
+ let response;
2567
+ try {
2568
+ response = await fetch(url, {
2569
+ method: "POST",
2570
+ headers: {
2571
+ "Content-Type": "application/json"
2572
+ },
2573
+ body: JSON.stringify(projectData)
2574
+ });
2575
+ } catch (fetchError) {
2576
+ logger8.error({
2577
+ error: fetchError instanceof Error ? fetchError.message : "Unknown fetch error",
2578
+ url,
2579
+ tenantId,
2580
+ projectId: projectData.id
2581
+ }, "Fetch request failed");
2582
+ throw fetchError;
2583
+ }
2480
2584
  if (!response.ok) {
2481
2585
  const errorText = await response.text();
2482
2586
  let errorMessage = `Failed to create project: ${response.status} ${response.statusText}`;
@@ -2518,13 +2622,24 @@ async function updateFullProjectViaAPI(tenantId, apiUrl, projectId, projectData)
2518
2622
  "Updating full project via API"
2519
2623
  );
2520
2624
  const url = `${apiUrl}/tenants/${tenantId}/project-full/${projectId}`;
2521
- const response = await fetch(url, {
2522
- method: "PUT",
2523
- headers: {
2524
- "Content-Type": "application/json"
2525
- },
2526
- body: JSON.stringify(projectData)
2527
- });
2625
+ let response;
2626
+ try {
2627
+ response = await fetch(url, {
2628
+ method: "PUT",
2629
+ headers: {
2630
+ "Content-Type": "application/json"
2631
+ },
2632
+ body: JSON.stringify(projectData)
2633
+ });
2634
+ } catch (fetchError) {
2635
+ logger8.error({
2636
+ error: fetchError instanceof Error ? fetchError.message : "Unknown fetch error",
2637
+ url,
2638
+ tenantId,
2639
+ projectId
2640
+ }, "Fetch request failed");
2641
+ throw fetchError;
2642
+ }
2528
2643
  if (!response.ok) {
2529
2644
  const errorText = await response.text();
2530
2645
  let errorMessage = `Failed to update project: ${response.status} ${response.statusText}`;
@@ -2677,7 +2792,7 @@ var Project = class {
2677
2792
  this.projectId = config.id;
2678
2793
  this.projectName = config.name;
2679
2794
  this.projectDescription = config.description;
2680
- this.tenantId = config.tenantId || "default";
2795
+ this.tenantId = process.env.INKEEP_TENANT_ID || "default";
2681
2796
  this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
2682
2797
  this.models = config.models;
2683
2798
  this.stopWhen = config.stopWhen;
@@ -2889,6 +3004,20 @@ var Project = class {
2889
3004
  setStopWhen(stopWhen) {
2890
3005
  this.stopWhen = stopWhen;
2891
3006
  }
3007
+ /**
3008
+ * Get credential tracking information
3009
+ */
3010
+ async getCredentialTracking() {
3011
+ const fullDef = await this.toFullProjectDefinition();
3012
+ const credentials = fullDef.credentialReferences || {};
3013
+ const usage = {};
3014
+ for (const [credId, credData] of Object.entries(credentials)) {
3015
+ if (credData.usedBy) {
3016
+ usage[credId] = credData.usedBy;
3017
+ }
3018
+ }
3019
+ return { credentials, usage };
3020
+ }
2892
3021
  /**
2893
3022
  * Get all graphs in the project
2894
3023
  */
@@ -2984,9 +3113,82 @@ var Project = class {
2984
3113
  const toolsObject = {};
2985
3114
  const dataComponentsObject = {};
2986
3115
  const artifactComponentsObject = {};
3116
+ const credentialReferencesObject = {};
3117
+ const credentialUsageMap = {};
2987
3118
  for (const graph of this.graphs) {
2988
3119
  const graphDefinition = await graph.toFullGraphDefinition();
2989
3120
  graphsObject[graph.getId()] = graphDefinition;
3121
+ const graphCredentials = graph.credentials;
3122
+ if (graphCredentials && Array.isArray(graphCredentials)) {
3123
+ for (const credential2 of graphCredentials) {
3124
+ if (credential2?.__type === "credential-ref") {
3125
+ continue;
3126
+ }
3127
+ if (credential2?.id) {
3128
+ if (!credentialReferencesObject[credential2.id]) {
3129
+ credentialReferencesObject[credential2.id] = {
3130
+ id: credential2.id,
3131
+ type: credential2.type,
3132
+ credentialStoreId: credential2.credentialStoreId,
3133
+ retrievalParams: credential2.retrievalParams
3134
+ };
3135
+ credentialUsageMap[credential2.id] = [];
3136
+ }
3137
+ credentialUsageMap[credential2.id].push({
3138
+ type: "graph",
3139
+ id: graph.getId()
3140
+ });
3141
+ }
3142
+ }
3143
+ }
3144
+ const contextConfig = graph.contextConfig;
3145
+ if (contextConfig) {
3146
+ const contextVariables = contextConfig.getContextVariables?.() || contextConfig.contextVariables;
3147
+ if (contextVariables) {
3148
+ for (const [key, variable] of Object.entries(contextVariables)) {
3149
+ if (variable?.credential) {
3150
+ const credential2 = variable.credential;
3151
+ let credId;
3152
+ if (credential2.__type === "credential-ref") {
3153
+ credId = credential2.id;
3154
+ if (credId && this.credentialReferences) {
3155
+ const resolvedCred = this.credentialReferences.find((c) => c.id === credId);
3156
+ if (resolvedCred && !credentialReferencesObject[credId]) {
3157
+ credentialReferencesObject[credId] = resolvedCred;
3158
+ credentialUsageMap[credId] = [];
3159
+ }
3160
+ }
3161
+ } else if (credential2.id) {
3162
+ credId = credential2.id;
3163
+ if (credId && !credentialReferencesObject[credId]) {
3164
+ credentialReferencesObject[credId] = credential2;
3165
+ credentialUsageMap[credId] = [];
3166
+ }
3167
+ }
3168
+ if (credId) {
3169
+ if (!credentialUsageMap[credId]) {
3170
+ credentialUsageMap[credId] = [];
3171
+ }
3172
+ credentialUsageMap[credId].push({
3173
+ type: "contextVariable",
3174
+ id: key,
3175
+ graphId: graph.getId()
3176
+ });
3177
+ }
3178
+ } else if (variable?.credentialReferenceId) {
3179
+ const credId = variable.credentialReferenceId;
3180
+ if (!credentialUsageMap[credId]) {
3181
+ credentialUsageMap[credId] = [];
3182
+ }
3183
+ credentialUsageMap[credId].push({
3184
+ type: "contextVariable",
3185
+ id: key,
3186
+ graphId: graph.getId()
3187
+ });
3188
+ }
3189
+ }
3190
+ }
3191
+ }
2990
3192
  for (const agent2 of graph.agents) {
2991
3193
  if (!agent2.getTools) {
2992
3194
  continue;
@@ -3051,7 +3253,27 @@ var Project = class {
3051
3253
  toolData.lastToolsSync = actualTool.lastToolsSync;
3052
3254
  }
3053
3255
  if (actualTool.getCredentialReferenceId?.()) {
3054
- toolData.credentialReferenceId = 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
+ });
3055
3277
  }
3056
3278
  toolsObject[toolId] = toolData;
3057
3279
  }
@@ -3060,13 +3282,27 @@ var Project = class {
3060
3282
  const agentDataComponents = agent2.getDataComponents?.();
3061
3283
  if (agentDataComponents) {
3062
3284
  for (const dataComponent2 of agentDataComponents) {
3063
- const dataComponentId = dataComponent2.id || dataComponent2.name.toLowerCase().replace(/\s+/g, "-");
3064
- if (!dataComponentsObject[dataComponentId]) {
3285
+ let dataComponentId;
3286
+ let dataComponentName;
3287
+ let dataComponentDescription;
3288
+ let dataComponentProps;
3289
+ if (dataComponent2.getId) {
3290
+ dataComponentId = dataComponent2.getId();
3291
+ dataComponentName = dataComponent2.getName();
3292
+ dataComponentDescription = dataComponent2.getDescription() || "";
3293
+ dataComponentProps = dataComponent2.getProps() || {};
3294
+ } else {
3295
+ dataComponentId = dataComponent2.id || (dataComponent2.name ? dataComponent2.name.toLowerCase().replace(/\s+/g, "-") : "");
3296
+ dataComponentName = dataComponent2.name || "";
3297
+ dataComponentDescription = dataComponent2.description || "";
3298
+ dataComponentProps = dataComponent2.props || {};
3299
+ }
3300
+ if (!dataComponentsObject[dataComponentId] && dataComponentName) {
3065
3301
  dataComponentsObject[dataComponentId] = {
3066
3302
  id: dataComponentId,
3067
- name: dataComponent2.name,
3068
- description: dataComponent2.description || "",
3069
- props: dataComponent2.props || {}
3303
+ name: dataComponentName,
3304
+ description: dataComponentDescription,
3305
+ props: dataComponentProps
3070
3306
  };
3071
3307
  }
3072
3308
  }
@@ -3074,20 +3310,52 @@ var Project = class {
3074
3310
  const agentArtifactComponents = agent2.getArtifactComponents?.();
3075
3311
  if (agentArtifactComponents) {
3076
3312
  for (const artifactComponent2 of agentArtifactComponents) {
3077
- const artifactComponentId = artifactComponent2.id || artifactComponent2.name.toLowerCase().replace(/\s+/g, "-");
3078
- if (!artifactComponentsObject[artifactComponentId]) {
3313
+ let artifactComponentId;
3314
+ let artifactComponentName;
3315
+ let artifactComponentDescription;
3316
+ let artifactComponentSummaryProps;
3317
+ let artifactComponentFullProps;
3318
+ if (artifactComponent2.getId) {
3319
+ artifactComponentId = artifactComponent2.getId();
3320
+ artifactComponentName = artifactComponent2.getName();
3321
+ artifactComponentDescription = artifactComponent2.getDescription() || "";
3322
+ artifactComponentSummaryProps = artifactComponent2.getSummaryProps() || {};
3323
+ artifactComponentFullProps = artifactComponent2.getFullProps() || {};
3324
+ } else {
3325
+ artifactComponentId = artifactComponent2.id || (artifactComponent2.name ? artifactComponent2.name.toLowerCase().replace(/\s+/g, "-") : "");
3326
+ artifactComponentName = artifactComponent2.name || "";
3327
+ artifactComponentDescription = artifactComponent2.description || "";
3328
+ artifactComponentSummaryProps = artifactComponent2.summaryProps || {};
3329
+ artifactComponentFullProps = artifactComponent2.fullProps || {};
3330
+ }
3331
+ if (!artifactComponentsObject[artifactComponentId] && artifactComponentName) {
3079
3332
  artifactComponentsObject[artifactComponentId] = {
3080
3333
  id: artifactComponentId,
3081
- name: artifactComponent2.name,
3082
- description: artifactComponent2.description || "",
3083
- summaryProps: artifactComponent2.summaryProps || {},
3084
- fullProps: artifactComponent2.fullProps || {}
3334
+ name: artifactComponentName,
3335
+ description: artifactComponentDescription,
3336
+ summaryProps: artifactComponentSummaryProps,
3337
+ fullProps: artifactComponentFullProps
3085
3338
  };
3086
3339
  }
3087
3340
  }
3088
3341
  }
3089
3342
  }
3090
3343
  }
3344
+ if (this.credentialReferences && this.credentialReferences.length > 0) {
3345
+ for (const credential2 of this.credentialReferences) {
3346
+ if (credential2.id) {
3347
+ if (!credentialReferencesObject[credential2.id]) {
3348
+ credentialReferencesObject[credential2.id] = credential2;
3349
+ credentialUsageMap[credential2.id] = [];
3350
+ }
3351
+ }
3352
+ }
3353
+ }
3354
+ for (const [credId, usages] of Object.entries(credentialUsageMap)) {
3355
+ if (credentialReferencesObject[credId]) {
3356
+ credentialReferencesObject[credId].usedBy = usages;
3357
+ }
3358
+ }
3091
3359
  return {
3092
3360
  id: this.projectId,
3093
3361
  name: this.projectName,
@@ -3098,31 +3366,13 @@ var Project = class {
3098
3366
  tools: toolsObject,
3099
3367
  dataComponents: Object.keys(dataComponentsObject).length > 0 ? dataComponentsObject : void 0,
3100
3368
  artifactComponents: Object.keys(artifactComponentsObject).length > 0 ? artifactComponentsObject : void 0,
3101
- credentialReferences: void 0,
3102
- // Projects don't directly hold credentials yet
3369
+ credentialReferences: Object.keys(credentialReferencesObject).length > 0 ? credentialReferencesObject : void 0,
3103
3370
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3104
3371
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
3105
3372
  };
3106
3373
  }
3107
- /**
3108
- * Convert project configuration to API format
3109
- */
3110
- toApiFormat() {
3111
- return {
3112
- id: this.projectId,
3113
- name: this.projectName,
3114
- description: this.projectDescription || "",
3115
- models: this.models,
3116
- stopWhen: this.stopWhen
3117
- };
3118
- }
3119
3374
  };
3120
3375
 
3121
- // src/utils/generateIdFromName.ts
3122
- function generateIdFromName3(name) {
3123
- return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
3124
- }
3125
-
3126
3376
  // src/builderFunctions.ts
3127
3377
  function agentGraph(config) {
3128
3378
  return new AgentGraph(config);
@@ -3145,13 +3395,12 @@ function mcpServer(config) {
3145
3395
  if (!config.serverUrl) {
3146
3396
  throw new Error("MCP server requires a serverUrl");
3147
3397
  }
3148
- const id = config.id || generateIdFromName3(config.name);
3398
+ const id = config.id || generateIdFromName(config.name);
3149
3399
  return new Tool({
3150
3400
  id,
3151
3401
  name: config.name,
3152
3402
  description: config.description,
3153
3403
  serverUrl: config.serverUrl,
3154
- tenantId: config.tenantId,
3155
3404
  credential: config.credential,
3156
3405
  activeTools: config.activeTools,
3157
3406
  headers: config.headers,
@@ -3162,24 +3411,24 @@ function mcpServer(config) {
3162
3411
  function mcpTool(config) {
3163
3412
  const configWithId = {
3164
3413
  ...config,
3165
- id: config.id || generateIdFromName3(config.name)
3414
+ id: config.id || generateIdFromName(config.name)
3166
3415
  };
3167
3416
  const validatedConfig = agentsCore.MCPToolConfigSchema.parse(configWithId);
3168
3417
  return new Tool(validatedConfig);
3169
3418
  }
3170
3419
  function artifactComponent(config) {
3171
- return new ArtifactComponent({
3420
+ const configWithId = {
3172
3421
  ...config,
3173
- tenantId: config.tenantId || "default",
3174
- projectId: config.projectId || "default"
3175
- });
3422
+ id: config.id || generateIdFromName(config.name)
3423
+ };
3424
+ return new ArtifactComponent(configWithId);
3176
3425
  }
3177
3426
  function dataComponent(config) {
3178
- return new DataComponent({
3427
+ const configWithId = {
3179
3428
  ...config,
3180
- tenantId: config.tenantId || "default",
3181
- projectId: config.projectId || "default"
3182
- });
3429
+ id: config.id || generateIdFromName(config.name)
3430
+ };
3431
+ return new DataComponent(configWithId);
3183
3432
  }
3184
3433
  function agentMcp(config) {
3185
3434
  return {
@@ -3188,6 +3437,17 @@ function agentMcp(config) {
3188
3437
  };
3189
3438
  }
3190
3439
 
3440
+ // src/credential-ref.ts
3441
+ function credentialRef(id) {
3442
+ return {
3443
+ __type: "credential-ref",
3444
+ id
3445
+ };
3446
+ }
3447
+ function isCredentialReference(value) {
3448
+ return value && typeof value === "object" && value.__type === "credential-ref";
3449
+ }
3450
+
3191
3451
  // src/utils/validateFunction.ts
3192
3452
  function validateFunction(value, name) {
3193
3453
  if (typeof value !== "function") {
@@ -3219,7 +3479,7 @@ function transfer(targetAgent, description, condition) {
3219
3479
  // src/environment-settings.ts
3220
3480
  function createEnvironmentSettings(environments) {
3221
3481
  return {
3222
- getEnvironmentSetting: async (key) => {
3482
+ getEnvironmentSetting: (key) => {
3223
3483
  const currentEnv = process.env.INKEEP_ENV || "development";
3224
3484
  const env = environments[currentEnv];
3225
3485
  if (!env) {
@@ -3451,11 +3711,13 @@ exports.artifactComponent = artifactComponent;
3451
3711
  exports.createEnvironmentSettings = createEnvironmentSettings;
3452
3712
  exports.createFullProjectViaAPI = createFullProjectViaAPI;
3453
3713
  exports.credential = credential;
3714
+ exports.credentialRef = credentialRef;
3454
3715
  exports.dataComponent = dataComponent;
3455
3716
  exports.deleteFullProjectViaAPI = deleteFullProjectViaAPI;
3456
3717
  exports.externalAgent = externalAgent;
3457
3718
  exports.externalAgents = externalAgents;
3458
3719
  exports.getFullProjectViaAPI = getFullProjectViaAPI;
3720
+ exports.isCredentialReference = isCredentialReference;
3459
3721
  exports.mcpServer = mcpServer;
3460
3722
  exports.mcpTool = mcpTool;
3461
3723
  exports.project = project;