@erosolaraijs/cure 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/bin/cure.d.ts +2 -5
  2. package/dist/bin/cure.d.ts.map +1 -1
  3. package/dist/bin/cure.js +360 -129
  4. package/dist/bin/cure.js.map +1 -1
  5. package/dist/clinician/decisionSupport.d.ts +325 -0
  6. package/dist/clinician/decisionSupport.d.ts.map +1 -0
  7. package/dist/clinician/decisionSupport.js +604 -0
  8. package/dist/clinician/decisionSupport.js.map +1 -0
  9. package/dist/clinician/index.d.ts +5 -0
  10. package/dist/clinician/index.d.ts.map +1 -0
  11. package/dist/clinician/index.js +5 -0
  12. package/dist/clinician/index.js.map +1 -0
  13. package/dist/compliance/index.d.ts +5 -0
  14. package/dist/compliance/index.d.ts.map +1 -0
  15. package/dist/compliance/index.js +5 -0
  16. package/dist/compliance/index.js.map +1 -0
  17. package/dist/index.d.ts +65 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +102 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/integrations/clinicalTrials/index.d.ts +5 -0
  22. package/dist/integrations/clinicalTrials/index.d.ts.map +1 -0
  23. package/dist/integrations/clinicalTrials/index.js +5 -0
  24. package/dist/integrations/clinicalTrials/index.js.map +1 -0
  25. package/dist/integrations/ehr/index.d.ts +5 -0
  26. package/dist/integrations/ehr/index.d.ts.map +1 -0
  27. package/dist/integrations/ehr/index.js +5 -0
  28. package/dist/integrations/ehr/index.js.map +1 -0
  29. package/dist/integrations/genomics/index.d.ts +5 -0
  30. package/dist/integrations/genomics/index.d.ts.map +1 -0
  31. package/dist/integrations/genomics/index.js +5 -0
  32. package/dist/integrations/genomics/index.js.map +1 -0
  33. package/dist/ml/index.d.ts +5 -0
  34. package/dist/ml/index.d.ts.map +1 -0
  35. package/dist/ml/index.js +5 -0
  36. package/dist/ml/index.js.map +1 -0
  37. package/dist/ml/outcomePredictor.d.ts +297 -0
  38. package/dist/ml/outcomePredictor.d.ts.map +1 -0
  39. package/dist/ml/outcomePredictor.js +823 -0
  40. package/dist/ml/outcomePredictor.js.map +1 -0
  41. package/dist/orchestrator/index.d.ts +5 -0
  42. package/dist/orchestrator/index.d.ts.map +1 -0
  43. package/dist/orchestrator/index.js +5 -0
  44. package/dist/orchestrator/index.js.map +1 -0
  45. package/dist/orchestrator/realWorldOncology.d.ts +351 -0
  46. package/dist/orchestrator/realWorldOncology.d.ts.map +1 -0
  47. package/dist/orchestrator/realWorldOncology.js +425 -0
  48. package/dist/orchestrator/realWorldOncology.js.map +1 -0
  49. package/dist/patient/index.d.ts +5 -0
  50. package/dist/patient/index.d.ts.map +1 -0
  51. package/dist/patient/index.js +5 -0
  52. package/dist/patient/index.js.map +1 -0
  53. package/dist/patient/patientPortal.d.ts +337 -0
  54. package/dist/patient/patientPortal.d.ts.map +1 -0
  55. package/dist/patient/patientPortal.js +667 -0
  56. package/dist/patient/patientPortal.js.map +1 -0
  57. package/dist/safety/drugInteractions.d.ts +230 -0
  58. package/dist/safety/drugInteractions.d.ts.map +1 -0
  59. package/dist/safety/drugInteractions.js +697 -0
  60. package/dist/safety/drugInteractions.js.map +1 -0
  61. package/dist/safety/index.d.ts +5 -0
  62. package/dist/safety/index.d.ts.map +1 -0
  63. package/dist/safety/index.js +5 -0
  64. package/dist/safety/index.js.map +1 -0
  65. package/dist/validation/index.d.ts +5 -0
  66. package/dist/validation/index.d.ts.map +1 -0
  67. package/dist/validation/index.js +5 -0
  68. package/dist/validation/index.js.map +1 -0
  69. package/dist/validation/retrospectiveValidator.d.ts +246 -0
  70. package/dist/validation/retrospectiveValidator.d.ts.map +1 -0
  71. package/dist/validation/retrospectiveValidator.js +602 -0
  72. package/dist/validation/retrospectiveValidator.js.map +1 -0
  73. package/package.json +1 -1
  74. package/src/bin/cure.ts +412 -143
  75. package/src/clinician/decisionSupport.ts +949 -0
  76. package/src/clinician/index.ts +11 -0
  77. package/src/compliance/index.ts +19 -0
  78. package/src/integrations/clinicalTrials/index.ts +21 -0
  79. package/src/integrations/ehr/index.ts +32 -0
  80. package/src/integrations/genomics/index.ts +23 -0
  81. package/src/ml/index.ts +15 -0
  82. package/src/orchestrator/index.ts +11 -0
  83. package/src/orchestrator/realWorldOncology.ts +803 -0
  84. package/src/patient/index.ts +14 -0
  85. package/src/patient/patientPortal.ts +1039 -0
  86. package/src/safety/index.ts +14 -0
  87. package/src/validation/index.ts +10 -0
package/src/bin/cure.ts CHANGED
@@ -1,182 +1,451 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * 癌症治疗统一人工智能框架 - 核心医疗控制台
4
- * Unified Cancer Treatment Framework - Core Medical Console
5
- *
6
- * 全球首个人工通用智能驱动的癌症治疗统一指挥控制平台
7
- * 提供完整的癌症研究、药物发现、治疗规划、患者管理和医疗系统集成能力
3
+ * Cure - AI Cancer Treatment Framework
4
+ * Interactive CLI powered by xAI Grok for precision oncology
8
5
  */
9
6
 
7
+ import * as readline from 'readline';
8
+ import * as https from 'https';
10
9
  import { CancerTreatmentCapabilityModule } from '../capabilities/cancerTreatmentCapability.js';
11
10
 
11
+ const VERSION = '1.0.3';
12
+ const XAI_MODEL = 'grok-4-1-fast-reasoning';
13
+
14
+ // ANSI color codes
15
+ const colors = {
16
+ reset: '\x1b[0m',
17
+ bold: '\x1b[1m',
18
+ dim: '\x1b[2m',
19
+ cyan: '\x1b[36m',
20
+ green: '\x1b[32m',
21
+ yellow: '\x1b[33m',
22
+ blue: '\x1b[34m',
23
+ magenta: '\x1b[35m',
24
+ red: '\x1b[31m',
25
+ white: '\x1b[37m',
26
+ };
27
+
28
+ let cancerTreatment: CancerTreatmentCapabilityModule;
29
+ let conversationHistory: Array<{role: string, content: string}> = [];
30
+
31
+ const SYSTEM_PROMPT = `You are Cure, an advanced AI oncologist assistant powered by the Cure Cancer Treatment Framework. You help doctors, researchers, and patients with:
32
+
33
+ 1. Cancer diagnosis and staging analysis
34
+ 2. Personalized treatment planning (chemotherapy, immunotherapy, targeted therapy, CAR-T)
35
+ 3. Drug target discovery and mechanism analysis
36
+ 4. Clinical trial matching and eligibility
37
+ 5. Genomic biomarker interpretation (EGFR, KRAS, BRAF, HER2, PD-L1, etc.)
38
+ 6. Treatment response prediction and survival analysis
39
+ 7. Drug interaction and safety checks
40
+ 8. HIPAA-compliant patient data handling
41
+
42
+ You have deep knowledge of:
43
+ - NCCN, ESMO, ASCO treatment guidelines
44
+ - FDA-approved cancer therapies and their mechanisms
45
+ - Precision medicine and molecular oncology
46
+ - Immunotherapy (checkpoint inhibitors, CAR-T, TILs)
47
+ - Targeted therapies for driver mutations
48
+ - Clinical trial design and interpretation
49
+
50
+ Be concise, scientifically accurate, and clinically relevant. When discussing specific treatments, cite evidence levels and relevant trials. Always recommend consulting with treating oncologists for actual patient care decisions.
51
+
52
+ Available commands the user can run:
53
+ - /analyze [patient_id] - Analyze patient data
54
+ - /plan [patient_id] - Design treatment plan
55
+ - /discover [gene] [cancer] - Drug target discovery
56
+ - /demo - Run framework demonstration
57
+ - /help - Show available commands`;
58
+
59
+ async function callXAI(userMessage: string): Promise<string> {
60
+ const apiKey = process.env.XAI_API_KEY;
61
+
62
+ if (!apiKey) {
63
+ return `${colors.yellow}Note: Set XAI_API_KEY environment variable for AI-powered responses.${colors.reset}\n\nI can help you with cancer treatment analysis. Try:\n /analyze P001 - Analyze patient\n /plan P001 - Design treatment plan\n /discover EGFR Lung - Find drug targets\n /demo - Run demonstration`;
64
+ }
65
+
66
+ conversationHistory.push({ role: 'user', content: userMessage });
67
+
68
+ const messages = [
69
+ { role: 'system', content: SYSTEM_PROMPT },
70
+ ...conversationHistory
71
+ ];
72
+
73
+ const requestBody = JSON.stringify({
74
+ model: XAI_MODEL,
75
+ messages: messages,
76
+ temperature: 0.7,
77
+ max_tokens: 2048
78
+ });
79
+
80
+ return new Promise((resolve, reject) => {
81
+ const options = {
82
+ hostname: 'api.x.ai',
83
+ port: 443,
84
+ path: '/v1/chat/completions',
85
+ method: 'POST',
86
+ headers: {
87
+ 'Content-Type': 'application/json',
88
+ 'Authorization': `Bearer ${apiKey}`,
89
+ 'Content-Length': Buffer.byteLength(requestBody)
90
+ }
91
+ };
92
+
93
+ const req = https.request(options, (res) => {
94
+ let data = '';
95
+ res.on('data', (chunk) => { data += chunk; });
96
+ res.on('end', () => {
97
+ try {
98
+ const response = JSON.parse(data);
99
+ if (response.choices && response.choices[0]?.message?.content) {
100
+ const assistantMessage = response.choices[0].message.content;
101
+ conversationHistory.push({ role: 'assistant', content: assistantMessage });
102
+
103
+ // Keep conversation history manageable
104
+ if (conversationHistory.length > 20) {
105
+ conversationHistory = conversationHistory.slice(-16);
106
+ }
107
+
108
+ resolve(assistantMessage);
109
+ } else if (response.error) {
110
+ resolve(`${colors.red}API Error: ${response.error.message}${colors.reset}`);
111
+ } else {
112
+ resolve(`${colors.red}Unexpected response format${colors.reset}`);
113
+ }
114
+ } catch (e) {
115
+ resolve(`${colors.red}Failed to parse response${colors.reset}`);
116
+ }
117
+ });
118
+ });
119
+
120
+ req.on('error', (e) => {
121
+ resolve(`${colors.red}Connection error: ${e.message}${colors.reset}`);
122
+ });
123
+
124
+ req.setTimeout(30000, () => {
125
+ req.destroy();
126
+ resolve(`${colors.yellow}Request timed out. Try again.${colors.reset}`);
127
+ });
128
+
129
+ req.write(requestBody);
130
+ req.end();
131
+ });
132
+ }
133
+
12
134
  async function main(): Promise<void> {
13
135
  const args = process.argv.slice(2);
14
136
 
15
- // Check for version flag
16
137
  if (args.includes('--version') || args.includes('-v')) {
17
- const pkg = JSON.parse(await import('fs').then(fs => fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf-8')));
18
- console.log(`agi-core-cancer-treatment v${pkg.version}`);
138
+ console.log(`cure v${VERSION}`);
19
139
  process.exit(0);
20
140
  }
21
141
 
22
- // Check for help flag
23
142
  if (args.includes('--help') || args.includes('-h')) {
24
143
  printHelp();
25
144
  process.exit(0);
26
145
  }
27
146
 
28
- // Initialize module
29
- const cancerTreatment = new CancerTreatmentCapabilityModule();
30
-
31
- // Handle commands
32
- if (args.includes('--cancer-treatment') || args.includes('--medical')) {
33
- console.log('\n🏥 癌症治疗人工智能框架激活\n');
34
- console.log('💊 最大能力癌症治疗框架 - 全面医疗与AI能力\n');
35
- console.log('📊 框架提供以下核心能力:');
36
- console.log(' • 个性化癌症治疗协议分析与规划');
37
- console.log(' • AI驱动的药物靶点发现与设计');
38
- console.log(' • 精准医疗与基因组分析管道');
39
- console.log(' • 临床试验管理与优化');
40
- console.log(' • 患者多维度评估与监测');
41
- console.log(' • 医疗系统集成与数据协调');
42
- console.log(' • 统一医疗指挥与协调系统');
43
- console.log(' • 人工智能治疗决策支持\n');
44
-
45
- console.log('✅ 癌症治疗能力框架初始化完成');
46
- console.log('🚀 使用 --help 查看可用命令');
147
+ cancerTreatment = new CancerTreatmentCapabilityModule();
148
+
149
+ if (args.length > 0) {
150
+ await handleCommand(args);
151
+ } else {
152
+ await launchInteractiveMode();
47
153
  }
48
- else if (args.includes('--analyze-patient')) {
49
- const patientId = args.find(arg => arg.startsWith('--patient='))?.split('=')[1] || 'P001';
50
- const includeGenomics = args.includes('--genomics');
51
-
52
- console.log(`\n🔍 分析患者: ${patientId}`);
53
- console.log('───────────────────────────');
54
-
55
- try {
56
- const result = await cancerTreatment.analyzePatient(patientId, includeGenomics);
57
- console.log('📊 分析结果:');
58
- console.log(` • 癌症类型: ${result.analysis.cancerType}`);
59
- console.log(` • 分期: ${result.analysis.stage}`);
60
- console.log(` • 生物标志物: ${result.analysis.biomarkers.join(', ')}`);
61
- console.log(` • 生存概率: ${(result.analysis.riskAssessment.survivalProbability * 100).toFixed(1)}%`);
62
- console.log('✅ 分析完成');
63
- } catch (error) {
64
- console.error('❌ 分析失败:', error);
154
+ }
155
+
156
+ async function launchInteractiveMode(): Promise<void> {
157
+ console.clear();
158
+ printBanner();
159
+
160
+ const rl = readline.createInterface({
161
+ input: process.stdin,
162
+ output: process.stdout,
163
+ });
164
+
165
+ const prompt = () => {
166
+ process.stdout.write(`\n${colors.cyan}cure${colors.reset} ${colors.dim}>${colors.reset} `);
167
+ };
168
+
169
+ const modelInfo = process.env.XAI_API_KEY
170
+ ? `${colors.green}Connected to xAI ${XAI_MODEL}${colors.reset}`
171
+ : `${colors.yellow}Set XAI_API_KEY for AI responses${colors.reset}`;
172
+
173
+ console.log(`${colors.dim}${modelInfo}${colors.reset}`);
174
+ console.log(`${colors.dim}Type your question or /help for commands.${colors.reset}\n`);
175
+ prompt();
176
+
177
+ rl.on('line', async (input) => {
178
+ const trimmed = input.trim();
179
+
180
+ if (!trimmed) {
181
+ prompt();
182
+ return;
65
183
  }
66
- }
67
- else if (args.includes('--treatment-plan')) {
68
- const patientId = args.find(arg => arg.startsWith('--patient='))?.split('=')[1] || 'P001';
69
- const protocolId = args.find(arg => arg.startsWith('--protocol='))?.split('=')[1];
70
-
71
- console.log(`\n💊 设计治疗计划: ${patientId}`);
72
- console.log('─────────────────────────────');
73
-
74
- try {
75
- const result = await cancerTreatment.designTreatmentPlan(patientId, protocolId);
76
- console.log('📋 治疗计划:');
77
- console.log(` • 协议: ${result.plan.protocol.name}`);
78
- console.log(` • 治疗方式: ${result.plan.protocol.treatmentModalities.join(', ')}`);
79
- console.log(` • 预计疗效: ${(result.estimatedEfficacy * 100).toFixed(1)}%`);
80
- console.log(` • 时间线: ${result.plan.treatmentTimeline.length} 周`);
81
- console.log('✅ 治疗计划设计完成');
82
- } catch (error) {
83
- console.error('❌ 治疗计划设计失败:', error);
184
+
185
+ if (trimmed === '/exit' || trimmed === '/quit' || trimmed === 'exit' || trimmed === 'quit') {
186
+ console.log(`\n${colors.dim}Goodbye.${colors.reset}\n`);
187
+ rl.close();
188
+ process.exit(0);
189
+ }
190
+
191
+ if (trimmed === '/help' || trimmed === 'help') {
192
+ printInteractiveHelp();
193
+ prompt();
194
+ return;
195
+ }
196
+
197
+ if (trimmed === '/clear') {
198
+ console.clear();
199
+ printBanner();
200
+ conversationHistory = [];
201
+ console.log(`${colors.dim}Conversation cleared.${colors.reset}`);
202
+ prompt();
203
+ return;
204
+ }
205
+
206
+ await processInput(trimmed);
207
+ prompt();
208
+ });
209
+
210
+ rl.on('close', () => {
211
+ process.exit(0);
212
+ });
213
+ }
214
+
215
+ async function processInput(input: string): Promise<void> {
216
+ // Slash commands
217
+ if (input.startsWith('/')) {
218
+ const parts = input.slice(1).split(' ');
219
+ const cmd = parts[0];
220
+ const args = parts.slice(1);
221
+
222
+ switch (cmd) {
223
+ case 'analyze':
224
+ await analyzePatient(args[0] || 'P001', args.includes('--genomics'));
225
+ return;
226
+ case 'plan':
227
+ await designTreatmentPlan(args[0] || 'P001', args[1]);
228
+ return;
229
+ case 'discover':
230
+ await discoverTargets(args[0] || 'EGFR', args[1] || 'Lung');
231
+ return;
232
+ case 'demo':
233
+ await runDemo();
234
+ return;
235
+ case 'version':
236
+ console.log(`\n${colors.cyan}cure${colors.reset} v${VERSION} (${XAI_MODEL})`);
237
+ return;
238
+ case 'model':
239
+ console.log(`\n${colors.cyan}Model:${colors.reset} ${XAI_MODEL}`);
240
+ console.log(`${colors.cyan}API:${colors.reset} ${process.env.XAI_API_KEY ? 'Connected' : 'Not configured'}`);
241
+ return;
242
+ default:
243
+ console.log(`\n${colors.red}Unknown command: /${cmd}${colors.reset}`);
244
+ console.log(`${colors.dim}Type /help for available commands.${colors.reset}`);
245
+ return;
84
246
  }
85
247
  }
86
- else if (args.includes('--drug-discovery')) {
87
- const targetGene = args.find(arg => arg.startsWith('--target='))?.split('=')[1] || 'EGFR';
88
- const cancerType = args.find(arg => arg.startsWith('--cancer='))?.split('=')[1] || 'Lung';
89
-
90
- console.log(`\n🧬 药物靶点发现: ${targetGene} (${cancerType} 癌症)`);
91
- console.log('──────────────────────────────');
92
-
93
- try {
94
- const result = await cancerTreatment.discoverDrugTargets(cancerType, targetGene);
95
- console.log('🔬 发现结果:');
96
- console.log(` • 癌症类型: ${result.cancerType}`);
97
- console.log(` • 目标基因: ${result.targetGene || '所有'}`);
98
- console.log(` • 发现靶点: ${result.discoveredTargets.length} 个`);
99
-
100
- result.discoveredTargets.slice(0, 3).forEach((target: any, index: number) => {
101
- console.log(` ${index + 1}. ${target.gene} - ${target.evidenceLevel} 证据等级`);
102
- console.log(` 相关癌症: ${target.cancerTypes.join(', ')}`);
103
- });
104
-
105
- console.log('✅ 药物靶点发现完成');
106
- } catch (error) {
107
- console.error('❌ 药物发现失败:', error);
248
+
249
+ // AI-powered response for natural language
250
+ console.log(`\n${colors.dim}Thinking...${colors.reset}`);
251
+ const response = await callXAI(input);
252
+ console.log(`\n${response}`);
253
+ }
254
+
255
+ async function analyzePatient(patientId: string, includeGenomics: boolean = false): Promise<void> {
256
+ console.log(`\n${colors.cyan}Analyzing patient ${patientId}...${colors.reset}\n`);
257
+
258
+ try {
259
+ const result = await cancerTreatment.analyzePatient(patientId, includeGenomics);
260
+
261
+ console.log(`${colors.bold}Patient Analysis${colors.reset}`);
262
+ console.log(`${colors.dim}─────────────────────────────${colors.reset}`);
263
+ console.log(` Cancer Type: ${colors.yellow}${result.analysis.cancerType}${colors.reset}`);
264
+ console.log(` Stage: ${colors.yellow}${result.analysis.stage}${colors.reset}`);
265
+ console.log(` Biomarkers: ${result.analysis.biomarkers.join(', ')}`);
266
+ console.log(` Survival Prob: ${colors.green}${(result.analysis.riskAssessment.survivalProbability * 100).toFixed(1)}%${colors.reset}`);
267
+ console.log(` Recurrence: ${colors.yellow}${(result.analysis.riskAssessment.recurrenceRisk * 100).toFixed(1)}%${colors.reset}`);
268
+
269
+ if (result.analysis.genomicProfile) {
270
+ console.log(`\n${colors.bold}Genomic Profile${colors.reset}`);
271
+ console.log(` Mutations: ${result.analysis.genomicProfile.mutations?.length || 0} detected`);
108
272
  }
273
+
274
+ console.log(`\n${colors.green}✓ Analysis complete${colors.reset}`);
275
+ } catch (error) {
276
+ console.error(`${colors.red}✗ Analysis failed:${colors.reset}`, error);
109
277
  }
110
- else if (args.includes('--demo')) {
111
- console.log('\n🏥 癌症治疗框架演示');
112
- console.log('────────────────────');
113
-
114
- try {
115
- const { demonstrateCancerTreatmentFramework } = await import('../examples/cancerTreatmentDemo.js');
116
- await demonstrateCancerTreatmentFramework();
117
- } catch (error) {
118
- console.error('❌ 演示失败:', error);
278
+ }
279
+
280
+ async function designTreatmentPlan(patientId: string, protocolId?: string): Promise<void> {
281
+ console.log(`\n${colors.cyan}Designing treatment plan for ${patientId}...${colors.reset}\n`);
282
+
283
+ try {
284
+ const result = await cancerTreatment.designTreatmentPlan(patientId, protocolId);
285
+
286
+ console.log(`${colors.bold}Treatment Plan${colors.reset}`);
287
+ console.log(`${colors.dim}─────────────────────────────${colors.reset}`);
288
+ console.log(` Protocol: ${colors.yellow}${result.plan.protocol.name}${colors.reset}`);
289
+ console.log(` Modalities: ${result.plan.protocol.treatmentModalities.join(', ')}`);
290
+ console.log(` Est. Efficacy: ${colors.green}${(result.estimatedEfficacy * 100).toFixed(1)}%${colors.reset}`);
291
+ console.log(` Duration: ${result.plan.treatmentTimeline.length} weeks`);
292
+
293
+ console.log(`\n${colors.bold}Timeline${colors.reset}`);
294
+ result.plan.treatmentTimeline.slice(0, 4).forEach((week: any, i: number) => {
295
+ console.log(` Week ${i + 1}: ${week.phase} - ${week.activities.join(', ')}`);
296
+ });
297
+ if (result.plan.treatmentTimeline.length > 4) {
298
+ console.log(` ${colors.dim}... and ${result.plan.treatmentTimeline.length - 4} more weeks${colors.reset}`);
119
299
  }
300
+
301
+ console.log(`\n${colors.green}✓ Plan generated${colors.reset}`);
302
+ } catch (error) {
303
+ console.error(`${colors.red}✗ Plan generation failed:${colors.reset}`, error);
120
304
  }
121
- else if (args.length === 0) {
122
- // Interactive mode
123
- console.log('\n🏥 AGI 癌症治疗框架');
124
- console.log('══════════════════════════════════════');
125
- console.log('\n🔧 可用命令:');
126
- console.log(' agi --cancer-treatment 激活癌症治疗框架');
127
- console.log(' agi --analyze-patient --patient=P001 分析患者数据');
128
- console.log(' agi --treatment-plan --patient=P001 设计治疗计划');
129
- console.log(' agi --drug-discovery --target=EGFR 药物靶点发现');
130
- console.log(' agi --clinical-trial 临床试验演示');
131
- console.log(' agi --demo 完整框架演示');
132
- console.log(' agi --help 显示帮助信息');
133
- console.log(' agi --version 显示版本信息');
134
- console.log('\n📚 了解更多:');
135
- console.log(' 查看 README.md 获取完整文档和使用指南');
305
+ }
306
+
307
+ async function discoverTargets(gene: string, cancerType: string): Promise<void> {
308
+ console.log(`\n${colors.cyan}Discovering drug targets for ${gene} in ${cancerType} cancer...${colors.reset}\n`);
309
+
310
+ try {
311
+ const result = await cancerTreatment.discoverDrugTargets(cancerType, gene);
312
+
313
+ console.log(`${colors.bold}Drug Target Discovery${colors.reset}`);
314
+ console.log(`${colors.dim}─────────────────────────────${colors.reset}`);
315
+ console.log(` Cancer Type: ${colors.yellow}${result.cancerType}${colors.reset}`);
316
+ console.log(` Target Gene: ${colors.yellow}${result.targetGene || 'All'}${colors.reset}`);
317
+ console.log(` Targets Found: ${result.discoveredTargets.length}`);
318
+
319
+ console.log(`\n${colors.bold}Top Targets${colors.reset}`);
320
+ result.discoveredTargets.slice(0, 5).forEach((target: any, i: number) => {
321
+ console.log(` ${i + 1}. ${colors.cyan}${target.gene}${colors.reset} - ${target.evidenceLevel} evidence`);
322
+ console.log(` ${colors.dim}Cancers: ${target.cancerTypes.slice(0, 3).join(', ')}${colors.reset}`);
323
+ });
324
+
325
+ console.log(`\n${colors.green}✓ Discovery complete${colors.reset}`);
326
+ } catch (error) {
327
+ console.error(`${colors.red}✗ Discovery failed:${colors.reset}`, error);
328
+ }
329
+ }
330
+
331
+ async function runDemo(): Promise<void> {
332
+ console.log(`\n${colors.cyan}Running framework demo...${colors.reset}\n`);
333
+
334
+ try {
335
+ const { demonstrateCancerTreatmentFramework } = await import('../examples/cancerTreatmentDemo.js');
336
+ await demonstrateCancerTreatmentFramework();
337
+ } catch (error) {
338
+ console.error(`${colors.red}✗ Demo failed:${colors.reset}`, error);
339
+ }
340
+ }
341
+
342
+ async function handleCommand(args: string[]): Promise<void> {
343
+ cancerTreatment = new CancerTreatmentCapabilityModule();
344
+
345
+ if (args.includes('--analyze-patient')) {
346
+ const patientId = args.find(a => a.startsWith('--patient='))?.split('=')[1] || 'P001';
347
+ await analyzePatient(patientId, args.includes('--genomics'));
348
+ }
349
+ else if (args.includes('--treatment-plan')) {
350
+ const patientId = args.find(a => a.startsWith('--patient='))?.split('=')[1] || 'P001';
351
+ const protocolId = args.find(a => a.startsWith('--protocol='))?.split('=')[1];
352
+ await designTreatmentPlan(patientId, protocolId);
353
+ }
354
+ else if (args.includes('--drug-discovery')) {
355
+ const gene = args.find(a => a.startsWith('--target='))?.split('=')[1] || 'EGFR';
356
+ const cancer = args.find(a => a.startsWith('--cancer='))?.split('=')[1] || 'Lung';
357
+ await discoverTargets(gene, cancer);
358
+ }
359
+ else if (args.includes('--demo')) {
360
+ await runDemo();
136
361
  }
137
362
  else {
138
- console.log('❌ 未知命令。使用 agi --help 查看可用命令。');
363
+ console.log(`${colors.red}Unknown command.${colors.reset} Use cure --help for usage.`);
139
364
  process.exit(1);
140
365
  }
141
366
  }
142
367
 
368
+ function printBanner(): void {
369
+ console.log(`
370
+ ${colors.cyan}${colors.bold} ╔═══════════════════════════════════════════════════════════╗
371
+ ║ ║
372
+ ║ ██████╗██╗ ██╗██████╗ ███████╗ ║
373
+ ║ ██╔════╝██║ ██║██╔══██╗██╔════╝ ║
374
+ ║ ██║ ██║ ██║██████╔╝█████╗ ║
375
+ ║ ██║ ██║ ██║██╔══██╗██╔══╝ ║
376
+ ║ ╚██████╗╚██████╔╝██║ ██║███████╗ ║
377
+ ║ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ║
378
+ ║ ║
379
+ ║ AI Cancer Treatment Framework ║
380
+ ║ Powered by xAI Grok ${XAI_MODEL} ║
381
+ ║ ║
382
+ ╚═══════════════════════════════════════════════════════════╝${colors.reset}
383
+
384
+ ${colors.dim}v${VERSION}${colors.reset}
385
+ `);
386
+ }
387
+
388
+ function printInteractiveHelp(): void {
389
+ console.log(`
390
+ ${colors.bold}Commands${colors.reset}
391
+ ${colors.dim}─────────────────────────────${colors.reset}
392
+ ${colors.cyan}/analyze${colors.reset} [patient] Analyze patient data
393
+ ${colors.cyan}/plan${colors.reset} [patient] Design treatment plan
394
+ ${colors.cyan}/discover${colors.reset} [gene] Drug target discovery
395
+ ${colors.cyan}/demo${colors.reset} Run framework demo
396
+ ${colors.cyan}/model${colors.reset} Show AI model info
397
+ ${colors.cyan}/clear${colors.reset} Clear conversation
398
+ ${colors.cyan}/help${colors.reset} Show this help
399
+ ${colors.cyan}/exit${colors.reset} Exit
400
+
401
+ ${colors.bold}AI Chat${colors.reset}
402
+ ${colors.dim}─────────────────────────────${colors.reset}
403
+ Just type naturally to chat with the AI oncologist:
404
+
405
+ "What are the treatment options for EGFR+ lung cancer?"
406
+ "Explain pembrolizumab mechanism of action"
407
+ "What biomarkers predict response to immunotherapy?"
408
+ "Compare osimertinib vs erlotinib for EGFR mutations"
409
+ `);
410
+ }
411
+
143
412
  function printHelp(): void {
144
413
  console.log(`
145
- 🏥 AGI 癌症治疗框架 - 命令行工具
146
-
147
- 使用方法:
148
- agi [命令] [选项]
149
-
150
- 命令:
151
- --cancer-treatment, --medical 激活癌症治疗框架
152
- --analyze-patient 分析患者数据
153
- --treatment-plan 设计个性化治疗计划
154
- --drug-discovery AI驱动的药物靶点发现
155
- --demo 完整框架演示
156
- --help, -h 显示此帮助信息
157
- --version, -v 显示版本信息
158
-
159
- 选项:
160
- --patient=<id> 患者ID (默认: P001)
161
- --protocol=<id> 治疗协议ID
162
- --genomics 包含基因组数据分析
163
- --target=<gene> 目标基因 (默认: EGFR)
164
- --cancer=<type> 癌症类型 (默认: Lung)
165
-
166
- 示例:
167
- agi --cancer-treatment
168
- agi --analyze-patient --patient=P001 --genomics
169
- agi --treatment-plan --patient=P001 --protocol=nccn-breast-early
170
- agi --drug-discovery --target=EGFR --cancer=Lung
171
- agi --demo
172
-
173
- 📞 技术支持: medical-support@agi-cancer-treatment.org
174
- 📚 文档: 查看项目目录中的 README.md
414
+ ${colors.bold}Cure - AI Cancer Treatment Framework${colors.reset}
415
+ Powered by xAI ${XAI_MODEL}
416
+
417
+ ${colors.bold}Usage:${colors.reset}
418
+ cure Launch interactive AI chat
419
+ cure [command] Run a specific command
420
+
421
+ ${colors.bold}Commands:${colors.reset}
422
+ --analyze-patient Analyze patient data
423
+ --treatment-plan Design treatment plan
424
+ --drug-discovery Drug target discovery
425
+ --demo Run framework demo
426
+ --help, -h Show this help
427
+ --version, -v Show version
428
+
429
+ ${colors.bold}Options:${colors.reset}
430
+ --patient=<id> Patient ID (default: P001)
431
+ --protocol=<id> Treatment protocol
432
+ --genomics Include genomic analysis
433
+ --target=<gene> Target gene (default: EGFR)
434
+ --cancer=<type> Cancer type (default: Lung)
435
+
436
+ ${colors.bold}Environment:${colors.reset}
437
+ XAI_API_KEY xAI API key for AI-powered responses
438
+
439
+ ${colors.bold}Examples:${colors.reset}
440
+ cure
441
+ cure --analyze-patient --patient=P001 --genomics
442
+ cure --drug-discovery --target=BRAF --cancer=Melanoma
443
+
444
+ ${colors.dim}https://npmjs.com/package/@erosolaraijs/cure${colors.reset}
175
445
  `);
176
446
  }
177
447
 
178
- // Run main function
179
448
  main().catch((error) => {
180
- console.error('应用程序错误:', error);
449
+ console.error(`${colors.red}Error:${colors.reset}`, error);
181
450
  process.exit(1);
182
- });
451
+ });