@inkeep/agents-core 0.2.2 → 0.5.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/{chunk-MXQKLGQK.js → chunk-LFWFXR4O.js} +123 -82
- package/dist/{chunk-KNC2AOJM.js → chunk-LPIKPCE5.js} +76 -29
- package/dist/{chunk-BAPMUHVN.js → chunk-XQRFKXVV.js} +20 -12
- package/dist/client-exports.cjs +195 -111
- package/dist/client-exports.js +4 -5
- package/dist/db/schema.cjs +121 -80
- package/dist/db/schema.js +1 -1
- package/dist/index.cjs +650 -644
- package/dist/index.js +436 -527
- package/dist/validation/index.cjs +213 -118
- package/dist/validation/index.js +2 -2
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { validateAndTypeGraphData, validateGraphStructure, isInternalAgent, isExternalAgent } from './chunk-
|
|
2
|
-
export { generateIdFromName, isExternalAgent, isInternalAgent, isValidResourceId, validateAgentRelationships, validateAndTypeGraphData, validateArtifactComponentReferences, validateDataComponentReferences, validateGraphStructure, validateToolReferences } from './chunk-
|
|
3
|
-
import { ContextConfigApiUpdateSchema } from './chunk-
|
|
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-
|
|
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';
|
|
1
|
+
import { validateAndTypeGraphData, validateGraphStructure, isInternalAgent, isExternalAgent } from './chunk-XQRFKXVV.js';
|
|
2
|
+
export { generateIdFromName, isExternalAgent, isInternalAgent, isValidResourceId, validateAgentRelationships, validateAndTypeGraphData, validateArtifactComponentReferences, validateDataComponentReferences, validateGraphStructure, validateToolReferences } from './chunk-XQRFKXVV.js';
|
|
3
|
+
import { ContextConfigApiUpdateSchema } from './chunk-LPIKPCE5.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, TenantProjectGraphIdParamsSchema, TenantProjectGraphParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsertSchema, ToolApiSelectSchema, ToolApiUpdateSchema, ToolInsertSchema, ToolSelectSchema, ToolStatusSchema, ToolUpdateSchema, URL_SAFE_ID_PATTERN, resourceIdSchema } from './chunk-LPIKPCE5.js';
|
|
7
5
|
export { TaskState } from './chunk-H2F72PDA.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
|
+
import pino from 'pino';
|
|
13
|
+
import pinoPretty from 'pino-pretty';
|
|
12
14
|
import jmespath from 'jmespath';
|
|
13
15
|
import { createClient } from '@libsql/client';
|
|
14
16
|
import { drizzle } from 'drizzle-orm/libsql';
|
|
15
|
-
import { and, eq, desc, count, isNotNull, inArray, sql, asc
|
|
17
|
+
import { and, eq, desc, count, isNotNull, inArray, sql, asc } from 'drizzle-orm';
|
|
16
18
|
import { customAlphabet, nanoid } from 'nanoid';
|
|
17
19
|
import crypto, { scrypt, randomBytes, timingSafeEqual } from 'crypto';
|
|
18
20
|
import { promisify } from 'util';
|
|
@@ -36,32 +38,114 @@ import dotenv from 'dotenv';
|
|
|
36
38
|
import { expand } from 'dotenv-expand';
|
|
37
39
|
import { findUpSync } from 'find-up';
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
constructor(name) {
|
|
41
|
+
var PinoLogger = class {
|
|
42
|
+
constructor(name, config = {}) {
|
|
42
43
|
this.name = name;
|
|
44
|
+
__publicField(this, "transportConfigs", []);
|
|
45
|
+
__publicField(this, "pinoInstance");
|
|
46
|
+
__publicField(this, "options");
|
|
47
|
+
this.options = {
|
|
48
|
+
name: this.name,
|
|
49
|
+
level: process.env.LOG_LEVEL || "info",
|
|
50
|
+
serializers: {
|
|
51
|
+
obj: (value) => ({ ...value })
|
|
52
|
+
},
|
|
53
|
+
redact: ["req.headers.authorization", 'req.headers["x-inkeep-admin-authentication"]'],
|
|
54
|
+
...config.options
|
|
55
|
+
};
|
|
56
|
+
if (config.transportConfigs) {
|
|
57
|
+
this.transportConfigs = config.transportConfigs;
|
|
58
|
+
}
|
|
59
|
+
if (this.transportConfigs.length > 0) {
|
|
60
|
+
this.pinoInstance = pino(this.options, pino.transport({ targets: this.transportConfigs }));
|
|
61
|
+
} else {
|
|
62
|
+
try {
|
|
63
|
+
const prettyStream = pinoPretty({
|
|
64
|
+
colorize: true,
|
|
65
|
+
translateTime: "HH:MM:ss",
|
|
66
|
+
ignore: "pid,hostname"
|
|
67
|
+
});
|
|
68
|
+
this.pinoInstance = pino(this.options, prettyStream);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.warn("Warning: pino-pretty failed, using standard JSON output:", error);
|
|
71
|
+
this.pinoInstance = pino(this.options);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
43
74
|
}
|
|
44
|
-
|
|
45
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Recreate the pino instance with current transports
|
|
77
|
+
*/
|
|
78
|
+
recreateInstance() {
|
|
79
|
+
if (this.pinoInstance && typeof this.pinoInstance.flush === "function") {
|
|
80
|
+
this.pinoInstance.flush();
|
|
81
|
+
}
|
|
82
|
+
if (this.transportConfigs.length === 0) {
|
|
83
|
+
try {
|
|
84
|
+
const prettyStream = pinoPretty({
|
|
85
|
+
colorize: true,
|
|
86
|
+
translateTime: "HH:MM:ss",
|
|
87
|
+
ignore: "pid,hostname"
|
|
88
|
+
});
|
|
89
|
+
this.pinoInstance = pino(this.options, prettyStream);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.warn("Warning: pino-pretty failed, using standard JSON output:", error);
|
|
92
|
+
this.pinoInstance = pino(this.options);
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
const multiTransport = { targets: this.transportConfigs };
|
|
96
|
+
const pinoTransport = pino.transport(multiTransport);
|
|
97
|
+
this.pinoInstance = pino(this.options, pinoTransport);
|
|
98
|
+
}
|
|
46
99
|
}
|
|
47
|
-
|
|
48
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Add a new transport to the logger
|
|
102
|
+
*/
|
|
103
|
+
addTransport(transportConfig) {
|
|
104
|
+
this.transportConfigs.push(transportConfig);
|
|
105
|
+
this.recreateInstance();
|
|
49
106
|
}
|
|
50
|
-
|
|
51
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Remove a transport by index
|
|
109
|
+
*/
|
|
110
|
+
removeTransport(index) {
|
|
111
|
+
if (index >= 0 && index < this.transportConfigs.length) {
|
|
112
|
+
this.transportConfigs.splice(index, 1);
|
|
113
|
+
this.recreateInstance();
|
|
114
|
+
}
|
|
52
115
|
}
|
|
53
|
-
|
|
54
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Get current transports
|
|
118
|
+
*/
|
|
119
|
+
getTransports() {
|
|
120
|
+
return [...this.transportConfigs];
|
|
55
121
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Update logger options
|
|
124
|
+
*/
|
|
125
|
+
updateOptions(options) {
|
|
126
|
+
this.options = {
|
|
127
|
+
...this.options,
|
|
128
|
+
...options
|
|
129
|
+
};
|
|
130
|
+
this.recreateInstance();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get the underlying pino instance for advanced usage
|
|
134
|
+
*/
|
|
135
|
+
getPinoInstance() {
|
|
136
|
+
return this.pinoInstance;
|
|
137
|
+
}
|
|
138
|
+
error(data, message) {
|
|
139
|
+
this.pinoInstance.error(data, message);
|
|
59
140
|
}
|
|
60
|
-
warn(
|
|
141
|
+
warn(data, message) {
|
|
142
|
+
this.pinoInstance.warn(data, message);
|
|
61
143
|
}
|
|
62
|
-
info(
|
|
144
|
+
info(data, message) {
|
|
145
|
+
this.pinoInstance.info(data, message);
|
|
63
146
|
}
|
|
64
|
-
debug(
|
|
147
|
+
debug(data, message) {
|
|
148
|
+
this.pinoInstance.debug(data, message);
|
|
65
149
|
}
|
|
66
150
|
};
|
|
67
151
|
var LoggerFactory = class {
|
|
@@ -93,7 +177,7 @@ var LoggerFactory = class {
|
|
|
93
177
|
} else if (this.config.defaultLogger) {
|
|
94
178
|
logger11 = this.config.defaultLogger;
|
|
95
179
|
} else {
|
|
96
|
-
logger11 = new
|
|
180
|
+
logger11 = new PinoLogger(name, this.config.pinoConfig);
|
|
97
181
|
}
|
|
98
182
|
this.loggers.set(name, logger11);
|
|
99
183
|
return logger11;
|
|
@@ -110,9 +194,6 @@ var loggerFactory = new LoggerFactory();
|
|
|
110
194
|
function getLogger(name) {
|
|
111
195
|
return loggerFactory.getLogger(name);
|
|
112
196
|
}
|
|
113
|
-
function configureLogging(config) {
|
|
114
|
-
loggerFactory.configure(config);
|
|
115
|
-
}
|
|
116
197
|
|
|
117
198
|
// src/context/ContextConfig.ts
|
|
118
199
|
var logger = getLogger("context-config");
|
|
@@ -790,6 +871,7 @@ var getAgentRelationById = (db) => async (params) => {
|
|
|
790
871
|
where: and(
|
|
791
872
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
792
873
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
874
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
793
875
|
eq(agentRelations.id, params.relationId)
|
|
794
876
|
)
|
|
795
877
|
});
|
|
@@ -800,7 +882,8 @@ var listAgentRelations = (db) => async (params) => {
|
|
|
800
882
|
const offset = (page - 1) * limit;
|
|
801
883
|
const whereClause = and(
|
|
802
884
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
803
|
-
eq(agentRelations.projectId, params.scopes.projectId)
|
|
885
|
+
eq(agentRelations.projectId, params.scopes.projectId),
|
|
886
|
+
eq(agentRelations.graphId, params.scopes.graphId)
|
|
804
887
|
);
|
|
805
888
|
const [data, totalResult] = await Promise.all([
|
|
806
889
|
db.select().from(agentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(agentRelations.createdAt)),
|
|
@@ -815,8 +898,8 @@ var getAgentRelations = (db) => async (params) => {
|
|
|
815
898
|
where: and(
|
|
816
899
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
817
900
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
818
|
-
eq(agentRelations.graphId, params.graphId),
|
|
819
|
-
eq(agentRelations.sourceAgentId, params.agentId)
|
|
901
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
902
|
+
eq(agentRelations.sourceAgentId, params.scopes.agentId)
|
|
820
903
|
)
|
|
821
904
|
});
|
|
822
905
|
};
|
|
@@ -825,7 +908,7 @@ var getAgentRelationsByGraph = (db) => async (params) => {
|
|
|
825
908
|
where: and(
|
|
826
909
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
827
910
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
828
|
-
eq(agentRelations.graphId, params.graphId)
|
|
911
|
+
eq(agentRelations.graphId, params.scopes.graphId)
|
|
829
912
|
)
|
|
830
913
|
});
|
|
831
914
|
};
|
|
@@ -836,6 +919,7 @@ var getAgentRelationsBySource = (db) => async (params) => {
|
|
|
836
919
|
const whereClause = and(
|
|
837
920
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
838
921
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
922
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
839
923
|
eq(agentRelations.sourceAgentId, params.sourceAgentId)
|
|
840
924
|
);
|
|
841
925
|
const [data, totalResult] = await Promise.all([
|
|
@@ -856,6 +940,7 @@ var getAgentRelationsByTarget = (db) => async (params) => {
|
|
|
856
940
|
const whereClause = and(
|
|
857
941
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
858
942
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
943
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
859
944
|
eq(agentRelations.targetAgentId, params.targetAgentId)
|
|
860
945
|
);
|
|
861
946
|
const [data, totalResult] = await Promise.all([
|
|
@@ -876,6 +961,7 @@ var getExternalAgentRelations = (db) => async (params) => {
|
|
|
876
961
|
const whereClause = and(
|
|
877
962
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
878
963
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
964
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
879
965
|
eq(agentRelations.externalAgentId, params.externalAgentId)
|
|
880
966
|
);
|
|
881
967
|
const [data, totalResult] = await Promise.all([
|
|
@@ -899,11 +985,12 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
|
|
|
899
985
|
and(
|
|
900
986
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
901
987
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
902
|
-
eq(agentRelations.graphId, params.graphId),
|
|
988
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
903
989
|
eq(agentRelations.sourceAgentId, params.agentId),
|
|
904
990
|
isNotNull(agentRelations.targetAgentId),
|
|
905
991
|
eq(agents.tenantId, params.scopes.tenantId),
|
|
906
|
-
eq(agents.projectId, params.scopes.projectId)
|
|
992
|
+
eq(agents.projectId, params.scopes.projectId),
|
|
993
|
+
eq(agents.graphId, params.scopes.graphId)
|
|
907
994
|
)
|
|
908
995
|
);
|
|
909
996
|
const externalRelations = await db.select({
|
|
@@ -919,11 +1006,12 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
|
|
|
919
1006
|
and(
|
|
920
1007
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
921
1008
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
922
|
-
eq(agentRelations.graphId, params.graphId),
|
|
1009
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
923
1010
|
eq(agentRelations.sourceAgentId, params.agentId),
|
|
924
1011
|
isNotNull(agentRelations.externalAgentId),
|
|
925
1012
|
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
926
|
-
eq(externalAgents.projectId, params.scopes.projectId)
|
|
1013
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1014
|
+
eq(externalAgents.graphId, params.scopes.graphId)
|
|
927
1015
|
)
|
|
928
1016
|
);
|
|
929
1017
|
return {
|
|
@@ -949,7 +1037,7 @@ var getAgentRelationByParams = (db) => async (params) => {
|
|
|
949
1037
|
const whereConditions = [
|
|
950
1038
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
951
1039
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
952
|
-
eq(agentRelations.graphId, params.graphId),
|
|
1040
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
953
1041
|
eq(agentRelations.sourceAgentId, params.sourceAgentId),
|
|
954
1042
|
eq(agentRelations.relationType, params.relationType)
|
|
955
1043
|
];
|
|
@@ -965,8 +1053,7 @@ var getAgentRelationByParams = (db) => async (params) => {
|
|
|
965
1053
|
};
|
|
966
1054
|
var upsertAgentRelation = (db) => async (params) => {
|
|
967
1055
|
const existing = await getAgentRelationByParams(db)({
|
|
968
|
-
scopes: { tenantId: params.tenantId, projectId: params.projectId },
|
|
969
|
-
graphId: params.graphId,
|
|
1056
|
+
scopes: { tenantId: params.tenantId, projectId: params.projectId, graphId: params.graphId },
|
|
970
1057
|
sourceAgentId: params.sourceAgentId,
|
|
971
1058
|
targetAgentId: params.targetAgentId,
|
|
972
1059
|
externalAgentId: params.externalAgentId,
|
|
@@ -992,6 +1079,7 @@ var updateAgentRelation = (db) => async (params) => {
|
|
|
992
1079
|
and(
|
|
993
1080
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
994
1081
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
1082
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
995
1083
|
eq(agentRelations.id, params.relationId)
|
|
996
1084
|
)
|
|
997
1085
|
).returning();
|
|
@@ -1002,6 +1090,7 @@ var deleteAgentRelation = (db) => async (params) => {
|
|
|
1002
1090
|
and(
|
|
1003
1091
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
1004
1092
|
eq(agentRelations.projectId, params.scopes.projectId),
|
|
1093
|
+
eq(agentRelations.graphId, params.scopes.graphId),
|
|
1005
1094
|
eq(agentRelations.id, params.relationId)
|
|
1006
1095
|
)
|
|
1007
1096
|
);
|
|
@@ -1011,7 +1100,7 @@ var deleteAgentRelationsByGraph = (db) => async (params) => {
|
|
|
1011
1100
|
const result = await db.delete(agentRelations).where(
|
|
1012
1101
|
and(
|
|
1013
1102
|
eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
1014
|
-
eq(agentRelations.graphId, params.graphId)
|
|
1103
|
+
eq(agentRelations.graphId, params.scopes.graphId)
|
|
1015
1104
|
)
|
|
1016
1105
|
);
|
|
1017
1106
|
return (result.rowsAffected || 0) > 0;
|
|
@@ -1022,6 +1111,7 @@ var createAgentToolRelation = (db) => async (params) => {
|
|
|
1022
1111
|
id: finalRelationId,
|
|
1023
1112
|
tenantId: params.scopes.tenantId,
|
|
1024
1113
|
projectId: params.scopes.projectId,
|
|
1114
|
+
graphId: params.scopes.graphId,
|
|
1025
1115
|
agentId: params.data.agentId,
|
|
1026
1116
|
toolId: params.data.toolId,
|
|
1027
1117
|
selectedTools: params.data.selectedTools
|
|
@@ -1037,6 +1127,7 @@ var updateAgentToolRelation = (db) => async (params) => {
|
|
|
1037
1127
|
and(
|
|
1038
1128
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1039
1129
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1130
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1040
1131
|
eq(agentToolRelations.id, params.relationId)
|
|
1041
1132
|
)
|
|
1042
1133
|
).returning();
|
|
@@ -1047,6 +1138,7 @@ var deleteAgentToolRelation = (db) => async (params) => {
|
|
|
1047
1138
|
and(
|
|
1048
1139
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1049
1140
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1141
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1050
1142
|
eq(agentToolRelations.id, params.relationId)
|
|
1051
1143
|
)
|
|
1052
1144
|
);
|
|
@@ -1056,7 +1148,9 @@ var deleteAgentToolRelationByAgent = (db) => async (params) => {
|
|
|
1056
1148
|
const result = await db.delete(agentToolRelations).where(
|
|
1057
1149
|
and(
|
|
1058
1150
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1059
|
-
eq(agentToolRelations.
|
|
1151
|
+
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1152
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1153
|
+
eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
1060
1154
|
)
|
|
1061
1155
|
);
|
|
1062
1156
|
return (result.rowsAffected || 0) > 0;
|
|
@@ -1066,6 +1160,7 @@ var getAgentToolRelationById = (db) => async (params) => {
|
|
|
1066
1160
|
where: and(
|
|
1067
1161
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1068
1162
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1163
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1069
1164
|
eq(agentToolRelations.id, params.relationId)
|
|
1070
1165
|
)
|
|
1071
1166
|
});
|
|
@@ -1079,14 +1174,14 @@ var getAgentToolRelationByAgent = (db) => async (params) => {
|
|
|
1079
1174
|
and(
|
|
1080
1175
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1081
1176
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1082
|
-
eq(agentToolRelations.agentId, params.agentId)
|
|
1177
|
+
eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
1083
1178
|
)
|
|
1084
1179
|
).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
|
|
1085
1180
|
db.select({ count: count() }).from(agentToolRelations).where(
|
|
1086
1181
|
and(
|
|
1087
1182
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1088
1183
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1089
|
-
eq(agentToolRelations.agentId, params.agentId)
|
|
1184
|
+
eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
1090
1185
|
)
|
|
1091
1186
|
)
|
|
1092
1187
|
]);
|
|
@@ -1106,6 +1201,7 @@ var getAgentToolRelationByTool = (db) => async (params) => {
|
|
|
1106
1201
|
and(
|
|
1107
1202
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1108
1203
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1204
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1109
1205
|
eq(agentToolRelations.toolId, params.toolId)
|
|
1110
1206
|
)
|
|
1111
1207
|
).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
|
|
@@ -1113,6 +1209,7 @@ var getAgentToolRelationByTool = (db) => async (params) => {
|
|
|
1113
1209
|
and(
|
|
1114
1210
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1115
1211
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1212
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1116
1213
|
eq(agentToolRelations.toolId, params.toolId)
|
|
1117
1214
|
)
|
|
1118
1215
|
)
|
|
@@ -1132,13 +1229,15 @@ var listAgentToolRelations = (db) => async (params) => {
|
|
|
1132
1229
|
db.select().from(agentToolRelations).where(
|
|
1133
1230
|
and(
|
|
1134
1231
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1135
|
-
eq(agentToolRelations.projectId, params.scopes.projectId)
|
|
1232
|
+
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1233
|
+
eq(agentToolRelations.graphId, params.scopes.graphId)
|
|
1136
1234
|
)
|
|
1137
1235
|
).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
|
|
1138
1236
|
db.select({ count: count() }).from(agentToolRelations).where(
|
|
1139
1237
|
and(
|
|
1140
1238
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1141
|
-
eq(agentToolRelations.projectId, params.scopes.projectId)
|
|
1239
|
+
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1240
|
+
eq(agentToolRelations.graphId, params.scopes.graphId)
|
|
1142
1241
|
)
|
|
1143
1242
|
)
|
|
1144
1243
|
]);
|
|
@@ -1149,26 +1248,6 @@ var listAgentToolRelations = (db) => async (params) => {
|
|
|
1149
1248
|
pagination: { page, limit, total, pages }
|
|
1150
1249
|
};
|
|
1151
1250
|
};
|
|
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
1251
|
var getToolsForAgent = (db) => async (params) => {
|
|
1173
1252
|
const page = params.pagination?.page || 1;
|
|
1174
1253
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
@@ -1199,14 +1278,16 @@ var getToolsForAgent = (db) => async (params) => {
|
|
|
1199
1278
|
and(
|
|
1200
1279
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1201
1280
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1202
|
-
eq(agentToolRelations.
|
|
1281
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1282
|
+
eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
1203
1283
|
)
|
|
1204
1284
|
).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
|
|
1205
1285
|
db.select({ count: count() }).from(agentToolRelations).where(
|
|
1206
1286
|
and(
|
|
1207
1287
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1208
1288
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1209
|
-
eq(agentToolRelations.
|
|
1289
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1290
|
+
eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
1210
1291
|
)
|
|
1211
1292
|
)
|
|
1212
1293
|
]);
|
|
@@ -1235,6 +1316,9 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
1235
1316
|
name: agents.name,
|
|
1236
1317
|
description: agents.description,
|
|
1237
1318
|
prompt: agents.prompt,
|
|
1319
|
+
conversationHistoryConfig: agents.conversationHistoryConfig,
|
|
1320
|
+
models: agents.models,
|
|
1321
|
+
stopWhen: agents.stopWhen,
|
|
1238
1322
|
createdAt: agents.createdAt,
|
|
1239
1323
|
updatedAt: agents.updatedAt
|
|
1240
1324
|
}
|
|
@@ -1242,6 +1326,7 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
1242
1326
|
and(
|
|
1243
1327
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1244
1328
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1329
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1245
1330
|
eq(agentToolRelations.toolId, params.toolId)
|
|
1246
1331
|
)
|
|
1247
1332
|
).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
|
|
@@ -1249,6 +1334,7 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
1249
1334
|
and(
|
|
1250
1335
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1251
1336
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1337
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1252
1338
|
eq(agentToolRelations.toolId, params.toolId)
|
|
1253
1339
|
)
|
|
1254
1340
|
)
|
|
@@ -1265,7 +1351,8 @@ var validateInternalAgent = (db) => async (params) => {
|
|
|
1265
1351
|
and(
|
|
1266
1352
|
eq(agents.tenantId, params.scopes.tenantId),
|
|
1267
1353
|
eq(agents.projectId, params.scopes.projectId),
|
|
1268
|
-
eq(agents.
|
|
1354
|
+
eq(agents.graphId, params.scopes.graphId),
|
|
1355
|
+
eq(agents.id, params.scopes.agentId)
|
|
1269
1356
|
)
|
|
1270
1357
|
).limit(1);
|
|
1271
1358
|
return result.length > 0;
|
|
@@ -1275,7 +1362,8 @@ var validateExternalAgent = (db) => async (params) => {
|
|
|
1275
1362
|
and(
|
|
1276
1363
|
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1277
1364
|
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1278
|
-
eq(externalAgents.
|
|
1365
|
+
eq(externalAgents.graphId, params.scopes.graphId),
|
|
1366
|
+
eq(externalAgents.id, params.scopes.agentId)
|
|
1279
1367
|
)
|
|
1280
1368
|
).limit(1);
|
|
1281
1369
|
return result.length > 0;
|
|
@@ -1285,6 +1373,7 @@ var getAgentById = (db) => async (params) => {
|
|
|
1285
1373
|
where: and(
|
|
1286
1374
|
eq(agents.tenantId, params.scopes.tenantId),
|
|
1287
1375
|
eq(agents.projectId, params.scopes.projectId),
|
|
1376
|
+
eq(agents.graphId, params.scopes.graphId),
|
|
1288
1377
|
eq(agents.id, params.agentId)
|
|
1289
1378
|
)
|
|
1290
1379
|
});
|
|
@@ -1294,7 +1383,8 @@ var listAgents = (db) => async (params) => {
|
|
|
1294
1383
|
return await db.query.agents.findMany({
|
|
1295
1384
|
where: and(
|
|
1296
1385
|
eq(agents.tenantId, params.scopes.tenantId),
|
|
1297
|
-
eq(agents.projectId, params.scopes.projectId)
|
|
1386
|
+
eq(agents.projectId, params.scopes.projectId),
|
|
1387
|
+
eq(agents.graphId, params.scopes.graphId)
|
|
1298
1388
|
)
|
|
1299
1389
|
});
|
|
1300
1390
|
};
|
|
@@ -1304,7 +1394,8 @@ var listAgentsPaginated = (db) => async (params) => {
|
|
|
1304
1394
|
const offset = (page - 1) * limit;
|
|
1305
1395
|
const whereClause = and(
|
|
1306
1396
|
eq(agents.tenantId, params.scopes.tenantId),
|
|
1307
|
-
eq(agents.projectId, params.scopes.projectId)
|
|
1397
|
+
eq(agents.projectId, params.scopes.projectId),
|
|
1398
|
+
eq(agents.graphId, params.scopes.graphId)
|
|
1308
1399
|
);
|
|
1309
1400
|
const [data, totalResult] = await Promise.all([
|
|
1310
1401
|
db.select().from(agents).where(whereClause).limit(limit).offset(offset).orderBy(desc(agents.createdAt)),
|
|
@@ -1336,13 +1427,18 @@ var updateAgent = (db) => async (params) => {
|
|
|
1336
1427
|
and(
|
|
1337
1428
|
eq(agents.tenantId, params.scopes.tenantId),
|
|
1338
1429
|
eq(agents.projectId, params.scopes.projectId),
|
|
1430
|
+
eq(agents.graphId, params.scopes.graphId),
|
|
1339
1431
|
eq(agents.id, params.agentId)
|
|
1340
1432
|
)
|
|
1341
1433
|
).returning();
|
|
1342
1434
|
return agent[0] ?? null;
|
|
1343
1435
|
};
|
|
1344
1436
|
var upsertAgent = (db) => async (params) => {
|
|
1345
|
-
const scopes = {
|
|
1437
|
+
const scopes = {
|
|
1438
|
+
tenantId: params.data.tenantId,
|
|
1439
|
+
projectId: params.data.projectId,
|
|
1440
|
+
graphId: params.data.graphId
|
|
1441
|
+
};
|
|
1346
1442
|
const existing = await getAgentById(db)({
|
|
1347
1443
|
scopes,
|
|
1348
1444
|
agentId: params.data.id
|
|
@@ -1373,6 +1469,7 @@ var deleteAgent = (db) => async (params) => {
|
|
|
1373
1469
|
and(
|
|
1374
1470
|
eq(agents.tenantId, params.scopes.tenantId),
|
|
1375
1471
|
eq(agents.projectId, params.scopes.projectId),
|
|
1472
|
+
eq(agents.graphId, params.scopes.graphId),
|
|
1376
1473
|
eq(agents.id, params.agentId)
|
|
1377
1474
|
)
|
|
1378
1475
|
);
|
|
@@ -1390,36 +1487,11 @@ var getAgentsByIds = (db) => async (params) => {
|
|
|
1390
1487
|
and(
|
|
1391
1488
|
eq(agents.tenantId, params.scopes.tenantId),
|
|
1392
1489
|
eq(agents.projectId, params.scopes.projectId),
|
|
1490
|
+
eq(agents.graphId, params.scopes.graphId),
|
|
1393
1491
|
inArray(agents.id, params.agentIds)
|
|
1394
1492
|
)
|
|
1395
1493
|
);
|
|
1396
1494
|
};
|
|
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
1495
|
var getContextConfigById = (db) => async (params) => {
|
|
1424
1496
|
return await db.query.contextConfigs.findFirst({
|
|
1425
1497
|
where: and(
|
|
@@ -1574,6 +1646,8 @@ var getExternalAgent = (db) => async (params) => {
|
|
|
1574
1646
|
const result = await db.query.externalAgents.findFirst({
|
|
1575
1647
|
where: and(
|
|
1576
1648
|
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1649
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1650
|
+
eq(externalAgents.graphId, params.scopes.graphId),
|
|
1577
1651
|
eq(externalAgents.id, params.agentId)
|
|
1578
1652
|
)
|
|
1579
1653
|
});
|
|
@@ -1583,6 +1657,8 @@ var getExternalAgentByUrl = (db) => async (params) => {
|
|
|
1583
1657
|
const result = await db.query.externalAgents.findFirst({
|
|
1584
1658
|
where: and(
|
|
1585
1659
|
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1660
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1661
|
+
eq(externalAgents.graphId, params.scopes.graphId),
|
|
1586
1662
|
eq(externalAgents.baseUrl, params.baseUrl)
|
|
1587
1663
|
)
|
|
1588
1664
|
});
|
|
@@ -1590,7 +1666,11 @@ var getExternalAgentByUrl = (db) => async (params) => {
|
|
|
1590
1666
|
};
|
|
1591
1667
|
var listExternalAgents = (db) => async (params) => {
|
|
1592
1668
|
return await db.query.externalAgents.findMany({
|
|
1593
|
-
where:
|
|
1669
|
+
where: and(
|
|
1670
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1671
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1672
|
+
eq(externalAgents.graphId, params.scopes.graphId)
|
|
1673
|
+
),
|
|
1594
1674
|
orderBy: [asc(externalAgents.name)]
|
|
1595
1675
|
});
|
|
1596
1676
|
};
|
|
@@ -1599,8 +1679,20 @@ var listExternalAgentsPaginated = (db) => async (params) => {
|
|
|
1599
1679
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
1600
1680
|
const offset = (page - 1) * limit;
|
|
1601
1681
|
const [data, totalResult] = await Promise.all([
|
|
1602
|
-
db.select().from(externalAgents).where(
|
|
1603
|
-
|
|
1682
|
+
db.select().from(externalAgents).where(
|
|
1683
|
+
and(
|
|
1684
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1685
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1686
|
+
eq(externalAgents.graphId, params.scopes.graphId)
|
|
1687
|
+
)
|
|
1688
|
+
).limit(limit).offset(offset).orderBy(desc(externalAgents.createdAt)),
|
|
1689
|
+
db.select({ count: count() }).from(externalAgents).where(
|
|
1690
|
+
and(
|
|
1691
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1692
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1693
|
+
eq(externalAgents.graphId, params.scopes.graphId)
|
|
1694
|
+
)
|
|
1695
|
+
)
|
|
1604
1696
|
]);
|
|
1605
1697
|
const total = typeof totalResult[0]?.count === "string" ? parseInt(totalResult[0].count, 10) : totalResult[0]?.count || 0;
|
|
1606
1698
|
const pages = Math.ceil(total / limit);
|
|
@@ -1626,13 +1718,19 @@ var updateExternalAgent = (db) => async (params) => {
|
|
|
1626
1718
|
const result = await db.update(externalAgents).set(updateData).where(
|
|
1627
1719
|
and(
|
|
1628
1720
|
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1721
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1722
|
+
eq(externalAgents.graphId, params.scopes.graphId),
|
|
1629
1723
|
eq(externalAgents.id, params.agentId)
|
|
1630
1724
|
)
|
|
1631
1725
|
).returning();
|
|
1632
1726
|
return result[0] || null;
|
|
1633
1727
|
};
|
|
1634
1728
|
var upsertExternalAgent = (db) => async (params) => {
|
|
1635
|
-
const scopes = {
|
|
1729
|
+
const scopes = {
|
|
1730
|
+
tenantId: params.data.tenantId,
|
|
1731
|
+
projectId: params.data.projectId,
|
|
1732
|
+
graphId: params.data.graphId
|
|
1733
|
+
};
|
|
1636
1734
|
const existing = await getExternalAgent(db)({
|
|
1637
1735
|
scopes,
|
|
1638
1736
|
agentId: params.data.id
|
|
@@ -1662,6 +1760,8 @@ var deleteExternalAgent = (db) => async (params) => {
|
|
|
1662
1760
|
const result = await db.delete(externalAgents).where(
|
|
1663
1761
|
and(
|
|
1664
1762
|
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1763
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1764
|
+
eq(externalAgents.graphId, params.scopes.graphId),
|
|
1665
1765
|
eq(externalAgents.id, params.agentId)
|
|
1666
1766
|
)
|
|
1667
1767
|
).returning();
|
|
@@ -1680,27 +1780,24 @@ var externalAgentUrlExists = (db) => async (params) => {
|
|
|
1680
1780
|
return agent !== null;
|
|
1681
1781
|
};
|
|
1682
1782
|
var countExternalAgents = (db) => async (params) => {
|
|
1683
|
-
const result = await db.select({ count: count() }).from(externalAgents).where(
|
|
1783
|
+
const result = await db.select({ count: count() }).from(externalAgents).where(
|
|
1784
|
+
and(
|
|
1785
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1786
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1787
|
+
eq(externalAgents.graphId, params.scopes.graphId)
|
|
1788
|
+
)
|
|
1789
|
+
);
|
|
1684
1790
|
const countValue = result[0]?.count;
|
|
1685
1791
|
return typeof countValue === "string" ? parseInt(countValue, 10) : countValue || 0;
|
|
1686
1792
|
};
|
|
1687
1793
|
|
|
1688
1794
|
// 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
1795
|
var getAgentGraphById = (db) => async (params) => {
|
|
1699
1796
|
const result = await db.query.agentGraph.findFirst({
|
|
1700
1797
|
where: and(
|
|
1701
1798
|
eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
1702
1799
|
eq(agentGraph.projectId, params.scopes.projectId),
|
|
1703
|
-
eq(agentGraph.id, params.graphId)
|
|
1800
|
+
eq(agentGraph.id, params.scopes.graphId)
|
|
1704
1801
|
)
|
|
1705
1802
|
});
|
|
1706
1803
|
return result ?? null;
|
|
@@ -1710,7 +1807,7 @@ var getAgentGraphWithDefaultAgent = (db) => async (params) => {
|
|
|
1710
1807
|
where: and(
|
|
1711
1808
|
eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
1712
1809
|
eq(agentGraph.projectId, params.scopes.projectId),
|
|
1713
|
-
eq(agentGraph.id, params.graphId)
|
|
1810
|
+
eq(agentGraph.id, params.scopes.graphId)
|
|
1714
1811
|
),
|
|
1715
1812
|
with: {
|
|
1716
1813
|
defaultAgent: true
|
|
@@ -1803,7 +1900,7 @@ var updateAgentGraph = (db) => async (params) => {
|
|
|
1803
1900
|
and(
|
|
1804
1901
|
eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
1805
1902
|
eq(agentGraph.projectId, params.scopes.projectId),
|
|
1806
|
-
eq(agentGraph.id, params.graphId)
|
|
1903
|
+
eq(agentGraph.id, params.scopes.graphId)
|
|
1807
1904
|
)
|
|
1808
1905
|
).returning();
|
|
1809
1906
|
return graph[0] ?? null;
|
|
@@ -1813,7 +1910,7 @@ var deleteAgentGraph = (db) => async (params) => {
|
|
|
1813
1910
|
and(
|
|
1814
1911
|
eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
1815
1912
|
eq(agentGraph.projectId, params.scopes.projectId),
|
|
1816
|
-
eq(agentGraph.id, params.graphId)
|
|
1913
|
+
eq(agentGraph.id, params.scopes.graphId)
|
|
1817
1914
|
)
|
|
1818
1915
|
).returning();
|
|
1819
1916
|
return result.length > 0;
|
|
@@ -1840,17 +1937,14 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
1840
1937
|
agentId
|
|
1841
1938
|
}) => {
|
|
1842
1939
|
const { tenantId, projectId } = scopes;
|
|
1843
|
-
const graph = await
|
|
1844
|
-
scopes: { tenantId, projectId }
|
|
1845
|
-
graphId
|
|
1940
|
+
const graph = await getAgentGraphById(db)({
|
|
1941
|
+
scopes: { tenantId, projectId, graphId }
|
|
1846
1942
|
});
|
|
1847
1943
|
if (!graph) {
|
|
1848
1944
|
throw new Error(`Agent graph with ID ${graphId} not found for tenant ${tenantId}`);
|
|
1849
1945
|
}
|
|
1850
1946
|
const relations = await getAgentRelations(db)({
|
|
1851
|
-
scopes: { tenantId, projectId }
|
|
1852
|
-
graphId,
|
|
1853
|
-
agentId
|
|
1947
|
+
scopes: { tenantId, projectId, graphId, agentId }
|
|
1854
1948
|
});
|
|
1855
1949
|
const targetAgentIds = relations.map((relation) => relation.targetAgentId).filter((id) => id !== null);
|
|
1856
1950
|
if (targetAgentIds.length === 0) {
|
|
@@ -1859,7 +1953,7 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
1859
1953
|
const agentInfos = await Promise.all(
|
|
1860
1954
|
targetAgentIds.map(async (targetAgentId) => {
|
|
1861
1955
|
const agent = await getAgentById(db)({
|
|
1862
|
-
scopes: { tenantId, projectId },
|
|
1956
|
+
scopes: { tenantId, projectId, graphId },
|
|
1863
1957
|
agentId: targetAgentId
|
|
1864
1958
|
});
|
|
1865
1959
|
if (agent !== void 0) {
|
|
@@ -1871,55 +1965,35 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
1871
1965
|
return agentInfos.filter((agent) => agent !== null);
|
|
1872
1966
|
};
|
|
1873
1967
|
var getFullGraphDefinition = (db) => async ({
|
|
1874
|
-
scopes: { tenantId, projectId }
|
|
1875
|
-
graphId
|
|
1968
|
+
scopes: { tenantId, projectId, graphId }
|
|
1876
1969
|
}) => {
|
|
1877
1970
|
const graph = await getAgentGraphById(db)({
|
|
1878
|
-
scopes: { tenantId, projectId }
|
|
1879
|
-
graphId
|
|
1971
|
+
scopes: { tenantId, projectId, graphId }
|
|
1880
1972
|
});
|
|
1881
1973
|
if (!graph) {
|
|
1882
1974
|
return null;
|
|
1883
1975
|
}
|
|
1884
1976
|
const graphRelations = await getAgentRelationsByGraph(db)({
|
|
1885
|
-
scopes: { tenantId, projectId }
|
|
1886
|
-
|
|
1977
|
+
scopes: { tenantId, projectId, graphId }
|
|
1978
|
+
});
|
|
1979
|
+
const graphAgents = await db.query.agents.findMany({
|
|
1980
|
+
where: and(
|
|
1981
|
+
eq(agents.tenantId, tenantId),
|
|
1982
|
+
eq(agents.projectId, projectId),
|
|
1983
|
+
eq(agents.graphId, graphId)
|
|
1984
|
+
)
|
|
1887
1985
|
});
|
|
1888
|
-
const internalAgentIds = /* @__PURE__ */ new Set();
|
|
1889
1986
|
const externalAgentIds = /* @__PURE__ */ new Set();
|
|
1890
|
-
internalAgentIds.add(graph.defaultAgentId);
|
|
1891
1987
|
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
1988
|
if (relation.externalAgentId) {
|
|
1899
1989
|
externalAgentIds.add(relation.externalAgentId);
|
|
1900
1990
|
}
|
|
1901
1991
|
}
|
|
1902
|
-
const
|
|
1903
|
-
|
|
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
|
-
});
|
|
1992
|
+
const processedAgents = await Promise.all(
|
|
1993
|
+
graphAgents.map(async (agent) => {
|
|
1920
1994
|
if (!agent) return null;
|
|
1921
1995
|
const agentRelationsList = graphRelations.filter(
|
|
1922
|
-
(relation) => relation.sourceAgentId ===
|
|
1996
|
+
(relation) => relation.sourceAgentId === agent.id
|
|
1923
1997
|
);
|
|
1924
1998
|
const canTransferTo = agentRelationsList.filter((rel) => rel.relationType === "transfer" || rel.relationType === "transfer_to").map((rel) => rel.targetAgentId).filter((id) => id !== null);
|
|
1925
1999
|
const canDelegateTo = agentRelationsList.filter((rel) => rel.relationType === "delegate" || rel.relationType === "delegate_to").map((rel) => rel.targetAgentId || rel.externalAgentId).filter((id) => id !== null);
|
|
@@ -1936,19 +2010,19 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
1936
2010
|
lastToolsSync: tools.lastToolsSync,
|
|
1937
2011
|
selectedTools: agentToolRelations.selectedTools
|
|
1938
2012
|
}).from(agentToolRelations).innerJoin(tools, eq(agentToolRelations.toolId, tools.id)).where(
|
|
1939
|
-
and(eq(agentToolRelations.tenantId, tenantId), eq(agentToolRelations.agentId,
|
|
2013
|
+
and(eq(agentToolRelations.tenantId, tenantId), eq(agentToolRelations.agentId, agent.id))
|
|
1940
2014
|
);
|
|
1941
2015
|
const agentDataComponentRelations = await db.query.agentDataComponents.findMany({
|
|
1942
2016
|
where: and(
|
|
1943
2017
|
eq(agentDataComponents.tenantId, tenantId),
|
|
1944
|
-
eq(agentDataComponents.agentId,
|
|
2018
|
+
eq(agentDataComponents.agentId, agent.id)
|
|
1945
2019
|
)
|
|
1946
2020
|
});
|
|
1947
2021
|
const agentDataComponentIds = agentDataComponentRelations.map((rel) => rel.dataComponentId);
|
|
1948
2022
|
const agentArtifactComponentRelations = await db.query.agentArtifactComponents.findMany({
|
|
1949
2023
|
where: and(
|
|
1950
2024
|
eq(agentArtifactComponents.tenantId, tenantId),
|
|
1951
|
-
eq(agentArtifactComponents.agentId,
|
|
2025
|
+
eq(agentArtifactComponents.agentId, agent.id)
|
|
1952
2026
|
)
|
|
1953
2027
|
});
|
|
1954
2028
|
const agentArtifactComponentIds = agentArtifactComponentRelations.map(
|
|
@@ -1991,7 +2065,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
1991
2065
|
const externalAgents2 = await Promise.all(
|
|
1992
2066
|
Array.from(externalAgentIds).map(async (agentId) => {
|
|
1993
2067
|
const agent = await getExternalAgent(db)({
|
|
1994
|
-
scopes: { tenantId, projectId },
|
|
2068
|
+
scopes: { tenantId, projectId, graphId },
|
|
1995
2069
|
agentId
|
|
1996
2070
|
});
|
|
1997
2071
|
if (!agent) return null;
|
|
@@ -2003,7 +2077,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
2003
2077
|
};
|
|
2004
2078
|
})
|
|
2005
2079
|
);
|
|
2006
|
-
const validAgents = [...
|
|
2080
|
+
const validAgents = [...processedAgents, ...externalAgents2].filter(
|
|
2007
2081
|
(agent) => agent !== null
|
|
2008
2082
|
);
|
|
2009
2083
|
const agentsObject = {};
|
|
@@ -2049,6 +2123,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
2049
2123
|
}
|
|
2050
2124
|
let dataComponentsObject = {};
|
|
2051
2125
|
try {
|
|
2126
|
+
const internalAgentIds = graphAgents.map((agent) => agent.id);
|
|
2052
2127
|
const agentIds = Array.from(internalAgentIds);
|
|
2053
2128
|
dataComponentsObject = await fetchComponentRelationships(db)(
|
|
2054
2129
|
{ tenantId, projectId },
|
|
@@ -2071,6 +2146,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
2071
2146
|
}
|
|
2072
2147
|
let artifactComponentsObject = {};
|
|
2073
2148
|
try {
|
|
2149
|
+
const internalAgentIds = graphAgents.map((agent) => agent.id);
|
|
2074
2150
|
const agentIds = Array.from(internalAgentIds);
|
|
2075
2151
|
artifactComponentsObject = await fetchComponentRelationships(db)(
|
|
2076
2152
|
{ tenantId, projectId },
|
|
@@ -2177,16 +2253,14 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
2177
2253
|
return result;
|
|
2178
2254
|
};
|
|
2179
2255
|
var upsertAgentGraph = (db) => async (params) => {
|
|
2180
|
-
const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId };
|
|
2181
2256
|
const graphId = params.data.id || nanoid();
|
|
2257
|
+
const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId, graphId };
|
|
2182
2258
|
const existing = await getAgentGraphById(db)({
|
|
2183
|
-
scopes
|
|
2184
|
-
graphId
|
|
2259
|
+
scopes
|
|
2185
2260
|
});
|
|
2186
2261
|
if (existing) {
|
|
2187
2262
|
return await updateAgentGraph(db)({
|
|
2188
2263
|
scopes,
|
|
2189
|
-
graphId,
|
|
2190
2264
|
data: {
|
|
2191
2265
|
name: params.data.name,
|
|
2192
2266
|
defaultAgentId: params.data.defaultAgentId,
|
|
@@ -2532,7 +2606,8 @@ var getArtifactComponentsForAgent = (db) => async (params) => {
|
|
|
2532
2606
|
and(
|
|
2533
2607
|
eq(artifactComponents.tenantId, params.scopes.tenantId),
|
|
2534
2608
|
eq(artifactComponents.projectId, params.scopes.projectId),
|
|
2535
|
-
eq(agentArtifactComponents.
|
|
2609
|
+
eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
2610
|
+
eq(agentArtifactComponents.agentId, params.scopes.agentId)
|
|
2536
2611
|
)
|
|
2537
2612
|
).orderBy(desc(artifactComponents.createdAt));
|
|
2538
2613
|
};
|
|
@@ -2541,7 +2616,8 @@ var associateArtifactComponentWithAgent = (db) => async (params) => {
|
|
|
2541
2616
|
id: nanoid(),
|
|
2542
2617
|
tenantId: params.scopes.tenantId,
|
|
2543
2618
|
projectId: params.scopes.projectId,
|
|
2544
|
-
|
|
2619
|
+
graphId: params.scopes.graphId,
|
|
2620
|
+
agentId: params.scopes.agentId,
|
|
2545
2621
|
artifactComponentId: params.artifactComponentId,
|
|
2546
2622
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2547
2623
|
}).returning();
|
|
@@ -2553,7 +2629,8 @@ var removeArtifactComponentFromAgent = (db) => async (params) => {
|
|
|
2553
2629
|
and(
|
|
2554
2630
|
eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
2555
2631
|
eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
2556
|
-
eq(agentArtifactComponents.
|
|
2632
|
+
eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
2633
|
+
eq(agentArtifactComponents.agentId, params.scopes.agentId),
|
|
2557
2634
|
eq(agentArtifactComponents.artifactComponentId, params.artifactComponentId)
|
|
2558
2635
|
)
|
|
2559
2636
|
).returning();
|
|
@@ -2567,13 +2644,15 @@ var deleteAgentArtifactComponentRelationByAgent = (db) => async (params) => {
|
|
|
2567
2644
|
const result = await db.delete(agentArtifactComponents).where(
|
|
2568
2645
|
and(
|
|
2569
2646
|
eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
2570
|
-
eq(agentArtifactComponents.
|
|
2647
|
+
eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
2648
|
+
eq(agentArtifactComponents.agentId, params.scopes.agentId)
|
|
2571
2649
|
)
|
|
2572
2650
|
);
|
|
2573
2651
|
return (result.rowsAffected || 0) > 0;
|
|
2574
2652
|
};
|
|
2575
2653
|
var getAgentsUsingArtifactComponent = (db) => async (params) => {
|
|
2576
2654
|
return await db.select({
|
|
2655
|
+
graphId: agentArtifactComponents.graphId,
|
|
2577
2656
|
agentId: agentArtifactComponents.agentId,
|
|
2578
2657
|
createdAt: agentArtifactComponents.createdAt
|
|
2579
2658
|
}).from(agentArtifactComponents).where(
|
|
@@ -2589,7 +2668,8 @@ var isArtifactComponentAssociatedWithAgent = (db) => async (params) => {
|
|
|
2589
2668
|
and(
|
|
2590
2669
|
eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
2591
2670
|
eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
2592
|
-
eq(agentArtifactComponents.
|
|
2671
|
+
eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
2672
|
+
eq(agentArtifactComponents.agentId, params.scopes.agentId),
|
|
2593
2673
|
eq(agentArtifactComponents.artifactComponentId, params.artifactComponentId)
|
|
2594
2674
|
)
|
|
2595
2675
|
).limit(1);
|
|
@@ -2600,7 +2680,7 @@ var graphHasArtifactComponents = (db) => async (params) => {
|
|
|
2600
2680
|
and(
|
|
2601
2681
|
eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
2602
2682
|
eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
2603
|
-
eq(agentRelations.graphId, params.graphId)
|
|
2683
|
+
eq(agentRelations.graphId, params.scopes.graphId)
|
|
2604
2684
|
)
|
|
2605
2685
|
).limit(1);
|
|
2606
2686
|
const total = result[0]?.count || 0;
|
|
@@ -2622,7 +2702,8 @@ var countArtifactComponentsForAgent = (db) => async (params) => {
|
|
|
2622
2702
|
and(
|
|
2623
2703
|
eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
2624
2704
|
eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
2625
|
-
eq(agentArtifactComponents.
|
|
2705
|
+
eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
2706
|
+
eq(agentArtifactComponents.agentId, params.scopes.agentId)
|
|
2626
2707
|
)
|
|
2627
2708
|
);
|
|
2628
2709
|
const total = result[0]?.count || 0;
|
|
@@ -3242,7 +3323,8 @@ var getDataComponentsForAgent = (db) => async (params) => {
|
|
|
3242
3323
|
and(
|
|
3243
3324
|
eq(dataComponents.tenantId, params.scopes.tenantId),
|
|
3244
3325
|
eq(dataComponents.projectId, params.scopes.projectId),
|
|
3245
|
-
eq(agentDataComponents.
|
|
3326
|
+
eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
3327
|
+
eq(agentDataComponents.agentId, params.scopes.agentId)
|
|
3246
3328
|
)
|
|
3247
3329
|
).orderBy(desc(dataComponents.createdAt));
|
|
3248
3330
|
};
|
|
@@ -3251,7 +3333,8 @@ var associateDataComponentWithAgent = (db) => async (params) => {
|
|
|
3251
3333
|
id: nanoid(),
|
|
3252
3334
|
tenantId: params.scopes.tenantId,
|
|
3253
3335
|
projectId: params.scopes.projectId,
|
|
3254
|
-
|
|
3336
|
+
graphId: params.scopes.graphId,
|
|
3337
|
+
agentId: params.scopes.agentId,
|
|
3255
3338
|
dataComponentId: params.dataComponentId
|
|
3256
3339
|
}).returning();
|
|
3257
3340
|
return association[0];
|
|
@@ -3261,7 +3344,8 @@ var removeDataComponentFromAgent = (db) => async (params) => {
|
|
|
3261
3344
|
and(
|
|
3262
3345
|
eq(agentDataComponents.tenantId, params.scopes.tenantId),
|
|
3263
3346
|
eq(agentDataComponents.projectId, params.scopes.projectId),
|
|
3264
|
-
eq(agentDataComponents.
|
|
3347
|
+
eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
3348
|
+
eq(agentDataComponents.agentId, params.scopes.agentId),
|
|
3265
3349
|
eq(agentDataComponents.dataComponentId, params.dataComponentId)
|
|
3266
3350
|
)
|
|
3267
3351
|
).returning();
|
|
@@ -3271,7 +3355,8 @@ var deleteAgentDataComponentRelationByAgent = (db) => async (params) => {
|
|
|
3271
3355
|
const result = await db.delete(agentDataComponents).where(
|
|
3272
3356
|
and(
|
|
3273
3357
|
eq(agentDataComponents.tenantId, params.scopes.tenantId),
|
|
3274
|
-
eq(agentDataComponents.
|
|
3358
|
+
eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
3359
|
+
eq(agentDataComponents.agentId, params.scopes.agentId)
|
|
3275
3360
|
)
|
|
3276
3361
|
);
|
|
3277
3362
|
return (result.rowsAffected || 0) > 0;
|
|
@@ -3293,7 +3378,8 @@ var isDataComponentAssociatedWithAgent = (db) => async (params) => {
|
|
|
3293
3378
|
and(
|
|
3294
3379
|
eq(agentDataComponents.tenantId, params.scopes.tenantId),
|
|
3295
3380
|
eq(agentDataComponents.projectId, params.scopes.projectId),
|
|
3296
|
-
eq(agentDataComponents.
|
|
3381
|
+
eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
3382
|
+
eq(agentDataComponents.agentId, params.scopes.agentId),
|
|
3297
3383
|
eq(agentDataComponents.dataComponentId, params.dataComponentId)
|
|
3298
3384
|
)
|
|
3299
3385
|
).limit(1);
|
|
@@ -3454,6 +3540,7 @@ var addToolToAgent = (db) => async (params) => {
|
|
|
3454
3540
|
id,
|
|
3455
3541
|
tenantId: params.scopes.tenantId,
|
|
3456
3542
|
projectId: params.scopes.projectId,
|
|
3543
|
+
graphId: params.scopes.graphId,
|
|
3457
3544
|
agentId: params.agentId,
|
|
3458
3545
|
toolId: params.toolId,
|
|
3459
3546
|
selectedTools: params.selectedTools,
|
|
@@ -3467,6 +3554,7 @@ var removeToolFromAgent = (db) => async (params) => {
|
|
|
3467
3554
|
and(
|
|
3468
3555
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
3469
3556
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
3557
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
3470
3558
|
eq(agentToolRelations.agentId, params.agentId),
|
|
3471
3559
|
eq(agentToolRelations.toolId, params.toolId)
|
|
3472
3560
|
)
|
|
@@ -3478,6 +3566,7 @@ var upsertAgentToolRelation = (db) => async (params) => {
|
|
|
3478
3566
|
where: and(
|
|
3479
3567
|
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
3480
3568
|
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
3569
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
3481
3570
|
eq(agentToolRelations.agentId, params.agentId),
|
|
3482
3571
|
eq(agentToolRelations.toolId, params.toolId)
|
|
3483
3572
|
)
|
|
@@ -3534,11 +3623,15 @@ var getHealthyToolsForAgent = (db) => async (params) => {
|
|
|
3534
3623
|
}).from(tools).innerJoin(
|
|
3535
3624
|
agentToolRelations,
|
|
3536
3625
|
and(
|
|
3537
|
-
eq(tools.
|
|
3538
|
-
eq(
|
|
3539
|
-
eq(agentToolRelations.tenantId, params.scopes.tenantId)
|
|
3626
|
+
eq(tools.tenantId, params.scopes.tenantId),
|
|
3627
|
+
eq(tools.projectId, params.scopes.projectId),
|
|
3628
|
+
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
3629
|
+
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
3630
|
+
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
3631
|
+
eq(agentToolRelations.agentId, params.scopes.agentId),
|
|
3632
|
+
eq(tools.id, agentToolRelations.toolId)
|
|
3540
3633
|
)
|
|
3541
|
-
).where(
|
|
3634
|
+
).where(eq(tools.status, "healthy"));
|
|
3542
3635
|
return healthyTools.map((row) => row.tool);
|
|
3543
3636
|
};
|
|
3544
3637
|
|
|
@@ -3633,59 +3726,37 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
3633
3726
|
validateGraphStructure(typed);
|
|
3634
3727
|
await applyExecutionLimitsInheritance(db, logger11, { tenantId, projectId }, typed);
|
|
3635
3728
|
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
3729
|
logger11.info(
|
|
3686
|
-
{
|
|
3687
|
-
"
|
|
3730
|
+
{},
|
|
3731
|
+
"CredentialReferences are project-scoped - skipping credential reference creation in graph"
|
|
3688
3732
|
);
|
|
3733
|
+
logger11.info({}, "Tools are project-scoped - skipping tool creation in graph");
|
|
3734
|
+
let finalGraphId;
|
|
3735
|
+
try {
|
|
3736
|
+
const graphId = typed.id || nanoid();
|
|
3737
|
+
logger11.info({ graphId }, "Creating agent graph metadata");
|
|
3738
|
+
const agentGraph2 = await upsertAgentGraph(db)({
|
|
3739
|
+
data: {
|
|
3740
|
+
id: graphId,
|
|
3741
|
+
tenantId,
|
|
3742
|
+
projectId,
|
|
3743
|
+
name: typed.name,
|
|
3744
|
+
defaultAgentId: typed.defaultAgentId,
|
|
3745
|
+
description: typed.description,
|
|
3746
|
+
contextConfigId: void 0,
|
|
3747
|
+
// Will be updated later if context config exists
|
|
3748
|
+
models: typed.models,
|
|
3749
|
+
statusUpdates: typed.statusUpdates,
|
|
3750
|
+
graphPrompt: typed.graphPrompt,
|
|
3751
|
+
stopWhen: typed.stopWhen
|
|
3752
|
+
}
|
|
3753
|
+
});
|
|
3754
|
+
finalGraphId = agentGraph2.id;
|
|
3755
|
+
logger11.info({ graphId: finalGraphId }, "Agent graph metadata created successfully");
|
|
3756
|
+
} catch (error) {
|
|
3757
|
+
logger11.error({ graphId: typed.id, error }, "Failed to create/update graph metadata");
|
|
3758
|
+
throw error;
|
|
3759
|
+
}
|
|
3689
3760
|
let contextConfigId;
|
|
3690
3761
|
if (typed.contextConfig) {
|
|
3691
3762
|
try {
|
|
@@ -3707,66 +3778,14 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
3707
3778
|
throw error;
|
|
3708
3779
|
}
|
|
3709
3780
|
}
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
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
|
-
}
|
|
3781
|
+
logger11.info(
|
|
3782
|
+
{},
|
|
3783
|
+
"DataComponents are project-scoped - skipping dataComponent creation in graph"
|
|
3784
|
+
);
|
|
3785
|
+
logger11.info(
|
|
3786
|
+
{},
|
|
3787
|
+
"ArtifactComponents are project-scoped - skipping artifactComponent creation in graph"
|
|
3788
|
+
);
|
|
3770
3789
|
const internalAgentPromises = Object.entries(typed.agents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([agentId, agentData]) => {
|
|
3771
3790
|
const internalAgent = agentData;
|
|
3772
3791
|
try {
|
|
@@ -3776,6 +3795,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
3776
3795
|
id: agentId,
|
|
3777
3796
|
tenantId,
|
|
3778
3797
|
projectId,
|
|
3798
|
+
graphId: finalGraphId,
|
|
3779
3799
|
name: internalAgent.name || "",
|
|
3780
3800
|
description: internalAgent.description || "",
|
|
3781
3801
|
prompt: internalAgent.prompt || "",
|
|
@@ -3804,6 +3824,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
3804
3824
|
id: agentId,
|
|
3805
3825
|
tenantId,
|
|
3806
3826
|
projectId,
|
|
3827
|
+
graphId: finalGraphId,
|
|
3807
3828
|
name: externalAgent.name,
|
|
3808
3829
|
description: externalAgent.description || "",
|
|
3809
3830
|
baseUrl: externalAgent.baseUrl,
|
|
@@ -3822,29 +3843,24 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
3822
3843
|
([_, agentData]) => isExternalAgent(agentData)
|
|
3823
3844
|
).length;
|
|
3824
3845
|
logger11.info({ externalAgentCount }, "All external agents created/updated successfully");
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
projectId,
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
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;
|
|
3846
|
+
if (contextConfigId) {
|
|
3847
|
+
try {
|
|
3848
|
+
logger11.info(
|
|
3849
|
+
{ graphId: finalGraphId, contextConfigId },
|
|
3850
|
+
"Updating graph with context config"
|
|
3851
|
+
);
|
|
3852
|
+
await updateAgentGraph(db)({
|
|
3853
|
+
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
3854
|
+
data: { contextConfigId }
|
|
3855
|
+
});
|
|
3856
|
+
logger11.info({ graphId: finalGraphId }, "Graph updated with context config");
|
|
3857
|
+
} catch (error) {
|
|
3858
|
+
logger11.error(
|
|
3859
|
+
{ graphId: finalGraphId, error },
|
|
3860
|
+
"Failed to update graph with context config"
|
|
3861
|
+
);
|
|
3862
|
+
throw error;
|
|
3863
|
+
}
|
|
3848
3864
|
}
|
|
3849
3865
|
const agentToolPromises = [];
|
|
3850
3866
|
for (const [agentId, agentData] of Object.entries(typed.agents)) {
|
|
@@ -3856,7 +3872,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
3856
3872
|
const selectedTools = agentData.selectedTools?.[toolId];
|
|
3857
3873
|
logger11.info({ agentId, toolId }, "Processing agent-tool relation");
|
|
3858
3874
|
await upsertAgentToolRelation(db)({
|
|
3859
|
-
scopes: { tenantId, projectId },
|
|
3875
|
+
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
3860
3876
|
agentId,
|
|
3861
3877
|
toolId,
|
|
3862
3878
|
selectedTools
|
|
@@ -3887,8 +3903,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
3887
3903
|
"Processing agent-data component relation"
|
|
3888
3904
|
);
|
|
3889
3905
|
await upsertAgentDataComponentRelation(db)({
|
|
3890
|
-
scopes: { tenantId, projectId },
|
|
3891
|
-
agentId,
|
|
3906
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
3892
3907
|
dataComponentId
|
|
3893
3908
|
});
|
|
3894
3909
|
logger11.info(
|
|
@@ -3920,8 +3935,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
3920
3935
|
"Processing agent-artifact component relation"
|
|
3921
3936
|
);
|
|
3922
3937
|
await upsertAgentArtifactComponentRelation(db)({
|
|
3923
|
-
scopes: { tenantId, projectId },
|
|
3924
|
-
agentId,
|
|
3938
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
3925
3939
|
artifactComponentId
|
|
3926
3940
|
});
|
|
3927
3941
|
logger11.info(
|
|
@@ -4017,8 +4031,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4017
4031
|
"All agent relations created"
|
|
4018
4032
|
);
|
|
4019
4033
|
const createdGraph = await getFullGraphDefinition(db)({
|
|
4020
|
-
scopes: { tenantId, projectId }
|
|
4021
|
-
graphId: finalGraphId
|
|
4034
|
+
scopes: { tenantId, projectId, graphId: finalGraphId }
|
|
4022
4035
|
});
|
|
4023
4036
|
if (!createdGraph) {
|
|
4024
4037
|
throw new Error("Failed to retrieve created graph");
|
|
@@ -4041,8 +4054,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4041
4054
|
{
|
|
4042
4055
|
tenantId,
|
|
4043
4056
|
graphId: typedGraphDefinition.id,
|
|
4044
|
-
agentCount: Object.keys(typedGraphDefinition.agents).length
|
|
4045
|
-
toolCount: Object.keys(typedGraphDefinition.tools || {}).length
|
|
4057
|
+
agentCount: Object.keys(typedGraphDefinition.agents).length
|
|
4046
4058
|
},
|
|
4047
4059
|
"Updating full graph in database"
|
|
4048
4060
|
);
|
|
@@ -4055,8 +4067,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4055
4067
|
);
|
|
4056
4068
|
try {
|
|
4057
4069
|
const existingGraph = await getAgentGraphById(db)({
|
|
4058
|
-
scopes: { tenantId, projectId }
|
|
4059
|
-
graphId: typedGraphDefinition.id
|
|
4070
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
4060
4071
|
});
|
|
4061
4072
|
if (!existingGraph) {
|
|
4062
4073
|
logger11.info(
|
|
@@ -4066,65 +4077,40 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4066
4077
|
return createFullGraphServerSide(db)(scopes, graphData);
|
|
4067
4078
|
}
|
|
4068
4079
|
const existingGraphModels = existingGraph.models;
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
const
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
);
|
|
4093
|
-
throw error;
|
|
4094
|
-
}
|
|
4080
|
+
logger11.info(
|
|
4081
|
+
{},
|
|
4082
|
+
"CredentialReferences are project-scoped - skipping credential reference update in graph"
|
|
4083
|
+
);
|
|
4084
|
+
logger11.info({}, "Tools are project-scoped - skipping tool creation in graph update");
|
|
4085
|
+
let finalGraphId;
|
|
4086
|
+
try {
|
|
4087
|
+
const graphId = typedGraphDefinition.id || nanoid();
|
|
4088
|
+
logger11.info({ graphId }, "Getting/creating agent graph metadata");
|
|
4089
|
+
const agentGraph2 = await upsertAgentGraph(db)({
|
|
4090
|
+
data: {
|
|
4091
|
+
id: graphId,
|
|
4092
|
+
tenantId,
|
|
4093
|
+
projectId,
|
|
4094
|
+
name: typedGraphDefinition.name,
|
|
4095
|
+
defaultAgentId: typedGraphDefinition.defaultAgentId,
|
|
4096
|
+
description: typedGraphDefinition.description,
|
|
4097
|
+
contextConfigId: void 0,
|
|
4098
|
+
// Will be updated later if context config exists
|
|
4099
|
+
models: typedGraphDefinition.models,
|
|
4100
|
+
statusUpdates: typedGraphDefinition.statusUpdates,
|
|
4101
|
+
graphPrompt: typedGraphDefinition.graphPrompt,
|
|
4102
|
+
stopWhen: typedGraphDefinition.stopWhen
|
|
4095
4103
|
}
|
|
4104
|
+
});
|
|
4105
|
+
finalGraphId = agentGraph2.id;
|
|
4106
|
+
logger11.info({ graphId: finalGraphId }, "Agent graph metadata ready");
|
|
4107
|
+
} catch (error) {
|
|
4108
|
+
logger11.error(
|
|
4109
|
+
{ graphId: typedGraphDefinition.id, error },
|
|
4110
|
+
"Failed to get/update graph metadata"
|
|
4096
4111
|
);
|
|
4097
|
-
|
|
4098
|
-
logger11.info(
|
|
4099
|
-
{
|
|
4100
|
-
credentialReferencesCount: Object.keys(typedGraphDefinition.credentialReferences).length
|
|
4101
|
-
},
|
|
4102
|
-
"All credential references created/updated successfully"
|
|
4103
|
-
);
|
|
4112
|
+
throw error;
|
|
4104
4113
|
}
|
|
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
4114
|
let contextConfigId;
|
|
4129
4115
|
if (typedGraphDefinition.contextConfig) {
|
|
4130
4116
|
try {
|
|
@@ -4149,66 +4135,11 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4149
4135
|
throw error;
|
|
4150
4136
|
}
|
|
4151
4137
|
}
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
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
|
-
}
|
|
4138
|
+
logger11.info({}, "DataComponents are project-scoped - skipping dataComponent update in graph");
|
|
4139
|
+
logger11.info(
|
|
4140
|
+
{},
|
|
4141
|
+
"ArtifactComponents are project-scoped - skipping artifactComponent update in graph"
|
|
4142
|
+
);
|
|
4212
4143
|
const internalAgentPromises = Object.entries(typedGraphDefinition.agents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([agentId, agentData]) => {
|
|
4213
4144
|
const internalAgent = agentData;
|
|
4214
4145
|
let existingAgent = null;
|
|
@@ -4232,17 +4163,17 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4232
4163
|
const modelTypes = ["base", "structuredOutput", "summarizer"];
|
|
4233
4164
|
const cascadedModels = { ...finalModelSettings };
|
|
4234
4165
|
for (const modelType of modelTypes) {
|
|
4235
|
-
if (agentModels[modelType]?.model && existingGraphModels?.[modelType]?.model && agentModels[modelType].model === existingGraphModels[modelType].model && graphModels[modelType]
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
};
|
|
4166
|
+
if (agentModels[modelType]?.model && existingGraphModels?.[modelType]?.model && agentModels[modelType].model === existingGraphModels[modelType].model && graphModels[modelType] && // Model name changed
|
|
4167
|
+
(graphModels[modelType].model !== existingGraphModels[modelType].model || // OR providerOptions changed
|
|
4168
|
+
JSON.stringify(graphModels[modelType].providerOptions) !== JSON.stringify(existingGraphModels[modelType].providerOptions))) {
|
|
4169
|
+
cascadedModels[modelType] = graphModels[modelType];
|
|
4240
4170
|
logger11.info(
|
|
4241
4171
|
{
|
|
4242
4172
|
agentId,
|
|
4243
4173
|
modelType,
|
|
4244
4174
|
oldModel: agentModels[modelType].model,
|
|
4245
|
-
newModel: graphModels[modelType].model
|
|
4175
|
+
newModel: graphModels[modelType].model,
|
|
4176
|
+
hasProviderOptions: !!graphModels[modelType].providerOptions
|
|
4246
4177
|
},
|
|
4247
4178
|
"Cascading model change from graph to agent"
|
|
4248
4179
|
);
|
|
@@ -4257,6 +4188,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4257
4188
|
id: agentId,
|
|
4258
4189
|
tenantId,
|
|
4259
4190
|
projectId,
|
|
4191
|
+
graphId: finalGraphId,
|
|
4260
4192
|
name: internalAgent.name || "",
|
|
4261
4193
|
description: internalAgent.description || "",
|
|
4262
4194
|
prompt: internalAgent.prompt || "",
|
|
@@ -4285,6 +4217,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4285
4217
|
id: agentId,
|
|
4286
4218
|
tenantId,
|
|
4287
4219
|
projectId,
|
|
4220
|
+
graphId: finalGraphId,
|
|
4288
4221
|
name: externalAgent.name,
|
|
4289
4222
|
description: externalAgent.description || "",
|
|
4290
4223
|
baseUrl: externalAgent.baseUrl,
|
|
@@ -4304,8 +4237,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4304
4237
|
).length;
|
|
4305
4238
|
logger11.info({ externalAgentCount }, "All external agents created/updated successfully");
|
|
4306
4239
|
await updateAgentGraph(db)({
|
|
4307
|
-
scopes: { tenantId, projectId },
|
|
4308
|
-
graphId: typedGraphDefinition.id,
|
|
4240
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id },
|
|
4309
4241
|
data: {
|
|
4310
4242
|
name: typedGraphDefinition.name,
|
|
4311
4243
|
defaultAgentId: typedGraphDefinition.defaultAgentId,
|
|
@@ -4320,8 +4252,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4320
4252
|
logger11.info({ graphId: typedGraphDefinition.id }, "Graph metadata updated");
|
|
4321
4253
|
for (const agentId of Object.keys(typedGraphDefinition.agents)) {
|
|
4322
4254
|
await deleteAgentToolRelationByAgent(db)({
|
|
4323
|
-
scopes: { tenantId, projectId }
|
|
4324
|
-
agentId
|
|
4255
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
|
|
4325
4256
|
});
|
|
4326
4257
|
}
|
|
4327
4258
|
const agentToolPromises = [];
|
|
@@ -4333,7 +4264,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4333
4264
|
try {
|
|
4334
4265
|
const selectedTools = agentData.selectedTools?.[toolId];
|
|
4335
4266
|
await createAgentToolRelation(db)({
|
|
4336
|
-
scopes: { tenantId, projectId },
|
|
4267
|
+
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
4337
4268
|
data: {
|
|
4338
4269
|
agentId,
|
|
4339
4270
|
toolId,
|
|
@@ -4356,8 +4287,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4356
4287
|
);
|
|
4357
4288
|
for (const agentId of Object.keys(typedGraphDefinition.agents)) {
|
|
4358
4289
|
await deleteAgentDataComponentRelationByAgent(db)({
|
|
4359
|
-
scopes: { tenantId, projectId }
|
|
4360
|
-
agentId
|
|
4290
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
|
|
4361
4291
|
});
|
|
4362
4292
|
}
|
|
4363
4293
|
const agentDataComponentPromises = [];
|
|
@@ -4368,8 +4298,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4368
4298
|
(async () => {
|
|
4369
4299
|
try {
|
|
4370
4300
|
await associateDataComponentWithAgent(db)({
|
|
4371
|
-
scopes: { tenantId, projectId },
|
|
4372
|
-
agentId,
|
|
4301
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
4373
4302
|
dataComponentId
|
|
4374
4303
|
});
|
|
4375
4304
|
logger11.info({ agentId, dataComponentId }, "Agent-dataComponent relation created");
|
|
@@ -4391,8 +4320,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4391
4320
|
);
|
|
4392
4321
|
for (const agentId of Object.keys(typedGraphDefinition.agents)) {
|
|
4393
4322
|
await deleteAgentArtifactComponentRelationByAgent(db)({
|
|
4394
|
-
scopes: { tenantId, projectId }
|
|
4395
|
-
agentId
|
|
4323
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
|
|
4396
4324
|
});
|
|
4397
4325
|
}
|
|
4398
4326
|
const agentArtifactComponentPromises = [];
|
|
@@ -4403,8 +4331,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4403
4331
|
(async () => {
|
|
4404
4332
|
try {
|
|
4405
4333
|
await associateArtifactComponentWithAgent(db)({
|
|
4406
|
-
scopes: { tenantId, projectId },
|
|
4407
|
-
agentId,
|
|
4334
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
4408
4335
|
artifactComponentId
|
|
4409
4336
|
});
|
|
4410
4337
|
logger11.info(
|
|
@@ -4428,8 +4355,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4428
4355
|
"All agent-artifactComponent relations updated"
|
|
4429
4356
|
);
|
|
4430
4357
|
await deleteAgentRelationsByGraph(db)({
|
|
4431
|
-
scopes: { tenantId, projectId }
|
|
4432
|
-
graphId: typedGraphDefinition.id
|
|
4358
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
4433
4359
|
});
|
|
4434
4360
|
const agentRelationPromises = [];
|
|
4435
4361
|
for (const [agentId, agentData] of Object.entries(typedGraphDefinition.agents)) {
|
|
@@ -4505,8 +4431,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4505
4431
|
"All agent relations updated"
|
|
4506
4432
|
);
|
|
4507
4433
|
const updatedGraph = await getFullGraphDefinition(db)({
|
|
4508
|
-
scopes: { tenantId, projectId }
|
|
4509
|
-
graphId: typedGraphDefinition.id
|
|
4434
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
4510
4435
|
});
|
|
4511
4436
|
if (!updatedGraph) {
|
|
4512
4437
|
throw new Error("Failed to retrieve updated graph");
|
|
@@ -4519,22 +4444,21 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
4519
4444
|
}
|
|
4520
4445
|
};
|
|
4521
4446
|
var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
4522
|
-
const { scopes
|
|
4447
|
+
const { scopes } = params;
|
|
4523
4448
|
const { tenantId, projectId } = scopes;
|
|
4524
|
-
logger11.info({ tenantId, graphId }, "Retrieving full graph definition");
|
|
4449
|
+
logger11.info({ tenantId, graphId: scopes.graphId }, "Retrieving full graph definition");
|
|
4525
4450
|
try {
|
|
4526
4451
|
const graph = await getFullGraphDefinition(db)({
|
|
4527
|
-
scopes: { tenantId, projectId }
|
|
4528
|
-
graphId
|
|
4452
|
+
scopes: { tenantId, projectId, graphId: scopes.graphId }
|
|
4529
4453
|
});
|
|
4530
4454
|
if (!graph) {
|
|
4531
|
-
logger11.info({ tenantId, graphId }, "Graph not found");
|
|
4455
|
+
logger11.info({ tenantId, graphId: scopes.graphId }, "Graph not found");
|
|
4532
4456
|
return null;
|
|
4533
4457
|
}
|
|
4534
4458
|
logger11.info(
|
|
4535
4459
|
{
|
|
4536
4460
|
tenantId,
|
|
4537
|
-
graphId,
|
|
4461
|
+
graphId: scopes.graphId,
|
|
4538
4462
|
agentCount: Object.keys(graph.agents).length
|
|
4539
4463
|
},
|
|
4540
4464
|
"Full graph retrieved successfully"
|
|
@@ -4544,7 +4468,7 @@ var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
|
4544
4468
|
logger11.error(
|
|
4545
4469
|
{
|
|
4546
4470
|
tenantId,
|
|
4547
|
-
graphId,
|
|
4471
|
+
graphId: scopes.graphId,
|
|
4548
4472
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
4549
4473
|
},
|
|
4550
4474
|
"Failed to retrieve full graph"
|
|
@@ -4553,29 +4477,25 @@ var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
|
4553
4477
|
}
|
|
4554
4478
|
};
|
|
4555
4479
|
var deleteFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
4556
|
-
const {
|
|
4557
|
-
const { tenantId, projectId } = scopes;
|
|
4480
|
+
const { tenantId, projectId, graphId } = params.scopes;
|
|
4558
4481
|
logger11.info({ tenantId, graphId }, "Deleting full graph and related entities");
|
|
4559
4482
|
try {
|
|
4560
4483
|
const graph = await getFullGraphDefinition(db)({
|
|
4561
|
-
scopes: { tenantId, projectId }
|
|
4562
|
-
graphId
|
|
4484
|
+
scopes: { tenantId, projectId, graphId }
|
|
4563
4485
|
});
|
|
4564
4486
|
if (!graph) {
|
|
4565
4487
|
logger11.info({ tenantId, graphId }, "Graph not found for deletion");
|
|
4566
4488
|
return false;
|
|
4567
4489
|
}
|
|
4568
4490
|
await deleteAgentRelationsByGraph(db)({
|
|
4569
|
-
scopes: { tenantId, projectId }
|
|
4570
|
-
graphId
|
|
4491
|
+
scopes: { tenantId, projectId, graphId }
|
|
4571
4492
|
});
|
|
4572
4493
|
logger11.info({ tenantId, graphId }, "Agent relations deleted");
|
|
4573
4494
|
const agentIds = Object.keys(graph.agents);
|
|
4574
4495
|
if (agentIds.length > 0) {
|
|
4575
4496
|
for (const agentId of agentIds) {
|
|
4576
4497
|
await deleteAgentToolRelationByAgent(db)({
|
|
4577
|
-
scopes: { tenantId, projectId }
|
|
4578
|
-
agentId
|
|
4498
|
+
scopes: { tenantId, projectId, graphId, agentId }
|
|
4579
4499
|
});
|
|
4580
4500
|
}
|
|
4581
4501
|
logger11.info(
|
|
@@ -4584,8 +4504,7 @@ var deleteFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
|
4584
4504
|
);
|
|
4585
4505
|
}
|
|
4586
4506
|
await deleteAgentGraph(db)({
|
|
4587
|
-
scopes: { tenantId, projectId }
|
|
4588
|
-
graphId
|
|
4507
|
+
scopes: { tenantId, projectId, graphId }
|
|
4589
4508
|
});
|
|
4590
4509
|
logger11.info({ tenantId, graphId }, "Graph metadata deleted");
|
|
4591
4510
|
logger11.info({ tenantId, graphId }, "Full graph deleted successfully");
|
|
@@ -5294,8 +5213,7 @@ var createFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
|
|
|
5294
5213
|
db,
|
|
5295
5214
|
logger11
|
|
5296
5215
|
)({
|
|
5297
|
-
scopes: { tenantId, projectId: typed.id }
|
|
5298
|
-
projectId: typed.id
|
|
5216
|
+
scopes: { tenantId, projectId: typed.id }
|
|
5299
5217
|
});
|
|
5300
5218
|
} catch (error) {
|
|
5301
5219
|
logger11.error(
|
|
@@ -5601,8 +5519,7 @@ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
|
|
|
5601
5519
|
db,
|
|
5602
5520
|
logger11
|
|
5603
5521
|
)({
|
|
5604
|
-
scopes: { tenantId, projectId: typed.id }
|
|
5605
|
-
projectId: typed.id
|
|
5522
|
+
scopes: { tenantId, projectId: typed.id }
|
|
5606
5523
|
});
|
|
5607
5524
|
} catch (error) {
|
|
5608
5525
|
logger11.error(
|
|
@@ -5617,8 +5534,8 @@ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
|
|
|
5617
5534
|
}
|
|
5618
5535
|
};
|
|
5619
5536
|
var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
5620
|
-
const { scopes
|
|
5621
|
-
const { tenantId } = scopes;
|
|
5537
|
+
const { scopes } = params;
|
|
5538
|
+
const { tenantId, projectId } = scopes;
|
|
5622
5539
|
logger11.info({ tenantId, projectId }, "Retrieving full project definition");
|
|
5623
5540
|
try {
|
|
5624
5541
|
const project = await getProject(db)({
|
|
@@ -5772,18 +5689,10 @@ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
|
5772
5689
|
"Retrieving full graph definition"
|
|
5773
5690
|
);
|
|
5774
5691
|
const fullGraph = await getFullGraph(db)({
|
|
5775
|
-
scopes: { tenantId, projectId }
|
|
5776
|
-
graphId: graph.id
|
|
5692
|
+
scopes: { tenantId, projectId, graphId: graph.id }
|
|
5777
5693
|
});
|
|
5778
5694
|
if (fullGraph) {
|
|
5779
|
-
const {
|
|
5780
|
-
tools: _tools,
|
|
5781
|
-
dataComponents: _dataComponents,
|
|
5782
|
-
artifactComponents: _artifactComponents,
|
|
5783
|
-
contextConfig: _contextConfig,
|
|
5784
|
-
credentialReferences: _credentialReferences,
|
|
5785
|
-
...graphWithoutProjectResources
|
|
5786
|
-
} = fullGraph;
|
|
5695
|
+
const { contextConfig: _contextConfig, ...graphWithoutProjectResources } = fullGraph;
|
|
5787
5696
|
graphs[graph.id] = graphWithoutProjectResources;
|
|
5788
5697
|
logger11.info(
|
|
5789
5698
|
{ tenantId, projectId, graphId: graph.id },
|
|
@@ -5838,16 +5747,15 @@ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
|
5838
5747
|
}
|
|
5839
5748
|
};
|
|
5840
5749
|
var deleteFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
5841
|
-
const { scopes
|
|
5842
|
-
const { tenantId } = scopes;
|
|
5750
|
+
const { scopes } = params;
|
|
5751
|
+
const { tenantId, projectId } = scopes;
|
|
5843
5752
|
logger11.info({ tenantId, projectId }, "Deleting full project and related entities");
|
|
5844
5753
|
try {
|
|
5845
5754
|
const project = await getFullProject(
|
|
5846
5755
|
db,
|
|
5847
5756
|
logger11
|
|
5848
5757
|
)({
|
|
5849
|
-
scopes: { tenantId, projectId }
|
|
5850
|
-
projectId
|
|
5758
|
+
scopes: { tenantId, projectId }
|
|
5851
5759
|
});
|
|
5852
5760
|
if (!project) {
|
|
5853
5761
|
logger11.info({ tenantId, projectId }, "Project not found for deletion");
|
|
@@ -5869,8 +5777,7 @@ var deleteFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
|
5869
5777
|
db,
|
|
5870
5778
|
logger11
|
|
5871
5779
|
)({
|
|
5872
|
-
scopes: { tenantId, projectId }
|
|
5873
|
-
graphId
|
|
5780
|
+
scopes: { tenantId, projectId, graphId }
|
|
5874
5781
|
});
|
|
5875
5782
|
logger11.info(
|
|
5876
5783
|
{ tenantId, projectId, graphId },
|
|
@@ -7285,8 +7192,7 @@ async function validateRequestContext({
|
|
|
7285
7192
|
}) {
|
|
7286
7193
|
try {
|
|
7287
7194
|
const agentGraph2 = await getAgentGraphWithDefaultAgent(dbClient)({
|
|
7288
|
-
scopes: { tenantId, projectId }
|
|
7289
|
-
graphId
|
|
7195
|
+
scopes: { tenantId, projectId, graphId }
|
|
7290
7196
|
});
|
|
7291
7197
|
if (!agentGraph2?.contextConfigId) {
|
|
7292
7198
|
logger7.debug({ graphId }, "No context config found for graph, skipping validation");
|
|
@@ -7426,13 +7332,11 @@ function contextValidationMiddleware(dbClient) {
|
|
|
7426
7332
|
},
|
|
7427
7333
|
"Request context validation failed"
|
|
7428
7334
|
);
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
400
|
|
7435
|
-
);
|
|
7335
|
+
const errorMessage = `Invalid request context: ${validationResult.errors.map((e) => `${e.field}: ${e.message}`).join(", ")}`;
|
|
7336
|
+
throw createApiError({
|
|
7337
|
+
code: "bad_request",
|
|
7338
|
+
message: errorMessage
|
|
7339
|
+
});
|
|
7436
7340
|
}
|
|
7437
7341
|
c.set("validatedContext", validationResult.validatedContext);
|
|
7438
7342
|
logger7.debug(
|
|
@@ -7451,13 +7355,10 @@ function contextValidationMiddleware(dbClient) {
|
|
|
7451
7355
|
},
|
|
7452
7356
|
"Context validation middleware error"
|
|
7453
7357
|
);
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
},
|
|
7459
|
-
500
|
|
7460
|
-
);
|
|
7358
|
+
throw createApiError({
|
|
7359
|
+
code: "internal_server_error",
|
|
7360
|
+
message: "Context validation failed"
|
|
7361
|
+
});
|
|
7461
7362
|
}
|
|
7462
7363
|
};
|
|
7463
7364
|
}
|
|
@@ -7833,7 +7734,15 @@ async function handleContextConfigChange(tenantId, projectId, conversationId, gr
|
|
|
7833
7734
|
);
|
|
7834
7735
|
}
|
|
7835
7736
|
}
|
|
7836
|
-
async function handleContextResolution(
|
|
7737
|
+
async function handleContextResolution({
|
|
7738
|
+
tenantId,
|
|
7739
|
+
projectId,
|
|
7740
|
+
graphId,
|
|
7741
|
+
conversationId,
|
|
7742
|
+
requestContext,
|
|
7743
|
+
dbClient,
|
|
7744
|
+
credentialStores
|
|
7745
|
+
}) {
|
|
7837
7746
|
return tracer.startActiveSpan(
|
|
7838
7747
|
"context.handle_context_resolution",
|
|
7839
7748
|
{
|
|
@@ -7846,8 +7755,7 @@ async function handleContextResolution(tenantId, projectId, conversationId, grap
|
|
|
7846
7755
|
let trigger;
|
|
7847
7756
|
try {
|
|
7848
7757
|
agentGraph2 = await getAgentGraphWithDefaultAgent(dbClient)({
|
|
7849
|
-
scopes: { tenantId, projectId }
|
|
7850
|
-
graphId
|
|
7758
|
+
scopes: { tenantId, projectId, graphId }
|
|
7851
7759
|
});
|
|
7852
7760
|
if (!agentGraph2?.contextConfigId) {
|
|
7853
7761
|
logger9.debug({ graphId }, "No context config found for graph");
|
|
@@ -8548,7 +8456,7 @@ function createDefaultCredentialStores() {
|
|
|
8548
8456
|
if (process.env.NANGO_SECRET_KEY) {
|
|
8549
8457
|
stores.push(
|
|
8550
8458
|
createNangoCredentialStore("nango-default", {
|
|
8551
|
-
apiUrl: process.env.
|
|
8459
|
+
apiUrl: process.env.NANGO_SERVER_URL || "https://api.nango.dev",
|
|
8552
8460
|
secretKey: process.env.NANGO_SECRET_KEY
|
|
8553
8461
|
})
|
|
8554
8462
|
);
|
|
@@ -8570,12 +8478,13 @@ var loadEnvironmentFiles = () => {
|
|
|
8570
8478
|
}
|
|
8571
8479
|
const userConfigPath = path.join(os.homedir(), ".inkeep", "config");
|
|
8572
8480
|
if (fs.existsSync(userConfigPath)) {
|
|
8573
|
-
dotenv.config({ path: userConfigPath, override: true });
|
|
8481
|
+
dotenv.config({ path: userConfigPath, override: true, quiet: true });
|
|
8574
8482
|
}
|
|
8575
8483
|
if (environmentFiles.length > 0) {
|
|
8576
8484
|
dotenv.config({
|
|
8577
8485
|
path: environmentFiles,
|
|
8578
|
-
override: false
|
|
8486
|
+
override: false,
|
|
8487
|
+
quiet: true
|
|
8579
8488
|
});
|
|
8580
8489
|
expand({ processEnv: process.env });
|
|
8581
8490
|
}
|
|
@@ -8603,4 +8512,4 @@ ${error.message}`
|
|
|
8603
8512
|
};
|
|
8604
8513
|
parseEnv();
|
|
8605
8514
|
|
|
8606
|
-
export {
|
|
8515
|
+
export { ContextCache, ContextConfigBuilder, ContextFetcher, ContextResolver, CredentialStoreRegistry, CredentialStuffer, ERROR_DOCS_BASE_URL, ErrorCode, HTTP_REQUEST_PARTS, InMemoryCredentialStore, KeyChainStore, McpClient, NangoCredentialStore, PinoLogger, TemplateEngine, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, 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 };
|