@inkeep/agents-core 0.41.2 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/dist/api-client/base-client.d.ts +87 -8
  2. package/dist/api-client/base-client.js +174 -1
  3. package/dist/api-client/eval-api-client.d.ts +47 -0
  4. package/dist/api-client/eval-api-client.js +65 -0
  5. package/dist/api-client/index.d.ts +4 -0
  6. package/dist/api-client/index.js +5 -0
  7. package/dist/api-client/manage-api-client.d.ts +34 -0
  8. package/dist/api-client/manage-api-client.js +104 -0
  9. package/dist/auth/auth.d.ts +86 -20
  10. package/dist/auth/auth.js +55 -1
  11. package/dist/auth/authz/client.d.ts +81 -0
  12. package/dist/auth/authz/client.js +189 -0
  13. package/dist/auth/authz/config.d.ts +76 -0
  14. package/dist/auth/authz/config.js +76 -0
  15. package/dist/auth/authz/index.d.ts +5 -0
  16. package/dist/auth/authz/index.js +6 -0
  17. package/dist/auth/authz/permissions.d.ts +57 -0
  18. package/dist/auth/authz/permissions.js +83 -0
  19. package/dist/auth/authz/sync.d.ts +85 -0
  20. package/dist/auth/authz/sync.js +237 -0
  21. package/dist/auth/permissions.d.ts +13 -13
  22. package/dist/auth/permissions.js +2 -181
  23. package/dist/client-exports.d.ts +8 -3
  24. package/dist/client-exports.js +3 -2
  25. package/dist/constants/context-breakdown.d.ts +61 -0
  26. package/dist/constants/context-breakdown.js +124 -0
  27. package/dist/constants/otel-attributes.d.ts +4 -0
  28. package/dist/constants/otel-attributes.js +4 -0
  29. package/dist/context/ContextConfig.d.ts +2 -2
  30. package/dist/context/ContextConfig.js +3 -3
  31. package/dist/context/TemplateEngine.js +0 -1
  32. package/dist/context/index.d.ts +1 -5
  33. package/dist/context/index.js +1 -5
  34. package/dist/credential-stuffer/CredentialStuffer.d.ts +1 -1
  35. package/dist/data-access/index.d.ts +34 -26
  36. package/dist/data-access/index.js +34 -26
  37. package/dist/data-access/manage/agentFull.d.ts +36 -0
  38. package/dist/data-access/{agentFull.js → manage/agentFull.js} +205 -7
  39. package/dist/data-access/{agents.d.ts → manage/agents.d.ts} +23 -22
  40. package/dist/data-access/{agents.js → manage/agents.js} +52 -7
  41. package/dist/data-access/{artifactComponents.d.ts → manage/artifactComponents.d.ts} +21 -21
  42. package/dist/data-access/{artifactComponents.js → manage/artifactComponents.js} +5 -5
  43. package/dist/data-access/{contextConfigs.d.ts → manage/contextConfigs.d.ts} +14 -14
  44. package/dist/data-access/{contextConfigs.js → manage/contextConfigs.js} +3 -3
  45. package/dist/data-access/{credentialReferences.d.ts → manage/credentialReferences.d.ts} +17 -17
  46. package/dist/data-access/{credentialReferences.js → manage/credentialReferences.js} +2 -2
  47. package/dist/data-access/{dataComponents.d.ts → manage/dataComponents.d.ts} +20 -20
  48. package/dist/data-access/{dataComponents.js → manage/dataComponents.js} +7 -7
  49. package/dist/data-access/manage/evalConfig.d.ts +221 -0
  50. package/dist/data-access/manage/evalConfig.js +275 -0
  51. package/dist/data-access/{externalAgents.d.ts → manage/externalAgents.d.ts} +16 -16
  52. package/dist/data-access/{externalAgents.js → manage/externalAgents.js} +2 -2
  53. package/dist/data-access/{functionTools.d.ts → manage/functionTools.d.ts} +65 -15
  54. package/dist/data-access/{functionTools.js → manage/functionTools.js} +90 -8
  55. package/dist/data-access/{functions.d.ts → manage/functions.d.ts} +9 -9
  56. package/dist/data-access/{functions.js → manage/functions.js} +3 -3
  57. package/dist/data-access/manage/projectFull.d.ts +38 -0
  58. package/dist/data-access/{projectFull.js → manage/projectFull.js} +64 -65
  59. package/dist/data-access/manage/projectLifecycle.d.ts +119 -0
  60. package/dist/data-access/manage/projectLifecycle.js +234 -0
  61. package/dist/data-access/manage/projects.d.ts +75 -0
  62. package/dist/data-access/{projects.js → manage/projects.js} +15 -16
  63. package/dist/data-access/{subAgentExternalAgentRelations.d.ts → manage/subAgentExternalAgentRelations.d.ts} +19 -19
  64. package/dist/data-access/{subAgentExternalAgentRelations.js → manage/subAgentExternalAgentRelations.js} +2 -2
  65. package/dist/data-access/{subAgentRelations.d.ts → manage/subAgentRelations.d.ts} +29 -29
  66. package/dist/data-access/{subAgentRelations.js → manage/subAgentRelations.js} +3 -3
  67. package/dist/data-access/{subAgentTeamAgentRelations.d.ts → manage/subAgentTeamAgentRelations.d.ts} +19 -19
  68. package/dist/data-access/{subAgentTeamAgentRelations.js → manage/subAgentTeamAgentRelations.js} +2 -2
  69. package/dist/data-access/{subAgents.d.ts → manage/subAgents.d.ts} +13 -13
  70. package/dist/data-access/{subAgents.js → manage/subAgents.js} +4 -4
  71. package/dist/data-access/{tools.d.ts → manage/tools.d.ts} +26 -19
  72. package/dist/data-access/{tools.js → manage/tools.js} +57 -35
  73. package/dist/data-access/manage/triggers.d.ts +80 -0
  74. package/dist/data-access/manage/triggers.js +81 -0
  75. package/dist/data-access/{apiKeys.d.ts → runtime/apiKeys.d.ts} +17 -17
  76. package/dist/data-access/{apiKeys.js → runtime/apiKeys.js} +3 -3
  77. package/dist/data-access/runtime/cascade-delete.d.ts +77 -0
  78. package/dist/data-access/runtime/cascade-delete.js +111 -0
  79. package/dist/data-access/{contextCache.d.ts → runtime/contextCache.d.ts} +13 -13
  80. package/dist/data-access/{contextCache.js → runtime/contextCache.js} +5 -5
  81. package/dist/data-access/{conversations.d.ts → runtime/conversations.d.ts} +68 -19
  82. package/dist/data-access/{conversations.js → runtime/conversations.js} +13 -7
  83. package/dist/data-access/runtime/evalRuns.d.ts +120 -0
  84. package/dist/data-access/runtime/evalRuns.js +168 -0
  85. package/dist/data-access/{ledgerArtifacts.d.ts → runtime/ledgerArtifacts.d.ts} +13 -13
  86. package/dist/data-access/{ledgerArtifacts.js → runtime/ledgerArtifacts.js} +3 -3
  87. package/dist/data-access/{messages.d.ts → runtime/messages.d.ts} +15 -15
  88. package/dist/data-access/{messages.js → runtime/messages.js} +2 -2
  89. package/dist/data-access/{organizations.d.ts → runtime/organizations.d.ts} +16 -7
  90. package/dist/data-access/{organizations.js → runtime/organizations.js} +15 -3
  91. package/dist/data-access/runtime/projects.d.ts +62 -0
  92. package/dist/data-access/runtime/projects.js +90 -0
  93. package/dist/data-access/runtime/tasks.d.ts +55 -0
  94. package/dist/data-access/{tasks.js → runtime/tasks.js} +2 -2
  95. package/dist/data-access/runtime/triggerInvocations.d.ts +62 -0
  96. package/dist/data-access/runtime/triggerInvocations.js +54 -0
  97. package/dist/data-access/runtime/users.d.ts +19 -0
  98. package/dist/data-access/{users.js → runtime/users.js} +2 -2
  99. package/dist/data-access/validation.d.ts +4 -4
  100. package/dist/data-access/validation.js +1 -1
  101. package/dist/db/clean.d.ts +8 -4
  102. package/dist/db/clean.js +14 -105
  103. package/dist/db/delete.d.ts +1 -1
  104. package/dist/db/delete.js +7 -10
  105. package/dist/db/manage/dolt-cleanup.d.ts +51 -0
  106. package/dist/db/manage/dolt-cleanup.js +132 -0
  107. package/dist/db/manage/manage-client.d.ts +26 -0
  108. package/dist/db/manage/manage-client.js +68 -0
  109. package/dist/db/{schema.d.ts → manage/manage-schema.d.ts} +1459 -1285
  110. package/dist/db/{schema.js → manage/manage-schema.js} +433 -341
  111. package/dist/db/manage/test-manage-client.d.ts +27 -0
  112. package/dist/db/manage/test-manage-client.js +68 -0
  113. package/dist/db/runtime/runtime-client.d.ts +20 -0
  114. package/dist/db/runtime/runtime-client.js +30 -0
  115. package/dist/db/runtime/runtime-schema.d.ts +2834 -0
  116. package/dist/db/runtime/runtime-schema.js +483 -0
  117. package/dist/db/runtime/test-runtime-client.d.ts +27 -0
  118. package/dist/db/{test-client.js → runtime/test-runtime-client.js} +11 -25
  119. package/dist/dolt/branch.d.ts +62 -0
  120. package/dist/dolt/branch.js +82 -0
  121. package/dist/dolt/branches-api.d.ts +108 -0
  122. package/dist/dolt/branches-api.js +162 -0
  123. package/dist/dolt/commit.d.ts +94 -0
  124. package/dist/dolt/commit.js +103 -0
  125. package/dist/dolt/diff.d.ts +27 -0
  126. package/dist/dolt/diff.js +21 -0
  127. package/dist/dolt/index.d.ts +10 -0
  128. package/dist/dolt/index.js +11 -0
  129. package/dist/dolt/merge.d.ts +63 -0
  130. package/dist/dolt/merge.js +81 -0
  131. package/dist/dolt/migrate-all-branches.d.ts +4 -0
  132. package/dist/dolt/migrate-all-branches.js +78 -0
  133. package/dist/dolt/migrate-dolt.d.ts +1 -0
  134. package/dist/dolt/migrate-dolt.js +22 -0
  135. package/dist/dolt/ref-helpers.d.ts +19 -0
  136. package/dist/dolt/ref-helpers.js +65 -0
  137. package/dist/dolt/ref-middleware.d.ts +82 -0
  138. package/dist/dolt/ref-middleware.js +217 -0
  139. package/dist/dolt/ref-scope.d.ts +101 -0
  140. package/dist/dolt/ref-scope.js +231 -0
  141. package/dist/dolt/schema-sync.d.ts +134 -0
  142. package/dist/dolt/schema-sync.js +246 -0
  143. package/dist/env.d.ts +6 -4
  144. package/dist/env.js +3 -2
  145. package/dist/index.d.ts +71 -44
  146. package/dist/index.js +74 -47
  147. package/dist/types/entities.d.ts +81 -2
  148. package/dist/types/index.d.ts +3 -3
  149. package/dist/types/utility.d.ts +45 -4
  150. package/dist/utils/JsonTransformer.d.ts +44 -0
  151. package/dist/utils/JsonTransformer.js +112 -0
  152. package/dist/utils/apiKeys.d.ts +5 -1
  153. package/dist/utils/apiKeys.js +11 -1
  154. package/dist/utils/colors.d.ts +34 -0
  155. package/dist/utils/colors.js +49 -0
  156. package/dist/utils/credential-store-utils.d.ts +1 -1
  157. package/dist/utils/format-messages.d.ts +1 -1
  158. package/dist/utils/index.d.ts +7 -3
  159. package/dist/utils/index.js +7 -3
  160. package/dist/utils/internal-service-auth.d.ts +79 -0
  161. package/dist/utils/internal-service-auth.js +140 -0
  162. package/dist/utils/jwt-helpers.d.ts +56 -0
  163. package/dist/utils/jwt-helpers.js +90 -0
  164. package/dist/utils/service-token-auth.d.ts +9 -27
  165. package/dist/utils/service-token-auth.js +48 -96
  166. package/dist/utils/template-interpolation.d.ts +22 -0
  167. package/dist/utils/template-interpolation.js +62 -0
  168. package/dist/utils/third-party-mcp-servers/composio-client.js +23 -23
  169. package/dist/utils/trigger-auth.d.ts +62 -0
  170. package/dist/utils/trigger-auth.js +125 -0
  171. package/dist/validation/agentFull.js +2 -4
  172. package/dist/validation/dolt-schemas.d.ts +49 -0
  173. package/dist/validation/dolt-schemas.js +44 -0
  174. package/dist/validation/drizzle-schema-helpers.d.ts +4 -26
  175. package/dist/validation/drizzle-schema-helpers.js +5 -151
  176. package/dist/validation/index.d.ts +4 -3
  177. package/dist/validation/index.js +3 -2
  178. package/dist/validation/schemas.d.ts +17647 -4789
  179. package/dist/validation/schemas.js +328 -11
  180. package/drizzle/manage/0000_tearful_rhodey.sql +414 -0
  181. package/drizzle/manage/0001_broken_wendell_vaughn.sql +19 -0
  182. package/drizzle/manage/0002_bent_sunfire.sql +1 -0
  183. package/drizzle/manage/meta/0000_snapshot.json +2987 -0
  184. package/drizzle/manage/meta/0001_snapshot.json +3115 -0
  185. package/drizzle/manage/meta/0002_snapshot.json +3115 -0
  186. package/drizzle/manage/meta/_journal.json +27 -0
  187. package/drizzle/runtime/0008_silly_preak.sql +127 -0
  188. package/drizzle/runtime/0009_freezing_leo.sql +17 -0
  189. package/drizzle/runtime/meta/0008_snapshot.json +2263 -0
  190. package/drizzle/runtime/meta/0009_snapshot.json +2397 -0
  191. package/drizzle/{meta → runtime/meta}/_journal.json +14 -0
  192. package/package.json +48 -15
  193. package/dist/context/ContextFetcher.d.ts +0 -73
  194. package/dist/context/ContextFetcher.js +0 -291
  195. package/dist/context/ContextResolver.d.ts +0 -60
  196. package/dist/context/ContextResolver.js +0 -278
  197. package/dist/context/context.d.ts +0 -27
  198. package/dist/context/context.js +0 -128
  199. package/dist/context/contextCache.d.ts +0 -58
  200. package/dist/context/contextCache.js +0 -177
  201. package/dist/data-access/agentFull.d.ts +0 -33
  202. package/dist/data-access/projectFull.d.ts +0 -32
  203. package/dist/data-access/projects.d.ts +0 -71
  204. package/dist/data-access/tasks.d.ts +0 -45
  205. package/dist/data-access/users.d.ts +0 -19
  206. package/dist/db/client.d.ts +0 -20
  207. package/dist/db/client.js +0 -28
  208. package/dist/db/test-client.d.ts +0 -31
  209. package/dist/middleware/contextValidation.d.ts +0 -46
  210. package/dist/middleware/contextValidation.js +0 -280
  211. package/dist/middleware/index.d.ts +0 -2
  212. package/dist/middleware/index.js +0 -3
  213. package/dist/utils/execution.d.ts +0 -22
  214. package/dist/utils/execution.js +0 -25
  215. /package/drizzle/{0000_exotic_mysterio.sql → runtime/0000_exotic_mysterio.sql} +0 -0
  216. /package/drizzle/{0001_calm_sheva_callister.sql → runtime/0001_calm_sheva_callister.sql} +0 -0
  217. /package/drizzle/{0002_puzzling_goblin_queen.sql → runtime/0002_puzzling_goblin_queen.sql} +0 -0
  218. /package/drizzle/{0003_sweet_human_robot.sql → runtime/0003_sweet_human_robot.sql} +0 -0
  219. /package/drizzle/{0004_cuddly_shooting_star.sql → runtime/0004_cuddly_shooting_star.sql} +0 -0
  220. /package/drizzle/{0005_reflective_starfox.sql → runtime/0005_reflective_starfox.sql} +0 -0
  221. /package/drizzle/{0006_stale_thaddeus_ross.sql → runtime/0006_stale_thaddeus_ross.sql} +0 -0
  222. /package/drizzle/{0007_slim_karma.sql → runtime/0007_slim_karma.sql} +0 -0
  223. /package/drizzle/{meta → runtime/meta}/0000_snapshot.json +0 -0
  224. /package/drizzle/{meta → runtime/meta}/0001_snapshot.json +0 -0
  225. /package/drizzle/{meta → runtime/meta}/0003_snapshot.json +0 -0
  226. /package/drizzle/{meta → runtime/meta}/0005_snapshot.json +0 -0
  227. /package/drizzle/{meta → runtime/meta}/0006_snapshot.json +0 -0
  228. /package/drizzle/{meta → runtime/meta}/0007_snapshot.json +0 -0
@@ -1,33 +0,0 @@
1
- import { FullAgentDefinition } from "../types/entities.js";
2
- import { AgentScopeConfig, ProjectScopeConfig } from "../types/utility.js";
3
- import { DatabaseClient } from "../db/client.js";
4
-
5
- //#region src/data-access/agentFull.d.ts
6
- interface AgentLogger {
7
- info(obj: Record<string, any>, msg?: string): void;
8
- error(obj: Record<string, any>, msg?: string): void;
9
- }
10
- /**
11
- * Server-side implementation of createFullAgent that performs actual database operations.
12
- * This function creates a complete agent with all agents, tools, and relationships.
13
- */
14
- declare const createFullAgentServerSide: (db: DatabaseClient, logger?: AgentLogger) => (scopes: ProjectScopeConfig, agentData: FullAgentDefinition) => Promise<FullAgentDefinition>;
15
- /**
16
- * Server-side implementation of updateFullAgent that performs actual database operations.
17
- * This function updates a complete agent with all agents, tools, and relationships.
18
- */
19
- declare const updateFullAgentServerSide: (db: DatabaseClient, logger?: AgentLogger) => (scopes: ProjectScopeConfig, agentData: FullAgentDefinition) => Promise<FullAgentDefinition>;
20
- /**
21
- * Get a complete agent definition by ID
22
- */
23
- declare const getFullAgent: (db: DatabaseClient, logger?: AgentLogger) => (params: {
24
- scopes: AgentScopeConfig;
25
- }) => Promise<FullAgentDefinition | null>;
26
- /**
27
- * Delete a complete agent and cascade to all related entities
28
- */
29
- declare const deleteFullAgent: (db: DatabaseClient, logger?: AgentLogger) => (params: {
30
- scopes: AgentScopeConfig;
31
- }) => Promise<boolean>;
32
- //#endregion
33
- export { AgentLogger, createFullAgentServerSide, deleteFullAgent, getFullAgent, updateFullAgentServerSide };
@@ -1,32 +0,0 @@
1
- import { FullProjectDefinition } from "../types/entities.js";
2
- import { getLogger } from "../utils/logger.js";
3
- import { ProjectScopeConfig } from "../types/utility.js";
4
- import { DatabaseClient } from "../db/client.js";
5
-
6
- //#region src/data-access/projectFull.d.ts
7
-
8
- type ProjectLogger = ReturnType<typeof getLogger>;
9
- /**
10
- * Server-side implementation of createFullProject that performs actual database operations.
11
- * This function creates a complete project with all agent and their nested resources.
12
- */
13
- declare const createFullProjectServerSide: (db: DatabaseClient, logger?: ProjectLogger) => (scopes: ProjectScopeConfig, projectData: FullProjectDefinition) => Promise<FullProjectDefinition>;
14
- /**
15
- * Server-side implementation of updateFullProject that performs actual database operations.
16
- * This function updates a complete project with all agent and their nested resources.
17
- */
18
- declare const updateFullProjectServerSide: (db: DatabaseClient, logger?: ProjectLogger) => (scopes: ProjectScopeConfig, projectData: FullProjectDefinition) => Promise<FullProjectDefinition>;
19
- /**
20
- * Get a complete project definition with all nested resources
21
- */
22
- declare const getFullProject: (db: DatabaseClient, logger?: ProjectLogger) => (params: {
23
- scopes: ProjectScopeConfig;
24
- }) => Promise<FullProjectDefinition | null>;
25
- /**
26
- * Delete a complete project and cascade to all related entities
27
- */
28
- declare const deleteFullProject: (db: DatabaseClient, logger?: ProjectLogger) => (params: {
29
- scopes: ProjectScopeConfig;
30
- }) => Promise<boolean>;
31
- //#endregion
32
- export { ProjectLogger, createFullProjectServerSide, deleteFullProject, getFullProject, updateFullProjectServerSide };
@@ -1,71 +0,0 @@
1
- import { ProjectInsert, ProjectSelect, ProjectUpdate } from "../types/entities.js";
2
- import { PaginationConfig, PaginationResult, ProjectInfo, ProjectResourceCounts, ProjectScopeConfig } from "../types/utility.js";
3
- import { DatabaseClient } from "../db/client.js";
4
-
5
- //#region src/data-access/projects.d.ts
6
-
7
- /**
8
- * List all unique project IDs within a tenant by scanning all resource tables
9
- */
10
- declare const listProjects: (db: DatabaseClient) => (params: {
11
- tenantId: string;
12
- }) => Promise<ProjectInfo[]>;
13
- /**
14
- * List all unique project IDs within a tenant with pagination
15
- */
16
- declare const listProjectsPaginated: (db: DatabaseClient) => (params: {
17
- tenantId: string;
18
- pagination?: PaginationConfig;
19
- }) => Promise<{
20
- data: ProjectSelect[];
21
- pagination: PaginationResult;
22
- }>;
23
- /**
24
- * Get resource counts for a specific project
25
- */
26
- declare const getProjectResourceCounts: (db: DatabaseClient) => (params: ProjectScopeConfig) => Promise<ProjectResourceCounts>;
27
- /**
28
- * Check if a project exists (has any resources)
29
- */
30
- declare const projectExists: (db: DatabaseClient) => (params: ProjectScopeConfig) => Promise<boolean>;
31
- /**
32
- * Count total projects for a tenant
33
- */
34
- declare const countProjects: (db: DatabaseClient) => (params: {
35
- tenantId: string;
36
- }) => Promise<number>;
37
- /**
38
- * Get a single project by ID
39
- */
40
- declare const getProject: (db: DatabaseClient) => (params: {
41
- scopes: ProjectScopeConfig;
42
- }) => Promise<ProjectSelect | null>;
43
- /**
44
- * Create a new project
45
- */
46
- declare const createProject: (db: DatabaseClient) => (params: ProjectInsert) => Promise<ProjectSelect>;
47
- /**
48
- * Update an existing project
49
- */
50
- declare const updateProject: (db: DatabaseClient) => (params: {
51
- scopes: ProjectScopeConfig;
52
- data: ProjectUpdate;
53
- }) => Promise<ProjectSelect | null>;
54
- /**
55
- * Check if a project exists in the projects table
56
- */
57
- declare const projectExistsInTable: (db: DatabaseClient) => (params: {
58
- scopes: ProjectScopeConfig;
59
- }) => Promise<boolean>;
60
- /**
61
- * Check if a project has any resources (used before deletion)
62
- */
63
- declare const projectHasResources: (db: DatabaseClient) => (params: ProjectScopeConfig) => Promise<boolean>;
64
- /**
65
- * Delete a project (with validation for existing resources)
66
- */
67
- declare const deleteProject: (db: DatabaseClient) => (params: {
68
- scopes: ProjectScopeConfig;
69
- }) => Promise<boolean>;
70
- //#endregion
71
- export { countProjects, createProject, deleteProject, getProject, getProjectResourceCounts, listProjects, listProjectsPaginated, projectExists, projectExistsInTable, projectHasResources, updateProject };
@@ -1,45 +0,0 @@
1
- import { TaskInsert, TaskSelect } from "../types/entities.js";
2
- import "../types/index.js";
3
- import "../index.js";
4
- import { TaskMetadataConfig } from "../types/utility.js";
5
- import { DatabaseClient } from "../db/client.js";
6
-
7
- //#region src/data-access/tasks.d.ts
8
- declare const createTask: (db: DatabaseClient) => (params: TaskInsert) => Promise<{
9
- tenantId: string;
10
- projectId: string;
11
- id: string;
12
- agentId: string;
13
- createdAt: string;
14
- updatedAt: string;
15
- metadata: TaskMetadataConfig | null;
16
- status: string;
17
- subAgentId: string;
18
- contextId: string;
19
- }>;
20
- declare const getTask: (db: DatabaseClient) => (params: {
21
- id: string;
22
- }) => Promise<TaskSelect | null>;
23
- declare const updateTask: (db: DatabaseClient) => (params: {
24
- taskId: string;
25
- data: {
26
- status?: string;
27
- metadata?: any;
28
- };
29
- }) => Promise<{
30
- createdAt: string;
31
- updatedAt: string;
32
- contextId: string;
33
- status: string;
34
- metadata: TaskMetadataConfig | null;
35
- subAgentId: string;
36
- agentId: string;
37
- projectId: string;
38
- tenantId: string;
39
- id: string;
40
- }>;
41
- declare const listTaskIdsByContextId: (db: DatabaseClient) => (params: {
42
- contextId: string;
43
- }) => Promise<string[]>;
44
- //#endregion
45
- export { createTask, getTask, listTaskIdsByContextId, updateTask };
@@ -1,19 +0,0 @@
1
- import { User } from "../auth/auth-validation-schemas.js";
2
- import { DatabaseClient } from "../db/client.js";
3
-
4
- //#region src/data-access/users.d.ts
5
-
6
- /**
7
- * User data access layer
8
- * All database queries for Better Auth's user table
9
- */
10
- /**
11
- * Get user by ID
12
- */
13
- declare const getUserById: (db: DatabaseClient) => (userId: string) => Promise<User | null>;
14
- /**
15
- * Get user by email
16
- */
17
- declare const getUserByEmail: (db: DatabaseClient) => (email: string) => Promise<User | null>;
18
- //#endregion
19
- export { getUserByEmail, getUserById };
@@ -1,20 +0,0 @@
1
- import { schema_d_exports } from "./schema.js";
2
- import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
- import { PgliteDatabase } from "drizzle-orm/pglite";
4
-
5
- //#region src/db/client.d.ts
6
- type DatabaseClient = NodePgDatabase<typeof schema_d_exports> | PgliteDatabase<typeof schema_d_exports>;
7
- interface DatabaseConfig {
8
- connectionString?: string;
9
- poolSize?: number;
10
- ssl?: boolean;
11
- logger?: {
12
- logQuery: (query: string, params: unknown[]) => void;
13
- };
14
- }
15
- /**
16
- * Creates a PostgreSQL database client with connection pooling
17
- */
18
- declare function createDatabaseClient(config?: DatabaseConfig): DatabaseClient;
19
- //#endregion
20
- export { DatabaseClient, DatabaseConfig, createDatabaseClient };
package/dist/db/client.js DELETED
@@ -1,28 +0,0 @@
1
- import { schema_exports } from "./schema.js";
2
- import { env, loadEnvironmentFiles } from "../env.js";
3
- import { drizzle } from "drizzle-orm/node-postgres";
4
- import { Pool } from "pg";
5
-
6
- //#region src/db/client.ts
7
- loadEnvironmentFiles();
8
- /**
9
- * Creates a PostgreSQL database client with connection pooling
10
- */
11
- function createDatabaseClient(config = {}) {
12
- const connectionString = config.connectionString || process.env.DATABASE_URL;
13
- if (!connectionString) throw new Error("DATABASE_URL environment variable is required. Please set it to your PostgreSQL connection string.");
14
- const pool = new Pool({
15
- connectionString,
16
- max: config.poolSize || Number(env.POSTGRES_POOL_SIZE) || 10
17
- });
18
- pool.on("error", (err) => {
19
- console.error("Unexpected PostgreSQL pool error:", err);
20
- });
21
- return drizzle(pool, {
22
- schema: schema_exports,
23
- logger: config.logger
24
- });
25
- }
26
-
27
- //#endregion
28
- export { createDatabaseClient };
@@ -1,31 +0,0 @@
1
- import { DatabaseClient } from "./client.js";
2
-
3
- //#region src/db/test-client.d.ts
4
-
5
- /**
6
- * Creates a test database client using an in-memory PostgreSQL database (PGlite)
7
- * This provides real database operations for integration testing with perfect isolation
8
- * Each call creates a fresh database with all migrations applied
9
- */
10
- declare function createTestDatabaseClient(drizzleDir?: string): Promise<DatabaseClient>;
11
- /**
12
- * Cleans up test database by removing all data but keeping schema
13
- * Dynamically gets all tables from the public schema and truncates them
14
- */
15
- declare function cleanupTestDatabase(db: DatabaseClient): Promise<void>;
16
- /**
17
- * Closes the test database and removes the file
18
- */
19
- declare function closeTestDatabase(db: DatabaseClient): Promise<void>;
20
- /**
21
- * Creates a test organization in the database
22
- * This is a helper for tests that need organization records before creating projects/agents
23
- */
24
- declare function createTestOrganization(db: DatabaseClient, tenantId: string): Promise<void>;
25
- /**
26
- * Creates a test project in the database
27
- * Ensures the organization exists first
28
- */
29
- declare function createTestProject(db: DatabaseClient, tenantId: string, projectId?: string): Promise<void>;
30
- //#endregion
31
- export { cleanupTestDatabase, closeTestDatabase, createTestDatabaseClient, createTestOrganization, createTestProject };
@@ -1,46 +0,0 @@
1
- import { CredentialStoreRegistry } from "../credential-stores/CredentialStoreRegistry.js";
2
- import { DatabaseClient } from "../db/client.js";
3
- import { ValidateFunction } from "ajv";
4
- import { Context, Next } from "hono";
5
-
6
- //#region src/middleware/contextValidation.d.ts
7
- declare const HTTP_REQUEST_PARTS: readonly ["headers"];
8
- type HttpRequestPart = (typeof HTTP_REQUEST_PARTS)[number];
9
- interface ContextValidationError {
10
- field: string;
11
- message: string;
12
- value?: unknown;
13
- }
14
- interface ContextValidationResult {
15
- valid: boolean;
16
- errors: ContextValidationError[];
17
- validatedContext?: Record<string, unknown> | ParsedHttpRequest;
18
- }
19
- interface ParsedHttpRequest {
20
- headers?: Record<string, string>;
21
- }
22
- declare function isValidHttpRequest(obj: any): obj is ParsedHttpRequest;
23
- declare function getCachedValidator(schema: Record<string, unknown>): ValidateFunction;
24
- declare function validationHelper(jsonSchema: Record<string, unknown>): ValidateFunction<unknown>;
25
- declare function validateAgainstJsonSchema(jsonSchema: Record<string, unknown>, context: unknown): boolean;
26
- declare function validateHttpRequestHeaders(headersSchema: any, httpRequest: ParsedHttpRequest): Promise<ContextValidationResult>;
27
- declare function validateHeaders({
28
- tenantId,
29
- projectId,
30
- agentId,
31
- conversationId,
32
- parsedRequest,
33
- dbClient,
34
- credentialStores
35
- }: {
36
- tenantId: string;
37
- projectId: string;
38
- agentId: string;
39
- conversationId: string;
40
- parsedRequest: ParsedHttpRequest;
41
- dbClient: DatabaseClient;
42
- credentialStores?: CredentialStoreRegistry;
43
- }): Promise<ContextValidationResult>;
44
- declare function contextValidationMiddleware(dbClient: DatabaseClient): (c: Context, next: Next) => Promise<void>;
45
- //#endregion
46
- export { ContextValidationError, ContextValidationResult, HTTP_REQUEST_PARTS, HttpRequestPart, ParsedHttpRequest, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
@@ -1,280 +0,0 @@
1
- import { getLogger } from "../utils/logger.js";
2
- import { getContextConfigById } from "../data-access/contextConfigs.js";
3
- import { createApiError } from "../utils/error.js";
4
- import { getRequestExecutionContext } from "../utils/execution.js";
5
- import { getAgentWithDefaultSubAgent } from "../data-access/agents.js";
6
- import { ContextResolver } from "../context/ContextResolver.js";
7
- import Ajv from "ajv";
8
-
9
- //#region src/middleware/contextValidation.ts
10
- const logger = getLogger("context-validation");
11
- const ajv = new Ajv({
12
- allErrors: true,
13
- strict: false
14
- });
15
- const HTTP_REQUEST_PARTS = ["headers"];
16
- const MAX_SCHEMA_CACHE_SIZE = 1e3;
17
- const schemaCache = /* @__PURE__ */ new Map();
18
- function isValidHttpRequest(obj) {
19
- return obj != null && typeof obj === "object" && !Array.isArray(obj) && "headers" in obj;
20
- }
21
- function getCachedValidator(schema) {
22
- const key = JSON.stringify(schema);
23
- if (schemaCache.has(key)) {
24
- const validator$1 = schemaCache.get(key);
25
- if (!validator$1) throw new Error("Unexpected: validator not found in cache after has() check");
26
- schemaCache.delete(key);
27
- schemaCache.set(key, validator$1);
28
- return validator$1;
29
- }
30
- if (schemaCache.size >= MAX_SCHEMA_CACHE_SIZE) {
31
- const firstKey = schemaCache.keys().next().value;
32
- if (firstKey) schemaCache.delete(firstKey);
33
- }
34
- const permissiveSchema = makeSchemaPermissive(schema);
35
- const validator = ajv.compile(permissiveSchema);
36
- schemaCache.set(key, validator);
37
- return validator;
38
- }
39
- function makeSchemaPermissive(schema) {
40
- if (!schema || typeof schema !== "object") return schema;
41
- const permissiveSchema = { ...schema };
42
- if (permissiveSchema.type === "object") {
43
- permissiveSchema.additionalProperties = true;
44
- if (permissiveSchema.properties && typeof permissiveSchema.properties === "object") {
45
- const newProperties = {};
46
- for (const [key, value] of Object.entries(permissiveSchema.properties)) newProperties[key] = makeSchemaPermissive(value);
47
- permissiveSchema.properties = newProperties;
48
- }
49
- }
50
- if (permissiveSchema.type === "array" && permissiveSchema.items) permissiveSchema.items = makeSchemaPermissive(permissiveSchema.items);
51
- if (permissiveSchema.oneOf) permissiveSchema.oneOf = permissiveSchema.oneOf.map(makeSchemaPermissive);
52
- if (permissiveSchema.anyOf) permissiveSchema.anyOf = permissiveSchema.anyOf.map(makeSchemaPermissive);
53
- if (permissiveSchema.allOf) permissiveSchema.allOf = permissiveSchema.allOf.map(makeSchemaPermissive);
54
- return permissiveSchema;
55
- }
56
- function validationHelper(jsonSchema) {
57
- return getCachedValidator(jsonSchema);
58
- }
59
- function validateAgainstJsonSchema(jsonSchema, context) {
60
- return validationHelper(jsonSchema)(context);
61
- }
62
- function filterByJsonSchema(data, schema) {
63
- if (!schema || data === null || data === void 0) return data;
64
- if (schema.type === "object" && schema.properties && typeof data === "object" && !Array.isArray(data)) {
65
- const filtered = {};
66
- for (const [key, propSchema] of Object.entries(schema.properties)) if (key in data) filtered[key] = filterByJsonSchema(data[key], propSchema);
67
- return filtered;
68
- }
69
- if (schema.type === "array" && schema.items && Array.isArray(data)) return data.map((item) => filterByJsonSchema(item, schema.items));
70
- if (schema.anyOf && Array.isArray(schema.anyOf)) {
71
- for (const subSchema of schema.anyOf) if (subSchema.type && typeof data === subSchema.type) return filterByJsonSchema(data, subSchema);
72
- return filterByJsonSchema(data, schema.anyOf[0]);
73
- }
74
- return data;
75
- }
76
- function filterContextToSchemaKeys(validatedContext, headersSchema) {
77
- if (!headersSchema || !validatedContext) return validatedContext;
78
- const filteredHeaders = filterByJsonSchema(validatedContext, headersSchema);
79
- if (filteredHeaders !== null && filteredHeaders !== void 0) {
80
- if (typeof filteredHeaders === "object" && Object.keys(filteredHeaders).length > 0) return filteredHeaders;
81
- if (typeof filteredHeaders !== "object") return filteredHeaders;
82
- }
83
- return {};
84
- }
85
- async function validateHttpRequestHeaders(headersSchema, httpRequest) {
86
- const errors = [];
87
- let validatedContext = {};
88
- if (!isValidHttpRequest(httpRequest)) return {
89
- valid: false,
90
- errors: [{
91
- field: "httpRequest",
92
- message: "Invalid HTTP request format - must contain headers"
93
- }]
94
- };
95
- try {
96
- if (headersSchema && httpRequest.headers !== void 0) try {
97
- const validate = validationHelper(headersSchema);
98
- if (validate(httpRequest.headers)) validatedContext = httpRequest.headers;
99
- else if (validate.errors) for (const error of validate.errors) errors.push({
100
- field: `headers.${error.instancePath || "root"}`,
101
- message: `headers ${error.message}`,
102
- value: error.data
103
- });
104
- } catch (validationError) {
105
- errors.push({
106
- field: "headers",
107
- message: `Failed to validate headers: ${validationError instanceof Error ? validationError.message : "Unknown error"}`
108
- });
109
- }
110
- const filteredContext = errors.length === 0 ? filterContextToSchemaKeys(validatedContext, headersSchema) : void 0;
111
- return {
112
- valid: errors.length === 0,
113
- errors,
114
- validatedContext: filteredContext
115
- };
116
- } catch (error) {
117
- logger.error({ error: error instanceof Error ? error.message : "Unknown error" }, "Failed to validate headers schema");
118
- return {
119
- valid: false,
120
- errors: [{
121
- field: "schema",
122
- message: "Failed to validate headers schema"
123
- }]
124
- };
125
- }
126
- }
127
- async function fetchExistingHeaders({ tenantId, projectId, contextConfig, conversationId, dbClient, credentialStores }) {
128
- const headers = await new ContextResolver(tenantId, projectId, dbClient, credentialStores).resolveHeaders(conversationId, contextConfig.id);
129
- if (Object.keys(headers).length > 0) return {
130
- valid: true,
131
- errors: [],
132
- validatedContext: headers
133
- };
134
- throw new Error("No headers found in cache. Please provide headers in request.");
135
- }
136
- async function validateHeaders({ tenantId, projectId, agentId, conversationId, parsedRequest, dbClient, credentialStores }) {
137
- try {
138
- const agent = await getAgentWithDefaultSubAgent(dbClient)({ scopes: {
139
- tenantId,
140
- projectId,
141
- agentId
142
- } });
143
- if (!agent?.contextConfigId) {
144
- logger.debug({ agentId }, "No context config found for agent, skipping validation");
145
- return {
146
- valid: true,
147
- errors: [],
148
- validatedContext: parsedRequest
149
- };
150
- }
151
- const contextConfig = await getContextConfigById(dbClient)({
152
- scopes: {
153
- tenantId,
154
- projectId,
155
- agentId
156
- },
157
- id: agent.contextConfigId
158
- });
159
- if (!contextConfig) {
160
- logger.warn({ contextConfigId: agent.contextConfigId }, "Context config not found");
161
- return {
162
- valid: false,
163
- errors: [{
164
- field: "contextConfig",
165
- message: "Context configuration not found"
166
- }]
167
- };
168
- }
169
- if (!contextConfig.headersSchema) {
170
- logger.debug({ contextConfigId: contextConfig.id }, "No headers schema defined, accepting any context");
171
- return {
172
- valid: true,
173
- errors: [],
174
- validatedContext: parsedRequest
175
- };
176
- }
177
- try {
178
- const schema = contextConfig.headersSchema;
179
- logger.debug({ contextConfigId: contextConfig.id }, "Using headers schema validation");
180
- const validationResult = await validateHttpRequestHeaders(schema, parsedRequest);
181
- if (validationResult.valid) return validationResult;
182
- try {
183
- return await fetchExistingHeaders({
184
- tenantId,
185
- projectId,
186
- contextConfig,
187
- conversationId,
188
- dbClient,
189
- credentialStores
190
- });
191
- } catch (_error) {
192
- validationResult.errors.push({
193
- field: "headers",
194
- message: "Failed to fetch headers from cache"
195
- });
196
- return validationResult;
197
- }
198
- } catch (error) {
199
- logger.error({
200
- contextConfigId: contextConfig.id,
201
- error: error instanceof Error ? error.message : "Unknown error"
202
- }, "Failed to compile or validate schema");
203
- return {
204
- valid: false,
205
- errors: [{
206
- field: "schema",
207
- message: "Invalid schema definition or validation error"
208
- }]
209
- };
210
- }
211
- } catch (error) {
212
- logger.error({
213
- tenantId,
214
- agentId,
215
- error: error instanceof Error ? error.message : "Unknown error"
216
- }, "Failed to validate headers");
217
- return {
218
- valid: false,
219
- errors: [{
220
- field: "validation",
221
- message: "Context validation failed due to internal error"
222
- }]
223
- };
224
- }
225
- }
226
- function contextValidationMiddleware(dbClient) {
227
- return async (c, next) => {
228
- try {
229
- let { tenantId, projectId, agentId } = getRequestExecutionContext(c);
230
- if (!tenantId || !projectId || !agentId) {
231
- tenantId = c.req.param("tenantId");
232
- projectId = c.req.param("projectId");
233
- agentId = c.req.param("agentId");
234
- }
235
- if (!tenantId || !projectId || !agentId) return next();
236
- const conversationId = (c.get("requestBody") || {}).conversationId || "";
237
- const headers = {};
238
- c.req.raw.headers.forEach((value, key) => {
239
- headers[key.toLowerCase()] = value;
240
- });
241
- const credentialStores = c.get("credentialStores");
242
- const validationResult = await validateHeaders({
243
- tenantId,
244
- projectId,
245
- agentId,
246
- conversationId,
247
- parsedRequest: { headers },
248
- dbClient,
249
- credentialStores
250
- });
251
- if (!validationResult.valid) {
252
- logger.warn({
253
- tenantId,
254
- agentId,
255
- errors: validationResult.errors
256
- }, "Headers validation failed");
257
- throw createApiError({
258
- code: "bad_request",
259
- message: `Invalid headers: ${validationResult.errors.map((e) => `${e.field}: ${e.message}`).join(", ")}`
260
- });
261
- }
262
- c.set("validatedContext", validationResult.validatedContext);
263
- logger.debug({
264
- tenantId,
265
- agentId,
266
- contextKeys: Object.keys(validationResult.validatedContext || {})
267
- }, "Request context validation successful");
268
- return next();
269
- } catch (error) {
270
- logger.error({ error: error instanceof Error ? error.message : "Unknown error" }, "Context validation middleware error");
271
- throw createApiError({
272
- code: "internal_server_error",
273
- message: "Context validation failed"
274
- });
275
- }
276
- };
277
- }
278
-
279
- //#endregion
280
- export { HTTP_REQUEST_PARTS, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
@@ -1,2 +0,0 @@
1
- import { ContextValidationError, ContextValidationResult, HTTP_REQUEST_PARTS, HttpRequestPart, ParsedHttpRequest, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper } from "./contextValidation.js";
2
- export { ContextValidationError, ContextValidationResult, HTTP_REQUEST_PARTS, HttpRequestPart, ParsedHttpRequest, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
@@ -1,3 +0,0 @@
1
- import { HTTP_REQUEST_PARTS, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper } from "./contextValidation.js";
2
-
3
- export { HTTP_REQUEST_PARTS, contextValidationMiddleware, getCachedValidator, isValidHttpRequest, validateAgainstJsonSchema, validateHeaders, validateHttpRequestHeaders, validationHelper };
@@ -1,22 +0,0 @@
1
- import { ExecutionContext } from "../types/utility.js";
2
- import { Context } from "hono";
3
-
4
- //#region src/utils/execution.d.ts
5
-
6
- /**
7
- * Create execution context from middleware values
8
- */
9
- declare function createExecutionContext(params: {
10
- apiKey: string;
11
- tenantId: string;
12
- projectId: string;
13
- agentId: string;
14
- apiKeyId: string;
15
- baseUrl?: string;
16
- }): ExecutionContext;
17
- /**
18
- * Get execution context from API key authentication
19
- */
20
- declare function getRequestExecutionContext(c: Context): ExecutionContext;
21
- //#endregion
22
- export { createExecutionContext, getRequestExecutionContext };
@@ -1,25 +0,0 @@
1
- //#region src/utils/execution.ts
2
- /**
3
- * Create execution context from middleware values
4
- */
5
- function createExecutionContext(params) {
6
- return {
7
- apiKey: params.apiKey,
8
- tenantId: params.tenantId,
9
- projectId: params.projectId,
10
- agentId: params.agentId,
11
- baseUrl: params.baseUrl || process.env.API_URL || "http://localhost:3003",
12
- apiKeyId: params.apiKeyId
13
- };
14
- }
15
- /**
16
- * Get execution context from API key authentication
17
- */
18
- function getRequestExecutionContext(c) {
19
- const executionContext = c.get("executionContext");
20
- if (!executionContext) throw new Error("No execution context available. API key authentication is required.");
21
- return executionContext;
22
- }
23
-
24
- //#endregion
25
- export { createExecutionContext, getRequestExecutionContext };