@inkeep/agents-core 0.58.14 → 0.58.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/auth-schema.d.ts +85 -85
- package/dist/auth/auth-validation-schemas.d.ts +135 -135
- package/dist/auth/auth.d.ts +9 -9
- package/dist/auth/auth.js +17 -45
- package/dist/auth/permissions.d.ts +9 -9
- package/dist/data-access/index.d.ts +4 -1
- package/dist/data-access/index.js +4 -1
- package/dist/data-access/manage/agentFull.js +28 -12
- package/dist/data-access/manage/agents.d.ts +25 -24
- package/dist/data-access/manage/agents.js +33 -33
- package/dist/data-access/manage/artifactComponents.d.ts +14 -14
- package/dist/data-access/manage/artifactComponents.js +14 -13
- package/dist/data-access/manage/audit-queries.js +6 -5
- package/dist/data-access/manage/contextConfigs.d.ts +12 -12
- package/dist/data-access/manage/contextConfigs.js +7 -6
- package/dist/data-access/manage/credentialReferences.js +12 -11
- package/dist/data-access/manage/dataComponents.d.ts +8 -8
- package/dist/data-access/manage/dataComponents.js +13 -11
- package/dist/data-access/manage/evalConfig.js +42 -41
- package/dist/data-access/manage/externalAgents.js +8 -7
- package/dist/data-access/manage/functionTools.d.ts +19 -23
- package/dist/data-access/manage/functionTools.js +27 -65
- package/dist/data-access/manage/functions.js +7 -10
- package/dist/data-access/manage/projects.js +37 -36
- package/dist/data-access/manage/scheduledTriggers.js +10 -6
- package/dist/data-access/manage/scheduledWorkflows.js +3 -2
- package/dist/data-access/manage/scope-helpers.d.ts +2 -1
- package/dist/data-access/manage/scope-helpers.js +2 -1
- package/dist/data-access/manage/skills.d.ts +17 -17
- package/dist/data-access/manage/skills.js +14 -9
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +24 -24
- package/dist/data-access/manage/subAgentRelations.d.ts +34 -34
- package/dist/data-access/manage/subAgentRelations.js +28 -26
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +24 -24
- package/dist/data-access/manage/subAgentTeamAgentRelations.js +16 -16
- package/dist/data-access/manage/subAgents.d.ts +12 -12
- package/dist/data-access/manage/subAgents.js +8 -7
- package/dist/data-access/manage/tools.d.ts +24 -24
- package/dist/data-access/manage/tools.js +8 -6
- package/dist/data-access/manage/triggers.js +12 -8
- package/dist/data-access/runtime/apiKeys.d.ts +16 -16
- package/dist/data-access/runtime/apiKeys.js +16 -12
- package/dist/data-access/runtime/apps.d.ts +8 -8
- package/dist/data-access/runtime/apps.js +8 -7
- package/dist/data-access/runtime/audit-queries.js +7 -7
- package/dist/data-access/runtime/auth.d.ts +18 -0
- package/dist/data-access/runtime/auth.js +35 -0
- package/dist/data-access/runtime/cascade-delete.js +29 -24
- package/dist/data-access/runtime/contextCache.d.ts +1 -0
- package/dist/data-access/runtime/contextCache.js +9 -8
- package/dist/data-access/runtime/conversations.d.ts +31 -31
- package/dist/data-access/runtime/conversations.js +8 -12
- package/dist/data-access/runtime/evalRuns.js +23 -22
- package/dist/data-access/runtime/github-work-app-installations.js +32 -21
- package/dist/data-access/runtime/ledgerArtifacts.js +9 -24
- package/dist/data-access/runtime/messages.d.ts +24 -24
- package/dist/data-access/runtime/messages.js +9 -8
- package/dist/data-access/runtime/projects.js +6 -5
- package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +3 -3
- package/dist/data-access/runtime/scheduledTriggerInvocations.js +16 -26
- package/dist/data-access/runtime/slack-work-app-mcp.js +6 -5
- package/dist/data-access/runtime/tasks.d.ts +12 -8
- package/dist/data-access/runtime/tasks.js +4 -5
- package/dist/data-access/runtime/triggerInvocations.js +4 -8
- package/dist/data-access/runtime/workAppSlack.js +21 -14
- package/dist/db/manage/manage-schema.d.ts +449 -449
- package/dist/db/runtime/runtime-schema.d.ts +332 -332
- package/dist/index.d.ts +6 -2
- package/dist/index.js +7 -1
- package/dist/retry/index.d.ts +3 -0
- package/dist/retry/index.js +4 -0
- package/dist/retry/retryable-errors.d.ts +10 -0
- package/dist/retry/retryable-errors.js +72 -0
- package/dist/retry/withRetry.d.ts +15 -0
- package/dist/retry/withRetry.js +37 -0
- package/dist/validation/dolt-schemas.d.ts +1 -1
- package/dist/validation/schemas.d.ts +412 -412
- package/package.json +1 -1
|
@@ -9,14 +9,14 @@ declare const getSubAgentTeamAgentRelationById: (db: AgentsManageDatabaseClient)
|
|
|
9
9
|
scopes: SubAgentScopeConfig;
|
|
10
10
|
relationId: string;
|
|
11
11
|
}) => Promise<{
|
|
12
|
+
tenantId: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
agentId: string;
|
|
15
|
+
subAgentId: string;
|
|
12
16
|
id: string;
|
|
13
17
|
createdAt: string;
|
|
14
18
|
updatedAt: string;
|
|
15
|
-
subAgentId: string;
|
|
16
|
-
projectId: string;
|
|
17
|
-
tenantId: string;
|
|
18
19
|
headers: Record<string, string> | null;
|
|
19
|
-
agentId: string;
|
|
20
20
|
targetAgentId: string;
|
|
21
21
|
} | undefined>;
|
|
22
22
|
declare const listSubAgentTeamAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -44,27 +44,27 @@ declare const listSubAgentTeamAgentRelations: (db: AgentsManageDatabaseClient) =
|
|
|
44
44
|
declare const getSubAgentTeamAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
|
|
45
45
|
scopes: SubAgentScopeConfig;
|
|
46
46
|
}) => Promise<{
|
|
47
|
+
tenantId: string;
|
|
48
|
+
projectId: string;
|
|
49
|
+
agentId: string;
|
|
50
|
+
subAgentId: string;
|
|
47
51
|
id: string;
|
|
48
52
|
createdAt: string;
|
|
49
53
|
updatedAt: string;
|
|
50
|
-
subAgentId: string;
|
|
51
|
-
projectId: string;
|
|
52
|
-
tenantId: string;
|
|
53
54
|
headers: Record<string, string> | null;
|
|
54
|
-
agentId: string;
|
|
55
55
|
targetAgentId: string;
|
|
56
56
|
}[]>;
|
|
57
57
|
declare const getSubAgentTeamAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
58
58
|
scopes: AgentScopeConfig;
|
|
59
59
|
}) => Promise<{
|
|
60
|
+
tenantId: string;
|
|
61
|
+
projectId: string;
|
|
62
|
+
agentId: string;
|
|
63
|
+
subAgentId: string;
|
|
60
64
|
id: string;
|
|
61
65
|
createdAt: string;
|
|
62
66
|
updatedAt: string;
|
|
63
|
-
subAgentId: string;
|
|
64
|
-
projectId: string;
|
|
65
|
-
tenantId: string;
|
|
66
67
|
headers: Record<string, string> | null;
|
|
67
|
-
agentId: string;
|
|
68
68
|
targetAgentId: string;
|
|
69
69
|
}[]>;
|
|
70
70
|
declare const getSubAgentTeamAgentRelationsByTeamAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -210,14 +210,14 @@ declare const createSubAgentTeamAgentRelation: (db: AgentsManageDatabaseClient)
|
|
|
210
210
|
headers?: Record<string, string> | null;
|
|
211
211
|
};
|
|
212
212
|
}) => Promise<{
|
|
213
|
+
tenantId: string;
|
|
214
|
+
projectId: string;
|
|
215
|
+
agentId: string;
|
|
216
|
+
subAgentId: string;
|
|
213
217
|
id: string;
|
|
214
218
|
createdAt: string;
|
|
215
219
|
updatedAt: string;
|
|
216
|
-
subAgentId: string;
|
|
217
|
-
projectId: string;
|
|
218
|
-
tenantId: string;
|
|
219
220
|
headers: Record<string, string> | null;
|
|
220
|
-
agentId: string;
|
|
221
221
|
targetAgentId: string;
|
|
222
222
|
}>;
|
|
223
223
|
/**
|
|
@@ -227,14 +227,14 @@ declare const getSubAgentTeamAgentRelationByParams: (db: AgentsManageDatabaseCli
|
|
|
227
227
|
scopes: SubAgentScopeConfig;
|
|
228
228
|
targetAgentId: string;
|
|
229
229
|
}) => Promise<{
|
|
230
|
+
tenantId: string;
|
|
231
|
+
projectId: string;
|
|
232
|
+
agentId: string;
|
|
233
|
+
subAgentId: string;
|
|
230
234
|
id: string;
|
|
231
235
|
createdAt: string;
|
|
232
236
|
updatedAt: string;
|
|
233
|
-
subAgentId: string;
|
|
234
|
-
projectId: string;
|
|
235
|
-
tenantId: string;
|
|
236
237
|
headers: Record<string, string> | null;
|
|
237
|
-
agentId: string;
|
|
238
238
|
targetAgentId: string;
|
|
239
239
|
} | undefined>;
|
|
240
240
|
/**
|
|
@@ -248,14 +248,14 @@ declare const upsertSubAgentTeamAgentRelation: (db: AgentsManageDatabaseClient)
|
|
|
248
248
|
headers?: Record<string, string> | null;
|
|
249
249
|
};
|
|
250
250
|
}) => Promise<{
|
|
251
|
+
tenantId: string;
|
|
252
|
+
projectId: string;
|
|
253
|
+
agentId: string;
|
|
254
|
+
subAgentId: string;
|
|
251
255
|
id: string;
|
|
252
256
|
createdAt: string;
|
|
253
257
|
updatedAt: string;
|
|
254
|
-
subAgentId: string;
|
|
255
|
-
projectId: string;
|
|
256
|
-
tenantId: string;
|
|
257
258
|
headers: Record<string, string> | null;
|
|
258
|
-
agentId: string;
|
|
259
259
|
targetAgentId: string;
|
|
260
260
|
}>;
|
|
261
261
|
declare const updateSubAgentTeamAgentRelation: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { agents, subAgentTeamAgentRelations, subAgents } from "../../db/manage/manage-schema.js";
|
|
2
|
+
import { agentScopedWhere, subAgentScopedWhere } from "./scope-helpers.js";
|
|
2
3
|
import { and, count, desc, eq } from "drizzle-orm";
|
|
3
4
|
import { nanoid } from "nanoid";
|
|
4
5
|
|
|
5
6
|
//#region src/data-access/manage/subAgentTeamAgentRelations.ts
|
|
6
7
|
const getSubAgentTeamAgentRelationById = (db) => async (params) => {
|
|
7
|
-
return db.query.subAgentTeamAgentRelations.findFirst({ where: and(
|
|
8
|
+
return db.query.subAgentTeamAgentRelations.findFirst({ where: and(subAgentScopedWhere(subAgentTeamAgentRelations, params.scopes), eq(subAgentTeamAgentRelations.id, params.relationId)) });
|
|
8
9
|
};
|
|
9
10
|
const listSubAgentTeamAgentRelations = (db) => async (params) => {
|
|
10
11
|
const page = params.pagination?.page || 1;
|
|
11
12
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
12
13
|
const offset = (page - 1) * limit;
|
|
13
|
-
const whereClause =
|
|
14
|
+
const whereClause = subAgentScopedWhere(subAgentTeamAgentRelations, params.scopes);
|
|
14
15
|
const [data, totalResult] = await Promise.all([db.select().from(subAgentTeamAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentTeamAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentTeamAgentRelations).where(whereClause)]);
|
|
15
16
|
const total = totalResult[0]?.count || 0;
|
|
16
17
|
return {
|
|
@@ -24,16 +25,16 @@ const listSubAgentTeamAgentRelations = (db) => async (params) => {
|
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
const getSubAgentTeamAgentRelations = (db) => async (params) => {
|
|
27
|
-
return await db.query.subAgentTeamAgentRelations.findMany({ where:
|
|
28
|
+
return await db.query.subAgentTeamAgentRelations.findMany({ where: subAgentScopedWhere(subAgentTeamAgentRelations, params.scopes) });
|
|
28
29
|
};
|
|
29
30
|
const getSubAgentTeamAgentRelationsByAgent = (db) => async (params) => {
|
|
30
|
-
return await db.query.subAgentTeamAgentRelations.findMany({ where:
|
|
31
|
+
return await db.query.subAgentTeamAgentRelations.findMany({ where: agentScopedWhere(subAgentTeamAgentRelations, params.scopes) });
|
|
31
32
|
};
|
|
32
33
|
const getSubAgentTeamAgentRelationsByTeamAgent = (db) => async (params) => {
|
|
33
34
|
const page = params.pagination?.page || 1;
|
|
34
35
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
35
36
|
const offset = (page - 1) * limit;
|
|
36
|
-
const whereClause = and(
|
|
37
|
+
const whereClause = and(agentScopedWhere(subAgentTeamAgentRelations, params.scopes), eq(subAgentTeamAgentRelations.targetAgentId, params.targetAgentId));
|
|
37
38
|
const [data, totalResult] = await Promise.all([db.select().from(subAgentTeamAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentTeamAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentTeamAgentRelations).where(whereClause)]);
|
|
38
39
|
const total = totalResult[0]?.count || 0;
|
|
39
40
|
return {
|
|
@@ -50,6 +51,7 @@ const getTeamAgentsForSubAgent = (db) => async (params) => {
|
|
|
50
51
|
const page = params.pagination?.page || 1;
|
|
51
52
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
52
53
|
const offset = (page - 1) * limit;
|
|
54
|
+
const whereClause = subAgentScopedWhere(subAgentTeamAgentRelations, params.scopes);
|
|
53
55
|
const [data, totalResult] = await Promise.all([db.select({
|
|
54
56
|
id: subAgentTeamAgentRelations.id,
|
|
55
57
|
tenantId: subAgentTeamAgentRelations.tenantId,
|
|
@@ -73,7 +75,7 @@ const getTeamAgentsForSubAgent = (db) => async (params) => {
|
|
|
73
75
|
createdAt: agents.createdAt,
|
|
74
76
|
updatedAt: agents.updatedAt
|
|
75
77
|
}
|
|
76
|
-
}).from(subAgentTeamAgentRelations).innerJoin(agents, and(eq(subAgentTeamAgentRelations.tenantId, agents.tenantId), eq(subAgentTeamAgentRelations.projectId, agents.projectId), eq(subAgentTeamAgentRelations.targetAgentId, agents.id))).where(
|
|
78
|
+
}).from(subAgentTeamAgentRelations).innerJoin(agents, and(eq(subAgentTeamAgentRelations.tenantId, agents.tenantId), eq(subAgentTeamAgentRelations.projectId, agents.projectId), eq(subAgentTeamAgentRelations.targetAgentId, agents.id))).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentTeamAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentTeamAgentRelations).where(whereClause)]);
|
|
77
79
|
const total = totalResult[0]?.count || 0;
|
|
78
80
|
return {
|
|
79
81
|
data,
|
|
@@ -89,6 +91,7 @@ const getSubAgentsForTeamAgent = (db) => async (params) => {
|
|
|
89
91
|
const page = params.pagination?.page || 1;
|
|
90
92
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
91
93
|
const offset = (page - 1) * limit;
|
|
94
|
+
const whereClause = and(agentScopedWhere(subAgentTeamAgentRelations, params.scopes), eq(subAgentTeamAgentRelations.targetAgentId, params.targetAgentId));
|
|
92
95
|
const [data, totalResult] = await Promise.all([db.select({
|
|
93
96
|
id: subAgentTeamAgentRelations.id,
|
|
94
97
|
tenantId: subAgentTeamAgentRelations.tenantId,
|
|
@@ -109,7 +112,7 @@ const getSubAgentsForTeamAgent = (db) => async (params) => {
|
|
|
109
112
|
createdAt: subAgents.createdAt,
|
|
110
113
|
updatedAt: subAgents.updatedAt
|
|
111
114
|
}
|
|
112
|
-
}).from(subAgentTeamAgentRelations).innerJoin(subAgents, and(eq(subAgentTeamAgentRelations.subAgentId, subAgents.id), eq(subAgentTeamAgentRelations.tenantId, subAgents.tenantId), eq(subAgentTeamAgentRelations.projectId, subAgents.projectId), eq(subAgentTeamAgentRelations.agentId, subAgents.agentId))).where(
|
|
115
|
+
}).from(subAgentTeamAgentRelations).innerJoin(subAgents, and(eq(subAgentTeamAgentRelations.subAgentId, subAgents.id), eq(subAgentTeamAgentRelations.tenantId, subAgents.tenantId), eq(subAgentTeamAgentRelations.projectId, subAgents.projectId), eq(subAgentTeamAgentRelations.agentId, subAgents.agentId))).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentTeamAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentTeamAgentRelations).where(whereClause)]);
|
|
113
116
|
const total = totalResult[0]?.count || 0;
|
|
114
117
|
return {
|
|
115
118
|
data,
|
|
@@ -125,10 +128,7 @@ const createSubAgentTeamAgentRelation = (db) => async (params) => {
|
|
|
125
128
|
const finalRelationId = params.relationId ?? nanoid();
|
|
126
129
|
return (await db.insert(subAgentTeamAgentRelations).values({
|
|
127
130
|
id: finalRelationId,
|
|
128
|
-
|
|
129
|
-
projectId: params.scopes.projectId,
|
|
130
|
-
agentId: params.scopes.agentId,
|
|
131
|
-
subAgentId: params.scopes.subAgentId,
|
|
131
|
+
...params.scopes,
|
|
132
132
|
targetAgentId: params.data.targetAgentId,
|
|
133
133
|
headers: params.data.headers
|
|
134
134
|
}).returning())[0];
|
|
@@ -137,7 +137,7 @@ const createSubAgentTeamAgentRelation = (db) => async (params) => {
|
|
|
137
137
|
* Check if sub-agent team agent relation exists by params
|
|
138
138
|
*/
|
|
139
139
|
const getSubAgentTeamAgentRelationByParams = (db) => async (params) => {
|
|
140
|
-
return db.query.subAgentTeamAgentRelations.findFirst({ where: and(
|
|
140
|
+
return db.query.subAgentTeamAgentRelations.findFirst({ where: and(subAgentScopedWhere(subAgentTeamAgentRelations, params.scopes), eq(subAgentTeamAgentRelations.targetAgentId, params.targetAgentId)) });
|
|
141
141
|
};
|
|
142
142
|
/**
|
|
143
143
|
* Upsert sub-agent team agent relation (create if it doesn't exist, update if it does)
|
|
@@ -164,16 +164,16 @@ const updateSubAgentTeamAgentRelation = (db) => async (params) => {
|
|
|
164
164
|
...params.data,
|
|
165
165
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
166
166
|
};
|
|
167
|
-
return (await db.update(subAgentTeamAgentRelations).set(updateData).where(and(
|
|
167
|
+
return (await db.update(subAgentTeamAgentRelations).set(updateData).where(and(subAgentScopedWhere(subAgentTeamAgentRelations, params.scopes), eq(subAgentTeamAgentRelations.id, params.relationId))).returning())[0];
|
|
168
168
|
};
|
|
169
169
|
const deleteSubAgentTeamAgentRelation = (db) => async (params) => {
|
|
170
|
-
return (await db.delete(subAgentTeamAgentRelations).where(and(
|
|
170
|
+
return (await db.delete(subAgentTeamAgentRelations).where(and(subAgentScopedWhere(subAgentTeamAgentRelations, params.scopes), eq(subAgentTeamAgentRelations.id, params.relationId))).returning()).length > 0;
|
|
171
171
|
};
|
|
172
172
|
const deleteSubAgentTeamAgentRelationsBySubAgent = (db) => async (params) => {
|
|
173
|
-
return (await db.delete(subAgentTeamAgentRelations).where(
|
|
173
|
+
return (await db.delete(subAgentTeamAgentRelations).where(subAgentScopedWhere(subAgentTeamAgentRelations, params.scopes)).returning()).length > 0;
|
|
174
174
|
};
|
|
175
175
|
const deleteSubAgentTeamAgentRelationsByAgent = (db) => async (params) => {
|
|
176
|
-
return (await db.delete(subAgentTeamAgentRelations).where(
|
|
176
|
+
return (await db.delete(subAgentTeamAgentRelations).where(agentScopedWhere(subAgentTeamAgentRelations, params.scopes)).returning()).length > 0;
|
|
177
177
|
};
|
|
178
178
|
|
|
179
179
|
//#endregion
|
|
@@ -9,13 +9,14 @@ declare const getSubAgentById: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
9
9
|
scopes: AgentScopeConfig;
|
|
10
10
|
subAgentId: string;
|
|
11
11
|
}) => Promise<{
|
|
12
|
+
tenantId: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
agentId: string;
|
|
12
15
|
id: string;
|
|
13
16
|
name: string;
|
|
17
|
+
description: string | null;
|
|
14
18
|
createdAt: string;
|
|
15
19
|
updatedAt: string;
|
|
16
|
-
description: string | null;
|
|
17
|
-
projectId: string;
|
|
18
|
-
tenantId: string;
|
|
19
20
|
models: {
|
|
20
21
|
base?: {
|
|
21
22
|
model?: string | undefined;
|
|
@@ -35,18 +36,18 @@ declare const getSubAgentById: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
35
36
|
} | null;
|
|
36
37
|
prompt: string | null;
|
|
37
38
|
conversationHistoryConfig: ConversationHistoryConfig | null;
|
|
38
|
-
agentId: string;
|
|
39
39
|
} | undefined>;
|
|
40
40
|
declare const listSubAgents: (db: AgentsManageDatabaseClient) => (params: {
|
|
41
41
|
scopes: AgentScopeConfig;
|
|
42
42
|
}) => Promise<{
|
|
43
|
+
tenantId: string;
|
|
44
|
+
projectId: string;
|
|
45
|
+
agentId: string;
|
|
43
46
|
id: string;
|
|
44
47
|
name: string;
|
|
48
|
+
description: string | null;
|
|
45
49
|
createdAt: string;
|
|
46
50
|
updatedAt: string;
|
|
47
|
-
description: string | null;
|
|
48
|
-
projectId: string;
|
|
49
|
-
tenantId: string;
|
|
50
51
|
models: {
|
|
51
52
|
base?: {
|
|
52
53
|
model?: string | undefined;
|
|
@@ -66,7 +67,6 @@ declare const listSubAgents: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
66
67
|
} | null;
|
|
67
68
|
prompt: string | null;
|
|
68
69
|
conversationHistoryConfig: ConversationHistoryConfig | null;
|
|
69
|
-
agentId: string;
|
|
70
70
|
}[]>;
|
|
71
71
|
declare const listSubAgentsPaginated: (db: AgentsManageDatabaseClient) => (params: {
|
|
72
72
|
scopes: AgentScopeConfig;
|
|
@@ -109,13 +109,14 @@ declare const listSubAgentsPaginated: (db: AgentsManageDatabaseClient) => (param
|
|
|
109
109
|
};
|
|
110
110
|
}>;
|
|
111
111
|
declare const createSubAgent: (db: AgentsManageDatabaseClient) => (params: SubAgentInsert) => Promise<{
|
|
112
|
+
tenantId: string;
|
|
113
|
+
projectId: string;
|
|
114
|
+
agentId: string;
|
|
112
115
|
id: string;
|
|
113
116
|
name: string;
|
|
117
|
+
description: string | null;
|
|
114
118
|
createdAt: string;
|
|
115
119
|
updatedAt: string;
|
|
116
|
-
description: string | null;
|
|
117
|
-
projectId: string;
|
|
118
|
-
tenantId: string;
|
|
119
120
|
models: {
|
|
120
121
|
base?: {
|
|
121
122
|
model?: string | undefined;
|
|
@@ -135,7 +136,6 @@ declare const createSubAgent: (db: AgentsManageDatabaseClient) => (params: SubAg
|
|
|
135
136
|
} | null;
|
|
136
137
|
prompt: string | null;
|
|
137
138
|
conversationHistoryConfig: ConversationHistoryConfig | null;
|
|
138
|
-
agentId: string;
|
|
139
139
|
}>;
|
|
140
140
|
declare const updateSubAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
141
141
|
scopes: AgentScopeConfig;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { agents, subAgents } from "../../db/manage/manage-schema.js";
|
|
2
|
+
import { agentScopedWhere, projectScopedWhere } from "./scope-helpers.js";
|
|
2
3
|
import { and, count, desc, eq, inArray } from "drizzle-orm";
|
|
3
4
|
|
|
4
5
|
//#region src/data-access/manage/subAgents.ts
|
|
5
6
|
const getSubAgentById = (db) => async (params) => {
|
|
6
|
-
return await db.query.subAgents.findFirst({ where: and(
|
|
7
|
+
return await db.query.subAgents.findFirst({ where: and(agentScopedWhere(subAgents, params.scopes), eq(subAgents.id, params.subAgentId)) });
|
|
7
8
|
};
|
|
8
9
|
const listSubAgents = (db) => async (params) => {
|
|
9
|
-
return await db.query.subAgents.findMany({ where:
|
|
10
|
+
return await db.query.subAgents.findMany({ where: agentScopedWhere(subAgents, params.scopes) });
|
|
10
11
|
};
|
|
11
12
|
const listSubAgentsPaginated = (db) => async (params) => {
|
|
12
13
|
const page = params.pagination?.page || 1;
|
|
13
14
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
14
15
|
const offset = (page - 1) * limit;
|
|
15
|
-
const whereClause =
|
|
16
|
+
const whereClause = agentScopedWhere(subAgents, params.scopes);
|
|
16
17
|
const [data, totalResult] = await Promise.all([db.select().from(subAgents).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgents.createdAt)), db.select({ count: count() }).from(subAgents).where(whereClause)]);
|
|
17
18
|
const total = totalResult[0]?.count || 0;
|
|
18
19
|
return {
|
|
@@ -37,7 +38,7 @@ const updateSubAgent = (db) => async (params) => {
|
|
|
37
38
|
...data,
|
|
38
39
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
39
40
|
};
|
|
40
|
-
return (await db.update(subAgents).set(updateData).where(and(
|
|
41
|
+
return (await db.update(subAgents).set(updateData).where(and(agentScopedWhere(subAgents, params.scopes), inArray(subAgents.id, [params.subAgentId]))).returning())[0] ?? null;
|
|
41
42
|
};
|
|
42
43
|
/**
|
|
43
44
|
* Upsert agent (create if it doesn't exist, update if it does)
|
|
@@ -78,8 +79,8 @@ var SubAgentIsDefaultError = class extends Error {
|
|
|
78
79
|
}
|
|
79
80
|
};
|
|
80
81
|
const deleteSubAgent = (db) => async (params) => {
|
|
81
|
-
if ((await db.select().from(agents).where(and(
|
|
82
|
-
await db.delete(subAgents).where(and(
|
|
82
|
+
if ((await db.select().from(agents).where(and(projectScopedWhere(agents, params.scopes), eq(agents.id, params.scopes.agentId), eq(agents.defaultSubAgentId, params.subAgentId))).limit(1)).length > 0) throw new SubAgentIsDefaultError(params.subAgentId, params.scopes.agentId);
|
|
83
|
+
await db.delete(subAgents).where(and(agentScopedWhere(subAgents, params.scopes), inArray(subAgents.id, [params.subAgentId])));
|
|
83
84
|
return await getSubAgentById(db)({
|
|
84
85
|
scopes: params.scopes,
|
|
85
86
|
subAgentId: params.subAgentId
|
|
@@ -87,7 +88,7 @@ const deleteSubAgent = (db) => async (params) => {
|
|
|
87
88
|
};
|
|
88
89
|
const getSubAgentsByIds = (db) => async (params) => {
|
|
89
90
|
if (params.subAgentIds.length === 0) return [];
|
|
90
|
-
return await db.select().from(subAgents).where(and(
|
|
91
|
+
return await db.select().from(subAgents).where(and(agentScopedWhere(subAgents, params.scopes), inArray(subAgents.id, params.subAgentIds)));
|
|
91
92
|
};
|
|
92
93
|
|
|
93
94
|
//#endregion
|
|
@@ -20,13 +20,13 @@ declare const getToolById: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
20
20
|
scopes: ProjectScopeConfig;
|
|
21
21
|
toolId: string;
|
|
22
22
|
}) => Promise<{
|
|
23
|
+
tenantId: string;
|
|
24
|
+
projectId: string;
|
|
23
25
|
id: string;
|
|
24
26
|
name: string;
|
|
27
|
+
description: string | null;
|
|
25
28
|
createdAt: string;
|
|
26
29
|
updatedAt: string;
|
|
27
|
-
description: string | null;
|
|
28
|
-
projectId: string;
|
|
29
|
-
tenantId: string;
|
|
30
30
|
headers: Record<string, string> | null;
|
|
31
31
|
config: {
|
|
32
32
|
type: "mcp";
|
|
@@ -78,13 +78,13 @@ declare const listTools: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
78
78
|
};
|
|
79
79
|
}>;
|
|
80
80
|
declare const createTool: (db: AgentsManageDatabaseClient) => (params: ToolInsert) => Promise<{
|
|
81
|
+
tenantId: string;
|
|
82
|
+
projectId: string;
|
|
81
83
|
id: string;
|
|
82
84
|
name: string;
|
|
85
|
+
description: string | null;
|
|
83
86
|
createdAt: string;
|
|
84
87
|
updatedAt: string;
|
|
85
|
-
description: string | null;
|
|
86
|
-
projectId: string;
|
|
87
|
-
tenantId: string;
|
|
88
88
|
headers: Record<string, string> | null;
|
|
89
89
|
config: {
|
|
90
90
|
type: "mcp";
|
|
@@ -135,15 +135,15 @@ declare const addToolToAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
135
135
|
needsApproval?: boolean;
|
|
136
136
|
}> | null;
|
|
137
137
|
}) => Promise<{
|
|
138
|
+
tenantId: string;
|
|
139
|
+
projectId: string;
|
|
140
|
+
agentId: string;
|
|
141
|
+
subAgentId: string;
|
|
142
|
+
toolId: string;
|
|
138
143
|
id: string;
|
|
139
144
|
createdAt: string;
|
|
140
145
|
updatedAt: string;
|
|
141
|
-
subAgentId: string;
|
|
142
|
-
projectId: string;
|
|
143
|
-
tenantId: string;
|
|
144
146
|
headers: Record<string, string> | null;
|
|
145
|
-
agentId: string;
|
|
146
|
-
toolId: string;
|
|
147
147
|
toolPolicies: Record<string, {
|
|
148
148
|
needsApproval?: boolean;
|
|
149
149
|
}> | null;
|
|
@@ -154,15 +154,15 @@ declare const removeToolFromAgent: (db: AgentsManageDatabaseClient) => (params:
|
|
|
154
154
|
subAgentId: string;
|
|
155
155
|
toolId: string;
|
|
156
156
|
}) => Promise<{
|
|
157
|
+
tenantId: string;
|
|
158
|
+
projectId: string;
|
|
159
|
+
agentId: string;
|
|
160
|
+
subAgentId: string;
|
|
161
|
+
toolId: string;
|
|
157
162
|
id: string;
|
|
158
163
|
createdAt: string;
|
|
159
164
|
updatedAt: string;
|
|
160
|
-
subAgentId: string;
|
|
161
|
-
projectId: string;
|
|
162
|
-
tenantId: string;
|
|
163
165
|
headers: Record<string, string> | null;
|
|
164
|
-
agentId: string;
|
|
165
|
-
toolId: string;
|
|
166
166
|
toolPolicies: Record<string, {
|
|
167
167
|
needsApproval?: boolean;
|
|
168
168
|
}> | null;
|
|
@@ -182,15 +182,15 @@ declare const upsertSubAgentToolRelation: (db: AgentsManageDatabaseClient) => (p
|
|
|
182
182
|
}> | null;
|
|
183
183
|
relationId?: string;
|
|
184
184
|
}) => Promise<{
|
|
185
|
+
tenantId: string;
|
|
186
|
+
projectId: string;
|
|
187
|
+
agentId: string;
|
|
188
|
+
subAgentId: string;
|
|
189
|
+
toolId: string;
|
|
185
190
|
id: string;
|
|
186
191
|
createdAt: string;
|
|
187
192
|
updatedAt: string;
|
|
188
|
-
subAgentId: string;
|
|
189
|
-
projectId: string;
|
|
190
|
-
tenantId: string;
|
|
191
193
|
headers: Record<string, string> | null;
|
|
192
|
-
agentId: string;
|
|
193
|
-
toolId: string;
|
|
194
194
|
toolPolicies: Record<string, {
|
|
195
195
|
needsApproval?: boolean;
|
|
196
196
|
}> | null;
|
|
@@ -202,13 +202,13 @@ declare const upsertSubAgentToolRelation: (db: AgentsManageDatabaseClient) => (p
|
|
|
202
202
|
declare const upsertTool: (db: AgentsManageDatabaseClient) => (params: {
|
|
203
203
|
data: ToolInsert;
|
|
204
204
|
}) => Promise<{
|
|
205
|
+
tenantId: string;
|
|
206
|
+
projectId: string;
|
|
205
207
|
id: string;
|
|
206
208
|
name: string;
|
|
209
|
+
description: string | null;
|
|
207
210
|
createdAt: string;
|
|
208
211
|
updatedAt: string;
|
|
209
|
-
description: string | null;
|
|
210
|
-
projectId: string;
|
|
211
|
-
tenantId: string;
|
|
212
212
|
headers: Record<string, string> | null;
|
|
213
213
|
config: {
|
|
214
214
|
type: "mcp";
|
|
@@ -9,9 +9,11 @@ import "../../credential-stuffer/index.js";
|
|
|
9
9
|
import { createAgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
10
10
|
import { generateId } from "../../utils/conversations.js";
|
|
11
11
|
import { getActiveBranch } from "../../dolt/schema-sync.js";
|
|
12
|
+
import { agentScopedWhere, projectScopedWhere } from "./scope-helpers.js";
|
|
12
13
|
import { isSlackWorkAppTool } from "../runtime/slack-work-app-mcp.js";
|
|
13
14
|
import { cascadeDeleteByTool } from "../runtime/cascade-delete.js";
|
|
14
15
|
import { updateAgentToolRelation } from "./subAgentRelations.js";
|
|
16
|
+
import { isSerializationError } from "../../retry/retryable-errors.js";
|
|
15
17
|
import { toISODateString } from "../../utils/date.js";
|
|
16
18
|
import { McpClient } from "../../utils/mcp-client.js";
|
|
17
19
|
import { configureComposioMCPServer } from "../../utils/third-party-mcp-servers/composio-client.js";
|
|
@@ -270,7 +272,7 @@ const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, re
|
|
|
270
272
|
}
|
|
271
273
|
});
|
|
272
274
|
} catch (updateError) {
|
|
273
|
-
if (
|
|
275
|
+
if (isSerializationError(updateError)) logger.debug({ toolId: dbResult.id }, "Skipping tool metadata update due to serialization conflict (concurrent request)");
|
|
274
276
|
else logger.warn({
|
|
275
277
|
toolId: dbResult.id,
|
|
276
278
|
error: updateError
|
|
@@ -293,7 +295,7 @@ const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, re
|
|
|
293
295
|
};
|
|
294
296
|
};
|
|
295
297
|
const getToolById = (db) => async (params) => {
|
|
296
|
-
return await db.query.tools.findFirst({ where: and(
|
|
298
|
+
return await db.query.tools.findFirst({ where: and(projectScopedWhere(tools, params.scopes), eq(tools.id, params.toolId)) }) ?? null;
|
|
297
299
|
};
|
|
298
300
|
const getMcpToolById = (db) => async (params) => {
|
|
299
301
|
const tool = await getToolById(db)({
|
|
@@ -307,7 +309,7 @@ const listTools = (db) => async (params) => {
|
|
|
307
309
|
const page = params.pagination?.page || 1;
|
|
308
310
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
309
311
|
const offset = (page - 1) * limit;
|
|
310
|
-
const whereClause =
|
|
312
|
+
const whereClause = projectScopedWhere(tools, params.scopes);
|
|
311
313
|
const [toolsDbResults, totalResult] = await Promise.all([db.select().from(tools).where(whereClause).limit(limit).offset(offset).orderBy(desc(tools.createdAt)), db.select({ count: count() }).from(tools).where(whereClause)]);
|
|
312
314
|
const total = totalResult[0]?.count || 0;
|
|
313
315
|
return {
|
|
@@ -334,11 +336,11 @@ const updateTool = (db) => async (params) => {
|
|
|
334
336
|
const [updated] = await db.update(tools).set({
|
|
335
337
|
...params.data,
|
|
336
338
|
updatedAt: now
|
|
337
|
-
}).where(and(
|
|
339
|
+
}).where(and(projectScopedWhere(tools, params.scopes), eq(tools.id, params.toolId))).returning();
|
|
338
340
|
return updated ?? null;
|
|
339
341
|
};
|
|
340
342
|
const deleteTool = (db) => async (params) => {
|
|
341
|
-
const [deleted] = await db.delete(tools).where(and(
|
|
343
|
+
const [deleted] = await db.delete(tools).where(and(projectScopedWhere(tools, params.scopes), eq(tools.id, params.toolId))).returning();
|
|
342
344
|
if (!deleted) return false;
|
|
343
345
|
if (deleted.isWorkApp && deleted.config.mcp.server.url.includes("/github/mcp") || isSlackWorkAppTool(deleted)) try {
|
|
344
346
|
if (await getActiveBranch(db)() === `${params.scopes.tenantId}_${params.scopes.projectId}_main`) await cascadeDeleteByTool(createAgentsRunDatabaseClient())({
|
|
@@ -373,7 +375,7 @@ const addToolToAgent = (db) => async (params) => {
|
|
|
373
375
|
return created;
|
|
374
376
|
};
|
|
375
377
|
const removeToolFromAgent = (db) => async (params) => {
|
|
376
|
-
const [deleted] = await db.delete(subAgentToolRelations).where(and(
|
|
378
|
+
const [deleted] = await db.delete(subAgentToolRelations).where(and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.subAgentId, params.subAgentId), eq(subAgentToolRelations.toolId, params.toolId))).returning();
|
|
377
379
|
return deleted;
|
|
378
380
|
};
|
|
379
381
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { triggers } from "../../db/manage/manage-schema.js";
|
|
2
|
+
import { agentScopedWhere, projectScopedWhere } from "./scope-helpers.js";
|
|
2
3
|
import { and, count, desc, eq } from "drizzle-orm";
|
|
3
4
|
|
|
4
5
|
//#region src/data-access/manage/triggers.ts
|
|
@@ -7,13 +8,13 @@ import { and, count, desc, eq } from "drizzle-orm";
|
|
|
7
8
|
*/
|
|
8
9
|
const getTriggerById = (db) => async (params) => {
|
|
9
10
|
const { scopes, triggerId } = params;
|
|
10
|
-
return await db.query.triggers.findFirst({ where: and(
|
|
11
|
+
return await db.query.triggers.findFirst({ where: and(agentScopedWhere(triggers, scopes), eq(triggers.id, triggerId)) });
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
14
|
* List all triggers for an agent
|
|
14
15
|
*/
|
|
15
16
|
const listTriggers = (db) => async (params) => {
|
|
16
|
-
return await db.query.triggers.findMany({ where:
|
|
17
|
+
return await db.query.triggers.findMany({ where: agentScopedWhere(triggers, params.scopes) });
|
|
17
18
|
};
|
|
18
19
|
/**
|
|
19
20
|
* List triggers for an agent with pagination
|
|
@@ -22,7 +23,7 @@ const listTriggersPaginated = (db) => async (params) => {
|
|
|
22
23
|
const page = params.pagination?.page || 1;
|
|
23
24
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
24
25
|
const offset = (page - 1) * limit;
|
|
25
|
-
const whereClause =
|
|
26
|
+
const whereClause = agentScopedWhere(triggers, params.scopes);
|
|
26
27
|
const [data, totalResult] = await Promise.all([db.select().from(triggers).where(whereClause).limit(limit).offset(offset).orderBy(desc(triggers.createdAt)), db.select({ count: count() }).from(triggers).where(whereClause)]);
|
|
27
28
|
const total = totalResult[0]?.count || 0;
|
|
28
29
|
return {
|
|
@@ -49,32 +50,35 @@ const updateTrigger = (db) => async (params) => {
|
|
|
49
50
|
...params.data,
|
|
50
51
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
51
52
|
};
|
|
52
|
-
return (await db.update(triggers).set(updateData).where(and(
|
|
53
|
+
return (await db.update(triggers).set(updateData).where(and(agentScopedWhere(triggers, params.scopes), eq(triggers.id, params.triggerId))).returning())[0];
|
|
53
54
|
};
|
|
54
55
|
/**
|
|
55
56
|
* Delete a trigger (agent-scoped)
|
|
56
57
|
*/
|
|
57
58
|
const deleteTrigger = (db) => async (params) => {
|
|
58
|
-
await db.delete(triggers).where(and(
|
|
59
|
+
await db.delete(triggers).where(and(agentScopedWhere(triggers, params.scopes), eq(triggers.id, params.triggerId)));
|
|
59
60
|
};
|
|
60
61
|
/**
|
|
61
62
|
* Delete all webhook triggers for a given runAsUserId within a tenant+project scope.
|
|
62
63
|
* Operates across all agents in the project (not agent-scoped).
|
|
63
64
|
*/
|
|
64
65
|
const deleteTriggersByRunAsUserId = (db) => async (params) => {
|
|
65
|
-
await db.delete(triggers).where(and(
|
|
66
|
+
await db.delete(triggers).where(and(projectScopedWhere(triggers, {
|
|
67
|
+
tenantId: params.tenantId,
|
|
68
|
+
projectId: params.projectId
|
|
69
|
+
}), eq(triggers.runAsUserId, params.runAsUserId)));
|
|
66
70
|
};
|
|
67
71
|
/**
|
|
68
72
|
* Upsert a trigger (create or update based on existence)
|
|
69
73
|
*/
|
|
70
74
|
const upsertTrigger = (db) => async (params) => {
|
|
71
75
|
const { scopes, data } = params;
|
|
72
|
-
if (await db.query.triggers.findFirst({ where: and(
|
|
76
|
+
if (await db.query.triggers.findFirst({ where: and(agentScopedWhere(triggers, scopes), eq(triggers.id, data.id)) })) {
|
|
73
77
|
const updateData = {
|
|
74
78
|
...data,
|
|
75
79
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
76
80
|
};
|
|
77
|
-
return (await db.update(triggers).set(updateData).where(and(
|
|
81
|
+
return (await db.update(triggers).set(updateData).where(and(agentScopedWhere(triggers, scopes), eq(triggers.id, data.id))).returning())[0];
|
|
78
82
|
}
|
|
79
83
|
return (await db.insert(triggers).values({
|
|
80
84
|
...data,
|