Skip to content

Conversation

@njhale
Copy link
Member

@njhale njhale commented Jul 18, 2024

Ensure the WORKSPACE_DIR and SCRIPTS_PATH directories are created before attempting to use them and refactor some misc related code.

Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
@njhale njhale requested review from thedadams and tylerslaton July 18, 2024 23:44
- Ensure the WORKSPACE_DIR and SCRIPTS_PATH directories are created before
attempting to use them.
- Refactor misc related code

Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
const files = await fs.readdir(SCRIPTS_PATH());
const gptFiles = files.filter(file => file.endsWith('.gpt'));
const scriptsPath = SCRIPTS_PATH()
await fs.mkdir(scriptsPath, {recursive: true})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: fs.mkdir doesn't throw an error if the directory already exists when the recursive: true option is passed.

Comment on lines -133 to -143
export async function updateThread(id: string, thread: Thread) {
const threadsDir = THREADS_DIR();
const threadPath = path.join(threadsDir,id);

if (thread.state) await fs.writeFile(path.join(threadPath, STATE_FILE), thread.state);
if (thread.meta) {
const existingMeta = await fs.readFile(path.join(threadPath, META_FILE), "utf-8");
const mergedMeta = { ...JSON.parse(existingMeta), ...thread.meta };
await fs.writeFile(path.join(threadPath, META_FILE), JSON.stringify(mergedMeta));
}
} No newline at end of file
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this isn't used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't right now.

@@ -1,4 +1,6 @@

export const dynamic = 'force-dynamic' // defaults to autover'
import {NextResponse} from "next/server";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My linter was complaining about Response.json not existing here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, it is auto imported I believe. Also this whole API section can get removed soonish. It isn't used right now, not important but just adjacent.

Copy link
Contributor

@tylerslaton tylerslaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@njhale njhale merged commit cc90b3e into gptscript-ai:main Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants