@inkeep/agents-core 0.1.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/LICENSE.md +51 -0
- package/README.md +464 -0
- package/dist/__tests__/integration/helpers.d.ts +5 -0
- package/dist/__tests__/integration/helpers.d.ts.map +1 -0
- package/dist/__tests__/integration/helpers.js +37 -0
- package/dist/__tests__/integration/helpers.js.map +1 -0
- package/dist/__tests__/setup.d.ts +3 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +29 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/client-exports.d.ts +301 -0
- package/dist/client-exports.d.ts.map +1 -0
- package/dist/client-exports.js +251 -0
- package/dist/client-exports.js.map +1 -0
- package/dist/context/ContextConfig.d.ts +55 -0
- package/dist/context/ContextConfig.d.ts.map +1 -0
- package/dist/context/ContextConfig.js +302 -0
- package/dist/context/ContextConfig.js.map +1 -0
- package/dist/context/ContextFetcher.d.ts +64 -0
- package/dist/context/ContextFetcher.d.ts.map +1 -0
- package/dist/context/ContextFetcher.js +325 -0
- package/dist/context/ContextFetcher.js.map +1 -0
- package/dist/context/ContextResolver.d.ts +52 -0
- package/dist/context/ContextResolver.d.ts.map +1 -0
- package/dist/context/ContextResolver.js +298 -0
- package/dist/context/ContextResolver.js.map +1 -0
- package/dist/context/TemplateEngine.d.ts +46 -0
- package/dist/context/TemplateEngine.d.ts.map +1 -0
- package/dist/context/TemplateEngine.js +175 -0
- package/dist/context/TemplateEngine.js.map +1 -0
- package/dist/context/context.d.ts +7 -0
- package/dist/context/context.d.ts.map +1 -0
- package/dist/context/context.js +157 -0
- package/dist/context/context.js.map +1 -0
- package/dist/context/contextCache.d.ts +50 -0
- package/dist/context/contextCache.d.ts.map +1 -0
- package/dist/context/contextCache.js +175 -0
- package/dist/context/contextCache.js.map +1 -0
- package/dist/context/index.d.ts +11 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +8 -0
- package/dist/context/index.js.map +1 -0
- package/dist/credential-stores/index.d.ts +4 -0
- package/dist/credential-stores/index.d.ts.map +1 -0
- package/dist/credential-stores/index.js +4 -0
- package/dist/credential-stores/index.js.map +1 -0
- package/dist/credential-stores/keychain-store.d.ts +100 -0
- package/dist/credential-stores/keychain-store.d.ts.map +1 -0
- package/dist/credential-stores/keychain-store.js +225 -0
- package/dist/credential-stores/keychain-store.js.map +1 -0
- package/dist/credential-stores/memory-store.d.ts +39 -0
- package/dist/credential-stores/memory-store.d.ts.map +1 -0
- package/dist/credential-stores/memory-store.js +58 -0
- package/dist/credential-stores/memory-store.js.map +1 -0
- package/dist/credential-stores/nango-store.d.ts +59 -0
- package/dist/credential-stores/nango-store.d.ts.map +1 -0
- package/dist/credential-stores/nango-store.js +264 -0
- package/dist/credential-stores/nango-store.js.map +1 -0
- package/dist/credential-stuffer/CredentialStuffer.d.ts +80 -0
- package/dist/credential-stuffer/CredentialStuffer.d.ts.map +1 -0
- package/dist/credential-stuffer/CredentialStuffer.js +186 -0
- package/dist/credential-stuffer/CredentialStuffer.js.map +1 -0
- package/dist/credential-stuffer/index.d.ts +2 -0
- package/dist/credential-stuffer/index.d.ts.map +1 -0
- package/dist/credential-stuffer/index.js +2 -0
- package/dist/credential-stuffer/index.js.map +1 -0
- package/dist/data-access/agentDataComponents.d.ts +1 -0
- package/dist/data-access/agentDataComponents.d.ts.map +1 -0
- package/dist/data-access/agentDataComponents.js +2 -0
- package/dist/data-access/agentDataComponents.js.map +1 -0
- package/dist/data-access/agentGraphs.d.ts +406 -0
- package/dist/data-access/agentGraphs.d.ts.map +1 -0
- package/dist/data-access/agentGraphs.js +551 -0
- package/dist/data-access/agentGraphs.js.map +1 -0
- package/dist/data-access/agentRelations.d.ts +456 -0
- package/dist/data-access/agentRelations.d.ts.map +1 -0
- package/dist/data-access/agentRelations.js +471 -0
- package/dist/data-access/agentRelations.js.map +1 -0
- package/dist/data-access/agents.d.ts +218 -0
- package/dist/data-access/agents.d.ts.map +1 -0
- package/dist/data-access/agents.js +130 -0
- package/dist/data-access/agents.js.map +1 -0
- package/dist/data-access/apiKeys.d.ts +114 -0
- package/dist/data-access/apiKeys.d.ts.map +1 -0
- package/dist/data-access/apiKeys.js +185 -0
- package/dist/data-access/apiKeys.js.map +1 -0
- package/dist/data-access/artifactComponents.d.ts +152 -0
- package/dist/data-access/artifactComponents.d.ts.map +1 -0
- package/dist/data-access/artifactComponents.js +214 -0
- package/dist/data-access/artifactComponents.js.map +1 -0
- package/dist/data-access/contextCache.d.ts +68 -0
- package/dist/data-access/contextCache.d.ts.map +1 -0
- package/dist/data-access/contextCache.js +160 -0
- package/dist/data-access/contextCache.js.map +1 -0
- package/dist/data-access/contextConfigs.d.ts +110 -0
- package/dist/data-access/contextConfigs.d.ts.map +1 -0
- package/dist/data-access/contextConfigs.js +156 -0
- package/dist/data-access/contextConfigs.js.map +1 -0
- package/dist/data-access/conversations.d.ts +125 -0
- package/dist/data-access/conversations.d.ts.map +1 -0
- package/dist/data-access/conversations.js +244 -0
- package/dist/data-access/conversations.js.map +1 -0
- package/dist/data-access/credentialReferences.d.ts +86 -0
- package/dist/data-access/credentialReferences.d.ts.map +1 -0
- package/dist/data-access/credentialReferences.js +175 -0
- package/dist/data-access/credentialReferences.js.map +1 -0
- package/dist/data-access/dataComponents.d.ts +129 -0
- package/dist/data-access/dataComponents.d.ts.map +1 -0
- package/dist/data-access/dataComponents.js +213 -0
- package/dist/data-access/dataComponents.js.map +1 -0
- package/dist/data-access/externalAgents.d.ts +83 -0
- package/dist/data-access/externalAgents.d.ts.map +1 -0
- package/dist/data-access/externalAgents.js +163 -0
- package/dist/data-access/externalAgents.js.map +1 -0
- package/dist/data-access/graphFull.d.ts +32 -0
- package/dist/data-access/graphFull.d.ts.map +1 -0
- package/dist/data-access/graphFull.js +995 -0
- package/dist/data-access/graphFull.js.map +1 -0
- package/dist/data-access/index.d.ts +21 -0
- package/dist/data-access/index.d.ts.map +1 -0
- package/dist/data-access/index.js +22 -0
- package/dist/data-access/index.js.map +1 -0
- package/dist/data-access/ledgerArtifacts.d.ts +50 -0
- package/dist/data-access/ledgerArtifacts.d.ts.map +1 -0
- package/dist/data-access/ledgerArtifacts.js +112 -0
- package/dist/data-access/ledgerArtifacts.js.map +1 -0
- package/dist/data-access/messages.d.ts +209 -0
- package/dist/data-access/messages.d.ts.map +1 -0
- package/dist/data-access/messages.js +100 -0
- package/dist/data-access/messages.js.map +1 -0
- package/dist/data-access/projects.d.ts +67 -0
- package/dist/data-access/projects.d.ts.map +1 -0
- package/dist/data-access/projects.js +336 -0
- package/dist/data-access/projects.js.map +1 -0
- package/dist/data-access/tasks.d.ts +37 -0
- package/dist/data-access/tasks.d.ts.map +1 -0
- package/dist/data-access/tasks.js +40 -0
- package/dist/data-access/tasks.js.map +1 -0
- package/dist/data-access/tools.d.ts +277 -0
- package/dist/data-access/tools.d.ts.map +1 -0
- package/dist/data-access/tools.js +183 -0
- package/dist/data-access/tools.js.map +1 -0
- package/dist/data-access/validation.d.ts +17 -0
- package/dist/data-access/validation.d.ts.map +1 -0
- package/dist/data-access/validation.js +52 -0
- package/dist/data-access/validation.js.map +1 -0
- package/dist/db/clean.d.ts +6 -0
- package/dist/db/clean.d.ts.map +1 -0
- package/dist/db/clean.js +81 -0
- package/dist/db/clean.js.map +1 -0
- package/dist/db/client.d.ts +19 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +24 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/schema.d.ts +4337 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +696 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/test-client.d.ts +25 -0
- package/dist/db/test-client.d.ts.map +1 -0
- package/dist/db/test-client.js +136 -0
- package/dist/db/test-client.js.map +1 -0
- package/dist/env.d.ts +17 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +48 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/contextValidation.d.ts +48 -0
- package/dist/middleware/contextValidation.d.ts.map +1 -0
- package/dist/middleware/contextValidation.js +469 -0
- package/dist/middleware/contextValidation.js.map +1 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/server/BaseServer.d.ts +83 -0
- package/dist/server/BaseServer.d.ts.map +1 -0
- package/dist/server/BaseServer.js +218 -0
- package/dist/server/BaseServer.js.map +1 -0
- package/dist/types/a2a.d.ts +373 -0
- package/dist/types/a2a.d.ts.map +1 -0
- package/dist/types/a2a.js +14 -0
- package/dist/types/a2a.js.map +1 -0
- package/dist/types/entities.d.ts +147 -0
- package/dist/types/entities.d.ts.map +1 -0
- package/dist/types/entities.js +2 -0
- package/dist/types/entities.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/server.d.ts +116 -0
- package/dist/types/server.d.ts.map +1 -0
- package/dist/types/server.js +2 -0
- package/dist/types/server.js.map +1 -0
- package/dist/types/utility.d.ts +214 -0
- package/dist/types/utility.d.ts.map +1 -0
- package/dist/types/utility.js +9 -0
- package/dist/types/utility.js.map +1 -0
- package/dist/utils/apiKeys.d.ts +32 -0
- package/dist/utils/apiKeys.d.ts.map +1 -0
- package/dist/utils/apiKeys.js +117 -0
- package/dist/utils/apiKeys.js.map +1 -0
- package/dist/utils/auth-detection.d.ts +23 -0
- package/dist/utils/auth-detection.d.ts.map +1 -0
- package/dist/utils/auth-detection.js +148 -0
- package/dist/utils/auth-detection.js.map +1 -0
- package/dist/utils/credential-store-utils.d.ts +11 -0
- package/dist/utils/credential-store-utils.d.ts.map +1 -0
- package/dist/utils/credential-store-utils.js +19 -0
- package/dist/utils/credential-store-utils.js.map +1 -0
- package/dist/utils/error.d.ts +526 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +282 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/execution.d.ts +18 -0
- package/dist/utils/execution.d.ts.map +1 -0
- package/dist/utils/execution.js +25 -0
- package/dist/utils/execution.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +79 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +102 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/logging.d.ts +11 -0
- package/dist/utils/logging.d.ts.map +1 -0
- package/dist/utils/logging.js +6 -0
- package/dist/utils/logging.js.map +1 -0
- package/dist/utils/mcp-client.d.ts +48 -0
- package/dist/utils/mcp-client.d.ts.map +1 -0
- package/dist/utils/mcp-client.js +171 -0
- package/dist/utils/mcp-client.js.map +1 -0
- package/dist/utils/tracer.d.ts +24 -0
- package/dist/utils/tracer.d.ts.map +1 -0
- package/dist/utils/tracer.js +98 -0
- package/dist/utils/tracer.js.map +1 -0
- package/dist/validation/graphFull.d.ts +36 -0
- package/dist/validation/graphFull.d.ts.map +1 -0
- package/dist/validation/graphFull.js +128 -0
- package/dist/validation/graphFull.js.map +1 -0
- package/dist/validation/id-validation.d.ts +38 -0
- package/dist/validation/id-validation.d.ts.map +1 -0
- package/dist/validation/id-validation.js +60 -0
- package/dist/validation/id-validation.js.map +1 -0
- package/dist/validation/index.d.ts +4 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +5 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/schemas.d.ts +7233 -0
- package/dist/validation/schemas.d.ts.map +1 -0
- package/dist/validation/schemas.js +525 -0
- package/dist/validation/schemas.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import type { DatabaseClient } from '../db/client.js';
|
|
2
|
+
import type { McpTool, McpToolStatus, PaginationConfig, ScopeConfig, ToolInsert, ToolSelect, ToolUpdate } from '../types/index.js';
|
|
3
|
+
export declare const dbResultToMcpTool: (dbResult: ToolSelect) => McpTool;
|
|
4
|
+
export declare const getToolById: (db: DatabaseClient) => (params: {
|
|
5
|
+
scopes: ScopeConfig;
|
|
6
|
+
toolId: string;
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
tenantId: string;
|
|
9
|
+
projectId: string;
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
config: {
|
|
13
|
+
type: "mcp";
|
|
14
|
+
mcp: import("../index.js").ToolMcpConfig;
|
|
15
|
+
};
|
|
16
|
+
credentialReferenceId: string | null;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
status: string;
|
|
20
|
+
headers: Record<string, string> | null;
|
|
21
|
+
imageUrl: string | null;
|
|
22
|
+
capabilities: import("../index.js").ToolServerCapabilities | null;
|
|
23
|
+
lastHealthCheck: string | null;
|
|
24
|
+
lastError: string | null;
|
|
25
|
+
availableTools: import("../index.js").McpToolDefinition[] | null;
|
|
26
|
+
lastToolsSync: string | null;
|
|
27
|
+
} | null>;
|
|
28
|
+
export declare const listTools: (db: DatabaseClient) => (params: {
|
|
29
|
+
scopes: ScopeConfig;
|
|
30
|
+
pagination?: PaginationConfig;
|
|
31
|
+
}) => Promise<{
|
|
32
|
+
data: {
|
|
33
|
+
tenantId: string;
|
|
34
|
+
projectId: string;
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
config: {
|
|
38
|
+
type: "mcp";
|
|
39
|
+
mcp: import("../index.js").ToolMcpConfig;
|
|
40
|
+
};
|
|
41
|
+
credentialReferenceId: string | null;
|
|
42
|
+
headers: Record<string, string> | null;
|
|
43
|
+
imageUrl: string | null;
|
|
44
|
+
capabilities: import("../index.js").ToolServerCapabilities | null;
|
|
45
|
+
status: string;
|
|
46
|
+
lastHealthCheck: string | null;
|
|
47
|
+
lastError: string | null;
|
|
48
|
+
availableTools: import("../index.js").McpToolDefinition[] | null;
|
|
49
|
+
lastToolsSync: string | null;
|
|
50
|
+
createdAt: string;
|
|
51
|
+
updatedAt: string;
|
|
52
|
+
}[];
|
|
53
|
+
pagination: {
|
|
54
|
+
page: number;
|
|
55
|
+
limit: number;
|
|
56
|
+
total: number;
|
|
57
|
+
pages: number;
|
|
58
|
+
};
|
|
59
|
+
}>;
|
|
60
|
+
export declare const getToolsByStatus: (db: DatabaseClient) => (params: {
|
|
61
|
+
scopes: ScopeConfig;
|
|
62
|
+
status: string;
|
|
63
|
+
}) => Promise<{
|
|
64
|
+
tenantId: string;
|
|
65
|
+
projectId: string;
|
|
66
|
+
id: string;
|
|
67
|
+
name: string;
|
|
68
|
+
config: {
|
|
69
|
+
type: "mcp";
|
|
70
|
+
mcp: import("../index.js").ToolMcpConfig;
|
|
71
|
+
};
|
|
72
|
+
credentialReferenceId: string | null;
|
|
73
|
+
headers: Record<string, string> | null;
|
|
74
|
+
imageUrl: string | null;
|
|
75
|
+
capabilities: import("../index.js").ToolServerCapabilities | null;
|
|
76
|
+
status: string;
|
|
77
|
+
lastHealthCheck: string | null;
|
|
78
|
+
lastError: string | null;
|
|
79
|
+
availableTools: import("../index.js").McpToolDefinition[] | null;
|
|
80
|
+
lastToolsSync: string | null;
|
|
81
|
+
createdAt: string;
|
|
82
|
+
updatedAt: string;
|
|
83
|
+
}[]>;
|
|
84
|
+
export declare const listToolsByStatus: (db: DatabaseClient) => (params: {
|
|
85
|
+
scopes: ScopeConfig;
|
|
86
|
+
status: McpToolStatus;
|
|
87
|
+
}) => Promise<{
|
|
88
|
+
tenantId: string;
|
|
89
|
+
projectId: string;
|
|
90
|
+
id: string;
|
|
91
|
+
name: string;
|
|
92
|
+
config: {
|
|
93
|
+
type: "mcp";
|
|
94
|
+
mcp: import("../index.js").ToolMcpConfig;
|
|
95
|
+
};
|
|
96
|
+
credentialReferenceId: string | null;
|
|
97
|
+
createdAt: string;
|
|
98
|
+
updatedAt: string;
|
|
99
|
+
status: string;
|
|
100
|
+
headers: Record<string, string> | null;
|
|
101
|
+
imageUrl: string | null;
|
|
102
|
+
capabilities: import("../index.js").ToolServerCapabilities | null;
|
|
103
|
+
lastHealthCheck: string | null;
|
|
104
|
+
lastError: string | null;
|
|
105
|
+
availableTools: import("../index.js").McpToolDefinition[] | null;
|
|
106
|
+
lastToolsSync: string | null;
|
|
107
|
+
}[]>;
|
|
108
|
+
export declare const createTool: (db: DatabaseClient) => (params: ToolInsert) => Promise<{
|
|
109
|
+
tenantId: string;
|
|
110
|
+
projectId: string;
|
|
111
|
+
id: string;
|
|
112
|
+
name: string;
|
|
113
|
+
config: {
|
|
114
|
+
type: "mcp";
|
|
115
|
+
mcp: import("../index.js").ToolMcpConfig;
|
|
116
|
+
};
|
|
117
|
+
credentialReferenceId: string | null;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
updatedAt: string;
|
|
120
|
+
status: string;
|
|
121
|
+
headers: Record<string, string> | null;
|
|
122
|
+
imageUrl: string | null;
|
|
123
|
+
capabilities: import("../index.js").ToolServerCapabilities | null;
|
|
124
|
+
lastHealthCheck: string | null;
|
|
125
|
+
lastError: string | null;
|
|
126
|
+
availableTools: import("../index.js").McpToolDefinition[] | null;
|
|
127
|
+
lastToolsSync: string | null;
|
|
128
|
+
}>;
|
|
129
|
+
export declare const updateTool: (db: DatabaseClient) => (params: {
|
|
130
|
+
scopes: ScopeConfig;
|
|
131
|
+
toolId: string;
|
|
132
|
+
data: ToolUpdate;
|
|
133
|
+
}) => Promise<{
|
|
134
|
+
tenantId: string;
|
|
135
|
+
projectId: string;
|
|
136
|
+
id: string;
|
|
137
|
+
name: string;
|
|
138
|
+
config: {
|
|
139
|
+
type: "mcp";
|
|
140
|
+
mcp: import("../index.js").ToolMcpConfig;
|
|
141
|
+
};
|
|
142
|
+
credentialReferenceId: string | null;
|
|
143
|
+
createdAt: string;
|
|
144
|
+
updatedAt: string;
|
|
145
|
+
status: string;
|
|
146
|
+
headers: Record<string, string> | null;
|
|
147
|
+
imageUrl: string | null;
|
|
148
|
+
capabilities: import("../index.js").ToolServerCapabilities | null;
|
|
149
|
+
lastHealthCheck: string | null;
|
|
150
|
+
lastError: string | null;
|
|
151
|
+
availableTools: import("../index.js").McpToolDefinition[] | null;
|
|
152
|
+
lastToolsSync: string | null;
|
|
153
|
+
}>;
|
|
154
|
+
export declare const deleteTool: (db: DatabaseClient) => (params: {
|
|
155
|
+
scopes: ScopeConfig;
|
|
156
|
+
toolId: string;
|
|
157
|
+
}) => Promise<boolean>;
|
|
158
|
+
export declare const addToolToAgent: (db: DatabaseClient) => (params: {
|
|
159
|
+
scopes: ScopeConfig;
|
|
160
|
+
agentId: string;
|
|
161
|
+
toolId: string;
|
|
162
|
+
}) => Promise<{
|
|
163
|
+
tenantId: string;
|
|
164
|
+
projectId: string;
|
|
165
|
+
id: string;
|
|
166
|
+
createdAt: string;
|
|
167
|
+
updatedAt: string;
|
|
168
|
+
agentId: string;
|
|
169
|
+
toolId: string;
|
|
170
|
+
}>;
|
|
171
|
+
export declare const removeToolFromAgent: (db: DatabaseClient) => (params: {
|
|
172
|
+
scopes: ScopeConfig;
|
|
173
|
+
agentId: string;
|
|
174
|
+
toolId: string;
|
|
175
|
+
}) => Promise<{
|
|
176
|
+
tenantId: string;
|
|
177
|
+
projectId: string;
|
|
178
|
+
id: string;
|
|
179
|
+
createdAt: string;
|
|
180
|
+
updatedAt: string;
|
|
181
|
+
agentId: string;
|
|
182
|
+
toolId: string;
|
|
183
|
+
}>;
|
|
184
|
+
/**
|
|
185
|
+
* Upsert agent-tool relation (create if it doesn't exist, no-op if it does)
|
|
186
|
+
*/
|
|
187
|
+
export declare const upsertAgentToolRelation: (db: DatabaseClient) => (params: {
|
|
188
|
+
scopes: ScopeConfig;
|
|
189
|
+
agentId: string;
|
|
190
|
+
toolId: string;
|
|
191
|
+
}) => Promise<{
|
|
192
|
+
tenantId: string;
|
|
193
|
+
projectId: string;
|
|
194
|
+
id: string;
|
|
195
|
+
createdAt: string;
|
|
196
|
+
updatedAt: string;
|
|
197
|
+
agentId: string;
|
|
198
|
+
toolId: string;
|
|
199
|
+
}>;
|
|
200
|
+
export declare const updateToolStatus: (db: DatabaseClient) => (params: {
|
|
201
|
+
scopes: ScopeConfig;
|
|
202
|
+
toolId: string;
|
|
203
|
+
status: string;
|
|
204
|
+
lastHealthCheck?: string;
|
|
205
|
+
lastError?: string;
|
|
206
|
+
}) => Promise<{
|
|
207
|
+
tenantId: string;
|
|
208
|
+
projectId: string;
|
|
209
|
+
id: string;
|
|
210
|
+
name: string;
|
|
211
|
+
config: {
|
|
212
|
+
type: "mcp";
|
|
213
|
+
mcp: import("../index.js").ToolMcpConfig;
|
|
214
|
+
};
|
|
215
|
+
credentialReferenceId: string | null;
|
|
216
|
+
createdAt: string;
|
|
217
|
+
updatedAt: string;
|
|
218
|
+
status: string;
|
|
219
|
+
headers: Record<string, string> | null;
|
|
220
|
+
imageUrl: string | null;
|
|
221
|
+
capabilities: import("../index.js").ToolServerCapabilities | null;
|
|
222
|
+
lastHealthCheck: string | null;
|
|
223
|
+
lastError: string | null;
|
|
224
|
+
availableTools: import("../index.js").McpToolDefinition[] | null;
|
|
225
|
+
lastToolsSync: string | null;
|
|
226
|
+
}>;
|
|
227
|
+
/**
|
|
228
|
+
* Upsert a tool (create if it doesn't exist, update if it does)
|
|
229
|
+
*/
|
|
230
|
+
export declare const upsertTool: (db: DatabaseClient) => (params: {
|
|
231
|
+
data: ToolInsert;
|
|
232
|
+
}) => Promise<{
|
|
233
|
+
tenantId: string;
|
|
234
|
+
projectId: string;
|
|
235
|
+
id: string;
|
|
236
|
+
name: string;
|
|
237
|
+
config: {
|
|
238
|
+
type: "mcp";
|
|
239
|
+
mcp: import("../index.js").ToolMcpConfig;
|
|
240
|
+
};
|
|
241
|
+
credentialReferenceId: string | null;
|
|
242
|
+
createdAt: string;
|
|
243
|
+
updatedAt: string;
|
|
244
|
+
status: string;
|
|
245
|
+
headers: Record<string, string> | null;
|
|
246
|
+
imageUrl: string | null;
|
|
247
|
+
capabilities: import("../index.js").ToolServerCapabilities | null;
|
|
248
|
+
lastHealthCheck: string | null;
|
|
249
|
+
lastError: string | null;
|
|
250
|
+
availableTools: import("../index.js").McpToolDefinition[] | null;
|
|
251
|
+
lastToolsSync: string | null;
|
|
252
|
+
}>;
|
|
253
|
+
export declare const getHealthyToolsForAgent: (db: DatabaseClient) => (params: {
|
|
254
|
+
scopes: ScopeConfig;
|
|
255
|
+
agentId: string;
|
|
256
|
+
}) => Promise<{
|
|
257
|
+
tenantId: string;
|
|
258
|
+
projectId: string;
|
|
259
|
+
id: string;
|
|
260
|
+
name: string;
|
|
261
|
+
config: {
|
|
262
|
+
type: "mcp";
|
|
263
|
+
mcp: import("../index.js").ToolMcpConfig;
|
|
264
|
+
};
|
|
265
|
+
credentialReferenceId: string | null;
|
|
266
|
+
headers: Record<string, string> | null;
|
|
267
|
+
imageUrl: string | null;
|
|
268
|
+
capabilities: import("../index.js").ToolServerCapabilities | null;
|
|
269
|
+
status: string;
|
|
270
|
+
lastHealthCheck: string | null;
|
|
271
|
+
lastError: string | null;
|
|
272
|
+
availableTools: import("../index.js").McpToolDefinition[] | null;
|
|
273
|
+
lastToolsSync: string | null;
|
|
274
|
+
createdAt: string;
|
|
275
|
+
updatedAt: string;
|
|
276
|
+
}[]>;
|
|
277
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/data-access/tools.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,mBAAmB,CAAC;AAG3B,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AAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;;;;;;;;EAkBtE,CAAC;AAEJ,eAAO,MAAM,mBAAmB,GAC7B,IAAI,cAAc,MACZ,QAAQ;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;;;;;;;;EActE,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,uBAAuB,GACjC,IAAI,cAAc,MACZ,QAAQ;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;;;;;;;;EAkBtE,CAAC;AAEJ,eAAO,MAAM,gBAAgB,GAC1B,IAAI,cAAc,MACZ,QAAQ;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;;;;;;;;;;;;;;;;;;;EAUA,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,IAAI,cAAc,MAAY,QAAQ;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;EAyBpF,CAAC;AAGF,eAAO,MAAM,uBAAuB,GACjC,IAAI,cAAc,MAAY,QAAQ;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;IAiB9E,CAAC"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { and, count, desc, eq } from 'drizzle-orm';
|
|
2
|
+
import { nanoid } from 'nanoid';
|
|
3
|
+
import { agentToolRelations, tools } from '../db/schema.js';
|
|
4
|
+
// Helper function to convert database result to McpTool
|
|
5
|
+
export const dbResultToMcpTool = (dbResult) => {
|
|
6
|
+
const { headers, capabilities, credentialReferenceId, lastError, availableTools, imageUrl, lastHealthCheck, lastToolsSync, createdAt, updatedAt, ...rest } = dbResult;
|
|
7
|
+
return {
|
|
8
|
+
...rest,
|
|
9
|
+
status: dbResult.status,
|
|
10
|
+
capabilities: capabilities || undefined,
|
|
11
|
+
credentialReferenceId: credentialReferenceId || undefined,
|
|
12
|
+
lastHealthCheck: lastHealthCheck ? new Date(lastHealthCheck) : undefined,
|
|
13
|
+
lastToolsSync: lastToolsSync ? new Date(lastToolsSync) : undefined,
|
|
14
|
+
createdAt: new Date(createdAt),
|
|
15
|
+
updatedAt: new Date(updatedAt),
|
|
16
|
+
lastError: lastError || undefined,
|
|
17
|
+
availableTools: availableTools || undefined,
|
|
18
|
+
headers: headers || undefined,
|
|
19
|
+
imageUrl: imageUrl || undefined,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export const getToolById = (db) => async (params) => {
|
|
23
|
+
const result = await db.query.tools.findFirst({
|
|
24
|
+
where: and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.projectId, params.scopes.projectId), eq(tools.id, params.toolId)),
|
|
25
|
+
});
|
|
26
|
+
return result ?? null;
|
|
27
|
+
};
|
|
28
|
+
export const listTools = (db) => async (params) => {
|
|
29
|
+
const page = params.pagination?.page || 1;
|
|
30
|
+
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
31
|
+
const offset = (page - 1) * limit;
|
|
32
|
+
const whereClause = and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.projectId, params.scopes.projectId));
|
|
33
|
+
const [query, totalResult] = await Promise.all([
|
|
34
|
+
db
|
|
35
|
+
.select()
|
|
36
|
+
.from(tools)
|
|
37
|
+
.where(whereClause)
|
|
38
|
+
.limit(limit)
|
|
39
|
+
.offset(offset)
|
|
40
|
+
.orderBy(desc(tools.createdAt)),
|
|
41
|
+
db.select({ count: count() }).from(tools).where(whereClause),
|
|
42
|
+
]);
|
|
43
|
+
const total = totalResult[0]?.count || 0;
|
|
44
|
+
const pages = Math.ceil(total / limit);
|
|
45
|
+
return {
|
|
46
|
+
data: query,
|
|
47
|
+
pagination: { page, limit, total, pages },
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export const getToolsByStatus = (db) => async (params) => {
|
|
51
|
+
return db
|
|
52
|
+
.select()
|
|
53
|
+
.from(tools)
|
|
54
|
+
.where(and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.projectId, params.scopes.projectId), eq(tools.status, params.status)));
|
|
55
|
+
};
|
|
56
|
+
export const listToolsByStatus = (db) => async (params) => {
|
|
57
|
+
const toolsList = await db.query.tools.findMany({
|
|
58
|
+
where: and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.status, params.status), eq(tools.projectId, params.scopes.projectId)),
|
|
59
|
+
orderBy: desc(tools.createdAt),
|
|
60
|
+
});
|
|
61
|
+
return toolsList;
|
|
62
|
+
};
|
|
63
|
+
export const createTool = (db) => async (params) => {
|
|
64
|
+
const now = new Date().toISOString();
|
|
65
|
+
const [created] = await db
|
|
66
|
+
.insert(tools)
|
|
67
|
+
.values({
|
|
68
|
+
...params,
|
|
69
|
+
createdAt: now,
|
|
70
|
+
updatedAt: now,
|
|
71
|
+
})
|
|
72
|
+
.returning();
|
|
73
|
+
return created;
|
|
74
|
+
};
|
|
75
|
+
export const updateTool = (db) => async (params) => {
|
|
76
|
+
const now = new Date().toISOString();
|
|
77
|
+
const [updated] = await db
|
|
78
|
+
.update(tools)
|
|
79
|
+
.set({
|
|
80
|
+
...params.data,
|
|
81
|
+
updatedAt: now,
|
|
82
|
+
})
|
|
83
|
+
.where(and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.projectId, params.scopes.projectId), eq(tools.id, params.toolId)))
|
|
84
|
+
.returning();
|
|
85
|
+
return updated ?? null;
|
|
86
|
+
};
|
|
87
|
+
export const deleteTool = (db) => async (params) => {
|
|
88
|
+
const [deleted] = await db
|
|
89
|
+
.delete(tools)
|
|
90
|
+
.where(and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.projectId, params.scopes.projectId), eq(tools.id, params.toolId)))
|
|
91
|
+
.returning();
|
|
92
|
+
return deleted ? true : false;
|
|
93
|
+
};
|
|
94
|
+
export const addToolToAgent = (db) => async (params) => {
|
|
95
|
+
const id = nanoid();
|
|
96
|
+
const now = new Date().toISOString();
|
|
97
|
+
const [created] = await db
|
|
98
|
+
.insert(agentToolRelations)
|
|
99
|
+
.values({
|
|
100
|
+
id,
|
|
101
|
+
tenantId: params.scopes.tenantId,
|
|
102
|
+
projectId: params.scopes.projectId,
|
|
103
|
+
agentId: params.agentId,
|
|
104
|
+
toolId: params.toolId,
|
|
105
|
+
createdAt: now,
|
|
106
|
+
updatedAt: now,
|
|
107
|
+
})
|
|
108
|
+
.returning();
|
|
109
|
+
return created;
|
|
110
|
+
};
|
|
111
|
+
export const removeToolFromAgent = (db) => async (params) => {
|
|
112
|
+
const [deleted] = await db
|
|
113
|
+
.delete(agentToolRelations)
|
|
114
|
+
.where(and(eq(agentToolRelations.tenantId, params.scopes.tenantId), eq(agentToolRelations.projectId, params.scopes.projectId), eq(agentToolRelations.agentId, params.agentId), eq(agentToolRelations.toolId, params.toolId)))
|
|
115
|
+
.returning();
|
|
116
|
+
return deleted;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Upsert agent-tool relation (create if it doesn't exist, no-op if it does)
|
|
120
|
+
*/
|
|
121
|
+
export const upsertAgentToolRelation = (db) => async (params) => {
|
|
122
|
+
// Check if relation already exists
|
|
123
|
+
const existing = await db.query.agentToolRelations.findFirst({
|
|
124
|
+
where: and(eq(agentToolRelations.tenantId, params.scopes.tenantId), eq(agentToolRelations.projectId, params.scopes.projectId), eq(agentToolRelations.agentId, params.agentId), eq(agentToolRelations.toolId, params.toolId)),
|
|
125
|
+
});
|
|
126
|
+
if (!existing) {
|
|
127
|
+
// Create the relation if it doesn't exist
|
|
128
|
+
return await addToolToAgent(db)(params);
|
|
129
|
+
}
|
|
130
|
+
// Return existing relation if it already exists
|
|
131
|
+
return existing;
|
|
132
|
+
};
|
|
133
|
+
export const updateToolStatus = (db) => async (params) => {
|
|
134
|
+
return updateTool(db)({
|
|
135
|
+
scopes: params.scopes,
|
|
136
|
+
toolId: params.toolId,
|
|
137
|
+
data: {
|
|
138
|
+
status: params.status,
|
|
139
|
+
lastHealthCheck: params.lastHealthCheck || new Date().toISOString(),
|
|
140
|
+
lastError: params.lastError,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Upsert a tool (create if it doesn't exist, update if it does)
|
|
146
|
+
*/
|
|
147
|
+
export const upsertTool = (db) => async (params) => {
|
|
148
|
+
const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId };
|
|
149
|
+
const existing = await getToolById(db)({
|
|
150
|
+
scopes,
|
|
151
|
+
toolId: params.data.id,
|
|
152
|
+
});
|
|
153
|
+
if (existing) {
|
|
154
|
+
// Update existing tool
|
|
155
|
+
return await updateTool(db)({
|
|
156
|
+
scopes,
|
|
157
|
+
toolId: params.data.id,
|
|
158
|
+
data: {
|
|
159
|
+
name: params.data.name,
|
|
160
|
+
config: params.data.config,
|
|
161
|
+
credentialReferenceId: params.data.credentialReferenceId,
|
|
162
|
+
imageUrl: params.data.imageUrl,
|
|
163
|
+
headers: params.data.headers,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// Create new tool
|
|
169
|
+
return await createTool(db)(params.data);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
// Get healthy tools for agent execution
|
|
173
|
+
export const getHealthyToolsForAgent = (db) => async (params) => {
|
|
174
|
+
const healthyTools = await db
|
|
175
|
+
.select({
|
|
176
|
+
tool: tools,
|
|
177
|
+
})
|
|
178
|
+
.from(tools)
|
|
179
|
+
.innerJoin(agentToolRelations, and(eq(tools.id, agentToolRelations.toolId), eq(agentToolRelations.agentId, params.agentId), eq(agentToolRelations.tenantId, params.scopes.tenantId)))
|
|
180
|
+
.where(and(eq(tools.tenantId, params.scopes.tenantId), eq(tools.status, 'healthy')));
|
|
181
|
+
return healthyTools.map((row) => row.tool);
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/data-access/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAW5D,wDAAwD;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAoB,EAAW,EAAE;IACjE,MAAM,EACJ,OAAO,EACP,YAAY,EACZ,qBAAqB,EACrB,SAAS,EACT,cAAc,EACd,QAAQ,EACR,eAAe,EACf,aAAa,EACb,SAAS,EACT,SAAS,EACT,GAAG,IAAI,EACR,GAAG,QAAQ,CAAC;IACb,OAAO;QACL,GAAG,IAAI;QACP,MAAM,EAAE,QAAQ,CAAC,MAAuB;QACxC,YAAY,EAAE,YAAY,IAAI,SAAS;QACvC,qBAAqB,EAAE,qBAAqB,IAAI,SAAS;QACzD,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS;QACxE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS;QAClE,SAAS,EAAE,IAAI,IAAI,CAAC,SAAS,CAAC;QAC9B,SAAS,EAAE,IAAI,IAAI,CAAC,SAAS,CAAC;QAC9B,SAAS,EAAE,SAAS,IAAI,SAAS;QACjC,cAAc,EAAE,cAAc,IAAI,SAAS;QAC3C,OAA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C,IAAI,CAAC,CAAC;AAC7C,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DatabaseClient } from '../db/client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a project exists before performing database operations
|
|
4
|
+
* This provides runtime validation even when foreign key constraints are not enforced
|
|
5
|
+
*/
|
|
6
|
+
export declare const validateProjectExists: (db: DatabaseClient, tenantId: string, projectId: string) => Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a database operation with project validation
|
|
9
|
+
* Ensures the project exists before executing the operation
|
|
10
|
+
*/
|
|
11
|
+
export declare const withProjectValidation: <T extends (...args: any[]) => Promise<any>>(db: DatabaseClient, operation: T) => (params: Parameters<T>[0]) => Promise<ReturnType<T>>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a validated version of data access functions
|
|
14
|
+
* Automatically adds project validation to insert/update operations
|
|
15
|
+
*/
|
|
16
|
+
export declare const createValidatedDataAccess: <T extends Record<string, any>>(db: DatabaseClient, dataAccessFunctions: T) => T;
|
|
17
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/data-access/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAChC,IAAI,cAAc,EAClB,UAAU,MAAM,EAChB,WAAW,MAAM,KAChB,OAAO,CAAC,IAAI,CAWd,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAC9E,IAAI,cAAc,EAClB,WAAW,CAAC,MAEE,QAAQ,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAW/D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrE,IAAI,cAAc,EAClB,qBAAqB,CAAC,KACrB,CAiBF,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { projectExistsInTable } from './projects.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a project exists before performing database operations
|
|
4
|
+
* This provides runtime validation even when foreign key constraints are not enforced
|
|
5
|
+
*/
|
|
6
|
+
export const validateProjectExists = async (db, tenantId, projectId) => {
|
|
7
|
+
const exists = await projectExistsInTable(db)({
|
|
8
|
+
scopes: { tenantId, projectId }
|
|
9
|
+
});
|
|
10
|
+
if (!exists) {
|
|
11
|
+
throw new Error(`Project with ID "${projectId}" does not exist for tenant "${tenantId}". ` +
|
|
12
|
+
`Please create the project first before adding resources to it.`);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Wraps a database operation with project validation
|
|
17
|
+
* Ensures the project exists before executing the operation
|
|
18
|
+
*/
|
|
19
|
+
export const withProjectValidation = (db, operation) => {
|
|
20
|
+
return async (params) => {
|
|
21
|
+
// Extract tenantId and projectId from params
|
|
22
|
+
const tenantId = params.tenantId || params.scopes?.tenantId;
|
|
23
|
+
const projectId = params.projectId || params.scopes?.projectId;
|
|
24
|
+
if (tenantId && projectId) {
|
|
25
|
+
await validateProjectExists(db, tenantId, projectId);
|
|
26
|
+
}
|
|
27
|
+
return operation(params);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Creates a validated version of data access functions
|
|
32
|
+
* Automatically adds project validation to insert/update operations
|
|
33
|
+
*/
|
|
34
|
+
export const createValidatedDataAccess = (db, dataAccessFunctions) => {
|
|
35
|
+
const validated = {};
|
|
36
|
+
for (const [key, fn] of Object.entries(dataAccessFunctions)) {
|
|
37
|
+
if (typeof fn === 'function') {
|
|
38
|
+
// Add validation to create/insert/update operations
|
|
39
|
+
if (key.startsWith('create') || key.startsWith('insert') || key.startsWith('update')) {
|
|
40
|
+
validated[key] = withProjectValidation(db, fn);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
validated[key] = fn;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
validated[key] = fn;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return validated;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/data-access/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EACxC,EAAkB,EAClB,QAAgB,EAChB,SAAiB,EACF,EAAE;IACjB,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,EAAE,CAAC,CAAC;QAC5C,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE;KAChC,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,oBAAoB,SAAS,gCAAgC,QAAQ,KAAK;YAC1E,gEAAgE,CACjE,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,EAAkB,EAClB,SAAY,EACZ,EAAE;IACF,OAAO,KAAK,EAAE,MAAwB,EAA0B,EAAE;QAChE,6CAA6C;QAC7C,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC;QAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;QAE/D,IAAI,QAAQ,IAAI,SAAS,EAAE,CAAC;YAC1B,MAAM,qBAAqB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,EAAkB,EAClB,mBAAsB,EACnB,EAAE;IACL,MAAM,SAAS,GAAG,EAAO,CAAC;IAE1B,KAAK,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC5D,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;YAC7B,oDAAoD;YACpD,IAAI,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACrF,SAAS,CAAC,GAAc,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE,EAAE,CAAe,CAAC;YAC1E,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,GAAc,CAAC,GAAG,EAAE,CAAC;YACjC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,GAAc,CAAC,GAAG,EAAE,CAAC;QACjC,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/db/clean.ts"],"names":[],"mappings":"AA4BA;;;GAGG;AACH,wBAAsB,aAAa,kBA6DlC"}
|
package/dist/db/clean.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { env } from '../env.js';
|
|
3
|
+
import { agentArtifactComponents, agentDataComponents, agentGraph, agentRelations, agents, agentToolRelations, artifactComponents, contextCache, contextConfigs, conversations, credentialReferences, dataComponents, externalAgents, ledgerArtifacts, messages, taskRelations, tasks, tools, } from '@inkeep/agents-core';
|
|
4
|
+
import { createDatabaseClient } from './client.js';
|
|
5
|
+
const dbClient = createDatabaseClient({
|
|
6
|
+
url: env.DB_FILE_NAME,
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* Truncates all tables in the database, respecting foreign key constraints
|
|
10
|
+
* Tables are cleared in dependency order (child tables first, then parent tables)
|
|
11
|
+
*/
|
|
12
|
+
export async function cleanDatabase() {
|
|
13
|
+
console.log(`🗑️ Cleaning database for environment: ${env.ENVIRONMENT}`);
|
|
14
|
+
console.log(`📁 Using database: ${env.DB_FILE_NAME}`);
|
|
15
|
+
console.log('---');
|
|
16
|
+
try {
|
|
17
|
+
// Disable foreign key constraints temporarily to make cleanup easier
|
|
18
|
+
await dbClient.run(sql `PRAGMA foreign_keys = OFF`);
|
|
19
|
+
// Order matters: clear dependent tables first
|
|
20
|
+
const tablesToClear = [
|
|
21
|
+
{ table: messages, name: 'messages' },
|
|
22
|
+
{ table: conversations, name: 'conversations' },
|
|
23
|
+
{ table: taskRelations, name: 'task_relations' },
|
|
24
|
+
{ table: tasks, name: 'tasks' },
|
|
25
|
+
{ table: agentArtifactComponents, name: 'agent_artifact_components' },
|
|
26
|
+
{ table: agentDataComponents, name: 'agent_data_components' },
|
|
27
|
+
{ table: agentToolRelations, name: 'agent_tool_relations' },
|
|
28
|
+
{ table: agentRelations, name: 'agent_relations' },
|
|
29
|
+
{ table: agentGraph, name: 'agent_graph' },
|
|
30
|
+
{ table: artifactComponents, name: 'artifact_components' },
|
|
31
|
+
{ table: dataComponents, name: 'data_components' },
|
|
32
|
+
{ table: tools, name: 'tools' },
|
|
33
|
+
{ table: agents, name: 'agents' },
|
|
34
|
+
{ table: externalAgents, name: 'external_agents' },
|
|
35
|
+
{ table: ledgerArtifacts, name: 'ledger_artifacts' },
|
|
36
|
+
{ table: credentialReferences, name: 'credential_references' },
|
|
37
|
+
{ table: contextConfigs, name: 'context_configs' },
|
|
38
|
+
{ table: contextCache, name: 'context_cache' },
|
|
39
|
+
];
|
|
40
|
+
for (const { table, name } of tablesToClear) {
|
|
41
|
+
try {
|
|
42
|
+
await dbClient.delete(table).run();
|
|
43
|
+
console.log(`✅ Cleared table: ${name}`);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
// Handle case where table doesn't exist
|
|
47
|
+
const errorMessage = error?.message || '';
|
|
48
|
+
const causeMessage = error?.cause?.message || '';
|
|
49
|
+
if (errorMessage.includes('no such table') ||
|
|
50
|
+
causeMessage.includes('no such table') ||
|
|
51
|
+
(error?.cause?.code === 'SQLITE_ERROR' && causeMessage.includes('no such table'))) {
|
|
52
|
+
console.log(`⚠️ Table ${name} doesn't exist, skipping`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Re-enable foreign key constraints
|
|
60
|
+
await dbClient.run(sql `PRAGMA foreign_keys = ON`);
|
|
61
|
+
console.log('---');
|
|
62
|
+
console.log('🎉 Database cleaned successfully');
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('❌ Failed to clean database:', error);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Run the clean function if executed directly
|
|
70
|
+
if (import.meta.url === new URL(import.meta.url).href) {
|
|
71
|
+
cleanDatabase()
|
|
72
|
+
.then(() => {
|
|
73
|
+
console.log('Database cleanup completed');
|
|
74
|
+
process.exit(0);
|
|
75
|
+
})
|
|
76
|
+
.catch((error) => {
|
|
77
|
+
console.error('Database cleanup failed:', error);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=clean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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