@inkeep/agents-core 0.0.0-dev-20250910233133

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.
Files changed (263) hide show
  1. package/LICENSE.md +56 -0
  2. package/README.md +464 -0
  3. package/dist/__tests__/integration/helpers.d.ts +5 -0
  4. package/dist/__tests__/integration/helpers.d.ts.map +1 -0
  5. package/dist/__tests__/integration/helpers.js +37 -0
  6. package/dist/__tests__/integration/helpers.js.map +1 -0
  7. package/dist/__tests__/setup.d.ts +3 -0
  8. package/dist/__tests__/setup.d.ts.map +1 -0
  9. package/dist/__tests__/setup.js +29 -0
  10. package/dist/__tests__/setup.js.map +1 -0
  11. package/dist/client-exports.d.ts +299 -0
  12. package/dist/client-exports.d.ts.map +1 -0
  13. package/dist/client-exports.js +252 -0
  14. package/dist/client-exports.js.map +1 -0
  15. package/dist/context/ContextConfig.d.ts +54 -0
  16. package/dist/context/ContextConfig.d.ts.map +1 -0
  17. package/dist/context/ContextConfig.js +302 -0
  18. package/dist/context/ContextConfig.js.map +1 -0
  19. package/dist/context/ContextFetcher.d.ts +64 -0
  20. package/dist/context/ContextFetcher.d.ts.map +1 -0
  21. package/dist/context/ContextFetcher.js +325 -0
  22. package/dist/context/ContextFetcher.js.map +1 -0
  23. package/dist/context/ContextResolver.d.ts +52 -0
  24. package/dist/context/ContextResolver.d.ts.map +1 -0
  25. package/dist/context/ContextResolver.js +298 -0
  26. package/dist/context/ContextResolver.js.map +1 -0
  27. package/dist/context/TemplateEngine.d.ts +46 -0
  28. package/dist/context/TemplateEngine.d.ts.map +1 -0
  29. package/dist/context/TemplateEngine.js +175 -0
  30. package/dist/context/TemplateEngine.js.map +1 -0
  31. package/dist/context/context.d.ts +8 -0
  32. package/dist/context/context.d.ts.map +1 -0
  33. package/dist/context/context.js +157 -0
  34. package/dist/context/context.js.map +1 -0
  35. package/dist/context/contextCache.d.ts +50 -0
  36. package/dist/context/contextCache.d.ts.map +1 -0
  37. package/dist/context/contextCache.js +175 -0
  38. package/dist/context/contextCache.js.map +1 -0
  39. package/dist/context/index.d.ts +11 -0
  40. package/dist/context/index.d.ts.map +1 -0
  41. package/dist/context/index.js +8 -0
  42. package/dist/context/index.js.map +1 -0
  43. package/dist/credential-stores/CredentialStoreRegistry.d.ts +39 -0
  44. package/dist/credential-stores/CredentialStoreRegistry.d.ts.map +1 -0
  45. package/dist/credential-stores/CredentialStoreRegistry.js +65 -0
  46. package/dist/credential-stores/CredentialStoreRegistry.js.map +1 -0
  47. package/dist/credential-stores/defaults.d.ts +6 -0
  48. package/dist/credential-stores/defaults.d.ts.map +1 -0
  49. package/dist/credential-stores/defaults.js +22 -0
  50. package/dist/credential-stores/defaults.js.map +1 -0
  51. package/dist/credential-stores/index.d.ts +6 -0
  52. package/dist/credential-stores/index.d.ts.map +1 -0
  53. package/dist/credential-stores/index.js +6 -0
  54. package/dist/credential-stores/index.js.map +1 -0
  55. package/dist/credential-stores/keychain-store.d.ts +100 -0
  56. package/dist/credential-stores/keychain-store.d.ts.map +1 -0
  57. package/dist/credential-stores/keychain-store.js +225 -0
  58. package/dist/credential-stores/keychain-store.js.map +1 -0
  59. package/dist/credential-stores/memory-store.d.ts +39 -0
  60. package/dist/credential-stores/memory-store.d.ts.map +1 -0
  61. package/dist/credential-stores/memory-store.js +58 -0
  62. package/dist/credential-stores/memory-store.js.map +1 -0
  63. package/dist/credential-stores/nango-store.d.ts +59 -0
  64. package/dist/credential-stores/nango-store.d.ts.map +1 -0
  65. package/dist/credential-stores/nango-store.js +264 -0
  66. package/dist/credential-stores/nango-store.js.map +1 -0
  67. package/dist/credential-stuffer/CredentialStuffer.d.ts +80 -0
  68. package/dist/credential-stuffer/CredentialStuffer.d.ts.map +1 -0
  69. package/dist/credential-stuffer/CredentialStuffer.js +186 -0
  70. package/dist/credential-stuffer/CredentialStuffer.js.map +1 -0
  71. package/dist/credential-stuffer/index.d.ts +2 -0
  72. package/dist/credential-stuffer/index.d.ts.map +1 -0
  73. package/dist/credential-stuffer/index.js +2 -0
  74. package/dist/credential-stuffer/index.js.map +1 -0
  75. package/dist/data-access/agentDataComponents.d.ts +1 -0
  76. package/dist/data-access/agentDataComponents.d.ts.map +1 -0
  77. package/dist/data-access/agentDataComponents.js +2 -0
  78. package/dist/data-access/agentDataComponents.js.map +1 -0
  79. package/dist/data-access/agentGraphs.d.ts +399 -0
  80. package/dist/data-access/agentGraphs.d.ts.map +1 -0
  81. package/dist/data-access/agentGraphs.js +551 -0
  82. package/dist/data-access/agentGraphs.js.map +1 -0
  83. package/dist/data-access/agentRelations.d.ts +456 -0
  84. package/dist/data-access/agentRelations.d.ts.map +1 -0
  85. package/dist/data-access/agentRelations.js +471 -0
  86. package/dist/data-access/agentRelations.js.map +1 -0
  87. package/dist/data-access/agents.d.ts +218 -0
  88. package/dist/data-access/agents.d.ts.map +1 -0
  89. package/dist/data-access/agents.js +130 -0
  90. package/dist/data-access/agents.js.map +1 -0
  91. package/dist/data-access/apiKeys.d.ts +114 -0
  92. package/dist/data-access/apiKeys.d.ts.map +1 -0
  93. package/dist/data-access/apiKeys.js +185 -0
  94. package/dist/data-access/apiKeys.js.map +1 -0
  95. package/dist/data-access/artifactComponents.d.ts +152 -0
  96. package/dist/data-access/artifactComponents.d.ts.map +1 -0
  97. package/dist/data-access/artifactComponents.js +214 -0
  98. package/dist/data-access/artifactComponents.js.map +1 -0
  99. package/dist/data-access/contextCache.d.ts +68 -0
  100. package/dist/data-access/contextCache.d.ts.map +1 -0
  101. package/dist/data-access/contextCache.js +135 -0
  102. package/dist/data-access/contextCache.js.map +1 -0
  103. package/dist/data-access/contextConfigs.d.ts +110 -0
  104. package/dist/data-access/contextConfigs.d.ts.map +1 -0
  105. package/dist/data-access/contextConfigs.js +156 -0
  106. package/dist/data-access/contextConfigs.js.map +1 -0
  107. package/dist/data-access/conversations.d.ts +125 -0
  108. package/dist/data-access/conversations.d.ts.map +1 -0
  109. package/dist/data-access/conversations.js +244 -0
  110. package/dist/data-access/conversations.js.map +1 -0
  111. package/dist/data-access/credentialReferences.d.ts +86 -0
  112. package/dist/data-access/credentialReferences.d.ts.map +1 -0
  113. package/dist/data-access/credentialReferences.js +175 -0
  114. package/dist/data-access/credentialReferences.js.map +1 -0
  115. package/dist/data-access/dataComponents.d.ts +129 -0
  116. package/dist/data-access/dataComponents.d.ts.map +1 -0
  117. package/dist/data-access/dataComponents.js +213 -0
  118. package/dist/data-access/dataComponents.js.map +1 -0
  119. package/dist/data-access/externalAgents.d.ts +83 -0
  120. package/dist/data-access/externalAgents.d.ts.map +1 -0
  121. package/dist/data-access/externalAgents.js +163 -0
  122. package/dist/data-access/externalAgents.js.map +1 -0
  123. package/dist/data-access/graphFull.d.ts +32 -0
  124. package/dist/data-access/graphFull.d.ts.map +1 -0
  125. package/dist/data-access/graphFull.js +996 -0
  126. package/dist/data-access/graphFull.js.map +1 -0
  127. package/dist/data-access/index.d.ts +21 -0
  128. package/dist/data-access/index.d.ts.map +1 -0
  129. package/dist/data-access/index.js +22 -0
  130. package/dist/data-access/index.js.map +1 -0
  131. package/dist/data-access/ledgerArtifacts.d.ts +49 -0
  132. package/dist/data-access/ledgerArtifacts.d.ts.map +1 -0
  133. package/dist/data-access/ledgerArtifacts.js +112 -0
  134. package/dist/data-access/ledgerArtifacts.js.map +1 -0
  135. package/dist/data-access/messages.d.ts +209 -0
  136. package/dist/data-access/messages.d.ts.map +1 -0
  137. package/dist/data-access/messages.js +100 -0
  138. package/dist/data-access/messages.js.map +1 -0
  139. package/dist/data-access/projects.d.ts +67 -0
  140. package/dist/data-access/projects.d.ts.map +1 -0
  141. package/dist/data-access/projects.js +337 -0
  142. package/dist/data-access/projects.js.map +1 -0
  143. package/dist/data-access/tasks.d.ts +37 -0
  144. package/dist/data-access/tasks.d.ts.map +1 -0
  145. package/dist/data-access/tasks.js +40 -0
  146. package/dist/data-access/tasks.js.map +1 -0
  147. package/dist/data-access/tools.d.ts +277 -0
  148. package/dist/data-access/tools.d.ts.map +1 -0
  149. package/dist/data-access/tools.js +183 -0
  150. package/dist/data-access/tools.js.map +1 -0
  151. package/dist/data-access/validation.d.ts +17 -0
  152. package/dist/data-access/validation.d.ts.map +1 -0
  153. package/dist/data-access/validation.js +52 -0
  154. package/dist/data-access/validation.js.map +1 -0
  155. package/dist/db/clean.d.ts +6 -0
  156. package/dist/db/clean.d.ts.map +1 -0
  157. package/dist/db/clean.js +81 -0
  158. package/dist/db/clean.js.map +1 -0
  159. package/dist/db/client.d.ts +19 -0
  160. package/dist/db/client.d.ts.map +1 -0
  161. package/dist/db/client.js +24 -0
  162. package/dist/db/client.js.map +1 -0
  163. package/dist/db/schema.d.ts +4335 -0
  164. package/dist/db/schema.d.ts.map +1 -0
  165. package/dist/db/schema.js +696 -0
  166. package/dist/db/schema.js.map +1 -0
  167. package/dist/db/test-client.d.ts +25 -0
  168. package/dist/db/test-client.d.ts.map +1 -0
  169. package/dist/db/test-client.js +136 -0
  170. package/dist/db/test-client.js.map +1 -0
  171. package/dist/env.d.ts +19 -0
  172. package/dist/env.d.ts.map +1 -0
  173. package/dist/env.js +49 -0
  174. package/dist/env.js.map +1 -0
  175. package/dist/index.d.ts +12 -0
  176. package/dist/index.d.ts.map +1 -0
  177. package/dist/index.js +13 -0
  178. package/dist/index.js.map +1 -0
  179. package/dist/middleware/contextValidation.d.ts +49 -0
  180. package/dist/middleware/contextValidation.d.ts.map +1 -0
  181. package/dist/middleware/contextValidation.js +473 -0
  182. package/dist/middleware/contextValidation.js.map +1 -0
  183. package/dist/middleware/index.d.ts +2 -0
  184. package/dist/middleware/index.d.ts.map +1 -0
  185. package/dist/middleware/index.js +2 -0
  186. package/dist/middleware/index.js.map +1 -0
  187. package/dist/types/a2a.d.ts +373 -0
  188. package/dist/types/a2a.d.ts.map +1 -0
  189. package/dist/types/a2a.js +14 -0
  190. package/dist/types/a2a.js.map +1 -0
  191. package/dist/types/entities.d.ts +147 -0
  192. package/dist/types/entities.d.ts.map +1 -0
  193. package/dist/types/entities.js +2 -0
  194. package/dist/types/entities.js.map +1 -0
  195. package/dist/types/index.d.ts +5 -0
  196. package/dist/types/index.d.ts.map +1 -0
  197. package/dist/types/index.js +6 -0
  198. package/dist/types/index.js.map +1 -0
  199. package/dist/types/server.d.ts +116 -0
  200. package/dist/types/server.d.ts.map +1 -0
  201. package/dist/types/server.js +2 -0
  202. package/dist/types/server.js.map +1 -0
  203. package/dist/types/utility.d.ts +213 -0
  204. package/dist/types/utility.d.ts.map +1 -0
  205. package/dist/types/utility.js +9 -0
  206. package/dist/types/utility.js.map +1 -0
  207. package/dist/utils/apiKeys.d.ts +32 -0
  208. package/dist/utils/apiKeys.d.ts.map +1 -0
  209. package/dist/utils/apiKeys.js +117 -0
  210. package/dist/utils/apiKeys.js.map +1 -0
  211. package/dist/utils/auth-detection.d.ts +23 -0
  212. package/dist/utils/auth-detection.d.ts.map +1 -0
  213. package/dist/utils/auth-detection.js +148 -0
  214. package/dist/utils/auth-detection.js.map +1 -0
  215. package/dist/utils/credential-store-utils.d.ts +11 -0
  216. package/dist/utils/credential-store-utils.d.ts.map +1 -0
  217. package/dist/utils/credential-store-utils.js +19 -0
  218. package/dist/utils/credential-store-utils.js.map +1 -0
  219. package/dist/utils/error.d.ts +526 -0
  220. package/dist/utils/error.d.ts.map +1 -0
  221. package/dist/utils/error.js +282 -0
  222. package/dist/utils/error.js.map +1 -0
  223. package/dist/utils/execution.d.ts +18 -0
  224. package/dist/utils/execution.d.ts.map +1 -0
  225. package/dist/utils/execution.js +25 -0
  226. package/dist/utils/execution.js.map +1 -0
  227. package/dist/utils/index.d.ts +9 -0
  228. package/dist/utils/index.d.ts.map +1 -0
  229. package/dist/utils/index.js +9 -0
  230. package/dist/utils/index.js.map +1 -0
  231. package/dist/utils/logger.d.ts +79 -0
  232. package/dist/utils/logger.d.ts.map +1 -0
  233. package/dist/utils/logger.js +102 -0
  234. package/dist/utils/logger.js.map +1 -0
  235. package/dist/utils/logging.d.ts +11 -0
  236. package/dist/utils/logging.d.ts.map +1 -0
  237. package/dist/utils/logging.js +6 -0
  238. package/dist/utils/logging.js.map +1 -0
  239. package/dist/utils/mcp-client.d.ts +48 -0
  240. package/dist/utils/mcp-client.d.ts.map +1 -0
  241. package/dist/utils/mcp-client.js +174 -0
  242. package/dist/utils/mcp-client.js.map +1 -0
  243. package/dist/utils/tracer.d.ts +24 -0
  244. package/dist/utils/tracer.d.ts.map +1 -0
  245. package/dist/utils/tracer.js +110 -0
  246. package/dist/utils/tracer.js.map +1 -0
  247. package/dist/validation/graphFull.d.ts +36 -0
  248. package/dist/validation/graphFull.d.ts.map +1 -0
  249. package/dist/validation/graphFull.js +128 -0
  250. package/dist/validation/graphFull.js.map +1 -0
  251. package/dist/validation/id-validation.d.ts +38 -0
  252. package/dist/validation/id-validation.d.ts.map +1 -0
  253. package/dist/validation/id-validation.js +60 -0
  254. package/dist/validation/id-validation.js.map +1 -0
  255. package/dist/validation/index.d.ts +4 -0
  256. package/dist/validation/index.d.ts.map +1 -0
  257. package/dist/validation/index.js +5 -0
  258. package/dist/validation/index.js.map +1 -0
  259. package/dist/validation/schemas.d.ts +7213 -0
  260. package/dist/validation/schemas.d.ts.map +1 -0
  261. package/dist/validation/schemas.js +576 -0
  262. package/dist/validation/schemas.js.map +1 -0
  263. package/package.json +95 -0
package/LICENSE.md ADDED
@@ -0,0 +1,56 @@
1
+ <!--
2
+ AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
3
+ Source: ./LICENSE.md
4
+ This file is automatically copied from the root LICENSE.md during build.
5
+ Any changes should be made to the root LICENSE.md file.
6
+ -->
7
+
8
+ # Inkeep SDK – Elastic License 2.0 with Supplemental Terms
9
+
10
+ NOTE: The Inkeep SDK is licensed under the Elastic License 2.0 (ELv2), subject to Supplemental Terms included in [SUPPLEMENTAL_TERMS.md](SUPPLEMENTAL_TERMS.md). In the event of conflict, the Supplemental Terms control.
11
+
12
+ # Elastic License 2.0
13
+
14
+ ## Acceptance
15
+ By using the software, you agree to all of the terms and conditions below.
16
+
17
+ ## Copyright License
18
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
19
+
20
+ ## Limitations
21
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
22
+
23
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
24
+
25
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
26
+
27
+ ## Patents
28
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
29
+
30
+ ## Notices
31
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
32
+
33
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
34
+
35
+ ## No Other Rights
36
+ These terms do not imply any licenses other than those expressly granted in these terms.
37
+
38
+ ## Termination
39
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
40
+
41
+ ## No Liability
42
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
43
+
44
+ ## Definitions
45
+ The **licensor** is the entity offering these terms, and the **software** is the software the licensor makes available under these terms, including any portion of it.
46
+
47
+ **you** refers to the individual or entity agreeing to these terms.
48
+
49
+ **your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
50
+
51
+ **your licenses** are all the licenses granted to you for the software under these terms.
52
+
53
+ **use** means anything you do with the software requiring one of your licenses.
54
+
55
+ **trademark** means trademarks, service marks, and similar rights.
56
+
package/README.md ADDED
@@ -0,0 +1,464 @@
1
+ # @inkeep/agents-core
2
+
3
+ Core database schema, types, validation, and data access layer for the Inkeep Agent Framework.
4
+
5
+ ## Overview
6
+
7
+ This package serves as the single source of truth for:
8
+ - **Database Schema**: Drizzle ORM schema definitions
9
+ - **Type System**: TypeScript types inferred from schemas
10
+ - **Validation**: Zod schemas for runtime validation
11
+ - **Data Access**: Functional data access layer with dependency injection
12
+ - **Migrations**: Database migration management
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pnpm add @inkeep/agents-core
18
+ ```
19
+
20
+ ## Architecture
21
+
22
+ ### Schema as Source of Truth
23
+
24
+ The Drizzle schema (`src/db/index.ts`) is the authoritative source for all database structure. From this schema:
25
+ 1. Database tables are generated
26
+ 2. Zod validation schemas are derived
27
+ 3. TypeScript types are inferred
28
+ 4. SQL migrations are created
29
+
30
+ ### Functional Data Access Pattern
31
+
32
+ All data access functions follow a consistent functional pattern with dependency injection:
33
+
34
+ ```typescript
35
+ export const getAgentById = (db: DatabaseClient) => async (params: {
36
+ tenantId: string;
37
+ projectId: string;
38
+ agentId: string;
39
+ }) => {
40
+ // Implementation
41
+ };
42
+ ```
43
+
44
+ This pattern enables:
45
+ - Easy testing with mock databases
46
+ - Flexible database configuration
47
+ - Clean separation of concerns
48
+ - Composable data operations
49
+
50
+ ## Usage
51
+
52
+ ### Database Client
53
+
54
+ ```typescript
55
+ import { createDatabaseClient } from '@inkeep/agents-core/data-access';
56
+
57
+ // Production database
58
+ const db = createDatabaseClient({
59
+ url: 'file:./production.db',
60
+ authToken: process.env.DATABASE_AUTH_TOKEN,
61
+ });
62
+
63
+ // In-memory database for testing
64
+ const testDb = createInMemoryDatabaseClient();
65
+ ```
66
+
67
+ ### Data Access
68
+
69
+ ```typescript
70
+ import { getAgentById, createAgent, updateAgent } from '@inkeep/agents-core/data-access';
71
+
72
+ // Create function with database dependency
73
+ const getAgent = getAgentById(db);
74
+
75
+ // Use the function
76
+ const agent = await getAgent({
77
+ tenantId: 'tenant-1',
78
+ projectId: 'project-1',
79
+ agentId: 'agent-1'
80
+ });
81
+ ```
82
+
83
+ ### Validation
84
+
85
+ ```typescript
86
+ import { AgentInsertSchema, AgentUpdateSchema } from '@inkeep/agents-core/validation';
87
+
88
+ // Validate input data
89
+ const validatedData = AgentInsertSchema.parse({
90
+ id: 'agent-1',
91
+ tenantId: 'tenant-1',
92
+ projectId: 'project-1',
93
+ name: 'Support Agent',
94
+ description: 'Handles customer support',
95
+ instructions: 'Be helpful and professional'
96
+ });
97
+
98
+ // Partial validation for updates
99
+ const updateData = AgentUpdateSchema.parse({
100
+ name: 'Updated Agent Name'
101
+ });
102
+ ```
103
+
104
+ ### Types
105
+
106
+ ```typescript
107
+ import type {
108
+ AgentInsert,
109
+ AgentSelect,
110
+ TaskInsert,
111
+ ConversationSelect
112
+ } from '@inkeep/agents-core/validation';
113
+
114
+ // Use types in your application
115
+ function processAgent(agent: AgentSelect) {
116
+ console.log(agent.name);
117
+ }
118
+ ```
119
+
120
+ ## Database Migrations
121
+
122
+ ### Generate Migrations
123
+
124
+ After modifying the schema in `src/db/index.ts`:
125
+
126
+ ```bash
127
+ # Generate SQL migration files
128
+ pnpm db:generate
129
+
130
+ # Preview changes
131
+ pnpm db:check
132
+ ```
133
+
134
+ ### Apply Migrations
135
+
136
+ ```bash
137
+ # Push schema changes directly (development)
138
+ pnpm db:push
139
+
140
+ # Run migrations (production)
141
+ pnpm db:migrate
142
+ ```
143
+
144
+ ### Database Studio
145
+
146
+ ```bash
147
+ # Open Drizzle Studio for database inspection
148
+ pnpm db:studio
149
+ ```
150
+
151
+ ## Testing
152
+
153
+ The package includes comprehensive tests for all components:
154
+
155
+ ```bash
156
+ # Run tests
157
+ pnpm test
158
+
159
+ # Run tests with coverage
160
+ pnpm test:coverage
161
+
162
+ # Watch mode
163
+ pnpm test:watch
164
+ ```
165
+
166
+ Tests use in-memory SQLite databases for isolation and speed.
167
+
168
+
169
+ ## Multi-Service Architecture
170
+
171
+ This package is designed to support a multi-service architecture:
172
+
173
+ ### Management API
174
+ Handles CRUD operations and entity management:
175
+ - Creating/updating agents
176
+ - Managing agent relationships
177
+ - Configuring tools
178
+ - Database migrations
179
+
180
+ ### Execution API
181
+ Handles runtime operations:
182
+ - Processing conversations
183
+ - Executing tasks
184
+ - Agent communication
185
+ - Tool invocation
186
+
187
+ Both services share the same database schema and data access layer from this core package.
188
+
189
+ ## Development
190
+
191
+ ```bash
192
+ # Install dependencies
193
+ pnpm install
194
+
195
+ # Build the package
196
+ pnpm build
197
+
198
+ # Development mode (watch)
199
+ pnpm dev
200
+
201
+ # Linting and formatting
202
+ pnpm lint
203
+ pnpm format
204
+
205
+ # Type checking
206
+ pnpm typecheck
207
+ ```
208
+
209
+ ## Contributing
210
+
211
+ ### Adding a New Entity to the Database Schema
212
+
213
+ When adding a new entity to the Inkeep Agent Framework, follow these steps to ensure proper integration across the schema, validation, and data access layers:
214
+
215
+ #### Step 1: Define the Drizzle Schema
216
+
217
+ Add your table definition to `src/db/index.ts`:
218
+
219
+ ```typescript
220
+ // Example: Adding a "workflows" table
221
+ export const workflows = sqliteTable(
222
+ 'workflows',
223
+ {
224
+ id: text('id').notNull().primaryKey(),
225
+ tenantId: text('tenant_id').notNull(),
226
+ projectId: text('project_id').notNull(),
227
+ name: text('name').notNull(),
228
+ description: text('description'),
229
+ config: text('config', { mode: 'json' }),
230
+ status: text('status').notNull().default('draft'),
231
+ createdAt: text('created_at')
232
+ .notNull()
233
+ .default(sql`(datetime('now'))`),
234
+ updatedAt: text('updated_at')
235
+ .notNull()
236
+ .default(sql`(datetime('now'))`),
237
+ },
238
+ (table) => ({
239
+ tenantProjectIdx: index('workflows_tenant_project_idx')
240
+ .on(table.tenantId, table.projectId),
241
+ })
242
+ );
243
+ ```
244
+
245
+ #### Step 2: Add Relationships (if applicable)
246
+
247
+ Define any relationships with existing tables:
248
+
249
+ ```typescript
250
+ export const workflowRelations = relations(workflows, ({ one, many }) => ({
251
+ // Example: A workflow belongs to an agent graph
252
+ agentGraph: one(agentGraphs, {
253
+ fields: [workflows.agentGraphId],
254
+ references: [agentGraphs.id],
255
+ }),
256
+ // Example: A workflow can have many tasks
257
+ tasks: many(tasks),
258
+ }));
259
+ ```
260
+
261
+ #### Step 3: Create Validation Schemas
262
+
263
+ Add validation schemas to `src/validation/schemas.ts`:
264
+
265
+ ```typescript
266
+ // Select schema (for reading from database)
267
+ export const WorkflowSelectSchema = createSelectSchema(workflows);
268
+
269
+ // Insert schema (for creating new records)
270
+ export const WorkflowInsertSchema = createInsertSchema(workflows).extend({
271
+ id: resourceIdSchema,
272
+ config: z.object({
273
+ // Define your config structure
274
+ triggers: z.array(z.string()).optional(),
275
+ actions: z.array(z.string()).optional(),
276
+ }).optional(),
277
+ });
278
+
279
+ // Update schema (for partial updates)
280
+ export const WorkflowUpdateSchema = WorkflowInsertSchema.partial().omit({
281
+ id: true,
282
+ tenantId: true,
283
+ projectId: true,
284
+ });
285
+
286
+ // API schemas (without tenant/project IDs for external APIs)
287
+ export const WorkflowApiSelectSchema = createApiSchema(WorkflowSelectSchema);
288
+ export const WorkflowApiInsertSchema = createApiInsertSchema(WorkflowInsertSchema);
289
+ export const WorkflowApiUpdateSchema = createApiUpdateSchema(WorkflowUpdateSchema);
290
+ ```
291
+
292
+ ### Step 3.5: Add Types
293
+
294
+ Add types to `src/types/entities`
295
+
296
+ ```typescript
297
+ export type WorkflowSelect = z.infer<typeof WorkflowSelectSchema>;
298
+ export type WorkflowInsert = z.infer<typeof WorkflowInsertSchema>;
299
+ export type WorkflowUpdate = z.infer<typeof WorkflowUpdateSchema>;
300
+ export type WorkflowApiSelect = z.infer<typeof WorkflowApiSelectSchema>;
301
+ export type WorkflowApiInsert = z.infer<typeof WorkflowApiInsertSchema>;
302
+ export type WorkflowApiUpdate = z.infer<typeof WorkflowApiUpdateSchema>;
303
+ ```
304
+
305
+ add any types not directly inferred from the drizzle schema to `src/types/utility.ts`
306
+
307
+ #### Step 4: Create Data Access Functions
308
+
309
+ Create a new file `src/data-access/workflows.ts`:
310
+
311
+ ```typescript
312
+ import { eq, and } from 'drizzle-orm';
313
+ import { workflows } from '../db/index';
314
+ import type { DatabaseClient } from './client';
315
+
316
+ // Get workflow by ID
317
+ export const getWorkflowById = (db: DatabaseClient) => async (params: {
318
+ tenantId: string;
319
+ projectId: string;
320
+ workflowId: string;
321
+ }) => {
322
+ return db.query.workflows.findFirst({
323
+ where: and(
324
+ eq(workflows.tenantId, params.tenantId),
325
+ eq(workflows.projectId, params.projectId),
326
+ eq(workflows.id, params.workflowId)
327
+ ),
328
+ });
329
+ };
330
+
331
+ // List workflows
332
+ export const listWorkflows = (db: DatabaseClient) => async (params: {
333
+ tenantId: string;
334
+ projectId: string;
335
+ }) => {
336
+ return db.query.workflows.findMany({
337
+ where: and(
338
+ eq(workflows.tenantId, params.tenantId),
339
+ eq(workflows.projectId, params.projectId)
340
+ ),
341
+ orderBy: (workflows, { desc }) => [desc(workflows.createdAt)],
342
+ });
343
+ };
344
+
345
+ // Create workflow
346
+ export const createWorkflow = (db: DatabaseClient) => async (params: {
347
+ tenantId: string;
348
+ projectId: string;
349
+ data: any;
350
+ }) => {
351
+ const [result] = await db.insert(workflows).values({
352
+ ...params.data,
353
+ tenantId: params.tenantId,
354
+ projectId: params.projectId,
355
+ }).returning();
356
+ return result;
357
+ };
358
+
359
+ // Update workflow
360
+ export const updateWorkflow = (db: DatabaseClient) => async (params: {
361
+ tenantId: string;
362
+ projectId: string;
363
+ workflowId: string;
364
+ data: any;
365
+ }) => {
366
+ const [result] = await db
367
+ .update(workflows)
368
+ .set({
369
+ ...params.data,
370
+ updatedAt: new Date().toISOString(),
371
+ })
372
+ .where(
373
+ and(
374
+ eq(workflows.tenantId, params.tenantId),
375
+ eq(workflows.projectId, params.projectId),
376
+ eq(workflows.id, params.workflowId)
377
+ )
378
+ )
379
+ .returning();
380
+ return result;
381
+ };
382
+
383
+ // Delete workflow
384
+ export const deleteWorkflow = (db: DatabaseClient) => async (params: {
385
+ tenantId: string;
386
+ projectId: string;
387
+ workflowId: string;
388
+ }) => {
389
+ await db.delete(workflows).where(
390
+ and(
391
+ eq(workflows.tenantId, params.tenantId),
392
+ eq(workflows.projectId, params.projectId),
393
+ eq(workflows.id, params.workflowId)
394
+ )
395
+ );
396
+ return true;
397
+ };
398
+ ```
399
+
400
+ #### Step 5: Export from Index Files
401
+
402
+ Update the relevant index files to export your new schemas and functions:
403
+
404
+ In `src/data-access/index.ts`:
405
+ ```typescript
406
+ export * from './workflows';
407
+ ```
408
+
409
+ #### Step 6: Generate and Apply Migrations
410
+
411
+ ```bash
412
+ # Generate SQL migration for your new table
413
+ pnpm db:generate
414
+
415
+ # Apply migration to database
416
+ pnpm db:push
417
+
418
+ # Or for production, run migrations
419
+ pnpm db:migrate
420
+ ```
421
+
422
+ #### Step 7: Write Tests
423
+
424
+ Create test files for your new entity:
425
+
426
+ 1. **Unit tests** in `src/__tests__/validation/workflows.test.ts`:
427
+ - Test schema validation
428
+ - Test edge cases and constraints
429
+
430
+ 2. **Integration tests** in `src/__tests__/integration/workflows.test.ts`:
431
+ - Test CRUD operations with real database
432
+ - Test relationships with other entities
433
+ - Test tenant isolation
434
+
435
+ Example integration test:
436
+ ```typescript
437
+ describe('Workflow Integration Tests', () => {
438
+ let db: DatabaseClient;
439
+
440
+ beforeEach(() => {
441
+ db = createInMemoryDatabaseClient();
442
+ });
443
+
444
+ it('should create and retrieve a workflow', async () => {
445
+ const workflowData = {
446
+ id: 'test-workflow',
447
+ tenantId: 'test-tenant',
448
+ projectId: 'test-project',
449
+ name: 'Test Workflow',
450
+ description: 'A test workflow',
451
+ status: 'draft',
452
+ };
453
+
454
+ const created = await createWorkflow(db)({
455
+ tenantId: workflowData.tenantId,
456
+ projectId: workflowData.projectId,
457
+ data: workflowData,
458
+ });
459
+
460
+ expect(created.name).toBe(workflowData.name);
461
+ });
462
+ });
463
+ ```
464
+
@@ -0,0 +1,5 @@
1
+ import type { AgentGraphInsert, AgentInsert, AgentRelationInsert } from '../../types/index';
2
+ export declare const createTestAgentData: (tenantId: string, projectId: string, suffix: string) => AgentInsert;
3
+ export declare const createTestRelationData: (tenantId: string, projectId: string, suffix: string) => AgentRelationInsert;
4
+ export declare const createTestGraphData: (tenantId: string, projectId: string, suffix: string) => AgentGraphInsert;
5
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/__tests__/integration/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE5F,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,EAChB,WAAW,MAAM,EACjB,QAAQ,MAAM,KACb,WASF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,UAAU,MAAM,EAChB,WAAW,MAAM,EACjB,QAAQ,MAAM,KACb,mBAUF,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,EAChB,WAAW,MAAM,EACjB,QAAQ,MAAM,KACb,gBAcF,CAAC"}
@@ -0,0 +1,37 @@
1
+ export const createTestAgentData = (tenantId, projectId, suffix) => {
2
+ return {
3
+ id: `default-agent-${suffix}`,
4
+ tenantId,
5
+ projectId,
6
+ name: `Default Agent ${suffix}`,
7
+ description: 'The default agent for the graph',
8
+ prompt: 'Route requests appropriately',
9
+ };
10
+ };
11
+ export const createTestRelationData = (tenantId, projectId, suffix) => {
12
+ return {
13
+ id: `test-relation-${suffix}`,
14
+ tenantId,
15
+ projectId,
16
+ graphId: `test-graph-${suffix}`,
17
+ sourceAgentId: `default-agent-${suffix}`,
18
+ targetAgentId: `default-agent-${suffix}`,
19
+ relationType: 'transfer',
20
+ };
21
+ };
22
+ export const createTestGraphData = (tenantId, projectId, suffix) => {
23
+ return {
24
+ id: `test-graph-${suffix}`,
25
+ tenantId,
26
+ projectId,
27
+ name: `Test Agent Graph ${suffix}`,
28
+ description: 'A comprehensive test graph',
29
+ defaultAgentId: `default-agent-${suffix}`,
30
+ models: {
31
+ base: {
32
+ model: 'gpt-4',
33
+ },
34
+ },
35
+ };
36
+ };
37
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/__tests__/integration/helpers.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,QAAgB,EAChB,SAAiB,EACjB,MAAc,EACD,EAAE;IACf,OAAO;QACL,EAAE,EAAE,iBAAiB,MAAM,EAAE;QAC7B,QAAQ;QACR,SAAS;QACT,IAAI,EAAE,iBAAiB,MAAM,EAAE;QAC/B,WAAW,EAAE,iCAAiC;QAC9C,MAAM,EAAE,8BAA8B;KACvC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,QAAgB,EAChB,SAAiB,EACjB,MAAc,EACO,EAAE;IACvB,OAAO;QACL,EAAE,EAAE,iBAAiB,MAAM,EAAE;QAC7B,QAAQ;QACR,SAAS;QACT,OAAO,EAAE,cAAc,MAAM,EAAE;QAC/B,aAAa,EAAE,iBAAiB,MAAM,EAAE;QACxC,aAAa,EAAE,iBAAiB,MAAM,EAAE;QACxC,YAAY,EAAE,UAAmB;KAClC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,QAAgB,EAChB,SAAiB,EACjB,MAAc,EACI,EAAE;IACpB,OAAO;QACL,EAAE,EAAE,cAAc,MAAM,EAAE;QAC1B,QAAQ;QACR,SAAS;QACT,IAAI,EAAE,oBAAoB,MAAM,EAAE;QAClC,WAAW,EAAE,4BAA4B;QACzC,cAAc,EAAE,iBAAiB,MAAM,EAAE;QACzC,MAAM,EAAE;YACN,IAAI,EAAE;gBACJ,KAAK,EAAE,OAAO;aACf;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const dbClient: import("..").DatabaseClient;
2
+ export { dbClient };
3
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,QAAQ,6BAA4C,CAAC;AAyB3D,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { migrate } from 'drizzle-orm/libsql/migrator';
3
+ import { afterAll, afterEach, beforeAll } from 'vitest';
4
+ import { createDatabaseClient } from '../db/client';
5
+ import { getLogger } from '../utils/logger';
6
+ // Create test database client using in-memory database
7
+ const dbClient = createDatabaseClient({ url: ':memory:' });
8
+ // Initialize database schema for in-memory test databases using Drizzle migrations
9
+ beforeAll(async () => {
10
+ const logger = getLogger('Test Setup');
11
+ try {
12
+ // Temporarily disable foreign key constraints for tests due to composite key issues
13
+ await dbClient.run(sql `PRAGMA foreign_keys = OFF`);
14
+ await migrate(dbClient, { migrationsFolder: './drizzle' });
15
+ }
16
+ catch (error) {
17
+ logger.error({ error }, 'Failed to apply database migrations');
18
+ throw error;
19
+ }
20
+ });
21
+ afterEach(() => {
22
+ // Any cleanup if needed
23
+ });
24
+ afterAll(() => {
25
+ // Any final cleanup if needed
26
+ });
27
+ // Export the test database client for use in tests
28
+ export { dbClient };
29
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,uDAAuD;AACvD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;AAE3D,mFAAmF;AACnF,SAAS,CAAC,KAAK,IAAI,EAAE;IACnB,MAAM,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IACvC,IAAI,CAAC;QACH,oFAAoF;QACpF,MAAM,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAA,2BAA2B,CAAC,CAAC;QAEnD,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,qCAAqC,CAAC,CAAC;QAC/D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,GAAG,EAAE;IACb,wBAAwB;AAC1B,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,GAAG,EAAE;IACZ,8BAA8B;AAChC,CAAC,CAAC,CAAC;AAEH,mDAAmD;AACnD,OAAO,EAAE,QAAQ,EAAE,CAAC"}