Add login key system

This commit is contained in:
Brian Hackett
2025-02-21 09:00:23 -08:00
parent 38d389a42e
commit 63dcd6702e
8 changed files with 83 additions and 35 deletions

View File

@@ -18,12 +18,13 @@ Focus specifically on fixing this bug. Do not guess about other problems.
async function chatAction({ context, request }: ActionFunctionArgs) {
ensureOpenTelemetryInitialized(context);
const { messages, files, promptId, simulationEnhancedPrompt, anthropicApiKey: clientAnthropicApiKey } = await request.json<{
const { messages, files, promptId, simulationEnhancedPrompt, anthropicApiKey: clientAnthropicApiKey, loginKey } = await request.json<{
messages: Messages;
files: FileMap;
promptId?: string;
simulationEnhancedPrompt?: string;
anthropicApiKey?: string;
loginKey?: string;
}>();
let finished: (v?: any) => void;
@@ -49,6 +50,7 @@ async function chatAction({ context, request }: ActionFunctionArgs) {
const anthropicApiKey: AnthropicApiKey = {
key: apiKey,
isUser: !!clientAnthropicApiKey,
userLoginKey: loginKey,
};
const resultStream = new ReadableStream({

View File

@@ -5,11 +5,10 @@ import BackgroundRays from '~/components/ui/BackgroundRays';
import { TooltipProvider } from '@radix-ui/react-tooltip';
import { ToastContainerWrapper, Status, Keywords } from './problems';
import { toast } from 'react-toastify';
import { useCallback, useEffect } from 'react';
import { useState } from 'react';
import { Suspense, useCallback, useEffect, useState } from 'react';
import { useParams } from '@remix-run/react';
import { getProblem, updateProblem as backendUpdateProblem, getProblemsUsername, BoltProblemStatus, hasNutAdminKey } from '~/lib/replay/Problems';
import type { BoltProblem, BoltProblemComment, BoltProblemInput } from '~/lib/replay/Problems';
import { getProblem, updateProblem as backendUpdateProblem, getProblemsUsername, BoltProblemStatus, getNutIsAdmin } from '~/lib/replay/Problems';
import type { BoltProblem, BoltProblemComment } from '~/lib/replay/Problems';
function Comments({ comments }: { comments: BoltProblemComment[] }) {
return (
@@ -152,6 +151,8 @@ function UpdateProblemForms({ updateProblem }: { updateProblem: UpdateProblemCal
)
}
const Nothing = () => null;
function ViewProblemPage() {
const params = useParams();
const problemId = params.id;
@@ -177,6 +178,7 @@ function ViewProblemPage() {
}, [problemId]);
return (
<Suspense fallback={<Nothing />}>
<TooltipProvider>
<div className="flex flex-col h-full w-full bg-bolt-elements-background-depth-1">
<BackgroundRays />
@@ -190,12 +192,13 @@ function ViewProblemPage() {
</div>)
: <ProblemViewer problem={problemData} />}
</div>
{hasNutAdminKey() && problemData && (
{getNutIsAdmin() && problemData && (
<UpdateProblemForms updateProblem={updateProblem} />
)}
<ToastContainerWrapper />
</div>
</TooltipProvider>
</Suspense>
);
}

View File

@@ -4,8 +4,7 @@ import { Menu } from '~/components/sidebar/Menu.client';
import BackgroundRays from '~/components/ui/BackgroundRays';
import { TooltipProvider } from '@radix-ui/react-tooltip';
import { cssTransition, ToastContainer } from 'react-toastify';
import { useEffect } from 'react';
import { useState } from 'react';
import { Suspense, useEffect, useState } from 'react';
import { BoltProblemStatus, listAllProblems } from '~/lib/replay/Problems';
import type { BoltProblemDescription } from '~/lib/replay/Problems';
@@ -91,6 +90,8 @@ function getProblemStatus(problem: BoltProblemDescription): BoltProblemStatus {
return problem.status ?? BoltProblemStatus.Pending;
}
const Nothing = () => null;
function ProblemsPage() {
const [problems, setProblems] = useState<BoltProblemDescription[] | null>(null);
const [statusFilter, setStatusFilter] = useState<BoltProblemStatus | 'all'>(BoltProblemStatus.Solved);
@@ -104,6 +105,7 @@ function ProblemsPage() {
});
return (
<Suspense fallback={<Nothing />}>
<TooltipProvider>
<div className="flex flex-col h-full w-full bg-bolt-elements-background-depth-1">
<BackgroundRays />
@@ -164,6 +166,7 @@ function ProblemsPage() {
<ToastContainerWrapper />
</div>
</TooltipProvider>
</Suspense>
);
}