mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add some instructions. Code readability
This commit is contained in:
parent
e68dd96f24
commit
bdcb3e52ff
@ -136,36 +136,33 @@ async function checkTaskCompleted() {
|
|||||||
} else {
|
} else {
|
||||||
console.debug(`Checked task completion. taskResponse: ${taskResponse}`)
|
console.debug(`Checked task completion. taskResponse: ${taskResponse}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set a task in extensionPrompt context. Defaults to first incomplete
|
// Set a task in extensionPrompt context. Defaults to first incomplete
|
||||||
function setCurrentTask(index=null) {
|
function setCurrentTask(index = null) {
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
currentTask = {}
|
let currentTask = {};
|
||||||
|
|
||||||
// Default to selecting first incomplete task if not given index, else no task
|
if (index === null) {
|
||||||
if (index==null){
|
currentTask = globalTasks.find(task => !task.completed) || {};
|
||||||
currentTask = globalTasks.find(task=>{return true? !task.completed: false})
|
} else if (index >= 0 && index < globalTasks.length) {
|
||||||
if (currentTask == undefined){
|
currentTask = globalTasks[index];
|
||||||
currentTask = {}
|
|
||||||
}
|
|
||||||
} else if (index < globalTasks.length && index > 0){
|
|
||||||
currentTask = globalTasks[index]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject task into extension prompt context
|
const { description } = currentTask;
|
||||||
if (Object.keys(currentTask).length > 0){
|
const injectPromptsTask = injectPrompts["task"].replace(/{{task}}/gi, description);
|
||||||
context.setExtensionPrompt(
|
|
||||||
MODULE_NAME, injectPrompts["task"].replace(/{{task}}/gi, currentTask.description), 1, $('#objective-chat-depth').val()
|
if (description) {
|
||||||
);
|
context.setExtensionPrompt(MODULE_NAME, injectPromptsTask, 1, $('#objective-chat-depth').val());
|
||||||
console.info(`Current task in context.extensionPrompts.Objective is ${JSON.stringify(context.extensionPrompts.Objective)}`)
|
console.info(`Current task in context.extensionPrompts.Objective is ${JSON.stringify(context.extensionPrompts.Objective)}`);
|
||||||
} else {
|
} else {
|
||||||
context.setExtensionPrompt(MODULE_NAME,'')
|
context.setExtensionPrompt(MODULE_NAME, '');
|
||||||
console.info(`No current task`)
|
console.info(`No current task`);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveState();
|
||||||
}
|
}
|
||||||
saveState()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -188,6 +185,9 @@ function resetState(){
|
|||||||
|
|
||||||
//
|
//
|
||||||
function saveState(){
|
function saveState(){
|
||||||
|
if (currentChatId == ""){
|
||||||
|
currentChatId = getContext().chatId
|
||||||
|
}
|
||||||
extension_settings.objective[currentChatId].objective = globalObjective
|
extension_settings.objective[currentChatId].objective = globalObjective
|
||||||
extension_settings.objective[currentChatId].tasks = globalTasks
|
extension_settings.objective[currentChatId].tasks = globalTasks
|
||||||
extension_settings.objective[currentChatId].checkFrequency = $('#objective-check-frequency').val()
|
extension_settings.objective[currentChatId].checkFrequency = $('#objective-check-frequency').val()
|
||||||
@ -211,42 +211,30 @@ window.debugObjectiveExtension = debugObjectiveExtension
|
|||||||
|
|
||||||
|
|
||||||
// Add a single task to the UI and attach event listeners for user edits
|
// Add a single task to the UI and attach event listeners for user edits
|
||||||
function addUiTask(taskIndex, taskComplete, taskDescription){
|
function addUiTask(taskIndex, taskComplete, taskDescription) {
|
||||||
let template = `
|
const template = `
|
||||||
<div id={{task_label_id}} class="flex1 checkbox_label">
|
<div id="objective-task-label-${taskIndex}" class="flex1 checkbox_label">
|
||||||
<span>{{task_index}}</span>
|
<span>${taskIndex}</span>
|
||||||
<input id="{{task_complete_id}}" type="checkbox">
|
<input id="objective-task-complete-${taskIndex}" type="checkbox">
|
||||||
<span id="{{task_description_id}}" contenteditable>{{task_description}}</span>
|
<span class="text_pole" style="display: block" id="objective-task-description-${taskIndex}" contenteditable>${taskDescription}</span>
|
||||||
</div><br>
|
</div><br>
|
||||||
`
|
`;
|
||||||
|
|
||||||
// Define id values
|
|
||||||
const taskLabelId = `objective-task-label-${taskIndex}`
|
|
||||||
const taskCompleteId = `objective-task-complete-${taskIndex}`
|
|
||||||
const taskDescriptionId = `objective-task-description-${taskIndex}`
|
|
||||||
|
|
||||||
// Assign id values and populate current state
|
|
||||||
template = template.replace(/{{task_index}}/gi,taskIndex)
|
|
||||||
template = template.replace(/{{task_description}}/gi,taskDescription)
|
|
||||||
template = template.replace(/{{task_label_id}}/gi,taskLabelId)
|
|
||||||
template = template.replace(/{{task_complete_id}}/gi,taskCompleteId)
|
|
||||||
template = template.replace(/{{task_description_id}}/gi,taskDescriptionId)
|
|
||||||
|
|
||||||
// Add the filled out template
|
// Add the filled out template
|
||||||
$('#objective-tasks').append(template)
|
$('#objective-tasks').append(template);
|
||||||
|
|
||||||
// Add event listeners and set properties
|
// Add event listeners and set properties
|
||||||
$(`#${taskCompleteId}`).prop('checked',taskComplete)
|
$(`#objective-task-complete-${taskIndex}`).prop('checked', taskComplete);
|
||||||
$(`#${taskCompleteId}`).on('click', event => {
|
$(`#objective-task-complete-${taskIndex}`).on('click', event => {
|
||||||
const index = Number(event.target.id[event.target.id.length - 1])
|
const index = Number(event.target.id.split('-').pop());
|
||||||
globalTasks[index].completed = event.target.checked
|
globalTasks[index].completed = event.target.checked;
|
||||||
setCurrentTask()
|
setCurrentTask();
|
||||||
});
|
});
|
||||||
$(`#${taskDescriptionId}`).on('keyup', event => {
|
$(`#objective-task-description-${taskIndex}`).on('keyup', event => {
|
||||||
const index = Number(event.target.id[event.target.id.length - 1])
|
const index = Number(event.target.id.split('-').pop());
|
||||||
globalTasks[index].description = event.target.textContent
|
globalTasks[index].description = event.target.textContent;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate UI task list
|
// Populate UI task list
|
||||||
function updateUiTaskList() {
|
function updateUiTaskList() {
|
||||||
@ -269,18 +257,12 @@ async function onGenerateObjectiveClick() {
|
|||||||
|
|
||||||
// Update extension prompts
|
// Update extension prompts
|
||||||
function onChatDepthInput() {
|
function onChatDepthInput() {
|
||||||
if (currentChatId == ""){
|
|
||||||
currentChatId = getContext().chatId
|
|
||||||
}
|
|
||||||
saveState()
|
saveState()
|
||||||
setCurrentTask() // Ensure extension prompt is updated
|
setCurrentTask() // Ensure extension prompt is updated
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update how often we check for task completion
|
// Update how often we check for task completion
|
||||||
function onCheckFrequencyInput() {
|
function onCheckFrequencyInput() {
|
||||||
if (currentChatId == ""){
|
|
||||||
currentChatId = getContext().chatId
|
|
||||||
}
|
|
||||||
saveState()
|
saveState()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,15 +302,17 @@ jQuery(() => {
|
|||||||
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
|
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="inline-drawer-content">
|
<div class="inline-drawer-content">
|
||||||
<label for="objective-text">Objective</label>
|
<label for="objective-text"><small>Enter an objective and generate tasks. The AI will attempt to complete tasks autonomously</small></label>
|
||||||
<textarea id="objective-text" type="text" class="text_pole textarea_compact" rows="4"></textarea>
|
<textarea id="objective-text" type="text" class="text_pole textarea_compact" rows="4"></textarea>
|
||||||
<input id="objective-generate" class="menu_button" type="submit" value="Generate Tasks" />
|
<input id="objective-generate" class="menu_button" type="submit" value="Generate Tasks" />
|
||||||
|
<small>Automatically generate tasks for an objective. Will take a moment and populate tasks below</small>
|
||||||
<div id="objective-tasks"> </div>
|
<div id="objective-tasks"> </div>
|
||||||
<label for="objective-chat-depth">In-chat @ Depth</label>
|
<label for="objective-chat-depth">In-chat @ Depth</label>
|
||||||
<input id="objective-chat-depth" class="text_pole widthUnset" type="number" min="0" max="99" /><br>
|
<input id="objective-chat-depth" class="text_pole widthUnset" type="number" min="0" max="99" /><br>
|
||||||
<label for="objective-check-frequency">Task Check Frequency</label>
|
<label for="objective-check-frequency">Task Check Frequency</label>
|
||||||
<input id="objective-check-frequency" class="text_pole widthUnset" type="number" min="1" max="99" /><br>
|
<input id="objective-check-frequency" class="text_pole widthUnset" type="number" min="" max="99" /><br>
|
||||||
<span> Messages until next task completion check <span id="objective-counter">0</span></span>
|
<span> Messages until next AI task completion check <span id="objective-counter">0</span></span> <small> 0 to disable auto completion checks </small>
|
||||||
|
<hr class="sysHR">
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
@ -346,8 +330,10 @@ jQuery(() => {
|
|||||||
if (currentChatId == undefined){
|
if (currentChatId == undefined){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if ($("#objective-check-frequency").val() > 0) {
|
||||||
checkTaskCompleted();
|
checkTaskCompleted();
|
||||||
checkCounter -= 1
|
checkCounter -= 1
|
||||||
|
}
|
||||||
setCurrentTask();
|
setCurrentTask();
|
||||||
$('#objective-counter').text(checkCounter)
|
$('#objective-counter').text(checkCounter)
|
||||||
});
|
});
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
color: orange;
|
color: orange;
|
||||||
}
|
}
|
||||||
|
|
||||||
[id^='objective-task-label-'] {
|
/* [id^='objective-task-label-'] {
|
||||||
border: 1px solid var(--white30a);
|
border: 1px solid var(--white30a);
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
padding: 7px;
|
padding: 7px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
} */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user