@inkeep/agents-core 0.1.4 → 0.1.7

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 (278) hide show
  1. package/README.md +2 -2
  2. package/SUPPLEMENTAL_TERMS.md +40 -0
  3. package/dist/chunk-BMKWVKI2.js +126 -0
  4. package/dist/chunk-H2F72PDA.js +15 -0
  5. package/dist/chunk-MKBO26DX.js +9 -0
  6. package/dist/chunk-MXQKLGQK.js +925 -0
  7. package/dist/chunk-R3VVJXX7.js +575 -0
  8. package/dist/chunk-SVGQSPW4.js +24 -0
  9. package/dist/client-exports.cjs +1702 -0
  10. package/dist/client-exports.js +202 -246
  11. package/dist/db/schema.cjs +922 -0
  12. package/dist/db/schema.js +1 -696
  13. package/dist/index.cjs +10122 -0
  14. package/dist/index.js +7989 -13
  15. package/dist/types/index.cjs +45 -0
  16. package/dist/types/index.js +2 -6
  17. package/dist/validation/index.cjs +1772 -0
  18. package/dist/validation/index.js +2 -5
  19. package/package.json +11 -6
  20. package/dist/__tests__/integration/helpers.d.ts +0 -5
  21. package/dist/__tests__/integration/helpers.d.ts.map +0 -1
  22. package/dist/__tests__/integration/helpers.js +0 -37
  23. package/dist/__tests__/integration/helpers.js.map +0 -1
  24. package/dist/__tests__/setup.d.ts +0 -3
  25. package/dist/__tests__/setup.d.ts.map +0 -1
  26. package/dist/__tests__/setup.js +0 -29
  27. package/dist/__tests__/setup.js.map +0 -1
  28. package/dist/client-exports.d.ts +0 -300
  29. package/dist/client-exports.d.ts.map +0 -1
  30. package/dist/client-exports.js.map +0 -1
  31. package/dist/context/ContextConfig.d.ts +0 -54
  32. package/dist/context/ContextConfig.d.ts.map +0 -1
  33. package/dist/context/ContextConfig.js +0 -302
  34. package/dist/context/ContextConfig.js.map +0 -1
  35. package/dist/context/ContextFetcher.d.ts +0 -64
  36. package/dist/context/ContextFetcher.d.ts.map +0 -1
  37. package/dist/context/ContextFetcher.js +0 -325
  38. package/dist/context/ContextFetcher.js.map +0 -1
  39. package/dist/context/ContextResolver.d.ts +0 -52
  40. package/dist/context/ContextResolver.d.ts.map +0 -1
  41. package/dist/context/ContextResolver.js +0 -298
  42. package/dist/context/ContextResolver.js.map +0 -1
  43. package/dist/context/TemplateEngine.d.ts +0 -46
  44. package/dist/context/TemplateEngine.d.ts.map +0 -1
  45. package/dist/context/TemplateEngine.js +0 -175
  46. package/dist/context/TemplateEngine.js.map +0 -1
  47. package/dist/context/context.d.ts +0 -8
  48. package/dist/context/context.d.ts.map +0 -1
  49. package/dist/context/context.js +0 -157
  50. package/dist/context/context.js.map +0 -1
  51. package/dist/context/contextCache.d.ts +0 -50
  52. package/dist/context/contextCache.d.ts.map +0 -1
  53. package/dist/context/contextCache.js +0 -175
  54. package/dist/context/contextCache.js.map +0 -1
  55. package/dist/context/index.d.ts +0 -11
  56. package/dist/context/index.d.ts.map +0 -1
  57. package/dist/context/index.js +0 -8
  58. package/dist/context/index.js.map +0 -1
  59. package/dist/credential-stores/CredentialStoreRegistry.d.ts +0 -39
  60. package/dist/credential-stores/CredentialStoreRegistry.d.ts.map +0 -1
  61. package/dist/credential-stores/CredentialStoreRegistry.js +0 -65
  62. package/dist/credential-stores/CredentialStoreRegistry.js.map +0 -1
  63. package/dist/credential-stores/defaults.d.ts +0 -6
  64. package/dist/credential-stores/defaults.d.ts.map +0 -1
  65. package/dist/credential-stores/defaults.js +0 -22
  66. package/dist/credential-stores/defaults.js.map +0 -1
  67. package/dist/credential-stores/index.d.ts +0 -6
  68. package/dist/credential-stores/index.d.ts.map +0 -1
  69. package/dist/credential-stores/index.js +0 -6
  70. package/dist/credential-stores/index.js.map +0 -1
  71. package/dist/credential-stores/keychain-store.d.ts +0 -100
  72. package/dist/credential-stores/keychain-store.d.ts.map +0 -1
  73. package/dist/credential-stores/keychain-store.js +0 -225
  74. package/dist/credential-stores/keychain-store.js.map +0 -1
  75. package/dist/credential-stores/memory-store.d.ts +0 -39
  76. package/dist/credential-stores/memory-store.d.ts.map +0 -1
  77. package/dist/credential-stores/memory-store.js +0 -58
  78. package/dist/credential-stores/memory-store.js.map +0 -1
  79. package/dist/credential-stores/nango-store.d.ts +0 -59
  80. package/dist/credential-stores/nango-store.d.ts.map +0 -1
  81. package/dist/credential-stores/nango-store.js +0 -264
  82. package/dist/credential-stores/nango-store.js.map +0 -1
  83. package/dist/credential-stuffer/CredentialStuffer.d.ts +0 -80
  84. package/dist/credential-stuffer/CredentialStuffer.d.ts.map +0 -1
  85. package/dist/credential-stuffer/CredentialStuffer.js +0 -186
  86. package/dist/credential-stuffer/CredentialStuffer.js.map +0 -1
  87. package/dist/credential-stuffer/index.d.ts +0 -2
  88. package/dist/credential-stuffer/index.d.ts.map +0 -1
  89. package/dist/credential-stuffer/index.js +0 -2
  90. package/dist/credential-stuffer/index.js.map +0 -1
  91. package/dist/data-access/agentDataComponents.d.ts +0 -1
  92. package/dist/data-access/agentDataComponents.d.ts.map +0 -1
  93. package/dist/data-access/agentDataComponents.js +0 -2
  94. package/dist/data-access/agentDataComponents.js.map +0 -1
  95. package/dist/data-access/agentGraphs.d.ts +0 -406
  96. package/dist/data-access/agentGraphs.d.ts.map +0 -1
  97. package/dist/data-access/agentGraphs.js +0 -551
  98. package/dist/data-access/agentGraphs.js.map +0 -1
  99. package/dist/data-access/agentRelations.d.ts +0 -456
  100. package/dist/data-access/agentRelations.d.ts.map +0 -1
  101. package/dist/data-access/agentRelations.js +0 -471
  102. package/dist/data-access/agentRelations.js.map +0 -1
  103. package/dist/data-access/agents.d.ts +0 -218
  104. package/dist/data-access/agents.d.ts.map +0 -1
  105. package/dist/data-access/agents.js +0 -130
  106. package/dist/data-access/agents.js.map +0 -1
  107. package/dist/data-access/apiKeys.d.ts +0 -114
  108. package/dist/data-access/apiKeys.d.ts.map +0 -1
  109. package/dist/data-access/apiKeys.js +0 -185
  110. package/dist/data-access/apiKeys.js.map +0 -1
  111. package/dist/data-access/artifactComponents.d.ts +0 -152
  112. package/dist/data-access/artifactComponents.d.ts.map +0 -1
  113. package/dist/data-access/artifactComponents.js +0 -214
  114. package/dist/data-access/artifactComponents.js.map +0 -1
  115. package/dist/data-access/contextCache.d.ts +0 -68
  116. package/dist/data-access/contextCache.d.ts.map +0 -1
  117. package/dist/data-access/contextCache.js +0 -160
  118. package/dist/data-access/contextCache.js.map +0 -1
  119. package/dist/data-access/contextConfigs.d.ts +0 -110
  120. package/dist/data-access/contextConfigs.d.ts.map +0 -1
  121. package/dist/data-access/contextConfigs.js +0 -156
  122. package/dist/data-access/contextConfigs.js.map +0 -1
  123. package/dist/data-access/conversations.d.ts +0 -125
  124. package/dist/data-access/conversations.d.ts.map +0 -1
  125. package/dist/data-access/conversations.js +0 -244
  126. package/dist/data-access/conversations.js.map +0 -1
  127. package/dist/data-access/credentialReferences.d.ts +0 -86
  128. package/dist/data-access/credentialReferences.d.ts.map +0 -1
  129. package/dist/data-access/credentialReferences.js +0 -175
  130. package/dist/data-access/credentialReferences.js.map +0 -1
  131. package/dist/data-access/dataComponents.d.ts +0 -129
  132. package/dist/data-access/dataComponents.d.ts.map +0 -1
  133. package/dist/data-access/dataComponents.js +0 -213
  134. package/dist/data-access/dataComponents.js.map +0 -1
  135. package/dist/data-access/externalAgents.d.ts +0 -83
  136. package/dist/data-access/externalAgents.d.ts.map +0 -1
  137. package/dist/data-access/externalAgents.js +0 -163
  138. package/dist/data-access/externalAgents.js.map +0 -1
  139. package/dist/data-access/graphFull.d.ts +0 -32
  140. package/dist/data-access/graphFull.d.ts.map +0 -1
  141. package/dist/data-access/graphFull.js +0 -996
  142. package/dist/data-access/graphFull.js.map +0 -1
  143. package/dist/data-access/index.d.ts +0 -21
  144. package/dist/data-access/index.d.ts.map +0 -1
  145. package/dist/data-access/index.js +0 -22
  146. package/dist/data-access/index.js.map +0 -1
  147. package/dist/data-access/ledgerArtifacts.d.ts +0 -49
  148. package/dist/data-access/ledgerArtifacts.d.ts.map +0 -1
  149. package/dist/data-access/ledgerArtifacts.js +0 -112
  150. package/dist/data-access/ledgerArtifacts.js.map +0 -1
  151. package/dist/data-access/messages.d.ts +0 -209
  152. package/dist/data-access/messages.d.ts.map +0 -1
  153. package/dist/data-access/messages.js +0 -100
  154. package/dist/data-access/messages.js.map +0 -1
  155. package/dist/data-access/projects.d.ts +0 -67
  156. package/dist/data-access/projects.d.ts.map +0 -1
  157. package/dist/data-access/projects.js +0 -337
  158. package/dist/data-access/projects.js.map +0 -1
  159. package/dist/data-access/tasks.d.ts +0 -37
  160. package/dist/data-access/tasks.d.ts.map +0 -1
  161. package/dist/data-access/tasks.js +0 -40
  162. package/dist/data-access/tasks.js.map +0 -1
  163. package/dist/data-access/tools.d.ts +0 -277
  164. package/dist/data-access/tools.d.ts.map +0 -1
  165. package/dist/data-access/tools.js +0 -183
  166. package/dist/data-access/tools.js.map +0 -1
  167. package/dist/data-access/validation.d.ts +0 -17
  168. package/dist/data-access/validation.d.ts.map +0 -1
  169. package/dist/data-access/validation.js +0 -52
  170. package/dist/data-access/validation.js.map +0 -1
  171. package/dist/db/clean.d.ts +0 -6
  172. package/dist/db/clean.d.ts.map +0 -1
  173. package/dist/db/clean.js +0 -81
  174. package/dist/db/clean.js.map +0 -1
  175. package/dist/db/client.d.ts +0 -19
  176. package/dist/db/client.d.ts.map +0 -1
  177. package/dist/db/client.js +0 -24
  178. package/dist/db/client.js.map +0 -1
  179. package/dist/db/schema.d.ts +0 -4337
  180. package/dist/db/schema.d.ts.map +0 -1
  181. package/dist/db/schema.js.map +0 -1
  182. package/dist/db/test-client.d.ts +0 -25
  183. package/dist/db/test-client.d.ts.map +0 -1
  184. package/dist/db/test-client.js +0 -136
  185. package/dist/db/test-client.js.map +0 -1
  186. package/dist/env.d.ts +0 -19
  187. package/dist/env.d.ts.map +0 -1
  188. package/dist/env.js +0 -49
  189. package/dist/env.js.map +0 -1
  190. package/dist/index.d.ts +0 -12
  191. package/dist/index.d.ts.map +0 -1
  192. package/dist/index.js.map +0 -1
  193. package/dist/middleware/contextValidation.d.ts +0 -49
  194. package/dist/middleware/contextValidation.d.ts.map +0 -1
  195. package/dist/middleware/contextValidation.js +0 -473
  196. package/dist/middleware/contextValidation.js.map +0 -1
  197. package/dist/middleware/index.d.ts +0 -2
  198. package/dist/middleware/index.d.ts.map +0 -1
  199. package/dist/middleware/index.js +0 -2
  200. package/dist/middleware/index.js.map +0 -1
  201. package/dist/server/BaseServer.d.ts +0 -83
  202. package/dist/server/BaseServer.d.ts.map +0 -1
  203. package/dist/server/BaseServer.js +0 -218
  204. package/dist/server/BaseServer.js.map +0 -1
  205. package/dist/types/a2a.d.ts +0 -373
  206. package/dist/types/a2a.d.ts.map +0 -1
  207. package/dist/types/a2a.js +0 -14
  208. package/dist/types/a2a.js.map +0 -1
  209. package/dist/types/entities.d.ts +0 -147
  210. package/dist/types/entities.d.ts.map +0 -1
  211. package/dist/types/entities.js +0 -2
  212. package/dist/types/entities.js.map +0 -1
  213. package/dist/types/index.d.ts +0 -5
  214. package/dist/types/index.d.ts.map +0 -1
  215. package/dist/types/index.js.map +0 -1
  216. package/dist/types/server.d.ts +0 -116
  217. package/dist/types/server.d.ts.map +0 -1
  218. package/dist/types/server.js +0 -2
  219. package/dist/types/server.js.map +0 -1
  220. package/dist/types/utility.d.ts +0 -213
  221. package/dist/types/utility.d.ts.map +0 -1
  222. package/dist/types/utility.js +0 -9
  223. package/dist/types/utility.js.map +0 -1
  224. package/dist/utils/apiKeys.d.ts +0 -32
  225. package/dist/utils/apiKeys.d.ts.map +0 -1
  226. package/dist/utils/apiKeys.js +0 -117
  227. package/dist/utils/apiKeys.js.map +0 -1
  228. package/dist/utils/auth-detection.d.ts +0 -23
  229. package/dist/utils/auth-detection.d.ts.map +0 -1
  230. package/dist/utils/auth-detection.js +0 -148
  231. package/dist/utils/auth-detection.js.map +0 -1
  232. package/dist/utils/credential-store-utils.d.ts +0 -11
  233. package/dist/utils/credential-store-utils.d.ts.map +0 -1
  234. package/dist/utils/credential-store-utils.js +0 -19
  235. package/dist/utils/credential-store-utils.js.map +0 -1
  236. package/dist/utils/error.d.ts +0 -526
  237. package/dist/utils/error.d.ts.map +0 -1
  238. package/dist/utils/error.js +0 -282
  239. package/dist/utils/error.js.map +0 -1
  240. package/dist/utils/execution.d.ts +0 -18
  241. package/dist/utils/execution.d.ts.map +0 -1
  242. package/dist/utils/execution.js +0 -25
  243. package/dist/utils/execution.js.map +0 -1
  244. package/dist/utils/index.d.ts +0 -9
  245. package/dist/utils/index.d.ts.map +0 -1
  246. package/dist/utils/index.js +0 -9
  247. package/dist/utils/index.js.map +0 -1
  248. package/dist/utils/logger.d.ts +0 -79
  249. package/dist/utils/logger.d.ts.map +0 -1
  250. package/dist/utils/logger.js +0 -102
  251. package/dist/utils/logger.js.map +0 -1
  252. package/dist/utils/logging.d.ts +0 -11
  253. package/dist/utils/logging.d.ts.map +0 -1
  254. package/dist/utils/logging.js +0 -6
  255. package/dist/utils/logging.js.map +0 -1
  256. package/dist/utils/mcp-client.d.ts +0 -48
  257. package/dist/utils/mcp-client.d.ts.map +0 -1
  258. package/dist/utils/mcp-client.js +0 -174
  259. package/dist/utils/mcp-client.js.map +0 -1
  260. package/dist/utils/tracer.d.ts +0 -24
  261. package/dist/utils/tracer.d.ts.map +0 -1
  262. package/dist/utils/tracer.js +0 -110
  263. package/dist/utils/tracer.js.map +0 -1
  264. package/dist/validation/graphFull.d.ts +0 -36
  265. package/dist/validation/graphFull.d.ts.map +0 -1
  266. package/dist/validation/graphFull.js +0 -128
  267. package/dist/validation/graphFull.js.map +0 -1
  268. package/dist/validation/id-validation.d.ts +0 -38
  269. package/dist/validation/id-validation.d.ts.map +0 -1
  270. package/dist/validation/id-validation.js +0 -60
  271. package/dist/validation/id-validation.js.map +0 -1
  272. package/dist/validation/index.d.ts +0 -4
  273. package/dist/validation/index.d.ts.map +0 -1
  274. package/dist/validation/index.js.map +0 -1
  275. package/dist/validation/schemas.d.ts +0 -7238
  276. package/dist/validation/schemas.d.ts.map +0 -1
  277. package/dist/validation/schemas.js +0 -575
  278. package/dist/validation/schemas.js.map +0 -1
@@ -0,0 +1,925 @@
1
+ import { __export } from './chunk-MKBO26DX.js';
2
+ import { relations, sql } from 'drizzle-orm';
3
+ import { sqliteTable, index, unique, text, primaryKey, blob, foreignKey, integer } from 'drizzle-orm/sqlite-core';
4
+
5
+ // src/db/schema.ts
6
+ var schema_exports = {};
7
+ __export(schema_exports, {
8
+ agentArtifactComponents: () => agentArtifactComponents,
9
+ agentArtifactComponentsRelations: () => agentArtifactComponentsRelations,
10
+ agentDataComponents: () => agentDataComponents,
11
+ agentGraph: () => agentGraph,
12
+ agentGraphRelations: () => agentGraphRelations,
13
+ agentRelations: () => agentRelations,
14
+ agentRelationsRelations: () => agentRelationsRelations,
15
+ agentToolRelations: () => agentToolRelations,
16
+ agentToolRelationsRelations: () => agentToolRelationsRelations,
17
+ agents: () => agents,
18
+ agentsRelations: () => agentsRelations,
19
+ apiKeys: () => apiKeys,
20
+ apiKeysRelations: () => apiKeysRelations,
21
+ artifactComponents: () => artifactComponents,
22
+ artifactComponentsRelations: () => artifactComponentsRelations,
23
+ contextCache: () => contextCache,
24
+ contextCacheRelations: () => contextCacheRelations,
25
+ contextConfigs: () => contextConfigs,
26
+ contextConfigsRelations: () => contextConfigsRelations,
27
+ conversations: () => conversations,
28
+ conversationsRelations: () => conversationsRelations,
29
+ credentialReferences: () => credentialReferences,
30
+ credentialReferencesRelations: () => credentialReferencesRelations,
31
+ dataComponents: () => dataComponents,
32
+ externalAgents: () => externalAgents,
33
+ externalAgentsRelations: () => externalAgentsRelations,
34
+ ledgerArtifacts: () => ledgerArtifacts,
35
+ ledgerArtifactsContextIdIdx: () => ledgerArtifactsContextIdIdx,
36
+ ledgerArtifactsTaskContextNameUnique: () => ledgerArtifactsTaskContextNameUnique,
37
+ ledgerArtifactsTaskIdIdx: () => ledgerArtifactsTaskIdIdx,
38
+ messages: () => messages,
39
+ messagesRelations: () => messagesRelations,
40
+ projects: () => projects,
41
+ projectsRelations: () => projectsRelations,
42
+ taskRelations: () => taskRelations,
43
+ taskRelationsRelations: () => taskRelationsRelations,
44
+ tasks: () => tasks,
45
+ tasksRelations: () => tasksRelations,
46
+ tools: () => tools,
47
+ toolsRelations: () => toolsRelations
48
+ });
49
+ var projects = sqliteTable(
50
+ "projects",
51
+ {
52
+ tenantId: text("tenant_id").notNull(),
53
+ id: text("id").notNull(),
54
+ // This IS the project ID
55
+ name: text("name").notNull(),
56
+ description: text("description").notNull(),
57
+ // Project-level default model settings that can be inherited by graphs and agents
58
+ models: text("models", { mode: "json" }).$type(),
59
+ // Project-level stopWhen configuration that can be inherited by graphs and agents
60
+ stopWhen: text("stop_when", { mode: "json" }).$type(),
61
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
62
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
63
+ },
64
+ (table) => [primaryKey({ columns: [table.tenantId, table.id] })]
65
+ );
66
+ var contextConfigs = sqliteTable(
67
+ "context_configs",
68
+ {
69
+ tenantId: text("tenant_id").notNull(),
70
+ projectId: text("project_id").notNull(),
71
+ id: text("id").notNull(),
72
+ name: text("name").notNull(),
73
+ description: text("description").notNull(),
74
+ // Developer-defined Zod schema for validating incoming request context
75
+ requestContextSchema: blob("request_context_schema", { mode: "json" }).$type(),
76
+ // Stores serialized Zod schema
77
+ // Object mapping template keys to fetch definitions that use request context data
78
+ contextVariables: blob("context_variables", { mode: "json" }).$type(),
79
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
80
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
81
+ },
82
+ (table) => [
83
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
84
+ foreignKey({
85
+ columns: [table.tenantId, table.projectId],
86
+ foreignColumns: [projects.tenantId, projects.id],
87
+ name: "context_configs_project_fk"
88
+ }).onDelete("cascade")
89
+ ]
90
+ );
91
+ var contextCache = sqliteTable(
92
+ "context_cache",
93
+ {
94
+ tenantId: text("tenant_id").notNull(),
95
+ projectId: text("project_id").notNull(),
96
+ id: text("id").notNull(),
97
+ // Always scoped to conversation for complete data isolation
98
+ conversationId: text("conversation_id").notNull(),
99
+ // Reference to the context config and specific fetch definition
100
+ contextConfigId: text("context_config_id").notNull(),
101
+ contextVariableKey: text("context_variable_key").notNull(),
102
+ // Key from contextVariables object
103
+ // The actual cached context data
104
+ value: blob("value", { mode: "json" }).$type().notNull(),
105
+ // Request hash for cache invalidation based on context changes
106
+ requestHash: text("request_hash"),
107
+ // Hash of request context that triggered this cache
108
+ // Metadata for monitoring and debugging
109
+ fetchedAt: text("fetched_at").notNull(),
110
+ fetchSource: text("fetch_source"),
111
+ // URL or source identifier
112
+ fetchDurationMs: integer("fetch_duration_ms"),
113
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
114
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
115
+ },
116
+ (table) => [
117
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
118
+ foreignKey({
119
+ columns: [table.tenantId, table.projectId],
120
+ foreignColumns: [projects.tenantId, projects.id],
121
+ name: "context_cache_project_fk"
122
+ }).onDelete("cascade"),
123
+ index("context_cache_lookup_idx").on(
124
+ table.conversationId,
125
+ table.contextConfigId,
126
+ table.contextVariableKey
127
+ )
128
+ ]
129
+ );
130
+ var agents = sqliteTable(
131
+ "agents",
132
+ {
133
+ tenantId: text("tenant_id").notNull(),
134
+ projectId: text("project_id").notNull(),
135
+ id: text("id").notNull(),
136
+ name: text("name").notNull(),
137
+ description: text("description").notNull(),
138
+ prompt: text("prompt").notNull(),
139
+ conversationHistoryConfig: text("conversation_history_config", {
140
+ mode: "json"
141
+ }).$type(),
142
+ models: text("models", { mode: "json" }).$type(),
143
+ // Agent-level stopWhen configuration (inherited from project)
144
+ stopWhen: text("stop_when", { mode: "json" }).$type(),
145
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
146
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
147
+ },
148
+ (table) => [
149
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
150
+ foreignKey({
151
+ columns: [table.tenantId, table.projectId],
152
+ foreignColumns: [projects.tenantId, projects.id],
153
+ name: "agents_project_fk"
154
+ }).onDelete("cascade")
155
+ ]
156
+ );
157
+ var agentRelations = sqliteTable(
158
+ "agent_relations",
159
+ {
160
+ tenantId: text("tenant_id").notNull(),
161
+ projectId: text("project_id").notNull(),
162
+ id: text("id").notNull(),
163
+ graphId: text("graph_id").notNull(),
164
+ sourceAgentId: text("source_agent_id").notNull(),
165
+ // For internal relationships
166
+ targetAgentId: text("target_agent_id"),
167
+ // For external relationships
168
+ externalAgentId: text("external_agent_id"),
169
+ relationType: text("relation_type"),
170
+ // 'transfer' | 'delegate'
171
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
172
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
173
+ },
174
+ (table) => [
175
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
176
+ foreignKey({
177
+ columns: [table.tenantId, table.projectId],
178
+ foreignColumns: [projects.tenantId, projects.id],
179
+ name: "agent_relations_project_fk"
180
+ }).onDelete("cascade")
181
+ ]
182
+ );
183
+ var externalAgents = sqliteTable(
184
+ "external_agents",
185
+ {
186
+ tenantId: text("tenant_id").notNull(),
187
+ projectId: text("project_id").notNull(),
188
+ id: text("id").notNull(),
189
+ name: text("name").notNull(),
190
+ description: text("description").notNull(),
191
+ baseUrl: text("base_url").notNull(),
192
+ // A2A endpoint URL
193
+ credentialReferenceId: text("credential_reference_id"),
194
+ headers: blob("headers", { mode: "json" }).$type(),
195
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
196
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
197
+ },
198
+ (table) => [
199
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
200
+ foreignKey({
201
+ columns: [table.tenantId, table.projectId],
202
+ foreignColumns: [projects.tenantId, projects.id],
203
+ name: "external_agents_project_fk"
204
+ }).onDelete("cascade"),
205
+ foreignKey({
206
+ columns: [table.tenantId, table.projectId, table.credentialReferenceId],
207
+ foreignColumns: [
208
+ credentialReferences.tenantId,
209
+ credentialReferences.projectId,
210
+ credentialReferences.id
211
+ ],
212
+ name: "external_agents_credential_reference_fk"
213
+ }).onDelete("set null")
214
+ ]
215
+ );
216
+ var agentGraph = sqliteTable(
217
+ "agent_graph",
218
+ {
219
+ tenantId: text("tenant_id").notNull(),
220
+ projectId: text("project_id").notNull(),
221
+ id: text("id").notNull(),
222
+ name: text("name").notNull(),
223
+ description: text("description"),
224
+ defaultAgentId: text("default_agent_id").notNull(),
225
+ // Reference to shared context configuration for all agents in this graph
226
+ contextConfigId: text("context_config_id"),
227
+ // Graph-level model settingsuration that can be inherited by agents
228
+ models: text("models", { mode: "json" }).$type(),
229
+ // Status updates configuration for intelligent progress summaries
230
+ statusUpdates: text("status_updates", { mode: "json" }).$type(),
231
+ // Graph-level prompt that can be used as additional context for agents
232
+ graphPrompt: text("graph_prompt"),
233
+ // Graph-level stopWhen configuration that can be inherited by agents
234
+ stopWhen: text("stop_when", { mode: "json" }).$type(),
235
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
236
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
237
+ },
238
+ (table) => [
239
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
240
+ foreignKey({
241
+ columns: [table.tenantId, table.projectId],
242
+ foreignColumns: [projects.tenantId, projects.id],
243
+ name: "agent_graph_project_fk"
244
+ }).onDelete("cascade")
245
+ ]
246
+ );
247
+ var tasks = sqliteTable(
248
+ "tasks",
249
+ {
250
+ tenantId: text("tenant_id").notNull(),
251
+ projectId: text("project_id").notNull(),
252
+ id: text("id").notNull(),
253
+ contextId: text("context_id").notNull(),
254
+ status: text("status").notNull(),
255
+ metadata: blob("metadata", { mode: "json" }).$type(),
256
+ agentId: text("agent_id").notNull(),
257
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
258
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
259
+ },
260
+ (table) => [
261
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
262
+ foreignKey({
263
+ columns: [table.tenantId, table.projectId],
264
+ foreignColumns: [projects.tenantId, projects.id],
265
+ name: "tasks_project_fk"
266
+ }).onDelete("cascade")
267
+ ]
268
+ );
269
+ var taskRelations = sqliteTable(
270
+ "task_relations",
271
+ {
272
+ tenantId: text("tenant_id").notNull(),
273
+ projectId: text("project_id").notNull(),
274
+ id: text("id").notNull(),
275
+ parentTaskId: text("parent_task_id").notNull(),
276
+ childTaskId: text("child_task_id").notNull(),
277
+ relationType: text("relation_type").default("parent_child"),
278
+ // Could be extended for other relation types
279
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
280
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
281
+ },
282
+ (table) => [
283
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
284
+ foreignKey({
285
+ columns: [table.tenantId, table.projectId],
286
+ foreignColumns: [projects.tenantId, projects.id],
287
+ name: "task_relations_project_fk"
288
+ }).onDelete("cascade")
289
+ ]
290
+ );
291
+ var dataComponents = sqliteTable(
292
+ "data_components",
293
+ {
294
+ tenantId: text("tenant_id").notNull(),
295
+ projectId: text("project_id").notNull(),
296
+ id: text("id").notNull(),
297
+ name: text("name").notNull(),
298
+ description: text("description").notNull(),
299
+ props: blob("props", { mode: "json" }).$type(),
300
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
301
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
302
+ },
303
+ (table) => [
304
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
305
+ foreignKey({
306
+ columns: [table.tenantId, table.projectId],
307
+ foreignColumns: [projects.tenantId, projects.id],
308
+ name: "data_components_project_fk"
309
+ }).onDelete("cascade")
310
+ ]
311
+ );
312
+ var agentDataComponents = sqliteTable(
313
+ "agent_data_components",
314
+ {
315
+ tenantId: text("tenant_id").notNull(),
316
+ projectId: text("project_id").notNull(),
317
+ id: text("id").notNull(),
318
+ agentId: text("agent_id").notNull(),
319
+ dataComponentId: text("data_component_id").notNull(),
320
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`)
321
+ },
322
+ (table) => [
323
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
324
+ // Foreign key constraint to projects table
325
+ foreignKey({
326
+ columns: [table.tenantId, table.projectId],
327
+ foreignColumns: [projects.tenantId, projects.id],
328
+ name: "agent_data_components_project_fk"
329
+ }).onDelete("cascade"),
330
+ // Foreign key constraint to agents table
331
+ foreignKey({
332
+ columns: [table.tenantId, table.projectId, table.agentId],
333
+ foreignColumns: [agents.tenantId, agents.projectId, agents.id],
334
+ name: "agent_data_components_agent_fk"
335
+ }).onDelete("cascade"),
336
+ // Foreign key constraint to data_components table
337
+ foreignKey({
338
+ columns: [table.tenantId, table.projectId, table.dataComponentId],
339
+ foreignColumns: [dataComponents.tenantId, dataComponents.projectId, dataComponents.id],
340
+ name: "agent_data_components_data_component_fk"
341
+ }).onDelete("cascade")
342
+ ]
343
+ );
344
+ var artifactComponents = sqliteTable(
345
+ "artifact_components",
346
+ {
347
+ tenantId: text("tenant_id").notNull(),
348
+ projectId: text("project_id").notNull(),
349
+ id: text("id").notNull(),
350
+ name: text("name").notNull(),
351
+ description: text("description").notNull(),
352
+ summaryProps: blob("summary_props", { mode: "json" }).$type(),
353
+ fullProps: blob("full_props", { mode: "json" }).$type(),
354
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
355
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
356
+ },
357
+ (table) => [
358
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
359
+ foreignKey({
360
+ columns: [table.tenantId, table.projectId],
361
+ foreignColumns: [projects.tenantId, projects.id],
362
+ name: "artifact_components_project_fk"
363
+ }).onDelete("cascade")
364
+ ]
365
+ );
366
+ var agentArtifactComponents = sqliteTable(
367
+ "agent_artifact_components",
368
+ {
369
+ tenantId: text("tenant_id").notNull(),
370
+ projectId: text("project_id").notNull(),
371
+ id: text("id").notNull(),
372
+ agentId: text("agent_id").notNull(),
373
+ artifactComponentId: text("artifact_component_id").notNull(),
374
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`)
375
+ },
376
+ (table) => [
377
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
378
+ // Foreign key constraint to projects table
379
+ foreignKey({
380
+ columns: [table.tenantId, table.projectId],
381
+ foreignColumns: [projects.tenantId, projects.id],
382
+ name: "agent_artifact_components_project_fk"
383
+ }).onDelete("cascade"),
384
+ // Foreign key constraint to agents table
385
+ foreignKey({
386
+ columns: [table.tenantId, table.projectId, table.agentId],
387
+ foreignColumns: [agents.tenantId, agents.projectId, agents.id],
388
+ name: "agent_artifact_components_agent_fk"
389
+ }).onDelete("cascade"),
390
+ // Foreign key constraint to artifact_components table
391
+ foreignKey({
392
+ columns: [table.tenantId, table.projectId, table.artifactComponentId],
393
+ foreignColumns: [
394
+ artifactComponents.tenantId,
395
+ artifactComponents.projectId,
396
+ artifactComponents.id
397
+ ],
398
+ name: "agent_artifact_components_artifact_component_fk"
399
+ }).onDelete("cascade")
400
+ ]
401
+ );
402
+ var tools = sqliteTable(
403
+ "tools",
404
+ {
405
+ tenantId: text("tenant_id").notNull(),
406
+ projectId: text("project_id").notNull(),
407
+ id: text("id").notNull(),
408
+ name: text("name").notNull(),
409
+ // Enhanced MCP configuration
410
+ config: blob("config", { mode: "json" }).$type().notNull(),
411
+ credentialReferenceId: text("credential_reference_id"),
412
+ headers: blob("headers", { mode: "json" }).$type(),
413
+ // Image URL for custom tool icon (supports regular URLs and base64 encoded images)
414
+ imageUrl: text("image_url"),
415
+ // Server capabilities and status
416
+ capabilities: blob("capabilities", { mode: "json" }).$type(),
417
+ // Connection health and monitoring
418
+ status: text("status").notNull().default("unknown"),
419
+ lastHealthCheck: text("last_health_check"),
420
+ lastError: text("last_error"),
421
+ // Tool discovery cache
422
+ availableTools: blob("available_tools", { mode: "json" }).$type(),
423
+ lastToolsSync: text("last_tools_sync"),
424
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
425
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
426
+ },
427
+ (table) => [
428
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
429
+ foreignKey({
430
+ columns: [table.tenantId, table.projectId],
431
+ foreignColumns: [projects.tenantId, projects.id],
432
+ name: "tools_project_fk"
433
+ }).onDelete("cascade")
434
+ ]
435
+ );
436
+ var agentToolRelations = sqliteTable(
437
+ "agent_tool_relations",
438
+ {
439
+ tenantId: text("tenant_id").notNull(),
440
+ projectId: text("project_id").notNull(),
441
+ id: text("id").notNull(),
442
+ agentId: text("agent_id").notNull(),
443
+ toolId: text("tool_id").notNull(),
444
+ selectedTools: blob("selected_tools", { mode: "json" }).$type(),
445
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
446
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
447
+ },
448
+ (table) => [
449
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
450
+ // Foreign key constraint to projects table
451
+ foreignKey({
452
+ columns: [table.tenantId, table.projectId],
453
+ foreignColumns: [projects.tenantId, projects.id],
454
+ name: "agent_tool_relations_project_fk"
455
+ }).onDelete("cascade"),
456
+ // Foreign key constraint to agents table
457
+ foreignKey({
458
+ columns: [table.tenantId, table.projectId, table.agentId],
459
+ foreignColumns: [agents.tenantId, agents.projectId, agents.id],
460
+ name: "agent_tool_relations_agent_fk"
461
+ }).onDelete("cascade"),
462
+ // Foreign key constraint to tools table
463
+ foreignKey({
464
+ columns: [table.tenantId, table.projectId, table.toolId],
465
+ foreignColumns: [tools.tenantId, tools.projectId, tools.id],
466
+ name: "agent_tool_relations_tool_fk"
467
+ }).onDelete("cascade")
468
+ ]
469
+ );
470
+ var conversations = sqliteTable(
471
+ "conversations",
472
+ {
473
+ tenantId: text("tenant_id").notNull(),
474
+ projectId: text("project_id").notNull(),
475
+ id: text("id").notNull(),
476
+ userId: text("user_id"),
477
+ activeAgentId: text("active_agent_id").notNull(),
478
+ title: text("title"),
479
+ lastContextResolution: text("last_context_resolution"),
480
+ metadata: blob("metadata", { mode: "json" }).$type(),
481
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
482
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
483
+ },
484
+ (table) => [
485
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
486
+ foreignKey({
487
+ columns: [table.tenantId, table.projectId],
488
+ foreignColumns: [projects.tenantId, projects.id],
489
+ name: "conversations_project_fk"
490
+ }).onDelete("cascade")
491
+ ]
492
+ );
493
+ var messages = sqliteTable(
494
+ "messages",
495
+ {
496
+ tenantId: text("tenant_id").notNull(),
497
+ projectId: text("project_id").notNull(),
498
+ id: text("id").notNull(),
499
+ conversationId: text("conversation_id").notNull(),
500
+ // Role mapping: user, agent, system (unified for both formats)
501
+ role: text("role").notNull(),
502
+ // 'user' | 'agent' | 'system'
503
+ // Agent sender/recipient tracking (nullable - only populated when relevant)
504
+ fromAgentId: text("from_agent_id"),
505
+ // Populated when message is from an agent
506
+ toAgentId: text("to_agent_id"),
507
+ // Populated when message is directed to a specific agent (e.g., transfers/delegations)
508
+ // External agent sender tracking
509
+ fromExternalAgentId: text("from_external_agent_id"),
510
+ // Populated when message is directed from an external agent
511
+ // External agent recipient tracking
512
+ toExternalAgentId: text("to_external_agent_id"),
513
+ // Populated when message is directed to an external agent
514
+ // Message content stored as JSON to support both formats
515
+ content: blob("content", { mode: "json" }).$type().notNull(),
516
+ // Message classification and filtering
517
+ visibility: text("visibility").notNull().default("user-facing"),
518
+ // 'user-facing' | 'internal' | 'system' | 'external'
519
+ messageType: text("message_type").notNull().default("chat"),
520
+ // 'chat' | 'a2a-request' | 'a2a-response' | 'task-update' | 'tool-call'
521
+ // Legacy agent association (consider deprecating in favor of fromAgentId/toAgentId)
522
+ agentId: text("agent_id"),
523
+ taskId: text("task_id"),
524
+ parentMessageId: text("parent_message_id"),
525
+ // Remove self-reference constraint here
526
+ // A2A specific fields
527
+ a2aTaskId: text("a2a_task_id"),
528
+ // Links to A2A task when relevant
529
+ a2aSessionId: text("a2a_session_id"),
530
+ // A2A session identifier
531
+ // Metadata for extensions
532
+ metadata: blob("metadata", { mode: "json" }).$type(),
533
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
534
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
535
+ },
536
+ (table) => [
537
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
538
+ foreignKey({
539
+ columns: [table.tenantId, table.projectId],
540
+ foreignColumns: [projects.tenantId, projects.id],
541
+ name: "messages_project_fk"
542
+ }).onDelete("cascade")
543
+ ]
544
+ );
545
+ var ledgerArtifacts = sqliteTable(
546
+ "ledger_artifacts",
547
+ {
548
+ // Primary identifier (maps to `artifactId`)
549
+ tenantId: text("tenant_id").notNull(),
550
+ projectId: text("project_id").notNull(),
551
+ id: text("id").notNull(),
552
+ // Links
553
+ taskId: text("task_id"),
554
+ contextId: text("context_id").notNull(),
555
+ // Core Artifact fields
556
+ type: text("type").notNull().default("source"),
557
+ name: text("name"),
558
+ description: text("description"),
559
+ parts: blob("parts", { mode: "json" }).$type(),
560
+ metadata: blob("metadata", { mode: "json" }).$type(),
561
+ // Extra ledger information (not part of the Artifact spec – kept optional)
562
+ summary: text("summary"),
563
+ mime: blob("mime", { mode: "json" }).$type(),
564
+ visibility: text("visibility").default("context"),
565
+ allowedAgents: blob("allowed_agents", { mode: "json" }).$type(),
566
+ derivedFrom: text("derived_from"),
567
+ // Timestamps
568
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
569
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
570
+ },
571
+ (table) => [
572
+ primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
573
+ foreignKey({
574
+ columns: [table.tenantId, table.projectId],
575
+ foreignColumns: [projects.tenantId, projects.id],
576
+ name: "ledger_artifacts_project_fk"
577
+ }).onDelete("cascade")
578
+ ]
579
+ );
580
+ var apiKeys = sqliteTable(
581
+ "api_keys",
582
+ {
583
+ id: text("id").primaryKey(),
584
+ tenantId: text("tenant_id").notNull(),
585
+ projectId: text("project_id").notNull(),
586
+ graphId: text("graph_id").notNull(),
587
+ publicId: text("public_id").notNull().unique(),
588
+ // Public ID for O(1) lookup (e.g., "abc123def456")
589
+ keyHash: text("key_hash").notNull(),
590
+ // Hashed API key (never store plaintext)
591
+ keyPrefix: text("key_prefix").notNull(),
592
+ // First 8 chars for identification (e.g., "sk_live_abc...")
593
+ lastUsedAt: text("last_used_at"),
594
+ expiresAt: text("expires_at"),
595
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
596
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
597
+ },
598
+ (t) => [
599
+ foreignKey({
600
+ columns: [t.tenantId, t.projectId],
601
+ foreignColumns: [projects.tenantId, projects.id],
602
+ name: "api_keys_project_fk"
603
+ }).onDelete("cascade"),
604
+ foreignKey({
605
+ columns: [t.tenantId, t.projectId, t.graphId],
606
+ foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
607
+ name: "api_keys_graph_fk"
608
+ }).onDelete("cascade"),
609
+ index("api_keys_tenant_graph_idx").on(t.tenantId, t.graphId),
610
+ index("api_keys_prefix_idx").on(t.keyPrefix),
611
+ index("api_keys_public_id_idx").on(t.publicId)
612
+ ]
613
+ );
614
+ var credentialReferences = sqliteTable(
615
+ "credential_references",
616
+ {
617
+ tenantId: text("tenant_id").notNull(),
618
+ projectId: text("project_id").notNull(),
619
+ id: text("id").notNull(),
620
+ type: text("type").notNull(),
621
+ // Implementation type: 'keychain', 'nango', 'memory', etc.
622
+ credentialStoreId: text("credential_store_id").notNull(),
623
+ // Maps to framework.getCredentialStore(id)
624
+ retrievalParams: blob("retrieval_params", { mode: "json" }).$type(),
625
+ createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
626
+ updatedAt: text("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`)
627
+ },
628
+ (t) => [
629
+ primaryKey({ columns: [t.tenantId, t.projectId, t.id] }),
630
+ foreignKey({
631
+ columns: [t.tenantId, t.projectId],
632
+ foreignColumns: [projects.tenantId, projects.id],
633
+ name: "credential_references_project_fk"
634
+ }).onDelete("cascade")
635
+ ]
636
+ );
637
+ var ledgerArtifactsTaskIdIdx = index("ledger_artifacts_task_id_idx").on(
638
+ ledgerArtifacts.taskId
639
+ );
640
+ var ledgerArtifactsContextIdIdx = index("ledger_artifacts_context_id_idx").on(
641
+ ledgerArtifacts.contextId
642
+ );
643
+ var ledgerArtifactsTaskContextNameUnique = unique(
644
+ "ledger_artifacts_task_context_name_unique"
645
+ ).on(ledgerArtifacts.taskId, ledgerArtifacts.contextId, ledgerArtifacts.name);
646
+ var tasksRelations = relations(tasks, ({ one, many }) => ({
647
+ // A task belongs to one project
648
+ project: one(projects, {
649
+ fields: [tasks.tenantId, tasks.projectId],
650
+ references: [projects.tenantId, projects.id]
651
+ }),
652
+ // A task can have many parent relationships (where it's the child)
653
+ parentRelations: many(taskRelations, {
654
+ relationName: "childTask"
655
+ }),
656
+ // A task can have many child relationships (where it's the parent)
657
+ childRelations: many(taskRelations, {
658
+ relationName: "parentTask"
659
+ }),
660
+ // A task belongs to one agent
661
+ agent: one(agents, {
662
+ fields: [tasks.agentId],
663
+ references: [agents.id]
664
+ }),
665
+ // A task can have many messages associated with it
666
+ messages: many(messages)
667
+ }));
668
+ var projectsRelations = relations(projects, ({ many }) => ({
669
+ // A project can have many agents
670
+ agents: many(agents),
671
+ // A project can have many agent graphs
672
+ agentGraphs: many(agentGraph),
673
+ // A project can have many tools
674
+ tools: many(tools),
675
+ // A project can have many context configs
676
+ contextConfigs: many(contextConfigs),
677
+ // A project can have many external agents
678
+ externalAgents: many(externalAgents),
679
+ // A project can have many conversations
680
+ conversations: many(conversations),
681
+ // A project can have many tasks
682
+ tasks: many(tasks)
683
+ }));
684
+ var taskRelationsRelations = relations(taskRelations, ({ one }) => ({
685
+ // Each relation has one parent task
686
+ parentTask: one(tasks, {
687
+ fields: [taskRelations.parentTaskId],
688
+ references: [tasks.id],
689
+ relationName: "parentTask"
690
+ }),
691
+ // Each relation has one child task
692
+ childTask: one(tasks, {
693
+ fields: [taskRelations.childTaskId],
694
+ references: [tasks.id],
695
+ relationName: "childTask"
696
+ })
697
+ }));
698
+ var contextConfigsRelations = relations(contextConfigs, ({ many, one }) => ({
699
+ // A context config belongs to one project
700
+ project: one(projects, {
701
+ fields: [contextConfigs.tenantId, contextConfigs.projectId],
702
+ references: [projects.tenantId, projects.id]
703
+ }),
704
+ // A context config can be used by many agent graphs
705
+ graphs: many(agentGraph),
706
+ // A context config can have many cached entries
707
+ cache: many(contextCache)
708
+ }));
709
+ var contextCacheRelations = relations(contextCache, ({ one }) => ({
710
+ // Each cache entry belongs to one context config
711
+ contextConfig: one(contextConfigs, {
712
+ fields: [contextCache.contextConfigId],
713
+ references: [contextConfigs.id]
714
+ })
715
+ }));
716
+ var agentsRelations = relations(agents, ({ many, one }) => ({
717
+ // A context config belongs to one project
718
+ project: one(projects, {
719
+ fields: [agents.tenantId, agents.projectId],
720
+ references: [projects.tenantId, projects.id]
721
+ }),
722
+ // An agent can have many tasks
723
+ tasks: many(tasks),
724
+ // An agent can be the default agent for many graphs
725
+ defaultForGraphs: many(agentGraph),
726
+ // Agent relation tracking
727
+ sourceRelations: many(agentRelations, {
728
+ relationName: "sourceRelations"
729
+ }),
730
+ targetRelations: many(agentRelations, {
731
+ relationName: "targetRelations"
732
+ }),
733
+ // Message tracking relations
734
+ sentMessages: many(messages, {
735
+ relationName: "sentMessages"
736
+ }),
737
+ receivedMessages: many(messages, {
738
+ relationName: "receivedMessages"
739
+ }),
740
+ // Legacy message association (consider deprecating)
741
+ associatedMessages: many(messages, {
742
+ relationName: "associatedAgent"
743
+ }),
744
+ toolRelations: many(agentToolRelations)
745
+ }));
746
+ var agentGraphRelations = relations(agentGraph, ({ one }) => ({
747
+ // An agent graph belongs to one project
748
+ project: one(projects, {
749
+ fields: [agentGraph.tenantId, agentGraph.projectId],
750
+ references: [projects.tenantId, projects.id]
751
+ }),
752
+ // An agent graph belongs to one default agent
753
+ defaultAgent: one(agents, {
754
+ fields: [agentGraph.defaultAgentId],
755
+ references: [agents.id]
756
+ }),
757
+ // An agent graph can reference one context config
758
+ contextConfig: one(contextConfigs, {
759
+ fields: [agentGraph.contextConfigId],
760
+ references: [contextConfigs.id]
761
+ })
762
+ }));
763
+ var externalAgentsRelations = relations(externalAgents, ({ one, many }) => ({
764
+ // An external agent belongs to one project
765
+ project: one(projects, {
766
+ fields: [externalAgents.tenantId, externalAgents.projectId],
767
+ references: [projects.tenantId, projects.id]
768
+ }),
769
+ // An external agent can be referenced by many agent relations
770
+ agentRelations: many(agentRelations),
771
+ // An external agent may have one credential reference
772
+ credentialReference: one(credentialReferences, {
773
+ fields: [externalAgents.credentialReferenceId],
774
+ references: [credentialReferences.id]
775
+ })
776
+ }));
777
+ var apiKeysRelations = relations(apiKeys, ({ one }) => ({
778
+ // An API key belongs to one project
779
+ project: one(projects, {
780
+ fields: [apiKeys.tenantId, apiKeys.projectId],
781
+ references: [projects.tenantId, projects.id]
782
+ }),
783
+ // An API key belongs to one tenant and graph
784
+ graph: one(agentGraph, {
785
+ fields: [apiKeys.graphId],
786
+ references: [agentGraph.id]
787
+ })
788
+ }));
789
+ var agentToolRelationsRelations = relations(agentToolRelations, ({ one }) => ({
790
+ // An agent-tool relation belongs to one agent
791
+ agent: one(agents, {
792
+ fields: [agentToolRelations.agentId],
793
+ references: [agents.id]
794
+ }),
795
+ // An agent-tool relation belongs to one tool
796
+ tool: one(tools, {
797
+ fields: [agentToolRelations.toolId],
798
+ references: [tools.id]
799
+ })
800
+ }));
801
+ var credentialReferencesRelations = relations(credentialReferences, ({ many }) => ({
802
+ tools: many(tools)
803
+ }));
804
+ var toolsRelations = relations(tools, ({ one, many }) => ({
805
+ // A tool belongs to one project
806
+ project: one(projects, {
807
+ fields: [tools.tenantId, tools.projectId],
808
+ references: [projects.tenantId, projects.id]
809
+ }),
810
+ // A tool can be used by many agents through agent-tool relations
811
+ agentRelations: many(agentToolRelations),
812
+ // A tool may have one credential reference
813
+ credentialReference: one(credentialReferences, {
814
+ fields: [tools.credentialReferenceId],
815
+ references: [credentialReferences.id]
816
+ })
817
+ }));
818
+ var conversationsRelations = relations(conversations, ({ one, many }) => ({
819
+ // A conversation belongs to one project
820
+ project: one(projects, {
821
+ fields: [conversations.tenantId, conversations.projectId],
822
+ references: [projects.tenantId, projects.id]
823
+ }),
824
+ // A conversation has many messages
825
+ messages: many(messages),
826
+ // A conversation has one active agent
827
+ activeAgent: one(agents, {
828
+ fields: [conversations.activeAgentId],
829
+ references: [agents.id]
830
+ })
831
+ }));
832
+ var messagesRelations = relations(messages, ({ one, many }) => ({
833
+ // A message belongs to one conversation
834
+ conversation: one(conversations, {
835
+ fields: [messages.conversationId],
836
+ references: [conversations.id]
837
+ }),
838
+ // Legacy agent association (consider deprecating)
839
+ agent: one(agents, {
840
+ fields: [messages.agentId],
841
+ references: [agents.id],
842
+ relationName: "associatedAgent"
843
+ }),
844
+ // Sender tracking relations
845
+ fromAgent: one(agents, {
846
+ fields: [messages.fromAgentId],
847
+ references: [agents.id],
848
+ relationName: "sentMessages"
849
+ }),
850
+ // Recipient tracking relations
851
+ toAgent: one(agents, {
852
+ fields: [messages.toAgentId],
853
+ references: [agents.id],
854
+ relationName: "receivedMessages"
855
+ }),
856
+ // External agent sender tracking relations
857
+ fromExternalAgent: one(externalAgents, {
858
+ fields: [messages.fromExternalAgentId],
859
+ references: [externalAgents.id],
860
+ relationName: "receivedExternalMessages"
861
+ }),
862
+ // External agent recipient tracking relations
863
+ toExternalAgent: one(externalAgents, {
864
+ fields: [messages.toExternalAgentId],
865
+ references: [externalAgents.id],
866
+ relationName: "sentExternalMessages"
867
+ }),
868
+ // A message may be associated with a task
869
+ task: one(tasks, {
870
+ fields: [messages.taskId],
871
+ references: [tasks.id]
872
+ }),
873
+ // A message may have a parent message (for threading)
874
+ parentMessage: one(messages, {
875
+ fields: [messages.parentMessageId],
876
+ references: [messages.id],
877
+ relationName: "parentChild"
878
+ }),
879
+ // A message may have child messages
880
+ childMessages: many(messages, {
881
+ relationName: "parentChild"
882
+ })
883
+ }));
884
+ var artifactComponentsRelations = relations(artifactComponents, ({ many }) => ({
885
+ // An artifact component can be associated with many agents
886
+ agentRelations: many(agentArtifactComponents)
887
+ }));
888
+ var agentArtifactComponentsRelations = relations(agentArtifactComponents, ({ one }) => ({
889
+ // An agent-artifact component relation belongs to one agent
890
+ agent: one(agents, {
891
+ fields: [agentArtifactComponents.agentId],
892
+ references: [agents.id]
893
+ }),
894
+ // An agent-artifact component relation belongs to one artifact component
895
+ artifactComponent: one(artifactComponents, {
896
+ fields: [agentArtifactComponents.artifactComponentId],
897
+ references: [artifactComponents.id]
898
+ })
899
+ }));
900
+ var agentRelationsRelations = relations(agentRelations, ({ one }) => ({
901
+ // An agent relation belongs to one graph
902
+ graph: one(agentGraph, {
903
+ fields: [agentRelations.graphId],
904
+ references: [agentGraph.id]
905
+ }),
906
+ // An agent relation has one source agent
907
+ sourceAgent: one(agents, {
908
+ fields: [agentRelations.sourceAgentId],
909
+ references: [agents.id],
910
+ relationName: "sourceRelations"
911
+ }),
912
+ // An agent relation may have one target agent (for internal relations)
913
+ targetAgent: one(agents, {
914
+ fields: [agentRelations.targetAgentId],
915
+ references: [agents.id],
916
+ relationName: "targetRelations"
917
+ }),
918
+ // An agent relation may have one external agent (for external relations)
919
+ externalAgent: one(externalAgents, {
920
+ fields: [agentRelations.externalAgentId],
921
+ references: [externalAgents.id]
922
+ })
923
+ }));
924
+
925
+ export { agentArtifactComponents, agentArtifactComponentsRelations, agentDataComponents, agentGraph, agentGraphRelations, agentRelations, agentRelationsRelations, agentToolRelations, agentToolRelationsRelations, agents, agentsRelations, apiKeys, apiKeysRelations, artifactComponents, artifactComponentsRelations, contextCache, contextCacheRelations, contextConfigs, contextConfigsRelations, conversations, conversationsRelations, credentialReferences, credentialReferencesRelations, dataComponents, externalAgents, externalAgentsRelations, ledgerArtifacts, ledgerArtifactsContextIdIdx, ledgerArtifactsTaskContextNameUnique, ledgerArtifactsTaskIdIdx, messages, messagesRelations, projects, projectsRelations, schema_exports, taskRelations, taskRelationsRelations, tasks, tasksRelations, tools, toolsRelations };