@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
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { AgentScopeConfig, ProjectScopeConfig } from "../../db/manage/scope-definitions.js";
|
|
1
|
+
import { AgentScopeConfig, ProjectScopeConfig, ScopedTable } from "../../db/manage/scope-definitions.js";
|
|
2
2
|
import { ConversationHistoryConfig, PaginationConfig } from "../../types/utility.js";
|
|
3
3
|
import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
|
|
4
4
|
import "../../index.js";
|
|
5
5
|
import { AgentInsert, AgentSelect, AgentUpdate, FullAgentDefinition, FullAgentSelectWithRelationIds } from "../../types/entities.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Column } from "drizzle-orm";
|
|
7
|
+
import { PgColumn } from "drizzle-orm/pg-core";
|
|
7
8
|
|
|
8
9
|
//#region src/data-access/manage/agents.d.ts
|
|
9
10
|
declare const getAgentById: (db: AgentsManageDatabaseClient) => (params: {
|
|
10
11
|
scopes: AgentScopeConfig;
|
|
11
12
|
}) => Promise<{
|
|
13
|
+
tenantId: string;
|
|
14
|
+
projectId: 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;
|
|
@@ -55,13 +56,13 @@ declare const getAgentById: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
55
56
|
declare const getAgentWithDefaultSubAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
56
57
|
scopes: AgentScopeConfig;
|
|
57
58
|
}) => Promise<{
|
|
59
|
+
tenantId: string;
|
|
60
|
+
projectId: string;
|
|
58
61
|
id: string;
|
|
59
62
|
name: string;
|
|
63
|
+
description: string | null;
|
|
60
64
|
createdAt: string;
|
|
61
65
|
updatedAt: string;
|
|
62
|
-
description: string | null;
|
|
63
|
-
projectId: string;
|
|
64
|
-
tenantId: string;
|
|
65
66
|
models: {
|
|
66
67
|
base?: {
|
|
67
68
|
model?: string | undefined;
|
|
@@ -98,13 +99,14 @@ declare const getAgentWithDefaultSubAgent: (db: AgentsManageDatabaseClient) => (
|
|
|
98
99
|
}[] | undefined;
|
|
99
100
|
} | null;
|
|
100
101
|
defaultSubAgent: {
|
|
102
|
+
tenantId: string;
|
|
103
|
+
projectId: string;
|
|
104
|
+
agentId: string;
|
|
101
105
|
id: string;
|
|
102
106
|
name: string;
|
|
107
|
+
description: string | null;
|
|
103
108
|
createdAt: string;
|
|
104
109
|
updatedAt: string;
|
|
105
|
-
description: string | null;
|
|
106
|
-
projectId: string;
|
|
107
|
-
tenantId: string;
|
|
108
110
|
models: {
|
|
109
111
|
base?: {
|
|
110
112
|
model?: string | undefined;
|
|
@@ -124,19 +126,18 @@ declare const getAgentWithDefaultSubAgent: (db: AgentsManageDatabaseClient) => (
|
|
|
124
126
|
} | null;
|
|
125
127
|
prompt: string | null;
|
|
126
128
|
conversationHistoryConfig: ConversationHistoryConfig | null;
|
|
127
|
-
agentId: string;
|
|
128
129
|
} | null;
|
|
129
130
|
} | null>;
|
|
130
131
|
declare const listAgents: (db: AgentsManageDatabaseClient) => (params: {
|
|
131
132
|
scopes: ProjectScopeConfig;
|
|
132
133
|
}) => Promise<{
|
|
134
|
+
tenantId: string;
|
|
135
|
+
projectId: string;
|
|
133
136
|
id: string;
|
|
134
137
|
name: string;
|
|
138
|
+
description: string | null;
|
|
135
139
|
createdAt: string;
|
|
136
140
|
updatedAt: string;
|
|
137
|
-
description: string | null;
|
|
138
|
-
projectId: string;
|
|
139
|
-
tenantId: string;
|
|
140
141
|
models: {
|
|
141
142
|
base?: {
|
|
142
143
|
model?: string | undefined;
|
|
@@ -246,13 +247,13 @@ declare function listAgentsAcrossProjectMainBranches(db: AgentsManageDatabaseCli
|
|
|
246
247
|
projectIds: string[];
|
|
247
248
|
}): Promise<AvailableAgentInfo[]>;
|
|
248
249
|
declare const createAgent: (db: AgentsManageDatabaseClient) => (data: AgentInsert) => Promise<{
|
|
250
|
+
tenantId: string;
|
|
251
|
+
projectId: string;
|
|
249
252
|
id: string;
|
|
250
253
|
name: string;
|
|
254
|
+
description: string | null;
|
|
251
255
|
createdAt: string;
|
|
252
256
|
updatedAt: string;
|
|
253
|
-
description: string | null;
|
|
254
|
-
projectId: string;
|
|
255
|
-
tenantId: string;
|
|
256
257
|
models: {
|
|
257
258
|
base?: {
|
|
258
259
|
model?: string | undefined;
|
|
@@ -343,12 +344,12 @@ declare const deleteAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
|
343
344
|
* Helper function to fetch component relationships using efficient joins
|
|
344
345
|
*/
|
|
345
346
|
declare const fetchComponentRelationships: (db: AgentsManageDatabaseClient) => <T extends Record<string, unknown>>(scopes: AgentScopeConfig, subAgentIds: string[], config: {
|
|
346
|
-
relationTable:
|
|
347
|
-
componentTable:
|
|
348
|
-
relationIdField:
|
|
349
|
-
componentIdField:
|
|
350
|
-
subAgentIdField:
|
|
351
|
-
selectFields: Record<string,
|
|
347
|
+
relationTable: ScopedTable<"agent">;
|
|
348
|
+
componentTable: ScopedTable<"project">;
|
|
349
|
+
relationIdField: Column;
|
|
350
|
+
componentIdField: Column;
|
|
351
|
+
subAgentIdField: Column;
|
|
352
|
+
selectFields: Record<string, PgColumn>;
|
|
352
353
|
}) => Promise<Record<string, T>>;
|
|
353
354
|
declare const getAgentSubAgentInfos: (db: AgentsManageDatabaseClient) => ({
|
|
354
355
|
scopes: {
|
|
@@ -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
|
|
@@ -9,11 +9,13 @@ declare const getArtifactComponentById: (db: AgentsManageDatabaseClient) => (par
|
|
|
9
9
|
scopes: ProjectScopeConfig;
|
|
10
10
|
id: string;
|
|
11
11
|
}) => Promise<{
|
|
12
|
+
tenantId: string;
|
|
13
|
+
projectId: string;
|
|
12
14
|
id: string;
|
|
13
15
|
name: string;
|
|
16
|
+
description: string | null;
|
|
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;
|
|
@@ -65,11 +65,13 @@ declare const listArtifactComponentsPaginated: (db: AgentsManageDatabaseClient)
|
|
|
65
65
|
};
|
|
66
66
|
}>;
|
|
67
67
|
declare const createArtifactComponent: (db: AgentsManageDatabaseClient) => (params: ArtifactComponentInsert) => Promise<{
|
|
68
|
+
tenantId: string;
|
|
69
|
+
projectId: string;
|
|
68
70
|
id: string;
|
|
69
71
|
name: string;
|
|
72
|
+
description: string | null;
|
|
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;
|
|
@@ -141,12 +141,12 @@ declare const associateArtifactComponentWithAgent: (db: AgentsManageDatabaseClie
|
|
|
141
141
|
scopes: SubAgentScopeConfig;
|
|
142
142
|
artifactComponentId: string;
|
|
143
143
|
}) => Promise<{
|
|
144
|
-
id: string;
|
|
145
|
-
createdAt: string;
|
|
146
|
-
subAgentId: string;
|
|
147
|
-
projectId: string;
|
|
148
144
|
tenantId: string;
|
|
145
|
+
projectId: string;
|
|
149
146
|
agentId: string;
|
|
147
|
+
subAgentId: string;
|
|
148
|
+
id: string;
|
|
149
|
+
createdAt: string;
|
|
150
150
|
artifactComponentId: string;
|
|
151
151
|
}>;
|
|
152
152
|
declare const removeArtifactComponentFromAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
@@ -184,12 +184,12 @@ declare const upsertAgentArtifactComponentRelation: (db: AgentsManageDatabaseCli
|
|
|
184
184
|
scopes: SubAgentScopeConfig;
|
|
185
185
|
artifactComponentId: string;
|
|
186
186
|
}) => Promise<{
|
|
187
|
-
id: string;
|
|
188
|
-
createdAt: string;
|
|
189
|
-
subAgentId: string;
|
|
190
|
-
projectId: string;
|
|
191
187
|
tenantId: string;
|
|
188
|
+
projectId: string;
|
|
192
189
|
agentId: string;
|
|
190
|
+
subAgentId: string;
|
|
191
|
+
id: string;
|
|
192
|
+
createdAt: 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
|
|
@@ -9,24 +9,24 @@ declare const getContextConfigById: (db: AgentsManageDatabaseClient) => (params:
|
|
|
9
9
|
scopes: AgentScopeConfig;
|
|
10
10
|
id: string;
|
|
11
11
|
}) => Promise<{
|
|
12
|
+
tenantId: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
agentId: string;
|
|
12
15
|
id: string;
|
|
13
16
|
createdAt: string;
|
|
14
17
|
updatedAt: string;
|
|
15
|
-
projectId: string;
|
|
16
|
-
tenantId: string;
|
|
17
|
-
agentId: string;
|
|
18
18
|
headersSchema: unknown;
|
|
19
19
|
contextVariables: Record<string, ContextFetchDefinition> | null;
|
|
20
20
|
} | undefined>;
|
|
21
21
|
declare const listContextConfigs: (db: AgentsManageDatabaseClient) => (params: {
|
|
22
22
|
scopes: AgentScopeConfig;
|
|
23
23
|
}) => Promise<{
|
|
24
|
+
tenantId: string;
|
|
25
|
+
projectId: string;
|
|
26
|
+
agentId: string;
|
|
24
27
|
id: string;
|
|
25
28
|
createdAt: string;
|
|
26
29
|
updatedAt: string;
|
|
27
|
-
projectId: string;
|
|
28
|
-
tenantId: string;
|
|
29
|
-
agentId: string;
|
|
30
30
|
headersSchema: unknown;
|
|
31
31
|
contextVariables: Record<string, ContextFetchDefinition> | null;
|
|
32
32
|
}[]>;
|
|
@@ -43,12 +43,12 @@ declare const listContextConfigsPaginated: (db: AgentsManageDatabaseClient) => (
|
|
|
43
43
|
};
|
|
44
44
|
}>;
|
|
45
45
|
declare const createContextConfig: (db: AgentsManageDatabaseClient) => (params: ContextConfigInsert) => Promise<{
|
|
46
|
+
tenantId: string;
|
|
47
|
+
projectId: string;
|
|
48
|
+
agentId: string;
|
|
46
49
|
id: string;
|
|
47
50
|
createdAt: string;
|
|
48
51
|
updatedAt: string;
|
|
49
|
-
projectId: string;
|
|
50
|
-
tenantId: string;
|
|
51
|
-
agentId: string;
|
|
52
52
|
headersSchema: unknown;
|
|
53
53
|
contextVariables: Record<string, ContextFetchDefinition> | null;
|
|
54
54
|
}>;
|
|
@@ -83,12 +83,12 @@ declare const countContextConfigs: (db: AgentsManageDatabaseClient) => (params:
|
|
|
83
83
|
declare const upsertContextConfig: (db: AgentsManageDatabaseClient) => (params: {
|
|
84
84
|
data: ContextConfigInsert;
|
|
85
85
|
}) => Promise<{
|
|
86
|
+
tenantId: string;
|
|
87
|
+
projectId: string;
|
|
88
|
+
agentId: string;
|
|
86
89
|
id: string;
|
|
87
90
|
createdAt: string;
|
|
88
91
|
updatedAt: string;
|
|
89
|
-
projectId: string;
|
|
90
|
-
tenantId: string;
|
|
91
|
-
agentId: 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
|
/**
|