1
1
import { AliasButtons } from "@/app/(website)/studio/features/modgpt/PromptPanel/AliasButtons" ;
2
2
import { ControlButtons } from "@/app/(website)/studio/features/modgpt/PromptPanel/ControlButtons" ;
3
- import { WebSocketButton } from "@/app/(website)/studio/features/modgpt/PromptPanel/WebSocketButton" ;
4
- import { insertValue } from "@/app/(website)/studio/features/modgpt/PromptPanel/utils" ;
5
- import type { useAiService } from "@/app/(website)/studio/features/modgpt/useAiService/useAiService" ;
6
- import type { useModGptSubmit } from "@/app/(website)/studio/features/modgpt/useAiService/useModGpt/useModGptSubmit" ;
7
3
import { getOrderedAliasList } from "@/app/(website)/studio/features/modgpt/utils" ;
4
+ import ButtonWithTooltip from "@/app/(website)/studio/src/components/button/BottonWithTooltip" ;
5
+ import { useSnippetsStore } from "@/app/(website)/studio/src/store/snippets" ;
8
6
import { useAuth } from "@clerk/nextjs" ;
9
7
import { useGetAliases } from "@studio/store/CFS/alias" ;
10
- import type { UseChatHelpers } from "ai/react " ;
8
+ import Link from "next/link " ;
11
9
import { useRef , useState } from "react" ;
10
+ import { useCodemodAi } from "../../hooks/codemod-ai" ;
11
+ import { useModGPT } from "../../hooks/modgpt" ;
12
+ import { useChatStore } from "../../store/chat-state" ;
12
13
import { PromptForm } from "./PromptForm" ;
13
14
import { ScrollToBottomButton } from "./ScrollToBottomButton" ;
14
15
15
- export type PromptPanelProps = Pick <
16
- UseChatHelpers ,
17
- "isLoading" | "reload" | "messages" | "stop" | "input" | "setInput"
18
- > & {
19
- handleSubmit : ReturnType < typeof useModGptSubmit > ;
20
- startIterativeCodemodGeneration : ReturnType <
21
- typeof useAiService
22
- > [ "startIterativeCodemodGeneration" ] ;
23
- resetMessages : ReturnType < typeof useAiService > [ "resetMessages" ] ;
24
- } ;
25
-
26
- export function PromptPanel ( props : PromptPanelProps ) {
16
+ export function PromptPanel ( ) {
27
17
const {
28
- handleSubmit,
29
- isLoading,
30
- stop,
18
+ reset,
19
+ isGeneratingCodemod,
20
+ isGeneratingTestCases,
21
+ messages,
22
+ appendMessage,
31
23
input,
32
24
setInput,
33
- messages,
34
- startIterativeCodemodGeneration,
35
- resetMessages,
36
- } = props ;
25
+ } = useChatStore ( ) ;
26
+
27
+ const { getAllSnippets } = useSnippetsStore ( ) ;
28
+
29
+ const { before, after } = getAllSnippets ( ) ;
30
+ const modGPT = useModGPT ( "gpt-4o" ) ;
31
+ const { send : startCodemodGeneration , abort } = useCodemodAi ( {
32
+ input : {
33
+ type : "generate_codemod" ,
34
+ before,
35
+ after,
36
+ context : "" ,
37
+ description : "" ,
38
+ } ,
39
+ onFinish : ( ) =>
40
+ appendMessage ( {
41
+ role : "assistant" ,
42
+ content : "Codemod created and added to a new tab" ,
43
+ } ) ,
44
+ } ) ;
45
+
37
46
const textAreaRef = useRef < HTMLTextAreaElement > ( null ) ;
38
47
const [ expandedHelper , setExpandedHelper ] = useState ( true ) ;
39
48
const { isSignedIn } = useAuth ( ) ;
40
49
const aliases = useGetAliases ( ) ;
41
50
const aliasList = getOrderedAliasList ( aliases ) ;
42
51
43
- const handleInsertValue = ( value : string ) => {
44
- const textArea = textAreaRef . current ;
45
- if ( textArea ) {
46
- const updatedInput = insertValue ( textArea , input , value ) ;
47
- setInput ( updatedInput ) ;
48
- textArea . focus ( ) ;
49
- }
50
- } ;
52
+ // const handleInsertValue = (value: string) => {
53
+ // const textArea = textAreaRef.current;
54
+ // if (textArea) {
55
+ // const updatedInput = insertValue(textArea, input, value);
56
+ // setInput(updatedInput);
57
+ // textArea.focus();
58
+ // }
59
+ // };
51
60
52
61
return (
53
62
< div className = "chatPanel absolute bottom-0 mx-auto w-full sm:pl-8 sm:pr-16" >
@@ -61,10 +70,28 @@ export function PromptPanel(props: PromptPanelProps) {
61
70
{ expandedHelper && (
62
71
< >
63
72
< div className = "mb-1 flex w-full gap-1 overflow-x-auto px-1 items-center justify-content-center actions" >
64
- < WebSocketButton
65
- handleButtonClick = { ( ) => startIterativeCodemodGeneration ( ) }
66
- isLoading = { isLoading }
67
- />
73
+ < ButtonWithTooltip
74
+ tooltipContent = {
75
+ < >
76
+ with selected model and Codemod’s iterative AI system.
77
+ < Link
78
+ style = { { color : "blue" } }
79
+ href = "https://codemod.com/blog/iterative-ai-system"
80
+ >
81
+ { " " }
82
+ Learn more
83
+ </ Link >
84
+ </ >
85
+ }
86
+ variant = "default"
87
+ size = "sm"
88
+ className = "text-white flex gap-1 text-xs my-0 h-8 !py-0 bg-black hover:bg-accent hover:text-black"
89
+ // className="group my-0 h-8 whitespace-nowrap !py-0 text-xs font-bold bg-primary"
90
+ onClick = { ( ) => startCodemodGeneration ( ) }
91
+ disabled = { isGeneratingCodemod }
92
+ >
93
+ Autogenerate with Codemod AI
94
+ </ ButtonWithTooltip >
68
95
</ div >
69
96
< AliasButtons
70
97
aliasList = { aliasList }
@@ -75,11 +102,9 @@ export function PromptPanel(props: PromptPanelProps) {
75
102
< div className = "relative" >
76
103
< PromptForm
77
104
ref = { textAreaRef }
78
- onSubmit = { handleSubmit }
79
105
input = { input }
80
106
setInput = { setInput }
81
- isLoading = { isLoading }
82
- onReset = { resetMessages }
107
+ onReset = { reset }
83
108
/>
84
109
</ div >
85
110
</ div >
0 commit comments