@inkeep/agents-core 0.58.13 → 0.58.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/auth-schema.d.ts +107 -107
- package/dist/auth/auth-validation-schemas.d.ts +152 -152
- package/dist/auth/auth.d.ts +9 -9
- package/dist/auth/auth.js +17 -45
- package/dist/auth/permissions.d.ts +9 -9
- package/dist/data-access/index.d.ts +6 -1
- package/dist/data-access/index.js +6 -1
- package/dist/data-access/manage/agentFull.js +28 -12
- package/dist/data-access/manage/agents.d.ts +40 -39
- package/dist/data-access/manage/agents.js +33 -33
- package/dist/data-access/manage/artifactComponents.d.ts +8 -8
- package/dist/data-access/manage/artifactComponents.js +14 -13
- package/dist/data-access/manage/audit-queries.d.ts +29 -0
- package/dist/data-access/manage/audit-queries.js +30 -0
- package/dist/data-access/manage/contextConfigs.d.ts +4 -4
- package/dist/data-access/manage/contextConfigs.js +7 -6
- package/dist/data-access/manage/credentialReferences.js +12 -11
- package/dist/data-access/manage/dataComponents.d.ts +4 -4
- package/dist/data-access/manage/dataComponents.js +13 -11
- package/dist/data-access/manage/evalConfig.js +42 -41
- package/dist/data-access/manage/externalAgents.js +8 -7
- package/dist/data-access/manage/functionTools.d.ts +11 -15
- package/dist/data-access/manage/functionTools.js +27 -65
- package/dist/data-access/manage/functions.js +7 -10
- package/dist/data-access/manage/projects.js +37 -36
- package/dist/data-access/manage/scheduledTriggers.js +10 -6
- package/dist/data-access/manage/scheduledWorkflows.js +3 -2
- package/dist/data-access/manage/scope-helpers.d.ts +2 -1
- package/dist/data-access/manage/scope-helpers.js +2 -1
- package/dist/data-access/manage/skills.d.ts +11 -11
- package/dist/data-access/manage/skills.js +14 -9
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +12 -12
- package/dist/data-access/manage/subAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgentRelations.js +28 -26
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +12 -12
- package/dist/data-access/manage/subAgentTeamAgentRelations.js +16 -16
- package/dist/data-access/manage/subAgents.d.ts +21 -21
- package/dist/data-access/manage/subAgents.js +8 -7
- package/dist/data-access/manage/tools.d.ts +15 -15
- package/dist/data-access/manage/tools.js +8 -6
- package/dist/data-access/manage/triggers.d.ts +2 -2
- package/dist/data-access/manage/triggers.js +12 -8
- package/dist/data-access/runtime/apiKeys.d.ts +16 -16
- package/dist/data-access/runtime/apiKeys.js +16 -12
- package/dist/data-access/runtime/apps.d.ts +6 -6
- package/dist/data-access/runtime/apps.js +8 -7
- package/dist/data-access/runtime/audit-queries.d.ts +41 -0
- package/dist/data-access/runtime/audit-queries.js +37 -0
- package/dist/data-access/runtime/auth.d.ts +18 -0
- package/dist/data-access/runtime/auth.js +35 -0
- package/dist/data-access/runtime/cascade-delete.js +29 -24
- package/dist/data-access/runtime/contextCache.d.ts +1 -0
- package/dist/data-access/runtime/contextCache.js +9 -8
- package/dist/data-access/runtime/conversations.d.ts +16 -16
- package/dist/data-access/runtime/conversations.js +8 -12
- package/dist/data-access/runtime/evalRuns.js +23 -22
- package/dist/data-access/runtime/github-work-app-installations.js +32 -21
- package/dist/data-access/runtime/ledgerArtifacts.js +9 -24
- package/dist/data-access/runtime/messages.d.ts +21 -21
- package/dist/data-access/runtime/messages.js +9 -8
- package/dist/data-access/runtime/projects.js +6 -5
- package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +3 -3
- package/dist/data-access/runtime/scheduledTriggerInvocations.js +16 -26
- package/dist/data-access/runtime/slack-work-app-mcp.js +6 -5
- package/dist/data-access/runtime/tasks.d.ts +9 -5
- package/dist/data-access/runtime/tasks.js +4 -5
- package/dist/data-access/runtime/triggerInvocations.js +4 -8
- package/dist/data-access/runtime/workAppSlack.js +21 -14
- package/dist/data-reconciliation/audit.d.ts +6 -0
- package/dist/data-reconciliation/audit.js +37 -0
- package/dist/data-reconciliation/index.d.ts +4 -0
- package/dist/data-reconciliation/index.js +5 -0
- package/dist/data-reconciliation/reconcile.d.ts +6 -0
- package/dist/data-reconciliation/reconcile.js +58 -0
- package/dist/data-reconciliation/types.d.ts +116 -0
- package/dist/data-reconciliation/types.js +7 -0
- package/dist/db/manage/manage-schema.d.ts +453 -453
- package/dist/db/runtime/runtime-schema.d.ts +326 -326
- package/dist/index.d.ts +12 -2
- package/dist/index.js +12 -1
- package/dist/retry/index.d.ts +3 -0
- package/dist/retry/index.js +4 -0
- package/dist/retry/retryable-errors.d.ts +10 -0
- package/dist/retry/retryable-errors.js +72 -0
- package/dist/retry/withRetry.d.ts +15 -0
- package/dist/retry/withRetry.js +37 -0
- package/dist/setup/setup.d.ts +1 -0
- package/dist/setup/setup.js +25 -8
- package/dist/utils/error.d.ts +51 -51
- package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
- package/dist/validation/schemas.d.ts +1987 -1990
- package/dist/validation/schemas.js +5 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { scheduledWorkflows } from "../../db/manage/manage-schema.js";
|
|
2
|
+
import { agentScopedWhere } from "./scope-helpers.js";
|
|
2
3
|
import { and, eq } from "drizzle-orm";
|
|
3
4
|
|
|
4
5
|
//#region src/data-access/manage/scheduledWorkflows.ts
|
|
@@ -7,7 +8,7 @@ import { and, eq } from "drizzle-orm";
|
|
|
7
8
|
*/
|
|
8
9
|
const getScheduledWorkflowByTriggerId = (db) => async (params) => {
|
|
9
10
|
const { scopes, scheduledTriggerId } = params;
|
|
10
|
-
return await db.query.scheduledWorkflows.findFirst({ where: and(
|
|
11
|
+
return await db.query.scheduledWorkflows.findFirst({ where: and(agentScopedWhere(scheduledWorkflows, scopes), eq(scheduledWorkflows.scheduledTriggerId, scheduledTriggerId)) });
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
14
|
* Create a new scheduled workflow (agent-scoped)
|
|
@@ -25,7 +26,7 @@ const updateScheduledWorkflowRunId = (db) => async (params) => {
|
|
|
25
26
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
26
27
|
};
|
|
27
28
|
if (params.status) updateData.status = params.status;
|
|
28
|
-
return (await db.update(scheduledWorkflows).set(updateData).where(and(
|
|
29
|
+
return (await db.update(scheduledWorkflows).set(updateData).where(and(agentScopedWhere(scheduledWorkflows, params.scopes), eq(scheduledWorkflows.id, params.scheduledWorkflowId))).returning())[0];
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
//#endregion
|
|
@@ -14,5 +14,6 @@ declare const tenantScopedWhere: <T extends ScopedTable<"tenant">>(table: T, sco
|
|
|
14
14
|
declare const projectScopedWhere: <T extends ScopedTable<"project">>(table: T, scopes: ScopeConfig<"project">) => SQL<unknown> | undefined;
|
|
15
15
|
declare const agentScopedWhere: <T extends ScopedTable<"agent">>(table: T, scopes: ScopeConfig<"agent">) => SQL<unknown> | undefined;
|
|
16
16
|
declare const subAgentScopedWhere: <T extends ScopedTable<"subAgent">>(table: T, scopes: ScopeConfig<"subAgent">) => SQL<unknown> | undefined;
|
|
17
|
+
declare const toolScopedWhere: <T extends ScopedTable<"tool">>(table: T, scopes: ScopeConfig<"tool">) => SQL<unknown> | undefined;
|
|
17
18
|
//#endregion
|
|
18
|
-
export { agentScopedWhere, projectScopedWhere, scopedWhere, subAgentScopedWhere, tenantScopedWhere };
|
|
19
|
+
export { agentScopedWhere, projectScopedWhere, scopedWhere, subAgentScopedWhere, tenantScopedWhere, toolScopedWhere };
|
|
@@ -16,6 +16,7 @@ const tenantScopedWhere = (table, scopes) => scopedWhere("tenant", table, scopes
|
|
|
16
16
|
const projectScopedWhere = (table, scopes) => scopedWhere("project", table, scopes);
|
|
17
17
|
const agentScopedWhere = (table, scopes) => scopedWhere("agent", table, scopes);
|
|
18
18
|
const subAgentScopedWhere = (table, scopes) => scopedWhere("subAgent", table, scopes);
|
|
19
|
+
const toolScopedWhere = (table, scopes) => scopedWhere("tool", table, scopes);
|
|
19
20
|
|
|
20
21
|
//#endregion
|
|
21
|
-
export { agentScopedWhere, projectScopedWhere, scopedWhere, subAgentScopedWhere, tenantScopedWhere };
|
|
22
|
+
export { agentScopedWhere, projectScopedWhere, scopedWhere, subAgentScopedWhere, tenantScopedWhere, toolScopedWhere };
|
|
@@ -8,14 +8,14 @@ declare const getSkillById: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
8
8
|
scopes: ProjectScopeConfig;
|
|
9
9
|
skillId: string;
|
|
10
10
|
}) => Promise<{
|
|
11
|
+
tenantId: string;
|
|
12
|
+
projectId: string;
|
|
11
13
|
id: string;
|
|
12
14
|
name: string;
|
|
13
15
|
description: string;
|
|
14
|
-
|
|
15
|
-
projectId: string;
|
|
16
|
+
metadata: Record<string, string> | null;
|
|
16
17
|
createdAt: string;
|
|
17
18
|
updatedAt: string;
|
|
18
|
-
metadata: Record<string, string> | null;
|
|
19
19
|
content: string;
|
|
20
20
|
} | null>;
|
|
21
21
|
declare const listSkills: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -41,25 +41,25 @@ declare const listSkills: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
41
41
|
};
|
|
42
42
|
}>;
|
|
43
43
|
declare const createSkill: (db: AgentsManageDatabaseClient) => (data: SkillInsert) => Promise<{
|
|
44
|
+
tenantId: string;
|
|
45
|
+
projectId: string;
|
|
44
46
|
id: string;
|
|
45
47
|
name: string;
|
|
46
48
|
description: string;
|
|
47
|
-
|
|
48
|
-
projectId: string;
|
|
49
|
+
metadata: Record<string, string> | null;
|
|
49
50
|
createdAt: string;
|
|
50
51
|
updatedAt: string;
|
|
51
|
-
metadata: Record<string, string> | null;
|
|
52
52
|
content: string;
|
|
53
53
|
}>;
|
|
54
54
|
declare const upsertSkill: (db: AgentsManageDatabaseClient) => (data: SkillInsert) => Promise<{
|
|
55
|
+
tenantId: string;
|
|
56
|
+
projectId: string;
|
|
55
57
|
id: string;
|
|
56
58
|
name: string;
|
|
57
59
|
description: string;
|
|
58
|
-
|
|
59
|
-
projectId: string;
|
|
60
|
+
metadata: Record<string, string> | null;
|
|
60
61
|
createdAt: string;
|
|
61
62
|
updatedAt: string;
|
|
62
|
-
metadata: Record<string, string> | null;
|
|
63
63
|
content: string;
|
|
64
64
|
}>;
|
|
65
65
|
declare const updateSkill: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -91,15 +91,15 @@ declare const upsertSubAgentSkill: (db: AgentsManageDatabaseClient) => (params:
|
|
|
91
91
|
index: number;
|
|
92
92
|
alwaysLoaded?: boolean;
|
|
93
93
|
}) => Promise<{
|
|
94
|
-
id: string;
|
|
95
94
|
tenantId: string;
|
|
96
95
|
projectId: string;
|
|
97
96
|
agentId: string;
|
|
97
|
+
subAgentId: string;
|
|
98
|
+
id: string;
|
|
98
99
|
createdAt: string;
|
|
99
100
|
updatedAt: string;
|
|
100
101
|
index: number;
|
|
101
102
|
alwaysLoaded: boolean;
|
|
102
|
-
subAgentId: string;
|
|
103
103
|
skillId: string;
|
|
104
104
|
}>;
|
|
105
105
|
declare const deleteSubAgentSkill: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { skills, subAgentSkills } from "../../db/manage/manage-schema.js";
|
|
2
2
|
import { getLogger } from "../../utils/logger.js";
|
|
3
3
|
import { generateId } from "../../utils/conversations.js";
|
|
4
|
+
import { agentScopedWhere, projectScopedWhere, subAgentScopedWhere } from "./scope-helpers.js";
|
|
4
5
|
import "../../index.js";
|
|
5
6
|
import { and, asc, count, desc, eq, inArray } from "drizzle-orm";
|
|
6
7
|
|
|
7
8
|
//#region src/data-access/manage/skills.ts
|
|
8
9
|
const logger = getLogger("skills-dal");
|
|
9
10
|
const getSkillById = (db) => async (params) => {
|
|
10
|
-
return await db.query.skills.findFirst({ where: and(
|
|
11
|
+
return await db.query.skills.findFirst({ where: and(projectScopedWhere(skills, params.scopes), eq(skills.id, params.skillId)) }) ?? null;
|
|
11
12
|
};
|
|
12
13
|
const listSkills = (db) => async (params) => {
|
|
13
14
|
const page = params.pagination?.page || 1;
|
|
14
15
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
15
16
|
const offset = (page - 1) * limit;
|
|
16
|
-
const whereClause =
|
|
17
|
+
const whereClause = projectScopedWhere(skills, params.scopes);
|
|
17
18
|
const [data, totalResult] = await Promise.all([db.select().from(skills).where(whereClause).limit(limit).offset(offset).orderBy(desc(skills.createdAt)), db.select({ count: count() }).from(skills).where(whereClause)]);
|
|
18
19
|
const total = totalResult[0]?.count || 0;
|
|
19
20
|
return {
|
|
@@ -43,14 +44,18 @@ const upsertSkill = (db) => async (data) => {
|
|
|
43
44
|
...data,
|
|
44
45
|
id: data.name
|
|
45
46
|
};
|
|
46
|
-
|
|
47
|
+
const scopes = {
|
|
48
|
+
tenantId: baseData.tenantId,
|
|
49
|
+
projectId: baseData.projectId
|
|
50
|
+
};
|
|
51
|
+
if (await db.query.skills.findFirst({ where: and(projectScopedWhere(skills, scopes), eq(skills.id, baseData.id)) })) {
|
|
47
52
|
const [result$1] = await db.update(skills).set({
|
|
48
53
|
name: baseData.name,
|
|
49
54
|
description: baseData.description,
|
|
50
55
|
content: baseData.content,
|
|
51
56
|
metadata: baseData.metadata,
|
|
52
57
|
updatedAt: now
|
|
53
|
-
}).where(and(
|
|
58
|
+
}).where(and(projectScopedWhere(skills, scopes), eq(skills.id, baseData.id))).returning();
|
|
54
59
|
logger.info({ skillId: baseData.id }, "Updated skill");
|
|
55
60
|
return result$1;
|
|
56
61
|
}
|
|
@@ -69,11 +74,11 @@ const updateSkill = (db) => async (params) => {
|
|
|
69
74
|
...data,
|
|
70
75
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
71
76
|
};
|
|
72
|
-
const [result] = await db.update(skills).set(updateData).where(and(
|
|
77
|
+
const [result] = await db.update(skills).set(updateData).where(and(projectScopedWhere(skills, params.scopes), eq(skills.id, params.skillId))).returning();
|
|
73
78
|
return result ?? null;
|
|
74
79
|
};
|
|
75
80
|
const deleteSkill = (db) => async (params) => {
|
|
76
|
-
return (await db.delete(skills).where(and(
|
|
81
|
+
return (await db.delete(skills).where(and(projectScopedWhere(skills, params.scopes), eq(skills.id, params.skillId))).returning()).length > 0;
|
|
77
82
|
};
|
|
78
83
|
const getSkillsForSubAgents = (db) => async (params) => {
|
|
79
84
|
if (!params.subAgentIds.length) return [];
|
|
@@ -89,11 +94,11 @@ const getSkillsForSubAgents = (db) => async (params) => {
|
|
|
89
94
|
metadata: skills.metadata,
|
|
90
95
|
createdAt: skills.createdAt,
|
|
91
96
|
updatedAt: skills.updatedAt
|
|
92
|
-
}).from(subAgentSkills).innerJoin(skills, and(eq(subAgentSkills.skillId, skills.id), eq(subAgentSkills.tenantId, skills.tenantId), eq(subAgentSkills.projectId, skills.projectId))).where(and(
|
|
97
|
+
}).from(subAgentSkills).innerJoin(skills, and(eq(subAgentSkills.skillId, skills.id), eq(subAgentSkills.tenantId, skills.tenantId), eq(subAgentSkills.projectId, skills.projectId))).where(and(agentScopedWhere(subAgentSkills, params.scopes), inArray(subAgentSkills.subAgentId, params.subAgentIds))).orderBy(asc(subAgentSkills.index), asc(subAgentSkills.createdAt));
|
|
93
98
|
};
|
|
94
99
|
const upsertSubAgentSkill = (db) => async (params) => {
|
|
95
100
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
96
|
-
const existing = await db.query.subAgentSkills.findFirst({ where: and(
|
|
101
|
+
const existing = await db.query.subAgentSkills.findFirst({ where: and(subAgentScopedWhere(subAgentSkills, params.scopes), eq(subAgentSkills.skillId, params.skillId)) });
|
|
97
102
|
if (existing) {
|
|
98
103
|
const [result$1] = await db.update(subAgentSkills).set({
|
|
99
104
|
index: params.index,
|
|
@@ -115,7 +120,7 @@ const upsertSubAgentSkill = (db) => async (params) => {
|
|
|
115
120
|
return result;
|
|
116
121
|
};
|
|
117
122
|
const deleteSubAgentSkill = (db) => async (params) => {
|
|
118
|
-
return (await db.delete(subAgentSkills).where(and(
|
|
123
|
+
return (await db.delete(subAgentSkills).where(and(agentScopedWhere(subAgentSkills, params.scopes), eq(subAgentSkills.id, params.subAgentSkillId))).returning()).length > 0;
|
|
119
124
|
};
|
|
120
125
|
|
|
121
126
|
//#endregion
|
|
@@ -9,15 +9,15 @@ declare const getSubAgentExternalAgentRelationById: (db: AgentsManageDatabaseCli
|
|
|
9
9
|
scopes: SubAgentScopeConfig;
|
|
10
10
|
relationId: string;
|
|
11
11
|
}) => Promise<{
|
|
12
|
-
id: string;
|
|
13
12
|
tenantId: string;
|
|
14
13
|
projectId: string;
|
|
15
14
|
agentId: string;
|
|
15
|
+
subAgentId: string;
|
|
16
|
+
id: string;
|
|
16
17
|
createdAt: string;
|
|
17
18
|
updatedAt: string;
|
|
18
19
|
headers: Record<string, string> | null;
|
|
19
20
|
externalAgentId: string;
|
|
20
|
-
subAgentId: string;
|
|
21
21
|
} | undefined>;
|
|
22
22
|
declare const listSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
|
|
23
23
|
scopes: SubAgentScopeConfig;
|
|
@@ -44,28 +44,28 @@ declare const listSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClien
|
|
|
44
44
|
declare const getSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
|
|
45
45
|
scopes: SubAgentScopeConfig;
|
|
46
46
|
}) => Promise<{
|
|
47
|
-
id: string;
|
|
48
47
|
tenantId: string;
|
|
49
48
|
projectId: string;
|
|
50
49
|
agentId: string;
|
|
50
|
+
subAgentId: string;
|
|
51
|
+
id: string;
|
|
51
52
|
createdAt: string;
|
|
52
53
|
updatedAt: string;
|
|
53
54
|
headers: Record<string, string> | null;
|
|
54
55
|
externalAgentId: string;
|
|
55
|
-
subAgentId: string;
|
|
56
56
|
}[]>;
|
|
57
57
|
declare const getSubAgentExternalAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
58
58
|
scopes: AgentScopeConfig;
|
|
59
59
|
}) => Promise<{
|
|
60
|
-
id: string;
|
|
61
60
|
tenantId: string;
|
|
62
61
|
projectId: string;
|
|
63
62
|
agentId: string;
|
|
63
|
+
subAgentId: string;
|
|
64
|
+
id: string;
|
|
64
65
|
createdAt: string;
|
|
65
66
|
updatedAt: string;
|
|
66
67
|
headers: Record<string, string> | null;
|
|
67
68
|
externalAgentId: string;
|
|
68
|
-
subAgentId: string;
|
|
69
69
|
}[]>;
|
|
70
70
|
declare const getSubAgentExternalAgentRelationsByExternalAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
71
71
|
scopes: AgentScopeConfig;
|
|
@@ -180,15 +180,15 @@ declare const createSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClie
|
|
|
180
180
|
headers?: Record<string, string> | null;
|
|
181
181
|
};
|
|
182
182
|
}) => Promise<{
|
|
183
|
-
id: string;
|
|
184
183
|
tenantId: string;
|
|
185
184
|
projectId: string;
|
|
186
185
|
agentId: string;
|
|
186
|
+
subAgentId: string;
|
|
187
|
+
id: string;
|
|
187
188
|
createdAt: string;
|
|
188
189
|
updatedAt: string;
|
|
189
190
|
headers: Record<string, string> | null;
|
|
190
191
|
externalAgentId: string;
|
|
191
|
-
subAgentId: string;
|
|
192
192
|
}>;
|
|
193
193
|
/**
|
|
194
194
|
* Check if sub-agent external agent relation exists by params
|
|
@@ -197,15 +197,15 @@ declare const getSubAgentExternalAgentRelationByParams: (db: AgentsManageDatabas
|
|
|
197
197
|
scopes: SubAgentScopeConfig;
|
|
198
198
|
externalAgentId: string;
|
|
199
199
|
}) => Promise<{
|
|
200
|
-
id: string;
|
|
201
200
|
tenantId: string;
|
|
202
201
|
projectId: string;
|
|
203
202
|
agentId: string;
|
|
203
|
+
subAgentId: string;
|
|
204
|
+
id: string;
|
|
204
205
|
createdAt: string;
|
|
205
206
|
updatedAt: string;
|
|
206
207
|
headers: Record<string, string> | null;
|
|
207
208
|
externalAgentId: string;
|
|
208
|
-
subAgentId: string;
|
|
209
209
|
} | undefined>;
|
|
210
210
|
/**
|
|
211
211
|
* Upsert sub-agent external agent relation (create if it doesn't exist, update if it does)
|
|
@@ -218,15 +218,15 @@ declare const upsertSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClie
|
|
|
218
218
|
headers?: Record<string, string> | null;
|
|
219
219
|
};
|
|
220
220
|
}) => Promise<{
|
|
221
|
-
id: string;
|
|
222
221
|
tenantId: string;
|
|
223
222
|
projectId: string;
|
|
224
223
|
agentId: string;
|
|
224
|
+
subAgentId: string;
|
|
225
|
+
id: string;
|
|
225
226
|
createdAt: string;
|
|
226
227
|
updatedAt: string;
|
|
227
228
|
headers: Record<string, string> | null;
|
|
228
229
|
externalAgentId: string;
|
|
229
|
-
subAgentId: string;
|
|
230
230
|
}>;
|
|
231
231
|
declare const updateSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClient) => (params: {
|
|
232
232
|
scopes: SubAgentScopeConfig;
|
|
@@ -9,15 +9,15 @@ declare const getAgentRelationById: (db: AgentsManageDatabaseClient) => (params:
|
|
|
9
9
|
scopes: AgentScopeConfig;
|
|
10
10
|
relationId: string;
|
|
11
11
|
}) => Promise<{
|
|
12
|
-
id: string;
|
|
13
12
|
tenantId: string;
|
|
14
13
|
projectId: string;
|
|
15
14
|
agentId: string;
|
|
15
|
+
id: string;
|
|
16
16
|
createdAt: string;
|
|
17
17
|
updatedAt: string;
|
|
18
|
+
relationType: string | null;
|
|
18
19
|
sourceSubAgentId: string;
|
|
19
20
|
targetSubAgentId: string | null;
|
|
20
|
-
relationType: string | null;
|
|
21
21
|
} | undefined>;
|
|
22
22
|
declare const listAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
|
|
23
23
|
scopes: AgentScopeConfig;
|
|
@@ -44,28 +44,28 @@ declare const listAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
44
44
|
declare const getAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
|
|
45
45
|
scopes: SubAgentScopeConfig;
|
|
46
46
|
}) => Promise<{
|
|
47
|
-
id: string;
|
|
48
47
|
tenantId: string;
|
|
49
48
|
projectId: string;
|
|
50
49
|
agentId: string;
|
|
50
|
+
id: string;
|
|
51
51
|
createdAt: string;
|
|
52
52
|
updatedAt: string;
|
|
53
|
+
relationType: string | null;
|
|
53
54
|
sourceSubAgentId: string;
|
|
54
55
|
targetSubAgentId: string | null;
|
|
55
|
-
relationType: string | null;
|
|
56
56
|
}[]>;
|
|
57
57
|
declare const getAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
58
58
|
scopes: AgentScopeConfig;
|
|
59
59
|
}) => Promise<{
|
|
60
|
-
id: string;
|
|
61
60
|
tenantId: string;
|
|
62
61
|
projectId: string;
|
|
63
62
|
agentId: string;
|
|
63
|
+
id: string;
|
|
64
64
|
createdAt: string;
|
|
65
65
|
updatedAt: string;
|
|
66
|
+
relationType: string | null;
|
|
66
67
|
sourceSubAgentId: string;
|
|
67
68
|
targetSubAgentId: string | null;
|
|
68
|
-
relationType: string | null;
|
|
69
69
|
}[]>;
|
|
70
70
|
declare const getAgentRelationsBySource: (db: AgentsManageDatabaseClient) => (params: {
|
|
71
71
|
scopes: AgentScopeConfig;
|
|
@@ -126,15 +126,15 @@ declare const getRelatedAgentsForAgent: (db: AgentsManageDatabaseClient) => (par
|
|
|
126
126
|
}[];
|
|
127
127
|
}>;
|
|
128
128
|
declare const createSubAgentRelation: (db: AgentsManageDatabaseClient) => (params: SubAgentRelationInsert) => Promise<{
|
|
129
|
-
id: string;
|
|
130
129
|
tenantId: string;
|
|
131
130
|
projectId: string;
|
|
132
131
|
agentId: string;
|
|
132
|
+
id: string;
|
|
133
133
|
createdAt: string;
|
|
134
134
|
updatedAt: string;
|
|
135
|
+
relationType: string | null;
|
|
135
136
|
sourceSubAgentId: string;
|
|
136
137
|
targetSubAgentId: string | null;
|
|
137
|
-
relationType: string | null;
|
|
138
138
|
}>;
|
|
139
139
|
/**
|
|
140
140
|
* Check if sub-agent relation exists by agent, source, target, and relation type
|
|
@@ -145,29 +145,29 @@ declare const getAgentRelationByParams: (db: AgentsManageDatabaseClient) => (par
|
|
|
145
145
|
targetSubAgentId?: string;
|
|
146
146
|
relationType: string;
|
|
147
147
|
}) => Promise<{
|
|
148
|
-
id: string;
|
|
149
148
|
tenantId: string;
|
|
150
149
|
projectId: string;
|
|
151
150
|
agentId: string;
|
|
151
|
+
id: string;
|
|
152
152
|
createdAt: string;
|
|
153
153
|
updatedAt: string;
|
|
154
|
+
relationType: string | null;
|
|
154
155
|
sourceSubAgentId: string;
|
|
155
156
|
targetSubAgentId: string | null;
|
|
156
|
-
relationType: string | null;
|
|
157
157
|
} | undefined>;
|
|
158
158
|
/**
|
|
159
159
|
* Upsert agent relation (create if it doesn't exist, no-op if it does)
|
|
160
160
|
*/
|
|
161
161
|
declare const upsertSubAgentRelation: (db: AgentsManageDatabaseClient) => (params: SubAgentRelationInsert) => Promise<{
|
|
162
|
-
id: string;
|
|
163
162
|
tenantId: string;
|
|
164
163
|
projectId: string;
|
|
165
164
|
agentId: string;
|
|
165
|
+
id: string;
|
|
166
166
|
createdAt: string;
|
|
167
167
|
updatedAt: string;
|
|
168
|
+
relationType: string | null;
|
|
168
169
|
sourceSubAgentId: string;
|
|
169
170
|
targetSubAgentId: string | null;
|
|
170
|
-
relationType: string | null;
|
|
171
171
|
}>;
|
|
172
172
|
declare const updateAgentRelation: (db: AgentsManageDatabaseClient) => (params: {
|
|
173
173
|
scopes: AgentScopeConfig;
|
|
@@ -204,18 +204,18 @@ declare const createAgentToolRelation: (db: AgentsManageDatabaseClient) => (para
|
|
|
204
204
|
}> | null;
|
|
205
205
|
};
|
|
206
206
|
}) => Promise<{
|
|
207
|
-
id: string;
|
|
208
207
|
tenantId: string;
|
|
209
208
|
projectId: string;
|
|
210
209
|
agentId: string;
|
|
210
|
+
subAgentId: string;
|
|
211
|
+
toolId: string;
|
|
212
|
+
id: string;
|
|
211
213
|
createdAt: string;
|
|
212
214
|
updatedAt: string;
|
|
213
|
-
toolId: string;
|
|
214
215
|
headers: Record<string, string> | null;
|
|
215
216
|
toolPolicies: Record<string, {
|
|
216
217
|
needsApproval?: boolean;
|
|
217
218
|
}> | null;
|
|
218
|
-
subAgentId: string;
|
|
219
219
|
selectedTools: string[] | null;
|
|
220
220
|
}>;
|
|
221
221
|
declare const updateAgentToolRelation: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -248,18 +248,18 @@ declare const getAgentToolRelationById: (db: AgentsManageDatabaseClient) => (par
|
|
|
248
248
|
scopes: SubAgentScopeConfig;
|
|
249
249
|
relationId: string;
|
|
250
250
|
}) => Promise<{
|
|
251
|
-
id: string;
|
|
252
251
|
tenantId: string;
|
|
253
252
|
projectId: string;
|
|
254
253
|
agentId: string;
|
|
254
|
+
subAgentId: string;
|
|
255
|
+
toolId: string;
|
|
256
|
+
id: string;
|
|
255
257
|
createdAt: string;
|
|
256
258
|
updatedAt: string;
|
|
257
|
-
toolId: string;
|
|
258
259
|
headers: Record<string, string> | null;
|
|
259
260
|
toolPolicies: Record<string, {
|
|
260
261
|
needsApproval?: boolean;
|
|
261
262
|
}> | null;
|
|
262
|
-
subAgentId: string;
|
|
263
263
|
selectedTools: string[] | null;
|
|
264
264
|
} | undefined>;
|
|
265
265
|
declare const getAgentToolRelationByAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { subAgentRelations, subAgentToolRelations, subAgents, tools } from "../../db/manage/manage-schema.js";
|
|
2
2
|
import { generateId } from "../../utils/conversations.js";
|
|
3
|
+
import { agentScopedWhere, subAgentScopedWhere } from "./scope-helpers.js";
|
|
3
4
|
import { and, count, desc, eq, isNotNull } from "drizzle-orm";
|
|
4
5
|
|
|
5
6
|
//#region src/data-access/manage/subAgentRelations.ts
|
|
6
7
|
const getAgentRelationById = (db) => async (params) => {
|
|
7
|
-
return db.query.subAgentRelations.findFirst({ where: and(
|
|
8
|
+
return db.query.subAgentRelations.findFirst({ where: and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.id, params.relationId)) });
|
|
8
9
|
};
|
|
9
10
|
const listAgentRelations = (db) => async (params) => {
|
|
10
11
|
const page = params.pagination?.page || 1;
|
|
11
12
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
12
13
|
const offset = (page - 1) * limit;
|
|
13
|
-
const whereClause =
|
|
14
|
+
const whereClause = agentScopedWhere(subAgentRelations, params.scopes);
|
|
14
15
|
const [data, totalResult] = await Promise.all([db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentRelations).where(whereClause)]);
|
|
15
16
|
const total = totalResult[0]?.count || 0;
|
|
16
17
|
return {
|
|
@@ -24,16 +25,16 @@ const listAgentRelations = (db) => async (params) => {
|
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
const getAgentRelations = (db) => async (params) => {
|
|
27
|
-
return await db.query.subAgentRelations.findMany({ where: and(
|
|
28
|
+
return await db.query.subAgentRelations.findMany({ where: and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.sourceSubAgentId, params.scopes.subAgentId)) });
|
|
28
29
|
};
|
|
29
30
|
const getAgentRelationsByAgent = (db) => async (params) => {
|
|
30
|
-
return await db.query.subAgentRelations.findMany({ where:
|
|
31
|
+
return await db.query.subAgentRelations.findMany({ where: agentScopedWhere(subAgentRelations, params.scopes) });
|
|
31
32
|
};
|
|
32
33
|
const getAgentRelationsBySource = (db) => async (params) => {
|
|
33
34
|
const page = params.pagination?.page || 1;
|
|
34
35
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
35
36
|
const offset = (page - 1) * limit;
|
|
36
|
-
const whereClause = and(
|
|
37
|
+
const whereClause = and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.sourceSubAgentId, params.sourceSubAgentId));
|
|
37
38
|
const [data, totalResult] = await Promise.all([db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentRelations).where(whereClause)]);
|
|
38
39
|
const total = totalResult[0]?.count || 0;
|
|
39
40
|
return {
|
|
@@ -50,7 +51,7 @@ const getSubAgentRelationsByTarget = (db) => async (params) => {
|
|
|
50
51
|
const page = params.pagination?.page || 1;
|
|
51
52
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
52
53
|
const offset = (page - 1) * limit;
|
|
53
|
-
const whereClause = and(
|
|
54
|
+
const whereClause = and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.targetSubAgentId, params.targetSubAgentId));
|
|
54
55
|
const [data, totalResult] = await Promise.all([db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentRelations).where(whereClause)]);
|
|
55
56
|
const total = totalResult[0]?.count || 0;
|
|
56
57
|
return {
|
|
@@ -70,7 +71,7 @@ const getRelatedAgentsForAgent = (db) => async (params) => {
|
|
|
70
71
|
description: subAgents.description,
|
|
71
72
|
relationType: subAgentRelations.relationType,
|
|
72
73
|
relationId: subAgentRelations.id
|
|
73
|
-
}).from(subAgentRelations).innerJoin(subAgents, and(eq(subAgentRelations.targetSubAgentId, subAgents.id), eq(subAgentRelations.tenantId, subAgents.tenantId), eq(subAgentRelations.projectId, subAgents.projectId), eq(subAgentRelations.agentId, subAgents.agentId))).where(and(
|
|
74
|
+
}).from(subAgentRelations).innerJoin(subAgents, and(eq(subAgentRelations.targetSubAgentId, subAgents.id), eq(subAgentRelations.tenantId, subAgents.tenantId), eq(subAgentRelations.projectId, subAgents.projectId), eq(subAgentRelations.agentId, subAgents.agentId))).where(and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.sourceSubAgentId, params.subAgentId), isNotNull(subAgentRelations.targetSubAgentId))) };
|
|
74
75
|
};
|
|
75
76
|
const createSubAgentRelation = (db) => async (params) => {
|
|
76
77
|
const count$1 = [
|
|
@@ -87,9 +88,7 @@ const createSubAgentRelation = (db) => async (params) => {
|
|
|
87
88
|
*/
|
|
88
89
|
const getAgentRelationByParams = (db) => async (params) => {
|
|
89
90
|
const whereConditions = [
|
|
90
|
-
|
|
91
|
-
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
92
|
-
eq(subAgentRelations.agentId, params.scopes.agentId),
|
|
91
|
+
agentScopedWhere(subAgentRelations, params.scopes),
|
|
93
92
|
eq(subAgentRelations.sourceSubAgentId, params.sourceSubAgentId),
|
|
94
93
|
eq(subAgentRelations.relationType, params.relationType)
|
|
95
94
|
];
|
|
@@ -118,21 +117,19 @@ const updateAgentRelation = (db) => async (params) => {
|
|
|
118
117
|
...params.data,
|
|
119
118
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
120
119
|
};
|
|
121
|
-
return (await db.update(subAgentRelations).set(updateData).where(and(
|
|
120
|
+
return (await db.update(subAgentRelations).set(updateData).where(and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.id, params.relationId))).returning())[0];
|
|
122
121
|
};
|
|
123
122
|
const deleteSubAgentRelation = (db) => async (params) => {
|
|
124
|
-
return (await db.delete(subAgentRelations).where(and(
|
|
123
|
+
return (await db.delete(subAgentRelations).where(and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.id, params.relationId))).returning()).length > 0;
|
|
125
124
|
};
|
|
126
125
|
const deleteAgentRelationsByAgent = (db) => async (params) => {
|
|
127
|
-
return (await db.delete(subAgentRelations).where(
|
|
126
|
+
return (await db.delete(subAgentRelations).where(agentScopedWhere(subAgentRelations, params.scopes)).returning()).length > 0;
|
|
128
127
|
};
|
|
129
128
|
const createAgentToolRelation = (db) => async (params) => {
|
|
130
129
|
const finalRelationId = params.relationId ?? generateId();
|
|
131
130
|
return (await db.insert(subAgentToolRelations).values({
|
|
132
131
|
id: finalRelationId,
|
|
133
|
-
|
|
134
|
-
projectId: params.scopes.projectId,
|
|
135
|
-
agentId: params.scopes.agentId,
|
|
132
|
+
...params.scopes,
|
|
136
133
|
subAgentId: params.data.subAgentId,
|
|
137
134
|
toolId: params.data.toolId,
|
|
138
135
|
selectedTools: params.data.selectedTools,
|
|
@@ -145,22 +142,23 @@ const updateAgentToolRelation = (db) => async (params) => {
|
|
|
145
142
|
...params.data,
|
|
146
143
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
147
144
|
};
|
|
148
|
-
return (await db.update(subAgentToolRelations).set(updateData).where(and(
|
|
145
|
+
return (await db.update(subAgentToolRelations).set(updateData).where(and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.id, params.relationId))).returning())[0];
|
|
149
146
|
};
|
|
150
147
|
const deleteAgentToolRelation = (db) => async (params) => {
|
|
151
|
-
return (await db.delete(subAgentToolRelations).where(and(
|
|
148
|
+
return (await db.delete(subAgentToolRelations).where(and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.id, params.relationId))).returning()).length > 0;
|
|
152
149
|
};
|
|
153
150
|
const deleteAgentToolRelationByAgent = (db) => async (params) => {
|
|
154
|
-
return (await db.delete(subAgentToolRelations).where(
|
|
151
|
+
return (await db.delete(subAgentToolRelations).where(subAgentScopedWhere(subAgentToolRelations, params.scopes)).returning()).length > 0;
|
|
155
152
|
};
|
|
156
153
|
const getAgentToolRelationById = (db) => async (params) => {
|
|
157
|
-
return await db.query.subAgentToolRelations.findFirst({ where: and(
|
|
154
|
+
return await db.query.subAgentToolRelations.findFirst({ where: and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.id, params.relationId)) });
|
|
158
155
|
};
|
|
159
156
|
const getAgentToolRelationByAgent = (db) => async (params) => {
|
|
160
157
|
const page = params.pagination?.page || 1;
|
|
161
158
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
162
159
|
const offset = (page - 1) * limit;
|
|
163
|
-
const
|
|
160
|
+
const whereClause = subAgentScopedWhere(subAgentToolRelations, params.scopes);
|
|
161
|
+
const [data, totalResult] = await Promise.all([db.select().from(subAgentToolRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
164
162
|
const total = totalResult[0]?.count || 0;
|
|
165
163
|
return {
|
|
166
164
|
data,
|
|
@@ -176,7 +174,8 @@ const getAgentToolRelationByTool = (db) => async (params) => {
|
|
|
176
174
|
const page = params.pagination?.page || 1;
|
|
177
175
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
178
176
|
const offset = (page - 1) * limit;
|
|
179
|
-
const
|
|
177
|
+
const whereClause = and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.toolId, params.toolId));
|
|
178
|
+
const [data, totalResult] = await Promise.all([db.select().from(subAgentToolRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
180
179
|
const total = totalResult[0]?.count || 0;
|
|
181
180
|
return {
|
|
182
181
|
data,
|
|
@@ -192,7 +191,8 @@ const listAgentToolRelations = (db) => async (params) => {
|
|
|
192
191
|
const page = params.pagination?.page || 1;
|
|
193
192
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
194
193
|
const offset = (page - 1) * limit;
|
|
195
|
-
const
|
|
194
|
+
const whereClause = agentScopedWhere(subAgentToolRelations, params.scopes);
|
|
195
|
+
const [data, totalResult] = await Promise.all([db.select().from(subAgentToolRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
196
196
|
const total = totalResult[0]?.count || 0;
|
|
197
197
|
return {
|
|
198
198
|
data,
|
|
@@ -208,6 +208,7 @@ const getToolsForAgent = (db) => async (params) => {
|
|
|
208
208
|
const page = params.pagination?.page || 1;
|
|
209
209
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
210
210
|
const offset = (page - 1) * limit;
|
|
211
|
+
const whereClause = subAgentScopedWhere(subAgentToolRelations, params.scopes);
|
|
211
212
|
const [data, totalResult] = await Promise.all([db.select({
|
|
212
213
|
id: subAgentToolRelations.id,
|
|
213
214
|
tenantId: subAgentToolRelations.tenantId,
|
|
@@ -234,7 +235,7 @@ const getToolsForAgent = (db) => async (params) => {
|
|
|
234
235
|
headers: tools.headers,
|
|
235
236
|
imageUrl: tools.imageUrl
|
|
236
237
|
}
|
|
237
|
-
}).from(subAgentToolRelations).innerJoin(tools, and(eq(subAgentToolRelations.tenantId, tools.tenantId), eq(subAgentToolRelations.projectId, tools.projectId), eq(subAgentToolRelations.toolId, tools.id))).where(
|
|
238
|
+
}).from(subAgentToolRelations).innerJoin(tools, and(eq(subAgentToolRelations.tenantId, tools.tenantId), eq(subAgentToolRelations.projectId, tools.projectId), eq(subAgentToolRelations.toolId, tools.id))).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
238
239
|
const total = totalResult[0]?.count || 0;
|
|
239
240
|
return {
|
|
240
241
|
data,
|
|
@@ -250,6 +251,7 @@ const getAgentsForTool = (db) => async (params) => {
|
|
|
250
251
|
const page = params.pagination?.page || 1;
|
|
251
252
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
252
253
|
const offset = (page - 1) * limit;
|
|
254
|
+
const whereClause = and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.toolId, params.toolId));
|
|
253
255
|
const [data, totalResult] = await Promise.all([db.select({
|
|
254
256
|
id: subAgentToolRelations.id,
|
|
255
257
|
tenantId: subAgentToolRelations.tenantId,
|
|
@@ -271,7 +273,7 @@ const getAgentsForTool = (db) => async (params) => {
|
|
|
271
273
|
createdAt: subAgents.createdAt,
|
|
272
274
|
updatedAt: subAgents.updatedAt
|
|
273
275
|
}
|
|
274
|
-
}).from(subAgentToolRelations).innerJoin(subAgents, and(eq(subAgentToolRelations.subAgentId, subAgents.id), eq(subAgentToolRelations.tenantId, subAgents.tenantId), eq(subAgentToolRelations.projectId, subAgents.projectId), eq(subAgentToolRelations.agentId, subAgents.agentId))).where(
|
|
276
|
+
}).from(subAgentToolRelations).innerJoin(subAgents, and(eq(subAgentToolRelations.subAgentId, subAgents.id), eq(subAgentToolRelations.tenantId, subAgents.tenantId), eq(subAgentToolRelations.projectId, subAgents.projectId), eq(subAgentToolRelations.agentId, subAgents.agentId))).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
275
277
|
const total = totalResult[0]?.count || 0;
|
|
276
278
|
return {
|
|
277
279
|
data,
|
|
@@ -284,7 +286,7 @@ const getAgentsForTool = (db) => async (params) => {
|
|
|
284
286
|
};
|
|
285
287
|
};
|
|
286
288
|
const validateSubAgent = (db) => async (params) => {
|
|
287
|
-
return (await db.select({ id: subAgents.id }).from(subAgents).where(and(
|
|
289
|
+
return (await db.select({ id: subAgents.id }).from(subAgents).where(and(agentScopedWhere(subAgents, params.scopes), eq(subAgents.id, params.scopes.subAgentId))).limit(1)).length > 0;
|
|
288
290
|
};
|
|
289
291
|
|
|
290
292
|
//#endregion
|