@intelligo-dev/core 1.0.0-beta.1 → 1.0.0-beta.13

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 (355) hide show
  1. package/NOTICE +6 -0
  2. package/README.md +102 -0
  3. package/dist/attachments/errors.d.ts +7 -0
  4. package/dist/attachments/errors.d.ts.map +1 -0
  5. package/dist/attachments/errors.js +11 -0
  6. package/dist/attachments/errors.js.map +1 -0
  7. package/dist/attachments/index.d.ts +8 -0
  8. package/dist/attachments/index.d.ts.map +1 -0
  9. package/dist/attachments/index.js +7 -0
  10. package/dist/attachments/index.js.map +1 -0
  11. package/dist/attachments/service.d.ts +45 -0
  12. package/dist/attachments/service.d.ts.map +1 -0
  13. package/dist/attachments/service.js +100 -0
  14. package/dist/attachments/service.js.map +1 -0
  15. package/dist/attachments/types.d.ts +6 -0
  16. package/dist/attachments/types.d.ts.map +1 -0
  17. package/dist/attachments/types.js +2 -0
  18. package/dist/attachments/types.js.map +1 -0
  19. package/dist/conversations/errors.d.ts +2 -8
  20. package/dist/conversations/errors.d.ts.map +1 -1
  21. package/dist/conversations/errors.js +2 -8
  22. package/dist/conversations/errors.js.map +1 -1
  23. package/dist/conversations/index.d.ts +4 -12
  24. package/dist/conversations/index.d.ts.map +1 -1
  25. package/dist/conversations/index.js +2 -11
  26. package/dist/conversations/index.js.map +1 -1
  27. package/dist/conversations/service.d.ts +49 -61
  28. package/dist/conversations/service.d.ts.map +1 -1
  29. package/dist/conversations/service.js +110 -83
  30. package/dist/conversations/service.js.map +1 -1
  31. package/dist/conversations/types.d.ts +1 -4
  32. package/dist/conversations/types.d.ts.map +1 -1
  33. package/dist/conversations/types.js +0 -3
  34. package/dist/conversations/types.js.map +1 -1
  35. package/dist/db/client.d.ts +21 -10
  36. package/dist/db/client.d.ts.map +1 -1
  37. package/dist/db/client.js +43 -18
  38. package/dist/db/client.js.map +1 -1
  39. package/dist/db/index.d.ts +3 -3
  40. package/dist/db/index.d.ts.map +1 -1
  41. package/dist/db/index.js +3 -7
  42. package/dist/db/index.js.map +1 -1
  43. package/dist/db/schema/agents.d.ts +14 -51
  44. package/dist/db/schema/agents.d.ts.map +1 -1
  45. package/dist/db/schema/agents.js +9 -21
  46. package/dist/db/schema/agents.js.map +1 -1
  47. package/dist/db/schema/ai.d.ts +86 -1556
  48. package/dist/db/schema/ai.d.ts.map +1 -1
  49. package/dist/db/schema/ai.js +32 -236
  50. package/dist/db/schema/ai.js.map +1 -1
  51. package/dist/db/schema/auth.d.ts +5 -34
  52. package/dist/db/schema/auth.d.ts.map +1 -1
  53. package/dist/db/schema/auth.js +25 -56
  54. package/dist/db/schema/auth.js.map +1 -1
  55. package/dist/db/schema/billing.d.ts +136 -107
  56. package/dist/db/schema/billing.d.ts.map +1 -1
  57. package/dist/db/schema/billing.js +72 -60
  58. package/dist/db/schema/billing.js.map +1 -1
  59. package/dist/db/schema/feature-flags.d.ts +3 -12
  60. package/dist/db/schema/feature-flags.d.ts.map +1 -1
  61. package/dist/db/schema/feature-flags.js +3 -12
  62. package/dist/db/schema/feature-flags.js.map +1 -1
  63. package/dist/db/schema/identity.d.ts +12 -274
  64. package/dist/db/schema/identity.d.ts.map +1 -1
  65. package/dist/db/schema/identity.js +19 -104
  66. package/dist/db/schema/identity.js.map +1 -1
  67. package/dist/db/schema/index.d.ts +8 -15
  68. package/dist/db/schema/index.d.ts.map +1 -1
  69. package/dist/db/schema/index.js +12 -42
  70. package/dist/db/schema/index.js.map +1 -1
  71. package/dist/db/schema/notifications.d.ts +3 -17
  72. package/dist/db/schema/notifications.d.ts.map +1 -1
  73. package/dist/db/schema/notifications.js +3 -17
  74. package/dist/db/schema/notifications.js.map +1 -1
  75. package/dist/db/schema/usage.d.ts +94 -77
  76. package/dist/db/schema/usage.d.ts.map +1 -1
  77. package/dist/db/schema/usage.js +59 -89
  78. package/dist/db/schema/usage.js.map +1 -1
  79. package/dist/db/validate.d.ts +2 -11
  80. package/dist/db/validate.d.ts.map +1 -1
  81. package/dist/db/validate.js +6 -17
  82. package/dist/db/validate.js.map +1 -1
  83. package/dist/db/workspace-queries.d.ts +5 -29
  84. package/dist/db/workspace-queries.d.ts.map +1 -1
  85. package/dist/db/workspace-queries.js +5 -29
  86. package/dist/db/workspace-queries.js.map +1 -1
  87. package/dist/documents/classifier.d.ts +5 -12
  88. package/dist/documents/classifier.d.ts.map +1 -1
  89. package/dist/documents/classifier.js +16 -16
  90. package/dist/documents/classifier.js.map +1 -1
  91. package/dist/documents/errors.d.ts +2 -10
  92. package/dist/documents/errors.d.ts.map +1 -1
  93. package/dist/documents/errors.js +2 -10
  94. package/dist/documents/errors.js.map +1 -1
  95. package/dist/documents/index.d.ts +4 -13
  96. package/dist/documents/index.d.ts.map +1 -1
  97. package/dist/documents/index.js +3 -12
  98. package/dist/documents/index.js.map +1 -1
  99. package/dist/documents/service.d.ts +19 -26
  100. package/dist/documents/service.d.ts.map +1 -1
  101. package/dist/documents/service.js +44 -38
  102. package/dist/documents/service.js.map +1 -1
  103. package/dist/documents/types.d.ts +6 -10
  104. package/dist/documents/types.d.ts.map +1 -1
  105. package/dist/documents/types.js +0 -3
  106. package/dist/documents/types.js.map +1 -1
  107. package/dist/email/brand.d.ts +17 -0
  108. package/dist/email/brand.d.ts.map +1 -0
  109. package/dist/email/brand.js +9 -0
  110. package/dist/email/brand.js.map +1 -0
  111. package/dist/email/index.d.ts +4 -4
  112. package/dist/email/index.js +4 -4
  113. package/dist/email/provider.d.ts +1 -7
  114. package/dist/email/provider.d.ts.map +1 -1
  115. package/dist/email/provider.js +10 -19
  116. package/dist/email/provider.js.map +1 -1
  117. package/dist/email/send.d.ts +12 -12
  118. package/dist/email/send.d.ts.map +1 -1
  119. package/dist/email/send.js +5 -19
  120. package/dist/email/send.js.map +1 -1
  121. package/dist/email/senders.d.ts +17 -30
  122. package/dist/email/senders.d.ts.map +1 -1
  123. package/dist/email/senders.js +33 -47
  124. package/dist/email/senders.js.map +1 -1
  125. package/dist/email/templates/base-layout.d.ts +1 -1
  126. package/dist/email/templates/base-layout.d.ts.map +1 -1
  127. package/dist/email/templates/base-layout.js +4 -6
  128. package/dist/email/templates/base-layout.js.map +1 -1
  129. package/dist/email/templates/index.d.ts +10 -10
  130. package/dist/email/templates/index.d.ts.map +1 -1
  131. package/dist/email/templates/index.js +10 -16
  132. package/dist/email/templates/index.js.map +1 -1
  133. package/dist/email/templates/password-reset.d.ts +2 -2
  134. package/dist/email/templates/password-reset.d.ts.map +1 -1
  135. package/dist/email/templates/password-reset.js +10 -22
  136. package/dist/email/templates/password-reset.js.map +1 -1
  137. package/dist/email/templates/payment-failed.d.ts +2 -2
  138. package/dist/email/templates/payment-failed.d.ts.map +1 -1
  139. package/dist/email/templates/payment-failed.js +11 -24
  140. package/dist/email/templates/payment-failed.js.map +1 -1
  141. package/dist/email/templates/quota-warning.d.ts +4 -4
  142. package/dist/email/templates/quota-warning.d.ts.map +1 -1
  143. package/dist/email/templates/quota-warning.js +19 -39
  144. package/dist/email/templates/quota-warning.js.map +1 -1
  145. package/dist/email/templates/subscription-confirmed.d.ts +2 -2
  146. package/dist/email/templates/subscription-confirmed.d.ts.map +1 -1
  147. package/dist/email/templates/subscription-confirmed.js +13 -28
  148. package/dist/email/templates/subscription-confirmed.js.map +1 -1
  149. package/dist/email/templates/trial-expiry.d.ts +2 -2
  150. package/dist/email/templates/trial-expiry.d.ts.map +1 -1
  151. package/dist/email/templates/trial-expiry.js +12 -36
  152. package/dist/email/templates/trial-expiry.js.map +1 -1
  153. package/dist/email/templates/trial-warning.d.ts +2 -2
  154. package/dist/email/templates/trial-warning.d.ts.map +1 -1
  155. package/dist/email/templates/trial-warning.js +15 -32
  156. package/dist/email/templates/trial-warning.js.map +1 -1
  157. package/dist/email/templates/verify-email.d.ts +2 -2
  158. package/dist/email/templates/verify-email.d.ts.map +1 -1
  159. package/dist/email/templates/verify-email.js +10 -22
  160. package/dist/email/templates/verify-email.js.map +1 -1
  161. package/dist/email/templates/welcome.d.ts +2 -2
  162. package/dist/email/templates/welcome.d.ts.map +1 -1
  163. package/dist/email/templates/welcome.js +13 -20
  164. package/dist/email/templates/welcome.js.map +1 -1
  165. package/dist/email/templates/workspace-invitation.d.ts +2 -2
  166. package/dist/email/templates/workspace-invitation.d.ts.map +1 -1
  167. package/dist/email/templates/workspace-invitation.js +12 -26
  168. package/dist/email/templates/workspace-invitation.js.map +1 -1
  169. package/dist/env.d.ts +5 -10
  170. package/dist/env.d.ts.map +1 -1
  171. package/dist/env.js +41 -31
  172. package/dist/env.js.map +1 -1
  173. package/dist/identity/audit.d.ts +11 -24
  174. package/dist/identity/audit.d.ts.map +1 -1
  175. package/dist/identity/audit.js +13 -27
  176. package/dist/identity/audit.js.map +1 -1
  177. package/dist/identity/errors.d.ts +4 -12
  178. package/dist/identity/errors.d.ts.map +1 -1
  179. package/dist/identity/errors.js +2 -8
  180. package/dist/identity/errors.js.map +1 -1
  181. package/dist/identity/index.d.ts +5 -13
  182. package/dist/identity/index.d.ts.map +1 -1
  183. package/dist/identity/index.js +4 -12
  184. package/dist/identity/index.js.map +1 -1
  185. package/dist/identity/service.d.ts +13 -47
  186. package/dist/identity/service.d.ts.map +1 -1
  187. package/dist/identity/service.js +31 -78
  188. package/dist/identity/service.js.map +1 -1
  189. package/dist/identity/types.d.ts +1 -4
  190. package/dist/identity/types.d.ts.map +1 -1
  191. package/dist/identity/types.js +0 -3
  192. package/dist/identity/types.js.map +1 -1
  193. package/dist/index.d.ts +1 -2
  194. package/dist/index.d.ts.map +1 -1
  195. package/dist/index.js +3 -10
  196. package/dist/index.js.map +1 -1
  197. package/dist/logger.d.ts +7 -18
  198. package/dist/logger.d.ts.map +1 -1
  199. package/dist/logger.js +45 -49
  200. package/dist/logger.js.map +1 -1
  201. package/dist/money.d.ts +95 -0
  202. package/dist/money.d.ts.map +1 -0
  203. package/dist/money.js +208 -0
  204. package/dist/money.js.map +1 -0
  205. package/dist/notifications/index.d.ts +9 -43
  206. package/dist/notifications/index.d.ts.map +1 -1
  207. package/dist/notifications/index.js +9 -49
  208. package/dist/notifications/index.js.map +1 -1
  209. package/dist/notifications/triggers.d.ts +9 -32
  210. package/dist/notifications/triggers.d.ts.map +1 -1
  211. package/dist/notifications/triggers.js +21 -58
  212. package/dist/notifications/triggers.js.map +1 -1
  213. package/dist/notifications/types.d.ts +1 -10
  214. package/dist/notifications/types.d.ts.map +1 -1
  215. package/dist/notifications/types.js +0 -9
  216. package/dist/notifications/types.js.map +1 -1
  217. package/dist/prompt.d.ts +38 -0
  218. package/dist/prompt.d.ts.map +1 -0
  219. package/dist/prompt.js +118 -0
  220. package/dist/prompt.js.map +1 -0
  221. package/dist/registry.d.ts +32 -0
  222. package/dist/registry.d.ts.map +1 -0
  223. package/dist/registry.js +60 -0
  224. package/dist/registry.js.map +1 -0
  225. package/dist/request-context.d.ts +49 -0
  226. package/dist/request-context.d.ts.map +1 -0
  227. package/dist/request-context.js +100 -0
  228. package/dist/request-context.js.map +1 -0
  229. package/dist/storage/index.d.ts +65 -0
  230. package/dist/storage/index.d.ts.map +1 -0
  231. package/dist/storage/index.js +109 -0
  232. package/dist/storage/index.js.map +1 -0
  233. package/package.json +74 -24
  234. package/src/attachments/errors.ts +18 -0
  235. package/src/attachments/index.ts +22 -0
  236. package/src/attachments/service.ts +178 -0
  237. package/src/attachments/types.ts +6 -0
  238. package/src/conversations/errors.ts +45 -0
  239. package/src/conversations/index.ts +39 -0
  240. package/src/conversations/service.ts +594 -0
  241. package/src/conversations/types.ts +15 -0
  242. package/src/db/client.ts +91 -0
  243. package/src/db/index.ts +3 -0
  244. package/src/db/migrations/0000_baseline.sql +652 -0
  245. package/src/db/migrations/0001_reconcile_chain_built_databases.sql +53 -0
  246. package/src/db/migrations/0002_webhook_claim_lease.sql +1 -0
  247. package/src/db/migrations/README.md +74 -36
  248. package/src/db/migrations/legacy-chain.json +197 -0
  249. package/src/db/migrations/meta/0000_snapshot.json +4182 -157
  250. package/src/db/migrations/meta/0002_snapshot.json +2478 -368
  251. package/src/db/migrations/meta/_journal.json +6 -279
  252. package/src/db/schema/agents.ts +57 -0
  253. package/src/db/schema/ai.ts +174 -0
  254. package/src/db/schema/auth.ts +183 -0
  255. package/src/db/schema/billing.ts +209 -0
  256. package/src/db/schema/feature-flags.ts +20 -0
  257. package/src/db/schema/identity.ts +250 -0
  258. package/src/db/schema/index.ts +12 -0
  259. package/src/db/schema/notifications.ts +31 -0
  260. package/src/db/schema/usage.ts +269 -0
  261. package/src/db/validate.ts +63 -0
  262. package/src/db/workspace-queries.ts +64 -0
  263. package/src/documents/classifier.ts +61 -0
  264. package/src/documents/errors.ts +44 -0
  265. package/src/documents/index.ts +24 -0
  266. package/src/documents/service.ts +256 -0
  267. package/src/documents/types.ts +24 -0
  268. package/src/email/brand.ts +24 -0
  269. package/src/email/index.ts +19 -0
  270. package/src/email/provider.ts +278 -0
  271. package/src/email/send.ts +169 -0
  272. package/src/email/senders.ts +292 -0
  273. package/src/email/templates/base-layout.tsx +145 -0
  274. package/src/email/templates/index.ts +28 -0
  275. package/src/email/templates/password-reset.tsx +72 -0
  276. package/src/email/templates/payment-failed.tsx +77 -0
  277. package/src/email/templates/quota-warning.tsx +118 -0
  278. package/src/email/templates/subscription-confirmed.tsx +91 -0
  279. package/src/email/templates/trial-expiry.tsx +124 -0
  280. package/src/email/templates/trial-warning.tsx +104 -0
  281. package/src/email/templates/verify-email.tsx +72 -0
  282. package/src/email/templates/welcome.tsx +64 -0
  283. package/src/email/templates/workspace-invitation.tsx +105 -0
  284. package/src/env.ts +180 -0
  285. package/src/identity/audit.ts +65 -0
  286. package/src/identity/errors.ts +44 -0
  287. package/src/identity/index.ts +26 -0
  288. package/src/identity/service.ts +202 -0
  289. package/src/identity/types.ts +28 -0
  290. package/src/index.ts +4 -0
  291. package/src/logger.ts +198 -0
  292. package/src/money.ts +270 -0
  293. package/src/notifications/index.ts +108 -0
  294. package/src/notifications/triggers.ts +158 -0
  295. package/src/notifications/types.ts +18 -0
  296. package/src/prompt.ts +142 -0
  297. package/src/registry.ts +75 -0
  298. package/src/request-context.ts +137 -0
  299. package/src/storage/index.ts +153 -0
  300. package/dist/db/schema/rag.d.ts +0 -171
  301. package/dist/db/schema/rag.d.ts.map +0 -1
  302. package/dist/db/schema/rag.js +0 -42
  303. package/dist/db/schema/rag.js.map +0 -1
  304. package/src/db/migrations/0000_sharp_night_nurse.sql +0 -52
  305. package/src/db/migrations/0001_hesitant_vapor.sql +0 -40
  306. package/src/db/migrations/0002_numerous_lady_vermin.sql +0 -235
  307. package/src/db/migrations/0003_mighty_jean_grey.sql +0 -37
  308. package/src/db/migrations/0004_cynical_grandmaster.sql +0 -2
  309. package/src/db/migrations/0005_careful_switch.sql +0 -8
  310. package/src/db/migrations/0006_tense_blue_marvel.sql +0 -16
  311. package/src/db/migrations/0007_next_squadron_sinister.sql +0 -1
  312. package/src/db/migrations/0008_powerful_scream.sql +0 -39
  313. package/src/db/migrations/0009_sad_ink.sql +0 -1
  314. package/src/db/migrations/0010_shocking_omega_flight.sql +0 -2
  315. package/src/db/migrations/0011_ambiguous_otto_octavius.sql +0 -151
  316. package/src/db/migrations/0011_hnsw_vector_index.sql +0 -17
  317. package/src/db/migrations/0012_user_profiles.sql +0 -30
  318. package/src/db/migrations/0013_trending_seasonal_columns.sql +0 -9
  319. package/src/db/migrations/0014_add_product_type_to_agents.sql +0 -6
  320. package/src/db/migrations/0015_new_v1_tables.sql +0 -149
  321. package/src/db/migrations/0016_document_types.sql +0 -30
  322. package/src/db/migrations/0017_document_metadata.sql +0 -2
  323. package/src/db/migrations/0018_identity_graph.sql +0 -200
  324. package/src/db/migrations/0019_db_driven_prompts.sql +0 -20
  325. package/src/db/migrations/0020_pending_extractions.sql +0 -35
  326. package/src/db/migrations/0021_rag_documents.sql +0 -39
  327. package/src/db/migrations/0022_user_quotas_usage_jsonb.sql +0 -70
  328. package/src/db/migrations/0023_user_facts_user_scoped_unique.sql +0 -17
  329. package/src/db/migrations/0024_user_memories_hnsw.sql +0 -23
  330. package/src/db/migrations/0025_audit_trigger_errcode.sql +0 -21
  331. package/src/db/migrations/0026_user_profile_snapshots_composite_pk.sql +0 -17
  332. package/src/db/migrations/0027_billing_settings_mnt_columns.sql +0 -54
  333. package/src/db/migrations/0028_trial_credits_normalized_email.sql +0 -37
  334. package/src/db/migrations/0029_usage_records_conversation_idx.sql +0 -13
  335. package/src/db/migrations/0030_pending_extractions_composite_idx.sql +0 -11
  336. package/src/db/migrations/0031_rag_documents_hnsw.sql +0 -16
  337. package/src/db/migrations/0032_rate_limit_unique_idx.sql +0 -16
  338. package/src/db/migrations/0033_pending_extractions_partial_idx.sql +0 -18
  339. package/src/db/migrations/0034_rate_limit_count.sql +0 -9
  340. package/src/db/migrations/0035_credit_reservations.sql +0 -24
  341. package/src/db/migrations/0036_executions_audit_jobs.sql +0 -96
  342. package/src/db/migrations/0037_rate_limit_minute_bucket.sql +0 -46
  343. package/src/db/migrations/0038_user_quotas_generic_usage.sql +0 -25
  344. package/src/db/migrations/0039_platform_admin_impersonation.sql +0 -27
  345. package/src/db/migrations/0040_ee_audit_chain.sql +0 -23
  346. package/src/db/migrations/meta/0001_snapshot.json +0 -631
  347. package/src/db/migrations/meta/0003_snapshot.json +0 -2488
  348. package/src/db/migrations/meta/0004_snapshot.json +0 -2500
  349. package/src/db/migrations/meta/0005_snapshot.json +0 -2548
  350. package/src/db/migrations/meta/0006_snapshot.json +0 -2650
  351. package/src/db/migrations/meta/0007_snapshot.json +0 -2657
  352. package/src/db/migrations/meta/0008_snapshot.json +0 -2719
  353. package/src/db/migrations/meta/0009_snapshot.json +0 -2726
  354. package/src/db/migrations/meta/0010_snapshot.json +0 -2739
  355. package/src/db/migrations/meta/0011_snapshot.json +0 -3886
@@ -5,295 +5,22 @@
5
5
  {
6
6
  "idx": 0,
7
7
  "version": "7",
8
- "when": 1770467636254,
9
- "tag": "0000_sharp_night_nurse",
8
+ "when": 1789740313941,
9
+ "tag": "0000_baseline",
10
10
  "breakpoints": true
11
11
  },
12
12
  {
13
13
  "idx": 1,
14
14
  "version": "7",
15
- "when": 1770475851108,
16
- "tag": "0001_hesitant_vapor",
15
+ "when": 1789740314941,
16
+ "tag": "0001_reconcile_chain_built_databases",
17
17
  "breakpoints": true
18
18
  },
19
19
  {
20
20
  "idx": 2,
21
21
  "version": "7",
22
- "when": 1770556082464,
23
- "tag": "0002_numerous_lady_vermin",
24
- "breakpoints": true
25
- },
26
- {
27
- "idx": 3,
28
- "version": "7",
29
- "when": 1770606381406,
30
- "tag": "0003_mighty_jean_grey",
31
- "breakpoints": true
32
- },
33
- {
34
- "idx": 4,
35
- "version": "7",
36
- "when": 1770743970189,
37
- "tag": "0004_cynical_grandmaster",
38
- "breakpoints": true
39
- },
40
- {
41
- "idx": 5,
42
- "version": "7",
43
- "when": 1771267120497,
44
- "tag": "0005_careful_switch",
45
- "breakpoints": true
46
- },
47
- {
48
- "idx": 6,
49
- "version": "7",
50
- "when": 1771340722768,
51
- "tag": "0006_tense_blue_marvel",
52
- "breakpoints": true
53
- },
54
- {
55
- "idx": 7,
56
- "version": "7",
57
- "when": 1771390659372,
58
- "tag": "0007_next_squadron_sinister",
59
- "breakpoints": true
60
- },
61
- {
62
- "idx": 8,
63
- "version": "7",
64
- "when": 1771666802968,
65
- "tag": "0008_powerful_scream",
66
- "breakpoints": true
67
- },
68
- {
69
- "idx": 9,
70
- "version": "7",
71
- "when": 1771669888764,
72
- "tag": "0009_sad_ink",
73
- "breakpoints": true
74
- },
75
- {
76
- "idx": 10,
77
- "version": "7",
78
- "when": 1771684216541,
79
- "tag": "0010_shocking_omega_flight",
80
- "breakpoints": true
81
- },
82
- {
83
- "idx": 11,
84
- "version": "7",
85
- "when": 1775401944659,
86
- "tag": "0011_ambiguous_otto_octavius",
87
- "breakpoints": true
88
- },
89
- {
90
- "idx": 12,
91
- "version": "7",
92
- "when": 1700000012000,
93
- "tag": "0011_hnsw_vector_index",
94
- "breakpoints": true
95
- },
96
- {
97
- "idx": 13,
98
- "version": "7",
99
- "when": 1700000013000,
100
- "tag": "0012_user_profiles",
101
- "breakpoints": true
102
- },
103
- {
104
- "idx": 14,
105
- "version": "7",
106
- "when": 1700000014000,
107
- "tag": "0013_trending_seasonal_columns",
108
- "breakpoints": true
109
- },
110
- {
111
- "idx": 15,
112
- "version": "7",
113
- "when": 1700000015000,
114
- "tag": "0014_add_product_type_to_agents",
115
- "breakpoints": true
116
- },
117
- {
118
- "idx": 16,
119
- "version": "7",
120
- "when": 1700000016000,
121
- "tag": "0015_new_v1_tables",
122
- "breakpoints": true
123
- },
124
- {
125
- "idx": 17,
126
- "version": "7",
127
- "when": 1700000017000,
128
- "tag": "0016_document_types",
129
- "breakpoints": true
130
- },
131
- {
132
- "idx": 18,
133
- "version": "7",
134
- "when": 1700000018000,
135
- "tag": "0017_document_metadata",
136
- "breakpoints": true
137
- },
138
- {
139
- "idx": 19,
140
- "version": "7",
141
- "when": 1700000019000,
142
- "tag": "0018_identity_graph",
143
- "breakpoints": true
144
- },
145
- {
146
- "idx": 20,
147
- "version": "7",
148
- "when": 1700000020000,
149
- "tag": "0019_db_driven_prompts",
150
- "breakpoints": true
151
- },
152
- {
153
- "idx": 21,
154
- "version": "7",
155
- "when": 1700000021000,
156
- "tag": "0020_pending_extractions",
157
- "breakpoints": true
158
- },
159
- {
160
- "idx": 22,
161
- "version": "7",
162
- "when": 1700000022000,
163
- "tag": "0021_rag_documents",
164
- "breakpoints": true
165
- },
166
- {
167
- "idx": 23,
168
- "version": "7",
169
- "when": 1700000023000,
170
- "tag": "0022_user_quotas_usage_jsonb",
171
- "breakpoints": true
172
- },
173
- {
174
- "idx": 24,
175
- "version": "7",
176
- "when": 1700000024000,
177
- "tag": "0023_user_facts_user_scoped_unique",
178
- "breakpoints": true
179
- },
180
- {
181
- "idx": 25,
182
- "version": "7",
183
- "when": 1700000025000,
184
- "tag": "0024_user_memories_hnsw",
185
- "breakpoints": true
186
- },
187
- {
188
- "idx": 26,
189
- "version": "7",
190
- "when": 1700000026000,
191
- "tag": "0025_audit_trigger_errcode",
192
- "breakpoints": true
193
- },
194
- {
195
- "idx": 27,
196
- "version": "7",
197
- "when": 1700000027000,
198
- "tag": "0026_user_profile_snapshots_composite_pk",
199
- "breakpoints": true
200
- },
201
- {
202
- "idx": 28,
203
- "version": "7",
204
- "when": 1700000028000,
205
- "tag": "0027_billing_settings_mnt_columns",
206
- "breakpoints": true
207
- },
208
- {
209
- "idx": 29,
210
- "version": "7",
211
- "when": 1700000029000,
212
- "tag": "0028_trial_credits_normalized_email",
213
- "breakpoints": true
214
- },
215
- {
216
- "idx": 30,
217
- "version": "7",
218
- "when": 1700000030000,
219
- "tag": "0029_usage_records_conversation_idx",
220
- "breakpoints": true
221
- },
222
- {
223
- "idx": 31,
224
- "version": "7",
225
- "when": 1700000031000,
226
- "tag": "0030_pending_extractions_composite_idx",
227
- "breakpoints": true
228
- },
229
- {
230
- "idx": 32,
231
- "version": "7",
232
- "when": 1700000032000,
233
- "tag": "0031_rag_documents_hnsw",
234
- "breakpoints": true
235
- },
236
- {
237
- "idx": 33,
238
- "version": "7",
239
- "when": 1700000033000,
240
- "tag": "0032_rate_limit_unique_idx",
241
- "breakpoints": true
242
- },
243
- {
244
- "idx": 34,
245
- "version": "7",
246
- "when": 1700000034000,
247
- "tag": "0033_pending_extractions_partial_idx",
248
- "breakpoints": true
249
- },
250
- {
251
- "idx": 35,
252
- "version": "7",
253
- "when": 1700000035000,
254
- "tag": "0034_rate_limit_count",
255
- "breakpoints": true
256
- },
257
- {
258
- "idx": 36,
259
- "version": "7",
260
- "when": 1700000036000,
261
- "tag": "0035_credit_reservations",
262
- "breakpoints": true
263
- },
264
- {
265
- "idx": 37,
266
- "version": "7",
267
- "when": 1700000037000,
268
- "tag": "0036_executions_audit_jobs",
269
- "breakpoints": true
270
- },
271
- {
272
- "idx": 38,
273
- "version": "7",
274
- "when": 1700000038000,
275
- "tag": "0037_rate_limit_minute_bucket",
276
- "breakpoints": true
277
- },
278
- {
279
- "idx": 39,
280
- "version": "7",
281
- "when": 1700000039000,
282
- "tag": "0038_user_quotas_generic_usage",
283
- "breakpoints": true
284
- },
285
- {
286
- "idx": 40,
287
- "version": "7",
288
- "when": 1700000040000,
289
- "tag": "0039_platform_admin_impersonation",
290
- "breakpoints": true
291
- },
292
- {
293
- "idx": 41,
294
- "version": "7",
295
- "when": 1700000041000,
296
- "tag": "0040_ee_audit_chain",
22
+ "when": 1789808201382,
23
+ "tag": "0002_webhook_claim_lease",
297
24
  "breakpoints": true
298
25
  }
299
26
  ]
@@ -0,0 +1,57 @@
1
+ import {
2
+ pgTable,
3
+ text,
4
+ timestamp,
5
+ integer,
6
+ boolean,
7
+ jsonb,
8
+ } from "drizzle-orm/pg-core";
9
+
10
+ /**
11
+ * Localized text, keyed by locale tag: `{ en: "…", de: "…" }`. Open, so
12
+ * adding a language is not a schema change.
13
+ */
14
+ export type LocalizedText = Record<string, string>;
15
+
16
+ /** A quick-start prompt shown for an agent. */
17
+ export type AgentSuggestion = {
18
+ id: string;
19
+ label: LocalizedText;
20
+ prompt: LocalizedText;
21
+ };
22
+
23
+ /** Per-agent model routing. Only `primary` is read. */
24
+ export type AgentModelConfig = {
25
+ primary: string;
26
+ fallback?: string;
27
+ routing?: Record<string, string>;
28
+ };
29
+
30
+ /** AI agent configuration: system prompt, tools and model per agent. */
31
+ export const agents = pgTable("agents", {
32
+ id: text("id").primaryKey(), // Slug, e.g. "support-assistant"
33
+ name: jsonb("name").notNull().$type<LocalizedText>(), // { en: "Support Assistant", … }
34
+ description: jsonb("description").notNull().$type<LocalizedText>(), // { en: "…", … }
35
+ systemPromptKey: text("system_prompt_key").notNull(), // Translation namespace key; not read at runtime (systemPrompt is).
36
+ systemPrompt: jsonb("system_prompt").$type<LocalizedText | null>(), // Source of truth for agent instructions.
37
+ modelConfig: jsonb("model_config").$type<AgentModelConfig | null>(), // Only `primary` is read.
38
+ icon: text("icon").notNull(), // Icon identifier (e.g., "briefcase", "map-pin")
39
+ defaultModel: text("default_model").notNull(), // AI model ID (e.g., "openai/gpt-4o") — fallback when modelConfig is null.
40
+ maxSteps: integer("max_steps").notNull(), // ToolLoopAgent max iterations
41
+ contextWindowSize: integer("context_window_size").notNull(), // Conversation windowing message count
42
+ tools: jsonb("tools").notNull().default([]).$type<string[]>(), // Array of tool names
43
+ basePath: text("base_path").notNull(), // URL base path (e.g., "/support")
44
+ isActive: boolean("is_active").notNull().default(true), // Whether agent is available to users
45
+ suggestions: jsonb("suggestions")
46
+ .notNull()
47
+ .default([])
48
+ .$type<AgentSuggestion[]>(), // Quick-start suggestion prompts
49
+ isSystem: boolean("is_system").notNull().default(true), // System agents can't be deleted by users
50
+ featureKey: text("feature_key"), // Nullable: billing feature key (e.g., "support_assistant"). Used for feature gating lookups.
51
+ color: text("color").notNull().default("bg-gray-500"), // Tailwind bg class for UI indicators (e.g., "bg-blue-500")
52
+ createdAt: timestamp("created_at").notNull().defaultNow(),
53
+ updatedAt: timestamp("updated_at").notNull().defaultNow(),
54
+ });
55
+
56
+ export type Agent = typeof agents.$inferSelect;
57
+ export type InsertAgent = typeof agents.$inferInsert;
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Chat persistence every product shares: conversations, messages,
3
+ * attachments, votes and documents (artifact versions).
4
+ */
5
+
6
+ import {
7
+ pgTable,
8
+ text,
9
+ timestamp,
10
+ integer,
11
+ index,
12
+ uniqueIndex,
13
+ boolean,
14
+ primaryKey,
15
+ jsonb,
16
+ } from "drizzle-orm/pg-core";
17
+ import { organization, users } from "./auth";
18
+
19
+ /**
20
+ * A product that attaches typed state to a conversation puts it under
21
+ * `productContext` and owns the shape.
22
+ */
23
+ export type ConversationMetadata = {
24
+ conversationSummary?: string; // LLM-generated summary of pruned messages
25
+ productContext?: Record<string, unknown>;
26
+ [key: string]: unknown;
27
+ };
28
+
29
+ /** One chat session between a user and an agent, within a workspace. */
30
+ export const conversations = pgTable(
31
+ "conversations",
32
+ {
33
+ id: text("id").primaryKey(),
34
+ workspaceId: text("workspace_id")
35
+ .notNull()
36
+ .references(() => organization.id, { onDelete: "cascade" }),
37
+ userId: text("user_id")
38
+ .notNull()
39
+ .references(() => users.id, { onDelete: "cascade" }),
40
+ agentId: text("agent_id").notNull(), // the product's agent slug
41
+ title: text("title"), // Nullable until the product sets one
42
+ modelId: text("model_id"), // e.g., "openai/gpt-4o"
43
+ visibility: text("visibility").notNull().default("private"), // "private" | "public"
44
+ metadata: jsonb("metadata"), // ConversationMetadata
45
+ createdAt: timestamp("created_at").notNull().defaultNow(),
46
+ updatedAt: timestamp("updated_at").notNull().defaultNow(),
47
+ },
48
+ (table) => [
49
+ index("conversations_workspace_id_idx").on(table.workspaceId),
50
+ index("conversations_user_id_idx").on(table.userId),
51
+ index("conversations_workspace_updated_idx").on(
52
+ table.workspaceId,
53
+ table.updatedAt
54
+ ),
55
+ index("conversations_workspace_user_idx").on(
56
+ table.workspaceId,
57
+ table.userId
58
+ ),
59
+ ]
60
+ );
61
+
62
+ export const messages = pgTable(
63
+ "messages",
64
+ {
65
+ id: text("id").primaryKey(),
66
+ conversationId: text("conversation_id")
67
+ .notNull()
68
+ .references(() => conversations.id, { onDelete: "cascade" }),
69
+ role: text("role").notNull(), // "user" | "assistant" | "system" | "tool"
70
+ content: text("content"), // Nullable; `parts` holds the message
71
+ parts: text("parts").notNull(), // JSON array of AI SDK UIMessagePart objects
72
+ attachments: text("attachments"), // JSON array of file attachment metadata
73
+ toolInvocations: text("tool_invocations"), // JSON string of tool calls/results (AI SDK format)
74
+ tokenCount: integer("token_count"),
75
+ createdAt: timestamp("created_at").notNull().defaultNow(),
76
+ },
77
+ (table) => [
78
+ index("messages_conversation_id_idx").on(table.conversationId),
79
+ index("messages_conversation_created_idx").on(
80
+ table.conversationId,
81
+ table.createdAt
82
+ ),
83
+ ]
84
+ );
85
+
86
+ /**
87
+ * Files a user put into a conversation. The object lives behind the
88
+ * storage port under `storage_key`; the
89
+ * row is what makes a URL safe to hand out (tenancy, type, size).
90
+ * `conversation_id` is set once the turn that carried the file is
91
+ * persisted; a row that never gets one is an orphan to sweep.
92
+ */
93
+ export const attachments = pgTable(
94
+ "attachments",
95
+ {
96
+ id: text("id").primaryKey(),
97
+ workspaceId: text("workspace_id")
98
+ .notNull()
99
+ .references(() => organization.id, { onDelete: "cascade" }),
100
+ userId: text("user_id")
101
+ .notNull()
102
+ .references(() => users.id, { onDelete: "cascade" }),
103
+ conversationId: text("conversation_id").references(() => conversations.id, {
104
+ onDelete: "set null",
105
+ }),
106
+ storageKey: text("storage_key").notNull(),
107
+ filename: text("filename").notNull(),
108
+ mediaType: text("media_type").notNull(),
109
+ sizeBytes: integer("size_bytes").notNull(),
110
+ extractedText: text("extracted_text"), // document text for the model, when a policy extracts it
111
+ createdAt: timestamp("created_at").notNull().defaultNow(),
112
+ },
113
+ (table) => [
114
+ index("attachments_workspace_id_idx").on(table.workspaceId),
115
+ index("attachments_conversation_id_idx").on(table.conversationId),
116
+ uniqueIndex("attachments_storage_key_idx").on(table.storageKey),
117
+ ]
118
+ );
119
+
120
+ /** One vote per message (composite key on chat and message). */
121
+ export const votes = pgTable(
122
+ "votes",
123
+ {
124
+ chatId: text("chat_id")
125
+ .notNull()
126
+ .references(() => conversations.id, { onDelete: "cascade" }),
127
+ messageId: text("message_id")
128
+ .notNull()
129
+ .references(() => messages.id, { onDelete: "cascade" }),
130
+ isUpvoted: boolean("is_upvoted").notNull(),
131
+ },
132
+ (table) => [
133
+ primaryKey({ columns: [table.chatId, table.messageId] }),
134
+ index("votes_message_id_idx").on(table.messageId),
135
+ ]
136
+ );
137
+
138
+ /**
139
+ * AI-generated documents with version history: each save is a new row,
140
+ * keyed on id + createdAt.
141
+ */
142
+ export const documents = pgTable(
143
+ "documents",
144
+ {
145
+ id: text("id").notNull(),
146
+ createdAt: timestamp("created_at").notNull().defaultNow(),
147
+ title: text("title").notNull(),
148
+ content: text("content"),
149
+ kind: text("kind").notNull().default("text"),
150
+ metadata: jsonb("metadata"), // Structured data (e.g. a report's JSON)
151
+ userId: text("user_id")
152
+ .notNull()
153
+ .references(() => users.id, { onDelete: "cascade" }),
154
+ workspaceId: text("workspace_id")
155
+ .notNull()
156
+ .references(() => organization.id, { onDelete: "cascade" }),
157
+ },
158
+ (table) => [
159
+ primaryKey({ columns: [table.id, table.createdAt] }),
160
+ index("documents_workspace_id_idx").on(table.workspaceId),
161
+ index("documents_user_id_idx").on(table.userId),
162
+ ]
163
+ );
164
+
165
+ export type Conversation = typeof conversations.$inferSelect;
166
+ export type InsertConversation = typeof conversations.$inferInsert;
167
+ export type Message = typeof messages.$inferSelect;
168
+ export type InsertMessage = typeof messages.$inferInsert;
169
+ export type Attachment = typeof attachments.$inferSelect;
170
+ export type InsertAttachment = typeof attachments.$inferInsert;
171
+ export type Vote = typeof votes.$inferSelect;
172
+ export type InsertVote = typeof votes.$inferInsert;
173
+ export type Document = typeof documents.$inferSelect;
174
+ export type InsertDocument = typeof documents.$inferInsert;