@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
|
@@ -3,6 +3,7 @@ import { getLogger } from "../../utils/logger.js";
|
|
|
3
3
|
import { createAgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
4
4
|
import { generateId } from "../../utils/conversations.js";
|
|
5
5
|
import { getActiveBranch } from "../../dolt/schema-sync.js";
|
|
6
|
+
import { agentScopedWhere, projectScopedWhere, subAgentScopedWhere, tenantScopedWhere } from "./scope-helpers.js";
|
|
6
7
|
import { getProjectMainBranchName } from "./projectLifecycle.js";
|
|
7
8
|
import { cascadeDeleteByAgent } from "../runtime/cascade-delete.js";
|
|
8
9
|
import { getContextConfigById } from "./contextConfigs.js";
|
|
@@ -21,22 +22,22 @@ import { and, count, desc, eq, inArray, sql } from "drizzle-orm";
|
|
|
21
22
|
|
|
22
23
|
//#region src/data-access/manage/agents.ts
|
|
23
24
|
const getAgentById = (db) => async (params) => {
|
|
24
|
-
return await db.query.agents.findFirst({ where: and(
|
|
25
|
+
return await db.query.agents.findFirst({ where: and(projectScopedWhere(agents, params.scopes), eq(agents.id, params.scopes.agentId)) }) ?? null;
|
|
25
26
|
};
|
|
26
27
|
const getAgentWithDefaultSubAgent = (db) => async (params) => {
|
|
27
28
|
return await db.query.agents.findFirst({
|
|
28
|
-
where: and(
|
|
29
|
+
where: and(projectScopedWhere(agents, params.scopes), eq(agents.id, params.scopes.agentId)),
|
|
29
30
|
with: { defaultSubAgent: true }
|
|
30
31
|
}) ?? null;
|
|
31
32
|
};
|
|
32
33
|
const listAgents = (db) => async (params) => {
|
|
33
|
-
return await db.query.agents.findMany({ where:
|
|
34
|
+
return await db.query.agents.findMany({ where: projectScopedWhere(agents, params.scopes) });
|
|
34
35
|
};
|
|
35
36
|
const listAgentsPaginated = (db) => async (params) => {
|
|
36
37
|
const page = params.pagination?.page || 1;
|
|
37
38
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
38
39
|
const offset = (page - 1) * limit;
|
|
39
|
-
const whereClause =
|
|
40
|
+
const whereClause = projectScopedWhere(agents, params.scopes);
|
|
40
41
|
const query = db.select().from(agents).where(whereClause).limit(limit).offset(offset).orderBy(desc(agents.createdAt));
|
|
41
42
|
const [data, totalResult] = await Promise.all([query, db.select({ count: count() }).from(agents).where(whereClause)]);
|
|
42
43
|
const total = totalResult[0]?.count || 0;
|
|
@@ -109,13 +110,13 @@ const updateAgent = (db) => async (params) => {
|
|
|
109
110
|
if (data.contextConfigId !== void 0 && !data.contextConfigId) updateData.contextConfigId = null;
|
|
110
111
|
if (data.prompt !== void 0 && !data.prompt) updateData.prompt = null;
|
|
111
112
|
if (data.stopWhen !== void 0 && !data.stopWhen) updateData.stopWhen = null;
|
|
112
|
-
return (await db.update(agents).set(updateData).where(and(
|
|
113
|
+
return (await db.update(agents).set(updateData).where(and(projectScopedWhere(agents, params.scopes), eq(agents.id, params.scopes.agentId))).returning())[0] ?? null;
|
|
113
114
|
};
|
|
114
115
|
const deleteAgent = (db) => async (params) => {
|
|
115
|
-
const {
|
|
116
|
+
const { agentId } = params.scopes;
|
|
116
117
|
try {
|
|
117
118
|
const currentBranch = await getActiveBranch(db)();
|
|
118
|
-
const subAgentIds = (await db.query.subAgents.findMany({ where:
|
|
119
|
+
const subAgentIds = (await db.query.subAgents.findMany({ where: agentScopedWhere(subAgents, params.scopes) })).map((sa) => sa.id);
|
|
119
120
|
await cascadeDeleteByAgent(createAgentsRunDatabaseClient())({
|
|
120
121
|
scopes: params.scopes,
|
|
121
122
|
fullBranchName: currentBranch,
|
|
@@ -127,7 +128,7 @@ const deleteAgent = (db) => async (params) => {
|
|
|
127
128
|
agentId
|
|
128
129
|
}, "Skipping runtime cascade delete - active_branch() not available");
|
|
129
130
|
}
|
|
130
|
-
return (await db.delete(agents).where(and(
|
|
131
|
+
return (await db.delete(agents).where(and(projectScopedWhere(agents, params.scopes), eq(agents.id, params.scopes.agentId))).returning()).length > 0;
|
|
131
132
|
};
|
|
132
133
|
/**
|
|
133
134
|
* Helper function to fetch component relationships using efficient joins
|
|
@@ -135,7 +136,7 @@ const deleteAgent = (db) => async (params) => {
|
|
|
135
136
|
const fetchComponentRelationships = (db) => async (scopes, subAgentIds, config) => {
|
|
136
137
|
const componentsObject = {};
|
|
137
138
|
if (subAgentIds.length > 0) {
|
|
138
|
-
const results = await db.select(config.selectFields).from(config.relationTable).innerJoin(config.componentTable, eq(config.relationIdField, config.componentIdField)).where(and(
|
|
139
|
+
const results = await db.select(config.selectFields).from(config.relationTable).innerJoin(config.componentTable, eq(config.relationIdField, config.componentIdField)).where(and(agentScopedWhere(config.relationTable, scopes), inArray(config.subAgentIdField, subAgentIds)));
|
|
139
140
|
for (const component of results) componentsObject[component.id] = component;
|
|
140
141
|
}
|
|
141
142
|
return componentsObject;
|
|
@@ -170,18 +171,15 @@ const getAgentSubAgentInfos = (db) => async ({ scopes: { tenantId, projectId },
|
|
|
170
171
|
}))).filter((agent) => agent !== null);
|
|
171
172
|
};
|
|
172
173
|
const getFullAgentDefinitionInternal = (db) => async ({ scopes: { tenantId, projectId, agentId }, includeRelationIds = false }) => {
|
|
173
|
-
const
|
|
174
|
+
const agentScope = {
|
|
174
175
|
tenantId,
|
|
175
176
|
projectId,
|
|
176
177
|
agentId
|
|
177
|
-
}
|
|
178
|
+
};
|
|
179
|
+
const agent = await getAgentById(db)({ scopes: agentScope });
|
|
178
180
|
if (!agent) return null;
|
|
179
|
-
const agentRelations = await getAgentRelationsByAgent(db)({ scopes:
|
|
180
|
-
|
|
181
|
-
projectId,
|
|
182
|
-
agentId
|
|
183
|
-
} });
|
|
184
|
-
const agentSubAgents = await db.query.subAgents.findMany({ where: and(eq(subAgents.tenantId, tenantId), eq(subAgents.projectId, projectId), eq(subAgents.agentId, agentId)) });
|
|
181
|
+
const agentRelations = await getAgentRelationsByAgent(db)({ scopes: agentScope });
|
|
182
|
+
const agentSubAgents = await db.query.subAgents.findMany({ where: agentScopedWhere(subAgents, agentScope) });
|
|
185
183
|
const subAgentIds = agentSubAgents.map((subAgent) => subAgent.id);
|
|
186
184
|
const externalAgentRelations = await getSubAgentExternalAgentRelationsByAgent(db)({ scopes: {
|
|
187
185
|
tenantId,
|
|
@@ -224,6 +222,12 @@ const getFullAgentDefinitionInternal = (db) => async ({ scopes: { tenantId, proj
|
|
|
224
222
|
}
|
|
225
223
|
const processedSubAgents = await Promise.all(agentSubAgents.map(async (agent$1) => {
|
|
226
224
|
if (!agent$1) return null;
|
|
225
|
+
const subAgentScope = {
|
|
226
|
+
tenantId,
|
|
227
|
+
projectId,
|
|
228
|
+
agentId,
|
|
229
|
+
subAgentId: agent$1.id
|
|
230
|
+
};
|
|
227
231
|
const subAgentRelationsList = agentRelations.filter((relation) => relation.sourceSubAgentId === agent$1.id);
|
|
228
232
|
const canTransferTo = includeRelationIds ? subAgentRelationsList.filter((rel) => (rel.relationType === "transfer" || rel.relationType === "transfer_to") && rel.targetSubAgentId !== null).map((rel) => ({
|
|
229
233
|
subAgentId: rel.targetSubAgentId,
|
|
@@ -264,7 +268,7 @@ const getFullAgentDefinitionInternal = (db) => async ({ scopes: { tenantId, proj
|
|
|
264
268
|
headers: subAgentToolRelations.headers,
|
|
265
269
|
toolPolicies: subAgentToolRelations.toolPolicies,
|
|
266
270
|
agentToolRelationId: subAgentToolRelations.id
|
|
267
|
-
}).from(subAgentToolRelations).innerJoin(tools, and(eq(subAgentToolRelations.toolId, tools.id), eq(subAgentToolRelations.tenantId, tools.tenantId), eq(subAgentToolRelations.projectId, tools.projectId))).where(
|
|
271
|
+
}).from(subAgentToolRelations).innerJoin(tools, and(eq(subAgentToolRelations.toolId, tools.id), eq(subAgentToolRelations.tenantId, tools.tenantId), eq(subAgentToolRelations.projectId, tools.projectId))).where(subAgentScopedWhere(subAgentToolRelations, subAgentScope));
|
|
268
272
|
const agentFunctionTools = await db.select({
|
|
269
273
|
id: functionTools.id,
|
|
270
274
|
name: functionTools.name,
|
|
@@ -277,9 +281,9 @@ const getFullAgentDefinitionInternal = (db) => async ({ scopes: { tenantId, proj
|
|
|
277
281
|
agentId: functionTools.agentId,
|
|
278
282
|
agentToolRelationId: subAgentFunctionToolRelations.id,
|
|
279
283
|
toolPolicies: subAgentFunctionToolRelations.toolPolicies
|
|
280
|
-
}).from(subAgentFunctionToolRelations).innerJoin(functionTools, and(eq(subAgentFunctionToolRelations.functionToolId, functionTools.id), eq(subAgentFunctionToolRelations.tenantId, functionTools.tenantId), eq(subAgentFunctionToolRelations.projectId, functionTools.projectId), eq(subAgentFunctionToolRelations.agentId, functionTools.agentId))).where(
|
|
281
|
-
const agentDataComponentIds = (await db.query.subAgentDataComponents.findMany({ where:
|
|
282
|
-
const agentArtifactComponentIds = (await db.query.subAgentArtifactComponents.findMany({ where:
|
|
284
|
+
}).from(subAgentFunctionToolRelations).innerJoin(functionTools, and(eq(subAgentFunctionToolRelations.functionToolId, functionTools.id), eq(subAgentFunctionToolRelations.tenantId, functionTools.tenantId), eq(subAgentFunctionToolRelations.projectId, functionTools.projectId), eq(subAgentFunctionToolRelations.agentId, functionTools.agentId))).where(subAgentScopedWhere(subAgentFunctionToolRelations, subAgentScope));
|
|
285
|
+
const agentDataComponentIds = (await db.query.subAgentDataComponents.findMany({ where: subAgentScopedWhere(subAgentDataComponents, subAgentScope) })).map((rel) => rel.dataComponentId);
|
|
286
|
+
const agentArtifactComponentIds = (await db.query.subAgentArtifactComponents.findMany({ where: subAgentScopedWhere(subAgentArtifactComponents, subAgentScope) })).map((rel) => rel.artifactComponentId);
|
|
283
287
|
const mcpToolCanUse = subAgentTools.map((tool) => ({
|
|
284
288
|
agentToolRelationId: tool.agentToolRelationId,
|
|
285
289
|
toolId: tool.id,
|
|
@@ -371,11 +375,7 @@ const getFullAgentDefinitionInternal = (db) => async ({ scopes: { tenantId, proj
|
|
|
371
375
|
}, "Failed to retrieve contextConfig");
|
|
372
376
|
}
|
|
373
377
|
try {
|
|
374
|
-
await fetchComponentRelationships(db)({
|
|
375
|
-
tenantId,
|
|
376
|
-
projectId,
|
|
377
|
-
agentId
|
|
378
|
-
}, subAgentIds, {
|
|
378
|
+
await fetchComponentRelationships(db)(agentScope, subAgentIds, {
|
|
379
379
|
relationTable: subAgentDataComponents,
|
|
380
380
|
componentTable: dataComponents,
|
|
381
381
|
relationIdField: subAgentDataComponents.dataComponentId,
|
|
@@ -392,11 +392,7 @@ const getFullAgentDefinitionInternal = (db) => async ({ scopes: { tenantId, proj
|
|
|
392
392
|
agentsLogger.warn({ error }, "Failed to retrieve dataComponents");
|
|
393
393
|
}
|
|
394
394
|
try {
|
|
395
|
-
await fetchComponentRelationships(db)({
|
|
396
|
-
tenantId,
|
|
397
|
-
projectId,
|
|
398
|
-
agentId
|
|
399
|
-
}, subAgentIds, {
|
|
395
|
+
await fetchComponentRelationships(db)(agentScope, subAgentIds, {
|
|
400
396
|
relationTable: subAgentArtifactComponents,
|
|
401
397
|
componentTable: artifactComponents,
|
|
402
398
|
relationIdField: subAgentArtifactComponents.artifactComponentId,
|
|
@@ -437,7 +433,7 @@ const getFullAgentDefinitionInternal = (db) => async ({ scopes: { tenantId, proj
|
|
|
437
433
|
}
|
|
438
434
|
try {
|
|
439
435
|
if (!db.query?.projects?.findFirst) return result;
|
|
440
|
-
const project = await db.query.projects.findFirst({ where: and(
|
|
436
|
+
const project = await db.query.projects.findFirst({ where: and(tenantScopedWhere(projects, { tenantId }), eq(projects.id, projectId)) });
|
|
441
437
|
if (project?.stopWhen) {
|
|
442
438
|
const projectStopWhen = project.stopWhen;
|
|
443
439
|
if (projectStopWhen.stepCountIs !== void 0) {
|
|
@@ -452,7 +448,11 @@ const getFullAgentDefinitionInternal = (db) => async ({ scopes: { tenantId, proj
|
|
|
452
448
|
await db.update(subAgents).set({
|
|
453
449
|
stopWhen: agent$1.stopWhen,
|
|
454
450
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
455
|
-
}).where(and(
|
|
451
|
+
}).where(and(agentScopedWhere(subAgents, {
|
|
452
|
+
tenantId,
|
|
453
|
+
projectId,
|
|
454
|
+
agentId
|
|
455
|
+
}), eq(subAgents.id, subAgentId)));
|
|
456
456
|
result.subAgents[subAgentId] = {
|
|
457
457
|
...result.subAgents[subAgentId],
|
|
458
458
|
stopWhen: agent$1.stopWhen
|
|
@@ -11,9 +11,11 @@ declare const getArtifactComponentById: (db: AgentsManageDatabaseClient) => (par
|
|
|
11
11
|
}) => Promise<{
|
|
12
12
|
id: string;
|
|
13
13
|
name: string;
|
|
14
|
+
description: string | null;
|
|
15
|
+
tenantId: string;
|
|
16
|
+
projectId: string;
|
|
14
17
|
createdAt: string;
|
|
15
18
|
updatedAt: string;
|
|
16
|
-
description: string | null;
|
|
17
19
|
props: {
|
|
18
20
|
[x: string]: unknown;
|
|
19
21
|
type: "object";
|
|
@@ -26,8 +28,6 @@ declare const getArtifactComponentById: (db: AgentsManageDatabaseClient) => (par
|
|
|
26
28
|
component: string;
|
|
27
29
|
mockData: Record<string, unknown>;
|
|
28
30
|
} | null;
|
|
29
|
-
projectId: string;
|
|
30
|
-
tenantId: string;
|
|
31
31
|
} | undefined>;
|
|
32
32
|
declare const listArtifactComponents: (db: AgentsManageDatabaseClient) => (params: {
|
|
33
33
|
scopes: ProjectScopeConfig;
|
|
@@ -67,9 +67,11 @@ declare const listArtifactComponentsPaginated: (db: AgentsManageDatabaseClient)
|
|
|
67
67
|
declare const createArtifactComponent: (db: AgentsManageDatabaseClient) => (params: ArtifactComponentInsert) => Promise<{
|
|
68
68
|
id: string;
|
|
69
69
|
name: string;
|
|
70
|
+
description: string | null;
|
|
71
|
+
tenantId: string;
|
|
72
|
+
projectId: string;
|
|
70
73
|
createdAt: string;
|
|
71
74
|
updatedAt: string;
|
|
72
|
-
description: string | null;
|
|
73
75
|
props: {
|
|
74
76
|
[x: string]: unknown;
|
|
75
77
|
type: "object";
|
|
@@ -82,8 +84,6 @@ declare const createArtifactComponent: (db: AgentsManageDatabaseClient) => (para
|
|
|
82
84
|
component: string;
|
|
83
85
|
mockData: Record<string, unknown>;
|
|
84
86
|
} | null;
|
|
85
|
-
projectId: string;
|
|
86
|
-
tenantId: string;
|
|
87
87
|
}>;
|
|
88
88
|
declare const updateArtifactComponent: (db: AgentsManageDatabaseClient) => (params: {
|
|
89
89
|
scopes: ProjectScopeConfig;
|
|
@@ -142,11 +142,11 @@ declare const associateArtifactComponentWithAgent: (db: AgentsManageDatabaseClie
|
|
|
142
142
|
artifactComponentId: string;
|
|
143
143
|
}) => Promise<{
|
|
144
144
|
id: string;
|
|
145
|
-
createdAt: string;
|
|
146
|
-
subAgentId: string;
|
|
147
|
-
projectId: string;
|
|
148
145
|
tenantId: string;
|
|
146
|
+
projectId: string;
|
|
149
147
|
agentId: string;
|
|
148
|
+
createdAt: string;
|
|
149
|
+
subAgentId: string;
|
|
150
150
|
artifactComponentId: string;
|
|
151
151
|
}>;
|
|
152
152
|
declare const removeArtifactComponentFromAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -185,11 +185,11 @@ declare const upsertAgentArtifactComponentRelation: (db: AgentsManageDatabaseCli
|
|
|
185
185
|
artifactComponentId: string;
|
|
186
186
|
}) => Promise<{
|
|
187
187
|
id: string;
|
|
188
|
-
createdAt: string;
|
|
189
|
-
subAgentId: string;
|
|
190
|
-
projectId: string;
|
|
191
188
|
tenantId: string;
|
|
189
|
+
projectId: string;
|
|
192
190
|
agentId: string;
|
|
191
|
+
createdAt: string;
|
|
192
|
+
subAgentId: string;
|
|
193
193
|
artifactComponentId: string;
|
|
194
194
|
} | null>;
|
|
195
195
|
/**
|
|
@@ -2,20 +2,21 @@ import { artifactComponents, subAgentArtifactComponents, subAgentRelations, subA
|
|
|
2
2
|
import { validatePropsAsJsonSchema } from "../../validation/props-validation.js";
|
|
3
3
|
import { validateRender } from "../../validation/render-validation.js";
|
|
4
4
|
import { generateId } from "../../utils/conversations.js";
|
|
5
|
+
import { agentScopedWhere, projectScopedWhere, subAgentScopedWhere } from "./scope-helpers.js";
|
|
5
6
|
import { and, count, desc, eq } from "drizzle-orm";
|
|
6
7
|
|
|
7
8
|
//#region src/data-access/manage/artifactComponents.ts
|
|
8
9
|
const getArtifactComponentById = (db) => async (params) => {
|
|
9
|
-
return await db.query.artifactComponents.findFirst({ where: and(
|
|
10
|
+
return await db.query.artifactComponents.findFirst({ where: and(projectScopedWhere(artifactComponents, params.scopes), eq(artifactComponents.id, params.id)) });
|
|
10
11
|
};
|
|
11
12
|
const listArtifactComponents = (db) => async (params) => {
|
|
12
|
-
return await db.select().from(artifactComponents).where(
|
|
13
|
+
return await db.select().from(artifactComponents).where(projectScopedWhere(artifactComponents, params.scopes)).orderBy(desc(artifactComponents.createdAt));
|
|
13
14
|
};
|
|
14
15
|
const listArtifactComponentsPaginated = (db) => async (params) => {
|
|
15
16
|
const page = params.pagination?.page || 1;
|
|
16
17
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
17
18
|
const offset = (page - 1) * limit;
|
|
18
|
-
const whereClause =
|
|
19
|
+
const whereClause = projectScopedWhere(artifactComponents, params.scopes);
|
|
19
20
|
const [data, totalResult] = await Promise.all([db.select().from(artifactComponents).where(whereClause).limit(limit).offset(offset).orderBy(desc(artifactComponents.createdAt)), db.select({ count: count() }).from(artifactComponents).where(whereClause)]);
|
|
20
21
|
const total = totalResult[0]?.count || 0;
|
|
21
22
|
const totalNumber = typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
@@ -75,12 +76,12 @@ const updateArtifactComponent = (db) => async (params) => {
|
|
|
75
76
|
const [updated] = await db.update(artifactComponents).set({
|
|
76
77
|
...params.data,
|
|
77
78
|
updatedAt: now
|
|
78
|
-
}).where(and(
|
|
79
|
+
}).where(and(projectScopedWhere(artifactComponents, params.scopes), eq(artifactComponents.id, params.id))).returning();
|
|
79
80
|
return updated;
|
|
80
81
|
};
|
|
81
82
|
const deleteArtifactComponent = (db) => async (params) => {
|
|
82
83
|
try {
|
|
83
|
-
return (await db.delete(artifactComponents).where(and(
|
|
84
|
+
return (await db.delete(artifactComponents).where(and(projectScopedWhere(artifactComponents, params.scopes), eq(artifactComponents.id, params.id))).returning()).length > 0;
|
|
84
85
|
} catch (error) {
|
|
85
86
|
console.error("Error deleting artifact component:", error);
|
|
86
87
|
return false;
|
|
@@ -97,7 +98,7 @@ const getArtifactComponentsForAgent = (db) => async (params) => {
|
|
|
97
98
|
render: artifactComponents.render,
|
|
98
99
|
createdAt: artifactComponents.createdAt,
|
|
99
100
|
updatedAt: artifactComponents.updatedAt
|
|
100
|
-
}).from(artifactComponents).innerJoin(subAgentArtifactComponents, and(eq(artifactComponents.id, subAgentArtifactComponents.artifactComponentId), eq(artifactComponents.tenantId, subAgentArtifactComponents.tenantId), eq(artifactComponents.projectId, subAgentArtifactComponents.projectId))).where(and(
|
|
101
|
+
}).from(artifactComponents).innerJoin(subAgentArtifactComponents, and(eq(artifactComponents.id, subAgentArtifactComponents.artifactComponentId), eq(artifactComponents.tenantId, subAgentArtifactComponents.tenantId), eq(artifactComponents.projectId, subAgentArtifactComponents.projectId))).where(and(projectScopedWhere(artifactComponents, params.scopes), eq(subAgentArtifactComponents.agentId, params.scopes.agentId), eq(subAgentArtifactComponents.subAgentId, params.scopes.subAgentId))).orderBy(desc(artifactComponents.createdAt));
|
|
101
102
|
};
|
|
102
103
|
const associateArtifactComponentWithAgent = (db) => async (params) => {
|
|
103
104
|
const [association] = await db.insert(subAgentArtifactComponents).values({
|
|
@@ -113,35 +114,35 @@ const associateArtifactComponentWithAgent = (db) => async (params) => {
|
|
|
113
114
|
};
|
|
114
115
|
const removeArtifactComponentFromAgent = (db) => async (params) => {
|
|
115
116
|
try {
|
|
116
|
-
return (await db.delete(subAgentArtifactComponents).where(and(
|
|
117
|
+
return (await db.delete(subAgentArtifactComponents).where(and(subAgentScopedWhere(subAgentArtifactComponents, params.scopes), eq(subAgentArtifactComponents.artifactComponentId, params.artifactComponentId))).returning()).length > 0;
|
|
117
118
|
} catch (error) {
|
|
118
119
|
console.error("Error removing artifact component from agent:", error);
|
|
119
120
|
return false;
|
|
120
121
|
}
|
|
121
122
|
};
|
|
122
123
|
const deleteAgentArtifactComponentRelationByAgent = (db) => async (params) => {
|
|
123
|
-
return (await db.delete(subAgentArtifactComponents).where(
|
|
124
|
+
return (await db.delete(subAgentArtifactComponents).where(subAgentScopedWhere(subAgentArtifactComponents, params.scopes)).returning()).length > 0;
|
|
124
125
|
};
|
|
125
126
|
const getAgentsUsingArtifactComponent = (db) => async (params) => {
|
|
126
127
|
return await db.select({
|
|
127
128
|
agentId: subAgentArtifactComponents.agentId,
|
|
128
129
|
subAgentId: subAgentArtifactComponents.subAgentId,
|
|
129
130
|
createdAt: subAgentArtifactComponents.createdAt
|
|
130
|
-
}).from(subAgentArtifactComponents).where(and(
|
|
131
|
+
}).from(subAgentArtifactComponents).where(and(projectScopedWhere(subAgentArtifactComponents, params.scopes), eq(subAgentArtifactComponents.artifactComponentId, params.artifactComponentId))).orderBy(desc(subAgentArtifactComponents.createdAt));
|
|
131
132
|
};
|
|
132
133
|
const isArtifactComponentAssociatedWithAgent = (db) => async (params) => {
|
|
133
|
-
return (await db.select({ id: subAgentArtifactComponents.id }).from(subAgentArtifactComponents).where(and(
|
|
134
|
+
return (await db.select({ id: subAgentArtifactComponents.id }).from(subAgentArtifactComponents).where(and(subAgentScopedWhere(subAgentArtifactComponents, params.scopes), eq(subAgentArtifactComponents.artifactComponentId, params.artifactComponentId))).limit(1)).length > 0;
|
|
134
135
|
};
|
|
135
136
|
const agentHasArtifactComponents = (db) => async (params) => {
|
|
136
|
-
const total = (await db.select({ count: count() }).from(subAgentArtifactComponents).innerJoin(subAgents, and(eq(subAgentArtifactComponents.subAgentId, subAgents.id), eq(subAgentArtifactComponents.tenantId, subAgents.tenantId), eq(subAgentArtifactComponents.projectId, subAgents.projectId), eq(subAgentArtifactComponents.agentId, subAgents.agentId))).innerJoin(subAgentRelations, and(eq(subAgents.id, subAgentRelations.sourceSubAgentId), eq(subAgents.tenantId, subAgentRelations.tenantId), eq(subAgents.projectId, subAgentRelations.projectId), eq(subAgents.agentId, subAgentRelations.agentId))).where(
|
|
137
|
+
const total = (await db.select({ count: count() }).from(subAgentArtifactComponents).innerJoin(subAgents, and(eq(subAgentArtifactComponents.subAgentId, subAgents.id), eq(subAgentArtifactComponents.tenantId, subAgents.tenantId), eq(subAgentArtifactComponents.projectId, subAgents.projectId), eq(subAgentArtifactComponents.agentId, subAgents.agentId))).innerJoin(subAgentRelations, and(eq(subAgents.id, subAgentRelations.sourceSubAgentId), eq(subAgents.tenantId, subAgentRelations.tenantId), eq(subAgents.projectId, subAgentRelations.projectId), eq(subAgents.agentId, subAgentRelations.agentId))).where(agentScopedWhere(subAgentArtifactComponents, params.scopes)).limit(1))[0]?.count || 0;
|
|
137
138
|
return (typeof total === "string" ? Number.parseInt(total, 10) : total) > 0;
|
|
138
139
|
};
|
|
139
140
|
const countArtifactComponents = (db) => async (params) => {
|
|
140
|
-
const total = (await db.select({ count: count() }).from(artifactComponents).where(
|
|
141
|
+
const total = (await db.select({ count: count() }).from(artifactComponents).where(projectScopedWhere(artifactComponents, params.scopes)))[0]?.count || 0;
|
|
141
142
|
return typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
142
143
|
};
|
|
143
144
|
const countArtifactComponentsForAgent = (db) => async (params) => {
|
|
144
|
-
const total = (await db.select({ count: count() }).from(subAgentArtifactComponents).where(
|
|
145
|
+
const total = (await db.select({ count: count() }).from(subAgentArtifactComponents).where(subAgentScopedWhere(subAgentArtifactComponents, params.scopes)))[0]?.count || 0;
|
|
145
146
|
return typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
146
147
|
};
|
|
147
148
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { agents, contextConfigs, scheduledTriggers, scheduledWorkflows, tools } from "../../db/manage/manage-schema.js";
|
|
2
|
+
import { projectScopedWhere } from "./scope-helpers.js";
|
|
2
3
|
import { and, eq } from "drizzle-orm";
|
|
3
4
|
|
|
4
5
|
//#region src/data-access/manage/audit-queries.ts
|
|
@@ -6,23 +7,23 @@ const listEnabledScheduledTriggers = (db) => async (params) => {
|
|
|
6
7
|
return db.select({
|
|
7
8
|
id: scheduledTriggers.id,
|
|
8
9
|
name: scheduledTriggers.name
|
|
9
|
-
}).from(scheduledTriggers).where(and(
|
|
10
|
+
}).from(scheduledTriggers).where(and(projectScopedWhere(scheduledTriggers, params.scopes), eq(scheduledTriggers.enabled, true)));
|
|
10
11
|
};
|
|
11
12
|
const listScheduledWorkflowsByProject = (db) => async (params) => {
|
|
12
13
|
return db.select({
|
|
13
14
|
id: scheduledWorkflows.id,
|
|
14
15
|
workflowRunId: scheduledWorkflows.workflowRunId,
|
|
15
16
|
scheduledTriggerId: scheduledWorkflows.scheduledTriggerId
|
|
16
|
-
}).from(scheduledWorkflows).where(
|
|
17
|
+
}).from(scheduledWorkflows).where(projectScopedWhere(scheduledWorkflows, params.scopes));
|
|
17
18
|
};
|
|
18
19
|
const listToolIdsByProject = (db) => async (params) => {
|
|
19
|
-
return (await db.select({ id: tools.id }).from(tools).where(
|
|
20
|
+
return (await db.select({ id: tools.id }).from(tools).where(projectScopedWhere(tools, params.scopes))).map((r) => r.id);
|
|
20
21
|
};
|
|
21
22
|
const listContextConfigIdsByProject = (db) => async (params) => {
|
|
22
|
-
return (await db.select({ id: contextConfigs.id }).from(contextConfigs).where(
|
|
23
|
+
return (await db.select({ id: contextConfigs.id }).from(contextConfigs).where(projectScopedWhere(contextConfigs, params.scopes))).map((r) => r.id);
|
|
23
24
|
};
|
|
24
25
|
const listAgentIdsByProject = (db) => async (params) => {
|
|
25
|
-
return (await db.select({ id: agents.id }).from(agents).where(
|
|
26
|
+
return (await db.select({ id: agents.id }).from(agents).where(projectScopedWhere(agents, params.scopes))).map((r) => r.id);
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
//#endregion
|
|
@@ -10,11 +10,11 @@ declare const getContextConfigById: (db: AgentsManageDatabaseClient) => (params:
|
|
|
10
10
|
id: 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
|
headersSchema: unknown;
|
|
19
19
|
contextVariables: Record<string, ContextFetchDefinition> | null;
|
|
20
20
|
} | undefined>;
|
|
@@ -22,11 +22,11 @@ declare const listContextConfigs: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
22
22
|
scopes: AgentScopeConfig;
|
|
23
23
|
}) => Promise<{
|
|
24
24
|
id: string;
|
|
25
|
-
createdAt: string;
|
|
26
|
-
updatedAt: string;
|
|
27
|
-
projectId: string;
|
|
28
25
|
tenantId: string;
|
|
26
|
+
projectId: string;
|
|
29
27
|
agentId: string;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
updatedAt: string;
|
|
30
30
|
headersSchema: unknown;
|
|
31
31
|
contextVariables: Record<string, ContextFetchDefinition> | null;
|
|
32
32
|
}[]>;
|
|
@@ -44,11 +44,11 @@ declare const listContextConfigsPaginated: (db: AgentsManageDatabaseClient) => (
|
|
|
44
44
|
}>;
|
|
45
45
|
declare const createContextConfig: (db: AgentsManageDatabaseClient) => (params: ContextConfigInsert) => Promise<{
|
|
46
46
|
id: string;
|
|
47
|
-
createdAt: string;
|
|
48
|
-
updatedAt: string;
|
|
49
|
-
projectId: string;
|
|
50
47
|
tenantId: string;
|
|
48
|
+
projectId: string;
|
|
51
49
|
agentId: string;
|
|
50
|
+
createdAt: string;
|
|
51
|
+
updatedAt: string;
|
|
52
52
|
headersSchema: unknown;
|
|
53
53
|
contextVariables: Record<string, ContextFetchDefinition> | null;
|
|
54
54
|
}>;
|
|
@@ -84,11 +84,11 @@ declare const upsertContextConfig: (db: AgentsManageDatabaseClient) => (params:
|
|
|
84
84
|
data: ContextConfigInsert;
|
|
85
85
|
}) => Promise<{
|
|
86
86
|
id: string;
|
|
87
|
-
createdAt: string;
|
|
88
|
-
updatedAt: string;
|
|
89
|
-
projectId: string;
|
|
90
87
|
tenantId: string;
|
|
88
|
+
projectId: string;
|
|
91
89
|
agentId: string;
|
|
90
|
+
createdAt: string;
|
|
91
|
+
updatedAt: string;
|
|
92
92
|
headersSchema: unknown;
|
|
93
93
|
contextVariables: Record<string, ContextFetchDefinition> | null;
|
|
94
94
|
}>;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { contextConfigs } from "../../db/manage/manage-schema.js";
|
|
2
2
|
import { generateId } from "../../utils/conversations.js";
|
|
3
|
+
import { agentScopedWhere } from "./scope-helpers.js";
|
|
3
4
|
import { and, count, desc, eq, sql } from "drizzle-orm";
|
|
4
5
|
|
|
5
6
|
//#region src/data-access/manage/contextConfigs.ts
|
|
6
7
|
const getContextConfigById = (db) => async (params) => {
|
|
7
|
-
return await db.query.contextConfigs.findFirst({ where: and(
|
|
8
|
+
return await db.query.contextConfigs.findFirst({ where: and(agentScopedWhere(contextConfigs, params.scopes), eq(contextConfigs.id, params.id)) });
|
|
8
9
|
};
|
|
9
10
|
const listContextConfigs = (db) => async (params) => {
|
|
10
11
|
return await db.query.contextConfigs.findMany({
|
|
11
|
-
where:
|
|
12
|
+
where: agentScopedWhere(contextConfigs, params.scopes),
|
|
12
13
|
orderBy: [desc(contextConfigs.createdAt)]
|
|
13
14
|
});
|
|
14
15
|
};
|
|
@@ -16,7 +17,7 @@ const listContextConfigsPaginated = (db) => async (params) => {
|
|
|
16
17
|
const page = params.pagination?.page || 1;
|
|
17
18
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
18
19
|
const offset = (page - 1) * limit;
|
|
19
|
-
const whereClause =
|
|
20
|
+
const whereClause = agentScopedWhere(contextConfigs, params.scopes);
|
|
20
21
|
const [contextConfigList, totalResult] = await Promise.all([db.select().from(contextConfigs).where(whereClause).limit(limit).offset(offset).orderBy(desc(contextConfigs.createdAt)), db.select({ count: sql`COUNT(*)` }).from(contextConfigs).where(whereClause)]);
|
|
21
22
|
const total = Number(totalResult[0]?.count || 0);
|
|
22
23
|
return {
|
|
@@ -55,11 +56,11 @@ const updateContextConfig = (db) => async (params) => {
|
|
|
55
56
|
return (await db.update(contextConfigs).set({
|
|
56
57
|
...processedData,
|
|
57
58
|
updatedAt: now
|
|
58
|
-
}).where(and(
|
|
59
|
+
}).where(and(agentScopedWhere(contextConfigs, params.scopes), eq(contextConfigs.id, params.id))).returning())[0];
|
|
59
60
|
};
|
|
60
61
|
const deleteContextConfig = (db) => async (params) => {
|
|
61
62
|
try {
|
|
62
|
-
return (await db.delete(contextConfigs).where(and(
|
|
63
|
+
return (await db.delete(contextConfigs).where(and(agentScopedWhere(contextConfigs, params.scopes), eq(contextConfigs.id, params.id))).returning()).length > 0;
|
|
63
64
|
} catch (error) {
|
|
64
65
|
console.error("Error deleting context config:", error);
|
|
65
66
|
return false;
|
|
@@ -69,7 +70,7 @@ const hasContextConfig = (db) => async (params) => {
|
|
|
69
70
|
return await getContextConfigById(db)(params) !== null;
|
|
70
71
|
};
|
|
71
72
|
const countContextConfigs = (db) => async (params) => {
|
|
72
|
-
const total = (await db.select({ count: count() }).from(contextConfigs).where(
|
|
73
|
+
const total = (await db.select({ count: count() }).from(contextConfigs).where(agentScopedWhere(contextConfigs, params.scopes)))[0]?.count || 0;
|
|
73
74
|
return typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
74
75
|
};
|
|
75
76
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { credentialReferences, externalAgents, tools } from "../../db/manage/manage-schema.js";
|
|
2
|
+
import { projectScopedWhere } from "./scope-helpers.js";
|
|
2
3
|
import { isUniqueConstraintError } from "../../utils/error.js";
|
|
3
4
|
import { and, count, desc, eq, sql } from "drizzle-orm";
|
|
4
5
|
|
|
@@ -7,22 +8,22 @@ import { and, count, desc, eq, sql } from "drizzle-orm";
|
|
|
7
8
|
* Get a credential reference by ID
|
|
8
9
|
*/
|
|
9
10
|
const getCredentialReference = (db) => async (params) => {
|
|
10
|
-
return await db.query.credentialReferences.findFirst({ where: and(
|
|
11
|
+
return await db.query.credentialReferences.findFirst({ where: and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)) });
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
14
|
* Get a user-scoped credential reference by toolId and userId
|
|
14
15
|
*/
|
|
15
16
|
const getUserScopedCredentialReference = (db) => async (params) => {
|
|
16
|
-
return await db.query.credentialReferences.findFirst({ where: and(
|
|
17
|
+
return await db.query.credentialReferences.findFirst({ where: and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.toolId, params.toolId), eq(credentialReferences.userId, params.userId)) });
|
|
17
18
|
};
|
|
18
19
|
/**
|
|
19
20
|
* Get a credential reference by ID with its related tools
|
|
20
21
|
*/
|
|
21
22
|
const getCredentialReferenceWithResources = (db) => async (params) => {
|
|
22
23
|
const [credential, relatedTools, relatedExternalAgents] = await Promise.all([
|
|
23
|
-
db.query.credentialReferences.findFirst({ where: and(
|
|
24
|
-
db.select().from(tools).where(and(
|
|
25
|
-
db.select().from(externalAgents).where(and(
|
|
24
|
+
db.query.credentialReferences.findFirst({ where: and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)) }),
|
|
25
|
+
db.select().from(tools).where(and(projectScopedWhere(tools, params.scopes), eq(tools.credentialReferenceId, params.id))),
|
|
26
|
+
db.select().from(externalAgents).where(and(projectScopedWhere(externalAgents, params.scopes), eq(externalAgents.credentialReferenceId, params.id)))
|
|
26
27
|
]);
|
|
27
28
|
if (!credential) return;
|
|
28
29
|
return {
|
|
@@ -36,7 +37,7 @@ const getCredentialReferenceWithResources = (db) => async (params) => {
|
|
|
36
37
|
*/
|
|
37
38
|
const listCredentialReferences = (db) => async (params) => {
|
|
38
39
|
return await db.query.credentialReferences.findMany({
|
|
39
|
-
where:
|
|
40
|
+
where: projectScopedWhere(credentialReferences, params.scopes),
|
|
40
41
|
orderBy: [desc(credentialReferences.createdAt)]
|
|
41
42
|
});
|
|
42
43
|
};
|
|
@@ -47,7 +48,7 @@ const listCredentialReferencesPaginated = (db) => async (params) => {
|
|
|
47
48
|
const page = params.pagination?.page || 1;
|
|
48
49
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
49
50
|
const offset = (page - 1) * limit;
|
|
50
|
-
const whereClause =
|
|
51
|
+
const whereClause = projectScopedWhere(credentialReferences, params.scopes);
|
|
51
52
|
const [data, totalResult] = await Promise.all([db.select().from(credentialReferences).where(whereClause).limit(limit).offset(offset).orderBy(desc(credentialReferences.createdAt)), db.select({ count: sql`COUNT(*)` }).from(credentialReferences).where(whereClause)]);
|
|
52
53
|
const total = Number(totalResult[0]?.count || 0);
|
|
53
54
|
return {
|
|
@@ -80,7 +81,7 @@ const updateCredentialReference = (db) => async (params) => {
|
|
|
80
81
|
await db.update(credentialReferences).set({
|
|
81
82
|
...params.data,
|
|
82
83
|
updatedAt: now
|
|
83
|
-
}).where(and(
|
|
84
|
+
}).where(and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)));
|
|
84
85
|
return await getCredentialReferenceWithResources(db)({
|
|
85
86
|
scopes: params.scopes,
|
|
86
87
|
id: params.id
|
|
@@ -94,7 +95,7 @@ const deleteCredentialReference = (db) => async (params) => {
|
|
|
94
95
|
scopes: params.scopes,
|
|
95
96
|
id: params.id
|
|
96
97
|
})) return false;
|
|
97
|
-
await db.delete(credentialReferences).where(and(
|
|
98
|
+
await db.delete(credentialReferences).where(and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)));
|
|
98
99
|
return await getCredentialReference(db)({
|
|
99
100
|
scopes: params.scopes,
|
|
100
101
|
id: params.id
|
|
@@ -110,13 +111,13 @@ const hasCredentialReference = (db) => async (params) => {
|
|
|
110
111
|
* Get credential reference by ID (simple version without tools)
|
|
111
112
|
*/
|
|
112
113
|
const getCredentialReferenceById = (db) => async (params) => {
|
|
113
|
-
return await db.query.credentialReferences.findFirst({ where: and(
|
|
114
|
+
return await db.query.credentialReferences.findFirst({ where: and(projectScopedWhere(credentialReferences, params.scopes), eq(credentialReferences.id, params.id)) }) || null;
|
|
114
115
|
};
|
|
115
116
|
/**
|
|
116
117
|
* Count credential references for a tenant/project
|
|
117
118
|
*/
|
|
118
119
|
const countCredentialReferences = (db) => async (params) => {
|
|
119
|
-
const total = (await db.select({ count: count() }).from(credentialReferences).where(
|
|
120
|
+
const total = (await db.select({ count: count() }).from(credentialReferences).where(projectScopedWhere(credentialReferences, params.scopes)))[0]?.count || 0;
|
|
120
121
|
return typeof total === "string" ? Number.parseInt(total, 10) : total;
|
|
121
122
|
};
|
|
122
123
|
/**
|
|
@@ -66,11 +66,11 @@ declare const associateDataComponentWithAgent: (db: AgentsManageDatabaseClient)
|
|
|
66
66
|
dataComponentId: string;
|
|
67
67
|
}) => Promise<{
|
|
68
68
|
id: string;
|
|
69
|
-
createdAt: string;
|
|
70
|
-
subAgentId: string;
|
|
71
|
-
projectId: string;
|
|
72
69
|
tenantId: string;
|
|
70
|
+
projectId: string;
|
|
73
71
|
agentId: string;
|
|
72
|
+
createdAt: string;
|
|
73
|
+
subAgentId: string;
|
|
74
74
|
dataComponentId: string;
|
|
75
75
|
}>;
|
|
76
76
|
/**
|
|
@@ -108,11 +108,11 @@ declare const upsertAgentDataComponentRelation: (db: AgentsManageDatabaseClient)
|
|
|
108
108
|
dataComponentId: string;
|
|
109
109
|
}) => Promise<{
|
|
110
110
|
id: string;
|
|
111
|
-
createdAt: string;
|
|
112
|
-
subAgentId: string;
|
|
113
|
-
projectId: string;
|
|
114
111
|
tenantId: string;
|
|
112
|
+
projectId: string;
|
|
115
113
|
agentId: string;
|
|
114
|
+
createdAt: string;
|
|
115
|
+
subAgentId: string;
|
|
116
116
|
dataComponentId: string;
|
|
117
117
|
} | null>;
|
|
118
118
|
/**
|