@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 { credentialReferences, externalAgents, tools } from "../../db/manage/manage-schema.js";
2
+ import { projectScopedWhere } from "./scope-helpers.js";
2
3
  import { isUniqueConstraintError } from "../../utils/error.js";
3
4
  import { and, count, desc, eq, sql } from "drizzle-orm";
4
5
 
@@ -7,22 +8,22 @@ import { and, count, desc, eq, sql } from "drizzle-orm";
7
8
  * Get a credential reference by ID
8
9
  */
9
10
  const getCredentialReference = (db) => async (params) => {
10
- return await db.query.credentialReferences.findFirst({ where: and(eq(credentialReferences.tenantId, params.scopes.tenantId), eq(credentialReferences.projectId, params.scopes.projectId), eq(credentialReferences.id, params.id)) });
11
+ return await db.query.credentialReferences.findFirst({ where: and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)) });
11
12
  };
12
13
  /**
13
14
  * Get a user-scoped credential reference by toolId and userId
14
15
  */
15
16
  const getUserScopedCredentialReference = (db) => async (params) => {
16
- return await db.query.credentialReferences.findFirst({ where: and(eq(credentialReferences.tenantId, params.scopes.tenantId), eq(credentialReferences.projectId, params.scopes.projectId), eq(credentialReferences.toolId, params.toolId), eq(credentialReferences.userId, params.userId)) });
17
+ return await db.query.credentialReferences.findFirst({ where: and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.toolId, params.toolId), eq(credentialReferences.userId, params.userId)) });
17
18
  };
18
19
  /**
19
20
  * Get a credential reference by ID with its related tools
20
21
  */
21
22
  const getCredentialReferenceWithResources = (db) => async (params) => {
22
23
  const [credential, relatedTools, relatedExternalAgents] = await Promise.all([
23
- db.query.credentialReferences.findFirst({ where: and(eq(credentialReferences.tenantId, params.scopes.tenantId), eq(credentialReferences.projectId, params.scopes.projectId), eq(credentialReferences.id, params.id)) }),
24
- db.select().from(tools).where(and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.projectId, params.scopes.projectId), eq(tools.credentialReferenceId, params.id))),
25
- db.select().from(externalAgents).where(and(eq(externalAgents.tenantId, params.scopes.tenantId), eq(externalAgents.projectId, params.scopes.projectId), eq(externalAgents.credentialReferenceId, params.id)))
24
+ db.query.credentialReferences.findFirst({ where: and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)) }),
25
+ db.select().from(tools).where(and(projectScopedWhere(tools, params.scopes), eq(tools.credentialReferenceId, params.id))),
26
+ db.select().from(externalAgents).where(and(projectScopedWhere(externalAgents, params.scopes), eq(externalAgents.credentialReferenceId, params.id)))
26
27
  ]);
27
28
  if (!credential) return;
28
29
  return {
@@ -36,7 +37,7 @@ const getCredentialReferenceWithResources = (db) => async (params) => {
36
37
  */
37
38
  const listCredentialReferences = (db) => async (params) => {
38
39
  return await db.query.credentialReferences.findMany({
39
- where: and(eq(credentialReferences.tenantId, params.scopes.tenantId), eq(credentialReferences.projectId, params.scopes.projectId)),
40
+ where: projectScopedWhere(credentialReferences, params.scopes),
40
41
  orderBy: [desc(credentialReferences.createdAt)]
41
42
  });
42
43
  };
@@ -47,7 +48,7 @@ const listCredentialReferencesPaginated = (db) => async (params) => {
47
48
  const page = params.pagination?.page || 1;
48
49
  const limit = Math.min(params.pagination?.limit || 10, 100);
49
50
  const offset = (page - 1) * limit;
50
- const whereClause = and(eq(credentialReferences.tenantId, params.scopes.tenantId), eq(credentialReferences.projectId, params.scopes.projectId));
51
+ const whereClause = projectScopedWhere(credentialReferences, params.scopes);
51
52
  const [data, totalResult] = await Promise.all([db.select().from(credentialReferences).where(whereClause).limit(limit).offset(offset).orderBy(desc(credentialReferences.createdAt)), db.select({ count: sql`COUNT(*)` }).from(credentialReferences).where(whereClause)]);
52
53
  const total = Number(totalResult[0]?.count || 0);
53
54
  return {
@@ -80,7 +81,7 @@ const updateCredentialReference = (db) => async (params) => {
80
81
  await db.update(credentialReferences).set({
81
82
  ...params.data,
82
83
  updatedAt: now
83
- }).where(and(eq(credentialReferences.tenantId, params.scopes.tenantId), eq(credentialReferences.projectId, params.scopes.projectId), eq(credentialReferences.id, params.id)));
84
+ }).where(and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)));
84
85
  return await getCredentialReferenceWithResources(db)({
85
86
  scopes: params.scopes,
86
87
  id: params.id
@@ -94,7 +95,7 @@ const deleteCredentialReference = (db) => async (params) => {
94
95
  scopes: params.scopes,
95
96
  id: params.id
96
97
  })) return false;
97
- await db.delete(credentialReferences).where(and(eq(credentialReferences.tenantId, params.scopes.tenantId), eq(credentialReferences.projectId, params.scopes.projectId), eq(credentialReferences.id, params.id)));
98
+ await db.delete(credentialReferences).where(and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)));
98
99
  return await getCredentialReference(db)({
99
100
  scopes: params.scopes,
100
101
  id: params.id
@@ -110,13 +111,13 @@ const hasCredentialReference = (db) => async (params) => {
110
111
  * Get credential reference by ID (simple version without tools)
111
112
  */
112
113
  const getCredentialReferenceById = (db) => async (params) => {
113
- return await db.query.credentialReferences.findFirst({ where: and(eq(credentialReferences.tenantId, params.scopes.tenantId), eq(credentialReferences.projectId, params.scopes.projectId), eq(credentialReferences.id, params.id)) }) || null;
114
+ return await db.query.credentialReferences.findFirst({ where: and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)) }) || null;
114
115
  };
115
116
  /**
116
117
  * Count credential references for a tenant/project
117
118
  */
118
119
  const countCredentialReferences = (db) => async (params) => {
119
- const total = (await db.select({ count: count() }).from(credentialReferences).where(and(eq(credentialReferences.tenantId, params.scopes.tenantId), eq(credentialReferences.projectId, params.scopes.projectId))))[0]?.count || 0;
120
+ const total = (await db.select({ count: count() }).from(credentialReferences).where(projectScopedWhere(credentialReferences, params.scopes)))[0]?.count || 0;
120
121
  return typeof total === "string" ? Number.parseInt(total, 10) : total;
121
122
  };
122
123
  /**
@@ -65,12 +65,12 @@ declare const associateDataComponentWithAgent: (db: AgentsManageDatabaseClient)
65
65
  scopes: SubAgentScopeConfig;
66
66
  dataComponentId: string;
67
67
  }) => Promise<{
68
- id: string;
69
- createdAt: string;
70
- subAgentId: string;
71
- projectId: string;
72
68
  tenantId: string;
69
+ projectId: string;
73
70
  agentId: string;
71
+ subAgentId: string;
72
+ id: string;
73
+ createdAt: string;
74
74
  dataComponentId: string;
75
75
  }>;
76
76
  /**
@@ -107,12 +107,12 @@ declare const upsertAgentDataComponentRelation: (db: AgentsManageDatabaseClient)
107
107
  scopes: SubAgentScopeConfig;
108
108
  dataComponentId: string;
109
109
  }) => Promise<{
110
- id: string;
111
- createdAt: string;
112
- subAgentId: string;
113
- projectId: string;
114
110
  tenantId: string;
111
+ projectId: string;
115
112
  agentId: string;
113
+ subAgentId: string;
114
+ id: string;
115
+ createdAt: string;
116
116
  dataComponentId: string;
117
117
  } | null>;
118
118
  /**
@@ -2,6 +2,7 @@ import { dataComponents, subAgentDataComponents } from "../../db/manage/manage-s
2
2
  import { validatePropsAsJsonSchema } from "../../validation/props-validation.js";
3
3
  import { validateRender } from "../../validation/render-validation.js";
4
4
  import { generateId } from "../../utils/conversations.js";
5
+ import { projectScopedWhere, subAgentScopedWhere } from "./scope-helpers.js";
5
6
  import { createApiError } from "../../utils/error.js";
6
7
  import "../../utils/index.js";
7
8
  import { and, count, desc, eq } from "drizzle-orm";
@@ -11,13 +12,13 @@ import { and, count, desc, eq } from "drizzle-orm";
11
12
  * Get a data component by ID
12
13
  */
13
14
  const getDataComponent = (db) => async (params) => {
14
- return await db.query.dataComponents.findFirst({ where: and(eq(dataComponents.tenantId, params.scopes.tenantId), eq(dataComponents.projectId, params.scopes.projectId), eq(dataComponents.id, params.dataComponentId)) }) || null;
15
+ return await db.query.dataComponents.findFirst({ where: and(projectScopedWhere(dataComponents, params.scopes), eq(dataComponents.id, params.dataComponentId)) }) || null;
15
16
  };
16
17
  /**
17
18
  * List all data components for a tenant/project
18
19
  */
19
20
  const listDataComponents = (db) => async (params) => {
20
- return await db.select().from(dataComponents).where(and(eq(dataComponents.tenantId, params.scopes.tenantId), eq(dataComponents.projectId, params.scopes.projectId))).orderBy(desc(dataComponents.createdAt));
21
+ return await db.select().from(dataComponents).where(projectScopedWhere(dataComponents, params.scopes)).orderBy(desc(dataComponents.createdAt));
21
22
  };
22
23
  /**
23
24
  * List data components with pagination
@@ -26,7 +27,8 @@ const listDataComponentsPaginated = (db) => async (params) => {
26
27
  const page = params.pagination?.page || 1;
27
28
  const limit = Math.min(params.pagination?.limit || 10, 100);
28
29
  const offset = (page - 1) * limit;
29
- const [data, totalResult] = await Promise.all([db.select().from(dataComponents).where(and(eq(dataComponents.tenantId, params.scopes.tenantId), eq(dataComponents.projectId, params.scopes.projectId))).limit(limit).offset(offset).orderBy(desc(dataComponents.createdAt)), db.select({ count: count() }).from(dataComponents).where(and(eq(dataComponents.tenantId, params.scopes.tenantId), eq(dataComponents.projectId, params.scopes.projectId)))]);
30
+ const whereClause = projectScopedWhere(dataComponents, params.scopes);
31
+ const [data, totalResult] = await Promise.all([db.select().from(dataComponents).where(whereClause).limit(limit).offset(offset).orderBy(desc(dataComponents.createdAt)), db.select({ count: count() }).from(dataComponents).where(whereClause)]);
30
32
  const total = typeof totalResult[0]?.count === "string" ? parseInt(totalResult[0].count, 10) : totalResult[0]?.count || 0;
31
33
  return {
32
34
  data,
@@ -84,7 +86,7 @@ const updateDataComponent = (db) => async (params) => {
84
86
  await db.update(dataComponents).set({
85
87
  ...params.data,
86
88
  updatedAt: now
87
- }).where(and(eq(dataComponents.tenantId, params.scopes.tenantId), eq(dataComponents.projectId, params.scopes.projectId), eq(dataComponents.id, params.dataComponentId)));
89
+ }).where(and(projectScopedWhere(dataComponents, params.scopes), eq(dataComponents.id, params.dataComponentId)));
88
90
  return await getDataComponent(db)({
89
91
  scopes: params.scopes,
90
92
  dataComponentId: params.dataComponentId
@@ -94,7 +96,7 @@ const updateDataComponent = (db) => async (params) => {
94
96
  * Delete a data component
95
97
  */
96
98
  const deleteDataComponent = (db) => async (params) => {
97
- return (await db.delete(dataComponents).where(and(eq(dataComponents.tenantId, params.scopes.tenantId), eq(dataComponents.projectId, params.scopes.projectId), eq(dataComponents.id, params.dataComponentId))).returning()).length > 0;
99
+ return (await db.delete(dataComponents).where(and(projectScopedWhere(dataComponents, params.scopes), eq(dataComponents.id, params.dataComponentId))).returning()).length > 0;
98
100
  };
99
101
  /**
100
102
  * Get data components for a specific agent
@@ -110,7 +112,7 @@ const getDataComponentsForAgent = (db) => async (params) => {
110
112
  createdAt: dataComponents.createdAt,
111
113
  updatedAt: dataComponents.updatedAt,
112
114
  render: dataComponents.render
113
- }).from(dataComponents).innerJoin(subAgentDataComponents, and(eq(dataComponents.id, subAgentDataComponents.dataComponentId), eq(dataComponents.tenantId, subAgentDataComponents.tenantId), eq(dataComponents.projectId, subAgentDataComponents.projectId))).where(and(eq(dataComponents.tenantId, params.scopes.tenantId), eq(dataComponents.projectId, params.scopes.projectId), eq(subAgentDataComponents.agentId, params.scopes.agentId), eq(subAgentDataComponents.subAgentId, params.scopes.subAgentId))).orderBy(desc(dataComponents.createdAt));
115
+ }).from(dataComponents).innerJoin(subAgentDataComponents, and(eq(dataComponents.id, subAgentDataComponents.dataComponentId), eq(dataComponents.tenantId, subAgentDataComponents.tenantId), eq(dataComponents.projectId, subAgentDataComponents.projectId))).where(and(projectScopedWhere(dataComponents, params.scopes), eq(subAgentDataComponents.agentId, params.scopes.agentId), eq(subAgentDataComponents.subAgentId, params.scopes.subAgentId))).orderBy(desc(dataComponents.createdAt));
114
116
  };
115
117
  /**
116
118
  * Associate a data component with an agent
@@ -129,10 +131,10 @@ const associateDataComponentWithAgent = (db) => async (params) => {
129
131
  * Remove association between data component and agent
130
132
  */
131
133
  const removeDataComponentFromAgent = (db) => async (params) => {
132
- return (await db.delete(subAgentDataComponents).where(and(eq(subAgentDataComponents.tenantId, params.scopes.tenantId), eq(subAgentDataComponents.projectId, params.scopes.projectId), eq(subAgentDataComponents.agentId, params.scopes.agentId), eq(subAgentDataComponents.subAgentId, params.scopes.subAgentId), eq(subAgentDataComponents.dataComponentId, params.dataComponentId))).returning()).length > 0;
134
+ return (await db.delete(subAgentDataComponents).where(and(subAgentScopedWhere(subAgentDataComponents, params.scopes), eq(subAgentDataComponents.dataComponentId, params.dataComponentId))).returning()).length > 0;
133
135
  };
134
136
  const deleteAgentDataComponentRelationByAgent = (db) => async (params) => {
135
- return (await db.delete(subAgentDataComponents).where(and(eq(subAgentDataComponents.tenantId, params.scopes.tenantId), eq(subAgentDataComponents.projectId, params.scopes.projectId), eq(subAgentDataComponents.agentId, params.scopes.agentId), eq(subAgentDataComponents.subAgentId, params.scopes.subAgentId))).returning()).length > 0;
137
+ return (await db.delete(subAgentDataComponents).where(subAgentScopedWhere(subAgentDataComponents, params.scopes)).returning()).length > 0;
136
138
  };
137
139
  /**
138
140
  * Get all agents that use a specific data component
@@ -141,13 +143,13 @@ const getAgentsUsingDataComponent = (db) => async (params) => {
141
143
  return await db.select({
142
144
  subAgentId: subAgentDataComponents.subAgentId,
143
145
  createdAt: subAgentDataComponents.createdAt
144
- }).from(subAgentDataComponents).where(and(eq(subAgentDataComponents.tenantId, params.scopes.tenantId), eq(subAgentDataComponents.projectId, params.scopes.projectId), eq(subAgentDataComponents.dataComponentId, params.dataComponentId))).orderBy(desc(subAgentDataComponents.createdAt));
146
+ }).from(subAgentDataComponents).where(and(projectScopedWhere(subAgentDataComponents, params.scopes), eq(subAgentDataComponents.dataComponentId, params.dataComponentId))).orderBy(desc(subAgentDataComponents.createdAt));
145
147
  };
146
148
  /**
147
149
  * Check if a data component is associated with an agent
148
150
  */
149
151
  const isDataComponentAssociatedWithAgent = (db) => async (params) => {
150
- return (await db.select({ id: subAgentDataComponents.id }).from(subAgentDataComponents).where(and(eq(subAgentDataComponents.tenantId, params.scopes.tenantId), eq(subAgentDataComponents.projectId, params.scopes.projectId), eq(subAgentDataComponents.agentId, params.scopes.agentId), eq(subAgentDataComponents.subAgentId, params.scopes.subAgentId), eq(subAgentDataComponents.dataComponentId, params.dataComponentId))).limit(1)).length > 0;
152
+ return (await db.select({ id: subAgentDataComponents.id }).from(subAgentDataComponents).where(and(subAgentScopedWhere(subAgentDataComponents, params.scopes), eq(subAgentDataComponents.dataComponentId, params.dataComponentId))).limit(1)).length > 0;
151
153
  };
152
154
  /**
153
155
  * Upsert agent-data component relation (create if it doesn't exist, no-op if it does)
@@ -160,7 +162,7 @@ const upsertAgentDataComponentRelation = (db) => async (params) => {
160
162
  * Count data components for a tenant/project
161
163
  */
162
164
  const countDataComponents = (db) => async (params) => {
163
- const countValue = (await db.select({ count: count() }).from(dataComponents).where(and(eq(dataComponents.tenantId, params.scopes.tenantId), eq(dataComponents.projectId, params.scopes.projectId))))[0]?.count;
165
+ const countValue = (await db.select({ count: count() }).from(dataComponents).where(projectScopedWhere(dataComponents, params.scopes)))[0]?.count;
164
166
  return typeof countValue === "string" ? parseInt(countValue, 10) : countValue || 0;
165
167
  };
166
168
  /**
@@ -1,13 +1,14 @@
1
1
  import { dataset, datasetItem, datasetRunConfig, datasetRunConfigAgentRelations, evaluationJobConfig, evaluationJobConfigEvaluatorRelations, evaluationRunConfig, evaluationRunConfigEvaluationSuiteConfigRelations, evaluationSuiteConfig, evaluationSuiteConfigEvaluatorRelations, evaluator } from "../../db/manage/manage-schema.js";
2
2
  import { datasetRun } from "../../db/runtime/runtime-schema.js";
3
+ import { projectScopedWhere } from "./scope-helpers.js";
3
4
  import { and, eq, inArray } from "drizzle-orm";
4
5
 
5
6
  //#region src/data-access/manage/evalConfig.ts
6
7
  const getDatasetById = (db) => async (params) => {
7
- return (await db.select().from(dataset).where(and(eq(dataset.tenantId, params.scopes.tenantId), eq(dataset.projectId, params.scopes.projectId), eq(dataset.id, params.scopes.datasetId))).limit(1))[0] ?? null;
8
+ return (await db.select().from(dataset).where(and(projectScopedWhere(dataset, params.scopes), eq(dataset.id, params.scopes.datasetId))).limit(1))[0] ?? null;
8
9
  };
9
10
  const listDatasets = (db) => async (params) => {
10
- return await db.select().from(dataset).where(and(eq(dataset.tenantId, params.scopes.tenantId), eq(dataset.projectId, params.scopes.projectId)));
11
+ return await db.select().from(dataset).where(projectScopedWhere(dataset, params.scopes));
11
12
  };
12
13
  const createDataset = (db) => async (data) => {
13
14
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -21,17 +22,17 @@ const createDataset = (db) => async (data) => {
21
22
  const updateDataset = (db) => async (params) => {
22
23
  const updateData = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
23
24
  for (const [key, value] of Object.entries(params.data)) if (value !== void 0) updateData[key] = value;
24
- const [updated] = await db.update(dataset).set(updateData).where(and(eq(dataset.tenantId, params.scopes.tenantId), eq(dataset.projectId, params.scopes.projectId), eq(dataset.id, params.scopes.datasetId))).returning();
25
+ const [updated] = await db.update(dataset).set(updateData).where(and(projectScopedWhere(dataset, params.scopes), eq(dataset.id, params.scopes.datasetId))).returning();
25
26
  return updated ?? null;
26
27
  };
27
28
  const deleteDataset = (db) => async (params) => {
28
- return (await db.delete(dataset).where(and(eq(dataset.tenantId, params.scopes.tenantId), eq(dataset.projectId, params.scopes.projectId), eq(dataset.id, params.scopes.datasetId))).returning()).length > 0;
29
+ return (await db.delete(dataset).where(and(projectScopedWhere(dataset, params.scopes), eq(dataset.id, params.scopes.datasetId))).returning()).length > 0;
29
30
  };
30
31
  const getDatasetItemById = (db) => async (params) => {
31
- return (await db.select().from(datasetItem).where(and(eq(datasetItem.tenantId, params.scopes.tenantId), eq(datasetItem.projectId, params.scopes.projectId), eq(datasetItem.id, params.scopes.datasetItemId))).limit(1))[0] ?? null;
32
+ return (await db.select().from(datasetItem).where(and(projectScopedWhere(datasetItem, params.scopes), eq(datasetItem.id, params.scopes.datasetItemId))).limit(1))[0] ?? null;
32
33
  };
33
34
  const listDatasetItems = (db) => async (params) => {
34
- return await db.select().from(datasetItem).where(and(eq(datasetItem.tenantId, params.scopes.tenantId), eq(datasetItem.projectId, params.scopes.projectId), eq(datasetItem.datasetId, params.scopes.datasetId)));
35
+ return await db.select().from(datasetItem).where(and(projectScopedWhere(datasetItem, params.scopes), eq(datasetItem.datasetId, params.scopes.datasetId)));
35
36
  };
36
37
  const createDatasetItem = (db) => async (data) => {
37
38
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -54,20 +55,20 @@ const createDatasetItems = (db) => async (data) => {
54
55
  const updateDatasetItem = (db) => async (params) => {
55
56
  const updateData = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
56
57
  for (const [key, value] of Object.entries(params.data)) if (value !== void 0) updateData[key] = value;
57
- const [updated] = await db.update(datasetItem).set(updateData).where(and(eq(datasetItem.tenantId, params.scopes.tenantId), eq(datasetItem.projectId, params.scopes.projectId), eq(datasetItem.id, params.scopes.datasetItemId))).returning();
58
+ const [updated] = await db.update(datasetItem).set(updateData).where(and(projectScopedWhere(datasetItem, params.scopes), eq(datasetItem.id, params.scopes.datasetItemId))).returning();
58
59
  return updated ?? null;
59
60
  };
60
61
  const deleteDatasetItem = (db) => async (params) => {
61
- return (await db.delete(datasetItem).where(and(eq(datasetItem.tenantId, params.scopes.tenantId), eq(datasetItem.projectId, params.scopes.projectId), eq(datasetItem.id, params.scopes.datasetItemId))).returning()).length > 0;
62
+ return (await db.delete(datasetItem).where(and(projectScopedWhere(datasetItem, params.scopes), eq(datasetItem.id, params.scopes.datasetItemId))).returning()).length > 0;
62
63
  };
63
64
  const deleteDatasetItemsByDataset = (db) => async (params) => {
64
- return (await db.delete(datasetItem).where(and(eq(datasetItem.tenantId, params.scopes.tenantId), eq(datasetItem.projectId, params.scopes.projectId), eq(datasetItem.datasetId, params.scopes.datasetId))).returning()).length;
65
+ return (await db.delete(datasetItem).where(and(projectScopedWhere(datasetItem, params.scopes), eq(datasetItem.datasetId, params.scopes.datasetId))).returning()).length;
65
66
  };
66
67
  const getDatasetRunConfigById = (db) => async (params) => {
67
- return (await db.select().from(datasetRunConfig).where(and(eq(datasetRunConfig.tenantId, params.scopes.tenantId), eq(datasetRunConfig.projectId, params.scopes.projectId), eq(datasetRunConfig.id, params.scopes.datasetRunConfigId))).limit(1))[0] ?? null;
68
+ return (await db.select().from(datasetRunConfig).where(and(projectScopedWhere(datasetRunConfig, params.scopes), eq(datasetRunConfig.id, params.scopes.datasetRunConfigId))).limit(1))[0] ?? null;
68
69
  };
69
70
  const listDatasetRunConfigs = (db) => async (params) => {
70
- return await db.select().from(datasetRunConfig).where(and(eq(datasetRunConfig.tenantId, params.scopes.tenantId), eq(datasetRunConfig.projectId, params.scopes.projectId)));
71
+ return await db.select().from(datasetRunConfig).where(projectScopedWhere(datasetRunConfig, params.scopes));
71
72
  };
72
73
  const createDatasetRunConfig = (db) => async (data) => {
73
74
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -81,14 +82,14 @@ const createDatasetRunConfig = (db) => async (data) => {
81
82
  const updateDatasetRunConfig = (db) => async (params) => {
82
83
  const updateData = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
83
84
  for (const [key, value] of Object.entries(params.data)) if (value !== void 0) updateData[key] = value;
84
- const [updated] = await db.update(datasetRunConfig).set(updateData).where(and(eq(datasetRunConfig.tenantId, params.scopes.tenantId), eq(datasetRunConfig.projectId, params.scopes.projectId), eq(datasetRunConfig.id, params.scopes.datasetRunConfigId))).returning();
85
+ const [updated] = await db.update(datasetRunConfig).set(updateData).where(and(projectScopedWhere(datasetRunConfig, params.scopes), eq(datasetRunConfig.id, params.scopes.datasetRunConfigId))).returning();
85
86
  return updated ?? null;
86
87
  };
87
88
  const deleteDatasetRunConfig = (db) => async (params) => {
88
- return (await db.delete(datasetRunConfig).where(and(eq(datasetRunConfig.tenantId, params.scopes.tenantId), eq(datasetRunConfig.projectId, params.scopes.projectId), eq(datasetRunConfig.id, params.scopes.datasetRunConfigId))).returning()).length > 0;
89
+ return (await db.delete(datasetRunConfig).where(and(projectScopedWhere(datasetRunConfig, params.scopes), eq(datasetRunConfig.id, params.scopes.datasetRunConfigId))).returning()).length > 0;
89
90
  };
90
91
  const getDatasetRunConfigAgentRelations = (db) => async (params) => {
91
- return await db.select().from(datasetRunConfigAgentRelations).where(and(eq(datasetRunConfigAgentRelations.tenantId, params.scopes.tenantId), eq(datasetRunConfigAgentRelations.projectId, params.scopes.projectId), eq(datasetRunConfigAgentRelations.datasetRunConfigId, params.scopes.datasetRunConfigId)));
92
+ return await db.select().from(datasetRunConfigAgentRelations).where(and(projectScopedWhere(datasetRunConfigAgentRelations, params.scopes), eq(datasetRunConfigAgentRelations.datasetRunConfigId, params.scopes.datasetRunConfigId)));
92
93
  };
93
94
  const createDatasetRunConfigAgentRelation = (db) => async (data) => {
94
95
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -100,17 +101,17 @@ const createDatasetRunConfigAgentRelation = (db) => async (data) => {
100
101
  return created;
101
102
  };
102
103
  const deleteDatasetRunConfigAgentRelation = (db) => async (params) => {
103
- return (await db.delete(datasetRunConfigAgentRelations).where(and(eq(datasetRunConfigAgentRelations.tenantId, params.scopes.tenantId), eq(datasetRunConfigAgentRelations.projectId, params.scopes.projectId), eq(datasetRunConfigAgentRelations.datasetRunConfigId, params.scopes.datasetRunConfigId), eq(datasetRunConfigAgentRelations.agentId, params.scopes.agentId))).returning()).length > 0;
104
+ return (await db.delete(datasetRunConfigAgentRelations).where(and(projectScopedWhere(datasetRunConfigAgentRelations, params.scopes), eq(datasetRunConfigAgentRelations.datasetRunConfigId, params.scopes.datasetRunConfigId), eq(datasetRunConfigAgentRelations.agentId, params.scopes.agentId))).returning()).length > 0;
104
105
  };
105
106
  const getEvaluatorById = (db) => async (params) => {
106
- return (await db.select().from(evaluator).where(and(eq(evaluator.tenantId, params.scopes.tenantId), eq(evaluator.projectId, params.scopes.projectId), eq(evaluator.id, params.scopes.evaluatorId))).limit(1))[0] ?? null;
107
+ return (await db.select().from(evaluator).where(and(projectScopedWhere(evaluator, params.scopes), eq(evaluator.id, params.scopes.evaluatorId))).limit(1))[0] ?? null;
107
108
  };
108
109
  const listEvaluators = (db) => async (params) => {
109
- return await db.select().from(evaluator).where(and(eq(evaluator.tenantId, params.scopes.tenantId), eq(evaluator.projectId, params.scopes.projectId)));
110
+ return await db.select().from(evaluator).where(projectScopedWhere(evaluator, params.scopes));
110
111
  };
111
112
  const getEvaluatorsByIds = (db) => async (params) => {
112
113
  if (params.evaluatorIds.length === 0) return [];
113
- return await db.select().from(evaluator).where(and(eq(evaluator.tenantId, params.scopes.tenantId), eq(evaluator.projectId, params.scopes.projectId), inArray(evaluator.id, params.evaluatorIds)));
114
+ return await db.select().from(evaluator).where(and(projectScopedWhere(evaluator, params.scopes), inArray(evaluator.id, params.evaluatorIds)));
114
115
  };
115
116
  const createEvaluator = (db) => async (data) => {
116
117
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -124,17 +125,17 @@ const createEvaluator = (db) => async (data) => {
124
125
  const updateEvaluator = (db) => async (params) => {
125
126
  const updateData = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
126
127
  for (const [key, value] of Object.entries(params.data)) if (value !== void 0) updateData[key] = value;
127
- const [updated] = await db.update(evaluator).set(updateData).where(and(eq(evaluator.tenantId, params.scopes.tenantId), eq(evaluator.projectId, params.scopes.projectId), eq(evaluator.id, params.scopes.evaluatorId))).returning();
128
+ const [updated] = await db.update(evaluator).set(updateData).where(and(projectScopedWhere(evaluator, params.scopes), eq(evaluator.id, params.scopes.evaluatorId))).returning();
128
129
  return updated ?? null;
129
130
  };
130
131
  const deleteEvaluator = (db) => async (params) => {
131
- return (await db.delete(evaluator).where(and(eq(evaluator.tenantId, params.scopes.tenantId), eq(evaluator.projectId, params.scopes.projectId), eq(evaluator.id, params.scopes.evaluatorId))).returning()).length > 0;
132
+ return (await db.delete(evaluator).where(and(projectScopedWhere(evaluator, params.scopes), eq(evaluator.id, params.scopes.evaluatorId))).returning()).length > 0;
132
133
  };
133
134
  const getEvaluationSuiteConfigById = (db) => async (params) => {
134
- return (await db.select().from(evaluationSuiteConfig).where(and(eq(evaluationSuiteConfig.tenantId, params.scopes.tenantId), eq(evaluationSuiteConfig.projectId, params.scopes.projectId), eq(evaluationSuiteConfig.id, params.scopes.evaluationSuiteConfigId))).limit(1))[0] ?? null;
135
+ return (await db.select().from(evaluationSuiteConfig).where(and(projectScopedWhere(evaluationSuiteConfig, params.scopes), eq(evaluationSuiteConfig.id, params.scopes.evaluationSuiteConfigId))).limit(1))[0] ?? null;
135
136
  };
136
137
  const listEvaluationSuiteConfigs = (db) => async (params) => {
137
- return await db.select().from(evaluationSuiteConfig).where(and(eq(evaluationSuiteConfig.tenantId, params.scopes.tenantId), eq(evaluationSuiteConfig.projectId, params.scopes.projectId)));
138
+ return await db.select().from(evaluationSuiteConfig).where(projectScopedWhere(evaluationSuiteConfig, params.scopes));
138
139
  };
139
140
  const createEvaluationSuiteConfig = (db) => async (data) => {
140
141
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -148,14 +149,14 @@ const createEvaluationSuiteConfig = (db) => async (data) => {
148
149
  const updateEvaluationSuiteConfig = (db) => async (params) => {
149
150
  const updateData = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
150
151
  for (const [key, value] of Object.entries(params.data)) if (value !== void 0) updateData[key] = value;
151
- const [updated] = await db.update(evaluationSuiteConfig).set(updateData).where(and(eq(evaluationSuiteConfig.tenantId, params.scopes.tenantId), eq(evaluationSuiteConfig.projectId, params.scopes.projectId), eq(evaluationSuiteConfig.id, params.scopes.evaluationSuiteConfigId))).returning();
152
+ const [updated] = await db.update(evaluationSuiteConfig).set(updateData).where(and(projectScopedWhere(evaluationSuiteConfig, params.scopes), eq(evaluationSuiteConfig.id, params.scopes.evaluationSuiteConfigId))).returning();
152
153
  return updated ?? null;
153
154
  };
154
155
  const deleteEvaluationSuiteConfig = (db) => async (params) => {
155
- return (await db.delete(evaluationSuiteConfig).where(and(eq(evaluationSuiteConfig.tenantId, params.scopes.tenantId), eq(evaluationSuiteConfig.projectId, params.scopes.projectId), eq(evaluationSuiteConfig.id, params.scopes.evaluationSuiteConfigId))).returning()).length > 0;
156
+ return (await db.delete(evaluationSuiteConfig).where(and(projectScopedWhere(evaluationSuiteConfig, params.scopes), eq(evaluationSuiteConfig.id, params.scopes.evaluationSuiteConfigId))).returning()).length > 0;
156
157
  };
157
158
  const getEvaluationSuiteConfigEvaluatorRelations = (db) => async (params) => {
158
- return await db.select().from(evaluationSuiteConfigEvaluatorRelations).where(and(eq(evaluationSuiteConfigEvaluatorRelations.tenantId, params.scopes.tenantId), eq(evaluationSuiteConfigEvaluatorRelations.projectId, params.scopes.projectId), eq(evaluationSuiteConfigEvaluatorRelations.evaluationSuiteConfigId, params.scopes.evaluationSuiteConfigId)));
159
+ return await db.select().from(evaluationSuiteConfigEvaluatorRelations).where(and(projectScopedWhere(evaluationSuiteConfigEvaluatorRelations, params.scopes), eq(evaluationSuiteConfigEvaluatorRelations.evaluationSuiteConfigId, params.scopes.evaluationSuiteConfigId)));
159
160
  };
160
161
  const createEvaluationSuiteConfigEvaluatorRelation = (db) => async (data) => {
161
162
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -167,22 +168,22 @@ const createEvaluationSuiteConfigEvaluatorRelation = (db) => async (data) => {
167
168
  return created;
168
169
  };
169
170
  const deleteEvaluationSuiteConfigEvaluatorRelation = (db) => async (params) => {
170
- return (await db.delete(evaluationSuiteConfigEvaluatorRelations).where(and(eq(evaluationSuiteConfigEvaluatorRelations.tenantId, params.scopes.tenantId), eq(evaluationSuiteConfigEvaluatorRelations.projectId, params.scopes.projectId), eq(evaluationSuiteConfigEvaluatorRelations.evaluationSuiteConfigId, params.scopes.evaluationSuiteConfigId), eq(evaluationSuiteConfigEvaluatorRelations.evaluatorId, params.scopes.evaluatorId))).returning()).length > 0;
171
+ return (await db.delete(evaluationSuiteConfigEvaluatorRelations).where(and(projectScopedWhere(evaluationSuiteConfigEvaluatorRelations, params.scopes), eq(evaluationSuiteConfigEvaluatorRelations.evaluationSuiteConfigId, params.scopes.evaluationSuiteConfigId), eq(evaluationSuiteConfigEvaluatorRelations.evaluatorId, params.scopes.evaluatorId))).returning()).length > 0;
171
172
  };
172
173
  const deleteEvaluationSuiteConfigEvaluatorRelationsByEvaluator = (db) => async (params) => {
173
- return (await db.delete(evaluationSuiteConfigEvaluatorRelations).where(and(eq(evaluationSuiteConfigEvaluatorRelations.tenantId, params.scopes.tenantId), eq(evaluationSuiteConfigEvaluatorRelations.projectId, params.scopes.projectId), eq(evaluationSuiteConfigEvaluatorRelations.evaluatorId, params.scopes.evaluatorId))).returning()).length;
174
+ return (await db.delete(evaluationSuiteConfigEvaluatorRelations).where(and(projectScopedWhere(evaluationSuiteConfigEvaluatorRelations, params.scopes), eq(evaluationSuiteConfigEvaluatorRelations.evaluatorId, params.scopes.evaluatorId))).returning()).length;
174
175
  };
175
176
  const getEvaluationRunConfigById = (db) => async (params) => {
176
- return (await db.select().from(evaluationRunConfig).where(and(eq(evaluationRunConfig.tenantId, params.scopes.tenantId), eq(evaluationRunConfig.projectId, params.scopes.projectId), eq(evaluationRunConfig.id, params.scopes.evaluationRunConfigId))).limit(1))[0] ?? null;
177
+ return (await db.select().from(evaluationRunConfig).where(and(projectScopedWhere(evaluationRunConfig, params.scopes), eq(evaluationRunConfig.id, params.scopes.evaluationRunConfigId))).limit(1))[0] ?? null;
177
178
  };
178
179
  const listEvaluationRunConfigs = (db) => async (params) => {
179
- return await db.select().from(evaluationRunConfig).where(and(eq(evaluationRunConfig.tenantId, params.scopes.tenantId), eq(evaluationRunConfig.projectId, params.scopes.projectId)));
180
+ return await db.select().from(evaluationRunConfig).where(projectScopedWhere(evaluationRunConfig, params.scopes));
180
181
  };
181
182
  const listEvaluationRunConfigsWithSuiteConfigs = (db) => async (params) => {
182
183
  const rows = await db.select({
183
184
  runConfig: evaluationRunConfig,
184
185
  suiteConfigId: evaluationRunConfigEvaluationSuiteConfigRelations.evaluationSuiteConfigId
185
- }).from(evaluationRunConfig).leftJoin(evaluationRunConfigEvaluationSuiteConfigRelations, and(eq(evaluationRunConfigEvaluationSuiteConfigRelations.tenantId, evaluationRunConfig.tenantId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.projectId, evaluationRunConfig.projectId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.evaluationRunConfigId, evaluationRunConfig.id))).where(and(eq(evaluationRunConfig.tenantId, params.scopes.tenantId), eq(evaluationRunConfig.projectId, params.scopes.projectId)));
186
+ }).from(evaluationRunConfig).leftJoin(evaluationRunConfigEvaluationSuiteConfigRelations, and(eq(evaluationRunConfigEvaluationSuiteConfigRelations.tenantId, evaluationRunConfig.tenantId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.projectId, evaluationRunConfig.projectId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.evaluationRunConfigId, evaluationRunConfig.id))).where(projectScopedWhere(evaluationRunConfig, params.scopes));
186
187
  const runConfigsById = /* @__PURE__ */ new Map();
187
188
  for (const row of rows) {
188
189
  const runConfig = row.runConfig;
@@ -210,14 +211,14 @@ const createEvaluationRunConfig = (db) => async (data) => {
210
211
  const updateEvaluationRunConfig = (db) => async (params) => {
211
212
  const updateData = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
212
213
  for (const [key, value] of Object.entries(params.data)) if (value !== void 0) updateData[key] = value;
213
- const [updated] = await db.update(evaluationRunConfig).set(updateData).where(and(eq(evaluationRunConfig.tenantId, params.scopes.tenantId), eq(evaluationRunConfig.projectId, params.scopes.projectId), eq(evaluationRunConfig.id, params.scopes.evaluationRunConfigId))).returning();
214
+ const [updated] = await db.update(evaluationRunConfig).set(updateData).where(and(projectScopedWhere(evaluationRunConfig, params.scopes), eq(evaluationRunConfig.id, params.scopes.evaluationRunConfigId))).returning();
214
215
  return updated ?? null;
215
216
  };
216
217
  const deleteEvaluationRunConfig = (db) => async (params) => {
217
- return (await db.delete(evaluationRunConfig).where(and(eq(evaluationRunConfig.tenantId, params.scopes.tenantId), eq(evaluationRunConfig.projectId, params.scopes.projectId), eq(evaluationRunConfig.id, params.scopes.evaluationRunConfigId))).returning()).length > 0;
218
+ return (await db.delete(evaluationRunConfig).where(and(projectScopedWhere(evaluationRunConfig, params.scopes), eq(evaluationRunConfig.id, params.scopes.evaluationRunConfigId))).returning()).length > 0;
218
219
  };
219
220
  const getEvaluationRunConfigEvaluationSuiteConfigRelations = (db) => async (params) => {
220
- return await db.select().from(evaluationRunConfigEvaluationSuiteConfigRelations).where(and(eq(evaluationRunConfigEvaluationSuiteConfigRelations.tenantId, params.scopes.tenantId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.projectId, params.scopes.projectId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.evaluationRunConfigId, params.scopes.evaluationRunConfigId)));
221
+ return await db.select().from(evaluationRunConfigEvaluationSuiteConfigRelations).where(and(projectScopedWhere(evaluationRunConfigEvaluationSuiteConfigRelations, params.scopes), eq(evaluationRunConfigEvaluationSuiteConfigRelations.evaluationRunConfigId, params.scopes.evaluationRunConfigId)));
221
222
  };
222
223
  const createEvaluationRunConfigEvaluationSuiteConfigRelation = (db) => async (data) => {
223
224
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -229,13 +230,13 @@ const createEvaluationRunConfigEvaluationSuiteConfigRelation = (db) => async (da
229
230
  return created;
230
231
  };
231
232
  const deleteEvaluationRunConfigEvaluationSuiteConfigRelation = (db) => async (params) => {
232
- return (await db.delete(evaluationRunConfigEvaluationSuiteConfigRelations).where(and(eq(evaluationRunConfigEvaluationSuiteConfigRelations.tenantId, params.scopes.tenantId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.projectId, params.scopes.projectId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.evaluationRunConfigId, params.scopes.evaluationRunConfigId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.evaluationSuiteConfigId, params.scopes.evaluationSuiteConfigId))).returning()).length > 0;
233
+ return (await db.delete(evaluationRunConfigEvaluationSuiteConfigRelations).where(and(projectScopedWhere(evaluationRunConfigEvaluationSuiteConfigRelations, params.scopes), eq(evaluationRunConfigEvaluationSuiteConfigRelations.evaluationRunConfigId, params.scopes.evaluationRunConfigId), eq(evaluationRunConfigEvaluationSuiteConfigRelations.evaluationSuiteConfigId, params.scopes.evaluationSuiteConfigId))).returning()).length > 0;
233
234
  };
234
235
  const getEvaluationJobConfigById = (db) => async (params) => {
235
- return (await db.select().from(evaluationJobConfig).where(and(eq(evaluationJobConfig.tenantId, params.scopes.tenantId), eq(evaluationJobConfig.projectId, params.scopes.projectId), eq(evaluationJobConfig.id, params.scopes.evaluationJobConfigId))).limit(1))[0] ?? null;
236
+ return (await db.select().from(evaluationJobConfig).where(and(projectScopedWhere(evaluationJobConfig, params.scopes), eq(evaluationJobConfig.id, params.scopes.evaluationJobConfigId))).limit(1))[0] ?? null;
236
237
  };
237
238
  const listEvaluationJobConfigs = (db) => async (params) => {
238
- return await db.select().from(evaluationJobConfig).where(and(eq(evaluationJobConfig.tenantId, params.scopes.tenantId), eq(evaluationJobConfig.projectId, params.scopes.projectId)));
239
+ return await db.select().from(evaluationJobConfig).where(projectScopedWhere(evaluationJobConfig, params.scopes));
239
240
  };
240
241
  const createEvaluationJobConfig = (db) => async (data) => {
241
242
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -247,10 +248,10 @@ const createEvaluationJobConfig = (db) => async (data) => {
247
248
  return created;
248
249
  };
249
250
  const deleteEvaluationJobConfig = (db) => async (params) => {
250
- return (await db.delete(evaluationJobConfig).where(and(eq(evaluationJobConfig.tenantId, params.scopes.tenantId), eq(evaluationJobConfig.projectId, params.scopes.projectId), eq(evaluationJobConfig.id, params.scopes.evaluationJobConfigId))).returning()).length > 0;
251
+ return (await db.delete(evaluationJobConfig).where(and(projectScopedWhere(evaluationJobConfig, params.scopes), eq(evaluationJobConfig.id, params.scopes.evaluationJobConfigId))).returning()).length > 0;
251
252
  };
252
253
  const getEvaluationJobConfigEvaluatorRelations = (db) => async (params) => {
253
- return await db.select().from(evaluationJobConfigEvaluatorRelations).where(and(eq(evaluationJobConfigEvaluatorRelations.tenantId, params.scopes.tenantId), eq(evaluationJobConfigEvaluatorRelations.projectId, params.scopes.projectId), eq(evaluationJobConfigEvaluatorRelations.evaluationJobConfigId, params.scopes.evaluationJobConfigId)));
254
+ return await db.select().from(evaluationJobConfigEvaluatorRelations).where(and(projectScopedWhere(evaluationJobConfigEvaluatorRelations, params.scopes), eq(evaluationJobConfigEvaluatorRelations.evaluationJobConfigId, params.scopes.evaluationJobConfigId)));
254
255
  };
255
256
  const createEvaluationJobConfigEvaluatorRelation = (db) => async (data) => {
256
257
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -262,13 +263,13 @@ const createEvaluationJobConfigEvaluatorRelation = (db) => async (data) => {
262
263
  return created;
263
264
  };
264
265
  const deleteEvaluationJobConfigEvaluatorRelation = (db) => async (params) => {
265
- return (await db.delete(evaluationJobConfigEvaluatorRelations).where(and(eq(evaluationJobConfigEvaluatorRelations.tenantId, params.scopes.tenantId), eq(evaluationJobConfigEvaluatorRelations.projectId, params.scopes.projectId), eq(evaluationJobConfigEvaluatorRelations.evaluationJobConfigId, params.scopes.evaluationJobConfigId), eq(evaluationJobConfigEvaluatorRelations.evaluatorId, params.scopes.evaluatorId))).returning()).length > 0;
266
+ return (await db.delete(evaluationJobConfigEvaluatorRelations).where(and(projectScopedWhere(evaluationJobConfigEvaluatorRelations, params.scopes), eq(evaluationJobConfigEvaluatorRelations.evaluationJobConfigId, params.scopes.evaluationJobConfigId), eq(evaluationJobConfigEvaluatorRelations.evaluatorId, params.scopes.evaluatorId))).returning()).length > 0;
266
267
  };
267
268
  const deleteEvaluationJobConfigEvaluatorRelationsByEvaluator = (db) => async (params) => {
268
- return (await db.delete(evaluationJobConfigEvaluatorRelations).where(and(eq(evaluationJobConfigEvaluatorRelations.tenantId, params.scopes.tenantId), eq(evaluationJobConfigEvaluatorRelations.projectId, params.scopes.projectId), eq(evaluationJobConfigEvaluatorRelations.evaluatorId, params.scopes.evaluatorId))).returning()).length;
269
+ return (await db.delete(evaluationJobConfigEvaluatorRelations).where(and(projectScopedWhere(evaluationJobConfigEvaluatorRelations, params.scopes), eq(evaluationJobConfigEvaluatorRelations.evaluatorId, params.scopes.evaluatorId))).returning()).length;
269
270
  };
270
271
  const linkDatasetRunToEvaluationJobConfig = (db) => async (params) => {
271
- await db.update(datasetRun).set({ evaluationJobConfigId: params.evaluationJobConfigId }).where(and(eq(datasetRun.tenantId, params.scopes.tenantId), eq(datasetRun.projectId, params.scopes.projectId), eq(datasetRun.id, params.scopes.datasetRunId)));
272
+ await db.update(datasetRun).set({ evaluationJobConfigId: params.evaluationJobConfigId }).where(and(projectScopedWhere(datasetRun, params.scopes), eq(datasetRun.id, params.scopes.datasetRunId)));
272
273
  };
273
274
 
274
275
  //#endregion
@@ -1,4 +1,5 @@
1
1
  import { externalAgents } from "../../db/manage/manage-schema.js";
2
+ import { projectScopedWhere } from "./scope-helpers.js";
2
3
  import { and, asc, count, desc, eq } from "drizzle-orm";
3
4
 
4
5
  //#region src/data-access/manage/externalAgents.ts
@@ -12,20 +13,20 @@ const createExternalAgent = (db) => async (params) => {
12
13
  * Get external agent by ID
13
14
  */
14
15
  const getExternalAgent = (db) => async (params) => {
15
- return await db.query.externalAgents.findFirst({ where: and(eq(externalAgents.tenantId, params.scopes.tenantId), eq(externalAgents.projectId, params.scopes.projectId), eq(externalAgents.id, params.externalAgentId)) }) || null;
16
+ return await db.query.externalAgents.findFirst({ where: and(projectScopedWhere(externalAgents, params.scopes), eq(externalAgents.id, params.externalAgentId)) }) || null;
16
17
  };
17
18
  /**
18
19
  * Get external agent by base URL
19
20
  */
20
21
  const getExternalAgentByUrl = (db) => async (params) => {
21
- return await db.query.externalAgents.findFirst({ where: and(eq(externalAgents.tenantId, params.scopes.tenantId), eq(externalAgents.projectId, params.scopes.projectId), eq(externalAgents.baseUrl, params.baseUrl)) }) || null;
22
+ return await db.query.externalAgents.findFirst({ where: and(projectScopedWhere(externalAgents, params.scopes), eq(externalAgents.baseUrl, params.baseUrl)) }) || null;
22
23
  };
23
24
  /**
24
25
  * List external agents for a project
25
26
  */
26
27
  const listExternalAgents = (db) => async (params) => {
27
28
  return await db.query.externalAgents.findMany({
28
- where: and(eq(externalAgents.tenantId, params.scopes.tenantId), eq(externalAgents.projectId, params.scopes.projectId)),
29
+ where: projectScopedWhere(externalAgents, params.scopes),
29
30
  orderBy: [asc(externalAgents.name)]
30
31
  });
31
32
  };
@@ -36,7 +37,7 @@ const listExternalAgentsPaginated = (db) => async (params) => {
36
37
  const page = params.pagination?.page || 1;
37
38
  const limit = Math.min(params.pagination?.limit || 10, 100);
38
39
  const offset = (page - 1) * limit;
39
- const [data, totalResult] = await Promise.all([db.select().from(externalAgents).where(and(eq(externalAgents.tenantId, params.scopes.tenantId), eq(externalAgents.projectId, params.scopes.projectId))).limit(limit).offset(offset).orderBy(desc(externalAgents.createdAt)), db.select({ count: count() }).from(externalAgents).where(and(eq(externalAgents.tenantId, params.scopes.tenantId), eq(externalAgents.projectId, params.scopes.projectId)))]);
40
+ const [data, totalResult] = await Promise.all([db.select().from(externalAgents).where(projectScopedWhere(externalAgents, params.scopes)).limit(limit).offset(offset).orderBy(desc(externalAgents.createdAt)), db.select({ count: count() }).from(externalAgents).where(projectScopedWhere(externalAgents, params.scopes))]);
40
41
  const total = typeof totalResult[0]?.count === "string" ? parseInt(totalResult[0].count, 10) : totalResult[0]?.count || 0;
41
42
  return {
42
43
  data,
@@ -58,7 +59,7 @@ const updateExternalAgent = (db) => async (params) => {
58
59
  };
59
60
  if (Object.keys(updateData).length === 1) throw new Error("No fields to update");
60
61
  if (updateData.credentialReferenceId === void 0) updateData.credentialReferenceId = null;
61
- return (await db.update(externalAgents).set(updateData).where(and(eq(externalAgents.tenantId, params.scopes.tenantId), eq(externalAgents.projectId, params.scopes.projectId), eq(externalAgents.id, params.externalAgentId))).returning())[0] || null;
62
+ return (await db.update(externalAgents).set(updateData).where(and(projectScopedWhere(externalAgents, params.scopes), eq(externalAgents.id, params.externalAgentId))).returning())[0] || null;
62
63
  };
63
64
  /**
64
65
  * Upsert external agent (create if it doesn't exist, update if it does)
@@ -92,7 +93,7 @@ const upsertExternalAgent = (db) => async (params) => {
92
93
  */
93
94
  const deleteExternalAgent = (db) => async (params) => {
94
95
  try {
95
- return (await db.delete(externalAgents).where(and(eq(externalAgents.tenantId, params.scopes.tenantId), eq(externalAgents.projectId, params.scopes.projectId), eq(externalAgents.id, params.externalAgentId))).returning()).length > 0;
96
+ return (await db.delete(externalAgents).where(and(projectScopedWhere(externalAgents, params.scopes), eq(externalAgents.id, params.externalAgentId))).returning()).length > 0;
96
97
  } catch (error) {
97
98
  console.error("Error deleting external agent:", error);
98
99
  return false;
@@ -114,7 +115,7 @@ const externalAgentUrlExists = (db) => async (params) => {
114
115
  * Count external agents for a project
115
116
  */
116
117
  const countExternalAgents = (db) => async (params) => {
117
- const countValue = (await db.select({ count: count() }).from(externalAgents).where(and(eq(externalAgents.tenantId, params.scopes.tenantId), eq(externalAgents.projectId, params.scopes.projectId))))[0]?.count;
118
+ const countValue = (await db.select({ count: count() }).from(externalAgents).where(projectScopedWhere(externalAgents, params.scopes)))[0]?.count;
118
119
  return typeof countValue === "string" ? parseInt(countValue, 10) : countValue || 0;
119
120
  };
120
121