@inkeep/agents-core 0.58.13 → 0.58.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/auth/auth-schema.d.ts +107 -107
  2. package/dist/auth/auth-validation-schemas.d.ts +152 -152
  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 +6 -1
  7. package/dist/data-access/index.js +6 -1
  8. package/dist/data-access/manage/agentFull.js +28 -12
  9. package/dist/data-access/manage/agents.d.ts +40 -39
  10. package/dist/data-access/manage/agents.js +33 -33
  11. package/dist/data-access/manage/artifactComponents.d.ts +8 -8
  12. package/dist/data-access/manage/artifactComponents.js +14 -13
  13. package/dist/data-access/manage/audit-queries.d.ts +29 -0
  14. package/dist/data-access/manage/audit-queries.js +30 -0
  15. package/dist/data-access/manage/contextConfigs.d.ts +4 -4
  16. package/dist/data-access/manage/contextConfigs.js +7 -6
  17. package/dist/data-access/manage/credentialReferences.js +12 -11
  18. package/dist/data-access/manage/dataComponents.d.ts +4 -4
  19. package/dist/data-access/manage/dataComponents.js +13 -11
  20. package/dist/data-access/manage/evalConfig.js +42 -41
  21. package/dist/data-access/manage/externalAgents.js +8 -7
  22. package/dist/data-access/manage/functionTools.d.ts +11 -15
  23. package/dist/data-access/manage/functionTools.js +27 -65
  24. package/dist/data-access/manage/functions.js +7 -10
  25. package/dist/data-access/manage/projects.js +37 -36
  26. package/dist/data-access/manage/scheduledTriggers.js +10 -6
  27. package/dist/data-access/manage/scheduledWorkflows.js +3 -2
  28. package/dist/data-access/manage/scope-helpers.d.ts +2 -1
  29. package/dist/data-access/manage/scope-helpers.js +2 -1
  30. package/dist/data-access/manage/skills.d.ts +11 -11
  31. package/dist/data-access/manage/skills.js +14 -9
  32. package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +12 -12
  33. package/dist/data-access/manage/subAgentRelations.d.ts +18 -18
  34. package/dist/data-access/manage/subAgentRelations.js +28 -26
  35. package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +12 -12
  36. package/dist/data-access/manage/subAgentTeamAgentRelations.js +16 -16
  37. package/dist/data-access/manage/subAgents.d.ts +21 -21
  38. package/dist/data-access/manage/subAgents.js +8 -7
  39. package/dist/data-access/manage/tools.d.ts +15 -15
  40. package/dist/data-access/manage/tools.js +8 -6
  41. package/dist/data-access/manage/triggers.d.ts +2 -2
  42. package/dist/data-access/manage/triggers.js +12 -8
  43. package/dist/data-access/runtime/apiKeys.d.ts +16 -16
  44. package/dist/data-access/runtime/apiKeys.js +16 -12
  45. package/dist/data-access/runtime/apps.d.ts +6 -6
  46. package/dist/data-access/runtime/apps.js +8 -7
  47. package/dist/data-access/runtime/audit-queries.d.ts +41 -0
  48. package/dist/data-access/runtime/audit-queries.js +37 -0
  49. package/dist/data-access/runtime/auth.d.ts +18 -0
  50. package/dist/data-access/runtime/auth.js +35 -0
  51. package/dist/data-access/runtime/cascade-delete.js +29 -24
  52. package/dist/data-access/runtime/contextCache.d.ts +1 -0
  53. package/dist/data-access/runtime/contextCache.js +9 -8
  54. package/dist/data-access/runtime/conversations.d.ts +16 -16
  55. package/dist/data-access/runtime/conversations.js +8 -12
  56. package/dist/data-access/runtime/evalRuns.js +23 -22
  57. package/dist/data-access/runtime/github-work-app-installations.js +32 -21
  58. package/dist/data-access/runtime/ledgerArtifacts.js +9 -24
  59. package/dist/data-access/runtime/messages.d.ts +21 -21
  60. package/dist/data-access/runtime/messages.js +9 -8
  61. package/dist/data-access/runtime/projects.js +6 -5
  62. package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +3 -3
  63. package/dist/data-access/runtime/scheduledTriggerInvocations.js +16 -26
  64. package/dist/data-access/runtime/slack-work-app-mcp.js +6 -5
  65. package/dist/data-access/runtime/tasks.d.ts +9 -5
  66. package/dist/data-access/runtime/tasks.js +4 -5
  67. package/dist/data-access/runtime/triggerInvocations.js +4 -8
  68. package/dist/data-access/runtime/workAppSlack.js +21 -14
  69. package/dist/data-reconciliation/audit.d.ts +6 -0
  70. package/dist/data-reconciliation/audit.js +37 -0
  71. package/dist/data-reconciliation/index.d.ts +4 -0
  72. package/dist/data-reconciliation/index.js +5 -0
  73. package/dist/data-reconciliation/reconcile.d.ts +6 -0
  74. package/dist/data-reconciliation/reconcile.js +58 -0
  75. package/dist/data-reconciliation/types.d.ts +116 -0
  76. package/dist/data-reconciliation/types.js +7 -0
  77. package/dist/db/manage/manage-schema.d.ts +453 -453
  78. package/dist/db/runtime/runtime-schema.d.ts +326 -326
  79. package/dist/index.d.ts +12 -2
  80. package/dist/index.js +12 -1
  81. package/dist/retry/index.d.ts +3 -0
  82. package/dist/retry/index.js +4 -0
  83. package/dist/retry/retryable-errors.d.ts +10 -0
  84. package/dist/retry/retryable-errors.js +72 -0
  85. package/dist/retry/withRetry.d.ts +15 -0
  86. package/dist/retry/withRetry.js +37 -0
  87. package/dist/setup/setup.d.ts +1 -0
  88. package/dist/setup/setup.js +25 -8
  89. package/dist/utils/error.d.ts +51 -51
  90. package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
  91. package/dist/validation/schemas.d.ts +1987 -1990
  92. package/dist/validation/schemas.js +5 -1
  93. package/package.json +1 -1
@@ -8,49 +8,49 @@ declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
8
8
  scopes: ProjectScopeConfig;
9
9
  id: string;
10
10
  }) => Promise<{
11
- id: string;
12
- name: string | null;
13
11
  tenantId: string;
14
12
  projectId: string;
15
13
  agentId: string;
14
+ id: string;
15
+ name: string | null;
16
16
  createdAt: string;
17
17
  updatedAt: string;
18
+ expiresAt: string | null;
18
19
  publicId: string;
19
20
  keyHash: string;
20
21
  keyPrefix: string;
21
22
  lastUsedAt: string | null;
22
- expiresAt: string | null;
23
23
  } | undefined>;
24
24
  declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: string) => Promise<{
25
- id: string;
26
- name: string | null;
27
25
  tenantId: string;
28
26
  projectId: string;
29
27
  agentId: string;
28
+ id: string;
29
+ name: string | null;
30
30
  createdAt: string;
31
31
  updatedAt: string;
32
+ expiresAt: string | null;
32
33
  publicId: string;
33
34
  keyHash: string;
34
35
  keyPrefix: string;
35
36
  lastUsedAt: string | null;
36
- expiresAt: string | null;
37
37
  } | undefined>;
38
38
  declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
39
39
  scopes: ProjectScopeConfig;
40
40
  agentId?: string;
41
41
  }) => Promise<{
42
- id: string;
43
- name: string | null;
44
42
  tenantId: string;
45
43
  projectId: string;
46
44
  agentId: string;
45
+ id: string;
46
+ name: string | null;
47
47
  createdAt: string;
48
48
  updatedAt: string;
49
+ expiresAt: string | null;
49
50
  publicId: string;
50
51
  keyHash: string;
51
52
  keyPrefix: string;
52
53
  lastUsedAt: string | null;
53
- expiresAt: string | null;
54
54
  }[]>;
55
55
  declare const listApiKeysPaginated: (db: AgentsRunDatabaseClient) => (params: {
56
56
  scopes: ProjectScopeConfig;
@@ -66,18 +66,18 @@ declare const listApiKeysPaginated: (db: AgentsRunDatabaseClient) => (params: {
66
66
  };
67
67
  }>;
68
68
  declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInsert) => Promise<{
69
- id: string;
70
- name: string | null;
71
69
  tenantId: string;
72
70
  projectId: string;
73
71
  agentId: string;
72
+ id: string;
73
+ name: string | null;
74
74
  createdAt: string;
75
75
  updatedAt: string;
76
+ expiresAt: string | null;
76
77
  publicId: string;
77
78
  keyHash: string;
78
79
  keyPrefix: string;
79
80
  lastUsedAt: string | null;
80
- expiresAt: string | null;
81
81
  }>;
82
82
  declare const updateApiKey: (db: AgentsRunDatabaseClient) => (params: {
83
83
  scopes: ProjectScopeConfig;
@@ -105,7 +105,10 @@ declare const hasApiKey: (db: AgentsRunDatabaseClient) => (params: {
105
105
  scopes: ProjectScopeConfig;
106
106
  id: string;
107
107
  }) => Promise<boolean>;
108
- declare const updateApiKeyLastUsed: (db: AgentsRunDatabaseClient) => (id: string) => Promise<void>;
108
+ declare const updateApiKeyLastUsed: (db: AgentsRunDatabaseClient) => (params: {
109
+ id: string;
110
+ scopes: ProjectScopeConfig;
111
+ }) => Promise<void>;
109
112
  declare const countApiKeys: (db: AgentsRunDatabaseClient) => (params: {
110
113
  scopes: ProjectScopeConfig;
111
114
  agentId?: string;
@@ -115,9 +118,6 @@ declare const countApiKeys: (db: AgentsRunDatabaseClient) => (params: {
115
118
  * Returns both the API key record and the full key (which should be shown to the user only once)
116
119
  */
117
120
  declare const generateAndCreateApiKey: (params: CreateApiKeyParams, db: AgentsRunDatabaseClient) => Promise<ApiKeyCreateResult>;
118
- /**
119
- * Validate an API key and return the associated record if valid
120
- */
121
121
  declare const validateAndGetApiKey: (key: string, db: AgentsRunDatabaseClient) => Promise<ApiKeySelect | null>;
122
122
  //#endregion
123
123
  export { countApiKeys, createApiKey, deleteApiKey, generateAndCreateApiKey, getApiKeyById, getApiKeyByPublicId, hasApiKey, listApiKeys, listApiKeysPaginated, updateApiKey, updateApiKeyLastUsed, validateAndGetApiKey };
@@ -1,16 +1,17 @@
1
1
  import { apiKeys } from "../../db/runtime/runtime-schema.js";
2
+ import { projectScopedWhere } from "../manage/scope-helpers.js";
2
3
  import { extractPublicId, generateApiKey, isApiKeyExpired, validateApiKey } from "../../utils/apiKeys.js";
3
4
  import { and, count, desc, eq } from "drizzle-orm";
4
5
 
5
6
  //#region src/data-access/runtime/apiKeys.ts
6
7
  const getApiKeyById = (db) => async (params) => {
7
- return await db.query.apiKeys.findFirst({ where: and(eq(apiKeys.tenantId, params.scopes.tenantId), eq(apiKeys.projectId, params.scopes.projectId), eq(apiKeys.id, params.id)) });
8
+ return await db.query.apiKeys.findFirst({ where: and(projectScopedWhere(apiKeys, params.scopes), eq(apiKeys.id, params.id)) });
8
9
  };
9
10
  const getApiKeyByPublicId = (db) => async (publicId) => {
10
11
  return await db.query.apiKeys.findFirst({ where: eq(apiKeys.publicId, publicId) });
11
12
  };
12
13
  const listApiKeys = (db) => async (params) => {
13
- const conditions = [eq(apiKeys.tenantId, params.scopes.tenantId), eq(apiKeys.projectId, params.scopes.projectId)];
14
+ const conditions = [projectScopedWhere(apiKeys, params.scopes)];
14
15
  if (params.agentId) conditions.push(eq(apiKeys.agentId, params.agentId));
15
16
  return await db.query.apiKeys.findMany({
16
17
  where: and(...conditions),
@@ -21,7 +22,7 @@ const listApiKeysPaginated = (db) => async (params) => {
21
22
  const page = params.pagination?.page || 1;
22
23
  const limit = Math.min(params.pagination?.limit || 10, 100);
23
24
  const offset = (page - 1) * limit;
24
- const conditions = [eq(apiKeys.tenantId, params.scopes.tenantId), eq(apiKeys.projectId, params.scopes.projectId)];
25
+ const conditions = [projectScopedWhere(apiKeys, params.scopes)];
25
26
  if (params.agentId) conditions.push(eq(apiKeys.agentId, params.agentId));
26
27
  const whereClause = and(...conditions);
27
28
  const [data, totalResult] = await Promise.all([db.select().from(apiKeys).where(whereClause).limit(limit).offset(offset).orderBy(desc(apiKeys.createdAt)), db.select({ count: count() }).from(apiKeys).where(whereClause)]);
@@ -60,7 +61,7 @@ const updateApiKey = (db) => async (params) => {
60
61
  name: params.data.name,
61
62
  expiresAt: params.data.expiresAt,
62
63
  updatedAt: now
63
- }).where(and(eq(apiKeys.tenantId, params.scopes.tenantId), eq(apiKeys.projectId, params.scopes.projectId), eq(apiKeys.id, params.id))).returning();
64
+ }).where(and(projectScopedWhere(apiKeys, params.scopes), eq(apiKeys.id, params.id))).returning();
64
65
  return updatedKey;
65
66
  };
66
67
  const deleteApiKey = (db) => async (params) => {
@@ -72,7 +73,7 @@ const deleteApiKey = (db) => async (params) => {
72
73
  console.error("API key not found", { params });
73
74
  return false;
74
75
  }
75
- await db.delete(apiKeys).where(and(eq(apiKeys.tenantId, params.scopes.tenantId), eq(apiKeys.projectId, params.scopes.projectId), eq(apiKeys.id, params.id)));
76
+ await db.delete(apiKeys).where(and(projectScopedWhere(apiKeys, params.scopes), eq(apiKeys.id, params.id)));
76
77
  return true;
77
78
  } catch (error) {
78
79
  console.error("Error deleting API key:", error);
@@ -82,11 +83,11 @@ const deleteApiKey = (db) => async (params) => {
82
83
  const hasApiKey = (db) => async (params) => {
83
84
  return await getApiKeyById(db)(params) !== null;
84
85
  };
85
- const updateApiKeyLastUsed = (db) => async (id) => {
86
- await db.update(apiKeys).set({ lastUsedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(eq(apiKeys.id, id));
86
+ const updateApiKeyLastUsed = (db) => async (params) => {
87
+ await db.update(apiKeys).set({ lastUsedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(and(projectScopedWhere(apiKeys, params.scopes), eq(apiKeys.id, params.id)));
87
88
  };
88
89
  const countApiKeys = (db) => async (params) => {
89
- const conditions = [eq(apiKeys.tenantId, params.scopes.tenantId), eq(apiKeys.projectId, params.scopes.projectId)];
90
+ const conditions = [projectScopedWhere(apiKeys, params.scopes)];
90
91
  if (params.agentId) conditions.push(eq(apiKeys.agentId, params.agentId));
91
92
  const total = (await db.select({ count: count() }).from(apiKeys).where(and(...conditions)))[0]?.count || 0;
92
93
  return typeof total === "string" ? Number.parseInt(total, 10) : total;
@@ -110,9 +111,6 @@ const generateAndCreateApiKey = async (params, db) => {
110
111
  key: keyData.key
111
112
  };
112
113
  };
113
- /**
114
- * Validate an API key and return the associated record if valid
115
- */
116
114
  const validateAndGetApiKey = async (key, db) => {
117
115
  const publicId = extractPublicId(key);
118
116
  if (!publicId) return null;
@@ -120,7 +118,13 @@ const validateAndGetApiKey = async (key, db) => {
120
118
  if (!apiKey) return null;
121
119
  if (!await validateApiKey(key, apiKey.keyHash)) return null;
122
120
  if (isApiKeyExpired(apiKey.expiresAt)) return null;
123
- await updateApiKeyLastUsed(db)(apiKey.id);
121
+ await updateApiKeyLastUsed(db)({
122
+ id: apiKey.id,
123
+ scopes: {
124
+ tenantId: apiKey.tenantId,
125
+ projectId: apiKey.projectId
126
+ }
127
+ });
124
128
  return apiKey;
125
129
  };
126
130
 
@@ -5,12 +5,12 @@ import { AppInsert, AppSelect, AppUpdate } from "../../types/entities.js";
5
5
 
6
6
  //#region src/data-access/runtime/apps.d.ts
7
7
  declare const getAppById: (db: AgentsRunDatabaseClient) => (id: string) => Promise<{
8
- id: string;
9
- name: string;
10
- description: string | null;
11
8
  tenantId: string | null;
12
9
  projectId: string | null;
10
+ id: string;
11
+ name: string;
13
12
  type: AppType;
13
+ description: string | null;
14
14
  createdAt: string;
15
15
  updatedAt: string;
16
16
  enabled: boolean;
@@ -48,12 +48,12 @@ declare const listAppsPaginated: (db: AgentsRunDatabaseClient) => (params: {
48
48
  };
49
49
  }>;
50
50
  declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) => Promise<{
51
- id: string;
52
- name: string;
53
- description: string | null;
54
51
  tenantId: string | null;
55
52
  projectId: string | null;
53
+ id: string;
54
+ name: string;
56
55
  type: AppType;
56
+ description: string | null;
57
57
  createdAt: string;
58
58
  updatedAt: string;
59
59
  enabled: boolean;
@@ -1,4 +1,5 @@
1
1
  import { apps } from "../../db/runtime/runtime-schema.js";
2
+ import { tenantScopedWhere } from "../manage/scope-helpers.js";
2
3
  import { and, count, desc, eq } from "drizzle-orm";
3
4
 
4
5
  //#region src/data-access/runtime/apps.ts
@@ -9,13 +10,13 @@ const updateAppLastUsed = (db) => async (id) => {
9
10
  await db.update(apps).set({ lastUsedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(eq(apps.id, id));
10
11
  };
11
12
  const getAppByIdForTenant = (db) => async (params) => {
12
- return db.query.apps.findFirst({ where: and(eq(apps.id, params.id), eq(apps.tenantId, params.scopes.tenantId)) });
13
+ return db.query.apps.findFirst({ where: and(eq(apps.id, params.id), tenantScopedWhere(apps, params.scopes)) });
13
14
  };
14
15
  const listAppsPaginated = (db) => async (params) => {
15
16
  const page = params.pagination?.page || 1;
16
17
  const limit = Math.min(params.pagination?.limit || 10, 100);
17
18
  const offset = (page - 1) * limit;
18
- const conditions = [eq(apps.tenantId, params.scopes.tenantId)];
19
+ const conditions = [tenantScopedWhere(apps, params.scopes)];
19
20
  if (params.scopes.projectId) conditions.push(eq(apps.projectId, params.scopes.projectId));
20
21
  if (params.type) conditions.push(eq(apps.type, params.type));
21
22
  const whereClause = and(...conditions);
@@ -46,27 +47,27 @@ const updateAppForTenant = (db) => async (params) => {
46
47
  const [updatedApp] = await db.update(apps).set({
47
48
  ...params.data,
48
49
  updatedAt: now
49
- }).where(and(eq(apps.id, params.id), eq(apps.tenantId, params.scopes.tenantId))).returning();
50
+ }).where(and(eq(apps.id, params.id), tenantScopedWhere(apps, params.scopes))).returning();
50
51
  return updatedApp;
51
52
  };
52
53
  const deleteAppForTenant = (db) => async (params) => {
53
- return (await db.delete(apps).where(and(eq(apps.id, params.id), eq(apps.tenantId, params.scopes.tenantId))).returning()).length > 0;
54
+ return (await db.delete(apps).where(and(eq(apps.id, params.id), tenantScopedWhere(apps, params.scopes))).returning()).length > 0;
54
55
  };
55
56
  const deleteAppsByProject = (db) => async (tenantId, projectId) => {
56
- return (await db.delete(apps).where(and(eq(apps.tenantId, tenantId), eq(apps.projectId, projectId))).returning()).length;
57
+ return (await db.delete(apps).where(and(tenantScopedWhere(apps, { tenantId }), eq(apps.projectId, projectId))).returning()).length;
57
58
  };
58
59
  const clearAppDefaultsByProject = (db) => async (tenantId, projectId) => {
59
60
  return (await db.update(apps).set({
60
61
  defaultProjectId: null,
61
62
  defaultAgentId: null,
62
63
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
63
- }).where(and(eq(apps.tenantId, tenantId), eq(apps.defaultProjectId, projectId))).returning()).length;
64
+ }).where(and(tenantScopedWhere(apps, { tenantId }), eq(apps.defaultProjectId, projectId))).returning()).length;
64
65
  };
65
66
  const clearAppDefaultsByAgent = (db) => async (tenantId, agentId) => {
66
67
  return (await db.update(apps).set({
67
68
  defaultAgentId: null,
68
69
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
69
- }).where(and(eq(apps.tenantId, tenantId), eq(apps.defaultAgentId, agentId))).returning()).length;
70
+ }).where(and(tenantScopedWhere(apps, { tenantId }), eq(apps.defaultAgentId, agentId))).returning()).length;
70
71
  };
71
72
  const updateApp = (db) => async (params) => {
72
73
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -0,0 +1,41 @@
1
+ import { ProjectScopeConfig } from "../../db/manage/scope-definitions.js";
2
+ import "../../types/utility.js";
3
+ import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
4
+
5
+ //#region src/data-access/runtime/audit-queries.d.ts
6
+ declare const listGitHubToolAccessByProject: (db: AgentsRunDatabaseClient) => (params: {
7
+ scopes: ProjectScopeConfig;
8
+ }) => Promise<{
9
+ id: string;
10
+ toolId: string;
11
+ }[]>;
12
+ declare const listGitHubToolAccessModeByProject: (db: AgentsRunDatabaseClient) => (params: {
13
+ scopes: ProjectScopeConfig;
14
+ }) => Promise<{
15
+ toolId: string;
16
+ }[]>;
17
+ declare const listSlackToolAccessConfigByProject: (db: AgentsRunDatabaseClient) => (params: {
18
+ scopes: ProjectScopeConfig;
19
+ }) => Promise<{
20
+ toolId: string;
21
+ }[]>;
22
+ declare const listContextCacheByProject: (db: AgentsRunDatabaseClient) => (params: {
23
+ scopes: ProjectScopeConfig;
24
+ }) => Promise<{
25
+ id: string;
26
+ contextConfigId: string;
27
+ }[]>;
28
+ declare const listApiKeysByProject: (db: AgentsRunDatabaseClient) => (params: {
29
+ scopes: ProjectScopeConfig;
30
+ }) => Promise<{
31
+ id: string;
32
+ agentId: string;
33
+ }[]>;
34
+ declare const listSlackChannelAgentConfigsByProject: (db: AgentsRunDatabaseClient) => (params: {
35
+ scopes: ProjectScopeConfig;
36
+ }) => Promise<{
37
+ id: string;
38
+ agentId: string;
39
+ }[]>;
40
+ //#endregion
41
+ export { listApiKeysByProject, listContextCacheByProject, listGitHubToolAccessByProject, listGitHubToolAccessModeByProject, listSlackChannelAgentConfigsByProject, listSlackToolAccessConfigByProject };
@@ -0,0 +1,37 @@
1
+ import { apiKeys, contextCache, workAppGitHubMcpToolAccessMode, workAppGitHubMcpToolRepositoryAccess, workAppSlackChannelAgentConfigs, workAppSlackMcpToolAccessConfig } from "../../db/runtime/runtime-schema.js";
2
+ import { projectScopedWhere } from "../manage/scope-helpers.js";
3
+
4
+ //#region src/data-access/runtime/audit-queries.ts
5
+ const listGitHubToolAccessByProject = (db) => async (params) => {
6
+ return db.select({
7
+ id: workAppGitHubMcpToolRepositoryAccess.id,
8
+ toolId: workAppGitHubMcpToolRepositoryAccess.toolId
9
+ }).from(workAppGitHubMcpToolRepositoryAccess).where(projectScopedWhere(workAppGitHubMcpToolRepositoryAccess, params.scopes));
10
+ };
11
+ const listGitHubToolAccessModeByProject = (db) => async (params) => {
12
+ return db.select({ toolId: workAppGitHubMcpToolAccessMode.toolId }).from(workAppGitHubMcpToolAccessMode).where(projectScopedWhere(workAppGitHubMcpToolAccessMode, params.scopes));
13
+ };
14
+ const listSlackToolAccessConfigByProject = (db) => async (params) => {
15
+ return db.select({ toolId: workAppSlackMcpToolAccessConfig.toolId }).from(workAppSlackMcpToolAccessConfig).where(projectScopedWhere(workAppSlackMcpToolAccessConfig, params.scopes));
16
+ };
17
+ const listContextCacheByProject = (db) => async (params) => {
18
+ return db.select({
19
+ id: contextCache.id,
20
+ contextConfigId: contextCache.contextConfigId
21
+ }).from(contextCache).where(projectScopedWhere(contextCache, params.scopes));
22
+ };
23
+ const listApiKeysByProject = (db) => async (params) => {
24
+ return db.select({
25
+ id: apiKeys.id,
26
+ agentId: apiKeys.agentId
27
+ }).from(apiKeys).where(projectScopedWhere(apiKeys, params.scopes));
28
+ };
29
+ const listSlackChannelAgentConfigsByProject = (db) => async (params) => {
30
+ return db.select({
31
+ id: workAppSlackChannelAgentConfigs.id,
32
+ agentId: workAppSlackChannelAgentConfigs.agentId
33
+ }).from(workAppSlackChannelAgentConfigs).where(projectScopedWhere(workAppSlackChannelAgentConfigs, params.scopes));
34
+ };
35
+
36
+ //#endregion
37
+ export { listApiKeysByProject, listContextCacheByProject, listGitHubToolAccessByProject, listGitHubToolAccessModeByProject, listSlackChannelAgentConfigsByProject, listSlackToolAccessConfigByProject };
@@ -0,0 +1,18 @@
1
+ import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
2
+
3
+ //#region src/data-access/runtime/auth.d.ts
4
+ declare const getInitialOrganization: (db: AgentsRunDatabaseClient) => (userId: string) => Promise<{
5
+ id: string;
6
+ } | null>;
7
+ declare const queryHasCredentialAccount: (db: AgentsRunDatabaseClient) => (userId: string) => Promise<boolean>;
8
+ interface SSOProviderRegistration {
9
+ providerId: string;
10
+ issuer: string;
11
+ domain: string;
12
+ organizationId?: string;
13
+ oidcConfig?: object;
14
+ samlConfig?: object;
15
+ }
16
+ declare const registerSSOProvider: (db: AgentsRunDatabaseClient) => (provider: SSOProviderRegistration) => Promise<void>;
17
+ //#endregion
18
+ export { SSOProviderRegistration, getInitialOrganization, queryHasCredentialAccount, registerSSOProvider };
@@ -0,0 +1,35 @@
1
+ import { account, member, ssoProvider } from "../../auth/auth-schema.js";
2
+ import { generateId } from "../../utils/conversations.js";
3
+ import "../../utils/index.js";
4
+ import { and, eq } from "drizzle-orm";
5
+
6
+ //#region src/data-access/runtime/auth.ts
7
+ const getInitialOrganization = (db) => async (userId) => {
8
+ const [membership] = await db.select({ organizationId: member.organizationId }).from(member).where(eq(member.userId, userId)).orderBy(member.createdAt).limit(1);
9
+ return membership ? { id: membership.organizationId } : null;
10
+ };
11
+ const queryHasCredentialAccount = (db) => async (userId) => {
12
+ const [row] = await db.select({ id: account.id }).from(account).where(and(eq(account.userId, userId), eq(account.providerId, "credential"))).limit(1);
13
+ return !!row;
14
+ };
15
+ const registerSSOProvider = (db) => async (provider) => {
16
+ try {
17
+ if ((await db.select().from(ssoProvider).where(eq(ssoProvider.providerId, provider.providerId)).limit(1)).length > 0) return;
18
+ if (!provider.domain) throw new Error(`SSO provider '${provider.providerId}' must have a domain`);
19
+ await db.insert(ssoProvider).values({
20
+ id: generateId(),
21
+ providerId: provider.providerId,
22
+ issuer: provider.issuer,
23
+ domain: provider.domain,
24
+ oidcConfig: provider.oidcConfig ? JSON.stringify(provider.oidcConfig) : null,
25
+ samlConfig: provider.samlConfig ? JSON.stringify(provider.samlConfig) : null,
26
+ userId: null,
27
+ organizationId: provider.organizationId || null
28
+ });
29
+ } catch (error) {
30
+ console.error(`❌ Failed to register SSO provider '${provider.providerId}':`, error);
31
+ }
32
+ };
33
+
34
+ //#endregion
35
+ export { getInitialOrganization, queryHasCredentialAccount, registerSSOProvider };
@@ -1,4 +1,5 @@
1
1
  import { apiKeys, contextCache, conversations, tasks, workAppGitHubMcpToolAccessMode, workAppGitHubMcpToolRepositoryAccess, workAppGitHubProjectAccessMode, workAppGitHubProjectRepositoryAccess } from "../../db/runtime/runtime-schema.js";
2
+ import { projectScopedWhere } from "../manage/scope-helpers.js";
2
3
  import { clearAppDefaultsByAgent, clearAppDefaultsByProject, deleteAppsByProject } from "./apps.js";
3
4
  import { deleteSlackMcpToolAccessConfig } from "./slack-work-app-mcp.js";
4
5
  import { clearDevConfigWorkspaceDefaultsByAgent, clearDevConfigWorkspaceDefaultsByProject, clearWorkspaceDefaultsByAgent, clearWorkspaceDefaultsByProject, deleteWorkAppSlackChannelAgentConfigsByAgent, deleteWorkAppSlackChannelAgentConfigsByProject } from "./workAppSlack.js";
@@ -14,9 +15,9 @@ import { and, eq, inArray, sql } from "drizzle-orm";
14
15
  */
15
16
  const cascadeDeleteByBranch = (db) => async (params) => {
16
17
  const { scopes, fullBranchName } = params;
17
- const contextCacheResult = await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning();
18
- const conversationsResult = await db.delete(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), sql`${conversations.ref}->>'name' = ${fullBranchName}`)).returning();
19
- const tasksResult = await db.delete(tasks).where(and(eq(tasks.tenantId, scopes.tenantId), eq(tasks.projectId, scopes.projectId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
18
+ const contextCacheResult = await db.delete(contextCache).where(and(projectScopedWhere(contextCache, scopes), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning();
19
+ const conversationsResult = await db.delete(conversations).where(and(projectScopedWhere(conversations, scopes), sql`${conversations.ref}->>'name' = ${fullBranchName}`)).returning();
20
+ const tasksResult = await db.delete(tasks).where(and(projectScopedWhere(tasks, scopes), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
20
21
  return {
21
22
  conversationsDeleted: conversationsResult.length,
22
23
  tasksDeleted: tasksResult.length,
@@ -38,10 +39,10 @@ const cascadeDeleteByBranch = (db) => async (params) => {
38
39
  */
39
40
  const cascadeDeleteByProject = (db) => async (params) => {
40
41
  const { scopes, fullBranchName } = params;
41
- const contextCacheResult = await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning();
42
- const conversationsResult = await db.delete(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), sql`${conversations.ref}->>'name' = ${fullBranchName}`)).returning();
43
- const tasksResult = await db.delete(tasks).where(and(eq(tasks.tenantId, scopes.tenantId), eq(tasks.projectId, scopes.projectId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
44
- const apiKeysResult = await db.delete(apiKeys).where(and(eq(apiKeys.tenantId, scopes.tenantId), eq(apiKeys.projectId, scopes.projectId))).returning();
42
+ const contextCacheResult = await db.delete(contextCache).where(and(projectScopedWhere(contextCache, scopes), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning();
43
+ const conversationsResult = await db.delete(conversations).where(and(projectScopedWhere(conversations, scopes), sql`${conversations.ref}->>'name' = ${fullBranchName}`)).returning();
44
+ const tasksResult = await db.delete(tasks).where(and(projectScopedWhere(tasks, scopes), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
45
+ const apiKeysResult = await db.delete(apiKeys).where(projectScopedWhere(apiKeys, scopes)).returning();
45
46
  await cascadeDeleteGitHubAccessByProject(db)({
46
47
  tenantId: scopes.tenantId,
47
48
  projectId: scopes.projectId
@@ -77,14 +78,14 @@ const cascadeDeleteByAgent = (db) => async (params) => {
77
78
  let tasksDeleted = 0;
78
79
  let apiKeysDeleted = 0;
79
80
  if (subAgentIds.length > 0) {
80
- const conversationIds = (await db.select({ id: conversations.id }).from(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), inArray(conversations.activeSubAgentId, subAgentIds), sql`${conversations.ref}->>'name' = ${fullBranchName}`))).map((c) => c.id);
81
+ const conversationIds = (await db.select({ id: conversations.id }).from(conversations).where(and(projectScopedWhere(conversations, scopes), inArray(conversations.activeSubAgentId, subAgentIds), sql`${conversations.ref}->>'name' = ${fullBranchName}`))).map((c) => c.id);
81
82
  if (conversationIds.length > 0) {
82
- contextCacheDeleted = (await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), inArray(contextCache.conversationId, conversationIds))).returning()).length;
83
- conversationsDeleted = (await db.delete(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), inArray(conversations.id, conversationIds))).returning()).length;
83
+ contextCacheDeleted = (await db.delete(contextCache).where(and(projectScopedWhere(contextCache, scopes), inArray(contextCache.conversationId, conversationIds))).returning()).length;
84
+ conversationsDeleted = (await db.delete(conversations).where(and(projectScopedWhere(conversations, scopes), inArray(conversations.id, conversationIds))).returning()).length;
84
85
  }
85
86
  }
86
- tasksDeleted = (await db.delete(tasks).where(and(eq(tasks.tenantId, scopes.tenantId), eq(tasks.projectId, scopes.projectId), eq(tasks.agentId, scopes.agentId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning()).length;
87
- apiKeysDeleted = (await db.delete(apiKeys).where(and(eq(apiKeys.tenantId, scopes.tenantId), eq(apiKeys.projectId, scopes.projectId), eq(apiKeys.agentId, scopes.agentId))).returning()).length;
87
+ tasksDeleted = (await db.delete(tasks).where(and(projectScopedWhere(tasks, scopes), eq(tasks.agentId, scopes.agentId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning()).length;
88
+ apiKeysDeleted = (await db.delete(apiKeys).where(and(projectScopedWhere(apiKeys, scopes), eq(apiKeys.agentId, scopes.agentId))).returning()).length;
88
89
  const appDefaultsCleared = await clearAppDefaultsByAgent(db)(scopes.tenantId, scopes.agentId);
89
90
  const slackChannelConfigsDeleted = await deleteWorkAppSlackChannelAgentConfigsByAgent(db)(scopes.tenantId, scopes.projectId, scopes.agentId);
90
91
  const slackWorkspaceDefaultsCleared = await clearWorkspaceDefaultsByAgent(db)(scopes.tenantId, scopes.projectId, scopes.agentId);
@@ -108,14 +109,14 @@ const cascadeDeleteByAgent = (db) => async (params) => {
108
109
  */
109
110
  const cascadeDeleteBySubAgent = (db) => async (params) => {
110
111
  const { scopes, subAgentId, fullBranchName } = params;
111
- const conversationIds = (await db.select({ id: conversations.id }).from(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), eq(conversations.activeSubAgentId, subAgentId), sql`${conversations.ref}->>'name' = ${fullBranchName}`))).map((c) => c.id);
112
+ const conversationIds = (await db.select({ id: conversations.id }).from(conversations).where(and(projectScopedWhere(conversations, scopes), eq(conversations.activeSubAgentId, subAgentId), sql`${conversations.ref}->>'name' = ${fullBranchName}`))).map((c) => c.id);
112
113
  let contextCacheDeleted = 0;
113
114
  let conversationsDeleted = 0;
114
115
  if (conversationIds.length > 0) {
115
- contextCacheDeleted = (await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), inArray(contextCache.conversationId, conversationIds))).returning()).length;
116
- conversationsDeleted = (await db.delete(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), inArray(conversations.id, conversationIds))).returning()).length;
116
+ contextCacheDeleted = (await db.delete(contextCache).where(and(projectScopedWhere(contextCache, scopes), inArray(contextCache.conversationId, conversationIds))).returning()).length;
117
+ conversationsDeleted = (await db.delete(conversations).where(and(projectScopedWhere(conversations, scopes), inArray(conversations.id, conversationIds))).returning()).length;
117
118
  }
118
- const tasksResult = await db.delete(tasks).where(and(eq(tasks.tenantId, scopes.tenantId), eq(tasks.projectId, scopes.projectId), eq(tasks.subAgentId, subAgentId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
119
+ const tasksResult = await db.delete(tasks).where(and(projectScopedWhere(tasks, scopes), eq(tasks.subAgentId, subAgentId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
119
120
  return {
120
121
  conversationsDeleted,
121
122
  tasksDeleted: tasksResult.length,
@@ -136,7 +137,7 @@ const cascadeDeleteBySubAgent = (db) => async (params) => {
136
137
  */
137
138
  const cascadeDeleteByContextConfig = (db) => async (params) => {
138
139
  const { scopes, contextConfigId, fullBranchName } = params;
139
- return { contextCacheDeleted: (await db.delete(contextCache).where(and(eq(contextCache.tenantId, scopes.tenantId), eq(contextCache.projectId, scopes.projectId), eq(contextCache.contextConfigId, contextConfigId), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning()).length };
140
+ return { contextCacheDeleted: (await db.delete(contextCache).where(and(projectScopedWhere(contextCache, scopes), eq(contextCache.contextConfigId, contextConfigId), sql`${contextCache.ref}->>'name' = ${fullBranchName}`)).returning()).length };
140
141
  };
141
142
  /**
142
143
  * Delete all runtime entities for a specific MCP tool.
@@ -151,8 +152,12 @@ const cascadeDeleteByContextConfig = (db) => async (params) => {
151
152
  */
152
153
  const cascadeDeleteByTool = (db) => async (params) => {
153
154
  const { toolId, tenantId, projectId } = params;
154
- const repositoryAccessResult = await db.delete(workAppGitHubMcpToolRepositoryAccess).where(and(eq(workAppGitHubMcpToolRepositoryAccess.tenantId, tenantId), eq(workAppGitHubMcpToolRepositoryAccess.projectId, projectId), eq(workAppGitHubMcpToolRepositoryAccess.toolId, toolId))).returning();
155
- const accessModeResult = await db.delete(workAppGitHubMcpToolAccessMode).where(and(eq(workAppGitHubMcpToolAccessMode.tenantId, tenantId), eq(workAppGitHubMcpToolAccessMode.projectId, projectId), eq(workAppGitHubMcpToolAccessMode.toolId, toolId))).returning();
155
+ const scopes = {
156
+ tenantId,
157
+ projectId
158
+ };
159
+ const repositoryAccessResult = await db.delete(workAppGitHubMcpToolRepositoryAccess).where(and(projectScopedWhere(workAppGitHubMcpToolRepositoryAccess, scopes), eq(workAppGitHubMcpToolRepositoryAccess.toolId, toolId))).returning();
160
+ const accessModeResult = await db.delete(workAppGitHubMcpToolAccessMode).where(and(projectScopedWhere(workAppGitHubMcpToolAccessMode, scopes), eq(workAppGitHubMcpToolAccessMode.toolId, toolId))).returning();
156
161
  const slackMcpDeleted = await deleteSlackMcpToolAccessConfig(db)({
157
162
  tenantId,
158
163
  projectId,
@@ -178,11 +183,11 @@ const cascadeDeleteByTool = (db) => async (params) => {
178
183
  * @returns Function that performs the cascade delete
179
184
  */
180
185
  const cascadeDeleteGitHubAccessByProject = (db) => async (params) => {
181
- const { tenantId, projectId } = params;
182
- const projectRepoAccessResult = await db.delete(workAppGitHubProjectRepositoryAccess).where(and(eq(workAppGitHubProjectRepositoryAccess.tenantId, tenantId), eq(workAppGitHubProjectRepositoryAccess.projectId, projectId))).returning();
183
- const projectAccessModeResult = await db.delete(workAppGitHubProjectAccessMode).where(and(eq(workAppGitHubProjectAccessMode.tenantId, tenantId), eq(workAppGitHubProjectAccessMode.projectId, projectId))).returning();
184
- const mcpToolRepoAccessResult = await db.delete(workAppGitHubMcpToolRepositoryAccess).where(and(eq(workAppGitHubMcpToolRepositoryAccess.tenantId, tenantId), eq(workAppGitHubMcpToolRepositoryAccess.projectId, projectId))).returning();
185
- const mcpToolAccessModeResult = await db.delete(workAppGitHubMcpToolAccessMode).where(and(eq(workAppGitHubMcpToolAccessMode.tenantId, tenantId), eq(workAppGitHubMcpToolAccessMode.projectId, projectId))).returning();
186
+ const scopes = params;
187
+ const projectRepoAccessResult = await db.delete(workAppGitHubProjectRepositoryAccess).where(projectScopedWhere(workAppGitHubProjectRepositoryAccess, scopes)).returning();
188
+ const projectAccessModeResult = await db.delete(workAppGitHubProjectAccessMode).where(projectScopedWhere(workAppGitHubProjectAccessMode, scopes)).returning();
189
+ const mcpToolRepoAccessResult = await db.delete(workAppGitHubMcpToolRepositoryAccess).where(projectScopedWhere(workAppGitHubMcpToolRepositoryAccess, scopes)).returning();
190
+ const mcpToolAccessModeResult = await db.delete(workAppGitHubMcpToolAccessMode).where(projectScopedWhere(workAppGitHubMcpToolAccessMode, scopes)).returning();
186
191
  return {
187
192
  projectRepositoryAccessDeleted: projectRepoAccessResult.length,
188
193
  projectAccessModeDeleted: projectAccessModeResult.length > 0,
@@ -12,6 +12,7 @@ declare const getCacheEntry: (db: AgentsRunDatabaseClient) => (params: {
12
12
  contextConfigId: string;
13
13
  contextVariableKey: string;
14
14
  requestHash?: string;
15
+ scopes: ProjectScopeConfig;
15
16
  }) => Promise<ContextCacheSelect | null>;
16
17
  /**
17
18
  * Set cached context data for a conversation
@@ -1,5 +1,6 @@
1
1
  import { contextCache } from "../../db/runtime/runtime-schema.js";
2
2
  import { generateId } from "../../utils/conversations.js";
3
+ import { projectScopedWhere } from "../manage/scope-helpers.js";
3
4
  import { and, eq } from "drizzle-orm";
4
5
 
5
6
  //#region src/data-access/runtime/contextCache.ts
@@ -8,7 +9,7 @@ import { and, eq } from "drizzle-orm";
8
9
  */
9
10
  const getCacheEntry = (db) => async (params) => {
10
11
  try {
11
- const cacheEntry = await db.query.contextCache.findFirst({ where: and(eq(contextCache.conversationId, params.conversationId), eq(contextCache.contextConfigId, params.contextConfigId), eq(contextCache.contextVariableKey, params.contextVariableKey)) });
12
+ const cacheEntry = await db.query.contextCache.findFirst({ where: and(projectScopedWhere(contextCache, params.scopes), eq(contextCache.conversationId, params.conversationId), eq(contextCache.contextConfigId, params.contextConfigId), eq(contextCache.contextVariableKey, params.contextVariableKey)) });
12
13
  if (!cacheEntry) return null;
13
14
  if (params.requestHash && cacheEntry.requestHash && cacheEntry.requestHash !== params.requestHash) return null;
14
15
  return {
@@ -52,25 +53,25 @@ const setCacheEntry = (db) => async (entry) => {
52
53
  * Clear cache entries for a specific conversation
53
54
  */
54
55
  const clearConversationCache = (db) => async (params) => {
55
- return (await db.delete(contextCache).where(and(eq(contextCache.tenantId, params.scopes.tenantId), eq(contextCache.projectId, params.scopes.projectId), eq(contextCache.conversationId, params.conversationId))).returning()).length;
56
+ return (await db.delete(contextCache).where(and(projectScopedWhere(contextCache, params.scopes), eq(contextCache.conversationId, params.conversationId))).returning()).length;
56
57
  };
57
58
  /**
58
59
  * Clear all cache entries for a specific context configuration
59
60
  */
60
61
  const clearContextConfigCache = (db) => async (params) => {
61
- return (await db.delete(contextCache).where(and(eq(contextCache.tenantId, params.scopes.tenantId), eq(contextCache.projectId, params.scopes.projectId), eq(contextCache.contextConfigId, params.contextConfigId))).returning()).length;
62
+ return (await db.delete(contextCache).where(and(projectScopedWhere(contextCache, params.scopes), eq(contextCache.contextConfigId, params.contextConfigId))).returning()).length;
62
63
  };
63
64
  /**
64
65
  * Clean up all cache entries for a tenant
65
66
  */
66
67
  const cleanupTenantCache = (db) => async (params) => {
67
- return (await db.delete(contextCache).where(and(eq(contextCache.tenantId, params.scopes.tenantId), eq(contextCache.projectId, params.scopes.projectId))).returning()).length;
68
+ return (await db.delete(contextCache).where(projectScopedWhere(contextCache, params.scopes)).returning()).length;
68
69
  };
69
70
  /**
70
71
  * Invalidate the headers cache for a conversation
71
72
  */
72
73
  const invalidateHeadersCache = (db) => async (params) => {
73
- return (await db.delete(contextCache).where(and(eq(contextCache.tenantId, params.scopes.tenantId), eq(contextCache.projectId, params.scopes.projectId), eq(contextCache.conversationId, params.conversationId), eq(contextCache.contextConfigId, params.contextConfigId), eq(contextCache.contextVariableKey, "headers"))).returning()).length;
74
+ return (await db.delete(contextCache).where(and(projectScopedWhere(contextCache, params.scopes), eq(contextCache.conversationId, params.conversationId), eq(contextCache.contextConfigId, params.contextConfigId), eq(contextCache.contextVariableKey, "headers"))).returning()).length;
74
75
  };
75
76
  /**
76
77
  * Invalidate specific cache entries for invocation-trigger definitions
@@ -78,7 +79,7 @@ const invalidateHeadersCache = (db) => async (params) => {
78
79
  const invalidateInvocationDefinitionsCache = (db) => async (params) => {
79
80
  let totalRowsAffected = 0;
80
81
  for (const definitionId of params.invocationDefinitionIds) {
81
- const result = await db.delete(contextCache).where(and(eq(contextCache.tenantId, params.scopes.tenantId), eq(contextCache.projectId, params.scopes.projectId), eq(contextCache.conversationId, params.conversationId), eq(contextCache.contextConfigId, params.contextConfigId), eq(contextCache.contextVariableKey, definitionId))).returning();
82
+ const result = await db.delete(contextCache).where(and(projectScopedWhere(contextCache, params.scopes), eq(contextCache.conversationId, params.conversationId), eq(contextCache.contextConfigId, params.contextConfigId), eq(contextCache.contextVariableKey, definitionId))).returning();
82
83
  totalRowsAffected += result.length;
83
84
  }
84
85
  return totalRowsAffected;
@@ -87,7 +88,7 @@ const invalidateInvocationDefinitionsCache = (db) => async (params) => {
87
88
  * Get all cache entries for a conversation
88
89
  */
89
90
  const getConversationCacheEntries = (db) => async (params) => {
90
- return (await db.query.contextCache.findMany({ where: and(eq(contextCache.tenantId, params.scopes.tenantId), eq(contextCache.projectId, params.scopes.projectId), eq(contextCache.conversationId, params.conversationId)) })).map((entry) => ({
91
+ return (await db.query.contextCache.findMany({ where: and(projectScopedWhere(contextCache, params.scopes), eq(contextCache.conversationId, params.conversationId)) })).map((entry) => ({
91
92
  ...entry,
92
93
  value: entry.value
93
94
  }));
@@ -96,7 +97,7 @@ const getConversationCacheEntries = (db) => async (params) => {
96
97
  * Get all cache entries for a context configuration
97
98
  */
98
99
  const getContextConfigCacheEntries = (db) => async (params) => {
99
- return (await db.query.contextCache.findMany({ where: and(eq(contextCache.tenantId, params.scopes.tenantId), eq(contextCache.projectId, params.scopes.projectId), eq(contextCache.contextConfigId, params.contextConfigId)) })).map((entry) => ({
100
+ return (await db.query.contextCache.findMany({ where: and(projectScopedWhere(contextCache, params.scopes), eq(contextCache.contextConfigId, params.contextConfigId)) })).map((entry) => ({
100
101
  ...entry,
101
102
  value: entry.value
102
103
  }));