MCPcopy
hub / github.com/codeceptjs/CodeceptJS / parseInput

Function parseInput

lib/pause.js:118–231  ·  view source on GitHub ↗
(cmd)

Source from the content-addressed store, hash-verified

116}
117
118async function parseInput(cmd) {
119 rl.pause()
120 next = false
121 recorder.session.start('pause')
122 if (cmd === '') next = true
123 if (!cmd || cmd === 'resume' || cmd === 'exit') {
124 if (typeof finish === 'function') finish()
125 recorder.session.restore('pause')
126 pauseSessionOpen = false
127 rl.close()
128 history.save()
129 return nextStep()
130 }
131 for (const k of Object.keys(registeredVariables)) {
132 eval(`var ${k} = registeredVariables['${k}'];`)
133 }
134
135 let executeCommand = Promise.resolve()
136
137 const getCmd = () => {
138 debug('Command:', cmd)
139 return cmd
140 }
141
142 let isCustomCommand = false
143 let lastError = null
144 let isAiCommand = false
145 let $res
146 try {
147 const locate = global.locate // enable locate in this context
148
149 const I = container.support('I')
150 if (cmd.trim().startsWith('=>')) {
151 isCustomCommand = true
152 cmd = cmd.trim().substring(2, cmd.length)
153 } else if (aiAssistant.isEnabled && cmd.trim() && !cmd.match(/^\w+\(/) && cmd.includes(' ')) {
154 const currentOutputLevel = output.level()
155 output.level(0)
156 const res = I.grabSource()
157 isAiCommand = true
158 executeCommand = executeCommand.then(async () => {
159 try {
160 const html = await res
161 await aiAssistant.setHtmlContext(html)
162 } catch (err) {
163 output.print(output.styles.error(' ERROR '), "Can't get HTML context", err.stack)
164 return
165 } finally {
166 output.level(currentOutputLevel)
167 }
168
169 const spinner = ora('Processing AI request...').start()
170 cmd = await aiAssistant.writeSteps(cmd)
171 spinner.stop()
172 output.print('')
173 output.print(colors.blue(aiAssistant.getResponse()))
174 output.print('')
175 return cmd

Callers

nothing calls this directly

Calls 15

getCmdFunction · 0.85
debugFunction · 0.85
supportMethod · 0.80
includesMethod · 0.80
setHtmlContextMethod · 0.80
writeStepsMethod · 0.80
stopMethod · 0.80
getResponseMethod · 0.80
logMethod · 0.80
debugMethod · 0.80
pushMethod · 0.80
popMethod · 0.80

Tested by

no test coverage detected