@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,92 @@
|
|
|
1
|
+
import { substituteVariables } from "@cortex/contracts/rich-text";
|
|
2
|
+
|
|
3
|
+
import type { ResolveResponse, RuntimeAgentConfig } from "./types";
|
|
4
|
+
|
|
5
|
+
type SharedShape = ResolveResponse["sharedShapes"][number];
|
|
6
|
+
type ToolSignature = ResolveResponse["tools"][number];
|
|
7
|
+
type ServiceCard = ResolveResponse["services"][number];
|
|
8
|
+
type KnowledgeChunk = ResolveResponse["knowledge"][number];
|
|
9
|
+
|
|
10
|
+
/** Values for the published prompt's `{{variable}}` placeholders, read from session/request context. */
|
|
11
|
+
export function buildPromptVariables(
|
|
12
|
+
promptVariables: RuntimeAgentConfig["promptVariables"],
|
|
13
|
+
sources: Record<string, unknown>,
|
|
14
|
+
) {
|
|
15
|
+
const variables: Record<string, string> = {};
|
|
16
|
+
for (const name of promptVariables) {
|
|
17
|
+
const value = sources[name];
|
|
18
|
+
if (typeof value === "string") variables[name] = value;
|
|
19
|
+
}
|
|
20
|
+
return variables;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function formatSharedShapes(shapes: SharedShape[]) {
|
|
24
|
+
return shapes.map((shape) => `${shape.ref}: ${shape.shape}`).join("\n");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function formatToolSignatures(tools: ToolSignature[]) {
|
|
28
|
+
return tools.map((tool) => tool.signature).join("\n\n");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function formatServiceCards(services: ServiceCard[]) {
|
|
32
|
+
return services.map((service) => service.card).join("\n\n");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function formatKnowledgeChunks(chunks: KnowledgeChunk[]) {
|
|
36
|
+
return chunks.map(formatKnowledgeChunk).join("\n\n");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function formatKnowledgeChunk(chunk: KnowledgeChunk) {
|
|
40
|
+
const { citation } = chunk;
|
|
41
|
+
const source = [
|
|
42
|
+
citation.service,
|
|
43
|
+
citation.documentTitle,
|
|
44
|
+
citation.section,
|
|
45
|
+
citation.page === null ? null : `p. ${citation.page}`,
|
|
46
|
+
]
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join(", ");
|
|
49
|
+
return `${chunk.text}\n[Source: ${source}]`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type CcPromptInput = {
|
|
53
|
+
config: RuntimeAgentConfig;
|
|
54
|
+
resolved: ResolveResponse | null;
|
|
55
|
+
variables: Record<string, string>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Dumb concatenator by contract: `signature`, `card`, and `shape` arrive
|
|
60
|
+
* pre-rendered from Control Center and are injected verbatim — never
|
|
61
|
+
* re-rendered from structured fields.
|
|
62
|
+
*/
|
|
63
|
+
export function buildCcSection(cc: CcPromptInput) {
|
|
64
|
+
const parts: string[] = [];
|
|
65
|
+
|
|
66
|
+
const prompt = substituteVariables(cc.config.systemPrompt, cc.variables).trim();
|
|
67
|
+
if (prompt) parts.push(prompt);
|
|
68
|
+
|
|
69
|
+
if (cc.config.catalogBlurb) {
|
|
70
|
+
parts.push(`## Capabilities\n${cc.config.catalogBlurb}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (cc.resolved) {
|
|
74
|
+
if (cc.resolved.sharedShapes.length > 0) {
|
|
75
|
+
parts.push(`## Response Shapes\n${formatSharedShapes(cc.resolved.sharedShapes)}`);
|
|
76
|
+
}
|
|
77
|
+
if (cc.resolved.tools.length > 0) {
|
|
78
|
+
parts.push(
|
|
79
|
+
"## Dynamic Tools\nCall these from executeCode via the `tools` global, e.g. `await tools.name(input)`.\n\n" +
|
|
80
|
+
formatToolSignatures(cc.resolved.tools),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (cc.resolved.services.length > 0) {
|
|
84
|
+
parts.push(`## Services\n${formatServiceCards(cc.resolved.services)}`);
|
|
85
|
+
}
|
|
86
|
+
if (cc.resolved.knowledge.length > 0) {
|
|
87
|
+
parts.push(`## Knowledge\n${formatKnowledgeChunks(cc.resolved.knowledge)}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return parts.join("\n\n");
|
|
92
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ControlCenterClient } from "./client";
|
|
2
|
+
import type { RuntimeAgentConfig } from "./types";
|
|
3
|
+
|
|
4
|
+
export type CcToolBinding = {
|
|
5
|
+
toolId: string;
|
|
6
|
+
readOnly: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Turn-scoped and mutable: seeded from /resolve, extended by searchTools
|
|
11
|
+
* mid-turn so a tool discovered at step 3 is callable at step 4.
|
|
12
|
+
*/
|
|
13
|
+
export type CcToolRegistry = Map<string, CcToolBinding>;
|
|
14
|
+
|
|
15
|
+
export function registerCcTools(
|
|
16
|
+
registry: CcToolRegistry,
|
|
17
|
+
tools: { name: string; toolId: string; readOnly: boolean }[],
|
|
18
|
+
) {
|
|
19
|
+
for (const tool of tools) {
|
|
20
|
+
registry.set(tool.name, { toolId: tool.toolId, readOnly: tool.readOnly });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Dynamic tools run inside the sandbox, so they never appear as message tool
|
|
25
|
+
// parts — track invocations here to feed /resolve's hints.recentToolNames.
|
|
26
|
+
// ponytail: in-memory per-thread recency, move to the DB if multi-instance matters
|
|
27
|
+
const MAX_RECENT_TOOLS = 20;
|
|
28
|
+
const MAX_TRACKED_THREADS = 1_000;
|
|
29
|
+
const recentToolsByThread = new Map<string, string[]>();
|
|
30
|
+
|
|
31
|
+
export function recordRecentCcTool(threadId: string, name: string) {
|
|
32
|
+
const recent = recentToolsByThread.get(threadId) ?? [];
|
|
33
|
+
const next = [name, ...recent.filter((n) => n !== name)].slice(0, MAX_RECENT_TOOLS);
|
|
34
|
+
recentToolsByThread.delete(threadId);
|
|
35
|
+
recentToolsByThread.set(threadId, next);
|
|
36
|
+
|
|
37
|
+
if (recentToolsByThread.size > MAX_TRACKED_THREADS) {
|
|
38
|
+
const oldest = recentToolsByThread.keys().next().value;
|
|
39
|
+
if (oldest !== undefined) recentToolsByThread.delete(oldest);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getRecentCcTools(threadId: string) {
|
|
44
|
+
return recentToolsByThread.get(threadId) ?? [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Everything a CC-aware tool needs for one turn. */
|
|
48
|
+
export type CcRuntime = {
|
|
49
|
+
client: ControlCenterClient;
|
|
50
|
+
agentId: string;
|
|
51
|
+
config: RuntimeAgentConfig;
|
|
52
|
+
registry: CcToolRegistry;
|
|
53
|
+
threadId: string;
|
|
54
|
+
turnKey: string;
|
|
55
|
+
userId: string;
|
|
56
|
+
locale: RuntimeAgentConfig["defaultLocale"];
|
|
57
|
+
endUserToken: string;
|
|
58
|
+
abortSignal?: AbortSignal;
|
|
59
|
+
getStepIndex: () => number;
|
|
60
|
+
nextCallIndex: (stepIndex: number) => number;
|
|
61
|
+
onToolProgress?: (toolName: string, toolCallId: string, status: "started" | "finished") => void;
|
|
62
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import {
|
|
3
|
+
RUNTIME_ERROR_KINDS,
|
|
4
|
+
runtimeErrorSchema as strictRuntimeErrorSchema,
|
|
5
|
+
} from "@cortex/contracts/runtime";
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
AGENT_SLUG_PATTERN,
|
|
9
|
+
executeResponseSchema,
|
|
10
|
+
resolveResponseSchema,
|
|
11
|
+
runtimeAgentConfigSchema,
|
|
12
|
+
searchKnowledgeResponseSchema,
|
|
13
|
+
searchServicesResponseSchema,
|
|
14
|
+
searchToolsResponseSchema,
|
|
15
|
+
type ExecuteRequest,
|
|
16
|
+
type ResolveRequest,
|
|
17
|
+
type ResolveResponse,
|
|
18
|
+
type RuntimeAgentConfig,
|
|
19
|
+
type SearchRequest,
|
|
20
|
+
} from "@cortex/contracts/runtime";
|
|
21
|
+
|
|
22
|
+
const knownRuntimeErrorKinds = new Set<string>(RUNTIME_ERROR_KINDS);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The contract's error envelope, hardened for this consumer: a newer runtime may
|
|
26
|
+
* answer with an error kind this build has never heard of, which must degrade to a
|
|
27
|
+
* generic non-retryable `internal` rather than fail the parse.
|
|
28
|
+
*/
|
|
29
|
+
export const runtimeErrorSchema = z.preprocess(function normalizeUnknownErrorKind(value) {
|
|
30
|
+
if (typeof value !== "object" || value === null || !("error" in value)) return value;
|
|
31
|
+
|
|
32
|
+
const error = value.error;
|
|
33
|
+
if (typeof error !== "object" || error === null || !("kind" in error)) return value;
|
|
34
|
+
if (typeof error.kind === "string" && knownRuntimeErrorKinds.has(error.kind)) return value;
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...value,
|
|
38
|
+
error: {
|
|
39
|
+
...error,
|
|
40
|
+
kind: "internal",
|
|
41
|
+
retryable: false,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}, strictRuntimeErrorSchema);
|
package/src/lib/config.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DatabaseAdapter } from "./adapters/database";
|
|
3
|
-
import type { StorageAdapter } from "./adapters/storage";
|
|
4
|
-
import type { DomainDef } from "
|
|
5
|
-
import type { RequestInterceptorOptions } from "./ai/interceptors/request-interceptor
|
|
6
|
-
import type { ContextConfig } from "./ai/context/types
|
|
7
|
-
import type { Thread } from "./types
|
|
1
|
+
import type { AnyServerTool } from "@tanstack/ai";
|
|
2
|
+
import type { DatabaseAdapter } from "./adapters/database/index";
|
|
3
|
+
import type { StorageAdapter } from "./adapters/storage/index";
|
|
4
|
+
import type { DomainDef } from "@cortex/contracts/graph";
|
|
5
|
+
import type { RequestInterceptorOptions } from "./ai/interceptors/request-interceptor";
|
|
6
|
+
import type { ContextConfig } from "./ai/context/types";
|
|
7
|
+
import type { ChatMessage, Thread } from "./types";
|
|
8
|
+
|
|
9
|
+
/** An agent's tools, as `chat()` takes them. */
|
|
10
|
+
export type ToolSet = ReadonlyArray<AnyServerTool>;
|
|
8
11
|
|
|
9
12
|
type ModelConfig = {
|
|
10
13
|
baseURL: string;
|
|
@@ -31,6 +34,11 @@ type RerankerConfig = {
|
|
|
31
34
|
apiKey: string;
|
|
32
35
|
};
|
|
33
36
|
|
|
37
|
+
export type ControlCenterConfig = {
|
|
38
|
+
url: string;
|
|
39
|
+
apiKey: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
34
42
|
export type KnowledgeConfig = {
|
|
35
43
|
swagger?: { url: string };
|
|
36
44
|
domains?: Record<string, DomainDef>;
|
|
@@ -66,10 +74,21 @@ export type ToolSetFactory<
|
|
|
66
74
|
> = (context: ToolContext<TSession, TRequestContext>) => ToolSet;
|
|
67
75
|
|
|
68
76
|
export type DatabaseConfig = {
|
|
69
|
-
type: "mssql";
|
|
77
|
+
type: "mssql" | "postgres";
|
|
70
78
|
connectionString: string;
|
|
71
79
|
};
|
|
72
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Optional. With Redis, live runs survive a producer restart and reach every
|
|
83
|
+
* instance: the chunk log, the thread→run claims, and abort fan-out all move
|
|
84
|
+
* there. Without it, an in-memory fallback covers a single process.
|
|
85
|
+
*/
|
|
86
|
+
export type RedisConfig = {
|
|
87
|
+
url: string;
|
|
88
|
+
/** How long a finished run's stream log stays replayable. Defaults to 24 h. */
|
|
89
|
+
streamTtlSeconds?: number;
|
|
90
|
+
};
|
|
91
|
+
|
|
73
92
|
export type StorageConfig = {
|
|
74
93
|
endPoint: string;
|
|
75
94
|
port: number;
|
|
@@ -79,24 +98,42 @@ export type StorageConfig = {
|
|
|
79
98
|
bucketName?: string;
|
|
80
99
|
};
|
|
81
100
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
type BackendFetchConfig = {
|
|
102
|
+
baseUrl: string;
|
|
103
|
+
apiKey: string;
|
|
104
|
+
headers?: Record<string, string>;
|
|
105
|
+
transformRequestBody?: (
|
|
106
|
+
body: Record<string, unknown>,
|
|
107
|
+
context: { token: string },
|
|
108
|
+
) => Promise<Record<string, unknown>>;
|
|
109
|
+
interceptor?: RequestInterceptorOptions;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** Model and knowledge-graph providers. Declared once at server level; an agent may override any of them. */
|
|
113
|
+
type ProviderConfig = {
|
|
114
|
+
model: ModelConfig;
|
|
115
|
+
fastModel?: ModelConfig;
|
|
116
|
+
vision?: ModelConfig;
|
|
117
|
+
embedding?: EmbeddingConfig;
|
|
118
|
+
neo4j?: Neo4jConfig;
|
|
119
|
+
reranker?: RerankerConfig;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* What an agent *does*, independent of where its providers came from. Shared
|
|
124
|
+
* verbatim by the authored definition and its resolved form — the two differ
|
|
125
|
+
* only in how providers and opt-outs are expressed, so everything else lives
|
|
126
|
+
* here and cannot drift between them.
|
|
127
|
+
*/
|
|
128
|
+
type AgentBehavior<
|
|
129
|
+
TSession extends Record<string, unknown>,
|
|
130
|
+
TRequestContext extends Record<string, unknown>,
|
|
85
131
|
> = {
|
|
86
|
-
systemPrompt
|
|
132
|
+
systemPrompt?:
|
|
87
133
|
| string
|
|
88
134
|
| ((context: PromptContext<TSession, TRequestContext>) => string | Promise<string>);
|
|
89
135
|
tools?: ToolSet | ToolSetFactory<TSession, TRequestContext>;
|
|
90
|
-
backendFetch?:
|
|
91
|
-
baseUrl: string;
|
|
92
|
-
apiKey: string;
|
|
93
|
-
headers?: Record<string, string>;
|
|
94
|
-
transformRequestBody?: (
|
|
95
|
-
body: Record<string, unknown>,
|
|
96
|
-
context: { token: string },
|
|
97
|
-
) => Promise<Record<string, unknown>>;
|
|
98
|
-
interceptor?: RequestInterceptorOptions;
|
|
99
|
-
};
|
|
136
|
+
backendFetch?: BackendFetchConfig;
|
|
100
137
|
loadSessionData?: (token: string) => Promise<TSession>;
|
|
101
138
|
resolveRequestContext?: (request: Request) => TRequestContext | Promise<TRequestContext>;
|
|
102
139
|
onToolCall?: (toolCall: {
|
|
@@ -104,68 +141,62 @@ export type CortexAgentDefinition<
|
|
|
104
141
|
toolCallId: string;
|
|
105
142
|
args: Record<string, unknown>;
|
|
106
143
|
}) => void;
|
|
107
|
-
onStreamFinish?: (result: { messages:
|
|
108
|
-
model?: ModelConfig;
|
|
109
|
-
fastModel?: ModelConfig;
|
|
110
|
-
embedding?: EmbeddingConfig;
|
|
111
|
-
neo4j?: Neo4jConfig;
|
|
112
|
-
reranker?: RerankerConfig;
|
|
113
|
-
context?: Partial<ContextConfig>;
|
|
114
|
-
knowledge?: KnowledgeConfig | null;
|
|
144
|
+
onStreamFinish?: (result: { messages: ChatMessage[]; isAborted: boolean }) => void;
|
|
115
145
|
};
|
|
116
146
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
headers?: Record<string, string>;
|
|
131
|
-
transformRequestBody?: (
|
|
132
|
-
body: Record<string, unknown>,
|
|
133
|
-
context: { token: string },
|
|
134
|
-
) => Promise<Record<string, unknown>>;
|
|
135
|
-
interceptor?: RequestInterceptorOptions;
|
|
147
|
+
/**
|
|
148
|
+
* An agent as authored. Providers are optional because an unset one inherits
|
|
149
|
+
* from server level; `null` on knowledge means "opt out entirely" rather than
|
|
150
|
+
* "inherit". The Control Center is server-level only: which agents it backs is
|
|
151
|
+
* decided by publishing them there, not per entry here.
|
|
152
|
+
*/
|
|
153
|
+
export type CortexAgentDefinition<
|
|
154
|
+
TSession extends Record<string, unknown> = Record<string, unknown>,
|
|
155
|
+
TRequestContext extends Record<string, unknown> = Record<string, unknown>,
|
|
156
|
+
> = AgentBehavior<TSession, TRequestContext> &
|
|
157
|
+
Partial<ProviderConfig> & {
|
|
158
|
+
knowledge?: KnowledgeConfig | null;
|
|
159
|
+
context?: Partial<ContextConfig>;
|
|
136
160
|
};
|
|
137
|
-
loadSessionData?: (token: string) => Promise<Record<string, unknown>>;
|
|
138
|
-
resolveRequestContext?: (
|
|
139
|
-
request: Request,
|
|
140
|
-
) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
141
|
-
onToolCall?: (toolCall: {
|
|
142
|
-
toolName: string;
|
|
143
|
-
toolCallId: string;
|
|
144
|
-
args: Record<string, unknown>;
|
|
145
|
-
}) => void;
|
|
146
|
-
onStreamFinish?: (result: { messages: UIMessage[]; isAborted: boolean }) => void;
|
|
147
|
-
context: ContextConfig;
|
|
148
|
-
knowledge?: KnowledgeConfig;
|
|
149
|
-
};
|
|
150
161
|
|
|
151
|
-
|
|
162
|
+
/**
|
|
163
|
+
* An agent after the factory has merged it with server-level config. Every
|
|
164
|
+
* inherit-or-opt-out decision is already resolved, so nothing here is nullable
|
|
165
|
+
* and `model`/`context` are guaranteed present.
|
|
166
|
+
*/
|
|
167
|
+
export type ResolvedCortexAgentConfig = AgentBehavior<
|
|
168
|
+
Record<string, unknown>,
|
|
169
|
+
Record<string, unknown>
|
|
170
|
+
> &
|
|
171
|
+
ProviderConfig & {
|
|
172
|
+
agentId: string;
|
|
173
|
+
db: DatabaseAdapter;
|
|
174
|
+
storage?: StorageAdapter;
|
|
175
|
+
controlCenter?: ControlCenterConfig;
|
|
176
|
+
knowledge?: KnowledgeConfig;
|
|
177
|
+
context: ContextConfig;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export type CortexConfig = ProviderConfig & {
|
|
152
181
|
port?: number;
|
|
153
182
|
database: DatabaseConfig;
|
|
154
|
-
storage
|
|
183
|
+
storage?: StorageConfig;
|
|
184
|
+
redis?: RedisConfig;
|
|
155
185
|
auth?: {
|
|
156
186
|
jwksUri: string;
|
|
157
187
|
issuer: string;
|
|
158
188
|
tokenExtractor?: (req: Request) => string | null;
|
|
159
189
|
cookieName?: string;
|
|
160
190
|
};
|
|
161
|
-
|
|
162
|
-
fastModel?: ModelConfig;
|
|
163
|
-
embedding: EmbeddingConfig;
|
|
164
|
-
neo4j?: Neo4jConfig;
|
|
165
|
-
reranker?: RerankerConfig;
|
|
191
|
+
controlCenter?: ControlCenterConfig;
|
|
166
192
|
context?: Partial<ContextConfig>;
|
|
167
193
|
knowledge?: KnowledgeConfig;
|
|
168
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Locally-defined agents. With `controlCenter` set, agents published there
|
|
196
|
+
* are served automatically and need no entry here; an entry is only needed
|
|
197
|
+
* for local behavior (tools, backendFetch, provider overrides).
|
|
198
|
+
*/
|
|
199
|
+
agents?: Record<string, CortexAgentDefinition>;
|
|
169
200
|
};
|
|
170
201
|
|
|
171
202
|
/**
|
|
@@ -176,6 +207,6 @@ export type CortexConfig = {
|
|
|
176
207
|
export function defineAgent<
|
|
177
208
|
TSession extends Record<string, unknown> = Record<string, unknown>,
|
|
178
209
|
TRequestContext extends Record<string, unknown> = Record<string, unknown>,
|
|
179
|
-
>(config: CortexAgentDefinition<TSession, TRequestContext>)
|
|
210
|
+
>(config: CortexAgentDefinition<TSession, TRequestContext>) {
|
|
180
211
|
return config as CortexAgentDefinition;
|
|
181
212
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineConfig } from "drizzle-kit";
|
|
2
|
+
|
|
3
|
+
// Paths are relative to the package root, which is where drizzle-kit is invoked from.
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
schema: "./src/lib/db/schema.mssql.ts",
|
|
6
|
+
out: "./src/lib/db/migrations/mssql",
|
|
7
|
+
dialect: "mssql",
|
|
8
|
+
casing: "snake_case",
|
|
9
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineConfig } from "drizzle-kit";
|
|
2
|
+
|
|
3
|
+
// Paths are relative to the package root, which is where drizzle-kit is invoked from.
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
schema: "./src/lib/db/schema.pg.ts",
|
|
6
|
+
out: "./src/lib/db/migrations/pg",
|
|
7
|
+
dialect: "postgresql",
|
|
8
|
+
casing: "snake_case",
|
|
9
|
+
});
|
package/src/lib/db/migrate.ts
CHANGED
|
@@ -1,21 +1,56 @@
|
|
|
1
|
-
import mssql from "mssql";
|
|
2
|
-
import { drizzle } from "drizzle-orm/node-mssql";
|
|
3
|
-
import { migrate } from "drizzle-orm/node-mssql/migrator";
|
|
4
1
|
import { resolve } from "path";
|
|
2
|
+
import type { DatabaseConfig } from "@/config";
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Each dialect keeps its own migration history — Postgres starts from a
|
|
6
|
+
* squashed initial migration rather than replaying MSSQL's. The driver imports
|
|
7
|
+
* are lazy so a server only loads the one it was configured for.
|
|
8
|
+
*/
|
|
9
|
+
export async function runMigrations(database: DatabaseConfig) {
|
|
10
|
+
const migrationsFolder = resolve(import.meta.dir, "migrations", folderFor(database.type));
|
|
11
|
+
console.log("[cortex-server] Running migrations from:", migrationsFolder);
|
|
9
12
|
|
|
10
13
|
try {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
if (database.type === "postgres") {
|
|
15
|
+
await migratePostgres(database.connectionString, migrationsFolder);
|
|
16
|
+
} else {
|
|
17
|
+
await migrateMssql(database.connectionString, migrationsFolder);
|
|
18
|
+
}
|
|
15
19
|
console.log("[cortex-server] Migrations complete");
|
|
16
20
|
} catch (e) {
|
|
17
21
|
console.log(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function folderFor(type: DatabaseConfig["type"]) {
|
|
26
|
+
return type === "postgres" ? "pg" : "mssql";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function migrateMssql(connectionString: string, migrationsFolder: string) {
|
|
30
|
+
const { default: mssql } = await import("mssql");
|
|
31
|
+
const { drizzle } = await import("drizzle-orm/node-mssql");
|
|
32
|
+
const { migrate } = await import("drizzle-orm/node-mssql/migrator");
|
|
33
|
+
|
|
34
|
+
const pool = new mssql.ConnectionPool(connectionString);
|
|
35
|
+
await pool.connect();
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
await migrate(drizzle({ client: pool, casing: "snake_case" }), { migrationsFolder });
|
|
18
39
|
} finally {
|
|
19
40
|
await pool.close();
|
|
20
41
|
}
|
|
21
42
|
}
|
|
43
|
+
|
|
44
|
+
async function migratePostgres(connectionString: string, migrationsFolder: string) {
|
|
45
|
+
const { default: pg } = await import("pg");
|
|
46
|
+
const { drizzle } = await import("drizzle-orm/node-postgres");
|
|
47
|
+
const { migrate } = await import("drizzle-orm/node-postgres/migrator");
|
|
48
|
+
|
|
49
|
+
const pool = new pg.Pool({ connectionString });
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
await migrate(drizzle({ client: pool, casing: "snake_case" }), { migrationsFolder });
|
|
53
|
+
} finally {
|
|
54
|
+
await pool.end();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
CREATE TABLE [ai].[attachments] (
|
|
2
|
+
[id] UNIQUEIDENTIFIER CONSTRAINT [attachments_id_default] DEFAULT (NEWID()),
|
|
3
|
+
[thread_id] UNIQUEIDENTIFIER NOT NULL,
|
|
4
|
+
[user_id] UNIQUEIDENTIFIER NOT NULL,
|
|
5
|
+
[message_id] nvarchar(128),
|
|
6
|
+
[filename] nvarchar(2048) NOT NULL,
|
|
7
|
+
[content_type] nvarchar(256) NOT NULL,
|
|
8
|
+
[size_bytes] int NOT NULL,
|
|
9
|
+
[storage_key] nvarchar(512) NOT NULL,
|
|
10
|
+
[status] nvarchar(16) NOT NULL,
|
|
11
|
+
[description] nvarchar(max),
|
|
12
|
+
[created_at] datetime2 NOT NULL,
|
|
13
|
+
[updated_at] datetime2 NOT NULL,
|
|
14
|
+
CONSTRAINT [attachments_pkey] PRIMARY KEY([id])
|
|
15
|
+
);
|
|
16
|
+
--> statement-breakpoint
|
|
17
|
+
DROP TABLE [ai].[captured_files];--> statement-breakpoint
|
|
18
|
+
ALTER TABLE [ai].[attachments] ADD CONSTRAINT [attachments_thread_id_threads_id_fk] FOREIGN KEY ([thread_id]) REFERENCES [ai].[threads]([id]) ON DELETE CASCADE;--> statement-breakpoint
|
|
19
|
+
ALTER TABLE [ai].[attachments] ADD CONSTRAINT [attachments_message_id_messages_id_fk] FOREIGN KEY ([message_id]) REFERENCES [ai].[messages]([id]);--> statement-breakpoint
|
|
20
|
+
CREATE INDEX [attachments_thread_id_index] ON [ai].[attachments] ([thread_id]);
|