Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

feat: theme, loading states, request details (#63)

Aman Agarwal15f12f015820
diff --git a/src/client/next.config.js b/src/client/next.config.js
index 3ac3cb32..20b04e5f 100644
--- a/src/client/next.config.js
+++ b/src/client/next.config.js
@@ -4,7 +4,11 @@ const nextConfig = {
remotePatterns: [
{
protocol: "https",
- hostname: "avatars.githubusercontent.com",
+ hostname: "*",
+ },
+ {
+ protocol: "https",
+ hostname: "raw.githubusercontent.com",
},
],
},
diff --git a/src/client/prisma/schema.prisma b/src/client/prisma/schema.prisma
index 74cead32..7d7df389 100644
--- a/src/client/prisma/schema.prisma
+++ b/src/client/prisma/schema.prisma
@@ -7,16 +7,45 @@ datasource db {
url = env("DATABASE_URL")
}
-model apikey {
- id Int @id @default(autoincrement())
- api_key String @unique @db.VarChar(255)
- name String @db.VarChar(50)
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
+model doku_apikeys {
+ id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
+ api_key String @unique @db.VarChar(255)
+ name String @db.VarChar(50)
+ created_at DateTime? @default(now()) @db.Timestamptz(6)
@@index([api_key], map: "idx_api_key")
}
+/// This table has subclasses and requires additional setup for migrations. Visit https://pris.ly/d/table-inheritance for more info.
+/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
+model doku_llm_data {
+ time DateTime @db.Timestamptz(6)
+ id String? @default(dbgenerated("gen_random_uuid()")) @db.Uuid
+ llmreqid String?
+ environment String @db.VarChar(50)
+ endpoint String @db.VarChar(50)
+ sourcelanguage String @db.VarChar(50)
+ applicationname String @db.VarChar(50)
+ completiontokens Int?
+ prompttokens Int?
+ totaltokens Int?
+ finishreason String? @db.VarChar(50)
+ requestduration Float?
+ usagecost Float?
+ model String? @db.VarChar(50)
+ prompt String?
+ response String?
+ imagesize String?
+ revisedprompt String?
+ image String?
+ audiovoice String?
+ finetunejobstatus String?
+
+ @@index([time(sort: Desc)])
+ @@ignore
+}
+
+
model Account {
id String @id @default(cuid())
userId String @map("user_id")
@@ -74,33 +103,4 @@ model VerificationRequest {
updatedAt DateTime @updatedAt
@@unique([identifier, token])
-}
-
-/// This table has subclasses and requires additional setup for migrations. Visit https://pris.ly/d/table-inheritance for more info.
-/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
-model doku {
- time DateTime @db.Timestamptz(6)
- name String @db.VarChar(10)
- environment String @db.VarChar(50)
- endpoint String @db.VarChar(50)
- sourcelanguage String @db.VarChar(50)
- applicationname String @db.VarChar(50)
- completiontokens Int?
- prompttokens Int?
- totaltokens Int?
- finishreason String? @db.VarChar(50)
- requestduration Float?
- usagecost Float?
- model String? @db.VarChar(50)
- prompt String?
- response String?
- imagesize String?
- revisedprompt String?
- image String?
- audiovoice String?
- finetunejobid String?
- finetunejobstatus String?
-
- @@index([time(sort: Desc)])
- @@ignore
-}
+}
\ No newline at end of file
diff --git a/src/client/public/banner.gif b/src/client/public/images/banner.gif
similarity index 100%
rename from src/client/public/banner.gif
rename to src/client/public/images/banner.gif
diff --git a/src/client/public/images/doku-logo-with-name.png b/src/client/public/images/doku-logo-with-name.png
new file mode 100644
index 00000000..50e59be9
Binary files /dev/null and b/src/client/public/images/doku-logo-with-name.png differ
diff --git a/src/client/public/github-mark.svg b/src/client/public/images/github-mark.svg
similarity index 100%
rename from src/client/public/github-mark.svg
rename to src/client/public/images/github-mark.svg
diff --git a/src/client/public/next.svg b/src/client/public/next.svg
deleted file mode 100644
index 5174b28c..00000000
--- a/src/client/public/next.svg
+++ /dev/null
@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
\ No newline at end of file
diff --git a/src/client/public/vercel.svg b/src/client/public/vercel.svg
deleted file mode 100644
index d2f84222..00000000
--- a/src/client/public/vercel.svg
+++ /dev/null
@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 283 64"><path fill="black" d="M141 16c-11 0-19 7-19 18s9 18 20 18c7 0 13-3 16-7l-7-5c-2 3-6 4-9 4-5 0-9-3-10-7h28v-3c0-11-8-18-19-18zm-9 15c1-4 4-7 9-7s8 3 9 7h-18zm117-15c-11 0-19 7-19 18s9 18 20 18c6 0 12-3 16-7l-8-5c-2 3-5 4-8 4-5 0-9-3-11-7h28l1-3c0-11-8-18-19-18zm-10 15c2-4 5-7 10-7s8 3 9 7h-19zm-39 3c0 6 4 10 10 10 4 0 7-2 9-5l8 5c-3 5-9 8-17 8-11 0-19-7-19-18s8-18 19-18c8 0 14 3 17 8l-8 5c-2-3-5-5-9-5-6 0-10 4-10 10zm83-29v46h-9V5h9zM37 0l37 64H0L37 0zm92 5-27 48L74 5h10l18 30 17-30h10zm59 12v10l-3-1c-6 0-10 4-10 10v15h-9V17h9v9c0-5 6-9 13-9z"/></svg>
\ No newline at end of file
diff --git a/src/client/src/app/(auth)/auth-form.tsx b/src/client/src/app/(auth)/auth-form.tsx
index 67b00d96..f9f4b1c0 100644
--- a/src/client/src/app/(auth)/auth-form.tsx
+++ b/src/client/src/app/(auth)/auth-form.tsx
@@ -1,9 +1,11 @@
import asaw from "@/utils/asaw";
import { signIn } from "next-auth/react";
+import Image from "next/image";
import Link from "next/link";
import { useState } from "react";
const errors = {
+ AccessDenied: "Access denied for this account.",
Signin: "Try signing with a different account.",
OAuthSignin: "Try signing with a different account.",
OAuthCallback: "Try signing with a different account.",
@@ -63,12 +65,15 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
}
return (
- <div className="flex h-screen w-screen items-center justify-center">
- <div className="z-10 w-full max-w-md overflow-hidden rounded-2xl shadow-xl">
- <div className="flex flex-col items-center justify-center space-y-3 px-4 py-6 pt-8 text-center sm:px-16">
- <h3 className="text-xl font-semibold">
- {type === "login" ? "Sign In" : "Sign Up"}
- </h3>
+ <div className="flex min-h-screen items-center justify-center bg-secondary p-8">
+ <div className="z-10 w-full max-w-md overflow-hidden rounded bg-tertiary text-secondary">
+ <div className="flex flex-col items-center justify-center space-y-3 px-4 py-6 pt-8 text-center">
+ <Image
+ alt="doku"
+ src="/images/doku-logo-with-name.png"
+ width={836}
+ height={298}
+ />
<p className="text-sm">
{type === "login"
? "Use your email and password to sign in"
@@ -78,7 +83,7 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
{error && <SignInError error={error as keyof typeof errors} />}
<form
action={type === "login" ? login : register}
- className="flex flex-col space-y-4 px-4 py-8 sm:px-16 text-gray-900"
+ className="flex flex-col space-y-4 px-4 py-8 sm:px-16"
>
<div className="flex flex-col w-full items-start">
<label htmlFor="email" className="block text-xs uppercase">
@@ -88,17 +93,14 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
id="email"
name="email"
type="email"
- placeholder="[email protected]"
+ placeholder="[email protected]"
autoComplete="email"
required
- className="mt-1 block w-full appearance-none border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
+ className="mt-1 block w-full appearance-none px-3 py-2 placeholder-secondary/[0.3] focus:outline-none bg-secondary/[0.05]"
/>
</div>
<div className="flex flex-col w-full items-start">
- <label
- htmlFor="password"
- className="block text-xs dark:text-gray-200 uppercase"
- >
+ <label htmlFor="password" className="block text-xs uppercase">
Password
</label>
<input
@@ -106,26 +108,21 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
id="password"
name="password"
type="password"
+ placeholder="********"
required
- className="mt-1 block w-full appearance-none border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
+ className="mt-1 block w-full appearance-none px-3 py-2 placeholder-secondary/[0.3] focus:outline-none bg-secondary/[0.05]"
/>
</div>
- {type === "login" ? (
- <button type="submit" className="p-3">
- Sign in
- </button>
- ) : (
- <button type="submit" className="p-3">
- Sign Up
- </button>
- )}
- <p className="text-center text-sm text-gray-600">
+ <button type="submit" className="p-2 bg-primary text-white rounded">
+ {type === "login" ? "Sign in" : "Sign Up"}
+ </button>
+ <p className="text-center text-sm">
{type === "login"
? "Don't have an account? "
: "Already have an account?"}
<Link
href={type === "login" ? "/register" : "/login"}
- className="font-semibold text-gray-600"
+ className="font-semibold text-secondary"
>
{type === "login" ? " Sign up" : " Sign in"}
</Link>
diff --git a/src/client/src/app/(playground)/api-keys/page.tsx b/src/client/src/app/(playground)/api-keys/page.tsx
index 731732f1..0fb0f339 100644
--- a/src/client/src/app/(playground)/api-keys/page.tsx
+++ b/src/client/src/app/(playground)/api-keys/page.tsx
@@ -1,53 +1,58 @@
"use client";
import AddAPIKeyModal from "@/components/(playground)/add-api-key-modal";
import ConfirmationModal from "@/components/common/confirmation-modal";
-import { deleteData, getData } from "@/utils/api";
+import useFetchWrapper from "@/utils/hooks/useFetchWrapper";
+import { Disclosure } from "@headlessui/react";
import { DocumentDuplicateIcon, TrashIcon } from "@heroicons/react/24/outline";
-import { PlusIcon } from "@heroicons/react/24/solid";
import copy from "copy-to-clipboard";
import { useCallback, useEffect, useRef, useState } from "react";
function ManageKeys() {
- const [data, setData] = useState<Array<any>>([]);
+ const { data, fireRequest: fireGetRequest, isLoading } = useFetchWrapper();
+ const { fireRequest: fireDeleteRequest, isLoading: isDeleting } =
+ useFetchWrapper();
+ const { fireRequest: firePostRequest, isLoading: isCreating } =
+ useFetchWrapper();
const [selectedKey, setSelectedKey] = useState<any>();
const [creating, setCreating] = useState<boolean>(false);
const newCreatedKey = useRef<any>();
- const fetchData = useCallback(async () => {
- const res = await getData({
- method: "GET",
+
+ const fetchData = useCallback(() => {
+ fireGetRequest({
url: "/api/api-key",
+ requestType: "GET",
});
-
- setData(res || []);
}, []);
useEffect(() => {
fetchData();
}, [fetchData]);
- const handleYes = useCallback(async () => {
- await deleteData({
+ const handleYes = useCallback(() => {
+ fireDeleteRequest({
url: `/api/api-key/${selectedKey?.id}`,
+ requestType: "DELETE",
+ successCb: () => {
+ setSelectedKey(null);
+ fetchData();
+ },
});
-
- setSelectedKey(null);
- fetchData();
- }, [selectedKey, fetchData]);
+ }, [selectedKey?.id]);
const handleNo = () => setSelectedKey(null);
- const handleYesCreation = async (name: string) => {
- const res = await getData({
+ const handleYesCreation = useCallback(async (name: string) => {
+ firePostRequest({
url: `/api/api-key`,
- method: "POST",
+ requestType: "POST",
body: JSON.stringify({ name }),
+ successCb: (resp) => {
+ newCreatedKey.current = resp;
+ setCreating(false);
+ fetchData();
+ },
});
-
- newCreatedKey.current = res;
-
- setCreating(false);
- fetchData();
- };
+ }, []);
const handleNoCreation = () => setCreating(false);
@@ -56,16 +61,16 @@ function ManageKeys() {
return (
<>
<table className="w-2/3 text-sm text-left rtl:text-right mt-4">
- <thead className="text-xs text-gray-700 uppercase">
- <tr className="border-b">
+ <thead className="text-xs text-tertiary uppercase">
+ <tr className="border-b border-secondary">
<th className="px-6 py-2 w-1/3">Name</th>
<th className="px-6 py-2 w-1/3">Key</th>
<th className="px-6 py-2 w-1/3">Actions</th>
</tr>
</thead>
<tbody>
- {data.map((item) => (
- <tr className="border-b" key={item.id}>
+ {(data as Array<any>)?.map((item) => (
+ <tr className="border-b border-secondary" key={item.id}>
<td className="px-6 py-3 w-1/3 font-medium ">{item.name}</td>
<td className="px-6 py-3 w-1/3">
{item.api_key}
@@ -84,23 +89,40 @@ function ManageKeys() {
</td>
</tr>
))}
- <tr onClick={() => setCreating(true)}>
- <td
- className="w-full bg-gray-200 hover:bg-gray-300 cursor-pointer py-1"
- colSpan={3}
- >
- <PlusIcon className="w-4 mx-auto" />
- </td>
- </tr>
+ {isLoading && (
+ <tr className="border-b border-secondary animate-pulse">
+ <td className="px-6 py-3 w-1/3 font-medium ">
+ <div className="h-2 w-2/3 bg-secondary/[0.9] rounded"></div>
+ </td>
+ <td className="px-6 py-3 w-1/3">
+ <div className="h-2 w-2/3 bg-secondary/[0.9] rounded"></div>
+ </td>
+ <td className="px-6 py-3 w-1/3">
+ <div className="h-2 w-1/3 bg-secondary/[0.9] rounded"></div>
+ </td>
+ </tr>
+ )}
</tbody>
</table>
+ <button
+ type="button"
+ className="bg-primary/[0.8] text-secondary hover:bg-primary cursor-pointer px-3 py-0.5 text-center text-sm self-start rounded mt-3 outline-none"
+ onClick={() => setCreating(true)}
+ >
+ Add new
+ </button>
{selectedKey?.id && (
- <ConfirmationModal handleNo={handleNo} handleYes={handleYes} />
+ <ConfirmationModal
+ handleNo={handleNo}
+ handleYes={handleYes}
+ isUpdating={isDeleting}
+ />
)}
{creating && (
<AddAPIKeyModal
handleNo={handleNoCreation}
handleYes={handleYesCreation}
+ isCreating={isCreating}
/>
)}
</>
@@ -109,28 +131,38 @@ function ManageKeys() {
export default function APIKeys() {
return (
- <div className="flex flex-col grow w-full h-full rounded overflow-hidden p-2 text-sm">
- <p>
+ <div className="flex flex-col w-full flex-1 overflow-auto">
+ <p className="text-base mb-5 text-tertiary/[0.8]">
Welcome to the API Key Management page. Here, you can view, generate,
and manage API keys for seamless integration with our services. Please
note that we do not display your secret API keys again after you
generate them.
</p>
- <ul className="list-disc list-inside mt-2">
- <li>
- <span className="font-medium">Keep Your Keys Secure:</span> Treat your
- API keys like passwords. Do not share them publicly or expose them in
- places where unauthorized individuals may access them.
- </li>
- <li>
- <span className="font-medium">Rotate Keys Regularly:</span> For
- enhanced security, consider rotating your keys periodically.
- </li>
- <li>
- <span className="font-medium">Revoke Unused Keys:</span> If a key is
- no longer needed or compromised, revoke it immediately.
- </li>
- </ul>
+ <Disclosure defaultOpen>
+ <Disclosure.Button className="flex w-full justify-between rounded-t-lg bg-secondary px-4 py-2 text-left text-sm font-medium text-primary focus:outline-none">
+ Keep Your Keys Secure
+ </Disclosure.Button>
+ <Disclosure.Panel className="p-4 text-sm rounded-b-lg text-tertiary/[0.7] bg-secondary/[0.5]">
+ Treat your API keys like passwords. Do not share them publicly or
+ expose them in places where unauthorized individuals may access them.
+ </Disclosure.Panel>
+ </Disclosure>
+ <Disclosure defaultOpen>
+ <Disclosure.Button className="flex w-full justify-between rounded-t-lg bg-secondary px-4 py-2 text-left text-sm font-medium text-primary focus:outline-none mt-3">
+ Rotate Keys Regularly
+ </Disclosure.Button>
+ <Disclosure.Panel className="p-4 text-sm rounded-b-lg text-tertiary/[0.7] bg-secondary/[0.5]">
+ For enhanced security, consider rotating your keys periodically.
+ </Disclosure.Panel>
+ </Disclosure>
+ <Disclosure defaultOpen>
+ <Disclosure.Button className="flex w-full justify-between rounded-t-lg bg-secondary px-4 py-2 text-left text-sm font-medium text-primary focus:outline-none mt-3">
+ Revoke Unused Keys
+ </Disclosure.Button>
+ <Disclosure.Panel className="p-4 text-sm rounded-b-lg text-tertiary/[0.7] bg-secondary/[0.5]">
+ If a key is no longer needed or compromised, revoke it immediately.
+ </Disclosure.Panel>
+ </Disclosure>
<ManageKeys />
</div>
);
diff --git a/src/client/src/app/(playground)/dashboard/models-categories.tsx b/src/client/src/app/(playground)/dashboard/models-categories.tsx
index 6520e79e..26009221 100644
--- a/src/client/src/app/(playground)/dashboard/models-categories.tsx
+++ b/src/client/src/app/(playground)/dashboard/models-categories.tsx
@@ -2,8 +2,8 @@ import { memo, useCallback, useEffect, useState } from "react";
import { useFilter } from "../filter-context";
import Card from "@/components/common/card";
import { DonutChart } from "@tremor/react";
-import { getData } from "@/utils/api";
import Legend from "@/components/common/legend";
+import useFetchWrapper from "@/utils/hooks/useFetchWrapper";
const COLORS = ["blue-900", "blue-700", "blue-500", "blue-300", "blue-100"];
@@ -24,38 +24,47 @@ const PieChartCard = memo(
url,
}: PieChartCardProps) => {
const [filter] = useFilter();
- const [data, setData] = useState<any[]>([]);
+ const { data, fireRequest, isFetched, isLoading } = useFetchWrapper();
const fetchData = useCallback(async () => {
- const res = await getData({
+ fireRequest({
body: JSON.stringify({
timeLimit: filter.timeLimit,
}),
- method: "POST",
+ requestType: "POST",
url,
+ responseDataKey: "data",
});
-
- setData(res?.data || []);
}, [filter, url]);
useEffect(() => {
if (filter.timeLimit.start && filter.timeLimit.end) fetchData();
}, [filter, fetchData]);
+ const updatedData = data as any[];
+
return (
<Card containerClass={containerClass} heading={heading}>
- <DonutChart
- className="mt-6"
- data={data}
- category={categoryKey}
- index={indexKey}
- colors={COLORS.slice(0, data.length)}
- />
- <Legend
- className="mt-3 flex-col"
- categories={data.map((item: any) => item[indexKey])}
- colors={COLORS.slice(0, data.length)}
- />
+ {isLoading || !isFetched ? (
+ <div className="animate-pulse h-9 w-1/3 bg-secondary/[0.9] rounded"></div>
+ ) : updatedData?.length ? (
+ <>
+ <DonutChart
+ className="mt-6"
+ data={updatedData}
+ category={categoryKey}
+ index={indexKey}
+ colors={COLORS.slice(0, updatedData.length)}
+ />
+ <Legend
+ className="mt-3 flex-col"
+ categories={updatedData.map((item: any) => item[indexKey])}
+ colors={COLORS.slice(0, updatedData.length)}
+ />
+ </>
+ ) : (
+ <div className="text-sm text-tertiary/[0.5]">No data</div>
+ )}
</Card>
);
}
diff --git a/src/client/src/app/(playground)/dashboard/number-stats.tsx b/src/client/src/app/(playground)/dashboard/number-stats.tsx
index 20841eee..62877b9c 100644
--- a/src/client/src/app/(playground)/dashboard/number-stats.tsx
+++ b/src/client/src/app/(playground)/dashboard/number-stats.tsx
@@ -1,31 +1,39 @@
-import { getData } from "@/utils/api";
import { useFilter } from "../filter-context";
-import { memo, useCallback, useEffect, useState } from "react";
+import { memo, useCallback, useEffect } from "react";
import { round } from "lodash";
import Card from "@/components/common/card";
+import useFetchWrapper from "@/utils/hooks/useFetchWrapper";
type StatCardProps = {
containerClass?: string;
dataKey: string;
heading: string;
+ textPrefix?: string;
+ textSuffix?: string;
url: string;
};
const StatCard = memo(
- ({ containerClass = "", dataKey, heading, url }: StatCardProps) => {
+ ({
+ containerClass = "",
+ dataKey,
+ heading,
+ textPrefix = "",
+ textSuffix = "",
+ url,
+ }: StatCardProps) => {
const [filter] = useFilter();
- const [data, setData] = useState<Record<any, any>>();
+ const { data, isFetched, isLoading, fireRequest } = useFetchWrapper();
const fetchData = useCallback(async () => {
- const res = await getData({
+ fireRequest({
body: JSON.stringify({
timeLimit: filter.timeLimit,
}),
- method: "POST",
+ requestType: "POST",
url,
+ responseDataKey: "data[0]",
});
-
- setData(res?.data?.[0] || {});
}, [filter, url]);
useEffect(() => {
@@ -36,7 +44,12 @@ const StatCard = memo(
<Card
containerClass={containerClass}
heading={heading}
- text={`${round(data?.[dataKey] || 0, 2)}`}
+ isLoading={isLoading || !isFetched}
+ text={`${textPrefix}${round(
+ (data as Record<any, any>)?.[dataKey] || 0,
+ 4
+ )}${textSuffix}`}
+ textClass="text-primary"
/>
);
}
@@ -44,7 +57,7 @@ const StatCard = memo(
StatCard.displayName = "StatCard";
-function NumberStats (){
+function NumberStats() {
return (
<div className="flex mb-4">
<StatCard
@@ -57,22 +70,25 @@ function NumberStats (){
containerClass="border-r-0 w-full"
dataKey="average_duration"
heading="Avg Request Duration"
+ textSuffix="s"
url="/api/metrics/request/duration/average"
/>
<StatCard
containerClass="border-r-0 w-full"
dataKey="total_usage_cost"
heading="Total costs"
+ textPrefix="$"
url="/api/metrics/cost/total"
/>
<StatCard
containerClass="rounded-r-lg w-full"
dataKey="average_usage_cost"
heading="Average cost per request"
+ textPrefix="$"
url="/api/metrics/cost/request/average"
/>
</div>
);
-};
+}
export default NumberStats;
diff --git a/src/client/src/app/(playground)/dashboard/page.tsx b/src/client/src/app/(playground)/dashboard/page.tsx
index 3372196c..3f164652 100644
--- a/src/client/src/app/(playground)/dashboard/page.tsx
+++ b/src/client/src/app/(playground)/dashboard/page.tsx
@@ -6,15 +6,15 @@ import RequestsPerTime from "./requests-per-time";
export default function PlaygroundPage() {
return (
- <div className="flex flex-col grow w-full h-full rounded overflow-hidden">
+ <>
<Filter />
- <div className="flex flex-col p-2 grow w-full h-full rounded overflow-y-auto mt-2">
+ <div className="flex flex-col grow w-full h-full rounded overflow-y-auto py-2">
<NumberStats />
<div className="flex flex-col gap-6">
<RequestsPerTime />
<ModelsCategories />
</div>
</div>
- </div>
+ </>
);
}
diff --git a/src/client/src/app/(playground)/dashboard/requests-per-time.tsx b/src/client/src/app/(playground)/dashboard/requests-per-time.tsx
index 6f4bea82..969b6d24 100644
--- a/src/client/src/app/(playground)/dashboard/requests-per-time.tsx
+++ b/src/client/src/app/(playground)/dashboard/requests-per-time.tsx
@@ -1,23 +1,21 @@
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect } from "react";
import { useFilter } from "../filter-context";
import Card from "@/components/common/card";
-import { getData } from "@/utils/api";
import { LineChart } from "@tremor/react";
+import useFetchWrapper from "@/utils/hooks/useFetchWrapper";
-export default function RequestsPerTime () {
+export default function RequestsPerTime() {
const [filter] = useFilter();
-
- const [data, setData] = useState<Array<any>>([]);
+ const { data, fireRequest, isFetched, isLoading } = useFetchWrapper();
const fetchData = useCallback(async () => {
- const res = await getData({
+ fireRequest({
body: JSON.stringify({
timeLimit: filter.timeLimit,
}),
- method: "POST",
+ requestType: "POST",
url: "/api/metrics/request/time",
+ responseDataKey: "data",
});
-
- setData(res?.data || []);
}, [filter]);
useEffect(() => {
@@ -28,11 +26,15 @@ export default function RequestsPerTime () {
<Card heading="Requests per time" containerClass="rounded-lg">
<LineChart
className="mt-6"
- data={data}
+ connectNulls
+ data={isLoading || !isFetched ? [] : (data as any[]) || []}
index="request_time"
categories={["total"]}
colors={["emerald"]}
yAxisWidth={40}
+ noDataText={
+ isLoading || !isFetched ? "Loading ..." : "No data available"
+ }
/>
</Card>
);
diff --git a/src/client/src/app/(playground)/filter-context.tsx b/src/client/src/app/(playground)/filter-context.tsx
index f4071b76..0096a54a 100644
--- a/src/client/src/app/(playground)/filter-context.tsx
+++ b/src/client/src/app/(playground)/filter-context.tsx
@@ -42,7 +42,6 @@ function getTimeLimitObject(value: string, keyPrefix: string) {
set(object, `${keyPrefix}start`, addMonths(currentDate, -1));
set(object, `${keyPrefix}end`, currentDate);
} else if (value === TIME_RANGE_TYPE["3M"]) {
- console.log("valuevaluevalue");
const currentDate = new Date();
set(object, `${keyPrefix}start`, addMonths(currentDate, -3));
set(object, `${keyPrefix}end`, currentDate);
diff --git a/src/client/src/app/(playground)/filter.tsx b/src/client/src/app/(playground)/filter.tsx
index cab8972a..cf052218 100644
--- a/src/client/src/app/(playground)/filter.tsx
+++ b/src/client/src/app/(playground)/filter.tsx
@@ -1,4 +1,4 @@
-import { Tab, TabGroup, TabList } from "@tremor/react";
+import { Tab } from "@headlessui/react";
import {
DEFAULT_TIME_RANGE,
TIME_RANGE_TYPE,
@@ -24,19 +24,25 @@ const Filter = () => {
};
return (
- <div className="flex p-2">
- <TabGroup
- onIndexChange={handleChange}
- defaultIndex={DEFAULT_CHECKED_INDEX}
- >
- <TabList variant="solid">
+ <div className="flex pb-3 pt-2">
+ <Tab.Group defaultIndex={DEFAULT_CHECKED_INDEX} onChange={handleChange}>
+ <Tab.List className="flex space-x-1 rounded-xl bg-secondary/[0.8] p-1">
{TIME_RANGE_TABS.map(({ label, key }) => (
- <Tab key={key} value={key}>
+ <Tab
+ key={key}
+ className={({ selected }) =>
+ `w-full rounded-lg px-2.5 py-1 text-sm ring-white/60 ring-offset-2 focus:outline-none ${
+ selected
+ ? "bg-primary/[0.2] text-primary shadow ring-offset-primary"
+ : "text-tertiary/[0.7] hover:bg-primary/[0.2] hover:text-primary/[0.7]"
+ }`
+ }
+ >
{label}
</Tab>
))}
- </TabList>
- </TabGroup>
+ </Tab.List>
+ </Tab.Group>
</div>
);
};
diff --git a/src/client/src/app/(playground)/layout.tsx b/src/client/src/app/(playground)/layout.tsx
index ca5f46e7..e1f1cf12 100644
--- a/src/client/src/app/(playground)/layout.tsx
+++ b/src/client/src/app/(playground)/layout.tsx
@@ -8,12 +8,16 @@ export default function PlaygroundLayout({
children: React.ReactNode;
}) {
return (
- <div className="h-screen w-screen overflow-hidden flex">
+ <div className="h-screen w-screen overflow-hidden flex bg-secondary/[.6]">
<Sidebar />
<FilterProvider>
- <main className="flex flex-col p-3 w-full h-full overflow-hidden">
- <Header />
- {children}
+ <main className="w-full h-full py-2 pr-2 overflow-hidden">
+ <div className="flex flex-col w-full h-full overflow-hidden rounded-lg bg-white/[0.9]">
+ <Header />
+ <div className="flex flex-col grow w-full h-full px-4 overflow-hidden">
+ {children}
+ </div>
+ </div>
</main>
</FilterProvider>
</div>
diff --git a/src/client/src/app/(playground)/requests/page.tsx b/src/client/src/app/(playground)/requests/page.tsx
index 4b0e615b..b9143a08 100644
--- a/src/client/src/app/(playground)/requests/page.tsx
+++ b/src/client/src/app/(playground)/requests/page.tsx
@@ -1,17 +1,17 @@
"use client";
import RequestTable from "./request-table";
import { useFilter } from "../filter-context";
-import { useCallback, useEffect, useState } from "react";
-import { getData } from "@/utils/api";
+import { useCallback, useEffect } from "react";
import RequestFilter, { FilterConfigProps } from "./request-filter";
import { RequestProvider } from "./request-context";
+import useFetchWrapper from "@/utils/hooks/useFetchWrapper";
+import RequestDetails from "./request-details";
export default function RequestPage() {
const [filter] = useFilter();
- const [data, setData] = useState<Array<any>>([]);
- const [config, setConfig] = useState<FilterConfigProps | undefined>();
+ const { data, fireRequest, isFetched, isLoading } = useFetchWrapper();
const fetchData = useCallback(async () => {
- const res = await getData({
+ fireRequest({
body: JSON.stringify({
timeLimit: filter.timeLimit,
// TODO: send config true based on if the config has not already been fetched or when the timeLimit is changed
@@ -24,12 +24,9 @@ export default function RequestPage() {
limit: filter.limit,
offset: filter.offset,
}),
- method: "POST",
+ requestType: "POST",
url: "/api/metrics/request",
});
-
- if (res?.config) setConfig(res.config);
- setData(res?.records || []);
}, [filter]);
useEffect(() => {
@@ -38,10 +35,15 @@ export default function RequestPage() {
return (
<RequestProvider>
- <div className="flex flex-col grow w-full h-full rounded overflow-hidden">
- <RequestFilter config={config} />
- <RequestTable data={data} />
- </div>
+ <RequestFilter
+ config={(data as any)?.config as FilterConfigProps | undefined}
+ />
+ <RequestTable
+ data={(data as any)?.records || []}
+ isFetched={isFetched}
+ isLoading={isLoading}
+ />
+ <RequestDetails />
</RequestProvider>
);
}
diff --git a/src/client/src/app/(playground)/requests/request-context.tsx b/src/client/src/app/(playground)/requests/request-context.tsx
index 38966896..2c0622e3 100644
--- a/src/client/src/app/(playground)/requests/request-context.tsx
+++ b/src/client/src/app/(playground)/requests/request-context.tsx
@@ -34,6 +34,10 @@ export const RequestMappings = {
label: "Finish Reason",
type: "string",
},
+ id: {
+ label: "Id",
+ type: "string",
+ },
image: {
label: "Image",
type: "string",
@@ -66,6 +70,10 @@ export const RequestMappings = {
label: "Response",
type: "string",
},
+ revisedprompt: {
+ label: "Revised Prompt",
+ type: "string",
+ },
sourcelanguage: {
label: "Source Language",
type: "string",
diff --git a/src/client/src/app/(playground)/requests/request-details.tsx b/src/client/src/app/(playground)/requests/request-details.tsx
new file mode 100644
index 00000000..bb4ffd7b
--- /dev/null
+++ b/src/client/src/app/(playground)/requests/request-details.tsx
@@ -0,0 +1,211 @@
+import { Fragment } from "react";
+import { Dialog, Transition } from "@headlessui/react";
+import {
+ BeakerIcon,
+ CalendarDaysIcon,
+ ClipboardDocumentCheckIcon,
+ ClipboardDocumentListIcon,
+ ClockIcon,
+ CogIcon,
+ CurrencyDollarIcon,
+ GlobeAltIcon,
+ LanguageIcon,
+ PhotoIcon,
+ SpeakerWaveIcon,
+ XMarkIcon,
+} from "@heroicons/react/24/outline";
+import { useRequest } from "@/app/(playground)/requests/request-context";
+import Image from "next/image";
+import { round } from "lodash";
+import { format } from "date-fns";
+
+export default function RequestDetails() {
+ const [request, updateRequest] = useRequest();
+
+ const onClose = () => {
+ updateRequest(null);
+ };
+
+ if (!request) return null;
+
+ return (
+ <Transition.Root show as={Fragment}>
+ <Dialog as="div" className="relative z-10" onClose={onClose}>
+ <Transition.Child
+ as={Fragment}
+ enter="ease-in-out duration-500"
+ enterFrom="opacity-0"
+ enterTo="opacity-100"
+ leave="ease-in-out duration-500"
+ leaveFrom="opacity-100"
+ leaveTo="opacity-0"
+ >
+ <div className="fixed inset-0 bg-tertiary/[0.5] bg-opacity-75 transition-opacity" />
+ </Transition.Child>
+
+ <div className="fixed inset-0 overflow-hidden">
+ <div className="absolute inset-0 overflow-hidden">
+ <div className="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10">
+ <Transition.Child
+ as={Fragment}
+ enter="transform transition ease-in-out duration-500 sm:duration-700"
+ enterFrom="translate-x-full"
+ enterTo="translate-x-0"
+ leave="transform transition ease-in-out duration-500 sm:duration-700"
+ leaveFrom="translate-x-0"
+ leaveTo="translate-x-full"
+ >
+ <Dialog.Panel className="pointer-events-auto relative w-screen max-w-2xl">
+ <div className="flex h-full flex-col overflow-y-scroll bg-white shadow-xl">
+ <div className="p-4 bg-secondary relative">
+ <div className="flex flex-col">
+ <Dialog.Title className="text-2xl font-bold leading-7 text-tertiary">
+ {request.applicationname}
+ </Dialog.Title>
+ <div className="flex items-center mt-3 text-tertiary/[.7]">
+ <BeakerIcon className="w-4 mr-3" />
+ <p className="text-sm leading-none mb-1">
+ {request.endpoint}
+ </p>
+ </div>
+ </div>
+ <Transition.Child
+ as={Fragment}
+ enter="ease-in-out duration-500"
+ enterFrom="opacity-0"
+ enterTo="opacity-100"
+ leave="ease-in-out duration-500"
+ leaveFrom="opacity-100"
+ leaveTo="opacity-0"
+ >
+ <div className="absolute right-0 top-0 flex pr-2 pt-4 sm:pr-4">
+ <button
+ type="button"
+ className="relative rounded-full text-tertiary/[0.7] hover:text-tertiary focus:outline-none"
+ onClick={onClose}
+ >
+ <span className="sr-only">Close panel</span>
+ <XMarkIcon className="h-6 w-6" aria-hidden="true" />
+ </button>
+ </div>
+ </Transition.Child>
+ </div>
+ <div className="relative p-6 flex-1">
+ <div className="flex items-start flex-wrap gap-3">
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <CalendarDaysIcon className="w-3" />
+ <span>Request Time : </span>
+ <span>
+ {format(request.time, "MMM do, y HH:mm:ss a")}
+ </span>
+ </div>
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <ClockIcon className="w-3" />
+ <span>Request duration : </span>
+ <span>{round(request.requestduration, 4)}s</span>
+ </div>
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <CogIcon className="w-3" />
+ <span>Model : </span>
+ <span>{request.model}</span>
+ </div>
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <CurrencyDollarIcon className="w-3" />
+ <span>Usage cost : </span>
+ <span>{round(request.usagecost, 6)}</span>
+ </div>
+ {request.prompttokens && (
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <ClipboardDocumentCheckIcon className="w-3" />
+ <span>Prompt tokens : </span>
+ <span>{request.prompttokens}</span>
+ </div>
+ )}
+ {request.totaltokens && (
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <ClipboardDocumentListIcon className="w-3" />
+ <span>Total tokens : </span>
+ <span>{request.totaltokens}</span>
+ </div>
+ )}
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <LanguageIcon className="w-3" />
+ <span>Source Language : </span>
+ <span>{request.sourcelanguage}</span>
+ </div>
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <GlobeAltIcon className="w-3" />
+ <span>Environment : </span>
+ <span>{request.environment}</span>
+ </div>
+ {request.audiovoice && (
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <SpeakerWaveIcon className="w-3" />
+ <span>Audio voice : </span>
+ <span>{request.audiovoice}</span>
+ </div>
+ )}
+ {request.imagesize && (
+ <div className="flex items-center justify-center space-x-1 px-3 py-1 rounded-full text-xs bg-primary/[0.1] text-primary font-medium">
+ <PhotoIcon className="w-3" />
+ <span>Image size : </span>
+ <span>{request.imagesize}</span>
+ </div>
+ )}
+ </div>
+ <div className="flex flex-col space-y-3 mt-4">
+ <span className="text-sm text-tertiary/[0.8] font-medium">
+ Prompt :{" "}
+ </span>
+ <code className="text-sm inline-flex text-left items-center bg-tertiary text-secondary rounded-md p-4">
+ {request.prompt}
+ </code>
+ </div>
+ {request.revisedprompt && (
+ <div className="flex flex-col space-y-3 mt-4">
+ <span className="text-sm text-tertiary/[0.8] font-medium">
+ Revised Prompt :{" "}
+ </span>
+ <code className="text-sm inline-flex text-left items-center bg-tertiary text-secondary rounded-md p-4">
+ {request.prompt}
+ </code>
+ </div>
+ )}
+ {request.response && (
+ <div className="flex flex-col space-y-3 mt-4">
+ <span className="text-sm text-tertiary/[0.8] font-medium">
+ Response :{" "}
+ </span>
+ <code className="text-sm inline-flex text-left items-center bg-tertiary text-secondary rounded-md p-4">
+ {request.response}
+ </code>
+ </div>
+ )}
+ {request.image && request.imagesize && (
+ <div className="flex items-center justify-center aspect-h-1 aspect-w-1 w-full overflow-hidden rounded-md bg-tertiary/[0.1] lg:aspect-none group-hover:opacity-75 lg:h-80 mt-4">
+ <Image
+ src={request.image}
+ alt={request.applicationname}
+ className="h-full w-full object-cover object-center lg:h-full lg:w-full"
+ width={parseInt(
+ request.imagesize.split("x")[0],
+ 10
+ )}
+ height={parseInt(
+ request.imagesize.split("x")[1],
+ 10
+ )}
+ />
+ </div>
+ )}
+ </div>
+ </div>
+ </Dialog.Panel>
+ </Transition.Child>
+ </div>
+ </div>
+ </div>
+ </Dialog>
+ </Transition.Root>
+ );
+}
diff --git a/src/client/src/app/(playground)/requests/request-filter.tsx b/src/client/src/app/(playground)/requests/request-filter.tsx
index b5916856..a98cace7 100644
--- a/src/client/src/app/(playground)/requests/request-filter.tsx
+++ b/src/client/src/app/(playground)/requests/request-filter.tsx
@@ -32,7 +32,7 @@ export default function RequestFilter({
<Pagination
currentPage={filter.offset / filter.limit + 1}
currentSize={filter.limit}
- totalPage={ceil(config.totalrows / filter.limit)}
+ totalPage={ceil((config.totalrows || 0) / filter.limit)}
onClickPageAction={onClickPageAction}
onClickPageLimit={onClickPageLimit}
/>
diff --git a/src/client/src/app/(playground)/requests/request-table.tsx b/src/client/src/app/(playground)/requests/request-table.tsx
index 432eef43..f6aacd57 100644
--- a/src/client/src/app/(playground)/requests/request-table.tsx
+++ b/src/client/src/app/(playground)/requests/request-table.tsx
@@ -6,94 +6,206 @@ import {
ClockIcon,
CogIcon,
CurrencyDollarIcon,
- EyeIcon,
} from "@heroicons/react/24/outline";
import { format } from "date-fns";
-import { round } from "lodash";
+import { fill, round } from "lodash";
import { DisplayDataRequestMappingKeys, useRequest } from "./request-context";
+import { ReactNode } from "react";
type RenderRowProps = {
item: Record<(typeof DisplayDataRequestMappingKeys)[number], any>;
+ isLoading?: boolean;
};
-const RenderRow = ({ item }: RenderRowProps) => {
- const [, updateRequest] = useRequest();
+const RowItem = ({
+ containerClass = "",
+ icon,
+ label,
+ text,
+ textClass = "",
+}: {
+ containerClass?: string;
+ icon?: ReactNode;
+ label: string;
+ text: string;
+ textClass?: string;
+}) => {
+ return (
+ <div
+ className={`flex ${containerClass} shrink-0 flex-1 relative h-full justify-center items-center p-2 space-x-2`}
+ >
+ {icon && <div className="flex self-start mt-2">{icon}</div>}
+ <div className="flex flex-col w-full justify-center space-y-1">
+ <span
+ className={`leading-none text-ellipsis py-2 overflow-hidden whitespace-nowrap ${textClass}`}
+ >
+ {text}
+ </span>
+ <span className="text-xs text-ellipsis overflow-hidden whitespace-nowrap text-tertiary/[0.4]">
+ {label}
+ </span>
+ </div>
+ </div>
+ );
+};
+
+const RenderRow = ({ item, isLoading }: RenderRowProps) => {
+ const [request, updateRequest] = useRequest();
+
+ const onClick = () => !isLoading && updateRequest(item);
return (
<div className="flex flex-col mb-4">
- <div className="flex items-center border rounded-t border-b-0 py-1 px-3 z-0 self-start bg-gray-200">
+ <div className="flex items-center rounded-t py-1 px-3 z-0 self-start bg-secondary text-primary font-medium">
<div className="flex items-center pr-3">
<CalendarDaysIcon className="w-4" />
- <p className="text-xs leading-none text-gray-600 ml-2">
- {format(item.time, "MMM do, Y")}
+ <p className="text-xs leading-none ml-2">
+ {format(item.time, "MMM do, y HH:mm:ss a")}
</p>
</div>
- <div className="flex items-center pl-3 border-l border-gray-500">
+ <div className="flex items-center pl-3 border-l border-tertiary/[0.2]">
<ClockIcon className="w-4" />
<p className="text-xs leading-none ml-2">
{round(item.requestduration, 4)}s
</p>
</div>
</div>
- <div className="flex items-stretch h-16 border relative items-center px-3 rounded-b">
- <div className="flex items-center w-2/12">
- <p className="text-base leading-none">{item.applicationname}</p>
- </div>
- <div className="flex items-center w-3/12 px-2">
- <BeakerIcon className="w-4 mr-3" />
- <p className="text-sm leading-none mb-1">{item.endpoint}</p>
- </div>
- <div className="flex items-center w-2/12 px-2">
- <CogIcon className="w-4" />
- <p className="text-sm leading-none text-gray-600 ml-2">
- {item.model}
- </p>
- </div>
- <div className="flex items-center justify-center w-2/12 relative">
- <CurrencyDollarIcon className="w-4" />
- <p className="text-sm leading-none text-gray-600 ml-2">
- {round(item.usagecost, 6)}
- </p>
- <p className="text-xs absolute bottom-1 left-0 opacity-30 w-full text-center">
- Usage Cost
- </p>
- </div>
- <div className="flex items-center justify-center w-2/12 relative">
- <ClipboardDocumentCheckIcon className="w-4" />
- <p className="text-sm leading-none text-gray-600 ml-2">
- {item.prompttokens}
- </p>
- <p className="text-xs absolute bottom-1 left-0 opacity-30 w-full text-center">
- Prompt Tokens
- </p>
- </div>
- <div className="flex items-center justify-center w-2/12 relative">
- <ClipboardDocumentListIcon className="w-4" />
- <p className="text-sm leading-none text-gray-600 ml-2">
- {item.totaltokens}
- </p>
- <p className="text-xs absolute bottom-1 left-0 opacity-30 w-full text-center">
- Total Tokens
- </p>
+ <div
+ className={`flex items-stretch h-16 border border-secondary relative items-center px-3 rounded-b cursor-pointer ${
+ request?.id === item.id && "bg-secondary/[0.7]"
+ }`}
+ onClick={onClick}
+ >
+ <RowItem
+ containerClass="w-3/12"
+ label="App name"
+ text={item.applicationname}
+ textClass="font-medium"
+ />
+ <RowItem
+ containerClass="w-3/12"
+ icon={<BeakerIcon className="w-4" />}
+ label="LLM client"
+ text={item.endpoint}
+ textClass="text-sm"
+ />
+ <RowItem
+ containerClass="w-1.5/12"
+ icon={<CogIcon className="w-4" />}
+ label="Model"
+ text={item.model}
+ textClass="text-sm"
+ />
+ <RowItem
+ containerClass="w-1.5/12"
+ icon={<CurrencyDollarIcon className="w-4" />}
+ label="Usage cost"
+ text={`${round(item.usagecost, 6)}`}
+ textClass="text-sm"
+ />
+ <RowItem
+ containerClass="w-1.5/12"
+ icon={<ClipboardDocumentCheckIcon className="w-4" />}
+ label="Prompt Tokens"
+ text={`${item.prompttokens || "-"}`}
+ textClass="text-sm"
+ />
+ <RowItem
+ containerClass="w-1.5/12"
+ icon={<ClipboardDocumentListIcon className="w-4" />}
+ label="Total Tokens"
+ text={`${item.totaltokens || "-"}`}
+ textClass="text-sm"
+ />
+ </div>
+ </div>
+ );
+};
+
+const RowItemLoader = ({
+ icon = false,
+ text = true,
+ width = "",
+}: {
+ icon?: boolean;
+ text?: boolean;
+ width?: string;
+}) => (
+ <div
+ className={`flex ${width} flex-1 shrink-0 relative h-full justify-center items-center py-4 px-2`}
+ >
+ {icon && (
+ <div className="h-3 w-3 mr-3 rounded-full bg-secondary/[0.9] rounded self-start shrink-0" />
+ )}
+ {text && (
+ <div className="flex flex-col w-full justify-center space-y-3">
+ <div className="h-1 w-24 bg-secondary/[0.9] rounded" />
+ <div className="h-1 w-16 bg-secondary/[0.9] rounded" />
+ </div>
+ )}
+ </div>
+);
+
+const RenderRowLoader = () => {
+ return (
+ <div className="flex flex-col mb-4 animate-pulse">
+ <div className="flex items-center rounded-t py-1.5 px-3 z-0 self-start bg-secondary text-primary font-medium">
+ <div className="flex items-center pr-3">
+ <div className="h-3 w-3 mr-2 rounded-full bg-secondary/[0.9] rounded" />
+ <div className="h-1 w-40 bg-secondary/[0.9] rounded" />
</div>
- <div className="flex items-center pl-3">
- <button type="button" onClick={() => updateRequest(item)}>
- <EyeIcon className="w-4" />
- </button>
+ <div className="flex items-center pl-3 border-l border-tertiary/[0.2]">
+ <div className="h-3 w-3 mr-2 rounded-full bg-secondary/[0.9] rounded" />
+ <div className="h-1 w-14 bg-secondary/[0.9] rounded" />
</div>
</div>
+ <div className="flex items-stretch h-16 border border-secondary relative items-center px-3 rounded-b">
+ <RowItemLoader width="w-3/12" />
+ <RowItemLoader icon width="w-3/12" />
+ <RowItemLoader icon width="w-1.5/12" />
+ <RowItemLoader icon width="w-1.5/12" />
+ <RowItemLoader icon width="w-1.5/12" />
+ <RowItemLoader icon width="w-1.5/12" />
+ </div>
</div>
);
};
-export default function RequestTable({ data }: { data: any[] }) {
+const NoDataBoundary = () => (
+ <div className="border border-secondary flex h-full items-center p-4 justify-center text-tertiary/[0.5]">
+ No data available
+ </div>
+);
+
+export default function RequestTable({
+ data,
+ isFetched,
+ isLoading,
+}: {
+ data: any[];
+ isFetched: boolean;
+ isLoading: boolean;
+}) {
return (
- <div className="flex flex-col p-2 w-full relative sm:rounded-lg overflow-hidden mt-3">
- <div className="overflow-auto">
- <div className="flex flex-col w-full text-sm text-left relative">
+ <div className="flex flex-col flex-1 p-2 w-full relative sm:rounded-lg overflow-hidden mt-3">
+ <div className="overflow-auto h-full">
+ <div
+ className={`flex flex-col w-full h-full text-sm text-left relative ${
+ isFetched && isLoading ? "animate-pulse" : ""
+ }`}
+ >
+ {(!isFetched || (isLoading && !data?.length)) &&
+ fill(new Array(5), 1).map((_, index) => (
+ <RenderRowLoader key={`item-loader-${index}`} />
+ ))}
{data.map((item, index) => (
- <RenderRow key={`item-${index}`} item={item} />
+ <RenderRow
+ key={`item-${index}`}
+ item={item}
+ isLoading={isLoading}
+ />
))}
+ {!data?.length && !isLoading && <NoDataBoundary />}
</div>
</div>
</div>
diff --git a/src/client/src/app/api/api-key/[id]/route.ts b/src/client/src/app/api/api-key/[id]/route.ts
index 66d1191f..0c082766 100644
--- a/src/client/src/app/api/api-key/[id]/route.ts
+++ b/src/client/src/app/api/api-key/[id]/route.ts
@@ -2,7 +2,7 @@ import { deleteAPIKey } from "@/lib/api-key";
export async function DELETE(_: Request, context: any) {
const { id } = context.params;
- const [err, res] = await deleteAPIKey(parseInt(id, 10));
+ const [err, res] = await deleteAPIKey(id);
if (err)
return Response.json(err, {
status: 400,
diff --git a/src/client/src/app/favicon.ico b/src/client/src/app/favicon.ico
index 718d6fea..1a459b6f 100644
Binary files a/src/client/src/app/favicon.ico and b/src/client/src/app/favicon.ico differ
diff --git a/src/client/src/app/page.tsx b/src/client/src/app/page.tsx
index 7a7a80c3..8eb679d7 100644
--- a/src/client/src/app/page.tsx
+++ b/src/client/src/app/page.tsx
@@ -1,17 +1,16 @@
import { ArrowRightIcon } from "@heroicons/react/24/solid";
-import { Metadata } from "next";
import Image from "next/image";
export default function Home() {
return (
- <>
- <section className="w-full px-8 text-gray-700 bg-white">
+ <div className="flex flex-col w-full min-h-screen bg-secondary">
+ <section className="w-full px-8">
<div className="container flex w-full items-center justify-between py-5">
<a
href="/"
- className="flex items-center font-medium text-gray-900 lg:w-auto lg:items-center lg:justify-center md:mb-0 shrink-0"
+ className="flex items-center font-medium text-tertiary lg:w-auto lg:items-center lg:justify-center md:mb-0 shrink-0"
>
- <span className="mx-auto text-xl font-black leading-none text-gray-900 select-none">
+ <span className="mx-auto text-xl font-black leading-none select-none">
Doku
</span>
</a>
@@ -19,11 +18,11 @@ export default function Home() {
<div className="flex grow items-center ml-5 space-x-6 justify-end">
<a
href="https://github.com/dokulabs/doku"
- className="text-base font-medium leading-6 text-gray-600 whitespace-no-wrap transition duration-150 ease-in-out hover:text-gray-900"
+ className="text-base font-medium leading-6 whitespace-no-wrap transition duration-150 ease-in-out"
>
<Image
alt="github"
- src="/github-mark.svg"
+ src="/images/github-mark.svg"
width={30}
height={30}
/>
@@ -32,18 +31,18 @@ export default function Home() {
</div>
</section>
- <section className="px-2 py-32 bg-white md:px-0">
+ <section className="px-2 py-32 md:px-0">
<div className="container items-center max-w-6xl px-8 mx-auto xl:px-5">
<div className="flex flex-wrap items-center sm:-mx-3">
<div className="w-full md:w-1/2 md:px-3">
<div className="w-full pb-6 space-y-6 sm:max-w-md lg:max-w-lg md:space-y-4 lg:space-y-8 xl:space-y-9 sm:pr-5 lg:pr-0 md:pb-0">
- <h1 className="text-4xl font-extrabold tracking-tight text-gray-900 sm:text-5xl md:text-4xl lg:text-5xl xl:text-6xl">
- <span className="block xl:inline">Doku - </span>
- <span className="block text-orange-600 xl:inline">
+ <h1 className="text-4xl font-extrabold tracking-tight sm:text-5xl md:text-4xl lg:text-5xl xl:text-6xl">
+ <span className="block xl:inline text-tertiary">Doku - </span>
+ <span className="block text-primary xl:inline">
LLM Observability
</span>
</h1>
- <p className="mx-auto text-base text-gray-500 sm:max-w-md lg:text-xl md:max-w-3xl">
+ <p className="mx-auto text-base text-tertiary/[0.8] sm:max-w-md lg:text-xl md:max-w-3xl">
An open source tool designed to collect and understand the
usage of Large Language Models (LLMs).
</p>
@@ -60,12 +59,17 @@ export default function Home() {
</div>
<div className="w-full md:w-1/2">
<div className="w-full h-auto overflow-hidden rounded-md shadow-xl sm:rounded-xl">
- <img src="/banner.gif" />
+ <Image
+ alt="doku"
+ src="/images/banner.gif"
+ width={600}
+ height={300}
+ />
</div>
</div>
</div>
</div>
</section>
- </>
+ </div>
);
}
diff --git a/src/client/src/components/(playground)/add-api-key-modal.tsx b/src/client/src/components/(playground)/add-api-key-modal.tsx
index b0b12f7f..060d9ddb 100644
--- a/src/client/src/components/(playground)/add-api-key-modal.tsx
+++ b/src/client/src/components/(playground)/add-api-key-modal.tsx
@@ -4,6 +4,7 @@ import { useRef } from "react";
type AddAPIKeyModalProps = {
handleYes: (name: string) => void;
handleNo: () => void;
+ isCreating?: boolean;
};
export default function AddAPIKeyModal(props: AddAPIKeyModalProps) {
@@ -15,43 +16,36 @@ export default function AddAPIKeyModal(props: AddAPIKeyModalProps) {
};
return (
- <div className="overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 flex justify-center items-center w-full h-full bg-gray-900/[.6]">
+ <div className="overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 flex justify-center items-center w-full h-full bg-tertiary/[.6]">
<form>
<div className="relative p-4 w-full max-w-md h-full md:h-auto">
- <div className="relative p-4 text-center bg-white rounded-lg shadow dark:bg-gray-800 sm:p-5">
+ <div className="relative p-4 text-center bg-white rounded sm:p-5">
<button
type="button"
- className="text-gray-400 absolute top-2.5 right-2.5 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center dark:hover:bg-gray-600 dark:hover:text-white"
+ className="absolute top-2 right-2 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center text-tertiary/[0.5]"
onClick={props.handleNo}
>
<XCircleIcon className="w-5" />
</button>
- <p className="mb-4 text-gray-500 dark:text-gray-300">
- Create an API Key
- </p>
- <div className="flex items-center my-3">
- <label
- htmlFor="name"
- className="block text-sm font-medium leading-6 text-gray-900 mr-3"
- >
- Name :
- </label>
- <div className="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600 sm:max-w-md">
- <input
- type="text"
- name="name"
- className="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6 w-48"
- placeholder="testing"
- ref={nameRef}
- required
- />
- </div>
+ <p className="mb-4 text-tertiary text-left">Create an API Key</p>
+ <div className="flex items-center my-3 outine-none border-b w-64">
+ <input
+ type="text"
+ name="name"
+ className="block flex-1 border-0 bg-transparent py-1.5 px-3 text-primary placeholder:text-primary/[0.3] sm:text-sm outine-none focus:outine-none"
+ placeholder="Name: testing"
+ ref={nameRef}
+ required
+ />
</div>
<div className="flex justify-end">
<button
type="button"
- className="py-2 px-3 text-sm font-medium text-center text-white bg-red-600 rounded-lg hover:bg-red-700 focus:ring-4 focus:outline-none focus:ring-red-300 dark:bg-red-500 dark:hover:bg-red-600 dark:focus:ring-red-900"
+ className={`py-2 px-3 text-sm text-center text-white bg-primary/[0.9] rounded hover:bg-primary outline-none ${
+ props.isCreating ? "animate-pulse" : ""
+ }`}
onClick={handleYes}
+ disabled={!!props.isCreating}
>
Create
</button>
diff --git a/src/client/src/components/(playground)/header.tsx b/src/client/src/components/(playground)/header.tsx
index 3963298a..eba2f459 100644
--- a/src/client/src/components/(playground)/header.tsx
+++ b/src/client/src/components/(playground)/header.tsx
@@ -4,8 +4,8 @@ import { usePathname } from "next/navigation";
export default function Header() {
const pathname = usePathname();
return (
- <div className="relative flex shrink-0 p-2 mb-2">
- <div className="flex flex-1 overflow-y-auto uppercase text-xl">
+ <div className="relative flex shrink-0 px-4 p-3 mb-3 border-b border-secondary text-tertiary">
+ <div className="flex flex-1 overflow-y-auto capitalize text-xl font-semibold">
{pathname.substring(1).replaceAll("-", " ")}
</div>
</div>
diff --git a/src/client/src/components/(playground)/sidebar.tsx b/src/client/src/components/(playground)/sidebar.tsx
index 83adbde6..07ec0436 100644
--- a/src/client/src/components/(playground)/sidebar.tsx
+++ b/src/client/src/components/(playground)/sidebar.tsx
@@ -3,7 +3,6 @@
import { signOut } from "next-auth/react";
import { ReactElement } from "react";
import {
- ArrowLeftCircleIcon,
CircleStackIcon,
HomeModernIcon,
KeyIcon,
@@ -11,9 +10,9 @@ import {
import Image from "next/image";
import { usePathname } from "next/navigation";
-type SidebarItem = {
+type SidebarItemProps = {
className?: string;
- icon: ReactElement;
+ icon?: ReactElement;
text: string;
link?: string;
onClick?: any;
@@ -22,7 +21,7 @@ type SidebarItem = {
const ICON_CLASSES =
"flex-shrink-0 w-6 h-6 transition duration-75 transition duration-75";
-const SIDEBAR_ITEMS = [
+const SIDEBAR_ITEMS: SidebarItemProps[] = [
{
icon: <HomeModernIcon className={ICON_CLASSES} />,
text: "Dashboard",
@@ -38,14 +37,16 @@ const SIDEBAR_ITEMS = [
text: "API keys",
link: "/api-keys",
},
+];
+
+const SIDEBAR_BOTTOM_ITEMS: SidebarItemProps[] = [
{
- icon: <ArrowLeftCircleIcon className={ICON_CLASSES} />,
text: "Signout",
onClick: signOut,
},
];
-const SidebarItem = (props: SidebarItem) => {
+const SidebarItem = (props: SidebarItemProps) => {
return (
<a
href={props.link}
@@ -55,7 +56,9 @@ const SidebarItem = (props: SidebarItem) => {
onClick={props.onClick}
>
{props.icon}
- <span className="ml-5 text-nowrap">{props.text}</span>
+ <span className={`${props.icon && "ml-5"} text-nowrap`}>
+ {props.text}
+ </span>
</a>
);
};
@@ -65,13 +68,13 @@ export default function Sidebar() {
return (
<aside
- className={`flex flex-col flex-shrink-0 w-48 h-full font-normal duration-75 transition-width border-r px-1`}
+ className={`flex flex-col flex-shrink-0 w-48 h-full font-normal duration-75 transition-width`}
aria-label="Sidebar"
>
<div className="relative flex flex-col flex-1 min-h-0 gap-2">
<div className="flex shrink-0 pt-2 relative items-center">
<SidebarItem
- className="w-full"
+ className="w-full text-tertiary font-bold"
link="/"
icon={
<Image
@@ -86,12 +89,30 @@ export default function Sidebar() {
text="Doku"
/>
</div>
- <div className="w-full border-t margin-y-2" />
+ <div className="w-full margin-y-2" />
<ul className="flex-1 pt-2 space-y-2">
{SIDEBAR_ITEMS.map((item, index) => (
<li key={`sidebar-${index}`}>
<SidebarItem
- className={item.link === pathname ? "border-r-4" : ""}
+ className={
+ item.link === pathname
+ ? "border-r-4 border-primary text-primary bg-primary/[.09]"
+ : "text-tertiary"
+ }
+ {...item}
+ />
+ </li>
+ ))}
+ </ul>
+ <ul className="shrink-0 space-y-2 bg-secondary/[0.9]">
+ {SIDEBAR_BOTTOM_ITEMS.map((item, index) => (
+ <li key={`sidebar-${index}`}>
+ <SidebarItem
+ className={
+ item.link === pathname
+ ? "border-r-4 border-primary text-primary bg-primary/[.09]"
+ : "text-tertiary/[0.5] justify-center"
+ }
{...item}
/>
</li>
diff --git a/src/client/src/components/common/card.tsx b/src/client/src/components/common/card.tsx
index 675f15fe..066f2e41 100644
--- a/src/client/src/components/common/card.tsx
+++ b/src/client/src/components/common/card.tsx
@@ -4,19 +4,29 @@ type CardProps = {
children?: ReactNode;
containerClass?: string;
heading: string;
+ isLoading?: boolean;
text?: string;
+ textClass?: string;
};
export default function Card({
children = null,
containerClass = "",
heading,
+ isLoading,
text,
+ textClass = "",
}: CardProps) {
return (
- <div className={`border relative text-left p-6 ${containerClass}`}>
+ <div
+ className={`border border-secondary relative text-left text-tertiary p-6 ${containerClass}`}
+ >
<p className="text-sm mb-4">{heading}</p>
- {text && <p className="font-semibold text-3xl">{text}</p>}
+ {!!isLoading ? (
+ <div className="animate-pulse h-9 w-12 bg-secondary/[0.9] rounded-full" />
+ ) : (
+ text && <p className={`font-semibold text-3xl ${textClass}`}>{text}</p>
+ )}
{children}
</div>
);
diff --git a/src/client/src/components/common/confirmation-modal.tsx b/src/client/src/components/common/confirmation-modal.tsx
index 6fa08ac8..1023d2d8 100644
--- a/src/client/src/components/common/confirmation-modal.tsx
+++ b/src/client/src/components/common/confirmation-modal.tsx
@@ -3,35 +3,38 @@ import { XCircleIcon } from "@heroicons/react/24/outline";
type ConfirmationModalProps = {
handleYes: () => void;
handleNo: () => void;
+ isUpdating?: boolean;
};
export default function ConfirmationModal(props: ConfirmationModalProps) {
return (
- <div className="overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 flex justify-center items-center w-full h-full bg-gray-900/[.6]">
+ <div className="overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 flex justify-center items-center w-full h-full bg-tertiary/[.6]">
<div className="relative p-4 w-full max-w-md h-full md:h-auto">
- <div className="relative p-4 text-center bg-white rounded-lg shadow dark:bg-gray-800 sm:p-5">
+ <div className="relative p-4 text-center bg-white rounded sm:p-5">
<button
type="button"
- className="text-gray-400 absolute top-2.5 right-2.5 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center dark:hover:bg-gray-600 dark:hover:text-white"
+ className="absolute top-2 right-2 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center text-tertiary/[0.5]"
onClick={props.handleNo}
>
<XCircleIcon className="w-5" />
</button>
- <p className="mb-4 text-gray-500 dark:text-gray-300">
+ <p className="mb-4 text-tertiary text-left">
Are you sure you want to delete this item?
</p>
- <div className="flex justify-center items-center space-x-4">
+ <div className="flex items-center space-x-4 w-full">
<button
type="button"
- className="py-2 px-3 text-sm font-medium text-gray-500 bg-white rounded-lg border border-gray-200 hover:bg-gray-100 focus:ring-4 focus:outline-none focus:ring-primary-300 hover:text-gray-900 focus:z-10 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-500 dark:hover:text-white dark:hover:bg-gray-600 dark:focus:ring-gray-600"
+ className="py-2 px-3 text-sm text-tertiary bg-secondary rounded outline-none flex-1"
onClick={props.handleNo}
+ disabled={!!props.isUpdating}
>
No, cancel
</button>
<button
type="button"
- className="py-2 px-3 text-sm font-medium text-center text-white bg-red-600 rounded-lg hover:bg-red-700 focus:ring-4 focus:outline-none focus:ring-red-300 dark:bg-red-500 dark:hover:bg-red-600 dark:focus:ring-red-900"
+ className="py-2 px-3 text-sm text-center text-white bg-primary rounded outline-none"
onClick={props.handleYes}
+ disabled={!!props.isUpdating}
>
Yes, I&apos;m sure
</button>
diff --git a/src/client/src/components/common/pagination.tsx b/src/client/src/components/common/pagination.tsx
index fa256569..ebd8b660 100644
--- a/src/client/src/components/common/pagination.tsx
+++ b/src/client/src/components/common/pagination.tsx
@@ -30,7 +30,7 @@ export default function Pagination(props: PaginationProps) {
const onSizeChange: MouseEventHandler = (ev) => {
const { size = "10" } = (ev.currentTarget as HTMLButtonElement).dataset;
props.onClickPageLimit(parseInt(size, 10));
- setIsMenuOpen(false);
+ setIsMenuOpen(false);
};
const handleClickOutside = (event: MouseEvent) => {
@@ -59,7 +59,7 @@ export default function Pagination(props: PaginationProps) {
<div className="relative flex items-center mr-5" ref={dropdownRef}>
<button
type="button"
- className="inline-flex justify-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-xs ring-1 ring-inset ring-gray-300"
+ className="inline-flex justify-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-xs ring-1 ring-inset ring-tertiary/[.2]"
onClick={() => setIsMenuOpen((e) => !e)}
>
{props.currentSize}
@@ -73,8 +73,8 @@ export default function Pagination(props: PaginationProps) {
{PageSizes.map((size: number) => (
<button
key={`size-${size}`}
- className={`text-gray-700 block px-4 py-2 text-sm hover:bg-gray-50 ${
- props.currentSize === size ? "bg-gray-50" : ""
+ className={`text-tertiary/[0.7] block px-4 py-2 text-sm hover:bg-secondary/[0.6] ${
+ props.currentSize === size ? "bg-secondary/[0.6]" : ""
}`}
data-size={size}
onClick={onSizeChange}
@@ -84,9 +84,12 @@ export default function Pagination(props: PaginationProps) {
))}
</div>
</div>
+ <div className="flex items-center mr-5 text-sm text-tertiary/[0.5]">
+ {props.currentPage} of {props.totalPage}
+ </div>
<div className="flex rounded-md shadow-sm" aria-label="Pagination">
<button
- className="relative inline-flex items-center rounded-l-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0 disabled:opacity-40 disabled:cursor-not-allowed"
+ className="relative inline-flex items-center rounded-l-md px-2 py-2 text-tertiary ring-1 ring-inset ring-tertiary/[.15] hover:bg-secondary focus:z-20 focus:outline-offset-0 disabled:opacity-40 disabled:cursor-not-allowed"
data-action="previous"
disabled={firstPage}
onClick={onClickAction}
@@ -94,7 +97,7 @@ export default function Pagination(props: PaginationProps) {
<ChevronLeftIcon className="w-4" />
</button>
<button
- className="relative inline-flex items-center rounded-r-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0 disabled:opacity-40 disabled:cursor-not-allowed"
+ className="relative inline-flex items-center rounded-r-md px-2 py-2 text-tertiary ring-1 ring-inset ring-tertiary/[.15] hover:bg-secondary focus:z-20 focus:outline-offset-0 disabled:opacity-40 disabled:cursor-not-allowed"
data-action="next"
disabled={lastPage}
onClick={onClickAction}
diff --git a/src/client/src/lib/api-key.ts b/src/client/src/lib/api-key.ts
index b2a31fdf..e9333a60 100644
--- a/src/client/src/lib/api-key.ts
+++ b/src/client/src/lib/api-key.ts
@@ -10,7 +10,7 @@ type GenerateAPIKeyProps = {
export async function generateAPIKey(params: GenerateAPIKeyProps) {
const api_key = crypto.randomBytes(32).toString("hex");
return await asaw(
- prisma.apikey.create({
+ prisma.doku_apikeys.create({
data: {
name: params.name,
api_key,
@@ -20,10 +20,10 @@ export async function generateAPIKey(params: GenerateAPIKeyProps) {
}
export async function getAPIKeys() {
- const [, data] = await asaw(prisma.apikey.findMany());
+ const [, data] = await asaw(prisma.doku_apikeys.findMany());
return normalizeAPIKeys(data);
}
-export async function deleteAPIKey(id: number) {
- return await asaw(prisma.apikey.delete({ where: { id } }));
+export async function deleteAPIKey(id: string) {
+ return await asaw(prisma.doku_apikeys.delete({ where: { id } }));
}
diff --git a/src/client/src/lib/doku/common.ts b/src/client/src/lib/doku/common.ts
index fc591142..e1fe8845 100644
--- a/src/client/src/lib/doku/common.ts
+++ b/src/client/src/lib/doku/common.ts
@@ -1,6 +1,6 @@
import { Prisma, PrismaClient } from ".prisma/client";
-export const TABLE_NAME = "doku";
+export const TABLE_NAME = "DOKU_LLM_DATA";
export type TimeLimit = {
start: Date;
diff --git a/src/client/src/middleware.ts b/src/client/src/middleware.ts
index eebf1c48..db4e70f4 100644
--- a/src/client/src/middleware.ts
+++ b/src/client/src/middleware.ts
@@ -4,12 +4,19 @@ import { NextResponse } from "next/server";
export default withAuth(
async function middleware(req) {
+ const pathname = req.nextUrl.pathname;
+ if (
+ pathname.startsWith("/_next") ||
+ pathname.startsWith("/static") ||
+ pathname.startsWith("/images")
+ )
+ return NextResponse.next();
+
const token = await getToken({ req });
const isAuth = !!token;
const isAuthPage =
- req.nextUrl.pathname.startsWith("/login") ||
- req.nextUrl.pathname.startsWith("/register");
- const isApiPage = req.nextUrl.pathname.startsWith("/api");
+ pathname.startsWith("/login") || pathname.startsWith("/register");
+ const isApiPage = pathname.startsWith("/api");
if (isAuthPage) {
if (isAuth) {
@@ -26,7 +33,7 @@ export default withAuth(
}
if (!isAuth) {
- let from = req.nextUrl.pathname;
+ let from = pathname;
if (req.nextUrl.search) {
from += req.nextUrl.search;
}
@@ -49,5 +56,12 @@ export default withAuth(
);
export const config = {
- matcher: ["/api/:path*", "/dashboard/:path*", "/login", "/register"],
+ matcher: [
+ "/api/:path*",
+ "/login",
+ "/register",
+ "/dashboard",
+ "/api-keys",
+ "/requests",
+ ],
};
diff --git a/src/client/src/utils/api-key.ts b/src/client/src/utils/api-key.ts
index 65fdd667..292d3954 100644
--- a/src/client/src/utils/api-key.ts
+++ b/src/client/src/utils/api-key.ts
@@ -1,10 +1,10 @@
-import { apikey } from "@prisma/client";
+import { doku_apikeys } from "@prisma/client";
export function maskingKey(key: string) {
return key.slice(0, 3) + "..." + key.slice(-3);
}
-export function normalizeAPIKeys(params: apikey[] | null | undefined) {
+export function normalizeAPIKeys(params: doku_apikeys[] | null | undefined) {
if (params?.length)
return params.map((p) => ({ ...p, api_key: maskingKey(p.api_key) }));
}
diff --git a/src/client/src/utils/api.ts b/src/client/src/utils/api.ts
index faa40472..fbd14575 100644
--- a/src/client/src/utils/api.ts
+++ b/src/client/src/utils/api.ts
@@ -17,6 +17,7 @@ export async function getData({ body, method = "POST", url }: GET_DATA) {
type DELETE_DATA = {
url: string;
};
+
export async function deleteData({ url }: DELETE_DATA) {
const res = await fetch(url, { method: "DELETE" });
if (!res.ok) {
diff --git a/src/client/src/utils/hooks/useFetchWrapper.ts b/src/client/src/utils/hooks/useFetchWrapper.ts
new file mode 100644
index 00000000..98c0269b
--- /dev/null
+++ b/src/client/src/utils/hooks/useFetchWrapper.ts
@@ -0,0 +1,59 @@
+import { get } from "lodash";
+import { useCallback, useState } from "react";
+import { deleteData, getData } from "@/utils/api";
+
+type useFetchWrapperProps = {
+ body?: string;
+ failureCb?: () => void;
+ url: string;
+ requestType: "GET" | "POST" | "DELETE";
+ responseDataKey?: string;
+ successCb?: (res?: any) => void;
+};
+
+export default function useFetchWrapper() {
+ const [data, setData] = useState<unknown>(null);
+ const [isLoading, setIsLoading] = useState<boolean>(false);
+ const [error, setError] = useState<unknown>(null);
+ const [isFetched, setIsFetched] = useState<boolean>(false);
+
+ const fireRequest = useCallback(
+ async ({
+ body,
+ failureCb,
+ url,
+ requestType,
+ responseDataKey = "",
+ successCb,
+ }: useFetchWrapperProps) => {
+ setIsLoading(true);
+ try {
+ let response;
+ if (requestType === "GET" || requestType === "POST") {
+ response = await getData({
+ body,
+ url,
+ method: requestType,
+ });
+ } else if (requestType === "DELETE") {
+ response = await deleteData({
+ url,
+ });
+ }
+
+ const finalResponse = get(response, responseDataKey, response);
+ setData(finalResponse);
+ if (typeof successCb === "function") successCb(finalResponse);
+ } catch (error) {
+ setError(error);
+ if (typeof failureCb === "function") failureCb();
+ }
+
+ setIsLoading(false);
+ setIsFetched(true);
+ },
+ [setData, setError, setIsFetched, setIsLoading]
+ );
+
+ return { data, fireRequest, error, isFetched, isLoading };
+}
diff --git a/src/client/tailwind.config.ts b/src/client/tailwind.config.ts
index 815bbc35..a13e4820 100644
--- a/src/client/tailwind.config.ts
+++ b/src/client/tailwind.config.ts
@@ -15,14 +15,12 @@ export default {
colors: {
darkMode: {
primary: "#0C120C",
- secondary: "#DE541E",
- tertiary: "#C0C5C1",
- blue: "#003F91",
+ secondary: "#212738",
+ tertiary: "#FFF4D8",
},
- primary: "#0C120C",
- secondary: "#DE541E",
- tertiary: "#C0C5C1",
- blue: "#003F91",
+ primary: "#F36C06",
+ secondary: "#FFF4D8",
+ tertiary: "#212738",
// light mode
tremor: {
brand: {