@inkeep/agents-core 0.43.0 → 0.45.0

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 (76) hide show
  1. package/dist/auth/auth.d.ts +4 -2
  2. package/dist/auth/auth.js +4 -3
  3. package/dist/auth/authz/client.d.ts +0 -1
  4. package/dist/auth/authz/client.js +0 -1
  5. package/dist/auth/authz/config.d.ts +1 -7
  6. package/dist/auth/authz/config.js +1 -9
  7. package/dist/auth/authz/index.d.ts +3 -3
  8. package/dist/auth/authz/index.js +3 -3
  9. package/dist/auth/authz/permissions.d.ts +16 -1
  10. package/dist/auth/authz/permissions.js +30 -9
  11. package/dist/auth/authz/sync.js +1 -11
  12. package/dist/auth/init.d.ts +1 -0
  13. package/dist/auth/init.js +115 -0
  14. package/dist/client-exports.d.ts +2 -6
  15. package/dist/client-exports.js +3 -7
  16. package/dist/constants/otel-attributes.d.ts +6 -0
  17. package/dist/constants/otel-attributes.js +9 -3
  18. package/dist/constants/signoz-queries.d.ts +1 -0
  19. package/dist/constants/signoz-queries.js +2 -1
  20. package/dist/data-access/index.d.ts +4 -3
  21. package/dist/data-access/index.js +6 -5
  22. package/dist/data-access/manage/agentFull.js +42 -1
  23. package/dist/data-access/manage/agents.d.ts +27 -10
  24. package/dist/data-access/manage/agents.js +33 -2
  25. package/dist/data-access/manage/artifactComponents.d.ts +4 -4
  26. package/dist/data-access/manage/artifactComponents.js +1 -1
  27. package/dist/data-access/manage/contextConfigs.d.ts +12 -12
  28. package/dist/data-access/manage/dataComponents.d.ts +4 -4
  29. package/dist/data-access/manage/dataComponents.js +1 -1
  30. package/dist/data-access/manage/functionTools.d.ts +4 -4
  31. package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +12 -12
  32. package/dist/data-access/manage/subAgentRelations.d.ts +18 -18
  33. package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +12 -12
  34. package/dist/data-access/manage/subAgents.d.ts +3 -3
  35. package/dist/data-access/manage/tools.d.ts +20 -15
  36. package/dist/data-access/manage/tools.js +20 -1
  37. package/dist/data-access/runtime/apiKeys.d.ts +4 -4
  38. package/dist/data-access/runtime/cascade-delete.d.ts +48 -1
  39. package/dist/data-access/runtime/cascade-delete.js +52 -2
  40. package/dist/data-access/runtime/conversations.d.ts +19 -19
  41. package/dist/data-access/runtime/github-work-app-installations.d.ts +261 -0
  42. package/dist/data-access/runtime/github-work-app-installations.js +457 -0
  43. package/dist/data-access/runtime/messages.d.ts +6 -6
  44. package/dist/data-access/runtime/organizations.js +2 -2
  45. package/dist/data-access/runtime/tasks.d.ts +4 -4
  46. package/dist/db/manage/manage-schema.d.ts +17 -0
  47. package/dist/db/manage/manage-schema.js +1 -0
  48. package/dist/db/runtime/runtime-schema.d.ts +1009 -165
  49. package/dist/db/runtime/runtime-schema.js +173 -5
  50. package/dist/dolt/ref-middleware.js +1 -1
  51. package/dist/env.d.ts +6 -4
  52. package/dist/env.js +11 -10
  53. package/dist/index.d.ts +10 -11
  54. package/dist/index.js +22 -23
  55. package/dist/types/entities.d.ts +9 -2
  56. package/dist/types/index.d.ts +3 -3
  57. package/dist/types/utility.d.ts +16 -2
  58. package/dist/utils/temp-jwt.d.ts +2 -1
  59. package/dist/utils/temp-jwt.js +3 -2
  60. package/dist/validation/agentFull.js +1 -1
  61. package/dist/validation/dolt-schemas.d.ts +1 -1
  62. package/dist/validation/drizzle-schema-helpers.d.ts +1 -20
  63. package/dist/validation/drizzle-schema-helpers.js +3 -30
  64. package/dist/validation/index.d.ts +2 -4
  65. package/dist/validation/index.js +4 -6
  66. package/dist/validation/schemas.d.ts +3021 -1228
  67. package/dist/validation/schemas.js +164 -79
  68. package/drizzle/manage/0006_fixed_umar.sql +1 -0
  69. package/drizzle/manage/meta/0006_snapshot.json +3148 -0
  70. package/drizzle/manage/meta/_journal.json +7 -0
  71. package/drizzle/runtime/0010_previous_black_knight.sql +84 -0
  72. package/drizzle/runtime/meta/0010_snapshot.json +3066 -0
  73. package/drizzle/runtime/meta/_journal.json +7 -0
  74. package/package.json +4 -2
  75. package/dist/validation/id-validation.d.ts +0 -24
  76. package/dist/validation/id-validation.js +0 -52
@@ -11,11 +11,11 @@ declare const getSubAgentExternalAgentRelationById: (db: AgentsManageDatabaseCli
11
11
  id: string;
12
12
  createdAt: string;
13
13
  updatedAt: string;
14
- tenantId: string;
14
+ headers: Record<string, string> | null;
15
15
  agentId: string;
16
16
  projectId: string;
17
+ tenantId: string;
17
18
  subAgentId: string;
18
- headers: Record<string, string> | null;
19
19
  externalAgentId: string;
20
20
  } | undefined>;
21
21
  declare const listSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
@@ -46,11 +46,11 @@ declare const getSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClient
46
46
  id: string;
47
47
  createdAt: string;
48
48
  updatedAt: string;
49
- tenantId: string;
49
+ headers: Record<string, string> | null;
50
50
  agentId: string;
51
51
  projectId: string;
52
+ tenantId: string;
52
53
  subAgentId: string;
53
- headers: Record<string, string> | null;
54
54
  externalAgentId: string;
55
55
  }[]>;
56
56
  declare const getSubAgentExternalAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (params: {
@@ -59,11 +59,11 @@ declare const getSubAgentExternalAgentRelationsByAgent: (db: AgentsManageDatabas
59
59
  id: string;
60
60
  createdAt: string;
61
61
  updatedAt: string;
62
- tenantId: string;
62
+ headers: Record<string, string> | null;
63
63
  agentId: string;
64
64
  projectId: string;
65
+ tenantId: string;
65
66
  subAgentId: string;
66
- headers: Record<string, string> | null;
67
67
  externalAgentId: string;
68
68
  }[]>;
69
69
  declare const getSubAgentExternalAgentRelationsByExternalAgent: (db: AgentsManageDatabaseClient) => (params: {
@@ -182,11 +182,11 @@ declare const createSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClie
182
182
  id: string;
183
183
  createdAt: string;
184
184
  updatedAt: string;
185
- tenantId: string;
185
+ headers: Record<string, string> | null;
186
186
  agentId: string;
187
187
  projectId: string;
188
+ tenantId: string;
188
189
  subAgentId: string;
189
- headers: Record<string, string> | null;
190
190
  externalAgentId: string;
191
191
  }>;
192
192
  /**
@@ -199,11 +199,11 @@ declare const getSubAgentExternalAgentRelationByParams: (db: AgentsManageDatabas
199
199
  id: string;
200
200
  createdAt: string;
201
201
  updatedAt: string;
202
- tenantId: string;
202
+ headers: Record<string, string> | null;
203
203
  agentId: string;
204
204
  projectId: string;
205
+ tenantId: string;
205
206
  subAgentId: string;
206
- headers: Record<string, string> | null;
207
207
  externalAgentId: string;
208
208
  } | undefined>;
209
209
  /**
@@ -220,11 +220,11 @@ declare const upsertSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClie
220
220
  id: string;
221
221
  createdAt: string;
222
222
  updatedAt: string;
223
- tenantId: string;
223
+ headers: Record<string, string> | null;
224
224
  agentId: string;
225
225
  projectId: string;
226
+ tenantId: string;
226
227
  subAgentId: string;
227
- headers: Record<string, string> | null;
228
228
  externalAgentId: string;
229
229
  }>;
230
230
  declare const updateSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClient) => (params: {
@@ -11,12 +11,12 @@ declare const getAgentRelationById: (db: AgentsManageDatabaseClient) => (params:
11
11
  id: string;
12
12
  createdAt: string;
13
13
  updatedAt: string;
14
- tenantId: string;
15
14
  agentId: string;
16
15
  projectId: string;
17
- relationType: string | null;
16
+ tenantId: string;
18
17
  sourceSubAgentId: string;
19
18
  targetSubAgentId: string | null;
19
+ relationType: string | null;
20
20
  } | undefined>;
21
21
  declare const listAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
22
22
  scopes: AgentScopeConfig;
@@ -46,12 +46,12 @@ declare const getAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
46
46
  id: string;
47
47
  createdAt: string;
48
48
  updatedAt: string;
49
- tenantId: string;
50
49
  agentId: string;
51
50
  projectId: string;
52
- relationType: string | null;
51
+ tenantId: string;
53
52
  sourceSubAgentId: string;
54
53
  targetSubAgentId: string | null;
54
+ relationType: string | null;
55
55
  }[]>;
56
56
  declare const getAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (params: {
57
57
  scopes: AgentScopeConfig;
@@ -59,12 +59,12 @@ declare const getAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (par
59
59
  id: string;
60
60
  createdAt: string;
61
61
  updatedAt: string;
62
- tenantId: string;
63
62
  agentId: string;
64
63
  projectId: string;
65
- relationType: string | null;
64
+ tenantId: string;
66
65
  sourceSubAgentId: string;
67
66
  targetSubAgentId: string | null;
67
+ relationType: string | null;
68
68
  }[]>;
69
69
  declare const getAgentRelationsBySource: (db: AgentsManageDatabaseClient) => (params: {
70
70
  scopes: AgentScopeConfig;
@@ -128,12 +128,12 @@ declare const createSubAgentRelation: (db: AgentsManageDatabaseClient) => (param
128
128
  id: string;
129
129
  createdAt: string;
130
130
  updatedAt: string;
131
- tenantId: string;
132
131
  agentId: string;
133
132
  projectId: string;
134
- relationType: string | null;
133
+ tenantId: string;
135
134
  sourceSubAgentId: string;
136
135
  targetSubAgentId: string | null;
136
+ relationType: string | null;
137
137
  }>;
138
138
  /**
139
139
  * Check if sub-agent relation exists by agent, source, target, and relation type
@@ -147,12 +147,12 @@ declare const getAgentRelationByParams: (db: AgentsManageDatabaseClient) => (par
147
147
  id: string;
148
148
  createdAt: string;
149
149
  updatedAt: string;
150
- tenantId: string;
151
150
  agentId: string;
152
151
  projectId: string;
153
- relationType: string | null;
152
+ tenantId: string;
154
153
  sourceSubAgentId: string;
155
154
  targetSubAgentId: string | null;
155
+ relationType: string | null;
156
156
  } | undefined>;
157
157
  /**
158
158
  * Upsert agent relation (create if it doesn't exist, no-op if it does)
@@ -161,12 +161,12 @@ declare const upsertSubAgentRelation: (db: AgentsManageDatabaseClient) => (param
161
161
  id: string;
162
162
  createdAt: string;
163
163
  updatedAt: string;
164
- tenantId: string;
165
164
  agentId: string;
166
165
  projectId: string;
167
- relationType: string | null;
166
+ tenantId: string;
168
167
  sourceSubAgentId: string;
169
168
  targetSubAgentId: string | null;
169
+ relationType: string | null;
170
170
  }>;
171
171
  declare const updateAgentRelation: (db: AgentsManageDatabaseClient) => (params: {
172
172
  scopes: AgentScopeConfig;
@@ -206,12 +206,12 @@ declare const createAgentToolRelation: (db: AgentsManageDatabaseClient) => (para
206
206
  id: string;
207
207
  createdAt: string;
208
208
  updatedAt: string;
209
- tenantId: string;
209
+ headers: Record<string, string> | null;
210
210
  agentId: string;
211
211
  projectId: string;
212
- subAgentId: string;
213
- headers: Record<string, string> | null;
212
+ tenantId: string;
214
213
  toolId: string;
214
+ subAgentId: string;
215
215
  selectedTools: string[] | null;
216
216
  toolPolicies: Record<string, {
217
217
  needsApproval?: boolean;
@@ -250,12 +250,12 @@ declare const getAgentToolRelationById: (db: AgentsManageDatabaseClient) => (par
250
250
  id: string;
251
251
  createdAt: string;
252
252
  updatedAt: string;
253
- tenantId: string;
253
+ headers: Record<string, string> | null;
254
254
  agentId: string;
255
255
  projectId: string;
256
- subAgentId: string;
257
- headers: Record<string, string> | null;
256
+ tenantId: string;
258
257
  toolId: string;
258
+ subAgentId: string;
259
259
  selectedTools: string[] | null;
260
260
  toolPolicies: Record<string, {
261
261
  needsApproval?: boolean;
@@ -11,11 +11,11 @@ declare const getSubAgentTeamAgentRelationById: (db: AgentsManageDatabaseClient)
11
11
  id: string;
12
12
  createdAt: string;
13
13
  updatedAt: string;
14
- tenantId: string;
14
+ headers: Record<string, string> | null;
15
15
  agentId: string;
16
16
  projectId: string;
17
+ tenantId: string;
17
18
  subAgentId: string;
18
- headers: Record<string, string> | null;
19
19
  targetAgentId: string;
20
20
  } | undefined>;
21
21
  declare const listSubAgentTeamAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
@@ -46,11 +46,11 @@ declare const getSubAgentTeamAgentRelations: (db: AgentsManageDatabaseClient) =>
46
46
  id: string;
47
47
  createdAt: string;
48
48
  updatedAt: string;
49
- tenantId: string;
49
+ headers: Record<string, string> | null;
50
50
  agentId: string;
51
51
  projectId: string;
52
+ tenantId: string;
52
53
  subAgentId: string;
53
- headers: Record<string, string> | null;
54
54
  targetAgentId: string;
55
55
  }[]>;
56
56
  declare const getSubAgentTeamAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (params: {
@@ -59,11 +59,11 @@ declare const getSubAgentTeamAgentRelationsByAgent: (db: AgentsManageDatabaseCli
59
59
  id: string;
60
60
  createdAt: string;
61
61
  updatedAt: string;
62
- tenantId: string;
62
+ headers: Record<string, string> | null;
63
63
  agentId: string;
64
64
  projectId: string;
65
+ tenantId: string;
65
66
  subAgentId: string;
66
- headers: Record<string, string> | null;
67
67
  targetAgentId: string;
68
68
  }[]>;
69
69
  declare const getSubAgentTeamAgentRelationsByTeamAgent: (db: AgentsManageDatabaseClient) => (params: {
@@ -212,11 +212,11 @@ declare const createSubAgentTeamAgentRelation: (db: AgentsManageDatabaseClient)
212
212
  id: string;
213
213
  createdAt: string;
214
214
  updatedAt: string;
215
- tenantId: string;
215
+ headers: Record<string, string> | null;
216
216
  agentId: string;
217
217
  projectId: string;
218
+ tenantId: string;
218
219
  subAgentId: string;
219
- headers: Record<string, string> | null;
220
220
  targetAgentId: string;
221
221
  }>;
222
222
  /**
@@ -229,11 +229,11 @@ declare const getSubAgentTeamAgentRelationByParams: (db: AgentsManageDatabaseCli
229
229
  id: string;
230
230
  createdAt: string;
231
231
  updatedAt: string;
232
- tenantId: string;
232
+ headers: Record<string, string> | null;
233
233
  agentId: string;
234
234
  projectId: string;
235
+ tenantId: string;
235
236
  subAgentId: string;
236
- headers: Record<string, string> | null;
237
237
  targetAgentId: string;
238
238
  } | undefined>;
239
239
  /**
@@ -250,11 +250,11 @@ declare const upsertSubAgentTeamAgentRelation: (db: AgentsManageDatabaseClient)
250
250
  id: string;
251
251
  createdAt: string;
252
252
  updatedAt: string;
253
- tenantId: string;
253
+ headers: Record<string, string> | null;
254
254
  agentId: string;
255
255
  projectId: string;
256
+ tenantId: string;
256
257
  subAgentId: string;
257
- headers: Record<string, string> | null;
258
258
  targetAgentId: string;
259
259
  }>;
260
260
  declare const updateSubAgentTeamAgentRelation: (db: AgentsManageDatabaseClient) => (params: {
@@ -13,9 +13,9 @@ declare const getSubAgentById: (db: AgentsManageDatabaseClient) => (params: {
13
13
  createdAt: string;
14
14
  updatedAt: string;
15
15
  description: string | null;
16
- tenantId: string;
17
16
  agentId: string;
18
17
  projectId: string;
18
+ tenantId: string;
19
19
  models: {
20
20
  base?: {
21
21
  model?: string | undefined;
@@ -44,9 +44,9 @@ declare const listSubAgents: (db: AgentsManageDatabaseClient) => (params: {
44
44
  createdAt: string;
45
45
  updatedAt: string;
46
46
  description: string | null;
47
- tenantId: string;
48
47
  agentId: string;
49
48
  projectId: string;
49
+ tenantId: string;
50
50
  models: {
51
51
  base?: {
52
52
  model?: string | undefined;
@@ -113,9 +113,9 @@ declare const createSubAgent: (db: AgentsManageDatabaseClient) => (params: SubAg
113
113
  createdAt: string;
114
114
  updatedAt: string;
115
115
  description: string | null;
116
- tenantId: string;
117
116
  agentId: string;
118
117
  projectId: string;
118
+ tenantId: string;
119
119
  models: {
120
120
  base?: {
121
121
  model?: string | undefined;
@@ -23,9 +23,9 @@ declare const getToolById: (db: AgentsManageDatabaseClient) => (params: {
23
23
  createdAt: string;
24
24
  updatedAt: string;
25
25
  description: string | null;
26
- tenantId: string;
27
- projectId: string;
28
26
  headers: Record<string, string> | null;
27
+ projectId: string;
28
+ tenantId: string;
29
29
  config: {
30
30
  type: "mcp";
31
31
  mcp: ToolMcpConfig;
@@ -35,6 +35,7 @@ declare const getToolById: (db: AgentsManageDatabaseClient) => (params: {
35
35
  imageUrl: string | null;
36
36
  capabilities: ToolServerCapabilities | null;
37
37
  lastError: string | null;
38
+ isWorkApp: boolean;
38
39
  } | null>;
39
40
  declare const getMcpToolById: (db: AgentsManageDatabaseClient) => (params: {
40
41
  scopes: ProjectScopeConfig;
@@ -62,6 +63,7 @@ declare const listTools: (db: AgentsManageDatabaseClient) => (params: {
62
63
  imageUrl: string | null;
63
64
  capabilities: ToolServerCapabilities | null;
64
65
  lastError: string | null;
66
+ isWorkApp: boolean;
65
67
  projectId: string;
66
68
  tenantId: string;
67
69
  id: string;
@@ -79,9 +81,9 @@ declare const createTool: (db: AgentsManageDatabaseClient) => (params: ToolInser
79
81
  createdAt: string;
80
82
  updatedAt: string;
81
83
  description: string | null;
82
- tenantId: string;
83
- projectId: string;
84
84
  headers: Record<string, string> | null;
85
+ projectId: string;
86
+ tenantId: string;
85
87
  config: {
86
88
  type: "mcp";
87
89
  mcp: ToolMcpConfig;
@@ -91,6 +93,7 @@ declare const createTool: (db: AgentsManageDatabaseClient) => (params: ToolInser
91
93
  imageUrl: string | null;
92
94
  capabilities: ToolServerCapabilities | null;
93
95
  lastError: string | null;
96
+ isWorkApp: boolean;
94
97
  }>;
95
98
  declare const updateTool: (db: AgentsManageDatabaseClient) => (params: {
96
99
  scopes: ProjectScopeConfig;
@@ -111,6 +114,7 @@ declare const updateTool: (db: AgentsManageDatabaseClient) => (params: {
111
114
  imageUrl: string | null;
112
115
  capabilities: ToolServerCapabilities | null;
113
116
  lastError: string | null;
117
+ isWorkApp: boolean;
114
118
  projectId: string;
115
119
  tenantId: string;
116
120
  id: string;
@@ -132,12 +136,12 @@ declare const addToolToAgent: (db: AgentsManageDatabaseClient) => (params: {
132
136
  id: string;
133
137
  createdAt: string;
134
138
  updatedAt: string;
135
- tenantId: string;
139
+ headers: Record<string, string> | null;
136
140
  agentId: string;
137
141
  projectId: string;
138
- subAgentId: string;
139
- headers: Record<string, string> | null;
142
+ tenantId: string;
140
143
  toolId: string;
144
+ subAgentId: string;
141
145
  selectedTools: string[] | null;
142
146
  toolPolicies: Record<string, {
143
147
  needsApproval?: boolean;
@@ -151,12 +155,12 @@ declare const removeToolFromAgent: (db: AgentsManageDatabaseClient) => (params:
151
155
  id: string;
152
156
  createdAt: string;
153
157
  updatedAt: string;
154
- tenantId: string;
158
+ headers: Record<string, string> | null;
155
159
  agentId: string;
156
160
  projectId: string;
157
- subAgentId: string;
158
- headers: Record<string, string> | null;
161
+ tenantId: string;
159
162
  toolId: string;
163
+ subAgentId: string;
160
164
  selectedTools: string[] | null;
161
165
  toolPolicies: Record<string, {
162
166
  needsApproval?: boolean;
@@ -179,12 +183,12 @@ declare const upsertSubAgentToolRelation: (db: AgentsManageDatabaseClient) => (p
179
183
  id: string;
180
184
  createdAt: string;
181
185
  updatedAt: string;
182
- tenantId: string;
186
+ headers: Record<string, string> | null;
183
187
  agentId: string;
184
188
  projectId: string;
185
- subAgentId: string;
186
- headers: Record<string, string> | null;
189
+ tenantId: string;
187
190
  toolId: string;
191
+ subAgentId: string;
188
192
  selectedTools: string[] | null;
189
193
  toolPolicies: Record<string, {
190
194
  needsApproval?: boolean;
@@ -201,9 +205,9 @@ declare const upsertTool: (db: AgentsManageDatabaseClient) => (params: {
201
205
  createdAt: string;
202
206
  updatedAt: string;
203
207
  description: string | null;
204
- tenantId: string;
205
- projectId: string;
206
208
  headers: Record<string, string> | null;
209
+ projectId: string;
210
+ tenantId: string;
207
211
  config: {
208
212
  type: "mcp";
209
213
  mcp: ToolMcpConfig;
@@ -213,6 +217,7 @@ declare const upsertTool: (db: AgentsManageDatabaseClient) => (params: {
213
217
  imageUrl: string | null;
214
218
  capabilities: ToolServerCapabilities | null;
215
219
  lastError: string | null;
220
+ isWorkApp: boolean;
216
221
  }>;
217
222
  //#endregion
218
223
  export { addToolToAgent, createTool, dbResultToMcpTool, dbResultToMcpToolSkeleton, deleteTool, getMcpToolById, getToolById, listTools, removeToolFromAgent, updateTool, upsertSubAgentToolRelation, upsertTool };
@@ -1,17 +1,22 @@
1
1
  import { CredentialStoreType, MCPServerType, MCPTransportType } from "../../types/utility.js";
2
2
  import { subAgentToolRelations, tools } from "../../db/manage/manage-schema.js";
3
3
  import { detectAuthenticationRequired } from "../../utils/auth-detection.js";
4
+ import { env } from "../../env.js";
4
5
  import { getLogger } from "../../utils/logger.js";
5
6
  import { getCredentialStoreLookupKeyFromRetrievalParams } from "../../utils/credential-store-utils.js";
6
7
  import { CredentialStuffer } from "../../credential-stuffer/CredentialStuffer.js";
7
8
  import "../../credential-stuffer/index.js";
9
+ import { createAgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
8
10
  import { generateId } from "../../utils/conversations.js";
11
+ import { getActiveBranch } from "../../dolt/schema-sync.js";
9
12
  import { updateAgentToolRelation } from "./subAgentRelations.js";
10
13
  import { toISODateString } from "../../utils/date.js";
11
14
  import { McpClient } from "../../utils/mcp-client.js";
12
15
  import { buildComposioMCPUrl } from "../../utils/third-party-mcp-servers/composio-client.js";
13
16
  import { isThirdPartyMCPServerAuthenticated } from "../../utils/third-party-mcp-servers/third-party-check.js";
14
17
  import "../../utils/index.js";
18
+ import { cascadeDeleteByTool } from "../runtime/cascade-delete.js";
19
+ import { isGithubWorkAppTool } from "../runtime/github-work-app-installations.js";
15
20
  import { getCredentialReference, getUserScopedCredentialReference } from "./credentialReferences.js";
16
21
  import { and, count, desc, eq } from "drizzle-orm";
17
22
  import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
@@ -114,6 +119,11 @@ const discoverToolsFromServer = async (tool, credentialReference, credentialStor
114
119
  sessionId: tool.config.mcp.transport?.sessionId
115
120
  };
116
121
  if (serverConfig.url) serverConfig.url = buildComposioMCPUrl(serverConfig.url.toString(), tool.tenantId, tool.projectId, tool.credentialScope === "user" ? "user" : "project", userId);
122
+ if (isGithubWorkAppTool(tool)) serverConfig.headers = {
123
+ ...serverConfig.headers,
124
+ "x-inkeep-tool-id": tool.id,
125
+ Authorization: `Bearer ${env.GITHUB_MCP_API_KEY}`
126
+ };
117
127
  const client = new McpClient({
118
128
  name: tool.name,
119
129
  server: serverConfig
@@ -307,7 +317,16 @@ const updateTool = (db) => async (params) => {
307
317
  };
308
318
  const deleteTool = (db) => async (params) => {
309
319
  const [deleted] = await db.delete(tools).where(and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.projectId, params.scopes.projectId), eq(tools.id, params.toolId))).returning();
310
- return !!deleted;
320
+ if (!deleted) return false;
321
+ if (deleted.isWorkApp && deleted.config.mcp.server.url.includes("/github/mcp")) try {
322
+ if (await getActiveBranch(db)() === `${params.scopes.tenantId}_${params.scopes.projectId}_main`) await cascadeDeleteByTool(createAgentsRunDatabaseClient())({ toolId: params.toolId });
323
+ } catch (error) {
324
+ logger.debug({
325
+ error,
326
+ toolId: params.toolId
327
+ }, "Skipping cascade delete - active_branch() not available");
328
+ }
329
+ return true;
311
330
  };
312
331
  const addToolToAgent = (db) => async (params) => {
313
332
  const id = generateId();
@@ -12,9 +12,9 @@ declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
12
12
  createdAt: string;
13
13
  updatedAt: string;
14
14
  expiresAt: string | null;
15
- tenantId: string;
16
15
  agentId: string;
17
16
  projectId: string;
17
+ tenantId: string;
18
18
  publicId: string;
19
19
  keyHash: string;
20
20
  keyPrefix: string;
@@ -26,9 +26,9 @@ declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: s
26
26
  createdAt: string;
27
27
  updatedAt: string;
28
28
  expiresAt: string | null;
29
- tenantId: string;
30
29
  agentId: string;
31
30
  projectId: string;
31
+ tenantId: string;
32
32
  publicId: string;
33
33
  keyHash: string;
34
34
  keyPrefix: string;
@@ -43,9 +43,9 @@ declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
43
43
  createdAt: string;
44
44
  updatedAt: string;
45
45
  expiresAt: string | null;
46
- tenantId: string;
47
46
  agentId: string;
48
47
  projectId: string;
48
+ tenantId: string;
49
49
  publicId: string;
50
50
  keyHash: string;
51
51
  keyPrefix: string;
@@ -70,9 +70,9 @@ declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInse
70
70
  createdAt: string;
71
71
  updatedAt: string;
72
72
  expiresAt: string | null;
73
- tenantId: string;
74
73
  agentId: string;
75
74
  projectId: string;
75
+ tenantId: string;
76
76
  publicId: string;
77
77
  keyHash: string;
78
78
  keyPrefix: string;
@@ -73,5 +73,52 @@ declare const cascadeDeleteByContextConfig: (db: AgentsRunDatabaseClient) => (pa
73
73
  }) => Promise<{
74
74
  contextCacheDeleted: number;
75
75
  }>;
76
+ /**
77
+ * Result of a tool cascade delete operation
78
+ */
79
+ type ToolCascadeDeleteResult = {
80
+ mcpToolRepositoryAccessDeleted: number;
81
+ mcpToolAccessModeDeleted: boolean;
82
+ };
83
+ /**
84
+ * Delete all runtime entities for a specific MCP tool.
85
+ * Called when an MCP tool is deleted from the manage database.
86
+ *
87
+ * Cleans up:
88
+ * - workAppGitHubMcpToolRepositoryAccess entries
89
+ * - workAppGitHubMcpToolAccessMode entry
90
+ *
91
+ * @param db - Runtime database client
92
+ * @returns Function that performs the cascade delete
93
+ */
94
+ declare const cascadeDeleteByTool: (db: AgentsRunDatabaseClient) => (params: {
95
+ toolId: string;
96
+ }) => Promise<ToolCascadeDeleteResult>;
97
+ /**
98
+ * Result of a project cascade delete operation (GitHub access only)
99
+ */
100
+ type ProjectGitHubAccessCascadeDeleteResult = {
101
+ projectRepositoryAccessDeleted: number;
102
+ projectAccessModeDeleted: boolean;
103
+ mcpToolRepositoryAccessDeleted: number;
104
+ mcpToolAccessModesDeleted: number;
105
+ };
106
+ /**
107
+ * Delete all GitHub access runtime entities for a specific project.
108
+ * Called when a project is deleted from the manage database.
109
+ *
110
+ * Cleans up:
111
+ * - workAppGitHubProjectRepositoryAccess entries
112
+ * - workAppGitHubProjectAccessMode entry
113
+ * - workAppGitHubMcpToolRepositoryAccess entries (for tools in this project)
114
+ * - workAppGitHubMcpToolAccessMode entries (for tools in this project)
115
+ *
116
+ * @param db - Runtime database client
117
+ * @returns Function that performs the cascade delete
118
+ */
119
+ declare const cascadeDeleteGitHubAccessByProject: (db: AgentsRunDatabaseClient) => (params: {
120
+ tenantId: string;
121
+ projectId: string;
122
+ }) => Promise<ProjectGitHubAccessCascadeDeleteResult>;
76
123
  //#endregion
77
- export { CascadeDeleteResult, cascadeDeleteByAgent, cascadeDeleteByBranch, cascadeDeleteByContextConfig, cascadeDeleteByProject, cascadeDeleteBySubAgent };
124
+ export { CascadeDeleteResult, ProjectGitHubAccessCascadeDeleteResult, ToolCascadeDeleteResult, cascadeDeleteByAgent, cascadeDeleteByBranch, cascadeDeleteByContextConfig, cascadeDeleteByProject, cascadeDeleteBySubAgent, cascadeDeleteByTool, cascadeDeleteGitHubAccessByProject };
@@ -1,4 +1,4 @@
1
- import { apiKeys, contextCache, conversations, tasks } from "../../db/runtime/runtime-schema.js";
1
+ import { apiKeys, contextCache, conversations, tasks, workAppGitHubMcpToolAccessMode, workAppGitHubMcpToolRepositoryAccess, workAppGitHubProjectAccessMode, workAppGitHubProjectRepositoryAccess } from "../../db/runtime/runtime-schema.js";
2
2
  import { and, eq, inArray, sql } from "drizzle-orm";
3
3
 
4
4
  //#region src/data-access/runtime/cascade-delete.ts
@@ -35,6 +35,10 @@ const cascadeDeleteByProject = (db) => async (params) => {
35
35
  const conversationsResult = await db.delete(conversations).where(and(eq(conversations.tenantId, scopes.tenantId), eq(conversations.projectId, scopes.projectId), sql`${conversations.ref}->>'name' = ${fullBranchName}`)).returning();
36
36
  const tasksResult = await db.delete(tasks).where(and(eq(tasks.tenantId, scopes.tenantId), eq(tasks.projectId, scopes.projectId), sql`${tasks.ref}->>'name' = ${fullBranchName}`)).returning();
37
37
  const apiKeysResult = await db.delete(apiKeys).where(and(eq(apiKeys.tenantId, scopes.tenantId), eq(apiKeys.projectId, scopes.projectId))).returning();
38
+ await cascadeDeleteGitHubAccessByProject(db)({
39
+ tenantId: scopes.tenantId,
40
+ projectId: scopes.projectId
41
+ });
38
42
  return {
39
43
  conversationsDeleted: conversationsResult.length,
40
44
  tasksDeleted: tasksResult.length,
@@ -106,6 +110,52 @@ const cascadeDeleteByContextConfig = (db) => async (params) => {
106
110
  const { scopes, contextConfigId, fullBranchName } = params;
107
111
  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 };
108
112
  };
113
+ /**
114
+ * Delete all runtime entities for a specific MCP tool.
115
+ * Called when an MCP tool is deleted from the manage database.
116
+ *
117
+ * Cleans up:
118
+ * - workAppGitHubMcpToolRepositoryAccess entries
119
+ * - workAppGitHubMcpToolAccessMode entry
120
+ *
121
+ * @param db - Runtime database client
122
+ * @returns Function that performs the cascade delete
123
+ */
124
+ const cascadeDeleteByTool = (db) => async (params) => {
125
+ const { toolId } = params;
126
+ const repositoryAccessResult = await db.delete(workAppGitHubMcpToolRepositoryAccess).where(eq(workAppGitHubMcpToolRepositoryAccess.toolId, toolId)).returning();
127
+ const accessModeResult = await db.delete(workAppGitHubMcpToolAccessMode).where(eq(workAppGitHubMcpToolAccessMode.toolId, toolId)).returning();
128
+ return {
129
+ mcpToolRepositoryAccessDeleted: repositoryAccessResult.length,
130
+ mcpToolAccessModeDeleted: accessModeResult.length > 0
131
+ };
132
+ };
133
+ /**
134
+ * Delete all GitHub access runtime entities for a specific project.
135
+ * Called when a project is deleted from the manage database.
136
+ *
137
+ * Cleans up:
138
+ * - workAppGitHubProjectRepositoryAccess entries
139
+ * - workAppGitHubProjectAccessMode entry
140
+ * - workAppGitHubMcpToolRepositoryAccess entries (for tools in this project)
141
+ * - workAppGitHubMcpToolAccessMode entries (for tools in this project)
142
+ *
143
+ * @param db - Runtime database client
144
+ * @returns Function that performs the cascade delete
145
+ */
146
+ const cascadeDeleteGitHubAccessByProject = (db) => async (params) => {
147
+ const { tenantId, projectId } = params;
148
+ const projectRepoAccessResult = await db.delete(workAppGitHubProjectRepositoryAccess).where(and(eq(workAppGitHubProjectRepositoryAccess.tenantId, tenantId), eq(workAppGitHubProjectRepositoryAccess.projectId, projectId))).returning();
149
+ const projectAccessModeResult = await db.delete(workAppGitHubProjectAccessMode).where(and(eq(workAppGitHubProjectAccessMode.tenantId, tenantId), eq(workAppGitHubProjectAccessMode.projectId, projectId))).returning();
150
+ const mcpToolRepoAccessResult = await db.delete(workAppGitHubMcpToolRepositoryAccess).where(and(eq(workAppGitHubMcpToolRepositoryAccess.tenantId, tenantId), eq(workAppGitHubMcpToolRepositoryAccess.projectId, projectId))).returning();
151
+ const mcpToolAccessModeResult = await db.delete(workAppGitHubMcpToolAccessMode).where(and(eq(workAppGitHubMcpToolAccessMode.tenantId, tenantId), eq(workAppGitHubMcpToolAccessMode.projectId, projectId))).returning();
152
+ return {
153
+ projectRepositoryAccessDeleted: projectRepoAccessResult.length,
154
+ projectAccessModeDeleted: projectAccessModeResult.length > 0,
155
+ mcpToolRepositoryAccessDeleted: mcpToolRepoAccessResult.length,
156
+ mcpToolAccessModesDeleted: mcpToolAccessModeResult.length
157
+ };
158
+ };
109
159
 
110
160
  //#endregion
111
- export { cascadeDeleteByAgent, cascadeDeleteByBranch, cascadeDeleteByContextConfig, cascadeDeleteByProject, cascadeDeleteBySubAgent };
161
+ export { cascadeDeleteByAgent, cascadeDeleteByBranch, cascadeDeleteByContextConfig, cascadeDeleteByProject, cascadeDeleteBySubAgent, cascadeDeleteByTool, cascadeDeleteGitHubAccessByProject };