@peopl-health/nexus 6.0.0-dev.725 → 6.0.0
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 +104 -0
- package/lib/adapters/BaileysProvider.js +8 -37
- package/lib/adapters/MessageAdapter.js +3 -1
- package/lib/adapters/MessageProvider.js +0 -11
- package/lib/adapters/TwilioProvider.js +44 -77
- package/lib/clinical/AssistantProcessor.js +414 -19
- package/lib/clinical/assistants/BaseAssistant.js +0 -15
- package/lib/clinical/config/checkInConfig.js +3 -0
- package/lib/clinical/config/cohortConfig.js +3 -3
- package/lib/clinical/config/composerConfig.js +42 -0
- package/lib/clinical/config/divergenceConfig.js +80 -50
- package/lib/clinical/config/llmConfig.js +11 -2
- package/lib/clinical/config/safetyNetConfig.js +108 -0
- package/lib/clinical/config/subAgentsConfig.js +61 -2
- package/lib/clinical/context/ToolRuntimeContext.js +121 -6
- package/lib/clinical/context/turnContext.js +50 -0
- package/lib/clinical/flags/bridgeConfig.js +31 -0
- package/lib/clinical/flags/clinicalContextFlags.js +46 -0
- package/lib/clinical/flags/composerFlags.js +14 -0
- package/lib/clinical/flags/contingencyFlags.js +19 -0
- package/lib/clinical/flags/escalationFlags.js +43 -0
- package/lib/clinical/flags/flagSnapshot.js +58 -0
- package/lib/clinical/flags/inboundRecoveryFlags.js +17 -0
- package/lib/clinical/flags/llmAuditConfig.js +7 -0
- package/lib/clinical/flags/llmMonitorConfig.js +18 -0
- package/lib/clinical/flags/patternConsultFlags.js +10 -0
- package/lib/clinical/flags/recommendationRecoveryFlags.js +9 -0
- package/lib/clinical/flags/supportLightFlags.js +7 -0
- package/lib/clinical/flags/triageRecommendationFlags.js +16 -0
- package/lib/clinical/flags/turnEfficiencyFlags.js +19 -0
- package/lib/clinical/helpers/auditReasoningHelper.js +30 -0
- package/lib/clinical/helpers/carePlanInterventionDerivation.js +76 -0
- package/lib/clinical/helpers/carePlanValidationHelper.js +62 -0
- package/lib/clinical/helpers/ceilingGapHelper.js +21 -0
- package/lib/clinical/helpers/chemoContextHelper.js +217 -0
- package/lib/clinical/helpers/clinicalContextHelper.js +162 -0
- package/lib/clinical/helpers/clinicalFactsHelper.js +45 -4
- package/lib/clinical/helpers/clinicalMentionHelper.js +16 -13
- package/lib/clinical/helpers/clinicalProfileHelper.js +60 -0
- package/lib/clinical/helpers/clinicalWorkflowGuard.js +175 -0
- package/lib/clinical/helpers/cohortHelper.js +3 -1
- package/lib/clinical/helpers/contextMirrorHelper.js +68 -0
- package/lib/clinical/helpers/dateAnchorHelper.js +18 -0
- package/lib/clinical/helpers/doctorReviewMessageHelper.js +152 -0
- package/lib/clinical/helpers/drugIdentityHelper.js +67 -0
- package/lib/clinical/helpers/encodedPairHelper.js +12 -0
- package/lib/clinical/helpers/evidenceAnchorHelper.js +70 -0
- package/lib/clinical/helpers/factAssertionHelper.js +300 -0
- package/lib/clinical/helpers/gradeEstimateHelper.js +148 -0
- package/lib/clinical/helpers/hospitalizationContextHelper.js +8 -0
- package/lib/clinical/helpers/legacyContextHelper.js +122 -0
- package/lib/clinical/helpers/legacyRecommendationFormatHelper.js +107 -0
- package/lib/clinical/helpers/llmsHelper.js +170 -87
- package/lib/clinical/helpers/managedSymptomProjectionHelper.js +23 -0
- package/lib/clinical/helpers/medicationNamingRule.js +5 -0
- package/lib/clinical/helpers/palliativeAssessmentHelper.js +62 -0
- package/lib/clinical/helpers/palliativeCarePlanHelper.js +68 -0
- package/lib/clinical/helpers/recommendationGateHelper.js +208 -0
- package/lib/clinical/helpers/recommendationPlanHelper.js +104 -0
- package/lib/clinical/helpers/resultsHelper.js +56 -0
- package/lib/clinical/helpers/reviewUpdateHelper.js +68 -0
- package/lib/clinical/helpers/shadowHelper.js +1 -13
- package/lib/clinical/helpers/skillActivationHelper.js +53 -0
- package/lib/clinical/helpers/structuredTextHelper.js +13 -0
- package/lib/clinical/helpers/toolResultHelper.js +35 -0
- package/lib/clinical/helpers/triageCaseBaseHelper.js +483 -0
- package/lib/clinical/helpers/triageResultMessageHelper.js +30 -0
- package/lib/clinical/helpers/triageRetriggerHelper.js +85 -0
- package/lib/clinical/helpers/triageSymptomsHelper.js +33 -0
- package/lib/clinical/index.js +4 -0
- package/lib/clinical/memory/DefaultMemoryManager.js +211 -39
- package/lib/clinical/memory/EnhancedMemoryManager.js +14 -8
- package/lib/clinical/models/llmCallModel.js +19 -0
- package/lib/clinical/models/llmMonitorCheckpointModel.js +20 -0
- package/lib/clinical/models/llmMonitorEvaluationModel.js +56 -0
- package/lib/clinical/models/patternConsultModel.js +37 -0
- package/lib/clinical/models/riskWarmupEventModel.js +23 -0
- package/lib/clinical/models/supportCandidateModel.js +90 -0
- package/lib/clinical/models/supportLightModel.js +95 -0
- package/lib/clinical/models/triageRecommendationEventModel.js +110 -0
- package/lib/clinical/models/turnTraceModel.js +24 -7
- package/lib/clinical/monitoring/AirtableMonitorSink.js +488 -0
- package/lib/clinical/monitoring/LlmMonitorService.js +558 -0
- package/lib/clinical/monitoring/contingencyMonitorSpec.js +601 -0
- package/lib/clinical/promptPlacement.js +5 -0
- package/lib/clinical/protocols/treatmentFormulary.js +387 -0
- package/lib/clinical/providers/AnthropicProvider.js +459 -31
- package/lib/clinical/providers/BaseLLMProvider.js +689 -52
- package/lib/clinical/providers/GatewayProvider.js +14 -4
- package/lib/clinical/providers/OpenAIResponsesProvider.js +73 -11
- package/lib/clinical/providers/OpenAIResponsesProviderTools.js +24 -9
- package/lib/clinical/providers/OpenRouterProvider.js +9 -2
- package/lib/clinical/services/assistantService.js +51 -7
- package/lib/clinical/services/bridgeService.js +93 -0
- package/lib/clinical/services/checkInDueService.js +134 -0
- package/lib/clinical/services/clinicalAirtableService.js +752 -0
- package/lib/clinical/services/clinicalContextReadService.js +47 -0
- package/lib/clinical/services/clinicalExtractionService.js +156 -23
- package/lib/clinical/services/composerService.js +78 -0
- package/lib/clinical/services/conceptVerifierService.js +127 -0
- package/lib/clinical/services/conditionCloseService.js +138 -0
- package/lib/clinical/services/contextCleanupService.js +85 -0
- package/lib/clinical/services/contextMirrorService.js +72 -0
- package/lib/clinical/services/contextSyncRunner.js +20 -0
- package/lib/clinical/services/contextSyncService.js +258 -0
- package/lib/clinical/services/contingencyDispatchService.js +496 -0
- package/lib/clinical/services/ctcaeLadderService.js +70 -0
- package/lib/clinical/services/ctcaeTermService.js +44 -0
- package/lib/clinical/services/currentRegimenService.js +60 -0
- package/lib/clinical/services/deliverySettlementService.js +39 -0
- package/lib/clinical/services/deniedSymptomBoundaryService.js +218 -0
- package/lib/clinical/services/dispatcherService.js +142 -0
- package/lib/clinical/services/escalationDraftService.js +229 -0
- package/lib/clinical/services/escalationNoteFactsService.js +131 -0
- package/lib/clinical/services/escalationQuestionsService.js +131 -0
- package/lib/clinical/services/gradeAnchorService.js +85 -0
- package/lib/clinical/services/gradeClaimService.js +73 -0
- package/lib/clinical/services/gradeSourceService.js +138 -0
- package/lib/clinical/services/impressionValidationService.js +19 -0
- package/lib/clinical/services/legacyContextSyncService.js +255 -0
- package/lib/clinical/services/llmAuditService.js +23 -0
- package/lib/clinical/services/nutritionPlanService.js +97 -0
- package/lib/clinical/services/outreachCarrierService.js +88 -0
- package/lib/clinical/services/outreachSweepRunner.js +8 -0
- package/lib/clinical/services/outreachSweepService.js +644 -0
- package/lib/clinical/services/patientHistoryService.js +203 -0
- package/lib/clinical/services/patientIdentityService.js +43 -0
- package/lib/clinical/services/patientProfileService.js +145 -0
- package/lib/clinical/services/patternConsultService.js +127 -0
- package/lib/clinical/services/pausedSafetyNetService.js +387 -0
- package/lib/clinical/services/promptComposerService.js +74 -21
- package/lib/clinical/services/radiotherapyContextService.js +40 -0
- package/lib/clinical/services/radiotherapyPhaseService.js +272 -0
- package/lib/clinical/services/recommendationRankService.js +180 -0
- package/lib/clinical/services/recommendationRecoveryService.js +241 -0
- package/lib/clinical/services/recommendationValidationService.js +206 -0
- package/lib/clinical/services/regimenCloserService.js +205 -0
- package/lib/clinical/services/reminderDispatchService.js +36 -0
- package/lib/clinical/services/riskAssessmentService.js +469 -0
- package/lib/clinical/services/riskHeadlineService.js +56 -0
- package/lib/clinical/services/safetyNetPledgeService.js +231 -0
- package/lib/clinical/services/shadowMessageService.js +30 -12
- package/lib/clinical/services/shadowService.js +8 -4
- package/lib/clinical/services/skillService.js +117 -0
- package/lib/clinical/services/supportActionService.js +122 -0
- package/lib/clinical/services/supportCandidateService.js +607 -0
- package/lib/clinical/services/supportInvitability.js +86 -0
- package/lib/clinical/services/supportLightEvaluationService.js +231 -0
- package/lib/clinical/services/supportLightService.js +277 -0
- package/lib/clinical/services/supportRoutingAgentService.js +118 -0
- package/lib/clinical/services/symptomLandscapeService.js +153 -0
- package/lib/clinical/services/treatmentProposalService.js +136 -0
- package/lib/clinical/services/triageRecommendationService.js +1226 -0
- package/lib/clinical/services/turnRiskBriefService.js +217 -0
- package/lib/clinical/services/writeClaimStore.js +126 -0
- package/lib/clinical/stores/CtcaeCatalog.js +21 -0
- package/lib/clinical/tools/analyzeSymptomPatternsTool.js +276 -0
- package/lib/clinical/tools/deliverPatientMessageTool.js +294 -0
- package/lib/clinical/tools/extractClinicalInfoTool.js +252 -37
- package/lib/clinical/tools/getActiveRecommendationsTool.js +44 -0
- package/lib/clinical/tools/getActiveSymptomLandscapeTool.js +37 -0
- package/lib/clinical/tools/getPatientHistoryTool.js +45 -0
- package/lib/clinical/tools/getPatientRiskAssessmentTool.js +66 -0
- package/lib/clinical/tools/getRouterContextBundleTool.js +136 -0
- package/lib/clinical/tools/lookupCtcaeEntryTool.js +36 -0
- package/lib/clinical/tools/openClusterHypothesisTool.js +175 -0
- package/lib/clinical/tools/openConditionTool.js +198 -0
- package/lib/clinical/tools/recordClinicalImpressionTool.js +394 -0
- package/lib/clinical/tools/recordInterventionTool.js +138 -0
- package/lib/clinical/tools/recordRecommendationOutcomeTool.js +72 -0
- package/lib/clinical/tools/registerClinicalTools.js +51 -6
- package/lib/clinical/tools/reportCrisisTool.js +193 -0
- package/lib/clinical/tools/reportMedicalEscalationTool.js +471 -0
- package/lib/clinical/tools/reportResultsReceivedTool.js +176 -0
- package/lib/clinical/tools/reportUnresolvedRequestv2Tool.js +164 -0
- package/lib/clinical/tools/requestPatternConsultTool.js +70 -0
- package/lib/clinical/tools/schedulePatientReminderTool.js +292 -0
- package/lib/clinical/tools/sendBridgeMessageTool.js +33 -0
- package/lib/clinical/tools/setContingencyPlanTool.js +332 -0
- package/lib/clinical/tools/skillTool.js +81 -0
- package/lib/clinical/tools/submitNutritionSafetyDecisionTool.js +200 -0
- package/lib/clinical/tools/submitOutreachDecisionTool.js +139 -0
- package/lib/clinical/tools/submitPalliativeAssessmentTool.js +75 -0
- package/lib/clinical/tools/submitPalliativeCarePlanTool.js +101 -0
- package/lib/clinical/tools/submitRecommendationPlanTool.js +145 -0
- package/lib/clinical/tools/submitRoutingDecisionTool.js +466 -0
- package/lib/clinical/tools/submitSafetyGateTool.js +130 -0
- package/lib/clinical/tools/submitSupportRoutingRecommendationTool.js +149 -0
- package/lib/clinical/tools/updateClusterHypothesisTool.js +178 -0
- package/lib/clinical/tools/updateConditionStatusTool.js +192 -0
- package/lib/clinical/tools/updatePalliativeAssessmentTool.js +78 -0
- package/lib/config/airtableArchiveConfig.js +177 -0
- package/lib/config/airtableConfig.js +24 -1
- package/lib/config/instructionConfig.js +5 -0
- package/lib/config/lifecycle.js +36 -1
- package/lib/config/programConfig.js +20 -0
- package/lib/controllers/assistantController.js +67 -11
- package/lib/controllers/contextSyncController.js +30 -0
- package/lib/controllers/contingencyController.js +28 -0
- package/lib/controllers/conversationController.js +7 -7
- package/lib/controllers/dashboardController.js +7 -4
- package/lib/controllers/escalationReviewController.js +299 -0
- package/lib/controllers/healthController.js +16 -0
- package/lib/controllers/interactionController.js +1 -1
- package/lib/controllers/messageController.js +67 -19
- package/lib/controllers/officeAssistantController.js +57 -0
- package/lib/controllers/patientController.js +216 -48
- package/lib/controllers/prescriptionController.js +10 -3
- package/lib/controllers/templateController.js +8 -17
- package/lib/controllers/traceController.js +26 -0
- package/lib/controllers/triageRecommendationController.js +41 -0
- package/lib/controllers/uploadController.js +2 -2
- package/lib/core/BatchingManager.js +146 -11
- package/lib/core/DeferredWorkRunner.js +257 -0
- package/lib/core/MessageParser.js +2 -2
- package/lib/core/NexusMessaging.js +948 -146
- package/lib/core/PhiProcessor.js +198 -17
- package/lib/core/ProcessingPipeline.js +49 -4
- package/lib/core/interactiveRouteService.js +64 -0
- package/lib/core/runtimeToolPolicy.js +3 -0
- package/lib/eval/EvalProvider.js +72 -25
- package/lib/fhir/config/catalogConfig.js +9 -14
- package/lib/fhir/config/fhirConfig.js +16 -12
- package/lib/fhir/constants/escalationCaseStatus.js +31 -0
- package/lib/fhir/constants/extensionSlugs.js +195 -0
- package/lib/fhir/constants/gradeMethods.js +12 -0
- package/lib/fhir/constants/projectionSlugs.js +69 -1
- package/lib/fhir/constants/severityPriority.js +8 -0
- package/lib/fhir/constants/variableRegistry.js +60 -0
- package/lib/fhir/helpers/compositeHelper.js +65 -12
- package/lib/fhir/helpers/contextArbitrationHelper.js +41 -0
- package/lib/fhir/helpers/elementHelper.js +39 -0
- package/lib/fhir/helpers/fhirHelper.js +4 -1
- package/lib/fhir/helpers/fhirReadHelper.js +62 -0
- package/lib/fhir/helpers/recommendationIds.js +44 -0
- package/lib/fhir/helpers/resourceDisplayHelper.js +9 -0
- package/lib/fhir/helpers/resourceHelper.js +46 -0
- package/lib/fhir/helpers/symptomAliasHelper.js +56 -0
- package/lib/fhir/helpers/termMatchHelper.js +42 -0
- package/lib/fhir/helpers/terminologyHelper.js +92 -5
- package/lib/fhir/helpers/triagePayloadHelper.js +133 -0
- package/lib/fhir/helpers/variableRegistryHelper.js +21 -0
- package/lib/fhir/index.js +75 -0
- package/lib/fhir/models/envelopeModel.js +22 -0
- package/lib/fhir/projections/clinicalMentionProjection.js +208 -46
- package/lib/fhir/projections/clusterProjection.js +124 -0
- package/lib/fhir/projections/contextFactProjection.js +380 -0
- package/lib/fhir/projections/contingencyProjection.js +224 -0
- package/lib/fhir/projections/dispatchedEscalationProjection.js +63 -0
- package/lib/fhir/projections/interventionProjection.js +245 -0
- package/lib/fhir/projections/palliativeCarePlanProjection.js +183 -0
- package/lib/fhir/projections/palliativeProjection.js +175 -0
- package/lib/fhir/projections/proctcaeProjection.js +62 -15
- package/lib/fhir/projections/recommendationPlanProjection.js +557 -0
- package/lib/fhir/projections/registerProjectors.js +10 -2
- package/lib/fhir/projections/reminderProjection.js +20 -0
- package/lib/fhir/projections/riskProjection.js +16 -0
- package/lib/fhir/projections/routingProjection.js +285 -0
- package/lib/fhir/projections/safetyGateProjection.js +42 -0
- package/lib/fhir/projections/symptomCaseProjection.js +324 -0
- package/lib/fhir/resources/CommunicationRequest.js +91 -0
- package/lib/fhir/resources/Condition.js +2 -24
- package/lib/fhir/resources/Encounter.js +30 -0
- package/lib/fhir/resources/Observation.js +22 -69
- package/lib/fhir/resources/Patient.js +57 -6
- package/lib/fhir/resources/Provenance.js +48 -12
- package/lib/fhir/resources/RiskAssessment.js +184 -0
- package/lib/fhir/resources/Task.js +102 -0
- package/lib/fhir/services/clinicalContextService.js +161 -0
- package/lib/fhir/services/clinicalMentionService.js +3 -5
- package/lib/fhir/services/clusterService.js +30 -0
- package/lib/fhir/services/contingencyService.js +47 -0
- package/lib/fhir/services/encounterService.js +16 -0
- package/lib/fhir/services/escalationService.js +85 -0
- package/lib/fhir/services/fhirService.js +20 -0
- package/lib/fhir/services/interventionService.js +50 -0
- package/lib/fhir/services/palliativeService.js +74 -0
- package/lib/fhir/services/patientService.js +41 -0
- package/lib/fhir/services/recommendationService.js +336 -0
- package/lib/fhir/services/resultObservationService.js +53 -0
- package/lib/fhir/services/riskService.js +202 -0
- package/lib/fhir/services/routingService.js +86 -0
- package/lib/fhir/services/snapshotService.js +18 -3
- package/lib/fhir/services/symptomCaseService.js +33 -0
- package/lib/fhir/services/terminologyService.js +16 -21
- package/lib/fhir/services/triageService.js +8 -4
- package/lib/fhir/stores/fhirStore.js +42 -19
- package/lib/fhir/utils/normalizeUtils.js +12 -0
- package/lib/helpers/airtableArchiveHelper.js +51 -0
- package/lib/helpers/airtableFormulaHelper.js +25 -0
- package/lib/helpers/caregiverHelper.js +136 -0
- package/lib/helpers/channelErrorHelper.js +31 -0
- package/lib/helpers/channelRetryHelper.js +156 -0
- package/lib/helpers/conversationWindowHelper.js +2 -2
- package/lib/helpers/deliveryAttemptHelper.js +14 -2
- package/lib/helpers/filesHelper.js +3 -3
- package/lib/helpers/healthHelper.js +40 -0
- package/lib/helpers/messageHelper.js +16 -6
- package/lib/helpers/messageStatusHelper.js +16 -22
- package/lib/helpers/metaSignatureHelper.js +6 -6
- package/lib/helpers/nerHelper.js +24 -0
- package/lib/helpers/outboundAllowlistHelper.js +51 -0
- package/lib/helpers/patientInformationHelper.js +20 -16
- package/lib/helpers/patientMessageHelper.js +79 -0
- package/lib/helpers/patientTaskRulesHelper.js +57 -0
- package/lib/helpers/pausedThreadHelper.js +37 -0
- package/lib/helpers/processHelper.js +47 -16
- package/lib/helpers/sendClaimHelper.js +126 -0
- package/lib/helpers/staffSendHelper.js +4 -0
- package/lib/helpers/templateFlowControllerHelper.js +1 -1
- package/lib/helpers/templateRecoveryHelper.js +66 -8
- package/lib/helpers/triageRecordHelper.js +124 -0
- package/lib/helpers/twilioHelper.js +7 -79
- package/lib/helpers/twilioMediaHelper.js +1 -1
- package/lib/helpers/whatsappHelper.js +3 -1
- package/lib/index.d.ts +844 -34
- package/lib/index.js +169 -11
- package/lib/jobs/ScheduledMessageJob.js +44 -0
- package/lib/jobs/TemplateApprovalJob.js +200 -33
- package/lib/models/agendaMessageModel.js +5 -0
- package/lib/models/airtableArchiveModel.js +225 -0
- package/lib/models/contactGateDecisionModel.js +27 -0
- package/lib/models/contextSyncStateModel.js +26 -0
- package/lib/models/deferredWorkModel.js +24 -0
- package/lib/models/deliveryAttemptModel.js +5 -1
- package/lib/models/escalationReviewModel.js +341 -0
- package/lib/models/flowRoutingModel.js +1 -1
- package/lib/models/messageModel.js +21 -1
- package/lib/models/patientProfileModel.js +24 -0
- package/lib/models/safetyNetPledgeModel.js +31 -0
- package/lib/models/sendClaimModel.js +18 -0
- package/lib/models/templateModel.js +1 -2
- package/lib/models/threadModel.js +7 -0
- package/lib/models/tokenMapModel.js +2 -1
- package/lib/models/writeClaimModel.js +14 -0
- package/lib/observability/telemetry.js +7 -7
- package/lib/providers/NerClient.js +2 -2
- package/lib/queue/QueueAdapter.js +1 -0
- package/lib/queue/RedisQueueAdapter.js +104 -7
- package/lib/routes/index.js +132 -2
- package/lib/services/airtableArchivePlanService.js +197 -0
- package/lib/services/airtableArchiveReadService.js +48 -0
- package/lib/services/airtableArchiveService.js +561 -0
- package/lib/services/airtableMirrorService.js +223 -0
- package/lib/services/airtableService.js +198 -18
- package/lib/services/assistantMessageService.js +140 -0
- package/lib/services/carePlanHistoryService.js +610 -0
- package/lib/services/characterizationOutcomeService.js +294 -0
- package/lib/services/contactGateService.js +178 -0
- package/lib/services/conversationService.js +66 -20
- package/lib/services/dashboard-provider-registry.js +38 -0
- package/lib/services/dashboardService.js +31 -4
- package/lib/services/escalationCaseTaskService.js +134 -0
- package/lib/services/escalationContextService.js +92 -0
- package/lib/services/escalationReviewService.js +2214 -0
- package/lib/services/flowDataExchangeService.js +1 -1
- package/lib/services/globalEntityService.js +1 -1
- package/lib/services/gravePendingService.js +41 -0
- package/lib/services/healthService.js +252 -0
- package/lib/services/heldMessageService.js +141 -0
- package/lib/services/inboundRecoveryService.js +354 -0
- package/lib/services/instructionInFlightService.js +17 -0
- package/lib/services/officeAssistantService.js +217 -0
- package/lib/services/orbisService.js +44 -0
- package/lib/services/patientClinicalStatusService.js +189 -0
- package/lib/services/patientResourceService.js +24 -0
- package/lib/services/patientService.js +28 -16
- package/lib/services/patientTaskService.js +221 -0
- package/lib/services/patientTaskSummaryService.js +93 -0
- package/lib/services/physicianService.js +31 -0
- package/lib/services/preprocessingService.js +18 -6
- package/lib/services/queueReconciliationService.js +161 -0
- package/lib/services/recommendationCarouselService.js +398 -0
- package/lib/services/reviewAlertSweepService.js +99 -0
- package/lib/services/reviewBoardService.js +75 -0
- package/lib/services/reviewDeadlineService.js +116 -0
- package/lib/services/reviewDraftSweepService.js +85 -0
- package/lib/services/teamAlertService.js +140 -0
- package/lib/services/templateService.js +1 -2
- package/lib/{helpers/threadHelper.js → services/threadService.js} +38 -6
- package/lib/services/tokenMapService.js +119 -22
- package/lib/services/toolRegistryService.js +43 -2
- package/lib/services/triageHistoryService.js +128 -0
- package/lib/services/twilioMediaService.js +79 -0
- package/lib/services/undeliverableService.js +36 -0
- package/lib/services/untakenAlertService.js +210 -0
- package/lib/shared/dtos/ClinicalAssertion.js +21 -0
- package/lib/shared/dtos/ClinicalMention.js +4 -0
- package/lib/shared/dtos/ClusterImpression.js +16 -5
- package/lib/shared/dtos/ContingencySafetyNet.js +69 -7
- package/lib/shared/dtos/DispatchedEscalation.js +4 -8
- package/lib/shared/dtos/GradedSymptom.js +2 -0
- package/lib/shared/dtos/Intervention.js +10 -3
- package/lib/shared/dtos/ManagedSymptom.js +40 -11
- package/lib/shared/dtos/NutritionSafetyDecision.js +128 -0
- package/lib/shared/dtos/PalliativeAssessment.js +62 -0
- package/lib/shared/dtos/PalliativeCarePlan.js +47 -0
- package/lib/shared/dtos/PatientRiskAssessment.js +25 -1
- package/lib/shared/dtos/RecommendationPlan.js +102 -0
- package/lib/shared/dtos/RecommendationSafetyGate.js +64 -0
- package/lib/shared/dtos/Reminder.js +2 -2
- package/lib/shared/dtos/RoutingDecision.js +2 -1
- package/lib/shared/dtos/SupportAction.js +28 -0
- package/lib/shared/dtos/SupportRoutingRecommendation.js +124 -0
- package/lib/shared/dtos/TriageCompletion.js +50 -0
- package/lib/shared/dtos/TriageResponse.js +7 -1
- package/lib/storage/MongoStorage.js +10 -1
- package/lib/templates/predefinedTemplates.js +1 -1
- package/lib/templates/templateStructure.js +15 -2
- package/lib/utils/MapCache.js +1 -1
- package/lib/utils/coercionUtils.js +11 -0
- package/lib/utils/concurrencyUtils.js +13 -0
- package/lib/utils/dateUtils.js +114 -6
- package/lib/utils/errorUtils.js +26 -1
- package/lib/utils/formatUtils.js +43 -37
- package/lib/utils/httpErrorUtils.js +9 -0
- package/lib/utils/intervalSweeper.js +75 -0
- package/lib/utils/jsonUtils.js +51 -0
- package/lib/utils/logger.js +8 -6
- package/lib/utils/paginationUtils.js +30 -0
- package/lib/utils/retryUtils.js +9 -1
- package/lib/utils/sanitizerUtils.js +87 -1
- package/lib/utils/scheduleUtils.js +70 -1
- package/lib/utils/shadowScope.js +13 -0
- package/lib/utils/statsUtils.js +21 -0
- package/lib/utils/textMatchUtils.js +76 -0
- package/lib/utils/timeoutUtils.js +16 -0
- package/lib/utils/tokenMapUtils.js +3 -3
- package/package.json +11 -11
- package/lib/clinical/helpers/divergenceHelper.js +0 -100
- package/lib/clinical/models/divergenceModel.js +0 -41
- package/lib/clinical/services/clinicalAgentService.js +0 -18
- package/lib/clinical/services/divergenceService.js +0 -90
- package/lib/core/workflowRunner.js +0 -35
- package/lib/fhir/resources/Appointment.js +0 -28
- package/lib/fhir/resources/MedicationStatement.js +0 -42
- package/lib/fhir/resources/Procedure.js +0 -30
- package/lib/services/twilioService.js +0 -13
|
@@ -2,18 +2,81 @@ const { Config_ID } = require('../../config/airtableConfig');
|
|
|
2
2
|
|
|
3
3
|
const { getRecordByFilter } = require('../../services/airtableService');
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const { ESCALATION_ROUTES } = require('../../shared/dtos/RecommendationSafetyGate');
|
|
6
|
+
|
|
7
|
+
const { MapCache } = require('../../utils/MapCache');
|
|
8
|
+
const { safeParseArray, isPlainObject } = require('../../utils/jsonUtils');
|
|
7
9
|
|
|
8
10
|
const DIVERGENCE_CONFIG_TABLE = 'divergence';
|
|
9
11
|
const CACHE_TTL = 5 * 60 * 1000;
|
|
10
12
|
const CACHE_KEY = 'divergenceConfig';
|
|
11
|
-
const COMPARATOR_TYPES = ['scalar', 'set'];
|
|
12
|
-
const ORACLE_CONNECTION_DEFAULTS = { enabled: false, baseUrl: '', timeoutMs: null };
|
|
13
|
-
const STOCHASTIC_DEFAULTS = { enabled: false, presetId: '' };
|
|
14
13
|
|
|
15
14
|
const cache = new MapCache({ maxSize: 1, ttl: CACHE_TTL });
|
|
16
15
|
|
|
16
|
+
function parseSafetyFlagPatterns(value) {
|
|
17
|
+
if (!value) return [];
|
|
18
|
+
const parsedPatterns = safeParseArray(value);
|
|
19
|
+
if (!parsedPatterns) throw new Error('divergence config SAFETY_FLAG_PATTERNS is not a JSON array');
|
|
20
|
+
return parsedPatterns.map((row) => {
|
|
21
|
+
if (!isPlainObject(row)) throw new Error('divergence config SAFETY_FLAG_PATTERNS row is not an object');
|
|
22
|
+
const { flag, pattern } = row;
|
|
23
|
+
if (!flag || !pattern) throw new Error('divergence config SAFETY_FLAG_PATTERNS row missing flag or pattern');
|
|
24
|
+
try {
|
|
25
|
+
return { flag, re: new RegExp(pattern, 'i') };
|
|
26
|
+
} catch (err) {
|
|
27
|
+
throw new Error(`divergence config SAFETY_FLAG_PATTERNS pattern for ${flag} is not a valid regex: ${err.message}`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseRedFlagMinRoute(row) {
|
|
33
|
+
if (!isPlainObject(row)) throw new Error('divergence config RED_FLAG_MIN_ROUTES row is not an object');
|
|
34
|
+
const {
|
|
35
|
+
flag,
|
|
36
|
+
ctcae_terms: ctcaeTerms,
|
|
37
|
+
min_route: minRoute,
|
|
38
|
+
max_action_time_hours: maxActionTimeHours,
|
|
39
|
+
requires_risk: requiresRisk = true,
|
|
40
|
+
} = row;
|
|
41
|
+
if (typeof flag !== 'string' || !flag.trim()) throw new Error('divergence config RED_FLAG_MIN_ROUTES row missing flag');
|
|
42
|
+
if (!Array.isArray(ctcaeTerms) || !ctcaeTerms.length || !ctcaeTerms.every((term) => typeof term === 'string' && term.trim())) {
|
|
43
|
+
throw new Error(`divergence config RED_FLAG_MIN_ROUTES ctcae_terms for ${flag} is not a non-empty list of terms`);
|
|
44
|
+
}
|
|
45
|
+
if (!ESCALATION_ROUTES.includes(minRoute)) {
|
|
46
|
+
throw new Error(`divergence config RED_FLAG_MIN_ROUTES min_route for ${flag} is not one of ${ESCALATION_ROUTES.join(', ')}`);
|
|
47
|
+
}
|
|
48
|
+
if (!Number.isInteger(maxActionTimeHours) || maxActionTimeHours < 1 || maxActionTimeHours > 24) {
|
|
49
|
+
throw new Error(`divergence config RED_FLAG_MIN_ROUTES max_action_time_hours for ${flag} is not an integer from 1 to 24`);
|
|
50
|
+
}
|
|
51
|
+
if (typeof requiresRisk !== 'boolean') throw new Error(`divergence config RED_FLAG_MIN_ROUTES requires_risk for ${flag} is not a boolean`);
|
|
52
|
+
return {
|
|
53
|
+
flag, ctcaeTerms, minRoute, maxActionTimeHours, requiresRisk,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parseRedFlagMinRoutes(value) {
|
|
58
|
+
const routes = { rows: [], invalidRows: [] };
|
|
59
|
+
if (!value) return routes;
|
|
60
|
+
const parsedRoutes = safeParseArray(value);
|
|
61
|
+
if (!parsedRoutes) throw new Error('divergence config RED_FLAG_MIN_ROUTES is not a JSON array');
|
|
62
|
+
for (const row of parsedRoutes) {
|
|
63
|
+
try {
|
|
64
|
+
routes.rows.push(parseRedFlagMinRoute(row));
|
|
65
|
+
} catch (err) {
|
|
66
|
+
routes.invalidRows.push(err.message);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return routes;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function parseIsolated(parse) {
|
|
73
|
+
try {
|
|
74
|
+
return { value: parse(), error: null };
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return { value: null, error };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
17
80
|
async function load() {
|
|
18
81
|
const cached = cache.get(CACHE_KEY);
|
|
19
82
|
if (cached) return cached;
|
|
@@ -22,47 +85,10 @@ async function load() {
|
|
|
22
85
|
if (!records) throw new Error('divergence config could not be read from the Config base');
|
|
23
86
|
const byKey = Object.fromEntries(records.map((r) => [r.config, r.value]));
|
|
24
87
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const unknown = fields.filter(({ type }) => !COMPARATOR_TYPES.includes(type));
|
|
31
|
-
if (unknown.length) throw new Error(`divergence config FIELDS has unknown types: ${unknown.map(({ field, type }) => `${field}:${type}`).join(', ')}`);
|
|
32
|
-
|
|
33
|
-
const misplaced = fields.filter(({ type, emergencyKinds }) => emergencyKinds && type !== 'scalar');
|
|
34
|
-
if (misplaced.length) throw new Error(`divergence config emergencyKinds only applies to scalar fields: ${misplaced.map(({ field }) => field).join(', ')}`);
|
|
35
|
-
|
|
36
|
-
const parsedOracle = safeParse(byKey.ORACLE_CONNECTION, null);
|
|
37
|
-
if (byKey.ORACLE_CONNECTION && !isPlainObject(parsedOracle)) throw new Error('divergence config ORACLE_CONNECTION is not a JSON object');
|
|
38
|
-
const oracleConnection = { ...ORACLE_CONNECTION_DEFAULTS, ...(parsedOracle || {}) };
|
|
39
|
-
if (oracleConnection.enabled) {
|
|
40
|
-
oracleConnection.timeoutMs = Number(oracleConnection.timeoutMs);
|
|
41
|
-
if (!Number.isFinite(oracleConnection.timeoutMs) || oracleConnection.timeoutMs <= 0) throw new Error('divergence config ORACLE_CONNECTION.timeoutMs is not a positive number');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const parsedStochastic = safeParse(byKey.STOCHASTIC, null);
|
|
45
|
-
if (byKey.STOCHASTIC && !isPlainObject(parsedStochastic)) throw new Error('divergence config STOCHASTIC is not a JSON object');
|
|
46
|
-
const stochastic = { ...STOCHASTIC_DEFAULTS, ...(parsedStochastic || {}) };
|
|
47
|
-
if (stochastic.enabled && !stochastic.presetId) throw new Error('divergence config STOCHASTIC.presetId is required when enabled');
|
|
48
|
-
|
|
49
|
-
let safetyFlagPatterns = [];
|
|
50
|
-
if (byKey.SAFETY_FLAG_PATTERNS) {
|
|
51
|
-
const parsedPatterns = safeParseArray(byKey.SAFETY_FLAG_PATTERNS);
|
|
52
|
-
if (!parsedPatterns) throw new Error('divergence config SAFETY_FLAG_PATTERNS is not a JSON array');
|
|
53
|
-
safetyFlagPatterns = parsedPatterns.map((row) => {
|
|
54
|
-
if (!isPlainObject(row)) throw new Error('divergence config SAFETY_FLAG_PATTERNS row is not an object');
|
|
55
|
-
const { flag, pattern } = row;
|
|
56
|
-
if (!flag || !pattern) throw new Error('divergence config SAFETY_FLAG_PATTERNS row missing flag or pattern');
|
|
57
|
-
try {
|
|
58
|
-
return { flag, re: new RegExp(pattern, 'i') };
|
|
59
|
-
} catch (err) {
|
|
60
|
-
throw new Error(`divergence config SAFETY_FLAG_PATTERNS pattern for ${flag} is not a valid regex: ${err.message}`);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const config = { FIELDS: fields, ORACLE_CONNECTION: oracleConnection, STOCHASTIC: stochastic, SAFETY_FLAG_PATTERNS: safetyFlagPatterns };
|
|
88
|
+
const config = {
|
|
89
|
+
SAFETY_FLAG_PATTERNS: parseIsolated(() => parseSafetyFlagPatterns(byKey.SAFETY_FLAG_PATTERNS)),
|
|
90
|
+
RED_FLAG_MIN_ROUTES: parseIsolated(() => parseRedFlagMinRoutes(byKey.RED_FLAG_MIN_ROUTES)),
|
|
91
|
+
};
|
|
66
92
|
cache.set(CACHE_KEY, config);
|
|
67
93
|
return config;
|
|
68
94
|
}
|
|
@@ -72,9 +98,13 @@ async function get(key) {
|
|
|
72
98
|
return config[key];
|
|
73
99
|
}
|
|
74
100
|
|
|
101
|
+
async function getIsolated(key) {
|
|
102
|
+
const { value, error } = await get(key);
|
|
103
|
+
if (error) throw error;
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
|
|
75
107
|
module.exports = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
getStochastic: () => get('STOCHASTIC'),
|
|
79
|
-
getSafetyFlagPatterns: () => get('SAFETY_FLAG_PATTERNS'),
|
|
108
|
+
getSafetyFlagPatterns: () => getIsolated('SAFETY_FLAG_PATTERNS'),
|
|
109
|
+
getRedFlagMinRoutes: () => getIsolated('RED_FLAG_MIN_ROUTES'),
|
|
80
110
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { createLLMProvider } = require('../providers/createLLMProvider');
|
|
2
|
+
const { REQUEST_MAX_RETRIES, resolveRequestTimeoutMs } = require('../providers/AnthropicProvider');
|
|
2
3
|
const runtimeConfig = require('../../config/runtimeConfig');
|
|
3
4
|
|
|
4
5
|
const { logger } = require('../../utils/logger');
|
|
@@ -7,7 +8,8 @@ const state = {
|
|
|
7
8
|
anthropicClient: null,
|
|
8
9
|
openaiClient: null,
|
|
9
10
|
provider: null,
|
|
10
|
-
variant: null
|
|
11
|
+
variant: null,
|
|
12
|
+
gatewayProvider: null
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
const setOpenAIProvider = (provider) => {
|
|
@@ -38,13 +40,18 @@ const configureOpenAIProvider = (config = {}) => {
|
|
|
38
40
|
return provider;
|
|
39
41
|
};
|
|
40
42
|
|
|
43
|
+
const requireGatewayProvider = () => {
|
|
44
|
+
if (!state.gatewayProvider) state.gatewayProvider = createLLMProvider({ variant: 'gateway' });
|
|
45
|
+
return state.gatewayProvider;
|
|
46
|
+
};
|
|
47
|
+
|
|
41
48
|
const getAnthropicClient = () => {
|
|
42
49
|
if (state.anthropicClient) return state.anthropicClient;
|
|
43
50
|
const apiKey = runtimeConfig.get('ANTHROPIC_API_KEY');
|
|
44
51
|
if (!apiKey) return null;
|
|
45
52
|
try {
|
|
46
53
|
const { Anthropic } = require('@anthropic-ai/sdk');
|
|
47
|
-
state.anthropicClient = new Anthropic({ apiKey });
|
|
54
|
+
state.anthropicClient = new Anthropic({ apiKey, timeout: resolveRequestTimeoutMs(), maxRetries: REQUEST_MAX_RETRIES });
|
|
48
55
|
logger.info('[llmConfig] Anthropic client initialised');
|
|
49
56
|
} catch (error) {
|
|
50
57
|
logger.warn('[llmConfig] Failed to initialise Anthropic client', { error: error?.message });
|
|
@@ -57,6 +64,7 @@ const _resetState = () => {
|
|
|
57
64
|
state.openaiClient = null;
|
|
58
65
|
state.provider = null;
|
|
59
66
|
state.variant = null;
|
|
67
|
+
state.gatewayProvider = null;
|
|
60
68
|
};
|
|
61
69
|
|
|
62
70
|
module.exports = {
|
|
@@ -67,6 +75,7 @@ module.exports = {
|
|
|
67
75
|
setOpenAIProvider,
|
|
68
76
|
getOpenAIProvider,
|
|
69
77
|
requireOpenAIProvider,
|
|
78
|
+
requireGatewayProvider,
|
|
70
79
|
configureOpenAIProvider,
|
|
71
80
|
_resetState
|
|
72
81
|
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const runtimeConfig = require('../../config/runtimeConfig');
|
|
2
|
+
|
|
3
|
+
const DEFAULT_OFFER_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
4
|
+
const DEFAULT_HUMAN_QUIET_MS = 24 * 60 * 60 * 1000;
|
|
5
|
+
const DEFAULT_ACTIVITY_QUIET_MS = 2 * 60 * 60 * 1000;
|
|
6
|
+
const DEFAULT_PAUSE_QUIET_MS = 10 * 60 * 1000;
|
|
7
|
+
const DEFAULT_TAP_WINDOW_MS = 30 * 60 * 1000;
|
|
8
|
+
const DEFAULT_PLEDGE_MS = 8 * 60 * 60 * 1000;
|
|
9
|
+
const DEFAULT_SWEEP_INTERVAL_MS = 5 * 60 * 1000;
|
|
10
|
+
|
|
11
|
+
const CONTACT_WINDOW = { timeZone: 'America/Mexico_City', startHour: 8, endHour: 21 };
|
|
12
|
+
|
|
13
|
+
const SAFETY_NET_SOURCE = 'paused_safety_net';
|
|
14
|
+
|
|
15
|
+
const BOT_ORIGIN = 'assistant';
|
|
16
|
+
const HUMAN_ORIGINS = ['whatsapp_platform'];
|
|
17
|
+
const UNDELIVERED_STATUSES = ['failed', 'undelivered'];
|
|
18
|
+
const RECEIVED_STATUSES = ['delivered', 'read'];
|
|
19
|
+
|
|
20
|
+
const namedSender = () => ({ $nin: [null, SAFETY_NET_SOURCE] });
|
|
21
|
+
|
|
22
|
+
const deliverableReplyFilter = (code, since) => ({
|
|
23
|
+
numero: code,
|
|
24
|
+
from_me: true,
|
|
25
|
+
content_sid: null,
|
|
26
|
+
'statusInfo.status': { $nin: UNDELIVERED_STATUSES },
|
|
27
|
+
createdAt: { $gt: since }
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const humanReplyFilter = (code, since) => ({
|
|
31
|
+
...deliverableReplyFilter(code, since),
|
|
32
|
+
origin: { $in: HUMAN_ORIGINS },
|
|
33
|
+
triggeredBy: namedSender()
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const anyReplyFilter = (code, since) => ({
|
|
37
|
+
...deliverableReplyFilter(code, since),
|
|
38
|
+
$or: [
|
|
39
|
+
{ origin: BOT_ORIGIN },
|
|
40
|
+
{ origin: { $in: HUMAN_ORIGINS }, triggeredBy: namedSender() }
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const staffSendFilter = (code, since) => ({
|
|
45
|
+
numero: code,
|
|
46
|
+
from_me: true,
|
|
47
|
+
origin: { $in: HUMAN_ORIGINS },
|
|
48
|
+
triggeredBy: { $regex: '@' },
|
|
49
|
+
'statusInfo.status': { $nin: UNDELIVERED_STATUSES },
|
|
50
|
+
createdAt: { $gt: since }
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const settledHumanReplyFilter = (code, since, unconfirmedBefore) => ({
|
|
54
|
+
...humanReplyFilter(code, since),
|
|
55
|
+
$or: [
|
|
56
|
+
{ 'statusInfo.status': { $in: RECEIVED_STATUSES } },
|
|
57
|
+
{ createdAt: { $lte: unconfirmedBefore } }
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const CHOICE_LABEL_KEYS = {
|
|
62
|
+
callback: 'PAUSED_SAFETY_NET_CALLBACK_LABEL'
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let injected = {};
|
|
66
|
+
|
|
67
|
+
const configureSafetyNet = (config = {}) => {
|
|
68
|
+
injected = config && typeof config === 'object' ? config : {};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const _resetSafetyNetConfig = () => {
|
|
72
|
+
injected = {};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const text = (key, envKey) => {
|
|
76
|
+
const raw = injected[key] ?? runtimeConfig.get(envKey);
|
|
77
|
+
const value = String(raw ?? '').trim();
|
|
78
|
+
return value || null;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const duration = (key, envKey, fallback) => {
|
|
82
|
+
const raw = Number(injected[key] ?? runtimeConfig.get(envKey));
|
|
83
|
+
return Number.isFinite(raw) && raw > 0 ? raw : fallback;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
CONTACT_WINDOW,
|
|
88
|
+
SAFETY_NET_SOURCE,
|
|
89
|
+
DEFAULT_PLEDGE_MS,
|
|
90
|
+
anyReplyFilter,
|
|
91
|
+
humanReplyFilter,
|
|
92
|
+
settledHumanReplyFilter,
|
|
93
|
+
staffSendFilter,
|
|
94
|
+
CHOICE_LABEL_KEYS,
|
|
95
|
+
configureSafetyNet,
|
|
96
|
+
_resetSafetyNetConfig,
|
|
97
|
+
getSafetyNetContentSid: () => text('contentSid', 'PAUSED_SAFETY_NET_CONTENT_SID'),
|
|
98
|
+
getSafetyNetUnassignedContentSid: () => text('unassignedContentSid', 'PAUSED_SAFETY_NET_UNASSIGNED_CONTENT_SID'),
|
|
99
|
+
getSafetyNetPhone: () => text('phone', 'PAUSED_SAFETY_NET_PHONE'),
|
|
100
|
+
getSafetyNetLabel: (choice) => text(`${choice}Label`, CHOICE_LABEL_KEYS[choice]),
|
|
101
|
+
getOfferWindowMs: () => duration('offerWindowMs', 'PAUSED_SAFETY_NET_WINDOW_MS', DEFAULT_OFFER_WINDOW_MS),
|
|
102
|
+
getHumanQuietMs: () => duration('humanQuietMs', 'SAFETY_NET_HUMAN_QUIET_MS', DEFAULT_HUMAN_QUIET_MS),
|
|
103
|
+
getActivityQuietMs: () => duration('activityQuietMs', 'SAFETY_NET_ACTIVITY_QUIET_MS', DEFAULT_ACTIVITY_QUIET_MS),
|
|
104
|
+
getPauseQuietMs: () => duration('pauseQuietMs', 'SAFETY_NET_PAUSE_QUIET_MS', DEFAULT_PAUSE_QUIET_MS),
|
|
105
|
+
getTapWindowMs: () => duration('tapWindowMs', 'SAFETY_NET_TAP_WINDOW_MS', DEFAULT_TAP_WINDOW_MS),
|
|
106
|
+
getPledgeMs: () => duration('pledgeMs', 'SAFETY_NET_PLEDGE_MS', DEFAULT_PLEDGE_MS),
|
|
107
|
+
getSweepIntervalMs: () => duration('sweepIntervalMs', 'SAFETY_NET_SWEEP_INTERVAL_MS', DEFAULT_SWEEP_INTERVAL_MS)
|
|
108
|
+
};
|
|
@@ -2,13 +2,23 @@ const { Config_ID } = require('../../config/airtableConfig');
|
|
|
2
2
|
|
|
3
3
|
const { getRecordByFilter } = require('../../services/airtableService');
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const { logger } = require('../../utils/logger');
|
|
6
|
+
const { MapCache } = require('../../utils/MapCache');
|
|
6
7
|
const { safeParse, isPlainObject } = require('../../utils/jsonUtils');
|
|
7
8
|
|
|
8
9
|
const SUBAGENTS_CONFIG_TABLE = 'sub_agents';
|
|
9
10
|
const CACHE_TTL = 5 * 60 * 1000;
|
|
10
11
|
const CACHE_KEY = 'subAgentsConfig';
|
|
11
12
|
const EXTRACTOR_DEFAULTS = { presetId: '' };
|
|
13
|
+
const COMPOSER_DEFAULTS = { presetId: '' };
|
|
14
|
+
const PATTERN_CONSULT_DEFAULTS = { presetId: '' };
|
|
15
|
+
const RISK_ASSESSMENT_DEFAULTS = { presetId: '' };
|
|
16
|
+
const TRIAGE_GATE_DEFAULTS = { presetId: '' };
|
|
17
|
+
const TRIAGE_PLAN_DEFAULTS = { presetId: '' };
|
|
18
|
+
const ESCALATION_DRAFT_DEFAULTS = { presetId: '' };
|
|
19
|
+
const ESCALATION_QUESTIONS_DEFAULTS = { presetId: '' };
|
|
20
|
+
const ESCALATION_NOTE_FACTS_DEFAULTS = { presetId: '' };
|
|
21
|
+
const SUPPORT_LIGHT_DEFAULTS = { presetId: '' };
|
|
12
22
|
|
|
13
23
|
const cache = new MapCache({ maxSize: 1, ttl: CACHE_TTL });
|
|
14
24
|
|
|
@@ -24,7 +34,47 @@ async function load() {
|
|
|
24
34
|
if (byKey.EXTRACTOR && !isPlainObject(parsedExtractor)) throw new Error('subAgents config EXTRACTOR is not a JSON object');
|
|
25
35
|
const extractor = { ...EXTRACTOR_DEFAULTS, ...(parsedExtractor || {}) };
|
|
26
36
|
|
|
27
|
-
const
|
|
37
|
+
const parsedComposer = safeParse(byKey.COMPOSER, null);
|
|
38
|
+
if (byKey.COMPOSER && !isPlainObject(parsedComposer)) throw new Error('subAgents config COMPOSER is not a JSON object');
|
|
39
|
+
const composer = { ...COMPOSER_DEFAULTS, ...(parsedComposer || {}) };
|
|
40
|
+
|
|
41
|
+
const parsedPatternConsult = safeParse(byKey.PATTERN_CONSULT, null);
|
|
42
|
+
if (byKey.PATTERN_CONSULT && !isPlainObject(parsedPatternConsult)) throw new Error('subAgents config PATTERN_CONSULT is not a JSON object');
|
|
43
|
+
const patternConsult = { ...PATTERN_CONSULT_DEFAULTS, ...(parsedPatternConsult || {}) };
|
|
44
|
+
|
|
45
|
+
// The Airtable row may still live under the pre-rename key RISK_SYNTHESIS.
|
|
46
|
+
const riskAssessmentRaw = byKey.RISK_ASSESSMENT ?? byKey.RISK_SYNTHESIS;
|
|
47
|
+
const parsedRiskAssessment = safeParse(riskAssessmentRaw, null);
|
|
48
|
+
if (riskAssessmentRaw && !isPlainObject(parsedRiskAssessment)) throw new Error('subAgents config RISK_ASSESSMENT is not a JSON object');
|
|
49
|
+
const riskAssessment = { ...RISK_ASSESSMENT_DEFAULTS, ...(parsedRiskAssessment || {}) };
|
|
50
|
+
|
|
51
|
+
const parsedTriageGate = safeParse(byKey.TRIAGE_GATE, null);
|
|
52
|
+
if (byKey.TRIAGE_GATE && !isPlainObject(parsedTriageGate)) throw new Error('subAgents config TRIAGE_GATE is not a JSON object');
|
|
53
|
+
const triageGate = { ...TRIAGE_GATE_DEFAULTS, ...(parsedTriageGate || {}) };
|
|
54
|
+
|
|
55
|
+
const parsedTriagePlan = safeParse(byKey.TRIAGE_PLAN, null);
|
|
56
|
+
if (byKey.TRIAGE_PLAN && !isPlainObject(parsedTriagePlan)) throw new Error('subAgents config TRIAGE_PLAN is not a JSON object');
|
|
57
|
+
const triagePlan = { ...TRIAGE_PLAN_DEFAULTS, ...(parsedTriagePlan || {}) };
|
|
58
|
+
|
|
59
|
+
const parsedEscalationDraft = safeParse(byKey.ESCALATION_DRAFT, null);
|
|
60
|
+
if (byKey.ESCALATION_DRAFT && !isPlainObject(parsedEscalationDraft)) throw new Error('subAgents config ESCALATION_DRAFT is not a JSON object');
|
|
61
|
+
const escalationDraft = { ...ESCALATION_DRAFT_DEFAULTS, ...(parsedEscalationDraft || {}) };
|
|
62
|
+
|
|
63
|
+
const parsedEscalationQuestions = safeParse(byKey.ESCALATION_QUESTIONS, null);
|
|
64
|
+
if (byKey.ESCALATION_QUESTIONS && !isPlainObject(parsedEscalationQuestions)) throw new Error('subAgents config ESCALATION_QUESTIONS is not a JSON object');
|
|
65
|
+
const escalationQuestions = { ...ESCALATION_QUESTIONS_DEFAULTS, ...(parsedEscalationQuestions || {}) };
|
|
66
|
+
|
|
67
|
+
const parsedNoteFacts = safeParse(byKey.ESCALATION_NOTE_FACTS, null);
|
|
68
|
+
if (byKey.ESCALATION_NOTE_FACTS && !isPlainObject(parsedNoteFacts)) throw new Error('subAgents config ESCALATION_NOTE_FACTS is not a JSON object');
|
|
69
|
+
const escalationNoteFacts = { ...ESCALATION_NOTE_FACTS_DEFAULTS, ...(parsedNoteFacts || {}) };
|
|
70
|
+
|
|
71
|
+
// SUPPORT_LIGHT drives an optional sweep, so a malformed row leaves it unconfigured instead of failing every sub-agent.
|
|
72
|
+
const parsedSupportLight = safeParse(byKey.SUPPORT_LIGHT, null);
|
|
73
|
+
const isSupportLightValid = !byKey.SUPPORT_LIGHT || isPlainObject(parsedSupportLight);
|
|
74
|
+
if (!isSupportLightValid) logger.error('[subAgentsConfig] SUPPORT_LIGHT is not a JSON object; the support-light sweep stays unconfigured');
|
|
75
|
+
const supportLight = { ...SUPPORT_LIGHT_DEFAULTS, ...(isSupportLightValid ? parsedSupportLight || {} : {}) };
|
|
76
|
+
|
|
77
|
+
const config = { EXTRACTOR: extractor, COMPOSER: composer, PATTERN_CONSULT: patternConsult, RISK_ASSESSMENT: riskAssessment, TRIAGE_GATE: triageGate, TRIAGE_PLAN: triagePlan, ESCALATION_DRAFT: escalationDraft, ESCALATION_QUESTIONS: escalationQuestions, ESCALATION_NOTE_FACTS: escalationNoteFacts, SUPPORT_LIGHT: supportLight };
|
|
28
78
|
cache.set(CACHE_KEY, config);
|
|
29
79
|
return config;
|
|
30
80
|
}
|
|
@@ -35,4 +85,13 @@ async function get(key) {
|
|
|
35
85
|
|
|
36
86
|
module.exports = {
|
|
37
87
|
getExtractor: () => get('EXTRACTOR'),
|
|
88
|
+
getComposer: () => get('COMPOSER'),
|
|
89
|
+
getPatternConsult: () => get('PATTERN_CONSULT'),
|
|
90
|
+
getRiskAssessment: () => get('RISK_ASSESSMENT'),
|
|
91
|
+
getTriageGate: () => get('TRIAGE_GATE'),
|
|
92
|
+
getTriagePlan: () => get('TRIAGE_PLAN'),
|
|
93
|
+
getEscalationDraft: () => get('ESCALATION_DRAFT'),
|
|
94
|
+
getEscalationQuestions: () => get('ESCALATION_QUESTIONS'),
|
|
95
|
+
getEscalationNoteFacts: () => get('ESCALATION_NOTE_FACTS'),
|
|
96
|
+
getSupportLightEvaluator: () => get('SUPPORT_LIGHT'),
|
|
38
97
|
};
|
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
const { getTurnTraceModel } = require('../models/turnTraceModel');
|
|
2
|
+
const { isToolFailure, toolFailureError } = require('../helpers/toolResultHelper');
|
|
3
|
+
const { GUARD_REFUSAL_CODES } = require('../helpers/clinicalWorkflowGuard');
|
|
4
|
+
const { redactDirectIdentifiers } = require('../../utils/sanitizerUtils');
|
|
5
|
+
const { logger } = require('../../utils/logger');
|
|
6
|
+
const { settleClaimedDelivery } = require('../services/deliverySettlementService');
|
|
7
|
+
const { normalizeTurnKind, TURN_KIND } = require('./turnContext');
|
|
8
|
+
|
|
9
|
+
const UNLISTED_REFUSAL = 'unlisted_refusal';
|
|
10
|
+
function refusalCode(output) {
|
|
11
|
+
const raw = toolFailureError(output, UNLISTED_REFUSAL);
|
|
12
|
+
return GUARD_REFUSAL_CODES.has(raw) ? raw : UNLISTED_REFUSAL;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function describeThrown(error) {
|
|
16
|
+
try {
|
|
17
|
+
if (error instanceof Error) return String(error.message);
|
|
18
|
+
if (typeof error !== 'object' || error === null) return String(error);
|
|
19
|
+
return String(JSON.stringify(error));
|
|
20
|
+
} catch (unprintable) {
|
|
21
|
+
return '[unprintable thrown value]';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
2
24
|
|
|
3
25
|
class ToolRuntimeContext {
|
|
4
26
|
constructor({
|
|
@@ -7,6 +29,10 @@ class ToolRuntimeContext {
|
|
|
7
29
|
sessionId = null,
|
|
8
30
|
repos = {},
|
|
9
31
|
contextSource = null,
|
|
32
|
+
shadow = false,
|
|
33
|
+
shouldContinue = null,
|
|
34
|
+
turnKind = TURN_KIND.UNKNOWN,
|
|
35
|
+
patientInput = null,
|
|
10
36
|
} = {}) {
|
|
11
37
|
if (typeof patientCode !== 'string' || !patientCode) {
|
|
12
38
|
throw new Error('ToolRuntimeContext requires a non-empty patientCode');
|
|
@@ -21,13 +47,44 @@ class ToolRuntimeContext {
|
|
|
21
47
|
this.patientCode = patientCode;
|
|
22
48
|
this.turnId = turnId;
|
|
23
49
|
this.sessionId = sessionId;
|
|
50
|
+
this.shouldContinue = shouldContinue;
|
|
51
|
+
this.abort = null;
|
|
24
52
|
this.repos = repos;
|
|
25
53
|
this.contextSource = contextSource;
|
|
54
|
+
this.enabledSkills = [];
|
|
55
|
+
this.activatedSkills = new Set();
|
|
56
|
+
this.skillActivationIteration = new Map();
|
|
57
|
+
this.currentIteration = null;
|
|
26
58
|
this.toolHistory = [];
|
|
59
|
+
this.toolRejections = [];
|
|
27
60
|
this.safetyArtifact = null;
|
|
28
61
|
this.palliativeAssessment = null;
|
|
29
62
|
this.careplan = null;
|
|
30
|
-
this.
|
|
63
|
+
this.consumerMetadata = null;
|
|
64
|
+
this.deliveryDirective = null;
|
|
65
|
+
this.trace = new (getTurnTraceModel())({ turnId, patientCode, sessionId, shadow });
|
|
66
|
+
this.setTurnContext({ turnKind, patientInput });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setTurnContext({ turnKind = TURN_KIND.UNKNOWN, patientInput = null } = {}) {
|
|
70
|
+
this.turnKind = normalizeTurnKind(turnKind);
|
|
71
|
+
this.patientInput = this.turnKind === TURN_KIND.PATIENT && patientInput
|
|
72
|
+
? {
|
|
73
|
+
kind: typeof patientInput.kind === 'string' ? patientInput.kind : 'text',
|
|
74
|
+
text: typeof patientInput.text === 'string' ? patientInput.text : null,
|
|
75
|
+
...(typeof patientInput.sourceId === 'string' && patientInput.sourceId && {
|
|
76
|
+
sourceId: patientInput.sourceId,
|
|
77
|
+
}),
|
|
78
|
+
...(typeof patientInput.observedAt === 'string' && patientInput.observedAt && {
|
|
79
|
+
observedAt: patientInput.observedAt,
|
|
80
|
+
}),
|
|
81
|
+
}
|
|
82
|
+
: null;
|
|
83
|
+
this.trace?.setSignals?.({
|
|
84
|
+
turnKind: this.turnKind,
|
|
85
|
+
patientInputKind: this.patientInput?.kind || 'none',
|
|
86
|
+
});
|
|
87
|
+
return this;
|
|
31
88
|
}
|
|
32
89
|
|
|
33
90
|
recordTool({ iteration, toolData } = {}) {
|
|
@@ -36,15 +93,43 @@ class ToolRuntimeContext {
|
|
|
36
93
|
}
|
|
37
94
|
this.trace.addStep({ iteration, ...toolData });
|
|
38
95
|
if (toolData.success) this.toolHistory.push(toolData);
|
|
96
|
+
if (!toolData.success || isToolFailure(toolData.tool_output)) {
|
|
97
|
+
const code = refusalCode(toolData.tool_output);
|
|
98
|
+
this.toolRejections.push({ tool: toolData.tool_name, code, iteration: iteration ?? null });
|
|
99
|
+
logger.warn('[toolRuntime] tool call rejected', {
|
|
100
|
+
tool: toolData.tool_name,
|
|
101
|
+
reason: code,
|
|
102
|
+
iteration: iteration ?? null,
|
|
103
|
+
turnId: this.turnId || null,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
39
106
|
return toolData;
|
|
40
107
|
}
|
|
41
108
|
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
|
|
109
|
+
isLive() {
|
|
110
|
+
return typeof this.shouldContinue !== 'function' || this.shouldContinue();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async store({ outbound = null, completed = false, predictionTimeMs = null, error = null } = {}) {
|
|
114
|
+
this.trace.setSignals({ activatedSkills: [...this.activatedSkills].sort(), toolRejections: [...this.toolRejections] });
|
|
115
|
+
this.trace.setOutbound(outbound || this.trace.outbound || null);
|
|
116
|
+
const hasError = error !== null && error !== undefined;
|
|
117
|
+
const isSuperseded = hasError ? false : !this.isLive();
|
|
118
|
+
const status = hasError ? 'failed' : (isSuperseded ? 'superseded' : (completed ? 'completed' : 'incomplete'));
|
|
119
|
+
const abort = hasError
|
|
120
|
+
? {
|
|
121
|
+
reason: 'run_failed',
|
|
122
|
+
message: redactDirectIdentifiers(describeThrown(error)).slice(0, 300),
|
|
123
|
+
}
|
|
124
|
+
: this.abort;
|
|
125
|
+
this.trace.setStatus(status, abort);
|
|
45
126
|
this.trace.setTimings({ predictionTimeMs });
|
|
46
|
-
|
|
47
|
-
|
|
127
|
+
await this.trace.save();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async storeSkipped(reason) {
|
|
131
|
+
this.trace.setStatus('skipped', { reason });
|
|
132
|
+
await this.trace.save();
|
|
48
133
|
}
|
|
49
134
|
|
|
50
135
|
setSafetyArtifact(artifact) {
|
|
@@ -59,6 +144,36 @@ class ToolRuntimeContext {
|
|
|
59
144
|
this.careplan = this._requireArtifact('careplan', artifact);
|
|
60
145
|
}
|
|
61
146
|
|
|
147
|
+
setConsumerMetadata(metadata) {
|
|
148
|
+
this.consumerMetadata = metadata;
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setDeliveryDirective(directive) {
|
|
153
|
+
const operationId = directive?.operationId;
|
|
154
|
+
const body = directive?.body;
|
|
155
|
+
if (typeof operationId !== 'string' || !/^[a-zA-Z0-9_-]{1,200}$/.test(operationId)
|
|
156
|
+
|| typeof body !== 'string' || !body.trim() || body.length > 4000) {
|
|
157
|
+
throw new Error('ToolRuntimeContext.deliveryDirective must have a valid operationId and non-empty body');
|
|
158
|
+
}
|
|
159
|
+
this.deliveryDirective = {
|
|
160
|
+
operationId, body, claimed: false, settled: false,
|
|
161
|
+
};
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async settleDelivery(outcome, providerMessageId = null) {
|
|
166
|
+
return settleClaimedDelivery({
|
|
167
|
+
directive: this.deliveryDirective,
|
|
168
|
+
settleDelivery: this.repos?.nutritionSafety?.settleDelivery,
|
|
169
|
+
outcome,
|
|
170
|
+
providerMessageId,
|
|
171
|
+
patientCode: this.patientCode,
|
|
172
|
+
turnId: this.turnId,
|
|
173
|
+
traceId: this.trace?._id ? String(this.trace._id) : null,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
62
177
|
_requireArtifact(slot, artifact) {
|
|
63
178
|
if (artifact === null || typeof artifact !== 'object' || Array.isArray(artifact)) {
|
|
64
179
|
throw new Error(`ToolRuntimeContext.${slot} must be a plain object`);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const TURN_KIND = Object.freeze({
|
|
2
|
+
PATIENT: 'patient',
|
|
3
|
+
OPERATOR_INSTRUCTION: 'operator_instruction',
|
|
4
|
+
SYSTEM: 'system',
|
|
5
|
+
PROACTIVE_OUTREACH: 'proactive_outreach',
|
|
6
|
+
UNKNOWN: 'unknown',
|
|
7
|
+
});
|
|
8
|
+
const TURN_KINDS = new Set(Object.values(TURN_KIND));
|
|
9
|
+
|
|
10
|
+
function normalizeTurnKind(turnKind) {
|
|
11
|
+
return TURN_KINDS.has(turnKind) ? turnKind : TURN_KIND.UNKNOWN;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function patientInputFrom(message) {
|
|
15
|
+
if (!message) return null;
|
|
16
|
+
let kind = 'text';
|
|
17
|
+
if (message.type === 'flow' || message.flow || message.interactive?.type === 'flow'
|
|
18
|
+
|| message.interactive_type === 'flow' || message.interactive_data?.type === 'flow') kind = 'flow';
|
|
19
|
+
else if (message.type === 'media' || message.media) kind = 'media';
|
|
20
|
+
const sourceId = message.message_id ?? message.messageId ?? message.id ?? null;
|
|
21
|
+
const observedAt = normalizeObservedAt(message.createdAt ?? message.timestamp ?? null);
|
|
22
|
+
return {
|
|
23
|
+
kind,
|
|
24
|
+
text: typeof message.body === 'string' ? message.body : null,
|
|
25
|
+
...(typeof sourceId === 'string' && sourceId && { sourceId }),
|
|
26
|
+
...(observedAt && { observedAt }),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function normalizeObservedAt(value) {
|
|
31
|
+
if (value === null || value === undefined || value === '') return null;
|
|
32
|
+
const parsed = value instanceof Date ? value : new Date(value);
|
|
33
|
+
return Number.isNaN(parsed.getTime()) ? null : parsed.toISOString();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function resolveTurnContext({ turnKind = null, message = null } = {}) {
|
|
37
|
+
const inferredKind = turnKind || (message ? TURN_KIND.PATIENT : TURN_KIND.UNKNOWN);
|
|
38
|
+
const kind = normalizeTurnKind(inferredKind);
|
|
39
|
+
return {
|
|
40
|
+
turnKind: kind,
|
|
41
|
+
patientInput: kind === TURN_KIND.PATIENT ? patientInputFrom(message) : null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
TURN_KIND,
|
|
47
|
+
TURN_KINDS,
|
|
48
|
+
normalizeTurnKind,
|
|
49
|
+
resolveTurnContext,
|
|
50
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const runtimeConfig = require('../../config/runtimeConfig');
|
|
2
|
+
|
|
3
|
+
const PIPELINE_PHRASES = [
|
|
4
|
+
'antes de responder', 'en paralelo', 'corro', 'corriendo', 'ejecuto', 'invoco',
|
|
5
|
+
'routear', 'rutear', 'intake', 'routine', 'pipeline', 'extraigo', 'extraerla',
|
|
6
|
+
'extraerlo', 'voy a extraer', 'debo extraer', 'debo correr', 'me detengo a',
|
|
7
|
+
'los proceso', 'lo proceso', 'voy a procesar',
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
const ENGLISH_PHRASES = [
|
|
11
|
+
'the', 'this', 'that', 'with', 'and', 'for', 'from', 'your', 'you', 'will',
|
|
12
|
+
'have', 'been', 'let me', 'starting', 'week', 'follow up', 'ongoing', 'skip',
|
|
13
|
+
'schedule', 'scheduled', 'therapy', 'treatment', 'monitoring', 'symptoms',
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
function isBridgeEnabled() {
|
|
17
|
+
return runtimeConfig.get('BRIDGE_ENABLED', 'false') === 'true';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getBlockedPhrases() {
|
|
21
|
+
const extra = runtimeConfig.get('BRIDGE_BLOCKED_PHRASES', '')
|
|
22
|
+
.split(',')
|
|
23
|
+
.map(phrase => phrase.trim().toLowerCase())
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
return [...PIPELINE_PHRASES, ...ENGLISH_PHRASES, ...extra];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
isBridgeEnabled,
|
|
30
|
+
getBlockedPhrases,
|
|
31
|
+
};
|