Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# production
/build
/electron-dist

# misc
.DS_Store
Expand All @@ -38,4 +39,5 @@ yarn-error.log*
next-env.d.ts

# app output
gptscripts
gptscripts/**
!gptscripts/.gitkeep
2 changes: 1 addition & 1 deletion actions/scripts/fetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const fetchScripts = async (): Promise<Record<string, string>> => {
try {
const files = await fs.readdir(SCRIPTS_PATH());
const gptFiles = files.filter(file => file.endsWith('.gpt'));

if (gptFiles.length === 0) throw new Error('no files found in scripts directory');

const scripts: Record<string, string> = {};
Expand Down
2 changes: 1 addition & 1 deletion actions/scripts/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function newFile(name: string, instructions: string, fileName: stri
if (!fileName.endsWith('.gpt')) {
throw new Error('file cannot be empty and must end with .gpt');
}

await fs.writeFile(`${SCRIPTS_PATH()}/${fileName}`, `---\nName: ${name}\nChat: true\n\n${instructions}\n\n`);
return fileName.replace('.gpt', '')
} catch (e) {
Expand Down
9 changes: 5 additions & 4 deletions app/api/file/[name]/[tool]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Positions } from '../route';
import { promises as fs } from 'fs';
import path from 'path';
import { SCRIPTS_PATH, gpt} from '@/config/env';
import { NextResponse } from 'next/server';

// Create a datastructure for the tool bindings in the UI
export async function PUT(
Expand All @@ -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});
}
}

Expand Down Expand Up @@ -51,4 +52,4 @@ const updateScript = (script: Block[], tool: string, updatedTool: Tool) => {
}
updatedScript[toolIndex] = updatedTool;
return updatedScript;
}
}
23 changes: 12 additions & 11 deletions app/api/file/[name]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
Edge as RFEdge,
XYPosition,
} from 'reactflow';
import { NextResponse } from 'next/server';

export async function DELETE(
_: NextRequest,
Expand All @@ -17,9 +18,9 @@ export async function DELETE(
try {
const { name } = params as any;
await fs.unlink(path.join(`${SCRIPTS_PATH()}/${name}.gpt`));
return Response.json({ success: true });
return NextResponse.json({ success: true });
} catch (e) {
return Response.json({ error: e }, { status: 500 });
return NextResponse.json({ error: e }, { status: 500 });
}
}

Expand All @@ -31,9 +32,9 @@ export async function DELETE(

// await fs.rename(`${scriptsPath}/${name}`, `${scriptsPath}/${name}.bak`);
// await fs.writeFile(`${scriptsPath}/${name}`, content);
// return Response.json({ success: true });
// return NextResponse.json({ success: true });
// } catch (e) {
// return Response.json({ error: e }, { status: 500 });
// return NextResponse.json({ error: e }, { status: 500 });
// }
// }

Expand All @@ -46,14 +47,14 @@ export async function GET(
const script = await gpt().parse(path.join(SCRIPTS_PATH(),`${name}.gpt`));
if (req.nextUrl.searchParams.get('nodeify') === 'true') {
const { nodes, edges } = await nodeify(script);
return Response.json({ nodes: nodes, edges: edges });
return NextResponse.json({ nodes: nodes, edges: edges });
}
return Response.json(script);
return NextResponse.json(script);
} 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 });
}
return Response.json({ error: e }, {status: 500});
return NextResponse.json({ error: e }, {status: 500});
}
}

Expand All @@ -67,12 +68,12 @@ export async function PUT(
const script = denodeify(nodes);

await fs.writeFile(path.join(SCRIPTS_PATH(),`${name}.gpt`), await gpt().stringify(script));
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 });
}
return Response.json({ error: e }, {status: 500});
return NextResponse.json({ error: e }, {status: 500});
}
}

Expand Down
15 changes: 8 additions & 7 deletions app/api/file/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ export const dynamic = 'force-dynamic' // defaults to auto
import { GPTScript } from '@gptscript-ai/gptscript'
import { promises as fs } from 'fs';
import { SCRIPTS_PATH, gpt } from '@/config/env';
import { NextResponse } from 'next/server';

export async function GET() {
try {
const files = await fs.readdir(SCRIPTS_PATH());
const gptFiles = files.filter(file => file.endsWith('.gpt'));

if (gptFiles.length === 0)
return Response.json({ error: 'no .gpt files found' }, { status: 404 });
return NextResponse.json({ error: 'no .gpt files found' }, { status: 404 });

const scripts: Record<string, string> = {};
for (const file of gptFiles) {
Expand All @@ -23,14 +24,14 @@ export async function GET() {
scripts[file] = description || '';
}

return Response.json(scripts);
return NextResponse.json(scripts);
} catch (e) {
const error = e as NodeJS.ErrnoException;
if (error.code === 'ENOENT'){
return Response.json({ error: 'no .gpt files found' }, { status: 404 });
return NextResponse.json({ error: 'no .gpt files found' }, { status: 404 });
}
console.error(e)
return Response.json({ error: e }, { status: 500 });
return NextResponse.json({ error: e }, { status: 500 });
}
}

Expand All @@ -46,8 +47,8 @@ export async function POST(_req: Request) {
newFileName = `new-file-${id}.gpt`;
}
await fs.writeFile(`${SCRIPTS_PATH()}/${newFileName}`, '---\nname: main');
return Response.json({ file: newFileName });
return NextResponse.json({ file: newFileName });
} catch (e) {
return Response.json({ error: e }, { status: 500 });
return NextResponse.json({ error: e }, { status: 500 });
}
}
16 changes: 9 additions & 7 deletions app/build/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { ReactFlowProvider } from 'reactflow';
import Graph from '@/components/build/graph';
import { GraphContextProvider } from '@/contexts/graph';

export default () => (
<ReactFlowProvider>
<GraphContextProvider>
<Graph />
</GraphContextProvider>
</ReactFlowProvider>
);
export default function Page() {
return (
<ReactFlowProvider>
<GraphContextProvider>
<Graph />
</GraphContextProvider>
</ReactFlowProvider>
)
}
16 changes: 14 additions & 2 deletions app/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import Configure from "@/components/edit/configure";
import { EditContextProvider } from "@/contexts/edit";
import New from "@/components/edit/new";
import ScriptNav from "@/components/edit/scriptNav";
import { Suspense } from 'react'

export default function Edit() {
const EditInner = () => {
const [file, setFile] = useState<string>(useSearchParams().get('file') || '');

if (!file || file === 'new') return (
Expand Down Expand Up @@ -36,4 +37,15 @@ export default function Edit() {
</div>
</EditContextProvider>
);
}
}

const Edit = () => {
return (
<Suspense>
<EditInner/>
</Suspense>
)
}

export default Edit;

17 changes: 13 additions & 4 deletions app/run/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import { useSearchParams } from 'next/navigation';
import Script from "@/components/script";
import { Suspense } from 'react';

const Run = () => {
const RunInner = () => {
const file = useSearchParams().get('file') || '';

return (
<div className="h-full w-full px-10 2xl:w-1/2 2xl:mx-auto 2xl:px-0 flex flex-col pb-10">
<Script className="pb-10" file={file} />
</div>
);
<Script className="pb-10" file={file} />
</div>
);
};

const Run = () => {
return (
<Suspense>
<RunInner/>
</Suspense>
)
}

export default Run;
Loading