mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Migrate objective extension settings to chat_metadata
This commit is contained in:
@ -1,10 +1,9 @@
|
||||
import { callPopup, extension_prompt_types } from "../../../script.js";
|
||||
import { chat_metadata } from "../../../script.js";
|
||||
import { getContext, extension_settings } from "../../extensions.js";
|
||||
import {
|
||||
substituteParams,
|
||||
eventSource,
|
||||
event_types,
|
||||
saveSettingsDebounced
|
||||
} from "../../../script.js";
|
||||
|
||||
const MODULE_NAME = "Objective"
|
||||
@ -97,6 +96,7 @@ function completeTask(task) {
|
||||
async function generateTasks() {
|
||||
const prompt = substituteParams(objectivePrompts["createTask"].replace(/{{objective}}/gi, globalObjective));
|
||||
console.log(`Generating tasks for objective with prompt`)
|
||||
toastr.info('Generating tasks for objective', 'Please wait...');
|
||||
const taskResponse = await generateQuietPrompt(prompt)
|
||||
globalTasks = []
|
||||
const numberedListPattern = /^\d+\./
|
||||
@ -109,6 +109,7 @@ async function generateTasks() {
|
||||
}
|
||||
updateUiTaskList()
|
||||
console.info(`Response for Objective: '${globalObjective}' was \n'${taskResponse}', \nwhich created tasks \n${JSON.stringify(globalTasks, null, 2)} `)
|
||||
toastr.success(`Generated ${globalTasks.length} tasks`, 'Done!');
|
||||
}
|
||||
|
||||
// Call Quiet Generate to check if a task is completed
|
||||
@ -186,15 +187,21 @@ function resetState(){
|
||||
|
||||
//
|
||||
function saveState() {
|
||||
const context = getContext();
|
||||
|
||||
if (currentChatId == "") {
|
||||
currentChatId = getContext().chatId
|
||||
currentChatId = context.chatId
|
||||
}
|
||||
extension_settings.objective[currentChatId].objective = globalObjective
|
||||
extension_settings.objective[currentChatId].tasks = globalTasks
|
||||
extension_settings.objective[currentChatId].checkFrequency = $('#objective-check-frequency').val()
|
||||
extension_settings.objective[currentChatId].chatDepth = $('#objective-chat-depth').val()
|
||||
extension_settings.objective[currentChatId].hideTasks = $('#objective-hide-tasks').prop('checked')
|
||||
saveSettingsDebounced()
|
||||
|
||||
chat_metadata['objective'] = {
|
||||
objective: globalObjective,
|
||||
tasks: globalTasks,
|
||||
checkFrequency: $('#objective-check-frequency').val(),
|
||||
chatDepth: $('#objective-chat-depth').val(),
|
||||
hideTasks: $('#objective-hide-tasks').prop('checked'),
|
||||
}
|
||||
|
||||
context.saveMetadata();
|
||||
}
|
||||
|
||||
// Dump core state
|
||||
@ -205,7 +212,7 @@ function debugObjectiveExtension(){
|
||||
"checkCounter": checkCounter,
|
||||
"globalObjective": globalObjective,
|
||||
"globalTasks": globalTasks,
|
||||
"extension_settings": extension_settings.objective[currentChatId],
|
||||
"extension_settings": chat_metadata['objective'],
|
||||
}, null, 2))
|
||||
}
|
||||
|
||||
@ -281,23 +288,29 @@ function loadSettings() {
|
||||
if (currentChatId == undefined) {
|
||||
return
|
||||
}
|
||||
if (!(currentChatId in extension_settings.objective)) {
|
||||
extension_settings.objective[currentChatId] = {}
|
||||
Object.assign(extension_settings.objective[currentChatId], defaultSettings)
|
||||
|
||||
// Migrate existing settings
|
||||
if (currentChatId in extension_settings.objective) {
|
||||
chat_metadata['objective'] = extension_settings.objective[currentChatId];
|
||||
delete extension_settings.objective[currentChatId];
|
||||
}
|
||||
|
||||
if (!('objective' in chat_metadata)) {
|
||||
Object.assign(chat_metadata, { objective: defaultSettings });
|
||||
}
|
||||
|
||||
// Update globals
|
||||
globalObjective = extension_settings.objective[currentChatId].objective
|
||||
globalTasks = extension_settings.objective[currentChatId].tasks
|
||||
checkCounter = extension_settings.objective[currentChatId].checkFrequency
|
||||
globalObjective = chat_metadata['objective'].objective
|
||||
globalTasks = chat_metadata['objective'].tasks
|
||||
checkCounter = chat_metadata['objective'].checkFrequency
|
||||
|
||||
// Update UI elements
|
||||
$('#objective-counter').text(checkCounter)
|
||||
$("#objective-text").text(globalObjective)
|
||||
updateUiTaskList()
|
||||
$('#objective-chat-depth').val(extension_settings.objective[currentChatId].chatDepth)
|
||||
$('#objective-check-frequency').val(extension_settings.objective[currentChatId].checkFrequency)
|
||||
$('#objective-hide-tasks').prop('checked',extension_settings.objective[currentChatId].hideTasks)
|
||||
$('#objective-chat-depth').val(chat_metadata['objective'].chatDepth)
|
||||
$('#objective-check-frequency').val(chat_metadata['objective'].checkFrequency)
|
||||
$('#objective-hide-tasks').prop('checked', chat_metadata['objective'].hideTasks)
|
||||
onHideTasksInput()
|
||||
setCurrentTask()
|
||||
}
|
||||
@ -313,14 +326,24 @@ jQuery(() => {
|
||||
<div class="inline-drawer-content">
|
||||
<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>
|
||||
<label class="checkbox_label"><input id="objective-generate" class="menu_button" type="submit" value="Generate Tasks" />
|
||||
<small>Automatically generate tasks for Objective. Takes a moment.</small></label></br>
|
||||
<div class="objective_block">
|
||||
<input id="objective-generate" class="menu_button" type="submit" value="Generate Tasks" />
|
||||
<small>Automatically generate tasks for Objective. Takes a moment.</small>
|
||||
</div>
|
||||
</br>
|
||||
<label class="checkbox_label"><input id="objective-hide-tasks" type="checkbox"> Hide Tasks</label><br>
|
||||
<div id="objective-tasks"> </div>
|
||||
<div class="objective_block">
|
||||
<div class="objective_block objective_block_control flex1">
|
||||
<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" />
|
||||
</div>
|
||||
<div class="objective_block objective_block_control flex1">
|
||||
<label for="objective-check-frequency">Task Check Frequency</label>
|
||||
<input id="objective-check-frequency" class="text_pole widthUnset" type="number" min="" max="99" /><small> (0 = disabled) </small><br>
|
||||
<input id="objective-check-frequency" class="text_pole widthUnset" type="number" min="0" max="99" />
|
||||
<small>(0 = disabled)</small>
|
||||
</div>
|
||||
</div>
|
||||
<span> Messages until next AI task completion check <span id="objective-counter">0</span></span>
|
||||
<hr class="sysHR">
|
||||
</div>
|
||||
|
@ -2,3 +2,15 @@
|
||||
font-weight: 600;
|
||||
color: orange;
|
||||
}
|
||||
|
||||
.objective_block {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
column-gap: 10px;
|
||||
}
|
||||
|
||||
.objective_block_control small,
|
||||
.objective_block_control label {
|
||||
width: max-content;
|
||||
}
|
||||
|
Reference in New Issue
Block a user