All files / src/apps/developer/pages GetStarted.tsx

43.75% Statements 7/16
53.33% Branches 8/15
33.33% Functions 3/9
50% Lines 7/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240                                    1x                                                         1x             4x 4x                                                                       1x 1x                                               3x                                                                                                                                                                                                                                                      
import React, { useState } from "react";
import { Link } from "react-router-dom";
import MainPage from "@/components/page/MainPage/MainPage";
import { APP_NAME, APP_ROUTES } from "@/routes/const";
import {
  KeyRound,
  Code2,
  Terminal,
  Zap,
  CheckCircle2,
  ChevronDown,
  ChevronRight,
  Copy,
  Check,
} from "lucide-react";
 
// ─── Code block ───────────────────────────────────────────────────────────────
 
const CodeBlock: React.FC<{ code: string; language?: string }> = ({ code, language = "bash" }) => {
  const [copied, setCopied] = useState(false);
  const handleCopy = () => {
    void navigator.clipboard.writeText(code).then(() => {
      setCopied(true);
      setTimeout(() => setCopied(false), 2000);
    });
  };
  return (
    <div className="relative rounded-lg bg-gray-900 dark:bg-gray-950 border border-gray-700 overflow-hidden">
      <div className="flex items-center justify-between px-4 py-2 border-b border-gray-700/60">
        <span className="text-xs text-gray-500 font-mono">{language}</span>
        <button
          onClick={handleCopy}
          className="flex items-center gap-1.5 text-xs text-gray-400 hover:text-gray-200 transition-colors"
        >
          {copied ? <Check className="size-3 text-emerald-400" /> : <Copy className="size-3" />}
          {copied ? "Copied" : "Copy"}
        </button>
      </div>
      <pre className="px-4 py-3 text-sm font-mono text-gray-200 overflow-x-auto leading-relaxed whitespace-pre">
        {code}
      </pre>
    </div>
  );
};
 
// ─── Step ─────────────────────────────────────────────────────────────────────
 
const Step: React.FC<{
  number: number;
  title: string;
  description: string;
  children?: React.ReactNode;
  completed?: boolean;
}> = ({ number, title, description, children, completed = false }) => {
  const [open, setOpen] = useState(number === 1);
  return (
    <div className="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-sm overflow-hidden">
      <button
        onClick={() => setOpen((o) => !o)}
        className="w-full flex items-center gap-4 px-5 py-4 text-left hover:bg-gray-50 dark:hover:bg-gray-700/30 transition-colors"
      >
        <div
          className={`size-7 rounded-full flex items-center justify-center shrink-0 text-xs font-bold ${
            completed
              ? "bg-emerald-100 dark:bg-emerald-950/40 text-emerald-600 dark:text-emerald-400"
              : "bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400"
          }`}
        >
          {completed ? <CheckCircle2 className="size-4" /> : number}
        </div>
        <div className="flex-1 min-w-0">
          <div className="text-sm font-semibold text-gray-800 dark:text-gray-200">{title}</div>
          <div className="text-xs text-gray-400 dark:text-gray-500 mt-0.5">{description}</div>
        </div>
        {open ? (
          <ChevronDown className="size-4 text-gray-400 shrink-0" />
        ) : (
          <ChevronRight className="size-4 text-gray-400 shrink-0" />
        )}
      </button>
      {open && children && (
        <div className="px-5 pb-5 pt-1 space-y-4 border-t border-gray-100 dark:border-gray-700">
          {children}
        </div>
      )}
    </div>
  );
};
 
// ─── DeveloperGetStarted ──────────────────────────────────────────────────────
 
const DeveloperGetStarted: React.FC = () => (
  <MainPage
    title="Get Started"
    description={`Set up your ${APP_NAME} Developer integration in minutes.`}
  >
    <div className="max-w-2xl space-y-8">
      {/* Overview */}
      <div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
        {[
          {
            icon: KeyRound,
            title: "Authenticate",
            description: "Generate an API key and attach it to every request.",
          },
          {
            icon: Code2,
            title: "Call the API",
            description: `Send prompts and commands to your ${APP_NAME} resources via REST.`,
          },
          {
            icon: Zap,
            title: "Integrate",
            description: "Embed your agents into your own systems.",
          },
        ].map(({ icon: Icon, title, description }) => (
          <div
            key={title}
            className="flex flex-col items-center gap-2 p-4 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-center"
          >
            <div className="p-2 rounded-lg bg-gray-100 dark:bg-gray-700">
              <Icon className="size-4 text-gray-600 dark:text-gray-300" />
            </div>
            <div className="text-sm font-semibold text-gray-800 dark:text-gray-200">{title}</div>
            <div className="text-xs text-gray-400 dark:text-gray-500 leading-relaxed">
              {description}
            </div>
          </div>
        ))}
      </div>
 
      {/* Steps */}
      <div className="space-y-3">
        <h2 className="text-xs font-semibold text-gray-400 dark:text-gray-500 uppercase tracking-widest">
          Setup Steps
        </h2>
 
        <Step
          number={1}
          title="Create an API Key"
          description="Generate credentials to authenticate your requests."
        >
          <p className="text-sm text-gray-600 dark:text-gray-400 leading-relaxed">
            Navigate to <strong className="text-gray-800 dark:text-gray-200">API Keys</strong> and
            create a new key. Give it a descriptive name and select the scopes your integration
            needs. Store the key securely — it is shown only once.
          </p>
          <Link
            to={APP_ROUTES.DEVELOPER.api_keys}
            className="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg bg-gray-900 dark:bg-white text-white dark:text-gray-900 text-sm font-medium hover:opacity-80 transition-opacity"
          >
            <KeyRound className="size-3.5" />
            Go to API Keys
          </Link>
        </Step>
 
        <Step
          number={2}
          title="Authenticate Requests"
          description="Pass your API key as a Bearer token in the Authorization header."
        >
          <p className="text-sm text-gray-600 dark:text-gray-400 leading-relaxed">
            All API requests must include your key in the{" "}
            <code className="text-xs font-mono bg-gray-100 dark:bg-gray-700 px-1.5 py-0.5 rounded">
              Authorization
            </code>{" "}
            header:
          </p>
          <CodeBlock
            language="http"
            code={`Authorization: Bearer <your-api-key>`}
          />
          <p className="text-sm text-gray-600 dark:text-gray-400 leading-relaxed">
            Or using cURL:
          </p>
          <CodeBlock
            language="bash"
            code={`curl https://api.example.com/v1/agents \\
  -H "Authorization: Bearer <your-api-key>"`}
          />
        </Step>
 
        <Step
          number={3}
          title="Make Your First Request"
          description="Send a prompt to an agent and receive a response."
        >
          <p className="text-sm text-gray-600 dark:text-gray-400 leading-relaxed">
            Once you have an agent configured, send it a prompt via the{" "}
            <code className="text-xs font-mono bg-gray-100 dark:bg-gray-700 px-1.5 py-0.5 rounded">
              POST /agents/{"{agent_id}"}/prompt
            </code>{" "}
            endpoint:
          </p>
          <CodeBlock
            language="bash"
            code={`curl -X POST https://api.example.com/v1/agents/<agent_id>/prompt \\
  -H "Authorization: Bearer <your-api-key>" \\
  -H "Content-Type: application/json" \\
  -d '{
    "prompt": "Summarise our Q1 2025 financial report.",
    "conversation_id": null,
    "system_messages": []
  }'`}
          />
          <CodeBlock
            language="json"
            code={`{
  "response": "In Q1 2025, total revenue was £4.2M...",
  "conversation_id": "3f9a1b2e-..."
}`}
          />
        </Step>
 
        <Step
          number={4}
          title="Store Secrets in the Key Vault"
          description="Keep external credentials encrypted and accessible to your integrations."
        >
          <p className="text-sm text-gray-600 dark:text-gray-400 leading-relaxed">
            If your integrations reference external APIs (databases, SaaS tools, etc.), store those
            credentials in the{" "}
            <strong className="text-gray-800 dark:text-gray-200">Key Vault</strong> rather than
            hard-coding them. They are encrypted at rest and injected at runtime.
          </p>
          <Link
            to={APP_ROUTES.DEVELOPER.keyvault}
            className="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg bg-gray-900 dark:bg-white text-white dark:text-gray-900 text-sm font-medium hover:opacity-80 transition-opacity"
          >
            <Terminal className="size-3.5" />
            Go to Key Vault
          </Link>
        </Step>
      </div>
    </div>
  </MainPage>
);
 
export default DeveloperGetStarted;