@inkeep/agents-core 0.58.14 → 0.58.16

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 (75) 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.js +17 -45
  4. package/dist/data-access/index.d.ts +5 -2
  5. package/dist/data-access/index.js +5 -2
  6. package/dist/data-access/manage/agentFull.js +28 -12
  7. package/dist/data-access/manage/agents.d.ts +35 -34
  8. package/dist/data-access/manage/agents.js +33 -33
  9. package/dist/data-access/manage/artifactComponents.d.ts +12 -12
  10. package/dist/data-access/manage/artifactComponents.js +14 -13
  11. package/dist/data-access/manage/audit-queries.js +6 -5
  12. package/dist/data-access/manage/contextConfigs.d.ts +12 -12
  13. package/dist/data-access/manage/contextConfigs.js +7 -6
  14. package/dist/data-access/manage/credentialReferences.js +12 -11
  15. package/dist/data-access/manage/dataComponents.d.ts +6 -6
  16. package/dist/data-access/manage/dataComponents.js +13 -11
  17. package/dist/data-access/manage/evalConfig.js +42 -41
  18. package/dist/data-access/manage/externalAgents.js +8 -7
  19. package/dist/data-access/manage/functionTools.d.ts +17 -21
  20. package/dist/data-access/manage/functionTools.js +27 -65
  21. package/dist/data-access/manage/functions.js +7 -10
  22. package/dist/data-access/manage/projects.js +37 -36
  23. package/dist/data-access/manage/scheduledTriggers.js +10 -6
  24. package/dist/data-access/manage/scheduledWorkflows.js +3 -2
  25. package/dist/data-access/manage/scope-helpers.d.ts +2 -1
  26. package/dist/data-access/manage/scope-helpers.js +2 -1
  27. package/dist/data-access/manage/skills.d.ts +14 -14
  28. package/dist/data-access/manage/skills.js +14 -9
  29. package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +24 -24
  30. package/dist/data-access/manage/subAgentRelations.d.ts +28 -28
  31. package/dist/data-access/manage/subAgentRelations.js +28 -26
  32. package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +24 -24
  33. package/dist/data-access/manage/subAgentTeamAgentRelations.js +16 -16
  34. package/dist/data-access/manage/subAgents.d.ts +18 -18
  35. package/dist/data-access/manage/subAgents.js +8 -7
  36. package/dist/data-access/manage/tools.d.ts +24 -24
  37. package/dist/data-access/manage/tools.js +8 -6
  38. package/dist/data-access/manage/triggers.js +12 -8
  39. package/dist/data-access/runtime/apiKeys.d.ts +20 -20
  40. package/dist/data-access/runtime/apiKeys.js +16 -12
  41. package/dist/data-access/runtime/apps.d.ts +10 -10
  42. package/dist/data-access/runtime/apps.js +8 -7
  43. package/dist/data-access/runtime/audit-queries.js +7 -7
  44. package/dist/data-access/runtime/auth.d.ts +18 -0
  45. package/dist/data-access/runtime/auth.js +35 -0
  46. package/dist/data-access/runtime/cascade-delete.js +29 -24
  47. package/dist/data-access/runtime/contextCache.d.ts +1 -0
  48. package/dist/data-access/runtime/contextCache.js +9 -8
  49. package/dist/data-access/runtime/conversations.d.ts +27 -27
  50. package/dist/data-access/runtime/conversations.js +8 -12
  51. package/dist/data-access/runtime/evalRuns.js +23 -22
  52. package/dist/data-access/runtime/github-work-app-installations.js +32 -21
  53. package/dist/data-access/runtime/ledgerArtifacts.js +9 -24
  54. package/dist/data-access/runtime/messages.d.ts +24 -19
  55. package/dist/data-access/runtime/messages.js +15 -9
  56. package/dist/data-access/runtime/projects.js +6 -5
  57. package/dist/data-access/runtime/scheduledTriggerInvocations.js +16 -26
  58. package/dist/data-access/runtime/slack-work-app-mcp.js +6 -5
  59. package/dist/data-access/runtime/tasks.d.ts +10 -6
  60. package/dist/data-access/runtime/tasks.js +4 -5
  61. package/dist/data-access/runtime/triggerInvocations.js +4 -8
  62. package/dist/data-access/runtime/workAppSlack.js +21 -14
  63. package/dist/db/manage/manage-schema.d.ts +357 -357
  64. package/dist/db/runtime/runtime-schema.d.ts +300 -300
  65. package/dist/index.d.ts +7 -3
  66. package/dist/index.js +8 -2
  67. package/dist/retry/index.d.ts +3 -0
  68. package/dist/retry/index.js +4 -0
  69. package/dist/retry/retryable-errors.d.ts +10 -0
  70. package/dist/retry/retryable-errors.js +72 -0
  71. package/dist/retry/withRetry.d.ts +15 -0
  72. package/dist/retry/withRetry.js +37 -0
  73. package/dist/validation/dolt-schemas.d.ts +1 -1
  74. package/dist/validation/schemas.d.ts +1704 -1704
  75. package/package.json +1 -1
@@ -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
 
@@ -55,12 +55,12 @@ declare const createFunctionTool: (db: AgentsManageDatabaseClient) => (params: {
55
55
  }) => Promise<{
56
56
  id: string;
57
57
  name: string;
58
- createdAt: string;
59
- updatedAt: string;
60
58
  description: string | null;
61
- projectId: string;
62
59
  tenantId: string;
60
+ projectId: string;
63
61
  agentId: string;
62
+ createdAt: string;
63
+ updatedAt: string;
64
64
  functionId: string;
65
65
  }>;
66
66
  /**
@@ -97,20 +97,16 @@ declare const upsertFunctionTool: (db: AgentsManageDatabaseClient) => (params: {
97
97
  }) => Promise<{
98
98
  id: string;
99
99
  name: string;
100
- createdAt: string;
101
- updatedAt: string;
102
100
  description: string | null;
103
- projectId: string;
104
101
  tenantId: string;
102
+ projectId: string;
105
103
  agentId: string;
104
+ createdAt: string;
105
+ updatedAt: string;
106
106
  functionId: string;
107
107
  }>;
108
108
  declare const getFunctionToolsForSubAgent: (db: AgentsManageDatabaseClient) => (params: {
109
- scopes: {
110
- tenantId: string;
111
- projectId: string;
112
- agentId: string;
113
- };
109
+ scopes: AgentScopeConfig;
114
110
  subAgentId: string;
115
111
  pagination?: PaginationConfig;
116
112
  }) => Promise<{
@@ -162,16 +158,16 @@ declare const addFunctionToolToSubAgent: (db: AgentsManageDatabaseClient) => (pa
162
158
  }> | null;
163
159
  }) => Promise<{
164
160
  id: string;
165
- createdAt: string;
166
- updatedAt: string;
167
- subAgentId: string;
168
- projectId: string;
169
161
  tenantId: string;
162
+ projectId: string;
170
163
  agentId: string;
171
- functionToolId: string;
164
+ createdAt: string;
165
+ updatedAt: string;
172
166
  toolPolicies: Record<string, {
173
167
  needsApproval?: boolean;
174
168
  }> | null;
169
+ subAgentId: string;
170
+ functionToolId: string;
175
171
  }>;
176
172
  /**
177
173
  * Update an agent-function tool relation
@@ -227,16 +223,16 @@ declare const associateFunctionToolWithSubAgent: (db: AgentsManageDatabaseClient
227
223
  }> | null;
228
224
  }) => Promise<{
229
225
  id: string;
230
- createdAt: string;
231
- updatedAt: string;
232
- subAgentId: string;
233
- projectId: string;
234
226
  tenantId: string;
227
+ projectId: string;
235
228
  agentId: string;
236
- functionToolId: string;
229
+ createdAt: string;
230
+ updatedAt: string;
237
231
  toolPolicies: Record<string, {
238
232
  needsApproval?: boolean;
239
233
  }> | null;
234
+ subAgentId: string;
235
+ functionToolId: string;
240
236
  }>;
241
237
  //#endregion
242
238
  export { addFunctionToolToSubAgent, associateFunctionToolWithSubAgent, createFunctionTool, deleteFunctionTool, getFunctionToolById, getFunctionToolsForSubAgent, getSubAgentsUsingFunctionTool, isFunctionToolAssociatedWithSubAgent, listFunctionTools, removeFunctionToolFromSubAgent, updateFunctionTool, updateSubAgentFunctionToolRelation, upsertFunctionTool, upsertSubAgentFunctionToolRelation };