@inkeep/agents-core 0.58.14 → 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.
Files changed (78) hide show
  1. package/dist/auth/auth-schema.d.ts +85 -85
  2. package/dist/auth/auth-validation-schemas.d.ts +135 -135
  3. package/dist/auth/auth.d.ts +9 -9
  4. package/dist/auth/auth.js +17 -45
  5. package/dist/auth/permissions.d.ts +9 -9
  6. package/dist/data-access/index.d.ts +4 -1
  7. package/dist/data-access/index.js +4 -1
  8. package/dist/data-access/manage/agentFull.js +28 -12
  9. package/dist/data-access/manage/agents.d.ts +25 -24
  10. package/dist/data-access/manage/agents.js +33 -33
  11. package/dist/data-access/manage/artifactComponents.d.ts +14 -14
  12. package/dist/data-access/manage/artifactComponents.js +14 -13
  13. package/dist/data-access/manage/audit-queries.js +6 -5
  14. package/dist/data-access/manage/contextConfigs.d.ts +12 -12
  15. package/dist/data-access/manage/contextConfigs.js +7 -6
  16. package/dist/data-access/manage/credentialReferences.js +12 -11
  17. package/dist/data-access/manage/dataComponents.d.ts +8 -8
  18. package/dist/data-access/manage/dataComponents.js +13 -11
  19. package/dist/data-access/manage/evalConfig.js +42 -41
  20. package/dist/data-access/manage/externalAgents.js +8 -7
  21. package/dist/data-access/manage/functionTools.d.ts +19 -23
  22. package/dist/data-access/manage/functionTools.js +27 -65
  23. package/dist/data-access/manage/functions.js +7 -10
  24. package/dist/data-access/manage/projects.js +37 -36
  25. package/dist/data-access/manage/scheduledTriggers.js +10 -6
  26. package/dist/data-access/manage/scheduledWorkflows.js +3 -2
  27. package/dist/data-access/manage/scope-helpers.d.ts +2 -1
  28. package/dist/data-access/manage/scope-helpers.js +2 -1
  29. package/dist/data-access/manage/skills.d.ts +17 -17
  30. package/dist/data-access/manage/skills.js +14 -9
  31. package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +24 -24
  32. package/dist/data-access/manage/subAgentRelations.d.ts +34 -34
  33. package/dist/data-access/manage/subAgentRelations.js +28 -26
  34. package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +24 -24
  35. package/dist/data-access/manage/subAgentTeamAgentRelations.js +16 -16
  36. package/dist/data-access/manage/subAgents.d.ts +12 -12
  37. package/dist/data-access/manage/subAgents.js +8 -7
  38. package/dist/data-access/manage/tools.d.ts +24 -24
  39. package/dist/data-access/manage/tools.js +8 -6
  40. package/dist/data-access/manage/triggers.js +12 -8
  41. package/dist/data-access/runtime/apiKeys.d.ts +16 -16
  42. package/dist/data-access/runtime/apiKeys.js +16 -12
  43. package/dist/data-access/runtime/apps.d.ts +8 -8
  44. package/dist/data-access/runtime/apps.js +8 -7
  45. package/dist/data-access/runtime/audit-queries.js +7 -7
  46. package/dist/data-access/runtime/auth.d.ts +18 -0
  47. package/dist/data-access/runtime/auth.js +35 -0
  48. package/dist/data-access/runtime/cascade-delete.js +29 -24
  49. package/dist/data-access/runtime/contextCache.d.ts +1 -0
  50. package/dist/data-access/runtime/contextCache.js +9 -8
  51. package/dist/data-access/runtime/conversations.d.ts +31 -31
  52. package/dist/data-access/runtime/conversations.js +8 -12
  53. package/dist/data-access/runtime/evalRuns.js +23 -22
  54. package/dist/data-access/runtime/github-work-app-installations.js +32 -21
  55. package/dist/data-access/runtime/ledgerArtifacts.js +9 -24
  56. package/dist/data-access/runtime/messages.d.ts +24 -24
  57. package/dist/data-access/runtime/messages.js +9 -8
  58. package/dist/data-access/runtime/projects.js +6 -5
  59. package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +3 -3
  60. package/dist/data-access/runtime/scheduledTriggerInvocations.js +16 -26
  61. package/dist/data-access/runtime/slack-work-app-mcp.js +6 -5
  62. package/dist/data-access/runtime/tasks.d.ts +12 -8
  63. package/dist/data-access/runtime/tasks.js +4 -5
  64. package/dist/data-access/runtime/triggerInvocations.js +4 -8
  65. package/dist/data-access/runtime/workAppSlack.js +21 -14
  66. package/dist/db/manage/manage-schema.d.ts +449 -449
  67. package/dist/db/runtime/runtime-schema.d.ts +332 -332
  68. package/dist/index.d.ts +6 -2
  69. package/dist/index.js +7 -1
  70. package/dist/retry/index.d.ts +3 -0
  71. package/dist/retry/index.js +4 -0
  72. package/dist/retry/retryable-errors.d.ts +10 -0
  73. package/dist/retry/retryable-errors.js +72 -0
  74. package/dist/retry/withRetry.d.ts +15 -0
  75. package/dist/retry/withRetry.js +37 -0
  76. package/dist/validation/dolt-schemas.d.ts +1 -1
  77. package/dist/validation/schemas.d.ts +412 -412
  78. 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(eq(scheduledWorkflows.tenantId, scopes.tenantId), eq(scheduledWorkflows.projectId, scopes.projectId), eq(scheduledWorkflows.agentId, scopes.agentId), eq(scheduledWorkflows.scheduledTriggerId, scheduledTriggerId)) });
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(eq(scheduledWorkflows.tenantId, params.scopes.tenantId), eq(scheduledWorkflows.projectId, params.scopes.projectId), eq(scheduledWorkflows.agentId, params.scopes.agentId), eq(scheduledWorkflows.id, params.scheduledWorkflowId))).returning())[0];
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;
15
+ description: string;
16
+ metadata: Record<string, string> | null;
13
17
  createdAt: string;
14
18
  updatedAt: string;
15
- metadata: Record<string, string> | null;
16
- description: string;
17
- projectId: string;
18
- tenantId: string;
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;
48
+ description: string;
49
+ metadata: Record<string, string> | null;
46
50
  createdAt: string;
47
51
  updatedAt: string;
48
- metadata: Record<string, string> | null;
49
- description: string;
50
- projectId: string;
51
- tenantId: string;
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;
59
+ description: string;
60
+ metadata: Record<string, string> | null;
57
61
  createdAt: string;
58
62
  updatedAt: string;
59
- metadata: Record<string, string> | null;
60
- description: string;
61
- projectId: string;
62
- tenantId: string;
63
63
  content: string;
64
64
  }>;
65
65
  declare const updateSkill: (db: AgentsManageDatabaseClient) => (params: {
@@ -91,16 +91,16 @@ declare const upsertSubAgentSkill: (db: AgentsManageDatabaseClient) => (params:
91
91
  index: number;
92
92
  alwaysLoaded?: boolean;
93
93
  }) => Promise<{
94
+ tenantId: string;
95
+ projectId: string;
96
+ agentId: string;
97
+ subAgentId: string;
94
98
  id: string;
95
99
  createdAt: string;
96
100
  updatedAt: string;
97
- subAgentId: string;
98
- projectId: string;
99
- tenantId: string;
100
- agentId: string;
101
- skillId: string;
102
101
  index: number;
103
102
  alwaysLoaded: boolean;
103
+ skillId: string;
104
104
  }>;
105
105
  declare const deleteSubAgentSkill: (db: AgentsManageDatabaseClient) => (params: {
106
106
  scopes: AgentScopeConfig;
@@ -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(eq(skills.tenantId, params.scopes.tenantId), eq(skills.projectId, params.scopes.projectId), eq(skills.id, params.skillId)) }) ?? null;
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 = and(eq(skills.tenantId, params.scopes.tenantId), eq(skills.projectId, params.scopes.projectId));
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
- if (await db.query.skills.findFirst({ where: and(eq(skills.tenantId, baseData.tenantId), eq(skills.projectId, baseData.projectId), eq(skills.id, baseData.id)) })) {
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(eq(skills.tenantId, baseData.tenantId), eq(skills.projectId, baseData.projectId), eq(skills.id, baseData.id))).returning();
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(eq(skills.tenantId, params.scopes.tenantId), eq(skills.projectId, params.scopes.projectId), eq(skills.id, params.skillId))).returning();
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(eq(skills.tenantId, params.scopes.tenantId), eq(skills.projectId, params.scopes.projectId), eq(skills.id, params.skillId))).returning()).length > 0;
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(eq(subAgentSkills.tenantId, params.scopes.tenantId), eq(subAgentSkills.projectId, params.scopes.projectId), eq(subAgentSkills.agentId, params.scopes.agentId), inArray(subAgentSkills.subAgentId, params.subAgentIds))).orderBy(asc(subAgentSkills.index), asc(subAgentSkills.createdAt));
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(eq(subAgentSkills.tenantId, params.scopes.tenantId), eq(subAgentSkills.projectId, params.scopes.projectId), eq(subAgentSkills.agentId, params.scopes.agentId), eq(subAgentSkills.subAgentId, params.scopes.subAgentId), eq(subAgentSkills.skillId, params.skillId)) });
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(eq(subAgentSkills.tenantId, params.scopes.tenantId), eq(subAgentSkills.projectId, params.scopes.projectId), eq(subAgentSkills.agentId, params.scopes.agentId), eq(subAgentSkills.id, params.subAgentSkillId))).returning()).length > 0;
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,14 +9,14 @@ declare const getSubAgentExternalAgentRelationById: (db: AgentsManageDatabaseCli
9
9
  scopes: SubAgentScopeConfig;
10
10
  relationId: string;
11
11
  }) => Promise<{
12
+ tenantId: string;
13
+ projectId: string;
14
+ agentId: string;
15
+ subAgentId: string;
12
16
  id: string;
13
17
  createdAt: string;
14
18
  updatedAt: string;
15
- subAgentId: string;
16
- projectId: string;
17
- tenantId: string;
18
19
  headers: Record<string, string> | null;
19
- agentId: string;
20
20
  externalAgentId: string;
21
21
  } | undefined>;
22
22
  declare const listSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
@@ -44,27 +44,27 @@ declare const listSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClien
44
44
  declare const getSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
45
45
  scopes: SubAgentScopeConfig;
46
46
  }) => Promise<{
47
+ tenantId: string;
48
+ projectId: string;
49
+ agentId: string;
50
+ subAgentId: string;
47
51
  id: string;
48
52
  createdAt: string;
49
53
  updatedAt: string;
50
- subAgentId: string;
51
- projectId: string;
52
- tenantId: string;
53
54
  headers: Record<string, string> | null;
54
- agentId: string;
55
55
  externalAgentId: string;
56
56
  }[]>;
57
57
  declare const getSubAgentExternalAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (params: {
58
58
  scopes: AgentScopeConfig;
59
59
  }) => Promise<{
60
+ tenantId: string;
61
+ projectId: string;
62
+ agentId: string;
63
+ subAgentId: string;
60
64
  id: string;
61
65
  createdAt: string;
62
66
  updatedAt: string;
63
- subAgentId: string;
64
- projectId: string;
65
- tenantId: string;
66
67
  headers: Record<string, string> | null;
67
- agentId: string;
68
68
  externalAgentId: string;
69
69
  }[]>;
70
70
  declare const getSubAgentExternalAgentRelationsByExternalAgent: (db: AgentsManageDatabaseClient) => (params: {
@@ -180,14 +180,14 @@ declare const createSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClie
180
180
  headers?: Record<string, string> | null;
181
181
  };
182
182
  }) => Promise<{
183
+ tenantId: string;
184
+ projectId: string;
185
+ agentId: string;
186
+ subAgentId: string;
183
187
  id: string;
184
188
  createdAt: string;
185
189
  updatedAt: string;
186
- subAgentId: string;
187
- projectId: string;
188
- tenantId: string;
189
190
  headers: Record<string, string> | null;
190
- agentId: string;
191
191
  externalAgentId: string;
192
192
  }>;
193
193
  /**
@@ -197,14 +197,14 @@ declare const getSubAgentExternalAgentRelationByParams: (db: AgentsManageDatabas
197
197
  scopes: SubAgentScopeConfig;
198
198
  externalAgentId: string;
199
199
  }) => Promise<{
200
+ tenantId: string;
201
+ projectId: string;
202
+ agentId: string;
203
+ subAgentId: string;
200
204
  id: string;
201
205
  createdAt: string;
202
206
  updatedAt: string;
203
- subAgentId: string;
204
- projectId: string;
205
- tenantId: string;
206
207
  headers: Record<string, string> | null;
207
- agentId: string;
208
208
  externalAgentId: string;
209
209
  } | undefined>;
210
210
  /**
@@ -218,14 +218,14 @@ declare const upsertSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClie
218
218
  headers?: Record<string, string> | null;
219
219
  };
220
220
  }) => Promise<{
221
+ tenantId: string;
222
+ projectId: string;
223
+ agentId: string;
224
+ subAgentId: string;
221
225
  id: string;
222
226
  createdAt: string;
223
227
  updatedAt: string;
224
- subAgentId: string;
225
- projectId: string;
226
- tenantId: string;
227
228
  headers: Record<string, string> | null;
228
- agentId: string;
229
229
  externalAgentId: string;
230
230
  }>;
231
231
  declare const updateSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClient) => (params: {
@@ -9,15 +9,15 @@ declare const getAgentRelationById: (db: AgentsManageDatabaseClient) => (params:
9
9
  scopes: AgentScopeConfig;
10
10
  relationId: string;
11
11
  }) => Promise<{
12
+ tenantId: string;
13
+ projectId: string;
14
+ agentId: string;
12
15
  id: string;
13
16
  createdAt: string;
14
17
  updatedAt: string;
15
- projectId: string;
16
- tenantId: string;
17
- agentId: 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
+ tenantId: string;
48
+ projectId: string;
49
+ agentId: string;
47
50
  id: string;
48
51
  createdAt: string;
49
52
  updatedAt: string;
50
- projectId: string;
51
- tenantId: string;
52
- agentId: 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
+ tenantId: string;
61
+ projectId: string;
62
+ agentId: string;
60
63
  id: string;
61
64
  createdAt: string;
62
65
  updatedAt: string;
63
- projectId: string;
64
- tenantId: string;
65
- agentId: 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
+ tenantId: string;
130
+ projectId: string;
131
+ agentId: string;
129
132
  id: string;
130
133
  createdAt: string;
131
134
  updatedAt: string;
132
- projectId: string;
133
- tenantId: string;
134
- agentId: 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
+ tenantId: string;
149
+ projectId: string;
150
+ agentId: string;
148
151
  id: string;
149
152
  createdAt: string;
150
153
  updatedAt: string;
151
- projectId: string;
152
- tenantId: string;
153
- agentId: 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
+ tenantId: string;
163
+ projectId: string;
164
+ agentId: string;
162
165
  id: string;
163
166
  createdAt: string;
164
167
  updatedAt: string;
165
- projectId: string;
166
- tenantId: string;
167
- agentId: 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,15 +204,15 @@ declare const createAgentToolRelation: (db: AgentsManageDatabaseClient) => (para
204
204
  }> | null;
205
205
  };
206
206
  }) => Promise<{
207
+ tenantId: string;
208
+ projectId: string;
209
+ agentId: string;
210
+ subAgentId: string;
211
+ toolId: string;
207
212
  id: string;
208
213
  createdAt: string;
209
214
  updatedAt: string;
210
- subAgentId: string;
211
- projectId: string;
212
- tenantId: string;
213
215
  headers: Record<string, string> | null;
214
- agentId: string;
215
- toolId: string;
216
216
  toolPolicies: Record<string, {
217
217
  needsApproval?: boolean;
218
218
  }> | null;
@@ -248,15 +248,15 @@ declare const getAgentToolRelationById: (db: AgentsManageDatabaseClient) => (par
248
248
  scopes: SubAgentScopeConfig;
249
249
  relationId: string;
250
250
  }) => Promise<{
251
+ tenantId: string;
252
+ projectId: string;
253
+ agentId: string;
254
+ subAgentId: string;
255
+ toolId: string;
251
256
  id: string;
252
257
  createdAt: string;
253
258
  updatedAt: string;
254
- subAgentId: string;
255
- projectId: string;
256
- tenantId: string;
257
259
  headers: Record<string, string> | null;
258
- agentId: string;
259
- toolId: string;
260
260
  toolPolicies: Record<string, {
261
261
  needsApproval?: boolean;
262
262
  }> | null;
@@ -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(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId), eq(subAgentRelations.id, params.relationId)) });
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 = and(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId));
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(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId), eq(subAgentRelations.sourceSubAgentId, params.scopes.subAgentId)) });
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: and(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId)) });
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(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId), eq(subAgentRelations.sourceSubAgentId, params.sourceSubAgentId));
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(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId), eq(subAgentRelations.targetSubAgentId, params.targetSubAgentId));
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(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId), eq(subAgentRelations.sourceSubAgentId, params.subAgentId), isNotNull(subAgentRelations.targetSubAgentId))) };
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
- eq(subAgentRelations.tenantId, params.scopes.tenantId),
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(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId), eq(subAgentRelations.id, params.relationId))).returning())[0];
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(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId), eq(subAgentRelations.id, params.relationId))).returning()).length > 0;
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(and(eq(subAgentRelations.tenantId, params.scopes.tenantId), eq(subAgentRelations.projectId, params.scopes.projectId), eq(subAgentRelations.agentId, params.scopes.agentId))).returning()).length > 0;
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
- tenantId: params.scopes.tenantId,
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(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.id, params.relationId))).returning())[0];
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(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.id, params.relationId))).returning()).length > 0;
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(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId))).returning()).length > 0;
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(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.id, params.relationId)) });
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 [data, totalResult] = await Promise.all([db.select().from(subAgentToolRelations).where(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId))).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId)))]);
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 [data, totalResult] = await Promise.all([db.select().from(subAgentToolRelations).where(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.toolId, params.toolId))).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.toolId, params.toolId)))]);
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 [data, totalResult] = await Promise.all([db.select().from(subAgentToolRelations).where(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId))).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId)))]);
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(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId))).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.subAgentId, params.scopes.subAgentId)))]);
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(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.toolId, params.toolId))).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(and(eq(subAgentToolRelations.tenantId, params.scopes.tenantId), eq(subAgentToolRelations.projectId, params.scopes.projectId), eq(subAgentToolRelations.agentId, params.scopes.agentId), eq(subAgentToolRelations.toolId, params.toolId)))]);
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(eq(subAgents.tenantId, params.scopes.tenantId), eq(subAgents.projectId, params.scopes.projectId), eq(subAgents.agentId, params.scopes.agentId), eq(subAgents.id, params.scopes.subAgentId))).limit(1)).length > 0;
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