@inkeep/agents-core 0.41.2 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client/base-client.d.ts +87 -8
- package/dist/api-client/base-client.js +174 -1
- package/dist/api-client/eval-api-client.d.ts +47 -0
- package/dist/api-client/eval-api-client.js +65 -0
- package/dist/api-client/index.d.ts +4 -0
- package/dist/api-client/index.js +5 -0
- package/dist/api-client/manage-api-client.d.ts +34 -0
- package/dist/api-client/manage-api-client.js +104 -0
- package/dist/auth/auth.d.ts +86 -20
- package/dist/auth/auth.js +55 -1
- package/dist/auth/authz/client.d.ts +81 -0
- package/dist/auth/authz/client.js +189 -0
- package/dist/auth/authz/config.d.ts +76 -0
- package/dist/auth/authz/config.js +76 -0
- package/dist/auth/authz/index.d.ts +5 -0
- package/dist/auth/authz/index.js +6 -0
- package/dist/auth/authz/permissions.d.ts +57 -0
- package/dist/auth/authz/permissions.js +83 -0
- package/dist/auth/authz/sync.d.ts +85 -0
- package/dist/auth/authz/sync.js +237 -0
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/auth/permissions.js +2 -181
- package/dist/client-exports.d.ts +8 -3
- package/dist/client-exports.js +3 -2
- package/dist/constants/context-breakdown.d.ts +61 -0
- package/dist/constants/context-breakdown.js +124 -0
- package/dist/constants/otel-attributes.d.ts +4 -0
- package/dist/constants/otel-attributes.js +4 -0
- package/dist/context/ContextConfig.d.ts +2 -2
- package/dist/context/ContextConfig.js +3 -3
- package/dist/context/TemplateEngine.js +0 -1
- package/dist/context/index.d.ts +1 -5
- package/dist/context/index.js +1 -5
- package/dist/credential-stuffer/CredentialStuffer.d.ts +1 -1
- package/dist/data-access/index.d.ts +34 -26
- package/dist/data-access/index.js +34 -26
- package/dist/data-access/manage/agentFull.d.ts +36 -0
- package/dist/data-access/{agentFull.js → manage/agentFull.js} +205 -7
- package/dist/data-access/{agents.d.ts → manage/agents.d.ts} +23 -22
- package/dist/data-access/{agents.js → manage/agents.js} +52 -7
- package/dist/data-access/{artifactComponents.d.ts → manage/artifactComponents.d.ts} +21 -21
- package/dist/data-access/{artifactComponents.js → manage/artifactComponents.js} +5 -5
- package/dist/data-access/{contextConfigs.d.ts → manage/contextConfigs.d.ts} +14 -14
- package/dist/data-access/{contextConfigs.js → manage/contextConfigs.js} +3 -3
- package/dist/data-access/{credentialReferences.d.ts → manage/credentialReferences.d.ts} +17 -17
- package/dist/data-access/{credentialReferences.js → manage/credentialReferences.js} +2 -2
- package/dist/data-access/{dataComponents.d.ts → manage/dataComponents.d.ts} +20 -20
- package/dist/data-access/{dataComponents.js → manage/dataComponents.js} +7 -7
- package/dist/data-access/manage/evalConfig.d.ts +221 -0
- package/dist/data-access/manage/evalConfig.js +275 -0
- package/dist/data-access/{externalAgents.d.ts → manage/externalAgents.d.ts} +16 -16
- package/dist/data-access/{externalAgents.js → manage/externalAgents.js} +2 -2
- package/dist/data-access/{functionTools.d.ts → manage/functionTools.d.ts} +65 -15
- package/dist/data-access/{functionTools.js → manage/functionTools.js} +90 -8
- package/dist/data-access/{functions.d.ts → manage/functions.d.ts} +9 -9
- package/dist/data-access/{functions.js → manage/functions.js} +3 -3
- package/dist/data-access/manage/projectFull.d.ts +38 -0
- package/dist/data-access/{projectFull.js → manage/projectFull.js} +64 -65
- package/dist/data-access/manage/projectLifecycle.d.ts +119 -0
- package/dist/data-access/manage/projectLifecycle.js +234 -0
- package/dist/data-access/manage/projects.d.ts +75 -0
- package/dist/data-access/{projects.js → manage/projects.js} +15 -16
- package/dist/data-access/{subAgentExternalAgentRelations.d.ts → manage/subAgentExternalAgentRelations.d.ts} +19 -19
- package/dist/data-access/{subAgentExternalAgentRelations.js → manage/subAgentExternalAgentRelations.js} +2 -2
- package/dist/data-access/{subAgentRelations.d.ts → manage/subAgentRelations.d.ts} +29 -29
- package/dist/data-access/{subAgentRelations.js → manage/subAgentRelations.js} +3 -3
- package/dist/data-access/{subAgentTeamAgentRelations.d.ts → manage/subAgentTeamAgentRelations.d.ts} +19 -19
- package/dist/data-access/{subAgentTeamAgentRelations.js → manage/subAgentTeamAgentRelations.js} +2 -2
- package/dist/data-access/{subAgents.d.ts → manage/subAgents.d.ts} +13 -13
- package/dist/data-access/{subAgents.js → manage/subAgents.js} +4 -4
- package/dist/data-access/{tools.d.ts → manage/tools.d.ts} +26 -19
- package/dist/data-access/{tools.js → manage/tools.js} +57 -35
- package/dist/data-access/manage/triggers.d.ts +80 -0
- package/dist/data-access/manage/triggers.js +81 -0
- package/dist/data-access/{apiKeys.d.ts → runtime/apiKeys.d.ts} +17 -17
- package/dist/data-access/{apiKeys.js → runtime/apiKeys.js} +3 -3
- package/dist/data-access/runtime/cascade-delete.d.ts +77 -0
- package/dist/data-access/runtime/cascade-delete.js +111 -0
- package/dist/data-access/{contextCache.d.ts → runtime/contextCache.d.ts} +13 -13
- package/dist/data-access/{contextCache.js → runtime/contextCache.js} +5 -5
- package/dist/data-access/{conversations.d.ts → runtime/conversations.d.ts} +68 -19
- package/dist/data-access/{conversations.js → runtime/conversations.js} +13 -7
- package/dist/data-access/runtime/evalRuns.d.ts +120 -0
- package/dist/data-access/runtime/evalRuns.js +168 -0
- package/dist/data-access/{ledgerArtifacts.d.ts → runtime/ledgerArtifacts.d.ts} +13 -13
- package/dist/data-access/{ledgerArtifacts.js → runtime/ledgerArtifacts.js} +3 -3
- package/dist/data-access/{messages.d.ts → runtime/messages.d.ts} +15 -15
- package/dist/data-access/{messages.js → runtime/messages.js} +2 -2
- package/dist/data-access/{organizations.d.ts → runtime/organizations.d.ts} +16 -7
- package/dist/data-access/{organizations.js → runtime/organizations.js} +15 -3
- package/dist/data-access/runtime/projects.d.ts +62 -0
- package/dist/data-access/runtime/projects.js +90 -0
- package/dist/data-access/runtime/tasks.d.ts +55 -0
- package/dist/data-access/{tasks.js → runtime/tasks.js} +2 -2
- package/dist/data-access/runtime/triggerInvocations.d.ts +62 -0
- package/dist/data-access/runtime/triggerInvocations.js +54 -0
- package/dist/data-access/runtime/users.d.ts +19 -0
- package/dist/data-access/{users.js → runtime/users.js} +2 -2
- package/dist/data-access/validation.d.ts +4 -4
- package/dist/data-access/validation.js +1 -1
- package/dist/db/clean.d.ts +8 -4
- package/dist/db/clean.js +14 -105
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +7 -10
- package/dist/db/manage/dolt-cleanup.d.ts +51 -0
- package/dist/db/manage/dolt-cleanup.js +132 -0
- package/dist/db/manage/manage-client.d.ts +26 -0
- package/dist/db/manage/manage-client.js +68 -0
- package/dist/db/{schema.d.ts → manage/manage-schema.d.ts} +1459 -1285
- package/dist/db/{schema.js → manage/manage-schema.js} +433 -341
- package/dist/db/manage/test-manage-client.d.ts +27 -0
- package/dist/db/manage/test-manage-client.js +68 -0
- package/dist/db/runtime/runtime-client.d.ts +20 -0
- package/dist/db/runtime/runtime-client.js +30 -0
- package/dist/db/runtime/runtime-schema.d.ts +2834 -0
- package/dist/db/runtime/runtime-schema.js +483 -0
- package/dist/db/runtime/test-runtime-client.d.ts +27 -0
- package/dist/db/{test-client.js → runtime/test-runtime-client.js} +11 -25
- package/dist/dolt/branch.d.ts +62 -0
- package/dist/dolt/branch.js +82 -0
- package/dist/dolt/branches-api.d.ts +108 -0
- package/dist/dolt/branches-api.js +162 -0
- package/dist/dolt/commit.d.ts +94 -0
- package/dist/dolt/commit.js +103 -0
- package/dist/dolt/diff.d.ts +27 -0
- package/dist/dolt/diff.js +21 -0
- package/dist/dolt/index.d.ts +10 -0
- package/dist/dolt/index.js +11 -0
- package/dist/dolt/merge.d.ts +63 -0
- package/dist/dolt/merge.js +81 -0
- package/dist/dolt/migrate-all-branches.d.ts +4 -0
- package/dist/dolt/migrate-all-branches.js +78 -0
- package/dist/dolt/migrate-dolt.d.ts +1 -0
- package/dist/dolt/migrate-dolt.js +22 -0
- package/dist/dolt/ref-helpers.d.ts +19 -0
- package/dist/dolt/ref-helpers.js +65 -0
- package/dist/dolt/ref-middleware.d.ts +82 -0
- package/dist/dolt/ref-middleware.js +217 -0
- package/dist/dolt/ref-scope.d.ts +101 -0
- package/dist/dolt/ref-scope.js +231 -0
- package/dist/dolt/schema-sync.d.ts +134 -0
- package/dist/dolt/schema-sync.js +246 -0
- package/dist/env.d.ts +6 -4
- package/dist/env.js +3 -2
- package/dist/index.d.ts +71 -44
- package/dist/index.js +74 -47
- package/dist/types/entities.d.ts +81 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +45 -4
- package/dist/utils/JsonTransformer.d.ts +44 -0
- package/dist/utils/JsonTransformer.js +112 -0
- package/dist/utils/apiKeys.d.ts +5 -1
- package/dist/utils/apiKeys.js +11 -1
- package/dist/utils/colors.d.ts +34 -0
- package/dist/utils/colors.js +49 -0
- package/dist/utils/credential-store-utils.d.ts +1 -1
- package/dist/utils/format-messages.d.ts +1 -1
- package/dist/utils/index.d.ts +7 -3
- package/dist/utils/index.js +7 -3
- package/dist/utils/internal-service-auth.d.ts +79 -0
- package/dist/utils/internal-service-auth.js +140 -0
- package/dist/utils/jwt-helpers.d.ts +56 -0
- package/dist/utils/jwt-helpers.js +90 -0
- package/dist/utils/service-token-auth.d.ts +9 -27
- package/dist/utils/service-token-auth.js +48 -96
- package/dist/utils/template-interpolation.d.ts +22 -0
- package/dist/utils/template-interpolation.js +62 -0
- package/dist/utils/third-party-mcp-servers/composio-client.js +23 -23
- package/dist/utils/trigger-auth.d.ts +62 -0
- package/dist/utils/trigger-auth.js +125 -0
- package/dist/validation/agentFull.js +2 -4
- package/dist/validation/dolt-schemas.d.ts +49 -0
- package/dist/validation/dolt-schemas.js +44 -0
- package/dist/validation/drizzle-schema-helpers.d.ts +4 -26
- package/dist/validation/drizzle-schema-helpers.js +5 -151
- package/dist/validation/index.d.ts +4 -3
- package/dist/validation/index.js +3 -2
- package/dist/validation/schemas.d.ts +17647 -4789
- package/dist/validation/schemas.js +328 -11
- package/drizzle/manage/0000_tearful_rhodey.sql +414 -0
- package/drizzle/manage/0001_broken_wendell_vaughn.sql +19 -0
- package/drizzle/manage/0002_bent_sunfire.sql +1 -0
- package/drizzle/manage/meta/0000_snapshot.json +2987 -0
- package/drizzle/manage/meta/0001_snapshot.json +3115 -0
- package/drizzle/manage/meta/0002_snapshot.json +3115 -0
- package/drizzle/manage/meta/_journal.json +27 -0
- package/drizzle/runtime/0008_silly_preak.sql +127 -0
- package/drizzle/runtime/0009_freezing_leo.sql +17 -0
- package/drizzle/runtime/meta/0008_snapshot.json +2263 -0
- package/drizzle/runtime/meta/0009_snapshot.json +2397 -0
- package/drizzle/{meta → runtime/meta}/_journal.json +14 -0
- package/package.json +48 -15
- package/dist/context/ContextFetcher.d.ts +0 -73
- package/dist/context/ContextFetcher.js +0 -291
- package/dist/context/ContextResolver.d.ts +0 -60
- package/dist/context/ContextResolver.js +0 -278
- package/dist/context/context.d.ts +0 -27
- package/dist/context/context.js +0 -128
- package/dist/context/contextCache.d.ts +0 -58
- package/dist/context/contextCache.js +0 -177
- package/dist/data-access/agentFull.d.ts +0 -33
- package/dist/data-access/projectFull.d.ts +0 -32
- package/dist/data-access/projects.d.ts +0 -71
- package/dist/data-access/tasks.d.ts +0 -45
- package/dist/data-access/users.d.ts +0 -19
- package/dist/db/client.d.ts +0 -20
- package/dist/db/client.js +0 -28
- package/dist/db/test-client.d.ts +0 -31
- package/dist/middleware/contextValidation.d.ts +0 -46
- package/dist/middleware/contextValidation.js +0 -280
- package/dist/middleware/index.d.ts +0 -2
- package/dist/middleware/index.js +0 -3
- package/dist/utils/execution.d.ts +0 -22
- package/dist/utils/execution.js +0 -25
- /package/drizzle/{0000_exotic_mysterio.sql → runtime/0000_exotic_mysterio.sql} +0 -0
- /package/drizzle/{0001_calm_sheva_callister.sql → runtime/0001_calm_sheva_callister.sql} +0 -0
- /package/drizzle/{0002_puzzling_goblin_queen.sql → runtime/0002_puzzling_goblin_queen.sql} +0 -0
- /package/drizzle/{0003_sweet_human_robot.sql → runtime/0003_sweet_human_robot.sql} +0 -0
- /package/drizzle/{0004_cuddly_shooting_star.sql → runtime/0004_cuddly_shooting_star.sql} +0 -0
- /package/drizzle/{0005_reflective_starfox.sql → runtime/0005_reflective_starfox.sql} +0 -0
- /package/drizzle/{0006_stale_thaddeus_ross.sql → runtime/0006_stale_thaddeus_ross.sql} +0 -0
- /package/drizzle/{0007_slim_karma.sql → runtime/0007_slim_karma.sql} +0 -0
- /package/drizzle/{meta → runtime/meta}/0000_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0001_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0003_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0005_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0006_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0007_snapshot.json +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { agents, subAgents } from "
|
|
1
|
+
import { agents, subAgents } from "../../db/manage/manage-schema.js";
|
|
2
2
|
import { and, count, desc, eq, inArray } from "drizzle-orm";
|
|
3
3
|
|
|
4
|
-
//#region src/data-access/subAgents.ts
|
|
4
|
+
//#region src/data-access/manage/subAgents.ts
|
|
5
5
|
const getSubAgentById = (db) => async (params) => {
|
|
6
6
|
return await db.query.subAgents.findFirst({ where: and(eq(subAgents.tenantId, params.scopes.tenantId), eq(subAgents.projectId, params.scopes.projectId), eq(subAgents.agentId, params.scopes.agentId), eq(subAgents.id, params.subAgentId)) });
|
|
7
7
|
};
|
|
@@ -37,7 +37,7 @@ const updateSubAgent = (db) => async (params) => {
|
|
|
37
37
|
...data,
|
|
38
38
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
39
39
|
};
|
|
40
|
-
return (await db.update(subAgents).set(updateData).where(and(eq(subAgents.tenantId, params.scopes.tenantId), eq(subAgents.projectId, params.scopes.projectId), eq(subAgents.agentId, params.scopes.agentId),
|
|
40
|
+
return (await db.update(subAgents).set(updateData).where(and(eq(subAgents.tenantId, params.scopes.tenantId), eq(subAgents.projectId, params.scopes.projectId), eq(subAgents.agentId, params.scopes.agentId), inArray(subAgents.id, [params.subAgentId]))).returning())[0] ?? null;
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
43
|
* Upsert agent (create if it doesn't exist, update if it does)
|
|
@@ -79,7 +79,7 @@ var SubAgentIsDefaultError = class extends Error {
|
|
|
79
79
|
};
|
|
80
80
|
const deleteSubAgent = (db) => async (params) => {
|
|
81
81
|
if ((await db.select().from(agents).where(and(eq(agents.tenantId, params.scopes.tenantId), eq(agents.projectId, params.scopes.projectId), eq(agents.id, params.scopes.agentId), eq(agents.defaultSubAgentId, params.subAgentId))).limit(1)).length > 0) throw new SubAgentIsDefaultError(params.subAgentId, params.scopes.agentId);
|
|
82
|
-
await db.delete(subAgents).where(and(eq(subAgents.tenantId, params.scopes.tenantId), eq(subAgents.projectId, params.scopes.projectId), eq(subAgents.agentId, params.scopes.agentId),
|
|
82
|
+
await db.delete(subAgents).where(and(eq(subAgents.tenantId, params.scopes.tenantId), eq(subAgents.projectId, params.scopes.projectId), eq(subAgents.agentId, params.scopes.agentId), inArray(subAgents.id, [params.subAgentId])));
|
|
83
83
|
return await getSubAgentById(db)({
|
|
84
84
|
scopes: params.scopes,
|
|
85
85
|
subAgentId: params.subAgentId
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "
|
|
3
|
-
import { CredentialStoreRegistry } from "
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
1
|
+
import { AgentScopeConfig, PaginationConfig, ProjectScopeConfig, ToolMcpConfig, ToolServerCapabilities } from "../../types/utility.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { CredentialStoreRegistry } from "../../credential-stores/CredentialStoreRegistry.js";
|
|
4
|
+
import "../../credential-stores/index.js";
|
|
5
|
+
import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
|
|
6
|
+
import "../../index.js";
|
|
7
|
+
import { McpTool, ToolInsert, ToolSelect, ToolUpdate } from "../../types/entities.js";
|
|
8
8
|
|
|
9
|
-
//#region src/data-access/tools.d.ts
|
|
10
|
-
declare const dbResultToMcpTool: (dbResult: ToolSelect, dbClient:
|
|
11
|
-
declare const getToolById: (db:
|
|
9
|
+
//#region src/data-access/manage/tools.d.ts
|
|
10
|
+
declare const dbResultToMcpTool: (dbResult: ToolSelect, dbClient: AgentsManageDatabaseClient, credentialStoreRegistry?: CredentialStoreRegistry, relationshipId?: string, userId?: string) => Promise<McpTool>;
|
|
11
|
+
declare const getToolById: (db: AgentsManageDatabaseClient) => (params: {
|
|
12
12
|
scopes: ProjectScopeConfig;
|
|
13
13
|
toolId: string;
|
|
14
14
|
}) => Promise<{
|
|
@@ -30,7 +30,14 @@ declare const getToolById: (db: DatabaseClient) => (params: {
|
|
|
30
30
|
capabilities: ToolServerCapabilities | null;
|
|
31
31
|
lastError: string | null;
|
|
32
32
|
} | null>;
|
|
33
|
-
declare const
|
|
33
|
+
declare const getMcpToolById: (db: AgentsManageDatabaseClient) => (params: {
|
|
34
|
+
scopes: ProjectScopeConfig;
|
|
35
|
+
toolId: string;
|
|
36
|
+
relationshipId?: string;
|
|
37
|
+
credentialStoreRegistry?: CredentialStoreRegistry;
|
|
38
|
+
userId?: string;
|
|
39
|
+
}) => Promise<McpTool | null>;
|
|
40
|
+
declare const listTools: (db: AgentsManageDatabaseClient) => (params: {
|
|
34
41
|
scopes: ProjectScopeConfig;
|
|
35
42
|
pagination?: PaginationConfig;
|
|
36
43
|
}) => Promise<{
|
|
@@ -60,7 +67,7 @@ declare const listTools: (db: DatabaseClient) => (params: {
|
|
|
60
67
|
pages: number;
|
|
61
68
|
};
|
|
62
69
|
}>;
|
|
63
|
-
declare const createTool: (db:
|
|
70
|
+
declare const createTool: (db: AgentsManageDatabaseClient) => (params: ToolInsert) => Promise<{
|
|
64
71
|
tenantId: string;
|
|
65
72
|
projectId: string;
|
|
66
73
|
id: string;
|
|
@@ -79,7 +86,7 @@ declare const createTool: (db: DatabaseClient) => (params: ToolInsert) => Promis
|
|
|
79
86
|
capabilities: ToolServerCapabilities | null;
|
|
80
87
|
lastError: string | null;
|
|
81
88
|
}>;
|
|
82
|
-
declare const updateTool: (db:
|
|
89
|
+
declare const updateTool: (db: AgentsManageDatabaseClient) => (params: {
|
|
83
90
|
scopes: ProjectScopeConfig;
|
|
84
91
|
toolId: string;
|
|
85
92
|
data: ToolUpdate;
|
|
@@ -102,11 +109,11 @@ declare const updateTool: (db: DatabaseClient) => (params: {
|
|
|
102
109
|
tenantId: string;
|
|
103
110
|
id: string;
|
|
104
111
|
}>;
|
|
105
|
-
declare const deleteTool: (db:
|
|
112
|
+
declare const deleteTool: (db: AgentsManageDatabaseClient) => (params: {
|
|
106
113
|
scopes: ProjectScopeConfig;
|
|
107
114
|
toolId: string;
|
|
108
115
|
}) => Promise<boolean>;
|
|
109
|
-
declare const addToolToAgent: (db:
|
|
116
|
+
declare const addToolToAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
110
117
|
scopes: AgentScopeConfig;
|
|
111
118
|
subAgentId: string;
|
|
112
119
|
toolId: string;
|
|
@@ -130,7 +137,7 @@ declare const addToolToAgent: (db: DatabaseClient) => (params: {
|
|
|
130
137
|
subAgentId: string;
|
|
131
138
|
selectedTools: string[] | null;
|
|
132
139
|
}>;
|
|
133
|
-
declare const removeToolFromAgent: (db:
|
|
140
|
+
declare const removeToolFromAgent: (db: AgentsManageDatabaseClient) => (params: {
|
|
134
141
|
scopes: AgentScopeConfig;
|
|
135
142
|
subAgentId: string;
|
|
136
143
|
toolId: string;
|
|
@@ -152,7 +159,7 @@ declare const removeToolFromAgent: (db: DatabaseClient) => (params: {
|
|
|
152
159
|
/**
|
|
153
160
|
* Upsert agent-tool relation (create if it doesn't exist, update if it does)
|
|
154
161
|
*/
|
|
155
|
-
declare const upsertSubAgentToolRelation: (db:
|
|
162
|
+
declare const upsertSubAgentToolRelation: (db: AgentsManageDatabaseClient) => (params: {
|
|
156
163
|
scopes: AgentScopeConfig;
|
|
157
164
|
subAgentId: string;
|
|
158
165
|
toolId: string;
|
|
@@ -180,7 +187,7 @@ declare const upsertSubAgentToolRelation: (db: DatabaseClient) => (params: {
|
|
|
180
187
|
/**
|
|
181
188
|
* Upsert a tool (create if it doesn't exist, update if it does)
|
|
182
189
|
*/
|
|
183
|
-
declare const upsertTool: (db:
|
|
190
|
+
declare const upsertTool: (db: AgentsManageDatabaseClient) => (params: {
|
|
184
191
|
data: ToolInsert;
|
|
185
192
|
}) => Promise<{
|
|
186
193
|
tenantId: string;
|
|
@@ -202,4 +209,4 @@ declare const upsertTool: (db: DatabaseClient) => (params: {
|
|
|
202
209
|
lastError: string | null;
|
|
203
210
|
}>;
|
|
204
211
|
//#endregion
|
|
205
|
-
export { addToolToAgent, createTool, dbResultToMcpTool, deleteTool, getToolById, listTools, removeToolFromAgent, updateTool, upsertSubAgentToolRelation, upsertTool };
|
|
212
|
+
export { addToolToAgent, createTool, dbResultToMcpTool, deleteTool, getMcpToolById, getToolById, listTools, removeToolFromAgent, updateTool, upsertSubAgentToolRelation, upsertTool };
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { CredentialStoreType, MCPServerType, MCPTransportType } from "
|
|
2
|
-
import { subAgentToolRelations, tools } from "
|
|
3
|
-
import { detectAuthenticationRequired } from "
|
|
4
|
-
import { getLogger } from "
|
|
5
|
-
import { getCredentialStoreLookupKeyFromRetrievalParams } from "
|
|
6
|
-
import { CredentialStuffer } from "
|
|
7
|
-
import
|
|
1
|
+
import { CredentialStoreType, MCPServerType, MCPTransportType } from "../../types/utility.js";
|
|
2
|
+
import { subAgentToolRelations, tools } from "../../db/manage/manage-schema.js";
|
|
3
|
+
import { detectAuthenticationRequired } from "../../utils/auth-detection.js";
|
|
4
|
+
import { getLogger } from "../../utils/logger.js";
|
|
5
|
+
import { getCredentialStoreLookupKeyFromRetrievalParams } from "../../utils/credential-store-utils.js";
|
|
6
|
+
import { CredentialStuffer } from "../../credential-stuffer/CredentialStuffer.js";
|
|
7
|
+
import "../../credential-stuffer/index.js";
|
|
8
|
+
import { generateId } from "../../utils/conversations.js";
|
|
8
9
|
import { updateAgentToolRelation } from "./subAgentRelations.js";
|
|
9
|
-
import "
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import "../utils/index.js";
|
|
10
|
+
import { toISODateString } from "../../utils/date.js";
|
|
11
|
+
import { McpClient } from "../../utils/mcp-client.js";
|
|
12
|
+
import { isThirdPartyMCPServerAuthenticated } from "../../utils/third-party-mcp-servers/third-party-check.js";
|
|
13
|
+
import "../../utils/index.js";
|
|
14
14
|
import { getCredentialReference, getUserScopedCredentialReference } from "./credentialReferences.js";
|
|
15
|
-
import { ContextResolver } from "../context/ContextResolver.js";
|
|
16
|
-
import "../context/index.js";
|
|
17
15
|
import { and, count, desc, eq } from "drizzle-orm";
|
|
18
16
|
|
|
19
|
-
//#region src/data-access/tools.ts
|
|
17
|
+
//#region src/data-access/manage/tools.ts
|
|
20
18
|
const logger = getLogger("tools");
|
|
21
19
|
/**
|
|
22
20
|
* Extract expiration date from credential data stored in credential store
|
|
@@ -49,7 +47,10 @@ async function getCredentialExpiresAt(credentialReference, credentialStoreRegist
|
|
|
49
47
|
* - parameters (direct) - alternative format
|
|
50
48
|
* - schema - another possible location
|
|
51
49
|
*/
|
|
52
|
-
function extractInputSchema(toolDef) {
|
|
50
|
+
function extractInputSchema(toolDef, _toolName, _toolOverrides) {
|
|
51
|
+
return extractOriginalSchema(toolDef);
|
|
52
|
+
}
|
|
53
|
+
function extractOriginalSchema(toolDef) {
|
|
53
54
|
if (toolDef.inputSchema) return toolDef.inputSchema;
|
|
54
55
|
if (toolDef.parameters?.properties) return toolDef.parameters.properties;
|
|
55
56
|
if (toolDef.parameters && typeof toolDef.parameters === "object") return toolDef.parameters;
|
|
@@ -65,7 +66,8 @@ const convertToMCPToolConfig = (tool) => {
|
|
|
65
66
|
serverUrl: tool.config.mcp.server.url,
|
|
66
67
|
mcpType: tool.config.mcp.server.url.includes("api.nango.dev") ? MCPServerType.nango : MCPServerType.generic,
|
|
67
68
|
transport: tool.config.mcp.transport,
|
|
68
|
-
headers: tool.headers
|
|
69
|
+
headers: tool.headers,
|
|
70
|
+
toolOverrides: tool.config.mcp.toolOverrides
|
|
69
71
|
};
|
|
70
72
|
};
|
|
71
73
|
const discoverToolsFromServer = async (tool, dbClient, credentialStoreRegistry, userId) => {
|
|
@@ -92,7 +94,7 @@ const discoverToolsFromServer = async (tool, dbClient, credentialStoreRegistry,
|
|
|
92
94
|
retrievalParams: credentialReference.retrievalParams || {}
|
|
93
95
|
};
|
|
94
96
|
if (!credentialStoreRegistry) throw new Error("CredentialStoreRegistry is required for authenticated tools");
|
|
95
|
-
serverConfig = await new CredentialStuffer(credentialStoreRegistry
|
|
97
|
+
serverConfig = await new CredentialStuffer(credentialStoreRegistry).buildMcpServerConfig({
|
|
96
98
|
tenantId: tool.tenantId,
|
|
97
99
|
projectId: tool.projectId
|
|
98
100
|
}, convertToMCPToolConfig(tool), storeReference);
|
|
@@ -122,11 +124,15 @@ const discoverToolsFromServer = async (tool, dbClient, credentialStoreRegistry,
|
|
|
122
124
|
await client.connect();
|
|
123
125
|
const serverTools = await client.tools();
|
|
124
126
|
await client.disconnect();
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
const toolOverrides = tool.config.mcp.toolOverrides;
|
|
128
|
+
return Object.entries(serverTools).map(([name, toolDef]) => {
|
|
129
|
+
const schema = extractInputSchema(toolDef, name, toolOverrides);
|
|
130
|
+
return {
|
|
131
|
+
name,
|
|
132
|
+
description: toolDef.description || "",
|
|
133
|
+
inputSchema: schema
|
|
134
|
+
};
|
|
135
|
+
});
|
|
130
136
|
} catch (error) {
|
|
131
137
|
logger.error({
|
|
132
138
|
toolId: tool.id,
|
|
@@ -196,17 +202,25 @@ const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, re
|
|
|
196
202
|
}
|
|
197
203
|
}
|
|
198
204
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
205
|
+
try {
|
|
206
|
+
await updateTool(dbClient)({
|
|
207
|
+
scopes: {
|
|
208
|
+
tenantId: dbResult.tenantId,
|
|
209
|
+
projectId: dbResult.projectId
|
|
210
|
+
},
|
|
211
|
+
toolId: dbResult.id,
|
|
212
|
+
data: {
|
|
213
|
+
updatedAt: now,
|
|
214
|
+
lastError: lastErrorComputed
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
} catch (updateError) {
|
|
218
|
+
if (updateError instanceof Error && (updateError.message.includes("serialization failure") || updateError.message.includes("40001") || updateError.cause?.code === "XX000")) logger.debug({ toolId: dbResult.id }, "Skipping tool metadata update due to serialization conflict (concurrent request)");
|
|
219
|
+
else logger.warn({
|
|
220
|
+
toolId: dbResult.id,
|
|
221
|
+
error: updateError
|
|
222
|
+
}, "Failed to update tool metadata - continuing with stale data");
|
|
223
|
+
}
|
|
210
224
|
return {
|
|
211
225
|
...rest,
|
|
212
226
|
status,
|
|
@@ -226,6 +240,14 @@ const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, re
|
|
|
226
240
|
const getToolById = (db) => async (params) => {
|
|
227
241
|
return await db.query.tools.findFirst({ where: and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.projectId, params.scopes.projectId), eq(tools.id, params.toolId)) }) ?? null;
|
|
228
242
|
};
|
|
243
|
+
const getMcpToolById = (db) => async (params) => {
|
|
244
|
+
const tool = await getToolById(db)({
|
|
245
|
+
scopes: params.scopes,
|
|
246
|
+
toolId: params.toolId
|
|
247
|
+
});
|
|
248
|
+
if (!tool) return null;
|
|
249
|
+
return await dbResultToMcpTool(tool, db, params.credentialStoreRegistry, params.relationshipId, params.userId);
|
|
250
|
+
};
|
|
229
251
|
const listTools = (db) => async (params) => {
|
|
230
252
|
const page = params.pagination?.page || 1;
|
|
231
253
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
@@ -329,4 +351,4 @@ const upsertTool = (db) => async (params) => {
|
|
|
329
351
|
};
|
|
330
352
|
|
|
331
353
|
//#endregion
|
|
332
|
-
export { addToolToAgent, createTool, dbResultToMcpTool, deleteTool, getToolById, listTools, removeToolFromAgent, updateTool, upsertSubAgentToolRelation, upsertTool };
|
|
354
|
+
export { addToolToAgent, createTool, dbResultToMcpTool, deleteTool, getMcpToolById, getToolById, listTools, removeToolFromAgent, updateTool, upsertSubAgentToolRelation, upsertTool };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { AgentScopeConfig, PaginationConfig } from "../../types/utility.js";
|
|
2
|
+
import { AgentsManageDatabaseClient } from "../../db/manage/manage-client.js";
|
|
3
|
+
import { TriggerInsert, TriggerSelect, TriggerUpdate } from "../../types/entities.js";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/manage/triggers.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get a trigger by ID (agent-scoped)
|
|
9
|
+
*/
|
|
10
|
+
declare const getTriggerById: (db: AgentsManageDatabaseClient) => (params: {
|
|
11
|
+
scopes: AgentScopeConfig;
|
|
12
|
+
triggerId: string;
|
|
13
|
+
}) => Promise<TriggerSelect | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* List all triggers for an agent
|
|
16
|
+
*/
|
|
17
|
+
declare const listTriggers: (db: AgentsManageDatabaseClient) => (params: {
|
|
18
|
+
scopes: AgentScopeConfig;
|
|
19
|
+
}) => Promise<TriggerSelect[]>;
|
|
20
|
+
/**
|
|
21
|
+
* List triggers for an agent with pagination
|
|
22
|
+
*/
|
|
23
|
+
declare const listTriggersPaginated: (db: AgentsManageDatabaseClient) => (params: {
|
|
24
|
+
scopes: AgentScopeConfig;
|
|
25
|
+
pagination?: PaginationConfig;
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
data: {
|
|
28
|
+
createdAt: string;
|
|
29
|
+
updatedAt: string;
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
inputSchema: Record<string, unknown> | null;
|
|
32
|
+
outputTransform: {
|
|
33
|
+
jmespath?: string;
|
|
34
|
+
objectTransformation?: Record<string, string>;
|
|
35
|
+
} | null;
|
|
36
|
+
messageTemplate: string | null;
|
|
37
|
+
authentication: unknown;
|
|
38
|
+
signingSecret: string | null;
|
|
39
|
+
name: string;
|
|
40
|
+
description: string | null;
|
|
41
|
+
agentId: string;
|
|
42
|
+
projectId: string;
|
|
43
|
+
tenantId: string;
|
|
44
|
+
id: string;
|
|
45
|
+
}[];
|
|
46
|
+
pagination: {
|
|
47
|
+
page: number;
|
|
48
|
+
limit: number;
|
|
49
|
+
total: number;
|
|
50
|
+
pages: number;
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Create a new trigger (agent-scoped)
|
|
55
|
+
*/
|
|
56
|
+
declare const createTrigger: (db: AgentsManageDatabaseClient) => (params: TriggerInsert) => Promise<TriggerSelect>;
|
|
57
|
+
/**
|
|
58
|
+
* Update a trigger (agent-scoped)
|
|
59
|
+
*/
|
|
60
|
+
declare const updateTrigger: (db: AgentsManageDatabaseClient) => (params: {
|
|
61
|
+
scopes: AgentScopeConfig;
|
|
62
|
+
triggerId: string;
|
|
63
|
+
data: TriggerUpdate;
|
|
64
|
+
}) => Promise<TriggerSelect>;
|
|
65
|
+
/**
|
|
66
|
+
* Delete a trigger (agent-scoped)
|
|
67
|
+
*/
|
|
68
|
+
declare const deleteTrigger: (db: AgentsManageDatabaseClient) => (params: {
|
|
69
|
+
scopes: AgentScopeConfig;
|
|
70
|
+
triggerId: string;
|
|
71
|
+
}) => Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Upsert a trigger (create or update based on existence)
|
|
74
|
+
*/
|
|
75
|
+
declare const upsertTrigger: (db: AgentsManageDatabaseClient) => (params: {
|
|
76
|
+
scopes: AgentScopeConfig;
|
|
77
|
+
data: TriggerInsert;
|
|
78
|
+
}) => Promise<TriggerSelect>;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createTrigger, deleteTrigger, getTriggerById, listTriggers, listTriggersPaginated, updateTrigger, upsertTrigger };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { triggers } from "../../db/manage/manage-schema.js";
|
|
2
|
+
import { and, count, desc, eq } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/manage/triggers.ts
|
|
5
|
+
/**
|
|
6
|
+
* Get a trigger by ID (agent-scoped)
|
|
7
|
+
*/
|
|
8
|
+
const getTriggerById = (db) => async (params) => {
|
|
9
|
+
const { scopes, triggerId } = params;
|
|
10
|
+
return await db.query.triggers.findFirst({ where: and(eq(triggers.tenantId, scopes.tenantId), eq(triggers.projectId, scopes.projectId), eq(triggers.agentId, scopes.agentId), eq(triggers.id, triggerId)) });
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* List all triggers for an agent
|
|
14
|
+
*/
|
|
15
|
+
const listTriggers = (db) => async (params) => {
|
|
16
|
+
return await db.query.triggers.findMany({ where: and(eq(triggers.tenantId, params.scopes.tenantId), eq(triggers.projectId, params.scopes.projectId), eq(triggers.agentId, params.scopes.agentId)) });
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* List triggers for an agent with pagination
|
|
20
|
+
*/
|
|
21
|
+
const listTriggersPaginated = (db) => async (params) => {
|
|
22
|
+
const page = params.pagination?.page || 1;
|
|
23
|
+
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
24
|
+
const offset = (page - 1) * limit;
|
|
25
|
+
const whereClause = and(eq(triggers.tenantId, params.scopes.tenantId), eq(triggers.projectId, params.scopes.projectId), eq(triggers.agentId, params.scopes.agentId));
|
|
26
|
+
const [data, totalResult] = await Promise.all([db.select().from(triggers).where(whereClause).limit(limit).offset(offset).orderBy(desc(triggers.createdAt)), db.select({ count: count() }).from(triggers).where(whereClause)]);
|
|
27
|
+
const total = totalResult[0]?.count || 0;
|
|
28
|
+
return {
|
|
29
|
+
data,
|
|
30
|
+
pagination: {
|
|
31
|
+
page,
|
|
32
|
+
limit,
|
|
33
|
+
total,
|
|
34
|
+
pages: Math.ceil(total / limit)
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Create a new trigger (agent-scoped)
|
|
40
|
+
*/
|
|
41
|
+
const createTrigger = (db) => async (params) => {
|
|
42
|
+
return (await db.insert(triggers).values(params).returning())[0];
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Update a trigger (agent-scoped)
|
|
46
|
+
*/
|
|
47
|
+
const updateTrigger = (db) => async (params) => {
|
|
48
|
+
const updateData = {
|
|
49
|
+
...params.data,
|
|
50
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
51
|
+
};
|
|
52
|
+
return (await db.update(triggers).set(updateData).where(and(eq(triggers.tenantId, params.scopes.tenantId), eq(triggers.projectId, params.scopes.projectId), eq(triggers.agentId, params.scopes.agentId), eq(triggers.id, params.triggerId))).returning())[0];
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Delete a trigger (agent-scoped)
|
|
56
|
+
*/
|
|
57
|
+
const deleteTrigger = (db) => async (params) => {
|
|
58
|
+
await db.delete(triggers).where(and(eq(triggers.tenantId, params.scopes.tenantId), eq(triggers.projectId, params.scopes.projectId), eq(triggers.agentId, params.scopes.agentId), eq(triggers.id, params.triggerId)));
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Upsert a trigger (create or update based on existence)
|
|
62
|
+
*/
|
|
63
|
+
const upsertTrigger = (db) => async (params) => {
|
|
64
|
+
const { scopes, data } = params;
|
|
65
|
+
if (await db.query.triggers.findFirst({ where: and(eq(triggers.tenantId, scopes.tenantId), eq(triggers.projectId, scopes.projectId), eq(triggers.agentId, scopes.agentId), eq(triggers.id, data.id)) })) {
|
|
66
|
+
const updateData = {
|
|
67
|
+
...data,
|
|
68
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
69
|
+
};
|
|
70
|
+
return (await db.update(triggers).set(updateData).where(and(eq(triggers.tenantId, scopes.tenantId), eq(triggers.projectId, scopes.projectId), eq(triggers.agentId, scopes.agentId), eq(triggers.id, data.id))).returning())[0];
|
|
71
|
+
}
|
|
72
|
+
return (await db.insert(triggers).values({
|
|
73
|
+
...data,
|
|
74
|
+
tenantId: scopes.tenantId,
|
|
75
|
+
projectId: scopes.projectId,
|
|
76
|
+
agentId: scopes.agentId
|
|
77
|
+
}).returning())[0];
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { createTrigger, deleteTrigger, getTriggerById, listTriggers, listTriggersPaginated, updateTrigger, upsertTrigger };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ApiKeyCreateResult, CreateApiKeyParams, PaginationConfig, ProjectScopeConfig } from "../../types/utility.js";
|
|
2
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
3
|
+
import { ApiKeyInsert, ApiKeySelect, ApiKeyUpdate } from "../../types/entities.js";
|
|
4
4
|
|
|
5
|
-
//#region src/data-access/apiKeys.d.ts
|
|
6
|
-
declare const getApiKeyById: (db:
|
|
5
|
+
//#region src/data-access/runtime/apiKeys.d.ts
|
|
6
|
+
declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
|
|
7
7
|
scopes: ProjectScopeConfig;
|
|
8
8
|
id: string;
|
|
9
9
|
}) => Promise<{
|
|
@@ -20,7 +20,7 @@ declare const getApiKeyById: (db: DatabaseClient) => (params: {
|
|
|
20
20
|
createdAt: string;
|
|
21
21
|
updatedAt: string;
|
|
22
22
|
} | undefined>;
|
|
23
|
-
declare const getApiKeyByPublicId: (db:
|
|
23
|
+
declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: string) => Promise<{
|
|
24
24
|
tenantId: string;
|
|
25
25
|
projectId: string;
|
|
26
26
|
id: string;
|
|
@@ -34,7 +34,7 @@ declare const getApiKeyByPublicId: (db: DatabaseClient) => (publicId: string) =>
|
|
|
34
34
|
createdAt: string;
|
|
35
35
|
updatedAt: string;
|
|
36
36
|
} | undefined>;
|
|
37
|
-
declare const listApiKeys: (db:
|
|
37
|
+
declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
|
|
38
38
|
scopes: ProjectScopeConfig;
|
|
39
39
|
agentId?: string;
|
|
40
40
|
}) => Promise<{
|
|
@@ -51,7 +51,7 @@ declare const listApiKeys: (db: DatabaseClient) => (params: {
|
|
|
51
51
|
createdAt: string;
|
|
52
52
|
updatedAt: string;
|
|
53
53
|
}[]>;
|
|
54
|
-
declare const listApiKeysPaginated: (db:
|
|
54
|
+
declare const listApiKeysPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
55
55
|
scopes: ProjectScopeConfig;
|
|
56
56
|
pagination?: PaginationConfig;
|
|
57
57
|
agentId?: string;
|
|
@@ -64,7 +64,7 @@ declare const listApiKeysPaginated: (db: DatabaseClient) => (params: {
|
|
|
64
64
|
pages: number;
|
|
65
65
|
};
|
|
66
66
|
}>;
|
|
67
|
-
declare const createApiKey: (db:
|
|
67
|
+
declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInsert) => Promise<{
|
|
68
68
|
tenantId: string;
|
|
69
69
|
projectId: string;
|
|
70
70
|
id: string;
|
|
@@ -78,34 +78,34 @@ declare const createApiKey: (db: DatabaseClient) => (params: ApiKeyInsert) => Pr
|
|
|
78
78
|
createdAt: string;
|
|
79
79
|
updatedAt: string;
|
|
80
80
|
}>;
|
|
81
|
-
declare const updateApiKey: (db:
|
|
81
|
+
declare const updateApiKey: (db: AgentsRunDatabaseClient) => (params: {
|
|
82
82
|
scopes: ProjectScopeConfig;
|
|
83
83
|
id: string;
|
|
84
84
|
data: ApiKeyUpdate;
|
|
85
85
|
}) => Promise<{
|
|
86
86
|
createdAt: string;
|
|
87
87
|
updatedAt: string;
|
|
88
|
+
agentId: string;
|
|
88
89
|
publicId: string;
|
|
89
90
|
keyHash: string;
|
|
90
91
|
keyPrefix: string;
|
|
91
92
|
name: string | null;
|
|
92
93
|
lastUsedAt: string | null;
|
|
93
94
|
expiresAt: string | null;
|
|
94
|
-
agentId: string;
|
|
95
95
|
projectId: string;
|
|
96
96
|
tenantId: string;
|
|
97
97
|
id: string;
|
|
98
98
|
}>;
|
|
99
|
-
declare const deleteApiKey: (db:
|
|
99
|
+
declare const deleteApiKey: (db: AgentsRunDatabaseClient) => (params: {
|
|
100
100
|
scopes: ProjectScopeConfig;
|
|
101
101
|
id: string;
|
|
102
102
|
}) => Promise<boolean>;
|
|
103
|
-
declare const hasApiKey: (db:
|
|
103
|
+
declare const hasApiKey: (db: AgentsRunDatabaseClient) => (params: {
|
|
104
104
|
scopes: ProjectScopeConfig;
|
|
105
105
|
id: string;
|
|
106
106
|
}) => Promise<boolean>;
|
|
107
|
-
declare const updateApiKeyLastUsed: (db:
|
|
108
|
-
declare const countApiKeys: (db:
|
|
107
|
+
declare const updateApiKeyLastUsed: (db: AgentsRunDatabaseClient) => (id: string) => Promise<void>;
|
|
108
|
+
declare const countApiKeys: (db: AgentsRunDatabaseClient) => (params: {
|
|
109
109
|
scopes: ProjectScopeConfig;
|
|
110
110
|
agentId?: string;
|
|
111
111
|
}) => Promise<number>;
|
|
@@ -113,10 +113,10 @@ declare const countApiKeys: (db: DatabaseClient) => (params: {
|
|
|
113
113
|
* Create a new API key
|
|
114
114
|
* Returns both the API key record and the full key (which should be shown to the user only once)
|
|
115
115
|
*/
|
|
116
|
-
declare const generateAndCreateApiKey: (params: CreateApiKeyParams, db:
|
|
116
|
+
declare const generateAndCreateApiKey: (params: CreateApiKeyParams, db: AgentsRunDatabaseClient) => Promise<ApiKeyCreateResult>;
|
|
117
117
|
/**
|
|
118
118
|
* Validate an API key and return the associated record if valid
|
|
119
119
|
*/
|
|
120
|
-
declare const validateAndGetApiKey: (key: string, db:
|
|
120
|
+
declare const validateAndGetApiKey: (key: string, db: AgentsRunDatabaseClient) => Promise<ApiKeySelect | null>;
|
|
121
121
|
//#endregion
|
|
122
122
|
export { countApiKeys, createApiKey, deleteApiKey, generateAndCreateApiKey, getApiKeyById, getApiKeyByPublicId, hasApiKey, listApiKeys, listApiKeysPaginated, updateApiKey, updateApiKeyLastUsed, validateAndGetApiKey };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { apiKeys } from "
|
|
2
|
-
import { extractPublicId, generateApiKey, isApiKeyExpired, validateApiKey } from "
|
|
1
|
+
import { apiKeys } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { extractPublicId, generateApiKey, isApiKeyExpired, validateApiKey } from "../../utils/apiKeys.js";
|
|
3
3
|
import { and, count, desc, eq } from "drizzle-orm";
|
|
4
4
|
|
|
5
|
-
//#region src/data-access/apiKeys.ts
|
|
5
|
+
//#region src/data-access/runtime/apiKeys.ts
|
|
6
6
|
const getApiKeyById = (db) => async (params) => {
|
|
7
7
|
return await db.query.apiKeys.findFirst({ where: and(eq(apiKeys.tenantId, params.scopes.tenantId), eq(apiKeys.projectId, params.scopes.projectId), eq(apiKeys.id, params.id)) });
|
|
8
8
|
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AgentScopeConfig, ProjectScopeConfig } from "../../types/utility.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/runtime/cascade-delete.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Result of a cascade delete operation
|
|
8
|
+
*/
|
|
9
|
+
type CascadeDeleteResult = {
|
|
10
|
+
conversationsDeleted: number;
|
|
11
|
+
tasksDeleted: number;
|
|
12
|
+
contextCacheDeleted: number;
|
|
13
|
+
apiKeysDeleted: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Delete all runtime entities for a specific branch.
|
|
17
|
+
* PostgreSQL cascades handle: messages, taskRelations, ledgerArtifacts
|
|
18
|
+
*
|
|
19
|
+
* @param db - Runtime database client
|
|
20
|
+
* @returns Function that performs the cascade delete
|
|
21
|
+
*/
|
|
22
|
+
declare const cascadeDeleteByBranch: (db: AgentsRunDatabaseClient) => (params: {
|
|
23
|
+
scopes: ProjectScopeConfig;
|
|
24
|
+
fullBranchName: string;
|
|
25
|
+
}) => Promise<CascadeDeleteResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Delete all runtime entities for a project on a specific branch.
|
|
28
|
+
* Used when deleting a project from a branch.
|
|
29
|
+
* PostgreSQL cascades handle: messages, taskRelations, ledgerArtifacts
|
|
30
|
+
*
|
|
31
|
+
* @param db - Runtime database client
|
|
32
|
+
* @returns Function that performs the cascade delete
|
|
33
|
+
*/
|
|
34
|
+
declare const cascadeDeleteByProject: (db: AgentsRunDatabaseClient) => (params: {
|
|
35
|
+
scopes: ProjectScopeConfig;
|
|
36
|
+
fullBranchName: string;
|
|
37
|
+
}) => Promise<CascadeDeleteResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Delete all runtime entities for a specific agent on a specific branch.
|
|
40
|
+
* This includes tasks for the agent and conversations where the agent's
|
|
41
|
+
* subAgents are active.
|
|
42
|
+
*
|
|
43
|
+
* @param db - Runtime database client
|
|
44
|
+
* @returns Function that performs the cascade delete
|
|
45
|
+
*/
|
|
46
|
+
declare const cascadeDeleteByAgent: (db: AgentsRunDatabaseClient) => (params: {
|
|
47
|
+
scopes: AgentScopeConfig;
|
|
48
|
+
fullBranchName: string;
|
|
49
|
+
subAgentIds: string[];
|
|
50
|
+
}) => Promise<CascadeDeleteResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Delete all runtime entities for a specific subAgent on a specific branch.
|
|
53
|
+
*
|
|
54
|
+
* @param db - Runtime database client
|
|
55
|
+
* @returns Function that performs the cascade delete
|
|
56
|
+
*/
|
|
57
|
+
declare const cascadeDeleteBySubAgent: (db: AgentsRunDatabaseClient) => (params: {
|
|
58
|
+
scopes: ProjectScopeConfig;
|
|
59
|
+
subAgentId: string;
|
|
60
|
+
fullBranchName: string;
|
|
61
|
+
}) => Promise<CascadeDeleteResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Delete contextCache entries for a specific contextConfig.
|
|
64
|
+
* Used when deleting a contextConfig from the manage DB.
|
|
65
|
+
*
|
|
66
|
+
* @param db - Runtime database client
|
|
67
|
+
* @returns Function that performs the delete
|
|
68
|
+
*/
|
|
69
|
+
declare const cascadeDeleteByContextConfig: (db: AgentsRunDatabaseClient) => (params: {
|
|
70
|
+
scopes: ProjectScopeConfig;
|
|
71
|
+
contextConfigId: string;
|
|
72
|
+
fullBranchName: string;
|
|
73
|
+
}) => Promise<{
|
|
74
|
+
contextCacheDeleted: number;
|
|
75
|
+
}>;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { CascadeDeleteResult, cascadeDeleteByAgent, cascadeDeleteByBranch, cascadeDeleteByContextConfig, cascadeDeleteByProject, cascadeDeleteBySubAgent };
|