-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix app.mjs panic and create settings.json on startup #481
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import nextConfig from '../next.config.js'; | |
import { Server } from 'socket.io'; | ||
import { GPTScript, RunEventType } from '@gptscript-ai/gptscript'; | ||
import dotenv from 'dotenv'; | ||
import fs from 'fs'; | ||
import fs, { existsSync } from 'fs'; | ||
import path from 'path'; | ||
import os from 'os'; | ||
|
||
|
@@ -135,8 +135,22 @@ const mount = async ( | |
process.env.WORKSPACE_DIR ?? process.env.GPTSCRIPT_WORKSPACE_DIR; | ||
const THREADS_DIR = | ||
process.env.THREADS_DIR ?? path.join(WORKSPACE_DIR, 'threads'); | ||
|
||
// Get the settings file. If it doesn't exist, use default settings instead. | ||
const settingsLocation = process.env.GPTSCRIPT_SETTINGS_FILE; | ||
const settings = JSON.parse(fs.readFileSync(settingsLocation, 'utf8')); | ||
let settings = { | ||
confirmToolCalls: false, | ||
browser: { | ||
headless: true, | ||
}, | ||
}; | ||
if (existsSync(settingsLocation)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: probably more safe to use default setting when file exists and parsing is correct, otherwise fallback to default file. In case the setting file is corrupted... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @StrongMonkey Can you take another look? I added some things to defend against malformed files. |
||
try { | ||
settings = JSON.parse(fs.readFileSync(settingsLocation, 'utf8')); | ||
} catch { | ||
console.error('Malformed settings file, using default settings...'); | ||
} | ||
} | ||
|
||
let script; | ||
if (typeof location === 'string') { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this comment is out of date?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its new, I added it just now. What's wrong with it?