Skip to content

Commit 2174c90

Browse files
committed
fix: rename file should before saveChatHistory
fix: interactive should display String as string feat: add shouldLoadChats
1 parent 0db3efa commit 2174c90

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/lib/run-script.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
256256
})
257257

258258
script = await AIScriptEx.loadFile(filename,
259-
{chatsDir: options.chatsDir},
259+
{
260+
chatsDir: options.chatsDir,
261+
shouldLoadChats: !options.newChat,
262+
},
260263
{
261264
ABORT_SEARCH_SCRIPTS_SIGNAL: aborter.signal,
262265
USER_ENV,
@@ -273,8 +276,8 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
273276
console.error('Load script error:',err)
274277
await shutdown('loadScriptError', 1)
275278
}
279+
276280
const chatsFilename = script.getChatsFilename()
277-
if ((options.newChat || options.backupChat) && chatsFilename) { renameOldFile(chatsFilename, options.backupChat) }
278281

279282
let isSilence = false
280283

@@ -376,6 +379,10 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
376379

377380
const saveChatHistory = async () => {
378381
if (chatsFilename) {
382+
if ((options.newChat || options.backupChat) && chatsFilename) {
383+
renameOldFile(chatsFilename, options.backupChat)
384+
}
385+
379386
await runtime.$saveChats(chatsFilename)
380387
}
381388
}
@@ -565,7 +572,7 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
565572
}
566573
}
567574
if (result) {
568-
const isString = typeof result === 'string'
575+
const isString = result instanceof String || typeof result === 'string'
569576
if (!isString) {
570577
result = ux.colorizeJson(result, {pretty: true, theme: options.theme?.json})
571578
}

0 commit comments

Comments
 (0)