Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions apps/ui/src/app/models/[name]/[provider]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ export default async function ModelProviderPage({ params }: PageProps) {
const decodedName = decodeURIComponent(name);
const decodedProvider = decodeURIComponent(provider);

// Discounts and ratings only depend on the model id, so they start in
// parallel with the model definition instead of behind it; the definition
// is awaited first so unknown models 404 without waiting for them, and
// fetchServerData never rejects (it logs and returns null).
const modelDataPromise = Promise.all([
fetchServerData<{ discounts: DiscountData[] }>(
"GET",
"/public/discounts/model/{modelId}",
{ params: { path: { modelId: decodedName } } },
),
fetchServerData<ModelRatingsData>("GET", "/public/model-ratings", {
params: { query: { modelId: decodedName } },
}),
]);
const modelDef = await findPublicModelDefinition(decodedName);

if (!modelDef) {
Expand All @@ -80,18 +94,7 @@ export default async function ModelProviderPage({ params }: PageProps) {
((await fetchProviders()).find(
(provider) => provider.id === decodedProvider,
) as unknown as (typeof providerDefinitions)[number] | undefined);

// Fetch global discounts and apply to provider
const [discountData, ratingsData] = await Promise.all([
fetchServerData<{ discounts: DiscountData[] }>(
"GET",
"/public/discounts/model/{modelId}",
{ params: { path: { modelId: decodedName } } },
),
fetchServerData<ModelRatingsData>("GET", "/public/model-ratings", {
params: { query: { modelId: decodedName } },
}),
]);
const [discountData, ratingsData] = await modelDataPromise;
const discounts = discountData?.discounts ?? [];
// A provider whose mappings are all deactivated still renders this page, but
// nothing can be routed to it — so it must not advertise a discounted price.
Expand Down
24 changes: 16 additions & 8 deletions apps/ui/src/app/models/[name]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,27 @@ export default async function ModelPage({ params }: PageProps) {
const { name } = await params;
const decodedName = decodeURIComponent(name);

const modelDef = await findPublicModelDefinition(decodedName);
// Discounts, ratings and carrier branding do not depend on the model
// definition, so all four catalogue requests start in one round-trip; the
// definition is awaited first so unknown models 404 without waiting for
// the rest. None of the batched fetchers reject — they log and return
// fallbacks — so abandoning the batch on notFound() is safe.
const modelDefPromise = findPublicModelDefinition(decodedName);
const pageDataPromise = Promise.all([
fetchModelDiscounts(decodedName),
fetchServerData<ModelRatingsData>("GET", "/public/model-ratings", {
params: { query: { modelId: decodedName } },
}),
fetchProviders(),
]);
const modelDef = await modelDefPromise;

if (!modelDef) {
notFound();
}

const [allDiscounts, ratingsData, apiProviders] = await pageDataPromise;

const getStabilityBadgeProps = (stability?: StabilityLevel) => {
switch (stability) {
case "beta":
Expand Down Expand Up @@ -107,15 +122,8 @@ export default async function ModelPage({ params }: PageProps) {
return stability && ["unstable", "experimental"].includes(stability);
};

const [allDiscounts, ratingsData] = await Promise.all([
fetchModelDiscounts(decodedName),
fetchServerData<ModelRatingsData>("GET", "/public/model-ratings", {
params: { query: { modelId: decodedName } },
}),
]);
// Carrier-uploaded branding (Airside claims) overlays the static provider
// info, and is the only provider info a DB-only carrier has.
const apiProviders = await fetchProviders();
const expandedProviders = expandAllProviderRegions(modelDef.providers);
const modelProviders = expandedProviders.map((provider) => {
const providerInfo = providerDefinitions.find(
Expand Down
7 changes: 6 additions & 1 deletion apps/ui/src/app/models/[name]/uptime/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ export default async function ModelUptimePage({ params }: PageProps) {
const { name } = await params;
const decodedName = decodeURIComponent(name);

// Provider names do not depend on the model definition, so both catalogue
// requests start in one round-trip; the definition is awaited first so
// unknown models 404 without waiting for the provider list, which never
// rejects (it logs and returns a fallback).
const providersPromise = fetchProviders();
const modelDef = await findPublicModelDefinition(decodedName);

if (!modelDef) {
notFound();
}

const apiProviders = await providersPromise;
const expandedProviders = expandAllProviderRegions(modelDef.providers);
const apiProviders = await fetchProviders();
const providerNames = Array.from(
new Set(
expandedProviders.map((p) => {
Expand Down
7 changes: 4 additions & 3 deletions apps/ui/src/app/providers/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ export default async function ProviderPage({ params }: ProviderPageProps) {
notFound();
}

const apiProviders = await fetchProviders();
const [apiProviders, apiModels] = await Promise.all([
fetchProviders(),
fetchModels(),
]);
const apiProvider = apiProviders.find((p) => p.id === id);
const uploadedLogo = apiProvider?.airsideLogoUrl ?? undefined;

const apiModels = await fetchModels();
const discountByModelId = new Map<string, string>();
for (const apiModel of apiModels) {
for (const mapping of apiModel.mappings) {
Expand Down
112 changes: 64 additions & 48 deletions packages/shared/src/components/jelly/jelly-logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect, useRef, useState } from "react";

import { Logo } from "@/components/ui/logo";

import { createJellyScene } from "./jelly-scene";
import type { createJellyScene } from "./jelly-scene";

export function JellyLogo() {
const canvas = useRef<HTMLCanvasElement>(null);
Expand All @@ -19,60 +19,76 @@ export function JellyLogo() {
}
const element = canvas.current;
let mounted = true;
let jelly: ReturnType<typeof createJellyScene>;
try {
jelly = createJellyScene(element);
} catch (error) {
// WebGL is optional; the static logo keeps the error page usable.
// eslint-disable-next-line no-console
console.warn("Could not initialize the 404 jelly", error);
return;
}
scene.current = jelly;
const motion = window.matchMedia("(prefers-reduced-motion: reduce)");
const updateMotion = () => {
jelly.setReducedMotion(motion.matches);
setReduced(motion.matches);
};
const updateTheme = () => {
jelly.setTheme(document.documentElement.classList.contains("dark"));
};
const theme = new MutationObserver(updateTheme);
theme.observe(document.documentElement, {
attributes: true,
attributeFilter: ["class"],
});
motion.addEventListener("change", updateMotion);
updateMotion();
updateTheme();
void jelly.ready
.then(() => {
if (mounted && scene.current === jelly) {
setReady(true);
let cleanup: (() => void) | undefined;
// The scene pulls in three.js, so it loads on demand to keep the 404
// page's initial chunk small; the static logo renders in the meantime.
void import("./jelly-scene")
.then(({ createJellyScene: create }) => {
if (!mounted) {
return;
}
let jelly: ReturnType<typeof create>;
try {
jelly = create(element);
} catch (error) {
// WebGL is optional; the static logo keeps the error page usable.
// eslint-disable-next-line no-console
console.warn("Could not initialize the 404 jelly", error);
return;
}
scene.current = jelly;
const motion = window.matchMedia("(prefers-reduced-motion: reduce)");
const updateMotion = () => {
jelly.setReducedMotion(motion.matches);
setReduced(motion.matches);
};
const updateTheme = () => {
jelly.setTheme(document.documentElement.classList.contains("dark"));
};
const theme = new MutationObserver(updateTheme);
theme.observe(document.documentElement, {
attributes: true,
attributeFilter: ["class"],
});
motion.addEventListener("change", updateMotion);
updateMotion();
updateTheme();
void jelly.ready
.then(() => {
if (mounted && scene.current === jelly) {
setReady(true);
}
})
.catch((error: unknown) => {
// eslint-disable-next-line no-console
console.warn("Could not load the 404 jelly studio", error);
jelly.dispose();
if (scene.current === jelly) {
scene.current = null;
}
});
const contextLost = (event: Event) => {
event.preventDefault();
jelly.dispose();
scene.current = null;
setReady(false);
};
element.addEventListener("webglcontextlost", contextLost);
cleanup = () => {
theme.disconnect();
motion.removeEventListener("change", updateMotion);
element.removeEventListener("webglcontextlost", contextLost);
jelly.dispose();
scene.current = null;
};
})
.catch((error: unknown) => {
// eslint-disable-next-line no-console
console.warn("Could not load the 404 jelly studio", error);
jelly.dispose();
if (scene.current === jelly) {
scene.current = null;
}
console.warn("Could not load the 404 jelly", error);
});
const contextLost = (event: Event) => {
event.preventDefault();
jelly.dispose();
scene.current = null;
setReady(false);
};
element.addEventListener("webglcontextlost", contextLost);
return () => {
mounted = false;
theme.disconnect();
motion.removeEventListener("change", updateMotion);
element.removeEventListener("webglcontextlost", contextLost);
jelly.dispose();
scene.current = null;
cleanup?.();
};
}, []);

Expand Down
Loading