Skip to content

Commit 5e1fedf

Browse files
committed
wip
1 parent e634fa3 commit 5e1fedf

File tree

13 files changed

+334
-235
lines changed

13 files changed

+334
-235
lines changed

apps/backend/src/cron.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { WebClient } from "@slack/web-api";
22
import axios from "axios";
33
import { CronJob } from "cron";
4-
import WebSocket from "ws";
4+
import { WebSocket } from "ws";
55

66
import { prisma } from "@codemod-com/database";
77

@@ -107,10 +107,10 @@ const services: Array<{
107107
{
108108
name: "Codemod AI Service",
109109
url: process.env.CODEMOD_AI_SERVICE_URL ?? "",
110-
type: "websocket",
110+
type: "http",
111111
available: true,
112112
webhook:
113-
" https://api.instatus.com/v3/integrations/webhook/clzbu558m93630kcn6fnvj8yk8",
113+
"https://api.instatus.com/v3/integrations/webhook/clzbu558m93630kcn6fnvj8yk8",
114114
},
115115
{
116116
name: "Run Service",

apps/frontend/app/(website)/studio/features/modGPT/Chat/Chat.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { useAiService } from "@/app/(website)/studio/features/modgpt/useAiService";
22
import { memo } from "react";
3-
import { useCodemodAi } from "../hooks/codemod-ai";
4-
import { useModGPT } from "../hooks/modgpt";
53
import { ChatWindow } from "./Chat/ChatWindow";
64
import { PromptPanel } from "./Chat/PromptPanel";
75

@@ -26,28 +24,25 @@ const ChatBase = ({ className, isSignedIn }: Props) => {
2624
// autogenerateTestCases,
2725
// };
2826

29-
const modGPT = useModGPT("gpt-4o");
30-
const { send: callCodemodAI, messages } = useCodemodAi("gpt-4o");
31-
3227
return (
3328
<>
3429
<ChatWindow
35-
isLoading={isLoading}
36-
messages={messages}
37-
isSignedIn={isSignedIn}
38-
className={className}
30+
// isLoading={isLoading}
31+
// messages={messages}
32+
// isSignedIn={isSignedIn}
33+
// className={className}
3934
/>
4035
<PromptPanel
41-
autogenerateTestCases={autogenerateTestCases}
42-
handleSubmit={modGptSubmit}
43-
resetMessages={resetMessages}
44-
isLoading={isLoading}
45-
stop={handleStop}
46-
reload={reload}
47-
messages={messages}
48-
input={input}
49-
setInput={setInput}
50-
startIterativeCodemodGeneration={startIterativeCodemodGeneration}
36+
// autogenerateTestCases={autogenerateTestCases}
37+
// handleSubmit={modGptSubmit}
38+
// resetMessages={resetMessages}
39+
// isLoading={isLoading}
40+
// stop={handleStop}
41+
// reload={reload}
42+
// messages={messages}
43+
// input={input}
44+
// setInput={setInput}
45+
// startIterativeCodemodGeneration={startIterativeCodemodGeneration}
5146
/>
5247
</>
5348
);

apps/frontend/app/(website)/studio/features/modGPT/Chat/PromptPanel/PromptForm.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { useEnterSubmit } from "@studio/hooks/useEnterSubmit";
99
import type { UseChatHelpers } from "ai/react";
1010
import * as React from "react";
1111
import Textarea from "react-textarea-autosize";
12+
import { useCodemodAi } from "../../hooks/codemod-ai";
13+
import { useModGPT } from "../../hooks/modgpt";
14+
import { useChatStore } from "../../store/chat-state";
1215

1316
export interface Props extends Pick<UseChatHelpers, "input" | "setInput"> {
1417
onSubmit: (value: string) => Promise<void>;
@@ -17,7 +20,12 @@ export interface Props extends Pick<UseChatHelpers, "input" | "setInput"> {
1720
}
1821

1922
export const PromptForm = React.forwardRef<HTMLTextAreaElement, Props>(
20-
({ onSubmit, onReset, input, setInput, isLoading }, ref) => {
23+
({ input, setInput }, ref) => {
24+
const { messages, reset, isGeneratingCodemod, isGeneratingTestCases } =
25+
useChatStore();
26+
const modGPT = useModGPT("gpt-4o");
27+
const { send: callCodemodAI, abort } = useCodemodAi("gpt-4o");
28+
2129
const { formRef, onKeyDown } = useEnterSubmit();
2230
const inputRef = React.useRef<HTMLTextAreaElement>(null);
2331

apps/frontend/app/(website)/studio/features/modGPT/Chat/PromptPanel/PromptPanel.tsx

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,62 @@
11
import { AliasButtons } from "@/app/(website)/studio/features/modgpt/PromptPanel/AliasButtons";
22
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";
73
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";
86
import { useAuth } from "@clerk/nextjs";
97
import { useGetAliases } from "@studio/store/CFS/alias";
10-
import type { UseChatHelpers } from "ai/react";
8+
import Link from "next/link";
119
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";
1213
import { PromptForm } from "./PromptForm";
1314
import { ScrollToBottomButton } from "./ScrollToBottomButton";
1415

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() {
2717
const {
28-
handleSubmit,
29-
isLoading,
30-
stop,
18+
reset,
19+
isGeneratingCodemod,
20+
isGeneratingTestCases,
21+
messages,
22+
appendMessage,
3123
input,
3224
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+
3746
const textAreaRef = useRef<HTMLTextAreaElement>(null);
3847
const [expandedHelper, setExpandedHelper] = useState(true);
3948
const { isSignedIn } = useAuth();
4049
const aliases = useGetAliases();
4150
const aliasList = getOrderedAliasList(aliases);
4251

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+
// };
5160

5261
return (
5362
<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) {
6170
{expandedHelper && (
6271
<>
6372
<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>
6895
</div>
6996
<AliasButtons
7097
aliasList={aliasList}
@@ -75,11 +102,9 @@ export function PromptPanel(props: PromptPanelProps) {
75102
<div className="relative">
76103
<PromptForm
77104
ref={textAreaRef}
78-
onSubmit={handleSubmit}
79105
input={input}
80106
setInput={setInput}
81-
isLoading={isLoading}
82-
onReset={resetMessages}
107+
onReset={reset}
83108
/>
84109
</div>
85110
</div>

apps/frontend/app/(website)/studio/features/modGPT/Chat/PromptPanel/WebSocketButton.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.

apps/frontend/app/(website)/studio/features/modGPT/api/fetch-stream.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ export async function fetchStream(opts: {
66
}) {
77
const { url, onChunk, options } = opts;
88

9-
const response = await fetch(url, options);
9+
const response = await fetch(url, {
10+
...options,
11+
headers: {
12+
...options?.headers,
13+
Authorization: `Bearer ${opts.token}`,
14+
},
15+
});
1016

1117
if (response.body === null) {
1218
throw new Error("ReadableStream not yet supported in this browser.");
1319
}
1420

1521
for await (const chunk of response.body as any) {
16-
if (options?.signal?.aborted) break; // just break out of loop
22+
if (options?.signal?.aborted) break;
1723

1824
onChunk(chunk.toString());
1925
}

0 commit comments

Comments
 (0)