@erosolaraijs/cure 2.2.0 → 2.3.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 +314 -26
- package/dist/bin/cure.js +173 -23
- package/dist/bin/cure.js.map +1 -1
- package/dist/capabilities/cureValidationFramework.d.ts +195 -0
- package/dist/capabilities/cureValidationFramework.d.ts.map +1 -0
- package/dist/capabilities/cureValidationFramework.js +577 -0
- package/dist/capabilities/cureValidationFramework.js.map +1 -0
- package/dist/capabilities/emergingTherapeutics.d.ts +145 -0
- package/dist/capabilities/emergingTherapeutics.d.ts.map +1 -0
- package/dist/capabilities/emergingTherapeutics.js +600 -0
- package/dist/capabilities/emergingTherapeutics.js.map +1 -0
- package/dist/capabilities/globalCancerCoverage.d.ts +143 -0
- package/dist/capabilities/globalCancerCoverage.d.ts.map +1 -0
- package/dist/capabilities/globalCancerCoverage.js +1066 -0
- package/dist/capabilities/globalCancerCoverage.js.map +1 -0
- package/dist/capabilities/index.d.ts +21 -0
- package/dist/capabilities/index.d.ts.map +1 -1
- package/dist/capabilities/index.js +24 -0
- package/dist/capabilities/index.js.map +1 -1
- package/dist/capabilities/resistanceManagement.d.ts +89 -0
- package/dist/capabilities/resistanceManagement.d.ts.map +1 -0
- package/dist/capabilities/resistanceManagement.js +713 -0
- package/dist/capabilities/resistanceManagement.js.map +1 -0
- package/dist/capabilities/universalCancerCureEngine.d.ts +254 -0
- package/dist/capabilities/universalCancerCureEngine.d.ts.map +1 -0
- package/dist/capabilities/universalCancerCureEngine.js +734 -0
- package/dist/capabilities/universalCancerCureEngine.js.map +1 -0
- package/package.json +1 -1
- package/src/bin/cure.ts +186 -23
- package/src/capabilities/cureValidationFramework.ts +757 -0
- package/src/capabilities/emergingTherapeutics.ts +760 -0
- package/src/capabilities/globalCancerCoverage.ts +1256 -0
- package/src/capabilities/index.ts +53 -0
- package/src/capabilities/resistanceManagement.ts +835 -0
- package/src/capabilities/universalCancerCureEngine.ts +1040 -0
package/README.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
# Cure
|
|
2
2
|
|
|
3
|
-
AI-powered
|
|
3
|
+
AI-powered precision oncology platform for cancer treatment, clinical decision support, and research.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
██████╗██╗ ██╗██████╗ ███████╗
|
|
7
|
+
██╔════╝██║ ██║██╔══██╗██╔════╝
|
|
8
|
+
██║ ██║ ██║██████╔╝█████╗
|
|
9
|
+
██║ ██║ ██║██╔══██╗██╔══╝
|
|
10
|
+
╚██████╗╚██████╔╝██║ ██║███████╗
|
|
11
|
+
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
|
|
12
|
+
```
|
|
4
13
|
|
|
5
14
|
## Installation
|
|
6
15
|
|
|
@@ -8,61 +17,335 @@ AI-powered cancer treatment framework for precision oncology research and clinic
|
|
|
8
17
|
npm install -g @erosolaraijs/cure
|
|
9
18
|
```
|
|
10
19
|
|
|
11
|
-
##
|
|
20
|
+
## Quick Start
|
|
12
21
|
|
|
13
22
|
```bash
|
|
23
|
+
# Launch interactive AI oncologist
|
|
14
24
|
cure
|
|
25
|
+
|
|
26
|
+
# Set your AI provider (xAI or OpenAI)
|
|
27
|
+
/model openai
|
|
28
|
+
/key YOUR_API_KEY
|
|
29
|
+
|
|
30
|
+
# Generate a cure protocol
|
|
31
|
+
/cure NSCLC IV KRAS_G12C
|
|
15
32
|
```
|
|
16
33
|
|
|
17
34
|
## Features
|
|
18
35
|
|
|
19
|
-
###
|
|
36
|
+
### Interactive AI Oncologist
|
|
37
|
+
|
|
38
|
+
Chat with an AI-powered oncology assistant for:
|
|
39
|
+
- Treatment recommendations based on cancer type, stage, and biomarkers
|
|
40
|
+
- Drug mechanism explanations
|
|
41
|
+
- Clinical trial guidance
|
|
42
|
+
- Biomarker interpretation
|
|
43
|
+
|
|
44
|
+
**Multi-Provider Support:**
|
|
45
|
+
- **xAI Grok** (`grok-4-1-fast-reasoning`) - Default
|
|
46
|
+
- **OpenAI GPT-5.1** (`gpt-5.1`) - Alternative
|
|
47
|
+
|
|
48
|
+
Switch providers at runtime with `/model xai` or `/model openai`.
|
|
49
|
+
|
|
50
|
+
### Comprehensive Cancer Coverage
|
|
51
|
+
|
|
52
|
+
| Category | Coverage |
|
|
53
|
+
|----------|----------|
|
|
54
|
+
| Cancer Types | 200+ types and histological subtypes |
|
|
55
|
+
| Biomarkers | 500+ actionable targets |
|
|
56
|
+
| Protocols | 100+ (NCCN, ESMO, ASCO, FDA) |
|
|
57
|
+
| Patient Populations | Pediatric, AYA, adult, elderly, frail |
|
|
58
|
+
| Special Circumstances | Pregnancy, transplant, autoimmune, HIV |
|
|
59
|
+
| Stages | Localized, locally advanced, metastatic, recurrent |
|
|
60
|
+
|
|
61
|
+
### Core Capabilities
|
|
62
|
+
|
|
63
|
+
#### Patient Analysis (`/analyze`)
|
|
20
64
|
- Genomic profiling and biomarker assessment
|
|
21
65
|
- Risk stratification and survival prediction
|
|
22
66
|
- Treatment response modeling
|
|
67
|
+
- MSI/TMB/HRD status analysis
|
|
23
68
|
|
|
24
|
-
|
|
69
|
+
#### Treatment Planning (`/plan`)
|
|
25
70
|
- NCCN, ESMO, ASCO protocol integration
|
|
26
71
|
- Personalized treatment recommendations
|
|
72
|
+
- Multi-modality planning (surgery, radiation, systemic)
|
|
27
73
|
- Timeline and monitoring schedules
|
|
28
74
|
|
|
29
|
-
|
|
75
|
+
#### Cure Protocol Generation (`/cure`)
|
|
76
|
+
- Comprehensive cure strategies by cancer type and stage
|
|
77
|
+
- Drug target prioritization with evidence levels
|
|
78
|
+
- Immunotherapy protocol matching
|
|
79
|
+
- Projected outcomes (response rate, 5-year survival, cure confidence)
|
|
80
|
+
|
|
81
|
+
#### Drug Target Discovery (`/discover`)
|
|
30
82
|
- AI-driven target identification
|
|
31
|
-
- Evidence-based prioritization
|
|
32
|
-
-
|
|
83
|
+
- Evidence-based prioritization (FDA-approved, clinical trials, preclinical)
|
|
84
|
+
- Pathway analysis
|
|
85
|
+
- Approved drug matching
|
|
86
|
+
|
|
87
|
+
#### Clinical Trial Matching (`/trials`)
|
|
88
|
+
- ClinicalTrials.gov integration
|
|
89
|
+
- Biomarker-based eligibility matching
|
|
90
|
+
- Location-aware search
|
|
91
|
+
- Phase and status filtering
|
|
92
|
+
|
|
93
|
+
#### Drug Safety (`/safety`)
|
|
94
|
+
- Drug-drug interaction checking
|
|
95
|
+
- Black box warning alerts
|
|
96
|
+
- QT prolongation risk assessment
|
|
97
|
+
- Pharmacogenomic considerations (DPYD, UGT1A1, TPMT/NUDT15)
|
|
98
|
+
|
|
99
|
+
#### ML Outcome Prediction (`/predict`)
|
|
100
|
+
- Response prediction (CR, PR, SD, PD)
|
|
101
|
+
- Survival estimates (PFS, OS with confidence intervals)
|
|
102
|
+
- Toxicity risk assessment
|
|
103
|
+
- Resistance prediction
|
|
104
|
+
|
|
105
|
+
### EHR Integration
|
|
106
|
+
|
|
107
|
+
Connect to hospital systems via HL7 FHIR R4:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
/ehr connect epic
|
|
111
|
+
/ehr connect cerner
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Supported Systems:**
|
|
115
|
+
- Epic
|
|
116
|
+
- Cerner
|
|
117
|
+
|
|
118
|
+
**Data Exchange:**
|
|
119
|
+
- Patient demographics
|
|
120
|
+
- Cancer diagnoses (ICD-10)
|
|
121
|
+
- Biomarker results
|
|
122
|
+
- Treatment history
|
|
123
|
+
- Medication records
|
|
124
|
+
|
|
125
|
+
### Genomic Platform Integration
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
/genomics platforms
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Supported Platforms:**
|
|
132
|
+
- **Foundation Medicine** (FoundationOne CDx)
|
|
133
|
+
- **Guardant Health** (Guardant360, GuardantOMNI)
|
|
134
|
+
- **Tempus** (xT, xF, xR)
|
|
135
|
+
|
|
136
|
+
**Analysis Types:**
|
|
137
|
+
- Somatic variant detection
|
|
138
|
+
- Copy number alterations
|
|
139
|
+
- Gene fusions
|
|
140
|
+
- MSI/TMB analysis
|
|
141
|
+
- Therapy matching
|
|
33
142
|
|
|
34
|
-
###
|
|
35
|
-
- Patient eligibility matching
|
|
36
|
-
- Protocol design support
|
|
37
|
-
- Outcome tracking
|
|
143
|
+
### HIPAA Compliance
|
|
38
144
|
|
|
39
|
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
145
|
+
- End-to-end encryption
|
|
146
|
+
- PHI masking and de-identification
|
|
147
|
+
- Audit logging with 7-year retention
|
|
148
|
+
- Role-based access control
|
|
149
|
+
- Consent management
|
|
43
150
|
|
|
44
|
-
|
|
45
|
-
- HIPAA-compliant data handling
|
|
46
|
-
- Audit logging and access controls
|
|
47
|
-
- PHI masking and encryption
|
|
151
|
+
## CLI Commands
|
|
48
152
|
|
|
49
|
-
|
|
153
|
+
### AI Chat Commands
|
|
154
|
+
| Command | Description |
|
|
155
|
+
|---------|-------------|
|
|
156
|
+
| `/key [provider] [key]` | Set API key (xai or openai) |
|
|
157
|
+
| `/model [xai\|openai]` | Show/switch AI provider |
|
|
158
|
+
| `/clear` | Clear conversation history |
|
|
159
|
+
|
|
160
|
+
### Clinical Commands
|
|
161
|
+
| Command | Description |
|
|
162
|
+
|---------|-------------|
|
|
163
|
+
| `/analyze [patient]` | Analyze patient data |
|
|
164
|
+
| `/plan [patient]` | Design treatment plan |
|
|
165
|
+
| `/cure [cancer] [stage] [mutations...]` | Generate cure protocol |
|
|
166
|
+
| `/discover [gene] [cancer]` | Drug target discovery |
|
|
167
|
+
| `/trials [cancer] [biomarkers...]` | Find clinical trials |
|
|
168
|
+
| `/safety [drug1] [drug2...]` | Check drug interactions |
|
|
169
|
+
| `/predict [patient]` | ML outcome predictions |
|
|
170
|
+
|
|
171
|
+
### System Commands
|
|
172
|
+
| Command | Description |
|
|
173
|
+
|---------|-------------|
|
|
174
|
+
| `/status` | System health check |
|
|
175
|
+
| `/ehr [connect\|status]` | EHR integration |
|
|
176
|
+
| `/genomics [platforms]` | Genomic platforms status |
|
|
177
|
+
| `/demo` | Run framework demonstration |
|
|
178
|
+
| `/version` | Show version |
|
|
179
|
+
| `/update` | Check for updates |
|
|
180
|
+
|
|
181
|
+
## Programmatic API
|
|
50
182
|
|
|
51
183
|
```typescript
|
|
52
|
-
import {
|
|
184
|
+
import {
|
|
185
|
+
CancerTreatmentCapabilityModule,
|
|
186
|
+
createOncologyPlatform,
|
|
187
|
+
FHIRClient,
|
|
188
|
+
ClinicalTrialsGovClient,
|
|
189
|
+
OutcomePredictorService,
|
|
190
|
+
DrugSafetyService,
|
|
191
|
+
HIPAAComplianceService
|
|
192
|
+
} from '@erosolaraijs/cure';
|
|
193
|
+
|
|
194
|
+
// Quick start with full platform
|
|
195
|
+
const platform = await createOncologyPlatform({
|
|
196
|
+
ehr: {
|
|
197
|
+
enabled: true,
|
|
198
|
+
vendor: 'epic',
|
|
199
|
+
baseUrl: 'https://epic.hospital.org/fhir',
|
|
200
|
+
clientId: 'your-client-id'
|
|
201
|
+
},
|
|
202
|
+
genomics: {
|
|
203
|
+
enabled: true,
|
|
204
|
+
platforms: ['foundation', 'guardant', 'tempus']
|
|
205
|
+
},
|
|
206
|
+
clinicalTrials: {
|
|
207
|
+
enabled: true,
|
|
208
|
+
maxDistance: 100
|
|
209
|
+
},
|
|
210
|
+
ml: {
|
|
211
|
+
enabled: true,
|
|
212
|
+
modelVersion: '1.0.0'
|
|
213
|
+
},
|
|
214
|
+
safety: {
|
|
215
|
+
enabled: true,
|
|
216
|
+
strictMode: true
|
|
217
|
+
},
|
|
218
|
+
compliance: {
|
|
219
|
+
enabled: true,
|
|
220
|
+
auditRetentionDays: 2555
|
|
221
|
+
}
|
|
222
|
+
});
|
|
53
223
|
|
|
54
|
-
|
|
224
|
+
// Generate comprehensive treatment plan
|
|
225
|
+
const plan = await platform.generateComprehensivePlan(patient, 'DR001');
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Core Module Usage
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
// Cancer treatment capability
|
|
232
|
+
const capability = new CancerTreatmentCapabilityModule();
|
|
55
233
|
|
|
56
234
|
// Analyze patient
|
|
57
|
-
const analysis = await capability.analyzePatient(
|
|
235
|
+
const analysis = await capability.analyzePatient('P001', true);
|
|
58
236
|
|
|
59
|
-
// Generate
|
|
60
|
-
const
|
|
237
|
+
// Generate cure protocol
|
|
238
|
+
const cure = await capability.cureCancer('P001', 'Lung', 'IV', {
|
|
239
|
+
mutations: ['EGFR', 'TP53'],
|
|
240
|
+
biomarkers: ['PD-L1'],
|
|
241
|
+
msiStatus: 'MSS',
|
|
242
|
+
tmbLevel: 'High'
|
|
243
|
+
});
|
|
61
244
|
|
|
62
245
|
// Discover drug targets
|
|
63
|
-
const targets = await capability.discoverDrugTargets(
|
|
246
|
+
const targets = await capability.discoverDrugTargets('Melanoma', 'BRAF');
|
|
64
247
|
```
|
|
65
248
|
|
|
249
|
+
### Individual Services
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
// EHR Integration
|
|
253
|
+
const fhir = new FHIRClient(config);
|
|
254
|
+
const patient = await fhir.getPatient('12345');
|
|
255
|
+
const conditions = await fhir.getConditions('12345');
|
|
256
|
+
|
|
257
|
+
// Clinical Trials
|
|
258
|
+
const trials = new ClinicalTrialsGovClient();
|
|
259
|
+
const matches = await trials.searchTrials({
|
|
260
|
+
condition: 'Non-Small Cell Lung Cancer',
|
|
261
|
+
intervention: 'pembrolizumab',
|
|
262
|
+
status: 'RECRUITING'
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// ML Predictions
|
|
266
|
+
const predictor = new OutcomePredictorService();
|
|
267
|
+
const response = await predictor.predictResponse(patientFeatures, treatmentFeatures);
|
|
268
|
+
|
|
269
|
+
// Drug Safety
|
|
270
|
+
const safety = new DrugSafetyService();
|
|
271
|
+
const interactions = await safety.checkInteractions(['pembrolizumab', 'ipilimumab']);
|
|
272
|
+
|
|
273
|
+
// HIPAA Compliance
|
|
274
|
+
const hipaa = new HIPAAComplianceService();
|
|
275
|
+
await hipaa.logAccess(userId, patientId, 'VIEW', 'Clinical review');
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Environment Variables
|
|
279
|
+
|
|
280
|
+
| Variable | Description |
|
|
281
|
+
|----------|-------------|
|
|
282
|
+
| `AI_PROVIDER` | AI provider: `xai` or `openai` (default: xai) |
|
|
283
|
+
| `XAI_API_KEY` | xAI API key |
|
|
284
|
+
| `OPENAI_API_KEY` | OpenAI API key |
|
|
285
|
+
| `FHIR_BASE_URL` | FHIR server URL |
|
|
286
|
+
| `FHIR_CLIENT_ID` | FHIR OAuth client ID |
|
|
287
|
+
| `FHIR_CLIENT_SECRET` | FHIR OAuth client secret |
|
|
288
|
+
|
|
289
|
+
## Supported Cancer Types
|
|
290
|
+
|
|
291
|
+
<details>
|
|
292
|
+
<summary>Click to expand full list</summary>
|
|
293
|
+
|
|
294
|
+
**Solid Tumors:**
|
|
295
|
+
- Lung (NSCLC, SCLC, mesothelioma)
|
|
296
|
+
- Breast (HR+, HER2+, TNBC)
|
|
297
|
+
- Colorectal
|
|
298
|
+
- Prostate
|
|
299
|
+
- Melanoma
|
|
300
|
+
- Pancreatic
|
|
301
|
+
- Hepatocellular
|
|
302
|
+
- Gastric/Esophageal
|
|
303
|
+
- Ovarian
|
|
304
|
+
- Endometrial
|
|
305
|
+
- Cervical
|
|
306
|
+
- Bladder/Urothelial
|
|
307
|
+
- Renal Cell
|
|
308
|
+
- Head and Neck
|
|
309
|
+
- Thyroid
|
|
310
|
+
- Sarcomas
|
|
311
|
+
- Brain (GBM, meningioma)
|
|
312
|
+
- And 150+ more subtypes
|
|
313
|
+
|
|
314
|
+
**Hematologic Malignancies:**
|
|
315
|
+
- Acute Myeloid Leukemia (AML)
|
|
316
|
+
- Acute Lymphoblastic Leukemia (ALL)
|
|
317
|
+
- Chronic Myeloid Leukemia (CML)
|
|
318
|
+
- Chronic Lymphocytic Leukemia (CLL)
|
|
319
|
+
- Diffuse Large B-Cell Lymphoma
|
|
320
|
+
- Follicular Lymphoma
|
|
321
|
+
- Hodgkin Lymphoma
|
|
322
|
+
- Multiple Myeloma
|
|
323
|
+
- Myelodysplastic Syndromes
|
|
324
|
+
- Myeloproliferative Neoplasms
|
|
325
|
+
|
|
326
|
+
**Rare Cancers:**
|
|
327
|
+
- Cholangiocarcinoma
|
|
328
|
+
- Neuroendocrine Tumors
|
|
329
|
+
- GIST
|
|
330
|
+
- Adrenocortical Carcinoma
|
|
331
|
+
- Thymoma
|
|
332
|
+
- And more
|
|
333
|
+
|
|
334
|
+
</details>
|
|
335
|
+
|
|
336
|
+
## Emerging Therapeutics
|
|
337
|
+
|
|
338
|
+
The platform includes cutting-edge treatment modalities:
|
|
339
|
+
|
|
340
|
+
- **Antibody-Drug Conjugates (ADCs):** T-DXd, sacituzumab govitecan
|
|
341
|
+
- **Bispecific Antibodies:** teclistamab, glofitamab
|
|
342
|
+
- **CAR-T Therapies:** axi-cel, liso-cel, ide-cel
|
|
343
|
+
- **Tumor-Infiltrating Lymphocytes (TILs):** lifileucel
|
|
344
|
+
- **KRAS Inhibitors:** sotorasib, adagrasib
|
|
345
|
+
- **Protein Degraders:** PROTACs, molecular glues
|
|
346
|
+
- **Radiopharmaceuticals:** Lu-177 PSMA, I-131 MIBG
|
|
347
|
+
- **Cancer Vaccines:** mRNA-4157, personalized neoantigen vaccines
|
|
348
|
+
|
|
66
349
|
## Requirements
|
|
67
350
|
|
|
68
351
|
- Node.js >= 18.0.0
|
|
@@ -70,3 +353,8 @@ const targets = await capability.discoverDrugTargets(cancerType, genomicData);
|
|
|
70
353
|
## License
|
|
71
354
|
|
|
72
355
|
MIT
|
|
356
|
+
|
|
357
|
+
## Links
|
|
358
|
+
|
|
359
|
+
- [npm Package](https://www.npmjs.com/package/@erosolaraijs/cure)
|
|
360
|
+
- [Report Issues](https://github.com/anthropics/claude-code/issues)
|
package/dist/bin/cure.js
CHANGED
|
@@ -19,10 +19,21 @@ import * as path from 'path';
|
|
|
19
19
|
import * as os from 'os';
|
|
20
20
|
import { CancerTreatmentCapabilityModule } from '../capabilities/cancerTreatmentCapability.js';
|
|
21
21
|
import { createRealWorldOncologyService } from '../orchestrator/realWorldOncology.js';
|
|
22
|
-
const VERSION = '2.
|
|
22
|
+
const VERSION = '2.3.1';
|
|
23
23
|
const PACKAGE_NAME = '@erosolaraijs/cure';
|
|
24
|
-
const XAI_MODEL = 'grok-4-1-fast-reasoning';
|
|
25
24
|
const UPDATE_CHECK_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours
|
|
25
|
+
let currentProvider = process.env.AI_PROVIDER || 'xai';
|
|
26
|
+
const XAI_MODEL = 'grok-4-1-fast-reasoning';
|
|
27
|
+
const OPENAI_MODEL = 'gpt-5.1';
|
|
28
|
+
function getActiveModel() {
|
|
29
|
+
return currentProvider === 'openai' ? OPENAI_MODEL : XAI_MODEL;
|
|
30
|
+
}
|
|
31
|
+
function getActiveProvider() {
|
|
32
|
+
return currentProvider === 'openai' ? 'OpenAI' : 'xAI';
|
|
33
|
+
}
|
|
34
|
+
function setProvider(provider) {
|
|
35
|
+
currentProvider = provider;
|
|
36
|
+
}
|
|
26
37
|
// Update check cache file
|
|
27
38
|
const UPDATE_CACHE_DIR = path.join(os.homedir(), '.cure');
|
|
28
39
|
const UPDATE_CACHE_FILE = path.join(UPDATE_CACHE_DIR, 'update-check.json');
|
|
@@ -44,6 +55,18 @@ let cancerTreatment;
|
|
|
44
55
|
let oncologyService = null;
|
|
45
56
|
let conversationHistory = [];
|
|
46
57
|
let xaiApiKey = process.env.XAI_API_KEY;
|
|
58
|
+
let openaiApiKey = process.env.OPENAI_API_KEY;
|
|
59
|
+
function getActiveApiKey() {
|
|
60
|
+
return currentProvider === 'openai' ? openaiApiKey : xaiApiKey;
|
|
61
|
+
}
|
|
62
|
+
function setActiveApiKey(key) {
|
|
63
|
+
if (currentProvider === 'openai') {
|
|
64
|
+
openaiApiKey = key;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
xaiApiKey = key;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
47
70
|
// Service configuration
|
|
48
71
|
let serviceConfig = {
|
|
49
72
|
ehr: { enabled: false, vendor: 'epic', baseUrl: '', clientId: '' },
|
|
@@ -301,6 +324,78 @@ async function callXAI(userMessage) {
|
|
|
301
324
|
req.end();
|
|
302
325
|
});
|
|
303
326
|
}
|
|
327
|
+
async function callOpenAI(userMessage) {
|
|
328
|
+
if (!openaiApiKey) {
|
|
329
|
+
return `${colors.yellow}API key not set.${colors.reset} Use ${colors.cyan}/key YOUR_API_KEY${colors.reset} to set your OpenAI API key.\n\nGet your key at: https://platform.openai.com/api-keys`;
|
|
330
|
+
}
|
|
331
|
+
const apiKey = openaiApiKey;
|
|
332
|
+
conversationHistory.push({ role: 'user', content: userMessage });
|
|
333
|
+
const messages = [
|
|
334
|
+
{ role: 'system', content: SYSTEM_PROMPT },
|
|
335
|
+
...conversationHistory
|
|
336
|
+
];
|
|
337
|
+
const requestBody = JSON.stringify({
|
|
338
|
+
model: OPENAI_MODEL,
|
|
339
|
+
messages: messages,
|
|
340
|
+
temperature: 0.7,
|
|
341
|
+
max_tokens: 2048
|
|
342
|
+
});
|
|
343
|
+
return new Promise((resolve, reject) => {
|
|
344
|
+
const options = {
|
|
345
|
+
hostname: 'api.openai.com',
|
|
346
|
+
port: 443,
|
|
347
|
+
path: '/v1/chat/completions',
|
|
348
|
+
method: 'POST',
|
|
349
|
+
headers: {
|
|
350
|
+
'Content-Type': 'application/json',
|
|
351
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
352
|
+
'Content-Length': Buffer.byteLength(requestBody)
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const req = https.request(options, (res) => {
|
|
356
|
+
let data = '';
|
|
357
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
358
|
+
res.on('end', () => {
|
|
359
|
+
try {
|
|
360
|
+
const response = JSON.parse(data);
|
|
361
|
+
if (response.choices && response.choices[0]?.message?.content) {
|
|
362
|
+
const assistantMessage = response.choices[0].message.content;
|
|
363
|
+
conversationHistory.push({ role: 'assistant', content: assistantMessage });
|
|
364
|
+
// Keep conversation history manageable
|
|
365
|
+
if (conversationHistory.length > 20) {
|
|
366
|
+
conversationHistory = conversationHistory.slice(-16);
|
|
367
|
+
}
|
|
368
|
+
resolve(assistantMessage);
|
|
369
|
+
}
|
|
370
|
+
else if (response.error) {
|
|
371
|
+
resolve(`${colors.red}API Error: ${response.error.message}${colors.reset}`);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
resolve(`${colors.red}Unexpected response format${colors.reset}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
catch (e) {
|
|
378
|
+
resolve(`${colors.red}Failed to parse response${colors.reset}`);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
req.on('error', (e) => {
|
|
383
|
+
resolve(`${colors.red}Connection error: ${e.message}${colors.reset}`);
|
|
384
|
+
});
|
|
385
|
+
req.setTimeout(30000, () => {
|
|
386
|
+
req.destroy();
|
|
387
|
+
resolve(`${colors.yellow}Request timed out. Try again.${colors.reset}`);
|
|
388
|
+
});
|
|
389
|
+
req.write(requestBody);
|
|
390
|
+
req.end();
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
async function callAI(userMessage) {
|
|
394
|
+
if (currentProvider === 'openai') {
|
|
395
|
+
return callOpenAI(userMessage);
|
|
396
|
+
}
|
|
397
|
+
return callXAI(userMessage);
|
|
398
|
+
}
|
|
304
399
|
async function initializeServices() {
|
|
305
400
|
console.log(`${colors.dim}Initializing oncology services...${colors.reset}`);
|
|
306
401
|
cancerTreatment = new CancerTreatmentCapabilityModule();
|
|
@@ -338,9 +433,9 @@ async function launchInteractiveMode() {
|
|
|
338
433
|
const prompt = () => {
|
|
339
434
|
process.stdout.write(`\n${colors.cyan}cure${colors.reset} ${colors.dim}>${colors.reset} `);
|
|
340
435
|
};
|
|
341
|
-
const modelInfo =
|
|
342
|
-
? `${colors.green}Connected to
|
|
343
|
-
: `${colors.yellow}Use /key YOUR_API_KEY to enable AI${colors.reset}`;
|
|
436
|
+
const modelInfo = getActiveApiKey()
|
|
437
|
+
? `${colors.green}Connected to ${getActiveProvider()} ${getActiveModel()}${colors.reset}`
|
|
438
|
+
: `${colors.yellow}Use /key YOUR_API_KEY to enable AI (${getActiveProvider()})${colors.reset}`;
|
|
344
439
|
console.log(`${colors.dim}${modelInfo}${colors.reset}`);
|
|
345
440
|
console.log(`${colors.dim}Real-world oncology platform ready. Type your question or /help for commands.${colors.reset}\n`);
|
|
346
441
|
prompt();
|
|
@@ -416,25 +511,74 @@ async function processInput(input) {
|
|
|
416
511
|
await runDemo();
|
|
417
512
|
return;
|
|
418
513
|
case 'version':
|
|
419
|
-
console.log(`\n${colors.cyan}cure${colors.reset} v${VERSION} (${
|
|
514
|
+
console.log(`\n${colors.cyan}cure${colors.reset} v${VERSION} (${getActiveProvider()} ${getActiveModel()})`);
|
|
420
515
|
return;
|
|
421
516
|
case 'update':
|
|
422
517
|
await checkForUpdate();
|
|
423
518
|
return;
|
|
424
519
|
case 'model':
|
|
425
|
-
|
|
426
|
-
|
|
520
|
+
if (args[0]) {
|
|
521
|
+
const provider = args[0].toLowerCase();
|
|
522
|
+
if (provider === 'xai' || provider === 'openai') {
|
|
523
|
+
setProvider(provider);
|
|
524
|
+
console.log(`\n${colors.green}✓ Switched to ${getActiveProvider()} ${getActiveModel()}${colors.reset}`);
|
|
525
|
+
if (!getActiveApiKey()) {
|
|
526
|
+
const keyUrl = currentProvider === 'openai'
|
|
527
|
+
? 'https://platform.openai.com/api-keys'
|
|
528
|
+
: 'https://console.x.ai';
|
|
529
|
+
console.log(`${colors.yellow}Note: API key not set for ${getActiveProvider()}${colors.reset}`);
|
|
530
|
+
console.log(`${colors.dim}Use /key YOUR_API_KEY or get one at: ${keyUrl}${colors.reset}`);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
console.log(`\n${colors.red}Unknown provider: ${provider}${colors.reset}`);
|
|
535
|
+
console.log(`${colors.dim}Available: xai, openai${colors.reset}`);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
console.log(`\n${colors.cyan}Provider:${colors.reset} ${getActiveProvider()}`);
|
|
540
|
+
console.log(`${colors.cyan}Model:${colors.reset} ${getActiveModel()}`);
|
|
541
|
+
console.log(`${colors.cyan}API:${colors.reset} ${getActiveApiKey() ? 'Connected' : 'Not configured'}`);
|
|
542
|
+
console.log(`\n${colors.dim}Available providers:${colors.reset}`);
|
|
543
|
+
console.log(` ${currentProvider === 'xai' ? colors.green + '●' : colors.dim + '○'} xai${colors.reset} - ${XAI_MODEL}`);
|
|
544
|
+
console.log(` ${currentProvider === 'openai' ? colors.green + '●' : colors.dim + '○'} openai${colors.reset} - ${OPENAI_MODEL}`);
|
|
545
|
+
console.log(`\n${colors.dim}Usage: /model <xai|openai> to switch providers${colors.reset}`);
|
|
546
|
+
}
|
|
427
547
|
return;
|
|
428
548
|
case 'key':
|
|
429
549
|
if (args[0]) {
|
|
430
|
-
|
|
431
|
-
|
|
550
|
+
// Check if first arg is a provider name
|
|
551
|
+
const providerArg = args[0].toLowerCase();
|
|
552
|
+
if ((providerArg === 'xai' || providerArg === 'openai') && args[1]) {
|
|
553
|
+
// Set key for specific provider: /key openai sk-xxx
|
|
554
|
+
if (providerArg === 'openai') {
|
|
555
|
+
openaiApiKey = args[1];
|
|
556
|
+
console.log(`\n${colors.green}✓ OpenAI API key set successfully${colors.reset}`);
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
xaiApiKey = args[1];
|
|
560
|
+
console.log(`\n${colors.green}✓ xAI API key set successfully${colors.reset}`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
// Set key for current provider: /key sk-xxx
|
|
565
|
+
setActiveApiKey(args[0]);
|
|
566
|
+
console.log(`\n${colors.green}✓ ${getActiveProvider()} API key set successfully${colors.reset}`);
|
|
567
|
+
}
|
|
432
568
|
console.log(`${colors.dim}You can now chat with the AI oncologist.${colors.reset}`);
|
|
433
569
|
}
|
|
434
570
|
else {
|
|
435
|
-
console.log(`\n${colors.
|
|
436
|
-
console.log(
|
|
437
|
-
console.log(
|
|
571
|
+
console.log(`\n${colors.bold}API Keys Status${colors.reset}`);
|
|
572
|
+
console.log(`${colors.dim}─────────────────────────────────────${colors.reset}`);
|
|
573
|
+
console.log(` ${currentProvider === 'xai' ? colors.green + '●' : colors.dim + '○'} xai${colors.reset} ${xaiApiKey ? colors.green + 'Set' : colors.yellow + 'Not set'}${colors.reset}`);
|
|
574
|
+
console.log(` ${currentProvider === 'openai' ? colors.green + '●' : colors.dim + '○'} openai${colors.reset} ${openaiApiKey ? colors.green + 'Set' : colors.yellow + 'Not set'}${colors.reset}`);
|
|
575
|
+
console.log(`\n${colors.dim}Usage:${colors.reset}`);
|
|
576
|
+
console.log(` /key YOUR_API_KEY Set key for current provider (${getActiveProvider()})`);
|
|
577
|
+
console.log(` /key xai YOUR_API_KEY Set xAI key`);
|
|
578
|
+
console.log(` /key openai YOUR_API_KEY Set OpenAI key`);
|
|
579
|
+
console.log(`\n${colors.dim}Get your keys at:${colors.reset}`);
|
|
580
|
+
console.log(` xAI: https://console.x.ai`);
|
|
581
|
+
console.log(` OpenAI: https://platform.openai.com/api-keys`);
|
|
438
582
|
}
|
|
439
583
|
return;
|
|
440
584
|
default:
|
|
@@ -445,7 +589,7 @@ async function processInput(input) {
|
|
|
445
589
|
}
|
|
446
590
|
// AI-powered response for natural language
|
|
447
591
|
console.log(`\n${colors.dim}Thinking...${colors.reset}`);
|
|
448
|
-
const response = await
|
|
592
|
+
const response = await callAI(input);
|
|
449
593
|
console.log(`\n${response}`);
|
|
450
594
|
}
|
|
451
595
|
async function analyzePatient(patientId, includeGenomics = false) {
|
|
@@ -750,8 +894,9 @@ async function showSystemStatus() {
|
|
|
750
894
|
console.log(` Safety Checks: ${serviceConfig.safety?.enabled ? colors.green + 'Enabled' : colors.dim + 'Disabled'}${colors.reset}`);
|
|
751
895
|
console.log(` HIPAA Compliance:${serviceConfig.compliance?.enabled ? colors.green + 'Enabled' : colors.dim + 'Disabled'}${colors.reset}`);
|
|
752
896
|
console.log(`\n${colors.bold}API${colors.reset}`);
|
|
753
|
-
console.log(`
|
|
754
|
-
console.log(`
|
|
897
|
+
console.log(` Provider: ${getActiveProvider()}`);
|
|
898
|
+
console.log(` API Status: ${getActiveApiKey() ? colors.green + 'Connected' : colors.yellow + 'Not configured'}${colors.reset}`);
|
|
899
|
+
console.log(` Model: ${getActiveModel()}`);
|
|
755
900
|
console.log(`\n${colors.green}✓ Status check complete${colors.reset}`);
|
|
756
901
|
}
|
|
757
902
|
catch (error) {
|
|
@@ -892,14 +1037,14 @@ ${colors.cyan}${colors.bold} ╔═══════════════
|
|
|
892
1037
|
║ ║
|
|
893
1038
|
╚═══════════════════════════════════════════════════════════╝${colors.reset}
|
|
894
1039
|
|
|
895
|
-
${colors.dim}v${VERSION} |
|
|
1040
|
+
${colors.dim}v${VERSION} | ${getActiveProvider()} ${getActiveModel()}${colors.reset}
|
|
896
1041
|
`);
|
|
897
1042
|
}
|
|
898
1043
|
function printInteractiveHelp() {
|
|
899
1044
|
console.log(`
|
|
900
1045
|
${colors.bold}Commands${colors.reset}
|
|
901
1046
|
${colors.dim}─────────────────────────────────────${colors.reset}
|
|
902
|
-
${colors.cyan}/key${colors.reset} [
|
|
1047
|
+
${colors.cyan}/key${colors.reset} [provider] [key] Set API key (for xai or openai)
|
|
903
1048
|
${colors.cyan}/analyze${colors.reset} [patient] Analyze patient data
|
|
904
1049
|
${colors.cyan}/plan${colors.reset} [patient] Design treatment plan
|
|
905
1050
|
${colors.cyan}/cure${colors.reset} [cancer] [stage] Generate cure protocol
|
|
@@ -917,7 +1062,7 @@ ${colors.dim}──────────────────────
|
|
|
917
1062
|
${colors.bold}Other${colors.reset}
|
|
918
1063
|
${colors.dim}─────────────────────────────────────${colors.reset}
|
|
919
1064
|
${colors.cyan}/demo${colors.reset} Run framework demo
|
|
920
|
-
${colors.cyan}/model${colors.reset}
|
|
1065
|
+
${colors.cyan}/model${colors.reset} [xai|openai] Show/switch AI provider
|
|
921
1066
|
${colors.cyan}/update${colors.reset} Check for updates
|
|
922
1067
|
${colors.cyan}/clear${colors.reset} Clear conversation
|
|
923
1068
|
${colors.cyan}/help${colors.reset} Show this help
|
|
@@ -942,15 +1087,18 @@ ${colors.dim}──────────────────────
|
|
|
942
1087
|
|
|
943
1088
|
${colors.bold}Setup${colors.reset}
|
|
944
1089
|
${colors.dim}─────────────────────────────────────${colors.reset}
|
|
945
|
-
1. Get API key
|
|
946
|
-
|
|
1090
|
+
1. Get API key:
|
|
1091
|
+
- xAI: https://console.x.ai
|
|
1092
|
+
- OpenAI: https://platform.openai.com/api-keys
|
|
1093
|
+
2. Set provider: AI_PROVIDER=openai (or xai)
|
|
1094
|
+
3. Run: /key YOUR_API_KEY
|
|
947
1095
|
`);
|
|
948
1096
|
}
|
|
949
1097
|
function printHelp() {
|
|
950
1098
|
console.log(`
|
|
951
1099
|
${colors.bold}Cure - AI Cancer Treatment Framework${colors.reset}
|
|
952
1100
|
Real-World Precision Oncology Platform
|
|
953
|
-
Powered by
|
|
1101
|
+
Powered by ${getActiveProvider()} ${getActiveModel()}
|
|
954
1102
|
|
|
955
1103
|
${colors.bold}Usage:${colors.reset}
|
|
956
1104
|
cure Launch interactive AI chat
|
|
@@ -981,7 +1129,9 @@ ${colors.bold}Options:${colors.reset}
|
|
|
981
1129
|
--drugs=<list> Comma-separated drug names
|
|
982
1130
|
|
|
983
1131
|
${colors.bold}Environment:${colors.reset}
|
|
984
|
-
|
|
1132
|
+
AI_PROVIDER AI provider: 'xai' or 'openai' (default: xai)
|
|
1133
|
+
XAI_API_KEY xAI API key (for xAI provider)
|
|
1134
|
+
OPENAI_API_KEY OpenAI API key (for OpenAI provider)
|
|
985
1135
|
FHIR_BASE_URL FHIR server URL for EHR integration
|
|
986
1136
|
FHIR_CLIENT_ID FHIR OAuth client ID
|
|
987
1137
|
FHIR_CLIENT_SECRET FHIR OAuth client secret
|