Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Ask for an OpenRouter API key before AI visibility setup (#1074)
Ben Senescu4d590b4d4f15
diff --git a/src/client/features/ai-visibility/OpenRouterKeyGate.tsx b/src/client/features/ai-visibility/OpenRouterKeyGate.tsxnew file mode 100644index 00000000..1cd622e3--- /dev/null+++ b/src/client/features/ai-visibility/OpenRouterKeyGate.tsx@@ -0,0 +1,91 @@+import type { ReactNode } from "react";+import { Link } from "@tanstack/react-router";+import { KeyRound } from "lucide-react";+import { GateCard } from "@/client/components/GateCard";+import { QueryError } from "@/client/components/QueryState";+import { SkeletonPageContent } from "@/client/components/SkeletonPresets";+import { Button } from "@/client/components/ui/button";+import { useSamAccess } from "@/client/features/sam/useSamAccess";++/**+ * AI visibility setup researches the brand and suggests prompts through+ * OpenRouter, so a self-hosted install without a key would only fail after+ * the user starts research. Ask for the key first (hosted always has one).+ */+export function OpenRouterKeyGate({+ projectId,+ children,+}: {+ projectId: string;+ children: ReactNode;+}) {+ const access = useSamAccess(projectId);+ if (access.status === "ready") return children;+ if (access.status === "checking") return <SkeletonPageContent />;+ if (access.status === "error")+ return (+ <QueryError+ error={access.error}+ fallback="Could not check the OpenRouter API key."+ onRetry={access.onRetry}+ isRetrying={access.isRetrying}+ />+ );+ return (+ <div className="grid min-h-[calc(100dvh-8rem)] place-items-center">+ <GateCard+ className="max-w-2xl"+ icon={KeyRound}+ tone="warning"+ title="Add an OpenRouter API key"+ description={+ <>+ <p>+ AI visibility uses OpenRouter to research your brand and suggest+ the prompts worth tracking, so you don't have to write them+ yourself. The tracking results, what ChatGPT and other AI engines+ actually answer, come from your DataForSEO account.+ </p>+ <p>+ Create a key on OpenRouter, set it as{" "}+ <code>OPENROUTER_API_KEY</code>, restart OpenSEO, then confirm+ here. The{" "}+ <Link+ className="underline underline-offset-2 hover:text-foreground"+ to="/help/openrouter-api-key"+ >+ OpenRouter API key setup guide+ </Link>{" "}+ has the steps for each deployment.+ </p>+ </>+ }+ actions={+ <>+ <Button+ size="lg"+ pending={access.isRefetching}+ onClick={access.onRetry}+ >+ Confirm API Key+ </Button>+ <Button+ size="lg"+ variant="outline"+ nativeButton={false}+ render={+ <a+ href="https://openrouter.ai/settings/keys"+ target="_blank"+ rel="noreferrer"+ />+ }+ >+ Open OpenRouter Keys+ </Button>+ </>+ }+ />+ </div>+ );+}diff --git a/src/routes/_app/p/$projectId/ai-visibility.tsx b/src/routes/_app/p/$projectId/ai-visibility.tsxindex 5c941662..4433eb8a 100644--- a/src/routes/_app/p/$projectId/ai-visibility.tsx+++ b/src/routes/_app/p/$projectId/ai-visibility.tsx@@ -4,6 +4,7 @@ import {aiResearchSetupQueryOptions,aiTrackerQueryOptions,} from "@/client/features/ai-visibility/shared";+import { OpenRouterKeyGate } from "@/client/features/ai-visibility/OpenRouterKeyGate";import { ProjectWebsiteGate } from "@/client/features/projects/ProjectWebsiteGate";import { queryClient } from "@/client/tanstack-db/queryClient";@@ -25,11 +26,13 @@ function AiVisibilityLayout() {return (<div className="overflow-auto px-4 py-4 pb-24 md:px-6 md:py-6 md:pb-8"><div className="mx-auto max-w-7xl space-y-5" key={projectId}>- <ProjectWebsiteGate projectId={projectId}>- <AiResearchSetupGate projectId={projectId}>- <Outlet />- </AiResearchSetupGate>- </ProjectWebsiteGate>+ <OpenRouterKeyGate projectId={projectId}>+ <ProjectWebsiteGate projectId={projectId}>+ <AiResearchSetupGate projectId={projectId}>+ <Outlet />+ </AiResearchSetupGate>+ </ProjectWebsiteGate>+ </OpenRouterKeyGate></div></div>);diff --git a/src/routes/_app/p/$projectId/prompt-explorer.tsx b/src/routes/_app/p/$projectId/prompt-explorer.tsxindex 431b9a2c..e2b5e105 100644--- a/src/routes/_app/p/$projectId/prompt-explorer.tsx+++ b/src/routes/_app/p/$projectId/prompt-explorer.tsx@@ -3,6 +3,7 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router";import { PromptExplorerPage } from "@/client/features/ai-search/PromptExplorerPage";import { AiResearchSetupGate } from "@/client/features/ai-visibility/AiResearchSetupGate";import { aiResearchSetupQueryOptions } from "@/client/features/ai-visibility/shared";+import { OpenRouterKeyGate } from "@/client/features/ai-visibility/OpenRouterKeyGate";import { ProjectWebsiteGate } from "@/client/features/projects/ProjectWebsiteGate";import { queryClient } from "@/client/tanstack-db/queryClient";import {@@ -43,29 +44,31 @@ function PromptExplorerRoute() {return (<div className="overflow-auto px-4 py-4 pb-24 md:px-6 md:py-6 md:pb-8"><div className="mx-auto max-w-7xl space-y-5" key={projectId}>- <ProjectWebsiteGate projectId={projectId}>- <AiResearchSetupGate projectId={projectId}>- <PromptExplorerPage- projectId={projectId}- urlState={urlState}- onSubmit={(values) => {- void navigate({- search: {- q: values.prompt,- models: values.models,- web: values.webSearch ? undefined : false,- cc: values.webSearchCountryCode,- hb: values.highlightBrand || undefined,- },- replace: true,- });- }}- onClear={() => {- void navigate({ search: {}, replace: true });- }}- />- </AiResearchSetupGate>- </ProjectWebsiteGate>+ <OpenRouterKeyGate projectId={projectId}>+ <ProjectWebsiteGate projectId={projectId}>+ <AiResearchSetupGate projectId={projectId}>+ <PromptExplorerPage+ projectId={projectId}+ urlState={urlState}+ onSubmit={(values) => {+ void navigate({+ search: {+ q: values.prompt,+ models: values.models,+ web: values.webSearch ? undefined : false,+ cc: values.webSearchCountryCode,+ hb: values.highlightBrand || undefined,+ },+ replace: true,+ });+ }}+ onClear={() => {+ void navigate({ search: {}, replace: true });+ }}+ />+ </AiResearchSetupGate>+ </ProjectWebsiteGate>+ </OpenRouterKeyGate></div></div>);