@inkeep/agents-core 0.41.2 → 0.43.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 +60 -2
- package/dist/auth/authz/client.d.ts +87 -0
- package/dist/auth/authz/client.js +196 -0
- package/dist/auth/authz/config.d.ts +103 -0
- package/dist/auth/authz/config.js +93 -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 +53 -0
- package/dist/auth/authz/permissions.js +83 -0
- package/dist/auth/authz/sync.d.ts +106 -0
- package/dist/auth/authz/sync.js +321 -0
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/auth/permissions.js +2 -181
- package/dist/client-exports.d.ts +9 -3
- package/dist/client-exports.js +4 -2
- package/dist/constants/context-breakdown.d.ts +61 -0
- package/dist/constants/context-breakdown.js +124 -0
- package/dist/constants/execution-limits-shared/defaults.d.ts +1 -1
- package/dist/constants/execution-limits-shared/defaults.js +1 -1
- package/dist/constants/execution-limits-shared/index.d.ts +1 -1
- 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.d.ts +0 -6
- package/dist/context/TemplateEngine.js +4 -19
- package/dist/context/index.d.ts +1 -5
- package/dist/context/index.js +1 -5
- package/dist/credential-stores/keychain-store.d.ts +20 -8
- package/dist/credential-stores/keychain-store.js +107 -43
- 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} +209 -7
- package/dist/data-access/{agents.d.ts → manage/agents.d.ts} +64 -63
- package/dist/data-access/{agents.js → manage/agents.js} +80 -27
- package/dist/data-access/{artifactComponents.d.ts → manage/artifactComponents.d.ts} +33 -33
- package/dist/data-access/{artifactComponents.js → manage/artifactComponents.js} +5 -5
- package/dist/data-access/{contextConfigs.d.ts → manage/contextConfigs.d.ts} +26 -26
- 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} +26 -26
- 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/manage/functionTools.d.ts +242 -0
- package/dist/data-access/{functionTools.js → manage/functionTools.js} +124 -30
- 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} +43 -43
- package/dist/data-access/{subAgentExternalAgentRelations.js → manage/subAgentExternalAgentRelations.js} +2 -2
- package/dist/data-access/{subAgentRelations.d.ts → manage/subAgentRelations.d.ts} +65 -65
- package/dist/data-access/{subAgentRelations.js → manage/subAgentRelations.js} +3 -3
- package/dist/data-access/{subAgentTeamAgentRelations.d.ts → manage/subAgentTeamAgentRelations.d.ts} +43 -43
- package/dist/data-access/{subAgentTeamAgentRelations.js → manage/subAgentTeamAgentRelations.js} +2 -2
- package/dist/data-access/{subAgents.d.ts → manage/subAgents.d.ts} +28 -28
- package/dist/data-access/{subAgents.js → manage/subAgents.js} +4 -4
- package/dist/data-access/{tools.d.ts → manage/tools.d.ts} +65 -52
- package/dist/data-access/{tools.js → manage/tools.js} +109 -64
- package/dist/data-access/manage/triggers.d.ts +106 -0
- package/dist/data-access/manage/triggers.js +81 -0
- package/dist/data-access/{apiKeys.d.ts → runtime/apiKeys.d.ts} +37 -37
- 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} +80 -31
- 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} +24 -24
- 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} +16 -4
- 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} +1257 -969
- package/dist/db/{schema.js → manage/manage-schema.js} +436 -334
- 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/db/utils.d.ts +6 -0
- package/dist/db/utils.js +42 -0
- 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 +83 -0
- package/dist/dolt/migrate-dolt.d.ts +1 -0
- package/dist/dolt/migrate-dolt.js +25 -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 +135 -0
- package/dist/dolt/schema-sync.js +255 -0
- package/dist/env.d.ts +6 -4
- package/dist/env.js +3 -2
- package/dist/index.d.ts +73 -46
- package/dist/index.js +76 -49
- package/dist/types/@napi-rs__keyring/index.d.ts +14 -0
- package/dist/types/entities.d.ts +81 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +46 -5
- package/dist/types/utility.js +2 -1
- package/dist/utils/JsonTransformer.d.ts +42 -0
- package/dist/utils/JsonTransformer.js +103 -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 +8 -4
- package/dist/utils/index.js +8 -4
- package/dist/utils/internal-service-auth.d.ts +79 -0
- package/dist/utils/internal-service-auth.js +140 -0
- package/dist/utils/jmespath-utils.d.ts +152 -0
- package/dist/utils/jmespath-utils.js +213 -0
- package/dist/utils/jwt-helpers.d.ts +56 -0
- package/dist/utils/jwt-helpers.js +90 -0
- package/dist/utils/mcp-client.d.ts +1 -1
- package/dist/utils/mcp-client.js +1 -1
- package/dist/utils/service-token-auth.d.ts +9 -27
- package/dist/utils/service-token-auth.js +48 -96
- package/dist/utils/signature-validation.d.ts +2 -0
- package/dist/utils/signature-validation.js +3 -0
- 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.d.ts +13 -1
- package/dist/utils/third-party-mcp-servers/composio-client.js +47 -29
- package/dist/utils/third-party-mcp-servers/index.d.ts +2 -2
- package/dist/utils/third-party-mcp-servers/index.js +2 -2
- package/dist/utils/trigger-auth.d.ts +85 -0
- package/dist/utils/trigger-auth.js +233 -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 +5 -4
- package/dist/validation/index.js +4 -3
- package/dist/validation/render-validation.js +19 -0
- package/dist/validation/schemas.d.ts +18223 -5148
- package/dist/validation/schemas.js +559 -12
- package/dist/validation/stream-event-schemas.d.ts +96 -1
- package/dist/validation/stream-event-schemas.js +67 -2
- 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/0003_tiny_captain_universe.sql +8 -0
- package/drizzle/manage/0004_curious_phil_sheldon.sql +2 -0
- package/drizzle/manage/0005_silent_shatterstar.sql +53 -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/0003_snapshot.json +3134 -0
- package/drizzle/manage/meta/0004_snapshot.json +3141 -0
- package/drizzle/manage/meta/0005_snapshot.json +3141 -0
- package/drizzle/manage/meta/_journal.json +48 -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 +56 -18
- package/spicedb/schema.zed +114 -0
- 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/functionTools.d.ts +0 -169
- 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,22 +1,36 @@
|
|
|
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 { isThirdPartyMCPServerAuthenticated } from "
|
|
13
|
-
import "
|
|
10
|
+
import { toISODateString } from "../../utils/date.js";
|
|
11
|
+
import { McpClient } from "../../utils/mcp-client.js";
|
|
12
|
+
import { buildComposioMCPUrl } from "../../utils/third-party-mcp-servers/composio-client.js";
|
|
13
|
+
import { isThirdPartyMCPServerAuthenticated } from "../../utils/third-party-mcp-servers/third-party-check.js";
|
|
14
|
+
import "../../utils/index.js";
|
|
14
15
|
import { getCredentialReference, getUserScopedCredentialReference } from "./credentialReferences.js";
|
|
15
|
-
import { ContextResolver } from "../context/ContextResolver.js";
|
|
16
|
-
import "../context/index.js";
|
|
17
16
|
import { and, count, desc, eq } from "drizzle-orm";
|
|
17
|
+
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
18
18
|
|
|
19
|
-
//#region src/data-access/tools.ts
|
|
19
|
+
//#region src/data-access/manage/tools.ts
|
|
20
|
+
/**
|
|
21
|
+
* Check if an error is a timeout/connection error.
|
|
22
|
+
* Uses MCP SDK ErrorCode for proper type safety.
|
|
23
|
+
*/
|
|
24
|
+
function isTimeoutOrConnectionError(error) {
|
|
25
|
+
if (error instanceof McpError) return error.code === ErrorCode.RequestTimeout || error.code === ErrorCode.ConnectionClosed;
|
|
26
|
+
if (error instanceof Error) {
|
|
27
|
+
const message = error.message.toLowerCase();
|
|
28
|
+
const cause = error.cause;
|
|
29
|
+
if (message.includes("timed out") || message.includes("timeout")) return true;
|
|
30
|
+
if (cause?.code === "ETIMEDOUT" || cause?.code === "ECONNABORTED" || cause?.code === "ECONNRESET") return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
20
34
|
const logger = getLogger("tools");
|
|
21
35
|
/**
|
|
22
36
|
* Extract expiration date from credential data stored in credential store
|
|
@@ -49,7 +63,10 @@ async function getCredentialExpiresAt(credentialReference, credentialStoreRegist
|
|
|
49
63
|
* - parameters (direct) - alternative format
|
|
50
64
|
* - schema - another possible location
|
|
51
65
|
*/
|
|
52
|
-
function extractInputSchema(toolDef) {
|
|
66
|
+
function extractInputSchema(toolDef, _toolName, _toolOverrides) {
|
|
67
|
+
return extractOriginalSchema(toolDef);
|
|
68
|
+
}
|
|
69
|
+
function extractOriginalSchema(toolDef) {
|
|
53
70
|
if (toolDef.inputSchema) return toolDef.inputSchema;
|
|
54
71
|
if (toolDef.parameters?.properties) return toolDef.parameters.properties;
|
|
55
72
|
if (toolDef.parameters && typeof toolDef.parameters === "object") return toolDef.parameters;
|
|
@@ -65,34 +82,21 @@ const convertToMCPToolConfig = (tool) => {
|
|
|
65
82
|
serverUrl: tool.config.mcp.server.url,
|
|
66
83
|
mcpType: tool.config.mcp.server.url.includes("api.nango.dev") ? MCPServerType.nango : MCPServerType.generic,
|
|
67
84
|
transport: tool.config.mcp.transport,
|
|
68
|
-
headers: tool.headers
|
|
85
|
+
headers: tool.headers,
|
|
86
|
+
toolOverrides: tool.config.mcp.toolOverrides
|
|
69
87
|
};
|
|
70
88
|
};
|
|
71
|
-
const discoverToolsFromServer = async (tool,
|
|
89
|
+
const discoverToolsFromServer = async (tool, credentialReference, credentialStoreRegistry, userId) => {
|
|
72
90
|
if (tool.config.type !== "mcp") throw new Error(`Cannot discover tools from non-MCP tool: ${tool.id}`);
|
|
73
91
|
try {
|
|
74
92
|
let serverConfig;
|
|
75
|
-
const credentialReference = tool.credentialReferenceId && tool.credentialScope !== "user" ? await getCredentialReference(dbClient)({
|
|
76
|
-
scopes: {
|
|
77
|
-
tenantId: tool.tenantId,
|
|
78
|
-
projectId: tool.projectId
|
|
79
|
-
},
|
|
80
|
-
id: tool.credentialReferenceId
|
|
81
|
-
}) : userId && tool.credentialScope === "user" ? await getUserScopedCredentialReference(dbClient)({
|
|
82
|
-
scopes: {
|
|
83
|
-
tenantId: tool.tenantId,
|
|
84
|
-
projectId: tool.projectId
|
|
85
|
-
},
|
|
86
|
-
toolId: tool.id,
|
|
87
|
-
userId
|
|
88
|
-
}) : void 0;
|
|
89
93
|
if (credentialReference) {
|
|
90
94
|
const storeReference = {
|
|
91
95
|
credentialStoreId: credentialReference.credentialStoreId,
|
|
92
96
|
retrievalParams: credentialReference.retrievalParams || {}
|
|
93
97
|
};
|
|
94
98
|
if (!credentialStoreRegistry) throw new Error("CredentialStoreRegistry is required for authenticated tools");
|
|
95
|
-
serverConfig = await new CredentialStuffer(credentialStoreRegistry
|
|
99
|
+
serverConfig = await new CredentialStuffer(credentialStoreRegistry).buildMcpServerConfig({
|
|
96
100
|
tenantId: tool.tenantId,
|
|
97
101
|
projectId: tool.projectId
|
|
98
102
|
}, convertToMCPToolConfig(tool), storeReference);
|
|
@@ -109,12 +113,7 @@ const discoverToolsFromServer = async (tool, dbClient, credentialStoreRegistry,
|
|
|
109
113
|
reconnectionOptions: tool.config.mcp.transport?.reconnectionOptions,
|
|
110
114
|
sessionId: tool.config.mcp.transport?.sessionId
|
|
111
115
|
};
|
|
112
|
-
if (serverConfig.url
|
|
113
|
-
const urlObj = new URL(serverConfig.url.toString());
|
|
114
|
-
if (tool.credentialScope === "user" && userId) urlObj.searchParams.set("user_id", userId);
|
|
115
|
-
else urlObj.searchParams.set("user_id", `${tool.tenantId}||${tool.projectId}`);
|
|
116
|
-
serverConfig.url = urlObj.toString();
|
|
117
|
-
}
|
|
116
|
+
if (serverConfig.url) serverConfig.url = buildComposioMCPUrl(serverConfig.url.toString(), tool.tenantId, tool.projectId, tool.credentialScope === "user" ? "user" : "project", userId);
|
|
118
117
|
const client = new McpClient({
|
|
119
118
|
name: tool.name,
|
|
120
119
|
server: serverConfig
|
|
@@ -122,11 +121,15 @@ const discoverToolsFromServer = async (tool, dbClient, credentialStoreRegistry,
|
|
|
122
121
|
await client.connect();
|
|
123
122
|
const serverTools = await client.tools();
|
|
124
123
|
await client.disconnect();
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
const toolOverrides = tool.config.mcp.toolOverrides;
|
|
125
|
+
return Object.entries(serverTools).map(([name, toolDef]) => {
|
|
126
|
+
const schema = extractInputSchema(toolDef, name, toolOverrides);
|
|
127
|
+
return {
|
|
128
|
+
name,
|
|
129
|
+
description: toolDef.description || "",
|
|
130
|
+
inputSchema: schema
|
|
131
|
+
};
|
|
132
|
+
});
|
|
130
133
|
} catch (error) {
|
|
131
134
|
logger.error({
|
|
132
135
|
toolId: tool.id,
|
|
@@ -135,6 +138,27 @@ const discoverToolsFromServer = async (tool, dbClient, credentialStoreRegistry,
|
|
|
135
138
|
throw error;
|
|
136
139
|
}
|
|
137
140
|
};
|
|
141
|
+
/**
|
|
142
|
+
* Convert DB result to McpTool skeleton WITHOUT MCP discovery.
|
|
143
|
+
* This is a fast path that returns status='unknown' and empty availableTools.
|
|
144
|
+
* Use this for list views where you want instant page load.
|
|
145
|
+
*/
|
|
146
|
+
const dbResultToMcpToolSkeleton = (dbResult, relationshipId) => {
|
|
147
|
+
const { headers, capabilities, credentialReferenceId, imageUrl, createdAt, ...rest } = dbResult;
|
|
148
|
+
return {
|
|
149
|
+
...rest,
|
|
150
|
+
status: "unknown",
|
|
151
|
+
availableTools: [],
|
|
152
|
+
capabilities: capabilities || void 0,
|
|
153
|
+
credentialReferenceId: credentialReferenceId || void 0,
|
|
154
|
+
createdAt: toISODateString(createdAt),
|
|
155
|
+
updatedAt: toISODateString(dbResult.updatedAt),
|
|
156
|
+
lastError: dbResult.lastError || null,
|
|
157
|
+
headers: headers || void 0,
|
|
158
|
+
imageUrl: imageUrl || void 0,
|
|
159
|
+
relationshipId
|
|
160
|
+
};
|
|
161
|
+
};
|
|
138
162
|
const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, relationshipId, userId) => {
|
|
139
163
|
const { headers, capabilities, credentialReferenceId, imageUrl, createdAt, ...rest } = dbResult;
|
|
140
164
|
if (dbResult.config.type !== "mcp") return {
|
|
@@ -175,18 +199,23 @@ const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, re
|
|
|
175
199
|
}
|
|
176
200
|
const mcpServerUrl = dbResult.config.mcp.server.url;
|
|
177
201
|
try {
|
|
178
|
-
availableTools = await discoverToolsFromServer(dbResult,
|
|
202
|
+
availableTools = await discoverToolsFromServer(dbResult, credentialReference, credentialStoreRegistry, userId);
|
|
179
203
|
status = "healthy";
|
|
180
204
|
lastErrorComputed = null;
|
|
181
205
|
} catch (error) {
|
|
182
|
-
const toolNeedsAuth = error instanceof Error && await detectAuthenticationRequired({
|
|
183
|
-
serverUrl: mcpServerUrl,
|
|
184
|
-
error,
|
|
185
|
-
logger
|
|
186
|
-
});
|
|
187
|
-
status = toolNeedsAuth ? "needs_auth" : "unhealthy";
|
|
188
206
|
const errorMessage = error instanceof Error ? error.message : "Tool discovery failed";
|
|
189
|
-
|
|
207
|
+
if (isTimeoutOrConnectionError(error)) {
|
|
208
|
+
status = "unavailable";
|
|
209
|
+
lastErrorComputed = `Connection failed - the MCP server may be slow or temporarily unreachable.${error instanceof McpError ? ` (MCP error ${error.code})` : ""} ${errorMessage}`;
|
|
210
|
+
} else {
|
|
211
|
+
const toolNeedsAuth = await detectAuthenticationRequired({
|
|
212
|
+
serverUrl: mcpServerUrl,
|
|
213
|
+
error: error instanceof Error ? error : void 0,
|
|
214
|
+
logger
|
|
215
|
+
});
|
|
216
|
+
status = toolNeedsAuth ? "needs_auth" : "unhealthy";
|
|
217
|
+
lastErrorComputed = toolNeedsAuth ? `Authentication required - OAuth login needed. ${errorMessage}` : errorMessage;
|
|
218
|
+
}
|
|
190
219
|
}
|
|
191
220
|
if (dbResult.config.mcp.server.url.includes("composio.dev")) {
|
|
192
221
|
const credentialScope = dbResult.credentialScope || "project";
|
|
@@ -196,17 +225,25 @@ const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, re
|
|
|
196
225
|
}
|
|
197
226
|
}
|
|
198
227
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
228
|
+
try {
|
|
229
|
+
await updateTool(dbClient)({
|
|
230
|
+
scopes: {
|
|
231
|
+
tenantId: dbResult.tenantId,
|
|
232
|
+
projectId: dbResult.projectId
|
|
233
|
+
},
|
|
234
|
+
toolId: dbResult.id,
|
|
235
|
+
data: {
|
|
236
|
+
updatedAt: now,
|
|
237
|
+
lastError: lastErrorComputed
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
} catch (updateError) {
|
|
241
|
+
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)");
|
|
242
|
+
else logger.warn({
|
|
243
|
+
toolId: dbResult.id,
|
|
244
|
+
error: updateError
|
|
245
|
+
}, "Failed to update tool metadata - continuing with stale data");
|
|
246
|
+
}
|
|
210
247
|
return {
|
|
211
248
|
...rest,
|
|
212
249
|
status,
|
|
@@ -226,6 +263,14 @@ const dbResultToMcpTool = async (dbResult, dbClient, credentialStoreRegistry, re
|
|
|
226
263
|
const getToolById = (db) => async (params) => {
|
|
227
264
|
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
265
|
};
|
|
266
|
+
const getMcpToolById = (db) => async (params) => {
|
|
267
|
+
const tool = await getToolById(db)({
|
|
268
|
+
scopes: params.scopes,
|
|
269
|
+
toolId: params.toolId
|
|
270
|
+
});
|
|
271
|
+
if (!tool) return null;
|
|
272
|
+
return await dbResultToMcpTool(tool, db, params.credentialStoreRegistry, params.relationshipId, params.userId);
|
|
273
|
+
};
|
|
229
274
|
const listTools = (db) => async (params) => {
|
|
230
275
|
const page = params.pagination?.page || 1;
|
|
231
276
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
@@ -329,4 +374,4 @@ const upsertTool = (db) => async (params) => {
|
|
|
329
374
|
};
|
|
330
375
|
|
|
331
376
|
//#endregion
|
|
332
|
-
export { addToolToAgent, createTool, dbResultToMcpTool, deleteTool, getToolById, listTools, removeToolFromAgent, updateTool, upsertSubAgentToolRelation, upsertTool };
|
|
377
|
+
export { addToolToAgent, createTool, dbResultToMcpTool, dbResultToMcpToolSkeleton, deleteTool, getMcpToolById, getToolById, listTools, removeToolFromAgent, updateTool, upsertSubAgentToolRelation, upsertTool };
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
signingSecretCredentialReferenceId: string | null;
|
|
39
|
+
signatureVerification: {
|
|
40
|
+
algorithm: "sha256" | "sha512" | "sha384" | "sha1" | "md5";
|
|
41
|
+
encoding: "hex" | "base64";
|
|
42
|
+
signature: {
|
|
43
|
+
source: "query" | "body" | "header";
|
|
44
|
+
key: string;
|
|
45
|
+
prefix?: string | undefined;
|
|
46
|
+
regex?: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
signedComponents: {
|
|
49
|
+
source: "literal" | "body" | "header";
|
|
50
|
+
required: boolean;
|
|
51
|
+
key?: string | undefined;
|
|
52
|
+
value?: string | undefined;
|
|
53
|
+
regex?: string | undefined;
|
|
54
|
+
}[];
|
|
55
|
+
componentJoin: {
|
|
56
|
+
strategy: "concatenate";
|
|
57
|
+
separator: string;
|
|
58
|
+
};
|
|
59
|
+
validation?: {
|
|
60
|
+
headerCaseSensitive: boolean;
|
|
61
|
+
allowEmptyBody: boolean;
|
|
62
|
+
normalizeUnicode: boolean;
|
|
63
|
+
} | undefined;
|
|
64
|
+
} | null;
|
|
65
|
+
name: string;
|
|
66
|
+
description: string | null;
|
|
67
|
+
agentId: string;
|
|
68
|
+
projectId: string;
|
|
69
|
+
tenantId: string;
|
|
70
|
+
id: string;
|
|
71
|
+
}[];
|
|
72
|
+
pagination: {
|
|
73
|
+
page: number;
|
|
74
|
+
limit: number;
|
|
75
|
+
total: number;
|
|
76
|
+
pages: number;
|
|
77
|
+
};
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Create a new trigger (agent-scoped)
|
|
81
|
+
*/
|
|
82
|
+
declare const createTrigger: (db: AgentsManageDatabaseClient) => (params: TriggerInsert) => Promise<TriggerSelect>;
|
|
83
|
+
/**
|
|
84
|
+
* Update a trigger (agent-scoped)
|
|
85
|
+
*/
|
|
86
|
+
declare const updateTrigger: (db: AgentsManageDatabaseClient) => (params: {
|
|
87
|
+
scopes: AgentScopeConfig;
|
|
88
|
+
triggerId: string;
|
|
89
|
+
data: TriggerUpdate;
|
|
90
|
+
}) => Promise<TriggerSelect>;
|
|
91
|
+
/**
|
|
92
|
+
* Delete a trigger (agent-scoped)
|
|
93
|
+
*/
|
|
94
|
+
declare const deleteTrigger: (db: AgentsManageDatabaseClient) => (params: {
|
|
95
|
+
scopes: AgentScopeConfig;
|
|
96
|
+
triggerId: string;
|
|
97
|
+
}) => Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Upsert a trigger (create or update based on existence)
|
|
100
|
+
*/
|
|
101
|
+
declare const upsertTrigger: (db: AgentsManageDatabaseClient) => (params: {
|
|
102
|
+
scopes: AgentScopeConfig;
|
|
103
|
+
data: TriggerInsert;
|
|
104
|
+
}) => Promise<TriggerSelect>;
|
|
105
|
+
//#endregion
|
|
106
|
+
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,57 +1,57 @@
|
|
|
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<{
|
|
10
|
-
tenantId: string;
|
|
11
|
-
projectId: string;
|
|
12
10
|
id: string;
|
|
13
11
|
name: string | null;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
expiresAt: string | null;
|
|
15
|
+
tenantId: string;
|
|
14
16
|
agentId: string;
|
|
17
|
+
projectId: string;
|
|
15
18
|
publicId: string;
|
|
16
19
|
keyHash: string;
|
|
17
20
|
keyPrefix: string;
|
|
18
21
|
lastUsedAt: string | null;
|
|
19
|
-
expiresAt: string | null;
|
|
20
|
-
createdAt: string;
|
|
21
|
-
updatedAt: string;
|
|
22
22
|
} | undefined>;
|
|
23
|
-
declare const getApiKeyByPublicId: (db:
|
|
24
|
-
tenantId: string;
|
|
25
|
-
projectId: string;
|
|
23
|
+
declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: string) => Promise<{
|
|
26
24
|
id: string;
|
|
27
25
|
name: string | null;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
updatedAt: string;
|
|
28
|
+
expiresAt: string | null;
|
|
29
|
+
tenantId: string;
|
|
28
30
|
agentId: string;
|
|
31
|
+
projectId: string;
|
|
29
32
|
publicId: string;
|
|
30
33
|
keyHash: string;
|
|
31
34
|
keyPrefix: string;
|
|
32
35
|
lastUsedAt: string | null;
|
|
33
|
-
expiresAt: string | null;
|
|
34
|
-
createdAt: string;
|
|
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<{
|
|
41
|
-
tenantId: string;
|
|
42
|
-
projectId: string;
|
|
43
41
|
id: string;
|
|
44
42
|
name: string | null;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
updatedAt: string;
|
|
45
|
+
expiresAt: string | null;
|
|
46
|
+
tenantId: string;
|
|
45
47
|
agentId: string;
|
|
48
|
+
projectId: string;
|
|
46
49
|
publicId: string;
|
|
47
50
|
keyHash: string;
|
|
48
51
|
keyPrefix: string;
|
|
49
52
|
lastUsedAt: string | null;
|
|
50
|
-
expiresAt: string | null;
|
|
51
|
-
createdAt: string;
|
|
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,48 +64,48 @@ declare const listApiKeysPaginated: (db: DatabaseClient) => (params: {
|
|
|
64
64
|
pages: number;
|
|
65
65
|
};
|
|
66
66
|
}>;
|
|
67
|
-
declare const createApiKey: (db:
|
|
68
|
-
tenantId: string;
|
|
69
|
-
projectId: string;
|
|
67
|
+
declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInsert) => Promise<{
|
|
70
68
|
id: string;
|
|
71
69
|
name: string | null;
|
|
70
|
+
createdAt: string;
|
|
71
|
+
updatedAt: string;
|
|
72
|
+
expiresAt: string | null;
|
|
73
|
+
tenantId: string;
|
|
72
74
|
agentId: string;
|
|
75
|
+
projectId: string;
|
|
73
76
|
publicId: string;
|
|
74
77
|
keyHash: string;
|
|
75
78
|
keyPrefix: string;
|
|
76
79
|
lastUsedAt: string | null;
|
|
77
|
-
expiresAt: string | null;
|
|
78
|
-
createdAt: string;
|
|
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
|
};
|