11export const dynamic = 'force-dynamic' // defaults to autover'
2- import { GPTScript , type Block , Tool } from '@gptscript-ai/gptscript'
2+ import { type Block , Tool } from '@gptscript-ai/gptscript'
33import { Positions } from '../route' ;
44import { promises as fs } from 'fs' ;
55import path from 'path' ;
6- import { SCRIPTS_PATH } from '@/config/env' ;
7-
8- const gptscript = new GPTScript ( ) ;
6+ import { SCRIPTS_PATH , gpt } from '@/config/env' ;
97
108// Create a datastructure for the tool bindings in the UI
119export async function PUT (
@@ -15,11 +13,11 @@ export async function PUT(
1513 try {
1614 const { name, tool } = params as any ;
1715
18- const script = await gptscript . parse ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) ) ;
16+ const script = await gpt ( ) . parse ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) ) ;
1917 const updatedScript = updateScript ( script , tool , ( await req . json ( ) ) as Tool ) ;
2018
21- await fs . writeFile ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) , await gptscript . stringify ( updatedScript ) ) ;
22- return Response . json ( await gptscript . parse ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) ) ) ;
19+ await fs . writeFile ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) , await gpt ( ) . stringify ( updatedScript ) ) ;
20+ return Response . json ( await gpt ( ) . parse ( path . join ( SCRIPTS_PATH ( ) , `${ name } .gpt` ) ) ) ;
2321 } catch ( e ) {
2422 if ( `${ e } ` . includes ( 'no such file' ) ) {
2523 return Response . json ( { error : '.gpt file not found' } , { status : 404 } ) ;
@@ -39,7 +37,7 @@ const updateScript = (script: Block[], tool: string, updatedTool: Tool) => {
3937 if ( tool !== updatedTool . name ) {
4038 updatedScript = script . map ( block => {
4139 if ( block . type === 'tool' && block . name !== tool ) {
42- block . tools = block . tools ?. map ( t => t === tool ? updatedTool . name : t ) ;
40+ block . tools = block . tools ?. map ( t => t === tool ? updatedTool . name : t ) as string [ ] | undefined ;
4341 } else if ( block . type === 'text' ) {
4442 const positions = JSON . parse ( block . content ) as Positions
4543 block . content = JSON . stringify (
0 commit comments