-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (61 loc) · 1.79 KB
/
index.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* This is the command line interface for the swarm orchestration system. It handles map the command line arguments and
* interactions back and forth with the user. The actual logic is handled by the API object and the rest of the code in
* src/.
*/
import {program} from 'commander'
import {initialize} from '@aiswarm/orchestrator'
/**
* Parses the arguments to the command line interface and starts the swarm orchestration system.
* Supports multiple flags e.g. for debugging purposes.
*/
async function start() {
program
.option(
// noinspection ALL
'-c, --config <path>',
'Path to the configuration file or directory. Defaults to ./config.'
)
.option(
'-d, --debug',
'Enable debug mode. Shows more information in the logs.'
)
.option(
'-v, --verbose',
'Enable verbose mode. Warning: This can get spammy and might leak secrets.'
)
.option('-h, --help', 'Print this help messageInput.')
.allowUnknownOption(true)
.showHelpAfterError(true)
.parse(process.argv)
program.addHelpText(
'after',
`
Optional Commands:
run <instructions> Run the AI swarm orchestrator with the given initial instruction.
`
)
const options = program.opts()
options.help && program.help()
let loglevel = 'info'
options.debug && (loglevel = 'debug')
options.verbose && (loglevel = 'trace')
const [command, prompt] = program.args
switch (command.trim()) {
case undefined:
case null:
case false:
case '':
case 'undefined':
await initialize(options.config, loglevel)
break
case 'run':
await (await initialize(options.config, loglevel)).run(prompt)
break
default:
// eslint-disable-next-line no-console
console.error('Unknown command', command)
process.exit(1)
}
}
await start()