%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/pages/
Upload File :
Create Path :
Current File : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/pages/ModelsPage.tsx

import { useMemo, useState } from "react";
import Button from "@/components/ui/Button";
import Card, { CardBody, CardHeader } from "@/components/ui/Card";
import Badge from "@/components/ui/Badge";
import { formatCompact } from "@/lib/format";
import { FEATURED_MODELS } from "@/lib/models";
import type { ModelInfo } from "@/types/api";

const iconProps = {
  className: "h-5 w-5",
  fill: "none",
  viewBox: "0 0 24 24",
  stroke: "currentColor",
  strokeWidth: 1.7,
} as const;

const RECOMMENDED_MODEL = "mercury-3";

/** Harga per 1M token (input, output, cache) dalam IDR β€” sama dengan seed DB. */
const MODEL_PRICES: Record<string, [number, number, number]> = {
  // ⚑ Tier Flash: 600 / 2.400 / 300
  "beam-1.0": [600, 2400, 300],
  "deepseek-v4.1-flash": [600, 2400, 300],
  "deepseek-v4.1-flash-1017": [600, 2400, 300],
  "deepseek-v4.1-flash-nvfp4": [600, 2400, 300],
  "deepseek-v4.1-flash-uncensored": [600, 2400, 300],
  "ernie-5.5-flash-preview": [600, 2400, 300],
  "hy4-flash": [600, 2400, 300],
  "ling-3.2-flash": [600, 2400, 300],
  "mimo-v2.6-flash": [600, 2400, 300],
  "minimax-m3.1-flash": [600, 2400, 300],
  "nemotron-3.5-lightning": [600, 2400, 300],
  "qwen-3.8-flash": [600, 2400, 300],
  "sensenova-6.8-flash": [600, 2400, 300],
  "solar-mini-4": [600, 2400, 300],
  "step-3.7-flash": [600, 2400, 300],
  // πŸ“˜ Tier Standar: 1.800 / 7.200 / 900
  "atria-dawn": [1800, 7200, 900],
  "exaone-v2.5": [1800, 7200, 900],
  "hungerg": [1800, 7200, 900],
  "iceman": [1800, 7200, 900],
  "mercury-3": [1800, 7200, 900],
  "qwen-3.8-27b": [1800, 7200, 900],
  // πŸ‘‘ Tier Premium: 4.800 / 19.200 / 2.400
  "big-pickle": [4800, 19200, 2400],
  "flint-40b": [4800, 19200, 2400],
  "gpt-6-luna": [4800, 19200, 2400],
  "grok-4.7": [4800, 19200, 2400],
  "nemotron-3.5-super-vl": [4800, 19200, 2400],
  "seaglass-alpha": [4800, 19200, 2400],
};

/** Daftar model statis yang ditampilkan di katalog (urutan tetap). */
function featuredModelList(): ModelInfo[] {
  return FEATURED_MODELS.map((id) => {
    const [inputPrice, outputPrice, cachePrice] = MODEL_PRICES[id] ?? [0, 0, 0];
    return {
      id,
      context_window: null,
      max_output: null,
      reasoning_effort: "",
      status: "active",
      uptime: undefined,
      last_latency_ms: null,
      input_price_per_1m: inputPrice,
      output_price_per_1m: outputPrice,
      cache_price_per_1m: cachePrice,
    };
  });
}

export default function ModelsPage() {
  const [q, setQ] = useState("");
  const [copiedId, setCopiedId] = useState<string | null>(null);

  const filtered = useMemo(() => {
    const featured = featuredModelList();
    const s = q.trim().toLowerCase();
    if (!s) return featured;
    return featured.filter((m) => m.id.toLowerCase().includes(s));
  }, [q]);

  const handleCopy = async (id: string) => {
    try {
      await navigator.clipboard.writeText(id);
      setCopiedId(id);
      window.setTimeout(
        () => setCopiedId((c) => (c === id ? null : c)),
        1500,
      );
    } catch {
      // Fallback: select manual bila clipboard tidak tersedia
      const ta = document.createElement("textarea");
      ta.value = id;
      document.body.appendChild(ta);
      ta.select();
      try {
        document.execCommand("copy");
        setCopiedId(id);
        window.setTimeout(
          () => setCopiedId((c) => (c === id ? null : c)),
          1500,
        );
      } finally {
        document.body.removeChild(ta);
      }
    }
  };

  return (
    <div className="space-y-6">
      <div className="flex flex-wrap items-center justify-between gap-4">
        <div>
          <h2 className="text-xl font-bold tracking-tight text-white sm:text-2xl">
            Model
          </h2>
          <p className="mt-1 text-sm text-slate-500">
            Cek katalog model yang tersedia.
          </p>
        </div>
      </div>

      <div className="space-y-6">
        {/* Katalog model */}
        <Card>
          <CardHeader
            title="Katalog Model"
            subtitle="Daftar model yang tersedia"
            action={
              <div className="relative">
                <input
                  value={q}
                  onChange={(e) => setQ(e.target.value)}
                  placeholder="Cari model…"
                  className="input-solid w-44 px-3 py-1.5 text-xs"
                />
              </div>
            }
          />
          <CardBody className="p-0">
            <div className="flex items-start gap-2.5 border-b border-blue-400/10 bg-blue-500/[0.05] px-4 py-3">
              <svg
                className="mt-0.5 h-4 w-4 shrink-0 text-blue-300"
                fill="none"
                viewBox="0 0 24 24"
                stroke="currentColor"
                strokeWidth={1.7}
              >
                <path
                  strokeLinecap="round"
                  strokeLinejoin="round"
                  d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"
                />
              </svg>
              <p className="text-xs leading-relaxed text-blue-200/85">
                Jika terjadi kendala pada sebuah model (misalnya error atau
                maintenance), Anda bisa langsung berganti ke model lain yang
                tersedia di daftar ini.
              </p>
            </div>
            {filtered.length === 0 ? (
              <div className="px-5 py-10 text-center text-sm text-slate-500">
                {q ? "Tidak ada model yang cocok." : "Belum ada model."}
              </div>
            ) : (
              <div className="p-2">
                {filtered.map((m) => (
                  <div
                    key={m.id}
                    className={`flex w-full items-center gap-3 rounded-xl border px-3.5 py-2.5 transition-colors ${
                      m.id === RECOMMENDED_MODEL
                        ? "border-emerald-400/25 bg-emerald-500/[0.04]"
                        : "border-white/[0.04] bg-white/[0.02]"
                    }`}
                  >
                    <div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-white/[0.06] bg-white/[0.03] text-slate-500">
                      <svg {...iconProps} className="h-4 w-4">
                        <path
                          strokeLinecap="round"
                          strokeLinejoin="round"
                          d="M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09z"
                        />
                      </svg>
                    </div>
                    <div className="min-w-0 flex-1">
                      <div className="flex min-w-0 items-center gap-2">
                        <p className="truncate font-mono text-sm font-medium text-slate-100">
                          {m.id}
                        </p>
                        {m.id === RECOMMENDED_MODEL && (
                          <Badge tone="success">Disarankan</Badge>
                        )}
                      </div>
                      <div className="mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-slate-500">
                        <span title="Input /1M token">
                          In Rp{formatCompact(m.input_price_per_1m ?? 0)}/1M
                        </span>
                        <span title="Output /1M token">
                          Out Rp{formatCompact(m.output_price_per_1m ?? 0)}/1M
                        </span>
                        <span title="Cache /1M token">
                          Cache Rp{formatCompact(m.cache_price_per_1m ?? 0)}/1M
                        </span>
                      </div>
                    </div>
                    <div className="flex shrink-0 items-center gap-1.5">
                      <Button
                        size="sm"
                        variant="ghost"
                        onClick={() => handleCopy(m.id)}
                      >
                        {copiedId === m.id ? "βœ“ Tersalin" : "Salin"}
                      </Button>
                    </div>
                  </div>
                ))}
              </div>
            )}
          </CardBody>
        </Card>
      </div>
    </div>
  );
}

Zerion Mini Shell 1.0