UNPKG

@convo-lang/convo-lang-cli

Version:
134 lines 4.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("@iyio/common"); const node_common_1 = require("@iyio/node-common"); const promises_1 = require("node:fs/promises"); const ConvoCli_js_1 = require("../lib/ConvoCli.js"); const convo_interface_converter_js_1 = require("../lib/convo-interface-converter.js"); const create_next_app_js_1 = require("../lib/create-next-app.js"); const args = (0, common_1.parseCliArgsT)({ args: process.argv, startIndex: 2, defaultKey: 'source', restKey: 'spawn', flags: [ 'parse', 'convert', 'bufferOutput', 'cmdMode', 'repl', 'stdin', 'syncWatch', 'printState', 'printFlat', 'printMessages', 'prefixOutput', 'createNextApp', 'listModels', 'make', 'makeTargets', ], converter: { source: args => args[0], inline: args => args[0], config: args => args[0], inlineConfig: args => args[0], sourcePath: args => args[0], out: args => args[0], parse: args => args.length ? true : false, convert: args => args.length ? true : false, parseFormat: args => (0, common_1.safeParseNumberOrUndefined)(args[0]), bufferOutput: args => args.length ? true : false, cmdMode: args => args.length ? true : false, repl: args => args.length ? true : false, stdin: args => args.length ? true : false, allowExec: args => args[0], prepend: args => args[0], exeCwd: args => args[0], syncTsConfig: args => args, syncWatch: args => args.length ? true : false, syncOut: args => args[0], spawn: args => args.join(' '), spawnDir: args => args[0], printState: args => args.length ? true : false, printFlat: args => args.length ? true : false, printMessages: args => args.length ? true : false, prefixOutput: args => args.length ? true : false, createAppDir: args => args[0], createNextApp: args => args.length ? true : false, createAppWorkingDir: args => args[0], listModels: args => args.length ? true : false, make: args => args.length ? true : false, makeTargets: args => args.length ? true : false, var: args => args, vars: args => args, varsPath: args => args, } }).parsed; const main = async () => { const cancel = new common_1.CancelToken(); let done = false; let shutdownIv; process.on('SIGINT', () => { (0, node_common_1.stopReadingStdIn)(); console.log("Stopping Convo-Lang"); cancel.cancelNow(); shutdownIv = setTimeout(() => { if (!done) { console.warn('Killing server. Shutdown took too long'); process.exit(); } }, 3000); }); process.on('unhandledRejection', (reason, promise) => { console.error('Unhandled Rejection at:', promise, 'reason:', reason); process.exit(1); }); process.on('uncaughtException', (ex, origin) => { console.error('Unhandled Exception', ex, 'origin', origin); process.exit(1); }); args.exeCwd = (0, common_1.normalizePath)(args.exeCwd ? await (0, promises_1.realpath)(args.exeCwd) : globalThis.process.cwd()); let toolPromises = []; if (!(0, common_1.getObjKeyCount)(args)) { args.repl = true; } if (args.syncTsConfig?.length) { toolPromises.push((0, convo_interface_converter_js_1.convertConvoInterfacesAsync)(args, cancel)); } if (args.createNextApp) { toolPromises.push((0, create_next_app_js_1.createNextAppAsync)(args, cancel)); } if (args.spawn) { toolPromises.push((0, node_common_1.spawnAsync)({ cmd: args.spawn, cwd: args.spawnDir, cancel, })); } await Promise.all(toolPromises); if (!toolPromises.length) { const cli = await (0, ConvoCli_js_1.createConvoCliAsync)(args); try { if (args.listModels) { const models = await cli.convo.getAllModelsAsync(); console.log(JSON.stringify(models, null, 4)); } else { await cli.executeAsync(cancel); } } catch (ex) { console.error('convo execution failed', ex); process.exit(1); } finally { cli.dispose(); } } (0, node_common_1.stopReadingStdIn)(); clearTimeout(shutdownIv); done = true; }; main(); //# sourceMappingURL=convo.js.map