@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.
- package/README.md +8 -3
- package/contracts/README.md +23 -0
- package/contracts/graph/embed.ts +50 -0
- package/{src/lib → contracts}/graph/helpers.ts +4 -10
- package/{src/lib → contracts}/graph/neo4j.ts +14 -27
- package/contracts/graph/schema.ts +65 -0
- package/{src/lib → contracts}/graph/types.ts +2 -29
- package/contracts/graph.ts +36 -0
- package/contracts/rich-text.ts +207 -0
- package/contracts/runtime.ts +243 -0
- package/contracts/wire.ts +143 -0
- package/dist/contracts/graph/embed.d.ts +22 -0
- package/dist/{src/lib → contracts}/graph/helpers.d.ts +16 -14
- package/dist/{src/lib → contracts}/graph/neo4j.d.ts +5 -5
- package/dist/contracts/graph/schema.d.ts +62 -0
- package/dist/{src/lib → contracts}/graph/types.d.ts +1 -1
- package/dist/contracts/graph.d.ts +14 -0
- package/dist/contracts/rich-text.d.ts +32 -0
- package/dist/contracts/runtime.d.ts +310 -0
- package/dist/contracts/wire.d.ts +120 -0
- package/dist/src/lib/adapters/database/index.d.ts +61 -0
- package/dist/src/lib/adapters/database/message-content.d.ts +30 -0
- package/dist/src/lib/adapters/database/mssql/attachments.d.ts +100 -0
- package/dist/src/lib/adapters/database/mssql/client.d.ts +8 -0
- package/dist/src/lib/adapters/database/mssql/index.d.ts +194 -0
- package/dist/src/lib/adapters/database/mssql/llm-requests.d.ts +17 -0
- package/dist/src/lib/adapters/database/mssql/messages.d.ts +37 -0
- package/dist/src/lib/adapters/database/mssql/threads.d.ts +50 -0
- package/dist/src/lib/adapters/database/postgres/attachments.d.ts +113 -0
- package/dist/src/lib/adapters/database/postgres/client.d.ts +8 -0
- package/dist/src/lib/adapters/database/postgres/index.d.ts +207 -0
- package/dist/src/lib/adapters/database/postgres/llm-requests.d.ts +17 -0
- package/dist/src/lib/adapters/database/postgres/messages.d.ts +37 -0
- package/dist/src/lib/adapters/database/postgres/threads.d.ts +50 -0
- package/{src/lib/adapters/storage.ts → dist/src/lib/adapters/storage/index.d.ts} +1 -1
- package/dist/src/lib/adapters/{minio.d.ts → storage/minio.d.ts} +1 -1
- package/dist/src/lib/ai/active-runs.d.ts +63 -0
- package/dist/src/lib/ai/attachments.d.ts +30 -0
- package/dist/src/lib/ai/backend-url.d.ts +16 -0
- package/dist/src/lib/ai/cc-runtime.d.ts +61 -0
- package/dist/src/lib/ai/commit-gate.d.ts +21 -0
- package/dist/src/lib/ai/context/builder.d.ts +6 -7
- package/dist/src/lib/ai/context/compression-middleware.d.ts +15 -0
- package/dist/src/lib/ai/context/compressor.d.ts +2 -13
- package/dist/src/lib/ai/context/intra-turn-compressor.d.ts +9 -9
- package/dist/src/lib/ai/context/optimize-thread-context.d.ts +9 -0
- package/dist/src/lib/ai/context/summarizer.d.ts +3 -3
- package/dist/src/lib/ai/context/token-estimator.d.ts +5 -8
- package/dist/src/lib/ai/fetch.d.ts +1 -1
- package/dist/src/lib/ai/finish-turn.d.ts +23 -0
- package/dist/src/lib/ai/helpers.d.ts +37 -4
- package/dist/src/lib/ai/index.d.ts +6 -3
- package/dist/src/lib/ai/inspector.d.ts +41 -0
- package/dist/src/lib/ai/interceptors/request-interceptor.d.ts +6 -5
- package/dist/src/lib/ai/prompt.d.ts +5 -4
- package/dist/src/lib/ai/redis-runs.d.ts +41 -0
- package/dist/src/lib/ai/redis-stream-log.d.ts +39 -0
- package/dist/src/lib/ai/tools/execute-code.tool.d.ts +18 -4
- package/dist/src/lib/ai/tools/query-graph.tool.d.ts +13 -5
- package/dist/src/lib/ai/tools/read-attachment.tool.d.ts +21 -0
- package/dist/src/lib/ai/tools/search-common.d.ts +17 -0
- package/dist/src/lib/ai/tools/search-knowledge.tool.d.ts +15 -0
- package/dist/src/lib/ai/tools/search-services.tool.d.ts +12 -0
- package/dist/src/lib/ai/tools/search-tools.tool.d.ts +12 -0
- package/dist/src/lib/ai/turn-tools.d.ts +39 -0
- package/dist/src/lib/ai/vision/rasterize-pdf.d.ts +26 -0
- package/dist/src/lib/ai/vision/rasterize-pdf.worker.d.ts +1 -0
- package/dist/src/lib/ai/vision/vision-reader.d.ts +45 -0
- package/dist/src/lib/cc/client.d.ts +183 -0
- package/dist/src/lib/cc/config-cache.d.ts +20 -0
- package/dist/src/lib/cc/format.d.ts +23 -0
- package/dist/src/lib/cc/registry.d.ts +34 -0
- package/dist/src/lib/cc/types.d.ts +27 -0
- package/dist/src/lib/config.d.ts +81 -64
- package/dist/src/lib/db/drizzle.config.mssql.d.ts +2 -0
- package/dist/src/lib/db/drizzle.config.pg.d.ts +2 -0
- package/dist/src/lib/db/migrate.d.ts +7 -1
- package/dist/src/lib/db/{schema.d.ts → schema.mssql.d.ts} +138 -29
- package/dist/src/lib/db/schema.pg.d.ts +546 -0
- package/dist/src/lib/factory.d.ts +2 -12
- package/dist/src/lib/graph/index.d.ts +10 -11
- package/dist/src/lib/graph/resolver.d.ts +2 -3
- package/dist/src/lib/index.d.ts +3 -3
- package/dist/src/lib/redis.d.ts +19 -0
- package/dist/src/lib/routes/chat.d.ts +1 -1
- package/dist/src/lib/routes/files.d.ts +1 -1
- package/dist/src/lib/routes/owned-thread.d.ts +17 -0
- package/dist/src/lib/routes/threads.d.ts +1 -1
- package/dist/src/lib/routes/ws.d.ts +1 -1
- package/dist/src/lib/types.d.ts +20 -37
- package/dist/src/lib/ws/connections.d.ts +2 -1
- package/package.json +33 -18
- package/src/lib/adapters/database/index.ts +78 -0
- package/src/lib/adapters/database/message-content.ts +39 -0
- package/src/lib/adapters/database/mssql/attachments.ts +90 -0
- package/src/lib/adapters/database/mssql/client.ts +11 -0
- package/src/lib/adapters/database/mssql/index.ts +23 -0
- package/src/lib/adapters/database/mssql/llm-requests.ts +43 -0
- package/src/lib/adapters/database/mssql/messages.ts +92 -0
- package/src/lib/adapters/database/mssql/threads.ts +83 -0
- package/src/lib/adapters/database/postgres/attachments.ts +88 -0
- package/src/lib/adapters/database/postgres/client.ts +11 -0
- package/src/lib/adapters/database/postgres/index.ts +23 -0
- package/src/lib/adapters/database/postgres/llm-requests.ts +45 -0
- package/src/lib/adapters/database/postgres/messages.ts +92 -0
- package/src/lib/adapters/database/postgres/threads.ts +84 -0
- package/{dist/src/lib/adapters/storage.d.ts → src/lib/adapters/storage/index.ts} +1 -1
- package/src/lib/adapters/{minio.ts → storage/minio.ts} +5 -5
- package/src/lib/ai/active-runs.ts +157 -0
- package/src/lib/ai/attachments.ts +144 -0
- package/src/lib/ai/backend-url.ts +27 -0
- package/src/lib/ai/cc-runtime.ts +63 -0
- package/src/lib/ai/commit-gate.ts +116 -0
- package/src/lib/ai/context/builder.ts +12 -14
- package/src/lib/ai/context/compression-middleware.ts +44 -0
- package/src/lib/ai/context/compressor.ts +67 -59
- package/src/lib/ai/context/intra-turn-compressor.ts +121 -204
- package/src/lib/ai/context/optimize-thread-context.ts +50 -0
- package/src/lib/ai/context/summarizer.ts +28 -30
- package/src/lib/ai/context/token-estimator.ts +35 -30
- package/src/lib/ai/fetch.ts +10 -5
- package/src/lib/ai/finish-turn.ts +75 -0
- package/src/lib/ai/helpers.ts +83 -15
- package/src/lib/ai/index.ts +366 -329
- package/src/lib/ai/inspector.ts +112 -0
- package/src/lib/ai/interceptors/request-interceptor.ts +70 -42
- package/src/lib/ai/prompt.ts +126 -125
- package/src/lib/ai/redis-runs.ts +167 -0
- package/src/lib/ai/redis-stream-log.ts +219 -0
- package/src/lib/ai/tools/execute-code.tool.ts +178 -67
- package/src/lib/ai/tools/query-graph.tool.ts +7 -8
- package/src/lib/ai/tools/read-attachment.tool.ts +59 -0
- package/src/lib/ai/tools/search-common.ts +15 -0
- package/src/lib/ai/tools/search-knowledge.tool.ts +33 -0
- package/src/lib/ai/tools/search-services.tool.ts +31 -0
- package/src/lib/ai/tools/search-tools.tool.ts +29 -0
- package/src/lib/ai/turn-tools.ts +154 -0
- package/src/lib/ai/vision/rasterize-pdf.ts +69 -0
- package/src/lib/ai/vision/rasterize-pdf.worker.ts +81 -0
- package/src/lib/ai/vision/vision-reader.ts +130 -0
- package/src/lib/auth/middleware.ts +5 -3
- package/src/lib/cc/client.ts +273 -0
- package/src/lib/cc/config-cache.ts +32 -0
- package/src/lib/cc/format.ts +92 -0
- package/src/lib/cc/registry.ts +62 -0
- package/src/lib/cc/types.ts +44 -0
- package/src/lib/config.ts +102 -71
- package/src/lib/db/drizzle.config.mssql.ts +9 -0
- package/src/lib/db/drizzle.config.pg.ts +9 -0
- package/src/lib/db/migrate.ts +45 -10
- package/src/lib/db/migrations/mssql/20260729092726_talented_wilson_fisk/migration.sql +20 -0
- package/src/lib/db/migrations/mssql/20260729092726_talented_wilson_fisk/snapshot.json +497 -0
- package/src/lib/db/migrations/mssql/20260801003652_perpetual_blue_shield/migration.sql +1 -0
- package/src/lib/db/migrations/mssql/20260801003652_perpetual_blue_shield/snapshot.json +516 -0
- package/src/lib/db/migrations/mssql/20260812174642_user_id_text/migration.sql +2 -0
- package/src/lib/db/migrations/mssql/20260812174642_user_id_text/snapshot.json +516 -0
- package/src/lib/db/migrations/pg/20260801084117_thick_ben_grimm/migration.sql +53 -0
- package/src/lib/db/migrations/pg/20260801084117_thick_ben_grimm/snapshot.json +584 -0
- package/src/lib/db/migrations/pg/20260812174622_user_id_text/migration.sql +2 -0
- package/src/lib/db/migrations/pg/20260812174622_user_id_text/snapshot.json +584 -0
- package/src/lib/db/{schema.ts → schema.mssql.ts} +29 -18
- package/src/lib/db/schema.pg.ts +95 -0
- package/src/lib/factory.ts +44 -89
- package/src/lib/graph/index.ts +12 -40
- package/src/lib/graph/resolver.ts +146 -116
- package/src/lib/index.ts +11 -4
- package/src/lib/redis.ts +44 -0
- package/src/lib/routes/chat.ts +91 -62
- package/src/lib/routes/files.ts +105 -83
- package/src/lib/routes/owned-thread.ts +17 -0
- package/src/lib/routes/threads.ts +14 -30
- package/src/lib/routes/ws.ts +9 -3
- package/src/lib/types.ts +37 -36
- package/src/lib/ws/connections.ts +9 -1
- package/tsconfig.json +48 -0
- package/dist/src/lib/adapters/database.d.ts +0 -45
- package/dist/src/lib/adapters/mssql.d.ts +0 -3
- package/dist/src/lib/ai/active-streams.d.ts +0 -14
- package/dist/src/lib/ai/context/index.d.ts +0 -16
- package/dist/src/lib/ai/tools/capture-files.tool.d.ts +0 -6
- package/dist/src/lib/cli/extract-endpoints.d.ts +0 -6
- package/dist/src/lib/graph/expand-domains.d.ts +0 -2
- package/dist/src/lib/graph/generate-cypher.d.ts +0 -22
- package/dist/src/lib/graph/seed.d.ts +0 -19
- package/dist/src/lib/graph/validate.d.ts +0 -2
- package/dist/src/lib/routes/index.d.ts +0 -4
- package/dist/src/lib/ws/events.d.ts +0 -39
- package/dist/src/lib/ws/index.d.ts +0 -3
- package/dist/src/lib/ws/notify.d.ts +0 -2
- package/src/lib/adapters/database.ts +0 -48
- package/src/lib/adapters/mssql.ts +0 -231
- package/src/lib/ai/active-streams.ts +0 -123
- package/src/lib/ai/context/index.ts +0 -80
- package/src/lib/ai/tools/capture-files.tool.ts +0 -20
- package/src/lib/cli/extract-endpoints.ts +0 -550
- package/src/lib/graph/expand-domains.ts +0 -276
- package/src/lib/graph/generate-cypher.ts +0 -192
- package/src/lib/graph/seed.ts +0 -162
- package/src/lib/graph/validate.ts +0 -78
- package/src/lib/routes/index.ts +0 -4
- package/src/lib/ws/events.ts +0 -39
- package/src/lib/ws/index.ts +0 -11
- package/src/lib/ws/notify.ts +0 -9
- package/src/sample/db/client.ts +0 -9
- package/src/sample/db/migrations/20260411023125_rich_purple_man/migration.sql +0 -5
- package/src/sample/db/migrations/20260411023125_rich_purple_man/snapshot.json +0 -50
- package/src/sample/db/schema.ts +0 -10
- package/src/sample/domains/account/concepts/session.concept.ts +0 -17
- package/src/sample/domains/account/endpoints/listCurrentSessions.endpoint.ts +0 -31
- package/src/sample/domains/account/endpoints/revokeAllOtherSessions.endpoint.ts +0 -22
- package/src/sample/domains/account/endpoints/revokeCurrentSession.endpoint.ts +0 -33
- package/src/sample/domains/account/index.ts +0 -18
- package/src/sample/domains/appraisals/concepts/appraisalCycle.concept.ts +0 -15
- package/src/sample/domains/appraisals/concepts/appraisalRecord.concept.ts +0 -20
- package/src/sample/domains/appraisals/concepts/appraisalRecordCompetency.concept.ts +0 -10
- package/src/sample/domains/appraisals/concepts/appraisalRecordFunctionalRequirement.concept.ts +0 -10
- package/src/sample/domains/appraisals/concepts/appraisalRecordGoal.concept.ts +0 -17
- package/src/sample/domains/appraisals/endpoints/getAppraisalRecordById.endpoint.ts +0 -321
- package/src/sample/domains/appraisals/endpoints/getAppraisalRecordCompetencies.endpoint.ts +0 -120
- package/src/sample/domains/appraisals/endpoints/getAppraisalRecordFunctionalRequirements.endpoint.ts +0 -126
- package/src/sample/domains/appraisals/endpoints/getAppraisalRecordGoals.endpoint.ts +0 -104
- package/src/sample/domains/appraisals/endpoints/getAppraisalRecordScore.endpoint.ts +0 -58
- package/src/sample/domains/appraisals/endpoints/listAppraisalCyclesSimple.endpoint.ts +0 -52
- package/src/sample/domains/appraisals/endpoints/listAppraisalRecords.endpoint.ts +0 -245
- package/src/sample/domains/appraisals/endpoints/listAppraisalTemplatesSimple.endpoint.ts +0 -52
- package/src/sample/domains/appraisals/index.ts +0 -40
- package/src/sample/domains/appraisals/rules/appraisalRecordScoping.rule.ts +0 -7
- package/src/sample/domains/attendance/concepts/attendancePermission.concept.ts +0 -17
- package/src/sample/domains/attendance/concepts/attendanceTransaction.concept.ts +0 -17
- package/src/sample/domains/attendance/concepts/publicHoliday.concept.ts +0 -10
- package/src/sample/domains/attendance/concepts/punch.concept.ts +0 -19
- package/src/sample/domains/attendance/endpoints/getAttendanceTransactionById.endpoint.ts +0 -444
- package/src/sample/domains/attendance/endpoints/getCurrentAttendanceProfile.endpoint.ts +0 -886
- package/src/sample/domains/attendance/endpoints/getCurrentAttendanceStatistics.endpoint.ts +0 -49
- package/src/sample/domains/attendance/endpoints/listAttendancePermissions.endpoint.ts +0 -176
- package/src/sample/domains/attendance/endpoints/listAttendanceTransactionStates.endpoint.ts +0 -26
- package/src/sample/domains/attendance/endpoints/listAttendanceTransactions.endpoint.ts +0 -373
- package/src/sample/domains/attendance/endpoints/listPublicHolidaysSimple.endpoint.ts +0 -52
- package/src/sample/domains/attendance/endpoints/listPunchTypes.endpoint.ts +0 -25
- package/src/sample/domains/attendance/endpoints/listPunches.endpoint.ts +0 -178
- package/src/sample/domains/attendance/index.ts +0 -41
- package/src/sample/domains/attendance/services/attendancePermissions.service.ts +0 -15
- package/src/sample/domains/employees/concepts/employee.concept.ts +0 -20
- package/src/sample/domains/employees/concepts/employeeBankAccount.concept.ts +0 -19
- package/src/sample/domains/employees/concepts/employeeChild.concept.ts +0 -19
- package/src/sample/domains/employees/concepts/employeeDocument.concept.ts +0 -21
- package/src/sample/domains/employees/concepts/employeeEvent.concept.ts +0 -21
- package/src/sample/domains/employees/concepts/employeeExperience.concept.ts +0 -18
- package/src/sample/domains/employees/concepts/employeeJobLevelChange.concept.ts +0 -21
- package/src/sample/domains/employees/concepts/employeeMedal.concept.ts +0 -20
- package/src/sample/domains/employees/concepts/employeeQualification.concept.ts +0 -20
- package/src/sample/domains/employees/concepts/employeeSpouse.concept.ts +0 -21
- package/src/sample/domains/employees/concepts/employeeViolation.concept.ts +0 -19
- package/src/sample/domains/employees/endpoints/getCurrentEmployee.endpoint.ts +0 -1651
- package/src/sample/domains/employees/endpoints/getCurrentIdentity.endpoint.ts +0 -197
- package/src/sample/domains/employees/endpoints/getCurrentManagers.endpoint.ts +0 -142
- package/src/sample/domains/employees/endpoints/getEmployeeById.endpoint.ts +0 -1659
- package/src/sample/domains/employees/endpoints/getEmployeeStatistics.endpoint.ts +0 -43
- package/src/sample/domains/employees/endpoints/listBankAccounts.endpoint.ts +0 -223
- package/src/sample/domains/employees/endpoints/listChildren.endpoint.ts +0 -211
- package/src/sample/domains/employees/endpoints/listDocuments.endpoint.ts +0 -222
- package/src/sample/domains/employees/endpoints/listEmployeesSimple.endpoint.ts +0 -156
- package/src/sample/domains/employees/endpoints/listEvents.endpoint.ts +0 -120
- package/src/sample/domains/employees/endpoints/listExperiences.endpoint.ts +0 -188
- package/src/sample/domains/employees/endpoints/listJobLevelChanges.endpoint.ts +0 -240
- package/src/sample/domains/employees/endpoints/listMedals.endpoint.ts +0 -266
- package/src/sample/domains/employees/endpoints/listQualifications.endpoint.ts +0 -265
- package/src/sample/domains/employees/endpoints/listSpouses.endpoint.ts +0 -278
- package/src/sample/domains/employees/endpoints/listViolations.endpoint.ts +0 -245
- package/src/sample/domains/employees/index.ts +0 -75
- package/src/sample/domains/employees/services/employees.service.ts +0 -181
- package/src/sample/domains/index.ts +0 -10
- package/src/sample/domains/leaves/concepts/leave.concept.ts +0 -21
- package/src/sample/domains/leaves/concepts/leaveBalance.concept.ts +0 -17
- package/src/sample/domains/leaves/concepts/leaveBalanceTransaction.concept.ts +0 -16
- package/src/sample/domains/leaves/concepts/leaveType.concept.ts +0 -13
- package/src/sample/domains/leaves/concepts/leaveTypes.concept.ts +0 -205
- package/src/sample/domains/leaves/endpoints/getBalance.endpoint.ts +0 -53
- package/src/sample/domains/leaves/endpoints/getLeaveById.endpoint.ts +0 -53
- package/src/sample/domains/leaves/endpoints/listBalanceTransactions.endpoint.ts +0 -196
- package/src/sample/domains/leaves/endpoints/listBalanceTypes.endpoint.ts +0 -26
- package/src/sample/domains/leaves/endpoints/listBalances.endpoint.ts +0 -201
- package/src/sample/domains/leaves/endpoints/listLeaveTypes.endpoint.ts +0 -28
- package/src/sample/domains/leaves/endpoints/listLeaves.endpoint.ts +0 -234
- package/src/sample/domains/leaves/index.ts +0 -38
- package/src/sample/domains/leaves/services/leaveRequests.service.ts +0 -232
- package/src/sample/domains/notifications/concepts/notification.concept.ts +0 -19
- package/src/sample/domains/notifications/endpoints/countMyNotifications.endpoint.ts +0 -21
- package/src/sample/domains/notifications/endpoints/getMyNotification.endpoint.ts +0 -57
- package/src/sample/domains/notifications/endpoints/listMyNotifications.endpoint.ts +0 -59
- package/src/sample/domains/notifications/endpoints/markMyNotificationAsRead.endpoint.ts +0 -32
- package/src/sample/domains/notifications/index.ts +0 -20
- package/src/sample/domains/payroll/concepts/payslip.concept.ts +0 -18
- package/src/sample/domains/payroll/concepts/salaryCertificate.concept.ts +0 -17
- package/src/sample/domains/payroll/concepts/salaryCertificateRequestingEntity.concept.ts +0 -8
- package/src/sample/domains/payroll/endpoints/getPayslipById.endpoint.ts +0 -238
- package/src/sample/domains/payroll/endpoints/listPayslips.endpoint.ts +0 -216
- package/src/sample/domains/payroll/endpoints/listSalaryCertificateLanguages.endpoint.ts +0 -25
- package/src/sample/domains/payroll/endpoints/listSalaryCertificateRequestingEntities.endpoint.ts +0 -62
- package/src/sample/domains/payroll/endpoints/listSalaryCertificateTypes.endpoint.ts +0 -24
- package/src/sample/domains/payroll/endpoints/listSalaryCertificates.endpoint.ts +0 -122
- package/src/sample/domains/payroll/endpoints/previewSalaryCertificate.endpoint.ts +0 -45
- package/src/sample/domains/payroll/index.ts +0 -32
- package/src/sample/domains/payroll/rules/payrollEmployeeContext.rule.ts +0 -7
- package/src/sample/domains/payroll/services/salaryCertificates.service.ts +0 -15
- package/src/sample/domains/servicing/concepts/service.concept.ts +0 -6
- package/src/sample/domains/servicing/concepts/serviceRequest.concept.ts +0 -12
- package/src/sample/domains/servicing/concepts/serviceRequestApproval.concept.ts +0 -9
- package/src/sample/domains/servicing/endpoints/cancelServiceRequest.endpoint.ts +0 -21
- package/src/sample/domains/servicing/endpoints/createServiceRequest.endpoint.ts +0 -511
- package/src/sample/domains/servicing/endpoints/getServiceRequest.endpoint.ts +0 -352
- package/src/sample/domains/servicing/endpoints/getServiceRequestFormItems.endpoint.ts +0 -219
- package/src/sample/domains/servicing/endpoints/getServiceRequestTransactionFormItems.endpoint.ts +0 -216
- package/src/sample/domains/servicing/endpoints/getServiceStates.endpoint.ts +0 -47
- package/src/sample/domains/servicing/endpoints/invokeServiceRequestAction.endpoint.ts +0 -139
- package/src/sample/domains/servicing/endpoints/listServiceRequests.endpoint.ts +0 -292
- package/src/sample/domains/servicing/endpoints/listServices.endpoint.ts +0 -108
- package/src/sample/domains/servicing/endpoints/updateServiceRequest.endpoint.ts +0 -355
- package/src/sample/domains/servicing/index.ts +0 -44
- package/src/sample/domains/servicing/rules/checkValidActions.rule.ts +0 -7
- package/src/sample/domains/servicing/rules/createServiceRequest.rule.ts +0 -7
- package/src/sample/domains/servicing/rules/filterServiceRequestsByState.rule.ts +0 -7
- package/src/sample/domains/servicing/rules/passingOptionFields.rule.ts +0 -7
- package/src/sample/domains/shared/rules/pagination.rule.ts +0 -7
- package/src/sample/domains/suggestions/concepts/suggestion.concept.ts +0 -19
- package/src/sample/domains/suggestions/concepts/suggestionCategory.concept.ts +0 -7
- package/src/sample/domains/suggestions/concepts/suggestionImpactLevel.concept.ts +0 -7
- package/src/sample/domains/suggestions/endpoints/createSuggestion.endpoint.ts +0 -705
- package/src/sample/domains/suggestions/endpoints/deleteSuggestion.endpoint.ts +0 -32
- package/src/sample/domains/suggestions/endpoints/getSuggestionById.endpoint.ts +0 -635
- package/src/sample/domains/suggestions/endpoints/listSuggestionCategories.endpoint.ts +0 -62
- package/src/sample/domains/suggestions/endpoints/listSuggestionImpactLevels.endpoint.ts +0 -62
- package/src/sample/domains/suggestions/endpoints/listSuggestionStates.endpoint.ts +0 -24
- package/src/sample/domains/suggestions/endpoints/listSuggestions.endpoint.ts +0 -132
- package/src/sample/domains/suggestions/endpoints/updateSuggestion.endpoint.ts +0 -690
- package/src/sample/domains/suggestions/endpoints/updateSuggestionState.endpoint.ts +0 -39
- package/src/sample/domains/suggestions/index.ts +0 -34
- package/src/sample/domains/suggestions/rules/suggestionScope.rule.ts +0 -7
- package/src/sample/domains/surveys/concepts/survey.concept.ts +0 -10
- package/src/sample/domains/surveys/concepts/surveyResponse.concept.ts +0 -14
- package/src/sample/domains/surveys/endpoints/getSurveyResponseById.endpoint.ts +0 -131
- package/src/sample/domains/surveys/endpoints/getTargetedSurvey.endpoint.ts +0 -129
- package/src/sample/domains/surveys/endpoints/listTargetedSurveys.endpoint.ts +0 -160
- package/src/sample/domains/surveys/endpoints/respondToSurvey.endpoint.ts +0 -144
- package/src/sample/domains/surveys/index.ts +0 -21
- package/src/sample/drizzle.config.ts +0 -11
- package/src/sample/index.bak.ts +0 -341
- package/src/sample/index.ts +0 -318
- package/src/sample/official-statements/defaults.ts +0 -57
- package/src/sample/official-statements/routes.ts +0 -137
- package/src/sample/official-statements/service.ts +0 -148
- package/src/sample/official-statements/types.ts +0 -23
- /package/src/lib/db/migrations/{20260326231647_nice_speedball → mssql/20260326231647_nice_speedball}/migration.sql +0 -0
- /package/src/lib/db/migrations/{20260326231647_nice_speedball → mssql/20260326231647_nice_speedball}/snapshot.json +0 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Runtime contract §1.1: the `:id` path param, validated on both sides of the wire. */
|
|
3
|
+
export declare const AGENT_SLUG_PATTERN: RegExp;
|
|
4
|
+
/** Runtime contract §5: tool names become `tools.<name>()` sandbox bindings. */
|
|
5
|
+
export declare const TOOL_NAME_PATTERN: RegExp;
|
|
6
|
+
export declare const PROMPT_VARIABLES: readonly ["userName", "channel", "locale", "utcTime", "timezone"];
|
|
7
|
+
/**
|
|
8
|
+
* One entry per prompt variable, driving editor autocomplete, validation, and
|
|
9
|
+
* runtime substitution alike. Adding a variable = extending the tuple above
|
|
10
|
+
* plus one entry here (the compiler enforces the pair); the consumer embedding
|
|
11
|
+
* the agent supplies the value in its session/request context under the same
|
|
12
|
+
* key. Descriptions are plain English on purpose: variables are code-like
|
|
13
|
+
* identifiers shown in an LTR suggestion list, not localized UI copy.
|
|
14
|
+
*/
|
|
15
|
+
export declare const PROMPT_VARIABLE_DEFINITIONS: {
|
|
16
|
+
userName: {
|
|
17
|
+
description: string;
|
|
18
|
+
example: string;
|
|
19
|
+
};
|
|
20
|
+
channel: {
|
|
21
|
+
description: string;
|
|
22
|
+
example: string;
|
|
23
|
+
};
|
|
24
|
+
locale: {
|
|
25
|
+
description: string;
|
|
26
|
+
example: string;
|
|
27
|
+
};
|
|
28
|
+
utcTime: {
|
|
29
|
+
description: string;
|
|
30
|
+
example: string;
|
|
31
|
+
};
|
|
32
|
+
timezone: {
|
|
33
|
+
description: string;
|
|
34
|
+
example: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare const RUNTIME_ERROR_KINDS: readonly ["timeout", "upstream_4xx", "upstream_5xx", "schema_mismatch", "rate_limited", "not_found", "unauthorized", "invalid_request", "egress_blocked", "internal"];
|
|
38
|
+
/** The ways an execute output may disagree with the tool's declared schema. */
|
|
39
|
+
export declare const JSON_SCHEMA_ISSUE_KINDS: readonly ["missing", "unexpected", "type_mismatch"];
|
|
40
|
+
export declare const agentSlugSchema: z.ZodString;
|
|
41
|
+
export declare const localeSchema: z.ZodEnum<{
|
|
42
|
+
ar: "ar";
|
|
43
|
+
en: "en";
|
|
44
|
+
}>;
|
|
45
|
+
export declare const catalogVersionSchema: z.ZodString;
|
|
46
|
+
export declare const sharedShapeSchema: z.ZodObject<{
|
|
47
|
+
ref: z.ZodString;
|
|
48
|
+
shape: z.ZodString;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
export declare const knowledgeChunkSchema: z.ZodObject<{
|
|
51
|
+
chunkId: z.ZodUUID;
|
|
52
|
+
text: z.ZodString;
|
|
53
|
+
score: z.ZodNumber;
|
|
54
|
+
citation: z.ZodObject<{
|
|
55
|
+
documentId: z.ZodUUID;
|
|
56
|
+
documentTitle: z.ZodString;
|
|
57
|
+
page: z.ZodNullable<z.ZodNumber>;
|
|
58
|
+
section: z.ZodNullable<z.ZodString>;
|
|
59
|
+
uri: z.ZodNullable<z.ZodURL>;
|
|
60
|
+
service: z.ZodNullable<z.ZodString>;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
export declare const toolSignatureSchema: z.ZodObject<{
|
|
64
|
+
toolId: z.ZodUUID;
|
|
65
|
+
name: z.ZodString;
|
|
66
|
+
version: z.ZodNumber;
|
|
67
|
+
readOnly: z.ZodBoolean;
|
|
68
|
+
tags: z.ZodArray<z.ZodString>;
|
|
69
|
+
signature: z.ZodString;
|
|
70
|
+
score: z.ZodNullable<z.ZodNumber>;
|
|
71
|
+
pinned: z.ZodBoolean;
|
|
72
|
+
}, z.core.$strip>;
|
|
73
|
+
export declare const serviceCardSchema: z.ZodObject<{
|
|
74
|
+
serviceId: z.ZodUUID;
|
|
75
|
+
key: z.ZodString;
|
|
76
|
+
name: z.ZodString;
|
|
77
|
+
card: z.ZodString;
|
|
78
|
+
score: z.ZodNumber;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
export declare const runtimeAgentConfigSchema: z.ZodObject<{
|
|
81
|
+
agentId: z.ZodString;
|
|
82
|
+
systemPrompt: z.ZodString;
|
|
83
|
+
promptVariables: z.ZodArray<z.ZodEnum<{
|
|
84
|
+
userName: "userName";
|
|
85
|
+
channel: "channel";
|
|
86
|
+
locale: "locale";
|
|
87
|
+
utcTime: "utcTime";
|
|
88
|
+
timezone: "timezone";
|
|
89
|
+
}>>;
|
|
90
|
+
catalogBlurb: z.ZodString;
|
|
91
|
+
defaultLocale: z.ZodEnum<{
|
|
92
|
+
ar: "ar";
|
|
93
|
+
en: "en";
|
|
94
|
+
}>;
|
|
95
|
+
metaTools: z.ZodObject<{
|
|
96
|
+
searchKnowledge: z.ZodBoolean;
|
|
97
|
+
searchTools: z.ZodBoolean;
|
|
98
|
+
searchServices: z.ZodBoolean;
|
|
99
|
+
}, z.core.$strip>;
|
|
100
|
+
limits: z.ZodObject<{
|
|
101
|
+
resolveTokenBudget: z.ZodNumber;
|
|
102
|
+
executeTimeoutMs: z.ZodNumber;
|
|
103
|
+
maxResponseBytes: z.ZodNumber;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
catalogVersion: z.ZodString;
|
|
106
|
+
publishedAt: z.ZodISODateTime;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
export declare const resolveRequestSchema: z.ZodObject<{
|
|
109
|
+
query: z.ZodString;
|
|
110
|
+
locale: z.ZodOptional<z.ZodEnum<{
|
|
111
|
+
ar: "ar";
|
|
112
|
+
en: "en";
|
|
113
|
+
}>>;
|
|
114
|
+
hints: z.ZodOptional<z.ZodObject<{
|
|
115
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
116
|
+
recentToolNames: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
117
|
+
turnIndex: z.ZodOptional<z.ZodNumber>;
|
|
118
|
+
}, z.core.$strip>>;
|
|
119
|
+
tokenBudget: z.ZodOptional<z.ZodNumber>;
|
|
120
|
+
limits: z.ZodOptional<z.ZodObject<{
|
|
121
|
+
knowledge: z.ZodDefault<z.ZodNumber>;
|
|
122
|
+
tools: z.ZodDefault<z.ZodNumber>;
|
|
123
|
+
services: z.ZodDefault<z.ZodNumber>;
|
|
124
|
+
}, z.core.$strip>>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
export declare const resolveResponseSchema: z.ZodObject<{
|
|
127
|
+
resolveId: z.ZodUUID;
|
|
128
|
+
catalogVersion: z.ZodString;
|
|
129
|
+
locale: z.ZodEnum<{
|
|
130
|
+
ar: "ar";
|
|
131
|
+
en: "en";
|
|
132
|
+
}>;
|
|
133
|
+
knowledge: z.ZodArray<z.ZodObject<{
|
|
134
|
+
chunkId: z.ZodUUID;
|
|
135
|
+
text: z.ZodString;
|
|
136
|
+
score: z.ZodNumber;
|
|
137
|
+
citation: z.ZodObject<{
|
|
138
|
+
documentId: z.ZodUUID;
|
|
139
|
+
documentTitle: z.ZodString;
|
|
140
|
+
page: z.ZodNullable<z.ZodNumber>;
|
|
141
|
+
section: z.ZodNullable<z.ZodString>;
|
|
142
|
+
uri: z.ZodNullable<z.ZodURL>;
|
|
143
|
+
service: z.ZodNullable<z.ZodString>;
|
|
144
|
+
}, z.core.$strip>;
|
|
145
|
+
}, z.core.$strip>>;
|
|
146
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
147
|
+
toolId: z.ZodUUID;
|
|
148
|
+
name: z.ZodString;
|
|
149
|
+
version: z.ZodNumber;
|
|
150
|
+
readOnly: z.ZodBoolean;
|
|
151
|
+
tags: z.ZodArray<z.ZodString>;
|
|
152
|
+
signature: z.ZodString;
|
|
153
|
+
score: z.ZodNullable<z.ZodNumber>;
|
|
154
|
+
pinned: z.ZodBoolean;
|
|
155
|
+
}, z.core.$strip>>;
|
|
156
|
+
services: z.ZodArray<z.ZodObject<{
|
|
157
|
+
serviceId: z.ZodUUID;
|
|
158
|
+
key: z.ZodString;
|
|
159
|
+
name: z.ZodString;
|
|
160
|
+
card: z.ZodString;
|
|
161
|
+
score: z.ZodNumber;
|
|
162
|
+
}, z.core.$strip>>;
|
|
163
|
+
sharedShapes: z.ZodArray<z.ZodObject<{
|
|
164
|
+
ref: z.ZodString;
|
|
165
|
+
shape: z.ZodString;
|
|
166
|
+
}, z.core.$strip>>;
|
|
167
|
+
budget: z.ZodObject<{
|
|
168
|
+
requested: z.ZodNumber;
|
|
169
|
+
used: z.ZodNumber;
|
|
170
|
+
truncated: z.ZodBoolean;
|
|
171
|
+
}, z.core.$strip>;
|
|
172
|
+
}, z.core.$strip>;
|
|
173
|
+
export declare const searchRequestSchema: z.ZodObject<{
|
|
174
|
+
query: z.ZodString;
|
|
175
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
176
|
+
locale: z.ZodOptional<z.ZodEnum<{
|
|
177
|
+
ar: "ar";
|
|
178
|
+
en: "en";
|
|
179
|
+
}>>;
|
|
180
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
181
|
+
service: z.ZodOptional<z.ZodString>;
|
|
182
|
+
}, z.core.$strip>;
|
|
183
|
+
export declare const searchToolsResponseSchema: z.ZodObject<{
|
|
184
|
+
catalogVersion: z.ZodString;
|
|
185
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
186
|
+
toolId: z.ZodUUID;
|
|
187
|
+
name: z.ZodString;
|
|
188
|
+
version: z.ZodNumber;
|
|
189
|
+
readOnly: z.ZodBoolean;
|
|
190
|
+
tags: z.ZodArray<z.ZodString>;
|
|
191
|
+
signature: z.ZodString;
|
|
192
|
+
score: z.ZodNullable<z.ZodNumber>;
|
|
193
|
+
pinned: z.ZodBoolean;
|
|
194
|
+
}, z.core.$strip>>;
|
|
195
|
+
sharedShapes: z.ZodArray<z.ZodObject<{
|
|
196
|
+
ref: z.ZodString;
|
|
197
|
+
shape: z.ZodString;
|
|
198
|
+
}, z.core.$strip>>;
|
|
199
|
+
}, z.core.$strip>;
|
|
200
|
+
export declare const searchServicesResponseSchema: z.ZodObject<{
|
|
201
|
+
catalogVersion: z.ZodString;
|
|
202
|
+
services: z.ZodArray<z.ZodObject<{
|
|
203
|
+
serviceId: z.ZodUUID;
|
|
204
|
+
key: z.ZodString;
|
|
205
|
+
name: z.ZodString;
|
|
206
|
+
card: z.ZodString;
|
|
207
|
+
score: z.ZodNumber;
|
|
208
|
+
}, z.core.$strip>>;
|
|
209
|
+
tools: z.ZodArray<z.ZodObject<{
|
|
210
|
+
toolId: z.ZodUUID;
|
|
211
|
+
name: z.ZodString;
|
|
212
|
+
version: z.ZodNumber;
|
|
213
|
+
readOnly: z.ZodBoolean;
|
|
214
|
+
tags: z.ZodArray<z.ZodString>;
|
|
215
|
+
signature: z.ZodString;
|
|
216
|
+
score: z.ZodNullable<z.ZodNumber>;
|
|
217
|
+
pinned: z.ZodBoolean;
|
|
218
|
+
}, z.core.$strip>>;
|
|
219
|
+
sharedShapes: z.ZodArray<z.ZodObject<{
|
|
220
|
+
ref: z.ZodString;
|
|
221
|
+
shape: z.ZodString;
|
|
222
|
+
}, z.core.$strip>>;
|
|
223
|
+
}, z.core.$strip>;
|
|
224
|
+
export declare const searchKnowledgeResponseSchema: z.ZodObject<{
|
|
225
|
+
catalogVersion: z.ZodString;
|
|
226
|
+
knowledge: z.ZodArray<z.ZodObject<{
|
|
227
|
+
chunkId: z.ZodUUID;
|
|
228
|
+
text: z.ZodString;
|
|
229
|
+
score: z.ZodNumber;
|
|
230
|
+
citation: z.ZodObject<{
|
|
231
|
+
documentId: z.ZodUUID;
|
|
232
|
+
documentTitle: z.ZodString;
|
|
233
|
+
page: z.ZodNullable<z.ZodNumber>;
|
|
234
|
+
section: z.ZodNullable<z.ZodString>;
|
|
235
|
+
uri: z.ZodNullable<z.ZodURL>;
|
|
236
|
+
service: z.ZodNullable<z.ZodString>;
|
|
237
|
+
}, z.core.$strip>;
|
|
238
|
+
}, z.core.$strip>>;
|
|
239
|
+
}, z.core.$strip>;
|
|
240
|
+
export declare const executeRequestSchema: z.ZodObject<{
|
|
241
|
+
input: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
242
|
+
context: z.ZodOptional<z.ZodObject<{
|
|
243
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
244
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
245
|
+
locale: z.ZodOptional<z.ZodEnum<{
|
|
246
|
+
ar: "ar";
|
|
247
|
+
en: "en";
|
|
248
|
+
}>>;
|
|
249
|
+
}, z.core.$strip>>;
|
|
250
|
+
}, z.core.$strip>;
|
|
251
|
+
export declare const executeResponseSchema: z.ZodObject<{
|
|
252
|
+
toolId: z.ZodUUID;
|
|
253
|
+
name: z.ZodString;
|
|
254
|
+
version: z.ZodNumber;
|
|
255
|
+
output: z.ZodUnknown;
|
|
256
|
+
meta: z.ZodObject<{
|
|
257
|
+
upstreamStatus: z.ZodNumber;
|
|
258
|
+
durationMs: z.ZodNumber;
|
|
259
|
+
replayed: z.ZodBoolean;
|
|
260
|
+
truncated: z.ZodBoolean;
|
|
261
|
+
truncatedPaths: z.ZodArray<z.ZodString>;
|
|
262
|
+
drift: z.ZodArray<z.ZodObject<{
|
|
263
|
+
path: z.ZodString;
|
|
264
|
+
kind: z.ZodEnum<{
|
|
265
|
+
missing: "missing";
|
|
266
|
+
unexpected: "unexpected";
|
|
267
|
+
type_mismatch: "type_mismatch";
|
|
268
|
+
}>;
|
|
269
|
+
}, z.core.$strip>>;
|
|
270
|
+
}, z.core.$strip>;
|
|
271
|
+
}, z.core.$strip>;
|
|
272
|
+
declare const runtimeErrorKindSchema: z.ZodEnum<{
|
|
273
|
+
timeout: "timeout";
|
|
274
|
+
upstream_4xx: "upstream_4xx";
|
|
275
|
+
upstream_5xx: "upstream_5xx";
|
|
276
|
+
schema_mismatch: "schema_mismatch";
|
|
277
|
+
rate_limited: "rate_limited";
|
|
278
|
+
not_found: "not_found";
|
|
279
|
+
unauthorized: "unauthorized";
|
|
280
|
+
invalid_request: "invalid_request";
|
|
281
|
+
egress_blocked: "egress_blocked";
|
|
282
|
+
internal: "internal";
|
|
283
|
+
}>;
|
|
284
|
+
export type RuntimeErrorKind = z.infer<typeof runtimeErrorKindSchema>;
|
|
285
|
+
export declare const runtimeErrorSchema: z.ZodObject<{
|
|
286
|
+
error: z.ZodObject<{
|
|
287
|
+
kind: z.ZodEnum<{
|
|
288
|
+
timeout: "timeout";
|
|
289
|
+
upstream_4xx: "upstream_4xx";
|
|
290
|
+
upstream_5xx: "upstream_5xx";
|
|
291
|
+
schema_mismatch: "schema_mismatch";
|
|
292
|
+
rate_limited: "rate_limited";
|
|
293
|
+
not_found: "not_found";
|
|
294
|
+
unauthorized: "unauthorized";
|
|
295
|
+
invalid_request: "invalid_request";
|
|
296
|
+
egress_blocked: "egress_blocked";
|
|
297
|
+
internal: "internal";
|
|
298
|
+
}>;
|
|
299
|
+
detail: z.ZodString;
|
|
300
|
+
retryable: z.ZodBoolean;
|
|
301
|
+
retryAfterSeconds: z.ZodOptional<z.ZodNumber>;
|
|
302
|
+
upstreamStatus: z.ZodOptional<z.ZodNumber>;
|
|
303
|
+
}, z.core.$strip>;
|
|
304
|
+
}, z.core.$strip>;
|
|
305
|
+
export type RuntimeAgentConfig = z.infer<typeof runtimeAgentConfigSchema>;
|
|
306
|
+
export type ResolveRequest = z.input<typeof resolveRequestSchema>;
|
|
307
|
+
export type ResolveResponse = z.infer<typeof resolveResponseSchema>;
|
|
308
|
+
export type SearchRequest = z.input<typeof searchRequestSchema>;
|
|
309
|
+
export type ExecuteRequest = z.input<typeof executeRequestSchema>;
|
|
310
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
export declare const ATTACHMENT_MIME_TYPES: readonly ["image/png", "image/jpeg", "image/webp", "application/pdf"];
|
|
11
|
+
export declare const ATTACHMENT_MAX_BYTES: number;
|
|
12
|
+
export declare const MAX_ATTACHMENTS_PER_MESSAGE = 5;
|
|
13
|
+
export declare const ATTACHMENT_STATUSES: readonly ["pending", "described", "failed", "skipped"];
|
|
14
|
+
export declare function checkAttachmentPolicy(contentType: string, sizeBytes: number): "type" | "size" | "ok";
|
|
15
|
+
export type AttachmentStatus = (typeof ATTACHMENT_STATUSES)[number];
|
|
16
|
+
export type AttachmentSummary = {
|
|
17
|
+
id: string;
|
|
18
|
+
filename: string;
|
|
19
|
+
contentType: string;
|
|
20
|
+
sizeBytes: number;
|
|
21
|
+
status: AttachmentStatus;
|
|
22
|
+
description?: string;
|
|
23
|
+
};
|
|
24
|
+
export type ThreadSummary = {
|
|
25
|
+
id: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
updatedAt: string;
|
|
29
|
+
isRunning: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Response of `POST /chat/:chatId/abort`. `aborted: false` means there was no
|
|
33
|
+
* live run to abort — the turn had already committed — so the caller must not
|
|
34
|
+
* present the turn as aborted and should read the settled state back instead.
|
|
35
|
+
*/
|
|
36
|
+
export type AbortRunResult = {
|
|
37
|
+
aborted: boolean;
|
|
38
|
+
};
|
|
39
|
+
export type TokenUsage = {
|
|
40
|
+
input: {
|
|
41
|
+
noCache: number;
|
|
42
|
+
cacheRead: number;
|
|
43
|
+
cacheWrite: number;
|
|
44
|
+
total: number;
|
|
45
|
+
};
|
|
46
|
+
output: {
|
|
47
|
+
reasoning: number;
|
|
48
|
+
text: number;
|
|
49
|
+
total: number;
|
|
50
|
+
};
|
|
51
|
+
total: number;
|
|
52
|
+
};
|
|
53
|
+
export type MessageMetadata = {
|
|
54
|
+
modelId?: string;
|
|
55
|
+
providerMetadata?: unknown;
|
|
56
|
+
isAborted?: boolean;
|
|
57
|
+
tokenUsage?: TokenUsage;
|
|
58
|
+
attachments?: AttachmentSummary[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A stored message as it is persisted and served. TanStack AI's `UIMessage`
|
|
62
|
+
* has no metadata field, so cortex owns the envelope: the SDK's parts plus the
|
|
63
|
+
* server-derived metadata the UI renders on settled messages.
|
|
64
|
+
*
|
|
65
|
+
* `TPart` stays generic so this file keeps its zero dependencies — both
|
|
66
|
+
* sides substitute the SDK's `MessagePart`.
|
|
67
|
+
*/
|
|
68
|
+
export type CortexMessage<TPart = unknown> = {
|
|
69
|
+
id: string;
|
|
70
|
+
role: "system" | "user" | "assistant";
|
|
71
|
+
parts: TPart[];
|
|
72
|
+
metadata?: MessageMetadata;
|
|
73
|
+
};
|
|
74
|
+
export type ThreadCreatedEvent = {
|
|
75
|
+
type: "thread:created";
|
|
76
|
+
payload: {
|
|
77
|
+
thread: ThreadSummary;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export type ThreadDeletedEvent = {
|
|
81
|
+
type: "thread:deleted";
|
|
82
|
+
payload: {
|
|
83
|
+
threadId: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
export type ThreadTitleUpdatedEvent = {
|
|
87
|
+
type: "thread:title-updated";
|
|
88
|
+
payload: {
|
|
89
|
+
thread: ThreadSummary;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export type ThreadRunStartedEvent = {
|
|
93
|
+
type: "thread:run-started";
|
|
94
|
+
payload: {
|
|
95
|
+
thread: ThreadSummary;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export type ThreadRunFinishedEvent = {
|
|
99
|
+
type: "thread:run-finished";
|
|
100
|
+
payload: {
|
|
101
|
+
thread: ThreadSummary;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
export type ThreadMessagesUpdatedEvent = {
|
|
105
|
+
type: "thread:messages-updated";
|
|
106
|
+
payload: {
|
|
107
|
+
threadId: string;
|
|
108
|
+
thread: ThreadSummary;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export type ToolProgressEvent = {
|
|
112
|
+
type: "thread:tool-progress";
|
|
113
|
+
payload: {
|
|
114
|
+
threadId: string;
|
|
115
|
+
toolCallId: string;
|
|
116
|
+
toolName: string;
|
|
117
|
+
status: "started" | "finished";
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
export type WsEvent = ThreadCreatedEvent | ThreadDeletedEvent | ThreadTitleUpdatedEvent | ThreadRunStartedEvent | ThreadRunFinishedEvent | ThreadMessagesUpdatedEvent | ToolProgressEvent;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Attachment, ChatMessage, NewAttachment, StoredMessage, Thread, TokenUsage } from "../../types";
|
|
2
|
+
import type { ThreadContextMeta } from "../../ai/context/types";
|
|
3
|
+
/**
|
|
4
|
+
* The persistence contract, implemented once per dialect under `mssql/` and
|
|
5
|
+
* `postgres/`.
|
|
6
|
+
*
|
|
7
|
+
* Those two trees are near-identical on purpose. Drizzle types its query
|
|
8
|
+
* builders per dialect, so a shared body is not expressible — `.top`/`.limit`,
|
|
9
|
+
* `.output`/`.returning` and the row-lock hint differ down in the query, not at
|
|
10
|
+
* a seam that could be factored out. What is *not* SQL lives in
|
|
11
|
+
* `message-content.ts` instead, so the rules the two must agree on are stated
|
|
12
|
+
* once.
|
|
13
|
+
*
|
|
14
|
+
* Drift is guarded rather than prevented: `db/schema.parity.test.ts` asserts the
|
|
15
|
+
* two schemas still infer the same rows, and the adapter tests beside this file
|
|
16
|
+
* run against both implementations. The `code-duplication` suppressions in
|
|
17
|
+
* `postgres/` record the same decision for fallow.
|
|
18
|
+
*/
|
|
19
|
+
export type DatabaseAdapter = {
|
|
20
|
+
threads: {
|
|
21
|
+
list(userId: string, agentId: string): Promise<Thread[]>;
|
|
22
|
+
getById(userId: string, threadId: string): Promise<Thread | null>;
|
|
23
|
+
create(userId: string, agentId: string): Promise<Thread>;
|
|
24
|
+
delete(userId: string, threadId: string): Promise<void>;
|
|
25
|
+
touch(threadId: string): Promise<Thread>;
|
|
26
|
+
updateTitle(threadId: string, title: string): Promise<void>;
|
|
27
|
+
updateSession(threadId: string, session: Record<string, unknown>): Promise<void>;
|
|
28
|
+
updateContextMeta(threadId: string, meta: ThreadContextMeta): Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
messages: {
|
|
31
|
+
list(userId: string, threadId: string, opts?: {
|
|
32
|
+
limit?: number;
|
|
33
|
+
}): Promise<StoredMessage[]>;
|
|
34
|
+
upsert(threadId: string, messages: ChatMessage[], options?: {
|
|
35
|
+
replaceAttachments?: boolean;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
};
|
|
38
|
+
llmRequests: {
|
|
39
|
+
insert(requests: {
|
|
40
|
+
messageId: string;
|
|
41
|
+
stepNumber: number;
|
|
42
|
+
prompt: string;
|
|
43
|
+
output: string | null;
|
|
44
|
+
tokenUsage: TokenUsage | null;
|
|
45
|
+
}[]): Promise<void>;
|
|
46
|
+
listByMessageId(messageId: string): Promise<{
|
|
47
|
+
id: string;
|
|
48
|
+
prompt: string;
|
|
49
|
+
output: string | null;
|
|
50
|
+
tokenUsage: TokenUsage | null;
|
|
51
|
+
}[]>;
|
|
52
|
+
};
|
|
53
|
+
attachments: {
|
|
54
|
+
createPending(row: NewAttachment, limit: number): Promise<Attachment | undefined>;
|
|
55
|
+
getById(id: string, userId: string): Promise<Attachment | undefined>;
|
|
56
|
+
listByThread(threadId: string, userId: string): Promise<Attachment[]>;
|
|
57
|
+
claimForMessage(threadId: string, userId: string, messageId: string): Promise<Attachment[]>;
|
|
58
|
+
setDescription(id: string, userId: string, status: Attachment["status"], description?: string): Promise<void>;
|
|
59
|
+
remove(id: string, userId: string): Promise<Attachment | undefined>;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChatMessage } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* The parts of `messages.upsert` that are decisions rather than SQL. Each
|
|
4
|
+
* dialect writes its own queries, but they must agree on what gets written —
|
|
5
|
+
* so the rules live here and neither repository restates them.
|
|
6
|
+
*/
|
|
7
|
+
/** Denormalized alongside the JSON content so the column is searchable. */
|
|
8
|
+
export declare function textOf(message: ChatMessage): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Attachments are the server's to assign: a caller may name them but never
|
|
11
|
+
* establish them. Only a turn that has just claimed them may carry them in.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withOwnedAttachments(messages: ChatMessage[], replaceAttachments?: boolean): (ChatMessage | {
|
|
14
|
+
metadata: {
|
|
15
|
+
modelId?: string;
|
|
16
|
+
providerMetadata?: unknown;
|
|
17
|
+
isAborted?: boolean;
|
|
18
|
+
tokenUsage?: import("../../types").TokenUsage;
|
|
19
|
+
};
|
|
20
|
+
id: string;
|
|
21
|
+
role: "system" | "user" | "assistant";
|
|
22
|
+
parts: import("@tanstack/ai").MessagePart[];
|
|
23
|
+
})[];
|
|
24
|
+
/**
|
|
25
|
+
* The envelope is the server's — usage, model id and the attachments it claimed
|
|
26
|
+
* are facts no caller carries in full, so an update only contributes the fields
|
|
27
|
+
* it actually set. Attachments were already stripped from anything that must
|
|
28
|
+
* not replace them.
|
|
29
|
+
*/
|
|
30
|
+
export declare function mergeStoredContent(existing: ChatMessage, incoming: ChatMessage): ChatMessage;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { MssqlDb } from "./client";
|
|
2
|
+
export declare function createAttachmentsRepository(db: MssqlDb): {
|
|
3
|
+
createPending(row: {
|
|
4
|
+
userId: string;
|
|
5
|
+
threadId: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
contentType: string;
|
|
8
|
+
sizeBytes: number;
|
|
9
|
+
storageKey: string;
|
|
10
|
+
status: "pending" | "described" | "failed" | "skipped";
|
|
11
|
+
id?: string | undefined;
|
|
12
|
+
createdAt?: Date | undefined;
|
|
13
|
+
updatedAt?: Date | undefined;
|
|
14
|
+
messageId?: string | null | undefined;
|
|
15
|
+
description?: string | null | undefined;
|
|
16
|
+
}, limit: number): Promise<{
|
|
17
|
+
id: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
updatedAt: Date;
|
|
21
|
+
threadId: string;
|
|
22
|
+
messageId: string | null;
|
|
23
|
+
filename: string;
|
|
24
|
+
contentType: string;
|
|
25
|
+
sizeBytes: number;
|
|
26
|
+
storageKey: string;
|
|
27
|
+
status: "pending" | "described" | "failed" | "skipped";
|
|
28
|
+
description: string | null;
|
|
29
|
+
} | undefined>;
|
|
30
|
+
getById(id: string, userId: string): Promise<{
|
|
31
|
+
id: string;
|
|
32
|
+
userId: string;
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
updatedAt: Date;
|
|
35
|
+
threadId: string;
|
|
36
|
+
messageId: string | null;
|
|
37
|
+
filename: string;
|
|
38
|
+
contentType: string;
|
|
39
|
+
sizeBytes: number;
|
|
40
|
+
storageKey: string;
|
|
41
|
+
status: "pending" | "described" | "failed" | "skipped";
|
|
42
|
+
description: string | null;
|
|
43
|
+
} | {
|
|
44
|
+
createdAt: Date;
|
|
45
|
+
updatedAt: Date;
|
|
46
|
+
id: string;
|
|
47
|
+
threadId: string;
|
|
48
|
+
userId: string;
|
|
49
|
+
messageId: string | null;
|
|
50
|
+
filename: string;
|
|
51
|
+
contentType: string;
|
|
52
|
+
sizeBytes: number;
|
|
53
|
+
storageKey: string;
|
|
54
|
+
status: "pending" | "described" | "failed" | "skipped";
|
|
55
|
+
description: string | null;
|
|
56
|
+
} | undefined>;
|
|
57
|
+
listByThread(threadId: string, userId: string): Promise<{
|
|
58
|
+
createdAt: Date;
|
|
59
|
+
updatedAt: Date;
|
|
60
|
+
id: string;
|
|
61
|
+
threadId: string;
|
|
62
|
+
userId: string;
|
|
63
|
+
messageId: string | null;
|
|
64
|
+
filename: string;
|
|
65
|
+
contentType: string;
|
|
66
|
+
sizeBytes: number;
|
|
67
|
+
storageKey: string;
|
|
68
|
+
status: "pending" | "described" | "failed" | "skipped";
|
|
69
|
+
description: string | null;
|
|
70
|
+
}[]>;
|
|
71
|
+
claimForMessage(threadId: string, userId: string, messageId: string): Promise<{
|
|
72
|
+
id: string;
|
|
73
|
+
userId: string;
|
|
74
|
+
createdAt: Date;
|
|
75
|
+
updatedAt: Date;
|
|
76
|
+
threadId: string;
|
|
77
|
+
messageId: string | null;
|
|
78
|
+
filename: string;
|
|
79
|
+
contentType: string;
|
|
80
|
+
sizeBytes: number;
|
|
81
|
+
storageKey: string;
|
|
82
|
+
status: "pending" | "described" | "failed" | "skipped";
|
|
83
|
+
description: string | null;
|
|
84
|
+
}[]>;
|
|
85
|
+
setDescription(id: string, userId: string, status: "pending" | "described" | "failed" | "skipped", description: string | undefined): Promise<void>;
|
|
86
|
+
remove(id: string, userId: string): Promise<{
|
|
87
|
+
id: string;
|
|
88
|
+
userId: string;
|
|
89
|
+
createdAt: Date;
|
|
90
|
+
updatedAt: Date;
|
|
91
|
+
threadId: string;
|
|
92
|
+
messageId: string | null;
|
|
93
|
+
filename: string;
|
|
94
|
+
contentType: string;
|
|
95
|
+
sizeBytes: number;
|
|
96
|
+
storageKey: string;
|
|
97
|
+
status: "pending" | "described" | "failed" | "skipped";
|
|
98
|
+
description: string | null;
|
|
99
|
+
} | undefined>;
|
|
100
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global snake_case mapping means schema columns are never spelled out twice —
|
|
3
|
+
* the TypeScript name is the source of truth and Drizzle derives the column.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createMssqlDb(connectionString: string): import("drizzle-orm/node-mssql").NodeMsSqlDatabase<Record<string, never>> & {
|
|
6
|
+
$client: import("drizzle-orm/node-mssql/pool").AutoPool;
|
|
7
|
+
};
|
|
8
|
+
export type MssqlDb = ReturnType<typeof createMssqlDb>;
|