fix structuredclone

This commit is contained in:
kwaroran
2024-10-25 18:11:00 +09:00
parent b3fddb814e
commit 0f6246bef6
28 changed files with 114 additions and 104 deletions

View File

@@ -229,7 +229,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
'personaPrompt':([] as OpenAIChat[])
}
let promptTemplate = structuredClone(db.promptTemplate)
let promptTemplate = safeStructuredClone(db.promptTemplate)
const usingPromptTemplate = !!promptTemplate
if(promptTemplate){
let hasPostEverything = false
@@ -466,7 +466,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
for(const card of template){
switch(card.type){
case 'persona':{
let pmt = structuredClone(unformated.personaPrompt)
let pmt = safeStructuredClone(unformated.personaPrompt)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content)
@@ -477,7 +477,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
break
}
case 'description':{
let pmt = structuredClone(unformated.description)
let pmt = safeStructuredClone(unformated.description)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content)
@@ -488,7 +488,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
break
}
case 'authornote':{
let pmt = structuredClone(unformated.authorNote)
let pmt = safeStructuredClone(unformated.authorNote)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content || card.defaultText || '')
@@ -883,7 +883,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
//make into one
let formated:OpenAIChat[] = []
const formatOrder = structuredClone(db.formatingOrder)
const formatOrder = safeStructuredClone(db.formatingOrder)
if(formatOrder){
formatOrder.push('postEverything')
}
@@ -927,7 +927,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
for(const card of template){
switch(card.type){
case 'persona':{
let pmt = structuredClone(unformated.personaPrompt)
let pmt = safeStructuredClone(unformated.personaPrompt)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content)
@@ -938,7 +938,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
break
}
case 'description':{
let pmt = structuredClone(unformated.description)
let pmt = safeStructuredClone(unformated.description)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content)
@@ -949,7 +949,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
break
}
case 'authornote':{
let pmt = structuredClone(unformated.authorNote)
let pmt = safeStructuredClone(unformated.authorNote)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content || card.defaultText || '')
@@ -1041,7 +1041,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
break
}
case 'memory':{
let pmt = structuredClone(memories)
let pmt = safeStructuredClone(memories)
if(card.innerFormat && pmt.length > 0){
for(let i=0;i<pmt.length;i++){
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content)

View File

@@ -214,7 +214,7 @@ export async function loadLoreBookV3Prompt(){
const characterLore = char.globalLore ?? []
const chatLore = char.chats[page].localLore ?? []
const moduleLorebook = getModuleLorebooks()
const fullLore = structuredClone(characterLore.concat(chatLore).concat(moduleLorebook))
const fullLore = safeStructuredClone(characterLore.concat(chatLore).concat(moduleLorebook))
const currentChat = char.chats[page].message
const loreDepth = char.loreSettings?.scanDepth ?? db.loreBookDepth
const loreToken = char.loreSettings?.tokenBudget ?? db.loreBookToken

View File

@@ -73,7 +73,7 @@ export async function supaMemory(
for(let j=0;j<HypaData.length;j++){
let i =0;
let countTokens = currentTokens
let countChats = structuredClone(chats)
let countChats = safeStructuredClone(chats)
while(true){
if(countChats.length === 0){
break

View File

@@ -44,7 +44,7 @@ export async function exportModule(module:RisuModule, arg:{
}
const assets = module.assets ?? []
module = structuredClone(module)
module = safeStructuredClone(module)
module.assets ??= []
module.assets = module.assets.map((asset) => {
return [asset[0], '', asset[2]] as [string,string,string]
@@ -360,7 +360,7 @@ export async function applyModule() {
return
}
const module = structuredClone(getModuleById(sel))
const module = safeStructuredClone(getModuleById(sel))
if (!module) {
return
}

View File

@@ -256,7 +256,7 @@ export const OobaParams = [
]
export function promptConvertion(files:{ name: string, content: string, type:string }[]){
let preset = structuredClone(presetTemplate)
let preset = safeStructuredClone(presetTemplate)
let instData = {
"system_prompt": "",
"input_sequence": "",

View File

@@ -179,7 +179,7 @@ export interface OpenAIChatExtra {
export async function requestChatDataMain(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
const db = getDatabase()
let formated = structuredClone(arg.formated)
let formated = safeStructuredClone(arg.formated)
let maxTokens = arg.maxTokens ??db.maxResponse
let temperature = arg.temperature ?? (db.temperature / 100)
let bias = arg.bias
@@ -245,7 +245,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
for(let i=0;i<formated.length;i++){
const m = formated[i]
if(m.multimodals && m.multimodals.length > 0 && m.role === 'user'){
let v:OpenAIChatExtra = structuredClone(m)
let v:OpenAIChatExtra = safeStructuredClone(m)
let contents:OpenAIContents[] = []
for(let j=0;j<m.multimodals.length;j++){
contents.push({

View File

@@ -231,7 +231,7 @@ export async function processScriptFull(char:character|groupChat|simpleCharacter
for (const script of scripts){
if(script.ableFlag && script.flag?.includes('<')){
const rregex = /<(.+?)>/g
const scriptData = structuredClone(script)
const scriptData = safeStructuredClone(script)
let order = 0
const actions:string[] = []
scriptData.flag = scriptData.flag?.replace(rregex, (v:string, p1:string) => {

View File

@@ -34,7 +34,7 @@ export const applyChatTemplate = (messages:OpenAIChat[], arg:{
if(!type){
throw new Error('Template type is not set')
}
let clonedMessages = structuredClone(messages)
let clonedMessages = safeStructuredClone(messages)
const template = type === 'jinja' ? (new Template(arg.custom ?? db.JinjaTemplate)) :(new Template(chatTemplates[type]))
let formatedMessages:{
"role": 'user'|'assistant'|'system',

View File

@@ -152,7 +152,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
manualName?: string
}){
arg.recursiveCount ??= 0
char = structuredClone(char)
char = safeStructuredClone(char)
let varChanged = false
let stopSending = arg.stopSending ?? false
const CharacterlowLevelAccess = char.lowLevelAccess ?? false
@@ -169,7 +169,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
}).concat(getModuleTriggers())
const db = getDatabase()
const defaultVariables = parseKeyValue(char.defaultVariables).concat(parseKeyValue(db.templateDefaultVariables))
let chat = structuredClone(arg.chat ?? char.chats[char.chatPage])
let chat = safeStructuredClone(arg.chat ?? char.chats[char.chatPage])
if((!triggers) || (triggers.length === 0)){
return null
}