From cd7754c66bd6c6c34c851ccf2cb625e1878dccbb Mon Sep 17 00:00:00 2001
From: ruru <142723369+ruru-m07@users.noreply.github.com>
Date: Fri, 10 May 2024 20:45:14 +0530
Subject: [PATCH 1/2] feat(app): implement new UI and update action and remove
unused API
---
action/index.ts | 54 ++++++---
app/api/route.ts | 27 -----
app/layout.tsx | 39 ++++++-
app/page.tsx | 189 ++++++++++++++++++-------------
components/AiLoading.tsx | 13 ---
components/Navbar.tsx | 45 --------
components/emptyScreen.tsx | 61 ++++++++++
components/listChat.tsx | 33 ------
components/listSuggestion.tsx | 19 ++++
components/loader.tsx | 7 ++
components/modeToggle.tsx | 40 +++++++
components/suggestions.json | 33 ++++++
components/ui/toast.tsx | 4 +-
public/logo-dark.png | Bin 0 -> 64199 bytes
public/logo-light.png | Bin 0 -> 63376 bytes
public/system.txt | 203 ----------------------------------
utils/index.ts | 37 +------
17 files changed, 353 insertions(+), 451 deletions(-)
delete mode 100644 app/api/route.ts
delete mode 100644 components/AiLoading.tsx
delete mode 100644 components/Navbar.tsx
create mode 100644 components/emptyScreen.tsx
delete mode 100644 components/listChat.tsx
create mode 100644 components/listSuggestion.tsx
create mode 100644 components/loader.tsx
create mode 100644 components/modeToggle.tsx
create mode 100644 components/suggestions.json
create mode 100644 public/logo-dark.png
create mode 100644 public/logo-light.png
delete mode 100644 public/system.txt
diff --git a/action/index.ts b/action/index.ts
index 8a5efdc..9b807a3 100644
--- a/action/index.ts
+++ b/action/index.ts
@@ -1,28 +1,50 @@
"use server";
-import { model, systemHistory } from "@/utils";
-import { Content } from "@google/generative-ai";
+import { model } from "@/utils";
-export const commitMessage = async ({
+export const commitChange = async ({
message,
- history,
}: {
- message: string;
- history: Content[];
-}) => {
- const chat = model.startChat({
- history: [...(await systemHistory()), ...history],
- });
+ message: string | null;
+}): Promise<{
+ data: {
+ text: string;
+ } | null;
+ error: string | null;
+}> => {
+ if (!message || message.trim() === "") {
+ return { data: null, error: "Please enter a message" };
+ }
try {
- const result = await chat.sendMessage(message);
- const response = result.response;
+ const modelResponse = model.generateContent({
+ contents: [{ role: "user", parts: [{ text: message }] }],
+ systemInstruction: `\
+ You are an assistant that helps to provide Git commit messages based on https://www.conventionalcommits.org/en/v1.0.0/.
+
+ - Provide a Git commit message in a code block as txt.
+ - Do not include the full command (e.g., \`git commit -m "here git message"\`).
+ - Only provide the commit message itself.
+ - Suggest 3 different commit messages to give the user some options.
+ - For example, if the user input is "I change lib folder to utils folder", then the output should be:
+
+ \`\`\`txt refactor(lib): change lib folder to utils folder \n\`\`\`\n
+ \`\`\`txt refactor(deps): rename lib folder to utils \n\`\`\`\n
+ \`\`\`txt fix(deps): rename lib folder to utils \n\`\`\`\n
+
+ `,
+ });
- const text = response.text();
- console.log("text", text);
+ const response = (await modelResponse).response.text();
- return { success: true, text: text };
+ return {
+ data: {
+ text: response,
+ },
+ error: null,
+ };
} catch (error) {
- return { success: false, error: error as string };
+ console.log("error on action", error);
+ return { data: null, error: "something went wrong!" };
}
};
diff --git a/app/api/route.ts b/app/api/route.ts
deleted file mode 100644
index 360af42..0000000
--- a/app/api/route.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { type NextRequest } from "next/server";
-import { model, systemHistory } from "@/utils";
-
-export async function GET(request: NextRequest) {
- const searchParams = request.nextUrl.searchParams;
- const message = searchParams.get("message");
-
- if (!message) {
- return new Response("No message provided", { status: 400 });
- }
-
- const chat = model.startChat({
- history: [...(await systemHistory())],
- });
-
- const result = await chat.sendMessageStream(message);
-
- const response = await result.response;
-
- const data = response.text();
-
- if (!data) {
- return new Response("something went wrong!", { status: 500 });
- }
-
- return new Response(data);
-}
diff --git a/app/layout.tsx b/app/layout.tsx
index 694ee4e..6e2fe22 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -4,6 +4,12 @@ import "./globals.css";
import { ThemeProvider } from "@/components/provider/theme-provider";
import { Toaster } from "@/components/ui/toaster";
import { siteConfig } from "@/config/site";
+import Link from "next/link";
+import { cn } from "@/lib/utils";
+import { buttonVariants } from "@/components/ui/button";
+import { GitHubLogoIcon } from "@radix-ui/react-icons";
+import { ModeToggle } from "@/components/modeToggle";
+import Image from "next/image";
const inter = Inter({ subsets: ["latin"] });
@@ -54,7 +60,38 @@ export default function RootLayout({
enableSystem
disableTransitionOnChange
>
- {children}
+
+
+