From 0e0a2c6d1236f91ad431626c53ef290f5ff148f5 Mon Sep 17 00:00:00 2001 From: "Amagi:DDmxh" Date: Tue, 18 Feb 2025 02:30:05 +0800 Subject: [PATCH 1/2] add new shadcn label and switch components --- components.json | 1 + components/ui/label.tsx | 26 ++++++++++++++++++ components/ui/switch.tsx | 30 +++++++++++++++++++++ package.json | 4 ++- pnpm-lock.yaml | 58 +++++++++++++++++++++++++++++++++++++++- 5 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 components/ui/label.tsx create mode 100644 components/ui/switch.tsx diff --git a/components.json b/components.json index 15f2b02..a01831e 100644 --- a/components.json +++ b/components.json @@ -12,6 +12,7 @@ }, "aliases": { "components": "@/components", + "ui": "@/components/ui", "utils": "@/lib/utils" } } \ No newline at end of file diff --git a/components/ui/label.tsx b/components/ui/label.tsx new file mode 100644 index 0000000..5341821 --- /dev/null +++ b/components/ui/label.tsx @@ -0,0 +1,26 @@ +"use client" + +import * as React from "react" +import * as LabelPrimitive from "@radix-ui/react-label" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const labelVariants = cva( + "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" +) + +const Label = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & + VariantProps +>(({ className, ...props }, ref) => ( + +)) +Label.displayName = LabelPrimitive.Root.displayName + +export { Label } diff --git a/components/ui/switch.tsx b/components/ui/switch.tsx new file mode 100644 index 0000000..7e6c8b0 --- /dev/null +++ b/components/ui/switch.tsx @@ -0,0 +1,30 @@ +"use client"; + +import * as React from "react"; +import * as SwitchPrimitives from "@radix-ui/react-switch"; + +import { cn } from "@/lib/utils"; + +const Switch = ({ + className, + ref, + ...props +}: React.ComponentProps) => ( + + + +); +Switch.displayName = SwitchPrimitives.Root.displayName; + +export { Switch }; diff --git a/package.json b/package.json index b7a5039..b538cf4 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,11 @@ "@opennextjs/aws": "^3.4.2", "@opennextjs/cloudflare": "^0.4.8", "@radix-ui/react-dialog": "^1.1.6", + "@radix-ui/react-label": "^2.1.2", "@radix-ui/react-select": "^2.1.6", "@radix-ui/react-slider": "^1.2.3", "@radix-ui/react-slot": "^1.1.2", + "@radix-ui/react-switch": "^1.1.3", "@radix-ui/react-tooltip": "^1.1.8", "ai": "^4.1.17", "autoprefixer": "10.4.17", @@ -41,7 +43,7 @@ "tailwindcss": "3.4.1", "tailwindcss-animate": "^1.0.7", "typescript": "5.3.3", - "usehooks-ts": "^3.1.0", + "usehooks-ts": "^3.1.1", "zod": "^3.24.1" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c785ef1..70e7599 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: '@radix-ui/react-dialog': specifier: ^1.1.6 version: 1.1.6(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + '@radix-ui/react-label': + specifier: ^2.1.2 + version: 2.1.2(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) '@radix-ui/react-select': specifier: ^2.1.6 version: 2.1.6(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -38,6 +41,9 @@ importers: '@radix-ui/react-slot': specifier: ^1.1.2 version: 1.1.2(@types/react@19.0.8)(react@19.0.0) + '@radix-ui/react-switch': + specifier: ^1.1.3 + version: 1.1.3(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) '@radix-ui/react-tooltip': specifier: ^1.1.8 version: 1.1.8(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -111,7 +117,7 @@ importers: specifier: 5.3.3 version: 5.3.3 usehooks-ts: - specifier: ^3.1.0 + specifier: ^3.1.1 version: 3.1.1(react@19.0.0) zod: specifier: ^3.24.1 @@ -1245,6 +1251,19 @@ packages: '@types/react': optional: true + '@radix-ui/react-label@2.1.2': + resolution: {integrity: sha512-zo1uGMTaNlHehDyFQcDZXRJhUPDuukcnHz0/jnrup0JA6qL+AFpAnty+7VKa9esuU5xTblAZzTGYJKSKaBxBhw==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + '@radix-ui/react-popper@1.2.2': resolution: {integrity: sha512-Rvqc3nOpwseCyj/rgjlJDYAgyfw7OC1tTkKn2ivhaMGcYt8FSBlahHOZak2i3QwkRXUXgGgzeEe2RuqeEHuHgA==} peerDependencies: @@ -1332,6 +1351,19 @@ packages: '@types/react': optional: true + '@radix-ui/react-switch@1.1.3': + resolution: {integrity: sha512-1nc+vjEOQkJVsJtWPSiISGT6OKm4SiOdjMo+/icLxo2G4vxz1GntC5MzfL4v8ey9OEfw787QCD1y3mUv0NiFEQ==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + '@radix-ui/react-tooltip@1.1.8': resolution: {integrity: sha512-YAA2cu48EkJZdAMHC0dqo9kialOcRStbtiY4nJPaht7Ptrhcvpo+eDChaM6BIs8kL6a8Z5l5poiqLnXcNduOkA==} peerDependencies: @@ -5224,6 +5256,15 @@ snapshots: optionalDependencies: '@types/react': 19.0.8 + '@radix-ui/react-label@2.1.2(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)': + dependencies: + '@radix-ui/react-primitive': 2.0.2(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + react: 19.0.0 + react-dom: 19.0.0(react@19.0.0) + optionalDependencies: + '@types/react': 19.0.8 + '@types/react-dom': 19.0.3(@types/react@19.0.8) + '@radix-ui/react-popper@1.2.2(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)': dependencies: '@floating-ui/react-dom': 2.1.2(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -5326,6 +5367,21 @@ snapshots: optionalDependencies: '@types/react': 19.0.8 + '@radix-ui/react-switch@1.1.3(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)': + dependencies: + '@radix-ui/primitive': 1.1.1 + '@radix-ui/react-compose-refs': 1.1.1(@types/react@19.0.8)(react@19.0.0) + '@radix-ui/react-context': 1.1.1(@types/react@19.0.8)(react@19.0.0) + '@radix-ui/react-primitive': 2.0.2(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + '@radix-ui/react-use-controllable-state': 1.1.0(@types/react@19.0.8)(react@19.0.0) + '@radix-ui/react-use-previous': 1.1.0(@types/react@19.0.8)(react@19.0.0) + '@radix-ui/react-use-size': 1.1.0(@types/react@19.0.8)(react@19.0.0) + react: 19.0.0 + react-dom: 19.0.0(react@19.0.0) + optionalDependencies: + '@types/react': 19.0.8 + '@types/react-dom': 19.0.3(@types/react@19.0.8) + '@radix-ui/react-tooltip@1.1.8(@types/react-dom@19.0.3(@types/react@19.0.8))(@types/react@19.0.8)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)': dependencies: '@radix-ui/primitive': 1.1.1 From cb0e842ac0dbacfcf53529fa102a00073382b7b2 Mon Sep 17 00:00:00 2001 From: "Amagi:DDmxh" Date: Tue, 18 Feb 2025 02:30:32 +0800 Subject: [PATCH 2/2] add custom model ui and features --- app/api/research/route.ts | 4 +- components/chat/api-key-dialog.tsx | 24 +- components/chat/custom-model-dialog.tsx | 77 +++ components/chat/input.tsx | 554 ++++++++++-------- lib/deep-research/ai/providers.ts | 3 +- public/providers/custom.svg | 9 + supabase/functions/_shared/feedback.ts | 14 +- supabase/functions/feedback/index.ts | 3 + supabase/functions/keys/index.ts | 10 +- .../research/deep-research/ai/providers.ts | 3 +- supabase/functions/research/index.ts | 4 +- 11 files changed, 451 insertions(+), 254 deletions(-) create mode 100644 components/chat/custom-model-dialog.tsx create mode 100644 public/providers/custom.svg diff --git a/app/api/research/route.ts b/app/api/research/route.ts index 9e37c1b..0be4261 100644 --- a/app/api/research/route.ts +++ b/app/api/research/route.ts @@ -29,6 +29,7 @@ export async function POST(req: NextRequest) { // Retrieve API keys from secure cookies const openaiKey = req.cookies.get("openai-key")?.value; const firecrawlKey = req.cookies.get("firecrawl-key")?.value; + const apiUrl = req.cookies.get("api-url")?.value; // Add API key validation if (process.env.NEXT_PUBLIC_ENABLE_API_KEYS === "true") { @@ -50,10 +51,11 @@ export async function POST(req: NextRequest) { console.log("API Keys Present:", { OpenAI: openaiKey ? "✅" : "❌", FireCrawl: firecrawlKey ? "✅" : "❌", + CustomApiUrl: apiUrl ? "✅" : "❌", }); try { - const model = createModel(modelId as AIModel, openaiKey); + const model = createModel(modelId as AIModel, openaiKey, apiUrl); console.log("\n🤖 [RESEARCH ROUTE] === Model Created ==="); console.log("Using Model:", modelId); diff --git a/components/chat/api-key-dialog.tsx b/components/chat/api-key-dialog.tsx index d630365..0bf63bb 100644 --- a/components/chat/api-key-dialog.tsx +++ b/components/chat/api-key-dialog.tsx @@ -31,6 +31,7 @@ interface ApiKeyDialogProps { export function ApiKeyDialog({ show, onClose, onSuccess }: ApiKeyDialogProps) { const [openaiKey, setOpenaiKey] = useState(""); const [firecrawlKey, setFirecrawlKey] = useState(""); + const [apiUrl, setApiUrl] = useState(); const [loading, setLoading] = useState(false); const handleApiKeySubmit = async () => { @@ -39,7 +40,7 @@ export function ApiKeyDialog({ show, onClose, onSuccess }: ApiKeyDialogProps) { const res = await fetch("/api/keys", { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ openaiKey, firecrawlKey }), + body: JSON.stringify({ openaiKey, firecrawlKey, apiUrl }), }); if (res.ok) { onClose(false); @@ -170,6 +171,27 @@ export function ApiKeyDialog({ show, onClose, onSuccess }: ApiKeyDialogProps) {

+
+ +
+ setApiUrl(e.target.value)} + placeholder="https://..." + className="pr-10 font-mono text-sm bg-background/50 border-border focus:border-primary focus:ring-primary h-9 sm:h-10" + /> +
+ +
+
+

+ Defaults to the OpenAI official API URL +

+
+