@inkeep/agents-core 0.0.0-dev-20251009192735 → 0.0.0-dev-20251009215610
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/README.md +2 -2
- package/dist/{chunk-VPJ6Z5QZ.js → chunk-5LRSB445.js} +115 -118
- package/dist/{chunk-TO2HNKGP.js → chunk-BVURASVM.js} +74 -110
- package/dist/chunk-TCLX6C3C.js +271 -0
- package/dist/chunk-ZSQFZL3Y.js +173 -0
- package/dist/client-exports.cjs +483 -225
- package/dist/client-exports.d.cts +6 -5
- package/dist/client-exports.d.ts +6 -5
- package/dist/client-exports.js +5 -4
- package/dist/db/schema.cjs +114 -117
- package/dist/db/schema.d.cts +2 -2
- package/dist/db/schema.d.ts +2 -2
- package/dist/db/schema.js +1 -1
- package/dist/index.cjs +1687 -1360
- package/dist/index.d.cts +1530 -1524
- package/dist/index.d.ts +1530 -1524
- package/dist/index.js +1016 -989
- package/dist/{schema-Ct2NlO81.d.cts → schema-B1rukNyF.d.ts} +118 -137
- package/dist/{schema-BQk_FMBV.d.ts → schema-BIYOOKX_.d.cts} +118 -137
- package/dist/signoz-queries-CifqdbnO.d.cts +269 -0
- package/dist/signoz-queries-CifqdbnO.d.ts +269 -0
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/{utility-s9c5CVOe.d.cts → utility-BEeDGMP9.d.cts} +226 -297
- package/dist/{utility-s9c5CVOe.d.ts → utility-BEeDGMP9.d.ts} +226 -297
- package/dist/validation/index.cjs +243 -238
- package/dist/validation/index.d.cts +76 -4
- package/dist/validation/index.d.ts +76 -4
- package/dist/validation/index.js +2 -2
- package/drizzle/0005_wide_shriek.sql +127 -0
- package/drizzle/meta/0005_snapshot.json +2558 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +1 -1
- package/dist/chunk-L53XWAYG.js +0 -134
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, DATA_SOURCES, DATA_TYPES, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, FIELD_TYPES, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, TOOL_NAMES, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, UNKNOWN_VALUE } from './chunk-TCLX6C3C.js';
|
|
1
2
|
export { TaskState } from './chunk-H2F72PDA.js';
|
|
2
3
|
import { getLogger, convertZodToJsonSchema } from './chunk-R2EERZSW.js';
|
|
3
4
|
export { PinoLogger, convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, extractPreviewFields, getLogger, isZodSchema, loggerFactory, preview } from './chunk-R2EERZSW.js';
|
|
4
|
-
import { validateAndTypeGraphData, validateGraphStructure, isInternalAgent, isExternalAgent } from './chunk-
|
|
5
|
-
export { generateIdFromName, isExternalAgent, isInternalAgent, isValidResourceId, validateAgentRelationships, validateAndTypeGraphData, validateArtifactComponentReferences, validateDataComponentReferences, validateGraphStructure, validateToolReferences } from './chunk-
|
|
6
|
-
import { ContextConfigApiUpdateSchema, validatePropsAsJsonSchema } from './chunk-
|
|
7
|
-
export {
|
|
8
|
-
import { schema_exports,
|
|
9
|
-
export {
|
|
5
|
+
import { validateAndTypeGraphData, validateGraphStructure, isInternalAgent, isExternalAgent } from './chunk-ZSQFZL3Y.js';
|
|
6
|
+
export { A2AMessageMetadataSchema, DataOperationDetailsSchema, DataOperationEventSchema, DelegationReturnedDataSchema, DelegationSentDataSchema, TransferDataSchema, generateIdFromName, isExternalAgent, isInternalAgent, isValidResourceId, validateAgentRelationships, validateAndTypeGraphData, validateArtifactComponentReferences, validateDataComponentReferences, validateGraphStructure, validateToolReferences } from './chunk-ZSQFZL3Y.js';
|
|
7
|
+
import { ContextConfigApiUpdateSchema, validatePropsAsJsonSchema } from './chunk-BVURASVM.js';
|
|
8
|
+
export { AgentArtifactComponentApiInsertSchema, AgentArtifactComponentApiSelectSchema, AgentArtifactComponentApiUpdateSchema, AgentArtifactComponentInsertSchema, AgentArtifactComponentSelectSchema, AgentArtifactComponentUpdateSchema, AgentDataComponentApiInsertSchema, AgentDataComponentApiSelectSchema, AgentDataComponentApiUpdateSchema, AgentDataComponentInsertSchema, AgentDataComponentSelectSchema, AgentDataComponentUpdateSchema, AgentGraphApiInsertSchema, AgentGraphApiSelectSchema, AgentGraphApiUpdateSchema, AgentGraphInsertSchema, AgentGraphSelectSchema, AgentGraphUpdateSchema, AgentRelationApiInsertSchema, AgentRelationApiSelectSchema, AgentRelationApiUpdateSchema, AgentRelationInsertSchema, AgentRelationQuerySchema, AgentRelationSelectSchema, AgentRelationUpdateSchema, AgentStopWhenSchema, AgentToolRelationApiInsertSchema, AgentToolRelationApiSelectSchema, AgentToolRelationApiUpdateSchema, AgentToolRelationInsertSchema, AgentToolRelationSelectSchema, AgentToolRelationUpdateSchema, AllAgentSchema, ApiKeyApiCreationResponseSchema, ApiKeyApiInsertSchema, ApiKeyApiSelectSchema, ApiKeyApiUpdateSchema, ApiKeyInsertSchema, ApiKeySelectSchema, ApiKeyUpdateSchema, ArtifactComponentApiInsertSchema, ArtifactComponentApiSelectSchema, ArtifactComponentApiUpdateSchema, ArtifactComponentInsertSchema, ArtifactComponentSelectSchema, ArtifactComponentUpdateSchema, CanUseItemSchema, 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, FullProjectDefinitionSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, FunctionInsertSchema, FunctionSelectSchema, FunctionToolConfigSchema, FunctionUpdateSchema, GraphStopWhenSchema, GraphWithinContextOfProjectSchema, HeadersScopeSchema, 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, SandboxConfigSchema, SingleResponseSchema, StatusComponentSchema, StatusUpdateSchema, StopWhenSchema, SubAgentApiInsertSchema, SubAgentApiSelectSchema, SubAgentApiUpdateSchema, SubAgentInsertSchema, SubAgentSelectSchema, SubAgentUpdateSchema, TaskApiInsertSchema, TaskApiSelectSchema, TaskApiUpdateSchema, TaskInsertSchema, TaskRelationApiInsertSchema, TaskRelationApiSelectSchema, TaskRelationApiUpdateSchema, TaskRelationInsertSchema, TaskRelationSelectSchema, TaskRelationUpdateSchema, TaskSelectSchema, TaskUpdateSchema, TenantIdParamsSchema, TenantParamsSchema, TenantProjectGraphIdParamsSchema, TenantProjectGraphParamsSchema, TenantProjectGraphSubAgentIdParamsSchema, TenantProjectGraphSubAgentParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsertSchema, ToolApiSelectSchema, ToolApiUpdateSchema, ToolInsertSchema, ToolSelectSchema, ToolStatusSchema, ToolUpdateSchema, URL_SAFE_ID_PATTERN, resourceIdSchema, validatePropsAsJsonSchema } from './chunk-BVURASVM.js';
|
|
9
|
+
import { schema_exports, contextConfigs, externalAgents, functions, subAgentRelations, subAgents, subAgentToolRelations, tools, credentialReferences, agentGraph, subAgentDataComponents, subAgentArtifactComponents, dataComponents, artifactComponents, projects, apiKeys, contextCache, conversations, messages, ledgerArtifacts, tasks, taskRelations } from './chunk-5LRSB445.js';
|
|
10
|
+
export { agentGraph, agentGraphRelations, agentToolRelationsRelations, apiKeys, apiKeysRelations, artifactComponents, artifactComponentsRelations, contextCache, contextCacheRelations, contextConfigs, contextConfigsRelations, conversations, conversationsRelations, credentialReferences, credentialReferencesRelations, dataComponents, dataComponentsRelations, externalAgents, externalAgentsRelations, functions, functionsRelations, ledgerArtifacts, ledgerArtifactsRelations, messages, messagesRelations, projects, projectsRelations, subAgentArtifactComponents, subAgentArtifactComponentsRelations, subAgentDataComponents, subAgentDataComponentsRelations, subAgentRelations, subAgentRelationsRelations, subAgentToolRelations, subAgents, subAgentsRelations, taskRelations, taskRelationsRelations, tasks, tasksRelations, tools, toolsRelations } from './chunk-5LRSB445.js';
|
|
10
11
|
import { CredentialStoreType, MCPServerType, MCPTransportType } from './chunk-YFHT5M2R.js';
|
|
11
12
|
export { CredentialStoreType, MCPServerType, MCPTransportType, TOOL_STATUS_VALUES, VALID_RELATION_TYPES } from './chunk-YFHT5M2R.js';
|
|
12
13
|
import { __publicField } from './chunk-MKBO26DX.js';
|
|
@@ -15,7 +16,7 @@ import { customAlphabet, nanoid } from 'nanoid';
|
|
|
15
16
|
import jmespath from 'jmespath';
|
|
16
17
|
import { createClient } from '@libsql/client';
|
|
17
18
|
import { drizzle } from 'drizzle-orm/libsql';
|
|
18
|
-
import { and, eq, desc,
|
|
19
|
+
import { and, eq, desc, sql, count, asc, isNotNull, inArray, not } from 'drizzle-orm';
|
|
19
20
|
import crypto, { scrypt, randomBytes, timingSafeEqual } from 'crypto';
|
|
20
21
|
import { promisify } from 'util';
|
|
21
22
|
import { z } from '@hono/zod-openapi';
|
|
@@ -753,13 +754,373 @@ function createInMemoryDatabaseClient() {
|
|
|
753
754
|
const db = createDatabaseClient({ url: ":memory:" });
|
|
754
755
|
return db;
|
|
755
756
|
}
|
|
757
|
+
var getContextConfigById = (db) => async (params) => {
|
|
758
|
+
return await db.query.contextConfigs.findFirst({
|
|
759
|
+
where: and(
|
|
760
|
+
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
761
|
+
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
762
|
+
eq(contextConfigs.graphId, params.scopes.graphId),
|
|
763
|
+
eq(contextConfigs.id, params.id)
|
|
764
|
+
)
|
|
765
|
+
});
|
|
766
|
+
};
|
|
767
|
+
var listContextConfigs = (db) => async (params) => {
|
|
768
|
+
return await db.query.contextConfigs.findMany({
|
|
769
|
+
where: and(
|
|
770
|
+
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
771
|
+
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
772
|
+
eq(contextConfigs.graphId, params.scopes.graphId)
|
|
773
|
+
),
|
|
774
|
+
orderBy: [desc(contextConfigs.createdAt)]
|
|
775
|
+
});
|
|
776
|
+
};
|
|
777
|
+
var listContextConfigsPaginated = (db) => async (params) => {
|
|
778
|
+
const page = params.pagination?.page || 1;
|
|
779
|
+
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
780
|
+
const offset = (page - 1) * limit;
|
|
781
|
+
const whereClause = and(
|
|
782
|
+
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
783
|
+
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
784
|
+
eq(contextConfigs.graphId, params.scopes.graphId)
|
|
785
|
+
);
|
|
786
|
+
const [contextConfigList, totalResult] = await Promise.all([
|
|
787
|
+
db.select().from(contextConfigs).where(whereClause).limit(limit).offset(offset).orderBy(desc(contextConfigs.createdAt)),
|
|
788
|
+
db.select({ count: sql`COUNT(*)` }).from(contextConfigs).where(whereClause)
|
|
789
|
+
]);
|
|
790
|
+
const total = Number(totalResult[0]?.count || 0);
|
|
791
|
+
const pages = Math.ceil(total / limit);
|
|
792
|
+
return {
|
|
793
|
+
data: contextConfigList,
|
|
794
|
+
pagination: {
|
|
795
|
+
page,
|
|
796
|
+
limit,
|
|
797
|
+
total,
|
|
798
|
+
pages
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
};
|
|
802
|
+
var createContextConfig = (db) => async (params) => {
|
|
803
|
+
const id = params.id || nanoid();
|
|
804
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
805
|
+
let contextVariables = params.contextVariables;
|
|
806
|
+
if (contextVariables !== void 0 && contextVariables !== null && typeof contextVariables === "object" && Object.keys(contextVariables).length === 0) {
|
|
807
|
+
contextVariables = null;
|
|
808
|
+
}
|
|
809
|
+
const contextConfig2 = await db.insert(contextConfigs).values({
|
|
810
|
+
id,
|
|
811
|
+
tenantId: params.tenantId,
|
|
812
|
+
projectId: params.projectId,
|
|
813
|
+
graphId: params.graphId,
|
|
814
|
+
headersSchema: params.headersSchema ?? null,
|
|
815
|
+
contextVariables: contextVariables ?? null,
|
|
816
|
+
createdAt: now,
|
|
817
|
+
updatedAt: now
|
|
818
|
+
}).returning();
|
|
819
|
+
return contextConfig2[0];
|
|
820
|
+
};
|
|
821
|
+
var updateContextConfig = (db) => async (params) => {
|
|
822
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
823
|
+
const processedData = { ...params.data };
|
|
824
|
+
if ("contextVariables" in params.data) {
|
|
825
|
+
if (params.data.contextVariables === null || typeof params.data.contextVariables === "object" && params.data.contextVariables !== null && Object.keys(params.data.contextVariables).length === 0) {
|
|
826
|
+
processedData.contextVariables = null;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
if ("headersSchema" in params.data && params.data.headersSchema === null) {
|
|
830
|
+
processedData.headersSchema = null;
|
|
831
|
+
}
|
|
832
|
+
const updated = await db.update(contextConfigs).set({
|
|
833
|
+
...processedData,
|
|
834
|
+
updatedAt: now
|
|
835
|
+
}).where(
|
|
836
|
+
and(
|
|
837
|
+
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
838
|
+
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
839
|
+
eq(contextConfigs.graphId, params.scopes.graphId),
|
|
840
|
+
eq(contextConfigs.id, params.id)
|
|
841
|
+
)
|
|
842
|
+
).returning();
|
|
843
|
+
return updated[0];
|
|
844
|
+
};
|
|
845
|
+
var deleteContextConfig = (db) => async (params) => {
|
|
846
|
+
try {
|
|
847
|
+
const result = await db.delete(contextConfigs).where(
|
|
848
|
+
and(
|
|
849
|
+
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
850
|
+
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
851
|
+
eq(contextConfigs.graphId, params.scopes.graphId),
|
|
852
|
+
eq(contextConfigs.id, params.id)
|
|
853
|
+
)
|
|
854
|
+
).returning();
|
|
855
|
+
return result.length > 0;
|
|
856
|
+
} catch (error) {
|
|
857
|
+
console.error("Error deleting context config:", error);
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
var hasContextConfig = (db) => async (params) => {
|
|
862
|
+
const contextConfig2 = await getContextConfigById(db)(params);
|
|
863
|
+
return contextConfig2 !== null;
|
|
864
|
+
};
|
|
865
|
+
var countContextConfigs = (db) => async (params) => {
|
|
866
|
+
const result = await db.select({ count: count() }).from(contextConfigs).where(
|
|
867
|
+
and(
|
|
868
|
+
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
869
|
+
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
870
|
+
eq(contextConfigs.graphId, params.scopes.graphId)
|
|
871
|
+
)
|
|
872
|
+
);
|
|
873
|
+
const total = result[0]?.count || 0;
|
|
874
|
+
return typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
875
|
+
};
|
|
876
|
+
var upsertContextConfig = (db) => async (params) => {
|
|
877
|
+
const scopes = {
|
|
878
|
+
tenantId: params.data.tenantId,
|
|
879
|
+
projectId: params.data.projectId,
|
|
880
|
+
graphId: params.data.graphId
|
|
881
|
+
};
|
|
882
|
+
if (params.data.id) {
|
|
883
|
+
const existing = await getContextConfigById(db)({
|
|
884
|
+
scopes,
|
|
885
|
+
id: params.data.id
|
|
886
|
+
});
|
|
887
|
+
if (existing) {
|
|
888
|
+
return await updateContextConfig(db)({
|
|
889
|
+
scopes,
|
|
890
|
+
id: params.data.id,
|
|
891
|
+
data: {
|
|
892
|
+
headersSchema: params.data.headersSchema,
|
|
893
|
+
contextVariables: params.data.contextVariables
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return await createContextConfig(db)(params.data);
|
|
899
|
+
};
|
|
900
|
+
var createExternalAgent = (db) => async (params) => {
|
|
901
|
+
const agent = await db.insert(externalAgents).values(params).returning();
|
|
902
|
+
return agent[0];
|
|
903
|
+
};
|
|
904
|
+
var getExternalAgent = (db) => async (params) => {
|
|
905
|
+
const result = await db.query.externalAgents.findFirst({
|
|
906
|
+
where: and(
|
|
907
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
908
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
909
|
+
eq(externalAgents.graphId, params.scopes.graphId),
|
|
910
|
+
eq(externalAgents.id, params.subAgentId)
|
|
911
|
+
)
|
|
912
|
+
});
|
|
913
|
+
return result || null;
|
|
914
|
+
};
|
|
915
|
+
var getExternalAgentByUrl = (db) => async (params) => {
|
|
916
|
+
const result = await db.query.externalAgents.findFirst({
|
|
917
|
+
where: and(
|
|
918
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
919
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
920
|
+
eq(externalAgents.graphId, params.scopes.graphId),
|
|
921
|
+
eq(externalAgents.baseUrl, params.baseUrl)
|
|
922
|
+
)
|
|
923
|
+
});
|
|
924
|
+
return result || null;
|
|
925
|
+
};
|
|
926
|
+
var listExternalAgents = (db) => async (params) => {
|
|
927
|
+
return await db.query.externalAgents.findMany({
|
|
928
|
+
where: and(
|
|
929
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
930
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
931
|
+
eq(externalAgents.graphId, params.scopes.graphId)
|
|
932
|
+
),
|
|
933
|
+
orderBy: [asc(externalAgents.name)]
|
|
934
|
+
});
|
|
935
|
+
};
|
|
936
|
+
var listExternalAgentsPaginated = (db) => async (params) => {
|
|
937
|
+
const page = params.pagination?.page || 1;
|
|
938
|
+
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
939
|
+
const offset = (page - 1) * limit;
|
|
940
|
+
const [data, totalResult] = await Promise.all([
|
|
941
|
+
db.select().from(externalAgents).where(
|
|
942
|
+
and(
|
|
943
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
944
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
945
|
+
eq(externalAgents.graphId, params.scopes.graphId)
|
|
946
|
+
)
|
|
947
|
+
).limit(limit).offset(offset).orderBy(desc(externalAgents.createdAt)),
|
|
948
|
+
db.select({ count: count() }).from(externalAgents).where(
|
|
949
|
+
and(
|
|
950
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
951
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
952
|
+
eq(externalAgents.graphId, params.scopes.graphId)
|
|
953
|
+
)
|
|
954
|
+
)
|
|
955
|
+
]);
|
|
956
|
+
const total = typeof totalResult[0]?.count === "string" ? parseInt(totalResult[0].count, 10) : totalResult[0]?.count || 0;
|
|
957
|
+
const pages = Math.ceil(total / limit);
|
|
958
|
+
return {
|
|
959
|
+
data,
|
|
960
|
+
pagination: { page, limit, total, pages }
|
|
961
|
+
};
|
|
962
|
+
};
|
|
963
|
+
var updateExternalAgent = (db) => async (params) => {
|
|
964
|
+
const updateData = {
|
|
965
|
+
...params.data,
|
|
966
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
967
|
+
};
|
|
968
|
+
if (Object.keys(updateData).length === 1) {
|
|
969
|
+
throw new Error("No fields to update");
|
|
970
|
+
}
|
|
971
|
+
if (updateData.headers !== void 0 && (updateData.headers === null || Object.keys(updateData.headers || {}).length === 0)) {
|
|
972
|
+
updateData.headers = null;
|
|
973
|
+
}
|
|
974
|
+
if (updateData.credentialReferenceId === void 0) {
|
|
975
|
+
updateData.credentialReferenceId = null;
|
|
976
|
+
}
|
|
977
|
+
const result = await db.update(externalAgents).set(updateData).where(
|
|
978
|
+
and(
|
|
979
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
980
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
981
|
+
eq(externalAgents.graphId, params.scopes.graphId),
|
|
982
|
+
eq(externalAgents.id, params.subAgentId)
|
|
983
|
+
)
|
|
984
|
+
).returning();
|
|
985
|
+
return result[0] || null;
|
|
986
|
+
};
|
|
987
|
+
var upsertExternalAgent = (db) => async (params) => {
|
|
988
|
+
const scopes = {
|
|
989
|
+
tenantId: params.data.tenantId,
|
|
990
|
+
projectId: params.data.projectId,
|
|
991
|
+
graphId: params.data.graphId
|
|
992
|
+
};
|
|
993
|
+
const existing = await getExternalAgent(db)({
|
|
994
|
+
scopes,
|
|
995
|
+
subAgentId: params.data.id
|
|
996
|
+
});
|
|
997
|
+
if (existing) {
|
|
998
|
+
const updated = await updateExternalAgent(db)({
|
|
999
|
+
scopes,
|
|
1000
|
+
subAgentId: params.data.id,
|
|
1001
|
+
data: {
|
|
1002
|
+
name: params.data.name,
|
|
1003
|
+
description: params.data.description,
|
|
1004
|
+
baseUrl: params.data.baseUrl,
|
|
1005
|
+
credentialReferenceId: params.data.credentialReferenceId,
|
|
1006
|
+
headers: params.data.headers
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
if (!updated) {
|
|
1010
|
+
throw new Error("Failed to update external agent - no rows affected");
|
|
1011
|
+
}
|
|
1012
|
+
return updated;
|
|
1013
|
+
} else {
|
|
1014
|
+
return await createExternalAgent(db)(params.data);
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
var deleteExternalAgent = (db) => async (params) => {
|
|
1018
|
+
try {
|
|
1019
|
+
const result = await db.delete(externalAgents).where(
|
|
1020
|
+
and(
|
|
1021
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1022
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1023
|
+
eq(externalAgents.graphId, params.scopes.graphId),
|
|
1024
|
+
eq(externalAgents.id, params.subAgentId)
|
|
1025
|
+
)
|
|
1026
|
+
).returning();
|
|
1027
|
+
return result.length > 0;
|
|
1028
|
+
} catch (error) {
|
|
1029
|
+
console.error("Error deleting external agent:", error);
|
|
1030
|
+
return false;
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
var externalAgentExists = (db) => async (params) => {
|
|
1034
|
+
const agent = await getExternalAgent(db)(params);
|
|
1035
|
+
return agent !== null;
|
|
1036
|
+
};
|
|
1037
|
+
var externalAgentUrlExists = (db) => async (params) => {
|
|
1038
|
+
const agent = await getExternalAgentByUrl(db)(params);
|
|
1039
|
+
return agent !== null;
|
|
1040
|
+
};
|
|
1041
|
+
var countExternalAgents = (db) => async (params) => {
|
|
1042
|
+
const result = await db.select({ count: count() }).from(externalAgents).where(
|
|
1043
|
+
and(
|
|
1044
|
+
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1045
|
+
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1046
|
+
eq(externalAgents.graphId, params.scopes.graphId)
|
|
1047
|
+
)
|
|
1048
|
+
);
|
|
1049
|
+
const countValue = result[0]?.count;
|
|
1050
|
+
return typeof countValue === "string" ? parseInt(countValue, 10) : countValue || 0;
|
|
1051
|
+
};
|
|
1052
|
+
var upsertFunction = (db) => async (params) => {
|
|
1053
|
+
const { data, scopes } = params;
|
|
1054
|
+
const { tenantId, projectId } = scopes;
|
|
1055
|
+
const existingFunction = await db.select().from(functions).where(
|
|
1056
|
+
and(
|
|
1057
|
+
eq(functions.tenantId, tenantId),
|
|
1058
|
+
eq(functions.projectId, projectId),
|
|
1059
|
+
eq(functions.id, data.id)
|
|
1060
|
+
)
|
|
1061
|
+
).limit(1);
|
|
1062
|
+
if (existingFunction.length > 0) {
|
|
1063
|
+
await db.update(functions).set({
|
|
1064
|
+
inputSchema: data.inputSchema,
|
|
1065
|
+
executeCode: data.executeCode,
|
|
1066
|
+
dependencies: data.dependencies,
|
|
1067
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1068
|
+
}).where(
|
|
1069
|
+
and(
|
|
1070
|
+
eq(functions.tenantId, tenantId),
|
|
1071
|
+
eq(functions.projectId, projectId),
|
|
1072
|
+
eq(functions.id, data.id)
|
|
1073
|
+
)
|
|
1074
|
+
);
|
|
1075
|
+
} else {
|
|
1076
|
+
await db.insert(functions).values({
|
|
1077
|
+
tenantId,
|
|
1078
|
+
projectId,
|
|
1079
|
+
id: data.id,
|
|
1080
|
+
inputSchema: data.inputSchema,
|
|
1081
|
+
executeCode: data.executeCode,
|
|
1082
|
+
dependencies: data.dependencies,
|
|
1083
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1084
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
var getFunction = (db) => async (params) => {
|
|
1089
|
+
const { functionId, scopes } = params;
|
|
1090
|
+
const { tenantId, projectId } = scopes;
|
|
1091
|
+
const result = await db.select().from(functions).where(
|
|
1092
|
+
and(
|
|
1093
|
+
eq(functions.tenantId, tenantId),
|
|
1094
|
+
eq(functions.projectId, projectId),
|
|
1095
|
+
eq(functions.id, functionId)
|
|
1096
|
+
)
|
|
1097
|
+
).limit(1);
|
|
1098
|
+
return result[0] || null;
|
|
1099
|
+
};
|
|
1100
|
+
var listFunctions = (db) => async (params) => {
|
|
1101
|
+
const { scopes } = params;
|
|
1102
|
+
const { tenantId, projectId } = scopes;
|
|
1103
|
+
const result = await db.select().from(functions).where(and(eq(functions.tenantId, tenantId), eq(functions.projectId, projectId)));
|
|
1104
|
+
return result;
|
|
1105
|
+
};
|
|
1106
|
+
var deleteFunction = (db) => async (params) => {
|
|
1107
|
+
const { functionId, scopes } = params;
|
|
1108
|
+
const { tenantId, projectId } = scopes;
|
|
1109
|
+
await db.delete(functions).where(
|
|
1110
|
+
and(
|
|
1111
|
+
eq(functions.tenantId, tenantId),
|
|
1112
|
+
eq(functions.projectId, projectId),
|
|
1113
|
+
eq(functions.id, functionId)
|
|
1114
|
+
)
|
|
1115
|
+
);
|
|
1116
|
+
};
|
|
756
1117
|
var getAgentRelationById = (db) => async (params) => {
|
|
757
|
-
return db.query.
|
|
1118
|
+
return db.query.subAgentRelations.findFirst({
|
|
758
1119
|
where: and(
|
|
759
|
-
eq(
|
|
760
|
-
eq(
|
|
761
|
-
eq(
|
|
762
|
-
eq(
|
|
1120
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1121
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1122
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1123
|
+
eq(subAgentRelations.id, params.relationId)
|
|
763
1124
|
)
|
|
764
1125
|
});
|
|
765
1126
|
};
|
|
@@ -768,34 +1129,34 @@ var listAgentRelations = (db) => async (params) => {
|
|
|
768
1129
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
769
1130
|
const offset = (page - 1) * limit;
|
|
770
1131
|
const whereClause = and(
|
|
771
|
-
eq(
|
|
772
|
-
eq(
|
|
773
|
-
eq(
|
|
1132
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1133
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1134
|
+
eq(subAgentRelations.graphId, params.scopes.graphId)
|
|
774
1135
|
);
|
|
775
1136
|
const [data, totalResult] = await Promise.all([
|
|
776
|
-
db.select().from(
|
|
777
|
-
db.select({ count: count() }).from(
|
|
1137
|
+
db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)),
|
|
1138
|
+
db.select({ count: count() }).from(subAgentRelations).where(whereClause)
|
|
778
1139
|
]);
|
|
779
1140
|
const total = totalResult[0]?.count || 0;
|
|
780
1141
|
const pages = Math.ceil(total / limit);
|
|
781
1142
|
return { data, pagination: { page, limit, total, pages } };
|
|
782
1143
|
};
|
|
783
1144
|
var getAgentRelations = (db) => async (params) => {
|
|
784
|
-
return await db.query.
|
|
1145
|
+
return await db.query.subAgentRelations.findMany({
|
|
785
1146
|
where: and(
|
|
786
|
-
eq(
|
|
787
|
-
eq(
|
|
788
|
-
eq(
|
|
789
|
-
eq(
|
|
1147
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1148
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1149
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1150
|
+
eq(subAgentRelations.sourceSubAgentId, params.scopes.subAgentId)
|
|
790
1151
|
)
|
|
791
1152
|
});
|
|
792
1153
|
};
|
|
793
1154
|
var getAgentRelationsByGraph = (db) => async (params) => {
|
|
794
|
-
return await db.query.
|
|
1155
|
+
return await db.query.subAgentRelations.findMany({
|
|
795
1156
|
where: and(
|
|
796
|
-
eq(
|
|
797
|
-
eq(
|
|
798
|
-
eq(
|
|
1157
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1158
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1159
|
+
eq(subAgentRelations.graphId, params.scopes.graphId)
|
|
799
1160
|
)
|
|
800
1161
|
});
|
|
801
1162
|
};
|
|
@@ -804,14 +1165,14 @@ var getAgentRelationsBySource = (db) => async (params) => {
|
|
|
804
1165
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
805
1166
|
const offset = (page - 1) * limit;
|
|
806
1167
|
const whereClause = and(
|
|
807
|
-
eq(
|
|
808
|
-
eq(
|
|
809
|
-
eq(
|
|
810
|
-
eq(
|
|
1168
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1169
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1170
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1171
|
+
eq(subAgentRelations.sourceSubAgentId, params.sourceSubAgentId)
|
|
811
1172
|
);
|
|
812
1173
|
const [data, totalResult] = await Promise.all([
|
|
813
|
-
db.select().from(
|
|
814
|
-
db.select({ count: count() }).from(
|
|
1174
|
+
db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)),
|
|
1175
|
+
db.select({ count: count() }).from(subAgentRelations).where(whereClause)
|
|
815
1176
|
]);
|
|
816
1177
|
const total = totalResult[0]?.count || 0;
|
|
817
1178
|
const pages = Math.ceil(total / limit);
|
|
@@ -825,14 +1186,14 @@ var getAgentRelationsByTarget = (db) => async (params) => {
|
|
|
825
1186
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
826
1187
|
const offset = (page - 1) * limit;
|
|
827
1188
|
const whereClause = and(
|
|
828
|
-
eq(
|
|
829
|
-
eq(
|
|
830
|
-
eq(
|
|
831
|
-
eq(
|
|
1189
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1190
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1191
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1192
|
+
eq(subAgentRelations.targetSubAgentId, params.targetSubAgentId)
|
|
832
1193
|
);
|
|
833
1194
|
const [data, totalResult] = await Promise.all([
|
|
834
|
-
db.select().from(
|
|
835
|
-
db.select({ count: count() }).from(
|
|
1195
|
+
db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)),
|
|
1196
|
+
db.select({ count: count() }).from(subAgentRelations).where(whereClause)
|
|
836
1197
|
]);
|
|
837
1198
|
const total = totalResult[0]?.count || 0;
|
|
838
1199
|
const pages = Math.ceil(total / limit);
|
|
@@ -846,14 +1207,14 @@ var getExternalAgentRelations = (db) => async (params) => {
|
|
|
846
1207
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
847
1208
|
const offset = (page - 1) * limit;
|
|
848
1209
|
const whereClause = and(
|
|
849
|
-
eq(
|
|
850
|
-
eq(
|
|
851
|
-
eq(
|
|
852
|
-
eq(
|
|
1210
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1211
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1212
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1213
|
+
eq(subAgentRelations.externalSubAgentId, params.externalSubAgentId)
|
|
853
1214
|
);
|
|
854
1215
|
const [data, totalResult] = await Promise.all([
|
|
855
|
-
db.select().from(
|
|
856
|
-
db.select({ count: count() }).from(
|
|
1216
|
+
db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)),
|
|
1217
|
+
db.select({ count: count() }).from(subAgentRelations).where(whereClause)
|
|
857
1218
|
]);
|
|
858
1219
|
const total = totalResult[0]?.count || 0;
|
|
859
1220
|
const pages = Math.ceil(total / limit);
|
|
@@ -864,51 +1225,51 @@ var getExternalAgentRelations = (db) => async (params) => {
|
|
|
864
1225
|
};
|
|
865
1226
|
var getRelatedAgentsForGraph = (db) => async (params) => {
|
|
866
1227
|
const internalRelations = await db.select({
|
|
867
|
-
id:
|
|
868
|
-
name:
|
|
869
|
-
description:
|
|
870
|
-
relationType:
|
|
871
|
-
}).from(
|
|
872
|
-
|
|
1228
|
+
id: subAgents.id,
|
|
1229
|
+
name: subAgents.name,
|
|
1230
|
+
description: subAgents.description,
|
|
1231
|
+
relationType: subAgentRelations.relationType
|
|
1232
|
+
}).from(subAgentRelations).innerJoin(
|
|
1233
|
+
subAgents,
|
|
873
1234
|
and(
|
|
874
|
-
eq(
|
|
875
|
-
eq(
|
|
876
|
-
eq(
|
|
877
|
-
eq(
|
|
1235
|
+
eq(subAgentRelations.targetSubAgentId, subAgents.id),
|
|
1236
|
+
eq(subAgentRelations.tenantId, subAgents.tenantId),
|
|
1237
|
+
eq(subAgentRelations.projectId, subAgents.projectId),
|
|
1238
|
+
eq(subAgentRelations.graphId, subAgents.graphId)
|
|
878
1239
|
)
|
|
879
1240
|
).where(
|
|
880
1241
|
and(
|
|
881
|
-
eq(
|
|
882
|
-
eq(
|
|
883
|
-
eq(
|
|
884
|
-
eq(
|
|
885
|
-
isNotNull(
|
|
1242
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1243
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1244
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1245
|
+
eq(subAgentRelations.sourceSubAgentId, params.subAgentId),
|
|
1246
|
+
isNotNull(subAgentRelations.targetSubAgentId)
|
|
886
1247
|
)
|
|
887
1248
|
);
|
|
888
1249
|
const externalRelations = await db.select({
|
|
889
|
-
id:
|
|
890
|
-
relationType:
|
|
1250
|
+
id: subAgentRelations.id,
|
|
1251
|
+
relationType: subAgentRelations.relationType,
|
|
891
1252
|
externalAgent: {
|
|
892
1253
|
id: externalAgents.id,
|
|
893
1254
|
name: externalAgents.name,
|
|
894
1255
|
description: externalAgents.description,
|
|
895
1256
|
baseUrl: externalAgents.baseUrl
|
|
896
1257
|
}
|
|
897
|
-
}).from(
|
|
1258
|
+
}).from(subAgentRelations).innerJoin(
|
|
898
1259
|
externalAgents,
|
|
899
1260
|
and(
|
|
900
|
-
eq(
|
|
901
|
-
eq(
|
|
902
|
-
eq(
|
|
903
|
-
eq(
|
|
1261
|
+
eq(subAgentRelations.externalSubAgentId, externalAgents.id),
|
|
1262
|
+
eq(subAgentRelations.tenantId, externalAgents.tenantId),
|
|
1263
|
+
eq(subAgentRelations.projectId, externalAgents.projectId),
|
|
1264
|
+
eq(subAgentRelations.graphId, externalAgents.graphId)
|
|
904
1265
|
)
|
|
905
1266
|
).where(
|
|
906
1267
|
and(
|
|
907
|
-
eq(
|
|
908
|
-
eq(
|
|
909
|
-
eq(
|
|
910
|
-
eq(
|
|
911
|
-
isNotNull(
|
|
1268
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1269
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1270
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1271
|
+
eq(subAgentRelations.sourceSubAgentId, params.subAgentId),
|
|
1272
|
+
isNotNull(subAgentRelations.externalSubAgentId)
|
|
912
1273
|
)
|
|
913
1274
|
);
|
|
914
1275
|
return {
|
|
@@ -916,55 +1277,55 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
|
|
|
916
1277
|
externalRelations
|
|
917
1278
|
};
|
|
918
1279
|
};
|
|
919
|
-
var
|
|
920
|
-
const hasTargetAgent = params.
|
|
921
|
-
const hasExternalAgent = params.
|
|
1280
|
+
var createSubAgentRelation = (db) => async (params) => {
|
|
1281
|
+
const hasTargetAgent = params.targetSubAgentId != null;
|
|
1282
|
+
const hasExternalAgent = params.externalSubAgentId != null;
|
|
922
1283
|
if (hasTargetAgent && hasExternalAgent) {
|
|
923
|
-
throw new Error("Cannot specify both
|
|
1284
|
+
throw new Error("Cannot specify both targetSubAgentId and externalSubAgentId");
|
|
924
1285
|
}
|
|
925
1286
|
if (!hasTargetAgent && !hasExternalAgent) {
|
|
926
|
-
throw new Error("Must specify either
|
|
1287
|
+
throw new Error("Must specify either targetSubAgentId or externalSubAgentId");
|
|
927
1288
|
}
|
|
928
|
-
const relation = await db.insert(
|
|
1289
|
+
const relation = await db.insert(subAgentRelations).values({
|
|
929
1290
|
...params
|
|
930
1291
|
}).returning();
|
|
931
1292
|
return relation[0];
|
|
932
1293
|
};
|
|
933
1294
|
var getAgentRelationByParams = (db) => async (params) => {
|
|
934
1295
|
const whereConditions = [
|
|
935
|
-
eq(
|
|
936
|
-
eq(
|
|
937
|
-
eq(
|
|
938
|
-
eq(
|
|
939
|
-
eq(
|
|
1296
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1297
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1298
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1299
|
+
eq(subAgentRelations.sourceSubAgentId, params.sourceSubAgentId),
|
|
1300
|
+
eq(subAgentRelations.relationType, params.relationType)
|
|
940
1301
|
];
|
|
941
|
-
if (params.
|
|
942
|
-
whereConditions.push(eq(
|
|
1302
|
+
if (params.targetSubAgentId) {
|
|
1303
|
+
whereConditions.push(eq(subAgentRelations.targetSubAgentId, params.targetSubAgentId));
|
|
943
1304
|
}
|
|
944
|
-
if (params.
|
|
945
|
-
whereConditions.push(eq(
|
|
1305
|
+
if (params.externalSubAgentId) {
|
|
1306
|
+
whereConditions.push(eq(subAgentRelations.externalSubAgentId, params.externalSubAgentId));
|
|
946
1307
|
}
|
|
947
|
-
return db.query.
|
|
1308
|
+
return db.query.subAgentRelations.findFirst({
|
|
948
1309
|
where: and(...whereConditions)
|
|
949
1310
|
});
|
|
950
1311
|
};
|
|
951
1312
|
var upsertAgentRelation = (db) => async (params) => {
|
|
952
1313
|
const existing = await getAgentRelationByParams(db)({
|
|
953
1314
|
scopes: { tenantId: params.tenantId, projectId: params.projectId, graphId: params.graphId },
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
1315
|
+
sourceSubAgentId: params.sourceSubAgentId,
|
|
1316
|
+
targetSubAgentId: params.targetSubAgentId,
|
|
1317
|
+
externalSubAgentId: params.externalSubAgentId,
|
|
957
1318
|
relationType: params.relationType ?? ""
|
|
958
1319
|
});
|
|
959
1320
|
if (!existing) {
|
|
960
|
-
return await
|
|
1321
|
+
return await createSubAgentRelation(db)(params);
|
|
961
1322
|
}
|
|
962
1323
|
return existing;
|
|
963
1324
|
};
|
|
964
1325
|
var createExternalAgentRelation = (db) => async (params) => {
|
|
965
|
-
return await
|
|
1326
|
+
return await createSubAgentRelation(db)({
|
|
966
1327
|
...params,
|
|
967
|
-
|
|
1328
|
+
targetSubAgentId: void 0
|
|
968
1329
|
});
|
|
969
1330
|
};
|
|
970
1331
|
var updateAgentRelation = (db) => async (params) => {
|
|
@@ -972,44 +1333,44 @@ var updateAgentRelation = (db) => async (params) => {
|
|
|
972
1333
|
...params.data,
|
|
973
1334
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
974
1335
|
};
|
|
975
|
-
const relation = await db.update(
|
|
1336
|
+
const relation = await db.update(subAgentRelations).set(updateData).where(
|
|
976
1337
|
and(
|
|
977
|
-
eq(
|
|
978
|
-
eq(
|
|
979
|
-
eq(
|
|
980
|
-
eq(
|
|
1338
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1339
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1340
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1341
|
+
eq(subAgentRelations.id, params.relationId)
|
|
981
1342
|
)
|
|
982
1343
|
).returning();
|
|
983
1344
|
return relation[0];
|
|
984
1345
|
};
|
|
985
|
-
var
|
|
986
|
-
const result = await db.delete(
|
|
1346
|
+
var deleteSubAgentRelation = (db) => async (params) => {
|
|
1347
|
+
const result = await db.delete(subAgentRelations).where(
|
|
987
1348
|
and(
|
|
988
|
-
eq(
|
|
989
|
-
eq(
|
|
990
|
-
eq(
|
|
991
|
-
eq(
|
|
1349
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1350
|
+
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
1351
|
+
eq(subAgentRelations.graphId, params.scopes.graphId),
|
|
1352
|
+
eq(subAgentRelations.id, params.relationId)
|
|
992
1353
|
)
|
|
993
1354
|
);
|
|
994
1355
|
return (result.rowsAffected || 0) > 0;
|
|
995
1356
|
};
|
|
996
1357
|
var deleteAgentRelationsByGraph = (db) => async (params) => {
|
|
997
|
-
const result = await db.delete(
|
|
1358
|
+
const result = await db.delete(subAgentRelations).where(
|
|
998
1359
|
and(
|
|
999
|
-
eq(
|
|
1000
|
-
eq(
|
|
1360
|
+
eq(subAgentRelations.tenantId, params.scopes.tenantId),
|
|
1361
|
+
eq(subAgentRelations.graphId, params.scopes.graphId)
|
|
1001
1362
|
)
|
|
1002
1363
|
);
|
|
1003
1364
|
return (result.rowsAffected || 0) > 0;
|
|
1004
1365
|
};
|
|
1005
1366
|
var createAgentToolRelation = (db) => async (params) => {
|
|
1006
1367
|
const finalRelationId = params.relationId ?? nanoid();
|
|
1007
|
-
const relation = await db.insert(
|
|
1368
|
+
const relation = await db.insert(subAgentToolRelations).values({
|
|
1008
1369
|
id: finalRelationId,
|
|
1009
1370
|
tenantId: params.scopes.tenantId,
|
|
1010
1371
|
projectId: params.scopes.projectId,
|
|
1011
1372
|
graphId: params.scopes.graphId,
|
|
1012
|
-
|
|
1373
|
+
subAgentId: params.data.subAgentId,
|
|
1013
1374
|
toolId: params.data.toolId,
|
|
1014
1375
|
selectedTools: params.data.selectedTools,
|
|
1015
1376
|
headers: params.data.headers
|
|
@@ -1021,45 +1382,45 @@ var updateAgentToolRelation = (db) => async (params) => {
|
|
|
1021
1382
|
...params.data,
|
|
1022
1383
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1023
1384
|
};
|
|
1024
|
-
const relation = await db.update(
|
|
1385
|
+
const relation = await db.update(subAgentToolRelations).set(updateData).where(
|
|
1025
1386
|
and(
|
|
1026
|
-
eq(
|
|
1027
|
-
eq(
|
|
1028
|
-
eq(
|
|
1029
|
-
eq(
|
|
1387
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1388
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1389
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1390
|
+
eq(subAgentToolRelations.id, params.relationId)
|
|
1030
1391
|
)
|
|
1031
1392
|
).returning();
|
|
1032
1393
|
return relation[0];
|
|
1033
1394
|
};
|
|
1034
1395
|
var deleteAgentToolRelation = (db) => async (params) => {
|
|
1035
|
-
const result = await db.delete(
|
|
1396
|
+
const result = await db.delete(subAgentToolRelations).where(
|
|
1036
1397
|
and(
|
|
1037
|
-
eq(
|
|
1038
|
-
eq(
|
|
1039
|
-
eq(
|
|
1040
|
-
eq(
|
|
1398
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1399
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1400
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1401
|
+
eq(subAgentToolRelations.id, params.relationId)
|
|
1041
1402
|
)
|
|
1042
1403
|
);
|
|
1043
1404
|
return (result.rowsAffected || 0) > 0;
|
|
1044
1405
|
};
|
|
1045
1406
|
var deleteAgentToolRelationByAgent = (db) => async (params) => {
|
|
1046
|
-
const result = await db.delete(
|
|
1407
|
+
const result = await db.delete(subAgentToolRelations).where(
|
|
1047
1408
|
and(
|
|
1048
|
-
eq(
|
|
1049
|
-
eq(
|
|
1050
|
-
eq(
|
|
1051
|
-
eq(
|
|
1409
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1410
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1411
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1412
|
+
eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId)
|
|
1052
1413
|
)
|
|
1053
1414
|
);
|
|
1054
1415
|
return (result.rowsAffected || 0) > 0;
|
|
1055
1416
|
};
|
|
1056
1417
|
var getAgentToolRelationById = (db) => async (params) => {
|
|
1057
|
-
return await db.query.
|
|
1418
|
+
return await db.query.subAgentToolRelations.findFirst({
|
|
1058
1419
|
where: and(
|
|
1059
|
-
eq(
|
|
1060
|
-
eq(
|
|
1061
|
-
eq(
|
|
1062
|
-
eq(
|
|
1420
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1421
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1422
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1423
|
+
eq(subAgentToolRelations.id, params.relationId)
|
|
1063
1424
|
)
|
|
1064
1425
|
});
|
|
1065
1426
|
};
|
|
@@ -1068,18 +1429,18 @@ var getAgentToolRelationByAgent = (db) => async (params) => {
|
|
|
1068
1429
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
1069
1430
|
const offset = (page - 1) * limit;
|
|
1070
1431
|
const [data, totalResult] = await Promise.all([
|
|
1071
|
-
db.select().from(
|
|
1432
|
+
db.select().from(subAgentToolRelations).where(
|
|
1072
1433
|
and(
|
|
1073
|
-
eq(
|
|
1074
|
-
eq(
|
|
1075
|
-
eq(
|
|
1434
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1435
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1436
|
+
eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId)
|
|
1076
1437
|
)
|
|
1077
|
-
).limit(limit).offset(offset).orderBy(desc(
|
|
1078
|
-
db.select({ count: count() }).from(
|
|
1438
|
+
).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)),
|
|
1439
|
+
db.select({ count: count() }).from(subAgentToolRelations).where(
|
|
1079
1440
|
and(
|
|
1080
|
-
eq(
|
|
1081
|
-
eq(
|
|
1082
|
-
eq(
|
|
1441
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1442
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1443
|
+
eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId)
|
|
1083
1444
|
)
|
|
1084
1445
|
)
|
|
1085
1446
|
]);
|
|
@@ -1095,20 +1456,20 @@ var getAgentToolRelationByTool = (db) => async (params) => {
|
|
|
1095
1456
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
1096
1457
|
const offset = (page - 1) * limit;
|
|
1097
1458
|
const [data, totalResult] = await Promise.all([
|
|
1098
|
-
db.select().from(
|
|
1459
|
+
db.select().from(subAgentToolRelations).where(
|
|
1099
1460
|
and(
|
|
1100
|
-
eq(
|
|
1101
|
-
eq(
|
|
1102
|
-
eq(
|
|
1103
|
-
eq(
|
|
1461
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1462
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1463
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1464
|
+
eq(subAgentToolRelations.toolId, params.toolId)
|
|
1104
1465
|
)
|
|
1105
|
-
).limit(limit).offset(offset).orderBy(desc(
|
|
1106
|
-
db.select({ count: count() }).from(
|
|
1466
|
+
).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)),
|
|
1467
|
+
db.select({ count: count() }).from(subAgentToolRelations).where(
|
|
1107
1468
|
and(
|
|
1108
|
-
eq(
|
|
1109
|
-
eq(
|
|
1110
|
-
eq(
|
|
1111
|
-
eq(
|
|
1469
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1470
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1471
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1472
|
+
eq(subAgentToolRelations.toolId, params.toolId)
|
|
1112
1473
|
)
|
|
1113
1474
|
)
|
|
1114
1475
|
]);
|
|
@@ -1124,18 +1485,18 @@ var listAgentToolRelations = (db) => async (params) => {
|
|
|
1124
1485
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
1125
1486
|
const offset = (page - 1) * limit;
|
|
1126
1487
|
const [data, totalResult] = await Promise.all([
|
|
1127
|
-
db.select().from(
|
|
1488
|
+
db.select().from(subAgentToolRelations).where(
|
|
1128
1489
|
and(
|
|
1129
|
-
eq(
|
|
1130
|
-
eq(
|
|
1131
|
-
eq(
|
|
1490
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1491
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1492
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId)
|
|
1132
1493
|
)
|
|
1133
|
-
).limit(limit).offset(offset).orderBy(desc(
|
|
1134
|
-
db.select({ count: count() }).from(
|
|
1494
|
+
).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)),
|
|
1495
|
+
db.select({ count: count() }).from(subAgentToolRelations).where(
|
|
1135
1496
|
and(
|
|
1136
|
-
eq(
|
|
1137
|
-
eq(
|
|
1138
|
-
eq(
|
|
1497
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1498
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1499
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId)
|
|
1139
1500
|
)
|
|
1140
1501
|
)
|
|
1141
1502
|
]);
|
|
@@ -1152,14 +1513,14 @@ var getToolsForAgent = (db) => async (params) => {
|
|
|
1152
1513
|
const offset = (page - 1) * limit;
|
|
1153
1514
|
const [data, totalResult] = await Promise.all([
|
|
1154
1515
|
db.select({
|
|
1155
|
-
id:
|
|
1156
|
-
tenantId:
|
|
1157
|
-
|
|
1158
|
-
toolId:
|
|
1159
|
-
selectedTools:
|
|
1160
|
-
headers:
|
|
1161
|
-
createdAt:
|
|
1162
|
-
updatedAt:
|
|
1516
|
+
id: subAgentToolRelations.id,
|
|
1517
|
+
tenantId: subAgentToolRelations.tenantId,
|
|
1518
|
+
subAgentId: subAgentToolRelations.subAgentId,
|
|
1519
|
+
toolId: subAgentToolRelations.toolId,
|
|
1520
|
+
selectedTools: subAgentToolRelations.selectedTools,
|
|
1521
|
+
headers: subAgentToolRelations.headers,
|
|
1522
|
+
createdAt: subAgentToolRelations.createdAt,
|
|
1523
|
+
updatedAt: subAgentToolRelations.updatedAt,
|
|
1163
1524
|
tool: {
|
|
1164
1525
|
id: tools.id,
|
|
1165
1526
|
name: tools.name,
|
|
@@ -1176,27 +1537,27 @@ var getToolsForAgent = (db) => async (params) => {
|
|
|
1176
1537
|
headers: tools.headers,
|
|
1177
1538
|
imageUrl: tools.imageUrl
|
|
1178
1539
|
}
|
|
1179
|
-
}).from(
|
|
1540
|
+
}).from(subAgentToolRelations).innerJoin(
|
|
1180
1541
|
tools,
|
|
1181
1542
|
and(
|
|
1182
|
-
eq(
|
|
1183
|
-
eq(
|
|
1184
|
-
eq(
|
|
1543
|
+
eq(subAgentToolRelations.tenantId, tools.tenantId),
|
|
1544
|
+
eq(subAgentToolRelations.projectId, tools.projectId),
|
|
1545
|
+
eq(subAgentToolRelations.toolId, tools.id)
|
|
1185
1546
|
)
|
|
1186
1547
|
).where(
|
|
1187
1548
|
and(
|
|
1188
|
-
eq(
|
|
1189
|
-
eq(
|
|
1190
|
-
eq(
|
|
1191
|
-
eq(
|
|
1549
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1550
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1551
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1552
|
+
eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId)
|
|
1192
1553
|
)
|
|
1193
|
-
).limit(limit).offset(offset).orderBy(desc(
|
|
1194
|
-
db.select({ count: count() }).from(
|
|
1554
|
+
).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)),
|
|
1555
|
+
db.select({ count: count() }).from(subAgentToolRelations).where(
|
|
1195
1556
|
and(
|
|
1196
|
-
eq(
|
|
1197
|
-
eq(
|
|
1198
|
-
eq(
|
|
1199
|
-
eq(
|
|
1557
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1558
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1559
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1560
|
+
eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId)
|
|
1200
1561
|
)
|
|
1201
1562
|
)
|
|
1202
1563
|
]);
|
|
@@ -1213,560 +1574,200 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
1213
1574
|
const offset = (page - 1) * limit;
|
|
1214
1575
|
const [data, totalResult] = await Promise.all([
|
|
1215
1576
|
db.select({
|
|
1216
|
-
id:
|
|
1217
|
-
tenantId:
|
|
1218
|
-
|
|
1219
|
-
toolId:
|
|
1220
|
-
selectedTools:
|
|
1221
|
-
headers:
|
|
1222
|
-
createdAt:
|
|
1223
|
-
updatedAt:
|
|
1224
|
-
|
|
1225
|
-
id:
|
|
1226
|
-
name:
|
|
1227
|
-
description:
|
|
1228
|
-
prompt:
|
|
1229
|
-
conversationHistoryConfig:
|
|
1230
|
-
models:
|
|
1231
|
-
stopWhen:
|
|
1232
|
-
createdAt:
|
|
1233
|
-
updatedAt:
|
|
1234
|
-
}
|
|
1235
|
-
}).from(
|
|
1236
|
-
|
|
1237
|
-
and(
|
|
1238
|
-
eq(agentToolRelations.agentId, agents.id),
|
|
1239
|
-
eq(agentToolRelations.tenantId, agents.tenantId),
|
|
1240
|
-
eq(agentToolRelations.projectId, agents.projectId),
|
|
1241
|
-
eq(agentToolRelations.graphId, agents.graphId)
|
|
1242
|
-
)
|
|
1243
|
-
).where(
|
|
1244
|
-
and(
|
|
1245
|
-
eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
1246
|
-
eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
1247
|
-
eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
1248
|
-
eq(agentToolRelations.toolId, params.toolId)
|
|
1249
|
-
)
|
|
1250
|
-
).limit(limit).offset(offset).orderBy(desc(agentToolRelations.createdAt)),
|
|
1251
|
-
db.select({ count: count() }).from(agentToolRelations).where(
|
|
1577
|
+
id: subAgentToolRelations.id,
|
|
1578
|
+
tenantId: subAgentToolRelations.tenantId,
|
|
1579
|
+
subAgentId: subAgentToolRelations.subAgentId,
|
|
1580
|
+
toolId: subAgentToolRelations.toolId,
|
|
1581
|
+
selectedTools: subAgentToolRelations.selectedTools,
|
|
1582
|
+
headers: subAgentToolRelations.headers,
|
|
1583
|
+
createdAt: subAgentToolRelations.createdAt,
|
|
1584
|
+
updatedAt: subAgentToolRelations.updatedAt,
|
|
1585
|
+
subAgent: {
|
|
1586
|
+
id: subAgents.id,
|
|
1587
|
+
name: subAgents.name,
|
|
1588
|
+
description: subAgents.description,
|
|
1589
|
+
prompt: subAgents.prompt,
|
|
1590
|
+
conversationHistoryConfig: subAgents.conversationHistoryConfig,
|
|
1591
|
+
models: subAgents.models,
|
|
1592
|
+
stopWhen: subAgents.stopWhen,
|
|
1593
|
+
createdAt: subAgents.createdAt,
|
|
1594
|
+
updatedAt: subAgents.updatedAt
|
|
1595
|
+
}
|
|
1596
|
+
}).from(subAgentToolRelations).innerJoin(
|
|
1597
|
+
subAgents,
|
|
1252
1598
|
and(
|
|
1253
|
-
eq(
|
|
1254
|
-
eq(
|
|
1255
|
-
eq(
|
|
1256
|
-
eq(
|
|
1599
|
+
eq(subAgentToolRelations.subAgentId, subAgents.id),
|
|
1600
|
+
eq(subAgentToolRelations.tenantId, subAgents.tenantId),
|
|
1601
|
+
eq(subAgentToolRelations.projectId, subAgents.projectId),
|
|
1602
|
+
eq(subAgentToolRelations.graphId, subAgents.graphId)
|
|
1257
1603
|
)
|
|
1258
|
-
)
|
|
1259
|
-
]);
|
|
1260
|
-
const total = totalResult[0]?.count || 0;
|
|
1261
|
-
const pages = Math.ceil(total / limit);
|
|
1262
|
-
return {
|
|
1263
|
-
data,
|
|
1264
|
-
pagination: { page, limit, total, pages }
|
|
1265
|
-
};
|
|
1266
|
-
};
|
|
1267
|
-
var validateInternalAgent = (db) => async (params) => {
|
|
1268
|
-
const result = await db.select({ id: agents.id }).from(agents).where(
|
|
1269
|
-
and(
|
|
1270
|
-
eq(agents.tenantId, params.scopes.tenantId),
|
|
1271
|
-
eq(agents.projectId, params.scopes.projectId),
|
|
1272
|
-
eq(agents.graphId, params.scopes.graphId),
|
|
1273
|
-
eq(agents.id, params.scopes.agentId)
|
|
1274
|
-
)
|
|
1275
|
-
).limit(1);
|
|
1276
|
-
return result.length > 0;
|
|
1277
|
-
};
|
|
1278
|
-
var validateExternalAgent = (db) => async (params) => {
|
|
1279
|
-
const result = await db.select({ id: externalAgents.id }).from(externalAgents).where(
|
|
1280
|
-
and(
|
|
1281
|
-
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1282
|
-
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1283
|
-
eq(externalAgents.graphId, params.scopes.graphId),
|
|
1284
|
-
eq(externalAgents.id, params.scopes.agentId)
|
|
1285
|
-
)
|
|
1286
|
-
).limit(1);
|
|
1287
|
-
return result.length > 0;
|
|
1288
|
-
};
|
|
1289
|
-
var getAgentById = (db) => async (params) => {
|
|
1290
|
-
const result = await db.query.agents.findFirst({
|
|
1291
|
-
where: and(
|
|
1292
|
-
eq(agents.tenantId, params.scopes.tenantId),
|
|
1293
|
-
eq(agents.projectId, params.scopes.projectId),
|
|
1294
|
-
eq(agents.graphId, params.scopes.graphId),
|
|
1295
|
-
eq(agents.id, params.agentId)
|
|
1296
|
-
)
|
|
1297
|
-
});
|
|
1298
|
-
return result;
|
|
1299
|
-
};
|
|
1300
|
-
var listAgents = (db) => async (params) => {
|
|
1301
|
-
return await db.query.agents.findMany({
|
|
1302
|
-
where: and(
|
|
1303
|
-
eq(agents.tenantId, params.scopes.tenantId),
|
|
1304
|
-
eq(agents.projectId, params.scopes.projectId),
|
|
1305
|
-
eq(agents.graphId, params.scopes.graphId)
|
|
1306
|
-
)
|
|
1307
|
-
});
|
|
1308
|
-
};
|
|
1309
|
-
var listAgentsPaginated = (db) => async (params) => {
|
|
1310
|
-
const page = params.pagination?.page || 1;
|
|
1311
|
-
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
1312
|
-
const offset = (page - 1) * limit;
|
|
1313
|
-
const whereClause = and(
|
|
1314
|
-
eq(agents.tenantId, params.scopes.tenantId),
|
|
1315
|
-
eq(agents.projectId, params.scopes.projectId),
|
|
1316
|
-
eq(agents.graphId, params.scopes.graphId)
|
|
1317
|
-
);
|
|
1318
|
-
const [data, totalResult] = await Promise.all([
|
|
1319
|
-
db.select().from(agents).where(whereClause).limit(limit).offset(offset).orderBy(desc(agents.createdAt)),
|
|
1320
|
-
db.select({ count: count() }).from(agents).where(whereClause)
|
|
1321
|
-
]);
|
|
1322
|
-
const total = totalResult[0]?.count || 0;
|
|
1323
|
-
const pages = Math.ceil(total / limit);
|
|
1324
|
-
return {
|
|
1325
|
-
data,
|
|
1326
|
-
pagination: { page, limit, total, pages }
|
|
1327
|
-
};
|
|
1328
|
-
};
|
|
1329
|
-
var createAgent = (db) => async (params) => {
|
|
1330
|
-
const agent = await db.insert(agents).values(params).returning();
|
|
1331
|
-
return agent[0];
|
|
1332
|
-
};
|
|
1333
|
-
var updateAgent = (db) => async (params) => {
|
|
1334
|
-
const data = params.data;
|
|
1335
|
-
if (data.models !== void 0) {
|
|
1336
|
-
if (!data.models || !data.models.base?.model && !data.models.structuredOutput?.model && !data.models.summarizer?.model && !data.models.base?.providerOptions && !data.models.structuredOutput?.providerOptions && !data.models.summarizer?.providerOptions) {
|
|
1337
|
-
data.models = null;
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
const updateData = {
|
|
1341
|
-
...data,
|
|
1342
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1343
|
-
};
|
|
1344
|
-
const agent = await db.update(agents).set(updateData).where(
|
|
1345
|
-
and(
|
|
1346
|
-
eq(agents.tenantId, params.scopes.tenantId),
|
|
1347
|
-
eq(agents.projectId, params.scopes.projectId),
|
|
1348
|
-
eq(agents.graphId, params.scopes.graphId),
|
|
1349
|
-
eq(agents.id, params.agentId)
|
|
1350
|
-
)
|
|
1351
|
-
).returning();
|
|
1352
|
-
return agent[0] ?? null;
|
|
1353
|
-
};
|
|
1354
|
-
var upsertAgent = (db) => async (params) => {
|
|
1355
|
-
const scopes = {
|
|
1356
|
-
tenantId: params.data.tenantId,
|
|
1357
|
-
projectId: params.data.projectId,
|
|
1358
|
-
graphId: params.data.graphId
|
|
1359
|
-
};
|
|
1360
|
-
const existing = await getAgentById(db)({
|
|
1361
|
-
scopes,
|
|
1362
|
-
agentId: params.data.id
|
|
1363
|
-
});
|
|
1364
|
-
if (existing) {
|
|
1365
|
-
const updated = await updateAgent(db)({
|
|
1366
|
-
scopes,
|
|
1367
|
-
agentId: params.data.id,
|
|
1368
|
-
data: {
|
|
1369
|
-
name: params.data.name,
|
|
1370
|
-
description: params.data.description,
|
|
1371
|
-
prompt: params.data.prompt,
|
|
1372
|
-
conversationHistoryConfig: params.data.conversationHistoryConfig,
|
|
1373
|
-
models: params.data.models,
|
|
1374
|
-
stopWhen: params.data.stopWhen
|
|
1375
|
-
}
|
|
1376
|
-
});
|
|
1377
|
-
if (!updated) {
|
|
1378
|
-
throw new Error("Failed to update agent - no rows affected");
|
|
1379
|
-
}
|
|
1380
|
-
return updated;
|
|
1381
|
-
} else {
|
|
1382
|
-
return await createAgent(db)(params.data);
|
|
1383
|
-
}
|
|
1384
|
-
};
|
|
1385
|
-
var deleteAgent = (db) => async (params) => {
|
|
1386
|
-
await db.delete(agents).where(
|
|
1387
|
-
and(
|
|
1388
|
-
eq(agents.tenantId, params.scopes.tenantId),
|
|
1389
|
-
eq(agents.projectId, params.scopes.projectId),
|
|
1390
|
-
eq(agents.graphId, params.scopes.graphId),
|
|
1391
|
-
eq(agents.id, params.agentId)
|
|
1392
|
-
)
|
|
1393
|
-
);
|
|
1394
|
-
const deletedAgent = await getAgentById(db)({
|
|
1395
|
-
scopes: params.scopes,
|
|
1396
|
-
agentId: params.agentId
|
|
1397
|
-
});
|
|
1398
|
-
return deletedAgent === void 0;
|
|
1399
|
-
};
|
|
1400
|
-
var getAgentsByIds = (db) => async (params) => {
|
|
1401
|
-
if (params.agentIds.length === 0) {
|
|
1402
|
-
return [];
|
|
1403
|
-
}
|
|
1404
|
-
return await db.select().from(agents).where(
|
|
1405
|
-
and(
|
|
1406
|
-
eq(agents.tenantId, params.scopes.tenantId),
|
|
1407
|
-
eq(agents.projectId, params.scopes.projectId),
|
|
1408
|
-
eq(agents.graphId, params.scopes.graphId),
|
|
1409
|
-
inArray(agents.id, params.agentIds)
|
|
1410
|
-
)
|
|
1411
|
-
);
|
|
1412
|
-
};
|
|
1413
|
-
var getContextConfigById = (db) => async (params) => {
|
|
1414
|
-
return await db.query.contextConfigs.findFirst({
|
|
1415
|
-
where: and(
|
|
1416
|
-
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
1417
|
-
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
1418
|
-
eq(contextConfigs.graphId, params.scopes.graphId),
|
|
1419
|
-
eq(contextConfigs.id, params.id)
|
|
1420
|
-
)
|
|
1421
|
-
});
|
|
1422
|
-
};
|
|
1423
|
-
var listContextConfigs = (db) => async (params) => {
|
|
1424
|
-
return await db.query.contextConfigs.findMany({
|
|
1425
|
-
where: and(
|
|
1426
|
-
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
1427
|
-
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
1428
|
-
eq(contextConfigs.graphId, params.scopes.graphId)
|
|
1429
|
-
),
|
|
1430
|
-
orderBy: [desc(contextConfigs.createdAt)]
|
|
1431
|
-
});
|
|
1432
|
-
};
|
|
1433
|
-
var listContextConfigsPaginated = (db) => async (params) => {
|
|
1434
|
-
const page = params.pagination?.page || 1;
|
|
1435
|
-
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
1436
|
-
const offset = (page - 1) * limit;
|
|
1437
|
-
const whereClause = and(
|
|
1438
|
-
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
1439
|
-
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
1440
|
-
eq(contextConfigs.graphId, params.scopes.graphId)
|
|
1441
|
-
);
|
|
1442
|
-
const [contextConfigList, totalResult] = await Promise.all([
|
|
1443
|
-
db.select().from(contextConfigs).where(whereClause).limit(limit).offset(offset).orderBy(desc(contextConfigs.createdAt)),
|
|
1444
|
-
db.select({ count: sql`COUNT(*)` }).from(contextConfigs).where(whereClause)
|
|
1445
|
-
]);
|
|
1446
|
-
const total = Number(totalResult[0]?.count || 0);
|
|
1447
|
-
const pages = Math.ceil(total / limit);
|
|
1448
|
-
return {
|
|
1449
|
-
data: contextConfigList,
|
|
1450
|
-
pagination: {
|
|
1451
|
-
page,
|
|
1452
|
-
limit,
|
|
1453
|
-
total,
|
|
1454
|
-
pages
|
|
1455
|
-
}
|
|
1456
|
-
};
|
|
1457
|
-
};
|
|
1458
|
-
var createContextConfig = (db) => async (params) => {
|
|
1459
|
-
const id = params.id || nanoid();
|
|
1460
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1461
|
-
let contextVariables = params.contextVariables;
|
|
1462
|
-
if (contextVariables !== void 0 && contextVariables !== null && typeof contextVariables === "object" && Object.keys(contextVariables).length === 0) {
|
|
1463
|
-
contextVariables = null;
|
|
1464
|
-
}
|
|
1465
|
-
const contextConfig2 = await db.insert(contextConfigs).values({
|
|
1466
|
-
id,
|
|
1467
|
-
tenantId: params.tenantId,
|
|
1468
|
-
projectId: params.projectId,
|
|
1469
|
-
graphId: params.graphId,
|
|
1470
|
-
headersSchema: params.headersSchema ?? null,
|
|
1471
|
-
contextVariables: contextVariables ?? null,
|
|
1472
|
-
createdAt: now,
|
|
1473
|
-
updatedAt: now
|
|
1474
|
-
}).returning();
|
|
1475
|
-
return contextConfig2[0];
|
|
1476
|
-
};
|
|
1477
|
-
var updateContextConfig = (db) => async (params) => {
|
|
1478
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1479
|
-
const processedData = { ...params.data };
|
|
1480
|
-
if ("contextVariables" in params.data) {
|
|
1481
|
-
if (params.data.contextVariables === null || typeof params.data.contextVariables === "object" && params.data.contextVariables !== null && Object.keys(params.data.contextVariables).length === 0) {
|
|
1482
|
-
processedData.contextVariables = null;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
if ("headersSchema" in params.data && params.data.headersSchema === null) {
|
|
1486
|
-
processedData.headersSchema = null;
|
|
1487
|
-
}
|
|
1488
|
-
const updated = await db.update(contextConfigs).set({
|
|
1489
|
-
...processedData,
|
|
1490
|
-
updatedAt: now
|
|
1491
|
-
}).where(
|
|
1492
|
-
and(
|
|
1493
|
-
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
1494
|
-
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
1495
|
-
eq(contextConfigs.graphId, params.scopes.graphId),
|
|
1496
|
-
eq(contextConfigs.id, params.id)
|
|
1497
|
-
)
|
|
1498
|
-
).returning();
|
|
1499
|
-
return updated[0];
|
|
1500
|
-
};
|
|
1501
|
-
var deleteContextConfig = (db) => async (params) => {
|
|
1502
|
-
try {
|
|
1503
|
-
const result = await db.delete(contextConfigs).where(
|
|
1604
|
+
).where(
|
|
1504
1605
|
and(
|
|
1505
|
-
eq(
|
|
1506
|
-
eq(
|
|
1507
|
-
eq(
|
|
1508
|
-
eq(
|
|
1606
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1607
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1608
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1609
|
+
eq(subAgentToolRelations.toolId, params.toolId)
|
|
1610
|
+
)
|
|
1611
|
+
).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)),
|
|
1612
|
+
db.select({ count: count() }).from(subAgentToolRelations).where(
|
|
1613
|
+
and(
|
|
1614
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
1615
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
1616
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
1617
|
+
eq(subAgentToolRelations.toolId, params.toolId)
|
|
1509
1618
|
)
|
|
1510
|
-
).returning();
|
|
1511
|
-
return result.length > 0;
|
|
1512
|
-
} catch (error) {
|
|
1513
|
-
console.error("Error deleting context config:", error);
|
|
1514
|
-
return false;
|
|
1515
|
-
}
|
|
1516
|
-
};
|
|
1517
|
-
var hasContextConfig = (db) => async (params) => {
|
|
1518
|
-
const contextConfig2 = await getContextConfigById(db)(params);
|
|
1519
|
-
return contextConfig2 !== null;
|
|
1520
|
-
};
|
|
1521
|
-
var countContextConfigs = (db) => async (params) => {
|
|
1522
|
-
const result = await db.select({ count: count() }).from(contextConfigs).where(
|
|
1523
|
-
and(
|
|
1524
|
-
eq(contextConfigs.tenantId, params.scopes.tenantId),
|
|
1525
|
-
eq(contextConfigs.projectId, params.scopes.projectId),
|
|
1526
|
-
eq(contextConfigs.graphId, params.scopes.graphId)
|
|
1527
1619
|
)
|
|
1528
|
-
);
|
|
1529
|
-
const total =
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
tenantId: params.data.tenantId,
|
|
1535
|
-
projectId: params.data.projectId,
|
|
1536
|
-
graphId: params.data.graphId
|
|
1620
|
+
]);
|
|
1621
|
+
const total = totalResult[0]?.count || 0;
|
|
1622
|
+
const pages = Math.ceil(total / limit);
|
|
1623
|
+
return {
|
|
1624
|
+
data,
|
|
1625
|
+
pagination: { page, limit, total, pages }
|
|
1537
1626
|
};
|
|
1538
|
-
if (params.data.id) {
|
|
1539
|
-
const existing = await getContextConfigById(db)({
|
|
1540
|
-
scopes,
|
|
1541
|
-
id: params.data.id
|
|
1542
|
-
});
|
|
1543
|
-
if (existing) {
|
|
1544
|
-
return await updateContextConfig(db)({
|
|
1545
|
-
scopes,
|
|
1546
|
-
id: params.data.id,
|
|
1547
|
-
data: {
|
|
1548
|
-
headersSchema: params.data.headersSchema,
|
|
1549
|
-
contextVariables: params.data.contextVariables
|
|
1550
|
-
}
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
return await createContextConfig(db)(params.data);
|
|
1555
1627
|
};
|
|
1556
|
-
var
|
|
1557
|
-
const
|
|
1558
|
-
|
|
1628
|
+
var validateInternalSubAgent = (db) => async (params) => {
|
|
1629
|
+
const result = await db.select({ id: subAgents.id }).from(subAgents).where(
|
|
1630
|
+
and(
|
|
1631
|
+
eq(subAgents.tenantId, params.scopes.tenantId),
|
|
1632
|
+
eq(subAgents.projectId, params.scopes.projectId),
|
|
1633
|
+
eq(subAgents.graphId, params.scopes.graphId),
|
|
1634
|
+
eq(subAgents.id, params.scopes.subAgentId)
|
|
1635
|
+
)
|
|
1636
|
+
).limit(1);
|
|
1637
|
+
return result.length > 0;
|
|
1559
1638
|
};
|
|
1560
|
-
var
|
|
1561
|
-
const result = await db.
|
|
1562
|
-
|
|
1639
|
+
var validateExternalAgent = (db) => async (params) => {
|
|
1640
|
+
const result = await db.select({ id: externalAgents.id }).from(externalAgents).where(
|
|
1641
|
+
and(
|
|
1563
1642
|
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1564
1643
|
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1565
1644
|
eq(externalAgents.graphId, params.scopes.graphId),
|
|
1566
|
-
eq(externalAgents.id, params.
|
|
1645
|
+
eq(externalAgents.id, params.scopes.subAgentId)
|
|
1567
1646
|
)
|
|
1568
|
-
|
|
1569
|
-
return result
|
|
1647
|
+
).limit(1);
|
|
1648
|
+
return result.length > 0;
|
|
1570
1649
|
};
|
|
1571
|
-
var
|
|
1572
|
-
const result = await db.query.
|
|
1650
|
+
var getSubAgentById = (db) => async (params) => {
|
|
1651
|
+
const result = await db.query.subAgents.findFirst({
|
|
1573
1652
|
where: and(
|
|
1574
|
-
eq(
|
|
1575
|
-
eq(
|
|
1576
|
-
eq(
|
|
1577
|
-
eq(
|
|
1653
|
+
eq(subAgents.tenantId, params.scopes.tenantId),
|
|
1654
|
+
eq(subAgents.projectId, params.scopes.projectId),
|
|
1655
|
+
eq(subAgents.graphId, params.scopes.graphId),
|
|
1656
|
+
eq(subAgents.id, params.subAgentId)
|
|
1578
1657
|
)
|
|
1579
1658
|
});
|
|
1580
|
-
return result
|
|
1659
|
+
return result;
|
|
1581
1660
|
};
|
|
1582
|
-
var
|
|
1583
|
-
return await db.query.
|
|
1661
|
+
var listSubAgents = (db) => async (params) => {
|
|
1662
|
+
return await db.query.subAgents.findMany({
|
|
1584
1663
|
where: and(
|
|
1585
|
-
eq(
|
|
1586
|
-
eq(
|
|
1587
|
-
eq(
|
|
1588
|
-
)
|
|
1589
|
-
orderBy: [asc(externalAgents.name)]
|
|
1664
|
+
eq(subAgents.tenantId, params.scopes.tenantId),
|
|
1665
|
+
eq(subAgents.projectId, params.scopes.projectId),
|
|
1666
|
+
eq(subAgents.graphId, params.scopes.graphId)
|
|
1667
|
+
)
|
|
1590
1668
|
});
|
|
1591
1669
|
};
|
|
1592
|
-
var
|
|
1670
|
+
var listSubAgentsPaginated = (db) => async (params) => {
|
|
1593
1671
|
const page = params.pagination?.page || 1;
|
|
1594
1672
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
1595
1673
|
const offset = (page - 1) * limit;
|
|
1674
|
+
const whereClause = and(
|
|
1675
|
+
eq(subAgents.tenantId, params.scopes.tenantId),
|
|
1676
|
+
eq(subAgents.projectId, params.scopes.projectId),
|
|
1677
|
+
eq(subAgents.graphId, params.scopes.graphId)
|
|
1678
|
+
);
|
|
1596
1679
|
const [data, totalResult] = await Promise.all([
|
|
1597
|
-
db.select().from(
|
|
1598
|
-
|
|
1599
|
-
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1600
|
-
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1601
|
-
eq(externalAgents.graphId, params.scopes.graphId)
|
|
1602
|
-
)
|
|
1603
|
-
).limit(limit).offset(offset).orderBy(desc(externalAgents.createdAt)),
|
|
1604
|
-
db.select({ count: count() }).from(externalAgents).where(
|
|
1605
|
-
and(
|
|
1606
|
-
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1607
|
-
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1608
|
-
eq(externalAgents.graphId, params.scopes.graphId)
|
|
1609
|
-
)
|
|
1610
|
-
)
|
|
1680
|
+
db.select().from(subAgents).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgents.createdAt)),
|
|
1681
|
+
db.select({ count: count() }).from(subAgents).where(whereClause)
|
|
1611
1682
|
]);
|
|
1612
|
-
const total =
|
|
1683
|
+
const total = totalResult[0]?.count || 0;
|
|
1613
1684
|
const pages = Math.ceil(total / limit);
|
|
1614
1685
|
return {
|
|
1615
1686
|
data,
|
|
1616
1687
|
pagination: { page, limit, total, pages }
|
|
1617
1688
|
};
|
|
1618
1689
|
};
|
|
1619
|
-
var
|
|
1690
|
+
var createSubAgent = (db) => async (params) => {
|
|
1691
|
+
const agent = await db.insert(subAgents).values(params).returning();
|
|
1692
|
+
return agent[0];
|
|
1693
|
+
};
|
|
1694
|
+
var updateSubAgent = (db) => async (params) => {
|
|
1695
|
+
const data = params.data;
|
|
1696
|
+
if (data.models !== void 0) {
|
|
1697
|
+
if (!data.models || !data.models.base?.model && !data.models.structuredOutput?.model && !data.models.summarizer?.model && !data.models.base?.providerOptions && !data.models.structuredOutput?.providerOptions && !data.models.summarizer?.providerOptions) {
|
|
1698
|
+
data.models = null;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1620
1701
|
const updateData = {
|
|
1621
|
-
...
|
|
1702
|
+
...data,
|
|
1622
1703
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1623
1704
|
};
|
|
1624
|
-
|
|
1625
|
-
throw new Error("No fields to update");
|
|
1626
|
-
}
|
|
1627
|
-
if (updateData.headers !== void 0 && (updateData.headers === null || Object.keys(updateData.headers || {}).length === 0)) {
|
|
1628
|
-
updateData.headers = null;
|
|
1629
|
-
}
|
|
1630
|
-
if (updateData.credentialReferenceId === void 0) {
|
|
1631
|
-
updateData.credentialReferenceId = null;
|
|
1632
|
-
}
|
|
1633
|
-
const result = await db.update(externalAgents).set(updateData).where(
|
|
1705
|
+
const agent = await db.update(subAgents).set(updateData).where(
|
|
1634
1706
|
and(
|
|
1635
|
-
eq(
|
|
1636
|
-
eq(
|
|
1637
|
-
eq(
|
|
1638
|
-
eq(
|
|
1707
|
+
eq(subAgents.tenantId, params.scopes.tenantId),
|
|
1708
|
+
eq(subAgents.projectId, params.scopes.projectId),
|
|
1709
|
+
eq(subAgents.graphId, params.scopes.graphId),
|
|
1710
|
+
eq(subAgents.id, params.subAgentId)
|
|
1639
1711
|
)
|
|
1640
1712
|
).returning();
|
|
1641
|
-
return
|
|
1713
|
+
return agent[0] ?? null;
|
|
1642
1714
|
};
|
|
1643
|
-
var
|
|
1715
|
+
var upsertSubAgent = (db) => async (params) => {
|
|
1644
1716
|
const scopes = {
|
|
1645
1717
|
tenantId: params.data.tenantId,
|
|
1646
1718
|
projectId: params.data.projectId,
|
|
1647
1719
|
graphId: params.data.graphId
|
|
1648
1720
|
};
|
|
1649
|
-
const existing = await
|
|
1721
|
+
const existing = await getSubAgentById(db)({
|
|
1650
1722
|
scopes,
|
|
1651
|
-
|
|
1723
|
+
subAgentId: params.data.id
|
|
1652
1724
|
});
|
|
1653
1725
|
if (existing) {
|
|
1654
|
-
const updated = await
|
|
1726
|
+
const updated = await updateSubAgent(db)({
|
|
1655
1727
|
scopes,
|
|
1656
|
-
|
|
1728
|
+
subAgentId: params.data.id,
|
|
1657
1729
|
data: {
|
|
1658
1730
|
name: params.data.name,
|
|
1659
1731
|
description: params.data.description,
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1732
|
+
prompt: params.data.prompt,
|
|
1733
|
+
conversationHistoryConfig: params.data.conversationHistoryConfig,
|
|
1734
|
+
models: params.data.models,
|
|
1735
|
+
stopWhen: params.data.stopWhen
|
|
1663
1736
|
}
|
|
1664
1737
|
});
|
|
1665
1738
|
if (!updated) {
|
|
1666
|
-
throw new Error("Failed to update
|
|
1739
|
+
throw new Error("Failed to update agent - no rows affected");
|
|
1667
1740
|
}
|
|
1668
1741
|
return updated;
|
|
1669
1742
|
} else {
|
|
1670
|
-
return await
|
|
1671
|
-
}
|
|
1672
|
-
};
|
|
1673
|
-
var deleteExternalAgent = (db) => async (params) => {
|
|
1674
|
-
try {
|
|
1675
|
-
const result = await db.delete(externalAgents).where(
|
|
1676
|
-
and(
|
|
1677
|
-
eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
1678
|
-
eq(externalAgents.projectId, params.scopes.projectId),
|
|
1679
|
-
eq(externalAgents.graphId, params.scopes.graphId),
|
|
1680
|
-
eq(externalAgents.id, params.agentId)
|
|
1681
|
-
)
|
|
1682
|
-
).returning();
|
|
1683
|
-
return result.length > 0;
|
|
1684
|
-
} catch (error) {
|
|
1685
|
-
console.error("Error deleting external agent:", error);
|
|
1686
|
-
return false;
|
|
1743
|
+
return await createSubAgent(db)(params.data);
|
|
1687
1744
|
}
|
|
1688
1745
|
};
|
|
1689
|
-
var
|
|
1690
|
-
|
|
1691
|
-
return agent !== null;
|
|
1692
|
-
};
|
|
1693
|
-
var externalAgentUrlExists = (db) => async (params) => {
|
|
1694
|
-
const agent = await getExternalAgentByUrl(db)(params);
|
|
1695
|
-
return agent !== null;
|
|
1696
|
-
};
|
|
1697
|
-
var countExternalAgents = (db) => async (params) => {
|
|
1698
|
-
const result = await db.select({ count: count() }).from(externalAgents).where(
|
|
1746
|
+
var deleteSubAgent = (db) => async (params) => {
|
|
1747
|
+
await db.delete(subAgents).where(
|
|
1699
1748
|
and(
|
|
1700
|
-
eq(
|
|
1701
|
-
eq(
|
|
1702
|
-
eq(
|
|
1749
|
+
eq(subAgents.tenantId, params.scopes.tenantId),
|
|
1750
|
+
eq(subAgents.projectId, params.scopes.projectId),
|
|
1751
|
+
eq(subAgents.graphId, params.scopes.graphId),
|
|
1752
|
+
eq(subAgents.id, params.subAgentId)
|
|
1703
1753
|
)
|
|
1704
1754
|
);
|
|
1705
|
-
const
|
|
1706
|
-
|
|
1755
|
+
const deletedSubAgent = await getSubAgentById(db)({
|
|
1756
|
+
scopes: params.scopes,
|
|
1757
|
+
subAgentId: params.subAgentId
|
|
1758
|
+
});
|
|
1759
|
+
return deletedSubAgent === void 0;
|
|
1707
1760
|
};
|
|
1708
|
-
var
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
const existingFunction = await db.select().from(functions).where(
|
|
1712
|
-
and(
|
|
1713
|
-
eq(functions.tenantId, tenantId),
|
|
1714
|
-
eq(functions.projectId, projectId),
|
|
1715
|
-
eq(functions.id, data.id)
|
|
1716
|
-
)
|
|
1717
|
-
).limit(1);
|
|
1718
|
-
if (existingFunction.length > 0) {
|
|
1719
|
-
await db.update(functions).set({
|
|
1720
|
-
inputSchema: data.inputSchema,
|
|
1721
|
-
executeCode: data.executeCode,
|
|
1722
|
-
dependencies: data.dependencies,
|
|
1723
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1724
|
-
}).where(
|
|
1725
|
-
and(
|
|
1726
|
-
eq(functions.tenantId, tenantId),
|
|
1727
|
-
eq(functions.projectId, projectId),
|
|
1728
|
-
eq(functions.id, data.id)
|
|
1729
|
-
)
|
|
1730
|
-
);
|
|
1731
|
-
} else {
|
|
1732
|
-
await db.insert(functions).values({
|
|
1733
|
-
tenantId,
|
|
1734
|
-
projectId,
|
|
1735
|
-
id: data.id,
|
|
1736
|
-
inputSchema: data.inputSchema,
|
|
1737
|
-
executeCode: data.executeCode,
|
|
1738
|
-
dependencies: data.dependencies,
|
|
1739
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1740
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1741
|
-
});
|
|
1761
|
+
var getSubAgentsByIds = (db) => async (params) => {
|
|
1762
|
+
if (params.subAgentIds.length === 0) {
|
|
1763
|
+
return [];
|
|
1742
1764
|
}
|
|
1743
|
-
|
|
1744
|
-
var getFunction = (db) => async (params) => {
|
|
1745
|
-
const { functionId, scopes } = params;
|
|
1746
|
-
const { tenantId, projectId } = scopes;
|
|
1747
|
-
const result = await db.select().from(functions).where(
|
|
1748
|
-
and(
|
|
1749
|
-
eq(functions.tenantId, tenantId),
|
|
1750
|
-
eq(functions.projectId, projectId),
|
|
1751
|
-
eq(functions.id, functionId)
|
|
1752
|
-
)
|
|
1753
|
-
).limit(1);
|
|
1754
|
-
return result[0] || null;
|
|
1755
|
-
};
|
|
1756
|
-
var listFunctions = (db) => async (params) => {
|
|
1757
|
-
const { scopes } = params;
|
|
1758
|
-
const { tenantId, projectId } = scopes;
|
|
1759
|
-
const result = await db.select().from(functions).where(and(eq(functions.tenantId, tenantId), eq(functions.projectId, projectId)));
|
|
1760
|
-
return result;
|
|
1761
|
-
};
|
|
1762
|
-
var deleteFunction = (db) => async (params) => {
|
|
1763
|
-
const { functionId, scopes } = params;
|
|
1764
|
-
const { tenantId, projectId } = scopes;
|
|
1765
|
-
await db.delete(functions).where(
|
|
1765
|
+
return await db.select().from(subAgents).where(
|
|
1766
1766
|
and(
|
|
1767
|
-
eq(
|
|
1768
|
-
eq(
|
|
1769
|
-
eq(
|
|
1767
|
+
eq(subAgents.tenantId, params.scopes.tenantId),
|
|
1768
|
+
eq(subAgents.projectId, params.scopes.projectId),
|
|
1769
|
+
eq(subAgents.graphId, params.scopes.graphId),
|
|
1770
|
+
inArray(subAgents.id, params.subAgentIds)
|
|
1770
1771
|
)
|
|
1771
1772
|
);
|
|
1772
1773
|
};
|
|
@@ -2847,12 +2848,12 @@ var deleteTool = (db) => async (params) => {
|
|
|
2847
2848
|
var addToolToAgent = (db) => async (params) => {
|
|
2848
2849
|
const id = nanoid();
|
|
2849
2850
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2850
|
-
const [created] = await db.insert(
|
|
2851
|
+
const [created] = await db.insert(subAgentToolRelations).values({
|
|
2851
2852
|
id,
|
|
2852
2853
|
tenantId: params.scopes.tenantId,
|
|
2853
2854
|
projectId: params.scopes.projectId,
|
|
2854
2855
|
graphId: params.scopes.graphId,
|
|
2855
|
-
|
|
2856
|
+
subAgentId: params.subAgentId,
|
|
2856
2857
|
toolId: params.toolId,
|
|
2857
2858
|
selectedTools: params.selectedTools,
|
|
2858
2859
|
headers: params.headers,
|
|
@@ -2862,13 +2863,13 @@ var addToolToAgent = (db) => async (params) => {
|
|
|
2862
2863
|
return created;
|
|
2863
2864
|
};
|
|
2864
2865
|
var removeToolFromAgent = (db) => async (params) => {
|
|
2865
|
-
const [deleted] = await db.delete(
|
|
2866
|
+
const [deleted] = await db.delete(subAgentToolRelations).where(
|
|
2866
2867
|
and(
|
|
2867
|
-
eq(
|
|
2868
|
-
eq(
|
|
2869
|
-
eq(
|
|
2870
|
-
eq(
|
|
2871
|
-
eq(
|
|
2868
|
+
eq(subAgentToolRelations.tenantId, params.scopes.tenantId),
|
|
2869
|
+
eq(subAgentToolRelations.projectId, params.scopes.projectId),
|
|
2870
|
+
eq(subAgentToolRelations.graphId, params.scopes.graphId),
|
|
2871
|
+
eq(subAgentToolRelations.subAgentId, params.subAgentId),
|
|
2872
|
+
eq(subAgentToolRelations.toolId, params.toolId)
|
|
2872
2873
|
)
|
|
2873
2874
|
).returning();
|
|
2874
2875
|
return deleted;
|
|
@@ -2879,7 +2880,7 @@ var upsertAgentToolRelation = (db) => async (params) => {
|
|
|
2879
2880
|
scopes: params.scopes,
|
|
2880
2881
|
relationId: params.relationId,
|
|
2881
2882
|
data: {
|
|
2882
|
-
|
|
2883
|
+
subAgentId: params.subAgentId,
|
|
2883
2884
|
toolId: params.toolId,
|
|
2884
2885
|
selectedTools: params.selectedTools,
|
|
2885
2886
|
headers: params.headers
|
|
@@ -2922,7 +2923,7 @@ var getAgentGraphById = (db) => async (params) => {
|
|
|
2922
2923
|
});
|
|
2923
2924
|
return result ?? null;
|
|
2924
2925
|
};
|
|
2925
|
-
var
|
|
2926
|
+
var getAgentGraphWithDefaultSubAgent = (db) => async (params) => {
|
|
2926
2927
|
const result = await db.query.agentGraph.findFirst({
|
|
2927
2928
|
where: and(
|
|
2928
2929
|
eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
@@ -2930,7 +2931,7 @@ var getAgentGraphWithDefaultAgent = (db) => async (params) => {
|
|
|
2930
2931
|
eq(agentGraph.id, params.scopes.graphId)
|
|
2931
2932
|
),
|
|
2932
2933
|
with: {
|
|
2933
|
-
|
|
2934
|
+
defaultSubAgent: true
|
|
2934
2935
|
}
|
|
2935
2936
|
});
|
|
2936
2937
|
return result ?? null;
|
|
@@ -3035,14 +3036,14 @@ var deleteAgentGraph = (db) => async (params) => {
|
|
|
3035
3036
|
).returning();
|
|
3036
3037
|
return result.length > 0;
|
|
3037
3038
|
};
|
|
3038
|
-
var fetchComponentRelationships = (db) => async (scopes,
|
|
3039
|
+
var fetchComponentRelationships = (db) => async (scopes, subAgentIds, config) => {
|
|
3039
3040
|
const componentsObject = {};
|
|
3040
|
-
if (
|
|
3041
|
+
if (subAgentIds.length > 0) {
|
|
3041
3042
|
const results = await db.select(config.selectFields).from(config.relationTable).innerJoin(config.componentTable, eq(config.relationIdField, config.componentIdField)).where(
|
|
3042
3043
|
and(
|
|
3043
3044
|
eq(config.relationTable.tenantId, scopes.tenantId),
|
|
3044
3045
|
eq(config.relationTable.projectId, scopes.projectId),
|
|
3045
|
-
inArray(config.
|
|
3046
|
+
inArray(config.subAgentIdField, subAgentIds)
|
|
3046
3047
|
)
|
|
3047
3048
|
);
|
|
3048
3049
|
for (const component of results) {
|
|
@@ -3054,7 +3055,7 @@ var fetchComponentRelationships = (db) => async (scopes, agentIds, config) => {
|
|
|
3054
3055
|
var getGraphAgentInfos = (db) => async ({
|
|
3055
3056
|
scopes,
|
|
3056
3057
|
graphId,
|
|
3057
|
-
|
|
3058
|
+
subAgentId
|
|
3058
3059
|
}) => {
|
|
3059
3060
|
const { tenantId, projectId } = scopes;
|
|
3060
3061
|
const graph = await getAgentGraphById(db)({
|
|
@@ -3064,17 +3065,17 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
3064
3065
|
throw new Error(`Agent graph with ID ${graphId} not found for tenant ${tenantId}`);
|
|
3065
3066
|
}
|
|
3066
3067
|
const relations = await getAgentRelations(db)({
|
|
3067
|
-
scopes: { tenantId, projectId, graphId,
|
|
3068
|
+
scopes: { tenantId, projectId, graphId, subAgentId }
|
|
3068
3069
|
});
|
|
3069
|
-
const
|
|
3070
|
-
if (
|
|
3070
|
+
const targetSubAgentIds = relations.map((relation) => relation.targetSubAgentId).filter((id) => id !== null);
|
|
3071
|
+
if (targetSubAgentIds.length === 0) {
|
|
3071
3072
|
return [];
|
|
3072
3073
|
}
|
|
3073
3074
|
const agentInfos = await Promise.all(
|
|
3074
|
-
|
|
3075
|
-
const agent = await
|
|
3075
|
+
targetSubAgentIds.map(async (subAgentId2) => {
|
|
3076
|
+
const agent = await getSubAgentById(db)({
|
|
3076
3077
|
scopes: { tenantId, projectId, graphId },
|
|
3077
|
-
|
|
3078
|
+
subAgentId: subAgentId2
|
|
3078
3079
|
});
|
|
3079
3080
|
if (agent !== void 0) {
|
|
3080
3081
|
return { id: agent.id, name: agent.name, description: agent.description };
|
|
@@ -3096,28 +3097,28 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3096
3097
|
const graphRelations = await getAgentRelationsByGraph(db)({
|
|
3097
3098
|
scopes: { tenantId, projectId, graphId }
|
|
3098
3099
|
});
|
|
3099
|
-
const
|
|
3100
|
+
const graphSubAgents = await db.query.subAgents.findMany({
|
|
3100
3101
|
where: and(
|
|
3101
|
-
eq(
|
|
3102
|
-
eq(
|
|
3103
|
-
eq(
|
|
3102
|
+
eq(subAgents.tenantId, tenantId),
|
|
3103
|
+
eq(subAgents.projectId, projectId),
|
|
3104
|
+
eq(subAgents.graphId, graphId)
|
|
3104
3105
|
)
|
|
3105
3106
|
});
|
|
3106
|
-
const
|
|
3107
|
+
const externalSubAgentIds = /* @__PURE__ */ new Set();
|
|
3107
3108
|
for (const relation of graphRelations) {
|
|
3108
|
-
if (relation.
|
|
3109
|
-
|
|
3109
|
+
if (relation.externalSubAgentId) {
|
|
3110
|
+
externalSubAgentIds.add(relation.externalSubAgentId);
|
|
3110
3111
|
}
|
|
3111
3112
|
}
|
|
3112
|
-
const
|
|
3113
|
-
|
|
3113
|
+
const processedSubAgents = await Promise.all(
|
|
3114
|
+
graphSubAgents.map(async (agent) => {
|
|
3114
3115
|
if (!agent) return null;
|
|
3115
|
-
const
|
|
3116
|
-
(relation) => relation.
|
|
3116
|
+
const subAgentRelationsList = graphRelations.filter(
|
|
3117
|
+
(relation) => relation.sourceSubAgentId === agent.id
|
|
3117
3118
|
);
|
|
3118
|
-
const canTransferTo =
|
|
3119
|
-
const canDelegateTo =
|
|
3120
|
-
const
|
|
3119
|
+
const canTransferTo = subAgentRelationsList.filter((rel) => rel.relationType === "transfer" || rel.relationType === "transfer_to").map((rel) => rel.targetSubAgentId).filter((id) => id !== null);
|
|
3120
|
+
const canDelegateTo = subAgentRelationsList.filter((rel) => rel.relationType === "delegate" || rel.relationType === "delegate_to").map((rel) => rel.targetSubAgentId || rel.externalSubAgentId).filter((id) => id !== null);
|
|
3121
|
+
const subAgentTools = await db.select({
|
|
3121
3122
|
id: tools.id,
|
|
3122
3123
|
name: tools.name,
|
|
3123
3124
|
config: tools.config,
|
|
@@ -3129,41 +3130,41 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3129
3130
|
tenantId: tools.tenantId,
|
|
3130
3131
|
projectId: tools.projectId,
|
|
3131
3132
|
imageUrl: tools.imageUrl,
|
|
3132
|
-
selectedTools:
|
|
3133
|
-
headers:
|
|
3134
|
-
agentToolRelationId:
|
|
3135
|
-
}).from(
|
|
3133
|
+
selectedTools: subAgentToolRelations.selectedTools,
|
|
3134
|
+
headers: subAgentToolRelations.headers,
|
|
3135
|
+
agentToolRelationId: subAgentToolRelations.id
|
|
3136
|
+
}).from(subAgentToolRelations).innerJoin(
|
|
3136
3137
|
tools,
|
|
3137
3138
|
and(
|
|
3138
|
-
eq(
|
|
3139
|
-
eq(
|
|
3140
|
-
eq(
|
|
3139
|
+
eq(subAgentToolRelations.toolId, tools.id),
|
|
3140
|
+
eq(subAgentToolRelations.tenantId, tools.tenantId),
|
|
3141
|
+
eq(subAgentToolRelations.projectId, tools.projectId)
|
|
3141
3142
|
)
|
|
3142
3143
|
).where(
|
|
3143
3144
|
and(
|
|
3144
|
-
eq(
|
|
3145
|
-
eq(
|
|
3146
|
-
eq(
|
|
3147
|
-
eq(
|
|
3145
|
+
eq(subAgentToolRelations.tenantId, tenantId),
|
|
3146
|
+
eq(subAgentToolRelations.projectId, projectId),
|
|
3147
|
+
eq(subAgentToolRelations.graphId, graphId),
|
|
3148
|
+
eq(subAgentToolRelations.subAgentId, agent.id)
|
|
3148
3149
|
)
|
|
3149
3150
|
);
|
|
3150
|
-
const agentDataComponentRelations = await db.query.
|
|
3151
|
+
const agentDataComponentRelations = await db.query.subAgentDataComponents.findMany({
|
|
3151
3152
|
where: and(
|
|
3152
|
-
eq(
|
|
3153
|
-
eq(
|
|
3153
|
+
eq(subAgentDataComponents.tenantId, tenantId),
|
|
3154
|
+
eq(subAgentDataComponents.subAgentId, agent.id)
|
|
3154
3155
|
)
|
|
3155
3156
|
});
|
|
3156
3157
|
const agentDataComponentIds = agentDataComponentRelations.map((rel) => rel.dataComponentId);
|
|
3157
|
-
const agentArtifactComponentRelations = await db.query.
|
|
3158
|
+
const agentArtifactComponentRelations = await db.query.subAgentArtifactComponents.findMany({
|
|
3158
3159
|
where: and(
|
|
3159
|
-
eq(
|
|
3160
|
-
eq(
|
|
3160
|
+
eq(subAgentArtifactComponents.tenantId, tenantId),
|
|
3161
|
+
eq(subAgentArtifactComponents.subAgentId, agent.id)
|
|
3161
3162
|
)
|
|
3162
3163
|
});
|
|
3163
3164
|
const agentArtifactComponentIds = agentArtifactComponentRelations.map(
|
|
3164
3165
|
(rel) => rel.artifactComponentId
|
|
3165
3166
|
);
|
|
3166
|
-
const canUse =
|
|
3167
|
+
const canUse = subAgentTools.map((tool2) => ({
|
|
3167
3168
|
agentToolRelationId: tool2.agentToolRelationId,
|
|
3168
3169
|
toolId: tool2.id,
|
|
3169
3170
|
toolSelection: tool2.selectedTools || null,
|
|
@@ -3185,24 +3186,24 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3185
3186
|
})
|
|
3186
3187
|
);
|
|
3187
3188
|
const externalAgents2 = await Promise.all(
|
|
3188
|
-
Array.from(
|
|
3189
|
-
const
|
|
3189
|
+
Array.from(externalSubAgentIds).map(async (subAgentId) => {
|
|
3190
|
+
const subAgent = await getExternalAgent(db)({
|
|
3190
3191
|
scopes: { tenantId, projectId, graphId },
|
|
3191
|
-
|
|
3192
|
+
subAgentId
|
|
3192
3193
|
});
|
|
3193
|
-
if (!
|
|
3194
|
+
if (!subAgent) return null;
|
|
3194
3195
|
return {
|
|
3195
|
-
id:
|
|
3196
|
-
name:
|
|
3197
|
-
description:
|
|
3198
|
-
baseUrl:
|
|
3199
|
-
headers:
|
|
3200
|
-
credentialReferenceId:
|
|
3196
|
+
id: subAgent.id,
|
|
3197
|
+
name: subAgent.name,
|
|
3198
|
+
description: subAgent.description,
|
|
3199
|
+
baseUrl: subAgent.baseUrl,
|
|
3200
|
+
headers: subAgent.headers,
|
|
3201
|
+
credentialReferenceId: subAgent.credentialReferenceId,
|
|
3201
3202
|
type: "external"
|
|
3202
3203
|
};
|
|
3203
3204
|
})
|
|
3204
3205
|
);
|
|
3205
|
-
const validAgents = [...
|
|
3206
|
+
const validAgents = [...processedSubAgents, ...externalAgents2].filter(
|
|
3206
3207
|
(agent) => agent !== null
|
|
3207
3208
|
);
|
|
3208
3209
|
const agentsObject = {};
|
|
@@ -3234,13 +3235,14 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3234
3235
|
}
|
|
3235
3236
|
}
|
|
3236
3237
|
try {
|
|
3237
|
-
const internalAgentIds =
|
|
3238
|
-
const
|
|
3239
|
-
await fetchComponentRelationships(db)({ tenantId, projectId },
|
|
3240
|
-
relationTable:
|
|
3238
|
+
const internalAgentIds = graphSubAgents.map((agent) => agent.id);
|
|
3239
|
+
const subAgentIds = Array.from(internalAgentIds);
|
|
3240
|
+
await fetchComponentRelationships(db)({ tenantId, projectId }, subAgentIds, {
|
|
3241
|
+
relationTable: subAgentDataComponents,
|
|
3241
3242
|
componentTable: dataComponents,
|
|
3242
|
-
relationIdField:
|
|
3243
|
+
relationIdField: subAgentDataComponents.dataComponentId,
|
|
3243
3244
|
componentIdField: dataComponents.id,
|
|
3245
|
+
subAgentIdField: subAgentDataComponents.subAgentId,
|
|
3244
3246
|
selectFields: {
|
|
3245
3247
|
id: dataComponents.id,
|
|
3246
3248
|
name: dataComponents.name,
|
|
@@ -3252,13 +3254,14 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3252
3254
|
console.warn("Failed to retrieve dataComponents:", error);
|
|
3253
3255
|
}
|
|
3254
3256
|
try {
|
|
3255
|
-
const internalAgentIds =
|
|
3256
|
-
const
|
|
3257
|
-
await fetchComponentRelationships(db)({ tenantId, projectId },
|
|
3258
|
-
relationTable:
|
|
3257
|
+
const internalAgentIds = graphSubAgents.map((agent) => agent.id);
|
|
3258
|
+
const subAgentIds = Array.from(internalAgentIds);
|
|
3259
|
+
await fetchComponentRelationships(db)({ tenantId, projectId }, subAgentIds, {
|
|
3260
|
+
relationTable: subAgentArtifactComponents,
|
|
3259
3261
|
componentTable: artifactComponents,
|
|
3260
|
-
relationIdField:
|
|
3262
|
+
relationIdField: subAgentArtifactComponents.artifactComponentId,
|
|
3261
3263
|
componentIdField: artifactComponents.id,
|
|
3264
|
+
subAgentIdField: subAgentArtifactComponents.subAgentId,
|
|
3262
3265
|
selectFields: {
|
|
3263
3266
|
id: artifactComponents.id,
|
|
3264
3267
|
name: artifactComponents.name,
|
|
@@ -3273,8 +3276,8 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3273
3276
|
id: graph.id,
|
|
3274
3277
|
name: graph.name,
|
|
3275
3278
|
description: graph.description,
|
|
3276
|
-
|
|
3277
|
-
|
|
3279
|
+
defaultSubAgentId: graph.defaultSubAgentId,
|
|
3280
|
+
subAgents: agentsObject,
|
|
3278
3281
|
// No tools field - tools are defined at project level
|
|
3279
3282
|
createdAt: graph.createdAt && !Number.isNaN(new Date(graph.createdAt).getTime()) ? new Date(graph.createdAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
3280
3283
|
updatedAt: graph.updatedAt && !Number.isNaN(new Date(graph.updatedAt).getTime()) ? new Date(graph.updatedAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -3308,7 +3311,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3308
3311
|
if (project?.stopWhen) {
|
|
3309
3312
|
const projectStopWhen = project.stopWhen;
|
|
3310
3313
|
if (projectStopWhen?.stepCountIs !== void 0) {
|
|
3311
|
-
for (const [
|
|
3314
|
+
for (const [subAgentId, agentData] of Object.entries(result.subAgents)) {
|
|
3312
3315
|
if (agentData && typeof agentData === "object" && !("baseUrl" in agentData)) {
|
|
3313
3316
|
const agent = agentData;
|
|
3314
3317
|
const needsInheritance = !agent.stopWhen || agent.stopWhen.stepCountIs === void 0;
|
|
@@ -3318,22 +3321,22 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3318
3321
|
}
|
|
3319
3322
|
agent.stopWhen.stepCountIs = projectStopWhen.stepCountIs;
|
|
3320
3323
|
try {
|
|
3321
|
-
await db.update(
|
|
3324
|
+
await db.update(subAgents).set({
|
|
3322
3325
|
stopWhen: agent.stopWhen,
|
|
3323
3326
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3324
3327
|
}).where(
|
|
3325
3328
|
and(
|
|
3326
|
-
eq(
|
|
3327
|
-
eq(
|
|
3328
|
-
eq(
|
|
3329
|
+
eq(subAgents.tenantId, tenantId),
|
|
3330
|
+
eq(subAgents.projectId, projectId),
|
|
3331
|
+
eq(subAgents.id, subAgentId)
|
|
3329
3332
|
)
|
|
3330
3333
|
);
|
|
3331
|
-
result.
|
|
3332
|
-
...result.
|
|
3334
|
+
result.subAgents[subAgentId] = {
|
|
3335
|
+
...result.subAgents[subAgentId],
|
|
3333
3336
|
stopWhen: agent.stopWhen
|
|
3334
3337
|
};
|
|
3335
3338
|
} catch (dbError) {
|
|
3336
|
-
console.warn(`Failed to persist stopWhen for agent ${
|
|
3339
|
+
console.warn(`Failed to persist stopWhen for agent ${subAgentId}:`, dbError);
|
|
3337
3340
|
}
|
|
3338
3341
|
}
|
|
3339
3342
|
}
|
|
@@ -3401,7 +3404,7 @@ var upsertAgentGraph = (db) => async (params) => {
|
|
|
3401
3404
|
scopes,
|
|
3402
3405
|
data: {
|
|
3403
3406
|
name: params.data.name,
|
|
3404
|
-
|
|
3407
|
+
defaultSubAgentId: params.data.defaultSubAgentId,
|
|
3405
3408
|
description: params.data.description,
|
|
3406
3409
|
contextConfigId: params.data.contextConfigId,
|
|
3407
3410
|
models: params.data.models,
|
|
@@ -3679,24 +3682,24 @@ var getArtifactComponentsForAgent = (db) => async (params) => {
|
|
|
3679
3682
|
createdAt: artifactComponents.createdAt,
|
|
3680
3683
|
updatedAt: artifactComponents.updatedAt
|
|
3681
3684
|
}).from(artifactComponents).innerJoin(
|
|
3682
|
-
|
|
3683
|
-
eq(artifactComponents.id,
|
|
3685
|
+
subAgentArtifactComponents,
|
|
3686
|
+
eq(artifactComponents.id, subAgentArtifactComponents.artifactComponentId)
|
|
3684
3687
|
).where(
|
|
3685
3688
|
and(
|
|
3686
3689
|
eq(artifactComponents.tenantId, params.scopes.tenantId),
|
|
3687
3690
|
eq(artifactComponents.projectId, params.scopes.projectId),
|
|
3688
|
-
eq(
|
|
3689
|
-
eq(
|
|
3691
|
+
eq(subAgentArtifactComponents.graphId, params.scopes.graphId),
|
|
3692
|
+
eq(subAgentArtifactComponents.subAgentId, params.scopes.subAgentId)
|
|
3690
3693
|
)
|
|
3691
3694
|
).orderBy(desc(artifactComponents.createdAt));
|
|
3692
3695
|
};
|
|
3693
3696
|
var associateArtifactComponentWithAgent = (db) => async (params) => {
|
|
3694
|
-
const [association] = await db.insert(
|
|
3697
|
+
const [association] = await db.insert(subAgentArtifactComponents).values({
|
|
3695
3698
|
id: nanoid(),
|
|
3696
3699
|
tenantId: params.scopes.tenantId,
|
|
3697
3700
|
projectId: params.scopes.projectId,
|
|
3698
3701
|
graphId: params.scopes.graphId,
|
|
3699
|
-
|
|
3702
|
+
subAgentId: params.scopes.subAgentId,
|
|
3700
3703
|
artifactComponentId: params.artifactComponentId,
|
|
3701
3704
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3702
3705
|
}).returning();
|
|
@@ -3704,13 +3707,13 @@ var associateArtifactComponentWithAgent = (db) => async (params) => {
|
|
|
3704
3707
|
};
|
|
3705
3708
|
var removeArtifactComponentFromAgent = (db) => async (params) => {
|
|
3706
3709
|
try {
|
|
3707
|
-
const result = await db.delete(
|
|
3710
|
+
const result = await db.delete(subAgentArtifactComponents).where(
|
|
3708
3711
|
and(
|
|
3709
|
-
eq(
|
|
3710
|
-
eq(
|
|
3711
|
-
eq(
|
|
3712
|
-
eq(
|
|
3713
|
-
eq(
|
|
3712
|
+
eq(subAgentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
3713
|
+
eq(subAgentArtifactComponents.projectId, params.scopes.projectId),
|
|
3714
|
+
eq(subAgentArtifactComponents.graphId, params.scopes.graphId),
|
|
3715
|
+
eq(subAgentArtifactComponents.subAgentId, params.scopes.subAgentId),
|
|
3716
|
+
eq(subAgentArtifactComponents.artifactComponentId, params.artifactComponentId)
|
|
3714
3717
|
)
|
|
3715
3718
|
).returning();
|
|
3716
3719
|
return result.length > 0;
|
|
@@ -3720,60 +3723,60 @@ var removeArtifactComponentFromAgent = (db) => async (params) => {
|
|
|
3720
3723
|
}
|
|
3721
3724
|
};
|
|
3722
3725
|
var deleteAgentArtifactComponentRelationByAgent = (db) => async (params) => {
|
|
3723
|
-
const result = await db.delete(
|
|
3726
|
+
const result = await db.delete(subAgentArtifactComponents).where(
|
|
3724
3727
|
and(
|
|
3725
|
-
eq(
|
|
3726
|
-
eq(
|
|
3727
|
-
eq(
|
|
3728
|
+
eq(subAgentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
3729
|
+
eq(subAgentArtifactComponents.graphId, params.scopes.graphId),
|
|
3730
|
+
eq(subAgentArtifactComponents.subAgentId, params.scopes.subAgentId)
|
|
3728
3731
|
)
|
|
3729
3732
|
);
|
|
3730
3733
|
return (result.rowsAffected || 0) > 0;
|
|
3731
3734
|
};
|
|
3732
3735
|
var getAgentsUsingArtifactComponent = (db) => async (params) => {
|
|
3733
3736
|
return await db.select({
|
|
3734
|
-
graphId:
|
|
3735
|
-
|
|
3736
|
-
createdAt:
|
|
3737
|
-
}).from(
|
|
3737
|
+
graphId: subAgentArtifactComponents.graphId,
|
|
3738
|
+
subAgentId: subAgentArtifactComponents.subAgentId,
|
|
3739
|
+
createdAt: subAgentArtifactComponents.createdAt
|
|
3740
|
+
}).from(subAgentArtifactComponents).where(
|
|
3738
3741
|
and(
|
|
3739
|
-
eq(
|
|
3740
|
-
eq(
|
|
3741
|
-
eq(
|
|
3742
|
+
eq(subAgentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
3743
|
+
eq(subAgentArtifactComponents.projectId, params.scopes.projectId),
|
|
3744
|
+
eq(subAgentArtifactComponents.artifactComponentId, params.artifactComponentId)
|
|
3742
3745
|
)
|
|
3743
|
-
).orderBy(desc(
|
|
3746
|
+
).orderBy(desc(subAgentArtifactComponents.createdAt));
|
|
3744
3747
|
};
|
|
3745
3748
|
var isArtifactComponentAssociatedWithAgent = (db) => async (params) => {
|
|
3746
|
-
const result = await db.select({ id:
|
|
3749
|
+
const result = await db.select({ id: subAgentArtifactComponents.id }).from(subAgentArtifactComponents).where(
|
|
3747
3750
|
and(
|
|
3748
|
-
eq(
|
|
3749
|
-
eq(
|
|
3750
|
-
eq(
|
|
3751
|
-
eq(
|
|
3752
|
-
eq(
|
|
3751
|
+
eq(subAgentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
3752
|
+
eq(subAgentArtifactComponents.projectId, params.scopes.projectId),
|
|
3753
|
+
eq(subAgentArtifactComponents.graphId, params.scopes.graphId),
|
|
3754
|
+
eq(subAgentArtifactComponents.subAgentId, params.scopes.subAgentId),
|
|
3755
|
+
eq(subAgentArtifactComponents.artifactComponentId, params.artifactComponentId)
|
|
3753
3756
|
)
|
|
3754
3757
|
).limit(1);
|
|
3755
3758
|
return result.length > 0;
|
|
3756
3759
|
};
|
|
3757
3760
|
var graphHasArtifactComponents = (db) => async (params) => {
|
|
3758
|
-
const result = await db.select({ count: count() }).from(
|
|
3759
|
-
|
|
3761
|
+
const result = await db.select({ count: count() }).from(subAgentArtifactComponents).innerJoin(
|
|
3762
|
+
subAgents,
|
|
3760
3763
|
and(
|
|
3761
|
-
eq(
|
|
3762
|
-
eq(
|
|
3764
|
+
eq(subAgentArtifactComponents.subAgentId, subAgents.id),
|
|
3765
|
+
eq(subAgentArtifactComponents.tenantId, subAgents.tenantId)
|
|
3763
3766
|
)
|
|
3764
3767
|
).innerJoin(
|
|
3765
|
-
|
|
3768
|
+
subAgentRelations,
|
|
3766
3769
|
and(
|
|
3767
|
-
eq(
|
|
3768
|
-
eq(
|
|
3769
|
-
eq(
|
|
3770
|
-
eq(
|
|
3770
|
+
eq(subAgents.id, subAgentRelations.sourceSubAgentId),
|
|
3771
|
+
eq(subAgents.tenantId, subAgentRelations.tenantId),
|
|
3772
|
+
eq(subAgents.projectId, subAgentRelations.projectId),
|
|
3773
|
+
eq(subAgents.graphId, subAgentRelations.graphId)
|
|
3771
3774
|
)
|
|
3772
3775
|
).where(
|
|
3773
3776
|
and(
|
|
3774
|
-
eq(
|
|
3775
|
-
eq(
|
|
3776
|
-
eq(
|
|
3777
|
+
eq(subAgentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
3778
|
+
eq(subAgentArtifactComponents.projectId, params.scopes.projectId),
|
|
3779
|
+
eq(subAgentRelations.graphId, params.scopes.graphId)
|
|
3777
3780
|
)
|
|
3778
3781
|
).limit(1);
|
|
3779
3782
|
const total = result[0]?.count || 0;
|
|
@@ -3791,12 +3794,12 @@ var countArtifactComponents = (db) => async (params) => {
|
|
|
3791
3794
|
return typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
3792
3795
|
};
|
|
3793
3796
|
var countArtifactComponentsForAgent = (db) => async (params) => {
|
|
3794
|
-
const result = await db.select({ count: count() }).from(
|
|
3797
|
+
const result = await db.select({ count: count() }).from(subAgentArtifactComponents).where(
|
|
3795
3798
|
and(
|
|
3796
|
-
eq(
|
|
3797
|
-
eq(
|
|
3798
|
-
eq(
|
|
3799
|
-
eq(
|
|
3799
|
+
eq(subAgentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
3800
|
+
eq(subAgentArtifactComponents.projectId, params.scopes.projectId),
|
|
3801
|
+
eq(subAgentArtifactComponents.graphId, params.scopes.graphId),
|
|
3802
|
+
eq(subAgentArtifactComponents.subAgentId, params.scopes.subAgentId)
|
|
3800
3803
|
)
|
|
3801
3804
|
);
|
|
3802
3805
|
const total = result[0]?.count || 0;
|
|
@@ -4031,7 +4034,7 @@ var updateConversationActiveAgent = (db) => async (params) => {
|
|
|
4031
4034
|
scopes: params.scopes,
|
|
4032
4035
|
conversationId: params.conversationId,
|
|
4033
4036
|
data: {
|
|
4034
|
-
|
|
4037
|
+
activeSubAgentId: params.activeSubAgentId
|
|
4035
4038
|
}
|
|
4036
4039
|
});
|
|
4037
4040
|
};
|
|
@@ -4051,12 +4054,12 @@ var createOrGetConversation = (db) => async (input) => {
|
|
|
4051
4054
|
where: and(eq(conversations.tenantId, input.tenantId), eq(conversations.id, input.id))
|
|
4052
4055
|
});
|
|
4053
4056
|
if (existing) {
|
|
4054
|
-
if (existing.
|
|
4057
|
+
if (existing.activeSubAgentId !== input.activeSubAgentId) {
|
|
4055
4058
|
await db.update(conversations).set({
|
|
4056
|
-
|
|
4059
|
+
activeSubAgentId: input.activeSubAgentId,
|
|
4057
4060
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4058
4061
|
}).where(eq(conversations.id, input.id));
|
|
4059
|
-
return { ...existing,
|
|
4062
|
+
return { ...existing, activeSubAgentId: input.activeSubAgentId };
|
|
4060
4063
|
}
|
|
4061
4064
|
return existing;
|
|
4062
4065
|
}
|
|
@@ -4066,7 +4069,7 @@ var createOrGetConversation = (db) => async (input) => {
|
|
|
4066
4069
|
tenantId: input.tenantId,
|
|
4067
4070
|
projectId: input.projectId,
|
|
4068
4071
|
userId: input.userId,
|
|
4069
|
-
|
|
4072
|
+
activeSubAgentId: input.activeSubAgentId,
|
|
4070
4073
|
title: input.title,
|
|
4071
4074
|
lastContextResolution: input.lastContextResolution,
|
|
4072
4075
|
metadata: input.metadata,
|
|
@@ -4152,13 +4155,13 @@ var setActiveAgentForConversation = (db) => async (params) => {
|
|
|
4152
4155
|
id: params.conversationId,
|
|
4153
4156
|
tenantId: params.scopes.tenantId,
|
|
4154
4157
|
projectId: params.scopes.projectId,
|
|
4155
|
-
|
|
4158
|
+
activeSubAgentId: params.subAgentId,
|
|
4156
4159
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4157
4160
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4158
4161
|
}).onConflictDoUpdate({
|
|
4159
4162
|
target: [conversations.tenantId, conversations.projectId, conversations.id],
|
|
4160
4163
|
set: {
|
|
4161
|
-
|
|
4164
|
+
activeSubAgentId: params.subAgentId,
|
|
4162
4165
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4163
4166
|
}
|
|
4164
4167
|
});
|
|
@@ -4166,9 +4169,13 @@ var setActiveAgentForConversation = (db) => async (params) => {
|
|
|
4166
4169
|
var setActiveAgentForThread = (db) => async ({
|
|
4167
4170
|
scopes,
|
|
4168
4171
|
threadId,
|
|
4169
|
-
|
|
4172
|
+
subAgentId
|
|
4170
4173
|
}) => {
|
|
4171
|
-
return setActiveAgentForConversation(db)({
|
|
4174
|
+
return setActiveAgentForConversation(db)({
|
|
4175
|
+
scopes,
|
|
4176
|
+
conversationId: threadId,
|
|
4177
|
+
subAgentId
|
|
4178
|
+
});
|
|
4172
4179
|
};
|
|
4173
4180
|
var getDataComponent = (db) => async (params) => {
|
|
4174
4181
|
const result = await db.query.dataComponents.findFirst({
|
|
@@ -4268,68 +4275,71 @@ var getDataComponentsForAgent = (db) => async (params) => {
|
|
|
4268
4275
|
props: dataComponents.props,
|
|
4269
4276
|
createdAt: dataComponents.createdAt,
|
|
4270
4277
|
updatedAt: dataComponents.updatedAt
|
|
4271
|
-
}).from(dataComponents).innerJoin(
|
|
4278
|
+
}).from(dataComponents).innerJoin(
|
|
4279
|
+
subAgentDataComponents,
|
|
4280
|
+
eq(dataComponents.id, subAgentDataComponents.dataComponentId)
|
|
4281
|
+
).where(
|
|
4272
4282
|
and(
|
|
4273
4283
|
eq(dataComponents.tenantId, params.scopes.tenantId),
|
|
4274
4284
|
eq(dataComponents.projectId, params.scopes.projectId),
|
|
4275
|
-
eq(
|
|
4276
|
-
eq(
|
|
4285
|
+
eq(subAgentDataComponents.graphId, params.scopes.graphId),
|
|
4286
|
+
eq(subAgentDataComponents.subAgentId, params.scopes.subAgentId)
|
|
4277
4287
|
)
|
|
4278
4288
|
).orderBy(desc(dataComponents.createdAt));
|
|
4279
4289
|
};
|
|
4280
4290
|
var associateDataComponentWithAgent = (db) => async (params) => {
|
|
4281
|
-
const association = await db.insert(
|
|
4291
|
+
const association = await db.insert(subAgentDataComponents).values({
|
|
4282
4292
|
id: nanoid(),
|
|
4283
4293
|
tenantId: params.scopes.tenantId,
|
|
4284
4294
|
projectId: params.scopes.projectId,
|
|
4285
4295
|
graphId: params.scopes.graphId,
|
|
4286
|
-
|
|
4296
|
+
subAgentId: params.scopes.subAgentId,
|
|
4287
4297
|
dataComponentId: params.dataComponentId
|
|
4288
4298
|
}).returning();
|
|
4289
4299
|
return association[0];
|
|
4290
4300
|
};
|
|
4291
4301
|
var removeDataComponentFromAgent = (db) => async (params) => {
|
|
4292
|
-
const result = await db.delete(
|
|
4302
|
+
const result = await db.delete(subAgentDataComponents).where(
|
|
4293
4303
|
and(
|
|
4294
|
-
eq(
|
|
4295
|
-
eq(
|
|
4296
|
-
eq(
|
|
4297
|
-
eq(
|
|
4298
|
-
eq(
|
|
4304
|
+
eq(subAgentDataComponents.tenantId, params.scopes.tenantId),
|
|
4305
|
+
eq(subAgentDataComponents.projectId, params.scopes.projectId),
|
|
4306
|
+
eq(subAgentDataComponents.graphId, params.scopes.graphId),
|
|
4307
|
+
eq(subAgentDataComponents.subAgentId, params.scopes.subAgentId),
|
|
4308
|
+
eq(subAgentDataComponents.dataComponentId, params.dataComponentId)
|
|
4299
4309
|
)
|
|
4300
4310
|
).returning();
|
|
4301
4311
|
return result.length > 0;
|
|
4302
4312
|
};
|
|
4303
4313
|
var deleteAgentDataComponentRelationByAgent = (db) => async (params) => {
|
|
4304
|
-
const result = await db.delete(
|
|
4314
|
+
const result = await db.delete(subAgentDataComponents).where(
|
|
4305
4315
|
and(
|
|
4306
|
-
eq(
|
|
4307
|
-
eq(
|
|
4308
|
-
eq(
|
|
4316
|
+
eq(subAgentDataComponents.tenantId, params.scopes.tenantId),
|
|
4317
|
+
eq(subAgentDataComponents.graphId, params.scopes.graphId),
|
|
4318
|
+
eq(subAgentDataComponents.subAgentId, params.scopes.subAgentId)
|
|
4309
4319
|
)
|
|
4310
4320
|
);
|
|
4311
4321
|
return (result.rowsAffected || 0) > 0;
|
|
4312
4322
|
};
|
|
4313
4323
|
var getAgentsUsingDataComponent = (db) => async (params) => {
|
|
4314
4324
|
return await db.select({
|
|
4315
|
-
|
|
4316
|
-
createdAt:
|
|
4317
|
-
}).from(
|
|
4325
|
+
subAgentId: subAgentDataComponents.subAgentId,
|
|
4326
|
+
createdAt: subAgentDataComponents.createdAt
|
|
4327
|
+
}).from(subAgentDataComponents).where(
|
|
4318
4328
|
and(
|
|
4319
|
-
eq(
|
|
4320
|
-
eq(
|
|
4321
|
-
eq(
|
|
4329
|
+
eq(subAgentDataComponents.tenantId, params.scopes.tenantId),
|
|
4330
|
+
eq(subAgentDataComponents.projectId, params.scopes.projectId),
|
|
4331
|
+
eq(subAgentDataComponents.dataComponentId, params.dataComponentId)
|
|
4322
4332
|
)
|
|
4323
|
-
).orderBy(desc(
|
|
4333
|
+
).orderBy(desc(subAgentDataComponents.createdAt));
|
|
4324
4334
|
};
|
|
4325
4335
|
var isDataComponentAssociatedWithAgent = (db) => async (params) => {
|
|
4326
|
-
const result = await db.select({ id:
|
|
4336
|
+
const result = await db.select({ id: subAgentDataComponents.id }).from(subAgentDataComponents).where(
|
|
4327
4337
|
and(
|
|
4328
|
-
eq(
|
|
4329
|
-
eq(
|
|
4330
|
-
eq(
|
|
4331
|
-
eq(
|
|
4332
|
-
eq(
|
|
4338
|
+
eq(subAgentDataComponents.tenantId, params.scopes.tenantId),
|
|
4339
|
+
eq(subAgentDataComponents.projectId, params.scopes.projectId),
|
|
4340
|
+
eq(subAgentDataComponents.graphId, params.scopes.graphId),
|
|
4341
|
+
eq(subAgentDataComponents.subAgentId, params.scopes.subAgentId),
|
|
4342
|
+
eq(subAgentDataComponents.dataComponentId, params.dataComponentId)
|
|
4333
4343
|
)
|
|
4334
4344
|
).limit(1);
|
|
4335
4345
|
return result.length > 0;
|
|
@@ -4426,7 +4436,7 @@ async function applyExecutionLimitsInheritance(db, logger12, scopes, graphData)
|
|
|
4426
4436
|
},
|
|
4427
4437
|
"Propagating stepCountIs to agents"
|
|
4428
4438
|
);
|
|
4429
|
-
for (const [
|
|
4439
|
+
for (const [subAgentId, agentData] of Object.entries(graphData.subAgents)) {
|
|
4430
4440
|
if (isInternalAgent(agentData)) {
|
|
4431
4441
|
const agent = agentData;
|
|
4432
4442
|
if (!agent.stopWhen) {
|
|
@@ -4436,7 +4446,7 @@ async function applyExecutionLimitsInheritance(db, logger12, scopes, graphData)
|
|
|
4436
4446
|
agent.stopWhen.stepCountIs = projectStopWhen.stepCountIs;
|
|
4437
4447
|
logger12.info(
|
|
4438
4448
|
{
|
|
4439
|
-
|
|
4449
|
+
subAgentId,
|
|
4440
4450
|
inheritedValue: projectStopWhen.stepCountIs
|
|
4441
4451
|
},
|
|
4442
4452
|
"Agent inherited stepCountIs from project"
|
|
@@ -4476,7 +4486,7 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4476
4486
|
tenantId,
|
|
4477
4487
|
projectId,
|
|
4478
4488
|
name: typed.name,
|
|
4479
|
-
|
|
4489
|
+
defaultSubAgentId: typed.defaultSubAgentId,
|
|
4480
4490
|
description: typed.description,
|
|
4481
4491
|
contextConfigId: void 0,
|
|
4482
4492
|
// Will be updated later if context config exists
|
|
@@ -4526,7 +4536,7 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4526
4536
|
tenantId,
|
|
4527
4537
|
projectId,
|
|
4528
4538
|
name: typed.name,
|
|
4529
|
-
|
|
4539
|
+
defaultSubAgentId: typed.defaultSubAgentId,
|
|
4530
4540
|
description: typed.description,
|
|
4531
4541
|
contextConfigId,
|
|
4532
4542
|
models: typed.models,
|
|
@@ -4555,13 +4565,13 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4555
4565
|
{},
|
|
4556
4566
|
"ArtifactComponents are project-scoped - skipping artifactComponent creation in graph"
|
|
4557
4567
|
);
|
|
4558
|
-
const internalAgentPromises = Object.entries(typed.
|
|
4568
|
+
const internalAgentPromises = Object.entries(typed.subAgents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([subAgentId, agentData]) => {
|
|
4559
4569
|
const internalAgent = agentData;
|
|
4560
4570
|
try {
|
|
4561
|
-
logger12.info({
|
|
4562
|
-
await
|
|
4571
|
+
logger12.info({ subAgentId }, "Processing internal agent");
|
|
4572
|
+
await upsertSubAgent(db)({
|
|
4563
4573
|
data: {
|
|
4564
|
-
id:
|
|
4574
|
+
id: subAgentId,
|
|
4565
4575
|
tenantId,
|
|
4566
4576
|
projectId,
|
|
4567
4577
|
graphId: finalGraphId,
|
|
@@ -4573,24 +4583,24 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4573
4583
|
stopWhen: internalAgent.stopWhen
|
|
4574
4584
|
}
|
|
4575
4585
|
});
|
|
4576
|
-
logger12.info({
|
|
4586
|
+
logger12.info({ subAgentId }, "Internal agent processed successfully");
|
|
4577
4587
|
} catch (error) {
|
|
4578
|
-
logger12.error({
|
|
4588
|
+
logger12.error({ subAgentId, error }, "Failed to create/update internal agent");
|
|
4579
4589
|
throw error;
|
|
4580
4590
|
}
|
|
4581
4591
|
});
|
|
4582
4592
|
await Promise.all(internalAgentPromises);
|
|
4583
|
-
const internalAgentCount = Object.entries(typed.
|
|
4593
|
+
const internalAgentCount = Object.entries(typed.subAgents).filter(
|
|
4584
4594
|
([_, agentData]) => isInternalAgent(agentData)
|
|
4585
4595
|
).length;
|
|
4586
4596
|
logger12.info({ internalAgentCount }, "All internal agents created/updated successfully");
|
|
4587
|
-
const externalAgentPromises = Object.entries(typed.
|
|
4597
|
+
const externalAgentPromises = Object.entries(typed.subAgents).filter(([_, agentData]) => isExternalAgent(agentData)).map(async ([subAgentId, agentData]) => {
|
|
4588
4598
|
const externalAgent = agentData;
|
|
4589
4599
|
try {
|
|
4590
|
-
logger12.info({
|
|
4600
|
+
logger12.info({ subAgentId }, "Processing external agent");
|
|
4591
4601
|
await upsertExternalAgent(db)({
|
|
4592
4602
|
data: {
|
|
4593
|
-
id:
|
|
4603
|
+
id: subAgentId,
|
|
4594
4604
|
tenantId,
|
|
4595
4605
|
projectId,
|
|
4596
4606
|
graphId: finalGraphId,
|
|
@@ -4601,14 +4611,14 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4601
4611
|
headers: externalAgent.headers || void 0
|
|
4602
4612
|
}
|
|
4603
4613
|
});
|
|
4604
|
-
logger12.info({
|
|
4614
|
+
logger12.info({ subAgentId }, "External agent processed successfully");
|
|
4605
4615
|
} catch (error) {
|
|
4606
|
-
logger12.error({
|
|
4616
|
+
logger12.error({ subAgentId, error }, "Failed to create/update external agent");
|
|
4607
4617
|
throw error;
|
|
4608
4618
|
}
|
|
4609
4619
|
});
|
|
4610
4620
|
await Promise.all(externalAgentPromises);
|
|
4611
|
-
const externalAgentCount = Object.entries(typed.
|
|
4621
|
+
const externalAgentCount = Object.entries(typed.subAgents).filter(
|
|
4612
4622
|
([_, agentData]) => isExternalAgent(agentData)
|
|
4613
4623
|
).length;
|
|
4614
4624
|
logger12.info({ externalAgentCount }, "All external agents created/updated successfully");
|
|
@@ -4632,26 +4642,26 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4632
4642
|
}
|
|
4633
4643
|
}
|
|
4634
4644
|
const agentToolPromises = [];
|
|
4635
|
-
for (const [
|
|
4645
|
+
for (const [subAgentId, agentData] of Object.entries(typed.subAgents)) {
|
|
4636
4646
|
if (isInternalAgent(agentData) && agentData.canUse && Array.isArray(agentData.canUse)) {
|
|
4637
4647
|
for (const canUseItem of agentData.canUse) {
|
|
4638
4648
|
agentToolPromises.push(
|
|
4639
4649
|
(async () => {
|
|
4640
4650
|
try {
|
|
4641
4651
|
const { toolId, toolSelection, headers: headers2, agentToolRelationId } = canUseItem;
|
|
4642
|
-
logger12.info({
|
|
4652
|
+
logger12.info({ subAgentId, toolId }, "Processing agent-tool relation");
|
|
4643
4653
|
await upsertAgentToolRelation(db)({
|
|
4644
4654
|
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
4645
|
-
|
|
4655
|
+
subAgentId,
|
|
4646
4656
|
toolId,
|
|
4647
4657
|
selectedTools: toolSelection || void 0,
|
|
4648
4658
|
headers: headers2 || void 0,
|
|
4649
4659
|
relationId: agentToolRelationId
|
|
4650
4660
|
});
|
|
4651
|
-
logger12.info({
|
|
4661
|
+
logger12.info({ subAgentId, toolId }, "Agent-tool relation processed successfully");
|
|
4652
4662
|
} catch (error) {
|
|
4653
4663
|
logger12.error(
|
|
4654
|
-
{
|
|
4664
|
+
{ subAgentId, toolId: canUseItem.toolId, error },
|
|
4655
4665
|
"Failed to create agent-tool relation"
|
|
4656
4666
|
);
|
|
4657
4667
|
}
|
|
@@ -4662,31 +4672,31 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4662
4672
|
}
|
|
4663
4673
|
await Promise.all(agentToolPromises);
|
|
4664
4674
|
logger12.info(
|
|
4665
|
-
{ agentToolCount: Object.keys(typed.
|
|
4675
|
+
{ agentToolCount: Object.keys(typed.subAgents).length },
|
|
4666
4676
|
"All agent-tool relations created"
|
|
4667
4677
|
);
|
|
4668
4678
|
const agentDataComponentPromises = [];
|
|
4669
|
-
for (const [
|
|
4679
|
+
for (const [subAgentId, agentData] of Object.entries(typed.subAgents)) {
|
|
4670
4680
|
if (isInternalAgent(agentData) && agentData.dataComponents) {
|
|
4671
4681
|
for (const dataComponentId of agentData.dataComponents) {
|
|
4672
4682
|
agentDataComponentPromises.push(
|
|
4673
4683
|
(async () => {
|
|
4674
4684
|
try {
|
|
4675
4685
|
logger12.info(
|
|
4676
|
-
{
|
|
4686
|
+
{ subAgentId, dataComponentId },
|
|
4677
4687
|
"Processing agent-data component relation"
|
|
4678
4688
|
);
|
|
4679
4689
|
await upsertAgentDataComponentRelation(db)({
|
|
4680
|
-
scopes: { tenantId, projectId, graphId: finalGraphId,
|
|
4690
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, subAgentId },
|
|
4681
4691
|
dataComponentId
|
|
4682
4692
|
});
|
|
4683
4693
|
logger12.info(
|
|
4684
|
-
{
|
|
4694
|
+
{ subAgentId, dataComponentId },
|
|
4685
4695
|
"Agent-data component relation processed successfully"
|
|
4686
4696
|
);
|
|
4687
4697
|
} catch (error) {
|
|
4688
4698
|
logger12.error(
|
|
4689
|
-
{
|
|
4699
|
+
{ subAgentId, dataComponentId, error },
|
|
4690
4700
|
"Failed to create agent-data component relation"
|
|
4691
4701
|
);
|
|
4692
4702
|
}
|
|
@@ -4698,27 +4708,27 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4698
4708
|
await Promise.all(agentDataComponentPromises);
|
|
4699
4709
|
logger12.info({}, "All agent-data component relations created");
|
|
4700
4710
|
const agentArtifactComponentPromises = [];
|
|
4701
|
-
for (const [
|
|
4711
|
+
for (const [subAgentId, agentData] of Object.entries(typed.subAgents)) {
|
|
4702
4712
|
if (isInternalAgent(agentData) && agentData.artifactComponents) {
|
|
4703
4713
|
for (const artifactComponentId of agentData.artifactComponents) {
|
|
4704
4714
|
agentArtifactComponentPromises.push(
|
|
4705
4715
|
(async () => {
|
|
4706
4716
|
try {
|
|
4707
4717
|
logger12.info(
|
|
4708
|
-
{
|
|
4718
|
+
{ subAgentId, artifactComponentId },
|
|
4709
4719
|
"Processing agent-artifact component relation"
|
|
4710
4720
|
);
|
|
4711
4721
|
await upsertAgentArtifactComponentRelation(db)({
|
|
4712
|
-
scopes: { tenantId, projectId, graphId: finalGraphId,
|
|
4722
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, subAgentId },
|
|
4713
4723
|
artifactComponentId
|
|
4714
4724
|
});
|
|
4715
4725
|
logger12.info(
|
|
4716
|
-
{
|
|
4726
|
+
{ subAgentId, artifactComponentId },
|
|
4717
4727
|
"Agent-artifact component relation processed successfully"
|
|
4718
4728
|
);
|
|
4719
4729
|
} catch (error) {
|
|
4720
4730
|
logger12.error(
|
|
4721
|
-
{
|
|
4731
|
+
{ subAgentId, artifactComponentId, error },
|
|
4722
4732
|
"Failed to create agent-artifact component relation"
|
|
4723
4733
|
);
|
|
4724
4734
|
}
|
|
@@ -4730,14 +4740,14 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4730
4740
|
await Promise.all(agentArtifactComponentPromises);
|
|
4731
4741
|
logger12.info({}, "All agent-artifact component relations created");
|
|
4732
4742
|
const agentRelationPromises = [];
|
|
4733
|
-
for (const [
|
|
4743
|
+
for (const [subAgentId, agentData] of Object.entries(typed.subAgents)) {
|
|
4734
4744
|
if (isInternalAgent(agentData) && agentData.canTransferTo) {
|
|
4735
|
-
for (const
|
|
4745
|
+
for (const targetSubAgentId of agentData.canTransferTo) {
|
|
4736
4746
|
agentRelationPromises.push(
|
|
4737
4747
|
(async () => {
|
|
4738
4748
|
try {
|
|
4739
4749
|
logger12.info(
|
|
4740
|
-
{
|
|
4750
|
+
{ subAgentId, targetSubAgentId, type: "transfer" },
|
|
4741
4751
|
"Processing agent transfer relation"
|
|
4742
4752
|
);
|
|
4743
4753
|
await upsertAgentRelation(db)({
|
|
@@ -4745,17 +4755,17 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4745
4755
|
tenantId,
|
|
4746
4756
|
projectId,
|
|
4747
4757
|
graphId: finalGraphId,
|
|
4748
|
-
|
|
4749
|
-
|
|
4758
|
+
sourceSubAgentId: subAgentId,
|
|
4759
|
+
targetSubAgentId,
|
|
4750
4760
|
relationType: "transfer"
|
|
4751
4761
|
});
|
|
4752
4762
|
logger12.info(
|
|
4753
|
-
{
|
|
4763
|
+
{ subAgentId, targetSubAgentId, type: "transfer" },
|
|
4754
4764
|
"Agent transfer relation processed successfully"
|
|
4755
4765
|
);
|
|
4756
4766
|
} catch (error) {
|
|
4757
4767
|
logger12.error(
|
|
4758
|
-
{
|
|
4768
|
+
{ subAgentId, targetSubAgentId, type: "transfer", error },
|
|
4759
4769
|
"Failed to create transfer relation"
|
|
4760
4770
|
);
|
|
4761
4771
|
}
|
|
@@ -4764,14 +4774,14 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4764
4774
|
}
|
|
4765
4775
|
}
|
|
4766
4776
|
if (isInternalAgent(agentData) && agentData.canDelegateTo) {
|
|
4767
|
-
for (const
|
|
4768
|
-
const targetAgentData = typed.
|
|
4777
|
+
for (const targetSubAgentId of agentData.canDelegateTo) {
|
|
4778
|
+
const targetAgentData = typed.subAgents[targetSubAgentId];
|
|
4769
4779
|
const isTargetExternal = isExternalAgent(targetAgentData);
|
|
4770
4780
|
agentRelationPromises.push(
|
|
4771
4781
|
(async () => {
|
|
4772
4782
|
try {
|
|
4773
4783
|
logger12.info(
|
|
4774
|
-
{
|
|
4784
|
+
{ subAgentId, targetSubAgentId, type: "delegate" },
|
|
4775
4785
|
"Processing agent delegation relation"
|
|
4776
4786
|
);
|
|
4777
4787
|
await upsertAgentRelation(db)({
|
|
@@ -4779,18 +4789,18 @@ var createFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4779
4789
|
tenantId,
|
|
4780
4790
|
projectId,
|
|
4781
4791
|
graphId: finalGraphId,
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4792
|
+
sourceSubAgentId: subAgentId,
|
|
4793
|
+
targetSubAgentId: isTargetExternal ? void 0 : targetSubAgentId,
|
|
4794
|
+
externalSubAgentId: isTargetExternal ? targetSubAgentId : void 0,
|
|
4785
4795
|
relationType: "delegate"
|
|
4786
4796
|
});
|
|
4787
4797
|
logger12.info(
|
|
4788
|
-
{
|
|
4798
|
+
{ subAgentId, targetSubAgentId, type: "delegate" },
|
|
4789
4799
|
"Agent delegation relation processed successfully"
|
|
4790
4800
|
);
|
|
4791
4801
|
} catch (error) {
|
|
4792
4802
|
logger12.error(
|
|
4793
|
-
{
|
|
4803
|
+
{ subAgentId, targetSubAgentId, type: "delegate", error },
|
|
4794
4804
|
"Failed to create delegation relation"
|
|
4795
4805
|
);
|
|
4796
4806
|
}
|
|
@@ -4828,7 +4838,7 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4828
4838
|
{
|
|
4829
4839
|
tenantId,
|
|
4830
4840
|
graphId: typedGraphDefinition.id,
|
|
4831
|
-
agentCount: Object.keys(typedGraphDefinition.
|
|
4841
|
+
agentCount: Object.keys(typedGraphDefinition.subAgents).length
|
|
4832
4842
|
},
|
|
4833
4843
|
"Updating full graph in database"
|
|
4834
4844
|
);
|
|
@@ -4866,7 +4876,7 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4866
4876
|
tenantId,
|
|
4867
4877
|
projectId,
|
|
4868
4878
|
name: typedGraphDefinition.name,
|
|
4869
|
-
|
|
4879
|
+
defaultSubAgentId: typedGraphDefinition.defaultSubAgentId,
|
|
4870
4880
|
description: typedGraphDefinition.description,
|
|
4871
4881
|
contextConfigId: void 0,
|
|
4872
4882
|
// Will be updated later if context config exists
|
|
@@ -4924,7 +4934,7 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4924
4934
|
tenantId,
|
|
4925
4935
|
projectId,
|
|
4926
4936
|
name: typedGraphDefinition.name,
|
|
4927
|
-
|
|
4937
|
+
defaultSubAgentId: typedGraphDefinition.defaultSubAgentId,
|
|
4928
4938
|
description: typedGraphDefinition.description,
|
|
4929
4939
|
contextConfigId,
|
|
4930
4940
|
models: typedGraphDefinition.models,
|
|
@@ -4950,15 +4960,15 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4950
4960
|
{},
|
|
4951
4961
|
"ArtifactComponents are project-scoped - skipping artifactComponent update in graph"
|
|
4952
4962
|
);
|
|
4953
|
-
const internalAgentPromises = Object.entries(typedGraphDefinition.
|
|
4963
|
+
const internalAgentPromises = Object.entries(typedGraphDefinition.subAgents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([subAgentId, agentData]) => {
|
|
4954
4964
|
const internalAgent = agentData;
|
|
4955
4965
|
let existingAgent = null;
|
|
4956
4966
|
try {
|
|
4957
|
-
existingAgent = await db.query.
|
|
4967
|
+
existingAgent = await db.query.subAgents.findFirst({
|
|
4958
4968
|
where: and(
|
|
4959
|
-
eq(
|
|
4960
|
-
eq(
|
|
4961
|
-
eq(
|
|
4969
|
+
eq(subAgents.id, subAgentId),
|
|
4970
|
+
eq(subAgents.tenantId, tenantId),
|
|
4971
|
+
eq(subAgents.projectId, projectId)
|
|
4962
4972
|
),
|
|
4963
4973
|
columns: {
|
|
4964
4974
|
models: true
|
|
@@ -4979,7 +4989,7 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4979
4989
|
cascadedModels[modelType] = graphModels[modelType];
|
|
4980
4990
|
logger12.info(
|
|
4981
4991
|
{
|
|
4982
|
-
|
|
4992
|
+
subAgentId,
|
|
4983
4993
|
modelType,
|
|
4984
4994
|
oldModel: agentModels[modelType].model,
|
|
4985
4995
|
newModel: graphModels[modelType].model,
|
|
@@ -4992,10 +5002,10 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
4992
5002
|
finalModelSettings = cascadedModels;
|
|
4993
5003
|
}
|
|
4994
5004
|
try {
|
|
4995
|
-
logger12.info({
|
|
4996
|
-
await
|
|
5005
|
+
logger12.info({ subAgentId }, "Processing internal agent");
|
|
5006
|
+
await upsertSubAgent(db)({
|
|
4997
5007
|
data: {
|
|
4998
|
-
id:
|
|
5008
|
+
id: subAgentId,
|
|
4999
5009
|
tenantId,
|
|
5000
5010
|
projectId,
|
|
5001
5011
|
graphId: finalGraphId,
|
|
@@ -5007,24 +5017,24 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5007
5017
|
stopWhen: internalAgent.stopWhen
|
|
5008
5018
|
}
|
|
5009
5019
|
});
|
|
5010
|
-
logger12.info({
|
|
5020
|
+
logger12.info({ subAgentId }, "Internal agent processed successfully");
|
|
5011
5021
|
} catch (error) {
|
|
5012
|
-
logger12.error({
|
|
5022
|
+
logger12.error({ subAgentId, error }, "Failed to create/update internal agent");
|
|
5013
5023
|
throw error;
|
|
5014
5024
|
}
|
|
5015
5025
|
});
|
|
5016
5026
|
await Promise.all(internalAgentPromises);
|
|
5017
|
-
const internalAgentCount = Object.entries(typedGraphDefinition.
|
|
5027
|
+
const internalAgentCount = Object.entries(typedGraphDefinition.subAgents).filter(
|
|
5018
5028
|
([_, agentData]) => isInternalAgent(agentData)
|
|
5019
5029
|
).length;
|
|
5020
5030
|
logger12.info({ internalAgentCount }, "All internal agents created/updated successfully");
|
|
5021
|
-
const externalAgentPromises = Object.entries(typedGraphDefinition.
|
|
5031
|
+
const externalAgentPromises = Object.entries(typedGraphDefinition.subAgents).filter(([_, agentData]) => isExternalAgent(agentData)).map(async ([subAgentId, agentData]) => {
|
|
5022
5032
|
const externalAgent = agentData;
|
|
5023
5033
|
try {
|
|
5024
|
-
logger12.info({
|
|
5034
|
+
logger12.info({ subAgentId }, "Processing external agent");
|
|
5025
5035
|
await upsertExternalAgent(db)({
|
|
5026
5036
|
data: {
|
|
5027
|
-
id:
|
|
5037
|
+
id: subAgentId,
|
|
5028
5038
|
tenantId,
|
|
5029
5039
|
projectId,
|
|
5030
5040
|
graphId: finalGraphId,
|
|
@@ -5035,19 +5045,19 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5035
5045
|
headers: externalAgent.headers || void 0
|
|
5036
5046
|
}
|
|
5037
5047
|
});
|
|
5038
|
-
logger12.info({
|
|
5048
|
+
logger12.info({ subAgentId }, "External agent processed successfully");
|
|
5039
5049
|
} catch (error) {
|
|
5040
|
-
logger12.error({
|
|
5050
|
+
logger12.error({ subAgentId, error }, "Failed to create/update external agent");
|
|
5041
5051
|
throw error;
|
|
5042
5052
|
}
|
|
5043
5053
|
});
|
|
5044
5054
|
await Promise.all(externalAgentPromises);
|
|
5045
|
-
const externalAgentCount = Object.entries(typedGraphDefinition.
|
|
5055
|
+
const externalAgentCount = Object.entries(typedGraphDefinition.subAgents).filter(
|
|
5046
5056
|
([_, agentData]) => isExternalAgent(agentData)
|
|
5047
5057
|
).length;
|
|
5048
5058
|
logger12.info({ externalAgentCount }, "All external agents created/updated successfully");
|
|
5049
|
-
const incomingAgentIds = new Set(Object.keys(typedGraphDefinition.
|
|
5050
|
-
const existingInternalAgents = await
|
|
5059
|
+
const incomingAgentIds = new Set(Object.keys(typedGraphDefinition.subAgents));
|
|
5060
|
+
const existingInternalAgents = await listSubAgents(db)({
|
|
5051
5061
|
scopes: { tenantId, projectId, graphId: finalGraphId }
|
|
5052
5062
|
});
|
|
5053
5063
|
const existingExternalAgents = await listExternalAgents(db)({
|
|
@@ -5057,14 +5067,17 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5057
5067
|
for (const agent of existingInternalAgents) {
|
|
5058
5068
|
if (!incomingAgentIds.has(agent.id)) {
|
|
5059
5069
|
try {
|
|
5060
|
-
await
|
|
5070
|
+
await deleteSubAgent(db)({
|
|
5061
5071
|
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
5062
|
-
|
|
5072
|
+
subAgentId: agent.id
|
|
5063
5073
|
});
|
|
5064
5074
|
deletedInternalCount++;
|
|
5065
|
-
logger12.info({
|
|
5075
|
+
logger12.info({ subAgentId: agent.id }, "Deleted orphaned internal agent");
|
|
5066
5076
|
} catch (error) {
|
|
5067
|
-
logger12.error(
|
|
5077
|
+
logger12.error(
|
|
5078
|
+
{ subAgentId: agent.id, error },
|
|
5079
|
+
"Failed to delete orphaned internal agent"
|
|
5080
|
+
);
|
|
5068
5081
|
}
|
|
5069
5082
|
}
|
|
5070
5083
|
}
|
|
@@ -5074,12 +5087,15 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5074
5087
|
try {
|
|
5075
5088
|
await deleteExternalAgent(db)({
|
|
5076
5089
|
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
5077
|
-
|
|
5090
|
+
subAgentId: agent.id
|
|
5078
5091
|
});
|
|
5079
5092
|
deletedExternalCount++;
|
|
5080
|
-
logger12.info({
|
|
5093
|
+
logger12.info({ subAgentId: agent.id }, "Deleted orphaned external agent");
|
|
5081
5094
|
} catch (error) {
|
|
5082
|
-
logger12.error(
|
|
5095
|
+
logger12.error(
|
|
5096
|
+
{ subAgentId: agent.id, error },
|
|
5097
|
+
"Failed to delete orphaned external agent"
|
|
5098
|
+
);
|
|
5083
5099
|
}
|
|
5084
5100
|
}
|
|
5085
5101
|
}
|
|
@@ -5097,7 +5113,7 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5097
5113
|
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id },
|
|
5098
5114
|
data: {
|
|
5099
5115
|
name: typedGraphDefinition.name,
|
|
5100
|
-
|
|
5116
|
+
defaultSubAgentId: typedGraphDefinition.defaultSubAgentId,
|
|
5101
5117
|
description: typedGraphDefinition.description,
|
|
5102
5118
|
contextConfigId,
|
|
5103
5119
|
models: typedGraphDefinition.models,
|
|
@@ -5108,7 +5124,7 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5108
5124
|
});
|
|
5109
5125
|
logger12.info({ graphId: typedGraphDefinition.id }, "Graph metadata updated");
|
|
5110
5126
|
const incomingRelationshipIds = /* @__PURE__ */ new Set();
|
|
5111
|
-
for (const [
|
|
5127
|
+
for (const [_subAgentId, agentData] of Object.entries(typedGraphDefinition.subAgents)) {
|
|
5112
5128
|
if (isInternalAgent(agentData) && agentData.canUse && Array.isArray(agentData.canUse)) {
|
|
5113
5129
|
for (const canUseItem of agentData.canUse) {
|
|
5114
5130
|
if (canUseItem.agentToolRelationId) {
|
|
@@ -5117,63 +5133,63 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5117
5133
|
}
|
|
5118
5134
|
}
|
|
5119
5135
|
}
|
|
5120
|
-
for (const
|
|
5136
|
+
for (const subAgentId of Object.keys(typedGraphDefinition.subAgents)) {
|
|
5121
5137
|
try {
|
|
5122
5138
|
let deletedCount = 0;
|
|
5123
5139
|
if (incomingRelationshipIds.size === 0) {
|
|
5124
|
-
const result = await db.delete(
|
|
5140
|
+
const result = await db.delete(subAgentToolRelations).where(
|
|
5125
5141
|
and(
|
|
5126
|
-
eq(
|
|
5127
|
-
eq(
|
|
5128
|
-
eq(
|
|
5129
|
-
eq(
|
|
5142
|
+
eq(subAgentToolRelations.tenantId, tenantId),
|
|
5143
|
+
eq(subAgentToolRelations.projectId, projectId),
|
|
5144
|
+
eq(subAgentToolRelations.graphId, finalGraphId),
|
|
5145
|
+
eq(subAgentToolRelations.subAgentId, subAgentId)
|
|
5130
5146
|
)
|
|
5131
5147
|
);
|
|
5132
5148
|
deletedCount = result.rowsAffected || 0;
|
|
5133
5149
|
} else {
|
|
5134
|
-
const result = await db.delete(
|
|
5150
|
+
const result = await db.delete(subAgentToolRelations).where(
|
|
5135
5151
|
and(
|
|
5136
|
-
eq(
|
|
5137
|
-
eq(
|
|
5138
|
-
eq(
|
|
5139
|
-
eq(
|
|
5140
|
-
not(inArray(
|
|
5152
|
+
eq(subAgentToolRelations.tenantId, tenantId),
|
|
5153
|
+
eq(subAgentToolRelations.projectId, projectId),
|
|
5154
|
+
eq(subAgentToolRelations.graphId, finalGraphId),
|
|
5155
|
+
eq(subAgentToolRelations.subAgentId, subAgentId),
|
|
5156
|
+
not(inArray(subAgentToolRelations.id, Array.from(incomingRelationshipIds)))
|
|
5141
5157
|
)
|
|
5142
5158
|
);
|
|
5143
5159
|
deletedCount = result.rowsAffected || 0;
|
|
5144
5160
|
}
|
|
5145
5161
|
if (deletedCount > 0) {
|
|
5146
|
-
logger12.info({
|
|
5162
|
+
logger12.info({ subAgentId, deletedCount }, "Deleted orphaned agent-tool relations");
|
|
5147
5163
|
}
|
|
5148
5164
|
} catch (error) {
|
|
5149
|
-
logger12.error({
|
|
5165
|
+
logger12.error({ subAgentId, error }, "Failed to delete orphaned agent-tool relations");
|
|
5150
5166
|
}
|
|
5151
5167
|
}
|
|
5152
5168
|
const agentToolPromises = [];
|
|
5153
|
-
for (const [
|
|
5169
|
+
for (const [subAgentId, agentData] of Object.entries(typedGraphDefinition.subAgents)) {
|
|
5154
5170
|
if (isInternalAgent(agentData) && agentData.canUse && Array.isArray(agentData.canUse)) {
|
|
5155
5171
|
for (const canUseItem of agentData.canUse) {
|
|
5156
5172
|
agentToolPromises.push(
|
|
5157
5173
|
(async () => {
|
|
5158
5174
|
try {
|
|
5159
5175
|
const { toolId, toolSelection, headers: headers2, agentToolRelationId } = canUseItem;
|
|
5160
|
-
logger12.info({
|
|
5176
|
+
logger12.info({ subAgentId, toolId }, "Processing agent-tool relation");
|
|
5161
5177
|
await upsertAgentToolRelation(db)({
|
|
5162
5178
|
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
5163
|
-
|
|
5179
|
+
subAgentId,
|
|
5164
5180
|
toolId,
|
|
5165
5181
|
selectedTools: toolSelection || void 0,
|
|
5166
5182
|
headers: headers2 || void 0,
|
|
5167
5183
|
relationId: agentToolRelationId
|
|
5168
5184
|
});
|
|
5169
5185
|
logger12.info(
|
|
5170
|
-
{
|
|
5186
|
+
{ subAgentId, toolId, relationId: agentToolRelationId },
|
|
5171
5187
|
"Agent-tool relation upserted"
|
|
5172
5188
|
);
|
|
5173
5189
|
} catch (error) {
|
|
5174
5190
|
logger12.error(
|
|
5175
5191
|
{
|
|
5176
|
-
|
|
5192
|
+
subAgentId,
|
|
5177
5193
|
toolId: canUseItem.toolId,
|
|
5178
5194
|
relationId: canUseItem.agentToolRelationId,
|
|
5179
5195
|
error
|
|
@@ -5191,26 +5207,29 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5191
5207
|
{ agentToolPromisesCount: agentToolPromises.length },
|
|
5192
5208
|
"All agent-tool relations updated"
|
|
5193
5209
|
);
|
|
5194
|
-
for (const
|
|
5210
|
+
for (const subAgentId of Object.keys(typedGraphDefinition.subAgents)) {
|
|
5195
5211
|
await deleteAgentDataComponentRelationByAgent(db)({
|
|
5196
|
-
scopes: { tenantId, projectId, graphId: finalGraphId,
|
|
5212
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, subAgentId }
|
|
5197
5213
|
});
|
|
5198
5214
|
}
|
|
5199
5215
|
const agentDataComponentPromises = [];
|
|
5200
|
-
for (const [
|
|
5216
|
+
for (const [subAgentId, agentData] of Object.entries(typedGraphDefinition.subAgents)) {
|
|
5201
5217
|
if (isInternalAgent(agentData) && agentData.dataComponents) {
|
|
5202
5218
|
for (const dataComponentId of agentData.dataComponents) {
|
|
5203
5219
|
agentDataComponentPromises.push(
|
|
5204
5220
|
(async () => {
|
|
5205
5221
|
try {
|
|
5206
5222
|
await associateDataComponentWithAgent(db)({
|
|
5207
|
-
scopes: { tenantId, projectId, graphId: finalGraphId,
|
|
5223
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, subAgentId },
|
|
5208
5224
|
dataComponentId
|
|
5209
5225
|
});
|
|
5210
|
-
logger12.info(
|
|
5226
|
+
logger12.info(
|
|
5227
|
+
{ subAgentId, dataComponentId },
|
|
5228
|
+
"Agent-dataComponent relation created"
|
|
5229
|
+
);
|
|
5211
5230
|
} catch (error) {
|
|
5212
5231
|
logger12.error(
|
|
5213
|
-
{
|
|
5232
|
+
{ subAgentId, dataComponentId, error },
|
|
5214
5233
|
"Failed to create agent-dataComponent relation"
|
|
5215
5234
|
);
|
|
5216
5235
|
}
|
|
@@ -5224,29 +5243,29 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5224
5243
|
{ agentDataComponentPromisesCount: agentDataComponentPromises.length },
|
|
5225
5244
|
"All agent-dataComponent relations updated"
|
|
5226
5245
|
);
|
|
5227
|
-
for (const
|
|
5246
|
+
for (const subAgentId of Object.keys(typedGraphDefinition.subAgents)) {
|
|
5228
5247
|
await deleteAgentArtifactComponentRelationByAgent(db)({
|
|
5229
|
-
scopes: { tenantId, projectId, graphId: finalGraphId,
|
|
5248
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, subAgentId }
|
|
5230
5249
|
});
|
|
5231
5250
|
}
|
|
5232
5251
|
const agentArtifactComponentPromises = [];
|
|
5233
|
-
for (const [
|
|
5252
|
+
for (const [subAgentId, agentData] of Object.entries(typedGraphDefinition.subAgents)) {
|
|
5234
5253
|
if (isInternalAgent(agentData) && agentData.artifactComponents) {
|
|
5235
5254
|
for (const artifactComponentId of agentData.artifactComponents) {
|
|
5236
5255
|
agentArtifactComponentPromises.push(
|
|
5237
5256
|
(async () => {
|
|
5238
5257
|
try {
|
|
5239
5258
|
await associateArtifactComponentWithAgent(db)({
|
|
5240
|
-
scopes: { tenantId, projectId, graphId: finalGraphId,
|
|
5259
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, subAgentId },
|
|
5241
5260
|
artifactComponentId
|
|
5242
5261
|
});
|
|
5243
5262
|
logger12.info(
|
|
5244
|
-
{
|
|
5263
|
+
{ subAgentId, artifactComponentId },
|
|
5245
5264
|
"Agent-artifactComponent relation created"
|
|
5246
5265
|
);
|
|
5247
5266
|
} catch (error) {
|
|
5248
5267
|
logger12.error(
|
|
5249
|
-
{
|
|
5268
|
+
{ subAgentId, artifactComponentId, error },
|
|
5250
5269
|
"Failed to create agent-artifactComponent relation"
|
|
5251
5270
|
);
|
|
5252
5271
|
}
|
|
@@ -5264,34 +5283,34 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5264
5283
|
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
5265
5284
|
});
|
|
5266
5285
|
const agentRelationPromises = [];
|
|
5267
|
-
for (const [
|
|
5286
|
+
for (const [subAgentId, agentData] of Object.entries(typedGraphDefinition.subAgents)) {
|
|
5268
5287
|
if (isInternalAgent(agentData) && agentData.canTransferTo) {
|
|
5269
|
-
for (const
|
|
5288
|
+
for (const targetSubAgentId of agentData.canTransferTo) {
|
|
5270
5289
|
agentRelationPromises.push(
|
|
5271
5290
|
(async () => {
|
|
5272
5291
|
try {
|
|
5273
|
-
const targetAgentData = typedGraphDefinition.
|
|
5292
|
+
const targetAgentData = typedGraphDefinition.subAgents[targetSubAgentId];
|
|
5274
5293
|
const isTargetExternal = isExternalAgent(targetAgentData);
|
|
5275
|
-
const targetField = isTargetExternal ? "
|
|
5294
|
+
const targetField = isTargetExternal ? "externalSubAgentId" : "targetSubAgentId";
|
|
5276
5295
|
const relationData = {
|
|
5277
5296
|
id: nanoid(),
|
|
5278
5297
|
graphId: typedGraphDefinition.id || "",
|
|
5279
|
-
|
|
5298
|
+
sourceSubAgentId: subAgentId,
|
|
5280
5299
|
relationType: "transfer",
|
|
5281
|
-
[targetField]:
|
|
5300
|
+
[targetField]: targetSubAgentId
|
|
5282
5301
|
};
|
|
5283
|
-
await
|
|
5302
|
+
await createSubAgentRelation(db)({
|
|
5284
5303
|
tenantId,
|
|
5285
5304
|
projectId,
|
|
5286
5305
|
...relationData
|
|
5287
5306
|
});
|
|
5288
5307
|
logger12.info(
|
|
5289
|
-
{
|
|
5308
|
+
{ subAgentId, targetSubAgentId, isTargetExternal },
|
|
5290
5309
|
"Transfer relation created"
|
|
5291
5310
|
);
|
|
5292
5311
|
} catch (error) {
|
|
5293
5312
|
logger12.error(
|
|
5294
|
-
{
|
|
5313
|
+
{ subAgentId, targetSubAgentId, error },
|
|
5295
5314
|
"Failed to create transfer relation"
|
|
5296
5315
|
);
|
|
5297
5316
|
}
|
|
@@ -5300,29 +5319,29 @@ var updateFullGraphServerSide = (db, logger12 = defaultLogger) => async (scopes,
|
|
|
5300
5319
|
}
|
|
5301
5320
|
}
|
|
5302
5321
|
if (isInternalAgent(agentData) && agentData.canDelegateTo) {
|
|
5303
|
-
for (const
|
|
5304
|
-
const targetAgentData = typedGraphDefinition.
|
|
5322
|
+
for (const targetSubAgentId of agentData.canDelegateTo) {
|
|
5323
|
+
const targetAgentData = typedGraphDefinition.subAgents[targetSubAgentId];
|
|
5305
5324
|
const isTargetExternal = isExternalAgent(targetAgentData);
|
|
5306
|
-
const targetField = isTargetExternal ? "
|
|
5325
|
+
const targetField = isTargetExternal ? "externalSubAgentId" : "targetSubAgentId";
|
|
5307
5326
|
agentRelationPromises.push(
|
|
5308
5327
|
(async () => {
|
|
5309
5328
|
try {
|
|
5310
5329
|
const relationData = {
|
|
5311
5330
|
id: nanoid(),
|
|
5312
5331
|
graphId: typedGraphDefinition.id || "",
|
|
5313
|
-
|
|
5332
|
+
sourceSubAgentId: subAgentId,
|
|
5314
5333
|
relationType: "delegate",
|
|
5315
|
-
[targetField]:
|
|
5334
|
+
[targetField]: targetSubAgentId
|
|
5316
5335
|
};
|
|
5317
|
-
await
|
|
5336
|
+
await createSubAgentRelation(db)({
|
|
5318
5337
|
tenantId,
|
|
5319
5338
|
projectId,
|
|
5320
5339
|
...relationData
|
|
5321
5340
|
});
|
|
5322
|
-
logger12.info({
|
|
5341
|
+
logger12.info({ subAgentId, targetSubAgentId }, "Delegation relation created");
|
|
5323
5342
|
} catch (error) {
|
|
5324
5343
|
logger12.error(
|
|
5325
|
-
{
|
|
5344
|
+
{ subAgentId, targetSubAgentId, error },
|
|
5326
5345
|
"Failed to create delegation relation"
|
|
5327
5346
|
);
|
|
5328
5347
|
}
|
|
@@ -5365,7 +5384,7 @@ var getFullGraph = (db, logger12 = defaultLogger) => async (params) => {
|
|
|
5365
5384
|
{
|
|
5366
5385
|
tenantId,
|
|
5367
5386
|
graphId: scopes.graphId,
|
|
5368
|
-
agentCount: Object.keys(graph.
|
|
5387
|
+
agentCount: Object.keys(graph.subAgents).length
|
|
5369
5388
|
},
|
|
5370
5389
|
"Full graph retrieved successfully"
|
|
5371
5390
|
);
|
|
@@ -5397,15 +5416,15 @@ var deleteFullGraph = (db, logger12 = defaultLogger) => async (params) => {
|
|
|
5397
5416
|
scopes: { tenantId, projectId, graphId }
|
|
5398
5417
|
});
|
|
5399
5418
|
logger12.info({ tenantId, graphId }, "Agent relations deleted");
|
|
5400
|
-
const
|
|
5401
|
-
if (
|
|
5402
|
-
for (const
|
|
5419
|
+
const subAgentIds = Object.keys(graph.subAgents);
|
|
5420
|
+
if (subAgentIds.length > 0) {
|
|
5421
|
+
for (const subAgentId of subAgentIds) {
|
|
5403
5422
|
await deleteAgentToolRelationByAgent(db)({
|
|
5404
|
-
scopes: { tenantId, projectId, graphId,
|
|
5423
|
+
scopes: { tenantId, projectId, graphId, subAgentId }
|
|
5405
5424
|
});
|
|
5406
5425
|
}
|
|
5407
5426
|
logger12.info(
|
|
5408
|
-
{ tenantId, graphId, agentCount:
|
|
5427
|
+
{ tenantId, graphId, agentCount: subAgentIds.length },
|
|
5409
5428
|
"Agent-tool relations deleted"
|
|
5410
5429
|
);
|
|
5411
5430
|
}
|
|
@@ -5804,15 +5823,15 @@ var listProjects = (db) => async (params) => {
|
|
|
5804
5823
|
return projectsFromTable.map((p) => ({ projectId: p.projectId }));
|
|
5805
5824
|
}
|
|
5806
5825
|
const projectIdSets = await Promise.all([
|
|
5807
|
-
db.selectDistinct({ projectId:
|
|
5826
|
+
db.selectDistinct({ projectId: subAgents.projectId }).from(subAgents).where(eq(subAgents.tenantId, params.tenantId)),
|
|
5808
5827
|
db.selectDistinct({ projectId: agentGraph.projectId }).from(agentGraph).where(eq(agentGraph.tenantId, params.tenantId)),
|
|
5809
5828
|
db.selectDistinct({ projectId: tools.projectId }).from(tools).where(eq(tools.tenantId, params.tenantId)),
|
|
5810
5829
|
db.selectDistinct({ projectId: contextConfigs.projectId }).from(contextConfigs).where(eq(contextConfigs.tenantId, params.tenantId)),
|
|
5811
5830
|
db.selectDistinct({ projectId: externalAgents.projectId }).from(externalAgents).where(eq(externalAgents.tenantId, params.tenantId)),
|
|
5812
|
-
db.selectDistinct({ projectId:
|
|
5813
|
-
db.selectDistinct({ projectId:
|
|
5814
|
-
db.selectDistinct({ projectId:
|
|
5815
|
-
db.selectDistinct({ projectId:
|
|
5831
|
+
db.selectDistinct({ projectId: subAgentRelations.projectId }).from(subAgentRelations).where(eq(subAgentRelations.tenantId, params.tenantId)),
|
|
5832
|
+
db.selectDistinct({ projectId: subAgentToolRelations.projectId }).from(subAgentToolRelations).where(eq(subAgentToolRelations.tenantId, params.tenantId)),
|
|
5833
|
+
db.selectDistinct({ projectId: subAgentDataComponents.projectId }).from(subAgentDataComponents).where(eq(subAgentDataComponents.tenantId, params.tenantId)),
|
|
5834
|
+
db.selectDistinct({ projectId: subAgentArtifactComponents.projectId }).from(subAgentArtifactComponents).where(eq(subAgentArtifactComponents.tenantId, params.tenantId)),
|
|
5816
5835
|
db.selectDistinct({ projectId: dataComponents.projectId }).from(dataComponents).where(eq(dataComponents.tenantId, params.tenantId)),
|
|
5817
5836
|
db.selectDistinct({ projectId: artifactComponents.projectId }).from(artifactComponents).where(eq(artifactComponents.tenantId, params.tenantId)),
|
|
5818
5837
|
db.selectDistinct({ projectId: tasks.projectId }).from(tasks).where(eq(tasks.tenantId, params.tenantId)),
|
|
@@ -5852,7 +5871,7 @@ var listProjectsPaginated = (db) => async (params) => {
|
|
|
5852
5871
|
var getProjectResourceCounts = (db) => async (params) => {
|
|
5853
5872
|
const whereClause = (table) => and(eq(table.tenantId, params.tenantId), eq(table.projectId, params.projectId));
|
|
5854
5873
|
const [agentResults, graphResults, toolResults, contextConfigResults, externalAgentResults] = await Promise.all([
|
|
5855
|
-
db.select({ count:
|
|
5874
|
+
db.select({ count: subAgents.id }).from(subAgents).where(whereClause(subAgents)),
|
|
5856
5875
|
db.select({ count: agentGraph.id }).from(agentGraph).where(whereClause(agentGraph)),
|
|
5857
5876
|
db.select({ count: tools.id }).from(tools).where(whereClause(tools)),
|
|
5858
5877
|
db.select({ count: contextConfigs.id }).from(contextConfigs).where(whereClause(contextConfigs)),
|
|
@@ -5869,7 +5888,7 @@ var getProjectResourceCounts = (db) => async (params) => {
|
|
|
5869
5888
|
var projectExists = (db) => async (params) => {
|
|
5870
5889
|
const whereClause = (table) => and(eq(table.tenantId, params.tenantId), eq(table.projectId, params.projectId));
|
|
5871
5890
|
const checks = [
|
|
5872
|
-
db.select({ id:
|
|
5891
|
+
db.select({ id: subAgents.id }).from(subAgents).where(whereClause(subAgents)).limit(1),
|
|
5873
5892
|
db.select({ id: agentGraph.id }).from(agentGraph).where(whereClause(agentGraph)).limit(1),
|
|
5874
5893
|
db.select({ id: tools.id }).from(tools).where(whereClause(tools)).limit(1),
|
|
5875
5894
|
db.select({ id: contextConfigs.id }).from(contextConfigs).where(whereClause(contextConfigs)).limit(1),
|
|
@@ -5976,8 +5995,8 @@ async function cascadeStopWhenUpdates(db, scopes, oldStopWhen, newStopWhen) {
|
|
|
5976
5995
|
}
|
|
5977
5996
|
}
|
|
5978
5997
|
if (oldStopWhen?.stepCountIs !== newStopWhen?.stepCountIs) {
|
|
5979
|
-
const agentsToUpdate = await db.query.
|
|
5980
|
-
where: and(eq(
|
|
5998
|
+
const agentsToUpdate = await db.query.subAgents.findMany({
|
|
5999
|
+
where: and(eq(subAgents.tenantId, tenantId), eq(subAgents.projectId, projectId))
|
|
5981
6000
|
});
|
|
5982
6001
|
for (const agent of agentsToUpdate) {
|
|
5983
6002
|
const agentStopWhen = agent.stopWhen;
|
|
@@ -5986,14 +6005,14 @@ async function cascadeStopWhenUpdates(db, scopes, oldStopWhen, newStopWhen) {
|
|
|
5986
6005
|
...agentStopWhen || {},
|
|
5987
6006
|
stepCountIs: newStopWhen?.stepCountIs
|
|
5988
6007
|
};
|
|
5989
|
-
await db.update(
|
|
6008
|
+
await db.update(subAgents).set({
|
|
5990
6009
|
stopWhen: updatedStopWhen,
|
|
5991
6010
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5992
6011
|
}).where(
|
|
5993
6012
|
and(
|
|
5994
|
-
eq(
|
|
5995
|
-
eq(
|
|
5996
|
-
eq(
|
|
6013
|
+
eq(subAgents.tenantId, tenantId),
|
|
6014
|
+
eq(subAgents.projectId, projectId),
|
|
6015
|
+
eq(subAgents.id, agent.id)
|
|
5997
6016
|
)
|
|
5998
6017
|
);
|
|
5999
6018
|
}
|
|
@@ -6245,6 +6264,10 @@ var createFullProjectServerSide = (db, logger12 = defaultLogger2) => async (scop
|
|
|
6245
6264
|
logger12.info({ projectId: typed.id, graphId }, "Creating graph in project");
|
|
6246
6265
|
const graphDataWithProjectResources = {
|
|
6247
6266
|
...graphData,
|
|
6267
|
+
agents: void 0,
|
|
6268
|
+
// Remove 'agents' property from GraphWithinContextOfProjectSchema
|
|
6269
|
+
subAgents: graphData.subAgents,
|
|
6270
|
+
// Map 'agents' to 'subAgents' for FullGraphDefinitionSchema
|
|
6248
6271
|
tools: typed.tools || {},
|
|
6249
6272
|
// Pass project-level resources for validation
|
|
6250
6273
|
dataComponents: typed.dataComponents || {},
|
|
@@ -6584,6 +6607,10 @@ var updateFullProjectServerSide = (db, logger12 = defaultLogger2) => async (scop
|
|
|
6584
6607
|
logger12.info({ projectId: typed.id, graphId }, "Updating graph in project");
|
|
6585
6608
|
const graphDataWithProjectResources = {
|
|
6586
6609
|
...graphData,
|
|
6610
|
+
agents: void 0,
|
|
6611
|
+
// Remove 'agents' property from GraphWithinContextOfProjectSchema
|
|
6612
|
+
subAgents: graphData.subAgents,
|
|
6613
|
+
// Map 'agents' to 'subAgents' for FullGraphDefinitionSchema
|
|
6587
6614
|
tools: typed.tools || {},
|
|
6588
6615
|
// Pass project-level resources for validation
|
|
6589
6616
|
dataComponents: typed.dataComponents || {},
|
|
@@ -7687,7 +7714,7 @@ async function validateHeaders({
|
|
|
7687
7714
|
credentialStores
|
|
7688
7715
|
}) {
|
|
7689
7716
|
try {
|
|
7690
|
-
const agentGraph2 = await
|
|
7717
|
+
const agentGraph2 = await getAgentGraphWithDefaultSubAgent(dbClient)({
|
|
7691
7718
|
scopes: { tenantId, projectId, graphId }
|
|
7692
7719
|
});
|
|
7693
7720
|
if (!agentGraph2?.contextConfigId) {
|
|
@@ -8250,7 +8277,7 @@ async function handleContextResolution({
|
|
|
8250
8277
|
let agentGraph2;
|
|
8251
8278
|
let trigger;
|
|
8252
8279
|
try {
|
|
8253
|
-
agentGraph2 = await
|
|
8280
|
+
agentGraph2 = await getAgentGraphWithDefaultSubAgent(dbClient)({
|
|
8254
8281
|
scopes: { tenantId, projectId, graphId }
|
|
8255
8282
|
});
|
|
8256
8283
|
if (!agentGraph2?.contextConfigId) {
|
|
@@ -9179,4 +9206,4 @@ ${error.message}`
|
|
|
9179
9206
|
};
|
|
9180
9207
|
parseEnv();
|
|
9181
9208
|
|
|
9182
|
-
export { ContextCache, ContextConfigBuilder, ContextFetcher, ContextResolver, CredentialStoreRegistry, CredentialStuffer, ERROR_DOCS_BASE_URL, ErrorCode, HTTP_REQUEST_PARTS, InMemoryCredentialStore, KeyChainStore, McpClient, NangoCredentialStore, TemplateEngine, addLedgerArtifacts, addToolToAgent, apiFetch, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects,
|
|
9209
|
+
export { ContextCache, ContextConfigBuilder, ContextFetcher, ContextResolver, CredentialStoreRegistry, CredentialStuffer, ERROR_DOCS_BASE_URL, ErrorCode, HTTP_REQUEST_PARTS, InMemoryCredentialStore, KeyChainStore, McpClient, NangoCredentialStore, TemplateEngine, addLedgerArtifacts, addToolToAgent, apiFetch, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgentGraph, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createKeyChainStore, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createSubAgent, createSubAgentRelation, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteFunction, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteSubAgent, deleteSubAgentRelation, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, generateId, getActiveAgentForConversation, getAgentGraphById, getAgentGraphWithDefaultSubAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getConversation, getConversationCacheEntries, getConversationHistory, getConversationId, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getFunction, getGraphAgentInfos, getLedgerArtifacts, getLedgerArtifactsByContext, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getSubAgentById, getSubAgentsByIds, getTask, getToolById, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, headers, invalidateHeadersCache, invalidateInvocationDefinitionsCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listFunctions, listMessages, listProjects, listProjectsPaginated, listSubAgents, listSubAgentsPaginated, listTaskIdsByContextId, listTools, loadEnvironmentFiles, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateSubAgent, updateTask, updateTool, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertFunction, upsertLedgerArtifact, upsertSubAgent, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHeaders, validateHttpRequestHeaders, validateInternalSubAgent, validateProjectExists, validationHelper, withProjectValidation };
|