Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

refactor(ai-gateway): split setup instruction tabs from data loading and add stories (#19307)

Tobias Wochinger32e19e0f8806
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx
index aa5d475026..8a373b345f 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx
@@ -1,32 +1,10 @@
-import { useState } from "react";
-import { Braces, SquareTerminal, type IconComponent } from "@langfuse/icons";
-import { SiClaude, SiOpenai } from "@langfuse/icons/si";
-
import { Alert } from "@/src/components/design-system/Alert/Alert";
-import { Button } from "@/src/components/design-system/Button/Button";
import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
-import { Tabs } from "@/src/components/design-system/Tabs/Tabs";
import { Skeleton } from "@/src/components/ui/skeleton";
-import type { AgentSetupInstructions } from "@/src/features/ai-gateway/types/agentSetupInstructions";
-import { AgentInstructionsPanel } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentInstructionsPanel";
-import {
- ClaudeSetupTabs,
- type ClaudeAgentId,
-} from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/ClaudeSetupTabs";
+import { SetupInstructionsTabs } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs";
import { MaskedGatewayKey } from "./components/MaskedGatewayKey";
import { useAgentSetupInstructions } from "./hooks/useAgentSetupInstructions";
-type TabId = Exclude<AgentSetupInstructions["id"], ClaudeAgentId> | "claude";
-
-const DEFAULT_TAB: TabId = "api";
-
-const TABS: { id: TabId; label: string; icon: IconComponent }[] = [
- { id: "api", label: "API", icon: Braces },
- { id: "claude", label: "Claude", icon: SiClaude },
- { id: "codex", label: "Codex", icon: SiOpenai },
- { id: "opencode", label: "OpenCode", icon: SquareTerminal },
-];
-
type SetupInstructionsProps = {
organizationId: string;
};
@@ -34,9 +12,6 @@ type SetupInstructionsProps = {
function SetupInstructions({ organizationId }: SetupInstructionsProps) {
const { instructions, isPending, isError } =
useAgentSetupInstructions(organizationId);
- const [activeTab, setActiveTab] = useState<string>(DEFAULT_TAB);
- const [claudeVariant, setClaudeVariant] =
- useState<ClaudeAgentId>("claude-code");
if (isPending) {
return <Skeleton className="h-48 w-full" />;
@@ -52,75 +27,7 @@ function SetupInstructions({ organizationId }: SetupInstructionsProps) {
);
}
- const findEntry = (id: string) =>
- instructions.find((entry) => entry.id === id);
- const activeEntry =
- findEntry(activeTab === "claude" ? claudeVariant : activeTab) ??
- instructions[0];
-
- return (
- <div className="flex flex-col gap-2">
- <div className="flex flex-col gap-1">
- <h3 className="font-bold">Usage instructions</h3>
- <p className="text-muted-foreground">
- Call the gateway from your code or connect an AI tool to it. Each tab
- has the steps for one tool.{" "}
- {activeEntry ? (
- <Button
- variant="text"
- text={
- activeEntry.id === "api"
- ? "How to call the gateway API"
- : `How to connect ${activeEntry.label}`
- }
- href={activeEntry.docsUrl}
- />
- ) : null}
- </p>
- </div>
- <Tabs value={activeTab} onValueChange={setActiveTab}>
- <div className="flex h-9 items-center border-b">
- <Tabs.List
- variant="underline"
- overflow="menu"
- aria-label="Setup instructions"
- >
- {TABS.map((tab) => (
- <Tabs.Trigger
- key={tab.id}
- value={tab.id}
- label={tab.label}
- icon={tab.icon}
- />
- ))}
- </Tabs.List>
- </div>
- {TABS.map((tab) => {
- if (tab.id === "claude") {
- return (
- <Tabs.Content key={tab.id} value={tab.id}>
- <div className="pt-4">
- <ClaudeSetupTabs
- instructions={instructions}
- value={claudeVariant}
- onValueChange={setClaudeVariant}
- />
- </div>
- </Tabs.Content>
- );
- }
- const entry = findEntry(tab.id);
- return entry ? (
- <Tabs.Content key={tab.id} value={tab.id}>
- <div className="pt-4">
- <AgentInstructionsPanel instructions={entry} />
- </div>
- </Tabs.Content>
- ) : null;
- })}
- </Tabs>
- </div>
- );
+ return <SetupInstructionsTabs instructions={instructions} />;
}
type GeneratedKeyContentProps = {
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.stories.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.stories.tsx
new file mode 100644
index 0000000000..fee5dc5c48
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.stories.tsx
@@ -0,0 +1,53 @@
+import { expect, userEvent, within } from "storybook/test";
+
+import preview from "@/.storybook/preview";
+import { buildAgentSetupInstructions } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/fns/agentSetupInstructions/buildAgentSetupInstructions";
+import { SetupInstructionsTabs } from "./SetupInstructionsTabs";
+
+const context = {
+ gatewayOrigin: "https://cloud.langfuse.com",
+ userId: "[email protected]",
+};
+
+const meta = preview.meta({ component: SetupInstructionsTabs });
+
+export const Default = meta.story({
+ args: {
+ instructions: buildAgentSetupInstructions({
+ ...context,
+ providers: ["ANTHROPIC", "OPENAI"],
+ }),
+ },
+});
+
+export const TestClaudeSwitch = meta.story({
+ name: "(Test) Claude tab switches between Code and Desktop",
+ args: Default.input.args,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ await userEvent.click(canvas.getByRole("tab", { name: "Claude" }));
+ await userEvent.click(canvas.getByRole("tab", { name: "Desktop" }));
+
+ await expect(
+ canvas.getByRole("link", { name: "How to connect Claude Desktop" }),
+ ).toBeVisible();
+ },
+});
+
+export const TestWarnsWithoutAnthropic = meta.story({
+ name: "(Test) Claude tab warns without an Anthropic connection",
+ args: {
+ instructions: buildAgentSetupInstructions({
+ ...context,
+ providers: ["OPENAI"],
+ }),
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ await userEvent.click(canvas.getByRole("tab", { name: "Claude" }));
+
+ await expect(
+ canvas.getByText(/needs an Anthropic provider connection/),
+ ).toBeVisible();
+ },
+});
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.tsx
new file mode 100644
index 0000000000..8160b44f8a
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.tsx
@@ -0,0 +1,105 @@
+import { useState } from "react";
+import { Braces, SquareTerminal, type IconComponent } from "@langfuse/icons";
+import { SiClaude, SiOpenai } from "@langfuse/icons/si";
+
+import { Button } from "@/src/components/design-system/Button/Button";
+import { Tabs } from "@/src/components/design-system/Tabs/Tabs";
+import type { AgentSetupInstructions } from "@/src/features/ai-gateway/types/agentSetupInstructions";
+import { AgentInstructionsPanel } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentInstructionsPanel";
+import {
+ ClaudeSetupTabs,
+ type ClaudeAgentId,
+} from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/ClaudeSetupTabs";
+
+type TabId = Exclude<AgentSetupInstructions["id"], ClaudeAgentId> | "claude";
+
+const DEFAULT_TAB: TabId = "api";
+
+const TABS: { id: TabId; label: string; icon: IconComponent }[] = [
+ { id: "api", label: "API", icon: Braces },
+ { id: "claude", label: "Claude", icon: SiClaude },
+ { id: "codex", label: "Codex", icon: SiOpenai },
+ { id: "opencode", label: "OpenCode", icon: SquareTerminal },
+];
+
+type SetupInstructionsTabsProps = {
+ instructions: AgentSetupInstructions[];
+};
+
+export function SetupInstructionsTabs({
+ instructions,
+}: SetupInstructionsTabsProps) {
+ const [activeTab, setActiveTab] = useState<string>(DEFAULT_TAB);
+ const [claudeVariant, setClaudeVariant] =
+ useState<ClaudeAgentId>("claude-code");
+
+ const findEntry = (id: string) =>
+ instructions.find((entry) => entry.id === id);
+ const activeEntry =
+ findEntry(activeTab === "claude" ? claudeVariant : activeTab) ??
+ instructions[0];
+
+ return (
+ <div className="flex flex-col gap-2">
+ <div className="flex flex-col gap-1">
+ <h3 className="font-bold">Usage instructions</h3>
+ <p className="text-muted-foreground">
+ Call the gateway from your code or connect an AI tool to it. Each tab
+ has the steps for one tool.{" "}
+ {activeEntry ? (
+ <Button
+ variant="text"
+ text={
+ activeEntry.id === "api"
+ ? "How to call the gateway API"
+ : `How to connect ${activeEntry.label}`
+ }
+ href={activeEntry.docsUrl}
+ />
+ ) : null}
+ </p>
+ </div>
+ <Tabs value={activeTab} onValueChange={setActiveTab}>
+ <div className="flex h-9 items-center border-b">
+ <Tabs.List
+ variant="underline"
+ overflow="menu"
+ aria-label="Setup instructions"
+ >
+ {TABS.map((tab) => (
+ <Tabs.Trigger
+ key={tab.id}
+ value={tab.id}
+ label={tab.label}
+ icon={tab.icon}
+ />
+ ))}
+ </Tabs.List>
+ </div>
+ {TABS.map((tab) => {
+ if (tab.id === "claude") {
+ return (
+ <Tabs.Content key={tab.id} value={tab.id}>
+ <div className="pt-4">
+ <ClaudeSetupTabs
+ instructions={instructions}
+ value={claudeVariant}
+ onValueChange={setClaudeVariant}
+ />
+ </div>
+ </Tabs.Content>
+ );
+ }
+ const entry = findEntry(tab.id);
+ return entry ? (
+ <Tabs.Content key={tab.id} value={tab.id}>
+ <div className="pt-4">
+ <AgentInstructionsPanel instructions={entry} />
+ </div>
+ </Tabs.Content>
+ ) : null;
+ })}
+ </Tabs>
+ </div>
+ );
+}