@@ -7,7 +7,7 @@ import path from 'path'
7
7
import colors from 'ansi-colors'
8
8
// import cliSpinners from 'cli-spinners'
9
9
import _logUpdate from 'log-update'
10
- import { get as getByPath } from 'lodash-es'
10
+ import { get as getByPath , omitBy } from 'lodash-es'
11
11
import {
12
12
ConfigFile ,
13
13
countRegexMatches ,
@@ -170,6 +170,8 @@ function renameOldFile(filename: string, backupChat?: boolean) {
170
170
}
171
171
}
172
172
}
173
+
174
+ let hasInited = false
173
175
export async function runScript ( filename : string , options : IRunScriptOptions ) {
174
176
// initTools(options)
175
177
@@ -199,20 +201,27 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
199
201
200
202
let script
201
203
const aborter = new AbortController ( )
202
- process . once ( 'SIGINT' , ( ) => {
203
- aborter . abort ( )
204
- } )
204
+ if ( ! hasInited ) {
205
+ process . once ( 'SIGINT' , ( ) => {
206
+ aborter . abort ( )
207
+ } )
205
208
206
- process . once ( 'exit' , function ( ) {
207
- aborter . abort ( )
208
- } )
209
+ process . once ( 'exit' , function ( ) {
210
+ aborter . abort ( )
211
+ } )
212
+ }
209
213
210
214
try {
215
+ const USER_ENV = omitBy ( options , ( v , k ) => {
216
+ const vT = typeof v
217
+ return k ?. [ 0 ] === '_' || v == null || vT === 'function' || ( vT === 'object' && ! Array . isArray ( v ) ) || vT === 'symbol'
218
+ } )
219
+
211
220
script = await AIScriptEx . loadFile ( filename ,
212
221
{ chatsDir : options . chatsDir } ,
213
222
{
214
223
ABORT_SEARCH_SCRIPTS_SIGNAL : aborter . signal ,
215
- USER_ENV : options ,
224
+ USER_ENV ,
216
225
FUNC_SCOPE : {
217
226
expandPath : function ( path : string ) {
218
227
// for formatting
@@ -277,8 +286,11 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
277
286
console . log ( 'quit for interrupted.' )
278
287
process . exit ( 0 )
279
288
}
280
- process . once ( 'SIGINT' , interrupted )
281
- process . once ( 'beforeExit' , saveChatHistory )
289
+
290
+ if ( ! hasInited ) {
291
+ process . once ( 'SIGINT' , interrupted )
292
+ process . once ( 'beforeExit' , saveChatHistory )
293
+ }
282
294
283
295
let llmLastContent = ''
284
296
let retryCount = 0
@@ -330,6 +342,8 @@ export async function runScript(filename: string, options: IRunScriptOptions) {
330
342
} )
331
343
}
332
344
345
+ hasInited = true
346
+
333
347
let lastError : any
334
348
try {
335
349
if ( aiPreferredLanguage && options . data ) {
0 commit comments