@m6d/cortex-server 1.8.0 → 2.0.1

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 (354) hide show
  1. package/README.md +8 -3
  2. package/contracts/README.md +23 -0
  3. package/contracts/graph/embed.ts +50 -0
  4. package/{src/lib → contracts}/graph/helpers.ts +4 -10
  5. package/{src/lib → contracts}/graph/neo4j.ts +14 -27
  6. package/contracts/graph/schema.ts +65 -0
  7. package/{src/lib → contracts}/graph/types.ts +2 -29
  8. package/contracts/graph.ts +36 -0
  9. package/contracts/rich-text.ts +207 -0
  10. package/contracts/runtime.ts +243 -0
  11. package/contracts/wire.ts +143 -0
  12. package/dist/contracts/graph/embed.d.ts +22 -0
  13. package/dist/{src/lib → contracts}/graph/helpers.d.ts +16 -14
  14. package/dist/{src/lib → contracts}/graph/neo4j.d.ts +5 -5
  15. package/dist/contracts/graph/schema.d.ts +62 -0
  16. package/dist/{src/lib → contracts}/graph/types.d.ts +1 -1
  17. package/dist/contracts/graph.d.ts +14 -0
  18. package/dist/contracts/rich-text.d.ts +32 -0
  19. package/dist/contracts/runtime.d.ts +310 -0
  20. package/dist/contracts/wire.d.ts +120 -0
  21. package/dist/src/lib/adapters/database/index.d.ts +61 -0
  22. package/dist/src/lib/adapters/database/message-content.d.ts +30 -0
  23. package/dist/src/lib/adapters/database/mssql/attachments.d.ts +100 -0
  24. package/dist/src/lib/adapters/database/mssql/client.d.ts +8 -0
  25. package/dist/src/lib/adapters/database/mssql/index.d.ts +194 -0
  26. package/dist/src/lib/adapters/database/mssql/llm-requests.d.ts +17 -0
  27. package/dist/src/lib/adapters/database/mssql/messages.d.ts +37 -0
  28. package/dist/src/lib/adapters/database/mssql/threads.d.ts +50 -0
  29. package/dist/src/lib/adapters/database/postgres/attachments.d.ts +113 -0
  30. package/dist/src/lib/adapters/database/postgres/client.d.ts +8 -0
  31. package/dist/src/lib/adapters/database/postgres/index.d.ts +207 -0
  32. package/dist/src/lib/adapters/database/postgres/llm-requests.d.ts +17 -0
  33. package/dist/src/lib/adapters/database/postgres/messages.d.ts +37 -0
  34. package/dist/src/lib/adapters/database/postgres/threads.d.ts +50 -0
  35. package/{src/lib/adapters/storage.ts → dist/src/lib/adapters/storage/index.d.ts} +1 -1
  36. package/dist/src/lib/adapters/{minio.d.ts → storage/minio.d.ts} +1 -1
  37. package/dist/src/lib/ai/active-runs.d.ts +63 -0
  38. package/dist/src/lib/ai/attachments.d.ts +30 -0
  39. package/dist/src/lib/ai/backend-url.d.ts +16 -0
  40. package/dist/src/lib/ai/cc-runtime.d.ts +61 -0
  41. package/dist/src/lib/ai/commit-gate.d.ts +21 -0
  42. package/dist/src/lib/ai/context/builder.d.ts +6 -7
  43. package/dist/src/lib/ai/context/compression-middleware.d.ts +15 -0
  44. package/dist/src/lib/ai/context/compressor.d.ts +2 -13
  45. package/dist/src/lib/ai/context/intra-turn-compressor.d.ts +9 -9
  46. package/dist/src/lib/ai/context/optimize-thread-context.d.ts +9 -0
  47. package/dist/src/lib/ai/context/summarizer.d.ts +3 -3
  48. package/dist/src/lib/ai/context/token-estimator.d.ts +5 -8
  49. package/dist/src/lib/ai/fetch.d.ts +1 -1
  50. package/dist/src/lib/ai/finish-turn.d.ts +23 -0
  51. package/dist/src/lib/ai/helpers.d.ts +37 -4
  52. package/dist/src/lib/ai/index.d.ts +6 -3
  53. package/dist/src/lib/ai/inspector.d.ts +41 -0
  54. package/dist/src/lib/ai/interceptors/request-interceptor.d.ts +6 -5
  55. package/dist/src/lib/ai/prompt.d.ts +5 -4
  56. package/dist/src/lib/ai/redis-runs.d.ts +41 -0
  57. package/dist/src/lib/ai/redis-stream-log.d.ts +39 -0
  58. package/dist/src/lib/ai/tools/execute-code.tool.d.ts +18 -4
  59. package/dist/src/lib/ai/tools/query-graph.tool.d.ts +13 -5
  60. package/dist/src/lib/ai/tools/read-attachment.tool.d.ts +21 -0
  61. package/dist/src/lib/ai/tools/search-common.d.ts +17 -0
  62. package/dist/src/lib/ai/tools/search-knowledge.tool.d.ts +15 -0
  63. package/dist/src/lib/ai/tools/search-services.tool.d.ts +12 -0
  64. package/dist/src/lib/ai/tools/search-tools.tool.d.ts +12 -0
  65. package/dist/src/lib/ai/turn-tools.d.ts +39 -0
  66. package/dist/src/lib/ai/vision/rasterize-pdf.d.ts +26 -0
  67. package/dist/src/lib/ai/vision/rasterize-pdf.worker.d.ts +1 -0
  68. package/dist/src/lib/ai/vision/vision-reader.d.ts +45 -0
  69. package/dist/src/lib/cc/client.d.ts +183 -0
  70. package/dist/src/lib/cc/config-cache.d.ts +20 -0
  71. package/dist/src/lib/cc/format.d.ts +23 -0
  72. package/dist/src/lib/cc/registry.d.ts +34 -0
  73. package/dist/src/lib/cc/types.d.ts +27 -0
  74. package/dist/src/lib/config.d.ts +81 -64
  75. package/dist/src/lib/db/drizzle.config.mssql.d.ts +2 -0
  76. package/dist/src/lib/db/drizzle.config.pg.d.ts +2 -0
  77. package/dist/src/lib/db/migrate.d.ts +7 -1
  78. package/dist/src/lib/db/{schema.d.ts → schema.mssql.d.ts} +138 -29
  79. package/dist/src/lib/db/schema.pg.d.ts +546 -0
  80. package/dist/src/lib/factory.d.ts +2 -12
  81. package/dist/src/lib/graph/index.d.ts +10 -11
  82. package/dist/src/lib/graph/resolver.d.ts +2 -3
  83. package/dist/src/lib/index.d.ts +3 -3
  84. package/dist/src/lib/redis.d.ts +19 -0
  85. package/dist/src/lib/routes/chat.d.ts +1 -1
  86. package/dist/src/lib/routes/files.d.ts +1 -1
  87. package/dist/src/lib/routes/owned-thread.d.ts +17 -0
  88. package/dist/src/lib/routes/threads.d.ts +1 -1
  89. package/dist/src/lib/routes/ws.d.ts +1 -1
  90. package/dist/src/lib/types.d.ts +20 -37
  91. package/dist/src/lib/ws/connections.d.ts +2 -1
  92. package/package.json +33 -18
  93. package/src/lib/adapters/database/index.ts +78 -0
  94. package/src/lib/adapters/database/message-content.ts +39 -0
  95. package/src/lib/adapters/database/mssql/attachments.ts +90 -0
  96. package/src/lib/adapters/database/mssql/client.ts +11 -0
  97. package/src/lib/adapters/database/mssql/index.ts +23 -0
  98. package/src/lib/adapters/database/mssql/llm-requests.ts +43 -0
  99. package/src/lib/adapters/database/mssql/messages.ts +92 -0
  100. package/src/lib/adapters/database/mssql/threads.ts +83 -0
  101. package/src/lib/adapters/database/postgres/attachments.ts +88 -0
  102. package/src/lib/adapters/database/postgres/client.ts +11 -0
  103. package/src/lib/adapters/database/postgres/index.ts +23 -0
  104. package/src/lib/adapters/database/postgres/llm-requests.ts +45 -0
  105. package/src/lib/adapters/database/postgres/messages.ts +92 -0
  106. package/src/lib/adapters/database/postgres/threads.ts +84 -0
  107. package/{dist/src/lib/adapters/storage.d.ts → src/lib/adapters/storage/index.ts} +1 -1
  108. package/src/lib/adapters/{minio.ts → storage/minio.ts} +5 -5
  109. package/src/lib/ai/active-runs.ts +157 -0
  110. package/src/lib/ai/attachments.ts +144 -0
  111. package/src/lib/ai/backend-url.ts +27 -0
  112. package/src/lib/ai/cc-runtime.ts +63 -0
  113. package/src/lib/ai/commit-gate.ts +116 -0
  114. package/src/lib/ai/context/builder.ts +12 -14
  115. package/src/lib/ai/context/compression-middleware.ts +44 -0
  116. package/src/lib/ai/context/compressor.ts +67 -59
  117. package/src/lib/ai/context/intra-turn-compressor.ts +121 -204
  118. package/src/lib/ai/context/optimize-thread-context.ts +50 -0
  119. package/src/lib/ai/context/summarizer.ts +28 -30
  120. package/src/lib/ai/context/token-estimator.ts +35 -30
  121. package/src/lib/ai/fetch.ts +10 -5
  122. package/src/lib/ai/finish-turn.ts +75 -0
  123. package/src/lib/ai/helpers.ts +83 -15
  124. package/src/lib/ai/index.ts +366 -329
  125. package/src/lib/ai/inspector.ts +112 -0
  126. package/src/lib/ai/interceptors/request-interceptor.ts +70 -42
  127. package/src/lib/ai/prompt.ts +126 -125
  128. package/src/lib/ai/redis-runs.ts +167 -0
  129. package/src/lib/ai/redis-stream-log.ts +219 -0
  130. package/src/lib/ai/tools/execute-code.tool.ts +178 -67
  131. package/src/lib/ai/tools/query-graph.tool.ts +7 -8
  132. package/src/lib/ai/tools/read-attachment.tool.ts +59 -0
  133. package/src/lib/ai/tools/search-common.ts +15 -0
  134. package/src/lib/ai/tools/search-knowledge.tool.ts +33 -0
  135. package/src/lib/ai/tools/search-services.tool.ts +31 -0
  136. package/src/lib/ai/tools/search-tools.tool.ts +29 -0
  137. package/src/lib/ai/turn-tools.ts +154 -0
  138. package/src/lib/ai/vision/rasterize-pdf.ts +69 -0
  139. package/src/lib/ai/vision/rasterize-pdf.worker.ts +81 -0
  140. package/src/lib/ai/vision/vision-reader.ts +130 -0
  141. package/src/lib/auth/middleware.ts +5 -3
  142. package/src/lib/cc/client.ts +273 -0
  143. package/src/lib/cc/config-cache.ts +32 -0
  144. package/src/lib/cc/format.ts +92 -0
  145. package/src/lib/cc/registry.ts +62 -0
  146. package/src/lib/cc/types.ts +44 -0
  147. package/src/lib/config.ts +102 -71
  148. package/src/lib/db/drizzle.config.mssql.ts +9 -0
  149. package/src/lib/db/drizzle.config.pg.ts +9 -0
  150. package/src/lib/db/migrate.ts +45 -10
  151. package/src/lib/db/migrations/mssql/20260729092726_talented_wilson_fisk/migration.sql +20 -0
  152. package/src/lib/db/migrations/mssql/20260729092726_talented_wilson_fisk/snapshot.json +497 -0
  153. package/src/lib/db/migrations/mssql/20260801003652_perpetual_blue_shield/migration.sql +1 -0
  154. package/src/lib/db/migrations/mssql/20260801003652_perpetual_blue_shield/snapshot.json +516 -0
  155. package/src/lib/db/migrations/mssql/20260812174642_user_id_text/migration.sql +2 -0
  156. package/src/lib/db/migrations/mssql/20260812174642_user_id_text/snapshot.json +516 -0
  157. package/src/lib/db/migrations/pg/20260801084117_thick_ben_grimm/migration.sql +53 -0
  158. package/src/lib/db/migrations/pg/20260801084117_thick_ben_grimm/snapshot.json +584 -0
  159. package/src/lib/db/migrations/pg/20260812174622_user_id_text/migration.sql +2 -0
  160. package/src/lib/db/migrations/pg/20260812174622_user_id_text/snapshot.json +584 -0
  161. package/src/lib/db/{schema.ts → schema.mssql.ts} +29 -18
  162. package/src/lib/db/schema.pg.ts +95 -0
  163. package/src/lib/factory.ts +44 -89
  164. package/src/lib/graph/index.ts +12 -40
  165. package/src/lib/graph/resolver.ts +146 -116
  166. package/src/lib/index.ts +11 -4
  167. package/src/lib/redis.ts +44 -0
  168. package/src/lib/routes/chat.ts +91 -62
  169. package/src/lib/routes/files.ts +105 -83
  170. package/src/lib/routes/owned-thread.ts +17 -0
  171. package/src/lib/routes/threads.ts +14 -30
  172. package/src/lib/routes/ws.ts +9 -3
  173. package/src/lib/types.ts +37 -36
  174. package/src/lib/ws/connections.ts +9 -1
  175. package/tsconfig.json +48 -0
  176. package/dist/src/lib/adapters/database.d.ts +0 -45
  177. package/dist/src/lib/adapters/mssql.d.ts +0 -3
  178. package/dist/src/lib/ai/active-streams.d.ts +0 -14
  179. package/dist/src/lib/ai/context/index.d.ts +0 -16
  180. package/dist/src/lib/ai/tools/capture-files.tool.d.ts +0 -6
  181. package/dist/src/lib/cli/extract-endpoints.d.ts +0 -6
  182. package/dist/src/lib/graph/expand-domains.d.ts +0 -2
  183. package/dist/src/lib/graph/generate-cypher.d.ts +0 -22
  184. package/dist/src/lib/graph/seed.d.ts +0 -19
  185. package/dist/src/lib/graph/validate.d.ts +0 -2
  186. package/dist/src/lib/routes/index.d.ts +0 -4
  187. package/dist/src/lib/ws/events.d.ts +0 -39
  188. package/dist/src/lib/ws/index.d.ts +0 -3
  189. package/dist/src/lib/ws/notify.d.ts +0 -2
  190. package/src/lib/adapters/database.ts +0 -48
  191. package/src/lib/adapters/mssql.ts +0 -231
  192. package/src/lib/ai/active-streams.ts +0 -123
  193. package/src/lib/ai/context/index.ts +0 -80
  194. package/src/lib/ai/tools/capture-files.tool.ts +0 -20
  195. package/src/lib/cli/extract-endpoints.ts +0 -550
  196. package/src/lib/graph/expand-domains.ts +0 -276
  197. package/src/lib/graph/generate-cypher.ts +0 -192
  198. package/src/lib/graph/seed.ts +0 -162
  199. package/src/lib/graph/validate.ts +0 -78
  200. package/src/lib/routes/index.ts +0 -4
  201. package/src/lib/ws/events.ts +0 -39
  202. package/src/lib/ws/index.ts +0 -11
  203. package/src/lib/ws/notify.ts +0 -9
  204. package/src/sample/db/client.ts +0 -9
  205. package/src/sample/db/migrations/20260411023125_rich_purple_man/migration.sql +0 -5
  206. package/src/sample/db/migrations/20260411023125_rich_purple_man/snapshot.json +0 -50
  207. package/src/sample/db/schema.ts +0 -10
  208. package/src/sample/domains/account/concepts/session.concept.ts +0 -17
  209. package/src/sample/domains/account/endpoints/listCurrentSessions.endpoint.ts +0 -31
  210. package/src/sample/domains/account/endpoints/revokeAllOtherSessions.endpoint.ts +0 -22
  211. package/src/sample/domains/account/endpoints/revokeCurrentSession.endpoint.ts +0 -33
  212. package/src/sample/domains/account/index.ts +0 -18
  213. package/src/sample/domains/appraisals/concepts/appraisalCycle.concept.ts +0 -15
  214. package/src/sample/domains/appraisals/concepts/appraisalRecord.concept.ts +0 -20
  215. package/src/sample/domains/appraisals/concepts/appraisalRecordCompetency.concept.ts +0 -10
  216. package/src/sample/domains/appraisals/concepts/appraisalRecordFunctionalRequirement.concept.ts +0 -10
  217. package/src/sample/domains/appraisals/concepts/appraisalRecordGoal.concept.ts +0 -17
  218. package/src/sample/domains/appraisals/endpoints/getAppraisalRecordById.endpoint.ts +0 -321
  219. package/src/sample/domains/appraisals/endpoints/getAppraisalRecordCompetencies.endpoint.ts +0 -120
  220. package/src/sample/domains/appraisals/endpoints/getAppraisalRecordFunctionalRequirements.endpoint.ts +0 -126
  221. package/src/sample/domains/appraisals/endpoints/getAppraisalRecordGoals.endpoint.ts +0 -104
  222. package/src/sample/domains/appraisals/endpoints/getAppraisalRecordScore.endpoint.ts +0 -58
  223. package/src/sample/domains/appraisals/endpoints/listAppraisalCyclesSimple.endpoint.ts +0 -52
  224. package/src/sample/domains/appraisals/endpoints/listAppraisalRecords.endpoint.ts +0 -245
  225. package/src/sample/domains/appraisals/endpoints/listAppraisalTemplatesSimple.endpoint.ts +0 -52
  226. package/src/sample/domains/appraisals/index.ts +0 -40
  227. package/src/sample/domains/appraisals/rules/appraisalRecordScoping.rule.ts +0 -7
  228. package/src/sample/domains/attendance/concepts/attendancePermission.concept.ts +0 -17
  229. package/src/sample/domains/attendance/concepts/attendanceTransaction.concept.ts +0 -17
  230. package/src/sample/domains/attendance/concepts/publicHoliday.concept.ts +0 -10
  231. package/src/sample/domains/attendance/concepts/punch.concept.ts +0 -19
  232. package/src/sample/domains/attendance/endpoints/getAttendanceTransactionById.endpoint.ts +0 -444
  233. package/src/sample/domains/attendance/endpoints/getCurrentAttendanceProfile.endpoint.ts +0 -886
  234. package/src/sample/domains/attendance/endpoints/getCurrentAttendanceStatistics.endpoint.ts +0 -49
  235. package/src/sample/domains/attendance/endpoints/listAttendancePermissions.endpoint.ts +0 -176
  236. package/src/sample/domains/attendance/endpoints/listAttendanceTransactionStates.endpoint.ts +0 -26
  237. package/src/sample/domains/attendance/endpoints/listAttendanceTransactions.endpoint.ts +0 -373
  238. package/src/sample/domains/attendance/endpoints/listPublicHolidaysSimple.endpoint.ts +0 -52
  239. package/src/sample/domains/attendance/endpoints/listPunchTypes.endpoint.ts +0 -25
  240. package/src/sample/domains/attendance/endpoints/listPunches.endpoint.ts +0 -178
  241. package/src/sample/domains/attendance/index.ts +0 -41
  242. package/src/sample/domains/attendance/services/attendancePermissions.service.ts +0 -15
  243. package/src/sample/domains/employees/concepts/employee.concept.ts +0 -20
  244. package/src/sample/domains/employees/concepts/employeeBankAccount.concept.ts +0 -19
  245. package/src/sample/domains/employees/concepts/employeeChild.concept.ts +0 -19
  246. package/src/sample/domains/employees/concepts/employeeDocument.concept.ts +0 -21
  247. package/src/sample/domains/employees/concepts/employeeEvent.concept.ts +0 -21
  248. package/src/sample/domains/employees/concepts/employeeExperience.concept.ts +0 -18
  249. package/src/sample/domains/employees/concepts/employeeJobLevelChange.concept.ts +0 -21
  250. package/src/sample/domains/employees/concepts/employeeMedal.concept.ts +0 -20
  251. package/src/sample/domains/employees/concepts/employeeQualification.concept.ts +0 -20
  252. package/src/sample/domains/employees/concepts/employeeSpouse.concept.ts +0 -21
  253. package/src/sample/domains/employees/concepts/employeeViolation.concept.ts +0 -19
  254. package/src/sample/domains/employees/endpoints/getCurrentEmployee.endpoint.ts +0 -1651
  255. package/src/sample/domains/employees/endpoints/getCurrentIdentity.endpoint.ts +0 -197
  256. package/src/sample/domains/employees/endpoints/getCurrentManagers.endpoint.ts +0 -142
  257. package/src/sample/domains/employees/endpoints/getEmployeeById.endpoint.ts +0 -1659
  258. package/src/sample/domains/employees/endpoints/getEmployeeStatistics.endpoint.ts +0 -43
  259. package/src/sample/domains/employees/endpoints/listBankAccounts.endpoint.ts +0 -223
  260. package/src/sample/domains/employees/endpoints/listChildren.endpoint.ts +0 -211
  261. package/src/sample/domains/employees/endpoints/listDocuments.endpoint.ts +0 -222
  262. package/src/sample/domains/employees/endpoints/listEmployeesSimple.endpoint.ts +0 -156
  263. package/src/sample/domains/employees/endpoints/listEvents.endpoint.ts +0 -120
  264. package/src/sample/domains/employees/endpoints/listExperiences.endpoint.ts +0 -188
  265. package/src/sample/domains/employees/endpoints/listJobLevelChanges.endpoint.ts +0 -240
  266. package/src/sample/domains/employees/endpoints/listMedals.endpoint.ts +0 -266
  267. package/src/sample/domains/employees/endpoints/listQualifications.endpoint.ts +0 -265
  268. package/src/sample/domains/employees/endpoints/listSpouses.endpoint.ts +0 -278
  269. package/src/sample/domains/employees/endpoints/listViolations.endpoint.ts +0 -245
  270. package/src/sample/domains/employees/index.ts +0 -75
  271. package/src/sample/domains/employees/services/employees.service.ts +0 -181
  272. package/src/sample/domains/index.ts +0 -10
  273. package/src/sample/domains/leaves/concepts/leave.concept.ts +0 -21
  274. package/src/sample/domains/leaves/concepts/leaveBalance.concept.ts +0 -17
  275. package/src/sample/domains/leaves/concepts/leaveBalanceTransaction.concept.ts +0 -16
  276. package/src/sample/domains/leaves/concepts/leaveType.concept.ts +0 -13
  277. package/src/sample/domains/leaves/concepts/leaveTypes.concept.ts +0 -205
  278. package/src/sample/domains/leaves/endpoints/getBalance.endpoint.ts +0 -53
  279. package/src/sample/domains/leaves/endpoints/getLeaveById.endpoint.ts +0 -53
  280. package/src/sample/domains/leaves/endpoints/listBalanceTransactions.endpoint.ts +0 -196
  281. package/src/sample/domains/leaves/endpoints/listBalanceTypes.endpoint.ts +0 -26
  282. package/src/sample/domains/leaves/endpoints/listBalances.endpoint.ts +0 -201
  283. package/src/sample/domains/leaves/endpoints/listLeaveTypes.endpoint.ts +0 -28
  284. package/src/sample/domains/leaves/endpoints/listLeaves.endpoint.ts +0 -234
  285. package/src/sample/domains/leaves/index.ts +0 -38
  286. package/src/sample/domains/leaves/services/leaveRequests.service.ts +0 -232
  287. package/src/sample/domains/notifications/concepts/notification.concept.ts +0 -19
  288. package/src/sample/domains/notifications/endpoints/countMyNotifications.endpoint.ts +0 -21
  289. package/src/sample/domains/notifications/endpoints/getMyNotification.endpoint.ts +0 -57
  290. package/src/sample/domains/notifications/endpoints/listMyNotifications.endpoint.ts +0 -59
  291. package/src/sample/domains/notifications/endpoints/markMyNotificationAsRead.endpoint.ts +0 -32
  292. package/src/sample/domains/notifications/index.ts +0 -20
  293. package/src/sample/domains/payroll/concepts/payslip.concept.ts +0 -18
  294. package/src/sample/domains/payroll/concepts/salaryCertificate.concept.ts +0 -17
  295. package/src/sample/domains/payroll/concepts/salaryCertificateRequestingEntity.concept.ts +0 -8
  296. package/src/sample/domains/payroll/endpoints/getPayslipById.endpoint.ts +0 -238
  297. package/src/sample/domains/payroll/endpoints/listPayslips.endpoint.ts +0 -216
  298. package/src/sample/domains/payroll/endpoints/listSalaryCertificateLanguages.endpoint.ts +0 -25
  299. package/src/sample/domains/payroll/endpoints/listSalaryCertificateRequestingEntities.endpoint.ts +0 -62
  300. package/src/sample/domains/payroll/endpoints/listSalaryCertificateTypes.endpoint.ts +0 -24
  301. package/src/sample/domains/payroll/endpoints/listSalaryCertificates.endpoint.ts +0 -122
  302. package/src/sample/domains/payroll/endpoints/previewSalaryCertificate.endpoint.ts +0 -45
  303. package/src/sample/domains/payroll/index.ts +0 -32
  304. package/src/sample/domains/payroll/rules/payrollEmployeeContext.rule.ts +0 -7
  305. package/src/sample/domains/payroll/services/salaryCertificates.service.ts +0 -15
  306. package/src/sample/domains/servicing/concepts/service.concept.ts +0 -6
  307. package/src/sample/domains/servicing/concepts/serviceRequest.concept.ts +0 -12
  308. package/src/sample/domains/servicing/concepts/serviceRequestApproval.concept.ts +0 -9
  309. package/src/sample/domains/servicing/endpoints/cancelServiceRequest.endpoint.ts +0 -21
  310. package/src/sample/domains/servicing/endpoints/createServiceRequest.endpoint.ts +0 -511
  311. package/src/sample/domains/servicing/endpoints/getServiceRequest.endpoint.ts +0 -352
  312. package/src/sample/domains/servicing/endpoints/getServiceRequestFormItems.endpoint.ts +0 -219
  313. package/src/sample/domains/servicing/endpoints/getServiceRequestTransactionFormItems.endpoint.ts +0 -216
  314. package/src/sample/domains/servicing/endpoints/getServiceStates.endpoint.ts +0 -47
  315. package/src/sample/domains/servicing/endpoints/invokeServiceRequestAction.endpoint.ts +0 -139
  316. package/src/sample/domains/servicing/endpoints/listServiceRequests.endpoint.ts +0 -292
  317. package/src/sample/domains/servicing/endpoints/listServices.endpoint.ts +0 -108
  318. package/src/sample/domains/servicing/endpoints/updateServiceRequest.endpoint.ts +0 -355
  319. package/src/sample/domains/servicing/index.ts +0 -44
  320. package/src/sample/domains/servicing/rules/checkValidActions.rule.ts +0 -7
  321. package/src/sample/domains/servicing/rules/createServiceRequest.rule.ts +0 -7
  322. package/src/sample/domains/servicing/rules/filterServiceRequestsByState.rule.ts +0 -7
  323. package/src/sample/domains/servicing/rules/passingOptionFields.rule.ts +0 -7
  324. package/src/sample/domains/shared/rules/pagination.rule.ts +0 -7
  325. package/src/sample/domains/suggestions/concepts/suggestion.concept.ts +0 -19
  326. package/src/sample/domains/suggestions/concepts/suggestionCategory.concept.ts +0 -7
  327. package/src/sample/domains/suggestions/concepts/suggestionImpactLevel.concept.ts +0 -7
  328. package/src/sample/domains/suggestions/endpoints/createSuggestion.endpoint.ts +0 -705
  329. package/src/sample/domains/suggestions/endpoints/deleteSuggestion.endpoint.ts +0 -32
  330. package/src/sample/domains/suggestions/endpoints/getSuggestionById.endpoint.ts +0 -635
  331. package/src/sample/domains/suggestions/endpoints/listSuggestionCategories.endpoint.ts +0 -62
  332. package/src/sample/domains/suggestions/endpoints/listSuggestionImpactLevels.endpoint.ts +0 -62
  333. package/src/sample/domains/suggestions/endpoints/listSuggestionStates.endpoint.ts +0 -24
  334. package/src/sample/domains/suggestions/endpoints/listSuggestions.endpoint.ts +0 -132
  335. package/src/sample/domains/suggestions/endpoints/updateSuggestion.endpoint.ts +0 -690
  336. package/src/sample/domains/suggestions/endpoints/updateSuggestionState.endpoint.ts +0 -39
  337. package/src/sample/domains/suggestions/index.ts +0 -34
  338. package/src/sample/domains/suggestions/rules/suggestionScope.rule.ts +0 -7
  339. package/src/sample/domains/surveys/concepts/survey.concept.ts +0 -10
  340. package/src/sample/domains/surveys/concepts/surveyResponse.concept.ts +0 -14
  341. package/src/sample/domains/surveys/endpoints/getSurveyResponseById.endpoint.ts +0 -131
  342. package/src/sample/domains/surveys/endpoints/getTargetedSurvey.endpoint.ts +0 -129
  343. package/src/sample/domains/surveys/endpoints/listTargetedSurveys.endpoint.ts +0 -160
  344. package/src/sample/domains/surveys/endpoints/respondToSurvey.endpoint.ts +0 -144
  345. package/src/sample/domains/surveys/index.ts +0 -21
  346. package/src/sample/drizzle.config.ts +0 -11
  347. package/src/sample/index.bak.ts +0 -341
  348. package/src/sample/index.ts +0 -318
  349. package/src/sample/official-statements/defaults.ts +0 -57
  350. package/src/sample/official-statements/routes.ts +0 -137
  351. package/src/sample/official-statements/service.ts +0 -148
  352. package/src/sample/official-statements/types.ts +0 -23
  353. /package/src/lib/db/migrations/{20260326231647_nice_speedball → mssql/20260326231647_nice_speedball}/migration.sql +0 -0
  354. /package/src/lib/db/migrations/{20260326231647_nice_speedball → mssql/20260326231647_nice_speedball}/snapshot.json +0 -0
@@ -0,0 +1,243 @@
1
+ import { z } from "zod";
2
+
3
+ /*
4
+ * The HTTP contract of the cortex-cc runtime API: the console (`apps/cortex-cc`)
5
+ * validates requests against these schemas and `@m6d/cortex-server` validates the
6
+ * responses it gets back. Request types use `z.input` because the callers build
7
+ * payloads the runtime's parser then fills defaults into.
8
+ */
9
+
10
+ /** Runtime contract §1.1: the `:id` path param, validated on both sides of the wire. */
11
+ export const AGENT_SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{0,62}$/;
12
+
13
+ /** Runtime contract §5: tool names become `tools.<name>()` sandbox bindings. */
14
+ export const TOOL_NAME_PATTERN = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
15
+
16
+ export const PROMPT_VARIABLES = ["userName", "channel", "locale", "utcTime", "timezone"] as const;
17
+
18
+ /**
19
+ * One entry per prompt variable, driving editor autocomplete, validation, and
20
+ * runtime substitution alike. Adding a variable = extending the tuple above
21
+ * plus one entry here (the compiler enforces the pair); the consumer embedding
22
+ * the agent supplies the value in its session/request context under the same
23
+ * key. Descriptions are plain English on purpose: variables are code-like
24
+ * identifiers shown in an LTR suggestion list, not localized UI copy.
25
+ */
26
+ export const PROMPT_VARIABLE_DEFINITIONS = {
27
+ userName: {
28
+ description: "Display name of the signed-in user",
29
+ example: "Sara",
30
+ },
31
+ channel: {
32
+ description: "Channel the conversation arrived on",
33
+ example: "web",
34
+ },
35
+ locale: {
36
+ description: "Resolved locale of the session",
37
+ example: "ar",
38
+ },
39
+ // The server computes utcTime per request (a consumer-supplied value
40
+ // still wins); timezone has no server default — only the consumer knows
41
+ // the session's zone, so it must arrive via session/request context or
42
+ // the placeholder stays literal.
43
+ utcTime: {
44
+ description: "Current time in UTC (ISO 8601)",
45
+ example: "2026-08-16T09:30:00Z",
46
+ },
47
+ timezone: {
48
+ description: "IANA time zone of the session",
49
+ example: "Asia/Dubai",
50
+ },
51
+ } satisfies Record<(typeof PROMPT_VARIABLES)[number], { description: string; example: string }>;
52
+
53
+ export const RUNTIME_ERROR_KINDS = [
54
+ "timeout",
55
+ "upstream_4xx",
56
+ "upstream_5xx",
57
+ "schema_mismatch",
58
+ "rate_limited",
59
+ "not_found",
60
+ "unauthorized",
61
+ "invalid_request",
62
+ "egress_blocked",
63
+ "internal",
64
+ ] as const;
65
+
66
+ /** The ways an execute output may disagree with the tool's declared schema. */
67
+ export const JSON_SCHEMA_ISSUE_KINDS = ["missing", "unexpected", "type_mismatch"] as const;
68
+
69
+ export const agentSlugSchema = z.string().regex(AGENT_SLUG_PATTERN);
70
+ export const localeSchema = z.enum(["en", "ar"]);
71
+ export const catalogVersionSchema = z.string().regex(/^[0-9a-f]{16}$/);
72
+
73
+ export const sharedShapeSchema = z.object({
74
+ ref: z.string().regex(/^\$R\d+$/),
75
+ shape: z.string(),
76
+ });
77
+
78
+ export const knowledgeChunkSchema = z.object({
79
+ chunkId: z.uuid(),
80
+ text: z.string(),
81
+ score: z.number(),
82
+ citation: z.object({
83
+ documentId: z.uuid(),
84
+ documentTitle: z.string(),
85
+ page: z.number().int().positive().nullable(),
86
+ section: z.string().nullable(),
87
+ uri: z.url().nullable(),
88
+ service: z.string().nullable(),
89
+ }),
90
+ });
91
+
92
+ export const toolSignatureSchema = z.object({
93
+ toolId: z.uuid(),
94
+ name: z.string().regex(TOOL_NAME_PATTERN),
95
+ version: z.number().int().positive(),
96
+ readOnly: z.boolean(),
97
+ tags: z.array(z.string()),
98
+ signature: z.string(),
99
+ score: z.number().nullable(),
100
+ pinned: z.boolean(),
101
+ });
102
+
103
+ export const serviceCardSchema = z.object({
104
+ serviceId: z.uuid(),
105
+ key: z
106
+ .string()
107
+ .regex(/^[a-z0-9]+(-[a-z0-9]+)*$/)
108
+ .max(64),
109
+ name: z.string(),
110
+ card: z.string(),
111
+ score: z.number(),
112
+ });
113
+
114
+ export const runtimeAgentConfigSchema = z.object({
115
+ agentId: agentSlugSchema,
116
+ systemPrompt: z.string(),
117
+ promptVariables: z.array(z.enum(PROMPT_VARIABLES)),
118
+ catalogBlurb: z.string(),
119
+ defaultLocale: localeSchema,
120
+ metaTools: z.object({
121
+ searchKnowledge: z.boolean(),
122
+ searchTools: z.boolean(),
123
+ searchServices: z.boolean(),
124
+ }),
125
+ limits: z.object({
126
+ resolveTokenBudget: z.number().int().positive(),
127
+ executeTimeoutMs: z.number().int().positive(),
128
+ maxResponseBytes: z.number().int().positive(),
129
+ }),
130
+ catalogVersion: catalogVersionSchema,
131
+ publishedAt: z.iso.datetime(),
132
+ });
133
+
134
+ export const resolveRequestSchema = z.object({
135
+ query: z.string().trim().min(1).max(4000),
136
+ locale: localeSchema.optional(),
137
+ hints: z
138
+ .object({
139
+ threadId: z.string().max(128).optional(),
140
+ recentToolNames: z.array(z.string()).max(20).default([]),
141
+ turnIndex: z.number().int().min(0).optional(),
142
+ })
143
+ .optional(),
144
+ tokenBudget: z.number().int().min(500).max(20000).optional(),
145
+ limits: z
146
+ .object({
147
+ knowledge: z.number().int().min(0).max(20).default(6),
148
+ tools: z.number().int().min(0).max(20).default(8),
149
+ services: z.number().int().min(0).max(20).default(5),
150
+ })
151
+ .optional(),
152
+ });
153
+
154
+ export const resolveResponseSchema = z.object({
155
+ resolveId: z.uuid(),
156
+ catalogVersion: catalogVersionSchema,
157
+ locale: localeSchema,
158
+ knowledge: z.array(knowledgeChunkSchema),
159
+ tools: z.array(toolSignatureSchema),
160
+ services: z.array(serviceCardSchema),
161
+ sharedShapes: z.array(sharedShapeSchema),
162
+ budget: z.object({
163
+ requested: z.number().int(),
164
+ used: z.number().int(),
165
+ truncated: z.boolean(),
166
+ }),
167
+ });
168
+
169
+ export const searchRequestSchema = z.object({
170
+ query: z.string().trim().min(1).max(4000),
171
+ limit: z.number().int().min(1).max(20).default(5),
172
+ locale: localeSchema.optional(),
173
+ threadId: z.string().max(128).optional(),
174
+ service: z.string().max(64).optional(),
175
+ });
176
+
177
+ export const searchToolsResponseSchema = z.object({
178
+ catalogVersion: catalogVersionSchema,
179
+ tools: z.array(toolSignatureSchema),
180
+ sharedShapes: z.array(sharedShapeSchema),
181
+ });
182
+
183
+ export const searchServicesResponseSchema = z.object({
184
+ catalogVersion: catalogVersionSchema,
185
+ services: z.array(serviceCardSchema),
186
+ tools: z.array(toolSignatureSchema),
187
+ sharedShapes: z.array(sharedShapeSchema),
188
+ });
189
+
190
+ export const searchKnowledgeResponseSchema = z.object({
191
+ catalogVersion: catalogVersionSchema,
192
+ knowledge: z.array(knowledgeChunkSchema),
193
+ });
194
+
195
+ export const executeRequestSchema = z.object({
196
+ input: z.record(z.string(), z.unknown()).default({}),
197
+ context: z
198
+ .object({
199
+ threadId: z.string().max(128).optional(),
200
+ userId: z.string().max(128).optional(),
201
+ locale: localeSchema.optional(),
202
+ })
203
+ .optional(),
204
+ });
205
+
206
+ export const executeResponseSchema = z.object({
207
+ toolId: z.uuid(),
208
+ name: z.string(),
209
+ version: z.number().int().positive(),
210
+ output: z.unknown(),
211
+ meta: z.object({
212
+ upstreamStatus: z.number().int().min(100).max(599),
213
+ durationMs: z.number().int().min(0),
214
+ replayed: z.boolean(),
215
+ truncated: z.boolean(),
216
+ truncatedPaths: z.array(z.string()),
217
+ drift: z.array(
218
+ z.object({
219
+ path: z.string(),
220
+ kind: z.enum(JSON_SCHEMA_ISSUE_KINDS),
221
+ }),
222
+ ),
223
+ }),
224
+ });
225
+
226
+ const runtimeErrorKindSchema = z.enum(RUNTIME_ERROR_KINDS);
227
+ export type RuntimeErrorKind = z.infer<typeof runtimeErrorKindSchema>;
228
+
229
+ export const runtimeErrorSchema = z.object({
230
+ error: z.object({
231
+ kind: runtimeErrorKindSchema,
232
+ detail: z.string().max(512),
233
+ retryable: z.boolean(),
234
+ retryAfterSeconds: z.number().int().positive().optional(),
235
+ upstreamStatus: z.number().int().min(100).max(599).optional(),
236
+ }),
237
+ });
238
+
239
+ export type RuntimeAgentConfig = z.infer<typeof runtimeAgentConfigSchema>;
240
+ export type ResolveRequest = z.input<typeof resolveRequestSchema>;
241
+ export type ResolveResponse = z.infer<typeof resolveResponseSchema>;
242
+ export type SearchRequest = z.input<typeof searchRequestSchema>;
243
+ export type ExecuteRequest = z.input<typeof executeRequestSchema>;
@@ -0,0 +1,143 @@
1
+ /**
2
+ * The wire contract — every shape that crosses the HTTP/WebSocket boundary
3
+ * between `@m6d/cortex-server` and the client SDKs (`@m6d/cortex-angular`,
4
+ * `@m6d/cortex-react`).
5
+ *
6
+ * Nothing here has a runtime dependency, and nothing here may grow one: this
7
+ * file is compiled into an Angular library, a React library and a Bun server
8
+ * alike.
9
+ */
10
+
11
+ export const ATTACHMENT_MIME_TYPES = [
12
+ "image/png",
13
+ "image/jpeg",
14
+ "image/webp",
15
+ "application/pdf",
16
+ ] as const;
17
+
18
+ export const ATTACHMENT_MAX_BYTES = 10 * 1024 * 1024;
19
+
20
+ export const MAX_ATTACHMENTS_PER_MESSAGE = 5;
21
+
22
+ export const ATTACHMENT_STATUSES = ["pending", "described", "failed", "skipped"] as const;
23
+
24
+ export function checkAttachmentPolicy(contentType: string, sizeBytes: number) {
25
+ if (!ATTACHMENT_MIME_TYPES.some((type) => type === contentType)) return "type";
26
+ if (sizeBytes > ATTACHMENT_MAX_BYTES) return "size";
27
+ return "ok";
28
+ }
29
+
30
+ export type AttachmentStatus = (typeof ATTACHMENT_STATUSES)[number];
31
+
32
+ export type AttachmentSummary = {
33
+ id: string;
34
+ filename: string;
35
+ contentType: string;
36
+ sizeBytes: number;
37
+ status: AttachmentStatus;
38
+ description?: string;
39
+ };
40
+
41
+ export type ThreadSummary = {
42
+ id: string;
43
+ title?: string;
44
+ createdAt: string;
45
+ updatedAt: string;
46
+ isRunning: boolean;
47
+ };
48
+
49
+ /**
50
+ * Response of `POST /chat/:chatId/abort`. `aborted: false` means there was no
51
+ * live run to abort — the turn had already committed — so the caller must not
52
+ * present the turn as aborted and should read the settled state back instead.
53
+ */
54
+ export type AbortRunResult = {
55
+ aborted: boolean;
56
+ };
57
+
58
+ export type TokenUsage = {
59
+ input: {
60
+ noCache: number;
61
+ cacheRead: number;
62
+ cacheWrite: number;
63
+ total: number;
64
+ };
65
+ output: {
66
+ reasoning: number;
67
+ text: number;
68
+ total: number;
69
+ };
70
+ total: number;
71
+ };
72
+
73
+ export type MessageMetadata = {
74
+ modelId?: string;
75
+ providerMetadata?: unknown;
76
+ isAborted?: boolean;
77
+ tokenUsage?: TokenUsage;
78
+ attachments?: AttachmentSummary[];
79
+ };
80
+
81
+ /**
82
+ * A stored message as it is persisted and served. TanStack AI's `UIMessage`
83
+ * has no metadata field, so cortex owns the envelope: the SDK's parts plus the
84
+ * server-derived metadata the UI renders on settled messages.
85
+ *
86
+ * `TPart` stays generic so this file keeps its zero dependencies — both
87
+ * sides substitute the SDK's `MessagePart`.
88
+ */
89
+ export type CortexMessage<TPart = unknown> = {
90
+ id: string;
91
+ role: "system" | "user" | "assistant";
92
+ parts: TPart[];
93
+ metadata?: MessageMetadata;
94
+ };
95
+
96
+ export type ThreadCreatedEvent = {
97
+ type: "thread:created";
98
+ payload: { thread: ThreadSummary };
99
+ };
100
+
101
+ export type ThreadDeletedEvent = {
102
+ type: "thread:deleted";
103
+ payload: { threadId: string };
104
+ };
105
+
106
+ export type ThreadTitleUpdatedEvent = {
107
+ type: "thread:title-updated";
108
+ payload: { thread: ThreadSummary };
109
+ };
110
+
111
+ export type ThreadRunStartedEvent = {
112
+ type: "thread:run-started";
113
+ payload: { thread: ThreadSummary };
114
+ };
115
+
116
+ export type ThreadRunFinishedEvent = {
117
+ type: "thread:run-finished";
118
+ payload: { thread: ThreadSummary };
119
+ };
120
+
121
+ export type ThreadMessagesUpdatedEvent = {
122
+ type: "thread:messages-updated";
123
+ payload: { threadId: string; thread: ThreadSummary };
124
+ };
125
+
126
+ export type ToolProgressEvent = {
127
+ type: "thread:tool-progress";
128
+ payload: {
129
+ threadId: string;
130
+ toolCallId: string;
131
+ toolName: string;
132
+ status: "started" | "finished";
133
+ };
134
+ };
135
+
136
+ export type WsEvent =
137
+ | ThreadCreatedEvent
138
+ | ThreadDeletedEvent
139
+ | ThreadTitleUpdatedEvent
140
+ | ThreadRunStartedEvent
141
+ | ThreadRunFinishedEvent
142
+ | ThreadMessagesUpdatedEvent
143
+ | ToolProgressEvent;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Embeddings, which both halves of the graph need: `@m6d/cortex-cli` embeds every
3
+ * concept description as it seeds, `@m6d/cortex-server` embeds every prompt as it
4
+ * resolves. Two embedders would mean two vector spaces, so there is one.
5
+ *
6
+ * TanStack AI removed embeddings, and the graph only ever needed the plain
7
+ * OpenAI-compatible `/embeddings` call cortex is already configured for — so this
8
+ * is a bare `fetch`, and this package keeps its zero dependencies.
9
+ *
10
+ * Everything under `./graph` is written to the oldest target any consumer builds
11
+ * against — an Angular library compiles these sources directly — and imports
12
+ * siblings by their `.js` specifier so one emit serves both `dist` and source.
13
+ */
14
+ /** Everything cortex needs to reach one OpenAI-compatible embeddings endpoint. */
15
+ export type EmbeddingProviderConfig = {
16
+ baseURL: string;
17
+ apiKey: string;
18
+ modelName: string;
19
+ };
20
+ /** Turns a batch of strings into their vectors, in the order given. */
21
+ export type EmbedFn = (values: string[]) => Promise<number[][]>;
22
+ export declare function createEmbedder(config: EmbeddingProviderConfig): (values: string[]) => Promise<number[][]>;
@@ -1,39 +1,41 @@
1
1
  /**
2
- * Helper functions for building knowledge graph seed data.
2
+ * Helper functions for building knowledge graph seed data. Projects author
3
+ * domains with these; `@m6d/cortex-server` re-exports them so authoring needs
4
+ * exactly one import path.
3
5
  */
4
- import type { ConceptDef, DomainDef, EndpointDef, EndpointInput, RuleDef, ServiceDef } from "./types.ts";
6
+ import type { ConceptDef, DomainDef, EndpointDef, EndpointInput, RuleDef, ServiceDef } from "./types";
5
7
  export declare function defineConcept(def: Omit<ConceptDef, "__brand">): {
6
- name: string;
7
8
  description: string;
9
+ name: string;
8
10
  aliases?: string[] | undefined;
11
+ metadata?: Record<string, unknown> | undefined;
9
12
  parentConcept?: ConceptDef | undefined;
10
13
  governedBy?: RuleDef[] | undefined;
11
- metadata?: Record<string, unknown> | undefined;
12
14
  __brand: "concept";
13
15
  };
14
16
  export declare function defineRule(def: Omit<RuleDef, "__brand">): {
15
- name: string;
16
17
  description: string;
18
+ name: string;
17
19
  metadata?: Record<string, unknown> | undefined;
18
20
  __brand: "rule";
19
21
  };
20
22
  export declare function defineService(def: Omit<ServiceDef, "__brand">): {
21
- name: string;
22
23
  description: string;
23
- governedBy?: RuleDef[] | undefined;
24
+ name: string;
24
25
  metadata?: Record<string, unknown> | undefined;
25
26
  builtInId: string;
27
+ governedBy?: RuleDef[] | undefined;
26
28
  belongsTo: ConceptDef;
27
29
  __brand: "service";
28
30
  };
29
31
  export declare function defineDomain(def: Omit<DomainDef, "__brand">): {
30
- name: string;
31
32
  description: string;
33
+ name: string;
32
34
  metadata?: Record<string, unknown> | undefined;
33
- rules?: RuleDef[] | undefined;
34
35
  concepts?: ConceptDef[] | undefined;
35
- services?: ServiceDef[] | undefined;
36
36
  endpoints?: EndpointDef[] | undefined;
37
+ services?: ServiceDef[] | undefined;
38
+ rules?: RuleDef[] | undefined;
37
39
  __brand: "domain";
38
40
  };
39
41
  export declare function defineEndpoint(input: EndpointInput): {
@@ -43,12 +45,12 @@ export declare function defineEndpoint(input: EndpointInput): {
43
45
  path: string;
44
46
  method: "GET" | "POST" | "PUT" | "DELETE";
45
47
  propertiesDescriptions: Record<string, string>;
46
- params: import("./types.ts").EndpointProperty[];
47
- body: import("./types.ts").EndpointProperty[];
48
- response: import("./types.ts").EndpointProperty[];
48
+ params: import("./types").EndpointProperty[];
49
+ body: import("./types").EndpointProperty[];
50
+ response: import("./types").EndpointProperty[];
49
51
  successStatus: number;
50
52
  errorStatuses: number[];
51
- responseKind: import("./types.ts").ResponseKind;
53
+ responseKind: import("./types").ResponseKind;
52
54
  queries: ConceptDef[] | undefined;
53
55
  mutates: ConceptDef[] | undefined;
54
56
  returns: {
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Configurable Neo4j HTTP client.
2
+ * Configurable Neo4j HTTP client, shared by the graph's writer and its reader.
3
3
  *
4
- * Replaces the hardcoded process.env-based client from packages/sample-backend.
5
- * All configuration is passed explicitly no environment variables are read.
4
+ * All configuration is passed explicitly no environment variables are read —
5
+ * and the transport is `fetch`, so this package stays dependency-free.
6
6
  */
7
- import type { EmbeddingModel } from "ai";
7
+ import type { EmbedFn } from "./embed";
8
8
  export type Neo4jConfig = {
9
9
  url: string;
10
10
  user: string;
@@ -13,6 +13,6 @@ export type Neo4jConfig = {
13
13
  export type Neo4jClient = {
14
14
  query(cypher: string, parameters?: Record<string, unknown>): Promise<string>;
15
15
  };
16
- export declare function createNeo4jClient(config: Neo4jConfig, embeddingModel?: EmbeddingModel): {
16
+ export declare function createNeo4jClient(config: Neo4jConfig, embed?: EmbedFn): {
17
17
  query: (cypher: string, parameters?: Record<string, unknown>) => Promise<string>;
18
18
  };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The contract between the graph's writer and its reader.
3
+ *
4
+ * Seeding lives in `@m6d/cortex-cli` and resolution lives in `@m6d/cortex-server`,
5
+ * two packages a project installs and upgrades separately. The labels, relationship
6
+ * types, property names and index name they agree on are this module, here, so
7
+ * neither side owns the vocabulary the other has to match.
8
+ *
9
+ * A mismatch between the two is invisible at runtime: the resolver's Cypher
10
+ * matches nothing and retrieval comes back empty rather than failing. That is what
11
+ * `GRAPH_SCHEMA_VERSION` is for — bump it on any change to the shape below. The
12
+ * CLI stamps the version it wrote onto the graph and the server checks that stamp
13
+ * on its first resolve, so skew surfaces as an error instead of as silence.
14
+ */
15
+ export declare const GRAPH_SCHEMA_VERSION = 1;
16
+ export declare const GRAPH_SCHEMA: {
17
+ readonly label: {
18
+ readonly domain: "Domain";
19
+ readonly concept: "Concept";
20
+ readonly endpoint: "Endpoint";
21
+ readonly service: "Service";
22
+ readonly rule: "Rule";
23
+ /** Stamped with the version above, so a stale graph is detectable later. */
24
+ readonly marker: "CortexGraph";
25
+ };
26
+ readonly rel: {
27
+ readonly belongsTo: "BELONGS_TO";
28
+ readonly specializes: "SPECIALIZES";
29
+ readonly queriedVia: "QUERIED_VIA";
30
+ readonly mutatedVia: "MUTATED_VIA";
31
+ readonly returns: "RETURNS";
32
+ readonly dependsOn: "DEPENDS_ON";
33
+ readonly governs: "GOVERNS";
34
+ readonly requestedVia: "REQUESTED_VIA";
35
+ };
36
+ readonly prop: {
37
+ readonly name: "name";
38
+ readonly description: "description";
39
+ readonly aliases: "aliases";
40
+ readonly metadata: "metadata";
41
+ readonly path: "path";
42
+ readonly method: "method";
43
+ readonly params: "params";
44
+ readonly body: "body";
45
+ readonly response: "response";
46
+ readonly propertiesDescriptions: "propertiesDescriptions";
47
+ readonly successStatus: "successStatus";
48
+ readonly errorStatuses: "errorStatuses";
49
+ readonly builtInId: "builtInId";
50
+ readonly embedding: "embedding";
51
+ /** On a RETURNS edge: which part of the response carries the concept. */
52
+ readonly field: "field";
53
+ /** On a DEPENDS_ON edge. */
54
+ readonly paramName: "paramName";
55
+ readonly fromField: "fromField";
56
+ /** On the marker node. */
57
+ readonly version: "version";
58
+ };
59
+ /** Created by the CLI's seeder, queried by name in the resolver's first hop. */
60
+ readonly conceptEmbeddingsIndex: "concept_embeddings";
61
+ };
62
+ export type GraphSchema = typeof GRAPH_SCHEMA;
@@ -10,7 +10,7 @@ export type EndpointScalarType = "uuid" | "number" | "date" | "datetime" | "stri
10
10
  export type EndpointProperty = {
11
11
  readonly name: string;
12
12
  readonly required: boolean;
13
- readonly type: EndpointScalarType | string;
13
+ readonly type: EndpointScalarType | (string & NonNullable<unknown>);
14
14
  readonly isArray?: boolean;
15
15
  readonly properties?: readonly EndpointProperty[];
16
16
  readonly description?: string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The graph contract — the knowledge-graph vocabulary, authoring types and
3
+ * clients that `@m6d/cortex-cli` writes with and `@m6d/cortex-server` reads
4
+ * with. `@m6d/cortex-server` re-exports all of it, so a project authoring
5
+ * domains still has exactly one import path.
6
+ */
7
+ export type { GraphSchema } from "./graph/schema";
8
+ export { GRAPH_SCHEMA, GRAPH_SCHEMA_VERSION } from "./graph/schema";
9
+ export type { EndpointScalarType, EndpointProperty, ResponseKind, AutoGenerated, ConceptDef, EndpointDef, EndpointInput, ServiceDef, RuleDef, DomainDef, } from "./graph/types";
10
+ export { defineConcept, defineRule, defineService, defineDomain, defineEndpoint, } from "./graph/helpers";
11
+ export type { Neo4jConfig, Neo4jClient } from "./graph/neo4j";
12
+ export { createNeo4jClient } from "./graph/neo4j";
13
+ export type { EmbedFn, EmbeddingProviderConfig } from "./graph/embed";
14
+ export { createEmbedder } from "./graph/embed";
@@ -0,0 +1,32 @@
1
+ /** One mention token, unanchored and flagless — the editor's tokenizer anchors it, the helpers below add `g`. */
2
+ export declare const MENTION_PATTERN_SOURCE: string;
3
+ export declare function extractMentionedToolIds(text: string): string[];
4
+ /** Replaces each mention token with the tool's current name (falling back to the cached inline name). */
5
+ export declare function renderMentions(text: string, toolNameById: ReadonlyMap<string, string>): string;
6
+ /** Refreshes stale display names inside stored text, keeping the tokens intact. */
7
+ export declare function normalizeMentions(text: string, toolNameById: ReadonlyMap<string, string>): string;
8
+ /** Splits the `{{variables}}` referenced in a text into known and unknown ones. */
9
+ export declare function analyzeVariables<Variable extends string>(text: string, known: ReadonlyArray<Variable>): {
10
+ variables: Variable[];
11
+ unknownVariables: string[];
12
+ };
13
+ /** Fills `{{variables}}` with per-request values; unknown names stay verbatim. */
14
+ export declare function substituteVariables(text: string, values: Record<string, string>): string;
15
+ /**
16
+ * Shifts user-authored headings down so they can never collide with the prompt
17
+ * skeleton, which owns `##` (sections) and `###` (card titles): `#` becomes
18
+ * `####`, deeper levels cap at `######`. Setext headings are rewritten as the
19
+ * equivalent demoted ATX heading, since two-level setext cannot express the
20
+ * shift. Fenced code is left alone.
21
+ */
22
+ export declare function demoteHeadings(text: string): string;
23
+ /** The one render step for LLM-bound rich text: resolve mentions, then demote headings. */
24
+ export declare function renderRichText(text: string, toolNameById: ReadonlyMap<string, string>): string;
25
+ /**
26
+ * Reduces rich text to plain prose for embeddings: mentions become tool names
27
+ * (cached inline names when no map is given) and markdown syntax is dropped.
28
+ * ponytail: a regex stripper, not a markdown parser — nested emphasis or exotic
29
+ * constructs may leave residue; swap in a real parser if retrieval quality
30
+ * ever shows it.
31
+ */
32
+ export declare function stripToPlaintext(text: string, toolNameById?: ReadonlyMap<string, string>): string;