-
Notifications
You must be signed in to change notification settings - Fork 12
fix: ensure app dirs exist #32
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
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 |
|---|---|---|
|
|
@@ -106,7 +106,7 @@ export async function createThread(script: string, firstMessage?: string): Promi | |
|
|
||
| if (firstMessage) { | ||
| const generatedThreadName = await generateThreadName(firstMessage) | ||
| renameThread(id, generatedThreadName); | ||
| await renameThread(id, generatedThreadName); | ||
| } | ||
|
|
||
| return { | ||
|
|
@@ -129,15 +129,3 @@ export async function renameThread(id: string, name: string) { | |
| threadMeta.name = name; | ||
| await fs.writeFile(path.join(threadPath, META_FILE), JSON.stringify(threadMeta)); | ||
| } | ||
|
|
||
| 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)); | ||
| } | ||
| } | ||
|
Comment on lines
-133
to
-143
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. Seems like this isn't used 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. It isn't right now. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export const dynamic = 'force-dynamic' // defaults to autover' | ||
| import {NextResponse} from "next/server"; | ||
|
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. My linter was complaining about 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. 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. |
||
| import {type Block, Tool} from '@gptscript-ai/gptscript' | ||
| import { Positions } from '../route'; | ||
| import { promises as fs } from 'fs'; | ||
|
|
@@ -17,13 +18,13 @@ export async function PUT( | |
| const updatedScript = updateScript(script, tool, (await req.json()) as Tool); | ||
|
|
||
| await fs.writeFile(path.join(SCRIPTS_PATH(),`${name}.gpt`), await gpt().stringify(updatedScript)); | ||
| return Response.json(await gpt().parse(path.join(SCRIPTS_PATH(),`${name}.gpt`))); | ||
| return NextResponse.json(await gpt().parse(path.join(SCRIPTS_PATH(),`${name}.gpt`))); | ||
| } catch (e) { | ||
| if (`${e}`.includes('no such file')){ | ||
| return Response.json({ error: '.gpt file not found' }, { status: 404 }); | ||
| return NextResponse.json({ error: '.gpt file not found' }, { status: 404 }); | ||
| } | ||
| console.error(e) | ||
| return Response.json({ error: e }, {status: 500}); | ||
| return NextResponse.json({ error: e }, {status: 500}); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Note:
fs.mkdirdoesn't throw an error if the directory already exists when therecursive: trueoption is passed.