show ai gateway resource details in launcher

This commit is contained in:
miloschwartz
2026-08-11 14:41:07 -04:00
parent e0a66e79bb
commit 98f5e39a7f
18 changed files with 1069 additions and 124 deletions
+11
View File
@@ -4053,7 +4053,18 @@
"resourceLauncherTcp": "TCP",
"resourceLauncherUdp": "UDP",
"resourceLauncherUnlabeled": "Unlabeled",
"resourceLauncherAiGateway": "AI Gateway",
"resourceLauncherNoSite": "No Site",
"resourceLauncherAvailableModels": "Available Models",
"resourceLauncherAvailableModelsDescription": "Models you can use with this inference resource.",
"resourceLauncherAvailableModelsEmpty": "No models are available for this resource.",
"resourceLauncherAvailableModelsError": "Could not load available models.",
"resourceLauncherApiKeys": "API Keys",
"resourceLauncherApiKeysDescription": "Use your identity key or an attributed key to authenticate with this resource.",
"resourceLauncherApiKeysIdentity": "Identity Key",
"resourceLauncherApiKeysManual": "Attributed Keys",
"resourceLauncherApiKeysEmpty": "No API keys are available for this resource.",
"resourceLauncherApiKeysError": "Could not load API keys.",
"resourceLauncherNoResourcesInGroup": "No resources in this group",
"resourceLauncherEmptyStateTitle": "No Resources Available",
"resourceLauncherEmptyStateDescription": "You don't have access to any resources yet. Contact your administrator to request access.",
+146
View File
@@ -518,6 +518,152 @@ export async function listSiteResourceAiProviders(siteResourceId: number) {
.where(eq(siteResourceAiProviders.siteResourceId, siteResourceId));
}
export type EffectiveAllowModel = {
modelId: number;
modelKey: string;
name: string;
providerId: number;
providerName: string;
};
export async function listEffectiveAllowModels(options: {
resourceId?: number;
siteResourceId?: number;
}): Promise<EffectiveAllowModel[]> {
if (
options.resourceId === undefined &&
options.siteResourceId === undefined
) {
return [];
}
const attachments =
options.resourceId !== undefined
? await listPublicResourceAiProviders(options.resourceId)
: await listSiteResourceAiProviders(options.siteResourceId!);
const activeAttachments = attachments.filter(
(a) => a.enabled && a.providerEnabled
);
if (activeAttachments.length === 0) {
return [];
}
const inheritProviderIds = activeAttachments
.filter((a) => a.accessMode === "inherit")
.map((a) => a.providerId);
const selectProviderIds = activeAttachments
.filter((a) => a.accessMode === "select")
.map((a) => a.providerId);
const providerNameById = new Map(
activeAttachments.map((a) => [a.providerId, a.name] as const)
);
const models: EffectiveAllowModel[] = [];
if (inheritProviderIds.length > 0) {
const rows = await db
.select({
modelId: aiModels.modelId,
modelKey: aiModels.modelKey,
name: aiModels.name,
providerId: aiModels.providerId
})
.from(aiModels)
.where(
and(
inArray(aiModels.providerId, inheritProviderIds),
eq(aiModels.enabled, true),
eq(aiModels.listType, "allow")
)
);
for (const row of rows) {
models.push({
...row,
providerName: providerNameById.get(row.providerId) ?? ""
});
}
}
if (selectProviderIds.length > 0) {
if (options.resourceId !== undefined) {
const rows = await db
.select({
modelId: aiModels.modelId,
modelKey: aiModels.modelKey,
name: aiModels.name,
providerId: aiModels.providerId
})
.from(resourceAiModels)
.innerJoin(
aiModels,
eq(resourceAiModels.modelId, aiModels.modelId)
)
.where(
and(
eq(resourceAiModels.resourceId, options.resourceId),
inArray(aiModels.providerId, selectProviderIds),
eq(resourceAiModels.listType, "allow"),
eq(aiModels.enabled, true)
)
);
for (const row of rows) {
models.push({
...row,
providerName: providerNameById.get(row.providerId) ?? ""
});
}
} else if (options.siteResourceId !== undefined) {
const rows = await db
.select({
modelId: aiModels.modelId,
modelKey: aiModels.modelKey,
name: aiModels.name,
providerId: aiModels.providerId
})
.from(siteResourceAiModels)
.innerJoin(
aiModels,
eq(siteResourceAiModels.modelId, aiModels.modelId)
)
.where(
and(
eq(
siteResourceAiModels.siteResourceId,
options.siteResourceId
),
inArray(aiModels.providerId, selectProviderIds),
eq(siteResourceAiModels.listType, "allow"),
eq(aiModels.enabled, true)
)
);
for (const row of rows) {
models.push({
...row,
providerName: providerNameById.get(row.providerId) ?? ""
});
}
}
}
models.sort((a, b) => {
const byProvider = a.providerName.localeCompare(
b.providerName,
undefined,
{
sensitivity: "base"
}
);
if (byProvider !== 0) {
return byProvider;
}
return a.name.localeCompare(b.name, undefined, { sensitivity: "base" });
});
return models;
}
/**
* Model list APIs require an inference resource with at least one select-mode
* attached provider.
+14
View File
@@ -590,6 +590,20 @@ authenticated.get(
launcher.listLauncherResources
);
authenticated.get(
"/org/:orgId/launcher/resource/:resourceId/ai-models",
verifyOrgAccess,
verifyResourceAccess,
launcher.listLauncherPublicAiModels
);
authenticated.get(
"/org/:orgId/launcher/site-resource/:siteResourceId/ai-models",
verifyOrgAccess,
verifySiteResourceAccess,
launcher.listLauncherSiteAiModels
);
authenticated.get(
"/org/:orgId/launcher/sites",
verifyOrgAccess,
+13 -10
View File
@@ -98,7 +98,7 @@ function formatTcpUdpResourceAccess(
export function formatPublicResourceAccess(
resource: PublicResourceAccessInput
): LauncherAccessFields {
const browserModes = ["http", "ssh", "rdp", "vnc"];
const browserModes = ["http", "ssh", "rdp", "vnc", "inference"];
if (!browserModes.includes(resource.mode)) {
return formatTcpUdpResourceAccess(
resource.exitNodeEndpoint,
@@ -125,15 +125,10 @@ export function formatPublicResourceAccess(
export function formatSiteResourceAccess(
resource: SiteResourceAccessInput
): LauncherAccessFields {
if (resource.alias) {
return {
accessDisplay: resource.alias,
accessCopyValue: resource.alias,
accessUrl: null
};
}
if (resource.mode === "http" && resource.fullDomain) {
if (
(resource.mode === "http" || resource.mode === "inference") &&
resource.fullDomain
) {
const url = `${resource.ssl ? "https" : "http"}://${resource.fullDomain}`;
return {
accessDisplay: url,
@@ -142,6 +137,14 @@ export function formatSiteResourceAccess(
};
}
if (resource.alias) {
return {
accessDisplay: resource.alias,
accessCopyValue: resource.alias,
accessUrl: null
};
}
const destination = formatSiteResourceDestinationDisplay({
mode: resource.mode as SiteResourceDestinationInput["mode"],
destination: resource.destination,
+5
View File
@@ -5,6 +5,11 @@ export { listLauncherResources } from "./listLauncherResources";
export { listLauncherSites } from "./listLauncherSites";
export { listLauncherLabels } from "./listLauncherLabels";
export { listLauncherViews } from "./listLauncherViews";
export {
listLauncherPublicAiModels,
listLauncherSiteAiModels
} from "./listLauncherAiModels";
export type { ListLauncherAiModelsResponse } from "./listLauncherAiModels";
export { createLauncherView } from "./createLauncherView";
export { updateLauncherView } from "./updateLauncherView";
export { deleteLauncherView } from "./deleteLauncherView";
+102 -41
View File
@@ -31,6 +31,7 @@ import {
inArray,
isNull,
like,
ne,
or,
sql,
type SQL
@@ -40,6 +41,7 @@ import {
formatSiteResourceAccess
} from "./formatLauncherAccess";
import {
LAUNCHER_AI_GATEWAY_GROUP_KEY,
LAUNCHER_FLAT_GROUP_KEY,
LAUNCHER_NO_SITE_GROUP_KEY,
LAUNCHER_UNLABELED_GROUP_KEY,
@@ -652,6 +654,7 @@ async function listSiteGroups(
}
}
let aiGatewayCount = 0;
let noSiteCount = 0;
if (accessible.resourceIds.length > 0 && siteFilterIds.length === 0) {
@@ -665,27 +668,49 @@ async function listSiteGroups(
noSitePublicConditions.push(searchPublic);
}
let noSitePublicQuery = db
.select({
itemCount: countDistinct(resources.resourceId)
})
.from(resources)
.leftJoin(targets, eq(targets.resourceId, resources.resourceId));
const buildNoSitePublicQuery = () => {
let queryBuilder = db
.select({
itemCount: countDistinct(resources.resourceId)
})
.from(resources)
.leftJoin(
targets,
eq(targets.resourceId, resources.resourceId)
);
if (labelFilterIds.length > 0) {
queryBuilder = queryBuilder.innerJoin(
resourceLabels,
eq(resourceLabels.resourceId, resources.resourceId)
);
}
return queryBuilder;
};
if (labelFilterIds.length > 0) {
noSitePublicQuery = noSitePublicQuery.innerJoin(
resourceLabels,
eq(resourceLabels.resourceId, resources.resourceId)
);
noSitePublicConditions.push(
inArray(resourceLabels.labelId, labelFilterIds)
);
}
const [noSitePublicRow] = await noSitePublicQuery.where(
and(...noSitePublicConditions, isNull(targets.targetId))
const [aiGatewayPublicRow] = await buildNoSitePublicQuery().where(
and(
...noSitePublicConditions,
isNull(targets.targetId),
eq(resources.mode, "inference")
)
);
const [noSitePublicRow] = await buildNoSitePublicQuery().where(
and(
...noSitePublicConditions,
isNull(targets.targetId),
ne(resources.mode, "inference")
)
);
aiGatewayCount += Number(aiGatewayPublicRow?.itemCount ?? 0);
noSiteCount += Number(noSitePublicRow?.itemCount ?? 0);
}
@@ -700,38 +725,57 @@ async function listSiteGroups(
noSiteSiteConditions.push(searchSite);
}
let noSiteSiteQuery = db
.select({
itemCount: countDistinct(siteResources.siteResourceId)
})
.from(siteResources)
.leftJoin(
siteNetworks,
eq(siteResources.networkId, siteNetworks.networkId)
)
.leftJoin(sites, eq(siteNetworks.siteId, sites.siteId));
const buildNoSiteSiteQuery = () => {
let queryBuilder = db
.select({
itemCount: countDistinct(siteResources.siteResourceId)
})
.from(siteResources)
.leftJoin(
siteNetworks,
eq(siteResources.networkId, siteNetworks.networkId)
)
.leftJoin(sites, eq(siteNetworks.siteId, sites.siteId));
if (labelFilterIds.length > 0) {
queryBuilder = queryBuilder.innerJoin(
siteResourceLabels,
eq(
siteResourceLabels.siteResourceId,
siteResources.siteResourceId
)
);
}
return queryBuilder;
};
if (labelFilterIds.length > 0) {
noSiteSiteQuery = noSiteSiteQuery.innerJoin(
siteResourceLabels,
eq(
siteResourceLabels.siteResourceId,
siteResources.siteResourceId
)
);
noSiteSiteConditions.push(
inArray(siteResourceLabels.labelId, labelFilterIds)
);
}
const [noSiteSiteRow] = await noSiteSiteQuery.where(
and(...noSiteSiteConditions, isNull(sites.siteId))
const [aiGatewaySiteRow] = await buildNoSiteSiteQuery().where(
and(
...noSiteSiteConditions,
isNull(sites.siteId),
eq(siteResources.mode, "inference")
)
);
const [noSiteSiteRow] = await buildNoSiteSiteQuery().where(
and(
...noSiteSiteConditions,
isNull(sites.siteId),
ne(siteResources.mode, "inference")
)
);
aiGatewayCount += Number(aiGatewaySiteRow?.itemCount ?? 0);
noSiteCount += Number(noSiteSiteRow?.itemCount ?? 0);
}
let groups: LauncherGroup[] = Array.from(siteCountMap.values()).map(
const siteGroups: LauncherGroup[] = Array.from(siteCountMap.values()).map(
(row) => ({
groupKey: String(row.siteId),
name: row.name,
@@ -742,8 +786,26 @@ async function listSiteGroups(
})
);
siteGroups.sort((a, b) => {
const cmp = a.name.localeCompare(b.name, undefined, {
sensitivity: "base"
});
return query.order === "desc" ? -cmp : cmp;
});
const pinnedGroups: LauncherGroup[] = [];
if (aiGatewayCount > 0 && siteFilterIds.length === 0) {
pinnedGroups.push({
groupKey: LAUNCHER_AI_GATEWAY_GROUP_KEY,
name: "AI Gateway",
groupType: "site",
itemCount: aiGatewayCount
});
}
if (noSiteCount > 0 && siteFilterIds.length === 0) {
groups.push({
pinnedGroups.push({
groupKey: LAUNCHER_NO_SITE_GROUP_KEY,
name: "No Site",
groupType: "site",
@@ -751,12 +813,7 @@ async function listSiteGroups(
});
}
groups.sort((a, b) => {
const cmp = a.name.localeCompare(b.name, undefined, {
sensitivity: "base"
});
return query.order === "desc" ? -cmp : cmp;
});
const groups = [...pinnedGroups, ...siteGroups];
const total = groups.length;
return {
@@ -1189,8 +1246,11 @@ function filterResourcesBySite(
items: LauncherResource[],
groupKey: string
): LauncherResource[] {
if (groupKey === LAUNCHER_AI_GATEWAY_GROUP_KEY) {
return items.filter((item) => item.mode === "inference");
}
if (groupKey === LAUNCHER_NO_SITE_GROUP_KEY) {
return items.filter((item) => !item.site);
return items.filter((item) => !item.site && item.mode !== "inference");
}
const siteId = Number.parseInt(groupKey, 10);
if (!Number.isFinite(siteId)) {
@@ -1327,7 +1387,8 @@ async function listLauncherResourcesForUserUncached(
const parsedSiteId =
query.groupBy === "site" &&
query.groupKey !== LAUNCHER_NO_SITE_GROUP_KEY
query.groupKey !== LAUNCHER_NO_SITE_GROUP_KEY &&
query.groupKey !== LAUNCHER_AI_GATEWAY_GROUP_KEY
? Number.parseInt(query.groupKey, 10)
: Number.NaN;
const siteIdFilter = Number.isFinite(parsedSiteId)
@@ -0,0 +1,172 @@
import { db, resources, siteResources } from "@server/db";
import { listEffectiveAllowModels } from "@server/lib/aiInferenceResource";
import { response } from "@server/lib/response";
import HttpCode from "@server/types/HttpCode";
import { and, eq } from "drizzle-orm";
import { NextFunction, Request, Response } from "express";
import createHttpError from "http-errors";
import { fromZodError } from "zod-validation-error";
import { z } from "zod";
const publicParamsSchema = z.strictObject({
orgId: z.string().min(1),
resourceId: z.coerce.number().int().positive()
});
const siteParamsSchema = z.strictObject({
orgId: z.string().min(1),
siteResourceId: z.coerce.number().int().positive()
});
export type ListLauncherAiModelsResponse = {
models: Awaited<ReturnType<typeof listEffectiveAllowModels>>;
};
export async function listLauncherPublicAiModels(
req: Request,
res: Response,
next: NextFunction
): Promise<any> {
try {
const orgId = req.userOrgId;
if (!orgId) {
return next(
createHttpError(HttpCode.BAD_REQUEST, "Invalid organization ID")
);
}
const parsed = publicParamsSchema.safeParse(req.params);
if (!parsed.success) {
return next(
createHttpError(
HttpCode.BAD_REQUEST,
fromZodError(parsed.error)
)
);
}
const { resourceId } = parsed.data;
const [resource] = await db
.select({
resourceId: resources.resourceId,
mode: resources.mode
})
.from(resources)
.where(
and(
eq(resources.resourceId, resourceId),
eq(resources.orgId, orgId)
)
)
.limit(1);
if (!resource || resource.mode !== "inference") {
return next(
createHttpError(
HttpCode.BAD_REQUEST,
"AI models are only available for inference resources"
)
);
}
const models = await listEffectiveAllowModels({ resourceId });
return response<ListLauncherAiModelsResponse>(res, {
data: { models },
success: true,
error: false,
message: "Launcher AI models retrieved successfully",
status: HttpCode.OK
});
} catch (error) {
if (createHttpError.isHttpError(error)) {
return next(error);
}
console.error("Error listing launcher AI models:", error);
return next(
createHttpError(
HttpCode.INTERNAL_SERVER_ERROR,
"Internal server error"
)
);
}
}
export async function listLauncherSiteAiModels(
req: Request,
res: Response,
next: NextFunction
): Promise<any> {
try {
const orgId = req.userOrgId;
if (!orgId) {
return next(
createHttpError(HttpCode.BAD_REQUEST, "Invalid organization ID")
);
}
const parsed = siteParamsSchema.safeParse(req.params);
if (!parsed.success) {
return next(
createHttpError(
HttpCode.BAD_REQUEST,
fromZodError(parsed.error)
)
);
}
const { siteResourceId } = parsed.data;
const siteResource =
req.siteResource ??
(
await db
.select({
siteResourceId: siteResources.siteResourceId,
mode: siteResources.mode,
orgId: siteResources.orgId
})
.from(siteResources)
.where(
and(
eq(siteResources.siteResourceId, siteResourceId),
eq(siteResources.orgId, orgId)
)
)
.limit(1)
)[0];
if (
!siteResource ||
siteResource.orgId !== orgId ||
siteResource.mode !== "inference"
) {
return next(
createHttpError(
HttpCode.BAD_REQUEST,
"AI models are only available for inference resources"
)
);
}
const models = await listEffectiveAllowModels({ siteResourceId });
return response<ListLauncherAiModelsResponse>(res, {
data: { models },
success: true,
error: false,
message: "Launcher AI models retrieved successfully",
status: HttpCode.OK
});
} catch (error) {
if (createHttpError.isHttpError(error)) {
return next(error);
}
console.error("Error listing launcher AI models:", error);
return next(
createHttpError(
HttpCode.INTERNAL_SERVER_ERROR,
"Internal server error"
)
);
}
}
+1
View File
@@ -2,6 +2,7 @@ import { z } from "zod";
export const LAUNCHER_UNLABELED_GROUP_KEY = "unlabeled";
export const LAUNCHER_NO_SITE_GROUP_KEY = "no-site";
export const LAUNCHER_AI_GATEWAY_GROUP_KEY = "ai-gateway";
export const LAUNCHER_FLAT_GROUP_KEY = "__all__";
export const launcherViewConfigSchema = z.object({
@@ -368,56 +368,65 @@ export default function CreatePrivateResourcePage() {
/>
</SettingsFormCell>
{mode === "http" ||
(mode === "inference" && (
<SettingsFormCell span="full">
<FormItem>
<DomainPicker
orgId={orgId}
cols={2}
hideFreeDomain
onDomainChange={(
res
) => {
if (!res) {
{(mode === "http" ||
mode === "inference") && (
<SettingsFormCell span="full">
<FormField
control={form.control}
name="httpConfigDomainId"
render={() => (
<FormItem>
<DomainPicker
orgId={orgId}
cols={2}
hideFreeDomain
onDomainChange={(
res
) => {
if (!res) {
form.setValue(
"httpConfigSubdomain",
null
);
form.setValue(
"httpConfigDomainId",
null
);
form.setValue(
"httpConfigFullDomain",
null
);
return;
}
form.setValue(
"httpConfigSubdomain",
null
res.subdomain ??
null
);
form.setValue(
"httpConfigDomainId",
null
res.domainId,
{
shouldValidate: true
}
);
form.setValue(
"httpConfigFullDomain",
null
res.fullDomain
);
return;
}
form.setValue(
"httpConfigSubdomain",
res.subdomain ??
null
);
form.setValue(
"httpConfigDomainId",
res.domainId
);
form.setValue(
"httpConfigFullDomain",
res.fullDomain
);
}}
/>
<FormMessage />
<FormDescription>
{t(
"resourceDomainDescription"
)}
</FormDescription>
</FormItem>
</SettingsFormCell>
))}
}}
/>
<FormMessage />
<FormDescription>
{t(
"resourceDomainDescription"
)}
</FormDescription>
</FormItem>
)}
/>
</SettingsFormCell>
)}
{(mode === "host" ||
(mode === "ssh" && !isNativeSsh)) && (
+6 -2
View File
@@ -124,13 +124,17 @@ export function PrivateResourceInfoSections({
siteResource.fullDomain &&
build != "oss"
);
const showPortRestrictions =
isPanel &&
siteResource.mode !== "http" &&
siteResource.mode !== "inference";
const numSections =
2 +
(showDestination ? 1 : 0) +
(showAlias ? 1 : 0) +
(showCertificate ? 1 : 0) +
(isPanel ? 1 : 0);
(showPortRestrictions ? 1 : 0);
const sections = (
<InfoSections cols={numSections} layout={isPanel ? "panel" : "default"}>
@@ -194,7 +198,7 @@ export function PrivateResourceInfoSections({
</InfoSection>
) : null}
{isPanel ? (
{showPortRestrictions ? (
<InfoSection>
<InfoSectionTitle>{t("portRestrictions")}</InfoSectionTitle>
<InfoSectionContent>
@@ -17,6 +17,7 @@ import type {
LauncherViewConfig
} from "@server/routers/launcher/types";
import {
LAUNCHER_AI_GATEWAY_GROUP_KEY,
LAUNCHER_NO_SITE_GROUP_KEY,
LAUNCHER_UNLABELED_GROUP_KEY
} from "@server/routers/launcher/types";
@@ -148,9 +149,11 @@ export function LauncherGroupSection({
const groupTitle =
group.groupKey === LAUNCHER_UNLABELED_GROUP_KEY
? t("resourceLauncherUnlabeled")
: group.groupKey === LAUNCHER_NO_SITE_GROUP_KEY
? t("resourceLauncherNoSite")
: group.name;
: group.groupKey === LAUNCHER_AI_GATEWAY_GROUP_KEY
? t("resourceLauncherAiGateway")
: group.groupKey === LAUNCHER_NO_SITE_GROUP_KEY
? t("resourceLauncherNoSite")
: group.name;
return (
<Collapsible
@@ -2,6 +2,10 @@
import { CollapsibleTrigger } from "@app/components/ui/collapsible";
import type { LauncherGroup } from "@server/routers/launcher/types";
import {
LAUNCHER_AI_GATEWAY_GROUP_KEY,
LAUNCHER_NO_SITE_GROUP_KEY
} from "@server/routers/launcher/types";
import { ChevronDown, ChevronLeft } from "lucide-react";
type LauncherGroupTriggerProps = {
@@ -21,6 +25,13 @@ function LauncherGroupStatusDot({ group }: { group: LauncherGroup }) {
}
if (group.groupType === "site") {
if (
group.groupKey === LAUNCHER_AI_GATEWAY_GROUP_KEY ||
group.groupKey === LAUNCHER_NO_SITE_GROUP_KEY
) {
return null;
}
if (
(group.siteType === "newt" || group.siteType === "wireguard") &&
typeof group.siteOnline === "boolean"
@@ -47,11 +58,11 @@ export function LauncherGroupTrigger({
title,
isOpen
}: LauncherGroupTriggerProps) {
const statusDot = <LauncherGroupStatusDot group={group} />;
return (
<CollapsibleTrigger className="flex w-full items-center gap-2.5 rounded-md bg-accent px-4 py-2.5 text-left transition-colors cursor-pointer">
{group.groupType === "site" || group.groupType === "label" ? (
<LauncherGroupStatusDot group={group} />
) : null}
{statusDot}
<span className="flex min-w-0 items-center gap-2.5 text-sm font-semibold text-foreground">
<span className="truncate">
{title} ({group.itemCount})
@@ -0,0 +1,223 @@
"use client";
import CopyToClipboard from "@app/components/CopyToClipboard";
import {
SettingsSection,
SettingsSectionBody,
SettingsSectionDescription,
SettingsSectionHeader,
SettingsSectionTitle,
SettingsSubsectionDescription,
SettingsSubsectionHeader,
SettingsSubsectionTitle
} from "@app/components/Settings";
import { Button } from "@app/components/ui/button";
import { createApiClient, formatAxiosError } from "@app/lib/api";
import { useEnvContext } from "@app/hooks/useEnvContext";
import { toast } from "@app/hooks/useToast";
import { launcherQueries } from "@app/lib/queries";
import type {
GetMyVirtualApiKeyResponse,
VirtualApiKeyWithResources
} from "@server/routers/virtualApiKey/types";
import { useQuery } from "@tanstack/react-query";
import type { AxiosResponse } from "axios";
import { Loader2 } from "lucide-react";
import { useTranslations } from "next-intl";
import { useState } from "react";
type LauncherInferenceApiKeysSectionProps = {
orgId: string;
resourceGuid: string;
};
function keyPreview(virtualApiKeyId: string, lastChars: string): string {
return `vk-${virtualApiKeyId}••••${lastChars}`;
}
function useRevealSecret(orgId: string, virtualApiKeyId: string) {
const t = useTranslations();
const api = createApiClient(useEnvContext());
const [credential, setCredential] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const revealSecret = () => {
if (credential || loading) {
return;
}
setLoading(true);
api.get<AxiosResponse<GetMyVirtualApiKeyResponse>>(
`/org/${orgId}/my-virtual-api-keys/${virtualApiKeyId}`
)
.then((res) => {
const secret = res.data.data.virtualApiKey.secret;
if (secret) {
setCredential(`vk-${virtualApiKeyId}.${secret}`);
} else {
toast({
variant: "destructive",
title: t("virtualApiKeysErrorFetchSecret"),
description: t(
"virtualApiKeysErrorFetchSecretDescription"
)
});
}
})
.catch((e) => {
toast({
variant: "destructive",
title: t("virtualApiKeysErrorFetchSecret"),
description: formatAxiosError(
e,
t("virtualApiKeysErrorFetchSecretDescription")
)
});
})
.finally(() => {
setLoading(false);
});
};
return { credential, loading, revealSecret };
}
function PanelKeySecret({
orgId,
virtualApiKeyId,
lastChars
}: {
orgId: string;
virtualApiKeyId: string;
lastChars: string;
}) {
const t = useTranslations();
const preview = keyPreview(virtualApiKeyId, lastChars);
const { credential, loading, revealSecret } = useRevealSecret(
orgId,
virtualApiKeyId
);
const displayValue = credential ?? preview;
return (
<div className="flex items-center gap-3 min-w-0">
<div className="min-w-0 flex-1">
<CopyToClipboard
text={displayValue}
displayText={displayValue}
/>
</div>
{!credential ? (
<Button
variant="link"
size="sm"
className="shrink-0 px-0 h-auto"
loading={loading}
onClick={revealSecret}
>
{t("myVirtualApiKeysRevealSecret")}
</Button>
) : null}
</div>
);
}
function ManualKeyRow({
orgId,
keyRow
}: {
orgId: string;
keyRow: VirtualApiKeyWithResources;
}) {
const t = useTranslations();
return (
<div className="space-y-1 min-w-0">
<p className="font-medium truncate">
{keyRow.name || t("myVirtualApiKeysUnnamed")}
</p>
{keyRow.description ? (
<p className="text-sm text-muted-foreground">
{keyRow.description}
</p>
) : null}
<PanelKeySecret
orgId={orgId}
virtualApiKeyId={keyRow.virtualApiKeyId}
lastChars={keyRow.lastChars}
/>
</div>
);
}
export function LauncherInferenceApiKeysSection({
orgId,
resourceGuid
}: LauncherInferenceApiKeysSectionProps) {
const t = useTranslations();
const { data, isPending, isError } = useQuery(
launcherQueries.myVirtualApiKeys(orgId, resourceGuid)
);
return (
<SettingsSection>
<SettingsSectionHeader>
<SettingsSectionTitle>
{t("resourceLauncherApiKeys")}
</SettingsSectionTitle>
<SettingsSectionDescription>
{t("resourceLauncherApiKeysDescription")}
</SettingsSectionDescription>
</SettingsSectionHeader>
<SettingsSectionBody>
{isPending ? (
<div className="flex items-center justify-center py-6 text-muted-foreground">
<Loader2 className="size-5 animate-spin" />
</div>
) : null}
{isError ? (
<p className="text-sm text-muted-foreground">
{t("resourceLauncherApiKeysError")}
</p>
) : null}
{!isPending && !isError && data ? (
<div className="space-y-4">
<div className="space-y-1 min-w-0">
<p className="font-medium">
{t("resourceLauncherApiKeysIdentity")}
</p>
<PanelKeySecret
orgId={orgId}
virtualApiKeyId={data.userKey.virtualApiKeyId}
lastChars={data.userKey.lastChars}
/>
</div>
{data.manualKeys.length > 0 ? (
<div>
<SettingsSubsectionHeader>
<SettingsSubsectionTitle>
{t("resourceLauncherApiKeysManual")}
</SettingsSubsectionTitle>
<SettingsSubsectionDescription>
{t(
"myVirtualApiKeysManualResourceDescription"
)}
</SettingsSubsectionDescription>
</SettingsSubsectionHeader>
<div className="space-y-3">
{data.manualKeys.map((keyRow) => (
<ManualKeyRow
key={keyRow.virtualApiKeyId}
orgId={orgId}
keyRow={keyRow}
/>
))}
</div>
</div>
) : null}
</div>
) : null}
</SettingsSectionBody>
</SettingsSection>
);
}
@@ -0,0 +1,170 @@
"use client";
import {
SettingsSection,
SettingsSectionBody,
SettingsSectionDescription,
SettingsSectionHeader,
SettingsSectionTitle
} from "@app/components/Settings";
import { Button } from "@app/components/ui/button";
import { cn } from "@app/lib/cn";
import { launcherQueries } from "@app/lib/queries";
import { useQuery } from "@tanstack/react-query";
import { Loader2 } from "lucide-react";
import { useTranslations } from "next-intl";
import { useEffect, useLayoutEffect, useRef, useState } from "react";
const COLLAPSED_ROWS = 5;
const GRID_COLUMNS = 2;
type LauncherInferenceModelsSectionProps = {
orgId: string;
params:
| {
resourceType: "public";
resourceId: number;
}
| {
resourceType: "site";
siteResourceId: number;
};
};
export function LauncherInferenceModelsSection({
orgId,
params
}: LauncherInferenceModelsSectionProps) {
const t = useTranslations();
const { data, isPending, isError } = useQuery(
launcherQueries.aiModels(orgId, params)
);
const models = data?.models ?? [];
const [listExpanded, setListExpanded] = useState(false);
const [clipHeight, setClipHeight] = useState<number | null>(null);
const gridRef = useRef<HTMLDivElement>(null);
const collapsedLimit = GRID_COLUMNS * COLLAPSED_ROWS;
const hasOverflow = models.length > collapsedLimit;
const isCollapsed = hasOverflow && !listExpanded;
useEffect(() => {
if (!hasOverflow) {
setListExpanded(false);
}
}, [hasOverflow]);
useLayoutEffect(() => {
if (!isCollapsed || !gridRef.current) {
setClipHeight(null);
return;
}
const children = Array.from(gridRef.current.children) as HTMLElement[];
const lastVisible = children[collapsedLimit - 1];
if (!lastVisible) {
setClipHeight(null);
return;
}
const gridTop = gridRef.current.getBoundingClientRect().top;
const cardBottom = lastVisible.getBoundingClientRect().bottom;
// Peek slightly into the next row so the fade has content to soften.
setClipHeight(cardBottom - gridTop + 12);
}, [isCollapsed, collapsedLimit, models]);
return (
<SettingsSection>
<SettingsSectionHeader>
<SettingsSectionTitle>
{t("resourceLauncherAvailableModels")}
</SettingsSectionTitle>
<SettingsSectionDescription>
{t("resourceLauncherAvailableModelsDescription")}
</SettingsSectionDescription>
</SettingsSectionHeader>
<SettingsSectionBody>
{isPending ? (
<div className="flex items-center justify-center py-6 text-muted-foreground">
<Loader2 className="size-5 animate-spin" />
</div>
) : null}
{isError ? (
<p className="text-sm text-muted-foreground">
{t("resourceLauncherAvailableModelsError")}
</p>
) : null}
{!isPending && !isError && models.length === 0 ? (
<p className="text-sm text-muted-foreground">
{t("resourceLauncherAvailableModelsEmpty")}
</p>
) : null}
{!isPending && !isError && models.length > 0 ? (
<div>
<div className="relative">
<div
ref={gridRef}
className={cn(
"grid grid-cols-2 gap-2",
isCollapsed && "overflow-hidden"
)}
style={
isCollapsed && clipHeight != null
? { maxHeight: clipHeight }
: undefined
}
>
{models.map((model) => (
<div
key={model.modelId}
className="flex min-w-0 flex-col gap-0.5 rounded-md border border-input px-2.5 py-2"
>
<span className="block truncate font-mono text-xs font-medium">
{model.modelKey}
</span>
{model.providerName ? (
<span className="block truncate text-xs text-muted-foreground">
{model.providerName}
</span>
) : null}
</div>
))}
</div>
{isCollapsed ? (
<div className="pointer-events-none absolute inset-x-0 bottom-0 h-14 bg-gradient-to-t from-card from-25% via-card/80 to-transparent" />
) : null}
</div>
{isCollapsed ? (
<div className="relative z-10 flex justify-center pt-2">
<Button
type="button"
variant="text"
size="sm"
className="bg-card px-2 text-muted-foreground hover:text-foreground"
onClick={() => setListExpanded(true)}
>
{t("aiProviderModelsViewMore", {
count: models.length - collapsedLimit
})}
</Button>
</div>
) : null}
{hasOverflow && listExpanded ? (
<div className="flex justify-center pt-1">
<Button
type="button"
variant="text"
size="sm"
className="text-muted-foreground hover:text-foreground"
onClick={() => setListExpanded(false)}
>
{t("aiProviderModelsViewLess")}
</Button>
</div>
) : null}
</div>
) : null}
</SettingsSectionBody>
</SettingsSection>
);
}
@@ -8,6 +8,8 @@ import {
InfoSectionTitle
} from "@app/components/InfoSection";
import { PrivateResourceInfoSections } from "@app/components/PrivateResourceInfoBox";
import { LauncherInferenceApiKeysSection } from "@app/components/resource-launcher/LauncherInferenceApiKeysSection";
import { LauncherInferenceModelsSection } from "@app/components/resource-launcher/LauncherInferenceModelsSection";
import {
SettingsSection,
SettingsSectionBody,
@@ -146,7 +148,8 @@ function HealthStatusDisplay({
);
}
const PUBLIC_AUTH_BROWSER_MODES = ["http", "ssh", "rdp", "vnc"];
const PUBLIC_AUTH_METHODS_MODES = ["http", "ssh", "rdp", "vnc"];
const PUBLIC_AUTH_BADGE_MODES = [...PUBLIC_AUTH_METHODS_MODES, "inference"];
function AuthMethodStatusDisplay({ enabled }: { enabled: boolean }) {
const t = useTranslations();
@@ -227,20 +230,24 @@ function PublicResourceAuthMethods({
}
function PublicResourceDetails({
orgId,
launcherResource,
resource,
authInfo
}: {
orgId: string;
launcherResource: LauncherResource;
resource: GetResourceResponse;
authInfo: GetResourceAuthInfoResponse;
}) {
const t = useTranslations();
const supportsAuth = PUBLIC_AUTH_BROWSER_MODES.includes(
resource.mode || ""
);
const mode = resource.mode || "";
const isInference = mode === "inference";
const showAuthBadge = PUBLIC_AUTH_BADGE_MODES.includes(mode);
const showAuthMethods = PUBLIC_AUTH_METHODS_MODES.includes(mode);
const showHealth = !isInference;
const authState = derivePublicAuthState(resource.mode, authInfo);
const infoSectionCount = supportsAuth ? 4 : 3;
const infoSectionCount = 2 + (showAuthBadge ? 1 : 0) + (showHealth ? 1 : 0);
return (
<div className="space-y-4">
@@ -275,7 +282,7 @@ function PublicResourceDetails({
/>
</InfoSectionContent>
</InfoSection>
{supportsAuth ? (
{showAuthBadge ? (
<InfoSection>
<InfoSectionTitle>
{t("authentication")}
@@ -295,30 +302,54 @@ function PublicResourceDetails({
</InfoSectionContent>
</InfoSection>
) : null}
<InfoSection>
<InfoSectionTitle>{t("health")}</InfoSectionTitle>
<InfoSectionContent>
<HealthStatusDisplay health={resource.health} />
</InfoSectionContent>
</InfoSection>
{showHealth ? (
<InfoSection>
<InfoSectionTitle>
{t("health")}
</InfoSectionTitle>
<InfoSectionContent>
<HealthStatusDisplay
health={resource.health}
/>
</InfoSectionContent>
</InfoSection>
) : null}
</InfoSections>
</SettingsSectionBody>
</SettingsSection>
{supportsAuth ? (
{showAuthMethods ? (
<PublicResourceAuthMethods authInfo={authInfo} />
) : null}
{isInference ? (
<>
<LauncherInferenceModelsSection
orgId={orgId}
params={{
resourceType: "public",
resourceId: resource.resourceId
}}
/>
<LauncherInferenceApiKeysSection
orgId={orgId}
resourceGuid={resource.resourceGuid}
/>
</>
) : null}
</div>
);
}
function PrivateResourceDetails({
orgId,
launcherResource,
resource
}: {
orgId: string;
launcherResource: LauncherResource;
resource: GetSiteResourceResponse;
}) {
const t = useTranslations();
const isInference = resource.mode === "inference";
return (
<div className="space-y-4">
@@ -365,6 +396,15 @@ function PrivateResourceDetails({
/>
</SettingsSectionBody>
</SettingsSection>
{isInference ? (
<LauncherInferenceModelsSection
orgId={orgId}
params={{
resourceType: "site",
siteResourceId: resource.siteResourceId
}}
/>
) : null}
</div>
);
}
@@ -405,6 +445,7 @@ function LauncherResourcePanelBody({
if (detail.resourceType === "public") {
return (
<PublicResourceDetails
orgId={orgId}
launcherResource={resource}
resource={detail.data}
authInfo={detail.authInfo}
@@ -414,6 +455,7 @@ function LauncherResourcePanelBody({
return (
<PrivateResourceDetails
orgId={orgId}
launcherResource={resource}
resource={detail.data}
/>
+10 -10
View File
@@ -37,7 +37,7 @@ export type LauncherAccessFields = {
export function formatPublicResourceAccess(
resource: PublicResourceAccessInput
): LauncherAccessFields {
const browserModes = ["http", "ssh", "rdp", "vnc"];
const browserModes = ["http", "ssh", "rdp", "vnc", "inference"];
if (!browserModes.includes(resource.mode)) {
const port = resource.proxyPort?.toString() ?? "";
return {
@@ -66,16 +66,8 @@ export function formatPublicResourceAccess(
export function formatSiteResourceAccess(
resource: SiteResourceAccessInput
): LauncherAccessFields {
if (resource.alias) {
return {
accessDisplay: resource.alias,
accessCopyValue: resource.alias,
accessUrl: null
};
}
if (
(resource.mode === "http" || resource.mode == "inference") &&
(resource.mode === "http" || resource.mode === "inference") &&
resource.fullDomain
) {
const url = `${resource.ssl ? "https" : "http"}://${resource.fullDomain}`;
@@ -86,6 +78,14 @@ export function formatSiteResourceAccess(
};
}
if (resource.alias) {
return {
accessDisplay: resource.alias,
accessCopyValue: resource.alias,
accessUrl: null
};
}
const destination = formatSiteResourceDestinationDisplay({
mode: resource.mode as SiteResourceDestinationInput["mode"],
destination: resource.destination,
+5 -1
View File
@@ -4,7 +4,7 @@ import type { GetSiteResourceResponse } from "@server/routers/siteResource/getSi
export type PublicAuthState = "protected" | "not_protected" | "none";
const BROWSER_MODES = ["http", "ssh", "rdp", "vnc"];
const BROWSER_MODES = ["http", "ssh", "rdp", "vnc", "inference"];
export function derivePublicAuthState(
mode: string | null,
@@ -37,6 +37,10 @@ export function formatPublicResourceType(
return resource.ssl ? "HTTPS" : "HTTP";
}
if (resource.mode === "inference") {
return "Inference";
}
const mode = (resource.mode || "").toLowerCase();
if (mode === "tcp") {
return "TCP";
+66
View File
@@ -34,6 +34,8 @@ import type {
ListLauncherSitesResponse,
ListLauncherViewsResponse
} from "@server/routers/launcher/types";
import type { ListLauncherAiModelsResponse } from "@server/routers/launcher/listLauncherAiModels";
import type { ListMyVirtualApiKeysResponse } from "@server/routers/virtualApiKey/types";
import type { GetResourcePolicyResponse } from "@server/routers/policy";
import type {
GetResourcePoliciesResponse,
@@ -1776,5 +1778,69 @@ export const launcherQueries = {
data: res.data.data
};
}
}),
aiModels: (
orgId: string,
params:
| {
resourceType: "public";
resourceId: number;
}
| {
resourceType: "site";
siteResourceId: number;
}
| null
) =>
queryOptions({
queryKey: ["ORG", orgId, "LAUNCHER", "AI_MODELS", params] as const,
enabled: params != null,
queryFn: async ({ signal, meta }) => {
if (!params) {
throw new Error("Resource params are required");
}
if (params.resourceType === "public") {
const res = await meta!.api.get<
AxiosResponse<ListLauncherAiModelsResponse>
>(
`/org/${orgId}/launcher/resource/${params.resourceId}/ai-models`,
{ signal }
);
return res.data.data;
}
const res = await meta!.api.get<
AxiosResponse<ListLauncherAiModelsResponse>
>(
`/org/${orgId}/launcher/site-resource/${params.siteResourceId}/ai-models`,
{ signal }
);
return res.data.data;
}
}),
myVirtualApiKeys: (orgId: string, resourceGuid: string | null) =>
queryOptions({
queryKey: [
"ORG",
orgId,
"LAUNCHER",
"MY_VIRTUAL_API_KEYS",
resourceGuid
] as const,
enabled: Boolean(resourceGuid),
queryFn: async ({ signal, meta }) => {
if (!resourceGuid) {
throw new Error("resourceGuid is required");
}
const res = await meta!.api.get<
AxiosResponse<ListMyVirtualApiKeysResponse>
>(
`/org/${orgId}/my-virtual-api-keys?resourceGuid=${encodeURIComponent(resourceGuid)}`,
{ signal }
);
return res.data.data;
}
})
};