@inkeep/agents-core 0.2.2 → 0.3.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.js CHANGED
@@ -1,18 +1,18 @@
1
- import { validateAndTypeGraphData, validateGraphStructure, isInternalAgent, isExternalAgent } from './chunk-BAPMUHVN.js';
2
- export { generateIdFromName, isExternalAgent, isInternalAgent, isValidResourceId, validateAgentRelationships, validateAndTypeGraphData, validateArtifactComponentReferences, validateDataComponentReferences, validateGraphStructure, validateToolReferences } from './chunk-BAPMUHVN.js';
3
- import { ContextConfigApiUpdateSchema } from './chunk-KNC2AOJM.js';
4
- export { AgentApiInsertSchema, AgentApiSelectSchema, AgentApiUpdateSchema, AgentArtifactComponentApiInsertSchema, AgentArtifactComponentApiSelectSchema, AgentArtifactComponentApiUpdateSchema, AgentArtifactComponentInsertSchema, AgentArtifactComponentSelectSchema, AgentArtifactComponentUpdateSchema, AgentDataComponentApiInsertSchema, AgentDataComponentApiSelectSchema, AgentDataComponentApiUpdateSchema, AgentDataComponentInsertSchema, AgentDataComponentSelectSchema, AgentDataComponentUpdateSchema, AgentGraphApiInsertSchema, AgentGraphApiSelectSchema, AgentGraphApiUpdateSchema, AgentGraphInsertSchema, AgentGraphSelectSchema, AgentGraphUpdateSchema, AgentInsertSchema, AgentRelationApiInsertSchema, AgentRelationApiSelectSchema, AgentRelationApiUpdateSchema, AgentRelationInsertSchema, AgentRelationQuerySchema, AgentRelationSelectSchema, AgentRelationUpdateSchema, AgentSelectSchema, AgentStopWhenSchema, AgentToolRelationApiInsertSchema, AgentToolRelationApiSelectSchema, AgentToolRelationApiUpdateSchema, AgentToolRelationInsertSchema, AgentToolRelationSelectSchema, AgentToolRelationUpdateSchema, AgentUpdateSchema, AllAgentSchema, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, ApiKeyApiSelectSchema, ApiKeyApiUpdateSchema, ApiKeyInsertSchema, ApiKeySelectSchema, ApiKeyUpdateSchema, ArtifactComponentApiInsertSchema, ArtifactComponentApiSelectSchema, ArtifactComponentApiUpdateSchema, ArtifactComponentInsertSchema, ArtifactComponentSelectSchema, ArtifactComponentUpdateSchema, ContextCacheApiInsertSchema, ContextCacheApiSelectSchema, ContextCacheApiUpdateSchema, ContextCacheInsertSchema, ContextCacheSelectSchema, ContextCacheUpdateSchema, ContextConfigApiInsertSchema, ContextConfigApiSelectSchema, ContextConfigApiUpdateSchema, ContextConfigInsertSchema, ContextConfigSelectSchema, ContextConfigUpdateSchema, ConversationApiInsertSchema, ConversationApiSelectSchema, ConversationApiUpdateSchema, ConversationInsertSchema, ConversationSelectSchema, ConversationUpdateSchema, CredentialReferenceApiInsertSchema, CredentialReferenceApiSelectSchema, CredentialReferenceApiUpdateSchema, CredentialReferenceInsertSchema, CredentialReferenceSelectSchema, CredentialReferenceUpdateSchema, DataComponentApiInsertSchema, DataComponentApiSelectSchema, DataComponentApiUpdateSchema, DataComponentBaseSchema, DataComponentInsertSchema, DataComponentSelectSchema, DataComponentUpdateSchema, ErrorResponseSchema, ExistsResponseSchema, ExternalAgentApiInsertSchema, ExternalAgentApiSelectSchema, ExternalAgentApiUpdateSchema, ExternalAgentInsertSchema, ExternalAgentRelationApiInsertSchema, ExternalAgentRelationInsertSchema, ExternalAgentSelectSchema, ExternalAgentUpdateSchema, FetchConfigSchema, FetchDefinitionSchema, FullGraphAgentInsertSchema, FullGraphDefinitionSchema, FullProjectDefinitionSchema, GraphStopWhenSchema, GraphWithinContextOfProjectSchema, HeadersScopeSchema, IdParamsSchema, LedgerArtifactApiInsertSchema, LedgerArtifactApiSelectSchema, LedgerArtifactApiUpdateSchema, LedgerArtifactInsertSchema, LedgerArtifactSelectSchema, LedgerArtifactUpdateSchema, ListResponseSchema, MAX_ID_LENGTH, MCPToolConfigSchema, MIN_ID_LENGTH, McpToolDefinitionSchema, McpToolSchema, McpTransportConfigSchema, MessageApiInsertSchema, MessageApiSelectSchema, MessageApiUpdateSchema, MessageInsertSchema, MessageSelectSchema, MessageUpdateSchema, ModelSchema, ModelSettingsSchema, PaginationQueryParamsSchema, PaginationSchema, ProjectApiInsertSchema, ProjectApiSelectSchema, ProjectApiUpdateSchema, ProjectInsertSchema, ProjectModelSchema, ProjectSelectSchema, ProjectUpdateSchema, RemovedResponseSchema, SingleResponseSchema, StatusComponentSchema, StatusUpdateSchema, StopWhenSchema, TaskApiInsertSchema, TaskApiSelectSchema, TaskApiUpdateSchema, TaskInsertSchema, TaskRelationApiInsertSchema, TaskRelationApiSelectSchema, TaskRelationApiUpdateSchema, TaskRelationInsertSchema, TaskRelationSelectSchema, TaskRelationUpdateSchema, TaskSelectSchema, TaskUpdateSchema, TenantIdParamsSchema, TenantParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsertSchema, ToolApiSelectSchema, ToolApiUpdateSchema, ToolInsertSchema, ToolSelectSchema, ToolStatusSchema, ToolUpdateSchema, URL_SAFE_ID_PATTERN, resourceIdSchema } from './chunk-KNC2AOJM.js';
5
- import { schema_exports, agentRelations, agents, externalAgents, agentToolRelations, tools, contextConfigs, agentGraph, agentDataComponents, agentArtifactComponents, dataComponents, artifactComponents, projects, apiKeys, contextCache, conversations, messages, credentialReferences, ledgerArtifacts, tasks, taskRelations } from './chunk-MXQKLGQK.js';
6
- export { agentArtifactComponents, agentArtifactComponentsRelations, agentDataComponents, agentGraph, agentGraphRelations, agentRelations, agentRelationsRelations, agentToolRelations, agentToolRelationsRelations, agents, agentsRelations, apiKeys, apiKeysRelations, artifactComponents, artifactComponentsRelations, contextCache, contextCacheRelations, contextConfigs, contextConfigsRelations, conversations, conversationsRelations, credentialReferences, credentialReferencesRelations, dataComponents, externalAgents, externalAgentsRelations, ledgerArtifacts, ledgerArtifactsContextIdIdx, ledgerArtifactsTaskContextNameUnique, ledgerArtifactsTaskIdIdx, messages, messagesRelations, projects, projectsRelations, taskRelations, taskRelationsRelations, tasks, tasksRelations, tools, toolsRelations } from './chunk-MXQKLGQK.js';
7
1
  export { TaskState } from './chunk-H2F72PDA.js';
2
+ import { validateAndTypeGraphData, validateGraphStructure, isInternalAgent, isExternalAgent } from './chunk-XQRFKXVV.js';
3
+ export { generateIdFromName, isExternalAgent, isInternalAgent, isValidResourceId, validateAgentRelationships, validateAndTypeGraphData, validateArtifactComponentReferences, validateDataComponentReferences, validateGraphStructure, validateToolReferences } from './chunk-XQRFKXVV.js';
4
+ import { ContextConfigApiUpdateSchema } from './chunk-LPIKPCE5.js';
5
+ export { AgentApiInsertSchema, AgentApiSelectSchema, AgentApiUpdateSchema, AgentArtifactComponentApiInsertSchema, AgentArtifactComponentApiSelectSchema, AgentArtifactComponentApiUpdateSchema, AgentArtifactComponentInsertSchema, AgentArtifactComponentSelectSchema, AgentArtifactComponentUpdateSchema, AgentDataComponentApiInsertSchema, AgentDataComponentApiSelectSchema, AgentDataComponentApiUpdateSchema, AgentDataComponentInsertSchema, AgentDataComponentSelectSchema, AgentDataComponentUpdateSchema, AgentGraphApiInsertSchema, AgentGraphApiSelectSchema, AgentGraphApiUpdateSchema, AgentGraphInsertSchema, AgentGraphSelectSchema, AgentGraphUpdateSchema, AgentInsertSchema, AgentRelationApiInsertSchema, AgentRelationApiSelectSchema, AgentRelationApiUpdateSchema, AgentRelationInsertSchema, AgentRelationQuerySchema, AgentRelationSelectSchema, AgentRelationUpdateSchema, AgentSelectSchema, AgentStopWhenSchema, AgentToolRelationApiInsertSchema, AgentToolRelationApiSelectSchema, AgentToolRelationApiUpdateSchema, AgentToolRelationInsertSchema, AgentToolRelationSelectSchema, AgentToolRelationUpdateSchema, AgentUpdateSchema, AllAgentSchema, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, ApiKeyApiSelectSchema, ApiKeyApiUpdateSchema, ApiKeyInsertSchema, ApiKeySelectSchema, ApiKeyUpdateSchema, ArtifactComponentApiInsertSchema, ArtifactComponentApiSelectSchema, ArtifactComponentApiUpdateSchema, ArtifactComponentInsertSchema, ArtifactComponentSelectSchema, ArtifactComponentUpdateSchema, ContextCacheApiInsertSchema, ContextCacheApiSelectSchema, ContextCacheApiUpdateSchema, ContextCacheInsertSchema, ContextCacheSelectSchema, ContextCacheUpdateSchema, ContextConfigApiInsertSchema, ContextConfigApiSelectSchema, ContextConfigApiUpdateSchema, ContextConfigInsertSchema, ContextConfigSelectSchema, ContextConfigUpdateSchema, ConversationApiInsertSchema, ConversationApiSelectSchema, ConversationApiUpdateSchema, ConversationInsertSchema, ConversationSelectSchema, ConversationUpdateSchema, CredentialReferenceApiInsertSchema, CredentialReferenceApiSelectSchema, CredentialReferenceApiUpdateSchema, CredentialReferenceInsertSchema, CredentialReferenceSelectSchema, CredentialReferenceUpdateSchema, DataComponentApiInsertSchema, DataComponentApiSelectSchema, DataComponentApiUpdateSchema, DataComponentBaseSchema, DataComponentInsertSchema, DataComponentSelectSchema, DataComponentUpdateSchema, ErrorResponseSchema, ExistsResponseSchema, ExternalAgentApiInsertSchema, ExternalAgentApiSelectSchema, ExternalAgentApiUpdateSchema, ExternalAgentInsertSchema, ExternalAgentRelationApiInsertSchema, ExternalAgentRelationInsertSchema, ExternalAgentSelectSchema, ExternalAgentUpdateSchema, FetchConfigSchema, FetchDefinitionSchema, FullGraphAgentInsertSchema, FullGraphDefinitionSchema, FullProjectDefinitionSchema, GraphStopWhenSchema, GraphWithinContextOfProjectSchema, HeadersScopeSchema, IdParamsSchema, LedgerArtifactApiInsertSchema, LedgerArtifactApiSelectSchema, LedgerArtifactApiUpdateSchema, LedgerArtifactInsertSchema, LedgerArtifactSelectSchema, LedgerArtifactUpdateSchema, ListResponseSchema, MAX_ID_LENGTH, MCPToolConfigSchema, MIN_ID_LENGTH, McpToolDefinitionSchema, McpToolSchema, McpTransportConfigSchema, MessageApiInsertSchema, MessageApiSelectSchema, MessageApiUpdateSchema, MessageInsertSchema, MessageSelectSchema, MessageUpdateSchema, ModelSchema, ModelSettingsSchema, PaginationQueryParamsSchema, PaginationSchema, ProjectApiInsertSchema, ProjectApiSelectSchema, ProjectApiUpdateSchema, ProjectInsertSchema, ProjectModelSchema, ProjectSelectSchema, ProjectUpdateSchema, RemovedResponseSchema, SingleResponseSchema, StatusComponentSchema, StatusUpdateSchema, StopWhenSchema, TaskApiInsertSchema, TaskApiSelectSchema, TaskApiUpdateSchema, TaskInsertSchema, TaskRelationApiInsertSchema, TaskRelationApiSelectSchema, TaskRelationApiUpdateSchema, TaskRelationInsertSchema, TaskRelationSelectSchema, TaskRelationUpdateSchema, TaskSelectSchema, TaskUpdateSchema, TenantIdParamsSchema, TenantParamsSchema, TenantProjectGraphIdParamsSchema, TenantProjectGraphParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsertSchema, ToolApiSelectSchema, ToolApiUpdateSchema, ToolInsertSchema, ToolSelectSchema, ToolStatusSchema, ToolUpdateSchema, URL_SAFE_ID_PATTERN, resourceIdSchema } from './chunk-LPIKPCE5.js';
8
6
  import { CredentialStoreType, MCPServerType, MCPTransportType } from './chunk-SVGQSPW4.js';
9
7
  export { CredentialStoreType, MCPServerType, MCPTransportType, TOOL_STATUS_VALUES, VALID_RELATION_TYPES } from './chunk-SVGQSPW4.js';
8
+ import { schema_exports, agentRelations, agents, externalAgents, agentToolRelations, tools, contextConfigs, agentGraph, agentDataComponents, agentArtifactComponents, dataComponents, artifactComponents, projects, apiKeys, contextCache, conversations, messages, credentialReferences, ledgerArtifacts, tasks, taskRelations } from './chunk-LFWFXR4O.js';
9
+ export { agentArtifactComponents, agentArtifactComponentsRelations, agentDataComponents, agentDataComponentsRelations, agentGraph, agentGraphRelations, agentRelations, agentRelationsRelations, agentToolRelations, agentToolRelationsRelations, agents, agentsRelations, apiKeys, apiKeysRelations, artifactComponents, artifactComponentsRelations, contextCache, contextCacheRelations, contextConfigs, contextConfigsRelations, conversations, conversationsRelations, credentialReferences, credentialReferencesRelations, dataComponents, dataComponentsRelations, externalAgents, externalAgentsRelations, ledgerArtifacts, ledgerArtifactsContextIdIdx, ledgerArtifactsRelations, ledgerArtifactsTaskContextNameUnique, ledgerArtifactsTaskIdIdx, messages, messagesRelations, projects, projectsRelations, taskRelations, taskRelationsRelations, tasks, tasksRelations, tools, toolsRelations } from './chunk-LFWFXR4O.js';
10
10
  import { __publicField } from './chunk-MKBO26DX.js';
11
11
  import { z as z$1 } from 'zod';
12
12
  import jmespath from 'jmespath';
13
13
  import { createClient } from '@libsql/client';
14
14
  import { drizzle } from 'drizzle-orm/libsql';
15
- import { and, eq, desc, count, isNotNull, inArray, sql, asc, like } from 'drizzle-orm';
15
+ import { and, eq, desc, count, isNotNull, inArray, sql, asc } from 'drizzle-orm';
16
16
  import { customAlphabet, nanoid } from 'nanoid';
17
17
  import crypto, { scrypt, randomBytes, timingSafeEqual } from 'crypto';
18
18
  import { promisify } from 'util';
@@ -790,6 +790,7 @@ var getAgentRelationById = (db) => async (params) => {
790
790
  where: and(
791
791
  eq(agentRelations.tenantId, params.scopes.tenantId),
792
792
  eq(agentRelations.projectId, params.scopes.projectId),
793
+ eq(agentRelations.graphId, params.scopes.graphId),
793
794
  eq(agentRelations.id, params.relationId)
794
795
  )
795
796
  });
@@ -800,7 +801,8 @@ var listAgentRelations = (db) => async (params) => {
800
801
  const offset = (page - 1) * limit;
801
802
  const whereClause = and(
802
803
  eq(agentRelations.tenantId, params.scopes.tenantId),
803
- eq(agentRelations.projectId, params.scopes.projectId)
804
+ eq(agentRelations.projectId, params.scopes.projectId),
805
+ eq(agentRelations.graphId, params.scopes.graphId)
804
806
  );
805
807
  const [data, totalResult] = await Promise.all([
806
808
  db.select().from(agentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(agentRelations.createdAt)),
@@ -815,8 +817,8 @@ var getAgentRelations = (db) => async (params) => {
815
817
  where: and(
816
818
  eq(agentRelations.tenantId, params.scopes.tenantId),
817
819
  eq(agentRelations.projectId, params.scopes.projectId),
818
- eq(agentRelations.graphId, params.graphId),
819
- eq(agentRelations.sourceAgentId, params.agentId)
820
+ eq(agentRelations.graphId, params.scopes.graphId),
821
+ eq(agentRelations.sourceAgentId, params.scopes.agentId)
820
822
  )
821
823
  });
822
824
  };
@@ -825,7 +827,7 @@ var getAgentRelationsByGraph = (db) => async (params) => {
825
827
  where: and(
826
828
  eq(agentRelations.tenantId, params.scopes.tenantId),
827
829
  eq(agentRelations.projectId, params.scopes.projectId),
828
- eq(agentRelations.graphId, params.graphId)
830
+ eq(agentRelations.graphId, params.scopes.graphId)
829
831
  )
830
832
  });
831
833
  };
@@ -836,6 +838,7 @@ var getAgentRelationsBySource = (db) => async (params) => {
836
838
  const whereClause = and(
837
839
  eq(agentRelations.tenantId, params.scopes.tenantId),
838
840
  eq(agentRelations.projectId, params.scopes.projectId),
841
+ eq(agentRelations.graphId, params.scopes.graphId),
839
842
  eq(agentRelations.sourceAgentId, params.sourceAgentId)
840
843
  );
841
844
  const [data, totalResult] = await Promise.all([
@@ -856,6 +859,7 @@ var getAgentRelationsByTarget = (db) => async (params) => {
856
859
  const whereClause = and(
857
860
  eq(agentRelations.tenantId, params.scopes.tenantId),
858
861
  eq(agentRelations.projectId, params.scopes.projectId),
862
+ eq(agentRelations.graphId, params.scopes.graphId),
859
863
  eq(agentRelations.targetAgentId, params.targetAgentId)
860
864
  );
861
865
  const [data, totalResult] = await Promise.all([
@@ -876,6 +880,7 @@ var getExternalAgentRelations = (db) => async (params) => {
876
880
  const whereClause = and(
877
881
  eq(agentRelations.tenantId, params.scopes.tenantId),
878
882
  eq(agentRelations.projectId, params.scopes.projectId),
883
+ eq(agentRelations.graphId, params.scopes.graphId),
879
884
  eq(agentRelations.externalAgentId, params.externalAgentId)
880
885
  );
881
886
  const [data, totalResult] = await Promise.all([
@@ -899,11 +904,12 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
899
904
  and(
900
905
  eq(agentRelations.tenantId, params.scopes.tenantId),
901
906
  eq(agentRelations.projectId, params.scopes.projectId),
902
- eq(agentRelations.graphId, params.graphId),
907
+ eq(agentRelations.graphId, params.scopes.graphId),
903
908
  eq(agentRelations.sourceAgentId, params.agentId),
904
909
  isNotNull(agentRelations.targetAgentId),
905
910
  eq(agents.tenantId, params.scopes.tenantId),
906
- eq(agents.projectId, params.scopes.projectId)
911
+ eq(agents.projectId, params.scopes.projectId),
912
+ eq(agents.graphId, params.scopes.graphId)
907
913
  )
908
914
  );
909
915
  const externalRelations = await db.select({
@@ -919,11 +925,12 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
919
925
  and(
920
926
  eq(agentRelations.tenantId, params.scopes.tenantId),
921
927
  eq(agentRelations.projectId, params.scopes.projectId),
922
- eq(agentRelations.graphId, params.graphId),
928
+ eq(agentRelations.graphId, params.scopes.graphId),
923
929
  eq(agentRelations.sourceAgentId, params.agentId),
924
930
  isNotNull(agentRelations.externalAgentId),
925
931
  eq(externalAgents.tenantId, params.scopes.tenantId),
926
- eq(externalAgents.projectId, params.scopes.projectId)
932
+ eq(externalAgents.projectId, params.scopes.projectId),
933
+ eq(externalAgents.graphId, params.scopes.graphId)
927
934
  )
928
935
  );
929
936
  return {
@@ -949,7 +956,7 @@ var getAgentRelationByParams = (db) => async (params) => {
949
956
  const whereConditions = [
950
957
  eq(agentRelations.tenantId, params.scopes.tenantId),
951
958
  eq(agentRelations.projectId, params.scopes.projectId),
952
- eq(agentRelations.graphId, params.graphId),
959
+ eq(agentRelations.graphId, params.scopes.graphId),
953
960
  eq(agentRelations.sourceAgentId, params.sourceAgentId),
954
961
  eq(agentRelations.relationType, params.relationType)
955
962
  ];
@@ -965,8 +972,7 @@ var getAgentRelationByParams = (db) => async (params) => {
965
972
  };
966
973
  var upsertAgentRelation = (db) => async (params) => {
967
974
  const existing = await getAgentRelationByParams(db)({
968
- scopes: { tenantId: params.tenantId, projectId: params.projectId },
969
- graphId: params.graphId,
975
+ scopes: { tenantId: params.tenantId, projectId: params.projectId, graphId: params.graphId },
970
976
  sourceAgentId: params.sourceAgentId,
971
977
  targetAgentId: params.targetAgentId,
972
978
  externalAgentId: params.externalAgentId,
@@ -992,6 +998,7 @@ var updateAgentRelation = (db) => async (params) => {
992
998
  and(
993
999
  eq(agentRelations.tenantId, params.scopes.tenantId),
994
1000
  eq(agentRelations.projectId, params.scopes.projectId),
1001
+ eq(agentRelations.graphId, params.scopes.graphId),
995
1002
  eq(agentRelations.id, params.relationId)
996
1003
  )
997
1004
  ).returning();
@@ -1002,6 +1009,7 @@ var deleteAgentRelation = (db) => async (params) => {
1002
1009
  and(
1003
1010
  eq(agentRelations.tenantId, params.scopes.tenantId),
1004
1011
  eq(agentRelations.projectId, params.scopes.projectId),
1012
+ eq(agentRelations.graphId, params.scopes.graphId),
1005
1013
  eq(agentRelations.id, params.relationId)
1006
1014
  )
1007
1015
  );
@@ -1011,7 +1019,7 @@ var deleteAgentRelationsByGraph = (db) => async (params) => {
1011
1019
  const result = await db.delete(agentRelations).where(
1012
1020
  and(
1013
1021
  eq(agentRelations.tenantId, params.scopes.tenantId),
1014
- eq(agentRelations.graphId, params.graphId)
1022
+ eq(agentRelations.graphId, params.scopes.graphId)
1015
1023
  )
1016
1024
  );
1017
1025
  return (result.rowsAffected || 0) > 0;
@@ -1022,6 +1030,7 @@ var createAgentToolRelation = (db) => async (params) => {
1022
1030
  id: finalRelationId,
1023
1031
  tenantId: params.scopes.tenantId,
1024
1032
  projectId: params.scopes.projectId,
1033
+ graphId: params.scopes.graphId,
1025
1034
  agentId: params.data.agentId,
1026
1035
  toolId: params.data.toolId,
1027
1036
  selectedTools: params.data.selectedTools
@@ -1037,6 +1046,7 @@ var updateAgentToolRelation = (db) => async (params) => {
1037
1046
  and(
1038
1047
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1039
1048
  eq(agentToolRelations.projectId, params.scopes.projectId),
1049
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1040
1050
  eq(agentToolRelations.id, params.relationId)
1041
1051
  )
1042
1052
  ).returning();
@@ -1047,6 +1057,7 @@ var deleteAgentToolRelation = (db) => async (params) => {
1047
1057
  and(
1048
1058
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1049
1059
  eq(agentToolRelations.projectId, params.scopes.projectId),
1060
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1050
1061
  eq(agentToolRelations.id, params.relationId)
1051
1062
  )
1052
1063
  );
@@ -1056,7 +1067,9 @@ var deleteAgentToolRelationByAgent = (db) => async (params) => {
1056
1067
  const result = await db.delete(agentToolRelations).where(
1057
1068
  and(
1058
1069
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1059
- eq(agentToolRelations.agentId, params.agentId)
1070
+ eq(agentToolRelations.projectId, params.scopes.projectId),
1071
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1072
+ eq(agentToolRelations.agentId, params.scopes.agentId)
1060
1073
  )
1061
1074
  );
1062
1075
  return (result.rowsAffected || 0) > 0;
@@ -1066,6 +1079,7 @@ var getAgentToolRelationById = (db) => async (params) => {
1066
1079
  where: and(
1067
1080
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1068
1081
  eq(agentToolRelations.projectId, params.scopes.projectId),
1082
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1069
1083
  eq(agentToolRelations.id, params.relationId)
1070
1084
  )
1071
1085
  });
@@ -1079,14 +1093,14 @@ var getAgentToolRelationByAgent = (db) => async (params) => {
1079
1093
  and(
1080
1094
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1081
1095
  eq(agentToolRelations.projectId, params.scopes.projectId),
1082
- eq(agentToolRelations.agentId, params.agentId)
1096
+ eq(agentToolRelations.agentId, params.scopes.agentId)
1083
1097
  )
1084
1098
  ).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
1085
1099
  db.select({ count: count() }).from(agentToolRelations).where(
1086
1100
  and(
1087
1101
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1088
1102
  eq(agentToolRelations.projectId, params.scopes.projectId),
1089
- eq(agentToolRelations.agentId, params.agentId)
1103
+ eq(agentToolRelations.agentId, params.scopes.agentId)
1090
1104
  )
1091
1105
  )
1092
1106
  ]);
@@ -1106,6 +1120,7 @@ var getAgentToolRelationByTool = (db) => async (params) => {
1106
1120
  and(
1107
1121
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1108
1122
  eq(agentToolRelations.projectId, params.scopes.projectId),
1123
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1109
1124
  eq(agentToolRelations.toolId, params.toolId)
1110
1125
  )
1111
1126
  ).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
@@ -1113,6 +1128,7 @@ var getAgentToolRelationByTool = (db) => async (params) => {
1113
1128
  and(
1114
1129
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1115
1130
  eq(agentToolRelations.projectId, params.scopes.projectId),
1131
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1116
1132
  eq(agentToolRelations.toolId, params.toolId)
1117
1133
  )
1118
1134
  )
@@ -1132,13 +1148,15 @@ var listAgentToolRelations = (db) => async (params) => {
1132
1148
  db.select().from(agentToolRelations).where(
1133
1149
  and(
1134
1150
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1135
- eq(agentToolRelations.projectId, params.scopes.projectId)
1151
+ eq(agentToolRelations.projectId, params.scopes.projectId),
1152
+ eq(agentToolRelations.graphId, params.scopes.graphId)
1136
1153
  )
1137
1154
  ).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
1138
1155
  db.select({ count: count() }).from(agentToolRelations).where(
1139
1156
  and(
1140
1157
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1141
- eq(agentToolRelations.projectId, params.scopes.projectId)
1158
+ eq(agentToolRelations.projectId, params.scopes.projectId),
1159
+ eq(agentToolRelations.graphId, params.scopes.graphId)
1142
1160
  )
1143
1161
  )
1144
1162
  ]);
@@ -1149,26 +1167,6 @@ var listAgentToolRelations = (db) => async (params) => {
1149
1167
  pagination: { page, limit, total, pages }
1150
1168
  };
1151
1169
  };
1152
- var listAgentToolRelationsByAgent = (db) => async (params) => {
1153
- const page = params.pagination?.page || 1;
1154
- const limit = Math.min(params.pagination?.limit || 10, 100);
1155
- const offset = (page - 1) * limit;
1156
- const whereClause = and(
1157
- eq(agentToolRelations.tenantId, params.scopes.tenantId),
1158
- eq(agentToolRelations.projectId, params.scopes.projectId),
1159
- eq(agentToolRelations.agentId, params.agentId)
1160
- );
1161
- const [data, totalResult] = await Promise.all([
1162
- db.select().from(agentToolRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
1163
- db.select({ count: count() }).from(agentToolRelations).where(whereClause)
1164
- ]);
1165
- const total = totalResult[0]?.count || 0;
1166
- const pages = Math.ceil(total / limit);
1167
- return {
1168
- data,
1169
- pagination: { page, limit, total, pages }
1170
- };
1171
- };
1172
1170
  var getToolsForAgent = (db) => async (params) => {
1173
1171
  const page = params.pagination?.page || 1;
1174
1172
  const limit = Math.min(params.pagination?.limit || 10, 100);
@@ -1199,14 +1197,16 @@ var getToolsForAgent = (db) => async (params) => {
1199
1197
  and(
1200
1198
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1201
1199
  eq(agentToolRelations.projectId, params.scopes.projectId),
1202
- eq(agentToolRelations.agentId, params.agentId)
1200
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1201
+ eq(agentToolRelations.agentId, params.scopes.agentId)
1203
1202
  )
1204
1203
  ).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
1205
1204
  db.select({ count: count() }).from(agentToolRelations).where(
1206
1205
  and(
1207
1206
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1208
1207
  eq(agentToolRelations.projectId, params.scopes.projectId),
1209
- eq(agentToolRelations.agentId, params.agentId)
1208
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1209
+ eq(agentToolRelations.agentId, params.scopes.agentId)
1210
1210
  )
1211
1211
  )
1212
1212
  ]);
@@ -1235,6 +1235,9 @@ var getAgentsForTool = (db) => async (params) => {
1235
1235
  name: agents.name,
1236
1236
  description: agents.description,
1237
1237
  prompt: agents.prompt,
1238
+ conversationHistoryConfig: agents.conversationHistoryConfig,
1239
+ models: agents.models,
1240
+ stopWhen: agents.stopWhen,
1238
1241
  createdAt: agents.createdAt,
1239
1242
  updatedAt: agents.updatedAt
1240
1243
  }
@@ -1242,6 +1245,7 @@ var getAgentsForTool = (db) => async (params) => {
1242
1245
  and(
1243
1246
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1244
1247
  eq(agentToolRelations.projectId, params.scopes.projectId),
1248
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1245
1249
  eq(agentToolRelations.toolId, params.toolId)
1246
1250
  )
1247
1251
  ).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
@@ -1249,6 +1253,7 @@ var getAgentsForTool = (db) => async (params) => {
1249
1253
  and(
1250
1254
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
1251
1255
  eq(agentToolRelations.projectId, params.scopes.projectId),
1256
+ eq(agentToolRelations.graphId, params.scopes.graphId),
1252
1257
  eq(agentToolRelations.toolId, params.toolId)
1253
1258
  )
1254
1259
  )
@@ -1265,7 +1270,8 @@ var validateInternalAgent = (db) => async (params) => {
1265
1270
  and(
1266
1271
  eq(agents.tenantId, params.scopes.tenantId),
1267
1272
  eq(agents.projectId, params.scopes.projectId),
1268
- eq(agents.id, params.agentId)
1273
+ eq(agents.graphId, params.scopes.graphId),
1274
+ eq(agents.id, params.scopes.agentId)
1269
1275
  )
1270
1276
  ).limit(1);
1271
1277
  return result.length > 0;
@@ -1275,7 +1281,8 @@ var validateExternalAgent = (db) => async (params) => {
1275
1281
  and(
1276
1282
  eq(externalAgents.tenantId, params.scopes.tenantId),
1277
1283
  eq(externalAgents.projectId, params.scopes.projectId),
1278
- eq(externalAgents.id, params.agentId)
1284
+ eq(externalAgents.graphId, params.scopes.graphId),
1285
+ eq(externalAgents.id, params.scopes.agentId)
1279
1286
  )
1280
1287
  ).limit(1);
1281
1288
  return result.length > 0;
@@ -1285,6 +1292,7 @@ var getAgentById = (db) => async (params) => {
1285
1292
  where: and(
1286
1293
  eq(agents.tenantId, params.scopes.tenantId),
1287
1294
  eq(agents.projectId, params.scopes.projectId),
1295
+ eq(agents.graphId, params.scopes.graphId),
1288
1296
  eq(agents.id, params.agentId)
1289
1297
  )
1290
1298
  });
@@ -1294,7 +1302,8 @@ var listAgents = (db) => async (params) => {
1294
1302
  return await db.query.agents.findMany({
1295
1303
  where: and(
1296
1304
  eq(agents.tenantId, params.scopes.tenantId),
1297
- eq(agents.projectId, params.scopes.projectId)
1305
+ eq(agents.projectId, params.scopes.projectId),
1306
+ eq(agents.graphId, params.scopes.graphId)
1298
1307
  )
1299
1308
  });
1300
1309
  };
@@ -1304,7 +1313,8 @@ var listAgentsPaginated = (db) => async (params) => {
1304
1313
  const offset = (page - 1) * limit;
1305
1314
  const whereClause = and(
1306
1315
  eq(agents.tenantId, params.scopes.tenantId),
1307
- eq(agents.projectId, params.scopes.projectId)
1316
+ eq(agents.projectId, params.scopes.projectId),
1317
+ eq(agents.graphId, params.scopes.graphId)
1308
1318
  );
1309
1319
  const [data, totalResult] = await Promise.all([
1310
1320
  db.select().from(agents).where(whereClause).limit(limit).offset(offset).orderBy(desc(agents.createdAt)),
@@ -1336,13 +1346,18 @@ var updateAgent = (db) => async (params) => {
1336
1346
  and(
1337
1347
  eq(agents.tenantId, params.scopes.tenantId),
1338
1348
  eq(agents.projectId, params.scopes.projectId),
1349
+ eq(agents.graphId, params.scopes.graphId),
1339
1350
  eq(agents.id, params.agentId)
1340
1351
  )
1341
1352
  ).returning();
1342
1353
  return agent[0] ?? null;
1343
1354
  };
1344
1355
  var upsertAgent = (db) => async (params) => {
1345
- const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId };
1356
+ const scopes = {
1357
+ tenantId: params.data.tenantId,
1358
+ projectId: params.data.projectId,
1359
+ graphId: params.data.graphId
1360
+ };
1346
1361
  const existing = await getAgentById(db)({
1347
1362
  scopes,
1348
1363
  agentId: params.data.id
@@ -1373,6 +1388,7 @@ var deleteAgent = (db) => async (params) => {
1373
1388
  and(
1374
1389
  eq(agents.tenantId, params.scopes.tenantId),
1375
1390
  eq(agents.projectId, params.scopes.projectId),
1391
+ eq(agents.graphId, params.scopes.graphId),
1376
1392
  eq(agents.id, params.agentId)
1377
1393
  )
1378
1394
  );
@@ -1390,36 +1406,11 @@ var getAgentsByIds = (db) => async (params) => {
1390
1406
  and(
1391
1407
  eq(agents.tenantId, params.scopes.tenantId),
1392
1408
  eq(agents.projectId, params.scopes.projectId),
1409
+ eq(agents.graphId, params.scopes.graphId),
1393
1410
  inArray(agents.id, params.agentIds)
1394
1411
  )
1395
1412
  );
1396
1413
  };
1397
- var getAgentInGraphContext = (db) => async (params) => {
1398
- return await db.select({
1399
- id: agents.id,
1400
- name: agents.name,
1401
- description: agents.description,
1402
- prompt: agents.prompt,
1403
- tenantId: agents.tenantId,
1404
- graphId: agentRelations.graphId,
1405
- sourceAgentId: agentRelations.sourceAgentId
1406
- }).from(agents).innerJoin(
1407
- agentRelations,
1408
- and(
1409
- eq(agents.tenantId, agentRelations.tenantId),
1410
- eq(agents.projectId, agentRelations.projectId),
1411
- eq(agents.id, agentRelations.sourceAgentId),
1412
- eq(agentRelations.graphId, params.graphId)
1413
- )
1414
- ).where(
1415
- and(
1416
- eq(agents.tenantId, params.scopes.tenantId),
1417
- eq(agents.projectId, params.scopes.projectId),
1418
- eq(agents.id, params.agentId),
1419
- eq(agentRelations.graphId, params.graphId)
1420
- )
1421
- );
1422
- };
1423
1414
  var getContextConfigById = (db) => async (params) => {
1424
1415
  return await db.query.contextConfigs.findFirst({
1425
1416
  where: and(
@@ -1574,6 +1565,8 @@ var getExternalAgent = (db) => async (params) => {
1574
1565
  const result = await db.query.externalAgents.findFirst({
1575
1566
  where: and(
1576
1567
  eq(externalAgents.tenantId, params.scopes.tenantId),
1568
+ eq(externalAgents.projectId, params.scopes.projectId),
1569
+ eq(externalAgents.graphId, params.scopes.graphId),
1577
1570
  eq(externalAgents.id, params.agentId)
1578
1571
  )
1579
1572
  });
@@ -1583,6 +1576,8 @@ var getExternalAgentByUrl = (db) => async (params) => {
1583
1576
  const result = await db.query.externalAgents.findFirst({
1584
1577
  where: and(
1585
1578
  eq(externalAgents.tenantId, params.scopes.tenantId),
1579
+ eq(externalAgents.projectId, params.scopes.projectId),
1580
+ eq(externalAgents.graphId, params.scopes.graphId),
1586
1581
  eq(externalAgents.baseUrl, params.baseUrl)
1587
1582
  )
1588
1583
  });
@@ -1590,7 +1585,11 @@ var getExternalAgentByUrl = (db) => async (params) => {
1590
1585
  };
1591
1586
  var listExternalAgents = (db) => async (params) => {
1592
1587
  return await db.query.externalAgents.findMany({
1593
- where: eq(externalAgents.tenantId, params.scopes.tenantId),
1588
+ where: and(
1589
+ eq(externalAgents.tenantId, params.scopes.tenantId),
1590
+ eq(externalAgents.projectId, params.scopes.projectId),
1591
+ eq(externalAgents.graphId, params.scopes.graphId)
1592
+ ),
1594
1593
  orderBy: [asc(externalAgents.name)]
1595
1594
  });
1596
1595
  };
@@ -1599,8 +1598,20 @@ var listExternalAgentsPaginated = (db) => async (params) => {
1599
1598
  const limit = Math.min(params.pagination?.limit || 10, 100);
1600
1599
  const offset = (page - 1) * limit;
1601
1600
  const [data, totalResult] = await Promise.all([
1602
- db.select().from(externalAgents).where(eq(externalAgents.tenantId, params.scopes.tenantId)).limit(limit).offset(offset).orderBy(desc(externalAgents.createdAt)),
1603
- db.select({ count: count() }).from(externalAgents).where(eq(externalAgents.tenantId, params.scopes.tenantId))
1601
+ db.select().from(externalAgents).where(
1602
+ and(
1603
+ eq(externalAgents.tenantId, params.scopes.tenantId),
1604
+ eq(externalAgents.projectId, params.scopes.projectId),
1605
+ eq(externalAgents.graphId, params.scopes.graphId)
1606
+ )
1607
+ ).limit(limit).offset(offset).orderBy(desc(externalAgents.createdAt)),
1608
+ db.select({ count: count() }).from(externalAgents).where(
1609
+ and(
1610
+ eq(externalAgents.tenantId, params.scopes.tenantId),
1611
+ eq(externalAgents.projectId, params.scopes.projectId),
1612
+ eq(externalAgents.graphId, params.scopes.graphId)
1613
+ )
1614
+ )
1604
1615
  ]);
1605
1616
  const total = typeof totalResult[0]?.count === "string" ? parseInt(totalResult[0].count, 10) : totalResult[0]?.count || 0;
1606
1617
  const pages = Math.ceil(total / limit);
@@ -1626,13 +1637,19 @@ var updateExternalAgent = (db) => async (params) => {
1626
1637
  const result = await db.update(externalAgents).set(updateData).where(
1627
1638
  and(
1628
1639
  eq(externalAgents.tenantId, params.scopes.tenantId),
1640
+ eq(externalAgents.projectId, params.scopes.projectId),
1641
+ eq(externalAgents.graphId, params.scopes.graphId),
1629
1642
  eq(externalAgents.id, params.agentId)
1630
1643
  )
1631
1644
  ).returning();
1632
1645
  return result[0] || null;
1633
1646
  };
1634
1647
  var upsertExternalAgent = (db) => async (params) => {
1635
- const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId };
1648
+ const scopes = {
1649
+ tenantId: params.data.tenantId,
1650
+ projectId: params.data.projectId,
1651
+ graphId: params.data.graphId
1652
+ };
1636
1653
  const existing = await getExternalAgent(db)({
1637
1654
  scopes,
1638
1655
  agentId: params.data.id
@@ -1662,6 +1679,8 @@ var deleteExternalAgent = (db) => async (params) => {
1662
1679
  const result = await db.delete(externalAgents).where(
1663
1680
  and(
1664
1681
  eq(externalAgents.tenantId, params.scopes.tenantId),
1682
+ eq(externalAgents.projectId, params.scopes.projectId),
1683
+ eq(externalAgents.graphId, params.scopes.graphId),
1665
1684
  eq(externalAgents.id, params.agentId)
1666
1685
  )
1667
1686
  ).returning();
@@ -1680,27 +1699,24 @@ var externalAgentUrlExists = (db) => async (params) => {
1680
1699
  return agent !== null;
1681
1700
  };
1682
1701
  var countExternalAgents = (db) => async (params) => {
1683
- const result = await db.select({ count: count() }).from(externalAgents).where(eq(externalAgents.tenantId, params.scopes.tenantId));
1702
+ const result = await db.select({ count: count() }).from(externalAgents).where(
1703
+ and(
1704
+ eq(externalAgents.tenantId, params.scopes.tenantId),
1705
+ eq(externalAgents.projectId, params.scopes.projectId),
1706
+ eq(externalAgents.graphId, params.scopes.graphId)
1707
+ )
1708
+ );
1684
1709
  const countValue = result[0]?.count;
1685
1710
  return typeof countValue === "string" ? parseInt(countValue, 10) : countValue || 0;
1686
1711
  };
1687
1712
 
1688
1713
  // src/data-access/agentGraphs.ts
1689
- var getAgentGraph = (db) => async (params) => {
1690
- return await db.query.agentGraph.findFirst({
1691
- where: and(
1692
- eq(agentGraph.tenantId, params.scopes.tenantId),
1693
- eq(agentGraph.projectId, params.scopes.projectId),
1694
- eq(agentGraph.id, params.graphId)
1695
- )
1696
- });
1697
- };
1698
1714
  var getAgentGraphById = (db) => async (params) => {
1699
1715
  const result = await db.query.agentGraph.findFirst({
1700
1716
  where: and(
1701
1717
  eq(agentGraph.tenantId, params.scopes.tenantId),
1702
1718
  eq(agentGraph.projectId, params.scopes.projectId),
1703
- eq(agentGraph.id, params.graphId)
1719
+ eq(agentGraph.id, params.scopes.graphId)
1704
1720
  )
1705
1721
  });
1706
1722
  return result ?? null;
@@ -1710,7 +1726,7 @@ var getAgentGraphWithDefaultAgent = (db) => async (params) => {
1710
1726
  where: and(
1711
1727
  eq(agentGraph.tenantId, params.scopes.tenantId),
1712
1728
  eq(agentGraph.projectId, params.scopes.projectId),
1713
- eq(agentGraph.id, params.graphId)
1729
+ eq(agentGraph.id, params.scopes.graphId)
1714
1730
  ),
1715
1731
  with: {
1716
1732
  defaultAgent: true
@@ -1803,7 +1819,7 @@ var updateAgentGraph = (db) => async (params) => {
1803
1819
  and(
1804
1820
  eq(agentGraph.tenantId, params.scopes.tenantId),
1805
1821
  eq(agentGraph.projectId, params.scopes.projectId),
1806
- eq(agentGraph.id, params.graphId)
1822
+ eq(agentGraph.id, params.scopes.graphId)
1807
1823
  )
1808
1824
  ).returning();
1809
1825
  return graph[0] ?? null;
@@ -1813,7 +1829,7 @@ var deleteAgentGraph = (db) => async (params) => {
1813
1829
  and(
1814
1830
  eq(agentGraph.tenantId, params.scopes.tenantId),
1815
1831
  eq(agentGraph.projectId, params.scopes.projectId),
1816
- eq(agentGraph.id, params.graphId)
1832
+ eq(agentGraph.id, params.scopes.graphId)
1817
1833
  )
1818
1834
  ).returning();
1819
1835
  return result.length > 0;
@@ -1840,17 +1856,14 @@ var getGraphAgentInfos = (db) => async ({
1840
1856
  agentId
1841
1857
  }) => {
1842
1858
  const { tenantId, projectId } = scopes;
1843
- const graph = await getAgentGraph(db)({
1844
- scopes: { tenantId, projectId },
1845
- graphId
1859
+ const graph = await getAgentGraphById(db)({
1860
+ scopes: { tenantId, projectId, graphId }
1846
1861
  });
1847
1862
  if (!graph) {
1848
1863
  throw new Error(`Agent graph with ID ${graphId} not found for tenant ${tenantId}`);
1849
1864
  }
1850
1865
  const relations = await getAgentRelations(db)({
1851
- scopes: { tenantId, projectId },
1852
- graphId,
1853
- agentId
1866
+ scopes: { tenantId, projectId, graphId, agentId }
1854
1867
  });
1855
1868
  const targetAgentIds = relations.map((relation) => relation.targetAgentId).filter((id) => id !== null);
1856
1869
  if (targetAgentIds.length === 0) {
@@ -1859,7 +1872,7 @@ var getGraphAgentInfos = (db) => async ({
1859
1872
  const agentInfos = await Promise.all(
1860
1873
  targetAgentIds.map(async (targetAgentId) => {
1861
1874
  const agent = await getAgentById(db)({
1862
- scopes: { tenantId, projectId },
1875
+ scopes: { tenantId, projectId, graphId },
1863
1876
  agentId: targetAgentId
1864
1877
  });
1865
1878
  if (agent !== void 0) {
@@ -1871,55 +1884,35 @@ var getGraphAgentInfos = (db) => async ({
1871
1884
  return agentInfos.filter((agent) => agent !== null);
1872
1885
  };
1873
1886
  var getFullGraphDefinition = (db) => async ({
1874
- scopes: { tenantId, projectId },
1875
- graphId
1887
+ scopes: { tenantId, projectId, graphId }
1876
1888
  }) => {
1877
1889
  const graph = await getAgentGraphById(db)({
1878
- scopes: { tenantId, projectId },
1879
- graphId
1890
+ scopes: { tenantId, projectId, graphId }
1880
1891
  });
1881
1892
  if (!graph) {
1882
1893
  return null;
1883
1894
  }
1884
1895
  const graphRelations = await getAgentRelationsByGraph(db)({
1885
- scopes: { tenantId, projectId },
1886
- graphId
1896
+ scopes: { tenantId, projectId, graphId }
1897
+ });
1898
+ const graphAgents = await db.query.agents.findMany({
1899
+ where: and(
1900
+ eq(agents.tenantId, tenantId),
1901
+ eq(agents.projectId, projectId),
1902
+ eq(agents.graphId, graphId)
1903
+ )
1887
1904
  });
1888
- const internalAgentIds = /* @__PURE__ */ new Set();
1889
1905
  const externalAgentIds = /* @__PURE__ */ new Set();
1890
- internalAgentIds.add(graph.defaultAgentId);
1891
1906
  for (const relation of graphRelations) {
1892
- if (relation.sourceAgentId) {
1893
- internalAgentIds.add(relation.sourceAgentId);
1894
- }
1895
- if (relation.targetAgentId) {
1896
- internalAgentIds.add(relation.targetAgentId);
1897
- }
1898
1907
  if (relation.externalAgentId) {
1899
1908
  externalAgentIds.add(relation.externalAgentId);
1900
1909
  }
1901
1910
  }
1902
- const agentsWithTools = await db.selectDistinct({ agentId: agentToolRelations.agentId }).from(agentToolRelations).innerJoin(tools, eq(agentToolRelations.toolId, tools.id)).where(
1903
- and(
1904
- eq(agentToolRelations.tenantId, tenantId),
1905
- eq(agentToolRelations.projectId, projectId),
1906
- // We need to find tools that belong to this graph
1907
- // Tools created as part of a graph have IDs that include the graph ID
1908
- like(tools.id, `%${graphId}%`)
1909
- )
1910
- );
1911
- for (const agentTool of agentsWithTools) {
1912
- internalAgentIds.add(agentTool.agentId);
1913
- }
1914
- const graphAgents = await Promise.all(
1915
- Array.from(internalAgentIds).map(async (agentId) => {
1916
- const agent = await getAgentById(db)({
1917
- scopes: { tenantId, projectId },
1918
- agentId
1919
- });
1911
+ const processedAgents = await Promise.all(
1912
+ graphAgents.map(async (agent) => {
1920
1913
  if (!agent) return null;
1921
1914
  const agentRelationsList = graphRelations.filter(
1922
- (relation) => relation.sourceAgentId === agentId
1915
+ (relation) => relation.sourceAgentId === agent.id
1923
1916
  );
1924
1917
  const canTransferTo = agentRelationsList.filter((rel) => rel.relationType === "transfer" || rel.relationType === "transfer_to").map((rel) => rel.targetAgentId).filter((id) => id !== null);
1925
1918
  const canDelegateTo = agentRelationsList.filter((rel) => rel.relationType === "delegate" || rel.relationType === "delegate_to").map((rel) => rel.targetAgentId || rel.externalAgentId).filter((id) => id !== null);
@@ -1936,19 +1929,19 @@ var getFullGraphDefinition = (db) => async ({
1936
1929
  lastToolsSync: tools.lastToolsSync,
1937
1930
  selectedTools: agentToolRelations.selectedTools
1938
1931
  }).from(agentToolRelations).innerJoin(tools, eq(agentToolRelations.toolId, tools.id)).where(
1939
- and(eq(agentToolRelations.tenantId, tenantId), eq(agentToolRelations.agentId, agentId))
1932
+ and(eq(agentToolRelations.tenantId, tenantId), eq(agentToolRelations.agentId, agent.id))
1940
1933
  );
1941
1934
  const agentDataComponentRelations = await db.query.agentDataComponents.findMany({
1942
1935
  where: and(
1943
1936
  eq(agentDataComponents.tenantId, tenantId),
1944
- eq(agentDataComponents.agentId, agentId)
1937
+ eq(agentDataComponents.agentId, agent.id)
1945
1938
  )
1946
1939
  });
1947
1940
  const agentDataComponentIds = agentDataComponentRelations.map((rel) => rel.dataComponentId);
1948
1941
  const agentArtifactComponentRelations = await db.query.agentArtifactComponents.findMany({
1949
1942
  where: and(
1950
1943
  eq(agentArtifactComponents.tenantId, tenantId),
1951
- eq(agentArtifactComponents.agentId, agentId)
1944
+ eq(agentArtifactComponents.agentId, agent.id)
1952
1945
  )
1953
1946
  });
1954
1947
  const agentArtifactComponentIds = agentArtifactComponentRelations.map(
@@ -1991,7 +1984,7 @@ var getFullGraphDefinition = (db) => async ({
1991
1984
  const externalAgents2 = await Promise.all(
1992
1985
  Array.from(externalAgentIds).map(async (agentId) => {
1993
1986
  const agent = await getExternalAgent(db)({
1994
- scopes: { tenantId, projectId },
1987
+ scopes: { tenantId, projectId, graphId },
1995
1988
  agentId
1996
1989
  });
1997
1990
  if (!agent) return null;
@@ -2003,7 +1996,7 @@ var getFullGraphDefinition = (db) => async ({
2003
1996
  };
2004
1997
  })
2005
1998
  );
2006
- const validAgents = [...graphAgents, ...externalAgents2].filter(
1999
+ const validAgents = [...processedAgents, ...externalAgents2].filter(
2007
2000
  (agent) => agent !== null
2008
2001
  );
2009
2002
  const agentsObject = {};
@@ -2049,6 +2042,7 @@ var getFullGraphDefinition = (db) => async ({
2049
2042
  }
2050
2043
  let dataComponentsObject = {};
2051
2044
  try {
2045
+ const internalAgentIds = graphAgents.map((agent) => agent.id);
2052
2046
  const agentIds = Array.from(internalAgentIds);
2053
2047
  dataComponentsObject = await fetchComponentRelationships(db)(
2054
2048
  { tenantId, projectId },
@@ -2071,6 +2065,7 @@ var getFullGraphDefinition = (db) => async ({
2071
2065
  }
2072
2066
  let artifactComponentsObject = {};
2073
2067
  try {
2068
+ const internalAgentIds = graphAgents.map((agent) => agent.id);
2074
2069
  const agentIds = Array.from(internalAgentIds);
2075
2070
  artifactComponentsObject = await fetchComponentRelationships(db)(
2076
2071
  { tenantId, projectId },
@@ -2177,16 +2172,14 @@ var getFullGraphDefinition = (db) => async ({
2177
2172
  return result;
2178
2173
  };
2179
2174
  var upsertAgentGraph = (db) => async (params) => {
2180
- const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId };
2181
2175
  const graphId = params.data.id || nanoid();
2176
+ const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId, graphId };
2182
2177
  const existing = await getAgentGraphById(db)({
2183
- scopes,
2184
- graphId
2178
+ scopes
2185
2179
  });
2186
2180
  if (existing) {
2187
2181
  return await updateAgentGraph(db)({
2188
2182
  scopes,
2189
- graphId,
2190
2183
  data: {
2191
2184
  name: params.data.name,
2192
2185
  defaultAgentId: params.data.defaultAgentId,
@@ -2532,7 +2525,8 @@ var getArtifactComponentsForAgent = (db) => async (params) => {
2532
2525
  and(
2533
2526
  eq(artifactComponents.tenantId, params.scopes.tenantId),
2534
2527
  eq(artifactComponents.projectId, params.scopes.projectId),
2535
- eq(agentArtifactComponents.agentId, params.agentId)
2528
+ eq(agentArtifactComponents.graphId, params.scopes.graphId),
2529
+ eq(agentArtifactComponents.agentId, params.scopes.agentId)
2536
2530
  )
2537
2531
  ).orderBy(desc(artifactComponents.createdAt));
2538
2532
  };
@@ -2541,7 +2535,8 @@ var associateArtifactComponentWithAgent = (db) => async (params) => {
2541
2535
  id: nanoid(),
2542
2536
  tenantId: params.scopes.tenantId,
2543
2537
  projectId: params.scopes.projectId,
2544
- agentId: params.agentId,
2538
+ graphId: params.scopes.graphId,
2539
+ agentId: params.scopes.agentId,
2545
2540
  artifactComponentId: params.artifactComponentId,
2546
2541
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
2547
2542
  }).returning();
@@ -2553,7 +2548,8 @@ var removeArtifactComponentFromAgent = (db) => async (params) => {
2553
2548
  and(
2554
2549
  eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
2555
2550
  eq(agentArtifactComponents.projectId, params.scopes.projectId),
2556
- eq(agentArtifactComponents.agentId, params.agentId),
2551
+ eq(agentArtifactComponents.graphId, params.scopes.graphId),
2552
+ eq(agentArtifactComponents.agentId, params.scopes.agentId),
2557
2553
  eq(agentArtifactComponents.artifactComponentId, params.artifactComponentId)
2558
2554
  )
2559
2555
  ).returning();
@@ -2567,13 +2563,15 @@ var deleteAgentArtifactComponentRelationByAgent = (db) => async (params) => {
2567
2563
  const result = await db.delete(agentArtifactComponents).where(
2568
2564
  and(
2569
2565
  eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
2570
- eq(agentArtifactComponents.agentId, params.agentId)
2566
+ eq(agentArtifactComponents.graphId, params.scopes.graphId),
2567
+ eq(agentArtifactComponents.agentId, params.scopes.agentId)
2571
2568
  )
2572
2569
  );
2573
2570
  return (result.rowsAffected || 0) > 0;
2574
2571
  };
2575
2572
  var getAgentsUsingArtifactComponent = (db) => async (params) => {
2576
2573
  return await db.select({
2574
+ graphId: agentArtifactComponents.graphId,
2577
2575
  agentId: agentArtifactComponents.agentId,
2578
2576
  createdAt: agentArtifactComponents.createdAt
2579
2577
  }).from(agentArtifactComponents).where(
@@ -2589,7 +2587,8 @@ var isArtifactComponentAssociatedWithAgent = (db) => async (params) => {
2589
2587
  and(
2590
2588
  eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
2591
2589
  eq(agentArtifactComponents.projectId, params.scopes.projectId),
2592
- eq(agentArtifactComponents.agentId, params.agentId),
2590
+ eq(agentArtifactComponents.graphId, params.scopes.graphId),
2591
+ eq(agentArtifactComponents.agentId, params.scopes.agentId),
2593
2592
  eq(agentArtifactComponents.artifactComponentId, params.artifactComponentId)
2594
2593
  )
2595
2594
  ).limit(1);
@@ -2600,7 +2599,7 @@ var graphHasArtifactComponents = (db) => async (params) => {
2600
2599
  and(
2601
2600
  eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
2602
2601
  eq(agentArtifactComponents.projectId, params.scopes.projectId),
2603
- eq(agentRelations.graphId, params.graphId)
2602
+ eq(agentRelations.graphId, params.scopes.graphId)
2604
2603
  )
2605
2604
  ).limit(1);
2606
2605
  const total = result[0]?.count || 0;
@@ -2622,7 +2621,8 @@ var countArtifactComponentsForAgent = (db) => async (params) => {
2622
2621
  and(
2623
2622
  eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
2624
2623
  eq(agentArtifactComponents.projectId, params.scopes.projectId),
2625
- eq(agentArtifactComponents.agentId, params.agentId)
2624
+ eq(agentArtifactComponents.graphId, params.scopes.graphId),
2625
+ eq(agentArtifactComponents.agentId, params.scopes.agentId)
2626
2626
  )
2627
2627
  );
2628
2628
  const total = result[0]?.count || 0;
@@ -3242,7 +3242,8 @@ var getDataComponentsForAgent = (db) => async (params) => {
3242
3242
  and(
3243
3243
  eq(dataComponents.tenantId, params.scopes.tenantId),
3244
3244
  eq(dataComponents.projectId, params.scopes.projectId),
3245
- eq(agentDataComponents.agentId, params.agentId)
3245
+ eq(agentDataComponents.graphId, params.scopes.graphId),
3246
+ eq(agentDataComponents.agentId, params.scopes.agentId)
3246
3247
  )
3247
3248
  ).orderBy(desc(dataComponents.createdAt));
3248
3249
  };
@@ -3251,7 +3252,8 @@ var associateDataComponentWithAgent = (db) => async (params) => {
3251
3252
  id: nanoid(),
3252
3253
  tenantId: params.scopes.tenantId,
3253
3254
  projectId: params.scopes.projectId,
3254
- agentId: params.agentId,
3255
+ graphId: params.scopes.graphId,
3256
+ agentId: params.scopes.agentId,
3255
3257
  dataComponentId: params.dataComponentId
3256
3258
  }).returning();
3257
3259
  return association[0];
@@ -3261,7 +3263,8 @@ var removeDataComponentFromAgent = (db) => async (params) => {
3261
3263
  and(
3262
3264
  eq(agentDataComponents.tenantId, params.scopes.tenantId),
3263
3265
  eq(agentDataComponents.projectId, params.scopes.projectId),
3264
- eq(agentDataComponents.agentId, params.agentId),
3266
+ eq(agentDataComponents.graphId, params.scopes.graphId),
3267
+ eq(agentDataComponents.agentId, params.scopes.agentId),
3265
3268
  eq(agentDataComponents.dataComponentId, params.dataComponentId)
3266
3269
  )
3267
3270
  ).returning();
@@ -3271,7 +3274,8 @@ var deleteAgentDataComponentRelationByAgent = (db) => async (params) => {
3271
3274
  const result = await db.delete(agentDataComponents).where(
3272
3275
  and(
3273
3276
  eq(agentDataComponents.tenantId, params.scopes.tenantId),
3274
- eq(agentDataComponents.agentId, params.agentId)
3277
+ eq(agentDataComponents.graphId, params.scopes.graphId),
3278
+ eq(agentDataComponents.agentId, params.scopes.agentId)
3275
3279
  )
3276
3280
  );
3277
3281
  return (result.rowsAffected || 0) > 0;
@@ -3293,7 +3297,8 @@ var isDataComponentAssociatedWithAgent = (db) => async (params) => {
3293
3297
  and(
3294
3298
  eq(agentDataComponents.tenantId, params.scopes.tenantId),
3295
3299
  eq(agentDataComponents.projectId, params.scopes.projectId),
3296
- eq(agentDataComponents.agentId, params.agentId),
3300
+ eq(agentDataComponents.graphId, params.scopes.graphId),
3301
+ eq(agentDataComponents.agentId, params.scopes.agentId),
3297
3302
  eq(agentDataComponents.dataComponentId, params.dataComponentId)
3298
3303
  )
3299
3304
  ).limit(1);
@@ -3454,6 +3459,7 @@ var addToolToAgent = (db) => async (params) => {
3454
3459
  id,
3455
3460
  tenantId: params.scopes.tenantId,
3456
3461
  projectId: params.scopes.projectId,
3462
+ graphId: params.scopes.graphId,
3457
3463
  agentId: params.agentId,
3458
3464
  toolId: params.toolId,
3459
3465
  selectedTools: params.selectedTools,
@@ -3467,6 +3473,7 @@ var removeToolFromAgent = (db) => async (params) => {
3467
3473
  and(
3468
3474
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
3469
3475
  eq(agentToolRelations.projectId, params.scopes.projectId),
3476
+ eq(agentToolRelations.graphId, params.scopes.graphId),
3470
3477
  eq(agentToolRelations.agentId, params.agentId),
3471
3478
  eq(agentToolRelations.toolId, params.toolId)
3472
3479
  )
@@ -3478,6 +3485,7 @@ var upsertAgentToolRelation = (db) => async (params) => {
3478
3485
  where: and(
3479
3486
  eq(agentToolRelations.tenantId, params.scopes.tenantId),
3480
3487
  eq(agentToolRelations.projectId, params.scopes.projectId),
3488
+ eq(agentToolRelations.graphId, params.scopes.graphId),
3481
3489
  eq(agentToolRelations.agentId, params.agentId),
3482
3490
  eq(agentToolRelations.toolId, params.toolId)
3483
3491
  )
@@ -3534,11 +3542,15 @@ var getHealthyToolsForAgent = (db) => async (params) => {
3534
3542
  }).from(tools).innerJoin(
3535
3543
  agentToolRelations,
3536
3544
  and(
3537
- eq(tools.id, agentToolRelations.toolId),
3538
- eq(agentToolRelations.agentId, params.agentId),
3539
- eq(agentToolRelations.tenantId, params.scopes.tenantId)
3545
+ eq(tools.tenantId, params.scopes.tenantId),
3546
+ eq(tools.projectId, params.scopes.projectId),
3547
+ eq(agentToolRelations.tenantId, params.scopes.tenantId),
3548
+ eq(agentToolRelations.projectId, params.scopes.projectId),
3549
+ eq(agentToolRelations.graphId, params.scopes.graphId),
3550
+ eq(agentToolRelations.agentId, params.scopes.agentId),
3551
+ eq(tools.id, agentToolRelations.toolId)
3540
3552
  )
3541
- ).where(and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.status, "healthy")));
3553
+ ).where(eq(tools.status, "healthy"));
3542
3554
  return healthyTools.map((row) => row.tool);
3543
3555
  };
3544
3556
 
@@ -3633,59 +3645,37 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
3633
3645
  validateGraphStructure(typed);
3634
3646
  await applyExecutionLimitsInheritance(db, logger11, { tenantId, projectId }, typed);
3635
3647
  try {
3636
- if (typed.credentialReferences && Object.keys(typed.credentialReferences).length > 0) {
3637
- logger11.info(
3638
- { credentialReferencesCount: Object.keys(typed.credentialReferences).length },
3639
- "Processing credential references"
3640
- );
3641
- const credentialRefPromises = Object.entries(typed.credentialReferences).map(
3642
- async ([_credId, credData]) => {
3643
- try {
3644
- logger11.info({ credId: credData.id }, "Processing credential reference");
3645
- await upsertCredentialReference(db)({
3646
- data: {
3647
- ...credData,
3648
- tenantId,
3649
- projectId
3650
- }
3651
- });
3652
- logger11.info({ credId: credData.id }, "Credential reference processed successfully");
3653
- } catch (error) {
3654
- logger11.error(
3655
- { credId: credData.id, error },
3656
- "Failed to create/update credential reference"
3657
- );
3658
- throw error;
3659
- }
3660
- }
3661
- );
3662
- await Promise.all(credentialRefPromises);
3663
- logger11.info(
3664
- { credentialReferencesCount: Object.keys(typed.credentialReferences).length },
3665
- "All credential references created/updated successfully"
3666
- );
3667
- }
3668
- const toolPromises = Object.entries(typed.tools || {}).map(async ([toolId, toolData]) => {
3669
- try {
3670
- logger11.info({ toolId }, "Processing tool");
3671
- await upsertTool(db)({
3672
- data: {
3673
- tenantId,
3674
- projectId,
3675
- ...toolData
3676
- }
3677
- });
3678
- logger11.info({ toolId }, "Tool processed successfully");
3679
- } catch (error) {
3680
- logger11.error({ toolId, error }, "Failed to create/update tool");
3681
- throw error;
3682
- }
3683
- });
3684
- await Promise.all(toolPromises);
3685
3648
  logger11.info(
3686
- { toolCount: Object.keys(typed.tools || {}).length },
3687
- "All tools created/updated successfully"
3649
+ {},
3650
+ "CredentialReferences are project-scoped - skipping credential reference creation in graph"
3688
3651
  );
3652
+ logger11.info({}, "Tools are project-scoped - skipping tool creation in graph");
3653
+ let finalGraphId;
3654
+ try {
3655
+ const graphId = typed.id || nanoid();
3656
+ logger11.info({ graphId }, "Creating agent graph metadata");
3657
+ const agentGraph2 = await upsertAgentGraph(db)({
3658
+ data: {
3659
+ id: graphId,
3660
+ tenantId,
3661
+ projectId,
3662
+ name: typed.name,
3663
+ defaultAgentId: typed.defaultAgentId,
3664
+ description: typed.description,
3665
+ contextConfigId: void 0,
3666
+ // Will be updated later if context config exists
3667
+ models: typed.models,
3668
+ statusUpdates: typed.statusUpdates,
3669
+ graphPrompt: typed.graphPrompt,
3670
+ stopWhen: typed.stopWhen
3671
+ }
3672
+ });
3673
+ finalGraphId = agentGraph2.id;
3674
+ logger11.info({ graphId: finalGraphId }, "Agent graph metadata created successfully");
3675
+ } catch (error) {
3676
+ logger11.error({ graphId: typed.id, error }, "Failed to create/update graph metadata");
3677
+ throw error;
3678
+ }
3689
3679
  let contextConfigId;
3690
3680
  if (typed.contextConfig) {
3691
3681
  try {
@@ -3707,66 +3697,14 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
3707
3697
  throw error;
3708
3698
  }
3709
3699
  }
3710
- if (typed.dataComponents && Object.keys(typed.dataComponents).length > 0) {
3711
- const dataComponentPromises = Object.entries(typed.dataComponents).map(
3712
- async ([dataComponentId, dataComponentData]) => {
3713
- try {
3714
- logger11.info({ dataComponentId }, "Processing data component");
3715
- await upsertDataComponent(db)({
3716
- data: {
3717
- id: dataComponentId,
3718
- tenantId,
3719
- projectId,
3720
- name: dataComponentData.name,
3721
- description: dataComponentData.description || "",
3722
- props: dataComponentData.props || {}
3723
- }
3724
- });
3725
- logger11.info({ dataComponentId }, "Data component processed successfully");
3726
- } catch (error) {
3727
- logger11.error({ dataComponentId, error }, "Failed to create/update dataComponent");
3728
- throw error;
3729
- }
3730
- }
3731
- );
3732
- await Promise.all(dataComponentPromises);
3733
- logger11.info(
3734
- { dataComponentCount: Object.keys(typed.dataComponents).length },
3735
- "All dataComponents created/updated successfully"
3736
- );
3737
- }
3738
- if (typed.artifactComponents && Object.keys(typed.artifactComponents).length > 0) {
3739
- const artifactComponentPromises = Object.entries(typed.artifactComponents).map(
3740
- async ([artifactComponentId, artifactComponentData]) => {
3741
- try {
3742
- logger11.info({ artifactComponentId }, "Processing artifact component");
3743
- await upsertArtifactComponent(db)({
3744
- data: {
3745
- id: artifactComponentId,
3746
- tenantId,
3747
- projectId,
3748
- name: artifactComponentData.name,
3749
- description: artifactComponentData.description || "",
3750
- summaryProps: artifactComponentData.summaryProps || {},
3751
- fullProps: artifactComponentData.fullProps || {}
3752
- }
3753
- });
3754
- logger11.info({ artifactComponentId }, "Artifact component processed successfully");
3755
- } catch (error) {
3756
- logger11.error(
3757
- { artifactComponentId, error },
3758
- "Failed to create/update artifactComponent"
3759
- );
3760
- throw error;
3761
- }
3762
- }
3763
- );
3764
- await Promise.all(artifactComponentPromises);
3765
- logger11.info(
3766
- { artifactComponentCount: Object.keys(typed.artifactComponents).length },
3767
- "All artifactComponents created/updated successfully"
3768
- );
3769
- }
3700
+ logger11.info(
3701
+ {},
3702
+ "DataComponents are project-scoped - skipping dataComponent creation in graph"
3703
+ );
3704
+ logger11.info(
3705
+ {},
3706
+ "ArtifactComponents are project-scoped - skipping artifactComponent creation in graph"
3707
+ );
3770
3708
  const internalAgentPromises = Object.entries(typed.agents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([agentId, agentData]) => {
3771
3709
  const internalAgent = agentData;
3772
3710
  try {
@@ -3776,6 +3714,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
3776
3714
  id: agentId,
3777
3715
  tenantId,
3778
3716
  projectId,
3717
+ graphId: finalGraphId,
3779
3718
  name: internalAgent.name || "",
3780
3719
  description: internalAgent.description || "",
3781
3720
  prompt: internalAgent.prompt || "",
@@ -3804,6 +3743,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
3804
3743
  id: agentId,
3805
3744
  tenantId,
3806
3745
  projectId,
3746
+ graphId: finalGraphId,
3807
3747
  name: externalAgent.name,
3808
3748
  description: externalAgent.description || "",
3809
3749
  baseUrl: externalAgent.baseUrl,
@@ -3822,29 +3762,24 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
3822
3762
  ([_, agentData]) => isExternalAgent(agentData)
3823
3763
  ).length;
3824
3764
  logger11.info({ externalAgentCount }, "All external agents created/updated successfully");
3825
- let finalGraphId;
3826
- try {
3827
- logger11.info({ graphId: typed.id }, "Processing agent graph metadata");
3828
- const agentGraph2 = await upsertAgentGraph(db)({
3829
- data: {
3830
- id: typed.id || nanoid(),
3831
- tenantId,
3832
- projectId,
3833
- name: typed.name,
3834
- defaultAgentId: typed.defaultAgentId,
3835
- description: typed.description,
3836
- contextConfigId,
3837
- models: typed.models,
3838
- statusUpdates: typed.statusUpdates,
3839
- graphPrompt: typed.graphPrompt,
3840
- stopWhen: typed.stopWhen
3841
- }
3842
- });
3843
- finalGraphId = agentGraph2.id;
3844
- logger11.info({ graphId: finalGraphId }, "Agent graph metadata processed successfully");
3845
- } catch (error) {
3846
- logger11.error({ graphId: typed.id, error }, "Failed to create/update graph metadata");
3847
- throw error;
3765
+ if (contextConfigId) {
3766
+ try {
3767
+ logger11.info(
3768
+ { graphId: finalGraphId, contextConfigId },
3769
+ "Updating graph with context config"
3770
+ );
3771
+ await updateAgentGraph(db)({
3772
+ scopes: { tenantId, projectId, graphId: finalGraphId },
3773
+ data: { contextConfigId }
3774
+ });
3775
+ logger11.info({ graphId: finalGraphId }, "Graph updated with context config");
3776
+ } catch (error) {
3777
+ logger11.error(
3778
+ { graphId: finalGraphId, error },
3779
+ "Failed to update graph with context config"
3780
+ );
3781
+ throw error;
3782
+ }
3848
3783
  }
3849
3784
  const agentToolPromises = [];
3850
3785
  for (const [agentId, agentData] of Object.entries(typed.agents)) {
@@ -3856,7 +3791,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
3856
3791
  const selectedTools = agentData.selectedTools?.[toolId];
3857
3792
  logger11.info({ agentId, toolId }, "Processing agent-tool relation");
3858
3793
  await upsertAgentToolRelation(db)({
3859
- scopes: { tenantId, projectId },
3794
+ scopes: { tenantId, projectId, graphId: finalGraphId },
3860
3795
  agentId,
3861
3796
  toolId,
3862
3797
  selectedTools
@@ -3887,8 +3822,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
3887
3822
  "Processing agent-data component relation"
3888
3823
  );
3889
3824
  await upsertAgentDataComponentRelation(db)({
3890
- scopes: { tenantId, projectId },
3891
- agentId,
3825
+ scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
3892
3826
  dataComponentId
3893
3827
  });
3894
3828
  logger11.info(
@@ -3920,8 +3854,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
3920
3854
  "Processing agent-artifact component relation"
3921
3855
  );
3922
3856
  await upsertAgentArtifactComponentRelation(db)({
3923
- scopes: { tenantId, projectId },
3924
- agentId,
3857
+ scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
3925
3858
  artifactComponentId
3926
3859
  });
3927
3860
  logger11.info(
@@ -4017,8 +3950,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4017
3950
  "All agent relations created"
4018
3951
  );
4019
3952
  const createdGraph = await getFullGraphDefinition(db)({
4020
- scopes: { tenantId, projectId },
4021
- graphId: finalGraphId
3953
+ scopes: { tenantId, projectId, graphId: finalGraphId }
4022
3954
  });
4023
3955
  if (!createdGraph) {
4024
3956
  throw new Error("Failed to retrieve created graph");
@@ -4041,8 +3973,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4041
3973
  {
4042
3974
  tenantId,
4043
3975
  graphId: typedGraphDefinition.id,
4044
- agentCount: Object.keys(typedGraphDefinition.agents).length,
4045
- toolCount: Object.keys(typedGraphDefinition.tools || {}).length
3976
+ agentCount: Object.keys(typedGraphDefinition.agents).length
4046
3977
  },
4047
3978
  "Updating full graph in database"
4048
3979
  );
@@ -4055,8 +3986,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4055
3986
  );
4056
3987
  try {
4057
3988
  const existingGraph = await getAgentGraphById(db)({
4058
- scopes: { tenantId, projectId },
4059
- graphId: typedGraphDefinition.id
3989
+ scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
4060
3990
  });
4061
3991
  if (!existingGraph) {
4062
3992
  logger11.info(
@@ -4066,65 +3996,40 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4066
3996
  return createFullGraphServerSide(db)(scopes, graphData);
4067
3997
  }
4068
3998
  const existingGraphModels = existingGraph.models;
4069
- if (typedGraphDefinition.credentialReferences && Object.keys(typedGraphDefinition.credentialReferences).length > 0) {
4070
- logger11.info(
4071
- {
4072
- credentialReferencesCount: Object.keys(typedGraphDefinition.credentialReferences).length
4073
- },
4074
- "Processing credential references"
4075
- );
4076
- const credentialRefPromises = Object.entries(typedGraphDefinition.credentialReferences).map(
4077
- async ([_credId, credData]) => {
4078
- try {
4079
- logger11.info({ credId: credData.id }, "Processing credential reference");
4080
- await upsertCredentialReference(db)({
4081
- data: {
4082
- ...credData,
4083
- tenantId,
4084
- projectId
4085
- }
4086
- });
4087
- logger11.info({ credId: credData.id }, "Credential reference processed successfully");
4088
- } catch (error) {
4089
- logger11.error(
4090
- { credId: credData.id, error },
4091
- "Failed to create/update credential reference"
4092
- );
4093
- throw error;
4094
- }
3999
+ logger11.info(
4000
+ {},
4001
+ "CredentialReferences are project-scoped - skipping credential reference update in graph"
4002
+ );
4003
+ logger11.info({}, "Tools are project-scoped - skipping tool creation in graph update");
4004
+ let finalGraphId;
4005
+ try {
4006
+ const graphId = typedGraphDefinition.id || nanoid();
4007
+ logger11.info({ graphId }, "Getting/creating agent graph metadata");
4008
+ const agentGraph2 = await upsertAgentGraph(db)({
4009
+ data: {
4010
+ id: graphId,
4011
+ tenantId,
4012
+ projectId,
4013
+ name: typedGraphDefinition.name,
4014
+ defaultAgentId: typedGraphDefinition.defaultAgentId,
4015
+ description: typedGraphDefinition.description,
4016
+ contextConfigId: void 0,
4017
+ // Will be updated later if context config exists
4018
+ models: typedGraphDefinition.models,
4019
+ statusUpdates: typedGraphDefinition.statusUpdates,
4020
+ graphPrompt: typedGraphDefinition.graphPrompt,
4021
+ stopWhen: typedGraphDefinition.stopWhen
4095
4022
  }
4023
+ });
4024
+ finalGraphId = agentGraph2.id;
4025
+ logger11.info({ graphId: finalGraphId }, "Agent graph metadata ready");
4026
+ } catch (error) {
4027
+ logger11.error(
4028
+ { graphId: typedGraphDefinition.id, error },
4029
+ "Failed to get/update graph metadata"
4096
4030
  );
4097
- await Promise.all(credentialRefPromises);
4098
- logger11.info(
4099
- {
4100
- credentialReferencesCount: Object.keys(typedGraphDefinition.credentialReferences).length
4101
- },
4102
- "All credential references created/updated successfully"
4103
- );
4031
+ throw error;
4104
4032
  }
4105
- const toolPromises = Object.entries(typedGraphDefinition.tools || {}).map(
4106
- async ([toolId, toolData]) => {
4107
- try {
4108
- logger11.info({ toolId }, "Processing tool");
4109
- await upsertTool(db)({
4110
- data: {
4111
- tenantId,
4112
- projectId,
4113
- ...toolData
4114
- }
4115
- });
4116
- logger11.info({ toolId }, "Tool processed successfully");
4117
- } catch (error) {
4118
- logger11.error({ toolId, error }, "Failed to create/update tool");
4119
- throw error;
4120
- }
4121
- }
4122
- );
4123
- await Promise.all(toolPromises);
4124
- logger11.info(
4125
- { toolCount: Object.keys(typedGraphDefinition.tools || {}).length },
4126
- "All tools created/updated successfully"
4127
- );
4128
4033
  let contextConfigId;
4129
4034
  if (typedGraphDefinition.contextConfig) {
4130
4035
  try {
@@ -4149,66 +4054,11 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4149
4054
  throw error;
4150
4055
  }
4151
4056
  }
4152
- if (typedGraphDefinition.dataComponents && Object.keys(typedGraphDefinition.dataComponents).length > 0) {
4153
- const dataComponentPromises = Object.entries(typedGraphDefinition.dataComponents).map(
4154
- async ([dataComponentId, dataComponentData]) => {
4155
- try {
4156
- logger11.info({ dataComponentId }, "Processing data component");
4157
- await upsertDataComponent(db)({
4158
- data: {
4159
- id: dataComponentId,
4160
- tenantId,
4161
- projectId,
4162
- name: dataComponentData.name,
4163
- description: dataComponentData.description || "",
4164
- props: dataComponentData.props || {}
4165
- }
4166
- });
4167
- logger11.info({ dataComponentId }, "Data component processed successfully");
4168
- } catch (error) {
4169
- logger11.error({ dataComponentId, error }, "Failed to create/update dataComponent");
4170
- throw error;
4171
- }
4172
- }
4173
- );
4174
- await Promise.all(dataComponentPromises);
4175
- logger11.info(
4176
- { dataComponentCount: Object.keys(typedGraphDefinition.dataComponents).length },
4177
- "All dataComponents created/updated successfully"
4178
- );
4179
- }
4180
- if (typedGraphDefinition.artifactComponents && Object.keys(typedGraphDefinition.artifactComponents).length > 0) {
4181
- const artifactComponentPromises = Object.entries(
4182
- typedGraphDefinition.artifactComponents
4183
- ).map(async ([artifactComponentId, artifactComponentData]) => {
4184
- try {
4185
- logger11.info({ artifactComponentId }, "Processing artifact component");
4186
- await upsertArtifactComponent(db)({
4187
- data: {
4188
- id: artifactComponentId,
4189
- tenantId,
4190
- projectId,
4191
- name: artifactComponentData.name,
4192
- description: artifactComponentData.description || "",
4193
- summaryProps: artifactComponentData.summaryProps || {},
4194
- fullProps: artifactComponentData.fullProps || {}
4195
- }
4196
- });
4197
- logger11.info({ artifactComponentId }, "Artifact component processed successfully");
4198
- } catch (error) {
4199
- logger11.error(
4200
- { artifactComponentId, error },
4201
- "Failed to create/update artifactComponent"
4202
- );
4203
- throw error;
4204
- }
4205
- });
4206
- await Promise.all(artifactComponentPromises);
4207
- logger11.info(
4208
- { artifactComponentCount: Object.keys(typedGraphDefinition.artifactComponents).length },
4209
- "All artifactComponents created/updated successfully"
4210
- );
4211
- }
4057
+ logger11.info({}, "DataComponents are project-scoped - skipping dataComponent update in graph");
4058
+ logger11.info(
4059
+ {},
4060
+ "ArtifactComponents are project-scoped - skipping artifactComponent update in graph"
4061
+ );
4212
4062
  const internalAgentPromises = Object.entries(typedGraphDefinition.agents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([agentId, agentData]) => {
4213
4063
  const internalAgent = agentData;
4214
4064
  let existingAgent = null;
@@ -4257,6 +4107,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4257
4107
  id: agentId,
4258
4108
  tenantId,
4259
4109
  projectId,
4110
+ graphId: finalGraphId,
4260
4111
  name: internalAgent.name || "",
4261
4112
  description: internalAgent.description || "",
4262
4113
  prompt: internalAgent.prompt || "",
@@ -4285,6 +4136,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4285
4136
  id: agentId,
4286
4137
  tenantId,
4287
4138
  projectId,
4139
+ graphId: finalGraphId,
4288
4140
  name: externalAgent.name,
4289
4141
  description: externalAgent.description || "",
4290
4142
  baseUrl: externalAgent.baseUrl,
@@ -4304,8 +4156,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4304
4156
  ).length;
4305
4157
  logger11.info({ externalAgentCount }, "All external agents created/updated successfully");
4306
4158
  await updateAgentGraph(db)({
4307
- scopes: { tenantId, projectId },
4308
- graphId: typedGraphDefinition.id,
4159
+ scopes: { tenantId, projectId, graphId: typedGraphDefinition.id },
4309
4160
  data: {
4310
4161
  name: typedGraphDefinition.name,
4311
4162
  defaultAgentId: typedGraphDefinition.defaultAgentId,
@@ -4320,8 +4171,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4320
4171
  logger11.info({ graphId: typedGraphDefinition.id }, "Graph metadata updated");
4321
4172
  for (const agentId of Object.keys(typedGraphDefinition.agents)) {
4322
4173
  await deleteAgentToolRelationByAgent(db)({
4323
- scopes: { tenantId, projectId },
4324
- agentId
4174
+ scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
4325
4175
  });
4326
4176
  }
4327
4177
  const agentToolPromises = [];
@@ -4333,7 +4183,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4333
4183
  try {
4334
4184
  const selectedTools = agentData.selectedTools?.[toolId];
4335
4185
  await createAgentToolRelation(db)({
4336
- scopes: { tenantId, projectId },
4186
+ scopes: { tenantId, projectId, graphId: finalGraphId },
4337
4187
  data: {
4338
4188
  agentId,
4339
4189
  toolId,
@@ -4356,8 +4206,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4356
4206
  );
4357
4207
  for (const agentId of Object.keys(typedGraphDefinition.agents)) {
4358
4208
  await deleteAgentDataComponentRelationByAgent(db)({
4359
- scopes: { tenantId, projectId },
4360
- agentId
4209
+ scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
4361
4210
  });
4362
4211
  }
4363
4212
  const agentDataComponentPromises = [];
@@ -4368,8 +4217,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4368
4217
  (async () => {
4369
4218
  try {
4370
4219
  await associateDataComponentWithAgent(db)({
4371
- scopes: { tenantId, projectId },
4372
- agentId,
4220
+ scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
4373
4221
  dataComponentId
4374
4222
  });
4375
4223
  logger11.info({ agentId, dataComponentId }, "Agent-dataComponent relation created");
@@ -4391,8 +4239,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4391
4239
  );
4392
4240
  for (const agentId of Object.keys(typedGraphDefinition.agents)) {
4393
4241
  await deleteAgentArtifactComponentRelationByAgent(db)({
4394
- scopes: { tenantId, projectId },
4395
- agentId
4242
+ scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
4396
4243
  });
4397
4244
  }
4398
4245
  const agentArtifactComponentPromises = [];
@@ -4403,8 +4250,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4403
4250
  (async () => {
4404
4251
  try {
4405
4252
  await associateArtifactComponentWithAgent(db)({
4406
- scopes: { tenantId, projectId },
4407
- agentId,
4253
+ scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
4408
4254
  artifactComponentId
4409
4255
  });
4410
4256
  logger11.info(
@@ -4428,8 +4274,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4428
4274
  "All agent-artifactComponent relations updated"
4429
4275
  );
4430
4276
  await deleteAgentRelationsByGraph(db)({
4431
- scopes: { tenantId, projectId },
4432
- graphId: typedGraphDefinition.id
4277
+ scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
4433
4278
  });
4434
4279
  const agentRelationPromises = [];
4435
4280
  for (const [agentId, agentData] of Object.entries(typedGraphDefinition.agents)) {
@@ -4505,8 +4350,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4505
4350
  "All agent relations updated"
4506
4351
  );
4507
4352
  const updatedGraph = await getFullGraphDefinition(db)({
4508
- scopes: { tenantId, projectId },
4509
- graphId: typedGraphDefinition.id
4353
+ scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
4510
4354
  });
4511
4355
  if (!updatedGraph) {
4512
4356
  throw new Error("Failed to retrieve updated graph");
@@ -4519,22 +4363,21 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
4519
4363
  }
4520
4364
  };
4521
4365
  var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
4522
- const { scopes, graphId } = params;
4366
+ const { scopes } = params;
4523
4367
  const { tenantId, projectId } = scopes;
4524
- logger11.info({ tenantId, graphId }, "Retrieving full graph definition");
4368
+ logger11.info({ tenantId, graphId: scopes.graphId }, "Retrieving full graph definition");
4525
4369
  try {
4526
4370
  const graph = await getFullGraphDefinition(db)({
4527
- scopes: { tenantId, projectId },
4528
- graphId
4371
+ scopes: { tenantId, projectId, graphId: scopes.graphId }
4529
4372
  });
4530
4373
  if (!graph) {
4531
- logger11.info({ tenantId, graphId }, "Graph not found");
4374
+ logger11.info({ tenantId, graphId: scopes.graphId }, "Graph not found");
4532
4375
  return null;
4533
4376
  }
4534
4377
  logger11.info(
4535
4378
  {
4536
4379
  tenantId,
4537
- graphId,
4380
+ graphId: scopes.graphId,
4538
4381
  agentCount: Object.keys(graph.agents).length
4539
4382
  },
4540
4383
  "Full graph retrieved successfully"
@@ -4544,7 +4387,7 @@ var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
4544
4387
  logger11.error(
4545
4388
  {
4546
4389
  tenantId,
4547
- graphId,
4390
+ graphId: scopes.graphId,
4548
4391
  error: error instanceof Error ? error.message : "Unknown error"
4549
4392
  },
4550
4393
  "Failed to retrieve full graph"
@@ -4553,29 +4396,25 @@ var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
4553
4396
  }
4554
4397
  };
4555
4398
  var deleteFullGraph = (db, logger11 = defaultLogger) => async (params) => {
4556
- const { scopes, graphId } = params;
4557
- const { tenantId, projectId } = scopes;
4399
+ const { tenantId, projectId, graphId } = params.scopes;
4558
4400
  logger11.info({ tenantId, graphId }, "Deleting full graph and related entities");
4559
4401
  try {
4560
4402
  const graph = await getFullGraphDefinition(db)({
4561
- scopes: { tenantId, projectId },
4562
- graphId
4403
+ scopes: { tenantId, projectId, graphId }
4563
4404
  });
4564
4405
  if (!graph) {
4565
4406
  logger11.info({ tenantId, graphId }, "Graph not found for deletion");
4566
4407
  return false;
4567
4408
  }
4568
4409
  await deleteAgentRelationsByGraph(db)({
4569
- scopes: { tenantId, projectId },
4570
- graphId
4410
+ scopes: { tenantId, projectId, graphId }
4571
4411
  });
4572
4412
  logger11.info({ tenantId, graphId }, "Agent relations deleted");
4573
4413
  const agentIds = Object.keys(graph.agents);
4574
4414
  if (agentIds.length > 0) {
4575
4415
  for (const agentId of agentIds) {
4576
4416
  await deleteAgentToolRelationByAgent(db)({
4577
- scopes: { tenantId, projectId },
4578
- agentId
4417
+ scopes: { tenantId, projectId, graphId, agentId }
4579
4418
  });
4580
4419
  }
4581
4420
  logger11.info(
@@ -4584,8 +4423,7 @@ var deleteFullGraph = (db, logger11 = defaultLogger) => async (params) => {
4584
4423
  );
4585
4424
  }
4586
4425
  await deleteAgentGraph(db)({
4587
- scopes: { tenantId, projectId },
4588
- graphId
4426
+ scopes: { tenantId, projectId, graphId }
4589
4427
  });
4590
4428
  logger11.info({ tenantId, graphId }, "Graph metadata deleted");
4591
4429
  logger11.info({ tenantId, graphId }, "Full graph deleted successfully");
@@ -5294,8 +5132,7 @@ var createFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
5294
5132
  db,
5295
5133
  logger11
5296
5134
  )({
5297
- scopes: { tenantId, projectId: typed.id },
5298
- projectId: typed.id
5135
+ scopes: { tenantId, projectId: typed.id }
5299
5136
  });
5300
5137
  } catch (error) {
5301
5138
  logger11.error(
@@ -5601,8 +5438,7 @@ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
5601
5438
  db,
5602
5439
  logger11
5603
5440
  )({
5604
- scopes: { tenantId, projectId: typed.id },
5605
- projectId: typed.id
5441
+ scopes: { tenantId, projectId: typed.id }
5606
5442
  });
5607
5443
  } catch (error) {
5608
5444
  logger11.error(
@@ -5617,8 +5453,8 @@ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
5617
5453
  }
5618
5454
  };
5619
5455
  var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
5620
- const { scopes, projectId } = params;
5621
- const { tenantId } = scopes;
5456
+ const { scopes } = params;
5457
+ const { tenantId, projectId } = scopes;
5622
5458
  logger11.info({ tenantId, projectId }, "Retrieving full project definition");
5623
5459
  try {
5624
5460
  const project = await getProject(db)({
@@ -5772,18 +5608,10 @@ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
5772
5608
  "Retrieving full graph definition"
5773
5609
  );
5774
5610
  const fullGraph = await getFullGraph(db)({
5775
- scopes: { tenantId, projectId },
5776
- graphId: graph.id
5611
+ scopes: { tenantId, projectId, graphId: graph.id }
5777
5612
  });
5778
5613
  if (fullGraph) {
5779
- const {
5780
- tools: _tools,
5781
- dataComponents: _dataComponents,
5782
- artifactComponents: _artifactComponents,
5783
- contextConfig: _contextConfig,
5784
- credentialReferences: _credentialReferences,
5785
- ...graphWithoutProjectResources
5786
- } = fullGraph;
5614
+ const { contextConfig: _contextConfig, ...graphWithoutProjectResources } = fullGraph;
5787
5615
  graphs[graph.id] = graphWithoutProjectResources;
5788
5616
  logger11.info(
5789
5617
  { tenantId, projectId, graphId: graph.id },
@@ -5838,16 +5666,15 @@ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
5838
5666
  }
5839
5667
  };
5840
5668
  var deleteFullProject = (db, logger11 = defaultLogger2) => async (params) => {
5841
- const { scopes, projectId } = params;
5842
- const { tenantId } = scopes;
5669
+ const { scopes } = params;
5670
+ const { tenantId, projectId } = scopes;
5843
5671
  logger11.info({ tenantId, projectId }, "Deleting full project and related entities");
5844
5672
  try {
5845
5673
  const project = await getFullProject(
5846
5674
  db,
5847
5675
  logger11
5848
5676
  )({
5849
- scopes: { tenantId, projectId },
5850
- projectId
5677
+ scopes: { tenantId, projectId }
5851
5678
  });
5852
5679
  if (!project) {
5853
5680
  logger11.info({ tenantId, projectId }, "Project not found for deletion");
@@ -5869,8 +5696,7 @@ var deleteFullProject = (db, logger11 = defaultLogger2) => async (params) => {
5869
5696
  db,
5870
5697
  logger11
5871
5698
  )({
5872
- scopes: { tenantId, projectId },
5873
- graphId
5699
+ scopes: { tenantId, projectId, graphId }
5874
5700
  });
5875
5701
  logger11.info(
5876
5702
  { tenantId, projectId, graphId },
@@ -7285,8 +7111,7 @@ async function validateRequestContext({
7285
7111
  }) {
7286
7112
  try {
7287
7113
  const agentGraph2 = await getAgentGraphWithDefaultAgent(dbClient)({
7288
- scopes: { tenantId, projectId },
7289
- graphId
7114
+ scopes: { tenantId, projectId, graphId }
7290
7115
  });
7291
7116
  if (!agentGraph2?.contextConfigId) {
7292
7117
  logger7.debug({ graphId }, "No context config found for graph, skipping validation");
@@ -7426,13 +7251,11 @@ function contextValidationMiddleware(dbClient) {
7426
7251
  },
7427
7252
  "Request context validation failed"
7428
7253
  );
7429
- return c.json(
7430
- {
7431
- error: "Invalid request context",
7432
- details: validationResult.errors
7433
- },
7434
- 400
7435
- );
7254
+ const errorMessage = `Invalid request context: ${validationResult.errors.map((e) => `${e.field}: ${e.message}`).join(", ")}`;
7255
+ throw createApiError({
7256
+ code: "bad_request",
7257
+ message: errorMessage
7258
+ });
7436
7259
  }
7437
7260
  c.set("validatedContext", validationResult.validatedContext);
7438
7261
  logger7.debug(
@@ -7451,13 +7274,10 @@ function contextValidationMiddleware(dbClient) {
7451
7274
  },
7452
7275
  "Context validation middleware error"
7453
7276
  );
7454
- return c.json(
7455
- {
7456
- error: "Context validation failed",
7457
- message: "Internal validation error"
7458
- },
7459
- 500
7460
- );
7277
+ throw createApiError({
7278
+ code: "internal_server_error",
7279
+ message: "Context validation failed"
7280
+ });
7461
7281
  }
7462
7282
  };
7463
7283
  }
@@ -7833,7 +7653,15 @@ async function handleContextConfigChange(tenantId, projectId, conversationId, gr
7833
7653
  );
7834
7654
  }
7835
7655
  }
7836
- async function handleContextResolution(tenantId, projectId, conversationId, graphId, requestContext, dbClient, credentialStores) {
7656
+ async function handleContextResolution({
7657
+ tenantId,
7658
+ projectId,
7659
+ graphId,
7660
+ conversationId,
7661
+ requestContext,
7662
+ dbClient,
7663
+ credentialStores
7664
+ }) {
7837
7665
  return tracer.startActiveSpan(
7838
7666
  "context.handle_context_resolution",
7839
7667
  {
@@ -7846,8 +7674,7 @@ async function handleContextResolution(tenantId, projectId, conversationId, grap
7846
7674
  let trigger;
7847
7675
  try {
7848
7676
  agentGraph2 = await getAgentGraphWithDefaultAgent(dbClient)({
7849
- scopes: { tenantId, projectId },
7850
- graphId
7677
+ scopes: { tenantId, projectId, graphId }
7851
7678
  });
7852
7679
  if (!agentGraph2?.contextConfigId) {
7853
7680
  logger9.debug({ graphId }, "No context config found for graph");
@@ -8570,12 +8397,13 @@ var loadEnvironmentFiles = () => {
8570
8397
  }
8571
8398
  const userConfigPath = path.join(os.homedir(), ".inkeep", "config");
8572
8399
  if (fs.existsSync(userConfigPath)) {
8573
- dotenv.config({ path: userConfigPath, override: true });
8400
+ dotenv.config({ path: userConfigPath, override: true, quiet: true });
8574
8401
  }
8575
8402
  if (environmentFiles.length > 0) {
8576
8403
  dotenv.config({
8577
8404
  path: environmentFiles,
8578
- override: false
8405
+ override: false,
8406
+ quiet: true
8579
8407
  });
8580
8408
  expand({ processEnv: process.env });
8581
8409
  }
@@ -8603,4 +8431,4 @@ ${error.message}`
8603
8431
  };
8604
8432
  parseEnv();
8605
8433
 
8606
- export { ConsoleLogger, ContextCache, ContextConfigBuilder, ContextFetcher, ContextResolver, CredentialStoreRegistry, CredentialStuffer, ERROR_DOCS_BASE_URL, ErrorCode, HTTP_REQUEST_PARTS, InMemoryCredentialStore, KeyChainStore, McpClient, NangoCredentialStore, NoOpLogger, TemplateEngine, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, configureLogging, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createKeyChainStore, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraph, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentInGraphContext, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getHealthyToolsForAgent, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsByStatus, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgentToolRelationsByAgent, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, listToolsByStatus, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, updateToolStatus, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };
8434
+ export { ConsoleLogger, ContextCache, ContextConfigBuilder, ContextFetcher, ContextResolver, CredentialStoreRegistry, CredentialStuffer, ERROR_DOCS_BASE_URL, ErrorCode, HTTP_REQUEST_PARTS, InMemoryCredentialStore, KeyChainStore, McpClient, NangoCredentialStore, NoOpLogger, TemplateEngine, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, configureLogging, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createKeyChainStore, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getHealthyToolsForAgent, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsByStatus, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, listToolsByStatus, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, updateToolStatus, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };