-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
54 lines (42 loc) · 1.48 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import prompt from 'prompt-sync';
import { config } from 'dotenv';
import { Structura } from './src/structura/structura-core';
import { readFileSync } from 'fs';
config();
async function main() {
const {
2: filename,
3: interactiveFlag
} = process.argv;
const structura = new Structura();
// This checks for an edge case where the user might have typed `npx ts-node main.ts -i`
if (filename === '-i' || filename === '--interactive') {
// Will fix this command line parsing later
await interactiveMode();
return;
}
if (!((filename || '').trim())) {
throw new Error('No filename provided!');
}
const isInteractive = interactiveFlag === '--interactive' || interactiveFlag === '-i';
const program = readFileSync(filename, 'utf-8');
if (process.env.VERBOSE === 'true') {
console.log('> Program:', program);
console.log('> AI output:', await structura.execute(program));
console.log('> Token length:', structura.tokenLength);
} else {
console.log(await structura.execute(program, isInteractive));
}
if (isInteractive) {
await interactiveMode();
}
async function interactiveMode() {
let input;
let messageCounter = 1;
while (input = prompt()(`${messageCounter++}> You: `)) {
const response = await structura.execute(input, true);
console.log(`> AI: ${response}\n`);
}
}
}
main().catch(console.error);