MCPcopy Create free account
hub / github.com/chieapp/chie / cliMain

Function cliMain

src/cli-main.ts:17–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15cliMain();
16
17async function cliMain() {
18 config.addItem('apis', apiManager);
19
20 // The CLI interface is stateless.
21 config.inMemory = true;
22 config.initFromFileSync();
23
24 extensionManager.activateBuiltinExtensions();
25
26 let credentialName;
27 for (let i = 2; i < process.argv.length; ++i) {
28 const arg = process.argv[i];
29 if (arg == '-h')
30 help();
31 if (arg == '-l')
32 list();
33 if (arg == '--credential')
34 credentialName = process.argv[i + 1];
35 }
36
37 // Find an credential that supports chat service.
38 const credential = apiManager.getCredentials()
39 // Only search from chatable credentials.
40 .filter(credential => {
41 try {
42 const {apiClass} = apiManager.getAPIRecord(credential.type);
43 return matchClass(ChatCompletionAPI, apiClass) ||
44 matchClass(ChatConversationAPI, apiClass);
45 } catch (error) {
46 if (error.message.includes('not exist'))
47 return false;
48 else
49 throw error;
50 }
51 })
52 // Return the one matches name.
53 .find(credential => credentialName ? credential.name == credentialName : true);
54 if (!credential)
55 throw new Error('Can not find an API credential that supports chatting.');
56
57 // Chat and exit.
58 await enterConversation(credential);
59 process.exit(0);
60}
61
62function help() {
63 console.log(`

Callers 1

cli-main.tsFile · 0.85

Calls 9

matchClassFunction · 0.90
helpFunction · 0.85
listFunction · 0.85
enterConversationFunction · 0.85
addItemMethod · 0.80
initFromFileSyncMethod · 0.80
getCredentialsMethod · 0.80
getAPIRecordMethod · 0.80

Tested by

no test coverage detected