1- import { useState , useEffect , useCallback , useContext } from "react" ;
2- import { Tool } from "@gptscript-ai/gptscript" ;
3- import Imports from "@/components/edit/configure/imports" ;
1+ import { useCallback , useContext , useEffect } from "react" ;
2+ import RemoteImports from "@/components/edit/configure/imports" ;
43import Loading from "@/components/loading" ;
5- import CustomTool from "@/components/edit/configure/customTool" ;
64import Models from "@/components/edit/configure/models" ;
75import Visibility from "@/components/edit/configure/visibility" ;
6+ import Code from "@/components/edit/configure/code" ;
87import { EditContext } from "@/contexts/edit" ;
9- import { ScriptContext } from "@/contexts/script" ;
8+ import { GoLightBulb , GoPlus , GoTools } from "react-icons/go" ;
9+ import { HiCog , HiOutlinePlus } from "react-icons/hi2" ;
10+ import { LuCircuitBoard } from "react-icons/lu" ;
1011import {
1112 Textarea ,
1213 Input ,
1314 Avatar ,
1415 Tooltip ,
15- Button ,
16- Select ,
17- SelectItem ,
18- Card ,
19- CardBody ,
16+ Accordion ,
17+ AccordionItem ,
2018} from "@nextui-org/react" ;
21- import { getModels } from "@/actions/models" ;
22- import { GoCode , GoPencil , GoPlay } from "react-icons/go" ;
23- import Code from "@/components/edit/configure/code" ;
19+ import { PiToolboxBold } from "react-icons/pi" ;
2420
2521interface ConfigureProps {
26- file : string ;
27- tool ?: Tool ;
22+ collapsed ?: boolean ;
2823 className ?: string ;
29- custom ?: boolean ;
3024}
3125
32- const Configure : React . FC < ConfigureProps > = ( { file , className, custom } ) => {
26+ const Configure : React . FC < ConfigureProps > = ( { className, collapsed } ) => {
3327 const {
3428 root,
3529 setRoot,
36- tools,
37- setTools,
30+ models,
3831 loading,
39- newestToolName,
4032 visibility,
4133 setVisibility,
34+ dynamicInstructions,
35+ setDynamicInstructions,
4236 } = useContext ( EditContext ) ;
43- const { setSubTool } = useContext ( ScriptContext ) ;
44- const [ models , setModels ] = useState < string [ ] > ( [ ] ) ;
45- const [ instructionsType , setInstructionsType ] = useState < string > ( "prompt" ) ;
46-
47- useEffect ( ( ) => {
48- getModels ( ) . then ( ( m ) => {
49- setModels ( m )
50- } )
51- } , [ ] ) ;
5237
5338 const abbreviate = ( name : string ) => {
5439 const words = name . split ( / (? = [ A - Z ] ) | [ \s _ - ] / ) ;
@@ -60,117 +45,94 @@ const Configure: React.FC<ConfigureProps> = ({file, className, custom}) => {
6045 setRoot ( { ...root , tools : newTools } ) ;
6146 } , [ root ] ) ;
6247
63- const setRootContexts = useCallback ( ( newContexts : string [ ] ) => {
64- setRoot ( { ...root , context : newContexts } ) ;
65- } , [ root ] ) ;
66-
67- const setRootAgents = useCallback ( ( newAgents : string [ ] ) => {
68- setRoot ( { ...root , agents : newAgents } ) ;
69- } , [ root ] ) ;
70-
71- if ( loading ) return < Loading > Loading your script's details...</ Loading > ;
48+ if ( loading ) return < Loading > Loading your assistant's details...</ Loading > ;
7249
7350 return (
7451 < >
75- < div className = "w-full" >
52+ < div className = "flex flex-col w-full justify-center items-center space-y-2 mb-6 mt-10 " >
7653 < Tooltip
77- content = { ` ${ root . name || "Main" } ` }
78- placement = "bottom "
54+ content = { "Upload a profile picture for your assistant." }
55+ placement = "top "
7956 closeDelay = { 0.5 }
8057 >
8158 < Avatar
82- size = "md"
83- name = { abbreviate ( root . name || 'Main' ) }
84- className = "mx-auto mb-6 mt-4 "
59+ size = "lg"
60+ icon = { < HiOutlinePlus className = "text-xl" /> }
61+ className = "block cursor-pointer mb-6"
8562 classNames = { { base : "bg-white p-6 text-sm border dark:border-none dark:bg-zinc-900" } }
8663 />
8764 </ Tooltip >
8865 </ div >
8966 < div className = "px-2 flex flex-col space-y-4 mb-6" >
90- < Visibility visibility = { visibility } setVisibility = { setVisibility } />
91- < Input
92- color = "primary"
93- variant = "bordered"
94- label = "Name"
95- placeholder = "Give your chat bot a name..."
96- defaultValue = { root . name }
97- onChange = { ( e ) => setRoot ( { ...root , name : e . target . value } ) }
98- />
67+ < div className = "relative" >
68+ < div className = "absolute top-3 right-0 z-40" >
69+ < Visibility visibility = { visibility } setVisibility = { setVisibility } />
70+ </ div >
71+ < Input
72+ color = "primary"
73+ variant = "bordered"
74+ label = "Name"
75+ placeholder = "Give your assistant a name..."
76+ defaultValue = { root . name }
77+ onChange = { ( e ) => setRoot ( { ...root , name : e . target . value } ) }
78+ />
79+ </ div >
9980 < Textarea
10081 color = "primary"
10182 fullWidth
10283 variant = "bordered"
10384 label = "Description"
104- placeholder = "Describe your script ..."
85+ placeholder = "Describe what your assistant does ..."
10586 defaultValue = { root . description }
10687 onChange = { ( e ) => setRoot ( { ...root , description : e . target . value } ) }
10788 />
108- < Select
89+ < Textarea
10990 color = "primary"
110- label = "Instructions Type"
91+ fullWidth
11192 variant = "bordered"
112- defaultSelectedKeys = { [ "prompt" ] }
113- onChange = { ( e ) => setInstructionsType ( e . target . value ) }
114- >
115- < SelectItem key = "prompt" value = "prompt" textValue = "Prompt" startContent = { < GoPencil /> } >
116- < h1 > Prompt</ h1 >
117- < p className = "text-default-500 text-tiny" > Standard - Describe behavior using natural language.</ p >
118- </ SelectItem >
119- < SelectItem key = "code" value = "code" startContent = { < GoCode /> } textValue = "Code" >
120- < h1 > Code</ h1 >
121- < p className = "text-default-500 text-tiny" > Advanced - Describe behavior using proramming languages.</ p >
122- </ SelectItem >
123- </ Select >
124- { ( instructionsType !== "code" ) &&
125- < >
126- < Textarea
127- color = "primary"
128- fullWidth
129- variant = "bordered"
130- label = "Instructions"
131- placeholder = "Describe your how your script should behave..."
132- defaultValue = { root . instructions }
133- onChange = { ( e ) => setRoot ( { ...root , instructions : e . target . value } ) }
134- />
135- < Models options = { models } defaultValue = { root . modelName } onChange = { ( model ) => setRoot ( { ...root , modelName : model } ) } />
136- < Imports className = "py-2"
93+ label = "Instructions"
94+ placeholder = "Give your assistant instructions on how to behave..."
95+ defaultValue = { root . instructions }
96+ onChange = { ( e ) => setRoot ( { ...root , instructions : e . target . value } ) }
97+ />
98+ < Accordion isCompact fullWidth selectionMode = "multiple" >
99+ < AccordionItem
100+ aria-label = "dynamic-instructions"
101+ title = { < h1 > Dynamic Instructions</ h1 > }
102+ startContent = { < LuCircuitBoard /> }
103+ classNames = { { content : "p-10 pt-6" } }
104+ >
105+ < div className = "flex bg-primary-50 rounded-xl p-4 mb-4 text-tiny italic text-primary-500 items-center space-x-4" >
106+ < GoLightBulb className = { `inline mb-1 text-sm ${ collapsed ? 'w-[200px] ' : 'w-fit' } ` } />
107+ < p >
108+ Augment your instructions with code that can pull information from local or remote systems.
109+ </ p >
110+ </ div >
111+ < Code label = "Code" code = { dynamicInstructions } onChange = { setDynamicInstructions } />
112+ { /* <div className="my-4"/>
113+ <Code label="Dependencies" code={'// package.json'} onChange={(code) => {}} /> */ }
114+ </ AccordionItem >
115+ < AccordionItem
116+ aria-label = "remote-tools"
117+ title = { < h1 > Tools</ h1 > }
118+ startContent = { < PiToolboxBold /> }
119+ classNames = { { content : "p-10 pt-6" } }
120+ >
121+ < RemoteImports
137122 tools = { root . tools }
138- contexts = { root . context }
139- agents = { root . agents }
140- setAgents = { setRootAgents }
141- setContexts = { setRootContexts }
142- setTools = { setRootTools } label = { "Tool" }
123+ setTools = { setRootTools }
124+ collapsed = { collapsed }
143125 />
144- { ! custom && tools && tools . length > 0 &&
145- < Card className = "w-full pt-2 pb-6" shadow = "sm" >
146- < CardBody >
147- < h1 className = "mb-4 px-2 text-lg" > Local Tools</ h1 >
148- < div className = "flex flex-col space-y-2 px-2" >
149- { tools && tools . map ( ( customTool , i ) => (
150- < div className = "flex space-x-2 " >
151- < CustomTool tool = { customTool } file = { file } models = { models } />
152- < Button
153- startContent = { < GoPlay /> }
154- color = "primary" variant = "flat"
155- size = "sm"
156- className = "text-sm"
157- isIconOnly
158- onPress = { ( ) => setSubTool ( customTool . name || '' ) }
159- />
160- </ div >
161- ) ) }
162- </ div >
163- </ CardBody >
164- </ Card >
165- }
166- </ >
167- }
168- { ( instructionsType === "code" ) &&
169- < Code
170- code = { root . instructions || '' }
171- onChange = { ( code ) => setRoot ( { ...root , instructions : code || '' } ) }
172- />
173- }
126+ </ AccordionItem >
127+ < AccordionItem
128+ aria-label = "advanced"
129+ title = { < h1 > Advanced</ h1 > }
130+ startContent = { < HiCog /> }
131+ classNames = { { content : "p-10 pt-6 h-[500px]" } }
132+ >
133+ < Models options = { models } defaultValue = { root . modelName } onChange = { ( model ) => setRoot ( { ...root , modelName : model } ) } />
134+ </ AccordionItem >
135+ </ Accordion >
174136 </ div >
175137 </ >
176138 ) ;
0 commit comments