@inkeep/agents-core 0.58.14 → 0.58.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/auth-schema.d.ts +85 -85
- package/dist/auth/auth-validation-schemas.d.ts +135 -135
- package/dist/auth/auth.js +17 -45
- package/dist/data-access/index.d.ts +5 -2
- package/dist/data-access/index.js +5 -2
- package/dist/data-access/manage/agentFull.js +28 -12
- package/dist/data-access/manage/agents.d.ts +35 -34
- package/dist/data-access/manage/agents.js +33 -33
- package/dist/data-access/manage/artifactComponents.d.ts +12 -12
- 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 +6 -6
- 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 +17 -21
- 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 +14 -14
- 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 +28 -28
- 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 +18 -18
- 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 +20 -20
- package/dist/data-access/runtime/apiKeys.js +16 -12
- package/dist/data-access/runtime/apps.d.ts +10 -10
- 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 +27 -27
- 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 -19
- package/dist/data-access/runtime/messages.js +15 -9
- package/dist/data-access/runtime/projects.js +6 -5
- 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 +10 -6
- 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 +357 -357
- package/dist/db/runtime/runtime-schema.d.ts +300 -300
- package/dist/index.d.ts +7 -3
- package/dist/index.js +8 -2
- 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 +1704 -1704
- package/package.json +1 -1
|
@@ -10,12 +10,12 @@ declare const getSkillById: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
10
10
|
}) => Promise<{
|
|
11
11
|
id: string;
|
|
12
12
|
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
tenantId: string;
|
|
15
|
+
projectId: string;
|
|
13
16
|
createdAt: string;
|
|
14
17
|
updatedAt: string;
|
|
15
18
|
metadata: Record<string, string> | null;
|
|
16
|
-
description: string;
|
|
17
|
-
projectId: string;
|
|
18
|
-
tenantId: string;
|
|
19
19
|
content: string;
|
|
20
20
|
} | null>;
|
|
21
21
|
declare const listSkills: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -43,23 +43,23 @@ declare const listSkills: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
43
43
|
declare const createSkill: (db: AgentsManageDatabaseClient) => (data: SkillInsert) => Promise<{
|
|
44
44
|
id: string;
|
|
45
45
|
name: string;
|
|
46
|
+
description: string;
|
|
47
|
+
tenantId: string;
|
|
48
|
+
projectId: string;
|
|
46
49
|
createdAt: string;
|
|
47
50
|
updatedAt: string;
|
|
48
51
|
metadata: Record<string, string> | null;
|
|
49
|
-
description: string;
|
|
50
|
-
projectId: string;
|
|
51
|
-
tenantId: string;
|
|
52
52
|
content: string;
|
|
53
53
|
}>;
|
|
54
54
|
declare const upsertSkill: (db: AgentsManageDatabaseClient) => (data: SkillInsert) => Promise<{
|
|
55
55
|
id: string;
|
|
56
56
|
name: string;
|
|
57
|
+
description: string;
|
|
58
|
+
tenantId: string;
|
|
59
|
+
projectId: string;
|
|
57
60
|
createdAt: string;
|
|
58
61
|
updatedAt: string;
|
|
59
62
|
metadata: Record<string, string> | null;
|
|
60
|
-
description: string;
|
|
61
|
-
projectId: string;
|
|
62
|
-
tenantId: string;
|
|
63
63
|
content: string;
|
|
64
64
|
}>;
|
|
65
65
|
declare const updateSkill: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -92,15 +92,15 @@ declare const upsertSubAgentSkill: (db: AgentsManageDatabaseClient) => (params:
|
|
|
92
92
|
alwaysLoaded?: boolean;
|
|
93
93
|
}) => Promise<{
|
|
94
94
|
id: string;
|
|
95
|
-
createdAt: string;
|
|
96
|
-
updatedAt: string;
|
|
97
|
-
subAgentId: string;
|
|
98
|
-
projectId: string;
|
|
99
95
|
tenantId: string;
|
|
96
|
+
projectId: string;
|
|
100
97
|
agentId: string;
|
|
101
|
-
|
|
98
|
+
createdAt: string;
|
|
99
|
+
updatedAt: string;
|
|
102
100
|
index: number;
|
|
103
101
|
alwaysLoaded: boolean;
|
|
102
|
+
subAgentId: string;
|
|
103
|
+
skillId: string;
|
|
104
104
|
}>;
|
|
105
105
|
declare const deleteSubAgentSkill: (db: AgentsManageDatabaseClient) => (params: {
|
|
106
106
|
scopes: AgentScopeConfig;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { skills, subAgentSkills } from "../../db/manage/manage-schema.js";
|
|
2
2
|
import { getLogger } from "../../utils/logger.js";
|
|
3
3
|
import { generateId } from "../../utils/conversations.js";
|
|
4
|
+
import { agentScopedWhere, projectScopedWhere, subAgentScopedWhere } from "./scope-helpers.js";
|
|
4
5
|
import "../../index.js";
|
|
5
6
|
import { and, asc, count, desc, eq, inArray } from "drizzle-orm";
|
|
6
7
|
|
|
7
8
|
//#region src/data-access/manage/skills.ts
|
|
8
9
|
const logger = getLogger("skills-dal");
|
|
9
10
|
const getSkillById = (db) => async (params) => {
|
|
10
|
-
return await db.query.skills.findFirst({ where: and(
|
|
11
|
+
return await db.query.skills.findFirst({ where: and(projectScopedWhere(skills, params.scopes), eq(skills.id, params.skillId)) }) ?? null;
|
|
11
12
|
};
|
|
12
13
|
const listSkills = (db) => async (params) => {
|
|
13
14
|
const page = params.pagination?.page || 1;
|
|
14
15
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
15
16
|
const offset = (page - 1) * limit;
|
|
16
|
-
const whereClause =
|
|
17
|
+
const whereClause = projectScopedWhere(skills, params.scopes);
|
|
17
18
|
const [data, totalResult] = await Promise.all([db.select().from(skills).where(whereClause).limit(limit).offset(offset).orderBy(desc(skills.createdAt)), db.select({ count: count() }).from(skills).where(whereClause)]);
|
|
18
19
|
const total = totalResult[0]?.count || 0;
|
|
19
20
|
return {
|
|
@@ -43,14 +44,18 @@ const upsertSkill = (db) => async (data) => {
|
|
|
43
44
|
...data,
|
|
44
45
|
id: data.name
|
|
45
46
|
};
|
|
46
|
-
|
|
47
|
+
const scopes = {
|
|
48
|
+
tenantId: baseData.tenantId,
|
|
49
|
+
projectId: baseData.projectId
|
|
50
|
+
};
|
|
51
|
+
if (await db.query.skills.findFirst({ where: and(projectScopedWhere(skills, scopes), eq(skills.id, baseData.id)) })) {
|
|
47
52
|
const [result$1] = await db.update(skills).set({
|
|
48
53
|
name: baseData.name,
|
|
49
54
|
description: baseData.description,
|
|
50
55
|
content: baseData.content,
|
|
51
56
|
metadata: baseData.metadata,
|
|
52
57
|
updatedAt: now
|
|
53
|
-
}).where(and(
|
|
58
|
+
}).where(and(projectScopedWhere(skills, scopes), eq(skills.id, baseData.id))).returning();
|
|
54
59
|
logger.info({ skillId: baseData.id }, "Updated skill");
|
|
55
60
|
return result$1;
|
|
56
61
|
}
|
|
@@ -69,11 +74,11 @@ const updateSkill = (db) => async (params) => {
|
|
|
69
74
|
...data,
|
|
70
75
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
71
76
|
};
|
|
72
|
-
const [result] = await db.update(skills).set(updateData).where(and(
|
|
77
|
+
const [result] = await db.update(skills).set(updateData).where(and(projectScopedWhere(skills, params.scopes), eq(skills.id, params.skillId))).returning();
|
|
73
78
|
return result ?? null;
|
|
74
79
|
};
|
|
75
80
|
const deleteSkill = (db) => async (params) => {
|
|
76
|
-
return (await db.delete(skills).where(and(
|
|
81
|
+
return (await db.delete(skills).where(and(projectScopedWhere(skills, params.scopes), eq(skills.id, params.skillId))).returning()).length > 0;
|
|
77
82
|
};
|
|
78
83
|
const getSkillsForSubAgents = (db) => async (params) => {
|
|
79
84
|
if (!params.subAgentIds.length) return [];
|
|
@@ -89,11 +94,11 @@ const getSkillsForSubAgents = (db) => async (params) => {
|
|
|
89
94
|
metadata: skills.metadata,
|
|
90
95
|
createdAt: skills.createdAt,
|
|
91
96
|
updatedAt: skills.updatedAt
|
|
92
|
-
}).from(subAgentSkills).innerJoin(skills, and(eq(subAgentSkills.skillId, skills.id), eq(subAgentSkills.tenantId, skills.tenantId), eq(subAgentSkills.projectId, skills.projectId))).where(and(
|
|
97
|
+
}).from(subAgentSkills).innerJoin(skills, and(eq(subAgentSkills.skillId, skills.id), eq(subAgentSkills.tenantId, skills.tenantId), eq(subAgentSkills.projectId, skills.projectId))).where(and(agentScopedWhere(subAgentSkills, params.scopes), inArray(subAgentSkills.subAgentId, params.subAgentIds))).orderBy(asc(subAgentSkills.index), asc(subAgentSkills.createdAt));
|
|
93
98
|
};
|
|
94
99
|
const upsertSubAgentSkill = (db) => async (params) => {
|
|
95
100
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
96
|
-
const existing = await db.query.subAgentSkills.findFirst({ where: and(
|
|
101
|
+
const existing = await db.query.subAgentSkills.findFirst({ where: and(subAgentScopedWhere(subAgentSkills, params.scopes), eq(subAgentSkills.skillId, params.skillId)) });
|
|
97
102
|
if (existing) {
|
|
98
103
|
const [result$1] = await db.update(subAgentSkills).set({
|
|
99
104
|
index: params.index,
|
|
@@ -115,7 +120,7 @@ const upsertSubAgentSkill = (db) => async (params) => {
|
|
|
115
120
|
return result;
|
|
116
121
|
};
|
|
117
122
|
const deleteSubAgentSkill = (db) => async (params) => {
|
|
118
|
-
return (await db.delete(subAgentSkills).where(and(
|
|
123
|
+
return (await db.delete(subAgentSkills).where(and(agentScopedWhere(subAgentSkills, params.scopes), eq(subAgentSkills.id, params.subAgentSkillId))).returning()).length > 0;
|
|
119
124
|
};
|
|
120
125
|
|
|
121
126
|
//#endregion
|
|
@@ -10,14 +10,14 @@ declare const getSubAgentExternalAgentRelationById: (db: AgentsManageDatabaseCli
|
|
|
10
10
|
relationId: string;
|
|
11
11
|
}) => Promise<{
|
|
12
12
|
id: string;
|
|
13
|
+
tenantId: string;
|
|
14
|
+
projectId: string;
|
|
15
|
+
agentId: string;
|
|
13
16
|
createdAt: string;
|
|
14
17
|
updatedAt: string;
|
|
15
|
-
subAgentId: string;
|
|
16
|
-
projectId: string;
|
|
17
|
-
tenantId: string;
|
|
18
18
|
headers: Record<string, string> | null;
|
|
19
|
-
agentId: string;
|
|
20
19
|
externalAgentId: string;
|
|
20
|
+
subAgentId: string;
|
|
21
21
|
} | undefined>;
|
|
22
22
|
declare const listSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
|
|
23
23
|
scopes: SubAgentScopeConfig;
|
|
@@ -45,27 +45,27 @@ declare const getSubAgentExternalAgentRelations: (db: AgentsManageDatabaseClient
|
|
|
45
45
|
scopes: SubAgentScopeConfig;
|
|
46
46
|
}) => Promise<{
|
|
47
47
|
id: string;
|
|
48
|
+
tenantId: string;
|
|
49
|
+
projectId: string;
|
|
50
|
+
agentId: string;
|
|
48
51
|
createdAt: string;
|
|
49
52
|
updatedAt: string;
|
|
50
|
-
subAgentId: string;
|
|
51
|
-
projectId: string;
|
|
52
|
-
tenantId: string;
|
|
53
53
|
headers: Record<string, string> | null;
|
|
54
|
-
agentId: string;
|
|
55
54
|
externalAgentId: string;
|
|
55
|
+
subAgentId: string;
|
|
56
56
|
}[]>;
|
|
57
57
|
declare const getSubAgentExternalAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
58
58
|
scopes: AgentScopeConfig;
|
|
59
59
|
}) => Promise<{
|
|
60
60
|
id: string;
|
|
61
|
+
tenantId: string;
|
|
62
|
+
projectId: string;
|
|
63
|
+
agentId: string;
|
|
61
64
|
createdAt: string;
|
|
62
65
|
updatedAt: string;
|
|
63
|
-
subAgentId: string;
|
|
64
|
-
projectId: string;
|
|
65
|
-
tenantId: string;
|
|
66
66
|
headers: Record<string, string> | null;
|
|
67
|
-
agentId: string;
|
|
68
67
|
externalAgentId: string;
|
|
68
|
+
subAgentId: string;
|
|
69
69
|
}[]>;
|
|
70
70
|
declare const getSubAgentExternalAgentRelationsByExternalAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
71
71
|
scopes: AgentScopeConfig;
|
|
@@ -181,14 +181,14 @@ declare const createSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClie
|
|
|
181
181
|
};
|
|
182
182
|
}) => Promise<{
|
|
183
183
|
id: string;
|
|
184
|
+
tenantId: string;
|
|
185
|
+
projectId: string;
|
|
186
|
+
agentId: string;
|
|
184
187
|
createdAt: string;
|
|
185
188
|
updatedAt: string;
|
|
186
|
-
subAgentId: string;
|
|
187
|
-
projectId: string;
|
|
188
|
-
tenantId: string;
|
|
189
189
|
headers: Record<string, string> | null;
|
|
190
|
-
agentId: string;
|
|
191
190
|
externalAgentId: string;
|
|
191
|
+
subAgentId: string;
|
|
192
192
|
}>;
|
|
193
193
|
/**
|
|
194
194
|
* Check if sub-agent external agent relation exists by params
|
|
@@ -198,14 +198,14 @@ declare const getSubAgentExternalAgentRelationByParams: (db: AgentsManageDatabas
|
|
|
198
198
|
externalAgentId: string;
|
|
199
199
|
}) => Promise<{
|
|
200
200
|
id: string;
|
|
201
|
+
tenantId: string;
|
|
202
|
+
projectId: string;
|
|
203
|
+
agentId: string;
|
|
201
204
|
createdAt: string;
|
|
202
205
|
updatedAt: string;
|
|
203
|
-
subAgentId: string;
|
|
204
|
-
projectId: string;
|
|
205
|
-
tenantId: string;
|
|
206
206
|
headers: Record<string, string> | null;
|
|
207
|
-
agentId: string;
|
|
208
207
|
externalAgentId: string;
|
|
208
|
+
subAgentId: string;
|
|
209
209
|
} | undefined>;
|
|
210
210
|
/**
|
|
211
211
|
* Upsert sub-agent external agent relation (create if it doesn't exist, update if it does)
|
|
@@ -219,14 +219,14 @@ declare const upsertSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClie
|
|
|
219
219
|
};
|
|
220
220
|
}) => Promise<{
|
|
221
221
|
id: string;
|
|
222
|
+
tenantId: string;
|
|
223
|
+
projectId: string;
|
|
224
|
+
agentId: string;
|
|
222
225
|
createdAt: string;
|
|
223
226
|
updatedAt: string;
|
|
224
|
-
subAgentId: string;
|
|
225
|
-
projectId: string;
|
|
226
|
-
tenantId: string;
|
|
227
227
|
headers: Record<string, string> | null;
|
|
228
|
-
agentId: string;
|
|
229
228
|
externalAgentId: string;
|
|
229
|
+
subAgentId: string;
|
|
230
230
|
}>;
|
|
231
231
|
declare const updateSubAgentExternalAgentRelation: (db: AgentsManageDatabaseClient) => (params: {
|
|
232
232
|
scopes: SubAgentScopeConfig;
|
|
@@ -10,11 +10,11 @@ declare const getAgentRelationById: (db: AgentsManageDatabaseClient) => (params:
|
|
|
10
10
|
relationId: string;
|
|
11
11
|
}) => Promise<{
|
|
12
12
|
id: string;
|
|
13
|
-
createdAt: string;
|
|
14
|
-
updatedAt: string;
|
|
15
|
-
projectId: string;
|
|
16
13
|
tenantId: string;
|
|
14
|
+
projectId: string;
|
|
17
15
|
agentId: string;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
18
|
sourceSubAgentId: string;
|
|
19
19
|
targetSubAgentId: string | null;
|
|
20
20
|
relationType: string | null;
|
|
@@ -45,11 +45,11 @@ declare const getAgentRelations: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
45
45
|
scopes: SubAgentScopeConfig;
|
|
46
46
|
}) => Promise<{
|
|
47
47
|
id: string;
|
|
48
|
-
createdAt: string;
|
|
49
|
-
updatedAt: string;
|
|
50
|
-
projectId: string;
|
|
51
48
|
tenantId: string;
|
|
49
|
+
projectId: string;
|
|
52
50
|
agentId: string;
|
|
51
|
+
createdAt: string;
|
|
52
|
+
updatedAt: string;
|
|
53
53
|
sourceSubAgentId: string;
|
|
54
54
|
targetSubAgentId: string | null;
|
|
55
55
|
relationType: string | null;
|
|
@@ -58,11 +58,11 @@ declare const getAgentRelationsByAgent: (db: AgentsManageDatabaseClient) => (par
|
|
|
58
58
|
scopes: AgentScopeConfig;
|
|
59
59
|
}) => Promise<{
|
|
60
60
|
id: string;
|
|
61
|
-
createdAt: string;
|
|
62
|
-
updatedAt: string;
|
|
63
|
-
projectId: string;
|
|
64
61
|
tenantId: string;
|
|
62
|
+
projectId: string;
|
|
65
63
|
agentId: string;
|
|
64
|
+
createdAt: string;
|
|
65
|
+
updatedAt: string;
|
|
66
66
|
sourceSubAgentId: string;
|
|
67
67
|
targetSubAgentId: string | null;
|
|
68
68
|
relationType: string | null;
|
|
@@ -127,11 +127,11 @@ declare const getRelatedAgentsForAgent: (db: AgentsManageDatabaseClient) => (par
|
|
|
127
127
|
}>;
|
|
128
128
|
declare const createSubAgentRelation: (db: AgentsManageDatabaseClient) => (params: SubAgentRelationInsert) => Promise<{
|
|
129
129
|
id: string;
|
|
130
|
-
createdAt: string;
|
|
131
|
-
updatedAt: string;
|
|
132
|
-
projectId: string;
|
|
133
130
|
tenantId: string;
|
|
131
|
+
projectId: string;
|
|
134
132
|
agentId: string;
|
|
133
|
+
createdAt: string;
|
|
134
|
+
updatedAt: string;
|
|
135
135
|
sourceSubAgentId: string;
|
|
136
136
|
targetSubAgentId: string | null;
|
|
137
137
|
relationType: string | null;
|
|
@@ -146,11 +146,11 @@ declare const getAgentRelationByParams: (db: AgentsManageDatabaseClient) => (par
|
|
|
146
146
|
relationType: string;
|
|
147
147
|
}) => Promise<{
|
|
148
148
|
id: string;
|
|
149
|
-
createdAt: string;
|
|
150
|
-
updatedAt: string;
|
|
151
|
-
projectId: string;
|
|
152
149
|
tenantId: string;
|
|
150
|
+
projectId: string;
|
|
153
151
|
agentId: string;
|
|
152
|
+
createdAt: string;
|
|
153
|
+
updatedAt: string;
|
|
154
154
|
sourceSubAgentId: string;
|
|
155
155
|
targetSubAgentId: string | null;
|
|
156
156
|
relationType: string | null;
|
|
@@ -160,11 +160,11 @@ declare const getAgentRelationByParams: (db: AgentsManageDatabaseClient) => (par
|
|
|
160
160
|
*/
|
|
161
161
|
declare const upsertSubAgentRelation: (db: AgentsManageDatabaseClient) => (params: SubAgentRelationInsert) => Promise<{
|
|
162
162
|
id: string;
|
|
163
|
-
createdAt: string;
|
|
164
|
-
updatedAt: string;
|
|
165
|
-
projectId: string;
|
|
166
163
|
tenantId: string;
|
|
164
|
+
projectId: string;
|
|
167
165
|
agentId: string;
|
|
166
|
+
createdAt: string;
|
|
167
|
+
updatedAt: string;
|
|
168
168
|
sourceSubAgentId: string;
|
|
169
169
|
targetSubAgentId: string | null;
|
|
170
170
|
relationType: string | null;
|
|
@@ -205,17 +205,17 @@ declare const createAgentToolRelation: (db: AgentsManageDatabaseClient) => (para
|
|
|
205
205
|
};
|
|
206
206
|
}) => Promise<{
|
|
207
207
|
id: string;
|
|
208
|
-
createdAt: string;
|
|
209
|
-
updatedAt: string;
|
|
210
|
-
subAgentId: string;
|
|
211
|
-
projectId: string;
|
|
212
208
|
tenantId: string;
|
|
213
|
-
|
|
209
|
+
projectId: string;
|
|
214
210
|
agentId: string;
|
|
211
|
+
createdAt: string;
|
|
212
|
+
updatedAt: string;
|
|
215
213
|
toolId: string;
|
|
214
|
+
headers: Record<string, string> | null;
|
|
216
215
|
toolPolicies: Record<string, {
|
|
217
216
|
needsApproval?: boolean;
|
|
218
217
|
}> | null;
|
|
218
|
+
subAgentId: string;
|
|
219
219
|
selectedTools: string[] | null;
|
|
220
220
|
}>;
|
|
221
221
|
declare const updateAgentToolRelation: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -249,17 +249,17 @@ declare const getAgentToolRelationById: (db: AgentsManageDatabaseClient) => (par
|
|
|
249
249
|
relationId: string;
|
|
250
250
|
}) => Promise<{
|
|
251
251
|
id: string;
|
|
252
|
-
createdAt: string;
|
|
253
|
-
updatedAt: string;
|
|
254
|
-
subAgentId: string;
|
|
255
|
-
projectId: string;
|
|
256
252
|
tenantId: string;
|
|
257
|
-
|
|
253
|
+
projectId: string;
|
|
258
254
|
agentId: string;
|
|
255
|
+
createdAt: string;
|
|
256
|
+
updatedAt: string;
|
|
259
257
|
toolId: string;
|
|
258
|
+
headers: Record<string, string> | null;
|
|
260
259
|
toolPolicies: Record<string, {
|
|
261
260
|
needsApproval?: boolean;
|
|
262
261
|
}> | null;
|
|
262
|
+
subAgentId: string;
|
|
263
263
|
selectedTools: string[] | null;
|
|
264
264
|
} | undefined>;
|
|
265
265
|
declare const getAgentToolRelationByAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { subAgentRelations, subAgentToolRelations, subAgents, tools } from "../../db/manage/manage-schema.js";
|
|
2
2
|
import { generateId } from "../../utils/conversations.js";
|
|
3
|
+
import { agentScopedWhere, subAgentScopedWhere } from "./scope-helpers.js";
|
|
3
4
|
import { and, count, desc, eq, isNotNull } from "drizzle-orm";
|
|
4
5
|
|
|
5
6
|
//#region src/data-access/manage/subAgentRelations.ts
|
|
6
7
|
const getAgentRelationById = (db) => async (params) => {
|
|
7
|
-
return db.query.subAgentRelations.findFirst({ where: and(
|
|
8
|
+
return db.query.subAgentRelations.findFirst({ where: and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.id, params.relationId)) });
|
|
8
9
|
};
|
|
9
10
|
const listAgentRelations = (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 = agentScopedWhere(subAgentRelations, params.scopes);
|
|
14
15
|
const [data, totalResult] = await Promise.all([db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentRelations).where(whereClause)]);
|
|
15
16
|
const total = totalResult[0]?.count || 0;
|
|
16
17
|
return {
|
|
@@ -24,16 +25,16 @@ const listAgentRelations = (db) => async (params) => {
|
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
const getAgentRelations = (db) => async (params) => {
|
|
27
|
-
return await db.query.subAgentRelations.findMany({ where: and(
|
|
28
|
+
return await db.query.subAgentRelations.findMany({ where: and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.sourceSubAgentId, params.scopes.subAgentId)) });
|
|
28
29
|
};
|
|
29
30
|
const getAgentRelationsByAgent = (db) => async (params) => {
|
|
30
|
-
return await db.query.subAgentRelations.findMany({ where:
|
|
31
|
+
return await db.query.subAgentRelations.findMany({ where: agentScopedWhere(subAgentRelations, params.scopes) });
|
|
31
32
|
};
|
|
32
33
|
const getAgentRelationsBySource = (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(subAgentRelations, params.scopes), eq(subAgentRelations.sourceSubAgentId, params.sourceSubAgentId));
|
|
37
38
|
const [data, totalResult] = await Promise.all([db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentRelations).where(whereClause)]);
|
|
38
39
|
const total = totalResult[0]?.count || 0;
|
|
39
40
|
return {
|
|
@@ -50,7 +51,7 @@ const getSubAgentRelationsByTarget = (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;
|
|
53
|
-
const whereClause = and(
|
|
54
|
+
const whereClause = and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.targetSubAgentId, params.targetSubAgentId));
|
|
54
55
|
const [data, totalResult] = await Promise.all([db.select().from(subAgentRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentRelations.createdAt)), db.select({ count: count() }).from(subAgentRelations).where(whereClause)]);
|
|
55
56
|
const total = totalResult[0]?.count || 0;
|
|
56
57
|
return {
|
|
@@ -70,7 +71,7 @@ const getRelatedAgentsForAgent = (db) => async (params) => {
|
|
|
70
71
|
description: subAgents.description,
|
|
71
72
|
relationType: subAgentRelations.relationType,
|
|
72
73
|
relationId: subAgentRelations.id
|
|
73
|
-
}).from(subAgentRelations).innerJoin(subAgents, and(eq(subAgentRelations.targetSubAgentId, subAgents.id), eq(subAgentRelations.tenantId, subAgents.tenantId), eq(subAgentRelations.projectId, subAgents.projectId), eq(subAgentRelations.agentId, subAgents.agentId))).where(and(
|
|
74
|
+
}).from(subAgentRelations).innerJoin(subAgents, and(eq(subAgentRelations.targetSubAgentId, subAgents.id), eq(subAgentRelations.tenantId, subAgents.tenantId), eq(subAgentRelations.projectId, subAgents.projectId), eq(subAgentRelations.agentId, subAgents.agentId))).where(and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.sourceSubAgentId, params.subAgentId), isNotNull(subAgentRelations.targetSubAgentId))) };
|
|
74
75
|
};
|
|
75
76
|
const createSubAgentRelation = (db) => async (params) => {
|
|
76
77
|
const count$1 = [
|
|
@@ -87,9 +88,7 @@ const createSubAgentRelation = (db) => async (params) => {
|
|
|
87
88
|
*/
|
|
88
89
|
const getAgentRelationByParams = (db) => async (params) => {
|
|
89
90
|
const whereConditions = [
|
|
90
|
-
|
|
91
|
-
eq(subAgentRelations.projectId, params.scopes.projectId),
|
|
92
|
-
eq(subAgentRelations.agentId, params.scopes.agentId),
|
|
91
|
+
agentScopedWhere(subAgentRelations, params.scopes),
|
|
93
92
|
eq(subAgentRelations.sourceSubAgentId, params.sourceSubAgentId),
|
|
94
93
|
eq(subAgentRelations.relationType, params.relationType)
|
|
95
94
|
];
|
|
@@ -118,21 +117,19 @@ const updateAgentRelation = (db) => async (params) => {
|
|
|
118
117
|
...params.data,
|
|
119
118
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
120
119
|
};
|
|
121
|
-
return (await db.update(subAgentRelations).set(updateData).where(and(
|
|
120
|
+
return (await db.update(subAgentRelations).set(updateData).where(and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.id, params.relationId))).returning())[0];
|
|
122
121
|
};
|
|
123
122
|
const deleteSubAgentRelation = (db) => async (params) => {
|
|
124
|
-
return (await db.delete(subAgentRelations).where(and(
|
|
123
|
+
return (await db.delete(subAgentRelations).where(and(agentScopedWhere(subAgentRelations, params.scopes), eq(subAgentRelations.id, params.relationId))).returning()).length > 0;
|
|
125
124
|
};
|
|
126
125
|
const deleteAgentRelationsByAgent = (db) => async (params) => {
|
|
127
|
-
return (await db.delete(subAgentRelations).where(
|
|
126
|
+
return (await db.delete(subAgentRelations).where(agentScopedWhere(subAgentRelations, params.scopes)).returning()).length > 0;
|
|
128
127
|
};
|
|
129
128
|
const createAgentToolRelation = (db) => async (params) => {
|
|
130
129
|
const finalRelationId = params.relationId ?? generateId();
|
|
131
130
|
return (await db.insert(subAgentToolRelations).values({
|
|
132
131
|
id: finalRelationId,
|
|
133
|
-
|
|
134
|
-
projectId: params.scopes.projectId,
|
|
135
|
-
agentId: params.scopes.agentId,
|
|
132
|
+
...params.scopes,
|
|
136
133
|
subAgentId: params.data.subAgentId,
|
|
137
134
|
toolId: params.data.toolId,
|
|
138
135
|
selectedTools: params.data.selectedTools,
|
|
@@ -145,22 +142,23 @@ const updateAgentToolRelation = (db) => async (params) => {
|
|
|
145
142
|
...params.data,
|
|
146
143
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
147
144
|
};
|
|
148
|
-
return (await db.update(subAgentToolRelations).set(updateData).where(and(
|
|
145
|
+
return (await db.update(subAgentToolRelations).set(updateData).where(and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.id, params.relationId))).returning())[0];
|
|
149
146
|
};
|
|
150
147
|
const deleteAgentToolRelation = (db) => async (params) => {
|
|
151
|
-
return (await db.delete(subAgentToolRelations).where(and(
|
|
148
|
+
return (await db.delete(subAgentToolRelations).where(and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.id, params.relationId))).returning()).length > 0;
|
|
152
149
|
};
|
|
153
150
|
const deleteAgentToolRelationByAgent = (db) => async (params) => {
|
|
154
|
-
return (await db.delete(subAgentToolRelations).where(
|
|
151
|
+
return (await db.delete(subAgentToolRelations).where(subAgentScopedWhere(subAgentToolRelations, params.scopes)).returning()).length > 0;
|
|
155
152
|
};
|
|
156
153
|
const getAgentToolRelationById = (db) => async (params) => {
|
|
157
|
-
return await db.query.subAgentToolRelations.findFirst({ where: and(
|
|
154
|
+
return await db.query.subAgentToolRelations.findFirst({ where: and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.id, params.relationId)) });
|
|
158
155
|
};
|
|
159
156
|
const getAgentToolRelationByAgent = (db) => async (params) => {
|
|
160
157
|
const page = params.pagination?.page || 1;
|
|
161
158
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
162
159
|
const offset = (page - 1) * limit;
|
|
163
|
-
const
|
|
160
|
+
const whereClause = subAgentScopedWhere(subAgentToolRelations, params.scopes);
|
|
161
|
+
const [data, totalResult] = await Promise.all([db.select().from(subAgentToolRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
164
162
|
const total = totalResult[0]?.count || 0;
|
|
165
163
|
return {
|
|
166
164
|
data,
|
|
@@ -176,7 +174,8 @@ const getAgentToolRelationByTool = (db) => async (params) => {
|
|
|
176
174
|
const page = params.pagination?.page || 1;
|
|
177
175
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
178
176
|
const offset = (page - 1) * limit;
|
|
179
|
-
const
|
|
177
|
+
const whereClause = and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.toolId, params.toolId));
|
|
178
|
+
const [data, totalResult] = await Promise.all([db.select().from(subAgentToolRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
180
179
|
const total = totalResult[0]?.count || 0;
|
|
181
180
|
return {
|
|
182
181
|
data,
|
|
@@ -192,7 +191,8 @@ const listAgentToolRelations = (db) => async (params) => {
|
|
|
192
191
|
const page = params.pagination?.page || 1;
|
|
193
192
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
194
193
|
const offset = (page - 1) * limit;
|
|
195
|
-
const
|
|
194
|
+
const whereClause = agentScopedWhere(subAgentToolRelations, params.scopes);
|
|
195
|
+
const [data, totalResult] = await Promise.all([db.select().from(subAgentToolRelations).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
196
196
|
const total = totalResult[0]?.count || 0;
|
|
197
197
|
return {
|
|
198
198
|
data,
|
|
@@ -208,6 +208,7 @@ const getToolsForAgent = (db) => async (params) => {
|
|
|
208
208
|
const page = params.pagination?.page || 1;
|
|
209
209
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
210
210
|
const offset = (page - 1) * limit;
|
|
211
|
+
const whereClause = subAgentScopedWhere(subAgentToolRelations, params.scopes);
|
|
211
212
|
const [data, totalResult] = await Promise.all([db.select({
|
|
212
213
|
id: subAgentToolRelations.id,
|
|
213
214
|
tenantId: subAgentToolRelations.tenantId,
|
|
@@ -234,7 +235,7 @@ const getToolsForAgent = (db) => async (params) => {
|
|
|
234
235
|
headers: tools.headers,
|
|
235
236
|
imageUrl: tools.imageUrl
|
|
236
237
|
}
|
|
237
|
-
}).from(subAgentToolRelations).innerJoin(tools, and(eq(subAgentToolRelations.tenantId, tools.tenantId), eq(subAgentToolRelations.projectId, tools.projectId), eq(subAgentToolRelations.toolId, tools.id))).where(
|
|
238
|
+
}).from(subAgentToolRelations).innerJoin(tools, and(eq(subAgentToolRelations.tenantId, tools.tenantId), eq(subAgentToolRelations.projectId, tools.projectId), eq(subAgentToolRelations.toolId, tools.id))).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
238
239
|
const total = totalResult[0]?.count || 0;
|
|
239
240
|
return {
|
|
240
241
|
data,
|
|
@@ -250,6 +251,7 @@ const getAgentsForTool = (db) => async (params) => {
|
|
|
250
251
|
const page = params.pagination?.page || 1;
|
|
251
252
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
252
253
|
const offset = (page - 1) * limit;
|
|
254
|
+
const whereClause = and(agentScopedWhere(subAgentToolRelations, params.scopes), eq(subAgentToolRelations.toolId, params.toolId));
|
|
253
255
|
const [data, totalResult] = await Promise.all([db.select({
|
|
254
256
|
id: subAgentToolRelations.id,
|
|
255
257
|
tenantId: subAgentToolRelations.tenantId,
|
|
@@ -271,7 +273,7 @@ const getAgentsForTool = (db) => async (params) => {
|
|
|
271
273
|
createdAt: subAgents.createdAt,
|
|
272
274
|
updatedAt: subAgents.updatedAt
|
|
273
275
|
}
|
|
274
|
-
}).from(subAgentToolRelations).innerJoin(subAgents, and(eq(subAgentToolRelations.subAgentId, subAgents.id), eq(subAgentToolRelations.tenantId, subAgents.tenantId), eq(subAgentToolRelations.projectId, subAgents.projectId), eq(subAgentToolRelations.agentId, subAgents.agentId))).where(
|
|
276
|
+
}).from(subAgentToolRelations).innerJoin(subAgents, and(eq(subAgentToolRelations.subAgentId, subAgents.id), eq(subAgentToolRelations.tenantId, subAgents.tenantId), eq(subAgentToolRelations.projectId, subAgents.projectId), eq(subAgentToolRelations.agentId, subAgents.agentId))).where(whereClause).limit(limit).offset(offset).orderBy(desc(subAgentToolRelations.createdAt)), db.select({ count: count() }).from(subAgentToolRelations).where(whereClause)]);
|
|
275
277
|
const total = totalResult[0]?.count || 0;
|
|
276
278
|
return {
|
|
277
279
|
data,
|
|
@@ -284,7 +286,7 @@ const getAgentsForTool = (db) => async (params) => {
|
|
|
284
286
|
};
|
|
285
287
|
};
|
|
286
288
|
const validateSubAgent = (db) => async (params) => {
|
|
287
|
-
return (await db.select({ id: subAgents.id }).from(subAgents).where(and(
|
|
289
|
+
return (await db.select({ id: subAgents.id }).from(subAgents).where(and(agentScopedWhere(subAgents, params.scopes), eq(subAgents.id, params.scopes.subAgentId))).limit(1)).length > 0;
|
|
288
290
|
};
|
|
289
291
|
|
|
290
292
|
//#endregion
|