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 { getContext, extension_settings } from "../../extensions.js";
|
||||||
import {
|
import {
|
||||||
substituteParams,
|
substituteParams,
|
||||||
eventSource,
|
eventSource,
|
||||||
event_types,
|
event_types,
|
||||||
saveSettingsDebounced
|
|
||||||
} from "../../../script.js";
|
} from "../../../script.js";
|
||||||
|
|
||||||
const MODULE_NAME = "Objective"
|
const MODULE_NAME = "Objective"
|
||||||
@ -97,6 +96,7 @@ function completeTask(task) {
|
|||||||
async function generateTasks() {
|
async function generateTasks() {
|
||||||
const prompt = substituteParams(objectivePrompts["createTask"].replace(/{{objective}}/gi, globalObjective));
|
const prompt = substituteParams(objectivePrompts["createTask"].replace(/{{objective}}/gi, globalObjective));
|
||||||
console.log(`Generating tasks for objective with prompt`)
|
console.log(`Generating tasks for objective with prompt`)
|
||||||
|
toastr.info('Generating tasks for objective', 'Please wait...');
|
||||||
const taskResponse = await generateQuietPrompt(prompt)
|
const taskResponse = await generateQuietPrompt(prompt)
|
||||||
globalTasks = []
|
globalTasks = []
|
||||||
const numberedListPattern = /^\d+\./
|
const numberedListPattern = /^\d+\./
|
||||||
@ -109,6 +109,7 @@ async function generateTasks() {
|
|||||||
}
|
}
|
||||||
updateUiTaskList()
|
updateUiTaskList()
|
||||||
console.info(`Response for Objective: '${globalObjective}' was \n'${taskResponse}', \nwhich created tasks \n${JSON.stringify(globalTasks, null, 2)} `)
|
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
|
// Call Quiet Generate to check if a task is completed
|
||||||
@ -186,15 +187,21 @@ function resetState(){
|
|||||||
|
|
||||||
//
|
//
|
||||||
function saveState() {
|
function saveState() {
|
||||||
|
const context = getContext();
|
||||||
|
|
||||||
if (currentChatId == "") {
|
if (currentChatId == "") {
|
||||||
currentChatId = getContext().chatId
|
currentChatId = context.chatId
|
||||||
}
|
}
|
||||||
extension_settings.objective[currentChatId].objective = globalObjective
|
|
||||||
extension_settings.objective[currentChatId].tasks = globalTasks
|
chat_metadata['objective'] = {
|
||||||
extension_settings.objective[currentChatId].checkFrequency = $('#objective-check-frequency').val()
|
objective: globalObjective,
|
||||||
extension_settings.objective[currentChatId].chatDepth = $('#objective-chat-depth').val()
|
tasks: globalTasks,
|
||||||
extension_settings.objective[currentChatId].hideTasks = $('#objective-hide-tasks').prop('checked')
|
checkFrequency: $('#objective-check-frequency').val(),
|
||||||
saveSettingsDebounced()
|
chatDepth: $('#objective-chat-depth').val(),
|
||||||
|
hideTasks: $('#objective-hide-tasks').prop('checked'),
|
||||||
|
}
|
||||||
|
|
||||||
|
context.saveMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump core state
|
// Dump core state
|
||||||
@ -205,7 +212,7 @@ function debugObjectiveExtension(){
|
|||||||
"checkCounter": checkCounter,
|
"checkCounter": checkCounter,
|
||||||
"globalObjective": globalObjective,
|
"globalObjective": globalObjective,
|
||||||
"globalTasks": globalTasks,
|
"globalTasks": globalTasks,
|
||||||
"extension_settings": extension_settings.objective[currentChatId],
|
"extension_settings": chat_metadata['objective'],
|
||||||
}, null, 2))
|
}, null, 2))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,23 +288,29 @@ function loadSettings() {
|
|||||||
if (currentChatId == undefined) {
|
if (currentChatId == undefined) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!(currentChatId in extension_settings.objective)) {
|
|
||||||
extension_settings.objective[currentChatId] = {}
|
// Migrate existing settings
|
||||||
Object.assign(extension_settings.objective[currentChatId], defaultSettings)
|
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
|
// Update globals
|
||||||
globalObjective = extension_settings.objective[currentChatId].objective
|
globalObjective = chat_metadata['objective'].objective
|
||||||
globalTasks = extension_settings.objective[currentChatId].tasks
|
globalTasks = chat_metadata['objective'].tasks
|
||||||
checkCounter = extension_settings.objective[currentChatId].checkFrequency
|
checkCounter = chat_metadata['objective'].checkFrequency
|
||||||
|
|
||||||
// Update UI elements
|
// Update UI elements
|
||||||
$('#objective-counter').text(checkCounter)
|
$('#objective-counter').text(checkCounter)
|
||||||
$("#objective-text").text(globalObjective)
|
$("#objective-text").text(globalObjective)
|
||||||
updateUiTaskList()
|
updateUiTaskList()
|
||||||
$('#objective-chat-depth').val(extension_settings.objective[currentChatId].chatDepth)
|
$('#objective-chat-depth').val(chat_metadata['objective'].chatDepth)
|
||||||
$('#objective-check-frequency').val(extension_settings.objective[currentChatId].checkFrequency)
|
$('#objective-check-frequency').val(chat_metadata['objective'].checkFrequency)
|
||||||
$('#objective-hide-tasks').prop('checked',extension_settings.objective[currentChatId].hideTasks)
|
$('#objective-hide-tasks').prop('checked', chat_metadata['objective'].hideTasks)
|
||||||
onHideTasksInput()
|
onHideTasksInput()
|
||||||
setCurrentTask()
|
setCurrentTask()
|
||||||
}
|
}
|
||||||
@ -313,14 +326,24 @@ jQuery(() => {
|
|||||||
<div class="inline-drawer-content">
|
<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>
|
<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>
|
||||||
<label class="checkbox_label"><input id="objective-generate" class="menu_button" type="submit" value="Generate Tasks" />
|
<div class="objective_block">
|
||||||
<small>Automatically generate tasks for Objective. Takes a moment.</small></label></br>
|
<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>
|
<label class="checkbox_label"><input id="objective-hide-tasks" type="checkbox"> Hide Tasks</label><br>
|
||||||
<div id="objective-tasks"> </div>
|
<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>
|
<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>
|
<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>
|
<span> Messages until next AI task completion check <span id="objective-counter">0</span></span>
|
||||||
<hr class="sysHR">
|
<hr class="sysHR">
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,3 +2,15 @@
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: orange;
|
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