Skip to content

Commit 6b1c93e

Browse files
Cancel request
1 parent 56c2cdf commit 6b1c93e

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

bin/web/views/index.ejs

+35-35
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ ${fields}
269269
document.querySelector(".loading").classList.add("hidden")
270270
}
271271
}
272+
const promptSelect = document.getElementById('prompt-select');
273+
const resetButton = document.querySelector("#prompt-reset")
272274
document.querySelector("form").addEventListener("input", (e) => {
273275
if (e.target.tagName === "SELECT") {
274276
config[e.target.name] = config.models[e.target.selectedIndex]
@@ -290,7 +292,7 @@ ${fields}
290292
socket.emit('request', config)
291293
config.id = null
292294
loading(config.prompt)
293-
input.textContent = "";
295+
input.textContent = promptSelect.value;
294296
}
295297
});
296298
input.addEventListener("keydown", (e) => {
@@ -303,9 +305,40 @@ ${fields}
303305
}
304306
}
305307
})
308+
document.querySelector("#prompt-cancel").addEventListener("click", (e) => {
309+
e.preventDefault()
310+
e.stopPropagation()
311+
socket.emit("request", {
312+
prompt: "/stop"
313+
})
314+
document.querySelector("#prompt-run").classList.remove("hidden")
315+
document.querySelector("#prompt-cancel").classList.add("hidden")
316+
})
306317
307318
// Load prompts from files
308-
const promptSelect = document.getElementById('prompt-select');
319+
320+
// Update the input text with the selected prompt value
321+
const handlePromptChange = () => {
322+
const selectedPromptValue = promptSelect.value;
323+
const currentInputValue = input.textContent;
324+
325+
input.textContent = selectedPromptValue;
326+
327+
// Move the cursor to the first instance of ">PROMPT" and select only the word ">PROMPT"
328+
const promptIndex = input.textContent.indexOf('>PROMPT');
329+
if (promptIndex >= 0) {
330+
const range = document.createRange();
331+
const selection = window.getSelection();
332+
const promptEndIndex = promptIndex + ">PROMPT".length;
333+
range.setStart(input.childNodes[0], promptIndex);
334+
range.setEnd(input.childNodes[0], promptEndIndex);
335+
selection.removeAllRanges();
336+
selection.addRange(range);
337+
}
338+
339+
// Focus the input
340+
input.focus();
341+
}
309342
fetch('./prompts')
310343
.then(response => response.json())
311344
.then(prompts => {
@@ -329,40 +362,7 @@ ${fields}
329362
promptSelect.value = initialPrompt.value;
330363
input.textContent = initialPrompt.value;
331364
332-
// Update the input text with the selected prompt value
333-
const handlePromptChange = () => {
334-
const selectedPromptValue = promptSelect.value;
335-
const currentInputValue = input.textContent;
336-
337-
input.textContent = selectedPromptValue;
338-
339-
// Move the cursor to the first instance of ">PROMPT" and select only the word ">PROMPT"
340-
const promptIndex = input.textContent.indexOf('>PROMPT');
341-
if (promptIndex >= 0) {
342-
const range = document.createRange();
343-
const selection = window.getSelection();
344-
const promptEndIndex = promptIndex + ">PROMPT".length;
345-
range.setStart(input.childNodes[0], promptIndex);
346-
range.setEnd(input.childNodes[0], promptEndIndex);
347-
selection.removeAllRanges();
348-
selection.addRange(range);
349-
}
350-
351-
// Focus the input
352-
input.focus();
353-
}
354365
promptSelect.addEventListener('change', handlePromptChange);
355-
356-
/*
357-
// Create a Reset button
358-
const resetButton = document.createElement('button');
359-
resetButton.textContent = 'Reset';
360-
361-
// Append the Reset button to the same container as the dropdown
362-
promptSelect.parentNode.appendChild(resetButton);
363-
*/
364-
const resetButton = document.querySelector("#prompt-reset")
365-
366366
resetButton.addEventListener('click', (e) => {
367367
e.preventDefault() // Prevent form from submitting
368368
handlePromptChange()

cmds/stop.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = (app) => {
2-
console.log("stop---------------------")
32
app.ptyProcess.onData((data) => {
43
// nothing
54
})
6-
app.ptyProcess.write('\u0003')
5+
//app.ptyProcess.write('\u0003')
6+
app.ptyProcess.kill()
77
app.ptyProcess = null
88
}

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class Dalai {
197197
const mod = require(`./cmds/${req.prompt.slice(1)}`)
198198
if (mod) {
199199
mod(this)
200+
return
200201
}
201202
} catch (e) {
202203
console.log("require log", e)

0 commit comments

Comments
 (0)