UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

111 lines 4.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const schema_1 = require("@sprucelabs/schema"); const AbstractAction_1 = __importDefault(require("../../AbstractAction")); const optionsSchema = (0, schema_1.buildSchema)({ id: 'testConversationOptions', description: 'Test your conversation topics.', fields: { shouldReturnImmediately: { type: 'boolean', isPrivate: true, }, shouldRunSilently: { type: 'boolean', isPrivate: true, }, }, }); class TestAction extends AbstractAction_1.default { optionsSchema = optionsSchema; commandAliases = ['test.conversation', 'chat']; invocationMessage = "Let's test talking about topics... 🎙"; killHandler; async execute(options) { const { shouldReturnImmediately, shouldRunSilently } = this.validateAndNormalizeOptions(options); this.ui.startLoading('Booting skill...'); try { const command = this.Service('command'); let isWriting = false; const promise = new Promise((resolve, reject) => { command .execute('yarn boot.local', { spawnOptions: shouldRunSilently ? undefined : { stdio: [process.stdin, 'pipe', 'pipe'], }, onData: shouldRunSilently ? undefined : async (data) => { if (!isWriting) { isWriting = data.search(':: Skill booted') > -1; if (isWriting) { this.ui.clear(); this.ui.stopLoading(); process.stdout?.write('? Send your first message to kick-off the conversation: '); } } else if (isWriting) { process.stdout?.write(data.replace('Skill :: Skill booted', '')); } }, onError: (data) => { if (!data.includes('warning package.json')) { // const err = new SpruceError({ // friendlyMessage: // `Testing conversations failed because of the following error:\n\n` + // data, // code: 'EXECUTING_COMMAND_FAILED', // cmd: 'ACTION=test.conversation yarn.boot.local', // stderr: data, // }) // reject(err) } }, env: { ACTION: 'test.conversation', }, }) .then(resolve) .catch(reject); }); this.killHandler = command.kill.bind(command); if (shouldReturnImmediately) { return { meta: { kill: this.killHandler, pid: command.pid(), promise, }, }; } else { await promise; } } catch (err) { if (err.options?.stderr?.includes('SIGINT') || err.options?.code === 'CONVERSATION_ABORTED') { return { summaryLines: ['Conversation terminated. ✌️'], }; } return { errors: [err], }; } return { summaryLines: ['Talk soon! 👋'], }; } async kill() { this.killHandler?.(); } } exports.default = TestAction; //# sourceMappingURL=TestAction.js.map